question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p03466
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>f(A, B)</var>, where <var>A</var> and <var>B</var> are positive integers, be the string satisfying the following conditions:</p> <ul> <li><var>f(A, B)</var> has length <var>A + B</var>;</li> <li><var>f(A, B)</var> contains exactly <var>A</var> letters <code>A</code> and exactly <var>B</var> letters <code>B</code>;</li> <li>The length of the longest substring of <var>f(A, B)</var> consisting of equal letters (ex., <code>AAAAA</code> or <code>BBBB</code>) is as small as possible under the conditions above;</li> <li><var>f(A, B)</var> is the lexicographically smallest string satisfying the conditions above.</li> </ul> <p>For example, <var>f(2, 3)</var> = <code>BABAB</code>, and <var>f(6, 4)</var> = <code>AABAABAABB</code>.</p> <p>Answer <var>Q</var> queries: find the substring of <var>f(A_i, B_i)</var> from position <var>C_i</var> to position <var>D_i</var> (1-based).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq Q \leq 10^3</var></li> <li><var>1 \leq A_i, B_i \leq 5 \times 10^8</var></li> <li><var>1 \leq C_i \leq D_i \leq A_i + B_i</var></li> <li><var>D_i - C_i + 1 \leq 100</var></li> <li>All input values are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>500</var> points will be awarded for passing the testset satisfying <var>1 \leq A_i, B_i \leq 10^3</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>Q</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>D_1</var> <var>A_2</var> <var>B_2</var> <var>C_2</var> <var>D_2</var> <var>:</var> <var>A_Q</var> <var>B_Q</var> <var>C_Q</var> <var>D_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query <var>i</var> in order of input, print a line containing the substring of <var>f(A_i, B_i)</var> from position <var>C_i</var> to position <var>D_i</var> (1-based).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 3 1 5 6 4 1 10 2 3 4 4 6 4 3 7 8 10 5 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>BABAB AABAABAABB A BAABA ABAB </pre></section> </div> </span>
p03036
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The development of algae in a pond is as follows.</p> <p>Let the total weight of the algae at the beginning of the year <var>i</var> be <var>x_i</var> gram. For <var>i≥2000</var>, the following formula holds:</p> <ul> <li><var>x_{i+1} = rx_i - D</var></li> </ul> <p>You are given <var>r</var>, <var>D</var> and <var>x_{2000}</var>. Calculate <var>x_{2001}</var>, <var>...</var>, <var>x_{2010}</var> and print them in order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≤ r ≤ 5</var></li> <li><var>1 ≤ D ≤ 100</var></li> <li><var>D &lt; x_{2000} ≤ 200</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>r</var> <var>D</var> <var>x_{2000}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>10</var> lines. The <var>i</var>-th line (<var>1 ≤ i ≤ 10</var>) should contain <var>x_{2000+i}</var> as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 10 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>30 50 90 170 330 650 1290 2570 5130 10250 </pre> <p>For example, <var>x_{2001} = rx_{2000} - D = 2 \times 20 - 10 = 30</var> and <var>x_{2002} = rx_{2001} - D = 2 \times 30 - 10 = 50</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 40 60 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>200 760 3000 11960 47800 191160 764600 3058360 12233400 48933560 </pre></section> </div> </span>
p02277
<H1>Quick Sort</H1> <!-- <p style="color:#f00"> Please note that problem description and judge data for this problem are still under construction. They may revised and your submissions can be rejudged. </p> --> <p> Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: </p> <pre> Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) </pre> <p> Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. </p> <p> Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance). </p> <H2>Input</H2> <p> The first line contains an integer <i>n</i>, the number of cards. </p> <p> <i>n</i> cards are given in the following lines. Each card is given in a line and represented by a pair of a character and an integer separated by a single space. </p> <H2>Output</H2> <p> In the first line, print the stability ("<span>Stable</span>" or "<span>Not stable</span>") of this output. </p> <p> In the following lines, print the arranged cards in the same manner of that of the input. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>n</i> &le; 100,000</li> <li>1 &le; the number of a card &le; 10<sup>9</sup></li> <li>There are no identical card in the input</li> </ul> <H2>Sample Input 1</H2> <pre> 6 D 3 H 2 D 1 S 3 D 2 C 1 </pre> <H2>Sample Output 1</H2> <pre> Not stable D 1 C 1 D 2 H 2 D 3 S 3 </pre> <H2>Sample Input 2</H2> <pre> 2 S 1 H 1 </pre> <H2>Sample Output 2</H2> <pre> Stable S 1 H 1 </pre>
p03935
<span class="lang-en lang-child hidden-lang"> <div class="part"> Max Score: $1400$ Points <br/> <section> <h3>Problem Statement</h3> E869120 defined a sequence $a$ like this: <br/> <ul> <li>$a_1=a_2=1$, $a_{k+2}=a_{k+1}+a_k \ (k \ge 1)$</li> </ul> <br/> He also defined sequences $d_1, d_2, d_3, \dots , d_n$, as the following recurrence relation : <br/> <ul> <li>$d_{1, j} = a_j$</li> <li>$d_{i, j} = \sum_{k = 1}^j d_{i - 1, k} \ (i \ge 2)$</li> </ul> <br/> You are given integers $n$ and $m$. Please calculate the value of $d_{n, m}$. <br/> Since the answer can be large number, print the answer modulo $998,244,353$. <br/> Can you solve this problem??? <br/> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> The input is given from standard input in the following format. <br/> <br/> <blockquote>$n \quad m$ </blockquote> </section> </div> <div class="part"> <section> <h3>Output</h3> <ul> <li>Print $d_{n, m}$ modulo $998,244,353$.</li> </ul> </section> <section> <h3>Constraints</h3> <ul> <li>$1 \le n \le 200,000$</li> <li>$1 \le m \le 10^{18}$</li> </ul> </section> <section> <h3>Subtasks</h3> Subtask 1 [ $100$ points ] <br/> <ul> <li>The testcase in this subtask satisfies $1 \le n, m \le 3,000$.</li> </ul> Subtask 2 [ $170$ points ] <br/> <ul> <li>The testcase in this subtask satisfies $1 \le m \le 200,000$.</li> </ul> Subtask 3 [ $230$ points ] <br/> <ul> <li>The testcase in this subtask satisfies $1 \le n \le 3$.</li> </ul> Subtask 4 [ $420$ points ] <br/> <ul> <li>The testcase in this subtask satisfies $1 \le n \le 1000$.</li> </ul> Subtask 5 [ $480$ points ] <br/> <ul> <li>There are no additional constraints.</li> </ul> <br/> </section> </div> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 4 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 176 </pre> The sequence is following:<br/> <table class="table-striped table-bordered table-condensed"> <tr align="center"> <th></th> <td width="75">$d_{i, 1}$</td> <td width="75">$d_{i, 2}$</td> <td width="75">$d_{i, 3}$</td> <td width="75">$d_{i, 4}$</td> <td width="75">$d_{i, 5}$</td> <td width="75">$d_{i, 6}$</td> <td width="75">$d_{i, 7}$</td> </tr> <tr align="center"> <th>$d_1$</th> <td>1</td> <td>1</td> <td>2</td> <td>3</td> <td>5</td> <td>8</td> <td>13</td> </tr> <tr align="center"> <th>$d_2$</th> <td>1</td> <td>2</td> <td>4</td> <td>7</td> <td>12</td> <td>20</td> <td>33</td> </tr> <tr align="center"> <th>$d_3$</th> <td>1</td> <td>3</td> <td>7</td> <td>14</td> <td>26</td> <td>46</td> <td>79</td> </tr> <tr align="center"> <th>$d_4$</th> <td>1</td> <td>4</td> <td>11</td> <td>25</td> <td>51</td> <td>97</td> <td>176</td> </tr> </table> <br/> As a result, the answer is $d_{4, 7} = 176$. <br/> </section> </div> <br/> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 12 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 174174144 </pre> </section> Interesting number. It only contains $1$, $4$ and $7$. <br/> </div> <br/> <div class="part"> <section> <h3>Sample Input 3</h3> <pre> 16 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3> <pre> 102292850 </pre> You can calculate that $d_{16, 30} = 1,193,004,294,685$.<br/> Please don't forget printing the answer mod $998,244,353$. </section> </div> <div class="part"> <section> Writer:square1001 </section> </div> </span>
p01908
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>D: パスワード</h1> <h2>問題</h2> <p> AOR イカちゃんは英小文字のみからなる強力なパスワードを作りたいと思っています。 友達から $N$ 個の危険なパスワードの例を教えてもらった AOR イカちゃんは、 以下の条件を全て満たすようなパスワードを作ることにしました。 </p> <ol> <li>長さは1文字以上である。</li> <li>どの危険なパスワードの、どの連続した部分文字列とも異なる。</li> <li>1, 2 の条件を満たした中で、最も短い文字列である。</li> <li>1,2,3の条件を満たした中で、辞書順に並べたとき先頭に来る文字列である。</li> </ol> <p> AOR イカちゃんに代わって強力なパスワードを生成するプログラムを書いてください。 </p> <h2>入力</h2> <p> 入力は以下の形式で標準入力から与えられる。 </p> <p> $N$<br> $S_1$<br> $\vdots$<br> $S_N$ </p> <ul> <li>1 行目には、文字列の数を表す整数 $N$ が与えられる。</li> <li>2 行目からの $N$ 行には、文字列 $S_i$ が与えられる。</li> <li>$|S_i|$ とは文字列の長さであり、1 文字以上である。</li> <li>$1 \le N \le 100,000$ を満たす。</li> <li>$1 \le \sum_{1\le i \le N} |S_i| \le 400,000$ を満たす。</li> <li>文字列は英小文字のみを含む。</li> </ul> <h2>出力</h2> <p> 答えを 1 行で出力せよ。また、末尾に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 5 password login admin root master </pre> <h3>サンプル出力 1</h3> <pre> b </pre> <h3>サンプル入力 2</h3> <pre> 3 abcdefghijklmnopqrstuvwxy qwertyuiopasdfghjklxcvbnm qawsxedcrfvtgbyhnujmikolp </pre> <h3>サンプル出力 2</h3> <pre> z </pre> <h3>サンプル入力 3</h3> <pre> 1 abcdefghijklmnopqrstuvwxyz </pre> <h3>サンプル出力 3</h3> <pre> aa </pre>
p02627
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>An uppercase or lowercase English letter <var>\alpha</var> will be given as input. If <var>\alpha</var> is uppercase, print <code>A</code>; if it is lowercase, print <code>a</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>\alpha</var> is an uppercase (<code>A</code> - <code>Z</code>) or lowercase (<code>a</code> - <code>z</code>) English letter.</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>α</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>\alpha</var> is uppercase, print <code>A</code>; if it is lowercase, print <code>a</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>B </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>A </pre> <p><code>B</code> is uppercase, so we should print <code>A</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>a </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>a </pre> <p><code>a</code> is lowercase, so we should print <code>a</code>.</p></section> </div> </span>
p02332
<!--<h1>写像12相 その2:ボールに区別あり・箱に区別あり・箱の中身は1つ以下</h1>--> <h1>Balls and Boxes 2</h1> <table border=""> <tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr> <tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td style="background-color:#aff">2</td><td>3</td></tr> <tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr> <tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr> <tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr> </table> <h2>Problem</h2> <p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p> <p>Find the number of ways to put the balls under the following conditions:</p> <ul> <li>Each ball is distinguished from the other.</li> <li>Each box is distinguished from the other.</li> <li>Each ball can go into only one box and no one remains outside of the boxes.</li> <li>Each box can contain at most one ball.</li> </ul> <p>Note that you must print this count modulo $10^9+7$.</p> <h2>Input</h2> <pre> $n$ $k$ </pre> <p>The first line will contain two integers $n$ and $k$.</p> <h2>Output</h2> <p>Print the number of ways modulo $10^9+7$ in a line.</p> <h2>Constraints</h2> <ul> <li>$1 \le n \le 1000$</li> <li>$1 \le k \le 1000$</li> </ul> <h2>Sample Input 1</h2> <pre> 2 3 </pre> <h2>Sample Output 1</h2> <pre> 6 </pre> <h2>Sample Input 2</h2> <pre> 3 2 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre> <h2>Sample Input 3</h2> <pre> 100 100 </pre> <h2>Sample Output 3</h2> <pre> 437918130 </pre>
p02298
<H1>Is-Convex</H1> <br/> <p> For a given polygon <var>g</var>, print "1" if <var>g</var> is a convex polygon, "0" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees. </p> <p> <var>g</var> is represented by a sequence of points <var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>,..., <var>p<sub>n</sub></var> where line segments connecting <var>p<sub>i</sub></var> and <var>p<sub>i+1</sub></var> (1 &le; <var>i</var> &le; <var>n-1</var>) are sides of the polygon. The line segment connecting <var>p<sub>n</sub></var> and <var>p<sub>1</sub></var> is also a side of the polygon. </p> <H2>Input</H2> <p> <var>g</var> is given by coordinates of the points <var>p<sub>1</sub></var>,..., <var>p<sub>n</sub></var> in the following format: </p> <pre> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <p> The first integer <var>n</var> is the number of points. The coordinate of a point <var>p<sub>i</sub></var> is given by two integers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. The coordinates of points are given in the order of counter-clockwise visit of them. </p> <H2>Output</H2> <p> Print "1" or "0" in a line. </p> <H2>Constraints</H2> <ul> <li> 3 &le; <var>n</var> &le; 100 </li> <li> -10000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 10000 </li> <li>No point of the polygon will occur more than once.</li> <li>Two sides of the polygon can intersect only at a common endpoint.</li> </ul> <H2>Sample Input 1</H2> <pre> 4 0 0 3 1 2 3 0 3 </pre> <H2>Sample Output 1</H2> <pre> 1 </pre> <br/> <H2>Sample Input 2</H2> <pre> 5 0 0 2 0 1 1 2 2 0 2 </pre> <H2>Sample Output 2</H2> <pre> 0 </pre>
p03870
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>A cheetah and a cheater are going to play the game of Nim. In this game they use <var>N</var> piles of stones. Initially the <var>i</var>-th pile contains <var>a_i</var> stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses.</p> <p>However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats.</p> <p>Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print <code>-1</code> instead.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 10^5</var></li> <li><var>2 ≤ a_i ≤ 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</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 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The only way for the cheater to win the game is to take stones from all piles and eat them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 100 100 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre></section> </div> </span>
p02762
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>An SNS has <var>N</var> users - User <var>1</var>, User <var>2</var>, <var>\cdots</var>, User <var>N</var>.</p> <p>Between these <var>N</var> users, there are some relationships - <var>M</var> <em>friendships</em> and <var>K</var> <em>blockships</em>.</p> <p>For each <var>i = 1, 2, \cdots, M</var>, there is a bidirectional friendship between User <var>A_i</var> and User <var>B_i</var>.</p> <p>For each <var>i = 1, 2, \cdots, K</var>, there is a bidirectional blockship between User <var>C_i</var> and User <var>D_i</var>.</p> <p>We define User <var>a</var> to be a <em>friend candidate</em> for User <var>b</var> when all of the following four conditions are satisfied:</p> <ul> <li><var>a \neq b</var>.</li> <li>There is not a friendship between User <var>a</var> and User <var>b</var>.</li> <li>There is not a blockship between User <var>a</var> and User <var>b</var>.</li> <li>There exists a sequence <var>c_0, c_1, c_2, \cdots, c_L</var> consisting of integers between <var>1</var> and <var>N</var> (inclusive) such that <var>c_0 = a</var>, <var>c_L = b</var>, and there is a friendship between User <var>c_i</var> and <var>c_{i+1}</var> for each <var>i = 0, 1, \cdots, L - 1</var>.</li> </ul> <p>For each user <var>i = 1, 2, ... N</var>, how many friend candidates does it have?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>2 ≤ N ≤ 10^5</var></li> <li><var>0 \leq M \leq 10^5</var></li> <li><var>0 \leq K \leq 10^5</var></li> <li><var>1 \leq A_i, B_i \leq N</var></li> <li><var>A_i \neq B_i</var></li> <li><var>1 \leq C_i, D_i \leq N</var></li> <li><var>C_i \neq D_i</var></li> <li><var>(A_i, B_i) \neq (A_j, B_j) (i \neq j)</var></li> <li><var>(A_i, B_i) \neq (B_j, A_j)</var></li> <li><var>(C_i, D_i) \neq (C_j, D_j) (i \neq j)</var></li> <li><var>(C_i, D_i) \neq (D_j, C_j)</var></li> <li><var>(A_i, B_i) \neq (C_j, D_j)</var></li> <li><var>(A_i, B_i) \neq (D_j, C_j)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K</var> <var>A_1</var> <var>B_1</var> <var>\vdots</var> <var>A_M</var> <var>B_M</var> <var>C_1</var> <var>D_1</var> <var>\vdots</var> <var>C_K</var> <var>D_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answers in order, with space in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 1 2 1 1 3 3 2 3 4 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 1 0 1 </pre> <p>There is a friendship between User <var>2</var> and <var>3</var>, and between <var>3</var> and <var>4</var>. Also, there is no friendship or blockship between User <var>2</var> and <var>4</var>. Thus, User <var>4</var> is a friend candidate for User <var>2</var>.</p> <p>However, neither User <var>1</var> or <var>3</var> is a friend candidate for User <var>2</var>, so User <var>2</var> has one friend candidate.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 10 0 1 2 1 3 1 4 1 5 3 2 2 4 2 5 4 3 5 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 0 0 0 0 </pre> <p>Everyone is a friend of everyone else and has no friend candidate.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 9 3 10 1 6 7 8 2 2 5 8 4 7 3 10 9 6 4 5 8 2 6 7 5 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 3 5 4 3 3 3 3 1 0 </pre></section> </div> </span>
p03523
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var>.</p> <p>Takahashi can insert the character <code>A</code> at any position in this string any number of times.</p> <p>Can he change <var>S</var> into <code>AKIHABARA</code>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 50</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>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to change <var>S</var> into <code>AKIHABARA</code>, print <code>YES</code>; otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>KIHBR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>Insert one <code>A</code> at each of the four positions: the beginning, immediately after <code>H</code>, immediately after <code>B</code> and the end.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>AKIBAHARA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p>The correct spell is <code>AKIHABARA</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>AAKIAHBAARA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre></section> </div> </span>
p03489
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a sequence of positive integers of length <var>N</var>, <var>a = (a_1, a_2, ..., a_N)</var>. Your objective is to remove some of the elements in <var>a</var> so that <var>a</var> will be a <strong>good sequence</strong>.</p> <p>Here, an sequence <var>b</var> is a <strong>good sequence</strong> when the following condition holds true:</p> <ul> <li>For each element <var>x</var> in <var>b</var>, the value <var>x</var> occurs exactly <var>x</var> times in <var>b</var>.</li> </ul> <p>For example, <var>(3, 3, 3)</var>, <var>(4, 2, 4, 1, 4, 2, 4)</var> and <var>()</var> (an empty sequence) are good sequences, while <var>(3, 3, 3, 3)</var> and <var>(2, 4, 1, 4, 2)</var> are not.</p> <p>Find the minimum number of elements that needs to be removed so that <var>a</var> will be a good sequence.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>a_i</var> is an integer.</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 number of elements that needs to be removed so that <var>a</var> will be a good sequence.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>We can, for example, remove one occurrence of <var>3</var>. Then, <var>(3, 3, 3)</var> is a good sequence.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 4 1 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>We can, for example, remove two occurrences of <var>4</var>. Then, <var>(2, 1, 2)</var> is a good sequence.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 2 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre> <p>Remove one occurrence of <var>10^9</var>. Then, <var>()</var> is a good sequence.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>8 2 7 1 8 2 8 1 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>5 </pre></section> </div> </span>
p03173
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> slimes lining up in a row. Initially, the <var>i</var>-th slime from the left has a size of <var>a_i</var>.</p> <p>Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime:</p> <ul> <li>Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of <var>x + y</var>, where <var>x</var> and <var>y</var> are the sizes of the slimes before combining them. Here, a cost of <var>x + y</var> is incurred. The positional relationship of the slimes does not change while combining slimes.</li> </ul> <p>Find the minimum possible total cost incurred.</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 400</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>\ldots</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible total cost incurred.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 10 20 30 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>190 </pre> <p>Taro should do as follows (slimes being combined are shown in bold):</p> <ul> <li>(<strong>10</strong>, <strong>20</strong>, 30, 40) → (<strong>30</strong>, 30, 40)</li> <li>(<strong>30</strong>, <strong>30</strong>, 40) → (<strong>60</strong>, 40)</li> <li>(<strong>60</strong>, <strong>40</strong>) → (<strong>100</strong>)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 10 10 10 10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>120 </pre> <p>Taro should do, for example, as follows:</p> <ul> <li>(<strong>10</strong>, <strong>10</strong>, 10, 10, 10) → (<strong>20</strong>, 10, 10, 10)</li> <li>(20, <strong>10</strong>, <strong>10</strong>, 10) → (20, <strong>20</strong>, 10)</li> <li>(20, <strong>20</strong>, <strong>10</strong>) → (20, <strong>30</strong>)</li> <li>(<strong>20</strong>, <strong>30</strong>) → (<strong>50</strong>)</li> </ul> </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>5000000000 </pre> <p>The answer may not fit into a 32-bit integer type.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 7 6 8 6 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>68 </pre> <p>Taro should do, for example, as follows:</p> <ul> <li>(7, 6, 8, 6, <strong>1</strong>, <strong>1</strong>) → (7, 6, 8, 6, <strong>2</strong>)</li> <li>(7, 6, 8, <strong>6</strong>, <strong>2</strong>) → (7, 6, 8, <strong>8</strong>)</li> <li>(<strong>7</strong>, <strong>6</strong>, 8, 8) → (<strong>13</strong>, 8, 8)</li> <li>(13, <strong>8</strong>, <strong>8</strong>) → (13, <strong>16</strong>)</li> <li>(<strong>13</strong>, <strong>16</strong>) → (<strong>29</strong>)</li> </ul></section> </div> </span>
p00476
<H1>ダンジョン</H1> <h2>問題</h2> <p> あなたはあるダンジョンの地下 N 階にある財宝を手に入れたいと思っている.最初,あなたは地下 1 階におり,あなたの体力は H(H は正整数) である.下の階に降りるときに,体力が消費される.あらかじめ各階における下の階に降りるときに消費される体力が分かっている.一方,各階には 1 つの回復の泉があり,泉を 1 回使うごとに回復できる体力がそれぞれ定まっている.体力が 0 以下になるとあなたは死んでしまう.また,体力が H よりも高くなることはない.回復の泉は何回でも使うことができるが,回復には時間がかかるので,あなたは泉の使用回数をできるだけ少なくしたいと考えている. </p> <p> N ,H ,各階の下の階に降りるときに消費される体力,そして各階で回復の泉を 1 回使用したときに回復する体力が与えられたとき,体力を 0 以下にすることなく地下 N 階まで到達するために必要な泉の使用回数の最小値を求めるプログラムを作成せよ. </p> <p> また,一度下の階に降りると,財宝を手に入れるまで上の階に戻ることはできない. </p> <h2>入力</h2> <!-- <p> 入力ファイルのファイル名は input.txt である. </p> --> <p> 入力は N 行からなる. 入力の 1 行目には 2 つの整数 N, H(2 &le; N &le; 100000 = 10<sup>5</sup>, 1 &le; H &le; 10000000 = 10<sup>7</sup> ) が空白を区切りとして書かれている.N は地下 N 階に財宝があるということを表し,H は初期体力 ( ダンジョンの地下 1 階に到着した段階の体力 ) であり,かつ体力の最大値である ( 回復によって体力が H より大きくなることはない ) . </p> <p> 続く N − 1 行には,2 つの整数が空白を区切りとして書かれている.1 + i 行目(1 &le; i &le; N − 1) の整数 di , hi について, di は地下 i 階から地下 i + 1 階に降りる際に消費される体力を,hi は地下 i 階で泉を 1 回使用したときに回復する体力を表す(0 &le; di &lt; H, 1 &le; hi &lt; H). </p> <p> どの採点用データにおいても,地下 N 階にたどり着く方法が存在する.採点用データのうち,配点の 10%分については,N &le; 1000 かつ H &le; 1000 を満たす.配点の30%分については,N &le;1000 を満たす.配点の 50%分については,泉の使用回数の最小値が 10<sup>6</sup> を超えない. </p> <h2> 出力</h2> <!-- <p> 出力ファイルのファイル名は output.txt である. </p> --> <p> <!--output.txt-->出力は,体力を 0 以下にすることなく地下 N 階に到達するために必要な,泉の使用回数の最小値を含む 1 行からなる. </p> <h2>注意</h2> <p> この問題では,扱う整数の範囲が 32bit に収まらない可能性があることに注意せよ. </p> <h2> 入出力例</h2> <h3>入力例 1</h3> <pre> 10 10 4 2 2 5 6 1 7 3 6 4 9 6 0 8 4 1 9 4 </pre> <h3>出力例 1</h3> <pre> 10 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p00026
<H1>Dropping Ink</H1> <p> As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (<var>x</var>, <var>y</var>) coordinate system. </p> <p> We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as shown in the figure depending on its size. In the figure, a star denotes the point of fall and a circle denotes the surrounding cells. </p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ink1"></center> <br/> <p> Originally, the paper is white that means for each cell the value of density is 0. The value of density is increased by 1 when the ink sinks into the corresponding cells. For example, if we put a drop of Small ink at (1, 2) and a drop of Medium ink at (3, 2), the ink will sink as shown in the following figure (left side): </p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ink2"></center> <br/> <p> In the figure, density values of empty cells are 0. The ink sinking into out of the paper should be ignored as shown in the figure (top side). We can put several drops of ink at the same point. </p> <p> Your task is to write a program which reads a sequence of points of fall (<var>x</var>, <var>y</var>) with its size (Small = 1, Medium = 2, Large = 3), and prints the number of cells whose density value is 0. The program must also print the maximum value of density. </p> <p> You may assume that the paper always consists of 10 &times; 10, and 0 &le; <var>x</var> &lt; 10, 0 &le; <var>y</var> &lt; 10. </p> <H2>Input</H2> <pre> <var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>s<sub>1</sub></var> <var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>,<var>s<sub>2</sub></var> : : </pre> <p> (<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>) represents the position of the <var>i</var>-th drop and <var>s<sub>i</sub></var> denotes its size. The number of drops is less than or equal to 50. </p> <H2>Output</H2> <p> Print the number of cells whose density value is 0 in first line.<br> Print the maximum value of density in the second line. </p> <H2>Sample Input</H2> <pre> 2,5,3 3,6,1 3,4,2 4,5,2 3,6,3 2,4,1 </pre> <H2>Output for the Sample Input</H2> <pre> 77 5 </pre>
p01267
<h1><font color="#000">Problem A:</font> Luck Manipulator</h1> <p> Nathan O. Davis くんは,あるゲームを攻略中であり,非常にレアなアイテムを手に入れようと四苦八苦していた.このレアなアイテムは,カジノのスロットマシーンで特殊な絵柄を一列に揃えたときに手に入れることができる.スロットマシーンには <i>N</i> 個のリールがあり,ボタンを一回押すと現在回転している最も左側のリールが停止する.そのため,このレアアイテムを手に入れるためには <i>N</i> 回ボタンを押す必要がある.また,特殊な絵柄で停止させるためにはあるタイミングでボタンを押す必要がある.ところが,このボタンを押すタイミングは非常にシビアであるため,なかなか上手くいかずに困っていた.そこで,Nathan くんはメモリビューアを利用して,ゲーム中におけるメモリの値を確認しながらゲームを解析することにした. </p> <p> Nathan くんの解析の結果,その特殊な絵柄でリールを停止させるためには,ボタンが押された時に,メモリの 007E0D1F 番地に書き込まれた「乱数」が特定の値になっている必要があることを突き止めた.乱数の値は 1 フレーム毎に線形合同法によって変化しており,またボタンが押されたかどうかの判定は 1 フレーム毎に 1 回行われていることも分かった.ここで,線形合同法とは擬似乱数を生成するための方法の一つであり,以下の式によって値を決定する. </p> <p> <i>x'</i> = (<i>A</i> &times; <i>x</i> + <i>B</i>) mod <i>C</i> </p> <p> ここで,<i>x</i> は現在の乱数の値,<i>x'</i> は次の乱数の値,<i>A</i>, <i>B</i>, <i>C</i> は何らかの定数である.また,<i>y</i> mod <i>z</i> は <i>y</i> を <i>z</i> で割ったときの余りを表す. </p> <p> 例えば,2 個のリールを持つスロットマシーンで <i>A</i> = 5,<i>B</i> = 7,<i>C</i> = 11 で,最初の「乱数」の値が 10 であったとする.そして,特殊な絵柄でリールを止めるための条件は,左側のリールが 2,右側のリールが 4 であったとする.このとき,1 フレーム目における乱数の値は (5 &times; 10 + 7) mod 11 = 2 であるため,1 フレーム目にボタンを押せば左側のリールは特殊な絵柄で停止する.続く 2 フレーム目での乱数の値は (5 &times; 2 + 7) mod 11 = 6 であるから,2 フレーム目にボタンを押しても右側のリールは特殊な絵柄では停止しない.続く 3 フレーム目では乱数の値が (5 &times; 6 + 7 ) mod 11 = 4 になるので,3 フレーム目にボタンを押せば右側のリールは特殊な絵柄で停止する.よって,最短 3 フレームで全てのリールを特殊な絵柄で停止されることができ,レアなアイテムを手に入れることができる. </p> <p> あなたの仕事は,最短で何フレーム目に全てのリールを特殊な絵柄で停止させることができるかを求めるプログラムを書いて,Nathan くんがレアなアイテムを手に入れられるよう助けてあげることである. </p> <h3>Input</h3> <p> 入力は複数のデータセットからなる.各データセットは次の形式で与えられる. </p> <blockquote> <i>N</i> <i>A</i> <i>B</i> <i>C</i> <i>X</i><br> <i>Y</i><sub>1</sub> <i>Y</i><sub>2</sub> ... <i>Y</i><sub>N</sub> </blockquote> <p> 最初の行には 5 つの整数 <i>N</i> (1 &le; <i>N</i> &le; 100) ,<i>A</i>, <i>B</i> (0 &le; <i>A</i>, <i>B</i> &le; 10,000),<i>C</i> (1 &le; <i>C</i> &le; 10,000) ,<i>X</i> (0 &le; <i>X</i> &lt; <i>C</i>) がそれぞれ 1 つの空白文字で区切られて与えられる.ここで,<i>X</i> は最初の乱数の値を表す.続く行では,<i>N</i> 個の整数 <i>Y</i><sub>1</sub>, <i>Y</i><sub>2</sub>, ... , <i>Y</i><sub><i>N</i></sub> (0 &le; <i>Y</i><sub><i>i</i></sub> &le; 10,000) が 1 つの空白文字で区切られて与えられる.これらは,リールを特定の絵柄で止めるための条件を表しており,その第 <i>i</i> 番目の数 <i>Y</i><sub><i>i</i></sub> は,左から <i>i</i> 番目のリールを特殊な絵柄で停止するためには,乱数の値が <i>Y</i><sub><i>i</I></sub> である必要がある,いう意味である. </p> <p> 入力の終わりは,空白で区切られた 5 つの 0 を含む 1 行で示される. </p> <h3>Output</h3> <p> 各データセットについて,特殊な絵柄で停止させるために必要となる最短のフレーム数を 1 行に出力せよ.なお,10,000 フレーム以内に停止させることができない場合は,フレーム数の代わりに -1 を出力せよ.出力に余計な空白や改行を含めてはならない. </p> <h3>Sample Input</h3> <pre> 1 5 7 11 10 10 2 5 7 11 10 2 4 2 1 1 256 0 128 255 2 0 0 1 0 1234 5678 2 1 1 100 0 99 98 2 1 1 100 0 99 99 2 1 1 10000 0 1 0 2 1 1 10000 0 2 1 0 0 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 0 3 255 -1 198 199 10000 -1 </pre>
p01637
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [['\\(','\\)']] } }); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> <h1 class="ndoc-heading1">Problem D: Change</h1> <p class="ndoc-top">ICPC World Finals 2日目</p> <p class="ndoc-top">ティー氏らは空港のターミナルについた。 これから飛行機を乗り継ぎ敵地R国に乗り込むのである。 我々はD国を経由するため、手持ちのお金を2種類の通貨に両替せねばならない。</p> <p class="ndoc-top">ケー氏「ティーさんはどのように両替しますか?」</p> <p class="ndoc-top">ティー氏「ハフハフハフハフハフハフハフハフ」</p> <p class="ndoc-top">ケー氏「なるほど。私も20,000円をD国用に5,000円、R国用に15,000円割り振ろうと思います」</p> <p class="ndoc-top">ティー氏「ハフハフハフハフハフハフハフハフ」</p> <p class="ndoc-top">ケー氏「あれ?変ですね。両替結果が私と違いますね…。」</p> <h2 class="ndoc-heading2">問題</h2> <p class="ndoc-top">ある旅行者は、日本を旅立ち、D国(通貨単位D)、R国(通貨単位R)を観光し、日本に帰ってくることを考えている。 今、\( M \)円持っている。 \( c_{D} \)[D]、\( c_{R} \)[R]を各国で消費することが分かっているので、 お金が不足しないように両替したい。 \( x \)円をD国のお金に両替すると\( \lfloor \frac{r_{D}x}{100} \rfloor \)[D]に、 \( x \)円をR国のお金に両替すると\( \lfloor \frac{r_{R}x}{100} \rfloor \)[R]になる。</p> <p class="ndoc-top">例えば、 \( r_{D}=11, c_{D}=10 \)の時に 150円をD国のお金に両替すると\( \lfloor \frac{11 \times 150}{100} \rfloor = \)16[D]になるためお金は不足しない。 しかし、50円しか両替しないと5[D]になり10[D]に満たないためお金が不足する。</p> <p class="ndoc-top">また、帰国時には手持ちのお金を全て日本円に両替する。 \( x \)[D]を日本円に両替すると\( \lfloor \frac{100x}{r_{D}} \rfloor \)円に、 \( x \)[R]を日本円に両替すると\( \lfloor \frac{100x}{r_{R}} \rfloor \)円になる。</p> <p class="ndoc-top">先の1つ目の例では、 得られた16[D]のうち10[D]を消費するため6[D]余る。 これを日本円に両替すると\( \lfloor \frac{100 \times 6}{11} \rfloor = 54\)円になる。</p> <p class="ndoc-top">出国時に日本円の最適な両替を行った時、帰国時に最終的に手元に戻ってくる日本円の最大額を求めよ。 いかなる両替を行なっても、D国またはR国のいずれかでお金が不足する場合には&quot;-1&quot;と出力せよ。</p> <p class="ndoc-top">※\( \lfloor x \rfloor \)は、\(x\)を超えない最大の整数を表す。</p> <h2 class="ndoc-heading2">入力</h2> <pre>M r<sub>D</sub> r<sub>R</sub> c<sub>D</sub> c<sub>R</sub> </pre><p>1行目に 現在手持ちの日本円の額\(M\)、 日本円とD国の通貨単位との両替レート\( r_{D} \)、 日本円とR国の通貨単位との両替レート\( r_{R} \)、 D国でのお金の消費額\( c_{D} \)、 R国でのお金の消費額\( c_{R} \)が空白区切りで与えられる。 </p> <h2 class="ndoc-heading2">出力</h2> <p class="ndoc-top">手元に戻ってくる日本円の最大額を1行に出力せよ。 いかなる両替を行なっても、D国またはR国のいずれかでお金が不足する場合は&quot;-1&quot;を出力せよ。</p> <h2 class="ndoc-heading2">制約</h2> <ul class="ndoc-indent"> <li>\( 0 \leq M \leq 10^{12}(= 1000000000000) \) <li>\( 1 \leq r_{D}, r_{R} \leq 100 \) <li>\( 0 \leq c_{D}, c_{R} \leq 10^{12}(= 1000000000000) \) </ul> <h2 class="ndoc-heading2">入出力例</h2> <h3 class="ndoc-heading3">入力1</h3> <pre>20000 3 1 20 100 </pre> <h3 class="ndoc-heading3">出力1</h3> <pre>9333 </pre><p>667円をD国のお金に、10,000円をR国のお金に変換すれば、それぞれ20[D]、100[R]が得られる。</p> <h3 class="ndoc-heading3">入力2</h3> <pre>1000000000000 3 1 20 100 </pre> <h3 class="ndoc-heading3">出力2</h3> <pre>999999989333 </pre><p>この旅行者は大金持ちである。</p> <h3 class="ndoc-heading3">入力3</h3> <pre>0 3 1 20 100 </pre> <h3 class="ndoc-heading3">出力3</h3> <pre>-1 </pre><p>この旅行者は一文無しであり、どこにも行けない。</p>
p02918
<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> people standing in a queue from west to east.</p> <p>Given is a string <var>S</var> of length <var>N</var> representing the directions of the people. The <var>i</var>-th person from the west is facing west if the <var>i</var>-th character of <var>S</var> is <code>L</code>, and east if that character of <var>S</var> is <code>R</code>.</p> <p>A person is happy if the person in front of him/her is facing the same direction. If no person is standing in front of a person, however, he/she is not happy.</p> <p>You can perform the following operation any number of times between <var>0</var> and <var>K</var> (inclusive):</p> <p>Operation: Choose integers <var>l</var> and <var>r</var> such that <var>1 \leq l \leq r \leq N</var>, and rotate by <var>180</var> degrees the part of the queue: the <var>l</var>-th, <var>(l+1)</var>-th, <var>...</var>, <var>r</var>-th persons. That is, for each <var>i = 0, 1, ..., r-l</var>, the <var>(l + i)</var>-th person from the west will stand the <var>(r - i)</var>-th from the west after the operation, facing east if he/she is facing west now, and vice versa.</p> <p>What is the maximum possible number of happy people you can have?</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><var>|S| = N</var></li> <li>Each character of <var>S</var> is <code>L</code> or <code>R</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>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 happy people after at most <var>K</var> operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 1 LRLRRL </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>If we choose <var>(l, r) = (2, 5)</var>, we have <code>LLLRLL</code>, where the <var>2</var>-nd, <var>3</var>-rd, and <var>6</var>-th persons from the west are happy.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>13 3 LRRLRLRRLRLLR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 LLLLLRRRRR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>9 2 RRRLRLRLL </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>7 </pre></section> </div> </span>
p00925
<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 B: Miscalculation </h2> <p> Bob is an elementary schoolboy, not so good at mathematics. He found Father's calculator and tried cheating on his homework using it. His homework was calculating given expressions containing multiplications and additions. Multiplications should be done prior to additions, of course, but the calculator evaluates the expression from left to right, neglecting the operator precedence. So his answers may be the result of either of the following two calculation rules. </p> <ul> <li> Doing multiplication before addition</li> <li> Doing calculation from left to right neglecting the operator precedence</li> </ul> <p> Write a program that tells which of the rules is applied from an expression and his answer. </p> <p> An expression consists of integers and operators. All the integers have only one digit, from 0 to 9. There are two kinds of operators <span>+</span> and <span>*</span>, which represent addition and multiplication, respectively. </p> <p> The following is an example expression. </p> <pre> 1+2*3+4 </pre> <p> Calculating this expression with the multiplication-first rule, the answer is 11, as in Sample Input 1. With the left-to-right rule, however, the answer will be 13 as shown in Sample Input 2. </p> <p> There may be cases in which both rules lead to the same result and you cannot tell which of the rules is applied. Moreover, Bob sometimes commits miscalculations. When neither rules would result in Bob’s answer, it is clear that he actually did. </p> <h3>Input</h3> <p> The input consists of a single test case specified with two lines. The first line contains the expression to be calculated. The number of characters of the expression is always odd and less than or equal to 17. Each of the odd-numbered characters in the expression is a digit from '<span>0</span>' to '<span>9</span>'. Each of the even-numbered characters is an operator '<span>+</span>' or '<span>*</span>'. The second line contains an integer which ranges from 0 to 999999999, inclusive. This integer represents Bob's answer for the expression given in the first line. </p> <h3>Output</h3> <p> Output one of the following four characters:<br> <br> <span>M &nbsp; &nbsp;</span> When only the multiplication-first rule results Bob's answer.<br> <span>L &nbsp; &nbsp;</span> When only the left-to-right rule results Bob's answer.<br> <span>U &nbsp; &nbsp;</span> When both of the rules result Bob's answer.<br> <span>I &nbsp; &nbsp;</span> When neither of the rules results Bob's answer.<br> </p> <h3>Sample Input 1</h3> <pre>1+2*3+4 11</pre> <h3>Sample Output 1</h3> <pre>M</pre> <h3>Sample Input 2</h3> <pre>1+2*3+4 13</pre> <h3>Sample Output 2</h3> <pre>L</pre> <h3>Sample Input 3</h3> <pre>3 3</pre> <h3>Sample Output 3</h3> <pre>U</pre> <h3>Sample Input 4</h3> <pre>1+2*3+4 9</pre> <h3>Sample Output 4</h3> <pre>I</pre>
p01322
<h1><font color="#000">Problem B:</font> 宝くじチェッカー</h1> <p>あなたは無事進学振り分けを終え、駒場近辺から本郷近辺へ引っ越す準備の最中であった。 家の中を整理していたところ去年購入した宝くじが大量に見つかった。 交換期限を確認したところ明日までに換金しなければならないのだが、引っ越しの準備がまだ全く終わっていないため少額の当選金のために宝くじ売り場まで行くのは面倒である。 そこであなたはいくら当選金が得られるかを調べることにした。</p> <p>宝くじは8桁の数字からなる。当選番号は同じく8桁で数字と'*'から構成され、持っている宝くじと数字部分が一致した場合、当選番号に応じた当選金が支払われる。</p> <p>例えば所持している宝くじの番号が "12345678" の場合、当選番号が "*******8" や "****5678" の場合は当選となるが、当選番号が "****4678" のときは当選とはならない。当選番号は複数あり得て、それぞれ独立に当選金が支払われる。ただし、当選番号は1枚の宝くじが2つ以上の当選番号に当たらないように選ばれる。たとえば当選番号が "*******8", "****5678" の2つであった場合、 "12345678" は両方に当選してしまうため、このような当選番号の選ばれ方がされることはない。</p> <p>あなたの仕事は、入力として与えられる所持している宝くじの番号と宝くじの当選番号に対して、いくらの当選金が得られるかを出力するプログラムを書くことである。 </p> <h2>Input</h2> <p>入力は以下のような形式で与えられる。</p> <p> <pre> <i>n</i> <i>m</i> <i>N<sub>1</sub></i> <i>M<sub>1</sub></i> ... <i>N<sub>n</sub></i> <i>M<sub>n</sub></i> <i>B<sub>1</sub></i> ... <i>B<sub>m</sub></i></pre></p> <p>1行目では当選番号の数 <i>n</i> (1 &le; <i>n</i> &le; 100)と所持している宝くじの枚数 <i>m</i> (1 &le; <i>m</i> &le; 1000)がそれぞれ整数で与えられる。</p> <p>続く <i>n</i> 行では、各行に当選番号 <i>N<sub>i</sub></i> と当選金 <i>M<sub>i</sub></i> (1 &le; <i>M<sub>i</sub></i> &le; 1000000)が与えられる。当選金は整数である。当選番号の形式は問題文中で述べたとおりである。</p> <p>続く <i>m</i> 行では所持している宝くじの番号が与えられる。 </p> <h2>Output</h2> <p>当選金の合計額を出力せよ。 </p> <h2>Notes on Test Cases</h2> <p> 上記入力形式で複数のデータセットが与えられます。各データセットに対して上記出力形式で出力を行うプログラムを作成して下さい。 </p> <p> n が 0 のとき入力の終わりを示します。 </p> <!-- <h2>Sample Input 1</h2> <pre>3 3 *******1 100 ******22 1000 11111112 1000000 01203291 02382022 11111111 </pre> <h2>Output for Sample Input 1</h2> <pre>1200 </pre> <h2>Sample Input 2</h2> <pre>10 10 ****3228 149416 ****3992 198635 ****4286 77783 ****4843 225244 ***49835 231046 ***59393 379996 *5763748 437345 *6726222 58054 *8117882 16375 *9244339 537727 77885716 96726222 26971031 66652868 89599648 37772338 64679621 65479161 92959393 57855682 </pre> <h2>Output for Sample Input 2</h2> <pre>438050 </pre> --> <h2>Sample Input</h2> <pre> 3 3 *******1 100 ******22 1000 11111112 1000000 01203291 02382022 11111111 10 10 ****3228 149416 ****3992 198635 ****4286 77783 ****4843 225244 ***49835 231046 ***59393 379996 *5763748 437345 *6726222 58054 *8117882 16375 *9244339 537727 77885716 96726222 26971031 66652868 89599648 37772338 64679621 65479161 92959393 57855682 0 0 </pre> <h2>Output for Sample Input</h2> <pre> 1200 438050 </pre>
p01772
<h2>A: A-Z Cat / A-Z キャット</h2> <h3>物語</h3> <p>あいずにゃんは若ヶ松高校のプログラミングコンテスト部,通称ぷろこん部に所属する2年生である.とてつもなくかわいい.あいずにゃんは友達のジョイに頼まれて猫を預かることになった.A-Z キャットと呼ばれる珍種の猫である.あいずにゃんは預かった A-Z キャットを「あいずにゃん 2 号」と (勝手に) 名付け,大層可愛がった.</p> <p>A-Z キャットは特定の条件を満たす文字列を好むとされる.そこであいずにゃんが試しに文字列を与えてみると,あいずにゃん 2 号は文字列の一部を爪で切り取った後,満足げな表情を浮かべた.どうやら,好みの文字列に書き換えようとしているようだ.</p> <p>天使のごとくかわいいあいずにゃんにぞっこんである D のひとは,あいずにゃんのために A-Z キャットが好む文字列の条件を見つけ出した.それは 'A' と 'Z' が交互に繰り返される文字列であり,かつ 'A' から始まり 'Z' で終わる文字列である.A-Z キャットはとても賢いので,最小限の文字消去で好みの文字列に変換しようとする.あいずにゃんにいい格好をしたい D のひとは,与えられた 'A' と 'Z' のみからなる文字列を A-Z キャットがどのような文字列に変換するか求めるプログラムを書くことにした.</p> <h3>問題</h3> <p>英大文字のみからなる文字列 <var>S</var> が与えられる.<var>S</var> の任意の文字を好きなだけ削除することで,'A' と 'Z' が交互に出現し,かつ 'A' から始まり 'Z' で終わる文字列を作る.削除回数を最小化したとき得られる文字列を求めよ.</p> <h3>入力形式</h3> <p>入力として文字列 <var>S</var> が1行に与えられる.<var>S</var> は英大文字のみからなり,<var>1 &le; |S| &le; 20</var>を満たす.</p> <h3>出力形式</h3> <p><var>S</var> に対し最小回数の文字削除を行って得られる,'A' と'Z' が交互に出現し,かつ 'A' から始まり 'Z' で終わる文字列を 1 行に出力せよ.どのような文字削除を行っても条件を満たす文字列が得られない場合は -1 を 1 行に出力せよ.</p> <h3>入力例1</h3> <pre>AIZUNYANPEROPERO</pre> <h3>出力例1</h3> <pre>AZ</pre> <h3>入力例2</h3> <pre>AZAZ</pre> <h3>出力例2</h3> <pre>AZAZ</pre> <h3>入力例3</h3> <pre>ZDDYAZAWABDDZAZPIDDA</pre> <h3>出力例3</h3> <pre>AZAZAZ</pre> <h3>入力例4</h3> <pre>ZZZZAAAAAA</pre> <h3>出力例4</h3> <pre>-1</pre>
p00860
<H1><font color="#000">Problem G:</font> The Morning after Halloween</H1> <p> You are working for an amusement park as an operator of an <i>obakeyashiki</i>, or a haunted house, in which guests walk through narrow and dark corridors. The house is proud of their lively ghosts, which are actually robots remotely controlled by the operator, hiding here and there in the corridors. One morning, you found that the ghosts are not in the positions where they are supposed to be. Ah, yesterday was Halloween. Believe or not, paranormal spirits have moved them around the corridors in the night. You have to move them into their right positions before guests come. Your manager is eager to know how long it takes to restore the ghosts. </p> <p> In this problem, you are asked to write a program that, given a floor map of a house, finds the smallest number of steps to move all ghosts to the positions where they are supposed to be. </p> <p> A floor consists of a matrix of square cells. A cell is either a wall cell where ghosts cannot move into or a corridor cell where they can. </p> <p> At each step, you can move any number of ghosts simultaneously. Every ghost can either stay in the current cell, or move to one of the corridor cells in its 4-neighborhood (i.e. immediately left, right, up or down), if the ghosts satisfy the following conditions: </p> <ol> <li> No more than one ghost occupies one position at the end of the step.</li> <li> No pair of ghosts exchange their positions one another in the step.</li> </ol> <p> For example, suppose ghosts are located as shown in the following (partial) map, where a sharp sign ('<span>#</span></i>) represents a wall cell and 'a', 'b', and 'c' ghosts. </p> <pre> #### ab# #c## #### </pre> <p> The following four maps show the only possible positions of the ghosts after one step. </p> <pre> #### #### #### #### ab# a b# acb# ab # #c## #c## # ## #c## #### #### #### #### </pre> <H2>Input</H2> <p> The input consists of at most 10 datasets, each of which represents a floor map of a house. The format of a dataset is as follows. </p> <pre> <i>w h n</i> <i>c</i><sub>11</sub><i>c</i><sub>12</sub>...<i>c</i><sub>1<i>w</i></sub> <i>c</i><sub>21</sub><i>c</i><sub>22</sub>...<i>c</i><sub>2<i>w</i></sub> . . .. . .. . . .. . <i>c</i><sub><i>h</i>1</sub><i>c</i><sub><i>h</i>2</sub>...<i>c</i><sub><i>h</i><i>w</i></sub> </pre> <p> <i>w</i>, <i>h</i> and <i>n</i> in the first line are integers, separated by a space. <i>w</i> and <i>h</i> are the floor width and height of the house, respectively. <i>n</i> is the number of ghosts. They satisfy the following constraints. </p> <center> <p> 4 &le; <i>w</i> &le; 16 </p> <p> 4 &le; <i>h</i> &le; 16 </p> <p> 1 &le; <i>n</i> &le; 3 </p> </center> <p> Subsequent <i>h</i> lines of <i>w</i> characters are the floor map. Each of <i>c<sub>ij</sub></i> is either: </p> <ul> <li>a '<span>#</span>' representing a wall cell,</li> <li> a lowercase letter representing a corridor cell which is the initial position of a ghost,</li> <li> an uppercase letter representing a corridor cell which is the position where the ghost corresponding to its lowercase letter is supposed to be, or</li> <li> a space representing a corridor cell that is none of the above.</li> </ul> <p> In each map, each of the first <i>n</i> letters from a and the first n letters from A appears once and only once. Outermost cells of a map are walls; i.e. all characters of the first and last lines are sharps; and the first and last characters on each line are also sharps. All corridor cells in a map are connected; i.e. given a corridor cell, you can reach any other corridor cell by following corridor cells in the 4-neighborhoods. Similarly, all wall cells are connected. Any 2 &times; 2 area on any map has at least one sharp. You can assume that every map has a sequence of moves of ghosts that restores all ghosts to the positions where they are supposed to be. </p> <p> The last dataset is followed by a line containing three zeros separated by a space. </p> <H2>Output</H2> <p> For each dataset in the input, one line containing the smallest number of steps to restore ghosts into the positions where they are supposed to be should be output. An output line should not contain extra characters such as spaces. </p> <H2>Sample Input</H2> <pre> 5 5 2 ##### #A#B# # # #b#a# ##### 16 4 3 ################ ## ########## ## # ABCcba # ################ 16 16 3 ################ ### ## # ## ## # ## # c# # ## ########b# # ## # # # # # # ## # # ## ## a# # # # # ### ## #### ## # ## # # # # # ##### # ## ## #### #B# # # ## C# # ### # # # ####### # # ###### A## # # # ## ################ 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 7 36 77 </pre>
p01288
<H1><font color="#000">Problem F:</font> Marked Ancestor</H1> <p> You are given a tree <i>T</i> that consists of <i>N</i> nodes. Each node is numbered from 1 to <i>N</i>, and node 1 is always the root node of <i>T</i>. Consider the following two operations on <i>T</i>: </p> <ul> <li><span>M v</span>: (Mark) Mark node <span>v</span>.</li> <li><span>Q v</span>: (Query) Print the index of the nearest marked ancestor of node <span>v</span> which is nearest to it. Initially, only the root node is marked. Note that a node is an ancestor of itself.</li> </ul> <p> Your job is to write a program that performs a sequence of these operations on a given tree and calculates the value that each Q operation will print. To avoid too large output file, your program is requested to print the sum of the outputs of all query operations. Note that the judges confirmed that it is possible to calculate every output of query operations in a given sequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> The first line of the input contains two integers <i>N</i> and <i>Q</i>, which denotes the number of nodes in the tree <i>T</i> and the number of operations, respectively. These numbers meet the following conditions: 1 &le; <i>N</i> &le; 100000 and 1 &le; <i>Q</i> &le; 100000. </p> <p> The following <i>N</i> - 1 lines describe the configuration of the tree <i>T</i>. Each line contains a single integer <i>p<sub>i</sub></i> (<i>i</i> = 2, ... , <i>N</i>), which represents the index of the parent of <i>i</i>-th node. </p> <p> The next <i>Q</i> lines contain operations in order. Each operation is formatted as "<span>M v</span>" or "<span>Q v</span>", where <i>v</i> is the index of a node. </p> <p> The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the sum of the outputs of all query operations in one line. </p> <H2>Sample Input</H2> <pre> 6 3 1 1 2 3 3 Q 5 M 3 Q 5 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4 </pre>
p00533
<h2>気象予報士 (Weather Forecaster)</h2> <h2>問題</h2> <p> JOI 市は南北方向に H キロメートル,東西方向に W キロメートルの長方形の形をしており,H &times; W 個の 1 キロメートル四方の小区画に区切られている.北から i 番目,西から j 番目の小区画を (i, j) と表す. </p> <p> 各小区画は上空に雲があるか雲がないかのどちらかである.すべての雲は,1 分経つごとに 1 キロメートル東に移動する.今日は実に天気が良いため,JOI 市の外から JOI 市内に雲が移動してくることはない. </p> <p> 今,各小区画の上空に雲があるかないかがわかっている.気象予報士であるあなたは,各小区画について,今から何分後に初めてその小区画の上空に雲が来るかを予測することになった. </p> <p> 各小区画について,今から何分後に初めてその小区画の上空に雲が来るか求めよ. </p> <h2>入力</h2> <p> 入力は 1 + H 行からなる. </p> <p> 1 行目には,整数 H, W (1 &le; H &le; 100, 1 &le; W &le; 100) が空白を区切りとして書かれている.これは,JOI 市が H &times; W 個の 1 キロメートル四方の小区画に区切られていることを表す. </p> <p> 続く H 行のうちの i 行目 (1 &le; i &le; H) には W 文字からなる文字列が書かれている.W 文字のうちの j 文字目 (1 &le; j &le; W) は,小区画 (i, j) の上空に,今,雲があるかどうかを表す.雲がある場合は文字 'c' (英小文字) が,雲がない場合は文字 '.' (ピリオド) が書かれている. </p> <h2>出力</h2> <p> 出力は H 行からなり,それぞれの行は空白を区切りとした W 個の整数からなる.出力の i 行目の j 番目の整数 (1 &le; i &le; H, 1 &le; j &le; W) は,今から何分後に初めて小区画 (i, j) の上空に雲が来るかを表さなければならない.ただし,今すでに小区画 (i, j) の上空に雲がある場合は 0 を,何分経っても小区画 (i, j) の上空に雲が来ない場合は -1 を出力せよ. </p> <p> 出力の各行の行頭と行末には余計な空白を入れないこと. </p> <h2>入出力例</h2> <h3>入力例 1</h3> <pre> 3 4 c..c ..c. .... </pre> <h3>出力例 1</h3> <pre> 0 1 2 0 -1 -1 0 1 -1 -1 -1 -1 </pre> <h3>入力例 2</h3> <pre> 6 8 .c...... ........ .ccc..c. ....c... ..c.cc.. ....c... </pre> <h3>出力例 2</h3> <pre> -1 0 1 2 3 4 5 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 1 2 0 1 -1 -1 -1 -1 0 1 2 3 -1 -1 0 1 0 0 1 2 -1 -1 -1 -1 0 1 2 3 </pre> <p> 入出力例 1 では,JOI 市は 3 &times; 4 個の小区画に区切られている.今の JOI 市の雲の状況は以下の通りである.図の上が北を表す. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_2015-yo-t3-fig01" width=384 height=288> </center> <p> この後,1 分ごとに雲は以下のように移動する. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_2015-yo-t3-fig02" width=384 height=288><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_2015-yo-t3-fig03" width=384 height=288><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_2015-yo-t3-fig04" width=384 height=288> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p00163
<H1>有料道路通行料</H1> <p> 20XX年に喜多方市熱塩加納町から南会津町までの6区間、総距離58kmの会津中央道路が完成し開通する予定です。 </p> <p> 開通後、半年間は利用促進のため17時30分〜19時30分までに出発ICか到着ICを通過し、なおかつ走行距離が40km以下の車に対する通行料金は半額になります。ただし料金は50円単位とし、端数は切り上げます。下記の表は料金と距離の一覧表です。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_highwayToll1"><br><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_highwayToll2"> </center><br> <p> 例えば喜多方(2)から会津若松(4)までは料金が450円、距離が12kmとなります。半額時間帯であれば250円になります。 </p> <p> 出発IC、出発IC通過時刻、到着IC、到着IC通過時刻を入力とし、料金を計算して出力するプログラムを作成してください。ただし、入力される時刻は24 時間表記の値とします。なお、17時30分および19時30分ちょうどに通過した場合も半額時間帯に含めます。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>d</var> <var>h<sub>d</sub></var> <var>m<sub>d</sub></var> <var>a</var> <var>h<sub>a</sub></var> <var>m<sub>a</sub></var> </pre> <p> 1行目に出発ICの番号 <var>d</var> (1 &le; <var>d</var> &le; 7)、2行目に出発ICの通過時刻の時間 <var>h<sub>d</sub></var> (0 &le; <var>h<sub>d</sub></var> &le; 23) と分 <var>m<sub>d</sub></var> (0 &le; <var>m<sub>d</sub></var> &le; 59) が与えられます。 </p> <p> 3行目に到着ICの番号 <var>a</var> (1 &le; <var>a</var> &le; 7)、4行目に到着ICの通過時刻の時間 <var>h<sub>a</sub></var> (0 &le; <var>h<sub>a</sub></var> &le; 23) と分 <var>m<sub>a</sub></var> (0 &le; <var>m<sub>a</sub></var> &le; 59) が与えられます。 </p> <H2>Output</H2> <p> データセットごとに通行料金(整数)を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 2 17 25 4 17 45 4 17 25 7 19 35 0 </pre> <H2>Output for the Sample Input</H2> <pre> 250 1300 </pre>
p00499
<H1>宿題 (Homework) </H1> <br/> <h2>問題</h2> <p> 冬休みの宿題に毎回苦しめられてきた JOI 君が,今回は宿題を計画的に実行することにした.宿題は国語と算数のドリルであり,国語のドリルは A ページ,算数のドリルは B ページある. </p> <p> JOI 君は,1 日に国語のドリルを最大 C ページと,算数のドリルを最大 D ページ進めることができるが,宿題をするとその日は遊ぶことができない. </p> <p> 冬休みは L 日あり,JOI 君は冬休み中に宿題を終わらせなければならない.JOI 君が冬休み中に最大で何日遊べるかを求めるプログラムを作成せよ. </p> <h2>入力</h2> <p> 入力は 5 行からなり,1 行に 1 つずつ正の整数が書かれている. </p> <p> 1 行目には整数 L (2 ≦ L ≦ 40) が書かれており,冬休みの日数を表す. </p> <p> 2 行目には整数 A (1 ≦ A ≦ 1000) が書かれており,国語のドリルのページ数を表す. </p> <p> 3 行目には整数 B (1 ≦ B ≦ 1000) が書かれており,算数のドリルのページ数を表す. </p> <p> 4 行目には整数 C (1 ≦ C ≦ 100) が書かれており,JOI 君が 1 日に進めることができる国語のドリルの最大ページ数を表す. </p> <p> 5 行目には整数 D (1 ≦ D ≦ 100) が書かれており,JOI 君が 1 日に進めることができる算数のドリルの最大ページ数を表す. </p> <p> ただし,与えられる入力データにおいては,JOI 君が冬休み中に宿題を必ず終わらせることができ, 少なくとも 1 日は遊べることが保証されている. </p> <h2> 出力</h2> <p> JOI 君が冬休み中に遊べる日数の最大値を 1 行で出力せよ. </p> <h2> 入出力例</h2> <h3>入力例 1</h3> <pre> 20 25 30 6 8 </pre> <h3>出力例 1</h3> <pre> 15 </pre> <p> 入出力例 1 では,冬休みは 20 日間あり,国語のドリルが 25 ページ,算数のドリルが 30 ページある.JOI 君は 1 日に国語のドリルを最大 6 ページ,算数のドリルを最大 8 ページ進めることができる.例えば JOI 君が冬休み初日から国語のドリルを 6 ページ,算数のドリルを 8 ページずつ進めたとすると,国語のドリルを 5 日目に,算数のドリルを 4 日目に終わらせることができ,15 日間遊ぶことができる.これが JOI 君が冬休み中に遊べる日数の最大値なので,15 を出力する. </p> <h3>入力例 2</h3> <pre> 15 32 48 4 6 </pre> <h3>出力例 2</h3> <pre> 7 </pre> <p> 入出力例 2 では, 例えば JOI 君が初日から国語のドリルを 4 ページ,算数のドリルを 6 ページずつ進めたとすると,8 日目に両方のドリルを終わらせることができ,7 日間遊ぶことができる.これが JOI 君が冬休み中に遊べる日数の最大値なので,7 を出力する. </p> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p03962
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is <var>a</var>, the color of the one he bought yesterday is <var>b</var>, and the color of the one he bought today is <var>c</var>. Here, the color of each paint can is represented by an integer between <var>1</var> and <var>100</var>, inclusive.</p> <p>Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦a,b,c≦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>a</var> <var>b</var> <var>c</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of different kinds of colors of the paint cans.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>Three different colors: <var>1</var>, <var>3</var>, and <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 33 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>Two different colors: <var>3</var> and <var>33</var>.</p></section> </div> </span>
p02670
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are <var>N</var> rows with <var>N</var> seats each, forming an <var>N\times N</var> square. We denote with <var>1, 2,\dots, N</var> the viewers in the first row (from left to right); with <var>N+1, \dots, 2N</var> the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by <var>N^2-N+1,\dots, N^2</var>.</p> <p>At the end of the movie, the viewers go out of the cinema in a certain order: the <var>i</var>-th viewer leaving her seat is the one denoted by the number <var>P_i</var>. The viewer <var>P_{i+1}</var> waits until viewer <var>P_i</var> has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its <var>4</var> adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer <var>x</var> goes through a seat <strong>currently</strong> occupied by viewer <var>y</var>; in that case viewer <var>y</var> will hate viewer <var>x</var> forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.</p> <p>Compute the number of pairs of viewers <var>(x, y)</var> such that <var>y</var> will hate <var>x</var> forever.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \le N \le 500</var></li> <li>The sequence <var>P_1, P_2, \dots, P_{N^2}</var> is a permutation of <var>\{1, 2, \dots, N^2\}</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 format</p> <pre><var>N</var> <var>P_1</var> <var>P_2</var> <var>\cdots</var> <var>P_{N^2}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>ans</var> is the number of pairs of viewers described in the statement, you should print on Standard Output</p> <pre><var>ans</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 3 7 9 5 4 8 6 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Before the end of the movie, the viewers are arranged in the cinema as follows:</p> <pre>1 2 3 4 5 6 7 8 9 </pre> <p>The first four viewers leaving the cinema (<var>1</var>, <var>3</var>, <var>7</var>, <var>9</var>) can leave the cinema without going through any seat, so they will not be hated by anybody.</p> <p>Then, viewer <var>5</var> must go through one of the seats where viewers <var>2</var>, <var>4</var>, <var>6</var>, <var>8</var> are currently seated while leaving the cinema; hence he will be hated by at least one of those viewers.</p> <p>Finally the remaining viewers can leave the cinema (in the order <var>4</var>, <var>8</var>, <var>6</var>, <var>2</var>) without going through any occupied seat (actually, they can leave the cinema without going through any seat at all).</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 6 7 1 4 13 16 10 9 5 11 12 14 15 2 3 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>11 </pre></section> </div> </span>
p02220
<span class="lang"> <span class="lang-ja"> <h1>I: 偶奇ソート</h1> <div class="part"> <section> <h3>問題文</h3><p>$0$ から $N-1$ までの整数を並び替えた長さ $N$ の順列 $P$ が与えられます。</p> <p>以下の操作を最大 $30$ 回まで行って、 $P$ を昇順に並べ替えてください。</p> </section> </div> <div class="part"> <section> <h3>操作</h3><p>$1$ 回の操作では、次の 1 から 4 を順に行う。</p> <ol> <li><code>0</code> と <code>1</code> からなる長さ $N$ の文字列 $S$ と、整数 $t$ ( $t = 0$ または $t = 1$ ) を宣言する。</li> <li>空の数列 $A, B$ を用意し、整数 $i$ を $1$ から $N$ まで動かしながら以下を行う。<ul> <li>$S_i$ が <code>0</code> のとき、何もしない。</li> <li>$S_i$ が <code>1</code> のとき、<ul> <li>$P_i$ が偶数ならば $A$ の末尾に $P_i$ を追加する。</li> <li>$P_i$ が奇数ならば $B$ の末尾に $P_i$ を追加する。</li> </ul> </li> </ul> </li> <li>数列 $C$ を以下のように定義する。<ul> <li>$t = 0$ のとき、 $C$ は $A$ と $B$ をこの順に連結したものとする。</li> <li>$t = 1$ のとき、 $C$ は $B$ と $A$ をこの順に連結したものとする。</li> </ul> </li> <li>整数 $i$ を $1$ から $N$ まで動かしながら以下を行う。<ul> <li>$S_i$ が <code>0</code> のとき、何もしない。</li> <li>$S_i$ が <code>1</code> のとき、 $P_i$ を $C$ の先頭の要素に置き換え、 $C$ の先頭の要素を消す。</li> </ul> </li> </ol> <p>例えば、$N = 7, P = {0, 4, 2, 3, 6, 5, 1}$ とします。</p> <p>$S$ を "1101101" とし、$t = 1$ とした操作を $1$ 回行うと、以下の図のように $P = {3, 1, 2, 0, 4, 5, 6}$ となります。</p> <p><img alt="parity-sort-example" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_parity-sort.png" /></p> </section> </div> <div class="part"> <section> <h3>制約</h3><ul> <li>$1 \leq N \leq 15000$</li> <li>$P$ は $0$ から $N-1$ までの整数を並び替えた順列</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以下の形式で標準入力から与えられる。</p> <pre>$N$ $P_1$ $P_2$ $\ldots$ $P_N$ </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>$30$ 回以内の操作で $P$ を昇順に並べ替えるような操作列の $1$ つを以下の形式で出力せよ。このような操作列は複数存在するかもしれないが、どれを出力しても正答となる。</p> <ul> <li>$1$ 行目には、操作を行う回数 $K$ を出力せよ。ただし、 $0 \le K \le 30$ でなければならない。</li> <li>$i + 1$ 行目 $(1 \le i \le K)$ には、 $i$ 回目の操作で宣言する整数 $t_i (t_i = 0,1)$ および長さ $N$ の文字列 $S_i$ をこの順に出力せよ。</li> </ul> <pre>$K$ $t_1$ $S_1$ $t_2$ $S_2$ $\vdots$ $t_K$ $S_K$ </pre> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力例1</h3><pre>7 0 4 2 3 6 5 1 </pre> </section> </div> <div class="part"> <section> <h3>出力例1</h3><pre>1 1 0100101 </pre> <p>操作を行うと、$A = { 4, 6 }, B = { 1 }$ となり、 $t = 1$ より $C = { 1, 4, 6 }$ となります。</p> <p>$P$ の要素を $C$ によって置き換えると、 $P = { 0, 1, 2, 3, 4, 5, 6 }$ となるので、この操作で $P$ を昇順に並べ替えることができます。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力例2</h3><pre>4 1 0 3 2 </pre> </section> </div> <div class="part"> <section> <h3>出力例2</h3><pre>2 0 1100 0 0011 </pre> <p>例えば以下のような出力も正答となります。</p> <pre>2 0 1111 1 0110 </pre> </section> </div> <hr /> <div class="part"> <section> <h3>入力例3</h3><pre>1 0 </pre> </section> </div> <div class="part"> <section> <h3>出力例3</h3><pre>0 </pre> <p>操作を行わなくても構いません。</p></section> </div> </span> </span>
p03061
<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> integers, <var>A_1, A_2, ..., A_N</var>, written on the blackboard.</p> <p>You will choose one of them and replace it with an integer of your choice between <var>1</var> and <var>10^9</var> (inclusive), possibly the same as the integer originally written.</p> <p>Find the maximum possible greatest common divisor of the <var>N</var> integers on the blackboard after your move.</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> <div class="part"> <section> <h3>Output</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 greatest common divisor of the <var>N</var> integers on the blackboard after your move.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 7 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>If we replace <var>7</var> with <var>4</var>, the greatest common divisor of the three integers on the blackboard will be <var>2</var>, which is the maximum possible value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 12 15 18 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000 </pre> <p>We can replace an integer with itself.</p></section> </div> </span>
p03431
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In Republic of AtCoder, Snuke Chameleons (Family: Chamaeleonidae, Genus: Bartaberia) are very popular pets. Ringo keeps <var>N</var> Snuke Chameleons in a cage.</p> <p>A Snuke Chameleon that has not eaten anything is blue. It changes its color according to the following rules:</p> <ul> <li>A Snuke Chameleon that is blue will change its color to red when the number of red balls it has eaten becomes strictly larger than the number of blue balls it has eaten.</li> <li>A Snuke Chameleon that is red will change its color to blue when the number of blue balls it has eaten becomes strictly larger than the number of red balls it has eaten.</li> </ul> <p>Initially, every Snuke Chameleon had not eaten anything. Ringo fed them by repeating the following process <var>K</var> times:</p> <ul> <li>Grab either a red ball or a blue ball.</li> <li>Throw that ball into the cage. Then, one of the chameleons eats it.</li> </ul> <p>After Ringo threw in <var>K</var> balls, all the chameleons were red. We are interested in the possible ways Ringo could have thrown in <var>K</var> balls. How many such ways are there? Find the count modulo <var>998244353</var>. Here, two ways to throw in balls are considered different when there exists <var>i</var> such that the color of the ball that are thrown in the <var>i</var>-th throw is different.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,K \leq 5 \times 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>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the possible ways Ringo could have thrown in <var>K</var> balls, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>We will use <code>R</code> to represent a red ball, and <code>B</code> to represent a blue ball. There are seven ways to throw in balls that satisfy the condition: <code>BRRR</code>, <code>RBRB</code>, <code>RBRR</code>, <code>RRBB</code>, <code>RRBR</code>, <code>RRRB</code> and <code>RRRR</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>57 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>46 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>123456 234567 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>857617983 </pre></section> </div> </span>
p03124
<span class="lang-en"> <p>Score : <var>2718</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a very long bench. The bench is divided into <var>M</var> sections, where <var>M</var> is a very large integer.</p> <p>Initially, the bench is vacant. Then, <var>M</var> people come to the bench one by one, and perform the following action:</p> <ul> <li>We call a section <em>comfortable</em> if the section is currently unoccupied and is not adjacent to any occupied sections. If there is no comfortable section, the person leaves the bench. Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there. (The choices are independent from each other).</li> </ul> <p>After all <var>M</var> people perform actions, Snuke chooses an interval of <var>N</var> consecutive sections uniformly at random (from <var>M-N+1</var> possible intervals), and takes a photo. His photo can be described by a string of length <var>N</var> consisting of <code>X</code> and <code>-</code>: the <var>i</var>-th character of the string is <code>X</code> if the <var>i</var>-th section from the left in the interval is occupied, and <code>-</code> otherwise. Note that the photo is directed. For example, <code>-X--X</code> and <code>X--X-</code> are different photos.</p> <p>What is the probability that the photo matches a given string <var>s</var>? This probability depends on <var>M</var>. You need to compute the limit of this probability when <var>M</var> goes infinity.</p> <p>Here, we can prove that the limit can be uniquely written in the following format using three <strong>rational</strong> numbers <var>p, q, r</var> and <var>e = 2.718 \ldots</var> (the base of natural logarithm):</p> <p><var>p + \frac{q}{e} + \frac{r}{e^2}</var></p> <p>Your task is to compute these three rational numbers, and print them modulo <var>10^9 + 7</var>, as described in Notes section.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>When you print a rational number, first write it as a fraction <var>\frac{y}{x}</var>, where <var>x, y</var> are integers and <var>x</var> is not divisible by <var>10^9 + 7</var> (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer <var>z</var> between <var>0</var> and <var>10^9 + 6</var>, inclusive, that satisfies <var>xz \equiv y \pmod{10^9 + 7}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>|s| = N</var></li> <li><var>s</var> consists of <code>X</code> and <code>-</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</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print three rational numbers <var>p, q, r</var>, separated by spaces.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 X </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>500000004 0 500000003 </pre> <p>The probability that a randomly chosen section is occupied converge to <var>\frac{1}{2} - \frac{1}{2e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 --- </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 0 0 </pre> <p>After the actions, no three consecutive unoccupied sections can be left.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 X--X- </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 0 1 </pre> <p>The limit is <var>\frac{1}{e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 X-X-X </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>500000004 0 833333337 </pre> <p>The limit is <var>\frac{1}{2} - \frac{13}{6e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>20 -X--X--X-X--X--X-X-X </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>0 0 183703705 </pre> <p>The limit is <var>\frac{7}{675e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>100 X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X- </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>0 0 435664291 </pre></section> </div> </span>
p01119
<!--<h2>Problem C</h2>--> <!-- begin en only --> <h3>Balance Scale</h3> <!-- end en only --> <!-- begin en only --> <p> You, an experimental chemist, have a balance scale and a kit of weights for measuring weights of powder chemicals. </p> <!-- end en only --> <!-- begin en only --> <p> For work efficiency, a single use of the balance scale should be enough for measurement of each amount. You can use any number of weights at a time, placing them either on the balance plate opposite to the chemical or on the same plate with the chemical. For example, if you have two weights of 2 and 9 units, you can measure out not only 2 and 9 units of the chemical, but also 11 units by placing both on the plate opposite to the chemical (Fig. C-1 left), and 7 units by placing one of them on the plate with the chemical (Fig. C-1 right). These are the only amounts that can be measured out efficiently. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_C1.png" style="width: 60%"> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. C-1 Measuring 11 and 7 units of chemical <!-- end en only --> </figcaption> </center> <!-- begin en only --> <p> You have at hand a list of amounts of chemicals to measure today. The weight kit already at hand, however, may not be enough to efficiently measure all the amounts in the measurement list. If not, you can purchase one single new weight to supplement the kit, but, as heavier weights are more expensive, you'd like to do with the lightest possible. </p> <!-- end en only --> <!-- begin en only --> <p> Note that, although weights of arbitrary positive masses are in the market, none with negative masses can be found. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of at most 100 datasets, each in the following format. </p> <!-- end en only --> <blockquote> <p> <i>n m</i><br> <i>a</i><sub>1</sub> <i>a</i><sub>2</sub> ... <i>a<sub>n</sub></i><br> <i>w</i><sub>1</sub> <i>w</i><sub>2</sub> ... <i>w<sub>m</sub></i><br> </p> </blockquote> <!-- begin en only --> <p> The first line of a dataset has <i>n</i> and <i>m</i>, the number of amounts in the measurement list and the number of weights in the weight kit at hand, respectively. They are integers separated by a space satisfying 1 &le; <i>n</i> &le; 100 and 1 &le; <i>m</i> &le; 10. </p> <!-- end en only --> <!-- begin en only --> <p> The next line has the <i>n</i> amounts in the measurement list, <i>a</i><sub>1</sub> through <i>a<sub>n</sub>,</i> separated by spaces. Each of <i>a<sub>i</sub></i> is an integer satisfying 1 &le; <i>a<sub>i</sub></i> &le; 10<sup>9</sup>, and <i>a<sub>i</sub></i> &ne; <i>a<sub>j</sub></i> holds for <i>i</i> &ne; <i>j</i>. </p> <!-- end en only --> <!-- begin en only --> <p> The third and final line of a dataset has the list of the masses of the <i>m</i> weights at hand, <i>w</i><sub>1</sub> through <i>w<sub>m</sub>,</i> separated by spaces. Each of <i>w<sub>j</sub></i> is an integer, satisfying 1 &le; <i>w<sub>j</sub></i> &le; 10<sup>8</sup>. Two or more weights may have the same mass. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing two zeros. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing an integer specified as follows. <ul> <li> If all the amounts in the measurement list can be measured out without any additional weights, <tt>0</tt>. </li> <li> If adding one more weight will make all the amounts in the measurement list measurable, the mass of the lightest among such weights. The weight added may be heavier than 10<sup>8</sup> units. </li> <li> If adding one more weight is never enough to measure out all the amounts in the measurement list, <tt>-1</tt>. </li> </ul> </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 4 2 9 2 7 11 2 9 6 2 7 3 6 12 16 9 2 9 5 2 7 3 6 12 17 2 9 7 5 15 21 33 48 51 75 111 36 54 57 93 113 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 0 5 -1 5 </pre>
p03574
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an <var>H × W</var> grid.<br/> The squares in the grid are described by <var>H</var> strings, <var>S_1,...,S_H</var>.<br/> The <var>j</var>-th character in the string <var>S_i</var> corresponds to the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left <var>(1 \leq i \leq H,1 \leq j \leq W)</var>.<br/> <code>.</code> stands for an empty square, and <code>#</code> stands for a square containing a bomb. </p> <p>Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.<br/> (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)<br/> He decides to replace each <code>.</code> in our <var>H</var> strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. </p> <p>Print the strings after the process. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H,W \leq 50</var></li> <li><var>S_i</var> is a string of length <var>W</var> consisting of <code>#</code> and <code>.</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format: </p> <pre><var>H</var> <var>W</var> <var>S_1</var> <var>:</var> <var>S_H</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the <var>H</var> strings after the process.<br/> The <var>i</var>-th line should contain a string <var>T_i</var> of length <var>W</var>, where the <var>j</var>-th character in <var>T_i</var> corresponds to the square at the <var>i</var>-th row from the top and <var>j</var>-th row from the left in the grid <var>(1 \leq i \leq H, 1 \leq j \leq W)</var>. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 ..... .#.#. ..... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>11211 1#2#1 11211 </pre> <p>For example, let us observe the empty square at the first row from the top and first column from the left.<br/> There is one bomb square adjacent to this empty square: the square at the second row and second column.<br/> Thus, the <code>.</code> corresponding to this empty square is replaced with <code>1</code>. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 ##### ##### ##### </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>##### ##### ##### </pre> <p>It is possible that there is no empty square. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 6 #####. #.#.## ####.# .#..#. #.##.. #.#... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>#####3 #8#7## ####5# 4#65#2 #5##21 #4#310 </pre></section> </div> </span>
p01549
<h1>問題名 Zero division checker</h1> <p>森下さんは困っていました... 姉原さんにプログラムを書いてもらったのですが、そのプログラムがクラッシュするのです。 </p> <p>姉原さんに書いてもらったのは、逆ポーランド記法の式を読んで、その計算結果を出力するプログラムで、クラッシュログによると、 0 で割り算をしてしまったのが原因のようです。これは、森下さんが間違った式を入力してしまったからかもしれませんし、もしかしたら、もしかしたら、姉原さんの書いたプログラムにバグがあるのかもしれません。 </p> <p>姉原さんの書いたプログラムを読んでみようと思いましたが、姉原さんのプログラムはアセンブリというよくわからないことばで書かれているようで、見ているだけで頭がガンガンしてきます。 </p> <p>そこで、森下さんはあなたに、式が間違っていないかどうか調べるプログラムを書いてもらうことにしました。式が間違っている、とは、その式に従って計算すると、 0 での割り算をしてしまう可能性のあることをいいます。 </p> <p>なお、姉原さんの書いたコードはとてもふるいコンピューターで動くもので、加減乗除は整数で行い、結果は 8 bit の符号なし整数として保存されます。 例えば、<code>255+1</code> は 0 になってしまうし、<code>3/2</code> は 1 になります。 </p> <p>あ、姉原さんにはないしょですよ。 </p> <h3>(参考)逆ポーランド記法で表された式を計算する、擬似コード</h3> </p><pre>s = 空のスタック n = 式の要素数 for i in 1..n: if 式のi番目の要素が整数: sにその整数をプッシュする if 式のi番目の要素が変数: sにその変数の値をプッシュする if 式のi番目の要素が演算子: sから値をポップし、bとする sから値をポップし、aとする if 演算子が'+': r = (a + b) % 256 とする if 演算子が'-': r = (a - b + 256) % 256 とする if 演算子が'*': r = (a * b) % 256 とする if 演算子が'/': r = (a / b) % 256 とする sにrをプッシュする sから値をポップし、式の計算結果とする </pre> <h2>Input</h2> <blockquote> <var>m</var><br> <var>name<sub>1</sub></var> <var>lb<sub>1</sub></var> <var>ub<sub>1</sub></var><br> ...<br> <var>name<sub>m</sub></var> <var>lb<sub>m</sub></var> <var>ub<sub>m</sub></var><br> <var>n</var><br> <var>e<sub>1</sub></var> <var>e<sub>2</sub></var> ... <var>e<sub>n</sub></var><br> </blockquote> <p><var>0 &le; m &le; 100</var> </p> <p><var>0 &le; lb<sub>i</sub> &le; ub<sub>i</sub> &le; 255</var> </p> <p><var>1 &le; name<sub>i</sub> (1 &le; i &le; m) の長さ &le; 20</var> </p> <p><var>1 &le; n &le; 100</var> </p> <p><var>m</var> は変数の数、<var>name<sub>i</sub></var>, <var>lb<sub>i</sub></var>, <var>ub<sub>i</sub></var> はそれぞれ変数iの名前、下限、上限を表します。 </p> <p><var>n</var> は式に含まれる要素の数を表し、<var>e<sub>i</sub></var> は式の <var>i</var> 番目の要素を表します。 </p> <p>各変数は式の中に高々1回しか現れません。 </p> <h2>Output</h2> <p>式が間違っているときには<code>error</code>、間違っていないときには<code>correct</code>と一行で出力してください。 </p> <h2>Sample Input 1</h2> <pre>1 a 1 10 3 10 a / </pre> <h2>Output for the Sample Input 1</h2> <pre>correct </pre> <h2>Sample Input 2</h2> <pre>2 a 1 10 b 1 10 5 1 a b - / </pre> <h2>Output for the Sample Input 2</h2> <pre>error </pre> <h2>Sample Input 3</h2> <pre>1 a 0 255 7 1 a 2 * 1 + / </pre> <h2>Output for the Sample Input 3</h2> <pre>correct </pre>
p03827
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have an integer variable <var>x</var>. Initially, <var>x=0</var>.</p> <p>Some person gave you a string <var>S</var> of length <var>N</var>, and using the string you performed the following operation <var>N</var> times. In the <var>i</var>-th operation, you incremented the value of <var>x</var> by <var>1</var> if <var>S_i=</var><code>I</code>, and decremented the value of <var>x</var> by <var>1</var> if <var>S_i=</var><code>D</code>.</p> <p>Find the maximum value taken by <var>x</var> during the operations (including before the first operation, and after the last operation).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤N≤100</var></li> <li><var>|S|=N</var></li> <li>No characters except <code>I</code> and <code>D</code> occur in <var>S</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>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum value taken by <var>x</var> during the operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 IIDID </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>After each operation, the value of <var>x</var> becomes <var>1</var>, <var>2</var>, <var>1</var>, <var>2</var> and <var>1</var>, respectively. Thus, the output should be <var>2</var>, the maximum value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 DDIDDII </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>The initial value <var>x=0</var> is the maximum value taken by <var>x</var>, thus the output should be <var>0</var>.</p></section> </div> </span>
p00708
<H1>Building a Space Station</H1> <P> You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. </P> <P> The space station is made up with a number of units, called <I>cells.</I> All cells are sphere-shaped, but their sizes are not necessarily uniform. Each cell is fixed at its predetermined position shortly after the station is successfully put into its orbit. It is quite strange that two cells may be touching each other, or even may be overlapping. In an extreme case, a cell may be totally enclosing another one. I do not know how such arrangements are possible. </P> <P> All the cells must be connected, since crew members should be able to walk from any cell to any other cell. They can walk from a cell A to another cell B, if, (1) A and B are touching each other or overlapping, (2) A and B are connected by a `corridor', or (3) there is a cell C such that walking from A to C, and also from B to C are both possible. Note that the condition (3) should be interpreted transitively. </P> <P> You are expected to design a configuration, namely, which pairs of cells are to be connected with corridors. There is some freedom in the corridor configuration. For example, if there are three cells A, B and C, not touching nor overlapping each other, at least three plans are possible in order to connect all three cells. The first is to build corridors A-B and A-C, the second B-C and B-A, the third C-A and C-B. The cost of building a corridor is proportional to its length. Therefore, you should choose a plan with the shortest total length of the corridors. </P> <P> You can ignore the width of a corridor. A corridor is built between points on two cells' surfaces. It can be made arbitrarily long, but of course the shortest one is chosen. Even if two corridors A-B and C-D intersect in space, they are not considered to form a connection path between (for example) A and C. In other words, you may consider that two corridors never intersect. </P> <H2>Input</H2> <P> The input consists of multiple data sets. Each data set is given in the following format. </P> <BLOCKQUOTE> <I>n</I><BR> <I>x</I><SUB>1</SUB> <I>y</I><SUB>1</SUB> <I>z</I><SUB>1</SUB> <I>r</I><SUB>1</SUB><BR> <I>x</I><SUB>2</SUB> <I>y</I><SUB>2</SUB> <I>z</I><SUB>2</SUB> <I>r</I><SUB>2</SUB><BR> ...<BR> <I>x</I><SUB><I>n</I></SUB> <I>y</I><SUB><I>n</I></SUB> <I>z</I><SUB><I>n</I></SUB> <I>r</I><SUB><I>n</I></SUB><BR> </BLOCKQUOTE> <P> The first line of a data set contains an integer <I>n</I>, which is the number of cells. <I>n</I> is positive, and does not exceed 100. </P> <P> The following <I>n</I> lines are descriptions of cells. Four values in a line are <I>x-</I>, <I>y-</I> and <I>z-</I>coordinates of the center, and radius (called <I>r</I> in the rest of the problem) of the sphere, in this order. Each value is given by a decimal fraction, with 3 digits after the decimal point. Values are separated by a space character. </P> <P> Each of <I>x</I>, <I>y</I>, <I>z</I> and <I>r</I> is positive and is less than 100.0. </P> <P> The end of the input is indicated by a line containing a zero. </P> <H2>Output</H2> <P> For each data set, the shortest total length of the corridors should be printed, each in a separate line. The printed values should have 3 digits after the decimal point. They may not have an error greater than 0.001. </P> <P> Note that if no corridors are necessary, that is, if all the cells are connected without corridors, the shortest total length of the corridors is 0.000. </P> <H2>Sample Input</H2> <PRE> 3 10.000 10.000 50.000 10.000 40.000 10.000 50.000 10.000 40.000 40.000 50.000 10.000 2 30.000 30.000 30.000 20.000 40.000 40.000 40.000 20.000 5 5.729 15.143 3.996 25.837 6.013 14.372 4.818 10.671 80.115 63.292 84.477 15.120 64.095 80.924 70.029 14.881 39.472 85.116 71.369 5.553 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> 20.000 0.000 73.834 </PRE>
p02735
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider a grid with <var>H</var> rows and <var>W</var> columns of squares. Let <var>(r, c)</var> denote the square at the <var>r</var>-th row from the top and the <var>c</var>-th column from the left. Each square is painted black or white.</p> <p>The grid is said to be <em>good</em> if and only if the following condition is satisfied:</p> <ul> <li>From <var>(1, 1)</var>, we can reach <var>(H, W)</var> by moving one square <strong>right or down</strong> repeatedly, while always being on a white square.</li> </ul> <p>Note that <var>(1, 1)</var> and <var>(H, W)</var> must be white if the grid is good.</p> <p>Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations.</p> <ul> <li>Choose four integers <var>r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W)</var>. For each pair <var>r, c</var> (<var>r_0 \leq r \leq r_1, c_0 \leq c \leq c_1</var>), invert the color of <var>(r, c)</var> - that is, from white to black and vice versa.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq H, W \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>H</var> <var>W</var> <var>s_{11} s_{12} \cdots s_{1W}</var> <var>s_{21} s_{22} \cdots s_{2W}</var> <var>\vdots</var> <var>s_{H1} s_{H2} \cdots s_{HW}</var> </pre> <p>Here <var>s_{rc}</var> represents the color of <var>(r, c)</var> - <code>#</code> stands for black, and <code>.</code> stands for white.</p> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations needed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 .## .#. ##. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Do the operation with <var>(r_0, c_0, r_1, c_1) = (2, 2, 2, 2)</var> to change just the color of <var>(2, 2)</var>, and we are done.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 #. .# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 4 ..## #... ###. ###. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>No operation may be needed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 5 .#.#. #.#.# .#.#. #.#.# .#.#. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>4 </pre></section> </div> </span>
p00358
<!--<H1>Cargo Layout</H1>--> <H1>Loading</H1> <p> Aizu Ocean Transport Company (AOTC) accepted a new shipping order. The pieces of the cargo included in this order all have the same square footprint (2m x 2m). The cargo room has a rectangular storage space of 4m width with various longitudinal extents. Each pieces of cargo must be placed in alignment with partition boundaries which form a 1m x 1m square grid. A straddling arrangement with a neighboring partition (for example, protrusion by 50 cm) is not allowed. Neither an angled layout nor stacked placement are allowed. Note also that there may be some partitions on which any cargo loading is prohibited. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_cargo" width="680"><br/> </center> <br/> <p> AOTC wishes to use the currently available ship for this consignment and needs to know how many pieces of cargo it can accommodate. </p> <p> Make a program to report the maximum cargo capacity of the cargo space given the following information: the depth (m) of the cargo space and the loading-inhibited partitions. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>H</var> <var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_N</var> <var>y_N</var> </pre> <p> The first line provides the longitudinal depth <var>H</var> (2 &le; <var>H</var> &le; 10<sup>4</sup>) of the cargo space in meters and the number of load-inhibited partitions <var>N</var> (0 &le; <var>N</var> &le; 4 &times; 10<sup>4</sup>). Each of the subsequent <var>N</var> lines defines the position of the <var>i</var>-th load-inhibited partition <var>x_i</var> (0 &le; <var>x_i</var> &le; 3) and <var>y_i</var> (0 &le; <var>y_i</var> &le; <var>H</var>-1) in integers, where <var>x</var> = 0 and <var>y</var> = 0 indicate the bottom-left corner partition. A load-inhibited partition appears only once in the list. </p> <h2>Output</h2> <p> Output the maximum number of cargo pieces loaded into the cargo space. </p> <h2>Sample Input 1</h2> <pre> 5 3 0 1 1 2 3 3 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <p> Input example 1 corresponds to the cargo layout shown in the left-most figure. </p> <h2>Sample Input 2</h2> <pre> 6 4 0 2 1 3 3 4 0 5 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre>
p02365
<H1>Minimum-Cost Arborescence</H1> <br/> <p> Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root <var>r</var> for a given weighted directed graph <var>G</var> = (<var>V</var>, <var>E</var>). </p> <H2>Input</H2> <pre> <var>|V|</var> <var>|E|</var> <var>r</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>w<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>w<sub>|E|-1</sub></var> </pre> <p> , where <var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively. <var>r</var> is the root of the Minimum-Cost Arborescence. </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 directed edge. <var>w<sub>i</sub></var> represents the weight of the <var>i</var>-th directed edge. </p> <H2>Output</H2> <p> Print the sum of the weights the Minimum-Cost Arborescence. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>|V|</var> &le; 100</li> <li>0 &le; <var>|E|</var> &le; 1,000</li> <li>0 &le; <var>w<sub>i</sub></var> &le; 10,000</li> <li><var>G</var> has arborescence(s) with the root <var>r</var></li> </ul> <H2>Sample Input 1</H2> <pre> 4 6 0 0 1 3 0 2 2 2 0 1 2 3 1 3 0 1 3 1 5 </pre> <H2>Sample Output 1</H2> <pre> 6 </pre> <br/> <H2>Sample Input 2</H2> <pre> 6 10 0 0 2 7 0 1 1 0 3 5 1 4 9 2 1 6 1 3 2 3 4 3 4 2 2 2 5 8 3 5 3 </pre> <H2>Sample Output 2</H2> <pre> 11 </pre>
p01660
<h2>E - すごろく</h2> <p> 友達のいないきつねのボブは,今日は一人ですごろく遊びをして過ごすことにした. 各面に整数<var>a_1,a_2,a_3,a_4,a_5,a_6</var>が書かれた6面ダイスと,駒と,直線上にM個のマスがあり 左から順に<var>1</var>から<var>M</var>までの番号が割り当てられたすごろく盤を用いることにした. すごろく盤の各マスには指示が数字で書かれており,<var>i</var>番目のマスには数字<var>N_i</var>が書かれている. これは,その値が正なら右,負なら左に,その絶対値だけ駒を移動せよという意味である. すなわち,<var>i+N_i</var>番目のマスに駒を移動せよという意味である. ボブは,以下のようにしてすごろく遊びをする.まず駒をスタート地点に置く. 次にサイコロを振り,サイコロが出た目の数を見て,駒を「現在のマスから右に移動する」か 「左に移動する」か「現在のマスに留まる」かを選択することができる. マスから移動する場合は,サイコロの出目の距離だけ駒を移動して,移動した先のマスの指示に従う. 指示に従って移動した先のマスの指示には従わない. 以後,ボブは上記のようにサイコロを振って駒を移動することを繰り返す. 移動した結果すごろく盤の外に駒が出てしまったらボブの負けであり,誤答(<em>Wrong Answer</em>)と判定される. この問題の目的はこのすごろくをゴールすることである.サイコロを振る回数は3000回以下とする. </p> <h2>入出力形式</h2> <p>入力は以下の形式で与えられる.</p> <pre> <var>M</var> <var>a_1</var> <var>a_2</var> <var>a_3</var> <var>a_4</var> <var>a_5</var> <var>a_6</var> <var>s</var> <var>g</var> <var>N_1</var> ... <var>N_M</var> </pre> <p> <var>M</var>はすごろく盤のマスの数である. <var>a_1</var> ... <var>a_6</var> はサイコロの各面に書かれている整数の値である. <var>s</var>と<var>g</var>はそれぞれすごろく盤のスタートとゴールの番号である. <var>N_i</var>は<var>i</var>番目のマスに書かれている指示である. これらの入力の後, さいころを振った結果を表す値 <var>dice</var> が改行とともに引き続いて入力から与えられる. これは,サイコロを振って出た目が <var>a<sub>dice</sub></var> であることを表す. これに対して,あなたのプログラムは駒を進めるかどうかを決め,その選択を出力しなければならない.駒を右に移動するならば <code>1</code> を,左に移動するならば <code>-1</code> を,現在のマスに留まるならば <code>0</code> を出力せよ.出力の後には改行を出力せよ. あなたのプログラムが進むか戻るか留まるかを出力すると,次のサイコロを振った結果を入力から受け取ることができる.これを繰り返す. 例えばC/C++では</p> <pre class="prettyprint">scanf("%d", &dice);</pre> <p>としてサイコロの面の番号を受け取り,これに対して左に移動するなら</p> <pre class="prettyprint">printf("-1\n"); fflush(stdout);</pre> <p>とする.次に,</p> <pre class="prettyprint">scanf("%d", &dice);</pre> <p>とすると,次のサイコロの面の番号を受け取ることが出来る.すごろくにゴールしたら直ちにプログラムを終了せよ. ゴールに辿り着くまでにサイコロを振る回数は3000回以下でなければならない. サイコロを振った回数が途中で3000回を超えた場合,誤答と判定される.</p> <h2>制約</h2> <ul> <li><var>2 &le; M &le; 300</var> </li> <li><var>1 &le; s &le; M, 1 &le; g &le; M</var></li> <li><var>s \neq g</var></li> <li><var>1 &le; a_i &le; M-1</var></li> <li><var>1 &le; dice &le; 6</var></li> <li><var>N_s = N_g = 0</var></li> <li>マスの命令に従って駒を進めて枠外に出る事はない.</li> <li><var>dice</var> は <var>\{1,2,…,6\}</var> から擬似乱数で一様ランダムに選ばれる.</li> <li>いくらサイコロを振ったとしてもゴールできない盤面は与えられない.</li> <li>入力の値は全て整数である.</li> </ul> <h2>入出力例1</h2> <pre style="padding-left:20px"> <!--<table class = "table table-striped table-bordered table-condensed">--> <table class="withborder"> <tr><th>すごろくの説明</th><th>プログラムの出力</th><th>プログラムへの入力</th><th>サイコロの目</th><th>駒の移動後のマスの番号</th></tr> <tr><th></th><td></td><td>10 1 6 2 5 3 4 1 10 0 -1 3 -1 3 -2 -6 -5 -7 0 </td><td></td><td></td></tr> <tr><th>1回目のサイコロ</th><td></td><td>1</td><td>1</td><td></td></tr> <tr><th>1回目のプログラムの出力</th><td>0</td><td></td><td></td><td>1</td></tr> <tr><th>2回目のサイコロ</th><td></td><td>3</td><td>2</td><td></td></tr> <tr><th>2回目のプログラムの出力</th><td>1</td><td></td><td></td><td>6</td></tr> <tr><th>3回目のサイコロ</th><td></td><td>5</td><td>3</td><td></td></tr> <tr><th>3回目のプログラムの出力</th><td>0</td><td></td><td></td><td>6</td></tr> <tr><th>4回目のサイコロ</th><td></td><td>1</td><td>1</td><td></td></tr> <tr><th>4回目のプログラムの出力</th><td>-1</td><td></td><td></td><td>8</td></tr> <tr><th>5回目のサイコロ</th><td></td><td>3</td><td>2</td><td></td><tr> <tr><th>5回目のプログラムの出力</th><td>1</td><td></td><td></td><td>10</td></tr> </table> </pre>
p00972
<h2>Eulerian Flight Tour</h2> <p> You have an airline route map of a certain region. All the airports in the region and all the <i>non-stop routes</i> between them are on the map. Here, a non-stop route is a flight route that provides non-stop flights in both ways. </p> <p> Named after the great mathematician Leonhard Euler, an <i>Eulerian tour</i> is an itinerary visiting all the airports in the region taking a single flight of every non-stop route available in the region. To be precise, it is a list of airports, satisfying all of the following. </p> <ul> <li> The list begins and ends with the same airport.</li> <li> There are non-stop routes between pairs of airports adjacent in the list.</li> <li> All the airports in the region appear <i>at least once</i> in the list. Note that it is allowed to have some airports appearing multiple times.</li> <li> For all the airport pairs with non-stop routes in between, there should be <i>one and only one adjacent appearance</i> of two airports of the pair in the list in either order.</li> </ul> <p> It may not always be possible to find an Eulerian tour only with the non-stop routes listed in the map. Adding more routes, however, may enable Eulerian tours. Your task is to find a set of additional routes that enables Eulerian tours. </p> <h3>Input</h3> <p> The input consists of a single test case. </p> <pre> $n$ $m$ $a_1$ $b_1$ ... $a_m$ $b_m$ </pre> <p> $n$ ($3 \leq n \leq 100$) is the number of airports. The airports are numbered from 1 to $n$. $m$ ($0 \leq m \leq \frac{n(n-1)}{2}$) is the number of pairs of airports that have non-stop routes. Among the $m$ lines following it, integers $a_i$ and $b_i$ on the $i$-th line of them ($1 \leq i \leq m$) are airport numbers between which a non-stop route is operated. You can assume $1 \leq a_i < b_i \leq n$, and for any $i \ne j$, either $a_i \ne a_j$ or $b_i \ne b_j$ holds. </p> <h3>Output</h3> <p> Output a set of additional non-stop routes that enables Eulerian tours. If two or more different sets will do, any one of them is acceptable. The output should be in the following format. </p> <pre> $k$ $c_1$ $d_1$ ... $c_k$ $d_k$ </pre> <p> $k$ is the number of non-stop routes to add, possibly zero. Each of the following $k$ lines should have a pair of integers, separated by a space. Integers $c_i$ and $d_i$ in the $i$-th line ($c_i < d_i$) are airport numbers specifying that a non-stop route is to be added between them. These pairs, ($c_i, d_i$) for $1 \leq i \leq k$, should be distinct and should not appear in the input. </p> <p> If adding new non-stop routes can never enable Eulerian tours, output <span>-1</span> in a line. </p> <h3>Sample Input 1</h3> <pre> 4 2 1 2 3 4 </pre> <h3>Sample Output 1</h3> <pre> 2 1 4 2 3 </pre> <h3>Sample Input 2</h3> <pre> 6 9 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6 </pre> <h3>Sample Output 2</h3> <pre> -1 </pre> <h3>Sample Input 3</h3> <pre> 6 7 1 2 1 3 1 4 2 3 4 5 4 6 5 6 </pre> <h3>Sample Output 3</h3> <pre> 3 1 5 2 4 2 5 </pre> <h3>Sample Input 4</h3> <pre> 4 3 2 3 2 4 3 4 </pre> <h3>Sample Output 4</h3> <pre> -1 </pre> <h3>Sample Input 5</h3> <pre> 5 5 1 3 1 4 2 4 2 5 3 5 </pre> <h3>Sample Output 5</h3> <pre> 0 </pre>
p01230
<h1><font color="#000">Problem H:</font> いけるかな?</h1> <p> あるところに,日本各地をまわりながら商売をする社長がいた. 彼はある日,不思議な切符を手に入れた. その切符を使うと,なんと目的地までの距離によらず電車の運賃が無料になるという. ただし, 現在の駅から隣接する駅へ移動するのを1ステップと数えたときに, 移動するステップ数がちょうど切符に書かれた数と等しくならないと 追加料金を取られてしまう. ある区間をただちに折り返すような移動は禁止されているが, 既に訪れた駅や区間を複数回通ること自体は許される. たとえば,駅1・駅2・駅1と移動することはできないが, 駅1・駅2・駅3・駅1・駅2のような移動は問題ない. また,最終的に目的地に到着するならば,出発地や目的地も何度でも通ってよい. </p> <p> 社長はさっそくこの切符を次の目的地に行くために使ってみようと考えた. しかし路線図は入り組んでいるため,簡単には経路が定まらない. あなたの仕事は,社長に代わって目的地に無料で到達できるかどうかを 判定するプログラムを書くことである. </p> <p> 駅は 1 から <var>N</var> までの番号が振られており, 出発地の駅は 1,目的地の駅は <var>N</var> と決まっている. 路線図は2つの駅を結ぶ区間の列によって与えられる. 区間はどちらの方向にも通行することができる. 同じ駅同士を結ぶような区間は存在しないことと, ある駅の対を結ぶ区間はたかだか1つであることが保証されている. </p> <h2>Input</h2> <p> 入力は複数のデータセットからなる. </p> <p> それぞれのデータセットは次のような形式で与えられる. </p> <p> <var>N</var> <var>M</var> <var>Z</var><br> <var>s</var><sub>1</sub> <var>d</var><sub>1</sub><br> <var>s</var><sub>2</sub> <var>d</var><sub>2</sub><br> ...<br> <var>s</var><sub><var>M</var></sub> <var>d</var><sub><var>M</var></sub> </p> <p> <var>N</var> は駅の総数,<var>M</var> は区間の総数であり, <var>Z</var> は切符に書かれたステップ数である. <var>s</var><sub><var>i</var></sub> と <var>d</var><sub><var>i</var></sub> (1 &le; <var>i</var> &le; M) は駅の番号を表す整数であり, それぞれ駅 <var>s</var><sub><var>i</var></sub> と駅 <var>d</var><sub><var>i</var></sub> の間に区間が存在することを表現している. </p> <p> <var>N</var>, <var>M</var>, <var>Z</var> は正の整数であり,次の条件を満たす: 2 &le; <var>N</var> &le; 50, 1 &le; <var>M</var> &le; 50, 0 &lt; <var>Z</var> &lt; 2<sup>31</sup>. </p> <p> 最後のデータセットの後ろに, &ldquo;<code>0 0 0</code>&rdquo; と書かれた1行がある. </p> <p> データセットの数は30を越えない. </p> <h2>Output</h2> <p> それぞれのデータセットに対し, チケットに書かれているステップ数ちょうどで 目的地に到達できるならば &ldquo;<code>yes</code>&rdquo;, 到達できないならば &ldquo;<code>no</code>&rdquo; のみを含む1行の文字列を出力せよ. </p> <h2>Sample Input</h2> <pre> 2 1 1 1 2 2 1 2 1 2 3 1 2 1 2 8 8 5778 1 2 2 3 2 4 3 5 5 6 6 7 7 8 4 8 8 8 5777 1 2 2 3 2 4 3 5 5 6 6 7 7 8 4 8 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> yes no no yes no </pre>
p04032
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given a string <var>t</var>, we will call it <em>unbalanced</em> if and only if the length of <var>t</var> is at least <var>2</var>, and more than half of the letters in <var>t</var> are the same. For example, both <code>voodoo</code> and <code>melee</code> are unbalanced, while neither <code>noon</code> nor <code>a</code> is.</p> <p>You are given a string <var>s</var> consisting of lowercase letters. Determine if there exists a (contiguous) substring of <var>s</var> that is unbalanced. If the answer is positive, show a position where such a substring occurs in <var>s</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≦ |s| ≦ 10^5</var></li> <li><var>s</var> consists of lowercase letters.</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>2 ≦ N ≦ 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>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists no unbalanced substring of <var>s</var>, print <code>-1 -1</code>.</p> <p>If there exists an unbalanced substring of <var>s</var>, let one such substring be <var>s_a s_{a+1} ... s_{b}</var> <var>(1 ≦ a &lt; b ≦ |s|)</var>, and print <code><var>a</var> <var>b</var></code>. If there exists more than one such substring, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>needed </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 5 </pre> <p>The string <var>s_2 s_3 s_4 s_5</var> <var>=</var> <code>eede</code> is unbalanced. There are also other unbalanced substrings. For example, the output <code>2 6</code> will also be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>atcoder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 -1 </pre> <p>The string <code>atcoder</code> contains no unbalanced substring.</p></section> </div> </span>
p00071
<H1>爆弾の連鎖</H1> <p> 縦 8、横 8 のマスからなる図1 のような平面があります。その平面上に、いくつかの爆弾が置かれています。図2 にその例を示します(● = 爆弾)。 </p> <center> <table> <tr> <td> <table cellpadding=0 cellspacing=0> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> </table> </td> <td> <table cellpadding=0 cellspacing=0> <tr><td>□</td><td>□</td><td>□</td><td>●</td><td>□</td><td>□</td><td>●</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>●</td><td>□</td><td>□</td></tr> <tr><td>●</td><td>□</td><td>□</td><td>□</td><td>●</td><td>□</td><td>□</td><td>●</td></tr> <tr><td>□</td><td>□</td><td>●</td><td>□</td><td>□</td><td>□</td><td>●</td><td>□</td></tr> <tr><td>□</td><td>●</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>●</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>●</td><td>□</td><td>●</td><td>□</td><td>□</td><td>□</td><td>●</td><td>□</td></tr> <tr><td>□</td><td>●</td><td>□</td><td>●</td><td>□</td><td>□</td><td>●</td><td>□</td></tr> </table> </td> </tr> <tr><th width=160>図1</th><th width=160>図2</th></tr> </table> </center> <br/> <!-- <pre > □□□□□□□□   □□□●□□●□   □□□□□□□□ □□□□□□□□   □□□□□●□□   □□□□□●□□ □□□□□□□□   ●□□□●□□●   ●□□□●□□● □□□□□□□□   □□●□□□●□   □□●□□□□□ □□□□□□□□   □●□□□□□□   □□□□□□□□ □□□□□□□□   □□□□●□□□   □□□□●□□□ □□□□□□□□   ●□●□□□●□   ●□●□□□□□ □□□□□□□□   □●□●□□●□   □□□□□□□□    図1           図2         図3 </pre> --> <p> 爆弾が爆発すると、その爆弾の上下左右 3 マスに爆風の影響が及び、それらのマスに置かれている爆弾も連鎖的に爆発します。たとえば、図 3 に示す爆弾が爆発すると図 4 の■のマスに爆風の影響が及びます。 </p> <center> <table> <tr> <td> <table cellpadding=0 cellspacing=0> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>●</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> </table> </td> <td> <table cellpadding=0 cellspacing=0> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>■</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>■</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>■</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>■</td><td>■</td><td>■</td><td>●</td><td>■</td><td>■</td><td>■</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>■</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>■</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> </table> </td> </tr> <tr><th width=160>図3</th><th width=160>図4</th></tr> </table> </center> <br/> <!-- <pre> 12345678  1 □□□□□□□□   □□□□□□□□ 2 □□□□□□□□   □□□□□□□□ 3 □□□□□□□□   □□□☆□□□□ 4 □□□□□□□□   □□□☆□□□□ 5 □□□□□□□□   □□□☆□□□□ 6 □□□●□□□□   ☆☆☆●☆☆☆□ 7 □□□□□□□□   □□□☆□□□□ 8 □□□□□□□□   □□□☆□□□□     図4           図5 </pre> --> <p> 爆弾が置かれている状態と最初に爆発する爆弾の位置を読み込んで、最終的な平面の状態を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は以下の形式で与えられます。 </p> <pre> <var>n</var> (空行) データセット 1 (空行) データセット 2 .. .. データセット <var>n</var> </pre> <p> 1行目にデータセットの数 <var>n</var> (<var>n</var> &le; 20) が与えられます。続いて <var>n</var> 個のデータセットが与えられます。各データセットの直前に1つの空行が与えられます。各データセットは以下の形式で与えられます。 </p> <pre> <var>g<sub>1,1</sub>g<sub>2,1</sub></var>...<var>g<sub>8,1</sub></var> <var>g<sub>1,2</sub>g<sub>2,2</sub></var>...<var>g<sub>8,2</sub></var> : <var>g<sub>1,8</sub>g<sub>2,8</sub></var>...<var>g<sub>8,8</sub></var> <var>X</var> <var>Y</var> </pre> <!-- <p> 平面の中で爆弾が置かれているマスを 1、置かれていないマスを 0 で表現した数字の列が与えられます。8文字からなる数列一行が、空間の一行を表現しています。さらに続く2 行で、最初に爆発する爆弾の座標が与えられます。第一行目の数字が X 座標、第二行目の数字が Y 座標を表します。左上、左下、右上、右下の座標が、それぞれ、(1, 1)、(1, 8)、(8, 1)、(8, 8) です。例えば、図4 に示す爆弾が最初に爆発するとき、与えられる座標は(4, 6) です。 </p> --> <p> 最初の8行に、平面を表す8つの文字列が与えられます。各文字列は8文字からなる数列で、爆弾が置かれているマスを 1、置かれていないマスを 0 で表します。 続く2行で、最初に爆発する爆弾の <var>X</var> 座標と <var>Y</var> 座標が与えられます。左上、左下、右上、右下の座標が、それぞれ、(1, 1)、(1, 8)、(8, 1)、(8, 8) です。例えば、図 4 に示す爆弾が最初に爆発するとき、与えられる座標は (4, 6) です。 </p> <H2>Output</H2> <p> 各データセットについて以下のように出力して下さい。 </p> <p> 爆発しないで残った爆弾のあるマスを 1、爆弾のないマスを 0 で表現することとします。平面の一行を数字 8 個からなる一行とし 8 行の文字列で最終的な平面の状態を出力してください。各データセットの先頭は、サンプル出力のように Data <var>x</var>: から出力しなければなりません。ここで、<var>x</var> はデータセットの番号です。 </p> <H2>Sample Input</H2> <pre> 2 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 00010010 00000100 10001001 00100010 01000000 00001000 10100010 01010010 2 5 </pre> <H2>Output for the Sample Input</H2> <pre> Data 1: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 Data 2: 00000000 00000100 10001001 00100000 00000000 00001000 10100000 00000000 </pre>
p00421
<h1>三角形の個数の和</h1>   <p> 座標平面上の原点$O$を左下、座標$(W,H)$にある点を右上とする長方形の領域が与えられています。この領域に含まれる、$x$座標と$y$座標がともに整数である点を3個以上含む点の集まりを考えます。このような点の集まりのすべての組み合わせの個数を$N$とし、点の集まりのそれぞれを$D_1, D_2, ..., D_N$で表したとき、$D_1, D_2, ..., D_N$のそれぞれに含まれる点を頂点とする三角形を考えます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/PCK2019_triangle"></img> </center> <p> たとえば、図のように$W=H=1$のとき、点$O(0,0)$、$A(1,0)$、$B(1,1)$、$C(0,1)$のうち、3個以上含む点の集まりは$\{O,A,B\}$、$\{O,A,C\}$、$\{O,B,C\}$、$\{A,B,C\}$、$\{O,A,B,C\}$の5つです。この例の場合、点の集まりのそれぞれに含まれる三角形は次のようになります。 </p> <ul> <li> $\{O,A,B\}$に含まれる三角形は$OAB$のみ。</li> <li> $\{O,A,C\}$に含まれる三角形は$OAC$のみ。</li> <li> $\{O,B,C\}$に含まれる三角形は$OBC$のみ。</li> <li> $\{A,B,C\}$に含まれる三角形は$ABC$のみ。</li> <li> $\{O,A,B,C\}$に含まれる三角形は$OAB$、$OAC$、$OBC$、$ABC$の4個。</li> </ul> <p> この例からわかるように、同じ三角形が2つ以上の点の集まりに含まれる場合があります。たとえば、三角形$OAB$は点の集まり$\{O,A,B\}$にも$\{O,A,B,C\}$にも含まれます。 </p> <p> $W$と$H$が与えられる。点の集まり$D_1, D_2, ..., D_N$それぞれに含まれる点を頂点とする三角形の個数を$t_1, t_2, ..., t_N$とするとき、三角形の個数の和$t_1+t_2+...+t_N$を計算するプログラムを作成せよ。 </p> <h2>入力</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> $W$ $H$ </pre> <p> 1行に$W$と$H$ ($1 \leq W,H \leq 1,000$)が与えられる。 </p> <h2>出力</h2> <p> それぞれの点の集まりに含まれる三角形の個数の和を1,000,000,007で割った余りを1行に出力する。 </p> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 1 1 </pre> <h3>出力例1</h3> <pre> 8 </pre> <h3>入力例2</h3> <pre> 1 2 </pre> <h3>出力例2</h3> <pre> 144 </pre> <h3>入力例3</h3> <pre> 100 100 </pre> <h3>出力例3</h3> <pre> 879128399 </pre>
p02109
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Problem L: Select Sets</h1> <h2>Problem</h2> <p> 整数の集合が<var>N</var>個ある。 これらの集合にはそれぞれ1から<var>N</var>までの番号が割り振られている。<var>i</var>番目の集合の要素数は<var>K<sub>i</sub></var>であり、その集合の要素の中で<var>j</var>番目に小さい整数は<var>a<sub>i,j</sub></var>である。 </p> <p> 太郎君はこの中から任意の数だけ集合を選ぶことになった。 ただ適当に選ぶだけではつまらないと思った太郎君は、少なくとも3つの集合を選ぶことにした。また、"選んだ集合の和集合の要素数"と"選んだ集合の積集合の要素数"の積ができるだけ大きくなるように選ぶことにした。 </p> <p> 太郎君が最適に集合を選んだとき、"選んだ集合の和集合の要素数"と"選んだ集合の積集合の要素数"の積の最大値を求めよ。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> <var>N</var> <var>K<sub>1</sub></var> <var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,K<sub>1</sub></sub></var> <var>K<sub>2</sub></var> <var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,K<sub>2</sub></sub></var> ... <var>K<sub>N</sub></var> <var>a<sub>N,1</sub></var> <var>a<sub>N,2</sub></var> ... <var>a<sub>N,K<sub>N</sub></sub></var> </pre> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>入力は全て整数である。</li> <li>3 &le; <var>N</var> &le; 20,000</li> <li>1 &le; <var>a<sub>i,j</sub></var> &le; 22</li> <li> <var>a<sub>i,j</sub></var> &lt; <var>a<sub>i,j+1</sub></var> ( 1 &le; <var>i</var> &le; <var>N</var> ) ( 1 &le; <var>j</var> &lt; <var>K<sub>i</sub></var>)</li> </ul> <h2>Output</h2> <p> 太郎君が最適に選んだときの"選んだ集合の和集合の要素数"と"選んだ集合の積集合の要素数"の積の最大値を出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 4 1 5 2 3 5 3 3 5 7 4 3 5 7 9 </pre> <h2>Sample Output 1</h2> <pre> 8 </pre> <h2>Sample Input 2</h2> <pre> 5 4 1 4 5 6 4 1 7 8 9 3 1 2 3 3 1 2 3 3 1 2 3 </pre> <h2>Sample Output 2</h2> <pre> 9 </pre> <h2>Sample Input 3</h2> <pre> 3 2 3 4 2 2 5 2 1 6 </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p00134
<H1>出口調査</H1> <p> あるデパートで買い物金額の出口調査を行いました。買い物金額のデータを入力とし、1 人あたりの平均買い物金額を計算し、出力するプログラムを作成してください。調査人数は、10 万人以下とし、一人あたりの買い物金額は 100 万円を超えないものとします。 </p> <H2>Input</H2> <p> 入力は以下の形式で与えられます。 </p> <pre> <var>n</var> <var>v<sub>1</sub></var> <var>v<sub>2</sub></var> : <var>v<sub>n</sub></var> </pre> <p> 1 行目に調査人数 <var>n</var>、続く <var>n</var> 行に <var>i</var> 人目の買い物金額を表す整数 <var>v<sub>i</sub></var> が与えられます。 </p> <H2>Output</H2> <p> 平均買い物金額(整数:小数点以下は切り捨て)を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> 6 12300 5600 33800 0 26495 52000 </pre> <H2>Output for the Sample Input</H2> <pre> 21699 </pre>
p02559
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an array <var>a_0, a_1, ..., a_{N-1}</var> of length <var>N</var>. Process <var>Q</var> queries of the following types.</p> <ul> <li><code>0 p x</code>: <var>a_p \gets a_p + x</var></li> <li><code>1 l r</code>: Print <var>\sum_{i = l}^{r - 1}{a_i}</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N, Q \leq 500,000</var></li> <li><var>0 \leq a_i, x \leq 10^9</var></li> <li><var>0 \leq p &lt; N</var></li> <li><var>0 \leq l_i &lt; r_i \leq N</var></li> <li>All values in Input are integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>a_0</var> <var>a_1</var> ... <var>a_{N - 1}</var> <var>\textrm{Query}_0</var> <var>\textrm{Query}_1</var> : <var>\textrm{Query}_{Q - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query of the latter type, print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 1 2 3 4 5 1 0 5 1 2 4 0 3 10 1 0 5 1 0 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>15 7 25 6 </pre></section> </div> </span>
p00564
<h1>鉛筆 (Pencils)</h1> <h2>問題文</h2> <p> JOI 君は鉛筆を <var>N</var> 本買うために近くの文房具店に行くことにした. </p> <p> 文房具店では鉛筆が一定の本数ずつのセットで売られている.セット <var>X</var> は <var>A</var> 本で <var>B</var> 円,セット <var>Y</var> は <var>C</var> 本で <var>D</var> 円である. </p> <p> JOI 君はセット <var>X</var> かセット <var>Y</var> の一方を選び,選んだセットをいくつか購入する.両方のセットを購入することはできない.<var>N</var> 本以上の鉛筆を得るために必要な金額の最小値を求めよ. </p> <h2>制約</h2> <ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>1 \leq A \leq 1000</var></li> <li><var>1 \leq B \leq 1000</var></li> <li><var>1 \leq C \leq 1000</var></li> <li><var>1 \leq D \leq 1000</var></li> </ul> <h2>入力・出力</h2> <p> <b>入力</b><br> 入力は以下の形式で標準入力から与えられる.<br> <var>N</var> <var>A</var> <var>B</var> <var>C</var> <var>D</var> </p> <p> <b>出力</b><br> JOI 君が <var>N</var> 本以上の鉛筆を手に入れるのに必要な金額の最小値を出力せよ.<br> <h2>入出力例</h2> <b>入力例 1</b><br> <pre> 10 3 100 5 180 </pre> <b>出力例 1</b><br> <pre> 360 </pre> <p> JOI 君は10本の鉛筆を入手したい.セット <var>X</var> は3本で100円,セット <var>Y</var> は5本で180円である.この時,セット <var>X</var> を選んだ場合は,セットを4つ購入する必要があり400円必要である.セット <var>Y</var> を選んだ場合は,セットを2つ購入する必要があり360円必要である.したがって,必要な金額の最小値は400円と360円の小さい方で360円である. </p> <hr> <b>入力例 2</b><br> <pre> 6 2 200 3 300 </pre> <b>出力例 2</b><br> <pre> 600 </pre> <p> このとき,セット <var>X</var> を選んだ場合もセット <var>Y</var> を選んだ場合も必要な金額は600円である.必要な金額の最小値は600円である. </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>
p01725
<p>小学生のイクタ君は、ある日おじいさんから数式が書かれた紙をもらった。 どうやらおじいさんは数式の答えの金額だけお小遣いをくれるらしい。 イクタ君はまだ足し算、引き算、掛け算しか習ってなかったので、数式にも足し算と引き算と掛け算しか使われていない。 通常の計算では足し算と引き算より掛け算を先に計算しなければならないのだが、イクタ君は演算子の優先順位についての理解があやふやだったので、とりあえず数式の計算結果が最大になるような都合の良い優先順位を考えることにした。 </p> <p><var>+&minus;&times;</var>の3つの二項演算子と括弧を含む数式が与えられる。 3つの演算子の優先順位を任意に変更して、数式を最大化したときの計算結果を答えよ。 </p> <p>ただし、以下の点に注意せよ。 </p> <ul><li> 演算子は必ず左結合である。 (同じ優先順位の演算子は必ず数式の左側から計算する。) </li><li> 異なる演算子が同じ優先順位であってもよい。 </li><li> 一つの数式を計算している途中で優先順位を変更してはならない。 </li></ul> <h2>Input</h2> <p>入力は以下の形式で与えられる。<br> 0〜9の数字と演算子'+','-','*'、括弧'(',')'で構成された数式<br> </p> <ul><li> 正確に記述すると入力は以下のBNFで示される形式になっている </li></ul> <blockquote> &lt;expr&gt; ::= ( &lt;expr&gt; ) | &lt;number&gt; | &lt;expr&gt; &lt;op> &lt;expr&gt; <br> &lt;op&gt; ::= + | - | * </blockquote> <p> &lt;number&gt;は非負整数を表す。</p> <h3>Constraints</h3> <p>入力は以下の制約を満たす。 </p> <ul><li> 数式は200文字以下である。 </li><li> どのような優先順位を設定しても、計算の結果やその途中で64bit整数型でoverflowするようなことはない。 </li></ul> <h2>Output</h2> <p>数式から得られる最大値を1行で出力せよ。 </p> <h2>Sample Input 1</h2> <pre>3-2*3 </pre> <h2>Output for the Sample Input 1</h2> <pre>3 </pre> <ul><li> *の優先順位を-より低くすることでこのようになる。 </li></ul> <h2>Sample Input 2</h2> <pre>(5-3*4)*(0-2+1) </pre> <h2>Output for the Sample Input 2</h2> <pre>21 </pre> <ul><li> 優先順位は+>*>- </li></ul> <h2>Sample Input 3</h2> <pre>1-2+3-4+5-6*0 </pre> <h2>Output for the Sample Input 3</h2> <pre>3 </pre> <ul><li> 優先順位が一般的な場合 </li></ul> <h2>Sample Input 4</h2> <pre>(1989967-3*1-211+4487) </pre> <h2>Output for the Sample Input 4</h2> <pre>8511076028 </pre>
p03718
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a pond with a rectangular shape. The pond is divided into a grid with <var>H</var> rows and <var>W</var> columns of squares. We will denote the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left by <var>(i,\ j)</var>.</p> <p>Some of the squares in the pond contains a lotus leaf floating on the water. On one of those leaves, <var>S</var>, there is a frog trying to get to another leaf <var>T</var>. The state of square <var>(i,\ j)</var> is given to you by a character <var>a_{ij}</var>, as follows:</p> <ul> <li><code>.</code> : A square without a leaf.</li> <li><code>o</code> : A square with a leaf floating on the water.</li> <li><code>S</code> : A square with the leaf <var>S</var>.</li> <li><code>T</code> : A square with the leaf <var>T</var>.</li> </ul> <p>The frog will repeatedly perform the following action to get to the leaf <var>T</var>: "jump to a leaf that is in the same row or the same column as the leaf where the frog is currently located."</p> <p>Snuke is trying to remove some of the leaves, other than <var>S</var> and <var>T</var>, so that the frog cannot get to the leaf <var>T</var>. Determine whether this objective is achievable. If it is achievable, find the minimum necessary number of leaves to remove.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≤ H, W ≤ 100</var></li> <li><var>a_{ij}</var> is <code>.</code>, <code>o</code>, <code>S</code> or <code>T</code>.</li> <li>There is exactly one <code>S</code> among <var>a_{ij}</var>.</li> <li>There is exactly one <code>T</code> among <var>a_{ij}</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>a_{11}</var> <var>...</var> <var>a_{1W}</var> <var>:</var> <var>a_{H1}</var> <var>...</var> <var>a_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the objective is achievable, print the minimum necessary number of leaves to remove. Otherwise, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 S.o .o. o.T </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Remove the upper-right and lower-left leaves.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 4 S... .oo. ...T </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 3 .S. .o. .o. .T. </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>10 10 .o...o..o. ....o..... ....oo.oo. ..oooo..o. ....oo.... ..o..o.... o..o....So o....T.... ....o..... ........oo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 </pre></section> </div> </span>
p00837
<H1><font color="#000">Problem B:</font> Book Replacement</H1> <p> The deadline of Prof. Hachioji’s assignment is tomorrow. To complete the task, students have to copy pages of many reference books in the library. </p> <p> All the reference books are in a storeroom and only the librarian is allowed to enter it. To obtain a copy of a reference book’s page, a student should ask the librarian to make it. The librarian brings books out of the storeroom and makes page copies according to the requests. The overall situation is shown in Figure 1. </p> <p> Students queue up in front of the counter. Only a single book can be requested at a time. If a student has more requests, the student goes to the end of the queue after the request has been served. </p> <p> In the storeroom, there are m desks <i>D</i><sub>1</sub>, ... , <i>D</i><sub><i>m</i></sub>, and a shelf. They are placed in a line in this order, from the door to the back of the room. Up to c books can be put on each of the desks. If a student requests a book, the librarian enters the storeroom and looks for it on <i>D</i><sub>1</sub>, ... , <i>D</i><sub><i>m</i></sub> in this order, and then on the shelf. After finding the book, the librarian takes it and gives a copy of a page to the student. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bookReplacement"> </center> <p> Then the librarian returns to the storeroom with the requested book, to put it on <i>D</i><sub>1</sub> according to the following procedure. </p> <ul> <li>If <i>D</i><sub>1</sub> is not full (in other words, the number of books on <i>D</i><sub>1</sub> &lt; <i>c</i>), the librarian puts the requested book there.</li> <li> If <i>D</i><sub>1</sub> is full, the librarian <ul> <li> temporarily puts the requested book on the non-full desk closest to the entrance or, in case all the desks are full, on the shelf,</li> <li> finds the book on <i>D</i><sub>1</sub> that has not been requested for the longest time (i.e. the least recently used book) and takes it,</li> <li> puts it on the non-full desk (except <i>D</i><sub>1</sub> ) closest to the entrance or, in case all the desks except <i>D</i><sub>1</sub> are full, on the shelf,</li> <li> takes the requested book from the temporary place,</li> <li> and finally puts it on <i>D</i><sub>1</sub> .</li> </ul> </ul> <p> Your task is to write a program which simulates the behaviors of the students and the librarian, and evaluates the total cost of the overall process. Costs are associated with <i>accessing</i> a desk or the shelf, that is, putting/taking a book on/from it in the description above. The cost of an access is <i>i</i> for desk <i>D<sub>i</sub></i> and <i>m</i> + 1 for the shelf. That is, an access to <i>D</i><sub>1</sub>, ... , <i>D<sub>m</sub></i> , and the shelf costs 1, ... , <i>m</i>, and <i>m</i> + 1, respectively. Costs of other actions are ignored. </p> <p> Initially, no books are put on desks. No new students appear after opening the library. </p> <H2>Input</H2> <p> The input consists of multiple datasets. The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset. </p> <p> The format of each dataset is as follows. </p> <pre> <i>m c n</i> <i>k</i><sub>1</sub> <i>b</i><sub>11</sub> . . . <i>b</i><sub>1<i>k</i><sub>1</sub></sub> . . . <i>k<sub>n</sub></i> <i>b</i><sub><i>n</i>1</sub> . . . <i>b<sub>nk<sub>n</sub></sub></i> </pre> <p> Here, all data items are positive integers. <i>m</i> is the number of desks not exceeding 10. <i>c</i> is the number of books allowed to put on a desk, which does not exceed 30. <i>n</i> is the number of students not exceeding 100. <i>k<sub>i</sub></i> is the number of books requested by the <i>i</i>-th student, which does not exceed 50. <i>b<sub>ij</sub></i> is the ID number of the book requested by the <i>i</i>-th student on the <i>j</i>-th turn. No two books have the same ID number. Note that a student may request the same book more than once. <i>b<sub>ij</sub></i> is less than 100. </p> <p> Here we show you an example of cost calculation for the following dataset. </p> <pre> 3 1 2 3 60 61 62 2 70 60 </pre> <p> In this dataset, there are 3 desks (<i>D</i><sub>1</sub>, <i>D</i><sub>2</sub>, <i>D</i><sub>3</sub> ). At most 1 book can be put on each desk. The number of students is 2. The first student requests 3 books of which IDs are 60, 61, and 62, respectively, and the second student 2 books of which IDs are 70 and 60, respectively. </p> <p> The calculation of the cost for this dataset is done as follows. First, for the first request of the first student, the librarian takes the book 60 from the shelf and puts it on <i>D</i><sub>1</sub> and the first student goes to the end of the queue, costing 5. Next, for the first request of the second student, the librarian takes the book 70 from the shelf, puts it on <i>D</i><sub>2</sub>, moves the book 60 from <i>D</i><sub>1</sub> to <i>D</i><sub>3</sub> , and finally moves the book 70 from <i>D</i><sub>2</sub> to <i>D</i><sub>1</sub> , costing 13. Similarly, the cost for the books 61, 60, and 62, are calculated as 14, 12, 14, respectively. Therefore, the total cost is 58. <H2>Output</H2> <p> For each dataset, output the total cost of processing all the requests, in a separate line. </p> <H2>Sample Input</H2> <pre> 2 1 1 1 50 2 1 2 1 50 1 60 2 1 2 2 60 61 1 70 4 2 3 3 60 61 62 1 70 2 80 81 3 1 2 3 60 61 62 2 70 60 1 2 5 2 87 95 3 96 71 35 2 68 2 3 3 18 93 2 57 2 2 2 1 5 1 2 1 3 1 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4 16 28 68 58 98 23 </pre>
p01375
<!-- begin en only --> <!--<h3><U>Intelligent Circular Perfect Cleaner</U></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><U>全自動円形掃除機</U></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> Automatic Cleaning Machine (ACM) 社は画期的な全自動円形掃除機 Intelligent Circular Perfect Cleaner(ICPC) を開発した. なんとこの ICPC は人がいない日中に自動で動き出し,自分が通り過ぎた場所のゴミを掃除する機能を備えている. 全自動という特性を活かすためにも ICPC の集塵機の容積を大きくし,人手でゴミを捨てる回数を減らしたい. しかしながら ICPC が大型化すればするほど ICPC が円形故に部屋の隅の掃除できない部分の面積も大きくなってしまう.(図G-1) </p> <p style="text-align: center;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011G-1" width="20%"><br/> 図G-1 </p> <p> また廊下の幅よりも大きくしてしまうと廊下を通ることができなくなってしまう.(図G-2) </p> <p style="text-align: center;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011G-2" width="40%"><br/> 図G-2 </p> <p> ACM 社は凄腕プログラマーのあなたに,部屋の見取り図とICPCの中心座標と半径からその部屋の中でICPCが掃除可能な面積を出力するプログラムの作成を依頼した. </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は複数のデータセットからなり,各データセットは以下の形式をしている. </p> <p> <i>n</i> <i>x</i> <i>y</i> <i>r</i><br/> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br/> <i>x<sub>2</sub></i> <i>y<sub>2</sub></i><br/> ...</br> <i>x<sub>n</sub></i> <i>y<sub>n</sub></i> </p> <p> データセットの1行目には4つの整数 <i>n</i> , <i>x</i> , <i>y</i> , <i>r</i> が記されており,それぞれ部屋を構成する多角形の頂点数(3 &le; <i>n</i> &le; 20), ICPCの初期位置の中心座標 (-100 &le; <i>x</i> , <i>y</i> &le; 100), ICPCの半径 (1 &le; <i>r</i> &le; 100)を表している. 続く <i>n</i> 行には多角形の頂点の座標が反時計回りに記されており,以下の条件を満たす. </p> <ul> <li>-100 &le; <i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> &le; 100</li> <li>全ての壁は,x軸かy軸に並行</li> <li>ICPCの初期位置は必ず部屋の内側にあり,どの部屋の壁とも10<sup>-3</sup>以上離れている</li> <li>任意の部屋の頂点同士の距離,任意の部屋の頂点と部屋の辺の距離,任意の部屋の辺同士の距離は 2<i>r</i> +10<sup>-3</sup>より大きいかもしくは 2<i>r</i> -10<sup>-3</sup>より小さい</li> </ul> </p> <p> 四つのゼロのみからなる行が入力の終わりを表す. </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 各データセットに対し,ICPCが掃除可能な領域の面積を1行に出力せよ.答えには10<sup>-6</sup>を超える誤差があってはならない. </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 4 5 5 1 0 0 10 0 10 10 0 10 8 5 5 1 0 0 9 0 9 1 10 1 10 9 9 9 9 10 0 10 12 25 5 1 0 0 10 0 10 4 20 4 20 0 40 0 40 10 20 10 20 5 10 5 10 10 0 10 0 0 0 0 </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 99.1415926535897 96.7123889804 199.2321787 </pre> </div>
p03348
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Coloring of the vertices of a tree <var>G</var> is called a <em>good coloring</em> when, for every pair of two vertices <var>u</var> and <var>v</var> painted in the same color, picking <var>u</var> as the root and picking <var>v</var> as the root would result in isomorphic rooted trees.</p> <p>Also, the <em>colorfulness</em> of <var>G</var> is defined as the minimum possible number of different colors used in a good coloring of <var>G</var>.</p> <p>You are given a tree with <var>N</var> vertices. The vertices are numbered <var>1</var> through <var>N</var>, and the <var>i</var>-th edge connects Vertex <var>a_i</var> and Vertex <var>b_i</var>. We will construct a new tree <var>T</var> by repeating the following operation on this tree some number of times:</p> <ul> <li>Add a new vertex to the tree by connecting it to one of the vertices in the current tree with an edge.</li> </ul> <p>Find the minimum possible colorfulness of <var>T</var>. Additionally, print the minimum number of leaves (vertices with degree <var>1</var>) in a tree <var>T</var> that achieves the minimum colorfulness.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>The phrase "picking <var>u</var> as the root and picking <var>v</var> as the root would result in isomorphic rooted trees" for a tree <var>G</var> means that there exists a bijective function <var>f_{uv}</var> from the vertex set of <var>G</var> to itself such that both of the following conditions are met:</p> <ul> <li><var>f_{uv}(u)=v</var></li> <li>For every pair of two vertices <var>(a,b)</var>, edge <var>(a,b)</var> exists if and only if edge <var>(f_{uv}(a),f_{uv}(b))</var> exists.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100</var></li> <li><var>1 \leq a_i,b_i \leq N(1\leq i\leq 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>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print two integers with a space in between. First, print the minimum possible colorfulness of a tree <var>T</var> that can be constructed. Second, print the minimum number of leaves in a tree that achieves it.</p> <p>It can be shown that, under the constraints of this problem, the values that should be printed fit into <var>64</var>-bit signed integers.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 2 3 3 4 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 4 </pre> <p>If we connect a new vertex <var>6</var> to vertex <var>2</var>, painting the vertices <var>(1,4,5,6)</var> red and painting the vertices <var>(2,3)</var> blue is a good coloring. Since painting all the vertices in a single color is not a good coloring, we can see that the colorfulness of this tree is <var>2</var>. This is actually the optimal solution. There are four leaves, so we should print <var>2</var> and <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 1 2 2 3 4 3 5 4 6 7 6 8 3 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 2 2 3 3 4 4 5 5 6 6 7 3 8 5 9 3 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>13 5 6 6 4 2 8 4 7 8 9 3 2 10 4 11 10 2 4 13 10 1 8 12 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>4 12 </pre></section> </div> </span>
p03427
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find the maximum possible sum of the digits (in base <var>10</var>) of a positive integer not greater than <var>N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1\leq N \leq 10^{16}</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the digits (in base <var>10</var>) of a positive integer not greater than <var>N</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>18 </pre> <p>For example, the sum of the digits in <var>99</var> is <var>18</var>, which turns out to be the maximum value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9995 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>35 </pre> <p>For example, the sum of the digits in <var>9989</var> is <var>35</var>, which turns out to be the maximum value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3141592653589793 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>137 </pre></section> </div> </span>
p03077
<span class="lang-en"> <p>Score: <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City <var>1, 2, 3, 4, 5, 6</var>)!</p> <p>There are five means of transport in this empire:</p> <ul> <li>Train: travels from City <var>1</var> to <var>2</var> in one minute. A train can occupy at most <var>A</var> people.</li> <li>Bus: travels from City <var>2</var> to <var>3</var> in one minute. A bus can occupy at most <var>B</var> people.</li> <li>Taxi: travels from City <var>3</var> to <var>4</var> in one minute. A taxi can occupy at most <var>C</var> people.</li> <li>Airplane: travels from City <var>4</var> to <var>5</var> in one minute. An airplane can occupy at most <var>D</var> people.</li> <li>Ship: travels from City <var>5</var> to <var>6</var> in one minute. A ship can occupy at most <var>E</var> people.</li> </ul> <p>For each of them, one vehicle leaves the city at each integer time (time <var>0</var>, <var>1</var>, <var>2</var>, <var>...</var>).</p> <p>There is a group of <var>N</var> people at City <var>1</var>, and they all want to go to City <var>6</var>.<br/> At least how long does it take for all of them to reach there? You can ignore the time needed to transfer. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N, A, B, C, D, E \leq 10^{15}</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</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the minimum time required for all of the people to reach City <var>6</var>, in minutes.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 2 4 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>One possible way to travel is as follows. First, there are <var>N = 5</var> people at City <var>1</var>, as shown in the following image:</p> <p><img alt=" " src="https://img.atcoder.jp/ghi/9c306138eddc8a2e08acfa5da19bdfe8.png"/></p> <p>In the first minute, three people travels from City <var>1</var> to City <var>2</var> by train. Note that a train can only occupy at most three people.</p> <p><img alt=" " src="https://img.atcoder.jp/ghi/bd30b5ab37fc06951c9f5256bb974e4f.png"/></p> <p>In the second minute, the remaining two people travels from City <var>1</var> to City <var>2</var> by train, and two of the three people who were already at City <var>2</var> travels to City <var>3</var> by bus. Note that a bus can only occupy at most two people.</p> <p><img alt=" " src="https://img.atcoder.jp/ghi/50f2e49a770a30193fc53588ec8475b3.png"/></p> <p>In the third minute, two people travels from City <var>2</var> to City <var>3</var> by train, and another two people travels from City <var>3</var> to City <var>4</var> by taxi.</p> <p><img alt=" " src="https://img.atcoder.jp/ghi/d6d80dc50abe58190905c8c5ea6ba345.png"/></p> <p>From then on, if they continue traveling without stopping until they reach City <var>6</var>, all of them can reach there in seven minutes.<br/> There is no way for them to reach City <var>6</var> in <var>6</var> minutes or less.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 123 123 123 123 123 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>All kinds of vehicles can occupy <var>N = 10</var> people at a time. Thus, if they continue traveling without stopping until they reach City <var>6</var>, all of them can reach there in five minutes. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10000000007 2 3 5 7 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5000000008 </pre> <p>Note that the input or output may not fit into a <var>32</var>-bit integer type.</p></section> </div> </span>
p02236
<h1>Optimal Binary Search Tree</h1> <p> Optimal Binary Search Tree is a binary search tree constructed from $n$ keys and $n+1$ dummy keys so as to minimize the expected value of cost for a search operation. </p> <p> We are given a sequence $K = {k_1, k_2, ..., k_n}$ of $n$ distinct keys in sorted order $(k_1 < k_2 < ... < k_n)$, and we wish to construct a binary search tree. For each key $k_i$, we have a probability $p_i$ that a search will be for $k_i$. Some searches may be for values not in $K$, and so we also have $n+1$ dummy keys $d_0, d_1, d_2, ..., d_n$ representing values not in $K$. The dummy keys $d_i (0 \le i \le n)$ are defined as follows: </p> <ul> <li>if $i=0$, then $d_i$ represents all values less than $k_1$</li> <li>if $i=n$, then $d_i$ represents all values greater than $k_n$</li> <li>if $1 \le i \le n-1$, then $d_i$ represents all values between $k_i$ and $k_{i+1}$</li> </ul> <p> For each dummy key $d_i$, we have a probability $q_i$ that a search will correspond to $d_i$. For $p_i (1 \le i \le n)$ and $q_i (0 \le i \le n)$, we have \[ \sum_{i=1}^n p_i + \sum_{i=0}^n q_i = 1 \] Then the expected cost of a search in a binary search tree $T$ is \[ E_T = \sum_{i=1}^n (depth_T(k_i) + 1) \cdot p_i + \sum_{i=0}^n (depth_T(d_i) + 1) \cdot q_i \] where $depth_T(v)$ is the depth of node $v$ in $T$. For a given set of probabilities, our goal is to construct a binary search tree whose expected search cost is smallest. We call such a tree an <b>optimal binary search tree</b>. </p> <p> Each key $k_i$ is an internal node and each dummy key $d_i$ is a leaf. For example, the following figure shows the optimal binary search tree obtained from Sample Input 1. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ALDS1_10_D_tree1"> </center> <h2>Task</h2> <p> Write a program which calculates the expected value of a search operation on the optimal binary search tree obtained by given $p_i$ that a search will be for $k_i$ and $q_i$ that a search will correspond to $d_i$. </p> <h2>Input</h2> <pre> $n$ $p_1$ $p_2$ ... $p_n$ $q_0$ $q_1$ $q_2$ ... $q_n$ </pre> <p> In the first line, an integer $n$ which represents the number of keys is given.<br> In the second line, $p_i (1 \le i \le n)$ are given in real numbers with four decimal places.<br> In the third line, $q_i (0 \le i \le n)$ are given in real numbers with four decimal places.<br> </p> <h2>Output</h2> <p> Print the expected value for a search operation on the optimal binary search tree in a line. The output must not contain an error greater than $10^{−4}$. </p> <h2>Constraints</h2> <ul> <li>$1 \le n \le 500$</li> <li>$0 \lt p_i, q_i \lt 1$</li> <li>$\displaystyle \sum_{i=1}^n p_i + \sum_{i=0}^n q_i = 1$</li> </ul> <h2>Sample Input 1</h2> <pre> 5 0.1500 0.1000 0.0500 0.1000 0.2000 0.0500 0.1000 0.0500 0.0500 0.0500 0.1000 </pre> <h2>Sample Output 1</h2> <pre> 2.75000000 </pre> <h2>Sample Input 2</h2> <pre> 7 0.0400 0.0600 0.0800 0.0200 0.1000 0.1200 0.1400 0.0600 0.0600 0.0600 0.0600 0.0500 0.0500 0.0500 0.0500 </pre> <h2>Sample Output 2</h2> <pre> 3.12000000 </pre>
p02666
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> towns numbered <var>1, 2, \cdots, N</var>.</p> <p>Some roads are planned to be built so that each of them connects two distinct towns bidirectionally. Currently, there are no roads connecting towns.</p> <p>In the planning of construction, each town chooses one town different from itself and requests the following: roads are built so that the chosen town is reachable from itself using one or more roads.</p> <p>These requests from the towns are represented by an array <var>P_1, P_2, \cdots, P_N</var>. If <var>P_i = -1</var>, it means that Town <var>i</var> has not chosen the request; if <var>1 \leq P_i \leq N</var>, it means that Town <var>i</var> has chosen Town <var>P_i</var>.</p> <p>Let <var>K</var> be the number of towns <var>i</var> such that <var>P_i = -1</var>. There are <var>(N-1)^K</var> ways in which the towns can make the requests. For each way to make requests, find the minimum number of roads needed to meet all the requests, and print the sum of those <var>(N-1)^K</var> numbers, modulo (<var>10^9+7</var>).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 5000</var></li> <li><var>P_i = -1</var> or <var>1 \leq P_i \leq N</var>.</li> <li><var>P_i \neq i</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>P_1</var> <var>P_2</var> <var>\cdots</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each way to make requests, find the minimum number of roads needed to meet all the requests, and print the sum of those <var>(N-1)^K</var> numbers, modulo (<var>10^9+7</var>).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 1 -1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>There are three ways to make requests, as follows:</p> <ul> <li>Choose <var>P_1 = 2, P_2 = 1, P_3 = 1, P_4 = 3</var>. In this case, at least three roads - for example, <var>(1,2),(1,3),(3,4)</var> - are needed to meet the requests.</li> <li>Choose <var>P_1 = 2, P_2 = 1, P_3 = 2, P_4 = 3</var>. In this case, at least three roads - for example, <var>(1,2),(1,3),(3,4)</var> - are needed to meet the requests.</li> <li>Choose <var>P_1 = 2, P_2 = 1, P_3 = 4, P_4 = 3</var>. In this case, at least two roads - for example, <var>(1,2),(3,4)</var> - are needed to meet the requests.</li> </ul> <p>Note that it is not mandatory to connect Town <var>i</var> and Town <var>P_i</var> directly.</p> <p>The sum of the above numbers is <var>8</var>.</p> </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> <p>There may be just one fixed way to make requests.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 2 6 9 -1 6 9 -1 -1 -1 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>527841 </pre></section> </div> </span>
p01949
<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> Route Calculator </H1> <p> You have a grid with $H$ rows and $W$ columns. $H + W$ is even. We denote the cell at the $i$-th row from the top and the $j$-th column from the left by ($i, j$). In any cell ($i, j$), an integer between $1$ and $9$ is written if $i+j$ is even, and either '<span>+</span>' or '<span>*</span>' is written if $i+j$ is odd. </p> <p> You can get a mathematical expression by moving right or down $H + W - 2$ times from ($1, 1$) to ($H, W$) and concatenating all the characters written in the cells you passed in order. Your task is to maximize the calculated value of the resulting mathematical expression by choosing an arbitrary path from ($1, 1$) to ($H, W$). If the maximum value is $10^{15}$ or less, print the value. Otherwise, print $-1$. </p> <H2>Input</H2> <p> The input consists of a single test case in the format below. </p> <pre> $H$ $W$ $a_{1,1}$ ... $a_{1,W}$ ... $a_{H,1}$ ... $a_{H,W}$ </pre> <p> The first line consists of two $H$ integers and $W$ ($1 \leq H, W \leq 50$). It is guaranteed that $H + W$ is even. The following $H$ lines represent the characters on the grid. $a_{i,j}$ represents the character written in the cell ($i, j$). In any cell ($i, j$), an integer between $1$ and $9$ is written if $i+j$ is even, and either '<span>+</span>' or '<span>*</span>' is written if $i+1$ is odd. </p> <H2>Output</H2> <p> Print the answer in one line. </p> <H2>Sample Input 1</H2> <pre> 3 3 1+2 +9* 1*5 </pre> <H2>Output for Sample Input 1</H2> <pre> 46 </pre> <p> The maximum value is obtained by passing through the following cells: $(1,1), (2,1), (2,2), (2,3), (3,3)$. </p> <H2>Sample Input 2</H2> <pre> 1 31 9*9*9*9*9*9*9*9*9*9*9*9*9*9*9*9 </pre> <H2>Output for Sample Input 2</H2> <pre> -1 </pre> <p> You can obtain $9^{16}$, but it's too large. </p> <H2>Sample Input 3</H2> <pre> 5 5 2+2+1 +1+1+ 1+2+2 +1+1+ 1+1+2 </pre> <H2>Output for Sample Input 3</H2> <pre> 10 </pre> <H2>Sample Input 4</H2> <pre> 9 7 8+9*4*8 *5*2+3+ 1*3*2*2 *5*1+9+ 1+2*2*2 *3*6*2* 7*7+6*5 *5+7*2+ 3+3*6+8 </pre> <H2>Output for Sample Input 4</H2> <pre> 86408 </pre>
p03974
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> strings of lowercase alphabet only. The <var>i</var>-th string is <var>S_i</var>. Every string is unique.</p> <p>Provide answers for the <var>Q</var> queries below. The <var>i</var>-th query has the following format:</p> <p>Query: An integer <var>k_i</var> and a string <var>p_{i,1}p_{i,2}...p_{i,26}</var> that results from permuting {<code>a</code><var>,</var><code>b</code><var>,...,</var><code>z</code>} are given. Output the sequence of the string <var>S_{k_i}</var> among the <var>N</var> strings in lexicographical order when the literal sequence is <var>p_{i,1}&lt;p_{i,2}&lt;...&lt;p_{i,26}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≦ N,Q ≦ 100000</var></li> <li><var>1 ≦ |S_i| (1 ≦ i ≦ N)</var></li> <li><var>S_i (1 ≦ i ≦ N)</var> is a string of lowercase alphabet.</li> <li>The sum of <var>|S_i|</var> is no more than <var>400000</var>.</li> <li>Every <var>S_i</var> is unique.</li> <li><var>1 ≦ k_i ≦ N (1 ≦ i ≦ Q)</var></li> <li>For all <var>1 ≦ i ≦ Q</var>, <var>p_{i,1}p_{i,2}...p_{i,26}</var> is a permutation of <code>abcd...z</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Inputs are provided from standard inputs in the following form.</p> <pre><var>N</var> <var>S_1</var> : <var>S_N</var> <var>Q</var> <var>k_1</var> <var>p_{1,1}p_{1,2}...p_{1,26}</var> : <var>k_Q</var> <var>p_{Q,1}p_{Q,2}...p_{Q,26}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Output <var>Q</var> lines.</p> <p>On line <var>i</var>, for the <var>i</var>-th query, output an integer indicating the sequence of the string <var>S_{k_i}</var> among the <var>N</var> strings in lexicographical order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 aa abbaa abbba aaab aaaaaba 5 1 abcdefghijklmnopqrstuvwxyz 2 bacdefghijklmnopqrstuvwxyz 3 abcdefghijklmnopqrstuvwxyz 4 bacdefghijklmnopqrstuvwxyz 5 abcdefghijklmnopqrstuvwxyz </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 5 4 2 </pre> <p>When the literal sequence is <code>a</code> <var>&lt;</var> <code>b</code>, sorting the input strings in lexicographical order yields <code>aa</code>, <code>aaaaaba</code>, <code>aaab</code>, <code>abbaa</code>, <code>abbba</code>. The answers to queries <var>1</var>, <var>3</var>, and <var>5</var> are thus <var>1</var>, <var>5</var>, and <var>2</var>, respectively.</p> <p>When the literal sequence is <code>b</code> <var>&lt;</var> <code>a</code>, sorting the input strings in lexicographical order yields <code>abbba</code>, <code>abbaa</code>, <code>aa</code>, <code>aaab</code>, <code>aaaaaba</code>. The answers to queries <var>2</var> and <var>4</var> are thus <var>2</var> and <var>4</var>, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 abrakatabra abadaba abracadabra atcoder grand contest ababa a 6 3 abcdefghijklmnopqrstuvwxyz 6 qwertyuiopasdfghjklzxcvbnm 8 poiuytrewqlkjhgfdsamnbvcxz 2 qazwsxedcrfvtgbyhnujmikolp 1 plokmijnuhbygvtfcrdxeszwaq 4 mnbvcxzasdfghjklpoiuytrewq </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 8 2 3 4 7 </pre></section> </div> </span>
p02689
<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> observatories in AtCoder Hill, called Obs. <var>1</var>, Obs. <var>2</var>, <var>...</var>, Obs. <var>N</var>. The elevation of Obs. <var>i</var> is <var>H_i</var>. There are also <var>M</var> roads, each connecting two different observatories. Road <var>j</var> connects Obs. <var>A_j</var> and Obs. <var>B_j</var>.</p> <p>Obs. <var>i</var> is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. <var>i</var> using just one road. Note that Obs. <var>i</var> is also good when no observatory can be reached from Obs. <var>i</var> using just one road.</p> <p>How many good observatories are there?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq M \leq 10^5</var></li> <li><var>1 \leq H_i \leq 10^9</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li><var>A_i \neq B_i</var></li> <li>Multiple roads may connect the same pair of observatories.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>:</var> <var>A_M</var> <var>B_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of good observatories.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 2 3 4 1 3 2 3 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <ul> <li> <p>From Obs. <var>1</var>, you can reach Obs. <var>3</var> using just one road. The elevation of Obs. <var>1</var> is not higher than that of Obs. <var>3</var>, so Obs. <var>1</var> is not good.</p> </li> <li> <p>From Obs. <var>2</var>, you can reach Obs. <var>3</var> and <var>4</var> using just one road. The elevation of Obs. <var>2</var> is not higher than that of Obs. <var>3</var>, so Obs. <var>2</var> is not good.</p> </li> <li> <p>From Obs. <var>3</var>, you can reach Obs. <var>1</var> and <var>2</var> using just one road. The elevation of Obs. <var>3</var> is higher than those of Obs. <var>1</var> and <var>2</var>, so Obs. <var>3</var> is good.</p> </li> <li> <p>From Obs. <var>4</var>, you can reach Obs. <var>2</var> using just one road. The elevation of Obs. <var>4</var> is higher than that of Obs. <var>2</var>, so Obs. <var>4</var> is good.</p> </li> </ul> <p>Thus, the good observatories are Obs. <var>3</var> and <var>4</var>, so there are two good observatories.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 5 8 6 9 1 2 1 1 3 4 2 4 3 4 6 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre></section> </div> </span>
p02373
<H1>LCA: Lowest Common Ancestor</H1> <p> For a rooted tree, find the lowest common ancestor of two nodes <var>u</var> and <var>v</var>. </p> <p> The given tree consists of <var>n</var> nodes and every node has a unique ID from 0 to <var>n</var>-1 where 0 is the root. </p> <H2>Input</H2> <pre> <var>n</var> <var>k<sub>0</sub></var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>k<sub>0</sub></sub></var> <var>k<sub>1</sub></var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>k<sub>1</sub></sub></var> : <var>k<sub>n-1</sub></var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>k<sub>n-1</sub></sub></var> <var>q</var> <var>u<sub>1</sub></var> <var>v<sub>1</sub></var> <var>u<sub>2</sub></var> <var>v<sub>2</sub></var> : <var>u<sub>q</sub></var> <var>v<sub>q</sub></var> </pre> <p> The first line of the input includes an integer <var>n</var>, the number of nodes of the tree. </p> <p> In the next <var>n</var> lines, the information of node <var>i</var> is given. <var>k<sub>i</sub></var> is the number of children of node <var>i</var>, and <var>c<sub>1</sub></var>, ... <var>c<sub>k<sub>i</sub></sub></var> are node IDs of 1st, ... <var>k</var>th child of node <var>i</var>. </P> <p> In the next line, the number of queryies <var>q</var> is given. In the next <var>q</var> lines, pairs of <var>u</var> and <var>v</var> are given as the queries. </p> <H2>Output</H2> <p> For each query, print the LCA of <var>u</var> and <var>v</var> in a line. </p> <H2>Constraints</H2> <ul> <li> <var>1 &le; n &le; 100000</var> </li> <li> <var>1 &le; q &le; 100000</var> </li> </ul> <H2>Sample Input 1</H2> <pre> 8 3 1 2 3 2 4 5 0 0 0 2 6 7 0 0 4 4 6 4 7 4 3 5 2 </pre> <H2>Sample Output 1</H2> <pre> 1 1 0 0 </pre>
p02723
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A string of length <var>6</var> consisting of lowercase English letters is said to be coffee-like if and only if its <var>3</var>-rd and <var>4</var>-th characters are equal and its <var>5</var>-th and <var>6</var>-th characters are also equal.<br/> Given a string <var>S</var>, determine whether it is coffee-like.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is a string of length <var>6</var> 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>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>S</var> is coffee-like, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>sippuu </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>In <code>sippuu</code>, the <var>3</var>-rd and <var>4</var>-th characters are equal, and the <var>5</var>-th and <var>6</var>-th characters are also equal.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>iphone </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>coffee </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
p03831
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> towns on a line running east-west. The towns are numbered <var>1</var> through <var>N</var>, in order from west to east. Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town <var>i</var> is <var>X_i</var>.</p> <p>You are now at town <var>1</var>, and you want to visit all the other towns. You have two ways to travel:</p> <ul> <li> <p>Walk on the line. Your <em>fatigue level</em> increases by <var>A</var> each time you travel a distance of <var>1</var>, regardless of direction.</p> </li> <li> <p>Teleport to any location of your choice. Your fatigue level increases by <var>B</var>, regardless of the distance covered.</p> </li> </ul> <p>Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>2≤N≤10^5</var></li> <li><var>1≤X_i≤10^9</var></li> <li>For all <var>i(1≤i≤N-1)</var>, <var>X_i&lt;X_{i+1}</var>.</li> <li><var>1≤A≤10^9</var></li> <li><var>1≤B≤10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible total increase of your fatigue level when you visit all the towns.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 5 1 2 5 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>11 </pre> <p>From town <var>1</var>, walk a distance of <var>1</var> to town <var>2</var>, then teleport to town <var>3</var>, then walk a distance of <var>2</var> to town <var>4</var>. The total increase of your fatigue level in this case is <var>2×1+5+2×2=11</var>, which is the minimum possible value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 1 100 40 43 45 105 108 115 124 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>84 </pre> <p>From town <var>1</var>, walk all the way to town <var>7</var>. The total increase of your fatigue level in this case is <var>84</var>, which is the minimum possible value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 2 24 35 40 68 72 99 103 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>12 </pre> <p>Visit all the towns in any order by teleporting six times. The total increase of your fatigue level in this case is <var>12</var>, which is the minimum possible value.</p></section> </div> </span>
p03098
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For two permutations <var>p</var> and <var>q</var> of the integers from <var>1</var> through <var>N</var>, let <var>f(p,q)</var> be the permutation that satisfies the following:</p> <ul> <li>The <var>p_i</var>-th element (<var>1 \leq i \leq N</var>) in <var>f(p,q)</var> is <var>q_i</var>. Here, <var>p_i</var> and <var>q_i</var> respectively denote the <var>i</var>-th element in <var>p</var> and <var>q</var>.</li> </ul> <p>You are given two permutations <var>p</var> and <var>q</var> of the integers from <var>1</var> through <var>N</var>. We will now define a sequence {<var>a_n</var>} of permutations of the integers from <var>1</var> through <var>N</var>, as follows:</p> <ul> <li><var>a_1=p</var>, <var>a_2=q</var></li> <li><var>a_{n+2}=f(a_n,a_{n+1})</var> ( <var>n \geq 1</var> )</li> </ul> <p>Given a positive integer <var>K</var>, find <var>a_K</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq K \leq 10^9</var></li> <li><var>p</var> and <var>q</var> are permutations of the integers from <var>1</var> through <var>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>p_1</var> <var>...</var> <var>p_N</var> <var>q_1</var> <var>...</var> <var>q_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> integers, with spaces in between. The <var>i</var>-th integer (<var>1 \leq i \leq N</var>) should be the <var>i</var>-th element in <var>a_K</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 3 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 2 1 </pre> <p>Since <var>a_3=f(p,q)</var>, we just need to find <var>f(p,q)</var>. We have <var>p_i=i</var> here, so <var>f(p,q)=q</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 4 5 1 2 3 3 2 1 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 3 2 1 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1000000000 7 10 6 5 4 2 9 1 3 8 4 1 9 2 3 7 8 10 6 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7 9 4 8 2 5 1 6 10 3 </pre></section> </div> </span>
p03562
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> non-negative integers written on a blackboard. The <var>i</var>-th integer is <var>A_i</var>.</p> <p>Takahashi can perform the following two kinds of operations any number of times in any order:</p> <ul> <li>Select one integer written on the board (let this integer be <var>X</var>). Write <var>2X</var> on the board, without erasing the selected integer.</li> <li>Select two integers, possibly the same, written on the board (let these integers be <var>X</var> and <var>Y</var>). Write <var>X</var> XOR <var>Y</var> (XOR stands for bitwise xor) on the blackboard, without erasing the selected integers.</li> </ul> <p>How many different integers not exceeding <var>X</var> can be written on the blackboard? We will also count the integers that are initially written on the board. Since the answer can be extremely large, find the count modulo <var>998244353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 6</var></li> <li><var>1 \leq X &lt; 2^{4000}</var></li> <li><var>1 \leq A_i &lt; 2^{4000}(1\leq i\leq N)</var></li> <li>All input values are integers.</li> <li><var>X</var> and <var>A_i(1\leq i\leq N)</var> are given in binary notation, with the most significant digit in each of them being <var>1</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> <var>A_1</var> <var>:</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of different integers not exceeding <var>X</var> that can be written on the blackboard.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 111 1111 10111 10010 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>Initially, <var>15</var>, <var>23</var> and <var>18</var> are written on the blackboard. Among the integers not exceeding <var>7</var>, four integers, <var>0</var>, <var>3</var>, <var>5</var> and <var>6</var>, can be written. For example, <var>6</var> can be written as follows:</p> <ul> <li>Double <var>15</var> to write <var>30</var>.</li> <li>Take XOR of <var>30</var> and <var>18</var> to write <var>12</var>.</li> <li>Double <var>12</var> to write <var>24</var>.</li> <li>Take XOR of <var>30</var> and <var>24</var> to write <var>6</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 100100 1011 1110 110101 1010110 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>37 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 111001100101001 10111110 1001000110 100000101 11110000011 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1843 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 111111111111111111111111111111111111111111111111111111111111111 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>466025955 </pre> <p>Be sure to find the count modulo <var>998244353</var>.</p></section> </div> </span>
p03132
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke stands on a number line. He has <var>L</var> ears, and he will walk along the line continuously under the following conditions:</p> <ul> <li>He never visits a point with coordinate less than <var>0</var>, or a point with coordinate greater than <var>L</var>.</li> <li>He starts walking at a point with integer coordinate, and also finishes walking at a point with integer coordinate.</li> <li>He only changes direction at a point with integer coordinate.</li> </ul> <p>Each time when Snuke passes a point with coordinate <var>i-0.5</var>, where <var>i</var> is an integer, he put a stone in his <var>i</var>-th ear.</p> <p>After Snuke finishes walking, Ringo will repeat the following operations in some order so that, for each <var>i</var>, Snuke's <var>i</var>-th ear contains <var>A_i</var> stones:</p> <ul> <li>Put a stone in one of Snuke's ears.</li> <li>Remove a stone from one of Snuke's ears.</li> </ul> <p>Find the minimum number of operations required when Ringo can freely decide how Snuke walks.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq L \leq 2\times 10^5</var></li> <li><var>0 \leq A_i \leq 10^9(1\leq i\leq L)</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>L</var> <var>A_1</var> <var>:</var> <var>A_L</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required when Ringo can freely decide how Snuke walks.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 0 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Assume that Snuke walks as follows:</p> <ul> <li>He starts walking at coordinate <var>3</var> and finishes walking at coordinate <var>4</var>, visiting coordinates <var>3,4,3,2,3,4</var> in this order.</li> </ul> <p>Then, Snuke's four ears will contain <var>0,0,2,3</var> stones, respectively. Ringo can satisfy the requirement by putting one stone in the first ear.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 2 0 0 2 1 3 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 314159265 358979323 846264338 327950288 419716939 937510582 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre></section> </div> </span>
p00437
<H1>品質検査</H1> <h2>問題</h2> <p> あなたはある機械の製造工場で品質管理の責任者をしている. この機械には, 部品として電源とモーターとケーブルが必要である. 製造工場には電源が a 個, モーターが b 個, ケーブルが c 個あり, それぞれ 1 から a まで, a+1 から a+b まで, a+b+1 から a+b+c までの番号が付いている. 困ったことに, 部品の中に故障しているものがあるかもしれない. 工場ではどの部品が故障していてどの部品が正常であるかを知りたい. </p> <p> そこで, 工場では次の方法で部品を検査した. 電源とモーターとケーブルを1つずつ持ってきてつなぎ, 動作させてみる. このとき, 3つの部品がすべて正常であるときは正しく動作して「合格」とわかる. 3つの中に故障している部品が1つでも入っているときは正しく動作しないので「不合格」とわかる. (工場で作っている機械はとても精密なので, 故障した部品がまざっているのに偶然正しく動作してしまうなどということは起きないのだ.) </p> <p> あなたには検査結果のリストが渡される. 検査結果のリストの各行には, 検査に使った電源とモーターとケーブルの番号と, 検査が合格だったか不合格だったかが書かれている. </p> <p> 検査結果のリストが与えられたとき, すべての部品を, 検査結果から確実に故障しているとわかる部品と, 確実に正常とわかる部品と, 検査結果からは故障しているとも正常であるとも決まらない部品に分類するプログラムを作成せよ. </p> <H2>入力</H2> <p> <!--入力ファイルの形式は以下の通りである.--> 入力は複数のデータセットからなる.各データセットの形式は以下の通りである.入力は3つのゼロを含む行で終了する. </p> <p> 1 行目には 3 個の整数が空白区切りで書かれており, 順に電源の個数 a, モーターの個数 b, ケーブルの個数 c を表す. </p> <p> 2 行目には 1 個の整数が書かれており, 検査結果のリストに含まれる検査の回数 N が書かれている. </p> <p> 続く N 行は検査結果のリストを表す. 各行には, 4 個の整数 i, j, k, r が1つの空白を区切りとして書かれており, 電源 i とモーター j とケーブル k をつないで検査した結果が, 「合格」 (r=1 のとき) か「不合格」 (r=0 のとき) だったことを表す. </p> <p> a, b, c, N は 1 &le; a, b, c &le; 100, 1 &le; N &le; 1000 を満たす. </p> <p> データセットの数は 5 を超えない. </p> <H2>出力</H2> <p> <!--提出する出力ファイルは以下の通りである.出力ファイルは a+b+c 行からなる.--> データセットごとに以下の形式で出力する.各データセットの出力は a+b+c 行からなる. </p> <p> i 行目 (1 &le; i &le; a+b+c): </p> <ul> <li> 検査結果から部品 i が故障しているとわかる場合は 0 を出力する.</li> <li> 検査結果から部品 i が正常とわかる場合は 1 を出力する.</li> <li> 検査結果から部品 i が故障しているか正常であるかが決まらない場合は 2 を出力する.</li> </ul> <h2>入出力例</h2> <!-- <table style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px;"> <tr> <th width="150" align="left">入力例</th> </tr> <tr><td></td><td></td></tr> <tr><td>2 2 2 </td></tr> <tr><td>4 </td></tr> <tr><td>2 4 5 0 </td></tr> <tr><td>2 3 6 0 </td></tr> <tr><td>1 4 5 0 </td></tr> <tr><td>2 3 5 1 </td></tr> <tr> <td> </td> </tr> <tr> <th width="150" align="left">出力例</th> </tr> <tr><td>2 </td></tr> <tr><td>1 </td></tr> <tr><td>1 </td></tr> <tr><td>0 </td></tr> <tr><td>1 </td></tr> <tr><td>0 </td></tr> </table> --> <h3>入力例</h3> <pre> 2 2 2 4 2 4 5 0 2 3 6 0 1 4 5 0 2 3 5 1 0 0 0 </pre> <h3>出力例</h3> <pre> 2 1 1 0 1 0 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p00067
<H1>島の数</H1> <p> 地勢を示す縦 12, 横 12 のマスからなる平面図があります。おのおののマスは白か黒に塗られています。白は海を、黒は陸地を表します。二つの黒いマスが上下、あるいは左右に接しているとき、これらは地続きであるといいます。この平面図では、黒いマス一つのみ、あるいは地続きの黒いマスが作る領域を「島」といいます。例えば下図には、5 つの島があります。 </p> <pre> ■■■■□□□□■■■■ ■■■□□□□□■■■■ ■■□□□□□□■■■■ ■□□□□□□□■■■■ □□□■□□□■□□□□ □□□□□□■■■□□□ □□□□□■■■■■□□ ■□□□■■■■■■■□ ■■□□□■■■■■□□ ■■■□□□■■■□□□ ■■■■□□□■□□□□ □□□□□□□□□□□□ </pre> <p> マスのデータを読み込んで、島の数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットに1つの平面図が与えられます。黒いマスを 1、白いマスを 0 で表現した 12 個の数字の列 12 行でひとつの平面図を表します。データセットの間は1つの空行で区切られています。 </p> <p> データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、島の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 111100001111 111000001111 110000001111 100000001111 000100010000 000000111000 000001111100 100011111110 110001111100 111000111000 111100010000 000000000000 010001111100 110010000010 010010000001 010000000001 010000000110 010000111000 010000000100 010000000010 010000000001 010010000001 010010000010 111001111100 000000000000 111111111111 100010100001 100010100001 100010100001 100010100001 100100100101 101000011101 100000000001 100000000001 111111111111 100000000001 </pre> <H2>Output for the Sample Input</H2> <pre> 5 13 4 </pre> <H2>Hint</H2> <p> 以下はサンプルインプットを■と□で表したものです。 <pre> ■■■■□□□□■■■■  □■□□□■■■■■□□  □□□□□□□□□□□□ ■■■□□□□□■■■■  ■■□□■□□□□□■□  ■■■■■■■■■■■■ ■■□□□□□□■■■■  □■□□■□□□□□□■  ■□□□■□■□□□□■ ■□□□□□□□■■■■  □■□□□□□□□□□■  ■□□□■□■□□□□■ □□□■□□□■□□□□  □■□□□□□□□■■□  ■□□□■□■□□□□■ □□□□□□■■■□□□  □■□□□□■■■□□□  ■□□□■□■□□□□■ □□□□□■■■■■□□  □■□□□□□□□■□□  ■□□■□□■□□■□■ ■□□□■■■■■■■□  □■□□□□□□□□■□  ■□■□□□□■■■□■ ■■□□□■■■■■□□  □■□□□□□□□□□■  ■□□□□□□□□□□■ ■■■□□□■■■□□□  □■□□■□□□□□□■  ■□□□□□□□□□□■ ■■■■□□□■□□□□  □■□□■□□□□□■□  ■■■■■■■■■■■■ □□□□□□□□□□□□  ■■■□□■■■■■□□  ■□□□□□□□□□□■ </pre> </p>
p04024
<span class="lang-en"> <p>Score : <var>1700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a grid from his mother, as a birthday present. The grid has <var>H</var> rows and <var>W</var> columns. Each cell is painted black or white. All black cells are <em>4-connected</em>, that is, it is possible to traverse from any black cell to any other black cell by just visiting black cells, where it is only allowed to move horizontally or vertically.</p> <p>The color of the cell at the <var>i</var>-th row and <var>j</var>-th column <var>(1 ≦ i ≦ H, 1 ≦ j ≦ W)</var> is represented by a character <var>s_{ij}</var>. If <var>s_{ij}</var> is <code>#</code>, the cell is painted black. If <var>s_{ij}</var> is <code>.</code>, the cell is painted white. At least one cell is painted black.</p> <p>We will define <em>fractals</em> as follows. The fractal of <em>level</em> <var>0</var> is a <var>1 × 1</var> grid with a black cell. The fractal of level <var>k+1</var> is obtained by arranging smaller grids in <var>H</var> rows and <var>W</var> columns, following the pattern of the Snuke's grid. At a position that corresponds to a black cell in the Snuke's grid, a copy of the fractal of level <var>k</var> is placed. At a position that corresponds to a white cell in the Snuke's grid, a grid whose cells are all white, with the same dimensions as the fractal of level <var>k</var>, is placed.</p> <p>You are given the description of the Snuke's grid, and an integer <var>K</var>. Find the number of connected components of black cells in the fractal of level <var>K</var>, modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≦ H,W ≦ 1000</var></li> <li><var>0 ≦ K ≦ 10^{18}</var></li> <li>Each <var>s_{ij}</var> is either <code>#</code> or <code>.</code>.</li> <li>All black cells in the given grid are 4-connected.</li> <li>There is at least one black cell in the given grid.</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>H</var> <var>W</var> <var>K</var> <var>s_{11} .. s_{1W}</var> : <var>s_{H1} .. s_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of connected components of black cells in the fractal of level <var>K</var>, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 3 .#. ### #.# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>20 </pre> <p>The fractal of level <var>K=3</var> in this case is shown below. There are <var>20</var> connected components of black cells.</p> <pre> .............#............. ............###............ ............#.#............ ..........#..#..#.......... .........#########......... .........#.##.##.#......... ..........#.....#.......... .........###...###......... .........#.#...#.#......... ....#........#........#.... ...###......###......###... ...#.#......#.#......#.#... .#..#..#..#..#..#..#..#..#. ########################### #.##.##.##.##.##.##.##.##.# .#.....#..#.....#..#.....#. ###...######...######...### #.#...#.##.#...#.##.#...#.# ....#.................#.... ...###...............###... ...#.#...............#.#... .#..#..#...........#..#..#. #########.........######### #.##.##.#.........#.##.##.# .#.....#...........#.....#. ###...###.........###...### #.#...#.#.........#.#...#.# </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 3 ### #.# ### </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>11 15 1000000000000000000 .....#......... ....###........ ....####....... ...######...... ...#######..... ..##.###.##.... ..##########... .###.....####.. .####...######. ############### #.##..##..##..# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>301811921 </pre></section> </div> </span>
p01226
<h1><font color="#000">Problem D:</font>バトルタウン</h1> <p> あなたは友人たちとゲームを開発することにした. ゲームのタイトルは「バトルタウン」. 戦車による市街戦をテーマにしたゲームだ. ゲーム開発の第一歩として,次のようなプロトタイプを開発することにした. </p> <p> このプロトタイプでは,登場する戦車はプレイヤーの戦車のみであり, 敵の戦車は登場しない. プレイヤーの戦車はプレイヤーの入力に従ってマップ上で様々な動作をする. 以下に,戦車の動作に関する仕様を述べる. </p> <p> マップの構成要素は表1の通りである. 戦車が移動できるのはマップ内の平地の上だけである. </p> <center> <table border="1"> <caption>表1: マップの構成要素</caption> <thead> <tr><th style="width:80px">文字</th><th>要素</th></tr> </thead> <tbody> <tr><td><code>.</code></td><td>平地</td></tr> <tr><td><code>*</code></td><td>レンガの壁</td></tr> <tr><td><code>#</code></td><td>鉄の壁</td></tr> <tr><td><code>-</code></td><td>水</td></tr> <tr><td><code>^</code></td><td>戦車(上向き)</td></tr> <tr><td><code>v</code></td><td>戦車(下向き)</td></tr> <tr><td><code>&lt;</code></td><td>戦車(左向き)</td></tr> <tr><td><code>&gt;</code></td><td>戦車(右向き)</td></tr> </tbody> </table> </center> <p> プレイヤーの入力は文字の列で与えられる. 各文字に対応する動作は表2の通りである. </p> <center> <table border="1"> <caption>表2: プレイヤーの入力に対する動作</caption> <thead> <tr><th>文字</th><th>動作</th></tr> </thead> <tbody> <tr> <td><code>U</code></td> <td>Up: 戦車を上向きに方向転換し,さらに一つ上のマスが平地ならばそのマスに移動する</td> </tr> <tr> <td><code>D</code></td> <td>Down: 戦車を下向きに方向転換し,さらに一つ下のマスが平地ならばそのマスに移動する</td> </tr> <tr> <td><code>L</code></td> <td>Left: 戦車を左向きに方向転換し,さらに一つ左のマスが平地ならばそのマスに移動する</td> </tr> <tr> <td><code>R</code></td> <td>Right: 戦車を右向きに方向転換し,さらに一つ右のマスが平地ならばそのマスに移動する</td> </tr> <tr> <td><code>S</code></td> <td>Shoot: 戦車が現在向いている方向に砲弾を発射する</td> </tr> </tbody> </table> </center> <p> 砲弾はレンガの壁あるいは鉄の壁にぶつかるか,マップの外に出るまで直進する. レンガの壁にぶつかった場合は,砲弾は消滅し,レンガの壁は平地に変化する. 鉄の壁にぶつかった場合は,砲弾は消滅するが,鉄の壁は変化しない. マップの外に出たときは砲弾はそのまま消滅する. </p> <p> あなたの仕事は,初期マップとプレイヤーの入力操作列が与えられたときに, 最終的なマップの状態を出力するプログラムを作成することである. </p> <h2>Input</h2> <p> 入力の1行目にはデータセット数を表す数 <var>T</var> (0 &lt; <var>T</var> &le; 100) が与えられる. この行に引き続き <var>T</var> 個のデータセットが与えられる. </p> <p> 各データセットの1行目にはマップの高さと幅を表す整数 <var>H</var> と <var>W</var> が 1つの空白文字で区切られて与えられる. これらの整数は 2 &le; <var>H</var> &le; 20, 2 &le; <var>W</var> &le; 20 を満たす. 続く <var>H</var> 行はマップの初期状態を表す. 各行は長さ <var>W</var> の文字列である. マップに含まれる文字はすべて表1で定義されたものであり, 全体でちょうど1つの戦車を含む. マップに続く行には入力操作列の長さ <var>N</var> (0 &lt; <var>N</var> &le; 100) が与えられ, 次の行には入力操作列を表す長さ <var>N</var> の文字列が与えられる. 入力操作列は表2で定義された文字のみからなる文字列である. </p> <h2>Output</h2> <p> 各データセットに対し,すべての入力操作を終えた後のマップを, 入力マップと同じ形式で出力せよ. データセットの間には1行の空行を出力せよ. 最後のデータセットの後に余計な空行を出力しないよう注意すること. </p> <h2>Sample Input</h2> <pre> 4 4 6 *.*..* *..... ..-... ^.*#.. 10 SRSSRRUSSR 2 2 &lt;. .. 12 DDSRRSUUSLLS 3 5 &gt;-#** .-*#* .-**# 15 SSSDRSSSDRSSSUU 5 5 v**** ***** ***** ***** ***** 44 SSSSDDRSDRSRDSULUURSSSSRRRRDSSSSDDLSDLSDLSSD </pre> <h2>Output for the Sample Input</h2> <pre> *....* ...... ..-... ..&gt;#.. &lt;. .. ^-#** .-.#* .-..# ..... .***. ..*.. ..*.. ....v </pre>
p00964
<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 H Homework </h2> <p> Taro is a student of Ibaraki College of Prominent Computing. In this semester, he takes two courses, mathematics and informatics. After each class, the teacher may assign homework. Taro may be given multiple assignments in a single class, and each assignment may have a different deadline. Each assignment has a unique ID number. </p> <p> Everyday after school, Taro completes at most one assignment as follows. First, he decides which course's homework to do at random by ipping a coin. Let $S$ be the set of all the unfinished assignments of the chosen course whose deadline has not yet passed. If $S$ is empty, he plays a video game without doing any homework on that day even if there are unfinished assignments of the other course. Otherwise, with $T \subseteq S$ being the set of assignments with the nearest deadline among $S$, he completes the one with the smallest assignment ID among $T$. </p> <p> The number of assignments Taro will complete until the end of the semester depends on the result of coin ips. Given the schedule of homework assignments, your task is to compute the maximum and the minimum numbers of assignments Taro will complete. </p> <h3>Input</h3> <p> The input consists of a single test case in the following format. </p> <pre> $n$ $m$ $s_1$ $t_1$ ... $s_n$ $t_n$ </pre> <p> The first line contains two integers $n$ and $m$ satisfying $1 \leq m < n \leq 400$. $n$ denotes the total number of assignments in this semester, and $m$ denotes the number of assignments of the mathematics course (so the number of assignments of the informatics course is $n - m$). Each assignment has a unique ID from $1$ to $n$; assignments with IDs $1$ through $m$ are those of the mathematics course, and the rest are of the informatics course. The next $n$ lines show the schedule of assignments. The $i$-th line of them contains two integers $s_i$ and $t_i$ satisfying $1 \leq s_i \leq t_i \leq 400$, which means that the assignment of ID $i$ is given to Taro on the $s_i$-th day of the semester, and its deadline is the end of the $t_i$-th day. </p> <h3>Output</h3> <p> In the first line, print the maximum number of assignments Taro will complete. In the second line, print the minimum number of assignments Taro will complete. </p> <h3>Sample Input 1</h3> <pre> 6 3 1 2 1 5 2 3 2 6 4 5 4 6 </pre> <h3>Sample Output 1</h3> <pre> 6 2 </pre> <h3>Sample Input 2</h3> <pre> 6 3 1 1 2 3 4 4 1 1 2 4 3 3 </pre> <h3>Sample Output 2</h3> <pre> 4 3 </pre>
p02959
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N+1</var> towns. The <var>i</var>-th town is being attacked by <var>A_i</var> monsters.</p> <p>We have <var>N</var> heroes. The <var>i</var>-th hero can defeat monsters attacking the <var>i</var>-th or <var>(i+1)</var>-th town, for a total of at most <var>B_i</var> monsters.</p> <p>What is the maximum total number of monsters the heroes can cooperate to defeat?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>1 \leq B_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+1}</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>Print the maximum total number of monsters the heroes can defeat.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 5 2 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>If the heroes choose the monsters to defeat as follows, they can defeat nine monsters in total, which is the maximum result.</p> <ul> <li>The first hero defeats two monsters attacking the first town and two monsters attacking the second town.</li> <li>The second hero defeats three monsters attacking the second town and two monsters attacking the third town.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 6 3 8 5 100 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>22 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 100 1 1 1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p01676
<h2>J - Tree Reconstruction</h2> <h3>Problem Statement</h3> <p> You have a directed graph. Some non-negative value is assigned on each edge of the graph. You know that the value of the graph satisfies the <em>flow conservation law</em> That is, for every node <var>v</var>, the sum of values on edges incoming to <var>v</var> equals to the sum of values of edges outgoing from <var>v</var>. For example, the following directed graph satisfies the flow conservation law. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_tree_reconstruction_flow3" width="201" height="261" /> </center><br> <p> Suppose that you choose a subset of edges in the graph, denoted by <var>E'</var>, and then you erase all the values on edges other than <var>E'</var>. Now you want to recover the erased values by seeing only remaining information. Due to the flow conservation law, it may be possible to recover all the erased values. Your task is to calculate the smallest possible size for such <var>E'</var>. </p> <p> For example, the smallest subset <var>E'</var> for the above graph will be green edges in the following figure. By the flow conservation law, we can recover values on gray edges. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_tree_reconstruction_flow4" width="201" height="261" style="align:center" /> </center><br> <h3>Input</h3> <p> The input consists of multiple test cases. The format of each test case is as follows. </p> <pre> <var>N</var> <var>M</var> <var>s_1</var> <var>t_1</var> ... <var>s_M</var> <var>t_M</var> </pre> <p> The first line contains two integers <var>N</var> (<var>1 \leq N \leq 500</var>) and <var>M</var> (<var>0 \leq M \leq 3,000</var>) that indicate the number of nodes and edges, respectively. Each of the following <var>M</var> lines consists of two integers <var>s_i</var> and <var>t_i</var> (<var>1 \leq s_i, t_i \leq N</var>). This means that there is an edge from <var>s_i</var> to <var>t_i</var> in the graph. </p> <p> You may assume that the given graph is simple: </p> <ul> <li>There are no self-loops: <var>s_i \neq t_i</var>.</li> <li>There are no multi-edges: for all <var>i < j</var>, <var>\{s_i, t_i\} \neq \{s_j, t_j\}</var>.</li> </ul> <p> Also, it is guaranteed that each component of the given graph is strongly connected. That is, for every pair of nodes <var>v</var> and <var>u</var>, if there exist a path from <var>v</var> to <var>u</var>, then there exists a path from <var>u</var> to <var>v</var>. </p> <p> Note that you are NOT given information of values on edges because it does not effect the answer. </p> <h3>Output</h3> <p> For each test case, print an answer in one line. </p> <h3>Sample Input 1</h3> <pre> 9 13 1 2 1 3 2 9 3 4 3 5 3 6 4 9 5 7 6 7 6 8 7 9 8 9 9 1 </pre> <h3>Output for the Sample Input 1</h3> <pre> 5 </pre> <h3>Sample Input 2</h3> <pre> 7 9 1 2 1 3 2 4 3 4 4 5 4 6 5 7 6 7 7 1 </pre> <h3>Output for the Sample Input 2</h3> <pre> 3 </pre> <h3>Sample Input 3</h3> <pre> 4 4 1 2 2 1 3 4 4 3 </pre> <h3>Output for the Sample Input 3</h3> <pre> 2 </pre>
p01363
<H1><font color="#000">Problem E:</font> Alice and Bomb</H1> <p> Alice and Bob were in love with each other, but they hate each other now. </p> <p> One day, Alice found a bag. It looks like a bag that Bob had used when they go on a date. Suddenly Alice heard tick-tack sound. Alice intuitively thought that Bob is to kill her with a bomb. Fortunately, the bomb has not exploded yet, and there may be a little time remained to hide behind the buildings. </p> <p> The appearance of the ACM city can be viewed as an infinite plane and each building forms a polygon. Alice is considered as a point and the bomb blast may reach Alice if the line segment which connects Alice and the bomb does not intersect an interior position of any building. Assume that the speed of bomb blast is infinite; when the bomb explodes, its blast wave will reach anywhere immediately, unless the bomb blast is interrupted by some buildings. </p> <p> The figure below shows the example of the bomb explosion. Left figure shows the bomb and the buildings(the polygons filled with black). Right figure shows the area(colored with gray) which is under the effect of blast wave after the bomb explosion. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_aliceAndBomb" width="50%"> <p> Figure 6: The example of the bomb explosion </p> </center> <p> Note that even if the line segment connecting Alice and the bomb touches a border of a building, bomb blast still can blow off Alice. Since Alice wants to escape early, she wants to minimize the length she runs in order to make herself hidden by the building. </p> <p> Your task is to write a program which reads the positions of Alice, the bomb and the buildings and calculate the minimum distance required for Alice to run and hide behind the building. </p> <H2>Input</H2> <p> The input contains multiple test cases. Each test case has the following format: </p> <p> <i>N</i><br> <i>bx by</i><br> <i>m</i><sub>1</sub> <i>x</i><sub>1,1</sub> <i>y</i><sub>1,1</sub> ... <i>x</i><sub>1,<i>m</i><sub>1</sub></sub> <i>y</i><sub>1,<i>m</i><sub>1</sub></sub><br> .<br> .<br> .<br> <i>m</i><sub><i>N</i></sub> <i>x</i><sub><i>N</i>,1</sub> <i>y</i><sub><i>N</i>,1</sub> ... <i>x</i><sub><i>N</i>,<i>m</i><sub><i>N</i></sub></sub> <i>y</i><sub><i>N</i>,<i>m</i><sub><i>N</i></sub></sub><br> </p> <p> The first line of each test case contains an integer <i>N</i> (1 &le; <i>N</i> &le; 100), which denotes the number of buildings. In the second line, there are two integers <i>bx</i> and <i>by</i> (-10000 &le; <i>bx</i>, <i>by</i> &le; 10000), which means the location of the bomb. Then, <i>N</i> lines follows, indicating the information of the buildings. </p> <p> The information of building is given as a polygon which consists of points. For each line, it has an integer <i>m<sub>i</sub></i> (3 &le; <i>m<sub>i</sub></i> &le; 100, &sum;<sup><i>N</i></sup><sub><i>i</i>=1</sub> <i>m<sub>i</sub></i> &le; 500) meaning the number of points the polygon has, and then <i>m<sub>i</sub></i> pairs of integers <i>x<sub>i,j</sub></i>, <i>y<sub>i,j</sub></i> follow providing the x and y coordinate of the point. </p> <p> You can assume that </p> <ul> <li> the polygon does not have self-intersections. </li> <li> any two polygons do not have a common point.</li> <li> the set of points is given in the counter-clockwise order.</li> <li> the initial positions of Alice and bomb will not by located inside the polygon.</li> <li> there are no bomb on the any extended lines of the given polygon’s segment.</li> </ul> <p> Alice is initially located at (0, 0). It is possible that Alice is located at the boundary of a polygon. </p> <p> N = 0 denotes the end of the input. You may not process this as a test case. </p> <H2>Output</H2> <p> For each test case, output one line which consists of the minimum distance required for Alice to run and hide behind the building. An absolute error or relative error in your answer must be less than 10<sup>-6</sup>. </p> <H2>Sample Input</H2> <pre> 1 1 1 4 -1 0 -2 -1 -1 -2 0 -1 1 0 3 4 1 1 1 2 -1 2 -1 1 1 -6 -6 6 1 -2 2 -2 2 3 -2 3 -2 1 1 1 1 -10 0 4 0 -5 1 -5 1 5 0 5 1 10 1 4 5 1 6 2 5 3 4 2 2 -47 -37 4 14 3 20 13 9 12 15 9 4 -38 -3 -34 -19 -34 -14 -24 -10 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1.00000000 0.00000000 3.23606798 5.00000000 1.00000000 11.78517297 </pre>
p01699
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <!-- begin en only --> <!--<h3><u>Elevator Hall Number</u></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><u>エレベーターホール・ナンバー</u></h3> <!-- end ja only --> <!-- begin en only --> <!-- end en only --> <!-- begin ja only --> <p>JAG (Japanese Alumni Group) は東京都某所のとある高層ビルに本部を置く謎の組織である. このビルでは $N$ 台のエレベーターが動いており,$i$ 台目のエレベーターは $low_i$ 階から $high_i$ 階までの各階に停まる ($1 \le i \le N$). </p> <p>JAG の新スタッフである X 氏は,本部を訪れようとビルのエレベーターホールまで辿り着いた. そこでボタンを押してエレベーターを待っていた X 氏は,エレベーターが現在いる階の表示が少々変わっていることに気づいた. $i$ 台目のエレベーターが $a_i$ 階にいるとき,$a_1, a_2, \ldots, a_N$ をこの順に並べて,十進表記で・先頭に 0 を加えず・空白を挟まずに繋げて書いた 1 つの数がディスプレイに映されるのである. 例えば,$N = 3$ で,エレベーターが順に $10$ 階,$2$ 階,$11$ 階にいるとき,$10211$ が表示される. </p> <p>X 氏は,ディスプレイに映される可能性がある数は全部で何通りあるかが気になってしまった. あなたの課題は,それを求めるプログラムを作成することである. </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は複数のデータセットからなり,各データセットは以下の形をしている. </p> <blockquote>$N$<br>$low_1$ $high_1$<br>...<br>$low_N$ $high_N$</blockquote> <p>データセットの最初の行は,エレベーターの台数を表す整数 $N$ ($2 \le N \le 6$) からなる. 続く $N$ 行のうち $i$ 行目は,$2$ 個の整数 $low_i$, $high_i$ ($1 \le low_i \le high_i \le 99$) からなり,$i$ 台目のエレベーターが動く範囲を表す. </p> <p>入力の終わりは,ゼロを $1$ 個だけ含む行で表される. </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各データセットに対して,ディスプレイに映される可能性がある数の個数を $1$ 行で出力せよ. </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>2 1 11 1 11 3 10 10 2 2 11 11 4 89 91 1 12 1 12 89 91 5 1 8 2 76 10 19 6 16 33 42 6 10 59 20 69 30 79 40 89 50 99 50 99 0</pre> <h3>Output for Sample Input</h3> <pre>120 1 1278 659520 15625000000</pre>
p00821
<H1><font color="#000">Problem C:</font> Area of Polygons</H1> <p> Yoko’s math homework today was to calculate areas of polygons in the <i>xy</i>-plane. Vertices are all aligned to grid points (i.e. they have integer coordinates). </p> <p> Your job is to help Yoko, not good either at math or at computer programming, get her home- work done. A polygon is given by listing the coordinates of its vertices. Your program should approximate its area by counting the number of unit squares (whose vertices are also grid points) intersecting the polygon. Precisely, a unit square “intersects the polygon” if and only if the in- tersection of the two has non-zero area. In the figure below, dashed horizontal and vertical lines are grid lines, and solid lines are edges of the polygon. Shaded unit squares are considered inter- secting the polygon. Your program should output 55 for this polygon (as you see, the number of shaded unit squares is 55). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_areaOfPolygon"><br> <p>Figure 1: A polygon and unit squares intersecting it</p> </center> <H2>Input</H2> <p> The input file describes polygons one after another, followed by a terminating line that only contains a single zero. </p> <p> A description of a polygon begins with a line containing a single integer, <i>m</i> (&ge; 3), that gives the number of its vertices. It is followed by <i>m</i> lines, each containing two integers <i>x</i> and <i>y</i>, the coordinates of a vertex. The <i>x</i> and <i>y</i> are separated by a single space. The <i>i</i>-th of these <i>m</i> lines gives the coordinates of the <i>i</i>-th vertex (<i>i</i> = 1, ... , <i>m</i>). For each <i>i</i> = 1, ... , <i>m</i> - 1, the <i>i</i>-th vertex and the (<i>i</i> + 1)-th vertex are connected by an edge. The <i>m</i>-th vertex and the first vertex are also connected by an edge (i.e., the curve is closed). Edges intersect only at vertices. No three edges share a single vertex (i.e., the curve is simple). The number of polygons is no more than 100. For each polygon, the number of vertices (<i>m</i>) is no more than 100. All coordinates <i>x</i> and <i>y</i> satisfy -2000 &le; <i>x</i> &le; 2000 and -2000 &le; <i>y</i> &le; 2000. </p> <H2>Output</H2> <p> The output should consist of as many lines as the number of polygons. The <i>k</i>-th output line should print an integer which is the area of the <i>k</i>-th polygon, approximated in the way described above. No other characters, including whitespaces, should be printed. </p> <H2>Sample Input</H2> <pre> 4 5 -3 1 0 1 7 -7 -1 3 5 5 18 5 5 10 3 -5 -5 -5 -10 -18 -10 5 0 0 20 2 11 1 21 2 2 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 55 41 41 23 </pre>
p01733
<p> Ievan Ritola is a researcher of behavioral ecology. Her group visited a forest to analyze an ecological system of some kinds of foxes. </p> <p> The forest can be expressed as a two-dimensional plane. With her previous research, foxes in the forest are known to live at lattice points. Here, lattice points are the points whose <var>x</var> and <var>y</var> coordinates are both integers. Two or more foxes might live at the same point. </p> <p> To observe the biology of these foxes, they decided to put a pair of sensors in the forest. The sensors can be put at lattice points. Then, they will be able to observe all foxes inside the bounding rectangle (including the boundary) where the sensors are catty-corner to each other. The sensors cannot be placed at the points that have the same <var>x</var> or <var>y</var> coordinate; in other words the rectangle must have non-zero area. </p> <p> The more foxes can be observed, the more data can be collected; on the other hand, monitoring a large area consumes a large amount of energy. So they want to maximize the value given by <var>N' / (|x_1 &minus; x_2| &times; |y_1 &minus; y_2|)</var>, where <var>N'</var> is the number of foxes observed and <var>(x_1, y_1)</var> and <var>(x_2, y_2)</var> are the positions of the two sensors. </p> <p> Let's help her observe cute foxes! </p> <h3>Input</h3> <p> The input is formatted as follows. </p> <pre> <var>N</var> <var>x_1</var> <var>y_1</var> <var>w_1</var> <var>x_2</var> <var>y_2</var> <var>w_2</var> : : <var>x_N</var> <var>y_N</var> <var>w_N</var> </pre> <p> The first line contains a single integer <var>N</var> (<var>1 &le; N &le; 10^5</var>) indicating the number of the fox lairs in the forest. Each of the next <var>N</var> lines contains three integers <var>x_i</var>, <var>y_i</var> (<var>|x_i|,\, |y_i| &le; 10^9</var>) and <var>w_i</var> (<var>1 &le; w_i &le; 10^4</var>), which represent there are <var>w_i</var> foxes at the point <var>(x_i, y_i)</var>. It is guaranteed that all points are mutually different. </p> <h3>Output</h3> <p>Output the maximized value as a fraction: </p> <pre> <var>a</var> / <var>b</var> </pre> <p>where <var>a</var> and <var>b</var> are integers representing the numerator and the denominato respectively. There should be exactly one space before and after the slash. The fraction should be written in the simplest form, that is, <var>a</var> and <var>b</var> must not have a common integer divisor greater than one. </p> <p>If the value becomes an integer, print a fraction with the denominator of one (e.g. <code>5 / 1</code> to represent 5). This implies zero should be printed as <code>0 / 1</code> (without quotes). </p> <h3>Sample Input 1</h3> <pre>2 1 1 2 2 2 3 </pre> <h3>Output for the Sample Input 1</h3> <pre>5 / 1 </pre>
p00572
<h1>団子職人(Dango Maker)</h1> <p> あなたは団子を作る職人である.今,あなたは団子に串を刺そうとしているところである. </p> <p> 団子は,縦<var>N</var> 行,横<var>M</var> 列に仕切られたマスの中に配置されている.各マスには団子が1 個ずつ入っている.それぞれの団子には,赤(R),緑(G), 白(W) のいずれかの色が付いている.あなたは,左から右の方向,または,上から下の方向に連続する3 マスから団子を取り出し,この順に1 本の串にちょうど3個刺すことができる. </p> <p> 今あなたは,赤,緑,白の団子が1 個ずつこの順に刺さった串を可能な限り多く作りたい.串に刺す順番は,マスから取り出した順番と同じでなければならない.また,同じ団子に2 本以上の串を刺すことはできない. </p> <p> あなたは,団子が刺さった串を最大何本作ることができるだろうか. </p> <h3>課題</h3> <p> マスの中に配置された団子の色の情報が与えられたとき,赤,緑,白の団子が1 個ずつこの順に刺さった串が最大何本作れるかを求めるプログラムを作成せよ. </p> <h3>入力</h3> <p> 標準入力から以下の入力を読み込め. </p> <ul> <li> 1 行目には,整数<var>N</var> と<var>M</var> が空白を区切りとして書かれている.</li> <li> 続く<var>N</var> 行のうちの<var>i</var> 行目(<var>1 \leq i \leq N</var>) には,R, G, W からなる長さ<var>M</var> の文字列が書かれている.この文字列の<var>j</var> 文字目(<var>1 \leq j \leq M</var>) は,上から<var>i</var> 行目,左から<var>j</var> 列目のマスの団子の色を表す.</li> </ul> <h3>出力</h3> <p> 標準出力に,団子が刺さった串の本数の最大値を1 行で出力せよ. </p> <h3>制限</h3> <p> すべての入力データは以下の条件を満たす. </p> <ul> <li><var> 1 \leq N \leq 3 000.</var></li> <li><var> 1 \leq M \leq 3 000.</var></li> </ul> <!-- 小課題 小課題1 [13 点] 以下の条件を満たす. N ≦ 4. M ≦ 4. 小課題2 [20 点] 以下の条件を満たす. N ≦ 10. M ≦ 10. 小課題3 [67 点] 追加の制限はない. --> <h3>入出力例</h3> <h3>入力例1</h3> <pre> 3 4 RGWR GRGG RGWW </pre> <h3>出力例1</h3> <pre> 3 </pre> <p> 次のように串に刺すことで,団子が刺さった串を3 本作ることができる. </p> <ul> <li> 上から1 行目,左から1 列目の団子から右方向に3 個の団子を取り出し,この順に串に刺す.</li> <li> 上から1 行目,左から4 列目の団子から下方向に3 個の団子を取り出し,この順に串に刺す.</li> <li> 上から3 行目,左から1 列目の団子から右方向に3 個の団子を取り出し,この順に串に刺す.</li> </ul> <p> 4 本以上の串を作ることはできないので,3 を出力する. </p> <h3>入力例2</h3> <pre> 4 4 RGWR GRRG WGGW WWWR </pre> <h3> 出力例2</h3> <pre> 4 </pre> <p> 次のように串に刺すことで,団子が刺さった串を4 本作ることができる. </p> <ul> <li> 上から1 行目,左から1 列目の団子から右方向に3 個の団子を取り出し,この順に串に刺す.</li> <li> 上から1 行目,左から4 列目の団子から下方向に3 個の団子を取り出し,この順に串に刺す.</li> <li> 上から2 行目,左から2 列目の団子から下方向に3 個の団子を取り出し,この順に串に刺す.</li> <li> 上から2 行目,左から3 列目の団子から下方向に3 個の団子を取り出し,この順に串に刺す.</li> </ul> <p> 5 本以上の串を作ることはできないので,4 を出力する. </p> <h3>入力例3</h3> <pre> 5 5 RGRGW GRRGW WGGWR RWRGW RGWGW </pre> <h3> 出力例3</h3> <pre> 6 </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>
p00088
<H1>博士が愛した符号</H1> <p> 博士 : ピーター君、ついにやったよ。<br/> ピーター : どうしました、デビッド博士?またくだらない発明ですか?<br/> 博士 : この表だよ、この表。<br/> </p> <center> <table width="700"><tr> <td width="140"> <table style="border: 1px #aaa solid; padding:4px"> <tr><td width="60">文字</td><td>符号</td></tr> <tr><td >(空白)</td><td>101</td></tr> <tr><td >'</td><td>000000</td></tr> <tr><td >,</td><td>000011</td></tr> <tr><td >-</td><td>10010001</td></tr> <tr><td >.</td><td>010001</td></tr> <tr><td >?</td><td>000001</td></tr> <tr><td >A</td><td>100101</td></tr> <tr><td >B</td><td>10011010</td></tr> </table> </td> <td width="140"> <table style="border: 1px #aaa solid; padding:4px"> <tr><td width="60">文字</td><td>符号</td></tr> <tr><td > C</td><td> 0101</td></tr> <tr><td > D</td><td> 0001</td></tr> <tr><td > E</td><td> 110</td></tr> <tr><td > F</td><td> 01001</td></tr> <tr><td > G</td><td> 10011011</td></tr> <tr><td > H</td><td> 010000</td></tr> <tr><td > I</td><td> 0111</td></tr> <tr><td > J</td><td> 10011000</td></tr> </table> </td> <td width="140"> <table style="border: 1px #aaa solid; padding:4px"> <tr><td width="60">文字</td><td>符号</td></tr> <tr><td > K</td><td> 0110</td></tr> <tr><td > L</td><td> 00100</td></tr> <tr><td > M</td><td> 10011001</td></tr> <tr><td > N</td><td> 10011110</td></tr> <tr><td > O</td><td> 00101</td></tr> <tr><td > P</td><td> 111</td></tr> <tr><td > Q</td><td> 10011111</td></tr> <tr><td > R</td><td> 1000</td></tr> </table> </td> <td width="140"> <table style="border: 1px #aaa solid; padding:4px"> <tr><td width="60">文字</td><td>符号</td></tr> <tr><td > S</td><td> 00110</td></tr> <tr><td > T</td><td> 00111</td></tr> <tr><td > U</td><td> 10011100</td></tr> <tr><td > V</td><td> 10011101</td></tr> <tr><td > W</td><td> 000010</td></tr> <tr><td > X</td><td> 10010010</td></tr> <tr><td > Y</td><td> 10010011</td></tr> <tr><td > Z</td><td> 10010000</td></tr> </table> </td> </tr></table> </center> <br/> <p> ピーター : なんですか? この表は。<br/> 博士 : いいから、言う通りにしてみなさい。まず、お前の名前を紙に書いてごらん。<br/> ピーター : はい"PETER POTTER" っと。<br/> 博士 : そうしたら、1文字ずつ、この表の「符号」に置き換えるのだよ。<br/> ピーター : えーと"P" を「111」にして"E" を「110」して…結構面倒ですね。 </p> <pre> 111 110 00111 110 1000 101 111 00101 00111 00111 110 1000 </pre> <p> になりました。なんだか、バーコードみたいですね。<br/> 博士 : よろしい。そうしたら、置き換えた文字列を全部つなげて、5文字ごとに区切ってみなさい。<br/> ピーター : はいはい、つなげて区切ると。 </p> <pre> 11111 00011 11101 00010 11110 01010 01110 01111 10100 0 </pre> <p> こんな感じになりました。けど、最後の「0」だけのやつはどうしますか?<br/> 博士 : 0を付け加えて5文字にしておいてくれ。<br/> ピーター : えーと最後が0が1個だけだから0をあと4つ加えてやればいいんですね。できました。<br/> </p> <pre> 11111 00011 11101 00010 11110 01010 01110 01111 10100 00000 </pre> <p> 博士 : 次はこの表を使うのだ。<br/> </p> <center> <table width="700"><tr> <td width="140"><table style="border: 1px #aaa solid; padding:4px"> <tr><td width="80" >符号</td><td>文字</td></tr> <tr><td> 00000</td><td > A</td></tr> <tr><td> 00001</td><td > B</td></tr> <tr><td> 00010</td><td > C</td></tr> <tr><td> 00011</td><td > D</td></tr> <tr><td> 00100</td><td > E</td></tr> <tr><td> 00101</td><td > F</td></tr> <tr><td> 00110</td><td > G</td></tr> <tr><td> 00111</td><td > H</td></tr> </table></td> <td width="140"><table style="border: 1px #aaa solid; padding:4px"> <tr><td width="80">符号</td><td>文字</td></tr> <tr><td> 01000</td><td > I</td></tr> <tr><td> 01001</td><td > J</td></tr> <tr><td> 01010</td><td > K</td></tr> <tr><td> 01011</td><td > L</td></tr> <tr><td> 01100</td><td > M</td></tr> <tr><td> 01101</td><td > N</td></tr> <tr><td> 01110</td><td > O</td></tr> <tr><td> 01111</td><td > P</td></tr> </table></td> <td width="140"><table style="border: 1px #aaa solid; padding:4px"> <tr><td width="80">符号</td><td>文字</td></tr> <tr><td> 10000</td><td > Q</td></tr> <tr><td> 10001</td><td > R</td></tr> <tr><td> 10010</td><td > S</td></tr> <tr><td> 10011</td><td > T</td></tr> <tr><td> 10100</td><td > U</td></tr> <tr><td> 10101</td><td > V</td></tr> <tr><td> 10110</td><td > W</td></tr> <tr><td> 10111</td><td > X</td></tr> </table></td> <td width="140"><table style="border: 1px #aaa solid; padding:4px"> <tr><td width="80">符号</td><td>文字</td></tr> <tr><td> 11000</td><td > Y</td></tr> <tr><td> 11001</td><td > Z</td></tr> <tr><td> 11010</td><td > (空白)</td></tr> <tr><td> 11011</td><td > .</td></tr> <tr><td> 11100</td><td > ,</td></tr> <tr><td> 11101</td><td > -</td></tr> <tr><td> 11110</td><td > '</td></tr> <tr><td> 11111</td><td > ?</td></tr> </table></td> </tr></table> </center> <br/> <p> ピーター : これをどう使うんですか…そうか!今度は符号から文字に置き換えるのか!<br/> 博士 : そうそう。「11111」だったら「?」に、「00011」だったら「D」にとやってゆけばいいんだよ。<br/> ピーター : これは単純ですね……えーと「?D-C'KOPUA」になりました。でも意味不明ですよ。<br/> 博士 : 文字数を数えてごらん。<br/> ピーター : 10文字ですよ。あっ、「PETER POTTER」は12文字だったのに2文字減っています。<br/> 博士 : そう、この表を使えば文字を減らすことができるのだよ。じゃあ今度はこの文章で同じことをやっ てごらん。<br/> </p> <pre> PETER PIPER PICKED A PECK OF PICKLED PEPPERS. A PECK OF PICKLED PEPPERS PETER PIPER PICKED. IF PETER PIPER PICKED A PECK OF PICKLED PEPPERS, WHERE'S THE PECK OF PICKLED PEPPERS PETER PIPER PICKED? </pre> <p> ピーター : ぎょぎょ、行が分かれていますが、どうするんですか?<br/> 博士 : 紙の都合で3行になってしまったが、改行文字のかわりに空白がある長い1行だと思っておくれ。<br/> ピーター : はいはい。行と行の間にあるのは空白だと。しかし面倒だな……。<br/> 博士 : だったらプログラムにやらせればいいではないか。<br/> </p> <p> ということで、ピーターの代わりに、読み込んだ文字列を符号に変換し出力するプログラムを作成してください。 </p> <H2>入力</H2> <p>複数のデータセットが与えられます。各データセットに文字列1行(表に含まれる文字からなる)が与えられます。文字列に含まれる文字の数は 1 文字以上 100 文字以下です。 </p> <p> データセットの数は 200 を超えません。 </p> <H2>出力</H2> <p>各データセットごとに、変換後の文字列を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> PETER POTTER </pre> <H2>Output for the Sample Input</H2> <pre> ?D-C'KOPUA </pre>
p00122
<H1>ぴょん吉の夏</H1> <p> 会津大学には一面芝生で覆われた公園があり、日差しを遮る木や建物がありません。日差しの強い夏の日には、公園内に設置されたスプリンクラーが作動して芝生に散水しています。この公園にはカエルのぴょん吉が住み着いています。ぴょん吉は暑いのが苦手で、日差しが強い夏の日には常にスプリンクラーの水に当たっていないと干からびて死んでしまいます。公園に設置されたスプリンクラーは、節水のため一度に一つだけ散水することになっているので、ぴょん吉はスプリンクラーの作動に合わせて移動しなくてはなりません。 </p> <center> <table> <tr><td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_phyonkichi1"> </td></tr> <tr> <th>(a) 公園の地図</th> </tr> </table> <br> <table> <tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_phyonkichi2"></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_phyonkichi3"></td></tr> <tr> <th>(b) ぴょん吉のジャンプ範囲 </th> <th>(c) スプリンクラーの散水範囲</th> </tr> </table> </center> <br/> <p> 公園は上図の(a)のとおりで、公園内の場所は縦横それぞれ 0~9 の座標で表し、黒い●がスプリンクラーで、その番号が作動する順番を表しています。これは一例で各スプリンクラーの場所と作動順序は日々変わります。 </p> <p> ぴょん吉は不器用なので、移動するにも決まった距離をジャンプすることしかできません。ぴょん吉のジャンプできる範囲は上図(b)のとおりで、それ以外の場所に移動することはできません。しかも、一回のジャンプで相当体力を消耗するため、しばらく水に当たって休まなくてはなりません。 </p> <p> スプリンクラーが散水できる範囲は上図(c)のとおりで、スプリンクラー自身の座標も含みます。各スプリンクラーは一定時間散水すると停止し、すぐに次のスプリンクラーが作動を開始します。ぴょん吉はこの時に一回だけジャンプするものとし、次に散水が停止するまでジャンプしないものとします。また、公園の四方は灼熱のアスファルトで囲まれているので公園の外にでてしまうような方向にはジャンプしないものとします。 </p> <p> 猛暑となったこの夏。果たしてぴょん吉は生き延びることができたのでしょうか? ある日のぴょん吉の初期位置、スプリンクラーの位置と作動順序を読み込み、ぴょん吉が生き延びられる移動経路が存在している場合は”OK”、どう頑張っても死んでしまう場合は”NA”を出力するプログラムを作成してください。ただし、スプリンクラーの数は最大 10 個とし、ぴょん吉は一番目のスプリンクラーの作動と同時に初期位置からジャンプすることとします。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットは以下の形式で与えられます。 </p> <pre> <var>px</var> <var>py</var> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> ... <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <p> 1 行目にぴょん吉の初期位置の横座標 <var>px</var> と縦座標 <var>py</var> が与えられます。 2 行目にスプリンクラーの数 <var>n</var> が与えられます。 3 行目に <var>i</var> 番目に動作するスプリンクラーの横座標 <var>x<sub>i</sub></var> と縦座標 <var>y<sub>i</sub></var> が与えられます。 </p> <p> 入力はゼロ2つの行で終わります。データセットの数は 20 を超えません。 </p> <H2>Output</H2> <p> 各データセットについて、生存の場合は OK、そうでない場合は NA を1行に出力してください。 </p> <H2>Sample Input</H2> <pre> 6 1 10 6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 8 3 6 1 10 6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 9 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> OK NA </pre>
p02631
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> Snuke Cats numbered <var>1, 2, \ldots, N</var>, where <var>N</var> is <strong>even</strong>.</p> <p>Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.</p> <p>Recently, they learned the operation called xor (exclusive OR).</p> <details> <summary style="display: list-item; outline: none;">What is xor?</summary> <p> For <var>n</var> non-negative integers <var>x_1, x_2, \ldots, x_n</var>, their xor, <var>x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n</var> is defined as follows: <ul> <li> When <var>x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if the number of integers among <var>x_1, x_2, \ldots, x_n</var> whose binary representations have <var>1</var> in the <var>2^k</var>'s place is odd, and <var>0</var> if that count is even. </li> </ul> For example, <var>3~\textrm{xor}~5 = 6</var>. </p> </details> <p>They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.</p> <p>We know that the xor calculated by Snuke Cat <var>i</var>, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat <var>i</var> is <var>a_i</var>. Using this information, restore the integer written on the scarf of each Snuke Cat.</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 200000</var></li> <li><var>N</var> is <strong>even</strong>.</li> <li><var>0 \leq a_i \leq 10^9</var></li> <li>There exists a combination of integers on the scarfs that is consistent with the given information.</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 a line containing <var>N</var> integers separated with space.</p> <p>The <var>i</var>-th of the integers from the left should represent the integer written on the scarf of Snuke Cat <var>i</var>.</p> <p>If there are multiple possible solutions, you may print any of them.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 20 11 9 24 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 5 7 22 </pre> <ul> <li><var>5~\textrm{xor}~7~\textrm{xor}~22 = 20</var></li> <li><var>26~\textrm{xor}~7~\textrm{xor}~22 = 11</var></li> <li><var>26~\textrm{xor}~5~\textrm{xor}~22 = 9</var></li> <li><var>26~\textrm{xor}~5~\textrm{xor}~7 = 24</var></li> </ul> <p>Thus, this output is consistent with the given information.</p></section> </div> </span>
p03923
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Rng is baking cookies.</p> <p>Initially, he can bake one cookie per second.</p> <p>He can also eat the cookies baked by himself. When there are <var>x</var> cookies not yet eaten, he can choose to eat all those cookies. After he finishes eating those cookies, the number of cookies he can bake per second becomes <var>x</var>. Note that a cookie always needs to be baked for <var>1</var> second, that is, he cannot bake a cookie in <var>1/x</var> seconds when <var>x &gt; 1</var>. When he choose to eat the cookies, he must eat all of them; he cannot choose to eat only part of them. It takes him <var>A</var> seconds to eat the cookies regardless of how many, during which no cookies can be baked.</p> <p>He wants to give <var>N</var> cookies to Grandma. Find the shortest time needed to produce at least <var>N</var> cookies not yet eaten.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^{12}</var></li> <li><var>0≦A≦10^{12}</var></li> <li><var>A</var> is an integer.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>500</var> points will be awarded for passing the test set satisfying <var>N≦10^6</var> and <var>A≦10^6</var>.</li> <li>Additional <var>500</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> <var>A</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the shortest time needed to produce at least <var>N</var> cookies not yet eaten.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>It is possible to produce <var>8</var> cookies in <var>7</var> seconds, as follows:</p> <ul> <li>After <var>1</var> second: <var>1</var> cookie is done.</li> <li>After <var>2</var> seconds: <var>1</var> more cookie is done, totaling <var>2</var>. Now, Rng starts eating those <var>2</var> cookies.</li> <li>After <var>3</var> seconds: He finishes eating the cookies, and he can now bake <var>2</var> cookies per second.</li> <li>After <var>4</var> seconds: <var>2</var> cookies are done.</li> <li>After <var>5</var> seconds: <var>2</var> more cookies are done, totaling <var>4</var>.</li> <li>After <var>6</var> seconds: <var>2</var> more cookies are done, totaling <var>6</var>.</li> <li>After <var>7</var> seconds: <var>2</var> more cookies are done, totaling <var>8</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000000000000 1000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000000000 </pre></section> </div> </span>
p03889
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of letters <code>b</code>, <code>d</code>, <code>p</code> and <code>q</code>. Determine whether <var>S</var> is a <em>mirror string</em>.</p> <p>Here, a mirror string is a string <var>S</var> such that the following sequence of operations on <var>S</var> results in the same string <var>S</var>:</p> <ol> <li> <p>Reverse the order of the characters in <var>S</var>.</p> </li> <li> <p>Replace each occurrence of <code>b</code> by <code>d</code>, <code>d</code> by <code>b</code>, <code>p</code> by <code>q</code>, and <code>q</code> by <code>p</code>, simultaneously.</p> </li> </ol> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 10^5</var></li> <li><var>S</var> consists of letters <code>b</code>, <code>d</code>, <code>p</code>, and <code>q</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</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>S</var> is a mirror string, print <code>Yes</code>. Otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>pdbq </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>ppqb </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre></section> </div> </span>
p02261
<H1>Stable Sort</H1> <p> Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by <span>H8</span> and 'one of diamonds' is represented by <span>D1</span>. </p> <p> Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: </p> <pre> BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] </pre> <pre> SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] </pre> <p> Note that, indices for array elements are based on 0-origin. </p <p> For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance). </p> <!-- <p> Note that, cards with same values but different suits must be appear in the same order of the input sequence. </p> --> <H2>Input</H2> <p> The first line contains an integer <i>N</i>, the number of cards. </p> <p> <i>N</i> cards are given in the following line. Each card is represented by two characters. Two consecutive cards are separated by a space character. </p> <H2>Output</H2> <p> In the first line, print the arranged cards provided by the Bubble Sort algorithm. Two consecutive cards should be separated by a space character. </p> <p> In the second line, print the stability ("<span>Stable</span>" or "<span>Not stable</span>") of this output. </p> <p> In the third line, print the arranged cards provided by the Selection Sort algorithm. Two consecutive cards should be separated by a space character. </p> <p> In the fourth line, print the stability ("<span>Stable</span>" or "<span>Not stable</span>") of this output. </p> <H2>Constraints</H2> <p> 1 &le; <i>N</i> &le; 36 </p> <H2>Sample Input 1</H2> <pre> 5 H4 C9 S4 D2 C3 </pre> <H2>Sample Output 1</H2> <pre> D2 C3 H4 S4 C9 Stable D2 C3 S4 H4 C9 Not stable </pre> <H2>Sample Input 2</H2> <pre> 2 S1 H1 </pre> <H2>Sample Output 2</H2> <pre> S1 H1 Stable S1 H1 Stable </pre>
p03020
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is playing with red and blue balls, placing them on a two-dimensional plane.</p> <p>First, he performed <var>N</var> operations to place red balls. In the <var>i</var>-th of these operations, he placed <var>RC_i</var> red balls at coordinates <var>(RX_i,RY_i)</var>. Then, he performed another <var>N</var> operations to place blue balls. In the <var>i</var>-th of these operations, he placed <var>BC_i</var> blue balls at coordinates <var>(BX_i,BY_i)</var>. The total number of red balls placed and the total number of blue balls placed are equal, that is, <var>\sum_{i=1}^{N} RC_i = \sum_{i=1}^{N} BC_i</var>. Let this value be <var>S</var>.</p> <p>Snuke will now form <var>S</var> pairs of red and blue balls so that every ball belongs to exactly one pair. Let us define the <em>score</em> of a pair of a red ball at coordinates <var>(rx, ry)</var> and a blue ball at coordinates <var>(bx, by)</var> as <var>|rx-bx| + |ry-by|</var>.</p> <p>Snuke wants to maximize the sum of the scores of the pairs. Help him by finding the maximum possible sum of the scores of the pairs.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>0 \leq RX_i,RY_i,BX_i,BY_i \leq 10^9</var></li> <li><var>1 \leq RC_i,BC_i \leq 10</var></li> <li><var>\sum_{i=1}^{N} RC_i = \sum_{i=1}^{N} BC_i</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>RX_1</var> <var>RY_1</var> <var>RC_1</var> <var>RX_2</var> <var>RY_2</var> <var>RC_2</var> <var>\vdots</var> <var>RX_N</var> <var>RY_N</var> <var>RC_N</var> <var>BX_1</var> <var>BY_1</var> <var>BC_1</var> <var>BX_2</var> <var>BY_2</var> <var>BC_2</var> <var>\vdots</var> <var>BX_N</var> <var>BY_N</var> <var>BC_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the scores of the pairs.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 0 1 3 2 1 2 2 1 5 0 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>If we pair the red ball at coordinates <var>(0,0)</var> and the blue ball at coordinates <var>(2,2)</var>, the score of this pair is <var>|0-2| + |0-2|=4</var>. Then, if we pair the red ball at coordinates <var>(3,2)</var> and the blue ball at coordinates <var>(5,0)</var>, the score of this pair is <var>|3-5| + |2-0|=4</var>. Making these two pairs results in the total score of <var>8</var>, which is the maximum result.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 0 1 2 2 1 0 0 2 1 1 1 1 1 1 3 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>16 </pre> <p>Snuke may have performed multiple operations at the same coordinates.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 582463373 690528069 8 621230322 318051944 4 356524296 974059503 6 372751381 111542460 9 392867214 581476334 6 606955458 513028121 5 882201596 791660614 9 250465517 91918758 3 618624774 406956634 6 426294747 736401096 5 974896051 888765942 5 726682138 336960821 3 715144179 82444709 6 599055841 501257806 6 390484433 962747856 4 912334580 219343832 8 570458984 648862300 6 638017635 572157978 10 435958984 585073520 7 445612658 234265014 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>45152033546 </pre></section> </div> </span>
p03470
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>An <em><var>X</var>-layered kagami mochi</em> <var>(X ≥ 1)</var> is a pile of <var>X</var> round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of <var>10</var>, <var>8</var> and <var>6</var> centimeters from bottom to top in this order, you have a <var>3</var>-layered kagami mochi; if you put just one mochi, you have a <var>1</var>-layered kagami mochi.</p> <p>Lunlun the dachshund has <var>N</var> round mochi, and the diameter of the <var>i</var>-th mochi is <var>d_i</var> centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 100</var></li> <li><var>1 ≤ d_i ≤ 100</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>d_1</var> <var>:</var> <var>d_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of layers in a kagami mochi that can be made.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 10 8 8 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>If we stack the mochi with diameters of <var>10</var>, <var>8</var> and <var>6</var> centimeters from bottom to top in this order, we have a <var>3</var>-layered kagami mochi, which is the maximum number of layers.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 15 15 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>When all the mochi have the same diameter, we can only have a <var>1</var>-layered kagami mochi.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 50 30 50 100 50 80 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p01158
<H1><font color="#000">Problem D:</font> Rock Man</H1> <p> You were the master craftsman in the stone age, and you devoted your life to carving many varieties of tools out of natural stones. Your works have ever been displayed respectfully in many museums, even in 2006 A.D. However, most people visiting the museums do not spend so much time to look at your works. Seeing the situation from the Heaven, you brought back memories of those days you had frantically lived. </p> <p> One day in your busiest days, you got a number of orders for making tools. Each order requested one tool which was different from the other orders. It often took some days to fill one order without special tools. But you could use tools which you had already made completely, in order to carve new tools more quickly. For each tool in the list of the orders, there was exactly one tool which could support carving it. </p> <p> In those days, your schedule to fill the orders was not so efficient. You are now thinking of making the most efficient schedule, i.e. the schedule for all orders being filled in the shortest days, using the program you are going to write. </p> <H2>Input</H2> <p> The input consists of a series of test cases. Each case begins with a line containing a single integer <i>N</i> which represents the number of ordered tools. </p> <p> Then <i>N</i> lines follow, each specifying an order by four elements separated by one or more space: <i>name</i>, <i>day</i><sub>1</sub>, <i>sup</i> and <i>day</i><sub>2</sub>. <i>name</i> is the name of the tool in the corresponding order. <i>day</i><sub>1</sub> is the number of required days to make the tool without any support tool. <i>sup</i> is the name of the tool that can support carving the target tool. <i>day</i><sub>2</sub> is the number of required days make the tool with the corresponding support tool. </p> <p> The input terminates with the case where <i>N</i> = 0. You should not process this case. </p> <p> You can assume that the input follows the constraints below: </p> <ul> <li> <i>N</i> &le; 1000;</li> <li> <i>name</i> consists of no longer than 32 non-space characters, and is unique in each case;</li> <li> <i>sup</i> is one of all <i>names</i> given in the same case; and</li> <li> 0 &lt; <i>day</i><sub>2</sub> &lt; <i>day</i><sub>1</sub> &lt; 20000.</li> </ul> <H2>Output</H2> <p> For each test case, output a single line containing an integer which represents the minimum number of days required to fill all <i>N</i> orders. </p> <H2>Sample Input</H2> <pre> 3 gu 20 pa 10 ci 20 gu 10 pa 20 ci 10 2 tool 20 tool 10 product 1000 tool 10 8 fishhook 21 disk 3 mill 14 axe 7 boomerang 56 sundial 28 flint 35 fishhook 5 axe 35 flint 14 disk 42 disk 2 sundial 14 disk 7 hammer 28 mill 7 0 </pre> <H2>Output for the Sample Input</H2> <pre> 40 30 113 </pre>
p03165
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given strings <var>s</var> and <var>t</var>. Find one longest string that is a subsequence of both <var>s</var> and <var>t</var>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>A <em>subsequence</em> of a string <var>x</var> is the string obtained by removing zero or more characters from <var>x</var> and concatenating the remaining characters without changing the order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>s</var> and <var>t</var> are strings consisting of lowercase English letters.</li> <li><var>1 \leq |s|, |t| \leq 3000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> <var>t</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print one longest string that is a subsequence of both <var>s</var> and <var>t</var>. If there are multiple such strings, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>axyb abyxb </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>axb </pre> <p>The answer is <code>axb</code> or <code>ayb</code>; either will be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>aa xayaz </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>aa </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>a z </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre> </pre> <p>The answer is <code></code> (an empty string).</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>abracadabra avadakedavra </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>aaadara </pre></section> </div> </span>
p01508
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Longest Lane</H1> <p> Mr. KM, the mayor of KM city, decided to build a new elementary school. The site for the school has an awkward polygonal shape, which caused several problems. The most serious problem was that there was not enough space for a short distance racetrack. Your task is to help Mr. KM to calculate the maximum possible length for the racetrack that can be built in the site. The track can be considered as a straight line segment whose width can be ignored. The boundary of the site has a simple polygonal shape without self-intersection, and the track can touch the boundary. Note that the boundary might not be convex. </p> <H2>Input</H2> <p> The input consists of multiple test cases, followed by a line containing &quot;0&quot;. Each test case has the following format. The first line contains an integer <var>N</var> (<var>3 \leq N \leq 100</var>). Each of the following <var>N</var> lines contains two integers <var>x_i</var> and <var>y_i</var> (<var>-1,000 \leq x_i, y_i \leq 1,000</var>), which describe the coordinates of a vertex of the polygonal border of the site, in counterclockwise order. </p> <H2>Output</H2> <p> For each test case, print its case number and the maximum possible length of the track in a line. The answer should be given as a floating point number with an absolute error of at most <var>10^{-6}</var>. </p> <H2>Sample Input</H2> <pre> 4 0 0 10 0 10 10 0 10 3 0 0 1 0 0 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 14.142135624 Case 2: 1.41421356 </pre>
p03535
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In CODE FESTIVAL XXXX, there are <var>N+1</var> participants from all over the world, including Takahashi.</p> <p>Takahashi checked and found that the <em>time gap</em> (defined below) between the local times in his city and the <var>i</var>-th person's city was <var>D_i</var> hours. The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is <var>d</var> o'clock at the moment when the local time in city A is <var>0</var> o'clock, then the time gap between these two cities is defined to be <var>min(d,24-d)</var> hours. Here, we are using <var>24</var>-hour notation. That is, the local time in the <var>i</var>-th person's city is either <var>d</var> o'clock or <var>24-d</var> o'clock at the moment when the local time in Takahashi's city is <var>0</var> o'clock, for example.</p> <p>Then, for each pair of two people chosen from the <var>N+1</var> people, he wrote out the time gap between their cities. Let the smallest time gap among them be <var>s</var> hours.</p> <p>Find the maximum possible value of <var>s</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>0 \leq D_i \leq 12</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of <var>s</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 7 12 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>For example, consider the situation where it is <var>7</var>, <var>12</var> and <var>16</var> o'clock in each person's city at the moment when it is <var>0</var> o'clock in Takahashi's city. In this case, the time gap between the second and third persons' cities is <var>4</var> hours.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 11 11 </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>1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>Note that Takahashi himself is also a participant.</p></section> </div> </span>
p02774
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have <var>N</var> integers <var>A_1, A_2, ..., A_N</var>.</p> <p>There are <var>\frac{N(N-1)}{2}</var> ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the <var>K</var>-th number in that list?</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 2 \times 10^5</var></li> <li><var>1 \leq K \leq \frac{N(N-1)}{2}</var></li> <li><var>-10^9 \leq A_i \leq 10^9\ (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>K</var> <var>A_1</var> <var>A_2</var> <var>\dots</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>4 3 3 3 -4 -2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>-6 </pre> <p>There are six ways to form a pair. The products of those pairs are <var>9</var>, <var>-12</var>, <var>-6</var>, <var>-12</var>, <var>-6</var>, <var>8</var>.</p> <p>Sorting those numbers in ascending order, we have <var>-12</var>, <var>-12</var>, <var>-6</var>, <var>-6</var>, <var>8</var>, <var>9</var>. The third number in this list is <var>-6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 40 5 4 3 2 -1 0 0 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>30 413 -170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>448283280358331064 </pre></section> </div> </span>
p00749
<h1><font color="#000000">Problem D:</font> Off Balance</h1> <!-- end en only --> <!-- begin en only --> <p> You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building. </p> <p>Submitted designs will look like a screenshot of a well known game as shown below.</p> <!-- end en only --> <p style="text-align: center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_D-1"> </p> <!-- begin en only --> <p>This is because the center specifies that the building should be constructed by stacking regular units called <i>pieces</i>, each of which consists of four cubic blocks. In addition, the center requires the competitors to submit designs that satisfy the following restrictions. </p> <ul> <li>All the pieces are aligned. When two pieces touch each other, the faces of the touching blocks must be placed exactly at the same position. <li>All the pieces are stable. Since pieces are merely stacked, their centers of masses must be carefully positioned so as not to collapse. <li>The pieces are stacked in a tree-like form in order to symbolize boundless potentiality of young artists. In other words, one and only one piece touches the ground, and each of other pieces touches one and only one piece on its bottom faces. <li>The building has a flat shape. This is because the construction site is a narrow area located between a straight moat and an expressway where no more than one block can be placed between the moat and the expressway as illustrated below. </ul> <!-- end en only --> <p style="text-align: center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_D-2"> </p> <!-- begin en only --> <p>It will take many days to fully check stability of designs as it requires complicated structural calculation. Therefore, you are asked to quickly check obviously unstable designs by focusing on centers of masses. The rules of your quick check are as follows.</p> <p> Assume the center of mass of a block is located at the center of the block, and all blocks have the same weight. We denote a location of a block by <i>xy</i>-coordinates of its left-bottom corner. The unit length is the edge length of a block. </p> <p> Among the blocks of the piece that touch another piece or the ground on their bottom faces, let <i>x<sub>L</sub></i> be the leftmost <i>x</i>-coordinate of the leftmost block, and let <i>x<sub>R</sub></i> be the rightmost <i>x</i>-coordinate of the rightmost block. Let the <i>x</i>-coordinate of its accumulated center of mass of the piece be <i>M</i>, where the accumulated center of mass of a piece <i>P</i> is the center of the mass of the pieces that are directly and indirectly supported by <i>P</i>, in addition to <i>P</i> itself. Then the piece is stable, if and only if <i>x<sub>L</sub></i> &lt; <i>M</i> &lt; <i>x<sub>R</sub></i>. Otherwise, it is unstable. A design of a building is unstable if any of its pieces is unstable. </p><p> Note that the above rules could judge some designs to be unstable even if it would not collapse in reality. For example, the left one of the following designs shall be judged to be unstable. </p> <!-- end en only --> <table><tr> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_D-3" ></td> <td></td> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_D-4" ></td> </tr></table> <!-- begin en only --> <p>Also note that the rules judge boundary cases to be unstable. For example, the top piece in the above right design has its center of mass exactly above the right end of the bottom piece. This shall be judged to be unstable. </p><p> Write a program that judges stability of each design based on the above quick check rules. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset, which represents a front view of a building, is formatted as follows. </p> <!-- end en only --> <blockquote> <i>w h</i> <br> <i>p</i><sub>0(<i>h</i>-1)</sub><i>p</i><sub>1(<i>h</i>-1)</sub>...<i>p</i><sub>(<i>w</i>-1)(<i>h</i>-1)</sub> <br> ... <br> <i>p</i><sub>01</sub><i>p</i><sub>11</sub>...<i>p</i><sub>(<i>w</i>-1)1</sub> <br> <i>p</i><sub>00</sub><i>p</i><sub>10</sub>...<i>p</i><sub>(<i>w</i>-1)0</sub> <br> </blockquote> <!-- begin en only --> <p> The integers <i>w</i> and <i>h</i> separated by a space are the numbers of columns and rows of the layout, respectively. You may assume 1 &le; <i>w</i> &le; 10 and 1 &le; <i>h</i> &le; 60. The next <i>h</i> lines specify the placement of the pieces. The character <i>p<sub>xy</sub></i> indicates the status of a block at (<i>x</i>,<i>y</i>), either `<code>.</code>', meaning empty, or one digit character between `<code>1</code>' and `<code>9</code>', inclusive, meaning a block of a piece. (As mentioned earlier, we denote a location of a block by <i>xy</i>-coordinates of its left-bottom corner.) </p><p> When two blocks with the same number touch each other by any of their top, bottom, left or right face, those blocks are of the same piece. (Note that there might be two different pieces that are denoted by the same number.) The bottom of a block at (<i>x</i>,0) touches the ground. </p><p> You may assume that the pieces in each dataset are stacked in a tree-like form. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a line containing a word <code>STABLE</code> when the design is stable with respect to the above quick check rules. Otherwise, output <code>UNSTABLE</code>. The output should be written with uppercase letters, and should not contain any other extra characters.</p> <!-- end en only --> <h3>Sample Input</h3> <pre> 4 5 ..33 ..33 2222 ..1. .111 5 7 ....1 .1..1 .1..1 11..1 .2222 ..111 ...1. 3 6 .3. 233 23. 22. .11 .11 4 3 2222 ..11 ..11 4 5 .3.. 33.. 322. 2211 .11. 3 3 222 2.1 111 3 4 11. 11. .2. 222 3 4 .11 .11 .2. 222 2 7 11 .1 21 22 23 .3 33 2 3 1. 11 .1 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> STABLE STABLE STABLE UNSTABLE STABLE STABLE UNSTABLE UNSTABLE UNSTABLE UNSTABLE </pre>
p03866
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On the <var>x</var><var>y</var>-plane, Snuke is going to travel from the point <var>(x_s, y_s)</var> to the point <var>(x_t, y_t)</var>. He can move in arbitrary directions with speed <var>1</var>. Here, we will consider him as a point without size.</p> <p>There are <var>N</var> circular barriers deployed on the plane. The center and the radius of the <var>i</var>-th barrier are <var>(x_i, y_i)</var> and <var>r_i</var>, respectively. The barriers may overlap or contain each other.</p> <p>A point on the plane is exposed to cosmic rays if the point is not within any of the barriers.</p> <p>Snuke wants to avoid exposure to cosmic rays as much as possible during the travel. Find the minimum possible duration of time he is exposed to cosmic rays during the travel.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>-10^9 ≤ x_s, y_s, x_t, y_t ≤ 10^9</var></li> <li><var>(x_s, y_s)</var> ≠ <var>(x_t, y_t)</var></li> <li><var>1≤N≤1,000</var></li> <li><var>-10^9 ≤ x_i, y_i ≤ 10^9</var></li> <li><var>1 ≤ r_i ≤ 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>x_s</var> <var>y_s</var> <var>x_t</var> <var>y_t</var> <var>N</var> <var>x_1</var> <var>y_1</var> <var>r_1</var> <var>x_2</var> <var>y_2</var> <var>r_2</var> <var>:</var> <var>x_N</var> <var>y_N</var> <var>r_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible duration of time Snuke is exposed to cosmic rays during the travel. The output is considered correct if the absolute or relative error is at most <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>-2 -2 2 2 1 0 0 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3.6568542495 </pre> <p>An optimal route is as follows:</p> <div style="text-align: center;"> <img alt="e9c630751968b7051df5750b7ddc0e07.png" src="https://atcoder.jp/img/arc064/e9c630751968b7051df5750b7ddc0e07.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>-2 0 2 0 2 -1 0 2 1 0 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0.0000000000 </pre> <p>An optimal route is as follows:</p> <div style="text-align: center;"> <img alt="fb82f6f4df5b22cffb868ce6333277aa.png" src="https://atcoder.jp/img/arc064/fb82f6f4df5b22cffb868ce6333277aa.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 -2 -2 4 3 0 0 2 4 0 1 0 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4.0000000000 </pre> <p>An optimal route is as follows:</p> <div style="text-align: center;"> <img alt="d09006720c225cbe69eae3fd9c186e67.png" src="https://atcoder.jp/img/arc064/d09006720c225cbe69eae3fd9c186e67.png"/> </div></section> </div> </span>
p02324
<H1>Chinese Postman Problem</H1> <p> For a given weighted undirected graph <var>G(V, E)</var>, find the distance of the shortest route that meets the following criteria: </p> <ul> <li>It is a closed cycle where it ends at the same point it starts.</li> <li>The route must go through every edge at least once.</li> </ul> <H2>Input</H2> <pre> <var>|V|</var> <var>|E|</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>d<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>d<sub>|E|-1</sub></var> </pre> <p> , where <var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively. </p> <p> <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target verticess of <var>i</var>-th edge (undirected) and <var>d<sub>i</sub></var> represents the distance between <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> (the <var>i</var>-th edge). </p> <p> Note that there can be multiple edges between a pair of vertices. </p> <H2>Output</H2> <p> Print the shortest distance in a line. </p> <H2>Constraints</H2> <ul> <li>2 &le; <var>|V|</var> &le; 15</li> <li>0 &le; <var>|E|</var> &le; 1,000</li> <li>0 &le; <var>d<sub>i</sub></var> &le; 1,000</li> <li> <var>s<sub>i</sub></var> &ne; <var>t<sub>i</sub></var></li> <li>The graph is connected</li> </ul> <H2>Sample Input 1</H2> <pre> 4 4 0 1 1 0 2 2 1 3 3 2 3 4 </pre> <H2>Sample Output 1</H2> <pre> 10 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 5 0 1 1 0 2 2 1 3 3 2 3 4 1 2 5 </pre> <H2>Sample Output 2</H2> <pre> 18 </pre> <br/> <H2>Sample Input 3</H2> <pre> 2 3 0 1 1 0 1 2 0 1 3 </pre> <H2>Sample Output 3</H2> <pre> 7 </pre>
p00319
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>滑降競技</H1> <p> あなたは磐梯山で開催されるスキー競技に参加します。この競技では、ゲレンデを各選手が2回滑降し、その合計時間の短さを競います。ゲレンデにはいくつもの旗が立っていて、それらの間には選手が通るラインが設定されています。選手はスタート地点からゴール地点まで、ラインをたどりながら滑降します。ラインは以下のように設定されています。 </p> <ul> <li> ゴール地点以外の旗からは一本以上のラインが延びている。</li> <li> ある旗とある旗を直接結ぶラインは多くても一つしかない。</li> <li> ラインは決まった方向にしか滑降できない。</li> <li> どの旗にも必ずスタートからたどり着くことができ、どの旗からもゴールにたどり着ける。</li> <li> どのようにラインをたどっていっても、同じ旗に戻ることはない。</li> </ul> <p> 選手は現在いる旗から延びているラインを選んで次に行く旗を決めることができます。ラインの選び方は自由なので、選手は滑降ごとに異なるラインを通ってゴールに向かうことができます。 </p> <p> 競技前夜、スポーツドクターのソルト君が、あなたが滑るときのゲレンデの状態を予想してくれました。それによると、1回目の滑降で通ったラインは通過の影響で雪質が変わってしまうため、2回目の滑降で同じラインを通ると、かかる時間が変わることがあるそうです。ソルト君は、それぞれのラインを1回目に通るときの時間と、2回目に通るときの時間を教えてくれました。あなたはこの情報をたよりに、2回の滑降の合計時間を最短にする滑り方を朝までに見つけなければなりません。 </p> <p> ゲレンデの状態が与えられたとき、2回の滑降の合計時間でもっとも短い値を計算するプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>P</var> <var>s<sub>1</sub></var> <var>e<sub>1</sub></var> <var>t<sub>1,1</sub></var> <var>t<sub>1,2</sub></var> <var>s<sub>2</sub></var> <var>e<sub>2</sub></var> <var>t<sub>2,1</sub></var> <var>t<sub>2,2</sub></var> : <var>s<sub>P</sub></var> <var>e<sub>P</sub></var> <var>t<sub>P,1</sub></var> <var>t<sub>P,2</sub></var> </pre> <p> 1行目に、旗の数 <var>N</var> (2 &le; <var>N</var> &le; 1000) と2つの旗を結ぶラインの数 <var>P</var> (1 &le; <var>P</var> &le; 2000) が与えられる。旗には 1 から <var>N</var> までの番号が振られていて、スタート地点の旗の番号が1、ゴール地点の旗の番号が <var>N</var> である。続く <var>P</var> 行に、2つの旗を結ぶラインの情報が与えられる。各行には、ラインの始点である旗の番号 <var>s<sub>i</sub></var> (1 &le; <var>s<sub>i</sub></var> &lt; <var>N</var>)、終点である旗の番号 <var>e<sub>i</sub></var> (1 &lt; <var>e<sub>i</sub></var> &le; <var>N</var>)、1回目に通るときの所要時間 <var>t<sub>i,1</sub></var> (1 &le; <var>t<sub>i,1</sub></var> &le; 100000)、同じラインを2回目に通ったときの所要時間(1 &le; <var>t<sub>i,2</sub></var> &le; 100000) が与えられる。 </p> <h2>Output</h2> <p> 2回の滑降の合計時間でもっとも短い値を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 3 3 1 2 1 2 2 3 1 2 1 3 1 3 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <br/> <h2>Sample Input 2</h2> <pre> 3 3 1 2 1 2 2 3 1 2 1 3 1 1 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> <br/> <h2>Sample Input 3</h2> <pre> 4 5 1 2 3 5 1 3 1 3 3 2 2 5 2 4 6 1 3 4 5 5 </pre> <h2>Sample Output 3</h2> <pre> 13 </pre>
p00933
<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 J: Exhibition </h2> <p> The city government is planning an exhibition and collecting industrial products. There are $n$ candidates of industrial products for the exhibition, and the city government decided to choose $k$ of them. They want to minimize the total price of the $k$ products. However, other criteria such as their sizes and weights should be also taken into account. To address this issue, the city government decided to use the following strategy: The $i$-th product has three parameters, price, size, and weight, denoted by $x_i$, $y_i$, and $z_i$, respectively. Then, the city government chooses $k$ items $i_1, . . . , i_k$ ($1 \leq i_j \leq n$) that minimizes the evaluation measure \[ e = (\sum^k_{j=1}x_{ij}) (\sum^k_{j=1}y_{ij}) (\sum^k_{j=1}z_{ij}), \] which incorporates the prices, the sizes, and the weights of products. If there are two or more choices that minimize $e$, the government chooses one of them uniformly at random. </p> <p> You are working for the company that makes the product 1. The company has decided to cut the price, reduce the size, and/or reduce the weight of the product so that the city government may choose the product of your company, that is, to make the probability of choosing the product positive. We have three parameters $A$, $B$, and $C$. If we want to reduce the price, size, and weight to $(1 − \alpha)x_1$, $(1 − \beta)y_1$, and $(1 − \gamma)z_1$ ($0 \leq \alpha, \beta, \gamma \leq 1$), respectively, then we have to invest $\alpha A + \beta B + \gamma C$ million yen. We note that the resulting price, size, and weight do not have to be integers. Your task is to compute the minimum investment required to make the city government possibly choose the product of your company. You may assume that employees of all the other companies are too lazy to make such an effort. </p> <h3>Input</h3> <p> The input consists of a single test case with the following format.<br> <br> $n$ $k$ $A$ $B$ $C$<br> $x_1$ $y_1$ $z_1$<br> $x_2$ $y_2$ $z_2$<br> .<br> .<br> .<br> $x_n$ $y_n$ $z_n$<br> <br> The first line contains five integers. The integer $n$ ($1 \leq n \leq 50$) is the number of industrial products, and the integer $k$ ($1 \leq k \leq n$) is the number of products that will be chosen by the city government. The integers $A$, $B$, $C$ ($1 \leq A, B, C \leq 100$) are the parameters that determine the cost of changing the price, the size, and the weight, respectively, of the product 1. </p> <p> Each of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ ($1 \leq x_i, y_i, z_i \leq 100$), which are the price, the size, and the weight, respectively, of the $i$-th product. </p> <h3>Output</h3> <p> Output the minimum cost (in million yen) in order to make the city government possibly choose the product of your company. The output should not contain an absolute error greater than $10^{−4}$. </p> <h3>Sample Input 1</h3> <pre>6 5 1 2 3 5 5 5 1 5 5 2 5 4 3 5 3 4 5 2 5 5 1</pre> <h3>Sample Output 1</h3> <pre>0.631579</pre> <h3>Sample Input 2</h3> <pre>6 1 1 2 3 10 20 30 1 2 3 2 4 6 3 6 9 4 8 12 5 10 15</pre> <h3>Sample Output 2</h3> <pre>0.999000</pre>
p01621
<!-- <h3><u>Sim Forest 2013</u></h3> --> <!-- end en only --> <!-- begin ja only --> <h1><u>どうぶつの盛り2013</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> Sim Forest 2013というゲームがある。このゲームでは、プレイヤーは森の神様となって森林の動物を育成することができる。 </p> <p> 動物は卵から孵化し、繁殖する。卵は特定の条件を満たすと、一定の確率で突然変異し新しい種族の動物が生まれる。 </p> <p> このゲームには動物事典というものが存在し、新しい種類の動物を入手すると動物辞典に記録されていく。 </p> <p> 盛さんは Sim Forest 2013の熱狂的なプレイヤーである。彼の動物辞典は残り1種族を埋めると完成となる。 </p> <p> 盛さんはこの残りの1種族を、卵からの突然変異により入手することにした。 </p> <p> ゲーム進行は以下のとおりである。 </p> <ul> <li>ステージ開始時に n個 の卵が出現する。</li> <li>ステージ開始から s分後 に n個 の卵が孵化する。</li> <li>各卵は、<b>*出現してから孵化するまで*</b> のすべての期間で(出現時と孵化する瞬間も含む)、特定の曜日かつ特定の時間帯内であればそれぞれ 1/p の確率で目的の動物に突然変異する。</li> <li>ステージ開始から t分後 にステージが終了し、その直後にまた同じステージが開始する(n個の卵がある状態で開始する。経過時間はリセットされない。)</li> <li>ステージは連続で m回 繰り返される。</li> </ul> <p> このゲームは、以下の仕様を満たしている。 </p> <ul> <li>卵から生まれた動物が卵を生むことは無い。</li> <li>卵が孵化するタイミングは、1回のステージにつきステージ開始からs分後の1回のみである。</li> <li>盛さんは、最初のステージの開始曜日・開始時刻を任意に設定できる。(二番目以降のステージの開始時刻は、直前のステージの終了直後となる)</li> <li>突然変異可能な曜日として、{全ての曜日, 日曜, 月曜, 火曜, 水曜, 木曜, 金曜, 土曜} のいずれかが与えられる。</li> <li>突然変異可能な時間帯として、{全ての時間帯, 朝, 夜} のいずれかが与えられる。</li> </ul> <p> 入力として s, n, t, 突然変異可能な曜日・時間帯, p, m が与えられる。 全ステージ終了までに突然変異が起こる確率が最大になるように最初のステージの開始曜日・開始時刻を設定したときの、その確率をもとめよ。 </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は複数のデータセットからなる。各データセットは以下の形式で与えられる。 </p> <pre> <var>s</var> <var>n</var> <var>t</var> <var>weekday</var> <var>time</var> <var>p</var> <var>m</var> </pre> <p> 各データセットは、ステージ開始から卵が孵化するのにかかる時間 s, ステージ開始時に出現する卵の数 n, 1つのステージが終了するまでにかかる時間 t, 突然変異可能な曜日 weekday, 突然変異可能な時間帯 time, 突然変異する確率の逆数 p (突然変異する確率は 1 / p である), 全ステージ数 m を含む。 </p> <p> 入力は以下の制約を満たす。 </p> <ul> <li>0 &lt; s &lt;= 500</li> <li>0 &lt; n &lt;= 100</li> <li>s &lt; t &lt;= 1000</li> <li>weekday ∈ {All, Sun, Mon, Tue, Wed, Thu, Fri, Sat}</li> <ul> <li> All は、全ての曜日を意味する </li> </ul> <li>time ∈ {All, Day, Night}</li> <ul> <li> All は [0:00~24:00), Day は [6:00~18:00), Night は [18:00~6:00) の時間帯を意味する。</li> </ul> <li>1 &lt;= p &lt;= 99999</li> <li>1 &lt;= m &lt;= 100</li> </ul> <p> 入力の終わりは以下の行で与えられる。 </p> <pre> <var>0</var> <var>0</var> <var>0</var> <var>None</var> <var>None</var> <var>0</var> <var>0</var> </pre> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各データセットごとに、全ステージ終了までに突然変異が起こる確率が最大になるように最初のステージの開始曜日・開始時刻を設定したときの、その確率を出力せよ。 解答の誤差は 0.00000001 (10<sup>-8</sup>) を超えてはならない.精度に関する条件を満たしていれば,小数点以下は何桁数字を出力しても構わない。 </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 1 1 3 All All 1 1 2 37 5 All Night 150 1 16 2 20 All Day 5 10 1 14 15 Mon All 20000 100 0 0 0 None None 0 0 </pre> <!-- begin ja only --> <!-- end ja only --> <h3>Output for Sample Input</h3> <pre> 1.0000000000 0.2192439716 0.9884707850 0.0649933899 </pre> <!-- begin ja only --> <!-- end ja only -->
p01271
<h1><font color="#000">Problem E:</font> Mirror Cave</h1> <p> 双子の冒険者 Rin と Len は鏡の洞窟でお宝を探している.この洞窟には鏡の間という対になった 2 つの部屋があり,その部屋の扉の向こうには高価な宝が眠っているという. </p> <p> 便宜上,2 つの部屋はそれぞれ <i>W</i> &times; <i>H</i> のセルが格子状に並んだものとみなす.部屋の外側は壁で囲まれている.また,部屋の内側にもところどころ壁が設置されており,壁の配置されているセルには進入することができない.宝の部屋への扉を開くためには,2 人が左右対称の動きをして,同時に特定のセルに到達しなければならない.しかも,片方だけが先に到達した場合は,扉はロックされて開かなくなってしまう. </p> <p> 左右対称の動きとは,北と北,西と東,東と西,南と南にそれぞれ同時に動くことを意味する.ただし,片方が動こうとしている先に壁があり,もう一方の先に壁が無いといった状況下でも左右対称の動きであると認められる.この場合は壁がある方はその場にとどまり,壁が無い方は隣のセルに動くことになる. </p> <p> 入力として,双子の初期位置,目的地,障害物の配置が与えられる.あなたの仕事は,この双子が扉を開けることが可能であるか判定するプログラムを書くことである. </p> <h3>Input</h3> <p> 入力は複数のデータセットからなる.各データセットは次の形式で与えられる. </p> <blockquote> <i>W</i> <i>H</i><br> <i>RoomL</i><sub>1</sub> <i>RoomR</i><sub>1</sub><br> <i>RoomL</i><sub>2</sub> <i>RoomR</i><sub>2</sub><br> ...<br> <i>RoomL</i><sub><i>H</i></sub> <i>RoomR</i><sub><i>H</i></sub> </blockquote> <p> 最初の行では 2 つの正の整数 <i>W</i>, <i>H</i> (1 &le; <i>W</i>, <i>H</i> &le; 50) が 1 つの空白で区切られて与えられる.その後,<i>H</i> 行に渡って 2 つの部屋の情報が与えられる.<i>RoomL</i><sub><i>i</i></sub>,<i>RoomR</i><sub><i>i</i></sub> はそれぞれ左側,右側の部屋の <i>i</i> 番目の行に対応する.両者とも長さ <i>W</i> の文字列で,<i>j</i> 番目の文字が部屋の <i>j</i> 番目の列に対応する.それぞれの文字は以下のいずれかである. </p> <ul> <li><code>.</code> : 自由に移動できるセル</li> <li><code>#</code> : 壁のあるセル(進入できない)</li> <li><code>%</code> : 目的地</li> <li><code>R</code> : Rin の初期位置</li> <li><code>L</code> : Len の初期位置</li> </ul> <p> 各部屋とも 1 行目が部屋の北端,1 列目が部屋の西端に対応する.また,各部屋は必ずちょうど 1 つの目的地があり,左側の部屋には Len,右側の部屋には Rin の初期位置がちょうど 1 つ存在する. </p> <p> 入力の終わりは,空白で区切られた 2 つの 0 を含む行で示される. </p> <h3>Output</h3> <p> 各データセットについて,双子が扉を開くことができるなら Yes,できなければ No をそれぞれ 1 行に出力せよ. </p> <h3>Sample Input</h3> <pre> 5 5 %#... ...#% .#.#. .#.#. .#.#. .#.#. .#.#. .#.#. ...#L R#... 3 2 .L. .R# %.. .%. 4 1 L.%. %..R 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> Yes Yes No </pre>