Dataset Viewer
Auto-converted to Parquet Duplicate
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>
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
10