question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00291 |
<h1>ã財åžã¡ã¿ã蚺æ</h1>
<p>
ïŒæã«æ¶è²»çšãïŒïŒ
ã«ãªã£ãŠãããã財åžã硬貚ã§ãã³ãã³ã«ãªã£ãŠããŸããããåãéé¡ãæã¡æ©ããªãç¡¬è²šã®ææ°ãå°ãªããããã§ãããã硬貚ã®åèšãïŒïŒïŒïŒå以äžãªãã硬貚ããæã«äž¡æ¿ããŠãã財åžã®ã¡ã¿ãç¶æ
ãè§£æ¶ã§ããŸãã
</p>
<p>
ã財åžã®äžã®ç¡¬è²šã®ææ°ãçš®é¡ããšã«äžãããããšãã硬貚ããæã«äž¡æ¿ã§ãããã©ãããå€å®ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>c1</var> <var>c5</var> <var>c10</var> <var>c50</var> <var>c100</var> <var>c500</var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªãã<var>c1</var>ã<var>c5</var>ã<var>c10</var>ã<var>c50</var>ã<var>c100</var>ã<var>c500</var> (0 ≤ <var>c1, c5, c10, c50, c100, c500</var> ≤ 50) ã¯ãããããã1åã5åã10åã50åã100åã500åç¡¬è²šã®ææ°ã衚ãã
</p>
<h2>åºå</h2>
<p>
硬貚ããæã«äž¡æ¿ã§ãããªã1 ããããã§ãªããã° 0 ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
3 1 4 0 4 1
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
0
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
2 1 4 3 2 3
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
1
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
21 5 9 3 1 1
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
0
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
2 4 3 3 3 1
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
1
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
50 50 50 4 0 0
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
1
</pre>
|
p02306 | <script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Incircle of a Triangle</H1>
<p>
Write a program which prints the central coordinate ($cx$,$cy$) and the radius $r$ of a incircle of a triangle which is constructed by three points ($x_1$, $y_1$), ($x_2$, $y_2$) and ($x_3$, $y_3$) on the plane surface.
</p>
<h2>Input</h2>
<p>The input is given in the following format</p>
<pre>
$x_1$ $y_1$
$x_2$ $y_2$
$x_3$ $y_3$
</pre>
<p>
All the input are integers.
</p>
<h2>Constraints</h2>
<ul>
<li>$-10000 \leq x_i, y_i \leq 10000$</li>
<li>The three points are not on the same straight line</li>
</ul>
<h2>Output</h2>
<p>
Print $cx$, $cy$ and $r$ separated by a single space in a line. The output values should be in a decimal fraction with an error less than 0.000001.
</p>
<h2>Sample Input 1</h2>
<pre>
1 -2
3 2
-2 0
</pre>
<h2>Sample Output 1</h2>
<pre>
0.53907943898209422325 -0.26437392711448356856 1.18845545916395465278
</pre>
<h2>Sample Input 2</h2>
<pre>
0 3
4 0
0 0
</pre>
<h2>Sample Output 2</h2>
<pre>
1.00000000000000000000 1.00000000000000000000 1.00000000000000000000
</pre>
|
p03147 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In a flower bed, there are <var>N</var> flowers, numbered <var>1,2,......,N</var>. Initially, the heights of all flowers are <var>0</var>.
You are given a sequence <var>h=\{h_1,h_2,h_3,......\}</var> as input. You would like to change the height of Flower <var>k</var> to <var>h_k</var> for all <var>k</var> <var>(1 \leq k \leq N)</var>, by repeating the following "watering" operation:</p>
<ul>
<li>Specify integers <var>l</var> and <var>r</var>. Increase the height of Flower <var>x</var> by <var>1</var> for all <var>x</var> such that <var>l \leq x \leq r</var>.</li>
</ul>
<p>Find the minimum number of watering operations required to satisfy the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq h_i \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>h_1</var> <var>h_2</var> <var>h_3</var> <var>......</var> <var>h_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of watering operations required to satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The minimum number of watering operations required is <var>2</var>.
One way to achieve it is:</p>
<ul>
<li>Perform the operation with <var>(l,r)=(1,3)</var>.</li>
<li>Perform the operation with <var>(l,r)=(2,4)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
3 1 2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
4 23 75 0 23 96 50 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>221
</pre></section>
</div>
</span> |
p01480 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<h1> Unequal Dice</h1>
<p>
Time Limit: 8 sec / Memory Limit: 64 MB
</p>
<h2> B: äžæããªãµã€ã³ã</h2>
<p>
ããã³ã³ã競銬ãªã©ã®è³ãäºã«ãéã䜿ããããŠïŒåéãŸã¿ãã«ãªã£ãããªãã¯ïŒ
Tæã°ã«ãŒãã®å°äžç£çã«å容ãããŠããŸã£ãïŒ
ããã§ããªãã¯ïŒåéãè¿ããŸã§å¥Žé·ã®ããã«åããªããŠã¯ãªããªãïŒ
</p>
<p>
ãŸããã®ç£çã«ã¯ããªããšåãå¢éã®äººãå€ãå容ãããŠããã®ã§ïŒ
ããã€ãã®çã«åããããŠããïŒ
ããçã§ã¯ïŒãµã€ã³ãã3ã€è»¢ãããŠãæ€ã«ãããŠæ¥œããç¿æ
£ãããïŒ
æè¿ïŒããã®çé·ã倧å€ãªç®ã«ãã£ããšããã話ãèãããïŒããªãã«çŽæ¥é¢ä¿ã¯ãªãïŒ
</p>
<p>
ããªãã®æå±ããçã§ã¯ã²ãšã€ã®ãµã€ã³ããæ¯ã£ãŠæ¥œããç¿æ
£ãããïŒ
ã«ãŒã«ã¯ïŒãµã€ã³ããæ¯ã£ãŠç®ã®å€§ããªå€ãåºãã°åã¡ãšããç°¡åãªãã®ã§ããïŒ
ãã ç¹æ®ãªããšãšããŠã¯ïŒçšãããããµã€ã³ãã®ããé¢ãåºã確çãïŒåæ§ã«ç¢ºãããããªããšããããšã§ããïŒ
ãŸããµã€ã³ããçš®é¡ãå€ãïŒ10é¢äœã®ãã®ãã100é¢äœã®ãã®ãšããŸããŸã«çšæãããŠããïŒ
ããã«äœãå€ã®æžãããŠããªãé¢ãŸã§ããïŒ
äœã®å€ãæžãããŠããªãé¢ãåºããšãã¯ïŒå床æ¯ããªãããããïŒ
</p>
<p>
ãã®ã²ãŒã ãä»åã£ãŠããçé·ããïŒãããããæ¯ã£ãŠãè¯ããµã€ã³ããããã€ãæç€ºãããã®ã ãïŒã©ãã䜿ã£ãŠãåãŠãæ°ãããªãæãããïŒ
</p>
<p>
ããã§ïŒäžãããããµã€ã³ãã®å
ïŒçé·ã䜿ããµã€ã³ãã§åºãå€ã®æåŸ
å€ããé«ããµã€ã³ããããã®ãã©ãã調ã¹ããïŒ
æåŸ
å€ãé«ããšã¯çé·ã®ãµã€ã³ãããïŒ0.0000001ãã倧ããæãæãïŒ
</p>
<h2> Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<pre>
<i>t</i>
<i>n<sub>1</sub></i> <i>m<sub>1</sub></i>
<i>v<sub>1</sub></i> <i>r<sub>1</sub></i>
...
<i>v<sub>m<sub>1</sub></sub></i> <i>r<sub>m<sub>1</sub></sub></i>
<i>n<sub>2</sub></i> <i>m<sub>2</sub></i>
...
<i>n<sub>t</sub></i> <i>m<sub>t</sub></i>
<i>v<sub>1</sub></i> <i>r<sub>1</sub></i>
...
<i>v<sub>m<sub>t</sub></sub></i> <i>r<sub>m<sub>t</sub></sub></i>
<i>p</i> <i>q</i>
<i>v<sub>1</sub></i> <i>r<sub>1</sub></i>
...
<i>v<sub>q</sub></i> <i>r<sub>q</sub></i>
</pre>
<p>
å
¥åã®åœ¢åŒã«å«ãŸããå倿°ã®æå³ãšå¶çŽã¯ä»¥äžã®éãã§ããïŒ
</p>
<ul>
<li> <i>t</i> ã¯äžãããããµã€ã³ãã®æ° <i>t</i> (0 < <i>t</i> <=10)</li>
<li> <i>n</i> ã¯äœé¢äœã§ããã®ããè¡šãæŽæ° (4 <= <i>n</i> <= 100)</li>
<li> <i>m</i> ã¯æ°å€ã®æ¯ãããŠããé¢ã®æ° (0 < <i>m</i> <= <i>n</i>)</li>
<li> <i>v<sub>i</sub></i> ã¯é¢ã«æ¯ãããŠããæ°å€ (0<= <i>v</i> <= 100) </li>
<li> <i>r<sub>i</sub></i> ã¯ãã®é¢ãåºã確ç (0 < <i>r</i> <= 1.0)</li>
<ul>
<li> <i>r<sub>1</sub></i> + <i>r<sub>2</sub></i> + ... + <i>r<sub>m</sub></i> <= 1.0ã¯ä¿èšŒãããïŒ</li>
</ul>
<ul>
<li> ãŸã <i>r<sub>i</sub></i> ã¯å°æ°ç¬¬10äœãŸã§äžããããããšãããïŒ</li>
</ul>
<li> <i>p</i> ã¯çé·ã®äœ¿ããµã€ã³ããäœé¢äœã§ããããè¡šãæŽæ°</li>
<li> <i>q</i> ã¯çé·ã®äœ¿ããµã€ã³ãã«æ°å€ã®æ¯ãããŠããé¢ã®æ°</li>
</ul>
<h2> Output</h2>
<p>
çé·ã®äœ¿ããµã€ã³ããããæåŸ
å€ã®é«ããµã€ã³ããããã°YESïŒããã§ãªããã°NOãåºåããïŒ
</p>
<h2> Sample Input 1</h2>
<pre>
2
4 2
4 0.4000000
3 0.5000000
4 1
5 0.3333333
5 3
5 0.7777777
4 0.1111111
2 0.0001111
</pre>
<h2> Sample Output 1</h2>
<pre>
YES
</pre>
<h2> Sample Input 2</h2>
<pre>
2
4 2
4 0.5000000
3 0.4000000
4 1
5 0.3333333
5 3
8 0.7777777
4 0.1111111
2 0.0001111
</pre>
<h2> Sample Output 2</h2>
<pre>
NO
</pre>
</body>
</html> |
p03517 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo has an undirected graph <var>G</var> with <var>N</var> vertices numbered <var>1,2,...,N</var> and <var>M</var> edges numbered <var>1,2,...,M</var>.
Edge <var>i</var> connects Vertex <var>a_{i}</var> and <var>b_{i}</var> and has a length of <var>w_i</var>.</p>
<p>Now, he is in the middle of painting these <var>N</var> vertices in <var>K</var> colors numbered <var>1,2,...,K</var>. Vertex <var>i</var> is already painted in Color <var>c_i</var>, except when <var>c_i = 0</var>, in which case Vertex <var>i</var> is not yet painted.</p>
<p>After he paints each vertex that is not yet painted in one of the <var>K</var> colors, he will give <var>G</var> to Snuke.</p>
<p>Based on <var>G</var>, Snuke will make another undirected graph <var>G'</var> with <var>K</var> vertices numbered <var>1,2,...,K</var> and <var>M</var> edges.
Initially, there is no edge in <var>G'</var>. The <var>i</var>-th edge will be added as follows:</p>
<ul>
<li>Let <var>x</var> and <var>y</var> be the colors of the two vertices connected by Edge <var>i</var> in <var>G</var>.</li>
<li>Add an edge of length <var>w_i</var> connecting Vertex <var>x</var> and <var>y</var> in <var>G'</var>.</li>
</ul>
<p>What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of <var>G'</var>? If <var>G'</var> will not be connected regardless of how Ringo paints the vertices, print <var>-1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 10^{5}</var></li>
<li><var>1 \leq K \leq N</var></li>
<li><var>0 \leq c_i \leq K</var></li>
<li><var>1 \leq a_i,b_i \leq N</var></li>
<li><var>1 \leq w_i \leq 10^{9}</var></li>
<li>The given graph may NOT be simple or connected.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>100</var> points, <var>N = K</var> and <var>c_i = i</var>.</li>
<li>In the test set worth another <var>100</var> points, <var>c_i \neq 0</var>.</li>
<li>In the test set worth another <var>200</var> points, <var>c_i = 0</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>K</var>
<var>c_1</var> <var>c_2</var> <var>...</var> <var>c_{N}</var>
<var>a_1</var> <var>b_1</var> <var>w_1</var>
<var>:</var>
<var>a_M</var> <var>b_M</var> <var>w_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3 3
1 0 1 2
1 2 10
2 3 20
2 4 50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>60
</pre>
<p><var>G'</var> will only be connected when Vertex <var>2</var> is painted in Color <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2 4
0 0 0 0 0
1 2 10
2 3 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Regardless of how Ringo paints the vertices, two edges is not enough to connect four vertices as one.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9 12 9
1 2 3 4 5 6 7 8 9
6 9 9
8 9 6
6 7 85
9 5 545631016
2 1 321545
1 6 33562944
7 3 84946329
9 7 15926167
4 7 53386480
5 8 70476
4 6 4549
4 8 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>118901402
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>18 37 12
5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1
17 1 1
11 16 7575
11 15 9
10 10 289938980
5 10 17376
18 4 1866625
8 11 959154208
18 13 200
16 13 2
2 7 982223
12 12 9331
13 12 8861390
14 13 743
2 10 162440
2 4 981849
7 9 1
14 17 2800
2 7 7225452
3 7 85
5 17 4
2 13 1
10 3 45
1 15 973
14 7 56553306
16 17 70476
7 18 9
9 13 27911
18 14 7788322
11 11 8925
9 13 654295
2 10 9
10 1 545631016
3 4 5
17 12 1929
2 11 57
1 5 4
1 17 7807368
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>171
</pre></section>
</div>
</span> |
p00012 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>A Point in a Triangle</H1>
<p>
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain.
</p>
<p>
Write a program which prints "<span>YES</span>" if a point $P$ $(x_p, y_p)$ is in the triangle and "<span>NO</span>" if not.
</p>
<!--
<p>
You can suppose that P is never on the points nor sides of the triangle.
</p>
-->
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset consists of:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_p$ $y_p$<br/>
</p>
<p>
All the input are real numbers. Input ends with EOF. The number of datasets is less than or equal to 100.
</p>
<h2>Constraints</h2>
<p>
You can assume that:
</p>
<ul>
<li>$ -100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \leq 100$</li>
<li>1.0 $\leq$ Length of each side of a tringle</li>
<li>0.001 $\leq$ Distance between $P$ and each side of a triangle</li>
</ul>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5
0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
p00442 |
<H1>ææªã®èšè
</H1>
<h2>åé¡</h2>
<p>
ããªã㯠JOI æ°è瀟ã®èšè
ã§ããïŒã¹ããŒãèšäºãæ
åœããŠããïŒ
</p>
<p>
æšæ¥ãŸã§ã«ïŒã¯ãã¢ãã¢ã§ã¯ïŒn åã®ãµãã«ãŒããŒã ã«ããç·åœãã®ãªãŒã°æŠãè¡ãããïŒå€§äŒå®è¡å§å¡äŒã¯ïŒè©ŠåçµæãšèŠå®ã«åºã¥ãåããŒã ã« 1 äœãã n äœãŸã§ã®é äœãã€ããããã§ããïŒããªãã«ã¯ïŒäžéšã®è©Šåã®åæãšãšãã«ïŒæ¬¡ã®æ
å ±ãäŒããããïŒ
<br/>
<b>æ
å ± 1</b> åŒãåãã®è©Šåã¯ãªãã£ãïŒ<br/>
<b>æ
å ± 2</b> å
šãŠã®ããŒã ã«ç°ãªãé äœãã€ããïŒ<br/>
<b>æ
å ± 3</b> å
šãŠã® 1 ≤ a < b ≤ n ã«å¯ŸãïŒa äœã®ããŒã ãš b äœã®ããŒã ã®è©Šåã«ãããŠïŒå¿
ã a äœã®ããŒã ãåå©ããïŒ
<br/>
</p>
<p>
ããªãã¯èšäºãäœæããããã«ïŒäžéšã®è©Šåã®åæãšïŒäŒããããæ
å ± 1 3 ãããšã«ïŒé äœè¡šãæšæž¬ããããšã«ããïŒ
</p>
<p>
å
¥åãšããŠäžéšã®è©Šåã®åæãäžãããããšãïŒäŒããããæ
å ±ã«é©åããé äœè¡šã 1 ã€åºåããããã°ã©ã ãäœãïŒãŸãïŒåºåããé äœè¡šä»¥å€ã«ïŒäŒããããæ
å ±ã«é©åããé äœè¡šãååšãããã©ãããå€å®ããïŒ
</p>
<p>
ããã§ïŒé äœè¡šãšã¯ 1 äœãã n äœã®é ã«ããŒã ã䞊ã¹ããã®ã®ããšãããïŒ
</p>
<h2>äŸ</h2>
<b>
äŸ1 (æ
å ±ã«é©åããé äœè¡šã 1 ã€ãããªãå Žå)
</b>
<p>
ããŒã æ°ã4ã§ïŒåããŒã ã«1ãã4ãŸã§ã®çªå·ãä»ããããŠããïŒåæã次ã®è¡šã§äžããããŠãããšããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_worstSportswriter1">
</center><br/>
<p>
i è¡ j åãâã®ãšãã¯ïŒçªå· i ã®ããŒã ãšçªå· j ã®ããŒã ã®è©Šåã«ãããŠïŒçªå· i ã®ããŒã ãåå©ããããšãæå³ããïŒãŸãïŒÃã®ãšãã¯ïŒçªå· j ã®ããŒã ãåå©ããããšãæå³ããïŒ? ã¯åæãäžããããŠããªãããšãæå³ããïŒãã®ãšãïŒäŒããããæ
å ±ã«é©åããé äœè¡šã¯æ¬¡ã® 1 ã€ãããªã
</p>
<center>
<table>
<tr><td>
1 äœ çªå· 3 ã®ããŒã <br/>
2 äœ çªå· 4 ã®ããŒã <br/>
3 äœ çªå· 1 ã®ããŒã <br/>
4 äœ çªå· 2 ã®ããŒã <br/>
</td></tr>
</table>
</center>
<br/>
<b>
äŸ2 (æ
å ±ã«é©åããé äœè¡šãè€æ°ååšããå Žå)
</b>
<p>
ããŒã æ°ã3ã§ïŒåããŒã ã«1ãã3ãŸã§ã®çªå·ãä»ããããŠããïŒåæã次ã®è¡šã§äžããããŠãããšããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_worstSportswriter2">
</center><br/>
<p>
ãã®ãšãïŒäŒããããæ
å ±ã«é©åããé äœè¡šã¯ïŒæ¬¡ã® 2 ã€ã§ããïŒ
</p>
<center>
<table>
<tr>
<td width="200">
1 äœ çªå· 2 ã®ããŒã <br/>
2 äœ çªå· 1 ã®ããŒã <br/>
3 äœ çªå· 3 ã®ããŒã <br/>
</td>
<td width="200">
1 äœ çªå· 2 ã®ããŒã <br/>
2 äœ çªå· 3 ã®ããŒã <br/>
3 äœ çªå· 1 ã®ããŒã <br/>
</td>
</tr>
</table>
</center>
<h2>å
¥å</h2>
<p>
<!--å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠input.txt ã§ããïŒ-->
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
1 è¡ç®ã«ã¯ïŒãµãã«ãŒããŒã ã®åæ° n ãæžãããŠããïŒåããŒã ã«ã¯ïŒ1 ãã n ãŸã§ã®çªå·ãä»ããããŠããïŒ
</p>
<p>
2 è¡ç®ã«ã¯ïŒäžãããã詊åã®åæã®åæ° m ãæžãããŠããïŒ
</p>
<p>
3 è¡ç®ãã m + 2 è¡ç®ã¯è©Šåã®åæã衚ãïŒåè¡ã¯ç©ºçœã§åºåããã 2 ã€ã®æŽæ° i, j ãå«ã¿ïŒçªå· i ã®ããŒã ãçªå· j ã®ããŒã ã«åå©ããããšã衚ãïŒ
</p>
<p>
n, m 㯠1 ≤ n ≤ 5000, 1 ≤ m ≤ 100000 ãã¿ããïŒ
</p>
<p>
æ¡ç¹ã®éã«çšãããã¹ãããŒã¿ã®ãã¡ïŒ30% 㯠1 ≤ n ≤ 7, 1 ≤ m ≤ 15 ãã¿ããïŒãŸãïŒ60% 㯠1 ≤ n ≤ 100, 1 ≤ m ≤ 2000 ãã¿ããïŒ
</p>
<h2>åºå</h2>
<!--
<p>
åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠output.txt ã§ããïŒ
</p>
-->
<p>
åºå<!--ãã¡ã€ã«-->㯠n + 1 è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ãã n è¡ç®ãŸã§ã® n è¡ã«ã¯ïŒäŒããããæ
å ±ã«é©åããé äœè¡šãåºåããïŒ
</p>
<p>
i è¡ç® (1 ≤ i ≤ n) ã« i äœã®ããŒã ã®çªå·ãåºåããïŒ
</p>
<p>
n + 1 è¡ç®ã«ã¯ïŒåºåããé äœè¡šä»¥å€ã«ïŒäŒããããæ
å ±ã«é©åããé äœè¡šãååšãããã©ãããè¡šãæŽæ°ãåºåããïŒããååšããªããã° 0 ãïŒååšããå Žå㯠1 ãåºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<p>
äŸ 1 ã«å¯Ÿå¿ããå
¥åºåã¯ä»¥äžã®éãã§ããïŒ
</p>
<h3>å
¥åäŸ 1</h3>
<pre>
4
5
1 2
3 1
3 2
3 4
4 1
</pre>
<h3>åºåäŸ 1</h3>
<pre>
3
4
1
2
0
</pre>
<br/>
<p>
äŸ 2 ã«å¯Ÿå¿ããå
¥åºåã¯ä»¥äžã®éãã§ããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
3
2
2 1
2 3
</pre>
<p>
ãã®å
¥åããŒã¿ã«å¯ŸããŠïŒæ¬¡ã® 2 éãã®åºåããŒã¿ãèããããïŒã©ã¡ããåºåããŠãããïŒ
</p>
<h3>åºåäŸ 2</h3>
<pre>
2
1
3
1
</pre>
<pre>
2
3
1
1
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02185 | <h2>D: Many Decimal Integers</h2>
<h3>åé¡</h3>
<p>æ°å (<var>0</var> ãã <var>9</var>) ã®ã¿ãããªãæåå <var>S</var> ãšãæ°å ãš <code>?</code> ã®ã¿ãããªãæåå <var>T</var> ãäžããããŸãã<var>S</var> ãš <var>T</var> ã¯åãé·ãã§ãã</p>
<p>
<var>T</var> å
ã«ååšããããããã® <code>?</code> ã«ã€ããŠã<var>0</var> ãã <var>9</var> ãŸã§ã®æ°åã®ãããã <var>1</var> ã€ã«å€æŽããæ°åã®ã¿ãããªãæåå <var>T'</var> ãäœãããšãèããŸãããã®ãšãã<var>f(T') \leq f(S)</var> ã§ããå¿
èŠããããŸããããã§ <var>f(t)</var> ã¯ãæåå <var>t</var> ã <var>10</var> 鲿°ãšããŠèªãã ãšãã®æŽæ°å€ãè¿ã颿°ãšããŸãã
ãŸãã<var>T'</var> ã®æäžäœã®æ¡ã«ããæ°å㯠<var>0</var> ã§ãã£ãŠããããã®ãšããŸãã
</p>
<p>ããåŸãæåå <var>T'</var> ãã¹ãŠã«ã€ããŠã<var>f(T')</var> ã®å€ã®ç·åã <var>10^9+7</var> ã§å²ã£ãäœããæ±ããŠãã ããããªããæ¡ä»¶ãæºãã <var>T'</var> ãã²ãšã€ãååšããªãå Žå㯠<var>0</var> ãšçããŠãã ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>S</var>
<var>T</var>
</pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq |S| = |T| \leq 2 \times 10^5</var></li>
<li> <var>S</var> ã¯æ°å (<var>0</var> ãã <var>9</var>) ã®ã¿ãããªãæåå</li>
<li> <var>T</var> ã¯æ°åãš <code>?</code> ã®ã¿ãããªãæåå</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>æ¡ä»¶ãæºãã <var>T'</var> ã®ç·åã <var>10^9+7</var> ã§å²ã£ãäœããäžè¡ã«åºåããŠãã ããã</p>
<h3>å
¥åäŸ1</h3>
<pre>
73
6?
</pre>
<h3>åºåäŸ1</h3>
<pre>645</pre>
<p><var>T'</var> ãšããŠããåŸãæååã¯ã<var>60</var> ãã <var>69</var> ãŸã§ã® <var>10</var> éããããŸãããããã®åèšã¯ <var>645</var> ã§ãã</p>
<h3>å
¥åäŸ2</h3>
<pre>
42
?1
</pre>
<h3>åºåäŸ2</h3>
<pre>105</pre>
<p><var>T'</var> ã®æäžäœã®æ¡ã«ããæ°å㯠<var>0</var> ã§ãããããã<var>01</var> ãæ¡ä»¶ãæºãããŸãã</p>
<h3>å
¥åäŸ3</h3>
<pre>
1730597319
16??35??8?
</pre>
<h3>åºåäŸ3</h3>
<pre>502295105</pre>
<p><var>10^9 + 7</var> ã§å²ã£ãäœããæ±ããŠãã ããã</p>
|
p01603 |
<h2>ãããœ</h2>
<h2>Problem Statement</h2>
<p>ããã®ããã¯æ£æ©ã倧奜ãã ïŒéãæ©ããšæ°ããçºèŠãããïŒ</p>
<p>ããã®äœãçºã¯ <var>N</var> åã®åºå Žãš <var>N-1</var> æ¬ã®éãããªãïŒ<br />
éã¯ã¡ããã©äºã€ã®åºå Žãã€ãªãã§ããïŒæåãããããéã©ããã亀ãã£ããããªãïŒ</p>
<p>éã«ã¯ïŒæ©ãã®ã«ãããæé <var>t</var>ïŒåŸãããçºèŠã®åæ°ã®äžé <var>m</var>ïŒããã³ïŒçºèŠäžã€ãããã®äŸ¡å€ <var>v</var> ãæå®ãããŠããïŒ<br />
éãäžæ¹ã®ç«¯ããããäžæ¹ã®ç«¯ãŸã§æ©ãããšãïŒ<var>m</var> åç®ãŸã§ã®éè¡ã§ã¯äŸ¡å€ <var>v</var> ã®çºèŠãäžã€åŸããããïŒ<var>m+1</var> åç®ä»¥éã¯çºèŠãåŸãããªãïŒ</p>
<p>仿¥ãããã¯ïŒçºå
ã®æ£æ©ã«åºãããããã ïŒ<br />
ããã®æ£æ©ã¯åºå Ž 1 ããå§ãŸãïŒããã€ãã®é ( 0 æ¬ãããããªã ) ãéã£ãŠïŒæåŸã«åºå Ž 1 ã«æ»ã£ãŠããïŒãšããã«ãŒãããšãïŒ<br />
ãŸãïŒæ¥ãæ®ãããšå¯ããæ°æã¡ã«ãªãã®ã§ïŒããã¯æ£æ©æéã <var>T</var> 以äžã«ããããšæã£ãŠããïŒ</p>
<p>ããã®å人ã§ããããªãã®ä»äºã¯ïŒæ£æ©æéã <var>T</var> 以äžã§ããæ£æ©ã«ãŒãã«ãããŠïŒåŸãããçºèŠã®äŸ¡å€ã®ç·åã®æå€§å€ãæ±ããããšã§ããïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ</p>
<pre><var>N</var> <var>T</var>
<var>a_1</var> <var>b_1</var> <var>t_1</var> <var>m_1</var> <var>v_1</var>
<var>. . .</var>
<var>a_{N-1}</var> <var>b_{N-1}</var> <var>t_{N-1}</var> <var>m_{N-1}</var> <var>v_{N-1}</var></pre>
<p>å
¥åã® <var>i+1</var> è¡ç®ã¯ïŒåºå Ž <var>a_i</var> ãš <var>b_i</var> ãã€ãªãïŒéè¡æé <var>t_i</var>ïŒåŸãããçºèŠã®åæ°ã®äžé <var>m_i</var>ïŒçºèŠäžã€ãããã®äŸ¡å€ <var>v_i</var> ã®éã衚ããŠããïŒ</p>
<h2>Constraints</h2>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1 ⊠N ⊠300</var></li>
<li><var>1 ⊠T ⊠10^4</var></li>
<li><var>1 ⊠a_i, b_i ⊠N</var></li>
<li><var>1 ⊠t_i ⊠10^4</var></li>
<li><var>0 ⊠m_i ⊠10^4</var></li>
<li><var>1 ⊠v_i ⊠10^5</var></li>
<li>ã©ã®äºã€ã®åºå Žãéãéã£ãŠè¡ãæ¥ã§ããïŒ</li></ul>
<h2>Output</h2>
<p>åŸãããçºèŠã®äŸ¡å€ã®ç·åã®æå€§å€ã 1 è¡ã«åºåããïŒ</p>
<h2>Sample Input 1</h2>
<pre>4 5
1 2 1 4 7
2 3 1 2 77
2 4 1 2 777</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1568</pre>
<p>1â2â4â2â1 ãšç§»åããããšã§ïŒåèšã§äŸ¡å€ 7+777+777+7=1568 ã®çºèŠãåŸãããïŒ</p>
<h2>Sample Input 2</h2>
<pre>2 10000
1 2 1 10 1</pre>
<h2>Output for the Sample Input 2</h2>
<pre>10</pre>
<h2>Sample Input 3</h2>
<pre>5 15
1 2 3 2 1
2 3 3 2 1
1 4 8 2 777
1 5 1 3 10</pre>
<h2>Output for the Sample Input 3</h2>
<pre>32</pre>
|
p00911 |
<H1><font color="#000">Problem H: </font>Company Organization</H1>
<p>
You started a company a few years ago and fortunately it has been highly successful. As the growth of the company, you noticed that you need to manage employees in a more organized way, and decided to form several groups and assign employees to them.
</p>
<p>
Now, you are planning to form n groups, each of which corresponds to a project in the company. Sometimes you have constraints on members in groups. For example, a group must be a subset of another group because the former group will consist of senior members of the latter group, the members in two groups must be the same because current activities of the two projects are closely related, the members in two groups must not be exactly the same to avoid corruption, two groups cannot have a common employee because of a security reason, and two groups must have a common employee to facilitate collaboration.
</p>
<p>
In summary, by letting <i>X<sub>i</sub></i> (<i>i</i> = 1, ... , <i>n</i>) be the set of employees assigned to the <i>i</i>-th group, we have five types of constraints as follows.
</p>
<ol>
<li> <i>X<sub>i</sub></i> ⊆ <i>X<sub>j</sub></i></li>
<li> <i>X<sub>i</sub></i> = <i>X<sub>j</sub></i></li>
<li> <i>X<sub>i</sub></i> ≠ <i>X<sub>j</sub></i></li>
<li> <i>X<sub>i</sub></i> ∩ <i>X<sub>j</sub></i> = ∅</li>
<li> <i>X<sub>i</sub></i> ∩ <i>X<sub>j</sub></i> ≠ ∅</li>
</ol>
<p>
Since you have listed up constraints without considering consistency, it might be the case that you cannot satisfy all the constraints. Constraints are thus ordered according to their priorities, and you now want to know how many constraints of the highest priority can be satisfied.
</p>
<p>
You do not have to take ability of employees into consideration. That is, you can assign anyone to any group. Also, you can form groups with no employee. Furthermore, you can hire or fire as many employees as you want if you can satisfy more constraints by doing so.
</p>
<p>
For example, suppose that we have the following five constraints on three groups in the order of their priorities, corresponding to the first dataset in the sample input.
</p>
<ul>
<li><i>X</i><sub>2</sub> ⊆ <i>X</i><sub>1</sub></li>
<li><i>X</i><sub>3</sub> ⊆ <i>X</i><sub>2</sub></li>
<li><i>X</i><sub>1</sub> ⊆ <i>X</i><sub>3</sub></li>
<li><i>X</i><sub>1</sub> ≠ <i>X</i><sub>3</sub></li>
<li><i>X</i><sub>3</sub> ⊆ <i>X</i><sub>1</sub></li>
</ul>
<p>
By assigning the same set of employees to <i>X</i><sub>1</sub>, <i>X</i><sub>2</sub>, and <i>X</i><sub>3</sub>, we can satisfy the first three constraints. However, no matter how we assign employees to <i>X</i><sub>1</sub>, <i>X</i><sub>2</sub>, and <i>X</i><sub>3</sub>, we cannot satisfy the first four highest priority constraints at the same time. Though we can satisfy the first three constraints and the fifth constraint at the same time, the answer should be three.
</p>
<H2>Input</H2>
<p>
The input consists of several datasets. The first line of a dataset consists of two integers <i>n</i> (2 ≤ <i>n</i> ≤ 100) and <i>m</i> (1 ≤ <i>m</i> ≤ 10000), which indicate the number of groups and the number of constraints, respectively. Then, description of <i>m</i> constraints follows. The description of each constraint consists of three integers <i>s</i> (1 ≤ <i>s</i> ≤ 5), <i>i</i> (1 ≤ <i>i</i> ≤ <i>n</i>), and <i>j</i> (1 ≤ <i>j</i> ≤ <i>n</i>, <i>j</i> ≠= <i>i</i>), meaning a constraint of the <i>s</i>-th type imposed on the <i>i</i>-th group and the <i>j</i>-th group. The type number of a constraint is as listed above. The constraints are given in the descending order of priority.
</p>
<p>
The input ends with a line containing two zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, output the number of constraints of the highest priority satisfiable at the same time.
</p>
<H2>Sample Input</H2>
<pre>
4 5
1 2 1
1 3 2
1 1 3
3 1 3
1 3 1
4 4
1 2 1
1 3 2
1 1 3
4 1 3
4 5
1 2 1
1 3 2
1 1 3
4 1 3
5 1 3
2 3
1 1 2
2 1 2
3 1 2
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
4
4
2
</pre> |
p01253 |
<H1><font color="#000">Problem D:</font> Deadly Dice Game</H1>
<p>
T.I. Financial Group, a world-famous group of finance companies, has decided to hold an evil gambling
game in which insolvent debtors compete for special treatment of exemption from their debts.
</p>
<p>
In this game, each debtor starts from one cell on the stage called the Deadly Ring. The Deadly Ring
consists of N cells and each cell is colored black or red. Each cell is connected to exactly two other
adjacent cells and all the cells form a ring. At the start of the game, each debtor chooses which cell to
start. Then he rolls a die and moves on the ring in clockwise order by cells as many as the number of
spots shown on the upside of the die. This step is called a round, and each debtor repeats a round <i>T</i> times.
A debtor will be exempted from his debt if he is standing on a red cell after he finishes all the rounds.
On the other hand, if he finishes the game at a black cell, he will be sent somewhere else and forced to
devote his entire life to hard labor.
</p>
<p>
You have happened to take part in this game. As you are allowed to choose the starting cell, you want to
start from a cell that maximizes the probability of finishing the game at a red cell. Fortunately you can
bring a laptop PC to the game stage, so you have decided to write a program that calculates the maximum
winning probability.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets.
</p>
<p>
Each dataset consists of two lines. The first line contains two integers <i>N</i> (1 ≤ <i>N</i> ≤ 2000) and <i>T</i> (1 ≤ <i>T</i> ≤ 2000) in this order, delimited with a single space. The second line contains a string of <i>N</i> characters that
consists of characters â<span>R</span>â and â<span>B</span>â, which indicate red and black respectively. This string represents the
colors of the cells in clockwise order.
</p>
<p>
The input is terminated by a line with two zeros. This is not part of any datasets and should not be
processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the maximum probability of finishing the game at a red cell in one line. Your
program may output an arbitrary number of digits after the decimal point, provided that the absolute
error does not exceed 10<sup>-8</sup>.
</p>
<H2>Sample Input</H2>
<pre>
6 1
RBRBRB
10 1
RBBBRBBBBB
10 2
RBBBRBBBBB
10 10
RBBBBBBBBB
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.50000000
0.33333333
0.22222222
0.10025221
</pre>
|
p04051 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p>
<p>This time, he will make one serving of <em>Skewer Meal</em>.</p>
<p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper.
All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p>
<p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper.
(Remaining Skewer Meal Packs will not be used.)
Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p>
<p>(See the image in the Sample section for better understanding.)</p>
<p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different.
Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2âŠNâŠ200,000</var></li>
<li><var>1âŠA_iâŠ2000, 1âŠB_iâŠ2000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 1
1 1
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>26
</pre>
<p>The <var>26</var> ways of making a Skewer Meal are shown below.
Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer.
Brown and green rectangles represent pieces of beef and green pepper, respectively.</p>
<div style="text-align: center;">
<img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png">
</img></div></section>
</div>
</span> |
p03794 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree <var>T</var> with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>.
For each <var>1 †i †N - 1</var>, the <var>i</var>-th edge connects vertices <var>a_i</var> and <var>b_i</var>.</p>
<p>Snuke is constructing a directed graph <var>T'</var> by arbitrarily assigning direction to each edge in <var>T</var>. (There are <var>2^{N - 1}</var> different ways to construct <var>T'</var>.)</p>
<p>For a fixed <var>T'</var>, we will define <var>d(s,\ t)</var> for each <var>1 †s,\ t †N</var>, as follows:</p>
<ul>
<li><var>d(s,\ t) = </var>(The number of edges that must be traversed against the assigned direction when traveling from vertex <var>s</var> to vertex <var>t</var>)</li>
</ul>
<p>In particular, <var>d(s,\ s) = 0</var> for each <var>1 †s †N</var>.
Also note that, in general, <var>d(s,\ t) â d(t,\ s)</var>.</p>
<p>We will further define <var>D</var> as the following:</p>
<div style="text-align: center;">
<img alt="3d2f3f88e8fa23f065c04cd175c14ebf.png" src="https://atcoder.jp/img/mujin/3d2f3f88e8fa23f065c04cd175c14ebf.png">
</img></div>
<p>Snuke is constructing <var>T'</var> so that <var>D</var> will be the minimum possible value.
How many different ways are there to construct <var>T'</var> so that <var>D</var> will be the minimum possible value, modulo <var>10^9 + 7</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †1000</var></li>
<li><var>1 †a_i,\ b_i †N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_{N - 1}</var> <var>b_{N - 1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different ways to construct <var>T'</var> so that <var>D</var> will be the minimum possible value, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2
1 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The minimum possible value for <var>D</var> is <var>1</var>.
There are two ways to construct <var>T'</var> to achieve this value, as shown in the following figure:</p>
<p><img alt="" src="https://atcoder.jp/img/mujin/de49901ddf69d8565fde5b6870afb595.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2
2 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
<p>The minimum possible value for <var>D</var> is <var>2</var>.
There are six ways to construct <var>T'</var> to achieve this value, as shown in the following figure:</p>
<p><img alt="" src="https://atcoder.jp/img/mujin/dcb377e8c7fe15d6dd0cb815dc57c41a.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2
1 3
1 4
2 5
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>14
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
2 4
2 5
8 3
10 7
1 6
2 8
9 5
8 6
10 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>102
</pre></section>
</div>
</span> |
p02886 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It's now the season of TAKOYAKI FESTIVAL!</p>
<p>This year, <var>N</var> takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The <em>deliciousness</em> of the <var>i</var>-th takoyaki is <var>d_i</var>.</p>
<p>As is commonly known, when you eat two takoyaki of deliciousness <var>x</var> and <var>y</var> together, you restore <var>x \times y</var> health points.</p>
<p>There are <var>\frac{N \times (N - 1)}{2}</var> ways to choose two from the <var>N</var> takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these <var>\frac{N \times (N - 1)}{2}</var> values.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 \leq N \leq 50</var></li>
<li><var>0 \leq d_i \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>d_1</var> <var>d_2</var> <var>...</var> <var>d_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the <var>N</var> takoyaki served.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
</pre>
<p>There are three possible choices:</p>
<ul>
<li>Eat the first and second takoyaki. You will restore <var>3</var> health points.</li>
<li>Eat the second and third takoyaki. You will restore <var>2</var> health points.</li>
<li>Eat the first and third takoyaki. You will restore <var>6</var> health points.</li>
</ul>
<p>The sum of these values is <var>11</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
5 0 7 8 3 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>312
</pre></section>
</div>
</span> |
p03281 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>The number <var>105</var> is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive divisors are there between <var>1</var> and <var>N</var> (inclusive)?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is an integer between <var>1</var> and <var>200</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the count.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>105
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Among the numbers between <var>1</var> and <var>105</var>, the only number that is odd and has exactly eight divisors is <var>105</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p><var>1</var> has one divisor. <var>3</var>, <var>5</var> and <var>7</var> are all prime and have two divisors. Thus, there is no number that satisfies the condition.</p></section>
</div>
</span> |
p01746 |
<p>
ãã¬ãåã¯ïŒåæç¶æ
ã§ã¯åãããšã¯ã§ããªãïŒ<var>i</var> çªç®ã®ãã±ããã®å€æ®µã¯ <var>p<sub>i</sub></var> ã§ããïŒãããè²·ããšä»»æã® <var>(x, y)</var> ãšä»»æã®éè² å®æ° <var>t</var> ã«å¯Ÿã<var>(x, y)</var> ãã<var>(x + ta<sub>i</sub>, y + tb<sub>i</sub>)</var> ã«ç§»åããããšãã§ããããã«ãªãïŒãã¬ãåãå¹³é¢äžã®ä»»æã®äºç¹éã(ããã€ãã®ãã±ãããçµã¿åãããŠ) ç§»åã§ããããã«ãªãããã«è²·ããªããã°ãªããªããã±ããã®åèšéé¡ã®æå°å€ãæ±ããïŒ
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>n</var> ≤ 200000</li>
<li> â10<sup>9</sup> ≤ <var>a<sub>i</sub>, b<sub>i</sub></var> ≤ 10<sup>9</sup></li>
<li> 1 ≤ <var>p<sub>i</sub> ≤ 10<sup>9</sup></li>
<li> å
¥åã¯å
šãп޿°ã§ãã</li>
</ul>
<h2>Input</h2>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>p<sub>1</sub></var>
. . .
<var>a<sub>n</sub></var> <var>b<sub>n</sub></var> <var>p<sub>n</sub></var>
</pre>
<h2>Output</h2>
<p>
å¹³é¢äžã®ä»»æã®äºç¹éãç§»åã§ããããã«ãªãããã«è²·ããªããã°ãªããªããã±ããã®åèšéé¡ã®æå°å€ãåºåããïŒã§ããªãå Žåã¯-1 ãåºåããïŒ
</p>
<h2>Sample Input 1</h2>
<pre>
7
0 3 1
0 3 2
1 -1 2
0 0 1
-2 4 1
-4 0 1
2 1 2
</pre>
<p>
ããšãã°ãã±ãã1, 3, 6 ãè²·ããšããïŒ
</p>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<h2>Sample Input 2</h2>
<pre>
2
1 2 3
4 5 6
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre> |
p00854 |
<H1><font color="#000">Problem A:</font> And Then There Was One</H1>
<p>
Letâs play a stone removing game.
</p>
<p>
Initially, <i>n</i> stones are arranged on a circle and numbered 1, ... , <i>n</i> clockwise (Figure 1). You are also given two numbers <i>k</i> and <i>m</i>. From this state, remove stones one by one following the rules explained below, until only one remains. In step 1, remove stone <i>m</i>. In step 2, locate the <i>k</i>-th next stone clockwise from <i>m</i> and remove it. In subsequent steps, start from the slot of the stone removed in the last step, make <i>k</i> hops clockwise on the remaining stones and remove the one you reach. In other words, skip (<i>k</i> - 1) remaining stones clockwise and remove the next one. Repeat this until only one stone is left and answer its number.
</p>
<p>
For example, the answer for the case <i>n</i> = 8, <i>k</i> = 5, <i>m</i> = 3 is 1, as shown in Figure 1.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_andThenThereWasOne">
<p>
Figure 1: An example game
</p>
</center>
<p>
<b>Initial state</b>: Eight stones are arranged on a circle.
</p>
<p>
<b>Step 1</b>: Stone 3 is removed since <i>m</i> = 3.
</p>
<p>
<b>Step 2</b>: You start from the slot that was occupied by stone 3. You skip four stones 4, 5, 6 and 7 (since <i>k</i> = 5), and remove the next one, which is 8.
</p>
<p>
<b>Step 3</b>: You skip stones 1, 2, 4 and 5, and thus remove 6. Note that you only count stones that are still on the circle and ignore those already removed. Stone 3 is ignored in this case.
</p>
<p>
<b>Steps 4-7</b>: You continue until only one stone is left. Notice that in later steps when only a few stones remain, the same stone may be skipped multiple times. For example, stones 1 and 4 are skipped twice in step 7.
</p>
<p>
<b>Final State</b>: Finally, only one stone, 1, is on the circle. This is the final state, so the answer is 1.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets each of which is formatted as follows.
</p>
<pre>
<i>n k m</i>
</pre>
<p>
The last dataset is followed by a line containing three zeros. Numbers in a line are separated by a single space. A dataset satisfies the following conditions.
</p>
<center>
<p>
2 ≤ <i>n</i> ≤ 10000, 1 ≤ <i>k</i> ≤ 10000, 1 ≤ <i>m</i> ≤ <i>n</i>
</p>
</center>
<p>
The number of datasets is less than 100.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing the stone number left in the final state. No extra characters such as spaces should appear in the output.
</p>
<H2>Sample Input</H2>
<pre>
8 5 3
100 9999 98
10000 10000 10000
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
93
2019
</pre>
|
p02869 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are positive integers <var>N</var> and <var>K</var>.</p>
<p>Determine if the <var>3N</var> integers <var>K, K+1, ..., K+3N-1</var> can be partitioned into <var>N</var> triples <var>(a_1,b_1,c_1), ..., (a_N,b_N,c_N)</var> so that the condition below is satisfied. Any of the integers <var>K, K+1, ..., K+3N-1</var> must appear in exactly one of those triples.</p>
<ul>
<li>For every integer <var>i</var> from <var>1</var> to <var>N</var>, <var>a_i + b_i \leq c_i</var> holds.</li>
</ul>
<p>If the answer is yes, construct one such partition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq K \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is impossible to partition the integers satisfying the condition, print <code>-1</code>. If it is possible, print <var>N</var> triples in the following format:</p>
<pre><var>a_1</var> <var>b_1</var> <var>c_1</var>
<var>:</var>
<var>a_N</var> <var>b_N</var> <var>c_N</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre></section>
</div>
</span> |
p01316 |
<h1><font color="#000000">Problem C:</font> Differential Pulse Code Modulation</h1>
<!--
<h3><U>å·®åãã«ã¹ç¬Šå·å€èª¿</U></h3>
-->
<p>å·®åãã«ã¹ç¬Šå·å€èª¿ã¯äž»ã«é³å£°ä¿¡å·ãå§çž®ããéã«çšããããå§çž®ææ³ã®äžã€ã§ããïŒ</p>
<p>é³å£°ä¿¡å·ã¯èšç®æ©äžã§ã¯æŽæ°å(ã€ã³ãã«ã¹å)ãšããŠæ±ãããïŒæŽæ°åã¯å
¥åä¿¡å·ãäžå®æéééã§æšæ¬å(ãµã³ããªã³ã°)ãïŒæ¯å¹
ãèšé²ãããã®ã§ããïŒäžè¬ã«ãã®æŽæ°åã¯ååŸã®å€ãè¿ããšããåŸåãããïŒãããå©çšãïŒååŸã®å€ã®å·®åã笊å·åãïŒå§çž®çãåäžãããã®ãå·®åãã«ã¹ç¬Šå·å€èª¿ã§ããïŒ</p>
<p>æ¬åé¡ã§ã¯å·®åã®å€ããããããå®ããããå€ã®éåããéžã¶ããšãèããïŒãã®å€ã®éåãã³ãŒãããã¯ãšåŒã¶ããšã«ããïŒåŸ©å·ååŸã®é³å£°ä¿¡å·
<i>y<sub>n</sub></i> ã¯ä»¥äžã®åŒã§å®ããããïŒ</p>
<blockquote><i>y</i><sub><i>n</i></sub> = <i>y</i><sub><i>n</i>
- 1</sub> + <i>C</i>[<i>k</i><sub><i>n</i></sub>]</blockquote>
<p>ããã§ <i>k</i><sub><i>n</i></sub> ã¯ããã°ã©ã ã«ãã£ãŠåºåãããåºåç³»åïŒ <i>C</i>[<i>j</i>]
ã¯ã³ãŒãããã¯ã® <i>j</i> çªç®ã®å€ã§ããïŒãã ã <i>y</i><sub><i>n</i></sub>
ã¯å ç®ã«ãã£ãŠ0æªæºã®å€ãšãªã£ãå Žåã¯0ã«ïŒ255ãã倧ããå€ãšãªã£ãå Žåã¯255ã«ããããäžžããããïŒãŸãïŒ <i>y</i><sub>0</sub>
ã®å€ã¯128ãšããïŒ</p>
<p>ããªãã®ä»äºã¯ïŒå
¥åä¿¡å·ãšã³ãŒãããã¯ãäžãããããšãã«ïŒå
ã®å
¥åä¿¡å·ãšåŸ©å·ååŸã®åºåä¿¡å·ãšã®å·®ã®äºä¹åãæå°ãšãªãããã«åºåç³»åãéžãã§ïŒãã®ãšãã®å·®ã®äºä¹åãåºåããããã°ã©ã ãæžãããšã§ããïŒ</p>
<p>äŸãã°ïŒã³ãŒãããã¯ãšã㊠<i>{4, 2, 1, 0, -1, -2, -4}</i> ãšããå€ã®ã»ããã䜿ã£ãŠ
<i>131, 137</i> ãšããåãå§çž®ããå ŽåïŒ
<i>y</i><sub><i>0</i></sub><i> = 128</i>,
<i>y</i><sub><i>1</i></sub><i> = 128 + 4 = 132</i>,
<i>y</i><sub><i>2</i></sub><i> = 132 + 4 = 136</i> ãšããåã«å§çž®ãããš
äºä¹åã <i>(131 - 132)^2 + (137 - 136)^2 = 2</i> ãšæå°ã«ãªãïŒ</p>
<p>ãŸãïŒåããã³ãŒãããã¯ãšã㊠<i>{4, 2, 1, 0, -1, -2, -4}</i> ãšããå€ã®ã»ããã䜿ã£ãŠ
<i>131, 123</i> ãšããåãå§çž®ããå ŽåïŒ
<i>y</i><sub><i>0</i></sub><i> = 128</i>,
<i>y</i><sub><i>1</i></sub><i> = 128 + 1 = 129</i>,
<i>y</i><sub><i>2</i></sub><i> = 129 - 4 = 125</i> ãšïŒå
çšã®äŸãšã¯éã£ãŠ
<i>131</i> ã«ããè¿ã¥ã <i>+2</i> ãæ¡çšããªãæ¹ã
<i>(131 - 129) ^ 2 + (123 - 125) ^ 2 = 8</i>
ãšããããå°ããªäºä¹åãåŸãããïŒ</p>
<p>äžèš 2ã€ã®äŸã¯ sample input ã®æåã® 2äŸã§ããïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒåããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã«ç€ºããšããã§ããïŒ</p>
<blockquote><i>N</i> <i>M</i><br />
<i>C<sub></sub>1</i><br />
<i>C<sub>2</sub></i><br />
...<br />
<i>C<sub>M</sub></i><br />
<i>x<sub>1</sub></i><br />
<i>x<sub>2</sub></i><br />
...<br />
<i>x<sub>N</sub></i><br />
</blockquote>
<p>æåã®è¡ã¯ïŒå
¥åããŒã¿ã»ããã®å€§ãããèŠå®ããïŒ <i>N</i> ã¯å§çž®ããå
¥åä¿¡å·ã®é·ã(ãµã³ãã«æ°)ã§ããïŒ <i>M</i>
ã¯ã³ãŒãããã¯ã«å«ãŸããå€ã®åæ°ã§ããïŒ <i>N</i> åã³ <i>M</i> ã¯1 ≤ <i>N</i> ≤ 20000ïŒ1
≤ <i>M</i> ≤ 16ãæºããïŒ</p>
<p>ããã«ç¶ã <i>M</i> è¡ã¯ïŒã³ãŒãããã¯ã®èšè¿°ã§ããïŒ <i>C<sub>i</sub></i> ã¯ã³ãŒãããã¯ã«å«ãŸãã
<i>i</i> çªç®ã®å€ã衚ãïŒ <i>C<sub>i</sub></i> ã¯-255 ≤ <i>C<sub>i</sub></i>
≤ 255ãæºããïŒ</p>
<p>ããã«ç¶ã <i>N</i> è¡ã¯ïŒå
¥åä¿¡å·ã®èšè¿°ã§ããïŒ <i>x<sub>i</sub></i> ã¯å
¥åä¿¡å·ãè¡šãæŽæ°åã® <i>i</i>
çªç®ã®å€ã§ããïŒ <i>x<sub>i</sub></i> ã¯0 ≤ <i>x<sub>i</sub></i> ≤ 255ãæºããïŒ</p>
<p>ããŒã¿ã»ããã®äžã®å
¥åé
ç®ã¯ïŒãã¹ãп޿°ã§ããïŒå
¥åã®çµãã¯ïŒç©ºçœæå1åã§åºåããã2åã®ãŒãã®ã¿ãããªãè¡ã§è¡šãããïŒ</p>
<h2>Output</h2>
<p>å
¥åã®åããŒã¿ã»ããã«å¯ŸããŠïŒ å
ã®å
¥åä¿¡å·ãšåŸ©å·ååŸã®åºåä¿¡å·ãšã®å·®ã®äºä¹åã®æå°å€ãäžè¡ã§åºåããïŒ</p>
<h2>Sample Input</h2>
<pre>
2 7
4
2
1
0
-1
-2
-4
131
137
2 7
4
2
1
0
-1
-2
-4
131
123
10 7
-4
-2
-1
0
1
2
4
132
134
135
134
132
128
124
122
121
122
5 1
255
0
0
0
0
0
4 1
0
255
0
255
0
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
2
8
0
325125
65026
</pre>
|
p00157 |
<H1>ãããªã§ãŒã·ã«</H1>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_russianDolls">
</center>
<p>
ãããªã§ãŒã·ã«ãšã¯å¥³æ§åãããã©ã£ãæšè£œã®äººåœ¢ã§ããã·ã¢ã®ä»£è¡šçãªæ°èžåã§ãããããªã§ãŒã·ã«ã¯ã倧ããªäººåœ¢ã®äžã«ããããå°ããªäººåœ¢ãå
¥ã£ãŠããå
¥ãåæ§é ã«ãªã£ãŠããã倧ããã®ç°ãªãè€æ°ã®äººåœ¢ã§æ§æãããŠããŸãããã®ãããªå
¥ãåæ§é ã«ãããããå人圢ã®èŽäœã¯äžäžã§åå²ã§ããçç¶ã®æ§é ã«ãªã£ãŠããŸãããããªã§ãŒã·ã«ã¯è·äººã®æã§æäœãããããããäžã€äžã€ã®äººåœ¢ã¯äžçã«äžã€ãããªãéåžžã«è²Žéãªãã®ã«ãªããŸãã
</p>
<p>
å
åŒã§ããäžéåãšæ¬¡éåã¯ããããªã§ãŒã·ã«ã§éã¶ã®ã倧奜ãã§ãåèªããããã1çµã®ãããªã§ãŒã·ã«ãæã£ãŠããŸãããäžéåã®ãããªã§ãŒã·ã«ã¯ <var>n</var> åã®äººåœ¢ããæ§æãããŠãããæ¬¡éåã®ãããªã§ãŒã·ã«ã¯ <var>m</var> åã®äººåœ¢ããæ§æãããŠããŸãã
</p>
<p>
ããæ¥ã奜å¥å¿ãæºçãªäžéåã¯ãããã2çµã®ãããªã§ãŒã·ã«ã«å«ãŸãã人圢ãã¡ãçµã¿åãããŠãããå€ãã®äººåœ¢ãå«ãæ°ããªãããªã§ãŒã·ã«ãäœããªãããšèããŸãããã€ãŸãã<var>n + m</var> åã®äººåœ¢ã䜿ãã<var>k</var> åã®äººåœ¢ãããªãïŒçµã®ãããªã§ãŒã·ã«ãäœãããšã詊ã¿ãã®ã§ãã<var>n</var> ãš <var>m</var> ã®å€§ããæ¹ããã <var>k</var> ã倧ããããããšãã§ããã°ãäžéåã®ç®çã¯éæãããŸãã
</p>
<p>
å
åŒã¯2人仲è¯ããã©ã®ããã«äººåœ¢ãçµã¿åãããã° <var>k</var> ã®å€ãæå€§ã«ã§ããããèããŸããããããã幌ã2人ã«ãšã£ãŠãã®åé¡ã¯ããŸãã«ãé£ããã®ã§ã幎äžã®ããªãã¯ããã°ã©ã ãäœæããŠåŒãã¡ãå©ããããšã«ããŸããã
</p>
<p>
äžéåãšæ¬¡éåã®ãããªã§ãŒã·ã«ã®äººåœ¢ã®æ
å ±ãå
¥åãšããæ°ããªãããªã§ãŒã·ã«ãå«ãäººåœ¢ã®æ° <var>k</var> ãåºåããããã°ã©ã ãäœæããŠäžãããå
¥åããã人圢ã«å€§ãããåããã®ã¯ååšããŸããããŸãã人圢ãé«ã <var>h</var> ååŸ <var>r</var> ã®åæ±ãšã¿ãªããå Žåãé«ã<var>h</var>ãååŸ <var>r</var> ã®äººåœ¢ãå«ãããšã®ã§ãã人圢㯠<var>x < h </var> ã〠<var>y < r</var> ãæºããé«ã <var>x</var> ååŸ <var>y</var> ã®äººåœ¢ã§ãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>h<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>h<sub>2</sub></var> <var>r<sub>2</sub></var>
:
<var>h<sub>n</sub></var> <var>r<sub>n</sub></var>
<var>m</var>
<var>h<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>h<sub>2</sub></var> <var>r<sub>2</sub></var>
:
<var>h<sub>m</sub></var> <var>r<sub>m</sub></var>
</pre>
<p>
ïŒè¡ç®ã«äžéåã®ãããªã§ãŒã·ã«ã®äººåœ¢ã®æ° <var>n</var> (<var>n</var> ≤ 100)ãç¶ã <var>n</var> è¡ã«äžéåã®ç¬¬ <var>i</var> ã®äººåœ¢ã®é«ã <var>h<sub>i</sub></var> ãšååŸ <var>r<sub>i</sub></var> (<var>h<sub>i</sub></var>, <var>r<sub>i</sub></var> < 1000) ãäžããããŸãã
</p>
<p>
ç¶ãè¡ã«äºéåã®ãããªã§ãŒã·ã«ã®äººåœ¢ã®æ° <var>m</var> (<var>m</var> ≤ 100)ãç¶ã <var>m</var> è¡ã«äºéåã®ç¬¬ <var>i</var> ã®äººåœ¢ã®é«ã <var>h<sub>i</sub></var> ãšååŸ <var>r<sub>i</sub></var> (<var>h<sub>i</sub></var>, <var>r<sub>i</sub></var> < 1000) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶ããªãã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«æ°ããªãããªã§ãŒã·ã«ãå«ãäººåœ¢ã®æ° <var>k</var> ãåºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
6
1 1
4 3
6 5
8 6
10 10
14 14
5
2 2
5 4
6 6
9 8
15 10
4
1 1
4 3
6 5
8 6
3
2 2
5 4
6 6
4
1 1
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
9
6
8
</pre>
|
p00507 |
<H1>åé¡ 3</H1>
<br/>
<p>
ãå
¥åãã¡ã€ã«ã®ïŒè¡ç®ã«æ£æŽæ° n ïŒnâ§3ïŒãæžããŠããïŒ
ã€ã¥ã n è¡ã«ç°ãªãæ£æŽæ° a<sub>1</sub>, ..., a<sub>n</sub> ã
ïŒã€ãã€æžããŠããïŒ
a<sub>1</sub>, ..., a<sub>n</sub> ããç°ãªãïŒåãéžãã§äœããã
é åãïŒæ°ãšããŠèŠãŠïŒå°ããé ã«äžŠã¹ããšãïŒ
ïŒçªç®ã«æ¥ããã®ãåºåããïŒ
</p>
<p>
ããã ãïŒ
äŸãã°ïŒa<sub>1</sub> = 1ïŒa<sub>4</sub> = 11 ã®ãããªå ŽåãïŒ
a<sub>1</sub>a<sub>4</sub> ãš a<sub>4</sub>a<sub>1</sub> ã¯ç°ãªãé åãšã¿ãªãïŒ
ãŸãïŒ
1âŠa<sub>i</sub>âŠ10000 (i=1, ..., n) ã〠3âŠnâŠ10<sup>4</sup> ã§ããïŒ
</p>
<p>
<!--ãå
¥åãã¡ã€ã«ã®æ¹è¡ã³ãŒã㯠CR+LF ã§ããïŒ
ãŸãïŒ-->
åºåãã¡ã€ã«ã«ãããŠã¯ïŒ
åºåã®æåŸã«ãæ¹è¡ã³ãŒããå
¥ããããšïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
3
2
7
5
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
52
</pre>
<br>
<h3>å
¥åäŸïŒ</h3>
<pre>
4
17
888
1
71
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
171
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02214 | <span class="lang">
<span class="lang-ja">
<h1>C: ãµããã³ã¯ãšãª</h1>
<div class="part">
<section>
<h3>å顿</h3><p>åçŽç¡åã°ã©ãã§ãä»»æã®èŸºãé«ã
$1$ ã€ã®åçŽéè·¯ã«ããå«ãŸããªããããªãã®ããµããã³ã°ã©ããšåŒã¶ããšã«ããŸãã</p>
<p>$N$ é ç¹ $M$ 蟺ã®é£çµãªãµããã³ã°ã©ã $G$ ãäžããããŸãã</p>
<p>åé ç¹ã¯ $1$ ãã $N$ ãŸã§çªå·ãä»ããŠããŸãã</p>
<p>ãŸãã$i$ åç®ã®èŸºã¯é ç¹ $a_i$ ãšé ç¹ $b_i$ ãçµãã§ãããã³ã¹ã㯠$c_i$ ã§ãã</p>
<p>ã°ã©ã $G$ äžã®åçŽãã¹ã®ã³ã¹ããããã®ãã¹äžã«å«ãŸããå
šãŠã®èŸºã®ã³ã¹ãã® XOR ãšå®ããŸãã</p>
<p>以äžã®ãããªåœ¢åŒã® $Q$ åã®ã¯ãšãªã«çããŠãã ããã</p>
<ul>
<li><code>x_i y_i k_i</code> â é ç¹ $x_i$ ãšé ç¹ $y_i$ ãç¹ããã¹ãŠã®åçŽãã¹ã®ã³ã¹ããåæããŠéè€ããå€ãé€ããå°ããé ã«äžŠã¹ãåã $d = d_1, d_2, ... , d_L$ ãšãããšãã«ã$d_{k_i}$ ãæ±ããããã ãããã®ã³ã¹ãå $d$ ã®é·ã $L$ ã $k_i$ ããå°ããå Žå㯠$-1$ ãšããã</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>å¶çŽ</h3><ul>
<li>$2 \leq N \leq 10^5$</li>
<li>$N - 1 \leq M \leq 2 \times 10^5$</li>
<li>$1 \leq a_i, b_i \leq N$</li>
<li>$a_i \neq b_i$</li>
<li>$0 \leq c_i < 2^{30}$</li>
<li>$1 \leq Q \leq 2 \times 10^5$</li>
<li>$1 \leq x_i, y_i \leq N$</li>
<li>$x_i \neq y_i$</li>
<li>$1 \leq k_i \leq 2^{30}$</li>
<li>äžããããã°ã©ãã¯é£çµãªãµããã³ã°ã©ãã§ããã</li>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
</ul>
</section>
</div>
<hr />
<div class="io-style">
<div class="part">
<section>
<h3>å
¥å</h3><p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>$N$ $M$
$a_1$ $b_1$ $c_1$
$a_2$ $b_2$ $c_2$
$:$
$a_M$ $b_M$ $c_M$
$Q$
$x_1$ $y_1$ $k_1$
$x_2$ $y_2$ $k_2$
$:$
$x_Q$ $y_Q$ $k_Q$
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºå</h3><p>$Q$ åã®ã¯ãšãªã®çããäžè¡ããšã«é çªã«åºåããã</p>
</section>
</div>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 1</h3><pre>4 4
1 2 1
1 3 8
3 2 0
1 4 7
4
1 2 1
2 1 2
1 4 1
3 4 1073741824
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 1</h3><pre>1
8
7
-1
</pre>
<ul>
<li>
<p>é ç¹ $1$ ããé ç¹ $2$ ãžã®åçŽãã¹ã¯ã蟺 $1$ ã®ã¿ãçµç±ãããã®ãšã蟺 $2, 3$ ãçµç±ãããã®ã§ãã³ã¹ãã¯ãããã $1$, $8$ ã§ãããªã®ã§ã$1$ ã€ãã®ã¯ãšãªã®çã㯠$1$ãšãªããŸãã</p>
</li>
<li>
<p>é ç¹ $2$ ããé ç¹ $1$ ãžã®åçŽãã¹ãäžèšãšåæ§ãªã®ã§ã $2$ ã€ç®ã®ã¯ãšãªã®çã㯠$8$ ãšãªããŸãã</p>
</li>
<li>
<p>é ç¹ $1$ ããé ç¹ $4$ ãžã®åçŽãã¹ã¯ã蟺 $4$ ã®ã¿ãçµç±ãããã®ã®ã¿ã§ãã³ã¹ã㯠$7$ ã§ãããªã®ã§ã$3$ ã€ç®ã®ã¯ãšãªã®çã㯠$7$ ãšãªããŸãã</p>
</li>
<li>
<p>é ç¹ $3$ ããé ç¹ $4$ ãžã®åçŽãã¹ã¯ã蟺 $2$, $4$ ãçµç±ãããã®ãšã蟺 $3$, $1$, $4$ ãçµç±ãããã®ã§ãã³ã¹ãã¯ãããã $15$, $6$ ã§ãã$1073741824$ çªç®ã«å°ããã³ã¹ãã¯ååšããªãã®ã§ã$4$ ã€ç®ã®ã¯ãšãªã®çã㯠$-1$ ãšãªããŸãã</p>
</li>
</ul>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 2</h3><pre>13 15
1 2 1
2 3 2
3 4 3
4 5 1
5 1 2
5 6 4
6 7 15
7 8 9
8 6 7
2 9 5
9 10 5
10 2 2
3 11 3
11 12 2
11 13 1
8
12 13 1
1 11 2
9 5 4
2 7 3
6 12 2
9 7 5
10 3 3
3 12 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 2</h3><pre>3
3
7
10
7
-1
2
-1
</pre></section>
</div>
</span>
</span>
|
p00229 |
<H1>倧åœãã!</H1>
<p>
ããã¥åŠå倧åŠéå±é«æ ¡ã®å€§é¿è¶³ãããåã¯ãã¹ããããã·ãŒã³ã§éã¶ããšã«ããŸããã
</p>
<p>
ãã®ãã·ãŒã³ã¯ãã¡ãã«ãæå
¥ãããšã3 ã€ã®ãªãŒã«ãå転ãå§ããåãªãŒã«ãèªåçã«æ¢ãŸããŸããéåžžã®1ã²ãŒã (éåžžã²ãŒã )㯠3 æã®ã¡ãã«ãæå
¥ãã峿ãæããšããã®å³æã«å¿ããŠæ¬¡ã®ãšããã¡ãã«ãåŸãããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bighit"><br/>
<br/>
</center>
<p>
å³æã®æãæ¹ã«ãã£ãŠã¯ç¹å¥ãªãµãŒãã¹ãéå§ãããŸãã 7 ã®å³æã 3 ã€æããšããã°ããŒãã¹ãå§ãŸããããŒãã¹ã²ãŒã ã 5 ã²ãŒã è¡ãããšãã§ããŸãããŸããBAR ã®å³æã 3 ã€æããšã¬ã®ã¥ã©ãŒããŒãã¹ãå§ãŸããããŒãã¹ã²ãŒã ã 3 ã²ãŒã è¡ãããšãã§ããŸãã
</p>
<p>
ã¹ã¿ãŒã®å³æã 3 ã€æããšç¡æã²ãŒã ãéå§ãããã¡ãã«ãåŸãããšã¯ã§ããŸããããæ¬¡ã®ã²ãŒã ãã¡ãã«ã®æå
¥ãªãå§ããããšãã§ããŸãã
</p>
<p>
ããŒãã¹ã²ãŒã äžã¯ 1 ã²ãŒã ããã 2 æã®ã¡ãã«ãæå
¥ãããšãèªåã§ãããŠã®å³æã 3 ã€æããã¡ãã«ã 15 æåŸãããšãã§ããŸãã
</p>
<p>
倧é¿è¶³å㯠100 æã®ã¡ãã«ãæã£ãŠãã·ãŒã³ã§éã³å§ããŸããããã°ããéã³ãéåžžã²ãŒã ã«ãªã£ãç¶æ
ã§çµäºããŸãããæå
ã«æ®ã£ãã¡ãã«ã¯äœæãšãªã£ãã§ããããã
</p>
<p>
ãã¬ã€æ
å ±ãå
¥åãšããæå
ã«æ®ã£ãã¡ãã«ã®æ°ãåºåããããã°ã©ã ãäœæããŠäžããã ãã¬ã€æ
å ±ãšããŠãããã°ããŒãã¹ã®åæ° <var>b</var>ãã¬ã®ã¥ã©ãŒããŒãã¹ã®åæ° <var>r</var>ãéåžžã²ãŒã äžã«ãããŠãæã£ãåæ° <var>g</var>ããã§ãªãŒãæã£ãåæ° <var>c</var>ãã¹ã¿ãŒãæã£ãåæ° <var>s</var>ãç·ã²ãŒã æ° <var>t</var> ãäžããããŸãã
</p>
<p>
ãªãã<var>t</var> ã«ã¯ããŒãã¹ã²ãŒã ã®åæ°ãå«ã¿ãŸãããŸããã¡ãã«ã¯ã²ãŒã ã®éäžã«ãªããªãããšã¯ãããŸããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããã£ã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
<pre>
<var>b</var> <var>r</var> <var>g</var> <var>c</var> <var>s</var> <var>t</var>
</pre>
<p>
<var>b, r, g, c, s</var> ã¯ãããã 0 ä»¥äž 200 以äžã®æŽæ°ã<var>t</var> 㯠1000 以äžã®æŽæ°ã§ãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 120 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãæå
ã«æ®ã£ãã¡ãã«ã®ææ°ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
3 2 30 3 26 226
9 0 18 3 20 118
5 5 12 2 15 203
7 4 19 2 22 197
7 4 24 4 17 209
0 0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
127
793
414
629
617
</pre>
|
p03956 | <span class="lang-en">
<p>Score : <var>1700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>N</var> rows and <var>N</var> columns.
The cell at the <var>i</var>-th row and <var>j</var>-th column is denoted (<var>i</var>, <var>j</var>).</p>
<p>Initially, <var>M</var> of the cells are painted black, and all other cells are white.
Specifically, the cells (<var>a_1</var>, <var>b_1</var>), (<var>a_2</var>, <var>b_2</var>), <var>...</var>, (<var>a_M</var>, <var>b_M</var>) are painted black.</p>
<p>Snuke will try to paint as many white cells black as possible, according to the following rule:</p>
<ul>
<li>If two cells (<var>x</var>, <var>y</var>) and (<var>y</var>, <var>z</var>) are both black and a cell (<var>z</var>, <var>x</var>) is white for integers <var>1â€x,y,zâ€N</var>, paint the cell (<var>z</var>, <var>x</var>) black.</li>
</ul>
<p>Find the number of black cells when no more white cells can be painted black.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€Nâ€10^5</var></li>
<li><var>1â€Mâ€10^5</var></li>
<li><var>1â€a_i,b_iâ€N</var></li>
<li>All pairs (<var>a_i</var>, <var>b_i</var>) are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of black cells when no more white cells can be painted black.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>It is possible to paint one white cell black, as follows:</p>
<ul>
<li>Since cells (<var>1</var>, <var>2</var>) and (<var>2</var>, <var>3</var>) are both black and a cell (<var>3</var>, <var>1</var>) is white, paint the cell (<var>3</var>, <var>1</var>) black.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
1 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>It is possible to paint two white cells black, as follows:</p>
<ul>
<li>Since cells (<var>1</var>, <var>1</var>) and (<var>1</var>, <var>2</var>) are both black and a cell (<var>2</var>, <var>1</var>) is white, paint the cell (<var>2</var>, <var>1</var>) black.</li>
<li>Since cells (<var>2</var>, <var>1</var>) and (<var>1</var>, <var>2</var>) are both black and a cell (<var>2</var>, <var>2</var>) is white, paint the cell (<var>2</var>, <var>2</var>) black.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 3
1 2
1 3
4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre>
<p>No white cells can be painted black.</p></section>
</div>
</span> |
p02644 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with <var>H</var> east-west rows and <var>W</var> north-south columns. Let <var>(i,j)</var> be the square at the <var>i</var>-th row from the north and <var>j</var>-th column from the west.</p>
<p>Some of the squares have a lotus leaf on it and cannot be entered.
The square <var>(i,j)</var> has a lotus leaf on it if <var>c_{ij}</var> is <code>@</code>, and it does not if <var>c_{ij}</var> is <code>.</code>.</p>
<p>In one stroke, Snuke can move between <var>1</var> and <var>K</var> squares (inclusive) toward one of the four directions: north, east, south, and west.
The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.</p>
<p>Find the minimum number of strokes Snuke takes to travel from the square <var>(x_1,y_1)</var> to <var>(x_2,y_2)</var>.
If the travel from <var>(x_1,y_1)</var> to <var>(x_2,y_2)</var> is impossible, point out that fact.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W,K \leq 10^6</var></li>
<li><var>H \times W \leq 10^6</var></li>
<li><var>1 \leq x_1,x_2 \leq H</var></li>
<li><var>1 \leq y_1,y_2 \leq W</var></li>
<li><var>x_1 \neq x_2</var> or <var>y_1 \neq y_2</var>.</li>
<li><var>c_{i,j}</var> is <code>.</code> or <code>@</code>.</li>
<li><var>c_{x_1,y_1} =</var> <code>.</code></li>
<li><var>c_{x_2,y_2} =</var> <code>.</code></li>
<li>All numbers in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>K</var>
<var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var>
<var>c_{1,1}c_{1,2}</var> <var>..</var> <var>c_{1,W}</var>
<var>c_{2,1}c_{2,2}</var> <var>..</var> <var>c_{2,W}</var>
<var>:</var>
<var>c_{H,1}c_{H,2}</var> <var>..</var> <var>c_{H,W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of strokes Snuke takes to travel from the square <var>(x_1,y_1)</var> to <var>(x_2,y_2)</var>, or print <code>-1</code> if the travel is impossible.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5 2
3 2 3 4
.....
.@..@
..@..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>Initially, Snuke is at the square <var>(3,2)</var>.
He can reach the square <var>(3, 4)</var> by making five strokes as follows:</p>
<ul>
<li>
<p>From <var>(3, 2)</var>, go west one square to <var>(3, 1)</var>.</p>
</li>
<li>
<p>From <var>(3, 1)</var>, go north two squares to <var>(1, 1)</var>.</p>
</li>
<li>
<p>From <var>(1, 1)</var>, go east two squares to <var>(1, 3)</var>.</p>
</li>
<li>
<p>From <var>(1, 3)</var>, go east one square to <var>(1, 4)</var>.</p>
</li>
<li>
<p>From <var>(1, 4)</var>, go south two squares to <var>(3, 4)</var>.</p>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 6 4
1 1 1 6
......
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 3 1
2 1 2 3
.@.
.@.
.@.
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre></section>
</div>
</span> |
p00679 |
<h1>KND Warp</h1>
<h2>Problem</h2>
<p>KNDåã¯äŒæŽ¥å€§åŠã«åšç±ããåŠçããã°ã©ãã ã圌ã¯ãã®åªç§ãªé è³ããã£ãŠã¯ãŒãè£
眮ãéçºããããšã§æåã§ãããã¯ãŒãè£
眮ãšã¯äŸ¿å©ãªãã®ã§ãããå Žæããå¥ã®å ŽæãŸã§ç¬æã«ç§»åããããšãã§ããã圌ã¯ããããå°çäžã«ç¹åšããã¯ãŒãè£
眮ãçšããŠæ§ã
ãªå Žæãå¯èœãªéãæ©ããããæ
ãèšç»ããŠããã</p>
<p>圌ã®é£äººã§ããããªãã®ä»äºã¯3次å
空é (xyzçŽäº€åº§æšç³») äžã«ååšãã<var>N</var>åã®ã¯ãŒãè£
眮ãããŸã䜿çšããŠã1ãã<var>M</var>ãŸã§ã®çªå·ããµããã<var>M</var>åã®ç¹ãé ã«éã£ãŠã<var>M</var>çªç®ã®ç¹ãŸã§ç§»åãããšãã®æå°ã®æèŠæéãæ±ããããšã ãã¯ããã¯1çªç®ã®ç¹ã«ãããã®ãšããã©ã®ã¯ãŒãè£
眮ãä»»æã®ã¯ãŒãè£
çœ®ãžæé0ã§ç§»åã§ãããã¯ãŒã以å€ã®åäœè·é¢ã®ç§»åã¯åäœæéãèŠãããçµç±ç¹ã®ã¯ãšãªã¯<var>Q</var>åäžããããã</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã
ã²ãšã€ã®ãã¹ãã±ãŒã¹ã¯ä»¥äžã®åœ¢åŒã§äžããããã
å
¥åã®çµããã<var>N</var> = <var>Q</var> = 0ã®ãšã瀺ãã
</p>
<pre>
<var>N</var> <var>Q</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var>
...
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>z<sub>N</sub></var>
<var>M<sub>1</sub></var>
<var>x<sub>1,1</sub></var> <var>y<sub>1,1</sub></var> <var>z<sub>1,1</sub></var>
<var>x<sub>1,2</sub></var> <var>y<sub>1,2</sub></var> <var>z<sub>1,2</sub></var>
...
<var>x<sub>1,M</sub></var> <var>y<sub>1,M</sub></var> <var>z<sub>1,M</sub></var>
<var>M<sub>2</sub></var>
<var>x<sub>2,1</sub></var> <var>y<sub>2,1</sub></var> <var>z<sub>2,1</sub></var>
<var>x<sub>2,2</sub></var> <var>y<sub>2,2</sub></var> <var>z<sub>2,2</sub></var>
...
<var>x<sub>2,M</sub></var> <var>y<sub>2,M</sub></var> <var>z<sub>2,M</sub></var>
...
<var>M<sub>Q</sub></var>
<var>x<sub>Q,1</sub></var> <var>y<sub>Q,1</sub></var> <var>z<sub>Q,1</sub></var>
<var>x<sub>Q,2</sub></var> <var>y<sub>Q,2</sub></var> <var>z<sub>Q,2</sub></var>
...
<var>x<sub>Q,M</sub></var> <var>y<sub>Q,M</sub></var> <var>z<sub>Q,M</sub></var>
</pre>
<p>
ããã§ã
</p>
<ul>
<li><var>N</var>:ã¯ãŒãè£
çœ®ã®æ°</li>
<li><var>Q</var>:æ
ã®ã¯ãšãªã®æ°</li>
<li><var>M<sub>i</sub></var>:içªç®ã¯ãšãªã®æ
ã§èšªããç¹ã®æ°</li>
<li><var>x<sub>i,j</sub></var>,<var>y<sub>i,j</sub></var>,<var>z<sub>i,j</sub></var>:içªç®ã®ã¯ãšãªã®æ
ã§èšªããjçªç®ã®ç¹ã®åº§æš(x,y,z)</li>
</ul>
<p>
ã§ããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>ãã¹ãã±ãŒã¹ã®æ°ã¯15åãè¶
ããªãã</li>
<li>å
¥åã®ååçšåºŠã¯<var>N</var>≤1000ãæºããã</li>
<li>å
¥åã«å«ãŸããå€ã¯ãã¹ãп޿°ã</li>
<li>2≤<var>N</var>≤100,000</li>
<li>1≤<var>Q</var>≤1,000</li>
<li>2≤<var>M</var>≤100</li>
<li>-1,000,000≤(å
šãŠã®x,y,z座æšå€)≤1,000,000</li>
<li>ã¯ãŒãè£
眮ã¯äžèšã®å¶çŽãæºãã空éäžã«ã©ã³ãã ã«ååžãã(Sample Inputã¯äŸå€)ã</li>
<li>ã¯ãŒãè£
眮å士ãäžç¶ç¹å士ãã¯ãŒãè£
眮ãšäžç¶ç¹ã¯ããããéãªãããšãããã</li>
</ul>
<h2>Output</h2>
<p>åã¯ãšãªã«ã€ãæå°ã®æèŠæéãäžè¡ã«åºåããããã®å€ã¯ãžã£ããžåºåã®å€ãš10<sup>-4</sup>ãã倧ããå·®ãæã£ãŠã¯ãªããªãã</p>
<h2>Sample Input</h2>
<pre>
3 2
0 0 0
1 1 1
2 2 2
4
-1 -1 -1
3 3 3
-1 -1 -1
4 4 4
2
1234 5678 9012
1716 6155 9455
0 0
</pre>
<h2>Sample Output</h2>
<pre>
12.124355653
810.001234567
</pre>
<h2>Notes</h2>
<p>å
¥åãã¡ã€ã«ã®ãµã€ãºã¯4MBçšåºŠã«ãªããå
¥åã¯é«éã«ããã»ããããããããšãã°C++ã§ããã°cinã§ãååã§ããã</p> |
p00383 | <h1>Points on a Straight Line</h1>
ã
<p>
The university of A stages a programming contest this year as has been the case in the past. As a member of the team in charge of devising the problems, you have worked out a set of input data for a problem, which is an arrangement of points on a 2D plane in the coordinate system. The problem requires that any combination of these points greater than or equal to $K$ in number must not align on a line. You want to confirm that your data satisfies this requirement.
</p>
<p>
Given the number of points $K$ and their respective 2D coordinates, make a program to check if any combination of points greater or equal to $K$ align on a line.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $K$
$x_1$ $y_1$
$x_2$ $y_2$
$...$
$x_N$ $y_N$
</pre>
<p>
The first line provides the number of points $N$ ($3 \leq N \leq 3000$) on the 2D coordinate system and an integer $K$ ($3 \leq K \leq N$). Each of the subsequent lines provides the $i$-th coordinate $x_i,y_i$ ($0 \leq x_i,y_i \leq 10000$) as integers. None of these coordinates coincide, i.e., if $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$.
</p>
<h2>Output</h2>
<p>
Output <span>1</span> if any combination of points greater or equal to $K$ aligns on a line, or <span>0</span> otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
0 0
1 0
1 1
0 1
2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
7 5
0 0
1 0
1 1
0 1
2 0
3 0
4 0
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
|
p01438 |
<H1><font color="#000">Problem B:</font> Butterfly</H1>
<p>
Claire is a man-eater. She's a real man-eater. She's going around with dozens of guys. She's dating all the time. And one day she found some conflicts in her date schedule. D'oh!
</p>
<p>
So she needs to pick some dates and give the others up. The dates are set by hours like 13:00 to 15:00. She may have more than one date with a guy. For example, she can have dates with Adam from 10:00 to 12:00 and from 14:00 to 16:00 and with Bob from 12:00 to 13:00 and from 18:00 to 20:00. She can have these dates as long as there is no overlap of time. Time of traveling, time of make-up, trouble from love triangles, and the likes are not of her concern. Thus she can keep all the dates with Adam and Bob in the previous example. All dates are set between 6:00 and 22:00 on the same day.
</p>
<p>
She wants to get the maximum amount of satisfaction in total. Each guy gives her some satisfaction if he has all scheduled dates. Let's say, for example, Adam's satisfaction is 100 and Bob's satisfaction is 200. Then, since she can make it with both guys, she can get 300 in total. Your task is to write a program to satisfy her demand. Then she could spend a few hours with
you... if you really want.
</p>
<H2>Input</H2>
<p>
The input consists of a sequence of datasets. Each dataset has the following format:
</p>
<p>
<i>N</i><br>
<i>Guy</i><sub>1</sub><br>
...<br>
<i>Guy</i><sub><i>N</i></sub><br>
</p>
<p>
The first line of the input contains an integer N (1 ≤ <i>N</i> ≤ 100), the number of guys. Then there come the descriptions of guys. Each description is given in this format:
</p>
<p>
<i>M L</i><br>
<i>S</i><sub>1</sub> <i>E</i><sub>1</sub><br>
...<br>
<i>S</i><sub><i>M</i></sub> <i>E</i><sub><i>M</i></sub><br>
</p>
<p>
The first line contains two integers <i>M<sub>i</sub></i> (1 ≤ <i>M<sub>i</sub></i> ≤ 16) and <i>L<sub>i</sub></i> (1 ≤ <i>L<sub>i</sub></i> ≤ 100,000,000), the number of dates set for the guy and the satisfaction she would get from him respectively. Then <i>M</i> lines follow. The <i>i</i>-th line contains two integers <i>S<sub>i</sub></i> and <i>E<sub>i</sub></i> (6 ≤ <i>S<sub>i</sub></i> < <i>E<sub>i</sub></i> ≤ 22), the starting and ending time of the <i>i</i>-th date.
</p>
<p>
The end of input is indicated by <i>N</i> = 0.
</p>
<H2>Output</H2>
<p>
For each dataset, output in a line the maximum amount of satisfaction she can get.
</p>
<H2>Sample Input</H2>
<pre>
2
2 100
10 12
14 16
2 200
12 13
18 20
4
1 100
6 22
1 1000
6 22
1 10000
6 22
1 100000
6 22
16
1 100000000
6 7
1 100000000
7 8
1 100000000
8 9
1 100000000
9 10
1 100000000
10 11
1 100000000
11 12
1 100000000
12 13
1 100000000
13 14
1 100000000
14 15
1 100000000
15 16
1 100000000
16 17
1 100000000
17 18
1 100000000
18 19
1 100000000
19 20
1 100000000
20 21
1 100000000
21 22
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
300
100000
1600000000
</pre>
|
p03405 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an undirected weighted graph with <var>N</var> vertices and <var>M</var> edges.
The <var>i</var>-th edge in the graph connects Vertex <var>U_i</var> and Vertex <var>V_i</var>, and has a weight of <var>W_i</var>.
Additionally, you are given an integer <var>X</var>.</p>
<p>Find the number of ways to paint each edge in this graph either white or black such that the following condition is met, modulo <var>10^9 + 7</var>:</p>
<ul>
<li>The graph has a spanning tree that contains both an edge painted white and an edge painted black. Furthermore, among such spanning trees, the one with the smallest weight has a weight of <var>X</var>.</li>
</ul>
<p>Here, the weight of a spanning tree is the sum of the weights of the edges contained in the spanning tree.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1</var> <var>000</var></li>
<li><var>1 \leq M \leq 2</var> <var>000</var></li>
<li><var>1 \leq U_i, V_i \leq N</var> (<var>1 \leq i \leq M</var>)</li>
<li><var>1 \leq W_i \leq 10^9</var> (<var>1 \leq i \leq M</var>)</li>
<li>If <var>i \neq j</var>, then <var>(U_i, V_i) \neq (U_j, V_j)</var> and <var>(U_i, V_i) \neq (V_j, U_j)</var>.</li>
<li><var>U_i \neq V_i</var> (<var>1 \leq i \leq M</var>)</li>
<li>The given graph is connected.</li>
<li><var>1 \leq X \leq 10^{12}</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>X</var>
<var>U_1</var> <var>V_1</var> <var>W_1</var>
<var>U_2</var> <var>V_2</var> <var>W_2</var>
<var>:</var>
<var>U_M</var> <var>V_M</var> <var>W_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
2
1 2 1
2 3 1
3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
3
1 2 1
2 3 1
3 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 4
1
1 2 3
1 3 3
2 4 6
2 5 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8 10
49
4 6 10
8 4 11
5 8 9
1 8 10
3 8 128773450
7 8 10
4 2 4
3 4 1
3 1 13
5 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>4
</pre></section>
</div>
</span> |
p01068 |
<h1>Equivalent Vertices</h1>
<h2>Background</h2>
<p>
äŒæŽ¥å€§åŠä»å±å¹Œçšåã¯ããã°ã©ãã³ã°ã倧奜ããªåäŸãéãŸã幌çšåã§ããã
åå
ã®äžäººã§ããããåã¯,ããã°ã©ãã³ã°ãšåãããããçµµæãã倧奜ãã ã
ãããŸã§ããåã¯äžžãšå
è§åœ¢ãšç¢å°ã§æ²¢å±±çµµãæžããŠããã
ããæ¥ããåã¯ãããã®çµµãã°ã©ãã§ããããšãç¥ãã
äžžãšå
è§åœ¢ã¯é ç¹ãšåŒã°ã,ç¢å°ã¯èŸºãšåŒã°ããŠãããããã
ããåã¯2ã€ã®é ç¹éãçµã¶ããã«ããŠç¢å°ãæããæŽã«ãã®äžã«0ã1ãæžãã
ãã®ããã«,蟺ã«éã¿(0ãŸãã¯1)ãããæåãªèŸºãããªãã°ã©ãã¯éã¿ä»ãæåã°ã©ããšåŒã°ããã
ãŸã,é ç¹ãšæ°å<var>x</var>(0ãŸãã¯1)ãäžããããæ,ãã®é ç¹ããåºãŠããç¢å°ã®ãã¡,<var>x</var>ãšåãéã¿ãæã€ç¢å°ã«åŸã£ãŠå¥ã®é ç¹ã«ç§»åããããšã<I><var>x</var>ã«åŸã£ãŠé·ç§»ãã</I>ãšèšãã
仿¥ããåã¯0ãš1ãããªãã©ã®ãããªæ°åã«åŸã£ãŠé·ç§»ããŠãæçµçã«å°éããé ç¹ã®çš®é¡(äžžãŸãã¯å
è§åœ¢)ãäžç·ã§ãããããªé ç¹ã®å¯Ÿãååšããããšã«æ°ãã€ããã
ããã«ã€ããŠããåã¯äžã€ã®åé¡ãæãã€ããã
</p>
<h2>Problem</h2>
<p>
éã¿ä»ãæåã°ã©ããäžããããã
ãã®ã°ã©ãã®åé ç¹ã¯0ããé çªã«<var>n</var>-1ãŸã§çªå·ãå²ãæ¯ãããŠããã
ãŸã,åé ç¹ã¯ããããéã¿ã0ã®èŸºãš1ã®èŸºã®åèš2æ¬ã®èŸºãåºãŠè¡ãã
ããã«,é ç¹ã«ã¯äžžãé ç¹ãå
è§åœ¢ã®é ç¹ã®2çš®é¡ãååšã,åé ç¹ã¯ãããã®ããããã§ããã
以äžã«Sample Input 2ã§äžããããéã¿ä»ãæåã°ã©ãã瀺ãã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_L1" alt="å³ïŒ" width="680" ><br>
å³1. Sample Input 2
</center>
<br>
<p>
以äžã®åœ¢åŒã§<var>m</var>åã®è³ªåãäžããããã®ã§ãããããã«ã€ããŠçããåºåããã
</p>
<ul>
<li>é ç¹ã®çªå·<var>q</var>ãäžããããã®ã§,ãã®é ç¹ãš<I>ç䟡</I>ãªé ç¹ã®æ°ãåºåãã</li>
</ul>
<p>
2ã€ã®é ç¹<var>a</var>,<var>b</var>ã以äžã®2ã€ã®æ¡ä»¶ãæºãããšã,<var>a</var>ãš<var>b</var>ã¯ç䟡ã§ããã
</p>
<ol>
<li><var>a</var>ãš<var>b</var>ã¯åãçš®é¡ã®é ç¹ã§ãã</li>
<li>0ãš1ãããªãé·ã1以äžã®ä»»æã®æ°åã«ã€ããŠ,ããã«åŸã£ãŠ<var>a</var>ãš<var>b</var>ã®ããããããé·ç§»ãéå§ãããšãæçµçã«å°éããé ç¹ã®çš®é¡ãåãã§ãã</li>
</ol>
<p>
äŸãã°,å³1ã®é ç¹3ããæ°å0,0,1,0ã«åŸã£ãŠé·ç§»ãéå§ãããš,
3→2→1→1→1ã®é çªã§é·ç§»ãæçµçã«å°éããé ç¹ã¯1ã§ããã
</p>
<p>
Sample Input 2 ã«ãããŠ,é ç¹0ãšé ç¹2,é ç¹0ãšé ç¹4ã¯ç䟡ã§ããã
é ç¹0ãšé ç¹4ã«ã€ããŠèããã
ãããã¯äž¡æ¹ãšãäžžãé ç¹ã§ãããã1ã€ãã®æ¡ä»¶ãæºããã
ãŸã,ãããã®é ç¹ãã0ãŸãã¯1ã§é·ç§»ããçµæå°éããé ç¹ã¯1ã5ã§ããã
é ç¹1,5ã¯ããããã©ã®ãããªæ°åã«åŸã£ãŠé·ç§»ããŠããã®é ç¹ã«æ¢ãŸãç¶ããã
ãŸã,äž¡æ¹ãšãå
è§åœ¢ã®é ç¹ã§ããã
ãããã,é ç¹0ãšé ç¹4ã¯ã©ã®ãããªæ°åã«åŸã£ãŠé·ç§»ããŠãæçµçã«å°éããé ç¹ã¯å
è§åœ¢ã®é ç¹ã§ãããã2ã€ãã®æ¡ä»¶ãæºããã
æ¡ä»¶ã2ã€ãšãæºããã®ã§é ç¹0ãšé ç¹4ã¯ç䟡ã§ããã
æçµçã«å°éããé ç¹ã¯çš®é¡ãåãã§ããã°è¯ããã,é ç¹ã®çªå·ãåãã§ããå¿
èŠã¯ãªãããšã«æ³šæããã
ãŸã,é ç¹0ãšé ç¹1ã¯ç䟡ã§ãªãã
é ç¹0ã¯äžžãé ç¹ã§é ç¹1ã¯å
è§åœ¢é ç¹ãªã®ã§,1ã€ãã®æ¡ä»¶ãæºãããªãã
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var>
<var>v<sub>0</sub></var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var>
<var>v<sub>1</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var>
âŠ
<var>v<sub>n−1</sub></var> <var>s<sub>n−1</sub></var> <var>t<sub>n−1</sub></var>
<var>q<sub>0</sub></var>
<var>q<sub>1</sub></var>
âŠ
<var>q<sub>m−1</sub></var>
</pre>
<ul>
<li><var>v<sub>i</sub></var>,<var>s<sub>i</sub></var>,<var>t<sub>i</sub></var>ã¯ãããã<var>i</var>çªã®é ç¹ã®çš®é¡,0ã«ããé·ç§»å
ã®é ç¹çªå·,1ã«ããé·ç§»å
ã®é ç¹çªå·</li>
<li><var>v<sub>i</sub></var>ã0ã®ãšã,<var>i</var>çªã®é ç¹ã¯äžžãé ç¹ã§ãã,1ã®ãšãå
è§åœ¢ã®é ç¹</li>
<li><var>q<sub>j</sub></var>ã¯<var>j</var>çªç®ã®è³ªåã§äžããããé ç¹ã®çªå·</li>
</ul>
<h2>Constraints</h2>
<ul>
<li> å
¥åã¯å
šãп޿°ãšããŠäžãããã</li>
<li> 1 ≤ <var>n</var> ≤ 3000</li>
<li> 1 ≤ <var>m</var> ≤ n</li>
<li> 0 ≤ <var>s<sub>i</sub></var>,<var>t<sub>i</sub></var>,<var>q<sub>j</sub></var> ≤ <var>n</var>-1</li>
<li> 0 ≤ <var>v<sub>i</sub></var> ≤ 1</li>
<li> äžããããã°ã©ãã®èŸºãåæ¹åã«ç§»åã§ãããã®ãšãããšã,ä»»æã®2ç¹ãçµã¶ãããªèŸºã®éåãååšãã, ã€ãŸãäžããããã°ã©ãã¯é£çµã§ãã</li>
</ul>
<h2>Output</h2>
<p>
å質åã§äžããããé ç¹ã®çªå·<var>q<sub>j</sub></var>ã«å¯ŸããŠ,ãããšç䟡ãªé ç¹ã®æ°ãããããäžè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
2 1
0 0 1
0 1 0
0
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
6 6
0 1 5
1 1 1
0 1 5
0 2 1
0 5 1
1 5 5
0
1
2
3
4
5
</pre>
<h2>Sample Output 2</h2>
<pre>
3
2
3
1
3
2
</pre>
|
p03055 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Aoki will play a game on a tree.
The tree has <var>N</var> vertices numbered <var>1</var> to <var>N</var>, and the <var>i</var>-th of the <var>N-1</var> edges connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p>
<p>At the beginning of the game, each vertex contains a coin.
Starting from Takahashi, he and Aoki will alternately perform the following operation:</p>
<ul>
<li>Choose a vertex <var>v</var> that contains one or more coins, and remove all the coins from <var>v</var>.</li>
<li>Then, move each coin remaining on the tree to the vertex that is nearest to <var>v</var> among the adjacent vertices of the coin's current vertex.</li>
</ul>
<p>The player who becomes unable to play, loses the game.
That is, the player who takes his turn when there is no coin remaining on the tree, loses the game.
Determine the winner of the game when both players play optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq a_i, b_i \leq N</var></li>
<li><var>a_i \neq b_i</var></li>
<li>The graph given as input is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>First</code> if Takahashi will win, and print <code>Second</code> if Aoki will win.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>First
</pre>
<p>Here is one possible progress of the game:</p>
<ul>
<li>Takahashi removes the coin from Vertex <var>1</var>. Now, Vertex <var>1</var> and Vertex <var>2</var> contain one coin each.</li>
<li>Aoki removes the coin from Vertex <var>2</var>. Now, Vertex <var>2</var> contains one coin.</li>
<li>Takahashi removes the coin from Vertex <var>2</var>. Now, there is no coin remaining on the tree.</li>
<li>Aoki takes his turn when there is no coin on the tree and loses.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
1 2
2 3
2 4
4 6
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Second
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1 7
7 4
3 4
7 5
6 3
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>First
</pre></section>
</div>
</span> |
p01592 |
<h2>Problem B: Blame Game</h2>
<p>Alice and Bob are in a factional dispute. Recently a big serious problem
arised in a project both Alice and Bob had been working for. This problem was
caused by lots of faults of Alice's and Bob's sides; those faults are closely
related.</p>
<p>Alice and Bob started to blame each other. First, Alice claimed it was
caused by Bob's fault. Then Bob insisted his fault was led by Alice's fault.
Soon after, Alice said that her fault should not have happened without Bob's
another fault. So on so forth. It was terrible. It was totally a blame game.
Still, they had their pride. They would not use the same fault more than once in
their claims.</p>
<p>All right, let's see the situation in terms of a game.</p>
<p>Alice and Bob have a number of faults. Some pairs of Alice and Bob faults
have direct relationship between them. This relationship is bidirectional; if a
fault X is led by another fault Y, they can say either "X was due to Y." or
"even with X, the problem could be avoided without Y." Note that not both, since
they never pick up the same fault in their claims.</p>
<p>Alice and Bob take their turns alternatively. Alice takes the first turn
by claiming any of Bob's faults. Then Bob makes his claim with Alice's fault
directly related to the claimed fault. Afterward, in each turn, one picks up
another's fault directly related to the fault claimed in the previous turn. If
he/she has no faults that have not been claimed, then he/she loses this game.</p>
<p>By the way, you have been working both under Alice and Bob. You know all
the faults and relationships. Your task is to write a program to find out which
would win this game, under the assumption that they always take their optimal
strategies. If you could choose the winning side, you would not have to take the
responsibility for the arisen problem.</p>
<h2>Input</h2>
<p>Each input contains one test case. The first line of the input contains
two integers <var>N</var> and <var>M</var> (0 <= <var>N</var>, <var>M</var> <=
500), which denote the numbers of Alice's and Bob's faults respectively. Alice's
faults are numbered from 1 to <var>N</var>; so are Bob's from 1 to <var>M</var>.
Then <var>N</var> lines follow to describe the relationships among the faults.
The <var>i</var>-th line begins with a non-negative integer <var>K<sub>i</sub></var>
(0 <= <var>K<sub>i</sub></var> <= <var>M</var>). It is then followed by <var>K<sub>i</sub></var>
positive integers, where the <var>j</var>-th number <var>b<sub>i,j</sub></var>
(1 <= <var>b<sub>i,j</sub></var> <= <var>M</var>) indicates there is a direct
relationship between the <var>i</var>-th Alice's fault and the <var>b<sub>i,j</sub></var>-th
Bob's fault. It is guaranteed that
<var>b<sub>i,j</sub></var> != <var>b<sub>i,j'</sub></var>
for all <var>i</var>, <var>j</var>, <var>j'</var>
such that 1 <= <var>i</var> <= <var>N</var> and 1 <= <var>j</var> < <var>j'</var>
<= <var>K<sub>i</sub></var>.</p>
<h2>Output</h2>
<p>Print either "Alice" or "Bob" to indicate the winner of the blame game.</p>
<h2>Sample Input 1</h2>
<pre>
1 1
1 1
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>
Bob
</pre>
<h2>Sample Input 2</h2>
<pre>
3 3
3 1 2 3
1 3
1 3
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>
Alice
</pre>
|
p01087 |
<h2>ICPC Calculator</h2>
<p>
In mathematics, we usually specify the order of operations by using
parentheses.
For example, 7 Ã (3 + 2) always means multiplying 7 by the result of 3 + 2 and never means adding 2 to the result of 7 Ã 3.
However, there are people who do not like parentheses.
International Counter of Parentheses Council (ICPC) is attempting
to make a notation without parentheses the world standard.
They are always making studies of such no-parentheses notations.
</p>
<p>
Dr. Tsukuba, a member of ICPC, invented a new parenthesis-free notation.
In his notation, a single expression is represented by multiple
lines, each of which contains an addition operator (<t>+</t>), a
multiplication operator (<t>*</t>) or an integer.
An expression is either a single integer or an operator application to <i>operands.</i>
Integers are denoted in decimal notation in one line.
An operator application is denoted by a line of its operator immediately
followed by lines denoting its two or more operands,
each of which is an expression, recursively.
Note that when an operand is an operator application,
it comprises multiple lines.
</p>
<p>
As expressions may be arbitrarily nested,
we have to make it clear which operator is applied to which operands.
For that purpose, each of the expressions is given its <i>nesting level.</i>
The top level expression has the nesting level of 0.
When an expression of level <i>n</i> is an operator application,
its operands are expressions of level <i>n</i> + 1.
The first line of an expression starts with a sequence of periods (<t>.</t>),
the number of which indicates the level of the expression.
</p>
<p>
For example, 2 + 3 in the regular mathematics is denoted as in Figure 1.
An operator can be applied to two or more operands.
Operators <t>+</t> and <t>*</t> represent operations
of summation of all operands and multiplication of all operands,
respectively. For example, Figure 2 shows an expression multiplying
2, 3, and 4.
For a more complicated example, an expression (2 + 3 + 4) Ã 5 in
the regular mathematics can be expressed as in Figure 3 while (2 + 3) Ã 4 Ã 5
can be expressed as in Figure 4.
</p>
<pre>+
.2
.3
</pre>
Figure 1: 2 + 3
<br><br>
<pre>*
.2
.3
.4
</pre>
Figure 2: An expression multiplying 2, 3, and 4
<br><br>
<pre>*
.+
..2
..3
..4
.5
</pre>
Figure 3: (2 + 3 + 4) Ã 5
<br><br>
<pre>*
.+
..2
..3
.4
.5
</pre>
Figure 4: (2 + 3) Ã 4 Ã 5
<br><br>
<p>
Your job is to write a program that computes the value of expressions
written in Dr. Tsukuba's notation to help him.
</p>
<h3>Input</h3>
<p>
The input consists of multiple datasets. Each dataset
starts with a line containing a positive integer <i>n</i>, followed by
<i>n</i> lines denoting a single expression in Dr. Tsukuba's notation.
</p>
<p>
You may assume that, in the expressions given in the input,
every integer comprises a single digit and that
every expression has no more than nine integers.
You may also assume that all the input expressions are valid
in the Dr. Tsukuba's notation.
The input contains no extra characters, such as spaces or empty lines.
</p>
<p>
The last dataset is immediately followed by a line with a single zero.
</p>
<h3>Output</h3>
<p>
For each dataset, output a single line containing an integer
which is the value of the given expression.
</p>
<h3>Sample Input</h3>
<pre>1
9
4
+
.1
.2
.3
9
+
.0
.+
..*
...1
...*
....1
....2
..0
10
+
.+
..6
..2
.+
..1
..*
...7
...6
.3
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>9
6
2
54
</pre> |
p03540 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some place in the Arctic Ocean, there are <var>H</var> rows and <var>W</var> columns of ice pieces floating on the sea.
We regard this area as a grid, and denote the square at the <var>i</var>-th row and <var>j</var>-th column as Square <var>(i,j)</var>.
The ice piece floating in each square is either thin ice or an iceberg, and a penguin lives in one of the squares that contain thin ice.
There are no ice pieces floating outside the grid.</p>
<p>The ice piece at Square <var>(i,j)</var> is represented by the character <var>S_{i,j}</var>.
<var>S_{i,j}</var> is <code>+</code>, <code>#</code> or <code>P</code>, each of which means the following:</p>
<ul>
<li><code>+</code>: Occupied by thin ice.</li>
<li><code>#</code>: Occupied by an iceberg.</li>
<li><code>P</code>: Occupied by thin ice. The penguin lives here.</li>
</ul>
<p>When summer comes, unstable thin ice that is not held between some pieces of ice collapses one after another.
Formally, thin ice at Square <var>(i,j)</var> will collapse when it does NOT satisfy either of the following conditions:</p>
<ul>
<li>Both Square <var>(i-1,j)</var> and Square <var>(i+1,j)</var> are occupied by an iceberg or uncollapsed thin ice.</li>
<li>Both Square <var>(i,j-1)</var> and Square <var>(i,j+1)</var> are occupied by an iceberg or uncollapsed thin ice.</li>
</ul>
<p>When a collapse happens, it may cause another. Note that icebergs do not collapse.</p>
<p>Now, a mischievous tourist comes here. He will do a little work so that, when summer comes, the thin ice inhabited by the penguin will collapse.
He can smash an iceberg with a hammer to turn it to thin ice.
At least how many icebergs does he need to smash?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 40</var></li>
<li><var>S_{i,j}</var> is <code>+</code>, <code>#</code> or <code>P</code>.</li>
<li><var>S</var> contains exactly one <code>P</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>S_{1,1}</var><var>S_{1,2}</var><var>...</var><var>S_{1,W}</var>
<var>S_{2,1}</var><var>S_{2,2}</var><var>...</var><var>S_{2,W}</var>
<var>:</var>
<var>S_{H,1}</var><var>S_{H,2}</var><var>...</var><var>S_{H,W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of icebergs that needs to be changed to thin ice in order to cause the collapse of the thin ice inhabited by the penguin when summer comes.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
+#+
#P#
+#+
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, when the right and bottom icebergs are changed to thin ice, collapses happen as follows:</p>
<pre>+#+ .#. .#. .#.
#P+ -> #P+ -> #P. -> #..
+++ .+. ... ...
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 6
#+++++
+++#++
#+++++
+++P+#
+##+++
++++#+
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>40 40
#++#+++++#+#+#+##+++++++##+#+++#++##++##
+##++++++++++#+###+##++++#+++++++++#++##
+++#+++++#++#++####+++#+#+###+++##+++#++
+++#+######++##+#+##+#+++#+++++++++#++#+
+++##+#+#++#+++#++++##+++++++++#++#+#+#+
#++#+++#+#++++##+#+#+++##+#+##+#++++##++
++#+##+++#++####+#++##++#+++#+#+#++++#++
+#+###++++++##++++++#++##+#####++#++##++
##+##+#+++#+#+##++#+###+######++++#+###+
+++#+++##+#####+#+#++++#+#+++++#+##++##+
#+++#+##+++++++#++#++++++++++###+#++#+#+
##+++##++#+++++#++++#++#+##++#+#+#++##+#
##+++#+###+++++##++#+#+++####+#+++++#+++
+++#++#++#+++++++++#++###++++++++###+##+
++#+++#++++++#####++##++#+++#+++++#++++#
++#++#+##++++#####+###+++####+#+#+######
++++++##+++++##+++++#++###++#++##+++++++
+#++++##++++++#++++#+#++++#++++##+++##+#
+++++++#+#++##+##+#+++++++###+###++##+++
++++++#++###+#+#+++##+#++++++#++#+#++#+#
##+##++++++#+++++#++#+#++##+++#+#+++##+#
#+++#+#+##+#+##++#P#++#++++++##++#+#++##
#+++#++##+##+#++++#++#++##++++++#+#+#+++
++++####+#++#####+++#+###+#++###++++#++#
#+#++####++##++#+#+#+##+#+#+##++++##++#+
+###+###+#+##+++#++++++#+#++++###+#+++++
+++#+++++#+++#+++++##++++++++###++#+#+++
+#+#++#+#++++++###+#++##+#+##+##+#+#####
#++++++++#+#+###+######++#++#+++++++++++
##+++##+#+#++#++#++#++++++#++##+#+#++###
+#+#+#+++++++#+++++++######+##++#++##+##
++#+++#+###+#++###+++#+++#+#++++#+###+++
#+#+###++#+#####+++++#+####++#++#+###+++
+#+##+#++#++##+++++++######++#++++++++++
+####+#+#+++++##+#+#++#+#++#+++##++++#+#
#++##++#+#+++++##+#++++####+++++###+#+#+
##+#++#++#+##+#+#++##++###+###+#+++++##+
##++###+###+#+#++#++#########+++###+#+##
+++#+++#++++++++++#+#+++#++#++###+####+#
++##+###+++++++##+++++#++#++++++++++++++
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>151
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 1
P
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre></section>
</div>
</span> |
p03110 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi received <em>otoshidama</em> (New Year's money gifts) from <var>N</var> of his relatives.</p>
<p>You are given <var>N</var> values <var>x_1, x_2, ..., x_N</var> and <var>N</var> strings <var>u_1, u_2, ..., u_N</var> as input. Each string <var>u_i</var> is either <code>JPY</code> or <code>BTC</code>, and <var>x_i</var> and <var>u_i</var> represent the content of the otoshidama from the <var>i</var>-th relative.</p>
<p>For example, if <var>x_1 =</var> <code>10000</code> and <var>u_1 =</var> <code>JPY</code>, the otoshidama from the first relative is <var>10000</var> Japanese yen; if <var>x_2 =</var> <code>0.10000000</code> and <var>u_2 =</var> <code>BTC</code>, the otoshidama from the second relative is <var>0.1</var> bitcoins.</p>
<p>If we convert the bitcoins into yen at the rate of <var>380000.0</var> JPY per <var>1.0</var> BTC, how much are the gifts worth in total?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10</var></li>
<li><var>u_i =</var> <code>JPY</code> or <code>BTC</code>.</li>
<li>If <var>u_i =</var> <code>JPY</code>, <var>x_i</var> is an integer such that <var>1 \leq x_i \leq 10^8</var>.</li>
<li>If <var>u_i =</var> <code>BTC</code>, <var>x_i</var> is a decimal with <var>8</var> decimal digits, such that <var>0.00000001 \leq x_i \leq 100.00000000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>u_1</var>
<var>x_2</var> <var>u_2</var>
<var>:</var>
<var>x_N</var> <var>u_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the gifts are worth <var>Y</var> yen in total, print the value <var>Y</var> (not necessarily an integer).</p>
<p>Output will be judged correct when the absolute or relative error from the judge's output is at most <var>10^{-5}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
10000 JPY
0.10000000 BTC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>48000.0
</pre>
<p>The otoshidama from the first relative is <var>10000</var> yen. The otoshidama from the second relative is <var>0.1</var> bitcoins, which is worth <var>38000.0</var> yen if converted at the rate of <var>380000.0</var> JPY per <var>1.0</var> BTC. The sum of these is <var>48000.0</var> yen.</p>
<p>Outputs such as <code>48000</code> and <code>48000.1</code> will also be judged correct.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
100000000 JPY
100.00000000 BTC
0.00000001 BTC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>138000000.0038
</pre>
<p>In this case, outputs such as <code>138001000</code> and <code>1.38e8</code> will also be judged correct.</p></section>
</div>
</span> |
p01984 | <h3>çææ°</h3>
<!-- begin ja only -->
<p>é¡ã¯ã㯠è±ã®äžã«ãŠ æ¥æ»ãªã ãã®ããããã® ææã®ãã</p>
<p>ããã¯ïŒè¥¿è¡æ³åž«ãè© ãã ãšãããïŒæåãªçæã®äžã€ã§ããïŒ
çæã¯ïŒæ¥æ¬ã«ãããŠå€ããã芪ããŸããŠããåæã®äžçš®ã§ããïŒãã®å€ã㯠5ã»7ã»5ã»7ã»7 ã®äºå¥äžåäžé³ãããªãïŒ</p>
<p>ãšããã§ïŒ57577 ãšããæ°ã¯ïŒ5 ãš 7 ã®äºçš®é¡ã®æ°åãããªãïŒ
ãã®ãããªïŒåé²è¡šèšãã¡ããã©äºçš®é¡ã®æ°åãããªãæ£ã®æŽæ°ãïŒçææ°ãšåŒã¶ããšã«ããïŒ
äŸãã°ïŒ10, 12, 57577, 25252 ãªã©ã¯çææ°ã§ãããïŒ5, 11, 123, 20180701 ãªã©ã¯çææ°ã§ã¯ãªãïŒ</p>
<p>æ£ã®æŽæ° <i>N</i> ãäžããããïŒ<i>N</i> çªç®ã«å°ããçææ°ãæ±ããïŒ</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯æå€§ã§ 100 åã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>N</i></blockquote>
<p>æŽæ° <i>N</i> 㯠<i>1 ≤ N ≤ 10<sup>18</sup></i> ãæºããïŒ</p>
<p>å
¥åã®çµãã㯠1 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«ã€ããŠïŒ<i>N</i> çªç®ã«å°ããçææ°ã 1 è¡ã«åºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>1
2
3
390
1124
1546
314159265358979323
0
</pre><h3>Output for the Sample Input</h3><pre>10
12
13
2020
25252
57577
7744444777744474777777774774744777747477444774744744
</pre>
|
p00696 |
<h1>
Multi-column List
</h1>
<P>Ever since Mr. Ikra became the chief manager of his office,
he has had little time for his favorites, programming and debugging.
So he wants to check programs in trains to and from his office
with program lists.
He has wished for the tool that prints source programs
as multi-column lists so that each column just fits in
a pocket of his business suit.
</P>
<P>In this problem, you should help him by making a program that prints
the given input text in a multi-column format. Since his business
suits have various sizes of pockets, your program should be flexible
enough and accept four parameters, (1) the number of lines in a
column, (2) the number of columns in a page, (3) the width of each
column, and (4) the width of the column spacing.
We assume that a fixed-width font is used for printing and so the
column width is given as the maximum number of characters in a line.
The column spacing is also specified as the number of
characters filling it.
</P>
<H2>Input</H2>
<P>In one file, stored are data sets in a form shown below.</P>
<PRE>
<I>plen</I><SUB>1</SUB>
<I>cnum</I><SUB>1</SUB>
<I>width</I><SUB>1</SUB>
<I>cspace</I><SUB>1</SUB>
<I>line</I><SUB>1</SUB><SUB>1</SUB>
<I>line</I><SUB>1</SUB><SUB>2</SUB>
....
<I>line</I><SUB>1</SUB><SUB>i</SUB>
....
?
<I>plen</I><SUB>2</SUB>
<I>cnum</I><SUB>2</SUB>
<I>width</I><SUB>2</SUB>
<I>cspace</I><SUB>2</SUB>
<I>text</I><SUB>2</SUB>
<I>line</I><SUB>2</SUB><SUB>1</SUB>
<I>line</I><SUB>2</SUB><SUB>2</SUB>
....
<I>line</I><SUB>2</SUB><SUB>i</SUB>
....
?
0
</PRE>
<P>The first four lines of each data set give
positive integers specifying the output format.
<I>Plen</I> (1 <= <I>plen</I> <= 100) is the number of lines in a column.
<I>Cnum</I> is the number of columns in one page.
<I>Width</I> is the column width, i.e., the number of characters in one column.
<I>Cspace</I> is the number of spacing characters between each pair of
neighboring columns.
You may assume
1 <= (<I>cnum</I> * <I>width</I> + <I>cspace</I> * (<I>cnum</I>-1)) <= 50.
</P>
<P>The subsequent lines terminated by a line consisting solely of '?'
are the input text.
Any lines of the input text do not include any characters except
alphanumeric characters '0'-'9', 'A'-'Z', and 'a'-'z'.
Note that some of input lines may be empty.
No input lines have more than 1,000 characters.
</P>
<H2>Output</H2>
<P>
Print the formatted pages in the order of input data sets.
Fill the gaps among them with dot('.') characters.
If an output line is shorter than <I>width</I>, also fill its
trailing space with dot characters.
An input line that is empty shall occupy a single line on an output
column.
This empty output line is naturally filled with dot characters.
An input text that is empty, however, shall not occupy any page.
A line larger than <I>width</I> is wrapped around
and printed on multiple lines.
At the end of each page, print a line consisting only of '#'.
At the end of each data set, print a line consisting only of '?'.
</P>
<H2>Sample Input</H2>
<PRE>
6
2
8
1
AZXU5
1GU2D4B
K
PO4IUTFV
THE
Q34NBVC78
T
1961
XWS34WQ
LNGLNSNXTTPG
ED
MN
MLMNG
?
4
2
6
2
QWERTY
FLHL
?
0
</PRE>
<H2>Output for the Sample Input</H2>
<P>You Should see the following section with a fixed-width font. </P>
<PRE>
AZXU5....8.......
1GU2D4B..T.......
K........1961....
PO4IUTFV.XWS34WQ.
THE..............
Q34NBVC7.LNGLNSNX
#
TTPG.............
ED...............
MN...............
MLMNG............
.................
.................
#
?
QWERTY........
FLHL..........
..............
..............
#
?
</PRE>
|
p02351 |
<H1>RSQ and RAQ</H1>
<p>
Write a program which manipulates a sequence <var>A</var> = {<var>a<sub>1</sub>, a<sub>2</sub>, . . . , a<sub>n</sub></var>} with the following operations:
</p>
<ul>
<li><var>add(s, t, x)</var>: add <var>x</var> to <var>a<sub>s</sub></var>, <var>a<sub>s+1</sub></var>, ..., <var>a<sub>t</sub></var>.</li>
<li><var>getSum(s, t)</var>: report the sum of <var>a<sub>s</sub></var>, <var>a<sub>s+1</sub></var>, ..., <var>a<sub>t</sub></var>.</li>
</ul>
<p>
Note that the initial values of <var>a<sub>i</sub></var> (<var>i = 1, 2, . . . , n</var>) are 0.
</p>
<H2>Input</H2>
<pre>
<var>n</var> <var>q</var>
<var>query<sub>1</sub></var>
<var>query<sub>2</sub></var>
:
<var>query<sub>q</sub></var>
</pre>
<p>
In the first line, <var>n</var> (the number of elements in <var>A</var>) and <var>q</var> (the number of queries) are given. Then, <i>i</i>th query <var>query<sub>i</sub></var> is given in the following format:
</p>
<pre>
0 <var>s</var> <var>t</var> <var>x</var>
</pre>
<p>
or
</p>
<pre>
1 <var>s</var> <var>t</var>
</pre>
<p>
The first digit represents the type of the query. '0' denotes <var>add(s, t, x)</var> and '1' denotes <var>getSum(s, t)</var>.
</p>
<H2>Output</H2>
<p>
For each <var>getSum</var> operation, print the sum;
</p>
<H2>Constraints</H2>
<ul>
<li>
<var>1 ≤ n ≤ 100000</var>
</li>
<li>
<var>1 ≤ q ≤ 100000</var>
</li>
<li>
<var>1 ≤ s ≤ t ≤ n</var>
</li>
<li>
<var>0 ≤ x < 1000</var>
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3 5
0 1 2 1
0 2 3 2
0 3 3 3
1 1 2
1 2 3
</pre>
<H2>Sample Output 1</H2>
<pre>
4
8
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4 3
1 1 4
0 1 4 1
1 1 4
</pre>
<H2>Sample Output 2</H2>
<pre>
0
4
</pre> |
p03813 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than <var>1200</var>, and participate in AtCoder Regular Contest (ARC) otherwise.</p>
<p>You are given Smeke's current rating, <var>x</var>. Print <code>ABC</code> if Smeke will participate in ABC, and print <code>ARC</code> otherwise.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠x ⊠3{,}000</var></li>
<li><var>x</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>x</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>ABC
</pre>
<p>Smeke's current rating is less than <var>1200</var>, thus the output should be <code>ABC</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>ARC
</pre>
<p>Smeke's current rating is not less than <var>1200</var>, thus the output should be <code>ARC</code>.</p></section>
</div>
</span> |
p02701 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You drew lottery <var>N</var> times. In the <var>i</var>-th draw, you got an item of the kind represented by a string <var>S_i</var>.</p>
<p>How many kinds of items did you get?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2\times 10^5</var></li>
<li><var>S_i</var> consists of lowercase English letters and has a length between <var>1</var> and <var>10</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S_1</var>
<var>:</var>
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of kinds of items you got.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
apple
orange
apple
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>You got two kinds of items: <code>apple</code> and <code>orange</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
grape
grape
grape
grape
grape
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
aaaa
a
aaa
aa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p04006 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke lives in another world, where slimes are real creatures and kept by some people.
Slimes come in <var>N</var> colors. Those colors are conveniently numbered <var>1</var> through <var>N</var>.
Snuke currently has no slime. His objective is to have slimes of all the colors together.</p>
<p>Snuke can perform the following two actions:</p>
<ul>
<li>
<p>Select a color <var>i</var> (<var>1â€iâ€N</var>), such that he does not currently have a slime in color <var>i</var>, and catch a slime in color <var>i</var>. This action takes him <var>a_i</var> seconds.</p>
</li>
<li>
<p>Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color <var>i</var> (<var>1â€iâ€N-1</var>) will become color <var>i+1</var>, and the color of a slime in color <var>N</var> will become color <var>1</var>. This action takes him <var>x</var> seconds.</p>
</li>
</ul>
<p>Find the minimum time that Snuke needs to have slimes in all <var>N</var> colors.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€Nâ€2,000</var></li>
<li><var>a_i</var> are integers.</li>
<li><var>1â€a_iâ€10^9</var></li>
<li><var>x</var> is an integer.</li>
<li><var>1â€xâ€10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>x</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the minimum time that Snuke needs to have slimes in all <var>N</var> colors.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 10
1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Snuke can act as follows:</p>
<ul>
<li>Catch a slime in color <var>1</var>. This takes <var>1</var> second.</li>
<li>Cast the spell. The color of the slime changes: <var>1</var> â <var>2</var>. This takes <var>10</var> seconds.</li>
<li>Catch a slime in color <var>1</var>. This takes <var>1</var> second.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 10
100 1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>23
</pre>
<p>Snuke can act as follows:</p>
<ul>
<li>Catch a slime in color <var>2</var>. This takes <var>1</var> second.</li>
<li>Cast the spell. The color of the slime changes: <var>2</var> â <var>3</var>. This takes <var>10</var> seconds.</li>
<li>Catch a slime in color <var>2</var>. This takes <var>1</var> second.</li>
<li>Cast the soell. The color of each slime changes: <var>3</var> â <var>1</var>, <var>2</var> â <var>3</var>. This takes <var>10</var> seconds.</li>
<li>Catch a slime in color <var>2</var>. This takes <var>1</var> second.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 10
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10
</pre>
<p>Snuke can act as follows:</p>
<ul>
<li>Catch a slime in color <var>1</var>. This takes <var>1</var> second.</li>
<li>Catch a slime in color <var>2</var>. This takes <var>2</var> seconds.</li>
<li>Catch a slime in color <var>3</var>. This takes <var>3</var> seconds.</li>
<li>Catch a slime in color <var>4</var>. This takes <var>4</var> seconds.</li>
</ul></section>
</div>
</span> |
p03239 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>When Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.</p>
<p>You, the smartwatch, has found <var>N</var> routes to his home.</p>
<p>If Mr. X uses the <var>i</var>-th of these routes, he will get home in time <var>t_i</var> at cost <var>c_i</var>.</p>
<p>Find the smallest cost of a route that takes not longer than time <var>T</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq T \leq 1000</var></li>
<li><var>1 \leq c_i \leq 1000</var></li>
<li><var>1 \leq t_i \leq 1000</var></li>
<li>The pairs <var>(c_i, t_i)</var> are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>T</var>
<var>c_1</var> <var>t_1</var>
<var>c_2</var> <var>t_2</var>
<var>:</var>
<var>c_N</var> <var>t_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest cost of a route that takes not longer than time <var>T</var>.</p>
<p>If there is no route that takes not longer than time <var>T</var>, print <code>TLE</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 70
7 60
1 80
4 50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<ul>
<li>The first route gets him home at cost <var>7</var>.</li>
<li>The second route takes longer than time <var>T = 70</var>.</li>
<li>The third route gets him home at cost <var>4</var>.</li>
</ul>
<p>Thus, the cost <var>4</var> of the third route is the minimum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
1 1000
2 4
3 1000
4 500
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>TLE
</pre>
<p>There is no route that takes not longer than time <var>T = 3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 9
25 8
5 9
4 10
1000 1000
6 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p01204 |
<H1><font color="#000">Problem C:</font> Save the Energy</H1>
<p>
You were caught in a magical trap and transferred to a strange field due to its cause. This field is three-
dimensional and has many straight paths of infinite length. With your special ability, you found where
you can exit the field, but moving there is not so easy. You can move along the paths easily without your
energy, but you need to spend your energy when moving outside the paths. One unit of energy is required
per distance unit. As you want to save your energy, you have decided to find the best route to the exit
with the assistance of your computer.
</p>
<p>
Your task is to write a program that computes the minimum amount of energy required to move between
the given source and destination. The width of each path is small enough to be negligible, and so is your
size.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets. Each data set has the following format:</p>
<pre>
<i>N</i>
<i>x<sub>s</sub> y<sub>s</sub> z<sub>s</sub> x<sub>t</sub> y<sub>t</sub> z<sub>t</sub></i>
<i>x</i><sub>1,1</sub> <i>y</i><sub>1,1</sub> <i>z</i><sub>1,1</sub> <i>x</i><sub>1,2</sub> <i>y</i><sub>1,2</sub> <i>z</i><sub>1,2</sub>
.
.
.
<i>x</i><sub><i>N</i>,1</sub> <i>y</i><sub><i>N</i>,1</sub> <i>z</i><sub><i>N</i>,1</sub> <i>x</i><sub><i>N</i>,2</sub> <i>y</i><sub><i>N</i>,2</sub> <i>z</i><sub><i>N</i>,2</sub>
</pre>
<p>
<i>N</i> is an integer that indicates the number of the straight paths (2 ≤ <i>N</i> ≤ 100). (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>, <i>z<sub>s</sub></i>) and (<i>x<sub>t</sub></i>, <i>y<sub>t</sub></i>, <i>z<sub>t</sub></i>)
denote the coordinates of the source and the destination respectively. (<i>x</i><sub><i>i</i>,1</sub>, <i>y</i><sub><i>i</i>,1</sub>, <i>z</i><sub><i>i</i>,1</sub>) and (<i>x</i><sub><i>i</i>,2</sub>, <i>y</i><sub><i>i</i>,2</sub>, <i>z</i><sub><i>i</i>,2</sub>)
denote the coordinates of the two points that the <i>i</i>-th straight path passes. All coordinates do not exceed 30,000 in their absolute values.
</p>
<p>
The distance units between two points (<i>x<sub>u</sub></i>, <i>y<sub>u</sub></i>, <i>z<sub>u</sub></i>) and (<i>x<sub>v</sub></i>, <i>y<sub>v</sub></i>, <i>z<sub>v</sub></i>) is given by the Euclidean distance as follows:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_saveTheEnergy">
</center>
<p>
It is guaranteed that the source and the destination both lie on paths. Also, each data set contains no
straight paths that are almost but not actually parallel, although may contain some straight paths that are
strictly parallel.
</p>
<p>
The end of input is indicated by a line with a single zero. This is not part of any data set.
</p>
<H2>Output</H2>
<p>
For each data set, print the required energy on a line. Each value may be printed with an arbitrary number
of decimal digits, but should not contain the error greater than 0.001.
</p>
<H2>Sample Input</H2>
<pre>
2
0 0 0 0 2 0
0 0 1 0 0 -1
2 0 0 0 2 0
3
0 5 0 3 1 4
0 1 0 0 -1 0
1 0 1 -1 0 1
3 1 -1 3 1 1
2
0 0 0 3 0 0
0 0 0 0 1 0
3 0 0 3 1 0
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1.414
2.000
3.000
</pre>
|
p03393 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible <strong>diverse</strong> words in lexicographical order.</p>
<p>A word is called <strong>diverse</strong> if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, <code>atcoder</code>, <code>zscoder</code> and <code>agc</code> are diverse words while <code>gotou</code> and <code>connect</code> aren't diverse words.</p>
<p>Given a diverse word <var>S</var>, determine the next word that appears after <var>S</var> in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than <var>S</var>, or determine that it doesn't exist.</p>
<p>Let <var>X = x_{1}x_{2}...x_{n}</var> and <var>Y = y_{1}y_{2}...y_{m}</var> be two distinct strings. <var>X</var> is lexicographically larger than <var>Y</var> if and only if <var>Y</var> is a prefix of <var>X</var> or <var>x_{j} > y_{j}</var> where <var>j</var> is the smallest integer such that <var>x_{j} \neq y_{j}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 26</var></li>
<li><var>S</var> is a diverse word.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the next word that appears after <var>S</var> in the dictionary, or <code>-1</code> if it doesn't exist.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>atcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>atcoderb
</pre>
<p><code>atcoderb</code> is the lexicographically smallest diverse word that is lexicographically larger than <code>atcoder</code>. Note that <code>atcoderb</code> is lexicographically smaller than <code>b</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>abcd
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>zyxwvutsrqponmlkjihgfedcba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>This is the lexicographically largest diverse word, so the answer is <code>-1</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>abcdefghijklmnopqrstuvwzyx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>abcdefghijklmnopqrstuvx
</pre></section>
</div>
</span> |
p03669 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> irregular jigsaw pieces. Each piece is composed of three rectangular parts of width <var>1</var> and various heights joined together. More specifically:</p>
<ul>
<li>The <var>i</var>-th piece is a part of height <var>H</var>, with another part of height <var>A_i</var> joined to the left, and yet another part of height <var>B_i</var> joined to the right, as shown below. Here, the bottom sides of the left and right parts are respectively at <var>C_i</var> and <var>D_i</var> units length above the bottom side of the center part.</li>
</ul>
<p><img alt="" src="https://atcoder.jp/img/agc017/2b6cd7f4500d3621bc18de407f167522.png"/></p>
<p>Snuke is arranging these pieces on a square table of side <var>10^{100}</var>. Here, the following conditions must be held:</p>
<ul>
<li>All pieces must be put on the table.</li>
<li>The entire bottom side of the center part of each piece must touch the front side of the table.</li>
<li>The entire bottom side of the non-center parts of each piece must either touch the front side of the table, or touch the top side of a part of some other piece.</li>
<li>The pieces must not be rotated or flipped.</li>
</ul>
<p>Determine whether such an arrangement is possible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100000</var></li>
<li><var>1 \leq H \leq 200</var></li>
<li><var>1 \leq A_i \leq H</var></li>
<li><var>1 \leq B_i \leq H</var></li>
<li><var>0 \leq C_i \leq H - A_i</var></li>
<li><var>0 \leq D_i \leq H - B_i</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>H</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var> <var>D_1</var>
<var>A_2</var> <var>B_2</var> <var>C_2</var> <var>D_2</var>
:
<var>A_N</var> <var>B_N</var> <var>C_N</var> <var>D_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to arrange the pieces under the conditions, print <code>YES</code>; if it is impossible, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
1 1 0 0
2 2 0 1
3 3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>The figure below shows a possible arrangement.</p>
<p><img alt="" src="https://atcoder.jp/img/agc017/27db184b6924d4cec5077a54b505706a.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2
1 1 0 1
1 1 0 1
1 1 0 1
1 1 0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 4
1 1 0 3
2 3 2 0
1 2 3 0
2 1 0 0
3 2 0 2
1 1 3 0
3 2 0 0
1 3 2 0
1 1 1 3
2 3 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre></section>
</div>
</span> |
p01654 |
<h2>Problem Statement</h2>
<p>
Chelsea is a modern artist. She decided to make her next work with ladders. She wants to combine some ladders and paint some beautiful pattern.
</p>
<p>
A ladder can be considered as a graph called <i>hashigo</i>. There are <var>n</var> <i>hashigos</i> numbered from 0 to <var>n-1</var>.
<i>Hashigo</i> <var>i</var> of length <var>l_i</var> has <var>2 l_{i} + 6</var> vertices <var>v_{i, 0}, v_{i, 1}, ..., v_{i, 2 l_{i} + 5}</var>
and has edges between the pair of vertices <var>(v_{i, j}, v_{i, j+2})</var> (<var>0 \leq j \leq 2 l_i +3</var>) and <var>(v_{i, 2j}, v_{i, 2j+1})</var> (<var>1 \leq j \leq l_i+1</var>).
The figure below is example of a <i>hashigo</i> of length 2. This corresponds to the graph given in the first dataset in the sample input.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_hashigoSama1" height="113" width="349"><br/>
<br/>
</center>
<p>
Two <i>hashigos</i> <var>i</var> and <var>j</var> are combined at position <var>p</var> (<var>0 \leq p \leq l_{i}-1</var>) and <var>q</var> (<var>0 \leq q \leq l_{j}-1</var>) by marged each pair of vertices <var>(v_{i, 2p+2}, v_{j, 2q+2})</var>, <var>(v_{i, 2p+3}, v_{j, 2q+4})</var>, <var>(v_{i, 2p+4}, v_{j, 2q+3})</var> and <var>(v_{i, 2p+5}, v_{j, 2q+5})</var>.
</p>
<p>
Chelsea performs this operation <var>n-1</var> times to combine the <var>n</var> <i>hashigos</i>.
After this operation, the graph should be connected and the maximum degree of the graph should not exceed 4.
The figure below is a example of the graph obtained by combining three <i>hashigos</i>. This corresponds to the graph given in the second dataset in the sample input.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_hashigoSama2" height="325" width="429"><br/>
<br/>
</center>
<p>
Now she decided to paint each vertex by black or white with satisfying the following condition:
</p>
<ul>
<li> The maximum components formed by the connected vertices painted by the same color is less than or equals to <var>k</var>. </li>
</ul>
<p>
She would like to try all the patterns and choose the best. However, the number of painting way can be very huge.
Since she is not good at math nor computing, she cannot calculate the number. So please help her with your superb programming skill!
</p>
<h2>Input</h2>
<p>
The input contains several datasets, and each dataset is in the following format.
</p>
<pre>
<var>n</var> <var>k</var>
<var>l_0</var> <var>l_1</var> ... <var>l_{n-1}</var>
<var>f_0</var> <var>p_0</var> <var>t_0</var> <var>q_0</var>
...
<var>f_{n-2}</var> <var>p_{n-2}</var> <var>t_{n-2}</var> <var>q_{n-2}</var>
</pre>
<p>
The first line contains two integers <var>n</var> (<var>1 \leq n \leq 30</var>) and <var>k</var> (<var>1 \leq k \leq 8</var>).
</p>
<p>
The next line contains <var>n</var> integers <var>l_i</var> (<var>1 \leq l_i \leq 30</var>), each denotes the length of <i>hashigo</i> <var>i</var>.
</p>
<p>
The following <var>n-1</var> lines each contains four integers <var>f_i</var> (<var>0 \leq f_i \leq n-1</var>), <var>p_i</var> (<var>0 \leq p_i \leq l_{f_i}-1</var>), <var>t_i</var> (<var>0 \leq t_i \leq n-1</var>), <var>q_i</var> (<var>0 \leq q_i \leq l_{t_i}-1</var>). It represents the <i>hashigo</i> <var>f_i</var> and the <i>hashigo</i> <var>t_i</var> are combined at the position <var>p_i</var> and the position <var>q_i</var>. You may assume that the graph obtained by combining <var>n</var> <i>hashigos</i> is connected and the degree of each vertex of the graph does not exceed 4.
</p>
<p>
The last dataset is followed by a line containing two zeros.
</p>
<h2>Output</h2>
<p>
For each dataset, print the number of different colorings modulo 1,000,000,007 in a line.
</p>
<h2>Sample Input</h2>
<pre>
1 5
2
3 7
2 3 1
0 1 1 0
1 2 2 0
2 8
5 6
0 2 1 2
2 8
1 1
0 0 1 0
2 2
2 2
0 1 1 0
2 3
3 3
0 2 1 1
2 4
3 1
1 0 0 1
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
708
1900484
438404500
3878
496
14246
9768
</pre> |
p00946 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem A
Rearranging a Sequence
</h2>
<p>
You are given an ordered sequence of integers, ($1, 2, 3, ..., n$). Then, a number of requests will be given. Each request specifies an integer in the sequence. You need to move the specified integer to the head of the sequence, leaving the order of the rest untouched. Your task is to find the order of the elements in the sequence after following all the requests successively.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following form.<br/>
<br/>
$n$ $m$<br/>
$e_1$<br/>
...<br/>
$e_m$<br/>
</p>
<p>
The integer $n$ is the length of the sequence ($1 \leq n \leq 200000$). The integer $m$ is the number of requests ($1 \leq m \leq 100000$). The following $m$ lines are the requests, namely $e_1, ..., e_m$, one per line. Each request $e_i$ ($1 \leq i \leq m$) is an integer between 1 and $n$, inclusive, designating the element to move. Note that, the integers designate the integers themselves to move, not their positions in the sequence.
</p>
<h3>Output</h3>
<p>
Output the sequence after processing all the requests. Its elements are to be output, one per line, in the order in the sequence.
</p>
<h3>Sample Input 1</h3>
<pre>5 3
4
2
5</pre>
<h3>Sample Output 1</h3>
<pre>5
2
4
1
3</pre>
<br/>
<h3>Sample Input 2</h3>
<pre>10 8
1
4
7
3
4
10
1
3</pre>
<h3>Sample Output 2</h3>
<pre>3
1
10
4
7
2
5
6
8
9</pre>
<p>
In Sample Input 1, the initial sequence is (1, 2, 3, 4, 5). The first request is to move the integer 4 to the head, that is, to change the sequence to (4, 1, 2, 3, 5). The next request to move the integer 2 to the head makes the sequence (2, 4, 1, 3, 5). Finally, 5 is moved to the head, resulting in (5, 2, 4, 1, 3).
</p> |
p00415 | <h1>ããžãã</h1>
ã
<p>
ã¢ã€ã
èµ€ã¹ãåºã§ã¯ãããžãããšåŒã°ãããŠããŒã¯ãªããããã販売ããŠããŸããåããã«ã¯ãå·Šããå³ãžåãã£ãŠ1åã«$N$åã®æ°åã䞊ãã§ããŸãããã ããæžãããŠããã®ã¯ïŒããïŒãŸã§ã®æ°åã§ãã
</p>
<p>
ããã®è³Œå
¥è
ã¯ããããã®æ°åãã$K$åã®æ°åãæ¶å»ããæ®ã£ã$N-K$åã®æ°åãå·Šããé çªã«äžŠã¹ãŠã§ããæ°ããã€ã³ããšããŠç²åŸããããšãã§ããŸããããšãã°$K=3$ã®ãšããããã«$1414213$ãšæžãããŠããã°ãå·Šãã$1$ã$1$ã$2$ãéžæããŠæ¶å»ããããšã§$4413$ãã€ã³ããç²åŸããããšãã§ããŸãã
</p>
<p>
æ°åã®åãšæŽæ°$K$ãäžãããããšããç²åŸã§ãããã€ã³ãã®æå€§å€ãåºåããããã°ã©ã ãäœæããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$N$ $K$
$a_1$ $a_2$ ... $a_N$
</pre>
<p>
ïŒè¡ç®ã«æ°åã®æ°$N$ ($1 \leq N \leq 200,000$)ãšæŽæ°$K$ ($0 \leq K < N$)ãäžãããããïŒè¡ç®ã«ããã«æžãããŠãã$N$åã®æ°$a_i$ ($1 \leq a_i \leq 9$)ãäžããããã
</p>
<h2>åºå</h2>
<p>
ãã€ã³ãã®æå€§å€ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
7 3
1 4 1 4 2 1 3
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
4423
</pre>
<h3>å
¥åäŸïŒ</h3>
<pre>
4 1
1 1 9 9
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
199
</pre>
|
p02428 | <h1>Enumeration of Subsets II</h1>
<p>
You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$.
Print all sets, each of which is a subset of $U$ and includes $T$ as a subset.
Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$
</pre>
<p>
$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.
</p>
<h2>Output</h2>
<p>
Print the subsets ordered by their decimal integers. Print a subset in the following format.
</p>
<pre>
$d$: $e_0$ $e_1$ ...
</pre>
<p>
Print '<span>:</span>' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 18$</li>
<li>$0 \leq k \leq n$</li>
<li>$0 \leq b_i < n$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4
2 0 2
</pre>
<h2>Sample Output 1</h2>
<pre>
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3
</pre>
|
p02582 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have weather records at AtCoder Town for some consecutive three days. A string of length <var>3</var>, <var>S</var>, represents the records - if the <var>i</var>-th character is <code>S</code>, it means it was sunny on the <var>i</var>-th day; if that character is <code>R</code>, it means it was rainy on that day.</p>
<p>Find the maximum number of consecutive rainy days in this period.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>|S| = 3</var></li>
<li>Each character of <var>S</var> is <code>S</code> or <code>R</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of consecutive rainy days in the period.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>RRS
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We had rain on the <var>1</var>-st and <var>2</var>-nd days in the period. Here, the maximum number of consecutive rainy days is <var>2</var>, so we should print <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>SSS
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>It was sunny throughout the period. We had no rainy days, so we should print <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>RSR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p>We had rain on the <var>1</var>-st and <var>3</var>-rd days - two "streaks" of one rainy day, so we should print <var>1</var>.</p></section>
</div>
</span> |
p00045 |
<H1>Sum and Average</H1>
<p>
販売å䟡ãšè²©å£²æ°éãèªã¿èŸŒãã§ã販売éé¡ã®ç·åèšãšè²©å£²æ°éã®å¹³åãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
販売å䟡,販売æ°é
販売å䟡,販売æ°é
:
:
</pre>
<p>
ã«ã³ãã§åºåããã販売å䟡ãšè²©å£²æ°éã®çµããè€æ°è¡ã«æž¡ã£ãŠäžããããŸããå
¥åãããå€ã¯ãã¹ãŠ 0 ä»¥äž 1,000 以äžã§ã販売å䟡ãšè²©å£²æ°éã®çµã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ïŒè¡ç®ã«è²©å£²éé¡ã®ç·åèšïŒæŽæ°ïŒãïŒè¡ç®ã«è²©å£²æ°éã®å¹³å(æŽæ°ïŒãåºåããŠãã ããã
販売æ°éã®å¹³åã«ç«¯æ°ïŒå°æ°ç¹ä»¥äžã®æ°ïŒãçããå Žåã¯å°æ°ç¹ä»¥äžç¬¬ 1 äœãåæšäºå
¥ããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
100,20
50,10
70,35
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4950
22
</pre>
|
p02078 | <h1>A: Undo Swapping</h1>
<h2>å顿</h2>
<p>$N$ è¡ $N$ åã®ãã¹ç®ã®äžã« $N$ åã®ç³ã眮ããŠãããŸãã
$i$ çªç®ã®ç³ã¯ $R_i$ è¡ $C_i$ åã«ãããŸããåããã¹ã«è€æ°ã®ç³ã眮ãããŠããããšã¯ãããŸããã</p>
<p>ããªãã¯æ¬¡ã®2çš®é¡ã®æäœãä»»æã®é ã§ä»»æã®åæ°è¡ãããšãã§ããŸãã</p>
<ol>
<li>2ã€ã®è¡ãéžã³ããããã亀æãã</li>
<li>2ã€ã®åãéžã³ããããã亀æããã</li>
</ol>
<p>$N$ åã®ç³ãããã¹ç®ã®å·Šäžããå³äžã«ãããŠã®å¯Ÿè§ç·äžã«äžŠã¹ãããšãåºæ¥ãããå€å®ããããã°ã©ã ãäœæããŠãã ããã
å¯èœãªå Žåã¯å¿
èŠãªæå°ã®æäœåæ°ãåºåããŠãã ãããäžå¯èœãªå Žå㯠$-1$ ãåºåããŠãã ããã</p>
<p>ãã ãã<strong>察è§ç·äžã«äžŠã¶ç³ã®é çªã¯é¢ä¿ç¡ã</strong> ããšã«æ³šæããŠãã ããã
äŸãã°ã1çªç®ã®ç³ã1è¡1åã®ãã¹ã«é
眮ããå¿
èŠã¯ãããŸããã</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åã¯å
šãп޿°</li>
<li>$1 \leq N \leq 10^5$</li>
<li>$1 \leq R_i, C_i \leq N$ $(1 \leq i \leq N)$</li>
<li>$R_i \ne R_j$ ãŸã㯠$C_i \ne C_j$ $(i \ne j)$</li>
</ul>
<h2>å
¥å</h2>
<p>å
¥åã¯æšæºå
¥åãã以äžã®åœ¢åŒã§äžããããŸãã</p>
<pre>
$N$
$R_1$ $C_1$
$R_2$ $C_2$
$\vdots$
$R_N$ $C_N$</pre>
<h2>åºå</h2>
<p>å顿äžã®æ¡ä»¶ãæºãããå Žåã¯ãå¿
èŠãªæå°ã®æäœåæ°ãäžè¡ã«åºåããŠãã ããã
äžå¯èœã§ããå Žåã$-1$ ãäžè¡ã«åºåããŠãã ããã</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>3
2 1
3 2
1 3
</pre>
<h3>åºåäŸ1</h3>
<pre>2
</pre>
<p>åãã«å1ãšå3ãå
¥ãæ¿ããæ¬¡ã«è¡2ãšè¡3ãå
¥ãæ¿ããããšã§éæã§ããŸãã
1åã®æäœã§æ¡ä»¶ãæºããããšã¯åºæ¥ãªããããçãã¯2ãšãªããŸãã</p>
<h3>å
¥åäŸ2</h3>
<pre>3
1 1
1 2
3 3
</pre>
<h3>åºåäŸ2</h3>
<pre>-1
</pre>
<h3>å
¥åäŸ3</h3>
<pre>3
1 1
2 2
3 3
</pre>
<h3>åºåäŸ3</h3>
<pre>0
</pre>
<h3>å
¥åäŸ4</h3>
<pre>5
4 1
3 5
5 4
1 2
2 3
</pre>
<h3>åºåäŸ4</h3>
<pre>4
</pre>
|
p00550 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h2>éééè³(Train Fare)</h2>
<p>
JOI åœã«ã¯ $N$ åã®éœåžãããïŒãããã $1, 2, ..., N$ ã®çªå·ãä»ããããŠããïŒéœåž 1 ã¯JOI åœã®éŠéœã§ããïŒ
</p>
<p>
ãŸãïŒJOI åœã«ã¯ééäŒç€Ÿãã²ãšã€ã ãããïŒãã®äŒç€Ÿã¯ $M$ åã®è·¯ç·ãéè¡ããŠããïŒãããã®è·¯ç·ã«ã¯ãããã $1, 2, ..., M$ ã®çªå·ãä»ããããŠããïŒ$i$ çªç® $(1 \leq i \leq M)$ ã®è·¯ç·ã¯éœåž $U_i$ ãšéœåž $V_i$ ãåæ¹åã«çµãã§ããïŒéœåžãšéœåžã®éãéé以å€ã§ç§»åããããšã¯ã§ããªãïŒãŸãïŒã©ã®éœåžããã©ã®éœåžãžãããã€ãã®è·¯ç·ãä¹ãç¶ãã§ç§»åããããšãã§ããããã«ãªã£ãŠããïŒ
</p>
<p>
çŸåšïŒã©ã®è·¯ç·ã®éè³ã 1 åã§ããïŒçµå¶äžæ¯ã«é¥ã£ãééäŒç€Ÿã¯ïŒä»åŸ $Q$ 幎éãããŠããã€ãã®è·¯ç·ã®éè³ãå€äžãããèšç»ãç«ãŠãïŒãã®èšç»ã§ã¯ïŒèšç»éå§ãã $j$ 幎ç®$(1 \leq j \leq Q)$ ã®å¹Žåãã«è·¯ç· $R_j$ ã®éè³ã 1 åãã 2 åã«å€äžãããäºå®ã§ããïŒå€äžããããè·¯ç·ã®éè³ã¯ïŒãã®åŸãã£ãš2 åã®ãŸãŸã§ããïŒåã³å€äžãããããšã¯ãªãïŒ
</p>
<p>
ãšããã§ïŒãã®ééäŒç€Ÿã§ã¯ïŒæ¯å¹ŽïŒåéœåžã®äœæ°ã®æºè¶³åºŠèª¿æ»ãè¡ã£ãŠããïŒèšç»éå§åã¯ïŒã©ã®éœåžã®äœæ°ããã®ééäŒç€Ÿã«æºè¶³ããŠãããïŒå€äžãã«ãã£ãŠäžæºãæã€äœæ°ãçŸããå¯èœæ§ãããïŒ
</p>
<p>
ããããã®å¹Žã®æºè¶³åºŠèª¿æ»ã¯ïŒãã®å¹Žã®å€äžãã®å®æœåŸã«è¡ãïŒãããã£ãŠïŒ $j$ 幎ç®$(1 \leq j \leq Q)$ ã®æºè¶³åºŠèª¿æ»ã¯ïŒè·¯ç· $R_1, R_2, ... , R_j$ ã®éè³ã®å€äžãã¯å®äºãïŒãã以å€ã®è·¯ç·ã®éè³ã¯å€äžããããŠããªãç¶æ
ã§è¡ãããããšã«ãªãïŒ $j$ 幎ç®$(1 \leq j \leq Q)$ ã®æºè¶³åºŠèª¿æ»ã§ã¯ïŒéœåž $k$ $(2 \leq k \leq N)$ ã®äœæ°ã¯ïŒä»¥äžã®æ¡ä»¶ãæºãããããšãïŒãããŠãã®ãšãã«éãééäŒç€Ÿã«äžæºãæ±ãïŒ
</p>
<ul>
<li> ãã®æã®éè³ã§éœåž $k$ ããéŠéœã§ããéœåž $1$ ãžç§»åãããšãã®è²»çšã®æå°å€ãïŒèšç»éå§åã®éè³ã§éœåž $k$ ããéœåž $1$ ãžç§»åãããšãã®è²»çšã®æå°å€ããã倧ããïŒ
</li>
</ul>
<p>
ãã ãïŒããã€ãã®è·¯ç·ã䜿ã£ãŠç§»åãããšãã®è²»çšã¯ïŒããããã®è·¯ç·ã®éè³ã®åèšã§ããïŒãŸãïŒéœåž $1$ ã®äœæ°ãééäŒç€Ÿã«å¯ŸããŠäžæºãæ±ãããšã¯ãªãïŒå€äžãåŸã®éè³ã§æå°ã®è²»çšãéæããçµè·¯ã¯ïŒèšç»éå§åã®éè³ã§æå°ã®è²»çšãéæããçµè·¯ãšç°ãªãå¯èœæ§ãããããšã«æ³šæããïŒ
</p>
<p>
èšç»ã®å®è¡ã«å
ç«ã£ãŠïŒä»åŸ $Q$ 幎éã®äœæ°ã®æºè¶³åºŠèª¿æ»ããããã«ãããŠïŒééäŒç€Ÿã«äžæºãæ±ãäœæ°ãããéœåžã®æ°ãèšç®ããŠããããïŒ
</p>
<h2>課é¡</h2>
<p>
JOI åœã®ééè·¯ç·ã®æ
å ±ãšïŒéè³ã®å€äžãèšç»ãäžãããããšãïŒããããã®æºè¶³åºŠèª¿æ»ã«ãããŠééäŒç€Ÿã«äžæºãæ±ãäœæ°ãããéœåžã®æ°ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒ3 åã®æŽæ° $N, M, Q$ ã空çœãåºåããšããŠæžãããŠããïŒãããã¯ïŒJOI åœã«ã¯ $N$ åã®éœåžãš $M$ åã®è·¯ç·ãããïŒéè³ã®å€äžãèšç»ã $Q$ 幎éã«æž¡ãããšã衚ããŠããïŒ</li>
<li> ç¶ã $M$ è¡ã®ãã¡ã® $i$ è¡ç®$(1 \leq i \leq M)$ ã«ã¯ïŒ2 åã®æŽæ° $U_i$, $V_i$ ã空çœãåºåããšããŠæžãããŠããïŒãããã¯ïŒ$i$ çªç®ã®è·¯ç·ãéœåž $U_i$ ãšéœåž $V_i$ ãçµãã§ããããšã衚ããŠããïŒ</li>
<li> ç¶ã $Q$ è¡ã®ãã¡ã® $j$ è¡ç®$(1 \leq j \leq Q)$ ã«ã¯ïŒæŽæ° $R_j$ ãæžãããŠããïŒããã¯ïŒèšç»ã® $j$ 幎ç®ã«è·¯ç· $R_j$ ã®éè³ãå€äžãããããšã衚ããŠããïŒ</li>
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã« $Q$ è¡ã§åºåããïŒ $j$ è¡ç®$(1 \leq j \leq Q)$ ã«ã¯ïŒ $j$ 幎ç®ã®æºè¶³åºŠèª¿æ»ã§äžæºãæ±ãäœæ°ãããéœåžã®æ°ãåºåããïŒ
</p>
<h2>å¶é</h2>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li> $2 \leq N \leq 100 000$ </li>
<li> $1 \leq Q \leq M \leq 200 000$ </li>
<li> $1 \leq U_i \leq N$ $(1 \leq i \leq M)$ </li>
<li> $1 \leq V_i \leq N$ $(1 \leq i \leq M)$ </li>
<li> $U_i \ne V_i$ $(1 \leq i \leq M)$ </li>
<li> $1 \leq R_j \leq M$ $(1 \leq j \leq Q)$ </li>
<li> $R_j \ne R_k$ $(1 \leq j < k \leq Q)$ </li>
<li> ã©ã®2 ã€ã®éœåžã«ã€ããŠãïŒããããçŽæ¥çµã¶è·¯ç·ã¯ 1 å以äžã§ããïŒ </li>
<li> ã©ã®éœåžã«ã€ããŠãïŒãã®éœåžããéœåž 1 ãŸã§ããã€ãã®è·¯ç·ã䜿ã£ãŠç§»åããããšãã§ããïŒ </li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
5 6 5
1 2
1 3
4 2
3 2
2 5
5 3
5
2
4
1
3
</pre>
<h3>åºåäŸ1</h3>
<pre>
0
2
2
4
4
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒèšç»éå§åïŒåã³ããããã®æºè¶³åºŠèª¿æ»ã®æç¹ã§ã®ããããã®éœåžããéœåž $1$ ãžã®éè³ã¯ïŒä»¥äžã®è¡šã®ããã«ãªãïŒ
</p>
<table>
<tr><td>æç¹</td><td>éœåž2 </td> <td>éœåž3 </td> <td>éœåž4 </td> <td>éœåž5 </td></tr>
<tr><td>èšç»éå§å </td><td>1</td> <td>1</td><td> 2</td><td> 2</td></tr>
<tr><td>1 幎ç®</td><td>1</td><td> 1</td><td> 2</td><td> 2</td></tr>
<tr><td>2 幎ç®</td><td>1</td><td> 2</td><td> 2</td><td> 3</td></tr>
<tr><td>3 幎ç®</td><td>1 </td><td>2 </td><td>2 </td><td>3</td></tr>
<tr><td>4 幎ç®</td><td>2 </td><td>2 </td><td>3 </td><td>3</td></tr>
<tr><td>5 幎ç®</td><td>2 </td><td>2 </td><td>4 </td><td>3</td></tr>
</table>
<br>
<p>
äŸãã°ïŒ3 幎ç®ã®æºè¶³åºŠèª¿æ»ã§ã¯ïŒéœåž $3$ ãšéœåž $5$ ã®äœæ°ãäžæºãæ±ãã®ã§ïŒåºåã® 3 è¡ç®ã«ã¯ 2 ãåºåããïŒ
</p>
<h3>å
¥åäŸ2</h3>
<pre>
4 6 6
1 2
1 3
1 4
2 3
2 4
3 4
1
4
2
5
3
6
</pre>
<h3>åºåäŸ2</h3>
<pre>
1
1
2
2
3
3
</pre>
<h3>å
¥åäŸ3</h3>
<pre>
2 1 1
1 2
1
</pre>
<h3>åºåäŸ3</h3>
<pre>
1
</pre>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf">第15å æ¥æ¬æ
å ±ãªãªã³ããã¯æ¬éž èª²é¡ 2016 幎 2 æ 14 æ¥</a>
</p>
</div>
|
p02097 |
<h2>J: Horizontal-Vertical Permutation</h2>
<h3>Problem Statement</h3>
<p>You are given a positive integer <var>N</var>. Your task is to determine if there exists a square matrix <var>A</var> whose dimension is <var>N</var> that satisfies the following conditions and provide an example of such matrices if it exists. <var>A_{i, j}</var> denotes the element of matrix <var>A</var> at the <var>i</var>-th row and <var>j</var>-th column.</p>
<ul>
<li> For all <var>i, j</var> <var>(1 \leq i, j \leq N)</var>, <var>A_{i, j}</var> is an integer that satisfies <var>1 \leq A_{i, j} \leq 2N - 1</var>.</li>
<li> For all <var>k = 1, 2, ..., N</var>, a set consists of <var>2N - 1</var> elements from the <var>k</var>-th row or <var>k</var>-th column is <var>\{1, 2, ..., 2N - 1\}</var>.</li>
</ul>
<p>If there are more than one possible matrices, output any of them.</p>
<h3>Input</h3>
<pre><var>N</var></pre>
<p>Input consists of one line, which contains the integer <var>N</var> that is the size of a square matrix to construct.</p>
<h3>Constraint</h3>
<ul>
<li> <var>N</var> is an integer that satisfies <var>1 \leq N \leq 500</var>.</li>
</ul>
<h3>Output</h3>
<p>Output <code>No</code> in a single line if such a square matrix does not exist.</p>
<p>If such a square matrix <var>A</var> exists, output <code>Yes</code> on the first line and <var>A</var> after that. More specifically, follow the following format.</p>
<pre>
Yes
<var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var>
<var>:</var>
<var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var>
</pre>
<h3>Sample Input 1</h3>
<pre>4</pre>
<h3>Output for Sample Input 1</h3>
<pre>
Yes
2 6 3 7
4 5 2 1
1 7 5 6
5 3 4 2
</pre>
<h3>Sample Input 2</h3>
<pre>3</pre>
<h3>Output for Sample Input 2</h3>
<pre>No</pre>
|
p00100 |
<H1>Sale Result</H1>
<p>
There is data on sales of your company. Your task is to write a program which identifies good workers.
</p>
<p>
The program should read a list of data where each item includes the employee ID <i>i</i>, the amount of sales <i>q</i> and the corresponding unit price <i>p</i>. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that <i>n</i> < 4000, and each employee has an unique ID. The unit price <i>p</i> is less than or equal to 1,000,000 and the amount of sales <i>q</i> is less than or equal to 100,000.
</p>
<H2>Input</H2>
<p>
The input consists of several datasets. The input ends with a line including a single 0. Each dataset consists of:
</p>
<pre class="exp">
<i>n</i> (the number of data in the list)
<i>i</i> <i>p</i> <i>q</i>
<i>i</i> <i>p</i> <i>q</i>
:
:
<i>i</i> <i>p</i> <i>q</i>
</pre>
<H2>Output</H2>
<p>
For each dataset, print a list of employee IDs or a text "NA"
</p>
<H2>Sample Input</H2>
<pre>
4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
2
1001 100 3
1005 1000 100
2
2013 5000 100
2013 5000 100
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1001
1003
NA
2013
</pre>
|
p01341 |
<H1><font color="#000">Problem C: </font> Save your cats</H1>
<p>
Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them.
</p>
<p>
One day, an evil witch visited the village. She envied the cats for being loved by everyone. She drove magical piles in his garden and enclosed the cats with magical fences running between the piles. She said âYour cats are shut away in the fences until they become ugly old cats.â like a curse and went away.
</p>
<p>
Nicholas tried to break the fences with a hummer, but the fences are impregnable against his effort. He went to a church and asked a priest help. The priest looked for how to destroy the magical fences in books and found they could be destroyed by holy water. The Required amount of the holy water to destroy a fence was proportional to the length of the fence. The holy water was, however, fairly expensive. So he decided to buy exactly the minimum amount of the holy water required to save all his cats. How much holy water would be required?
</p>
<H2>Input</H2>
<p>
The input has the following format:
</p>
<p>
<i>N M</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub></br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub></br>
<i>p</i><sub>1</sub> <i>q</i><sub>1</sub><br>
.<br>
.<br>
.<br>
<i>p</i><sub><i>M</i></sub> <i>q</i><sub><i>M</i></sub><br>
</p>
<p>
The first line of the input contains two integers <i>N</i> (2 ≤ <i>N</i> ≤ 10000) and <i>M</i> (1 ≤ <i>M</i>). <i>N</i> indicates the number of magical piles and <i>M</i> indicates the number of magical fences. The following <i>N</i> lines describe the coordinates of the piles. Each line contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> (-10000 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 10000). The following <i>M</i> lines describe the both ends of the fences. Each line contains two integers <i>p<sub>j</sub></i> and <i>q<sub>j</sub></i> (1 ≤ <i>p<sub>j</sub></i>, <i>q<sub>j</sub></i> ≤ <i>N</i>). It indicates a fence runs between the <i>p<sub>j</sub></i>-th pile and the <i>q<sub>j</sub></i>-th pile.
</p>
<p>
You can assume the following:
</p>
<ul>
<li> No Piles have the same coordinates.</li>
<li> A pile doesnât lie on the middle of fence.</li>
<li> No Fences cross each other.</li>
<li> There is at least one cat in each enclosed area.</li>
<li> It is impossible to destroy a fence partially.</li>
<li> A unit of holy water is required to destroy a unit length of magical fence.</li>
</ul>
<H2>Output</H2>
<p>
Output a line containing the minimum amount of the holy water required to save all his cats. Your program may output an arbitrary number of digits after the decimal point. However, the absolute error should be 0.001 or less.
</p>
<H2>Sample Input 1</H2>
<pre>
3 3
0 0
3 0
0 4
1 2
2 3
3 1
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
3.000
</pre>
<H2>Sample Input 2</H2>
<pre>
4 3
0 0
-100 0
100 0
0 100
1 2
1 3
1 4
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
0.000
</pre>
<H2>Sample Input 3</H2>
<pre>
6 7
2 0
6 0
8 2
6 3
0 5
1 7
1 2
2 3
3 4
4 1
5 1
5 4
5 6
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
7.236
</pre>
<H2>Sample Input 4</H2>
<pre>
6 6
0 0
0 1
1 0
30 0
0 40
30 40
1 2
2 3
3 1
4 5
5 6
6 4
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>
31.000
</pre>
|
p03686 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>M</var> chairs arranged in a line. The coordinate of the <var>i</var>-th chair <var>(1 †i †M)</var> is <var>i</var>.</p>
<p><var>N</var> people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the <var>i</var>-th person wishes to sit in a chair whose coordinate is not greater than <var>L_i</var>, or not less than <var>R_i</var>. Naturally, only one person can sit in the same chair.</p>
<p>It may not be possible for all of them to sit in their favorite chairs, if nothing is done.
Aoki, who cares for the health of the people of the Takahashi clan, decides to provide additional chairs so that all of them can sit in chairs at their favorite positions.</p>
<p>Additional chairs can be placed at arbitrary real coordinates. Find the minimum required number of additional chairs.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N,M †2 à 10^5</var></li>
<li><var>0 †L_i < R_i †M + 1(1 †i †N)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>L_1</var> <var>R_1</var>
<var>:</var>
<var>L_N</var> <var>R_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum required number of additional chairs.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
0 3
2 3
1 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>The four people can sit in chairs at the coordinates <var>3</var>, <var>2</var>, <var>1</var> and <var>4</var>, respectively, and no more chair is needed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 6
0 7
1 5
3 6
2 7
1 6
2 6
3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>If we place additional chairs at the coordinates <var>0</var> and <var>2.5</var>, the seven people can sit at coordinates <var>0</var>, <var>5</var>, <var>3</var>, <var>2</var>, <var>6</var>, <var>1</var> and <var>2.5</var>, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 1
1 2
1 2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6 6
1 6
1 6
1 5
1 5
2 6
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>2
</pre></section>
</div>
</span> |
p02994 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have <var>N</var> apples, called Apple <var>1</var>, Apple <var>2</var>, Apple <var>3</var>, ..., Apple <var>N</var>. The <em>flavor</em> of Apple <var>i</var> is <var>L+i-1</var>, which can be negative.</p>
<p>You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.</p>
<p>You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.</p>
<p>You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining <var>N-1</var> apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the <var>N</var> apples.</p>
<p>Find the flavor of the apple pie made of the remaining <var>N-1</var> apples when you choose the apple to eat as above.</p>
<p>We can prove that this value is uniquely determined.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200</var></li>
<li><var>-100 \leq L \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>L</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the flavor of the apple pie made of the remaining <var>N-1</var> apples when you optimally choose the apple to eat.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>18
</pre>
<p>The flavors of Apple <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, and <var>5</var> are <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var>, and <var>6</var>, respectively. The optimal choice is to eat Apple <var>1</var>, so the answer is <var>3+4+5+6=18</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The flavors of Apple <var>1</var>, <var>2</var>, and <var>3</var> are <var>-1</var>, <var>0</var>, and <var>1</var>, respectively. The optimal choice is to eat Apple <var>2</var>, so the answer is <var>(-1)+1=0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>30 -50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1044
</pre></section>
</div>
</span> |
p01711 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
color: #333333;
display: block;
padding: 8.5px;
margin: 0 0 9px;
font-size: 12px;
line-height: 18px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}</style><div class="part"><h3>Problem Statement</h3><p>Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.)
</p>
<p>"<samp>Filtering</samp>" is an operation to determine the color of a pixel from the colors of itself and its six neighbors. Examples of filterings are shown below.
</p>
<p>Example 1: Color a pixel in white when all of its neighboring pixels are white. Otherwise the color will not change.
</p>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_NoiseCanceller" height="235" width="488" />
</p>
<p>Performing this operation on all the pixels simultaneously results in "<samp>noise canceling,</samp>" which removes isolated black pixels.
</p>
<p>Example 2: Color a pixel in white when its all neighboring pixels are black. Otherwise the color will not change.
</p>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_EdgeDetector" height="235" width="488" />
</p>
<p>Performing this operation on all the pixels simultaneously results in "<samp>edge detection,</samp>" which leaves only the edges of filled areas.
</p>
<p>Example 3: Color a pixel with the color of the pixel just below it, ignoring any other neighbors.
</p>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_MoveUp" height="487" width="489" />
</p>
<p>Performing this operation on all the pixels simultaneously results in "<samp>shifting up</samp>" the whole image by one pixel.
</p>
<p>Applying some filter, such as "<samp>noise canceling</samp>" and "<samp>edge detection,</samp>" twice to any image yields the exactly same result as if they were applied only once.
We call such filters <i>idempotent</i>. The "<samp>shifting up</samp>" filter is not idempotent since every repeated application shifts the image up by one pixel.
</p>
<p>Your task is to determine whether the given filter is idempotent or not.
</p>
</div><div class="part"><h3>Input</h3>
<p>The input consists of multiple datasets. The number of dataset is less than $100$.
Each dataset is a string representing a filter and has the following format (without spaces between digits).
</p>
<blockquote style="font-size:14pt"> $c_0c_1\cdots{}c_{127}$</blockquote>
<p>$c_i$ is either '<samp>0</samp>' (represents black) or '<samp>1</samp>' (represents white), which indicates the output of the filter for a pixel when the binary representation of the pixel and its neighboring six pixels is $i$.
The mapping from the pixels to the bits is as following:
</p>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_Bit" height="235" width="226" />
</p>
<p>and the binary representation $i$ is defined as $i = \sum_{j=0}^6{\mathit{bit}_j \times 2^j}$,
where $\mathit{bit}_j$ is $0$ or $1$ if the corresponding pixel is in black or white, respectively.
Note that the filter is applied on the center pixel, denoted as bit 3.
</p>
<p>The input ends with a line that contains only a single "<samp>#</samp>".
</p>
</div><div class="part"><h3>Output</h3>
<p>For each dataset, print "<samp>yes</samp>" in a line if the given filter is idempotent, or "<samp>no</samp>" otherwise (quotes are for clarity).
</p>
</div><div class="part"><h3>Sample Input</h3>
<pre>00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111
10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111
01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
#</pre>
</div><div class="part"><h3>Output for the Sample Input</h3>
<pre>yes
yes
no</pre>
</div> |
p00803 |
<H1><font color="#000">Problem A:</font> Starship Hakodate-maru</H1>
<p>
The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.
</p>
<p>
There, however, is an inconvenience. The shapes of the fuel containers <i>#</i>1 and <i>#</i>2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should be either empty or filled according to their shapes. Otherwise, the fuel balls become extremely unstable and may explode in the fuel containers. Thus, the number of fuel balls for the container <i>#</i>1 should be a cubic number (<i>n</i><sup>3</sup> for some <i>n</i> = 0, 1, 2, 3,... ) and that for the container <i>#</i>2 should be a tetrahedral number ( <i>n</i>(<i>n</i> + 1)(<i>n</i> + 2)/6 for some <i>n</i> = 0, 1, 2, 3,... ).
</p>
<p>
Hakodate-maru is now at the star base Goryokaku preparing for the next mission to create a precise and detailed chart of stars and interstellar matters. Both of the fuel containers are now empty. Commander Parus of Goryokaku will soon send a message to Captain Future of Hakodate-maru on how many fuel balls Goryokaku can supply. Captain Future should quickly answer to Commander Parus on how many fuel balls she requests before her ship leaves Goryokaku. Of course, Captain Future and her omcers want as many fuel balls as possible.
</p>
<p>
For example, consider the case Commander Parus offers 151200 fuel balls. If only the fuel container <i>#</i>1 were available (i.e. ifthe fuel container <i>#</i>2 were unavailable), at most 148877 fuel balls could be put into the fuel container since 148877 = 53 × 53 × 53 < 151200 < 54 × 54 × 54 . If only the fuel container <i>#</i>2 were available, at most 147440 fuel balls could be put into the fuel container since 147440 = 95 × 96 × 97/6 < 151200 < 96 × 97 × 98/6 . Using both of the fuel containers <i>#</i>1 and <i>#</i>2, 151200 fuel balls can be put into the fuel containers since 151200 = 39 × 39 × 39 + 81 × 82 × 83/6 . In this case, Captain Future's answer should be "151200".
</p>
<p>
Commander Parus's offer cannot be greater than 151200 because of the capacity of the fuel storages of Goryokaku. Captain Future and her omcers know that well.
</p>
<p>
You are a fuel engineer assigned to Hakodate-maru. Your duty today is to help Captain Future with calculating the number of fuel balls she should request.
</p>
<H2>Input</H2>
<p>
The input is a sequence of at most 1024 positive integers. Each line contains a single integer. The sequence is followed by a zero, which indicates the end of data and should not be treated as input. You may assume that none of the input integers is greater than 151200.
</p>
<H2>Output</H2>
<p>
The output is composed of lines, each containing a single integer. Each output integer should be the greatest integer that is the sum of a nonnegative cubic number and a nonnegative tetrahedral number and that is not greater than the corresponding input number. No other characters should appear in the output.
</p>
<H2>Sample Input</H2>
<pre>
100
64
50
20
151200
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
99
64
47
20
151200
</pre>
|
p01506 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Digit</H1>
<p>
For a positive integer <var>a</var>, let <var>S(a)</var> be the sum of the digits in base <var>l</var>.
Also let <var>L(a)</var> be the minimum <var>k</var> such that <var>S^k(a)</var> is less than or equal to <var>l-1</var>.
Find the minimum <var>a</var> such that <var>L(a) = N</var> for a given <var>N</var>, and print <var>a</var> modulo <var>m</var>.
</p>
<H2>Input</H2>
<p>
The input contains several test cases, followed by a line containing "0 0 0".
Each test case is given by a line with three integers <var>N</var>, <var>m</var>, <var>l</var> (<var>0 \leq N \leq 10^5</var>, <var>1 \leq m \leq 10^9</var>, <var>2 \leq l \leq 10^9</var>).
</p>
<H2>Output</H2>
<p>
For each test case, print its case number and the minimum <var>a</var> modulo <var>m</var> as described above.
</p>
<H2>Sample Input</H2>
<pre>
0 1000 10
1 1000 10
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 1
Case 2: 10
</pre>
|
p03491 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For strings <var>s</var> and <var>t</var>, we will say that <var>s</var> and <var>t</var> are <em>prefix-free</em> when neither is a prefix of the other.</p>
<p>Let <var>L</var> be a positive integer. A set of strings <var>S</var> is a <em>good string set</em> when the following conditions hold true:</p>
<ul>
<li>Each string in <var>S</var> has a length between <var>1</var> and <var>L</var> (inclusive) and consists of the characters <code>0</code> and <code>1</code>.</li>
<li>Any two distinct strings in <var>S</var> are prefix-free.</li>
</ul>
<p>We have a good string set <var>S = \{ s_1, s_2, ..., s_N \}</var>. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:</p>
<ul>
<li>Add a new string to <var>S</var>. After addition, <var>S</var> must still be a good string set.</li>
</ul>
<p>The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq L \leq 10^{18}</var></li>
<li><var>s_1</var>, <var>s_2</var>, ..., <var>s_N</var> are all distinct.</li>
<li>{ <var>s_1</var>, <var>s_2</var>, ..., <var>s_N</var> } is a good string set.</li>
<li><var>|s_1| + |s_2| + ... + |s_N| \leq 10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>L</var>
<var>s_1</var>
<var>s_2</var>
<var>:</var>
<var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Alice will win, print <code>Alice</code>; if Bob will win, print <code>Bob</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
00
01
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Alice
</pre>
<p>If Alice adds <code>1</code>, Bob will be unable to add a new string.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
00
11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Bob
</pre>
<p>There are two strings that Alice can add on the first turn: <code>01</code> and <code>10</code>.
In case she adds <code>01</code>, if Bob add <code>10</code>, she will be unable to add a new string.
Also, in case she adds <code>10</code>, if Bob add <code>01</code>, she will be unable to add a new string.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 3
0
10
110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Alice
</pre>
<p>If Alice adds <code>111</code>, Bob will be unable to add a new string.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 1
0
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Bob
</pre>
<p>Alice is unable to add a new string on the first turn.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1 2
11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Alice
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>2 3
101
11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>Bob
</pre></section>
</div>
</span> |
p01156 |
<H1><font color="#000">Problem B:</font> Hyper Rock-Scissors-Paper</H1>
<p>
Rock-Scissors-Paper is a game played with hands and often used for random choice of a person for some
purpose. Today, we have got an extended version, namely, <i>Hyper Rock-Scissors-Paper</i> (or Hyper RSP
for short).
</p>
<p>
In a game of Hyper RSP, the players simultaneously presents their hands forming any one of the following
15 gestures: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil,
Lightning, and Gun.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hyperRSP"><br>
<p>Figure 1: Hyper Rock-Scissors-Paper</p>
</center>
<p>
The arrows in the figure above show the defeating relation. For example, Rock defeats Fire, Scissors,
Snake, Human, Tree, Wolf, and Sponge. Fire defeats Scissors, Snake, Human, Tree, Wolf, Sponge, and
Paper. Generally speaking, each hand defeats other seven hands located after in anti-clockwise order in
the figure. A player is said to win the game if the playerâs hand defeats at least one of the other hands,
and is not defeated by any of the other hands.
</p>
<p>
Your task is to determine the winning hand, given multiple hands presented by the players.
</p>
<H2>Input</H2>
<p>
The input consists of a series of data sets. The first line of each data set is the number <i>N</i> of the players
(<i>N</i> < 1000). The next <i>N</i> lines are the hands presented by the players.
</p>
<p>
The end of the input is indicated by a line containing single zero.
</p>
<H2>Output</H2>
<p>
For each data set, output the winning hand in a single line. When there are no winners in the game,
output âDrawâ (without quotes).
</p>
<H2>Sample Input</H2>
<pre>
8
Lightning
Gun
Paper
Sponge
Water
Dragon
Devil
Air
3
Rock
Scissors
Paper
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Sponge
Draw
</pre>
|
p00317 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ç³ç</H1>
<p>
å€ä»£åœå®¶ã€ã¯ã·ãã®éºè·¡ããç¡æ°ã®ç³çãçºèŠããããç ç©¶è
ã®èª¿æ»ã«ãã£ãŠãåç³çã«ã¯äžã€ã®åèªãå»ãŸããŠããããšãåãã£ããããããé·å¹Žã®é¢šåã«ãã£ãŠã以äžã®çç±ã§è§£èªãå°é£ãªç³çãããããã ã
</p>
<ul>
<li> ç³çã«æžãããŠããåèªã®äžã€ã®æåã ãã è(ãã)ã§èŠãããŠããå Žåãããããã®æåãææ¡ããããšãã§ããªãã
</li>
<li> ç³çã®å·ŠåŽãæ¬ ããŠãããããã«äœãæååãæžãããŠãããããããªãïŒç³çã®å·ŠåŽïŒæå以äžãææ¡ããããšãã§ããªãïŒã</li>
<li> ç³çã®å³åŽãæ¬ ããŠãããããã«äœãæååãæžãããŠãããããããªãïŒç³çã®å³åŽïŒæå以äžãææ¡ããããšãã§ããªãïŒã
</li>
</ul>
<p>
ç³çã«èãçããŠããå Žæã¯å€ããŠãäžãæãããªãããŸããæ¬ ããç³çã«èãçããŠããããšã¯ããããç³çã®äž¡åŽãåæã«æ¬ ããŠããããšã¯ãªãã
</p>
<p>
ç ç©¶è
ã¯ãç³ççºèŠä»¥åã®èª¿æ»ã§ããã£ãŠããåèªããŸãšããèŸæžãæã£ãŠããããããã颚åã®åœ±é¿ã«ããèãšæ¬ ããããç³çããå
ã®åèªãæšæž¬ãããšããèŸæžã®äžã®åèªã«åœãŠã¯ãŸããã®ãããã€ããããããã«ã¯åãããªãã
</p>
<p>
ç³çã®æ
å ±ãäžãããããšããäžããããèŸæžã®äžã«åœãŠã¯ãŸããããªåèªãããã€ããããæ°ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>word<sub>1</sub></var>
<var>word<sub>2</sub></var>
:
<var>word<sub>N</sub></var>
<var>slate<sub>1</sub></var>
<var>slate<sub>2</sub></var>
:
<var>slate<sub>M</sub></var>
</pre>
<p>
ïŒè¡ç®ã«èŸæžã«èŒã£ãŠããåèªã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 50000)ãç³çã®æ° <var>M</var> (1 ≤ <var>M</var> ≤ 50000) ãäžãããããç¶ã <var>N</var> è¡ã«åèª <var>word<sub>i</sub></var> ãäžãããããåèªã¯è±å°æåã®ã¿ãå«ãé·ãã 1 ä»¥äž 200 以äžã®æååã§ããããã ãã<var>N</var> åã®åèªã¯å
šãŠç°ãªããç¶ã <var>M</var> è¡ã«ãåç³çã®æ
å ±ã衚ãæåå <var>slate<sub>i</sub></var> ãäžããããã<var>slate<sub>i</sub></var> ã¯è±å°æåãã?ããã*ããå«ãé·ãã 1 ä»¥äž 200 以äžã®æååã§ããã? ã¯èã«èŠãããæåã衚ãã? ã¯äžã€ã®æååã«ãå€ããšãäžã€ããçŸããªããæååã®å
é ã * ã®å Žåãç³çã®å·ŠåŽãæ¬ ããŠããããšã瀺ããæååã®æ«å°Ÿã * ã®å Žåãç³çã®å³åŽãæ¬ ããŠããããšã瀺ãã* ã¯ãæååã®å
é ãæ«å°Ÿä»¥å€ã«ã¯çŸãããåæã«äž¡åŽã«çŸããããšã¯ãªãã* ãäžã€ã ãã®æååãäžããããããšã¯ãªãã
</p>
<p>
å
¥åã§äžããããæååã®æåã®ç·æ°ã¯ 3000000 ãè¶
ããªãã
</p>
<h2>Output</h2>
<p>
åç³çã«ã€ããŠãåèªã®æ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
aloe
apple
apricot
cactus
cat
apple
ap*
*e
ca?*
</pre>
<h2>Sample Output 1</h2>
<pre>
1
2
2
2
</pre> |
p02280 | <H1>Binary Tree</H1>
<p>
A rooted binary tree is a tree with a root node in which every node has at most two children.
</p>
<p>
Your task is to write a program which reads a rooted binary tree <i>T</i> and prints the following information for each node <i>u</i> of <i>T</i>:
</p>
<ul>
<li>node ID of <i>u</i></li>
<li>parent of <i>u</i></li>
<li>sibling of <i>u</i></li>
<li>the number of children of <i>u</i></li>
<li>depth of <i>u</i></li>
<li>height of <i>u</i></li>
<li>node type (root, internal node or leaf)</li>
</ul>
<p>
If two nodes have the same parent, they are <b>siblings</b>. Here, if <i>u</i> and <i>v</i> have the same parent, we say <i>u</i> is a sibling of <i>v</i> (vice versa).
</p>
<p>
The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf.
</p>
<p>
Here, the given binary tree consists of <i>n</i> nodes and evey node has a unique ID from 0 to <i>n</i>-1.
</p>
<H2>Input</H2>
<p>
The first line of the input includes an integer <i>n</i>, the number of nodes of the tree.
</p>
<p>
In the next <i>n</i> lines, the information of each node is given in the following format:
</p>
<p>
<i>id left right</i>
</p>
<p>
<i>id</i> is the node ID, <i>left</i> is ID of the left child and <i>right</i> is ID of the right child. If the node does not have the left (right) child, the <i>left</i>(<i>right</i>) is indicated by <span>-1</span>.
</p>
<H2>Output</H2>
<p>
Print the information of each node in the following format:
</p>
<p>
<span>node</span> <i>id</i><span>: <span>parent = </span><i>p</i><span>, sibling = </span><i>s</i><span>, degree = </span><i>deg</i><span>, depth = <span><i>dep</i><span>, height = </span><i>h</i><span>, </span><i>type</i><br>
</p>
<p>
<i>p</i> is ID of its parent. If the node does not have a parent, print <spna>-1</span>.
</p>
<p>
<i>s</i> is ID of its sibling. If the node does not have a sibling, print <spna>-1</span>.
</p>
<p>
<i>deg</i>, <i>dep</i> and <i>h</i> are the number of children, depth and height of the node respectively.
</p>
<p>
<i>type</i> is a type of nodes represented by a string (<span>root</span>, <span>internal node</span> or <span>leaf</span>. If the root can be considered as a leaf or an internal node, print <span>root</span>.
</p>
<p>
Please follow the format presented in a sample output below.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 25</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
9
0 1 4
1 2 3
2 -1 -1
3 -1 -1
4 5 8
5 6 7
6 -1 -1
7 -1 -1
8 -1 -1
</pre>
<H2>Sample Output 1</H2>
<pre>
node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root
node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node
node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf
node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf
node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node
node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node
node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf
node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf
node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_7_B_1"><br>
</center>
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p>
|
p01855 |
<h1 id="d-åžæŸæš¡æ§-checkered-pattern">D : åžæŸæš¡æ§ / Checkered Pattern</h1>
<h2 id="å顿">å顿</h2>
<p>瞊暪ã®é·ãã <var>h, w</var> ã®é·æ¹åœ¢ãããïŒ å
éšã«ã¯äžèŸºã®é·ãã <var>1</var> ã®æ£æ¹åœ¢ã®ãã¹ãæ·ãè©°ããããŠããïŒ æãå·Šäžã®ãã¹ã <var>(0,0)</var> ãšãïŒ <var>(0,0)</var> ã® <var>i</var> åäžã§ <var>j</var> åå³ã®ãã¹ã <var>(i,j)</var> ã®ããã«è¡šãããšã«ãããšïŒ <var>(i,j)</var> 㯠<var>i+j</var> ãå¶æ°ãªãèµ€è²ã«ïŒå¥æ°ãªãéè²ã«å¡ãããŠããïŒ</p>
<p>ä»ïŒ<var>(0,0)</var> ã®å·Šäžã®é ç¹ãš <var>(h − 1,w − 1)</var> ã®å³äžã®é ç¹ãç·åã§çµãã ïŒ ãã®ç·åãéãèµ€è²ã®éšåã®é·ãã <var>a</var>, éè²ã®éšåã®é·ãã <var>b</var> ãšããããšãïŒ æ¯ <var>a : b</var> ã¯æŽæ°æ¯ãšãªãïŒ<var>a : b</var> ãæãç°¡åã«ããŠ(äºãã«çŽ ãªæŽæ°ã§)衚ãïŒ</p>
<h2 id="å
¥å">å
¥å</h2>
<pre>
<var>T</var>
<var>h_1 \ w_1</var>
<var>âŠ</var>
<var>h_T \ w_T</var>
</pre>
<p><var>1</var> ã€ã®ãã¡ã€ã«ã« <var>T</var> åã®å
¥åãå«ãŸããïŒ <var>1</var> è¡ç®ã« <var>T</var>ïŒ <var>1+i</var> è¡ç®ã« <var>T</var> çªç®ã®å
¥åã«ããã瞊暪ã®é·ã <var>h_i</var>, <var>w_i</var> ãå
¥åãããïŒ</p>
<h2 id="å¶çŽ">å¶çŽ</h2>
<ul>
<li>æŽæ°ã§ãã</li>
<li><var>1 ≤ T ≤ 1000</var></li>
<li><var>1 ≤ h_i, w_i ≤ 10<sup>9</sup></var></li>
</ul>
<h2 id="åºå">åºå</h2>
<p>åã±ãŒã¹ã«å¯Ÿããçãã <var>1</var> ã§ã¹ããŒã¹åºåãã§åºåããïŒ å
šäœã§ <var>T</var> è¡ã«ãããïŒ</p>
<h2 id="ãµã³ãã«">ãµã³ãã«</h2>
<h3 id="ãµã³ãã«å
¥å1">ãµã³ãã«å
¥å1</h3>
<pre>
3
2 3
3 3
4 3
</pre>
<h3 id="ãµã³ãã«åºå1">ãµã³ãã«åºå1</h3>
<pre>
1 1
1 0
1 1
</pre>
<div class="figure">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RUPC2015ACPC2015_D" />
</div>
<!-- - - - end nicebady - - - -->
|
p03868 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>There are <var>N</var> computers and <var>N</var> sockets in a one-dimensional world.
The coordinate of the <var>i</var>-th computer is <var>a_i</var>, and the coordinate of the <var>i</var>-th socket is <var>b_i</var>.
It is guaranteed that these <var>2N</var> coordinates are pairwise distinct.</p>
<p>Snuke wants to connect each computer to a socket using a cable.
Each socket can be connected to only one computer.</p>
<p>In how many ways can he minimize the total length of the cables?
Compute the answer modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^5</var></li>
<li><var>0 †a_i, b_i †10^9</var></li>
<li>The coordinates are integers.</li>
<li>The coordinates are pairwise distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var>
:
<var>a_N</var>
<var>b_1</var>
:
<var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to minimize the total length of the cables, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0
10
20
30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two optimal connections: <var>0-20, 10-30</var> and <var>0-30, 10-20</var>.
In both connections the total length of the cables is <var>40</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
3
10
8
7
12
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre></section>
</div>
</span> |
p00747 |
<!-- begin en only -->
<h1><font color="#000000">Problem B:</font> Amazing Mazes</h1>
<!-- end en only -->
<!-- begin en only -->
<p>
You are requested to solve maze problems. Without passing through
these mazes, you might not be able to pass through the domestic
contest!
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A maze here is a rectangular area of a number of squares, lined up
both lengthwise and widthwise, The area is surrounded by walls except
for its entry and exit. The entry to the maze is at the leftmost part
of the upper side of the rectangular area, that is, the upper side of
the uppermost leftmost square of the maze is open. The exit is
located at the rightmost part of the lower side, likewise.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
In the maze, you can move from a square to one of the squares
adjoining either horizontally or vertically. Adjoining squares,
however, may be separated by a wall, and when they are, you cannot go
through the wall.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Your task is to find the length of the shortest path from the entry to
the exit. Note that there may be more than one shortest paths, or
there may be none.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of one or more datasets, each of which represents a
maze.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The first line of a dataset contains two integer numbers, the
width <i>w</i> and the height <i>h</i> of the rectangular area, in
this order.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The following 2 × <i>h</i> − 1 lines of a dataset describe
whether there are walls between squares or not. The first line starts
with a space and the rest of the line contains <i>w</i> − 1
integers, 1 or 0, separated by a space. These indicate whether walls
separate horizontally adjoining squares in the first row. An integer
1 indicates a wall is placed, and 0 indicates no wall is there. The
second line starts without a space and contains <i>w</i> integers, 1 or 0,
separated by a space. These indicate whether walls separate
vertically adjoining squares in the first and the second rows. An
integer 1/0 indicates a wall is placed or not. The following lines
indicate placing of walls between horizontally and vertically
adjoining squares, alternately, in the same manner.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The number of datasets is no more than 100. Both the widths and the
heights of rectangular areas are no less than 2 and no more than 30.
</p>
<!-- end en only -->
</p>
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a line having an integer indicating the
length of the shortest path from the entry to the exit. The length of
a path is given by the number of visited squares. If there exists
no path to go through the maze, output a line containing a single
zero. The line should not contain any character other than this
number.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_B-1" align="right" width=60%>
<pre>
2 3
1
0 1
0
1 0
1
9 4
1 0 1 0 0 0 0 0
0 1 1 0 1 1 0 0 0
1 0 1 1 0 0 0 0
0 0 0 0 0 0 0 1 1
0 0 0 1 0 0 1 1
0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 1 0
12 5
1 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 0 0 0 0
0 0 1 0 0 1 0 1 0 0 0
0 0 0 1 1 0 1 1 0 1 1 0
0 0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0
0 0
</pre>
<br clear=all>
<h3>Output for the Sample Input</h3>
<pre>
4
0
20
</pre>
|
p00252 |
<H1>ä¹è»åž</H1>
<p>
æ°å¹¹ç·ã«ä¹ãããã«ã¯ããä¹è»åžããç¹æ¥åžãã®2æã®å笊ãå¿
èŠã§ããçµè·¯ã®äžéšã§æ°å¹¹ç·ãå©çšããªãå Žåãããããããããã¯å¥ã
ã®å笊ãšãªã£ãŠããŸãããæ°å¹¹ç·ã®ã¿ãå©çšããçµè·¯ã§ã¯ã1æã§ä¹è»åžãšç¹æ¥åžãå
Œãããä¹è»ã»ç¹æ¥åžããçºè¡ãããããšããããŸãã
</p>
<p>
èªåæ¹ææ©ã§ã¯ããããã®å笊ãèªã¿èŸŒãã§ãæ£ããå笊ãæå
¥ããããšãã ãã²ãŒããéããªããã°ãªããŸããããä¹è»åžããšãç¹æ¥åžãããããïŒæããŸãã¯ããã®äž¡æ¹ããŸãã¯ããä¹è»ã»ç¹æ¥åžããïŒææå
¥ããããã©ãããå€å®ããèªåæ¹ææ©ã®æã®ééã倿ããããã°ã©ã ãäœæããŠäžããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
b<sub>1</sub> b<sub>2</sub> b<sub>3</sub>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªããïŒã€ã®ç©ºçœã§åºåãããïŒã€ã®æŽæ°ãå«ããb<sub>1</sub> ã¯ãä¹è»åžãã®æå
¥ç¶æ
ãb<sub>2</sub> ã¯ãç¹æ¥åžãã®æå
¥ç¶æ
ãb<sub>3</sub> ã¯ãä¹è»ã»ç¹æ¥åžãã®æå
¥ç¶æ
ã瀺ããæå
¥ç¶æ
ã¯0ãŸãã¯1ã§è¡šããã0ã®å Žåã¯æå
¥ãããŠããªãç¶æ
ã1ã®å Žåã¯æå
¥ãããŠããç¶æ
ã衚ãããã ããæ³å®ãããæå
¥ç¶æ
ã®çµã¿åããã¯ä»¥äžã®å Žåã®ã¿ãšããã
</p>
<center>
<table class="withborder">
<tr>
<th>å
¥å</th>
<th>æå
¥ç¶æ
</th>
<th>æå
¥ã«å¯Ÿããæã®åäœ</th>
</tr>
<tr>
<td>1 0 0</td>
<td>ãä¹è»åžãã®ã¿æå
¥</td>
<td>Close</td>
</tr>
<tr>
<td>0 1 0</td>
<td>ãç¹æ¥åžãã®ã¿æå
¥</td>
<td>Close</td>
</tr>
<tr>
<td>1 1 0</td>
<td>ãä¹è»åžããšãç¹æ¥åžãæå
¥</td>
<td>Open</td>
</tr>
<tr>
<td>0 0 1</td>
<td>ãä¹è»ã»ç¹æ¥åžãæå
¥</td>
<td>Open</td>
</tr>
<tr>
<td>0 0 0</td>
<td>æå
¥ãªã</td>
<td>Close</td>
</tr>
</table>
</center>
<br/>
<h2>åºå</h2>
<p>
èªåæ¹ææ©ã®ééã衚ãOpenãŸãã¯CloseãïŒè¡ã«åºåããã
</p>
<h2>å
¥åäŸ1</h2>
<pre>
0 0 1
</pre>
<h2>åºåäŸ1</h2>
<pre>
Open
</pre>
<br/>
<h2>å
¥åäŸ2</h2>
<pre>
0 1 0
</pre>
<h2>åºåäŸ2</h2>
<pre>
Close
</pre> |
p03887 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>Consider all integers between <var>1</var> and <var>2N</var>, inclusive.
Snuke wants to divide these integers into <var>N</var> pairs such that:</p>
<ul>
<li>Each integer between <var>1</var> and <var>2N</var> is contained in exactly one of the pairs.</li>
<li>In exactly <var>A</var> pairs, the difference between the two integers is <var>1</var>.</li>
<li>In exactly <var>B</var> pairs, the difference between the two integers is <var>2</var>.</li>
<li>In exactly <var>C</var> pairs, the difference between the two integers is <var>3</var>.</li>
</ul>
<p>Note that the constraints guarantee that <var>N = A + B + C</var>, thus no pair can have the difference of <var>4</var> or more.</p>
<p>Compute the number of ways to do this, modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †5000</var></li>
<li><var>0 †A, B, C</var></li>
<li><var>A + B + C = N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two possibilities: <var>1-2, 3-5, 4-6</var> or <var>1-3, 2-4, 5-6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>600 100 200 300
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>522158867
</pre></section>
</div>
</span> |
p02795 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns, where all the squares are initially white.</p>
<p>You will perform some number of painting operations on the grid.
In one operation, you can do one of the following two actions:</p>
<ul>
<li>Choose one row, then paint all the squares in that row black.</li>
<li>Choose one column, then paint all the squares in that column black.</li>
</ul>
<p>At least how many operations do you need in order to have <var>N</var> or more black squares in the grid?
It is guaranteed that, under the conditions in Constraints, having <var>N</var> or more black squares is always possible by performing some number of operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H \leq 100</var></li>
<li><var>1 \leq W \leq 100</var></li>
<li><var>1 \leq N \leq H \times W</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var>
<var>W</var>
<var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations needed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
7
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>You can have <var>14</var> black squares in the grid by performing the "row" operation twice, on different rows.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>14
12
112
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
100
200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> |
p01910 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>F: ã«ãŒãã²ãŒã </h1>
<h2>åé¡</h2>
<p>
ã«ãŒãã䜿ã£ãã²ãŒã ã $Q$ åè¡ããŸãã
ã«ãŒãã«ã¯ $1 \cdots N$ ã®æ°ãæžãããŠãããåæ°ãæžãããã«ãŒãã¯ã²ãŒã ãè¡ãã®ã«ååãªææ°ããããŸãã
$i$ åç®ã®ã²ãŒã ã§ã¯ãã¯ããã«ææãšã㊠2 æã®ã«ãŒããé
ãããŸãã
ããããã®ã«ãŒãã«æžãããŠããæ°å㯠$x_i$ ãš $y_i$ ã§ãã
ã«ãŒãã¯ã«ãŒã«ã«åŸã£ãŠäº€æããããšãã§ããŸãã
$j$ çªç® $(1 \le j \le M)$ ã®ã«ãŒã«ã§ã¯ãã«ãŒã $a_j$ ãææ°æ $c_j$ åã§å¥ã®ã«ãŒã $b_j$ ã«äº€æããããšãã§ããŸãã
åã«ãŒã«ã¯äœåã§ãçšããããšãã§ããŸãããŸããææ°æãè¶³ããªããŠäº€æã§ããªãå Žåã¯ãããŸããã
æåŸã«ãææã®ã«ãŒãã®æ°åã $R$ ã§å²ã£ãããŸããçããæãå ±é
¬ãšã㊠$z_i$ ååãåããŸãã
ç°ãªãå Žåå ±é
¬ã¯ $0$ åã§ãã
</p>
<p>
$Q$ åã²ãŒã ãçµããæã«å¢ããããšã®ã§ãããéã®æå€§å€ãæ±ããŠãã ããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le N \le 10^5$</li>
<li>$0 \le M \le \min(2 \times 10^5, N\times(N-1))$</li>
<li>$2 \le R \le 10$</li>
<li>$1 \le Q \le 10^5$</li>
<li>$1 \le a_j, b_j \le N$</li>
<li>$a_j \neq b_j$</li>
<li>$0 \le c_j \le 10^5$</li>
<li>$1 \le x_i, y_i \le N$</li>
<li>$0 \le z_i \le 10^5$</li>
</ul>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããŸãã
</p>
<p>
$N \ M \ R \ Q$<br>
$a_1 \ b_1 \ c_1$<br>
$\vdots$<br>
$a_M \ b_M \ c_M$<br>
$x_1 \ y_1 \ z_1$<br>
$\vdots$<br>
$x_Q \ y_Q \ z_Q$
</p>
<h2>åºå</h2>
<p>
ã²ãŒã ã $Q$ åè¡ã£ããšãã«å¢ããããšã®ã§ãããéã®æå€§å€ã 1 è¡ã§åºåããŠãã ããããŸããæ«å°Ÿã«æ¹è¡ãåºåããŠãã ããã
</p>
<h2>ãµã³ãã«</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
4 4 2 2
1 2 1
2 3 1
3 4 5
4 1 7
1 4 5
2 4 3
</pre>
<h3>åºåäŸ 1</h3>
<pre>
7
</pre>
<p>
1 åç®ã®ã²ãŒã ã§ã¯ã«ãŒã 1 ãææ°æ 1 ã§ã«ãŒã 2 ã«äº€æãããšææã®ã«ãŒãã 2 ã§å²ã£ãæã®ããŸããã©ã¡ãã 0 ãšãªããåŸãããå ±é
¬ã¯ 5 ãšãªããŸãã
2 åç®ã®ã²ãŒã ã§ã¯ãã§ã« 2 ã§å²ã£ããšãã®ããŸããã©ã¡ãã 0 ã§ãããåŸãããå ±é
¬ã¯ 3 ãšãªããŸãã
2 åã®ã²ãŒã ã®çµæãå¢ããããé㯠$5-1+3=7$ ã§ãã
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
4 4 2 1
1 2 1
2 3 1
3 4 5
4 1 7
3 4 2
</pre>
<h3>åºåäŸ 2</h3>
<pre>
0
</pre>
<p>
ã«ãŒãã®äº€æã§ã®ææ°æãå ±é
¬ãããå€ãã®ã§ã亀æãè¡ããªãã®ãæé©ã§ãã
</p>
|
p00602 |
<H1><font color="#000000">Problem H:</font> Fibonacci Sets</H1>
<p>
Fibonacci number <i>f</i>(<i>i</i>) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule <i>f</i>(<i>i</i>) = <i>f</i>(<i>i</i> - 1) + <i>f</i>(<i>i</i> - 2), where we set <i>f</i>(0) = 1 = <i>f</i>(-1).
</p>
<!--
<p>
Let <i>V</i> and <i>d</i> be two certain positive integers and be <i>N</i> ≡ 1001 a constant. Consider a set of <i>V</i> nodes, each node <i>i</i> having a Fibonacci label (<i>f</i>(<i>i</i>) mod N) assigned for <i>i</i> = 1,..., <i>V</i> ≤ N. If |<i>f</i>(<i>i</i>) - <i>f</i>(<i>j</i>)| < <i>d</i>, then the nodes <i>i</i> and <i>j</i> are connected.
</p>
-->
<p>
Let <i>V</i> and <i>d</i> be two certain positive integers and be <i>N</i> ≡ 1001 a constant. Consider a set of <i>V</i> nodes, each node <i>i</i> having a Fibonacci label <i>F</i>[<i>i</i>] = (<i>f</i>(<i>i</i>) mod N) assigned for <i>i</i> = 1,..., <i>V</i> ≤ N. If |<i>F</i>(<i>i</i>) - <i>F</i>(<i>j</i>)| < <i>d</i>, then the nodes <i>i</i> and <i>j</i> are connected.
</p>
<p>
Given <i>V</i> and <i>d</i>, how many connected subsets of nodes will you obtain?
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fibonaccisets">
</center>
<center>
<p>
Figure 1: There are 4 connected subsets for <i>V</i> = 20 and <i>d</i> = 100.
</p>
</center>
<H2>Input</H2>
<p>
Each data set is defined as one line with two integers as follows:
</p>
<p>
<i>Line 1</i>: Number of nodes <i>V</i> and the distance <i>d</i>.
</p>
<p>
Input includes several data sets (i.e., several lines). The number of dat sets is less than or equal to 50.
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ V ≤ 1000</li>
<li>1 ≤ d ≤ 150</li>
</ul>
<H2>Output</H2>
<p>
Output line contains one integer - the number of connected subsets - for each input line.
</p>
<H2>Sample Input</H2>
<pre>
5 5
50 1
13 13
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
50
8
</pre> |
p01443 |
<H1><font color="#000">Problem G:</font> Number Sorting</H1>
<p>
Consider sets of natural numbers. Some sets can be sorted in the same order numerically and lexicographically. {2, 27, 3125, 9000} is one example of such sets; {2, 27, 243} is not since lexicographic sorting would yield {2, 243, 27}.
</p>
<p>
Your task is to write a program that, for the set of integers in a given range [<i>A</i>,<i>B</i>] (i.e. between <i>A</i> and <i>B</i> inclusive), counts the number of non-empty subsets satisfying the above property. Since the resulting number is expected to be very huge, your program should output the number in modulo <i>P</i> given as the input.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of a line with three integers <i>A</i>, <i>B</i>, and <i>P</i> separated by a space. These numbers satisfy the following conditions: 1 ≤ <i>A</i> ≤ 1,000,000,000, 0 ≤ <i>B</i> - <i>A</i> < 100,000, 1 ≤ <i>P</i> ≤ 1,000,000,000.
</p>
<p>
The end of input is indicated by a line with three zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, output the number of the subsets in modulo <i>P</i>.
</p>
<H2>Sample Input</H2>
<pre>
1 10 1000
1 100000 1000000000
999999999 1000099998 1000000000
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
513
899507743
941554688
</pre>
|
p03184 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns.
Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p>
<p>In the grid, <var>N</var> Squares <var>(r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N)</var> are wall squares, and the others are all empty squares.
It is guaranteed that Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</p>
<p>Taro will start from Square <var>(1, 1)</var> and reach <var>(H, W)</var> by repeatedly moving right or down to an adjacent empty square.</p>
<p>Find the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 \leq H, W \leq 10^5</var></li>
<li><var>1 \leq N \leq 3000</var></li>
<li><var>1 \leq r_i \leq H</var></li>
<li><var>1 \leq c_i \leq W</var></li>
<li>Squares <var>(r_i, c_i)</var> are all distinct.</li>
<li>Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>N</var>
<var>r_1</var> <var>c_1</var>
<var>r_2</var> <var>c_2</var>
<var>:</var>
<var>r_N</var> <var>c_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 2
2 2
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There are three paths as follows:</p>
<p><img alt="" src="https://img.atcoder.jp/dp/grid_1_0_muffet.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2 2
2 1
4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There may be no paths.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5 4
3 1
3 5
1 3
5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>24
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 1
50000 50000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>123445622
</pre>
<p>Be sure to print the count modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p01013 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1> Problem H: Cone Cut</h1>
<h2> Problem </h2>
<p>
ãã®åé¡ã§ã¯3次å
空éäžã®ããç¹<var>X </var>ãšããç¹<var>Y </var>ãéããããªçŽç·ãçŽç·<var>XY </var>ãšæžãã
</p>
<p>
3次å
空éäžã«åéãšãã®åéå
éšã®ç¹<var>P </var>ãäžãããããç¹<var>P </var>ãéãåéã®åºé¢ã«åçŽãªçŽç·ãšåéã®åºé¢ãšã®äº€ç¹ãç¹<var>Q </var>ãšããããã®æãåéã®åºé¢ã®äžå¿ã<var>O </var>ãšããçŽç·<var>OQ </var>ãšåéã®åºé¢ã®ååšãšã®äº€ç¹ããç¹<var>Q </var>ã«è¿ãæ¹ããç¹<var>A </var>ãç¹<var>B </var>ãšãã(ãã ããç¹<var>O </var>ãšç¹<var>Q </var>ãåäžç¹ã®ãšãã¯ãç¹<var>O </var>ãéãä»»æã®çŽç·ãšåéã®åºé¢ã®ååšãšã®äº€ç¹ãç¹<var>A </var>ãç¹<var>B </var>ãšããã)ããŸããåéã®åºé¢ãå«ããããªå¹³é¢ã«ãããŠãç¹<var>O </var>ãéããçŽç·<var>AB </var>ãšåçŽã«äº€ããçŽç·ãšåéã®åºé¢ã®ååšãšã®äº€ç¹ãç¹<var>C </var>ãç¹<var>D </var>ãšãã(ãã ããç¹<var>C </var>ãšç¹<var>D </var>ã¯å
¥ãæ¿ããŠãåé¡ãªã)ã<br />
</p>
<p>
以äžã®å³ã¯ãåéã®é ç¹æ¹åããèŠãåéã®åºé¢ã®å³ã§ããã
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_bird" alt="åéã®é ç¹æ¹åããèŠãåéã®åºé¢ã®å³"><br />
</p>
<p>
çŽç·<var>AP </var>ãšçŽç·<var>BP </var>ã®åéãšã®äº€ç¹ïŒçŽç·<var>AP </var>ã®å Žåãç¹<var>A </var>ã§ãªãæ¹ã®äº€ç¹ãæããçŽç·<var>BP </var>ãåæ§ãïŒãç¹<var>A' </var>ãç¹<var>B' </var>ãšããç¹<var>A' </var>ãšç¹<var>B' </var>ãéãçŽç·<var>CD </var>ãšå¹³è¡ãªå¹³é¢<var>S </var>ã§åéãåæããããã®æãåæåŸã®é ç¹ãå«ãå³åœ¢ã®äœç©ãšããäžæ¹ã®å³åœ¢ã®äœç©ã空çœåºåãã§åºåããã
</p>
<h2> Input </h2>
<p>
åéã®é ç¹ã®<var>x </var>åº§æš <var>y </var>åº§æš <var>z </var>座æš<br />
åéã®åºé¢ã®äžå¿ã®<var>x </var>åº§æš <var>y </var>åº§æš <var>z </var>åº§æš åéã®åºé¢ã®ååŸ<br />
ç¹<var>P </var>ã®<var>x </var>åº§æš <var>y </var>åº§æš <var>z </var>座æš<br />
<br />
åè¡ã®ããããã®å€ã¯ã¹ããŒã¹åºåãã§äžããããã
</p>
<h2> Constraint </h2>
<p>
å
¥åã®å€ã¯ãã¹ãп޿°ã§ããããã®çµ¶å¯Ÿå€ã¯1000以äžã§ããã<br />
åéã®é«ããšãã®åºé¢ã®ååŸã¯1以äžã§ãããç¹<var>P </var>ãšåéã®è·é¢ã¯10<sup>-5</sup>以äžããã
</p>
<h2> Output </h2>
<p>
åæåŸã®é ç¹ãå«ãå³åœ¢ã®äœç©ãšããäžæ¹ã®å³åœ¢ã®äœç©ã空çœåºåãã§åºåããã<br />
ãã ãã10<sup>-5</sup>ãè¶
ãã誀差ãå«ãã§ã¯ãããªãã
</p>
<h2> Sample Input 1</h2>
<pre>
0 0 10
0 0 0 4
0 0 1
</pre>
<h2> Sample Output 1</h2>
<pre>
91.769438 75.782170
</pre>
<h2> Sample Input 2</h2>
<pre>
0 0 10
0 0 0 4
1 1 1
</pre>
<h2> Sample Output 2</h2>
<pre>
84.050413 83.501195
</pre>
<h2> Sample Input 3</h2>
<pre>
0 0 0
8 9 10 5
1 1 1
</pre>
<h2> Sample Output 3</h2>
<pre>
0.071663 409.709196
</pre> |
p02146 | <h1>Problem J: Averaging</h1>
<h2>Problem</h2>
<p>
ã¢ã€ã
åœã«ã¯$N$åã®å³¶ãš$N-1$åã®æ©ããããåå³¶ã¯ãããã$1$ãã$N$ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã
$i$çªç®ã®æ©ã¯å³¶$u_i$ãšå³¶$v_i$ãåæ¹åã«çµãã§ãããå³¶æ°ã¯æ©ãçšããŠå³¶ãšå³¶ãšãè¡ãæ¥ããããšãã§ããããŸããæ©ä»¥å€ã«å³¶ãšå³¶ãè¡ãæ¥ããæ¹æ³ã¯ãªãã
ã©ã®å³¶ããã©ã®å³¶ãžãããã€ãã®æ©ãæž¡ãããšã§å°éããããšãã§ããã
</p>
<p>
çŸåšãå³¶$i$ã«ã¯$X_i$人ã®å³¶æ°ãããã
åå³¶ã®ç°å¢ãžã®è² è·ã忣ãããããã«ã¢ã€ã
åœã¯äœäººãã®åœæ°ã«å¥ã®å³¶ãžåŒè¶ããŠãããããšã«ããã
å³¶$a$ã«äœãã§ãã人ãå³¶$b$ã«åŒè¶ããããããã«ã¯å³¶$a$ãšå³¶$b$ã®è·é¢ãšåãåã®ã³ã¹ãããããããã ããå³¶$a$ãšå³¶$b$ã®è·é¢ã¯å³¶$a$ããå³¶$b$ãžè¡ãããã«æž¡ãå¿
èŠã®ããæ©ã®æ°ã®æå°å€ã§å®çŸ©ãããã
</p>
<p>
ã©ã®$2$ã€ã®å³¶ãéžãã§ããããã®å³¶æ°ã®äººæ°ã®å·®ã®çµ¶å¯Ÿå€ã$1$以äžã«ãªãããã«åœæ°ã«åŒè¶ããŠãããããã
ãã®ãšããå¿
èŠãªã³ã¹ãã®ç·åã®æå°å€ãæ±ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§ãã¹ãп޿°ã§äžããããã</p>
<pre>
$N$
$X_1$ $X_2$ ... $X_N$
$u_1$ $v_1$
$u_2$ $v_2$
...
$u_{N-1}$ $v_{N-1}$
</pre>
<p>
$1$è¡ç®ã«å³¶ã®æ°$N$ãäžããããã<br>
$2$è¡ç®ã«ã¯åå³¶ã®å³¶æ°ã®äººæ°ã衚ã$N$åã®æŽæ°ã空çœåºåãã§äžããããã$i$çªç®ã®æŽæ°$X_i$ã¯å³¶$i$ã®å³¶æ°ã®äººæ°ã衚ãã<br>
$3$è¡ç®ããç¶ã$N-1$è¡ã«ã¯åæ©ãã€ãªãå³¶ã®çªå·ã空çœåºåãã§äžããããã$2+i$è¡ç®ã®å
¥åã§ã¯ã$i$çªç®ã®æ©ãå³¶$u_i$ãšå³¶$v_i$ãåæ¹åã«çµãã§ããããšã衚ãã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$2 \le N \le 5000$</li>
<li>$0 \le X_i \le 10^9$</li>
<li>$1 \le u_i, v_i \le N$</li>
<li>ã©ã®å³¶ããã©ã®å³¶ãžãããã€ãã®æ©ãæž¡ãããšã§å°éããããšãã§ãã</li>
</ul>
<h2>Output</h2>
<p>
ã³ã¹ãã®ç·åã®æå°å€ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5
4 0 4 0 0
1 2
1 3
1 4
2 5
</pre>
<h2>Sample Output 1</h2>
<pre>
7
</pre>
<p>
å³¶$1$ã®äººã$1$人ãå³¶$2$ãžã<br>
å³¶$1$ã®äººã$1$人ãå³¶$5$ãžã<br>
å³¶$3$ã®äººã$2$人ãå³¶$4$ãžåŒã£è¶ãããšã§ã©ã®$2$ã€ã®å³¶ãéžãã§ããããã®å³¶æ°ã®äººæ°ã®å·®ã®çµ¶å¯Ÿå€ã$1$以äžã«ãªãã
ãŸããã®ãšãã®ã³ã¹ãã®ç·åã¯$1+2+2\times2 = 7$ã§ããããããæå°ã§ããã
</p>
<h2>Sample Input 2</h2>
<pre>
7
0 7 2 5 0 3 0
1 2
1 3
1 4
2 5
3 6
3 7
</pre>
<h2>Sample Output 2</h2>
<pre>
10
</pre>
|
p00481 |
<H1>ããŒãº (Cheese)</H1>
<h2>åé¡</h2>
<p>
ä»å¹Žã JOI çºã®ããŒãºå·¥å ŽãããŒãºã®çç£ãå§ãïŒããã¿ãå·£ããé¡ãåºããïŒJOI çºã¯æ±è¥¿ååã«åºç»æŽçãããŠããŠïŒååºç»ã¯å·£ïŒããŒãºå·¥å ŽïŒé害ç©ïŒç©ºãå°ã®ããããã§ããïŒããã¿ã¯å·£ããåºçºããŠå
šãŠã®ããŒãºå·¥å Žã蚪ãããŒãºã 1 åãã€é£ã¹ãïŒ
</p>
<p>
ãã®çºã«ã¯ïŒN åã®ããŒãºå·¥å ŽãããïŒã©ã®å·¥å ŽãïŒçš®é¡ã®ããŒãºã ããçç£ããŠããïŒããŒãºã®ç¡¬ãã¯å·¥å Žã«ãã£ãŠç°ãªã£ãŠããïŒç¡¬ã 1 ãã N ãŸã§ã®ããŒãºãçç£ããããŒãºå·¥å Žãã¡ããã© 1 ã€ãã€ããïŒ
</p>
<p>
ããã¿ã®æåã®äœå㯠1 ã§ããïŒããŒãºã 1 åé£ã¹ãããšã«äœåã 1 å¢ããïŒãã ãïŒããã¿ã¯èªåã®äœåããã硬ãããŒãºãé£ã¹ãããšã¯ã§ããªãïŒ
</p>
<p>
ããã¿ã¯ïŒæ±è¥¿ååã«é£ãåãåºç»ã« 1 åã§ç§»åããããšãã§ãããïŒé害ç©ã®åºç»ã«ã¯å
¥ãããšãã§ããªãïŒããŒãºå·¥å ŽãããŒãºãé£ã¹ãã«éãéããããšãã§ããïŒãã¹ãŠã®ããŒãºãé£ã¹çµãããŸã§ã«ãããæçæéãæ±ããããã°ã©ã ãæžãïŒãã ãïŒããã¿ãããŒãºãé£ã¹ãã®ã«ãããæéã¯ç¡èŠã§ããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠H+1 è¡ããïŒ1 è¡ç®ã«ã¯ 3 ã€ã®æŽæ° HïŒWïŒN (1 ≤ H ≤ 1000ïŒ1 ≤ W ≤ 1000ïŒ1 ≤ N ≤ 9) ããã®é ã«ç©ºçœã§åºåãããŠæžãããŠããïŒ2 è¡ç®ãã H+1 è¡ç®ãŸã§ã®åè¡ã«ã¯ïŒ'S'ïŒ'1', '2', ..., '9'ïŒ'X'ïŒ'.' ãããªã W æåã®æååãæžãããŠããïŒåã
ãååºç»ã®ç¶æ
ã衚ããŠããïŒåãã i çªç®ïŒè¥¿ãã j çªç®ã®åºç»ã (i,j) ãšèšè¿°ããããšã«ãããš (1 ≤ i ≤ H, 1 ≤ j ≤ W)ïŒç¬¬ i+1 è¡ç®ã® j çªç®ã®æåã¯ïŒåºç» (i,j) ãå·£ã§ããå Žå㯠'S' ãšãªãïŒé害ç©ã§ããå Žå㯠'X' ãšãªãïŒç©ºãå°ã§ããå Žå㯠'.' ãšãªãïŒç¡¬ã 1, 2, ..., 9 ã®ããŒãºãçç£ããå·¥å Žã§ããå Žåã¯ãããã '1', '2', ..., '9' ãšãªãïŒå
¥åã«ã¯å·£ãšç¡¬ã 1, 2, ..., N ã®ããŒãºãçç£ããå·¥å Žããããã 1 ã€ãã€ããïŒä»ã®ãã¹ã¯é害ç©ãŸãã¯ç©ºãå°ã§ããããšãä¿èšŒãããŠããïŒããã¿ã¯å
šãŠã®ããŒãºãé£ã¹ãããããšãä¿èšŒãããŠããïŒ
</p>
<h2>åºå</h2>
<p>
ãã¹ãŠã®ããŒãºãé£ã¹çµãããŸã§ã«ãããæçæéïŒåïŒãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
3 3 1
S..
...
..1
</pre>
<h3>åºåäŸ 1</h3>
<pre>
4
</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
4 5 2
.X..1
....X
.XX.S
.2.X.
</pre>
<h3>åºåäŸ 2</h3>
<pre>
12
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
10 10 9
.X...X.S.X
6..5X..X1X
...XXXX..X
X..9X...X.
8.X2X..X3X
...XX.X4..
XX....7X..
X..X..XX..
X...X.XX..
..X.......
</pre>
<h3>åºåäŸ 3</h3>
<pre>
91
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
<br> |
p03307 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a positive integer <var>N</var>.
Find the minimum positive integer divisible by both <var>2</var> and <var>N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum positive integer divisible by both <var>2</var> and <var>N</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p><var>6</var> is divisible by both <var>2</var> and <var>3</var>.
Also, there is no positive integer less than <var>6</var> that is divisible by both <var>2</var> and <var>3</var>.
Thus, the answer is <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>999999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1999999998
</pre></section>
</div>
</span> |
p03757 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
Max Score: <var>1450</var> Points <br/>
<section>
<h3>Problem Statement</h3>
There are <var>N</var> workers in Atcoder company. Each worker is numbered <var>0</var> through <var>N - 1</var>, and the boss for worker <var>i</var> is <var>p_i</var> like a tree structure and the salary is currently <var>a_i</var>. (<var>p_i < i</var>, especially <var>p_0 = -1</var> because worker <var>0</var> is a president) <br/>
In atcoder, the boss of boss of boss of ... (repeated <var>k</var> times) worker <var>i</var> called "<var>k</var>-th upper boss", and "<var>k</var>-th lower subordinate" called for vice versa. <br/>
<br/>
You have to process <var>Q</var> queries for Atcoder: <br/>
<ul>
<li>Query 1: You are given <var>v_i, d_i, x_i</var>. Increase the salary of worker <var>v_i</var>, and all <var>j</var>-th (<var>1 †j †d_i</var>) lower subordinates by <var>x_i</var>.</li>
<li>Query 2: You are given <var>v_i, d_i</var>. Calculate the sum of salary of worker <var>v_i</var> and all <var>j</var>-th (<var>1 †j †d_i</var>) lower subordinates.</li>
<li>Query 3: You are given <var>pr_i, ar_i</var>. Now Atcoder has a new worker <var>c</var>! (<var>c</var> is the current number of workers) The boss is <var>pr_i</var>, and the first salary is <var>ar_i</var>.</li>
</ul>
Process all queries!!! <br/>
</section>
</div>
<div class="io-style">
<div class="part">
<section>
<h3>Input Format</h3>
Let the <var>i</var>-th query <var>query_i</var>, the input format is following:<br/>
<pre>
<var>N</var> <var>Q</var>
<var>p_0</var> <var>a_0</var>
<var>p_1</var> <var>a_1</var>
: :
<var>p_{N - 1}</var> <var>a_{N - 1}</var>
<var>query_0</var>
<var>query_1</var>
: :
<var>query_{Q - 1}</var>
</pre>
THe format of <var>query_i</var> is one of the three format:<br/>
<pre>
1 <var>v_i</var> <var>d_i</var> <var>x_i</var>
</pre>
<pre>
2 <var>v_i</var> <var>d_i</var>
</pre>
<pre>
3 <var>pr_i</var> <var>ar_i</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output Format</h3>
Print the result in one line for each query 2.<br/>
</section>
<section>
<h3>Constraints</h3>
<ul>
<li><var>N †400000</var></li>
<li><var>Q †50000</var></li>
<li><var>p_i < i</var> for all valid <var>i</var>.</li>
<li>In each question 1 or 2, worker <var>v_i</var> exists.</li>
<li><var>d_i †400000</var></li>
<li><var>0 †a_i, x_i †1000</var></li>
</ul>
</section>
<section>
<h3>Scoring</h3>
Subtask 1 [<var>170</var> points] <br/>
<ul>
<li><var>N, Q †5000</var></li>
</ul>
Subtask 2 [<var>310</var> points] <br/>
<ul>
<li><var>p_i + 1 = i</var> for all valid <var>i</var>.</li>
</ul>
Subtask 3 [<var>380</var> points] <br/>
<ul>
<li>There are no query 3.</li>
</ul>
Subtask 4 [<var>590</var> points] <br/>
<ul>
<li>There are no additional constraints.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
6 7
-1 6
0 5
0 4
2 3
2 2
1 1
2 0 1
1 0 2 1
2 2 1
3 3 3
2 0 3
3 3 4
2 1 1
</pre>
</section>
<section>
<h3>Sample Output 1</h3>
<pre>
15
12
30
8
</pre>
</section>
</div>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
7 9
-1 1
0 5
0 7
0 8
1 3
4 1
5 1
2 1 1
2 1 2
1 1 2 3
1 4 1 1
2 3 1
2 0 2
3 6 1
3 7 11
2 0 15
</pre>
</section>
<section>
<h3>Sample Output 2</h3>
<pre>
8
9
8
31
49
</pre>
</section>
</div>
<!-- å
¥åºåäŸã®èª¬æãã§ããã°æžã -->
</span> |
p00878 |
<H1><font color="#000">Problem E:</font> Origami Through-Hole</H1>
<p>
Origami is the traditional Japanese art of paper folding. One day, Professor Egami found the
message board decorated with some pieces of origami works pinned on it, and became interested
in the pinholes on the origami paper. Your mission is to simulate paper folding and pin punching
on the folded sheet, and calculate the number of pinholes on the original sheet when unfolded.
</p>
<p>
A sequence of folding instructions for a flat and square piece of paper and a single pinhole
position are specified. As a folding instruction, two points <i>P</i> and <i>Q</i> are given. The paper should
be folded so that <i>P</i> touches <i>Q</i> from above (Figure 4). To make a fold, we first divide the sheet
into two segments by creasing the sheet along the <i>folding line</i>, i.e., the perpendicular bisector
of the line segment <i>PQ</i>, and then turn over the segment containing <i>P</i> onto the other. You can
ignore the thickness of the paper.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_origami1"><br>
<p>Figure 4: Simple case of paper folding</p>
</center>
<p>
The original flat square piece of paper is folded into a structure consisting of layered paper
segments, which are connected by linear hinges. For each instruction, we fold one or more paper
segments along the specified folding line, dividing the original segments into new smaller ones.
The folding operation turns over some of the paper segments (not only the new smaller segments
but also some other segments that have no intersection with the folding line) to the reflective
position against the folding line. That is, for a paper segment that intersects with the folding
line, one of the two new segments made by dividing the original is turned over; for a paper
segment that does not intersect with the folding line, the whole segment is simply turned over.
</p>
<p>
The folding operation is carried out repeatedly applying the following rules, until we have no
segment to turn over.
</p>
<ul>
<li> Rule 1: The uppermost segment that contains <i>P</i> must be turned over.</li>
<li> Rule 2: If a hinge of a segment is moved to the other side of the folding line by the
operation, any segment that shares the same hinge must be turned over.</li>
<li>Rule 3: If two paper segments overlap and the lower segment is turned over, the upper
segment must be turned over too.</li>
</ul>
<p>
In the examples shown in Figure 5, (a) and (c) show cases where only Rule 1 is applied. (b)
shows a case where Rule 1 and 2 are applied to turn over two paper segments connected by a
hinge, and (d) shows a case where Rule 1, 3 and 2 are applied to turn over three paper segments.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_origami2"><br>
<p>Figure 5: Different cases of folding</p>
</center>
<p>
After processing all the folding instructions, the pinhole goes through all the layered segments
of paper at that position. In the case of Figure 6, there are three pinholes on the unfolded sheet
of paper.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_origami3"><br>
<p>Figure 6: Number of pinholes on the unfolded sheet</p>
</center>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The end of the input is indicated by a line containing a
zero.
</p>
<p>
Each dataset is formatted as follows.
</p>
<p>
<i>k</i><br>
<i>p</i><sub><i>x</i></sub><sup>1</sup> <i>p</i><sub><i>y</i></sub><sup>1</sup> <i>q</i><sub><i>x</i></sub><sup>1</sup> <i>q</i><sub><i>y</i></sub><sup>1</sup><br>
.<br>
.<br>
.<br>
<i>p</i><sub><i>x</i></sub><sup><i>k</i></sup> <i>p</i><sub><i>y</i></sub><sup><i>k</i></sup> <i>q</i><sub><i>x</i></sub><sup><i>k</i></sup> <i>q</i><sub><i>y</i></sub><sup><i>k</i></sup><br>
<i>h<sub>x</sub> h<sub>y</sub></i>
</p>
<p>
For all datasets, the size of the initial sheet is 100 mm square, and, using mm as the coordinate
unit, the corners of the sheet are located at the coordinates (0, 0), (100, 0), (100, 100) and
(0, 100). The integer <i>k</i> is the number of folding instructions and 1 ≤ <i>k</i> ≤ 10. Each of the
following <i>k</i> lines represents a single folding instruction and consists of four integers <i>p<sub>x</sub><sup>i</sup></i>, <i>p<sub>y</sub><sup>i</sup></i>, <i>q<sub>x</sub><sup>i</sup></i>, and <i>q<sub>y</sub><sup>i</sup></i>, delimited by a space. The positions of point <i>P</i> and <i>Q</i> for the <i>i</i>-th instruction are given by (<i>p<sub>x</sub><sup>i</sup></i>, <i>p<sub>y</sub><sup>i</sup></i>) and (<i>q<sub>x</sub><sup>i</sup></i>, <i>q<sub>y</sub><sup>i</sup></i>), respectively. You can assume that <i>P</i> ≠ <i>Q</i>. You must carry out these
instructions in the given order. The last line of a dataset contains two integers <i>h<sub>x</sub></i> and <i>h<sub>y</sub></i>
delimited by a space, and (<i>h<sub>x</sub></i>, <i>h<sub>y</sub></i> ) represents the position of the pinhole.
</p>
<p>
You can assume the following properties:
</p>
<ol>
<li> The points <i>P</i> and <i>Q</i> of the folding instructions are placed on some paper segments at the
folding time, and <i>P</i> is at least 0.01 mm distant from any borders of the paper segments.</li>
<li> The position of the pinhole also is at least 0.01 mm distant from any borders of the paper
segments at the punching time.</li>
<li> Every folding line, when infinitely extended to both directions, is at least 0.01 mm distant
from any corners of the paper segments before the folding along that folding line.</li>
<li> When two paper segments have any overlap, the overlapping area cannot be placed between
any two parallel lines with 0.01 mm distance. When two paper segments do not overlap,
any points on one segment are at least 0.01 mm distant from any points on the other
segment.</li>
</ol>
<p>
For example, Figure 5 (a), (b), (c) and (d) correspond to the first four datasets of the sample
input.
</p>
<H2>Output</H2>
<p>
For each dataset, output a single line containing the number of the pinholes on the sheet of
paper, when unfolded. No extra characters should appear in the output.
</p>
<H2>Sample Input</H2>
<pre>
2
90 90 80 20
80 20 75 50
50 35
2
90 90 80 20
75 50 80 20
55 20
3
5 90 15 70
95 90 85 75
20 67 20 73
20 75
3
5 90 15 70
5 10 15 55
20 67 20 73
75 80
8
1 48 1 50
10 73 10 75
31 87 31 89
91 94 91 96
63 97 62 96
63 80 61 82
39 97 41 95
62 89 62 90
41 93
5
2 1 1 1
-95 1 -96 1
-190 1 -191 1
-283 1 -284 1
-373 1 -374 1
-450 1
2
77 17 89 8
103 13 85 10
53 36
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
4
3
2
32
1
0
</pre>
|
p02845 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><var>N</var> people are standing in a queue, numbered <var>1, 2, 3, ..., N</var> from front to back. Each person wears a hat, which is red, blue, or green.</p>
<p>The person numbered <var>i</var> says:</p>
<ul>
<li>"In front of me, exactly <var>A_i</var> people are wearing hats with the same color as mine."</li>
</ul>
<p>Assuming that all these statements are correct, find the number of possible combinations of colors of the <var>N</var> people's hats.</p>
<p>Since the count can be enormous, compute it modulo <var>1000000007</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 100000</var></li>
<li><var>0 \leq A_i \leq N-1</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>A_3</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the number of possible combinations of colors of the <var>N</var> people's hats, modulo <var>1000000007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
0 1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We have three possible combinations, as follows:</p>
<ul>
<li>Red, Red, Red, Red, Red, Red</li>
<li>Blue, Blue, Blue, Blue, Blue, Blue</li>
<li>Green, Green, Green, Green, Green, Green</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>115295190
</pre></section>
</div>
</span> |
p01290 |
<H1><font color="#000">Problem H:</font> Queen's Case</H1>
<p>
A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler.
People in the country suffered from heavy taxes and forced labor. So some young people decided to form
a revolutionary army and fight against the queen. Now, they besieged the palace and have just rushed into
the entrance.
</p>
<p>
Your task is to write a program to determine whether the queen can escape or will be caught by the army.
</p>
<p>
Here is detailed description.
</p>
<ul>
<li> The palace can be considered as grid squares.</li>
<li> The queen and the army move alternately. The queen moves first.</li>
<li> At each of their turns, they either move to an adjacent cell or stay at the same cell.</li>
<li> Each of them must follow the optimal strategy.</li>
<li> If the queen and the army are at the same cell, the queen will be caught by the army immediately.</li>
<li> If the queen is at any of exit cells alone after the armyâs turn, the queen can escape from the army.</li>
<li> There may be cases in which the queen cannot escape but wonât be caught by the army forever,
under their optimal strategies.</li>
</ul>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset describes a map of the palace. The first line of the input contains two integers <i>W</i> (1 ≤ <i>W</i> ≤ 30) and <i>H</i> (1 ≤ <i>H</i> ≤ 30), which indicate the width and height of the palace. The following <i>H</i> lines, each of which contains <i>W</i> characters, denote the map of the palace. "<span>Q</span>" indicates the queen, "<span>A</span>" the army,"<span>E</span>" an exit,"<span>#</span>" a wall and "<span>.</span>" a floor.
</p>
<p>
The map contains exactly one "<span>Q</span>", exactly one "<span>A</span>" and at least one "<span>E</span>". You can assume both the queen and the army can reach all the exits.
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, output "<span>Queen can escape.</span>", "<span>Army can catch Queen.</span>" or "<span>Queen can not escape and Army can not catch Queen.</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2 2
QE
EA
3 1
QAE
3 1
AQE
5 5
..E..
.###.
A###Q
.###.
..E..
5 1
A.E.Q
5 5
A....
####.
..E..
.####
....Q
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Queen can not escape and Army can not catch Queen.
Army can catch Queen.
Queen can escape.
Queen can not escape and Army can not catch Queen.
Army can catch Queen.
Army can catch Queen.
</pre>
<h2>Hint</h2>
<p>
On the first sample input, the queen can move to exit cells, but either way the queen will be caught at the
next armyâs turn. So the optimal strategy for the queen is staying at the same cell. Then the army can
move to exit cells as well, but again either way the army will miss the queen from the other exit. So the
optimal strategy for the army is also staying at the same cell. Thus the queen cannot escape but wonât be
caught.
</p>
|
p01785 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>F - Polygon Guards</h2>
<h3>Problem Statement</h3>
<p>
You are an IT system administrator in the Ministry of Defense of Polygon Country.
</p>
<p>
Polygon Country's border forms the polygon with $N$ vertices. Drawn on the 2D-plane, all of its vertices are at the lattice points and all of its edges are parallel with either the $x$-axis or the $y$-axis.
</p>
<p>
In order to prevent enemies from invading the country, it is surrounded by very strong defense walls along its border. However, on the vertices, the junctions of walls have unavoidable structural weaknesses. Therefore, enemies might attack and invade from the vertices.
</p>
<p>
To observe the vertices and find an invasion by enemies as soon as possible, the ministry decided to hire some guards. The ministry plans to locate them on some vertices such that all the vertices are observed by at least one guard. A guard at the vertex $A$ can observe a vertex $B$ if the entire segment connecting $A$ and $B$ is inside or on the edge of Polygon Country. Of course, guards can observe the vertices they are located on. And a guard can observe simultaneously all the vertices he or she can observe.
</p>
<p>
To reduce the defense expense, the ministry wants to minimize the number of guards. Your task is to calculate the minimum number of guards required to observe all the vertices of Polygon Country.
</p>
<h3>Input</h3>
<p>The input is formatted as follows.
</p>
<blockquote>$N$<br>$X_1$ $Y_1$<br>:<br>:<br>$X_N$ $Y_N$</blockquote>
<p>
The first line contains an even integer $N$ ($4 \le N \lt 40$). The following $N$ lines describe the vertices of Polygon Country. Each of the lines contains two integers, $X_i$ and $Y_i$ ($1 \le i \le N$, $\lvert X_i \rvert \le 1{,}000$, $\lvert Y_i \rvert \le 1{,}000$), separated by one space. The position of the $i$-th vertex is $(X_i,Y_i)$.
</p>
<p>
If $i$ is odd, $X_i = X_{i+1}$, $Y_i \ne Y_{i+1}$. Otherwise, $X_i \ne X_{i+1}$, $Y_i = Y_{i+1}$. Here, we regard that $X_{N+1} = X_1$, and $Y_{N+1} = Y_1$. The vertices are given in counterclockwise order under the coordinate system that the $x$-axis goes right, and the $y$-axis goes up. The shape of Polygon Country is simple. That is, each edge doesnât share any points with other edges except that its both end points are shared with its neighbor edges.
</p>
<h3>Output</h3>
<p>Print the minimum number of guards in one line.
</p>
<h3>Sample Input 1</h3>
<pre>8
0 2
0 0
2 0
2 1
3 1
3 3
1 3
1 2</pre>
<h3>Output for the Sample Input 1</h3>
<pre>1</pre>
<h3>Sample Input 2</h3>
<pre>12
0 0
0 -13
3 -13
3 -10
10 -10
10 10
-1 10
-1 13
-4 13
-4 10
-10 10
-10 0</pre>
<h3>Output for the Sample Input 2</h3>
<pre>2</pre> |
p00897 |
<H1><font color="#000">Problem D: </font>Long Distance Taxi </H1>
<p>
A taxi driver, Nakamura, was so delighted because he got a passenger who wanted to go to a
city thousands of kilometers away. However, he had a problem. As you may know, most taxis in
Japan run on liquefied petroleum gas (LPG) because it is cheaper than gasoline. There are more
than 50,000 gas stations in the country, but less than one percent of them sell LPG. Although
the LPG tank of his car was full, the tank capacity is limited and his car runs 10 kilometer per
liter, so he may not be able to get to the destination without filling the tank on the way. He
knew all the locations of LPG stations.
Your task is to write a program that finds the best way from the current location to the destination without running out of gas.
</p>
<H2>Input</H2>
<p>
The input consists of several datasets, and each dataset is in the following format.
</p>
<p>
<i>N M cap<br>
src dest</i><br>
<i>c</i><sub>1,1</sub> <i>c</i><sub>1,2</sub> <i>d</i><sub>1</sub><br>
<i>c</i><sub>2,1</sub> <i>c</i><sub>2,2</sub> <i>d</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>c</i><sub>N,1</sub> <i>c</i><sub>N,2</sub> <i>d</i><sub>N</sub><br>
<i>s</i><sub>1</sub><br>
<i>s</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>s</i><sub>M</sub>
<p>
The first line of a dataset contains three integers (<i>N, M, cap</i>), where <i>N</i> is the number of roads
(1 ≤ <i>N</i> ≤ 3000),<i>M</i> is the number of LPG stations (1≤ <i>M</i> ≤ 300), and <i>cap</i> is the tank capacity
(1 ≤ <i>cap</i> ≤ 200) in liter. The next line contains the name of the current city (<i>src</i>) and the name
of the destination city (<i>dest</i>). The destination city is always different from the current city.
The following <i>N</i> lines describe roads that connect cities. The road i (1 ≤ <i>i</i> ≤ N) connects two
different cities <i>c</i><sub>i,1</sub> and <i>c</i><sub>i,2</sub> with an integer distance <i>d</i><sub>i</sub> (0 < <i>d</i><sub>i</sub> ≤ 2000) in kilometer, and he can
go from either city to the other. You can assume that no two different roads connect the same
pair of cities. The columns are separated by a single space. The next <i>M</i> lines (<i>s</i><sub>1</sub>,<i>s</i><sub>2</sub>,...,<i>s</i><sub>M</sub>) indicate the names of the cities with LPG station.
You can assume that a city with LPG station has at least one road.
</p>
<p>
The name of a city has no more than 15 characters. Only English alphabet ('A' to 'Z' and 'a'
to 'z', case sensitive) is allowed for the name.
</p>
<p>
A line with three zeros terminates the input.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing the length (in kilometer) of the shortest possible
journey from the current city to the destination city. If Nakamura cannot reach the destination,
output "-1" (without quotation marks). You must not output any other characters.
The actual tank capacity is usually a little bit larger than that on the specification sheet, so
you can assume that he can reach a city even when the remaining amount of the gas becomes
exactly zero. In addition, you can always fill the tank at the destination so you do not have to
worry about the return trip.
</p>
<H2>Sample Input</H2>
<pre>
6 3 34
Tokyo Kyoto
Tokyo Niigata 335
Tokyo Shizuoka 174
Shizuoka Nagoya 176
Nagoya Kyoto 195
Toyama Niigata 215
Toyama Kyoto 296
Nagoya
Niigata
Toyama
6 3 30
Tokyo Kyoto
Tokyo Niigata 335
Tokyo Shizuoka 174
Shizuoka Nagoya 176
Nagoya Kyoto 195
Toyama Niigata 215
Toyama Kyoto 296
Nagoya
Niigata
Toyama
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
846
-1
</pre> |
p03242 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Cat Snuke is learning to write characters.
Today, he practiced writing digits <code>1</code> and <code>9</code>, but he did it the other way around.</p>
<p>You are given a three-digit integer <var>n</var> written by Snuke.
Print the integer obtained by replacing each digit <code>1</code> with <code>9</code> and each digit <code>9</code> with <code>1</code> in <var>n</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>111 \leq n \leq 999</var></li>
<li><var>n</var> is an integer consisting of digits <code>1</code> and <code>9</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the integer obtained by replacing each occurrence of <code>1</code> with <code>9</code> and each occurrence of <code>9</code> with <code>1</code> in <var>n</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>119
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>991
</pre>
<p>Replace the <code>9</code> in the ones place with <code>1</code>, the <code>1</code> in the tens place with <code>9</code> and the <code>1</code> in the hundreds place with <code>9</code>. The answer is <code>991</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>111
</pre></section>
</div>
</span> |
p03612 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a permutation <var>p_1,p_2,...,p_N</var> consisting of <var>1</var>,<var>2</var>,..,<var>N</var>.
You can perform the following operation any number of times (possibly zero):</p>
<p>Operation: Swap two <strong>adjacent</strong> elements in the permutation.</p>
<p>You want to have <var>p_i â i</var> for all <var>1â€iâ€N</var>.
Find the minimum required number of operations to achieve this.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€Nâ€10^5</var></li>
<li><var>p_1,p_2,..,p_N</var> is a permutation of <var>1,2,..,N</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> .. <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum required number of operations</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 4 3 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Swap <var>1</var> and <var>4</var>, then swap <var>1</var> and <var>3</var>. <var>p</var> is now <var>4,3,1,5,2</var> and satisfies the condition.
This is the minimum possible number, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>Swapping <var>1</var> and <var>2</var> satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>The condition is already satisfied initially.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>9
1 2 4 9 5 8 7 3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre></section>
</div>
</span> |
p02900 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are positive integers <var>A</var> and <var>B</var>.</p>
<p>Let us choose some number of positive common divisors of <var>A</var> and <var>B</var>.</p>
<p>Here, any two of the chosen divisors must be coprime.</p>
<p>At most, how many divisors can we choose?</p>
<details><summary>Definition of common divisor</summary><div>
<p>An integer <var>d</var> is said to be a common divisor of integers <var>x</var> and <var>y</var> when <var>d</var> divides both <var>x</var> and <var>y</var>.</p>
</div></details>
<details><summary>Definition of being coprime</summary><div>
<p>Integers <var>x</var> and <var>y</var> are said to be coprime when <var>x</var> and <var>y</var> have no positive common divisors other than <var>1</var>.</p>
</div></details>
<details><summary>Definition of dividing</summary><div>
<p>An integer <var>x</var> is said to divide another integer <var>y</var> when there exists an integer <var>\alpha</var> such that <var>y = \alpha x</var>.</p>
</div></details>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A, B \leq 10^{12}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of divisors that can be chosen to satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>12 18
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><var>12</var> and <var>18</var> have the following positive common divisors: <var>1</var>, <var>2</var>, <var>3</var>, and <var>6</var>.</p>
<p><var>1</var> and <var>2</var> are coprime, <var>2</var> and <var>3</var> are coprime, and <var>3</var> and <var>1</var> are coprime, so we can choose <var>1</var>, <var>2</var>, and <var>3</var>, which achieve the maximum result.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>420 660
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 2019
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p><var>1</var> and <var>2019</var> have no positive common divisors other than <var>1</var>.</p></section>
</div>
</span> |
p00194 |
<H1>ééäŒç€Ÿ</H1>
<table>
<tr>
<td style="vertical-align:top">
<p>
çœèééã¯äŒæŽ¥è¥æŸåžã代衚ããééäŒç€Ÿã§ããæšä»ã®åæ²¹äŸ¡æ Œã®é«éš°ã¯ééäŒç€Ÿã«ãå€å€§ãªãã¡ãŒãžãäžããééäŒç€Ÿå瀟ã§ã¯ãã§ããã ãå°ãªãã¬ãœãªã³ã§è·ç©ãéã¶ããšã課é¡ãšãªã£ãŠããŸãã
</p>
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_byakkoDelivery1">
</td>
</tr>
</table>
<p>
çœèééã§ã¯ãéãè·ç©ãç©ãã ãã©ãã¯ã¯ããã®èµ°ãã ãã«å€ãã®ãšãã«ã®ãŒãå¿
èŠãšããããšã«çç®ããŸããããã©ãã¯ãå庫ãåºçºããŠããäžåºŠã忢ããããšãªãç®çå°ãŸã§å°éããçµè·¯ã®äžã§æçæéã®çµè·¯ãéãããšã§ãã¬ãœãªã³ã®ç¯çŽãã§ãããšèããŸããã
</p>
<p>
ããªãã®ä»äºã¯ããã®ãããªæççµè·¯ãèšç®ã§ããã«ãŒãããéçºããããšã§ããäœæããã«ãŒããçšããã°ã©ã ã®ä»æ§ã¯ä»¥äžã®ãšããã§ãã
</p>
<ul>
<li>åžå
ã¯ãäžå³ã®ããã«ãæ±è¥¿æ¹åã®éè·¯ <var>M</var> æ¬ãååæ¹åã®éè·¯ <var>N</var> æ¬ ãããªãæ Œåã§è¡šããæ Œåã®å亀ç¹ã¯äº€å·®ç¹ã衚ããŸãã</li>
<li>亀差ç¹ã®ããã€ãã«ã¯æ±è¥¿ - ååã®æ¹åã«ä¿¡å·æ©ãèšçœ®ãããŠãããäžå®ã®åšæã§éãèµ€ã®ã·ã°ãã«ãç¹ç¯ããŠããŸãã</li>
<li>åžå
ã®äº€å·®ç¹éãçµã¶éè·¯ã«ã¯å·¥äºäžã§ééã§ããªãåæãããã€ããããŸãã</li>
<li>ãã©ãã¯ã亀差ç¹ãã亀差ç¹ãžç§»åããã®ã«å¿
èŠãªæéã¯äžå®ã§ãããæžæ»ããŠããéè·¯ã§ã¯ããã«é·ãæéãããããŸãã</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_byakkoDelivery2">
</center>
<br/>
<p>
åžå
ã®éè·¯æ
å ±ããã©ãã¯ã亀差ç¹éãç§»åããã®ã«å¿
èŠãªæéãä¿¡å·æ©ããã亀差ç¹ãšåä¿¡å·æ©ã®åšæãå·¥äºäžã®éè·¯ãæžæ»ããŠããéè·¯ãšæžæ»åºŠãçœèééã®å庫(å§ç¹)ãšç®çå°(çµç¹)ã®äœçœ®ãå
¥åãšããå§ç¹ããçµç¹ãŸã§ã®æçã®æéãåºåããããã°ã©ã ãäœæããŠäžããã
</p>
<p>
å³ã®ããã«ãæ±è¥¿ã®æ¹åã®éè·¯ã¯aãbãcã... ãšè±å°æåã§ååãä»ããã ãååã®æ¹åã®é路㯠1ã2ã3ã... ãšæŽæ°ã§ååãä»ããããŠããŸããåžå
ã®äº€å·®ç¹ã¯ããããã®è±å°æåãšæŽæ°ã®çµã¿åãã <var>H</var>-<var>V</var> ã§æå®ãããŸãã
</p>
<p>
äŸãã°ãåžå
ã®æå西ã®äº€å·®ç¹ã¯ a-1 ã§æå®ãããŸããåä¿¡å·ã¯åšæ <var>k</var> ããã¡ã<var>k</var> åããšã«åãæ¿ãããŸããæ±è¥¿ãéãªãã°ååãèµ€ã§ãååãéãªãã°æ±è¥¿ãèµ€ã§ããé»è²ã®ã·ã°ãã«ã¯ååšããŸããããã©ãã¯ã¯äºã€ã®äº€å·®ç¹ãçµã¶éè·¯ãç§»åããã®ã« <var>D</var> åèŠããŸããããã®éè·¯ãæžæ»ããŠããå Žåã¯ããã« <var>d</var> åã®æéãèŠããŸãããã©ãã¯ã¯éè·¯ãå·¥äºäžã®å Žåã¯ç§»åã§ããŸããã
</p>
<p>
ãŸãã亀差ç¹ã«å°éããæå»ã«ãä¿¡å·ãèµ€ã®å Žåã«ã¯é²å
¥ã§ããŸããããã©ãã¯ã¯äº€å·®ç¹ã§ã®ã¿ãæ±ã西ãåãåã«æ¹åãå€ããããšãã§ããŸãããæ¥ãæ¹åãžã¯ç§»å(Uã¿ãŒã³)ã§ããŸãããéè·¯ã¯2æ¹éè¡ã§ããããã©ãã¯ãè¡ãæ¥ããæéãå·¥äºç¶æ³ãæžæ»åºŠã¯2æ¹åå
±éã§ãã
</p>
<p>
åæç¶æ
ãšããŠããã©ãã¯ã¯æ±ãåããŠããŠããã©ãã¯ãå庫ãåºçºããç¬éãã¹ãŠã®ä¿¡å·æ©ãååã®æ¹åã«éã«åãæ¿ãããã®ãšããŸãããŸãããã©ãã¯ã¯ 100å以å
ã§ç®çå°ã«å°éã§ãããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>M</var> <var>N</var>
<var>D</var>
<var>ns</var>
<var>H<sub>1</sub></var>-<var>V<sub>1</sub></var> <var>k<sub>1</sub></var>
<var>H<sub>2</sub></var>-<var>V<sub>2</sub></var> <var>k<sub>2</sub></var>
:
<var>H<sub>ns</sub></var>-<var>V<sub>ns</sub></var> <var>k<sub>ns</sub></var>
<var>nc</var>
<var>H<sub>11</sub></var>-<var>V<sub>11</sub></var> <var>H<sub>12</sub></var>-<var>V<sub>12</sub></var>
<var>H<sub>21</sub></var>-<var>V<sub>21</sub></var> <var>H<sub>22</sub></var>-<var>V<sub>22</sub></var>
:
<var>H<sub>nc1</sub></var>-<var>V<sub>nc1</sub></var> <var>H<sub>nc2</sub></var>-<var>V<sub>nc2</sub></var>
<var>nj</var>
<var>H<sub>11</sub></var>-<var>V<sub>11</sub></var> <var>H<sub>12</sub></var>-<var>V<sub>12</sub></var> <var>d<sub>1</sub></var>
<var>H<sub>21</sub></var>-<var>V<sub>21</sub></var> <var>H<sub>22</sub></var>-<var>V<sub>22</sub></var> <var>d<sub>2</sub></var>
:
<var>H<sub>nj1</sub></var>-<var>V<sub>nj1</sub></var> <var>H<sub>nj2</sub></var>-<var>V<sub>nj2</sub></var> <var>d<sub>nj</sub></var>
<var>H<sub>s</sub></var>-<var>V<sub>s</sub></var> <var>H<sub>d</sub></var>-<var>V<sub>d</sub></var>
</pre>
<p>
ïŒè¡ç®ã«éè·¯ã®æ¬æ° <var>M</var>, <var>N</var> (2 ≤ <var>M, N</var> ≤ 20) ãäžããããŸããïŒè¡ç®ã«ãäºã€ã®äº€å·®ç¹ãçµã¶éè·¯ãç§»åããã®ã«èŠããæé <var>D</var> (1 ≤ <var>D</var> ≤ D, æŽæ°) ãäžããããŸãã
</p>
<p>
ïŒè¡ç®ã«ä¿¡å·æ©ã®æ° <var>ns</var> ãäžããããŸããç¶ã <var>ns</var> è¡ã«ã<var>i</var> åç®ã®ä¿¡å·æ©ã®äœçœ®ã衚ãè±å°æåãšæŽæ°ã®çµ <var>H<sub>i</sub></var>-<var>V<sub>i</sub></var> ãšåšæ <var>k</var> (1 ≤ <var>k</var> ≤ 100) ãäžããããŸãã
</p>
<p>
ç¶ãè¡ã«ãå·¥äºäžã®éè·¯ã®æ° <var>nc</var> ãäžããããŸããç¶ã <var>nc</var> è¡ã«ã<var>i</var> åç®ã®å·¥äºäžã®éè·¯ã®ïŒã€ã®ç«¯ç¹ïŒäº€å·®ç¹ïŒã衚ãè±å°æåãšæŽæ°ã®çµ <var>H<sub>i1</sub></var>-<var>V<sub>i1</sub></var> <var>H<sub>i2</sub></var>-<var>V<sub>i2</sub></var> ãäžããããŸãã
</p>
<p>
ç¶ãè¡ã«ãæžæ»éè·¯ã®æ° <var>nj</var> ãäžããããŸããç¶ã <var>nj</var> è¡ã«ã<var>i</var> åç®ã®æžæ»éè·¯ã®ïŒã€ã®ç«¯ç¹ïŒäº€å·®ç¹ïŒã衚ãè±å°æåãšæŽæ°ã®çµ <var>H<sub>i1</sub></var>-<var>V<sub>i1</sub></var> <var>H<sub>i2</sub></var>-<var>V<sub>i2</sub></var> ãšæé <var>d<sub>i</sub></var> (1 ≤ <var>d<sub>i</sub></var> ≤ 100) ãäžããããŸãã
</p>
<p>
æåŸã®è¡ã«ãå§ç¹ã®äº€å·®ç¹ <var>H<sub>s</sub></var>-<var>V<sub>d</sub></var> ãšçµç¹ã®äº€å·®ç¹ <var>H<sub>d</sub></var>-<var>V<sub>d</sub></var> ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«æçæéãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
4 5
1
3
b-2 3
c-3 2
c-4 1
3
a-2 b-2
b-3 c-3
d-3 d-4
2
b-3 b-4 1
c-1 d-1 1
d-1 b-4
4 5
1
3
b-2 3
c-3 2
c-4 1
3
a-2 b-2
b-3 c-3
d-3 d-4
2
b-3 b-4 1
c-1 d-1 1
d-2 b-4
4 5
1
3
b-2 3
c-3 2
c-4 1
3
a-2 b-2
b-3 c-3
d-3 d-4
2
b-3 b-4 1
c-1 d-1 1
d-3 b-4
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7
4
8
</pre>
|
p02453 | <h1>Lower Bound</h1>
<p>
For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, find the lower bound for a specific value $k$ given as a query.
</p>
<ul>
<li>
lower bound: the place pointing to the first element greater than or equal to a specific value, or $n$ if there is no such element.
</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ,..., \; a_{n-1}$
$q$
$k_1$
$k_2$
:
$k_q$
</pre>
<p>
The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries.
</p>
<h2>Output</h2>
<p>
For each query, print the position $i$ ($i = 0, 1, ..., n$) of the lower bound in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 100,000$</li>
<li>$1 \leq q \leq 200,000$</li>
<li>$0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$
<li>$0 \leq k_i \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4
1 2 2 4
3
2
3
5
</pre>
<h2>Sample Output 1</h2>
<pre>
1
3
4
</pre>
|
p02003 | <h1>H: æ¿</h1>
<h2>åé¡</h2>
<p>
$R * C$ ã®ãã¹ãäžããããŸãïŒåãã¹ã¯äœããªããã¹ãïŒç©ŽãéããŠãããã¹ã®ã©ã¡ããã§ãïŒ
äžãããããã¹ã¯ä»¥äžã®æ¡ä»¶ãæºãããŸãã
</p>
<ul>
<li> 穎ã®éãããã¹å士ã¯é£çµã§ããïŒïŒç©Žã®éãããã¹ãååæ¹åã«ã€ãã£ãŠä»»æã®ç©Žã®éãããã¹ã«ç§»åããããšãã§ããïŒ</li>
<li> äœããªããã¹å士ã¯é£çµã§ããïŒ</li>
</ul>
<p>
ããªãã¯å¹
ã $1$ ã®ä»»æé·ã®é·æ¹åœ¢åã®ã¿ã€ã«ãçæããããšãã§ããŸãïŒ
ãã®ã¿ã€ã«ãè€æ°æèšçœ®ããŠå
šãŠã®ç©Žã®ãããã¹ãåãããã§ãïŒã¿ã€ã«ãèšçœ®ãããšãïŒä»¥äžã®å¶çŽãå®ãå¿
èŠããããŸãïŒ
</p>
<ul>
<li>ã¿ã€ã«ã¯çžŠåããæšªåãã® $2$ æ¹åã§ã®ã¿èšçœ®ãå¯èœã§ããïŒ</li>
<li>äžã€ã®ãã¹ã«äºæä»¥äžã®ã¿ã€ã«ãéãªãããã«èšçœ®ããŠã¯ãããªãïŒ</li>
<li>穎ã®ãªããã¹ã®äžã«ã¿ã€ã«ããã£ãŠã¯ãããªãïŒ</li>
</ul>
<p>
äžèšã®å¶çŽãå®ã£ãŠå
šãŠã®ç©Žã®ãããã¹ãã¿ã€ã«ã§åãããšãã®ïŒã¿ã€ã«ã®æå°ææ°ãçããŠãã ããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \leq R, C \leq 25$</li>
<li>$|S_i| = C \ \ \ \ |S_i|$ ã¯æååã®é·ãã衚ãã</li>
<li>$S_{i,j}$ 㯠'#' ãŸã㯠'.' ã§ããããã穎ã®éãããã¹ãäœããªããã¹ã衚ãã</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã </p>
<p>
$R\ C$<br>
$S_{1,1} \dots S_{1,C}$<br>
$\vdots$<br>
$S_{R,1} \dots S_{R,C}$<br>
</p>
<h2>åºå</h2>
<p> æå°åæ°ãåºåããŠãã ãããæ«å°Ÿã«æ¹è¡ãåºåããŠãã ããã </p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
5 5
.....
.#.#.
.###.
.#.#.
.....
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
3
</pre>
<p>
$3$ æã®ã¿ã€ã«ã以äžã®ããã«çœ®ãã®ãæé©ã§ã
</p>
<pre>
.....
.1.3.
.123
.1.3
.....
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
4 10
##########
....#.....
....#.....
..........
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
2
</pre>
<p>
$2$ æã®ã¿ã€ã«ã以äžã®ããã«çœ®ãã®ãæé©ã§ãïŒã¿ã€ã«ã®é·ãã¯ä»»æé·ã«ã§ãïŒçžŠåãã«ã暪åãã«ã䜿ããããšã«æ³šæããŠãã ããïŒ
</p>
<pre>
1111111111
....2.....
....2.....
..........
</pre>
|
p01802 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<!-- begin en only -->
<h3><u>Koto Municipal Subway</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>Kotoåžå¶å°äžé</u></h3>
<!-- end ja only -->
<!-- begin ja only -->
<p>Kotoåžã¯ïŒäžå³ã®ããã«ïŒéè·¯ãç¢ç€ã®ç®ç¶ã§ããæåãªè¡ã§ããïŒ
ååã«äŒžã³ãéãšæ±è¥¿ã«äŒžã³ãéã¯ïŒãããã1kmã®ééã§äžŠãã§ããïŒ
Kotoåžã®æãå西ã®äº€å·®ç¹ã«ããKotoé§
ã (0, 0) ãšããŠïŒããããæ±ã« <var>x</var> kmïŒåã« <var>y</var> km é²ãã äœçœ®ã (<var>x</var>, <var>y</var>) ãšèšãããšãšãã (0 ≤ <var>x</var>, <var>y</var> ã§ãã)ïŒ
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2015_A1" height="456" width="414" />
<p>5幎åŸã«éããããªãªã³ããã¯ã«ãã芳å
客ãå¢å€§ããããšãèŠè¶ããŠïŒåžã¯Kotoé§
ãå§çºé§
ãšããæ°ããå°äžéã®è·¯ç·ã建èšããããšã決ããïŒ
çŸåšïŒKotoé§
ã®æ¬¡ã®é§
ãšããŠæ°ãã建èšãããShin-Kotoé§
ãŸã§ã®ã¬ãŒã«ãæ·ãèšç»ãç«ãŠãŠããïŒ
ã¬ãŒã«ã¯ïŒKotoé§
ããShin-Kotoé§
ã«åãã£ãŠãŸã£ããæ·ãïŒ
åŸã£ãŠïŒShin-Kotoé§
ã®å Žæã (<var>x</var>, <var>y</var>) ãšãããšãïŒã¬ãŒã«ã®é·ãã¯ïŒ √(<var>x</var><sup>2</sup> + <var>y</var><sup>2</sup>) ã§ããïŒ
ã¬ãŒã«ãæ·ãããã®è²»çšã¯ïŒæ·ããã¬ãŒã«ã®é·ãåã ãå¿
èŠã«ãªãïŒ
ã¬ãŒã«ã®é·ãã1.5kmã®ããã«å°æ°ã§ãã£ãŠãïŒè²»çšãåãããã«1.5å¿
èŠãšãªãïŒ
</p>
<p>Shin-Kotoé§
ã®å Žæ (<var>x</var>, <var>y</var>) ã¯ãŸã 決å®ããŠãããïŒä»¥äžã®æ¡ä»¶ãæºããå Žæã«ããäºå®ã§ããïŒ
</p>
<ul><li> 亀差ç¹ã§ããïŒã€ãŸãïŒ <var>x</var> ãš <var>y</var> ãããããæŽæ°ã§ããïŒ
</li><li> Kotoé§
ããéè·¯ã«æ²¿ã£ãŠæ©ããæçè·é¢ãïŒã¡ããã© <var>D</var> ã§ããïŒã€ãŸãïŒ <var>x</var> + <var>y</var> = <var>D</var> ãæºããïŒ
</li></ul>
<p>äžã®2ã€ã®æ¡ä»¶ãæºããäžã§ïŒåžãå®ããã¬ãŒã«ã®äºç® <var>E</var> ãšã¬ãŒã«ã®è²»çšãšã®ãã | √(<var>x</var><sup>2</sup> + <var>y</var><sup>2</sup>) - <var>E</var> | ãæå°ãšãªãããã«Shin-Kotoé§
ã®å Žæãéžã¶ïŒ
ããã§ |<var>A</var>| ã¯ïŒ <var>A</var> ã®çµ¶å¯Ÿå€ã衚ãïŒ
ããªãã®ä»äºã¯ïŒäžèšã®ããã«Shin-Kotoé§
ã建èšãããšãã®ïŒã¬ãŒã«ãæ·ãããã®è²»çšãšäºç®ãšã®ãããåºåããããã°ã©ã ãäœæããããšã§ããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ããããæ§æããïŒ1ã€ã®å
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯100以äžã§ããïŒ åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ
</p>
<blockquote><var>D</var> <var>E</var></blockquote>
<p><var>D</var> (1 ≤ <var>D</var> ≤ 100)ã¯ïŒKotoé§
ããShin-Kotoé§
ãŸã§éè·¯ã«æ²¿ã£ãŠæ©ãããšãã®æçè·é¢ãè¡šãæŽæ°ã§ããïŒ
<var>E</var> (1 ≤ <var>E</var> ≤ 100)ã¯ïŒã¬ãŒã«å»ºèšã®ããã®äºç®ãè¡šãæŽæ°ã§ããïŒ
</p>
<p>å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã2ã€ã®ãŒããããªãè¡ã«ãã£ãŠç€ºãããïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸããŠïŒåé¡ã®æ¡ä»¶ãæºããããã«ã¬ãŒã«ãæ·ãããšãã®è²»çšãšäºç®ãšã®ããã1è¡ã§åºåããïŒ
çãã«ã¯ 10<sup>-3</sup> ãè¶ãã絶察誀差ããã£ãŠã¯ãªããªãïŒ
åè¡ã®çµããã«æ¹è¡ãåºåããªãã£ãå ŽåãïŒäžå¿
èŠãªæåãåºåããå ŽåïŒèª€çãšå€æãããŠããŸãããïŒæ³šæããããšïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>2 1
7 5
7 6
7 7
76 5
8 41
0 0</pre>
<h3>Output for Sample Input</h3>
<pre>0.4142135624
0
0.0827625303
0
48.7401153702
33</pre>
<h3>Hint</h3>
<!-- begin ja only -->
<p>1ã€ç®ã®ããŒã¿ã»ããã§ã¯ïŒäžå³ã®ããã«ïŒKotoé§
ããéè·¯ã«æ²¿ã£ãŠ2kmé²ãã 亀差ç¹ãShin-Kotoé§
ã建èšããå Žæã®åè£ãšãªãïŒ
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2015_A2" height="146" width="453" />
<p>å亀差ç¹ã«Shin-Kotoé§
ã建èšããå Žåã®ïŒã¬ãŒã«ãæ·ãããã®è²»çšãšäºç®1ãšã®ããã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<ul><li> (2, 0) ïŒ | √(2<sup>2</sup> + 0<sup>2</sup>) - 1 | = 1.0
</li><li> (1, 1) ïŒ | √(1<sup>2</sup> + 1<sup>2</sup>) - 1 | = 0.4142135623...
</li><li> (0, 2) ïŒ | √(0<sup>2</sup> + 2<sup>2</sup>) - 1 | = 1.0
</li></ul>
<p>ãã£ãŠïŒè²»çšãšäºç®ãšã®ãããæå°ã«ãªãã®ã¯ïŒ (1, 1) ã«å»ºèšããå ŽåãšãªãïŒ
</p>
<!-- end ja only --> |
p00710 |
<h1>
<font color="#000">Problem A:</font> Hanafuda Shuffle
</h1>
<p>
There are a number of ways to shuffle a deck of cards. Hanafuda
shuffling for Japanese card game 'Hanafuda' is one such example.
The following is how to perform Hanafuda shuffling.
</p>
<p>
There is a deck of <I>n</I> cards. Starting from the <I>p</I>-th card
from the top of the deck, <I>c</I> cards are pulled out
and put on the top of the deck, as shown in Figure 1.
This operation, called a cutting operation, is repeated.
</p>
<p>
Write a program that simulates Hanafuda shuffling and answers which
card will be finally placed on the top of the deck.
</p>
<center>
<table>
<tr>
<td ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hanafuda"></td>
</tr>
<tr>
<td ALIGN="center">Figure 1: Cutting operation</td>
</tr>
</table>
</center>
<h2>Input</h2>
<p>
The input consists of multiple data sets.
Each data set starts with a line containing two positive integers <I>n</I>
(1 <= <I>n</I> <= 50) and <I>r</I> (1 <= <I>r</I> <= 50); <I>n</I> and
<I>r</I> are the number of cards in the deck and the number of cutting
operations, respectively.
</p>
<p>
There are <I>r</I> more lines in the data set, each of which
represents a cutting operation. These cutting operations
are performed in the listed order.
Each line contains two positive integers <I>p</I> and <I>c</I>
(<I>p</I> + <I>c</I> <= <I>n</I> + 1).
Starting from the <I>p</I>-th card from the top of the deck, <I>c</I>
cards should be pulled out and put on the top.
</p>
<p>
The end of the input is indicated by a line which contains two zeros.
</p>
<p>
Each input line contains exactly two integers separated by a space
character.
There are no other characters in the line.
</p>
<h2>Output</h2>
<p>
For each data set in the input, your program
should write the number of the top card after the shuffle.
Assume that at the beginning the cards
are numbered from 1 to <I>n</I>, from the bottom to the top.
Each number should be written in a separate line
without any superfluous characters such as leading or following spaces.
</p>
<h2>Sample Input</h2>
<pre>
5 2
3 1
3 1
10 3
1 10
10 1
8 3
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
4
4
</pre>
|
p00340 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>é·æ¹åœ¢ </H1>
<p>
ã¢ã€ã
æŸéåäŒã®æè²çªçµ(æè²)ã§ã¯ãåã©ãåãã®å·¥äœçªçµããããã§ã€ããããæŸéããŠããŸãã仿¥ã¯æ£ã§é·æ¹åœ¢ãäœãåã§ãããçšæããïŒæ¬ã®æ£ã䜿ã£ãŠé·æ¹åœ¢ãã§ãããã確ãããããšæããŸãããã ããæ£ã¯åã£ããæã£ããããŠã¯ãããŸããã
</p>
<br/>
<p>
ïŒæ¬ã®æ£ã®é·ããäžããããã®ã§ãããããã¹ãŠã蟺ãšããé·æ¹åœ¢ãäœãããã©ããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>e<sub>1</suv></var> <var>e<sub>2</suv></var> <var>e<sub>3</suv></var> <var>e<sub>4</suv></var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªãã忣ã®é·ããè¡šãæŽæ° <var>e<sub>i</sub></var> (1 ≤ <var>e<sub>i</sub></var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
é·æ¹åœ¢ãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããæ£æ¹åœ¢ã¯é·æ¹åœ¢ã®äžçš®ãªã®ã§ãæ£æ¹åœ¢ã®å Žåã§ããyesããšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1 1 3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
no
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
1 1 2 2
</pre>
<h2>Sample Output 2</h2>
<pre>
yes
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
2 1 1 2
</pre>
<h2>Sample Output 3</h2>
<pre>
yes
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
4 4 4 10
</pre>
<h2>Sample Output 4</h2>
<pre>
no
</pre>
<br/> |
p03995 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>R</var> rows and <var>C</var> columns.
We call the cell in the <var>r</var>-th row and <var>c</var>-th column (<var>rïŒc</var>).</p>
<p>Mr. Takahashi wrote non-negative integers into <var>N</var> of the cells, that is, he wrote a non-negative integer <var>a_i</var> into (<var>r_iïŒc_i</var>) for each <var>i</var> (<var>1â€iâ€N</var>).
After that he fell asleep.</p>
<p>Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing integers into all remaining cells.
The grid must meet the following conditions to really surprise Mr. Takahashi.</p>
<ul>
<li>Condition <var>1</var>: Each cell contains a non-negative integer.</li>
<li>Condition <var>2</var>: For any <var>2Ã2</var> square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.</li>
</ul>
<p>Determine whether it is possible to meet those conditions by properly writing integers into all remaining cells.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€RïŒCâ€10^5</var></li>
<li><var>1â€Nâ€10^5</var></li>
<li><var>1â€r_iâ€R</var></li>
<li><var>1â€c_iâ€C</var></li>
<li><var>(r_iïŒc_i) â (r_jïŒc_j)</var> (<var>iâ j</var>)</li>
<li><var>a_i</var> is an integer.</li>
<li><var>0â€a_iâ€10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>R</var> <var>C</var>
<var>N</var>
<var>r_1</var> <var>c_1</var> <var>a_1</var>
<var>r_2</var> <var>c_2</var> <var>a_2</var>
<var>:</var>
<var>r_N</var> <var>c_N</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Yes</code> if it is possible to meet the conditions by properly writing integers into all remaining cells.
Otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
3
1 1 0
1 2 10
2 1 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>You can write integers as follows.</p>
<p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_0.png" width="300"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3
5
1 1 0
1 2 10
1 3 20
2 1 30
2 3 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>There are two <var>2Ã2</var> squares on the grid, formed by the following cells:</p>
<ul>
<li>Cells <var>(1ïŒ1)</var>, <var>(1ïŒ2)</var>, <var>(2ïŒ1)</var> and <var>(2ïŒ2)</var></li>
<li>Cells <var>(1ïŒ2)</var>, <var>(1ïŒ3)</var>, <var>(2ïŒ2)</var> and <var>(2ïŒ3)</var></li>
</ul>
<p>You have to write <var>40</var> into the empty cell to meet the condition on the left square, but then it does not satisfy the condition on the right square.</p>
<p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_1.png" width="168"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 2
3
1 1 20
1 2 10
2 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
<p>You have to write <var>-10</var> into the empty cell to meet condition <var>2</var>, but then it does not satisfy condition <var>1</var>.</p>
<p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_2.png" width="120"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3 3
4
1 1 0
1 3 10
3 1 10
3 3 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre>
<p>You can write integers as follows.</p>
<p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_3.png" width="396"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>2 2
4
1 1 0
1 2 10
2 1 30
2 2 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>No
</pre>
<p>All cells already contain a integer and condition <var>2</var> is not satisfied.</p>
<p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_4.png" width="120"/></p></section>
</div>
</span> |
p02687 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoder Inc. holds a contest every Saturday.</p>
<p>There are two types of contests called ABC and ARC, and just one of them is held at a time.</p>
<p>The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.</p>
<p>Given a string <var>S</var> representing the type of the contest held last week, print the string representing the type of the contest held this week.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is <code>ABC</code> or <code>ARC</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string representing the type of the contest held this week.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>ABC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>ARC
</pre>
<p>They held an ABC last week, so they will hold an ARC this week.</p></section>
</div>
</span> |
p01101 |
<h3><u>Taro's Shopping</u></h3>
<p>
Mammy decided to give Taro his first shopping experience.
Mammy tells him to choose any two items he wants from those
listed in the shopping catalogue,
but Taro cannot decide which two, as all the items look attractive.
Thus he plans to buy the pair of two items with
the highest price sum, not exceeding the amount Mammy allows.
As getting two of the same item is boring, he wants two different items.
</p>
<p>
You are asked to help Taro select the two items.
The price list for all of the items is given.
Among pairs of two items in the list,
find the pair with the highest price sum
not exceeding the allowed amount,
and report the sum.
Taro is buying two items, not one, nor three, nor more.
Note that, two or more items in the list may be priced equally.
</p>
<h3>Input</h3>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<pre>
<i>n</i> <i>m</i>
<i>a</i><sub>1</sub> <i>a</i><sub>2</sub> ... <i>a<sub>n</sub></i>
</pre>
<p>
A dataset consists of two lines.
In the first line, the number of items <i>n</i> and the maximum
payment allowed <i>m</i> are given.
<i>n</i> is an integer satisfying 2 ≤ <i>n</i> ≤ 1000.
<i>m</i> is an integer satisfying 2 ≤ <i>m</i> ≤ 2,000,000.
In the second line, prices of <i>n</i> items are given.
<i>a<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) is the price
of the <i>i</i>-th item.
This value is an integer greater than or equal to 1 and
less than or equal to 1,000,000.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
The sum of <i>n</i>'s of all the datasets does not exceed 50,000.
</p>
<h3>Output</h3>
<p>
For each dataset, find the pair with the highest price sum
not exceeding the allowed amount <i>m</i>
and output the sum in a line.
If the price sum of every pair of items exceeds <i>m</i>,
output <tt>NONE</tt> instead.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>3 45
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>40
10
99
NONE
20
</pre>
|
p01551 |
<h1>åé¡å DNA</h1>
<p>éºäŒåã¯ã<code>A</code>, <code>T</code>, <code>G</code>, <code>C</code> ãããªãæååã§ãã
ãã®äžçã®éºäŒåã¯å¥åŠãªããšã«ãããæ§æèŠåã«åŸãããšãç¥ãããŠããŸãã
</p>
<p>æ§æèŠåã¯ã次ã®ãããªåœ¢ã§äžããããŸãã
</p><pre>éçµç«¯èšå·1: èšå·1_1 èšå·1_2 ... èšå·1_n1
éçµç«¯èšå·2: èšå·2_1 èšå·2_2 ... èšå·2_n2
...
éçµç«¯èšå·m: èšå·m_1 èšå·m_2 ... èšå·m_nm
</pre>
<p>èšå·ã¯éçµç«¯èšå·ãŸãã¯çµç«¯èšå·ã®ã©ã¡ããã§ãã
éçµç«¯èšå·ã¯å°æåæååã§è¡šãããçµç«¯èšå·ã¯<code>A</code>, <code>T</code>, <code>G</code>, <code>C</code>ã®ãã¡ã®ããã€ãã®æåãã"<code>[</code>"ãš"<code>]</code>"ã«å²ãŸããæååã§è¡šãããŸãã
</p>
<p>æ§æèŠåã®äŸã¯æ¬¡ã®ããã«ãªããŸãã
</p><pre>dna: a a b b
a: [AT]
b: [GC]
</pre>
<p>"<code>éçµç«¯èšå·i: èšå·i_1 èšå·i_2 ... èšå·i_ni</code>" ãéçµç«¯èšå· <var>i</var> ã®ã«ãŒã«ãšåŒã³ãã«ãŒã«ã¯ãæ§æèŠåã«çŸããåéçµç«¯èšå·ã«å¯ŸããŠãã¡ããã© 1 ã€ã¥ã€ååšããŸãã
</p>
<p>æåå <var>s</var> ãéçµç«¯èšå· <var>i</var> ã«ã<code>ããããã</code>ããšã¯ã <var>s = s<sub>1</sub> + s<sub>2</sub> + ... + s<sub>ni</sub></var> ãšãªããã㪠<var>s</var> ã®éšåæåå <var>{s<sub>j</sub>}</var> ãååšãã<var>s<sub>j</sub></var> (<var>1 ≤ j ≤ n<sub>i</sub></var>)ãã«ãŒã«å
ã®èšå· <var>j</var> ã«ãããããããšããããŸãã
</p>
<p>æåå <var>s</var> ãçµç«¯èšå·ã«ã<code>ããããã</code>ããšã¯ãæååã 1 æåãããªãããã®æåãçµç«¯èšå·ã衚ãæååã«å«ãŸããããšããããŸãã
</p>
<p>æååãæ§æèŠåã«åŸããšã¯ãéçµç«¯èšå· <var>1</var> ã«ãã®æååããããããããšããããŸãã
</p>
<p>ã«ãŒã« <var>i</var> ã¯ãèšå·ã®ãã¡ã«ãéçµç«¯èšå· <var>j</var> (<var>j ≤ i</var>) ãå«ã¿ãŸããã
</p>
<p>æ§æèŠåãšã4ã€ã®æŽæ° <var>Na</var> , <var>Nt</var>, <var>Ng</var>, <var>Nc</var> ãäžããããŸãã
æ§æèŠåã«åŸããA ãã¡ããã© <var>Na</var> åãT ãã¡ããã© <var>Nt</var> åãG ãã¡ããã© <var>Ng</var> åãC ãã¡ããã© <var>Nc</var> åå«ããããªéºäŒåã®ç·æ°ã 1,000,000,007 ã§å²ã£ãäœããæ±ããªããã
</p>
<h2>Input</h2>
<blockquote>
<var>Na</var> <var>Nt</var> <var>Ng</var> <var>Nc</var><br><var>m</var><br>éçµç«¯èšå·1: èšå· <var>1<sub>1</sub></var> èšå· <var>1<sub>2</sub></var> ... èšå· <var>1<sub>n1</sub></var><br>éçµç«¯èšå·2: èšå· <var>2<sub>1</sub></var> èšå· <var>2<sub>2</sub></var> ... èšå· <var>2<sub>n2</sub></var><br>...<br>éçµç«¯èšå· <var>m</var>: èšå· <var>m<sub>1</sub></var> èšå· <var>m<sub>2</sub></var> ... èšå· <var>m<sub>nm</sub></var><br></blockquote>
<p><var>0 ≤ Na, Nt, Ng, Nc ≤ 50</var>
</p>
<p><var>1 ≤ m ≤ 50</var>
</p>
<p><var>1 ≤ ni ≤ 10</var>
</p>
<p><var>1 ≤ </var> èšå·ã衚ãæååã®é·ã <var> ≤ 20</var> (â»èšå·ã«ãããããæååã®é·ãã§ã¯ãªãããšã«æ³šæ)
</p>
<h2>Output</h2>
<p>ç·æ°ã 1,000,000,007 ã§å²ã£ãäœã
</p>
<h2>Sample Input 1</h2>
<pre>1 0 1 0
3
dna: a b
a: [AT]
b: [GC]
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
</pre>
<p>"AG"ã®äžã€ã§ãã
</p>
<h2>Sample Input 2</h2>
<pre>1 1 1 2
1
k: [ATG] [ATG] [ATG] [C] [C]
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>6
</pre>
<p>"ATGCC", "AGTCC", "TAGCC", "TGACC", "GATCC", "GTACC"ã®6ã€ã§ãã
</p>
<h2>Sample Input 3</h2>
<pre>3 1 1 1
3
inv: at b b b
at: [ATG] b
b: [C]
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>0
</pre>
|
p03096 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. The <var>i</var>-th stone from the left is painted in the color <var>C_i</var>.</p>
<p>Snuke will perform the following operation zero or more times:</p>
<ul>
<li>Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.</li>
</ul>
<p>Find the number of possible final sequences of colors of the stones, modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2\times 10^5</var></li>
<li><var>1 \leq C_i \leq 2\times 10^5(1\leq i\leq N)</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>C_1</var>
<var>:</var>
<var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible final sequences of colors of the stones, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1
2
1
2
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We can make three sequences of colors of stones, as follows:</p>
<ul>
<li><var>(1,2,1,2,2)</var>, by doing nothing.</li>
<li><var>(1,1,1,2,2)</var>, by choosing the first and third stones to perform the operation.</li>
<li><var>(1,2,2,2,2)</var>, by choosing the second and fourth stones to perform the operation.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
4
2
5
4
2
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1
3
1
2
3
3
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p03583 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>.</p>
<p>Find a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> such that <var>4/N = 1/h + 1/n + 1/w</var>.</p>
<p>If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>It is guaranteed that, for the given integer <var>N</var>, there exists a solution such that <var>h,n,w \leq 3500</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> that satisfies the condition, in the following format:</p>
<pre><var>h</var> <var>n</var> <var>w</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 2
</pre>
<p><var>4/2 = 1/1 + 1/2 + 1/2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3485
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>872 1012974 1539173474040
</pre>
<p>It is allowed to use an integer exceeding <var>3500</var> in a solution.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4664
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3498 3498 3498
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.