question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01634
<h1 class="ndoc-heading1">Problem A: Register Phase</h1> <p class="ndoc-top"> インターネットをより安全に活用するために、堅牢なパスワードを使うことは重要である。それと同時に、同じパスワードを使い回さないことも非常に重要である。どんなに強いパスワードを使っていても、一箇所で平文が流出してしまえば、破るのは非常に容易になってしまう。もちろん、全てのアプリケーションがパスワードをハッシュ化し、SALTを適切に使用していれば流出してもそのような被害は発生しないが、いまだにパスワードを平文で保存しているアプリケーションはあるのである。</p> <p class="ndoc-top">さて、そろそろコンテストが始まる。チームのアカウントを登録しなくては…。</p> <h2 class="ndoc-heading2">問題</h2> <p class="ndoc-top"> パスワードを表す文字列が与えられる。その文字列が以下の条件を全て満たすか調べ、満たす場合は<span style= "font-family: monospace;">"VALID"</span>と、ひとつでも満たさない項目がある場合は<span style="font-family: monospace;">"INVALID"</span>と出力せよ。</p> <ul class="ndoc-indent"> <li>文字列長が6以上である</li> <li>数字を一つ以上含んでいる</li> <li>大文字英字を一つ以上含んでいる</li> <li>小文字英字を一つ以上含んでいる</li> </ul> <h2 class="ndoc-heading2">入力</h2> <p class="ndoc-top">パスワードを表す文字列が一行に与えられる。</p> <h2 class="ndoc-heading2">出力</h2> <p class="ndoc-top">パスワードを表す文字列が問題の条件を全て満たすなら<span style= "font-family: monospace;">"VALID"</span>と、満たさない条件があるなら<span style= "font-family: monospace;">"INVALID"</span>と、一行に出力せよ。</p> <h2 class="ndoc-heading2">制約</h2> <ul class="ndoc-indent"> <li>パスワードを表す文字列は1文字以上20文字以内である</li> <li>パスワードを表す文字列は英大文字、英小文字、数字のみを含む</li> </ul> <h2 class="ndoc-heading2">入出力例</h2> <h3 class="ndoc-heading3">入力1</h3> <pre> password </pre> <h3 class="ndoc-heading3">出力1</h3> <pre> INVALID </pre> <p>世界中で広く使われているパスワードである。</p> <h3 class="ndoc-heading3">入力2</h3> <pre> AizuCamp2013 </pre> <h3 class="ndoc-heading3">出力2</h3> <pre> VALID </pre> <p>素晴しいパスワードである。</p> <h3 class="ndoc-heading3">入力3</h3> <pre> 1234 </pre> <h3 class="ndoc-heading3">出力3</h3> <pre> INVALID </pre> <p>暗証番号として広く使われている。</p> <h3 class="ndoc-heading3">入力4</h3> <pre> NaBiO3 </pre> <h3 class="ndoc-heading3">出力4</h3> <pre> VALID </pre> <p>ぎりぎり6文字以上である。</p>
p03609
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a sandglass that runs for <var>X</var> seconds. The sand drops from the upper bulb at a rate of <var>1</var> gram per second. That is, the upper bulb initially contains <var>X</var> grams of sand.</p> <p>How many grams of sand will the upper bulb contains after <var>t</var> seconds?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤X≤10^9</var></li> <li><var>1≤t≤10^9</var></li> <li><var>X</var> and <var>t</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>X</var> <var>t</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of sand in the upper bulb after <var>t</var> second.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>100 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>83 </pre> <p><var>17</var> out of the initial <var>100</var> grams of sand will be consumed, resulting in <var>83</var> grams.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>48 58 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>All <var>48</var> grams of sand will be gone, resulting in <var>0</var> grams.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p02448
<h1>Sorting Tuples</h1> <p> Write a program which reads $n$ items and sorts them. Each item has attributes $\{value, weight, type, date, name\}$ and they are represented by $\{$ integer, integer, upper-case letter, integer, string $\}$ respectively. Sort the items based on the following priorities. </p> <ol> <li>first by value (ascending)</li> <li>in case of a tie, by weight (ascending)</li> <li>in case of a tie, by type (ascending in lexicographic order)</li> <li>in case of a tie, by date (ascending)</li> <li>in case of a tie, by name (ascending in lexicographic order)</li> </ol> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $v_0 \; w_0 \; t_0 \; d_0 \; s_0$ $v_1 \; w_1 \; t_1 \; d_1 \; s_1$ : $v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$ </pre> <p> In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively. </p> <h2>Output</h2> <p> Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 100,000$</li> <li>$0 \leq v_i \leq 1,000,000,000$</li> <li>$0 \leq w_i \leq 1,000,000,000$</li> <li>$t_i$ is a upper-case letter</li> <li>$0 \leq d_i \leq 2,000,000,000,000$</li> <li>$1 \leq $ size of $s_i \leq 20$</li> <li>$s_i \ne s_j$ if $(i \ne j)$</li> </ul> <h2>Sample Input 1</h2> <pre> 5 105 24 C 1500000000000 white 100 23 C 1500000000000 blue 105 23 A 1480000000000 pink 110 25 B 1500000000000 black 110 20 A 1300000000000 gree </pre> <h2>Sample Output 1</h2> <pre> 100 23 C 1500000000000 blue 105 23 A 1480000000000 pink 105 24 C 1500000000000 white 110 20 A 1300000000000 gree 110 25 B 1500000000000 black </pre>
p00475
<H1>博覧会</H1> <h2> 問題</h2> <p> JOI 市では,とある大規模な博覧会を開催することになった. </p> <p> 今回の博覧会には 2 つのテーマがあり,JOI 市にある N 個の展示施設でそれぞれ, 2 つのテーマのうちどちらか一方に沿った展示を行う予定である. </p> <p> 施設の位置は平面座標 (x, y) で表される.位置 (x, y) にある施設から (x′ , y′) にある施設まで移動するためには, |x − x′| + |y − y′| だけの時間がかかる (整数 a に対して, |a| で a の絶対値を表す).同一テーマ内での統一感を出すため,および一方のテーマのみに関心を持つ人に不便を感じさせないために,同一のテーマで展示を行っている 2 つの施設の間の移動時間がなるべく短くなるようにテーマを割りふりたい.すべての展示施設に同じテーマを割りふらない限り, どのようにテーマを割りふってもよい. </p> <p> 同一のテーマで展示を行っている 2 つの施設の間の移動時間の最大値を M とする. N 個の展示施設の位置が与えられたとき, M の最小値を求めるプログラムを作成せよ. </p> <h2>入力</h2> <!-- <p> 入力ファイルのファイル名は input.txt である. </p> --> <p> 入力の 1 行目には, 施設の個数 N(3 &le; N &le; 100000 = 10<sup>5</sup> ) が書かれている.入力のi + 1 行目 (1 &le; i &le; N) には,各施設の座標を表す 2 つの整数 x<sub>i</sub>, y<sub>i</sub> (|x<sub>i</sub>| &le; 100000 = 10<sup>5</sup>, |y<sub>i</sub>| &le; 100000 = 10<sup>5</sup> ) が空白区切りで書かれている.これは,i 個目の施設の座標が(x<sub>i</sub> , y<sub>i</sub>) であることを表す. 同一の座標に 2 つ以上の施設が存在することはない. </p> <p> 採点用データのうち,配点の 40% 分については, N &le; 2000 である. </p> <h2> 出力</h2> <!-- <p> 出力ファイルのファイル名は output.txt である. </p> --> <p> 出力は 1 行のみからなる.同一のテーマで展示を行っている 2 つの施設間の移動時間の最大値 M の最小値を出力せよ. </p> <h2> 入出力例</h2> <h3>入力例 1</h3> <pre> 5 0 0 1 0 -1 -2 0 1 -1 1</pre> <h3>出力例 1</h3> <pre> 3</pre> <p> この場合,たとえば座標 (0, 0), (1, 0), (0, 1) にある施設に一方のテーマを,(−1, −2), (−1, 1) にある施設にもう一方のテーマを割りふると,同一のテーマで展示を行う 2 つの施設間の移動時間はすべて 3 以下になる.移動時間をすべて 2 以下にすることはできないので,3 を出力する. </p> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p02018
<h2>D: 忖度 (Surmise)</h2> <p>とある双子は、偶数が好きである。</p> <p>$N$ 個の整数 $A_1, A_2, A_3, \dots, A_N$ の中に偶数がいくつあるか数えよ。</p> <h3>入力</h3> <p>1 行目には整数 $N$ が与えられる。</p> <p>2 行目には $N$ 個の整数 $A_1, A_2, A_3, \dots, A_N$ が空白区切りで与えられる。</p> <h3>出力</h3> <p>偶数の個数を出力せよ。ただし、最後に改行を入れること。</p> <h3>制約</h3> <ul> <li>$N$ は $1$ 以上 $100$ 以下の整数</li> <li>$A_1, A_2, A_3, \dots, A_N$ は $1$ 以上 $100$ 以下の整数</li> </ul> <h3>入力例1</h3> <pre> 5 4 3 5 2 6 </pre> <h3>出力例1</h3> <pre> 3 </pre> <p>$A_1 = 4$、$A_4 = 2$ と $A_5 = 6$ が偶数です。よって、偶数の個数は $3$ つです。</p> <h3>入力例2</h3> <pre> 3 2 2 2 </pre> <h3>出力例2</h3> <pre> 3 </pre> <p>同じ数でも、$A_1, A_2, A_3, \dots, A_N$ の中の位置が違うのであれば、別のものとしてカウントします。</p>
p00025
<H1>Hit and Blow</H1> <p> Let's play Hit and Blow game. <i>A</i> imagines four numbers and <i>B</i> guesses the numbers. After <i>B</i> picks out four numbers, <i>A</i> answers: </p> <ul> <li> The number of numbers which have the same place with numbers <i>A</i> imagined (Hit) </li> <li> The number of numbers included (but different place) in the numbers <i>A</i> imagined (Blow)</li> </ul> <p> For example, if <i>A</i> imagined numbers: </p> <pre> 9 1 8 2 </pre> <p> and <i>B</i> chose: </p> <pre> 4 1 5 9 </pre> <p> <i>A</i> should say 1 Hit and 1 Blow. </p> <p> Write a program which reads four numbers <i>A</i> imagined and four numbers <i>B</i> chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset set consists of: </p> <pre> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> <var>a<sub>3</sub></var> <var>a<sub>4</sub></var> <var>b<sub>1</sub></var> <var>b<sub>2</sub></var> <var>b<sub>3</sub></var> <var>b<sub>4</sub></var> </pre> <p> , where <var>a<sub>i</sub></var> (0 &le; <var>a<sub>i</sub></var> &le; 9) is <var>i</var>-th number <i>A</i> imagined and <var>b<sub>i</sub></var> (0 &le; <var>b<sub>i</sub></var> &le; 9) is <var>i</var>-th number <i>B</i> chose. </p> <p> The input ends with EOF. The number of datasets is less than or equal to 50. </P> <H2>Output</H2> <p> For each dataset, print the number of Hit and Blow in a line. These two numbers should be separated by a space. </p> <H2>Sample Input</H2> <pre> 9 1 8 2 4 1 5 9 4 6 8 2 4 6 3 2 </pre> <H2>Output for the Sample Input</H2> <pre> 1 1 3 0 </pre>
p02736
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a sequence of <var>N</var> digits <var>a_1a_2\ldots a_N</var>, where each element is <var>1</var>, <var>2</var>, or <var>3</var>. Let <var>x_{i,j}</var> defined as follows:</p> <ul> <li><var>x_{1,j} := a_j</var> <var>\quad</var> (<var>1 \leq j \leq N</var>)</li> <li><var>x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} |</var> <var>\quad</var> (<var>2 \leq i \leq N</var> and <var>1 \leq j \leq N+1-i</var>)</li> </ul> <p>Find <var>x_{N,1}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^6</var></li> <li><var>a_i = 1,2,3</var> <var>(1 \leq 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>a_1</var><var>a_2</var><var>\ldots</var><var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>x_{N,1}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1231 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p><var>x_{1,1},x_{1,2},x_{1,3},x_{1,4}</var> are respectively <var>1,2,3,1</var>.</p> <p><var>x_{2,1},x_{2,2},x_{2,3}</var> are respectively <var>|1-2| = 1,|2-3| = 1,|3-1| = 2</var>.</p> <p><var>x_{3,1},x_{3,2}</var> are respectively <var>|1-1| = 0,|1-2| = 1</var>.</p> <p>Finally, <var>x_{4,1} = |0-1| = 1</var>, so the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 2311312312 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre></section> </div> </span>
p03824
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will recursively define <em>uninity</em> of a tree, as follows: (<em>Uni</em> is a Japanese word for sea urchins.)</p> <ul> <li>A tree consisting of one vertex is a tree of uninity <var>0</var>.</li> <li>Suppose there are zero or more trees of uninity <var>k</var>, and a vertex <var>v</var>. If a vertex is selected from each tree of uninity <var>k</var> and connected to <var>v</var> with an edge, the resulting tree is a tree of uninity <var>k+1</var>.</li> </ul> <p>It can be shown that a tree of uninity <var>k</var> is also a tree of uninity <var>k+1,k+2,...</var>, and so forth.</p> <p>You are given a tree consisting of <var>N</var> vertices. The vertices of the tree are numbered <var>1</var> through <var>N</var>, and the <var>i</var>-th of the <var>N-1</var> edges connects vertices <var>a_i</var> and <var>b_i</var>.</p> <p>Find the minimum <var>k</var> such that the given tree is a tree of uninity <var>k</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≦ N ≦ 10^5</var></li> <li><var>1 ≦ a_i, b_i ≦ N(1 ≦ i ≦ N-1)</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> : <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum <var>k</var> such that the given tree is a tree of uninity <var>k</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 1 2 2 3 2 4 4 6 6 7 7 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>A tree of uninity <var>1</var> consisting of vertices <var>1</var>, <var>2</var>, <var>3</var> and <var>4</var> can be constructed from the following: a tree of uninity <var>0</var> consisting of vertex <var>1</var>, a tree of uninity <var>0</var> consisting of vertex <var>3</var>, a tree of uninity <var>0</var> consisting of vertex <var>4</var>, and vertex <var>2</var>.</p> <p>A tree of uninity <var>1</var> consisting of vertices <var>5</var> and <var>7</var> can be constructed from the following: a tree of uninity <var>1</var> consisting of vertex <var>5</var>, and vertex <var>7</var>.</p> <p>A tree of uninity <var>2</var> consisting of vertices <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var>, <var>6</var> and <var>7</var> can be constructed from the following: a tree of uninity <var>1</var> consisting of vertex <var>1</var>, <var>2</var>, <var>3</var> and <var>4</var>, a tree of uninity <var>1</var> consisting of vertex <var>5</var> and <var>7</var>, and vertex <var>6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>12 1 2 2 3 2 4 4 5 5 6 6 7 7 8 5 9 9 10 10 11 11 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre></section> </div> </span>
p01819
<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: Where is the Boundary </h2> <p> An island country JAGAN in a certain planet is very long and narrow, and extends east and west. This long country is said to consist of two major cultural areas | the eastern and the western. Regions in the east tend to have the eastern cultural features and regions in the west tend to have the western cultural features, but, of course, the boundary between the two cultural areas is not clear, which has been an issue. </p> <p> You are given an assignment estimating the boundary using a given data set. </p> <p> More precise specification of the assignment is as follows: </p> <ol> <li> JAGAN is divided into $n$ prefectures forming a line in the east-west direction. Each prefecture is numbered 1, 2, ..., $n$ <b>from WEST to EAST</b>.</li> <li> Each data set consists of $m$ features, which has 'E' (east) or 'W' (west) for each prefecture. These data indicate that each prefecture has eastern or western features from $m$ different point of views, for example, food, clothing, and so on.</li> <li> In the estimation, you have to choose a cultural boundary achieving the minimal errors. That is, you have to minimize the sum of 'W's in the eastern side and 'E's in the western side.</li> <li> In the estimation, you can choose a cultural boundary only from the boundaries between two prefectures.</li> </ol> <p> Sometimes all prefectures may be estimated to be the eastern or the western cultural area. In these cases, to simplify, you must virtually consider that the boundary is placed between prefecture No. 0 and No. 1 or between prefecture No. $n$ and No. $n+1$. When you get multiple minimums, you must output the most western (least-numbered) result. </p> <p> Write a program to solve the assignment. </p> <h3>Input</h3> <p> Each input is formatted as follows:<br> <br> $n$ $m$<br> $d_{11} ... d_{1n}$<br> :<br> :<br> $d_{m1} ... d_{mn}$<br> <br> </p> <p> The first line consists of two integers $n$ ($1 \leq n \leq 10,000$), $m$ ($1 \leq m \leq 100$), which indicate the number of prefectures and the number of features in the assignment. The following m lines are the given data set in the assignment. Each line contains exactly $n$ characters. The $j$-th character in the $i$-th line $d_{ij}$ is 'E' (east) or 'W' (west), which indicates $j$-th prefecture has the eastern or the western feature from the $i$-th point of view. </p> <h3>Output</h3> <p> Print the estimated result in a line. The output consists of two integers sorted in the ascending order which indicate two prefectures touching the boundary. </p> <h3>Sample Input</h3> <pre> 2 1 WE </pre> <h3>Output for the Sample Input</h3> <pre> 1 2 </pre> <h3>Sample Input</h3> <pre> 3 2 WWE WEE </pre> <h3>Output for the Sample Input</h3> <pre> 1 2 </pre> <p> Both estimates "1 2" and "2 3" achieve 1 error as the minimum. From the restriction that you must adopt the most western estimate, you must output "1 2". </p> <h3>Sample Input</h3> <pre> 3 1 WWW </pre> <h3>Output for the Sample Input</h3> <pre> 3 4 </pre> <p> In this case, all the prefectures are western. As described in the problem statement, you must virtually consider that the boundary is placed between third and fourth prefectures. </p> <h3>Sample Input</h3> <pre> 3 1 WEW </pre> <h3>Output for the Sample Input</h3> <pre> 1 2 </pre> <p> You cannot assume that 'E's and 'W's are separated. </p>
p02366
<H1>Articulation Points</H1> <p> Find articulation points of a given undirected graph <var>G(V, E)</var>. </p> <p> A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph. </p> <H2>Input</H2> <pre> <var>|V|</var> <var>|E|</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<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). </p> <H2>Output</H2> <p> A list of <i>articulation points</i> of the graph <var>G</var> ordered by name. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>|V|</var> &le; 100,000</li> <li>0 &le; <var>|E|</var> &le; 100,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 4 0 1 0 2 1 2 2 3 </pre> <H2>Sample Output 1</H2> <pre> 2 </pre> <br/> <H2>Sample Input 2</H2> <pre> 5 4 0 1 1 2 2 3 3 4 </pre> <H2>Sample Output 2</H2> <pre> 1 2 3 </pre>
p03127
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> monsters, numbered <var>1, 2, ..., N</var>.</p> <p>Initially, the health of Monster <var>i</var> is <var>A_i</var>.</p> <p>Below, a monster with at least <var>1</var> health is called alive.</p> <p>Until there is only one alive monster, the following is repeated:</p> <ul> <li>A random alive monster attacks another random alive monster.</li> <li>As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.</li> </ul> <p>Find the minimum possible final health of the last monster alive.</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 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>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 minimum possible final health of the last monster alive.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 10 8 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>When only the first monster keeps on attacking, the final health of the last monster will be <var>2</var>, which is minimum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 13 8 1000000000 </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>3 1000000000 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000 </pre></section> </div> </span>
p03577
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Rng is going to a festival.</p> <p>The name of the festival is given to you as a string <var>S</var>, which ends with <code>FESTIVAL</code>, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.</p> <p>Here, assume that the name of "a festival of <var>s</var>" is a string obtained by appending <code>FESTIVAL</code> to the end of <var>s</var>. For example, <code>CODEFESTIVAL</code> is a festival of <code>CODE</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>9 \leq |S| \leq 50</var></li> <li><var>S</var> consists of uppercase English letters.</li> <li><var>S</var> ends with <code>FESTIVAL</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 answer to the question: "Rng is going to a festival of what?"</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>CODEFESTIVAL </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>CODE </pre> <p>This is the same as the example in the statement.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>CODEFESTIVALFESTIVAL </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>CODEFESTIVAL </pre> <p>This string is obtained by appending <code>FESTIVAL</code> to the end of <code>CODEFESTIVAL</code>, so it is a festival of <code>CODEFESTIVAL</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>YAKINIKUFESTIVAL </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YAKINIKU </pre></section> </div> </span>
p03598
<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 in the <var>xy</var>-plane. The coordinates of the <var>i</var>-th of them is <var>(x_i, i)</var>. Thus, we have one ball on each of the <var>N</var> lines <var>y = 1</var>, <var>y = 2</var>, <var>...</var>, <var>y = N</var>.</p> <p>In order to collect these balls, Snuke prepared <var>2N</var> robots, <var>N</var> of type A and <var>N</var> of type B. Then, he placed the <var>i</var>-th type-A robot at coordinates <var>(0, i)</var>, and the <var>i</var>-th type-B robot at coordinates <var>(K, i)</var>. Thus, now we have one type-A robot and one type-B robot on each of the <var>N</var> lines <var>y = 1</var>, <var>y = 2</var>, <var>...</var>, <var>y = N</var>.</p> <p>When activated, each type of robot will operate as follows.</p> <ul> <li> <p>When a type-A robot is activated at coordinates <var>(0, a)</var>, it will move to the position of the ball on the line <var>y = a</var>, collect the ball, move back to its original position <var>(0, a)</var> and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p> </li> <li> <p>When a type-B robot is activated at coordinates <var>(K, b)</var>, it will move to the position of the ball on the line <var>y = b</var>, collect the ball, move back to its original position <var>(K, b)</var> and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p> </li> </ul> <p>Snuke will activate some of the <var>2N</var> robots to collect all of the balls. Find the minimum possible total distance covered by robots.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq K \leq 100</var></li> <li><var>0 &lt; x_i &lt; K</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>Print the minimum possible total distance covered by robots.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 10 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are just one ball, one type-A robot and one type-B robot.</p> <p>If the type-A robot is used to collect the ball, the distance from the robot to the ball is <var>2</var>, and the distance from the ball to the original position of the robot is also <var>2</var>, for a total distance of <var>4</var>.</p> <p>Similarly, if the type-B robot is used, the total distance covered will be <var>16</var>.</p> <p>Thus, the total distance covered will be minimized when the type-A robot is used. The output should be <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 9 3 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>12 </pre> <p>The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 20 11 12 9 17 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>74 </pre></section> </div> </span>
p03062
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> integers, <var>A_1, A_2, ..., A_N</var>, arranged in a row in this order.</p> <p>You can perform the following operation on this integer sequence any number of times:</p> <p><strong>Operation</strong>: Choose an integer <var>i</var> satisfying <var>1 \leq i \leq N-1</var>. Multiply both <var>A_i</var> and <var>A_{i+1}</var> by <var>-1</var>.</p> <p>Let <var>B_1, B_2, ..., B_N</var> be the integer sequence after your operations.</p> <p>Find the maximum possible value of <var>B_1 + B_2 + ... + B_N</var>.</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 10^5</var></li> <li><var>-10^9 \leq A_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>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 possible value of <var>B_1 + B_2 + ... + B_N</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 -10 5 -4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>19 </pre> <p>If we perform the operation as follows:</p> <ul> <li>Choose <var>1</var> as <var>i</var>, which changes the sequence to <var>10, -5, -4</var>.</li> <li>Choose <var>2</var> as <var>i</var>, which changes the sequence to <var>10, 5, 4</var>.</li> </ul> <p>we have <var>B_1 = 10, B_2 = 5, B_3 = 4</var>. The sum here, <var>B_1 + B_2 + B_3 = 10 + 5 + 4 = 19</var>, is the maximum possible result.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 10 -4 -8 -11 3 </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>11 -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>10000000000 </pre> <p>The output may not fit into a <var>32</var>-bit integer type.</p></section> </div> </span>
p03432
<span class="lang-en"> <p>Score : <var>1800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have an <var>N \times M</var> grid. The square at the <var>i</var>-th row and <var>j</var>-th column will be denoted as <var>(i,j)</var>. Particularly, the top-left square will be denoted as <var>(1,1)</var>, and the bottom-right square will be denoted as <var>(N,M)</var>. Takahashi painted some of the squares (possibly zero) black, and painted the other squares white.</p> <p>We will define an integer sequence <var>A</var> of length <var>N</var>, and two integer sequences <var>B</var> and <var>C</var> of length <var>M</var> each, as follows:</p> <ul> <li><var>A_i(1\leq i\leq N)</var> is the minimum <var>j</var> such that <var>(i,j)</var> is painted black, or <var>M+1</var> if it does not exist.</li> <li><var>B_i(1\leq i\leq M)</var> is the minimum <var>k</var> such that <var>(k,i)</var> is painted black, or <var>N+1</var> if it does not exist.</li> <li><var>C_i(1\leq i\leq M)</var> is the maximum <var>k</var> such that <var>(k,i)</var> is painted black, or <var>0</var> if it does not exist.</li> </ul> <p>How many triples <var>(A,B,C)</var> can occur? Find the count modulo <var>998244353</var>.</p> </section> </div> <div class="part"> <section> <h3>Notice</h3><p><font color="Red">In this problem, the length of your source code must be at most <var>20000</var> B. Note that we will invalidate submissions that exceed the maximum length.</font></p> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 8000</var></li> <li><var>1 \leq M \leq 200</var></li> <li><var>N</var> and <var>M</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>1500</var> points will be awarded for passing the test set satisfying <var>N\leq 300</var>.</li> </ul> </section> </div> </div> <hr/> <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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of triples <var>(A,B,C)</var>, modulo <var>998244353</var>.</p> </section> </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>64 </pre> <p>Since <var>N=2</var>, given <var>B_i</var> and <var>C_i</var>, we can uniquely determine the arrangement of black squares in each column. For each <var>i</var>, there are four possible pairs <var>(B_i,C_i)</var>: <var>(1,1)</var>, <var>(1,2)</var>, <var>(2,2)</var> and <var>(3,0)</var>. Thus, the answer is <var>4^M=64</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2588 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>17 13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>229876268 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5000 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>57613837 </pre></section> </div> </span>
p02389
<H1>Rectangle</H1> <p> Write a program which calculates the area and perimeter of a given rectangle. </p> <H2>Input</H2> <p> The length <var>a</var> and breadth <var>b</var> of the rectangle are given in a line separated by a single space. </p> <H2>Output</H2> <p> Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>a</var>, <var>b</var> &le; 100</li> </ul> <H2>Sample Input 1</H2> <pre> 3 5 </pre> <H2>Sample Output 1</H2> <pre> 15 16 </pre>
p02673
<span class="lang-en"> <p>Score : <var>1300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position <var>p\in\{1,2,\dots, N\}</var>. The <var>N</var> positions are arranged on a circle (so that <var>1</var> is between <var>N</var> and <var>2</var>).</p> <p>The game consists of turns. At each turn you can either end the game, and get <var>A_p</var> dollars (where <var>p</var> is the current position of the pawn), or pay <var>B_p</var> dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions <var>p-1</var>, <var>p+1</var> (with the identifications <var>0 = N</var> and <var>N+1=1</var>).</p> <p>What is the expected gain of an optimal strategy?</p> <p><strong>Note</strong>: The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a <em>finite</em> number of turns.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \le N \le 200,000</var></li> <li><var>0 \le A_p \le 10^{12}</var> for any <var>p = 1,\ldots, N</var></li> <li><var>0 \le B_p \le 100</var> for any <var>p = 1, \ldots, N</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var> <var>B_1</var> <var>B_2</var> <var>\cdots</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed <var>10^{-10}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 2 6 3 5 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4.700000000000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 100 0 100 0 0 100 0 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>50.000000000000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>14 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912 34 54 61 32 52 61 21 43 65 12 45 21 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7047.142857142857 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951 26 83 30 59 100 88 84 91 54 61 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>815899161079.400024414062 </pre></section> </div> </span>
p03961
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>One day Mr. Takahashi picked up a dictionary containing all of the <var>N</var>! permutations of integers <var>1</var> through <var>N</var>. The dictionary has <var>N</var>! pages, and page <var>i</var> (<var>1 ≤ i ≤ N!</var>) contains the <var>i</var>-th permutation in the lexicographical order.</p> <p>Mr. Takahashi wanted to look up a certain permutation of length <var>N</var> in this dictionary, but he forgot some part of it.</p> <p>His memory of the permutation is described by a sequence <var>P_1, P_2, ..., P_N</var>. If <var>P_i = 0</var>, it means that he forgot the <var>i</var>-th element of the permutation; otherwise, it means that he remembered the <var>i</var>-th element of the permutation and it is <var>P_i</var>.</p> <p>He decided to look up all the possible permutations in the dictionary. Compute the sum of the page numbers of the pages he has to check, modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 500000</var></li> <li><var>0 ≤ P_i ≤ N</var></li> <li><var>P_i ≠ P_j</var> if <var>i ≠ j</var> (<var>1 ≤ i, j ≤ N</var>), <var>P_i ≠ 0</var> and <var>P_j ≠ 0</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li>In test cases worth <var>500</var> points, <var>1 ≤ N ≤ 3000</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the page numbers of the pages he has to check, as modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 0 2 3 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>23 </pre> <p>The possible permutations are [<var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>] and [<var>4</var>, <var>2</var>, <var>3</var>, <var>1</var>]. Since the former is on page <var>1</var> and the latter is on page <var>22</var>, the answer is <var>23</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>21 </pre> <p>Since all permutations of length <var>3</var> are possible, the answer is <var>1 + 2 + 3 + 4 + 5 + 6 = 21</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 2 3 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre> <p>Mr. Takahashi remembered all the elements of the permutation.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre> <p>The dictionary consists of one page.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>10 0 3 0 0 1 0 4 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>953330050 </pre></section> </div> </span>
p02223
<span class="lang"> <span class="lang-ja"> <h1>M: 文字列集合</h1> <div class="part"> <section> <h3>問題文</h3><p>以下の条件を満たす文字列集合 $S$ のうち、要素数が最大となるものを $1$ つ構成してください。</p> <ul> <li>$S$ に含まれる文字列の長さは $1$ 以上 $N$ 以下である。</li> <li>$S$ に含まれる文字列の長さはそれぞれ異なる。</li> <li>$S$ に含まれる文字列は、文字 <code>0</code>, <code>1</code> のみからなる。</li> <li>$S$ に含まれるどの $2$ つの文字列についても、一方がもう一方の部分文字列とならない。</li> </ul> <p>ただし、文字列 $x$ の部分文字列とは、 $x$ の先頭と末尾から $0$ 文字以上の文字を取り除くことで得られる文字列のことを言います。</p> </section> </div> <div class="part"> <section> <h3>制約</h3><ul> <li>$1 \leq N \leq 300$</li> <li>$N$ は整数である</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以下の形式で標準入力から与えられる。</p> <pre>$N$ </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>条件を満たす文字列集合 $S$ のうち、要素数が最大となるものを $1$ つ出力せよ。このような $S$ は複数存在する可能性があるが、どれを出力しても正答となる。</p> <p>具体的には、以下の形式で出力せよ。</p> <p>$1$ 行目に $S$ の要素数 $K$ を出力せよ。</p> <p>$2$ 行目から $K+1$ 行目に $S$ の要素をすべて出力せよ。各行には $S$ の要素を $1$ つ出力せよ。</p> <pre>$K$ $S_1$ $S_2$ $\vdots$ $S_K$ </pre> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力例1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>出力例1</h3><pre>2 0 11 </pre> <p>文字列集合 $\{0, 11\}$ は、条件を満たす集合の中で要素数が最大となるものです。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力例2</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>出力例2</h3><pre>1 0 </pre></section> </div> </span> </span>
p02809
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Niwango has <var>N</var> cards, numbered <var>1,2,\ldots,N</var>. He will now arrange these cards in a row.</p> <p>Niwango wants to know if there is a way to arrange the cards while satisfying all the <var>N</var> conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangement.</p> <ul> <li>To the immediate right of Card <var>1</var> (if any) is NOT Card <var>a_1</var>.</li> <li>To the immediate right of Card <var>2</var> (if any) is NOT Card <var>a_2</var>.</li> <li><var>\vdots</var></li> <li>To the immediate right of Card <var>N</var> (if any) is NOT Card <var>a_N</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>2 \leq N \leq 10^{5}</var></li> <li><var>1 \leq a_i \leq N</var></li> <li><var>a_i \neq 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>\ldots</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If no arrangements satisfy the conditions, print <code>-1</code>. If such arrangements exist, print the lexicographically smallest such arrangement, in the following format:</p> <pre><var>b_1</var> <var>b_2</var> <var>\ldots</var> <var>b_N</var> </pre> <p>Here, <var>b_i</var> represents the <var>i</var>-th card from the left.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 3 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 3 2 4 </pre> <ul> <li>The arrangement <var>(1,2,3,4)</var> is lexicographically smaller than <var>(1,3,2,4)</var>, but is invalid, since it violates the condition "to the immediate right of Card <var>1</var> is not Card <var>2</var>."</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <ul> <li>If no arrangements satisfy the conditions, print <code>-1</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>13 2 3 4 5 6 7 8 9 10 11 12 13 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 3 2 4 6 5 7 9 8 10 12 11 13 </pre></section> </div> </span>
p00834
<H1><font color="#000">Problem H:</font> Inherit the Spheres</H1> <p> In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to contain positions and radiuses of spheres. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_inheritTheSpheres1"> <p>Figure 1: A strange object</p> </center> <p> Initially their objective was unknown, but Professor Zambendorf found the cross section formed by a horizontal plane plays an important role. For example, the cross section of an object changes as in Figure 2 by sliding the plane from bottom to top. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_inheritTheSpheres2"> <p>Figure 2: Cross sections at different positions</p> </center> <p> He eventually found that some information is expressed by the transition of the number of connected figures in the cross section, where each connected figure is a union of discs intersecting or touching each other, and each disc is a cross section of the corresponding solid sphere. For instance, in Figure 2, whose geometry is described in the first sample dataset later, the number of connected figures changes as 0, 1, 2, 1, 2, 3, 2, 1, and 0, at <i>z</i> = 0.0000, 162.0000, 167.0000, 173.0004, 185.0000, 191.9996, 198.0000, 203.0000, and 205.0000, respectively. By assigning 1 for increment and 0 for decrement, the transitions of this sequence can be expressed by an 8-bit binary number 11011000. </p> <p> For helping further analysis, write a program to determine the transitions when sliding the horizontal plane from bottom (<i>z</i> = 0) to top (<i>z</i> = 36000). </p> <H2>Input</H2> <p> The input consists of a series of datasets. Each dataset begins with a line containing a positive integer, which indicates the number of spheres <i>N</i> in the dataset. It is followed by <i>N</i> lines describing the centers and radiuses of the spheres. Each of the <i>N</i> lines has four positive integers <i>X<sub>i</sub></i>, <i>Y<sub>i</sub></i>, <i>Z<sub>i</sub></i>, and <i>R<sub>i</sub></i> (<i>i</i> = 1, . . . , <i>N</i>) describing the center and the radius of the <i>i</i>-th sphere, respectively. </p> <p> You may assume 1 &le; <i>N</i> &le; 100, 1 &le; <i>R<sub>i</sub></i> &le; 2000, 0 &lt; <i>X<sub>i</sub></i> - <i>R<sub>i</sub></i> &lt; <i>X<sub>i</sub></i> + <i>R<sub>i</sub></i> &lt; 4000, 0 &lt; <i>Y<sub>i</sub></i> - <i>R<sub>i</sub></i> &lt; <i>Y<sub>i</sub></i> + <i>R<sub>i</sub></i> &lt; 16000, and 0 &lt; <i>Z<sub>i</sub></i> - <i>R<sub>i</sub></i> &lt; <i>Z<sub>i</sub></i> + <i>R<sub>i</sub></i> &lt; 36000. Each solid sphere is defined as the set of all points (<i>x</i>, <i>y</i>, <i>z</i>) satisfying (<i>x</i> - <i>X<sub>i</sub></i>)<sup>2</sup> + (<i>y</i> - <i>Y<sub>i</sub></i>)<sup>2</sup> + (<i>z</i> - <i>Z<sub>i</sub></i>)<sup>2</sup> &le; <i>R<sub>i</sub></i><sup>2</sup>. </p> <p> A sphere may contain other spheres. No two spheres are mutually tangent. Every <i>Z<sub>i</sub></i> &plusmn; <i>R<sub>i</sub></i> and minimum/maximum <i>z</i> coordinates of a circle formed by the intersection of any two spheres differ from each other by at least 0.01. </p> <p> The end of the input is indicated by a line with one zero. </p> <H2>Output</H2> <p> For each dataset, your program should output two lines. The first line should contain an integer <i>M</i> indicating the number of transitions. The second line should contain an <i>M</i>-bit binary number that expresses the transitions of the number of connected figures as specified above. </p> <H2>Sample Input</H2> <pre> 3 95 20 180 18 125 20 185 18 40 27 195 10 1 5 5 5 4 2 5 5 5 4 5 5 5 3 2 5 5 5 4 5 7 5 3 16 2338 3465 29034 710 1571 14389 25019 842 1706 8015 11324 1155 1899 4359 33815 888 2160 10364 20511 1264 2048 8835 23706 1906 2598 13041 23679 618 1613 11112 8003 1125 1777 4754 25986 929 2707 9945 11458 617 1153 10358 4305 755 2462 8450 21838 934 1822 11539 10025 1639 1473 11939 12924 638 1388 8519 18653 834 2239 7384 32729 862 0 </pre> <H2>Output for the Sample Input</H2> <pre> 8 11011000 2 10 2 10 2 10 28 1011100100110101101000101100 </pre>
p01726
<p>不運なイクタ君は持っていた大事な文字列<var>T</var>をウィルスによって異なる文字列<var>T'</var>に書き換えられてしまった。そのウィルスが<var>T</var>の1文字を異なる文字に書き換えてしまったことがわかっている。すなわち<var>T</var>と<var>T'</var>はちょうど1文字のみ異なっている。イクタ君は<var>T</var>を復元するために、<var>T</var>が出現していると思われる文書<var>S</var>を用意した。<var>T</var>を復元するための下準備として<var>S</var>の部分文字列で<var>T</var>と一致している可能性があるものの個数を調べたい。 </p> <p>文字列<var>T'</var>と文書<var>S</var>が与えられる。 <var>S = a<sub>1</sub> a<sub>2</sub> a<sub>3</sub> . . . a<sub>|S|</sub></var>の長さ<var>|T'|</var>の部分文字列<var>a<sub>k</sub> a<sub>k+1</sub> . . . a<sub>k+|T'|&minus;1</sub>(1 &le; k &le; |S| &minus; |T'| + 1)</var> で<var>T'</var>と比較して1文字だけ異なるものの数を求めよ。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。 </p> <pre> <var>S</var><br><var>T'</var> </pre> <ul> <li>1行目で<var>S</var>が与えられる。 </li><li>2行目で<var>T'</var>が与えられる。 </li><li><var>S</var>, <var>T'</var>はそれぞれ大文字、小文字のアルファベットのみからなる。 </li></ul> <h3>Constraints</h3> <p>入力中の各変数は以下の制約を満たす。 </p> <ul> <li><var>1 &le; |S| &le; 300,000</var> </li> <li><var>1 &le; |T'| &le; |S|</var> </li></ul> <h2>Output</h2> <p>条件を満たす部分文字列の数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre>abcbcdbc abc </pre> <h2>Output for the Sample Input 1</h2> <pre>2 </pre> <ul><li><var>S</var>の3番目の文字から始まるcbc, <var>S</var>の6番目の文字から始まるdbcが条件を満たす。 </li></ul> <h2>Sample Input 2</h2> <pre>aaaaaa aaaaaa </pre> <h2>Output for the Sample Input 2</h2> <pre>0 </pre> <ul><li>完全に一致する文字列は数えてはならない。</li></ul> <h2>Sample Input 3</h2> <pre> baaaaaaaa b </pre> <h2>Output for the Sample Input 3</h2> <pre>8 </pre>
p01376
<div> <h1 class="title">問題 A : プログラミングコンテスト</h1> <p>時は 20XX 年,世界は G○○gle 社の支配によるディストピアである. 現在,人々の娯楽はプログラミングコンテストに限られている. 例えば,週末に家族で T○pC○der アリーナを訪れるというのはとてもよく見られる光景である. しかし,それは光の世界のプログラミングコンテストの姿に過ぎない. 一方で,G○○gle と反抗勢力がぶつかり合う闇の世界では, 命をかけたプログラミングコンテストが行われている.</p> <p>自分も久しぶりにプログラミングコンテストに参加してみよう. 足慣らしに,まずは,プログラミングコンテストの結果を処理するプログラムでも書いてみることにしよう.</p> <div> <h1>問題</h1> <p><span style="font-size:110%;font-family:times new roman;"><i>M</i></span> 人の参加者が居て <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 問の問題から成るプログラミングコンテストを考える. 各参加者に関して,各問題を解いているか解いていないかが与えられるので, 最も多く問題を解いている人が解いた問題数を出力するプログラムを作成せよ.</p> </div> <div> <h1>入力</h1> <p>入力の最初の行は 2 つの整数 <span style="font-size:110%;font-family:times new roman;"><i>M</i>,&nbsp;<i>N</i></span> を含む. これは,参加者数と問題数を表す.</p> <p>続く <span style="font-size:110%;font-family:times new roman;"><i>M</i></span> 行には,各参加者が各問題を解いているか解いていないかが与えられる. これらの行のうちの <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> 行目は <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 個の 0 か 1 の数字 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i>,&nbsp;1</sub>,&nbsp;<i>a</i><sub><i>i</i>,&nbsp;2</sub>,&nbsp;…,&nbsp;<i>a</i><sub><i>i</i>,&nbsp;<i>N</i></sub></span> が書かれている. <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i>,&nbsp;<i>j</i></sub></span> は以下のような意味を持つ.</p> <ul class="simple"> <li><span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i>,&nbsp;<i>j</i></sub></span> が 0 の時,参加者 <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> は問題 <span style="font-size:110%;font-family:times new roman;"><i>j</i></span> を解いていない.</li> <li><span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i>,&nbsp;<i>j</i></sub></span> が 1 の時,参加者 <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> は問題 <span style="font-size:110%;font-family:times new roman;"><i>j</i></span> を解いている.</li> </ul> </div> <div> <h1>出力</h1> <p>最も多く問題を解いている人が解いた問題数を出力せよ.</p> </div> <div> <h1>制約</h1> <ul class="simple"> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>M</i>&nbsp;&le;&nbsp;20</span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>N</i>&nbsp;&le;&nbsp;20</span></li> </ul> </div> <div> <h1>入出力例</h1> <div> <h2>入出力例 1</h2> <p>入力例 1:</p> <pre class="literal-block"> 3 4 1 0 1 0 1 1 1 0 0 0 0 1 </pre> <p>入力例 1 に対する出力例:</p> <pre class="literal-block"> 3 </pre> <p>参加者 1 は 2 問(問題 1, 3), 参加者 2 は 3 問(問題 1, 2, 3), 参加者 3 は 1 問(問題 4)を解いている. 最も多く問題をといているのは参加者 2 で, その問題数は 3 であり,3 が正しい出力である.</p> </div> <div> <h2>入出力例 2</h2> <p>入力例 2:</p> <pre class="literal-block"> 3 4 1 1 1 1 1 1 1 1 1 1 1 1 </pre> <p>入力例 2 に対する出力例:</p> <pre class="literal-block"> 4 </pre> <p>全ての参加者が 4 問全てを解いている. 最も多く問題を解いている参加者というのは 参加者全員であり,その問題数は 4 である.</p> </div> <div> <h2>入出力例 3</h2> <p>入力例 3:</p> <pre class="literal-block"> 1 1 0 </pre> <p>入力例 3 に対する出力例:</p> <pre class="literal-block"> 0 </pre> </div> </div> </div>
p00137
<H1>平方採中法</H1> <p> 古典的な乱数生成方法の一つである平方採中法のプログラムを作成します。平方採中法は、フォンノイマンによって 1940 年代半ばに提案された方法です。 </p> <p> 平方採中法は、生成する乱数の桁数を <var>n</var> としたとき、初期値 <var>s</var> の2乗を計算し、その数値を <var>2n</var> 桁の数値とみて、(下の例のように 2 乗した桁数が足りないときは、0 を補います。)その中央にある <var>n</var> 個の数字を最初の乱数とします。次にこの乱数を 2 乗して、同じ様に、中央にある <var>n</var> 個の数字をとって、次の乱数とします。例えば、123 を初期値とすると </p> <pre> 123<sup>2</sup> = 00015129 → 0151 151<sup>2</sup> = 00022801 → 0228 228<sup>2</sup> = 00051984 → 0519 519<sup>2</sup> = 00269361 → 2693 2693<sup>2</sup> = 07252249 → 2522 </pre> <p> の様になります。この方法を用いて、初期値 <var>s</var>(10000未満の正の整数)を入力とし、<var>n</var> = 4 の場合の乱数を 10 個生成し出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。1行目にデータセットの数 <var>d</var> (<var>d</var> &le; 10) が与えられます。各データセットとして、1行に初期値 <var>s</var>(整数、1 &le; <var>s</var> &lt; 10000)が与えられます。 </pre> <H2>Output</H2> <p> 各データセットに対して、 </p> <pre> Case <var>x</var>: (<var>x</var> は 1 から始まるデータセット番号) 1個目の生成した乱数(整数) 2個目の生成した乱数(整数) : : 10個目の生成した乱数(整数) </pre> <p> を出力してください。 </p> <H2>Sample Input</H2> <pre> 2 123 567 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 151 228 519 2693 2522 3604 9888 7725 6756 6435 Case 2: 3214 3297 8702 7248 5335 4622 3628 1623 6341 2082 </pre>
p00567
<h1>水ようかん (Mizuyokan)</h1> <h2>問題文</h2> <p> 水ようかんとは,おもに小豆からなる餡を型に流し込んで寒天で固めることにより作られる和菓子である.いま,JOI 君の手元には,横長の直方体の形をした水ようかんがひとつある.JOI 君は,今日のおやつとしてこの水ようかんを食べる予定である.</p> <p> この水ようかんには,縦方向の切れ目が全部で <var>N-1</var> 箇所に入っている.水ようかんの長さは <var>L_1 + L_2 + ... + L_N</var> であり,<var>i</var> 番目 <var>(1 ≦ i ≦ N-1)</var> の切れ目は,左から <var>L_1 + L_2 + ... + L_i</var> の位置にある.</p> <p> この水ようかんは丸ごと食べるには大きすぎるので,JOI 君は,水ようかんに入っている切れ目から <var>1</var> 箇所以上を選び,選んだ切れ目に沿って水ようかんを切って,複数のピースに切り分けることにした.ただし,ピースの大きさが不揃いでは見栄えが悪いので,長さ最大のピースと最小のピースの長さの差ができるだけ小さくなるように切ることにした.</p> <p> 長さ最大のピースと最小のピースの長さの差の最小値を求めよ.</p> <h2>制約</h2> <ul> <li><var>2 \leq N \leq 50</var></li> <li><var>1 \leq L_i \leq 1000 (1 \leq i \leq N)</var></li> </ul> <h2>入力・出力</h2> <p> <b>入力</b><br> 入力は以下の形式で標準入力から与えられる.<br> <var>N</var><br> <var>L_1</var><br> <var>L_2</var><br> :<br> <var>L_N</var> </p> <p> <b>出力</b><br> 長さ最大のピースと最小のピースの長さの差の最小値を <var>1</var> 行で出力せよ.</p> <!-- <h2> 小課題</h2> <p> <b>小課題 1 [10点]</b> </p> <ul> <li><var>N ≦ 15</var></li> </ul> <p> <b>小課題 2 [27点]</b> </p> <ul> <li><var>L_i ≦ 10 (1 ≦ i ≦ N)</var></li> </ul> <p> <b>小課題 3 [63点]</b> </p> <ul> <li>追加の制限はない.</li> </ul> --> <h2>入出力例</h2> <b>入力例 1</b><br> <pre> 11 2 3 8 4 7 6 6 5 1 7 5 </pre> <b>出力例 1</b><br> <pre> 2 </pre> <p> この例では,<var>4</var> 番目および <var>7</var> 番目の切れ目に沿って切り分けることで,長さ <var>17, 19, 18</var> の <var>3</var> つのピースに切り分けることができる. このとき,いちばん長いピースは長さ <var>19</var> で,いちばん短いピースは長さ <var>17</var> であるので,長さの差は <var>2</var> となる. これが最小値なので,<var>2</var> を出力する.</p> <hr> <b>入力例 2</b><br> <pre> 2 1 10 </pre> <b>出力例 2</b><br> <pre> 9 </pre> <p> どんなに大きさが不揃いであっても,必ず <var>1</var> 箇所以上を切る必要がある. </p> <hr> <b>入力例 3</b><br> <pre> 5 5 5 5 5 5 </pre> <b>出力例 3</b><br> <pre> 0 </pre> <p> この例では水ようかんをちょうど同じ大きさの <var>5</var> つのピースに分割できる. </p> <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>
p00072
<H1>灯篭</H1> <p> 会津若松市は「歴史の町」として知られています。今から約 400 年前、蒲生氏郷により城下町の骨格が作られましたが、その後、徳川三代将軍家光公の異母弟「保科正之」公を藩祖とする会津藩 23 万石の中心都市として発展しました。今でも市内のいたるところに史跡や昔日の面影が残っているため、毎年、全国から多くの観光客が訪れています。 </p> <p> <!--特に、-->今年は、NHK大河ドラマで「新選組!」が放送されているため、新選組ゆかりの地(*1)として、大幅に観光客が増加しています。そこで市では、市内に点在する史跡を結ぶ通り沿いに 100 m 間隔で灯篭を設置して飾りたてることにしました。灯篭を飾ってある通りを辿れば市内の全ての史跡に到達できるように設置することが条件ですが、一筆書きでたどれる必要はありません。しかし、予算が限られているので設置する灯篭の数を最小限にする必要があります。 </p> <p> 史跡と史跡を結ぶ通りのデータを読み込んで、必要最小限の灯篭の数を出力するプログラムを作成して下さい。ただし、史跡と史跡の間の距離は 200 m 以上で、100 の倍数で与えられます。おのおのの史跡から一番近い灯篭までの距離は 100 m で、市内の史跡は 100 箇所以内です。史跡自身には灯篭を設置する必要はありません。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_carden"> </center> <br/> <p> (*1) 新選組は会津藩御預という形で発足、白虎隊の悲劇で知られる会津戊辰戦争に参戦、市内天寧寺に土方歳三が近藤勇の墓を建立 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットは以下の形式で与えられます。 </p> <pre class=exp> <var>n</var> <var>m</var> <var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>,<var>d<sub>1</sub></var> <var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>,<var>d<sub>2</sub></var> : <var>a<sub>m</sub></var>,<var>b<sub>m</sub></var>,<var>d<sub>m</sub></var> </pre> <p> 各データセットの最初の 1 行には史跡の箇所数 <var>n</var> が与えられます。続いて史跡と史跡を結ぶ通りの数 <var>m</var> が与えられます。続く <var>m</var> 行に カンマで区切られてた3 つの数数 <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>d<sub>i</sub></var> が与えられます。<var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> は史跡の番号です。史跡の番号は 0 番から <var>n</var> - 1 番まで振られています。<var>a<sub>i</sub></var> <var>b<sub>i</sub></var> はそれらを結ぶ通りがあることを示し、<var>d<sub>i</sub></var> は <var>a<sub>i</sub></var> <var>b<sub>i</sub></var> 間の道路の距離を表します。 </p> <p> <var>n</var> が 0 のとき入力の最後とします。データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、必要最小限の灯篭の数を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 4 4 0,1,1500 0,2,2000 1,2,600 1,3,500 0 </pre> <H2>Output for the Sample Input</H2> <pre> 23 </pre>
p00588
<H1>Extraordinary Girl (I)</H1> <p> She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_1002"> </center> <p> Since she is so lazy that she doesn’t want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves. </p> <H2>Input</H2> <p> The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n. </p> <H2>Output</H2> <p> The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case. </p> <H2>Sample Input</H2> <pre> 2 2 YNNNNYYY 4 NYNNYYNNNYNYYNNN </pre> <H2>Output for the Sample Input</H2> <pre> 6 9 </pre>
p00422
<h1>惑星ヤナイヅの資源</h1>  <p> 人類はついに知的生命体の存在する惑星ヤナイヅを発見した。惑星ヤナイヅでは科学が進歩していたので、次第に我々との共同研究が盛んにおこなわれるようになった。 </p> <p> 惑星ヤナイヅではベコという虫が重要な資源とみなされている。ベコは幼虫からう化して成虫になる。ベコの生息域ではベコの幼虫が群れて生息している群生がいくつもあり、そのような群生が一列に並んでいる。惑星ヤナイヅのバイオテクノロジーを使うと、群生に対して以下のような操作ができる。 </p> <ul> <li> 指定した範囲のすべての群生に、同じ数の幼虫を追加する。</li> <li> 指定した範囲のすべての群生で、指定した数の幼虫を成虫にう化させ、う化した幼虫の数の合計を求める。このとき、う化させる幼虫の数を一つだけ指定できる。</li> </ul> <p> 2つ目の操作では、指定した数よりも幼虫の数が少ない群生については、その群生にいるすべての幼虫をう化させる。たとえば、群生1に幼虫が3匹、群生2に幼虫が2匹いる場合、群生1から2の範囲に対してう化させる数3を指定すると、群生1からは3匹、群生2からは2匹を成虫にすることになる。このときにう化した幼虫の数の合計は5匹である。 </p> <p> 今回の共同研究では、我々人類がベコの幼虫に対するこれらの操作のシミュレーションを担当することとなった。ここは我々の科学の力を示すときである。 </p> <p> 各群生に存在する幼虫の情報が与えられたとき、それらに対する操作をシミュレーションするプログラムを作成せよ。 </p> <h2>入力</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> $N$ $c_1$ $c_2$ : $c_N$ $M$ $manip_1$ $manip_2$ : $manip_M$ </pre> <p> 1行目に群生の数$N$ ($1 \leq N \leq 100,000$)が与えられる。続く$N$行に、各群生にいる幼虫の数$c_i$ ($0 \leq c_i \leq 100,000$)が与えられる。 </p> <p>  続く1行に、操作の数$M$ ($1 \leq M \leq 100,000$)が与えられる。続く$M$行に操作の内容が与えられる。各操作の内容は次のいずれかである。 </p> <pre> 1 $a$ $b$ $d$ </pre> <p> または </p> <pre> 2 $a$ $b$ $d$ </pre> <p> 先頭の数字が1のとき、指定した範囲$a$から$b$ ($1 \leq a \leq b \leq N$)の群生に対して、幼虫を$d$匹($1 \leq d \leq 1,000$)追加する。先頭の数字が2のとき、指定した範囲$a$から$b$ ($1 \leq a \leq b \leq N$)の群生に対して、幼虫を$d$匹($1 \leq d \leq 1,000$)だけ成虫にう化させる操作を表す。このとき、実際にう化した幼虫の合計を出力する。また、先頭の数字が2である操作は必ずひとつ以上与えられるものとする。 </p> <h2>出力</h2> <p> 幼虫をう化させる操作ごとに、実際にう化した幼虫の合計を1行に出力する。 </p> <h2>入出力例</h2> <h3>入力例<h3> <pre> 3 1 2 3 3 2 1 3 2 1 1 2 5 2 2 3 3 </pre> <h3>出力例<h3> <pre> 5 4 </pre>
p00971
<h2>Shortest Common Non-Subsequence</h2> <p> A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, "<span>ICPC</span>" is a subsequence of "<span>MICROPROCESSOR</span>". </p> <p> A common subsequence of two sequences is a subsequence of both sequences. The famous longest common subsequence problem is finding the longest of common subsequences of two given sequences. </p> <p> In this problem, conversely, we consider <i>the shortest common non-subsequence problem</i>: Given two sequences consisting of 0 and 1, your task is to find the shortest sequence also consisting of 0 and 1 that is a subsequence of <i>neither</i> of the two sequences. </p> <h3>Input</h3> <p> The input consists of a single test case with two lines. Both lines are sequences consisting only of 0 and 1. Their lengths are between 1 and 4000, inclusive. </p> <h3>Output</h3> <p> Output in one line the shortest common non-subsequence of two given sequences. If there are two or more such sequences, you should output the lexicographically smallest one. Here, a sequence $P$ is lexicographically smaller than another sequence $Q$ of the same length if there exists $k$ such that $P_1 = Q_1, ... , P_{k-1} = Q_{k-1}$, and $P_k < Q_k$, where $S_i$ is the $i$-th character of a sequence $S$. </p> <h3>Sample Input 1</h3> <pre> 0101 1100001 </pre> <h3>Sample Output 1</h3> <pre> 0010 </pre> <h3>Sample Input 2</h3> <pre> 101010101 010101010 </pre> <h3>Sample Output 2</h3> <pre> 000000 </pre> <h3>Sample Input 3</h3> <pre> 11111111 00000000 </pre> <h3>Sample Output 3</h3> <pre> 01 </pre>
p01663
<h2>H - N and K</h2> <p> 1以上<var>N</var>以下の整数からなる狭義単調増加数列で,数列の要素からどの2つの異なる数を取ってきても 他方が一方を割り切ることがないようなものを考える. そのような数列のうち,とりうる最大の長さを<var>L</var>として,そのような数列<var>(a_1,a_2,...,a_L)</var>を考える. この数列の<var>K</var>番目の要素<var>a_K</var>を求めよ.ただし,そのような数列<var>(a_1...a_L)</var>が複数個存在する場合は, <var>a_K</var>の値としてとりうる最小の値を出力せよ. また,<var>K &gt; L</var>のときは-1を出力せよ. </p> <h2>入力形式</h2> <p>入力は複数の入力からなる.入力の数は<var>C</var>セットあり,<var>i</var>番目の入力は<var>N_i, K_i</var>である. テストケースは以下の形式で与えられる.</p> <pre> <var>C</var> <var>N_1</var> <var>K_1</var> … <var>N_C</var> <var>K_C</var> </pre> <h2>出力形式</h2> <p> 出力は<var>C</var>行からなる. <var>i</var>行目の出力は,<var>N_i</var>と<var>K_i</var>についての答えである. </p> <h2>制約</h2> <ul> <li><var>1 \leq C \leq 10^5</var></li> <li><var>1 \leq N_i \leq 10^{18}</var></li> <li><var>1 \leq K_i \leq N_i</var></li> <li>入力値はすべて整数である.</li> </ul> <p> この問題の判定には,50 点分のテストケースのグループが設定されている.このグループに含まれるテストケースは上記の制約に加えて下記の制約も満たす. </p> <ul> <li><var>C=1, N_i \leq 50</var></li> </ul> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 5 3 2 5 2 8 3 10 1 18 12 </pre> <h3>出力例1</h3> <pre> 3 3 5 4 -1 </pre> <p> <var>N=3</var>のとき,2番目に小さい要素が最小となる組み合わせの一例として<var>(2,3)</var>が挙げられる.<br> <var>N=5</var>のとき,2番目に小さい要素が最小となる組み合わせの一例として<var>(2,3,5)</var>が挙げられる.<br> <var>N=8</var>のとき,3番目に小さい要素が最小となる組み合わせの一例として<var>(3,4,5,7)</var>が挙げられる.<br> <var>N=10</var>のとき,1番目に小さい要素が最小となる組み合わせの一例として<var>(4,6,7,9,10)</var>が挙げられる. </p>
p01399
<h2> Problem B: B問題 </h2> <p> R大学の2D好きの人たち (2DRespecters)は、A津大学で開催されるプログラミングの練習合宿に参加する。 この練習合宿では、参加者たちが自作のプログラミング問題を持ち寄り、練習に用いる。 </p> <p> 2DRespectersも、いくつかの問題を作成することになった。 しかし、合宿の3日前になっても、まだ、B問題が完成していなかった。 最初のB問題の担当者が作成した問題は、担当者が問題の制約を難しくし過ぎてしまったため、C問題以降にまわされてしまったのだ。 そして、簡単すぎても、難しすぎてもいけない、微妙な難易度の調整が必要とされるB問題は、誰もが手を付けたがらなかった。 それ以来、B問題担当者の椅子は空席のままである。 </p> <p> 合宿3日前になって、遂に、この問題を解決するために、2DRespecters期待のホープが立ち上がった。 だが、彼は、B問題を作成する気がない。 彼は、自分でB問題を作成したくないので、B問題の作成担当を他者に押し付ける手法を考え出したのだ。 彼の手法は、表面上、B問題の作成担当者を平等に決定する。 </p> <p> 彼の手法は、以下の通りである。 <ul> <li> 問題作成のために要した作業時間が最も少ない人がB問題担当者になる。</li> <li> 作業時間が最も少ない人が複数人居た場合は、より問題難易度の小さい問題の担当者がB問題作成担当者になる。</li> <li> 作業時間が最も少ない人が複数人居て、その中で、問題難易度の最も小さい人が複数人いた場合は、ホープの彼がB問題作成担当者になる。</li> </ul> 彼の手法は、一見、最も仕事をしていない人がB問題の作成を担当するため、2DRespectersのメンバー全員に快く受け入れられた。 </p> <p> しかし、彼の手法には、以下のような裏がある。 <ul> <li> 各個人の作業時間は、各個人が口頭で申請するため、嘘の申請をすることが可能である。</li> <li> 問題の作業可能時間を超える作業時間や負の作業時間を申請すると、嘘だとばれる。</li> <li> ある問題の作成のための作業時間は、必ず問題難易度の整数倍になることが知られているため、これに反する作業時間を申請した場合も、嘘だとばれる。</li> </ul> 嘘の申請をした人の嘘がばれた場合、その人が必ずB問題作成担当者になる。 申請は一人ずつ順番に行い、嘘がばれる場合は、申請の時点でばれる。 一人でも嘘の申請がばれた時点で、B問題作成担当者が決まり、それ以降の申請は行わない。 </p> <p> 申請者は、自分より前の申請のみを考慮し、申請の時点で自分がB問題作成担当者にならないような最小の作業時間を申請するものとする。 申請の時点で、申請者がB問題作成担当者にならないような報告ができない場合は、嘘だとばれないような最大の作業時間を申請する。 </p> <p> 各個人の担当する問題難易度のリストが申請順に与えられたとき、誰がB問題作成担当者になるかを求めるプログラムを作成せよ。 ホープの彼の申請順番は、一番最後である。 </p> <p> なお、本問題はフィクションであり、本問題の作成の経緯とは一切の関係がない。 </p> <h2> Input </h2> <p> 入力は、複数のデータセットからなり、データセットの終わりは、半角スペースで区切られた0が二つだけを含む行で表される。 データセットの総数は40以下である。 データセットの1行目では、整数<i>n</i>(<i>2 &le; n &le; <s>100</s><em> 1,000</em></i>)と整数<i>m</i>(<i>1 &le; m &le; 1,000</i>)が半角スペース区切りで与えられる。 データセットの2行目では、整数<i>a_1</i>, <i>a_2</i>, ..., <i>a_n</i>(<i>1 &le; a_i &le; 1,000</i>, <i>1 &le; i &le; n</i>)が半角スペース区切りで与えられる。 </p> <p> 1行目の<i>n</i>と<i>m</i>は、それぞれ、申請者の数と問題の作業可能時間を表す。 2行目では、申請順に並べられた問題難易度のリストが与えられており、<i>a_i</i>は、問題の難易度を表す。 </p> <h2> Output </h2> <p> それぞれのデータセットごとに、B問題作成担当者の申請順番を1行で出力せよ。 </p> <h2> Sample Input </h2> <pre> 3 100 3 7 4 5 24 4 6 12 3 8 5 1 1 1 2 2 3 0 0 </pre> <h2> Output for Sample Input </h2> <pre> 2 4 5 </pre>
p01233
<h1><font color="#000">Problem K:</font> 電波基地</h1> <p> 20XX年,長年の研究が実を結び, 無線によるエネルギー送受信の技術が実用化された. この技術を利用することで, コストが見合わず今まで電力線を引くことができなかった過疎地にも 電力を供給することが可能となった. この技術には少しくせがあって, どこまでも遠くにエネルギーを送ることができるのだが, 特定の位置でしか電波の受信ができないという制約が存在する. つまり,世界を2次元平面で表し,<var>y</var>軸正の方向を北, <var>x</var>軸正の方向を東とすると, <var>x</var>座標・<var>y</var>座標がともに整数の地点でしか 電波を受信することができない(位相の問題である). また,基地(電波の送受信が可能な設備) から見て8方位(東・西・南・北・北東・北西・南東・南西) の方向にしか電波を送信することができない. </p> <p> この制約のために,目標の場所に電波を直接供給できない場合があるが, これは中継基地を置くことで解決可能である. 例えば,座標 (0, 0) から (3, 7) へは直接エネルギーを送ることができないが, (3, 3) に中継基地を置くことで解決できる. </p> <p> あなたは電力会社のエンジニアで, 顧客からある場所に基地を用意してほしいと言われている. ただし,ある箇所が故障しただけで電力が止まってしまうという問題を避けるため, 新たに基地を敷設する際には,既に建っている2箇所以上の基地から エネルギーを受け取れなくてはいけない. また,基地は同時には1つしか建てることができず, 同じ場所に基地を2つ置くことはできない. 既存の基地の位置が2つ与えられるので, 顧客の要望を満たすためには最低でもあと何件の基地を建てる必要があるかを 求めて欲しい. </p> <h2>Input</h2> <p> 入力は複数のデータセットからなる. </p> <p> 入力の最初の行にデータセット数 <var>N</var> (0 &lt; <var>N</var> &le; 300) が与えられる. 以降の <var>N</var> 行に,それぞれのデータセットが与えられる. </p> <p> 1つのデータセットは1行の文字列からなり, 以下のようにスペースで区切られた6つの整数が与えられる. </p> <p> <var>x</var><sub>1</sub> <var>y</var><sub>1</sub> <var>x</var><sub>2</sub> <var>y</var><sub>2</sub> <var>X</var> <var>Y</var> </p> <p> (<var>x</var><sub>1</sub>, <var>y</var><sub>1</sub>) と (<var>x</var><sub>2</sub>, <var>y</var><sub>2</sub>) は既存の2つの基地の座標であり, (<var>X</var>, <var>Y</var>) は目的地の座標である. 入力で与えられる <var>x</var>, <var>y</var> 座標値は −100000000 &le; <var>x</var>, <var>y</var> &le; 100000000 を満たす. 既存の2つの基地の座標は異なっていることが保証されている. </p> <h2>Output</h2> <p> データセットごとに,敷設する必要のある基地の数を1行で出力せよ. </p> <h2>Sample Input</h2> <pre> 4 0 1 3 2 0 1 1 1 2 2 9 9 0 0 1 4 5 5 0 0 1 4 5 10 </pre> <h2>Output for the Sample Input</h2> <pre> 0 1 2 3 </pre>
p04031
<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>
p03561
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between <var>1</var> and <var>N</var> (inclusive) consisting of integers between <var>1</var> and <var>K</var> (inclusive) are listed.</p> <p>Let the total number of sequences listed in FEIS be <var>X</var>. Among those sequences, find the <var>(X/2)</var>-th (rounded up to the nearest integer) lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,K \leq 3 × 10^5</var></li> <li><var>N</var> and <var>K</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>K</var> <var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the <var>(X/2)</var>-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where <var>X</var> is the total number of sequences listed in FEIS.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 </pre> <p>There are <var>12</var> sequences listed in FEIS: <var>(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3)</var>. The <var>(12/2 = 6)</var>-th lexicographically smallest one among them is <var>(2,1)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 2 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 14 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 3 3 3 3 3 3 3 3 3 3 3 2 2 </pre></section> </div> </span>
p03131
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly <var>K</var> times in total, in the order he likes:</p> <ul> <li>Hit his pocket, which magically increases the number of biscuits by one.</li> <li>Exchange <var>A</var> biscuits to <var>1</var> yen.</li> <li>Exchange <var>1</var> yen to <var>B</var> biscuits.</li> </ul> <p>Find the maximum possible number of biscuits in Snuke's pocket after <var>K</var> operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K,A,B \leq 10^9</var></li> <li><var>K,A</var> and <var>B</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>K</var> <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible number of biscuits in Snuke's pocket after <var>K</var> operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>The number of biscuits in Snuke's pocket after <var>K</var> operations is maximized as follows:</p> <ul> <li>Hit his pocket. Now he has <var>2</var> biscuits and <var>0</var> yen.</li> <li>Exchange <var>2</var> biscuits to <var>1</var> yen. his pocket. Now he has <var>0</var> biscuits and <var>1</var> yen.</li> <li>Hit his pocket. Now he has <var>1</var> biscuits and <var>1</var> yen.</li> <li>Exchange <var>1</var> yen to <var>6</var> biscuits. his pocket. Now he has <var>7</var> biscuits and <var>0</var> yen.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314159265 35897932 384626433 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>48518828981938099 </pre></section> </div> </span>
p03998
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Alice, Bob and Charlie are playing <em>Card Game for Three</em>, as below:</p> <ul> <li>At first, each of the three players has a deck consisting of some number of cards. Each card has a letter <code>a</code>, <code>b</code> or <code>c</code> written on it. The orders of the cards in the decks cannot be rearranged.</li> <li>The players take turns. Alice goes first.</li> <li>If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says <code>a</code>, Alice takes the next turn.)</li> <li>If the current player's deck is empty, the game ends and the current player wins the game.</li> </ul> <p>You are given the initial decks of the players. More specifically, you are given three strings <var>S_A</var>, <var>S_B</var> and <var>S_C</var>. The <var>i</var>-th <var>(1≦i≦|S_A|)</var> letter in <var>S_A</var> is the letter on the <var>i</var>-th card in Alice's initial deck. <var>S_B</var> and <var>S_C</var> describes Bob's and Charlie's initial decks in the same way.</p> <p>Determine the winner of the game.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦|S_A|≦100</var></li> <li><var>1≦|S_B|≦100</var></li> <li><var>1≦|S_C|≦100</var></li> <li>Each letter in <var>S_A</var>, <var>S_B</var>, <var>S_C</var> is <code>a</code>, <code>b</code> or <code>c</code>.</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>S_A</var> <var>S_B</var> <var>S_C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Alice will win, print <code>A</code>. If Bob will win, print <code>B</code>. If Charlie will win, print <code>C</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>aca accc ca </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>A </pre> <p>The game will progress as below:</p> <ul> <li>Alice discards the top card in her deck, <code>a</code>. Alice takes the next turn.</li> <li>Alice discards the top card in her deck, <code>c</code>. Charlie takes the next turn.</li> <li>Charlie discards the top card in his deck, <code>c</code>. Charlie takes the next turn.</li> <li>Charlie discards the top card in his deck, <code>a</code>. Alice takes the next turn.</li> <li>Alice discards the top card in her deck, <code>a</code>. Alice takes the next turn.</li> <li>Alice's deck is empty. The game ends and Alice wins the game.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>abcb aacb bccc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>C </pre></section> </div> </span>
p02370
<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>Topological Sort</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_GRL_tsort"> </center> <br> <p> A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You can obtain the proper sequence of all the tasks by a topological sort. </p> <p> Given a DAG $G$, print the order of vertices after the topological sort. </p> <H2>Input</H2> <p> A directed graph $G$ is given in the following format: <br> $|V|\;|E|$<br> $s_0 \; t_0$<br> $s_1 \; t_1$<br> :<br> $s_{|E|-1} \; t_{|E|-1}$<br> <br> </p> <p> $|V|$ is the number of vertices and $|E|$ is the number of edges in the graph. The graph vertices are named with the numbers $0, 1,..., |V|-1$ respectively. </p> <p> $s_i$ and $t_i$ represent source and target nodes of $i$-th edge (directed). </p> <H2>Output</H2> <p> Print the vertices numbers in order. Print a number in a line. </p> <p> If there are multiple possible solutions, print any one of them (the solution is judged by a special validator). </p> <h2>Constraints</h2> <ul> <li> $1 \leq |V| \leq 10,000$</li> <li> $0 \leq |E| \leq 100,000$</li> <li> There are no parallel edges in $G$</li> <li> There are no self loops in $G$</li> </ul> <H2>Sample Input </H2> <pre> 6 6 0 1 1 2 3 1 3 4 4 5 5 2 </pre> <H2>Sample Output </H2> <pre> 0 3 1 4 5 2 </pre>
p03832
<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> people, conveniently numbered <var>1</var> through <var>N</var>. We want to divide them into some number of groups, under the following two conditions:</p> <ul> <li> <p>Every group contains between <var>A</var> and <var>B</var> people, inclusive.</p> </li> <li> <p>Let <var>F_i</var> be the number of the groups containing exactly <var>i</var> people. Then, for all <var>i</var>, either <var>F_i=0</var> or <var>C≤F_i≤D</var> holds.</p> </li> </ul> <p>Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count 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> <li><var>1≤A≤B≤N</var></li> <li><var>1≤C≤D≤N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to divide the people into groups under the conditions, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 3 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four ways to divide the people:</p> <ul> <li><var>(1,2),(3)</var></li> <li><var>(1,3),(2)</var></li> <li><var>(2,3),(1)</var></li> <li><var>(1,2,3)</var></li> </ul> <p>The following way to divide the people does not count: <var>(1),(2),(3)</var>. This is because it only satisfies the first condition and not the second.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 2 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>105 </pre> <p>The only ways to divide the people under the conditions are the ones where there are two groups of two people, and one group of three people. There are <var>105</var> such ways.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000 1 1000 1 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>465231251 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 3 4 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 </pre> <p>The answer can be <var>0</var>.</p></section> </div> </span>
p02720
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>A positive integer <var>X</var> is said to be a lunlun number if and only if the following condition is satisfied:</p> <ul> <li>In the base ten representation of <var>X</var> (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most <var>1</var>.</li> </ul> <p>For example, <var>1234</var>, <var>1</var>, and <var>334</var> are lunlun numbers, while none of <var>31415</var>, <var>119</var>, or <var>13579</var> is.</p> <p>You are given a positive integer <var>K</var>. Find the <var>K</var>-th smallest lunlun number.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq K \leq 10^5</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>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>15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>23 </pre> <p>We will list the <var>15</var> smallest lunlun numbers in ascending order:<br/> <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var>, <var>6</var>, <var>7</var>, <var>8</var>, <var>9</var>, <var>10</var>, <var>11</var>, <var>12</var>, <var>21</var>, <var>22</var>, <var>23</var>.<br/> Thus, the answer is <var>23</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 </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>13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>21 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3234566667 </pre> <p>Note that the answer may not fit into the <var>32</var>-bit signed integer type.</p></section> </div> </span>
p02235
<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>Longest Common Subsequence</H1> <p> For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \{a,b,c,b,d,a,b\}$ and $Y = \{b,d,c,a,b,a\}$, the sequence $\{b,c,a\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\{b,c,a\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\{b,c,b,a\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\{b,c,b,a\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. </p> <p> Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters. </p> <H2>Input</H2> <p> The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given. </p> <H2>Output</H2> <p> For each dataset, print the length of LCS of $X$ and $Y$ in a line. </p> <H2>Constraints</H2> <ul> <li>$1 \leq q \leq 150$</li> <li>$1 \leq$ length of $X$ and $Y$ $\leq 1,000$</li> <li>$q \leq 20$ if the dataset includes a sequence whose length is more than 100</li> </ul> <H2>Sample Input 1</H2> <pre> 3 abcbdab bdcaba abc abc abc bc </pre> <H2>Sample Output 1</H2> <pre> 4 3 2 </pre> <H2>Reference</H2> <p> Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. </p>
p00208
<H1>病院の部屋番号 </H1> <p> ウォーターデブンに住む建築家のデブンキーさんのもとに、古い大病院を改装する仕事の依頼が舞い込んできました。 </p> <p> 国によっては忌み数(いみかず)として嫌われる数字を部屋番号に用いたくない人がいます(日本では 4 と 9 が有名です)。しかし、この病院の部屋番号は忌み数に関係なく、1 から順番に付けられていました。 </p> <p> それが気になったデブンキーさんは、機材やベッドの入れ替えが全て終わる前にウォーターデブンの忌み数である「4」と「6」を除いた数字で部屋番号を付けなおしてしまいました。しかし、入れ替え作業は旧部屋番号で計画していたので、残りの作業を確実に行うには旧部屋番号を新部屋番号に変換する必要があります。計算が苦手なデブンキーさんはこのことに気づいて愕然としています。 </p> <p> そんなデブンキーさんのために、旧部屋番号を入力とし対応する新部屋番号を出力するプログラムを作成してください。 </p> <p> 15 番目までの部屋番号の対応表は以下のようになります。 </p> <center> <table border=1 cellpadding=0 cellspacing=0> <tr> <td width=100>旧部屋番号</td><td width=24> 1</td><td width=24> 2</td><td width=24> 3</td><td width=24> 4</td><td width=24> 5</td><td width=24> 6</td><td width=24> 7</td><td width=24> 8 </td><td width=24> 9 </td><td width=24> 10 </td><td width=24> 11</td><td width=24> 12</td><td width=24> 13</td><td width=24> 14</td><td width=24> 15</td> </tr> <tr> <td>新部屋番号</td><td> 1</td><td> 2</td><td> 3</td><td> 5 </td><td>7</td><td> 8</td><td> 9</td><td> 10</td><td> 11</td><td> 12</td><td> 13</td><td> 15</td><td> 17</td><td> 18 </td><td>19</td> </tr> </table> </center> <br/> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。 各データセットとして、旧部屋番号を表す整数 <var>n</var> (1 &le; <var>n</var> &le; 1,000,000,000) が1行に与えられます。 </p> <p> データセットの数は 30000 を超えません。 </p> <H2>Output</H2> <p> 入力データセットごとに、新部屋番号を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 15 100 1000000000 3 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 155 9358757000 3 </pre>
p03977
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"><section> <h3>Problem Statement</h3> <p>A professor invented Cookie Breeding Machine for his students who like cookies very much. </p> <p>When one cookie with the taste of <var>x</var> is put into the machine and a non-negative integer <var>y</var> less than or equal to <var>127</var> is input on the machine, it consumes the cookie and generates two cookies with the taste of <var>y</var> and (<var>x</var> XOR <var>y</var>). </p> <p>Here, XOR represents <a href="https://en.wikipedia.org/wiki/Exclusive_or">Bitwise Exclusive OR</a>. </p> <p>At first, there is only one cookie and the taste of it is <var>D</var> . </p> <p>Find the maximum value of the sum of the taste of the exactly <var>N</var> cookies generated after the following operation is conducted <var>N-1</var> times. </p> <ol> <li>Put one of the cookies into the machine. </li> <li>Input a non-negative integer less than or equal to <var>127</var> on the machine. </li> </ol> </section></div> <div class="part"><section> <h3>Constraints</h3> <ul> <li><var>1 \leq T \leq 1000</var></li> <li><var>1 \leq N_t \leq 1000</var> <var>(1 \leq t \leq T)</var></li> <li><var>1 \leq D_t \leq 127</var> <var>(1 \leq t \leq T)</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>T</var> <var>N_1</var> <var>D_1</var> : <var>N_T</var> <var>D_T</var> </pre> <p> The input consists of multiple test cases. An Integer <var>T</var> that represents the number of test cases is given on line <var>1</var>. <br/> Each test case is given on the next <var>T</var> lines. <br/> In the <var>t</var>-th test case (<var> 1 \leq t \leq T </var>), <var>N_t</var> that represents the number of cookies generated through the operations and <var>D_t</var> that represents the taste of the initial cookie are given separated by space. <br/> </p> </section></div> <div class="part"><section> <h3>Output</h3> <p>For each test case, print the maximum value of the sum of the taste of the <var>N</var> cookies generated through the operations on one line. </p> </section></div> </div> <hr/> <div class="part"><section> <h3>Sample Input 1</h3> <pre> 3 3 1 4 108 1 10 </pre> </section></div> <div class="part"><section> <h3>Sample Output 1</h3> <pre> 255 400 10 </pre> <p> On the 1st test case, if the machine is used as follows, three cookies with the taste of <var>61</var>, <var>95</var> and <var>99</var> are generated. Since the sum of these values is maximum among all possible ways, the answer is <var>255</var>. <ol> <li>Put the cookie with the taste of <var>1</var> and input an integer <var>60</var> on the machine, lose the cookie and get two cookies with the taste of <var>60</var> and <var>61</var>. </li> <li>Put the cookie with the taste of <var>60</var> and input an integer <var>99</var> on the machine, lose the cookie and get two cookies with the taste of <var>99</var> and <var>95</var>. </li> </ol> </p> <p> On the 3rd test case, the machine may not be used. </p> </section></div> </span>
p02665
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is an integer sequence of length <var>N+1</var>: <var>A_0, A_1, A_2, \ldots, A_N</var>. Is there a binary tree of depth <var>N</var> such that, for each <var>d = 0, 1, \ldots, N</var>, there are exactly <var>A_d</var> leaves at depth <var>d</var>? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print <var>-1</var>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><ul> <li>A binary tree is a rooted tree such that each vertex has at most two direct children.</li> <li>A leaf in a binary tree is a vertex with zero children.</li> <li>The depth of a vertex <var>v</var> in a binary tree is the distance from the tree's root to <var>v</var>. (The root has the depth of <var>0</var>.)</li> <li>The depth of a binary tree is the maximum depth of a vertex in the tree.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq N \leq 10^5</var></li> <li><var>0 \leq A_i \leq 10^{8}</var> (<var>0 \leq i \leq N</var>)</li> <li><var>A_N \geq 1</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_0</var> <var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>Below is the tree with the maximum possible number of vertices. It has seven vertices, so we should print <var>7</var>. <div style="text-align: center;"> <img alt="0d8d99d13df036f23b0c9fcec52b842b.png" src="https://img.atcoder.jp/nomura2020/0d8d99d13df036f23b0c9fcec52b842b.png"> </img></div></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 0 0 1 0 2 </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>2 0 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>10 0 0 1 1 2 3 5 8 13 21 34 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>264 </pre></section> </div> </span>
p00658
<H1>Problem L: The Tower</H1> <p> Your task is to write a program that reads some lines of command for the following game and simulates operations until the player reaches the game over. We call following 2-dimensional grid of <i>m</i> by <i>n</i> characters Tower. The objective of this game is to move blocks in the tower to climb to a goal block. In the following grid, the bottom line is the first row and the top one is the <i>n</i>-th row. The leftmost column is the first column and the rightmost one is the <i>m</i>-th column. </p> <pre> .................... (<i>n</i>=13 th row) .....#.....G........ ....##.....##.....## ...####...IIII...### ..####.....##.....## ...####B..####....## ....###....#33##..## .....####...#33#3.## .##CCCC#####2##.#### ..#####..###.#...### ...###....###.....#1 ....####..##.......# S..###..#.####.....# (1st row) </pre> <p><strong>Explanation of cell marks:</strong></p> <ul> <li>'#' : Normal block<br>Normal block.</li> <li>'I' : Ice block<br>Block made of the ice. This has different features from the normal one.</li> <li>'G' : Goal block<br>If the player climbs to this, game is over and clear.</li> <li>'C' : Fixed block<br>The player can not move this directly.</li> <li>'B' : Different dimensional block<br>If the player climbs to this, game is over and lose.</li> <li>'.' : Space<br>Empty place.</li> <li>'3' : Fragile block(3)<br>A fragile block of count 3.</li> <li>'2' : Fragile block(2)<br>A fragile block of count 2.</li> <li>'1' : Fragile block(1)<br>A fragile block of count 1. If the count is zero, this block will be broken and become a space.</li> <li>'S' : Player<br>The player.</li> </ul> <p><strong>Explanation of relative positions:</strong></p> <pre> 123 4S5 678 </pre> <p> In the following description, assume that left up is the position of 1, up(over S) is 2, right up is 3, left is 4, right is 5, left down is 6, down(under S) is 7, right down is 8 for S. </p> <p><strong>Movements of the player</strong><br> The player must not go out of the tower. The outside of the tower is considered as space cells. </p> <ul> <li>Move<br>The player can move everywhere in the current row as long as some of the following conditions are satisfied. <ul> <li>The player is in the first row and the target cell is a space.</li> <li>There are blocks under the route connecting the current cell and the target cell (horizontal segment) and the target cell is a space. It is OK that some blocks in the horizontal segment. And the case that some of blocks under the segment are different dimensional ones, it is also OK.</li> </ul> </li> <li>Climb<br> If the player at the row below the n-th row (from 1st to n-1 th row) and there is a block in the right(left) and both of a cell over the player (up cell) and a right up(left up) cell are space, the player can move to the right up(left up) cell.</li> <li>Get down<br> If the player at the row above the 1st row (from 2nd to n-th row), he can get down to right(left) down. If the direction for getting down is right(left) and if there is no blocks in the right down (left down) cell and the right (left) cell, the player can move to the right down (left down) cell.</li> <li>Push<br> If there is a block or continuous blocks in the right or left of the player, he can push the blocks to the direction one cell. Here, blocks are "continuous" if there are two or more blocks and no space exist between them. However, if there is a fixed block in pushing blocks, the player can not push them. Pushed blocks will not stop the end of the row of the tower (1st and mth column). If the pushed blocks go out of the tower, this will be vanished.<br>In the result of pushing, a block moved over the ice block continues to move to the pushed direction as long as there is a space in the progress direction, there is an ice block under the block and the pushed block is not vanished.<br> If the pushed block is an ice block, this continues to move to the pushed direction as long as there is a block under the ice block, there is a space in the progress direction and the pushed ice block is not vanished. However, for an ice block in the first row, the below the block do not have to be a space. And here, if the player pushes continuous blocks, pushing movements begin from the most distant block to a nearest block. Here, the distance is manhattan distance at the gird.</li> <li>Pull<br> If there is a block in the right(left) of the player and the left(right) cell is space, the player can pull the block. However, if the pulling block is fixed one, he can not pull this. If the player pulls block, the player will move one cell to the direction of pulling.</li> </ul> <p> <strong>Automated operations after the player operation:</strong><br> Automated operations occur in the following order. This repeats in this order as long as the cells of the tower are changed by this operations. After this operations, the player can do the next operation. </p> <ul> <li>Countdown of fragile blocks<br> If the player over a fragile block moved to somewhere else, that fragile block's count will decrease by one. However, this count does not change if the player over the fragile block is moved to somewhere else by the automated operations.</li> <li>Erasing blocks<br>A block over an different dimensional block will be vanished.</li> <li>Falling of the player<br>If there is no block under the player, the player continues to fall as long as satisfying this condition or come to 1st row.</li> <li>Falling of blocks<br>If there is no block under a block and left down and right down of a certain block, the block in the row over the 1st row (from 2nd to n-th row) continues to fall as long as satisfying this condition. Falling of blocks begins from lower blocks of the tower and then lefter blocks.</li> </ul> <p><strong>Conditions for game over:</strong><br> After the movement of the player or the automated operations, the game is over when the one of next conditions is satisfied. These conditions are judged in the following order. Note that, the condition (E) should not be judged after the movement of the player. </p> <ul> <li>(A) The player is over the goal block.</li> <li>(B) The player is over the different dimensional block.</li> <li>(C) The player and a block is in the same cell.</li> <li>(D) The goal block is moved from its initial position.</li> <li>(E) There is no next commands.</li> </ul> <p>Finally, show some examples.<br> Documents of commands will be give in the description of Input.</p> <table class="withborder" border=1 style='font-family:monospace;'> <caption>Example table</caption> <tr><th>Movement or<br>Automated operation</th><th>Before</th><th>After</th><th>Command</th></tr> <tr><td>Move</td><td>.#S<br>###</td><td>S#.<br>###</td><td>MOVETO 1</td> <tr><td>Climb</td><td>...<br>3S#</td><td>S..<br>3.#</td><td>CLIMB LEFT</td> <tr><td>Get down</td><td>S..<br>3.#</td><td>...<br>2S#</td><td>GETDOWN RIGHT</td> <tr><td>Push</td><td>.#S#####..<br>###II.I.I.</td><td>.#S.####.#<br>###II.I.I.</td><td>PUSH RIGHT</td> <tr><td>Push</td><td>.#SI...<br>###.###</td><td>.#S....<br>###.###</td><td>PUSH RIGHT</td> <tr><td>Push</td><td>.#...S#<br>###.###</td><td>.....S.<br>###.###</td><td>PUSH RIGHT</td> <tr><td>Pull</td><td>..S#####..<br>###.#.#.#.</td><td>.S#.####..<br>###.#.#.#.</td><td>PULL LEFT</td> <tr><td>Falling of the player</td><td>.#S#<br>.#.#<br>.#.#<br>.#.#</td><td>.#.#<br>.#.#<br>.#.#<br>.#S#<td>-</td> <tr><td>Falling of blocks</td><td>.###.<br>#...#<br>#...#<br>#...#<br>.#.#</td><td>.#.#.<br>#...#<br>#...#<br>#.#.#<br>.#.#<td>-</td> </table> <h2>Input</h2> <p> Input consists of multiple datasets.<br> A dataset is given in the following format. </p> <pre> <i>n</i> <i>m</i> <i>D<sub>n,1</sub></i> <i>D<sub>n,2</sub></i> ... <i>D<sub>n,m</sub></i> <i>D<sub>n-1,1</sub></i> <i>D<sub>n-1,2</sub></i> ... <i>D<sub>n-1,m</sub></i> ... <i>D<sub>1,1</sub></i> <i>D<sub>1,2</sub></i> ... <i>D<sub>1,m</sub></i> <i>T</i> <i>Command<sub>1</sub></i> <i>Command<sub>2</sub></i> ... <i>Command<sub>T</sub></i> </pre> <p> Here, <i>m</i>, <i>n</i> is the width and height of the tower. <i>D<sub>i,j</sub></i>(1&le;<i>i</i>&le;<i>n</i> and 1&le;<i>j</i>&le;<i>m</i>) is a mark of the cell. The explanation of marks described above. <i>Command<sub>k</sub></i>(1&le;<i>k</i>&le;<i>T</i>) is the <i>k</i>-th player operation (movement). This is a string and one of following strings. </p> <pre> "MOVETO s" means move to <i>s</i>-th column cell in the same row. "PUSH RIGHT" means push right block(s). "PUSH LEFT" means push left block(s). "PULL RIGHT" means pull the left block to right. "PULL LEFT" means pull the right block to left. "GETDOWN RIGHT" means get down to right down. "GETDOWN LEFT" means get down to left down. "CLIMB RIGHT" means climb to the right block. "CLIMB LEFT" means climb to the left block. </pre> <p> Some of commands are invalid. You must ignore these commands. And after game is over, the command input may continue in case. In this case, you must also ignore following commands. <i>m</i>=<i>n</i>=0 shows the end of input. </p> <h2>Constraints</h2> <p> 3&le;<i>m</i>&le;50<br> 3&le;<i>n</i>&le;50<br> Characters 'S' and 'G' will appear exactly once in the tower description. </p> <h2>Output</h2> <p> Each dataset, output a string that represents the result of the game in the following format. </p> <pre> <i>Result</i> </pre> <p>Here, <i>Result</i> is a string and one of the following strings (quotes for clarity).</p> <ul> <li>"Game Over : Cleared" (A)</li> <li>"Game Over : Death by Hole" (B)</li> <li>"Game Over : Death by Block" (C)</li> <li>"Game Over : Death by Walking Goal" (D)</li> <li>"Game Over : Gave Up" (E)</li> </ul> <h2>Sample Input</h2> <pre> 8 8 ........ ........ ....###. ...#.#.G S#B...## #ICII.I# #..#.#.# .#..#.#. 7 PUSH RIGHT MOVETO 2 CLIMB RIGHT CLIMB RIGHT GETDOWN RIGHT CLIMB RIGHT GETDOWN RIGHT 8 8 ........ ........ ........ ...G.... S#B..... #ICIIIII #..#.#.# .#..#.#. 4 PUSH RIGHT MOVETO 2 CLIMB RIGHT CLIMB RIGHT 8 8 ........ ....#.#. .....#.G ...#..#. S#B....# #ICIII.# #..#.#.# .#..#.#. 8 PUSH RIGHT MOVETO 2 CLIMB RIGHT CLIMB RIGHT CLIMB RIGHT GETDOWN RIGHT CLIMB RIGHT GETDOWN RIGHT 0 0 </pre> <h2>Sample Output</h2> <pre> Game Over : Death by Hole Game Over : Cleared Game Over : Death by Walking Goal </pre>
p01419
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>On or Off</H1> <p> Saving electricity is very important! </p> <p> You are in the office represented as <var>R \times C</var> grid that consists of walls and rooms. It is guaranteed that, for any pair of rooms in the office, there exists exactly one route between the two rooms. It takes 1 unit of time for you to move to the next room (that is, the grid adjacent to the current room). Rooms are so dark that you need to switch on a light when you enter a room. When you leave the room, you can either leave the light on, or of course you can switch off the light. Each room keeps consuming electric power while the light is on. </p> <p> Today you have a lot of tasks across the office. Tasks are given as a list of coordinates, and they need to be done in the specified order. To save electricity, you want to finish all the tasks with the minimal amount of electric power. </p> <p> The problem is not so easy though, because you will consume electricity not only when light is on, but also when you switch on/off the light. Luckily, you know the cost of power consumption per unit time and also the cost to switch on/off the light for all the rooms in the office. Besides, you are so smart that you don't need any time to do the tasks themselves. So please figure out the optimal strategy to minimize the amount of electric power consumed. </p> <p> After you finished all the tasks, please DO NOT leave the light on at any room. It's obviously wasting! </p> <H2>Input</H2> <p> The first line of the input contains three positive integers <var>R</var> (<var>0 \lt R \leq 50</var>), <var>C</var> (<var>0 \lt C \leq 50</var>) and <var>M</var> (<var>2 \leq M \leq 1000</var>). The following <var>R</var> lines, which contain <var>C</var> characters each, describe the layout of the office. '.' describes a room and '#' describes a wall. </p> <p> This is followed by three matrices with <var>R</var> rows, <var>C</var> columns each. Every elements of the matrices are positive integers. The <var>(r, c)</var> element in the first matrix describes the power consumption per unit of time for the room at the coordinate <var>(r, c)</var>. The <var>(r, c)</var> element in the second matrix and the third matrix describe the cost to turn on the light and the cost to turn off the light, respectively, in the room at the coordinate <var>(r, c)</var>. </p> <p> Each of the last <var>M</var> lines contains two positive integers, which describe the coodinates of the room for you to do the task. </p> <p> Note that you cannot do the <var>i</var>-th task if any of the <var>j</var>-th task (<var>0 \leq j \leq i</var>) is left undone. </p> <H2>Output</H2> <p> Print one integer that describes the minimal amount of electric power consumed when you finished all the tasks. </p> <H2>Sample Input 1</H2> <pre> 1 3 2 ... 1 1 1 1 2 1 1 1 1 0 0 0 2 </pre> <H2>Output for the Sample Input 1</H2> <pre> 7 </pre> <H2>Sample Input 2</H2> <pre> 3 3 5 ... .## ..# 1 1 1 1 0 0 1 1 0 3 3 3 3 0 0 3 3 0 5 4 5 4 0 0 5 4 0 1 0 2 1 0 2 2 0 0 0 </pre> <H2>Output for the Sample Input 2</H2> <pre> 77 </pre> <H2>Sample Input 3</H2> <pre> 5 5 10 #.### #.... ###.# ..#.# #.... 0 12 0 0 0 0 4 3 2 10 0 0 0 99 0 11 13 0 2 0 0 1 1 2 1 0 4 0 0 0 0 13 8 2 4 0 0 0 16 0 1 1 0 2 0 0 2 3 1 99 0 2 0 0 0 0 12 2 12 2 0 0 0 3 0 4 14 0 16 0 0 2 14 2 90 0 1 3 0 4 4 1 4 1 1 4 4 1 1 4 3 3 0 1 4 </pre> <H2>Output for the Sample Input 3</H2> <pre> 777 </pre>
p03424
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In Japan, people make offerings called <em>hina arare</em>, colorful crackers, on March <var>3</var>.</p> <p>We have a bag that contains <var>N</var> hina arare. (From here, we call them arare.)</p> <p>It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.</p> <p>We have taken out the arare in the bag one by one, and the color of the <var>i</var>-th arare was <var>S_i</var>, where colors are represented as follows - pink: <code>P</code>, white: <code>W</code>, green: <code>G</code>, yellow: <code>Y</code>.</p> <p>If the number of colors of the arare in the bag was three, print <code>Three</code>; if the number of colors was four, print <code>Four</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>S_i</var> is <code>P</code>, <code>W</code>, <code>G</code> or <code>Y</code>.</li> <li>There always exist <var>i</var>, <var>j</var> and <var>k</var> such that <var>S_i=</var><code>P</code>, <var>S_j=</var><code>W</code> and <var>S_k=</var><code>G</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>S_1</var> <var>S_2</var> <var>...</var> <var>S_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the number of colors of the arare in the bag was three, print <code>Three</code>; if the number of colors was four, print <code>Four</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 G W Y P Y W </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Four </pre> <p>The bag contained arare in four colors, so you should print <code>Four</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 G W W G P W P G G </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Three </pre> <p>The bag contained arare in three colors, so you should print <code>Three</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 P Y W G Y W Y Y </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Four </pre></section> </div> </span>
p01049
<h1>Array Update</h1> <h2>Problem</h2> <p> 項数 <var>N</var>、初項 <var>a</var>、公差 <var>d</var> の等差数列 <var>A</var> がある。以下の形式で数列を更新する命令文が <var>M</var> 個与えられるので、与えられた順序で数列 <var>A</var> を <var>M</var> 回更新したときの <var>K</var> 項目の値を求めよ。 </p> <ul> <li> <var>i</var> 番目の命令文は3つの整数 <var> x<sub>i</sub> , y<sub>i</sub> , z<sub>i</sub> </var>で表される(1 &le; <var>i</var> &le; <var>M</var>)。<br> </li> <li> <var>x<sub>i</sub></var>が0だった場合、<var>y<sub>i</sub></var>項目の値と <var>z<sub>i</sub></var>項目の値を入れ替える。<br> </li> <li> <var>x<sub>i</sub></var>が1だった場合、<var>y<sub>i</sub></var>項目の値を <var>z<sub>i</sub></var>項目の値に書き換える。 <br> </li> </ul> <h2>Input</h2> <pre> <var>N</var> <var>a</var> <var>d</var> <var>M</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var> ... <var>x<sub>M</sub></var> <var>y<sub>M</sub></var> <var>z<sub>M</sub></var> <var>K</var> </pre> <p> 1行目に、1つの整数 <var>N</var> が与えられる。 2行目に、2つの整数 <var>a</var> と <var>d</var> が空白区切りで与えられる。 3行目に、1つの整数 <var>M</var> が与えられる。 4行目からの <var>M</var> 行のうち <var>i</var> 行目には <var>i</var> 番目の命令文を表す 3 つの整数 <var>x<sub>i</sub>, y<sub>i</sub>, z<sub>i</sub></var> が空白区切りで与えられる。 最後の行に、1つの整数 <var>K</var> が与えられる。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>N</var> &le; 10<sup>8</sup></li> <li>1 &le; <var>a</var> &le; 5</li> <li>1 &le; <var>d</var> &le; 5</li> <li>1 &le; <var>M</var> &le; 10</li> <li>0 &le; <var>x<sub>i</sub></var> &le; 1 (1 &le; <var>i</var> &le; <var>M</var>)</li> <li>1 &le; <var>y<sub>i</sub></var> &le; <var>N</var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li>1 &le; <var>z<sub>i</sub></var> &le; <var>N</var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li><var>y<sub>i</sub></var> &ne; <var>z<sub>i</sub></var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li>1 &le; <var>K</var> &le; <var>N</var></li> </ul> <h2>Output</h2> <p> 入力で与えられた順番で数列<var>A</var>を<var>M</var>回更新したときの<var>K</var>項目を出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 5 2 3 3 0 2 5 0 3 5 1 2 4 2 </pre> <h2>Sample Output 1</h2> <pre> 11 </pre> <p> { 2 , 5 , 8 , 11 , 14 }<br>   ↓<br> 0 2 5 … 2項目の値と5項目の値を入れ替える<br>   ↓<br> { 2 , 14 , 8 , 11 , 5 }<br>   ↓<br> 0 3 5 … 3項目の値と5項目の値を入れ替える<br>   ↓<br> { 2 , 14 , 5 , 11 , 8 }<br>   ↓<br> 1 2 4 … 2項目の値を4項目の値に書き換える<br>   ↓<br> { 2 , 11 , 5 , 11 , 8 }<br> よって2項目は11である。 </p> <h2>Sample Input 2</h2> <pre> 6 5 5 4 0 1 2 1 1 2 0 4 1 1 1 6 3 </pre> <h2>Sample Output 2</h2> <pre> 15 </pre>
p03074
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>N</var> people are arranged in a row from left to right.</p> <p>You are given a string <var>S</var> of length <var>N</var> consisting of <code>0</code> and <code>1</code>, and a positive integer <var>K</var>.</p> <p>The <var>i</var>-th person from the left is standing on feet if the <var>i</var>-th character of <var>S</var> is <code>0</code>, and standing on hands if that character is <code>1</code>.</p> <p>You will give the following direction at most <var>K</var> times (possibly zero):</p> <p><strong>Direction</strong>: Choose integers <var>l</var> and <var>r</var> satisfying <var>1 \leq l \leq r \leq N</var>, and flip the <var>l</var>-th, <var>(l+1)</var>-th, <var>...</var>, and <var>r</var>-th persons. That is, for each <var>i = l, l+1, ..., r</var>, the <var>i</var>-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands.</p> <p>Find the maximum possible number of <strong>consecutive</strong> people standing on hands after at most <var>K</var> directions.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an integer satisfying <var>1 \leq N \leq 10^5</var>.</li> <li><var>K</var> is an integer satisfying <var>1 \leq K \leq 10^5</var>.</li> <li>The length of the string <var>S</var> is <var>N</var>.</li> <li>Each character of the string <var>S</var> is <code>0</code> or <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>N</var> <var>K</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible number of consecutive people standing on hands after at most <var>K</var> directions.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 00010 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>We can have four consecutive people standing on hands, which is the maximum result, by giving the following direction:</p> <ul> <li>Give the direction with <var>l = 1, r = 3</var>, which flips the first, second and third persons from the left.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>14 2 11101010110011 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p>No directions are necessary.</p></section> </div> </span>
p00571
<h1>美術展(Art Exhibition)</h1> <p> JOI 国で美術展が行われることになった.美術展では,国中から集まった様々な美術品が展示される予定である. </p> <p> 展示される美術品の候補として,<var>N</var> 点の美術品が集まった.これらの美術品には<var>1, 2, ..., N</var> の番号が付けられている.それぞれの美術品には大きさと価値と呼ばれる値が定まっている.美術品<var>i</var> <var>(1 \leq i \leq N)</var> の大きさは<var>A_i</var>,価値は<var>B_i</var> である. </p> <p> 美術展では,これらの美術品のうちから1 点以上を選んで展示する.美術展の会場は十分に広く,<var>N</var> 点の美術品すべてを展示することも可能である.しかし,JOI 国の人々の美的感覚のため,美術品の間で大きさの差があまり大きくならないように展示する美術品を選びたい.一方,できるだけ価値の大きい美術品を多く展示したい.そのため,次の条件を満たすように展示する美術品を選ぶことにした: </p> <ul> <li> 選んだ美術品の中で,大きさが最大のものの大きさを<var>A_{max}</var>,最小のものの大きさを<var>A_{min}</var> とする.また,選んだ美術品の価値の総和を<var>S</var> とする.</li> <li> このとき,<var>S - (A_{max} - A_{min})</var> を最大化する.</li> </ul> <h3>課題</h3> <p> 展示される美術品の候補の個数と,それぞれの美術品の大きさと価値が与えられたとき,<var>S - (A_{max} - A_{min})</var>の最大値を求めよ. </p> <h3>入力</h3> <p> 標準入力から以下の入力を読み込め. </p> <ul> <li> 1 行目には,整数<var>N</var> が書かれている.これは,展示される美術品の候補の個数を表す.</li> <li> 続く<var>N</var> 行のうちの<var>i</var> 行目(<var>1 \leq i \leq N</var>) には,2 個の整数<var>A_i, B_i</var> が空白を区切りとして書かれている.これらは,美術品<var>i</var> の大きさが<var>A_i</var>,価値が<var>B_i</var> であることを表す. </ul> <h3>出力</h3> <p> 標準出力に,<var>S - (A_{max} - A_{min})</var> の最大値を1 行で出力せよ. </p> <h3>制限</h3> <p> すべての入力データは以下の条件を満たす. </p> <ul> <li><var> 2 \leq N \leq 500 000.</var></li> <li><var> 1 \leq A_i \leq 1 000 000 000 000 000 = 10^{15} (1 \leq i \leq N).</var></li> <li><var> 1 \leq B_i \leq 1 000 000 000 (1 \leq i \leq N).</var></li> </ul> <!-- 小課題 小課題1 [10 点] N ≦ 16 を満たす. 小課題2 [20 点] N ≦ 300 を満たす. 小課題3 [20 点] N ≦ 5000 を満たす. 小課題4 [50 点] 追加の制限はない. --> <h3>入出力例</h3> <h3>入力例1</h3> <pre> 3 2 3 11 2 4 5 </pre> <h3>出力例1</h3> <pre> 6 </pre> <p> この入力例では,展示される美術品の候補が3 点ある.それぞれの美術品の大きさ,価値は次の通りである. </p> <ul> <li> 美術品1 の大きさは2,価値は3 である.</li> <li> 美術品2 の大きさは11,価値は2 である.</li> <li> 美術品3 の大きさは4,価値は5 である.</li> </ul> <p> この場合,美術品1 と美術品3 を展示するために選ぶと,次のようにして<var>S - (A_{max} - A_{min}) = 6</var> となる. </p> <ul> <li> 選んだ中で大きさが最大の美術品は,美術品3 である.よって,<var>A_{max} = 4</var> である.</li> <li> 選んだ中で大きさが最小の美術品は,美術品1 である.よって,<var>A_{min} = 2</var> である.</li> <li> 選んだ美術品の価値の総和は<var>3 + 5 = 8</var> であるから,<var>S = 8</var> である.</li> </ul> <p> <var>S - (A_{max} - A_{min})</var> を7 以上にすることは不可能なので,6 を出力する. </p> <h3>入力例2</h3> <pre> 6 4 1 1 5 10 3 9 1 4 2 5 3 </pre> <h3>出力例2</h3> <pre> 7 </pre> <h3>入力例3 </h3> <pre> 15 1543361732 260774320 2089759661 257198921 1555665663 389548466 4133306295 296394520 2596448427 301103944 1701413087 274491541 2347488426 912791996 2133012079 444074242 2659886224 656957044 1345396764 259870638 2671164286 233246973 2791812672 585862344 2996614635 91065315 971304780 488995617 1523452673 988137562 </pre> <h3>出力例3</h3> <pre> 4232545716 </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>
p00121
<H1>7 パズル</H1> <p> 7 パズルは 8 つの正方形のカードとこれらのカードがぴたりと収まる枠で構成されています。それぞれのカードには、互いに区別できるように 0, 1, 2, ..., 7 と番号がつけられています。枠には、縦に 2 個、横に 4 個のカードを並べることができます。 </p> <p> 7 パズルを始めるときには、まず枠にすべてのカードを入れます。枠のなかで 0 のカードだけは、上下左右に隣接するカードと位置を交換することができます。たとえば、枠の状態が図(a) のときに、0 のカードの右に隣接した、7 のカードと位置を交換すれば、図(b) の状態になります。あるいは、図(a) の状態から 0 のカードの下に隣接した 2 のカードと位置を交換すれば図(c) の状態になります。図(a) の状態で 0 のカードと上下左右に隣接するカードは 7 と 2 のカードだけなので、これ以外の位置の入れ替えは許されません。 </p> <p> ゲームの目的は、カードをきれいに整列して図(d) の状態にすることです。最初の状態を入力とし、カードをきれいに整列するまでに、必要な最小手数を出力するプログラムを作成してください。ただし、入力されたカードの状態からは図(d) の状態に移ることは可能であるとします。 </p> <p> 入力データは、1 行に 8 つの数字が空白区切りで与えられます。これらは、最初の状態のカードの並びを表します。例えば、図(a) の数字表現は<span>0 7 3 4 2 5 1 6</span> に、図(c) は <span>2 7 3 4 0 5 1 6</span> となります。 </p> <center> <table> <tr> <td width="280"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_sevenpuzzle1" width="240"></td> <td width="280"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_sevenpuzzle2" width="240"></td> </tr> <tr> <th>図(a) <span>0 7 3 4 2 5 1 6</span> の場合</th> <th>図(b) <span>7 0 3 4 2 5 1 6</span> の場合</th> </tr> </table> <br><br> <table> <tr> <td width="280"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_sevenpuzzle3" width="240"></td> <td width="280"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_sevenpuzzle4" width="240"></td> </tr> <tr> <th>図(c) <span>2 7 3 4 0 5 1 6</span> の場合</th> <th>図(d) <span>0 1 2 3 4 5 6 7</span> (最終状態)</th> </tr> </table> </center> <br/> <H2>Input</H2> <p> 上記形式で複数のパズルが与えられます。入力の最後まで処理してください。 与えられるパズルの数は 1,000 以下です。 </p> <H2>Output</H2> <p> 各パズルについて、最終状態へ移行する最小手数を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 1 28 </pre>
p01360
<H1><font color="#000">Problem B:</font> Step Step Evolution</H1> <p> Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown in the front screen. </p> <p> There are eight types of direction arrows in the Step Step Evolution: UP, UPPER RIGHT, RIGHT, LOWER RIGHT, DOWN, LOWER LEFT, LEFT, and UPPER LEFT. These direction arrows will scroll upward from the bottom of the screen. When the direction arrow overlaps the stationary arrow nearby the top, then the player must step on the corresponding arrow panel on the dance platform. The figure below shows how the dance platform looks like. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_stepstep1"><br> <p> Figure 1: the dance platform for Step Step Evolution </p> </center> <p> In the game, you have to obey the following rule: </p> <ul> <li> Except for the beginning of the play, you must not press the arrow panel which is not correspond to the edit data.</li> <li> The foot must stay upon the panel where it presses last time, and will not be moved until it’s going to press the next arrow panel.</li> <li>The left foot must not step on the panel which locates at right to the panel on which the right foot rests. Conversely, the right foot must not step on the panel which locates at left to the panel on which the left foot rests.</li> </ul> <p> As for the third condition, the following figure shows the examples of the valid and invalid footsteps. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_stepstep2"><br> <p> Figure 2: the examples of valid and invalid footsteps </p> </center> <p> The first one (left foot for LEFT, right foot for DOWN) and the second one (left foot for LOWER LEFT, right foot for UPPER LEFT) are valid footstep. The last one (left foot for RIGHT, right foot for DOWN) is invalid footstep. </p> <p> Note that, at the beginning of the play, the left foot and right foot can be placed anywhere at the arrow panel. Also, you can start first step with left foot or right foot, whichever you want. </p> <p> To play this game in a beautiful way, the play style called “ Natural footstep style” is commonly known among talented players. “Natural footstep style” is the style in which players make steps by the left foot and the right foot in turn. However, when a sequence of arrows is difficult, players are sometimes forced to violate this style. </p> <p> Now, your friend has created an edit data (the original sequence of direction arrows to be pushed) for you. You are interested in how many times you have to violate “Natural footstep style” when you optimally played with this edit data. In other words, what is the minimum number of times you have to step on two consecutive arrows using the same foot? </p> <H2>Input</H2> <p> The input consists of several detasets. Each dataset is specified by one line containing a sequence of direction arrows. Directions are described by numbers from 1 to 9, except for 5. The figure below shows the correspondence between numbers and directions. </p> <p> You may assume that the length of the sequence is between 1 and 100000, inclusive. Also, arrows of the same direction won’t appear consecutively in the line. The end of the input is indicated by a single “<span>#</span>”. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_stepstep3"><br> <p> Figure 3: the correspondence of the numbers to the direction arrows </p> </center> <H2>Output</H2> <p> For each dataset, output how many times you have to violate “Natural footstep style” when you play optimally in one line. </p> <H2>Sample Input</H2> <pre> 1 12 123 369 6748 4247219123 1232123212321232 # </pre> <H2>Output for the Sample Input</H2> <pre> 0 0 1 0 1 2 7 </pre>
p00988
<h2>Fun Region</h2> <p> Dr. Ciel lives in a planar island with a polygonal coastline. She loves strolling on the island along spiral paths. Here, a path is called <i>spiral</i> if both of the following are satisfied. </p> <ul> <li> The path is a simple planar polyline with no self-intersections.</li> <li> At all of its vertices, the line segment directions turn clockwise.</li> </ul> <p> Four paths are depicted below. Circle markers represent the departure points, and arrow heads represent the destinations of paths. Among the paths, only the leftmost is spiral. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_fun_region_1" width="600"/> </center> <p> Dr. Ciel finds a point <i>fun</i> if, for all of the vertices of the island’s coastline, there exists a spiral path that starts from the point, ends at the vertex, and does not cross the coastline. Here, the spiral path may touch or overlap the coastline. </p> <p> In the following figure, the outer polygon represents a coastline. The point &#9733; is fun, while the point &#10006; is not fun. Dotted polylines starting from &#9733; are valid spiral paths that end at coastline vertices. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_fun_region_2" width="400"/> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_fun_region_3" width="600"/><br> Figure J.1. Samples 1, 2, and 3. </center> <p> We can prove that the set of all the fun points forms a (possibly empty) connected region, which we call the <i>fun region</i>. Given the coastline, your task is to write a program that computes the area size of the fun region. </p> <p> Figure J.1 visualizes the three samples given below. The outer polygons correspond to the island’s coastlines. The fun regions are shown as the gray areas. </p> <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> $n$ is the number of vertices of the polygon that represents the coastline ($3 \leq n \leq 2000$). 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. $x_i$ and $y_i$ are between $0$ and $10 000$, inclusive. Here, the $x$-axis of the coordinate system directs right and the $y$-axis directs up. The polygon is simple, that is, it does not intersect nor touch itself. Note that the polygon may be non-convex. It is guaranteed that the inner angle of each vertex is not exactly $180$ degrees. </p> <h3>Output</h3> <p> Output the area of the fun region in one line. Absolute or relative errors less than $10^{−7}$ are permissible. </p> <h3>Sample Input 1 </h3> <pre> 4 10 0 20 10 10 30 0 10 </pre> <h3>Sample Output 1</h3> <pre> 300.00 </pre> <h3>Sample Input 2 </h3> <pre> 10 145 269 299 271 343 193 183 139 408 181 356 324 176 327 147 404 334 434 102 424 </pre> <h3>Sample Output 2</h3> <pre> 12658.3130191 </pre> <h3>Sample Input 3 </h3> <pre> 6 144 401 297 322 114 282 372 178 197 271 368 305 </pre> <h3>Sample Output 3</h3> <pre> 0.0 </pre>
p01730
<p>キョウトという街は古い寺社仏閣で有名な観光地である。</p> <p>イクタ君は数人の友人とキョウト観光に来ていたが、全員が好き勝手に行動した結果、みんな迷子になってしまった。 </p> <p>そこでイクタ君は、なるべく早く全員と合流するためには集合場所をどこにするのがよいか考えることにした。 </p> <p> キョウトの道路は東西と南北に距離10の間隔で無数に走っており、無限に広がる正方格子とみなすことができる。 </p> <p> 道路は直線であるとみなし、幅は無いものとする。 また、街の中心を基準として東に距離<var>x</var>、北に距離<var>y</var>移動した位置を<var>(x,y)</var>という座標で表す。 </p> <p>街の中心である<var>(0,0)</var>では東西の道路と南北の道路が交差している。 </p> <p>下図はキョウトの道路と、いくつかの点の座標を図示したものである。 </p> <br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_TripToKyoto_kyoto" height="400" width="400"> <br> <p><var>N</var>人の観光客の座標<var>(X<sub>i</sub>,Y<sub>i</sub>)</var>が整数で与えられるので、<var>N</var>人が道路上を移動して1点に集合するのに必要な時間の最小値を答えよ。 </p> <p>観光客は時間1あたり距離1の速さで連続的に道路上を動くことができるとする。 </p> <p>与えられる<var>N</var>人の観光客の座標はそれぞれ相異なり、また全ての座標は道路上にあることが保証されている。 </p> <p>また、複数の観光客が同時に1点に存在したり、観光客同士がすれ違うように移動することも可能であるとする。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。 </p><blockquote> <var>N</var><br><var>X<sub>1</sub></var> <var>Y<sub>1</sub></var><br>...<br><var>X<sub>N</sub></var> <var>Y<sub>N</sub></var><br></blockquote> <p>1行目のNは観光客の人数である。 次のN行のうちi行目(<var>1&le; i &le; N</var>)はi番目の観光客の位置<var>(X<sub>i</sub>, Y<sub>i</sub>)</var>を表している。 <var>X<sub>i</sub></var>,<var>Y<sub>i</sub></var>はそれぞれ整数で与えられる。 </p> <h3>Constraints</h3> <p>入力中の各変数は以下の制約を満たす。</p> <ul> <li> <var>2 &le; N &le; 10000</var> </li> <li> <var>&minus;10<sup>8</sup> &le; X<sub>i</sub>, Y<sub>i</sub> &le; 10<sup>8</sup></var> </li> <li> <var>i &ne; j</var> のとき <var>(X<sub>i</sub>, Y<sub>i</sub>) &ne; (X<sub>j</sub>, Y<sub>j</sub>)</var> </li> <li> <var>X<sub>i</sub></var> と <var>Y<sub>i</sub></var> のうち少なくとも一方は10の倍数である </li></ul> <h2>Output</h2> <p>問題の解を1行に出力せよ。 <var>10<sup>&minus;3</sup></var>までの絶対誤差を許容する。 </p> <h2>Sample Input 1</h2> <pre>3 5 10 -10 0 3 -10 </pre> <h2>Output for the Sample Input 1</h2> <pre>14 </pre> <ul><li><var>(0, 1)</var>に集合すればよい(この入力例は問題文中の図と対応している) </li></ul> <h2>Sample Input 2</h2> <pre>2 0 0 0 1 </pre> <h2>Output for the Sample Input 2</h2> <pre>0.5 </pre> <ul><li><var>(0, 0.5)</var>に集合すればよい(整数座標以外に集まる場合もあることに注意せよ) </li></ul> <h2>Sample Input 3</h2> <pre>4 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 </pre> <h2>Output for the Sample Input 3</h2> <pre>200000000 </pre>
p00822
<H1><font color="#000">Problem D:</font> Weather Forecast</H1> <p> You are the God of Wind. </p> <p> By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else. </p> <p> But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small humans, in their poor vocabulary, only describe this as “weather forecast”. </p> <p> You are in charge of a small country, called Paccimc. This country is constituted of 4 &times; 4 square areas, denoted by their numbers. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_weatherForecast"> </center> <p> Your cloud is of size 2 &times; 2, and may not cross the borders of the country. </p> <p> You are given the schedule of markets and festivals in each area for a period of time. </p> <p> On the first day of the period, it is raining in the central areas (6-7-10-11), independently of the schedule. </p> <p> On each of the following days, you may move your cloud by 1 or 2 squares in one of the four cardinal directions (North, West, South, and East), or leave it in the same position. Diagonal moves are not allowed. All moves occur at the beginning of the day. </p> <p> You should not leave an area without rain for a full week (that is, you are allowed at most 6 consecutive days without rain). You don’t have to care about rain on days outside the period you were given: i.e. you can assume it rains on the whole country the day before the period, and the day after it finishes. </p> <H2>Input</H2> <p> The input is a sequence of data sets, followed by a terminating line containing only a zero. </p> <p> A data set gives the number <i>N</i> of days (no more than 365) in the period on a single line, followed by <i>N</i> lines giving the schedule for markets and festivals. The <i>i</i>-th line gives the schedule for the i-th day. It is composed of 16 numbers, either 0 or 1, 0 standing for a normal day, and 1 a market or festival day. The numbers are separated by one or more spaces. </p> <H2>Output</H2> <p> The answer is a 0 or 1 on a single line for each data set, 1 if you can satisfy everybody, 0 if there is no way to do it. </p> <H2>Sample Input</H2> <pre> 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 1 0 1 </pre>
p04027
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><strong>12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience.</strong></p> <p>There are <var>N</var> children in AtCoder Kindergarten, conveniently numbered <var>1</var> through <var>N</var>. Mr. Evi will distribute <var>C</var> indistinguishable candies to the children.</p> <p>If child <var>i</var> is given <var>a</var> candies, the child's <em>happiness</em> will become <var>x_i^a</var>, where <var>x_i</var> is the child's <em>excitement level</em>. The <em>activity level</em> of the kindergarten is the <strong>product</strong> of the happiness of all the <var>N</var> children.</p> <p>For each possible way to distribute <var>C</var> candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute <var>C</var> candies. This sum can be seen as a function of the children's excitement levels <var>x_1,..,x_N</var>, thus we call it <var>f(x_1,..,x_N)</var>.</p> <p>You are given integers <var>A_i,B_i (1≦i≦N)</var>. Find <img alt="" src="http://arc059.contest.atcoder.jp/img/arc/059/E_sigmaf.gif"> modulo <var>10^9+7</var>.</img></p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦400</var></li> <li><var>1≦C≦400</var></li> <li><var>1≦A_i≦B_i≦400 (1≦i≦N)</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>400</var> points will be awarded for passing the test set satisfying <var>A_i=B_i (1≦i≦N)</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>C</var> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> <var>B_1</var> <var>B_2</var> ... <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the value of <img alt="" src="http://arc059.contest.atcoder.jp/img/arc/059/E_sigmaf.gif"> modulo <var>10^9+7</var>.</img></p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>This case is included in the test set for the partial score, since <var>A_i=B_i</var>. We only have to consider the sum of the activity level of the kindergarten where the excitement level of both child <var>1</var> and child <var>2</var> are <var>1</var> (<var>f(1,1)</var>).</p> <ul> <li>If child <var>1</var> is given <var>0</var> candy, and child <var>2</var> is given <var>3</var> candies, the activity level of the kindergarten is <var>1^0*1^3=1</var>.</li> <li>If child <var>1</var> is given <var>1</var> candy, and child <var>2</var> is given <var>2</var> candies, the activity level of the kindergarten is <var>1^1*1^2=1</var>.</li> <li>If child <var>1</var> is given <var>2</var> candies, and child <var>2</var> is given <var>1</var> candy, the activity level of the kindergarten is <var>1^2*1^1=1</var>.</li> <li>If child <var>1</var> is given <var>3</var> candies, and child <var>2</var> is given <var>0</var> candy, the activity level of the kindergarten is <var>1^3*1^0=1</var>.</li> </ul> <p>Thus, <var>f(1,1)=1+1+1+1=4</var>, and the sum over all <var>f</var> is also <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>14 </pre> <p>Since there is only one child, child <var>1</var>'s happiness itself will be the activity level of the kindergarten. Since the only possible way to distribute <var>2</var> candies is to give both candies to child <var>1</var>, the activity level in this case will become the value of <var>f</var>.</p> <ul> <li>When the excitement level of child <var>1</var> is <var>1</var>, <var>f(1)=1^2=1</var>.</li> <li>When the excitement level of child <var>1</var> is <var>2</var>, <var>f(2)=2^2=4</var>.</li> <li>When the excitement level of child <var>1</var> is <var>3</var>, <var>f(3)=3^2=9</var>.</li> </ul> <p>Thus, the answer is <var>1+4+9=14</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 3 1 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>66 </pre> <p>Since it can be seen that <var>f(1,1)=4 , f(1,2)=15 , f(2,1)=15 , f(2,2)=32</var>, the answer is <var>4+15+15+32=66</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 8 3 1 4 1 3 1 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>421749 </pre> <p>This case is included in the test set for the partial score.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>3 100 7 6 5 9 9 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>139123417 </pre></section> </div> </span>
p03218
<span class="lang-en"> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {skipTags:["script","noscript","style","textarea","code"],inlineMath: [['\\(','\\)']]} }); </script> <script async="" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" type="text/javascript"> </script> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Niwango-kun has \(N\) chickens as his pets. The chickens are identified by numbers \(1\) to \(N\), and the size of the \(i\)-th chicken is a positive integer \(a_i\).</p> <p>\(N\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \(p\) of \(1, \ldots , N\). Chicken \(i\) takes chicken \(p_i\)'s left hand by its right hand. Chickens may take their own hand.</p> <p>Let us define the <em>cycle</em> containing chicken \(i\) as the set consisting of chickens \(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\). It can be proven that after each chicken takes some chicken's hand, the \(N\) chickens can be decomposed into cycles.</p> <p>The <em>beauty</em> \(f(p)\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \(b_i \ (1 \leq i \leq N)\) be the sum of \(f(p)\) among all possible permutations \(p\) for which \(i\) cycles are formed in the procedure above.</p> <p>Find the greatest common divisor of \(b_1, b_2, \ldots, b_N\) and print it \({\rm mod} \ 998244353\).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>\(1 \leq N \leq 10^5\)</li> <li>\(1 \leq a_i \leq 10^9\)</li> <li>All numbers given 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>\(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) </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>2 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre>3 </pre> <p>In this case, \(N = 2, a = [ 4, 3 ]\).</p> <p>For the permutation \(p = [ 1, 2 ]\), a cycle of an only chicken \(1\) and a cycle of an only chicken \(2\) are made, thus \(f([1, 2]) = a_1 \times a_2 = 12\).</p> <p>For the permutation \(p = [ 2, 1 ]\), a cycle of two chickens \(1\) and \(2\) is made, and the size of the smallest chicken is \(a_2 = 3\), thus \(f([2, 1]) = a_2 = 3\).</p> <p>Now we know \(b_1 = f([2, 1]) = 3, b_2 = f([1, 2]) = 12\), and the greatest common divisor of \(b_1\) and \(b_2\) is \(3\).</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3> <pre>4 2 5 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre>2 </pre> <p>There are always \(N!\) permutations because chickens of the same size can be distinguished from each other.</p> <p>The following picture illustrates the cycles formed and their beauties when \(p = (2, 1, 4, 3)\) and \(p = (3, 4, 1, 2)\), respectively. <div style="text-align: center;"> <img alt="bdd8ce0a7db3b4f920b04551c60aa207.png" src="https://img.atcoder.jp/dwacon5th-prelims/bdd8ce0a7db3b4f920b04551c60aa207.png"> </img></div></p></section> </div> </span>
p01225
<h1><font color="#000">Problem C:</font> ラミー</h1> <p> あなたの友達は最近 UT-Rummy というカードゲームを思いついた. </p> <p> このゲームで使うカードには赤・緑・青のいずれかの色と1から9までのいずれかの番号が つけられている. このゲームのプレイヤーはそれぞれ9枚の手札を持ち, 自分のターンに手札から1枚選んで捨てて, 代わりに山札から1枚引いてくるということを繰り返す. このように順番にターンを進めていき, 最初に手持ちのカードに3枚ずつ3つの「セット」を作ったプレイヤーが勝ちとなる. セットとは,同じ色の3枚のカードからなる組で,すべて同じ数を持っているか 連番をなしているもののことを言う. 連番に関しては,番号の巡回は認められない. 例えば,7, 8, 9は連番であるが 9, 1, 2は連番ではない. </p> <p> あなたの友達はこのゲームをコンピュータゲームとして売り出すという計画を立てて, その一環としてあなたに勝利条件の判定部分を作成して欲しいと頼んできた. あなたの仕事は,手札が勝利条件を満たしているかどうかを判定する プログラムを書くことである. </p> <h2>Input</h2> <p> 入力の1行目にはデータセット数を表す数 <var>T</var> (0 &lt; <var>T</var> &le; 50) が与えられる. この行に引き続き <var>T</var> 個のデータセットが与えられる. </p> <p> 各データセットは2行からなり, 1行目には <var>i</var> 番目 (<var>i</var> = 1, 2, ..., 9) のカードの数字 <var>n</var><sub><var>i</var></sub> がそれぞれスペースで区切られて与えられ, 2行目には <var>i</var> 番目のカードの色を表す文字 <var>c</var><sub><var>i</var></sub> がそれぞれスペースで区切られて与えられる. カードの数字 <var>n</var><sub><var>i</var></sub> は 1 &le; <var>n</var><sub><var>i</var></sub> &le; 9 を満たす整数であり, カードの色 <var>c</var><sub><var>i</var></sub> はそれぞれ &ldquo;<code>R</code>&rdquo;, &ldquo;<code>G</code>&rdquo;, &ldquo;<code>B</code>&rdquo; のいずれかの文字である. </p> <p> 1つのデータセット内に色と数字がともに同じカードが5枚以上出現することはない. </p> <h2>Output</h2> <p> 各データセットにつき,勝利条件を満たしていれば &ldquo;<code>1</code>&rdquo;, そうでなければ &ldquo;<code>0</code>&rdquo; と出力せよ. </p> <h2>Sample Input</h2> <pre> 5 1 2 3 3 4 5 7 7 7 R R R R R R G G G 1 2 2 3 4 4 4 4 5 R R R R R R R R R 1 2 3 4 4 4 5 5 5 R R B R R R R R R 1 1 1 3 4 5 6 6 6 R R B G G G R R R 2 2 2 3 3 3 1 1 1 R G B R G B R G B </pre> <h2>Output for the Sample Input</h2> <pre> 1 0 0 0 1 </pre>
p03648
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a sequence of length <var>N</var> consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes <var>N-1</var> or smaller.</p> <ul> <li>Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by <var>N</var>, and increase each of the other elements by <var>1</var>.</li> </ul> <p>It can be proved that the largest element in the sequence becomes <var>N-1</var> or smaller after a finite number of operations.</p> <p>You are given an integer <var>K</var>. Find an integer sequence <var>a_i</var> such that the number of times we will perform the above operation is exactly <var>K</var>. It can be shown that there is always such a sequence under the constraints on input and output in this problem.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≤ K ≤ 50 \times 10^{16}</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>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a solution in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> ... <var>a_N</var> </pre> <p>Here, <var>2 ≤ N ≤ 50</var> and <var>0 ≤ a_i ≤ 10^{16} + 1000</var> must hold.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 3 3 3 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 1 0 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 2 2 </pre> <p>The operation will be performed twice: [2, 2] -&gt; [0, 3] -&gt; [1, 1].</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>7 27 0 0 0 0 0 0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>1234567894848 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>10 1000 193 256 777 0 1 1192 1234567891011 48 425 </pre></section> </div> </span>
p01675
<h2>I - The J-th Number</h2> <h3>Problem Statement</h3> <p> You are given <var>N</var> empty arrays, <var>t_1, ..., t_n</var>. At first, you execute <var>M</var> queries as follows. </p> <ul> <li>add a value <var>v</var> to array <var>t_i</var> (<var>a \leq i \leq b</var>)</li> </ul> <p> Next, you process <var>Q</var> following output queries. </p> <ul> <li>output the <var>j</var>-th number of the sequence sorted all values in <var>t_i</var> (<var>x \leq i \leq y</var>)</li> </ul> <h3>Input</h3> <p> The dataset is formatted as follows. </p> <pre> <var>N</var> <var>M</var> <var>Q</var> <var>a_1</var> <var>b_1</var> <var>v_1</var> ... <var>a_M</var> <var>b_M</var> <var>v_M</var> <var>x_1</var> <var>y_1</var> <var>j_1</var> ... <var>x_Q</var> <var>y_Q</var> <var>j_Q</var> </pre> <p> The first line contains three integers <var>N</var> (<var>1 \leq N \leq 10^9</var>), <var>M</var> (<var>1 \leq M \leq 10^5</var>) and <var>Q</var> (<var>1 \leq Q \leq 10^5</var>). Each of the following <var>M</var> lines consists of three integers <var>a_i</var>, <var>b_i</var> and <var>v_i</var> (<var>1 \leq a_i \leq b_i \leq N</var>, <var>1 \leq v_i \leq 10^9</var>). Finally the following <var>Q</var> lines give the list of output queries, each of these lines consists of three integers <var>x_i</var>, <var>y_i</var> and <var>j_i</var> (<var>1 \leq x_i \leq y_i \leq N, 1 \leq j_i \leq &Sigma;_{x_i \leq k \leq y_i} |t_k|</var>). </p> <h3>Output</h3> <p> For each output query, print in a line the <var>j</var>-th number. </p> <h3>Sample Input 1</h3> <pre> 5 4 1 1 5 1 1 1 3 4 5 1 3 4 2 1 3 4 </pre> <h3>Output for the Sample Input 1</h3> <pre> 2 </pre> <p> After the <var>M</var>-th query is executed, each <var>t_i</var> is as follows: </p> <pre> [1,3], [1], [1,2], [1,1,2], [1,1] </pre> <p> The sequence sorted values in <var>t_1</var>, <var>t_2</var> and <var>t_3</var> is [1,1,1,2,3]. In the sequence, the 4-th number is 2. </p> <h3>Sample Input 2</h3> <pre> 10 4 4 1 4 11 2 3 22 6 9 33 8 9 44 1 1 1 4 5 1 4 6 2 1 10 12 </pre> <h3>Output for the Sample Input 2</h3> <pre> 11 11 33 44 </pre>
p00967
<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 K Counting Cycles </h2> <p> Given an undirected graph, count the number of simple cycles in the graph. Here, a simple cycle is a connected subgraph all of whose vertices have degree exactly two. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $m$ $u_1$ $v_1$ ... $u_m$ $v_m$ </pre> <p> A test case represents an undirected graph $G$. </p> <p> The first line shows the number of vertices $n$ ($3 \leq n \leq 100 000$) and the number of edges $m$ ($n - 1 \leq m \leq n + 15$). The vertices of the graph are numbered from $1$ to $n$. </p> <p> The edges of the graph are specified in the following $m$ lines. Two integers $u_i$ and $v_i$ in the $i$-th line of these m lines mean that there is an edge between vertices $u_i$ and $v_i$. Here, you can assume that $u_i < v_i$ and thus there are no self loops. </p> <p> For all pairs of $i$ and $j$ ($i \ne j$), either $u_i \ne u_j$ or $v_i \ne v_j$ holds. In other words, there are no parallel edges. </p> <p> You can assume that $G$ is connected. </p> <h3>Output</h3> <p> The output should be a line containing a single number that is the number of simple cycles in the graph. </p> <h3>Sample Input 1</h3> <pre> 4 5 1 2 1 3 1 4 2 3 3 4 </pre> <h3>Sample Output 1</h3> <pre> 3 </pre> <h3>Sample Input 2</h3> <pre> 7 9 1 2 1 3 2 4 2 5 3 6 3 7 2 3 4 5 6 7 </pre> <h3>Sample Output 2</h3> <pre> 3 </pre> <h3>Sample Input 3</h3> <pre> 4 6 1 2 1 3 1 4 2 3 2 4 3 4 </pre> <h3>Sample Output 3</h3> <pre> 7 </pre>
p00434
<H1>未提出者は誰だ</H1> <h2>問題</h2> <p> JOI大学のM教授はプログラミングの授業を担当している.クラスには30人の受講生がいて各受講生には1番から30番までの出席番号がふられている.この授業の課題を28人の学生が提出した.提出した28人の出席番号から提出していない2人の出席番号を求めるプログラムを作成せよ. </p> <H2>入力</H2> <p> 入力は28行あり,各行には提出者の出席番号(1以上30以下)が1つずつ書かれている.入力される出席番号に重複はないが,どのような順に入力されるかはわからない. </p> <H2>出力</H2> <p> <!--提出する出力ファイルは2行からなる. 1行目に2人の未提出者の出席番号のうち小さいほうを, 2行目に大きいほうを出力せよ.--> 出力は2行からなる. 1行目に2人の未提出者の出席番号のうち小さいほうを, 2行目に大きいほうを出力せよ. </p> <h2>入出力例</h2> <h3>入力例 1</h3> <pre> 3 1 4 5 7 9 6 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 </pre> <h3>出力例 1</h3> <pre> 2 8 </pre> <h3>入力例 2</h3> <pre> 9 30 6 12 10 20 21 11 7 5 28 4 18 29 17 19 27 13 16 26 14 23 22 15 3 1 24 25 </pre> <h3>出力例 2</h3> <pre> 2 8 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p02409
<H1>Official House</H1> <p> You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. </p> <p> For each notice, you are given four integers <var>b</var>, <var>f</var>, <var>r</var> and <var>v</var> which represent that <var>v</var> persons entered to room <var>r</var> of <var>f</var>th floor at building <var>b</var>. If <var>v</var> is negative, it means that <var>&minus;v</var> persons left. </p> <p> Assume that initially no person lives in the building. </p> <H2>Input</H2> <p> In the first line, the number of notices <var>n</var> is given. In the following <var>n</var> lines, a set of four integers <var>b</var>, <var>f</var>, <var>r</var> and <var>v</var> which represents <var>i</var>th notice is given in a line. </p> <H2>Output</H2> <p> For each building, print the information of 1st, 2nd and 3rd floor in this order. For each floor information, print the number of tenants of 1st, 2nd, .. and 10th room in this order. Print a single space character before the number of tenants. Print "####################" (20 '#') between buildings. </p> <h2>Constraints</h2> <ul> <li>No incorrect building, floor and room numbers are given.</li> <li>0 &le; the number of tenants during the management &le; 9</li> </ul> <H2>Sample Input</H2> <pre> 3 1 1 3 8 3 2 2 7 4 3 8 1 </pre> <H2>Sample Output</H2> <pre> 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #################### 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #################### 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #################### 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 </pre>
p00064
<H1>暗証番号</H1> <p> 新しい暗証番号は覚えにくいものです。メモするのはダメといわれましたが、覚えられそうにありません。そこで文章の中に数値を埋め込んで暗証番号をメモすることにしました。ここでは全ての数値の和が暗証番号になります。 </p> <p> メモされた文章を読み込んで、暗証番号を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 正の整数が埋め込まれた文章が複数行にわたり与えられます。各行は半角英数字、記号、空白を含む文字列または空行です。 ただし、入力は 1 行あたり 80 文字以内で、暗証番号は 10,000 以下であることが保障されています。 </p> <H2>Output</H2> <p> 暗証番号(文章中の正の整数の合計)を1行に出力します。 </p> <H2>Sample Input</H2> <pre> Thereare100yenonthetable.Iam17yearsold. Ishouldgohomeat6pm. </pre> <H2>Output for the Sample Input</H2> <pre> 123 </pre>
p02059
<h2>H: Revenge of UMG</h2> <h3>問題</h3> <p>'U', 'M', 'G' の三種類の文字からなる文字列 <var>T</var> に対し、<var>1, 2, ..., |T|</var> 文字目をそれぞれ <var>T_1, T_2, ..., T_{|T|}</var> と表すことにしたとき、以下の条件を満たす <var>(i, j, k)</var> の組の個数を、文字列 <var>T</var> の “UMG 数”と呼ぶことにします:</p> <ul> <li> <var>1 \leq i &lt; j &lt; k \leq |T|</var></li> <li> <var>j - i = k - j</var></li> <li> <var>T_i</var> = 'U', <var>T_j</var> = 'M', <var>T_k</var> = 'G'</li> </ul> <p>さて、'U', 'M', 'G', '?' の四種類の文字からなる文字列 <var>S</var> が与えられます。<var>S</var> の '?' をそれぞれ 'U', 'M', 'G' のいずれかに置き換えてできる文字列は、'?' の個数を <var>N</var> として <var>3^{N}</var> 通り考えられますが、それぞれの文字列の UMG 数について総和をとったものを <var>998244353</var> で割ったあまりを求めてください。</p> <h3>入力形式</h3> <pre><var>S</var></pre> <h3>制約</h3> <ul> <li> <var>3 \leq |S| \leq 2 \times 10^{5}</var></li> <li> <var>S</var> は 'U', 'M', 'G', '?' の四種類の文字からなる文字列である。</li> </ul> <h3>出力形式</h3> <p>答えを表す整数を一行に出力してください。<var>998244353</var> で割ったあまりを出力することに注意してください。</p> <h3>入力例 1</h3> <pre>?MG?</pre> <h3>出力例 1</h3> <pre>3</pre> <p>最初の '?' が 'U' でない場合には UMG 数は <var>0 </var> になります。最初の '?' を 'U' としたとき、</p> <ul> <li> <code>UMGU</code> の UMG 数は <var>1</var></li> <li> <code>UMGM</code> の UMG 数は <var>1</var></li> <li> <code>UMGG</code> の UMG 数は <var>1</var></li> </ul> <p>となり、合計値は <var>3</var> になります。</p> <h3>入力例 2</h3> <pre>UUMMGGGUMG</pre> <h3>出力例 2</h3> <pre>4</pre> <h3>入力例 3</h3> <pre>?????G????U???M??????G?????M????G???U??????M???G??</pre> <h3>出力例 3</h3> <pre>648330088</pre> <p><var>998244353</var> で割ったあまりを答えてください。</p>
p01858
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>--> <h2>A: 磯野、あれやろうぜ! - Sendame -</h2> <h3>物語</h3> <p>中島「磯野〜,あれやろうぜ!」</p> <p>磯野「あれって何だよ,中島」</p> <p>中島「ほら,あれだよ,あれ.なぜか文字で表さなきゃならないから,説明しづらいな〜」</p> <p>磯野「いや,図や写真も入れられるみたいだぞ?」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_sazae" type="image/jpeg" width="300"></img> <p>中島「本当だ!」</p> <p>磯野「で,何をやるんだ?」</p> <p>中島「ほら,リズムに乗って,手を2回叩いた後に,防御,溜め,攻撃のポーズを取るやつ」</p> <p>磯野「う〜ん,イマイチわからないな…」</p> <p>中島「2回手を叩いた後に,例えば防御だったら」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_bougyo" type="image/jpeg" width="300"></img> <p>中島「で,溜めだったら」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_tame" type="image/jpeg" width="300"></img> <p>中島「攻撃だったら」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_kougeki" type="image/jpeg" width="300"></img> <p>中島「ってやるやつ,知ってるだろ?」</p> <p>磯野「ああ!写真が入ると劇的に分かりやすくなるな!」</p> <p>中島「これぞ文明の進歩だな!」</p> <p>(それから悠久の時が経った)</p> <p>花沢「い゛そ゛の゛く゛〜゛ん゛な゛か゛じ゛ま゛く゛〜゛ん゛」</p> <p>二人「(パチパチ…パチパチ…パチパチ…)」</p> <p>花沢「アンタたち,まさか寝ながらあれやってるの…!?」</p> <p>花沢「今勝負ついたじゃない…磯野くん,今あなた勝ったわよ?」</p> <p>磯野「……花沢さん来てたんだ…中島もう一度やるぞ…zzz」</p> <p>中島「(こくり)」</p> <p>二人「(パチパチ…パチパチ…)」</p> <p>花沢「もう…ここに,あれの勝敗判定ロボット置いておくから…」</p> <p>そうして花沢さんは去って行った.</p> <p>ということがあるかもしれないので,あれの勝敗判定プログラムを書いてください.</p> <h3>問題</h3> <p>「あれ」は2人で行うゲームである.リズムに合わせて2人が同時に,防御,溜め,攻撃のいずれかのポーズを取ることを繰り返す.ここで,2人がポーズを取るタイミングのことを「回」と表記する.このゲームでは,ある回で勝敗がつき,かつ,それまでの回で勝敗がついていないとき,その勝敗がゲームの勝敗となる.</p> <p>2人はそれぞれ「攻撃力」というパラメータを持ち,ゲーム開始時,攻撃力は <var>0</var> である.</p> <p>攻撃のポーズを取った場合,その時点での攻撃力に応じて,次のようになる.</p> <ul> <li>攻撃力が <var>0</var> のときに攻撃のポーズを取ると,反則負けとなる.ただし,相手も攻撃力が <var>0</var> で攻撃のポーズをした場合,その回では勝敗がつかない.</li> <li>自分の攻撃力が <var>1</var> 以上のときに攻撃のポーズをとると,相手に攻撃を加える.また,その回で相手も攻撃のポーズを取った場合,攻撃力のより高いプレイヤーが勝利する.ただし,両プレイヤーが同じ攻撃力で攻撃のポーズを取った場合には,その回では勝敗がつかない.</li> </ul> <p>また,攻撃のポーズを取った回の終了時に,自分の攻撃力が <var>0</var> になる.</p> <p>溜めのポーズを取ると,そのプレイヤーの攻撃力が <var>1</var> だけ上昇する.ただし,攻撃力が <var>5</var> である場合,そのプレイヤーが溜めのポーズを取っても,攻撃力は <var>5</var> のままである.溜めのポーズを取った回で,相手が攻撃を加えた場合,相手が勝利する.なお,溜めのポーズを取った回で,相手が攻撃以外のポーズをとった場合,勝敗がつかない.</p> <p>防御のポーズを取った回に,相手が攻撃力 <var>5</var> の攻撃を加えた場合,相手が勝利する.一方,防御のポーズを取った回に,相手が攻撃力 <var>4</var> 以下の攻撃を加えた場合や,溜めまたは防御のポーズを取った場合,その回では勝敗がつかない.なお,防御のポーズを取っても,そのプレイヤーの攻撃力に変化はない.</p> <p>両プレイヤーのポーズが順に与えられるので,勝敗を出力せよ.なお,両プレイヤーは勝敗が決定した後もポーズをとり続けることがあるが,勝敗が決定した後のポーズは無視するものとする.</p> <h3>入力形式</h3> <p>入力は以下の形式で与えられる.</p> <pre> <var>K</var> <var>I_1</var> ... <var>I_K</var> <var>N_1</var> ... <var>N_K</var> </pre> <p> 入力の1行目には,1個の整数 <var>K</var> (<var> 1 &le; K &le; 100</var>) が与えられる. 2行目からの <var>K</var> 行には,磯野が取ったポーズ <var>I_i</var> (<var>1 &le; i &le; K</var>) が順に与えられる. その直後の <var>K</var> 行には,中島が取ったポーズ <var>N_i</var> (<var>1 &le; i &le; K</var>) が順に与えられる. <var>I_i</var> および <var>N_i</var> は “mamoru”, “tameru”, “kougekida” のいずれかである.これらの文字列は順に,防御,溜め,攻撃のポーズを表す. </p> <h3>出力形式</h3> <p>磯野が勝利した場合には “Isono-kun” ,中島が勝利した場合には “Nakajima-kun” , <var>K</var> 回で勝敗がつかない場合には, “Hikiwake-kun” と1行で出力せよ.</p> <h3>入力例1</h3> <pre> 3 tameru tameru tameru tameru kougekida tameru </pre> <h3>出力例1</h3> <pre>Nakajima-kun</pre> <p><var>2</var> 回目で,磯野が溜めのポーズをしているのに対し,中島は攻撃力 <var>1</var> の攻撃をしているので,中島の勝利です.</p> <h3>入力例2</h3> <pre> 3 mamoru mamoru mamoru tameru tameru tameru </pre> <h3>出力例2</h3> <pre>Hikiwake-kun</pre> <p>どちらも攻撃をしなかったので,勝敗がつきませんでした.</p> <h3>入力例3</h3> <pre> 5 tameru tameru mamoru mamoru kougekida tameru tameru kougekida tameru kougekida </pre> <h3>出力例3</h3> <pre>Isono-kun</pre> <p><var>1</var> 回目から <var>4</var> 回目まででは勝敗がつきません. <var>5</var> 回目で,両プレイヤーが攻撃のポーズをしていますが,磯野の攻撃力が <var>2</var> なのに対し,中島の攻撃力が <var>1</var> なので,磯野の勝利です.</p> <h3>入力例4</h3> <pre> 3 kougekida kougekida tameru kougekida mamoru kougekida </pre> <h3>出力例4</h3> <pre>Nakajima-kun</pre> <p><var>1</var> 回目では,両プレイヤーが攻撃力 <var>0</var> で攻撃のポーズを取っているので,勝敗がつきません. <var>2</var> 回目では,磯野のみが攻撃力 <var>0</var> で攻撃のポーズをとっているので,中島の勝利です.</p> <h3>入力例5</h3> <pre> 8 tameru mamoru tameru tameru tameru tameru tameru kougekida tameru kougekida mamoru mamoru mamoru mamoru mamoru mamoru </pre> <h3>出力例5</h3> <pre>Isono-kun</pre> <p><var>2</var> 回目では,中島が攻撃力 <var>1</var> で攻撃のポーズを取っていますが,磯野が防御のポーズを取っているので,勝敗がつきません. <var>7</var> 回目では,磯野が攻撃力 <var>5</var> で溜めのポーズを取っているので,磯野の攻撃力は <var>5</var> のままです. <var>8</var> 回目では,磯野が攻撃力 <var>5</var> で攻撃のポーズをとり,中島が防御のポーズを取っているので,磯野が勝利します.</p>
p03865
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a string <var>s</var> of length <var>3</var> or greater. No two neighboring characters in <var>s</var> are equal.</p> <p>Takahashi and Aoki will play a game against each other. The two players alternately performs the following operation, Takahashi going first:</p> <ul> <li>Remove one of the characters in <var>s</var>, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in <var>s</var>.</li> </ul> <p>The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 ≤ |s| ≤ 10^5</var></li> <li><var>s</var> consists of lowercase English letters.</li> <li>No two neighboring characters in <var>s</var> are equal.</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>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Takahashi will win, print <code>First</code>. If Aoki will win, print <code>Second</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>aba </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Second </pre> <p>Takahashi, who goes first, cannot perform the operation, since removal of the <code>b</code>, which is the only character not at either ends of <var>s</var>, would result in <var>s</var> becoming <code>aa</code>, with two <code>a</code>s neighboring.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>abc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>First </pre> <p>When Takahashi removes <code>b</code> from <var>s</var>, it becomes <code>ac</code>. Then, Aoki cannot perform the operation, since there is no character in <var>s</var>, excluding both ends.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>abcab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>First </pre></section> </div> </span>
p02777
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have <var>A</var> balls with the string <var>S</var> written on each of them and <var>B</var> balls with the string <var>T</var> written on each of them.<br/> From these balls, Takahashi chooses one with the string <var>U</var> written on it and throws it away.<br/> Find the number of balls with the string <var>S</var> and balls with the string <var>T</var> that we have now.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>S</var>, <var>T</var>, and <var>U</var> are strings consisting of lowercase English letters.</li> <li>The lengths of <var>S</var> and <var>T</var> are each between <var>1</var> and <var>10</var> (inclusive).</li> <li><var>S \not= T</var></li> <li><var>S=U</var> or <var>T=U</var>.</li> <li><var>1 \leq A,B \leq 10</var></li> <li><var>A</var> and <var>B</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>S</var> <var>T</var> <var>A</var> <var>B</var> <var>U</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer, with space in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>red blue 3 4 red </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 4 </pre> <p>Takahashi chose a ball with <code>red</code> written on it and threw it away. Now we have two balls with the string <var>S</var> and four balls with the string <var>T</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>red blue 5 5 blue </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 4 </pre> <p>Takahashi chose a ball with <code>blue</code> written on it and threw it away. Now we have five balls with the string <var>S</var> and four balls with the string <var>T</var>.</p></section> </div> </span>
p02327
<H1>Largest Rectangle</H1> <p> Given a matrix (<var>H</var> &times; <var>W</var>) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. </p> <H2>Input</H2> <pre> <var>H</var> <var>W</var> <var>c</var><sub>1,1</sub> <var>c</var><sub>1,2</sub> ... <var>c<sub>1,W</sub></var> <var>c</var><sub>2,1</sub> <var>c</var><sub>2,2</sub> ... <var>c<sub>2,W</sub></var> : <var>c<sub>H,1</sub></var> <var>c<sub>H,2</sub></var> ... <var>c<sub>H,W</sub></var> </pre> <p> In the first line, two integers <var>H</var> and <var>W</var> separated by a space character are given. In the following <var>H</var> lines, <var>c</var><sub><var>i</var>,<var>j</var></sub>, elements of the <var>H</var> &times; <var>W</var> matrix, are given. </p> <H2>Output</H2> <p> Print the area (the number of 0s) of the largest rectangle. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>H</var>, <var>W</var> &le; 1,400</li> </ul> <H2>Sample Input</H2> <pre> 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 </pre> <H2>Sample Output</H2> <pre> 6 </pre>
p03166
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a directed graph <var>G</var> with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>1, 2, \ldots, N</var>, and for each <var>i</var> (<var>1 \leq i \leq M</var>), the <var>i</var>-th directed edge goes from Vertex <var>x_i</var> to <var>y_i</var>. <var>G</var> <strong>does not contain directed cycles</strong>.</p> <p>Find the length of the longest directed path in <var>G</var>. Here, the length of a directed path is the number of edges in it.</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 10^5</var></li> <li><var>1 \leq M \leq 10^5</var></li> <li><var>1 \leq x_i, y_i \leq N</var></li> <li>All pairs <var>(x_i, y_i)</var> are distinct.</li> <li><var>G</var> <strong>does not contain directed cycles</strong>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_M</var> <var>y_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the length of the longest directed path in <var>G</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 1 2 1 3 3 2 2 4 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The red directed path in the following figure is the longest:</p> <p><img alt="" src="https://img.atcoder.jp/dp/longest_0_muffet.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 2 3 4 5 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>The red directed path in the following figure is the longest:</p> <p><img alt="" src="https://img.atcoder.jp/dp/longest_1_muffet.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 8 5 3 2 3 2 4 5 2 5 1 1 4 4 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre> <p>The red directed path in the following figure is one of the longest:</p> <p><img alt="" src="https://img.atcoder.jp/dp/longest_2_muffet.png"/></p></section> </div> </span>
p03536
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In the final of CODE FESTIVAL in some year, there are <var>N</var> participants. The <em>height</em> and <em>power</em> of Participant <var>i</var> is <var>H_i</var> and <var>P_i</var>, respectively.</p> <p>Ringo is hosting a game of stacking zabuton (cushions).</p> <p>The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Initially, the stack is empty. When it is Participant <var>i</var>'s turn, if there are <var>H_i</var> or less zabuton already stacked, he/she will add exactly <var>P_i</var> zabuton to the stack. Otherwise, he/she will give up and do nothing.</p> <p>Ringo wants to maximize the number of participants who can add zabuton to the stack. How many participants can add zabuton to the stack in the optimal order of participants?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 5000</var></li> <li><var>0 \leq H_i \leq 10^9</var></li> <li><var>1 \leq P_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>H_1</var> <var>P_1</var> <var>H_2</var> <var>P_2</var> <var>:</var> <var>H_N</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of participants who can add zabuton to the stack.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 2 1 3 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>When the participants line up in the same order as the input, Participants <var>1</var> and <var>3</var> will be able to add zabuton.</p> <p>On the other hand, there is no order such that all three participants can add zabuton. Thus, the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 4 3 1 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>When the participants line up in the order <var>2</var>, <var>3</var>, <var>1</var>, all of them will be able to add zabuton.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 3 8 4 8 3 9 1 6 4 2 3 4 2 9 2 8 3 0 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre></section> </div> </span>
p03023
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given an integer <var>N</var> not less than <var>3</var>, find the sum of the interior angles of a regular polygon with <var>N</var> sides.</p> <p>Print the answer in degrees, but do not print units.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the sum of the interior angles of a regular polygon with <var>N</var> sides.</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>180 </pre> <p>The sum of the interior angles of a regular triangle is <var>180</var> degrees.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>17640 </pre></section> </div> </span>
p03189
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>: <var>A_1,A_2,...,A_N</var>. Let us perform <var>Q</var> operations in order. The <var>i</var>-th operation is described by two integers <var>X_i</var> and <var>Y_i</var>. In this operation, we will choose one of the following two actions and perform it:</p> <ul> <li>Swap the values of <var>A_{X_i}</var> and <var>A_{Y_i}</var></li> <li>Do nothing</li> </ul> <p>There are <var>2^Q</var> ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo <var>10^9+7</var>.</p> <p>Here, the inversion number of a sequence <var>P_1,P_2,...,P_M</var> is the number of pairs of integers <var>(i,j)</var> such that <var>1\leq i &lt; j\leq M</var> and <var>P_i &gt; P_j</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 3000</var></li> <li><var>0 \leq Q \leq 3000</var></li> <li><var>0 \leq A_i \leq 10^9(1\leq i\leq N)</var></li> <li><var>1 \leq X_i,Y_i \leq N(1\leq i\leq Q)</var></li> <li><var>X_i\neq Y_i(1\leq i\leq Q)</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>Q</var> <var>A_1</var> <var>:</var> <var>A_N</var> <var>X_1</var> <var>Y_1</var> <var>:</var> <var>X_Q</var> <var>Y_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the inversion numbers of the final sequences, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 2 3 1 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>There are four ways to perform operations, as follows:</p> <ul> <li>Do nothing, both in the first and second operations. The final sequence would be <var>1,2,3</var>, with the inversion number of <var>0</var>.</li> <li>Do nothing in the first operation, then perform the swap in the second. The final sequence would be <var>3,2,1</var>, with the inversion number of <var>3</var>.</li> <li>Perform the swap in the first operation, then do nothing in the second. The final sequence would be <var>2,1,3</var>, with the inversion number of <var>1</var>.</li> <li>Perform the swap, both in the first and second operations. The final sequence would be <var>3,1,2</var>, with the inversion number of <var>2</var>.</li> </ul> <p>The sum of these inversion numbers, <var>0+3+1+2=6</var>, should be printed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 3 2 3 1 4 1 5 2 3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>36 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 5 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>425 </pre></section> </div> </span>
p03473
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>How many hours do we have until New Year at <var>M</var> o'clock (24-hour notation) on <var>30</var>th, December?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤M≤23</var></li> <li><var>M</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>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If we have <var>x</var> hours until New Year at <var>M</var> o'clock on <var>30</var>th, December, print <var>x</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>21 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>27 </pre> <p>We have <var>27</var> hours until New Year at <var>21</var> o'clock on <var>30</var>th, December.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>36 </pre></section> </div> </span>
p03920
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The problem set at <em>CODE FESTIVAL 20XX Finals</em> consists of <var>N</var> problems.</p> <p>The score allocated to the <var>i</var>-th <var>(1≦i≦N)</var> problem is <var>i</var> points.</p> <p>Takahashi, a contestant, is trying to score exactly <var>N</var> points. For that, he is deciding which problems to solve.</p> <p>As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.</p> <p>Determine the set of problems that should be solved.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^7</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>200</var> points will be awarded for passing the test set satisfying <var>1≦N≦1000</var>.</li> <li>Additional <var>100</var> points will be awarded for passing the test set without additional constraints.</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>Among the sets of problems with the total score of <var>N</var>, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line.</p> <p>If there exists more than one such set, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 3 </pre> <p>Solving only the <var>4</var>-th problem will also result in the total score of <var>4</var> points, but solving the <var>1</var>-st and <var>3</var>-rd problems will lower the highest score of a solved problem.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 4 </pre> <p>The set <var>\{3,4\}</var> will also be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre></section> </div> </span>
p02632
<span class="lang-en"> <p>Score: <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>How many strings can be obtained by applying the following operation on a string <var>S</var> exactly <var>K</var> times: "choose one lowercase English letter and insert it somewhere"?</p> <p>The answer can be enormous, so print it modulo <var>(10^9+7)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>K</var> is an integer between <var>1</var> and <var>10^6</var> (inclusive).</li> <li><var>S</var> is a string of length between <var>1</var> and <var>10^6</var> (inclusive) consisting of lowercase English letters.</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>K</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of strings satisfying the condition, modulo <var>(10^9+7)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 oof </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>575111451 </pre> <p>For example, we can obtain <code>proofend</code>, <code>moonwolf</code>, and <code>onionpuf</code>, while we cannot obtain <code>oofsix</code>, <code>oofelevennn</code>, <code>voxafolt</code>, or <code>fooooooo</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>37564 whydidyoudesertme </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>318008117 </pre></section> </div> </span>
p02798
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> cards numbered <var>1, 2, ..., N</var>. Card <var>i</var> (<var>1 \leq i \leq N</var>) has an integer <var>A_i</var> written in red ink on one side and an integer <var>B_i</var> written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card <var>1</var> to Card <var>N</var>, with the red numbers facing up.</p> <p>Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each <var>i</var> (<var>1 \leq i \leq N - 1</var>), the integer facing up on the <var>(i+1)</var>-th card from the left is not less than the integer facing up on the <var>i</var>-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it.</p> <ul> <li>Choose an integer <var>i</var> (<var>1 \leq i \leq N - 1</var>). Swap the <var>i</var>-th and <var>(i+1)</var>-th cards from the left, then flip these two cards.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 18</var></li> <li><var>1 \leq A_i, B_i \leq 50</var> (<var>1 \leq i \leq N</var>)</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> <var>B_1</var> <var>B_2</var> <var>...</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is impossible to have a non-decreasing sequence, print <code>-1</code>. If it is possible, print the minimum number of operations required to achieve it.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 4 3 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>By doing the operation once with <var>i = 1</var>, we have a sequence <var>[2, 3, 3]</var> facing up, which is non-decreasing.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>After any number of operations, we have the sequence <var>[2, 1]</var> facing up, which is not non-decreasing.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 2 3 4 5 6 7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>No operation may be required.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 28 15 22 43 31 20 22 43 33 32 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>5 4 46 6 38 43 33 15 18 27 37 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>3 </pre></section> </div> </span>
p02262
<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> <h2>Shell Sort</h2> <p> Shell Sort is a generalization of <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A">Insertion Sort</a> to arrange a list of $n$ elements $A$. </p> <pre> 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) </pre> <p> A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. </p> <p> Your task is to complete the above program by filling <span>?</span>. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: </p> <ul> <li>$1 \leq m \leq 100$</li> <li>$0 \leq G_i \leq n$</li> <li><span>cnt</span> does not exceed $\lceil n^{1.5}\rceil$</li> </ul> <h2>Input</h2> <p> In the first line, an integer $n$ is given. In the following $n$ lines, $A_i (i=0,1,...,n-1)$ are given for each line. </p> <h2>Output</h2> <p> In the first line, print an integer $m$. In the second line, print $m$ integers $G_i (i=0,1,...,m-1)$ separated by single space character in a line.<br> In the third line, print <span>cnt</span> in a line. In the following $n$ lines, print $A_i (i=0,1,...,n-1)$ respectively. </p> <p> This problem has multiple solutions and the judge will be performed by a special validator. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 1,000,000$</li> <li>$0 \leq A_i \leq 10^9$</li> </ul> <h2>Sample Input 1</h2> <pre> 5 5 1 4 3 2 </pre> <h2>Sample Output 1</h2> <pre> 2 4 1 3 1 2 3 4 5 </pre> <h2>Sample Input 2</h2> <pre> 3 3 2 1 </pre> <h2>Sample Output 2</h2> <pre> 1 1 3 1 2 3 </pre>
p01767
<h1 id="b-rupc">B : RUPC</h1> <h2 id="問題文">問題文</h2> <p>ロシア連邦でプログラミングコンテストが開催される。コンテストには <var>N</var> 個の問題が出題され、<var>M</var> 人の参加者がいる。問題 <var>i</var> には得点 <var>a_i</var> が設定されており、参加者 <var>j</var> の実力は <var>b_j</var> であることがわかっている。問題 <var>i</var> と参加者 <var>j</var> について、 <var>a_i &le; b_j</var> のときかつそのとき限り、参加者 <var>j</var> は問題 <var>i</var> を必ず解くことができる。 コンテストを通した参加者の得点は、その人が解くことができた問題の得点の総和である。また、参加者 <var>j</var> は、このコンテストでの目標点数 <var>c_j</var> を定めている。</p> <p>各参加者が、目標点数以上の得点を獲得できるか判定せよ。</p> <h2 id="入力">入力</h2> <p>入力は以下の形式で与えられる。</p> <pre><var>N</var> <var>a_{0}</var> <var>a_{1}</var> <var>a_{2}</var> <var>…</var> <var>a_{N&minus;1}</var> <var>M</var> <var>b_{0}</var> <var>b_{1}</var> <var>b_{2}</var> <var>…</var> <var>b_{M&minus;1}</var> <var>c_{0}</var> <var>c_{1}</var> <var>c_{2}</var> <var>…</var> <var>c_{M&minus;1}</var> </pre> <h2 id="制約">制約</h2> <ul> <li>入力はすべて整数である</li> <li><var>1 \&le; N \&le; 300\,000</var></li> <li><var>1 \&le; M \&le; 300\,000</var></li> <li><var>0 \&le; a_{i} \&le; 1\,000\,000</var></li> <li><var>0 \&le; b_{i} \&le; 1\,000\,000</var></li> <li><var>0 \&le; c_{i} \&le; &sum;a_k</var></li> </ul> <h2 id="出力">出力</h2> <p>答えを <var>M</var> 行で出力せよ。 <var>i</var> 行目には、参加者 <var>i&minus;1</var> が目標点数以上の得点を獲得できるなら <code>Yes</code>、できないなら <code>No</code> と出力せよ。</p> <h2 id="サンプル">サンプル</h2> <h3 id="サンプル入力1">サンプル入力1</h3> <pre>6 1 2 1 3 4 5 7 1 3 4 5 3 1 0 2 4 5 3 4 5 3 </pre> <h3 id="サンプル出力1">サンプル出力1</h3> <pre>Yes Yes Yes Yes Yes No No </pre> <p>各参加者の得られる得点は以下のようになる。</p> <ul> <li>参加者0 : <var>1+1=2</var></li> <li>参加者1 : <var>1+2+1+3=7</var></li> <li>参加者2 : <var>1+2+1+3+4=11</var></li> <li>参加者3 : <var>1+2+1+3+4+5=16</var></li> <li>参加者4 : <var>1+2+1+3=7</var></li> <li>参加者5 : <var>1+1=2</var></li> <li>参加者6 : <var>0</var></li> </ul> <h3 id="サンプル入力2">サンプル入力2</h3> <pre>8 1 1 2 3 3 4 6 100 4 1 3 4 99 1 10 15 120 </pre> <h3 id="サンプル出力2">サンプル出力2</h3> <pre>Yes Yes No No </pre>
p00875
<H1><font color="#000">Problem B:</font> Repeated Substitution with Sed</H1> <p> Do you know "sed," a tool provided with Unix? Its most popular use is to substitute every occurrence of a string <i.&alpha;</i> contained in the input string (actually each input line) with another string <i>&beta;</i>. More precisely, it proceeds as follows. </p> <ol> <li> Within the input string, every non-overlapping (but possibly adjacent) occurrences of <i>&alpha;</i> are marked. If there is more than one possibility for non-overlapping matching, the leftmost one is chosen.</li> <li> Each of the marked occurrences is substituted with <i>&beta;</i> to obtain the output string; other parts of the input string remain intact.</li> </ol> <p> For example, when <i>&alpha;</i> is "<span>aa</span>" and <i>&beta;</i> is "<span>bca</span>", an input string "<span>aaxaaa</span>" will produce "<span>bcaxbcaa</span>", but not "<span>aaxbcaa</span>" nor "<span>bcaxabca</span>". Further application of the same substitution to the string "<span>bcaxbcaa</span>" will result in "<spna>bcaxbcbca</span>", but this is another substitution, which is counted as the second one. </p> <p> In this problem, a set of substitution pairs (<i>&alpha;<sub>i</sub></i>, <i>&beta;<sub>i</sub></i>) (<i>i</i> = 1, 2, ... , <i>n</i>), an initial string <i>&gamma;</i>, and a final string <i>&delta;</i> are given, and you must investigate how to produce <i>&delta;</i> from <i>&gamma;</i> with a minimum number of substitutions. A single substitution (<i>&alpha;<sub>i</sub></i>, <i>&beta;<sub>i</sub></i>) here means simultaneously substituting all the non-overlapping occurrences of <i>&alpha;<sub>i</sub></i>, in the sense described above, with <i>&beta;<sub>i</sub></i>. </p> <p> You may use a specific substitution (<i>&alpha;<sub>i</sub></i>, <i>&beta;<sub>i</sub></i> ) multiple times, including zero times. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each in the following format. </p> <p> <i>n</i><br> <i>&alpha;</i><sub>1</sub> <i>&beta;</i><sub>1</sub><br> <i>&alpha;</i><sub>2</sub> <i>&beta;</i><sub>2</sub><br> .<br> .<br> .<br> <i>&alpha;</i><sub><i>n</i></sub> <i>&beta;</i><sub><i>n</i></sub><br> <i>&gamma;</i></br> <i>&delta;</i></br> </p> <p> <i>n</i> is a positive integer indicating the number of pairs. <i>&alpha;<sub>i</sub></i> and <i>&beta;<sub>i</sub></i> are separated by a single space. You may assume that 1 &le; |<i>&alpha;<sub>i</sub></i>| &lt; |<i>&beta;<sub>i</sub></i>| &le; 10 for any <i>i</i> (|<i>s</i>| means the length of the string <i>s</i>), <i>&alpha;<sub>i</sub></i> &ne; <i>&alpha;<sub>j</sub></i> for any <i>i</i> &ne; <i>j</i>, <i>n</i> &le; 10 and 1 &le; |<i>&gamma;</i>| &lt; |<i>&delta;</i>| &le; 10. All the strings consist solely of lowercase letters. The end of the input is indicated by a line containing a single zero. </p> <H2>Output</H2> <p> For each dataset, output the minimum number of substitutions to obtain <i>&delta;</i> from <i>&gamma;</i>. If <i>&delta;</i> cannot be produced from <i>&gamma;</i> with the given set of substitutions, output <span>-1</span>. </p> <H2>Sample Input</H2> <pre> 2 a bb b aa a bbbbbbbb 1 a aa a aaaaa 3 ab aab abc aadc ad dee abc deeeeeeeec 10 a abc b bai c acf d bed e abh f fag g abe h bag i aaj j bbb a abacfaabe 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 -1 7 4 </pre>
p02848
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a string <var>S</var> consisting of uppercase English letters. Additionally, an integer <var>N</var> will be given.</p> <p>Shift each character of <var>S</var> by <var>N</var> in alphabetical order (see below), and print the resulting string.</p> <p>We assume that <code>A</code> follows <code>Z</code>. For example, shifting <code>A</code> by <var>2</var> results in <code>C</code> (<code>A</code> <var>\to</var> <code>B</code> <var>\to</var> <code>C</code>), and shifting <code>Y</code> by <var>3</var> results in <code>B</code> (<code>Y</code> <var>\to</var> <code>Z</code> <var>\to</var> <code>A</code> <var>\to</var> <code>B</code>).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq N \leq 26</var></li> <li><var>1 \leq |S| \leq 10^4</var></li> <li><var>S</var> consists of uppercase English letters.</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the string resulting from shifting each character of <var>S</var> by <var>N</var> in alphabetical order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 ABCXYZ </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>CDEZAB </pre> <p>Note that <code>A</code> follows <code>Z</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 ABCXYZ </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>ABCXYZ </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>13 ABCDEFGHIJKLMNOPQRSTUVWXYZ </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NOPQRSTUVWXYZABCDEFGHIJKLM </pre></section> </div> </span>
p01337
<h1><font color="#000">Problem E:</font> The Number of the Real Roots of a Cubic Equation</h1> <h2>Description</h2> <p>3次方程式:<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_03Emath" alt="ax^3+bx^2+cx+d=0"> が与えられるので,その正の実数根の個数,負の実数根の個数をそれぞれ調べて欲しい.</p> <p>根の個数は,重根も含めて数えるものとする.</p> <h2>Input</h2> <p>入力は複数のテストケースからなり,1行目にはその個数が記される.</p> <p>2行目以降は<i>a b c d</i>の形式で3次方程式の係数が記される.<i>a</i>は0ではなく,またそれぞれの数は-100から100までの整数値である.</p> <h2>Output</h2> <p>与えられた3次方程式に対し,正の実数根の個数,負の実数根の個数をスペースで区切って出力せよ.</p> <h2>Sample Input</h2> <pre> 2 1 3 3 1 -10 0 0 0 </pre> <h2>Output for Sample Input</h2> <pre> 0 3 0 0 </pre>
p00176
<H1>何色?</H1> <p> ウェブデザイナーを目指す太郎君はただいま修行中。事務所の先輩から「このページの背景色は#ffe085で」と、ウェブデザイン特有の色番号で指示されるのですが、それがどんな色かパッと思い浮かべることができません。 </p> <p> この色番号は光の三原色である赤、緑、青それぞれの強さを表わしています。具体的には2 桁の 16 進数を3 つ組み合わせたもので、色番号を“#RGB”とするとき、R は赤の強さ、G は緑の強さ、は青の強さを表します。それぞれ 00 から ff までの値になります。 </p> <p> 色番号にまだ不慣れな太郎君のために、色番号を入力とし、色の表の中からもっとも近い色の名前 を出力するプログラムを作成してください。使用する色の表は以下の通りです。 </p> <center> <table> <tr><td width="20">&nbsp;</td><td width="100"> 色の名前</td><td width="80">赤の強さ</td><td width="80"> 緑の強さ</td><td width="80"> 青の強さ</td></tr> <tr><td bgcolor="#000000"></td><td>black</td><td> 00</td><td> 00</td><td> 00</td></tr> <tr><td bgcolor="#0000ff"></td><td>blue</td><td> 00</td><td> 00</td><td> ff</td></tr> <tr><td bgcolor="#00ff00"></td><td> lime</td><td> 00</td><td> ff</td><td> 00</td></tr> <tr><td bgcolor="#00ffff"></td><td> aqua</td><td> 00</td><td> ff</td><td> ff</td></tr> <tr><td bgcolor="#ff0000"></td><td> red</td><td> ff</td><td> 00</td><td> 00</td></tr> <tr><td bgcolor="#ff00ff"></td><td> fuchsia</td><td> ff</td><td> 00</td><td> ff</td></tr> <tr><td bgcolor="#ffff00"></td><td> yellow</td><td> ff</td><td> ff</td><td> 00</td></tr> <tr><td bgcolor="#ffffff"></td><td> white</td><td> ff</td><td> ff</td><td> ff</td></tr> </table> </center> <br/> <br/> <p> 「もっとも近い色」とは、以下のように定義します。与えられた色番号での赤、緑、青の強さをそれぞれ <var>R</var>、<var>G</var>、<var>B</var> とし、表の <var>k</var> 番目の色の赤、緑、青の強さをそれぞれ <var>R<sub>k</sub></var>、<var>G<sub>k</sub></var>、<var>B<sub>k</sub></var> とするとき、次の式で計算する <var>d<sub>k</sub></var> の値が最も小さい色がもっとも近い色とします。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck2008_04"> </center> <br/> <br/> <p> なお、<var>d<sub>k</sub></var> の値が同じになる色が複数存在する場合は表の中でより上にある色がもっとも近い色になり ます。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。各データセットとして、色番号を表す文字列が、<span>#</span><var>RGB</var> 形式で1行に与えられます。 </p> <p> データセットの数は 1000 を超えません。 </p> <H2>Output</H2> <p> データセット毎に最も近い色の名前を1行に出力します。 </p> <H2>Sample Input</H2> <pre> #ffe085 #787878 #decade #ff55ff 0 </pre> <H2>Output for the Sample Input</H2> <pre> white black white fuchsia </pre>
p00526
<h2>電飾(Illumination)</h2> <p> JOI 高校の文化祭では毎年廊下に電飾が飾られる.電飾は <var>N</var> 個の電球で構成されており,電球は廊下の西側から東側に一列に並んでいる.各電球は明かりがついているか,ついていないかのいずれかの状態である. </p> <p> JOI 高校の倉庫には電球を操作する機械が眠っている.この機械は電飾内で連続した電球を指定すると,指定された電球のうち,明かりがついている電球全てを明かりがついていない状態にし,明かりがついていない電球全てを明かりがついている状態にする.ただし,機械は老朽化のため,1 回しか使用できない. </p> <p> JOI 高校の生徒達は明かりがついている電球とついていない電球が交互に並んだ列(このような電球の列を交互列と呼ぶ)が好きである.そこで,この機械を必要ならば1 回だけ使って,できるだけ長い交互列を含む電飾を作ることにした. </p> <h3>例</h3> <p> 例えば,電飾の配置が西から東に向かって </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_1_1"><br><br> <p> となっていたとする(○は明かりがついている電球を,●は明かりがついていない電球を表す).このとき,4 番目から7 番目までの4 個の電球に対して機械を操作すると, </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_1_2"><br><br> <p> となり,2 番目から8 番目までの電球が長さ7 の交互列をなす. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_1_3"><br><br> <p> また,8 番目の電球のみに対して機械を操作すると, </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_1_4"><br><br> <p> となり,4 番目から10 番目までの電球が長さ7 の交互列をなす. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_1_5"><br><br> <p> 機械を最大1 回使用することで,長さが8 以上の交互列を作ることはできない. </p> <h3>課題</h3> <p> 電飾の情報が与えられたとき,機械を最大1 回使用することで得られる電球の配列に含まれる交互列の長さとして考えられるものの最大値を求めるプログラムを作成せよ. </p> <h3>制限</h3> <ul> <li>2 &le; <var>N</var> &le; 100 000 &nbsp;&nbsp;&nbsp;&nbsp; 電飾を構成する電球の個数</li> </ul> <h3>入力</h3> <p> 標準入力から以下のデータを読み込め. </p> <ul> <li> 1 行目には整数 <var>N</var> が書かれている.</li> <li> 2 行目には <var>N</var> 個の 0 または 1 が空白を区切りとして書かれている.各整数は機械を操作する前における電球の情報を表している.左から<var>i</var> ( 1 &le; <var>i</var> &le; <var>N</var> ) 番目の整数は西側から <var>i</var> 番目の電球の情報を表しており,整数が 1 ならば電球の明かりがついていて,0 ならば明かりがついていないことを表す.</li> </ul> <h3>出力</h3> <p> 標準出力に,作成可能な電球の列に含まれる交互列の長さの最大値を表す整数を1 行で出力せよ. </p> <h3>入出力例</h3> <h3>入力例 1</h3> <pre> 10 1 1 0 0 1 0 1 1 1 0 </pre> <h3> 出力例 1</h3> <pre> 7 </pre> <p> これは問題文中で説明された例である. </p> <br> <h3>入力例 2</h3> <pre> 10 1 0 0 0 0 1 0 1 0 1 </pre> <h3>出力例 2</h3> <pre> 8 </pre> <p> 西側から 4 番目の電球のみを操作すると,最大値 8 を満たす交互列が得られる. </p> <br> <h3>入力例 3</h3> <pre> 5 1 1 0 1 1 </pre> <h3>出力例 3</h3> <pre> 5 </pre> <p> 西側から数えて 2 番目から 4 番目までの電球を操作すると,全ての電球からなる交互列を作ることがで きる. </p> <br> <h3>入力例 4</h3> <pre> 3 0 1 0 </pre> <h3>出力例 4</h3> <pre> 3 </pre> <p> 機械を使用しなくても良い場合があることに注意せよ. </p> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p00033
<H1>玉</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ball"> </center> <br/> <p> 図のように二股に分かれている容器があります。1 から 10 までの番号が付けられた10 個の玉を容器の開口部 A から落とし、左の筒 B か右の筒 C に玉を入れます。板 D は支点 E を中心に左右に回転できるので、板 D を動かすことで筒 B と筒 C のどちらに入れるか決めることができます。 </p> <p> 開口部 A から落とす玉の並びを与えます。それらを順番に筒 B 又は筒 Cに入れていきます。このとき、筒 B と筒 C のおのおのが両方とも番号の小さい玉の上に大きい玉を並べられる場合は YES、並べられない場合は NO と出力するプログラムを作成してください。ただし、容器の中で玉の順序を入れ替えることはできないものとします。また、続けて同じ筒に入れることができるものとし、筒 B, C ともに 10 個の玉がすべて入るだけの余裕があるものとします。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。1行目にデータセット数 <var>N</var> が与えられます。つづいて、<var>N</var> 行のデータセットが与えられます。各データセットに 10 個の番号が左から順番に空白区切りで与えられます。 </p> <H2>Output</H2> <p> 各データセットに対して、<span>YES</span> または <span>NO</span> を1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 2 3 1 4 2 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO </pre>
p00463
<H1>あみだくじ </H1> <h2>問題</h2> <p> あなたは J 君と一緒にあみだくじを使って遊んでいる.あみだくじは <i>n</i> 本の縦棒と <i>m</i> 本の横棒からなる.縦棒には左から順に 1 から <i>n</i> の番号がついており,縦棒 <i>i</i> の下端には正整数 <i>s<sub>i</sub></i> が書かれている. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amidakuji1"> <p> 図 3-1 あみだくじの例(<i>n</i> = 4, <i>m</i> = 5, <i>s</i><sub>1</sub> = 20, <i>s</i><sub>2</sub> = 80, <i>s</i><sub>3</sub> = 100, <i>s</i><sub>4</sub> = 50) </p> </center> <p> 縦棒 <i>i</i> の一番上から順に道をたどっていき到達した下端に書かれている整数が, 縦 棒 <i>i</i> を選んだ場合の得点である.例えば,図 3-1 では,縦棒 1 を選ぶと得点は 80 点 であり,縦棒 2 を選ぶと得点は 100 点である. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amidakuji2"> <p> 図 3-2 道のたどり方の例 </p> </center> <p> J 君は縦棒 1 から縦棒 <i>k</i> までの連続した <i>k</i> 本を選ぶことにした.それら <i>k</i> 本の縦棒を選んだときの点数の合計が J 君の得点となる.ただし,あなたはあみだくじ内の 横棒を一本選び,その横棒をあみだくじから削除することができる. (削除しなくてもよい.) もし,あなたが横棒を一本削除した場合は,削除後のあみだくじにおいて, 縦棒 1 から縦棒 <i>k</i> までの連続した <i>k</i> 本の縦棒を選んだときの点数の合計が J 君の得点となる. </p> <p> 入力としてあみだくじの形と J 君の選ぶ縦棒の本数 <i>k</i> が与えられたとき,J 君の得 点の最小値を求めるプログラムを作成せよ. </p> <h2>入力</h2> <p> <!-- 入力ファイルのファイル名は input.txt である.<br>--> 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. </p> <p> 1 行目には 4 つの整数 <i>n</i>, <i>m</i>, <i>h</i>, <i>k</i> が空白区切りで書かれている. <i>n</i> (2 &le; <i>n</i> &le; 1000) は縦棒の本数を, <i>m</i> (1 &le; <i>m</i> &le; 100000) は横棒の本数を, <i>h</i> (2 &le; <i>h</i> &le; 1000) は縦棒の長さを,<i>k</i> (1 &le; <i>k</i> &le; n) は J 君が選ぶ縦棒の本数を表す. </p> <p> 続く <i>n</i> 行には縦棒の下端に書かれている点数が書かれている. <i>i</i> + 1 行目 (1 &le; <i>i</i> &le; n)には正整数 <i>s<sub>i</sub></i> が書かれている. また, <i>s</i><sub>1</sub> + <i>s</i><sub>2</sub> + ... + <i>s<sub>n</sub></i> &le; 2000000000 = 2 &times; 10<sup>9</sup> を満たす. </p> <p> 続く <i>m</i> 行には横棒の位置が書かれている.横棒には 1 から <i>m</i> までの番号がついている.<i>i</i> + <i>n</i> + 1 行目 (1 &le; <i>i</i> &le; <i>m</i>) には, 横棒 <i>i</i> の位置を表す 2 つの整数 <i>a<sub>i</sub></i>, <i>b<sub>i</sub></i> (1 &le; <i>a<sub>i</sub></i> &le; <i>n</i> - 1, 1 &le; <i>b<sub>i</sub></i> &le; <i>h</i> - 1) が空白区切りで書かれており,横棒 <i>i</i> が縦棒 <i>a<sub>i</sub></i> と縦棒 <i>a<sub>i</sub></i> + 1 を結び, 横棒 <i>i</i> の上端からの距離が <i>b<sub>i</sub></i> であることを表す. ただし,どの 2 つの横棒も端点を共有することはない. </p> <p> 採点用データのうち,配点の 20 % 分は横棒を削除しない場合に J 君の得点が最少となる.また,配点の 30 % 分は <i>n</i> &le; 20, <i>m</i> &le; 30, <i>h</i> &le; 10 を満たし,配点の 60 % 分は <i>m</i> &le; 1000 を満たす. </p> <p> 入力の終わりは 4つのゼロを含む行で示される. データセットの数は 10 を超えない. </p> <h2>出力</h2> <p> <!-- 出力ファイルのファイル名は output.txt である. output.txt は J 君の得点の最小値のみを含む 1 行からなる. --> データセットごとに, J 君の得点の最小値を1 行に出力する. </p> <h2>入出力例</h2> <h3>入力例</h3> <pre> 4 5 7 2 20 80 100 50 1 1 2 6 2 3 1 5 3 1 2 2 5 1 10 20 1 1 1 3 0 0 0 0 </pre> <h3>出力例</h3> <pre> 100 10 </pre> <p> 1つ目の例 は図 3-1 に対応し,あなたが横棒 4 (縦棒 1 と縦棒 2 を上端から距離 5 の場所で結ぶ横棒)を削除したとき,J 君の得点は最小になる.例 2 では,あなたが横棒を削除しない場合に J 君の得点が最小になる. (図3-3 を見よ.) </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amidakuji3"> <p> 図 3-3 </p> </center> <br> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p00199
<h1>難儀な人たちが座る椅子</h1> <p> 4つの国の中心にある中立都市アイズシティには、大陸横断列車バンダイ号のホームがあります。 ホームには、バンダイ号を待つ乗客用の椅子が一列に用意されており、ホームに入ってきた人は自由に椅子を利用することができます。 </p> <p> このバンダイ号、安いし早いし快適ということで、周囲の4つの国からの利用者が絶えません。今日は開通記念日ということで、ホームに座っている人たちに特別なことをしてあげようと思っています。そのためには、改札を通った人たちがどこに座っているか把握しなければなりません。4つの国の人たちの難儀な性格を考慮して、椅子がどのように埋まっているかをシミュレートするプログラムを作成してください。改札を通った人たちは、次々に一列に並んだ椅子に座っていきます。4つの国の人たちは、国ごとに決まった性格と座り方があります。それぞれの座り方は以下の通りです。 </p> <table border=1 cellpadding=8 cellspacing=1> <tr> <td width=120>A国人の性格</td> <td> A 国人は座れればいい。左端から見ていき空いている椅子に座る。</td> </tr> </table> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chair1"> </center> <br/> <br/> <table border=1 cellpadding=8 cellspacing=1> <tr> <td width=120 rowspan="2">B国人の性格</td> <td colspan="2"> B 国人は A 国人が苦手。 A 国人の隣以外で、右端から空いている椅子に座る。ただし、 A国人の隣しか空いていない場合、我慢して左端から空いている椅子に座る。</td> </tr> </table> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chair2">&nbsp;&nbsp;&nbsp;&nbsp; <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chair3"> <br/> <br/> </center> <table border=1 cellpadding=8 cellspacing=1> <tr> <td width=120 rowspan="2">C国人の性格</td> <td colspan="2"> C 国人は人の隣に座りたい。左側から順に座っている人を見ていき、一番左側に座っている人 の右隣に座ろうとするが、そこが埋まっているならその人の左隣に座ろうとする。そこも埋まっ ているなら次の人の隣に同条件で座ろうとする。どの椅子にも人が座っていなければ真ん中(椅子の数 <var>n</var> が奇数の場合 (<var>n</var>+1)/2 、偶数の場合 <var>n</var>/2+1 )の椅子に座る。 </td> </tr> </table> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chair4">&nbsp;&nbsp;&nbsp;&nbsp; <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chair5"> <br/> <br/> </center> <table border=1 cellpadding=8 cellspacing=1> <tr> <td width=120 rowspan="2">D国人の性格</td> <td colspan="2"> D 国人は人の隣に座りたくない。一番近い人との距離が、一番大きくなる椅子に座ろうとする。同条件の椅子が複数ある場合や、どうしても誰かの隣に座らなければならない場合、その中で一番左側にある椅子に座る。誰も座っていない場合は左端の椅子に座る。 </td> </tr> </table> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chair6">&nbsp;&nbsp;&nbsp;&nbsp; <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chair7"> <br/> <br/> </center> <p> バンダイ号に乗ろうとしている乗客の情報を入力とし、 椅子にどのように座っているかを出力するプログラムを作成してください。左から順番に座っている人の国籍を出力します。ただし、空席の場合は # (半角シャープ)を出力してください。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。 入力の終わりはゼロふたつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>n</var> <var>m</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> : <var>a<sub>m</sub></var> </pre> <p> 1 行目に椅子の数 <var>n</var> (1 &le; <var>n</var> &le; 100) と乗客の数 <var>m</var> (<var>m</var> &le; <var>n</var>) が与えられます。続く <var>m</var> 行に <var>i</var> 人目の情報 <var>a<sub>i</sub></var> が与えられます。<var>a<sub>i</sub></var> は1つの文字で、'A' ならば A 国人、'B' ならば B 国人、'C' ならば C 国人、'D' ならば D 国人を表します。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、最終的な椅子の状態を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 5 4 A B C D 5 4 D C B A 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> ACD#B DCA#B </pre>
p01622
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <!-- begin en only --> <!-- <h3><u>Twin book report</u></h3> --> <!-- end en only --> <!-- begin ja only --> <h1><u>双子の読書感想文</u></h1> <!-- end ja only --> <!-- begin en only --> <!-- <p> English text is not available in this practice contest. </p> --> <!-- end en only --> <!-- begin ja only --> <p> 双子のアミとマミが通う学校では早くも夏休みに突入し,今年もおびただしい量の宿題が出された. しかし,遊び盛りの2人は今日も宿題には一切手をつけずに外へ遊びに行こうとしていた. このままでは夏休み最終日に泣きを見るのは明らかなので,保護者役のあなたは,心を鬼にして今日は読書感想文の宿題が終わるまで2人を家から出さないことにした. </p> <p> 準備の良いあなたは既に図書館から全ての課題図書を借りてある. ただし,図書館の規則により各本は1冊ずつしか借りられていない. さて,教育上の理由から2人には互いに協力することなく,それぞれ全ての本を読み,感想を書いてもらう事にした. 加えて,本の返却期限が近いため,まずはなるべく早くすべての本を読み終えるようにしてもらう事にした. そして,あなたはその条件下でなるべく早く宿題が終わるような宿題の進め方を考えることにした. ここで,本を読み終えた時間,宿題を終えた時間は,それぞれ双子の両方が作業を終えた時間で考える. </p> <p> 各本は1冊ずつしかないため,2人が同時刻に同じ本を読むことはできない. 加えて,大人の事情により,ある本を読み始めたらそれを中断する事はできず,ある本についての感想文を書き始めたらそれを中断することもできない. 当然ながら,読んでいない本について感想を書くこともできない. なお,アミとマミは双子であるため,各本について読むのにかかる時間,感想文を書くのにかかる時間は2人で共通している. </p> <p> 例えば,3冊の本があり,それぞれ本を読むのにかかる時間,感想文を書くのにかかる時間が以下の通りであるとする. </p> <center> <table cellpadding="4" cellspacing="4" style="border: solid 1px #000"> <tr align=right> <td style="border: solid 1px #000"></td> <td style="border: solid 1px #000">本を読む時間</td> <td style="border: solid 1px #000">感想文を書く時間</td> </tr> <tr align=right> <td style="border: solid 1px #000">本1</td> <td style="border: solid 1px #000">5</td> <td style="border: solid 1px #000">3</td> </tr> <tr align=right> <td style="border: solid 1px #000">本2</td> <td style="border: solid 1px #000">1</td> <td style="border: solid 1px #000">2</td> </tr> <tr align=right> <td style="border: solid 1px #000">本3</td> <td style="border: solid 1px #000">1</td> <td style="border: solid 1px #000">2</td> </tr> </table> </center> <br/> <p> この場合は,図C-1のように宿題を進めると,時間10で全ての本を読み終え,時間15で宿題を終える事ができる. 図C-2の進め方では時間14で宿題を終えているが,本を読み終える時間が最短でないため,今回は採用できない. また,図C-3のように2人が同時に同じ本を読んだり, 図C-4のように本を読むのを中断したり,読んでいない本の感想を書く事もできない. </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_twinBookReport_1" height="167" width="762"> </center> </center> <center> <p> <i>図 C-1: 最短で宿題を終わらせる進め方の例</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_twinBookReport_2" height="167" width="762"> </center> </center> <center> <p> <i>図 C-2: 本を読み終える時間が最短でない例</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_twinBookReport_3" height="167" width="762"> </center> </center> <center> <p> <i>図 C-3: 2人が同時に同じ本を読んでしまっている例</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_twinBookReport_4" height="168" width="762"> </center> </center> <center> <p> <i>図 C-4: 読んでいない本の感想を書いたり,作業を中断したりしている例</i> </p> </center> <p> 様々な大人の事情を考慮しつつ,遊びに行きたがっている双子のためになるべく早く宿題が終わるような進め方を考えてあげよう. </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は複数のデータセットから構成される.各データセットの形式は次の通りである. </p> <pre> <var>N</var> <var>r<sub>1</sub></var> <var>w<sub>1</sub></var> <var>r<sub>2</sub></var> <var>w<sub>2</sub></var> <var>...</var> <var>r<sub>N</sub></var> <var>w<sub>N</sub></var> </pre> <p> Nは課題図書の数を表す整数であり,1以上1,000以下と仮定して良い. </p> <p> 続くN行は課題図書についての情報を表す. 各行はスペースで区切られた2つの整数を含み,r<sub>i</sub> (1 &#8804; r<sub>i</sub> &#8804; 1,000) は i 番目の本を読むのにかかる時間,w<sub>i</sub> (1 &#8804; w<sub>i</sub> &#8804; 1,000) は i 番目の本の感想文を書くのにかかる時間を表す. </p> <p> N=0 は入力の終わりを示す. これはデータセットには含めない. </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各データセットについて,2人が全ての本を読み終えるまでの時間を最小にしたときの,全ての感想文を書き終えるまでの最小の時間を1行に出力しなさい. </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 4 1 1 3 1 4 1 2 1 3 5 3 1 2 1 2 1 1000 1000 10 5 62 10 68 15 72 20 73 25 75 30 77 35 79 40 82 45 100 815 283 6 74 78 53 55 77 77 12 13 39 42 1 1 0 </pre> <!-- begin ja only --> <!-- end ja only --> <h3>Output for Sample Input</h3> <pre> 14 15 3000 2013 522 </pre> <!-- begin ja only --> <!-- end ja only -->
p00930
<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 G: Flipping Parentheses </h2> <p> A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. </p> <ul> <li> A string "()" is balanced.</li> <li> Concatenation of two balanced strings are balanced.</li> <li> When a string $s$ is balanced, so is the concatenation of three strings "(", $s$, and ")" in this order.</li> </ul> <p> Note that the condition is stronger than merely the numbers of '(' and ')' are equal. For instance, "())(()" is not balanced. </p> <p> Your task is to keep a string in a balanced state, under a severe condition in which a cosmic ray may flip the direction of parentheses. </p> <p> You are initially given a balanced string. Each time the direction of a single parenthesis is flipped, your program is notified the position of the changed character in the string. Then, calculate and output the <i>leftmost</i> position that, if the parenthesis there is flipped, the whole string gets back to the balanced state. After the string is balanced by changing the parenthesis indicated by your program, next cosmic ray flips another parenthesis, and the steps are repeated several times. </p> <h3>Input</h3> <p> The input consists of a single test case formatted as follows.<br> <br> $N$ $Q$<br> $s$<br> $q_1$<br> .<br> .<br> .<br> $q_Q$<br> <br> The first line consists of two integers $N$ and $Q$ ($2 \leq N \leq 300000$, $1 \leq Q \leq 150000$). The second line is a string $s$ of balanced parentheses with length $N$. Each of the following $Q$ lines is an integer $q_i$ ($1 \leq q_i \leq N$) that indicates that the direction of the $q_i$-th parenthesis is flipped. </p> <h3>Output</h3> <p> For each event $q_i$, output the position of the leftmost parenthesis you need to flip in order to get back to the balanced state. </p> <p> Note that each input flipping event $q_i$ is applied to the string after the previous flip $q_{i−1}$ and its fix. </p> <h3>Sample Input 1</h3> <pre>6 3 ((())) 4 3 1</pre> <h3>Sample Output 1</h3> <pre>2 2 1</pre> <h3>Sample Input 2</h3> <pre>20 9 ()((((()))))()()()() 15 20 13 5 3 10 3 17 18</pre> <h3>Sample Output 2</h3> <pre>2 20 8 5 3 2 2 3 18</pre> <p> In the first sample, the initial state is "((()))". The 4th parenthesis is flipped and the string becomes "(((())". Then, to keep the balance you should flip the 2nd parenthesis and get "()(())". The next flip of the 3rd parenthesis is applied to the last state and yields "())())". To rebalance it, you have to change the 2nd parenthesis again yielding "(()())". </p>
p01272
<h1><font color="#000">Problem F:</font> Shore Erosion</h1> <p> あなたは地元の市役所に勤めるプログラマーである.あなたの住んでいる町は観光業が盛んで,とくに離れ小島にある海岸の海水浴場が人気がある.この島の周囲は砂浜により構成されているのだが,近年海岸浸食によって砂浜の面積が減ってきた.事態を重く見た観光課は,あなたに砂浜の形状変化のシミュレーションを依頼してきた. </p> <p> シミュレーションでは,現在の砂浜の形状をもとに,ある期間が経過した後の砂浜の形状を求める.簡単のため,島の海岸線の形状は多角形(凸とは限らない)とみなす.期間のうちに,砂浜は現在の海岸線からマンハッタン距離で <i>R</i> だけ浸食されて海に沈むものと仮定する.ここで,マンハッタン距離とは <i>x</i> 座標同士の差と <i>y</i> 座標同士の差を足したものである.すなわち,(<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) と (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) のマンハッタン距離は |<i>x</i><sub>1</sub> - <i>x</i><sub>2</sub>| + |<i>y</i><sub>1</sub> - <i>y</i><sub>2</sub>| で与えられる. </p> <p> あなたの仕事は,入力として与えられた砂浜の海岸線から,シミュレーションの結果として得られる海岸線の長さを求めるプログラムを書くことである.なお,島が海岸浸食により 2 つ以上に分割された場合は,分割されたそれぞれの島について海岸線の長さを求めて,それらの和を出力すること. </p> <p> なお,海岸線に含まれる 2 本の線分について,平行でかつマンハッタン距離がちょうど 2<i>R</i> になることはない.<!--また,浸食幅 <i>R</i> が &epsilon; (|&epsilon;| &lt; ????) だけ変化したときに,結果の長さが ????? より大きく変化することはないと仮定してよい.--> </p> <h3>Input</h3> <p> 入力は,複数のデータセットからなる.各データセットは次の形式で与えられる. </p> <blockquote> <i>N</i> <i>R</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub><br> ...<br> <i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub> </blockquote> <p> 最初の行では 2 つの非負の整数 <i>N</i> (3 &le; <i>N</i> &le; 100),<i>R</i> (0 &lt; <i>R</i> &le; 100) が与えられる. これらの整数は,それぞれ海岸線の頂点数と浸食される距離を表す. 続く <i>N</i> 行では頂点の情報が各行に 1 つずつ与えられる. 頂点の情報は 2 つの整数 <i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub> (-10000 &le; <i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub> &le; 10000) で与えられる. 座標 (<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>) は,それぞれ海岸線の <i>i</i> 番目の頂点の座標を表す. なお,島の頂点座標は常に反時計回りで与えられる. </p> <p> 入力の終わりは,空白で区切られた 2 つの 0 を含む 1 行で示される. </p> <h3>Output</h3> <p> 各データセットに対して,浸食された海岸線の長さを出力せよ.なお,島が完全に浸食され消失した場合は海岸線の長さは 0.0 と扱うこと.出力する値は 0.01 以下の誤差を含んでいても構わない.また,値は小数点以下何桁表示しても構わない. </p> <h3>Sample Input</h3> <pre> 3 1 0 0 10 0 5 10 3 1 0 0 10 0 0 10 4 1 0 0 10 0 10 10 0 10 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 22.6524758425 23.8994949366 32.0000000000 </pre>
p01788
<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>I - Tokyo Olympics Center</h2> <h3>Problem Statement</h3> <p> You are participating in the Summer Training Camp for Programming Cotests. The camp is held in an accommodation facility called <i>Tokyo Olympics Center</i>. Today is the last day of the camp. Unfortunately, you are ordered to check if all the participants have properly cleaned their rooms. </p> <p> The accommodation facility is a rectangular field whose height is $H$ and width is $W$. The field is divided into square cells. The rows are numbered $1$ through $H$ from top to bottom and the columns are numbered $1$ through $W$ from left to right. The cell in row $i$, column $j$ is denoted by $(i, j)$. Two cells are adjacent if they share an edge. </p> <p> Each cell is called either a <i>wall cell</i> or a <i>floor cell</i>. A wall cell represents a wall which no one can enter. A floor cell is a part of the inside of the accommodation facility. Everybody can move between two adjacent floor cells. The floor cells are divided into several units. Each unit is assigned an uppercase English letter (<code>A</code>, <code>B</code>, <code>C</code>, ...). A floor cell adjacent to exactly one floor cell is called a <i>room</i>. Otherwise the floor cell is called an <i>aisle</i>. For example, the accommodation facility can be shown as the following figure. We denote a wall cell by <code>.</code> (single period). </p> <pre>................... .....AAABBBBBBB.... ...A.AA.A...B.B..B. ..AAAAAAAABBBBBBBB. ...A..A.A.....B.... ......A.......BBBB. ....A.AA..C.C...B.. ...AAAAACCCCCCBBBB. ...A..A...C.C...B.. ...................</pre> <p> In the above figure, there are $7$ rooms in unit A, $4$ rooms in unit B, and $4$ rooms in unit C. </p> <p> Because the accommodation facility is too large to explore alone, you asked the other participants of the camp to check the rooms. For simplicity's sake, we call them <i>staffs</i>. Now, there are $K$ staffs at the cell $(s, t)$. You decided to check the rooms according to the following procedure. </p> <ol> <li> First, you assign each staff to some of units. Every unit must be assigned to exactly one staff. Note that it is allowed to assign all the units to one staff or to assign no units to some staffs.</li> <li> Then, each staff starts to check the rooms in the assigned units at the same time. The staffs can move between two adjacent floor cells in $T_{\mathit{move}}$ time. To check the room at $(i, j)$, the staffs must move to the cell $(i, j)$ and spend $T_{\mathit{check}}$ time there. Each staff first determines the order of the units to check and he or she must check the rooms according to the order. For example, suppose that there is a staff who is assigned units A, C, and E. He may decide that the order is E-&gt;A-&gt;C. After that, he must check all the rooms in unit E at first. Then, he must check all the rooms in unit A, and so on. The staffs can pass any floor cells. However, the staffs cannot check rooms that are not assigned to them. Further, the staffs cannot check rooms against the order of units that they have decided. </li> <li> After checking all the assigned rooms, the staffs must return to the cell $(s, t)$. </li> <li> When every staff returns to the cell $(s, t)$, the task is done. </li> </ol> <p> Because you do not have enough time before the next contest, you want to minimize the total time to check all the rooms. </p> <h3>Input</h3> <p> The first line of the input contains three integers $H$, $W$, and $K$ ($1 \le H \le 50$, $1 \le W \le 50$, $1 \le K \le 12$). The second line contains four integers $s$, $t$, $T_{\mathit{move}}$, and $T_{\mathit{check}}$ ($1 \le s \le H$, $1 \le t \le W$, $1 \le T_{\mathit{move}},T_{\mathit{check}} \le 10{,}000$). Each of the following $H$ lines contains exactly $W$ characters. Each character represents a cell in the accommodation facility. The $j$-th character in the $i$-th line of these lines is <code>.</code> if the cell $(i, j)$ is a wall cell. Otherwise, the character is an uppercase English letter (<code>A</code>-<code>L</code>) representing the unit to which the cell $(i, j)$ belongs. </p> <p> You can assume that the following conditions are satisfied. </p> <ul> <li> The number of rooms in each unit is between $1$ and $12$, inclusive. </li> <li> The cell $(s, t)$ is guaranteed to be an aisle.</li> <li> Floor cells in each unit are connected.</li> <li> Floor cells in the field are connected.</li> <li> Every unit contains at least two cells.</li> </ul> <h3>Output</h3> <p> Output the minimum required time to check all the rooms in one line. </p> <h3>Sample Input 1</h3> <pre>3 3 1 1 1 10 10 AAA A.. A..</pre> <h3>Output for the Sample Input 1</h3> <pre>100</pre> <h3>Sample Input 2</h3> <pre>3 3 2 1 1 10 10 ABB A.. A..</pre> <h3>Output for the Sample Input 2</h3> <pre>50</pre> <h3>Sample Input 3</h3> <pre>5 10 3 3 6 1 100 ...G.H.A.. .AAGAHAABB FFAAAAAAA. .EEAAADACC ..E...D...</pre> <h3>Output for the Sample Input 3</h3> <pre>316</pre> <h3>Sample Input 4</h3> <pre>10 19 2 6 15 3 10 ................... .....AAABBBBBBB.... ...A.AA.A...B.B..B. ..AAAAAAAABBBBBBBB. ...A..A.A.....B.... ......A.......BBBB. ....A.AA..C.C...B.. ...AAAAACCCCCCBBBB. ...A..A...C.C...B.. ...................</pre> <h3>Output for the Sample Input 4</h3> <pre>232</pre> <h3>Sample Input 5</h3> <pre>27 36 6 24 19 616 1933 .................................... ..........B...............B......... ..........BBB..........BBBB......... ..........BBBBB.......BBBB.......... ...........BBBBBBBBBBBBBBB.......... ...........BBBBBBBBBBBBBBB.......... ...........BBBBBBBBBBBBBB........... ............BBBBBBBBBBBBB........... ...........BBBBBBBBBBBBBBB.......... ..........BBBBBBBBBBBBBBBBB......... ......B...BBBBBBBBBBBBBBBBB...B..... ......BB.BBBBBBBBBBBBBBBBBB..BB..... .......BBBBBBBBBBBBBBBBBBBB.BB...... .........BBBBBBBBBBBBBBBBBBBB....... ........BBBBB..BBBBBBBB..BBBBB...... ......BBBBBB....BBBBB....BBBBBB..... .....BBBBBBBB...BBBBB..BBBBBBBB.B... ...BBBBBBB..B...BBBBB..B..BBBBBBBB.. .BBBBBBBBB.....BBBBBBB......BBBBBBB. ..BBBBBBB......BBBBBBB........BBB... .BBBB.........BBBBBBBBB........BBB.. ..............BBBBBBBBB............. .............BBBBBBBBBB............. .............BBBBBBBBBB............. ..............BBBBBBBB.............. ..............BBBBBBBB.............. ....................................</pre> <h3>Output for the Sample Input 5</h3> <pre>137071</pre>
p01065
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Barter</h1> <!-- <p> 私の名前は五月雨ほたる。父のお菓子会社に駄菓子屋を経営する馬田ヨウさんを引っこ抜くためにこの村にやってきたわ。そこで出会ったヨウさんの息子のナナツくんが駄菓子センスバツグン!…なのだけれど、自身は漫画を書きたがっていて、ヨウさんの駄菓子屋を継ぐ気がないみたい……せっかく才能があるのだから、どうにか説得して駄菓子屋を継がせたいのだけれど…… </p> <p> そうだわ!駄菓子交換会を開催しましょう!少ないお小遣いでやりくりする子どもたちにとって、交換会は普段買わないような駄菓子を試し、また買いすぎたお菓子を処分する千載一遇のチャンス……駄菓子センスバツグンなナナツ君なら、きっとこれで少年の心を取り戻し、ヨウさんの駄菓子屋を継いでくれるはずよ! </p> --> <h2>Problem</h2> <p> ナナツ君は、うまか棒を<var>x</var>本、ふがしを<var>y</var>本持っている。<br><br> <var>n</var>人のお菓子交換人がいる。 それぞれの交換人<var>i</var>は、 </p> <ul> <li>ナナツ君のうまか棒<var>a<sub>i</sub></var>本と交換人のふがし<var>b<sub>i</sub></var>本</li> <li>ナナツ君のふがし<var>c<sub>i</sub></var>本と交換人のブタメソ<var>d<sub>i</sub></var>個</li> </ul> <p> のどちらか1つの方法で1回だけ交換してくれる。<br><br> この制約の下で、最終的に所持しているブタメソの個数を最大化せよ。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> <var>n</var> <var>x</var> <var>y</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var> <var>d<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var> <var>d<sub>2</sub></var> ... <var>a<sub>n</sub></var> <var>b<sub>n</sub></var> <var>c<sub>n</sub></var> <var>d<sub>n</sub></var> </pre> <p> 1行目に整数<var>n</var>が与えられる。<br> 2行目に整数<var>x</var>, <var>y</var>が空白区切りで与えられる。<br> 3行目から<var>n</var>+2行目に整数<var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>c<sub>i</sub></var>, <var>d<sub>i</sub></var>が空白区切りで与えられる。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>n</var> &le; 100</li> <li>0 &le; <var>x</var>, <var>y</var> &le; 300</li> <li>1 &le; <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>c<sub>i</sub></var>, <var>d<sub>i</sub></var> &le; 300</li> <li>\(\sum_{i=1}^na_i\) &le; 300, \(\sum_{i=1}^nb_i\) &le; 300, \(\sum_{i=1}^nc_i\) &le; 300, \(\sum_{i=1}^nd_i\) &le; 300</li> </ul> <h2>Output</h2> <p> 最終的にナナツ君が所持しているブタメソの個数の最大値を1行に出力する </p> <h2>Sample Input 1</h2> <pre> 3 3 3 3 2 4 1 5 1 2 1 3 1 3 2 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <h2>Sample Input 2</h2> <pre> 3 3 4 3 1 3 1 3 1 4 1 3 1 2 1 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> <h2>Sample Input 3</h2> <pre> 4 5 0 5 1 1 1 2 1 2 1 4 1 1 1 3 1 3 1 </pre> <h2>Sample Output 3</h2> <pre> 2 </pre> <h2>Sample Input 4</h2> <pre> 4 0 0 1 10 1 10 2 5 2 5 3 25 5 6 1 15 2 20 </pre> <h2>Sample Output 4</h2> <pre> 0 </pre>
p03058
<span class="lang-en"> <p>Score : <var>2200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a tree <var>T</var> with <var>N</var> vertices and an undirected graph <var>G</var> with <var>N</var> vertices and <var>M</var> edges. The vertices of each graph are numbered <var>1</var> to <var>N</var>. The <var>i</var>-th of the <var>N-1</var> edges in <var>T</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>, and the <var>j</var>-th of the <var>M</var> edges in <var>G</var> connects Vertex <var>c_j</var> and Vertex <var>d_j</var>.</p> <p>Consider adding edges to <var>G</var> by repeatedly performing the following operation:</p> <ul> <li>Choose three integers <var>a</var>, <var>b</var> and <var>c</var> such that <var>G</var> has an edge connecting Vertex <var>a</var> and <var>b</var> and an edge connecting Vertex <var>b</var> and <var>c</var> but not an edge connecting Vertex <var>a</var> and <var>c</var>. If there is a simple path in <var>T</var> that contains all three of Vertex <var>a, b</var> and <var>c</var> in some order, add an edge in <var>G</var> connecting Vertex <var>a</var> and <var>c</var>.</li> </ul> <p>Print the number of edges in <var>G</var> when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2000</var></li> <li><var>1 \leq M \leq 2000</var></li> <li><var>1 \leq a_i, b_i \leq N</var></li> <li><var>a_i \neq b_i</var></li> <li><var>1 \leq c_j, d_j \leq N</var></li> <li><var>c_j \neq d_j</var></li> <li><var>G</var> does not contain multiple edges.</li> <li><var>T</var> is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_1</var> <var>d_1</var> <var>:</var> <var>c_M</var> <var>d_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the final number of edges in <var>G</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 1 2 1 3 3 4 1 5 5 4 2 5 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>We can have at most six edges in <var>G</var> by adding edges as follows:</p> <ul> <li>Let <var>(a,b,c)=(1,5,4)</var> and add an edge connecting Vertex <var>1</var> and <var>4</var>.</li> <li>Let <var>(a,b,c)=(1,5,2)</var> and add an edge connecting Vertex <var>1</var> and <var>2</var>.</li> <li>Let <var>(a,b,c)=(2,1,4)</var> and add an edge connecting Vertex <var>2</var> and <var>4</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 5 1 5 1 4 1 7 1 2 2 6 6 3 2 5 1 3 1 6 4 6 4 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>11 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>13 11 6 13 1 2 5 1 8 4 9 7 12 2 10 11 1 9 13 7 13 11 8 10 3 8 4 13 8 12 4 7 2 3 5 11 1 4 2 11 8 10 3 5 6 9 4 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>27 </pre></section> </div> </span>
p01435
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script> <h2>問題文</h2> <p> <i>キュゥべえ</i>はワルプルギスの夜に向けて魔女の合成に明け暮れている.ワルプルギスの夜のために,特別な<i>グリーフシード</i> (魔女の卵) を使って手に入れやすい魔女をうまく合成し目的である舞台装置の魔女を創り上げなければならないからである. </p> <p> <i>キュゥべえ</i>は手に入れやすい種類の魔女の<i>グリーフシード</i>から魔女の素となるものを取り出し,空の特別な<i>グリーフシード</i>に入れることで,その<i>グリーフシード</i>に魔女を宿らせることができる.また,この世界には,ある組み合わせで複数の魔女を合成すると新たな <var>1</var> つの魔女を生み出すことができるという合成法則がいくつかある.そこで,いくつかの特別な<i>グリーフシード</i>を使い,それらの中にある魔女の素となるものを合成し,<var>1</var> つの特別な<i>グリーフシード</i>に新たな魔女を宿らせることができる.また,合成した結果空となった特別な<i>グリーフシード</i>は再利用することができる.例えば,<var>3</var> 個の特別な<i>グリーフシード</i>に入った魔女を合成すると,それらの <var>3</var> 個の<i>グリーフシード</i>は,新たな魔女が宿った <var>1</var> 個の特別な<i>グリーフシード</i>と <var>2</var> 個の空の特別な<i>グリーフシード</i>となる.しかし,同じ種類の魔女を同時に複数の<i>グリーフシード</i>に入れることは出来ない. </p> <p> <i>キュゥべえ</i>は魔女の特別な<i>グリーフシード</i>への寄宿と魔女の合成を繰り返すことにより舞台装置の魔女を創りだしたい.舞台装置の魔女を創りだすにはいくつの特別な<i>グリーフシード</i>が必要か求めよ. </p> <h2>入力形式</h2> <p>入力は以下のような形式で与えられる.</p> <pre><var> N\ E\ T\\ W_1\ W_2\ …\ W_N\\ G_1\ C_1\ S_{1,1}\ S_{1,2}\ …\ S_{1,C_1}\\ G_2\ C_2\ S_{2,1}\ S_{2,2}\ …\ S_{2,C_2}\\ …\\ G_E\ C_E\ S_{E,1}\ S_{E,2}\ …\ S_{E,C_E}\\ </var></pre> <p><var>N</var> は魔女の種類の個数,<var>E</var> は合成法則の個数,<var>T</var> は舞台装置の魔女の番号である.<var>W_i</var> は <var>i</var> 番目の魔女が手に入れやすい魔女であるかどうかを表し,<code>1</code> ならば手に入れやすい魔女であり,<code>0</code> ならば手に入れやすい魔女ではない.</p> <p>続く <var>E</var> 行に合成法則が次のように表される:「番号が <var>S_{i,1}\ S_{i,2}\ …\ S_{i,C_i}</var> の魔女を合成することによって <var>G_i</var> の番号の魔女が得られる.」</p> <h2>出力形式</h2> <p>舞台装置の魔女を創りだすのに最低限必要な特別な<i>グリーフシード</i>の個数を出力せよ.創りだすことができない場合は <code>-1</code> を出力せよ.</p> <h2>制約</h2> <ul> <li><var>1 \lt N \leq 300</var></li> <li><var>0 \leq E \leq 1000</var></li> <li><var>1 \leq T \leq N</var></li> <li><var>0 \leq W_i \leq 1\ (1 \leq i \leq N)</var></li> <li><var>1 \leq G_i \leq N\ (1 \leq i \leq E)</var></li> <li><var>2 \leq C_i \leq 10\ (1 \leq i \leq E)</var></li> <li><var>1 \leq S_{i,j} \leq N\ (1 \leq i \leq E,\ 1 \leq j \leq C_i)</var></li> <li><var>\{G_i, S_{i,1}\ S_{i,2}\ …\ S_{i,C_i}\}</var> は全て異なる.</li> <li>入力中に同一の合成法則が <var>2</var> 回以上現れることはない.</li> </ul> <h2>入出力例</h2> <h3>入力例 1</h3> <pre>3 1 3 1 1 0 3 2 1 2</pre> <h3>出力例1</h3> <pre>2</pre> <h3>入力例 2</h3> <pre>5 0 1 1 1 1 1 1</pre> <h3>出力例 2</h3> <pre>1</pre> <h3>入力例 3</h3> <pre>18 5 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 2 3 4 5 2 2 6 7 3 3 8 9 10 4 4 11 12 13 14 5 4 15 16 17 18</pre> <h3>出力例 3</h3> <pre>5</pre> <h3>入力例 4</h3> <pre>6 4 6 1 1 1 0 0 0 4 2 1 2 5 2 2 3 6 2 4 5 6 3 1 2 4</pre> <h3>出力例 4</h3> <pre>3</pre> <h3>入力例 5</h3> <pre>13 9 13 1 1 0 1 1 0 1 1 0 1 1 0 0 3 2 1 2 6 2 4 5 9 2 7 8 12 2 10 11 6 2 2 3 9 2 5 6 12 2 8 9 3 2 11 12 13 4 3 6 9 12</pre> <h3>出力例 5</h3> <pre>5</pre> <h3>入力例 6</h3> <pre>4 4 4 1 1 0 0 1 2 2 3 2 2 3 1 3 2 1 2 3 3 1 2 4</pre> <h3>出力例 6</h3> <pre>-1</pre> <hr> <address>Problem Setter: Flat35</address>
p03408
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has <var>N</var> blue cards and <var>M</var> red cards. A string is written on each card. The string written on the <var>i</var>-th blue card is <var>s_i</var>, and the string written on the <var>i</var>-th red card is <var>t_i</var>.</p> <p>Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn <var>1</var> yen (the currency of Japan); each time he finds a red card with that string, he will lose <var>1</var> yen.</p> <p>Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces <code>atcoder</code>, he will not earn money even if there are blue cards with <code>atcoderr</code>, <code>atcode</code>, <code>btcoder</code>, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)</p> <p>At most how much can he earn on balance?</p> <p>Note that the same string may be written on multiple cards.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> and <var>M</var> are integers.</li> <li><var>1 \leq N, M \leq 100</var></li> <li><var>s_1, s_2, ..., s_N, t_1, t_2, ..., t_M</var> are all strings of lengths between <var>1</var> and <var>10</var> (inclusive) consisting of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s_1</var> <var>s_2</var> <var>:</var> <var>s_N</var> <var>M</var> <var>t_1</var> <var>t_2</var> <var>:</var> <var>t_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Takahashi can earn at most <var>X</var> yen on balance, print <var>X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 apple orange apple 1 grape </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>He can earn <var>2</var> yen by announcing <code>apple</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 apple orange apple 5 apple apple apple apple apple </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>If he announces <code>apple</code>, he will lose <var>3</var> yen. If he announces <code>orange</code>, he can earn <var>1</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 voldemort 10 voldemort voldemort voldemort voldemort voldemort voldemort voldemort voldemort voldemort voldemort </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>If he announces <code>voldemort</code>, he will lose <var>9</var> yen. If he announces <code>orange</code>, for example, he can avoid losing a yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 red red blue yellow yellow red 5 red red yellow green blue </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre></section> </div> </span>
p01966
<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> Conveyor Belt </H1> <p> <i>Awesome Conveyor Machine</i> (ACM) is the most important equipment of a factory of <i>Industrial Conveyor Product Corporation</i> (ICPC). ACM has a long conveyor belt to deliver their products from some points to other points. You are a programmer hired to make efficient schedule plan for product delivery. </p> <p> ACM's conveyor belt goes through $N$ points at equal intervals. The conveyor has plates on each of which at most one product can be put. Initially, there are no plates at any points. The conveyor belt moves by exactly one plate length per unit time; after one second, a plate is at position 1 while there are no plates at the other positions. After further 1 seconds, the plate at position 1 is moved to position 2 and a new plate comes at position 1, and so on. Note that the conveyor has the unlimited number of plates: after $N$ seconds or later, each of the $N$ positions has exactly one plate. </p> <p> A delivery task is represented by positions $a$ and $b$; delivery is accomplished by putting a product on a plate on the belt at $a$, and retrieving it at $b$ after $b - a$ seconds ($a < b$). (Of course, it is necessary that an empty plate exists at the position at the putting time.) In addition, putting and retrieving products must bedone in the following manner: </p> <ul> <li>When putting and retrieving a product, a plate must be located just at the position. That is, products must be put and retrieved at integer seconds.</li> <li>Putting and retrieving at the same position <i>cannot</i> be done at the same time. On the other hand, putting and retrieving at the different positions can be done at the same time.</li> </ul> <p> If there are several tasks, the time to finish all the tasks may be reduced by changing schedule when each product is put on the belt. Your job is to write a program minimizing the time to complete all the tasks... wait, wait. When have you started misunderstanding that you can know all the tasks initially? New delivery requests are coming moment by moment, like plates on the conveyor! So you should update your optimal schedule per every new request. </p> <p> A request consists of a start point $a$, a goal point $b$, and the number $p$ of products to deliver from $a$ to $b$. Delivery requests will be added $Q$ times. Your (true) job is to write a program such that for each $1 \leq i \leq Q$, minimizing the entire time to complete delivery tasks in requests 1 to $i$. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $N$ $Q$ $a_1$ $b_1$ $p_1$ : $a_Q$ $b_Q$ $p_Q$ </pre> <p> A first line includes two integers $N$ and $Q$ ($2 \leq N \leq 10^5, 1 \leq Q \leq 10^5$): $N$ is the number of positions the conveyor belt goes through and $Q$ is the number of requests will come. The $i$-th line of the following $Q$ lines consists of three integers $a_i, b_i,$ and $p_i$ ($1 \leq a_i < b_i \leq N, 1 \leq p_i \leq 10^9$), which mean that the $i$-th request requires $p_i$ products to be delivered from position $a_i$ to position $b_i$. </p> <H2>Output</H2> <p> In the $i$-th line, print the minimum time to complete all the tasks required by requests $1$ to $i$. </p> <H2>Sample Input 1</H2> <pre> 5 2 1 4 1 2 3 1 </pre> <H2>Output for Sample Input 1</H2> <pre> 4 4 </pre> <H2>Sample Input 2</H2> <pre> 5 2 1 4 1 2 3 5 </pre> <H2>Output for Sample Input 2</H2> <pre> 4 8 </pre> <H2>Sample Input 3</H2> <pre> 5 2 1 3 3 3 5 1 </pre> <H2>Output for Sample Input 3</H2> <pre> 5 6 </pre> <H2>Sample Input 4</H2> <pre> 10 4 3 5 2 5 7 5 8 9 2 1 7 5 </pre> <H2>Output for Sample Input 4</H2> <pre> 6 11 11 16 </pre> <p> Regarding the first example, the minimum time to complete only the first request is 4 seconds. All the two requests can be completed within 4 seconds too. See the below figure. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2017_conveyorBelt" width="640"> </center>
p02649
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are <var>N</var> pairwise distinct non-negative integers <var>A_1,A_2,\ldots,A_N</var>. Find the number of ways to choose a set of between <var>1</var> and <var>K</var> numbers (inclusive) from the given numbers so that the following two conditions are satisfied:</p> <ul> <li>The bitwise AND of the chosen numbers is <var>S</var>.</li> <li>The bitwise OR of the chosen numbers is <var>T</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>0 \leq A_i &lt; 2^{18}</var></li> <li><var>0 \leq S &lt; 2^{18}</var></li> <li><var>0 \leq T &lt; 2^{18}</var></li> <li><var>A_i \neq A_j</var> (<var>1 \leq i &lt; j \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>S</var> <var>T</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 answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 0 3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The conditions are satisfied when we choose <var>\{1,2\}</var> or <var>\{1,2,3\}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 1 7 3 4 9 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 4 0 15 3 4 9 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p00674
<h1>Problem F: Strawberry Cake</h1> <p> 会津大学附属小学校 (会津大小) に入学したシャ、ネロ、エリ、コーは競技プログラマとして活躍するために IPPC というプログラミングコンテストに出場することにした。しかし IPPC は 3 人 1 組でチームとしてコンテストに出場する決まりで、4 人でチームを組むことはできない。そこで彼らは 2 人ずつに分かれてチームを組み、2 人 1 組で参加できる IPOCH というプログラミングコンテストに出場することにした。 </p> <p> チームは分かれてしまったが、実力は拮抗しており互いに良い練習相手になっている。 </p> <p> ある日彼らのコーチが差し入れにホールケーキを買ってきた。彼らはそれをシャの家で食べることにした。しかし家に着いて箱を開けてみるとケーキが変形していて、形は上から見ると円形ではなく凸多角形のようになっていた。ネロに運ばせたのが悪かったようだ。 ケーキの上にはイチゴが 1 つ乗っている。とりあえず 2 チームで分けるために、いまこのケーキをイチゴを通る直線にそって半分になるようにナイフで切ることが決定した。ケーキを切る前にイチゴを先にとってしまうのは彼らの美意識に反する。 </p> <p> あなたの仕事は 2 次元平面上に与えられる凸多角形 K を原点 (0, 0) を通る直線 L で分割したとき、分割で出来た 2 つの凸多角形の面積が等しくなるように直線 L を定めることである。もし複数あるならいずれかひとつで構わない。<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_1089"> </p> <h2>Input</h2> <p> 入力は複数のテストケースからなる。各テストケースは以下の形式に従う。 </p> <pre> N x<sub>1</sub> y<sub>1</sub> x<sub>2</sub> y<sub>2</sub> ... x<sub>N</sub> y<sub>N</sub> </pre> <p> N は与えられる凸多角形 K の頂点数である。点 (x<sub>i</sub>, y<sub>i</sub>) ( 1 &le; i &le; N ) はすべて凸多角形 K を成す頂点の座標であり、互いに異なる。これらは反時計回りの順で与えられる。また、凸多角形 K のどの辺上の点も原点との距離が 1 以上で、凸多角形 K は常に原点を内包する。入力の終了はひとつの0を含む1行で示される。原点を含む、入力で与えられる異なる 3 点は共線となりうることに注意して欲しい。 </p> <h2>Constraints</h2> <ul> <li>入力はすべて整数</li> <li>3 &le; N &le; 20</li> <li>-100 &le; x<sub>i</sub> &le; 100 ( 1 &le; i &le; N )</li> <li>-100 &le; y<sub>i</sub> &le; 100 ( 1 &le; i &le; N )</li> <li>テストケースの数は 1,000 を超えない。</li> </ul> <h2>Output</h2> <p> 以下の形式で直線 L 上の点 A (A<sub>x</sub>, A<sub>y</sub>) を出力せよ。ただし点 A と原点との距離は 1 以上でなければならない。 </p> <pre> A<sub>x</sub> A<sub>y</sub> </pre> <p> 原点とこの点 A を通る直線で凸多角形 K を分割したとき 2 つの凸多角形の面積の差が 10<sup>-5</sup> 未満でなければならない。点 A の座標は小数点以下 15 桁出力して欲しい。 </p> <h2>Sample Input</h2> <pre> 4 -100 -100 100 -100 100 100 -100 100 4 -99 -100 100 -100 100 100 -99 100 4 -100 -99 100 -99 100 100 -100 100 14 -99 -70 -92 -79 10 -98 37 -100 62 -95 77 -69 88 -47 92 -10 96 28 100 91 42 92 -62 92 -88 91 -98 64 0 </pre> <h2>Sample Output</h2> <pre> 100.000000000000000 0.000000000000000 100.000000000000000 0.000000000000000 0.000000000000000 100.000000000000000 -96.983291994836122 66.745111613942484 </pre>
p02219
<span class="lang"> <span class="lang-ja"> <h1>H: 魔法使いの塔</h1> <div class="part"> <section> <h3>問題文</h3><p>あなたが持っている魔導書には、 $N$ 個の魔法が載っています。</p> <p>魔法には $1$ から $N$ までの番号がついていて、魔法 $i (1 \le i \le N)$ のコストははじめ整数 $A_i$ です。</p> <p>あなたの目的は、魔導書に載っているすべての魔法を $1$ 回ずつ唱えることです。</p> <p>魔法を唱えはじめる前に、あなたはクッキーを $K$ 枚食べることができます。クッキーを食べるのに時間はかかりません。</p> <p>あなたはクッキーを $1$ 枚食べるたびに、コストが正の魔法を $1$ つ選び、そのコストを $1$ 下げることができます。</p> <p>クッキーを食べたあと、あなたは魔法を唱え始めます。</p> <p>あなたの MP ははじめ $M$ です。あなたは以下のどちらかを繰り返して、 $N$ 個の魔法を任意の順番で $1$ 回ずつ唱えます。</p> <ul> <li>整数 $i (1 \le i \le N)$ を $1$ つ選び、魔法 $i$ を唱える。ただし、 現在の MP は魔法 $i$ のコスト以上でなければならない。<ul> <li>時間は経過しない。</li> <li>MP を魔法 $i$ のコストだけ消費する。</li> </ul> </li> <li>休憩する。ただし、現在の MP を $m$ とすると、 $m &lt; M$ でなければならない。 <ul> <li>時間が $M - m$ 経過する。</li> <li>MP を $1$ 回復する。</li> </ul> </li> </ul> <p>あなたが $N$ 個の魔法を任意の順番で $1$ 回ずつ唱えるためにかかる時間の最小値を求めてください。</p> </section> </div> <div class="part"> <section> <h3>制約</h3><ul> <li>$1 \leq N \leq 10^5$</li> <li>$1 \leq M \leq 10^6$</li> <li>$0 \leq K \leq \sum_{i=1}^{N} A_i$</li> <li>$1 \leq A_i \leq M$</li> <li>入力はすべて整数である。</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以下の形式で標準入力から与えられる。</p> <pre>$N$ $M$ $K$ $A_1$ $A_2$ $\ldots$ $A_N$ </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>$N$ 個の魔法を $1$ 回ずつ唱えるためにかかる時間の最小値を出力せよ。</p> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力例1</h3><pre>2 4 0 2 4 </pre> </section> </div> <div class="part"> <section> <h3>出力例1</h3><pre>3 </pre> <p>どの魔法のコストも減らすことができないので、このまま魔法を唱えていくことにします。</p> <ul> <li>まず、魔法 $1$ を唱えます。 MP を $2$ 消費するので、残りの MP は $4 - 2 = 2$ になります。</li> </ul> <p>魔法 $2$ を唱えるには MP が $4$ 必要なので、このままでは魔法 $2$ を唱えることはできません。</p> <ul> <li>休憩します。時間が $4 - 2 = 2$ 秒経過します。 MP を $1$ 回復するので、残りの MP は $2 + 1 = 3$ になります。</li> <li>休憩します。時間が $4 - 3 = 1$ 秒経過します。 MP を $1$ 回復するので、残りの MP は $3 + 1 = 4$ になります。</li> <li>魔法 $2$ を唱えます。 MP を $4$ 消費するので、残りの MP は $4 - 4 = 0$ になります。</li> </ul> <p>以上より、時間を $2 + 1 = 3$ 秒かければ、魔法 $1,2$ を $1$ 回ずつ唱えることができます。 これより短い時間ですべての魔法を唱えることはできないので、求める答えは $3$ となります。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力例2</h3><pre>3 9 6 2 3 9 </pre> </section> </div> <div class="part"> <section> <h3>出力例2</h3><pre>0 </pre> <p>最終的な魔法のコストを $2, 2, 4$ とすると、休憩することなくすべての魔法を唱えることができます。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力例3</h3><pre>3 16 2 6 9 9 </pre> </section> </div> <div class="part"> <section> <h3>出力例3</h3><pre>21 </pre> </section> </div> <hr /> <div class="part"> <section> <h3>入力例4</h3><pre>2 1000000 0 1000000 1000000 </pre> </section> </div> <div class="part"> <section> <h3>出力例4</h3><pre>500000500000 </pre> <p>答えは 32bit 整数で表せる範囲に収まらないことがあります。</p></section> </div> </span> </span>
p00224
<H1>自転車でダイエット</H1> <p> A さんは甘いものが大好きですが、最近は奥さんからダイエットするように言われています。ある日、A さんが自宅から市役所に出かけるとき、奥さんは自転車で行くことを勧めました。そこでA さんはしぶしぶ自転車に乗って出かけましたが、甘い物の好きな A さんは、途中にあるケーキ屋さんに立ち寄りケーキの食べ歩きをしようと思いつきました。 </p> <p> 自転車をこげば走行距離に応じてカロリーが消費されますが、ケーキを食べればその分カロリーが摂取されます。正味の消費カロリーは、自転車をこいで消費したカロリーからケーキを食べて摂取したカロリーを引いた値になります。したがって、正味の消費カロリーが 0 より小さくなることもあります。 </p> <p> ケーキ屋さんでケーキを買ったら、 Aさんはその場でケーキを全部食べてしまいます。 Aさんがすべてのケーキ屋さんに立ち寄るとは限りませんが、ケーキ屋さんが存在する地点を通るときには、必ず立ち寄ってケーキを 1 つ買って食べるものとします。ただし、同じケーキ屋さんの前を何度も通るのはさすがに気がひけるので、各ケーキ屋さんに訪れられるのは 1 回だけとします。また、目的地の市役所をいったん通り過ぎてからケーキ屋さんに立ち寄り、その後で市役所に戻って用を済ませてもよいものとし、ケーキ屋さん以外は何度訪れても良いものとします。 </p> <p> A さんの自宅から市役所までの地図情報と、その途中にあるケーキ屋さんで食べられるケーキのカロリーの一覧、単位距離の走行による消費カロリーを入力とし、自宅を出発してから市役所に入るまでの正味の消費カロリーの最小値を出力するプログラムを作成してください。 </p> <p> 地図には、A さんの自宅と市役所、ケーキ屋さんとランドマーク(目印)になる建物が書かれています。地図を表す入力データは、A さんの自宅、市役所、ケーキ屋さんとランドマークの各地点の間をつなぐ道があるとき、2 つの地点を表す記号とその間の距離からなる行を含みます。たとえば、5 番目のケーキ屋さんと 3 番目のランドマークの間の距離が 10 なら、入力データは以下のような行を含みます。 </p> <pre> C5 L3 10 </pre> <p> このようにケーキ屋さんには C、ランドマークには L を番号の前につけて表します。また、A さんの自宅は H、市役所は D で表します。入力データに 2 つの地点とその間の距離が与えられているなら、2 地点の間をどちら向きにも進めます。たとえば、上の例ではケーキ屋さんからランドマークへも、その逆向きへも進むことができます。また、自宅から市役所までは必ずたどり着けるものとします。それ以外に与えられる入力データは、ケーキ屋さんの数 <var>m</var>、ランドマークの数 <var>n</var>、単位距離あたりの消費カロリー <var>k</var>、 1 番目のケーキ屋さんから <var>m</var> 番目のケーキ屋さんまでのそれぞれで買えるケーキのカロリーを表す <var>m</var> 個のデータ、距離のデータの総数 <var>d</var> です。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりは四つの 0 の行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>m</var> <var>n</var> <var>k</var> <var>d</var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>m</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>e<sub>1</sub></var> <var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>e<sub>2</sub></var> : <var>s<sub>d</sub></var> <var>t<sub>d</sub></var> <var>e<sub>d</sub></var> </pre> <p> 1 行目にケーキ屋さんの数 <var>m</var> (1 &le; <var>m</var> &le; 6)、 ランドマークの数 <var>n</var> (1 &le; <var>n</var> &le; 100) 、単位距離あたりの消費カロリー <var>k</var> (1 &le; <var>k</var> &le; 5)、距離のデータの総数 <var>d</var> (5 &le; <var>d</var> &le; 256) が与えられます。 </p> <p> 2 行目に各ケーキ屋で買うケーキのカロリー <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; 100) が与えられます。 </p> <p> 続く <var>d</var> 行に <var>i</var> 番目の 2 つの地点間の距離データ <var>s<sub>i</sub></var>, <var>t<sub>i</sub></var>, <var>e<sub>i</sub></var> (1 &le; <var>e<sub>i</sub></var> &le; 20) が与えられます。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> 入力データセットごとに、全体の消費カロリーの最小値を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 1 1 2 5 35 H L1 5 C1 D 6 C1 H 12 L1 D 10 C1 L1 20 2 1 4 6 100 70 H L1 5 C1 L1 12 C1 D 11 C2 L1 7 C2 D 15 L1 D 8 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 -2 </pre>
p01823
<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 F: Marching Course </h2> <p> Since members of Kitafuji High School Brass Band Club succeeded in convincing their stern coach of their playing skills, they will be able to participate in Moon Light Festival as a marching band. This festival is a prelude in terms of appealing their presence for the coming domestic contest. Hence, they want to attract a festival audience by their performance. </p> <p> Although this festival restricts performance time up to $P$ minutes, each team can freely determine their performance course from a provided area. The provided area consists of $N$ checkpoints, numbered 1 through $N$, and $M$ bidirectional roads connecting two checkpoints. Kitafuji Brass Band already has the information about each road: its length and the expected number of people on its roadside. Each team must start at the checkpoint 1, and return back to the checkpoint 1 in $P$ minutes. In order to show the performance ability of Kitafuji Brass Band to a festival audience, their stern coach would like to determine their performance course so that many people listen their march as long as possible. </p> <p> The coach uses "impression degree" to determine their best course. If they play $m$ minutes on the road with length $d$ and the expected number $v$ of people, then the impression degree will be $m \times v/d$. The impression degree of a course is the sum of impression degree of their performance on the course. Marching bands must move at a constant speed during marching: 1 unit length per 1 minute. On the other hand, they can turn in the opposite direction at any time, any place including a point on a road. The impression degree is accumulated even if they pass the same interval two or more times. </p> <p> Your task is to write a program to determine a course with the maximum impression degree in order to show the performance ability of Kitafuji Brass Band to an audience as much as possible. </p> <h3>Input</h3> <p> The input is formatted as follows.<br> <br> $N$ $M$ $P$<br> $s_1$ $t_1$ $d_1$ $v_1$<br> : : :<br> $s_M$ $t_M$ $d_M$ $v_M$<br> <br> </p> <p> The first line contains three integers $N$, $M$, and $P$: the number of checkpoints $N$ ($2 \leq N \leq 200$), the number of roads $M$ ($N - 1 \leq M \leq N(N - 1)/2$), and the performance time $P$ ($1 \leq P \leq 1,000$). The following $M$ lines represent the information about roads. The $i$-th line of them contains four integers $s_i$, $t_i$, $d_i$, and $v_i$: the $i$-th road bidirectionally connects between checkpoints $s_i$ and $t_i$ ($1 \leq s_i, t_i \leq N, s_i \ne t_i$) with length $d_i$ ($1 \leq d_i \leq 1,000$) and the expected number $v_i$ ($1 \leq v_i \leq 1,000$) of people. </p> <p> You can assume that any two checkpoints are directly or indirectly connected with one or more roads. You can also assume that there are no pair of roads having the same pair of endpoints. </p> <h3>Output</h3> <p> Output the maximum impression degree of a course for a $P$-minute performance. The absolute error should be less than $10^{-4}$. </p> <h3>Sample Input</h3> <pre> 3 3 4 1 2 1 1 2 3 2 4 3 1 1 1 </pre> <h3>Output for the Sample Input</h3> <pre> 6 </pre> <h3>Sample Input</h3> <pre> 4 3 9 1 2 2 1 1 3 2 2 1 4 2 3 </pre> <h3>Output for the Sample Input</h3> <pre> 13.5 </pre> <h3>Sample Input</h3> <pre> 4 3 5 1 2 10 1 2 3 2 100 1 4 3 10 </pre> <h3>Output for the Sample Input</h3> <pre> 16.6666666667 </pre> <h3>Sample Input</h3> <pre> 3 3 10 1 2 3 1 1 3 4 5 2 3 2 10 </pre> <h3>Output for the Sample Input</h3> <pre> 22 </pre>