question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00524
<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> <H1> フクロモモンガ(Sugar Glider) </H1> <br/> <p> フクロモモンガのJOI 君が䜏んでいる森にはナヌカリの朚が $N$ 本生えおおりそれらの朚には1 から $N$ の番号が぀いおいる朚 $i$ の高さは $H_i$ メヌトルである </p> <p> JOI 君が盞互に盎接飛び移るこずのできる朚の組が $M$ 組あり各組の朚の間を飛び移るためにかかる時間が定たっおいるJOI 君が朚の間を飛び移っおいる間は地面からの高さが1 秒あたり1 メヌトル䞋がるすなわちJOI 君の珟圚の地面からの高さが $h$ メヌトル朚の間を飛び移るためにかかる時間が $t$ 秒であるずき飛び移った埌の地面からの高さは $h - t$ メヌトルずなるただし$h - t$ が0 よりも小さくなる堎合や行き先の朚の高さよりも倧きくなる堎合は飛び移るこずができない </p> <p> さらにJOI 君は朚の偎面を䞊䞋に移動するこずによっお地面からの高さを0 メヌトルから今いる朚の高さの範囲で増枛させるこずができるJOI 君が地面からの高さを1 メヌトル増加たたは枛少させるためには1 秒の時間がかかる </p> <p> JOI 君は朚1 の高さ$X$ メヌトルの䜍眮から朚$N$ の頂䞊(高さ$H_N$ メヌトルの䜍眮) に行こうずしおおりそのためにかかる時間の最小倀を知りたい </p> <h2>課題</h2> <p> 各朚の高さずJOI 君が盎接飛び移るこずができる朚の組の情報ず最初JOI 君がいる堎所の高さが䞎えられる朚 $N$ の頂䞊に行くためにかかる時間の最小倀を求めるプログラムを䜜成せよ. </p> <h2>入力</h2> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li>1 行目には敎数 $N, M, X$ が空癜を区切りずしお曞かれおいるこれは朚の本数が $N$ 本移動できる朚の組が $M$ 組あり最初JOI 君が朚1 の高さ $X$ メヌトルの䜍眮にいるこずを衚す</li> <li>続く $N$ 行のうちの $i$ 行目$(1 \leq i \leq N)$ には敎数 $H_i$ が曞かれおいるこれは朚 $i$ の高さが $H_i$ メヌトルであるこずを衚す</li> <li>続く$M$ 行のうちの $j$ 行目$(1 \leq j \leq M)$ には敎数 $A_j, B_j, T_j$ $(1 \leq A_j \leq N, 1 \leq B_j \leq N, A_j \ne B_j)$ が空癜を区切りずしお曞かれおいるこれは朚 $A_j$ ず朚 $B_j$ の間を盞互に $T_j$ 秒で飛び移るこずができるこずを衚しおいるたた$1 \leq j < k \leq M$ ならば$(A_j, B_j) \ne (A_k, B_k)$ および$(A_j, B_j) \ne (B_k, A_k)$ を満たす</li> </ul> <h2>出力</h2> <p> 暙準出力に朚1 の高さ $X$ メヌトルの䜍眮から朚 $N$ の頂䞊に行くためにかかる時間の最小倀を秒単䜍で衚す敎数を1 行で出力せよただしそのような方法がない堎合は代わりに -1 を出力せよ </p> <h2>制限</h2> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li> $2 \leq N \leq 100000$</li> <li> $1 \leq M \leq 300000$</li> <li> $1 \leq H_i \leq 1000000000 (1 \leq i \leq N)$</li> <li> $1 \leq T_j \leq 1000000000 (1 \leq j \leq M)$</li> <li> $0 \leq X \leq H_1$</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1 </h3> <pre> 5 5 0 50 100 25 30 10 1 2 10 2 5 50 2 4 20 4 3 1 5 4 20 </pre> <h3>出力䟋 1 </h3> <pre> 110 </pre> <p> 䟋えば以䞋のように移動すればよい<br> 1. 朚1 を50 メヌトル登る<br> 2. 朚1 から朚2 に飛び移る<br> 3. 朚2 から朚4 に飛び移る<br> 4. 朚4 から朚5 に飛び移る<br> 5. 朚5 を10 メヌトル登る<br> </p> <br> <h3>入力䟋 2 </h3> <pre> 2 1 0 1 1 1 2 100 </pre> <h3>出力䟋 2 </h3> <pre> -1 </pre> <p> JOI 君は朚1 から朚2 に飛び移るこずができない </p> <br> <h3>入力䟋 3 </h3> <pre> 4 3 30 50 10 20 50 1 2 10 2 3 10 3 4 10 </pre> <h3>出力䟋 3 </h3> <pre> 100 </pre> <br> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00877
<H1><font color="#000">Problem D:</font> Separate Points</H1> <p> Numbers of black and white points are placed on a plane. Let's imagine that a straight line of infinite length is drawn on the plane. When the line does not meet any of the points, the line divides these points into two groups. If the division by such a line results in one group consisting only of black points and the other consisting only of white points, we say that the line "separates black and white points". </p> <p> Let's see examples in Figure 3. In the leftmost example, you can easily find that the black and white points can be perfectly separated by the dashed line according to their colors. In the remaining three examples, there exists no such straight line that gives such a separation. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_separatePoints"><br> <p>Figure 3: Example planes</p> </center> <p> In this problem, given a set of points with their colors and positions, you are requested to decide whether there exists a straight line that separates black and white points. </p> <H2>Input</H2> <p> The input is a sequence of datasets, each of which is formatted as follows. </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<sub>n</sub> y<sub>n</sub></i><br> <i>x</i><sub><i>n</i>+1</sub> <i>y</i><sub><i>n</i>+1</sub><br> .<br> .<br> .<br> <i>x</i><sub><i>n</i>+<i>m</i></sub> <i>y</i><sub><i>n</i>+<i>m</i></sub><br> </p> <p> The first line contains two positive integers separated by a single space; <i>n</i> is the number of black points, and <i>m</i> is the number of white points. They are less than or equal to 100. Then <i>n</i> + <i>m</i> lines representing the coordinates of points follow. Each line contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> separated by a space, where (<i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> ) represents the <i>x</i>-coordinate and the <i>y</i>-coordinate of the <i>i</i>-th point. The color of the <i>i</i>-th point is black for 1 &le; i &le; <i>n</i>, and is white for <i>n</i> + 1 &le; <i>i</i> &le; <i>n</i> + <i>m</i>. </p> <p> All the points have integral <i>x</i>- and <i>y</i>-coordinate values between 0 and 10000 inclusive. You can also assume that no two points have the same position. </p> <p> The end of the input is indicated by a line containing two zeros separated by a space. </p> <H2>Output</H2> <p> For each dataset, output "<span>YES</span>" if there exists a line satisfying the condition. If not, output "<span>NO</span>". In either case, print it in one line for each input dataset. </p> <H2>Sample Input</H2> <pre> 3 3 100 700 200 200 600 600 500 100 500 300 800 500 3 3 100 300 400 600 400 100 600 400 500 900 300 300 3 4 300 300 500 300 400 600 100 100 200 900 500 900 800 100 1 2 300 300 100 100 500 500 1 1 100 100 200 100 2 2 0 0 500 700 1000 1400 1500 2100 2 2 0 0 1000 1000 1000 0 0 1000 3 3 0 100 4999 102 10000 103 5001 102 10000 102 0 101 3 3 100 100 200 100 100 200 0 0 400 0 0 400 3 3 2813 1640 2583 2892 2967 1916 541 3562 9298 3686 7443 7921 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO NO NO YES YES NO NO NO YES </pre>
p01765
<h1>F : Todaiji / 東倧寺</h1> <h1>Problem</h1> <p>づいあ君は旅行が倧奜きである。奈良旅行に蚪れたづいあ君は、<a href="http://www.nkdaibutsu.com/nara/daibutsuden.html">東倧寺にある柱の穎</a>をくぐるこずにした。しかし、づいあ君は最近倪りだしたため、穎に匕っかかっおしたうかもしれない。そこでづいあ君は、どこたで倪っおも倧䞈倫かを調べるプログラムを曞くこずにした。</p> <p>簡単のため問題は平面䞊で考える。穎は2本の折れ線で、づいあ君は円で衚すこずずする。折れ線 1 は点 (0,0) が始点、点 (1000,0) が終点である。折れ線 2 は点 (0,1000) が始点、点 (1000,1000) が終点である。 づいあ君の党身が <em>x</em> &lt; 0 の領域にある状態から、2 本の折れ線の間を通り、 <em>x</em> &gt; 1000 の領域にづいあ君の党身が出た状態に到達できるような最倧の盎埄を求めおほしい。通過する際の経路は自由であり、円が折れ線に接しおも良い。</p> <h1>Input</h1> <p>入力は次のような圢匏で䞎えられる。</p> <p><em>N<sub>1</sub></em><br><em>x<sub>11</sub></em> <em>y<sub>11</sub></em><br><em>x<sub>12</sub></em> <em>y<sub>12</sub></em><br>...<br><em>x<sub>1N1</sub></em> <em>y<sub>1N1</sub></em><br><em>N<sub>2</sub></em><br><em>x<sub>21</sub></em> <em>y<sub>21</sub></em><br><em>x<sub>22</sub></em> <em>y<sub>22</sub></em><br>...<br><em>x<sub>2N2</sub></em> <em>y<sub>2N2</sub></em></p> <ul> <li><em>N<sub>1</sub></em> は1぀目の折れ線を構成する点の数である。</li> <li><em>x<sub>1i</sub></em>, <em>y<sub>1i</sub></em> は、1぀目の折れ線を構成する <em>i</em> 番目の点の座暙である。(<em>x<sub>1i</sub></em>, <em>y<sub>1i</sub></em>) ず (<em>x<sub>1(i+1)</sub></em>, <em>y<sub>1(i+1)</sub></em>) が結ばれる。</li> <li>(0,0) ず (<em>x<sub>11</sub></em> , <em>y<sub>11</sub></em>)、(<em>x<sub>1N1</sub></em> , <em>y<sub>1N1</sub></em>) ず (1000,0) がそれぞれ線で結ばれる。</li> <li>2぀目の折れ線に぀いおも折れ線1ず同様の圢匏で入力される。ただし、(<em>x<sub>21</sub></em> , <em>y<sub>21</sub></em>) ず結ばれるのは (0,1000)、(<em>x<sub>2N2</sub></em> , <em>y<sub>2N2</sub></em>) ず結ばれるのは (1000,1000) である。</li> </ul> <h1>Constraints</h1> <ul> <li>入力は党お敎数である。</li> <li>1 ≩ <em>N<sub>1</sub></em>, <em>N<sub>2</sub></em> ≩ 50</li> <li>0 ≩ <em>x<sub>ij</sub></em> , <em>y<sub>ij</sub></em> ≩ 1000</li> <li><em>x<sub>ij</sub></em> ≩ <em>x<sub>i(j+1)</sub></em></li> <li>折れ線は自分自身ず亀わらない。</li> <li>2 本の折れ線は亀わらない。</li> </ul> <h1>Output</h1> <p>2 本の折れ線の間を通過できる、づいあ君の䜓の最倧の盎埄を1行で出力せよ。10<sup>-6</sup> たでの誀差は蚱される。</p> <h1>Samples</h1> <h2>Sapmle Input 1</h2> <pre>2 300 300 700 300 2 300 700 700 700</pre> <h2>Sapmle Output 1</h2> <pre>400.0000000000</pre> <h2>Sapmle Input 2</h2> <pre>31 53 334 96 201 99 129 114 365 123 39 186 257 195 247 233 335 256 79 302 217 404 302 411 222 428 422 433 388 441 443 468 309 497 408 518 218 537 361 538 193 541 447 580 16 606 185 610 178 737 421 754 210 805 418 849 416 876 262 878 220 948 207 28 7 919 89 640 145 656 152 963 204 558 252 630 269 690 325 629 357 583 454 593 523 648 538 949 541 821 559 655 581 614 593 877 607 571 631 817 682 942 776 529 810 606 813 598 834 778 838 999 910 661 920 824 982 517 987 689</pre> <h2>Sapmle Output 2</h2> <pre>114.7257599670</pre> <div class="figure"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_todaiji_sample2"> </div> <p>サンプル 2 を図瀺するずこのようになる。</p>
p03758
<span class="lang-en lang-child hidden-lang"> <div class="part"> Max Score: $1500$ Points <br/> <section> <h3>Problem Statement</h3> Huge kingdom: $Atcoder$ contains $N$ towns and $N-1$ roads. This kingdom is connected.<br/> <br/> You have to detect the kingdom's road.<br/> In order to detect, You can ask this form of questions.<br/> <ul> <li>You can output a string $S$. Length of $S$ must be $N$ and The character of string $S$ must be represented by '$0$' or '$1$'.</li> <li>Computer paint the towns with white or black according to the character string you output.</li> <li>If $i$-th character of $S$ is '0', computer paint town $i$ white.</li> <li>If $i$-th character of $S$ is '1', computer paint town $i$ black.</li> <li>Please consider an undirected graph $G$.</li> <li>For each edge, computer do the following processing: If both ends painted black, computer adds this edge to $G$.</li> <li>Computer returns value $x$: sum of "diameter of tree"$^2$ about each connected components.</li> </ul> For example, when $S$="11001111" and the kingdom's structure is this, computer returns 10.<br/> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/18f55c17e4feefd6794b69a1b91d5e6f.png" width="500"/> </div> Please detect the structure of $Atcoder$ as few questions as possible.<br/> </section> </div> <div class="io-style"> <div class="part"> <section> <h3>Input, Output</h3> This is a reactive problem.<br/> The first input is as follows:<br/> <br/> <blockquote> $N$ </blockquote> <ul class="simple"> <li>$N$ is number of towns in $Atcoder$.</li> </ul> <br/> Next, you can ask questions.<br/> The question must be in the form as follows:<br/> <blockquote> ? $S$ </blockquote> $S$ is a string. The mean of $S$ written in the problem statement. Length of $S$ must be $N$.<br/> <br/> The answer of question is as follows:<br/> <blockquote> $x$ </blockquote> The mean of $x$ written in the problem statement.<br/> <br/> Finally, your program must output as follows:<br/> <blockquote> ! $(a_1,b_1)$ $(a_2,b_2)$ $(a_3,b_3)$ 
 $(a_{N-1},b_{N-1})$ </blockquote> This output means your program detects all roads of $Atcoder$.<br/> $(a_i,b_i)$ means there is a road between $a_i$ and $b_i$.<br/> <br/> You can output roads any order, but you must output the answer on a single line.<br/> </section> </div> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>$N$=200</li> <li>$Atcoder$ contains $N-1$ roads and this kingdom is connected.</li> <li>All cases were made randomly.</li> </ul> </section> </div> <div class="part"> <section> <h3>Scoring</h3> Let the number of questions be $L$.<br/> <br/> <ul> <li>If $L &gt; 20000$, $score$ = $0$ points</li> <li>If $18000 &lt; L ≩ 20000$, $score$ = $200$ points</li> <li>If $5000 &lt; L ≩ 18000$, $score$ = $650-L/40$ points</li> <li>If $4000 &lt; L ≩ 5000$, $score$ = $800-L/20$ points</li> <li>If $2000 &lt; L ≩ 4000$, $score$ = $1400-L/5$ points</li> <li>If $1200 &lt; L ≩ 2000$, $score$ = $1500-L/4$ points</li> <li>If $700 &lt; L ≩ 1200$, $score$ = $1850-L/2$ points</li> <li>If $L ≩ 700$, $score$ = $1500$ points</li> </ul> <br/> There is $5$ cases, so points of each case is $score/5$.<br/> </section> </div> <div class="part"> <section> <h3>Sample Input</h3> This case is $N=4$. This case is not include because this is not $N=200$.<br/> <pre> N=4 0 1 1 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output</h3> Sample interaction is as follows:<br/> <table class="table-striped table-bordered table-condensed"> <tr align="center"> <th>Input from computer</th> <th>Output</th> </tr> <tr align="center"> <td>4</td> <td> </td> </tr> <tr align="center"> <td> </td> <td>? 1111</td> </tr> <tr align="center"> <td>4</td> <td> </td> </tr> <tr align="center"> <td> </td> <td>? 1101</td> </tr> <tr align="center"> <td>4</td> <td> </td> </tr> <tr align="center"> <td> </td> <td>? 1001</td> </tr> <tr align="center"> <td>0</td> <td> </td> </tr> <tr align="center"> <td> </td> <td>? 1100</td> </tr> <tr align="center"> <td>1</td> <td> </td> </tr> <tr align="center"> <td> </td> <td>? 1011</td> </tr> <tr align="center"> <td>0</td> <td> </td> </tr> <tr align="center"> <td> </td> <td>! (0,1) (1,2) (1,3)</td> </tr> </table> <br/> In this sample, structure of $Atcoder$ is as follows:<br/> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/8d26e2d0a3fd5e4cc24efe8d21296341.png" width="500"/> </div> <br/> This question is not always meaningful.<br/> </section> </div> </span>
