question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01190
<H1><font color="#000"></font>Reading Brackets in English</H1> <!-- Problem B--> <p> Shun and his professor are studying Lisp and S-expressions. Shun is in Tokyo in order to make a presen- tation of their research. His professor cannot go with him because of another work today. </p> <p> He was making final checks for his slides an hour ago. Then, unfortunately, he found some serious mistakes! He called his professor immediately since he did not have enough data in his hand to fix the mistakes. </p> <p> Their discussion is still going on now. The discussion looks proceeding with difficulty. Most of their data are written in S-expressions, so they have to exchange S-expressions via telephone. </p> <p> Your task is to write a program that outputs S-expressions represented by a given English phrase. </p> <H2>Input</H2> <p> The first line of the input contains a single positive integer <i>N</i>, which represents the number of test cases. Then <i>N</i> test cases follow. </p> <p> Each case consists of a line. The line contains an English phrase that represents an S-expression. The length of the phrase is up to 1000 characters. </p> <p> The rules to translate an S-expression are as follows. </p> <ol> <li> An S-expression which has one element is translated into “a list of &lt;<i>the element of the S-expression</i>&gt;”. (e.g. “(A)” will be “a list of A”)</li> <li> An S-expression which has two elements is translated into “a list of &lt;<i>the first element of the S-expression</i>&gt; and &lt;<i>the second element of the S-expression</i>&gt;”. (e.g. “(A B)” will be “a list of A and B”)</li> <li> An S-expression which has more than three elements is translated into “a list of &lt;<i>the first element of the S-expression</i>&gt;, &lt;<i>the second element of the S-expression</i>&gt;, . . . and &lt;<i>the last element of the S-expression</i>&gt;”. (e.g. “(A B C D)” will be “a list of A, B, C and D”)</li> <li> The above rules are applied recursively. (e.g. “(A (P Q) B (X Y Z) C)” will be “a list of A, a list of P and Q, B, a list of X, Y and Z and C”)</li> </ol> <p> Each atomic element of an S-expression is a string made of less than 10 capital letters. All words (“a”, “list”, “of” and “and”) and atomic elements of S-expressions are separated by a single space character, but no space character is inserted before comma (”,”). No phrases for empty S-expressions occur in the input. You can assume that all test cases can be translated into S-expressions, but the possible expressions may not be unique. </p> <H2>Output</H2> <p> For each test case, output the corresponding S-expression in a separate line. If the given phrase involves two or more different S-expressions, output “AMBIGUOUS” (without quotes). </p> <p> A single space character should be inserted between the elements of the S-expression, while no space character should be inserted after open brackets (“(”) and before closing brackets (“)”). </p> <H2>Sample Input</H2> <pre> 4 a list of A, B, C and D a list of A, a list of P and Q, B, a list of X, Y and Z and C a list of A a list of a list of A and B </pre> <H2>Output for the Sample Input</H2> <pre> (A B C D) (A (P Q) B (X Y Z) C) (A) AMBIGUOUS </pre>
p02616
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are <var>N</var> integers <var>A_1,\ldots,A_N</var>.</p> <p>We will choose exactly <var>K</var> of these elements. Find the maximum possible product of the chosen elements.</p> <p>Then, print the maximum product modulo <var>(10^9+7)</var>, using an integer between <var>0</var> and <var>10^9+6</var> (inclusive).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq N \leq 2\times 10^5</var></li> <li><var>|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>K</var> <var>A_1</var> <var>\ldots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum product modulo <var>(10^9+7)</var>, using an integer between <var>0</var> and <var>10^9+6</var> (inclusive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 1 2 -3 -4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>The possible products of the two chosen elements are <var>2</var>, <var>-3</var>, <var>-4</var>, <var>-6</var>, <var>-8</var>, and <var>12</var>, so the maximum product is <var>12</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 -1 -2 -3 -4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000001 </pre> <p>The possible products of the three chosen elements are <var>-24</var>, <var>-12</var>, <var>-8</var>, and <var>-6</var>, so the maximum product is <var>-6</var>.</p> <p>We print this value modulo <var>(10^9+7)</var>, that is, <var>1000000001</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 -1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000 </pre> <p>The possible products of the one chosen element are <var>-1</var> and <var>1000000000</var>, so the maximum product is <var>1000000000</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 10 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>999983200 </pre> <p>Be sure to print the product modulo <var>(10^9+7)</var>.</p></section> </div> </span>
p03904
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of digits between <code>1</code> and <code>9</code>, inclusive. You will insert at most <var>K</var> commas (<code>,</code>) into this string to separate it into multiple numbers.</p> <p>Your task is to minimize the maximum number among those produced by inserting commas. Find minimum possible such value.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≩ K &lt; |S| ≩ 100,000</var></li> <li><var>S</var> consists of digits between <code>1</code> and <code>9</code>, inclusive.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li>In the test set worth <var>100</var> points, <var>|S| ≩ 2</var>.</li> <li>In the test set worth another <var>100</var> points, <var>|S| ≩ 16</var>.</li> <li>In the test set worth another <var>200</var> points, <var>|S| ≩ 100</var>.</li> <li>In the test set worth another <var>200</var> points, <var>|S| ≩ 2,000</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>K</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible value.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 15267315 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>315 </pre> <p>When the string is separated into <var>152</var>, <var>67</var> and <var>315</var>, the maximum among these is <var>315</var>, which is the minimum possible value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 12456174517653111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>12456174517653111 </pre> <p><var>12456174517653111</var> itself is the answer.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 127356176351764127645176543176531763517635176531278461856198765816581726586715987216581 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5317635176 </pre></section> </div> </span>
p01939
<h2>B えびちゃんず数列 - Ebi-chan and Integer Sequences -</h2> <h3>問題</h3> <p> えびちゃんは数列が奜きです。䞭でも等差数列が特に奜きです。 今回は以䞋の条件を満たす数列を䜜るこずにしたした。 </p> <ul> <li> 長さ <var>n</var> の等差数列である</li> <li> 数列の <var>i</var> 番目の芁玠を <var>s_i</var> ず定める時、党おの <var>s_i (1 \leq i \leq n)</var> が <var>0 \leq s_i \leq m</var> を満たす敎数である</li> </ul> <p> 䞊の条件を満たすような数列はいく぀あるでしょうか ただし答えは非垞に倧きくなるこずがあるので、 <var>10^9 + 7</var> で割った䜙りを出力しおください。 </p> <h3>入力圢匏</h3> <p>入力は䞀行で䞎えられる。</p> <pre><var>n</var> <var>m</var></pre> <p><var>n</var> は数列の長さを衚す。</p> <h3>制玄</h3> <ul> <li> <var>1 \leq n \leq 10^{15}</var></li> <li> <var>0 \leq m \leq 10^{15}</var></li> </ul> <h3>出力圢匏</h3> <p>条件を満たす等差数列の数を <var>10^9 + 7</var> で割った䜙りを䞀行に出力せよ。</p> <h3>入力䟋1</h3> <pre>3 9</pre> <h3>出力䟋1</h3> <pre>50</pre> <h3>入力䟋2</h3> <pre>10000000000 10000000000</pre> <h3>出力䟋2</h3> <pre>999999942</pre> <p>入力は32bit敎数には収たりきらないこずに泚意しおください。</p>
p02246
<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>15 Puzzle</H1> <p> The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space. </p> <p> In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 15 as shown below. </p> <pre> 1 2 3 4 6 7 8 0 5 10 11 12 9 13 14 15 </pre> <p> You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps). </p> <pre> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 </pre> <p> Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle. </p> <H2>Input</H2> <p> The $4 \times 4$ integers denoting the pieces or space are given. </p> <H2>Output</H2> <p> Print the fewest steps in a line. </p> <H2>Constraints</H2> <ul> <li>The given puzzle is solvable in at most 45 steps.</li> </ul> <H2>Sample Input</H2> <pre> 1 2 3 4 6 7 8 0 5 10 11 12 9 13 14 15 </pre> <H2>Sample Output</H2> <pre> 8 </pre>
p00781
<H1><font color="#000">Problem B:</font> Lattice Practices</H1> <p> Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4 &times; 4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice1"> </center> <p> The cocoon bed can be divided into 10 rectangular boards, each of which has 5 slits: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice2"> </center> <p> Note that, except for the slit depth, there is no difference between the left side and the right side of the board (or, between the front and the back); thus, we cannot distinguish a symmetric board from its rotated image as is shown in the following: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice3"> </center> <p> Slits have two kinds of depth, either shallow or deep. The cocoon bed should be constructed by fitting five of the boards vertically and the others horizontally, matching a shallow slit with a deep slit. </p> <p> Your job is to write a program that calculates the number of possible configurations to make the lattice. You may assume that there is no pair of identical boards. Notice that we are interested in the number of essentially different configurations and therefore you should not count mirror image configurations and rotated configurations separately as different configurations. </p> <p> The following is an example of mirror image and rotated configurations, showing vertical and horizontal boards separately, where shallow and deep slits are denoted by '1' and '0' respectively. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice4"> </center> <p> Notice that a rotation may exchange position of a vertical board and a horizontal board. </p> <H2>Input</H2> <p> The input consists of multiple data sets, each in a line. A data set gives the patterns of slits of 10 boards used to construct the lattice. The format of a data set is as follows: </p> <pre> XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX </pre> <p> Each x is either '0' or '1'. '0' means a deep slit, and '1' a shallow slit. A block of five slit descriptions corresponds to a board. There are 10 blocks of slit descriptions in a line. Two adjacent blocks are separated by a space. </p> <p> For example, the first data set in the Sample Input means the set of the following 10 boards: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice5"> </center> <p> The end of the input is indicated by a line consisting solely of three characters "END". </p> <H2>Output</H2> <p> For each data set, the number of possible configurations to make the lattice from the given 10 boards should be output, each in a separate line. </p> <H2>Sample Input</H2> <pre> 10000 01000 00100 11000 01100 11111 01110 11100 10110 11110 10101 01000 00000 11001 01100 11101 01110 11100 10110 11010 END </pre> <H2>Output for the Sample Input</H2> <pre> 40 6 </pre>
p01893
<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>C: 倱われしグラフ / Lost Graph</h1> <h2>問題文</h2> <p> あなたず AOR むカちゃんは競技プログラミングのグラフ問題の準備をしおいる。 入力ケヌスの生成は AOR むカちゃんの仕事である。 その問題の入力ケヌスは $N$ 頂点の有向グラフである。 頂点には $1$ から $N$ たでの番号が付いおいる。 蟺には自己ルヌプが含たれるかもしれないが、倚重蟺は含たれない。 </p> <p> ずころが、AOR むカちゃんは突然音信䞍通ずなっおしたい、元のグラフが手に入らなくなっおしたった。残っおいるのは次の情報だけである。 </p> <ul> <li> 入次数が $i$ の頂点の数は $a_i$ 個である。぀たり、 $i$ を終点ずする頂点の数は $a_i$ 個である。 </li> <li> 出次数が $i$ の頂点の数は $b_i$ 個である。぀たり、 $i$ を始点ずする頂点の数は $b_i$ 個である。 </li> </ul> <p> 残された情報ず矛盟しない有向グラフは存圚するだろうか。 それを刀定し、存圚するなら YES ず出力した埌矛盟しない有向グラフを 1 ぀出力せよ。 耇数ある堎合はどれを出力しおもよい。存圚しないなら NO ず出力せよ。 </p> <h2>入力</h2> <p> $n$<br> $a_0 \cdots a_n$<br> $b_0 \cdots b_n$<br> </p> <h2>入力の制玄</h2> <p> $1 \leq n \leq 50$<br> $0 \leq a_i \leq n$<br> $0 \leq b_i \leq n$<br> </p> <h2>出力</h2> <p> 条件を満たすグラフが存圚する堎合は以䞋の圢匏で出力せよ。$e_{ij}$ は、 $i$ から $j$ ぞの有向蟺が存圚するならば 1 、しないなら 0 ずせよ。 行末に空癜を出力しないように泚意せよ。 </p> <p> YES<br> $e_{11} \ e_{12} \cdots e_{1n}$<br> $e_{21} \ e_{22} \cdots e_{2n}$<br> $\vdots$<br> $e_{n1} \ e_{n2} \cdots e_{nn}$<br> </p> <p> しない堎合は以䞋のずおりに出力せよ。 </p> <p> NO </p> <h2>サンプル</h2> <h3>サンプル入力1</h3> <pre> 3 1 2 0 0 1 2 0 0 </pre> <h3>サンプル出力1</h3> <pre> YES 0 1 0 0 0 1 0 0 0 </pre> <h3>サンプル入力2</h3> <pre> 1 1 0 1 0 </pre> <h3>サンプル出力2</h3> <pre> YES 0 </pre> <h3>サンプル入力3</h3> <pre> 2 0 2 0 0 2 0 </pre> <h3>サンプル出力3</h3> <pre> YES 0 1 1 0 </pre> <h3>サンプル入力4</h3> <pre> 4 1 3 0 0 0 3 0 0 1 0 </pre> <h3>サンプル出力4</h3> <pre> YES 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 </pre> <h3>サンプル入力5</h3> <pre> 1 1 1 0 0 </pre> <h3>サンプル出力5</h3> <pre> NO </pre>
p00851
<H1><font color="#000">Problem G:</font> Polygons on the Grid</H1> <p> The ultimate Tantra is said to have been kept in the most distinguished temple deep in the sacred forest somewhere in Japan. Paleographers finally identified its location, surprisingly a small temple in Hiyoshi, after years of eager research. The temple has an underground secret room built with huge stones. This underground megalith is suspected to be where the Tantra is enshrined. </p> <p> The room door is, however, securely locked. Legends tell that the key of the door lock was an integer, that only highest priests knew. As the sect that built the temple decayed down, it is impossible to know the integer now, and the Agency for Cultural Affairs bans breaking up the door. Fortunately, a figure of a number of rods that might be used as a clue to guess that secret number is engraved on the door. </p> <p> Many distinguished scholars have challenged the riddle, but no one could have ever succeeded in solving it, until recently a brilliant young computer scientist finally deciphered the puzzle. Lengths of the rods are multiples of a certain unit length. He found that, to find the secret number, all the rods should be placed on a grid of the unit length to make one convex polygon. Both ends of each rod must be set on grid points. Elementary mathematics tells that the polygon's area ought to be an integer multiple of the square of the unit length. The area size of the polygon with the largest area is the secret number which is needed to unlock the door. </p> <p> For example, if you have five rods whose lengths are 1, 2, 5, 5, and 5, respectively, you can make essentially only three kinds of polygons, shown in Figure 7. Then, you know that the maximum area is 19. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_polygonsGrid"> <p> Figure 7: Convex polygons consisting of five rods of lengths 1, 2, 5, 5, and 5 </p> </center> <p> Your task is to write a program to find the maximum area of convex polygons using all the given rods whose ends are on grid points. </p> <H2>Input</H2> <p> The input consists of multiple datasets, followed by a line containing a single zero which indicates the end of the input. The format of a dataset is as follows. </p> <pre> <i>n</i> <i>r</i><sub>1</sub> <i>r</i><sub>2</sub> ... <i>r<sub>n</sub></i> </pre> <p> <i>n</i> is an integer which means the number of rods and satisfies 3 &le; <i>n</i> &le; 6. <i>r<sub>i</sub></i> means the length of the <i>i</i>-th rod and satisfies 1 &le; <i>r<sub>i</sub></i> &le; 300. </p> <H2>Output</H2> <p> For each dataset, output a line containing an integer which is the area of the largest convex polygon. When there are no possible convex polygons for a dataset, output "<span>-1</span>". </p> <H2>Sample Input</H2> <pre> 3 3 4 5 5 1 2 5 5 5 6 195 221 255 260 265 290 6 130 145 169 185 195 265 3 1 1 2 6 3 3 3 3 3 3 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 19 158253 -1 -1 18 </pre>
p01743
<p> <var>m</var> 頂点の完党グラフがある最初完党グラフの蟺には色は塗られおいないすぬけ君は各 <var>i</var>(1 &le; <var>i</var> &le; <var>n</var>) に぀いお次の操䜜を行った: 完党グラフから <var>a<sub>i</sub></var> 個の頂点を遞び遞ばれた頂点同士を結ぶ蟺すべおを色 <var>i</var> でぬる耇数個の色が塗られた蟺はなかった<var>m</var> ずしお考えられる最小倀を求めよ </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>n</var> &le; 5</li> <li> 2 &le; <var>a<sub>i</sub></var> &le; 10<sup>9</sup></li> </ul> <h2>Input</h2> <pre> <var>n</var> <var>a<sub>1</sub></var> . . . <var>a<sub>n</sub></var> </pre> <h2>Output</h2> <p> <var>m</var> の最小倀を䞀行に出力せよ </p> <h2>Sample Input 1</h2> <pre> 2 3 3 </pre> <h2>Sample Output 1</h2> <pre> 5 </pre> <p> たずえば頂点1, 2, 3, 4, 5 からなるグラフがあった堎合次のように色を塗るこずができる </p> <ul> <li> 頂点1, 2, 3 を遞びその間を結ぶ蟺を色1 でぬる</li> <li> 頂点1, 4, 5 を遞びその間を結ぶ蟺を色2 でぬる</li> </ul> <h2>Sample Input 2</h2> <pre> 5 2 3 4 5 6 </pre> <h2>Sample Output 2</h2> <pre> 12 </pre>
p03284
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has decided to distribute <var>N</var> AtCoder Crackers to <var>K</var> users of as evenly as possible. When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,K \leq 100</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>The crackers can be distributed evenly.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01313
<h1><font color="#000">Problem K:</font> Cat Numbers!</h1> <p> ねこのアリストテレスは数孊の問題を考えるのを趣味にしおいる。今圌が考えおいる問題は以䞋のようなものである。 </p> <p> 1以䞊の自然数 <var>A</var>, <var>B</var> (<var>A</var> &lt; <var>B</var>) に察しお、<var>A</var> から <var>B</var> たでの自然数の和を <var>C</var>、<var>A</var> ず <var>B</var> を十進衚蚘しお <var>A</var>, <var>B</var> の順に結合したものを <var>D</var> ずするず、䞡者が等しくなるこずがある。たずえば1から5たでの和は15、2から7たでの和は27、7から119たでの和は 7119、ずいった具合である。このような <var>A</var> ず <var>B</var> のペアのこずを cat numbers ず呌ぶこずにする。アリストテレスは、<var>A</var> ず <var>B</var> の桁数が䞎えられたずきに、cat numbersを党お列挙したい、ず考えた。 </p> <p> アリストテレスは、<var>A</var> たたは <var>B</var> を固定した堎合に解が存圚するかどうかを確かめる方法は思い぀いたので、小さい桁数に察しおは答えを埗るこずができた。しかし、桁数が倧きくなるにしたがっお蚈算をするのが倧倉になり、途䞭でうんざりしお投げ出しおしたった。そこで、あなたにお願いがある。アリストテレスに代わっお、指定された桁数のcat numbersを党お列挙するプログラムを曞いおほしい。 </p> <h2>Input</h2> <p> 入力は1行のみからなる。<var>A</var> の桁数 <var>a</var> および <var>B</var> の桁数 <var>b</var> が1぀の空癜文字で区切られお䞎えられる。これらは 1 &le; <var>a</var> &le; <var>b</var> &le; 16 を満たす。 </p> <h2>Output</h2> <p> 指定された桁数のcat numbersを、<var>A</var> が小さいものから順に出力せよ。<var>A</var> が同じものが耇数ある堎合は、<var>B</var> が小さいものから出力せよ。各行には1぀のcat numbersにおける <var>A</var> ず <var>B</var> を1぀の空癜文字で区切ったものを出力せよ。たた、条件に合うcat numbersが存圚しない堎合は "No cats." ず1行に出力せよ。 <h2>Notes on Submission</h2> <p> 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 </p> <h2>Sample Input</h2> <pre> 4 1 1 1 3 1 4 2 2 </pre> <h2>Output for the Sample Input</h2> <pre> 1 5 2 7 7 119 No cats. 13 53 18 63 33 88 35 91 </pre>
p00152
<H1>ボりリング</H1> <p> クラスのレクリ゚ヌションずしおボりリングを行うこずになりたした。参加者ごずの投球情報を入力ずし、埗点の高い順に成瞟情報を出力するプログラムを䜜成しおください。なお、同点の堎合は孊籍番号の若い順に出力しおください。ただし参加者は 3 名以䞊 40 名以䞋ずし、1人圓たり1ゲヌムず぀投球しおいるものずしたす。 </p> <p> ボりリングずは、プレむダヌに察しお頂点を向けお正䞉角圢に䞊べられた、10 本のピンをめがけおボヌルを転がし、ピンを倒すスポヌツです。 1 回目の投球ですべお転倒した堎合をストラむクず蚀い、その投球のみで次のフレヌムに進みたす。ストラむクでない堎合は、残ったピンをそのたたにしお 2 回目の投球を行いたす。2 回目の投球ですべお転倒した堎合をスペアず蚀いたす。2 回目の投球終了埌、次のフレヌムに進みたす。 </p> <p> 1 ゲヌムは 10 のフレヌムから構成され、第 1 から第 9 の各フレヌムは 2 回投球できたす。各フレヌムの開始時点では、10 本のピンがすべお立った状態で甚意されたす。第 10 フレヌムは、ストラむクもしくはスペアが出た堎合には蚈 3 回の投球を、それ以倖の堎合は 2 回の投球を行い、ゲヌム終了ずなりたす。 </p> <center> スコア䟋<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bowling1"> <br><br> スコア䟋最高埗点300点の堎合<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bowling2"><br> </center> <br/> <p>スコア蚈算の方法</p> <ul> <li> 各フレヌムにおいおスペア、ストラむクがない堎合は、 2 回の投球で倒したピンの本数がそのフレヌムの埗点ずなりたす。スコア䟋の第 4 フレヌムず第 8 フレヌム</li> <li>スペアを出した堎合、倒した本数である 10 点に加え、次の投球で倒したピンの本数がこのフレヌムの埗点に加算されたす。スコア䟋の第 1 フレヌムず第 2 フレヌムの関係などスコア䟋の第 1 フレヌムでは第 2 フレヌムの 1 投で倒した 10 本点を加えた 20 点が埗点ずなりたす。第 3 フレヌムも同様の蚈算方法です。</li> <li>ストラむクを出した堎合、倒した本数である 10 点に加え、続く 2 回の投球で倒したピンの本数が加算されたす。スコア䟋の第 2 フレヌムず第 3 フレヌムの関係などもちろん続く 2 投䞭にストラむクの堎合がありたす。スコア䟋の第 5 フレヌムず第 6、7 フレヌムの関係など</li> <li>第 10 フレヌムのみ、スペア、ストラむクを出した堎合、3 投しお倒したピンの総数が第 10 フレヌムの埗点ずしお加算されたす。</li> <li>各フレヌムの埗点の合蚈が 1 ゲヌムの埗点ずなり、最高埗点は 300 点ずなりたす。</li> </ul> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。</p> <pre> <var>m</var> <var>score<sub>1</sub></var> <var>score<sub>2</sub></var> : <var>score<sub>m</sub></var> </pre> <p> 1行目に参加者数 <var>m</var> 3 &le; <var>m</var> &le; 40、続く<var>m</var> 行に<var>i</var> 人目の参加者情報 <var>score<sub>i</sub></var> が䞎えられたす。各参加者情報は行ず぀次の圢匏で䞎えられたす。 </p> <pre> <var>id</var> <var>s<sub>1</sub></var> <var>s<sub>2</sub></var> ... <var>s<sub>n</sub></var> </pre> <p> 先頭に孊籍番号<var>id</var> (0 &le; <var>id</var> &le; 9999)、続いお第 <var>j</var> 投の転倒ピン数 <var>s<sub>j</sub></var> (0 &le; <var>s<sub>j</sub></var> &le; 10) が䞎えられたす。総投球数 <var>n</var> は、12 以䞊 21 以䞋であり、埗点蚈算に必芁なピン数が過䞍足なく䞎えられるものずしたす。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、孊籍番号ず埗点を、埗点の高い順同点の堎合は孊籍番号の若い順に出力したす。孊籍番号ず埗点を぀の空癜で区切っお行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 3 1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0 1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9 1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10 3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1 3335 10 10 10 10 10 10 10 10 10 10 10 10 3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1200 127 1010 123 1101 60 3335 300 3321 200 3340 175 3332 122 </pre>
p00502
<H1>暑い日々 (Hot days) </H1> <br/> <h2> 問題</h2> <p> 日本が冬であるこの時期南半球にあるオヌストラリアでは暑い日が続いおいるオヌストラリアに䜏む IOI 君はある D 日間の倩気予報をもずに着る服の蚈画を立おるこずにしたi 日目 (1 ≩ i ≩ D) の最高気枩は T<sub>i</sub> 床であるず予報されおいる </p> <p> IOI 君は N 皮類の服を持っおおりそれらには 1 から N たでの番号が぀いおいる服 j (1 ≩ j ≩ N) は最高気枩が A<sub>j</sub> 床以䞊 B<sub>j</sub> 床以䞋の日に着るのに適しおいるたたそれぞれの服には「掟手さ」ずよばれる敎数が定たっおおり服 j の掟手さは C<sub>j</sub> である </p> <p> D 日間のそれぞれに察しIOI 君は最高気枩が倩気予報に埓ったずきに着るのに適した服のうち 1 ぀を着る服ずしお遞ぶ同じ服を䜕床遞んでもよいしD 日間で䞀床も遞ばれない服があっおもよい </p> <p> 䌌おいる服を連続しお着るこずをなるべく避けようず思った IOI 君は連続する日に着る服の掟手さの差の絶察倀の合蚈をできるだけ倧きくしようず考えたすなわちi 日目に服 x<sub>i</sub> を遞んだずしお倀 |C<sub>x<sub>1</sub></sub> - C<sub>x<sub>2</sub></sub>| + |C<sub>x<sub>2</sub></sub> - C<sub>x<sub>3</sub></sub>| + 
 + |C<sub>x<sub>D-1</sub></sub> - C<sub>x<sub>D</sub></sub>| を最倧にしたいこの最倧倀を求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は 1 + D + N 行からなる </p> <p> 1 行目には2 ぀の敎数 D, N (2 ≩ D ≩ 2001 ≩ N ≩ 200) が空癜を区切りずしお曞かれおいるD は服の蚈画を立おる日数N は IOI 君が持っおいる服の皮類の数を衚す </p> <p> 続く D 行のうちの i 行目 (1 ≩ i ≩ D) には1 ぀の敎数 T<sub>i</sub> (0 ≩ T<sub>i</sub> ≩ 60) が曞かれおいるこれはi 日目の最高気枩が T<sub>i</sub> 床であるず予報されおいるこずを衚す </p> <p> 続く N 行のうちの j 行目 (1 ≩ j ≩ N) には3 ぀の敎数 A<sub>j</sub>, B<sub>j</sub>, C<sub>j</sub> (0 ≩ A<sub>j</sub> ≩ B<sub>j</sub> ≩ 600 ≩ C<sub>j</sub> ≩ 100) が曞かれおいるこれらは服 j は最高気枩が A<sub>j</sub> 床以䞊 B<sub>j</sub> 床以䞋の日に着るのに適しおおり掟手さが C<sub>j</sub> であるこずを衚す </p> <p> 最高気枩が倩気予報に埓ったずきに着るのに適した服がD 日間のどの日に察しおも 1 ぀以䞊存圚するこずが保蚌されおいる </p> <h2> 出力</h2> <p> 連続する日に着る服の掟手さの差の絶察倀の合蚈すなわち倀 |C<sub>x<sub>1</sub></sub> - C<sub>x<sub>2</sub></sub>| + |C<sub>x<sub>2</sub></sub> - C<sub>x<sub>3</sub></sub>| + 
 + |C<sub>x<sub>D-1</sub></sub> - C<sub>x<sub>D</sub></sub>| の最倧倀を 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 3 4 31 27 35 20 25 30 23 29 90 21 35 60 28 33 40 </pre> <h3>出力䟋 1</h3> <pre> 80 </pre> <p> 入出力䟋 1 においお1 日目の服の候補は服 3 ず服 4 であり2 日目の服の候補は服 2 ず服 3 であり3 日目の服の候補は服 3 のみである1 日目に服 4 を2 日目に服 2 を3 日目に服 3 を遞ぶすなわちx<sub>1</sub> = 4x<sub>2</sub> = 2x<sub>3</sub> = 3 ずするこのずき1 日目ず 2 日目の服の掟手さの差の絶察倀は |40 - 90| = 50 であり2 日目ず 3 日目の服の掟手さの差の絶察倀は |90 - 60| = 30 である合蚈は 80 ずなりこれが最倧倀である </p> <h3>入力䟋 2</h3> <pre> 5 2 26 28 32 29 34 30 35 0 25 30 100 </pre> <h3>出力䟋 2</h3> <pre> 300 </pre> <p> 入出力䟋 2 においお1 日目には服 2 を2 日目には服 2 を3 日目には服 1 を4 日目には服 2 を5 日目には服 1 を遞ばなければならないこのずき求める倀は |100 - 100| + |100 - 0| + |0 - 100| + |100 - 0| = 300 ずなる </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00017
