question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00731
<h1><font color="#000">Problem D:</font> Cliff Climbing</h1> <!-- end en only --> <!-- begin en only --> <p> At 17:00, special agent Jack starts to escape from the enemy camp. There is a cliff in between the camp and the nearest safety zone. Jack has to climb the almost vertical cliff by stepping his feet on the blocks that cover the cliff. The cliff has slippery blocks where Jack has to spend time to take each step. He also has to bypass some blocks that are too loose to support his weight. Your mission is to write a program that calculates the minimum time to complete climbing. </p> <!-- end en only --> <!-- begin en only --> <p> Figure D-1 shows an example of cliff data that you will receive. The cliff is covered with square blocks. Jack starts cliff climbing from the ground under the cliff, by stepping his left or right foot on one of the blocks marked with 'S' at the bottom row. The numbers on the blocks are the "slippery levels". It takes <i>t</i> time units for him to safely put his foot on a block marked with <i>t</i>, where 1 &le; <i>t</i> &le; 9. He cannot put his feet on blocks marked with 'X'. He completes the climbing when he puts either of his feet on one of the blocks marked with 'T' at the top row. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_d-1" border="1"><br> <!-- begin en only --> Figure D-1: Example of Cliff Data <!-- end en only --> </center> <!-- begin en only --> <p> Jack's movement must meet the following constraints. After putting his left (or right) foot on a block, he can only move his right (or left, respectively) foot. His left foot position (<i>lx</i>, <i>ly</i>) and his right foot position (<i>rx</i>, <i>ry</i>) should satisfy <i>lx</i> &lt; <i>rx</i></li> and | <i>lx</i> - <i>rx</i> | + | <i>ly</i> - <i>ry</i> | &le; 3</li>. This implies that, given a position of his left foot in Figure D-2 (a), he has to place his right foot on one of the nine blocks marked with blue color. Similarly, given a position of his right foot in Figure D-2 (b), he has to place his left foot on one of the nine blocks marked with blue color. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_d-2" border="1"><br> <!-- begin en only --> Figure D-2: Possible Placements of Feet <!-- end en only --> </center> <h2>Input</h2> <!-- begin en only --> <p> The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows: </p> <!-- end en only --> <p> <blockquote> <i>w h</i><br> <i>s(1,1)</i> ... <i>s(1,w)</i><br> <i>s(2,1)</i> ... <i>s(2,w)</i><br> ... <br> <i>s(h,1)</i> ... <i>s(h,w)</i><br> </blockquote> </p> <!-- begin en only --> <p> The integers <i>w</i> and <i>h</i> are the width and the height of the matrix data of the cliff. You may assume 2 &le; <i>w</i> &le; 30 and 5 &le; <i>h</i> &le; 60. Each of the following <i>h</i> lines consists of <i>w</i> characters delimited by a space. The character <i>s(y, x)</i> represents the state of the block at position (<i>x</i>, <i>y</i>) as follows: <ul> <li> 'S': Jack can start cliff climbing from this block. </li> <li> 'T': Jack finishes climbing when he reaches this block. </li> <li> 'X': Jack cannot put his feet on this block. </li> <li> '1' - '9' (<i>= t</i>): Jack has to spend <i>t</i> time units to put either of his feet on this block. </li> </ul> </p> <p> You can assume that it takes no time to put a foot on a block marked with 'S' or 'T'. </p> <!-- end en only --> <h2>Output</h2> <!-- begin en only --> <p> For each dataset, print a line only having a decimal integer indicating the minimum time required for the cliff climbing, when Jack can complete it. Otherwise, print a line only having "-1" for the dataset. Each line should not have any characters other than these numbers. </p> <!-- end en only --> <h2>Sample Input</h2> <pre> 6 6 4 4 X X T T 4 7 8 2 X 7 3 X X X 1 8 1 2 X X X 6 1 1 2 4 4 7 S S 2 3 X X 2 10 T 1 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 2 10 T X 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 10 10 T T T T T T T T T T X 2 X X X X X 3 4 X 9 8 9 X X X 2 9 X 9 7 7 X 7 3 X X 8 9 X 8 9 9 9 6 3 X 5 X 5 8 9 9 9 6 X X 5 X 5 8 6 5 4 6 8 X 5 X 5 8 9 3 9 6 8 X 5 X 5 8 3 9 9 6 X X X 5 X S S S S S S S S S S 10 7 2 3 2 3 2 3 2 3 T T 1 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 4 3 2 3 2 3 2 3 2 3 5 3 2 3 1 3 2 3 2 3 5 2 2 3 2 4 2 3 2 3 5 S S 2 3 2 1 2 3 2 3 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 12 5 -1 22 12 </pre>
p00361
<!--<H1>Modification of Road Network</H1>--> <h1>Road Improvement</h1> <p> Aizu is a country famous for its rich tourism resources and has <var>N</var> cities, each of which is uniquely identified with a number (0 to <var>N</var>-1). It has a road network consisting of <var>M</var> one-way roads connecting a city to another. </p> <p> All the roads connecting the cities in Aizu have a row of cherry trees along their routes. For enhancing the cherry-viewing experience, a proposal was made to modify the road network so that a tourist can travel around all the roads. To achieve this target, it was decided to construct several one-way roads, each connecting two cities and abiding by the following rules. </p> <ul> <li>The newly constructed road is for one-way traffic</li> <li>Starting from any city, a tourist is able to make a roundtrip and return to the city, whereby he/she drives all the roads exhaustively, including the newly constructed ones. Multiple passages of some of the roads are allowed.</li> </ul> <p> You, as a tourism promotion officer, are assigned with the task of writing a program for the road construction project. </p> <p> Write a program to determine the minimum number of roads to be constructed given the road network information in Aizu. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>N</var> <var>M</var> <var>s_1</var> <var>t_1</var> <var>s_2</var> <var>t_2</var> : <var>s_M</var> <var>t_M</var> </pre> <p> The first line provides the number of cities <var>N</var> (1 &le; <var>N</var> &le; 10<sup>4</sup>) and roads <var>M</var> (0 &le; <var>M</var> &le; 10<sup>5</sup>). Each of the subsequent <var>M</var> lines provides the numbers assigned to start and destination cities for the <var>i</var>-th road: <var>s_i</var>, <var>t_i</var> (0 &le; <var>s_i</var>, <var>t_i</var> &le; <var>N</var>-1) , where <var>s_i &ne; t_i</var>. (no duplicate appearance of a road) </p> <h2>Output</h2> <p> Output the minimum number of roads to be newly constructed. </p> <h2>Sample Input 1</h2> <pre> 6 7 0 2 2 1 1 0 2 3 4 3 4 5 5 4 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 6 9 0 2 2 1 1 0 2 3 4 3 4 5 5 4 5 2 3 4 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre>
p01989
<h2>A: IPアドレス (Internet Protocol Address)</h2> <h3>問題</h3> <p> 数字列が <var>1</var> つ与えられるので、IPv4のIPアドレスとして有効な区切り方の個数を求めよ。 ただし、IPv4のIPアドレスとして有効な区切り方は以下の通りである。 </p> <ul> <li>数字列は <var>4</var> つに区切られ、区切られた各列について以下をすべて満たす。</li> <ul> <li>空列でない。</li> <li><var>10</var> 進数として読むと <var>0</var> 以上 <var>255</var> 以下の整数である。</li> <li>その数が <var>0</var> ならば、その列は <code>0</code> である(<code>00</code> などは認められない)。</li> <li>その数が <var>0</var> でないならば、先頭の数字は <code>0</code> でない(<code>01</code> などは認められない)。</li> </ul> </ul> <h3>入力形式</h3> <pre><var>S</var></pre> <h3>制約</h3> <ul> <li><var>4 \leq |S| \leq 12</var></li> <li><var>S</var> に含まれる文字は数字のみである。</li> </ul> <h3>出力形式</h3> <p>有効な区切り方の通り数を一行に出力せよ。</p> <h3>入力例1</h3> <pre>123456789</pre> <h3>出力例1</h3> <pre>1</pre> <p>有効な区切り方は <code>123.45.67.89</code> の <var>1</var> 通りである。</p> <h3>入力例2</h3> <pre>768426</pre> <h3>出力例2</h3> <pre>6</pre>
p01120
<!--<h2>Problem D</h2>--> <!-- begin en only --> <h3>Tally Counters</h3> <!-- end en only --> <!-- begin en only --> <p> A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is already the maximum, it goes down to one. All the counters are of the same model with the same maximum value. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_D1.png" style="width: 40%"> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. D-1 Tally Counters <!-- end en only --> </figcaption> </center> <!-- begin en only --> <p> Starting from the values initially displayed on each of the counters, you want to change all the displayed values to target values specified for each. As you don't want the hassle, however, of pushing buttons of many counters one be one, you devised a special tool. Using the tool, you can push buttons of one or more adjacent counters, one push for each, in a single operation. You can choose an arbitrary number of counters at any position in each operation, as far as they are consecutively lined up. </p> <!-- end en only --> <!-- begin en only --> <p> How many operations are required at least to change the displayed values on counters to the target values? </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of multiple datasets, each in the following format. </p> <!-- end en only --> <p> <blockquote> <i>n</i> <i>m</i> <br> <i>a</i><sub>1</sub> <i>a</i><sub>2</sub> ... <i>a<sub>n</sub></i> <br> <i>b</i><sub>1</sub> <i>b</i><sub>2</sub> ... <i>b<sub>n</sub></i> <br> </blockquote> </p> <!-- begin en only --> <p> Each dataset consists of 3 lines. The first line contains <i>n</i> (1 &le; <i>n</i> &le; 1000) and <i>m</i> (1 &le; <i>m</i> &le; 10000), the number of counters and the maximum value displayed on counters, respectively. The second line contains the initial values on counters, <i>a<sub>i</sub></i> (1 &le; <i>a<sub>i</sub></i> &le; <i>m</i>), separated by spaces. The third line contains the target values on counters, <i>b<sub>i</sub></i> (1 &le; <i>b<sub>i</sub></i> &le; <i>m</i>), separated by spaces. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing two zeros. The number of datasets does not exceed 100. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, print in a line the minimum number of operations required to make all of the counters display the target values. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 4 5 2 3 1 4 2 5 5 2 3 100 1 10 100 1 10 100 5 10000 4971 7482 1238 8523 1823 3287 9013 9812 297 1809 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 4 0 14731 </pre>
p01570
<h1>Usoperanto</h1> <p>Usoperanto is an artificial spoken language designed and regulated by Usoperanto Academy. The academy is now in study to establish Strict Usoperanto, a variation of the language intended for formal documents. </p> <p>In Usoperanto, each word can modify at most one other word, and modifiers are always put before modifiees. For example, with a noun <i>uso</i> (&quot;truth&quot;) modified by an adjective <i>makka</i> (&quot;total&quot;), people say <i>makka uso</i>, not <i>uso makka</i>. On the other hand, there have been no rules about the order among multiple words modifying the same word, so in case <i>uso</i> is modified by one more adjective <i>beta</i> (&quot;obvious&quot;), people could say both <i>makka beta uso</i> and <i>beta makka uso</i>. </p> <p>In Strict Usoperanto, the word order will be restricted according to <i>modification costs</i>. Words in a phrase must be arranged so that the total modification cost is minimized. Each pair of a modifier and a modifiee is assigned a cost equal to the number of letters between the two words; the total modification cost is the sum of the costs over all modifier-modifiee pairs in the phrase. For example, the pair of <i>makka</i> and <i>uso</i> in a phrase <i>makka beta uso</i> has the cost of 4 for <i>beta</i> (four letters). As the pair of <i>beta</i> and <i>uso</i> has no words in between and thus the cost of zero, <i>makka beta uso</i> has the total modification cost of 4. Similarly <i>beta makka uso</i> has the total modification cost of 5. Applying the &quot;minimum total modification cost&quot; rule, <i>makka beta uso</i> is preferred to <i>beta makka uso</i> in Strict Usoperanto. </p> <p>Your mission in this problem is to write a program that, given a set of words in a phrase, finds the correct word order in Strict Usoperanto and reports the total modification cost. </p> <h2>Input</h2> <p>The format of the input is as follows. </p> <blockquote> <var>N</var><br><var>M<sub>0</sub></var> <var>L<sub>0</sub></var><br><var>...</var><br><var>M<sub>N-1</sub></var> <var>L<sub>N-1</sub></var><br></blockquote> <p>The first line contains an integer <!--<var>N</var> (<var>1 &le; N &le; 160,000</var>).--> <var>N</var> (<var>1 &le; N &le; 10<sup>6</sup></var>). <var>N</var> is the number of words in a phrase. </p> <p>Each of the following <var>N</var> lines contains two integers <var>M<sub>i</sub></var> (<var>1 &le; M<sub>i</sub> &le; 10</var>) and <var>L<sub>i</sub></var> (<var>-1 &le; L<sub>i</sub> &le; N - 1</var>, <var>L<sub>i</sub> &ne; i</var>) describing the <var>i</var>-th word (<var>0 &le; i &le; N-1</var>). <var>M<sub>i</sub></var> is the number of the letters in the word. <var>L<sub>i</sub></var> specifies the modification: <var>L<sub>i</sub> = -1</var> indicates it does not modify any word; otherwise it modifies the <var>L<sub>i</sub></var>-th word. </p> <p>Note the first sample input below can be interpreted as the <i>uso</i>-<i>beta</i>-<i>makka</i> case. </p> <h2>Output</h2> <p>Print the total modification cost. </p> <h2>Sample Input 1</h2> <pre>3 3 -1 4 0 5 0 </pre> <h2>Output for the Sample Input 1</h2> <pre>4 </pre> <h2>Sample Input 2</h2> <pre>3 10 -1 10 0 10 1 </pre> <h2>Output for the Sample Input 2</h2> <pre>0 </pre> <h2>Sample Input 3</h2> <pre>4 1 -1 1 0 1 1 1 0 </pre> <h2>Output for the Sample Input 3</h2> <pre>1 </pre>
p00048
<H1>階級</H1> <p> ボクシングは体重によって階級が分けられています。体重を読み込んで、その階級を出力するプログラムを作成してください。階級と体重の関係は以下の表のとおりとします。 </p> <center> <table border=1> <tr><td bgcolor="#88AAFF" width="120">階級</td><td bgcolor="#88AAFF" width="240">体重(kg)</td></tr> <tr><td>light fly</td><td>48.00kg 以下</td></tr> <tr><td>fly</td><td>48.00kg 超 51.00kg 以下</td></tr> <tr><td>bantam</td><td>51.00kg 超 54.00kg 以下</td></tr> <tr><td>feather</td><td>54.00kg 超 57.00kg 以下</td></tr> <tr><td>light</td><td>57.00kg 超 60.00kg 以下</td></tr> <tr><td>light welter</td><td>60.00kg 超 64.00kg 以下</td></tr> <tr><td>welter</td><td>64.00kg 超 69.00 kg 以下</td></tr> <tr><td>light middle</td><td>69.00kg 超 75.00 kg 以下</td></tr> <tr><td>middle</td><td>75.00kg 超 81.00 kg 以下</td></tr> <tr><td>light heavy</td><td>81.00kg 超 91.00 kg 以下</td></tr> <tr><td>heavy</td><td>91.00kg 超</td></tr> </table> </center> <br/> <H2>Input</H2> <p> 入力は複数のデータセットからなります。各データセットとして、体重を表す1つの実数 <var>w</var> (40 &le; <var>w</var> &le; 150) が1行に与えられます。データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、対応する階級を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 60.2 70.2 48.0 80.2 </pre> <H2>Output for the Sample Input</H2> <pre> light welter light middle light fly middle </pre>
p02075
<style type="text/css"> blockquote { font-family: Menlo, Monaco, "Courier New", monospace; display: block; margin: 10px 0 10px 30px; font-size: 16px; line-height: 18px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; } table.ioexample { width: 100%; border-collapse: collapse; } table.ioexample td { width: 50%; border: 1px solid rgba(0, 0, 0, 0.15); vertical-align: top; padding: 5px; } .no-page-break { page-break-inside: avoid; } .page-break { page-break-before: always; } </style> <h3>Problem Statement</h3> <p>Your friend, Tatsumi, is a producer of Immortal Culture Production in Chiba (ICPC). His company is planning to form a zombie rock band named Gray Faces and cheer Chiba Prefecture up.</p> <p>But, unfortunately, there is only one zombie in ICPC. So, Tatsumi decided to release the zombie on a platform of Soga station to produce a sufficient number of zombies. As you may know, a zombie changes a human into a new zombie by passing by the human. In other words, a human becomes a zombie when the human and a zombie are at the same point. Note that a zombie who used to be a human changes a human into a zombie too.</p> <p>The platform of Soga station is represented by an infinitely long line, and Tatsumi will release a zombie at a point with coordinate $x_Z$. After the release, the zombie will start walking in the positive direction at $v_Z$ per second. If $v_Z$ is negative, the zombie will walk in the negative direction at $|v_Z|$ per second.</p> <p>There are $N$ humans on the platform. When Tatsumi releases the zombie, the $i$-th human will be at a point with coordinate $x_i$ and will start walking in the positive direction at $v_i$ per second. If $v_i$ is negative, the human will walk in the negative direction at $|v_i|$ per second as well as the zombie.</p> <p>For each human on the platform, Tatsumi wants to know when the human becomes a zombie. Please help him by writing a program that calculates a time when each human on the platform becomes a zombie.</p> <hr /> <h3>Input</h3> <p>The input consists of a single test case in the following format.</p> <blockquote>$N$ $x_Z$ $v_Z$ $x_1$ $v_1$ $\vdots$ $x_N$ $v_N$</blockquote> <p>The first line consists of an integer $N \, (1 \le N \le 2 \times 10^5)$ which is the number of humans on a platform of Soga station. The second line consists of two integers $x_Z \, (-10^9 \le x_Z \le 10^9)$ and $v_Z \, (-10^9 \le v_Z \le 10^9)$ separated by a space, where $x_Z$ is an initial position of a zombie Tatsumi will release and $v_Z$ is the velocity of the zombie. The $i$-th line in the following $N$ lines contains two integers $x_i \, (-10^9 \le x_i \le 10^9)$ and $v_i \, (-10^9 \le v_i \le 10^9)$ separated by a space, where the $x_i$ is an initial position of the $i$-th human and $v_i$ is the velocity of the human. There is no human that shares their initial position with the zombie. In addition, initial positions of the humans are different from each other.</p> <h3>Output</h3> <p>The output consists of $N$ lines. In the $i$-th line, print how many seconds it will take for the $i$-th human to become a zombie. If the $i$-th human will never become a zombie, print $-1$ instead. The answer will be considered as correct if the values output have an absolute or relative error less than $10^{-9}$.</p> <p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>6 3 1 -5 0 5 0 -4 -3 0 -2 6 -3 2 -1 </pre></td><td><pre>3.66666666666667 2.00000000000000 -1 6.00000000000000 0.75000000000000 2.00000000000000 </pre></td></tr><tr><td><pre>5 31415 -926 5358 979 323846 26 -433832 7950 288 -4 -1971 -69 </pre></td><td><pre>13.67821522309711 95.61812216052499 52.41629112212708 33.76030368763558 38.95682613768962 </pre></td></tr></table></div></p>
p00418
<h1>決まりごとの多いジム</h1>  <p> イヅア村のスポーツジムには$1$から$N$までの番号が付いた$N$台のトレーニング機器があります。トレーニング機器を1回利用するには、その機器の番号が書かれたチケットが1枚必要です。トレーニング機器を1回利用したときの消費カロリーは、機器ごとに決まっています。 </p> <p> このスポーツジムのチケットを何枚かもらったアツシ君は、運動不足解消のためにジムに行きました。このジムでは、利用者が運動をやりすぎて体を痛めないように、機器の利用回数にルールがあります。たとえば、「2番の機器は3番の機器よりも5回以上多く使ってはいけません」というようなルールです。機器を使う人は、ルールを守って機器を利用しなければなりません。 </p> <p> アツシ君は、もらったチケットを使って、ルールで許される範囲でなるべく多くのカロリーを消費したいと思っています。 </p. <p> もらったチケットとそれぞれの機器の情報が与えられたとき、ルールを守ったときの消費カロリーの最大値を求めるプログラムを作成しなさい。 </p> <h2>入力</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> $N$ $R$ $t_1$ $e_1$ $t_2$ $e_2$ : $t_N$ $e_N$ $a_1$ $b_1$ $c_1$ $a_2$ $b_2$ $c_2$ : $a_R$ $b_R$ $c_R$ </pre> <p> 1行目にトレーニング機器の台数$N$ ($1 \leq N \leq 100,000$)とルールの数$R$ ($0 \leq R \leq 100,000$)が与えられる。続く$N$行に、$i$番の機器について、アツシ君がもらったチケットの枚数$t_i$ ($1 \leq t_i \leq 200,000$)とその機器を使ったときの消費カロリー$e_i$ ($0 \leq e_i \leq 100,000$)が与えられる。続く$R$行に、「$a_i$番の機器は$b_i$番の機器よりも$c_i$回以上多く使ってはいけません」というルールを表す数$a_i$ ($1 \leq a_i \leq N$)、$b_i$ ($1 \leq b_i \leq N$)、$c_i$ ($1 \leq c_i \leq 100,000$)が与えられる。 </p> <p> 入力は以下の制約を満たす。 </p> <ul> <li> 同じ機器のペアに対するルールは1度しか与えられない($i \ne j$なら$a_i \ne a_j$または$b_i \ne b_j$)。</li> <li> 同じ機器自身に対するルールは与えられない($a_i \ne b_i$)。</li> </ul> <h2>出力</h2> <p> 消費カロリーの最大値を1行に出力する。 </p> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 3 2 5 1 10 4 6 2 2 1 3 3 2 1 </pre> <h3>出力例1</h3> <pre> 45 </pre> <p> もらったチケットを使って、ルールを守って使える各機器の最大の回数は、$1$番が$5$回、$2$番が$7$回、$3$番が$6$回なので、消費カロリーの最大値は$5 \times 1 + 7 \times 4 + 6 \times 2 = 45$となる。 </p> <h3>入力例2</h3> <pre> 4 5 5 1 6 2 2 3 7 1 1 2 4 2 1 3 1 3 2 3 2 3 3 4 2 </pre> <h3>出力例2</h3> <pre> 26 </pre> <h3>入力例3</h3> <pre> 1 0 200000 100000 </pre> <h3>出力例3</h3> <pre> 20000000000 </pre>
p02425
<h1>Bit Flag</h1> <p> A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF). The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1. </p> <p> Given a sequence of bits with 64 flags which represent a state, perform the following operations. Note that each flag of the bits is initialized by OFF. </p> <ul> <li>test(i): Print 1 if $i$-th flag is ON, otherwise 0</li> <li>set(i): Set $i$-th flag to ON</li> <li>clear(i): Set $i$-th flag to OFF</li> <li>flip(i): Inverse $i$-th flag</li> <li>all: Print 1 if all flags are ON, otherwise 0</li> <li>any: Print 1 if at least one flag is ON, otherwise 0</li> <li>none: Print 1 if all flags are OFF, otherwise 0</li> <li>count: Print the number of ON flags</li> <li>val: Print the decimal value of the state</li> </ul> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $q$ $query_1$ $query_2$ : $query_q$ </pre> <p> Each query $query_i$ is given in the following format: </p> <pre> 0 $i$ </pre> <p>or</p> <pre> 1 $i$ </pre> <p>or</p> <pre> 2 $i$ </pre> <p>or</p> <pre> 3 $i$ </pre> <p>or</p> <pre> 4 </pre> <p>or</p> <pre> 5 </pre> <p>or</p> <pre> 6 </pre> <p>or</p> <pre> 7 </pre> <p>or</p> <pre> 8 </pre> <p> The first digit <span>0</span>, <span>1</span>,...,<span>8</span> represents the operation test(i), set(i), clear(i), flip(i), all, any, none, count or val respectively. </p> <h2>Output</h2> <p> Print the result in a line for each test, all, any, none, count and val operation. </p> <h2>Constraints</h2> <ul> <li>$1 \leq q \leq 200,000$</li> <li>$0 \leq i < 64$</li> </ul> <h2>Sample Input 1</h2> <pre> 14 1 0 1 1 1 2 2 1 0 0 0 1 0 2 0 3 3 3 4 5 6 7 8 </pre> <h2>Sample Output 1</h2> <pre> 1 0 1 0 0 1 0 3 13 </pre>
p03664
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of <var>N</var> vertices numbered <var>1</var> through <var>N</var> and <var>M</var> edges. The <var>i</var>-th edge connects Vertices <var>a_i</var> and <var>b_i</var>, and it costs <var>c_i</var> yen (the currency of Japan) to remove it.</p> <p>Mole would like to remove some of the edges so that there is exactly one path from Vertex <var>1</var> to Vertex <var>N</var> that does not visit the same vertex more than once. Find the minimum budget needed to achieve this.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 15</var></li> <li><var>N-1 \leq M \leq N(N-1)/2</var></li> <li><var>1 \leq a_i, b_i \leq N</var></li> <li><var>1 \leq c_i \leq 10^{6}</var></li> <li>There are neither multiple edges nor self-loops in the given graph.</li> <li>The given graph is connected.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> <var>:</var> <var>a_M</var> <var>b_M</var> <var>c_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 6 1 2 100 3 1 100 2 4 100 4 3 100 1 4 100 3 2 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>200 </pre> <p>By removing the two edges represented by the red dotted lines in the figure below, the objective can be achieved for a cost of <var>200</var> yen.</p> <div style="text-align: center;"> <img alt="45c15676bb602ca3b762561fc014ecd0.png" src="https://atcoder.jp/img/arc078/45c15676bb602ca3b762561fc014ecd0.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>It is possible that there is already only one path from Vertex <var>1</var> to Vertex <var>N</var> in the beginning.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>15 22 8 13 33418 14 15 55849 7 10 15207 4 6 64328 6 9 86902 15 7 46978 8 14 53526 1 2 8720 14 12 37748 8 3 61543 6 5 32425 4 11 20932 3 12 55123 8 2 45333 9 12 77796 3 9 71922 12 15 70793 2 4 25485 11 6 1436 2 7 81563 7 11 97843 3 1 40491 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>133677 </pre></section> </div> </span>
p01659
<h2>D - カーペット</h2> <p> 総合研究7号館の引越しに伴い,研究室にカーペットを敷くことになった. この問題では研究室を上から見たときの床を,二次元平面上の多角形とみなす. 床の形状を表す要素数<var>N</var>の数列<var>\{a_i\}</var>が与えられる. <var>R_i</var>を,左下の座標が<var>(i,0)</var>で右上の座標が<var>(i+1,a_i)</var>である各辺がx軸またはy軸に平行な長方形の境界及び内部領域とする. このとき,床を表す多角形は<var>R_1 ∪ R_2 ∪ R_3 ∪ … ∪ R_N</var>によって表される. カーペットは長方形であればどんな大きさのものを何枚でも用意することができる. 以下の条件を満たすようにカーペットを配置し,研究室の床を全て覆いつくしたい. </p> <ul> <li>カーペットは研究室からはみ出してはいけない.</li> <li>カーペットはいくらでも重ねて敷くことが可能である.このとき,カーペットの厚さは無視する.</li> <li>カーペットを切り離して利用することはできない.</li> <li>カーペットは各辺がx軸またはy軸に平行になるように配置しなければならない.</li> </ul> <p> 研究室の床を覆い尽くすために必要なカーペットの最小数を求めよ. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_carpet1" alt="入力例1の床" height="160" width="240"><br/> 図D-1. 入力例1の床<br/> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_carpet2" alt="入力例2の床" height="320" width="800"> <br/> 図D-2. 入力例2の床<br/> </center> <h2>入力形式</h2> <p>入力は以下の形式で与えられる.</p> <pre> <var>N</var> <var>a_1</var> … <var>a_N</var> </pre> <h2>出力形式</h2> <p> 研究室の床を覆い尽くすために必要なカーペットの最小数を1行に出力せよ. </p> <h2>制約</h2> <ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq a_i \leq 10^9</var></li> <li>入力値はすべて整数である.</li> </ul> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 3 1 2 1 </pre> <h3>出力例1</h3> <pre> 2 </pre> <h3>入力例2</h3> <pre> 10 1 2 2 1 3 4 3 1 2 2 </pre> <h3>出力例2</h3> <pre> 5 </pre>
p02976
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a simple connected undirected graph with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>1</var> to <var>N</var>, and the <var>i</var>-th edge connects Vertex <var>A_i</var> and Vertex <var>B_i</var>. Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph. Determine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>An undirected graph is said to be simple when it contains no self-loops or multiple edges.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>N-1 \leq M \leq 10^5</var></li> <li><var>1 \leq A_i,B_i \leq N (1\leq i\leq M)</var></li> <li>The given graph is simple and connected.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>A_M</var> <var>B_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is impossible to assign directions to satisfy the requirement, print <var>-1</var>. Otherwise, print an assignment of directions that satisfies the requirement, in the following format:</p> <pre><var>C_1</var> <var>D_1</var> <var>:</var> <var>C_M</var> <var>D_M</var> </pre> <p>Here each pair (<var>C_i</var>, <var>D_i</var>) means that there is an edge directed from Vertex <var>C_i</var> to Vertex <var>D_i</var>. The edges may be printed in any order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 1 2 2 3 3 4 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 4 3 2 3 4 </pre> <p>After this assignment of directions, Vertex <var>1</var> and <var>3</var> will each have two outgoing edges, and Vertex <var>2</var> and <var>4</var> will each have zero outgoing edges.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 1 2 2 3 3 4 2 5 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre></section> </div> </span>
p03234
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>2N</var> points evenly spaced on the circumference of a circle. These points are numbered <var>1</var> to <var>2N</var> in clockwise order, starting from some of them.</p> <p>Snuke will divide these points into <var>N</var> pairs, then for each pair, he will draw a line segment connecting the two points. After the line segments are drawn, two points are <em>connected</em> when one can reach from one of those points to the other by traveling only on the line segments. <em>The number of the connected parts</em> here is the number of the connected components in the graph with <var>2N</var> vertices, corresponding to the <var>2N</var> points, where every pair of vertices corresponding to two connected points is connected with an edge.</p> <p>Snuke has already decided <var>K</var> of the pairs, and the <var>i</var>-th of them is a pair of Point <var>A_i</var> and Point <var>B_i</var>.</p> <p>He is thinking of trying all possible ways to make the remaining <var>N-K</var> pairs and counting the number of the connected parts for each of those ways. Find the sum of those numbers of the connected parts. As the answer can be extremely large, compute the sum modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300</var></li> <li><var>0 \leq K \leq N</var></li> <li><var>1 \leq A_i,B_i \leq 2N</var></li> <li><var>A_1,\ A_2,\ ...\ A_K,\ B_1,\ B_2,\ ...\ B_K</var> are all distinct.</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>K</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>:</var> <var>A_K</var> <var>B_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the numbers of the connected parts for all possible ways to make the remaining <var>N-K</var> pairs.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are three ways to draw line segments, as shown below, and the number of the connected parts for these ways are <var>2</var>, <var>2</var> and <var>1</var>, respectively. Thus, the answer is <var>2+2+1=5</var>.</p> <p><img alt="" src="https://img.atcoder.jp/agc028/b5dcbaf5c8caf26b4e7e4915954565f7.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 5 2 6 1 </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>20 10 10 18 11 17 14 7 4 6 30 28 19 24 29 22 25 32 38 34 36 39 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>27087418 </pre></section> </div> </span>
p01209
<H1><font color="#000">Problem C:</font> !</H1> <p> You are one of ICPC participants and in charge of developing a library for multiprecision numbers and radix conversion. You have just finished writing the code, so next you have to test if it works correctly. You decided to write a simple, well-known factorial function for this purpose: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_exclamation"> </center> <p> Your task is to write a program that shows the number of trailing zeros when you compute <i>M</i>! in base <i>N</i>, given <i>N</i> and <i>M</i>. </p> <H2>Input</H2> <p> The input contains multiple data sets. Each data set is described by one line in the format below: </p> <pre> <i>N M</i> </pre> <p> where <i>N</i> is a decimal number between 8 and 36 inclusive, and <i>M</i> is given in the string repre- sentation in base <i>N</i>. Exactly one white space character appears between them. </p> <p> The string representation of <i>M</i> contains up to 12 characters in base <i>N</i>. In case <i>N</i> is greater than 10, capital letters A, B, C, ... may appear in the string representation, and they represent 10, 11, 12, ..., respectively. </p> <p> The input is terminated by a line containing two zeros. You should not process this line. </p> <H2>Output</H2> <p> For each data set, output a line containing a decimal integer, which is equal to the number of trailing zeros in the string representation of <i>M</i>! in base <i>N</i>. </p> <H2>Sample Input</H2> <pre> 10 500 16 A 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 124 2 </pre>
p03721
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an empty array. The following <var>N</var> operations will be performed to insert integers into the array. In the <var>i</var>-th operation <var>(1≤i≤N)</var>, <var>b_i</var> copies of an integer <var>a_i</var> are inserted into the array. Find the <var>K</var>-th smallest integer in the array after the <var>N</var> operations. For example, the <var>4</var>-th smallest integer in the array <var>\{1,2,2,3,3,3\}</var> is <var>3</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤N≤10^5</var> </li> <li><var>1≤a_i,b_i≤10^5</var> </li> <li><var>1≤K≤b_1…+…b_n</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format: </p> <pre><var>N</var> <var>K</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_N</var> <var>b_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the <var>K</var>-th smallest integer in the array after the <var>N</var> operations. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 1 1 2 2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The resulting array is the same as the one in the problem statement.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 500000 1 100000 1 100000 1 100000 1 100000 1 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre></section> </div> </span>
p02833
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For an integer <var>n</var> not less than <var>0</var>, let us define <var>f(n)</var> as follows:</p> <ul> <li><var>f(n) = 1</var> (if <var>n &lt; 2</var>)</li> <li><var>f(n) = n f(n-2)</var> (if <var>n \geq 2</var>)</li> </ul> <p>Given is an integer <var>N</var>. Find the number of trailing zeros in the decimal notation of <var>f(N)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq N \leq 10^{18}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of trailing zeros in the decimal notation of <var>f(N)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p><var>f(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080</var>, which has one trailing zero.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p><var>f(5) = 5 × 3 × 1 = 15</var>, which has no trailing zeros.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>124999999999999995 </pre></section> </div> </span>
p02999
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>X</var> and <var>A</var> are integers between <var>0</var> and <var>9</var> (inclusive).</p> <p>If <var>X</var> is less than <var>A</var>, print <var>0</var>; if <var>X</var> is not less than <var>A</var>, print <var>10</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq X, A \leq 9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> <var>A</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>X</var> is less than <var>A</var>, print <var>0</var>; if <var>X</var> is not less than <var>A</var>, print <var>10</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>0 </pre> <p><var>3</var> is less than <var>5</var>, so we should print <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> <p><var>7</var> is not less than <var>5</var>, so we should print <var>10</var>.</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>10 </pre> <p><var>6</var> is not less than <var>6</var>, so we should print <var>10</var>.</p></section> </div> </span>
p03371
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are <var>A</var> yen, <var>B</var> yen and <var>C</var> yen (yen is the currency of Japan), respectively.</p> <p>Nakahashi needs to prepare <var>X</var> A-pizzas and <var>Y</var> B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ A, B, C ≤ 5000</var></li> <li><var>1 ≤ X, Y ≤ 10^5</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum amount of money required to prepare <var>X</var> A-pizzas and <var>Y</var> B-pizzas.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1500 2000 1600 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7900 </pre> <p>It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1500 2000 1900 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8500 </pre> <p>It is optimal to directly buy three A-pizzas and two B-pizzas.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1500 2000 500 90000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>100000000 </pre> <p>It is optimal to buy <var>200000</var> AB-pizzas and rearrange them into <var>100000</var> A-pizzas and <var>100000</var> B-pizzas. We will have <var>10000</var> more A-pizzas than necessary, but that is fine.</p></section> </div> </span>
p02130
<h1>Problem G: Combine Two Elements</h1> <h2>Problem</h2> <p> $N$個の非負整数のペア$(a_i, b_i)$と非負整数$A$, $B$ が与えられる。<br> 以下のいずれかの操作をできるだけたくさん行いたい。<br> <ul> <li>$|a_i - b_i| \leq A$ または $B \leq |a_i - b_i| \leq 2A$を満たす要素$i$を取り出し、削除する</li> <li> $|(a_i + a_j) - (b_i + b_j)| \leq A$ または $B \leq |(a_i + a_j) - (b_i + b_j)| \leq 2A$ を満たす要素$i$と要素$j$ ($i \neq j$)の組を取り出し、削除する</li> </ul> 最大の操作回数を求めよ。<br> </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $N$ $A$ $B$ $a_1$ $b_1$ $a_2$ $b_2$ ... $a_N$ $b_N$ </pre> <p> 入力はすべて整数で与えられる。<br> 1行目に$N$,$A$,$B$が空白区切りで与えられる。<br> 2行目以降の$N$行に$i$個目のペア$a_i$と$b_i$($1 \leq i \leq N$)が空白区切りで与えられる。<br> </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$1 \leq N \leq 800 $</li> <li>$0 \leq A, B \leq 10^5 $ <li>$0 \leq a_i, b_i \leq 10^5$ <li>$A \leq B$ かつ $B \leq 2A$ </ul> <h2>Output</h2> <p> 最大の操作回数を1行に出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 5 3 5 7 2 13 1 1 1 2 9 2 4 </pre> <h2>Sample Output 1</h2> <pre> 4 </pre> <p> (7,2)を選んで削除する。<br> (1,1)を選んで削除する。<br> (2,4)を選んで削除する。<br> (13, 1)と(2, 9)を選んで削除する。<br> 以上のように操作すると4回操作することができ、これが最大となる。 </p> <h2>Sample Input 2</h2> <pre> 10 7 12 34 70 36 0 12 50 76 46 33 45 61 21 0 1 24 3 98 41 23 84 </pre> <h2>Sample Output 2</h2> <pre> 5 </pre>
p02560
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In this problem, you should process <var>T</var> testcases.</p> <p>For each testcase, you are given four integers <var>N, M, A, B</var>.</p> <p>Calculate <var>\sum_{i = 0}^{N - 1} floor((A \times i + B) / M)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq T \leq 100,000</var></li> <li><var>1 \leq N, M \leq 10^9</var></li> <li><var>0 \leq A, B &lt; M</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>T</var> <var>N_0</var> <var>M_0</var> <var>A_0</var> <var>B_0</var> <var>N_1</var> <var>M_1</var> <var>A_1</var> <var>B_1</var> : <var>N_{T - 1}</var> <var>M_{T - 1}</var> <var>A_{T - 1}</var> <var>B_{T - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer for each testcase.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 10 6 3 6 5 4 3 1 1 0 0 31415 92653 58979 32384 1000000000 1000000000 999999999 999999999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 13 0 314095480 499999999500000000 </pre></section> </div> </span>
p00273
<H1>入場料金</H1> <p> アイヅ温泉には、浴場とプールがあり、浴場を利用するには入浴券を、プールを利用するにはプール券をそれぞれ買う必要があります。これらの券の値段は、日によって変わるかもしれません。また、アイヅ温泉には以下のようなルールがあります。 </p> <ul> <li> 券は購入当日1回の利用に限り有効。</li> <li> 「入浴券5枚以上かつプール券2枚以上」でまとめて買うと、すべての券が2割引になる。</li> </ul> <p> 温泉好きの貞吉さんとその友人たちは、アイヅ温泉に毎日のように通っています。彼らは皆気まぐれで、日によって使う枚数は異なります。アイヅ温泉には割引ルールがあるため、グループで協力して上手に買えば、合計料金を安く済ますことができるかもしれません。 </p> <p> 入浴券とプール券の料金、使用する入浴券の枚数とプール券の枚数が入力として与えられたとき、最も安い合計料金を出力するプログラムを作成してください。ただし、使用する枚数より多く券を買うことで合計料金が安くなるなら、買った券すべてを使わなくともよいものとします。 </p> <h2>入力</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>b<sub>1</sub></var> <var>p<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>b<sub>2</sub></var> <var>p<sub>2</sub></var> : <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>b<sub>N</sub></var> <var>p<sub>N</sub></var> </pre> <p> 1行目の<var>N</var>(1 &le; <var>N</var> &le; 365)は料金を計算したい日数である。続く<var>N</var>行に、<var>i</var>日目の入浴券の料金<var>x<sub>i</sub></var>(100 &le; <var>x<sub>i</sub></var> &le; 1000)、プール券の料金<var>y<sub>i</sub></var>(100 &le; <var>y<sub>i</sub></var> &le; 1000)、使用する入浴券の枚数<var>b<sub>i</sub></var>(0 &le; <var>b<sub>i</sub></var> &le; 6)、使用するプール券の枚数<var>p<sub>i</sub></var>(0 &le; <var>p<sub>i</sub></var> &le; 6)が与えられる。入浴券とプール券共に料金は50円刻みである。 </p> <h2>出力</h2> <p> それぞれの日について最も安い合計料金を1行に出力する。 </p> <h2>入力例 1</h2> <pre> 2 100 100 1 1 1000 500 5 2 </pre> <h2>出力例 1</h2> <pre> 200 4800 </pre> <br/> <h2>入力例 2</h2> <pre> 5 500 500 1 1 500 500 5 2 1000 100 0 6 1000 100 6 0 100 1000 0 0 </pre> <h2>出力例 2</h2> <pre> 1000 2800 600 4960 0 </pre>
p00789
<H1><font color="#000">Problem B:</font> Square Coins</H1> <p> People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 17<sup>2</sup>), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland. </p> <p> There are four combinations of coins to pay ten credits: </p> <ul> <li>ten 1-credit coins,</li> <li>one 4-credit coin and six 1-credit coins,</li> <li>two 4-credit coins and two 1-credit coins, and</li> <li>one 9-credit coin and one 1-credit coin.</li> </ul> <p> Your mission is to count the number of ways to pay a given amount using coins of Silverland. </p> <H2>Input</H2> <p> The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300. </p> <H2>Output</H2> <p> For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output. </p> <H2>Sample Input</H2> <pre> 2 10 30 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 4 27 </pre>
p01931
<!-- - - - - - begin nicebody - - - - - --> <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>A: 丸付け</h1> <h2>問題</h2> <p> AORイカちゃんはテストに合格するため勉強しています。 </p> <p> AORイカちゃんは、 $N$ 問、問題を解きました。 その後、解いた問題の丸付けを以下の手順で行います。 </p> <ol> <li>解答の正誤を確認する。</li> <li>解答が正しい場合はマル印、誤っていた場合はバツ印を解答用紙に書き込む。</li> </ol> <p> 解答が $2$ 問連続で誤りであるとわかった瞬間、テストに不合格になってしまう恐怖から、AORイカちゃんは失神してしまいます。そして、それ以降丸付けを行うことはできません。 </p> <p> 失神は手順 $1$ と $2$ の間で起こります。 </p> <p> AORイカちゃんが解いた問題の数を表す整数 $N$ と、解答の正誤を表した長さ $N$ の文字列 $S$ が与えられます。 文字列は 'o' と 'x' からなり、 'o' は解答が正しく、 'x' は解答が誤りであることを表しています。 $i$ 文字目が $i$ 問目の正誤を表しており、AORイカちゃんは $1$ 問目から順番に丸付けを行います。 </p> <p> AORイカちゃんが正誤を書き込めた問題数を出力してください。 </p> <h2>制約</h2> <ul> <li>$1 \leq N \leq 10^5$</li> </ul> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる。 </p> <p> $N$<br> $S$<br> </p> <h2>出力</h2> <p> AORイカちゃんが正誤を書き込めた問題数を $1$ 行で出力せよ。また、末尾に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 3 oxx </pre> <h3>サンプル出力 1</h3> <pre> 2 </pre> <p> $3$ 問目の手順 $1$ を行うと失神するため、手順 $2$ は行えません。 </p> <h3>サンプル入力 2</h3> <pre> 8 oxoxoxox </pre> <h3>サンプル出力 2</h3> <pre> 8 </pre> <h3>サンプル入力 3</h3> <pre> 4 xxxx </pre> <h3>サンプル出力 3</h3> <pre> 1 </pre> <!-- - - - - - end nicebody - - - - - -->
p00623
<H1><font color="#000000">Problem C:</font> Midnight Teatime</H1> <p> ICPCの国内予選に備えて問題を解いていた僕は, その日3つ目のAcceptを貰ったところでキーボードを叩く手を止めた. 時計を見れば, もう日付が変わろうかという時刻だ. 紅茶とお菓子で一服して, 今日はもう寝ることにしよう. そう思って僕はキッチンへと向かった. </p> <p> ダージリンのかぐわしい香りがキッチンを満たした頃, 妹がやってきた. 受験生である彼女は今日もこんな時間まで真面目に勉強していたようだ. 僕は彼女を誘って, 小さな深夜のお茶会を開くことにした. </p> <p> 都合の良いことに, キッチンには4つのお菓子があった. これをただ2人で分けるのもつまらないので, 僕はこのお菓子を賭けて簡単なゲームをしないかと提案した. そのゲームの内容を説明しよう. </p> <p> まず最初に, 僕はどのノードも0個または2個の子を持つような二分木を書く. 次に, その木の葉に当たる(つまり, 子を持たない)ノードに, それぞれ S = {a, b, c, d} の任意の部分集合を書き込む. 4つのお菓子は, それぞれ a, b, c, d に対応する. </p> <p> 最後に妹は, 木の内部接点(つまり、2つの子を持つ)ノードに 'A', 'O', 'X' のいずれかの文字を書き込む. </p> <p> 妹は, 木の根にあたるノードが示すお菓子を得る. ただし, ノードが示すお菓子とは, </p> <ul> <li> そのノードが葉であれば, そこに書かれているお菓子 <li> そのノードが内部接点であれば,</li> <ul> <li> そのノードに書かれた文字が A のとき、 sl と sr の積集合</li> <li> そのノードに書かれた文字が O のとき、 sl と sr の和集合</li> <li> そのノードに書かれた文字が X のとき、 sl と sr の対称差</li> </ul> </ul> <p> のことである. ここで、sl はそのノードの左の子ノードが示すお菓子, sr はそのノードの右の子ノードが示すお菓子を指す. 2つの集合の対称差は, どちらか一方の集合にのみ含まれるような元から成る集合である. </p> <p> このゲームに妹は乗ってきた. それどころか, お菓子を4つとも巻き上げてやろうと目を輝かせている. 出来れば僕の分も残しておいてくれると嬉しいのだけれども. </p> <p> 僕が書いた木に対して, 妹が全てのお菓子を得られるような内部接点の書き込み方は, いったい何通りあるだろうか? </p> <H2>Input</H2> <p> 入力ファイルは、複数のデータセットを含む. </p> <p> データセットの最初の行には, 木の情報が与えられる. 木の記述は, </p> <p> "(" <左部分木の記述> <一つのスペース> <右部分木の記述> ")" </p> <p> または, </p> <p> <一つの数字> </p> <p> のどちらかの形式を取る. 前者が内部接点の記述, 後者が葉の記述である. </p> <p> 次の行は1つの整数 N (N &lt; 10) を含み, 続く N 行に葉に書き込まれた部分集合の情報が与えられる. </p> <p> 部分集合の情報は, 空白文字で区切られた4つの数字で表される. 4つの文字はそれぞれ, その部分集合が a, b, c, d を含むかどうかを表す. 含むならば 1 が、含まないならば 0 が与えられる. </p> <p> 葉の記述として与えられた数字が n であるとき、その葉に書き込まれた部分集合はこれら N 個のうち n 番目のものである. 1 &le; n &le; N と仮定してよい. </p> <p> 与えられる木は、最大 8 個の内部接点を含む. </p> <p> 木の記述の代わりに与えられる "END" という文字列が, 入力の終わりを表す. </p> <H2>Output</H2> <p> 各データセットについて, 妹が全てのお菓子を得られるような内部接点の書き込み方の数を、一行に出力せよ. </p> <H2>Sample Input</H2> <pre> (1 2) 2 0 1 0 1 1 0 1 0 ((1 2) 3) 3 1 1 0 0 1 0 1 0 0 0 0 1 END </pre> <H2>Output for the Sample Input</H2> <pre> 2 2 </pre>
p01462
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Network Reliability</H1> <p> An undirected graph is given. Each edge of the graph disappears with a constant probability. Calculate the probability with which the remained graph is connected. </p> <H2>Input</H2> <p> The first line contains three integers <var>N</var> (<var>1 \leq N \leq 14</var>), <var>M</var> (<var>0 \leq M \leq 100</var>) and <var>P</var> (<var>0 \leq P \leq 100</var>), separated by a single space. <var>N</var> is the number of the vertices and <var>M</var> is the number of the edges. <var>P</var> is the probability represented by a percentage. </p> <p> The following <var>M</var> lines describe the edges. Each line contains two integers <var>v_i</var> and <var>u_i</var> (<var>1 \leq u_i, v_i \leq N</var>). (<var>u_i, v_i</var>) indicates the edge that connects the two vertices <var>u_i</var> and <var>v_i</var>. </p> <H2>Output</H2> <p> Output a line containing the probability with which the remained graph is connected. Your program may output an arbitrary number of digits after the decimal point. However, the absolute error should be <var>10^{-9}</var> or less. </p> <H2>Sample Input 1</H2> <pre> 3 3 50 1 2 2 3 3 1 </pre> <H2>Output for the Sample Input 1</H2> <pre> 0.500000000000 </pre> <H2>Sample Input 2</H2> <pre> 3 3 10 1 2 2 3 3 1 </pre> <H2>Output for the Sample Input 2</H2> <pre> 0.972000000000 </pre> <H2>Sample Input 3</H2> <pre> 4 5 50 1 2 2 3 3 4 4 1 1 3 </pre> <H2>Output for the Sample Input 3</H2> <pre> 0.437500000000 </pre>
p01198
<H1><font color="#000"></font>Dock to the Future</H1> <!-- Problem A --> <p> You had long wanted a spaceship, and finally you bought a used one yesterday! You have heard that the most difficult thing on spaceship driving is to stop your ship at the right position in the dock. Of course you are no exception. After a dozen of failures, you gave up doing all the docking process manually. You began to write a simple program that helps you to stop a spaceship. </p> <p> First, you somehow put the spaceship on the straight course to the dock manually. Let the distance to the limit line be <i>x</i>[m], and the speed against the dock be <i>v</i>[m/s]. Now you turn on the decelerating rocket. Then, your program will control the rocket to stop the spaceship at the best position. </p> <p> Your spaceship is equipped with a decelerating rocket with n modes. When the spaceship is in mode-<i>i</i> (0 &le; <i>i</i> &lt; <i>n</i>), the deceleration rate is <i>a<sub>i</sub></i>[m/s<sup>2</sup>]. You cannot re-accelerate the spaceship. The accelerating rocket is too powerful to be used during docking. Also, you cannot turn off-and-on the decelerating rocket, because your spaceship is a used and old one, once you stopped the rocket, it is less certain whether you can turn it on again. In other words, the time you turn off the rocket is the time you stop your spaceship at the right position. </p> <p> After turning on the deceleration rocket, your program can change the mode or stop the rocket at every sec- ond, starting at the very moment the deceleration began. Given <i>x</i> and <i>v</i>, your program have to make a plan of deceleration. The purpose and the priority of your program is as follows: </p> <ol> <li> Stop the spaceship exactly at the limit line. If this is possible, print “perfect”.</li> <li> If it is impossible, then stop the spaceship at the position nearest possible to the limit line, but <i>before</i> the line. In this case, print “good <i>d</i>”, where <i>d</i> is the distance between the limit line and the stopped position. Print three digits after the decimal point.</li> <li> If it is impossible again, decelerate the spaceship to have negative speed, and print “try again”.</li> <li> If all of these three cases are impossible, then the spaceship cannot avoid overrunning the limit line. In this case, print “crash”.</li> </ol> <H2>Input</H2> <p> The first line of the input consists of a single integer <i>c</i>, the number of test cases. </p> <p> Each test case begins with a single integer <i>n</i> (1 &le; <i>n</i> &le; 10), the number of deceleration modes. The following line contains <i>n</i> positive integers <i>a</i><sub>0</sub>, . . . , <i>a</i><sub>n-1</sub> (1 &le; <i>a<sub>i</sub></i> &le; 100), each denoting the deceleration rate of each mode. </p> <p> The next line contains a single integer <i>q</i> (1 &le; <i>q</i> &le; 20), and then <i>q</i> lines follow. Each of them contains two positive integers <i>x</i> and <i>v</i> (1 &le; <i>x</i>, <i>v</i> &le; 100) defined in the problem statement. </p> <H2>Output</H2> <p> For each pair of <i>x</i> and <i>v</i>, print the result in one line. A blank line should be inserted between the test cases. </p> <H2>Sample Input</H2> <pre> 1 3 2 4 6 4 10 100 2 3 10 6 7 6 </pre> <H2>Output for the Sample Input</H2> <pre> crash try again good 1.000 perfect </pre>
p01032
<h1>Problem E: Rooted Tree Game</h1> <h2>Problem</h2> <p> 初期状態として複数の根付き木が与えられる。これに対しAliceとBobはゲームを行う。ゲームは2人交互に行い、先手がAliceで後手がBobである。ターンが回ってきたプレイヤーは以下の行動を取る。 </p> <ol> <li>根(親を持たない頂点)を1つ選択する。この頂点を<var>S</var>とする。</li> <li><var>S</var>を根とする根付き木に含まれる頂点を選択する(ここでは<var>S</var>も選択可能)。この頂点を<var>T</var>とする。</li> <li><var>S</var>から<var>T</var>への経路上にある頂点を、<var>S</var>と<var>T</var>も含めすべて削除する。また、削除された頂点が端点であるような辺もすべて削除する。</li> </ol> <p> ターンが回ってきた時点で頂点がすべて削除されていた場合、そのプレイヤーの負けとなる。 </p> <p> AliceとBobが常に最適な行動を取る時、与えられた初期状態に対し、勝利するプレイヤーを判定せよ。 </p> <p> 以下の図は、プレイヤーの行動の例を示す。<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_AizuCamp14_Day2_E_img.png" width="700" alt="プレイヤーの行動の例"> </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>M</var> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> : <var>p<sub>M</sub></var> </pre> <p> 1行目に、初期状態の頂点数<var>N</var>と辺の数<var>M</var>が空白区切りで与えられる。この時、各頂点を表す番号は1~<var>N</var>である。次の<var>M</var>行では、辺の情報が与えられる。このうち<var>i</var>行目では1つの整数<var>p<sub>i</sub></var>が与えられる。これは、頂点<var>p<sub>i</sub></var>から頂点<var>i</var>への辺があることを表す。言い換えると、頂点<var>i</var>の親が頂点<var>p<sub>i</sub></var>であることを表す。 </p> <h2>Constraints</h2> <p> 入力は以下の制約を満たす。 </p> <ul> <li>1 &le; <var>N</var> &le; 1000</li> <li>0 &le; <var>M</var> &lt; N</li> <li><var>i</var> &lt; <var>p<sub>i</sub></var> &le; N ( 1 &le; <var>i</var> &le; <var>M</var> )</li> </ul> <h2>Output</h2> <p> 勝利するプレイヤーの名前(AliceまたはBob)を1行に出力せよ。 </p> <h2>Sample Input1</h2> <pre> 6 3 4 4 5 </pre> <h2>Sample Output1</h2> <pre> Alice </pre> <h2>Sample Input2</h2> <pre> 6 4 2 5 4 5 </pre> <h2>Sample Output2</h2> <pre> Bob </pre>
p01527
<h1>H - 植林</h1> <h2>問題文</h2> <p> とある大学の魔法学部の生徒であるK君は広大な屋敷に住んでいる. 屋敷の裏には林が広がっていたが,所々木が生えていない箇所があった. このままでは屋敷からの見た目が悪いと感じたので,K君は木が生えていない箇所に木を植えることに決めた. 魔法使いの卵であるK君は使い魔を召喚することが出来るので,植林の作業を使い魔にやらせようと考えた. </p> <p> 林は <var>H &times; W</var> 個のセルを持つ長方形領域とみなすことが出来る. 各セルは木が1本生えているか1本も生えていないかのどちらかである. K君はこの <var>H &times; W</var> 個のセルのどれか 1 つを指定し,そこに使い魔を召喚する. しかしK君はまだ未熟者なので,魔力を調節することが出来ず,使い魔を召喚するときは必ず 5 匹召喚してしまう. さらに悪いことに,K君が召喚する使い魔はひねくれもので,訪れたセルに木が生えていない場合はそこに木を植えるが,訪れたセルに既に木が生えている場合はそのセルの木を消してしまう. 召喚された使い魔のうちの 4 匹は,指定されたセルを始点として東西南北に散らばり1直線上を進み,1つ1つセルを訪れていく.これらの使い魔は林の外に出ると消える. 残りの使い魔は指定されたセルのみを訪問し,その後直ちに消える. </p> <p> より正確に言えば,K君がセル <var>(i, j)</var> に使い魔を召喚すると,<var>i</var> 行目か或いは <var>j</var> 列目にある <var>H+W-1</var> 個のセルに対し, 木が生えていなければ木が植えられ,木が生えていれば木が消されるという操作が行われる. </p> <p> 召喚には多くの魔力を必要とするので,出来るだけ少ない召喚回数で林を木で覆いつくしたい. K君はどのセルに使い魔を召喚すれば最小の召喚回数で林を木で覆いつくすことが出来るだろうか. </p> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる. </p> <pre><var>H</var> <var>W</var> <var>a<sub>1,1</sub></var> ... <var>a<sub>1,W</sub></var> ... <var>a<sub>H,1</sub></var> ... <var>a<sub>H,W</sub></var> </pre> <p> <var>a<sub>i,j</sub></var> が <var>1</var> ならセル <var>(i,j)</var> に木が生えていることを意味し, <var>0</var>なら生えていないことを意味する. </p> <h2>出力形式</h2> <p> もし林を木で覆いつくすことが不可能なら,1行に <code>Impossible</code> を出力せよ. そうでなければ,召喚回数を最小にするような召喚手順を以下の形式で <var>H</var> 行に出力せよ. </p> <pre><var> b<sub>1,1</sub> ... b<sub>1,W</sub> ... b<sub>H,1</sub> ... b<sub>H,W</sub> </var> </pre> <p> <var>b<sub>i,j</sub></var> は <var>0</var> もしくは <var>1</var> でなければならず, <var>1</var> ならセル <var>(i,j)</var> に使い魔を召喚する事を意味し,<var>0</var> なら召喚しない事を意味する. </p> <p> 2回同じ場所に使い魔を召喚しても意味が無いことに注意せよ.召喚回数を最小にするような召喚手順が複数ある場合はどれを出力しても良い. </p> <h2>制約</h2> <ul> <li><var>2 &le; H,W &le; 1000</var></li> <li><var>H,W</var> は偶数</li> <li><var>a<sub>i,j</sub> &isin; {0, 1}</var></li> </ul> <p> この問題の判定には,3 点分のテストケースのグループが設定されている. このグループに含まれるテストケースは上記の制約に加えて下記の制約も満たす. </p> <ul> <li><var>H &times; W &le; 20</var></li> </ul> <h2>入出力例</h2> <h3>入力例 1</h3> <pre> 4 4 0 0 0 1 0 1 1 0 0 1 1 0 1 0 0 0 </pre> <h3>出力例 1</h3> <pre> 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 </pre> <p> セル <var>(1,1)</var> とセル <var>(4,4)</var> に使い魔を召喚することで林を木で覆いつくすことが出来る. </p> <hr> <address>Writer: 田村和範</address> <address>Tester: 花田裕一朗</address>
p01177
<H1><font color="#000">Problem G:</font> Entangled Tree</H1> <p> The electronics division in Ishimatsu Company consists of various development departments for electronic devices including disks and storages, network devices, mobile phones, and many others. Each department covers a wide range of products. For example, the department of disks and storages develops internal and external hard disk drives, USB thumb drives, solid-state drives, and so on. This situation brings staff in the product management division difficulty categorizing these numerous products because of their poor understanding of computer devices. </p> <p> One day, a staff member suggested a tree-based diagram named a <i>category diagram</i> in order to make their tasks easier. A category diagram is depicted as follows. Firstly, they prepare one large sheet of paper. Secondly, they write down the names of the development departments on the upper side of the sheet. These names represent the <i>start nodes</i> of the diagram. Each start node is connected to either a single <i>split node</i> or a single end node (these nodes will be mentioned soon later). Then they write down a number of questions that distinguish features of products in the middle, and these questions represent the split nodes of the diagram. Each split node is connected with other split nodes and end nodes, and each line from a split node is labeled with the answer to the question. Finally, they write down all category names on the lower side, which represents the <i>end nodes</i>. </p> <p> The classification of each product is done like the following. They begin with the start node that corresponds to the department developing the product. Visiting some split nodes, they traces the lines down until they reach one of the end nodes labeled with a category name. Then they find the product classified into the resultant category. </p> <p> The visual appearance of a category diagram makes the diagram quite understandable even for non-geek persons. However, product managers are not good at drawing the figures by hand, so most of the diagrams were often messy due to many line crossings. For this reason, they hired you, a talented programmer, to obtain the <i>clean diagrams</i> equivalent to their diagrams. Here, we mean the clean diagrams as those with no line crossings. </p> <p> Your task is to write a program that finds the clean diagrams. For simplicity, we simply ignore the questions of the split nodes, and use integers from 1 to <i>N</i> instead of the category names. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset follows the format below: </p> <pre> <i>N M Q</i> <i>split node info</i><sub>1</sub> <i>split node info</i><sub>2</sub> ... <i>split node info</i><sub><i>M</i></sub> <i>query</i><sub>1</sub> <i>query</i><sub>2</sub> ... <i>query</i><sub><i>Q</i></sub> </pre> <p> The first line of each dataset contains three integers <i>N</i> (1 &le; <i>N</i> &le; 100000), <i>M</i> (0 &le; <i>M</i> &le; <i>N</i> - 1), and <i>Q</i> (1 &le; <i>Q</i> &le; 1000, <i>Q</i> &le; <i>N</i>), representing the number of end nodes and split nodes, and the number of queries respectively. Then <i>M</i> lines describing the split nodes follow. Each split node is described in the format below: </p> <pre> <i>Y L label</i><sub>1</sub> <i>label</i><sub>2</sub> . . . </pre> <p> The first two integers, <i>Y</i> (0 &le; <i>Y</i> &le; 10<sup>9</sup> ) and <i>L</i>, which indicates the <i>y</i>-coordinate where the split node locates (the smaller is the higher) and the size of a label list. After that, <i>L</i> integer numbers of end node labels which directly or indirectly connected to the split node follow. This is a key information for node connections. A split node A is connected to another split node B if and only if both A and B refer (at least) one identical end node in their label lists, and the y-coordinate of B is the lowest of all split nodes referring identical end nodes and located below A. The split node is connected to the end node if and only if that is the lowest node among all nodes which contain the same label as the end node’s label. The start node is directly connected to the end node, if and only if the end node is connected to none of the split nodes. </p> <p> After the information of the category diagram, <i>Q</i> lines of integers follow. These integers indicate the horizontal positions of the end nodes in the diagram. The leftmost position is numbered 1. </p> <p> The input is terminated by the dataset with <i>N</i> = <i>M</i> = <i>Q</i> = 0, and this dataset should not be processed. </p> <H2>Output</H2> <p> Your program must print the <i>Q</i> lines, each of which denotes the label of the end node at the position indicated by the queries in the clean diagram. One blank line must follow after the output for each dataset. </p> <H2>Sample Input</H2> <pre> 3 2 3 10 2 1 2 20 2 3 2 1 2 3 5 2 5 10 3 1 2 4 20 3 2 3 5 1 2 3 4 5 4 1 4 10 2 1 4 1 2 3 4 4 3 4 30 2 1 4 20 2 2 4 10 2 3 4 1 2 3 4 4 3 4 10 2 1 4 20 2 2 4 30 2 3 4 1 2 3 4 4 3 4 10 2 1 2 15 2 1 4 20 2 2 3 1 2 3 4 3 2 3 10 2 2 3 20 2 1 2 1 2 3 1 0 1 1 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 3 1 2 3 5 4 1 4 2 3 1 4 2 3 1 2 3 4 1 4 2 3 1 2 3 1 </pre>
p00336
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>繰り返す呪文</H1> <p> 古代国家イワシロを発見し調査を進めた我々研究者は、ついにイワシロの中心部にある神殿を発見した。神殿にはイワシロの神にささげた石版が保管されていた。石版には、文章と呪文が一つずつ、2つの文字列が書かれていた。 </p> <p> イワシロでは呪文が文章の中に、何回現れるかが重要な意味を持つ。ただし、呪文に含まれるすべての文字が順番に、文章の中にとびとびで現れるものも1回現れていると考える。例えば、文章が"abab" で、呪文が "ab" であれば、連続でないものも含めて "ab" は "abab" の中に3回現われている( <u>ab</u>ab, ab<u>ab</u>, <u>a</u>ba<u>b</u> の3通り)。 </p> <p> 文章と呪文が与えられたとき、呪文が文章の中に何回現れるかを出力するプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>t</var> <var>b</var> </pre> <p> 1行目に、石版に書かれた文章を表す文字列tが与えられる。2行目に、石版に書かれた呪文を表す文字列bが与えられる。どちらの文字列も英小文字だけから成る、長さが1以上1000以下の文字列である。 </p> <h2>Output</h2> <p> 呪文が文章の中に何回現れるかを1行に出力する。ただし、出力すべき値は非常に大きくなりうるので、代わりに 1,000,000,007 で割った余りを出力する。 </p> <h2>Sample Input 1</h2> <pre> abab ab </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <br/> <h2>Sample Input 2</h2> <pre> aaaabaaaabaaaabaaaab aaaaa </pre> <h2>Sample Output 2</h2> <pre> 4368 </pre> <br> <h2>Sample Input 3</h2> <pre> data structure </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p01874
<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script> <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> <h2>C: 成長する点 - Growing Point -</h2> <h3>問題</h3> <p> 粘菌コンピュータというものがある。 ある種の粘菌には「餌を求め、餌と餌の最短距離をつなぐ形に変形する」 という性質がある。 これを利用し、餌を「入力」、形を「出力」とみなして コンピュータとして利用することができる。 </p> <p> 今、二次元平面上に1つの粘菌の拠点と<var>N</var>個の餌が存在する。それぞれの餌には<var>1</var>から<var>N</var>までの異なる番号が与えられ、拠点には番号0が与えられている。 この粘菌はある餌を食べるために、その餌と最も近い拠点の最短距離を結ぶ管状に 成長し、食べた位置に新たに拠点を形成する。 新たに形成した拠点は拠点を形成する直前に食べた餌と同じ番号を持つ。 粘菌は拠点以外の場所から成長することはできない。 以降では、拠点と餌を二次元平面上の点、管状に成長した粘菌を複数の線分として考える。 </p> <p> すべての拠点と線分からなる構造を粘菌網と呼ぶ。 粘菌は1つの餌を食べるために次のような操作を繰り返す。 </p> <ol> <li>まだ食べていない餌の中で粘菌網に最も近い餌を選ぶ。そのような餌が複数存在する場合は番号が最も小さい餌を選ぶ。</li> <li>選んだ餌と最も近い拠点を選ぶ。そのような拠点が複数存在する場合は、最も拠点の番号が小さいものから取る。</li> <li>選んだ拠点と餌を結ぶ線分を引く。以降ではこのとき選んだ餌も拠点として扱う。</li> </ol> <p> この粘菌は生きるために必要な栄養を取るのに<var>M</var>個の餌を食べる必要がある。 粘菌が<var>M</var>個の餌を食べるまでに引いたすべての線分の長さの合計を求めよ。 また、出力する値は0.0001以下の誤差を含んでいても良い。 </p> <p>以下の図では入力例2の粘菌の様子を示している。</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_HUPC20160308_c1" type="image/jpeg" width="320"></img> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_HUPC20160308_c2" type="image/jpeg" width="320"></img> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_HUPC20160308_c3" type="image/jpeg" width="320"></img> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_HUPC20160308_c4" type="image/jpeg" width="320"></img> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_HUPC20160308_c5" type="image/jpeg" width="320"></img> <h3>入力形式</h3> <pre> <var>N</var> <var>M</var> <var>X</var> <var>Y</var> <var>px_1</var> <var>py_1</var> ... <var>px_n</var> <var>py_n</var> </pre> <p> <var>1</var>行目には餌の数<var>N</var>(<var>1 \&le; N \&le; 5,000</var>)、食べる餌の個数<var>M</var> (<var>1 \&le; M \&le; N</var>)、番号0の拠点の座標<var>X</var>, <var>Y</var>(<var>&minus;5,000 \&le; X, Y \&le; 5,000</var>)が整数値で与えられる。続く<var>N</var>行には番号順に餌の座標<var>px_i</var>, <var>py_i</var>(<var>1 \&le; i \&le; N</var>)が整数値で与えられる。(<var>&minus;5,000 \&le; px_i, py_i \&le; 5,000</var>) また、番号が異なる餌は異なる座標に存在し、それぞれの餌と番号0の拠点の座標は異なる。 </p> <h3>出力形式</h3> <p>成長した距離の合計を1行で出力せよ。また、出力する値は0.0001以下の誤差を含んでいても良い。</p> <h3>入力例1</h3> <pre> 2 2 0 0 3 3 4 0 </pre> <h3>出力例1</h3> <pre>7.16227766017</pre> <p> 最初は番号1の餌と拠点の距離が $3\sqrt{2}$ と番号2の餌と拠点の距離が<var>4</var>なので 番号2の餌が選ばれる。その後番号1の餌と粘菌網との距離が<var>3</var>になり、番号1の餌が選ばれる。 </p> <h3>入力例2</h3> <pre> 4 4 1 3 3 3 2 1 3 1 1 1 </pre> <h3>出力例2</h3> <pre>6.2360679775</pre> <p>図のように餌1、2、4、3の順に粘菌は餌を食べていく</p> <h3>入力例3</h3> <pre> 16 15 -4077 763 -2480 2841 -2908 -1096 676 -4080 -4988 -2634 3004 -1360 -2272 1773 -4344 -3631 -355 4426 -3740 3634 -3330 2191 -3423 -2999 -3438 2281 4754 -1500 -3440 -3873 -2089 -3419 1426 2793 </pre> <h3>出力例3</h3> <pre>25349.9626798834</pre>
p03849
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a positive integer <var>N</var>. Find the number of the pairs of integers <var>u</var> and <var>v</var> <var>(0≦u,v≦N)</var> such that there exist two non-negative integers <var>a</var> and <var>b</var> satisfying <var>a</var> <var>xor</var> <var>b=u</var> and <var>a+b=v</var>. Here, <var>xor</var> denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^{18}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the possible pairs of integers <var>u</var> and <var>v</var>, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>The five possible pairs of <var>u</var> and <var>v</var> are:</p> <ul> <li> <p><var>u=0,v=0</var> (Let <var>a=0,b=0</var>, then <var>0</var> <var>xor</var> <var>0=0</var>, <var>0+0=0</var>.)</p> </li> <li> <p><var>u=0,v=2</var> (Let <var>a=1,b=1</var>, then <var>1</var> <var>xor</var> <var>1=0</var>, <var>1+1=2</var>.)</p> </li> <li> <p><var>u=1,v=1</var> (Let <var>a=1,b=0</var>, then <var>1</var> <var>xor</var> <var>0=1</var>, <var>1+0=1</var>.)</p> </li> <li> <p><var>u=2,v=2</var> (Let <var>a=2,b=0</var>, then <var>2</var> <var>xor</var> <var>0=2</var>, <var>2+0=2</var>.)</p> </li> <li> <p><var>u=3,v=3</var> (Let <var>a=3,b=0</var>, then <var>3</var> <var>xor</var> <var>0=3</var>, <var>3+0=3</var>.)</p> </li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1422 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>52277 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>787014179 </pre></section> </div> </span>
p00766
<h1>Patisserie ACM</h1> <!-- end en only --> <!-- begin en only --> <p> Amber Claes Maes, a patissier, opened her own shop last month. She decided to submit her work to the International Chocolate Patissier Competition to promote her shop, and she was pursuing a recipe of sweet chocolate bars. After thousands of trials, she finally reached the recipe. However, the recipe required high skill levels to form chocolate to an orderly rectangular shape. Sadly, she has just made another strange-shaped chocolate bar as shown in Figure G-1. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1185_1"><br> <!-- begin en only --> <p>Figure G-1: A strange-shaped chocolate bar</p> <!-- end en only --> </center> <!-- begin en only --> <p> Each chocolate bar consists of many small rectangular segments of chocolate. Adjacent segments are separated with a groove in between them for ease of snapping. She planned to cut the strange-shaped chocolate bars into several rectangular pieces and sell them in her shop. She wants to cut each chocolate bar as follows. <ul> <li>The bar must be cut along grooves.</li> <li>The bar must be cut into rectangular pieces.</li> <li>The bar must be cut into as few pieces as possible.</li> </ul> Following the rules, Figure G-2 can be an instance of cutting of the chocolate bar shown in Figure G-1. Figures G-3 and G-4 do not meet the rules; Figure G-3 has a non-rectangular piece, and Figure G-4 has more pieces than Figure G-2. </p> <!-- end en only --> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1185_2"><br> <!-- begin en only --> <p>Figure G-2: An instance of cutting that follows the rules</p> <!-- end en only --> <br><br> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1185_3"><br> <!-- begin en only --> <p>Figure G-3: An instance of cutting that leaves a non-rectangular piece</p> <!-- end en only --> <br><br> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1185_4"><br> <!-- begin en only --> <p>Figure G-4: An instance of cutting that yields more pieces than Figure G-2</p> <!-- end en only --> </center> <!-- begin en only --> <p> Your job is to write a program that computes the number of pieces of chocolate after cutting according to the rules. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows. <blockquote> <i>h</i> <i>w</i><br> <i>r</i><sub>(1, 1)</sub> ... <i>r</i><sub>(1, <i>w</i>)</sub><br> <i>r</i><sub>(2, 1)</sub> ... <i>r</i><sub>(2, <i>w</i>)</sub><br> ...<br> <i>r</i><sub>(<i>h</i>, 1)</sub> ... <i>r</i><sub>(<i>h</i>, <i>w</i>)</sub><br> </blockquote> The integers <i>h</i> and <i>w</i> are the lengths of the two orthogonal dimensions of the chocolate, in number of segments. You may assume that 2 &le; <i>h</i> &le; 100 and 2 &le; <i>w</i> &le; 100. Each of the following <i>h</i> lines consists of <i>w</i> characters, each is either a &quot;<t>.</t>&quot; or a &quot;<t>#</t>&quot;. The character <i>r</i><sub>(<i>i</i>, <i>j</i>)</sub> represents whether the chocolate segment exists at the position (<i>i</i>, <i>j</i> ) as follows. <ul> <li>&quot;<t>.</t>&quot;: There is no chocolate.</li> <li>&quot;<t>#</t>&quot;: There is a segment of chocolate.</li> </ul> You can assume that there is no dataset that represents either multiple disconnected bars as depicted in Figure G-5 or a bar in a shape with hole(s) as depicted in Figure G-6 and G-7. You can also assume that there is at least one &quot;<t>#</t>&quot; character in each dataset. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1185_5"><br> <!-- begin en only --> <p>Figure G-5: Disconnected chocolate bars</p> <!-- end en only --> <br><br> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1185_6"><br> <!-- begin en only --> <p>Figure G-6: A chocolate bar with a hole</p> <!-- end en only --> <br><br> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1185_7"><br> <!-- begin en only --> <p>Figure G-7: Another instance of a chocolate bar with a hole</p> <!-- end en only --> </center> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a line containing the integer representing the number of chocolate pieces obtained by cutting according to the rules. No other characters are allowed in the output. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 3 5 ###.# ##### ###.. 4 5 .#.## .#### ####. ##.#. 8 8 .#.#.#.# ######## .######. ######## .######. ######## .######. ######## 8 8 .#.#.#.# ######## .##.#.#. ##....## .##.###. ##...### .##.###. ###.#.## 4 4 #### #### #### #### 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 3 5 11 19 1 </pre>
p03799
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke loves puzzles.</p> <p>Today, he is working on a puzzle using <code>S</code>- and <code>c</code>-shaped pieces. In this puzzle, you can combine two <code>c</code>-shaped pieces into one <code>S</code>-shaped piece, as shown in the figure below:</p> <div style="text-align: center;"> <img alt="9b0bd546db9f28b4093d417b8f274124.png" src="https://atcoder.jp/img/arc069/9b0bd546db9f28b4093d417b8f274124.png"> </img></div> <p>Snuke decided to create as many <code>Scc</code> groups as possible by putting together one <code>S</code>-shaped piece and two <code>c</code>-shaped pieces.</p> <p>Find the maximum number of <code>Scc</code> groups that can be created when Snuke has <var>N</var> <code>S</code>-shaped pieces and <var>M</var> <code>c</code>-shaped pieces.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N,M ≤ 10^{12}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> </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>1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Two <code>Scc</code> groups can be created as follows:</p> <ul> <li>Combine two <code>c</code>-shaped pieces into one <code>S</code>-shaped piece</li> <li>Create two <code>Scc</code> groups, each from one <code>S</code>-shaped piece and two <code>c</code>-shaped pieces</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>12345 678901 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>175897 </pre></section> </div> </span>
p03263
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid of square cells with <var>H</var> horizontal rows and <var>W</var> vertical columns. The cell at the <var>i</var>-th row and the <var>j</var>-th column will be denoted as Cell <var>(i, j)</var>.</p> <p>In Cell <var>(i, j)</var>, <var>a_{ij}</var> coins are placed.</p> <p>You can perform the following operation any number of times:</p> <p>Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.</p> <p>Maximize the number of cells containing an even number of coins.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq H, W \leq 500</var></li> <li><var>0 \leq a_{ij} \leq 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>H</var> <var>W</var> <var>a_{11}</var> <var>a_{12}</var> <var>...</var> <var>a_{1W}</var> <var>a_{21}</var> <var>a_{22}</var> <var>...</var> <var>a_{2W}</var> <var>:</var> <var>a_{H1}</var> <var>a_{H2}</var> <var>...</var> <var>a_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:</p> <pre><var>N</var> <var>y_1</var> <var>x_1</var> <var>y_1'</var> <var>x_1'</var> <var>y_2</var> <var>x_2</var> <var>y_2'</var> <var>x_2'</var> <var>:</var> <var>y_N</var> <var>x_N</var> <var>y_N'</var> <var>x_N'</var> </pre> <p>That is, in the first line, print an integer <var>N</var> between <var>0</var> and <var>H \times W</var> (inclusive), representing the number of operations.</p> <p>In the <var>(i+1)</var>-th line (<var>1 \leq i \leq N</var>), print four integers <var>y_i, x_i, y_i'</var> and <var>x_i'</var> (<var>1 \leq y_i, y_i' \leq H</var> and <var>1 \leq x_i, x_i' \leq W</var>), representing the <var>i</var>-th operation. These four integers represents the operation of moving one of the coins placed in Cell <var>(y_i, x_i)</var> to a vertically or horizontally adjacent cell, <var>(y_i', x_i')</var>.</p> <p>Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in <em>Wrong Answer</em>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 1 2 3 0 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 2 2 2 3 1 1 1 2 1 3 1 2 </pre> <p>Every cell contains an even number of coins after the following sequence of operations:</p> <ul> <li>Move the coin in Cell <var>(2, 2)</var> to Cell <var>(2, 3)</var>.</li> <li>Move the coin in Cell <var>(1, 1)</var> to Cell <var>(1, 2)</var>.</li> <li>Move one of the coins in Cell <var>(1, 3)</var> to Cell <var>(1, 2)</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 1 0 2 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 1 1 1 2 1 2 2 2 3 1 3 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 5 9 9 9 9 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 1 1 1 2 1 3 1 4 </pre></section> </div> </span>
p03633
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> clocks. The hand of the <var>i</var>-th clock <var>(1≤i≤N)</var> rotates through <var>360°</var> in exactly <var>T_i</var> seconds.<br/> Initially, the hand of every clock stands still, pointing directly upward.<br/> Now, Dolphin starts all the clocks simultaneously.<br/> In how many seconds will the hand of every clock point directly upward again?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤N≤100</var> </li> <li><var>1≤T_i≤10^{18}</var> </li> <li>All input values are integers. </li> <li>The correct answer is at most <var>10^{18}</var> seconds.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format: </p> <pre><var>N</var> <var>T_1</var> <var>:</var> <var>T_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of seconds after which the hand of every clock point directly upward again.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>We have two clocks. The time when the hand of each clock points upward is as follows:</p> <ul> <li>Clock <var>1</var>: <var>2</var>, <var>4</var>, <var>6</var>, <var>...</var> seconds after the beginning</li> <li>Clock <var>2</var>: <var>3</var>, <var>6</var>, <var>9</var>, <var>...</var> seconds after the beginning</li> </ul> <p>Therefore, it takes <var>6</var> seconds until the hands of both clocks point directly upward.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 5 10 1000000000000000000 1000000000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000000000000000 </pre></section> </div> </span>
p02921
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You will be given a string <var>S</var> of length <var>3</var> representing the weather forecast for three days in the past.</p> <p>The <var>i</var>-th character <var>(1 \leq i \leq 3)</var> of <var>S</var> represents the forecast for the <var>i</var>-th day. <code>S</code>, <code>C</code>, and <code>R</code> stand for sunny, cloudy, and rainy, respectively.</p> <p>You will also be given a string <var>T</var> of length <var>3</var> representing the actual weather on those three days.</p> <p>The <var>i</var>-th character <var>(1 \leq i \leq 3)</var> of <var>S</var> represents the actual weather on the <var>i</var>-th day. <code>S</code>, <code>C</code>, and <code>R</code> stand for sunny, cloudy, and rainy, respectively.</p> <p>Print the number of days for which the forecast was correct.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> and <var>T</var> are strings of length <var>3</var> each.</li> <li><var>S</var> and <var>T</var> consist of <code>S</code>, <code>C</code>, and <code>R</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of days for which the forecast was correct.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>CSS CSR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <ul> <li>For the first day, it was forecast to be cloudy, and it was indeed cloudy.</li> <li>For the second day, it was forecast to be sunny, and it was indeed sunny.</li> <li>For the third day, it was forecast to be sunny, but it was rainy.</li> </ul> <p>Thus, the forecast was correct for two days in this case.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>SSR SSR </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>RRR SSS </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p02188
<h2>G: Restricted DFS</h2> <h3>問題</h3> <p><var>N</var> 頂点 <var>N-1</var> 辺からなる、自己ループや多重辺が存在しない無向木 <var>G</var> がある。頂点はそれぞれ <var>1</var> から <var>N</var> まで番号付けされており、辺もそれぞれ <var>1</var> から <var>N-1</var> まで番号付けされており、<var>i</var> 番目の辺は <var>u_i</var> と <var>v_i</var> を結んでいる。また、<var>i</var> 番目の頂点には非負整数 <var>A_i</var> がそれぞれ割り当てられている。</p> <p>この木に対して、根 <var>r</var> から以下の擬似コードにしたがって DFS (深さ優先探索) を行うことを考える。</p> <pre>// [input] // G: dfs の対象となるグラフ // A: それぞれの頂点に割り当てられた非負整数 // v: dfs を開始する頂点 // step: ステップ数を記録する整数 // [output] // 以下のうちどちらかの二値 // - SUCCESS: dfs が途中で終了することなく、頂点 v まで戻ってくる // - FAILURE: dfs が途中で終了する function dfs(G, A, v, step) if (A[v] が 0 である) then return FAILURE A[v] ← A[v] - 1 step ← step + 1 v の子を頂点番号が小さい順にソート // c は頂点番号が小さい順に見られる for each (v の子 c) do if (dfs(G, A, c, step) が FAILURE である) then return FAILURE if (A[v] が 0 である) then return FAILURE A[v] ← A[v] - 1 step ← step + 1 return SUCCESS </pre> <p>つまり、与えられた <var>G</var> と <var>A</var> に対して、根 <var>r</var> について</p> <pre>dfs(G, A, r, 0)</pre> <p>を実行することを考える。</p> <p>それぞれの頂点を根としたときの、この DFS のステップ数を求めよ。</p> <h3>入力形式</h3> <pre> <var>N</var> <var>A_1</var> ... <var>A_N</var> <var>u_1</var> <var>v_1</var> ... <var>u_{N-1}</var> <var>v_{N-1}</var> </pre> <ul> <li> <var>1</var> 行目では、与えられるグラフの頂点数 <var>N</var> が与えられる。</li> <li> <var>2</var> 行目は <var>N</var> 個の整数からなる。<var>i</var> 個目の整数 <var>A_i</var> は、<var>i</var> 番目の頂点に書かれている値を表す。</li> <li> <var>3</var> 行目から <var>N+1</var> 行目までは、与えられるグラフの辺の情報が与えられる。<var>u_i, v_i</var> は、頂点 <var>u_i</var> と頂点 <var>v_i</var> を結ぶ無向辺がグラフ中に存在することを表す。</li> </ul> <h3>制約</h3> <ul> <li> <var>1 \leq N \leq 3 \times 10^5</var></li> <li> <var>0 \leq A_i \leq 10^9</var></li> <li> <var>1 \leq u_i &lt; v_i \leq N</var></li> <li> 与えられるグラフは木であることが保証される</li> <li> 入力は全て整数で与えられる</li> </ul> <h3>出力形式</h3> <p><var>N</var> 行出力せよ。<var>i</var> 行目には、頂点 <var>i</var> を根としたときのステップ数を出力せよ。</p> <h3>入力例1</h3> <pre> 3 1 2 3 1 2 1 3 </pre> <h3>出力例1</h3> <pre> 2 3 3 </pre> <ul> <li> <var>1</var> 番目の頂点を根としたとき</li> <ul> <li> 頂点 <var>1</var> (<var>A_1</var>: <var>1</var> → <var>0</var>) → 頂点 <var>2</var> (<var>A_2</var>: <var>2</var> → <var>1</var>) → 頂点 <var>1</var> (<var>A_1</var> が <var>0</var> であるため、頂点 <var>1</var> に訪れることなく終了する)</li> </ul> <li> <var>2</var> 番目の頂点を根としたとき</li> <ul> <li> 頂点 <var>2</var> (<var>A_2</var>: <var>2</var> → <var>1</var>) → 頂点 <var>1</var> (<var>A_1</var>: <var>1</var> → <var>0</var>) → 頂点 <var>3</var> (<var>A_3</var>: <var>3</var> → <var>2</var>) → 頂点 <var>1</var> (<var>A_1</var> が <var>0</var> であるため、頂点 <var>1</var> に訪れることなく終了する)</li> </ul> <li> <var>3</var> 番目の頂点を根としたとき</li> <ul> <li> 頂点 <var>3</var> (<var>A_3</var>: <var>3</var> → <var>2</var>) → 頂点 <var>1</var> (<var>A_1</var>: <var>1</var> → <var>0</var>) → 頂点 <var>2</var> (<var>A_2</var>: <var>2</var> → <var>1</var>) → 頂点 <var>1</var> (<var>A_1</var> が <var>0</var> であるため、頂点 <var>1</var> に訪れることなく終了する)</li> </ul> </ul> <p>よって、答えはそれぞれ <var>2, 3, 3</var> となる。はじめに根から出発するときも <var>A_i</var> の値を減らすことに注意せよ。</p> <h3>入力例2</h3> <pre> 3 1 2 3 1 2 2 3 </pre> <h3>出力例2</h3> <pre> 4 4 5 </pre>
p02472
<h2>Addition of Big Integers</h2> <p> Given two integers $A$ and $B$, compute the sum, $A + B$. </p> <h3>Input</h3> <p> Two integers $A$ and $B$ separated by a space character are given in a line. </p> <h3>Output</h3> <p> Print the sum in a line. </p> <h3>Constraints</h3> <ul> <li>$-1 \times 10^{100000} \leq A, B \leq 10^{100000}$</li> </ul> <h3>Sample Input 1</h3> <pre> 5 8 </pre> <h3>Sample Output 1</h3> <pre> 13 </pre> <h3>Sample Input 2</h3> <pre> 100 25 </pre> <h3>Sample Output 2</h3> <pre> 125 </pre> <h3>Sample Input 3</h3> <pre> -1 1 </pre> <h3>Sample Output 3</h3> <pre> 0 </pre> <h3>Sample Input 4</h3> <pre> 12 -3 </pre> <h3>Sample Output 4</h3> <pre> 9 </pre>
p02022
<h2>H: 慈悲 (Mercy)</h2> <p>サンタクロースは、クリスマスなのにプログラミングをやっている集団を見つけた。</p> <p>サンタクロースは彼らを可哀想に思ったので、ケーキをプレゼントすることにした。</p> <p>クリームが $N$ 種類あって、美味しさは $A_1, A_2, A_3, \dots, A_N$ である。</p> <p>スポンジが $M$ 種類あって、美味しさは $B_1, B_2, B_3, \dots, B_M$ である。</p> <p>クリーム 1 種類とスポンジ 1 種類を組み合わせてケーキを作り、その美味しさは (クリームの美味しさ) × (スポンジの美味しさ) になる。</p> <p>サンタクロースは慈悲深いので、$N \times M$ 通りの組み合わせのケーキをすべて一つずつ作った。</p> <p>ケーキの美味しさは合計いくつか。</p> <h3>入力</h3> <p>1 行目には、整数 $N, M$ が空白区切りで与えられる。</p> <p>2 行目には、整数 $A_1, A_2, A_3, \dots, A_N$ が空白区切りで与えられる。</p> <p>3 行目には、整数 $B_1, B_2, B_3, \dots, B_M$ が空白区切りで与えられる。</p> <h3>出力</h3> <p>サンタクロースの作ったケーキの美味しさの合計を出力せよ。最後には改行を入れること。</p> <h3>制約</h3> <ul> <li>$N, M$ は $1$ 以上 $100 \ 000$ 以下の整数</li> <li>$A_1, A_2, A_3, \dots, A_N$ は $1$ 以上 $1 \ 000$ 以下の整数</li> <li>$B_1, B_2, B_3, \dots, B_M$ は $1$ 以上 $1 \ 000$ 以下の整数</li> </ul> <h3>注意</h3> <p>答えが 32 bit 整数型 (int 型など) の範囲に収まらない可能性があるので、64 bit 整数型 (long long 型など) を使いましょう。</p> <h3>入力例1</h3> <pre> 3 2 3 1 5 2 4 </pre> <h3>出力例1</h3> <pre> 54 </pre> <p>サンタクロースは、次の 6 種類のケーキを作ります。</p> <ul> <li>クリーム 1 とスポンジ 1 を組み合わせたケーキの美味しさ:$3 \times 2 = 6$</li> <li>クリーム 1 とスポンジ 2 を組み合わせたケーキの美味しさ:$3 \times 4 = 12$</li> <li>クリーム 2 とスポンジ 1 を組み合わせたケーキの美味しさ:$1 \times 2 = 2$</li> <li>クリーム 2 とスポンジ 2 を組み合わせたケーキの美味しさ:$1 \times 4 = 4$</li> <li>クリーム 3 とスポンジ 1 を組み合わせたケーキの美味しさ:$5 \times 2 = 10$</li> <li>クリーム 3 とスポンジ 2 を組み合わせたケーキの美味しさ:$5 \times 4 = 20$</li> </ul> <p>合計の美味しさは $54$ となります。</p> <h3>入力例2</h3> <pre> 10 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 </pre> <h3>出力例2</h3> <pre> 3025 </pre>
p02537
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a sequence <var>A_1, A_2, ..., A_N</var> and an integer <var>K</var>.</p> <p>Print the maximum possible length of a sequence <var>B</var> that satisfies the following conditions:</p> <ul> <li><var>B</var> is a (not necessarily continuous) subsequence of <var>A</var>.</li> <li>For each pair of adjacents elements of <var>B</var>, the absolute difference of the elements is at most <var>K</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300,000</var></li> <li><var>0 \leq A_i \leq 300,000</var></li> <li><var>0 \leq K \leq 300,000</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>K</var> <var>A_1</var> <var>A_2</var> <var>:</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 3 1 5 4 3 8 6 9 7 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>For example, <var>B = (1, 4, 3, 6, 9, 7, 4)</var> satisfies the conditions.</p> <ul> <li>It is a subsequence of <var>A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4)</var>.</li> <li>All of the absolute differences between two adjacent elements (<var>|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|</var>) are at most <var>K = 3</var>.</li> </ul></section> </div> </span>
p02167
<h1>Problem F: Bus</h1> <h2>Problem</h2> <p> 円環状に $1$ から $N$ までの番号がつけられた $N$ 個のバス停が右回りに並んでいる。 隣接するバス停どうしは道で結ばれている。 各 $i \ (1 \le i \le N)$ について、バス停 $i$ とバス停 $i+1$ の間を直接結ぶ道の長さは $d_i$ メートルである。 ただし、バス停 $N+1$ はバス停 $1$ のことを表す。 <p> <p> $M$ 台のバスがある。 $j \ (1 \le j \le M)$ 番目のバスは $c_j='R'$ のとき右回り、$c_j='L'$ のとき左回りに走行する。 また、時刻 $0$ にバス停 $b_j$ を出発し、$1$ メートル進むのに $t_j$ 秒かかる。 </p> <p> この問題において、 <ul> <li>バスは永遠に走り続ける</li> <li>バスの乗り降りには時間がかからない</li> <li>バス停では、あるバスがそのバス停を通過する瞬間、そのバスに乗り降りできる</li> <li>バス停以外でバスに乗り降りすることはできない</li> <li>何台のバスに乗ってもよい</li> </ul> </p> <p> とする。 </p> <p> 以下のクエリを合計 $Q$ 回処理せよ。 <ul> <li>時刻 $0$ にバス停 $x_k$ を出発し、バス停 $y_k$ までバスのみを利用して移動するときの、所要時間の最小値を求めよ。</li> </ul> </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $N$ $M$ $Q$ $d_1$ $\ldots$ $d_N$ $c_1$ $b_1$ $t_1$ $\vdots$ $c_M$ $b_M$ $t_M$ $x_1$ $y_1$ $\vdots$ $x_Q$ $y_Q$ </pre> <p> 1行目にバス停の数 $N$、バスの数 $M$、クエリの数 $Q$ が空白区切りで与えられる。<br> 2行目に隣接するバス停を繋ぐ道の情報が空白区切りで与えられる。<br> 3行目から続く $M$ 行にバスの情報が空白区切りで与えられる。<br> 続く $Q$ 行にクエリの情報が空白区切りで与えられる。<br> </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$3 \leq N \leq 10^5 $</li> <li>$1 \leq M \leq 10^5 $</li> <li>$1 \leq Q \leq 10^5 $</li> <li>$ 1 \leq d_i \leq 10^2 \ (1 \leq i \leq N) $</li> <li>$ c_j = 'R' \ or \ 'L' \ (1 \leq j \leq M) $</li> <li>$ 1 \leq b_j \leq N \ (1 \leq j \leq M) $</li> <li>$ 1 \leq t_j \leq 10^5 \ (1 \leq j \leq M) $</li> <li>$ 1 \leq x_k, y_k \leq N \ (1 \leq k \leq Q) $</li> <li>$ x_k \neq y_k \ (1 \leq k \leq Q) $</li> <li>入力で与えられる数はすべて整数<br></li> </ul> <h2>Output</h2> <p> 出力は $Q$ 行からなる。<br> 各クエリに対し、所要時間の最小値を出力せよ。<br> $k$ 行目には $k$ 番目のクエリに対する答えを出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 3 1 6 1 2 3 R 1 1 1 2 1 3 2 1 2 3 3 1 3 2 </pre> <h2>Sample Output 1</h2> <pre> 1 3 6 3 6 7 </pre> <p> $1$ つ目のクエリでは、時刻 $0$ にバス停 $1$ からバス $1$ に乗り、時刻 $1$ にバス停 $2$ で降りるのが最適である。 </p> <h2>Sample Input 2</h2> <pre> 4 6 7 45 72 81 47 R 1 47202 L 1 2156 L 2 95728 R 1 30739 L 3 39679 L 4 86568 3 2 3 4 1 2 2 4 4 3 1 4 2 1 </pre> <h2>Sample Output 2</h2> <pre> 431200 629552 431200 629552 275968 101332 528220 </pre>
p03326
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Takahashi became a pastry chef and opened a shop <em>La Confiserie d'ABC</em> to celebrate AtCoder Beginner Contest 100.</p> <p>The shop sells <var>N</var> kinds of cakes.<br/> Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The <var>i</var>-th kind of cake has the beauty of <var>x_i</var>, the tastiness of <var>y_i</var> and the popularity of <var>z_i</var>.<br/> These values may be zero or negative.</p> <p>Ringo has decided to have <var>M</var> pieces of cakes here. He will choose the set of cakes as follows:</p> <ul> <li>Do not have two or more pieces of the same kind of cake.</li> <li>Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).</li> </ul> <p>Find the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is an integer between <var>1</var> and <var>1 \ 000</var> (inclusive).</li> <li><var>M</var> is an integer between <var>0</var> and <var>N</var> (inclusive).</li> <li><var>x_i, y_i, z_i \ (1 \leq i \leq N)</var> are integers between <var>-10 \ 000 \ 000 \ 000</var> and <var>10 \ 000 \ 000 \ 000</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>x_1</var> <var>y_1</var> <var>z_1</var> <var>x_2</var> <var>y_2</var> <var>z_2</var> <var>:</var> <var>:</var> <var>x_N</var> <var>y_N</var> <var>z_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>56 </pre> <p>Consider having the <var>2</var>-nd, <var>4</var>-th and <var>5</var>-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:</p> <ul> <li>Beauty: <var>1 + 3 + 9 = 13</var></li> <li>Tastiness: <var>5 + 5 + 7 = 17</var></li> <li>Popularity: <var>9 + 8 + 9 = 26</var></li> </ul> <p>The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is <var>13 + 17 + 26 = 56</var>. This is the maximum value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 1 -2 3 -4 5 -6 7 -8 -9 -10 11 -12 13 -14 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>54 </pre> <p>Consider having the <var>1</var>-st, <var>3</var>-rd and <var>5</var>-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:</p> <ul> <li>Beauty: <var>1 + 7 + 13 = 21</var></li> <li>Tastiness: <var>(-2) + (-8) + (-14) = -24</var></li> <li>Popularity: <var>3 + (-9) + 15 = 9</var></li> </ul> <p>The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is <var>21 + 24 + 9 = 54</var>. This is the maximum value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 5 10 -80 21 23 8 38 -94 28 11 -26 -2 18 -69 72 79 -26 -86 -54 -72 -50 59 21 65 -32 40 -94 87 -62 18 82 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>638 </pre> <p>If we have the <var>3</var>-rd, <var>4</var>-th, <var>5</var>-th, <var>7</var>-th and <var>10</var>-th kinds of cakes, the total beauty, tastiness and popularity will be <var>-323</var>, <var>66</var> and <var>249</var>, respectively.<br/> The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is <var>323 + 66 + 249 = 638</var>. This is the maximum value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 2 2000000000 -9000000000 4000000000 7000000000 -5000000000 3000000000 6000000000 -1000000000 8000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>30000000000 </pre> <p>The values of the beauty, tastiness and popularity of the cakes and the value to be printed may not fit into 32-bit integers.</p></section> </div> </span>
p03776
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given <var>N</var> items.<br/> The <em>value</em> of the <var>i</var>-th item <var>(1 \leq i \leq N)</var> is <var>v_i</var>.<br/> Your have to select at least <var>A</var> and at most <var>B</var> of these items.<br/> Under this condition, find the maximum possible arithmetic mean of the values of selected items.<br/> Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>1 \leq A,B \leq N</var></li> <li><var>1 \leq v_i \leq 10^{15}</var></li> <li>Each <var>v_i</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>v_1</var> <var>v_2</var> ... <var>v_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print two lines.<br/> The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most <var>10^{-6}</var>.<br/> The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 2 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4.500000 1 </pre> <p>The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain <var>4.5</var>.<br/> There is no other way to select items so that the mean of the values will be <var>4.5</var>, and thus the second line of the output should contain <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 3 10 20 10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>15.000000 3 </pre> <p>There can be multiple ways to select items so that the mean of the values will be maximized.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 5 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000000000.000000 1 </pre></section> </div> </span>
p00859
<H1><font color="#000">Problem F:</font> Slim Span</H1> <p> Given an undirected weighted graph <i>G</i>, you should find one of spanning trees specified as follows. </p> <p> The graph <i>G</i> is an ordered pair (<i>V</i>, <i>E</i>), where <i>V</i> is a set of vertices {<i>v</i><sub>1</sub>, <i>v</i><sub>2</sub>, ... , <i>v<sub>n</sub></i>} and <i>E</i> is a set of undirected edges {<i>e</i><sub>1</sub>, <i>e</i><sub>2</sub>, ... , <i>e<sub>m</sub></i>}. Each edge <i>e</i> &isin; <i>E</i> has its weight <i>w</i>(<i>e</i>). </p> <p> A spanning tree <i>T</i> is a tree (a connected subgraph without cycles) which connects all the n vertices with <i>n</i> - 1 edges. The <i>slimness</i> of a spanning tree <i>T</i> is defined as the difference between the largest weight and the smallest weight among the <i>n</i> - 1 edges of <i>T</i>. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_slimSpan1"> <p> Figure 5: A graph <i>G</i> and the weights of the edges </p> </center> <p> For example, a graph <i>G</i> in Figure 5(a) has four vertices {<i>v</i><sub>1</sub>, <i>v</i><sub>2</sub>, <i>v</i><sub>3</sub>, <i>v</i><sub>4</sub>} and five undirected edges {<i>e</i><sub>1</sub>, <i>e</i><sub>2</sub>, <i>e</i><sub>3</sub>, <i>e</i><sub>4</sub>, <i>e</i><sub>5</sub>}. The weights of the edges are <i>w</i>(<i>e</i><sub>1</sub>) = 3, <i>w</i>(<i>e</i><sub>2</sub>) = 5, <i>w</i>(<i>e</i><sub>3</sub>) = 6, <i>w</i>(<i>e</i><sub>4</sub>) = 6, <i>w</i>(<i>e</i><sub>5</sub>) = 7 as shown in Figure 5(b). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_slimSpan2"> <p> Figure 6: Examples of the spanning trees of <i>G</i> </p> </center> <p> There are several spanning trees for <i>G</i>. Four of them are depicted in Figure 6(a)-(d). The spanning tree <i>T</i><sub>a</sub> in Figure 6(a) has three edges whose weights are 3, 6 and 7. The largest weight is 7 and the smallest weight is 3 so that the slimness of the tree <i>T</i><sub>a</sub> is 4. The slimnesses of spanning trees <i>T</i><sub>b</sub> , <i>T</i><sub>c</sub> and <i>T</i><sub>d</sub> shown in Figure 6(b), (c) and (d) are 3, 2 and 1, respectively. You can easily see the slimness of any other spanning tree is greater than or equal to 1, thus the spanning tree <i>T</i><sub>d</sub> in Figure 6(d) is one of the slimmest spanning trees whose slimness is 1. </p> <p> Your job is to write a program that computes the smallest slimness. </p> <H2>Input</H2> <p> The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset has the following format. </p> <pre> <i>n m</i> <i>a</i><sub>1</sub> <i>b</i><sub>1</sub> <i>w</i><sub>1</sub> . . . <i>a</i><sub><i>m</i></sub> <i>b</i><sub><i>m</i></sub> <i>w</i><sub><i>m</i></sub> </pre> <p> Every input item in a dataset is a non-negative integer. Items in a line are separated by a space. </p> <p> <i>n</i> is the number of the vertices and m the number of the edges. You can assume 2 &le; <i>n</i> &le; 100 and 0 &le; <i>m</i> &le; <i>n</i>(<i>n</i> - 1)/2. <i>a<sub>k</sub></i> and <i>b<sub>k</sub></i> (<i>k</i> = 1, ... , <i>m</i>) are positive integers less than or equal to <i>n</i>, which represent the two vertices <i>v<sub>a<sub>k</sub></sub></i> and <i>v<sub>b<sub>k</sub></sub></i> connected by the <i>k</i>th edge <i>e<sub>k</sub></i>. <i>w<sub>k</sub></i> is a positive integer less than or equal to 10000, which indicates the weight of <i>e<sub>k</sub></i> . You can assume that the graph <i>G</i> = (<i>V</i>, <i>E</i>) is simple, that is, there are no self-loops (that connect the same vertex) nor parallel edges (that are two or more edges whose both ends are the same two vertices). </p> <H2>Output</H2> <p> For each dataset, if the graph has spanning trees, the smallest slimness among them should be printed. Otherwise, <span>-1</span> should be printed. An output should not contain extra characters. </p> <H2>Sample Input</H2> <pre> 4 5 1 2 3 1 3 5 1 4 6 2 4 6 3 4 7 4 6 1 2 10 1 3 100 1 4 90 2 3 20 2 4 80 3 4 40 2 1 1 2 1 3 0 3 1 1 2 1 3 3 1 2 2 2 3 5 1 3 6 5 10 1 2 110 1 3 120 1 4 130 1 5 120 2 3 110 2 4 120 2 5 130 3 4 120 3 5 110 4 5 120 5 10 1 2 9384 1 3 887 1 4 2778 1 5 6916 2 3 7794 2 4 8336 2 5 5387 3 4 493 3 5 6650 4 5 1422 5 8 1 2 1 2 3 100 3 4 100 4 5 100 1 5 50 2 5 50 3 5 50 4 1 150 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 20 0 -1 -1 1 0 1686 50 </pre>
p02864
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will create an artwork by painting black some squares in a white square grid with <var>10^9</var> rows and <var>N</var> columns.<br/> The current plan is as follows: for the <var>i</var>-th column from the left, we will paint the <var>H_i</var> bottommost squares and will not paint the other squares in that column.<br/> Before starting to work, you can choose at most <var>K</var> columns (possibly zero) and change the values of <var>H_i</var> for these columns to any integers of your choice between <var>0</var> and <var>10^9</var> (inclusive).<br/> Different values can be chosen for different columns.<br/></p> <p>Then, you will create the modified artwork by repeating the following operation:<br/></p> <ul> <li>Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)</li> </ul> <p>Find the minimum number of times you need to perform this operation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300</var></li> <li><var>0 \leq K \leq N</var></li> <li><var>0 \leq H_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 3 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>For example, by changing the value of <var>H_3</var> to <var>2</var>, you can create the modified artwork by the following three operations:</p> <ul> <li>Paint black the <var>1</var>-st through <var>4</var>-th squares from the left in the <var>1</var>-st row from the bottom.</li> <li>Paint black the <var>1</var>-st through <var>3</var>-rd squares from the left in the <var>2</var>-nd row from the bottom.</li> <li>Paint black the <var>2</var>-nd square from the left in the <var>3</var>-rd row from the bottom.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 2 8 6 9 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 0 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4999999996 </pre></section> </div> </span>
p03019
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi and Aoki will take <var>N</var> exams numbered <var>1</var> to <var>N</var>. They have decided to compete in these exams. The winner will be determined as follows:</p> <ul> <li> <p>For each exam <var>i</var>, Takahashi decides its <em>importance</em> <var>c_i</var>, which must be an integer between <var>l_i</var> and <var>u_i</var> (inclusive).</p> </li> <li> <p>Let <var>A</var> be <var>\sum_{i=1}^{N} c_i \times</var> (Takahashi's score on Exam <var>i</var>), and <var>B</var> be <var>\sum_{i=1}^{N} c_i \times</var> (Aoki's score on Exam <var>i</var>). Takahashi wins if <var>A \geq B</var>, and Aoki wins if <var>A &lt; B</var>.</p> </li> </ul> <p>Takahashi knows that Aoki will score <var>b_i</var> on Exam <var>i</var>, with his supernatural power.</p> <p>Takahashi himself, on the other hand, will score <var>0</var> on all the exams without studying more. For each hour of study, he can increase his score on some exam by <var>1</var>. (He can only study for an integer number of hours.) However, <strong>he cannot score more than <var>X</var> on an exam</strong>, since the perfect score for all the exams is <var>X</var>.</p> <p>Print the minimum number of study hours required for Takahashi to win.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq X \leq 10^5</var></li> <li><var>0 \leq b_i \leq X</var> <var>(1 \leq i \leq N)</var></li> <li><var>1 \leq l_i \leq u_i \leq 10^5</var> <var>(1 \leq i \leq N)</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> <var>b_1</var> <var>l_1</var> <var>u_1</var> <var>b_2</var> <var>l_2</var> <var>u_2</var> <var>:</var> <var>b_N</var> <var>l_N</var> <var>u_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of study hours required for Takahashi to win.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 100 85 2 3 60 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>115 </pre> <p>One optimal strategy is as follows:</p> <ul> <li> <p>Choose <var>c_1 = 3, c_2 = 1</var>.</p> </li> <li> <p>Study to score <var>100</var> on Exam <var>1</var> and <var>15</var> on Exam <var>2</var>.</p> </li> </ul> <p>Then, <var>A = 3 \times 100 + 1 \times 15 = 315</var>, <var>B = 3 \times 85 + 1 \times 60 = 315</var> and Takahashi will win.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 100 85 2 3 60 10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>77 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 100000 31415 2718 2818 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>31415 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 1000 451 4593 6263 324 310 6991 378 1431 7068 71 1757 9218 204 3676 4328 840 6221 9080 684 1545 8511 709 5467 8674 862 6504 9835 283 4965 9980 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>2540 </pre></section> </div> </span>
p01024
<h1>Problem I: Sum of Last Digits</h1> <h2>Problem</h2> <p> 3つの整数 <var>n</var>, <var>m</var>, <var>k</var> が与えられるので<br> <br> <b> <var>n</var><sup>1</sup>%10 &nbsp;+ &nbsp;<var>n</var><sup>1+<var>m</var></sup>%10 &nbsp;+ &nbsp;<var>n</var><sup>1+2<var>m</var></sup>%10 &nbsp;+ ... + &nbsp;<var>n</var><sup>1+(<var>k</var>-1)<var>m</var></sup>%10 </b> <br> <br> を計算せよ。 <var>a % b</var> は <var>a</var> を <var>b</var> で割ったときの余りを表す。 </p> <h2>Input</h2> <pre> <var>n</var> <var>m</var> <var>k</var> </pre> <p> 1行に <var>n</var>, <var>m</var>, <var>k</var> が与えられる。 </p> <h2>Constraints</h2> 入力は以下の条件を満たす <ul> <li>0 &le; <var>n</var> &le; 10<sup>18</sup></li> <li>0 &le; <var>m</var> &le; 10<sup>9</sup></li> <li>1 &le; <var>k</var> &le; 10<sup>9</sup></li> </ul> <h2>Output</h2> <p>答えを1行に出力せよ。</p> <h2>Sample Input 1</h2> <pre> 1 1 9 </pre> <h2>Sample Output 1</h2> <pre> 9 </pre> <h2>Sample Input 2</h2> <pre> 2 1 3 </pre> <h2>Sample Output 2</h2> <pre> 14 </pre> <h2>Sample Input 3</h2> <pre> 6 11 11 </pre> <h2>Sample Output 3</h2> <pre> 66 </pre> <h2>Sample Input 4</h2> <pre> 100 7 12 </pre> <h2>Sample Output 4</h2> <pre> 0 </pre> <h2>Sample Input 5</h2> <pre> 123 123 3 </pre> <h2>Sample Output 5</h2> <pre> 11 </pre>
p03449
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a <var>2 \times N</var> grid. We will denote the square at the <var>i</var>-th row and <var>j</var>-th column (<var>1 \leq i \leq 2</var>, <var>1 \leq j \leq N</var>) as <var>(i, j)</var>.</p> <p>You are initially in the top-left square, <var>(1, 1)</var>. You will travel to the bottom-right square, <var>(2, N)</var>, by repeatedly moving right or down.</p> <p>The square <var>(i, j)</var> contains <var>A_{i, j}</var> candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them.</p> <p>At most how many candies can you collect when you choose the best way to travel?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq A_{i, j} \leq 100</var> (<var>1 \leq i \leq 2</var>, <var>1 \leq j \leq N</var>)</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var> <var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of candies that can be collected.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 2 2 4 1 1 2 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>14 </pre> <p>The number of collected candies will be maximized when you:</p> <ul> <li>move right three times, then move down once, then move right once.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 1 1 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>You will always collect the same number of candies, regardless of how you travel.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 3 3 4 5 4 5 3 5 3 4 4 2 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>29 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 </pre></section> </div> </span>
p01474
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h2>問題文</h2> <p>以下の条件を満たす整数列 $X_1, X_2, ..., X_N$ の個数を求めよ。<br /></p> <ol><li>任意の整数 $i$ ($1 \leq i \leq N$)に対して、$X_j=i$ となる $j$ ($1 \leq j \leq N$)が存在する。</li> <li>$X_s = t$</li> <li>$X_{a_i} &lt; X_{b_i}$ ($1 \leq i \leq C$)</li></ol> <h2>入力</h2> <p>入力は以下の形式に従う。与えられる数は全て整数である。</p> <pre>$N$ $C$ $s$ $t$ $a_1$ $b_1$ $a_2$ $b_2$ $...$ $a_C$ $b_C$</pre> <h2>制約</h2> <ul><li>$1 \leq N \leq 2000$</li> <li>$0 \leq C \leq N$</li> <li>$1 \leq s \leq N$</li> <li>$1 \leq t \leq N$</li> <li>$1 \leq a_i \leq N$</li> <li>$1 \leq b_i \leq N$</li> <li>$a_i \neq b_i$</li> <li>$i \neq j$ ならば $a_i \neq a_j$</li></ul> <h2>出力</h2> <p>条件を満たす数列の個数を $10^9+7$ で割った余りを1行に出力せよ(条件を満たす数列の個数がたかだか有限個しかないことは簡単に示される)。</p> <h2>Sample Input 1</h2> <pre>3 1 1 1 1 3</pre> <h2>Output for the Sample Input 1</h2> <pre>2</pre> <p>$\{X_1, X_2, X_3\} = \{1, 2, 3\}, \{1, 3, 2\}$ の2つが条件を満たす。</p> <h2>Sample Input 2</h2> <pre>4 2 1 1 2 3 3 2 </pre> <h2>Output for the Sample Input 2</h2> <pre>0</pre> <p>$X_2&lt;X_3$ かつ $X_3&lt;X_2$ を満たす数列は存在しない。</p>
p00635
<H1><font color="#000000">Problem 09:</font> Building Houses</H1> <p> この秋、割火ハウスは最近開拓が進んでいる松短地区の神暗通り沿いの土地を分譲することにした。 先日募集をかけ、今日は購入者に分譲説明会を開催する。 </p> <p> 購入者が説明会場に集まりだしたところ、なんだか空気がとても凍り付いていた。不思議に思った担当者は開催前に </p> <p> 「皆さん新天地を求めてきたというのに、ちょっと表情が暗いですが大丈夫ですか?」 </p> <p> と聞いてみた。そこで思わぬ事実が判明した。実は、購入者全員が現在隣町の集合団地の住人で、あまりにも周辺の人たちと折り合いが合わないため今回引越しをしようと検討していたのだった。 </p> <p> 購入者たちはすでに費用を支払済みで以前の住まいを引き払っている。従って、今回分譲した松短地区の神暗通りに家を立てる他方法はない。 </p> <p> しかしながら、少しでも快適な新居ライフを送ってもらおうと担当者は頭を悩ませた。よくよく話を聞いてみると、仲の悪さにはバラツキがあったので、聞き込みを行い図1のような仲の悪い度チェック表を作成した: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_buildingHouses"><br> <p>図1:仲の悪い度チェック表</p> </center> <p> 購入者の数を <i>n</i> とすると、表は <i>n</i> &times; <i>n</i> の行列となり、要素 <i>a<sub>i,j</sub></i> は、購入者 <i>i</i> が自分の家から購入者 <i>j</i> の家を最低でも何 m 離したいかを示す。例えば、図1の表において、購入者 A は自分の家と購入者 B の家の距離が 2 m 以上離れていないと納得しない。さらに、購入者 B は自分の家と購入者 A の家の距離が 4 m 以上離れていないと納得しない。従って A と B の距離は 4 m 以上離す必要がある。 </p> <p> 担当者はこの表に基づき隣の家との間隔を設け土地のレイアウトを設計することにした。 </p> <p> あなたの仕事は、仲の悪い度チェック表を入力し、購入者の家を神暗通り(一直線上)に建てるために最低限必要な通りの長さ(m)を出力するプログラムを作成することである。 なお簡単のために、家は点として扱い、その幅は 0 m と仮定する。 </p> <H2>Input</H2> <p> 入力として複数のデータセットが与えられる。各データセットは以下の形式で与えられる:<br> <br> <i>n</i> (購入者の数:整数)<br> <i>a</i><sub>1,1</sub> <i>a</i><sub>1,2</sub> ... <i>a</i><sub>1,<i>n</i></sub> (<i>a</i><sub>1,<i>j</i></sub>:整数)<br> <i>a</i><sub>2,1</sub> <i>a</i><sub>2,2</sub> ... <i>a</i><sub>2,<i>n</i></sub> (<i>a</i><sub>2,<i>j</i></sub>:整数)<br> .<br> .<br> <i>a</i><sub><i>n</i>,1</sub> <i>a</i><sub><i>n</i>,2</sub> ... <i>a</i><sub><i>n</i>,<i>n</i></sub> (<i>a</i><sub><i>n</i>,<i>j</i></sub>:整数)<br> </p> <p> <i>n</i> は 10 以下とする。<i>a</i><sub><i>i</i>,<i>i</i></sub></i> は 0 であり、<i>a</i><sub><i>i</i>,<i>j</i></sub></i> (<i>i</i> &ne; <i>j</i>) は 1 以上である。 </p> <p> <i>n</i> が 0 のとき入力の終わりとする。 </p> <H2>Output</H2> <p> 各データセットについて、最低限必要な通りの長さを1行に出力せよ。 </p> <H2>Sample Input</H2> <pre> 4 0 2 3 1 4 0 4 2 1 1 0 3 3 1 5 0 2 0 3 3 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 8 3 </pre>
p02608
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>f(n)</var> be the number of triples of integers <var>(x,y,z)</var> that satisfy both of the following conditions:</p> <ul> <li><var>1 \leq x,y,z</var></li> <li><var>x^2 + y^2 + z^2 + xy + yz + zx = n</var></li> </ul> <p>Given an integer <var>N</var>, find each of <var>f(1),f(2),f(3),\ldots,f(N)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^4</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain the value <var>f(i)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 0 0 0 0 1 0 0 0 0 3 0 0 0 0 0 3 3 0 0 </pre> <ul> <li>For <var>n=6</var>, only <var>(1,1,1)</var> satisfies both of the conditions. Thus, <var>f(6) = 1</var>.</li> <li>For <var>n=11</var>, three triples, <var>(1,1,2)</var>, <var>(1,2,1)</var>, and <var>(2,1,1)</var>, satisfy both of the conditions. Thus, <var>f(6) = 3</var>.</li> <li>For <var>n=17</var>, three triples, <var>(1,2,2)</var>, <var>(2,1,2)</var>, and <var>(2,2,1)</var>, satisfy both of the conditions. Thus, <var>f(17) = 3</var>.</li> <li>For <var>n=18</var>, three triples, <var>(1,1,3)</var>, <var>(1,3,1)</var>, and <var>(3,1,1)</var>, satisfy both of the conditions. Thus, <var>f(18) = 3</var>.</li> </ul></section> </div> </span>
p01927
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>凸多角形柱工業都市</h3> <p>凸多角形柱工業都市 (Industrial Convex Pillar City, ICPC) はいくつかの凸多角形柱の形状をした建物からなる街である.あなたはこの街の中を現在地 <i>S</i> から目的地 <i>T</i> に向けて歩こうとしている.今日は日差しが強いので,出来る限りひなたを通らずに目的地へ向かいたい.あなたが立っている地点と太陽を一直線に結んだ線上に建物がある場合,あなたは建物の陰にいるので日差しを受けずにすむ.また,この街の建物の外周には全てひさしが付いているので,建物の外周に沿って歩いている間は,日が当たる縁に沿って歩いても日差しを受けることはない.あなたは建物の内部以外はこの街をどこでも自由に歩くことができる. </p> <p>もっとも日差しを受けないように現在地から目的地まで歩いた時の,ひなたを歩く距離を出力するプログラムを作成しなさい. </p> <div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_E1" witdh="300" height="300"> <p>図E1: 第1インプットの場合 </p> </div> <div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_E2" witdh="300" height="300"> <p>図E2: 第2インプットの場合 </p> </div> <div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_E3" witdh="300" height="300"> <p>図E3: 第3インプットの場合 </p> </div> <h3>Input</h3> <p>入力は複数のデータセットからなる. データセットの個数は最大でも 30 個を超えない. 各データセットは次の形式で表される. </p><blockquote><i>N</i><br><i>NV<sub>1</sub></i> <i>H<sub>1</sub></i> <i>X<sub>1,1</sub></i> <i>Y<sub>1,1</sub></i> <i>X<sub>1,2</sub></i> <i>Y<sub>1,2</sub></i> ... <i>X<sub>1,NV<sub>1</sub></sub></i> <i>Y<sub>1,NV<sub>1</sub></sub></i><br>...<br><i>NV<sub>N</sub></i> <i>H<sub>N</sub></i> <i>X<sub>N,1</sub></i> <i>Y<sub>N,1</sub></i> <i>X<sub>N,2</sub></i> <i>Y<sub>N,2</sub></i> ... <i>X<sub>N,NV<sub>N</sub></sub></i> <i>Y<sub>N,NV<sub>N</sub></sub></i><br><i>&theta;</i> <i>&phi;</i><br><i>S<sub>x</sub></i> <i>S<sub>y</sub></i> <i>T<sub>x</sub></i> <i>T<sub>y</sub></i><br></blockquote> <p>1行目の <i>N</i> は建物の数を表す.続く <i>N</i> 行は各建物の形状を指定する.<i>NV<sub>i</sub></i> は <i>i</i> 番目の建物を上から見た多角形の頂点数,<i>H<sub>i</sub></i> は <i>i</i> 番目の建物の高さを表す.<i>X<sub>i, j</sub></i> と <i>Y<sub>i, j</sub></i> は <i>i</i> 番目の建物を上から見た多角形の <i>j</i> 番目の頂点の <i>x</i> 座標と <i>y</i> 座標を表す.頂点は反時計回りの順で与えられる.全ての建物は上から見ると凸多角形であり,建物の内部に他の建物があったり,頂点や辺が他の多角形と重なったりすることはない.続く行には太陽の方向を表す <i>&theta;</i> と <i>&phi;</i> が与えられ,<i>&theta;</i> は太陽の向きを <i>x</i> の正の方向から反時計回りの角度で表し,<i>&phi;</i> は地平線からの太陽の仰角,すなわち太陽を見上げた時の視線の方向と地表面がなす角度を表す.ただし,太陽は無限遠にあり,移動中には位置を変えないものとする.続く行には現在地と目的地の座標, (<i>S<sub>x</sub></i>, <i>S<sub>y</sub></i>) と (<i>T<sub>x</sub></i>, <i>T<sub>y</sub></i>) が与えられる. </p><blockquote></blockquote> <p>入力で与えられる数値は全て整数であり,以下の条件を満たす. </p><blockquote><i>1 &le; N &le; 100</i><br><i>3 &le; NV<sub>i</sub> &le; 12</i><br><i>1 &le; H<sub>i</sub> &le; 1,</sub>000</i><br><i>0 &le; &theta; &lt; 360</i><br><i>0 &lt; &phi; &lt; 90</i></blockquote> <p>座標は全て <i>-1,</sub>000</i> 以上 <i>1,</sub>000</i> 以下である. 現在地と目的地は異なり,どちらも建物の内部及び外周には存在しない. </p><blockquote></blockquote> <p>入力の終わりは,1つのゼロからなる行で表される. </p><blockquote></blockquote> <h3>Output</h3> <p>各データセットについて,ひなたを歩く最短距離を1行に出力せよ.出力には 0.001 を超える絶対誤差があってはならない. </p><blockquote></blockquote> <h3>Sample Input</h3> <pre>2 4 1 0 0 1 0 1 1 0 1 4 2 2 2 3 2 3 3 2 3 60 45 -1 -1 4 4 4 4 1 0 0 3 1 1 2 0 1 3 2 10 7 8 2 12 4 6 8 7 12 8 13 9 15 10 19 11 24 10 25 5 4 16 2 16 4 12 8 14 2 15 0 167 38 3 3 15 21 12 4 3 -8 -3 -9 -3 -9 -5 -8 -6 4 5 -4 -5 -7 -5 -7 -6 -5 -6 4 2 -4 1 -5 1 -5 -4 -4 -4 4 1 -1 1 -2 1 -2 -4 -1 -3 4 2 2 3 -1 3 -2 2 3 2 4 1 3 1 2 1 2 -3 3 -4 4 7 1 0 0 0 0 -1 1 -1 4 4 9 5 7 5 7 4 10 4 4 3 6 5 5 4 5 0 6 0 4 5 8 -1 5 -1 6 -2 8 -2 4 1 10 0 9 0 9 -2 10 -1 4 6 10 2 8 2 8 1 10 1 131 78 -10 10 10 -10 0 </pre> <h3>Output for Sample Input</h3> <pre>1.93185 7.87174 20.86840</pre>
p00265
<H1>モジュロ・クエリ</H1> <p> あなたに N 枚のカードを渡します。どのカードにも一つだけ自然数が書いてあります。ただし、同じ数が書いてあることはありません。 </p> <p> これから質問として、適当な自然数を言います。あなたが持っているカードに書いてある数を私が言った数で割ったときに得られる余りのうち最も大きなものを答えてください。 </p> <p> たとえば、あなたは 3 枚のカードを持っていて、それぞれ 9、3、8 と書いてあるとします。私が「4」と言ったら、9 と 3 と 8 をそれぞれ4 で割った余りを求めてください。余りはそれぞれ 1、3、0 ですが、この中でもっとも大きな余りは3 なので、3 が正しい答えになります。 </p> <p> では始めましょうか。え? カードがいっぱいあるとたいへんだ? しょうがないですね。それではコ ンピュータを使って最大の余りを見つけることにしましょう。カードに書いてある数を、質問された数で割った余りのうち、最大のものを見つけるプログラムを作成してください。なお、質問は1回だけでなく何度もしますが、同じ数を 2 回以上質問することはありません。 </p> <h2>入力</h2> <p> 入力は1つのデータセットからなる。入力データは以下の形式で与えられる。 </p> <pre> N Q c<sub>1</sub> c<sub>2</sub> ... c<sub>N</sub> q<sub>1</sub> q<sub>2</sub> : q<sub>Q</sub> </pre> <p> 1行目にカードの枚数 N (2 &le; N &le; 300000) と質問の回数 Q (2 &le; Q &le; 100000) が1つの空白区切りで与えられ、2行目にカードに書かれた数 c<sub>i</sub> (1 &le; c<sub>i</sub> &le; 300000) が1つの空白区切りで与えられる。続くQ 行に質問として与えられる数 q<sub>i</sub> (1 &le; q<sub>i</sub> &le; 300000) が与えられる。 </p> <h2>出力</h2> <p> 質問ごとに最大の余りを1行に出力する。 </p> <h2>入力例</h2> <pre> 3 3 9 3 8 4 6 5 </pre> <h2>出力例</h2> <pre> 3 3 4 </pre>
p02258
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <H1>Maximum Profit</H1> <p> You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) &times; 1000 = 8000 yen. </p> <p> Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ . </p> <H2>Input</H2> <p> The first line contains an integer $n$. In the following $n$ lines, $R_t$ ($t = 0, 1, 2, ... n-1$) are given in order. </p> <H2>Output</H2> <p> Print the maximum value in a line. </p> <H2>Constraints</H2> <ul> <li>$2 \leq n \leq 200,000$</li> <li>$1 \leq R_t \leq 10^9$</li> </ul> <H2>Sample Input 1</H2> <pre> 6 5 3 1 3 4 3 </pre> <H2>Sample Output 1</H2> <pre> 3 </pre> <H2>Sample Input 2</H2> <pre> 3 4 3 2 </pre> <H2>Sample Output 2</H2> <pre> -1 </pre>
p00770
<h3>Prime Caves</h3> <p> An international expedition discovered abandoned Buddhist cave temples in a giant cliff standing on the middle of a desert. There were many small caves dug into halfway down the vertical cliff, which were aligned on square grids. The archaeologists in the expedition were excited by Buddha's statues in those caves. More excitingly, there were scrolls of Buddhism sutras (holy books) hidden in some of the caves. Those scrolls, which estimated to be written more than thousand years ago, were of immeasurable value. </p> <p> The leader of the expedition wanted to collect as many scrolls as possible. However, it was not easy to get into the caves as they were located in the middle of the cliff. The only way to enter a cave was to hang you from a helicopter. Once entered and explored a cave, you can climb down to one of the three caves under your cave; i.e., either the cave directly below your cave, the caves one left or right to the cave directly below your cave. This can be repeated for as many times as you want, and then you can descent down to the ground by using a long rope. </p> <p> So you can explore several caves in one attempt. But which caves you should visit? By examining the results of the preliminary attempts, a mathematician member of the expedition discovered that (1) the caves can be numbered from the central one, spiraling out as shown in Figure D-1; and (2) only those caves with their cave numbers being prime (let's call such caves <em>prime caves</em>), which are circled in the figure, store scrolls. From the next attempt, you would be able to maximize the number of prime caves to explore. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_primeCaves"> <br><br> Figure D-1: Numbering of the caves and the prime caves <br> </center> <p> Write a program, given the total number of the caves and the cave visited first, that finds the descending route containing the maximum number of prime caves. </p> <h3>Input</h3> <p> The input consists of multiple datasets. Each dataset has an integer <i>m</i> (1 &le; <i>m</i> &le; 10<sup>6</sup>) and an integer <i>n</i> (1 &le; <i>n</i> &le; <i>m</i>) in one line, separated by a space. <i>m</i> represents the total number of caves. <i>n</i> represents the cave number of the cave from which you will start your exploration. The last dataset is followed by a line with two zeros. </p> <h3>Output</h3> <p> For each dataset, find the path that starts from the cave <i>n</i> and contains the largest number of prime caves, and output the number of the prime caves on the path and the last prime cave number on the path in one line, separated by a space. The cave <i>n</i>, explored first, is included in the caves on the path. If there is more than one such path, output for the path in which the last of the prime caves explored has the largest number among such paths. When there is no such path that explores prime caves, output "<code>0 0</code>" (without quotation marks). </p> <h3>Sample Input</h3> <pre> 49 22 46 37 42 23 945 561 1081 681 1056 452 1042 862 973 677 1000000 1000000 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 0 0 6 43 1 23 20 829 18 947 10 947 13 947 23 947 534 993541 </pre>
p01862
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>--> <h2>E: 星の作り方 - How To Make Stars -</h2> <h3>物語</h3> <p>北ノ木坂学院1年生の星屑鈴だニャ!鈴はお星様がだ〜い好き!夜はいつも幼馴染の花代ちんと一緒に,こっそりと学校の屋上でお星様を見てるんだ!だけど,今日のお天気はあいにくの雨・・・.これじゃ,お星様を見ることができないニャ!花代ちんどうしよう〜!</p> <p>鈴「・・・ああっ!いいこと思い付いたニャ!色んなお星様を見れるような,おっきなプラネタリウムを作るニャ!花代ちん!さっそくやるニャ!」</p> <p>花代「えっ,えぇっ,鈴ちゃんちょっと待って!プラネタリウムの作り方なんて,私知らないよ!」</p> <p>鈴「大丈夫ニャ!2人で力を合わせればきっとできるよ!ニャニャニャニャ〜!」</p> <p>花代「だ,ダレカタスケテ〜!」</p> <h3>問題</h3> <p>自己交差のない多角形の中で,頂点数が10でありかつ,任意の頂点から一定の方向に周上をたどったとき,内角が30度以上60度以下である部分と,内角が240度以上270度以下である部分が交互に現れるものを「星」と定義する.</p> <p>星は面積によって階級が定まる.具体的には,面積が <var>S_1</var> 以上のものを1級星, <var>S_{i&minus;1}</var>より小さく<var>S_i</var>以上のものを<var>i</var>級星 (<var>i &ge; 2</var>) と呼ぶように階級を付ける.</p> <p>階級が<var>n</var>個あるとして,階級の目安となる<var>n</var>種類の面積<var>S_1</var>, ..., <var>S_n</var>が与えられるので,各<var>k (1 &le; k &le; n)</var>について<var>k</var>級星となる星を作り,2次元平面上に配置せよ. ただし,各星が互いに重なってはならない.</p> <h3>入力形式</h3> <p>入力は以下の形式で与えられる.</p> <pre> <var>n</var> <var>S_1</var> ... <var>S_n</var> </pre> <p> 1行目には階級の数<var>n</var>が与えられる. 2行目には,階級の目安となる面積を表す整数<var>S_1</var>から<var>S_n</var>が順に空白区切りで与えられる. </p> <p>入力は以下の制約を満たす.</p> <ul> <li><var>1 &le; n &le; 100</var></li> <li><var>1 &le; S_i &le; 100,000 (1 &le; i &le; n)</var></li> <li><var>i &lt; j</var>ならば<var>S_i &gt; S_j</var></li> </ul> <h3>出力形式</h3> <p>全ての階級の星について,1行目には階級を表す整数<var>k</var>を,続く10行には任意の頂点から反時計回りで10個の頂点の座標<var>(x, y)</var>を1行ごとに出力せよ.頂点の座標<var>(x, y)</var>は<var>x</var>と<var>y</var>を空白区切りで出力せよ.星は,1級星から順に出力せよ.すなわち,出力は以下のようになる.</p> <pre> <var>1</var>級星の出力 ... <var>n</var>級星の出力 </pre> <p><var>k</var>級星の星については,以下のように出力する.</p> <pre> <var>k</var> <var>x_1</var> <var>y_1</var> ... <var>x_{10}</var> <var>y_{10}</var> </pre> <p>ただし,座標の絶対値が<var>5,000</var>を超えてはならない.また,出力が非常に大きくなる可能性があるため,座標値の出力は小数点以下9桁までとせよ.</p> <p>星の内角について,指定の範囲からの絶対誤差を<var>10^{&minus;3}</var>rad(ラジアン)まで許す.</p> <p>星が互いに交差することや,接触していること,ある星が他の星に内包されるといったことは許されない.ここで,星が接触しているとは,異なる星に含まれる任意の2辺の距離が<var>10^{&minus;7}</var>以下であるときを指す.</p> <p>1級星の面積は<var>S_1</var>以上,<var>i</var>級星 (<var>i &ge; 2</var>) の面積は<var>S_{i&minus;1}</var>未満<var>S_i</var>以上でなければならないが,絶対誤差を<var>10^{&minus;7}</var>まで許す.</p> <p>1つの星を構成する任意の2頂点間の距離は<var>10^{&minus;3}</var>以上でなければならない.</p> <h3>入力例1</h3> <pre> 2 10 5 </pre> <h3>出力例1</h3> <pre> 1 -10.00 -6.48 -10.79 -8.91 -13.34 -8.91 -11.28 -10.41 -12.07 -12.84 -10.00 -11.34 -7.93 -12.84 -8.72 -10.41 -6.66 -8.91 -9.21 -8.91 2 10.00 12.34 9.47 10.72 7.77 10.72 9.15 9.72 8.62 8.10 10.00 9.10 11.38 8.10 10.85 9.72 12.23 10.72 10.53 10.72 </pre> <h3>入力例2</h3> <pre> 3 10 8 5 </pre> <h3>出力例2</h3> <pre> 1 -10.00 -6.48 -10.79 -8.91 -13.34 -8.91 -11.28 -10.41 -12.07 -12.84 -10.00 -11.34 -7.93 -12.84 -8.72 -10.41 -6.66 -8.91 -9.21 -8.91 2 10.00 12.93 9.34 10.91 7.21 10.91 8.94 9.65 8.28 7.63 10.00 8.88 11.72 7.63 11.06 9.65 12.79 10.91 10.66 10.91 3 20.00 22.34 19.47 20.72 17.77 20.72 19.15 19.72 18.62 18.10 20.00 19.10 21.38 18.10 20.85 19.72 22.23 20.72 20.53 20.72 </pre>
p00320
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>直方体</H1> <p> アイヅ放送協会の教育番組(AHK教育)では、子供向けの工作番組「あそんでつくろ」という番組を放送しています。今日は画用紙で箱を作る回ですが、用意した長方形の画用紙で直方体ができるかを確かめたいと思います。ただし、画用紙は切ったり折ったりしてはいけません。 </p> <p> 6つの長方形が与えられるので、それらを使って直方体が作れるかどうか判定するプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>h<sub>1</sub></var> <var>w<sub>1</sub></var> <var>h<sub>2</sub></var> <var>w<sub>2</sub></var> <var>h<sub>3</sub></var> <var>w<sub>3</sub></var> <var>h<sub>4</sub></var> <var>w<sub>4</sub></var> <var>h<sub>5</sub></var> <var>w<sub>5</sub></var> <var>h<sub>6</sub></var> <var>w<sub>6</sub></var> </pre> <p> 入力は6行からなり、それぞれの行に各長方形の縦の長さを表す整数 <var>h<sub>i</sub></var> (1 &le; <var>h<sub>i</sub></var> &le; 1000) と横の長さを表す整数 <var>w<sub>i</sub></var> (1 &le; <var>w<sub>i</sub></var> &le; 1000) が与えられる。 </p> <h2>Output</h2> <p> 直方体を作成できる場合には「yes」を、作成できない場合には「no」を出力する。ただし、立方体は直方体の一種なので、立方体の場合でも「yes」と出力する。 </p> <h2>Sample Input 1</h2> <pre> 2 2 2 3 2 3 2 3 2 2 3 2 </pre> <h2>Sample Output 1</h2> <pre> yes </pre> <br/> <h2>Sample Input 2</h2> <pre> 2 2 2 3 2 3 2 3 2 2 2 2 </pre> <h2>Sample Output 2</h2> <pre> no </pre>
p01161
<H1><font color="#000">Problem G:</font> Traffic</H1> <p> You are a resident of Kyoot (oh, well, it’s not a misspelling!) city. All streets there are neatly built on a grid; some streets run in a meridional (north-south) direction and others in a zonal (east-west) direction. The streets that run from north to south are called avenues, whereas those which run from east to west are called <i>drives</i>. </p> <p> Every avenue and drive in the city is numbered to distinguish one from another. The westernmost avenue is called the <i>1st avenue</i>. The avenue which lies next to the <i>1st avenue</i> is the <i>2nd avenue</i>, and so forth. Similarly, drives are numbered from south to north. The figure below illustrates this situation. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_traffic1"> <p>Figure 1: The Road Map of the Kyoot City </center> <p> There is an intersection with traffic signals to regulate traffic on each crossing point of an avenue and a drive. Each traffic signal in this city has two lights. One of these lights is colored green, and means “you may go”. The other is red, and means “you must stop here”. If you reached an intersection during the red light (including the case where the light turns to red on your arrival), you must stop and wait there until the light turns to green again. However, you do not have to wait in the case where the light has just turned to green when you arrived there. </p> <p> Traffic signals are controlled by a computer so that the lights for two different directions always show different colors. Thus if the light for an avenue is green, then the light for a drive must be red, and vice versa. In order to avoid car crashes, they will never be green together. Nor will they be red together, for efficiency. So all the signals at one intersection turn simultaneously; no sooner does one signal turn to red than the other turns to green. Each signal has a prescribed time interval and permanently repeats the cycle. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_traffic2"> <p>Figure 2: Signal and Intersection</p> </center> <p> By the way, you are planning to visit your friend by car tomorrow. You want to see her as early as possible, so you are going to drive through the shortest route. However, due to existence of the traffic signals, you cannot easily figure out which way to take (the city also has a very sophisticated camera network to prevent crime or violation: the police would surely arrest you if you didn’t stop on the red light!). So you decided to write a program to calculate the shortest possible time to her house, given the town map and the configuration of all traffic signals. </p> <p> Your car runs one unit distance in one unit time. Time needed to turn left or right, to begin moving, and to stop your car is negligible. You do not need to take other cars into consideration. </p> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case is given in the format below: </p> <pre><i> w h d<sub>A,1</sub> d<sub>A,2</sub> . . . d<sub>A,w−1</sub> d<sub>D,1</sub> d<sub>D,2</sub> . . . d<sub>D,h−1</sub> ns<sub>1,1</sub> ew<sub>1,1</sub> s<sub>1,1</sub> . . . ns<sub>w,1</sub> ew<sub>w,1</sub> s<sub>w,1</sub> ns<sub>1,2</sub> ew<sub>1,2</sub> s<sub>1,2</sub> . . . ns<sub>w,h</sub> ew<sub>w,h</sub> s<sub>w,h</sub> x<sub>s</sub> y<sub>s</sub> x<sub>d</sub> y<sub>d</sub> </pre></i> <p> Two integers w and h (2 &le; <i>w</i>, <i>h</i> &le; 100) in the first line indicate the number of avenues and drives in the city, respectively. The next two lines contain (<i>w</i> - 1) and (<i>h</i> - 1) integers, each of which specifies the distance between two adjacent avenues and drives. It is guaranteed that 2 &le; <i>d<sub>A,i</sub></i> , <i>d<sub>D,j</sub></i> &le; 1, 000. </p> <p> The next (<i>w</i> &times <i>h</i>) lines are the configuration of traffic signals. Three parameters <i>ns<sub>i,j</sub></i>, <i>ew<sub>i,j</sub></i> and <i>s<sub>i,j</sub></i> describe the traffic signal (<i>i</i>, <i>j</i>) which stands at the crossing point of the <i>i</i>-th avenue and the <i>j</i>-th drive. <i>ns<sub>i,j</sub></i> and <i>ew<sub>i,j</sub></i> (1 &le; <i>ns<sub>i,j</sub></i>, <i>ew<sub>i,j</sub></i> < 100) are time intervals for which the light for a meridional direction and a zonal direction is green, respectively. <i>s<sub>i,j</sub></i> is the initial state of the light: 0 indicates the light is green for a meridional direction, 1 for a zonal direction. All the traffic signal have just switched the state to <i>s<sub>i,j</sub></i> at your departure time. </p> <p> The last two lines of a case specify the position of your house (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i> ) and your friend’s house (<i>x<sub>d</sub></i>, <i>y<sub>d</sub></i> ), respectively. These coordinates are relative to the traffic signal (0, 0). <i>x</i>-axis is parallel to the drives, and <i>y</i>-axis is parallel to the avenues. x-coordinate increases as you go east, and y-coordinate increases as you go north. You may assume that these positions are on streets and will never coincide with any intersection. </p> <p> All parameters are integers and separated by a blank character. </p> <p> The end of input is identified by a line containing two zeros. This is not a part of the input and should not be processed. </p> <H2>Output</H2> <p> For each test case, output a line containing the shortest possible time from your house to your friend’s house. </p> <H2>Sample Input</H2> <pre> 4 4 2 2 2 2 2 2 99 1 0 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 99 1 0 99 1 0 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 99 1 0 1 0 1 6 2 2 10 10 5 5 0 5 5 0 5 5 0 5 5 0 5 0 5 10 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 28 25 </pre>
p01531
<h1> Flick Input</h1> <h2> A: フリック入力</h2> <p> 二次元が大好きな大学生,通称2D君は,長年使用していたガラパゴス携帯からスマホに買いかえた.初めてスマホを操作した2D君は,文字入力の方式が,昔の携帯と少し違うことに気付いた.スマホでは,画面をタッチ・フリックできることを利用して,フリック入力という方式が採用されていたのである(フリックとは,「画面上で指を滑らせて弾く操作」を意味する).フリック入力は,次に示すような文字入力方式である. </p> <p> フリック入力では,図A(a)のように,0-9の10個のボタンにより入力を行う(#と*については,今回は省略している).各ボタンには,図のようにあ行-わ行が1つずつ割り当てられている. </p> <p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day1_A" width="600"> </td> </tr> <tr> <td> <center> 図A: スマホのボタン詳細 </center> </td> </tr> </table> </center> </p> <p> ある1つのボタンは,図A(b)に表す方法により操作することができる.つまり, </p> <ul> <li> ボタンを「タッチ」するだけだと,そのボタンに対応する「あ段」の文字を出力</li> <li> ボタンを「左に向かってフリック」すると,「い段」を出力</li> <li> ボタンを「上に向かってフリック」すると,「う段」を出力</li> <li> ボタンを「右に向かってフリック」すると,「え段」を出力</li> <li> ボタンを「下に向かってフリック」すると,「お段」を出力</li> </ul> <p> ということである.フリック入力の仕方を全てのボタンについて表すと図A(c)のようになる.「ん」を出力するためには,ボタン0を上側にフリックすることに注意してほしい. </p> <p> あなたの仕事は,フリック入力の操作を示す文字列が与えられたとき,その操作の結果出力される文字列を求めることである. </p> <h2> Input</h2> <p> フリック入力の操作を表す文字列が,1行で与えられる(2文字以上1000文字以下).この文字列は,操作するボタンを表す'0'-'9'の数字と,フリック方向を表す'T','L','U','R','D'の5種類の文字の組み合わせからなる. </p> <p> フリック方向を表す文字は,次の意味を表す. </p> <ul> <li> 'T':タッチするだけ</li> <li> 'L':左にフリックする</li> <li> 'U':上にフリックする</li> <li> 'R':右にフリックする</li> <li> 'D':下にフリックする</li> </ul> <p> 例えば,&quot;2D&quot;は,「2のボタンを下に向かってフリック」という操作を表すため,「こ」を出力することができる. </p> <p> 与えられる文字列は,数字1文字とフリック方向を表す1文字が交互に現れる.また,必ず数字1文字から始まり,フリック方向を表す1文字で終わる.さらに,図A(c)において,文字がない場所に向かってフリックを行うことはない(&quot;8L&quot;などの入力はない). </p> <h2> Output</h2> <p> フリック入力操作の結果を表す文字列をローマ字表記で出力せよ. </p> <p> ローマ字の子音には, </p> <ul> <li> か行:'k'</li> <li> さ行:'s'</li> <li> た行:'t'</li> <li> な行:'n'</li> <li> は行:'h'</li> <li> ま行:'m'</li> <li> や行:'y'</li> <li> ら行:'r'</li> <li> わ行:'w'</li> </ul> <p> を使用すること.ひらがな1文字を表すローマ字は,上記で表される子音と母音('a','i','u','e','o')をセットにして2文字で出力すること.&quot;shi&quot;や&quot;fu&quot;はこの条件に反するため間違いである.ただし,「あ行」の文字は母音1文字だけを出力し,「ん」は'n'を2回続けて&quot;nn&quot;と出力すること. </p> <p> 文字列の最後には,改行を出力すること. </p> <h2> Sample Input 1</h2> <pre> 5R2D </pre> <h2> Sample Output 1</h2> <pre> neko </pre> <h2> Sample Input 2</h2> <pre> 8U9U6U0T </pre> <h2> Sample Output 2</h2> <pre> yuruhuwa </pre> <h2> Sample Input 3</h2> <pre> 9L4U7R1L2D0U4R3U4D </pre> <h2> Sample Output 3</h2> <pre> ritumeikonntesuto </pre>
p02034
<h2>E: 往復文字列 / Round-trip String</h2> <h3>物語</h3> <p>ここは全人類が競技プログラマーになった世界。この世界ではみなさんの生きる現代では考えられないような習慣が多数存在する。その中の一つに、両親、特に母親に感謝の証を表す時は、文字列を送るという風習がある。送る文字列としてどのような文字列がふさわしいかは地域差があるが、北の大地北海道では、できるだけシンプルな文字列が贈り物としてふさわしい。また、送られた側の母親は子供に返礼として、送られた文字列がどれほど美しいかを答える必要がある。</p> <p>さて、今あなたは1児の母親から相談を受けている。その母親は子供から素晴らしそうな文字列をもらったのだが、どれくらい素晴らしいのかうまく測れないでいるそうだ。北海道の風習では、母親に送る文字列 <var>T</var> はある文字列 <var>S</var> を往復させて作ることになっている。この時、 <var>S</var> ができるだけ短い文字列ならばより素晴らしい文字列 <var>T</var> である。母親は子供の頑張りに報いるため、<var>T</var> を作ることができる文字列の中で、最短の文字列を見つけてあげたいが、それはなかなか難しいとのことだ。あなたのプログラミング能力を駆使して母親の悩みを解決して欲しい。</p> <h3>問題</h3> <p>長さが <var>2</var> 以上の文字列 <var>S</var> から、以下のルールに従って長さ <var>N</var> の文字列 <var>T</var> を生成する。ここで、 <var>S</var> の文字列長を <var>K</var> とし、<var>T[i]</var> は文字列 <var>T</var> の <var>i</var> 番目の文字を表す。ここで、 <var>T</var> の先頭文字は <var>0</var> 番目の文字とする。</p> <p><var>T[i] = S[K - 1 - | (i</var> $\bmod$ <var>(2K - 2)) - K + 1 |]</var></p> <p><var>T</var> のみが与えられたとき、 <var>T</var> を生成する文字列は複数考えられる。 それらの文字列の中で最小の文字列長 <var>K_{min}</var> を出力せよ。</p> <h3>入力形式</h3> <pre> <var>N</var> <var>T</var> </pre> <h3>制約</h3> <ul> <li> <var>2 \leq N = |T| \leq 1,000,000</var></li> <li> 文字列は英小文字のみからなる</li> </ul> <h3>出力形式</h3> <p><var>T</var> を生成する長さ最小の文字列 <var>S</var> の長さ <var>K_{min}</var> を出力してください。</p> <h3>入力例1</h3> <pre> 6 tabata </pre> <h3>出力例1</h3> <pre>3</pre> <code>tabata</code> 、<code>tabat</code> 、<code>tab</code> の <var>3</var> つが考えられますが、 <code>tab</code> が長さ最小なので、答えは <var>3</var> です。 <h3>入力例2</h3> <pre> 4 hcpc </pre> <h3>出力例2</h3> <pre>3</pre> <h3>入力例3</h3> <pre> 60 aaaaaabbbbbbbbbbbaaaaaaaaaaabbbbbbbbbbbaaaaaaaaaaabbbbbbbbbb </pre> <h3>出力例3</h3> <pre>12</pre>
p00009
<H1>Prime Number</H1> <p> Write a program which reads an integer <var>n</var> and prints the number of prime numbers which are less than or equal to <var>n</var>. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset has an integer <var>n</var> (1 &le; <var>n</var> &le; 999,999) in a line. </p> <p> The number of datasets is less than or equal to 30. </p> <H2>Output</H2> <p> For each dataset, prints the number of prime numbers. </p> <H2>Sample Input</H2> <pre> 10 3 11 </pre> <H2>Output for the Sample Input</H2> <pre> 4 2 5 </pre>
p02464
<h1>Set Intersection</h1> <p> Find the intersection of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ </pre> <p> Elements of $A$ and $B$ are given in ascending order respectively. There are no duplicate elements in each set. </p> <h2>Output</h2> <p> Print elements in the intersection in ascending order. Print an element in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n, m \leq 200,000$</li> <li>$0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$</li> <li>$0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 1 2 5 8 5 2 3 5 9 11 </pre> <h2>Sample Output 1</h2> <pre> 2 5 </pre>
p00459
<H1>シャッフル </H1> <h2>問題</h2> <p> 1 から n までの番号が書かれた n 枚のカードがある.まず,一番上が番号 1 のカード,上から2枚目が番号 2 のカード,…,一番下が番号 n のカードとなるように順番に重ねて,カードの山を作る. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t5-1"><br> <br> <p> カードの山に対して,「シャッフル(x,y)」と呼ばれる次のような操作を行うことで,カードを並び替える(x, y は 1 &le; x &lt; y &lt; n をみたす整数). </p> <p> <b>シャッフル(x,y)</b><br> n 枚のカードを,一番上から x 枚目までのカードからなる山A, x+1 枚目から y 枚目のカードからなる山B, y+1 枚目から n 枚目のカードからなる山C の3つの山に分ける.そして,山Aの上に山Bを重ね,さらにその上に山Cを重ねる. </p> <p> 例えば,順番に並んでいる9枚のカードに対して「シャッフル(3,5)」を行うと, 9 枚のカードに書かれた番号は, 上から順番に 6, 7, 8, 9, 4, 5, 1, 2, 3 となる. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t5-2"><br> <br> <p> 最初の山の状態から m 回のシャッフル「シャッフル(x<sub>1</sub>, y<sub>1</sub>)」「シャッフル(x<sub>2</sub>, y<sub>2</sub>)」 … 「シャッフル(x<sub>m</sub>, y<sub>m</sub>)」を順番に行った後のカードの山において,上から数えて p 枚目から q 枚目のカードの中に番号が r 以下のカードが何枚含まれているかを求めるプログラムを作成せよ. </p> <h2>入力</h2> <p> 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. </p> <p> 入力は m+3 行からなる. 1 行目にはカードの枚数 n が書かれている(3 &le; n &le; 1000000000 = 10<sup>9</sup>). 2 行目にはシャッフルの回数を表す整数 m が書かれている(1 &le; m &le; 5000). 3 行目には整数 p, q, r が書かれている(1 &le; p &le; q &le; n, 1 &le; r &le; n). i + 3 行目(1 &le; i &le; m)には2つの整数 x<sub>i</sub>, y<sub>i</sub> (1 &le; x<sub>i</sub> &lt; y<sub>i</sub> &lt; n) が空白を区切りとして書かれている. </p> <p> n が 0 のとき入力の終了を示す. データセットの数は 5 を超えない. </p> <h2>出力</h2> <p> データセットごとに, m 回のシャッフル後のカードの山において,上から数えて p 枚目から q 枚目のカードの中に含まれている番号が r 以下のカードの枚数を1行に出力せよ. </p> <h2>入出力例</h2> <h3>入力例</h3> <pre> 9 1 3 7 4 3 5 12 3 3 8 5 3 8 2 5 6 10 0 </pre> <h3>出力例</h3> <pre> 2 3 </pre> <p> 1つ目の入力例の山に対して, 「シャッフル(3,5)」を行うと,カードは上から順番に 6, 7, 8, 9, 4, 5, 1, 2, 3 となる.上から数えて 3 枚目から 7 枚目に含まれる番号が 4 以下のカードは,番号 4 と番号 1 の 2 枚である. </p> <p> また,2つ目の入力例の山に対して, 「シャッフル(3,8)」「シャッフル(2,5)」「シャッフル(6,10)」を順番に行うと,カードは上から順番に 9, 10, 3, 11, 12, 4, 5, 6, 7, 8, 1, 2 となる.上から数えて 3 枚目から 8 枚目に含まれる番号が 5 以下のカードは 3 枚である. </p> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p02937
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are two strings <var>s</var> and <var>t</var> consisting of lowercase English letters. Determine if there exists an integer <var>i</var> satisfying the following condition, and find the minimum such <var>i</var> if it exists.</p> <ul> <li>Let <var>s'</var> be the concatenation of <var>10^{100}</var> copies of <var>s</var>. <var>t</var> is a subsequence of the string <var>{s'}_1{s'}_2\ldots{s'}_i</var> (the first <var>i</var> characters in <var>s'</var>).</li> </ul> </section> </div> <div class="part"> <section> <h3>Notes</h3><ul> <li>A subsequence of a string <var>a</var> is a string obtained by deleting zero or more characters from <var>a</var> and concatenating the remaining characters without changing the relative order. For example, the subsequences of <code>contest</code> include <code>net</code>, <code>c</code>, and <code>contest</code>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |s| \leq 10^5</var></li> <li><var>1 \leq |t| \leq 10^5</var></li> <li><var>s</var> and <var>t</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> <var>t</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists an integer <var>i</var> satisfying the following condition, print the minimum such <var>i</var>; otherwise, print <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>contest son </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p><var>t =</var> <code>son</code> is a subsequence of the string <code>contestcon</code> (the first <var>10</var> characters in <var>s' =</var> <code>contestcontestcontest...</code>), so <var>i = 10</var> satisfies the condition.</p> <p>On the other hand, <var>t</var> is not a subsequence of the string <code>contestco</code> (the first <var>9</var> characters in <var>s'</var>), so <var>i = 9</var> does not satisfy the condition.</p> <p>Similarly, any integer less than <var>9</var> does not satisfy the condition, either. Thus, the minimum integer <var>i</var> satisfying the condition is <var>10</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>contest programming </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p><var>t =</var> <code>programming</code> is not a substring of <var>s' =</var> <code>contestcontestcontest...</code>. Thus, there is no integer <var>i</var> satisfying the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>contest sentence </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>33 </pre> <p>Note that the answer may not fit into a <var>32</var>-bit integer type, though we cannot put such a case here.</p></section> </div> </span>
p01618
<h1>F: Opeartion training for BYDOL / BYDOLの操作訓練</h1> <p>u'sというスクールアイドルを結成した私達は,さらなる高みを目指すため,部室にあったDVDで憧れの841プロダクションに所属するアイドル達を見ていた. このアイドル達は今でこそ輝くステージの上で活躍しているが,以前はBYDOLと呼ばれるロボットに乗り込み,隕石の撤去作業をしていたらしい. そこで,トップアイドルになるために,BYDOLの操縦技術が必要であることを知った私達は,急遽BYDOLを入手し,他校のスクールアイドルとBYDOLを用いた模擬戦をすることにした.</p> <p>この模擬戦では,白の軍と赤の軍に分かれ,BYDOLに積まれている弾により撃ち合いを行う. 各軍のメンバは,それぞれBYDOLに乗り込み,合図が出ると同時に<strong>「1度だけ」</strong>弾を撃つ. 合図が出る時点での全てのBYDOLの座標は決まっており,BYDOL同士はレーダーによって互いの座標を把握できる. 同じ座標にBYDOLが2台以上現れることはない.</p> <p>BYDOLが移動できるフィールドは2次元平面で表され,非常に広くフィールド全体を囲む壁はないものとして考える. しかし,フィールド内部にいくつかの円形の壁が用意されている. この壁の内側は,コンクリートで塗り固められているため,BYDOLが侵入することはできない. 壁を構成する円は,互いに接したり交差したり内包関係になったりすることはなく,BYDOLがいる座標上に壁は存在しない.</p> <p>各BYDOLには,合図が出る時点で位置する座標,射程,1度に発射できる弾数,壁で反射する弾を積んでいるか,倒された時に敵軍が得る点数の5つのパラメータが設定されている.</p> <p>弾は,BYDOLがいる位置から360度どの方向へも発射することができ,一直線状に進む. 発射されてから進んだ弾の距離が射程の値以下である間,かつ他のBYDOLや壁に弾が当たらない間であれば,弾は進み続ける. フィールド上を動く全ての弾は,弾道が交差していても衝突しないものとする.</p> <p>BYDOLによっては壁で反射する弾を積んでいる場合がある. この場合のBYDOLの弾は全て,1回のみ壁で反射する. ただし,自分のBYDOLから壁の反射した地点までの距離と,反射した地点から相手のBYDOLまでの距離の合計が,射程の値以下でなければ,相手に当たったことにはならない. 壁で反射するときは図1のように,弾が壁に当たった地点に対して接線を引き,この線を基準に入射角<em>&theta;</em><sub>1</sub>と反射角<em>&theta;</em><sub>2</sub>が等しくなるように反射する. 弾道が壁を構成する円に接する場合,そのまままっすぐ弾は進み,壁で反射したことにはならない.</p> <div align="center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day3_F_F_fig_sabage1" alt="弾の反射"/> <p><strong>図1:</strong> 弾の反射</p> </div> <p>あるBYDOLは,発射できる弾数の範囲で,1度に複数の弾を撃ち,複数のBYDOLに当てることができる.ただし,同じBYDOLが,全く同じ方向へ向かって弾を2発以上撃つことは許されない.</p> <p>各BYDOLには,倒された時に敵軍が得る点数が設定されている. この撃ち合いでは,より多くの点数を得た軍が勝者となる. 同じ点数を得た場合は,引き分けとする. BYDOLは1発弾を当てれば倒れるため,同じBYDOLに何発撃ち込もうが,得られる点数は1度きりである. 味方のBYDOLを撃った場合,失格になってしまうため絶対に撃ってはいけない. 自滅することも許されない.</p> <p>u'sにおける作戦指揮担当であるあなたの仕事は,各軍が最大の点数をとれるように行動したときの点数を求め,どちらの軍が勝つことができるのかを判定することである. これができれば,u'sはトップアイドルへ一歩近づくことができるだろう.</p> <div> <h1>Input</h1> <p>入力は次の形式で表される.</p> <div> <em>n</em> <em>m</em> <em>o</em><br /> <em>ax</em><sub>1</sub> <em>ay</em><sub>1</sub> <em>ap</em><sub>1</sub> <em>aq</em><sub>1</sub> <em>ar</em><sub>1</sub> <em>as</em><sub>1</sub><br /> ...<br /> <em>ax</em><sub>n</sub> <em>ay</em><sub>n</sub> <em>ap</em><sub>n</sub> <em>aq</em><sub>n</sub> <em>ar</em><sub>n</sub> <em>as</em><sub>n</sub><br /> <em>bx</em><sub>1</sub> <em>by</em><sub>1</sub> <em>bp</em><sub>1</sub> <em>bq</em><sub>1</sub> <em>br</em><sub>1</sub> <em>bs</em><sub>1</sub><br /> ...<br /> <em>bx</em><sub>m</sub> <em>by</em><sub>m</sub> <em>bp</em><sub>m</sub> <em>bq</em><sub>m</sub> <em>br</em><sub>m</sub> <em>bs</em><sub>m</sub><br /> <em>wx</em><sub>1</sub> <em>wy</em><sub>1</sub> <em>wr</em><sub>1</sub><br /> ...<br /> <em>wx</em><sub>o</sub> <em>wy</em><sub>o</sub> <em>wr</em><sub>o</sub><br /> </div> <br/> <p>全ての数値は整数で入力される. <em>n</em>, <em>m</em> (1 ≦ <em>n</em>, <em>m</em> ≦ 50) は白の軍と赤の軍のBYDOLの数,<em>o</em> (0 ≦ <em>o</em> ≦ 15) は壁の数を表す. <em>ax</em><sub>i</sub>, <em>ay</em><sub>i</sub> (0 ≦ <em>ax</em><sub>i</sub>, <em>ay</em><sub>i</sub> ≦ 100) はi番目の白の軍のBYDOLの座標,<em>ap</em><sub>i</sub> (0 ≦ <em>ap</em><sub>i</sub> ≦ 200) は射程,<em>aq</em><sub>i</sub> (1 ≦ <em>aq</em><sub>i</sub> ≦ 5) は1度に発射できる弾の数,<em>ar</em><sub>i</sub> (0 &lt;= <em>ar</em><sub>i</sub> &lt;= 1) は壁で反射する弾を積んでいるかどうか,<em>as</em><sub>i</sub> (0≦ <em>as</em><sub>i</sub> ≦ 100) は倒された時に,敵軍が得る点数である. <em>ar</em><sub>i</sub> が,0であるときは所持している弾が反射できないこと,1であるときは反射できることを表している. 赤の軍のBYDOLの情報も同様に与えられる.</p> <p>その後,壁の中心座標(<em>wx</em><sub>i</sub>, <em>wy</em><sub>i</sub>)と半径 <em>wr</em><sub>i</sub> が与えられる(0 ≦ <em>wx</em><sub>i</sub>, <em>wy</em><sub>i</sub> ≦ 100, 1 ≦ <em>wr</em><sub>i</sub> ≦ 30) .</p> </div> <div> <h1>Output</h1> <p>白の軍と赤の軍それぞれが,最も点数が得られるように弾を発射したときの点数を空白区切りで1行目に出力せよ. さらに,白の軍が勝つ場合はwin,負ける場合はlose,引き分けの場合はdrawを2行目に出力せよ. 出力には,これら以外の文字があってはならない.</p> </div> <div> <h1>Sample Input 1</h1> <pre> 2 2 0 0 0 5 1 0 0 1 0 5 1 0 0 0 1 5 1 0 10 1 1 5 1 0 10 </pre> </div> <div> <h1>Sample Output 1</h1> <pre> 20 0 win </pre> </div> <div> <h1>Sample Input 2</h1> <pre> 2 3 0 0 0 5 1 0 20 1 0 5 1 0 10 10 10 4 1 0 100 10 0 1 1 0 50 4 0 5 1 0 10 </pre> </div> <div> <h1>Sample Output 2</h1> <pre> 10 10 draw </pre> </div> <div> <h1>Sample Input 3</h1> <pre> 1 1 2 0 0 20 1 1 20 10 0 20 1 0 20 5 0 2 5 8 2 </pre> </div> <div> <h1>Sample Output 3</h1> <pre> 20 0 win </pre> </div> <div> <h1>Sample Input 4</h1> <pre> 1 1 1 0 0 5 1 0 5 5 0 5 1 0 10 1 1 1 </pre> </div> <div> <h1>Sample Output 4</h1> <pre> 10 5 win </pre> <div> <h1>Sample Input 5</h1> <pre> 1 2 5 13 27 19 4 0 30 14 14 34 4 1 9 49 71 21 3 1 31 5 86 18 85 27 3 90 91 1 34 50 10 92 54 15 </pre> </div> <div> <h1>Sample Output 5</h1> <pre> 9 30 lose </pre> </div>
p03625
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> sticks with negligible thickness. The length of the <var>i</var>-th stick is <var>A_i</var>.</p> <p>Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>4 \leq N \leq 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>A_i</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> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible area of the rectangle. If no rectangle can be formed, print <var>0</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 3 1 2 4 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p><var>1 \times 2</var> rectangle can be formed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>No rectangle can be formed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 3 3 3 3 4 4 4 5 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>20 </pre></section> </div> </span>
p01248
<H1><font color="#000">Problem I:</font> Text Justification</H1> <p> You are hired by the ∀I¶אΞ℘, an extraterrestrial intelligence, as a programmer of their typesetting system. Your task today is to design an algorithm for <i>text justification</i>. </p> <p> Text justification is to equalize the line widths as much as possible by inserting line breaks at appropriate posi- tions, given a word sequence called a <i>paragraph</i> and the width of the paper. Since you have not developed an automatic hyphenation algorithm yet, you cannot break a line in the middle of a word. And since their language does not put spaces between words, you do not need to consider about spacing. </p> <p> To measure how well the text is justified in one configuration (i.e., a set of lines generated by inserting line breaks to a paragraph), you have defined its <i>cost</i> as follows: </p> <ul> <li> The total cost of a paragraph is the sum of the cost of each line.</li> <li> The cost for the last line is defined as max(0, <i>s</i> - <i>w</i>).</li> <li> The cost for other lines are given by |<i>s</i> - <i>w</i>|.</li> </ul> <p> where <i>s</i> is the sum of the widths of the words in the line, and <i>w</i> is the width of the paper. </p> <p> Please design the algorithm which takes a paragraph and calculates the configuration of the minimum cost. </p> <H2>Input</H2> <p> The input consists of multiple test cases. </p> <p> The first line of each test case contains two positive integers <i>n</i> and <i>w</i> (0 &le; <i>n</i> &le; 1000 and 0 &le; <i>w</i> &le; 1,000,000). <i>n</i> is the length of paragraph and <i>w</i> is the width of the used paper. Each of the following n lines contains one positive integer <i>a<sub>i</sub></i> which indicates the width of the <i>i</i>-th word in the paragraph. Here it is guaranteed that 0 &le; <i>a<sub>i</sub></i> &le; <i>w</i>. </p> <p> The input terminates with the line containing two zeros. This is not a part of any test case and should not be processed. </p> <H2>Output</H2> <p> For each test case, print the case number and the minimum cost for the paragraph. </p> <H2>Sample Input</H2> <pre> 4 10 8 6 9 1 4 7 1 2 3 4 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 4 Case 2: 1 </pre>
p03275
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will define the <strong>median</strong> of a sequence <var>b</var> of length <var>M</var>, as follows:</p> <ul> <li>Let <var>b'</var> be the sequence obtained by sorting <var>b</var> in non-decreasing order. Then, the value of the <var>(M / 2 + 1)</var>-th element of <var>b'</var> is the median of <var>b</var>. Here, <var>/</var> is integer division, rounding down.</li> </ul> <p>For example, the median of <var>(10, 30, 20)</var> is <var>20</var>; the median of <var>(10, 30, 20, 40)</var> is <var>30</var>; the median of <var>(10, 10, 10, 20, 30)</var> is <var>10</var>.</p> <p>Snuke comes up with the following problem.</p> <p>You are given a sequence <var>a</var> of length <var>N</var>. For each pair <var>(l, r)</var> (<var>1 \leq l \leq r \leq N</var>), let <var>m_{l, r}</var> be the median of the contiguous subsequence <var>(a_l, a_{l + 1}, ..., a_r)</var> of <var>a</var>. We will list <var>m_{l, r}</var> for all pairs <var>(l, r)</var> to create a new sequence <var>m</var>. Find the median of <var>m</var>.</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 median of <var>m</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 10 30 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>30 </pre> <p>The median of each contiguous subsequence of <var>a</var> is as follows:</p> <ul> <li>The median of <var>(10)</var> is <var>10</var>.</li> <li>The median of <var>(30)</var> is <var>30</var>.</li> <li>The median of <var>(20)</var> is <var>20</var>.</li> <li>The median of <var>(10, 30)</var> is <var>30</var>.</li> <li>The median of <var>(30, 20)</var> is <var>30</var>.</li> <li>The median of <var>(10, 30, 20)</var> is <var>20</var>.</li> </ul> <p>Thus, <var>m = (10, 30, 20, 30, 30, 20)</var> and the median of <var>m</var> is <var>30</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 5 9 5 9 8 9 3 5 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p02872
<span class="lang-en"> <div class="part"> <section> <h3>Problem Setting</h3></section> </div> <div class="part"> <section> <h3>Overview</h3> <ul> <li><strong>Concept:</strong> In this programming contest, you will run a delivery service. Customers will place orders with your shop. Each order has a unique <var>\text{ID}</var> and should be delivered to the corresponding customer. Your delivery service has one car. The car will fetch the ordered item from the shop and deliver it to the customer.</li> <li><strong>Score:</strong> Your goal is to deliver as many items as possible, as quickly as possible in a given amount of time <var>T_{\text{max}}</var>. (Orders are expected until <var>0.95 \times T_{\text{max}}</var>).</li> <li><strong>Constraint:</strong> In this contest there is no constraint on the number of items you can place in the car. However, an item can only be loaded in the car, by fetching it from the shop, after the order has been placed.</li> <li><strong>Problem A/B:</strong> In problem A all order positions and times are given to the contestant in advance and the contestant algorithm shall optimize the moves of the car to make as many deliveries as possible as fast as possible. On the other hand, in problem B orders appear online, that is new orders appear, while you move your car to make as many deliveries as possible as fast as possible.</li> </ul> <div style="text-align:center;"> <img alt="overview" src="https://img.atcoder.jp/hokudai-hitachi2019-1/7faf401c00c790b9a8cb5c6968dc80c3.png" title="overview"> </img></div> </section> </div> <div class="part"> <section> <h3>Specification of Time and Space:</h3> <ul> <li><strong>Time:</strong> In this contest we model the progress of time by integer values <var>0 \le t &lt; T_{\text{max}}</var>.</li> <li><strong>Map:</strong> In this contest we model a map by a simple, undirected, and connected graph <var>G=(V, E)</var>, consisting of a set of vertices <var>V</var> and a set of edges <var>E</var></li> <li><strong>Shop and customer locations:</strong> The vertices <var>u \in V</var> are labeled from <var>1</var> to <var>|V|</var> and the vertex <var>u=1</var> denotes the location of your shop, while vertices <var>u = 2,...,|V|</var> denote locations of potential customers. Here, <var>|V|</var> denotes the number of elements of the set <var>V</var>.</li> <li><strong>Streets:</strong> Each edge <var>\left\{ u, v \right\} \in E</var> represents a street connecting the vertices <var>u, v \in V</var>. The corresponding length is given by an integer edge weight <var>d_{u, v} \ge 1</var>.</li> <li><strong>Graph creation:</strong> The algorithm for generating the map graph based on a random seed is specified in the following pseudo-code. For further details, please see the sample code below.</li> </ul> <details> <summary style="display:list-item"> <b>Pseudo code:</b> Map graph generator </summary> <ul> <li> <b>Input:</b><var>|V|</var>, <var>|E|</var>, <var>\mathrm{MaxDegree}=5</var></li> <li> <b>2d vertex grid:</b> <ul> <li> First, find the largest integer <var>R&gt;0</var> such that <var>|V| = R^{2} + r</var>, with <var>r</var> being the smallest possible non-negative integer.</li> <li> Then we plot points <var>(x, y)</var> on the 2d vertex grid <var>(0 \leq x, y \lt R)</var>.</li> <li> For each point <var>(x, y)</var> add a uniform random offset <var>dx, dy \in [0, 1] </var>, giving the final vertex position <var>(x + dx, y + dy)\in [0,R] \times [0,R]</var>.</li> <li> Finally, add the remaining <var>r</var> vertices at a uniform random position <var>(x, y)</var> with <var>0 \leq x, y \leq R</var>.</li> <li> Vertex labels <var>u \in V</var> are assigned by random shuffling. The shop is the vertex <var>u=1</var>.</li> </ul> </li> <li> <b>How we create Highways:</b> <ul> <li> To generate a highway network, we create a complete graph <var>G_{\text{comp}}</var> on the vertex set <var>u \in V</var>, assigning each vertex pair <var>u, v \in V \times V</var> the Euclidean distance <var>W_{u, v}</var> as an edge weight.</li> <li> Next, we construct a <a href="https://en.wikipedia.org/wiki/Minimum_spanning_tree"> minimum spanning </a> tree of <var>G_{\text{comp}}</var>. The <var>|V|-1</var> edges of the minimum spanning tree are the highway network of the graph <var>G</var>. We assign each of those edges <var>\left\{ u, v \right\}</var> an edge weight <var>d_{u,v} \leftarrow \lceil 2 \times W_{u, v} \rceil </var>. </li> </ul> </li> <li> <b>How we add side roads:</b> <ul> <li> To create a network of side roads, we successively add <var>|E|-(|V|-1)</var> edges to the graph <var>G</var> as follows: <ul> <li> Update <var>\mathrm{cost}(u,v)</var>. </li> <li> Among the vertex pairs <var>\left( u, v \right) \in V\times V</var>, not yet connected by an edge, select a pair with minimal <var>\mathrm{cost}(u,v)</var>.</li> <li> Assign the edge weight <var>d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil </var>.</li> </ul> </li> <li> Here, <var>\mathrm{cost}(u,v)</var> is essentially based on the Euclidean distance of vertices, giving preference to connecting nearby vertices with low degree. In addition, preference is given to side roads along the rectangular grid, to avoid too many bridges. The detailed definitions are as follows: <ul> <li> Define <var>\mathrm{degree}(u)</var>, the degree of vertex <var>u\in V</var> as the number of incident edges. </li> <li> Define <var>\mathrm{color}(u)</var> for each vertex <var>u\in V</var> according to its original position <var>(x,y)</var> on the vertex grid as: <ul> <li> If <var>x+y</var> is even : <var>\mathrm{color}(u) = 0</var> </li> <li> If <var>x+y</var> is odd : <var>\mathrm{color}(u) = 1</var> </li> <li> For the remaining <var>r</var> vertices : Assign a color <var>\mathrm{color}(u) \in \left\{0,1\right\}</var> at random. </li> </ul> </li> <li> Define a factor <var>f(u,v)</var> as follows: <ul> <li> If <var>\mathrm{color}(u)</var> and <var>\mathrm{color}(v)</var> are the same : Set <var>\mathrm{f}(u,v) = 5</var> </li> <li> If <var>\mathrm{color}(u)</var> and <var>\mathrm{color}(v)</var> are different : Set <var>\mathrm{f}(u,v) = 1</var> </li> </ul> </li> <li> Define a factor <var>g(u)</var> as follows: <ul> <li> If <var>\mathrm{degree}(u) \lt \mathrm{MaxDegree}</var> : Set <var>g(u)=1</var> </li> <li> If <var>\mathrm{degree}(u) \geq \mathrm{MaxDegree}</var> : Set <var>g(u)=\infty</var> </li> </ul> </li> <li> Finally, the cost is defined as follows: <ul> <li> <var>\mathrm{cost}(u,v) = W_{u,v}\times \mathrm{degree}(u) \times \mathrm{degree}(v) \times f(u,v) \times g(u) \times g(v)</var>. </li> </ul> </li> </ul> </li> </ul> </li> <li> <b> How we assign order frequencies: </b> <ul> <li> Assign each vertex <var>u \in V</var> an order frequency <var>f_u \in \left\{0,1,2\right\}</var>.</li> <li> Init the order frequency of the shop vertex: <var>f_1 \leftarrow 0</var>. </li> <li> Init the order frequency of the other vertices: <var>f_u \leftarrow 1</var></li> <li> Now determine vertices with order frequency 2. For this draw a uniform random center point <var>c=(c_x,c_y)\in [R/4,3R/4]\times[R/4,3R/4]</var> and then for all vertices <var>u=2,...,|V|</var> do: <ul> <li> If <var>\mathrm{EuclideanDistance}(c,u)\le R/8 + \mathrm{uniformRandom}[0,R/8]</var>: <var>f_{u} \leftarrow 2</var> </li> </ul> </li> </ul> </li> </ul> </details> </section> </div> <div class="part"> <section> <h3>Specification of Car Locations and Moves:</h3> <p>In order to make deliveries you will operate a delivery car, which can take positions and make moves as specified below.</p> <ul> <li> <p><strong>Car position:</strong> A car can generally take two types of position:</p> <ul> <li>on a vertex <var>u \in V</var>.</li> <li>on an edge <var>\left\{ u, v \right\} \in E</var>. More specifically, it is located at a distance <var>x</var> <var>(0 \lt x \lt d_{u, v})</var> from <var> u </var> to <var> v </var>.</li> </ul> </li> <li> <p><strong>Car move:</strong> At each step <var> 0 \le t &lt; T_{\text{max}} </var> you have to choose one of the following actions in order to control your delivery car.</p> <ul> <li><code>stay</code>: stay at the current position.</li> <li><code>move w</code>: Take one step towards vertex <var>w \in V</var>.</li> </ul> <p>In case of choosing <code>move w</code>, <var>w</var> must obey the following constraints. A failure to obey these constraints results in a wrong answer <code>WA</code>. <ul> <li> <var>w</var> must be a vertex, i.e., <var>w \in V</var>.</li> <li> If the car is on vertex <var>u \in V</var>, there must be an edge connecting <var>u</var> and <var>v</var>, i.e., <var>\left\{ u, w \right\} \in E</var>.</li> <li> If the car is on the edge <var>\left\{ u, v \right\} \in E</var>, <var>w</var> must either be <var>w = u</var> or <var>w = v</var>.</li> </ul></p> </li> </ul> <div style="text-align:center;"> <img alt="Car position and moves" src="https://img.atcoder.jp/hokudai-hitachi2019-1/60c6d261238fb10fb2bb26d89d275f9c.png" title="Car position and moves"/> </div> </section> </div> <div class="part"> <section> <h3>Orders, Deliveries, and Constraints:</h3> <ul> <li><strong>Orders:</strong> Throughout the contest each order is characterized by three quantities: A unique order ID, a vertex <var>v \in V</var> indicating the order destination, and the order time <var>t</var> at which the order appeared. For the detailed format see below.</li> <li><strong>Order generation:</strong> At each time <var> 0 \le t \le T_{\text{last}} = 0.95 \times T_{\text{max}}</var> up to one new order can appear with probability <var>p_{\text{order}}(t)</var>. In case there is an order, the order destination <var>i</var> is chosen from the vertex set <var>V</var> with probability proportional to the order frequency <var>f_i</var>. For details, see the pseudo-code below or the sample code further below.</li> </ul> <details> <summary style="display:list-item"> <b>Pseudo code:</b> Order generation </summary> <ul> <li> <b>Input:</b> Last order time <var>T_{\text{last}}</var> and average order probability <var>p_{\text{order}}(t)</var>. </li> <li> <b>Init:</b> <var> \mathrm{ID} \leftarrow 0</var>. </li> <li> For each step <var>t = 0, ..., T_{\text{last}} </var> do: <ul> <li> Generate a uniform random number <var>r \in [0,1] </var>. </li> <li> <b>If</b> <var> r \le p_{\text{order}}(t) </var>: <ul> <li> Select a vertex position <var> u \in V </var> at random with probability proportional to the order frequency <var> f_{u} </var> of the vertex. </li> <li> <var>\mathrm{ID} \leftarrow \mathrm{ID} + 1</var> </li> <li> place order (new order ID, order time <var>t</var>, vertex position <var> u \in V </var>)</li> </ul> </li> <li> <b>Else:</b> place no order</li> </ul> </li> </ul> <ul style="list-style:none;"> <li> <b>Note:</b> The average order probability is defined as follows: <li> <var> p_{\text{order}}(t) = \begin{cases} t / T_{\text{peak}}, &amp; \text{if } 0\le t \lt T_{\text{peak}}, \\ (T_{\text{last}} - t) / (T_{\text{last}}- T_{\text{peak}}), &amp; \text{if } T_{\text{peak}} \le t \lt T_{\text{last}}, \\ 0, &amp; \text{if } T_{\text{last}} \le t, \end{cases} </var></li> <li>where <var>T_{\text{last}}:=0.95 \times T_{\max}</var> and <var>T_{\text{peak}}</var> is drawn randomly uniform from the interval <var>[0, T_{\text{last}}]</var>.</li> <li> Note: The value of <var>T_{\text{peak}}</var> will not be given as an input. </li> </li></ul> <div style="text-align:center;"> <img src="https://img.atcoder.jp/hokudai-hitachi2019-1/caa24f9e6a715e0d1a778f1fdfe4e14b.png"/> </div> </details> <ul> <li><strong>Delivery:</strong> To deliver an order, the contestant must do the following steps after the order has been placed:<ul> <li><strong>(1st) Move the car onto the shop:</strong> Note: When moving a car onto the shop, all orders with order time less than or equal to the current time, will be transfered into the car. On the other hand, orders which have not appeared yet, cannot be placed into the car.</li> <li><strong>(2nd) Move the car to the customer position:</strong> To finalize a delivery, move the car onto the vertex of the customer position. Note: Orders which have not been transfered into the car yet, will not be delivered, even if you arrive at the customer position.</li> </ul> </li> </ul> <div style="text-align:center;"> <img alt="constraint image" src="https://img.atcoder.jp/hokudai-hitachi2019-1/03b28647c6ddc92cc3cbb33ade09f468.png" title="Constraints"/> </div> <ul> <li><strong>Constraints:</strong> Throughout the contest, we assume each order has a unique <var>\text{ID}</var> and should be delivered to the corresponding customer. It is further assumed that an unlimited number of orders can be placed in the car.</li> </ul> </section> </div> <div class="part"> <section> <h3>Scoring</h3> <ul> <li> During the contest the total score of a submission is determined by summing the score of the submission with respect to 30 input cases.</li> <li> After the contest a system test will be performed. To this end, the contestant's <b>last submission</b> will be scored by summing the score of the submission on 100 previously unseen input cases.</li> <li> For each input case, the score is calculated as follows: <p style="text-align:center;"> <var> \text{Score} = \sum_{i \in D} {(T_{\text{max}})}^{2} - {(\mathrm{waitingTime}_i)}^{2}, </var> </p> Here we use the following definitions: <ul> <li> <var> D </var> : the set of orders delivered until <var>t=T_{\text{max}}</var></li> <li> the waiting time of the <var>i</var>th order: <var>\mathrm{waitingTime}_i = \mathrm{deliveredTime}_i - \mathrm{orderedTime}_i</var>.</li> <li>Note that an input case giving the output <code>WA</code> will receive <var>0</var> points.</li> </ul> </li> </ul></section> </div> <div class="part"> <section> <h3>Particulars of Problem B:</h3> <p> Problem B is an <span style="color:red"> interactive </span> contest, where the contestant code successively receives updates on newly generated and delivered orders from a host code, while simultaneously servicing the customer by moving the car to a neighboring position in every step <var>t=0,...,T_{\max}-1</var>. The precise flow which details the interaction of the contestant and host code is shown below. </p> <table class="table table-bordered"> <thead> <tr> <th align="center"></th> <th>Contestant Code</th> <th>Host Code</th> </tr> </thead> <tbody> <tr> <td align="center"></td> <td></td> <td>Generate and output graph <var>G</var></td> </tr> <tr> <td align="center">+</td> <td></td> <td>Time <var>t</var>: Generate and output new orders</td> </tr> <tr> <td align="center">+</td> <td></td> <td>Time <var>t</var>: If on shop, output orders loaded into car</td> </tr> <tr> <td align="center">+</td> <td>Time <var>t</var>: Determine and output a move</td> <td></td> </tr> <tr> <td align="center">+</td> <td></td> <td>Check feasibility of move; If move unfeasible: output <code>NG</code>, If feasible: output <code>OK</code></td> </tr> <tr> <td align="center">+</td> <td></td> <td>Time <var>t+1</var>: update and output information on delivered items (if any)</td> </tr> </tbody> </table> <p>Note: The host code outputs the graph only once. The processes marked by a "+" on the left side of the table are repeated iteratively for integers <var>t</var> in <var> t = 0,..., T_{\max} - 1</var>.</p> <hr/> </section> </div> <div class="part"> <section> <h3>Input/Output Format for the Standard IO</h3> <p>At first, the host code will output a graph <var>G</var>, the order frequencies <var>f_{i}</var> for each vertex <var>i</var>, which are proportional to the probability of an order to appear at vertex <var>i</var>, and the total number of steps <var>T_{\max}</var>.</p> <pre><var>|V|</var> <var>|E|</var> <var>u_1</var> <var>v_1</var> <var>d_{u_1, v_1}</var> <var>u_2</var> <var>v_2</var> <var>d_{u_2, v_2}</var> <var>\vdots</var> <var>u_{|E|}</var> <var>v_{|E|}</var> <var>d_{u_{|E|}, v_{|E|}}</var> <var>f_1</var> <var>f_2</var> <var>\ldots</var> <var>f_{|V|}</var> <var>T_{\max}</var> </pre> <ul> <li>First line: <var>|V|</var> number of vertices, <var>|E|</var> number of edges</li> <li>The next <var>|E|</var> lines: The edges of the graph. In particular, the <var>i</var>th line denotes the vertices <var>u_i</var> and <var>v_i</var> which form an edge, along with the corresponding edge weight <var>d_{u_i, v_i}</var>.</li> <li>The next line: The order frequencies <var>f_i</var> which determine the probability of an order at vertex <var>i</var> as <var>p_{i}=\frac{f_{i}}{\sum_{i}f_{i}}</var>.</li> <li>The last line: The total number of car updates <var>T_{\max}</var>.</li> </ul> <p>At time <var>t</var> we first obtain the following information through the standard input.</p> <pre><var>N_{\text{new}}</var> <var>\mathrm{new\_id}_1</var> <var>\mathrm{dst}_1</var> <var>\mathrm{new\_id}_2</var> <var>\mathrm{dst}_2</var> <var>\vdots</var> <var>\mathrm{new\_id}_{N_{\text{new}}}</var> <var>\mathrm{dst}_{N_{\text{new}}}</var> <var>N_{\text{put}}</var> <var>\mathrm{put\_id}_1</var> <var>\mathrm{put\_id}_2</var> <var>\mathrm{put\_id}_{N_{\text{put}}}</var> </pre> <ul> <li><var>N_{\text{new}}</var> represents the number of new orders which appeared at time <var>t</var>.</li> <li>The next <var>N_{\text{new}}</var> lines give the newly generated order information. The <var>i</var>th order information indicates that the order ID <var>\mathrm{new_{id}}_i</var> of the new order, while <var>\mathrm{dst}_i</var> denotes the vertex to which the customer wishes the order to be delivered.</li> <li><var>N_{\text{put}}</var> represents the number of items transfered into the car at time <var>t</var>.<ul> <li>If the car is not at the vertex of the store <var>N_{\text{put}}</var> will be zero.</li> </ul> </li> <li>The subsequent <var>N_{\text{put}}</var> lines indicate the order information for the newly loaded items. In particular, the <var>i</var>th line indicates that the order ID corresponding to the product loaded in the car is <var>\mathrm{put_{id}}_i</var>.</li> </ul> <p>Next, in order to move the delivery car to a neighboring position the contestant code must at every time <var>t</var> (<var>0 \leq t \lt T_{\max}</var>) output the following <var>\mathrm{command}</var> to the standard output.</p> <pre><var>\mathrm{command}</var> </pre> <p>Here, <var>\mathrm{command}</var> must be of the following form</p> <ul> <li>If you want the car to <code>stay</code> at its current position, send <code>-1</code> to the standard output</li> <li>If you want the car to move one step towards a neigboring vertex <code>move w</code>, send <code>w</code> to the standard output</li> </ul> <p>Note: In case you choose <code>move w</code>, <var>w</var> must meet all of the following conditions. If any of the following conditions is violated, the host code will output <code>NG</code> and the contestant should terminate the program, ultimately leading to <code>WA</code> (incorrect).</p> <ul> <li><var>w</var> is a vertex index with <var>w \in \left\{1, ... , |V|\right\}</var></li> <li>If the car is on a vertex <var>u</var>, the edge <var>\left\{ u, w \right\} \in E</var> must exist</li> <li>If the car is on an edge <var>\left\{ u, v \right\}</var>, <var>w</var> must either be <var>w = u</var> or <var>w = v</var></li> </ul> <p>After your action at time <var> t </var> is send to the standard output, the host code will send the following information about time <var> t + 1 </var> to the standard input.</p> <pre><var>\mathrm{verdict}</var> <var>N_{\text{achieve}}</var> <var>\mathrm{achieve\_id}_1</var> <var>\mathrm{achieve\_id}_2</var> <var>\vdots</var> <var>\mathrm{achieve\_id}_{N_{\text{achieve}}}</var> </pre> <ul> <li><var>\mathrm{verdict}</var> is a string indicating whether your action at time <var> t </var> was valid. It can be one of the two following options.<ul> <li><code>OK</code>: Indicating that your action was feasible</li> <li><code>NG</code>: Indicates that your action is infeasible. If you receive this input, <strong>you must terminate the program immediately.</strong> It is guaranteed to be WA (incorrect), if it is terminated immediately.If you do not terminate immediately the behavior is undefined.</li> </ul> </li> <li><var>N_{\text{achieve}}</var> represents the number of orders that have been delivered at time <var>t</var>.<ul> <li>If the car is not at a delivery vertex, no orders have been delivered and <var>N_{\text{achieve}}=0</var>.</li> </ul> </li> <li>The subsequent <var>N_{\text{achieve}}</var> lines indicate the delivered orders. In particular, the <var>i</var>th line indicates the order ID <var>\mathrm{achieve\_{id}}_i</var>.</li> </ul> <p>Finally, after receiving the standard input of the host code after the last step <var>T_{\max}</var> <strong>you must terminate the program immediately.</strong></p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <h4>I/O Constraints</h4> <ul> <li> All numbers given through the standard input are integers. </li> <li> All outputs must be integers </li> <li> <var>T_{\text{max}} = 10000</var> </li> <li> <var>200 \leq |V| \leq 400</var> </li> <li> <var>1.5 |V| \leq |E| \leq 2|V|</var></li> <li><var>1 \leq u_{i}, v_{i} \leq |V|</var> <var>(1 \leq i \leq |E|)</var></li> <li><var>1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil</var> <var>(1 \leq i \leq |E|)</var></li> <li>The given graph has no self-loops, no multiple edges and is guaranteed to be connected.</li> <li> <var>f_1 = 0</var> </li> <li> <var>f_i \in \left\{ 1, 2 \right\}</var> (<var>2 \leq i \leq |V|</var>) </li> <li> <var>\mathrm{verdict} \in \left\{ \text{"OK"}, \text{"NG"} \right\}</var> </li> <li><var>0 \leq N_{\text{new}} \leq 1</var></li> <li><var>1 \leq \mathrm{new\_id}_{i} \leq T_{\text{last}}+1</var> <var>(1 \leq i \leq N_{\text{new}})</var>. Note: If all orders are generated by the order generation rule as explained above, the total number of orders is at most <var>T_{\text{last}}+1</var>. Therefore, the possible range of <var>\mathrm{new\_id}_{i}</var> should be from <var>1</var> to <var>T_{\text{last}}+1</var>.</li> <li>The order IDs <var>\mathrm{new\_{id}}_i</var> are unique. </li> <li><var>2 \leq \mathrm{dst}_i \leq |V|</var> <var>(1 \leq i \leq N_{\text{new}})</var></li> <li> The integer which the contestant outputs to the standard output at time <var>t</var> must either be <var>-1</var> or <var>1 \leq w \leq |V|</var> </li> </ul> <hr/> </section> </div> <div class="part"> <section> <h3>Input/Output Example</h3> <style> .pre-sample-inout { margin: 0; } </style> <table class="table table-striped table-bordered"> <tr> <th>Time</th> <th>Contestant</th> <th>Host Code</th> <th>Explanation</th> </tr> <tr> <td></td> <td></td> <td> <pre class="pre-sample-inout"> 5 7 1 2 5 5 3 4 2 4 8 1 5 1 2 3 3 4 5 3 4 3 9 0 1 1 5 5 500 </pre> </td> <td> At first, the host code provides the graph data through the standard input. In this example, the graph has <var>|V| = 5</var> vertices and <var>| E | = 7</var> edges. Next, the order frequency for each vertex is given in one line. Finally, <var>T_{\max}</var> is given. </td> </tr> <tr> <td rowspan="3"><var>0 \rightarrow 1</var></td> <td></td> <td> <pre class="pre-sample-inout"> 1 1 5 1 1 </pre> </td> <td> At time <var>t=0</var> we get one order. This order has ID<var>= 1</var> and should be delivered to vertex <var> 5</var>. Because your car is currently at vertex one, the order will be automatically transfered into your car. In this way, when your car is at the shop, all orders which have been made at present and before, will automatically be loaded into your car.</td> </tr> <tr> <td> <pre class="pre-sample-inout"> 2 </pre> </td> <td></td> <td>You decided to move one step towards vertex.</td> </tr> <tr> <td></td> <td> <pre class="pre-sample-inout"> OK 0 </pre> </td> <td>The first line indicates that your move was feasible. The second line shows that no orders have been delivered.</td> </tr> <tr> <td rowspan="3"><var>1 \rightarrow 2</var></td> <td></td> <td> <pre class="pre-sample-inout"> 1 2 2 0 </pre> </td> <td> One new order (ID <var>=2</var>, delivery vertex <var>=2</var>) has occured. Your car is on the edge between vertex <var>1</var> and <var>2</var>, so zero orders have been transfered to your car.</td> </tr> <tr> <td> <pre class="pre-sample-inout"> -1 </pre> </td> <td></td> <td>You decided to keep your car in the same position.</td> </tr> <tr> <td></td> <td> <pre class="pre-sample-inout"> OK 0 </pre> </td> <td> Your move was valid. No orders will be delivered, because you are not at a delivery item position.</td> </tr> <tr> <td rowspan="3"><var>2 \rightarrow 3</var></td> <td></td> <td> <pre class="pre-sample-inout"> 1 3 4 0 </pre> </td> <td>A new order (ID <var>=3</var>, delivery vertex <var>=4</var>) has appeared. </td> </tr> <tr> <td> <pre class="pre-sample-inout"> 1 </pre> </td> <td></td> <td>You decided to move back one step towards vertex <var>1</var>. In this way you are allowed to perform a U-turn.</td> </tr> <tr> <td></td> <td> <pre class="pre-sample-inout"> OK 0 </pre> </td> <td>No orders have been delivered.</td> </tr> <tr> <td rowspan="3"><var>3 \rightarrow 4</var></td> <td></td> <td> <pre class="pre-sample-inout"> 0 2 2 3 </pre> </td> <td>Since the car has returned to the store, products corresponding to order ID 2 and 3 are loaded onto the car.</td> </tr> <tr> <td> <pre class="pre-sample-inout"> 5 </pre> </td> <td></td> <td>The contestant has decided to move one step towards vertex 5.</td> </tr> <tr> <td></td> <td> <pre class="pre-sample-inout"> OK 1 1 </pre> </td> <td>Since you arrived at vertex 5, the order with ID <var>1</var> was delivered.</td> </tr> <tr> <td rowspan="3"><var>4 \rightarrow 5</var></td> <td></td> <td> <pre class="pre-sample-inout"> 0 0 </pre> </td> <td>There is no new order. </td> </tr> <tr> <td> <pre class="pre-sample-inout"> 5 </pre> </td> <td></td> <td>The contestant decides to move one step towards vertex <var>5</var>.</td> </tr> <tr> <td></td> <td> <pre> NG </pre> </td> <td>The input was invalid and you should terminate your program. </td> </tr> </table> </section> </div> <div class="part"> <section> <h3>Using the Standard Output</h3> <p>When returning your move instruction to the standard output, please use the flush command. As an example, consider the case where you want to output <code>-1</code>. This is how to do it in some of the major programming languages.</p> <h4>C++</h4> <pre class="prettyprint"> std::cout &lt;&lt; "-1" &lt;&lt; std::endl; </pre> <h4>Java</h4> <p><pre class="prettyprint"> System.out.println("-1"); </pre></p> <h4>Python 3.4</h4> <p><pre class="prettyprint"> print("-1", flush=True) </pre></p> </section> </div> <div class="part"> <section> <h3>Sample Code B</h3> <p>A software toolkit for generation of input samples, scoring and testing on a local contestant environment, and sample codes for beginners is provided through the following <a href="https://img.atcoder.jp/hokudai-hitachi2019-1/7742d79123e4cd369848aebec76fbc63.zip">link</a>. In addition we provide <a href="https://img.atcoder.jp/hokudai-hitachi2019-1/d2dded0de70ff38cbb8aa6dbfb88dfc3.zip">software for visualizing</a> the contestants results.</p></section> </div> </span>
p03760
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.</p> <p>You are given two strings <var>O</var> and <var>E</var>. <var>O</var> contains the characters at the odd-numbered positions retaining their relative order, and <var>E</var> contains the characters at the even-numbered positions retaining their relative order. Restore the original password.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>O</var> and <var>E</var> consists of lowercase English letters (<code>a</code> - <code>z</code>).</li> <li><var>1 \leq |O|,|E| \leq 50</var></li> <li><var>|O| - |E|</var> is either <var>0</var> or <var>1</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>O</var> <var>E</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the original password.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>xyz abc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>xaybzc </pre> <p>The original password is <code>xaybzc</code>. Extracting the characters at the odd-numbered positions results in <code>xyz</code>, and extracting the characters at the even-numbered positions results in <code>abc</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>atcoderbeginnercontest atcoderregularcontest </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>aattccooddeerrbreeggiunlnaerrccoonntteesstt </pre></section> </div> </span>
p03330
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with <var>N</var> rows and <var>N</var> columns of squares. Let <var>(i,j)</var> be the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p> <p>These squares have to be painted in one of the <var>C</var> colors from Color <var>1</var> to Color <var>C</var>. Initially, <var>(i,j)</var> is painted in Color <var>c_{i,j}</var>.</p> <p>We say the grid is a <em>good</em> grid when the following condition is met for all <var>i,j,x,y</var> satisfying <var>1 \leq i,j,x,y \leq N</var>:</p> <ul> <li>If <var>(i+j) \% 3=(x+y) \% 3</var>, the color of <var>(i,j)</var> and the color of <var>(x,y)</var> are the same.</li> <li>If <var>(i+j) \% 3 \neq (x+y) \% 3</var>, the color of <var>(i,j)</var> and the color of <var>(x,y)</var> are different.</li> </ul> <p>Here, <var>X \% Y</var> represents <var>X</var> modulo <var>Y</var>.</p> <p>We will repaint zero or more squares so that the grid will be a good grid.</p> <p>For a square, the <em>wrongness</em> when the color of the square is <var>X</var> before repainting and <var>Y</var> after repainting, is <var>D_{X,Y}</var>.</p> <p>Find the minimum possible sum of the wrongness of all the squares.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 500</var></li> <li><var>3 \leq C \leq 30</var></li> <li><var>1 \leq D_{i,j} \leq 1000 (i \neq j),D_{i,j}=0 (i=j)</var></li> <li><var>1 \leq c_{i,j} \leq C</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>C</var> <var>D_{1,1}</var> <var>...</var> <var>D_{1,C}</var> <var>:</var> <var>D_{C,1}</var> <var>...</var> <var>D_{C,C}</var> <var>c_{1,1}</var> <var>...</var> <var>c_{1,N}</var> <var>:</var> <var>c_{N,1}</var> <var>...</var> <var>c_{N,N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the minimum possible sum of the wrongness of all the squares is <var>x</var>, print <var>x</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 0 1 1 1 0 1 1 4 0 1 2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <ul> <li>Repaint <var>(1,1)</var> to Color <var>2</var>. The wrongness of <var>(1,1)</var> becomes <var>D_{1,2}=1</var>.</li> <li>Repaint <var>(1,2)</var> to Color <var>3</var>. The wrongness of <var>(1,2)</var> becomes <var>D_{2,3}=1</var>.</li> <li>Repaint <var>(2,2)</var> to Color <var>1</var>. The wrongness of <var>(2,2)</var> becomes <var>D_{3,1}=1</var>.</li> </ul> <p>In this case, the sum of the wrongness of all the squares is <var>3</var>.</p> <p>Note that <var>D_{i,j} \neq D_{j,i}</var> is possible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 0 12 71 81 0 53 14 92 0 1 1 2 1 2 1 1 2 2 2 1 3 1 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>428 </pre></section> </div> </span>
p02171
<h1>Problem J: Ukunichia Query</h1> <h2>Problem</h2> <p> $N$ 人の人が左から右へ一列に並んでいる。彼らの間では文字列 $S$ が流行している。<br> 各人は、以下の条件を満たすとき<b>幸せ</b>であり、そうでないとき<b>幸せ</b>ではない。<br> <ul> <li>今までに $|S|$ 文字以上の文字を伝えられていて、かつ直近の $|S|$ 文字を古い順から新しい順に並べると $S$ と一致する</li> </ul> </p> <p> 以下の $2$ 種類のクエリを合計 $Q$ 回処理せよ。 </p> <p> クエリ1<br> $1$ $l$ $r$ $c$<br> 区間 $[l, r]$ に含まれる人に文字列 $c$ を左から一文字ずつ伝える。 </p> <p> クエリ2<br> $2$ $l$ $r$ <br> 区間 $[l, r]$ に含まれる<b>幸せ</b>な人の数を求める。 </p> <p> ただし、区間 $[l, r]$ とは、左から $l$ 番目から $r$ 番目までの人のことを表す。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $S$ $N$ $Q$ $query_1$ $\vdots$ $query_Q$ </pre> <p> $1$ 行目に流行している文字列 $S$ が与えられる。<br> $2$ 行目に並んでいる人の数 $N$ とクエリの数 $Q$ が空白区切りで与えられる。<br> $3$ 行目から続く $Q$ 行にクエリの情報が与えられる。<br> </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$1 \leq |S| \leq 20 $</li> <li>$1 \leq N \leq 10^5 $</li> <li>$1 \leq Q \leq 10^5 $</li> <li>$1 \leq l \leq r \leq N$</li> <li>$1 \leq |c| \leq 10 $</li> <li>$S, c$ は英小文字からなる</li> <li>各クエリはクエリ1かクエリ2のいずれかである</li> <li>クエリ2が必ず一つ以上含まれる</li> </ul> <h2>Output</h2> <p> 各クエリ2について、<b>幸せ</b>な人の数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> abab 5 5 2 2 4 1 1 5 abab 2 3 5 1 3 3 a 2 1 5 </pre> <h2>Sample Output 1</h2> <pre> 0 3 4 </pre> <p> </p> <h2>Sample Input 2</h2> <pre> uku 1333 5 2 232 423 1 13 532 uku 2 322 567 1 3 33 ku 2 1 333 </pre> <h2>Sample Output 2</h2> <pre> 0 211 321 </pre> <h2>Sample Input 3</h2> <pre> aabb 1879 20 2 69 1585 1 415 1680 aabb 1 756 1628 abbabbaa 1 849 1273 abba 2 418 1172 2 1063 1164 2 203 623 2 481 1209 1 107 110 ababaaaab 1 857 985 bbbbabbbaa 1 868 947 aaa 1 1619 1789 aabab 2 204 844 2 493 1422 2 821 1499 1 757 1817 abbabbb 2 232 911 1 653 797 aaabaaaab 2 701 1657 1 868 940 aaabbbaaa </pre> <h2>Sample Output 3</h2> <pre> 0 338 0 209 275 341 263 0 341 0 </pre>
p00232
<H1>人生ゲーム</H1> <p> 太郎君は、おもちゃ屋さんに会津ホビー社製の人生ゲームを買いに行きました。人生ゲームは、マス目の書かれたボードとルーレットを使って遊びます。ボードには図のようにスタート地点とゴール地点が一つずつあり、それらはひとつながりのマス目でつながっています。最初に、コマはスタート地点のマスに置かれ、ルーレットを回して出た数によってコマを進めます。マスによっては、そこに止まったり通過したりすることでお金を得たり、コマの位置を変えたりするイベントマスがあります。最終的な勝敗は、コマがゴール地点に到達した時点の所持金の多寡で決まります。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_lifeGame1"><br/> </center> <br/> <p> この会社の人生ゲームの面白いところは、ルーレットの出る目の大きさ、ゴールまでのマスの数、イベントマスの配置がひとつひとつパッケージごとに異なるところです。それらはケースに書かれており、それを読むことで確認することができます。お金を最も得られる人生ゲームを選びたい太郎君は、得るお金の期待値が一番大きいものを買いたがっています。そこであなたは、太郎君のゲーム選びを手伝うことにしました。 </p> <p> ルーレットは、円周を <var>X</var> 等分に区分され、それぞれに <var>V<sub>1</sub></var>、<var>V<sub>2</sub></var>、...、<var>V<sub>X</sub></var> という値が記入されているとします。ボードには、0 番、1 番、...、<var>Y</var> 番と番号がふられたマス目があり、順番につながっています。マス目の中には、イベントマスと呼ばれる特別なマスが <var>Z</var> 個あり、そこに到達すると特別な動作を行います。イベントマスのマス目の番号は <var>N<sub>i</sub></var> で与えられます。イベントマスには 1 ~ 3 の種類 (<var>E<sub>i</sub></var>) があり、それぞれ次の動作が行われます。 </p> <center> <table> <tr> <th width="80"> 種類 (<var>E<sub>i</sub></var>)</th><th width="340"> 特別動作 </th><th width="120"> 値 (<var>A<sub>i</sub></var>) の範囲</th> </tr> <tr> <td> 1 </td><td> 指定の値 <var>A<sub>i</sub></var> だけ先へ進む </td><td> 1~10 </td> </tr> <tr> <td> 2 </td><td> 指定の値 <var>A<sub>i</sub></var> の金額を得る </td><td> 1~100</td> </tr> <tr> <td> 3 </td><td> 指定の値 <var>A<sub>i</sub></var> の金額を支払う </td><td> 1~100</td> </tr> </table> </center> <br/> <p> 最初の所持金は 0 円で、第 0 マス目からスタートし、第 <var>Y</var> マス目に到達するとゴールとなります。ゴールを越えた場合もゴールと見なします。スタートとゴールにイベントは無く、1 マスに複数のイベントが重なることはありません。イベントによって進んだ先のマスのイベントは無視します。所持金が 0 円より少なくなる場合は 0 円とします。 </p> <p> 例えば、ある人生ゲームで得られるお金の期待値は以下のように計算できます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_lifeGame2"><br/> </center> <br/> <p> この例では、スタート、イベントマス(100 円入手) 、ゴールの 3 つのマスと、1 か 2 が出るルーレットからなる人生ゲームが表されています。まず、1 回目にルーレットを回した時、1 が出ればイベントマスに到達し、所持金は 100 円になります。一方、2 が出た場合はゴールに到達し、所持金は 0 円のままです。これらはどちらも 2 分の 1 の確率で起こります。 </p> <p> さらに、1 回目でイベントマスに到達した場合は 2 回目のルーレットを回しますが、どの値が出てもゴールに到達し、所持金はどの場合も 100 円です。 </p> <p> このように、全部で 3 通りのゴールの仕方があります。ゴールした時点の所持金に着目すると、0 円になる場合が 1 通りでその確率は 2 分の 1、100 円になる場合が 2 通りでその確率が 4 分の 1 です。この場合、ゴールでの所持金の期待値は、ゴールの仕方ごとの (所持金 &times; その確率) を足した値であり、この人生ゲームの期待値は 50 円になります。 </p> <p> ルーレットの情報とボードの情報を入力とし、ゴール時の所持金の期待値を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロみっつの行で示されます。各データセットは以下の形式で与えられます。 </p> <pre> <var>X</var> <var>Y</var> <var>Z</var> <var>V<sub>1</sub></var> <var>V<sub>2</sub></var> ... <var>V<sub>X</sub></var> <var>N<sub>1</sub></var> <var>E<sub>1</sub></var> <var>A<sub>1</sub></var> <var>N<sub>2</sub></var> <var>E<sub>2</sub></var> <var>A<sub>2</sub></var> : <var>N<sub>Z</sub></var> <var>E<sub>Z</sub></var> <var>A<sub>Z</sub></var> </pre> <p> <var>X</var> (1 &le; <var>X</var> &le; 4)、<var>V<sub>i</sub></var> (1 &le; <var>V<sub>i</sub></var> &le; 10)、<var>Y</var> (1 &le; <var>Y</var> &le; 50)、<var>N<sub>i</sub></var> (1 &le; <var>N<sub>i</sub></var> &le; <var>Y</var>-1)、<var>Z</var> (0 &le; <var>Z</var> &le; <var>Y</var>-1)、<var>E<sub>i</sub></var> (1 &le; <var>E<sub>i</sub></var> &le; 3)、 <var>A<sub>i</sub></var> (1 &le; <var>A<sub>i</sub></var> &le; 100) は整数で与えられます。 <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> 入力データセットごとに、最終的な所持金の期待値を1行に出力します。なお、所持金の期待値は小数点以下切り捨ての整数で出力してください。 </p> <H2>Sample Input</H2> <pre> 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 100 0 50 20 </pre>
p00662
<H1>Problem D: The Great Summer Contest</H1> <p> 現在、人々の娯楽はプログラミングコンテストに限られている。彼女が所属しているとある中学校の娯楽部の活動内容は、プログラミングコンテストを企画し運営することだ。彼女の仕事は問題を作成することではない。多くの人から問題を募り、審判団を組織し、またコンテストの宣伝を行う、いわば裏方のお仕事だ。カリスマ作題者や著名なアルゴリズマーと違い、そういった仕事をする人に光が当たることはほとんどない。存在感はないけれども欠かすことのできないその仕事に、彼女は誇りを持って取り組んでいた。 </p> <p> 娯楽部は常に問題を募集しているが、それらの問題は以下の 6 種類に分類される。 </p> <ul> <li>Math</li> <li>Greedy</li> <li>Geometry</li> <li>DP</li> <li>Graph</li> <li>Other</li> </ul> <p> 幸いにも多くの問題が集まったので、彼女はたくさんコンテストを開こうと考えた。コンテストは 3 問の問題からなるが、彼女はコンテストがより教育的になるようにと、以下の 4 種類のコンテストを開くことに決めた。 </p> <ol> <li>数学ゲーコンテスト: Math の問題と DP の問題合わせて3問の問題セット</li> <li>アルゴリズムゲーコンテスト: Greedy の問題と Graph の問題合わせて3問の問題セット</li> <li>実装ゲーコンテスト: Geometry の問題と Other の問題合わせて3問の問題セット</li> <li>バランスの良いコンテスト: Math または DP から 1 問、Greedy または Graph から 1 問、Geometry または Other から 1 問、合わせて3問の問題セット</li> </ol> <p> もちろん、あるコンテストに出題した問題は他のコンテストに出題することはできない。彼女の望みは、できるだけ多くのコンテストを開くことだ。6 種類の問題のストック数は分かっているが、さて、最大何回コンテストを開けるだろうか。彼女にとってこれは難しい問題だが、カリスマアルゴリズマーであるあなたなら解決できるはずだ。 </p> <h2>Input</h2> <p> 入力は複数のケースからなる。 各ケースは以下のフォーマットで与えられる。 </p> <pre> <i>n<sub>Math</sub></i> <i>n<sub>Greedy</sub></i> <i>n<sub>Geometry</sub></i> <i>n<sub>DP</sub></i> <i>n<sub>Graph</sub></i> <i>n<sub>Other</sub></i> </pre> <p> 各入力の値はそれぞれの種類の問題のストックの数を表す。 </p> <p> 入力の終わりは </p> <pre>0 0 0 0 0 0</pre> <p> からなる行によって与えられる。 </p> <p> 各値は以下の条件を満たす。<br> <i>n<sub>Math</sub></i> + <i>n<sub>Greedy</sub></i> + <i>n<sub>Geometry</sub></i> + <i>n<sub>DP</sub></i> + <i>n<sub>Graph</sub></i> + <i>n<sub>Other</sub></i> &le; 100,000,000<br> </p> <p> またテストケースの数は20,000個を超えない。 </p> <h2>Output</h2> <p> 開催可能なコンテストの最大数を1行に出力せよ。 </p> <h2>Sample input</h2> <pre> 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 0 1 1 3 0 0 3 0 0 3 1 0 1 3 1 1 2 0 2 0 1 0 0 1 1 0 3 1 0 0 1 1 0 0 0 0 0 0 0 </pre> <H2>Sample output</H2> <pre> 2 1 1 2 3 1 1 0 </pre> <hr> <p> The University of Aizu Programming Contest 2011 Summer<br> 原案: Tomoya Sakai<br> 問題文: Takashi Tayama<br> </p>
p01970
<h2>D: 素因数分解の多様性 (The Diversity of Prime Factorization)</h2> <h3>Problem</h3> <p>Ebi-chan has the FACTORIZATION MACHINE, which can factorize natural numbers M (greater than 1) in <var>O(</var>$\log$<var> M)</var> time! But unfortunately, the machine could display only digits and whitespaces.</p> <p>In general, we consider the factorization of <var>M</var> as <var>p_1^{e_1} \times p_2^{e_2} \times ... \times p_K^{e_K}</var> where (1) <var>i &lt; j</var> implies <var>p_i &lt; p_j</var> and (2) <var>p_i</var> is prime. Now, she gives M to the machine, and the machine displays according to the following rules in ascending order with respect to <var>i</var>:</p> <ul> <li> If <var>e_i = 1</var>, then displays <var>p_i</var>,</li> <li> otherwise, displays <var>p_i</var> <var>e_i</var>.</li> </ul> <p>For example, if she gives either <code>22</code> or <code>2048</code>, then <code>2 11</code> is displayed. If either <code>24</code> or <code>54</code>, then <code>2 3 3</code>.</p> <p>Okay, Ebi-chan has written down the output of the machine, but she notices that she has forgotten to write down the input! Now, your task is to count how many natural numbers result in a noted output. Note that Ebi-chan has mistaken writing and no input could result in the output.</p> <p>The answer could be too large, so, you must output it modulo <var>10^9+7</var> (prime number).</p> <h3>Input</h3> <pre> <var>N</var> <var>q_1</var> <var>q_2</var> $\cdots$ <var>q_N</var> </pre> <p>In the first line, the number of the output of the machine is given. In the second line, the output of the machine is given.</p> <h3>Constraints</h3> <ul> <li> <var>1 \leq N \leq 10^5</var></li> <li> <var>2 \leq q_i \leq 10^6</var> (<var>1 \leq i \leq N</var>)</li> </ul> <h3>Output</h3> <p>Print the number of the natural numbers that result in the given output of the machine.</p> <h3>Sample Input 1</h3> <pre> 3 2 3 3 </pre> <h3>Sample Output for Input 1</h3> <pre>2</pre> <p><var>24 = 2^3 \times 3</var> and <var>54 = 2 \times 3^3</var> satisfy the condition.</p> <h3>Sample Input 2</h3> <pre> 3 2 3 4 </pre> <h3>Sample Output 2 for Input 2</h3> <pre>1</pre> <p>Only <var>162 = 2 \times 3^4</var> satisfies the condition. Note that <var>4</var> is not prime.</p> <h3>Sample Input 3</h3> <pre> 3 3 5 2 </pre> <h3>Sample Output for Input 3</h3> <pre>1</pre> <p>Since <var>2 &lt; 3 &lt; 5</var>, only <var>75 = 3 \times 5^2</var> satisfies the condition.</p> <h3>Sample Input 4</h3> <pre> 1 4 </pre> <h3>Sample Output for Input 4</h3> <pre>0</pre> <p>Ebi-chan should have written down it more carefully.</p>
p00398
<h1>Road Construction</h1> <p> The Zuia Kingdom has finally emerged through annexation of $N$ cities, which are identified by index from $1$ to $N$. You are appointed the Minister of Transport of the newly born kingdom to construct the inter-city road network. </p> <p> To simplify the conceptual design planning, you opted to consider each city as a point on the map, so that the $i$-th city can be represented by an coordinate ($x_i, y_i$). </p> <p> The cost of road construction connecting $u$-th and $v$-th cities is equal to the distance $|x_u - x_v|$ or $|y_u - y_v|$, whichever the larger. The notation $|A|$ represents the absolute value of $A$. The object here is to explore the minimum cost required to construct the road network in such a way that people can move between different cities along one or more roads. </p> <p> Make a program to calculate the minimum of total road construction cost from the number of cities and their coordinates. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $x_1$ $y_1$ $x_2$ $y_2$ ... $x_N$ $y_N$ </pre> <p> The first line provides the number of cities $N$ ($2 \leq N \leq 10^5$). Each of the subsequent $N$ lines provides the coordinate of the $i$-th city $x_i, y_i$ ($0 \leq x_i, y_i \leq 10^9$) as integers. Note that none of these coordinates coincides if: $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$. </p> <h2>Output</h2> <p> Output the minimum road construction cost. </p> <h2>Sample Input 1 </h2> <pre> 3 1 2 3 4 10 1 </pre> <h2>Sample Output 1</h2> <pre> 9 </pre> <p> The road connecting city 1 and 2 can be constructed at the cost of 2, and that connecting city 2 and 3 at the cost of 7. Therefore, the total cost becomes 9, which is the minimum. </p> <h2>Sample Input 2</h2> <pre> 3 1 2 3 4 3 2 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre> <h2>Sample Input 3</h2> <pre> 5 7 41 10 0 99 27 71 87 14 25 </pre> <h2>Sample Output 3</h2> <pre> 163 </pre>
p01423
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Rabbit Party</H1> <p> A rabbit Taro decided to hold a party and invite some friends as guests. He has <var>n</var> rabbit friends, and <var>m</var> pairs of rabbits are also friends with each other. Friendliness of each pair is expressed with a positive integer. If two rabbits are not friends, their friendliness is assumed to be 0. </p> <p> When a rabbit is invited to the party, his satisfaction score is defined as the minimal friendliness with any other guests. The satisfaction of the party itself is defined as the sum of satisfaction score for all the guests. </p> <p> To maximize satisfaction scores for the party, who should Taro invite? Write a program to calculate the maximal possible satisfaction score for the party. </p> <H2>Input</H2> <p> The first line of the input contains two integers, <var>n</var> and <var>m</var> (<var>1 \leq n \leq 100</var>, <var>0 \leq m \leq 100</var>). The rabbits are numbered from <var>1</var> to <var>n</var>. </p> <p> Each of the following <var>m</var> lines has three integers, <var>u</var>, <var>v</var> and <var>f</var>. <var>u</var> and <var>v</var> (<var>1 \leq u, v \leq n</var>, <var>u \neq v</var>, <var>1 \leq f \leq 1,000,000</var>) stands for the rabbits' number, and <var>f</var> stands for their friendliness. </p> <p> You may assume that the friendliness of a pair of rabbits will be given at most once. </p> <H2>Output</H2> <p> Output the maximal possible satisfaction score of the party in a line. </p> <H2>Sample Input 1</H2> <pre> 3 3 1 2 3 2 3 1 3 1 2 </pre> <H2>Output for the Sample Input 1</H2> <pre> 6 </pre> <H2>Sample Input 2</H2> <pre> 2 1 1 2 5 </pre> <H2>Output for the Sample Input 2</H2> <pre> 10 </pre> <H2>Sample Input 3</H2> <pre> 1 0 </pre> <H2>Output for the Sample Input 3</H2> <pre> 0 </pre> <H2>Sample Input 4</H2> <pre> 4 5 1 2 4 1 3 3 2 3 7 2 4 5 3 4 6 </pre> <H2>Output for the Sample Input 4</H2> <pre> 16 </pre>
p01073
<h1>Problem B: Potatoes</h1> <h2>Problem</h2> <p> がっちょ君は<var>N</var>面の畑と<var>M</var>個の芋を所有している。各畑にはそれぞれ1から<var>N</var>までの番号が付けられている。がっちょ君は畑に芋を植え収穫することで、芋の数を増やしたいと考えている。 </p> <p> がっちょ君は一人暮らしであり、1人では<var>K</var>面までの畑しか管理することができない。また、各畑の土の状態や面積は様々で、芋の収穫数や植えることのできる芋の数も様々である。芋を畑<var>i</var>に植えた場合、1年後には畑<var>i</var>に植えた芋1つにつき<var>a<sub>i</sub></var>個の芋を収穫することができる。ただし、畑<var>i</var>には最大でも<var>b<sub>i</sub></var>個の芋しか植えることができない。 </p> <p> がっちょ君が<var>K</var>面以内の畑に<var>M</var>個以内の芋を植えた時、1年後に所有することができる芋の数の最大値を求めてほしい。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> <var>N</var> <var>M</var> <var>K</var> <var>a<sub>1</sub></var>&nbsp;<var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var> <var>b<sub>1</sub></var>&nbsp;<var>b<sub>2</sub></var> ... <var>b<sub>N</sub></var> </pre> <p> 1行目に3個の整数<var>N</var>, <var>M</var>, <var>K</var>が空白区切りで与えられる。<br> 2行目に<var>N</var>個の整数<var>a<sub>i</sub></var>が空白区切りで与えられる。<br> 3行目に<var>N</var>個の整数<var>b<sub>i</sub></var>が空白区切りで与えられる。<br> </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>N</var> &le; 15</li> <li>1 &le; <var>M</var> &le; 10<sup>4</sup></li> <li>1 &le; <var>K</var> &le; min(<var>N</var>,3)</li> <li>1 &le; <var>a<sub>i</sub></var> &le; 10<sup>3</sup></li> <li>1 &le; <var>b<sub>i</sub></var> &le; 10<sup>4</sup></li> </ul> <h2>Output</h2> <p> 芋の数の最大値を1行で出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 5 100 3 2 3 4 5 6 50 40 20 10 5 </pre> <h2>Sample Output 1</h2> <pre> 280 </pre> <p>畑1に40個、畑2に40個、畑3に20個植えることで収穫後に280個の芋を所有することができる。</p> <h2>Sample Input 2</h2> <pre> 5 100 3 2 3 4 5 100 50 40 20 10 1 </pre> <h2>Sample Output 2</h2> <pre> 339 </pre> <p>畑2に40個、畑3に20個、畑5に1個植えることで300個の芋を収穫することができ、植えなかった芋と合わせて答えは339になる。</p>
p01589
<H1><font color="#000">Problem I:</font> Strange Currency System</H1> <p> The currency system in the Kingdom of Yoax-Musty is strange and fairly inefficient. Like other countries, the kingdom has its own currencty unit denoted by K <span>$</span> (kingdom dollar). However, the Ministry of Finance issues bills for every value between 1 K <span>$</span> and (2<sup>31</sup> - 1) K <span>$</span> worth. </p> <p> On the other hand, this system often enables people to make many different values just with a small number of bills. For example, if you have four bills of 1 K <span>$</span>, 2 K <span>$</span>, 4 K <span>$</span>, and 8 K <span>$</span> worth respectively, you can make any values from 1 K #36; to 15 K <span>$</span>. </p> <p> In this problem, you are requested to write a program that finds the minimum value that cannot be made with a given set (multiset in a mathematical sense) of bills. For the case with the four bills (1 K <span>$</span>, 2 K <span>$</span>, 4 K <span>$</span>, and 8 K <span>$</span>), since you can make any values up to 15 K <span>$</span>, your program should report 16 K <span>$</span>. </p> <H2>Input</H2> <p> The input consists of two lines. The first line contains an integer <i>N</i> (1 &le; <i>N</i> &le; 10000), the number of bills. The second line contains <i>N</i> integers, each of which represents the value of a bill in K <span>$</span>. There may be multiple bills of the same value. </p> <H2>Output</H2> <p> Print the minimum value unable to be made on a line. The value should be given in K <span>$</span> and without any currency sign or name. </p> <H2>Sample Input and Output</H2> <H2>Input #1</H2> <pre> 4 1 2 4 8 </pre> <H2>Output #1</H2> <pre> 16 </pre> <br/> <H2>Input #2</H2> <pre> 5 1 1 3 11 2 </pre> <H2>Output #2</H2> <pre> 8 </pre>
p01566
<h1>Pipeline Plans</h1> <p>There are twelve types of tiles in Fig. 1. You were asked to fill a table with <var>R &times; C</var> cells with these tiles. <var>R</var> is the number of rows and <var>C</var> is the number of columns. </p> <p>How many arrangements in the table meet the following constraints? </p><ul><li><p> Each cell has one tile. </p></li><li><p> the center of the upper left cell (1,1) and the center of the lower right cell (<var>C</var>, <var>R</var>) are connected by some roads. </p></li></ul> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_tiles" height="634" width="926"></center></p> <p><center><i>Fig. 1: the types of tiles</i></center></p> </p> <h2>Input</h2> <p>The first line contains two integers <var>R</var> and <var>C</var> <var>(2 &le; R &times; C &le; 15)</var>. You can safely assume at least one of <var>R</var> and <var>C</var> is greater than 1.<br> The second line contains twelve integers, <var>t<sub>1</sub></var>, <var>t<sub>2</sub></var>, ..., <var>t<sub>12</sub></var> <var>(0 &le; t<sub>1</sub> + .... + t<sub>12</sub> &le; 15)</var>. <var>t<sub>i</sub></var> represents the number of the <var>i</var>-th tiles you have. </p> <h2>Output</h2> <p>Output the number of arrangments in a line. </p> <h2>Sample Input 1</h2> <pre>3 3 4 2 2 0 0 0 0 0 0 0 0 1 </pre> <h2>Output for the Sample Input 1</h2> <pre>2 </pre> <h2>Sample Input 2</h2> <pre>3 3 0 1 1 0 0 0 0 0 0 0 0 7 </pre> <h2>Output for the Sample Input 2</h2> <pre>66 </pre> <h2>Sample Input 3</h2> <pre>3 3 0 0 0 0 0 0 0 0 0 0 0 10 </pre> <h2>Output for the Sample Input 3</h2> <pre>1 </pre> <h2>Sample Input 4</h2> <pre>2 4 0 0 1 1 1 2 0 1 0 0 1 1 </pre> <h2>Output for the Sample Input 4</h2> <pre>2012 </pre> <h2>Sample Input 5</h2> <pre>5 2 0 1 1 1 0 1 2 1 2 0 0 1 </pre> <h2>Output for the Sample Input 5</h2> <pre>8512 </pre>
p01136
<h1><font color="#000000">Problem F:</font> Gather the Maps!</h1> <p> はるか昔、八尾氏が残したとされる伝説の秘宝が八王子のどこかに眠っているという。 その在処を示すとされる宝の地図は、いくつかの断片に分割された状態で、八尾氏の <i>n</i> 人の子孫達によって受け継がれている。 </p> <p> 今、八尾氏の子孫達は協力してその秘宝を手に入れようとしていた。 ところが、秘宝の在処を指し示す宝の地図の一部分だけでは秘宝を見つけることができない。 そこで、八尾氏の子孫達は全員で集まって地図を 1 ヶ所に集めようとした。 ところが、いざ実行に移そうとしてもなかなか予定が合わずに集まることができない。 しかしこの秘宝に関する情報は、一族において秘密裏に伝えられてきた貴重な情報である。 漏洩の危険性を考慮すると、公共の通信手段を用いて地図をやりとりすることなど問題外である。 </p> <p> そこで、子孫同士が直接会って地図を手渡すということを繰り返すことで、ある 1 人の子孫のところに地図を集めることにした。 なお、1 人が 1 日に会える人数に制限はないが、互いにスケジュールが空いていることが必要である。 </p> <p> あなたの仕事は、それぞれの子孫に対するスケジュールの空いている日のリストから、地図を集めるには最低で何日必要かを求めるプログラムを書くことである。 </p> <p> ちなみに、八尾氏一族の結束は非常に固い。 最終的に地図全体を手にした子孫が、他の子孫を裏切って秘宝を持ち逃げすれば、一族から制裁を受けることになる。その制裁はきわめて恐ろしいものであるため、実際にその子孫が秘宝を持ち逃げすることは事実上不可能である。 </p> <h2>Input</h2> <p> 入力は複数のデータセットからなる。 </p> <p> それぞれのデータセットは複数の行からなる。 その最初の行には、地図の断片を持った者の人数を表す整数 <i>n</i> (1 &lt; <i>n</i> &lt;= 50) が記述されている。 続く <i>n</i> 行には、それぞれの子孫のスケジュールが書かれている。 <i>i</i> 行目は <i>i</i> 人目の子孫のスケジュールが表しており、いくつかの整数が 1 文字のスペースを区切りとして書かれている。 最初の整数 <i>f<sub>i</sub></i> (0 &lt;= <i>f<sub>i</sub></i> &lt;= 30) は、その子孫のスケジュールが空いている日の日数を表す整数である。 続く <i>f<sub>i</sub></i> 個の整数は、スケジュールが空いている日付を表す。 これらの日付は互いに異なり、全て 1 以上 30 以下である。 </p> <p> 入力の最後に 0 のみを含んだ 1 行がある。 </p> <h2>Output</h2> <p> 各データセットに対して、1 つの整数を 1 行に出力せよ。 もし、30 日以内に地図を集めることができる場合は、地図を集めるのに最低限必要となる日数を、集めることができない場合は -1 を出力せよ。 </p> <p> <b>追記 :</b> 上記の「地図を集めるのに最低限必要となる日数」は 1 日を起点として最も早く全ての地図が集まる日付を意味する. </p> <h2>Sample Input</h2> <pre> 4 1 1 2 2 3 2 1 2 3 3 4 5 0 </pre> <h2>Output for the Sample Input</h2> <pre> 3 </pre>
p00377
<h1>Cake Party</h1> <p>  I’m planning to have a party on my birthday. Many of my friends will come to the party. Some of them will come with one or more pieces of cakes, but it is not certain if the number of the cakes is a multiple of the number of people coming. </p> <p> I wish to enjoy the cakes equally among the partiers. So, I decided to apply the following rules. First, all the party attendants are given the same number of cakes. If some remainder occurs, a piece goes on a priority basis to the party host (that’s me!). How many pieces of cake can I enjoy? </p> <p> Given the number of my friends and cake information, make a program to calculate how many pieces of cake I can enjoy. Note that I am not counted in the number of my friends. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $C$ $p_1$ $p_2$ ... $p_C$ </pre> <p> The first line provides the number of my friends $N$ ($1 \leq N \leq 100$) and the number of those among them who brought one or more pieces of cake with them $C$ ($1 \leq C \leq N$). The second line provides an array of integers $p_i$ ($1 \leq p_i \leq100$), each of which shows the number of cakes of the $i$-th friend of mine who was willing to come up with one or more pieces of cake. </p> <h2>Output</h2> <p> Output the number of cakes I can enjoy. </p> <h2>Sample Input 1</h2> <pre> 5 4 5 5 6 5 </pre> <h2>Sample Output 1</h2> <pre> 4 </pre> <h2>Sample Input 2</h2> <pre> 7 5 8 8 8 8 8 </pre> <h2>Sample Output 2</h2> <pre> 5 </pre> <h2>Sample Input 3</h2> <pre> 100 3 3 3 3 </pre> <h2>Sample Output 3</h2> <pre> 1 </pre>
p00727
<H1><font color="#000">Problem F</font> Secrets in Shadows</h1> <P> Long long ago, there were several identical columns (or cylinders) built vertically in a big open space near Yokohama (Fig. F-1). In the daytime, the shadows of the columns were moving on the ground as the sun moves in the sky. Each column was very tall so that its shadow was very long. The top view of the shadows is shown in Fig. F-2. </p> <P> The directions of the sun that minimizes and maximizes the widths of the shadows of the columns were said to give the important keys to the secrets of ancient treasures. </p> <CENTER><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cyl" border=1><BR><!-- begin ja only -->Fig. F-1: Columns (or cylinders) <!-- end ja only --></CENTER><BR><BR> <CENTER><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_sun4b" border=1><BR><!-- begin ja only -->Gig. F-2: Top view of the columns (Fig. F-1) and their shadows <!-- end ja only --></CENTER><!-- begin ja only --> <p> The width of the shadow of each column is the same as the diameter of the base disk. But the width of the whole shadow (the union of the shadows of all the columns) alters according to the direction of the sun since the shadows of some columns may overlap those of other columns. </p> <p> Fig. F-3 shows the direction of the sun that minimizes the width of the whole shadow for the arrangement of columns in Fig. F-2. </p> <CENTER><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_minarg4" border=1><BR><!-- begin ja only -->Fig. F-3: The direction of the sun for the minimal width of the whole shadow <!-- end ja only --></CENTER><BR><BR><!-- begin ja only --> <P>Fig. F-4 shows the direction of the sun that maximizes the width of the whole shadow. When the whole shadow is separated into several parts (two parts in this case), the width of the whole shadow is defined as the sum of the widths of the parts.</P><!-- end ja only --> <CENTER><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_maxarg4" border=1><BR><!-- begin ja only -->Fig. F-4: The direction of the sun for the maximal width of the whole shadow<!-- end ja only --></CENTER><BR><BR><!-- begin ja only --> <P> A direction of the sun is specified by an angle <i>&theta;</i> defined in Fig. F-5. For example, the east is indicated by <i>&theta;</i> = 0, the south by <i>&theta;</i> = <i>&pi;</i>/2, and the west by <i>&theta;</i> = <i>&pi</i>. You may assume that the sun rises in the east (<i>&theta;</i> = 0) and sets in the west (<i>&theta;</i> = <i>&pi;</i>). </p> <p> Your job is to write a program that, given an arrangement of columns, computes two directions <i>&theta;</i><sub>min</sub> and <i>&theta;</i><sub>max</sub> of the sun that give the minimal width and the maximal width of the whole shadow, respectively. </p> <p> The position of the center of the base disk of each column is specified by its (<i>x</i>, <i>y</i>) coordinates. The <i>x</i>-axis and <i>y</i>-axis are parallel to the line between the east and the west and that between the north and the south, respectively. Their positive directions indicate the east and the north, respectively. </p> <p> You can assume that the big open space is a plane surface. </p> <CENTER><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_dir" border=1><BR><!-- begin ja only -->Fig. F-5: The definition of the angle of the direction of the sun <!-- end ja only --></CENTER><!-- begin ja only --> <p> There may be more than one <i>&theta;</i><sub>min</sub> or <i>&theta;</i><sub>max</sub> for some arrangements in general, but here, you may assume that we only consider the arrangements that have unique <i>&theta;</i><sub>min</sub> and <i>&theta;</i><sub>max</sub> in the range 0 &le; <i>&theta;</i><sub>min</sub> &lt; <i>&pi;</i>, 0 &le; <i>&theta;</i><sub>max</sub> &lt; <i>&pi;</i>. </p> <H2>Input</H2> <p> The input consists of multiple datasets, followed by the last line containing a single zero. </p> <p> Each dataset is formatted as follows. </p> <pre> <i>n</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> ... <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> </pre> <p> <i>n</i> is the number of the columns in the big open space. It is a positive integer no more than 100. </p> <p> <i>x<sub>k</sub></i> and <i>y<sub>k</sub></i> are the values of <i>x</i>-coordinate and <i>y</i>-coordinate of the center of the base disk of the <i>k</i>-th column (<i>k</i>=1, ..., <i>n</i>). They are positive integers no more than 30. They are separated by a space. </p> <p> Note that the radius of the base disk of each column is one unit (the diameter is two units). You may assume that some columns may touch each other but no columns overlap others. </p> <p> For example, a dataset </p> <pre> 3 1 1 3 1 4 3 </pre> <p> corresponds to the arrangement of three columns depicted in Fig. F-6. Two of them touch each other. </p> <CENTER><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ex" border=1><BR><!-- begin ja only -->Fig. F-6: An arrangement of three columns <!-- end ja only --></CENTER> <H2>Output</H2> <p> For each dataset in the input, two lines should be output as specified below. The output lines should not contain extra characters such as spaces. </p> <p> In the first line, the angle <i>&theta;</i><sub>min</sub>, the direction of the sun giving the minimal width, should be printed. In the second line, the other angle <i>&theta;</i><sub>max</sub>, the direction of the sun giving the maximal width, should be printed. </p> <p> Each angle should be contained in the interval between 0 and <i>&pi;</i> (abbreviated to [0, <i>&pi;</i>]) and should not have an error greater than <i>&epsilon;</i>=0.0000000001 (=10<sup>-10</sup>). </p> <p> When the correct angle <i>&theta;</i> is in [0,<i>&epsilon;</i>], approximate values in [0,<i>&theta;</i>+<i>&epsilon;</i>] or in [<i>&pi;</i>+<i>&theta;</i>-<i>&epsilon;</i>, <i>&pi;</i>] are accepted. When the correct angle <i>&theta;</i> is in [<i>&pi;</i>-<i>&epsilon;</i>, <i>&pi</i>], approximate values in [0, <i>&theta;</i>+<i>&epsilon;</i>-<i>&pi;</i>] or in [<i>&theta;</i>-<i>&epsilon;</i>, <i>&pi;</i>] are accepted. </p> <p> You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. </p> <H2>Sample Input</H2> <PRE> 3 1 1 3 1 4 3 4 1 1 2 3 3 8 1 9 8 1 1 3 1 6 1 1 3 5 3 1 7 3 5 5 5 8 20 7 1 27 30 14 9 6 17 13 4 2 17 7 8 9 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> 2.553590050042226 0.982793723247329 1.570796326794896 2.819842099193151 1.325817663668032 2.094395102393196 2.777613697080149 0.588002603547568 </PRE>
p03808
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> boxes arranged in a circle. The <var>i</var>-th box contains <var>A_i</var> stones.</p> <p>Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation:</p> <ul> <li>Select one box. Let the box be the <var>i</var>-th box. Then, for each <var>j</var> from <var>1</var> through <var>N</var>, remove exactly <var>j</var> stones from the <var>(i+j)</var>-th box. Here, the <var>(N+k)</var>-th box is identified with the <var>k</var>-th box.</li> </ul> <p>Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≦ N ≦ 10^5</var></li> <li><var>1 ≦ 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_2</var> … <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to remove all the stones from the boxes, print <code>YES</code>. Otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 5 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>All the stones can be removed in one operation by selecting the second box.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 6 9 12 10 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>YES </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre></section> </div> </span>
p01835
<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>Donut Decoration</h2> <p> Donut maker's morning is early. Mr. D, who is also called Mr. Donuts, is an awesome donut maker. Also today, he goes to his kitchen and prepares to make donuts before sunrise. </p> <p> In a twinkling, Mr. D finishes frying $N$ donuts with a practiced hand. But these donuts as they are must not be displayed in a showcase. Filling cream, dipping in chocolate, topping somehow cute, colorful things, etc., several decoration tasks are needed. There are $K$ tasks numbered 1 through $K$, and each of them must be done exactly once in the order $1, 2, ..., K$ to finish the donuts as items on sale. </p> <p> Instantly, Mr. D arranges the $N$ donuts in a row. He seems to intend to accomplish each decoration tasks sequentially at once. However, what in the world is he doing? Mr. D, who stayed up late at yesterday night, decorates only a part of the donuts in a consecutive interval for each task. It's clearly a mistake! Not only that, he does some tasks zero or several times, and the order of tasks is also disordered. The donuts which are not decorated by correct process cannot be provided as items on sale, so he should trash them. </p> <p> Fortunately, there are data recording a sequence of tasks he did. The data contain the following information: for each task, the consecutive interval $[l, r]$ of the decorated donuts and the ID $x$ of the task. Please write a program enumerating the number of the donuts which can be displayed in a showcase as items on sale for given recorded data. </p> <h3>Input</h3> <p> The input consists of a single test case. The test case is formatted as follows.<br/> <br/> $N$ $K$<br/> $T$<br/> $l_1$ $r_1$ $x_1$<br/> ...<br/> $l_T$ $r_T$ $x_T$<br/> </p> <p> The first line contains two integers $N$ and $K$, where $N$ ($1 \leq N \leq 200,000$) is the number of the donuts fried by Mr. D, and $K$ ($1 \leq K \leq 200,000$) is the number of decoration tasks should be applied to the donuts. The second line contains a single integer $T$ ($1 \leq T \leq 200,000$), which means the number of information about tasks Mr. D did. Each of next $T$ lines contains three integers $l_i$, $r_i$, and $x_i$ representing the $i$-th task Mr. D did: the $i$-th task was applied to the interval $[l_i, r_i]$ ($1 \leq l_i \leq r_i \leq N$) of the donuts inclusive, and has ID $x_i$ ($1 \leq x_i \leq K$). </p> <h3>Output</h3> <p> Output the number of the donuts that can be provided as items on sale. </p> <h3>Sample Input 1</h3> <pre> 3 2 3 1 2 1 2 3 2 3 3 1 </pre> <h3>Output for the Sample Input 1</h3> <pre> 1 </pre> <h3>Sample Input 2</h3> <pre> 5 3 6 2 3 1 1 3 2 4 5 1 2 4 3 3 5 2 5 5 3 </pre> <h3>Output for the Sample Input 2</h3> <pre> 2 </pre> <h3>Sample Input 3</h3> <pre> 10 1 2 2 9 1 5 7 1 </pre> <h3>Output for the Sample Input 3</h3> <pre> 5 </pre>
p03222
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Amidakuji is a traditional method of lottery in Japan.</p> <p>To make an amidakuji, we first draw <var>W</var> parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is <var>H+1</var> [cm], and the endpoints of the horizontal lines must be at <var>1, 2, 3, ...,</var> or <var>H</var> [cm] from the top of a vertical line.</p> <p>A <em>valid amidakuji</em> is an amidakuji that satisfies the following conditions:</p> <ul> <li>No two horizontal lines share an endpoint.</li> <li>The two endpoints of each horizontal lines must be at the same height.</li> <li>A horizontal line must connect adjacent vertical lines.</li> </ul> <p><img alt="" src="https://img.atcoder.jp/ghi/6b3e1470b9c551e0b7cfdcd802f300b3.png"/></p> <p>Find the number of the valid amidakuji that satisfy the following condition, modulo <var>1\ 000\ 000\ 007</var>: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the <var>K</var>-th vertical line from the left.</p> <p>For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.</p> <p><img alt="" src="https://img.atcoder.jp/ghi/d40ccbb88ee2ac60a6239c11b16ceb40.png"/></p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>H</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</li> <li><var>W</var> is an integer between <var>1</var> and <var>8</var> (inclusive).</li> <li><var>K</var> is an integer between <var>1</var> and <var>W</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the amidakuji that satisfy the condition, modulo <var>1\ 000\ 000\ 007</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Only the following one amidakuji satisfies the condition:</p> <p><img alt="" src="https://img.atcoder.jp/ghi/c68c6daccfc4cba8bc94af5f1a80ef2f.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>Only the following two amidakuji satisfy the condition:</p> <p><img alt="" src="https://img.atcoder.jp/ghi/4be150946de8bef9b14d9bc17814d963.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p>Only the following one amidakuji satisfies the condition:</p> <p><img alt="" src="https://img.atcoder.jp/ghi/9b2e9f49832458c3488b1e04afd51ed4.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 </pre> <p>Only the following five amidakuji satisfy the condition:</p> <p><img alt="" src="https://img.atcoder.jp/ghi/bf6ec766f8923ac2f082f538a6c736b6.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>7 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>1 </pre> <p>As there is only one vertical line, we cannot draw any horizontal lines. Thus, there is only one amidakuji that satisfies the condition: the amidakuji with no horizontal lines.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>15 8 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>437760187 </pre> <p>Be sure to print the answer modulo <var>1\ 000\ 000\ 007</var>.</p></section> </div> </span>
p03388
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>10^{10^{10}}</var> participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through <var>10^{10^{10}}</var>-th.</p> <p>The <em>score</em> of a participant is the product of his/her ranks in the two contests.</p> <p>Process the following <var>Q</var> queries:</p> <ul> <li>In the <var>i</var>-th query, you are given two positive integers <var>A_i</var> and <var>B_i</var>. Assuming that Takahashi was ranked <var>A_i</var>-th in the first contest and <var>B_i</var>-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq Q \leq 100</var></li> <li><var>1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>Q</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>A_Q</var> <var>B_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 12 4 11 14 57 31 671644785 </pre> <p>Let us denote a participant who was ranked <var>x</var>-th in the first contest and <var>y</var>-th in the second contest as <var>(x,y)</var>.</p> <p>In the first query, <var>(2,1)</var> is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print <var>1</var>.</p></section> </div> </span>
p02960
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var>. Each character in <var>S</var> is either a digit (<code>0</code>, ..., <code>9</code>) or <code>?</code>.</p> <p>Among the integers obtained by replacing each occurrence of <code>?</code> with a digit, how many have a remainder of <var>5</var> when divided by <var>13</var>? An integer may begin with <var>0</var>.</p> <p>Since the answer can be enormous, print the count modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>S</var> is a string consisting of digits (<code>0</code>, ..., <code>9</code>) and <code>?</code>.</li> <li><var>1 \leq |S| \leq 10^5</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of integers satisfying the condition, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>??2??5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>768 </pre> <p>For example, <var>482305, 002865,</var> and <var>972665</var> satisfy the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>?44 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>Only <var>044</var> satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7?4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>We may not be able to produce an integer satisfying the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76??? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>153716888 </pre></section> </div> </span>
p03672
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will call a string that can be obtained by concatenating two equal strings an <em>even</em> string. For example, <code>xyzxyz</code> and <code>aaaaaa</code> are even, while <code>ababab</code> and <code>xyzxy</code> are not.</p> <p>You are given an even string <var>S</var> consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of <var>S</var>. It is guaranteed that such a non-empty string exists for a given input.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq |S| \leq 200</var></li> <li><var>S</var> is an even string consisting of lowercase English letters.</li> <li>There exists a non-empty even string that can be obtained by deleting one or more characters from the end of <var>S</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the length of the longest even string that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>abaababaab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <ul> <li><code>abaababaab</code> itself is even, but we need to delete at least one character.</li> <li><code>abaababaa</code> is not even.</li> <li><code>abaababa</code> is not even.</li> <li><code>abaabab</code> is not even.</li> <li><code>abaaba</code> is even. Thus, we should print its length, <var>6</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>xxxx </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <ul> <li><code>xxx</code> is not even.</li> <li><code>xx</code> is even.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>abcabcabcabc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6 </pre> <p>The longest even string that can be obtained is <code>abcabc</code>, whose length is <var>6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>akasakaakasakasakaakas </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>14 </pre> <p>The longest even string that can be obtained is <code>akasakaakasaka</code>, whose length is <var>14</var>.</p></section> </div> </span>
p02433
<h1>List</h1> <p> For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor. </p> <ul> <li>insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element.</li> <li>move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative.</li> <li>erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END. </li> </ul> <p> In the initial state, $L$ is empty and the cursor points END. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $q$ $query_1$ $query_2$ : $query_q$ </pre> <p> Each query $query_i$ is given by </p> <pre> 0 $x$ </pre> <p>or</p> <pre> 1 $d$ </pre> <p>or</p> <pre> 2 </pre> <p> where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent insert, move and erase operations respectively. </p> <h2>Output</h2> <p> Print all elements of the list in order after performing given operations. Print an element in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq q \leq 500,000$</li> <li>The cursor indicates an element of $L$ or END during the operations</li> <li>Erase operation will not given when the cursor points END</li> <li>$-1,000,000,000 \leq x \leq 1,000,000,000$</li> <li>Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000</li> <li>$L$ is not empty after performing all operations</li> </ul> <h2>Sample Input 1</h2> <pre> 5 0 1 0 2 0 3 1 1 2 </pre> <h2>Sample Output 1</h2> <pre> 3 1 </pre>
p02599
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> colored balls arranged in a row from left to right; the color of the <var>i</var>-th ball from the left is <var>c_i</var>.</p> <p>You are given <var>Q</var> queries. The <var>i</var>-th query is as follows: how many different colors do the <var>l_i</var>-th through <var>r_i</var>-th balls from the left have?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1\leq N,Q \leq 5 \times 10^5</var></li> <li><var>1\leq c_i \leq N</var></li> <li><var>1\leq l_i \leq r_i \leq N</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>c_1</var> <var>c_2</var> <var>\cdots</var> <var>c_N</var> <var>l_1</var> <var>r_1</var> <var>l_2</var> <var>r_2</var> <var>:</var> <var>l_Q</var> <var>r_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the response to the <var>i</var>-th query.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 2 1 3 1 3 2 4 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 3 1 </pre> <ul> <li>The <var>1</var>-st, <var>2</var>-nd, and <var>3</var>-rd balls from the left have the colors <var>1</var>, <var>2</var>, and <var>1</var> - two different colors.</li> <li>The <var>2</var>-st, <var>3</var>-rd, and <var>4</var>-th balls from the left have the colors <var>2</var>, <var>1</var>, and <var>3</var> - three different colors.</li> <li>The <var>3</var>-rd ball from the left has the color <var>1</var> - just one color.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 10 2 5 6 5 2 1 7 9 7 2 5 5 2 4 6 7 2 2 7 8 7 9 1 8 6 9 8 10 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 2 1 2 2 6 3 3 3 </pre></section> </div> </span>
p02063
<h2>D: 貪欲が最適?</h2> <h3>物語</h3> <p><var>1</var>, <var>5</var>, <var>10</var>, <var>50</var>, <var>100</var>, <var>500</var> 円玉がある日本では、ある金額を支払う時、大きい金額の硬貨をできるだけ多く使うという方法で支払うと、硬貨の枚数を最小化できることが知られている。</p> <p>硬貨の金額が日本とは異なる場合、貪欲に支払うと必ずしも最小化できるとは限らない。</p> <p>貪欲に支払うのが最適になるために、硬貨の金額が満たすべき条件は何なのだろうか。</p> <h3>問題</h3> <p>TAB 君は上のことが気になったので、まずは硬貨が <var>1</var>, <var>A</var>, <var>B</var> の <var>3</var> 種類しかない場合について考えることにした。</p> <p><var>A</var>, <var>B</var> が与えられるので、貪欲に支払った場合枚数が最小にならないような金額のうち、最小のものを出力せよ。</p> <p>また、どんな金額でも貪欲法が最適な場合は、<var>-1</var> を出力せよ。</p> <h3>入力形式</h3> <pre><var>A</var> <var>B</var></pre> <h3>制約</h3> <ul> <li><var>1 &lt; A \leq 10^5</var></li> <li><var>A &lt; B \leq 10^9</var></li> </ul> <h3>入力例 1</h3> <pre>4 6</pre> <h3>出力例 1</h3> <pre>8</pre> <p><var>8</var> 円を貪欲に支払うと、 <var>6 + 1 \times 2</var> で支払うことになり、合計 <var>3</var> 枚必要だが、<var>4 \times 2</var> で合計 <var>2</var> 枚で支払うことができる。</p> <h3>入力例 2</h3> <pre>2 1000000000</pre> <h3>出力例 2</h3> <pre>-1</pre> <p>どんな金額であっても貪欲に支払うのが最適である。</p>
p02576
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi loves takoyaki - a ball-shaped snack.</p> <p>With a takoyaki machine, he can make at most <var>X</var> pieces of takoyaki at a time, taking <var>T</var> minutes regardless of the number of pieces to make.</p> <p>How long does it take to make <var>N</var> takoyaki?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,X,T \leq 1000</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>X</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the minimum number of minutes needed to make <var>N</var> pieces of takoyaki.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>20 12 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>He can make <var>12</var> pieces of takoyaki in the first <var>6</var> minutes and <var>8</var> more in the next <var>6</var> minutes, so he can make <var>20</var> in a total of <var>12</var> minutes.</p> <p>Note that being able to make <var>12</var> in <var>6</var> minutes does not mean he can make <var>2</var> in <var>1</var> minute.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000 1 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000 </pre> <p>It seems to take a long time to make this kind of takoyaki.</p></section> </div> </span>
p02126
<h1>Problem C: Ball</h1> <h2>Problem</h2> <p> $N$個のボールがあり、各ボールには色と価値が決められている。<br> ボールの色は$1$から$C$まで$C$種類存在し、各色ごとに選べるボールの数の上限が決められている。<br> ボールを全体で高々$M$個選ぶとき、得られる価値の合計を最大化せよ。<br> </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $N$ $M$ $C$ $l_1$ $l_2$ ... $l_C$ $c_1$ $w_1$ $c_2$ $w_2$ ... $c_N$ $w_N$ </pre> <p> 入力はすべて整数で与えられる。<br> 1行目に$N$, $M$, $C$が空白区切りで与えられる。<br> 2行目に色$i$の選べるボールの数の上限$l_i$($1 \leq i \leq C$)が空白区切りで与えられる。<br> 3行目以降の$N$行にボール$i$の色$c_i$と価値$w_i$($1 \leq i \leq N$)が空白区切りで与えられる。<br> </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$1 \leq M \leq N \leq 10^5 $</li> <li>$1 \leq C \leq 10^5 $</li> <li>$0 \leq l_i \leq N $</li> <li>$1 \leq c_i \leq C $</li> <li>$1 \leq w_i \leq 1000 $</li> </ul> <h2>Output</h2> <p> 得られる価値の最大値を1行に出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 3 3 2 1 1 1 1 1 100 2 10 </pre> <h2>Sample Output 1</h2> <pre> 110 </pre> 2番目と3番目のボールを選ぶのが最適である。 <h2>Sample Input 2</h2> <pre> 3 3 3 1 0 1 1 1 2 100 3 1 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> ある色のボールが一個も選べない場合もある。 <h2>Sample Input 3</h2> <pre> 22 7 26 11 14 15 3 11 7 16 17 1 4 2 19 4 14 16 16 3 13 17 12 7 11 2 20 12 22 6 10 1 3 13 1 16 5 4 1 20 7 18 4 26 6 9 1 12 2 21 1 21 7 18 1 14 5 24 5 6 1 3 1 2 5 21 2 7 6 10 9 15 7 </pre> <h2>Sample Output 3</h2> <pre> 52 </pre>
p03367
<span class="lang-en"> <p>Score : <var>1700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has an integer sequence <var>A</var> whose length is <var>N</var>. He likes permutations of <var>(1, 2, ..., N)</var>, <var>P</var>, that satisfy the following condition:</p> <ul> <li><var>P_i \leq A_i</var> for all <var>i</var> ( <var>1 \leq i \leq N</var> ).</li> </ul> <p>Snuke is interested in the inversion numbers of such permutations. Find the sum of the inversion numbers over all permutations that satisfy the condition. Since this can be extremely large, compute the sum modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>The <em>inversion number</em> of a sequence <var>Z</var> whose length <var>N</var> is the number of pairs of integers <var>i</var> and <var>j</var> ( <var>1 \leq i &lt; j \leq N</var> ) such that <var>Z_i &gt; Z_j</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq A_i \leq N</var> ( <var>1 \leq i \leq N</var> )</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the inversion numbers over all permutations that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four permutations that satisfy the condition: <var>(1,2,3)</var>, <var>(1,3,2)</var>, <var>(2,1,3)</var> and <var>(2,3,1)</var>. The inversion numbers of these permutations are <var>0</var>, <var>1</var>, <var>1</var> and <var>2</var>, respectively, for a total of <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 4 2 5 1 6 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> <p>Only one permutation <var>(4,2,5,1,6,3)</var> satisfies the condition. The inversion number of this permutation is <var>7</var>, so the answer is <var>7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 4 4 4 4 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>No permutation satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>30 22 30 15 20 10 29 11 29 28 11 26 10 18 28 22 5 29 16 24 24 27 10 21 30 29 19 28 27 18 23 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>848414012 </pre></section> </div> </span>
p02825
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let us consider a grid of squares with <var>N</var> rows and <var>N</var> columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.</p> <p>For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.</p> <p>Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \le N \le 1000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the required domino placement doesn't exist, print a single integer <code>-1</code>.</p> <p>Otherwise, output your placement as <var>N</var> strings of <var>N</var> characters each. If a square is not covered, the corresponding character must be <code>.</code> (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>aabb.. b..zz. ba.... .a..aa ..a..b ..a..b </pre> <p>The quality of every row and every column is 2.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre></section> </div> </span>
p00818
<H1><font color="#000">Problem H:</font> Viva Confetti</H1> <p> Do you know <i>confetti</i>? They are small discs of colored paper, and people throw them around during parties or festivals. Since people throw lots of confetti, they may end up stacked one on another, so there may be hidden ones underneath.</p> <p> A handful of various sized confetti have been dropped on a table. Given their positions and sizes, can you tell us how many of them you can see? </p> <p> The following figure represents the disc configuration for the first sample input, where the bottom disc is still visible. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_viva"> </center> <H2>Input</H2> <p> The input is composed of a number of configurations of the following form. </p> <pre> <i>n</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>z</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>z</i><sub>2</sub> . . . <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>z</i><sub><i>n</i></sub> </pre> <p> The first line in a configuration is the number of discs in the configuration (a positive integer not more than 100), followed by one Ine descriptions of each disc: coordinates of its center and radius, expressed as real numbers in decimal notation, with up to 12 digits after the decimal point. The imprecision margin is &plusmn;5 &times 10<sup>-13</sup>. That is, it is guaranteed that variations of less than &plusmn;5 &times; 10<sup>-13</sup> on input values do not change which discs are visible. Coordinates of all points contained in discs are between -10 and 10. </p> <p> Confetti are listed in their stacking order, <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>r</i><sub>1</sub> being the bottom one and <i>x<sub>n</sub> y<sub>n</sub> r<sub>n</sub></i> the top one. You are observing from the top. </p> <p> The end of the input is marked by a zero on a single line. </p> <H2>Output</H2> <p> For each configuration you should output the number of visible confetti on a single line. </p> <H2>Sample Input</H2> <pre> 3 0 0 0.5 -0.9 0 1.00000000001 0.9 0 1.00000000001 5 0 1 0.5 1 1 1.00000000001 0 2 1.00000000001 -1 1 1.00000000001 0 -0.00001 1.00000000001 5 0 1 0.5 1 1 1.00000000001 0 2 1.00000000001 -1 1 1.00000000001 0 0 1.00000000001 2 0 0 1.0000001 0 0 1 2 0 0 1 0.00000001 0 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 5 4 2 2 </pre>
p03737
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given three words <var>s_1</var>, <var>s_2</var> and <var>s_3</var>, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>s_1</var>, <var>s_2</var> and <var>s_3</var> are composed of lowercase English letters.</li> <li><var>1 ≤ |s_i| ≤ 10 (1≤i≤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>s_1</var> <var>s_2</var> <var>s_3</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>atcoder beginner contest </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>ABC </pre> <p>The initial letters of <code>atcoder</code>, <code>beginner</code> and <code>contest</code> are <code>a</code>, <code>b</code> and <code>c</code>. Uppercase and concatenate them to obtain <code>ABC</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>resident register number </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>RRN </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>k nearest neighbor </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>KNN </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>async layered coding </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>ALC </pre></section> </div> </span>