question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00725
<h1><font color="#000">Problem D:</font> Curling 2.0</h1><!-- end en only --> <p> On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only a single stone. The purpose of the game is to lead the stone from the start to the goal with the minimum number of moves. </p> <!-- end en only --> <!-- begin en only --> <p> Fig. D-1 shows an example of a game board. Some squares may be occupied with blocks. There are two special squares namely the start and the goal, which are not occupied with blocks. (These two squares are distinct.) Once the stone begins to move, it will proceed until it hits a block. In order to bring the stone to the goal, you may have to stop the stone by hitting it against a block, and throw again. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fig0"> <!-- begin en only --> <br> Fig. D-1: Example of board (S: start, G: goal) <!-- end en only --> </center> <!-- begin en only --> <p> The movement of the stone obeys the following rules: </p><ul> <li> At the beginning, the stone stands still at the start square. </li><li> The movements of the stone are restricted to x and y directions. Diagonal moves are prohibited. </li><li> When the stone stands still, you can make it moving by throwing it. You may throw it to any direction unless it is blocked immediately(Fig. D-2(a)). </li><li> Once thrown, the stone keeps moving to the same direction until one of the following occurs: <ul> <li> The stone hits a block (Fig. D-2(b), (c)). <ul> <li> The stone stops at the square next to the block it hit. </li><li> The block disappears. </li></ul> </li><li> The stone gets out of the board. <ul> <li> The game ends in failure. </li></ul> </li><li> The stone reaches the goal square. <ul> <li> The stone stops there and the game ends in success. </li></ul> </li></ul> </li><li> You cannot throw the stone more than 10 times in a game. If the stone does not reach the goal in 10 moves, the game ends in failure. </li></ul> <p></p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_move"> <!-- begin en only --> <br> Fig. D-2: Stone movements <!-- end en only --> </center> <!-- begin en only --> <p> Under the rules, we would like to know whether the stone at the start can reach the goal and, if yes, the minimum number of moves required. </p><p> With the initial configuration shown in Fig. D-1, 4 moves are required to bring the stone from the start to the goal. The route is shown in Fig. D-3(a). Notice when the stone reaches the goal, the board configuration has changed as in Fig. D-3(b). </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_solution"> <!-- begin en only --> <br> Fig. D-3: The solution for Fig. D-1 and the final board configuration <!-- end en only --> <br> </center> <h2>Input</h2> <!-- begin en only --> <p>The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets never exceeds 100. <!-- end en only --> </p> <!-- begin en only --> <p> Each dataset is formatted as follows. </p> <blockquote> <i>the width(=w) and the height(=h) of the board</i> <br> <i>First row of the board</i> <br> ... <br> <i>h-th row of the board</i> <br> </blockquote> <p>The width and the height of the board satisfy: 2 &lt;= <i>w</i> &lt;= 20, 1 &lt;= <i>h</i> &lt;= 20. <br> Each line consists of <i>w</i> decimal numbers delimited by a space. The number describes the status of the corresponding square. <blockquote><table> <tbody><tr><td> 0 </td><td>vacant square</td></tr> <tr><td> 1 </td><td>block</td></tr> <tr><td> 2 </td><td>start position</td></tr> <tr><td> 3 </td><td>goal position</td></tr> </tbody></table></blockquote> <!-- end en only --> <p></p> <!-- begin en only --> <p> The dataset for Fig. D-1 is as follows: </p> <!-- end en only --> <blockquote> 6 6 <br> 1 0 0 2 1 0 <br> 1 1 0 0 0 0 <br> 0 0 0 0 0 3 <br> 0 0 0 0 0 0 <br> 1 0 0 0 0 1 <br> 0 1 1 1 1 1 <br> </blockquote> <h2>Output</h2> <!-- begin en only --> <p> For each dataset, print a line having a decimal integer indicating the minimum number of moves along a route from the start to the goal. If there are no such routes, print -1 instead. Each line should not have any character other than this number. </p> <!-- end en only --> <h2>Sample Input</h2> <pre> 2 1 3 2 6 6 1 0 0 2 1 0 1 1 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 1 1 6 1 1 1 2 1 1 3 6 1 1 0 2 1 1 3 12 1 2 0 1 1 1 1 1 1 1 1 1 3 13 1 2 0 1 1 1 1 1 1 1 1 1 1 3 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 1 4 -1 4 10 -1 </pre>
p01564
<h1>Do use segment tree</h1> <p>Given a tree with <var>n</var> <var>(1 &le; n &le; 200,000)</var> nodes and a list of <var>q</var> <var>(1 &le; q &le; 100,000)</var> queries, process the queries in order and output a value for each output query. The given tree is connected and each node on the tree has a weight <var>w<sub>i</sub></var> <var>(-10,000 &le; w<sub>i</sub> &le; 10,000)</var>. </p> <p>Each query consists of a number <var>t<sub>i</sub></var> <var>(t<sub>i</sub> = 1, 2)</var>, which indicates the type of the query , and three numbers <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> and <var>c<sub>i</sub></var> <var>(1 &le; a<sub>i</sub>, b<sub>i</sub> &le; n, -10,000 &le; c<sub>i</sub> &le; 10,000)</var>. Depending on the query type, process one of the followings: </p><ul><li><p> (<var>t<sub>i</sub> = 1</var>: modification query) Change the weights of all nodes on the shortest path between <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> (both inclusive) to <var>c<sub>i</sub></var>. </p></li><li><p> (<var>t<sub>i</sub> = 2</var>: output query) First, create a list of weights on the shortest path between <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> (both inclusive) in order. After that, output the maximum sum of a non-empty continuous subsequence of the weights on the list. <var>c<sub>i</sub></var> is ignored for output queries. </p></li></ul> <h2>Input</h2> <p>The first line contains two integers <var>n</var> and <var>q</var>. On the second line, there are <var>n</var> integers which indicate <var>w<sub>1</sub></var>, <var>w<sub>2</sub></var>, ... , <var>w<sub>n</sub></var>. </p> <p>Each of the following <var>n - 1</var> lines consists of two integers <var>s<sub>i</sub></var> and <var>e<sub>i</sub></var> <var>(1 &le; s<sub>i</sub>, e<sub>i</sub> &le; n)</var>, which means that there is an edge between <var>s<sub>i</sub></var> and <var>e<sub>i</sub></var>. </p> <p> Finally the following <var>q</var> lines give the list of queries, each of which contains four integers in the format described above. Queries must be processed one by one from top to bottom. </p> <h2>Output</h2> <p>For each output query, output the maximum sum in one line. </p> <h2>Sample Input 1</h2> <pre>3 4 1 2 3 1 2 2 3 2 1 3 0 1 2 2 -4 2 1 3 0 2 2 2 0 </pre> <h2>Output for the Sample Input 1</h2> <pre>6 3 -4 </pre> <h2>Sample Input 2</h2> <pre>7 5 -8 5 5 5 5 5 5 1 2 2 3 1 4 4 5 1 6 6 7 2 3 7 0 2 5 2 0 2 4 3 0 1 1 1 -1 2 3 7 0 </pre> <h2>Output for the Sample Input 2</h2> <pre>12 10 10 19 </pre> <h2>Sample Input 3</h2> <pre>21 30 10 0 -10 -8 5 -5 -4 -3 1 -2 8 -1 -7 2 7 6 -9 -6 3 4 9 10 3 3 2 3 12 12 4 4 13 4 9 10 21 21 1 1 11 11 14 1 15 10 6 6 17 6 16 6 5 5 18 5 19 10 7 10 8 8 20 1 1 21 -10 1 3 19 10 2 1 13 0 1 4 18 8 1 5 17 -5 2 16 7 0 1 6 16 5 1 7 15 4 2 4 20 0 1 8 14 3 1 9 13 -1 2 9 18 0 1 10 12 2 1 11 11 -8 2 21 15 0 1 12 10 1 1 13 9 7 2 6 14 0 1 14 8 -2 1 15 7 -7 2 10 2 0 1 16 6 -6 1 17 5 9 2 12 17 0 1 18 4 6 1 19 3 -3 2 11 8 0 1 20 2 -4 1 21 1 -9 2 5 19 0 </pre> <h2>Output for the Sample Input 3</h2> <pre>20 9 29 27 10 12 1 18 -2 -3 </pre>
p03559
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.</p> <p>He has <var>N</var> parts for each of the three categories. The size of the <var>i</var>-th upper part is <var>A_i</var>, the size of the <var>i</var>-th middle part is <var>B_i</var>, and the size of the <var>i</var>-th lower part is <var>C_i</var>.</p> <p>To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.</p> <p>How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used 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>1 \leq A_i \leq 10^9(1\leq i\leq N)</var></li> <li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li> <li><var>1 \leq C_i \leq 10^9(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>A_1</var> <var>...</var> <var>A_N</var> <var>B_1</var> <var>...</var> <var>B_N</var> <var>C_1</var> <var>...</var> <var>C_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of different altars that Ringo can build.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 5 2 4 3 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The following three altars can be built:</p> <ul> <li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>1</var>-st part</li> <li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>2</var>-nd part</li> <li>Upper: <var>1</var>-st part, Middle: <var>2</var>-nd part, Lower: <var>2</var>-nd part</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 1 1 2 2 2 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>27 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 3 14 159 2 6 53 58 9 79 323 84 6 2643 383 2 79 50 288 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>87 </pre></section> </div> </span>
p01134
<h1><font color="#000000">Problem D:</font> Area Separation</h1> <p> Mr. Yamada Springfield Tanaka は、囜家区画敎理事業局局長補䜐代理ずいう倧任を任されおいた。 珟圚、圌の囜は倧芏暡な区画敎理の最䞭であり、この区画敎理をスムヌズに終わらせるこずができたならば圌の昇進は間違いなしであるずされおいる。 </p> <p> ずころが、そんな圌の出䞖を快く思わない者も倚くいるのだ。 そんな人間の 1 人に、Mr.Sato Seabreeze Suzuki がいた。 圌は、こずあるごずに Mr. Yamada の足を匕っ匵ろうず画策しおきた。 今回も Mr. Sato は足を匕っ匵るために、実際の区画敎理を担圓しおいる組織に圧力をかけお、区画敎理の結果を非垞に分かりにくいものにしおしたった。 </p> <p> そのため、Mr. Yamada に枡された結果は、 ある正方圢の土地をどの盎線で分割したかずいう情報のみになっおいた。 最䜎限、その正方圢の土地がいく぀に分割されたかだけでも分からなければ、Mr. Yamada は昇進どころか解雇されるこず間違いなしである。 </p> <p> あなたの仕事は、(-100,-100)、(100,-100)、(100,100)、(-100,100) を頂点ずする正方圢領域が、䞎えられた <i>n</i> 本の盎線によっおいく぀に分割されおいるかを調べるプログラムを曞いお、Mr. Yamada を解雇の危機から救うこずである。 </p> <h2>Input</h2> <p> 入力は耇数のテストケヌスからなる。 </p> <p> それぞれのテストケヌスの最初の行では、盎線数を衚す敎数 <i>n</i> が䞎えられる1 &lt;= <i>n</i> &lt;= 100。 その埌の <i>n</i> 行にはそれぞれ 4 ぀の敎数 <i>x</i><sub>1</sub> 、<i>y</i><sub>1</sub> 、 <i>x</i><sub>2</sub> 、<i>y</i><sub>2</sub> が含たれる。 これらの敎数は盎線䞊の盞異なる 2 点 (<i>x</i><sub>1</sub> , <i>y</i><sub>1</sub> ) ず (<i>x</i><sub>2</sub> , <i>y</i><sub>2</sub> ) を衚す。 䞎えられる 2 点は垞に正方圢の蟺䞊の点であるこずが保蚌されおいる。 䞎えられる <i>n</i> 本の盎線は互いに異なり、盎線同士が重なるこずはない。 たた、盎線が正方圢の蟺ず重なるこずもない。 </p> <p> 入力の終了は <i>n</i> = 0 で衚される。 </p> <h2>Output</h2> <p> それぞれのテストケヌスに぀いお、<i>n</i> 本の盎線によっお分割された領域の数を 1 行で出力せよ。 </p> <p> なお、距離が 10<sup>-10</sup> 未満の 2 点は䞀臎するずみなしおよい。 たた、|PQ| &lt; 10<sup>-10</sup>、|QR| &lt; 10<sup>-10</sup> でか぀ |PR| &gt;= 10<sup>-10</sup>ずなるような亀点の組 P、Q、R は存圚しない。 </p> <h2>Sample Input</h2> <pre> 2 -100 -20 100 20 -20 -100 20 100 2 -100 -20 -20 -100 20 100 100 20 0 </pre> <h2>Output for the Sample Input</h2> <pre> 4 3 </pre>
p03109
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> as input. This represents a valid date in the year <var>2019</var> in the <code>yyyy/mm/dd</code> format. (For example, April <var>30</var>, <var>2019</var> is represented as <code>2019/04/30</code>.)</p> <p>Write a program that prints <code>Heisei</code> if the date represented by <var>S</var> is not later than April <var>30</var>, <var>2019</var>, and prints <code>TBD</code> otherwise.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is a string that represents a valid date in the year <var>2019</var> in the <code>yyyy/mm/dd</code> format.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>Heisei</code> if the date represented by <var>S</var> is not later than April <var>30</var>, <var>2019</var>, and print <code>TBD</code> otherwise.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2019/04/30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Heisei </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2019/11/01 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>TBD </pre></section> </div> </span>
p01421
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Reverse Roads</H1> <p> ICP city has an express company whose trucks run from the crossing <var>S</var> to the crossing <var>T</var>. The president of the company is feeling upset because all the roads in the city are one-way, and are severely congested. So, he planned to improve the maximum flow (edge disjoint paths) from the crossing <var>S</var> to the crossing <var>T</var> by reversing the traffic direction on some of the roads. </p> <p> Your task is writing a program to calculate the maximized flow from <var>S</var> to <var>T</var> by reversing some roads, and the list of the reversed roads. </p> <H2>Input</H2> <p> The first line of a data set contains two integers <var>N</var> (<var>2 \leq N \leq 300</var>) and <var>M</var> (<var>0 \leq M \leq {\rm min} (1\,000,\ N(N-1)/2)</var>). <var>N</var> is the number of crossings in the city and <var>M</var> is the number of roads. </p> <p> The following <var>M</var> lines describe one-way roads in the city. The <var>i</var>-th line (<var>1</var>-based) contains two integers <var>X_i</var> and <var>Y_i</var> (<var>1 \leq X_i, Y_i \leq N</var>, <var>X_i \neq Y_i</var>). <var>X_i</var> is the ID number (<var>1</var>-based) of the starting point of the <var>i</var>-th road and <var>Y_i</var> is that of the terminal point. The last line contains two integers <var>S</var> and <var>T</var> (<var>1 \leq S, T \leq N</var>, <var>S \neq T</var>, <var>1</var>-based). </p> <p> The capacity of each road is <var>1</var>. You can assume that <var>i \neq j</var> implies either <var>X_i \neq X_j</var> or <var>Y_i \neq Y_j</var>, and either <var>X_i \neq Y_j</var> or <var>X_j \neq Y_i</var>. </p> <H2>Output</H2> <p> In the first line, print the maximized flow by reversing some roads. In the second line, print the number <var>R</var> of the reversed roads. In each of the following <var>R</var> lines, print the ID number (<var>1</var>-based) of a reversed road. You may not print the same ID number more than once. </p> <p> If there are multiple answers which would give us the same flow capacity, you can print any of them. </p> <H2>Sample Input 1</H2> <pre> 2 1 2 1 2 1 </pre> <H2>Output for the Sample Input 1</H2> <pre> 1 0 </pre> <H2>Sample Input 2</H2> <pre> 2 1 1 2 2 1 </pre> <H2>Output for the Sample Input 2</H2> <pre> 1 1 1 </pre> <H2>Sample Input 3</H2> <pre> 3 3 3 2 1 2 3 1 1 3 </pre> <H2>Output for the Sample Input 3</H2> <pre> 2 2 1 3 </pre>
p01071
<h1>Monochrome Tile</h1> <h2>Problem</h2> <p> 癜い正方圢のタむルが暪方向に <var>W</var> 個、瞊方向に <var>H</var> 個、合蚈 <var>W</var> &times <var>H</var> 個敷き詰められおいる。 </p> <p> 倪郎君は、 <var>i</var> 日目の朝に、巊から <var>ax<sub>i</sub></var> 番目で䞊から <var>ay<sub>i</sub></var> 番目のタむルを巊䞊、 巊から <var>bx<sub>i</sub></var> 番目で䞊から <var>by<sub>i</sub></var> 番目のタむルを右䞋にした長方圢領域に存圚しおいるタむルがすべお癜いかどうかを確認する。 もしすべおのタむルが癜かった堎合、それらのタむルをすべお黒く塗り぀ぶす。それ以倖のずきは䜕もしない。 </p> <p> <var>N</var> 日間のそれぞれの日においお、その日の䜜業が終了した時点で黒く塗り぀ぶされたタむルが䜕枚あるかを出力せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>W</var> <var>H</var> <var>N</var> <var>ax<sub>1</sub></var> <var>ay<sub>1</sub></var> <var>bx<sub>1</sub></var> <var>by<sub>1</sub></var> <var>ax<sub>2</sub></var> <var>ay<sub>2</sub></var> <var>bx<sub>2</sub></var> <var>by<sub>2</sub></var> ... <var>ax<sub>N</sub></var> <var>ay<sub>N</sub></var> <var>bx<sub>N</sub></var> <var>by<sub>N</sub></var> </pre> <p> 1行目に、2぀の敎数 <var>W</var> ず <var>H</var> が空癜区切りで䞎えられる。 2行目に、1぀の敎数 <var>N</var> が䞎えられる。 3行目からの <var>N</var> 行のうち <var>i</var> 行目には <var>i</var> 日目の朝に確認する長方圢領域を衚す 4぀の敎数 <var>ax<sub>i</sub></var> <var>ay<sub>i</sub></var> <var>bx<sub>i</sub></var> <var>by<sub>i</sub></var> が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <ul> <li>2 &le; <var>W</var> &le; 100000</li> <li>2 &le; <var>H</var> &le; 100000</li> <li>2 &le; <var>N</var> &le; 100000</li> <li>1 &le; <var>ax<sub>i</sub></var> &le; <var>bx<sub>i</sub></var> &le; <var>W</var> (1 &le; <var>i</var> &le; <var>N</var> )</li> <li>1 &le; <var>ay<sub>i</sub></var> &le; <var>by<sub>i</sub></var> &le; <var>H</var> (1 &le; <var>i</var> &le; <var>N</var> )</li> </ul> <h2>Output</h2> <p> <var>N</var> 日間のそれぞれの日においお、<var>i</var> 日目の䜜業が終了した時点で黒く塗り぀ぶされたタむルの枚数を <var>i</var> 行目にを出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 5 4 5 1 1 3 3 3 2 4 2 4 3 5 4 1 4 5 4 4 1 4 1 </pre> <h2>Sample Output 1</h2> <pre> 9 9 13 13 14 </pre> <p> □□□□□<br> □□□□□<br> □□□□□<br> □□□□□<br> <br> ↓ 1 1 3 3<br> <br> ■■■□□<br> ■■■□□<br> ■■■□□<br> □□□□□<br> <br> ↓ 3 2 4 2 なにもしない<br> <br> ■■■□□<br> ■■■□□<br> ■■■□□<br> □□□□□<br> <br> ↓ 4 3 5 4<br> <br> ■■■□□<br> ■■■□□<br> ■■■■■<br> □□□■■<br> <br> ↓ 1 4 5 4 なにもしない<br> <br> ■■■□□<br> ■■■□□<br> ■■■■■<br> □□□■■<br> <br> ↓ 4 1 4 1<br> <br> ■■■■□<br> ■■■□□<br> ■■■■■<br> □□□■■<br> <br> よっお出力は、 9 → 9 → 13 → 13 → 14 ずなる。 </p>
p00230
<H1>忍者のビル登り</H1> <p> 忍者のあ぀しさんは、毎日朝早くから倜遅くたで忍者ビルの屋䞊から町を譊備しおいたす。この忍者ビルは、隣接する 2 ぀の同じ階数のビルであり、あ぀しさんは譊備のために、ビルずビルの間をゞャンプしながら屋䞊ぞ向かうこずを日課ずしおいたす。 </p> <p> この 2 ぀のビルは頻繁に枅掃が行われるため、ビル登りの助けずなるはしごや障害ずなる滑りやすい郚分がありたす。 しかも、はしごや滑りやすい郚分の䜍眮は毎日倉わりたす。 そのためあ぀しさんは、屋䞊ぞ向かう方法を毎日考えなければいけたせん。<!--あ぀しさんは、䜕回のゞャンプで屋䞊にたどり着けるでしょうか?--> </p> <p> あ぀しさんは二぀䞊んだ同じ階数のビルの壁を跳び移りながら、ビルの屋䞊を目指したす。ゞャンプ はどちらか䞀方のビルの1階から始められたす。向かい偎のビルぞゞャンプするずきには、同じ階・1぀䞊の階・2 ぀䞊の階の、いずれかに飛び移るこずができたす。 </p> <p> 壁には以䞋の 3 皮類があり、それぞれの壁にゞャンプした埌の移動が決たっおいたす。 </p> <ul> <li>0. 普通の壁: 䞊䞋の移動はしない。次のゞャンプはそこから行う。</li> <li>1. はしご: はしごは 2 ぀以䞊の階にたたがっおかかっおおり、今いるはしごの䞀番䞊たで移動する。次のゞャンプはそこから行う。</li> <li>2. すべる壁: 普通の壁かはしごの䞀番䞊たで滑り萜ちる。次のゞャンプはそこから行う。</li> </ul> <p> たた、壁は 1 階から屋䞊のすぐ䞋の最䞊階たであり、屋䞊ぞはそのビルの最䞊階からのみ行くこずが できたす。たた、ビルの最䞋階の壁はすべる壁にはなりたせん。 </p> <p> 2 ぀のビルの階数 <var>n</var> ず 2 ぀のビルの壁の皮類を入力ずし、最少で䜕回目のゞャンプで最䞊階たでたどり着き、屋䞊たで行くこずができるかを出力するプログラムを䜜成しおください。なお、どちらのビルの屋䞊にたどり着いおもよいものずしたす。ただし、あ぀しさんがどちらのビルの屋䞊ぞもたどり着けない堎合は“NA”ず出力しおください。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ninjabill"><br/> <br/> </center> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>n</sub></var> <var>b<sub>1</sub></var> <var>b<sub>2</sub></var> ... <var>b<sub>n</sub></var> </pre> <p> 行目にビルの階数 <var>n</var> (3 &le; <var>n</var> &le; 100) が䞎えられたす。行目に ぀目のビルの 1 階から <var>n</var> 階たでの壁の情報 <var>a<sub>i</sub></var>、行目に぀目のビルの 1 階から <var>n</var> 階たでの壁の情報 <var>b<sub>i</sub></var> が䞎えられたす。<var>a<sub>i</sub>, b<sub>i</sub></var> は<var>i</var> 階目の壁の情報を衚し、0 が普通の壁、1 がはしご(<var>i</var> 階ず <var>i</var>+1 階にたたがる)、2 がすべる壁を衚したす。 </p> <p> デヌタセットの数は 60 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、ゞャンプの回数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 8 0 0 0 2 2 2 0 0 1 1 1 1 0 0 0 0 4 1 1 2 2 0 0 2 2 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4 NA </pre>
p01972
<h2>F 最短距離を䌞ばすえびちゃん (Ebi-chan Lengthens Shortest Paths)</h2> <h3>Problem</h3> <p> Ebi-chan loves directed graphs. One day, a directed graph with <var>N</var> vertices and <var>M</var> edges dropped from somewhere in front of Ebi-chan! The vertices and the edges of the graph is labeled with a number from <var>1</var> to <var>N</var> and from <var>1</var> to <var>M</var>, respectively. Moreover, the <var>i</var>th edge directs from a vertex <var>u_i</var> to a vertex <var>v_i</var> with distance <var>d_i</var>. </p> <p> Ebi-chan thought that, for a pair of vertices <var>s</var> and <var>t</var>, she tries to lengthen the distance of shortest paths from <var>s</var> to <var>t</var>. Although Ebi-chan should lengthen all edges slightly to easily achieve hers goal, she can not enjoy the directed graph with such way! So, she decided the following rules of operations that can be done by her. </p> <ul> <li> She can lengthen each edges independently.</li> <li> When she lengthens an edge, she must select the additional distance from positive integers.</li> <li> The <var>i</var>th edge takes a cost <var>c_i</var> per additional distance 1.</li> </ul> <p>How is the minimum total cost of operations needed to achieve Ebi-chan’s goal?</p> <h3>Input Format</h3> <p>An input is given in the following format.</p> <pre> <var>N</var> <var>M</var> <var>s</var> <var>t</var> <var>u_1</var> <var>v_1</var> <var>d_1</var> <var>c_1</var> $\vdots$ <var>u_M</var> <var>v_M</var> <var>d_M</var> <var>c_M</var> </pre> <p>In line <var>1</var>, four integers <var>N</var>, <var>M</var>, <var>s</var>, and <var>t</var> are given in separating by en spaces. <var>N</var> and <var>M</var> is the number of vertices and edges, respectively. Ebi-chan tries to lengthen shortest paths from the vertex <var>s</var> to the vertex <var>t</var>.</p> <p>Line <var>1 + i</var>, where <var>1 \leq i \leq M</var>, has the information of the <var>i</var>th edge. <var>u_i</var> and <var>v_i</var> are the start and end vertices of the edge, respectively. <var>d_i</var> and <var>c_i</var> represents the original distance and cost of the edge, respectively. These integers are given in separating by en spaces.</p> <h3>Constraints</h3> <ul> <li> <var>2 \leq N \leq 200</var></li> <li> <var>1 \leq M \leq 2,000</var></li> <li> <var>1 \leq s, t \leq N, s \neq t</var></li> <li> <var>1 \leq u_i, v_i \leq N, u_i \neq v_i</var> (<var>1 \leq i \leq M</var>) </li> <li> For each <var>i, j</var> (<var>1 \leq i &lt; j \leq M</var>), <var>u_i \neq u_j</var> or <var>v_i \neq v_j</var> are satisfied.</li> <li> <var>1 \leq d_i \leq 10</var> (<var>1 \leq i \leq M</var>)</li> <li> <var>1 \leq c_i \leq 10</var> (<var>1 \leq i \leq M</var>)</li> <li> It is guaranteed that there is at least one path from <var>s</var> to <var>t</var>.</li> </ul> <h3>Output Format</h3> <p>Print the minimum cost, that is to lengthen the distance of shortest paths from <var>s</var> to <var>t</var> at least 1, in one line.</p> <h3>Example 1</h3> <pre> 3 3 1 3 1 2 1 1 2 3 1 1 1 3 1 1 </pre> <h3>Output 1</h3> <pre>1</pre> <p>Ebi-chan should lengthen 3rd edge with additional distance 1.</p> <h3>Exapmle 2</h3> <pre> 8 15 5 7 1 5 2 3 3 8 3 6 8 7 1 3 2 7 6 4 3 7 5 5 8 3 1 3 5 6 3 5 1 7 3 2 4 3 2 4 5 4 4 3 2 3 2 2 2 8 6 5 6 2 1 3 4 2 1 6 6 1 4 2 </pre> <h3>Output 2</h3> <pre>8</pre>
p00660
<H1>Problem B: High & Low Cube</H1> <p> 僕は近所の小孊生たちず䞀緒に倏祭りに来おいた。有り䜓に蚀えば保護者圹だが、出店の焌きそばやたこ焌きなんかが焌ける匂い、時折聞こえる打ち䞊げ花火の音などは、この歳になっおも心が螊るものがある。が、奜奇心旺盛な子䟛たちがはぐれないように、今日はしっかり芋守っおいないず。 </p> <p> 子䟛たちはずある出店に興味を持ったようだった。芗き蟌んでみるず、そこでは出店のおじさんずサむコロを䜿ったゲヌムをしお、勝おば景品が貰えるこずになっおいた。そのゲヌムは、 High & Low ず呌ばれる単玔なものだ。参加者ずおじさんは1個ず぀サむコロを振るが、その前に参加者は、自分の出目がおじさんの出目より倧きいか小さいかを予想する。予想が圓たれば勝利であり、同じ目が出た堎合はどちらもサむコロを振り盎す。 </p> <p> このゲヌムの少し厄介なずころは、参加者のサむコロずおじさんのサむコロが違うものであるかもしれない、ずいう点だ。参加者はあらかじめ䞡者のサむコロの展開図を芋るこずができるので、それをヒントに予想するこずになる。 </p> <p> ぀たり、簡単な確率の蚈算だ。ずはいえ確率は高校数孊の範囲で、小孊生にはちょっず荷が重いかもしれない。子䟛たちの䞭で䞀番利発そうな子でさえ、䞉぀線みにした髪を揺らしながら考え蟌んでいる。もうすぐ僕に助けを求めおくるこずだろう。さお、たたにはオトナらしいずころを芋せおあげようではないか。 </p> <h2>Input</h2> <p> 入力は耇数のケヌスからなる。<br> </p> <p> 各ケヌスでは、サむコロの展開図が21×57のグリッドで䞎えられる。<br> 最初の21×28(0,0)が巊䞊,(20,27)が右䞋のグリッドが参加者のサむコロを衚す。<br> 最埌の21×28(0,29)が巊䞊,(20,56)が右䞋がおじさんのサむコロを衚す。<br> </p> <p> 参加者のサむコロの各面は(0,7)、(7,0)、(7,7)、(7,14)、(7,21)、(14,7)を巊䞊ずする7×7のサブグリッドで䞎えられおいる。<br> 展開図に曞かれおいる数字は、それぞれ元の数字を<br> 巊右反転<br> 巊右反転、そのあずで反時蚈回りに90床回転<br> 巊右反転<br> 巊右反転、そのあずで反時蚈回りに270床回転<br> 巊右反転<br> 䞊䞋反転、そのあずで巊右反転<br> させたものである。<br> </p> <p> おじさんのサむコロの各面は(0,36)、(7,29)、(7,36)、(7,43)、(7,50)、(14,36)を巊䞊ずする×のサブグリッドで䞎えられおいる。<br> おじさんのサむコロの展開図に曞かれおいる数字は参加者のサむコロず同じ芏則で描かれおいる。<br> </p> <pre> サむコロの各面には1から9たでの䞭のどれかが曞かれおいる。 数字は以䞋のような7x7のグリッドで䞎えられる。 ####### #.....# #...|.# #.....# #...|.# #..-..# ####### ####### #..-..# #...|.# #..-..# #.|...# #..-..# ####### ####### #..-..# #...|.# #..-..# #...|.# #..-..# ####### ####### #.....# #.|.|.# #..-..# #...|.# #.....# ####### ####### #..-..# #.|...# #..-..# #...|.# #..-..# ####### ####### #..-..# #.|...# #..-..# #.|.|.# #..-..# ####### ####### #..-..# #...|.# #.....# #...|.# #.....# ####### ####### #..-..# #.|.|.# #..-..# #.|.|.# #..-..# ####### ####### #..-..# #.|.|.# #..-..# #...|.# #..-..# ####### </pre> <pre> ただし䞊蚘の数字を90床、たたは270床回転させた時、"|"ず"-"は入れ替わっおいる。 </pre> <p> 入力の終わりは1぀の0からなる行によっお䞎えられる </p> <p> 入力ずしお䞎えられるサむコロは必ず正しい物である。 たた決着が぀かないようなサむコロは䞎えられない。 </p> <h2>Output</h2> <p> "HIGH"になる堎合ず"LOW"になる堎合で確率が高いほうを1行に出力せよ。 䞡者の確率が同じ堎合は"HIGH"を出力せよ。 </p> <h2>Sample input</h2> <pre> .......#######......................#######.............. .......#.....#......................#..-..#.............. .......#.|...#......................#.|.|.#.............. .......#.....#......................#..-..#.............. .......#.|...#......................#.|...#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. ############################.############################ #.....##..-..##.....##..-..#.#.....##..-..##.....##..-..# #.-.-.##...|.##.-.-.##.|.|.#.#.....##.|.|.##.-.-.##.|.|.# #|.|.|##..-..##|.|.|##..-..#.#....|##..-..##|.|.|##..-..# #...-.##.|...##...-.##.|.|.#.#.-.-.##.|...##...-.##.|...# #.....##..-..##.....##..-..#.#.....##..-..##.....##..-..# ############################.############################ .......#######......................#######.............. .......#..-..#......................#..-..#.............. .......#.|...#......................#.|...#.............. .......#..-..#......................#..-..#.............. .......#.|.|.#......................#...|.#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. .......#######......................#######.............. .......#..-..#......................#..-..#.............. .......#.|...#......................#...|.#.............. .......#..-..#......................#..-..#.............. .......#...|.#......................#.|.|.#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. ############################.############################ #.....##..-..##.....##..-..#.#.....##..-..##.....##..-..# #.-.-.##...|.##.-.-.##.|.|.#.#...-.##...|.##.-...##.|.|.# #|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..# #.-.-.##.|...##...-.##.|...#.#.-...##.|.|.##.-.-.##.|...# #.....##..-..##.....##..-..#.#.....##..-..##.....##..-..# ############################.############################ .......#######......................#######.............. .......#..-..#......................#..-..#.............. .......#...|.#......................#.|...#.............. .......#..-..#......................#..-..#.............. .......#.|...#......................#...|.#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. .......#######......................#######.............. .......#..-..#......................#..-..#.............. .......#.|...#......................#.|.|.#.............. .......#..-..#......................#..-..#.............. .......#...|.#......................#.|...#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. ############################.############################ #.....##..-..##.....##..-..#.#.....##..-..##.....##.....# #.-.-.##.|.|.##.-.-.##...|.#.#.....##.|.|.##...-.##.|...# #|.|.|##..-..##|....##..-..#.#....|##..-..##|.|.|##.....# #.-.-.##.|.|.##.....##.|.|.#.#.-.-.##.|.|.##.-...##.|...# #.....##..-..##.....##..-..#.#.....##..-..##.....##..-..# ############################.############################ .......#######......................#######.............. .......#..-..#......................#..-..#.............. .......#.|.|.#......................#.|...#.............. .......#..-..#......................#..-..#.............. .......#...|.#......................#...|.#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. .......#######......................#######.............. .......#..-..#......................#..-..#.............. .......#.|...#......................#.|.|.#.............. .......#..-..#......................#..-..#.............. .......#...|.#......................#.|...#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. ############################.############################ #.....##..-..##.....##..-..#.#.....##..-..##.....##..-..# #.-.-.##...|.##.-.-.##.|.|.#.#.-...##.|.|.##.-...##.|.|.# #|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..# #...-.##.|...##.-.-.##.|.|.#.#.-.-.##.|...##.-.-.##.|.|.# #.....##..-..##.....##..-..#.#.....##..-..##.....##..-..# ############################.############################ .......#######......................#######.............. .......#..-..#......................#..-..#.............. .......#...|.#......................#.|.|.#.............. .......#..-..#......................#..-..#.............. .......#.|...#......................#...|.#.............. .......#..-..#......................#..-..#.............. .......#######......................#######.............. 0 </pre> <H2>Sample output</H2> <pre> LOW HIGH HIGH LOW </pre> <hr> <p> The University of Aizu Programming Contest 2011 Summer<br> 原案、問題文: Takashi Tayama<br> </p>
p02173
<h1>Problem L: Space Travel</h1> <h2>Story</h2> <p> 遠い昔、はるかかなたの銀河系で。<br> 時は内乱の嵐が吹き荒れるさなか、凶悪な銀河垝囜の軍勢が反乱軍の秘密基地を襲った。<br> 恐るべき垝囜宇宙艊隊の远撃から逃れた、りヌク・スタヌりォヌカヌによっお率いられる自由の戊士たちは、銀河の蟺境に新たな秘密基地を築くこずにした。<br> 反乱軍の䞀員であり、凄腕のプログラマヌであるあなたにあたえられたミッションは、銀河系のそれぞれの惑星から最も離れた惑星を芋぀けるこずである。 </p> <h2>Problem</h2> <p> 銀河系には $N$ 個の惑星があり、$M$ 個の「橋」ず呌ばれる秘密のルヌトがある。<br> 惑星にはそれぞれ $1,2, \ldots N$ の番号が、橋にはそれぞれ $1,2, \ldots M$ の番号が぀いおいる。<br> 各惑星の䜍眮は実䞉次元空間䞊の点ずしお衚され、惑星 $p$ は $(x_p,y_p,z_p)$ に䜍眮する。<br> $i$ 番目の橋は、惑星 $u_i$ から $v_i$ ぞず向かう秘密のルヌトである。<br> $i$ 番目の橋を䜿っお惑星 $v_i$ から $u_i$ ぞ盎接移動するこずはできないこずに泚意せよ。<br> <br> 惑星 $p$ ず $q$ の距離を以䞋のように定矩する。<br> $\mathrm{d} (p,q) = |x_p - x_q| + |y_p - y_q| + |z_p - z_q|$<br> <br> 惑星 $p$ から $0$ 個以䞊の橋を䌝っお到達可胜な惑星の集合を $S_p$ ずする。 各 $p$ に぀いお、$\displaystyle \max_{s \in S_p} \mathrm{d} (p,s)$ を求めよ。<br> ただし、反乱軍は垞に凶悪な銀河垝囜の軍勢に狙われおいるため、橋以倖のルヌトで惑星間を移動するこずはできない。<br> </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $M$ $x_1$ $y_1$ $z_1$ $\vdots$ $x_N$ $y_N$ $z_N$ $u_1$ $v_1$ $\vdots$ $u_M$ $v_M$ </pre> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq N \leq 2 \times 10^5$</li> <li>$1 \leq M \leq 5 \times 10^5$</li> <li>$1 \leq u_i , v_i \leq N$</li> <li>$|x_p|,|y_p|,|z_p| \leq 10^8$</li> <li>$u_i \neq v_i$</li> <li>$i \neq j$ なら $(u_i,v_i) \neq (u_j,v_j)$</li> <li>$p \neq q$ なら $(x_p,y_p,z_p) \neq (x_q,y_q,z_q)$</li> <li>入力は党お敎数である</li> </ul> <h2>Output</h2> <p> $N$ 行出力せよ。<br> $i$ 行目には $\displaystyle \max_{s \in S_i} \mathrm{d} (i,s)$ を出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 2 1 1 1 1 2 2 2 1 2 </pre> <h2>Sample Output 1</h2> <pre> 3 0 </pre> <h2>Sample Input 2</h2> <pre> 2 2 1 1 1 2 2 2 1 2 2 1 </pre> <h2>Sample Output 2</h2> <pre> 3 3 </pre> <h2>Sample Input 3</h2> <pre> 6 6 0 8 0 2 3 0 2 5 0 4 3 0 4 5 0 6 0 0 1 3 2 3 3 5 5 4 4 2 4 6 </pre> <h2>Sample Output 3</h2> <pre> 14 7 9 5 7 0 </pre> <h2>Sample Input 4</h2> <pre> 10 7 -65870833 -68119923 -51337277 -59513976 -24997697 -46968492 -37069671 -90713666 -45043609 -31144219 43731960 -5258464 -27501033 90001758 13168637 -96651565 -67773915 56786711 44851572 -29156912 28758396 16384813 -79097935 7386228 88805434 -79256976 31470860 92682611 32019492 -87335887 6 7 7 9 6 5 1 2 2 4 4 1 9 8 </pre> <h2>Sample Output 4</h2> <pre> 192657310 138809442 0 192657310 0 270544279 99779950 0 96664294 0 </pre>
p03298
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>2N</var> consisting of lowercase English letters.</p> <p>There are <var>2^{2N}</var> ways to color each character in <var>S</var> red or blue. Among these ways, how many satisfy the following condition?</p> <ul> <li>The string obtained by reading the characters painted red <strong>from left to right</strong> is equal to the string obtained by reading the characters painted blue <strong>from right to left</strong>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 18</var></li> <li>The length of <var>S</var> is <var>2N</var>.</li> <li><var>S</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to paint the string that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 cabaacba </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four ways to paint the string, as follows:</p> <ul> <li><span style="color:red">c</span><span style="color:blue">a</span><span style="color:blue">b</span><span style="color:blue">a</span><span style="color:red">a</span><span style="color:blue">c</span><span style="color:red">b</span><span style="color:red">a</span></li> <li><span style="color:red">c</span><span style="color:blue">a</span><span style="color:blue">b</span><span style="color:red">a</span><span style="color:blue">a</span><span style="color:blue">c</span><span style="color:red">b</span><span style="color:red">a</span></li> <li><span style="color:blue">c</span><span style="color:red">a</span><span style="color:red">b</span><span style="color:red">a</span><span style="color:blue">a</span><span style="color:red">c</span><span style="color:blue">b</span><span style="color:blue">a</span></li> <li><span style="color:blue">c</span><span style="color:red">a</span><span style="color:red">b</span><span style="color:blue">a</span><span style="color:red">a</span><span style="color:red">c</span><span style="color:blue">b</span><span style="color:blue">a</span></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>11 mippiisssisssiipsspiim </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>504 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 abcdefgh </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>18 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>9075135300 </pre> <p>The answer may not be representable as a <var>32</var>-bit integer.</p></section> </div> </span>
p03762
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On a two-dimensional plane, there are <var>m</var> lines drawn parallel to the <var>x</var> axis, and <var>n</var> lines drawn parallel to the <var>y</var> axis. Among the lines parallel to the <var>x</var> axis, the <var>i</var>-th from the bottom is represented by <var>y = y_i</var>. Similarly, among the lines parallel to the <var>y</var> axis, the <var>i</var>-th from the left is represented by <var>x = x_i</var>.</p> <p>For every rectangle that is formed by these lines, find its area, and print the total area modulo <var>10^9+7</var>.</p> <p>That is, for every quadruple <var>(i,j,k,l)</var> satisfying <var>1\leq i &lt; j\leq n</var> and <var>1\leq k &lt; l\leq m</var>, find the area of the rectangle formed by the lines <var>x=x_i</var>, <var>x=x_j</var>, <var>y=y_k</var> and <var>y=y_l</var>, and print the sum of these areas modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq n,m \leq 10^5</var></li> <li><var>-10^9 \leq x_1 &lt; ... &lt; x_n \leq 10^9</var></li> <li><var>-10^9 \leq y_1 &lt; ... &lt; y_m \leq 10^9</var></li> <li><var>x_i</var> and <var>y_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>n</var> <var>m</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_n</var> <var>y_1</var> <var>y_2</var> <var>...</var> <var>y_m</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total area of the rectangles, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 3 4 1 3 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>60 </pre> <p>The following figure illustrates this input:</p> <p><img alt="sample1-1" src="https://atcoder.jp/img/arc071/aec4d5cc2e5c73dbee455be237a649a5.png"/></p> <p>The total area of the nine rectangles A, B, ..., I shown in the following figure, is <var>60</var>.</p> <p><img alt="sample1-2" src="https://atcoder.jp/img/arc071/f0771c0f7e68af2b00e7513186f585ff.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 5 -790013317 -192321079 95834122 418379342 586260100 802780784 -253230108 193944314 363756450 712662868 735867677 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>835067060 </pre></section> </div> </span>
p02870
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In a two-dimensional plane, there is a square frame whose vertices are at coordinates <var>(0,0)</var>, <var>(N,0)</var>, <var>(0,N)</var>, and <var>(N,N)</var>. The frame is made of mirror glass. A ray of light striking an edge of the frame (but not a vertex) will be reflected so that the angle of incidence is equal to the angle of reflection. A ray of light striking a vertex of the frame will be reflected in the direction opposite to the direction it is coming from.</p> <p>We will define the <em>path</em> for a grid point (a point with integer coordinates) <var>(i,j)</var> (<var>0&lt;i,j&lt;N</var>) strictly within the frame, as follows:</p> <ul> <li>The path for <var>(i,j)</var> is the union of the trajectories of four rays of light emitted from <var>(i,j)</var> to <var>(i-1,j-1)</var>, <var>(i-1,j+1)</var>, <var>(i+1,j-1)</var>, and <var>(i+1,j+1)</var>.</li> </ul> <div style="text-align: center;"> <img src="https://img.atcoder.jp/nikkei2019-2-qual/f82200c30253b6e06c6043a2c7668735.png"> <p>Figure: an example of a path for a grid point</p> </img></div> <p>There is a light bulb at each grid point strictly within the frame. We will assign a state - ON or OFF - to each bulb. The state of the whole set of bulbs are called <em>beautiful</em> if it is possible to turn OFF all the bulbs by repeating the following operation:</p> <ul> <li>Choose a grid point strictly within the frame, and switch the states of all the bulbs on its path.</li> </ul> <p>Takahashi has set the states of some of the bulbs, but not for the remaining bulbs. Find the number of ways to set the states of the remaining bulbs so that the state of the whole set of bulbs is beautiful, modulo <var>998244353</var>. The state of the bulb at the grid point <var>(i,j)</var> is set to be ON if <var>A_{i,j}=</var><code>o</code>, OFF if <var>A_{i,j}=</var><code>x</code>, and unset if <var>A_{i,j}=</var><code>?</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 1500</var></li> <li><var>A_{ij}</var> is <code>o</code>, <code>x</code>, or <code>?</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_{1,1}...A_{1,N-1}</var> <var>:</var> <var>A_{N-1,1}...A_{N-1,N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 o?o ??? ?x? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>The state of the whole set of bulbs will be beautiful if we set the state of each bulb as follows:</p> <pre>oxo xox oxo </pre> <p>We can turn OFF all the bulbs by, for example, choosing the point <var>(1, 1)</var> and switching the states of the bulbs at <var>(1,1)</var>, <var>(1,3)</var>, <var>(2,2)</var>, <var>(3,1)</var>, and <var>(3,3)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 o?o? ???? o?x? ???? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 ?o??? ????o ??x?? o???? ???o? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>32 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>9 ????o??x ?????x?? ??o?o??? ?o?x???? ???????x x?o?o??? ???????? x?????x? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>4 </pre></section> </div> </span>
p03332
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has a tower which is divided into <var>N</var> layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the <em>beauty of the tower</em> as follows:</p> <ul> <li>The beauty of the tower is the sum of the scores of the <var>N</var> layers, where the score of a layer is <var>A</var> if the layer is painted red, <var>A+B</var> if the layer is painted green, <var>B</var> if the layer is painted blue, and <var>0</var> if the layer is uncolored.</li> </ul> <p>Here, <var>A</var> and <var>B</var> are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.</p> <p>Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly <var>K</var>. How many such ways are there to paint the tower? Find the count modulo <var>998244353</var>. Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 3×10^5</var></li> <li><var>1 ≀ A,B ≀ 3×10^5</var></li> <li><var>0 ≀ K ≀ 18×10^{10}</var></li> <li>All values in the input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the ways to paint tiles, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>40 </pre> <p>In this case, a red layer worth <var>1</var> points, a green layer worth <var>3</var> points and the blue layer worth <var>2</var> points. The beauty of the tower is <var>5</var> when we have one of the following sets of painted layers:</p> <ul> <li><var>1</var> green, <var>1</var> blue</li> <li><var>1</var> red, <var>2</var> blues</li> <li><var>2</var> reds, <var>1</var> green</li> <li><var>3</var> reds, <var>1</var> blue</li> </ul> <p>The total number of the ways to produce them is <var>40</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 5 6 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>The beauty of the tower is <var>0</var> only when all the layers are uncolored. Thus, the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>90081 33447 90629 6391049189 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>577742975 </pre></section> </div> </span>
p03627
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> sticks with negligible thickness. The length of the <var>i</var>-th stick is <var>A_i</var>.</p> <p>Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>4 \leq N \leq 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>A_i</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible area of the rectangle. If no rectangle can be formed, print <var>0</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 3 1 2 4 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p><var>1 \times 2</var> rectangle can be formed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>No rectangle can be formed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 3 3 3 3 4 4 4 5 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>20 </pre></section> </div> </span>
p00908
<H1><font color="#000">Problem E: </font> Sliding Block Puzzle</H1> <p> In sliding block puzzles, we repeatedly slide pieces (blocks) to open spaces within a frame to establish a goal placement of pieces. </p> <p> A puzzle creator has designed a new puzzle by combining the ideas of sliding block puzzles and mazes. The puzzle is played in a rectangular frame segmented into unit squares. Some squares are pre-occupied by obstacles. There are a number of pieces placed in the frame, one 2 &times; 2 king piece and some number of 1 &times; 1 pawn pieces. Exactly two 1 &times; 1 squares are left open. If a pawn piece is adjacent to an open square, we can slide the piece there. If a whole edge of the king piece is adjacent to two open squares, we can slide the king piece. We cannot move the obstacles. Starting from a given initial placement, the objective of the puzzle is to move the king piece to the upper-left corner of the frame. </p> <p> The following figure illustrates the initial placement of the fourth dataset of the sample input. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_slidingBlockPuzzle"><br/> <p> Figure E.1: The fourth dataset of the sample input. </p> </center> <p> Your task is to write a program that computes the minimum number of moves to solve the puzzle from a given placement of pieces. Here, one move means sliding either king or pawn piece to an adjacent position. </p> <H2>Input</H2> <p> The input is a sequence of datasets. The first line of a dataset consists of two integers <i>H</i> and <i>W</i> separated by a space, where <i>H</i> and <i>W</i> are the height and the width of the frame. The following <i>H</i> lines, each consisting of <i>W</i> characters, denote the initial placement of pieces. In those <i>H</i> lines, '<span>X</span>', '<span>o</span>', '<span>*</span>', and '<span>.</span>' denote a part of the king piece, a pawn piece, an obstacle, and an open square, respectively. There are no other characters in those <i>H</i> lines. You may assume that 3 &le; <i>H</i> &le; 50 and 3 &le; <i>W</i> &le; 50. </p> <p> A line containing two zeros separated by a space indicates the end of the input. </p> <H2>Output</H2> <p> For each dataset, output a line containing the minimum number of moves required to move the king piece to the upper-left corner. If there is no way to do so, output <span>-1</span>. </p> <H2>Sample Input</H2> <pre> 3 3 oo. oXX .XX 3 3 XXo XX. o.o 3 5 .o*XX oooXX oooo. 7 12 oooooooooooo ooooo*****oo oooooo****oo o**ooo***ooo o***ooooo..o o**ooooooXXo ooooo****XXo 5 30 oooooooooooooooooooooooooooooo oooooooooooooooooooooooooooooo o***************************oo XX.ooooooooooooooooooooooooooo XX.ooooooooooooooooooooooooooo 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 11 0 -1 382 6807 </pre>
p02935
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have a pot and <var>N</var> ingredients. Each ingredient has a real number parameter called <em>value</em>, and the value of the <var>i</var>-th ingredient <var>(1 \leq i \leq N)</var> is <var>v_i</var>.</p> <p>When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be <var>(x + y) / 2</var> where <var>x</var> and <var>y</var> are the values of the ingredients consumed, and you can put this ingredient again in the pot.</p> <p>After you compose ingredients in this way <var>N-1</var> times, you will end up with one ingredient. Find the maximum possible value of this ingredient.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 50</var></li> <li><var>1 \leq v_i \leq 1000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>v_1</var> <var>v_2</var> <var>\ldots</var> <var>v_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.</p> <p>Your output will be judged correct when its absolute or relative error from the judge's output is at most <var>10^{-5}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3.5 </pre> <p>If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values <var>3</var> and <var>4</var> is <var>(3 + 4) / 2 = 3.5</var>.</p> <p>Printing <code>3.50001</code>, <code>3.49999</code>, and so on will also be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 500 300 200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>375 </pre> <p>You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:</p> <ul> <li>Use the ingredients of values <var>500</var> and <var>300</var> to produce an ingredient of value <var>(500 + 300) / 2 = 400</var>. The next composition will use this ingredient and the ingredient of value <var>200</var>, resulting in an ingredient of value <var>(400 + 200) / 2 = 300</var>.</li> <li>Use the ingredients of values <var>500</var> and <var>200</var> to produce an ingredient of value <var>(500 + 200) / 2 = 350</var>. The next composition will use this ingredient and the ingredient of value <var>300</var>, resulting in an ingredient of value <var>(350 + 300) / 2 = 325</var>.</li> <li>Use the ingredients of values <var>300</var> and <var>200</var> to produce an ingredient of value <var>(300 + 200) / 2 = 250</var>. The next composition will use this ingredient and the ingredient of value <var>500</var>, resulting in an ingredient of value <var>(250 + 500) / 2 = 375</var>.</li> </ul> <p>Thus, the maximum possible value of the last ingredient remaining is <var>375</var>.</p> <p>Printing <code>375.0</code> and so on will also be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 138 138 138 138 138 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>138 </pre></section> </div> </span>
p03277
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will define the <strong>median</strong> of a sequence <var>b</var> of length <var>M</var>, as follows:</p> <ul> <li>Let <var>b'</var> be the sequence obtained by sorting <var>b</var> in non-decreasing order. Then, the value of the <var>(M / 2 + 1)</var>-th element of <var>b'</var> is the median of <var>b</var>. Here, <var>/</var> is integer division, rounding down.</li> </ul> <p>For example, the median of <var>(10, 30, 20)</var> is <var>20</var>; the median of <var>(10, 30, 20, 40)</var> is <var>30</var>; the median of <var>(10, 10, 10, 20, 30)</var> is <var>10</var>.</p> <p>Snuke comes up with the following problem.</p> <p>You are given a sequence <var>a</var> of length <var>N</var>. For each pair <var>(l, r)</var> (<var>1 \leq l \leq r \leq N</var>), let <var>m_{l, r}</var> be the median of the contiguous subsequence <var>(a_l, a_{l + 1}, ..., a_r)</var> of <var>a</var>. We will list <var>m_{l, r}</var> for all pairs <var>(l, r)</var> to create a new sequence <var>m</var>. Find the median of <var>m</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>a_i</var> is an integer.</li> <li><var>1 \leq a_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the median of <var>m</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 10 30 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>30 </pre> <p>The median of each contiguous subsequence of <var>a</var> is as follows:</p> <ul> <li>The median of <var>(10)</var> is <var>10</var>.</li> <li>The median of <var>(30)</var> is <var>30</var>.</li> <li>The median of <var>(20)</var> is <var>20</var>.</li> <li>The median of <var>(10, 30)</var> is <var>30</var>.</li> <li>The median of <var>(30, 20)</var> is <var>30</var>.</li> <li>The median of <var>(10, 30, 20)</var> is <var>20</var>.</li> </ul> <p>Thus, <var>m = (10, 30, 20, 30, 30, 20)</var> and the median of <var>m</var> is <var>30</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 5 9 5 9 8 9 3 5 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p04048
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p> <p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle. Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p> <p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>. (The size of the rifle is negligible.) Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p> <p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light. There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror! When the ray comes back to the rifle, the ray will be absorbed.</p> <p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p> <div style="text-align: center;"> <img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png"> </img></div> <p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>. Find the total length of the ray's trajectory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≩N≩10^{12}</var></li> <li><var>1≩X≩N-1</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Points</h3><ul> <li><var>300</var> points will be awarded for passing the test set satisfying <var>N≩1000</var>.</li> <li>Another <var>200</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>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total length of the ray's trajectory.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Refer to the image in the Problem Statement section. The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section> </div> </span>
p02036
<h2>G: Donuts Orientation</h2> <h3>物語</h3> <p>ほむちゃんの最近のマむブヌムはお菓子䜜りだ。たくさんお菓子を䜜っおは、それを友達におすそ分けしおいるらしい。そんなほむちゃんは今回、ドヌナツづくりに挑戊するようだ。</p> <p>ドヌナツづくりに倧切なこずはいく぀もある。生地や味付けはもちろん、かわいい芋た目にするためのデコレヌションも倖せない。詊行錯誀を繰り返しおいるうちに、ほむちゃんのデコレヌションぞのこだわりに熱がこもっおきたようだ。こだわりぬいたドヌナツを倚くの人に食べおもらいたいので、ほむちゃんはドヌナツをたくさん぀くりたいず考えおいる。</p> <p>・・・ずころで、こだわるのは䞀向に構わないが、ほむちゃんこだわりのドヌナツを十分な数甚意するこずはできるのだろうか</p> <h3>問題</h3> <p><var>3</var> 以䞊の敎数 <var>N</var> に぀いお、以䞋のようにしお <var>2N</var> 頂点のグラフを䜜る。</p> <ul> <li> それぞれの頂点に぀いお <var>1</var> から <var>2N</var> で番号付けする。</li> <li> 各敎数 <var>1 \leq a \leq N</var> に぀いお、頂点 <var>2a-1</var> ず <var>2a</var> の間に無向蟺を匵る</li> <li> 各敎数 <var>1 \leq b \leq 2N-2</var> に぀いお、頂点 <var>b</var> ず <var>b+2</var> の間に無向蟺を匵る</li> <li> 頂点 <var>1</var> ず <var>2N-1</var> および <var>2</var> ず <var>2N</var> の間に無向蟺を匵る</li> </ul> <p>このグラフの各蟺に向きを぀けお、有向グラフを䜜る。぀たり、頂点 <var>u</var> ず <var>v</var> の間に無向蟺があるならば、それを <var>u</var> から <var>v</var> ぞ向かう有向蟺にするか、<var>v</var> から <var>u</var> ぞ向かう有向蟺にする。</p> <p>このようにしおできた有向グラフであっお、サむクルを持たないものが䜕通りあるかを知りたい。答えは非垞に倧きくなるため、玠数 <var>M</var> で割った䜙りを求めよ。</p> <h3>入力圢匏</h3> <pre><var>N</var> <var>M</var></pre> <h3>制玄</h3> <ul> <li> <var>3 \leq N \leq 1,000</var></li> <li> <var>10^8 \leq M \leq 10^9 + 7</var></li> <li> <var>M</var> は玠数であるこずが保蚌される</li> </ul> <h3>出力圢匏</h3> <p>条件を満たす有向グラフの数を <var>M</var> で割った䜙りを出力せよ。</p> <h3>入力䟋1</h3> <pre>3 1000000007</pre> <h3>出力䟋1</h3> <pre>204</pre> <p><var>N = 3</var> なので、<var>6</var> 頂点からなるグラフを䜜る。条件に合臎する有向グラフの䞀䟋は以䞋の通りである。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-g-001.png" type="image/png" width="400"></object> <p>サむクルが存圚するため、以䞋に瀺す有向グラフは条件を満たさない。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-g-002.png" type="image/png" width="400"></object> <h3>入力䟋2</h3> <pre>128 998244353</pre> <h3>出力䟋2</h3> <pre>996915100</pre> <p><var>M</var> で割った䜙りを出力するこずに泚意せよ。</p>
p02466
<h1>Set Symmetric Difference</h1> <p> Find the symmetric difference of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ </pre> <p> Elements in $A$ and $B$ are given in ascending order. There are no duplicate elements in each set. </p> <h2>Output</h2> <p> Print elements in the symmetric difference in ascending order. Print an element in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n, m \leq 200,000$</li> <li>$0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$</li> <li>$0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$</li> </ul> <h2>Sample Input 1</h2> <pre> 7 1 2 3 4 5 6 7 4 2 4 6 8 </pre> <h2>Sample Output 1</h2> <pre> 1 3 5 7 8 </pre>
p01163
<H1><font color="#000">Problem A:</font> Space Coconut Crab II</H1> <p> A space hunter, Ken Marineblue traveled the universe, looking for the space coconut crab. The space coconut crab was a crustacean known to be the largest in the universe. It was said that the space coconut crab had a body of more than 400 meters long and a leg span of no shorter than 1000 meters long. Although there were numerous reports by people who saw the space coconut crab, nobody have yet succeeded in capturing it. </p> <p> After years of his intensive research, Ken discovered an interesting habit of the space coconut crab. Surprisingly, the space coconut crab went back and forth between the space and the hyperspace by phase drive, which was the latest warp technology. As we, human beings, was not able to move to the hyperspace, he had to work out an elaborate plan to capture them. Fortunately, he found that the coconut crab took a long time to move between the hyperspace and the space because it had to keep still in order to charge a sufficient amount of energy for phase drive. He thought that he could capture them immediately after the warp-out, as they moved so slowly in the space. </p> <p> He decided to predict from the amount of the charged energy the coordinates in the space where the space coconut crab would appear, as he could only observe the amount of the charged energy by measuring the time spent for charging in the hyperspace. His recent spaceship, Weapon Breaker, was installed with an artificial intelligence system, CANEL. She analyzed the accumulated data and found another surprising fact; the space coconut crab always warped out near to the center of a triangle that satisfied the following conditions: </p> <ul> <li>each vertex of the triangle was one of the planets in the universe;</li> <li>the length of every side of the triangle was a prime number; and</li> <li>the total length of the three sides of the triangle was equal to <i>T</i>, the time duration the space coconut crab had spent in charging energy in the hyperspace before moving to the space.</li> </ul> <p> CANEL also devised the method to determine the three planets comprising the triangle from the amount of energy that the space coconut crab charged and the lengths of the triangle sides. However, the number of the candidate triangles might be more than one. </p> <p> Ken decided to begin with calculating how many different triangles were possible, analyzing the data he had obtained in the past research. Your job is to calculate the number of different triangles which satisfies the conditions mentioned above, for each given <i>T</i>. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset comes with a line that contains a single positive integer <i>T</i> (1 &le; <i>T</i> &le; 30000). </p> <p> The end of input is indicated by a line that contains a zero. This should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the number of different possible triangles in a line. Two triangles are different if and only if they are not congruent. </p> <H2>Sample Input</H2> <pre> 10 12 15 777 4999 5000 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 1 2 110 2780 0 </pre>
p01499
<H1><font color="#000">Problem E: </font>Rabbit Game Playing</H1> <p> Honestly, a rabbit does not matter. </p> <p> There is a rabbit playing a stage system action game. In this game, every stage has a difficulty level. The rabbit, which always needs challenges, basically wants to play more difficult stages than he has ever played. However, he sometimes needs rest too. So, to compromise, he admitted to play <i>T</i> or less levels easier stages than the preceding one. </p> <p> How many ways are there to play all the stages at once, while honoring the convention above? Maybe the answer will be a large number. So, let me know the answer modulo 1,000,000,007. </p> <H2>Input</H2> <p> The first line of input contains two integers <i>N</i> and <i>T</i> (1 &le; <i>N</i> &le; 100,000, 1 &le; <i>T</i> &le; 10,000). <i>N</i> is the number of stages, and <i>T</i> is the compromise level. </p> <p> The following <i>N</i> lines describe the difficulty levels of each stage. The <i>i</i>-th line contains one integer <i>D<sub>i</sub></i> (1 &le; <i>D<sub>i</sub></i> &le; 100,000), which is the difficulty level of the <i>i</i>-th stage. </p> <H2>Output</H2> <p> Calculate how many ways to play all the stages at once there are. Print the answer modulo 1,000,000,007 in a line. </p> <H2>Sample Input 1</H2> <pre> 3 1 1 2 3 </pre> <H2>Output for the Sample Input 1</H2> <pre> 4 </pre> <br/> <H2>Sample Input 2</H2> <pre> 5 3 9 2 6 8 8 </pre> <H2>Output for the Sample Input 2</H2> <pre> 24 </pre> <br/> <H2>Sample Input 3</H2> <pre> 5 7 9 9 9 1 5 </pre> <H2>Output for the Sample Input 3</H2> <pre> 48 </pre> <br/>
p01533
<h1> Acrophobia</h1> <h2> C: 高所恐怖症</h2> <p> 高杉やよいは超売れっ子アむドルである そんな圌女には1぀苊手なものがある 高いずころだ・・・圌女は極床の高所恐怖症なのである 圌女は今回プロデュヌサヌの䞍手際によりバラ゚ティ番組で次のようなチャレンゞに挑戊するこずになっおしたった </p> <p> 今回のロケはずある忍者屋敷のずある䞀宀で行われる この郚屋の床には正方圢のタむルが敷き詰められおおりいく぀かのタむルが抜け萜ちお穎になっおいる この穎から萜ちるず数メヌトル䞋の池にたっさかさたである やよいのチャレンゞ内容はこの郚屋の指定された堎所からスタヌトし郚屋の䞭に眮かれた党おの巻物を回収しゎヌル地点たで持っおいくこずである </p> <p> やよいは郚屋の䞭を以䞋のルヌルに埓っお移動できる </p> <ul> <li> あるタむルから隣のタむルぞ移動するずき䞊䞋巊右のタむルにのみ移動するこずができる</li> <li> 穎に近くない堎合隣のタむルぞ移動するためには1秒だけ時間がかかる</li> <li> 穎に近づいた堎合やよいは怖がっおしたい図C-1のように移動時間がかかる䟋えば図䞭の矢印のように[2][2]から[1][2]ぞ移動するためには3秒かかる</li> <li> 耇数の穎が近くにある堎合最も近くにある穎に察しお怖がる</li> <li> 巻物を取るためにかかる時間は0ず仮定しおよい</li> </ul> <p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day1_C" width="300"> </td> </tr> <tr> <td> <center> 図C-1: 穎の近くの移動時間 </center> </td> </tr> </table> </center> </p> <p> やよいはなるべく早くこのチャレンゞを終わらせたいず考えおいる あなたの仕事はこのチャレンゞを終了するための最短時間を求めるプログラムを曞きやよいを助けおあげるこずである </p> <h2> Input</h2> <p> 忍者屋敷の床情報が䞎えられる </p> <p> たず1行目に郚屋の倧きさを衚す<i>W</i>ず<i>H</i>がスペヌス区切りで入力される(2 &lt;= <i>W</i>, <i>H</i> &lt;= 100) 続く<i>H</i>行の各行には<i>W</i>文字の文字列が入力される 床情報を衚す文字には以䞋の皮類がある </p> <ul> <li> '.' : 歩ける床</li> <li> '#' : 穎</li> <li> 'S' : やよいが開始時に立っおいる堎所</li> <li> 'G' : やよいが蟿り぀くべき堎所</li> <li> 'M' : 巻物が眮いおある堎所</li> </ul> <p> 'S'ず'G'ず'M'は歩ける床である 'S'ず'G'はそれぞれ郚屋の䞭にちょうど1個存圚する党おの巻物が揃っおいない状態でゎヌルを通過しおも構わない 'M'は郚屋の䞭に最小で1個最倧で5個存圚する </p> <h2> Output</h2> <p> 党おの巻物を集めおスタヌトからゎヌルぞたどり着くための最短タむムを1行に出力せよ入力デヌタには必ずそのようなルヌトがあるず仮定しおよい<br/> 行の最埌には改行を出力するこず </p> <h2> Sample Input 1</h2> <pre> 3 4 S.M ... ... M.G </pre> <h2> Sample Output 1</h2> <pre> 9 </pre> <h2> Sample Input 2</h2> <pre> 4 4 S..M .... ...# #..G </pre> <h2> Sample Output 2</h2> <pre> 18 </pre> <h2> Sample Input 3</h2> <pre> 11 7 M.........M ........... ...#.S.#... ........... ...#.G.#... ........... M.........M </pre> <h2> Sample Output 3</h2> <pre> 62 </pre>
p01860
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>--> <h2>C: 買い出し - Shopping -</h2> <h3>物語</h3> <p>磯野の姉であるサゟ゚さんは『あれ』や『あれ』で遊んでいる磯野ず䞭島のために倕食を䜜っおあげるこずにしたしたあいにく冷蔵庫には食材が残り僅かしか無くサゟ゚さんは買い出しに行くこずにしたした幟぀か食材を買おうずしおいるサゟ゚さんですが倧倉陜気であるため䞀床に䞀品のみレゞで䌚蚈しおしたいたすこのたたでは遊んでいた磯野ず䞭島が買い物を終える前に垰っおきおしたい倕食を準備するこずが出来ないかもしれたせんそこでサゟ゚さんの友人であるあなたはサゟ゚さんのためにサゟ゚さんの買い物にかかる最小の時間を求めおください</p> <h3>問題</h3> <p>ずあるスヌパヌに<var>N</var>個のレゞがありそれぞれ<var>1</var>〜<var>N</var>たでの番号が぀いおいる</p> <p>たた客が<var>M</var>人居おそれぞれ<var>1</var>〜<var>M</var>たでの番号が぀いおいる<var>i</var>番目の客は時刻<var>a_i</var>に<var>c_i</var>番目のレゞに䞊び䌚蚈に<var>b_i</var>の時間がかかる1人の客は䞀床だけ䌚蚈をする</p> <p>ここである客が䞊んだレゞに既に人が䞊んでいる堎合その客は既に䞊んでいる人党員の䌚蚈が終了した埌に䌚蚈をする<var>i</var>番目の客ず<var>i+1</var>番目の客が同じレゞに䞊んでいたずするず<var>i</var>番目の客の䌚蚈開始時刻が<var>t</var>であった堎合<var>i</var>番目の客の䌚蚈終了時刻は<var>t+b_i</var><var>i+1</var>番目の客の䌚蚈開始時刻は<var>t+b_i</var>そしお<var>i+1</var>番目の客の䌚蚈終了時刻は<var>t+b_i+b_{i+1}</var>ずなる</p> <p>サゟ゚さんは1人の客であるしかしサゟ゚さんは䟋倖的に<var>K</var>回䌚蚈をするたた䌚蚈にかかる時間は0すなわちサゟ゚さんの䌚蚈開始時刻を<var>t</var>ずするず䌚蚈終了時刻は<var>t</var>ずなり次の客の䌚蚈開始時刻は<var>t</var>ずなるその埌サゟ゚さんが再床レゞに䞊ぶ際䌚蚈終了時刻<var>t</var>から品定めにかかる時間<var>D</var>だけ経っおから䞊ばなければいけない぀たり再床レゞに䞊ぶこずができる時刻は<var>t+D</var>ずなる</p> <p>たたサゟ゚さんは時刻<var>S</var>にスヌパヌにやっお来るそしお時刻<var>S</var>から<var>D</var>だけ経った時刻<var>S+D</var>に初めおサゟ゚さんはレゞに䞊ぶこずが出来る</p> <p><var>N</var><var>M</var><var>K</var><var>D</var><var>S</var>ず<var>1</var>番目〜<var>M</var>番目たでの客の情報がそれぞれ䞎えられるのでサゟ゚さんがスヌパヌに来おから最埌の䌚蚈を終えるたでにかかる時間の最小倀を求めよこの時異なる2人の客が同じ時刻に同じレゞに䞊ぶこずは無いずしサゟ゚さんずほかの人が同時にレゞに䞊がうずした堎合サゟ゚さんは垞にほかの客に順番を譲るこずずする</p> <h3>入力圢匏</h3> <p>入力は次の圢匏で䞎えられる</p> <pre> <var>N</var> <var>M</var> <var>K</var> <var>D</var> <var>S</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> ... <var>a_M</var> <var>b_M</var> <var>c_M</var> </pre> <p>1行目にスヌパヌにあるレゞの数<var>N</var><var>1 &le; N &le; 10^{15}</var>蚪れる客の数<var>M</var>(<var>1 &le; M &le; 10^5</var>)サゟ゚さんがレゞを回る回数<var>K</var>(<var>1 &le; K &le; 10^4</var>)サゟ゚さんの品定めにかかる時間<var>D</var>(<var>1 &le; D &le; 10^4</var>)サゟ゚さんがスヌパヌに来る時刻<var>S</var>(<var>1 &le; S &le; 10^4</var>)が空癜区切りで䞎えられる</p> <p>続く<var>M</var>行に蚪れる客の情報が䞎えられる<var>M</var>行のうち<var>i</var>(<var>1 &le; i &le; M</var>)行目には<var>i</var>番目の客がレゞに来る時刻<var>a_i</var>(<var>1 &le; a_i &le; 10^4</var>)䌚蚈にかかる時間<var>b_i</var>(<var>1 &le; b_i &le; 10^4</var>)やっお来るレゞの番号<var>c_i</var>(<var>1 &le; c_i &le; N</var>)が空癜区切りで䞎えられるここで<var>2 &le; M</var>の時党おの<var>i</var>(<var>1 &le; i &le; M&minus;1</var>)に぀いお<var>a_i &le; a_{i+1}</var>が成立する</p> <p>なお入力が非垞に倧きくなる堎合があるため入力の受け取りには高速な関数を甚いるこずを掚奚する</p> <h3>出力圢匏</h3> <p>サゟ゚さんがスヌパヌに来おから最埌の䌚蚈を終えるたでにかかる時間の最小倀を1行で出力せよ</p> <h3>入力䟋1</h3> <pre> 3 9 3 2 3 1 2 3 1 1 2 2 3 1 3 4 2 4 1 3 4 1 1 5 1 1 6 2 3 7 2 2 </pre> <h3>出力䟋1</h3> <pre>6</pre> <p> 時間5にレゞ3時間7にレゞ1時間9にレゞ2に䞊ぶ サゟ゚さんの入店時間が時間3なので初めおレゞに䞊んでから時間6で3回の䌚蚈が終了する たた時間9に䞊ぶレゞはレゞ1もしくはレゞ3でも最適解になる </p> <h3>入力䟋2</h3> <pre> 3 9 3 1 3 1 2 3 1 1 2 2 3 1 3 4 2 4 1 3 4 1 1 5 1 1 6 2 3 7 2 2 </pre> <h3>出力䟋2</h3> <pre>5</pre> <h3>入力䟋3</h3> <pre> 1 3 3 2 1 1 1 1 2 2 1 3 2 1 </pre> <h3>出力䟋3</h3> <pre>9</pre>
p00772
<h3>Rotate and Rewrite</h3> <p> Two sequences of integers A: <i>A</i><sub>1</sub> <i>A</i><sub>2</sub> ... <i>A</i><sub><i>n</i></sub> and B: <i>B</i><sub>1</sub> <i>B</i><sub>2</sub> ... <i>B</i><sub><i>m</i></sub> and a set of <em>rewriting rules</em> of the form "<i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> &rarr; <i>y</i>" are given. The following transformations on each of the sequences are allowed an arbitrary number of times in an arbitrary order independently. </p> <ul> <li> <b>Rotate</b>: Moving the first element of a sequence to the last. That is, transforming a sequence <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> ... <i>c</i><sub><i>p</i></sub> to <i>c</i><sub>2</sub> ... <i>c</i><sub><i>p</i></sub> <i>c</i><sub>1</sub>. </li> <li> <b>Rewrite</b>: With a rewriting rule "<i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> &rarr; <i>y</i>", transforming a sequence <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> ... <i>c</i><sub><i>i</i></sub> <i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> <i>d</i><sub>1</sub> <i>d</i><sub>2</sub> ... <i>d</i><sub><i>j</i></sub> to <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> ... <i>c</i><sub><i>i</i></sub> <i>y</i> <i>d</i><sub>1</sub> <i>d</i><sub>2</sub> ... <i>d</i><sub><i>j</i></sub>. </li> </ul> <p> Your task is to determine whether it is possible to transform the two sequences A and B into the same sequence. If possible, compute the length of the longest of the sequences after such a transformation. </p> <h3>Input</h3> <p>The input consists of multiple datasets. Each dataset has the following form.</p> <blockquote> <i>n m r</i> <br> <i>A</i><sub>1</sub> <i>A</i><sub>2</sub> ... <i>A</i><sub><i>n</i></sub><br> <i>B</i><sub>1</sub> <i>B</i><sub>2</sub> ... <i>B</i><sub><i>m</i></sub><br> <i>R</i><sub>1</sub><br> ...<br> <i>R</i><sub><i>r</i></sub><br> </blockquote> <p> The first line of a dataset consists of three positive integers <i>n</i>, <i>m</i>, and <i>r,</i> where <i>n</i> (<i>n</i> &le; 25) is the length of the sequence A, <i>m</i> (<i>m</i> &le; 25) is the length of the sequence B, and <i>r</i> (<i>r</i> &le; 60) is the number of rewriting rules. The second line contains <i>n</i> integers representing the <i>n</i> elements of A. The third line contains <i>m</i> integers representing the <i>m</i> elements of B. Each of the last <i>r</i> lines describes a rewriting rule in the following form. </p> <blockquote> <i>k</i> <i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> <i>y</i><br> </blockquote> <p> The first <i>k</i> is an integer (2 &le; <i>k</i> &le; 10), which is the length of the left-hand side of the rule. It is followed by <i>k</i> integers <i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub>, representing the left-hand side of the rule. Finally comes an integer <i>y</i>, representing the right-hand side. </p> <p> All of <i>A</i><sub>1</sub>, .., <i>A</i><sub><i>n</i></sub>, <i>B</i><sub>1</sub>, ..., <i>B</i><sub><i>m</i></sub>, <i>x</i><sub>1</sub>, ..., <i>x</i><sub><i>k</i></sub>, and <i>y</i> are in the range between 1 and 30, inclusive. </p> <p>A line "0 0 0" denotes the end of the input.</p> <h3>Output</h3> <p> For each dataset, if it is possible to transform A and B to the same sequence, print the length of the longest of the sequences after such a transformation. Print <code>-1</code> if it is impossible. </p> <h3>Sample Input</h3> <pre> 3 3 3 1 2 3 4 5 6 2 1 2 5 2 6 4 3 2 5 3 1 3 3 2 1 1 1 2 2 1 2 1 1 2 2 2 2 1 7 1 2 1 1 2 1 4 1 2 4 3 1 4 1 4 3 2 4 2 4 16 14 5 2 1 2 2 1 3 2 1 3 2 2 1 1 3 1 2 2 1 3 1 1 2 3 1 2 2 2 2 1 3 2 3 1 3 3 2 2 2 1 3 2 2 1 2 3 1 2 2 2 4 2 1 2 2 2 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 2 -1 1 9 </pre>
p00288
<h1>アルゎリズム怜定詊隓</h1> <p> あなたはむズア地区におけるアルゎリズム怜定詊隓を運営しおおり、運営費を最小にしたいず考えおいたす。運営費は、䌚堎䜿甚料、バスの䜿甚料、移動補助金の総和です。 </p> <p> 今幎は <var>N</var> 人の受隓者登録があり、それぞれ <var>c<sub>i</sub></var> 人たで受け入れ可胜な <var>M</var> 個の䌚堎を確保したした。あなたは各受隓者を必ずどこかの䌚堎に割り圓おなければなりたせん。1 人以䞊割り圓おた䌚堎に぀いおは、人数にかかわらず <var>f<sub>i</sub></var> 円の䌚堎䜿甚料を支払う必芁がありたす。 </p> <p> むズア地区は図に瀺すように東西方向ず南北方向に 1 km 間隔で道が走っおおり、受隓者の家ず䌚堎は亀差点䞊にあるず考えたす。各受隓者は家から䌚堎たで道に沿っお埒歩で移動できたす。たた、この怜定詊隓では、1 人以䞊受隓者を受け入れる各䌚堎に぀き 1 台のシャトルバスが運行されるので、受隓者はバスを利甚するこずもできたす。ただし、自分が受隓する䌚堎行きのバスにしか乗れたせん。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_algorithm" width="600"> </center> <br> <p> 各シャトルバスは、䌚堎からの東西方向の距離ず南北方向の距離の和が <var>D</var> 以内のすべおの亀差点に停車したす図は <var>D</var> = 3 の堎合。バスの䜿甚料は <var>D</var> に比䟋し、<var>D</var> が 1 km 増えるず <var>B</var> 円䞊がりたす。぀たり、シャトルバスを運行するには 1 䌚堎あたり <var>D &times; B</var> 円の費甚を支払う必芁がありたす。なお、<var>D</var> 及び <var>B</var> はすべおの䌚堎で共通の倀を甚いたす。 </p> <p> 移動補助金ずは、各受隓者に必芁な最䜎限の埒歩での移動に察しお運営者が受隓者に支払う費甚で、1 km に぀いお 1 円を払う必芁がありたす。 </p> <p> あなたは受隓者の家ず䌚堎の䜍眮、䌚堎の受け入れ可胜人数ず䜿甚料、<var>D</var> が 1 km 増えたずきに加算される料金 <var>B</var> の情報を入力デヌタずしお持っおおり、各受隓者ぞの䌚堎割り圓おず <var>D</var> を決定するこずができたすただし、<var>D</var> は 0 以䞊の敎数)。このずき、運営費の最小倀を求めおください。 </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる。入力の終わりはれロ぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>B</var> <var>ax</var><sub>1</sub> <var>ay</var><sub>1</sub> <var>ax</var><sub>2</sub> <var>ay</var><sub>2</sub> : <var>ax<sub>N</sub></var> <var>ay<sub>N</sub></var> <var>bx</var><sub>1</sub> <var>by</var><sub>1</sub> <var>c</var><sub>1</sub> <var>f</var><sub>1</sub> <var>bx</var><sub>2</sub> <var>by</var><sub>2</sub> <var>c</var><sub>2</sub> <var>f</var><sub>2</sub> : <var>bx<sub>M</sub></var> <var>by<sub>M</sub></var> <var>c<sub>M</sub></var> <var>f<sub>M</sub></var> </pre> <p> 1 行目は぀の敎数からなる。<var>N</var> (1 &le; <var>N</var> &le; 100) は受隓者の人数、<var>M</var> (1 &le; <var>M</var> &le; 5) は䌚堎数である。<var>B</var> (0 &le; <var>B</var> &le; 1000) はシャトルバスを運行する際に、<var>D</var>が 1 km 増えたずきに加算される料金である。続く <var>N</var> 行に各受隓者の家の座暙が䞎えられる。<var>ax<sub>i</sub></var>, <var>ay<sub>i</sub></var> (-1000 &le; <var>ax<sub>i</sub></var>, <var>ay<sub>i</sub></var> &le; 1000) はそれぞれ受隓者 <var>i</var> の家の <var>x</var> 座暙ず <var>y</var> 座暙を瀺す。続く <var>M</var> 行に各䌚堎の情報が䞎えられる。<var>bx<sub>i</sub></var>, <var>by<sub>i</sub></var> (-1000 &le; <var>bx<sub>i</sub></var>, <var>by<sub>i</sub></var> &le; 1000) はそれぞれ䌚堎 <var>i</var> の <var>x</var> 座暙ず <var>y</var> 座暙を瀺す。<var>c<sub>i</sub></var>(1 &le; <var>c<sub>i</sub></var> &le; 100) は䌚堎 <var>i</var> の受け入れ可胜人数、<var>f<sub>i</sub></var> (0 &le; <var>f<sub>i</sub></var> &le; 100000) は䌚堎 <var>i</var> の䜿甚料を瀺す。ただし、<var>c<sub>1</sub></var> から<var>c<sub>M</sub></var> たでの合蚈は <var>N</var> 以䞊である。 </p> <p> 入力は以䞋の条件を満たすず考えおよい。 </p> <ul> <li> 䜿甚する䌚堎を決めたずき、<var>D = i</var> におけるそれらの䌚堎ぞの受隓者の割り圓お方のうち移動補助金が最小ずなるずきの金額を <var>F</var>(<var>i</var>) ずする。このずき、<var>F</var>(<var>i</var>+2) - <var>F</var>(<var>i</var>+1) &ge; <var>F</var>(<var>i</var>+1)-<var>F</var>(<var>i</var>) が成立する。</li> </ul> <p> デヌタセットの数は 10 を超えない。 </p> <h2>出力</h2> <p> デヌタセットごずに詊隓の運営費の最小倀を 1 行に出力する。 </p> <h2>入出力䟋</h2> <br> <h2>入力䟋</h2> <pre> 1 1 1 0 0 0 0 1 0 1 1 0 0 0 -3 0 2 3 1 3 1 0 0 -3 0 2 3 0 -5 2 0 4 0 2 1 4 3 1 0 0 0 0 0 0 0 0 -3 0 2 3 0 -5 2 0 4 0 2 1 6 3 1 0 0 0 0 0 0 0 0 0 0 0 0 -3 0 2 3 0 -5 2 0 4 0 2 1 6 3 2 0 0 0 0 0 0 0 0 0 0 0 0 -3 0 2 3 0 -5 2 0 4 0 2 1 10 5 1 0 0 2 0 4 0 8 0 100 0 100 0 100 0 100 0 100 0 100 0 -3 0 1 0 1 0 1 0 3 0 2 0 15 0 1 0 105 0 6 0 10 5 2 0 0 2 0 4 0 8 0 100 0 100 0 100 0 100 0 100 0 100 0 -3 0 1 0 1 0 1 0 3 0 2 0 15 0 1 0 105 0 6 0 0 0 0 </pre> <h2>出力䟋</h2> <pre> 0 3 5 11 18 28 20 38 </pre>
p00322
<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> 足し算は筆算で簡単に蚈算できたすが、もし、いく぀かの数字が欠けおいたら、欠けおいる数字を埋めるのは簡単でしょうか 䟋えば、以䞋のような筆算においお、からの数字が䞀床しか珟れないずいう条件があるずき、ずのマスに入る数字はいく぀になるでしょう この堎合、に入るのはに入るのはが正解ずなりたす。このように、数字がいく぀か欠けおいる挔算を虫食い算ず呌びたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_calculation1"><br/> </center> <br/> <p> からの数字が䞀床しか珟れないずいう条件はそのたたで、以䞋のようにもっずたくさんの数字が欠けおいたら、正解ずなる数字の埋め方は䞀通りしかないのでしょうか 実は、必ず䞀通りに決たるずは限りたせん。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_calculation2"><br/> </center> <br/> <p> 䞊の図のような圢をした虫食い算の、からの各マスの情報が䞎えられたずき、正しい埋め方が䜕通りあるかを出力するプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var> <var>G</var> <var>H</var> <var>I</var> </pre> <p> 行に、虫食い算の <var></var> から <var></var> のマスに入っおいる数字の情報が䞎えられる。ただし、䞎えられた倀が -1 のずきは、そのマスの数字が欠けおいるこずを衚す。-1 以倖の倀は、1 から 9 の敎数のいずれかで、それらの間に重耇はない。 </p> <h2>Output</h2> <p> 正しい埋め方が䜕通りあるかを行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 7 6 -1 1 -1 9 2 3 4 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <br/> <h2>Sample Input 2</h2> <pre> 7 6 5 1 8 9 2 3 4 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre> <br/> <h2>Sample Input 3</h2> <pre> -1 -1 -1 -1 -1 -1 8 4 6 </pre> <h2>Sample Output 3</h2> <pre> 12 </pre> <br/> <h2>Sample Input 4</h2> <pre> -1 -1 -1 -1 -1 -1 -1 -1 -1 </pre> <h2>Sample Output 4</h2> <pre> 168 </pre>
p01925
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>クむズ</h3> <p>あなたはクむズ番組のディレクタヌである クむズ番組には解答者ずしお <i>N</i> 人が出挔予定でありそれぞれ 1 から <i>N</i> たで番号付けられおいる </p> <p>問題は <i>M+1</i> 問出題する予定でありそれぞれの問題は 1 から <i>M+1</i> たで番号付けられおいる 問題は番号順に出題されそれぞれ早抌しで最初に正解した人にのみ埗点が入る<i>i</i> 問目の問題の埗点は敎数 <i>S<sub>i</sub></i> である <i>M+1</i> 問目の問題を終えた時点で総合埗点が最倧の人が優勝する ただし最倧埗点の人が耇数人存圚する堎合優勝者は存圚しない </p> <p>珟圚 <i>M</i> 問目たで配点を決めたので<i>M+1</i> 問目の配点を決めようず考えおいる 最埌の問題は誰でも逆転できる点数にするのがクむズ番組のお玄束である しかしその堎で解答者たちの総合埗点を芋お問題の点数を決めるず解答者たちのやる気を削ぐ可胜性があるそこで どんな点数状況でも党員に逆転のチャンスがあるような点数蚭定をあらかじめ考えるこずにした </p> <p>幞い1 から <i>M</i> 問目たではそれぞれ正解する可胜性がある解答者が分かっおいる<i>M+1</i> 問目は党員が正解する可胜性のある問題である正解する可胜性がある解答者の䞭で早抌しで正解した1名のみが問題の埗点 <i>S<sub>i</sub></i> を埗る問題ぞの解答は正解した解答者が珟れた時点で締め切られ同じ解答者は䜕床でも解答を行うこずができるためある問題の埗点 <i>S<sub>i</sub></i> を誰も埗られない堎合は考慮しなくおよいたた耇数人の解答者がある問題の埗点 <i>S<sub>i</sub></i> を重耇しお獲埗したり埗点を分け合ったりするこずもない </p> <p>各問の配点ず正解可胜な解答者の情報を基に 起こりうるどのような埗点状況においおも最埌の問題を正解すれば必ず誰でも優勝できるように最埌の問題の点数 <i>S<sub>M+1</sub></i> を蚭定したい 条件を満たす敎数 <i>S<sub>M+1</sub></i> ずしお最小の倀を求めよ </p> <h3>Input</h3> <blockquote></blockquote> <p>入力デヌタセットは耇数のケヌスから構成される各ケヌスは次のような圢匏である </p><blockquote><i>N</i> <i>M</i><br><i>S<sub>1</sub></i> <i>k<sub>1</sub></i> <i>c<sub>1,1</sub></i> ... <i>c<sub>1,k<sub>1</sub></sub></sub></i><br>...<br><i>S<sub>M</sub></i> <i>k<sub>M</sub></i> <i>c<sub>M,1</sub></i> ... <i>c<sub>M,k<sub>M</sub></sub></sub></i></blockquote> <p>1 行目には解答者の数 <i>N</i> ず最埌の問題を陀いた問題の個数 <i>M</i> が䞎えられる 続く <i>M</i> 行には問題 1 〜 <i>M</i> に぀いおの解答できる可胜性のある解答者の情報が䞎えられるそのうち <i>i</i> 行目には<i>i</i> 問目の埗点 <i>S<sub>i</sub></i> ず<i>i</i> 問目に正解する可胜性がある解答者の人数 <i>k<sub>i</sub></i> が䞎えられたたその盎埌に <i>k<sub>i</sub></i> 個の数 <i>c<sub>i,1</sub> ... c<sub>i,k<sub>i</sub></sub></i> が䞎えられる<i>c<sub>i,j</sub></i> (<i>1 &le; j &le; k<sub>i</sub></i>) はそれぞれ <i>i</i> 問目に正解する可胜性がある解答者の番号を衚す </p> <p>入力の終わりは 2 ぀のれロからなる行で瀺すデヌタセットの個数は最倧でも 30 個を超えない </p> <p>入力で䞎えられる数倀は党お敎数であり以䞋の条件を満たす </p><ul><li> <i>2 &le; N &le; 10,</sub>000</i> </li><li> <i>1 &le; M &le; 1,</sub>000</i> </li><li> <i>1 &le; S<sub>i</sub> &le; 100</i> </li><li> <i>1 &le; k<sub>i</sub> &le; N</i> </li><li> <i>1 &le; c<sub>i,1</sub> < ... < c<sub>i,k<sub>i</sub></sub> &le; N</i> </li><li> <i>Σk<sub>i</sub> &le; 100,000</i> </li></ul> <p>ただし出力すべき <i>S<sub>M+1</sub></i> はこの範囲を超える堎合があるこずに泚意せよ </p> <h3>Output</h3> <p>各デヌタセットに぀いお条件を満たすような最埌の問題の点数 <i>S<sub>M+1</sub></i> の最小倀を 1 行に出力せよ </p> <h3>Sample Input</h3> <pre>3 2 5 2 1 3 8 2 2 3 2 3 8 2 1 2 3 1 1 5 1 2 2 5 100 1 1 100 1 1 100 1 1 100 1 1 100 1 1 3 4 5 1 1 5 1 2 100 2 1 3 100 2 2 3 0 0</pre> <h3>Output for Sample Input</h3> <pre>14 11 501 196</pre>
p03918
<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>
p00637
<H1><font color="#000000">Problem A:</font> Citation Format</H1> <p> To write a research paper, you should definitely follow the structured format. This format, in many cases, is strictly defined, and students who try to write their papers have a hard time with it. </p> <p> One of such formats is related to citations. If you refer several pages of a material, you should enumerate their page numbers in ascending order. However, enumerating many page numbers waste space, so you should use the following abbreviated notation: </p> <p> When you refer all pages between page <i>a</i> and page <i>b</i> (<i>a</i> &lt; <i>b</i>), you must use the notation "<i>a</i>-<i>b</i>". For example, when you refer pages 1, 2, 3, 4, you must write "1-4" not "1 2 3 4". You must not write, for example, "1-2 3-4", "1-3 4", "1-3 2-4" and so on. When you refer one page and do not refer the previous and the next page of that page, you can write just the number of that page, but you must follow the notation when you refer successive pages (more than or equal to 2). Typically, commas are used to separate page numbers, in this problem we use space to separate the page numbers. </p> <p> You, a kind senior, decided to write a program which generates the abbreviated notation for your junior who struggle with the citation. </p> <H2>Input</H2> <p> Input consists of several datasets. </p> <p> The first line of the dataset indicates the number of pages <i>n</i>. </p> <p> Next line consists of <i>n</i> integers. These integers are arranged in ascending order and they are differ from each other. </p> <p> Input ends when <i>n</i> = 0. </p> <H2>Output</H2> <p> For each dataset, output the abbreviated notation in a line. Your program should not print extra space. Especially, be careful about the space at the end of line. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>n</i> &le; 50</li> </ul> <H2>Sample Input</H2> <pre> 5 1 2 3 5 6 3 7 8 9 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1-3 5-6 7-9 </pre>
p00267
<H1>寂しがり屋の぀いた嘘</H1> <p> パケットモンスタヌずいうゲヌムがありたす。モンスタヌを捕たえ、育お、戊わせたり亀換したりするゲヌムで、日本䞭で倧流行しおいたす。もちろん、わたしのクラスでも。だからわたしもこのゲヌムでみんなず遊べるようにモンスタヌを育おおいるけど、悲しいこずに察戊する盞手がいたせん。わたしは積極的に人に話しかけるのが埗意なタむプではないからです。だから今日も、クラスメむトが誘っおくれるのを埅ちながら、独り寂しくモンスタヌのレベルを䞊げおいたす。 </p> <p> そしお぀いに、埅ち望んでいた瞬間が蚪れたした。クラスメむトの䞀人が察戊しないかずわたしに話を持ちかけおきたのでした。圌女は自慢気に、圌女のモンスタヌたちを芋せおくれたした。 </p> <p> 䞀般的なパケットモンスタヌの察戊ルヌルでは、各プレむダヌがそれぞれN 匹のモンスタヌを甚意し、互いに1 匹ず぀戊わせたす。各モンスタヌには成長の床合いを瀺す「レベル」ずいう数倀があり、レベルが倧きいモンスタヌが必ず勝ちたす。同レベルのずきは匕き分けです。䞀床戊ったモンスタヌは、それ以䞊戊わせるこずができたせん。こうしお䞀察䞀の戊いをN 回行ったあず、過半数の勝利を収めたプレむダヌが勝者ずなりたす。 </p> <p> わたしは、圌女のモンスタヌを芋た瞬間、嫌な予感がしたした。圌女のモンスタヌはどれも、ずおも匷そうなのです。わたしず戊っおくれるのなら負けおもかたいたせん。でも、あたりにもひどい負け方をしたら、"こい぀ず戊っおも面癜くないな"ずか思われお、もう遊んでくれなくなるんじゃないかな。それは、ずおも嫌です。だから、<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;「ごめん、わたしただモンスタヌをN 匹持っおなくお」 </p> <p> 嘘を぀きたした。 </p> <p> N 回勝負では勝ち目がなくおも、それより少ない数のモンスタヌで勝負する特別ルヌルなら、もしかしたら勝おるかもしれたせん。さっきは負けたっおかたわないず蚀ったけど、やっぱり勝おたら嬉しいです。 </p> <p> 圌女はこの特別ルヌルを受け入れおくれたした。぀たり、二人が持っおいるモンスタヌからお互いに k 匹遞んで䞀匹ず぀順番に戊わせ、過半数の(぀たり、k/2 より倧きな数の) 勝利を収めた方が勝ちずなりたす。 </p> <p> さっきわたしは、圌女のモンスタヌのレベルを知っおしたいたした。圌女がどのモンスタヌを遞び、どんな順番で出しおくるのかはわかりたせん。でも、察戊させるモンスタヌの数kをわたしがうたく決めれば、圌女がどんな遞択をしようずわたしが勝぀こずができるかもしれたせん。 </p> <p> 皆さんにお願いです。モンスタヌの数 N ず、二人が持っおいるモンスタヌのレベルを入力するず、圌女がどんな遞択をしようずわたしが勝おるような最小のモンスタヌの数 k を出力するプログラムを䜜成しお䞋さい。 </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる。入力の終わりはれロ぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 </p> <pre> N a<sub>1</sub> a<sub>2</sub> ... a<sub>N</sub> b<sub>1</sub> b<sub>2</sub> ... b<sub>N</sub> </pre> <p> 行目にモンスタヌの数 N (1 &le; N &le; 40000) が䞎えられる。行目に自分のモンスタヌのレベル a<sub>i</sub> (1 &le; a<sub>i</sub> &le; 100000) が぀の空癜区切りで䞎えられる。行目にクラスメむトのモンスタヌのレベル b<sub>i</sub> (1 &le; b<sub>i</sub> &le; 100000) が぀の空癜区切りで䞎えられる。 </p> <p> デヌタセットの数は 50 を超えない。 </p> <h2>出力</h2> <p> デヌタセットごずに、k (1 &le; k &lt; N) が存圚すれば最小倀を行に出力する。もし、k が存圚しないか、k が N に等しければ NA ず出力する。 </p> <h2>入力䟋</h2> <pre> 10 4 9 1 9 5 9 2 3 2 1 8 7 6 5 10 5 5 4 7 6 5 4 3 2 5 1 4 4 4 4 4 4 4 1 3 2 4 3 2 1 0 </pre> <h2>出力䟋</h2> <pre> 3 1 NA </pre> <p> ぀目のデヌタセットでは、わたしは匹での察戊を提案し、レベルが [9, 9, 9] のモンスタヌを遞べば良い。盞手のレベル 10 以倖のどのモンスタヌにも勝おるので、少なくずも勝できる。匹での察戊では 勝敗になる可胜性があり、これは過半数の勝利ずは蚀えないので、2 は答えにならない。 </p> <p> ぀目のデヌタセットでは、わたしは最匷のモンスタヌを匹遞べば良い。 </p> <p> ぀目のデヌタセットでは、わたしがどの k 匹を遞び、どの順番で出したずしおも、圌女が党く同じモンスタヌを同じ順番で出しおきお匕き分けになる可胜性がある。したがっお、「圌女がどんな遞択をしようずわたしが勝぀こずができる」ずは蚀い切れない。 </p>
p01026
<h1>Problem K: Witch Craft Moves</h1> <h2>Problem</h2> <p> 䌚接魔法孊校は、魔法を䜿える者が集る孊校である。 䌚接魔法孊校には1~<var>N</var>たでの番号が぀いた教宀ず教宀同士を぀なぐ廊䞋がある。教宀や廊䞋は䜕床でも通るこずができる。たた、䌚接魔法孊校には任意の教宀<var>u</var>,<var>v</var>間を0個以䞊の教宀ず廊䞋を䞀床ず぀通っお移動するこずができるような経路がただ1぀ある。 各教宀には魔法陣が蚭眮しおある。この魔方陣によっお、教宀に入る床に入った者の魔力が増枛させられおしたうのだ。生埒の移動を助けるために以䞋の二぀の質問に応えおほしい。 </p> <p> 質問1<br/> 0 A B<br/> 教宀<var>A</var>から<var>B</var>ぞ移動したずきの魔力の残量を出力しおほしい。教宀<var>A</var>ず<var>B</var>での増枛も含む。たた、この質問開始時点での魔力の量は毎回0である。 </p> <p> 質問2<br/> 1 A C<br/> 教宀<var>A</var>の魔力の増枛量が<var>C</var>だけ倉動させる。 </p> <h2>Input</h2> <pre> <var>N</var> <var>cost<sub>1</sub></var> : <var>cost<sub>N</sub></var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> : <var>a<sub>N-1</sub></var> <var>b<sub>N-1</sub></var> <var>Q</var> <var>query<sub>1</sub></var> : <var>query<sub>Q</sub></var> </pre> <p> 入力の最初に教宀の数<var>N</var>が䞎えられる。続く<var>N</var>行に各教宀に入ったずきの魔力が増枛する量が䞎えられる。<var>i</var>行目の倀が<var>i</var>番の教宀の情報に察応する。続く<var>N-1</var>行に廊䞋の情報が䞎えられる。<var>j</var>行目の廊䞋は<var>a<sub>j</sub></var>番目ず<var>b<sub>j</sub></var>番目の教宀を぀なぐこずを衚す。次に質問の数<var>Q</var>が䞎えられる。続く<var>Q</var>行に䞊蚘の圢匏で質問が䞎えられる。 </p> <h2>Output</h2> <p>各質問1に぀いお、答えを行に出力せよ。</p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var>&le; 2000</li> <li>1 &le; <var>A<sub>i<sub></var>&le; 2000</li> <li>1 &le; <var>B<sub>i<sub></var>&le; 2000</li> <li>1 &le; <var>a<sub>j<sub></var>,<var>b<sub>j</sub> &le; N</var></li> <li>1 &le; <var>Q</var>&le; 1000000</li> <li>-10000 &le; <var>C<sub>i<sub></var>&le; 10000</li> </ul> <h2>Sample Input 1</h2> <pre> 7 1 2 3 4 5 6 7 1 2 1 3 3 4 3 5 5 6 5 7 10 0 1 7 0 2 7 1 1 15 0 1 7 0 2 7 0 1 1 1 1 -15 0 1 7 0 2 7 0 1 1 </pre> <h2>Sample Output 1</h2> <pre> 16 18 31 33 16 16 18 1 </pre>
p01476
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h2>問題文</h2> <p>実数倉数 $X_1, X_2, ...$ があり、䜕らかの初期倀が割り振られおいる。 これから $Q$ 個の情報が順番に䞎えられる。䞎えられる情報は以䞋の2皮類のいずれかである。</p> <ul><li>min $\{X_{a_i}, X_{a_i+1}, ..., X_{b_i}\} = y_i$ である。</li> <li>倉数 $X_{a_i}, X_{a_i+1}, ..., X_{b_i}$ に $y_i$ を代入する。</li></ul> <p>これら $Q$ 個の情報が矛盟しないように各倉数の初期倀を遞べるかどうか刀定せよ。</p> <h2>入力</h2> <p>入力は以䞋の圢匏に埓う。䞎えられる数は党お敎数である。</p> <pre>$Q$ $t_1$ $a_1$ $b_1$ $y_1$ $t_2$ $a_2$ $b_2$ $y_2$ $...$ $t_Q$ $a_Q$ $b_Q$ $y_Q$</pre> <ol><li>$t_i=0$ のずき、min$\{X_{a_i}, X_{a_i+1}, ..., X_{b_i}\} = y_i$ であるこずを瀺しおいる。</li> <li>$t_i=1$ のずき、$X_{a_i}, X_{a_i+1}, ..., X_{b_i}$ に $y_i$ を代入するこずを瀺しおいる。</li></ol> <h2>制玄</h2> <ul><li>$1 \leq Q \leq 5 \times 10^4$</li> <li>$0 \leq t_i \leq 1$</li> <li>$1 \leq a_i \leq b_i \leq 10^9$</li> <li>$1 \leq y_i \leq 10^9$</li></ul> <h2>出力</h2> <p>党おの情報が矛盟しないような初期倀が存圚すれば&quot;YES&quot;を、そうでなければ&quot;NO&quot;を1行に出力せよ。</p> <h2>Sample Input 1</h2> <pre>5 0 1 2 8 0 2 3 9 0 2 2 11 1 2 2 7 0 1 3 7</pre> <h2>Output for the Sample Input 1</h2> <pre>YES</pre> <p>初期倀を、$\{X_1, X_2, X_3\} = \{8, 11, 9\}$ ずする。このずき、</p> <ol><li> min$\{X_1, X_2\} = $min$\{8, 11\} = 8$</li> <li>min$\{X_2, X_3\} = $min$\{11, 9\} = 9$</li> <li>min$\{X_2\} = $min$\{11\} = 11$</li> <li>$X_2 = 7$</li> <li>min$\{X_1, X_2, X_3\} = $min$\{8, 7, 9\} = 7$</li></ol> <p>ずなり党おの情報ず矛盟しない。</p> <h2>Sample Input 2</h2> <pre>2 1 10 100 333 0 100 1000 555</pre> <h2>Output for the Sample Input 2</h2> <pre>NO</pre> <p>1぀目の情報で $X_{10}$ から $X_{100}$ の倀が $333$ になったこずが分かる。 2぀目の情報は min$\{X_{100},...,X_{1000}\}=555$ ずなるこずを瀺しおいるが、これは $X_{100}=333$ であるこずから矛盟が生じる。</p>
p01319
<h1><font color="#000">Problem F:</font> Canal: Water Going Up and Down</h1> <!-- <h3><U>閘門匏運河: 䞊䞋に動く氎面</U></h3> --> <p>ACM囜には䞭倮を東西に流れる川があるこの川は西の隣囜からACM囜を通り東の隣囜ぞず流れおおりACM囜内の党長は <i>K</i> kmであるこの川にいく぀かの閘門を蚭眮し運河ずしお利甚するこずが蚈画されおいる</p> <p>閘門ずは異なる2぀の氎䜍間を船が移動するための仕組みである閘門は䞊流偎ず䞋流偎にそれぞれ氎門を持ちそれらの間に閘宀ず呌ばれる小さな氎域を持぀この閘宀に船を入れた埌に泚氎あるいは排氎を行い閘宀の氎䜍を䞊䞋させるこずで船も䞊䞋させる以䞋にその暡匏図を瀺す</p> <center> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_F1" /><br /> 図 F-1: 閘門の暡匏図</p> </center> <p>この川の川幅はあたり広くないため西から東ぞ䞀方通行の運河ずなるこずが決たっおいる蚭蚈の担圓者は運河を効率良く運甚するため予想される船の航行スケゞュヌルに合わせお閘門の蚭眮堎所などを最適にしたいず考えおいる</p> <p>あなたは蚭蚈担圓者に雇われおいるプログラマヌであるあなたの仕事は閘門の情報ず耇数の船の航行スケゞュヌルが䞎えられたずき党おの船が川を通過するたでの時間をシミュレヌションにより求めるプログラムを曞くこずである</p> <p>各閘門は以䞋の情報によっお衚される</p> <ul> <li>ACM囜西端からの距離 <i>X</i> (km)</li> <li>氎䜍の切り替えに必芁な氎の容積 <i>L</i> (L)</li> <li>単䜍時間あたりの最倧泚氎量 <i>F</i> (L/h)</li> <li>単䜍時間あたりの最倧排氎量 <i>D</i> (L/h)</li> <li>閘門の西偎の氎䜍ず東偎の氎䜍の䞊䞋関係</li> </ul> <p>䟿宜䞊シミュレヌションにおいお川はACM囜倖においおも同様に無限に続いおいるものずする</p> <p>シミュレヌションの開始時点においお党おの閘宀の氎䜍は東偎ず西偎の氎䜍のうち䜎い方にあるたた航行スケゞュヌルに含たれる船はACM囜の西端を先頭地点ずしお入力で䞎えられる順に東から西に向かっお1kmおきに䞊んでいるものずする 䟿宜䞊先頭の船の初期䜍眮を0km地点ずする</p> <p>シミュレヌション開始ずずもに船は東に向かっお航行を始めるこのずきある船の前埌1km未満に他の船が入っおはならない 各船にはそれぞれ最倧船速 <i>V</i> (km/h)が蚭定されおいる船は䞀瞬で任意の船速に達しさらに䞀瞬で静止するこずすらできる基本的に船は最倧船速で航行するが先行する船より埌続の船のほうが最倧船速が速くか぀埌続の船が先行する船の1km手前に远い぀いた堎合は埌続の船は先行する船ず同じ船速で航行する船及び閘門の倧きさは無芖できるものずする</p> <p>船は閘門の西偎の氎䜍ず閘宀の氎䜍が等しいずきのみその閘門に入るこずができる同様に閘門の東偎の氎䜍ず閘宀の氎䜍が等しいずきのみその閘門から出るこずができる各閘宀の氎䜍は䞭に船がいない堎合はその閘門の西偎の氎䜍ず䞀臎するたで䞊昇たたは䞋降するたた船がいる堎合はその閘門の東偎の氎䜍ず䞀臎するたで倉䜍する閘門の䞁床1km先で船が停泊しおいる堎合でも船は閘門から出るこずができるただしこのずき船は先行する船が発進するたで閘門から出たずころで停泊しなければならない</p> <p>船はACM囜の東端を通過した埌可胜な限りの速床で無限遠たで航行する党おの船がACM囜の東端を通過し終えた時点でシミュレヌションは終了する</p> <h2>Input</h2> <p>入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる</p> <blockquote><i>N</i> <i>M</i> <i>K</i><br /> <i>X<sub>1</sub></i> <i>L<sub>1</sub></i> <i>F<sub>1</sub></i> <i>D<sub>1</sub></i> <i>UD<sub>1</sub></i><br /> <i>X<sub>2</sub></i> <i>L<sub>2</sub></i> <i>F<sub>2</sub></i> <i>D<sub>2</sub></i> <i>UD<sub>2</sub></i><br /> ...<br /> <i>X<sub>N</sub></i> <i>L<sub>N</sub></i> <i>F<sub>N</sub></i> <i>D<sub>N</sub></i> <i>UD<sub>N</sub></i><br /> <i>V<sub>1</sub></i><br /> <i>V<sub>2</sub></i><br /> ...<br /> <i>V<sub>M</sub></i><br /> </blockquote> <p>最初の1行は3぀の敎数 <i>N</i>, <i>M</i>, <i>K</i> からなる <i>N</i> (1 &le; <i>N</i> &le; 100) は閘門の数 <i>M</i> (1 &le; <i>M</i> &le; 100) は船の数 <i>K</i> (2 &le; <i>K</i> &le; 1000) は川のACM囜内における党長をそれぞれ衚す</p> <p>続く <i>N</i> 行は閘門の情報を衚す 各行は5぀の敎数 <i>X<sub>i</sub></i>, <i>L<sub>i</sub></i>, <i>F<sub>i</sub></i>, <i>D<sub>i</sub></i>, <i>UD<sub>i</sub></i> からなる <i>X<sub>i</sub></i> (1 &le; <i>X<sub>i</sub></i> &le; <i>K</i> - 1) は閘門 <i>i</i> のACM囜西端からの䜍眮(km) <i>L<sub>i</sub></i> (1 &le; <i>L<sub>i</sub></i> &le; 1000) は閘門 <i>i</i> の氎䜍の切り替えに必芁な氎の容積(L) <i>F<sub>i</sub></i> (1 &le; <i>F<sub>i</sub></i> &le; 1000) は閘門 <i>i</i> の単䜍時間あたりの最倧泚氎量(L/h) <i>D<sub>i</sub></i> (1 &le; <i>D<sub>i</sub></i> &le; 1000) は閘門 <i>i</i> の単䜍時間あたりの最倧排氎量(L/h) <i>UD<sub>i</sub></i> (<i>UD<sub>i</sub></i> &isin; {0, 1})は閘門 <i>i</i> の西偎の氎䜍ず東偎の氎䜍の䞊䞋関係をそれぞれ衚す <i>UD<sub>i</sub></i> が 0 の堎合閘門 <i>i</i> は西偎より東偎が氎䜍が高いこずを衚す䞀方 <i>UD<sub>i</sub></i> が 1 の堎合閘門 <i>i</i> は西偎より東偎が氎䜍が䜎いこずを衚す</p> <p>続く <i>M</i> 行には各行に <i>i</i> 番目の船の最倧船速(km/h)を衚す敎数 <i>V<sub>i</sub></i> (1 &le; <i>V<sub>i</sub></i> &le; 1000) が䞎えられる</p> <p>閘門は <i>X<sub>i</sub></i> の倀の小さい順で䞎えられるたた同䞀の䜍眮に耇数の閘門が蚭眮されるこずはない</p> <p>入力の終りはスペヌスで区切られた3個のれロからなる</p> <h2>Output</h2> <p>各デヌタセットに察しシミュレヌション開始から終了たでの時刻を1行で出力せよ出力する倀は10<sup>-6</sup>以䞋の誀差を含んでいおも構わない倀は小数点以䞋䜕桁衚瀺しおも構わない</p> <h2>Sample Input</h2> <pre> 1 1 100 50 200 20 40 0 1 2 4 100 7 4 1 4 1 19 5 1 4 0 5 3 7 9 1 2 3 1 1 1 1 0 1 3 1 2 10 5 10 1 1 1 2 3 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 110 46.6666666667 5 41.6666666667 </pre>
p03324
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.<br/> As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by <var>100</var> <strong>exactly</strong> <var>D</var> times.</p> <p>Find the <var>N</var>-th smallest integer that would make Ringo happy.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>D</var> is <var>0</var>, <var>1</var> or <var>2</var>.</li> <li><var>N</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>D</var> <var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the <var>N</var>-th smallest integer that can be divided by <var>100</var> exactly <var>D</var> times.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>0 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>The integers that can be divided by <var>100</var> exactly <var>0</var> times (that is, not divisible by <var>100</var>) are as follows: <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var>, <var>6</var>, <var>7</var>, ...<br/> Thus, the <var>5</var>-th smallest integer that would make Ringo happy is <var>5</var>. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1100 </pre> <p>The integers that can be divided by <var>100</var> exactly once are as follows: <var>100</var>, <var>200</var>, <var>300</var>, <var>400</var>, <var>500</var>, <var>600</var>, <var>700</var>, <var>800</var>, <var>900</var>, <var>1 \ 000</var>, <var>1 \ 100</var>, ...<br/> Thus, the integer we are seeking is <var>1 \ 100</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 85 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>850000 </pre> <p>The integers that can be divided by <var>100</var> exactly twice are as follows: <var>10 \ 000</var>, <var>20 \ 000</var>, <var>30 \ 000</var>, ...<br/> Thus, the integer we are seeking is <var>850 \ 000</var>.</p></section> </div> </span>
p02866
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is an integer sequence <var>D_1,...,D_N</var> of <var>N</var> elements. Find the number, modulo <var>998244353</var>, of trees with <var>N</var> vertices numbered <var>1</var> to <var>N</var> that satisfy the following condition:</p> <ul> <li>For every integer <var>i</var> from <var>1</var> to <var>N</var>, the distance between Vertex <var>1</var> and Vertex <var>i</var> is <var>D_i</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Notes</h3><ul> <li>A tree of <var>N</var> vertices is a connected undirected graph with <var>N</var> vertices and <var>N-1</var> edges, and the distance between two vertices are the number of edges in the shortest path between them.</li> <li>Two trees are considered different if and only if there are two vertices <var>x</var> and <var>y</var> such that there is an edge between <var>x</var> and <var>y</var> in one of those trees and not in the other.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>0 \leq D_i \leq N-1</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 0 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>For example, a tree with edges <var>(1,2)</var>, <var>(1,3)</var>, and <var>(2,4)</var> satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 0 3 2 1 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>24 </pre></section> </div> </span>
p01749
<p> すぬけ君は"<var>s</var> で<var>t</var> <var>t</var>" ずいうダゞャレを思い぀いたが忘れおしたったすぬけ君は以䞋のこずを芚えおいる </p> <ul> <li> <var>s</var> の長さは <var>N</var> である</li> <li> <var>t</var> の長さは <var>M</var> である</li> <li> <var>t</var> は <var>s</var> の郚分文字列である(<var>s</var> の連続する <var>M</var> 文字で <var>t</var> ず䞀臎しおいる郚分が存圚する)</li> </ul> <p> <var>(s, t)</var> ずしお考えられる組み合わせの個数を 1,000,000,007 で割ったあたりを求めよただし文字は <var>A</var> 皮類存圚するものずする </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>N</var> &le; 200 </li> <li> 1 &le; <var>M</var> &le; 50</li> <li> <var>M</var> &le; <var>N</var></li> <li> 1 &le; <var>A</var> &le; 1000</li> </ul> <h2>Input</h2> <Pre> <var>N</var> <var>M</var> <var>A</var> </pre> <h2>Output</h2> <p> 条件を満たす文字列の組 <var>(s, t)</var> の個数を 1,000,000,007 で割ったあたりを出力せよ </p> <h2>Sample Input 1</h2> <pre> 3 2 2 </pre> <h2>Sample Output 1</h2> <pre> 14 </pre> <h2>Sample Input 2</h2> <pre> 200 50 1000 </pre> <h2>Sample Output 2</h2> <pre> 678200960 </pre>
p03774
<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> students and <var>M</var> checkpoints on the <var>xy</var>-plane.<br/> The coordinates of the <var>i</var>-th student <var>(1 \leq i \leq N)</var> is <var>(a_i,b_i)</var>, and the coordinates of the checkpoint numbered <var>j</var> <var>(1 \leq j \leq M)</var> is <var>(c_j,d_j)</var>.<br/> When the teacher gives a signal, each student has to go to the nearest checkpoint measured in <em>Manhattan distance</em>. <br/> The Manhattan distance between two points <var>(x_1,y_1)</var> and <var>(x_2,y_2)</var> is <var>|x_1-x_2|+|y_1-y_2|</var>.<br/> Here, <var>|x|</var> denotes the absolute value of <var>x</var>.<br/> If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.<br/> Which checkpoint will each student go to?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,M \leq 50</var></li> <li><var>-10^8 \leq a_i,b_i,c_j,d_j \leq 10^8</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>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_N</var> <var>b_N</var> <var>c_1</var> <var>d_1</var> <var>:</var> <var>c_M</var> <var>d_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines.<br/> The <var>i</var>-th line <var>(1 \leq i \leq N)</var> should contain the index of the checkpoint for the <var>i</var>-th student to go.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 0 0 0 -1 0 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 </pre> <p>The Manhattan distance between the first student and each checkpoint is:</p> <ul> <li>For checkpoint <var>1</var>: <var>|2-(-1)|+|0-0|=3</var></li> <li>For checkpoint <var>2</var>: <var>|2-1|+|0-0|=1</var></li> </ul> <p>The nearest checkpoint is checkpoint <var>2</var>. Thus, the first line in the output should contain <var>2</var>.</p> <p>The Manhattan distance between the second student and each checkpoint is:</p> <ul> <li>For checkpoint <var>1</var>: <var>|0-(-1)|+|0-0|=1</var></li> <li>For checkpoint <var>2</var>: <var>|0-1|+|0-0|=1</var></li> </ul> <p>When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 4 10 10 -10 -10 3 3 1 2 2 3 3 5 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 1 2 </pre> <p>There can be multiple checkpoints at the same coordinates.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 5 -100000000 -100000000 -100000000 100000000 100000000 -100000000 100000000 100000000 0 0 0 0 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 4 3 2 1 </pre></section> </div> </span>
p02535
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke likes integers that are greater than or equal to <var>A</var>, and less than or equal to <var>B</var>. Takahashi likes integers that are greater than or equal to <var>C</var>, and less than or equal to <var>D</var>.</p> <p>Does there exist an integer liked by both people?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq A \leq B \leq 10^{18}</var></li> <li><var>0 \leq C \leq D \leq 10^{18}</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</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>10 30 20 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>For example, both like <var>25</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 20 30 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre></section> </div> </span>
p00508
<H1>問題 </H1> <br/> <p>  平面䞊の n 個の点 P<sub>1</sub>, ..., P<sub>n</sub> が䞎えられたずき 距離が最小の点を求めたい </p> <p>  入力ファむルの行目には敎数 n が曞いおある 行目から n+1 行目のそれぞれには ぀の正敎数 x, y が぀の半角空癜文字を区切りずしお曞いおある i+1 行目の x, y はそれぞれ P<sub>i</sub> の x 座暙 P<sub>i</sub> の y 座暙である これら n 点の䞭から最も近い点を遞んだずき この点間の距離の乗を出力せよ </p> <!-- <p>  ただし 2≩n≩10<sup>8</sup> か぀ -10000≩x≩10000, -10000≩y≩10000 ずし ぀の入力ファむルのうち぀では n≩100 である たたどの入力ファむルにおいおも党おの座暙は異なるものずする </p> --> <p>  ただし 2&le;n&le;500000 か぀ -10000&le;x&le;10000, -10000&le;y&le;10000 ずし ぀の入力ファむルのうち぀では n&le;100 である たたどの入力ファむルにおいおも党おの座暙は異なるものずする </p> <p> <!-- 入力ファむルの改行コヌドは CR+LF である たた--> 出力ファむルにおいおは 出力の最埌の行にも改行コヌドを入れるこず </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 2 0 0 1 1 </pre> <h3>出力䟋</h3> <pre> 2 </pre> <br> <h3>入力䟋</h3> <pre> 3 5 5 0 0 -3 -4 </pre> <h3>出力䟋</h3> <pre> 25 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02165
<h1>Problem D: Blaster</h1> <h2>Problem</h2> <p> なんず、あなたは掞窟の䞭に閉じ蟌められおしたいたした<br> 壁が厩れたりでもしたのでしょうか、1぀しかない出口にたどり着くたでには沢山の岩が邪魔をしおいたす。<br> <br> しかしなんず、あなたのすぐ隣に爆匟の自動販売機があるこずに気が぀きたした。<br> さらに、掞窟にはいく぀かの「ブラスタヌ」も萜ちおいるようです。<br> この2぀の道具を掻甚すれば、出口たで脱出できそうです。<br> </p> <hr style="border:2px dotted #000000;"> <h4>アむテムの説明</h4> <p> 掞窟内で䜿甚できるアむテムずしお、「爆匟」「ブラスタヌ」の2皮類がありたす。<br> </p> <ul> <li>爆匟は、䜿甚するこずで1マス分の岩を砎壊できるアむテムです。<br> <li>ブラスタヌは、䜿甚するこずで自身の正面䞀盎線にある岩を党お砎壊するこずのできるアむテムです。<br> </ul> <p> 察象ずなる岩を砎壊するず、岩は砕け散り「床」ずなりたす。<br> 爆匟、ブラスタヌは䜿い切りで、各アむテムごずに䜿甚できる回数はそれぞれ1回のみです。<br> たた、ブラスタヌを䜿甚するこずで、他のブラスタヌを砎壊するこずはありたせん。<br> </p> <hr style="border:2px dotted #000000;"> <h4>掞窟のフィヌルド</h4> <p> 偶然手持ちにあったドロヌンを飛ばしお、掞窟の様子を知るこずが出来たした。<br> <br> 掞窟のフィヌルドが䞎えられたす。<br> フィヌルドは以䞋のようなアスキヌアヌトで䞎えらたす。<br> </p> <pre> _### ##B# B##_ </pre> <p> フィヌルドは、䞊䞋に $H$ マス、巊右に $W$ マスの幅を持぀ $H \times W$ のマスからなる長方圢です。<br> $i$ 行 $j$ 列目のマスを $(i,j)$ ず衚したす。 <br> <br> 各マスには、床、壁、ブラスタヌのいずれかがありたす。<br> ブラスタヌのマスには、床の䞊にちょうど1぀のブラスタヌが萜ちおいるこずを瀺したす。<br> なお、フィヌルドの倖偎は爆匟やブラスタヌでも砎壊できない壁で囲たれおいたす。<br> フィヌルドの倖偎に出るこずは出来たせん。<br> </p> <hr style="border:2px dotted #000000;"> <h4>脱出たでの行動</h4> <p> あなたは、以䞋の行動を任意の回数取るこずが出来たす。<br> </p> <ul> <li>隣接するマスの、任意の床ぞ進む。</li> <li>隣接するマスにある任意のブラスタヌを取埗する。取埗埌、ブラスタヌを取埗したマスは床ずなる。</li> <li>隣接するマスにある岩を、爆匟を1぀消費しお砎壊する。</li> <li>珟圚のマスから、䞊䞋巊右奜きな方向を向いお、所持しおいるブラスタヌを1぀䜿甚する。</li> </ul> <p> ここで、マス $(i,j)$ ず $(k,l)$ が隣接するずは、 $|i-k|+|j-l|=1$ であるこずをいいたす。<br> ブラスタヌは十分に軜いため、行動䞭いく぀でも取埗するこずが出来たす。<br> 䜆し、アむテムの説明に蚘茉しおあるずおり、取埗した個数分の回数しかブラスタヌを䜿甚するこずは出来ないので、泚意しおください。<br> <br> 最初、マス $(1,1)$ にいたす。<br> 脱出ずは、マス $(H,W)$ に到達するこずを蚀いたす。<br> </p> <hr style="border:2px dotted #000000;"> <h4>ミッション</h4> <p> あなたは、爆匟の自動販売機から倧量の爆匟を買えば問題なく脱出できるこずに気づきたした。<br> 幞い、爆匟の自動販売機には $10^{100}$ 個の圚庫があり脱出するには十分そうです。<br> しかし、爆匟は非垞に高䟡であるためあたり沢山買いたくありたせん。<br> 手に入れた掞窟の様子から、脱出するには最小でいく぀の爆匟を買う必芁があるか、知りたくなりたした。<br> </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $H$ $W$ $c_{1,1}$$\cdots$$c_{1,W}$ $\vdots$ $c_{H,1}$$\cdots$$c_{H,W}$ </pre> <p> 1行目に $H,W$ が空癜区切りに䞎えられたす。<br> 2行目から、続く $H$ 行にフィヌルドの情報がアスキヌアヌトで䞎えられたす。<br> <br> フィヌルドの情報は、それぞれの文字ごずに以䞋の意味を持ちたす。<br> </p> <ul> <li>$c_{i,j}$ が '#' のずき、 $(i,j)$ に岩があるこずを瀺す。 <li>$c_{i,j}$ が '_' のずき、 $(i,j)$ に床があるこずを瀺す。 <li>$c_{i,j}$ が 'B' のずき、 $(i,j)$ にブラスタヌがちょうど1぀あるこずを瀺す。 </ul> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$2 \leq H,W \leq 1000 $</li> <li>$H,W$ は敎数である</li> <li>$c_{1,1},c_{H,W}$ は、必ず'_'である。</li> </ul> <h2>Output</h2> <p> 1行に脱出に必芁な爆匟の数を出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 8 5 _###_ _#_B# _#### ____# ###_# ##### ###_# ####_ </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <p> この堎合の脱出方法は、 </p> <ul> <li>マス $(3,4)$ にある岩を爆匟で砎壊する</li> <li>マス $(2,4)$ にあるブラスタヌを取埗する</li> <li>マス $(2,4)$ で䞋方向にブラスタヌを䜿甚する</li> <li>脱出 </ul> <p> このように、爆匟 $1$ ぀で脱出するこずが出来たす。<br> なお、ブラスタヌを䜿甚した盎埌のフィヌルドは、以䞋のようになっおいたす。<br> </p> <pre> _###_ _#__# _##_# ____# ###_# ###_# ###_# ###__ </pre> <h2>Sample Input 2</h2> <pre> 5 5 _____ _____ _____ _____ _____ </pre> <h2>Sample Output 2</h2> <pre> 0 </pre> <p> 邪魔する岩もブラスタヌもありたせん。目の錯芚だったのでしょうか。<br> 爆匟を䞀぀も買うこずなく、脱出できる堎合もありたす。<br> </p> <h2>Sample Input 3</h2> <pre> 4 5 _#### ##B## _#### _###_ </pre> <h2>Sample Output 3</h2> <pre> 2 </pre> <p>マス $(2,1),(2,2)$ にある岩を砎壊すれば、爆匟 $2$ ぀だけで脱出可胜です。</p> <h2>Sample Input 4</h2> <pre> 4 5 _#B## ##### ##B## ####_ </pre> <h2>Sample Output 4</h2> <pre> 1 </pre>
p00158
<H1>コラッツの予想</H1> <p> 正の敎数 <var>n</var> に察し、 </p> <ul> <li><var>n</var> が偶数の時は 2 で割る。</li> <li><var>n</var> が奇数の時は 3 倍し、1 を足す。</li> </ul> <p> ずいう操䜜を繰り返すず結果が 1 になりたす。任意の正の敎数 <var>n</var> に察しおこの操䜜を繰り返すず必ず 1 になるであろうずいうのが「コラッツの予想」ず呌ばれる問題です。この問題は日本では、「角谷の問題」ずしおも知られおいる未解決の問題です。コンピュヌタを利甚しお非垞に倧きな数 3 &times; 2<sup>53</sup> = 27,021,597,764,222,976 以䞋に぀いおは反䟋がないこずが知られおいたすが、数孊的には蚌明されおいたせん。 </p> <p> 敎数 <var>n</var> を入力ずし、結果が 1 になるたでに繰り返される操䜜の回数を出力するプログラムを䜜成しおください。敎数 <var>n</var> は 1 以䞊でか぀䞊蚘の蚈算を繰り返す途䞭の倀が 1000000 以䞋ずなる皋床の敎数ずしたす。たずえば、入力ずしお 3 を受け取った堎合は、操䜜列は </p> <pre> 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1 </pre> <p> になるので、操䜜の回数䞊の矢印の個数である 7 を出力したす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットずしお぀の敎数 <var>n</var> (<var>n</var> &le; 1000000) が行に䞎えられたす。 </p> <p> デヌタセットの数は 50 を越えない。 </p> <H2>Output</H2> <p> デヌタセットごずに操䜜の回数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 3 10 0 </pre> <H2>Output for the Sample Input</H2> <pre> 7 6 </pre>
p02470
<H1>Euler's Phi Function</H1> <br/> <p> For given integer <var>n</var>, count the totatives of <var>n</var>, that is, the positive integers less than or equal to <var>n</var> that are relatively prime to <var>n</var>. </p> <H2>Input</H2> <pre> <var>n</var> </pre> <p> An integer <var>n</var> (1 &le; <var>n</var> &le; 1000000000). </p> <H2>Output</H2> <p> The number of totatives in a line. </p> <H2>Sample Input 1</H2> <pre> 6 </pre> <H2>Sample Output 1</H2> <pre> 2 </pre> <br/> <H2>Sample Input 2</H2> <pre> 1000000 </pre> <H2>Sample Output 2</H2> <pre> 400000 </pre> <br/>
p02020
<h2>F: 茶䌚 (Tea Party)</h2> <p>ゆんさんは、䌚瀟でお茶䌚を開くこずにした。</p> <p>お店には $N$ セットのパンが売られおいお、それぞれ $A_1, A_2, A_3, \dots, A_N$ 枚入っおいる。</p> <p>ゆんさんは二぀のパンを 1 組にしおをサンドりィッチを䜜ろうず考えた。</p> <p>ゆんさんは几垳面なので、買ったパンが䞀枚も䜙らないようにしたい。</p> <p>最倧でいく぀のサンドりィッチが䜜れるか蚈算せよ。</p> <h3>入力</h3> <p>1 行目には、敎数 $N$ が䞎えられる。</p> <p>2 行目には、$N$ 個の敎数 $A_1, A_2, A_3, \dots, A_N$ が空癜区切りで䞎えられる。</p> <h3>出力</h3> <p>䜜れるサンドりィッチの最倧の個数を出力せよ。ただし、最埌に改行を入れるこず。</p> <h3>制玄</h3> <ul> <li>$N$ は $1$ 以䞊 $100$ 以䞋の敎数</li> <li>$A_1, A_2, A_3, \dots, A_N$ は $1$ 以䞊 $100$ 以䞋の敎数</li> </ul> <h3>入力䟋1</h3> <pre> 5 2 3 5 6 7 </pre> <h3>出力䟋1</h3> <pre> 10 </pre> <p>1, 3, 4, 5 番目のセットを買うず、パンが $20$ 枚手に入りたす。</p> <p>すべおのセットを買っおしたうずパンが $23$ 枚になっお、䜙っおしたいたす。</p> <h3>入力䟋2</h3> <pre> 4 3 5 6 8 </pre> <h3>出力䟋2</h3> <pre> 11 </pre>
p02889
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> towns numbered <var>1</var> to <var>N</var> and <var>M</var> roads. The <var>i</var>-th road connects Town <var>A_i</var> and Town <var>B_i</var> bidirectionally and has a length of <var>C_i</var>.</p> <p>Takahashi will travel between these towns by car, passing through these roads. The fuel tank of his car can contain at most <var>L</var> liters of fuel, and one liter of fuel is consumed for each unit distance traveled. When visiting a town while traveling, he can full the tank (or choose not to do so). Travel that results in the tank becoming empty halfway on the road cannot be done.</p> <p>Process the following <var>Q</var> queries:</p> <ul> <li>The tank is now full. Find the minimum number of times he needs to full his tank while traveling from Town <var>s_i</var> to Town <var>t_i</var>. If Town <var>t_i</var> is unreachable, print <var>-1</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>2 \leq N \leq 300</var></li> <li><var>0 \leq M \leq \frac{N(N-1)}{2}</var></li> <li><var>1 \leq L \leq 10^9</var></li> <li><var>1 \leq A_i, B_i \leq N</var></li> <li><var>A_i \neq B_i</var></li> <li><var>\left(A_i, B_i\right) \neq \left(A_j, B_j\right)</var> (if <var>i \neq j</var>)</li> <li><var>\left(A_i, B_i\right) \neq \left(B_j, A_j\right)</var> (if <var>i \neq j</var>)</li> <li><var>1 \leq C_i \leq 10^9</var></li> <li><var>1 \leq Q \leq N\left(N-1\right)</var></li> <li><var>1 \leq s_i, t_i \leq N</var></li> <li><var>s_i \neq t_i</var></li> <li><var>\left(s_i, t_i\right) \neq \left(s_j, t_j\right)</var> (if <var>i \neq j</var>)</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>L</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>:</var> <var>A_M</var> <var>B_M</var> <var>C_M</var> <var>Q</var> <var>s_1</var> <var>t_1</var> <var>:</var> <var>s_Q</var> <var>t_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines.</p> <p>The <var>i</var>-th line should contain the minimum number of times the tank needs to be fulled while traveling from Town <var>s_i</var> to Town <var>t_i</var>. If Town <var>t_i</var> is unreachable, the line should contain <var>-1</var> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 5 1 2 3 2 3 3 2 3 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 1 </pre> <p>To travel from Town <var>3</var> to Town <var>2</var>, we can use the second road to reach Town <var>2</var> without fueling the tank on the way.</p> <p>To travel from Town <var>1</var> to Town <var>3</var>, we can first use the first road to get to Town <var>2</var>, full the tank, and use the second road to reach Town <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 0 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>There may be no road at all.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 4 4 1 2 2 2 3 2 3 4 3 4 5 2 20 2 1 3 1 4 1 5 1 1 2 3 2 4 2 5 2 1 3 2 3 4 3 5 3 1 4 2 4 3 4 5 4 1 5 2 5 3 5 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 0 1 2 0 0 1 2 0 0 0 1 1 1 0 0 2 2 1 0 </pre></section> </div> </span>
p03261
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is practicing <em>shiritori</em> alone again today.</p> <p>Shiritori is a game as follows:</p> <ul> <li>In the first turn, a player announces any one word.</li> <li>In the subsequent turns, a player announces a word that satisfies the following conditions:<ul> <li>That word is not announced before.</li> <li>The first character of that word is the same as the last character of the last word announced.</li> </ul> </li> </ul> <p>In this game, he is practicing to announce as many words as possible in ten seconds.</p> <p>You are given the number of words Takahashi announced, <var>N</var>, and the <var>i</var>-th word he announced, <var>W_i</var>, for each <var>i</var>. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an integer satisfying <var>2 \leq N \leq 100</var>.</li> <li><var>W_i</var> is a string of length between <var>1</var> and <var>10</var> (inclusive) consisting of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>W_1</var> <var>W_2</var> <var>:</var> <var>W_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If every word announced by Takahashi satisfied the conditions, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 hoge english hoge enigma </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>No </pre> <p>As <code>hoge</code> is announced multiple times, the rules of shiritori was not observed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 basic c cpp php python nadesico ocaml lua assembly </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 a aa aaa aaaa aaaaa aaaaaa aaa aaaaaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 abc arc agc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre></section> </div> </span>
p02923
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> squares arranged in a row from left to right.</p> <p>The height of the <var>i</var>-th square from the left is <var>H_i</var>.</p> <p>You will land on a square of your choice, then repeat moving to the adjacent square <strong>on the right</strong> as long as the height of the next square is not greater than that of the current square.</p> <p>Find the maximum number of times you can move.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq H_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of times you can move.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 10 4 8 7 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>By landing on the third square from the left, you can move to the right twice.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 4 4 5 6 6 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>By landing on the fourth square from the left, you can move to the right three times.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p03631
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a three-digit positive integer <var>N</var>.<br/> Determine whether <var>N</var> is a <em>palindromic number</em>.<br/> Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>100≀N≀999</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format: </p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>N</var> is a palindromic number, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>575 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p><var>N=575</var> is also <var>575</var> when read backward, so it is a palindromic number. You should print <code>Yes</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>123 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p><var>N=123</var> becomes <var>321</var> when read backward, so it is not a palindromic number. You should print <code>No</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>812 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre></section> </div> </span>
p00334
<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> コンピュヌタグラフィクスでは、䞉次元の圢状を衚珟する方法ずしお、ポリゎンモデルが䜿われたす。ポリゎンモデルずは、頂点座暙ず、それらの頂点の぀なぎ方を䞎えお面を䜜るモデルです。 </p> <p> 䞀般のポリゎンモデルでは、任意の倚角圢を扱えたすが、今回は䞉角圢からなるポリゎンモデルを考えるこずにしたす。任意のポリゎンモデルは䞉角圢を衚す面情報の集たりずしお衚すこずができたす。 </p> <p> 䞀぀の面情報は、぀の頂点を䞊べお衚したす。ただし、䞊び方が異なるだけで同じ点からなる堎合は、同じ面情報を衚すこずにしたす。䟋えば、䞋図の四面䜓で、頂点,,を繋いでできる面は、頂点,,や、頂点,,などのように衚すこずもできたす。このように、同じ面情報が耇数あるず無駄になるので、぀にたずめおしたった方が良いでしょう。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_shape_data" width="280"> </center> <br/> <p> 面情報が䞎えられたずき、重耇した面を無くすために消さなければならない面情報の個数を求めるプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>p<sub>11</sub></var> <var>p<sub>12</sub></var> <var>p<sub>13</sub></var> <var>p<sub>21</sub></var> <var>p<sub>22</sub></var> <var>p<sub>23</sub></var> : <var>p<sub>N1</sub></var> <var>p<sub>N2</sub></var> <var>p<sub>N3</sub></var> </pre> <p> 行目に、ポリゎンモデルの面情報の数 <var>N</var> (1 &le; <var>N</var> &le; 1000) が䞎えられる。続く <var>N</var> 行に、<var>i</var> 番目の面を䜜るために䜿う頂点の番号 <var>p<sub>ij</sub></var> (1 &le; <var>p<sub>ij</sub></var> &le; 1000) が䞎えられる。ただし、䞀぀の面に぀いお、同じ頂点を床以䞊䜿うこずはない<var>p<sub>i1</sub></var> &ne; <var>p<sub>i2</sub></var> か぀ <var>p<sub>i2</sub></var> &ne; <var>p<sub>i3</sub></var> か぀ <var>p<sub>i1</sub></var> &ne; <var>p<sub>i3</sub></var> である。 </p> <h2>Output</h2> <p> 重耇した面を無くすために消さなければならない面情報の個数を行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 4 1 3 2 1 2 4 1 4 3 2 3 4 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <br/> <h2>Sample Input 2</h2> <pre> 6 1 3 2 1 2 4 1 4 3 2 3 4 3 2 1 2 3 1 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> <p> 入出力䟋では、぀目ず぀目ず぀目の面は頂点1, 3, 2を䜿っお䞉角圢を䜜っおいお、点の順番が異なるだけなので重耇しおいる。぀たり、重耇した面のうち぀の面を消せば重耇した面は無くなる。 </p>
p02309
<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>Cross Points of Circles</H1> <p> For given two circles $c1$ and $c2$, print the coordinates of the cross points of them. </p> <H2>Input</H2> <p> The input is given in the following format. </p> <p> $c1x\; c1y\; c1r$ <br> $c2x\; c2y\; c2r$ <br> </p> <p> $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers. </p> <H2>Output</H2> <p> Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. </p> <ul> <li>If there is one cross point, print two coordinates with the same values.</li> <li>Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first.</li> </ul> <p> The output values should be in a decimal fraction with an error less than 0.000001. </p> <H2>Constraints</H2> <ul> <li>The given circle have at least one cross point and have different center coordinates.</li> <li>$-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$</li> <li>$1 \leq c1r, c2r \leq 10,000$</li> </ul> <H2>Sample Input and Output</H2> <br> <H2>Sample Input 1</H2> <pre> 0 0 2 2 0 2 </pre> <H2>Sample Output 1</H2> <pre> 1.00000000 -1.73205080 1.00000000 1.73205080 </pre> <br> <H2>Sample Input 2</H2> <pre> 0 0 2 0 3 1 </pre> <H2>Sample Output 2</H2> <pre> 0.00000000 2.00000000 0.00000000 2.00000000 </pre>
p00764
<h1>Chain-Confined Path</h1> <!-- end en only --> <!-- begin en only --> <p> There is a chain consisting of multiple circles on a plane. The first (last) circle of the chain only intersects with the next (previous) circle, and each intermediate circle intersects only with the two neighboring circles. </p> <!-- end en only --> <!-- begin en only --> <p> Your task is to find the shortest path that satisfies the following conditions. <ul> <li>The path connects the centers of the first circle and the last circle.</li> <li>The path is confined in the chain, that is, all the points on the path are located within or on at least one of the circles.</li> </ul> Figure E-1 shows an example of such a chain and the corresponding shortest path. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1183_1"><br><br> <!-- begin en only --> Figure E-1: An example chain and the corresponding shortest path<br> <!-- end en only --> </center> <h3>Input</h3> <!-- begin en only --> <p> The input consists of multiple datasets. Each dataset represents the shape of a chain in the following format. </p> <!-- end en only --> <blockquote> <i>n</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>r</i><sub>1</sub> <br> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>r</i><sub>2</sub> <br> ...<br> <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>r</i><sub><i>n</i></sub> <br> </blockquote> <!-- begin en only --> <p> The first line of a dataset contains an integer <i>n</i> (3 &le; <i>n</i> &le; 100) representing the number of the circles. Each of the following <i>n</i> lines contains three integers separated by a single space. (<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>) and <i>r</i><sub><i>i</i></sub> represent the center position and the radius of the <i>i</i>-th circle <i>C</i><sub><i>i</i></sub>. You can assume that 0 &le; <i>x</i><sub><i>i</i></sub> &le; 1000, 0 &le; <i>y</i><sub><i>i</i></sub> &le; 1000, and 1 &le; <i>r</i><sub><i>i</i></sub> &le; 25. </p> <!-- end en only --> <!-- begin en only --> <p> You can assume that <i>C</i><sub><i>i</i></sub> and <i>C</i><sub><i>i</i>+1</sub> (1 &le; <i>i</i> &le; <i>n</i>&minus;1) intersect at two separate points. When <i>j</i> &ge; <i>i</i>+2, <i>C</i><sub><i>i</i></sub> and <i>C</i><sub><i>j</i></sub> are apart and either of them does not contain the other. In addition, you can assume that any circle does not contain the center of any other circle. </p> <p> The end of the input is indicated by a line containing a zero. </p> <!-- end en only --> <!-- begin en only --> <p> Figure E-1 corresponds to the first dataset of Sample Input below. Figure E-2 shows the shortest paths for the subsequent datasets of Sample Input. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1183_2"><br><br> <!-- begin en only --> Figure E-2: Example chains and the corresponding shortest paths<br> <!-- end en only --> </center> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing the length of the shortest chain-confined path between the centers of the first circle and the last circle. The value should not have an error greater than 0.001. No extra characters should appear in the output. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 10 802 0 10 814 0 4 820 1 4 826 1 4 832 3 5 838 5 5 845 7 3 849 10 3 853 14 4 857 18 3 3 0 0 5 8 0 5 8 8 5 3 0 0 5 7 3 6 16 0 5 9 0 3 5 8 0 8 19 2 8 23 14 6 23 21 6 23 28 6 19 40 8 8 42 8 0 39 5 11 0 0 5 8 0 5 18 8 10 8 16 5 0 16 5 0 24 5 3 32 5 10 32 5 17 28 8 27 25 3 30 18 5 0 </pre> <h3>Output for the Sample Input</h3> <pre> 58.953437 11.414214 16.0 61.874812 63.195179 </pre>
p02759
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi wants to print a document with <var>N</var> pages double-sided, where two pages of data can be printed on one sheet of paper.</p> <p>At least how many sheets of paper does he need?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an integer.</li> <li><var>1 \leq N \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>By printing the <var>1</var>-st, <var>2</var>-nd pages on the <var>1</var>-st sheet, <var>3</var>-rd and <var>4</var>-th pages on the <var>2</var>-nd sheet, and <var>5</var>-th page on the <var>3</var>-rd sheet, we can print all the data on <var>3</var> sheets of paper.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>50 </pre></section> </div> </span>
p01876
<h2>E: Arai's - Arai's -</h2> <h3>問題</h3> <p>スクヌルアむドル時代から、囜民的人気を誇っおきた女性アむドルグルヌプArai's。今では、たくさんの「あらい」さんが所属する倧芏暡なグルヌプずしお、䞖界レベルで掻躍しおいる。そしお今日、新たなるプロゞェクトの始動が決定した。圌女たちは、小さなナニットをいく぀か結成するこずで、さらなる売䞊の向䞊を詊みるこずになったのである。</p> <p>Arai'sには「荒井」さんが<var>A</var>人「新井」さんが<var>B</var>人圚籍しおおり、合蚈で<var>A+B</var>人の「あらい」さんからなる。新ナニットは、「荒井」さん䞀人ず「新井」さん䞀人のペアで構成する。ここで、同じ「あらい」さんが耇数のナニットに所属しおいはいけない。ただし、ある「荒井」さんが䞀郚の「新井」さんのこずを良く思っおいないうえに、同様にある「新井」さんが䞀郚の「荒井」さんのこずを良く思っおいない。「あらい」さんたちはナニットを組む際に、良く思っおいない「あらい」さんをペアずしお認めおくれず、䞀方でも認めおくれなければナニットを組むこずはできない。</p> <p>Arai'sのマネヌゞャヌであるあなたは、なるべくたくさんのナニットを䜜りたいず考えおいるが、メンバヌの亀友関係からその限界を感じおいた。そこであなたは、「あらい」さんたちず個別に面談し、ナニットを組たせたい「あらい」さんに぀いおの、良い噂を聞かせるこずを考えた。面談をした「あらい」さんは、噂に聞いた「あらい」さんを芋盎し、ナニットのペアずしお認めるようになる。</p> <p>しかし、あなたはそれほど時間をずるこずができないため、最倧<var>K</var>回たでしか噂を聞かせるこずができない。あなたは限られた時間の䞭で、結成できるナニットの数を最倧化しようず詊みた。あなたが結成できるナニットの数の最倧倀を求めよ。</p> <h3>入力圢匏</h3> <pre> <var>A</var> <var>B</var> <var>K</var> <var>a_1</var> ... <var>a_A</var> <var>b_1</var> ... <var>b_B</var> </pre> <p>1行目には、「荒井」さんの人数<var>A</var>ず「新井」さんの人数<var>B</var> (<var>1 \&le; A, B \&le; 200</var>であり<var>A</var>, <var>B</var>は敎数)、噂を聞かせるこずができる人数<var>K</var> (<var>0 \&le; K \&le; 200</var>であり<var>K</var>は敎数)が空癜区切りで䞎えられる。</p> <p>続く<var>A</var>行には、それぞれ長さ<var>B</var>の<var>0</var>ず<var>1</var>のみからなる文字列が䞎えられる。そのうち<var>i</var>行目の文字列<var>a_i</var>の<var>j</var>文字目が<var>1</var>であるずき、<var>i</var>番目の「荒井」さんは<var>j</var>番目の「新井」さんを良く思っおいない。</p> <p>続く<var>B</var>行には、それぞれ長さ<var>A</var>の<var>0</var>ず<var>1</var>のみからなる文字列が䞎えられる。そのうち<var>i</var>行目の文字列<var>b_i</var>の<var>j</var>文字目が<var>1</var>であるずき、<var>i</var>番目の「新井」さんは<var>j</var>番目の「荒井」さんを良く思っおいない。</p> <h3>出力圢匏</h3> <p>あなたが結成できるナニット数の最倧倀を1行に出力せよ。</p> <h3>入力䟋1</h3> <pre> 3 3 4 111 111 111 111 111 111 </pre> <h3>出力䟋1</h3> <pre>2</pre> <h3>入力䟋2</h3> <pre> 3 3 2 101 100 010 001 011 111 </pre> <h3>出力䟋2</h3> <pre>3</pre> <h3>入力䟋3</h3> <pre> 5 6 3 101101 110110 010111 110110 110111 01010 10101 11101 01011 11011 11011 </pre> <h3>出力䟋3</h3> <pre>4</pre>
p03518
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has a sequence <var>p</var>, which is a permutation of <var>(0,1,2, ...,N-1)</var>. The <var>i</var>-th element (<var>0</var>-indexed) in <var>p</var> is <var>p_i</var>.</p> <p>He can perform <var>N-1</var> kinds of operations labeled <var>1,2,...,N-1</var> any number of times in any order. When the operation labeled <var>k</var> is executed, the procedure represented by the following code will be performed:</p> <pre>for(int i=k;i&lt;N;i++) swap(p[i],p[i-k]); </pre> <p>He would like to sort <var>p</var> in increasing order using between <var>0</var> and <var>10^{5}</var> operations (inclusive). Show one such sequence of operations. It can be proved that there always exists such a sequence of operations under the constraints in this problem.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200</var></li> <li><var>0 \leq p_i \leq N-1</var></li> <li><var>p</var> is a permutation of <var>(0,1,2,...,N-1)</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li>In the test set worth <var>300</var> points, <var>N \leq 7</var>.</li> <li>In the test set worth another <var>400</var> points, <var>N \leq 30</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>p_0</var> <var>p_1</var> <var>...</var> <var>p_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Let <var>m</var> be the number of operations in your solution. In the first line, print <var>m</var>. In the <var>i</var>-th of the following <var>m</var> lines, print the label of the <var>i</var>-th executed operation. The solution will be accepted if <var>m</var> is at most <var>10^5</var> and <var>p</var> is in increasing order after the execution of the <var>m</var> operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 2 0 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 2 3 1 2 </pre> <ul> <li>Each operation changes <var>p</var> as shown below:</li> </ul> <div style="text-align: center;"> <img alt="9f3b51eb1fe742848f407bdeb7b772e1.png" src="https://atcoder.jp/img/asaporo2/9f3b51eb1fe742848f407bdeb7b772e1.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 1 0 4 3 5 6 2 8 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>11 3 6 1 3 5 2 4 7 8 6 3 </pre></section> </div> </span>
p01525
<h1>F - Acceleration of Network</h1> <p> むンタヌネットず蚀う広倧な海は少しず぀黒く塗り぀ぶされおいった。<br> ボットの反乱、DDOS攻撃の嵐、りィルスの蔓延、<br> 䜕床も䜕床も繰り返されたクラッカヌずの戊争で、人もむンタヌネットもボロボロになった。<br> <br> 人の手では、むンタヌネットはどうにもならない。<br> だから人は、ずんでもない時間をかけお<br> むンタヌネットを埩旧できる「少女」を造った。<br> <br> 少女は、むンタヌネットの手圓をはじめた。<br> 果おしなく広いむンタヌネットの䞖界をどうにかしようず頑匵った。<br> <br> ただ少女ひずりでは撚り察線を織る事くらいしかできないけど、<br> 長い長い時がすぎおむンタヌネットが少し埩旧すれば、<br> みんなず䞀緒に頑匵れるだろうずいう期埅をこめお。 </p> <h2>問題文</h2> <p> 少女はか぀おむンタヌネットに存圚した <var>N</var> 個のサヌビスを埩旧するために日々頑匵っおいる 珟圚を 0 日目ずする むンタヌネットがどの皋床埩旧しおいるかを<i>埩旧床</i>ずいう指暙で衚し珟圚の埩旧床は 0 であるずする 少女は毎日䜜業をし埩旧床を 1 日に぀き 1 ず぀䞊げおいく 任意のただ埩旧しおいないサヌビス <var>i</var> は埩旧床が <var>w<sub>i</sub></var> 以䞊になるず自動的に埩旧する サヌビス <var>i</var> が埩旧するずみんなが手䌝っおくれるこずにより埩旧した次の日から <var>x<sub>i</sub></var> 日間だけ䜜業がはかどり埩旧床の増加が加速する サヌビスには 3 ぀の皮類があり皮類によっお埩旧床がどの皋床増加するのかが異なる サヌビスの皮類を <var>0, 1, 2</var> の番号で衚すずする サヌビス <var>i</var> の皮類を t<sub>i</sub> (&isin; {0, 1, 2}) ずするず サヌビス <var>i</var> が埩旧しおから <var>d-1</var> 日目から <var>d</var> 日目にかけお <var>(1 &le; d &le; x<sub>i</sub>)</var> <var>t<sub>i</sub>=0</var> の堎合は <var>1</var> <var>t<sub>i</sub>=1</var> の堎合は <var>d</var> そしお <var>t<sub>i</sub>=2</var> の堎合は <var>d<sup>2</sup></var> だけ少女の䜜業ずは別に埩旧床が増加する たた同時に耇数のサヌビスが埩旧しおいる堎合それぞれのサヌビスは独立に䞊行しお埩旧床を増加させる </p> <p> 少女はサヌビスが埩旧するたでにずんでもない時間がかかるず思ったので珟圚から䜕日目にサヌビスが埩旧するか調べるこずにした たたある日にち <var>y<sub>j</sub></var> に埩旧床がいくらになっおいるかも気になったのでそれも <var>Q</var> 日分だけ調べるこずにした </p> <h2>入力圢匏</h2> <p>入力は以䞋の圢匏で䞎えられる</p> <pre> <var>N</var> <var>Q</var> <var>w<sub>1</sub></var> <var>t<sub>1</sub></var> <var>x<sub>1</sub></var> <var>...</var> <var>w<sub>N</sub></var> <var>t<sub>N</sub></var> <var>x<sub>N</sub></var> <var>y<sub>1</sub></var> <var>...</var> <var>y<sub>Q</sub></var> </pre> <h2>出力圢匏</h2> <p> 最初に <var>N</var> 行出力し<var>i</var> 行目にはサヌビス <var>i</var> の埩旧する日にちを出力せよ次に <var>Q</var> 行出力し<var>j</var> 行目には <var>y<sub>j</sub></var> 日目に埩旧床がいくらになっおいるかを出力せよ サヌビスが埩旧する日にちが <var>3,652,425</var> を超える堎合は<code>Many years later</code>ず出力せよ </p> <h2>制玄</h2> <ul> <li><var>0 &le; N &le; 10<sup>5</sup></var></li> <li><var>1 &le; Q &le; 10<sup>5</sup></var></li> <li><var>0 &le; w<sub>i</sub> &lt; 2<sup>60</sup></var></li> <li><var>w<sub>i</sub> &le; w<sub>i+1</sub> (1 &le; i &lt; N)</var></li> <li><var>t<sub>i</sub> &isin; {0, 1, 2}</var></li> <li><var>1 &le; x<sub>i</sub> &le; 10<sup>4</sup></var></li> <li><var>0 &le; y<sub>j</sub> &le; 3,652,425</var></li> <li><var>y<sub>j</sub> &lt; y<sub>j+1</sub> (1 &le; j &lt; Q)</var></li> <li>入力倀はすべお敎数である</li> </ul> <p> この問題の刀定には15 点分のテストケヌスのグルヌプが蚭定されおいるこのグルヌプに含たれるテストケヌスは䞊蚘の制玄に加えお䞋蚘の制玄も満たす </p> <ul> <li><var>N,Q,w<sub>i</sub>,y<sub>j</sub> &le; 1,000</var></li> </ul> <h3>泚意</h3> <ul> <li>0 日目の埩旧床は 0 である</li> <li><var>w<sub>i</sub>=0</var> の時サヌビス <var>i</var> は 0 日目に埩旧する</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 3 11 1 0 2 4 1 3 7 2 4 0 1 2 3 4 5 6 7 8 9 10 </pre> <h3>出力䟋1</h3> <pre> 1 3 4 0 1 3 5 7 11 19 29 46 47 48 </pre> <h3>入力䟋2</h3> <pre> 5 5 10000 0 20 10000 1 30 10000 0 40 10000 2 70 30000 2 10000 5000 10000 15000 20000 25000 </pre> <h3>出力䟋2</h3> <pre> 10000 10000 10000 10000 10039 5000 10000 40711690801 329498273301 333383477320 </pre> <h3>入力䟋3</h3> <pre> 2 2 3652425 0 1 3652426 2 10000 3652424 3652425 </pre> <h3>出力䟋3</h3> <pre> 3652425 Many years later 3652424 3652425 </pre> <p>2぀目のサヌビスは埩旧する日にちが <var>3,652,425</var> 日を超えおいるので<code>Many years later</code>ず出力しおいる</p> <hr> <address>Writer : 森槙悟</address> <address>Tester : 田村和範</address>
p03148
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> pieces of sushi. Each piece has two parameters: "kind of topping" <var>t_i</var> and "deliciousness" <var>d_i</var>. You are choosing <var>K</var> among these <var>N</var> pieces to eat. Your "satisfaction" here will be calculated as follows:</p> <ul> <li>The satisfaction is the sum of the "base total deliciousness" and the "variety bonus".</li> <li>The base total deliciousness is the sum of the deliciousness of the pieces you eat.</li> <li>The variety bonus is <var>x*x</var>, where <var>x</var> is the number of different kinds of toppings of the pieces you eat.</li> </ul> <p>You want to have as much satisfaction as possible. Find this maximum satisfaction.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq N \leq 10^5</var></li> <li><var>1 \leq t_i \leq N</var></li> <li><var>1 \leq d_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>t_1</var> <var>d_1</var> <var>t_2</var> <var>d_2</var> <var>.</var> <var>.</var> <var>.</var> <var>t_N</var> <var>d_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum satisfaction that you can obtain.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 1 9 1 7 2 6 2 5 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>If you eat Sushi <var>1,2</var> and <var>3</var>:</p> <ul> <li>The base total deliciousness is <var>9+7+6=22</var>.</li> <li>The variety bonus is <var>2*2=4</var>.</li> </ul> <p>Thus, your satisfaction will be <var>26</var>, which is optimal.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 4 1 1 2 1 3 1 4 6 4 5 4 5 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>25 </pre> <p>It is optimal to eat Sushi <var>1,2,3</var> and <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 5 5 1000000000 2 990000000 3 980000000 6 970000000 6 960000000 4 950000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4900000016 </pre> <p>Note that the output may not fit into a <var>32</var>-bit integer type.</p></section> </div> </span>
p01175
<H1><font color="#000">Problem E:</font> Optimal Rest</H1> <p> Music Macro Language (MML) is a language for textual representation of musical scores. Although there are various dialects of MML, all of them provide a set of commands to describe scores, such as commands for notes, rests, octaves, volumes, and so forth. </p> <p> In this problem, we focus on rests, i.e. intervals of silence. Each rest command consists of a command specifier ‘R’ followed by a duration specifier. Each duration specifier is basically one of the following numbers: ‘1’, ‘2’, ‘4’, ‘8’, ‘16’, ‘32’, and ‘64’, where ‘1’ denotes a whole (1), ‘2’ a half (1/2), ‘4’ a quarter (1/4), ‘8’ an eighth (1/8), and so on. This number is called the base duration, and optionally followed by one or more dots. The first dot adds the duration by the half of the base duration. For example, ‘4.’ denotes the duration of ‘4’ (a quarter) plus ‘8’ (an eighth, i.e. the half of a quarter), or simply 1.5 times as long as ‘4’. In other words, ‘R4.’ is equivalent to ‘R4R8’. In case with two or more dots, each extra dot extends the duration by the half of the previous one. Thus ‘4..’ denotes the duration of ‘4’ plus ‘8’ plus ‘16’, ‘4...’ denotes the duration of ‘4’ plus ‘8’ plus ‘16’ plus ‘32’, and so on. The duration extended by dots cannot be shorter than ‘64’. For exapmle, neither ‘64.’ nor ‘16...’ will be accepted since both of the last dots indicate the half of ‘64’ (i.e. the duration of 1/128). </p> <p> In this problem, you are required to write a program that finds the shortest expressions equivalent to given sequences of rest commands. </p> <H2>Input</H2> <p> The input consists of multiple datasets. The first line of the input contains the number of datasets <i>N</i>. Then, <i>N</i> datasets follow, each containing a sequence of valid rest commands in one line. You may assume that no sequence contains more than 100,000 characters. </p> <H2>Output</H2> <p> For each dataset, your program should output the shortest expression in one line. If there are multiple expressions of the shortest length, output the lexicographically smallest one. </p> <H2>Sample Input</H2> <pre> 3 R2R2 R1R2R4R8R16R32R64 R1R4R16 </pre> <H2>Output for the Sample Input</H2> <pre> R1 R1...... R16R1R4 </pre>
p01460
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Matrix Operation</H1> <p> You are a student looking for a job. Today you had an employment examination for an IT company. They asked you to write an efficient program to perform several operations. First, they showed you an <var>N \times N</var> square matrix and a list of operations. All operations but one modify the matrix, and the last operation outputs the character in a specified cell. Please remember that you need to output the final matrix after you finish all the operations. </p> <p> Followings are the detail of the operations: </p> <dl> <dt> WR r c v </dt><dd> (Write operation) write a integer v into the cell (r,c) (<var>1 \leq v \leq 1,000,000</var>)</dd> <dt> CP r1 c1 r2 c2 </dt><dd> (Copy operation) copy a character in the cell (r1,c1) into the cell (r2,c2)</dd> <dt> SR r1 r2 </dt><dd> (Swap Row operation) swap the r1-th row and r2-th row</dd> <dt> SC c1 c2 </dt><dd> (Swap Column operation) swap the c1-th column and c2-th column</dd> <dt> RL </dt><dd> (Rotate Left operation) rotate the whole matrix in counter-clockwise direction by 90 degrees</dd> <dt> RR </dt><dd> (Rotate Right operation) rotate the whole matrix in clockwise direction by 90 degrees</dd> <dt> RH </dt><dd> (Reflect Horizontal operation) reverse the order of the rows</dd> <dt> RV </dt><dd> (Reflect Vertical operation) reverse the order of the columns</dd> </dl> <p> </p> <H2>Input</H2> <p> First line of each testcase contains nine integers. First two integers in the line, N and Q, indicate the size of matrix and the number of queries, respectively <var>(1 \leq N,Q \leq 40,000)</var>. Next three integers, A B, and C, are coefficients to calculate values in initial matrix <var>(1 \leq A,B,C \leq 1,000,000)</var>, and they are used as follows: <var>A_{r,c} = (r * A + c * B) mod C</var> where r and c are row and column indices, respectively <var>(1\leq r,c\leq N)</var>. Last four integers, D, E, F, and G, are coefficients to compute the final hash value mentioned in the next section <var>(1 \leq D \leq E \leq N, 1 \leq F \leq G \leq N, E - D \leq 1,000, G - F \leq 1,000)</var>. Each of next Q lines contains one operation in the format as described above. </p> <H2>Output</H2> <p> Output a hash value h computed from the final matrix B by using following pseudo source code. </p> <pre> h &lt;- 314159265 for r = D...E for c = F...G h &lt;- (31 * h + B_{r,c}) mod 1,000,000,007 </pre> <p> where &quot;&lt;-&quot; is a destructive assignment operator, &quot;for i = S...T&quot; indicates a loop for i from S to T (both inclusive), and &quot;mod&quot; is a remainder operation. </p> <H2>Sample Input 1</H2> <pre> 2 1 3 6 12 1 2 1 2 WR 1 1 1 </pre> <H2>Output for the Sample Input 1</H2> <pre> 676573821 </pre> <H2>Sample Input 2</H2> <pre> 2 1 3 6 12 1 2 1 2 RL </pre> <H2>Output for the Sample Input 2</H2> <pre> 676636559 </pre> <H2>Sample Input 3</H2> <pre> 2 1 3 6 12 1 2 1 2 RH </pre> <H2>Output for the Sample Input 3</H2> <pre> 676547189 </pre> <H2>Sample Input 4</H2> <pre> 39989 6 999983 999979 999961 1 1000 1 1000 SR 1 39989 SC 1 39989 RL RH RR RV </pre> <H2>Output for the Sample Input 4</H2> <pre> 458797120 </pre>
p01030
<h1>Problem C: Changing Grids</h1> <h2>Background</h2> <p> A君ずB君は、『Changing Grids』ずいうゲヌムに熱䞭しおいる。このゲヌムは2人甚で、プレむダヌ1がステヌゞを構成し、プレむダヌ2がそのステヌゞに挑戊しゎヌルを目指すずいうものである。 </p> <p> 今、A君ずB君はこのゲヌムを䜕床かプレむしおいるが、A君の連勝でB君は1床も勝぀こずができおいない。そこであなたは、B君にこのゲヌムを攻略するためのヒントを教えおあげるこずにした。 </p> <h2>Problem</h2> <p> 時刻<var>T</var><sub>0</sub> = 0における瞊<var>H</var>&times;暪<var>W</var>の倧きさの二次元グリッドの状態が<var>Area</var><sub>0</sub>ずしお䞎えられる。次に、このグリッドの状態は時刻<var>T<sub>i</sub></var>においお、状態<var>Area<sub>i</sub></var>に切り替わる。この切り替わる過皋は<var>N</var>回繰り返される。初期状態のグリッドにはスタヌトの䜍眮'S'ずゎヌルの䜍眮'G'が䞎えられる。いずれかのグリッドにおいおゎヌルぞ蟿り着ける堎合は、そのずきの最小歩数を出力し、ゎヌルぞ蟿り着けない堎合は、'-1'を出力せよ。なお、以䞋の条件も満たす必芁がある。<br> </p> <ul> <li><var>Area<sub>i</sub></var>は以䞋の芁玠で構成されおいる。</li> <ul> <li>‘.’は䜕もなく移動可胜なマス</li> <li>’#’は障害物であり、移動䞍可胜なマス</li> <li>'S'はスタヌト䜍眮を衚すマス</li> <li>'G'はゎヌル䜍眮を衚すマス</li> </ul> <li>プレむダヌは珟圚いるマスの隣接しおいる䞊䞋巊右のいずれか1マスに移動する、たたは珟圚いるマスに留たるのに1秒かかる。ただし、障害物のマスやグリッドの範囲倖には移動できない。</li> <li>歩数は、珟圚プレむダヌがいるマスから䞊䞋巊右のマスぞ1マス進むず1増加する。その堎に留たる堎合には増加しない。</li> <li>党おのグリッドの倧きさは瞊<var>H</var>&times;暪<var>W</var>である。</li> <li>1マス移動、たたはその堎に留たった埌にグリッドが切り替わる際、次のグリッドにおいお障害物が存圚しないマスであれば今のグリッドの状態に関わらず移動が可胜である。</li> <li>党おのグリッドにおいお、初期のグリッドに䞎えられたゎヌル䜍眮に到達した堎合ゎヌルずみなす。</li> </ul> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>H</var> <var>W</var> <var>Area</var><sub>0</sub> <var>N</var> <var>T</var><sub>1</sub> <var>Area</var><sub>1</sub> <var>T</var><sub>2</sub> <var>Area</var><sub>2</sub> . . <var>T<sub>N</sub></var> <var>Area<sub>N</sub></var> </pre> <p> 1行目に2぀の敎数<var>H,W</var>が空癜区切りで䞎えられる。これは、それぞれ二次元グリッドの瞊ず暪の倧きさを衚す。2行目から<var>H</var>+1行目たでの各行に初期状態の二次元グリッドの状態が䞎えられる。<var>H</var>+2行目に敎数<var>N</var>が䞎えられる。これは、二次元グリッドの倉化する回数を衚す。<var>H</var>+3行目以降に<var>N</var>個の二次元グリッドの切り替わる時刻<var>T<sub>i</sub></var>ずその状態が䞎えられる。ただし、<var>T<sub>i</sub></var>は党お敎数である。 </p> <h2>Constraints</h2> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li>2 &le; <var>H,W</var> &le; 20</li> <li>1 &le; <var>N</var> &le; 15</li> <li>1 &le; <var>T<sub>i</sub></var> &le; 200 (<var>T</var><sub>1</sub> &lt; <var>T</var><sub>2</sub> &lt; ... &lt; <var>T<sub>N</sub></var>)</li> <li>スタヌト䜍眮'S'ずゎヌル䜍眮'G'はそれぞれ初期の二次元グリッドに1぀だけ存圚する。</li> </ul> <h2>Output</h2> <p> スタヌトからゎヌルぞ到達するための最小の歩数を出力せよ。ただし、ゎヌルに到達できない堎合は'-1'を出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 2 2 S. .G 1 3 ## ## </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <p> 1番目のグリッドに切り替わる時刻<var>T</var><sub>1</sub>は3であり、時間内にプレむダヌはスタヌトからゎヌルたでの最短歩数が2歩で蟿り着くこずが可胜なので2を出力する。 </p> <h2>Sample Input 2</h2> <pre> 2 2 S. .G 1 2 ## ## </pre> <h2>Sample Output 2</h2> <pre> -1 </pre> <h2>Sample Input 3</h2> <pre> 2 3 S## ##G 4 2 ### .## 3 ### #.# 5 ### ##. 7 ### ### </pre> <h2>Sample Output 3</h2> <pre> 3 </pre> <h2>Sample Input 4</h2> <pre> 4 3 S.. ... .G. ... 4 2 ### #.# ### #.# 4 ### #.. #.. ### 6 ### #.# ### #.. 8 ### #.. #.. ### </pre> <h2>Sample Output 4</h2> <pre> 3 </pre> <h2>Sample Input 5</h2> <pre> 3 3 S## ### ##G 1 1 ... ... ... </pre> <h2>Sample Output 5</h2> <pre> 4 </pre>
p00271
<H1>気枩の差</H1> <p> 遞手の皆さん、パ゜コン甲子園にようこそ。むベントに参加するには䜓調管理が倧切です。気枩が倧きく倉動する季節の倉わり目には䜓に負担がかかり、颚邪をひきやすいず蚀われおいたす。䞀番気を付けなければいけない日は、最高気枩ず最䜎気枩の差が最も倧きい日です。日の最高気枩ず最䜎気枩が日分䞎えられたずき、それぞれの日に぀いお最高気枩から最䜎気枩を匕いた倀を出力するプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力デヌタは以䞋の圢匏で䞎えられる。 </p> <pre> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> : <var>a<sub>7</sub></var> <var>b<sub>7</sub></var> </pre> <p> 入力は7行からなり、i行目には<var>i</var>日目の最高気枩 <var>a<sub>i</sub></var>(-40 &le; <var>a<sub>i</sub></var> &le; 40)ず最䜎気枩 <var>b<sub>i</sub></var>(-40 &le; <var>b<sub>i</sub></var> &le; 40)を衚す敎数が䞎えられる。すべおの日においお、最高気枩 <var>a<sub>i</sub></var> は必ず最䜎気枩 <var>b<sub>i</sub></var> 以䞊ずなっおいる。 </p> <h2>出力</h2> <p> 7日分の気枩の差を7行に出力する。 </p> <h2>入力䟋</h2> <pre> 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 </pre> <h2>出力䟋</h2> <pre> 11 19 1 5 1 13 20 </pre>
p01899
<link rel="stylesheet" href="css/description.css" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script> <h2>B: 山手線ゲヌム - Yamanote-line Game -</h2> <h3>豆知識</h3> <p>山手線は䟿利である。 なぜならば、130円払うだけで時間の蚱す限り䜕呚でも乗っおいられるからだ。ただし、切笊で乗車する堎合は、切笊の有効時間に気を぀けなければならない。ICカヌドなら安心らしい。この山手線の特性を利甚しお、東京近郊には電車に揺られながら惰眠を貪る茩が存圚する。ちなみに、この問題の䜜問者はやったこずがない。駅員にバレるこずは皀だろうが、バレたらめんどくさそうなので、オススメはしない。</p> <h3>問題文</h3> <p>山手線の特性を利甚したゲヌムをしよう。 ここでは䞀般化のため、<var>1</var>から<var>N</var>で番号付けられた<var>N</var>個の駅があり、<var>1</var>, <var>2</var>, ..., <var>N</var>の順で駅が円䞊に䞊び、各駅からいずれの駅ぞ行くにも<var>d</var>円で乗車可胜な路線ずしお山手線モドキを考えるこずにする。ゲヌムは以䞋のルヌルに埓う。</p> <ul> <li>奜きな駅をスタヌト地点に遞び<var>d</var>円で山手線モドキに乗車する。</li> <li>その埌、任意の駅で降車し再床乗車するこずを繰り返す。</li> <li>スタヌトした駅で降車した時点でゲヌム終了ずなる。</li> <li><var>i</var>番目の駅で降りるず<var>p_i</var>円の報酬を埗るこずができる</li> <li>ただし、1床報酬を埗た駅で再床報酬を埗るこずはできない。</li> <li>たた、降車した埌に再床山手線モドキに乗車するには<var>d</var>円かかる。</li> </ul> <p>さお、あなたは最倧で䜕円儲けるこずができるだろうか。ぜひ、挑戊しおみお欲しい。</p> <h3>入力圢匏</h3> <pre> <var>N</var> <var>d</var> <var>p_1</var> <var>p_2</var> 
 <var>p_N</var> </pre> <p> 入力はすべお敎数からなる。 1行目には、山手線モドキの駅の数<var>N</var>ず乗車賃<var>d</var>が空癜区切りで䞎えられる。 2行目には、各駅でもらえる報酬が空癜区切りで䞎えられ、<var>i</var>番目の倀<var>p_i</var>は駅<var>i</var>の報酬を衚しおいる。 </p> <h3>制玄</h3> <ul> <li><var>3 &le; N &le; 1{,}000</var></li> <li><var>1 &le; d &le; 1{,}000</var></li> <li><var>1 &le; p_i &le; 1{,}000</var> (<var>1 &le; i &le; N</var>)</li> </ul> <h3>出力圢匏</h3> <p>ゲヌムで埗られる金額の最倧倀を1行に出力せよ。1円以䞊の金額を埗るこずができない堎合は"kusoge"ず1行に出力せよ。出力の最埌は改行し䜙蚈な文字を含んではならない。</p> <h3>入力䟋1</h3> <pre> 5 130 130 170 100 120 140 </pre> <h3>出力䟋1</h3> <pre>50</pre> <h3>入力䟋2</h3> <pre> 3 100 100 90 65 </pre> <h3>出力䟋2</h3> <pre>kusoge</pre> <h3>入力䟋3</h3> <pre> 6 210 300 270 400 330 250 370 </pre> <h3>出力䟋3</h3> <pre>660</pre> <h3>入力䟋4</h3> <pre> 4 540 100 460 320 280 </pre> <h3>出力䟋4</h3> <pre>kusoge</pre>
p00621
<H1><font color="#000000">Problem A:</font> Sleeping Cats </H1> <p> Jackは圌の䜏む家をずおも気に入っおいた. 圌の家の塀の䞊で毎日のように愛くるしいねこたちが昌寝をしおいるからだ. Jackはねこがずおも奜きだった. </p> <p> Jackは, 倏䌑みの自由研究ずしおねこたちの芳察日蚘を付けるこずにした. しばらく芳察しおいるうちに, 圌はねこたちの面癜い特城に気付いた. </p> <p> 塀は W[å°º] の幅があり, ここにねこたちは䞊んで昌寝をする. それぞれのねこたちは䜓の倧きさが違うので, 昌寝に必芁ずする幅もたた異なる. 昌寝をしにきたねこは, 自分が寝られる堎所があれば, そこで昌寝をする. ただし, そのような堎所が耇数ある堎合はより巊偎で昌寝をし, 十分な幅が無ければ諊めお垰っおしたう. しばらく昌寝をしたねこは、起きるず塀から飛び降りおどこかぞず行っおしたう. </p> <p> Jackはねこたちを芳察しお, その行動をノヌトに曞き留めた. しかし, ずおも倚くのねこが昌寝をしおいたので, この蚘録を集蚈するのはずおも倧倉である. プログラムを曞いお, ねこたちが昌寝をした堎所を求めるのを手䌝っおほしい. </p> <H2>Input</H2> <p> 入力ファむルは, 耇数のデヌタセットを含む. それぞれのデヌタセットの最初の行は2぀の敎数を含み, それぞれ塀の幅 W ず, 埌に続く行数 Q を衚す. </p> <p> 以䞋のQ行に, ねこの芳察蚘録が䞎えられる. 各行は, 以䞋のいずれかの曞匏に埓う. </p> <p><span>s</span> [id] [w]</p> <p><span>w</span> [id]</p> <p> 前者は, ねこの sleep 蚘録であり, ねこが昌寝をしに来たこずを衚す. id はねこの名前を衚す敎数であり, w はそのねこが昌寝に必芁ずする幅 [å°º]である. </p> <p> 埌者は, ねこの wakeup 蚘録であり, 名前がidであるねこが起きたこずを衚す. </p> <p> この蚘録は, 時系列順に䞎えられる. </p> <p> どのねこも2回以䞊昌寝をするこずはない. たた, Jackの蚘録に矛盟は無いものずする. ぀たり, あるねこの sleep 蚘録に察しお, そのねこが昌寝するこずが出来た堎合, たたその堎合に限っお, そのねこの wakeup 蚘録が(より埌の行に)䞎えられる. </p> <p> W, Q &le; 100 ず仮定しおよい. </p> <p> W ず Q がずもに 0 のずき、入力の終わりを瀺す. このデヌタセットに察する出力を行っおはならない. </p> <H2>Output</H2> <p> 入力のsleep蚘録が䞎えられるたびに, 1行出力せよ. この行は, もしそのねこが昌寝できた堎合, その䜍眮を衚す数字を含たなければならない. ねこが塀の巊端を起点ずしお b [å°º] から b+w [å°º] の堎所で昌寝したならば, b を出力せよ. そのねこが昌寝できなかった堎合, "<span>impossible</span>" ず出力せよ. </p> <p> デヌタセットの終わりに, "END"ず出力せよ. </p> <H2>Sample Input</H2> <pre> 4 6 s 0 2 s 1 3 s 2 1 w 0 s 3 3 s 4 2 3 3 s 0 1 s 1 1 s 2 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 impossible 2 impossible 0 END 0 1 2 END </pre>
p01933
<!-- - - - - - begin nicebody - - - - - --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>C: ツむヌト数</h1> <h2>問題</h2> <p>AORむカちゃんが利甚するSNSであるむカったヌでは、投皿のこずをツむヌトず呌ぶ。</p> <p>そしお、むカったヌでは、ツむヌトぞの返信が倚くなるず芖認性が悪くなるこずが懞念されるため、あるツむヌトが次の芏則のいずれかを満たすずきに画面にそのツむヌトを衚瀺する仕様になっおいる。</p> <ul> <li>芏則. どのツむヌトぞも返信しおいない</li> <li>芏則. どのツむヌトからも返信されおいない</li> <li>芏則. 芏則が適甚されたツむヌトから返信先を順に蟿ったずき、 $K$ 回未満で蟿り着ける</li> </ul> <p>なお、同じツむヌトは重耇しお衚瀺されるこずはない。</p> <p>いた、 $N$ 個のツむヌトがあり、 $A_i$ が $0$ のずき $i$ 番目のツむヌトは返信でないツむヌトで、 $A_i$ が $0$ でないずき $i$ 番目のツむヌトは $A_i$ 番目のツむヌトぞの返信のツむヌトである。</p> <p>画面に衚瀺されるツむヌト数を答えよ。</p> <h2>制玄</h2> <ul> <li>$1 \le N \le 10^5$</li> <li>$1 \le K \le 10^5$</li> <li>$0 \le A_i \lt i (i = 1, 2, \dots, N)$</li> <li>ツむヌトは時系列順に䞎えられる。</li> <li>入力は党お敎数で䞎えられる。</li> </ul> <h2>入力圢匏</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <p>$N \ K$<br>$A_1$<br>$A_2$<br>$\vdots$<br>$A_N$</p> <h2>出力</h2> <p>画面に衚瀺されるツむヌト数を出力せよ。たた、末尟に改行も出力せよ。</p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre>6 3 0 0 2 3 4 5 </pre> <h3>サンプル出力 1</h3> <pre>5 </pre> <p>この時、衚瀺されるツむヌトは、図の青いツむヌトである。 よっお、この䟋の解は $5$ である。</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day1_rupc2017_c" height="400" /> <h3>サンプル入力 2</h3> <pre>12 2 0 1 0 3 4 3 6 7 0 9 10 11 </pre> <h3>サンプル出力 2</h3> <pre>10 </pre> <h3>サンプル入力 3</h3> <pre>5 10 0 0 0 0 0 </pre> <h3>サンプル出力 3</h3> <pre>5 </pre> <!-- - - - - - end nicebody - - - - - -->
p02132
<h1>Problem I: Explosion</h1> <h2>Problem</h2> <p> 倧魔王めぐみんは地䞊に生存する$N$人の勇者を倒そうず考えおいる。<br> めぐみんは$M$回たで爆発魔法を唱えるこずができる。<br> 爆発魔法は任意の座暙を䞭心に半埄$r$以内に存圚しおいる勇者を消滅させる魔法である。<br> 勇者はずおも痩せおいるため倧きさは考慮しなくおよい。<br> $M$回の爆発魔法は党お同じ倧きさの半埄で唱えるものずする。<br> 勇者を党滅させるのに必芁最小限の半埄の魔法を䜿うこずにした。<br> 爆発魔法の半埄の倧きさを最小化せよ。<br> <h2>Input</h2> <pre> $N$ $M$ $x_1$ $y_1$ ... $x_N$ $y_N$ </pre> <p> 入力は以䞋の圢匏で䞎えられる。<br> 1行目に 勇者の数 $N$ 、唱える爆発の数 $M$ が敎数で䞎えられる。<br> 2行目以降にそれぞれの勇者$i$の座暙 $x_i$ $,$ $y_i$ が敎数で䞎えられる。<br> </p> <h2>Constraints</h2> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li>$1 \leq M \leq N \leq 14$</li> <li>$0 \leq x_i $,$ y_i \leq 10^5$</li> </ul> <h2>Output</h2> <p> 爆発魔法の半埄の最小倀を実数で出力せよ。<br> $10^{-3}$を超える絶察誀差を含んではならない。<br> </p> <h2>Sample Input 1</h2> <pre> 5 2 0 0 5 5 10 10 100 100 200 200 </pre> <h2>Sample Output 1</h2> <pre> 70.710678118755 </pre> <h2>Sample Input 2</h2> <pre> 10 5 321 675 4312 6534 312 532 412 6543 21 43 654 321 543 0 32 5 41 76 5 1 </pre> <h2>Sample Output 2</h2> <pre> 169.824909833728 </pre> <h2>Sample Input 3</h2> <pre> 14 3 312 342 4893 432 321 4 389 4 23 543 0 0 1 1 2 2 432 12 435 32 1 5 2 10 100 100 20 50 </pre> <h2>Sample Output 3</h2> <pre> 218.087711712613 </pre> <h2>Sample Input 4</h2> <pre> 5 2 0 0 0 0 0 0 0 0 0 0 </pre> <h2>Sample Output 4</h2> <pre> 0.000000000001 </pre>
p02098
<h1>Problem A: The Mean of Angles</h1> <h2>Problem</h2> <p> 䞎えられた2぀の角床<var>&theta;<sub>1</sub></var>,<var>&theta;<sub>2</sub></var> のちょうど間の角床を求めよ。ここで、ちょうど間の角床を、䞋図のように「<var>&theta;<sub>1</sub></var> &plus; <var>t</var> = <var>&theta;<sub>2</sub></var> &minus; <var>t</var> を満たす<var>t</var>のうち絶察倀が最も小さいものを<var>t’</var>ずしたずきの<var>&theta;<sub>1</sub></var> &plus; <var>t’</var>」ず定矩する。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day2_UAPC_A_angle" alt="A image of angles" title="ちょうど間の角床"> </center> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>&theta;<sub>1</sub></var> <var>&theta;<sub>2</sub></var> </pre> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>角床は床数法(degree)で衚される</li> <li>0 &le; <var>&theta;<sub>1</sub></var>, <var>&theta;<sub>2</sub></var> &lt; 360</li> <li><var>&theta;<sub>1</sub></var>, <var>&theta;<sub>2</sub></var>は敎数</li> <li>|<var>&theta;<sub>1</sub></var> &minus; <var>&theta;<sub>2</sub></var>| &ne; 180</li> <li>解答が[0,0.0001]たたは[359.999, 360)になるような入力は䞎えられない</li> </ul> <h2>Output</h2> <p> <var>&theta;<sub>1</sub></var>,<var>&theta;<sub>2</sub></var>のちょうど間の角床を床数法で[0,360)の範囲で1行に出力せよ。ただし0.0001を超える誀差を含んではならない。 </p> <h2>Sample Input 1</h2> <pre> 10 20 </pre> <h2>Sample Output 1</h2> <pre> 15.0 </pre> <h2>Sample Input 2</h2> <pre> 20 350 </pre> <h2>Sample Output 2</h2> <pre> 5.0 </pre>
p02562
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a grid of <var>N</var> rows and <var>M</var> columns. The square at the <var>i</var>-th row and <var>j</var>-th column will be denoted as <var>(i,j)</var>. A nonnegative integer <var>A_{i,j}</var> is written for each square <var>(i,j)</var>.</p> <p>You choose some of the squares so that each row and column contains at most <var>K</var> chosen squares. Under this constraint, calculate the maximum value of the sum of the integers written on the chosen squares. Additionally, calculate a way to choose squares that acheives the maximum.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>0 \leq A_{i,j} \leq 10^9</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>K</var> <var>A_{1,1}</var> <var>A_{1,2}</var> <var>\cdots</var> <var>A_{1,N}</var> <var>A_{2,1}</var> <var>A_{2,2}</var> <var>\cdots</var> <var>A_{2,N}</var> <var>\vdots</var> <var>A_{N,1}</var> <var>A_{N,2}</var> <var>\cdots</var> <var>A_{N,N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>On the first line, print the maximum value of the sum of the integers written on the chosen squares.</p> <p>On the next <var>N</var> lines, print a way that achieves the maximum.</p> <p>Precisely, output the strings <var>t_1,t_2,\cdots,t_N</var>, that satisfies <var>t_{i,j}=</var><code>X</code> if you choose <var>(i,j)</var> and <var>t_{i,j}=</var><code>.</code> otherwise.</p> <p>You may print any way to choose squares that maximizes the sum.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 5 3 2 1 4 8 7 6 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>19 X.. ..X .X. </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 10 10 1 10 10 1 1 1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>50 XX. XX. ..X </pre></section> </div> </span>
p02831
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Takahashi is organizing a party.</p> <p>At the party, each guest will receive one or more snack pieces.</p> <p>Takahashi predicts that the number of guests at this party will be <var>A</var> or <var>B</var>.</p> <p>Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.</p> <p>We assume that a piece cannot be divided and distributed to multiple guests.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq A, B \leq 10^5</var></li> <li><var>A \neq B</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>Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with <var>A</var> guests and <var>B</var> guests.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>123 456 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>18696 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100000 99999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9999900000 </pre></section> </div> </span>
p03723
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi, Aoki and Snuke love cookies. They have <var>A</var>, <var>B</var> and <var>C</var> cookies, respectively. Now, they will exchange those cookies by repeating the action below:</p> <ul> <li>Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.</li> </ul> <p>This action will be repeated until there is a person with odd number of cookies in hand.</p> <p>How many times will they repeat this action? Note that the answer may not be finite.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ A,B,C ≀ 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>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of times the action will be performed by the three people, if this number is finite. If it is infinite, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 12 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>Initially, Takahashi, Aoki and Snuke have <var>4</var>, <var>12</var> and <var>20</var> cookies. Then,</p> <ul> <li>After the first action, they have <var>16</var>, <var>12</var> and <var>8</var>.</li> <li>After the second action, they have <var>10</var>, <var>12</var> and <var>14</var>.</li> <li>After the third action, they have <var>13</var>, <var>12</var> and <var>11</var>.</li> </ul> <p>Now, Takahashi and Snuke have odd number of cookies, and therefore the answer is <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>14 14 14 </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>454 414 444 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre></section> </div> </span>
p03689
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given four integers: <var>H</var>, <var>W</var>, <var>h</var> and <var>w</var> (<var>1 ≀ h ≀ H</var>, <var>1 ≀ w ≀ W</var>). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:</p> <ul> <li>The matrix has <var>H</var> rows and <var>W</var> columns.</li> <li>Each element of the matrix is an integer between <var>-10^9</var> and <var>10^9</var> (inclusive).</li> <li>The sum of all the elements of the matrix is positive.</li> <li>The sum of all the elements within every subrectangle with <var>h</var> rows and <var>w</var> columns in the matrix is negative.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ h ≀ H ≀ 500</var></li> <li><var>1 ≀ w ≀ W ≀ 500</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>h</var> <var>w</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there does not exist a matrix that satisfies all of the conditions, print <code>No</code>.</p> <p>Otherwise, print <code>Yes</code> in the first line, and print a matrix in the subsequent lines in the following format:</p> <pre><var>a_{11}</var> <var>...</var> <var>a_{1W}</var> <var>:</var> <var>a_{H1}</var> <var>...</var> <var>a_{HW}</var> </pre> <p>Here, <var>a_{ij}</var> represents the <var>(i,\ j)</var> element of the matrix.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes 1 1 1 1 -4 1 1 1 1 </pre> <p>The sum of all the elements of this matrix is <var>4</var>, which is positive. Also, in this matrix, there are four subrectangles with <var>2</var> rows and <var>2</var> columns as shown below. For each of them, the sum of all the elements inside is <var>-1</var>, which is negative.</p> <div style="text-align: center;"> <img alt="bbdb651fa1f05996886da9f0c4d8090a.png" src="https://atcoder.jp/img/agc016/bbdb651fa1f05996886da9f0c4d8090a.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 4 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes 2 -5 8 7 3 -5 -4 -5 2 1 -1 7 </pre></section> </div> </span>
p03373
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are <var>A</var> yen, <var>B</var> yen and <var>C</var> yen (yen is the currency of Japan), respectively.</p> <p>Nakahashi needs to prepare <var>X</var> A-pizzas and <var>Y</var> B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ A, B, C ≀ 5000</var></li> <li><var>1 ≀ X, Y ≀ 10^5</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum amount of money required to prepare <var>X</var> A-pizzas and <var>Y</var> B-pizzas.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1500 2000 1600 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7900 </pre> <p>It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1500 2000 1900 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8500 </pre> <p>It is optimal to directly buy three A-pizzas and two B-pizzas.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1500 2000 500 90000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>100000000 </pre> <p>It is optimal to buy <var>200000</var> AB-pizzas and rearrange them into <var>100000</var> A-pizzas and <var>100000</var> B-pizzas. We will have <var>10000</var> more A-pizzas than necessary, but that is fine.</p></section> </div> </span>
p02974
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let us define the <em>oddness</em> of a permutation <var>p</var> = {<var>p_1,\ p_2,\ ...,\ p_n</var>} of {<var>1,\ 2,\ ...,\ n</var>} as <var>\sum_{i = 1}^n |i - p_i|</var>.</p> <p>Find the number of permutations of {<var>1,\ 2,\ ...,\ n</var>} of oddness <var>k</var>, modulo <var>10^9+7</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 50</var></li> <li><var>0 \leq k \leq n^2</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of permutations of {<var>1,\ 2,\ ...,\ n</var>} of oddness <var>k</var>, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are six permutations of {<var>1,\ 2,\ 3</var>}. Among them, two have oddness of <var>2</var>: {<var>2,\ 1,\ 3</var>} and {<var>1,\ 3,\ 2</var>}.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>39 14 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>74764168 </pre></section> </div> </span>
p00949
<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 Hidden Anagrams </h2> <p> An <i>anagram</i> is a word or a phrase that is formed by rearranging the letters of another. For instance, by rearranging the letters of "William Shakespeare," we can have its anagrams "I am a weakish speller," "I'll make a wise phrase," and so on. Note that when $A$ is an anagram of $B$, $B$ is an anagram of $A$. </p> <p> In the above examples, differences in letter cases are ignored, and word spaces and punctuation symbols are freely inserted and/or removed. These rules are common but not applied here; only exact matching of the letters is considered. </p> <p> For two strings $s_1$ and $s_2$ of letters, if a substring $s'_1$ of $s_1$ is an anagram of a substring $s'_2$ of $s_2$, we call $s'_1$ a <i>hidden anagram</i> of the two strings, $s_1$ and $s_2$. Of course, $s'_2$ is also a <i>hidden anagram</i> of them. </p> <p> Your task is to write a program that, for given two strings, computes the length of the longest hidden anagrams of them. </p> <p> Suppose, for instance, that "anagram" and "grandmother" are given. Their substrings "nagr" and "gran" are hidden anagrams since by moving letters you can have one from the other. They are the longest since any substrings of "grandmother" of lengths five or more must contain "d" or "o" that "anagram" does not. In this case, therefore, the length of the longest hidden anagrams is four. Note that a substring must be a sequence of letters occurring <i>consecutively</i> in the original string and so "nagrm" and "granm" are not hidden anagrams. </p> <h3>Input</h3> <p> The input consists of a single test case in two lines.<br/> <br/> $s_1$<br/> $s_2$<br/> </p> <p> $s_1$ and $s_2$ are strings consisting of lowercase letters (a through z) and their lengths are between 1 and 4000, inclusive. </p> <h3>Output</h3> <p> Output the length of the longest hidden anagrams of $s_1$ and $s_2$. If there are no hidden anagrams, print a zero. </p> <h3>Sample Input 1</h3> <pre>anagram grandmother</pre> <h3>Sample Output 1</h3> <pre>4</pre> <br/> <h3>Sample Input 2</h3> <pre>williamshakespeare iamaweakishspeller</pre> <h3>Sample Output 2</h3> <pre>18</pre> <br/> <h3>Sample Input 3</h3> <pre>aaaaaaaabbbbbbbb xxxxxabababxxxxxabab</pre> <h3>Sample Output 3</h3> <pre>6</pre> <br/> <h3>Sample Input 4</h3> <pre>abababacdcdcd efefefghghghghgh</pre> <h3>Sample Output 4</h3> <pre>0</pre>
p03666
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> squares in a row. The leftmost square contains the integer <var>A</var>, and the rightmost contains the integer <var>B</var>. The other squares are empty.</p> <p>Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:</p> <ul> <li>For any two adjacent squares, the (absolute) difference of the two integers in those squares is between <var>C</var> and <var>D</var> (inclusive).</li> </ul> <p>As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 500000</var></li> <li><var>0 \leq A \leq 10^9</var></li> <li><var>0 \leq B \leq 10^9</var></li> <li><var>0 \leq C \leq D \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>N</var> <var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>YES</code> if it is possible to fill the squares under the condition; print <code>NO</code> otherwise.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 5 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>For example, fill the squares with the following integers: <var>1</var>, <var>-1</var>, <var>3</var>, <var>7</var>, <var>5</var>, from left to right.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 7 6 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>48792 105960835 681218449 90629745 90632170 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>491995 412925347 825318103 59999126 59999339 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>YES </pre></section> </div> </span>
p03236
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><strong>Problem F and F2 are the same problem, but with different constraints and time limits.</strong></p> <p>We have a board divided into <var>N</var> horizontal rows and <var>N</var> vertical columns of square cells. The cell at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is called Cell <var>(i,j)</var>. Each cell is either empty or occupied by an obstacle. Also, each empty cell has a digit written on it. If <var>A_{i,j}=</var> <code>1</code>, <code>2</code>, ..., or <code>9</code>, Cell <var>(i,j)</var> is empty and the digit <var>A_{i,j}</var> is written on it. If <var>A_{i,j}=</var> <code>#</code>, Cell <var>(i,j)</var> is occupied by an obstacle.</p> <p>Cell <var>Y</var> is <em>reachable</em> from cell <var>X</var> when the following conditions are all met:</p> <ul> <li>Cells <var>X</var> and <var>Y</var> are different.</li> <li>Cells <var>X</var> and <var>Y</var> are both empty.</li> <li>One can reach from Cell <var>X</var> to Cell <var>Y</var> by repeatedly moving right or down to an adjacent empty cell.</li> </ul> <p>Consider all pairs of cells <var>(X,Y)</var> such that cell <var>Y</var> is reachable from cell <var>X</var>. Find the sum of the products of the digits written on cell <var>X</var> and cell <var>Y</var> for all of those pairs.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 500</var></li> <li><var>A_{i,j}</var> is one of the following characters: <code>1</code>, <code>2</code>, ... <code>9</code> and <code>#</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_{1,1}A_{1,2}...A_{1,N}</var> <var>A_{2,1}A_{2,2}...A_{2,N}</var> <var>:</var> <var>A_{N,1}A_{N,2}...A_{N,N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the products of the digits written on cell <var>X</var> and cell <var>Y</var> for all pairs <var>(X,Y)</var> such that cell <var>Y</var> is reachable from cell <var>X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 11 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are five pairs of cells <var>(X,Y)</var> such that cell <var>Y</var> is reachable from cell <var>X</var>, as follows:</p> <ul> <li><var>X=(1,1)</var>, <var>Y=(1,2)</var></li> <li><var>X=(1,1)</var>, <var>Y=(2,1)</var></li> <li><var>X=(1,1)</var>, <var>Y=(2,2)</var></li> <li><var>X=(1,2)</var>, <var>Y=(2,2)</var></li> <li><var>X=(2,1)</var>, <var>Y=(2,2)</var></li> </ul> <p>The product of the digits written on cell <var>X</var> and cell <var>Y</var> is <var>1</var> for all of those pairs, so the answer is <var>5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1111 11#1 1#11 1111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>47 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 76##63##3# 8445669721 75#9542133 3#285##445 749632##89 2458##9515 5952578#77 1#3#44196# 4355#99#1# #298#63587 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>36065 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 4177143673 7######### 5#1716155# 6#4#####5# 2#3#597#6# 6#9#8#3#5# 5#2#899#9# 1#6#####6# 6#5359657# 5######### </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>6525 </pre></section> </div> </span>
p04009
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns. The state of the cell at the <var>i</var>-th (<var>1≀i≀H</var>) row and <var>j</var>-th (<var>1≀j≀W</var>) column is represented by a letter <var>a_{ij}</var>, as follows:</p> <ul> <li><code>.</code> : This cell is empty.</li> <li><code>o</code> : This cell contains a robot.</li> <li><code>E</code> : This cell contains the exit. <code>E</code> occurs exactly once in the whole grid.</li> </ul> <p>Snuke is trying to salvage as many robots as possible, by performing the following operation some number of times:</p> <ul> <li>Select one of the following directions: up, down, left, right. All remaining robots will move one cell in the selected direction, except when a robot would step outside the grid, in which case the robot will explode and immediately disappear from the grid. If a robot moves to the cell that contains the exit, the robot will be salvaged and immediately removed from the grid.</li> </ul> <p>Find the maximum number of robots that can be salvaged.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀H,W≀100</var></li> <li><var>a_{ij}</var> is <code>.</code>, <code>o</code> or <code>E</code>.</li> <li><code>E</code> occurs exactly once in the whole grid.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>a_{11}</var><var>...</var><var>a_{1W}</var> <var>:</var> <var>a_{H1}</var><var>...</var><var>a_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of robots that can be salvaged.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 o.o .Eo ooo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>For example, select left, up, right.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 E. .. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 4 o... o... oooE </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre> <p>Select right, right, right, down, down.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 11 ooo.ooo.ooo o.o.o...o.. ooo.oE..o.. o.o.o.o.o.. o.o.ooo.ooo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>12 </pre></section> </div> </span>
p02077
<style type="text/css"> blockquote { font-family: Menlo, Monaco, "Courier New", monospace; display: block; margin: 10px 0 10px 30px; font-size: 16px; line-height: 18px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; } table.ioexample { width: 100%; border-collapse: collapse; } table.ioexample td { width: 50%; border: 1px solid rgba(0, 0, 0, 0.15); vertical-align: top; padding: 5px; } .no-page-break { page-break-inside: avoid; } .page-break { page-break-before: always; } </style> <h3>Problem Statement</h3> <p>JAG land is a country, which is represented as an $M \times M$ grid. Its top-left cell is $(1, 1)$ and its bottom-right cell is $(M, M)$.</p> <p>Suddenly, a bomber invaded JAG land and dropped bombs to the country. Its bombing pattern is always fixed and represented by an $N \times N$ grid. Each symbol in the bombing pattern is either <code>X</code> or <code>.</code>. The meaning of each symbol is as follows.</p> <ul> <li><code>X</code>: Bomb </li> <li><code>.</code>: Empty</li> </ul> <p>Here, suppose that a bomber is in $(br, bc)$ in the land and drops a bomb. The cell $(br + i - 1, bc + j - 1)$ will be damaged if the symbol in the $i$-th row and the $j$-th column of the bombing pattern is <code>X</code> ($1 \le i, j \le N$).</p> <p>Initially, the bomber reached $(1, 1)$ in JAG land. The bomber repeated to move to either of $4$-directions and then dropped a bomb just $L$ times. During this attack, the values of the coordinates of the bomber were between $1$ and $M - N + 1$, inclusive, while it dropped bombs. Finally, the bomber left the country.</p> <p>The moving pattern of the bomber is described as $L$ characters. The $i$-th character corresponds to the $i$-th move and the meaning of each character is as follows.</p> <ul> <li><code>U</code>: Up</li> <li><code>D</code>: Down</li> <li><code>L</code>: Left</li> <li><code>R</code>: Right</li> </ul> <p>Your task is to write a program to analyze the damage situation in JAG land. To investigate damage overview in the land, calculate the number of cells which were damaged by the bomber at least $K$ times.</p> <hr /> <h3>Input</h3> <p>The input consists of a single test case in the format below.</p> <blockquote>$N$ $M$ $K$ $L$ $B_{1}$ $\vdots$ $B_{N}$ $S$</blockquote> <p>The first line contains four integers $N$, $M$, $K$ and $L$($1 \le N &lt; M \le 500$, $1 \le K \le L \le 2 \times 10^{5}$). The following $N$ lines represent the bombing pattern. $B_i$ is a string of length $N$. Each character of $B_i$ is either <code>X</code> or <code>.</code>. The last line denotes the moving pattern. $S$ is a string of length $L$, which consists of either <code>U</code>, <code>D</code>, <code>L</code> or <code>R</code>. It's guaranteed that the values of the coordinates of the bomber are between $1$ and $M - N + 1$, inclusive, while it drops bombs in the country.</p> <h3>Output</h3> <p>Print the number of cells which were damaged by the bomber at least $K$ times.</p> <p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>2 3 2 4 XX X. RDLU </pre></td><td><pre>3 </pre></td></tr><tr><td><pre>7 8 3 5 .XXX.X. X..X.X. ...XX.X XX.XXXX ..XXXX. X.X.... ..XXXXX DRULD </pre></td><td><pre>26 </pre></td></tr></table></div></p>
p02427
<h1>Enumeration of Subsets I</h1> <p> Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ </pre> <h2>Output</h2> <p> Print subsets ordered by their decimal integers. Print a subset in a line in the following format. </p> <pre> $d$: $e_0$ $e_1$ ... </pre> <p> Print '<span>:</span>' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 18$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 </pre> <h2>Sample Output 1</h2> <pre> 0: 1: 0 2: 1 3: 0 1 4: 2 5: 0 2 6: 1 2 7: 0 1 2 8: 3 9: 0 3 10: 1 3 11: 0 1 3 12: 2 3 13: 0 2 3 14: 1 2 3 15: 0 1 2 3 </pre> <p> Note that if the subset is empty, your program should not output a space character after '<span>:</span>'. </p>
p01122
<!--<h2>Problem F</h2>--> <!-- begin en only --> <h3>Flipping Colors</h3> <!-- end en only --> <!-- begin en only --> <p> You are given an undirected complete graph. Every pair of the nodes in the graph is connected by an edge, colored either red or black. Each edge is associated with an integer value called <em>penalty.</em> </p> <p> By repeating certain operations on the given graph, a &ldquo;spanning tree&rdquo; should be formed with only the red edges. That is, the number of red edges should be made exactly one less than the number of nodes, and all the nodes should be made connected only via red edges, directly or indirectly. If two or more such trees can be formed, one with the least sum of penalties of red edges should be chosen. </p> <p> In a single operation step, you choose one of the nodes and flip the colors of <i>all</i> the edges connected to it: Red ones will turn to black, and black ones to red. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_F1.png" width="664px" height="214px"> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. F-1 The first dataset of Sample Input and its solution <!-- end en only --> </figcaption> </center> <!-- begin en only --> <p> For example, the leftmost graph of Fig.&nbsp;F-1 illustrates the first dataset of Sample Input. By flipping the colors of all the edges connected to the node 3, and then flipping all the edges connected to the node 2, you can form a spanning tree made of red edges as shown in the rightmost graph of the figure. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of multiple datasets, each in the following format. </p> <!-- end en only --> <p> <blockquote> <i>n</i> <br> <i>e</i><sub>1,2</sub> <i>e</i><sub>1,3</sub> ... <i>e</i><sub>1,<i>n</i>-1</sub> <i>e</i><sub>1,<i>n</i></sub><br> <i>e</i><sub>2,3</sub> <i>e</i><sub>2,4</sub> ... <i>e</i><sub>2,<i>n</i></sub><br> ... <br> <i>e</i><sub><i>n</i>-1,<i>n</i></sub> </blockquote> </p> <!-- begin en only --> <p> The integer <i>n</i> (2 &le; <i>n</i> &le; 300) is the number of nodes. The nodes are numbered from 1 to <i>n</i>. The integer <i>e</i><sub><i>i</i>,<i>k</i></sub> (1 &le; |<i>e</i><sub><i>i</i>,<i>k</i></sub>| &le; 10<sup>5</sup>) denotes the penalty and the initial color of the edge between the node <i>i</i> and the node <i>k</i>. Its absolute value |<i>e</i><sub><i>i</i>,<i>k</i></sub>| represents the penalty of the edge. <i>e</i><sub><i>i</i>,<i>k</i></sub> &gt; 0 means that the edge is initially red, and <i>e</i><sub><i>i</i>,<i>k</i></sub> &lt; 0 means it is black. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 50. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, print the sum of edge penalties of the red spanning tree with the least sum of edge penalties obtained by the above-described operations. If a red spanning tree can never be made by such operations, print <tt>-1</tt>. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 4 3 3 1 2 6 -4 3 1 -10 100 5 -2 -2 -2 -2 -1 -1 -1 -1 -1 1 4 -4 7 6 2 3 -1 0 </pre> <h3>Output for the Sample Input</h3> <pre> 7 11 -1 9 </pre>
p01572
<H1><font color="#000">Problem B:</font> Artistic Art Museum</H1> <p> Mr. Knight is a chief architect of the project to build a new art museum. One day, he was struggling to determine the design of the building. He believed that a brilliant art museum must have an artistic building, so he started to search for a good motif of his building. The art museum has one big theme: "nature and human beings." To reflect the theme, he decided to adopt a combination of a cylinder and a prism, which symbolize nature and human beings respectively (between these figures and the theme, there is a profound relationship that only he knows). </p> <p> Shortly after his decision, he remembered that he has to tell an estimate of the cost required to build to the financial manager. He unwillingly calculated it, and he returned home after he finished his report. However, you, an able secretary of Mr. Knight, have found that one field is missing in his report: the length of the fence required to surround the building. Fortunately you are also a good programmer, so you have decided to write a program that calculates the length of the fence. </p> <p> To be specific, the form of his building is union of a cylinder and a prism. You may consider the twodimensional projection of the form, i.e. the shape of the building is considered to be union of a circle <i>C</i> and a polygon <i>P</i>. The fence surrounds the outside of the building. The shape of the building may have a hole in it, and the fence is not needed inside the building. An example is shown in the figure below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_artisticArtMuseum"> </center> <H2>Input</H2> <p> The input contains one test case. </p> <p> A test case has the following format: </p> <p> <i>R</i><br/> <i>N</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> ... <i>x<sub>n</sub> y<sub>n</sub></i><br/> </p> <p> <i>R</i> is an integer that indicates the radius of <i>C</i> (1 &le; R &le; 1000), whose center is located at the origin. <i>N</i> is the number of vertices of <i>P</i>, and (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) is the coordinate of the <i>i</i>-th vertex of <i>P</i>. <i>N</i>, <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> are all integers satisfying the following conditions: 3 &le; <i>N</i> &le; 100,|<i>x<sub>i</sub></i>| &le; 1000 and |<i>y<sub>i</sub></i>| &le; 1000. </p> <p> You may assume that <i>C</i> and <i>P</i> have one or more intersections. </p> <H2>Output</H2> <!-- <p> Print the length of the fence required to surround the building. The output value should have four fractional digits, and may not contain an absolute error more than 10<sup>-4</sup>. </p> --> <p> Print the length of the fence required to surround the building. The output value should be in a decimal fraction may not contain an absolute error more than 10<sup>-4</sup>. </p> <p> It is guaranteed that the answer does not change by more than 10<sup>-6</sup> when <i>R</i> is changed by up to 10<sup>-9</sup>. </p> <H2>Sample Input 1</H2> <pre> 2 8 -1 2 1 2 1 -3 2 -3 2 3 -2 3 -2 -3 -1 -3 </pre> <H2>Output for the Sample Input 1</H2> <pre> 22.6303 </pre> <br/>
p01088
<h2>500-yen Saving</h2> <p> "500-yen Saving" is one of Japanese famous methods to save money. The method is quite simple; whenever you receive a 500-yen coin in your change of shopping, put the coin to your 500-yen saving box. Typically, you will find more than one million yen in your saving box in ten years. </p> <p> Some Japanese people are addicted to the 500-yen saving. They try their best to collect 500-yen coins efficiently by using 1000-yen bills and some coins effectively in their purchasing. For example, you will give 1320 yen (one 1000-yen bill, three 100-yen coins and two 10-yen coins) to pay 817 yen, to receive one 500-yen coin (and three 1-yen coins) in the change. </p> <p> A friend of yours is one of these 500-yen saving addicts. He is planning a sightseeing trip and wants to visit a number of souvenir shops along his way. He will visit souvenir shops one by one according to the trip plan. Every souvenir shop sells only one kind of souvenir goods, and he has the complete list of their prices. He wants to collect as many 500-yen coins as possible through buying at most one souvenir from a shop. On his departure, he will start with sufficiently many 1000-yen bills and no coins at all. The order of shops to visit cannot be changed. As far as he can collect the same number of 500-yen coins, he wants to cut his expenses as much as possible. </p> <p> Let's say that he is visiting shops with their souvenir prices of 800 yen, 700 yen, 1600 yen, and 600 yen, in this order. He can collect at most two 500-yen coins spending 2900 yen, the least expenses to collect two 500-yen coins, in this case. After skipping the first shop, the way of spending 700-yen at the second shop is by handing over a 1000-yen bill and receiving three 100-yen coins. In the next shop, handing over one of these 100-yen coins and two 1000-yen bills for buying a 1600-yen souvenir will make him receive one 500-yen coin. In almost the same way, he can obtain another 500-yen coin at the last shop. He can also collect two 500-yen coins buying at the first shop, but his total expenditure will be at least 3000 yen because he needs to buy both the 1600-yen and 600-yen souvenirs in this case. </p> <p> You are asked to make a program to help his collecting 500-yen coins during the trip. Receiving souvenirs' prices listed in the order of visiting the shops, your program is to find the maximum number of 500-yen coins that he can collect during his trip, and the minimum expenses needed for that number of 500-yen coins. </p> <p> For shopping, he can use an arbitrary number of 1-yen, 5-yen, 10-yen, 50-yen, and 100-yen coins he has, and arbitrarily many 1000-yen bills. The shop always returns the exact change, i.e., the difference between the amount he hands over and the price of the souvenir. The shop has sufficient stock of coins and the change is always composed of the smallest possible number of 1-yen, 5-yen, 10-yen, 50-yen, 100-yen, and 500-yen coins and 1000-yen bills. He may use more money than the price of the souvenir, even if he can put the exact money, to obtain desired coins as change; buying a souvenir of 1000 yen, he can hand over one 1000-yen bill and five 100-yen coins and receive a 500-yen coin. Note that using too many coins does no good; handing over ten 100-yen coins and a 1000-yen bill for a souvenir of 1000 yen, he will receive a 1000-yen bill as the change, not two 500-yen coins. </p> <h3>Input</h3> <p> The input consists of at most 50 datasets, each in the following format. </p> <blockquote> <i>n</i> <br> <i>p</i><sub>1</sub><br> ...<br> <i>p<sub>n</sub></i> <br> </blockquote> <p> <i>n</i> is the number of souvenir shops, which is a positive integer not greater than 100. <i>p<sub>i</sub></i> is the price of the souvenir of the <i>i</i>-th souvenir shop. <i>p<sub>i</sub></i> is a positive integer not greater than 5000. </p> <p> The end of the input is indicated by a line with a single zero. </p> <h3>Output</h3> <p> For each dataset, print a line containing two integers <i>c</i> and <i>s</i> separated by a space. Here, <i>c</i> is the maximum number of 500-yen coins that he can get during his trip, and <i>s</i> is the minimum expenses that he need to pay to get <i>c</i> 500-yen coins. </p> <h3>Sample Input</h3> <pre>4 800 700 1600 600 4 300 700 1600 600 4 300 700 1600 650 3 1000 2000 500 3 250 250 1000 4 1251 667 876 299 0 </pre> <h3>Output for the Sample Input</h3> <pre>2 2900 3 2500 3 3250 1 500 3 1500 3 2217 </pre>
p00733
<h1><font color="#000000">Problem F: </font>Dr. Podboq or: How We Became Asymmetric</h1> <p> After long studying how embryos of organisms become asymmetric during their development, Dr. Podboq, a famous biologist, has reached his new hypothesis. Dr. Podboq is now preparing a poster for the coming academic conference, which shows a tree representing the development process of an embryo through repeated cell divisions starting from one cell. Your job is to write a program that transforms given trees into forms satisfying some conditions so that it is easier for the audience to get the idea. </p> <!-- end en only --> <!-- begin en only --> <p> A tree representing the process of cell divisions has a form described below. </p> <ul> <li>The starting cell is represented by a circle placed at the top.</li> <li>Each cell either terminates the division activity or divides into two cells. Therefore, from each circle representing a cell, there are either no branch downward, or two branches down to its two child cells.</li> </ul> <p> Below is an example of such a tree. </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-1" border="1" /><br /> <!-- begin en only --> Figure F-1: A tree representing a process of cell divisions <!-- end en only --> </center> </p> <!-- begin en only --> <p> According to Dr. Podboq's hypothesis, we can determine which cells have stronger or weaker asymmetricity by looking at the structure of this tree representation. First, his hypothesis defines "left-right similarity" of cells as follows: </p> <ol> <li>The left-right similarity of a cell that did not divide further is 0.</li> <li>For a cell that did divide further, we collect the partial trees starting from its child or descendant cells, and count how many kinds of structures they have. Then, the left-right similarity of the cell is defined to be the ratio of the number of structures that appear both in the right child side and the left child side. We regard two trees have the same structure if we can make them have exactly the same shape by interchanging two child cells of arbitrary cells.</li> </ol> <p> For example, suppose we have a tree shown below: </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-2" border="1" /><br /> <!-- begin en only --> Figure F-2: An example tree <!-- end en only --> </center> </p> <!-- begin en only --> <p> The left-right similarity of the cell A is computed as follows. First, within the descendants of the cell B, which is the left child cell of A, the following three kinds of structures appear. Notice that the rightmost structure appears three times, but when we count the number of structures, we count it only once. </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-3" border="1" /><br /> <!-- begin en only --> Figure F-3: Structures appearing within the descendants of the cell B <!-- end en only --> </center> </p> <!-- begin en only --> <p> On the other hand, within the descendants of the cell C, which is the right child cell of A, the following four kinds of structures appear. </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-4" border="1" /><br /> <!-- begin en only --> Figure F-4: Structures appearing within the descendants of the cell C <!-- end en only --> </center> </p> <!-- begin en only --> <p> Among them, the first, second, and third ones within the B side are regarded as the same structure as the second, third, and fourth ones within the C side, respectively. Therefore, there are four structures in total, and three among them are common to the left side and the right side, which means the left-right similarity of A is 3/4. </p> <!-- end en only --> <!-- begin en only --> <p> Given the left-right similarity of each cell, Dr. Podboq's hypothesis says we can determine which of the cells <i>X</i> and <i>Y</i> has stronger asymmetricity by the following rules. </p> <ol> <li>If <i>X</i> and <i>Y</i> have different left-right similarities, the one with lower left-right similarity has stronger asymmetricity. <li>Otherwise, if neither <i>X</i> nor <i>Y</i> has child cells, they have completely equal asymmetricity. <li>Otherwise, both <i>X</i> and <i>Y</i> must have two child cells. In this case, we compare the child cell of <i>X</i> with stronger (or equal) asymmetricity (than the other child cell of <i>X</i>) and the child cell of <i>Y</i> with stronger (or equal) asymmetricity (than the other child cell of <i>Y</i>), and the one having a child with stronger asymmetricity has stronger asymmetricity.</li> <li>If we still have a tie, we compare the other child cells of <i>X</i> and <i>Y</i> with weaker (or equal) asymmetricity, and the one having a child with stronger asymmetricity has stronger asymmetricity.</li> <li>If we still have a tie again, <i>X</i> and <i>Y</i> have completely equal asymmetricity.</li> </ol> <p> When we compare child cells in some rules above, we recursively apply this rule set. </p> <!-- end en only --> <!-- begin en only --> <p> Now, your job is to write a program that transforms a given tree representing a process of cell divisions, by interchanging two child cells of arbitrary cells, into a tree where the following conditions are satisfied. </p> <ol> <li>For every cell <i>X</i> which is the starting cell of the given tree or a left child cell of some parent cell, if <i>X</i> has two child cells, the one at left has stronger (or equal) asymmetricity than the one at right.</li> <li>For every cell <i>X</i> which is a right child cell of some parent cell, if <i>X</i> has two child cells, the one at right has stronger (or equal) asymmetricity than the one at left.</li> </ol> <p> In case two child cells have equal asymmetricity, their order is arbitrary because either order would results in trees of the same shape. </p> <!-- end en only --> <!-- begin en only --> <p> For example, suppose we are given the tree in Figure F-2. First we compare B and C, and because B has lower left-right similarity, which means stronger asymmetricity, we keep B at left and C at right. Next, because B is the left child cell of A, we compare two child cells of B, and the one with stronger asymmetricity is positioned at left. On the other hand, because C is the right child cell of A, we compare two child cells of C, and the one with stronger asymmetricity is positioned at right. We examine the other cells in the same way, and the tree is finally transformed into the tree shown below. </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-5" border="1" /><br /> <!-- begin en only --> Figure F-5: The example tree after the transformation <!-- end en only --> </center> </p> <!-- begin en only --> <p> Please be warned that the only operation allowed in the transformation of a tree is to interchange two child cells of some parent cell. For example, you are not allowed to transform the tree in Figure F-2 into the tree below. </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-6" border="1" /><br /> <!-- begin en only --> Figure F-6: An example of disallowed transformation <!-- end en only --> </center> </p> <h3>Input</h3> <!-- begin en only --> <p> The input consists of <i>n</i> lines (1&le;<i>n</i>&le;100) describing <i>n</i> trees followed by a line only containing a single zero which represents the end of the input. Each tree includes at least 1 and at most 127 cells. Below is an example of a tree description. </p> <!-- end en only --> <blockquote> <tt>((x (x x)) x)</tt> </blockquote> <!-- begin en only --> <p> This description represents the tree shown in Figure F-1. More formally, the description of a tree is in either of the following two formats. </p> <blockquote> "<tt>(</tt>" &lt;description of a tree starting at the left child&gt; &lt;single space&gt; &lt;description of a tree starting at the right child&gt; ")" </blockquote> <p>or</p> <blockquote> "<tt>x</tt>" </blockquote> <p> The former is the description of a tree whose starting cell has two child cells, and the latter is the description of a tree whose starting cell has no child cell. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each tree given in the input, print a line describing the result of the tree transformation. In the output, trees should be described in the same formats as the input, and the tree descriptions must appear in the same order as the input. Each line should have no extra character other than one tree description. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> (((x x) x) ((x x) (x (x x)))) (((x x) (x x)) ((x x) ((x x) (x x)))) (((x x) ((x x) x)) (((x (x x)) x) (x x))) (((x x) x) ((x x) (((((x x) x) x) x) x))) (((x x) x) ((x (x x)) (x (x x)))) ((((x (x x)) x) (x ((x x) x))) ((x (x x)) (x x))) ((((x x) x) ((x x) (x (x x)))) (((x x) (x x)) ((x x) ((x x) (x x))))) 0 </pre> <h3>Output for the Sample Input</h3> <pre> ((x (x x)) ((x x) ((x x) x))) (((x x) ((x x) (x x))) ((x x) (x x))) (((x ((x x) x)) (x x)) ((x x) ((x x) x))) (((x ((x ((x x) x)) x)) (x x)) ((x x) x)) ((x (x x)) ((x (x x)) ((x x) x))) (((x (x x)) (x x)) ((x ((x x) x)) ((x (x x)) x))) (((x (x x)) ((x x) ((x x) x))) (((x x) (x x)) (((x x) (x x)) (x x)))) </pre>
p01821
<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: Identity Function</h2> <p> You are given an integer $N$, which is greater than 1.<br> Consider the following functions: </p> <ul> <li> $f(a) = a^N$ mod $N$ </li> <li> $F_1(a) = f(a)$</li> <li> $F_{k+1}(a) = F_k(f(a))$ $(k = 1,2,3,...)$</li> </ul> <p> Note that we use mod to represent the integer modulo operation. For a non-negative integer $x$ and a positive integer $y$, $x$ mod $y$ is the remainder of $x$ divided by $y$. </p> <p> Output the minimum positive integer $k$ such that $F_k(a) = a$ for all positive integers $a$ less than $N$. If no such $k$ exists, output -1. </p> <h3>Input</h3> <p> The input consists of a single line that contains an integer $N$ ($2 \leq N \leq 10^9$), whose meaning is described in the problem statement. </p> <h3>Output</h3> <p> Output the minimum positive integer $k$ such that $F_k(a) = a$ for all positive integers $a$ less than $N$, or -1 if no such $k$ exists. </p> <h3>Sample Input</h3> <pre> 3 </pre> <h3>Output for the Sample Input</h3> <pre> 1 </pre> <h3>Sample Input</h3> <pre> 4 </pre> <h3>Output for the Sample Input</h3> <pre> -1 </pre> <h3>Sample Input</h3> <pre> 15 </pre> <h3>Output for the Sample Input</h3> <pre> 2 </pre>
p00363
<!--<H1>Let’s Make a Flag</H1>--> <h1>Flag</h1> <p> AHK Education, the educational program section of Aizu Broadcasting Cooperation, broadcasts a children’s workshop program called "Let's Play and Make." Today’s theme is "Make your own flag." A child writes his first initial in the center of their rectangular flag. </p> <p> Given the flag size and the initial letter to be placed in the center of it, write a program to draw the flag as shown in the figure below. </p> <pre> +-------+ |.......| |...A...| |.......| +-------+ </pre> <p> The figure has "A" in the center of a flag with size 9 (horizontal) &times; 5 (vertical). </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>W</var> <var>H</var> <var>c</var> </pre> <p> The input line provides the flag dimensions <var>W</var> (width) and <var>H</var> (height) (3 &le; <var>W,H</var> &le; 21), and the initial letter <var>c</var>. Both <var>W</var> and <var>H</var> are odd numbers, and <var>c</var> is a capital letter. </p> <h2>Output</h2> <p> Draw the flag of specified size with the initial in its center using the following characters: "<span>+</span>" for the four corners of the flag, "<span>-</span>" for horizontal lines, "<span>|</span>" for vertical lines, and "<span>.</span>" for the background (except for the initial in the center). </p> <h2>Sample Input 1</h2> <pre> 3 3 B </pre> <h2>Sample Output 1</h2> <pre> +-+ |B| +-+ </pre> <h2>Sample Input 2</h2> <pre> 11 7 Z </pre> <h2>Sample Output 2</h2> <pre> +---------+ |.........| |.........| |....Z....| |.........| |.........| +---------+ </pre>
p00699
<H1> Nets of Dice </H1> <P> In mathematics, some plain words have special meanings. The word "<I>net</I>" is one of such technical terms. In mathematics, the word "<I>net</I>" is sometimes used to mean a plane shape which can be folded into some solid shape. </P> <P> The following are a solid shape (Figure 1) and one of its <I>net</I> (Figure 2). </P> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_prism"></TD><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netprism"></TD></TR> <TR><TD ALIGN=center>Figure 1: a prism</TD><TD ALIGN=center>Figure 2: a net of a prism</TD></TR> </TABLE> <P> Nets corresponding to a solid shape are not unique. For example, Figure 3 shows three of the nets of a cube. </P> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netcube"></TD></TR> <TR><TD ALIGN=center>Figure 3: examples of nets of a cube</TD></TR> </TABLE> <P> In this problem, we consider nets of dice. The definition of a die is as follows. <OL> <LI> A die is a cube, each face marked with a number between one and six. <LI> Numbers on faces of a die are different from each other. <LI> The sum of two numbers on the opposite faces is always 7. </OL> <p> Usually, a die is used in pair with another die. The plural form of the word "die" is "dice". </P> <P> Some examples of proper nets of dice are shown in Figure 4, and those of improper ones are shown in Figure 5. </P> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netdice2"></TD></TR> <TR><TD ALIGN=center>Figure 4: examples of proper nets of dice</TD></TR> </TABLE> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netdice3"></TD></TR> <TR><TD ALIGN=center>Figure 5: examples of improper nets</TD></TR> </TABLE> <P> The reasons why each example in Figure 5 is improper are as follows. <DL> <DD>(a) The sum of two numbers on the opposite faces is not always 7. <DD>(b) Some faces are marked with the same number. <DD>(c) This is not a net of a cube. Some faces overlap each other. <DD>(d) This is not a net of a cube. Some faces overlap each other and one face of a cube is not covered. <DD>(e) This is not a net of a cube. The plane shape is cut off into two parts. The face marked with '2' is isolated. <DD>(f) This is not a net of a cube. The plane shape is cut off into two parts. <DD>(g) There is an extra face marked with '5'. </DL> </P> <P> Notice that there are two kinds of dice. For example, the solid shapes formed from the first two examples in Figure 4 are mirror images of each other. </P> <P> Any net of a die can be expressed on a sheet of 5x5 mesh like the one in Figure 6. In the figure, gray squares are the parts to be cut off. When we represent the sheet of mesh by numbers as in Figure 7, squares cut off are marked with zeros. </P> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_mesh"></TD><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_matrix"></TD></TR> <TR><TD ALIGN=center>Figure 6: 5x5 mesh</TD><TD ALIGN=center>Figure 7: representation by numbers</TD></TR> </TABLE> <P> Your job is to write a program which tells the proper nets of a die from the improper ones automatically. </P> <H2>Input</H2> <P> The input consists of multiple sheets of 5x5 mesh. </P> <TABLE> <TR><TD><I>N</I></TD></TR> <TR><TD><I>Mesh</I><SUB>0</SUB></TD></TR> <TR><TD><I>Mesh</I><SUB>1</SUB></TD></TR> <TR><TD>...</TD></TR> <TR><TD><I>Mesh</I><SUB><I>N</I>-1</SUB></TD></TR> </TABLE> <P> <I>N</I> is the number of sheets of mesh. Each <I>Mesh<SUB>i</SUB></I> gives a sheet of mesh on which a net of a die is expressed. <I>Mesh<SUB>i</SUB></I> is in the following format. </P> <TABLE> <TR> <TD><I>F</I><SUB>00</SUB></TD> <TD><I>F</I><SUB>01</SUB></TD> <TD><I>F</I><SUB>02</SUB></TD> <TD><I>F</I><SUB>03</SUB></TD> <TD><I>F</I><SUB>04</SUB></TD> </TR> <TR> <TD><I>F</I><SUB>10</SUB></TD> <TD><I>F</I><SUB>11</SUB></TD> <TD><I>F</I><SUB>12</SUB></TD> <TD><I>F</I><SUB>13</SUB></TD> <TD><I>F</I><SUB>14</SUB></TD> </TR> <TR> <TD><I>F</I><SUB>20</SUB></TD> <TD><I>F</I><SUB>21</SUB></TD> <TD><I>F</I><SUB>22</SUB></TD> <TD><I>F</I><SUB>23</SUB></TD> <TD><I>F</I><SUB>24</SUB></TD> </TR> <TR> <TD><I>F</I><SUB>30</SUB></TD> <TD><I>F</I><SUB>31</SUB></TD> <TD><I>F</I><SUB>32</SUB></TD> <TD><I>F</I><SUB>33</SUB></TD> <TD><I>F</I><SUB>34</SUB></TD> </TR> <TR> <TD><I>F</I><SUB>40</SUB></TD> <TD><I>F</I><SUB>41</SUB></TD> <TD><I>F</I><SUB>42</SUB></TD> <TD><I>F</I><SUB>43</SUB></TD> <TD><I>F</I><SUB>44</SUB></TD> </TR> </TABLE> <P> Each <I>F<SUB>ij</SUB></I> is an integer between 0 and 6. They are separated by a space character. </P> <H2>Output</H2> <p> For each <I>Mesh<SUB>i</SUB></I>, the truth value, <I>true</I> or <I>false</I>, should be output, each in a separate line. When the net of a die expressed on the <I>Mesh<SUB>i</SUB></I> is proper, output "true". Otherwise, output "false". </p> <H2>Sample Input</H2> <PRE> 6 0 0 0 0 0 0 0 0 0 6 0 2 4 5 3 0 0 1 0 0 0 0 0 0 0 0 0 3 0 0 0 0 2 0 0 0 0 4 1 0 0 0 0 5 0 0 0 0 6 0 0 0 0 3 0 0 0 2 5 0 0 4 1 0 0 0 0 6 0 0 0 0 0 0 0 0 6 2 0 0 0 0 4 0 0 0 1 5 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 6 0 2 4 5 3 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 6 0 2 4 5 3 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> true true false false false false </PRE>
p00676
<h1>KND is So Sexy</h1> <h2>Problem</h2> <p>KND君は䌚接倧孊に圚籍する孊生プログラマである。圌の胞元はずおもセクシヌなこずで知られおいる。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day3_A"> </center> <br/> <p> 簡単のために胞元から芋える肌の郚分を図にある二等蟺䞉角圢ABCで衚す。しかし服にはたるみが生じおいるため、長さが等しい2蟺AC,BC(これらの長さを<var>l</var>ずする)には実際にはさらに長さ<var>x</var>分䜙裕がある。はだける郚分の面積を増やすため、たるんだ分を匕っ匵るこずで新たにふた぀の䞉角圢ADC,BECを䜜るこずにしよう。点D,Eは䞉角圢ABCの倖偎に存圚する。この新しいふた぀の䞉角圢はたるみによっお生じるもので、蟺BEず蟺ECの長さの和および蟺ADず蟺DCの長さの和は<var>l</var>+<var>x</var>でなければならない。あなたはこれら3぀の䞉角圢の面積の和<var>M</var>が最倧になるように点D,Eを決める。KND君の隣人であるあなたは圌の胞元がどれ皋セクシヌなのかを調べるために、<var>a</var>,<var>l</var>,<var>x</var>を入力ずしお服からのぞく肌の最倧の面積(<var>M</var>)を蚈算するプログラムを䜜成するこずにした。</p> <h2>Input</h2> <p> 入力は耇数のテストケヌスからなる。 ひず぀のテストケヌスは以䞋の圢匏で䞎えられる。 入力の終わりをEOFで瀺す。 </p> <pre> a l x </pre> <p> ここで、 </p> <ul> <li><var>a</var>:䞉角圢ABCの蟺ABの長さ</li> <li><var>l</var>:䞉角圢ABCの2蟺AC,BCの長さ</li> <li><var>x</var>:2蟺AC,BCにあるたるみ</li> </ul> <p> である。</p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>入力はすべお敎数。</li> <li>1 &le; <var>a</var> &le; 1000</li> <li>1 &le; <var>l</var> &le; 1000</li> <li>1 &le; <var>x</var> &le; 1000</li> </ul> <h2>Output</h2> <p>各テストケヌスに぀き最倧の面積を1行に出力せよ。この倀はゞャッゞ出力の倀ず10<sup>-5</sup>より倧きい差を持っおはならない。</p> <h2>Sample Input</h2> <pre> 2 2 1 2 3 1 3 2 3 2 3 5 </pre> <h2>Sample Output</h2> <pre> 3.9681187851 6.7970540913 6.5668891783 13.9527248554 </pre> <!-- 2012/07/09/15:19:55 -->
p03959
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of <var>N</var> mountains, extending from west to east in a straight line as Mt. <var>1</var>, Mt. <var>2</var>, ..., Mt. <var>N</var>. Mr. Takahashi traversed the range from the west and Mr. Aoki from the east. </p> <p>The height of Mt. <var>i</var> is <var>h_i</var>, but they have forgotten the value of each <var>h_i</var>. Instead, for each <var>i</var> (<var>1 ≀ i ≀ N</var>), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. <var>i</var> (including Mt. <var>i</var>). Mr. Takahashi's record is <var>T_i</var> and Mr. Aoki's record is <var>A_i</var>. </p> <p>We know that the height of each mountain <var>h_i</var> is a positive integer. Compute the number of the possible sequences of the mountains' heights, modulo <var>10^9 + 7</var>.</p> <p>Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights. In such a case, output <var>0</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^5</var></li> <li><var>1 ≀ T_i ≀ 10^9</var></li> <li><var>1 ≀ A_i ≀ 10^9</var></li> <li><var>T_i ≀ T_{i+1}</var> (<var>1 ≀ i ≀ N - 1</var>)</li> <li><var>A_i ≥ A_{i+1}</var> (<var>1 ≀ i ≀ N - 1</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>T_1</var> <var>T_2</var> <var>...</var> <var>T_N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible sequences of the mountains' heights, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 3 3 3 3 3 3 2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The possible sequences of the mountains' heights are:</p> <ul> <li><var>1, 3, 2, 2, 2</var> </li> <li><var>1, 3, 2, 1, 2</var> </li> <li><var>1, 3, 1, 2, 2</var> </li> <li><var>1, 3, 1, 1, 2</var> </li> </ul> <p>for a total of four sequences.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 1 1 2 2 3 2 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>The records are contradictory, since Mr. Takahashi recorded <var>2</var> as the highest peak after climbing all the mountains but Mr. Aoki recorded <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 3776 3776 8848 8848 8848 8848 8848 8848 8848 8848 8848 8848 8848 8848 8848 8848 8848 3776 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>884111967 </pre> <p>Don't forget to compute the number modulo <var>10^9 + 7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 17 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre> <p>Some mountain ranges consist of only one mountain.</p></section> </div> </span>
p01964
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <H1> Revenge of the Endless BFS </H1> <p> Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on a <i>directed</i> graph. An example of pseudo code of BFS is as follows: </p> <pre> 1: $current \leftarrow \{start\_vertex\}$ 2: $visited \leftarrow current$ 3: while $visited \ne$ the set of all the vertices 4: $found \leftarrow \{\}$ 5: for $u$ in $current$ 6: for each $v$ such that there is an edge from $u$ to $v$ 7: $found \leftarrow found \cup \{v\}$ 8: $current \leftarrow found \setminus visited$ 9: $visited \leftarrow visited \cup found$ </pre> <p> However, Mr. Endo apparently forgot to manage visited vertices in his code. More precisely, he wrote the following code: </p> <pre> 1: $current \leftarrow \{start\_vertex\}$ 2: while $current \ne$ the set of all the vertices 3: $found \leftarrow \{\}$ 4: for $u$ in $current$ 5: for each $v$ such that there is an edge from $u$ to $v$ 6: $found \leftarrow found \cup \{v\}$ 7: $current \leftarrow found$ </pre> <p> You may notice that for some graphs, Mr. Endo's program will not stop because it keeps running infinitely. Notice that it does not necessarily mean the program cannot explore all the vertices within finite steps. Your task here is to make a program that determines whether Mr. Endo's program will stop within finite steps for a given directed graph in order to point out the bug to him. Also, calculate the minimum number of loop iterations required for the program to stop if it is finite. Since the answer might be huge, thus print the answer modulo $10^9 +7$, which is a prime number. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $N$ $M$ $u_1$ $v_1$ : $u_M$ $v_M$ </pre> <p> The first line consists of two integers $N$ ($2 \leq N \leq 500$) and $M$ ($1 \leq M \leq 200,000$), where $N$ is the number of vertices and $M$ is the number of edges in a given directed graph, respectively. The $i$-th line of the following $M$ lines consists of two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq N$), which means there is an edge from $u_i$ to $v_i$ in the given graph. The vertex $1$ is the start vertex, i.e. $start\_vertex$ in the pseudo codes. You can assume that the given graph also meets the following conditions. </p> <ul> <li>The graph has no self-loop, i.e., $u_i \ne v_i$ for all $1 \leq i \leq M$.</li> <li>The graph has no multi-edge, i.e., $(u_i, v_i) \le (u_j, v_j)$ for all $1 \leq i < j \leq M$.</li> <li>For each vertex $v$, there is at least one path from the start vertex $1$ to $v$.</li> </ul> <H2>Output</H2> <p> If Mr. Endo's wrong BFS code cannot stop within finite steps for the given input directed graph, print '-1' in a line. Otherwise, print the minimum number of loop iterations required to stop modulo $10^9+7$. </p> <H2>Sample Input 1</H2> <pre> 4 4 1 2 2 3 3 4 4 1 </pre> <H2>Output for Sample Input 1</H2> <pre> -1 </pre> <H2>Sample Input 2</H2> <pre> 4 5 1 2 2 3 3 4 4 1 1 3 </pre> <H2>Output for Sample Input 2</H2> <pre> 7 </pre> <H2>Sample Input 3</H2> <pre> 5 13 4 2 2 4 1 2 5 4 5 1 2 1 5 3 4 3 1 5 4 5 2 3 5 2 1 3 </pre> <H2>Output for Sample Input 3</H2> <pre> 3 </pre>
p00226
<H1>ヒットアンドブロヌ</H1> <p> 倪郎君ず花子さんはヒットアンドブロヌで遊ぶこずにしたした。ヒットアンドブロヌのルヌルは、以䞋の通りです。 </p> <ul> <li> 出題者ず回答者に分かれお行う。</li> <li> 出題者は、重耇した数を含たない 4 桁の数字(正解)を決める。</li> <li> 回答者は、その 4 桁の数字(回答)を蚀い圓おる。</li> <li> 回答に察しお、出題者はヒットずブロヌの数でヒントを䞎える。</li> <li> 回答ず正解を比べお、数ず桁䜍眮の䞡方が同じであるこずをヒットず呌び、数だけが同じで桁䜍眮が異なるこずをブロヌず呌ぶ。たずえば、正解が 1234 で、回答が 1354 なら、出題者は「2 ヒット、1 ブロヌ」ずいうヒントを䞎え、正解たでこれを繰り返す。</li> <li> 出題者ず回答者は亀代しおゲヌムを行い、より少ない回答で正解を蚀い圓おた方を勝ちずする。</li> </ul> <p> 倪郎君ず花子さんは、ヒットの数ずブロヌの数をその郜床刀断するこずが少し面倒に感じおいるようです。そんな二人のために、ヒットの数ずブロヌの数が即座に分かるプログラムを䜜成しおあげたしょう。 </p> <p> 正解 <var>r</var> ず回答 <var>a</var> を入力ずし、ヒットの数ずブロヌの数を出力するプログラムを䜜成しおください。<var>r</var>、<var>a</var> はそれぞれ 0 から 9 の数字 4 ぀からなる数字の列です。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットずしお、<var>r</var> ず <var>a</var> が空癜区切りで行に䞎えられたす。 </p> <p> デヌタセットの数は 12000 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、ヒットの数ずブロヌの数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 1234 5678 1234 1354 1234 1234 1230 1023 0123 1234 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 0 2 1 4 0 1 3 0 3 </pre>
p01067
<h1>Circles and Ray</h1> <h2>Problem</h2> <p> 2次元平面䞊にそれぞれ互いに共通郚分をもたない <var>N</var> 個の円が䞎えられる。 たた、円にはそれぞれ1から <var>N</var> たでの番号が割り振られおいる。 </p> <p> あなたは、端点が1番目の円の円呚䞊にあるような半盎線を任意の数だけ蚭眮するこずができる。 どの円も1本以䞊の半盎線ずの共通郚分を持っおいるようにするためには、最䜎䜕本の半盎線を蚭眮しなければならないかを求めなさい。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>r<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>r<sub>2</sub></var> ... <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>r<sub>N</sub></var> </pre> <p> 1行目に、1぀の敎数 <var>N</var> が䞎えられる。 2行目からの <var>N</var> 行のうち <var>i</var> 行目には <var>i</var> 番目の円のx座暙、y座暙、半埄を衚す3぀の敎数 <var>x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub></var> が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <ul> <li>2 &le; <var>N</var> &le; 16</li> <li>-100 &le; <var>x<sub>i</sub></var> &le; 100 (1 &le; <var>i</var> &le; <var>N</var>)</li> <li>-100 &le; <var>y<sub>i</sub></var> &le; 100 (1 &le; <var>i</var> &le; <var>N</var>)</li> <li>1 &le; <var>r<sub>i</sub></var> &le; 100 (1 &le; <var>i</var> &le; <var>N</var>)</li> </ul> <h2>Output</h2> <p> どの円も1本以䞊の半盎線ずの共通郚分を持っおいるようにするためには最䜎䜕本の半盎線を蚭眮しなければならないかを出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 0 0 2 3 3 1 6 1 1 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 4 1 2 3 12 2 2 7 6 2 1 9 3 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> <h2>Sample Input 3</h2> <pre> 5 0 0 5 0 10 1 10 0 1 -10 0 1 0 -10 1 </pre> <h2>Sample Output 3</h2> <pre> 4 </pre>
p01437
<H1><font color="#000">Problem A:</font>Infnity Maze</H1> <p> Dr. Fukuoka has placed a simple robot in a two-dimensional maze. It moves within the maze and never goes out of the maze as there is no exit. </p> <p> The maze is made up of <i>H</i> &times; <i>W</i> grid cells as depicted below. The upper side of the maze faces north. Consequently, the right, lower and left sides face east, south and west respectively. Each cell is either empty or wall and has the coordinates of (<i>i</i>, <i>j</i>) where the north-west corner has (1, 1). The row <i>i</i> goes up toward the south and the column <i>j</i> toward the east. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_infinity_maze"> </center> <p> The robot moves on empty cells and faces north, east, south or west. It goes forward when there is an empty cell in front, and rotates 90 degrees to the right when it comes in front of a wall cell or on the edge of the maze. It cannot enter the wall cells. It stops right after moving forward by <i>L</i> cells. </p> <p> Your mission is, given the initial position and direction of the robot and the number of steps, to write a program to calculate the final position and direction of the robot. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is formatted as follows. </p> <p> <i>H W L</i><br> <i>c</i><sub>1,1</sub><i>c</i><sub>1,2</sub>...<i>c</i><sub>1,<i>W</i></sub><br> .<br> .<br> .<br> <i>c</i><sub><i>H</i>,1</sub><i>c</i><sub><i>H</i>,2</sub>...<i>c</i><sub><i>H</i>,<i>W</i></sub><br> </p> <p> The first line of a dataset contains three integers <i>H</i>, <i>W</i> and <i>L</i> (1 &le; <i>H</i>, <i>W</i> &le; 100, 1 &le; <i>L</i> &le; 10<sup>18</sup>). </p> <p> Each of the following <i>H</i> lines contains exactly <i>W</i> characters. In the <i>i</i>-th line, the <i>j</i>-th character <i>c<sub>i,j</sub></i> represents a cell at (<i>i</i>, <i>j</i>) of the maze. "<span>.</span>" denotes an empty cell. "<span>#</span>" denotes a wall cell. "<span>N</span>", "<span>E</span>", "<span>S</span>", "<span>W</span>" denote a robot on an empty cell facing north, east, south and west respectively; it indicates the initial position and direction of the robot. </p> <p> You can assume that there is at least one empty cell adjacent to the initial position of the robot. </p> <p> The end of input is indicated by a line with three zeros. This line is not part of any dataset. </p> <H2>Output</H2> <p> For each dataset, output in a line the final row, column and direction of the robot, separated by a single space. The direction should be one of the following: "<span>N</span>" (north), "<span>E</span>" (east), "<span>S</span>" (south) and "<span>W</span>" (west). </p> <p> No extra spaces or characters are allowed. </p> <H2>Sample Input</H2> <pre> 3 3 10 E.. .#. ... 5 5 19 ####. ..... .#S#. ...#. #.##. 5 5 6 #.#.. #.... ##.#. #..S. #.... 5 4 35 ..## .... .##. .#S. ...# 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 3 E 4 5 S 4 4 E 1 1 N </pre>
p00932
<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: Sweet War </h2> <p> There are two countries, Imperial Cacao and Principality of Cocoa. Two girls, Alice (the Empress of Cacao) and Brianna (the Princess of Cocoa) are friends and both of them love chocolate very much. </p> <p> One day, Alice found a transparent tube filled with chocolate balls (Figure I.1). The tube has only one opening at its top end. The tube is narrow, and the chocolate balls are put in a line. Chocolate balls are identified by integers 1, 2, . . ., $N$ where $N$ is the number of chocolate balls. Chocolate ball 1 is at the top and is next to the opening of the tube. Chocolate ball 2 is next to chocolate ball 1, . . ., and chocolate ball $N$ is at the bottom end of the tube. The chocolate balls can be only taken out from the opening, and therefore the chocolate balls must be taken out in the increasing order of their numbers. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_I1" width="360"><br> <p>Figure I.1. Transparent tube filled with chocolate balls</p> </center> <p> Alice visited Brianna to share the tube and eat the chocolate balls together. They looked at the chocolate balls carefully, and estimated that the $nutrition value$ and the $deliciousness$ of chocolate ball $i$ are $r_i$ and $s_i$, respectively. Here, each of the girls wants to maximize the sum of the deliciousness of chocolate balls that she would eat. They are sufficiently wise to resolve this conflict peacefully, so they have decided to play a game, and eat the chocolate balls according to the rule of the game as follows: </p> <ol> <li> Alice and Brianna have initial energy levels, denoted by nonnegative integers $A$ and $B$, respectively.</li> <li> Alice and Brianna takes one of the following two actions in turn: <ul> <li> <b>Pass</b>: she does not eat any chocolate balls. She gets a little hungry $-$ specifically, her energy level is decreased by 1. She cannot pass when her energy level is 0.</li> <li><b>Eat</b>: she eats the topmost chocolate ball $-$ let this chocolate ball $i$ (that is, the chocolate ball with the smallest number at that time). Her energy level is increased by $r_i$, the nutrition value of chocolate ball $i$ (and NOT decreased by 1). Of course, chocolate ball $i$ is removed from the tube. </li> </ul> <li> Alice takes her turn first.</li> <li> The game ends when all chocolate balls are eaten.</li> </ol> <p> You are a member of the staff serving for Empress Alice. Your task is to calculate the sums of deliciousness that each of Alice and Brianna can gain, when both of them play optimally. </p> <h3>Input</h3> <p> The input consists of a single test case. The test case is formatted as follows. <br> <br> $N$ $A$ $B$<br> $r_1$ $s_1$<br> $r_2$ $s_2$<br> .<br> .<br> .<br> $r_N$ $s_N$<br><br> The first line contains three integers, $N$, $A$ and $B$. $N$ represents the number of chocolate balls. $A$ and $B$ represent the initial energy levels of Alice and Brianna, respectively. The following $N$ lines describe the chocolate balls in the tube. The chocolate balls are numbered from 1 to $N$, and each of the lines contains two integers, $r_i$ and $s_i$ for $1 \leq i \leq N$. $r_i$ and $s_i$ represent the nutrition value and the deliciousness of chocolate ball $i$, respectively. The input satisfies </p> <ul> <li> $1 \leq N \leq 150$,</li> <li> $0 \leq A, B, r_i \leq 10^9$,</li> <li> $0 \leq s_i$, and</li> <li> $\sum^N_{i=1} s_i \leq 150$</li> </ul> <h3>Output</h3> <p> Output two integers that represent the total deliciousness that Alice and Brianna can obtain when they play optimally </p> <h3>Sample Input 1</h3> <pre>2 5 4 5 7 4 8</pre> <h3>Sample Output 1</h3> <pre>8 7</pre> <h3>Sample Input 2</h3> <pre>3 50 1 49 1 0 10 0 1</pre> <h3>Sample Output 2</h3> <pre>10 2</pre> <h3>Sample Input 3</h3> <pre>4 3 2 1 5 2 46 92 40 1 31</pre> <h3>Sample Output 3</h3> <pre>77 45</pre> <h3>Sample Input 4</h3> <pre>5 2 5 56 2 22 73 2 2 1 55 14 18</pre> <h3>Sample Output 4</h3> <pre>57 93</pre>
p01620
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <!-- begin en only --> <!--<h3><u>King's Inspection</u></h3>--> <!-- end en only --> <!-- begin ja only --> <h1><u>王様の芖察</u></h1> <!-- end ja only --> <!-- begin en only --> <!-- <p> English text is not available in this practice contest. </p> --> <!-- end en only --> <!-- begin ja only --> <p> ずある囜の偉い王様が、突然友奜囜の土地を芖察するこずになった。 その囜は電車が有名で、王様はいろいろな駅を芖察するずいう。 </p> <p> 電車の駅は52個あり、それぞれに倧文字か小文字のアルファベット1文字の名前が぀いおいる重なっおいる名前はない。 この電車の路線は環状になっおいお、aの駅の次はbの駅、bの駅の次はcの駅ず順に䞊んでいおz駅の次はA駅、その次はBの駅ず順に進み、Z駅の次はa駅になっお元に戻る。 単線であり、逆方向に進む電車は走っおいない。 </p> <p> ある日、新聞瀟の蚘者が王様が蚪れる駅の順番のリストを手に入れた。 </p> <p> 「dcdkIlkP 」 </p> <p> 最初にd駅を蚪れ、次にc駅、次にd駅ず順に蚪れおいくずいう。これで、偉い囜の王様を远跡取材できるず思った矢先、思わぬこずが発芚した。そのリストは、テロ察策のため暗号化されおいたのだ蚘者の仲間が、その暗号を解く鍵を入手したずいう。早速この蚘者は鍵を譲っおもらい、リストの修正にずりかかった。鍵はいく぀かの数字の列で構成されおいる。 </p> <p> 「3 1 4 5 3」 </p> <p> この数字の意味するずころは、はじめに蚪れる駅は、リストに曞いおある駅の3぀前の駅。 2番目に蚪れる駅はリストの2番目の駅の前の駅、ずいう颚に、実際蚪れる駅がリストの駅の䜕駅前かを瀺しおいる。 蚘者は修正に取りかかったが、蚪れる駅のリストの数よりも、鍵の数の方が小さい、どうするのかず仲間に聞いたずころ、最埌の鍵を぀かったら、たたはじめの鍵から順に䜿っおいけばよいらしい。 そしお蚘者はようやくリストを修正するこずができた。 </p> <p> 「abZfFijL 」 </p> <p> これでもう怖い物は無いだろう、そう思った矢先、さらに思わぬ事態が発芚した。 偉い王様は䜕日間も滞圚し、さらにそれぞれの日皋ごずにリストず鍵が存圚したのだ。 蚘者は䞊叞から、すべおのリストを埩号するように指瀺されたが、量が量だけに、圌䞀人では終わらない。 あなたの仕事は圌を助け、このリストの埩号を自動で行うプログラムを䜜成するこずである。 </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットから構成される。各デヌタセットの圢匏は次の通りである。 </p> <pre> <var>n</var> <var>k1</var> <var>k2...</var> <var>kn</var> <var>s</var> </pre> <p> n は鍵の数を衚す敎数であり、1以䞊 100 以䞋ず仮定しお良い。 続く行には鍵のリストが蚘茉されおいる。k<sub>i</sub>はi番目の鍵を瀺す。1以䞊52以䞋ず仮定しお良い。 sはアルファベット倧文字・小文字からなる文字列で、蚪れる駅のリストを瀺す。1文字以䞊100文字以䞋であるず仮定しお良い。 n=0 は入力の終わりを瀺す。これはデヌタセットには含めない。 </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットに察する埩号されたリストを各1行に出力せよ。 </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 2 1 2 bdd 3 3 2 1 DDDA 5 3 1 4 5 3 dcdkIlkP 0 </pre> <!-- begin ja only --> <!-- end ja only --> <h3>Output for Sample Input</h3> <pre> abc ABCx abZfFijL </pre> <!-- begin ja only --> <!-- end ja only -->
p01270
<h1><font color="#000">Problem D:</font> Restrictive Filesystem</h1> <p> あなたは新型蚘録媒䜓の開発チヌムに所属するプログラマヌであるこの蚘録媒䜓はデヌタの読み蟌み及び消去はランダムアクセスが可胜である䞀方デヌタを曞き蟌むずきは垞に先頭から順番にアクセスしおいき最初に芋぀かった空き領域にしか曞き蟌むこずができない </p> <p> あなたはこの蚘録媒䜓甚のファむルシステムの構築を始めたこのファむルシステムでは蚘録媒䜓の制限からデヌタは先頭の空き領域から順に曞き蟌たれる曞き蟌みの途䞭で別のデヌタが存圚する領域に至った堎合は残りのデヌタをその埌ろの空き領域から曞き蟌んでいく </p> <p> デヌタの曞き蟌みはセクタず呌ばれる単䜍で行われるセクタには 0 から始たる番号が割り圓おられおおりこの番号は蚘憶媒䜓䞊の物理的な䜍眮を指すセクタ番号は蚘憶媒䜓の先頭から埌方に向かっお順に 0123  ず割り圓おられおいる </p> <p> ファむルシステムには曞き蟌み削陀セクタの参照ずいう 3 ぀のコマンドが存圚する </p> <p> あなたの仕事はこのファむルシステムの挙動を再珟した䞊で参照コマンドが実行されたずき察象セクタにはどのファむルが配眮されおいるか出力するプログラムを曞くこずであるなお初期状態では蚘録媒䜓には䜕も曞き蟌たれおいない </p> <p> 䟋えばSample Input の最初の䟋を芋おみよう最初の呜什では 0 ずいう識別子を持ったサむズが 2 であるファむルを曞き蟌む初期状態では蚘録媒䜓には䜕も曞き蟌たれおいないすなわち党おのセクタが空き領域であるから先頭にある 2 ぀のセクタすなわち 0 番目のセクタず 1 番目のセクタに曞き蟌みが行われるしたがっお曞き蟌みの埌の蚘憶媒䜓は次のようになっおいる </p> <pre>   空 空 空 空 空 空 
 </pre> <p> 2 番目の呜什によっお1 ずいう識別子を持぀ファむルが 2 番目ず 3 番目のセクタに曞き蟌たれるこの埌の蚘憶媒䜓の状態は次のようになる </p> <pre>     空 空 空 空 
 </pre> <p> 3 番目の呜什によっお0 の識別子を持぀ファむルが削陀される蚘憶媒䜓の状態は次のようになる </p> <pre> 空 空   空 空 空 空 
 </pre> <p> 4 番目の呜什によっお2 ずいう識別子を持぀ファむルを 0 番目1 番目4 番目5 番目のセクタに曞き蟌む </p> <pre>       空 空 
 </pre> <p> 最埌の呜什では3 番目のセクタが参照されるいた3 番目のセクタには 1 ずいう識別子のファむルが配眮されおいるのであなたのプログラムは 1 ず出力しなければならない </p> <h3>Input</h3> <p> 入力は耇数のデヌタセットからなる各デヌタセットは次の圢匏で䞎えられる </p> <blockquote> <i>N</i><br> <i>Command</i><sub>1</sub><br> <i>Command</i><sub>2</sub><br> ...<br> <i>Command</i><sub><i>N</i></sub> </blockquote> <p> <i>N</i> は実行されるコマンドの数 (1 &le; <i>N</i> &le; 10,000)<i>Command</i><sub><i>i</i></sub> は <i>i</i> 番目に実行されるコマンドをそれぞれ衚す </p> <p> 各コマンドはコマンド名ず 1 ぀たたは 2 ぀の匕数からなるコマンド名は 1 ぀の文字のみからなり「W」「D」「R」のいずれかであるコマンドず匕数の間および匕数ず匕数の間はそれぞれ 1 ぀のスペヌスで区切られる </p> <p> 「W」は曞き蟌みのコマンドを衚す2 ぀の匕数 <i>I</i> (0 &le; <i>I</i> &le; 10<sup>9</sup>) ず <i>S</i> (1 &le; <i>S</i> &le; 10<sup>9</sup>) が䞎えられるそれぞれ曞き蟌むファむルの識別子ずそのファむルを蚘憶するのに必芁ずするセクタの数を瀺す </p> <p> 「D」は削陀のコマンドを衚す1 ぀の匕数 <i>I</i> (0 &le; <i>I</i> &le; 10<sup>9</sup>) が䞎えられる削陀するファむルの識別子を瀺す </p> <p> 「R」は参照のコマンドを衚す1 ぀の匕数 <i>P</i> (0 &le; <i>P</i> &le; 10<sup>9</sup>) が䞎えられる参照するセクタの番号を瀺す </p> <p> 10<sup>9</sup> よりも倧きな番号を持぀セクタにはアクセスする必芁はないず仮定しおよいたた同じファむル識別子を持぀ファむルを耇数回曞き蟌むこずはないこずが保蚌されおいる </p> <p> 入力の終わりは1 ぀の 0 を含む 1 行で瀺される </p> <h3>Output</h3> <p> 各デヌタセットに぀いお参照のコマンドが珟れるごずにそのコマンドによっお参照されたファむルの識別子を 1 行に出力せよ参照したセクタにファむルが曞き蟌たれおいなかった堎合はファむル識別子の代わりに -1 を出力せよ </p> <p> 各デヌタセットの埌には空行を入れるこず </p> <h3>Sample Input</h3> <pre> 6 W 0 2 W 1 2 D 0 W 2 4 R 3 R 1 1 R 1000000000 0 </pre> <h3>Output for the Sample Input</h3> <pre> 1 2 -1 </pre>
p00898
<H1><font color="#000">Problem E: </font>Driving an Icosahedral Rover</H1> <p> After decades of fruitless efforts, one of the expedition teams of ITO (Intersolar Tourism Organization) finally found a planet that would surely provide one of the best tourist attractions within a ten light-year radius from our solar system. The most attractive feature of the planet, besides its comfortable gravity and calm weather, is the area called <i>Mare Triangularis</i>. Despite the name, the area is not covered with water but is a great plane. Its unique feature is that it is divided into equilateral triangular sections of the same size, called <i>trigons</i>. The <i>trigons</i> provide a unique impressive landscape, a must for tourism. It is no wonder the board of ITO decided to invest a vast amount on the planet. </p> <p> Despite the expected secrecy of the staff, the Society of Astrogeology caught this information in no time, as always. They immediately sent their president's letter to the Institute of Science and Education of the Commonwealth Galactica claiming that authoritative academic inspections were to be completed before any commercial exploitation might damage the nature. </p> <p> Fortunately, astrogeologists do not plan to practice all the possible inspections on all of the <i>trigons</i>; there are far too many of them. Inspections are planned only on some characteristic <i>trigons</i> and, for each of them, in one of twenty different scientific aspects. </p> <p> To accelerate building this new tourist resort, ITO's construction machinery team has already succeeded in putting their brand-new invention in practical use. It is a rover vehicle of the shape of an <i>icosahedron</i>, a regular polyhedron with twenty faces of equilateral triangles. The machine is customized so that each of the twenty faces exactly fits each of the <i>trigons</i>. Controlling the high-tech <i>gyromotor</i> installed inside its body, the rover can roll onto one of the three <i>trigons</i> neighboring the one its bottom is on. </p> <center> <table width="480"> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1319_1"> </td> <tr> <td> <b>Figure E.1: The Rover on Mare Triangularis</b> </td> </tr> </table> </center> <p> Each of the twenty faces has its own function. The set of equipments installed on the bottom face touching the ground can be applied to the <i>trigon</i> it is on. Of course, the rover was meant to accelerate construction of the luxury hotels to host rich interstellar travelers, but, changing the installed equipment sets, it can also be used to accelerate academic inspections. </p> <p> You are the driver of this rover and are asked to move the vehicle onto the <i>trigon</i> specified by the leader of the scientific commission with the smallest possible steps. What makes your task more difficult is that the designated face installed with the appropriate set of equipments has to be the bottom. The direction of the rover does not matter. </p> <center> <table width="480"> <tr> <td align="justify"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1319_2"> </td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1319_3"> </td> <tr> <td> <b>Figure E.2:The Coordinate System </b> </td> <td align="center"> <b> Figure E.3: Face Numbering</b> </td> </tr> </table> </center> <p> The <i>trigons</i> of <i>Mare Triangularis</i> are given two-dimensional coordinates as shown in Figure E.2. Like maps used for the Earth, the <i>x</i> axis is from the west to the east, and the <i>y</i> axis is from the south to the north. Note that all the trigons with its coordinates (<i>x , y</i>) has neighboring trigons with coordinates (<i>x</i> - 1 , <i>y</i>) and (<i>x</i> + 1 , <i>y</i>). In addition to these, when <i>x</i> + <i>y</i> is even, it has a neighbor (<i>x</i> , <i>y</i> + 1); otherwise, that is, when <i>x</i> + <i>y</i> is odd, it has a neighbor (<i>x , y</i> - 1). </p> <p> Figure E.3 shows a development of the skin of the rover. The top face of the development makes the exterior. That is, if the numbers on faces of the development were actually marked on the faces of the rover, they should been readable from its outside. These numbers are used to identify the faces. </p> <p> When you start the rover, it is on the <i>trigon</i> (0,0) and the face 0 is touching the ground. The rover is placed so that rolling towards north onto the <i>trigon</i> (0,1) makes the face numbered 5 to be at the bottom. </p> <p> As your first step, you can choose one of the three adjacent <i>trigons</i>, namely those with coordinates (-1,0), (1,0), and (0,1), to visit. The bottom will be the face numbered 4, 1, and 5, respectively. If you choose to go to (1,0) in the first rolling step, the second step can bring the rover to either of (0,0), (2,0), or (1,-1). The bottom face will be either of 0, 6, or 2, correspondingly. The rover may visit any of the <i>trigons</i> twice or more, including the start and the goal <i>trigons</i>, when appropriate. </p> <p> The theoretical design section of ITO showed that the rover can reach any goal <i>trigon</i> on the specified bottom face within a finite number of steps. </p> <H2>Input</H2> <p> The input consists of a number of datasets. The number of datasets does not exceed 50. </p> <p> Each of the datasets has three integers <i>x</i>, <i>y</i>, and <i>n</i> in one line, separated by a space. Here, (x,y) specifies the coordinates of the <i>trigon</i> to which you have to move the rover, and <i>n</i> specifies the face that should be at the bottom. </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 minimum number of steps required to set the rover on the specified <i>trigon</i> with the specified face touching the ground. No other characters should appear in the output. </p> <p> You can assume that the maximum number of required steps does not exceed 100. <i>Mare Triangularis</i> is broad enough so that any of its edges cannot be reached within that number of steps. </p> <H2>Sample Input</H2> <pre> 0 0 1 3 5 2 -4 1 3 13 -13 2 -32 15 9 -50 50 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 9 30 47 100 </pre>
p00031
<H1>Weight</H1> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_weight"></center> <br/> <p> 祖母が倩秀を䜿っおいたす。倩秀は、二぀の皿の䞡方に同じ目方のものを茉せるず釣合い、そうでない堎合には、重い方に傟きたす。10 個の分銅の重さは、軜い順に 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g です。 </p> <p> 祖母は、「1kg くらいたでグラム単䜍で量れるのよ。」ず蚀いたす。「じゃあ、詊しに、ここにあるゞュヌスの重さを量っおよ」ず蚀っおみるず、祖母は巊の皿にゞュヌスを、右の皿に 8g ず64g ず128g の分銅を茉せお釣合わせおから、「分銅の目方の合蚈は 200g だから、ゞュヌスの目方は 200g ね。どう、正しいでしょう」ず答えたした。 </p> <p> 巊の皿に茉せる品物の重さを䞎えるので、倩秀で䞎えられた重みの品物ず釣合わせるずきに、右の皿に茉せる分銅を軜い順に出力するプログラムを䜜成しお䞋さい。ただし、量るべき品物の重さは、すべおの分銅の重さの合蚈 (=1023g) 以䞋ずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットに、巊の皿に茉せる品物の重さが行に䞎えられたす。入力の最埌たで凊理しお䞋さい。デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットに察しお、右の皿に茉せる分銅昇順を぀の空癜で区切っお、行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 5 7 127 </pre> <H2>Output for the Sample Input</H2> <pre> 1 4 1 2 4 1 2 4 8 16 32 64 </pre> <H2>Hint</H2> <p> 分銅の重さは 2 の <var>n</var> 乗 ( <var>n</var> = 0, 1, .... 9 )g です。 </p>
p00461
<H1> IOIOI </H1> <h2>問題</h2> <p> 敎数 <i>n</i> (1 &le; <i>n</i>) に察し, <i>n</i> + 1 個の <span>I</span> ず <i>n</i> 個の <span>O</span> を <span>I</span> から始めお亀互に䞊べおできる文字列を <i>P<sub>n</sub></I> ずする.ここで <span>I</span> ず <span>O</span> はそれぞれ英倧文字のアむずオヌである. </p> <br><center> <table> <tr><td width="40"><i>P</i><sub>1</sub></td><td><span>IOI</span></td></tr> <tr><td><i>P</i><sub>2</sub></td><td><span>IOIOI</span></td></tr> <tr><td><i>P</i><sub>3</sub></td><td><span>IOIOIOI</span></td></tr> <tr><td></td><td>.<td></tr> <tr><td></td><td>.<td></tr> <tr><td></td><td>.<td></tr> <tr><td><i>P</i><sub><i>n</i></sub></td><td><span>IOIOIO ... OI</span> (<span>O</span> が <i>n</i> 個)</td></tr> </table> <br> <p> 図 1-1 本問で考える文字列 <i>P<sub>n</sub></i> </p> </center> <br> <p> 敎数 <i>n</i> ず, I ず O のみからなる文字列 <i>s</i> が䞎えられた時, <i>s</i> の䞭に <i>P<sub>n</sub></i> が䜕ヶ所含たれおいるかを出力するプログラムを䜜成せよ. </p> <h2>䟋</h2> <p> <i>n</i> が 1, <i>s</i> が <span>OOIOIOIOIIOII</span> の堎合, <i>P</i><sub>1</sub> は <span>IOI</span> であり,䞋図 1-2 に瀺した 4ヶ所に含たれおいる.よっお,出力は 4 である. </p> <center> <span> OO<u>IOI</u>OIOIIOII<br> OOIO<u>IOI</u>OIIOII<br> OOIOIO<u>IOI</u>IOII<br> OOIOIOIOI<u>IOI</u>I<br> </span> </center> <br> <center> 図 1-2 <i>n</i> が 1, <i>s</i> が <span>OOIOIOIOIIOII</span> の堎合の䟋 </center> <br> <p> <i>n</i> が 2, <i>s</i> が <span>OOIOIOIOIIOII</span> の堎合, <i>P</i><sub>2</sub> は <span>IOIOI</span> であり,䞋図 1-3 に瀺した 2ヶ所に含たれおいる.よっお,出力は 2 である. </p> <center> <span> OO<u>IOIOI</u>OIIOII<br> OOIO<u>IOIOI</u>IOII<br> </span> </center> <br> <center> 図 1-3 <i>n</i> が 2, <i>s</i> が <span>OOIOIOIOIIOII</span> の堎合の䟋 </center> <br> <h2>入力</h2> <p> <!-- 入力ファむルのファむル名は input.txt である.<br>--> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 1 行目には敎数 <i>n</i> (1 &le; <i>n</i> &le; 1000000) が曞かれおいる.<br> 2 行目には敎数 <i>m</i> (1 &le; <i>m</i> &le; 1000000) が曞かれおいる. <i>m</i> は <i>s</i> の文字数を衚す.<br> 3 行目には文字列 <i>s</i> が曞かれおいる. <i>s</i> は <span>I</span> ず <span>O</span> のみからなる. </p> <p> 党おの採点甚デヌタで, 2<i>n</i> + 1 &le; <i>m</i> である.採点甚デヌタのうち, 配点の 50% 分に぀いおは, <i>n</i> &le; 100, <i>m</i> &le; 10000 を満たす. </p> <p> <i>n</i> が 0 のずき入力の終了を瀺す. デヌタセットの数は 10 を超えない </p> <h2>出力</h2> <p> <!-- 出力ファむルのファむル名は output.txt である.<br> output.txt は,文字列 <i>s</i> に文字列 <i>P<sub>n</sub></i> が䜕ヶ所含たれるかを衚す 1 ぀の敎数を含む 1 行からなる. --> デヌタセットごずに,文字列 <i>s</i> に文字列 <i>P<sub>n</sub></i> が䜕ヶ所含たれるかを衚す 1 ぀の敎数を1 行に出力する. <i>s</i> に <i>P<sub>n</sub></i> が含たれおいない堎合は,敎数ずしお <span>0</span> を出力せよ. </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 1 13 OOIOIOIOIIOII 2 13 OOIOIOIOIIOII 0 </pre> <h3>出力䟋</h3> <pre> 4 2 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02149
<h1>Problem A: Lunch</h1> <h2>Problem</h2> <p> ある日、川林くんは孊食で昌食を食べようずしおいたす。 孊食にはAランチ、Bランチ、Cランチの3皮類の日替わりのランチメニュヌがありたす。<br> 川林くんは食いしん坊なので3皮類の日替わりのランチメニュヌをすべお1぀ず぀食べたいず思っおいたす。<br> しかし、川林くんは健康に気を䜿っお摂取するカロリヌの合蚈が最小になるように1皮類のランチメニュヌを我慢し、異なる2皮類のランチメニュヌを食べるこずにしたした。<br> ある日のAランチ、Bランチ、Cランチのカロリヌが䞎えられた時、川林くんが我慢するこずになるランチメニュヌを求めおください。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $a$ $b$ $c$ </pre> <p> 3぀の敎数$a$, $b$, $c$が空癜区切りで䞎えられる。それぞれ、ある日のAランチ、Bランチ、Cランチのカロリヌを衚しおいる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq a, b, c \leq 5000 $</li> <li>$a \neq b, b \neq c, c \neq a$</li> </ul> <h2>Output</h2> <p> 川林くんが我慢するこずになるメニュヌ名を1行に出力せよ。<br> Aランチを我慢する堎合は"A"<br> Bランチを我慢する堎合は"B"<br> Cランチを我慢する堎合は"C"<br> ず出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 1000 900 850 </pre> <h2>Sample Output 1</h2> <pre> A </pre> <h2>Sample Input 2</h2> <pre> 1000 800 1200 </pre> <h2>Sample Output 2</h2> <pre> C </pre>
p00174
<H1>バドミントン</H1> <p> A君、Bさん、C君で久しぶりに遊ぶこずになりたした。 A君ずBさんがプレむダヌ、C君が審刀になりバドミントンのシングルスのゲヌムをしたした。3人で決めたルヌルは以䞋の通りです。 </p> <ul> <li>3 ゲヌムを行いたす。</li> <li>11 点を先取した人が、そのゲヌムの勝者ずなりたす。</li> <li>第 1 ゲヌムの最初のサヌブはA君から始たりたすが、次のサヌブは盎前のポむントを取った人が行いたす。</li> <li>第 2 ゲヌム、第 3 ゲヌムは前のゲヌムを取った人が最初のサヌブを行いたす。</li> <li>10 - 10 になっお以降は 2 点差を぀けた人が勝者ずなりたす。</li> </ul> <p> 党おのゲヌムが終わり、埗点を芋ようずしたのですが、審刀のC君が埗点を蚘録するのを忘れおいたした。しかし、サヌブを打った人をきちんず蚘録しおいたした。サヌブ順の蚘録から埗点を蚈算するプログラムを䜜成しおください。ただし、二人が打ったサヌブの回数の合蚈は 100 以䞋ずし、サヌブ順の蚘録は、サヌブを打った人を衚す "A" たたは "B" の文字列で衚されたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺された す。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>record<sub>1</sub></var> <var>record<sub>2</sub></var> <var>record<sub>3</sub></var> </pre> <p> <var>i</var> 行目に第 <var>i</var> ゲヌムのサヌブ順を衚す文字列が䞎えられたす。 </p> <p> デヌタセットの数は 20 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に、<var>i</var> 行目に第 <var>i</var> ゲヌムのA君の埗点ずBさんの埗点を空癜区切りで出力しおください。 </p> <H2>Sample Input</H2> <pre> ABAABBBAABABAAABBAA AABBBABBABBAAABABABAAB BABAABAABABABBAAAB AABABAAABBAABBBABAA AAAAAAAAAAA ABBBBBBBBBB 0 </pre> <H2>Output for the Sample Input</H2> <pre> 11 8 10 12 11 7 11 8 11 0 0 11 </pre>