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> 1行目に探査レーダによって測定されたデータの数 <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) が与えられる。観測点が同じ観測データが2つ以上与えられることもある。 </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> 三目並べは,3 &times; 3のマス目の中に交互に ○ と × を入れていき、縦・横・斜めの何れかに一列 ○ か × が並んだときに、勝ちとなるゲームです(図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>図1:○の勝ち</td> <td>図2:× の勝ち</td> <td>図3:引き分け</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>図4:ありえない局面</td> </tr> </table> </center> <br/> <p> 三目並べの盤面を読み込んで、勝敗の結果を出力するプログラムを作成して下さい。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、盤面を表す1つの文字列が1行に与えられます。 盤面の文字列は、○、×、空白をそれぞれ半角英小文字の 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 を1行に出力してください。 </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> 図1に例示するように整数(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> 入力例に示すように、カンマで区切られた整数の並びが、ひし形状に与えられます。各行に空白文字は含まれません。入力例は図1に対応しています。 データの行数は 100 行未満です。 </p> <H2>Output</H2> <p> ルールに従って通過する整数の和の最大値を1行に出力します。 </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 を1行に出力してください。 </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 - 7歳教</h2> <p>7歳の誕生日に"彼"は父から告げられた.</p> <p>「お前が7歳になったということは,私はもう引退だ.今日からお前が7歳教の長だ.<br> 7歳教の戒律により,7歳教の長が7歳の間だけ布教活動を行うことが認められている.<br> この宇宙船を使って,よりたくさんの人々に7歳教の素晴らしさを広めてきなさい.」 </p> <p> 7歳教をよりたくさんの人に広めるために"彼"は,自分の周りの星についての情報を集めた.<br> "彼"の星の周りには,<var>n</var> 個の惑星があり,惑星は <var> 1, ... , n</var> で番号付けされていることがわかった.<br> 惑星<var>i</var> から 惑星<var>j</var>の間を移動するには,<var>w_i_j</var> (年)の時間がかかることもわかった. </p> <p> そして,それぞれの星で彼が7歳でいられる時間,つまり布教活動できる時間が異なることがわかった.<br> それぞれの惑星上では,宇宙暦<var>l_i</var>年1月1日00:00:00以降<var>r_i</var>年1月1日00:00:00より前までの時間帯であれば7歳でいられる. <br> たとえ一度ある星で7歳以外の年齢になっても,その星で後から7歳になった場合や,別の星で7歳になれば布教活動を再開することができる. </p> <p> しかしどの星でどれくらい,そしてどの順序で布教活動を行えばより多くの人に7歳教を伝えることができるのか,<br> "彼"にはわからなかった.そこで"彼"はプログラミングが得意なあなたに助けを求めることにした. </p> <p> 現在は宇宙暦0年1月1日00:00:00であり,"彼"は惑星 <var>s</var> にいる. 惑星間を最適に移動・滞在した場合に布教活動が行える最長の年数,<br> つまり"彼"が7歳でかつ惑星で過ごす最長の年数<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)が空白区切りで1行に与えられます。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、<var>n</var> 個の整数の和が <var>s</var> になる組み合わせの個数を1行に出力します。 </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> 1行目にアルファを構成する分子の数$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> 各質問に対して、答えを1行に出力する。 </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> がそれぞれ1行に与えられます。 </p> <H2>Output</H2> <p> <var>i</var> 番目の時刻の判定結果 safe、warning、または alert を順番にそれぞれ1行に出力してください。 </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> 各データセットとして、2つの整数 <var>m</var> と <var>n</var> (1 &le; <var>m</var>, <var>n</var> &le; 1000000, <var>m</var> &le; <var>n</var>) が空白区切りで1行に与えられます。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに <var>m</var> 以上 <var>n</var> 以下のハミング数の個数を1行に出力します。 </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>