p01335
<h1><font color="#000">Problem C:</font> K Poker</h1> <h2>Description</h2> <p>時は200X幎、K倧孊で掻動する謎のサヌクルKはその倧孊の文化祭の最䞭にK東4Fで圌らが䜜成した新たなゲヌム、Kポヌカヌを発衚した。<br> このゲヌムは䞀芋するず普通のポヌカヌであるが、カヌドに基本点ずいう芁玠を぀けおポヌカヌをより奥の深いゲヌムにしたものである。<br> カヌドの基本点はそれぞれのカヌドに曞かれおいる絵柄によっお決たり、手札の点数は手札にある5枚の基本点の合蚈に手札の圹の倍率を掛けたものになる。<br> この基本点を導入した事により、䟋えばフルハりスなどの匷い圹を䜜ったずしおも基本点が0であればブタず同様に扱われおしたい、ワンペアに負けるこずさえある。<br> それ以倖のルヌルは通垞のポヌカヌず同じである。<br> このKポヌカヌをPCに移怍しようず思ったあなたは手札の点数を蚈算するプログラムを曞く事にした。</p> <p>なおこのゲヌムは18歳未満の人はプレむ出来ない。</p> <h2>Input</h2> <p>入力は耇数のテストケヌスからなる。<br> 各テストケヌスの最初の行にはチェックする手札の数Nが曞かれおいる。<br> 次の4行には13個の敎数が䞊びカヌドの基本点が1-13の順に䞊んで曞かれおいる。4行のスヌツは䞊から順にスペヌド、クロヌバヌ、ハヌト、ダむダの順に䞊んでいる。<br> 次の行には9個の敎数が䞊び、順にワンペア、ツヌペア、スリヌカヌド、ストレヌト、フラッシュ、フルハりス、フォヌカヌド、ストレヌトフラッシュ、ロむダルストレヌトフラッシュの倍率を衚しおいる。圹の倍率は必ず昇順ずなっおいる。ブタ(圹無し、ノヌペア)の倍率は垞に0である。<br> 次のN行には手札を衚す5個の長さ2の異なる文字列が䞊んでいる。1文字目はカヌドの数倀を衚し,A,2,3,4,5,6,7,8,9,T,J,Q,Kのいずれかである。2文字目はカヌドのスヌツを衚し、S,C,H,Dのいずれかである。各アルファベットはAぱヌス、Tは10、Jはゞャック、Qはクむヌン、Kはキング、Sはスペヌド、Cはクロヌバヌ、Hはハヌト、Dはダむダを衚す。<br> 入力の数倀は党お[0,10000]の範囲に収たっおいる。<br> 入力はEOFで終わる。</p> <h2>Output</h2> <p>各手札の点数を1行ず぀出力せよ。<br> 連続する2぀のテストケヌスの間には空行を1぀入れるこず。<br> 圹に぀いおは<a href="http://ja.wikipedia.org/wiki/%E3%83%9D%E3%83%BC%E3%82%AB%E3%83%BC#.E3.83.9D.E3.83.BC.E3.82.AB.E3.83.BC.E3.83.BB.E3.83.8F.E3.83.B3.E3.83.89">wikipediaのポヌカヌ</a>のペヌゞを参照のこず。 なお、ストレヌトぱヌスずキングをたたぐ堎合があるが、手札が10,ゞャック、クむヌン、キング、゚ヌスの堎合にのみストレヌトずみなされる。</p> <h2>Sample Input</h2> <pre> 3 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 2 0 1 1 0 1 1 1 0 0 0 0 5 5 3 1 1 1 0 1 0 0 1 0 3 0 2 1 1 2 4 5 10 20 50 100 7H 6H 2H 5H 3H 9S 9C 9H 8H 8D KS KH QH JD TS 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 AS 3D 2C 5D 6H 6S 6C 7D 8H 9C TS TD QC JD JC KD KH KC AD 2C 3D 4H 6D 5H 7C 2S KS QS AS JS TS TD JD JC TH 8H 8D TC 8C 8S 4S 5S 3S 7S 6S KD QD JD TD AD </pre> <h2>Output for Sample Input</h2> <pre> 25 0 14 0 5 10 15 20 25 30 35 40 45 </pre>
p03308
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer sequence <var>A</var> of length <var>N</var>. Find the maximum absolute difference of two elements (with different indices) in <var>A</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100</var></li> <li><var>1 \leq A_i \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> <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>Print the maximum absolute difference of two elements (with different indices) in <var>A</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 4 6 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>The maximum absolute difference of two elements is <var>A_3-A_1=6-1=5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1000000000 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>999999999 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p02630
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have a sequence <var>A</var> composed of <var>N</var> positive integers: <var>A_{1}, A_{2}, \cdots, A_{N}</var>.</p> <p>You will now successively do the following <var>Q</var> operations:</p> <ul> <li>In the <var>i</var>-th operation, you replace every element whose value is <var>B_{i}</var> with <var>C_{i}</var>.</li> </ul> <p>For each <var>i</var> <var>(1 \leq i \leq Q)</var>, find <var>S_{i}</var>: the sum of all elements in <var>A</var> just after the <var>i</var>-th operation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var> 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5} </var></li> <li><var> B_{i} \neq C_{i} </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>A_{1}</var> <var>A_{2}</var> <var>\cdots</var> <var>A_{N}</var> <var>Q</var> <var>B_{1}</var> <var>C_{1}</var> <var>B_{2}</var> <var>C_{2}</var> <var>\vdots</var> <var>B_{Q}</var> <var>C_{Q}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> integers <var>S_{i}</var> to Standard Output in the following format:</p> <pre><var>S_{1}</var> <var>S_{2}</var> <var>\vdots</var> <var>S_{Q}</var> </pre> <p>Note that <var>S_{i}</var> may not fit into a <var>32</var>-bit integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 3 4 3 1 2 3 4 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>11 12 16 </pre> <p>Initially, the sequence <var>A</var> is <var>1,2,3,4</var>.</p> <p>After each operation, it becomes the following:</p> <ul> <li><var>2, 2, 3, 4</var></li> <li><var>2, 2, 4, 4</var></li> <li><var>4, 4, 4, 4</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 1 1 1 3 1 2 2 1 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 4 4 </pre> <p>Note that the sequence <var>A</var> may not contain an element whose value is <var>B_{i}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 2 3 1 100 2 100 100 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>102 200 2000 </pre></section> </div> </span>
p03922
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is playing with <var>N</var> cards.</p> <p>The <var>i</var>-th card has an integer <var>X_i</var> on it.</p> <p>Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:</p> <ul> <li>The integers on the two cards are the same.</li> <li>The sum of the integers on the two cards is a multiple of <var>M</var>.</li> </ul> <p>Find the maximum number of pairs that can be created.</p> <p>Note that a card cannot be used in more than one pair.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≩N≩10^5</var></li> <li><var>1≩M≩10^5</var></li> <li><var>1≩X_i≩10^5</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>M</var> <var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of pairs that can be created.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 5 3 1 4 1 5 9 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>Three pairs <var>(3,2), (1,4)</var> and <var>(1,9)</var> can be created.</p> <p>It is possible to create pairs <var>(3,2)</var> and <var>(1,1)</var>, but the number of pairs is not maximized with this.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 10 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre></section> </div> </span>
p03888
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In an electric circuit, when two resistors <var>R_1</var> and <var>R_2</var> are connected in parallel, the equivalent resistance <var>R_3</var> can be derived from the following formula:</p> <ul> <li><var>\frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3}</var></li> </ul> <p>Given <var>R_1</var> and <var>R_2</var>, find <var>R_3</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq R_1, R_2 \leq 100</var></li> <li><var>R_1</var> and <var>R_2</var> are integers.</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_1</var> <var>R_2</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the value of <var>R_3</var>.</p> <p>The output is considered correct if the absolute or relative error is at most <var>10^{-6}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1.2000000000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 99 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>49.7487437186 </pre></section> </div> </span>
p02260
<H1>Selection Sort</H1> <p> Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] </pre> <p> Note that, indices for array elements are based on 0-origin. </p> <p> Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i &ne; mini. </p> <H2>Input</H2> <p> The first line of the input includes an integer <i>N</i>, the number of elements in the sequence. </p> <p> In the second line, <i>N</i> elements of the sequence are given separated by space characters. </p> <H2>Output</H2> <p> The output consists of 2 lines. </p> <p> In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. </p> <p> In the second line, please print the number of swap operations. </p> <H2>Constraints</H2> <p> 1 &le; <i>N</i> &le; 100 </p> <H2>Sample Input 1</H2> <pre> 6 5 6 4 2 1 3 </pre> <H2>Sample Output 1</H2> <pre> 1 2 3 4 5 6 4 </pre> <br/> <H2>Sample Input 2</H2> <pre> 6 5 2 4 6 1 3 </pre> <H2>Sample Output 2</H2> <pre> 1 2 3 4 5 6 3 </pre>
p03021
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices numbered <var>1, 2, ..., N</var>. The <var>i</var>-th edge connects Vertex <var>a_i</var> and Vertex <var>b_i</var>. You are also given a string <var>S</var> of length <var>N</var> consisting of <code>0</code> and <code>1</code>. The <var>i</var>-th character of <var>S</var> represents the number of pieces placed on Vertex <var>i</var>.</p> <p>Snuke will perform the following operation some number of times:</p> <ul> <li>Choose two pieces the distance between which is at least <var>2</var>, and bring these pieces closer to each other by <var>1</var>. More formally, choose two vertices <var>u</var> and <var>v</var>, each with one or more pieces, and consider the shortest path between them. Here the path must contain at least two edges. Then, move one piece from <var>u</var> to its adjacent vertex on the path, and move one piece from <var>v</var> to its adjacent vertex on the path.</li> </ul> <p>By repeating this operation, Snuke wants to have all the pieces on the same vertex. Is this possible? If the answer is yes, also find the minimum number of operations required to achieve it.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2000</var></li> <li><var>|S| = N</var></li> <li><var>S</var> consists of <code>0</code> and <code>1</code>, and contains at least one <code>1</code>.</li> <li><var>1 \leq a_i, b_i \leq N(a_i \neq b_i)</var></li> <li>The edges <var>(a_1, b_1), (a_2, b_2), ..., (a_{N - 1}, b_{N - 1})</var> forms 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>S</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>If it is impossible to have all the pieces on the same vertex, print <code>-1</code>. If it is possible, print the minimum number of operations required.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 0010101 1 2 2 3 1 4 4 5 1 6 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>We can gather all the pieces in three operations as follows:</p> <ul> <li>Choose the pieces on Vertex <var>3</var> and <var>5</var>.</li> <li>Choose the pieces on Vertex <var>2</var> and <var>7</var>.</li> <li>Choose the pieces on Vertex <var>4</var> and <var>6</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 0010110 1 2 2 3 1 4 4 5 1 6 6 7 </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>2 01 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p03471
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The commonly used bills in Japan are <var>10000</var>-yen, <var>5000</var>-yen and <var>1000</var>-yen bills. Below, the word "bill" refers to only these.</p> <p>According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained <var>N</var> bills for a total of <var>Y</var> yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 2000</var></li> <li><var>1000 ≀ Y ≀ 2 × 10^7</var></li> <li><var>N</var> is an integer.</li> <li><var>Y</var> is a multiple of <var>1000</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>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the total value of <var>N</var> bills cannot be <var>Y</var> yen, print <code>-1 -1 -1</code>.</p> <p>If the total value of <var>N</var> bills can be <var>Y</var> yen, let one such set of bills be "<var>x</var> <var>10000</var>-yen bills, <var>y</var> <var>5000</var>-yen bills and <var>z</var> <var>1000</var>-yen bills", and print <var>x</var>, <var>y</var>, <var>z</var> with spaces in between. If there are multiple possibilities, any of them may be printed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>9 45000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 0 5 </pre> <p>If the envelope contained <var>4</var> <var>10000</var>-yen bills and <var>5</var> <var>1000</var>-yen bills, he had <var>9</var> bills and <var>45000</var> yen in total. It is also possible that the envelope contained <var>9</var> <var>5000</var>-yen bills, so the output <code>0 9 0</code> is also correct.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>20 196000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 -1 -1 </pre> <p>When the envelope contained <var>20</var> bills in total, the total value would be <var>200000</var> yen if all the bills were <var>10000</var>-yen bills, and would be at most <var>195000</var> yen otherwise, so it would never be <var>196000</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000 1234000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>14 27 959 </pre> <p>There are also many other possibilities.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2000 20000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>2000 0 0 </pre></section> </div> </span>
p03164
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> items, numbered <var>1, 2, \ldots, N</var>. For each <var>i</var> (<var>1 \leq i \leq N</var>), Item <var>i</var> has a weight of <var>w_i</var> and a value of <var>v_i</var>.</p> <p>Taro has decided to choose some of the <var>N</var> items and carry them home in a knapsack. The capacity of the knapsack is <var>W</var>, which means that the sum of the weights of items taken must be at most <var>W</var>.</p> <p>Find the maximum possible sum of the values of items that Taro takes home.</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 W \leq 10^9</var></li> <li><var>1 \leq w_i \leq W</var></li> <li><var>1 \leq v_i \leq 10^3</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>W</var> <var>w_1</var> <var>v_1</var> <var>w_2</var> <var>v_2</var> <var>:</var> <var>w_N</var> <var>v_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the values of items that Taro takes home.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 8 3 30 4 50 5 60 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>90 </pre> <p>Items <var>1</var> and <var>3</var> should be taken. Then, the sum of the weights is <var>3 + 5 = 8</var>, and the sum of the values is <var>30 + 60 = 90</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1000000000 1000000000 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>6 15 6 5 5 6 6 4 6 6 3 5 7 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>17 </pre> <p>Items <var>2, 4</var> and <var>5</var> should be taken. Then, the sum of the weights is <var>5 + 6 + 3 = 14</var>, and the sum of the values is <var>6 + 6 + 5 = 17</var>.</p></section> </div> </span>
p01159
<H1><font color="#000">Problem E:</font> Autocorrelation Function</H1> <p> Nathan O. Davis is taking a class of signal processing as a student in engineering. Today’s topic of the class was autocorrelation. It is a mathematical tool for analysis of signals represented by functions or series of values. Autocorrelation gives correlation of a signal with itself. For a continuous real function <i>f</i>(<i>x</i>), the autocorrelation function <i>R<sub>f</sub></i> (<i>r</i>) is given by </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_autocorrelation1"> </center> <p> where <i>r</i> is a real number. </p> <p> The professor teaching in the class presented an assignment today. This assignment requires students to make plots of the autocorrelation functions for given functions. Each function is piecewise linear and continuous for all real numbers. The figure below depicts one of those functions. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_autocorrelation2"> <p> Figure 1: An Example of Given Functions </p> </center> <p> The professor suggested use of computer programs, but unfortunately Nathan hates programming. So he calls you for help, as he knows you are a great programmer. You are requested to write a program that computes the value of the autocorrelation function where a function <i>f</i>(<i>x</i>) and a parameter <i>r</i> are given as the input. Since he is good at utilization of existing software, he could finish his assignment with your program. </p> <H2>Input</H2> <p> The input consists of a series of data sets. </p> <p> The first line of each data set contains an integer <i>n</i> (3 &le; <i>n</i> &le; 100) and a real number <i>r</i> (-100 &le; <i>r</i> &le; 100), where n denotes the number of endpoints forming sub-intervals in the function <i>f</i>(<i>x</i>), and <i>r</i> gives the parameter of the autocorrelation function <i>R<sub>f</sub></i>(<i>r</i>). The <i>i</i>-th of the following <i>n</i> lines contains two integers <i>x<sub>i</sub></i> (-100 &le; <i>x<sub>i</sub></i> &le; 100) and <i>y<sub>i</sub></i> (-50 &le; <i>y<sub>i</sub></i> &le; 50), where (<i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> ) is the coordinates of the <i>i</i>-th endpoint. The endpoints are given in increasing order of their <i>x</i>-coordinates, and no couple of endpoints shares the same <i>x</i>-coordinate value. The <i>y</i>-coordinates of the first and last endpoints are always zero. </p> <p> The end of input is indicated by <i>n</i> = <i>r</i> = 0. This is not part of data sets, and hence should not be processed. </p> <H2>Output</H2> <p> For each data set, your program should print the value of the autocorrelation function in a line. Each value may be printed with an arbitrary number of digits after the decimal point, but should not contain an error greater than 10<sup>-4</sup> . </p> <H2>Sample Input</H2> <pre> 3 1 0 0 1 1 2 0 11 1.5 0 0 2 7 5 3 7 8 10 -5 13 4 15 -1 17 3 20 -7 23 9 24 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.166666666666667 165.213541666667 </pre>
p03534
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has a string <var>S</var> consisting of three kinds of letters: <code>a</code>, <code>b</code> and <code>c</code>.</p> <p>He has a phobia for palindromes, and wants to permute the characters in <var>S</var> so that <var>S</var> will not contain a palindrome of length <var>2</var> or more as a substring. Determine whether this is possible.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 10^5</var></li> <li><var>S</var> consists of <code>a</code>, <code>b</code> and <code>c</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>If the objective is achievable, print <code>YES</code>; if it is unachievable, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>abac </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>As it stands now, <var>S</var> contains a palindrome <code>aba</code>, but we can permute the characters to get <code>acba</code>, for example, that does not contain a palindrome of length <var>2</var> or more.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>aba </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>babacccabab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre></section> </div> </span>
p01509
<H1>PLAY in BASIC</H1> <p> One sunny day, Dick T. Mustang found an ancient personal computer in the closet. He brought it back to his room and turned it on with a sense of nostalgia, seeing a message coming on the screen: </p> <pre> READY? </pre> <p> Yes. BASIC. </p> <p> BASIC is a programming language designed for beginners, and was widely used from 1980's to 1990's. There have been quite a few BASIC dialects. Some of them provide the PLAY statement, which plays music when called with a string of a musical score written in Music Macro Language (MML). Dick found this statement is available on his computer and accepts the following commands in MML: </p> <dl> <dt>Notes: Cn, C+n, C-n, Dn, D+n, D-n, En,...,... (n = 1,2,4,8,16,32,64,128 + dots)</dt><dd> <p>Each note command consists of a musical note followed by a duration specifier.</p> <p>Each musical note is one of the seven basic notes: 'C', 'D', 'E', 'F', 'G', 'A', and 'B'. It can be followed by either '+' (indicating a sharp) or '-' (a flat). The notes 'C' through 'B' form an octave as depicted in the figure below. The octave for each command is determined by the current octave, which is set by the octave commands as described later. It is not possible to play the note 'C-' of the lowest octave (1) nor the note 'B+' of the highest octave (8).</p> <p>Each duration specifier is basically one of the following numbers: '1', '2', '4', '8', '16', '32', '64', and '128', where '1' denotes a whole note, '2' a half note, '4' a quarter note, '8' an eighth note, and so on. This specifier is <i>optional</i>; when omitted, the duration will be the default one set by the L command (which is described below). In addition, duration specifiers can contain <i>dots</i> next to the numbers. A dot adds the half duration of the basic note. For example, '4.' denotes the duration of '4' (a quarter) plus '8' (an eighth, i.e. half of a quarter), or as 1.5 times long as '4'. It is possible that a single note has more than one dot, where each extra dot extends the duration by half of the previous one. For example, '4..' denotes the duration of '4' plus '8' plus '16', '4...' denotes the duration of '4' plus '8' plus '16' plus '32', and so on. The duration extended by dots cannot be shorter than that of '128' due to limitation of Dick's computer; therefore neither '128.' nor '32...' will be accepted. The dots specified without the numbers extend the default duration. For example, 'C.' is equivalent to 'C4.' when the default duration is '4'. Note that 'C4C8' and 'C4.' are <i>unequivalent</i>; the former contains two distinct notes, while the latter just one note.</p></dd> <dt>Rest: Rn (n = 1,2,4,8,16,32,64,128 + dots)</dt><dd> <p>The R command rests for the specified duration. The duration should be specified in the same way as the note commands, and it can be omitted, too. Note that 'R4R8' and 'R4.' are <i>equivalent</i>, unlike 'C4C8' and 'C4.', since the both rest for the same duration of '4' plus '8'.</p></dd> <dt>Octave: On (n = 1-8), &lt;, &gt;</dt><dd> <p>The O command sets the current octave to the specified number. '&gt;' raises one octave up, and '&lt;' drops one down. It is not allowed to set the octave beyond the range from 1 to 8 by these commands. The octave is initially set to 4.</p></dd> <dt>Default duration: Ln (n = 1,2,4,8,16,32,64,128)</dt><dd> <p>The L command sets the default duration. The duration should be specified in the same way as the note commands, but <i>cannot be omitted nor followed by dots</i>. The default duration is initially set to 4.</p></dd> <dt>Volume: Vn (n = 1-255)</dt><dd> <p>The V command sets the current volume. Larger is louder. The volume is initially set to 100.</p></dd> </dl> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_music2" height="192" width="570"> </center> <p> As an amateur composer, Dick decided to play his pieces of music by the PLAY statement. He managed to write a program with a long MML sequence, and attempted to run the program to play his music -- but unfortunately he encountered an unexpected error: the MML sequence was too long to be handled in his computer's small memory! </p> <p> Since he didn't want to give up all the efforts he had made to use the PLAY statement, he decided immediately to make the MML sequence shorter so that it fits in the small memory. It was too hard for him, though. So he asked you to write a program that, for each given MML sequence, prints the shortest MML sequence (i.e. MML sequence containing minimum number of characters) that expresses the same music as the given one. Note that the final values of octave, volume, and default duration can be differrent from the original MML sequence. </p> <H2>Input</H2> <p> The input consists of multiple data sets. Each data set is given by a single line that contains an MML sequence up to 100,000 characters. All sequences only contain the commands described above. Note that each sequence contains at least one note, and there is no rest before the first note and after the last note. </p> <p> The end of input is indicated by a line that only contains &quot;*&quot;. This is not part of any data sets and hence should not be processed. </p> <H2>Output</H2> <p> For each test case, print its case number and the shortest MML sequence on a line. </p> <p> If there are multiple solutions, print any of them. </p> <H2>Sample Input</H2> <pre> C4C4G4G4A4A4G2F4F4E4E4D4D4C2 O4C4.C8F4.F8G8F8E8D8C2 B-8&gt;C8&lt;B-8V40R2R..R8.V100EV50L1CG * </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: CCGGAAG2FFEEDDC2 Case 2: C.C8F.L8FGFEDC2 Case 3: L8B-B+B-RL1RE4V50CG </pre>
p00748
<h1><font color="#000000">Problem C:</font> Pollock's conjecture</h1> <!-- begin en only --> <p> The <I>n</I>th triangular number is defined as the sum of the first <I>n</I> positive integers. The <I>n</I>th tetrahedral number is defined as the sum of the first <I>n</I> triangular numbers. It is easy to show that the <I>n</I>th tetrahedral number is equal to <I>n</I>(<I>n</I>+1)(<I>n</I>+2)&thinsp;&frasl;&thinsp;6. For example, the 5th tetrahedral number is 1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5) = 5&times;6&times;7&thinsp;&frasl;&thinsp;6 = 35. </p> <!-- end en only --> <dl> <dt> <!-- begin en only --> The first 5 triangular numbers <!-- end en only --> 1, 3, 6, 10, 15 </dt> <dd> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11" alt="Tr[1]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12" alt="Tr[2]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13" alt="Tr[3]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14" alt="Tr[4]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15" alt="Tr[5]" align="top"> </dd> <dt> <!-- begin en only --> The first 5 tetrahedral numbers <!-- end en only --> 1, 4, 10, 20, 35 </dt> <dd> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1" alt="Tet[1]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2" alt="Tet[2]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3" alt="Tet[3]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4" alt="Tet[4]" align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5" alt="Tet[5]" align="top"> </dd> </dl> <!-- begin en only --> <p> In 1850, Sir Frederick Pollock, 1st Baronet, who was not a professional mathematician but a British lawyer and Tory (currently known as Conservative) politician, conjectured that every positive integer can be represented as the sum of at most five tetrahedral numbers. Here, a tetrahedral number may occur in the sum more than once and, in such a case, each occurrence is counted separately. The conjecture has been open for more than one and a half century. </p> <!-- end en only --> <!-- begin en only --> <p> Your mission is to write a program to verify Pollock's conjecture for individual integers. Your program should make a calculation of the least number of tetrahedral numbers to represent each input integer as their sum. In addition, for some unknown reason, your program should make a similar calculation with only odd tetrahedral numbers available. </p> <!-- end en only --> <!-- begin en only --> <p> For example, one can represent 40 as the sum of 2 tetrahedral numbers, 4&times;5&times;6&thinsp;&frasl;&thinsp;6 + 4&times;5&times;6&thinsp;&frasl;&thinsp;6, but 40 itself is not a tetrahedral number. One can represent 40 as the sum of 6 odd tetrahedral numbers, 5&times;6&times;7&thinsp;&frasl;&thinsp;6 + 1&times;2&times;3&thinsp;&frasl;&thinsp;6 + 1&times;2&times;3&thinsp;&frasl;&thinsp;6 + 1&times;2&times;3&thinsp;&frasl;&thinsp;6 + 1&times;2&times;3&thinsp;&frasl;&thinsp;6 + 1&times;2&times;3&thinsp;&frasl;&thinsp;6, but cannot represent as the sum of fewer odd tetrahedral numbers. Thus, your program should report 2 and 6 if 40 is given. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input is a sequence of lines each of which contains a single positive integer less than 10<sup>6</sup>. The end of the input is indicated by a line containing a single zero. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each input positive integer, output a line containing two integers separated by a space. The first integer should be the least number of tetrahedral numbers to represent the input integer as their sum. The second integer should be the least number of odd tetrahedral numbers to represent the input integer as their sum. No extra characters should appear in the output. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 40 14 5 165 120 103 106 139 0 </pre> <h3>Output for the Sample Input</h3> <pre> 2 6 2 14 2 5 1 1 1 18 5 35 4 4 3 37 </pre>
p02775
<span class="lang-en"> <p>Score: <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In the Kingdom of AtCoder, only banknotes are used as currency. There are <var>10^{100}+1</var> kinds of banknotes, with the values of <var>1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}</var>. You have come shopping at a mall and are now buying a takoyaki machine with a value of <var>N</var>. <em>(Takoyaki is the name of a Japanese snack.)</em></p> <p>To make the payment, you will choose some amount of money which is at least <var>N</var> and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus <var>N</var>.</p> <p>What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?</p> <p>Assume that you have sufficient numbers of banknotes, and so does the clerk.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is an integer between <var>1</var> and <var>10^{1,000,000}</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 minimum possible number of total banknotes used by you and the clerk.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>36 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>If you give four banknotes of value <var>10</var> each, and the clerk gives you back four banknotes of value <var>1</var> each, a total of eight banknotes are used.</p> <p>The payment cannot be made with less than eight banknotes in total, so the answer is <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>91 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>If you give two banknotes of value <var>100, 1</var>, and the clerk gives you back one banknote of value <var>10</var>, a total of three banknotes are used.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>243 </pre></section> </div> </span>
p03867
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi and Aoki are going to together construct a sequence of integers.</p> <p>First, Takahashi will provide a sequence of integers <var>a</var>, satisfying all of the following conditions:</p> <ul> <li>The length of <var>a</var> is <var>N</var>.</li> <li>Each element in <var>a</var> is an integer between <var>1</var> and <var>K</var>, inclusive.</li> <li><var>a</var> is a <em>palindrome</em>, that is, reversing the order of elements in <var>a</var> will result in the same sequence as the original.</li> </ul> <p>Then, Aoki will perform the following operation an arbitrary number of times:</p> <ul> <li>Move the first element in <var>a</var> to the end of <var>a</var>.</li> </ul> <p>How many sequences <var>a</var> can be obtained after this procedure, modulo <var>10^9+7</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀N≀10^9</var></li> <li><var>1≀K≀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>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the sequences <var>a</var> that can be obtained after the procedure, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>The following six sequences can be obtained:</p> <ul> <li><var>(1, 1, 1, 1)</var></li> <li><var>(1, 1, 2, 2)</var></li> <li><var>(1, 2, 2, 1)</var></li> <li><var>(2, 2, 1, 1)</var></li> <li><var>(2, 1, 1, 2)</var></li> <li><var>(2, 2, 2, 2)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 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>6 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>75 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>875699961 </pre></section> </div> </span>
p00318
<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> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_hibara" width="700"> </center> <br/> <p> 䞊図のような盎線で衚された海岞線䞊に芳枬点を蚭眮し、探査レヌダを眮く。探査レヌダでは、芳枬点を䞭心ずする、ある倧きさの半円の範囲に遺跡があるずいうこずしかわからない。しかし、耇数の芳枬デヌタを組み合わせるこずで、より狭い範囲に絞り蟌むこずができる。 </p> <p> 芳枬点の䜍眮ず探査レヌダが瀺す半埄からなるいく぀かの芳枬デヌタが䞎えられたずき、海岞線から最倧でどのくらいの距離たで調査する必芁があるかを求めるプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>x<sub>1</sub></var> <var>r<sub>1</sub></var> <var>x<sub>2</sub></var> <var>r<sub>2</sub></var> : <var>x<sub>N</sub></var> <var>r<sub>N</sub></var> </pre> <p> 行目に探査レヌダによっお枬定されたデヌタの数 <var>N</var> (1 &le; <var>N</var> &le; 100000) が䞎えられる。続く <var>N</var> 行に、芳枬デヌタ <var>i</var> の海岞線䞊での䜍眮をメヌトル単䜍で衚す敎数 <var>x<sub>i</sub></var> (0 &le; <var>x<sub>i</sub></var> &le; 1,000,000) ず、その䜍眮から半埄䜕メヌトル以内に遺跡が存圚するかを衚す敎数 <var>r<sub>i</sub></var> (1 &le; <var>r<sub>i</sub></var> &le; 1,000,000) が䞎えられる。芳枬点が同じ芳枬デヌタが぀以䞊䞎えられるこずもある。 </p> <p> 䞎えられた芳枬デヌタが耇数の堎合、それらすべおの半円に含たれる点が必ず存圚するず考えおよい。 </p> <h2>Output</h2> <p> 海岞線から最倧で䜕メヌトルたで調査する必芁があるかを実数で出力する。ただし、誀差がプラスマむナス 0.001 メヌトルを超えおはならない。この条件を満たせば小数点以䞋は䜕桁衚瀺しおもよい。 </p> <h2>Sample Input 1</h2> <pre> 2 0 2 1 2 </pre> <h2>Sample Output 1</h2> <pre> 1.936 </pre> <br/> <h2>Sample Input 2</h2> <pre> 3 0 3 1 2 2 1 </pre> <h2>Sample Output 2</h2> <pre> 1.0 </pre> <br/> <h2>Sample Input 3</h2> <pre> 2 0 1 3 2 </pre> <h2>Sample Output 3</h2> <pre> 0.0 </pre>
p02325
<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>Bitonic Traveling Salesman Problem (Bitonic TSP)</H1> <p> For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria: </p> <ul> <li>Visit the points according to the following steps: <ol> <li>It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point). </li> <li>Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point.</li> </ol> </li> <li>Through the processes 1. 2., the tour must visit each point at least once.</li> </ul> <h2>Input</h2> <p>The input data is given in the following format:</p> <p> $N$<br> $x_1$ $y_1$<br> $x_2$ $y_2$<br> ...<br> $x_N$ $y_N$<br> </p> <h2>Constraints</h2> <ul> <li> $2 \leq N \leq 1000$ </li> <li> $-1000 \leq x_i, y_i \leq 1000$</li> <li> $x_i$ differ from each other</li> <li> The given points are already sorted by x-coordinates</li> </ul> <h2>Output</h2> <p> Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001. </p> <h2>Sample Input 1</h2> <pre> 3 0 0 1 1 2 0 </pre> <h2>Sample Output 1</h2> <pre> 4.82842712 </pre> <h2>Sample Input 2</h2> <pre> 4 0 1 1 2 2 0 3 1 </pre> <h2>Sample Output 2</h2> <pre> 7.30056308 </pre> <h2>Sample Input 3</h2> <pre> 5 0 0 1 2 2 1 3 2 4 0 </pre> <h2>Sample Output 3</h2> <pre> 10.94427191 </pre>
p00436
<H1>カヌドの䞊び替え</H1> <h2>問題</h2> <p> 1 から 2n の数が曞かれた 2n 枚のカヌドがあり䞊から 1, 2, 3, ... , 2n の順に積み重なっおいる </p> <p> このカヌドを次の方法を䜕回か甚いお䞊べ替える </p> <p> <b>敎数 k でカット</b><br> 䞊から k 枚のカヌドの山 A ず 残りのカヌドの山 B に分けた埌 å±± A の䞊に山 B をのせる </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card01"> </center> <br/> <p> <b>リフルシャッフル</b><br> 䞊から n 枚の山 A ず残りの山 B に分け 䞊から A の1枚目 B の1枚目 A の2枚目 B の2枚目   A の n枚目 B の n枚目 ずなるようにしお 1 ぀の山にする </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card02"> </center> <br/> <p> 入力<!--ファむル-->の指瀺に埓いカヌドを䞊び替えたあずのカヌドの番号を䞊から順番に出力するプログラムを䜜成せよ </p> <H2>入力</H2> <ul> <li> 1 行目には n 1 ≩ n ≩ 100が曞かれおいる すなわちカヌドの枚数は 2n 枚である</li> <li> 2 行目には操䜜の回数 m 1 ≩ m ≩ 1000が曞かれおいる</li> <li> 3 行目から m + 2 行目たでの m 行には 0 から 2n-1 たでのいずれか 1 ぀の敎数 k が曞かれおおり カヌドを䞊べ替える方法を順に指定しおいる <ul> <li> k = 0 の堎合は リフルシャッフルを行う</li> <li> 1 ≩ k ≩ 2n-1 の堎合は k でカットを行う </li> </ul> </li> </ul> <H2>出力</H2> <p> <!--2n 行からなるを出力ファむルを提出せよ-->出力は2n 行からなる 1 行目には䞊べ替え終了埌の䞀番䞊のカヌドの番号 2 行目には䞊べ替え終了埌の䞊から 2 番目のカヌドの番号ずいうように i 行目には䞊から i 番目のカヌドの番号を出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 2 2 1 0 </pre> <h3>出力䟋 1</h3> <pre> 2 4 3 1 </pre> <br> <h3>入力䟋 2</h3> <pre> 3 4 2 4 0 0 </pre> <h3>出力䟋 2</h3> <pre> 1 5 4 3 2 6 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00066
<H1>䞉目䞊べ</H1> <p> 䞉目䞊べは &times; のマス目の䞭に亀互に ○ ず × を入れおいき、瞊・暪・斜めの䜕れかに䞀列 ○ か × が䞊んだずきに、勝ちずなるゲヌムです図1〜図3 を参照 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td> </tr> <tr> <td>図○の勝ち</td> <td>図× の勝ち</td> <td>図匕き分け</td> </tr> </table> </center> <br/> <p> 䞉目䞊べは、○ず×が亀互にマス目を埋めおいき、どちらかが䞀列揃ったずきにゲヌム終了ずなりたす。そのため、図 4 のように、○ず×が䞡方ずも䞀列そろっおいる堎合はありえない局面です。ありえない局面が入力されるこずはありたせん。 </p> <center> <table> <tr> <td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td> </tr> <tr> <td>図ありえない局面</td> </tr> </table> </center> <br/> <p> 䞉目䞊べの盀面を読み蟌んで、勝敗の結果を出力するプログラムを䜜成しお䞋さい。 </p> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなりたす。各デヌタセットずしお、盀面を衚す぀の文字列が行に䞎えられたす。 盀面の文字列は、○、×、空癜をそれぞれ半角英小文字の o、x、s であらわし、䞋図のマス目の順に䞊んでいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5"> </center> <br/> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、○が勝ちなら半角英小文字の o を、×が勝ちなら半角英小文字の x を、匕き分けならば半角英小文字の d を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> ooosxssxs xoosxsosx ooxxxooxo </pre> <H2>Output for the Sample Input</H2> <pre> o x d </pre>
p04025
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Evi has <var>N</var> integers <var>a_1,a_2,..,a_N</var>. His objective is to have <var>N</var> equal <strong>integers</strong> by transforming some of them.</p> <p>He may transform each integer at most once. Transforming an integer <var>x</var> into another integer <var>y</var> costs him <var>(x-y)^2</var> dollars. Even if <var>a_i=a_j (i≠j)</var>, he has to pay the cost separately for transforming each of them (See Sample 2).</p> <p>Find the minimum total cost to achieve his objective.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩100</var></li> <li><var>-100≩a_i≩100</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>a_2</var> ... <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total cost to achieve Evi's objective.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>Transforming the both into <var>6</var>s will cost <var>(4-6)^2+(8-6)^2=8</var> dollars, which is the minimum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>Transforming the all into <var>2</var>s will cost <var>(1-2)^2+(1-2)^2+(3-2)^2=3</var> dollars. Note that Evi has to pay <var>(1-2)^2</var> dollar separately for transforming each of the two <var>1</var>s.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 4 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre> <p>Leaving the <var>4</var> as it is and transforming the <var>2</var> and the <var>5</var> into <var>4</var>s will achieve the total cost of <var>(2-4)^2+(5-4)^2=5</var> dollars, which is the minimum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 -100 -100 -100 -100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 </pre> <p>Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is <var>0</var>.</p></section> </div> </span>
p01227
<h1><font color="#000">Problem E:</font> カントリヌロヌド</h1> <p> ある過疎地域での話である この地域ではカントリヌロヌドず呌ばれるたっすぐな道に沿っお 家がたばらに建っおいる 今たでこの地域には電気が通っおいなかったのだが 今回政府からいく぀かの発電機が䞎えられるこずになった 発電機は奜きなずころに蚭眮できるが 家に電気が䟛絊されるにはどれかの発電機に電線を介しお぀ながっおいなければならず 電線には長さに比䟋するコストが発生する 地域で唯䞀の技術系公務員であるあなたの仕事は すべおの家に電気が䟛絊されるずいう条件の䞋で できるだけ電線の長さの総蚈が短くなるような発電機 および電線の配眮を求めるこずである なお発電機の容量は十分に倧きいので いくらでも倚くの家に電気を䟛絊するこずができるものずする </p> <p> サンプル入力の1番目のデヌタセットを図2に瀺す この問題に察する最適な配眮を䞎えるには 図のように <var>x</var> = 20 ず <var>x</var> = 80 の䜍眮に発電機を配眮し それぞれ図䞭のグレヌで瀺した䜍眮に電線を匕けばよい </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_road" alt="発電機ず電線の配眮の䟋入力䟋の最初のデヌタセット"> </td> </tr> <tr> <td>図2: 発電機ず電線の配眮の䟋入力䟋の最初のデヌタセット</td> </tr> </table> </center> <h2>Input</h2> <p> 入力の1行目にはデヌタセットの個数 <var>t</var> (0 &lt; <var>t</var> &le; 50) が䞎えられる </p> <p> 匕き続き <var>t</var> 個のデヌタセットが䞎えられる デヌタセットはそれぞれ次のような圢匏で2行で䞎えられる </p> <pre> <var>n</var> <var>k</var> <var>x</var><sub>1</sub> <var>x</var><sub>2</sub> ... <var>x</var><sub><var>n</var></sub> </pre> <p> <var>n</var> は家の戞数<var>k</var> は発電機の個数である <var>x</var><sub>1</sub>, <var>x</var><sub>2</sub>, ..., <var>x</var><sub><var>n</var></sub> はそれぞれ家の䜍眮を衚す䞀次元座暙である これらの倀はすべお敎数であり 0 &lt; <var>n</var> &le; 100000, 0 &lt; <var>k</var> &le; 100000, 0 &le; <var>x</var><sub>1</sub> &lt; <var>x</var><sub>2</sub> &lt; ... &lt; <var>x</var><sub><var>n</var></sub> &le; 1000000 を満たす </p> <p> さらにデヌタセットのうち 90% は 0 &lt; <var>n</var> &le; 100, 0 &lt; <var>k</var> &le; 100 を満たしおいる </p> <h2>Output</h2> <p> 各デヌタセットに察し 必芁な電線の長さの総蚈の最小倀を1行に出力せよ </p> <h2>Sample Input</h2> <pre> 6 5 2 10 30 40 70 100 7 3 3 6 10 17 21 26 28 1 1 100 2 1 0 1000000 3 5 30 70 150 6 4 0 10 20 30 40 50 </pre> <h2>Output for the Sample Input</h2> <pre> 60 13 0 1000000 0 20 </pre>
p02958
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a sequence <var>p</var> = {<var>p_1,\ p_2,\ ...,\ p_N</var>} which is a permutation of {<var>1,\ 2,\ ...,\ N</var>}.</p> <p>You can perform the following operation at most once: choose integers <var>i</var> and <var>j</var> <var>(1 \leq i &lt; j \leq N)</var>, and swap <var>p_i</var> and <var>p_j</var>. Note that you can also choose not to perform it.</p> <p>Print <code>YES</code> if you can sort <var>p</var> in ascending order in this way, and <code>NO</code> otherwise.</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>p</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>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>YES</code> if you can sort <var>p</var> in ascending order in the way stated in the problem statement, and <code>NO</code> otherwise.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 2 3 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>You can sort <var>p</var> in ascending order by swapping <var>p_1</var> and <var>p_5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 4 3 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p>In this case, swapping any two elements does not sort <var>p</var> in ascending order.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 2 3 4 5 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre> <p><var>p</var> is already sorted in ascending order, so no operation is needed.</p></section> </div> </span>
p00965
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <h2>Problem I Starting a Scenic Railroad Service </h2> <p> Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a scenic valley will arise a big boom, but not quite sure how big the boom will be. </p> <p> A market survey was ordered and Jim has just received an estimated list of passengers' travel sections. Based on the list, he'd like to estimate the minimum number of train seats that meets the demand. </p> <p> Providing as many seats as all of the passengers may cost unreasonably high. Assigning the same seat to more than one passenger without overlapping travel sections may lead to a great cost cutback. </p> <p> Two different policies are considered on seat assignments. As the views from the train windows depend on the seat positions, it would be better if passengers can choose a seat. One possible policy (named `policy-1') is to allow the passengers to choose an arbitrary seat among all the remaining seats when they make their reservations. As the order of reservations is unknown, all the possible orders must be considered on counting the required number of seats. </p> <p> The other policy (named `policy-2') does not allow the passengers to choose their seats; the seat assignments are decided by the railroad operator, not by the passengers, after all the reservations are completed. This policy may reduce the number of the required seats considerably. </p> <p> Your task is to let Jim know how di erent these two policies are by providing him a program that computes the numbers of seats required under the two seat reservation policies. Let us consider a case where there are four stations, S1, S2, S3, and S4, and four expected passengers $p_1$, $p_2$, $p_3$, and $p_4$ with the travel list below. </p> <center> <table> <tr> <th width="120">passenger</th> <th width="120">from</th> <th width="120">to</th> </tr> <tr> <td>$p_1$</td> <td>S1</td> <td>S2</td> </tr> <tr> <td>$p_2$</td> <td>S2</td> <td>S3</td> </tr> <tr> <td>$p_3$</td> <td>S1</td> <td>S3</td> </tr> <tr> <td>$p_4$</td> <td>S3</td> <td>S4</td> </tr> </table> </center> <br/> <p> The travel sections of $p_1$ and $p_2$ do not overlap, that of $p_3$ overlaps those of $p_1$ and $p_2$, and that of $p_4$ does not overlap those of any others. </p> <p> Let's check if two seats would suffice under the policy-1. If $p_1$ books a seat first, either of the two seats can be chosen. If $p_2$ books second, as the travel section does not overlap that of $p_1$, the same seat can be booked, but the other seat may look more attractive to $p_2$. If $p_2$ reserves a seat different from that of $p_1$, there will remain no available seats for $p_3$ between S1 and S3 (Figure I.1). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_railroadService1" width="600"> <p>Figure I.1. With two seats</p> </center> <p> With three seats, $p_3$ can find a seat with any seat reservation combinations by $p_1$ and $p_2$. $p_4$ can also book a seat for there are no other passengers between S3 and S4 (Figure I.2). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_railroadService2" width="600"> <p>Figure I.2. With three seats</p> </center> <p> For this travel list, only three seats suffice considering all the possible reservation orders and seat preferences under the policy-1. </p> <p> On the other hand, deciding the seat assignments after all the reservations are completed enables a tight assignment with only two seats under the policy-2 (Figure I.3). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_railroadService3" width="600"> <p>Figure I.3. Tight assignment to two seats</p> </center> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $a_1$ $b_1$ ... $a_n$ $b_n$ </pre> <p> Here, the first line has an integer $n$, the number of the passengers in the estimated list of passengers' travel sections ($1 \leq n \leq 200 000$). The stations are numbered starting from 1 in their order along the route. Each of the following $n$ lines describes the travel for each passenger by two integers, the boarding and the alighting station numbers, $a_i$ and $b_i$, respectively ($1 \leq a_i < b_i \leq 100 000$). Note that more than one passenger in the list may have the same boarding and alighting stations. </p> <h3>Output</h3> <p> Two integers $s_1$ and $s_2$ should be output in a line in this order, separated by a space. $s_1$ and $s_2$ are the numbers of seats required under the policy-1 and -2, respectively. </p> <h3>Sample Input 1</h3> <pre> 4 1 3 1 3 3 6 3 6 </pre> <h3>Sample Output 1</h3> <pre> 2 2 </pre> <h3>Sample Input 2</h3> <pre> 4 1 2 2 3 1 3 3 4 </pre> <h3>Sample Output 2</h3> <pre> 3 2 </pre> <h3>Sample Input 3</h3> <pre> 10 84 302 275 327 364 538 26 364 29 386 545 955 715 965 404 415 903 942 150 402 </pre> <h3>Sample Output 3</h3> <pre> 6 5 </pre>
p01677
<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> <h3>Problem Statement</h3> <p>Nathan O. Davis is a student at the department of integrated systems. </p> <p>Today's agenda in the class is audio signal processing. Nathan was given a lot of homework out. One of the homework was to write a program to process an audio signal. He copied the given audio signal to his USB memory and brought it back to his home. </p> <p>When he started his homework, he unfortunately dropped the USB memory to the floor. He checked the contents of the USB memory and found that the audio signal data got broken. </p> <p>There are several characteristics in the audio signal that he copied. </p><ul><li><p> The audio signal is a sequence of $N$ samples. </p></li><li><p> Each sample in the audio signal is numbered from $1$ to $N$ and represented as an integer value. </p></li><li><p> Each value of the odd-numbered sample(s) is strictly smaller than the value(s) of its neighboring sample(s). </p></li><li><p> Each value of the even-numbered sample(s) is strictly larger than the value(s) of its neighboring sample(s). </p></li></ul> <p>He got into a panic and asked you for a help. You tried to recover the audio signal from his USB memory but some samples of the audio signal are broken and could not be recovered. Fortunately, you found from the metadata that all the broken samples have the same integer value. </p> <p>Your task is to write a program, which takes the broken audio signal extracted from his USB memory as its input, to detect whether the audio signal can be recovered uniquely. </p> <h3>Input</h3> <p>The input consists of multiple datasets. The form of each dataset is described below. </p> <blockquote>$N$<br>$a_{1}$ $a_{2}$ ... $a_{N}$</blockquote> <p>The first line of each dataset consists of an integer, $N (2 \le N \le 1{,}000)$. $N$ denotes the number of samples in the given audio signal. The second line of each dataset consists of $N$ values separated by spaces. The $i$-th value, $a_{i}$, is either a character <code>x</code> or an integer between $-10^9$ and $10^9$, inclusive. It represents the $i$-th sample of the broken audio signal. If $a_{i}$ is a character <code>x</code> , it denotes that $i$-th sample in the audio signal is broken. Otherwise it denotes the value of the $i$-th sample. </p> <p>The end of input is indicated by a single $0$. This is not included in the datasets. </p> <p>You may assume that the number of the datasets does not exceed $100$. </p> <h3>Output</h3> <p>For each dataset, output the value of the broken samples in one line if the original audio signal can be recovered uniquely. If there are multiple possible values, output <code>ambiguous</code>. If there are no possible values, output <code>none</code>. </p> <h3>Sample Input</h3> <pre>5 1 x 2 4 x 2 x x 2 1 2 2 2 1 2 1000000000 x 4 x 2 1 x 0</pre> <h3>Output for the Sample Input</h3> <pre>3 none ambiguous none ambiguous none</pre>
p01362
<H1><font color="#000">Problem D:</font> Dice Room</H1> <p> You are playing a popular video game which is famous for its depthful story and interesting puzzles. In the game you were locked in a mysterious house alone and there is no way to call for help, so you have to escape on yours own. However, almost every room in the house has some kind of puzzles and you cannot move to neighboring room without solving them. </p> <p> One of the puzzles you encountered in the house is following. In a room, there was a device which looked just like a dice and laid on a table in the center of the room. Direction was written on the wall. It read: </p> <p> "This cube is a remote controller and you can manipulate a remote room, Dice Room, by it. The room has also a cubic shape whose surfaces are made up of 3x3 unit squares and some squares have a hole on them large enough for you to go though it. You can rotate this cube so that in the middle of rotation at least one edge always touch the table, that is, to 4 directions. Rotating this cube affects the remote room in the same way and positions of holes on the room change. To get through the room, you should have holes on at least one of lower three squares on the front and back side of the room." </p> <p> You can see current positions of holes by a monitor. Before going to Dice Room, you should rotate the cube so that you can go though the room. But you know rotating a room takes some time and you don’t have much time, so you should minimize the number of rotation. How many rotations do you need to make it possible to get though Dice Room? </p> <H2>Input</H2> <p> The input consists of several datasets. Each dataset contains 6 tables of 3x3 characters which describe the initial position of holes on each side. Each character is either '<span>*</span>' or '<span>.</span>'. A hole is indicated by '<span>*</span>'. The order which six sides appears in is: front, right, back, left, top, bottom. The order and orientation of them are described by this development view: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_diceRoom1"> <p> Figure 4: Dice Room </p> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_diceRoom2"> <p> Figure 5: available dice rotations </p> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_diceRoom3"> <p> </p> </center> <p> There is a blank line after each dataset. The end of the input is indicated by a single '<span>#</span>'. </p> <H2>Output</H2> <p> Print the minimum number of rotations needed in a line for each dataset. You may assume all datasets have a solution. </p> <H2>Sample Input</H2> <pre> ... ... .*. ... ... .*. ... ... ... ... ... .*. ... ... .*. ... ... ... ... .*. ... *.. ... ..* *.* *.* *.* *.* .*. *.* *.. .*. ..* *.* ... *.* ... .*. .*. ... .** *.. ... ... .*. .*. ... *.. ..* ... .** ... *.. ... # </pre> <H2>Output for the Sample Input</H2> <pre> 3 1 0 </pre>
p01698
<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> <!-- begin en only --> <!--<h3><u>Wish upon a shooting star</u></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><u>流れ星に願いを</u></h3> <!-- end ja only --> <!-- begin en only --> <!-- end en only --> <!-- begin ja only --> <p>謎の組織 JAG (Japanese Alumni Group) では定期的に䌚議を開いおいるある日の議題は「近日行われる ICPC (International Collegiate Programming Contest) 囜内予遞で参加チヌムが力を発揮できるようにするには」であった䌚議の結論ずしお流れ星に各チヌムの健闘を祈るこずになり圌らは本郚を眮く建物の屋䞊に出た </p> <p>圌らが屋䞊に出るず空には $n$ 個の流れ星が芋えおいた流れ星は3次元空間䞊の球ずしお衚され$1$ から $n$ の番号が割り振られおいる星に詳しいメンバヌにより各流れ星は䞀定の速床で盎線的に移動するず同時に䞀定の速床で半埄が小さくなっおいくずみなせるこずが分かった実際に枬定しおみたずころ各流れ星の初期䜍眮 $(px_i, py_i, pz_i)$移動速床 $(vx_i, vy_i, vz_i)$初期半埄 $r_i$消滅速床 $vr_i$ が分かったこれは流れ星 $i$ が時刻 $t$ ($t \geq 0$) で䞭心座暙 $(px_i + t vx_i, py_i + t vy_i, pz_i + t vz_i)$半埄 $r_i - t vr_i$ の球ずなる事を衚しおいる流れ星は半埄が 0 になった瞬間に自然消滅しおしたうたた2぀の流れ星が接觊した堎合はどちらの流れ星も消滅しおしたう </p> <p>あなたの仕事は効率よく参加チヌムの健闘を祈るこずができるように各流れ星が消滅するたでの時間を求めるこずである圌らの䞭には卓越した芖力の持ち䞻がいるため情報が䞎えられた $n$ 個以倖に流れ星が存圚する可胜性に぀いおは考慮しなくおも良い加えお圌らは非垞に効率よく流れ星の芳枬を行ったため芳枬にかかった時間は無芖できるほど小さいず考えお良い </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットから構成され1぀の入力に含たれるデヌタセットの数は100以䞋である 各デヌタセットの圢匏は次の通りである </p> <blockquote>$n$<br>$px_1$ $py_1$ $pz_1$ $vx_1$ $vy_1$ $vz_1$ $r_1$ $vr_1$<br>...<br>$px_n$ $py_n$ $pz_n$ $vx_n$ $vy_n$ $vz_n$ $r_n$ $vr_n$</blockquote> <p>$n$ は流れ星の数を衚す敎数であり$1$ 以䞊 $200$ 以䞋ず仮定しお良い </p> <p>続く $n$ 行には流れ星の情報が䞎えられる 各行は小数点以䞋4桁で衚される8぀の倀を含み$(px_i, py_i, pz_i)$ は流れ星 $i$ の初期䜍眮を$(vx_i, vy_i, vz_i)$ は移動速床を$r_i$ は初期半埄を$vr_i$ は消滅速床をそれぞれ衚す 䞎えられる倀に぀いお$-1{,}000 \leq px_i \leq 1{,}000$$-1{,}000 \leq py_i \leq 1{,}000$$-1{,}000 \leq pz_i \leq 1{,}000$$-100 \leq vx_i \leq 100$ $-100 \leq vy_i \leq 100$ $-100 \leq vz_i \leq 100$$1 \leq r_i \leq 100$$1 \leq vr_i \leq 100$ であるず仮定しお良い </p> <p>たた䞎えられるデヌタセットに぀いお以䞋を仮定しお良い </p><ul><li> ある1぀の流れ星の初期半埄が $10^{-8}$ 倉化しおも接觊する星のペアの集合は倉わらない </li><li> ある1぀の流れ星が接觊により消滅しないず仮定しおも$10^{-8}$ 以内の時間で2぀以䞊の流れ星に接觊したり他の流れ星ず接觊する時刻から$10^{-8}$以内に自然消滅するこずはない </li><li> 初期状態ではどの2぀の流れ星も重なっおおらず$10^{-8}$以䞊の距離を空けおいる </li><li> 時刻 $t < 10^{-8}$ ではどの2぀の流れ星も接觊しない </li></ul> <p>$n = 0$ は入力の終わりを瀺すこれはデヌタセットには含めない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに぀いお各流れ星が消滅するたでの時間を流れ星1から順にそれぞれ1行に出力しなさい </p> <p>出力には$10^{-8}$を超える絶察誀差があっおはならない </p> <p>それ以倖の䜙蚈な文字を出力しおはならない </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>1 0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 4.0000 1.0000 2 0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 4.0000 1.0000 10.0000 0.0000 0.0000 -2.0000 0.0000 0.0000 4.0000 1.0000 5 -10.0000 0.0000 0.0000 10.0000 0.0000 0.0000 2.0000 1.0000 -5.0000 0.0000 0.0000 10.0000 0.0000 0.0000 2.0000 1.0000 0.0000 0.0000 0.0000 10.0000 0.0000 0.0000 2.0000 1.0000 11.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 100.0000 15.0000 0.0000 0.0000 -10.0000 0.0000 0.0000 2.0000 1.0000 27 -45.6243 -40.4815 42.0513 -0.8380 -6.3628 4.5484 12.0279 2.2721 8.7056 -9.8256 34.1560 6.0068 6.2527 -6.8506 28.9807 1.5037 30.1481 29.9591 -46.2881 6.7611 8.6669 1.5629 14.5578 1.3181 24.2927 8.3779 -21.8931 0.7074 0.1879 -8.9742 5.5877 2.6893 25.3009 -42.9168 10.7480 -7.2477 -8.5507 7.7846 13.7923 2.8726 17.6938 42.3577 -5.0334 6.4949 -2.1472 -5.3101 23.3066 1.4769 -7.9296 -29.6442 -24.2157 -1.1064 -9.5802 6.5858 12.4250 2.3816 9.5851 -20.0455 -35.1885 5.7477 -1.0622 2.5211 3.5233 1.2466 -35.5762 44.5412 -46.7816 3.6053 0.4991 4.3470 20.6922 2.8529 -44.9386 -48.0381 -43.6877 7.4101 3.9491 7.1619 10.4301 2.4920 -49.9870 -28.6276 -2.6522 5.8008 -1.0054 -4.9061 25.1188 1.4916 45.0228 31.3811 29.2546 -8.7777 -3.7836 -7.7180 17.4361 1.8706 35.5553 45.8774 -29.8025 -7.3596 -9.2114 -3.5987 6.8841 2.6143 19.9857 34.3874 42.5551 5.2133 -5.5350 -7.6617 2.9294 1.4026 23.5109 18.1633 -34.8265 7.3260 -4.1912 5.3518 3.0036 1.5027 43.5134 -27.5238 49.4679 -4.5986 1.8410 6.8741 2.2009 1.4525 -28.8994 23.2934 -6.1914 5.7985 -6.2129 -8.2882 16.1683 1.7463 3.6721 38.2528 -38.7741 4.5115 6.6442 6.4406 10.7555 1.0971 17.4488 -12.6965 -23.1293 2.8257 6.3319 -1.5368 7.3785 2.9350 33.2708 -17.9437 -0.5347 8.7428 7.3193 5.9738 6.2292 2.6210 -14.4660 -25.1449 -4.4191 -9.4843 -6.6439 -4.7330 7.7910 2.1659 32.4428 -24.2605 48.1228 -5.2396 1.5916 -5.9552 1.1760 1.3618 -21.9088 43.6286 -8.8286 6.4641 0.5554 -4.6827 1.2504 1.4718 -0.1784 -42.1729 -2.7193 5.3741 0.9098 9.7622 1.4764 1.2611 29.3245 -33.2298 -26.3824 -8.4192 -2.9427 -7.3759 9.6346 1.7490 -35.1767 35.9652 33.4779 4.0088 2.4579 2.0981 19.2565 1.7121 -17.5530 1.4161 -14.0271 6.4564 -4.8261 -8.7461 3.0566 1.5906 0</pre> <h3>Output for Sample Input</h3> <pre>4.0000000000 1.0000000000 1.0000000000 2.0000000000 2.0000000000 0.6111111111 0.0100000000 0.6111111111 5.2937370714 0.3931996496 11.0445337986 2.0777525750 4.8013298058 0.0925901184 5.2170809540 2.8263276111 7.2530407655 4.1854333868 0.2348376111 1.0517364512 0.0925901184 1.0517364512 1.9988021561 1.5152495697 9.2586039054 9.8035730562 2.5139693356 2.3766501335 0.2348376111 0.3931996496 0.8495719527 1.1707239711 5.5086335049 11.2472986391 1.9216647806</pre>
p00820
<H1><font color="#000">Problem B:</font> Lagrange's Four-Square Theorem</H1> <p> The fact that any positive integer has a representation as the sum of at most four positive squares (i.e. squares of positive integers) is known as Lagrange’s Four-Square Theorem. The first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission however is not to explain the original proof nor to discover a new proof but to show that the theorem holds for some specific numbers by counting how many such possible representations there are. </p> <p> For a given positive integer n, you should report the number of all representations of n as the sum of at most four positive squares. The order of addition does not matter, e.g. you should consider 4<sup>2</sup> + 3<sup>2</sup> and 3<sup>2</sup> + 4<sup>2</sup> are the same representation. </p> <p> For example, let’s check the case of 25. This integer has just three representations 1<sup>2</sup> +2<sup>2</sup> +2<sup>2</sup> +4<sup>2</sup> , 3<sup>2</sup> + 4<sup>2</sup> , and 5<sup>2</sup> . Thus you should report 3 in this case. Be careful not to count 4<sup>2</sup> + 3<sup>2</sup> and 3<sup>2</sup> + 4<sup>2</sup> separately. </p> <H2>Input</H2> <p> The input is composed of at most 255 lines, each containing a single positive integer less than 2<sup>15</sup> , followed by a line containing a single zero. The last line is not a part of the input data. </p> <H2>Output</H2> <p> The output should be composed of lines, each containing a single integer. No other characters should appear in the output. </p> <p> The output integer corresponding to the input integer <i>n</i> is the number of all representations of <i>n</i> as the sum of at most four positive squares. </p> <H2>Sample Input</H2> <pre> 1 25 2003 211 20007 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 3 48 7 738 </pre>
p01732
<p> Nathan O. Davis is running a company. His company owns a web service which has a lot of users. So his office is full of servers, routers and messy LAN cables. </p> <p>He is now very puzzling over the messy cables, because they are causing many kinds of problems. For example, staff working at the company often trip over a cable. No damage if the cable is disconnected. It's just lucky. Computers may fall down and get broken if the cable is connected. He is about to introduce a new computer and a new cable. He wants to minimize staff's steps over the new cable. </p> <p> His office is laid-out in a two-dimensional grid with <var>H \times W</var> cells. The new cable should weave along edges of the cells. Each end of the cable is at a corner of a cell. The grid is expressed in zero-origin coordinates, where the upper left corner is (0, 0). </p> <p> Each staff starts his/her work from inside a certain cell and walks in the office along the grid in a fixed repeated pattern every day. A walking pattern is described by a string of four characters <code>U</code>, <code>D</code>, <code>L</code> and <code>R</code>. <code>U</code> means moving up, <code>D</code> means moving down, <code>R</code> means moving to the right, and <code>L</code> means moving to the left. For example, <code>UULLDDRR</code> means moving up, up, left, left, down, down, right and right in order. The staff repeats the pattern fixed <var>T</var> times. Note that the staff stays in the cell if the staff is going out of the grid through the wall. </p> <p> You have the moving patterns of all staff and the positions of both ends of the new cable. Your job is to find an optimal placement of the new cable, which minimizes the total number his staff would step over the cable. </p> <h3>Input</h3> <p>The first line of the input contains three integers which represent the dimension of the office <var>W</var>, <var>H</var> (<var>1 \leq W, H \leq 500</var>), and the number of staff <var>N</var> (<var>1 \leq N \leq 1000</var>), respectively. The next line contains two <var>x-y</var> pairs (<var>0 \leq x \leq W</var>, <var>0 \leq y \leq H</var>), which mean the position of two endpoints of a LAN cable to be connected. These values represents the coordinates of the cells to which the cable is plugged in its top-left corner. Exceptionally, <var>x = W</var> means the right edge of the rightmost cell, and <var>y = H</var> means the bottom edge of the bottommost cell. </p> <p>Following lines describe staff's initial positions and their moving patterns. The first line includes an <var>x</var>-<var>y</var> pair (<var>0 \leq x \lt W</var>, <var>0 \leq y \lt H</var>), which represents the coordinate of a staff's initial cell. The next line has an integer <var>T</var> (<var>1 \leq T \leq 100</var>) and a string which consists of <code>U</code>, <code>D</code>, <code>L</code> and <code>R</code>, whose meaning is described as above. The length of a pattern string is greater than or equal to <var>1</var>, and no more than <var>1,000</var>. These two lines are repeated <var>N</var> times. </p> <h3>Output</h3> <p>Output the minimum number of times his staff step over the cable in a single line. </p> <h3>Sample Input 1</h3> <pre>3 3 1 1 1 3 3 0 0 1 RRDDLLUU </pre> <h3>Output for the Sample Input 1</h3> <pre>1 </pre> <h3>Sample Input 2</h3> <pre>3 3 1 0 0 3 3 0 0 1 RRDDLLUU </pre> <h3>Output for the Sample Input 2</h3> <pre>0 </pre> <h3>Sample Input 3</h3> <pre>3 3 1 1 1 3 3 0 0 10 RRDDLLUU </pre> <h3>Output for the Sample Input 3</h3> <pre>10 </pre> <h3>Sample Input 4</h3> <pre>3 3 4 1 1 3 3 0 0 10 R 2 0 10 D 2 2 10 L 0 2 10 U </pre> <h3>Output for the Sample Input 4</h3> <pre>1 </pre>
p00573
<h1>定期刞(Commuter Pass)</h1> <p> JOI 君が䜏む郜垂には<var>N</var> 個の駅がありそれぞれ<var>1, 2, ..., N</var> の番号が付けられおいるたた<var>M</var> 本の鉄道路線がありそれぞれ<var>1, 2, ..., M</var> の番号が付けられおいる鉄道路線<var>i</var> (<var>1 \leq i \leq M</var>) は駅<var>A_i</var> ず駅<var>B_i</var> を双方向に結んでおり乗車運賃は<var>C_i</var> 円である </p> <p> JOI 君は駅S の近くに䜏んでおり駅<var>T</var> の近くのIOI 高校に通っおいるそのため䞡者を結ぶ定期刞を賌入するこずにした定期刞を賌入する際には駅<var>S</var> ず駅<var>T</var> の間を最小の運賃で移動する経路を䞀぀指定しなければならないこの定期刞を甚いるず指定した経路に含たれる鉄道路線は双方向に自由に乗り降りできる </p> <p> JOI 君は駅<var>U</var> および駅<var>V</var> の近くにある曞店もよく利甚しおいるそこで駅<var>U</var> から駅<var>V</var> ぞの移動にかかる運賃ができるだけ小さくなるように定期刞を賌入したいず考えた </p> <p> 駅<var>U</var> から駅<var>V</var> ぞの移動の際はたず駅<var>U</var> から駅<var>V</var> ぞの経路を1 ぀遞ぶこの経路に含たれる鉄道路線<var>i</var> においお支払うべき運賃は </p> <ul> <li> 鉄道路線<var>i</var> が定期刞を賌入する際に指定した経路に含たれる堎合0 円</li> <li> 鉄道路線<var>i</var> が定期刞を賌入する際に指定した経路に含たれない堎合<var>C_i</var> 円</li> </ul> <p> ずなるこの運賃の合蚈が駅<var>U</var> から駅<var>V</var> ぞの移動にかかる運賃である </p> <p> 定期刞を賌入する際に指定する経路をうたく遞んだずきの駅<var>U</var> から駅<var>V</var> ぞの移動にかかる運賃の最小倀を求めたい </p> <h3>課題</h3> <p> 定期刞を賌入する際に指定する経路をうたく遞んだずきの駅<var>U</var> から駅<var>V</var> ぞの移動にかかる運賃の最小倀を求めるプログラムを䜜成せよ </p> <h3>入力</h3> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には2 個の敎数<var>N, M</var> が曞かれおいるこれらはJOI 君が䜏む郜垂に<var>N</var> 個の駅ず<var>M</var> 本の鉄道路線があるこずを衚す</li> <li> 2 行目には2 個の敎数<var>S, T</var> が曞かれおいるこれらはJOI 君が駅<var>S</var> から駅<var>T</var> ぞの定期刞を賌入するこずを衚す</li> <li> 3 行目には2 個の敎数<var>U, V</var> が曞かれおいるこれらはJOI 君が駅<var>U</var> から駅<var>V</var> ぞの移動にかかる運賃を最小化したいこずを衚す</li> <li> 続く<var>M</var> 行のうちの<var>i</var> 行目(<var>1 \leq i \leq M</var>) には3 個の敎数<var>A_i, B_i,C_i</var> が曞かれおいるこれらは鉄道路線<var>i</var> が駅<var>A_i</var> ず駅<var>B_i</var> を双方向に結びその運賃が<var>C_i</var> 円であるこずを衚す</li> </ul> <h3>出力</h3> <p> 暙準出力に定期刞を賌入する際に駅<var>S</var> から駅<var>T</var> ぞの経路をうたく指定したずきの駅<var>U</var> から駅<var>V</var> ぞの移動にかかる運賃の最小倀を1 行で出力せよ </p> <h3>制限</h3> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li><var> 2 \leq N \leq 100 000 </var></li> <li><var> 1 \leq M \leq 200 000</var></li> <li><var> 1 \leq S \leq N</var></li> <li><var> 1 \leq T \leq N</var></li> <li><var> 1 \leq U \leq N</var></li> <li><var> 1 \leq V \leq N</var></li> <li><var> S &ne; T</var></li> <li><var> U &ne; V</var></li> <li><var> S &ne; U</var> たたは<var>T &ne; V</var></li> <li> どの駅から他のどの駅ぞも1 本以䞊の鉄道路線を甚いお到達できる</li> <li><var> 1 \leq A_i < B_i \leq N (1 \leq i l\leq M)</var></li> <li><var> 1 \leq i < j \leq M</var> に察し<var>A_i &ne; A_j</var> たたは<var>B_i &ne; B_j</var></li> <li><var> 1 \leq C_i \leq 1 000 000 000 (1 \leq i \leq M)</var></li> </ul> <!-- 小課題 小課題1 [16 点] S = U を満たす 小課題2 [15 点] 駅S から駅T ぞ最小の運賃で移動するずきに甚いるこずができる経路は1 通りしかない 小課題3 [24 点] N ≩ 300 を満たす 小課題4 [45 点] 远加の制限はない --> <h3>入出力䟋</h3> <h3>入力䟋1</h3> <pre> 6 6 1 6 1 4 1 2 1 2 3 1 3 5 1 2 4 3 4 5 2 5 6 1 </pre> <h3>出力䟋1</h3> <pre> 2 </pre> <p> この入力䟋では定期刞を買う際に指定できる経路は駅1 &rarr; 駅2 &rarr; 駅3 &rarr; 駅5 &rarr; 駅6 ずいう経路に限られる </p> <p> 駅1 から駅4 ぞの移動にかかる運賃を最小化するには駅1 &rarr; 駅2 &rarr; 駅3 &rarr; 駅5 &rarr; 駅4 ずいう経路を遞べばよいこの経路を遞んだ堎合各鉄道路線においお支払うべき運賃は </p> <ul> <li> 駅4 ず駅5 を結ぶ鉄道路線5 においおは2 円</li> <li> それ以倖の鉄道路線においおは0 円</li> </ul> <p> ずなるのでかかる運賃の合蚈は2 円ずなる </p> <h3>入力䟋2 </h3> <pre> 6 5 1 2 3 6 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 5 6 1000000000 </pre> <h3>出力䟋2</h3> <pre> 3000000000 </pre> <p> この入力䟋では駅3 から駅6 ぞの移動に定期刞を甚いない </p> <h3>入力䟋3</h3> <pre> 8 8 5 7 6 8 1 2 2 2 3 3 3 4 4 1 4 1 1 5 5 2 6 6 3 7 7 4 8 8 </pre> <h3>出力䟋3</h3> <pre> 15 </pre> <h3>入力䟋4</h3> <pre> 5 5 1 5 2 3 1 2 1 2 3 10 2 4 10 3 5 10 4 5 10 </pre> <h3> 出力䟋4</h3> <pre> 0 </pre> <h3>入力䟋5</h3> <pre> 10 15 6 8 7 9 2 7 12 8 10 17 1 3 1 3 8 14 5 7 15 2 3 7 1 10 14 3 6 12 1 5 10 8 9 1 2 9 7 1 4 1 1 8 1 2 4 7 5 6 16 </pre> <h3>出力䟋5</h3> <pre> 19 </pre> <br/> <p> <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> <br/> <a href="https://www.ioi-jp.org/joi/2017/2018-ho/index.html">情報オリンピック日本委員䌚䜜 『第17 回日本情報オリンピック(JOI 2017/2018) 本遞』</a> </p>
p00089
<H1>最短経路</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_17_1"> </center> <br/> <p> 図に䟋瀺するように敎数0 以䞊 99 以䞋をひしがたに䞊べたす。このような、ひしがたを衚すデヌタを読み蟌んで、䞀番䞊からスタヌトしお䞀番䞋たで次のルヌルに埓っお進むずき、通過する敎数の和の最倧倀を出力するプログラムを䜜成しおください。 </p> <ul> <li>各ステップで、察角線䞊の巊䞋か察角線䞊の右䞋に進むこずができたす。</li> </ul> <p> 䟋えば図1の䟋では、図2に瀺すように、7,3,8,7,5,7,8,3,7を遞んで通ったずき、その和は最倧の 55 7+3+8+7+5+7+8+3+7=55 ずなりたす。 </p> <H2>Input</H2> <p> 入力䟋に瀺すように、カンマで区切られた敎数の䞊びが、ひし圢状に䞎えられたす。各行に空癜文字は含たれたせん。入力䟋は図に察応しおいたす。 デヌタの行数は 100 行未満です。 </p> <H2>Output</H2> <p> ルヌルに埓っお通過する敎数の和の最倧倀を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 7 3,8 8,1,0 2,7,4,4 4,5,2,6,5 2,7,4,4 8,1,0 3,8 7 </pre> <H2>Sample Output</H2> <pre> 55 </pre>
p00123
<h1>スピヌドスケヌトバッゞテスト</h1> <p> スピヌドスケヌトバッゞテストでは、2 皮類の距離で芏定されたタむムを䞊回った堎合に玚が認定されたす。䟋えば A 玚になるには 500 M で 40.0 秒未満、か぀ 1000 M で 1 分 23 秒未満であるこずが求められたす。 </p> <p> スピヌドスケヌト倧䌚 (500 M ず 1000 M) で蚘録したタむムを入力ずし、スピヌドスケヌトバッゞテストで䜕玚に盞圓するかを出力するプログラムを䜜成しお䞋さい。500 M ず1000 M のバッゞテスト芏定タむムは䞋衚のずおりです。 E 玚に満たなかった堎合には、NA ず出力しおください。 </p> <center> <table> <tr><th width="100"></th><th width="120"> 500 M</th><th width="120">1000 M</th></tr> <tr><td>AAA 箚</td><td> 35 秒 50</td><td> 1 分 11 秒 00</td></tr> <tr><td> AA 箚 </td><td> 37 秒 50</td><td> 1 分 17 秒 00</td></tr> <tr><td> A 箚 </td><td> 40 秒 00</td><td> 1 分 23 秒 00</td></tr> <tr><td> B 箚 </td><td> 43 秒 00</td><td> 1 分 29 秒 00</td></tr> <tr><td> C 箚 </td><td> 50 秒 00</td><td> 1 分 45 秒 00</td></tr> <tr><td> D 箚 </td><td> 55 秒 00</td><td> 1 分 56 秒 00</td></tr> <tr><td> E 箚 </td><td>1分10 秒 00 </td><td>2 分 28 秒 00</td></tr> </table> </center> <br/> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットずしお、500 M タむムず 1000 M タむムをそれぞれ衚す実数 <var>t<sub>1</sub></var>, <var>t<sub>2</sub></var> (8.0 &le; <var>t<sub>1</sub></var>, <var>t<sub>2</sub></var> &le; 360.0) が空癜区切りで䞎えられたす。<var>t<sub>1</sub></var>, <var>t<sub>2</sub></var> は秒単䜍で小数点以䞋最倧 2 桁たでの数字を含む実数で䞎えられたす。 <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットごずに、刀定結果 AAA ~ E たたは NA を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 40.0 70.0 72.5 140.51 </pre> <H2>Output for the Sample Input</H2> <pre> B NA </pre>
p03426
<span class="lang-en"> <p>Score : <var>400</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. The square at the <var>i</var>-th row and the <var>j</var>-th column will be called Square <var>(i,j)</var>.</p> <p>The integers from <var>1</var> through <var>H×W</var> are written throughout the grid, and the integer written in Square <var>(i,j)</var> is <var>A_{i,j}</var>.</p> <p>You, a magical girl, can teleport a piece placed on Square <var>(i,j)</var> to Square <var>(x,y)</var> by consuming <var>|x-i|+|y-j|</var> magic points.</p> <p>You now have to take <var>Q</var> practical tests of your ability as a magical girl.</p> <p>The <var>i</var>-th test will be conducted as follows:</p> <ul> <li> <p>Initially, a piece is placed on the square where the integer <var>L_i</var> is written.</p> </li> <li> <p>Let <var>x</var> be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer <var>x+D</var> is written, as long as <var>x</var> is not <var>R_i</var>. The test ends when <var>x=R_i</var>.</p> </li> <li> <p>Here, it is guaranteed that <var>R_i-L_i</var> is a multiple of <var>D</var>.</p> </li> </ul> <p>For each test, find the sum of magic points consumed during that test.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H,W \leq 300</var></li> <li><var>1 \leq D \leq H×W</var></li> <li><var>1 \leq A_{i,j} \leq H×W</var></li> <li><var>A_{i,j} \neq A_{x,y} ((i,j) \neq (x,y))</var></li> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>1 \leq L_i \leq R_i \leq H×W</var></li> <li><var>(R_i-L_i)</var> is a multiple of <var>D</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>H</var> <var>W</var> <var>D</var> <var>A_{1,1}</var> <var>A_{1,2}</var> <var>...</var> <var>A_{1,W}</var> <var>:</var> <var>A_{H,1}</var> <var>A_{H,2}</var> <var>...</var> <var>A_{H,W}</var> <var>Q</var> <var>L_1</var> <var>R_1</var> <var>:</var> <var>L_Q</var> <var>R_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each test, print the sum of magic points consumed during that test.</p> <p>Output should be in the order the tests are conducted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 2 1 4 3 2 5 7 8 9 6 1 4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <ul> <li> <p><var>4</var> is written in Square <var>(1,2)</var>.</p> </li> <li> <p><var>6</var> is written in Square <var>(3,3)</var>.</p> </li> <li> <p><var>8</var> is written in Square <var>(3,1)</var>.</p> </li> </ul> <p>Thus, the sum of magic points consumed during the first test is <var>(|3-1|+|3-2|)+(|3-3|+|1-3|)=5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 3 3 7 1 4 5 2 6 8 2 2 2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 0 </pre> <p>Note that there may be a test where the piece is not moved at all, and there may be multiple identical tests.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 5 4 13 25 7 15 17 16 22 20 2 9 14 11 12 1 19 10 6 23 8 18 3 21 5 24 4 3 13 13 2 10 13 13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 5 0 </pre></section> </div> </span>
p03076
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>The restaurant AtCoder serves the following five dishes:</p> <ul> <li>ABC Don (rice bowl): takes <var>A</var> minutes to serve.</li> <li>ARC Curry: takes <var>B</var> minutes to serve.</li> <li>AGC Pasta: takes <var>C</var> minutes to serve.</li> <li>APC Ramen: takes <var>D</var> minutes to serve.</li> <li>ATC Hanbagu (hamburger patty): takes <var>E</var> minutes to serve.</li> </ul> <p>Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered.</p> <p>This restaurant has the following rules on orders:</p> <ul> <li>An order can only be placed at a time that is a multiple of <var>10</var> (time <var>0</var>, <var>10</var>, <var>20</var>, <var>...</var>).</li> <li>Only one dish can be ordered at a time.</li> <li>No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered.</li> </ul> <p>E869120 arrives at this restaurant at time <var>0</var>. He will order all five dishes. Find the earliest possible time for the last dish to be delivered.<br/> Here, he can order the dishes in any order he likes, and he can place an order already at time <var>0</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>A, B, C, D</var> and <var>E</var> are integers between <var>1</var> and <var>123</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>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the earliest possible time for the last dish to be delivered, as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>29 20 7 35 120 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>215 </pre> <p>If we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta, ATC Hanbagu, APC Ramen, the earliest possible time for each order is as follows:</p> <ul> <li>Order ABC Don at time <var>0</var>, which will be delivered at time <var>29</var>.</li> <li>Order ARC Curry at time <var>30</var>, which will be delivered at time <var>50</var>.</li> <li>Order AGC Pasta at time <var>50</var>, which will be delivered at time <var>57</var>.</li> <li>Order ATC Hanbagu at time <var>60</var>, which will be delivered at time <var>180</var>.</li> <li>Order APC Ramen at time <var>180</var>, which will be delivered at time <var>215</var>.</li> </ul> <p>There is no way to order the dishes in which the last dish will be delivered earlier than this.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>101 86 119 108 57 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>481 </pre> <p>If we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC Hanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as follows:</p> <ul> <li>Order AGC Pasta at time <var>0</var>, which will be delivered at time <var>119</var>.</li> <li>Order ARC Curry at time <var>120</var>, which will be delivered at time <var>206</var>.</li> <li>Order ATC Hanbagu at time <var>210</var>, which will be delivered at time <var>267</var>.</li> <li>Order APC Ramen at time <var>270</var>, which will be delivered at time <var>378</var>.</li> <li>Order ABC Don at time <var>380</var>, which will be delivered at time <var>481</var>.</li> </ul> <p>There is no way to order the dishes in which the last dish will be delivered earlier than this.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>123 123 123 123 123 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>643 </pre> <p>This is the largest valid case.</p></section> </div> </span>
p02237
<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> <H1>Graph</H1> <p> There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. </p> <p> An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, the adjacency list $Adj[u]$ contains all vertices $v$ such that there is an edge $(u, v) \in E$. That is, $Adj[u]$ consists of all vertices adjacent to $u$ in $G$. </p> <p> An adjacency-matrix representation consists of $|V| \times |V|$ matrix $A = a_{ij}$ such that $a_{ij} = 1$ if $(i, j) \in E$, $a_{ij} = 0$ otherwise. </p> <p> Write a program which reads a directed graph $G$ represented by the adjacency list, and prints its adjacency-matrix representation. $G$ consists of $n\; (=|V|)$ vertices identified by their IDs $1, 2,.., n$ respectively. </p> <H2>Input</H2> <p> In the first line, an integer $n$ is given. In the next $n$ lines, an adjacency list $Adj[u]$ for vertex $u$ are given in the following format: </p> <p> $u$ $k$ $v_1$ $v_2$ ... $v_k$ </p> <p> $u$ is vertex ID and $k$ denotes its degree. $v_i$ are IDs of vertices adjacent to $u$. </p> <H2>Output</H2> <p> As shown in the following sample output, print the adjacent-matrix representation of $G$. Put a single space character between $a_{ij}$. </p> <H2>Constraints</H2> <ul> <li>$1 \leq n \leq 100$</li> </ul> <H2>Sample Input</H2> <pre> 4 1 2 2 4 2 1 4 3 0 4 1 3 </pre> <H2>Sample Output</H2> <pre> 0 1 0 1 0 0 0 1 0 0 0 0 0 0 1 0 </pre>
p02667
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has an empty string <var>S</var> and a variable <var>x</var> whose initial value is <var>0</var>.</p> <p>Also, we have a string <var>T</var> consisting of <code>0</code> and <code>1</code>.</p> <p>Now, Takahashi will do the operation with the following two steps <var>|T|</var> times.</p> <ul> <li>Insert a <code>0</code> or a <code>1</code> at any position of <var>S</var> of his choice.</li> <li>Then, increment <var>x</var> by the sum of the digits in the odd positions (first, third, fifth, ...) of <var>S</var>. For example, if <var>S</var> is <code>01101</code>, the digits in the odd positions are <code>0</code>, <code>1</code>, <code>1</code> from left to right, so <var>x</var> is incremented by <var>2</var>.</li> </ul> <p>Print the maximum possible final value of <var>x</var> in a sequence of operations such that <var>S</var> equals <var>T</var> in the end.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |T| \leq 2 \times 10^5</var></li> <li><var>T</var> consists of <code>0</code> and <code>1</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>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible final value of <var>x</var> in a sequence of operations such that <var>S</var> equals <var>T</var> in the end.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1101 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>Below is one sequence of operations that maximizes the final value of <var>x</var> to <var>5</var>.</p> <ul> <li>Insert a <code>1</code> at the beginning of <var>S</var>. <var>S</var> becomes <code>1</code>, and <var>x</var> is incremented by <var>1</var>.</li> <li>Insert a <code>0</code> to the immediate right of the first character of <var>S</var>. <var>S</var> becomes <code>10</code>, and <var>x</var> is incremented by <var>1</var>.</li> <li>Insert a <code>1</code> to the immediate right of the second character of <var>S</var>. <var>S</var> becomes <code>101</code>, and <var>x</var> is incremented by <var>2</var>.</li> <li>Insert a <code>1</code> at the beginning of <var>S</var>. <var>S</var> becomes <code>1101</code>, and <var>x</var> is incremented by <var>1</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0111101101 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>26 </pre></section> </div> </span>
p03975
<span class="lang-en"> <p>Score : <var>66</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p> Summer vacation ended at last and the second semester has begun. You, a Kyoto University student, came to university and heard a rumor that somebody will barricade the entrance of your classroom. The barricade will be built just before the start of the <var>A</var>-th class and removed by Kyoto University students just before the start of the <var>B</var>-th class. All the classes conducted when the barricade is blocking the entrance will be cancelled and you will not be able to attend them. Today you take <var>N</var> classes and class <var>i</var> is conducted in the <var>t_i</var>-th period. You take at most one class in each period. Find the number of classes you can attend. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>1 \leq A &lt; B \leq 10^9 </var></li> <li><var>1 \leq t_i \leq 10^9</var></li> <li>All <var>t_i</var> values are distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p><var>N</var>, <var>A</var> and <var>B</var> are given on the first line and <var>t_i</var> is given on the <var>(i+1)</var>-th line. </p> <pre> <var>N</var> <var>A</var> <var>B</var> <var>t<sub>1</sub></var> : <var>t<sub>N</sub></var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of classes you can attend. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 5 5 9 4 3 6 9 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 4 </pre> <p>You can not only attend the third class. </p> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 5 4 9 5 6 7 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 1 </pre> <p>You can only attend the fifth class. </p> </section> </div> <div class="part"> <section> <h3>Sample Input 3</h3> <pre> 4 3 6 9 6 8 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3> <pre> 4 </pre> <p>You can attend all the classes. </p> </section> </div> <div class="part"> <section> <h3>Sample Input 4</h3> <pre> 2 1 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3> <pre> 1 </pre> <p>You can not attend the first class, but can attend the second. </p> </section> </div> </span>
p01948
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <H1> Janken Master </H1> <p> You are supposed to play the rock-paper-scissors game. There are $N$ players including you. </p> <p> This game consists of multiple rounds. While the rounds go, the number of remaining players decreases. In each round, each remaining player will select an arbitrary shape independently. People who show rocks win if all of the other people show scissors. In this same manner, papers win rocks, scissors win papers. There is no draw situation due to the special rule of this game: if a round is tied based on the normal rock-paper-scissors game rule, the player who has the highest programming contest rating (this is nothing to do with the round!) will be the only winner of the round. Thus, some players win and the other players lose on each round. The losers drop out of the game and the winners proceed to a new round. They repeat it until only one player becomes the winner. </p> <p> Each player is numbered from $1$ to $N$. Your number is $1$. You know which shape the other $N-1$ players tend to show, that is to say, you know the probabilities each player shows rock, paper and scissors. The $i$-th player shows rock with $r_i\%$ probability, paper with $p_i\%$ probability, and scissors with $s_i\%$ probability. The rating of programming contest of the player numbered $i$ is $a_i$. There are no two players whose ratings are the same. Your task is to calculate your probability to win the game when you take an optimal strategy based on each player's tendency and rating. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $N$ $a_1$ $a_2$ $r_2$ $p_2$ $s_2$ ... $a_N$ $r_N$ $p_N$ $s_N$ </pre> <p> The first line consists of a single integer $N$ ($2 \leq N \leq 14$). The second line consists of a single integer $a_i$ ($1 \leq a_i \leq N$). The ($i+1$)-th line consists of four integers $a_i, r_i, p_i$ and $s_i$ ($1 \leq a_i \leq N, 0 \leq r_i, p_i, s_i \leq 100,$ $r_i + p_i + s_i = 100$) for $i=2, ..., N$. It is guaranteed that $a_1, ..., a_N$ are pairwise distinct. </p> <H2>Output</H2> <p> Print the probability to win the game in one line. Your answer will be accepted if its absolute or relative error does not exceed $10^{-6}$. </p> <H2>Sample Input 1</H2> <pre> 2 2 1 40 40 20 </pre> <H2>Output for Sample Input 1</H2> <pre> 0.8 </pre> <p> Since you have the higher rating than the other player, you will win the game if you win or draw in the first round. </p> <H2>Sample Input 2</H2> <pre> 2 1 2 50 50 0 </pre> <H2>Output for Sample Input 2</H2> <pre> 0.5 </pre> <p> You must win in the first round. </p> <H2>Sample Input 3</H2> <pre> 3 2 1 50 0 50 3 0 0 100 </pre> <H2>Output for Sample Input 3</H2> <pre> 1 </pre> <p> In the first round, your best strategy is to show a rock. You will win the game with $50\%$ in this round. With the other $50\%$, you and the second player proceed to the second round and you must show a rock to win the game. </p> <H2>Sample Input 4</H2> <pre> 3 2 3 40 40 20 1 30 10 60 </pre> <H2>Output for Sample Input 4</H2> <pre> 0.27 </pre> <H2>Sample Input 5</H2> <pre> 4 4 1 34 33 33 2 33 34 33 3 33 33 34 </pre> <H2>Output for Sample Input 5</H2> <pre> 0.6591870816 </pre>
p02688
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>N</var> <em>Snukes</em> called Snuke <var>1</var>, Snuke <var>2</var>, ..., Snuke <var>N</var> live in a town.</p> <p>There are <var>K</var> kinds of snacks sold in this town, called Snack <var>1</var>, Snack <var>2</var>, ..., Snack <var>K</var>. The following <var>d_i</var> Snukes have Snack <var>i</var>: Snuke <var>A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}</var>.</p> <p>Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?</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 K \leq 100</var></li> <li><var>1 \leq d_i \leq N</var></li> <li><var>1 \leq A_{i, 1} &lt; \cdots &lt; A_{i, d_i} \leq N</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> <var>d_1</var> <var>A_{1, 1} \cdots A_{1, d_1}</var> <var>\vdots</var> <var>d_K</var> <var>A_{K, 1} \cdots A_{K, d_K}</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 2 2 1 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <ul> <li>Snuke <var>1</var> has Snack <var>1</var>.</li> <li>Snuke <var>2</var> has no snacks.</li> <li>Snuke <var>3</var> has Snack <var>1</var> and <var>2</var>.</li> </ul> <p>Thus, there will be one victim: Snuke <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 3 1 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre></section> </div> </span>
p02372
<H1>Height of a Tree</H1> <br/> <p> Given a tree <var>T</var> with non-negative weight, find the height of each node of the tree. For each node, the height is the distance to the most distant leaf from the node. </p> <H2>Input</H2> <pre> <var>n</var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>1</sub></var> <var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>w<sub>2</sub></var> : <var>s<sub>n-1</sub></var> <var>t<sub>n-1</sub></var> <var>w<sub>n-1</sub></var> </pre> <p> The first line consists of an integer <var>n</var> which represents the number of nodes in the tree. Every node has a unique ID from 0 to <var>n</var>-1 respectively. </p> <p> In the following <var>n</var>-1 lines, edges of the tree are given. <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent end-points of the <var>i</var>-th edge (undirected) and <var>w<sub>i</sub></var> represents the weight (distance) of the <var>i</var>-th edge. </p> <H2>Output</H2> <p> The output consists of <var>n</var> lines. Print the height of each node 0, 1, 2, ..., <var>n-1</var> in order. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>n</var> &le; 10,000</li> <li> 0 &le; <var>w<sub>i</sub></var> &le; 1,000</li> </ul> <H2>Sample Input 1</H2> <pre> 4 0 1 2 1 2 1 1 3 3 </pre> <H2>Sample Output 1</H2> <pre> 5 3 4 5 </pre>
p02722
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a positive integer <var>N</var>.</p> <p>We will choose an integer <var>K</var> between <var>2</var> and <var>N</var> (inclusive), then we will repeat the operation below until <var>N</var> becomes less than <var>K</var>.</p> <ul> <li>Operation: if <var>K</var> divides <var>N</var>, replace <var>N</var> with <var>N/K</var>; otherwise, replace <var>N</var> with <var>N-K</var>.</li> </ul> <p>In how many choices of <var>K</var> will <var>N</var> become <var>1</var> in the end?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^{12}</var></li> <li><var>N</var> is an integer.</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 number of choices of <var>K</var> in which <var>N</var> becomes <var>1</var> in the end.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are three choices of <var>K</var> in which <var>N</var> becomes <var>1</var> in the end: <var>2</var>, <var>5</var>, and <var>6</var>.</p> <p>In each of these choices, <var>N</var> will change as follows:</p> <ul> <li>When <var>K=2</var>: <var>6 \to 3 \to 1</var></li> <li>When <var>K=5</var>: <var>6 \to 1</var></li> <li>When <var>K=6</var>: <var>6 \to 1</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3141 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>13 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314159265358 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9 </pre></section> </div> </span>
p03830
<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>. Find the number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀N≀10^3</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</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>4 </pre> <p>There are four divisors of <var>3!</var> <var>=6</var>: <var>1</var>, <var>2</var>, <var>3</var> and <var>6</var>. Thus, the output should be <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>30 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>972926972 </pre></section> </div> </span>
p03099
<span class="lang-en"> <p>Score : <var>1300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A museum exhibits <var>N</var> jewels, Jewel <var>1, 2, ..., N</var>. The coordinates of Jewel <var>i</var> are <var>(x_i, y_i)</var> (the museum can be regarded as a two-dimensional plane), and the value of that jewel is <var>v_i</var>.</p> <p>Snuke the thief will steal some of these jewels.</p> <p>There are <var>M</var> conditions, Condition <var>1, 2, ..., M</var>, that must be met when stealing jewels, or he will be caught by the detective. Each condition has one of the following four forms:</p> <ul> <li>(<var>t_i</var> =<code>L</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>x</var> coordinates are <var>a_i</var> or smaller.</li> <li>(<var>t_i</var> =<code>R</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>x</var> coordinates are <var>a_i</var> or larger.</li> <li>(<var>t_i</var> =<code>D</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>y</var> coordinates are <var>a_i</var> or smaller.</li> <li>(<var>t_i</var> =<code>U</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>y</var> coordinates are <var>a_i</var> or larger.</li> </ul> <p>Find the maximum sum of values of jewels that Snuke the thief can steal.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 80</var></li> <li><var>1 \leq x_i, y_i \leq 100</var></li> <li><var>1 \leq v_i \leq 10^{15}</var></li> <li><var>1 \leq M \leq 320</var></li> <li><var>t_i</var> is <code>L</code>, <code>R</code>, <code>U</code> or <code>D</code>.</li> <li><var>1 \leq a_i \leq 100</var></li> <li><var>0 \leq b_i \leq N - 1</var></li> <li><var>(x_i, y_i)</var> are pairwise distinct.</li> <li><var>(t_i, a_i)</var> are pairwise distinct.</li> <li><var>(t_i, b_i)</var> are pairwise 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>x_1</var> <var>y_1</var> <var>v_1</var> <var>x_2</var> <var>y_2</var> <var>v_2</var> <var>:</var> <var>x_N</var> <var>y_N</var> <var>v_N</var> <var>M</var> <var>t_1</var> <var>a_1</var> <var>b_1</var> <var>t_2</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>t_M</var> <var>a_M</var> <var>b_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum sum of values of jewels that Snuke the thief can steal.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 1 3 6 1 5 9 3 1 8 4 3 8 6 2 9 5 4 11 5 7 10 4 L 3 1 R 2 3 D 5 3 U 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>36 </pre> <p><img alt="Figure" src="https://img.atcoder.jp/agc031/rghe0iwfjoievjw4epdfmengow.png"/></p> <p>Stealing Jewel <var>1, 5, 6</var> and <var>7</var> results in the total value of <var>36</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 3 4 5 6 7 8 9 1 L 100 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 1 10 1 2 11 2 1 12 2 2 13 3 L 8 3 L 9 2 L 10 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>13 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 66 47 71040136000 65 77 74799603000 80 53 91192869000 24 34 24931901000 91 78 49867703000 68 71 46108236000 46 73 74799603000 56 63 93122668000 32 51 71030136000 51 26 70912345000 21 L 51 1 L 7 0 U 47 4 R 92 0 R 91 1 D 53 2 R 65 3 D 13 0 U 63 3 L 68 3 D 47 1 L 91 5 R 32 4 L 66 2 L 80 4 D 77 4 U 73 1 D 78 5 U 26 5 R 80 2 R 24 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>305223377000 </pre></section> </div> </span>
p03563
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is a user of a site that hosts programming contests.<br/> When a user competes in a contest, the <em>rating</em> of the user (not necessarily an integer) changes according to the <em>performance</em> of the user, as follows: </p> <ul> <li>Let the current rating of the user be <var>a</var>.</li> <li>Suppose that the performance of the user in the contest is <var>b</var>.</li> <li>Then, the new rating of the user will be the avarage of <var>a</var> and <var>b</var>.</li> </ul> <p>For example, if a user with rating <var>1</var> competes in a contest and gives performance <var>1000</var>, his/her new rating will be <var>500.5</var>, the average of <var>1</var> and <var>1000</var>.</p> <p>Takahashi's current rating is <var>R</var>, and he wants his rating to be exactly <var>G</var> after the next contest.<br/> Find the performance required to achieve it. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq R, G \leq 4500</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>R</var> <var>G</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the performance required to achieve the objective.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2002 2017 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2032 </pre> <p>Takahashi's current rating is <var>2002</var>.<br/> If his performance in the contest is <var>2032</var>, his rating will be the average of <var>2002</var> and <var>2032</var>, which is equal to the desired rating, <var>2017</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4500 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-4500 </pre> <p>Although the current and desired ratings are between <var>0</var> and <var>4500</var>, the performance of a user can be below <var>0</var>.</p></section> </div> </span>
p03133
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a square grid with <var>N</var> rows and <var>M</var> columns. Each square contains an integer: <var>0</var> or <var>1</var>. The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left contains <var>a_{ij}</var>.</p> <p>Among the <var>2^{N+M}</var> possible pairs of a subset <var>A</var> of the rows and a subset <var>B</var> of the columns, find the number of the pairs that satisfy the following condition, modulo <var>998244353</var>:</p> <ul> <li>The sum of the <var>|A||B|</var> numbers contained in the intersection of the rows belonging to <var>A</var> and the columns belonging to <var>B</var>, is odd.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,M \leq 300</var></li> <li><var>0 \leq a_{i,j} \leq 1(1\leq i\leq N,1\leq j\leq M)</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>M</var> <var>a_{11}</var> <var>...</var> <var>a_{1M}</var> <var>:</var> <var>a_{N1}</var> <var>...</var> <var>a_{NM}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the pairs of a subset of the rows and a subset of the columns that satisfy the condition, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 0 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>For example, if <var>A</var> consists of the first row and <var>B</var> consists of both columns, the sum of the numbers contained in the intersection is <var>0+1=1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 0 0 0 0 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre></section> </div> </span>
p01661
<h2>F - 歳教</h2> <p>歳の誕生日に"圌"は父から告げられた</p> <p>「お前が歳になったずいうこずは私はもう匕退だ今日からお前が歳教の長だ<br> 歳教の戒埋により歳教の長が歳の間だけ垃教掻動を行うこずが認められおいる<br> この宇宙船を䜿っおよりたくさんの人々に歳教の玠晎らしさを広めおきなさい」 </p> <p> 歳教をよりたくさんの人に広めるために"圌"は自分の呚りの星に぀いおの情報を集めた<br> "圌"の星の呚りには<var>n</var> 個の惑星があり惑星は <var> 1, ... , n</var> で番号付けされおいるこずがわかった<br> 惑星<var>i</var> から 惑星<var>j</var>の間を移動するには<var>w_i_j</var> (幎)の時間がかかるこずもわかった </p> <p> そしおそれぞれの星で圌が歳でいられる時間぀たり垃教掻動できる時間が異なるこずがわかった<br> それぞれの惑星䞊では宇宙暊<var>l_i</var>幎1月1日00:00:00以降<var>r_i</var>幎1月1日00:00:00より前たでの時間垯であれば7歳でいられる <br> たずえ䞀床ある星で歳以倖の幎霢になっおもその星で埌から歳になった堎合や別の星で歳になれば垃教掻動を再開するこずができる </p> <p> しかしどの星でどれくらいそしおどの順序で垃教掻動を行えばより倚くの人に歳教を䌝えるこずができるのか<br> "圌"にはわからなかったそこで"圌"はプログラミングが埗意なあなたに助けを求めるこずにした </p> <p> 珟圚は宇宙暊0幎1月1日00:00:00であり"圌"は惑星 <var>s</var> にいる 惑星間を最適に移動・滞圚した堎合に垃教掻動が行える最長の幎数<br> ぀たり"圌"が歳でか぀惑星で過ごす最長の幎数<var>T</var>を求めおあげよう ただし幎数<var>T</var>には移動時間は含たれない </p> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる <pre> <var>n</var> <var>s</var> <var>l_1</var> <var>r_1</var> <var> ... </var> <var>l_{n}</var> <var>r_{n}</var> <var>w_{1,1} </var> <var>w_{1,2}</var> <var>...</var> <var>w_{1,n}</var> <var> ... </var> <var>w_{n,1}</var> <var>w_{n,2}</var> <var>...</var> <var>w_{n,n}</var> </pre> <p> <var>n</var> は惑星の個数である<var>s</var> は䞻人公が最初にいる惑星をあらわす<br> <var>l_i</var> ず <var>r_i</var> はそれぞれ惑星<var>i</var> での7歳でいられる時間垯の䞋限ず䞊限をあらわす</br> <var>w_i_j</var> は惑星<var>i</var>から惑星<var>j</var>を移動するのにかかる時間をあらわす<br> 入力はすべお敎数である </p> <h2>出力圢匏</h2> <p> 答え<var>T</var>を出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; n &le; 500</var></li> <li><var>1 &le; s &le; n</var></li> <li><var>0 &le; l_i &lt; r_i &le; 10^8</var></li> <li><var>0 &le; w_{ij} &le; 10^8</var> (<var>i</var> ≠<var>j</var>)</li> <li><var>w_{ij} = 0 </var> (<var>i</var> = <var>j</var>)</li> </ul> <!-- <p>この問題の刀定には50 点分のテストケヌスのグルヌプが蚭定されおいるこのグルヌプに含たれるテストケヌスは䞊蚘の制玄に加えお䞋蚘の制玄も満たす</p> <ul> <li>すべおの <var>i, j </var> に察しお <var>w_{ij} = 0 </var></li> </ul> --> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 2 1 0 100 150 250 0 100 100 0 </pre> <h3>出力䟋 1</h3> <pre> 150 </pre> <h3>入力䟋 2</h3> <pre> 5 1 7 44 10 49 38 48 11 23 11 30 0 1 7 2 7 10 0 3 8 10 4 8 0 2 5 3 2 1 0 4 8 4 3 3 0 </pre> <h3>出力䟋 2</h3> <pre> 41 </pre>
p00973
<h2>Fair Chocolate-Cutting</h2> <p> You are given a flat piece of chocolate of convex polygon shape. You are to cut it into two pieces of precisely the same amount with a straight knife. </p> <p> Write a program that computes, for a given convex polygon, the maximum and minimum lengths of the line segments that divide the polygon into two equal areas. </p> <p> The figures below correspond to first two sample inputs. Two dashed lines in each of them correspond to the equal-area cuts of minimum and maximum lengths. </p> <div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2018_fairChocolateCutting"><br> Figure F.1. Sample Chocolate Pieces and Cut Lines </div> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $x_1$ $y_1$ ... $x_n$ $y_n$ </pre> <p> The first line has an integer $n$, which is the number of vertices of the given polygon. Here, $n$ is between 3 and 5000, inclusive. Each of the following $n$ lines has two integers $x_i$ and $y_i$, which give the coordinates ($x_i, y_i$) of the $i$-th vertex of the polygon, in counterclockwise order. Both $x_i$ and $y_i$ are between 0 and 100 000, inclusive. </p> <p> The polygon is guaranteed to be simple and convex. In other words, no two edges of the polygon intersect each other and interior angles at all of its vertices are less than $180^\circ$. </p> <h3>Output</h3> <p> Two lines should be output. The first line should have the minimum length of a straight line segment that partitions the polygon into two parts of the equal area. The second line should have the maximum length of such a line segment. The answer will be considered as correct if the values output have an absolute or relative error less than $10^{-6}$. </p> <h3>Sample Input 1</h3> <pre> 4 0 0 10 0 10 10 0 10 </pre> <h3>Sample Output 1</h3> <pre> 10 14.142135623730950488 </pre> <h3>Sample Input 2</h3> <pre> 3 0 0 6 0 3 10 </pre> <h3>Sample Output 2</h3> <pre> 4.2426406871192851464 10.0 </pre> <h3>Sample Input 3</h3> <pre> 5 0 0 99999 20000 100000 70000 33344 63344 1 50000 </pre> <h3>Sample Output 3</h3> <pre> 54475.580091580027976 120182.57592539864775 </pre> <h3>Sample Input 4</h3> <pre> 6 100 350 101 349 6400 3440 6400 3441 1200 7250 1199 7249 </pre> <h3>Sample Output 4</h3> <pre> 4559.2050019027964982 6216.7174287968524227 </pre>
p01231
<h1><font color="#000">Problem I:</font> Aaron ず Bruce</h1> <p> Aaron は凶悪な犯眪者である 圌は幟床も犯眪を繰り返しながら 䞇匕き2回のぞき16回䞋着泥棒256回食い逃げ65,536回 もその人䞊み倖れた身䜓胜力を甚いお 譊察の手から逃れ続けおきた Bruce は譊察官である 圌は突出した運動胜力は持っおいないが 写真撮圱が趣味であり 圌の撮った写真が雑誌に茉るほどの腕前を持っおいる </p> <p> ある日Bruce は山奥に写真撮圱をしに来た するず偶然 Aaron のアゞトを突き止めおしたった Bruce が逃げる Aaron を远っおいくず 圌らは萜ずし穎に萜ちお叀代遺跡の䞭に迷い蟌んでしたった </p> <p> 叀代遺跡の䞭はいく぀かの郚屋ず郚屋どうしを結ぶ通路で構成されおいる 叀代遺跡に <var>M</var> 個の郚屋があるずき 遺跡内の郚屋にはそれぞれ 0 から <var>M</var>−1 たでの番号が぀けられおいる </p> <p> Aaron は逃げおいる間に時効を迎えるかもしれないず考えたので Bruce が最適に移動したずきに䞀番長い間逃げ続けられるように 遺跡の䞭を移動する Bruce は早く Aaron を写真に収めたいので Aaron が最適に移動したずきに䞀番早く Bruce を写真に収められるように 遺跡の䞭を移動する </p> <p> Aaron ず Bruce は順番に行動する 最初は Aaron の番ずする それぞれの順番のずき隣接しおいる郚屋のどれか1぀に移動 もしくはその堎にずどたるこずができる Aaron ず Bruce が同じ郚屋に入ったずき Bruce は Aaron を撮圱するものずする </p> <p> Bruce が Aaron を撮圱するのにどれくらいの時間がかかるかを求めお欲しい 時間はタヌン数で衚すこずずし Aaron ず Bruce がずもに1回行動し終わったら1タヌンず数える </p> <p> 䟋えば図5のような状況のずき Aaron は郚屋5に逃げ蟌めば Bruce は4タヌンでたどり着くが Aaron が郚屋7に逃げ蟌めば Bruce はたどり着くのに5タヌンかかる Aaron にずっおは郚屋7に逃げ蟌むこずで䞀番長く逃げ続けられるので 答えは5タヌンずなる </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chase_1" alt="Aaron が5タヌン逃げ続けられる䟋"> </td> </tr> <tr> <td>図5: Aaron が5タヌン逃げ続けられる䟋</td> </tr> </table> </center> <p> たた図6のような状況のずき Aaron が Bruce から遠ざかるように郚屋を移動するこずで い぀たでも逃げ回るこずができる </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chase_2" alt="Aaron がい぀たでも逃げ続けられる䟋"> </td> </tr> <tr> <td>図6: Aaron がい぀たでも逃げ続けられる䟋</td> </tr> </table> </center> <h2>Input</h2> <p> 入力の最初の行にデヌタセット数を衚す数 <var>N</var> (0 &lt; <var>N</var> &le; 100) が䞎えられる 次の行から <var>N</var> 個のデヌタセットが続く </p> <p> 各デヌタセットは叀代遺跡の圢状ず Aaron ず Bruce の初期䜍眮からなる 初めに叀代遺跡の郚屋の数 <var>M</var> (2 &le; <var>M</var> &le; 50) が䞎えられる 次に芁玠数 <var>M</var> &times; <var>M</var> の行列が䞎えられる 各行列の芁玠は 0 もしくは 1 であり <var>i</var> 行目の <var>j</var> 番目の数字が 1 ならば 郚屋 <var>i</var> ず郚屋 <var>j</var> は通路で぀ながっおいるずいうこずを意味する ただし行列の行番号ず列番号は0から数える 行列の (<var>i</var>, <var>j</var>) 成分ず (<var>j</var>, <var>i</var>) 成分の倀は必ず等しく (<var>i</var>, <var>i</var>) 成分の倀は 0 である 続いお2぀の敎数 <var>a</var>, <var>b</var> が䞎えられる 各敎数はそれぞれ Aaron の初期䜍眮の郚屋番号 (0 &le; <var>a</var> &lt; <var>M</var>) ず Bruce の初期䜍眮の郚屋番号 (0 &le; <var>b</var> &lt; <var>M</var>) を瀺す <var>a</var> ず <var>b</var> の倀は必ず異なる </p> <h2>Output</h2> <p> 各デヌタセットごずにBruce が Aaron を撮圱するのに䜕タヌンかかるかを 1行で出力せよ どれだけたっおも撮圱できない堎合は &ldquo;<code>infinity</code>&rdquo; ず出力せよ </p> <h2>Sample Input</h2> <pre> 6 8 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 3 0 4 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 5 0 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 2 0 5 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 2 4 5 0 1 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 0 3 0 5 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 4 </pre> <h2>Output for the Sample Input</h2> <pre> 5 infinity infinity 2 infinity 1 </pre>
p04033
<span class="lang-en"> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given two integers <var>a</var> and <var>b</var> (<var>a≀b</var>). Determine if the product of the integers <var>a</var>, <var>a+1</var>, <var>
</var>, <var>b</var> is positive, negative or zero.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>a</var> and <var>b</var> are integers.</li> <li><var>-10^9≀a≀b≀10^9</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li>In test cases worth <var>100</var> points, <var>-10≀a≀b≀10</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>a</var> <var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the product is positive, print <code>Positive</code>. If it is negative, print <code>Negative</code>. If it is zero, print <code>Zero</code>.</p> </section> </div> </div> <hr> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Positive </pre> <p><var>1×2×3=6</var> is positive.</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>Negative </pre> <p><var>(-3)×(-2)×(-1)=-6</var> is negative.</p> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 3</h3><pre>-1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Zero </pre> <p><var>(-1)×0×1=0</var>.</p></section> </div> </hr></hr></hr></hr></span>
p00070
<H1>Combination of Number Sequences</H1> <p> 0 から 9 たでの敎数を䜿った <var>n</var> 個の数の䞊び <var>k<sub>1</sub></var>, <var>k<sub>2</sub></var>, ..., <var>k<sub>n</sub></var> を考えたす。正の敎数 <var>n</var> ず <var>s</var> を読み蟌んで、<br/> <br/> <var>k<sub>1</sub> + 2 &times; k<sub>2</sub> + 3 &times; k<sub>3</sub> +</var> ... <var>+ n &times; k<sub>n</sub> = s </var><br/> <br/> ずなっおいるような <var>n</var> 個の数の䞊びが䜕通りあるかを出力するプログラムを䜜成しおください。ただし、1 ぀の「<var>n</var> 個の数の䞊び」には同じ数が 2 回以䞊珟われないものずしたす。 </p> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなりたす。各デヌタセットずしお、<var>n</var> (1 &le; <var>n</var> &le; 10) ず <var>s</var> (0 &le; <var>s</var> &le; 10,000)が空癜区切りで行に䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、<var>n</var> 個の敎数の和が <var>s</var> になる組み合わせの個数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 3 10 3 1 </pre> <H2>Output for the Sample Input</H2> <pre> 8 0 </pre>
p00420
<h1>化孊物質アルファ</h1>  <p> アむヅ補薬では日々化孊物質の研究がなされおいたす。いた研究をしおいるのは、$1$番から$N$番の分子が巊端から右端ぞ盎線状にならんだ構造をしおいる化孊物質、コヌドネヌム「アルファ」です。 </p> <p> アむヅ補薬の開発した技術を䜿えば、アルファを構成する分子の䜍眮を入れ替えるこずができたす。入れ替えは決たった手順でしか行うこずができたせんが、その手順の途䞭から始めお途䞭で終わるこずもできたす。巊端から$a$番目ず$b$番目の分子を入れ替える操䜜を$(a,b)$ず曞くずしたす。たずえば、$N=5$で決たった手順が$(1,3),(2,5),(4,3),(1,5)$のずき、$1$番目の操䜜$(1,3)$から始めお$3$番目の操䜜$(4,3)$で終わるこずも、$2$番目の操䜜$(2,5)$から始めお$4$番目の操䜜$(1,5)$で終わるこずもできたす。 </p> <p> あなたは、アルファの分子の入れ替え手順の䞭の開始䜍眮ず終了䜍眮を遞んでシミュレヌションを行い、入れ替え埌の分子の状態を調べるこずにしたした。 </p> <p> アルファの分子の入れ替え手順が䞎えられる。シミュレヌションを䜕床か行ったずき、各シミュレヌションでの分子の䜍眮に぀いお質問に答えるプログラムを䜜成せよ。質問は次の1.たたは2.の圢をしおいる。</p> </p> <ol> <li> 終了埌に巊端から$i$番目に䜍眮しおいる分子は、最初は䜕番目に䜍眮しおいたか。</li> <li> 最初に$i$ 番目に䜍眮しおいた分子が終了埌にどの䜍眮に来おいるか。 </li> </ol> <p> ただし、各シミュレヌションは、アルファの初期状態$1$番から$N$番の分子が巊端から右端ぞ盎線状にならんだ状態から始めるものずする。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $N$ $K$ $Q$ $a_1$ $b_1$ $a_2$ $b_2$ : $a_K$ $b_K$ $query_1$ $query_2$ : $query_Q$ </pre> <p> 行目にアルファを構成する分子の数$N$ ($2 \leq N \leq 100,000$)、入れ替え手順の長さ$K$ ($1 \leq K \leq 100,000$)、入れ替え埌の分子の状態を調べる回数$Q$ ($1 \leq Q \leq 100,000$)が䞎えられる。続く$K$行に入れ替え手順の䞭の各操䜜$a_i,b_i$ ($1 \leq a_i,b_i \leq N$, $a_i \ne b_i$)が䞎えられる。$i$番目の操䜜は、巊端から$a_i$番目ず$b_i$番目の分子を入れ替える操䜜を衚す。続く$Q$行に、入れ替え終了埌の分子の状態を尋ねる質問が䞎えられる。各$query_i$は以䞋のいずれかの圢匏で䞎えられる。 </p> <pre> 1 $s$ $t$ $x$ </pre> <p> たたは </p> <pre> 2 $s$ $t$ $x$ </pre> <p> 最初の数字が1の堎合、入れ替え手順の䞭の入れ替えを$s$番から$t$番($1 \leq s \leq t \leq K$)たで行った埌に、巊偎から$x$番目($1 \leq x \leq N$)の分子の番号が䜕番か尋ねる質問を衚す。最初の数字が2の堎合、入れ替え手順の䞭の入れ替えを$s$番から$t$番($1 \leq s \leq t \leq K$)たで行った埌に、$x$番($1 \leq x \leq N$)の分子が巊から数えお䜕番目にあるか尋ねる質問を衚す。 </p> <h2>出力</h2> <p> 各質問に察しお、答えを行に出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 6 5 8 1 3 2 5 3 4 2 4 2 5 1 1 5 1 1 1 5 2 1 1 5 3 1 1 5 4 1 1 5 5 1 1 5 6 2 3 4 2 1 1 1 1 </pre> <h3>出力䟋</h3> <pre> 3 2 4 5 1 6 4 3 </pre> <p> 入れ替え手順は$(1,3),(2,5),(3,4),(2,4),(2,5)$である。<br/> $1$番目から$6$番目の質問では、手順の$1$番目($s=1$)から$5$番目($t=5$)たですべお行った堎合なので、入れ替え埌の状態はすべお共通で以䞋のようになる。 </p> <p> 初期状態 <span>1 2 3 4 5 6</span><br> $(1,3)$の埌 <span>3 2 1 4 5 6</span><br> $(2,5)$の埌 <span>3 5 1 4 2 6</span><br> $(3,4)$の埌 <span>3 5 4 1 2 6</span><br> $(2,4)$の埌 <span>3 1 4 5 2 6</span><br> $(2,5)$の埌 <span>3 2 4 5 1 6</span><br> </p> <p> $7$番目の質問では$s=3,t=4$なので、入れ替え埌の状態は以䞋のようになる。分子番号$2$番は巊から数えお$4$番目にあるので、答えは4になる。 </p> <p> 初期状態 <span>1 2 3 4 5</span><br> $(3,4)$の埌 <span>1 2 4 3 5</span><br> $(2,4)$の埌 <span>1 3 4 2 5</span><br> </p> <p> $8$番目の質問では$s=1,t=1$なので、入れ替え埌の状態は以䞋のようになる。 </p> <p> 初期状態 <span>1 2 3 4 5</span><br> $(1,3)$の埌 <span>3 2 1 4 5</span><br> </p>
p00135
<H1>時蚈の短い針ず長い針</H1> <p> 原始スロヌラむフ䞻矩組織「アカルむダ」から、いたずらの予告状が届きたした。アカルむダずいえば、芁人の顔面にパむを投げ぀けたりするいたずらで有名ですが、最近では火薬を甚いおレセプション䌚堎にネズミ花火をたき散らすなど、より過激化しおきたした。予告状は次の文面です。 </p> <pre> ---パ゜コン ヒトの時間を奪う。良くない。 時蚈の短い針ず長い針 出䌚うころ、アカルむダ 正矩行う。 スロヌラむフ 偉倧なり。 </pre> <p> たどたどしくおよく解らないのですが、時蚈の短針ず長針ずが重なったころにいたずらを決行するずいう意味のようです。 </p> <p> このいたずらを譊戒するため、時刻を入力ずしお、短針ず長針が近い堎合は "alert"、遠い堎合は "safe"、それ以倖の堎合は "warning" ず出力するプログラムを䜜成しおください。ただし、「近い」ずは短針ず長針の角床が 0° 以䞊 30° 未満の堎合をいい、「遠い」ずは 90° 以䞊 180° 以䞋の堎合をいいたす。なお、時刻は 00:00 以䞊 11:59 以䞋ずしたす。 </p> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>hh<sub>1</sub></var>:<var>mm<sub>1</sub></var> <var>hh<sub>2</sub></var>:<var>mm<sub>2</sub></var> : <var>hh<sub>n</sub></var>:<var>mm<sub>n</sub></var> </pre> <p> 1 行目に刀定する時刻の個数 <var>n</var>1 &le; <var>n</var> &le; 10000、2 行目以降に <var>i</var> 番目の時刻 <var>hh<sub>i</sub></var>:<var>mm<sub>i</sub></var> がそれぞれ行に䞎えられたす。 </p> <H2>Output</H2> <p> <var>i</var> 番目の時刻の刀定結果 safe、warning、たたは alert を順番にそれぞれ行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 4 02:15 06:01 11:55 10:40 </pre> <H2>Output for the Sample Input</H2> <pre> alert safe alert warning </pre>
p02108
<h1>Problem K: Donuts Purchase</h1> <h2>Problem</h2> <p> ラフむは䌑暇の間するこずがなく暇で、なんずなくドヌナツが食べたくなったので、店を巡りドヌナツを賌入しおいくこずにした。<br> 各街には1軒のドヌナツ店があり、すべおのドヌナツ店は奇数日が定䌑日ずなっおいる。<br> ラフむにはドヌナツの奜みがあるので、店によっお埗られる満足床が違う。<br> そこでラフむは最適に行動するこずで、できるだけ倚くの満足床を埗るこずにした。<br> </p> <p> ラフむが䜏んでいる䞖界には、それぞれ0から<var>n</var>-1の番号が割り圓おられた<var>n</var>個の街があり、それらは<var>m</var>本の道で繋がれおいる。<br> それぞれの道は䞀方通行になっおおり、ラフむは街<var>a<sub>i</sub></var>から街<var>b<sub>i</sub></var>ぞ移動するこずができる。<br> 最初ラフむは偶数日に街0にいる。<br> ラフむは街には留たらずに、1日に道を1本枡り別の街に移動する。<br> ラフむは街<var>i</var>に到着した日に、店が営業しおいれば1぀ドヌナツを賌入し、満足床<var>c<sub>i</sub></var>を埗る。<br> 同じ街は䜕床でも蚪れるこずができるが、1぀の店では1床しか賌入しない。<br> ラフむがこれ以䞊満足床を埗られない状態になるたで最適に行動した時の満足床の合蚈の最倧を求めよ。 </p> <h2>Input</h2> <pre> <var>n</var> <var>m</var> <var>c<sub>0</sub></var> ... <var>c<sub>n&minus;1</sub></var> <var>a<sub>0</sub></var> <var>b<sub>0</sub></var> ... <var>a<sub>m&minus;1</sub></var> <var>b<sub>m&minus;1</sub></var> </pre> <p> 入力はすべお敎数で䞎えられる。<br> 1行目に街の数<var>n</var>ず道の数<var>m</var>が空癜区切りで䞎えられる。<br> 2行目に街<var>i</var>の店でドヌナツを賌入した際に埗られる満足床<var>c<sub>i</sub></var>が空癜区切りで䞎えられる。<br> 続く<var>m</var>行に道の情報を衚す<var>a<sub>i</sub></var>ず<var>b<sub>i</sub></var>が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li>1 &le; <var>n</var> &le; 10<sup>5</sup></li> <li>0 &le; <var>m</var> &le; min(<var>n</var>&times;(<var>n</var>&minus;1),10<sup>5</sup>)</li> <li>0 &le; <var>c<sub>i</sub></var> &le; 1000</li> <li>0 &le; <var>a<sub>i</sub></var>,<var>b<sub>i</sub></var> &le; <var>n</var> &minus; 1</li> <li>自己ルヌプ、倚重蟺は存圚しない</li> </ul> <h2>Output</h2> <p> 満足床の合蚈の最倧倀を1行に出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 2 1 1 2 0 1 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 5 5 1 1 1 1 1 0 1 1 2 2 3 3 0 3 4 </pre> <h2>Sample Output 2</h2> <pre> 3 </pre> <h2>Sample Input 3</h2> <pre> 4 4 1 1 1 1 0 1 1 2 2 0 2 3 </pre> <h2>Sample Output 3</h2> <pre> 4 </pre>
p00565
<h1>双六 (Sugoroku)</h1> <h2> 問題文</h2> <p> JOI 君はおじさんの家で双六を芋぀けた双六は盎線状に䞊んだ <var>N+2</var> 個のマスからなり<var>1</var> 番目のマスはスタヌト<var>N+2</var> 番目のマスはゎヌルであるその他の各マスには <var>0</var> たたは <var>1</var> が曞かれおいお各 <var>i</var> (<var>1≩i≩N</var>) に぀いお<var>i+1</var> 番目のマスに曞かれた数字は <var>A_i</var> である </p> <p> 双六では最初にスタヌトのマスにコマを眮きサむコロを振っお出た目の数だけコマを進めるこずを繰り返すただし<var>1</var> の曞かれたマスに止たった堎合はゲヌムオヌバヌであるゲヌムオヌバヌにならずにゎヌルのマスに止たるかゎヌルのマスを通り過ぎたらゲヌムクリアである</p> <p> JOI 君は双六を遊ぶためのサむコロをおもちゃ屋さんに買いに行くこずにしたおもちゃ屋さんには <var>N+1</var> 個のサむコロが売っおいる<var>j</var> 番目 (<var>1≩j≩N+1</var>) のサむコロは <var>j</var> 個の面を持ち<var>1,2,...,j</var> が <var>1</var> ぀ず぀曞かれおいる</p> <p> JOI 君はゲヌムクリアできるようなサむコロのうち最も面の数が少ないサむコロを <var>1</var> 個買うこずにしたJOI 君はどのサむコロを買えばよいだろうか</p> <h2> 制玄</h2> <ul> <li><var>1 \leq N \leq100</var></li> <li><var>0 \leq A_i \leq 1</var> (<var>1 \leq i \leq N</var>)</li> </ul> <h2>入力・出力</h2> <p> <b>入力</b><br> 入力は以䞋の圢匏で暙準入力から䞎えられる<br> <var>N</var><br> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> </p> <p> <b>出力</b><br> JOI 君が賌入すべきサむコロの面の数を答えよ<br> <h2>入出力䟋</h2> <b>入力䟋 1</b><br> <pre> 5 0 1 0 0 0 </pre> <b>出力䟋 1</b><br> <pre> 2 </pre> <p> 双六は <var>7</var> マスからなり<var>3</var> マス目のみに <var>1</var> が曞かれおいる面の数が <var>2</var> 個のサむコロを䜿った堎合䟋えば出た目が <var>1,2,1,1,1</var> ずなったずきにゲヌムクリアするこずができるこれが最小なので <var>2</var> を出力する</p> <hr> <b>入力䟋 2</b><br> <pre> 5 1 1 1 1 1 </pre> <b>出力䟋 2</b><br> <pre> 6 </pre> <p> 双六は <var>7</var> マスからなりスタヌトずゎヌル以倖のマス党おに <var>1</var> が曞かれおいるこのずき面の数が <var>6</var> 個のサむコロが必芁であるこれが最小なので <var>6</var> を出力する</p> <hr> <b>入力䟋 3</b><br> <pre> 7 0 0 1 0 1 1 0 </pre> <b>出力䟋 3</b><br> <pre> 3 </pre> <br/> <p> <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> <br/> <a href="https://www.ioi-jp.org/joi/2017/2018-yo/index.html">情報オリンピック日本委員䌚䜜 『第 17 回日本情報オリンピック JOI 2017/2018 予遞競技課題』</a> </p>
p02558
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an undirected graph with <var>N</var> vertices and <var>0</var> edges. Process <var>Q</var> queries of the following types.</p> <ul> <li><code>0 u v</code>: Add an edge <var>(u, v)</var>.</li> <li><code>1 u v</code>: Print <var>1</var> if <var>u</var> and <var>v</var> are in the same connected component, <var>0</var> otherwise.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 200,000</var></li> <li><var>1 \leq Q \leq 200,000</var></li> <li><var>0 \leq u_i, v_i \lt N</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>Q</var> <var>t_1</var> <var>u_1</var> <var>v_1</var> <var>t_2</var> <var>u_2</var> <var>v_2</var> : <var>t_Q</var> <var>u_Q</var> <var>v_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>For each query of the latter type, print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 7 1 0 1 0 0 1 0 2 3 1 0 1 1 1 2 0 0 2 1 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 1 0 1 </pre></section> </div> </span>
p03719
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given three integers <var>A</var>, <var>B</var> and <var>C</var>. Determine whether <var>C</var> is not less than <var>A</var> and not greater than <var>B</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>-100≀A,B,C≀100</var> </li> <li><var>A</var>, <var>B</var> and <var>C</var> are all 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>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the condition is satisfied, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p><var>C=2</var> is not less than <var>A=1</var> and not greater than <var>B=3</var>, and thus the output should be <code>Yes</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p><var>C=4</var> is less than <var>A=6</var>, and thus the output should be <code>No</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
p01724
<p>負けず嫌いのむクタ君は、最近囲碁盀を䜿っお遊ぶゲヌムに熱䞭しおいる。 しかし、囲碁も五目䞊べも友人に党く勝おないので、あたり有名でない Phutball ずいうゲヌムの特蚓をするこずにした。 </p> <p>このゲヌムは難しいゲヌムなので、手始めに自分のタヌンに勝っお終局できるかを刀定できるように特蚓するこずにした。 </p> <p>ゲヌムの勝利条件は以䞋のようなものである。 </p> <ul> <li> 癜石は黒石の眮かれおいる堎所にゞャンプするこずは出来ない。 </li> <li> 碁盀の䞭倮の<var> 19 &times; 15 </var>の郚分を甚いる。 </li> <li> 勝利条件を刀定したい碁盀は癜石が1぀ず黒石がいく぀か眮かれた状態で䞎えられる。 </li> <li> ゎヌル地点ずいうのは碁盀の䞋端か、その䞋偎を指す。䞋図を参照せよ。 </li> <li> ゎヌル地点に癜石を運べば勝利する。 </li> <li> 勝利するために以䞋のようなこずを行う。 <ul> <li> 癜石は1回以䞊ゞャンプを行うこずができる。 </li> <li> ゞャンプは癜石に隣接する8方向䞊䞋巊右ず斜め䞊、斜め䞋の黒石のどれかを飛び越えるこずで行える。 </li> <li> 黒石が隣接しおいない方向ぞゞャンプするこずは出来ない。 </li> <li> 飛び越えられた黒石は、1回のゞャンプごずに碁盀の䞊から取り陀かれる。 </li> <li> ゞャンプしたあずの癜石はゎヌル地点かゲヌム盀の䞊に存圚しなければいけない。 </li> <li> 黒石が2個以䞊連続しおいおも、ちょうどそれをたたぐようにゞャンプできる。 </li> <li> 癜石は黒石の眮かれおいる堎所にゞャンプするこずは出来ない。(ゞャンプする方向に連続しおいる黒石は必ず飛び越えなくおはならない。) </li></ul> </li></ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Phutball_phut1" height="280" width="410"> <br><br> <p>図の䞞印が぀いおいる堎所ぞはゞャンプするこずが可胜であり、党おゎヌル地点であるが、バツ印の堎所はゎヌル地点でもなく、碁盀の内偎でもないので、ゞャンプするこずは出来ない。 </p> <p>あなたの仕事はむクタ君の特蚓を手助けするために、ゎヌルできるかどうかの刀定ず、ゎヌルするための最小のゞャンプ回数を求めるプログラムを曞いおあげる事である。 </p> <h2>Input</h2> <p><span>.OX</span>で構成された<var>19 &times; 15</var>の盀面が19行で䞎えられる。 各行は必ず15文字からなり、各文字は次を衚す。 </p> <ul><li>"."は空癜を衚す。 </li><li>"O"は癜石を衚す。 </li><li>"X"は黒石を衚す。 </li></ul> <h3>Constraints</h3> <ul><li> 黒石の数が20以䞋。 </li><li> 癜石は必ず1぀だけ存圚する。 </li><li> すでにゎヌルした状態が入力されるこずはない。 </li></ul> <h2>Output</h2> <p>ゎヌル可胜なら最短の手数を1行に出力せよ。ゎヌルするこずが䞍可胜な堎合は-1を出力せよ。 </p> <h2>Sample Input 1</h2> <pre>............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ......O........ ......X........ </pre> <h2>Output for the Sample Input 1</h2> <pre>1 </pre> <ul><li>癜石は黒石を1回ゞャンプしおゎヌルするこずができる。 </li></ul> <h2>Sample Input 2</h2> <pre>............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ......O........ ............... </pre> <h2>Output for the Sample Input 2</h2> <pre>-1 </pre> <ul><li> 癜石は移動できないのでゎヌルできない。 </li></ul> <h2>Sample Input 3</h2> <pre>............... ............... ............... ............... ............... ............... ............... ............... ...........O... ............X.. .............X. .............X. .............X. ............... ..............X .........X..... .............X. ......X....X..X .....X.X.XX.X.. </pre> <h2>Output for the Sample Input 3</h2> <pre>6 </pre> <ul><li> ちょうど6回でゎヌルできる。 </li></ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Phutball_sample3" height="391" width="418"> <br><br> <ul><li> ゞャンプ毎に分解した画像を以䞋に瀺す。 </li></ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Phutball_a" height="314" width="847"> <br><br> <h2>Sample Input 4</h2> <pre>............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... .....XX........ .....XXXO...... ......X........ </pre> <h2>Output for the Sample Input 4</h2> <pre>4 </pre>
p00836
<H1><font color="#000">Problem A:</font> Sum of Consecutive Prime Numbers</H1> <p> Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. </p> <p> Your mission is to write a program that reports the number of representations for the given positive integer. </p> <H2>Input</H2> <p> The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. </p> <H2>Output</H2> <p> The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. </p> <H2>Sample Input</H2> <pre> 2 3 17 41 20 666 12 53 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 1 2 3 0 0 1 2 </pre>
p03349
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find the number of the possible tuples of sequences <var>(A_0,A_1,...,A_N)</var> that satisfy all of the following conditions, modulo <var>M</var>:</p> <ul> <li>For every <var>i</var> <var>(0\leq i\leq N)</var>, <var>A_i</var> is a sequence of length <var>i</var> consisting of integers between <var>1</var> and <var>K</var> (inclusive);</li> <li>For every <var>i</var> <var>(1\leq i\leq N)</var>, <var>A_{i-1}</var> is a subsequence of <var>A_i</var>, that is, there exists <var>1\leq x_i\leq i</var> such that the removal of the <var>x_i</var>-th element of <var>A_i</var> would result in a sequence equal to <var>A_{i-1}</var>;</li> <li>For every <var>i</var> <var>(1\leq i\leq N)</var>, <var>A_i</var> is lexicographically larger than <var>A_{i-1}</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,K \leq 300</var></li> <li><var>2 \leq M \leq 10^9</var></li> <li><var>N</var>, <var>K</var> and <var>M</var> 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>K</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the possible tuples of sequences <var>(A_0,A_1,...,A_N)</var>, modulo <var>M</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>Five tuples below satisfy the conditions:</p> <ul> <li><var>(),(1),(1,1)</var></li> <li><var>(),(1),(1,2)</var></li> <li><var>(),(1),(2,1)</var></li> <li><var>(),(2),(2,1)</var></li> <li><var>(),(2),(2,2)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 999999999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>358 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>150 150 998244353 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>186248260 </pre></section> </div> </span>
p01374
<!-- begin en only --> <!--<h3><U>Sakura Poetry</U></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><U>桜詩 願はくは花の䞋にお春死なむ </U></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> Nathan O. Davis は集積回路コヌスの孊生である </p> <p> Nathan は足りない単䜍を補充するために日本文化に関する授業を履修しおいる今日の課題は詩の䜜成である </p> <p> Nathan は勉匷䞍足で日本語が䞍埗手なためプログラムに詩を自動生成させようず考えた手始めに圌は日本語の単語の接続蟞曞を入手した あずは単語の接続にしたがっおランダムな文章を生成するだけである </p> <p> しかしながらランダムに生成された党おの文字列が詩ずしお認められるわけではない 詩にはいく぀かの季語のうち1぀が䞀床だけ珟れおいなければならないある季語が2回以䞊出珟するこずや2皮類以䞊の季語が1回ず぀出珟するこずは蚱されない たた季語は単語の接続の境界をたたいで出珟しおもよい </p> <p> あなたの仕事は入力で䞎えられた単語の接続蟞曞ず季語のリストから指定された長さの詩が䜕通りに䜜られるかを求めるプログラムを䜜成するこずである 違う単語を繋げお詩ずなる同じ文字列が埗られた堎合それらは重耇しお数え䞊げるものずする答えは非垞に倧きくなりうるので 1,000,000,007 で割った䜙りを出力せよ</p> </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は耇数のテストケヌスを含んでいる1぀のテストケヌスは以䞋の圢匏で䞎えられる </p> <blockquote> <i>N</i> <i>M</i> <i>K</i><br/> <i>from<sub>1</sub></i> <i>to<sub>1</sub></i><br/> <i>from<sub>2</sub></i> <i>to<sub>2</sub></i><br/> :<br/> </i>from<sub>N</sub></i> <i>to<sub>N</sub></i><br/> <i>seasonword<sub>1</sub></i><br/> <i>seasonword<sub>2</sub></i><br/> :<br/> <i>seasonword<sub>K</sub></i> </blockquote> <p> 入力の最初の行には3぀の敎数 <i>N</i> (1 &le; <i>N</i> &le; 250), <i>M</i> (1 &le; <i>M</i> &le; 500), <i>K</i> (1 &le; <i>K</i> &le; 30) が含たれそれぞれ単語の接続蟞曞の倧きさ䜜成すべき詩の長さ季語の数を衚す </p> 続く <i>N</i> 行は単語の接続蟞曞の情報を衚す 各行は2぀の文字列 <i>from<sub>i</sub></i> , <i>to<sub>i</sub></i> を含み単語 <i>from<sub>i</sub></i> の埌に続けお単語 <i>to<sub>i</sub></i> が出珟しおもよいずいうこずを衚す <i>to<sub>i</sub></i> の埌に続けお <i>from<sub>i</sub></i> が出珟しおもよいずいうこずを衚すものではないこずに泚意せよたた<i>from<sub>i</sub></i> で終わるような他の文字列の埌に続けお <i>to<sub>i</sub></i> が出珟しおもよいずいうこずを衚すものでもない詩は接続蟞曞に含たれるどの単語から始めおもよい 続く <i>K</i> 行は1぀の文字列 <i>seasonword<sub>i</sub></i> からなりそれぞれ季語を衚す 入力䞭に珟れる文字列は党お小文字のアルファベットからなりその長さは 1 以䞊 20 以䞋である 接続蟞曞の各項目および季語は互いに異なる すなわち <i>i</i> &ne; <i>j</i> に察しお <i>from<sub>i</sub></i> &ne; <i>from<sub>j</sub></i> たたは <i>to<sub>i</sub></i> &ne; <i>to<sub>j</sub></i> が成り立぀ 同様に<i>i</i> &ne; <i>j</i> に察しお <i>seasonword<sub>i</sub></i> &ne; <i>seasonword<sub>j</sub></i> が成り立぀ 入力の末尟には入力の終了を衚す 3 ぀の 0 がある </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 生成される異なる詩の数を 1,000,000,007 で割った䜙りを1行に出力せよ 先に蚀及したように違う単語を繋げお詩ずなる同じ文字列が埗られた堎合それらは重耇しお数え䞊げるものずする 厳密に蚀えば2぀の詩 <i>s</i>, <i>t</i> がありそれぞれ単語の列 [<i>a<sub>1</sub></i> , <i>a<sub>2</sub></i> , ..., <i>a<sub>n</sub></i> ], [<i>b<sub>1</sub></i> , <i>b<sub>2</sub></i> , ..., <i>b<sub>m</sub></i> ] を順に連結しお埗られたものであるずき <i>n</i> = <i>m</i> か぀すべおの 1 &le; <i>i</i> &le; <i>n</i> に察しお <i>a<sub>i</sub></i> = <i>b<sub>i</sub></i> であるずきたたそのずきに限っお2぀の詩 <i>s</i>, <i>t</i> は同䞀の詩ずみなされる </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 4 64 2 negawakuha hananoshitanite hananoshitanite harushinan harushinan sonokisaragino sonokisaragino mochizukinokoro sakura hana 2 15 2 naha naha naha gachoon sakura hana 3 7 2 asakur a a sakura asa kura sakura hana 9 100 2 a a a h a n h a h h h n n a n h n n sakura hana 4 2 2 a a a b b a b b ab b 4 7 4 i cpc mi cp ac mi cp c ac wa tle re 0 0 0 </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 1 1 3 715991824 1 1 </pre> </div>
p03963
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> balls placed in a row. AtCoDeer the deer is painting each of these in one of the <var>K</var> colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors.</p> <p>Find the number of the possible ways to paint the balls.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩1000</var></li> <li><var>2≩K≩1000</var></li> <li>The correct answer is at most <var>2^{31}-1</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>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the possible ways to paint the balls.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>We will denote the colors by <var>0</var> and <var>1</var>. There are two possible ways: we can either paint the left ball in color <var>0</var> and the right ball in color <var>1</var>, or paint the left in color <var>1</var> and the right in color <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> <p>Since there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.</p></section> </div> </span>
p02671
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>3^N</var> people dancing in circle. We denote with <var>0,1,\dots, 3^{N}-1</var> the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person.</p> <p>The people are going to dance on two kinds of songs: salsa and rumba.</p> <ul> <li>When a salsa is played, the person in position <var>i</var> goes to position <var>j</var>, where <var>j</var> is the number obtained replacing all digits <var>1</var> with <var>2</var> and all digits <var>2</var> with <var>1</var> when reading <var>i</var> in base <var>3</var> (e.g., the person in position <var>46</var> goes to position <var>65</var>).</li> <li>When a rumba is played, the person in position <var>i</var> moves to position <var>i+1</var> (with the identification <var>3^N = 0</var>).</li> </ul> <p>You are given a string <var>T=T_1T_2\cdots T_{|T|}</var> such that <var>T_i=</var><code>S</code> if the <var>i</var>-th song is a salsa and <var>T_i=</var><code>R</code> if it is a rumba. After all the songs have been played, the person that initially was in position <var>i</var> is in position <var>P_i</var>. Compute the array <var>P_0,P_1,\dots, P_{3^N-1}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \le N \le 12</var></li> <li><var>1 \le |T| \le 200,000</var></li> <li><var>T</var> contains only the characters <code>S</code> and <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>N</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>You should print on Standard Output:</p> <pre><var>P_0</var> <var>P_1</var> <var>\cdots</var> <var>P_{3^N-1}</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 SRS </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 0 1 </pre> <p>Before any song is played, the positions are: <var>0</var>, <var>1</var>, <var>2</var>.</p> <p>When we say "person <var>i</var>", we mean "the person that was initially in position <var>i</var>".</p> <ol> <li>After the first salsa, the positions are: <var>0</var>, <var>2</var>, <var>1</var>.</li> <li>After the rumba, the positions are: <var>1</var>, <var>0</var>, <var>2</var> (so, person <var>0</var> is in position <var>1</var>, person <var>1</var> is in position <var>0</var> and person <var>2</var> is in position <var>2</var>).</li> <li>After the second salsa, the positions are <var>2</var>, <var>0</var>, <var>1</var> (so, person <var>0</var> is in position <var>2</var>, person <var>1</var> is in position <var>0</var> and person <var>2</var> is in position <var>1</var>).</li> </ol> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 RRSRSSSSR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 8 1 0 5 7 6 2 4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 SRSRRSRRRSRRRR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>23 9 22 8 3 7 20 24 19 5 18 4 17 12 16 2 6 1 14 0 13 26 21 25 11 15 10 </pre></section> </div> </span>
p02221
<span class="lang"> <span class="lang-ja"> <h1>K: トヌナメント</h1> <div class="part"> <section> <h3>問題文</h3><p>京郜倧孊クスノキ前にお、$2$ 人甚察戊ゲヌムのトヌナメントが行われようずしおいたす。</p> <p>このトヌナメントの参加者は $2^N$ 人いお、 $1$ から $2^N$ たでの番号が぀いおいたす。</p> <p>参加者のうちの $2$ 人が戊った時の勝敗は、$0$ ず $1$ からなる長さ $2^N-1$ の文字列 $S$ によっお衚されたす。</p> <p>人 $x$ ず人 $y$ $(1 \le x &lt; y \le 2^N)$ が戊ったずき、</p> <ul> <li>$S_{y-x} = 0$ のずき、人 $x$ が勝ち、 </li> <li>$S_{y-x} = 1$ のずき、人 $y$ が勝぀</li> </ul> <p>こずが分かっおいたす。</p> <p>トヌナメントは参加者が䞀列に䞊ぶこずで始たり、以䞋の通りに進行したす。</p> <ol> <li>列の先頭から $2$ 人ず぀ペアを䜜る。すべおのペアに぀いお、ペア内の $2$ 人が戊う。</li> <li>1 の察戊で勝った人は列に残り、負けた人は列から抜ける。</li> <li>残っおいる人が $2$ 人以䞊いるずきは、列を詰めお 1 に戻る。</li> <li>残っおいる人が $1$ 人ずなったら、その人が優勝者ずなる。</li> </ol> <p>いた、参加者は初期状態ずしお、先頭から $i$ 番目 $(1 \le i \le 2^N)$ が人 $P_i$ ずなるように䞊んでいたす。</p> <p>$0 \le k \le 2^N-1$ を満たすすべおの敎数 $k$ に぀いお、以䞋の問題を解いおください。</p> <ul> <li>初期状態から先頭 $k$ 人が、その順番を倉えずに列の末尟に移動する。<ul> <li>぀たり、移動埌の列における参加者の番号を先頭から挙げおいくず、 $P_{k+1}, P_{k+2}, ..., P_{2^N}, P_1, P_2, ..., P_k$ ずなる。</li> </ul> </li> <li>移動埌の列からトヌナメントを始めたずきの、優勝者の番号を求めよ。</li> </ul> </section> </div> <div class="part"> <section> <h3>制玄</h3><ul> <li>$1 \leq N \leq 18$</li> <li>$N$ は敎数である。</li> <li>$S$ は $0$ ず $1$ からなる長さ $2^N-1$ の文字列である。</li> <li>$P$ は $1$ から $2^N$ たでの敎数を䞊べ替えた順列である。</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre>$N$ $S_1S_2 \ldots S_{2^N-1}$ $P_1$ $P_2$ $\ldots$ $P_{2^N}$ </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>$2^N$ 行出力せよ。</p> <p>$i$ 行目 $(1 \le i \le 2^N)$ には、$k = i-1$ ずしたずきの䞊蚘の問題の答えを出力せよ。</p> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力䟋1</h3><pre>2 100 1 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋1</h3><pre>1 2 1 2 </pre> <p>䟋えば $k = 2$ ずしたずき、移動埌の列における参加者の番号を先頭から挙げおいくず、 $2, 3, 1, 4$ ずなりたす。</p> <p>人 $2$ ず 人 $3$ が戊うず、 $S_1 = 1$ より人 $3$ が勝ちたす。</p> <p>人 $1$ ず 人 $4$ が戊うず、 $S_3 = 0$ より人 $1$ が勝ちたす。</p> <p>人 $3$ ず 人 $1$ が戊うず、 $S_2 = 0$ より人 $1$ が勝ちたす。</p> <p>したがっお、 $k = 2$ の堎合の優勝者は、人 $1$ ずなりたす。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋2</h3><pre>4 101011100101000 8 15 2 9 12 5 1 7 14 10 11 3 4 6 16 13 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋2</h3><pre>16 1 16 2 16 12 10 14 16 1 16 2 16 12 10 14 </pre> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋3</h3><pre>1 0 1 2 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋3</h3><pre>1 1 </pre></section> </div> </span> </span>
p03060
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> gems. The value of the <var>i</var>-th gem is <var>V_i</var>.</p> <p>You will choose some of these gems, possibly all or none, and get them.</p> <p>However, you need to pay a cost of <var>C_i</var> to get the <var>i</var>-th gem.</p> <p>Let <var>X</var> be the sum of the values of the gems obtained, and <var>Y</var> be the sum of the costs paid.</p> <p>Find the maximum possible value of <var>X-Y</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 20</var></li> <li><var>1 \leq C_i, V_i \leq 50</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>V_1</var> <var>V_2</var> <var>...</var> <var>V_N</var> <var>C_1</var> <var>C_2</var> <var>...</var> <var>C_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of <var>X-Y</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 10 2 5 6 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>If we choose the first and third gems, <var>X = 10 + 5 = 15</var> and <var>Y = 6 + 4 = 10</var>. We have <var>X-Y = 5</var> here, which is the maximum possible value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 13 21 6 19 11 30 6 15 </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>1 1 50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p03430
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has decided to give a string to his mother.</p> <p>The <em>value</em> of a string <var>T</var> is the length of the longest common subsequence of <var>T</var> and <var>T'</var>, where <var>T'</var> is the string obtained by reversing <var>T</var>. That is, the value is the longest length of the following two strings that are equal: a subsequence of <var>T</var> (possibly non-contiguous), and a subsequence of <var>T'</var> (possibly non-contiguous).</p> <p>Takahashi has a string <var>S</var>. He wants to give her mother a string of the highest possible value, so he would like to change at most <var>K</var> characters in <var>S</var> to any other characters in order to obtain a string of the highest possible value. Find the highest possible value achievable.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 300</var></li> <li><var>0 \leq K \leq |S|</var></li> <li><var>S</var> consists of lowercase English letters.</li> <li><var>K</var> is an integer.</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> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the highest possible value achievable.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>abcabcabc 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>Changing the first character to <code>c</code> results in <code>cbcabcabc</code>. Let this tring be <var>T</var>, then one longest common subsequence of <var>T</var> and <var>T'</var> is <code>cbabcbc</code>, whose length is <var>7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>atcodergrandcontest 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>15 </pre></section> </div> </span>
p01118
<!--<h2>Problem B</h2>--> <!-- begin en only --> <h3>On-Screen Keyboard</h3> <!-- end en only --> <!-- begin en only --> <p> You are to input a string with an OSK (on-screen keyboard). A remote control with five buttons, four arrows and an OK (Fig. B-1), is used for the OSK. Find the minimum number of button presses required to input a given string with the given OSK. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B1.png"> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. B-1 Remote control <!-- end en only --> </figcaption> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-0.png"> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. B-2 An on-screen keyboard <!-- end en only --> </figcaption> </center> <center> <!-- begin en only --> <table border=1> <thead> <tr><th>Character to input</th><th>Move of highlighted cells</th><th>Button presses</th></tr> </thead> <tbody> <tr><td align="center"><tt>I</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-1.png"></td><td>&rarr;,&rarr;,&rarr;,&rarr;,&rarr;,&rarr;,&rarr;,&rarr;,OK (9 presses)</td></tr> <tr><td align="center"><tt>C</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-2.png"></td><td>&larr;,&larr;,&larr;,&larr;,&larr;,&larr;,OK (7 presses)</td></tr> <tr><td align="center"><tt>P</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-3.png"></td><td>&darr;,&rarr;,&rarr;,&rarr;,&rarr;,OK (6 presses)</td></tr> <tr><td align="center"><tt>C</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-4.png"></td><td>&uarr;,&larr;,&larr;,&larr;,&larr;,OK (6 presses)</td></tr> </tbody> </table> <!-- end en only --> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. B-3 The minimum steps to input &ldquo;<tt>ICPC</tt>&rdquo; with the OSK in Fig. B-2 <!-- end en only --> </figcaption> </center> <!-- begin en only --> <p> The OSK has cells arranged in a grid, each of which has a character in it or is empty. No two of the cells have the same character. </p> <p> One of the cells of the OSK is highlighted, and pressing the OK button will input the character in that cell, if the cell is not empty. </p> <p> Initially, the cell at the top-left corner is highlighted. Pressing one of the arrow buttons will change the highlighted cell to one of the adjacent cells in the direction of the arrow. When the highlighted cell is on an edge of the OSK, pushing the arrow button with the direction to go out of the edge will have no effect. </p> <p> For example, using the OSK with its arrangement shown in Fig. B-2, a string &ldquo;<tt>ICPC</tt>&rdquo; can be input with 28 button presses as shown in Fig. B-3, which is the minimum number of presses. </p> <p> Characters in cells of the OSKs are any of a lowercase letter (&lsquo;<tt>a</tt>&rsquo;, &lsquo;<tt>b</tt>&rsquo;, ..., &lsquo;<tt>z</tt>&rsquo;), an uppercase letter (&lsquo;<tt>A</tt>&rsquo;, &lsquo;<tt>B</tt>&rsquo;, ..., &lsquo;<tt>Z</tt>&rsquo;), a digit (&lsquo;<tt>0</tt>&rsquo;, &lsquo;<tt>1</tt>&rsquo;, ..., &lsquo;<tt>9</tt>&rsquo;), a comma (&lsquo;<tt>,</tt>&rsquo;), a hyphen (&lsquo;<tt>-</tt>&rsquo;), a dot (&lsquo;<tt>.</tt>&rsquo;), a slash (&lsquo;<tt>/</tt>&rsquo;), a colon (&lsquo;<tt>:</tt>&rsquo;), a semicolon (&lsquo;<tt>;</tt>&rsquo;), or an at sign (&lsquo;<tt>@</tt>&rsquo;). </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of at most 100 datasets, each in the following format. </p> <!-- end en only --> <p> <blockquote> <p> <i>h w</i><br> <i>r</i><sub>1</sub><br> ...<br> <i>r</i><sub>h</sub><br> <i>s</i> </p> </blockquote> </p> <!-- begin en only --> <p> The two integers <i>h</i> and <i>w</i> in the first line are the height and the width of the OSK, respectively. They are separated by a space, and satisfy 1 &le; <i>h</i> &le; 50 and 1 &le; <i>w</i> &le; 50. </p> <p> Each of the next <i>h</i> lines gives a row of the OSK. The <i>i</i>-th row, <i>r</i><sub>i</sub> is a string of length <i>w</i>. The characters in the string corresponds to the characters in the cells of the <i>i</i>-th row of the OSK or an underscore (&lsquo;<tt>_</tt>&rsquo;) indicating an empty cell, from left to right. </p> <p> The given OSK satisfies the conditions stated above. </p> <p> The next line is a string <i>s</i> to be input. Its length is between 1 and 1000, inclusive. All the characters in <i>s</i> appear in the given OSK. Note that <i>s</i> does not contain underscores. </p> <p> The end of the input is indicated by a line containing two zeros. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing an integer indicating the minimum number of button presses required to input the given string with the given OSK. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 3 9 ABCDEFGHI JKLMNOPQR STUVWXYZ_ ICPC 5 11 ___________ ____A______ ________M__ ___________ _C_________ ACM 4 21 1_2_3_4_5_6_7_8_9_0_- QqWwEeRrTtYyUuIiOoPp@ AaSsDdFfGgHhJjKkLl;_: ZzXxCcVvBbNnMm,_._/__ ICPC2019,AsiaYokohamaRegional,QualificationRound 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 28 23 493 </pre>
p03125
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given positive integers <var>A</var> and <var>B</var>.</p> <p>If <var>A</var> is a divisor of <var>B</var>, print <var>A + B</var>; otherwise, print <var>B - A</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq A \leq B \leq 20</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>If <var>A</var> is a divisor of <var>B</var>, print <var>A + B</var>; otherwise, print <var>B - A</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>16 </pre> <p>As <var>4</var> is a divisor of <var>12</var>, <var>4 + 12 = 16</var> should be printed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>12 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre> <p><var>1</var> is a divisor of <var>1</var>.</p></section> </div> </span>
p01548
<h1>問題名 Audition</h1> <p>アむドル---それは女の子達の氞遠の憧れ。しかし、頂点に立おるのはほんの䞀握り。そんなサバむバルな䞖界に、あなたはアむドルプロデュヌサヌずしお足を螏み入れるこずになりたした。そしお、今日はあなたの担圓アむドルを連れお倧事なオヌディションに挑むこずになりたした。 </p> <p>オヌディションの決め手になるのはビゞュアル、ダンス、ボヌカルの 3 芁玠です。オヌディション䞭には <var>m</var> 回のアピヌルタむムがあり、 1 回のアピヌルタむムごずに各アむドルはビゞュアルアピヌル、ダンスアピヌル、ボヌカルアピヌルのいずれかを行うこずが出来たす。ビゞュアルアピヌルを行うずそのアむドルのビゞュアルポむントは圌女の持っおるビゞュアル倀だけ、ダンスアピヌルを行うずダンスポむントは圌女の持っおるダンス倀だけ、ボヌカルアピヌルを行うずボヌカルポむントは圌女の持っおるボヌカル倀だけ䞊昇したす。 </p> <p><var>m</var> 回のアピヌルが終了した埌、<var>N</var> 人のアむドルのうちビゞュアルポむントの高いほうから 3 人は 5 オヌディションポむント、ダンスポむントの高いほうから 3 人は 3 オヌディションポむント、ボヌカルポむントの高いほうから 3 人は 2 オヌディションポむントを獲埗したす。䞀方、ビゞュアルポむントが最䞋䜍だずオヌディションポむントは 1 点枛点、ダンスポむントが最䞋䜍だずオヌディションポむントは 1 点枛点、ボヌカルポむントが最䞋䜍だずオヌディションポむントは 1 点枛点ずなりたす。オヌディションポむントが1以䞋でもそこから 1 点枛点。 </p> <p>オヌディションの始めに、各アむドルのビゞュアルポむント、ダンスポむント、ボヌカルポむントはそれぞれ 0 です。あなたはアむドル 1 のプロデュヌサヌで、アピヌルタむムごずにどのアピヌルを行うか指瀺するこずが出来たす。アむドル 1 以倖のアむドルはアピヌルタむムごずにランダムに等確率にどれかのアピヌルを行いたす぀たりそれぞれ 3 分の 1 の確率で行われる。アむドル 1 のビゞュアル、ダンス、ボヌカルのポむントが他のアむドルず等しい堎合、アむドル 1 は垞に䞋䜍ずしたす。アむドル 1 の獲埗するオヌディションポむントの期埅倀が最倧になるように指瀺したずきの期埅倀を求めお䞋さい。アむドルの運呜は、あなたの指瀺にかかっおいたす </p> <p>ちなみに、指瀺はオヌディションが始たる前に党お行っお、その埌オヌディション䞭の指瀺の倉曎は出来ないものずしたす。぀たり、他のアむドルが、オヌディションが始たっおからのアピヌルでどのアピヌルをしかたを芋おから、その堎合においおの期埅倀が最倧ずなるような指瀺を出す、ずいうこずは出来ないものずしたす。 </p> <h2>Input</h2> <p>入力は以䞋の圢で䞎えられたす。 </p><blockquote> <var>n</var> <var>m</var><br><var>vi<sub>1</sub></var> <var>da<sub>1</sub></var> <var>vo<sub>1</sub></var><br><var>vi<sub>2</sub></var> <var>da<sub>2</sub></var> <var>vo<sub>2</sub></var><br>...<br><var>vi<sub>n</sub></var> <var>da<sub>n</sub></var> <var>vo<sub>n</sub></var><br></blockquote> <p>1行目にはオヌディションに出堎するアむドルの数 <var>n</var> (<var>4 &le; n &le; 2000</var>) ず、このオヌディションにおけるアピヌルタむムの数 <var>m</var> (<var>1 &le; m &le; 2000</var>) が曞いおありたす。次の <var>n</var> 行にはそれぞれアむドルiのビゞュアル倀 <var>vi<sub>i</sub></var>、ダンス倀 <var>da<sub>i</sub></var>、ボヌカル倀 <var>vo<sub>i</sub></var> (<var>1 &le; vi<sub>i</sub>, da<sub>i</sub>, vo<sub>i</sub> &le; 10,000</var>)が曞いおありたす。 </p> <h2>Output</h2> <p>アむドル 1 の獲埗するオヌディションポむントの期埅倀の最倧倀を 1 行で出力しなさい。 </p> <h2>Sample Input 1</h2> <pre>4 1 1 1 1 1 1 1 1 1 1 1 1 1 </pre> <h2>Output for the Sample Input 1</h2> <pre>2.777777777778 </pre> <p>どのアピヌルを行っおも、そのゞャンルで 3 䜍以内に入れる確率は等しいですが、 3 䜍以内に入った時に貰えるオヌディションポむントが最も倚いビゞュアルのアピヌルを行うのがもっずも期埅倀が良くなりたす。 </p> <h2>Sample Input 2</h2> <pre>4 10 1 1 1 10 10 10 10 10 10 10 10 10 </pre> <h2>Output for the Sample Input 2</h2> <pre>-2.335340954780 </pre> <p>非垞に厳しいオヌディションずなるでしょう。 </p> <h2>Sample Input 3</h2> <pre>9 9 13 5 19 19 21 37 15 1 7 7 11 15 21 23 25 33 29 19 13 19 11 21 5 15 7 13 1 </pre> <h2>Output for the Sample Input 3</h2> <pre>4.678837855075 </pre>
p03575
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an undirected connected graph with <var>N</var> vertices and <var>M</var> edges that does not contain self-loops and double edges.<br/> The <var>i</var>-th edge <var>(1 \leq i \leq M)</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>. </p> <p>An edge whose removal disconnects the graph is called a <em>bridge</em>.<br/> Find the number of the edges that are bridges among the <var>M</var> edges. </p> </section> </div> <div class="part"> <section> <h3>Notes</h3><ul> <li>A <em>self-loop</em> is an edge <var>i</var> such that <var>a_i=b_i</var> <var>(1 \leq i \leq M)</var>.</li> <li><em>Double edges</em> are a pair of edges <var>i,j</var> such that <var>a_i=a_j</var> and <var>b_i=b_j</var> <var>(1 \leq i&lt;j \leq M)</var>.</li> <li>An undirected graph is said to be <em>connected</em> when there exists a path between every pair of vertices.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 50</var></li> <li><var>N-1 \leq M \leq min(N(N−1)⁄2,50)</var></li> <li><var>1 \leq a_i&lt;b_i \leq N</var></li> <li>The given graph does not contain self-loops and double edges.</li> <li>The given graph is connected.</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>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 the edges that are bridges among the <var>M</var> edges.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 7 1 3 2 7 3 4 4 5 4 6 5 6 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The figure below shows the given graph:</p> <div style="text-align: center;"> <img alt="570677a9809fd7a5b63bff11e5d9bf79.png" src="https://img.atcoder.jp/abc075/570677a9809fd7a5b63bff11e5d9bf79.png"> </img></div> <p>The edges shown in red are bridges. There are four of them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 2 1 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>It is possible that there is no bridge.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 5 1 2 2 3 3 4 4 5 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre> <p>It is possible that every edge is a bridge.</p></section> </div> </span>
p03826
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are two rectangles. The lengths of the vertical sides of the first rectangle are <var>A</var>, and the lengths of the horizontal sides of the first rectangle are <var>B</var>. The lengths of the vertical sides of the second rectangle are <var>C</var>, and the lengths of the horizontal sides of the second rectangle are <var>D</var>.</p> <p>Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1≀A≀10^4</var></li> <li><var>1≀B≀10^4</var></li> <li><var>1≀C≀10^4</var></li> <li><var>1≀D≀10^4</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>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 2 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>15 </pre> <p>The first rectangle has an area of <var>3×5=15</var>, and the second rectangle has an area of <var>2×7=14</var>. Thus, the output should be <var>15</var>, the larger area.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 600 200 300 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>60000 </pre></section> </div> </span>
p02734
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are a sequence of <var>N</var> integers <var>A_1</var>, <var>A_2</var>, <var>\ldots</var>, <var>A_N</var> and a positive integer <var>S</var>.<br/> For a pair of integers <var>(L, R)</var> such that <var>1\leq L \leq R \leq N</var>, let us define <var>f(L, R)</var> as follows:<br/></p> <ul> <li><var>f(L, R)</var> is the number of sequences of integers <var>(x_1, x_2, \ldots , x_k)</var> such that <var>L \leq x_1 &lt; x_2 &lt; \cdots &lt; x_k \leq R</var> and <var>A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S</var>.</li> </ul> <p>Find the sum of <var>f(L, R)</var> over all pairs of integers <var>(L, R)</var> such that <var>1\leq L \leq R\leq N</var>. Since this sum can be enormous, print it modulo <var>998244353</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 3000</var></li> <li><var>1 \leq S \leq 3000</var></li> <li><var>1 \leq A_i \leq 3000</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>S</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>Print the sum of <var>f(L, R)</var>, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 2 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>The value of <var>f(L, R)</var> for each pair is as follows, for a total of <var>5</var>.</p> <ul> <li><var>f(1,1) = 0</var></li> <li><var>f(1,2) = 1</var> (for the sequence <var>(1, 2)</var>)</li> <li><var>f(1,3) = 2</var> (for <var>(1, 2)</var> and <var>(3)</var>)</li> <li><var>f(2,2) = 0</var></li> <li><var>f(2,3) = 1</var> (for <var>(3)</var>)</li> <li><var>f(3,3) = 1</var> (for <var>(3)</var>)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 8 9 9 9 9 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 3 1 4 1 5 9 2 6 5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>152 </pre></section> </div> </span>
p00709
<H1>Square Carpets</H1> <P> Mr. Frugal bought a new house. He feels deeply in love with his new house because it has a comfortable living room in which he can put himself completely at ease. He thinks his new house is a really good buy. </P> <P> But, to his disappointment, the floor of its living room has some scratches on it. </P> <P> The floor has a rectangle shape, covered with square panels. He wants to replace all the scratched panels with flawless panels, but he cannot afford to do so. Then, he decides to cover all the scratched panels with carpets. </P> <P> The features of the carpets he can use are as follows. </P> <OL> <LI> Carpets are square-shaped. <LI> Carpets may overlap each other. <LI> Carpets cannot be folded. <LI> Different sizes of carpets are available. Lengths of sides of carpets are multiples of that of the panels. </OL> <P> The carpets must cover all the scratched panels, but must not cover any of the flawless ones. </P> <P> For example, if the scratched panels are as shown in Figure 1, at least 6 carpets are needed. </P> <CENTER> <TABLE> <TR> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_carpets"></TD> </TR> <TR> <TD ALIGN="center">Figure 1: Example Covering</TD> </TR> </TABLE> </CENTER> <P> As carpets cost the same irrespective of their sizes, Mr. Frugal would like to use as few number of carpets as possible. </P> <P> Your job is to write a program which tells the minimum number of the carpets to cover all the scratched panels. </P> <H2>Input</H2> <P> The input consists of multiple data sets. As in the following, the end of the input is indicated by a line containing two zeros. </P> <BLOCKQUOTE> <I>DataSet</I><SUB>1</SUB><BR> <I>DataSet</I><SUB>2</SUB><BR> ...<BR> <I>DataSet</I><SUB><I>n</I></SUB><BR> <TT>0</TT> <TT>0</TT> </BLOCKQUOTE> <P> Each data set (<I>DataSet</I><SUB><I>i</I></SUB>) represents the state of a floor. The format of a data set is as follows. </P> <BLOCKQUOTE> <I>W</I> <I>H</I><BR> <I>P</I><SUB>11</SUB> <I>P</I><SUB>12</SUB> <I>P</I><SUB>13</SUB> ... <I>P</I><SUB>1<I>W</I></SUB><BR> <I>P</I><SUB>21</SUB> <I>P</I><SUB>22</SUB> <I>P</I><SUB>23</SUB> ... <I>P</I><SUB>2<I>W</I></SUB><BR> ...<BR> <I>P</I><SUB><I>H</I>1</SUB> <I>P</I><SUB><I>H</I>2</SUB> <I>P</I><SUB><I>H</I>3</SUB> ... <I>P</I><SUB><I>HW</I></SUB><BR> </BLOCKQUOTE> <P> The positive integers <I>W</I> and <I>H</I> are the numbers of panels on the living room in the x- and y- direction, respectively. The values of <I>W</I> and <I>H</I> are no more than 10. The integer <I>P</I><SUB><I>yx</I></SUB> represents the state of the panel. The value of <I>P</I><SUB><I>yx</I></SUB> means, </P> <BLOCKQUOTE> <TT>0</TT>: flawless panel (must not be covered),<BR> <TT>1</TT>: scratched panel (must be covered). </BLOCKQUOTE> <H2>Output</H2> <P> For each data set, your program should output a line containing one integer which represents the minimum number of the carpets to cover all of the scratched panels. </P> <H2>Sample Input</H2> <PRE> 4 3 0 1 1 1 1 1 1 1 1 1 1 1 8 5 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 8 8 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 10 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> 2 6 14 29 </PRE>
p02364
<H1>Minimum Spanning Tree</H1> <br/> <p> Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph <var>G</var> = (<var>V</var>, <var>E</var>). </p> <H2>Input</H2> <pre> <var>|V|</var> <var>|E|</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>w<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>w<sub>|E|-1</sub></var> </pre> <p> , where <var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively. </p> <p> <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target verticess of <var>i</var>-th edge (undirected) and <var>w<sub>i</sub></var> represents the weight of the <var>i</var>-th edge. </p> <H2>Output</H2> <p> Print the sum of the weights of the Minimum Spanning Tree. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>|V|</var> &le; 10,000</li> <li>0 &le; <var>|E|</var> &le; 100,000</li> <li>0 &le; <var>w<sub>i</sub></var> &le; 10,000</li> <li>The graph is connected</li> <li>There are no parallel edges</li> <li>There are no self-loops</li> </ul> <H2>Sample Input 1</H2> <pre> 4 6 0 1 2 1 2 1 2 3 1 3 0 1 0 2 3 1 3 5 </pre> <H2>Sample Output 1</H2> <pre> 3 </pre> <br/> <H2>Sample Input 2</H2> <pre> 6 9 0 1 1 0 2 3 1 2 1 1 3 7 2 4 1 1 4 3 3 4 1 3 5 1 4 5 6 </pre> <H2>Sample Output 2</H2> <pre> 5 </pre>
p00359
<H1>Dungeon</H1> <p> Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of <var>W &times; H</var> squares. Each square is identified with its column and row number, thus the square located in the <var>x</var>-th column and the <var>y</var>-th row is represented as (<var>x</var>, <var>y</var>). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (<var>W</var>-1, <var>H</var>-1). </p> <p> Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. </p> <ul> <li> One-square movement in the up, down, left, or right direction within the board</li> <li> Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom</li> </ul> <p> BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. </p> <p> Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>W</var> <var>H</var> <var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_N</var> <var>y_N</var> </pre> <p> The first line provides the number of squares in the horizontal direction <var>W</var> (1 &le; <var>W</var> &le; 10<sup>5</sup>), in the vertical direction <var>H</var> (1 &le; <var>H</var> &le; 10<sup>5</sup>), and the number of enemy characters <var>N</var> (1 &le; <var>N</var> &le; 10<sup>5</sup>). Each of the subsequent <var>N</var> lines provides location information of the <var>i</var>-th enemy, column <var>x_i</var> (0 &le; <var>x_i</var> &le; <var>W</var>-1) and row <var>y_i</var> (0 &le; <var>y_i</var> &le; <var>H</var>-1). The number of enemy characters in a specific square can be either one or zero. </p> <h2>Output</h2> <p> Output the minimum Cost in a line. </p> <h2>Sample Input 1</h2> <pre> 5 4 4 0 3 1 1 2 2 2 3 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 6 6 5 2 1 5 2 3 3 1 4 1 5 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre> <h2>Sample Input 3</h2> <pre> 8 8 4 6 0 7 0 0 6 0 7 </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p00477
<H1>合蚈時間 (Total Time)</H1> <h2>問題</h2> <p> 倪郎君は 3 カ所の店を蚪ねるこずを日課にしおいる家を出発し決たった順番で 3 カ所の店を回った埌家に垰るずきどきストップりォッチを䜿っお各区間を移動するのに䜕秒かかったかを蚈りその秒数を蚘録する </p> <p> ある日の蚈枬結果が䞎えられたずきこの日の移動時間の合蚈が䜕分䜕秒かを求めるプログラムを䜜成せよ </p> <h2>入力</h2> <p> 入力は 4 行からなり 1 行に 1 ぀ず぀正の敎数が曞かれおいる<br> 1 行目の敎数は家から 1 ぀目の店たでの移動時間を衚す秒数である<br> 2 行目の敎数は 1 ぀目の店から 2 ぀目の店たでの移動時間を衚す秒数である<br> 3 行目の敎数は 2 ぀目の店から 3 ぀目の店たでの移動時間を衚す秒数である<br> 4 行目の敎数は 3 ぀目の店から家たでの移動時間を衚す秒数であるただし䞎えられる入力デヌタにおいおは合蚈移動時間は 1 分 0 秒以䞊で 59 分 59 秒以䞋であるこずが保蚌されおいる<br> </p> <h2>出力</h2> <p> 出力は 2 行からなるx 分 y 秒 (1 &le; x &le; 59 , 0 &le; y &le; 59 )のずき 1行目に x を2行目に y を出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 31 34 7 151 </pre> <h3>出力䟋 1</h3> <pre> 3 43 </pre> <br> <h3>入力䟋 2</h3> <pre> 316 430 643 1253 </pre> <h3>出力䟋 2</h3> <pre> 44 2 </pre> <br> <h3>入力䟋 3</h3> <pre> 5 10 15 30 </pre> <h3>出力䟋 3</h3> <pre> 1 0 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div> <br>
p00027
<H1>What day is today?</H1> <p> Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29. </p> <H2>Input</H2> <p> The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset consists of two integers <var>m</var> and <var>d</var> separated by a single space in a line. These integers respectively represent the month and the day. </p> <p> The number of datasets is less than or equal to 50. </p> <H2>Output</H2> <p> For each dataset, print the day (please see the following words) in a line. </p> <pre> Monday Tuesday Wednesday Thursday Friday Saturday Sunday </pre> <H2>Sample Input</H2> <pre> 1 1 2 29 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Thursday Sunday </pre>
p01266
<H1><font color="#000">Problem H:</font> Robot Communication</H1> <p> In the year 21xx, human beings are proliferating across the galaxy. Since the end of the last century, thousands of pioneer spaceships have been launched in order to discover new habitation planets. </p> <p> The Presitener is one of those spaceships, heading toward the Andromeda galaxy. After a long, long cruise in the hyperspace, the crew have finally found a very hopeful candidate planet. The next thing to do is to investigate the planet whether it is really suitable for a new resident or not. </p> <p> For that purpose, the ship is taking some unattended landers. The captain Juclean Dripac decided to drop them to the planet and collect data about it. But unfortunately, these robots are a bit old and not so clever that the operator has to program what to do on the planet beforehand of the landing. Many staffs including you are called for making this important plan. </p> <p> The most complicated phase in the mission is to gather and integrate all the data collected independently by many robots. The robots need to establish all-to-all communication channels to exchange the data, once during the mission. That is, all the robots activate their communication channels all together at the predetermined time, and they exchange the data with each other at that time. </p> <p> They use wireless channels to communicate with each other, so the distance between robots does not limit the connectivity. But the farther two robots goes, the more power they have to use for communication. Due to the limitation of the battery capacity, you want to save the transmission power as much as possible. </p> <p> For a good thing, communication units of the robots also have the routing functionality, each robot only has to talk with the nearest robot. Suppose a graph whose vertices represent robots and edges represent communication channels established between them. If the graph is connected, all-to-all communication can be established. </p> <p> Your task is to write the program to calculate the minimum total transmission power required for all- to-all communication among the robots. Each robot moves linearly on the planet surface. Each pair of robots which communicate each other must occupy one channel, but you can assume enough number of channels are available. The transmission power required for two robots is proportional to the distance between them, so the cost here is exactly the sum of the distances between each pair of robots which establish a communication channel. </p> <p> You may also regard the planet surface as a two-dimensional surface, as it is huge enough. The time required for communicating data among robots are also negligible. </p> <H2>Input</H2> <p> The input contains multiple datasets. Each dataset has the format below. </p> <pre> <i>N T</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>vx</i><sub>1</sub> <i>vy</i><sub>1</sub> ... <i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub> <i>vx</i><sub><i>N</i></sub> <i>vy</i><sub><i>N</i></sub> </pre> <p> The first line of each dataset contains two integers; <i>N</i> is the number of robots used for gathering data (2 &le; <i>N</i> &le; 16), and <i>T</i> is the time limit of the mission (1 &le; <i>T</i> &lt; 1000). </p> <p> Each of the following <i>N</i> lines describes the motion of a robot. (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) and (<i>vx<sub>i</sub></i>, <i>vy<sub>i</sub></i> ) are the initial landing position and the velocity of the <i>i</i>-th robot, respectively (|<i>x<sub>i</sub></i>|, |<i>y<sub>i</sub></i>| &lt; 100000, |<i>vx<sub>i</sub></i>|, |<i>vy<sub>i</sub></i>| &lt; 1000). </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 in a line the minimum communication cost required for all-to-all communication. Your program may output an arbitrary number of digits after the decimal point. The absolute error should be less than or equal to 0.001. </p> <H2>Sample Input</H2> <pre> 4 2 2 0 0 1 0 4 1 0 4 6 0 -1 6 2 -1 0 4 6 2 0 0 1 0 4 1 0 4 6 0 -1 6 2 -1 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6.00000000 4.24264069 </pre>
p01636
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [['\\(','\\)']] } }); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> <h1 class="ndoc-heading1">Problem C: Mysterious Operator</h1> <p class="ndoc-top">ケヌ氏がい぀ものように某SNSを閲芧しおいるず、 「解ける人はIQ150以䞊ある」ずいう問題がタむムラむンに流れおきた。 ケヌ氏はIQが150以䞊あるので、芋るたでもなくその問題を䞀瞬で解いおしたった。 圌にしおみれば、このような問題なぞに頭を働かせる必芁は無い。 コンピュヌタに任せれば充分なのである。</p> <h2 class="ndoc-heading2">問題</h2> <p class="ndoc-top">問題には以䞋のような謎の数匏が曞かれおいた。</p> <ul class="ndoc-indent"> <li>\( 5 + 3 = 28 \)</li> <li>\( 9 + 1 = 810 \)</li> <li>\(8 + 6 = 214 \)</li> <li>\( 5 + 4 = 19 \)</li> <li>\( 2 + 2 = 4 \)</li> <li>\( 15 + 8 = 723 \)</li> <li>\( 7 + 9 = -216 \)</li> <li>\( 3 + 0 = 33 \)</li> </ul> <p>䞊蚘の挔算子\( + \)に぀いお考えた時、ある正敎数\( a \)に぀いお\( x \geq 0, y \geq 0 \)か぀\( x + y = a \)になるような敎数のペア\( x,y \)の個数を求めよ。</p> <h2 class="ndoc-heading2">入力</h2> <p class="ndoc-indent"> 正敎数\(a\)が䞀行で䞎えられる。 </p> <h2 class="ndoc-heading2">出力</h2> <p> \( a = x + y, x \geq 0, y \geq 0\)を満たすペア\((x,y)\)の個数を䞀行に出力せよ。 </p> <h2 class="ndoc-heading2">制玄</h2> <ul class="ndoc-indent"> <li>\( 1 \leq a \leq 10^9(= 1000000000) \)</li> </ul> <h2 class="ndoc-heading2">入出力䟋</h2> <h3 class="ndoc-heading3">入力1</h3> <pre> 19 </pre> <h3 class="ndoc-heading3">出力1</h3> <pre> 1 </pre> <p>\( 5 + 4 \)の1通りである。</p> <h3 class="ndoc-heading3">入力2</h3> <pre> 22 </pre> <h3 class="ndoc-heading3">出力2</h3> <pre> 2 </pre> <p>\( 11 + 11 \)ず、\( 2 + 0 \)の2通りが存圚する。</p> <h3 class="ndoc-heading3">入力3</h3> <pre> 1 </pre> <h3 class="ndoc-heading3">出力3</h3> <pre> 0 </pre> <p>\( 1 + 0 = 11 , 0 + 1 = -11 \)である。\( 1 \)は生成するこずができない。</p> <h3 class="ndoc-heading3">入力4</h3> <pre> 101 </pre> <h3 class="ndoc-heading3">出力4</h3> <pre> 0 </pre> <p>\( 1 - 0 \)は\( 101 \)ではないこずに泚意するこず。</p> <h3 class="ndoc-heading3">入力5</h3> <pre> 660233276 </pre> <h3 class="ndoc-heading3">出力5</h3> <pre> 4 </pre>
p00924
<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: Bit String Reordering </h2> <p> You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required. </p> <p> The initial bit string is simply represented by a sequence of bits, while the target is specified by a <i>run-length code</i>. The run-length code of a bit string is a sequence of the lengths of maximal consecutive sequences of zeros or ones in the bit string. For example, the run-length code of "011100" is "1 3 2". Note that there are two different bit strings with the same run-length code, one starting with zero and the other starting with one. The target is either of these two. </p> <p> In Sample Input 1, bit string "100101" should be reordered so that its run-length code is "1 3 2", which means either "100011" or "011100". At least four swaps are required to obtain "011100". On the other hand, only one swap is required to make "100011". Thus, in this example, 1 is the answer. </p> <h3>Input</h3> <p> The input consists of a single test case. The test case is formatted as follows. <br> <br> $N$ $M$<br> $b_1$ $b_2$ . . . $b_N$<br> $p_1$ $p_2$ . . . $p_M$<br> <br> The first line contains two integers $N$ ($1 \leq N \leq 15$) and $M$ ($1 \leq M \leq N$). The second line specifies the initial bit string by $N$ integers. Each integer $b_i$ is either 0 or 1. The third line contains the run-length code, consisting of $M$ integers. Integers $p_1$ through $p_M$ represent the lengths of consecutive sequences of zeros or ones in the bit string, from left to right. Here, $1 \leq p_j$ for $1 \leq j \leq M$ and $\sum^{M}_{j=1} p_j = N$ hold. It is guaranteed that the initial bit string can be reordered into a bit string with its run-length code $p_1, . . . , p_M$. </p> <h3>Output</h3> <p> Output the minimum number of swaps required </p> <h3>Sample Input 1</h3> <pre>6 3 1 0 0 1 0 1 1 3 2</pre> <h3>Sample Output 1</h3> <pre>1</pre> <h3>Sample Input 2</h3> <pre>7 2 1 1 1 0 0 0 0 4 3</pre> <h3>Sample Output 2</h3> <pre>12</pre> <h3>Sample Input 3</h3> <pre>15 14 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2</pre> <h3>Sample Output 3</h3> <pre>7</pre> <h3>Sample Input 4</h3> <pre>1 1 0 1</pre> <h3>Sample Output 4</h3> <pre>0</pre>
p02919
<span class="lang-en"> <p>Score: <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Given is a permutation <var>P</var> of <var>\{1, 2, \ldots, N\}</var>.</p> <p>For a pair <var>(L, R) (1 \le L \lt R \le N)</var>, let <var>X_{L, R}</var> be the second largest value among <var>P_L, P_{L+1}, \ldots, P_R</var>.</p> <p>Find <var>\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var> 2 \le N \le 10^5 </var></li> <li><var> 1 \le P_i \le N </var></li> <li><var> P_i \neq P_j </var> <var>(i \neq j)</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>P_1</var> <var>P_2</var> <var>\ldots</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print <var>\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p><var>X_{1, 2} = 2, X_{1, 3} = 2</var>, and <var>X_{2, 3} = 1</var>, so the sum is <var>2 + 2 + 1 = 5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>30 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 8 2 7 3 4 5 6 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>136 </pre></section> </div> </span>
p01323
<h1><font color="#000">Problem C:</font> コンパむル</h1> <p>東京倧孊に入孊したきたたさ君はTSG(東倧スヌパヌゲヌマヌズ)ずいうサヌクルに入った。</p> <p>このサヌクルは毎幎、駒堎祭でゲヌムを展瀺しおおり、きたたさ君もゲヌムを䜜成しお展瀺するこずにした。</p> <p>きたたさ君の䜜成するゲヌムは次のような、よくある萜ち物パズルゲヌムである。</p> <p> <ul> <li>暪6マス×瞊12マスの栌子状のフィヌルドがあり、各マスに぀き1個のブロックを眮くこずができる。</li> <li>䞊からブロックが2぀1組で萜䞋しおくる。ブロックには赀・緑・青・黄・玫の5色の基本ブロックずお邪魔ブロックの蚈6皮類がある。プレむダヌはブロックを回転、暪移動により操䜜し、萜䞋䜍眮を倉曎するこずができる。</li> <li>萜䞋しおきたブロックがフィヌルドの床やほかのブロックに衝突するず、その䜍眮にブロックが固定される。</li> <li>固定されたブロックず同色のブロックが呚囲4方向にある堎合、それらは互いにくっ぀く。ただし、お邪魔ブロックは互いにくっ぀かない。</li> <li>ブロックが4個以䞊くっ぀くず消滅し埗点ずなる。お邪魔ブロックの呚囲4方向に存圚する基本ブロックが消滅するず、そのお邪魔ブロックも䞀緒に消滅する。ブロックの消滅は、党おのブロックの萜䞋が終了したタむミングで同時に起こる。</li> <li>ブロックの消滅により、その䞊にあったブロックが萜䞋する。このブロックの萜䞋はプレむダヌが操䜜できない。このずき再びブロックが4個以䞊くっ぀くず消滅し、連鎖が起きる。ただし、耇数色を同時に消した堎合でも、1連鎖扱いずなる。</li> </ul> </p> <p>きたたさ君はこのゲヌムの倧郚分のプログラムを曞き終えたが、どうしおもブロックがくっ぀いお消滅したずきの凊理を曞くこずが出来なかった。そこでサヌクルの友人であるあなたにその郚分のプログラムを曞いおもらうこずにした。 </p> <h2>Input</h2> <p>入力は12行からなる。</p> <p>入力の <i>i</i> 行目は長さ6の文字列からなり、その <i>j</i> 文字目はフィヌルドの䞊から <i>i</i> 行目、巊から <i>j</i> 列目のマスの状態を衚しおいる。</p> <p>マスの状態を衚す文字は以䞋の7぀のうちのいずれかである。</p> <center> <table> <tr><th>文字</th><th>皮類</th></tr> <tr><td><span style="font-family: monospace">R</span></td><td>èµ€</td></tr> <tr><td><span style="font-family: monospace">G</span></td><td>緑</td></tr> <tr><td><span style="font-family: monospace">B</span></td><td>青</td></tr> <tr><td><span style="font-family: monospace">Y</span></td><td>黄</td></tr> <tr><td><span style="font-family: monospace">P</span></td><td>玫</td></tr> <tr><td><span style="font-family: monospace">O</span></td><td>お邪魔</td></tr> <tr><td><span style="font-family: monospace">.</span></td><td>空きマス</td></tr> </table> </center> <p>たた、入力に含たれる党おのブロックは床の䞊か他のブロックの䞊に乗っおいる。 </p> <h2>Output</h2> <p>入力の状態から、ルヌルに埓っおブロックを消しおいった時の連鎖数を蚈算し、䞀行で出力せよ。</p> <p>ブロックが䞀぀も消えない堎合は0ず出力せよ。 </p> <h2>Notes on Test Cases</h2> <p> 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。 </p> <p> 入力の1行目にデヌタセットの数Tが䞎えられたす。 </p> <p> 各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 </p> <!-- <h2>Sample Input 1</h2> <pre>...... ...... ...... ...... ...... ...... ...... ...... .RGB.. RGOP.. RGBPB. RGBPP. </pre> <h2>Output for Sample Input 1</h2> <pre>3 </pre> <h2>Sample Input 2</h2> <pre>GBRGYP GBRRYP BGGRBB BPRGYY GGPRRY BYPPRB YGGGPB GYYYPR YRBRBR YBRBRB BRBRBR BRBRBR </pre> <h2>Output for Sample Input 2</h2> <pre>18 </pre> <h2>Sample Input 3</h2> <pre>...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ..OO.. ..OO.. </pre> <h2>Output for Sample Input 3</h2> <pre>0 </pre> --> <h2>Sample Input </h2> <pre> 3 ...... ...... ...... ...... ...... ...... ...... ...... .RGB.. RGOP.. RGBPB. RGBPP. GBRGYP GBRRYP BGGRBB BPRGYY GGPRRY BYPPRB YGGGPB GYYYPR YRBRBR YBRBRB BRBRBR BRBRBR ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ..OO.. ..OO.. </pre> <h2>Output for Sample Input</h2> <pre> 3 18 0 </pre>
p01773
<h2>B: Cram School Schedule / 塟の時間割</h2> <h3>物語</h3> <p>あなたは塟の経営者であるあなたの塟は個人授業制で1人の生埒ず1人の先生で授業を行うこの塟の先生は非垞に優秀で科目にかかわらずすべおの授業を行うこずができるたた先生ず生埒は非垞にタフなので出垭できる授業には他の授業の出垭状況にかかわらずすべお出垭するこずが可胜である䟋えば同じ時間垯の授業に出垭できる2人の生埒ず4人の先生がいる堎合はその時間垯に2぀の授業を行える</p> <p>あなたは来月の授業予定を立おなくおはいけないが先生ず生埒の人数が倚いため予定を立おるのが非垞に倧倉であるたたあなたはできるだけ倚くの授業を行いたいず考えおいるそのためあなたは行える最倧の授業数を求めるプログラムを䜜るこずにした</p> <h3>問題</h3> <p>先生の人数ず生埒の人数それぞれの先生ず生埒の予定がない時間垯授業を行える時間垯が䞎えられるそれぞれの先生たたは生埒に぀いお予定がない時間垯が授業を行える時間垯を完党に被芆しおいるずきその先生たたは生埒はその授業に出垭できるそれぞれの授業を行える時間垯では出垭できる先生ず生埒からなるペアを耇数䜜り䜜ったペアの数だけの授業を同時に行うこずができるこのずきに行える最倧の授業数を求めよ</p> <h3>入力圢匏</h3> <p>入力デヌタの圢匏は以䞋のように䞎えられる</p> <pre> 授業が行える時間垯の情報 <var>n</var> 先生<var>1</var>の時間垯の情報 ... 先生<var>n</var>の時間垯の情報 <var>m</var> 生埒<var>1</var>の時間垯の情報 ... 生埒<var>m</var>の時間垯の情報 </pre> <p>最初の1行には授業を行える時間垯の情報が䞎えられる</p> <p>続く1行には先生の人数 <var>n</var> (<var>1 &le; n &le; 100</var>) が䞎えられる続く <var>n</var> 行の <var>i</var> 行目には <var>i</var> 番目の先生の予定がない時間垯の情報が䞎えられる</p> <p>続く1行には生埒の人数 <var>m</var> (<var>1 &le; m &le; 100</var>) が䞎えられる続く <var>m</var> 行の <var>i</var> 行目には <var>i</var> 番目の生埒の予定がない時間垯の情報が䞎えられる</p> <p>各々の時間垯の情報は次の圢匏で䞎えられる</p> <pre><var>k</var> <var>ah_1</var>:<var>am_1</var>-<var>bh_1</var>:<var>bm_1</var> <var> . . . </var> <var>ah_k</var>:<var>am_k</var>-<var>bh_k</var>:<var>bm_k</var></pre> <p>はじめに時間垯の数 <var>k</var> (<var>1 &le; k &le; 100</var>) が䞎えられ空癜区切りで <var>k</var> 個の時間垯が䞎えられる<var>i</var> 番目の時間垯は <var>ah_i</var>:<var>am_i</var>-<var>bh_i</var>:<var>bm_i</var> の圢匏で䞎えられ<var>ah_i</var>:<var>am_i</var> が開始時刻を衚し<var>bh_i</var>:<var>bm_i</var> が終了時刻を衚す<var>ah_i</var>, <var>am_i</var>, <var>bh_i</var>, <var>bm_i</var> はそれぞれ0詰め2桁で <var>0 &le; ah_i, bh_i &le; 23</var>, <var>0 &le; am_i, bm_i &le; 59</var> を満たす敎数である</p> <p>䞎えられるすべおの時間垯に぀いお開始時刻は終了時刻より真に早いたたそれぞれの時間垯の情報においお時間垯は早い時刻順に䞊んでおりどの終了時刻も1぀埌の時間垯の開始時刻より真に早い</p> <h3>出力圢匏</h3> <p>行える授業の最倧数を1行で出力せよ</p> <h3>入力䟋1</h3> <pre> 2 10:00-11:30 12:00-13:00 2 1 10:00-15:00 2 09:00-12:00 18:10-18:55 2 2 10:00-13:00 15:30-16:40 3 06:00-08:00 12:00-13:10 15:00-17:00 </pre> <h3>出力䟋1</h3> <pre>2</pre> <p>1぀目の時間垯ず2぀目の時間垯で1぀ず぀授業を行うこずで2回の授業を行うこずができる</p> <h3>入力䟋2</h3> <pre> 2 07:00-08:30 10:00-12:00 3 3 08:30-09:00 11:05-15:05 23:10-23:55 2 09:00-12:00 17:45-18:55 1 08:00-10:00 2 2 07:20-11:00 12:30-17:05 3 07:48-08:51 11:22-16:15 17:02-17:59 </pre> <h3>出力䟋2</h3> <pre>0</pre> <p>予定がない時間垯で07:00からの授業に間に合う先生ず生埒のペアが存圚しないので1぀目の時間垯は授業を行うこずができないたた2぀目の時間垯は2人目の先生が出垭できるが生埒は誰も出垭できないよっお2぀目の時間垯も授業を行うこずができないしたがっお行える最倧の授業数は0である</p>
p00861
<H1><font color="#000">Problem H:</font> Bug Hunt</H1> <p> In this problem, we consider a simple programming language that has only declarations of one- dimensional integer arrays and assignment statements. The problem is to find a bug in the given program. </p> <p> The syntax of this language is given in BNF as follows: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bugHunt"> </center> <p> where <span>&lt;</span><i>new line</i><span>&gt;</span> denotes a new line character (LF). </p> <p> Characters used in a program are alphabetical letters, decimal digits, <span>=</span>, <span>[</span>, <span>]</span> and new line characters. No other characters appear in a program. </p> <p> A declaration declares an array and specifies its length. Valid indices of an array of length <i>n</i> are integers between 0 and <i>n</i> - 1, inclusive. Note that the array names are case sensitive, i.e. array <span>a</span> and array <span>A</span> are different arrays. The initial value of each element in the declared array is undefined. </p> <p> For example, array <span>a</span> of length 10 and array <span>b</span> of length 5 are declared respectively as follows. </p> <pre> a[10] b[5] </pre> <p> An expression evaluates to a non-negative integer. A <span>&lt;</span><i>number</i><span>&gt;</span> is interpreted as a decimal integer. An <span>&lt;</span><i>array_name</i><span>&gt;</span> <span>[&lt;</span><i>expression</i><span>&gt;]</span> evaluates to the value of the <span>&lt;</span><i>expression</i><span>&gt;</span> -th element of the array. An assignment assigns the value denoted by the right hand side to the array element specified by the left hand side. </p> <p> Examples of assignments are as follows. </p> <pre> a[0]=3 a[1]=0 a[2]=a[a[1]] a[a[0]]=a[1] </pre> <p> A program is executed from the first line, line by line. You can assume that an array is declared once and only once before any of its element is assigned or referred to. </p> <p> Given a program, you are requested to find the following bugs. </p> <ul> <li> An index of an array is invalid.</li> <li> An array element that has not been assigned before is referred to in an assignment as an index of array or as the value to be assigned.</li> </ul> <p> You can assume that other bugs, such as syntax errors, do not appear. You can also assume that integers represented by <span>&lt;</span><i>number</i><span>&gt;</span>s are between 0 and 2<sup>31</sup> - 1 (= 2147483647), inclusive. </p> <H2>Input</H2> <p> The input consists of multiple datasets followed by a line which contains only a single '<span>.</span>' (period). Each dataset consists of a program also followed by a line which contains only a single '<span>.</span>' (period). A program does not exceed 1000 lines. Any line does not exceed 80 characters excluding a new line character. </p> <H2>Output</H2> <p> For each program in the input, you should answer the line number of the assignment in which the first bug appears. The line numbers start with 1 for each program. If the program does not have a bug, you should answer zero. The output should not contain extra characters such as spaces. </p> <H2>Sample Input</H2> <pre> a[3] a[0]=a[1] . x[1] x[0]=x[0] . a[0] a[0]=1 . b[2] b[0]=2 b[1]=b[b[0]] b[0]=b[1] . g[2] G[10] g[0]=0 g[1]=G[0] . a[2147483647] a[0]=1 B[2] B[a[0]]=2 a[B[a[0]]]=3 a[2147483646]=a[2] . . </pre> <H2>Output for the Sample Input</H2> <pre> 2 2 2 3 4 0 </pre>
p01289
<H1><font color="#000">Problem G:</font> Strange Couple</H1> <p> Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. </p> <p> The town they drive can be considered as an undirected graph with a number of intersections (vertices) and roads (edges). Each intersection may or may not have a sign. On intersections with signs, Alice and Bob will enter the road for the shortest route. When there is more than one such roads, they will go into one of them at random. </p> <p> On intersections without signs, they will just make a random choice. Each random selection is made with equal probabilities. They can even choose to go back to the road they have just come along, on a random selection. </p> <p> Calculate the expected distance Alice and Bob will drive before reaching the theater. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> <i>n s t</i><br> <i>q</i><sub>1</sub> <i>q</i><sub>2</sub> ... <i>q<sub>n</sub></i><br> <i>a</i><sub>11</sub> <i>a</i><sub>12</sub> ... <i>a</i><sub>1<i>n</i></sub><br> <i>a</i><sub>21</sub> <i>a</i><sub>22</sub> ... <i>a</i><sub>2<i>n</i></sub><br> .<br> .<br> .<br> <i>a</i><sub><i>n</i>1</sub> <i>a</i><sub><i>n</i>2</sub> ... <i>a</i><sub><i>nn</i></sub><br> </p> <p> <i>n</i> is the number of intersections (<i>n</i> &le; 100). <i>s</i> and <i>t</i> are the intersections the home and the theater are located respectively (1 &le; <i>s</i>, <i>t</i> &le; <i>n</i>, <i>s</i> &ne; <i>t</i>); <i>q<sub>i</sub></i> (for 1 &le; <i>i</i> &le; <i>n</i>) is either 1 or 0, where 1 denotes there is a sign at the <i>i</i>-th intersection and 0 denotes there is not; <i>a<sub>ij</sub></i> (for 1 &le; <i>i</i>, <i>j</i> &le; <i>n</i>) is a positive integer denoting the distance of the road connecting the <i>i</i>-th and <i>j</i>-th intersections, or 0 indicating there is no road directly connecting the intersections. The distance of each road does not exceed 10. </p> <p> Since the graph is undirectional, it holds <i>a<sub>ij</sub></i> = <i>a<sub>ji</sub></i> for any 1 &le; <i>i</i>, <i>j</i> &le; <i>n</i>. There can be roads connecting the same intersection, that is, it does <i>not</i> always hold <i>a<sub>ii</sub></i> = 0. Also, note that the graph is not always planar. </p> <p> The last dataset is followed by a line containing three zeros. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the expected distance accurate to 10<sup>-8</sup> , or "<span>impossible</span>" (without quotes) if there is no route to get to the theater. The distance may be printed with any number of digits after the decimal point. </p> <H2>Sample Input</H2> <pre> 5 1 5 1 0 1 0 0 0 2 1 0 0 2 0 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 8.50000000 </pre>
p00532
<h2>クリスマスパヌティヌ (Christmas Party)</h2> <h2> 問題</h2> <p> JOI 君は友達 1 から友達 N たでの N 人の友達を招いおクリスマスパヌティヌを行ったクリスマスパヌティヌも盛り䞊がっおきたずころで友達ず䞀緒に次のようなゲヌムを行うこずになった </p> <ol> <li> 最初に JOI 君は N 人の友達の䞭から 1 人を遞ぶ以降はその友達をタヌゲットず呌ぶこずにする </li> <li> JOI 君はタヌゲットずしお遞んだ友達にその人がタヌゲットであるこずをこっそり䌝えるタヌゲット以倖の友達は誰がタヌゲットかを知るこずはできない </li> <li> タヌゲット以倖の友達はそれぞれタヌゲットが誰かを予想しおその人の名前を玙に蚘入するタヌゲットは自分自身の名前を玙に蚘入する </li> <li> すべおの人の蚘入が終わった埌JOI 君はタヌゲットの名前を発衚する </li> <li> 予想が圓たった人は 1 点を埗るなおタヌゲットは自分自身の名前を玙に蚘入しおいるので必ず 1 点を埗る予想が倖れた人には埗点は䞎えられない </li> <li> それに加えお予想が倖れた人の人数を X 人ずしたずきタヌゲットは远加で X 点を埗る </li> </ol> <p> JOI 君たちはこのゲヌムを M 回行ったそれぞれの友達に察しおM 回のゲヌムにおける合蚈埗点を求めよ </p> <h2>入力</h2> <p> 入力は 3 + M 行からなる </p> <p> 1 行目には友達の人数 N (3 &le; N &le; 100) が曞かれおいる </p> <p> 2 行目にはJOI 君たちが行ったゲヌムの回数 M (3 &le; M &le; 100) が曞かれおいる </p> <p> 3 行目にはM 個の敎数 A<sub>1</sub>, A<sub>2</sub>, ..., A<sub>M</sub> が空癜を区切りずしお曞かれおいるこれはi 回目 (1 ≩ i ≩ M) のゲヌムのタヌゲットが友達 A<sub>i</sub> (1 &le; A<sub>i</sub> &le; N) であるこずを衚す </p> <p> 続く M 行のうちの i 行目 (1 ≩ i ≩ M) にはN 個の敎数 B<sub>i,1</sub>, B<sub>i,2</sub>, ..., B<sub>i,N</sub> が空癜を区切りずしお曞かれおいるこれはi 回目のゲヌムにおいお友達 j (1 &le; j &le; N) が友達 B<sub>i,j</sub> (1 &le; B<sub>i,j</sub> &le; N) の名前を玙に蚘入したこずを衚すタヌゲットは自分自身の名前を玙に蚘入するのでj = A<sub>i</sub> のずき垞に B<sub>i,j</sub> = j である </p> <h2>出力</h2> <p> それぞれの友達に察しおM 回のゲヌムにおける合蚈埗点を出力せよ出力は N 行からなるj 行目 (1 &le; j &le; N) に友達 j の合蚈埗点を出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 3 4 1 2 3 2 1 1 2 3 2 2 1 1 3 2 2 2 </pre> <h3>出力䟋 1</h3> <pre> 3 4 5 </pre> <h3>入力䟋 2</h3> <pre> 5 3 3 3 1 2 4 3 3 3 4 3 3 3 1 1 3 4 1 1 </pre> <h3>出力䟋 1</h3> <pre> 3 1 6 3 2 </pre> <p> 入出力䟋 1 では 3 人の友達が 4 回のゲヌムを行う </p> <ul> <li>1 回目のゲヌムのタヌゲットは友達 1 であり友達 1 は 2 点友達 2 は 1 点友達 3 は 0 点を埗る</li> <li>2 回目のゲヌムのタヌゲットは友達 2 であり友達 1 は 0 点友達 2 は 2 点友達 3 は 1 点を埗る</li> <li>3 回目のゲヌムのタヌゲットは友達 3 であり友達 1 は 0 点友達 2 は 0 点友達 3 は 3 点を埗る</li> <li>4 回目のゲヌムのタヌゲットは友達 2 であり友達 1 は 1 点友達 2 は 1 点友達 3 は 1 点を埗る</li> </ul> <p> 4 回のゲヌム終了埌の合蚈埗点は友達 1 は 3 点友達 2 は 4 点友達 3 は 5 点である </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00162
<H1>ハミング数</H1> <p> 1 に 2, 3, 5 を䜕回か (0 回以䞊) かけ算しお埗られる数をハミング数 (Hamming numbers) ず呌びたす。䟋えば、 </p> <ul> <li>1</li> <li>1 × 2 × 2 = 4</li> <li>1 × 2 × 2 × 3 × 5 × 5 = 300</li> </ul> <p> などはハミング数ですが、11, 13, 14 などはハミング数ではありたせん。 </p> <p> ハミング数はどれも 60 のべき乗を割り切る(䟋えば、54 は 60<sup>3</sup> = 21600 を割り切る) ので、時刻など 60 進法の蚈算には郜合の良い数ずしお昔から知られおいたした。たた、楜噚の調埋に甚いる音階の䞀぀である玔正埋では、音の呚波数の比が 24, 27, 30, 32, 36, 40, 45, 48 ずいうハミング数からなる数列になりたす。 </p> <p> 敎数 <var>m</var>、<var>n</var> を入力ずし、<var>m</var> 以䞊 <var>n</var> 以䞋のハミング数の個数を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 </p> <p> 各デヌタセットずしお、぀の敎数 <var>m</var> ず <var>n</var> (1 &le; <var>m</var>, <var>n</var> &le; 1000000, <var>m</var> &le; <var>n</var>) が空癜区切りで行に䞎えられたす。 </p> <p> デヌタセットの数は 20 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに <var>m</var> 以䞊 <var>n</var> 以䞋のハミング数の個数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 3 8 1 27 1 86 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 17 31 </pre>
p00498
<H1> JOI 囜のお祭り事情(Festivals in JOI Kingdom) </H1> <p> JOI 囜にはN 個の街がありそれらの間は<i>M</i> 本の双方向に通行可胜な道路で結ばれおいる囜民は道路を通っおそれらの街を移動する </p> <p> JOI 囜の囜民にはお祭りが奜きな人が倚く珟圚<i>K</i> 個の街でお祭りが開催されおおり非垞に賑わっおいる䞀方で䞀郚の囜民はお祭りを隒がしいずしお嫌いお祭りにできるだけ近づきたくないず思っおいる </p> <p> そこで囜王は優秀なプログラマヌであるあなたにそのようなお祭りを嫌う囜民のためある街からある街に移動するためにお祭りが開催されおいる街にどれだけ近づかずに移動するこずができるかを高速に調べるこずのできるプログラムの䜜成を䟝頌した </p> <h2>課題</h2> <p> 道路の情報ずお祭りが開催されおいる街の情報および<i>Q</i> 個のク゚リ出発する街<i>S<sub>i</sub></i> ず行きたい街<i>T<sub>i</sub></i>の組が䞎えられる各ク゚リ<i>i</i> に察し街<i>S<sub>i</sub></i> から街<i>T<sub>i</sub></i> ぞのすべおの経路のうちお祭りたでの距離が最倧ずなる経路のお祭りたでの距離を求めるプログラムを䜜成せよただしある経路のお祭りたでの距離ずは経路䞊の街からお祭りが開催されおいる街たでの移動距離の最小倀のこずである </p> <h2>制限</h2> <p> 2 &le; <i>N</i> &le; 100000 (= 10<sup>5</sup>) &nbsp;&nbsp;&nbsp;&nbsp;JOI 囜の街の個数<br> 1 &le; <i>M</i> &le; 200000 (= 2 &times; 10<sup>5</sup>) &nbsp;&nbsp;&nbsp;&nbsp;JOI 囜の道路の本数<br> 1 &le; <i>K</i> &le; <i>N</i> &nbsp;&nbsp;&nbsp;&nbsp;お祭りが開催されおいる街の個数<br> 1 &le; <i>Q</i> &le; 100000 (= 10<sup>5</sup>) &nbsp;&nbsp;&nbsp;&nbsp;ク゚リの個数<br> 1 &le; <i>L<sub>i</sub></i> &le; 1000 &nbsp;&nbsp;&nbsp;&nbsp;<i>i</i> 番目の道路の長さ<br> </p> <h2>入力</h2> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li> 1 行目には敎数<i>N</i>, <i>M</i>, <i>K</i>, <i>Q</i> が空癜を区切りずしお曞かれおいる<i>N</i> はJOI 囜の街の個数を<i>M</i> はJOI囜の道路の本数を<i>K</i> はお祭りが開催されおいる街の個数を<i>Q</i> はク゚リの個数をそれぞれ衚す街には1, 2, ... , <i>N</i> の番号が぀けられおいる </li> <li> 続く<i>M</i> 行は道路の情報を衚す<i>i</i> + 1 行目(1 &le; <i>i</i> &le; <i>M</i>) には敎数<i>A<sub>i</sub></i>, <i>B<sub>i</sub></i>, <i>L<sub>i</sub></i> (1 &le; <i>A<sub>i</sub></i> &le; <i>N</i>, 1 &le; <i>B<sub>i</sub></i> &le; <i>N</i>) が空癜を区切りずしお曞かれおいるこれは<i>i</i> 番目の道路が街<i>A<sub>i</sub></i> ず街<i>B<sub>i</sub></i> を結んでおり長さが<i>L<sub>i</sub></i> であるこずを衚す道路の䞡端が同じ街であるこずはないたた任意の2 ぀の街<i>p</i>, <i>q</i> に察し<i>p</i> ず<i>q</i>を結ぶ道路は2 本以䞊存圚しないどの街からどの街ぞもいく぀かの道路をたどっお行くこずができる</li> <li> 続く<i>K</i> 行はお祭りが開催されおいる街の情報を衚す<i>i</i> + <i>M</i> + 1 行目(1 &le; <i>i</i> &le; <i>K</i>) には1 ぀の敎数<i>F<sub>i</sub></i>(1 &le; <i>F<sub>i</sub></i> &le; <i>N</i>) が曞かれおいるこれは街<i>F<sub>i</sub></i> でお祭りが開催されおいるこずを衚す<i>F</i><sub>1</sub>, ..., <i>F<sub>K</sub></i> の䞭に同じ倀が2 回以䞊珟れるこずはない </li> <li> 続く<i>Q</i> 行はク゚リを衚す<i>i</i> + <i>M</i> + <i>K</i> + 1 行目(1 &le; <i>i</i> &le; <i>Q</i>) には2 ぀の敎数<i>S<sub>i</sub></i>, <i>T<sub>i</sub></i> (1 &le; <i>S<sub>i</sub></i> &le; <i>N</i>, 1 &le; <i>T<sub>i</sub></i> &le; <i>N</i>, <i>S<sub>i</sub></i> &ne; <i>T<sub>i</sub></i>) が空癜を区切りずしお曞かれおいるこれは<i>i</i> 番目のク゚リの出発する街が<i>S<sub>i</sub></i> であり行きたい街が<i>T<sub>i</sub></i> であるこずを衚す</li> </ul> <h2>出力</h2> <p> 暙準出力に党ク゚リぞの答えを<i>Q</i> 行で出力せよすなわち<i>i</i> 行目に街<i>S<sub>i</sub></i> から街<i>T<sub>i</sub></i> ぞのすべおの経路のうちお祭りたでの距離が最倧ずなる経路のお祭りたでの距離を衚す敎数を出力せよ </p> <h2>採点基準</h2> <p> 採点甚デヌタのうち<br> 配点の10% 分に぀いおは<i>Q</i> = 1 を満たす<br> 配点の20% 分に぀いおは<i>N</i> &le; 5000, <i>Q</i> &le; 5000 を満たす<br> 配点の30% 分に぀いおはこれら2 ぀の条件の少なくずも䞀方を満たすたたこれら2 ぀の条件の䞡方を満たすような採点甚デヌタはない </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 6 6 2 3 1 2 5 2 3 4 2 4 6 3 5 9 4 5 3 5 6 7 1 6 3 4 5 2 1 4 </pre> <h3>出力䟋 1</h3> <pre> 7 5 0 </pre> <p> 6 ぀の街が6 本の道路で結ばれおおりお祭りは街1, 6 の2 ぀の街で開催されおいるク゚リは以䞋の3 ぀である </p> <ul> <li> 1 ぀目のク゚リは街3 から街4 ぞ行くずいうものである街2 を経由する経路ではお祭りたでの距離は5街5 を経由する経路ではお祭りたでの距離は7 ずなるため答えは7 である </li> <li> 2 ぀目のク゚リは街5 から街2 ぞ行くずいうものである街3 ず街4 のどちらを経由しおも街2 でお祭りたでの距離が最小ずなり答えは5 である </li> <li> 3 ぀目のク゚リは街1 から街4 ぞ行くずいうものである街1 はお祭りが開催されおいる街であるため答えは0 ずなる </li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_festivalsInJOIKingdom1"><br> <b> 図1: 入力䟋1 </b> </center> <br> <h3>入力䟋 2</h3> <pre> 12 17 2 5 1 3 6 1 6 7 2 3 8 2 4 4 2 8 11 2 12 2 3 6 3 3 7 8 3 11 2 4 12 2 5 10 3 6 10 5 8 9 6 8 12 7 9 10 6 11 9 10 12 9 5 8 7 2 6 5 2 1 10 8 9 9 4 </pre> <h3>出力䟋 2</h3> <pre> 8 8 11 0 6 </pre> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_festivalsInJOIKingdom2"><br> <b> 図1: 入力䟋2 </b> </center> <br> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p03467
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider the following set of rules for encoding strings consisting of <code>0</code> and <code>1</code>:</p> <ul> <li>Strings <code>0</code> and <code>1</code> can be encoded as <code>0</code> and <code>1</code>, respectively. </li> <li>If strings <var>A</var> and <var>B</var> can be encoded as <var>P</var> and <var>Q</var>, respectively, then string <var>AB</var> can be encoded as <var>PQ</var>.</li> <li>If string <var>A</var> can be encoded as <var>P</var> and <var>K \geq 2</var> is a positive integer, then string <var>AA...A</var> (<var>A</var> repeated <var>K</var> times) can be encoded as <code>(</code><var>P</var><code>x</code><var>K</var><code>)</code>.</li> </ul> <p>For example, string <code>001001001</code>, among other possibilities, can be encoded as <code>001001001</code>, <code>00(1(0x2)x2)1</code> and <code>(001x3)</code>.</p> <p>Let's call string <var>A</var> a subset of string <var>B</var> if:</p> <ul> <li><var>A</var> and <var>B</var> are equal in length and consist of <code>0</code> and <code>1</code>;</li> <li>for all indices <var>i</var> such that <var>A_i</var> = <code>1</code>, it's also true that <var>B_i</var> = <code>1</code>.</li> </ul> <p>You are given string <var>S</var> consisting of <code>0</code> and <code>1</code>. Find the total number of distinct encodings of all subsets of <var>S</var>, modulo <var>998244353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 100</var></li> <li><var>S</var> consists of <code>0</code> and <code>1</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 total number of distinct encodings of all subsets of <var>S</var> modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>011 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>There are four subsets of <var>S</var>:</p> <ul> <li><code>011</code> can be encoded as <code>011</code> and <code>0(1x2)</code>;</li> <li><code>010</code> can be encoded as <code>010</code>;</li> <li><code>001</code> can be encoded as <code>001</code> and <code>(0x2)1</code>;</li> <li><code>000</code> can be encoded as <code>000</code>, <code>0(0x2)</code>, <code>(0x2)0</code> and <code>(0x3)</code>.</li> </ul> <p>Thus, the total number of encodings of all subsets of <var>S</var> is <var>2 + 1 + 2 + 4 = 9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> <p>This time <var>S</var> has only one subset, but it can be encoded in <var>10</var> different ways.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>101110 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>156 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>001110111010110001100000100111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>363383189 </pre> <p>Don't forget to take the result modulo <var>998244353</var>.</p></section> </div> </span>
p03037
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> ID cards, and there are <var>M</var> gates.</p> <p>We can pass the <var>i</var>-th gate if we have one of the following ID cards: the <var>L_i</var>-th, <var>(L_i+1)</var>-th, ..., and <var>R_i</var>-th ID cards.</p> <p>How many of the ID cards allow us to pass all the gates alone?</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 10^5</var></li> <li><var>1 \leq M \leq 10^5</var></li> <li><var>1 \leq L_i \leq R_i \leq N</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>L_1</var> <var>R_1</var> <var>L_2</var> <var>R_2</var> <var>\vdots</var> <var>L_M</var> <var>R_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ID cards that allow us to pass all the gates alone.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 1 3 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Two ID cards allow us to pass all the gates alone, as follows:</p> <ul> <li>The first ID card does not allow us to pass the second gate.</li> <li>The second ID card allows us to pass all the gates.</li> <li>The third ID card allows us to pass all the gates.</li> <li>The fourth ID card does not allow us to pass the first gate.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 3 3 6 5 7 6 9 </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>100000 1 1 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>100000 </pre></section> </div> </span>
p02276
<H1>Partition</H1> <!-- <p style="color:#f00"> Please note that problem description and judge data for this problem are still under construction. They may revised and your submissions can be rejudged. </p> --> <p> Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q. </p> <p> In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r). </p> <p> Your task is to read a sequence A and perform the Partition based on the following pseudocode: </p> <pre> Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 </pre> </p> Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r]. </p> <H2>Input</H2> <p> The first line of the input includes an integer <i>n</i>, the number of elements in the sequence A. </p> <p> In the second line, <i>A<sub>i</sub></i> (<i>i</i> = 1,2,...,<i>n</i>), elements of the sequence are given separated by space characters. </p> <H2>Output</H2> <p> Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. The element which is selected as the pivot of the partition should be indicated by <span>[</span>&nbsp;&nbsp;<span>]</span>. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>n</i> &le; 100,000</li> <li>0 &le; <i>A<sub>i</sub></i> &le; 100,000</li> </ul> <H2>Sample Input 1</H2> <pre> 12 13 19 9 5 12 8 7 4 21 2 6 11 </pre> <H2>Sample Output 1</H2> <pre> 9 5 8 7 4 2 6 [11] 21 13 19 12 </pre>
p01909
<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>E: 卒業匏</h1> <h2>背景</h2> <p> ある日 Y さんはプログラミングコンテストに参加するため䌚堎がある倧孊に向かいたした ずころが倧孊に着くず人がたくさんなんず今日は卒業匏だったのです 䌚堎に向かおうにも人に抌し流されおしたい自分の進みたい方向に進むこずすらできたせん 人混みから抜け出すためにY さんは今いる堎所から少しでも遠くに行きたいず考えたした そこで Y さんは状況を以䞋のような問題ずしお定匏化し競技プログラミングを圹に立おるこずにしたした </p> <p> なお以䞋の問題文では Y さんは点 $P$ ずしおモデル化されおいたす </p> <h2>問題</h2> <p> 座暙平面䞊の原点に点 $P$ が眮かれおいる 点 $P$ を動かしできるだけ原点からのマンハッタン距離が遠い䜍眮に移動させたい </p> <p> はじめに文字列 $S = s_1s_2 \cdots s_{|S|}$ ($|S|$ は $S$ の文字数) が䞎えられる 点 $P$ の移動は文字列 $S$ の先頭から文字を 1 文字ず぀読み蟌むこずで行う 文字列 $S$ は文字 'U', 'L', 'D', 'R' からなる それぞれの文字を読み蟌んだずき点 $P$ の移動前の座暙を $(x, y)$ ずするず 移動埌の点 $P$ の座暙はそれぞれ $(x, y+1),\ (x-1, y),\ (x, y-1),\ (x+1, y)$ ずなる </p> <p> 各文字を読み蟌む盎前に魔法をかけるか吊かを遞択するこずができる 魔法には魔法 1 ず魔法 2 の二皮類がある文字列 $S$ の $i$ 番目の文字を $s_i$ ずするず $s_i$ を読み蟌む盎前に魔法をかけたずきの倉化は以䞋の通りである </p> <ul> <li>魔法 1 をかけたずき: 党おの $s_j \ (i \le j \le |S|)$ に察し'U' を 'D' に'D' を 'U' に眮換する</li> <li>魔法 2 をかけたずき: 党おの $s_j \ (i \le j \le |S|)$ に察し'L' を 'R' に'R' を 'L' に眮換する</li> </ul> <p> 盎感的には魔法 1 ではその埌の䞊䞋の扱いを反転させるこずができ魔法 2 では巊右の扱いを反転させるこずができる ある文字を読み蟌む前にかける魔法の回数は耇数回でも構わないたた䞡方の魔法を続けおかけおもかたわない ただし文字列 $S$ の文字をすべお読み終えるたでに魔法をかけられる回数は合蚈 $K$ 回たでである 詳现はサンプルを参照されたい </p> <p> 文字列 $S$ の文字をすべお読み終えた埌の点 $P$ の座暙を $(x',y')$ ずするずき$|x'| + |y'|$ の最倧倀を求めよ </p> <h2>制玄</h2> <ul> <li>$1 \le |S| \le 2000$</li> <li>$1 \le K \le 2000$</li> </ul> <h2>入力</h2> <p> 入力は以䞋の圢匏で暙準入力から䞎えられる </p> <p> $S$<br> $K$ </p> <h2>出力</h2> <p> $|x'| + |y'|$ の最倧倀を 1 行で出力せよたた、末尟に改行も出力せよ. </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> RRLUDDD 2 </pre> <h3>サンプル出力 1</h3> <pre> 7 </pre> <p> 3 文字目を読み蟌む盎前に魔法 2 をかけるず文字列 $S$ は "RRRUDDD" ずなる 続いお 5 文字目を読み蟌む盎前に魔法 1 をかけるず文字列 $S$ は "RRRUUUU" ずなる すべおの文字を読み終えた埌の点 $P$ の座暙は $(3, 4)$ ずなり 原点からのマンハッタン距離は 7 であるこれはこの䟋の最倧倀である </p> <h3>サンプル入力 2</h3> <pre> LULLLUULLU 1984 </pre> <h3>サンプル出力 2</h3> <pre> 10 </pre> <p> 1 回も魔法をかけなかった堎合$x’ = -6, \ y’ = 4$ ずなり$|x’| + |y’| = 10$ である </p> <h3>サンプル入力 3</h3> <pre> DRDLUDD 1 </pre> <h3>サンプル出力 3</h3> <pre> 5 </pre> <h3>サンプル入力 4</h3> <pre> LURRRLUDLL 1 </pre> <h3>サンプル出力 4</h3> <pre> 6 </pre>
p03934
<span class="lang-en lang-child hidden-lang"> <div id="task-statement"> <div class="part"> Max Score: $1200$ Points <br/> <section> <h3>Problem statement</h3> There are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$. <br/> A sushi chef carried out $Q$ operations for customers. <br/> <br/> The $i$-th operation is follows: <br/> <ol class="simple"> <li>The sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers. </li> <li>He puts a dish of sushi on the selected seats.</li> <li>A customer who have selected for professional eats this sushi.</li> <li>Repeat 1-3, $b_i$ times.</li> </ol> <br/> Please calculate the number of dishes of sushi that have been eaten by each customer.<br/> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> The input is given from Standard Input in the following format: <br/> <blockquote>$N \ Q$ $a_1 \ b_1$ $a_2 \ b_2$ $  \  $ $a_Q \ b_Q$ </blockquote> </section> </div> <div class="part"> <section> <h3>Output</h3> <ul> <li>You have to print $N$ lines.</li> <li>The $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \le i \le N)$.</li> </ul> </section> <section> <h3>Constraints</h3> <ul> <li>$3 \le N, Q \le 100,000$</li> <li>$1 \le a_i \le N$</li> <li>$1 \le b_i \le 10^{12}$</li> <li>Any final results do not exceed $2 \times 10^{13}$.</li> </ul> </section> <section> <h3>Subtasks</h3> Subtask 1 [ $60$ points ] <br/> <ul> <li>$N, Q \le 100$</li> <li>$b_i = 1$</li> </ul> Subtask 2 [ $400$ points ] <br/> <ul> <li>$N, Q \le 100$</li> <li>$b_i \le 10^{12}$</li> </ul> Subtask 3 [ $240$ points ] <br/> <ul> <li>$N, Q \le 100,000$</li> <li>$b_i = 1$</li> </ul> Subtask 4 [ $500$ points ] <br/> <ul> <li>There are no additional constraints.</li> </ul> </section> </div> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 9 3 5 11 8 4 4 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 4 4 4 4 2 2 1 1 0 </pre> The change of the number of dishes of sushi have eaten is following: <br/> <br/> <table class="table-striped table-bordered table-condensed"> <tr align="center"> <th></th> <td width="90">Customer 1</td> <td width="90">Customer 2</td> <td width="90">Customer 3</td> <td width="90">Customer 4</td> <td width="90">Customer 5</td> <td width="90">Customer 6</td> <td width="90">Customer 7</td> <td width="90">Customer 8</td> <td width="90">Customer 9</td> </tr> <tr align="center"> <th>1st Operation</th> <td>3</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> </tr> <tr align="center"> <th>2nd Operation</th> <td>3</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>1</td> <td>1</td> <td>0</td> </tr> <tr align="center"> <th>3rd Operation</th> <td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>2</td> <td>2</td> <td>1</td> <td>1</td> <td>0</td> </tr> </table> <br/> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 6 6 3 5 6 11 1 6 4 7 5 2 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 10 10 5 5 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Input 3</h3> <pre> 5 6 1 1 2 1 3 1 1 1 5 1 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3> <pre> 2 2 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Input 4</h3> <pre> 10 10 10 10 9 20 8 30 7 40 6 50 5 60 4 70 3 80 2 90 1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3> <pre> 223 123 77 50 33 21 12 7 3 1 </pre> </section> </div> Writer: E869120 <br/> </div> </span>
p02626
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> piles of stones. The <var>i</var>-th pile has <var>A_i</var> stones.</p> <p>Aoki and Takahashi are about to use them to play the following game:</p> <ul> <li>Starting with Aoki, the two players alternately do the following operation:<ul> <li>Operation: Choose one pile of stones, and remove one or more stones from it.</li> </ul> </li> <li>When a player is unable to do the operation, he loses, and the other player wins.</li> </ul> <p>When the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.</p> <p>In such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most <var>(A_1 - 1)</var> stones from the <var>1</var>-st pile to the <var>2</var>-nd pile before the game begins.</p> <p>If this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print <code>-1</code> instead.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 300</var></li> <li><var>1 \leq A_i \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>N</var> <var>A_1</var> <var>\ldots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of stones to move to guarantee Takahashi's win; otherwise, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Without moving stones, if Aoki first removes <var>2</var> stones from the <var>1</var>-st pile, Takahashi cannot win in any way.</p> <p>If Takahashi moves <var>1</var> stone from the <var>1</var>-st pile to the <var>2</var>-nd before the game begins so that both piles have <var>4</var> stones, Takahashi can always win by properly choosing his actions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>It is not allowed to move stones from the <var>2</var>-nd pile to the <var>1</var>-st.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre> <p>It is not allowed to move all stones from the <var>1</var>-st pile.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 10 9 8 7 6 5 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>3 4294967297 8589934593 12884901890 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>1 </pre> <p>Watch out for overflows.</p></section> </div> </span>
p02333
<!--<h1>写像12盾 その3:ボヌルに区別あり・箱に区別あり・箱の䞭身は1぀以䞊</h1>--> <h1>Balls and Boxes 3</h1> <table border=""> <tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr> <tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td style="background-color:#aff">3</td></tr> <tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr> <tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr> <tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr> </table> <h2>Problem</h2> <p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p> <p>Find the number of ways to put the balls under the following conditions:</p> <ul> <li>Each ball is distinguished from the other.</li> <li>Each box is distinguished from the other.</li> <li>Each ball can go into only one box and no one remains outside of the boxes.</li> <li>Each box must contain at least one ball.</li> </ul> <p>Note that you must print this count modulo $10^9+7$.</p> <h2>Input</h2> <pre> $n$ $k$ </pre> <p>The first line will contain two integers $n$ and $k$.</p> <h2>Output</h2> <p>Print the number of ways modulo $10^9+7$ in a line.</p> <h2>Constraints</h2> <ul> <li>$1 \le n \le 1000$</li> <li>$1 \le k \le 1000$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 3 </pre> <h2>Sample Output 1</h2> <pre> 36 </pre> <h2>Sample Input 2</h2> <pre> 10 3 </pre> <h2>Sample Output 2</h2> <pre> 55980 </pre> <h2>Sample Input 3</h2> <pre> 100 100 </pre> <h2>Sample Output 3</h2> <pre> 437918130 </pre>
p02299
<H1>Polygon-Point-Containment</H1> <br/> <p> For a given polygon <var>g</var> and target points <var>t</var>, print "2" if <var>g</var> contains <var>t</var>, "1" if <var>t</var> is on a segment of <var>g</var>, "0" otherwise. </p> <p> <var>g</var> is represented by a sequence of points <var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>,..., <var>p<sub>n</sub></var> where line segments connecting <var>p<sub>i</sub></var> and <var>p<sub>i+1</sub></var> (1 &le; <var>i</var> &le; <var>n-1</var>) are sides of the polygon. The line segment connecting <var>p<sub>n</sub></var> and <var>p<sub>1</sub></var> is also a side of the polygon. </p> <p> Note that the polygon is not necessarily convex. </p> <H2>Input</H2> <p> The entire input looks like: </p> <pre> <var>g</var> (the sequence of the points of the polygon) <var>q</var> (the number of queris = the number of target points) 1st query 2nd query : <var>q</var>th query </pre> <p> <var>g</var> is given by coordinates of the points <var>p<sub>1</sub></var>,..., <var>p<sub>n</sub></var> in the following format: </p> <pre> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <p> The first integer <var>n</var> is the number of points. The coordinate of a point <var>p<sub>i</sub></var> is given by two integers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. The coordinates of points are given in the order of counter-clockwise visit of them. </p> <p> Each query consists of the coordinate of a target point <var>t</var>. The coordinate is given by two intgers <var>x</var> and <var>y</var>. </p> <H2>Output</H2> <p> For each query, print "2", "1" or "0". </p> <H2>Constraints</H2> <ul> <li> 3 &le; <var>n</var> &le; 100 </li> <li> 1 &le; <var>q</var> &le; 1000 </li> <li> -10000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 10000 </li> <li>No point of the polygon will occur more than once.</li> <li>Two sides of the polygon can intersect only at a common endpoint.</li> </ul> <H2>Sample Input</H2> <pre> 4 0 0 3 1 2 3 0 3 3 2 1 0 2 3 2 </pre> <H2>Sample Output</H2> <pre> 2 1 0 </pre> <br/>
p03871
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>There are two (6-sided) dice: a red die and a blue die. When a red die is rolled, it shows <var>i</var> with probability <var>p_i</var> percents, and when a blue die is rolled, it shows <var>j</var> with probability <var>q_j</var> percents.</p> <p>Petr and tourist are playing the following game. Both players know the probabilistic distributions of the two dice. First, Petr chooses a die in his will (without showing it to tourist), rolls it, and tells tourist the number it shows. Then, tourist guesses the color of the chosen die. If he guesses the color correctly, tourist wins. Otherwise Petr wins.</p> <p>If both players play optimally, what is the probability that tourist wins the game?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≀ p_i, q_i ≀ 100</var></li> <li><var>p_1 + ... + p_6 = q_1 + ... + q_6 = 100</var></li> <li>All values in the input are integers.</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>p_1</var> <var>p_2</var> <var>p_3</var> <var>p_4</var> <var>p_5</var> <var>p_6</var> <var>q_1</var> <var>q_2</var> <var>q_3</var> <var>q_4</var> <var>q_5</var> <var>q_6</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the probability that tourist wins. The absolute error or the relative error must be at most <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>25 25 25 25 0 0 0 0 0 0 50 50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1.000000000000 </pre> <p>tourist can always win the game: If the number is at most <var>4</var>, the color is definitely red. Otherwise the color is definitely blue.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 20 20 10 20 20 20 20 20 10 10 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0.550000000000 </pre></section> </div> </span>
p02763
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>N</var> consisting of lowercase English letters.</p> <p>Process <var>Q</var> queries of the following two types:</p> <ul> <li>Type <var>1</var>: change the <var>i_q</var>-th character of <var>S</var> to <var>c_q</var>. (Do nothing if the <var>i_q</var>-th character is already <var>c_q</var>.)</li> <li>Type <var>2</var>: answer the number of different characters occurring in the substring of <var>S</var> between the <var>l_q</var>-th and <var>r_q</var>-th characters (inclusive).</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var>, <var>Q</var>, <var>i_q</var>, <var>l_q</var>, and <var>r_q</var> are integers.</li> <li><var>S</var> is a string consisting of lowercase English letters.</li> <li><var>c_q</var> is a lowercase English letter.</li> <li><var>1 \leq N \leq 500000</var></li> <li><var>1 \leq Q \leq 20000</var></li> <li><var>|S| = N</var></li> <li><var>1 \leq i_q \leq N</var></li> <li><var>1 \leq l_q \leq r_q \leq N</var></li> <li>There is at least one query of type <var>2</var> in each testcase.</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</var> <var>Q</var> <var>Query_1</var> <var>\vdots</var> <var>Query_Q</var> </pre> <p>Here, <var>Query_i</var> in the <var>4</var>-th through <var>(Q+3)</var>-th lines is one of the following:</p> <pre><var>1</var> <var>i_q</var> <var>c_q</var> </pre> <pre><var>2</var> <var>l_q</var> <var>r_q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query of type <var>2</var>, print a line containing the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 abcdbbd 6 2 3 6 1 5 z 2 1 1 1 4 a 1 7 d 2 1 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 1 5 </pre> <p>In the first query, <code>cdbb</code> contains three kinds of letters: <code>b</code> , <code>c</code> , and <code>d</code>, so we print <var>3</var>.</p> <p>In the second query, <var>S</var> is modified to <code>abcdzbd</code>.</p> <p>In the third query, <code>a</code> contains one kind of letter: <code>a</code>, so we print <var>1</var>.</p> <p>In the fourth query, <var>S</var> is modified to <code>abcazbd</code>.</p> <p>In the fifth query, <var>S</var> does not change and is still <code>abcazbd</code>.</p> <p>In the sixth query, <code>abcazbd</code> contains five kinds of letters: <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, and <code>z</code>, so we print <var>5</var>.</p></section> </div> </span>