<H1>Caesar Cipher</H1> <p> In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would become 'c', 'y' would become 'z', 'z' would become 'a', and so on. In that case, a text: <pre> this is a pen </pre> <p> is would become: </p> <pre> uijt jt b qfo </pre> <p> Write a program which reads a text encrypted by Caesar Chipher and prints the corresponding decoded text. The number of shift is secret and it depends on datasets, but you can assume that the decoded text includes any of the following words: "the", "this", or "that". </p> <H2>Input</H2> <p> Input consists of several datasets. Each dataset consists of texts in a line. Input ends with EOF. The text consists of lower-case letters, periods, space, and end-of-lines. Only the letters have been encrypted. A line consists of at most 80 characters. </p> <p> You may assume that you can create one decoded text which includes any of "the", "this", or "that" from the given input text. </p> <p> The number of datasets is less than or equal to 20. </p> <H2>Output</H2> <p> Print decoded texts in a line. </p> <H2>Sample Input</H2> <pre> xlmw mw xli tmgxyvi xlex m xsso mr xli xvmt. </pre> <H2>Output for the Sample Input</H2> <pre> this is the picture that i took in the trip. </pre>
p02180
<h1>F: 友達探し</h1> <h2>問題</h2> <p> $1$ から $N$ たでの番号が付けられた $N$ 人の人に察しおある郚屋の入退宀蚘録が $M$ 個䞎えられる <br> $i$ 番目の入退宀蚘録は $A_i\ B_i\ C_i$ の $3$ ぀の敎数からなりこれは以䞋を瀺しおいる<br> <ul> <li>$C_i = 1$ のずき時刻 $A_i$ に $B_i$ さんが郚屋に入宀したこずを衚す.</li> <li>$C_i = 0$ のずき時刻 $A_i$ に $B_i$ さんが郚屋から退宀したこずを衚す.</li> </ul> </p> <p> $i$ 番目($1 \leq i \leq N$)の人に぀いお時刻 $T$ たでに郚屋で䞀緒に過ごした時間が最も長い人を答えよ </p> <h2>制玄</h2> <ul> <li>入力倀は党お敎数である.</li> <li>$2 \leq N,\ M \leq 10^5$</li> <li>$1 \leq T \leq 10^9$</li> <li>$1 \leq A_i \leq T$</li> <li>$A_i \leq A_{i+1}$</li> <li>$1 \leq B_i \leq N$</li> <li>$(A_i = A_j$ か぀ $B_i = B_j$) ならば $i=j$</li> <li>$0 \leq C_i \leq 1$</li> <li>時刻 $0$ には郚屋に誰もいない</li> <li>入退宀が矛盟する入力は䞎えられない</li> <li><b>郚屋に $100$ 人より倚くの人がいるこずはない</b></li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる. </p> <p> $N\ M\ T$<br> $A_1\ B_1\ C_1$<br> 
<br> $A_M\ B_M\ C_M$<br> </p> <h2>出力</h2> <p> $i$ 行目には $i$ 番目の人に぀いお時刻 $T$ たでに郚屋で䞀緒に過ごした時間が最も長い人を出力する<br> ただし自分以倖で䞀緒に過ごした時間が最も長い人が耇数人いる堎合は最も小さい番号の人を出力せよ<br> たた各行の末尟に改行を出力せよ </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 3 6 10 1 1 1 2 2 1 4 3 1 5 1 0 6 2 0 6 3 0 </pre> <h3>サンプル出力 1</h3> <pre> 2 1 2 </pre> <h3>サンプル入力 2</h3> <pre> 3 2 5 1 1 1 2 2 1 </pre> <h3>サンプル出力 2</h3> <pre> 2 1 1 </pre> <p> $3$ 番目の人は$1$ 番目の人ずも $2$ 番目の人ずも䞀緒にいた時間が $0$ なので最も小さい $1$ を出力する. </p>
p00447
<H1>星座探し </H1> <h2>問題</h2> <p> あなたは星空の写真の䞭から星座を探しおいる写真には必ず探したい星座ず同じ圢・向き・倧きさの図圢がちょうど䞀぀含たれおいるただし写真の䞭には星座を構成する星以倖に䜙分な星が写っおいる可胜性がある </p> <p> 䟋えば図 1 の星座は図 2 の写真に含たれおいる䞞で囲んで瀺した䞎えられた星座の星の座暙を x 方向に 2 y 方向に −3 だけ平行移動するず写真の䞭の䜍眮になる </p> <p> 探したい星座の圢ず写真に写っおいる星の䜍眮が䞎えられたずき星座の座暙を写真の䞭の座暙に倉換するために平行移動するべき量を答えるプログラムを曞け </p> <table style="margin-left: 30px; margin-right: 30px; text-align: center;"> <col><col> <tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_constellation1" width="270" height="270"></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_constellation2" width="270" height="270"></td></tr> <tr><td>図 1: 探したい星座</td><td>図 2: 星空の写真</td></tr> </table> <br> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 入力の 1 行目には探したい星座を構成する星の個数 <i>m</i> が曞かれおいる続く <i>m</i> 行には探したい星座を構成する <i>m</i> 個の星の x 座暙ず y 座暙を瀺す敎数が空癜区切りで曞かれおいる <i>m</i>+2 行目には写真に写っおいる星の個数 <i>n</i> が曞かれおいる続く <i>n</i> 行には写真に写っおいる <i>n</i> 個の星の x 座暙ず y 座暙を瀺す敎数が空癜区切りで曞かれおいる </p> <p> 星座を構成する <i>m</i> 個の星の䜍眮はすべお異なるたた写真に写っおいる <i>n</i> 個の星の䜍眮はすべお異なる 1 &le; <i>m</i> &le; 200 1 &le; <i>n</i> &le; 1000 である星の x 座暙ず y 座暙はすべお 0 以䞊 1000000 以䞋である </p> <p> <i>m</i> が 0 のずき入力の終わりを瀺す. デヌタセットの数は 5 を超えない </p> <h2>出力</h2> <p> <!--提出する出力ファむル-->各デヌタセットの出力は 1 行からなり 2 個の敎数を空癜区切りで曞くこれらは探したい星座の座暙をどれだけ平行移動すれば写真の䞭の座暙になるかを衚す最初の敎数が x 方向に平行移動する量次の敎数が y 方向に平行移動する量である </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 </pre> <h3>出力䟋</h3> <pre> 2 -3 -384281 179674 </pre> <p> 入出力䟋の぀目は䞊の図に察応しおいる </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02929
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>2N</var> squares arranged from left to right. You are given a string of length <var>2N</var> representing the color of each of the squares.</p> <p>The color of the <var>i</var>-th square from the left is black if the <var>i</var>-th character of <var>S</var> is <code>B</code>, and white if that character is <code>W</code>.</p> <p>You will perform the following operation exactly <var>N</var> times: choose two distinct squares, then invert the colors of these squares and the squares between them. Here, to invert the color of a square is to make it white if it is black, and vice versa. </p> <p>Throughout this process, you cannot choose the same square twice or more. That is, each square has to be chosen exactly once.</p> <p>Find the number of ways to make all the squares white at the end of the process, modulo <var>10^9+7</var>.</p> <p>Two ways to make the squares white are considered different if and only if there exists <var>i</var> <var>(1 \leq i \leq N)</var> such that the pair of the squares chosen in the <var>i</var>-th operation is different.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>|S| = 2N</var></li> <li>Each character of <var>S</var> is <code>B</code> or <code>W</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to make all the squares white at the end of the process, modulo <var>10^9+7</var>. If there are no such ways, print <var>0</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 BWWB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four ways to make all the squares white, as follows:</p> <ul> <li>Choose Squares <var>1, 3</var> in the first operation, and choose Squares <var>2, 4</var> in the second operation.</li> <li>Choose Squares <var>2, 4</var> in the first operation, and choose Squares <var>1, 3</var> in the second operation.</li> <li>Choose Squares <var>1, 4</var> in the first operation, and choose Squares <var>2, 3</var> in the second operation.</li> <li>Choose Squares <var>2, 3</var> in the first operation, and choose Squares <var>1, 4</var> in the second operation.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 BWBBWWWB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>288 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 WWWWWWWWWW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p00914
<H1><font color="#000">Problem A: </font>Equal Sum Sets</H1> <p> Let us consider sets of positive integers less than or equal to <var>n</var>. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. </p> <p> Specifying the number of set elements and their sum to be <var>k</var> and <var>s</var>, respectively, sets satisfying the conditions are limited. When <var>n</var> = 9, <var>k</var> = 3 and <var>s</var> = 23, {6, 8, 9} is the only such set. There may be more than one such set, in general, however. When <var>n</var> = 9, <var>k</var> = 3 and <var>s</var> = 22, both {5, 8, 9} and {6, 7, 9} are possible. </p> <p> You have to write a program that calculates the number of the sets that satisfy the given conditions. </p> <H2>Input</H2> <p> The input consists of multiple datasets. The number of datasets does not exceed 100. </p> <p> Each of the datasets has three integers <var>n</var>, <var>k</var> and <var>s</var> in one line, separated by a space. You may assume 1 &le; <var>n</var> &le; 20, 1 &le; <var>k</var> &le; 10 and 1 &le; <var>s</var> &le; 155. </p> <p> The end of the input is indicated by a line containing three zeros. </p> <H2>Output</H2> <p> The output for each dataset should be a line containing a single integer that gives the number of the sets that satisfy the conditions. No other characters should appear in the output. </p> <p> You can assume that the number of sets does not exceed 2<sup>31</sup> - 1. </p> <H2>Sample Input</H2> <pre> 9 3 23 9 3 22 10 3 28 16 10 107 20 8 102 20 10 105 20 10 155 3 4 3 4 2 11 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 0 20 1542 5448 1 0 0 </pre>
p01606
<h2>Sliding GCD</h2> <h2>Problem Statement</h2> <p>自然数の集合 <var>S</var> に察しお集合 <var>\{ GCD(T) | T ⊆ S, T は空でない \}</var> の芁玠数を <var>f(S)</var> ずおく</p> <p>ここで<var>GCD(T)</var> は <var>T</var> に含たれるすべおの数を割り切るような最倧の敎数である<br /> 特に<var>T</var> が䞀぀の敎数 <var>a</var> のみからなるずきは <var>GCD(\{a\}) = a</var> であるこずに泚意せよ</p> <p><var>i = 1, 2, . . ., N - W+1</var> に察しお <var>f(\{i, i+1, . . ., i+W - 1\})</var> を求めよ</p> <h2>Input</h2> <p>入力は以䞋の圢匏に埓う䞎えられる数は党お敎数である</p> <pre><var>N</var> <var>W</var></pre> <h2>Constraints</h2> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1 ≩ W ≩ N ≩ 10^5</var></li></ul> <h2>Output</h2> <p><var>i = 1, 2, . . ., N-W+1</var> のずきの <var>f(\{i, i+1, . . ., i+W-1\})</var> の倀を半角スペヌス区切りで 1 行に出力せよ</p> <h2>Sample Input 1</h2> <pre>10 2</pre> <h2>Output for the Sample Input 1</h2> <pre>2 3 3 3 3 3 3 3 3</pre> <p><var>GCD(\{1\}) = 1, GCD(\{2\}) = 2, GCD(\{1,2\}) = 1</var> ずなるから <var>f(\{1,2\}) = 2</var> である</p> <h2>Sample Input 2</h2> <pre>30 7</pre> <h2>Output for the Sample Input 2</h2> <pre>7 8 9 10 10 11 11 11 11 12 11 12 10 12 12 11 10 12 12 12 10 11 11 13</pre>
p02883
<span class="lang-en"> <p>Score: <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Takahashi will take part in an eating contest. Teams of <var>N</var> members will compete in this contest, and Takahashi's team consists of <var>N</var> players numbered <var>1</var> through <var>N</var> from youngest to oldest. The <em>consumption coefficient</em> of Member <var>i</var> is <var>A_i</var>.</p> <p>In the contest, <var>N</var> foods numbered <var>1</var> through <var>N</var> will be presented, and the <em>difficulty</em> of Food <var>i</var> is <var>F_i</var>. The details of the contest are as follows:</p> <ul> <li>A team should assign one member to each food, and should not assign the same member to multiple foods.</li> <li>It will take <var>x \times y</var> seconds for a member to finish the food, where <var>x</var> is the consumption coefficient of the member and <var>y</var> is the difficulty of the dish.</li> <li>The score of a team is the longest time it takes for an individual member to finish the food.</li> </ul> <p>Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by <var>1</var>, as long as it does not go below <var>0</var>. However, for financial reasons, the <var>N</var> members can do at most <var>K</var> sets of training in total.</p> <p>What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?</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 2 \times 10^5</var></li> <li><var>0 \leq K \leq 10^{18}</var></li> <li><var>1 \leq A_i \leq 10^6\ (1 \leq i \leq N)</var></li> <li><var>1 \leq F_i \leq 10^6\ (1 \leq i \leq N)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> <var>F_1</var> <var>F_2</var> <var>...</var> <var>F_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the minimum possible score of the team.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 4 2 1 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>They can achieve the score of <var>2</var>, as follows:</p> <ul> <li>Member <var>1</var> does <var>4</var> sets of training and eats Food <var>2</var> in <var>(4-4) \times 3 = 0</var> seconds.</li> <li>Member <var>2</var> does <var>1</var> set of training and eats Food <var>3</var> in <var>(2-1) \times 1 = 1</var> second.</li> <li>Member <var>3</var> does <var>0</var> sets of training and eats Food <var>1</var> in <var>(1-0) \times 2 = 2</var> seconds.</li> </ul> <p>They cannot achieve a score of less than <var>2</var>, so the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 8 4 2 1 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>They can choose not to do exactly <var>K</var> sets of training.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>12 </pre></section> </div> </span>
p03791
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are developing frog-shaped robots, and decided to race them against each other.</p> <p>First, you placed <var>N</var> robots onto a number line. These robots are numbered <var>1</var> through <var>N</var>. The current coordinate of robot <var>i</var> is <var>x_i</var>. Here, all <var>x_i</var> are integers, and <var>0 &lt; x_1 &lt; x_2 &lt; ... &lt; x_N</var>.</p> <p>You will repeatedly perform the following operation:</p> <ul> <li>Select a robot on the number line. Let the coordinate of the robot be <var>x</var>. Select the destination coordinate, either <var>x-1</var> or <var>x-2</var>, that is not occupied by another robot. The robot now jumps to the selected coordinate.</li> </ul> <p>When the coordinate of a robot becomes <var>0</var> or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race.</p> <p>Depending on your choice in the operation, the <var>N</var> robots can finish the race in different orders. In how many different orders can the <var>N</var> robots finish the race? Find the answer modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 10^5</var></li> <li><var>x_i</var> is an integer.</li> <li><var>0 &lt; x_1 &lt; x_2 &lt; ... &lt; x_N ≀ 10^9</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li>In a test set worth <var>500</var> points, <var>N ≀ 8</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>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different orders in which the <var>N</var> robots can finish the race, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four different orders in which the three robots can finish the race:</p> <ul> <li><var>(</var>Robot <var>1 →</var> Robot <var>2 →</var> Robot <var>3)</var></li> <li><var>(</var>Robot <var>1 →</var> Robot <var>3 →</var> Robot <var>2)</var></li> <li><var>(</var>Robot <var>2 →</var> Robot <var>1 →</var> Robot <var>3)</var></li> <li><var>(</var>Robot <var>2 →</var> Robot <var>3 →</var> Robot <var>1)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> <p>There are six different orders in which the three robots can finish the race:</p> <ul> <li><var>(</var>Robot <var>1 →</var> Robot <var>2 →</var> Robot <var>3)</var></li> <li><var>(</var>Robot <var>1 →</var> Robot <var>3 →</var> Robot <var>2)</var></li> <li><var>(</var>Robot <var>2 →</var> Robot <var>1 →</var> Robot <var>3)</var></li> <li><var>(</var>Robot <var>2 →</var> Robot <var>3 →</var> Robot <var>1)</var></li> <li><var>(</var>Robot <var>3 →</var> Robot <var>1 →</var> Robot <var>2)</var></li> <li><var>(</var>Robot <var>3 →</var> Robot <var>2 →</var> Robot <var>1)</var></li> </ul> <p>For example, the order <var>(</var>Robot <var>3 →</var> Robot <var>2 →</var> Robot <var>1)</var> can be achieved as shown in the figure below:</p> <div style="text-align: center;"> <img alt="a55aed48a00614569d4844f39807e2fb.png" src="https://atcoder.jp/img/mujin/a55aed48a00614569d4844f39807e2fb.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 1 2 3 5 7 11 13 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>10080 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>13 4 6 8 9 10 12 14 15 16 18 20 21 22 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>311014372 </pre> <p>Remember to print the answer modulo <var>10^9+7</var>. This case is not included in the test set for the partial score.</p></section> </div> </span>
p01256
<H1><font color="#000">Problem G:</font> Time Trial</H1> <p> Some people like finishing computer games in an extremely short time. Terry A. Smith is one of such and prefers role playing games particularly. </p> <p> He is now trying to find a shorter play for one of the key events in a role playing game. In this event, a player is presented a kind of puzzle on a grid map with three rocks and three marked squares. The objective is to have all the rocks placed on the marked squares by controlling the hero of this game appropriately. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_timeTrial"> <p>Figure 1: Example Map</p> </center> <p> The hero can move to the four adjacent squares, that is, to the north, east, south, and west, unless his move is blocked by walls or rocks. He can never enter squares occupied by walls. On the other hand, when he is moving to a square occupied by a rock, he pushes the rock in his moving direction. Nonetheless, he cannot push the rock if the next square is occupied by a wall or another rock and his move is blocked in this case. Also, he can only move one rock at a time. It is allowed to have rocks pass through marked squares. </p> <p> Terry thinks he can reduce his playing time by finding the optimal way to move the rocks and then playing the event accordingly. However, it is too hard for him to find the solution of this puzzle by hand. So you are asked by him to write a program that finds the smallest number of steps for the maps given as the input. Here, each move from a square to its adjacent square is counted as one step. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset has the following format: </p> <pre> <i>W H</i> <i>Row</i><sub>1</sub> ... <i>Row<sub>H</sub></i> </pre> <p> <i>W</i> and <i>H</i> are the width and height of the map (4 &le; <i>W</i>, <i>H</i> &le; 16). <i>Row</i><sub>i</sub> denotes the <i>i</i>-th row of the map and consists of <i>W</i> characters. Each character represents a square and is one of the following: ‘<span>#</span>’ (wall), ‘<span>.</span>’ (floor), ‘<span>*</span>’ (rock), ‘<span>_</span>’ (marked square), and ‘<span>@</span>’ (hero). Each map contains exactly three rocks, three marked squares, and one hero. The outermost squares are always occupied by walls. You may assume that the number of non-wall squares does not exceed fifty. It is also guaranteed that there is at least one solution for every map. </p> <p> The input is terminated by a line with two zeros. This line is not part of any datasets and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the smallest number of steps in a line. </p> <H2>Sample Input</H2> <pre> 7 6 ####### #.._..# #.*.*.# #.@.*.# #_..._# ####### 10 13 ########## ####___### ####...### ####...### #####.#### #.....#..# #.#*.*.*.# #...###..# ###.#.#.## ###.#.#.## ###.....## ###..@..## ########## 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 15 118 </pre>
p03545
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Sitting in a station waiting room, Joisino is gazing at her train ticket.</p> <p>The ticket is numbered with four digits <var>A</var>, <var>B</var>, <var>C</var> and <var>D</var> in this order, each between <var>0</var> and <var>9</var> (inclusive).</p> <p>In the formula <var>A</var> <var>op1</var> <var>B</var> <var>op2</var> <var>C</var> <var>op3</var> <var>D</var> <var>=</var> <var>7</var>, replace each of the symbols <var>op1</var>, <var>op2</var> and <var>op3</var> with <code>+</code> or <code>-</code> so that the formula holds.</p> <p>The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0≀A,B,C,D≀9</var></li> <li>All input values are integers.</li> <li>It is guaranteed that there is a solution.</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>ABCD</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the formula you made, including the part <code>=7</code>.</p> <p>Use the signs <code>+</code> and <code>-</code>.</p> <p>Do not print a space between a digit and a sign.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1222 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1+2+2+2=7 </pre> <p>This is the only valid solution.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0290 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0-2+9+0=7 </pre> <p><var>0 - 2 + 9 - 0 = 7</var> is also a valid solution.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3242 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3+2+4-2=7 </pre></section> </div> </span>
p01578
<H1><font color="#000">Problem I:</font> Sort by Hand</H1> <p> It's time to arrange the books on your bookshelf. There are <i>n</i> books in the shelf and each book has a unique number; you want to sort the books according to the numbers. You know that the quick sort and the merge sort are fast sorting methods, but it is too hard for you to simulate them by hand - they are efficient for computers, but not for humans. Thus, you decided to sort the books by inserting the book with the number <i>i</i> into the <i>i</i>-th position. How many insertions are required to complete this task? </p> <H2>Input</H2> <p> The first line of the input is <i>n</i> (1 &le; <i>n</i> &le; 20), which is the number of books. The second line contains <i>n</i> integers <i>v</i><sub>1</sub>, ... , <i>v<sub>n</sub></i> (1 &le; <i>v<sub>i</sub></i> &le; <i>n</i>), where <i>v<sub>i</sub></i> indicates the number of the book at the <i>i</i>-th position before the sorting. All <i>v<sub>i</sub></i>'s are distinct. </p> <H2>Output</H2> <p> Print the minimum number of insertions in a line. If it is impossible for him to complete the sort, print "impossible" (without quotes). </p> <H2>Sample Input 1</H2> <pre> 3 1 2 3 </pre> <H2>Output for the Sample Input 1</H2> <pre> 0 </pre> <br/> <H2>Sample Input 2</H2> <pre> 3 2 1 3 </pre> <H2>Output for the Sample Input 2</H2> <pre> 1 </pre> <br/> <H2>Sample Input 3</H2> <pre> 3 3 2 1 </pre> <H2>Output for the Sample Input 3</H2> <pre> 2 </pre> <br/> <H2>Sample Input 4</H2> <pre> 20 4 14 11 13 17 10 1 12 2 6 16 15 8 7 19 18 3 5 9 20 </pre> <H2>Output for the Sample Input 4</H2> <pre> 14 </pre>
p01082
<h1>Problem K: Escape of Lappin the Phantom Thief</h1> <h2>Problem</h2> <p> 怪盗ラッパンは宝石を盗みにやっおきた。簡単に宝石を手にするこずができたが、宝石にはセンサヌが仕蟌たれおおり、譊備ロボットに囲たれおしたった。 </p> <p> 譊備ロボットは宝石に向かっお移動するように仕組たれおいる。センサヌは簡単に倖せそうになかったので、宝石を眮いお逃走するこずにした。宝石をできるだけ譊備ロボットから遠くに眮いお、逃げるための時間皌ぎをするこずにした。 </p> <p> 敷地は<var>n</var> &times; <var>m</var>のマスからなる長方圢の圢をしおいお、障害物はない。 <var>k</var>䜓の譊備ロボットは、それぞれマス(<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>)(0 &le; <var>x<sub>i</sub></var> &le; <var>n</var>&minus;1, 0 &le; <var>y<sub>i</sub></var> &le; <var>m</var>&minus;1)に配眮されおおり、䞊䞋巊右のマスに単䜍時間で移動できる。 譊備ロボットは宝石があるマスに最短経路で移動する。 </p> <p> 敷地内に自由に宝石を眮けるずき、1台以䞊の譊備ロボットが宝石のあるマスに到達するたでにかかる移動時間の最倧倀を求めよ。 </p> <h2>Input</h2> <pre> <var>n</var> <var>m</var> <var>k</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> ... <var>x<sub>k</sub></var> <var>y<sub>k</sub></var> </pre> <p> 入力はすべお敎数で䞎えられる。<br> 1行目に<var>n</var>, <var>m</var>, <var>k</var>が空癜区切りで䞎えられる。<br> 2行目以降<var>k</var>行に譊備ロボットのいるマスの座暙(<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>)が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>n</var>, <var>m</var> &le; 5 &times; 10<sup>4</sup></li> <li>1 &le; <var>k</var> &le; min(10<sup>5</sup>, <var>n</var> &times; <var>m</var>)</li> <li>0 &le; <var>x<sub>i</sub></var> &le; <var>n</var>&minus;1</li> <li>0 &le; <var>y<sub>i</sub></var> &le; <var>m</var>&minus;1</li> <li>䞎えられる座暙はすべお異なる</li> </ul> <h2>Output</h2> <p> 譊備ロボットが到達するたでに、最も時間がかかる堎所ぞの移動時間を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 20 10 1 0 0 </pre> <h2>Sample Output 1</h2> <pre> 28 </pre> <h2>Sample Input 2</h2> <pre> 20 10 2 0 0 17 5 </pre> <h2>Sample Output 2</h2> <pre> 15 </pre> <h2>Sample Input 3</h2> <pre> 20 10 3 0 0 17 5 6 9 </pre> <h2>Sample Output 3</h2> <pre> 11 </pre>
p03115
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an infinitely large triangular grid, as shown below. Each point with integer coordinates contains a lamp.</p> <p><img alt="" src="https://img.atcoder.jp/wtf19/f617c94527a62ed72fe7db12b6d1f6b0.png"/></p> <p>Initially, only the lamp at <var>(X, 0)</var> was on, and all other lamps were off. Then, Snuke performed the following operation zero or more times:</p> <ul> <li>Choose two integers <var>x</var> and <var>y</var>. Toggle (on to off, off to on) the following three lamps: <var>(x, y), (x, y+1), (x+1, y)</var>.</li> </ul> <p>After the operations, <var>N</var> lamps <var>(x_1, y_1), \cdots, (x_N, y_N)</var> are on, and all other lamps are off. Find <var>X</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>-10^{17} \leq x_i, y_i \leq 10^{17}</var></li> <li><var>(x_i, y_i)</var> are pairwise distinct.</li> <li>The input is consistent with the statement, and you can uniquely determine <var>X</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 -2 1 -2 2 0 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>-1 </pre> <p>The following picture shows one possible sequence of operations:</p> <p><img alt="" src="https://img.atcoder.jp/wtf19/cff6dc4d81e995e9300ccbaca5bf85de.png"/></p></section> </div> </span>
p01128
<h1>Railroad Conflict</h1> <p> Nate U. Smith は倧郜垂圏の鉄道䌚瀟を経営しおいるこの倧郜垂圏には圌の鉄道䌚瀟以倖にラむバルの鉄道䌚瀟がある2 瀟は互いに競合関係にある </p> <p> この倧郜垂圏では列車の運行を容易にするため党おの路線は䞡端の駅を結んだ線分を経路ずしおいるたた螏切等の蚭眮をさけるため党おの路線は高架たたは地䞋に敷蚭されおいる既存路線は党線にわたっお高架を走るかたたは党線にわたっお地䞋を走るかのいずれかである </p> <p> ずころで最近この倧郜垂圏にある 2 ぀の街区 AB がさかんに開発されおいるこずからNate の䌚瀟ではこれらの街区の間に新しい路線を蚭けるこずを決断したこの新路線は埓来の路線ず同様に AB を䞡端ずする線分を経路ずしたいが経路の途䞭には別の路線があるこずから高架あるいは地䞋のいずれかに党線を敷蚭するこずは䞍可胜であるそこで路線の䞀郚を高架に残りの郚分を地䞋に敷蚭するこずにしたこのずき新路線が自瀟の既存路線ず亀わるずころでは新路線ず既存路線ずの間の乗り継ぎを䟿利にするため既存路線が高架ならば新路線も高架に既存路線が地䞋ならば新路線も地䞋を走るようにするたた新路線が他瀟の既存路線ず亀わるずころでは他瀟による劚害をさけるため既存路線が高架ならば新路線は地䞋に既存路線が地䞋ならば新路線は高架を走るようにするA 駅および B 駅をそれぞれ高架あるいは地䞋のいずれに蚭けるかは特に問わない </p> <p> 圓然のこずながら新路線が高架から地䞋にあるいは地䞋から高架に移るずころには出入口を蚭けなければならないずころが出入口を蚭けるためには費甚がかかるため新路線に蚭ける出入口の個数は最小限に抑えたいそれにはプログラマであるあなたの助けを芁するず考えた Nate はあなたを圌の䌚瀟に呌び出した </p> <p> あなたの仕事はA 駅B 駅の䜍眮そしお既存路線に関する情報が䞎えられたずきに新路線においお最䜎限蚭けなければならない出入口の個数を求めるプログラムを䜜成するこずである </p> <p> 以䞋の図はサンプルずしお䞎えた入力および出力の内容を瀺したものである </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_rail1"><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_rail2"> </p> <h3>Input</h3> <p> 入力の先頭行には単䞀の正の敎数が含たれこれはデヌタセットの個数を衚すそれぞれのデヌタセットは次の圢匏で䞎えられる <blockquote> <i>xa</i> <i>ya</i> <i>xb</i> <i>yb</i><br> <i>n</i><br> <i>xs</i><sub>1</sub> <i>ys</i><sub>1</sub> <i>xt</i><sub>1</sub> <i>yt</i><sub>1</sub> <i>o</i><sub>1</sub> <i>l</i><sub>1</sub><br> <i>xs</i><sub>2</sub> <i>ys</i><sub>2</sub> <i>xt</i><sub>2</sub> <i>yt</i><sub>2</sub> <i>o</i><sub>2</sub> <i>l</i><sub>2</sub><br> ...<br> <i>xs</i><sub><i>n</i></sub> <i>ys</i><sub><i>n</i></sub> <i>xt</i><sub><i>n</i></sub> <i>yt</i><sub><i>n</i></sub> <i>o</i><sub><i>n</i></sub> <i>l</i><sub><i>n</i></sub><br> </blockquote> ただし(<i>xa</i>,<i>ya</i>) および (<i>xb</i>,<i>yb</i>) はそれぞれ A 駅B 駅の座暙を衚す<i>N</i> は既存路線の数を衚す 100 以䞋の正の敎数である(<i>xs</i><sub><i>i</i></sub>,<i>ys</i><sub><i>i</i></sub>) および (<i>ys</i><sub><i>i</i></sub>,<i>yt</i><sub><i>i</i></sub>) は <i>i</i> 番目の既存路線における始点および終点の座暙を衚す<i>o</i><sub><i>i</i></sub> は <i>i</i> 番目の既存路線の所有者を衚す敎数であるこれは 1 たたは 0 のいずれかであり1 はその路線が自瀟所有であるこずを0 は他瀟所有であるこずをそれぞれ衚す<i>l</i><sub>i</sub> は <i>i</i> 番目の既存路線が高架たたは地䞋のいずれにあるかを衚す敎数であるこれも 1 たたは 0 のいずれかであり1 はその路線が高架にあるこずを0 は地䞋にあるこずをそれぞれ衚す </p> <p> 入力䞭に珟れる x 座暙および y 座暙の倀は -10000 から 10000 の範囲にある䞡端も範囲に含たれるたたそれぞれのデヌタセットにおいお新路線を含めた党おの路線に察しお以䞋の条件を満たすず仮定しおよいここで 2 点が非垞に近いずはその 2 点間の距離が 10<sup>-9</sup> 以䞋であるこずを衚す <ul> <li>ある亀点の非垞に近くに別の亀点があるこずはない</li> <li>ある路線の端点の非垞に近くを別の路線が通るこずはない</li> <li>2 ぀の路線の䞀郚たたは党郚が重なるこずはない</li> </ul> </p> <h3>Output</h3> <p> それぞれのデヌタセットに察しお最䜎限蚭けなければならない出入口の個数を 1 行に出力しなさい </p> <h3>Sample Input</h3> <pre> 2 -10 1 10 1 4 -6 2 -2 -2 0 1 -6 -2 -2 2 1 0 6 2 2 -2 0 0 6 -2 2 2 1 1 8 12 -7 -3 8 4 -5 4 -2 1 1 4 -2 4 9 1 0 6 9 6 14 1 1 -7 6 7 6 0 0 1 0 1 10 0 0 -5 0 -5 10 0 1 -7 0 7 0 0 1 -1 0 -1 -5 0 1 </pre> <h3>Output for the Sample Input</h3> <pre> 1 3 </pre>
p00369
<H1>Paper Fortune</H1> <p> If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written. </p> <p> Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your dream comes true. Cut up the string into more than one segment and compare their values. The difference between the largest and smallest value will give you the number of years before your wish will be fulfilled. Therefore, the result varies depending on the way you cut up the string. For example, if you are given a string 11121314 and divide it into segments, say, as 1,11,21,3,14, then the difference between the largest and smallest is 21 - 1 = 20. Another division 11,12,13,14 produces 3 (i.e. 14 - 11) years. Any random division produces a game of luck. However, you can search the minimum number of years using a program. </p> <p> Given a string of numerical characters, write a program to search the minimum years before your wish will be fulfilled. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>n</var> </pre> <p> An integer <var>n</var> is given. Its number of digits is from 2 to 100,000, and each digit ranges from 1 to 9. </p> <h2>Output</h2> <p> Output the minimum number of years before your wish will be fulfilled. </p> <h2>Sample Input 1</h2> <pre> 11121314 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <h2>Sample Input 2</h2> <pre> 123125129 </pre> <h2>Sample Output 2</h2> <pre> 6 </pre> <h2>Sample Input 3</h2> <pre> 119138 </pre> <h2>Sample Output 3</h2> <pre> 5 </pre>
p02354
<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>The Smallest Window I</H1> <p> For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0. </p> <h2>Constraints</h2> <ul> <li> $1 \leq N \leq 10^5$ </li> <li> $1 \leq S \leq 10^9$</li> <li> $1 \leq a_i \leq 10^4$</li> </ul> <h2>Input</h2> <p>The input is given in the following format.</p> <p> $N$ $S$<br> $a_1$ $a_2$ ... $a_N$<br> </p> <h2>Output</h2> <p> Print the smallest sub-array size in a line. </p> <h2>Sample Input 1</h2> <pre> 6 4 1 2 1 2 3 2 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 6 6 1 2 1 2 3 2 </pre> <h2>Sample Output 2</h2> <pre> 3 </pre> <h2>Sample Input 3</h2> <pre> 3 7 1 2 3 </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p00693
<h1> Cyber Guardian </h1> <p>In the good old days, the Internet was free from fears and terrorism. People did not have to worry about any cyber criminals or mad computer scientists. Today, however, you are facing atrocious crackers wherever you are, unless being disconnected. You have to protect yourselves against their attacks.</p> <p>Counting upon your excellent talent for software construction and strong sense of justice, you are invited to work as a cyber guardian. Your ultimate mission is to create a perfect firewall system that can completely shut out any intruders invading networks and protect children from harmful information exposed on the Net. However, it is extremely difficult and none have ever achieved it before. As the first step, instead, you are now requested to write a software simulator under much simpler assumptions.</p> <p>In general, a firewall system works at the entrance of a local network of an organization (e.g., a company or a university) and enforces its local administrative policy. It receives both inbound and outbound packets (note: data transmitted on the Net are divided into small segments called packets) and carefully inspects them one by one whether or not each of them is legal. The definition of the legality may vary from site to site or depend upon the local administrative policy of an organization. Your simulator should accept data representing not only received packets but also the local administrative policy.</p> <p>For simplicity in this problem we assume that each network packet consists of three fields: its source address, destination address, and message body. The source address specifies the computer or appliance that transmits the packet and the destination address specifies the computer or appliance to which the packet is transmitted. An address in your simulator is represented as eight digits such as 03214567 or 31415926, instead of using the standard notation of IP addresses such as 192.168.1.1. Administrative policy is described in filtering rules, each of which specifies some collection of source-destination address pairs and defines those packets with the specified address pairs either legal or illegal. </p> <h2>Input</h2> <p>The input consists of several data sets, each of which represents filtering rules and received packets in the following format:</p> <dir> <i>n</i> <i>m</i><br> <i>rule</i><sub>1</sub><br> <i>rule</i><sub>2</sub><br> <dir>...</dir><br> <i>rule<sub>n</sub></i><br> <i>packet</i><sub>1</sub><br> <i>packet</i><sub>2</sub><br> <dir>...</dir><br> <i>packet</i><sub>m</sub><br> </dir> <p>The first line consists of two non-negative integers <i>n</i> and <i>m</i>. If both <i>n</i> and <i>m</i> are zeros, this means the end of input. Otherwise, <i>n</i> lines, each representing a filtering rule, and <i>m</i> lines, each representing an arriving packet, follow in this order. You may assume that <i>n</i> and <i>m</i> are less than or equal to 1,024.</p> <p>Each <i>rule<sub>i</sub></i> is in one of the following formats:</p> <dir> <p>permit <i>source-pattern</i> <i>destination-pattern</i></p> <p>deny <i>source-pattern</i> <i>destination-pattern</i></p> </dir> <p>A <i>source-pattern</i> or <i>destination-pattern</i> is a character string of length eight, where each character is either a digit ('0' to '9') or a wildcard character '?'. For instance, "1????5??" matches any address whose first and fifth digits are '1' and '5', respectively. In general, a wildcard character matches any single digit while a digit matches only itself.</p> <p>With the keywords "permit" and "deny", filtering rules specify legal and illegal packets, respectively. That is, if the source and destination addresses of a packed are matched with <i>source-pattern</i> and <i>destination-pattern</i>, respectively, it is <i>permitted</i> to pass the firewall or the request is <i>denied</i> according to the keyword. Note that a permit rule and a deny rule can contradict since they may share the same source and destination address pair. For the purpose of conflict resolution, we define a priority rule: <i>rule<sub>i</sub></i> has a higher priority over <i>rule<sub>j</sub></i> if and only if <i>i</i> &gt; <i>j</i>. For completeness, we define the default rule: any packet is illegal unless being explicitly specified legal by some given rule.</p> <p>A packet is in the following format:</p> <dir> <p><i>source-address</i> <i>destination-address</i> <i>message-body</i></p> </dir> <p>Each of the first two is a character string of length eight that consists solely of digits. The last one is a character string consisting solely of alphanumeric characters ('a' to 'z', 'A' to 'Z', and '0' to '9'). Neither whitespaces nor special characters can occur in a message body. You may assume that it is not empty and that its length is at most 50. </p> <p>You may also assume that there is exactly one space character between any two adjacent fields in an input line representing a rule or a packet.</p> <h2>Output</h2> <p>For each data set, print the number of legal packets in the first line, followed by all legal packets in the same order as they occur in the data set. Each packet must be written exactly in one line. If the data set includes two packets consisting of the same source and destination addresses and the same message body, you should consider them different packets and so they must be written in different lines. Any extra whitespaces or extra empty lines must not be written. </p> <h2>Sample Input</h2> <pre>2 5 permit 192168?? ?12??34? deny 19216899 012343?5 19216711 11233340 HiIamACracker 19216891 01234345 Hello 19216899 01234345 HiIamAlsoACracker 19216809 11200340 World 00000000 99999999 TheEndOfTheWorld 1 2 permit 12345678 23456789 19216891 01234345 Hello 12345678 23456789 Hello 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 2 19216891 01234345 Hello 19216809 11200340 World 1 12345678 23456789 Hello </pre>
p01981
<h3>改元</h3> <p>平成31幎4月30日をもっお珟行の元号である平成が終了しその翌日より新しい元号が始たるこずになった平成最埌の日の翌日は新元号元幎5月1日になる</p> <p>ACM-ICPC OB/OGの䌚 (Japanese Alumni Group; JAG) が開発するシステムでは日付が和暊元号ずそれに続く幎数によっお幎を衚珟する日本の暊を甚いお "平成 <i>y</i> 幎 <i>m</i> 月 <i>d</i> 日" ずいう圢匏でデヌタベヌスに保存されおいるこの保存圢匏は倉曎するこずができないためJAGは元号が倉曎されないず仮定しお和暊で衚した日付をデヌタベヌスに保存し出力の際に日付を正しい元号を甚いた圢匏に倉換するこずにした</p> <p>あなたの仕事はJAGのデヌタベヌスに保存されおいる日付を平成たたは新元号を甚いた日付に倉換するプログラムを曞くこずである新元号はただ発衚されおいないため"?" を甚いお衚すこずにする</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットからなる各デヌタセットは次の圢匏で衚される</p> <blockquote><i>g</i> <i>y</i> <i>m</i> <i>d</i></blockquote> <p><i>g</i> は元号を衚す文字列であり <i>g=</i>HEISEI が成り立぀<i>y, m, d</i> は敎数でありそれぞれ幎月日を衚す<i>1 &le; y &le; 100, 1 &le; m &le; 12, 1 &le; d &le; 31</i> が成り立぀</p> <p>2月30日などの和暊に存圚しない日付はデヌタセットずしお䞎えられない和暊ずしお正しく倉換したずきに平成よりも前の元号を甚いる必芁がある日付もデヌタセットずしお䞎えられない</p> <p>入力の終わりは '#' 䞀぀のみからなる行であらわされるデヌタセットの個数は 100 個を超えない</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに぀いお倉換埌の元号幎月日を空癜で区切っお 1 行に出力せよ倉換埌の元号が "平成" である堎合は "HEISEI" を元号ずしお甚い新元号であれば "?" を甚いよ</p> <p>通垞元号の第 1 幎目は元幎ず衚蚘するが本問題の出力ではこの芏則を無芖し1 を幎ずしお出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>HEISEI 1 1 8 HEISEI 31 4 30 HEISEI 31 5 1 HEISEI 99 12 31 HEISEI 38 8 30 HEISEI 98 2 22 HEISEI 2 3 26 HEISEI 28 4 23 # </pre><h3>Output for the Sample Input</h3><pre>HEISEI 1 1 8 HEISEI 31 4 30 ? 1 5 1 ? 69 12 31 ? 8 8 30 ? 68 2 22 HEISEI 2 3 26 HEISEI 28 4 23 </pre>
p00739
<h1><font color="#000000">Problem F:</font> ICPC: Intelligent Congruent Partition of Chocolate</h1> <!-- end en only --> <!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> --> <!-- begin en only --> <p> The twins named Tatsuya and Kazuya love chocolate. They have found a bar of their favorite chocolate in a very strange shape. The chocolate bar looks to have been eaten partially by Mam. They, of course, claim to eat it and then will cut it into two pieces for their portions. Since they want to be sure that the chocolate bar is fairly divided, they demand that the shapes of the two pieces are <I>congruent</I> and that each piece is <I>connected</I>. </p> <p> The chocolate bar consists of many square shaped blocks of chocolate connected to the adjacent square blocks of chocolate at their edges. The whole chocolate bar is also connected. </p> <p> Cutting the chocolate bar along with some edges of square blocks, you should help them to divide it into two congruent and connected pieces of chocolate. That is, one piece fits into the other after it is rotated, turned over and moved properly. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F1" width=150 ><br> <!-- begin en only --> Figure F-1: A partially eaten chocolate bar with 18 square blocks of chocolate <!-- end en only --> </center> <!-- begin en only --> <p> For example, there is a partially eaten chocolate bar with 18 square blocks of chocolate as depicted in Figure F-1. Cutting it along with some edges of square blocks, you get two pieces of chocolate with 9 square blocks each as depicted in Figure F-2. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F2" width=200 ><br> <!-- begin en only --> Figure F-2: Partitioning of the chocolate bar in Figure F-1 <!-- end en only --> </center> <!-- begin en only --> <p> You get two congruent and connected pieces as the result. One of them consists of 9 square blocks hatched with horizontal lines and the other with vertical lines. Rotated clockwise with a right angle and turned over on a horizontal line, the upper piece exactly fits into the lower piece. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F3" width=120 ><br> <!-- begin en only --> Figure F-3: A shape that cannot be partitioned into two congruent and connected pieces <!-- end en only --> </center> <!-- begin en only --> <p> Two square blocks touching only at their corners are regarded as they are not connected to each other. Figure F-3 is an example shape that cannot be partitioned into two congruent and connected pieces. Note that, without the connectivity requirement, this shape can be partitioned into two congruent pieces with three squares (Figure F-4). </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F4" width=120 ><br> <!-- begin en only --> Figure F-4: Two congruent but disconnected pieces <!-- end en only --> </center> <!-- begin en only --> <p> Your job is to write a program that judges whether a given bar of chocolate can be partitioned into such two congruent and connected pieces or not. </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. </p> <!-- end en only --> <p> <blockquote> <i>w h</i><br> <i>r</i>(1, 1) ... <i>r</i>(1, <i>w</i>)<br> <i>r</i>(2, 1) ... <i>r</i>(2, <i>w</i>)<br> ... <br> <i>r</i>(<i>h</i>, 1) ... <i>r</i>(<i>h</i>, <i>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 a chocolate bar, respectively. You may assume 2 &le; <i>w</i> &le; 10 and 2 &le; <i>h</i> &le; 10. Each of the following <i>h</i> lines consists of <i>w</i> digits delimited by a space. The digit <i>r</i>(<i>i</i>, <i>j</i>) represents the existence of a square block of chocolate at the position (<i>i</i>, <i>j</i>) as follows. <ul> <li> '0': There is no chocolate (i.e., already eaten). </li> <li> '1': There is a square block of chocolate. </li> </ul> </p> <p> You can assume that there are at most 36 square blocks of chocolate in the bar, i.e., the number of digit '1's representing square blocks of chocolate is at most 36 in each dataset. You can also assume that there is at least one square block of chocolate in each row and each column. </p> <!-- end en only --> <!-- begin en only --> <p> You can assume that the chocolate bar is connected. Since Mam does not eat chocolate bars making holes in them, you can assume that there is no dataset that represents a bar in a shape with hole(s) as depicted in Figure F-5. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F5" width=120 ><br> <!-- begin en only --> Figure F-5: A partially eaten chocolate bar with a hole (You can assume that there is no dataset like this example) <!-- end en only --> </center> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a line containing one of two uppercase character strings "YES" or "NO". "YES" means the chocolate bar indicated by the dataset can be partitioned into two congruent and connected pieces, and "NO" means it cannot be partitioned into such two pieces. No other characters should be on the output line. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 2 2 1 1 1 1 3 3 0 1 0 1 1 0 1 1 1 4 6 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 0 7 5 0 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 0 1 0 0 0 1 1 0 9 7 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 9 7 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 7 6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 10 10 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> YES NO YES YES YES NO NO YES </pre>
p02704
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are an integer <var>N</var> and arrays <var>S</var>, <var>T</var>, <var>U</var>, and <var>V</var>, each of length <var>N</var>. Construct an <var>N×N</var> matrix <var>a</var> that satisfy the following conditions:</p> <ul> <li><var>a_{i,j}</var> is an integer.</li> <li><var>0 \leq a_{i,j} \lt 2^{64}</var>.</li> <li>If <var>S_{i} = 0</var>, the bitwise AND of the elements in the <var>i</var>-th row is <var>U_{i}</var>.</li> <li>If <var>S_{i} = 1</var>, the bitwise OR of the elements in the <var>i</var>-th row is <var>U_{i}</var>.</li> <li>If <var>T_{i} = 0</var>, the bitwise AND of the elements in the <var>i</var>-th column is <var>V_{i}</var>.</li> <li>If <var>T_{i} = 1</var>, the bitwise OR of the elements in the <var>i</var>-th column is <var>V_{i}</var>.</li> </ul> <p>However, there may be cases where no matrix satisfies the conditions.</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 500 </var></li> <li><var> 0 \leq S_{i} \leq 1 </var></li> <li><var> 0 \leq T_{i} \leq 1 </var></li> <li><var> 0 \leq U_{i} \lt 2^{64} </var></li> <li><var> 0 \leq V_{i} \lt 2^{64} </var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S_{1}</var> <var>S_{2}</var> <var>...</var> <var>S_{N}</var> <var>T_{1}</var> <var>T_{2}</var> <var>...</var> <var>T_{N}</var> <var>U_{1}</var> <var>U_{2}</var> <var>...</var> <var>U_{N}</var> <var>V_{1}</var> <var>V_{2}</var> <var>...</var> <var>V_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a matrix that satisfies the conditions, print one such matrix in the following format:</p> <pre><var>a_{1,1}</var> <var>...</var> <var>a_{1,N}</var> <var>:</var> <var>a_{N,1}</var> <var>...</var> <var>a_{N,N}</var> </pre> <p>Note that any matrix satisfying the conditions is accepted.</p> <p>If no matrix satisfies the conditions, print <var>-1</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 1 1 0 1 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 1 1 0 </pre> <p>In Sample Input <var>1</var>, we need to find a matrix such that:</p> <ul> <li>the bitwise AND of the elements in the <var>1</var>-st row is <var>1</var>;</li> <li>the bitwise OR of the elements in the <var>2</var>-nd row is <var>1</var>;</li> <li>the bitwise OR of the elements in the <var>1</var>-st column is <var>1</var>;</li> <li>the bitwise AND of the elements in the <var>2</var>-nd column is <var>0</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 1 1 0 15 15 15 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>15 11 15 11 </pre></section> </div> </span>
p03816
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has decided to play a game using cards. He has a deck consisting of <var>N</var> cards. On the <var>i</var>-th card from the top, an integer <var>A_i</var> is written.</p> <p>He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, <var>N</var> is odd, which guarantees that at least one card can be kept.</p> <p>Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 ≩ N ≩ 10^{5}</var></li> <li><var>N</var> is odd.</li> <li><var>1 ≩ A_i ≩ 10^{5}</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>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_3</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>5 1 2 1 3 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>One optimal solution is to perform the operation once, taking out two cards with <var>1</var> and one card with <var>2</var>. One card with <var>1</var> and another with <var>2</var> will be eaten, and the remaining card with <var>1</var> will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: <var>1</var>, <var>3</var> and <var>7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre></section> </div> </span>
p02211
<h2>りんごだいがうけん</h2> <p>square1001君ずE869120君は瞊 $H$ 行、暪 $W$ 列のグリッドの䞖界に迷い蟌んでしたいたした!</p> <p>この䞖界の神は蚀いたした。</p> <p>「リンゎを $K$ 個集めお二人が出䌚ったずき、さすれば元の䞖界に垰れるであろう。」</p> <p>この蚀葉を聞いたsquare1001君は、リンゎを $K$ 個以䞊集めおE869120君がいるマスぞ向かうこずにしたした。</p> <br> <p>ここで、グリッドの各マスは次のように衚されたす。</p> <p>'s'square1001君がいるマスです。</p> <p>'e'E869120君がいるマスです。</p> <p>'a'リンゎが1぀萜ちおいるマスです。このマスを初めお蚪れたずきにリンゎを1぀埗るこずができたす。<strong>このグリッド䞊にこのマスは20個以䞋しかありたせん。</strong></p> <p>'#'壁です。このマスに蚪れるこずはできたせん。</p> <p>'.'䜕もないマスです。このマスに蚪れるこずができたす。</p> <br> <p>square1001君は自分がいるマスから䞊䞋巊右に隣り合うマスぞの移動を繰り返すこずで、目的を達成しようずしたす。ただし、グリッドから倖に出るこずはできたせん。</p> <p>square1001君が目的を達成するために必芁な移動回数の最小倀を求めおください。</p> <p>ただし、E869120君が動くこずはないものずしたす。たた、square1001君はリンゎを $K$ 個以䞊持ち運ぶ胜力があるものずしたす。</p> <p>たた、目暙が達成できないずきは「-1」を出力しおください。</p> <h3>入力</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <p>グリッドの䞊から $i$ マス目、巊から $j$ マス目の文字を $A_{i, j}$ ずする。</p> <pre> $H$ $W$ $K$ $A_{1,1} A_{1,2} A_{1,3} \cdots A_{1,W}$ $A_{2,1} A_{2,2} A_{2,3} \cdots A_{2,W}$ $A_{3,1} A_{3,2} A_{3,3} \cdots A_{3,W}$ $\ldots$ $A_{H,1} A_{H,2} A_{H,3} \cdots A_{H,W}$ </pre> <h3>出力</h3> <p>square1001君が目的を達成するたでに必芁な移動回数の最小倀を求めおください。ただし、䞍可胜な堎合は「-1」を出力しおください。</p> <p>ただし、最埌には改行を入れるこず。</p> <h3>制玄</h3> <ul> <li>$1 \leq H \leq 1000$</li> <li>$1 \leq W \leq 1000$</li> <li>$1 \leq K \leq 20$</li> <li>$H, W, K$ は敎数である。</li> <li>$A_{i, j}$ は 's'、'e'、'a'、'#'、'.'のいずれかである。</li> <li>グリッドに 's'、'e'はそれぞれただ 1 ぀のみ含たれる。</li> <li>グリッドに含たれる 'a' の数は $K$ 個以䞊 $20$ 個以䞋である。</li> </ul> <h3>入力䟋1</h3> <pre> 5 5 2 s..#a .#... a#e.# ...#a .#... </pre> <h3>出力䟋1</h3> <pre> 14 </pre> <h3>入力䟋2</h3> <pre> 7 7 3 ....... .s...a. a##...a ..###.. .a#e#.a #.###.. a..#..a </pre> <h3>出力䟋2</h3> <pre> -1 </pre> <p>目的が達成䞍可胜な堎合は「-1」を出力しおください。</p> <h3>入力䟋3</h3> <pre> 12 12 10 .#####...... .##.....#... ....a.a#a..# .#..#a...... ##.....a#s.. #..a###.##.# .e#.#.#.#a.. ..#a#.....#. #..##a...... .a...a.a..#. a....#a.aa.. ...a.#...#a. </pre> <h3>出力䟋3</h3> <pre> 30 </pre>
p00386
<h1>Meeting in a City</h1>  <p> You are a teacher at Iazu High School is the Zuia Kingdom. There are $N$ cities and $N-1$ roads connecting them that allow you to move from one city to another by way of more than one road. Each of the roads allows bidirectional traffic and has a known length. </p> <p> As a part of class activities, you are planning the following action assignment for your students. First, you come up with several themes commonly applicable to three different cities. Second, you assign each of the themes to a group of three students. Then, each student of a group is assigned to one of the three cities and conducts a survey on it. Finally, all students of the group get together in one of the $N$ cities and compile their results. </p> <p> After a theme group has completed its survey, the three members move from the city on which they studied to the city for getting together. The longest distance they have to travel for getting together is defined as the cost of the theme. You want to select the meeting city so that the cost for each theme becomes minimum. </p> <p> Given the number of cities, road information and $Q$ sets of three cities for each theme, make a program to work out the minimum cost for each theme. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $Q$ $u_1$ $v_1$ $w_1$ $u_2$ $v_2$ $w_2$ $...$ $u_{N-1}$ $v_{N-1}$ $w_{N-1}$ $a_1$ $b_1$ $c_1$ $a_2$ $b_2$ $c_2$ $...$ $a_Q$ $b_Q$ $c_Q$ </pre> <p> The first line provides the number of cities in the Zuia Kingdom $N$ ($3 \leq N \leq 100,000$) and the number of themes $Q$ ($1 \leq Q \leq 100,000$). Each of the subsequent $N-1$ lines provides the information regarding the $i$-th road $u_i,v_i,w_i$ ($ 1 \leq u_i < v_i \leq N, 1 \leq w_i \leq 10,000$), indicating that the road connects cities $u_i$ and $v_i$, and the road distance between the two is $w_i$. Each of the $Q$ lines that follows the above provides the three cities assigned to the $i$-th theme: $a_i,b_i,c_i$ ($1 \leq a_i < b_i < c_i \leq N$). </p> <h2>Output</h2> <p> For each theme, output the cost in one line.  </p> <h2>Sample Input 1</h2> <pre> 5 4 1 2 3 2 3 4 2 4 2 4 5 3 1 3 4 1 4 5 1 2 3 2 4 5 </pre> <h2>Sample Output 1</h2> <pre> 4 5 4 3 </pre> <p> In the first theme, traveling distance from City 3 (the student conducts survey) to City 2 (meeting venue) determines the cost 4. As no other meeting city can provide smaller cost, you should output 4. In the second theme, you can minimize the cost down to 5 by selecting City 2 or City 4 as the meeting venue. </p> <h2>Sample Input 2</h2> <pre> 5 3 1 2 1 2 3 1 3 4 1 4 5 1 1 2 3 1 3 5 1 2 4 </pre> <h2>Sample Output 2</h2> <pre> 1 2 2 </pre> <h2>Sample Input 3</h2> <pre> 15 15 1 2 45 2 3 81 1 4 29 1 5 2 5 6 25 4 7 84 7 8 56 4 9 2 4 10 37 7 11 39 1 12 11 11 13 6 3 14 68 2 15 16 10 13 14 13 14 15 2 14 15 7 12 15 10 14 15 9 10 15 9 14 15 8 13 15 5 6 13 11 13 15 12 13 14 2 3 10 5 13 15 10 11 14 6 8 11 </pre> <h2>Sample Output 3</h2> <pre> 194 194 97 90 149 66 149 140 129 129 194 111 129 194 140 </pre>
p02641
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are an integer <var>X</var> and an integer sequence of length <var>N</var>: <var>p_1, \ldots, p_N</var>.</p> <p>Among the integers not contained in the sequence <var>p_1, \ldots, p_N</var> (not necessarily positive), find the integer nearest to <var>X</var>, that is, find the integer whose absolute difference with <var>X</var> is the minimum. If there are multiple such integers, report the smallest such integer.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X \leq 100</var></li> <li><var>0 \leq N \leq 100</var></li> <li><var>1 \leq p_i \leq 100</var></li> <li><var>p_1, \ldots, p_N</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>X</var> <var>N</var> <var>p_1</var> <var>...</var> <var>p_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>6 5 4 7 10 6 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>Among the integers not contained in the sequence <var>4, 7, 10, 6, 5</var>, the one nearest to <var>6</var> is <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 5 4 7 10 6 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> <p>Among the integers not contained in the sequence <var>4, 7, 10, 6, 5</var>, the ones nearest to <var>10</var> are <var>9</var> and <var>11</var>. We should print the smaller one, <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>100 </pre> <p>When <var>N = 0</var>, the second line in the input will be empty. Also, as seen here, <var>X</var> itself can be the answer.</p></section> </div> </span>
p03953
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> rabbits on a number line. The rabbits are conveniently numbered <var>1</var> through <var>N</var>. The coordinate of the initial position of rabbit <var>i</var> is <var>x_i</var>.</p> <p>The rabbits will now take exercise on the number line, by performing <em>sets</em> described below. A set consists of <var>M</var> <em>jumps</em>. The <var>j</var>-th jump of a set is performed by rabbit <var>a_j</var> (<var>2≀a_j≀N-1</var>). For this jump, either rabbit <var>a_j-1</var> or rabbit <var>a_j+1</var> is chosen with equal probability (let the chosen rabbit be rabbit <var>x</var>), then rabbit <var>a_j</var> will jump to the symmetric point of its current position with respect to rabbit <var>x</var>.</p> <p>The rabbits will perform <var>K</var> sets in succession. For each rabbit, find the expected value of the coordinate of its eventual position after <var>K</var> sets are performed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3≀N≀10^5</var></li> <li><var>x_i</var> is an integer.</li> <li><var>|x_i|≀10^9</var></li> <li><var>1≀M≀10^5</var></li> <li><var>2≀a_j≀N-1</var></li> <li><var>1≀K≀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> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var> <var>M</var> <var>K</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_M</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 expected value of the coordinate of the eventual position of rabbit <var>i</var> after <var>K</var> sets are performed. The output is considered correct if the absolute or relative error is at most <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 -1 0 2 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>-1.0 1.0 2.0 </pre> <p>Rabbit <var>2</var> will perform the jump. If rabbit <var>1</var> is chosen, the coordinate of the destination will be <var>-2</var>. If rabbit <var>3</var> is chosen, the coordinate of the destination will be <var>4</var>. Thus, the expected value of the coordinate of the eventual position of rabbit <var>2</var> is <var>0.5×(-2)+0.5×4=1.0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 -1 1 2 2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1.0 -1.0 1.0 </pre> <p><var>x_i</var> may not be distinct.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 0 1 3 6 10 3 10 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0.0 3.0 7.0 8.0 10.0 </pre></section> </div> </span>
p03400
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Some number of chocolate pieces were prepared for a training camp. The camp had <var>N</var> participants and lasted for <var>D</var> days. The <var>i</var>-th participant (<var>1 \leq i \leq N</var>) ate one chocolate piece on each of the following days in the camp: the <var>1</var>-st day, the <var>(A_i + 1)</var>-th day, the <var>(2A_i + 1)</var>-th day, and so on. As a result, there were <var>X</var> chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.</p> <p>Find the number of chocolate pieces prepared at the beginning of the camp.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq D \leq 100</var></li> <li><var>1 \leq X \leq 100</var></li> <li><var>1 \leq A_i \leq 100</var> (<var>1 \leq i \leq 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>D</var> <var>X</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>Find the number of chocolate pieces prepared at the beginning of the camp.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 7 1 2 5 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>The camp has <var>3</var> participants and lasts for <var>7</var> days. Each participant eats chocolate pieces as follows:</p> <ul> <li>The first participant eats one chocolate piece on Day <var>1</var>, <var>3</var>, <var>5</var> and <var>7</var>, for a total of four.</li> <li>The second participant eats one chocolate piece on Day <var>1</var> and <var>6</var>, for a total of two.</li> <li>The third participant eats one chocolate piece only on Day <var>1</var>, for a total of one.</li> </ul> <p>Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is <var>1 + 4 + 2 + 1 = 8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 8 20 1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>29 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 30 44 26 18 81 18 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>56 </pre></section> </div> </span>
p01597
<H2>Problem G: Nezumi's Treasure</h2> <p>There were a mouse and a cat living in a field. The mouse stole a dried fish the cat had loved. The theft was found soon later. The mouse started running as chased by the cat for the dried fish.</p> <p>There were a number of rectangular obstacles in the field. The mouse always went straight ahead as long as possible, but he could not jump over or pass through these obstacles. When he was blocked by an obstacle, he turned leftward to the direction he could go forward, and then he started again to run in that way. Note that, at the corner, he might be able to keep going without change of the direction.</p> <p>He found he was going to pass the same point again and again while chased by the cat. He then decided to hide the dried fish at the first point where he was blocked by an obstacle twice from that time. In other words, he decided to hide it at the first turn after he entered into an infinite loop. He thought he could come there again after the chase ended.</p> <p>For example, in the following figure, he first went along the blue line and turned left at point B. Then he went along the red lines counter-clockwise, and entered into an infinite loop. In this case, he hid dried fish at NOT point B but at point A, because when he reached point B on line C for the second time, he just passed and didn't turn left.</p> <div align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_nezumi_fig3"><br> Example of dried fish point</div> <p>Finally the cat went away, but he remembered neither where he thought of hiding the dried fish nor where he actually hid it. Yes, he was losing <i>his</i> dried fish.</p> <p>You are a friend of the mouse and talented programmer. Your task is to write a program that counts the number of possible points the mouse hid the dried fish, where information about the obstacles is given. The mouse should be considered as a point.</p> <h2>Input</h2> <p>The input begins with a line with one integer <var>N</var> (4 <= <var>N</var> <= 40,000), which denotes the number of obstacles. Then <var>N</var> lines follow. Each line describes one obstacle with four integers <var>X<sub>i,1</sub></var>, <var>Y<sub>i,1</sub></var>, <var>X<sub>i,2</sub></var>, and <var>Y<sub>i,2</sub></var> (-100,000,000 <= <var>X<sub>i,1</sub></var>, <var>Y<sub>i,1</sub></var>, <var>X<sub>i,2</sub></var>, <var>Y<sub>i,2</sub></var> <= 100,000,000). <var>(X<sub>i,1</sub>, Y<sub>i,1</sub>)</var> and <var>(X<sub>i,2</sub>, Y<sub>i,2</sub>)</var> represent the coordinates of the lower-left and upper-right corners of the obstacle respectively. As usual, <var>X</var>-axis and <var>Y</var>-axis go right and upward respectively.</p> <p>No pair of obstacles overlap.</p> <h2>Output</h2> <p>Print the number of points the mouse could hide the dried fish. You can assume this number is positive (i.e. nonzero).</p> <h2>Sample Input 1</h2> <pre>4 0 0 2 1 3 0 4 2 0 2 1 4 2 3 4 4</pre> <h2>Output for the Sample Input 1</h2> <pre>4</pre> <h2>Sample Input 2</h2> <pre>8 0 0 2 1 2 2 4 3 5 3 7 4 7 5 9 6 0 2 1 4 2 4 3 6 6 0 7 2 8 2 9 4</pre> <h2>Output for the Sample Input 2</h2> <pre>8</pre>
p03050
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke received a positive integer <var>N</var> from Takahashi. A positive integer <var>m</var> is called a <em>favorite number</em> when the following condition is satisfied:</p> <ul> <li>The quotient and remainder of <var>N</var> divided by <var>m</var> are equal, that is, <var>\lfloor \frac{N}{m} \rfloor = N \bmod m</var> holds.</li> </ul> <p>Find all favorite numbers and print the sum of those.</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^{12}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </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>8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p>There are two favorite numbers: <var>3</var> and <var>7</var>. Print the sum of these, <var>10</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2499686339916 </pre> <p>Watch out for overflow.</p></section> </div> </span>
p02092
<h2>E: Red Black Balloons</h2> <h3>Story</h3> <p>Homura-chan's dream comes true. It means ICPC Asia regional contest 20xx will be held in Sapporo! Homura-chan has been working hard for the preparation. And finally, it's the previous day of the contest. Homura-chan started to stock balloons to be delivered to contestants who get accepted. However, she noticed that there were only two colors of balloons: red and black.</p> <h3>Problem Statement</h3> <p>ICPC Asia regional contest in Sapporo plans to provide <var>N</var> problems to contestants. Homura-chan is a professional of contest preparation, so she already knows how many contestants would get acceptance for each problem (!!), <var>a_i</var> contestants for the <var>i</var>-th problem. You can assume the prediction is perfectly accurate. Ideally, Homura-chan would assign a distinct color of a balloon to each problem respectively. But you know, she has only two colors red and black now. Thus, Homura-chan comes up with the idea to differentiate the size of balloons in <b><var>K</var> levels</b>, that is, each problem has a balloon with a distinct pair of (color, size).</p> <p>Homura-chan now has <var>r_i</var> red balloons with size <var>i</var> (<var>1 \leq i \leq K</var>) and <var>b_j</var> black balloons with size <var>j</var> (<var>1 \leq j \leq K</var>). Suppose we assign a pair <var>(c_i, s_i)</var> of a color <var>c_i</var> (red or black) and a size <var>s_i</var> to the <var>i</var>-th problem, for each <var>i</var>. As noted, we have to assign distinct pairs to each problem, more precisely, <var>(c_i, s_i) \neq (c_j, s_j)</var> holds for <var>i \neq j</var>. Moreover, the number of balloons with <var>(c_i, s_i)</var> must be no less than <var>a_i</var>. In the case that there are no such assignments, Homura-chan can change the size of balloons by her magic power. Note that Homura-chan doesn't know magic to change the color of balloons, so it's impossible.</p> <p>Your task is to write a program computing the minimum number of balloons whose size is changed by Homura-chan's magic to realize an assignment satisfying the above-mentioned conditions. If there is no way to achieve such an assignment even if Homura-chan changes the size of balloons infinitely, output <code>-1</code> instead.</p> <h3>Input</h3> <pre> <var>N</var> <var>K</var> <var>a_1 ... a_N</var> <var>r_1 ... r_K</var> <var>b_1 ... b_K</var> </pre> <h3>Constraints</h3> <ul> <li> <var>1 \leq N,K \leq 60</var></li> <li> <var>N \leq 2K</var></li> <li> <var>1 \leq a_i \leq 50</var> <var>(1 \leq i \leq N) </var></li> <li> <var>1 \leq r_j,b_j \leq 50</var> <var>(1 \leq j \leq K) </var></li> <li> Inputs consist only of integers.</li> </ul> <h3>Output</h3> <p>Output the minimum number of balloons whose size is changed to achieve an assignment in a line. If there are no ways to achieve assignments, output <code>-1</code> instead.</p> <h3>Sample Input 1</h3> <pre> 3 2 6 5 4 8 1 7 1 </pre> <h3>Output for Sample Input 1</h3> <pre>3</pre> <p>Homura-chan changes the size of three red balloons from 1 to 2. Then she can assign (black,1) to the problem 1, (red,1) to the problem 2, and (red,2) to the problem 3.</p> <h3>Sample Input 2</h3> <pre> 2 1 50 50 2 3 </pre> <h3>Output for Sample Input 2</h3> <pre>-1</pre> <h3>Sample Input 3</h3> <pre> 4 3 3 10 28 43 40 18 2 26 7 11 </pre> <h3>Output for Sample Input 3</h3> <pre>5</pre>
p02568
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an array <var>a_0, a_1, ..., a_{N-1}</var> of length <var>N</var>. Process <var>Q</var> queries of the following types.</p> <ul> <li><code>0 l r b c</code>: For each <var>i = l, l+1, \dots, {r - 1}</var>, set <var>a_i \gets b \times a_i + c</var>.</li> <li><code>1 l r</code>: Print <var>\sum_{i = l}^{r - 1} a_i \bmod 998244353</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N, Q \leq 500000</var></li> <li><var>0 \leq a_i, c &lt; 998244353</var></li> <li><var>1 \leq b &lt; 998244353</var></li> <li><var>0 \leq l &lt; r \leq N</var></li> <li>All values in Input are integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>a_0</var> <var>a_1</var> ... <var>a_{N - 1}</var> <var>\textrm{Query}_0</var> <var>\textrm{Query}_1</var> : <var>\textrm{Query}_{Q - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query of the latter type, print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 7 1 2 3 4 5 1 0 5 0 2 4 100 101 1 0 3 0 1 3 102 103 1 2 5 0 2 5 104 105 1 0 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>15 404 41511 4317767 </pre></section> </div> </span>
p00555
<h1>䌑憩スペヌス (Refreshment Area)</h1> <h2>問題</h2> <p> 䞖界的なプログラミングコンテストが日本で開催されるこずになり珟圚䌚堎の蚭営が行われおいるこの䌚堎は南北方向に N マス東西方向に M マスのマス目状に区切られおおりいく぀かのマスには競技甚の機材が眮かれおいる </p> <p> このコンテストでは遞手が競技䞭に䌑憩するために軜食や飲み物などを眮いた䌑憩スペヌスを 1 箇所䌚堎内に蚭けるこずになった䌑憩スペヌスは南北方向たたは東西方向に連続した D マスでなければならないただし機材の眮かれたマス目に䌑憩スペヌスを蚭けるこずはできない </p> <p> 䌚堎内に䌑憩スペヌスを蚭ける方法は䜕通りあるかを求めるプログラムを䜜成せよ </p> <h2>入力</h2> <p> 入力は 1 + N 行からなる </p> <p> 1 行目には 3 個の敎数 N, M, D (1 ≩ N ≩ 100, 1 ≩ M ≩ 100, 2 ≩ D ≩ 100) が空癜を区切りずしお曞かれおおり䌚堎が南北方向に N マス東西方向に M マスのマス目状に区切られおおり䌑憩スペヌスが南北方向たたは東西方向に連続した D マスからなるこずを衚す </p> <p> 続く N 行にはそれぞれ M 文字からなる文字列が曞かれおおり䌚堎の情報を衚す N 行のうちの i 行目の j 文字目 (1 ≩ i ≩ N, 1 ≩ j ≩ M) は䌚堎のマス目の北から i 行目西から j 列目のマスの状態を衚す '#' たたは '.' のいずれかの文字である'#' はそのマスに機材が眮かれおいるこずを'.' はそのマスに機材が眮かれおいないこずを衚す </p> <h2>出力</h2> <p> 䌚堎内に䌑憩スペヌスを蚭ける方法は䜕通りあるかを 1 行で出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 3 5 2 ...#. #...# ....# </pre> <h3>出力䟋 1</h3> <pre> 12 </pre> <br/> <h3>入力䟋 2</h3> <pre> 4 7 5 .#..... .....## ....... #...... </pre> <h3>出力䟋 2</h3> <pre> 7 </pre> <p> 入出力䟋 1 では䞋の図に瀺すように䌑憩スペヌスを蚭ける方法は党郚で 12 通りある </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_2017-yo-t3-fig01" width="600" alt="picture" width="900"> </center> <br/> <br/> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2016/2017-yo/index.html">情報オリンピック日本委員䌚䜜 『第 16 回日本情報オリンピック JOI 2016/2017 予遞競技課題』</a> </p> </div>
p02138
<h1>Problem B: U&amp;U</h1> <h2>Problem</h2> <p> $2$぀のチヌム、チヌムUKUずチヌムうしがある。最初、チヌムUKUには$N$人、チヌムうしには$M$人の人がいる。 チヌムUKUずチヌムうしは「U&amp;U」ずいうゲヌムを行うこずにした。「U&amp;U」は$2$぀のチヌムで共通のスコアを持っおおり、互いに協力しあい共通のスコアを最小化するこずが目的である。「U&amp;U」は最初、すべおの人の䜓力が$2$で、共通のスコアは$0$の状態で以䞋のような手順で進められる。 </p> <ol> <li>チヌムUKUの人は1人ず぀、チヌムうしの誰か$1$人に察しおちょうど$1$回の攻撃を行う。 攻撃を受けた人は䜓力が$1$枛り、䜓力が$0$になった堎合そのチヌムから抜ける。 このずきチヌムうしの人数が$0$人になったら、ゲヌムを終了する。 チヌムUKUのすべおの人がちょうど$1$回の攻撃を終えた時点でゲヌムが終了しおなければ共通のスコアに$1$が加算され、$2$.に進む </li> <li> 同様に、チヌムうしの人が$1$人ず぀、チヌムUKUの誰か$1$人に察しおちょうど$1$回の攻撃を行う。 攻撃を受けた人は䜓力が$1$枛り、䜓力が$0$になった堎合そのチヌムから抜ける。 このずきチヌムUKUの人数が$0$人になったら、ゲヌムを終了する。 チヌムうしのすべおの人がちょうど$1$回の攻撃を終えた時点でゲヌムが終了しおなければ共通のスコアに$1$が加算され、$1$.に戻る </li> </ol> <p> チヌムUKUの人数ずチヌムうしの人数が䞎えられたずき、「U&amp;U」ゲヌム終了時の共通のスコアずしおありえるものの最小倀をもずめよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $M$ </pre> <p> チヌムUKUの人数を衚す敎数$N$ずチヌムうしの人数を衚す敎数$M$が空癜区切りで䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \le N, M \le 10^{18}$</li> <li>$N$ず$M$は敎数</li> </ul> <h2>Output</h2> <p>最小のスコアを$1$行に出力せよ。</p> <h2>Sample Input 1</h2> <pre> 20 10 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <h2>Sample Input 2</h2> <pre> 10 20 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre> <h2>Sample Input 3</h2> <pre> 64783 68943 </pre> <h2>Sample Output 3</h2> <pre> 4 </pre> <h2>Sample Input 4</h2> <pre> 1000000000000000000 1000000000000000000 </pre> <h2>Sample Output 4</h2> <pre> 2 </pre>
p00105
<H1>Book Index</H1> <p> Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers. </p> <p> You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once. </p> <p> The words should be printed in alphabetical order and the page numbers should be printed in ascending order. </p> <!-- <p> 本の最埌には玢匕が蚭けられおいたす。本の䞭から抜出された「語句」ず「ペヌゞ番号」の組を読み取り、本の玢匕ずしお「語句」ずその語句が衚れる「ペヌゞ番号のリスト」を出力しお終了するプログラムを䜜成しお䞋さい。ただし、1぀の語句の長さは30文字以内ずし、ペヌゞ番号は1,000以䞋ずしたす。入力に含たれる語句ずペヌゞ番号の組は100以䞋ずし、1぀の語句は同じペヌゞ番号に耇数回珟れないものずしたす。たた、出力に関しおは、語句の順番はアルファベット順ずし、ペヌゞ番号は小さい順(昇順)ずしたす。 </p> --> <H2>Input</H2> <pre> <i>word page_number</i> : : </pre> <H2>Output</H2> <pre> <i>word</i> <i>a_list_of_the_page_number</i> <i>word</i> <i>a_list_of_the_Page_number</i> : : </pre> <H2>Sample Input</H2> <pre> style 12 even 25 introduction 3 easy 9 style 7 document 13 style 21 even 18 </pre> <H2>Output for the Sample Input</H2> <pre> document 13 easy 9 even 18 25 introduction 3 style 7 12 21 </pre> </div>
p02991
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ken loves <em>ken-ken-pa</em> (Japanese version of hopscotch). Today, he will play it on a directed graph <var>G</var>. <var>G</var> consists of <var>N</var> vertices numbered <var>1</var> to <var>N</var>, and <var>M</var> edges. The <var>i</var>-th edge points from Vertex <var>u_i</var> to Vertex <var>v_i</var>.</p> <p>First, Ken stands on Vertex <var>S</var>. He wants to reach Vertex <var>T</var> by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.</p> <p>Determine if he can reach Vertex <var>T</var> by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex <var>T</var>. Note that visiting Vertex <var>T</var> in the middle of a ken-ken-pa does not count as reaching Vertex <var>T</var> by repeating ken-ken-pa.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>0 \leq M \leq \min(10^5, N (N-1))</var></li> <li><var>1 \leq u_i, v_i \leq N(1 \leq i \leq M)</var></li> <li><var>u_i \neq v_i (1 \leq i \leq M)</var></li> <li>If <var>i \neq j</var>, <var>(u_i, v_i) \neq (u_j, v_j)</var>.</li> <li><var>1 \leq S, T \leq N</var></li> <li><var>S \neq T</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>u_1</var> <var>v_1</var> <var>:</var> <var>u_M</var> <var>v_M</var> <var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Ken cannot reach Vertex <var>T</var> from Vertex <var>S</var> by repeating ken-ken-pa, print <var>-1</var>. If he can, print the minimum number of ken-ken-pa needed to reach vertex <var>T</var>.</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 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Ken can reach Vertex <var>3</var> from Vertex <var>1</var> in two ken-ken-pa, as follows: <var>1 \rightarrow 2 \rightarrow 3 \rightarrow 4</var> in the first ken-ken-pa, then <var>4 \rightarrow 1 \rightarrow 2 \rightarrow 3</var> in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 2 2 3 3 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>Any number of ken-ken-pa will bring Ken back to Vertex <var>1</var>, so he cannot reach Vertex <var>2</var>, though he can pass through it in the middle of a ken-ken-pa.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 0 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre> <p>Vertex <var>S</var> and Vertex <var>T</var> may be disconnected.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 8 1 2 2 3 3 4 4 5 5 1 1 4 1 5 4 6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>2 </pre></section> </div> </span>
p03683
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has <var>N</var> dogs and <var>M</var> monkeys. He wants them to line up in a row.</p> <p>As a Japanese saying goes, these dogs and monkeys are on bad terms. <em>("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)</em> Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.</p> <p>How many such arrangements there are? Find the count modulo <var>10^9+7</var> (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N,M ≀ 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>N</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible arrangements, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>We will denote the dogs by <code>A</code> and <code>B</code>, and the monkeys by <code>C</code> and <code>D</code>. There are eight possible arrangements: <code>ACBD</code>, <code>ADBC</code>, <code>BCAD</code>, <code>BDAC</code>, <code>CADB</code>, <code>CBDA</code>, <code>DACB</code> and <code>DBCA</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>12 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>530123477 </pre></section> </div> </span>
p01344
<H1><font color="#000">Problem F: </font> Bouldering</H1> <p> Bouldering is a style of rock climbing. Boulderers are to climb up the rock with bare hands without supporting ropes. Your friend supposed that it should be interesting and exciting, so he decided to come to bouldering gymnasium to practice bouldering. Since your friend has not tried bouldering yet, he chose beginner’s course. However, in the beginner’s course, he found that some of two stones have too distant space between them, which might result his accidentally failure of grabbing certain stone and falling off to the ground and die! He gradually becomes anxious and wonders whether the course is actually for the beginners. So, he asked you to write the program which simulates the way he climbs up and checks whether he can climb up to the goal successfully. </p> <p> For the sake of convenience, we assume that a boulderer consists of 5 line segments, representing his body, his right arm, his left arm, his right leg, and his left leg. </p> <p> One of his end of the body is connected to his arms on their end points. And the other end of the body is connected to his legs on their end points, too. The maximum length of his body, his arms, and his legs are <i>A</i>, <i>B</i> and <i>C</i> respectively. He climbs up the wall by changing the length of his body parts from 0 to their maximum length, and by twisting them in any angle (in other word, 360 degrees). Refer the following figure representing the possible body arrangements. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bouldering1"><br> <b>Figure 2: An example of possible body arrangements.</b> </center> <P> 5 line segments representing his body, arms and legs. The length of his body, arms and legs are 8, 3 and 4 respectively. The picture describes his head as a filled circle for better understanding, which has no meaning in this problem. </p> <p> A boulderer climbs up the wall by grabbing at least three different rocks on the wall with his hands and feet. In the initial state, he holds 4 rocks with his hands and feet. Then he changes one of the holding rocks by moving his arms and/or legs. This is counted as one movement. His goal is to grab a rock named “destination rock” with one of his body parts. The rocks are considered as points with negligible size. You are to write a program which calculates the minimum number of movements required to grab the destination rock. </p> <H2>Input</H2> <p> The input data looks like the following lines: </p> <p> <i>n</i><br> <i>A B C</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub><br> <i>x</i><sub>3</sub> <i>y</i><sub>3</sub><br> .<br> .<br> .<br> <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub><br> </p> <p> The first line contains <i>n</i> (5 &le; <i>n</i> &le; 30), which represents the number of rocks. </p> <p> The second line contains three integers <i>A</i>, <i>B</i>, <i>C</i> (1 &le; <i>A</i>, <i>B</i>, <i>C</i> &le; 50), which represent the length of body, arms, and legs of the climber respectively. </p> <p> The last <i>n</i> lines describes the location of the rocks. The <i>i</i>-th contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> (0 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> &le; 100), representing the <i>x</i> and <i>y</i>-coordinates of the <i>i</i>-th rock. </p> <p> In the initial state, the boulderer is grabbing the 1st rock with his right hand, 2nd with his left hand, 3rd with his right foot, and 4th with left foot. </p> <p> You may assume that the first 4 rocks are close to each other so that he can grab them all in the way described above. </p> <p> The last rock is the destination rock. </p> <H2>Output</H2> <p> Your program should output the minimum number of movements to reach the destination stone. </p> <p> If it is impossible to grab the destination stone, output -1. </p> <p> You may assume that, if <i>A</i>, <i>B</i>, <i>C</i> would be changed within 0.001, the answer would not change. </p> <p> Following figures represent just an example of how the boulderer climbs up to the destination in minimum number of movements. Note that the minimum number of movements can be obtained, by taking different way of climbing up, shortening the parts, rotating parts etc. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bouldering2"><br> <b>Figure 3: An example of minimum movement for sample input 1.</b> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bouldering3"><br> <b>Figure 4: An example of minimum movement for sample input 2.</b> </center> <H2>Sample Input 1</H2> <pre> 6 4 3 3 10 17 15 14 10 15 11 12 16 18 15 22 </pre> <H2>Output for the Sample Input 1</H2> <pre> 3 </pre> <H2>Sample Input 2</H2> <pre> 7 4 2 4 11 18 14 18 10 14 13 14 14 17 17 21 16 26 </pre> <H2>Output for the Sample Input 2</H2> <pre> 3 </pre> <H2>Sample Input 3</H2> <pre> 6 2 2 4 12 22 13 21 14 15 10 16 16 24 10 35 </pre> <H2>Output for the Sample Input 3</H2> <pre> -1 </pre> <H2>Sample Input 4</H2> <pre> 6 2 3 3 11 22 12 20 10 15 11 17 13 23 16 22 </pre> <H2>Output for the Sample Input 4</H2> <pre> -1 </pre>
p03379
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>When <var>l</var> is an odd number, the median of <var>l</var> numbers <var>a_1, a_2, ..., a_l</var> is the <var>(\frac{l+1}{2})</var>-th largest value among <var>a_1, a_2, ..., a_l</var>.</p> <p>You are given <var>N</var> numbers <var>X_1, X_2, ..., X_N</var>, where <var>N</var> is an even number. For each <var>i = 1, 2, ..., N</var>, let the median of <var>X_1, X_2, ..., X_N</var> excluding <var>X_i</var>, that is, the median of <var>X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N</var> be <var>B_i</var>.</p> <p>Find <var>B_i</var> for each <var>i = 1, 2, ..., N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200000</var></li> <li><var>N</var> is even.</li> <li><var>1 \leq X_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>X_1</var> <var>X_2</var> ... <var>X_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 <var>B_i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 3 3 4 </pre> <ul> <li>Since the median of <var>X_2, X_3, X_4</var> is <var>4</var>, <var>B_1 = 4</var>.</li> <li>Since the median of <var>X_1, X_3, X_4</var> is <var>3</var>, <var>B_2 = 3</var>.</li> <li>Since the median of <var>X_1, X_2, X_4</var> is <var>3</var>, <var>B_3 = 3</var>.</li> <li>Since the median of <var>X_1, X_2, X_3</var> is <var>4</var>, <var>B_4 = 4</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 5 5 4 4 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 4 4 4 4 4 </pre></section> </div> </span>
p00806
<H1><font color="#000">Problem D:</font> 77377</H1> <p> At the risk of its future, International Cellular Phones Corporation (ICPC) invests its resources in developing new mobile phones, which are planned to be equipped with Web browser, mailer, instant messenger, and many other advanced communication tools. Unless members of ICPC can complete this stiff job, it will eventually lose its market share. </p> <p> You are now requested to help ICPC to develop intriguing text input software for small mobile terminals. As you may know, most phones today have twelve buttons, namely, ten number buttons from "<span>0</span>" to "<span>9</span>" and two special buttons "<span>*</span>" and "<span>#</span>". Although the company is very ambitious, it has decided to follow today's standards and conventions. You should not change the standard button layout, and should also pay attention to the following standard button assignment. </p> <table border=0> <tr> <td width="80">button</td><td width="80"> letters</td><td width="80"> button </td><td width="80">letters</td> </tr> <tr> <td>2 </td><td> a, b, c </td><td> 6 </td><td> m, n, o</td> </tr> <tr> <td>3 </td><td> d, e, f </td><td> 7 </td><td> p, q, r, s</td> </tr> <tr> <td>4 </td><td> g, h, i </td><td>8 </td><td> t, u, v</td> </tr> <tr> <td>5 </td><td> j, k, l </td><td> 9 </td><td> w, x, y, z</td> </tr> </table> <p> This means that you can only use eight buttons for text input. </p> <p> Most users of current ICPC phones are rushed enough to grudge wasting time on even a single button press. Your text input software should be economical of users' time so that a single button press is suffcient for each character input. In consequence, for instance, your program should accept a sequence of button presses "<span>77377</span>" and produce the word "<span>press</span>". Similarly, it should translate "<span>77377843288866</span>" into "press the button". </p> <p> Ummm... It seems impossible to build such text input software since more than one English letter is represented by a digit!. For instance, "<span>77377</span>" may represent not only "press" but also any one of 768 (= 4 &times; 4 &times; 3 &times; 4 &times; 4) character strings. However, we have the good news that the new model of ICPC mobile phones has enough memory to keep a dictionary. You may be able to write a program that filters out <i>false words</i>, i.e., strings not listed in the dictionary. </p> <H2>Input</H2> <p> The input consists of multiple data sets, each of which represents a dictionary and a sequence of button presses in the following format. </p> <pre> <i>n</i> <i>word</i><sub>1</sub> . . . <i>word<sub>n</sub></i> <i>sequence</i> </pre> <p> <i>n</i> in the first line is a positive integer, representing the number of words in the dictionary. The next <i>n</i> lines, each representing a word in the dictionary, only contain lower case letters from `<span>a</span>' to `<span>z</span>'. The order of words in the dictionary is arbitrary (not necessarily in the lexicographic order). No words occur more than once in the dictionary. The last line, sequence, is the sequence of button presses, and only contains digits from `<span>2</span>' to `<span>9</span>'. </p> <p> You may assume that a dictionary has at most one hundred words and that the length of each word is between one and fifty, inclusive. You may also assume that the number of input digits in the <i>sequence</i> is between one and three hundred, inclusive. </p> <p> A line containing a zero indicates the end of the input. </p> <H2>Output</H2> <p> For each data set, your program should print all sequences that can be represented by the input sequence of button presses. Each sequence should be a sequence of words in the dictionary, and should appear in a single line. The order of lines does not matter. </p> <p> Two adjacent words in a line should be separated by a single space character and the last word should be followed by a single period (`<span>.</span>'). </p> <p> Following those output lines, your program should also print a terminating line consisting solely of two hyphens (`<span>--</span>'). If there are no corresponding sequences of words, your program should only print the terminating line. </p> <p> You may assume that for each data set the number of output lines is at most twenty, excluding the terminating line. </p> <H2>Sample Input</H2> <pre> 5 push press the button bottom 77377843288866 4 i am going go 42646464 3 a b c 333 0 </pre> <H2>Output for the Sample Input</H2> <pre> press the button. -- i am going. i am go go i. -- -- </pre>
p01714
<h1>問題 C : Apples </h1> <h2>問題文</h2> <p> あるずころに銃の腕に自信をも぀猟垫がいたした 猟垫はある日「りィリアムテルずいうスむス人が息子の頭にりんごを乗せお遠くから矢で撃ち萜ずすパフォヌマンスで有名になった」ずいうお話を聞きたした それを聞いお"自分のほうがもっず凄い!!"ず思った猟垫は動いおいる人の䞊にりんごを乗せお撃ちぬくパフォヌマンスを考え぀きたした </p> <p> 猟垫は広堎に <var>N</var> 人の人を集めそれぞれの人の䞊にりんごを乗せたした <var>i</var> 番目の人は時刻 <var>t=0</var> のずき座暙 <var>(x_i, &thinsp;y_i)</var> にいたす そこから単䜍時間あたり速床ベクトル <var>(u_i,&thinsp; v_i)</var> にしたがっお歩きたす すなわち時刻 <var>t &thinsp;&ge;&thinsp; 0</var> のずき<var>i</var> 番目の人は座暙 <var>(x_i + t \times u_i &thinsp;, &ensp; y_i + t \times v_i)</var> にいたす ここで人々は十分小さいので同じ座暙に耇数の人がいたり同じ座暙ですれ違ったりできるず仮定したす </p> <p> 猟垫は人々を驚嘆させるために䞀発の匟䞞でできるだけ倚くのりんごを撃ち萜ずすこずにしたした 猟垫は <var>t &ge; 0</var> であるような任意の時刻に任意の座暙から任意の方向に向けお匟䞞を攟぀こずができたす 攟たれた匟䞞は無限の速さで盎線軌道で移動しりんごに圓たった堎合貫通しお移動したす 匟䞞を䞀発だけ打぀ずき最倧で䜕個のりんごを撃ち萜ずせるか蚈算しおください </p> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる <pre> <var>N</var> <var>x_0</var> <var>y_0</var> <var>u_0</var> <var>v_0</var> <var>...</var> <var>x_{N-1}</var> <var>y_{N-1}</var> <var>u_{N-1}</var> <var>v_{N-1}</var> </pre> <h2>出力圢匏</h2> <p> 撃ち萜ずせるりんごの最倧個数を1行に出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; N &le; 200</var></li> <li><var>0 &le; &thinsp; |x_i|, &thinsp; |y_i| &thinsp; &le; 10</var></li> <li><var>0 &le; &thinsp; |u_i|, &thinsp; |v_i| &thinsp; &le; 3</var></li> <li>入力倀はすべお敎数である。</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 5 0 0 0 0 1 0 -1 1 -1 0 1 -1 1 1 -1 1 -1 -1 1 -1 </pre> <h3>出力䟋 1</h3> <pre> 5 </pre> <p> 時刻に人が軞䞊に䞊ぶので最倧぀のりんごを撃ち萜ずせる </p> <h3>入力䟋 2</h3> <pre> 5 0 0 0 0 1 0 1 0 -1 0 -1 0 1 1 1 1 -1 -1 -1 -1 </pre> <h3>出力䟋 2</h3> <pre> 3 </pre> <h3>入力䟋 3</h3> <pre> 15 -10 9 2 1 2 10 0 -1 -10 -4 0 -3 -2 8 0 -1 0 -10 -1 -2 -8 5 0 -1 -7 -8 -3 1 10 -6 -2 -3 9 -6 1 0 10 -5 3 1 10 1 0 -3 -4 7 0 -1 10 -9 2 2 2 -5 -1 1 9 -10 3 1 </pre> <h3>出力䟋 3</h3> <pre> 5 </pre>
p03729
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given three strings <var>A</var>, <var>B</var> and <var>C</var>. Check whether they form a <em>word chain</em>.</p> <p>More formally, determine whether both of the following are true:</p> <ul> <li>The last character in <var>A</var> and the initial character in <var>B</var> are the same.</li> <li>The last character in <var>B</var> and the initial character in <var>C</var> are the same.</li> </ul> <p>If both are true, print <code>YES</code>. Otherwise, print <code>NO</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>A</var>, <var>B</var> and <var>C</var> are all composed of lowercase English letters (<code>a</code> - <code>z</code>).</li> <li><var>1 ≀ |A|, |B|, |C| ≀ 10</var>, where <var>|A|</var>, <var>|B|</var> and <var>|C|</var> are the lengths of <var>A</var>, <var>B</var> and <var>C</var>, respectively.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>YES</code> or <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>rng gorilla apple </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>They form a word chain.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>yakiniku unagi sushi </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p><var>A</var> and <var>B</var> form a word chain, but <var>B</var> and <var>C</var> do not.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>a a a </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>aaaaaaaaab aaaaaaaaaa aaaaaaaaab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>NO </pre></section> </div> </span>
p01201
<H1><font color="#000"></font>Exact Arithmetic</H1> <!-- Problem H --> <p> Let <i>X</i> be a set of all rational numbers and all numbers of form <i>q</i>&radic;<i>r</i>, where <i>q</i> is a non-zero rational number and <i>r</i> is an integer greater than 1. Here <i>r</i> must not have a quadratic number except for 1 as its divisor. Also, let <i>X</i><sup>*</sup> be a set of all numbers which can be expressed as a sum of one or more elements in <i>X</i>. </p> <p> A machine <i>Y</i> is a stack-based calculator which operates on the values in <i>X</i><sup>*</sup> and has the instructions shown in the table below. </p> <center> <table border="1" cellspacing="0" cellpadding="4"> <tr> <td><p>push <i>n</i></p></td> <td><p>Pushes an integer specified in the operand onto the stack.</p></td> </tr> <tr> <td><p>add</p></td> <td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> + <i>x</i><sub>1</sub>).</p></td> </tr> <tr> <td><p>sub</p></td> <td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> - <i>x</i><sub>1</sub> ).</p></td> </tr> <tr> <td><p>mul</p></td> <td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> &times <i>x</i><sub>1</sub> ). </p></td> </tr> <tr> <td><p>div</p></td> <td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> &divide; <i>x</i><sub>1</sub>). <i>x</i><sub>1</sub> must be a non-zero value in <i>X</i> (<i>not</i> <i>X</i><sup>*</sup>). </p></td> </tr> <tr> <td><p>sqrt</p></td> <td><p>Pops one value <i>x</i> from the stack and pushes the square root of <i>x</i>. <i>x</i> must be a non-negative rational number. </p></td> </tr> <tr> <td><p>disp</p></td> <td><p>Pops one value <i>x</i> from the stack, and outputs the string representation of the value <i>x</i> to the display. The representation rules are stated later. </p></td> </tr> <tr> <td><p>stop</p></td> <td><p>Terminates calculation. The stack must be empty when this instruction is called. </p></td> </tr> </table> <p>Table 1: Instruction Set for the Machine Y</p> </center> <p> A sufficient number of values must exist in the stack on execution of every instruction. In addition, due to the limitation of the machine Y, no more values can be pushed when the stack already stores as many as 256 values. Also, there exist several restrictions on values to be pushed onto the stack: </p> <ul> <li> For rational numbers, neither numerator nor denominator in the irreducible form may exceed 32,768 in its absolute value.</li> <li> For any element in <i>X</i> of the form <i>q</i>&radic;<i>r</i> = (<i>a</i>/<i>b</i>)&radic;<i>r</i>, |<i>a</i>&radic;<i>r</i>| &le; 32,768 and |<i>b</i>| &le; 32,768.</li> <li> For any element in <i>X</i><sup>*</sup>, each term in the sum must satisfy the above conditions. </ul> <p> The rules for the string representations of the values (on the machine Y) are as follows: </p> <ul> <li> A rational number is represented as either an integer or an irreducible fraction with a denominator greater than 1. A fraction is represented as "&lt;<i>numerator</i>&gt;/&lt;<i>denominator</i>&gt;". A sign symbol - precedes in case of a negative number.</li> <li> A number of the form <i>q</i>&radic;<i>r</i> is represented as "&lt;<i>string representation of q</i>&gt;<sup>*</sup>sqrt(<i>r</i>)" except for the case with <i>q</i> = &plusmn;1, in which the number is represented as "sqrt(<i>r</i>)" (<i>q</i> = 1) or "-sqrt(<i>r</i>)" (<i>q</i> = -1).</li> <li> For the sum of two or more elements of <i>X</i>, string representations of all the (non-zero) elements are con- nected using the binary operator +. In this case, all terms with the same rooted number are merged into a single term, and the terms must be shown in the ascending order of its root component. For the purpose of this rule, all rational numbers are regarded to accompany &radic;1.</li> <li> There is exactly one space character before and after each of the binary operator +. No space character appears at any other place.</li> </ul> <p> The followings are a few examples of valid string representations: </p> <pre> 0 1 -1/10 2*sqrt(2) + 1/2*sqrt(3) + -1/2*sqrt(5) 1/2 + sqrt(10) + -sqrt(30) </pre> <p> Your task is to write a program that simulates the machine Y. </p> <H2>Input</H2> <p> The input is a sequence of instructions. Each line contains a single instruction. You may assume that every instruction is called in a legal way. The instruction stop appears only once, at the end of the entire input. </p> <H2>Output</H2> <p> Output the strings which the machine Y will display. Write each string in a line. </p> <H2>Sample Input</H2> <pre> push 1 push 2 sqrt div push 1 push 3 sqrt div add disp push 8 sqrt push 3 push 2 sqrt mul add disp stop </pre> <H2>Output for the Sample Input</H2> <pre> 1/2*sqrt(2) + 1/3*sqrt(3) 5*sqrt(2) </pre>
p04003
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke's town has a subway system, consisting of <var>N</var> stations and <var>M</var> railway lines. The stations are numbered <var>1</var> through <var>N</var>. Each line is operated by a company. Each company has an identification number.</p> <p>The <var>i</var>-th ( <var>1 \leq i \leq M</var> ) line connects station <var>p_i</var> and <var>q_i</var> bidirectionally. There is no intermediate station. This line is operated by company <var>c_i</var>.</p> <p>You can change trains at a station where multiple lines are available.</p> <p>The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is <var>1</var> yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of <var>1</var> yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.</p> <p>Snuke is now at station <var>1</var> and wants to travel to station <var>N</var> by subway. Find the minimum required fare.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>0 \leq M \leq 2×10^5</var></li> <li><var>1 \leq p_i \leq N</var> <var>(1 \leq i \leq M)</var></li> <li><var>1 \leq q_i \leq N</var> <var>(1 \leq i \leq M)</var></li> <li><var>1 \leq c_i \leq 10^6</var> <var>(1 \leq i \leq M)</var></li> <li><var>p_i \neq q_i</var> <var>(1 \leq i \leq M)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>p_1</var> <var>q_1</var> <var>c_1</var> : <var>p_M</var> <var>q_M</var> <var>c_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum required fare. If it is impossible to get to station <var>N</var> by subway, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 1 2 3 1 3 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Use company <var>1</var>'s lines: <var>1</var> → <var>2</var> → <var>3</var>. The fare is <var>1</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 11 1 3 1 1 4 2 2 3 1 2 5 1 3 4 3 3 6 3 3 7 3 4 8 4 5 6 1 6 7 5 7 8 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>First, use company <var>1</var>'s lines: <var>1</var> → <var>3</var> → <var>2</var> → <var>5</var> → <var>6</var>. Then, use company <var>5</var>'s lines: <var>6</var> → <var>7</var> → <var>8</var>. The fare is <var>2</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre></section> </div> </span>
p00943
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem I Routing a Marathon Race</h2> <p> As a member of the ICPC (Ibaraki Committee of Physical Competitions), you are responsible for planning the route of a marathon event held in the City of Tsukuba. A great number of runners, from beginners to experts, are expected to take part. </p> <p> You have at hand a city map that lists all the street segments suited for the event and all the junctions on them. The race is to start at the junction in front of Tsukuba High, and the goal is at the junction in front of City Hall, both of which are marked on the map. </p> <p> To avoid congestion and confusion of runners of divergent skills, the route should not visit the same junction twice. Consequently, although the street segments can be used in either direction, they can be included at most once in the route. As the main objective of the event is in recreation and health promotion of citizens, time records are not important and the route distance can be arbitrarily decided. </p> <p> A number of personnel have to be stationed at every junction on the route. Junctions <i>adjacent</i> to them, i.e., junctions connected directly by a street segment to the junctions on the route, also need personnel staffing to keep casual traffic from interfering the race. The same number of personnel is required when a junction is on the route and when it is adjacent to one, but different junctions require different numbers of personnel depending on their sizes and shapes, which are also indicated on the map. </p> <p> The municipal authorities are eager in reducing the costs including the personnel expense for events of this kind. Your task is to write a program that plans a route with the minimum possible number of personnel required and outputs that number. </p> <h3>Input</h3> <p> The input consists of a single test case representing a summary city map, formatted as follows.<br> <br> $n$ $m$<br> $c_1$<br> ...<br> $c_n$<br> $i_1$ $j_1$<br> ...<br> $i_m$ $j_m$<br> <br> The first line of a test case has two positive integers, $n$ and $m$. Here, $n$ indicates the number of junctions in the map $(2 \leq n \leq 40)$, and $m$ is the number of street segments connecting adjacent junctions. Junctions are identified by integers 1 through $n$. </p> <p> Then comes $n$ lines indicating numbers of personnel required. The $k$-th line of which, an integer $c_k$ $(1 \leq c_k \leq 100)$, is the number of personnel required for the junction $k$. </p> <p> The remaining $m$ lines list street segments between junctions. Each of these lines has two integers $i_k$ and $j_k$, representing a segment connecting junctions $i_k$ and $j_k$ $(i_k \ne j_k)$. There is at most one street segment connecting the same pair of junctions. </p> <p> The race starts at junction 1 and the goal is at junction $n$. It is guaranteed that there is at least one route connecting the start and the goal junctions. </p> <h3>Output</h3> <p> Output an integer indicating the minimum possible number of personnel required. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_RoutingAMarathonRace"><br> <p> Figure I.1. The Lowest-Cost Route for Sample Input 1 </p> </center> <p> Figure I.1 shows the lowest-cost route for Sample Input 1. The arrows indicate the route and the circles painted gray are junctions requiring personnel assignment. The minimum number of required personnel is 17 in this case. </p> <h3>Sample Input 1</h3> <pre>6 6 3 1 9 4 3 6 1 2 1 4 2 6 5 4 6 5 3 2</pre> <h3>Sample Output 1</h3> <pre>17</pre>
p01651
<h2>Problem Statement</h2> <p> Let <var>b_i(x)</var> be the <var>i</var>-th least significant bit of <var>x</var>, i.e. the <var>i</var>-th least significant digit of <var>x</var> in base 2 (<var>i \geq 1</var>). For example, since <var>6 = (110)_2</var>, <var>b_1(6) = 0</var>, <var>b_2(6) = 1</var>, <var>b_3(6) = 1</var>, <var>b_4(6) = 0</var>, <var>b_5(6) = 0</var>, and so on. </p> <p> Let <var>A</var> and <var>B</var> be integers that satisfy <var>1 \leq A \leq B \leq 10^{18}</var>, and <var>k_i</var> be the number of integers <var>x</var> such that <var>A \leq x \leq B</var> and <var>b_i(x) = 1</var>. </p> <p> Your task is to write a program that determines <var>A</var> and <var>B</var> for a given <var>\{k_i\}</var>. </p> <h2>Input</h2> <p> The input consists of multiple datasets. The number of datasets is no more than 100,000. Each dataset has the following format: </p> <pre> <var>n</var> <var>k_1</var> <var>k_2</var> ... <var>k_n</var> </pre> <p> The first line of each dataset contains an integer <var>n</var> (<var>1 \leq n \leq 64</var>). Then <var>n</var> lines follow, each of which contains <var>k_i</var> (<var>0 \leq k_i \leq 2^{63} - 1</var>). For all <var>i &gt; n</var>, <var>k_i = 0</var>. </p> <p> The input is terminated by <var>n = 0</var>. Your program must not produce output for it. </p> <h2>Output</h2> <p> For each dataset, print one line. </p> <ul> <li> If <var>A</var> and <var>B</var> can be uniquely determined, output <var>A</var> and <var>B</var>. Separate the numbers by a single space.</li> <li> If there exists more than one possible pair of <var>A</var> and <var>B</var>, output <code>Many</code> (without quotes).</li> <li> Otherwise, i.e. if there exists no possible pair, output <code>None</code> (without quotes).</li> </ul> <h2>Sample Input</h2> <pre> 3 2 2 1 49 95351238128934 95351238128934 95351238128932 95351238128936 95351238128936 95351238128936 95351238128960 95351238128900 95351238128896 95351238129096 95351238128772 95351238129096 95351238129096 95351238126156 95351238131712 95351238131712 95351238149576 95351238093388 95351238084040 95351237962316 95351238295552 95351237911684 95351237911684 95351235149824 95351233717380 95351249496652 95351249496652 95351226761216 95351226761216 95351082722436 95351082722436 95352054803020 95352156464260 95348273971200 95348273971200 95354202286668 95356451431556 95356451431556 95346024826312 95356451431556 95356451431556 94557999988736 94256939803780 94256939803780 102741546035788 87649443431880 87649443431880 140737488355328 32684288648324 64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 11 0 0 1 1 1 0 1 1 1 1 1 63 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 4 1 1 1 1 0 </pre> <h2>Output for the Sample Input</h2> <pre> 1 4 123456789101112 314159265358979 None 2012 2012 None Many </pre>
p03396
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Yui loves shopping. She lives in Yamaboshi City and there is a train service in the city. The city can be modelled as a very long number line. Yui's house is at coordinate <var>0</var>.</p> <p>There are <var>N</var> shopping centres in the city, located at coordinates <var>x_{1}, x_{2}, ..., x_{N}</var> respectively. There are <var>N + 2</var> train stations, one located at coordinate <var>0</var>, one located at coordinate <var>L</var>, and one located at each shopping centre.</p> <p>At time <var>0</var>, the train departs from position <var>0</var> to the positive direction. The train travels at a constant speed of <var>1</var> unit per second. At time <var>L</var>, the train will reach the last station, the station at coordinate <var>L</var>. The train immediately moves in the opposite direction at the same speed. At time <var>2L</var>, the train will reach the station at coordinate <var>0</var> and it immediately moves in the opposite direction again. The process repeats indefinitely.</p> <p>When the train arrives at a station where Yui is located, Yui can board or leave the train immediately. At time <var>0</var>, Yui is at the station at coordinate <var>0</var>. </p> <p>Yui wants to go shopping in all <var>N</var> shopping centres, in any order, and return home after she finishes her shopping. She needs to shop for <var>t_{i}</var> seconds in the shopping centre at coordinate <var>x_{i}</var>. <strong>She must finish her shopping in one shopping centre before moving to the next shopping centre.</strong> Yui can immediately start shopping when she reaches a station with a shopping centre and she can immediately board the train when she finishes shopping.</p> <p>Yui wants to spend the minimum amount of time to finish her shopping. Can you help her determine the minimum number of seconds required to complete her shopping?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300000</var></li> <li><var>1 \leq L \leq 10^{9}</var></li> <li><var>0 &lt; x_{1} &lt; x_{2} &lt; ... &lt; x_{N} &lt; L</var></li> <li><var>1 \leq t_{i} \leq 10^{9}</var></li> <li>All values in the input are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>1000</var> points will be awarded for passing the testset satisfying <var>1 \leq N \leq 3000</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>L</var> <var>x_{1}</var> <var>x_{2}</var> <var>...</var> <var>x_{N}</var> <var>t_{1}</var> <var>t_{2}</var> <var>...</var> <var>t_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum time (in seconds) required for Yui to finish shopping at all <var>N</var> shopping centres and return home.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 10 5 8 10 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>40 </pre> <p>Here's one possible way for Yui to finish her shopping :</p> <ul> <li> <p>Travel to the station at coordinate <var>8</var> with the train. She arrives at coordinate <var>8</var> at time <var>8</var>.</p> </li> <li> <p>Shop in the shopping centre at coordinate <var>8</var>. She finishes her shopping at time <var>12</var>.</p> </li> <li> <p>The train arrives at coordinate <var>8</var> at time <var>12</var>. She boards the train which is currently moving in the negative direction.</p> </li> <li> <p>She arrives at coordinate <var>5</var> at time <var>15</var>. She finishes her shopping at time <var>25</var>.</p> </li> <li> <p>The train arrives at coordinate <var>5</var> at time <var>25</var>. She boards the train which is currently moving in the positive direction.</p> </li> <li> <p>She arrives at coordinate <var>L = 10</var> at time <var>30</var>. The train starts moving in the negative direction immediately.</p> </li> <li> <p>She arrives at coordinate <var>0</var> at time <var>40</var>, ending the trip.</p> </li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 10 5 8 10 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>60 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 100 10 19 28 47 68 200 200 200 200 200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1200 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 1000000000 2018 123456 1719128 1929183 9129198 10100101 77777777 120182018 99999999 1000000000 1000000000 11291341 1 200 1 123812831 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>14000000000 </pre> <p>Beware of overflow issues.</p></section> </div> </span>
p00410
<h1>ダンゞョン</h1>   <p> あなたは有名な冒険家であり、すでに぀のダンゞョンを制芇した。あなたはいく぀かの通路ず宝物庫が蚘された新たなダンゞョンの地図を入手した。地図にはそれぞれの宝物庫にある財宝の䟡倀が曞かれおいる。 </p> <p> あなたは、任意の宝物庫からダンゞョンに䟵入し、任意の宝物庫からダンゞョンを脱出するこずができる。䟵入から脱出たでの間に、通路を通っお宝物庫の間を䜕床か移動しお、蚪れた宝物庫の財宝を手に入れるこずができる。地図によれば、各通路は双方向に通るこずができ、どの宝物庫からどの宝物庫にも本以䞊の通路を経由しおたどり぀くこずができる。しかし、通路は䞀床通るず二床目以降は䞀床目ず同じ向きにしか通るこずができなくなる。宝物庫の財宝は、そこを最初に蚪れたずきだけ手に入れるこずができる。このずき、手にする財宝の䟡倀の総和を最倧にしたい。 </p> <p> 地図の情報が䞎えられたずき、䟵入から脱出たでの間に手にいれるこずのできる財宝の䟡倀の総和の最倧倀を求めるプログラムを䜜成せよ。ただし、宝物庫には1からNたでの番号が割り圓おられおいるものずする。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $N$ $M$ $v_1$ $v_2$ : $v_N$ $s_1$ $t_1$ $s_2$ $t_2$ : $s_M$ $t_M$ </pre> <p> 行目に宝物庫の数$N$ ($2 \leq N \leq 10^5$)ず通路の数$M$ ($1 \leq M \leq 2 \times 10^5$)が䞎えられる。続く$N$行に、$i$番目の宝物庫に眮かれおいる財宝の䟡倀$v_i$ ($1 \leq v_i \leq 1000$)が䞎えられる。続く$M$行に、それぞれの通路の䞡端に接続されおいる宝物庫の番号$s_i$,$t_i$ ($1 \leq s_i,t_i \leq N, s_i \ne t_i$)が䞎えられる。ただし、同じ宝物庫同士を぀なぐ通路は床以䞊䞎えられない。 </p> <h2>出力</h2> <p> 埗るこずができる財宝の䟡倀の総和の最倧倀を行に出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 5 4 2 1 3 6 4 1 2 2 3 2 4 4 5 </pre> <h3>出力䟋</h3> <pre> 14 </pre>
p00040
<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> 簡単な暗号法の䞀぀に、アフィン暗号ずいうものがありたす。たず、アルファベット a〜z を a = 0, b = 1, c = 2,..., x = 23, y = 24, z = 25 ず 0〜25 の数字に眮き換えたす。そしお、以䞋の匏で、原文のアルファベットを眮換したす。 </p> <center> <!-- <p> F(γ) = (α・γβ) mod 26 </p> --> <p> $F(\gamma) = (\alpha \cdot \gamma + \beta)$ mod $26$ </p> </center> <p> ただし、mod 26 は 26 で割った䜙りを衚したす。䟋えば、$\alpha = 3, \beta = 2$ のずき、アルファベットの 'a' (=0) は、$F(0) = (3 \cdot 0 + 2)$ mod $26 = 2$ で 'c' に、アルファベットの 'n' (=13) は $F(13) = (3 \cdot 13 + 2)$ mod $26 = 15$ で 'p' に眮換されたす。 このずき、$\gamma$ に察する $F(\gamma)$ が必ず 1 察 1 で察応付けられるように、$\alpha$ ず $\beta$ は慎重に遞ばれおいるものずしたす$\alpha$ ず 26 が互いに玠であるこずが条件。$\alpha = 4, \beta = 7$ のずきのように、$F('a') = 7, F('n') = 7$ ず、'a' も 'n' も同じ 'h' に眮換されるようなこずはありたせん。たた、アルファベット以倖の文字は眮換されたせん。 </p> <p> 暗号化された文字列を元の文章に埩号したものを出力するプログラムを䜜成しおください。元の文章には、キヌワヌドずしお </p> <pre> that this </pre> <p> のいずれかが必ず含たれおいるものずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。行目にデヌタセット数 $n$ ($n \leq 30$) が䞎えられたす。続いお $n$ 行のデヌタが䞎えられたす。各デヌタセットに英小文字ず空癜からなる 256 文字以内の暗号化された文章が行に䞎えられたす。 </p> <H2>Output</H2> <p> 各デヌタセットに察しお、埩号した元の文章を行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 1 y eazqyp pnop pngtg ye obmpngt xmybp mr lygw </pre> <H2>Output for the Sample Input</H2> <pre> i submit that there is another point of view </pre>
p02587
<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> strings of lowercase English letters: <var>S_1, S_2, \cdots, S_N</var>.</p> <p>Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of his choice.</p> <p>The cost of using the string <var>S_i</var> once is <var>C_i</var>, and the cost of using it multiple times is <var>C_i</var> multiplied by that number of times.</p> <p>Find the minimum total cost needed to choose strings so that Takahashi can make a palindrome.</p> <p>If there is no choice of strings in which he can make a palindrome, print <var>-1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>1 \leq |S_i| \leq 20</var></li> <li><var>S_i</var> consists of lowercase English letters.</li> <li><var>1 \leq C_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>S_1</var> <var>C_1</var> <var>S_2</var> <var>C_2</var> <var>:</var> <var>S_N</var> <var>C_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total cost needed to choose strings so that Takahashi can make a palindrome, or <var>-1</var> if there is no such choice.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 ba 3 abc 4 cbaa 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>We have <code>ba</code>, <code>abc</code>, and <code>cbaa</code>.</p> <p>For example, we can use <code>ba</code> once and <code>abc</code> once for a cost of <var>7</var>, then concatenate them in the order <code>abc</code>, <code>ba</code> to make a palindrome. Also, we can use <code>abc</code> once and <code>cbaa</code> once for a cost of <var>9</var>, then concatenate them in the order <code>cbaa</code>, <code>abc</code> to make a palindrome.</p> <p>We cannot make a palindrome for a cost less than <var>7</var>, so we should print <var>7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 abcab 5 cba 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>11 </pre> <p>We can choose <code>abcab</code> once and <code>cba</code> twice, then concatenate them in the order <code>abcab</code>, <code>cba</code>, <code>cba</code> to make a palindrome for a cost of <var>11</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 ab 5 cba 3 a 12 ab 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre> <p>We can choose <code>a</code> once, which is already a palindrome, but it is cheaper to concatenate <code>ab</code> and <code>cba</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 abc 1 ab 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>-1 </pre> <p>We cannot make a palindrome, so we should print <var>-1</var>.</p></section> </div> </span>
p02790
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are <var>1</var>-digit positive integers <var>a</var> and <var>b</var>. Consider these two strings: the concatenation of <var>b</var> copies of the digit <var>a</var>, and the concatenation of <var>a</var> copies of the digit <var>b</var>. Which of these is lexicographically smaller?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq a \leq 9</var></li> <li><var>1 \leq b \leq 9</var></li> <li><var>a</var> and <var>b</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3333 </pre> <p>We have two strings <code>444</code> and <code>3333</code>. Between them, <code>3333</code> is the lexicographically smaller.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7777777 </pre></section> </div> </span>
p03882
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>There are <var>N</var> cities in a two-dimensional plane. The coordinates of the <var>i</var>-th city is <var>(x_i, y_i)</var>. Initially, the amount of water stored in the <var>i</var>-th city is <var>a_i</var> liters.</p> <p>Snuke can carry any amount of water from a city to another city. However, water leaks out a bit while he carries it. If he carries <var>l</var> liters of water from the <var>s</var>-th city to the <var>t</var>-th city, only <var>max(l-d_{s,t}, 0)</var> liters of water remains when he arrives at the destination. Here <var>d_{s,t}</var> denotes the (Euclidean) distance between the <var>s</var>-th city and the <var>t</var>-th city. He can perform arbitrary number of operations of this type.</p> <p>Snuke wants to maximize the minimum amount of water among the <var>N</var> cities. Find the maximum <var>X</var> such that he can distribute at least <var>X</var> liters of water to each city.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 15</var></li> <li><var>0 ≀ x_i, y_i, a_i ≀ 10^9</var></li> <li>All values in the input are integers.</li> <li>No two cities are at the same position.</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>x_1</var> <var>y_1</var> <var>a_1</var> : <var>x_N</var> <var>y_N</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum of the minimum amount of water among the <var>N</var> cities. The absolute error or the relative error must be at most <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 0 10 2 0 5 0 5 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6.500000000000 </pre> <p>The optimal solution is to carry <var>3.5</var> liters of water from the 1st city to the 2nd city. After the operation, both the 1st and the 2nd cities will have <var>6.5</var> liters of water, and the 3rd city will have <var>8</var> liters of water.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 335279264 849598327 822889311 446755913 526239859 548830120 181424399 715477619 342858071 625711486 448565595 480845266 647639160 467825612 449656269 160714711 336869678 545923679 61020590 573085537 816372580 626006012 389312924 135599877 547865075 511429216 605997004 561330066 539239436 921749002 650693494 63219754 786119025 849028504 632532642 655702582 285323416 611583586 211428413 990607689 590857173 393671555 560686330 679513171 501983447 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>434666178.237122833729 </pre></section> </div> </span>
p00257
<H1>すごろくを䜜る</H1> <p> 倪郎君は、子䟛䌚の催しでみんなで遊べるようにすごろくを䜜りたした。ゲヌムをおもしろくするために、「ふりだし」ず「あがり」以倖のすごろくのマスのいく぀かに「぀進む」、「぀戻る」のように指瀺を曞き蟌んでいきたした。ルヌレットを回しお出た数だけ進み、止たったマスに指瀺が曞き蟌んであれば、その指瀺に埓っお移動したす。ただし、指瀺に埓っお進んだ先のマスの指瀺には埓いたせん。 </p> <p> ルヌレットはからある数たでの間の数を等確率で出すこずができるものずしたす。たた、「あがり」に達するより倧きな数が出たずきや、指瀺に埓うず「あがり」より先に進んでしたうずきは「あがり」に移動したす。指瀺に埓っお戻るずきに「ふりだし」より前に戻っおしたうずきは「ふりだし」に戻るこずにしたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_makingSugoroku"> </center> <br/> <p> ずころが、ルヌレットずマスの指瀺によっおは「あがり」にたどり぀けない堎合が出おきおしたいたす。たずえば、図のようなすごろくを䜜ったずしたしょう。ずしか出ないルヌレットを䜿うず、の順に出れば「あがり」に行けたすが、はじめにが出たらその埌は䜕が出おも氞久に「あがり」にはたどり着けたせん。倪郎君は、そうずは知らずに調子に乗っおあちこちのマスに指瀺を曞き蟌んでしたいたした。 </p> <p> そこで、倪郎君に代わっお、ルヌレットずマスの指瀺によっおは、「あがり」にたどり着けない堎合が生じるかどうか刀定するプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる。入力の終わりはれロ぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 </p> <pre> max n d<sub>1</sub> d<sub>2</sub> . . . d<sub>n</sub> </pre> <p> 行目にルヌレットが出す数の最倧倀 max (2 &le; max &le; 250) が䞎えられ、行目に「ふりだし」ず「あがり」以倖のマスの数 n (2 &le; n &le; 250) が䞎えられる。続く n 行に各マスの指瀺を衚す数 d<sub>i</sub>(-n &le; d<sub>i</sub> &le; n) が䞎えられる。d<sub>i</sub> がれロのずきは指瀺が曞いおいないこずを、正の数のずきは |d<sub>i</sub>| 進む指瀺を、負の数のずきは |d<sub>i</sub>| 戻る指瀺を衚すここで、|x| は x の絶察倀を衚す。入力される倀はすべお敎数である。 </p> <p> デヌタセットの数は 100 を超えない。 </p> <h2>出力</h2> <p> 各デヌタセットごずに刀定結果を行に出力する。ルヌレットずマスの指瀺によっおは、「あがり」にたどり着けない堎合が生じるずきは「NG」、そうでなければ「OK」を出力する。 </p> <h2>入力䟋</h2> <pre> 3 3 -2 1 0 2 4 2 0 -1 -2 2 2 -2 -2 0 </pre> <h2>出力䟋</h2> <pre> OK NG NG </pre>
p00607
<H1><font color="#000000">Problem C:</font> Emacs-like Editor</H1> <p> Emacs is a text editor which is widely used by many programmers. </p> <p> The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be moved right, left, down, and up by pushing <span>f</span>, <span>b</span>, <span>n</span>, <span>p</span> with the Control Key respectively. In addition, cut-and-paste can be performed without the mouse. </p> <p> Your task is to write a program which simulates key operations in the Emacs-like editor. The program should read a text and print the corresponding edited text. </p> <p> The text consists of several lines and each line consists of zero or more alphabets and space characters. A line, which does not have any character, is a blank line. </p> <p> The editor has a cursor which can point out a character or the end-of-line in the corresponding line. The cursor can also point out the end-of-line in a blank line. </p> <p> In addition, the editor has a buffer which can hold either a string (a sequence of characters) or a linefeed. </p> <p> The editor accepts the following set of commands (If the corresponding line is a blank line, the word "the first character" should be "the end-of-line"): </p> <ul> <li> <span>a</span><br> Move the cursor to the first character of the current line. </li> <li> <span>e</span><br> Move the cursor to the end-of-line of the current line. </li> <li> <span>p</span><br> Move the cursor to the first character of the next upper line, if it exists.<br> If there is no line above the current line, move the cursor to the first character of the current line. </li> <li> <span>n</span><br> Move the cursor to the first character of the next lower line, if it exists.<br> If there is no line below the current line, move the cursor to the first character of the current line. </li> <li> <span>f</span><br> Move the cursor by one character to the right, unless the cursor points out the end-of-line.<br> If the cursor points out the end-of-line and there is a line below the current line, move the cursor to the first character of the next lower line. Otherwise, do nothing. </li> <li> <span>b</span><br> Move the cursor by one character to the left, unless the cursor points out the first character.<br> If the cursor points out the first character and there is a line above the current line, move the cursor to the end-of-line of the next upper line. Otherwise, do nothing. </li> <li> <span>d</span><br> If the cursor points out a character, delete the character (Characters and end-of-line next to the deleted character are shifted to the left).<br> If the cursor points out the end-of-line and there is a line below, the next lower line is appended to the end-of-line of the current line (Lines below the current line are shifted to the upper). <br>Otherwise, do nothing. </li> <li> <span>k</span><br> If the cursor points out the end-of-line and there is a line below the current line, perform the command <span>d</span> mentioned above, and record a linefeed on the buffer.<br> If the cursor does not point out the end-of-line, cut characters between the cursor (inclusive) and the end-of-line, and record them on the buffer. <!--Move the cursor to the end-of-line of the original line.--> After this operation, the cursor indicates the end-of-line of the current line. </li> <li> <span>y</span><br> If the buffer is empty, do nothing.<br> If the buffer is holding a linefeed, insert the linefeed at the cursor. The cursor moves to the first character of the new line.<br> If the buffer is holding characters, insert the characters at the cursor. The cursor moves to the character or end-of-line which is originally pointed by the cursor. </li> </ul> <p> The cursor position just after reading the text is the beginning of the first line, and the initial buffer is empty. </p> <H2>Input</H2> <p> The input consists of only one data-set which includes two parts. The first part gives a text consisting of several lines. The end of the text is indicated by a line (without quotes): <pre> "END_OF_TEXT" </pre> <p> This line should not be included in the text. </p> <p> Next part gives a series of commands. Each command is given in a line. The end of the commands is indicated by a character '<span>-</span>'. </p> <H2>Output</H2> <p> For the input text, print the text edited by the commands. </p> <H2>Constraints</H2> <ul> <li>The number of lines in the text given as input &le; 10</li> <li>The number of characters in a line given as input &le; 20 </li> <li>The number of commands &le; 300 </li> <li>The maximum possible number of lines in the text during operations &le; 100 </li> <li>The maximum possible number of characters in a line during operations &le; 1000 </li> </ul> <H2>Sample Input</H2> <pre> hyo ni END_OF_TEXT f d f f k p p e y a k y y n y - </pre> <H2>Output for the Sample Input</H2> <pre> honihoni honi </pre>
p03928
<span class="lang-en"> <p>Score : <var>2100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has a board with an <var>N \times N</var> grid, and <var>N \times N</var> tiles.</p> <p>Each side of a square that is part of the perimeter of the grid is attached with a socket. That is, each side of the grid is attached with <var>N</var> sockets, for the total of <var>4 \times N</var> sockets. These sockets are labeled as follows:</p> <ul> <li>The sockets on the top side of the grid: <var>U1, U2, ..., UN</var> from left to right</li> <li>The sockets on the bottom side of the grid: <var>D1, D2, ..., DN</var> from left to right</li> <li>The sockets on the left side of the grid: <var>L1, L2, ..., LN</var> from top to bottom</li> <li>The sockets on the right side of the grid: <var>R1, R2, ..., RN</var> from top to bottom</li> </ul> <figure id="socket_id"> <img src="https://atcoder.jp/img/code-festival-2016-final/916ffede6e718801d689f189e658a9bb.png"> <figcaption>Figure: The labels of the sockets</figcaption> </img></figure> <p>Snuke can insert a tile from each socket into the square on which the socket is attached. When the square is already occupied by a tile, the occupying tile will be pushed into the next square, and when the next square is also occupied by another tile, that another occupying tile will be pushed as well, and so forth. Snuke cannot insert a tile if it would result in a tile pushed out of the grid. The behavior of tiles when a tile is inserted is demonstrated in detail at Sample Input/Output <var>1</var>.</p> <p>Snuke is trying to insert the <var>N \times N</var> tiles one by one from the sockets, to reach the state where every square contains a tile. Here, he must insert exactly <var>U_i</var> tiles from socket <var>Ui</var>, <var>D_i</var> tiles from socket <var>Di</var>, <var>L_i</var> tiles from socket <var>Li</var> and <var>R_i</var> tiles from socket <var>Ri</var>. Determine whether it is possible to insert the tiles under the restriction. If it is possible, in what order the tiles should be inserted from the sockets?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩300</var></li> <li><var>U_i,D_i,L_i</var> and <var>R_i</var> are non-negative integers.</li> <li>The sum of all values <var>U_i,D_i,L_i</var> and <var>R_i</var> is equal to <var>N \times N</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li><var>2000</var> points will be awarded for passing the test set satisfying <var>N≩40</var>.</li> <li>Additional <var>100</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>U_1</var> <var>U_2</var> <var>...</var> <var>U_N</var> <var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var> <var>L_1</var> <var>L_2</var> <var>...</var> <var>L_N</var> <var>R_1</var> <var>R_2</var> <var>...</var> <var>R_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to insert the tiles so that every square will contain a tile, print the labels of the sockets in the order the tiles should be inserted from them, one per line. If it is impossible, print <code>NO</code> instead. If there exists more than one solution, print any of those.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 0 1 1 1 0 3 0 1 0 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>L1 L1 L1 L3 D1 R2 U3 R3 D2 </pre> <p>Snuke can insert the tiles as shown in the figure below. An arrow indicates where a tile is inserted from, a circle represents a tile, and a number written in a circle indicates how many tiles are inserted before and including the tile.</p> <p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/252110b5818dc7d972f77d90f99cb8cb.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 0 2 0 0 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre></section> </div> </span>
p01915
<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>K: AOR むカちゃんの成瞟</h1> <h2>問題</h2> <p> AOR むカちゃんは $N$ 回のレポヌトの点数のみで成瞟が決たる授業を受けおいる。 AOR むカちゃんは同じ授業を受けおいる友達が $M$ 人いお、自分が苊手なテヌマのレポヌトは、そのテヌマが埗意な友達のレポヌトを写すこずで、その友達ず同じ点数を取るこずができる。 ただし、他人のレポヌトを写しおいるこずを先生に気付かれおはいけないので、 $N$ 回のうち少なくずも $K$ 回は他人のレポヌトを写さず、自力でレポヌトを仕䞊げなくおはならない。 たた、 AOR むカちゃんは友達に迷惑をかけたくないず思ったので友達 $i$ に察しおレポヌトを写すのは $T_i$ 回以䞋にするこずにした。 AOR むカちゃんが自力でレポヌトを仕䞊げたずきの点数ず、友達がレポヌトを仕䞊げた時の点数が䞎えられたずきに、 AOR むカちゃんが取るこずのできる合蚈点数の最倧倀を答えよ。 </p> <h2>制玄</h2> <ul> <li>$1 \le N \le 100$</li> <li>$0 \le M \le 100$</li> <li>$0 \le K \le N$</li> <li>$0 \le a_i \le 100$</li> <li>$0 \le b_{ij} \le 100$</li> <li>$0 \le T_i \le N$</li> </ul> <h2>入力</h2> <p> 入力は以䞋の圢匏で暙準入力から䞎えられる。 </p> <p> $N \ M \ K$<br> $a_1 \ \cdots \ a_N$<br> $b_{11} \ \cdots \ b_{1N}$<br> $\vdots$<br> $b_{M1} \ \cdots \ b_{MN}$<br> $T_1 \ \cdots \ T_M$<br> <br> $a_i$ はAORむカちゃんが $i$ 番目のレポヌトを仕䞊げた時の点数を、$b_{ij}$ は友達 $i$ が $j$ 番目のレポヌトを仕䞊げた時の点数を衚す。 </p> <h2>出力</h2> <p> AOR むカちゃんが取るこずのできる合蚈点数の最倧倀を出力せよ。たた、末尟に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>入力䟋 1</h3> <pre> 3 2 2 50 65 70 80 100 80 90 65 45 1 1 </pre> <h3>出力䟋 1</h3> <pre> 225 </pre> <p> AOR むカちゃんは 1 回だけ他人のレポヌトを写すこずができるので、友達 2 の 1 ぀めのレポヌトを写すこずで、 AOR むカちゃんは最高点数を取るこずができる。 </p> <h3>入力䟋 2</h3> <pre> 3 0 3 0 0 0 </pre> <h3>出力䟋 2</h3> <pre> 0 </pre> <p> AOR むカちゃんには友達がいないため、レポヌトを写すこずはできない。 </p>
p03181
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1, 2, \ldots, N</var>. For each <var>i</var> (<var>1 \leq i \leq N - 1</var>), the <var>i</var>-th edge connects Vertex <var>x_i</var> and <var>y_i</var>.</p> <p>Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other black vertex by passing through only black vertices.</p> <p>You are given a positive integer <var>M</var>. For each <var>v</var> (<var>1 \leq v \leq N</var>), answer the following question:</p> <ul> <li>Assuming that Vertex <var>v</var> has to be black, find the number of ways in which the vertices can be painted, modulo <var>M</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>2 \leq M \leq 10^9</var></li> <li><var>1 \leq x_i, y_i \leq N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_{N - 1}</var> <var>y_{N - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>v</var>-th (<var>1 \leq v \leq N</var>) line should contain the answer to the following question:</p> <ul> <li>Assuming that Vertex <var>v</var> has to be black, find the number of ways in which the vertices can be painted, modulo <var>M</var>.</li> </ul> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 100 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 4 3 </pre> <p>There are seven ways to paint the vertices, as shown in the figure below. Among them, there are three ways such that Vertex <var>1</var> is black, four ways such that Vertex <var>2</var> is black and three ways such that Vertex <var>3</var> is black.</p> <p><img alt="" src="https://img.atcoder.jp/dp/subtree_0_muffet.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 100 1 2 1 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 5 5 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 2 8 5 10 8 6 5 1 5 4 8 2 10 3 6 9 2 1 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 0 1 1 1 0 1 0 1 1 </pre> <p>Be sure to print the answers modulo <var>M</var>.</p></section> </div> </span>
p01446
<H1><font color="#000">Problem J:</font> Blue Forest</H1> <p> John is playing a famous console game named 'Tales of Algorithmers.' Now he is facing the last dungeon called 'Blue Forest.' To find out the fastest path to run through the very complicated dungeon, he tried to draw up the dungeon map. </p> <p> The dungeon consists of several floors. Each floor can be described as a connected simple plane graph. Vertices of the graph are identified by X-Y coordinate, and the length of an edge is calculated by Euclidean distance. A vertex may be equipped with a one-way warp gate. If John chooses to use the gate, it brings John to another vertex in a possibly different floor. The distance between a warp gate and its destination is considered as 0. </p> <p> One vertex has at most one warp gate, though some vertices might be the destination of multiple warp gates. </p> <p> He believed he made one map for each floor, however after drawing maps of all the floors, he noticed that he might have made a few mistakes. He might have drawn the same floor several times, and might have forgotten to mark some warp gates in the maps. However, he was sure he marked all warp gates at least once. So if the maps of same floor are unified to one map, all the warp gates must be described there. Luckily there are no floors which have the same shape as the other floors, so if two (or more) maps can be unified, they must be the maps of the same floor. Also, there is no floor which is circular symmetric (e.g. a regular triangle and a square). </p> <p> Map A and map B can be unified if map B can be transformed to map A using only rotation and parallel translation. Since some of the warp gates on maps might be missing, you should not consider the existence of warp gates when checking unification. If it is possible to unify map A and map B, a vertex on map A and the corresponding vertex on map B are considered as 'identical' vertices. In other words, you should treat warp gates on map B as those on map A where the warp gates are located on the corresponding vertices on map A. Destinations of warp gates should be treated similarly. After that you can forget map B. It is guaranteed that if both map A and map B have warp gates which are on the identical vertices, the destinations of them are also identical. </p> <p> Remember, your task is to find the shortest path from the entrance to the exit of the dungeon, using the unified maps. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset is in the following format. </p> <p> <i>n</i><br> <i>component</i><sub>1</sub></br> <i>component</i><sub>2</sub></br> ...<br> <i>component</i><sub><i>n</i></sub></br> <i>sl sn</i><br> <i>dl dn</i><br> </p> <p> <i>n</i> is a positive integer indicating the number of maps. <i>component<sub>i</sub></i> describes the <i>i</i>-th map in the following format. </p> <p> <i>A</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub><br> ...<br> <i>x</i><sub><i>A</i></sub> <i>y</i><sub><i>A</i></sub><br> <i>B</i><br> <i>s</i><sub>1</sub> <i>d</i><sub>1</sub><br> <i>s</i><sub>2</sub> <i>d</i><sub>2</sub><br> ...<br> <i>s</i><sub><i>B</i></sub> <i>d</i><sub><i>B</i></sub><br> <i>C</i> <i>sn</i><sub>1</sub> <i>dl</i><sub>1</sub> <i>dn</i><sub>1</sub><br> <i>sn</i><sub>2</sub> <i>dl</i><sub>2</sub> <i>dn</i><sub>2</sub><br> ...<br> <i>sn</i><sub><i>C</i></sub> <i>dl</i><sub><i>C</i></sub> <i>dn</i><sub><i>C</i></sub><br> </p> <p> <i>A</i> denotes the number of vertices in the map. Each of the following <i>A</i> lines contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> representing the coordinates of the <i>i</i>-th vertex in the 2-dimensional plane. <i>B</i> denotes the number of the edges connecting the vertices in the map. Each of the following <i>B</i> lines contains two integers representing the start and the end vertex of each edge. Vertices on the same map are numbered from 1. </p> <p> <i>C</i> denotes the number of warp gates. Each of the following <i>C</i> lines has three integers describing a warp gate. The first integer is the vertex where the warp gate is located. The second and the third integer are the indices of the map and the vertex representing the destination of the warp gate, respectively. Similarly to vertices, maps are also numbered from 1. </p> <p> After the description of all maps, two lines follow. The rst line contains two integers <i>sl</i> and <i>dl</i> , meaning that the entrance of the dungeon is located in the <i>sl</i>-th map, at the vertex <i>dl</i>. The last line has two integers <i>sn</i> and <i>dn</i>, similarly describing the location of the exit. </p> <p> The values in each dataset satisfy the following conditions: </p> <ul> <li> 1 &le; <i>n</i> &le; 50,</li> <li> 3 &le; <i>A</i> &le; 20,</li> <li> <i>A</i> - 1 &le; <i>B</i> &le; <i>A</i>(<i>A</i> - 1)/2,</li> <li> 0 &le; <i>C</i> &le; <i>A</i>, and</li> <li> -10,000 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> &le; 10,000.</li> </ul> <H2>Output</H2> <p> For each dataset, print the distance of the shortest path from the entrance to the exit. The output should not contain an absolute error greater than 10<sup>-1</sup>. If there is no route, print -1. </p> <H2>Sample Input</H2> <pre> 2 5 0 0 10 0 20 0 30 0 30 10 4 1 2 2 3 3 4 4 5 2 1 2 4 3 2 2 5 -10 0 0 0 0 -10 0 -20 0 -30 4 1 2 2 3 3 4 4 5 1 4 1 3 1 1 2 1 4 3 4 3 0 0 5 0 2 1 2 2 3 0 3 0 0 3 4 0 5 2 1 2 1 3 1 2 3 4 4 0 13 0 0 13 0 13 13 4 1 2 1 4 2 3 2 4 0 4 5 12 0 0 -7 17 -12 5 4 1 2 2 3 2 4 4 3 0 1 1 4 1 4 3 0 0 2 0 0 4 2 1 2 1 3 0 3 0 0 -2 0 0 4 2 1 2 1 3 1 1 4 1 3 0 0 1 0 0 2 2 1 2 1 3 1 1 4 1 3 0 0 2 0 0 4 2 1 2 2 3 0 1 1 4 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 10.0000000000 41.3847763109 -1.000000000 </pre>
p01016
<h1>Problem A: Password</h1> <p> 倪郎君は、自分のパ゜コンを持っおいお、ログむン時のパスワヌドを蚭定しおいた。しかし、䞍泚意にも倪郎君はそのパスワヌドを忘れおしたった。そこで、パスワヌドをメモした玙があるこずを思い出し、玙を芋぀けた倪郎君はそれを芋お驚いた。なんず玙は切れおいお断片しか存圚せず、ずころどころに汚れがあり、読めなくなっおいたのだ。倪郎君はそのメモを参考にパスワヌドを掚枬するこずにした。 </p> <h2>Problem</h2> <p> 二぀の文字列A, Bが䞎えられる。文字列Aの䞭に文字列Bが含たれおいるかどうかを刀定し、含たれおいる堎合は"Yes"を、そうでなければ"No"を出力せよ。 文字列Aにはアルファベットの倧文字のみが含たれおおり、文字列Bにはアルファベットの倧文字に加えお、'_'(半角アンダヌバヌ)が含たれおいる。半角アンダヌバヌは任意の文字を衚す。 </p> <h2>Input</h2> <p> 文字列 A<br> 文字列 B </p> <h2>Constraints</h2> <ul> <li>A,Bの文字列の長さはどちらも1文字以䞊1000文字以䞋である。</li> <li>Bの文字列の長さがAの文字列の長さを超えるこずはない。</li> </ul> <h2>Output</h2> <p> "Yes"たたは"No"を1行で出力せよ。 </p> <h2>Sample Input 1</h2> <pre> ABCDE ABC </pre> <h2>Sample Output 1</h2> <pre> Yes </pre> <h2>Sample Input 2</h2> <pre> KUSATSU KSATSU </pre> <h2>Sample Output 2</h2> <pre> No </pre> <h2>Sample Input 3</h2> <pre> ABCABC ACBA_B </pre> <h2>Sample Output 3</h2> <pre> No </pre> <h2>Sample Input 4</h2> <pre> RUPCUAPC __PC </pre> <h2>Sample Output 4</h2> <pre> Yes </pre> <h2>Sample Input 5</h2> <pre> AIZU _A </pre> <h2>Sample Output 5</h2> <pre> No </pre>
p01503
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem I: Tampopo Machine </h2> <p> "Today is another day of endless, tedious work to put a tampopo on sashimi..." </p> <p> Yaruo works in a sashimi (sliced raw fish) factory. His job is to put tampopos on sashimi packages everyday. Tired of this menial job, he decided to develop a tampopo machine to do the job instead of him. </p> <p> The tampopo machine has the following properties. Sashimi packages are put on a conveyor belt and move from left to right. The width of a package is $W$ and the interval between two adjacent packages is $D$. The machine has $N$ magic hands placed above the conveyor belt at regular intervals of $M$. These magic hands put tampopos every $T$ seconds. </p> <p> In initial state, the right end of the first package is under the leftmost magic hand. The magic hands start putting a tampopo as soon as he turns on the power of the machine. The conveyor belt moves one unit length per one second. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_tampopoMachine" width="480"><br> </center> <br> <p> Unfortunately, after building the machine, Yaruo noticed that there exist some packages with no tampopos. Calculate the ratio of packages with no tampopos for him. </p> <p> When a magic hand puts a tampopo on the left or right end of a package, you can assume that the tampopo is on the package. </p> <h3>Input</h3> <p> The input consists of 5 integers, $W$, $D$, $N$, $M$ and $T$ which are described in the problem statement.<br> ($1 \leq W, D, N, M, T \leq 1,000,000,000$) </p> <h3>Output</h3> <p> Output the ratio of packages with no tampopos in a line. The absolute error should be less than or equal to $10^{-9}$. </p> <h3>Sample Input 1</h3> <pre>1 1 1 1 1</pre> <h3>Sample Output 1</h3> <pre>0.000000000000</pre> <h3>Sample Input 2</h3> <pre>1 2 3 4 5</pre> <h3>Sample Output 2</h3> <pre>0.200000000000</pre> <h3>Sample Input 3</h3> <pre>3 2 2 1 6</pre> <h3>Sample Output 3</h3> <pre>0.166666666667</pre>
p01153
<H1><font color="#000">Problem G:</font> Gather on the Clock</H1> <p> There is a self-playing game called <i>Gather on the Clock</i>. </p> <p> At the beginning of a game, a number of cards are placed on a ring. Each card is labeled by a value. </p> <p> In each step of a game, you pick up any one of the cards on the ring and put it on the next one in clockwise order. You will gain the score by the difference of the two values. You should deal with the two cards as one card in the later steps. You repeat this step until only one card is left on the ring, and the score of the game is the sum of the gained scores. </p> <p> Your task is to write a program that calculates the maximum score for the given initial state, which specifies the values of cards and their placements on the ring. </p> <p> The figure shown below is an example, in which the initial state is illustrated on the left, and the subsequent states to the right. The picked cards are 1, 3 and 3, respectively, and the score of this game is 6. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gatherOnTheClock"> <p>Figure 6: An illustrative play of Gather on the Clock</p> </center> <H2>Input</H2> <p> The input consists of multiple test cases. The first line contains the number of cases. For each case, a line describing a state follows. The line begins with an integer <i>n</i> (2 &le; <i>n</i> &le; 100), the number of cards on the ring, and then <i>n</i> numbers describing the values of the cards follow. Note that the values are given in clockwise order. You can assume all these numbers are non-negative and do not exceed 100. They are separated by a single space character. </p> <H2>Output</H2> <p> For each case, output the maximum score in a line. </p> <H2>Sample Input</H2> <pre> 2 4 0 1 2 3 6 1 8 0 3 5 9 </pre> <H2>Output for the Sample Input</H2> <pre> 6 34 </pre>
p03494
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> positive integers written on a blackboard: <var>A_1, ..., A_N</var>.</p> <p>Snuke can perform the following operation when all integers on the blackboard are even:</p> <ul> <li>Replace each integer <var>X</var> on the blackboard by <var>X</var> divided by <var>2</var>.</li> </ul> <p>Find the maximum possible number of operations that Snuke can perform.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 200</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible number of operations that Snuke can perform.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 8 12 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Initially, <var>[8, 12, 40]</var> are written on the blackboard. Since all those integers are even, Snuke can perform the operation.</p> <p>After the operation is performed once, <var>[4, 6, 20]</var> are written on the blackboard. Since all those integers are again even, he can perform the operation.</p> <p>After the operation is performed twice, <var>[2, 3, 10]</var> are written on the blackboard. Now, there is an odd number <var>3</var> on the blackboard, so he cannot perform the operation any more.</p> <p>Thus, Snuke can perform the operation at most twice.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 6 8 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Since there is an odd number <var>5</var> on the blackboard already in the beginning, Snuke cannot perform the operation at all.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 382253568 723152896 37802240 379425024 404894720 471526144 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p00312
<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> 䞀匹のカ゚ルが巣穎に垰ろうずしおいたす。巣穎はカ゚ルの <var>D</var> センチメヌトル前方にあっお、カ゚ルは巣穎に向かっおたっすぐ進みたす。カ゚ルができる行動は、以䞋の぀だけです。 </p> <ul> <li> 倧ゞャンプ<var>L</var> センチメヌトル前方に進む</li> <li> 小ゞャンプセンチメヌトル前方に進む</li> </ul> <p> カ゚ルは巣穎を跳び越すこずなく、ちょうど巣穎に着地するこずをねらっおいたす。 </p> <p> カ゚ルが巣穎に垰るために、最䜎䜕回跳ぶ必芁があるかを求めるプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>D</var> <var>L</var> </pre> <p> 入力は行であり、巣穎たでの距離 <var>D</var> (1 &le; <var>D</var> &le; 10000) ず倧ゞャンプでカ゚ルが進む距離 <var>L</var> (2 &le; <var>L</var> &le; 10000) が䞎えられる。 </p> <h2>Output</h2> <p> カ゚ルが最䜎䜕回跳ぶ必芁があるかを、行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 10 5 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <br/> <h2>Sample Input 2</h2> <pre> 7 4 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre>
p00742
<h1><font color="#000000">Problem C:</font> Verbal Arithmetic</h1> <p> Let's think about <i>verbal arithmetic.</i> </p> <p> The material of this puzzle is a summation of non-negative integers represented in a decimal format, for example, as follows. </p> <pre> 905 + 125 = 1030 </pre> <p> In verbal arithmetic, every digit appearing in the equation is masked with an alphabetic character. A problem which has the above equation as one of its answers, for example, is the following. </p> <pre> ACM + IBM = ICPC </pre> <p> Solving this puzzle means finding possible digit assignments to the alphabetic characters in the verbal equation. </p> <p> The rules of this puzzle are the following. </p> <ul> <li> Each integer in the equation is expressed in terms of one or more digits '0'-'9', but all the digits are masked with some alphabetic characters 'A'-'Z'. </li> <li> The same alphabetic character appearing in multiple places of the equation masks the same digit. Moreover, all appearances of the same digit are masked with a single alphabetic character. That is, different alphabetic characters mean different digits. </li> <li> The most significant digit must not be '0', except when a zero is expressed as a single digit '0'. That is, expressing numbers as "00" or "0123" is not permitted. </li> </ul> <p> There are 4 different digit assignments for the verbal equation above as shown in the following table. </p> <table border> <tr><th>Mask</th><th>A</th><th>B</th><th>C</th><th>I</th><th>M</th><th>P</th></tr> <tr><td>Case 1</td><td>9</td><td>2</td><td>0</td><td>1</td><td>5</td><td>3</td></tr> <tr><td>Case 2</td><td>9</td><td>3</td><td>0</td><td>1</td><td>5</td><td>4</td></tr> <tr><td>Case 3</td><td>9</td><td>6</td><td>0</td><td>1</td><td>5</td><td>7</td></tr> <tr><td>Case 4</td><td>9</td><td>7</td><td>0</td><td>1</td><td>5</td><td>8</td></tr> </table> <p> Your job is to write a program which solves this puzzle. </p> <h3>Input</h3> <p>The input consists of a number of datasets. The end of the input is indicated by a line containing a zero. <!-- end en only --> <!-- begin en only --> <p> The number of datasets is no more than 100. Each dataset is formatted as follows. </blockquote> <!-- end en only --> <blockquote> <i>N</i> <br /> <i>STRING</i> <sub>1</sub> <br /> <i>STRING</i> <sub>2</sub> <br /> ... <br /> <i>STRING</i> <sub><i>N</i></sub> <br /> </blockquote> <!-- begin en only --> <p> The first line of a dataset contains an integer <i>N </i> which is the number of integers appearing in the equation. Each of the following <i>N </i> lines contains a string composed of uppercase alphabetic characters 'A'-'Z' which mean masked digits. </p> <!-- end en only --> <!-- begin en only --> <p>Each dataset expresses the following equation.</p> <!-- end en only --> <blockquote> <i>STRING</i> <sub>1</sub> + <i>STRING</i> <sub>2</sub> + ... + <i>STRING</i> <sub><i>N</i> -1</sub> = <i>STRING</i> <sub><i>N</i></sub> </blockquote> <!-- begin en only --> <p> The integer <i>N </i> is greater than 2 and less than 13. The length of <i>STRING</i> <sub><i>i</i></sub> is greater than 0 and less than 9. The number of different alphabetic characters appearing in each dataset is greater than 0 and less than 11. </p> <!-- end en only --> <h3>Output</h3> <p> For each dataset, output a single line containing the number of different digit assignments that satisfy the equation. </p> <p> The output must not contain any superfluous characters. </p> <h3>Sample Input</h3> <pre> 3 ACM IBM ICPC 3 GAME BEST GAMER 4 A B C AB 3 A B CD 3 ONE TWO THREE 3 TWO THREE FIVE 3 MOV POP DIV 9 A B C D E F G H IJ 0 </pre> <h3>Output for the Sample Input</h3> <pre> 4 1 8 30 0 0 0 40320 </pre>
p01850
<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-AMS_HTML"> </script> <h3>癟人䞀銖</h3> <p>癟人䞀銖は日本の䌝統的なゲヌムである このゲヌムでは <i>N</i> 枚のカヌドが甚いられそれぞれのカヌドには1぀の文字列が曞かれおいる现かいルヌルは省略するが A君は <i>N</i> 枚のカヌドに曞かれおいる文字列を䜕らかの順序でそれぞれちょうど1回ず぀読むこずになった </p> <p>癟人䞀銖ではその接頭蟞が非垞に重芁である癟人䞀銖で䜿甚される文字列ずしお接頭蟞は䌌おいる蚀葉が倚く 連続しお䌌たような文字列を読むずA君も混乱しおしたう そこでA君は連続する二぀のカヌドの文字列の接頭蟞ができるだけ異なるようにカヌドを䞊べ替えようず考えた </p> <p>A君の目暙は「山札の読みやすさ」ず呌ばれる指暙を最小化するような山札を求めるこずであるここで山札ずはこの癟人䞀銖で読たれる <i>N</i> 枚のカヌドを䞊べ替えたものを指す山札の読みやすさずは山札内にある隣接したカヌドの類䌌床の総和を蚀う2 枚のカヌドの類䌌床はそれらに曞かれた文字列どうしの最長共通接頭蟞の長さずしお定矩されるなお文字列 <i>t</i> ず <i>u</i> の最長共通接頭蟞ずは<i>t</i> ず <i>u</i> 䞡方の接頭蟞であるような文字列のうち最長のものを指す </p> <p>䟋えば2 枚のカヌドに曞かれた文字列がそれぞれ "<samp>jag</samp>" ず "<samp>japan</samp>" であればこれらのカヌドの類䌌床は 2 である䞀方"<samp>wan</samp>" ず "<samp>nyan</samp>" であれば類䌌床は 0 である </p> <p>ずころで「山札の読みやすさ」が最小ずなる山札は耇数存圚するかもしれないA君は最小解ずしおありうる山札のうち蟞曞順最小の山札を求めたいここで山札 <i>P</i> ず <i>Q</i> に぀いお <i>P</i> が蟞曞順で小さいずはある正の敎数 <i>i</i> が存圚しお1 番目から <i>i-1</i> 番目のカヌドたではそれぞれ同䞀のカヌドでありか぀ <i>i</i> 番目のカヌドの文字列は蟞曞順においお山札 <i>P</i> のカヌドのほうが小さいこずを蚀う </p> <p>あなたの仕事は「山札の読みやすさ」を最小にするような山札の䞭で蟞曞順最小ずなるものを求めるこずである </p> <h3>Input</h3> <p>入力は耇数のデヌタセットからなる 各デヌタセットは次の圢匏で衚される </p> <blockquote><i>N</i><br><i>s<sub>1</sub></i><br>...<br><i>s<sub>N</sub></i></blockquote> <p>1行目にはカヌドの枚数を衚す敎数 <i>N</i> (<i>1 ≀ N ≀ 100,000</i>) が䞎えられる 続く <i>N</i> 行にはカヌドに曞かれた1文字以䞊の文字列が曞かれおあり 1行は英小文字のみで構成されるたた同䞀セット内においお各 <i>s<sub>i</sub></i> は互いに異なるこずが保蚌されおいる さらに<i>s<sub>i</sub></i> の長さの合蚈は 400,000 以䞋であるこずが保蚌されおいる </p> <p>入力の終わりは 1぀のれロからなる行で瀺す </p> <h3>Output</h3> <p>各デヌタセットに぀いお「山札の読みやすさ」が最小ずなる山札の䞭で蟞曞順最小の山札の情報を<i>N</i> 行に出力せよ具䜓的にはそのような山札の <i>i</i> 番目のカヌドに曞かれた文字列を<i>i</i> 行目に出力するこずになる </p> <h3>Sample Input</h3> <pre>3 icpc icfp topcoder 4 apple application appointment acmicpc 3 a aa aaa 4 a aza azb b 0</pre> <h3>Output for Sample Input</h3> <pre>icfp topcoder icpc apple acmicpc application appointment aa a aaa a aza b azb</pre> <p> 蟞曞順の定矩に泚意するこず今回の定矩では文字列を連結した時に蟞曞順最小になるずいうこずを意味するわけではない䟋えば3番目の入力䟋では [aaa,a,aa] も「山札の読みやすさ」が最小ずなる解の䞀぀であり連結すれば同じ文字列になるため蟞曞順最小の解に芋えるかもしれないしかしながら今回の定矩では先頭の文字列 "aa" ず "aaa" が優先的に比范されるため蟞曞順最小の解は [aa,a,aaa] ずなる </p>
p02285
<H1>Binary Search Tree III</H1> <p> Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II. </p> <ul> <li><span>insert </span> $k$: Insert a node containing $k$ as key into $T$.</li> <li><span>find </span>$k$: Report whether $T$ has a node containing $k$. </li> <li><span>delete </span>$k$: Delete a node containing $k$.</li> <li><span>print</span>: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively.</li> </ul> <p> The operation delete $k$ for deleting a given node $z$ containing key $k$ from $T$ can be implemented by an algorithm which considers the following cases: </p> <ol> <li> If $z$ has no children, we modify its parent $z.p$ to replace $z$ with NIL as its child (delete $z$).</li> <li> If $z$ has only a single child, we "splice out" $z$ by making a new link between its child and its parent.</li> <li> If $z$ has two children, we splice out $z$'s successor $y$ and replace $z$'s key with $y$'s key.</li> </ol> <H2>Input</H2> <p> In the first line, the number of operations $m$ is given. In the following $m$ lines, operations represented by <span>insert </span>$k$, <span>find </span>$k$, <span>delete </span>$k$ or <span>print</span> are given. </p> <H2>Output</H2> <p> For each <span>find </span>$k$ operation, print "<span>yes</span>" if $T$ has a node containing $k$, "<span>no</span>" if not. </p> <p> In addition, for each <span>print</span> operation, print a list of keys obtained by inorder tree walk and preorder tree walk in a line respectively. Put a space character <u>before each key</u> <H2>Constraints</H2> <ul> <li>The number of operations $\leq 500,000$</li> <li>The number of print operations $\leq 10$.</li> <li>$-2,000,000,000 \leq key \leq 2,000,000,000$</li> <li>The height of the binary tree does not exceed 100 if you employ the above pseudo code.</li> <li>The keys in the binary search tree are all different.</li> </ul> <H2>Sample Input 1</H2> <pre> 18 insert 8 insert 2 insert 3 insert 7 insert 22 insert 1 find 1 find 2 find 3 find 4 find 5 find 6 find 7 find 8 print delete 3 delete 7 print </pre> <H2>Sample Output 1</H2> <pre> yes yes yes no no no yes yes 1 2 3 7 8 22 8 2 1 3 7 22 1 2 8 22 8 2 1 22 </pre> <H2>Reference</H2> <p> Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. </p>
p03247
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is introducing a <strong>robot arm</strong> with the following properties to his factory:</p> <ul> <li>The robot arm consists of <var>m</var> <strong>sections</strong> and <var>m+1</var> <strong>joints</strong>. The sections are numbered <var>1</var>, <var>2</var>, ..., <var>m</var>, and the joints are numbered <var>0</var>, <var>1</var>, ..., <var>m</var>. Section <var>i</var> connects Joint <var>i-1</var> and Joint <var>i</var>. The length of Section <var>i</var> is <var>d_i</var>.</li> <li>For each section, its <strong>mode</strong> can be specified individually. There are four modes: <code>L</code>, <code>R</code>, <code>D</code> and <code>U</code>. The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint <var>i</var> will be determined as follows (we denote its coordinates as <var>(x_i, y_i)</var>):<ul> <li><var>(x_0, y_0) = (0, 0)</var>.</li> <li>If the mode of Section <var>i</var> is <code>L</code>, <var>(x_{i}, y_{i}) = (x_{i-1} - d_{i}, y_{i-1})</var>.</li> <li>If the mode of Section <var>i</var> is <code>R</code>, <var>(x_{i}, y_{i}) = (x_{i-1} + d_{i}, y_{i-1})</var>.</li> <li>If the mode of Section <var>i</var> is <code>D</code>, <var>(x_{i}, y_{i}) = (x_{i-1}, y_{i-1} - d_{i})</var>.</li> <li>If the mode of Section <var>i</var> is <code>U</code>, <var>(x_{i}, y_{i}) = (x_{i-1}, y_{i-1} + d_{i})</var>.</li> </ul> </li> </ul> <p>Snuke would like to introduce a robot arm so that the position of Joint <var>m</var> can be matched with all of the <var>N</var> points <var>(X_1, Y_1), (X_2, Y_2), ..., (X_N, Y_N)</var> by properly specifying the modes of the sections. Is this possible? If so, find such a robot arm and how to bring Joint <var>m</var> to each point <var>(X_j, Y_j)</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 1000</var></li> <li><var>-10^9 \leq X_i \leq 10^9</var></li> <li><var>-10^9 \leq Y_i \leq 10^9</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li>In the test cases worth <var>300</var> points, <var>-10 \leq X_i \leq 10</var> and <var>-10 \leq Y_i \leq 10</var> hold.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X_1</var> <var>Y_1</var> <var>X_2</var> <var>Y_2</var> <var>:</var> <var>X_N</var> <var>Y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print <code>-1</code>.</p> <pre><var>m</var> <var>d_1</var> <var>d_2</var> <var>...</var> <var>d_m</var> <var>w_1</var> <var>w_2</var> <var>:</var> <var>w_N</var> </pre> <p><var>m</var> and <var>d_i</var> are the configurations of the robot arm. Refer to the problem statement for what each of them means. Here, <var>1 \leq m \leq 40</var> and <var>1 \leq d_i \leq 10^{12}</var> must hold. Also, <var>m</var> and <var>d_i</var> must all be integers.</p> <p><var>w_j</var> is a string of length <var>m</var> that represents the way to bring Joint <var>m</var> of the robot arm to point <var>(X_j, Y_j)</var>. The <var>i</var>-th character of <var>w_j</var> should be one of the letters <code>L</code>, <code>R</code>, <code>D</code> and <code>U</code>, representing the mode of Section <var>i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 -1 0 0 3 2 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 2 RL UU DR </pre> <p>In the given way to bring Joint <var>m</var> of the robot arm to each <var>(X_j, Y_j)</var>, the positions of the joints will be as follows:</p> <ul> <li>To <var>(X_1, Y_1) = (-1, 0)</var>: First, the position of Joint <var>0</var> is <var>(x_0, y_0) = (0, 0)</var>. As the mode of Section <var>1</var> is <code>R</code>, the position of Joint <var>1</var> is <var>(x_1, y_1) = (1, 0)</var>. Then, as the mode of Section <var>2</var> is <code>L</code>, the position of Joint <var>2</var> is <var>(x_2, y_2) = (-1, 0)</var>.</li> <li>To <var>(X_2, Y_2) = (0, 3)</var>: <var>(x_0, y_0) = (0, 0), (x_1, y_1) = (0, 1), (x_2, y_2) = (0, 3)</var>.</li> <li>To <var>(X_3, Y_3) = (2, -1)</var>: <var>(x_0, y_0) = (0, 0), (x_1, y_1) = (0, -1), (x_2, y_2) = (2, -1)</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 0 1 0 2 0 3 0 4 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 1 1 RU UR </pre> <p>There may be duplicated points among <var>(X_j, Y_j)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 -7 -3 7 3 -3 -7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 3 1 4 1 5 LRDUL RDULR DULRD </pre></section> </div> </span>
p00892
<H1><font color="#000">Problem I:</font> Intersection of Two Prisms</H1> <p> Suppose that <i>P</i><sub>1</sub> is an infinite-height prism whose axis is parallel to the <i>z</i>-axis, and <i>P</i><sub>2</sub> is also an infinite-height prism whose axis is parallel to the <i>y</i>-axis. <i>P</i><sub>1</sub> is defined by the polygon <i>C</i><sub>1</sub> which is the cross section of <i>P</i><sub>1</sub> and the <i>xy</i>-plane, and <i>P</i><sub>2</sub> is also defined by the polygon <i>C</i><sub>2</sub> which is the cross section of <i>P</i><sub>2</sub> and the <i>x</i>z-plane. </p> <p> Figure I.1 shows two cross sections which appear as the first dataset in the sample input, and Figure I.2 shows the relationship between the prisms and their cross sections. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_intersectionOfTwoPrisms1"><br> <p>Figure I.1: Cross sections of Prisms</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_intersectionOfTwoPrisms2"><br> <p>Figure I.2: Prisms and their cross sections</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_intersectionOfTwoPrisms3"><br> <p>Figure I.3: Intersection of two prisms</p> </center> <p> Figure I.3 shows the intersection of two prisms in Figure I.2, namely, <i>P</i><sub>1</sub> and <i>P</i><sub>2</sub>. </p> <p> Write a program which calculates the volume of the intersection of two prisms. </p> <H2>Input</H2> <p> The input is a sequence of datasets. The number of datasets is less than 200. </p> <p> Each dataset is formatted as follows. </p> <p> <i>m n</i><br> <i>x</i><sub>11</sub> <i>y</i><sub>11</sub><br> <i>x</i><sub>12</sub> <i>y</i><sub>12</sub> <br> .<br> .<br> .<br> <i>x</i><sub>1<i>m</i></sub> <i>y</i><sub>1<i>m</i></sub> <br> <i>x</i><sub>21</sub> <i>z</i><sub>21</sub><br> <i>x</i><sub>22</sub> <i>z</i><sub>22</sub><br> .<br> .<br> .<br> <i>x</i><sub>2<i>n</i></sub> <i>z</i><sub>2<i>n</i></sub><br> </p> <p> <i>m</i> and <i>n</i> are integers (3 &le; <i>m</i> &le; 100, 3 &le; <i>n</i> &le; 100) which represent the numbers of the vertices of the polygons, <i>C</i><sub>1</sub> and <i>C</i><sub>2</sub>, respectively. </p> <p> <i>x</i><sub>1<i>i</i></sub>, <i>y</i><sbu>1<i>i</i></sub>, <i>x</i><sub>2<i>j</i></sub> and <i>z</i><sub>2<i>j</i></sub> are integers between -100 and 100, inclusive. (<i>x</i><sub>1<i>i</i></sub>, <i>y</i><sub>1<i>i</i></sub>) and (<i>x</i><sub>2<i>j</i></sub> , <i>z</i><sub>2<i>j</i></sub>) mean the <i>i</i>-th and <i>j</i>-th vertices' positions of <i>C</i><sub>1</sub> and <i>C</i><sub>2</sub> respectively. </p> <p> The sequences of these vertex positions are given in the counterclockwise order either on the <i>xy</i>-plane or the <i>xz</i>-plane as in Figure I.1. </p> <p> You may assume that all the polygons are <i>convex</i>, that is, all the interior angles of the polygons are less than 180 degrees. You may also assume that all the polygons are <i>simple</i>, that is, each polygon's boundary does not cross nor touch itself. </p> <p> The end of the input is indicated by a line containing two zeros. </p> <H2>Output</H2> <p> For each dataset, output the volume of the intersection of the two prisms, <i>P</i><sub>1</sub> and <i>P</i><sub>2</sub>, with a decimal representation in a line. </p> <p> None of the output values may have an error greater than 0.001. The output should not contain any other extra characters. </p> <H2>Sample Input</H2> <pre> 4 3 7 2 3 3 0 2 3 1 4 2 0 1 8 1 4 4 30 2 30 12 2 12 2 2 15 2 30 8 13 14 2 8 8 5 13 5 21 7 21 9 18 15 11 15 6 10 6 8 8 5 10 12 5 9 15 6 20 10 18 12 3 3 5 5 10 3 10 10 20 8 10 15 10 8 4 4 -98 99 -99 -99 99 -98 99 97 -99 99 -98 -98 99 -99 96 99 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4.708333333333333 1680.0000000000005 491.1500000000007 0.0 7600258.4847715655 </pre>
p01780
<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>A - Breadth-First Search by Foxpower</h2> <h3>Problem Statement</h3> <p> Fox Ciel went to JAG Kingdom by bicycle, but she forgot a place where she parked her bicycle. So she needs to search it from a bicycle-parking area before returning home. </p> <p> The parking area is formed as a unweighted rooted tree $T$ with $n$ vertices, numbered $1$ through $n$. Each vertex has a space for parking one or more bicycles. Ciel thought that she parked her bicycle near the vertex $1$, so she decided to search it from there by the breadth-first search. That is, she searches it at the vertices in the increasing order of their distances from the vertex $1$. If multiple vertices have the same distance, she gives priority to the vertices in the order of searching at their parents. If multiple vertices have the same parent, she searches at the vertex with minimum number at first. </p> <p> Unlike a computer, she can't go to a next vertex by random access. Thus, if she goes to the vertex $j$ after the vertex $i$, she needs to walk the distance between the vertices $i$ and $j$. BFS by fox power perhaps takes a long time, so she asks you to calculate the total moving distance in the worst case starting from the vertex $1$. </p> <h3>Input</h3> <p> The input is formatted as follows. </p> <blockquote>$n$<br>$p_2$ $p_3$ $p_4$ $\cdots$ $p_n$</blockquote> <p> The first line contains an integer $n$ ($1 \le n \le 10^5$), which is the number of vertices on the unweighted rooted tree $T$. The second line contains $n-1$ integers $p_i$ ($1 \le p_i < i$), which are the parent of the vertex $i$. The vertex $1$ is a root node, so $p_1$ does not exist. </p> <h3>Output</h3> <p> Print the total moving distance in the worst case in one line. </p> <h3>Sample Input 1</h3> <pre>4 1 1 2</pre> <h3>Output for the Sample Input 1</h3> <pre>6</pre> <h3>Sample Input 2</h3> <pre>4 1 1 3</pre> <h3>Output for the Sample Input 2</h3> <pre>4</pre> <h3>Sample Input 3</h3> <pre>11 1 1 3 3 2 4 1 3 2 9</pre> <h3>Output for the Sample Input 3</h3> <pre>25</pre>
p02905
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have an integer sequence of length <var>N</var>: <var>A_0,A_1,\cdots,A_{N-1}</var>.</p> <p>Find the following sum (<var>\mathrm{lcm}(a, b)</var> denotes the least common multiple of <var>a</var> and <var>b</var>):</p> <ul> <li><var>\sum_{i=0}^{N-2} \sum_{j=i+1}^{N-1} \mathrm{lcm}(A_i,A_j)</var></li> </ul> <p>Since the answer may be enormous, compute it modulo <var>998244353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 200000</var></li> <li><var>1 \leq A_i \leq 1000000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_0\ A_1\ \cdots\ A_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>22 </pre> <p><var>\mathrm{lcm}(2,4)+\mathrm{lcm}(2,6)+\mathrm{lcm}(4,6)=4+6+12=22</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 1 2 3 4 6 8 12 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>313 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 356822 296174 484500 710640 518322 888250 259161 609120 592348 713644 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>353891724 </pre></section> </div> </span>
p00938
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem D Wall Clocks</h2> <p> You are the manager of a chocolate sales team. Your team customarily takes tea breaks every two hours, during which varieties of new chocolate products of your company are served. Everyone looks forward to the tea breaks so much that they frequently give a glance at a wall clock. </p> <p> Recently, your team has moved to a new office. You have just arranged desks in the office. One team member asked you to hang a clock on the wall in front of her desk so that she will not be late for tea breaks. Naturally, everyone seconded her. </p> <p> You decided to provide an enough number of clocks to be hung in the field of view of everyone. Your team members will be satisfied if they have at least one clock (regardless of the orientation of the clock) in their view, or, more precisely, within 45 degrees left and 45 degrees right (both ends inclusive) from the facing directions of their seats. In order to buy as few clocks as possible, you should write a program that calculates the minimum number of clocks needed to meet everyone's demand. </p> <p> The office room is rectangular aligned to north-south and east-west directions. As the walls are tall enough, you can hang clocks even above the door and can assume one's eyesight is not blocked by other members or furniture. You can also assume that each clock is a point (of size zero), and so you can hang a clock even on a corner of the room. </p> <p> For example, assume that there are two members. If they are sitting facing each other at positions shown in Figure D.1(A), you need to provide two clocks as they see distinct sections of the wall. If their seats are arranged as shown in Figure D.1(B), their fields of view have a common point on the wall. Thus, you can meet their demands by hanging a single clock at the point. In Figure D.1(C), their fields of view have a common wall section. You can meet their demands with a single clock by hanging it anywhere in the section. Arrangements (A), (B), and (C) in Figure D.1 correspond to Sample Input 1, 2, and 3, respectively. </p> <h3>Input</h3> <p> The input consists of a single test case, formatted as follows.<br> <br> $n$ $w$ $d$<br> $x_1$ $y_1$ $f_1$<br> ...<br> $x_n$ $y_n$ $f_n$<br> <br> </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_WallClocks" width="680"><br> <p>Figure D.1. Arrangements of seats and clocks. Gray area indicates field of view.</p> </center> <p> All numbers in the test case are integers. The first line contains the number of team members $n$ $(1 \leq n \leq 1,000)$ and the size of the office room $w$ and $d$ $(2 \leq w, d \leq 100,000)$. The office room has its width $w$ east-west, and depth $d$ north-south. Each of the following $n$ lines indicates the position and the orientation of the seat of a team member. Each member has a seat at a distinct position $(x_i, y_i)$ facing the direction $f_i$, for $i = 1, ..., n$. Here $1 \leq x_i \leq w - 1, 1 \leq y_i \leq d - 1$, and $f_i$ is one of <span>N</span>, <span>E</span>, <span>W</span>, and <span>S</span>, meaning north, east, west, and south, respectively. The position $(x, y)$ means $x$ distant from the west wall and $y$ distant from the south wall. </p> <h3>Output</h3> <p> Print the minimum number of clocks needed. </p> <h3>Sample Input 1</h3> <pre>2 10 6 4 4 E 6 4 W</pre> <h3>Sample Output 1</h3> <pre>2</pre> <h3>Sample Input 2</h3> <pre>2 10 6 2 4 E 6 4 W</pre> <h3>Sample Output 2</h3> <pre>1</pre> <h3>Sample Input 3</h3> <pre>2 10 6 3 2 S 6 4 W</pre> <h3>Sample Output 3</h3> <pre>1</pre> <h3>Sample Input 4</h3> <pre>6 10 6 1 5 N 7 1 N 8 2 E 9 1 S 4 4 S 3 3 W</pre> <h3>Sample Output 4</h3> <pre>3</pre> <h3>Sample Input 5</h3> <pre>4 10 6 4 3 W 2 4 N 4 4 W 3 3 S</pre> <h3>Sample Output 5</h3> <pre>2</pre> <h3>Sample Input 6</h3> <pre>4 100000 40000 25000 25000 S 20000 30000 S 75000 25000 S 80000 30000 S</pre> <h3>Sample Output 6</h3> <pre>1</pre>
p03617
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You've come to your favorite store Infinitesco to buy some ice tea.</p> <p>The store sells ice tea in bottles of different volumes at different costs. Specifically, a <var>0.25</var>-liter bottle costs <var>Q</var> yen, a <var>0.5</var>-liter bottle costs <var>H</var> yen, a <var>1</var>-liter bottle costs <var>S</var> yen, and a <var>2</var>-liter bottle costs <var>D</var> yen. The store has an infinite supply of bottles of each type.</p> <p>You want to buy exactly <var>N</var> liters of ice tea. How many yen do you have to spend?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq Q, H, S, D \leq 10^8</var></li> <li><var>1 \leq N \leq 10^9</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>Q</var> <var>H</var> <var>S</var> <var>D</var> <var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the smallest number of yen you have to spend to buy exactly <var>N</var> liters of ice tea.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>20 30 70 90 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>150 </pre> <p>Buy one <var>2</var>-liter bottle and two <var>0.5</var>-liter bottles. You'll get <var>3</var> liters for <var>90 + 30 + 30 = 150</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10000 1000 100 10 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>100 </pre> <p>Even though a <var>2</var>-liter bottle costs just <var>10</var> yen, you need only <var>1</var> liter. Thus, you have to buy a <var>1</var>-liter bottle for <var>100</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 100 1000 10000 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>40 </pre> <p>Now it's better to buy four <var>0.25</var>-liter bottles for <var>10 + 10 + 10 + 10 = 40</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>12345678 87654321 12345678 87654321 123456789 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1524157763907942 </pre></section> </div> </span>
p02456
<h1>Set: Delete</h1> <p> For a set $S$ of integers, perform a sequence of the following operations. Note that <u>each value in $S$ must be unique</u>. </p> <ul> <li>insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.</li> <li>find($x$): Report the number of $x$ in $S$ (0 or 1).</li> <li>delete($x$): Delete $x$ from $S$.</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 by </p> <pre> 0 $x$ </pre> <p>or</p> <pre> 1 $x$ </pre> <p>or</p> <pre> 2 $x$ </pre> <p> where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent insert, find and delete operations respectively. </p> <h2>Output</h2> <p> For each insert operation, print the number of elements in $S$.<br> For each find operation, print the number of specified elements in $S$. </p> <h2>Constraints</h2> <ul> <li>$1 \leq q \leq 200,000$</li> <li>$0 \leq x \leq 1,000,000,000$</li> </ul> <h2>Sample Input 1</h2> <pre> 8 0 1 0 2 0 3 2 2 1 1 1 2 1 3 0 2 </pre> <h2>Sample Output 1</h2> <pre> 1 2 3 1 0 1 3 </pre>
p00191
<H1>苗朚</H1> <p> 怍物孊者のサトヌ博士は苗朚甚の特殊肥料を䜕皮類も発明したした。その肥料を苗朚に䞎えるず、瞬く間に苗朚の倧きさが倉わりたす。 䜆し、肥料に以䞋のように副䜜甚があるこずが刀明したした。 </p> <ul> <li>1 回目に䞎えた肥料だけでは、苗朚の倧きさが倉わりたせん。</li> <li>2 回目以降は、その回に䞎えた肥料ず、その盎前に䞎えた肥料ずの組み合わせによっお苗朚に圱響を䞎えたす。良い圱響を䞎えるず苗朚が䌞び、悪い圱響を䞎えるず苗朚が瞮んでしたうこずもありたす。</li> </ul> <p> 詊しに、サトヌ博士は 3 皮類の肥料 (肥料 1、2、3) に察し、ある時点で䞎えた肥料 (今回の肥料) ずその盎前に䞎えた肥料 (盎前の肥料) の組み合わせによる苗朚の成長床合いを調べ、以䞋の「成長床衚」を䜜成したした。 </p> <table> <tr> <td style="vertical-align:top"> <p> 右衚の 1 行目は今回䞎える肥料の番号で、1 列目はその盎前に䞎えた肥料の番号です。他の数字は盎前に䞎えた肥料ず今回䞎える肥料の組み合わせによる苗朚の成長床 (成長埌察成長前の倧きさの比率) を瀺したす。成長床 &gt; 1.0 の堎合は苗朚が䌞びる、成長床 &lt; 1.0 の堎合は苗朚が瞮むこずを瀺したす。䟋えば肥料 1 の埌に肥料 2 を䞎えるず苗朚の倧きさが 3 倍になるが、肥料 1 の埌に肥料 3 を䞎えるず苗朚の倧きさが半分に瞮んでしたいたす。 </p> </td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_babyTree1"> </td> </tr> </table> <br/> <p> 苗朚に䞎える肥料の回数が制限された堎合、苗朚をできるだけ倧きく育おるにはどの肥料をどのような順で䞎えればよいでしょうか?「成長床衚」がその答え教えおくれたす。䟋ずしお䞊の衚にある肥料を 3 回だけ䞎える堎合、以䞋のように肥料 3 → 肥料 1 → 肥料 2 の順にあげるず最も苗朚が成長したす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_babyTree2"> </center> <br/> <ul> <li> 1 回目の肥料 (肥料 3) では苗朚の倧きさは倉わりたせん。</li> <li> 2 回目の肥料 (肥料 1) では、衚より肥料 3 埌の肥料 1 での成長床が 3.0 なので、苗朚の倧きさは前回の 3.0 倍になりたす。</li> <li> 3 回目の肥料 (肥料 2) では、衚より肥料 1 埌の肥料 2 での成長床が 3.0 なので、苗朚の倧きさはさらに前回の 3.0 倍で、最初の 3.0 &times; 3.0 の 9.0 倍になりたす。</li> </ul> <p> 今床は、サトヌ博士は発明した <var>n</var> 皮類の肥料を党郚調べお、䞊のような「成長床衚」を䜜りあげたしたが、非垞に倧きな衚になっおしたい、肥料の皮類ず䞎える順番を決めるのに倧倉苊劎しおいたす。 </p> <p> そこで博士に代わり、<var>n</var> 皮類の肥料の組み合わせによる苗朚の「成長床衚」䞭の成長床倀郚分を入力ずし、肥料を <var>m</var> 回䞎えた埌の最倧の苗朚の倧きさを求めるプログラムを䜜成しおください。ただし、初めの苗朚の倧きさを 1 ずし、1 回目に䞎える肥料の成長床はどの肥料でも 1.0 ずしたす。なお、肥料は 1 から <var>n</var> たで番号付けされおいたす。 <!--出力する苗朚の倧きさは、小数点第 3 䜍を四捚五入しお、小数点第 2 䜍たで求めおください。--> </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>m</var> <var>g<sub>11</sub></var> <var>g<sub>12</sub></var> ... <var>g<sub>1n</sub></var> <var>g<sub>21</sub></var> <var>g<sub>22</sub></var> ... <var>g<sub>2n</sub></var> : <var>g<sub>n1</sub></var> <var>g<sub>n2</sub></var> ... <var>g<sub>nn</sub></var> </pre> <p> 1 行目に肥料の皮類数 <var>n</var> (2 &le; <var>n</var> &le; 100)、 肥料を䞎える回数 <var>m</var> (1 &le; <var>m</var> &le; 100) が䞎えられたす。 </p> <p> 続く<var>n</var> 行に、肥料 <var>i</var> の埌に肥料 <var>j</var> を䞎えた時の苗朚の成長床 <var>g<sub>ij</sub></var> (0.0 &le; <var>g<sub>ij</sub></var> &le; 10.0, 実数) が䞎えられたす。 </p> <p> デヌタセットの数は 20 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に、最倧の苗朚の倧きさを行に出力したす。出力する苗朚の倧きさは、小数点第 3 䜍を四捚五入しお、小数点第 2 䜍たで求めおください。 </p> <H2>Sample Input</H2> <pre> 3 3 1.3 3.0 0.5 2.4 2.1 1.0 3.0 0.8 1.2 2 2 1.0 1.0 1.0 1.0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 9.00 1.00 </pre>
p02006
<h1>Problem C. Santa's Gift</h1> <!-- Time Limit: 2 sec Memory Limit: 512 MB --> <p> Santa is going to pack gifts into a bag for a family. There are $N$ kinds of gifts. The size and the price of the $i$-th gift ($1 \leq i \leq N$) are $s_i$ and $p_i$, respectively. The size of the bag is $C$, thus Santa can pack gifts so that the total size of the gifts does not exceed $C$. Children are unhappy if they are given multiple items of the same kind gift, so Santa has to choose at most one gift of the same kind per child. </p> <p> In addition, if a child did not receive a gift that the other children in the same family receive, he/she will complain about that. Hence Santa must distribute gifts fairly to all the children of a family, by giving the same set of gifts to each child. In other words, for a family with $k$ children, Santa must pack zero or $k$ items for each kind of gifts. Santa gives one bag to one family, therefore, the total size of the gifts for each family does not exceed $C$. </p> <p> Santa wants to maximize the total price of packed items for a family but does not know the number of children in the family he is going to visit yet. The number seems at most $M$. To prepare all the possible cases, calculate the maximum total price of items for a family with $k$ children for each $1 \leq k \leq M$. </p> <h2>Input</h2> <p> The input consists of a single test case in the following format. </p> <pre> $C$ $N$ $M$ $s_1$ $p_1$ $...$ $s_N$ $p_N$ </pre> <p> The first line contains three integers $C$, $N$ and $M$, where $C$ ($1 \leq C \leq 10^4$) is the size of the bag, $N$ ($1 \leq N \leq 10^4$) is the number of kinds of the gifts, and $M$ ($1 \leq M \leq 10^4$) is the maximum number of children in the family. The $i$-th line of the following $N$ lines contains two integers $s_i$ and $p_i$ ($1 \leq s_i, p_i \leq 10^4$), where $s_i$ and $p_i$ are the size and the price of the $i$-th gift, respectively. </p> <h2>Output</h2> <p> The output should consist of $M$ lines. In the $k$-th line, print the maximum total price of gifts for a family with $k$ children. </p> <h2>Examples</h2> <h2>Sample Input 1</h2> <pre> 6 3 2 1 2 2 10 3 5 </pre> <h2>Output for Sample Input 1</h2> <pre> 17 24 </pre> <h2>Sample Input 2</h2> <pre> 200 5 5 31 41 59 26 53 58 97 93 23 84 </pre> <h2>Output for Sample Input 2</h2> <pre> 235 284 375 336 420 </pre> <h2>Sample Input 3</h2> <pre> 1 1 2 1 1 </pre> <h2>Output for Sample Input 3</h2> <pre> 1 0 </pre> <h2>Sample Input 4</h2> <pre> 2 2 2 1 1 2 100 </pre> <h2>Output for Sample Input 4</h2> <pre> 100 2 </pre>
p00484
<H1>叀本屋(Books) </H1> <p> あなたの町にはJOI 叀本店ずいう老舗の叀本屋がありあなたはJOI 叀本店をよく利甚しおいるそれぞれの本には基準䟡栌が定たっおおりJOI 叀本店に行けばその䟡栌で買い取っおもらえる </p> <p> JOI 叀本店では本を小説,挫画,雑誌など10 皮類のゞャンルに分類しお扱っおいるゞャンルには1から10 たでの番号が付けられおいるJOI 叀本店には同じゞャンルの本をたずめお買い取っおもらうず高倀で買い取っおくれるずいうサヌビスがある具䜓的には同じゞャンルの本をたずめおT 冊買い取っおもらう堎合そのゞャンルの本の䞀冊あたりの買取䟡栌が基準䟡栌よりT - 1 円高くなる䟋えば同じゞャンルで基準䟡栌100 円120 円150 円の本をたずめおJOI 叀本店に売ったずするず買取䟡栌はそれぞれ102 円122 円152 円ずなる </p> <p> さおあなたは䞀身䞊の郜合で急遜匕越しをするこずになったあなたはN 冊の本を持っおいるが新しい䜏居にすべおの本を持っおいくこずは困難なため<i>N</i> 冊の本のうち<i>K</i> 冊をJOI 叀本店に売るこずにした </p> <h2>課題</h2> <p> <i>N</i> 冊の本それぞれの基準䟡栌ずゞャンルの番号が䞎えられるずき合蚈買取䟡栌の最倧倀を求めるプログラムを䜜成せよ </p> <h2>制限</h2> <p> 2 &le; <i>N</i> &le; 2000 &nbsp;&nbsp;&nbsp;あなたが持っおいる本の冊数<br> 1 &le; <i>K</i> &lt; <i>N</i> &nbsp;&nbsp;&nbsp;JOI 叀本店に売る本の冊数<br> 1 &le; <i>C<sub>i</sub></i> &le; 100000 = 10<sup>5</sup> &nbsp;&nbsp;&nbsp;<i>i</i> 番目の本の基準䟡栌<br> 1 &le; <i>G<sub>i</sub></i> &le; 10 &nbsp;&nbsp;&nbsp;<i>i</i> 番目の本のゞャンルの番号 </ul> <h2>入力</h2> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には敎数<i>N</i>, <i>K</i> が空癜を区切りずしお曞かれおおりあなたの持っおいる本の冊数が<i>N</i> でそのうち<i>K</i> 冊をJOI 叀本店に売るこずを衚す </li> <li> 続く<i>N</i> 行にはあなたの持っおいる本の情報が曞かれおいる<i>i</i> + 1 行目(1 &le; <i>i</i> &le; <i>N</i>) には敎数<i>C<sub>i</sub></i>,<i>G<sub>i</sub></i>が空癜を区切りずしお曞かれおおり<i>i</i> 番目の本の基準䟡栌が<i>C<sub>i</sub></i> でゞャンルの番号が<i>G<sub>i</sub></i> であるこずを衚す</li> </ul> <h2>出力</h2> <p> 暙準出力に合蚈買取䟡栌の最倧倀を衚す敎数を1 行で出力せよ </p> <h2>採点基準</h2> <p> 採点甚デヌタのうち<br> 配点の20% 分に぀いおは<i>N</i> &le; 20 を満たす<br> 配点の20% 分に぀いおはすべおの本のゞャンルは1 たたは2 である<br> 配点の10% 分に぀いおはこれら2 ぀の条件の䞡方を満たす<br> 配点の30% 分に぀いおはこれら2 ぀の条件の少なくずも䞀方を満たす<br> </p> <h2>入出力の䟋</h2> <h3>入力䟋</h3> <pre> 7 4 14 1 13 2 12 3 14 2 8 2 16 3 11 2 </pre> <h3>出力䟋</h3> <pre> 60 </pre> <p> この入力䟋では2 番目4 番目6 番目7 番目の4 冊の本を売ったずきゞャンル2 の本の買取䟡栌が1 冊あたり2 円高くなるのでこれらの本の買取䟡栌は以䞋のようになる </p> <table style="margin-left: 50px; margin-right: 50px;"> <tr> <th width="100" align="left">番号</th> <th width="100" align="left">基準䟡栌</th> <th width="100" align="left">ゞャンル</th> <th width="100" align="left">買取䟡栌</th> </tr> <tr> <td> <pre> 2 4 6 7 </pre> </td> <td> <pre> 13 14 16 11 </pre> </td> <td> <pre> 2 2 3 2 </pre> </td> <td> <pre> 15 16 16 13 </pre> </td> </tr> </table> <p> よっお合蚈買取䟡栌は15 + 16 + 16 + 13 = 60 円であるこのずき合蚈買取䟡栌は最倧ずなる </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02143
<h1>Problem G: Painting</h1> <h2>Problem</h2> <p>長さ$N$の数列$X$が䞎えられる。初期状態では$X$の芁玠は党お$0$である。加えお、$M$個の敎数のペア$(A_i, B_i)$が䞎えられる。各ペアに察し以䞋の操䜜を行い、最終的な数列$X$を出力せよ。</p> <li>敎数$j$ $(1 \le j \le N)$に察し、$(A_i+j)$を$B_i$で割った䜙りを$X_j$に加える。</li> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $M$ $A_1$ $B_1$ $A_2$ $B_2$ : $A_M$ $B_M$ </pre> <p> $1$行目に、䞎えられる数列の芁玠数$N$、ペアの数$M$が空癜区切りで䞎えられる。<br> 続く$M$行に、$i$番目のペア$(A_i, B_i)$が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \le N, M \le 10^5$</li> <li>$0 \le A_i < B_i \le 10^9 (1 \le i \le M)$</li> <li>䞎えられる入力は党お敎数である</li> </ul> <h2>Output</h2> <p>操䜜埌の数列を$N$行で出力せよ。$j$行目に$X_j$を出力せよ。</p> <h2>Sample Input 1</h2> <pre> 5 3 1 4 3 7 0 1000 </pre> <h2>Sample Output 1</h2> <pre> 7 10 9 5 8 </pre> <h2>Sample Input 2</h2> <pre> 14 12 1 4 2 3 0 5 1 4 1 2 0 8 0 2 0 10 0 1 0 8 3 10 1 10 </pre> <h2>Sample Output 2</h2> <pre> 15 24 25 31 35 44 32 25 24 15 16 25 31 40 </pre>
p03302
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given two integers <var>a</var> and <var>b</var>. Determine if <var>a+b=15</var> or <var>a\times b=15</var> or neither holds.</p> <p>Note that <var>a+b=15</var> and <var>a\times b=15</var> do not hold at the same time.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq a,b \leq 15</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>a+b=15</var>, print <code>+</code>; if <var>a\times b=15</var>, print <code>*</code>; if neither holds, print <code>x</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>+ </pre> <p><var>4+11=15</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>* </pre> <p><var>3\times 5=15</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>x </pre> <p><var>1+1=2</var> and <var>1\times 1=1</var>, neither of which is <var>15</var>.</p></section> </div> </span>
p01295
<H1><font color="#000">Problem C:</font>Champernowne Constant</H1> <p> Champernown constant is an irrational number represented in decimal by "<span>0.</span>" followed by concatenation of all positive integers in the increasing order. The first few digits of this constant are: 0.123456789101112... </p> <p> Your task is to write a program that outputs the <i>K</i> digits of Chapnernown constant starting at the <i>N</i>-th place for given two natural numbers <i>K</i> and <i>N</i>. </p> <H2>Input</H2> <p> The input has multiple lines. Each line has two positive integers <i>N</i> and <i>K</i> (<i>N</i> &le; 10<sup>9</sup>, <i>K</i> &le; 100) separated by a space. </p> <p> The end of input is indicated by a line with two zeros. This line should not be processed. </p> <H2>Output</H2> <p> For each line, output a line that contains the <i>K</i> digits. </p> <H2>Sample Input</H2> <pre> 4 5 6 7 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 45678 6789101 </pre>
p02840
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have an integer sequence <var>A</var> of length <var>N</var>, where <var>A_1 = X, A_{i+1} = A_i + D (1 \leq i &lt; N )</var> holds.</p> <p>Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.</p> <p>Let <var>S</var> and <var>T</var> be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of <var>S - T</var> are there?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>-10^8 \leq X, D \leq 10^8</var></li> <li><var>1 \leq N \leq 2 \times 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>N</var> <var>X</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible values of <var>S - T</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p><var>A</var> is <var>(4, 6, 8)</var>.</p> <p>There are eight ways for (Takahashi, Aoki) to take the elements: <var>((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4)))</var>, and <var>((4, 6, 8), ())</var>.</p> <p>The values of <var>S - T</var> in these ways are <var>-18, -10, -6, -2, 2, 6, 10</var>, and <var>18</var>, respectively, so there are eight possible values of <var>S - T</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 -3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p><var>A</var> is <var>(3, 0)</var>. There are two possible values of <var>S - T</var>: <var>-3</var> and <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 14 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>49805 </pre></section> </div> </span>
p03752
<span class="lang-en lang-child hidden-lang"> <div id="task-statement"> Max Score: <var>350</var> Points <br/> <section> <h3>Problem Statement</h3> There are <var>N</var> buildings along the line. The <var>i</var>-th building from the left is colored in color <var>i</var>, and its height is currently <var>a_i</var> meters. <br/> Chokudai is a mayor of the city, and he loves colorful thigs. And now he wants to see at least <var>K</var> buildings from the left. <br/> <br/> You can increase height of buildings, but it costs <var>1</var> yens to increase <var>1</var> meters. It means you cannot make building that height is not integer. <br/> You cannot decrease height of buildings. <br/> Calculate the minimum cost of satisfying Chokudai's objective. <br/> Note: "Building <var>i</var> can see from the left" means there are no <var>j</var> exists that (height of building <var>j</var>) ≥ (height of building <var>i</var>) and <var>j &lt; i</var>. <br/> </section> </div> <div class="io-style"> <div class="part"> <section> <h3>Input Format</h3> <pre> <var>N</var> <var>K</var> <var>a_1</var> <var>a_2</var> <var>a_3</var> ... <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output Format</h3> Print the minimum cost in one line. In the end put a line break.<br/> </section> <section> <h3>Constraints</h3> <ul> <li><var>1 ≀ K ≀ N ≀ 15</var></li> <li><var>1 ≀ a_i ≀ 10^9</var></li> </ul> </section> <section> <h3>Scoring</h3> Subtask 1 [<var>120</var> points] <br/> <ul> <li><var>N = K</var></li> </ul> Subtask 2 [<var>90</var> points] <br/> <ul> <li><var>N ≀ 5</var></li> <li><var>a_i ≀ 7</var></li> </ul> Subtask 3 [<var>140</var> points] <br/> <ul> <li>There are no additional constraints.</li> </ul> </section> </div> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 5 5 3949 3774 3598 3469 3424 </pre> </section> <section> <h3>Sample Output 1</h3> <pre> 1541 </pre> The optimal solution is (height of buildings from the left) <var>= [3949, 3950, 3951, 3952, 3953]</var>.<br/> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 5 3 7 4 2 6 4 </pre> </section> <section> <h3>Sample Output 2</h3> <pre> 7 </pre> The optimal solution is (height of buildings from the left) <var>= [7, 8, 2, 9, 4]</var>.<br/> </section> </div> </span>
p01041
<h1>Problem E: Distinct Dictionary</h1> <h2>Background</h2> <p> 蟞曞をこよなく愛する者がいた。圌らは自分だけの蟞曞を䜜るこずが倧奜きである。 そこであなたは圌らの蟞曞に、自由にカスタマむズする機胜を付け加えおあげるこずにした。 </p> <h2>Problem</h2> <p> 初めに、䜕の単語も入っおいない空の蟞曞が存圚する。 <var>N</var>個の文字列<var>S<sub>id</sub></var>ず<var>Q</var>個のク゚リが䞎えられる。 各ク゚リはク゚リの皮類<var>k</var>ず文字列を指す<var>id</var>で䞎えられる。 ク゚リの皮類は以䞋の3぀である。 </p> <ul> <li><var>k</var>=1のずき<var>S<sub>id</sub></var>を蟞曞に远加する。</li> <li><var>k</var>=2のずき<var>S<sub>id</sub></var>を蟞曞から削陀する。</li> <li><var>k</var>=3のずき蟞曞に远加された文字列の䞭で<var>S<sub>id</sub></var>を先頭からの郚分文字列に含み䞔぀蟞曞順最小の文字列の<var>id</var>を出力する。無い堎合は-1を出力する。</li> </ul> <p> 各ク゚リに答えるプログラムを曞いおほしい。 </p> <p> 泚意 入力のサむズが倧きいので高速な入力に察応する圢匏を掚奚する。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>S<sub>1</sub></var> <var>S<sub>2</sub></var> . . . <var>S<sub>N</sub></var> <var>Q</var> <var>k<sub>1</sub></var> <var>id<sub>1</sub></var> <var>k<sub>2</sub></var> <var>id<sub>2</sub></var> . . . <var>k<sub>Q</sub></var> <var>id<sub>Q</sub></var> </pre> <p> 1行目に、1぀の敎数<var>N</var>が䞎えられる。2行目から<var>N</var>+1行に、<var>N</var>個の文字列<var>S<sub>id</sub></var>が䞎えられる。 <var>N</var>+2行目にク゚リの数<var>Q</var>が䞎えられ、続く<var>Q</var>行に各ク゚リの皮類を衚す<var>k</var>ず文字列を指す<var>id</var>が䞎えれる。 </p> <h2>Constraints</h2> <ul> <li>文字列は党お異なる。</li> <li><var>N</var>個の文字列<var>S<sub>id</sub></var>の長さの合蚈は10<sup>6</sup>を超えない。</li> <li>既に蟞曞に远加されおいる文字列が再び远加されるような入力は存圚しない。</li> <li>蟞曞に远加されおいない文字列を削陀するような入力は存圚しない。</li> <li>䞎えられる文字列に含たれる文字は英小文字のみである。</li> <li>1 &le; <var>N</var> &le; 10<sup>5</sup></li> <li>1 &le; <var>id</var> &le; <var>N</var></li> <li>1 &le; <var>Q</var> &le; 10<sup>5</sup></li> <li>1 &le; |<var>S<sub>id</sub></var>| &le; 10<sup>5</sup> (ただし、|<var>s</var>|は文字列<var>s</var>の長さを衚す。)</li> </ul> <h2>Output</h2> <p> ク゚リごずに解答を䞀行に出力せよ。 </p> <h2>Sample Input1</h2> <pre> 3 apple app banana 9 1 1 3 1 3 2 3 3 2 1 1 2 3 1 3 2 3 3 </pre> <h2>Sample Output1</h2> <pre> 1 1 -1 -1 2 -1 </pre> <h2>Sample Input2</h2> <pre> 7 aaaab aaa aaaa aaaaaabc abbbbbc ab abbb 13 1 1 3 2 1 4 3 2 1 3 3 2 2 3 3 3 1 5 1 7 3 6 2 5 3 6 </pre> <h2>Sample Output2</h2> <pre> 1 4 3 4 7 7 </pre>
p03586
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Process the <var>Q</var> queries below.</p> <ul> <li>You are given two integers <var>A_i</var> and <var>M_i</var>. Determine whether there exists a positive integer <var>K_i</var> not exceeding <var>2 × 10^{18}</var> such that <var>A_i^{K_i} ≡ K_i</var> <var>(mod</var> <var>M_i)</var>, and find one if it exists.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq Q \leq 100</var></li> <li><var>0 \leq A_i \leq 10^9(1 \leq i \leq Q)</var></li> <li><var>1 \leq M_i \leq 10^9(1 \leq i \leq Q)</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>Q</var> <var>A_1</var> <var>M_1</var> : <var>A_Q</var> <var>M_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>In the <var>i</var>-th line, print <var>-1</var> if there is no integer <var>K_i</var> that satisfies the condition. Otherwise, print an integer <var>K_i</var> not exceeding <var>2 × 10^{18}</var> such that <var>A_i^{K_i} ≡ K_i</var> <var>(mod</var> <var>M_i)</var>. If there are multiple solutions, any of them will be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 3 8 9 6 10 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 11 9 2 </pre> <p>It can be seen that the condition is satisfied: <var>2^4 = 16 ≡ 4</var> <var>(mod</var> <var>4)</var>, <var>3^{11} = 177147 ≡ 11</var> <var>(mod</var> <var>8)</var>, <var>9^9 = 387420489 ≡ 9</var> <var>(mod</var> <var>6)</var> and <var>10^2 = 100 ≡ 2</var> <var>(mod</var> <var>7)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 177 168 2028 88772 123456789 987654321 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7953 234831584 471523108231963269 </pre></section> </div> </span>
p01411
<H1>E: Entangled with Lottery</H1> <p> ICPC で良い成瞟を収めるには修行が欠かせないうさぎは ICPC で勝ちたいので今日も修行をするこずにした </p> <p> 今日の修行はあみだくじを利甚しお未来を読む力を぀けお運気を高めようずいうものであるもちろん盎感に頌るだけでなく綿密な確率蚈算も欠かせない </p> <p> 今回考えるあみだくじは長さ <i>H</i> + 1 センチメヌトルの瞊棒 <i>N</i> 本からなるうさぎは棒の䞊郚を芋お<i>N</i> 本のうち 1 本を遞ぶこずになる棒の䞋郚には巊から <i>P</i> 本目の棒の堎所にのみ「圓たり」ず曞かれおいるあみだくじにはいく぀かの暪棒が含たれる暪棒の配眮に関しお以䞋の条件を考えよう </p> <ul> <li>各暪棒は<i>a</i> を 1 以䞊 <i>H</i> 以䞋の敎数ずしお瞊棒の䞊端から <i>a</i> センチメヌトルの高さにある</li> <li>各暪棒は隣り合った 2 本の瞊棒のみを結ぶ</li> <li>同じ高さには耇数の暪棒は存圚しない</li> </ul> <p> うさぎはこれらの条件を満たすように <i>M</i> 本の暪棒を匕いたあいにくうさぎは蚘憶力が良いので圓たりの䜍眮や暪棒の䜍眮をすべお芚えおしたっおおりあみだくじを楜しめないそこで友達のねこにさらに暪棒を远加しおもらうこずにした </p> <p> たずうさぎは圓たりを狙っお <i>N</i> 本の棒のうち 1 本を遞ぶその埌ねこは以䞋の操䜜をちょうど <i>K</i> 回行う </p> <ul> <li>暪棒を远加しおも䞊で指定された条件を満たすような堎所のうち 1 箇所を無䜜為に遞ぶここでどの堎所も等確率で遞ばれるものずする遞んだ堎所に暪棒を远加する</li> </ul> <p> そしおうさぎが遞んだ棒が圓たりであったかを刀定する棒の蟿り方は通垞のあみだくじず同様である (暪棒に出䌚うたびに隣の瞊棒に移る)うさぎは可胜な限り圓たりずなる確率を高くしたい </p> <H2>Input</H2> <pre> <i>H</i> <i>N</i> <i>P</i> <i>M</i> <i>K</i> <i>A</i><sub>1</sub> <i>B</i><sub>1</sub> ... <i>A</i><sub><i>M</i></sub> <i>B</i><sub><i>M</i></sub> </pre> <p> <i>A</i><sub><i>i</i></sub>, <i>B</i><sub><i>i</i></sub> (1 &le; <i>i</i> &le; <i>M</i>) はうさぎが匕いた暪棒のうち <i>i</i> 番目のものが瞊棒の䞊端から <i>A</i><sub><i>i</i></sub> センチメヌトルの高さにあり巊から <i>B</i><sub><i>i</i></sub> 本目の瞊棒ず巊から <i>B</i><sub><i>i</i></sub> + 1 本目の瞊棒を結ぶこずを衚す敎数である </p> <p> 2 &le; <i>H</i> &le; 5002 &le; <i>N</i> &le; 1001 &le; <i>P</i> &le; <i>N</i>1 &le; <i>M</i> &le; 1001 &le; <i>K</i> &le; 100<i>M</i> + <i>K</i> &le; <i>H</i>1 &le; <i>A</i><sub>1</sub> &lt; <i>A</i><sub>2</sub> &lt; ... &lt; <i>A</i><sub><i>M</i></sub> &le; <i>H</i>1 &le; <i>B</i><sub><i>i</i></sub> &le; <i>N</i> - 1 を満たす </p> <H2>Output</H2> <p> 圓たりずなる確率が最倧ずなるようにうさぎが棒を遞んだずきの圓たりずなる確率を 1 行に出力せよ10<sup>-6</sup> 以䞋の絶察誀差が蚱容される </p> <H2>Sample Input 1</H2> <pre> 9 4 3 2 1 2 1 7 3 </pre> <H2>Sample Output 1</H2> <pre> 0.571428571 </pre> <H2>Sample Input 2</H2> <pre> 9 4 3 2 3 2 1 7 3 </pre> <H2>Sample Output 2</H2> <pre> 0.375661376 </pre>
p00650
<H1>Problem D: The House of Huge Family</H1> <p> Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future. </p> <p> Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as that of town. </p> <p> They all had warm and gracious personality and were close each other. However, in this year the two members of them became to hate each other. Since the two members had enormous influence in the family, they were split into two groups. </p> <p> They hope that the two groups don't meet each other in the new house. Though they are in the same building, they can avoid to meet each other by adjusting passageways. </p> <p> Now, you have a figure of room layout. Your task is written below. </p> <p> You have to decide the two groups each room should belong to. Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group. All of the rooms need to belong to exactly one group. And any group has at least one room. </p> <p> To do the task, you can cancel building passageway. Because the house is under construction, to cancel causes some cost. You'll be given the number of rooms and information of passageway. You have to do the task by the lowest cost. </p> <p> Please answer the lowest cost. </p> <p> By characteristics of Mr. Dango's family, they move very slowly. So all passageways are escalators. Because of it, the passageways are one-way. </p> <h2>Input</h2> <p> The input consists of multiple datasets. Each dataset is given in the following format. </p> <pre> <i>n</i> <i>m</i> <i>X<sub>1</sub> Y<sub>1</sub> C<sub>1</sub></i> ... <i>X<sub>m</sub> Y<sub>m</sub> C<sub>m</sub></i> </pre> <p> All numbers in each datasets are integers. The integers in each line are separated by a space. </p> <p> The first line of each datasets contains two integers. <i>n</i> is the number of rooms in the house, m is the number of passageways in the house. Each room is indexed from 0 to <i>n</i>-1. </p> <p> Each of following <i> m </i> lines gives the details of the passageways in the house. Each line contains three integers. The first integer <i>X<sub>i</sub></i> is an index of the room, the starting point of the passageway. The second integer <i>Y<sub>i</sub></i> is an index of the room, the end point of the passageway. The third integer <i>C<sub>i</sub></i> is the cost to cancel construction of the passageway. The passageways, they are escalators, are one-way. The last dataset is followed by a line containing two zeros (separated by a space). </p> <H2>Constraints</h2> <ul> <li>2 &le; <i> n </i> &le; 100</li> <li>-10,000 &le; <i>C<sub>i</sub></i> &le; 10,000</li> <li><i>Y<sub>1</sub></i> ... <i>Y<sub>m</sub></i> can't be duplicated integer by each other.</li> </ul> <h2>Output</h2> <p> For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers. </p> <h2>Sample input</h2> <pre> 3 2 0 1 2 1 2 1 2 1 0 1 100 2 1 0 1 0 2 1 0 1 -1 0 0 </pre> <h2>Sample output</h2> <pre> 1 100 0 -1 </pre>
p01942
<h2>E たい焌きマスタヌず食べ盛り - Taiyaki-Master and Eater</h2> <h3>物語</h3> <p>぀たさんはたい焌きを䜜るのがずおも䞊手い。えびちゃんはそんな぀たさんが䜜るたい焌きが倧奜きだ。 <var>2</var> 人は毎週たい焌きを䜜っお食べお幞せに過ごしおいるが、たい焌きを䜜っおいるそばで食べ盛りのえびちゃんに぀たみ食いをされおしたうのが぀たさんの最近の悩みだ。</p> <p>孊校祭でたい焌きを䜜るこずになった぀たさんは、い぀ものようにえびちゃんに぀たみ食いされおいたら売䞊が心配なので、自分が泚目しおいる範囲のたい焌きの様子を知るこずができればいいなず思った。孊校祭が成功するように、぀たさんを助けおあげよう。</p> <h3>問題</h3> <p>瞊 <var>H</var>、暪 <var>W</var> の長方圢状のたい焌きプレヌトがあり、たい焌きをセットしおから焌き䞊がるたでに <var>T</var> 分かかる。このプレヌトはたい焌きを䞀床に最倧 <var>HW</var> 個焌くこずができ、プレヌトの䞊から <var>i</var> <var>(1 \leq i \leq H)</var> 番目で巊から <var>j</var> <var>(1 \leq j \leq W)</var> 番目の堎所で焌いおいるたい焌きは <var>(i, j)</var> で衚される。</p> <p>次の <var>3</var> 皮類のむベントが合蚈 <var>Q</var> 回発生する。なお、初期状態ではたい焌きはいずれの堎所にもセットされおいない。</p> <ul> <li>時刻 <var>t</var> に぀たさんが <var>(h, w)</var> にたい焌きを <var>1</var> ぀セットする。そのたい焌きは <var>T</var> 分で焌き䞊がり、時刻 <var>t+T</var> の時点で食べるこずができるようになる。ただし、すでにたい焌きがセットされおいる堎所にたい焌きをセットするこずはない。</li> <li>時刻 <var>t</var> に、えびちゃんが <var>(h, w)</var> にあるたい焌きを぀たみ食いしようずする。ただし、<b>぀たみ食いできるのはすでに焌き䞊がったたい焌きのみである</b>。぀たみ食いした埌はその堎所からたい焌きが無くなる (すなわち、たい焌きがセットされおいない状態になる)。たい焌きが焌き䞊がっおいない、たたはたい焌きがない堎所にも぀たみ食いのむベントが発生する堎合があるこずに泚意せよ。</li> <li>巊䞊が <var>(h_1, w_1)</var>、右䞋が <var>(h_2, w_2)</var> ずなるような長方圢領域内 (<var>(h_1, w_1)</var> および <var>(h_2, w_2)</var> を含む) のたい焌きに぀いお、次の数が時刻 <var>t</var> の時点でそれぞれいく぀であるかを぀たさんがカりントする。</li> <ul> <li>すでに焌き䞊がったたい焌きの数</li> <li>ただ焌き䞊がっおいないたい焌きの数</li> </ul> </ul> <h3>入力圢匏</h3> <pre> <var>H</var> <var>W</var> <var>T</var> <var>Q</var> <var>t_1</var> <var>c_1</var> <var>h_{11}</var> <var>w_{11}</var> <var>(h_{12}</var> <var>w_{12})</var> <var>t_2</var> <var>c_2</var> <var>h_{21}</var> <var>w_{21}</var> <var>(h_{22}</var> <var>w_{22})</var> <var>
</var> <var>t_Q</var> <var>c_Q</var> <var>h_{Q1}</var> <var>w_{Q1}</var> <var>(h_{Q2}</var> <var>w_{Q2})</var> </pre> <p>入力は党お敎数で䞎えられる。</p> <p><var>1</var> 行目には、たい焌きプレヌトの瞊 <var>H</var>、 暪 <var>W</var>、 たい焌きをセットしおから焌きあがるたでの時間 <var>T</var>、 むベントの数 <var>Q</var> が䞎えられる。</p> <p><var>1+i</var> <var>(1 \leq i \leq Q)</var> 行目には、時刻 <var>t_i</var> で発生したむベントの内容が䞎えられる。</p> <ul> <li><var>c_i</var> はむベントの皮類を衚す。この倀が <var>0</var> ならばたい焌きをセットするむベント、 <var>1</var> ならば぀たみ食いをするむベント、 <var>2</var> ならばたい焌きをカりントするむベントを指す。</li> <li><var>h_{i1}</var> <var>(1 \leq h_{i1} \leq H)</var>、<var>w_{i1}</var> <var>(1 \leq w_{i1} \leq W)</var> は、<var>c_i = 0, 1</var> においお次のような意味である。</li> <ul> <li><var>c_i = 0</var> のずき、<var>(h_{i1}, w_{i1})</var> の堎所にたい焌きを1぀セットする。</li> <li><var>c_i = 1</var> のずき、<var>(h_{i1}, w_{i1})</var> の堎所に焌き䞊がった状態のたい焌きがあれば぀たみ食いをし、そうでなければ䜕もしない。</li> </ul> <li><var>h_{i2}</var>、<var>w_{i2}</var> は、<var>c_i = 2</var> のずきのみ䞎えられる。</li> <ul> <li><var>c_i = 2</var> のずき、巊䞊を <var>(h_{i1}, w_{i1})</var>、 右䞋を <var>(h_{i2}, w_{i2})</var> ずする長方圢領域内のたい焌きに぀いおカりントする。</li> </ul> </ul> <p>入出力が非垞に倚くなるこずが予想されるため、入出力に遅い関数を䜿っおいる堎合は泚意しおください。</p> <h3>制玄</h3> <ul> <li> <var>1 \leq H \leq 2 \times 10^3</var></li> <li> <var>1 \leq W \leq 2 \times 10^3</var></li> <li> <var>1 \leq T \leq 10^9</var></li> <li> <var>1 \leq Q \leq 10^5</var></li> <li> <var>1 \leq t_i \leq 10^9</var></li> <li> <var>i \lt j</var> ならば、 <var>t_i \lt t_j</var></li> <li> <var>0 \leq c_i \leq 2</var></li> <li> <var>1 \leq h_{i1} \leq h_{i2} \leq H</var></li> <li> <var>1 \leq w_{i1} \leq w_{i2} \leq W</var></li> </ul> <h3>出力圢匏</h3> <p>(<var>c_i = 2</var> <var>(1 \leq i \leq Q)</var> の個数) を <var>n</var> ずする。たい焌きのカりントの結果を、次の曞き方に埓っおむベントの発生時間が早い順に <var>n</var> 行に出力せよ。</p> <pre> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>
</var> <var>a_n</var> <var>b_n</var> </pre> <ul> <li><var>a_i</var> は、領域内にある「焌き䞊がったたい焌きの数」である。</li> <li><var>b_i</var> は、領域内にある「ただ焌き䞊がっおいないたい焌きの数」である。</li> <li>末尟の改行を忘れないこず。</li> </ul> <h3>入力䟋1</h3> <pre> 3 3 3 6 1 0 1 1 2 2 1 1 2 2 3 1 1 1 4 0 2 1 5 2 1 1 2 2 6 2 2 1 3 3 </pre> <h3>出力䟋1</h3> <pre> 0 1 1 1 0 1 </pre> <p>この入出力䟋では以䞋のむベントが発生しおいる。</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t01" type="image/png" width="300"></img> <ul> <li>時刻 <var>1</var> 分に、<var>(1, 1)</var> にたい焌きをセットする。このたい焌きは時刻 <var>4</var> 分に焌き䞊がる。</li> </ul> <img data="IMAGE3/ACPC2017Day3/HUPC2017/aizu17-e-t02.png" type="image/png" width="300"></img> <ul> <li>時刻 <var>2</var> 分に、巊䞊 <var>(1, 1)</var>、右䞋 <var>(2, 2)</var> の長方圢領域にあるたい焌きをカりントする。<var>(1, 1)</var> にセットしたたい焌きはただ焌き䞊がっおいないため、<code>0 1</code> を出力する。</li> </ul> <ul> <li>時刻 <var>3</var> 分に、<var>(1, 1)</var> にあるたい焌きを぀たみ食いしようずするが、ただ焌き䞊がっおいないので䜕もしない。</li> </ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t04" type="image/png" width="300"></img> <ul> <li>時刻 <var>4</var> 分に、<var>(2, 1)</var> にたい焌きをセットする。このたい焌きは時刻 <var>7</var> 分に焌き䞊がる。</li> </ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t05" type="image/png" width="300"></img> <ul> <li>時刻 <var>5</var> 分に、巊䞊 <var>(1, 1)</var>、右䞋 <var>(2, 2)</var> の長方圢領域にあるたい焌きをカりントする。<var>(1, 1)</var> のたい焌きは焌き䞊がっおおり、 <var>(2, 1)</var> のたい焌きはただ焌き䞊がっおいないため、<code>1 1</code> を出力する。</li> </ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t06" type="image/png" width="300"></img> <ul> <li>時刻 <var>6</var> 分に、巊䞊 <var>(2, 1)</var>、右䞋 <var>(3, 3)</var> の長方圢領域にあるたい焌きをカりントする。<var>(2, 1)</var> のたい焌きはただ焌き䞊がっおいないため、<code>0 1</code> を出力する。</li> </ul>
p02397
<H1>Swapping Two Numbers</H1> <p> Write a program which reads two integers <var>x</var> and <var>y</var>, and prints them in ascending order. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset consists of two integers <var>x</var> and <var>y</var> separated by a single space. </p> <p> The input ends with two 0 (when both <var>x</var> and <var>y</var> are zero). Your program should not process for these terminal symbols. </p> <H2>Output</H2> <p> For each dataset, print <var>x</var> and <var>y</var> in ascending order in a line. Put a single space between <var>x</var> and </var>y</var>. </p> <h2>Constraints</h2> <ul> <li> 0 &le; <var>x</var>, <var>y</var> &le; 10000</li> <li> the number of datasets &le; 3000</li> </ul> <H2>Sample Input</H2> <pre> 3 2 2 2 5 3 0 0 </pre> <H2>Sample Output</H2> <pre> 2 3 2 2 3 5 </pre>
p00200
<h1>青春の片道切笊</h1> <p> 倪郎君は倏䌑みに電車で長旅をする蚈画を立おおいたす。しかし高校生の身である倪郎君が䞀ヵ月しかない倏䌑みで可胜な限り遠くに旅をするには、出来るだけ安い行き方ず出来るだけ早い行き方をそれぞれ芋぀けなければうたく蚈画が立おられたせん。倪郎君が玠敵な旅を満喫できるように、倪郎君の蚈画の助けになるプログラムを䜜っおあげたしょう。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_trip"> </center> <br><br> <p> 線路の情報、駅の数を入力ずし、問い合わせに応じお、最小金額たたは最短時間を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>m</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>cost<sub>1</sub></var> <var>time<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>cost<sub>2</sub></var> <var>time<sub>2</sub></var> : <var>a<sub>n</sub></var> <var>b<sub>n</sub></var> <var>cost<sub>n</sub></var> <var>time<sub>n</sub></var> <var>k</var> <var>p<sub>1</sub></var> <var>q<sub>1</sub></var> <var>r<sub>1</sub></var> <var>p<sub>2</sub></var> <var>q<sub>2</sub></var> <var>r<sub>2</sub></var> : <var>p<sub>k</sub></var> <var>q<sub>k</sub></var> <var>r<sub>k</sub></var> </pre> <p> 1 行目に線路の情報の数 <var>n</var> (1 &le; <var>n</var> &le; 3000)ず駅の数 <var>m</var> (1 &le; <var>m</var> &le; 100) が䞎えられたす。 </p> <p> 続く <var>n</var> 行に <var>i</var> 番目の路線の情報が䞎えられたす。各路線の情報ずしお、路線が぀なぐ぀の駅の番号 <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> &le; <var>m</var>)、料金 <var>cost<sub>i</sub></var> (1 &le; <var>cost<sub>i</sub></var> &le; 1000)、移動時間 <var>time<sub>i</sub></var> (1 &le; <var>time<sub>i</sub></var> &le; 1000) が䞎えられたす。ただし、各駅は 1 から <var>m</var> たで順番に番号が付けられおいるものずしたす。 なお、<var>a<sub>i</sub></var> ず <var>b<sub>i</sub></var> が線路で぀ながっおいれば、<var>a<sub>i</sub></var> から <var>b<sub>i</sub></var>、 <var>b<sub>i</sub></var> から<var>a<sub>i</sub></var> の䞡方の移動が同じ料金ず時間で可胜ずしたす。 </p> <p> 続く行に問い合わせの数 <var>k</var> (1 &le; <var>k</var> &le; 200) が䞎えられたす。続く <var>k</var> 行に <var>i</var> 番目の問い合わせが䞎えられたす。各問合わせずしお、出発駅 <var>p<sub>i</sub></var> 、到着駅 <var>q<sub>i</sub></var> 、出力する倀の皮類 <var>r<sub>i</sub></var> (0 たたは 1)が䞎えられたす。なお、問い合わせには必ず経路があるものずしたす。 </p> <p> デヌタセットの数は 50 を超えない。 </p> <H2>Output</H2> <p> デヌタセットごずに、最小金額もしくは最短時間を行に出力したす。<var>r<sub>i</sub></var> が 0 の時は最小金額を、 1 の時は最短時間を出力したす。 </p> <H2>Sample Input</H2> <pre> 6 5 1 2 200 10 1 4 400 15 1 3 250 25 2 4 100 10 4 5 150 20 3 5 300 20 2 1 5 0 1 5 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 450 35 </pre>
p00715
<H1> <font color="#000">Problem F:</font> Name the Crossing </H1> <P> The city of Kyoto is well-known for its Chinese plan: streets are either North-South or East-West. Some streets are numbered, but most of them have real names. <br> Crossings are named after the two streets crossing there, e.g. Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo street. But there is a problem: which name should come first? At first the order seems quite arbitrary: one says Kawaramachi-Sanjo (North-South first) but Shijo-Kawaramachi (East-West first). With some experience, one realizes that actually there seems to be an "order" on the streets, for instance in the above Shijo is "stronger" than Kawaramachi, which in turn is "stronger" than Sanjo. One can use this order to deduce the names of other crossings. </P> <P> You are given as input a list of known crossing names X-Y. Streets are either North-South or East-West, and only orthogonal streets may cross. </P> <P> As your list is very incomplete, you start by completing it using the following rule: </P> <ul> <li> two streets A and B have <i>equal strength</i> if (1) to (3) are all true: <ol> <li> they both cross the same third street C in the input </li> <li> there is no street D such that D-A and B-D appear in the input </li> <li> there is no street E such that A-E and E-B appear in the input </li> </ol> </li> </ul> <P> We use this definition to extend our strength relation: </P> <ul> <li> A is <i>stronger</i> than B, when there is a sequence A = A<sub>1</sub>, A<sub>2</sub>, ..., A<sub><i>n</i></sub> = B, with <i>n</i> at least 2, <br> where, for any <i>i</i> in 1 .. <i>n</i>-1, either A<sub><i>i</i></sub>-A<sub><i>i</i>+1</sub> is an input crossing or A<sub><i>i</i></sub> and A<sub><i>i</i>+1</sub> have equal strength. </li> </ul> <P> Then you are asked whether some other possible crossing names X-Y are valid. You should answer affirmatively if you can infer the validity of a name, negatively if you cannot. Concretely: </P> <ul> <li> YES if you can infer that the two streets are orthogonal, and X is stronger than Y </li> <li> NO otherwise </li> </ul> <H2>Input</H2> <P> The input is a sequence of data sets, each of the form </P> <blockquote> <pre><i>N Crossing<sub>1</sub> ... Crossing<sub>N</sub> M Question<sub>1</sub> ... Question<sub>M</sub> </i></pre> </blockquote> <P> Both <i>Crossing</i>s and <i>Question</i>s are of the form </P> <blockquote> <i>X-Y</i> </blockquote> <P> where <i>X</i> and <i>Y</i> are strings of alphanumerical characters, of lengths no more than 16. There is no white space, and case matters for alphabetical characters. <br> <i>N</i> and <i>M</i> are between 1 and 1000 inclusive, and there are no more than 200 streets in a data set. </P> <P> The last data set is followed by a line containing a zero. </P> <H2>Output</H2> <P> The output for each data set should be composed of <i>M</i>+1 lines, the first one containing the number of streets in the <i>Crossing</i> part of the input, followed by the answers to each question, either YES or NO without any spaces. </P> <H2>Sample Input</H2> <PRE> 7 Shijo-Kawaramachi Karasuma-Imadegawa Kawaramachi-Imadegawa Nishioji-Shijo Karasuma-Gojo Torimaru-Rokujo Rokujo-Karasuma 6 Shijo-Karasuma Imadegawa-Nishioji Nishioji-Gojo Shijo-Torimaru Torimaru-Gojo Shijo-Kawabata 4 1jo-Midosuji Midosuji-2jo 2jo-Omotesando Omotesando-1jo 4 Midosuji-1jo 1jo-Midosuji Midosuji-Omotesando 1jo-1jo 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> 8 YES NO YES NO YES NO 4 YES YES NO NO </PRE>