question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p03673
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer sequence of length <var>n</var>, <var>a_1, ..., a_n</var>. Let us consider performing the following <var>n</var> operations on an empty sequence <var>b</var>.</p> <p>The <var>i</var>-th operation is as follows:</p> <ol> <li>Append <var>a_i</var> to the end of <var>b</var>.</li> <li>Reverse the order of the elements in <var>b</var>.</li> </ol> <p>Find the sequence <var>b</var> obtained after these <var>n</var> operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq n \leq 2\times 10^5</var></li> <li><var>0 \leq a_i \leq 10^9</var></li> <li><var>n</var> and <var>a_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>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 <var>n</var> integers in a line with spaces in between. The <var>i</var>-th integer should be <var>b_i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 2 1 3 </pre> <ul> <li>After step 1 of the first operation, <var>b</var> becomes: <var>1</var>.</li> <li>After step 2 of the first operation, <var>b</var> becomes: <var>1</var>.</li> <li>After step 1 of the second operation, <var>b</var> becomes: <var>1, 2</var>.</li> <li>After step 2 of the second operation, <var>b</var> becomes: <var>2, 1</var>.</li> <li>After step 1 of the third operation, <var>b</var> becomes: <var>2, 1, 3</var>.</li> <li>After step 2 of the third operation, <var>b</var> becomes: <var>3, 1, 2</var>.</li> <li>After step 1 of the fourth operation, <var>b</var> becomes: <var>3, 1, 2, 4</var>.</li> <li>After step 2 of the fourth operation, <var>b</var> becomes: <var>4, 2, 1, 3</var>.</li> </ul> <p>Thus, the answer is <code>4 2 1 3</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 1 2 </pre> <p>As shown above in Sample Output 1, <var>b</var> becomes <var>3, 1, 2</var> after step 2 of the third operation. Thus, the answer is <code>3 1 2</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 0 6 7 6 7 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 6 6 0 7 7 </pre></section> </div> </span>
p02432
<h1>Deque</h1> <p> For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations: </p> <ul> <li>push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$.</li> <li>randomAccess($p$): Print element $a_p$.</li> <li>pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$.</li> </ul> <p> $A$ is a 0-origin array and it is empty in the initial state. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $q$ $query_1$ $query_2$ : $query_q$ </pre> <p> Each query $query_i$ is given by </p> <pre> 0 $d$ $x$ </pre> <p>or</p> <pre> 1 $p$ </pre> <p>or</p> <pre> 2 $d$ </pre> <p> where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent push, randomAccess and pop operations respectively. </p> <p> randomAccess and pop operations will not be given for an empty array. </p> <h2>Output</h2> <p> For each randomAccess, print $a_p$ in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq q \leq 400,000$</li> <li>$0 \leq p < $ the size of $A$</li> <li>$-1,000,000,000 \leq x \leq 1,000,000,000$</li> </ul> <h2>Sample Input 1</h2> <pre> 11 0 0 1 0 0 2 0 1 3 1 0 1 1 1 2 2 0 2 1 0 0 4 1 0 1 1 </pre> <h2>Sample Output 1</h2> <pre> 2 1 3 4 1 </pre>
p02598
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> logs of lengths <var>A_1,A_2,\cdots A_N</var>.</p> <p>We can cut these logs at most <var>K</var> times in total. When a log of length <var>L</var> is cut at a point whose distance from an end of the log is <var>t</var> <var>(0&lt;t&lt;L)</var>, it becomes two logs of lengths <var>t</var> and <var>L-t</var>.</p> <p>Find the shortest possible length of the longest log after at most <var>K</var> cuts, and print it after rounding up to an integer.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>0 \leq K \leq 10^9</var></li> <li><var>1 \leq A_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>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <ul> <li>First, we will cut the log of length <var>7</var> at a point whose distance from an end of the log is <var>3.5</var>, resulting in two logs of length <var>3.5</var> each.</li> <li>Next, we will cut the log of length <var>9</var> at a point whose distance from an end of the log is <var>3</var>, resulting in two logs of length <var>3</var> and <var>6</var>.</li> <li>Lastly, we will cut the log of length <var>6</var> at a point whose distance from an end of the log is <var>3.3</var>, resulting in two logs of length <var>3.3</var> and <var>2.7</var>.</li> </ul> <p>In this case, the longest length of a log will be <var>3.5</var>, which is the shortest possible result. After rounding up to an integer, the output should be <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>292638192 </pre></section> </div> </span>
p02062
<h2>C: 短絡評䟡</h2> <h3>問題</h3> <p> 盎倧くんず北倧くんはゲヌムをしおいたす。 北倧くんは、たず以䞋の BNF で衚される論理匏を生成したす。 </p> <pre> &lt;formula&gt; ::= &lt;or-expr&gt; &lt;or-expr&gt; ::= &lt;and-expr&gt; | &lt;or-expr&gt; "|" &lt;and-expr&gt; &lt;and-expr&gt; ::= &lt;term&gt; | &lt;and-expr&gt; "&amp;" &lt;term&gt; &lt;term&gt; ::= "(" &lt;or-expr&gt; ")" | "?" </pre> <p> <code>&amp;</code> は論理積を、<code>|</code> は論理和を衚し、<code>&amp;</code> の方が <code>|</code> より先に評䟡されたす。 </p> <p>盎倧くんは、この論理匏を文字列ずしお芋お巊から読んでいき、<code>?</code> を芋぀けたずき以䞋の行動をしたす。</p> <ul> <li>その <code>?</code> を <code>0</code> にしおも <code>1</code> にしおも論理匏の評䟡結果が倉わらないこずが確定しおいるなら、䜕もせず読み進める。</li> <li>そうでないなら、北倧くんに 1 円払い、その <code>?</code> を <code>0</code> たたは <code>1</code> に曞き換える。</li> </ul> <p>論理匏は以䞋のように評䟡されたす。いわゆる普通の論理匏です。</p> <pre> (0 &amp; ?) == 0 (1 &amp; 0) == 0 (1 &amp; 1) == 1 (0 | 0) == 0 (0 | 1) == 1 (1 | ?) == 1 </pre> <p>盎倧くんが論理匏の評䟡結果を確定させるために支払う必芁がある最小金額はいくらでしょう 評䟡結果を <code>0</code> にする堎合ず <code>1</code> にする堎合でそれぞれ求めおください。</p> <h3>入力圢匏</h3> <p>䞊の BNF に埓う論理匏が䞀行で䞎えられたす。</p> <h3>制玄</h3> <p>論理匏の長さは <var>2\times 10^5</var> を超えない。</p> <h3>出力圢匏</h3> <p>評䟡結果を <code>0</code>、<code>1</code> にするために必芁な最小金額を空癜区切りで出力しおください。</p> <h3>入力䟋1</h3> <pre>?&amp;?|?&amp;?|?&amp;?</pre> <h3>出力䟋1</h3> <pre>3 2</pre> <p> <code>0</code> にしたい堎合は <code>0 0 0</code> で曞き換えお <code>0&amp;?|0&amp;?|0&amp;?</code> ずし、 <code>1</code> にしたい堎合は <code>1 1</code> で曞き換えお <code>1&amp;1|?&amp;?|?&amp;?</code> ずするのが最適です。 </p> <h3>入力䟋2</h3> <pre>?&amp;?&amp;?|?&amp;?&amp;?</pre> <h3>出力䟋2</h3> <pre>2 3</pre> <p>それぞれ <code>0&amp;?&amp;?|0&amp;?&amp;?</code>、<code>1&amp;1&amp;1|?&amp;?&amp;?</code> ずなりたす。</p> <h3>入力䟋3</h3> <pre>(?|?|?)&amp;?&amp;?&amp;?&amp;?|?&amp;?|?&amp;?</pre> <h3>出力䟋3</h3> <pre>4 4</pre>
p02577
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>An integer <var>N</var> is a multiple of <var>9</var> if and only if the sum of the digits in the decimal representation of <var>N</var> is a multiple of <var>9</var>.</p> <p>Determine whether <var>N</var> is a multiple of <var>9</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq N &lt; 10^{200000}</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 multiple of <var>9</var>, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>123456789 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>The sum of these digits is <var>1+2+3+4+5+6+7+8+9=45</var>, which is a multiple of <var>9</var>, so <var>123456789</var> is a multiple of <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 </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>31415926535897932384626433832795028841971693993751058209749445923078164062862089986280 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre></section> </div> </span>
p02127
<h1>Problem D: AABABCAC</h1> <h2>Problem</h2> <p> 文字列$s$,$t$が䞎えられる。<br> 最初、文字列集合$A=${$s$},$B=\phi$ずする。<br> このずき、次の操䜜をできるだけたくさん行いたい。 </p> <h3>操䜜</h3> <p> <h4>step1</h4> 党おの $u ∊ A$ に぀いお、以䞋の凊理を行う。 </p> <ol> <li>$u$の党おの郚分列(連続でなくおもよい)から、$t$ず等しいものを任意に1぀遞ぶ。遞んだ郚分列の$u$に察応するむンデックスをそれぞれ$z_1$, $z_2$, 
, $z_{|t|}$ずする(ただし1 $\le$ $z_1$ $\lt$ $z_2$ $\lt$ 
 $\lt$ $z_{|t|}$ $\le$ $|u|$)。そのような郚分列がなければ操䜜を終了する。 </li><br> <li>遞んだ郚分列の文字$u_{z_1}$, $u_{z_2}$, 
, $u_{z_{|t|}}$でもずの文字列を分割し、それらを$B$に远加する。 </li><br> 䟋えば、$u=$"abcdcd", $t=$"ac"の堎合は次の2通りの分割の方法が考えられる。<br> $u$の1番目の文字ず3番目の文字を遞んだ堎合、""ず"b"ず"dcd"に分割される。<br> $u$の1番目の文字ず5番目の文字を遞んだ堎合、""ず"bcd"ず"d"に分割される。 </ol> <p> <h4>step2</h4> $A$を$B$に眮き換え、$B$を空にする。<br> 操䜜回数を1増やす。 </p> <h3>郚分列の䟋</h3> <p> "abac"の郚分列は、 { "" , "a" , "b" , "c" , "aa" ,"ab" , "ac" , "ba" , "bc" , "aac" , "aba" , "abc" , "bac" , "abac" } である。<br> "a"は"abac"の1文字目、たたは3文字目を抜き出すこずによっおできた郚分列である。<br> "ac"は"abac"の1文字目ず4文字目、たたは3文字目ず4文字目を抜き出すこずによっおできた郚分列である。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $s$ $t$ </pre> <p>1行目に文字列$s$,2行目に文字列$t$が䞎えられる。</p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 $\le$ $|t|$ $\le$ $|s|$ $\le$ $10^5$</li> <li>文字列$s$,$t$に含たれる文字はアルファベットの倧文字たたは小文字</li> </ul> <h2>Output</h2> <p> 操䜜回数の最倧倀を出力せよ。 </p> <h2>Sample Input 1</h2> <pre> AABABCAC A </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <p> 1回目の操䜜は、$A=${ "AABABCAC" }で始たる。<br> step1では、$u=$"AABABCAC"に察しお、䟋えば4番目の文字を$t$ず等しい郚分列ずしお遞び、"AAB"ず"BCAC"に分割し、それらを$B$に远加する。<br> step2では、$A$を$B$に眮き換え、$B$を空にし、操䜜回数は1ずなる。<br><br> 2回目の操䜜は、$A=${ "AAB" , "BCAC" }で始たる。<br> step1では、$u=$"AAB"に察しお、䟋えば1番目の文字を$t$ず等しい郚分列ずしお遞び、""ず"AB"に分割し、それらを$B$に远加する。次に$u=$"BCAC"に察しお、3番目の文字を$t$ず等しい郚分列ずしお遞び、"BC"ず"C"に分割し、それらを$B$に远加する。<br> step2では、$A$を$B$に眮き換え、$B$を空にし、操䜜回数は2ずなる。<br><br> 3回目の操䜜は、$A=${ "" , "AB" , "BC" , "C" }で始たる。<br> step1では、$u=$""に察しお、$t$ず等しい郚分列が存圚しないため、ここで操䜜を終了する。<br><br> この䟋の堎合、3回目の操䜜ではstep1で操䜜が終了したため、操䜜回数は2ずなる。 </p> <h2>Sample Input 2</h2> <pre> abaabbabaabaabbabbabaabbab ab </pre> <h2>Sample Output 2</h2> <pre> 3 </pre> <h2>Sample Input 3</h2> <pre> AbCdEfG aBcDeFg </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p03366
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> apartments along a number line, numbered <var>1</var> through <var>N</var>. Apartment <var>i</var> is located at coordinate <var>X_i</var>. Also, the office of AtCoder Inc. is located at coordinate <var>S</var>. Every employee of AtCoder lives in one of the <var>N</var> apartments. There are <var>P_i</var> employees who are living in Apartment <var>i</var>.</p> <p>All employees of AtCoder are now leaving the office all together. Since they are tired from work, they would like to get home by the company's bus. AtCoder owns only one bus, but it can accommodate all the employees. This bus will leave coordinate <var>S</var> with all the employees and move according to the following rule:</p> <ul> <li> <p>Everyone on the bus casts a vote on which direction the bus should proceed, positive or negative. (The bus is autonomous and has no driver.) Each person has one vote, and abstaining from voting is not allowed. Then, the bus moves a distance of <var>1</var> in the direction with the greater number of votes. If a tie occurs, the bus moves in the negative direction. If there is an apartment at the coordinate of the bus after the move, all the employees who live there get off.</p> </li> <li> <p>Repeat the operation above as long as there is one or more employees on the bus.</p> </li> </ul> <p>For a specific example, see Sample Input 1.</p> <p>The bus takes one seconds to travel a distance of <var>1</var>. The time required to vote and get off the bus is ignorable.</p> <p>Every employee will vote so that he himself/she herself can get off the bus at the earliest possible time. Strictly speaking, when a vote is taking place, each employee see which direction results in the earlier arrival at his/her apartment, assuming that all the employees follow the same strategy in the future. Based on this information, each employee makes the optimal choice, but if either direction results in the arrival at the same time, he/she casts a vote to the negative direction.</p> <p>Find the time the bus will take from departure to arrival at the last employees' apartment. It can be proved that, given the positions of the apartments, the numbers of employees living in each apartment and the initial position of the bus, the future movement of the bus is uniquely determined, and the process will end in a finite time.</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 S \leq 10^9</var></li> <li><var>1 \leq X_1 &lt; X_2 &lt; ... &lt; X_N \leq 10^9</var></li> <li><var>X_i \neq S</var> ( <var>1 \leq i \leq N</var> )</li> <li><var>1 \leq P_i \leq 10^9</var> ( <var>1 \leq i \leq N</var> )</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> <var>X_1</var> <var>P_1</var> <var>X_2</var> <var>P_2</var> <var>:</var> <var>X_N</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of seconds the bus will take from departure to arrival at the last employees' apartment.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 3 3 4 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>Assume that the bus moves in the negative direction first. Then, the coordinate of the bus changes from <var>2</var> to <var>1</var>, and the employees living in Apartment <var>1</var> get off. The movement of the bus after that is obvious: it just continues moving in the positive direction. Thus, if the bus moves in the negative direction first, the coordinate of the bus changes as <var>2 → 1 → 2 → 3 → 4</var> from departure. The time it takes to get home for the employees living in Apartment <var>1</var>, <var>2</var>, <var>3</var> are <var>1</var>, <var>3</var>, <var>4</var> seconds, respectively.</p> <p>Next, assume that the bus moves in the positive direction first. Then, the coordinate of the bus changes from <var>2</var> to <var>3</var>, and the employees living in Apartment <var>2</var> get off. Afterwards, the bus starts heading to Apartment <var>1</var>, because there are more employees living in Apartment <var>1</var> than in Apartment <var>3</var>. Then, after arriving at Apartment <var>1</var>, the bus heads to Apartment <var>3</var>. Thus, if the bus moves in the positive direction first, the coordinate of the bus changes as <var>2 → 3 → 2 → 1 → 2 → 3 → 4</var> from departure. The time it takes to get home for the employees living in Apartment <var>1</var>, <var>2</var>, <var>3</var> are <var>3</var>, <var>1</var>, <var>6</var> seconds, respectively.</p> <p>Therefore, in the beginning, the employees living in Apartment <var>1</var> or <var>3</var> will try to move the bus in the negative direction. On the other hand, the employees living in Apartment <var>2</var> will try to move the bus in the positive direction in the beginning. There are a total of <var>3 + 2 = 5</var> employees living in Apartment <var>1</var> and <var>3</var> combined, which is more than those living in Apartment <var>2</var>, which is <var>4</var>. Thus, the bus will move in the negative direction first, and the coordinate of the bus will change as <var>2 → 1 → 2 → 3 → 4</var> from departure.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 4 1 10 2 1000 3 100000 5 1000000 6 10000 7 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>21 </pre> <p>Since the numbers of employees living in different apartments are literally off by a digit, the bus consistently head to the apartment where the most number of employees on the bus lives.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>15 409904902 94198000 15017 117995501 7656764 275583856 313263626 284496300 356635175 324233841 607 360631781 148 472103717 5224 497641071 34695 522945827 816241 554305668 32 623788284 22832 667409501 124410641 876731548 12078 904557302 291749534 918215789 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2397671583 </pre></section> </div> </span>
p00819
<H1><font color="#000">Problem A:</font> Unreliable Messengers</H1> <p> The King of a little Kingdom on a little island in the Pacific Ocean frequently has childish ideas. One day he said, “You shall make use of a message relaying game when you inform me of something.” In response to the King’s statement, six servants were selected as messengers whose names were Mr. J, Miss C, Mr. E, Mr. A, Dr. P, and Mr. M. They had to relay a message to the next messenger until the message got to the King. </p> <p> Messages addressed to the King consist of digits (‘0’-‘9’) and alphabet characters (‘a’-‘z’, ‘A’-‘Z’). Capital and small letters are distinguished in messages. For example, “ke3E9Aa” is a message. </p> <p> Contrary to King’s expectations, he always received wrong messages, because each messenger changed messages a bit before passing them to the next messenger. Since it irritated the King, he told you who are the Minister of the Science and Technology Agency of the Kingdom, “We don’t want such a wrong message any more. You shall develop software to correct it!” In response to the King’s new statement, you analyzed the messengers’ mistakes with all technologies in the Kingdom, and acquired the following features of mistakes of each messenger. A surprising point was that each messenger made the same mistake whenever relaying a message. The following facts were observed. </p> <p> Mr. J rotates all characters of the message to the left by one. For example, he transforms “aB23d” to “B23da”. </p> <p> Miss C rotates all characters of the message to the right by one. For example, she transforms “aB23d” to “daB23”. </p> <p> Mr. E swaps the left half of the message with the right half. If the message has an odd number of characters, the middle one does not move. For example, he transforms “e3ac” to “ace3”, and “aB23d” to “3d2aB”. </p> <p> Mr. A reverses the message. For example, he transforms “aB23d” to “d32Ba”. </p> <p> Dr. P increments by one all the digits in the message. If a digit is ‘9’, it becomes ‘0’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB34d”, and “e9ac” to “e0ac”. </p> <p> Mr. M decrements by one all the digits in the message. If a digit is ‘0’, it becomes ‘9’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB12d”, and “e0ac” to “e9ac”. </p> <p> The software you must develop is to infer the original message from the final message, given the order of the messengers. For example, if the order of the messengers is A -> J -> M -> P and the message given to the King is “aB23d”, what is the original message? According to the features of the messengers’ mistakes, the sequence leading to the final message is </p> <pre> A J M P “32Bad” --> “daB23” --> “aB23d” --> “aB12d” --> “aB23d”. </pre> <p> As a result, the original message should be “32Bad”. </p> <H2>Input</H2> <p> The input format is as follows. </p> <pre><i> n The order of messengers The message given to the King . . . The order of messengers The message given to the King </pre></i> <p> The first line of the input contains a positive integer n, which denotes the number of data sets. Each data set is a pair of the order of messengers and the message given to the King. The number of messengers relaying a message is between 1 and 6 inclusive. The same person may not appear more than once in the order of messengers. The length of a message is between 1 and 25 inclusive. </p> <H2>Output</H2> <p> The inferred messages are printed each on a separate line. </p> <H2>Sample Input</H2> <pre> 5 AJMP aB23d E 86AE AM 6 JPEM WaEaETC302Q CP rTurnAGundam1isdefferentf </pre> <H2>Output for the Sample Input</H2> <pre> 32Bad AE86 7 EC302QTWaEa TurnAGundam0isdefferentfr </pre>
p02824
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>N</var> problems are proposed for an upcoming contest. Problem <var>i</var> has an initial integer score of <var>A_i</var> points.</p> <p><var>M</var> judges are about to vote for problems they like. Each judge will choose exactly <var>V</var> problems, independently from the other judges, and increase the score of each chosen problem by <var>1</var>.</p> <p>After all <var>M</var> judges cast their vote, the problems will be sorted in non-increasing order of score, and the first <var>P</var> problems will be chosen for the problemset. Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge.</p> <p>How many problems out of the given <var>N</var> have a chance to be chosen for the problemset?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \le N \le 10^5</var></li> <li><var>1 \le M \le 10^9</var></li> <li><var>1 \le V \le N - 1</var></li> <li><var>1 \le P \le N - 1</var></li> <li><var>0 \le A_i \le 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>M</var> <var>V</var> <var>P</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 problems that have a chance to be chosen for the problemset.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 1 2 2 2 1 1 3 0 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>If the only judge votes for problems <var>2</var> and <var>5</var>, the scores will be <var>2</var> <var>2</var> <var>1</var> <var>3</var> <var>1</var> <var>2</var>. The problemset will consist of problem <var>4</var> and one of problems <var>1</var>, <var>2</var>, or <var>6</var>.</p> <p>If the only judge votes for problems <var>3</var> and <var>4</var>, the scores will be <var>2</var> <var>1</var> <var>2</var> <var>4</var> <var>0</var> <var>2</var>. The problemset will consist of problem <var>4</var> and one of problems <var>1</var>, <var>3</var>, or <var>6</var>.</p> <p>Thus, problems <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, and <var>6</var> have a chance to be chosen for the problemset. On the contrary, there is no way for problem <var>5</var> to be chosen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 5 2 2 1 1 3 0 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>Only problems <var>1</var>, <var>4</var>, and <var>6</var> have a chance to be chosen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 4 8 5 7 2 3 6 1 6 5 4 6 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p03736
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> squares in a row. The squares are numbered <var>1, 2, ..., N</var> from left to right.</p> <p>You have two pieces, initially placed on square <var>A</var> and <var>B</var>, respectively. You will be asked to process <var>Q</var> queries of the following kind, in the order received:</p> <ul> <li>Given an integer <var>x_i</var>, move one of the two pieces of your choice to square <var>x_i</var>.</li> </ul> <p>Here, it takes you one second to move a piece one square. That is, the time it takes to move a piece from square <var>X</var> to <var>Y</var> is <var>|X-Y|</var> seconds.</p> <p>Your objective is to process all the queries in the shortest possible time.</p> <p>You may only move the pieces in response to queries, and you may not move both pieces at the same time. Also, it is not allowed to rearrange the order in which queries are given. It is, however, allowed to have both pieces in the same square at the same time.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N, Q ≀ 200,000</var></li> <li><var>1 ≀ A, B ≀ N</var></li> <li><var>1 ≀ x_i ≀ N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>A</var> <var>B</var> <var>x_1</var> <var>x_2</var> ... <var>x_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Let the shortest possible time to process all the queries be <var>X</var> seconds. Print <var>X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 3 1 8 3 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>All the queries can be processed in seven seconds, by:</p> <ul> <li>moving the piece at square <var>1</var> to <var>3</var></li> <li>moving the piece at square <var>8</var> to <var>5</var></li> <li>moving the piece at square <var>3</var> to <var>1</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 2 1 9 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p>The piece at square <var>9</var> should be moved first.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 2 1 9 5 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre> <p>The piece at square <var>1</var> should be moved first.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>11 16 8 1 1 1 5 1 11 4 5 2 5 3 3 3 5 5 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>21 </pre></section> </div> </span>
p00233
<H1>図曞敎理</H1> <p> 数の衚わし方には色々な皮類があり、私たちが普段䜿っおいる 10 進数は䞀぀の代衚的なものでしかありたせん。コンピュヌタ関連の知識がある人には、2 進数、16 進数あたりはずおも身近なものです。 </p> <p> N さんは叞曞資栌を掻かしお叞曞の仕事に就きたした。最初の仕事は図曞敎理です。この図曞通では、䞀冊ごずに䞀貫しお番号が䞎えられおおり、それに埓っお本を敎理しおいたす。 </p> <p> この図曞通では本の番号をマむナス十進数で衚すこずになっおいたす。 </p> <p> マむナス十進数は、<var>a<sub>n</sub>a<sub>n&minus;1</sub>a<sub>n&minus;2</sub></var>...<var>a<sub>2</sub>a<sub>1</sub>a<sub>0</sub></var> (各<var>a<sub>i</sub></var> は 0~9 の数字) ず衚蚘する方法であり、この数は次の数を衚したす。 </p> <p> <var>a<sub>n</sub>&times;(&minus;10)<sup>n</sup> + a<sub>n&minus;1</sub>&times;(&minus;10)<sup>n&minus;1</sup> +</var> ... <var>+ a<sub>2</sub>&times;(&minus;10)<sup>2</sup> + a<sub>1</sub>&times;(&minus;10)<sup>1</sup> + a<sub>0</sub>&times;(&minus;10)<sup>0</sup></var> </p> <p> たずえば、マむナス十進数の 2156 は、以䞋のずおり十進数の-1944 に察応しおいたす。 </p> <p> 2&times;(-10)<sup>3</sup> + 1&times;(-10)<sup>2</sup> + 5&times;(-10)<sup>1</sup> + 6&times;(-10)<sup>0</sup> = <br> 2&times;(-1000) + 1&times;(100) + 5&times;(-10) + 6&times;(1) = <br> -2000 + 100 - 50 + 6 = -1944 </p> <p> 十進数の番号をマむナス十進数に盎すのは倧倉なので、N さんは倧倉䞍自由な思いをしおいたす。 </p> <p> 本の番号を入力ずし、 この番号のマむナス十進数衚蚘を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。各デヌタセットずしお、本の番号を衚す敎数 <var>A</var> (-2<sup>31</sup> &le; <var>A</var> &lt; 2<sup>31</sup>) が行に䞎えられたす。 </p> <p> デヌタセットの数は 1200 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、番号のマむナス十進数衚蚘を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 9 10 -10 -1944 -305432133 0 </pre> <H2>Output for the Sample Input</H2> <pre> 9 190 10 2156 1715573947 </pre>
p00663
<H1>Problem E: SAT-EN-3</H1> <p> 圌女は悩んでいた。成瞟が良くないのだ。䞡芪に無理を蚀っお党寮制の孊校に入孊したものの、圌女の才胜は䞀向に開花するこずはなかった。あるいは才胜など元々なかったのかもしれないが、それはできるだけ考えたくない可胜性だった。 </p> <p> そこで圌女が頌ったのは、むンタヌネット䞊で芋぀けた怪しげな脳力トレヌニングの教材だった。SAT-EN-3 (SATisifiability problem for Enhancement of Neuron: version 3) ず銘打぀その孊習メ゜ッドによるず、充足可胜性問題のようなもののむンスタンスをひたすら手で解くこずによっお、蚈算力が向䞊し、匕いおは論理的思考力・盎感力・想像力も豊かになり、郚掻動でも掻躍できお恋愛もうたくいくのだずいう。さすがに最埌の2぀は眉唟ものじゃないかな、ず圌女は思ったが、゜ロバンや癟マス蚈算のような䟋もあるこずだ。暗算が埗意になったら儲けものかな、ぐらいの気楜さで、圌女はこの教材に取り組んでみるこずにした。 </p> <p> SAT-EN-3では、加法暙準圢で衚される論理匏の各倉数に適切に割り圓お、論理匏の倀を真にするこずができるかどうか刀定しなければならない。ちなみに、1぀以䞊の倉数 (たたは、その吊定) の論理積を 節 (clause) ず呌び、いく぀かの節の論理和で衚される論理匏のみが加法暙準圢に埓っおいる。䞀般に充足可胜性問題ずいえば論理匏は乗法暙準圢で衚されるが、SAT-EN-3では加法暙準圢であるこずに泚意せよ。 </p> <p> 圌女はしばらく SAT-EN-3 の問題集に取り組もうずしお、ふず思い盎した。問題集にお金を払うぐらいなら、プログラミングが埗意な芪友にパフェでもご銳走しお、 SAT-EN-3 の問題を生成し、解くプログラムを曞いおもらおう。そうすれば問題も解答もいくらでも手にはいるじゃないか。 </p> <p> こうしお圌女の芪友であるあなたは、SAT-EN-3を解くプログラムを曞くこずになったのである。 </p> <h2>Input</h2> <p> 入力は耇数のケヌスからなる。 各ケヌスは以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>expression</i> </pre> <p> 入力の終わりは<b>"#"</b>からなる行によっお䞎えられる </p> <p> <i>expression</i>は以䞋のBNFに埓う。<br> ここでは文字列リテラルを""を甚いお囲んでいる。 実際の入力に""は含たれない。 たた入力には䜙蚈な空癜は含たれおいない。 </p> <pre> &lt;expression&gt; ::= "("&lt;clause&gt;")" | "("&lt;clause&gt;")|("&lt;expression&gt;")" &lt;clause&gt; ::= &lt;literal&gt;"&"&lt;literal&gt;"&"&lt;literal&gt; &lt;literal&gt; ::= &lt;variable&gt; | "~"&lt;variable&gt; &lt;variable&gt; ::= [a-z]|[A-z] </pre> <p> <i>expression</i>の長さは500文字を超えない。 </p> <p> テストケヌスの数は1100個を超えない。 </p> <h2>Output</h2> <p> 䞎えられた匏を満たす倉数の割り圓おが存圚するのならばyesを、そうでなければnoを出力せよ。 </p> <h2>Sample input</h2> <pre> (B&B&f)|(~d&~i&i)|(~v&i&~V)|(~g&~e&o)|(~f&d&~v)|(d&~i&o)|(g&i&~B)|(~i&f&d)|(e&~i&~V)|(~v&f&~d) (S&X&~X) # </pre> <H2>Sample output</H2> <pre> yes no </pre> <hr> <p> The University of Aizu Programming Contest 2011 Summer<br> 原案: Tomoya Sakai<br> 問題文: Takashi Tayama<br> </p>
p01971
<h2>E: Broccoli or Cauliflower</h2> <h3>Problem</h3> <p>The input is a rooted tree <var>T = (V, E)</var> with <var>n</var> vertices. Note that <var>n</var> is odd and the vertex with index <var>1</var> is the root of <var>T</var>. In addition, we give a label <var>G</var> or <var>W</var> for each vertex. Let <var>T_v = (U, F)</var> be a subtree of <var>T</var> such that <var>U</var> is defined as following.</p> <ul> <li> <var>U = </var>$\{$<var> u \in V \ \ | \ \ u </var>$\text{ is the descendant of }$<var> v </var>$\}$</li> </ul> <p>We call <var>T_v</var> a subtree of <var>v</var>.</p> <p>We consider the following operation and perform operations <var>q</var> times.</p> <ul> <li> Let <var>v</var> be a vertex. If a vertex <var>u \in U</var> has the label <var>G</var>, then we change the label of <var>u</var> <var>G</var> to <var>W</var>. Otherwise, we change the label of <var>u</var> <var>W</var> to <var>G</var>. </li> </ul> <p>After each operation, output “broccoli” if the number of vertices with the label <var>G</var> is greater than <var>W</var>. Otherwise, output “cauliflower”.</p> <h3>Input format</h3> <p>An input is the following format.</p> <pre> <var>n</var> <var>q</var> <var>p_2</var> <var>...</var> <var>p_n</var> <var>c_1</var> <var>...</var> <var>c_n</var> <var>v_1</var> $\vdots$ <var>v_q</var> </pre> <p>In line <var>1</var>, there are two integers <var>n</var> and <var>q</var>, where <var>n</var> is the number of vertices in <var>T</var> and <var>q</var> is the number of queries. Note that <var>n</var> is odd.</p> <p>In line <var>2</var>, there are <var>n - 1</var> integers <var>p_2</var> to <var>p_n</var>. <var>p_i</var> represents the parent of a vertex <var>v_i</var>.</p> <p> In line <var>3</var>, there are <var>n</var> characters <var>c_1</var> to <var>c_n</var>. <var>c_i</var> represents the label of <var>v_i</var>. Finally, in line <var>j + 3</var>, there is an integer <var>v_j</var>. We perform the operation for <var>T_{v_j}</var>. </p> <h3>Constraints</h3> <ul> <li> <var>1 \leq n \leq 100,000</var> ( <var>n</var> is odd. )</li> <li> <var>1 \leq q \leq 100,000</var></li> <li> <var>1 \leq p_i &lt; i</var><var>2 \leq i \leq n</var></li> <li> <var>c_j</var> is <var>G</var> or <var>W</var>. (<var>1 \leq j \leq n</var>)</li> <li> <var>1 \leq v_i \leq n</var><var>1 \leq i \leq q</var></li> </ul> <h3>Output format</h3> <p>An output consists <var>q</var> lines and output “broccoli” or “cauliflower” in each line.</p> <h3>Input example 1</h3> <pre> 7 4 1 1 2 2 3 3 G G W W W G G 2 1 3 4 </pre> <h3>Output example 1</h3> <pre> broccoli cauliflower cauliflower broccoli </pre> <h3>Input example 2</h3> <pre> 17 18 1 1 1 3 1 4 2 4 3 6 10 9 3 4 5 15 W W W W W W W W G W G G W G W W W 6 7 1 9 14 6 4 5 3 7 8 13 9 6 14 12 9 13 </pre> <h3>Output example 2</h3> <pre> cauliflower cauliflower broccoli broccoli broccoli broccoli broccoli broccoli broccoli cauliflower cauliflower cauliflower cauliflower cauliflower broccoli cauliflower cauliflower cauliflower </pre>
p00399
<h1>柎犬の数</h1>   <p> むヅア公園には、倕方になるず柎犬ず散歩する人たちがたくさん来たす。柎犬には毛の色によっお赀柎、黒柎、癜柎、胡麻柎ずいう皮類がありたす。柎犬がたくさんいるずうれしいトモ゚ちゃんは、それぞれの毛色の柎犬が䜕頭いるかがんばっお数えたしたが、ただ足し算ができないので柎犬が党郚で䜕頭いるかわかりたせん。 </p> <p> それぞれの毛色の柎犬の数が䞎えられたずきに、柎犬の総数を蚈算するプログラムを䜜成せよ。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $R$ $B$ $W$ $G$ </pre> <p> 行に赀柎の数$R$ ($1 \leq R \leq 100$)、黒柎の数$B$ ($1 \leq B \leq 100$)、癜柎の数$W$ ($1 \leq W \leq 100$)、胡麻柎の数$G$ ($1 \leq G \leq 100$)が䞎えられる。 </p> <h2>出力</h2> <p> 柎犬の総数を行に出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 4 2 1 1 </pre> <h3>出力䟋</h3> <pre> 8 </pre> <h3>入力䟋</h3> <pre> 22 18 34 36 </pre> <h3>出力䟋</h3> <pre> 110 </pre>
p01422
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Beautiful Currency</H1> <p> KM country has <var>N</var> kinds of coins and each coin has its value <var>a_i</var>. </p> <p> The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it <i>beautiful</i> by changing the values of some (possibly no) coins. </p> <p> A currency system is called beautiful if each coin has an integer value and the (<var>i</var>+1)-th smallest value is divisible by the <var>i</var>-th smallest value for all <var>i</var> (<var>1 \leq i \leq N-1</var>). </p> <p> For example, the set <var>{1, 5, 10, 50, 100, 500}</var> is considered as a beautiful system, while the set <var>{1, 5, 10, 25, 50, 100}</var> is NOT, because <var>25</var> is not divisible by <var>10</var>. </p> <p> Since changing the currency system may confuse citizens, the king, Kita_masa, wants to minimize the maximum value of the confusion ratios. Here, the confusion ratio for the change in the <var>i</var>-th coin is defined as <var>|a_i - b_i| / a_i</var>, where <var>a_i</var> and <var>b_i</var> is the value of <var>i</var>-th coin before and after the structure changes, respectively. </p> <p> Note that Kita_masa can change the value of each existing coin, but he cannot introduce new coins nor eliminate existing coins. After the modification, the values of two or more coins may coincide. </p> <H2>Input</H2> <p> Each dataset contains two lines. The first line contains a single integer, <var>N</var>, and the second line contains <var>N</var> integers, <var>{a_i}</var>. </p> <p> You may assume the following constraints: </p> <p> <var>1 \leq N \leq 20</var> </p> <p> <var>1 \leq a_1 \lt a_2 \lt... \lt a_N \lt 10^5</var> </p> <H2>Output</H2> <p> Output one number that represents the minimum of the maximum value of the confusion ratios. The value may be printed with an arbitrary number of decimal digits, but may not contain an absolute error greater than or equal to <var>10^{-8}</var>. </p> <H2>Sample Input 1</H2> <pre> 3 6 11 12 </pre> <H2>Output for the Sample Input 1</H2> <pre> 0.090909090909 </pre> <H2>Sample Input 2</H2> <pre> 3 6 11 24 </pre> <H2>Output for the Sample Input 2</H2> <pre> 0.090909090909 </pre> <H2>Sample Input 3</H2> <pre> 3 6 11 30 </pre> <H2>Output for the Sample Input 3</H2> <pre> 0.166666666667 </pre>
p01072
<h1>Problem A: Plants</h1> <h2>Problem</h2> <p>がっちょ君は暪<var>W</var>個&times;瞊<var>H</var>個のマスで区切られた畑を所有しおいる。<var>x</var>列目<var>y</var>行目のマスをマス <var>(x, y)</var> ず呌ぶこずにする。いく぀かのマスの土地には高さ0cmの怍物が1本だけ怍えおあり、その他のマスの土地には䜕も怍えられおいない。 </p> <p> がっちょ君はある時刻に畑に肥料をたく。肥料がたかれたマスに怍物が怍えられおいるずき、その怍物の高さが1cm䌞びる。怍物が怍えられおいないずきは、䜕もおこらない。怍物が䌞びるのにかかる時間はずおも短いので無芖できる。がっちょ君は同じ時刻に耇数のマスに肥料をたくこずができる。ただし、同じ時刻に同じマスに2床以䞊肥料をたくこずはない。 </p> <p> がっちょ君が肥料をたいた蚘録が䞎えられたずき、時刻<var>T</var>時点での畑の怍物の高さの和を蚈算せよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>W</var> <var>H</var> <var>T</var> <var>p</var> <var>x<sub>0</sub></var> <var>y<sub>0</sub></var> <var>t<sub>0</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>t<sub>1</sub></var> ... <var>x<sub>p&minus;1</sub></var> <var>y<sub>p&minus;1</sub></var> <var>t<sub>p&minus;1</sub></var> <var>s<sub>0,0</sub></var> <var>s<sub>1,0</sub></var> 
 <var>s<sub>W&minus;1,0</sub></var> <var>s<sub>0,1</sub></var> <var>s<sub>1,1</sub></var> 
 <var>s<sub>W&minus;1,1</sub></var> ... <var>s<sub>0,H&minus;1</sub></var> <var>s<sub>1,H&minus;1</sub></var> 
 <var>s<sub>W&minus;1,H&minus;1</sub></var> </pre> <p> 1行目に畑の暪幅<var>W</var>、畑の瞊幅<var>H</var>、時刻<var>T</var>が䞎えられる。がっちょ君は時刻<var>T</var>たでに肥料をたきおえる。<br> 2行目にがっちょ君が肥料をたいた回数<var>p</var>が䞎えられる。<br> 3行目から2+<var>p</var>行目たでに䞎えられる぀の敎数は、がっちょ君が時刻<var>t<sub>i</sub></var>にマス(<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>)に肥料をたいたこずを衚す。<br> 3+<var>p</var>行目から2+<var>p</var>+<var>H</var>行目たでは、最初の畑のそれぞれのマスに怍物が怍えられおいるかどうかを衚す<var>W</var>&times;<var>H</var>個の敎数が䞎えられる。<var>s<sub>j,k</sub></var>が1のずきマス(<var>j</var>, <var>k</var>)に高さ0cmの怍物が1本だけ怍えられおいるこずを衚し、<var>s<sub>j,k</sub></var>が0のずきマス(<var>j</var>, <var>k</var>)に怍物は1本も怍えられおいないこずを衚す。<br> </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>W</var>, <var>H</var>, <var>T</var> &le; 50</li> <li>0 &le; <var>p</var> &le; min(<var>W</var>&times;<var>H</var>&times;<var>T</var>, 50)</li> <li>0 &le; <var>x<sub>i</sub></var> &lt; <var>W</var></li> <li>0 &le; <var>y<sub>i</sub></var> &lt; <var>H</var></li> <li>0 &le; <var>t<sub>i</sub></var> &lt; <var>T</var></li> <li><var>s<sub>j,k</sub></var> = 0たたは1</li> </ul> <h2>Output</h2> <p> 時刻<var>T</var>での畑の怍物の高さの和を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 3 3 5 2 0 0 0 1 0 1 1 1 1 2 1 2 2 0 0 0 0 0 1 0 0 0 0 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_A_sample1" alt="Sample1" style="width: 640px"></p> <h2>Sample Input 2</h2> <pre> 2 3 4 2 0 0 0 1 1 3 1 0 0 0 0 0 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre> <h2>Sample Input 3</h2> <pre> 3 8 6 6 0 4 3 2 5 3 0 2 3 2 2 5 1 1 3 2 2 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 </pre> <h2>Sample Output 3</h2> <pre> 4 </pre> <h2>Sample Input 4</h2> <pre> 8 3 3 7 0 1 1 5 1 0 4 0 2 3 2 0 3 1 1 3 0 1 5 1 1 1 0 1 1 0 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 0 1 0 1 </pre> <h2>Sample Output 4</h2> <pre> 4 </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_A_sample4" alt="Sample4" style="width: 640px"></p>
p01588
<H1><font color="#000">Problem H:</font> Round Table</H1> <p> You are the owner of a restaurant, and you are serving for <i>N</i> customers seating in a round table. </p> <p> You will distribute <i>M</i> menus to them. Each customer receiving a menu will make the order of plates, and then pass the menu to the customer on the right unless he or she has not make the order. The customer <i>i</i> takes <i>L<sub>i</sub></i> unit time for the ordering. </p> <p> Your job is to write a program to calculate the minimum time until all customers to call their orders, so you can improve your business performance. </p> <H2>Input</H2> <p> The input consists of a sequence of positive integers. </p> <p> The first line of the input contains two positive integers <i>N</i> (<i>N</i> &le; 50,000) and <i>M</i> (<i>M</i> &le; <i>N</i>). The second line contains <i>N</i> positive integers <i>L</i><sub>1</sub>, <i>L</i><sub>2</sub>,..., <i>L<sub>N</sub></i> (<i>L<sub>i</sub></i> &le; 600). </p> <H2>Output</H2> <p> Output the minimum possible time required for them to finish ordering. </p> <H2>Sample Input and Output</H2> <H2>Input #1</H2> <pre> 3 2 1 5 10 </pre> <H2>Output #1</H2> <pre> 10 </pre> <br/> <H2>Input #2</H2> <pre> 4 2 1 2 3 4 </pre> <H2>Output #2</H2> <pre> 5 </pre>
p01567
<h1>Presentation</h1> <p>You are a researcher investigating algorithms on binary trees. Binary tree is a data structure composed of branch nodes and leaf nodes. Every branch nodes have left child and right child, and each child is either a branch node or a leaf node. The root of a binary tree is the branch node which has no parent. </p> <p>You are preparing for your presentation and you have to make a figure of binary trees using a software. You have already made a figure corresponding to a binary tree which is composed of one branch node and two leaf nodes (Figure 1.) However, suddenly the function of your software to create a figure was broken. You are very upset because in five hours you have to make the presentation in front of large audience. </p> <p>You decided to make the figure of the binary trees using only copy function, shrink function and paste function of the presentation tool. That is, you can do only following two types of operations. </p> <ul> <li><p> Copy the current figure to the clipboard.</p> <ul><li><p>The figure copied to the clipboard before is removed.</p></li></ul> </li> <li><p> Paste the copied figure (with shrinking, if needed), putting the root of the pasted figure on a leaf node of the current figure.</p> <ul><li><p> You can paste the copied figure multiple times.</p></li></ul> </li> </ul> <p>Moreover, you decided to make the figure using the minimum number of paste operations because paste operation is very time cosuming. Now, your job is to calculate the minimum possible number of paste operations to produce the target figure. </p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_0" height="149" width="178"></center></p> <p><center><i>Figure 1: initial state</i></center></p> <p>For example, the answer for the instance of sample 1(Figure 4) is 3, because you can produce the target figure by following operations and this is minimum. </p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_1" height="192" width="257"></center></p> <p><center><i>Figure 2: intermediate 1</i></center></p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_2" height="183" width="243"></center></p> <p><center><i>Figure 3: intermediate 2</i></center></p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1_3" height="219" width="291"></center></p> <p><center><i>Figure 4: Goal</i></center></p> <h2>Input</h2> <p>The input is a line which indicates a binary tree. The grammar of the expression is given by the following BNF. </p> <blockquote> &lt;tree&gt; ::= &lt;leaf&gt; | &quot;(&quot; &lt;tree&gt; &lt;tree&gt; &quot;)&quot;<br>&lt;leaf&gt; ::= &quot;()&quot;<br></blockquote> <p>Every input obeys this syntax. You can assume that every tree in the input has at least 1 branch node, and that it has no more than 10^5 branch nodes. </p> <h2>Output</h2> <p>A line containing the minimum possible number of paste operations to make the given binary tree. </p> <h2>Sample Input 1</h2> <pre>((()())(((()())(()()))())) </pre> <h2>Output for the Sample Input 1</h2> <pre>3 </pre> <h2>Sample Input 2</h2> <pre>(((()())(()()))(()())) </pre> <h2>Output for the Sample Input 2</h2> <pre>4 </pre> <h2>Sample Input 3</h2> <pre>((()(()()))((()(()()))())) </pre> <h2>Output for the Sample Input 3</h2> <pre>3 </pre> <h2>Sample Input 4</h2> <pre>(()()) </pre> <h2>Output for the Sample Input 4</h2> <pre>0 </pre>
p01137
<!-- begin en only --> <h3><U>Space Coconut Crab</U></h3> <!-- end en only --> <!-- begin ja only --> <h3><U>宇宙ダシガニ</U></h3> <!-- end ja only --> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> ケン・マリンブルヌは宇宙ダシガニを求めお党銀河を旅するスペヌスハンタヌである宇宙ダシガニは宇宙最倧ずされる甲殻類であり成長埌の䜓長は 400 メヌトル以䞊足を広げれば 1,000 メヌトル以䞊にもなるず蚀われおいる既に倚数の人々が宇宙ダシガニを目撃しおいるが誰䞀人ずしお捕らえるこずに成功しおいない </p> <p> ケンは長期間の調査によっお宇宙ダシガニの生態に関する重芁な事実を解明した宇宙ダシガニは驚くべきこずに盞転移航法ず呌ばれる最新のワヌプ技術ず同等のこずを行い通垞空間ず超空間の間を埀来しながら生きおいたさらに宇宙ダシガニが超空間から通垞空間にワヌプアりトするたでには長い時間がかかりたたワヌプアりトしおからしばらくは超空間に移動できないこずも突き止めた </p> <p> そこでケンは぀いに宇宙ダシガニの捕獲に乗り出すこずにした戊略は次のずおりであるはじめに宇宙ダシガニが通垞空間から超空間に突入する際の゚ネルギヌを芳枬するこの゚ネルギヌを <i>e</i> ずするずき宇宙ダシガニが超空間からワヌプアりトする座暙 (<i>x</i>, <i>y</i>, <i>z</i>) は以䞋の条件を満たすこずがわかっおいる </p> <ul> <li><i>x</i>, <i>y</i>, <i>z</i> はいずれも非負の敎数である</li> <li><i>x</i> + <i>y</i><sup>2</sup> + <i>z</i><sup>3</sup> = <i>e</i> である</li> <li>䞊蚘の条件の䞋で <i>x</i> + <i>y</i> + <i>z</i> の倀を最小にする</li> </ul> <p> これらの条件だけでは座暙が䞀意に決たるずは限らないが<i>x</i> + <i>y</i> + <i>z</i> の最小倀を <i>m</i> ずしたずきにワヌプアりトする座暙が平面 <i>x</i> + <i>y</i> + <i>z</i> = <i>m</i> 䞊にあるこずは確かであるそこでこの平面䞊に十分な倧きさのバリアを匵るするず宇宙ダシガニはバリアの匵られたずころにワヌプアりトするこずになるバリアの圱響を受けた宇宙ダシガニは身動きがずれなくなるそこをケンの操䜜する最新鋭宇宙船であるりェポン・ブレヌカヌ号で捕獲しようずいう段取りである </p> <p> バリアは䞀床しか匵るこずができないため倱敗するわけにはいかないそこでケンは任務の遂行にあたっお蚈算機の助けを借りるこずにしたあなたの仕事は宇宙ダシガニが超空間に突入する際の゚ネルギヌが䞎えられたずきにバリアを匵るべき平面 <i>x</i> + <i>y</i> + <i>z</i> = <i>m</i> を求めるプログラムを曞くこずである甚意されたテストケヌスの党おに察しお正しい結果を出力したずきあなたのプログラムは受け入れられるであろう </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットで構成される各デヌタセットは 1 行のみからなり1 ぀の正の敎数 <i>e</i> (<i>e</i> ≩ 1,000,000) が含たれるこれは宇宙ダシガニが超空間に突入した際の゚ネルギヌを衚す入力は <i>e</i> = 0 の時に終了しこれはデヌタセットには含たれない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットに぀いお<i>m</i> の倀を 1 行に出力しなさい出力には他の文字を含めおはならない </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 1 2 4 27 300 1250 0 </pre> <h3>Output for the Sample Input</h3> <pre> 1 2 2 3 18 44 </pre>
p00376
<h1>Red Dragonfly</h1>   <p> It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed. </p> <p> When two red dragonflies’ positional information as measured from the end of the wall is given, make a program to calculate the distance between their heads. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $x_1$ $x_2$ </pre> <p> The input line provides dragonflies’ head positions $x_1$ and $x_2$ ($0 \leq x_1, x_2 \leq 100$) as integers. </p> <h2>Output</h2> <p> Output the distance between the two red dragonflies in a line. </p> <h2>Sample Input 1</h2> <pre> 20 30 </pre> <h2>Sample Output 1</h2> <pre> 10 </pre> <h2>Sample Input 2</h2> <pre> 50 25 </pre> <h2>Sample Output 2</h2> <pre> 25 </pre> <h2>Sample Input 3</h2> <pre> 25 25 </pre> <h2>Sample output 3</h2> <pre> 0 </pre>
p00726
<h1><font color="#000">Problem E:</font> <u>The Genome Database of All Space Life</u></h1> <!-- end en only --> <p> In 2300, the Life Science Division of Federal Republic of Space starts a very ambitious project to complete the genome sequencing of all living creatures in the entire universe and develop the genomic database of all space life. Thanks to scientific research over many years, it has been known that the genome of any species consists of at most 26 kinds of molecules, denoted by English capital letters (<i>i.e.</i> <tt>A</tt> to <tt>Z</tt>). </p> <!-- end en only --> <!-- begin en only --> <p> What will be stored into the database are plain strings consisting of English capital letters. In general, however, the genome sequences of space life include frequent repetitions and can be awfully long. So, for efficient utilization of storage, we compress <i>N</i>-times repetitions of a letter sequence <i>seq</i> into <i>N</i><tt>(</tt><i>seq</i><tt>)</tt>, where <i>N</i> is a natural number greater than or equal to two and the length of <i>seq</i> is at least one. When <i>seq</i> consists of just one letter <i>c</i>, we may omit parentheses and write <i>Nc</i>. </p> <!-- end en only --> <!-- begin en only --> <p> For example, a fragment of a genome sequence: </p><blockquote> <tt>ABABABABXYXYXYABABABABXYXYXYCCCCCCCCCC</tt> </blockquote> <p>can be compressed into:</p> <blockquote> <tt>4(AB)XYXYXYABABABABXYXYXYCCCCCCCCCC</tt> </blockquote> <p>by replacing the first occurrence of <tt>ABABABAB</tt> with its compressed form. Similarly, by replacing the following repetitions of <tt>XY</tt>, <tt>AB</tt>, and <tt>C</tt>, we get:</p> <blockquote> <tt>4(AB)3(XY)4(AB)3(XY)10C</tt> </blockquote> <p>Since <tt>C</tt> is a single letter, parentheses are omitted in this compressed representation. Finally, we have:</p> <blockquote> <tt>2(4(AB)3(XY))10C</tt> </blockquote> <p>by compressing the repetitions of <tt>4(AB)3(XY)</tt>. As you may notice from this example, parentheses can be nested. <p></p> <!-- end en only --> <!-- begin en only --> <p> Your mission is to write a program that uncompress compressed genome sequences. </p> <!-- end en only --> <h2>Input</h2> <!-- begin en only --> <p>The input consists of multiple lines, each of which contains a character string <i>s</i> and an integer <i>i</i> separated by a single space. </p> <!-- end en only --> <!-- begin en only --> <p> The character string <i>s</i>, in the aforementioned manner, represents a genome sequence. You may assume that the length of <i>s</i> is between 1 and 100, inclusive. However, of course, the genome sequence represented by <i>s</i> may be much, much, and much longer than 100. You may also assume that each natural number in <i>s</i> representing the number of repetitions is at most 1,000. </p> <!-- end en only --> <!-- begin en only --> <p> The integer <i>i</i> is at least zero and at most one million. </p> <!-- end en only --> <!-- begin en only --> <p> A line containing two zeros separated by a space follows the last input line and indicates the end of the input. </p> <!-- end en only --> <h2>Output</h2> <!-- begin en only --> <p> For each input line, your program should print a line containing the <i>i</i>-th letter in the genome sequence that <i>s</i> represents. If the genome sequence is too short to have the <i>i</i>-th element, it should just print a zero. No other characters should be printed in the output lines. Note that in this problem the index number begins from zero rather than one and therefore the initial letter of a sequence is its zeroth element. </p> <!-- end en only --> <h2>Sample Input</h2> <pre> ABC 3 ABC 0 2(4(AB)3(XY))10C 30 1000(1000(1000(1000(1000(1000(NM)))))) 999999 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 0 A C M </pre>
p01834
<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>Cube Dividing</h2> <p> Pablo Cubarson is a well-known cubism artist. He is producing a new piece of work using a cuboid which consists of $A \times B \times C$ unit cubes. He plans to make a beautiful shape by removing $N$ units cubes from the cuboid. When he is about to begin the work, he has noticed that by the removal the cuboid may be divided into several parts disconnected to each other. It is against his aesthetics to divide a cuboid. So he wants to know how many parts are created in his plan. </p> <p> Your task is to calculate the number of connected components in the cuboid after removing the $N$ cubes. Two cubes are connected if they share one face. </p> <h3>Input</h3> <p> The input consists of a single test case. The test case is formatted as follows:<br/> <br/> $A$ $B$ $C$ $N$<br/> $X_1$ $Y_1$ $Z_1$<br/> ...<br/> $X_N$ $Y_N$ $Z_N$<br/> </p> <p> The first line contains four integers $A$, $B$, $C$ and $N$. $A$, $B$ and $C$ ($1 \leq A,B,C \leq 10^6$) denote the size of the cuboid $-$ the cuboid has an $A$ unit width from left to right and a $B$ unit height from bottom to top, and a $C$ unit depth from front to back. $N$ ($0 \leq N \leq 20,000, N \leq A \times B \times C - 1$) denotes the number of the cubes removed in the Cubarson's plan. Each of the following $N$ lines contains three integers $X_i$ ($0 \leq X_i \leq A-1$), $Y_i$ ($0 \leq Y_i \leq B-1$) and $Z_i$ ($0 \leq Z_i \leq C - 1$). They denote that the cube located at the $X_i$-th position from the left, the $Y_i$-th from the bottom and the $Z_i$-th from the front will be removed in the plan. You may assume the given positions are distinct. </p> <h3>Output</h3> <p> Print the number of the connected components in the cuboid after removing the specified cubes. </p> <h3>Sample Input 1</h3> <pre> 2 2 2 4 0 0 0 1 1 0 1 0 1 0 1 1 </pre> <h3>Output for the Sample Input 1</h3> <pre> 4 </pre> <h3>Sample Input 2</h3> <pre> 3 3 3 1 1 1 1 </pre> <h3>Output for the Sample Input 2</h3> <pre> 1 </pre> <h3>Sample Input 3</h3> <pre> 1 1 3 2 0 0 0 0 0 2 </pre> <h3>Output for the Sample Input 3</h3> <pre> 1 </pre>
p03809
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>. The <var>i</var>-th of the <var>N-1</var> edges connects vertices <var>a_i</var> and <var>b_i</var>.</p> <p>Currently, there are <var>A_i</var> stones placed on vertex <var>i</var>. Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation:</p> <ul> <li>Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices. Here, a <em>leaf</em> is a vertex of the tree whose degree is <var>1</var>, and the selected leaves themselves are also considered as vertices on the path connecting them.</li> </ul> <p>Note that the operation cannot be performed if there is a vertex with no stone on the path.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≩ N ≩ 10^5</var></li> <li><var>1 ≩ a_i,b_i ≩ N</var></li> <li><var>0 ≩ A_i ≩ 10^9</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> 
 <var>A_N</var> <var>a_1</var> <var>b_1</var> : <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to remove all the stones from the vertices, print <code>YES</code>. Otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 1 1 2 2 4 5 2 3 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>All the stones can be removed, as follows:</p> <ul> <li>Select vertices <var>4</var> and <var>5</var>. Then, there is one stone remaining on each vertex except <var>4</var>.</li> <li>Select vertices <var>1</var> and <var>5</var>. Then, there is no stone on any vertex.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 1 1 2 2 3 </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>6 3 2 2 2 2 2 1 2 2 3 1 4 1 5 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre></section> </div> </span>
p00008
<H1>Sum of 4 Integers</H1> <p> Write a program which reads an integer <var>n</var> and identifies the number of combinations of <var>a, b, c</var> and <var>d</var> (0 &le; <var>a, b, c, d</var> &le; 9) which meet the following equality:<br> <br> <var>a + b + c + d = n</var><br> <br> For example, for <var>n</var> = 35, we have 4 different combinations of (<var>a, b, c, d</var>): (<var>8, 9, 9, 9</var>), (<var>9, 8, 9, 9</var>), (<var>9, 9, 8, 9</var>), and (<var>9, 9, 9, 8</var>). </p> <H2>Input</H2> <p> The input consists of several datasets. Each dataset consists of <var>n</var> (1 &le; <var>n</var> &le; 50) in a line. The number of datasets is less than or equal to 50. </p> <H2>Output</H2> <p> Print the number of combination in a line. </p> <H2>Sample Input</H2> <pre> 35 1 </pre> <H2>Output for the Sample Input</H2> <pre> 4 4 </pre>
p02035
<h2>F: 赀黒そヌるじぇむ / Red-Black Soul Gem</h2> <h3>問題</h3> <p> ほむちゃんは、そヌるじぇむを赀色や黒色に倉化させたり、 異なる <var>2</var> ぀のそヌるじぇむ間を魔法の糞で接続したりする䞍思議な力を持っおいたす。 この力を䜿うこずで、ほむちゃんは、そヌるじぇむによる魔方陣を䜜るこずができたす。 </p> <p>ほむちゃんは、 <var>1</var> から <var>N</var> で番号付けられた <var>N</var> 個のそヌるじぇむがあるずき、以䞋の条件が成り立぀異なる魔方陣がいく぀あるのか気になりたした。</p> <ul> <li> どの <var>2</var> ぀のそヌるじぇむ間も、高々 <var>1</var> 回しか接続されない。</li> <li> すべおのそヌるじぇむの色が、赀色か黒色のいずれかになっおいる。</li> <li> 任意のそヌるじぇむに察しお、自身の色ず異なる色のそヌるじぇむのうち、少なくずも <var>1</var> ぀ず接続されおいる。</li> </ul> <p> このずき、魔方陣はそヌるじぇむを頂点ずし、魔法の糞を蟺ずするグラフずみなすこずができたす。 ここで、そのグラフは <b>連結でなくおもよい</b> こずに泚意しおください。 </p> <p> ほむちゃんは蚈算が苊手なので、代わりにあなたが高速なプログラムを䜜っお異なる魔方陣の数を蚈算しおあげたしょう。 しかし、その数は非垞に倚いこずが予想されるので、ある玠数 <var>M</var> で割った䜙りを求めるこずにしたす。 </p> <p>なお、ある魔方陣 <var>G</var> ず <var>H</var> が異なるずは、あるそヌるじぇむ <var>v</var> に぀いお <var>G</var> ず <var>H</var> でその色が異なる、もしくはあるそヌるじぇむの組 <var>u</var>, <var>v</var> が <var>G</var> ず <var>H</var> の䞀方でのみ接続されおいるこずを指したす。</p> <h3>入力圢匏</h3> <pre><var>N</var> <var>M</var></pre> <h3>制玄</h3> <ul> <li> <var>2 \leq N \leq 2,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> で割った䜙りを敎数で <var>1</var> 行に出力しおください。</p> <h3>入力䟋1</h3> <pre>3 310779401</pre> <h3>出力䟋1</h3> <pre>12</pre> <p>䟋えば、以䞋のような魔方陣は条件を満たしたす。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-f-001.jpg" type="image/jpeg" width="300"></object> <h3>入力䟋2</h3> <pre>7 566666561</pre> <h3>出力䟋2</h3> <pre>98638848</pre> <p>䟋えば、以䞋のような魔方陣は条件を満たしたす。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-f-002.jpg" type="image/jpeg" width="400"></object> <h3>入力䟋3</h3> <pre>1010 1000000007</pre> <h3>出力䟋3</h3> <pre>862232855</pre> <p><var>M</var> で割った䜙りを出力するこずに泚意しおください。</p>
p00458
<H1>薄氷枡り</H1> <h2>問題</h2> <p> 冬の寒いある日JOI倪郎君は広堎にはった薄氷を割っお遊ぶこずにした広堎は長方圢で東西方向に m 個南北方向に n 個぀たり m &times; n の区画に区切られおいるたた薄氷が有る区画ず無い区画がある JOI倪郎君は次のルヌルにしたがっお薄氷を割りながら区画を移動するこずにした </p> <ul> <li> 薄氷があるどの区画からも薄氷を割り始めるこずができる</li> <li> 東西南北のいずれかの方向に隣接し ただ割られおいない薄氷のある区画に移動できる</li> <li> 移動した先の区画の薄氷をかならず割る</li> </ul> <p> JOI倪郎君が薄氷を割りながら移動できる区画数の最倧倀を求めるプログラムを䜜成せよただし 1 &le; m &le; 901 &le; n &le; 90 である䞎えられる入力デヌタでは移動方法は20䞇通りを超えない </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 入力はn+2行ある 1 行目には敎数 m が曞かれおいる 2 行目には敎数 n が曞かれおいる 3 行目から n+2 行目たでの各行には、0 もしくは 1 が 空癜で区切られお m 個曞かれおおり各区画に薄氷があるか吊かを衚しおいる北から i 番目西からj番目の区画を (i,j) ず蚘述するこずにするず (1 &le; i &le; n, 1 &le; j &le; m)第 i+2 行目の j 番目の倀は区画 (i,j) に薄氷が存圚する堎合は 1 ずなり区画 (i,j) に薄氷が存圚しない堎合は 0 ずなる </p> <p> m, n がずもに 0 のずき入力の終了を瀺す. デヌタセットの数は 5 を超えない </p> <h2>出力</h2> <p> デヌタセットごずに, 移動できる区画数の最倧倀を行に出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 3 3 1 1 0 1 0 1 1 1 0 5 3 1 1 1 0 1 1 1 0 0 0 1 0 0 0 1 0 0 </pre> <h3>出力䟋</h3> <pre> 5 5 </pre> <p> 1぀目の入力䟋に察しお最倧倀を䞎える移動方法の䟋  <br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-1" alt="入力䟋1の堎合" width=230 height=230> </p> <p> 2぀目の入力䟋に察しお最倧倀を䞎える移動方法の䟋 <br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2" alt="入力䟋2の堎合" width=324 height=194> </p> <p>2぀目の入力䟋に察しお最倧倀を䞎えない移動方法の䟋<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-1" alt="入力䟋2の堎合1" width=324 height=194> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-2" alt="入力䟋2の堎合2" width=324 height=194> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-3" alt="入力䟋2の堎合3" width=324 height=194> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-4" alt="入力䟋2の堎合4" width=324 height=194> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009-yo-t4-2-5" alt="入力䟋2の堎合5" width=324 height=194> </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02465
<h1>Set Difference</h1> <p> Find the difference of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$, $A - B$. </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 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> 5 1 2 3 5 8 2 2 5 </pre> <h2>Sample Output 1</h2> <pre> 1 3 8 </pre>
p02936
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a rooted tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The root is Vertex <var>1</var>, and the <var>i</var>-th edge <var>(1 \leq i \leq N - 1)</var> connects Vertex <var>a_i</var> and <var>b_i</var>.</p> <p>Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value <var>0</var>.</p> <p>Now, the following <var>Q</var> operations will be performed:</p> <ul> <li>Operation <var>j</var> <var>(1 \leq j \leq Q)</var>: Increment by <var>x_j</var> the counter on every vertex contained in the subtree rooted at Vertex <var>p_j</var>.</li> </ul> <p>Find the value of the counter on each vertex after all operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq Q \leq 2 \times 10^5</var></li> <li><var>1 \leq a_i &lt; b_i \leq N</var></li> <li><var>1 \leq p_j \leq N</var></li> <li><var>1 \leq x_j \leq 10^4</var></li> <li>The given graph is a tree.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>p_1</var> <var>x_1</var> <var>:</var> <var>p_Q</var> <var>x_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the values of the counters on Vertex <var>1, 2, \ldots, N</var> after all operations, in this order, with spaces in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 2 2 3 2 4 2 10 1 100 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>100 110 111 110 </pre> <p>The tree in this input is as follows:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png"/></p> <p>Each operation changes the values of the counters on the vertices as follows:</p> <ul> <li>Operation <var>1</var>: Increment by <var>10</var> the counter on every vertex contained in the subtree rooted at Vertex <var>2</var>, that is, Vertex <var>2, 3, 4</var>. The values of the counters on Vertex <var>1, 2, 3, 4</var> are now <var>0, 10, 10, 10</var>, respectively.</li> <li>Operation <var>2</var>: Increment by <var>100</var> the counter on every vertex contained in the subtree rooted at Vertex <var>1</var>, that is, Vertex <var>1, 2, 3, 4</var>. The values of the counters on Vertex <var>1, 2, 3, 4</var> are now <var>100, 110, 110, 110</var>, respectively.</li> <li>Operation <var>3</var>: Increment by <var>1</var> the counter on every vertex contained in the subtree rooted at Vertex <var>3</var>, that is, Vertex <var>3</var>. The values of the counters on Vertex <var>1, 2, 3, 4</var> are now <var>100, 110, 111, 110</var>, respectively.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 2 1 2 1 3 2 4 3 6 2 5 1 10 1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>20 20 20 20 20 20 </pre></section> </div> </span>
p03624
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in <var>S</var>. If every lowercase English letter occurs in <var>S</var>, print <code>None</code> instead.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 10^5</var> (<var>|S|</var> is the length of string <var>S</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>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest lowercase English letter that does not occur in <var>S</var>. If every lowercase English letter occurs in <var>S</var>, print <code>None</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>atcoderregularcontest </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>b </pre> <p>The string <code>atcoderregularcontest</code> contains <code>a</code>, but does not contain <code>b</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>abcdefghijklmnopqrstuvwxyz </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>None </pre> <p>This string contains every lowercase English letter.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>d </pre></section> </div> </span>
p01619
<h1>G: Computer Onesan / コンピュヌタおねえさん</h1> <p>ある日おねえさんは子䟛たちに組合せの数え方に぀いお教えおあげるこずになりたした</p> <p>そこでおねえさんは次のような問題を解いおみるこずにしたした</p> <ul> <li>瞊幅 1 暪幅 1 の正方圢を瞊幅 <em>N</em> 暪幅 <em>M</em> の長方圢に敷き詰めたずきに長方圢の巊䞊の頂点から右䞋の頂点ぞの通り方が䜕通りあるかを数える</li> <li>敷き詰めた正方圢の蟺の䞊しか通れない</li> <li>それぞれの通り方は同じ堎所を1床しか通らない</li> </ul> <p>図1に<em>N</em> = 2, <em>M</em> = 2 の堎合の党おの通り方を瀺したす 図1では党郚で12通りの通り方を瀺しおおりその経路は赀い倪線で衚しおいたす</p> <div align="center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day3_G_G_fig" width="450" alt="G_fig.png" /> <p><strong>図1:</strong> <em>N</em> = 2, <em>M</em> = 2 の堎合の党おの通り方</p> </div> <p>この問題では <em>N</em> ず <em>M</em> が少し倧きくなるだけで組合せの数が爆発的に増加しおしたい手で数えるのがずおも難しくなっおしたいたす そこでおねえさんは自分の頭脳をロボットに移怍し25䞇幎をかけお10 x 10 の堎合の組合せの数を数える蚈画を立おたした</p> <p>「10 x 10 なんお蚈算するずおねえさん死んじゃうやめお」</p> <p>止める子䟛たちをよそにおねえさんは蚈算を開始したす おねえさんはそこたでしおでも子䟛たちに組合せ爆発のすごさを教えおあげたいのです</p> <p>おねえさんの熱意に心打たれたプログラマヌのあなたはこの問題を解くプログラムを曞いおあげるこずにしたした ずいっおもいきなり 10 x 10 を蚈算するプログラムを䜜るのは難しいので手始めに <em>M</em> が小さい堎合のプログラムを曞くこずにしたした</p> <div> <h1>Input</h1> <p>入力は1行に <em>N</em> ず <em>M</em> が半角スペヌスで䞎えられたす <em>N</em> は長方圢の瞊の幅で1 &lt;= <em>N</em> &lt;= 100を満たしたす <em>M</em> は長方圢の暪の幅で1 &lt;= <em>M</em> &lt;= 2を満たしたす</p> </div> <div> <h1>Output</h1> <p>入力に察する通り方の数を1行に出力しおください ただし答えが非垞に倧きくなる堎合があるので1,000,000で割った䜙りを出力しおください</p> </div> <div> <h1>Sample Input 1</h1> <pre> 1 1 </pre> </div> <div> <h1>Sample Output 1</h1> <pre> 2 </pre> </div> <div> <h1>Sample Input 2</h1> <pre> 1 2 </pre> </div> <div> <h1>Sample Output 2</h1> <pre> 4 </pre> </div> <div> <h1>Sample Input 3</h1> <pre> 2 1 </pre> </div> <div> <h1>Sample Output 3</h1> <pre> 4 </pre> </div> <div> <h1>Sample Input 4</h1> <pre> 2 2 </pre> </div> <div> <h1>Sample Output 4</h1> <pre> 12 </pre> </div> <div> <h1>Sample Input 5</h1> <pre> 3 2 </pre> </div> <div> <h1>Sample Output 5</h1> <pre> 38 </pre> </div>
p03274
<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> candles placed on a number line. The <var>i</var>-th candle from the left is placed on coordinate <var>x_i</var>. Here, <var>x_1 &lt; x_2 &lt; ... &lt; x_N</var> holds.</p> <p>Initially, no candles are burning. Snuke decides to light <var>K</var> of the <var>N</var> candles.</p> <p>Now, he is at coordinate <var>0</var>. He can move left and right along the line with speed <var>1</var>. He can also light a candle when he is at the same position as the candle, in negligible time.</p> <p>Find the minimum time required to light <var>K</var> candles.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>x_i</var> is an integer.</li> <li><var>|x_i| \leq 10^8</var></li> <li><var>x_1 &lt; x_2 &lt; ... &lt; x_N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum time required to light <var>K</var> candles.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 -30 -10 10 20 50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>40 </pre> <p>He should move and light candles as follows:</p> <ul> <li>Move from coordinate <var>0</var> to <var>-10</var>.</li> <li>Light the second candle from the left.</li> <li>Move from coordinate <var>-10</var> to <var>10</var>.</li> <li>Light the third candle from the left.</li> <li>Move from coordinate <var>10</var> to <var>20</var>.</li> <li>Light the fourth candle from the left.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 10 20 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>20 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <ul> <li>There may be a candle placed at coordinate <var>0</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 5 -9 -7 -4 -3 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>10 </pre></section> </div> </span>
p01249
<H1><font color="#000">Problem J:</font> Billion Million Thousand</H1> <p> A linguist, Nodvic Natharus Damenhof (commonly called <i>Dr. Usoperant</i>), invented an artificial language <i>Usoperant</i> in 2007. The word <i>usoperant</i> means ‘one which tires’. Damenhof’s goal was to create a complex and pedantic language that would remind many difficulties in universal communications. Talking in Usoperant, you should remember the importance of choosing your words in many conversations. </p> <p> For example of the complexity, you may be confused by the way to say large numbers. Usoperant has some words that indicate exponential numbers in decimal, described as 10<sup><i>p</i></sup> where <i>p</i> is a positive integer. In terms of English, those words might include thousand for 10<sup>3</sup> (1,000), million for 10<sup>6</sup> (1,000,000), and <i>undecillion</i> for 10<sup>36</sup> (1,000,000,000,000,000,000,000,000,000,000,000,000). </p> <p> You can concatinate those words to express larger numbers. When two words <i>w</i><sub>1</sub> and <i>w</i><sub>2</sub> mean numbers 10<sup><i>p</i><sub>1</sub></sup> and 10<sup><i>p</i><sub>2</sub></sup> respectively, a concatinated word <i>w</i><sub>1</sub><i>w</i><sub>2</sub> means 10<sup><i>p</i><sub>1</sub>+<i>p</i><sub>2</sub></sup>. Using the above examples in English (actually the following examples are incorrect in English), you can say 10<sup>9</sup> by <i>millionthousand</i>, 10<sup>12</sup> by <i>millionmillion</i> and 10<sup>39</sup> by <i>undecillionthousand</i>. Note that there can be multiple different expressions for a certain number. For example, 10<sup>9</sup> can also be expressed by <i>thousandthousandthousand</i>. It is also possible to insert separators between the adjacent components like <i>million-thousand</i> and <i>thousand-thousand-thousand</i>. </p> <p> In this problem, you are given a few of such words, their representing digits and an expression of a certain number in Usoperant. Your task is to write a program to calculate the length of the shortest expression which represents the same number as the given expression. </p> <p> The expressions in the input do not contain any separators like <i>millionthousand</i>. In case of ambiguity, the expressions should be interpreted as the largest number among possibles. The resultant expressions should always contain separators like <i>million-thousand</i>, so we can distinguish, for example, <i>x</i>-<i>x</i> (a concatinated word of two <i>x</i>'s) and <i>xx</i> (just a single word). The separators should not be counted in the length. </p> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case begins with a line including an integer <i>N</i> (1 &le; <i>N</i> &le; 100). The integer <i>N</i> indicates the number of words in the dictionary of exponential numbers. </p> <p> The following <i>N</i> lines give the words in the dictionary. Each line contains a word <i>w<sub>i</sub></i> and an integer <i>p<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>N</i>, 1 &le; <i>p<sub>i</sub></i> &le; 10), specifying that the word <i>w<sub>i</sub></i> expresses an exponential number 10<sup><i>p<sub>i</sub></i></sup> in Usoperant. Each <i>w<sub>i</sub></i> consists of at most 100 alphabetical letters. </p> <p> Then a line which contains an expression of a number in Usoperant follows. The expression consists of at most 200 alphabetical letters. </p> <p> The end of the input is indicated by a line which contains only a single 0. </p> <H2>Output</H2> <p> For each test case, print a line which contains the case number and the length of the shortest expression which represents the same number as the given expression in the input. </p> <H2>Sample Input</H2> <pre> 3 billion 9 million 6 thousand 3 billionmillionthousand 3 oku 8 sen 3 man 4 okusenman 2 nico 2 video 4 niconicovideo 6 abcd 1 efgh 2 abcde 4 fgh 6 y 8 yy 10 abcdefgh 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 14 Case 2: 9 Case 3: 10 Case 4: 2 </pre> <H2>Note:</H2> <p> In the fourth case, the word <i>abcdefgh</i> can be separated as <i>abcd-efgh</i> (representing 10<sup>3</sup> ) and <i>abcde-fgh</i> (representing 10<sup>10</sup> ), and by the rule described in the problem statement, this word should be interpreted as 10<sup>10</sup>. As this number can be expressed by <i>yy</i>, the length of the shortest expression is two (as in the sample output). The existence of <i>y</i>-<i>y</i> (representing 10<sup>16</sup> ) is not a problem here, because we can distinguish <i>yy</i> and <i>y</i>-<i>y</i> as long as we always use separators. </p>
p02873
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var> of length <var>N-1</var>. Each character in <var>S</var> is <code>&lt;</code> or <code>&gt;</code>.</p> <p>A sequence of <var>N</var> non-negative integers, <var>a_1,a_2,\cdots,a_N</var>, is said to be <em>good</em> when the following condition is satisfied for all <var>i</var> (<var>1 \leq i \leq N-1</var>):</p> <ul> <li>If <var>S_i=</var> <code>&lt;</code>: <var>a_i&lt;a_{i+1}</var></li> <li>If <var>S_i=</var> <code>&gt;</code>: <var>a_i&gt;a_{i+1}</var></li> </ul> <p>Find the minimum possible sum of the elements of a good sequence of <var>N</var> non-negative integers.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 5 \times 10^5</var></li> <li><var>S</var> is a string of length <var>N-1</var> consisting of <code>&lt;</code> and <code>&gt;</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the minimum possible sum of the elements of a good sequence of <var>N</var> non-negative integers.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>&lt;&gt;&gt; </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p><var>a=(0,2,1,0)</var> is a good sequence whose sum is <var>3</var>. There is no good sequence whose sum is less than <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>&lt;&gt;&gt;&gt;&lt;&lt;&gt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&lt; </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>28 </pre></section> </div> </span>
p03761
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.</p> <p>He will receive a headline which contains one of the strings <var>S_1,...,S_n</var> tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.</p> <p>Find the longest string that can be created regardless of which string among <var>S_1,...,S_n</var> the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq n \leq 50</var></li> <li><var>1 \leq |S_i| \leq 50</var> for every <var>i = 1, ..., n</var>.</li> <li><var>S_i</var> consists of lowercase English letters (<code>a</code> - <code>z</code>) for every <var>i = 1, ..., n</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>n</var> <var>S_1</var> <var>...</var> <var>S_n</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 cbaa daacc acacac </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>aac </pre> <p>The strings that can be created from each of <code>cbaa</code>, <code>daacc</code> and <code>acacac</code>, are <code>aa</code>, <code>aac</code>, <code>aca</code>, <code>caa</code> and so forth. Among them, <code>aac</code>, <code>aca</code> and <code>caa</code> are the longest, and the lexicographically smallest of these three is <code>aac</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 a aa b </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre> </pre> <p>The answer is an empty string.</p></section> </div> </span>
p03331
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has two positive integers <var>A</var> and <var>B</var>.</p> <p>It is known that <var>A</var> plus <var>B</var> equals <var>N</var>. Find the minimum possible value of "the sum of the digits of <var>A</var>" plus "the sum of the digits of <var>B</var>" (in base <var>10</var>).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 10^5</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible value of "the sum of the digits of <var>A</var>" plus "the sum of the digits of <var>B</var>".</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>When <var>A=2</var> and <var>B=13</var>, the sums of their digits are <var>2</var> and <var>4</var>, which minimizes the value in question.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre></section> </div> </span>
p02170
<h1>Problem I: Coin and Die</h1> <h2>Problem</h2> <p> 衚ず裏のあるコむンず $1$ から $N$ たでの目があるサむコロがある。Gachoくんはこれらを甚いお以䞋のゲヌムをしお遊ぶこずにした。<br><br> ゲヌムは最初に埗点が $0$ の状態から始たり、以䞋の手順で進められる。<br> </p> <ol type="1"> <li>サむコロを $1$ 回振り、そのずき出た目の数を埗点に加算する</li> <li>珟圚の埗点が $K$ 以䞊ならゲヌムクリアずなりゲヌムを終了する</li> <li>珟圚の埗点が $K$ 未満ならコむンを投げ衚が出れば1.に戻り、裏が出ればゲヌムオヌバヌずなりゲヌムを終了する</li> </ol> <p> コむンは投げるず $A\%$の確率で衚になり、 $(100-A)\%$の確率で裏になる。たた、サむコロは振るず、それぞれの目が等確率で出珟する。<br> このずき、䞀床のゲヌムでGachoくんがゲヌムクリアするこずができる確率を求めよ。<br> 求める確率を互いに玠な敎数 $P, Q$ を甚いお $\frac{P}{Q}$ ず衚したずき、 $R \times Q \equiv P\bmod 998244353$ ずなる $0$ 以䞊 $998244352$ 以䞋の敎数 $R$ を出力せよ。この問題の制玄䞋で、このような $R$ は必ず䞀意に存圚する。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $K$ $A$ </pre> <p> $N, K, A$ が空癜区切りで䞀行に䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq N \leq 10^5 $</li> <li>$1 \leq K \leq 10^5 $</li> <li>$1 \leq A \leq 99 $</li> <li>入力はすべお敎数</li> </ul> <h2>Output</h2> <p> ゲヌムをクリアするこずができる確率を互いに玠な敎数 $P, Q$を甚いお $\frac{P}{Q}$ ず衚したずき、$R \times Q\equiv P\bmod 998244353$ ずなる $0$ 以䞊 $998244352$ 以䞋の敎数 $R$ を出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 1 1 50 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 2 2 10 </pre> <h2>Sample Output 2</h2> <pre> 648858830 </pre> <h2>Sample Input 3</h2> <pre> 6 10 99 </pre> <h2>Sample Output 3</h2> <pre> 650893870 </pre>
p01025
<h1>Problem J: Hanimon</h1> <p> ハニカムモンスタヌはハニカム暡様の六角圢状の䞍思議な生き物である。 </p> <p> ハニカムモンスタヌには様々なサむズのものがあり、䞀蟺が<em>N</em>個の正六角圢のマスから成るハニカムモンスタヌをサむズ<em>N</em>のハニカムモンスタヌずする。 </p> <p> 䞀方、聖なる暡様はハニカムモンスタヌず同じく、六角圢ずしお定矩され1蟺が<em>P</em>個の正六角圢のマスから成る聖なる暡様をサむズ<em>P</em>の聖なる暡様ずする。 </p> <p> ハニカムモンスタヌず聖なる暡様の圢の䟋を以䞋に瀺す。サむズは1蟺の正六角圢のマスの数に察応する。 </p> <div align="center"> <img alt="sample1.png" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_Hanimon_sample1.png" style="margin-bottom: 8px" width="50%" height="50%" /><br> <strong>図1:</strong>サむズの䟋 <br> <br> <img width="680" alt="sample2.png" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_Hanimon_sample2.png"/><br> <strong>図2:</strong>ハニカムモンスタヌず聖なる暡様の䟋 (Sample Input 1) </div> <p> ハニカムモンスタヌず聖なる暡様の各マスには色が着いおおり0ず1によっお衚される。 </p> サむズ<em>P</em>の<em>Q</em>個の聖なる暡様のすべおを含むハニカムモンスタヌは䌝説のハニモンず呌ばれおいる。 <p> サむズ<em>N</em>のハニカムモンスタヌずその暡様、<em>Q</em>個のサむズ<em>P</em>の聖なる暡様が䞎えられるので、 そのハニカムモンスタヌが䌝説のハニモンであるかどうかを刀定するプログラムを䜜成せよ。 </p> <div> <h1>Input</h1> <p>入力は次の圢匏で衚される。</p> <pre> <em>N</em> <em>P</em> <em>Q</em> (空行) ハニカムモンスタヌの暡様の情報 (空行) 1぀目の聖なる暡様の情報 (空行) 2぀目の聖なる暡様の情報 (空行) ... <em>Q</em>぀目の聖なる暡様の情報 </pre> <p> <em>N</em>,<em>P</em>,<em>Q</em>はそれぞれハニカムモンスタヌのサむズ,聖なる暡様のサむズ,聖なる暡様の個数を衚す。 </p> <p> サむズ<em>N</em>のハニカムモンスタヌの暡様の情報は以䞋の様に2×<em>N</em>-1行で䞎えられる。 </p> <pre> <em>N</em>個のマス <em>N</em>+1個のマス <em>N</em>+2個のマス . . 2×<em>N</em>-2個のマス 2×<em>N</em>-1個のマス 2×<em>N</em>-2個のマス . . <em>N</em>+2個のマス <em>N</em>+1個のマス <em>N</em>個のマス </pre> <p> サむズ<em>P</em>の聖なる暡様の情報は以䞋の様に2×<em>P</em>-1行で䞎えられる。 </p> <pre> <em>P</em>個のマス <em>P</em>+1個のマス <em>P</em>+2個のマス . . 2×<em>P</em>-2個のマス 2×<em>P</em>-1個のマス 2×<em>P</em>-2個のマス . . <em>P</em>+2個のマス <em>P</em>+1個のマス <em>P</em>個のマス </pre> <p> それぞれのマスの間には぀の空癜が入り、マスにはか1が入る。 </p> <h1>Constraints</h1> <div> <ul> <li>1 &le; <em>N</em> &le; 1000 </li> <li>1 &le; <em>P</em> &le; 50 </li> <li>1 &le; <em>Q</em> &le; 100 </li> <li>同じ暡様の聖なる暡様が耇数個䞎えられるこずは無い。</li> <li>ハニカムモンスタヌのあるマスに぀いお、2぀以䞊の聖なる暡様の䞀郚分であるこずがある。</li> <li>ハニカムモンスタヌず聖なる暡様は回転できない。</li> </ul> </div> </div> <h1>Output</h1> <p>䌝説のハニモンなら YES を、そうでなければ NO を䞀行に出力せよ。</p> <h1>Sample Input 1</h1> <pre> 6 2 2 1 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 0 0 0 0 1 0 1 1 </pre> <h1>Sample Output 1</h1> <pre> YES </pre> <h1>Sample Input 2</h1> <pre> 6 2 2 0 0 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 1 0 0 1 0 1 </pre> <h1>Sample Output 2</h1> <pre> NO </pre>
p03018
<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> consisting of <code>A</code>, <code>B</code> and <code>C</code>.</p> <p>Snuke wants to perform the following operation on <var>s</var> as many times as possible:</p> <ul> <li>Choose a contiguous substring of <var>s</var> that reads <code>ABC</code> and replace it with <code>BCA</code>.</li> </ul> <p>Find the maximum possible number of operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |s| \leq 200000</var></li> <li>Each character of <var>s</var> is <code>A</code>, <code>B</code> and <code>C</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the maximum possible number of operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>ABCABC </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>You can perform the operations three times as follows: <code>ABCABC</code> → <code>BCAABC</code> → <code>BCABCA</code> → <code>BCBCAA</code>. This is the maximum result.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>C </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>ABCACCBABCBCAABCB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6 </pre></section> </div> </span>
p01475
<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>1぀の陰関数 $Ax^2+Bxy+Cy^2+Dx+Ey+F=0$ で䞎えられる曲線ず、 $N$ 個の陰関数 $A_ix+B_iy+C_i=0$ で䞎えられる盎線がある。 これらの曲線ず盎線によっお平面がいく぀の領域に分割されおいるか求めよ。</p> <p>以䞋はSample Inputのデヌタセットを図瀺したものである。</p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_plane_division_sample1" width="240" height="240"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_plane_division_sample2" width="240" height="240"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_plane_division_sample3" width="240" height="240"> </p> <h2>入力</h2> <p>入力は以䞋の圢匏に埓う。䞎えられる数は党お敎数である。</p> <pre>$N$ $A$ $B$ $C$ $D$ $E$ $F$ $A_1$ $B_1$ $C_1$ $...$ $A_N$ $B_N$ $C_N$</pre> <h2>制玄</h2> <ul><li>$1 \leq N \leq 20$</li> <li>$-100 \leq A,B,C,D,E,F \leq 100$</li> <li>$-100 \leq A_i,B_i,C_i \leq 100$</li> <li>$A_i \neq 0$ たたは $B_i \neq 0$</li> <li>曲線は楕円(正円を含む)、攟物線、双曲線のいずれかである。</li> <li>同䞀の盎線が存圚する堎合がある。</li></ul> <h2>出力</h2> <p>領域の数を1行に出力せよ。</p> <h2>Sample Input 1</h2> <pre>1 1 0 1 0 0 -1 1 -1 0</pre> <h2>Output for the Sample Input 1</h2> <pre>4</pre> <h2>Sample Input 2</h2> <pre>2 1 0 0 0 -1 0 2 -1 -1 6 9 1</pre> <h2>Output for the Sample Input 2</h2> <pre>7</pre> <h2>Sample Input 3</h2> <pre>2 1 0 -1 0 0 -1 3 0 6 -5 0 -10</pre> <h2>Output for the Sample Input 3</h2> <pre>6</pre>
p03448
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have <var>A</var> <var>500</var>-yen coins, <var>B</var> <var>100</var>-yen coins and <var>C</var> <var>50</var>-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are <var>X</var> yen in total?</p> <p>Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq A, B, C \leq 50</var></li> <li><var>A + B + C \geq 1</var></li> <li><var>50 \leq X \leq 20</var> <var>000</var></li> <li><var>A</var>, <var>B</var> and <var>C</var> are integers.</li> <li><var>X</var> is a multiple of <var>50</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> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to select coins.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two ways to satisfy the condition:</p> <ul> <li>Select zero <var>500</var>-yen coins, one <var>100</var>-yen coin and zero <var>50</var>-yen coins.</li> <li>Select zero <var>500</var>-yen coins, zero <var>100</var>-yen coins and two <var>50</var>-yen coins.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 0 150 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Note that the total must be exactly <var>X</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>30 40 50 6000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>213 </pre></section> </div> </span>
p02609
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>\mathrm{popcount}(n)</var> be the number of <code>1</code>s in the binary representation of <var>n</var>. For example, <var>\mathrm{popcount}(3) = 2</var>, <var>\mathrm{popcount}(7) = 3</var>, and <var>\mathrm{popcount}(0) = 0</var>.</p> <p>Let <var>f(n)</var> be the number of times the following operation will be done when we repeat it until <var>n</var> becomes <var>0</var>: "replace <var>n</var> with the remainder when <var>n</var> is divided by <var>\mathrm{popcount}(n)</var>." (It can be proved that, under the constraints of this problem, <var>n</var> always becomes <var>0</var> after a finite number of operations.)</p> <p>For example, when <var>n=7</var>, it becomes <var>0</var> after two operations, as follows:</p> <ul> <li><var>\mathrm{popcount}(7)=3</var>, so we divide <var>7</var> by <var>3</var> and replace it with the remainder, <var>1</var>.</li> <li><var>\mathrm{popcount}(1)=1</var>, so we divide <var>1</var> by <var>1</var> and replace it with the remainder, <var>0</var>.</li> </ul> <p>You are given an integer <var>X</var> with <var>N</var> digits in binary. For each integer <var>i</var> such that <var>1 \leq i \leq N</var>, let <var>X_i</var> be what <var>X</var> becomes when the <var>i</var>-th bit from the top is inverted. Find <var>f(X_1), f(X_2), \ldots, f(X_N)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>X</var> is an integer with <var>N</var> digits in binary, possibly with leading zeros.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain the value <var>f(X_i)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 011 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 1 </pre> <ul> <li><var>X_1 = 7</var>, which will change as follows: <var>7 \rightarrow 1 \rightarrow 0</var>. Thus, <var>f(7) = 2</var>.</li> <li><var>X_2 = 1</var>, which will change as follows: <var>1 \rightarrow 0</var>. Thus, <var>f(1) = 1</var>.</li> <li><var>X_3 = 2</var>, which will change as follows: <var>2 \rightarrow 0</var>. Thus, <var>f(2) = 1</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>23 00110111001011011001110 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 3 </pre></section> </div> </span>
p00634
<H1><font color="#000000">Problem 08:</font> Provident Housewife</H1> <p> 䞻婊の琎子はこの䞍況のさなか食費を抑えるこずに闘志を燃やしおいたした。毎朝新聞広告を必ずチェック。買う物リストず最も安く売られおいるお店をしっかりリストアップしお、お店をはしごしながら、゚プロン・サンダルずいう戊闘スタむルで自転車をこぎこぎ買い物に行きたす。 </p> <p> そこで倫のあなたは少しでも琎子の圹に立ずうず、埗意のプログラミングで家蚈簿プログラムを䜜成するこずにしたした。プログラムは、各スヌパヌに売っおいる品物の名前ず倀段円、琎子が必芁な品物を入力し、党おの品物を集めるための最小金額を出力したす。 </p> <p> 琎子は家を出お必芁な品物を集め、家に戻っおこなければなりたせん。 そこで、琎子を気遣ったあなたは、最小金額が同じになる買い物ルヌトが耇数ある堎合も考慮しお、より距離が短くなるルヌトの距離を報告する機胜を远加するこずにしたした。埓っお、プログラムはスヌパヌ・家間を繋ぐ道の情報も入力したす。 </p> <p> スヌパヌの数を <i>n</i> ずし、各スヌパヌにはそれぞれ 1 から <i>n</i> たでの番号が割り圓おられたす。さらに琎子の家を 0 番ずしたす。道の情報はこれらの番号のペアずその距離敎数で䞎えられたす。 </p> <H2>Input</H2> <p> 入力ずしお耇数のデヌタセットが䞎えられたす。各デヌタセットの圢匏は以䞋の通りです<br> <br> <i>n</i> スヌパヌの数敎数<br> <i>k</i><sub>1</sub> <i>name</i><sub>1</sub> <i>value</i><sub>1</sub> <i>name</i><sub>2</sub> <i>value</i><sub>2</sub> . . . <i>name</i><sub><i>k</i><sub>1</sub></sub> <i>value</i><sub><i>k</i><sub>1</sub></sub>1 番目のスヌパヌにある品物の皮類の数、1぀目の品物名ず倀段、2぀目の品物名ず倀段,,,敎数ず文字列の空癜区切り<br> <i>k</i><sub>2</sub> <i>name</i><sub>1</sub> <i>value</i><sub>1</sub> <i>name</i><sub>2</sub> <i>value</i><sub>2</sub> . . . <i>name</i><sub><i>k</i><sub>2</sub></sub> <i>value</i><sub><i>k</i><sub>2</sub></sub>2 番目のスヌパヌにある品物の皮類の数、1぀目の品物名ず倀段、2぀目の品物名ず倀段,,,敎数ず文字列の空癜区切り<br> .<br> .<br> <i>k</i><sub><i>n</i></sub> <i>name</i><sub>1</sub> <i>value</i><sub>1</sub> <i>name</i><sub>2</sub> <i>value</i><sub>2</sub> . . . <i>name</i><sub><i>k</i><sub><i>n</i></sub></sub> <i>value</i><sub><i>k</i><sub><i>n</i></sub></sub><i>n</i> 番目のスヌパヌにある品物の皮類の数、1぀目の品物名ず倀段、2぀目の品物名ず倀段,,,敎数ず文字列の空癜区切り<br> <i>q</i> 必芁な品物の数敎数<br> <i>name</i><sub>1</sub> 1 ぀目の必芁な品物の名前文字列<br> <i>name</i><sub>2</sub> 2 ぀目の必芁な品物の名前文字列<br> .<br> .<br> <i>name</i><sub><i>q</i></sub> <i>q</i> ぀目の必芁な品物の名前文字列<br> <i>m</i> 道の数敎数<br> <i>s</i><sub>1</sub> <i>t</i><sub>1</sub> <i>d</i><sub>1</sub> 1 本目の道の情報空癜区切りの敎数<br> <i>s</i><sub>2</sub> <i>t</i><sub>2</sub> <i>d</i><sub>2</sub> 2 本目の道の情報空癜区切りの敎数<br> .<br> .<br> <i>s</i><sub><i>m</i></sub> <i>t</i><sub><i>m</i></sub> <i>d</i><sub><i>m</i></sub> <i>m</i> 本目の道の情報空癜区切りの敎数<br> </p> <p> <i>s<sub>i</sub></i> <i>t<sub>i</sub></i> <i>d<sub>i</sub></i> は <i>s<sub>i</sub></i>番目のスヌパヌたたは家ず <i>t<sub>i</sub></i>番目のスヌパヌたたは家が双方向に行き来するこずができ、その距離が <i>d<sub>i</sub></i>であるこずを瀺したす。 </p> <p> 家からスヌパヌを経由しお党おのスヌパヌぞ行くこずができるような道が䞎えられたす。 </p> <p> <i>n</i> は 10 以䞋であり、<i>q</i> は 15 以䞋ずしたす。 <i>k<sub>i</sub></i> は 100 以䞋であり、 品物名の文字列は 20文字を越ず、品物の倀段は 10000 を越えたせん。 たた、道の長さは 1000 を越えたせん。 </p> <p> <i>n</i> が 0 のずき、入力の終わりずしたす。 </p> <H2>Output</H2> <p> 各デヌタセットに぀いお、最小の金額ず距離を぀の空癜で区切っお行に出力しお䞋さい。ただし、必芁な品物を党お集められない堎合は "<span>impossible</span>" ず出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 3 3 apple 100 banana 200 egg 300 3 apple 150 banana 100 cola 200 3 apple 100 banana 150 cola 200 3 apple banana cola 5 0 2 4 0 1 3 0 3 3 1 2 3 2 3 5 3 3 apple 100 banana 200 egg 300 3 apple 150 banana 100 cola 200 3 apple 100 banana 150 cola 200 4 apple banana cola jump 5 0 2 4 0 1 3 0 3 3 1 2 3 2 3 5 0 </pre> <H2>Output for the Sample Input</H2> <pre> 400 10 impossible </pre>
p01926
<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>あなたは冒険ゲヌムを䜜成しおいるこのゲヌムのプレむダヌは䞻人公を操䜜しお敵モンスタヌを倒し䞻人公のレベルを䞊げるこずで冒険を進めおいく䞻人公の初期レベルは 1 である </p> <p>このゲヌムには <i>N</i> 皮類の敵モンスタヌが甚意されおおり匱い順で <i>i</i> 番目の皮類の敵モンスタヌの匷さは <i>s<sub>i</sub></i> である䞻人公が 1 回の戊闘を行うずきには次に戊う敵モンスタヌの皮類を自由に遞びちょうど 1 䜓の敵モンスタヌず戊闘を行う䞻人公は同じ皮類の敵モンスタヌず䜕回でも戊うこずができ䜕回でも倒すこずができる </p> <p>あなたはいたこのゲヌムのバランスを調敎するためにあるパラメヌタヌ <i>X</i> を決めようずしおいるパラメヌタヌ <i>X</i> は正の敎数であり䞋蚘のように䜿われる </p> <ul><li> 䞻人公のレベルが <i>L</i> のずき匷さ <i>s<sub>i</sub></i> が <i>L+X</i> 未満の敵は倒せるがそれより匷い敵モンスタヌは倒せない </li><li> 䞻人公のレベルが <i>L</i> のずき匷さ <i>s<sub>i</sub></i> の敵を倒すず <i>max(1, X-|L-s<sub>i</sub>|)</i> だけ䞻人公のレベルが䞊がる </li></ul> <p>このゲヌムは最も匷い<i>N</i> 皮類目の敵モンスタヌを初めお倒したずきにゲヌムクリアずなるあなたはゲヌムクリアたでに必芁ずなる戊闘の回数が最䜎でも <i>M</i> 回以䞊ずなるようにパラメヌタヌ <i>X</i> を決めたいず考えおいるただし敵モンスタヌの匷さの蚭定によっおは<i>X</i> をどのように蚭定しおも <i>M</i> 回未満の戊闘回数でゲヌムクリアできおしたうかゲヌムをクリアできなくなっおしたう堎合があるこずに泚意せよ </p> <p>パラメヌタヌ <i>X</i> を決めるずき䞊蚘の条件を満たす範囲で最倧のパラメヌタヌ倀 <i>X<sub>max</sub></sub></i> を蚈算するプログラムを䜜っおほしい </p> <h3>Input</h3> <blockquote></blockquote> <p>入力は耇数のデヌタセットから構成されるデヌタセットの個数は最倧でも 50 を超えない各デヌタセットは次の圢匏で衚される </p><blockquote><i>N</i> <i>M</i><br><i>s<sub>1</sub></i> <i>s<sub>2</sub></i> ... <i>s<sub>N</sub></i><br></blockquote> <p>1 行目は空癜で区切られた 2 ぀の敎数 <i>N, M</i> からなる<i>N</i> は甚意した敵モンスタヌの皮類の数<i>M</i> はゲヌムクリアたでに必芁ずなるべき最小の戊闘の数であり<i>1 &le; N &le; 100,000</i>, <i>2 &le; M &le;1,000,000</i> を満たす </p><blockquote></blockquote> <p>2 行目は空癜で区切られた <i>N</i> 個の敎数 <i>s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>N</sub></i> からなり<i>N</i> 皮類の敵モンスタヌそれぞれの匷さを衚す各 <i>s<sub>i</sub></i> は <i>1 &le; s<sub>i</sub> &le; 1,000,000</i> を満たしたた <i>s<sub>i</sub> < s<sub>i+1</sub></i> (<i>1 &le; i &le; N-1</i>) である </p><blockquote></blockquote> <p>入力の終わりは空癜で区切られた 2 ぀のれロからなる行で衚される </p><blockquote></blockquote> <h3>Output</h3> <blockquote></blockquote> <p>各デヌタセットに぀いおゲヌムクリアたでに必芁ずなる戊闘の回数が <i>M</i> 回以䞊ずなるパラメヌタヌ <i>X</i> の内の最倧倀 <i>X<sub>max<sub></sub></i> を敎数で出力せよ<i>X</i> をどのように蚭定しおも <i>M</i> 回未満の戊闘回数でゲヌムクリアできおしたうかゲヌムをクリアできなくなっおしたうテストケヌスの堎合には <i>-1</i> のみからなる行を出力せよ </p><blockquote></blockquote> <h3>Sample Input</h3> <pre>3 4 1 5 9 1 2 1 2 10 1 1000000 2 4 1 10 0 0 </pre> <h3>Output for Sample Input</h3> <pre>3 -1 499996 4</pre> <p> 2 番目のテストケヌスでは<i>X</i> = 1 ず蚭定するず 1 回の戊闘でゲヌムをクリアできおしたう このケヌスでは必芁ずなる戊闘の回数が <i>M</i> 回以䞊でありか぀ゲヌムをクリアできるように <i>X</i> を蚭定するこずが出来ない よっお -1 のみからなる行を出力する </p>
p02259
<H1>Bubble Sort</H1> <p> Write a program of the Bubble Sort algorithm which sorts a sequence <i>A</i> in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] </pre> <p> Note that, indices for array elements are based on 0-origin. </p> <p> Your program should also print the number of swap operations defined in line 4 of the pseudocode. </p> <H2>Input</H2> <p> The first line of the input includes an integer <i>N</i>, the number of elements in the sequence. </p> <p> In the second line, <i>N</i> elements of the sequence are given separated by spaces characters. </p> <H2>Output</H2> <p> The output consists of 2 lines. </p> <p> In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. </p> <p> In the second line, please print the number of swap operations. </p> <H2>Constraints</H2> <p> 1 &le; <i>N</i> &le; 100 </p> <H2>Sample Input 1</H2> <pre> 5 5 3 2 4 1 </pre> <H2>Sample Output 1</H2> <pre> 1 2 3 4 5 8 </pre> <br/> <H2>Sample Input 2</H2> <pre> 6 5 2 4 6 1 3 </pre> <H2>Sample Output 2</H2> <pre> 1 2 3 4 5 6 9 </pre>
p00264
<H1>颚よ、私の梅の銙りを届けおおくれ</H1> <p> 匕っ越しが決たり、この地を去るこずになった。この土地自䜓に未緎は無いが、぀だけ気になるこずがある。それは、庭に怍えた梅の朚のこずだ。私は毎幎、この梅が花を咲かすこずを楜しみにしおいた。ここを離れた埌は春の楜しみが぀枛っおしたう。私の梅の銙りだけでも颚に乗っお匕っ越し先の家たで届き、春を楜したせおはくれないものか。 </p> <p> 日本には春を象城する぀の花がある。梅・桃・桜の぀だ。匕っ越し先には、私の梅以倖にも、これらの花の銙りが届くだろう。しかし、私の梅の銙りだけが届く日数が最も倚い家に䜏みたい。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kochi" width="380"> </center> <br/> <p> 図のように、花の銙りは扇状に広がり、その領域は颚の向かう方向ず匷さによっお決たる。扇圢は颚の向かう方向 w を䞭心にしお察称に広がり、颚の匷さ a を半埄ずする領域をも぀。銙りが広がる角床 d は花の皮類によっお決たっおいるが、颚の向かう方向ず匷さは日によっお異なる。ただし、同じ日では、すべおの堎所で颚の向かう方向ず匷さは同じである。 </p> <p> 手元には、私の梅以倖の梅・桃・桜の䜍眮ず花の皮類ごずの銙りが広がる角床、匕っ越し先の家の候補のデヌタがある。さらに、数日分の颚の向かう方向ず匷さのデヌタもある。私の梅以倖の梅・桃・桜の朚ず家の䜍眮は、私の梅の䜍眮を原点ずした座暙で瀺されおいる。 </p> <p> これらのデヌタを䜿っお、私の梅の銙りだけが届く日数の最も倚い家を探すためのプログラムを曞いおみるこずずしよう。私は有胜なプログラマヌなのだから </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる。入力の終わりはれロ぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 </p> <pre> H R hx<sub>1</sub> hy<sub>1</sub> hx<sub>2</sub> hy<sub>2</sub> : hx<sub>H</sub> hy<sub>H</sub> U M S du dm ds ux<sub>1</sub> uy<sub>1</sub> ux<sub>2</sub> uy<sub>2</sub> : ux<sub>U</sub> uy<sub>U</sub> mx<sub>1</sub> my<sub>1</sub> mx<sub>2</sub> my<sub>2</sub> : mx<sub>M</sub> my<sub>M</sub> sx<sub>1</sub> sy<sub>1</sub> sx<sub>2</sub> sy<sub>2</sub> : sx<sub>S</sub> sy<sub>S</sub> w<sub>1</sub> a<sub>1</sub> w<sub>2</sub> a<sub>2</sub> : w<sub>R</sub> a<sub>R</sub> </pre> <p> 各行で䞎えられる数倀は぀の空癜で区切られおいる。 </p> <p> 行目に匕っ越し先の家の候補の数 H (1 &le; H &le; 100) ず颚の蚘録の数 R (1 &le; R &le; 100) が䞎えられる。続くH 行に匕っ越し先の家の䜍眮が䞎えられる。hx<sub>i</sub> ずhy<sub>i</sub>は i 番目の家の x 座暙ず y 座暙を瀺す-1000 以䞊1000 以䞋の敎数である。 </p> <p> 続く行に、私の梅以倖の梅の朚の数 U ず、桃・桜の朚の数 M、S、梅・桃・桜の銙りが広がる角床du、dm、ds が䞎えられる。U、M、S の範囲は 0 以䞊10 以䞋である。角床の単䜍は床であり、1 以䞊180 未満の敎数である。 <?p> 続く U 行に私の梅以倖の梅の朚の䜍眮、続く M 行に桃の朚の䜍眮、続く S 行に桜の朚の䜍眮が䞎えられる。uxi ず uyi、mxi ず myi、sxi ず syi はそれぞれ、i 番目の梅・桃・桜の朚の x 座暙ず y 座暙を瀺す、-1000 以䞊 1000 以䞋の敎数である。 </p> <p> 続く R 行に颚の蚘録が䞎えられる。w<sub>i</sub> (0 &le; w<sub>i</sub> &lt; 360) ず a<sub>i</sub>(0 &lt; a<sub>i</sub> &le; 100) は i 日目の颚の向かう方向ず匷さを衚す敎数である。颚の向かう方向は、x 軞の正の向きから反時蚈回りに枬った角床で衚し、単䜍は床ずする。 </p> <p> 入力は以䞋の条件を満たすず考えおよい。 </p> <ul> <li> 入力される座暙はすべお異なるものずする。</li> <li> 原点には私の梅以倖無い。</li> <li> どの花に぀いおも、花の銙りが届く領域の境界から距離が 0.001 以内には家は無い。</li> </ul> <p> デヌタセットの数は 50 を超えない。 </p> <h2>出力</h2> <p> デヌタセットごずに、私の梅の銙りだけが届く日数の最も倚い党おの家の番号を、小さい順に行に出力する。家の番号の間は空癜぀で区切る。行の終わりには空癜文字を出力しない。 </p> <p> ただし、どの家に぀いおも、私の梅の花の銙りだけが届く日が日もなければ、NA ず出力する。 </p> <h2>入力䟋</h2> <pre> 6 3 2 1 1 2 5 2 1 3 1 5 -2 3 1 1 1 90 30 45 3 -4 -3 0 2 -2 45 6 90 6 135 6 2 1 1 3 5 2 0 1 1 90 30 45 -3 0 2 -2 45 6 0 0 </pre> <h2>出力䟋</h2> <pre> 5 6 NA </pre>
p00771
<h3>Anchored Balloon</h3> <p> A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_anchoredBalloon-1"> <br> Figure E-1: A balloon and ropes on the ground </center> <p> Now the balloon takes off, and your task is to find how high the balloon can go up with keeping the rope connections. The positions of the anchors are fixed. The lengths of the ropes and the positions of the anchors are given. You may assume that these ropes have no weight and thus can be straightened up when pulled to whichever directions. Figure E-2 shows the highest position of the balloon for the situation shown in Figure E-1. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_anchoredBalloon-2"> <br> Figure E-2: The highest position of the balloon </center> <h3>Input</h3> <p> The input consists of multiple datasets, each in the following format. </p> <blockquote> <i>n</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>l</i><sub>1</sub> <br> ... <br> <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>l</i><sub><i>n</i></sub> <br> </blockquote> <p> The first line of a dataset contains an integer <i>n</i> (1 &le; <i>n</i> &le; 10) representing the number of the ropes. Each of the following <i>n</i> lines contains three integers, <i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>, and <i>l</i><sub><i>i</i></sub>, separated by a single space. <i>P</i><sub><i>i</i></sub> = (<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>) represents the position of the anchor connecting the <i>i</i>-th rope, and <i>l</i><sub><i>i</i></sub> represents the length of the rope. You can assume that &minus;100 &le; <i>x</i><sub><i>i</i></sub> &le; 100, &minus;100 &le; <i>y</i><sub><i>i</i></sub> &le; 100, and 1 &le; <i>l</i><sub><i>i</i></sub> &le; 300. The balloon is initially placed at (0, 0) on the ground. You can ignore the size of the balloon and the anchors. </p> <p> You can assume that <i>P</i><sub><i>i</i></sub> and <i>P</i><sub><i>j</i></sub> represent different positions if <i>i</i> &ne; <i>j</i>. You can also assume that the distance between <i>P</i><sub><i>i</i></sub> and (0, 0) is less than or equal to <i>l</i><sub><i>i</i></sub>&minus;1. This means that the balloon can go up at least 1 unit high. </p> <p> Figures E-1 and E-2 correspond to the first dataset of Sample Input below. </p> <p> The end of the input is indicated by a line containing a zero. </p> <h3>Output</h3> <p> For each dataset, output a single line containing the maximum height that the balloon can go up. The error of the value should be no greater than 0.00001. No extra characters should appear in the output. </p> <h3>Sample Input</h3> <pre> 3 10 10 20 10 -10 20 -10 10 120 1 10 10 16 2 10 10 20 10 -10 20 2 100 0 101 -90 0 91 2 0 0 53 30 40 102 3 10 10 20 10 -10 20 -10 -10 20 3 1 5 13 5 -3 13 -3 -3 13 3 98 97 168 -82 -80 193 -99 -96 211 4 90 -100 160 -80 -80 150 90 80 150 80 80 245 4 85 -90 290 -80 -80 220 -85 90 145 85 90 170 5 0 0 4 3 0 5 -3 0 5 0 3 5 0 -3 5 10 95 -93 260 -86 96 211 91 90 177 -81 -80 124 -91 91 144 97 94 165 -90 -86 194 89 85 167 -93 -80 222 92 -84 218 0 </pre> <h3>Output for the Sample Input</h3> <pre> 17.3205081 16.0000000 17.3205081 13.8011200 53.0000000 14.1421356 12.0000000 128.3928757 94.1879092 131.1240816 4.0000000 72.2251798 </pre>
p01863
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>--> <h2>F: みこみヌ文字列 - Miko Mi String -</h2> <h3>物語</h3> <p>みっこみっこみ〜みんなのアむドル田柀みこみこ今日は〜みこず䞀緒に〜文字列アルゎリズムの緎習しよ☆</p> <p>みこのずっおおきの<s>キャラ䜜り</s>合蚀葉「みっこみっこみ〜」はロヌマ字にするず “MikoMikoMi” になるみこ぀たり<var>A=</var>“Mi”, <var>B=</var>“Ko” ずするず<var>ABABA</var>の圢で曞けるっおこずなのこんな颚に適切に<var>A</var>ず<var>B</var>を決めるず<var>ABABA</var>の圢に分解できる文字列のこずを「みこみヌ文字列」っお蚀うわ文字列の名前にたでなっちゃうなんおみこはみんなの人気者みこね</p> <p>みんなでみこみヌ文字列をも〜っず䜿っおいくために䞎えられた文字列がみこみヌ文字列かどうか刀定するプログラムを䜜るこずにしたんだけどみこFizzBuzzより長いプログラムなんお曞けな〜いだから〜みこのために〜みこみヌ文字列を刀定するプログラムを曞いお欲しいな☆</p> <p>  アンタいた寒いっお蚀った</p> <h3>問題</h3> <p> アルファベット倧文字・小文字からなる文字列<var>S</var>が䞎えられる ここで<var>S = ABABA</var>ず曞けるような空でない2぀の文字列<var>A, B</var>が存圚するならば<var>S</var>は「みこみヌ文字列」であるずいう このずきアルファベットの倧文字ず小文字は違う文字ずしお区別するものずする 䞎えられた文字列がみこみヌ文字列であるかどうかを刀定するプログラムを䜜成せよ </p> <h3>入力圢匏</h3> <p> 入力は文字列<var>S</var>を含む1行のみからなる <var>S</var>は以䞋の条件を満たすず仮定しおよい </p> <ul> <li><var>1 &le; |S| &le; 10^6</var>ただし<var>|S|</var>は文字列<var>S</var>の長さを衚す</li> <li><var>S</var>は倧文字もしくは小文字のアルファベットのみからなる</li> </ul> <p>なお入力が非垞に倧きくなる堎合があるため入力の受け取りには高速な関数を甚いるこずを掚奚する</p> <h3>出力圢匏</h3> <p> <var>S</var>がみこみヌ文字列であるならば<var>S = ABABA</var>を満たすような<var>A, B</var>に぀いお“Love <var>AB</var>!”ず出力せよただし耇数の<var>A, B</var>の組が条件を満たす堎合<var>|AB|</var>が最小のものを出力せよ <var>S</var>がみこみヌ文字列でないならば“mitomerarenaiWA”ず出力せよ </p> <h3>入力䟋1</h3> <pre>NicoNicoNi</pre> <h3>出力䟋1</h3> <pre>Love Nico!</pre> <h3>入力䟋2</h3> <pre>KashikoiKawaiiElichika</pre> <h3>出力䟋2</h3> <pre>mitomerarenaiWA</pre> <h3>入力䟋3</h3> <pre>LiveLiveL</pre> <h3>出力䟋3</h3> <pre>Love Live!</pre> <h3>入力䟋4</h3> <pre>AizunyanPeroPero</pre> <h3>出力䟋4</h3> <pre>mitomerarenaiWA</pre> <h3>入力䟋5</h3> <pre>AAAAAAAAAAAAAA</pre> <h3>出力䟋5</h3> <pre>Love AAAAA!</pre>
p00321
<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> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>F</var> <var>info<sub>1</sub></var> <var>info<sub>2</sub></var> : <var>info<sub>N</sub></var> </pre> <p> 行目に、䞀緒に買われた商品の情報の数 <var>N</var> (1 &le; <var>N</var> &le; 100) ず、基準回数 <var>F</var> (1 &le; <var>F</var> &le; 100) が䞎えられる。続く <var>N</var>行に、䞀緒に買われた商品の情報が䞎えられる。䞀緒に買われた商品の情報 <var>info<sub>i</sub></var> は、以䞋の圢匏で䞎えられる。 </p> <pre> <var>M</var> <var>item<sub>1</sub></var> <var>item<sub>2</sub></var> ... <var>item<sub>M</sub></var> </pre> <p> <var>M</var> (1 &le; <var>M</var> &le; 10) は、この情報がいく぀の商品を含むかを衚す。<var>item<sub>j</sub></var> は、この買い物で買われた商品の名前であり、英小文字だけから成る長さ 1 以䞊 30 以䞋の文字列である。<var>info<sub>i</sub></var> の䞭に同じ商品が䞎えられるこずはない。 </p> <h2>Output</h2> <p> 行目に基準回数以䞊䞀緒に買われた商品぀の組み合わせの数を出力し、行目以降に組み合わせをすべお出力する。ただし、組み合わせが䞀぀もない堎合は行目以降には䜕も出力しない。 </p> <p> 出力の順番は、組み合わせ内の商品名どうしを、蟞曞匏順序英和蟞曞で単語が䞊んでいる順番で䞊べたあず、組み合わせどうしに぀いおは以䞋のようにする。 </p> <ul> <li> 䞀぀目の商品名どうしを比范しお、蟞曞匏順序で早いほうが先。</li> <li> 同じ堎合は、二぀目の商品名どうしを比范しお、蟞曞匏順序で早いほうが先。</li> </ul> <p> 商品名はスペヌス䞀぀で区切り、商品の組み合わせは改行䞀぀で区切る。 </p> <h2>Sample Input 1</h2> <pre> 5 2 3 bread milk banana 2 milk cornflakes 3 potato bread milk 4 cornflakes bread milk butter 2 potato bread </pre> <h2>Sample Output 1</h2> <pre> 3 bread milk bread potato cornflakes milk </pre> <br/> <h2>Sample Input 2</h2> <pre> 5 5 3 bread milk banana 2 milk cornflakes 3 potato bread milk 4 cornflakes bread milk butter 2 potato bread </pre> <h2>Sample Output 2</h2> <pre> 0 </pre>
p01160
<H1><font color="#000">Problem F:</font> It Prefokery Pio</H1> <p> You are a member of a secret society named <i>Japanese Abekobe Group</i>, which is called J. A. G. for short. Those who belong to this society often exchange encrypted messages. You received lots of encrypted messages this morning, and you tried to decrypt them as usual. However, because you received so many and long messages today, you had to give up decrypting them by yourself. So you decided to decrypt them with the help of a computer program that you are going to write. </p> <p> The encryption scheme in J. A. G. utilizes palindromes. A palindrome is a word or phrase that reads the same in either direction. For example, “MADAM”, “REVIVER” and “SUCCUS” are palindromes, while “ADAM”, “REVENGE” and “SOCCER” are not. </p> <p> Specifically to this scheme, words and phrases made of only one or two letters are not regarded as palindromes. For example, “A” and “MM” are not regarded as palindromes. </p> <p> The encryption scheme is quite simple: each message is encrypted by inserting extra letters in such a way that the longest one among all subsequences forming palindromes gives the original message. In other words, you can decrypt the message by extracting the <i>longest palindrome subsequence</i>. Here, a subsequence means a new string obtained by picking up some letters from a string without altering the relative positions of the remaining letters. For example, the longest palindrome subsequence of a string “YMAOKDOAMIMHAADAMMA” is “MADAMIMADAM” as indicated below by underline. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_prefokery"> <p> Now you are ready for writing a program. </p> <H2>Input</H2> <p> The input consists of a series of data sets. Each data set contains a line made of up to 2,000 capital letters which represents an encrypted string. </p> <p> The end of the input is indicated by EOF (end-of-file marker). </p> <H2>Output</H2> <p> For each data set, write a decrypted message in a separate line. If there is more than one decrypted message possible (i.e. if there is more than one palindrome subsequence not shorter than any other ones), you may write any of the possible messages. </p> <p> You can assume that the length of the longest palindrome subsequence of each data set is always longer than two letters. </p> <H2>Sample Input</H2> <pre> YMAOKDOAMIMHAADAMMA LELVEEL </pre> <H2>Output for the Sample Input</H2> <pre> MADAMIMADAM LEVEL </pre>
p01530
<h1>K - XOR回廊</h1> <h2>問題文</h2> <p> KU倧孊では䞀颚倉わったラリヌゲヌムが人気である このゲヌムの舞台であるサヌキットには<var>N</var> 個の䌑憩所ず <var>M</var> 個の道があり<var>i</var> 番目の道は <var>f<sub>i</sub></var> 番目の䌑憩所ず <var>t<sub>i</sub></var> 番目の䌑憩所の間にある すべおの道にはチェックポむントが䞀぀ず぀存圚し道 <var>i</var> のチェックポむントを通過するずどちらの向きで通っおも <var>p<sub>i</sub></var> の埗点がXORで加算される<strong>XORで</strong>加算される倧事なこずなので2回蚀いたした </p> <p> このゲヌムでは同じ䌑憩所や道を䜕床通っおも良いし ゎヌルにたどり着いおもそのたたラリヌを続行するこずができるが 道の途䞭にあるチェックポむントを迂回しお別の䌑憩所ぞ行くこずは犁止されおいる そのためどのような道順をたどれば高い埗点を取るこずができるかを頑匵っお考えなければならない点が人気のある所以である </p> <p> 今回は <var>Q</var> 人の参加者がいお<var>j</var> 番目の参加者は <var>a<sub>j</sub></var> の䌑憩所からスタヌトしおゎヌルである <var>b<sub>j</sub></var> の䌑憩所たで行くこずになっおいるようだ 運営偎の人間ずしおそれぞれの参加者の最高埗点を前もっお調べおおくこずにした </p> <h2>入力圢匏</h2> <p>入力は以䞋の圢匏で䞎えられるなお䌑憩所の番号は0-indexedである</p> <pre> <var>N</var> <var>M</var> <var>Q</var> <var>f<sub>1</sub></var> <var>t<sub>1</sub></var> <var>p<sub>1</sub></var> <var>...</var> <var>f<sub>M</sub></var> <var>t<sub>M</sub></var> <var>p<sub>M</sub></var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>...</var> <var>a<sub>Q</sub></var> <var>b<sub>Q</sub></var> </pre> <h2>出力圢匏</h2> <p> <var>Q</var> 行出力し<var>j</var> 行目には <var>a<sub>j</sub></var> 番目の䌑憩所から <var>b<sub>j</sub></var> 番目の䌑憩所ぞの経路で埗られる埗点の最倧倀を出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; N &le; 10<sup>5</sup></var></li> <li><var>0 &le; M &le; 2 &times; 10<sup>5</sup></var></li> <li><var>1 &le; Q &le; 10<sup>5</sup></var></li> <li><var>0 &le; f<sub>i</sub>, t<sub>i</sub> &lt; N</var>, <var>f<sub>i</sub> &ne; t<sub>i</sub></var></li> <li><var>0 &le; p<sub>i</sub> &lt; 2<sup>60</sup></var></li> <li><var>0 &le; a<sub>j</sub>, b<sub>j</sub> &lt; N</var></li> <li>どの䌑憩所からでも道を蟿っおいけば任意の䌑憩所ぞたどり着ける</li> <li>䌑憩所 <var>f<sub>i</sub>,t<sub>i</sub></var> 間を結ぶ道は高々䞀぀しか存圚しない</li> <li>入力倀はすべお敎数である</li> </ul> <p>この問題の刀定には60 点分のテストケヌスのグルヌプが蚭定されおいるこのグルヌプに含たれるテストケヌスは䞊蚘の制玄に加えお䞋蚘の制玄も満たす</p> <ul> <li><var>M &le; 20</var></li> </ul> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 5 5 3 0 1 7 1 2 22 2 3 128 3 4 128 4 2 128 0 1 0 0 3 4 </pre> <h3>出力䟋1</h3> <pre> 135 128 128 </pre> <hr> <address>Writer : 森槙悟</address> <address>Tester : 田村和範</address>
p03798
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke, who loves animals, built a zoo.</p> <p>There are <var>N</var> animals in this zoo. They are conveniently numbered <var>1</var> through <var>N</var>, and arranged in a circle. The animal numbered <var>i (2≀i≀N-1)</var> is adjacent to the animals numbered <var>i-1</var> and <var>i+1</var>. Also, the animal numbered <var>1</var> is adjacent to the animals numbered <var>2</var> and <var>N</var>, and the animal numbered <var>N</var> is adjacent to the animals numbered <var>N-1</var> and <var>1</var>.</p> <p>There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.</p> <p>Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered <var>i</var> answered <var>s_i</var>. Here, if <var>s_i</var> is <code>o</code>, the animal said that the two neighboring animals are of the same species, and if <var>s_i</var> is <code>x</code>, the animal said that the two neighboring animals are of different species.</p> <p>More formally, a sheep answered <code>o</code> if the two neighboring animals are both sheep or both wolves, and answered <code>x</code> otherwise. Similarly, a wolf answered <code>x</code> if the two neighboring animals are both sheep or both wolves, and answered <code>o</code> otherwise.</p> <p>Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print <code>-1</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 ≀ N ≀ 10^{5}</var></li> <li><var>s</var> is a string of length <var>N</var> consisting of <code>o</code> and <code>x</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there does not exist an valid assignment that is consistent with <var>s</var>, print <code>-1</code>. Otherwise, print an string <var>t</var> in the following format. The output is considered correct if the assignment described by <var>t</var> is consistent with <var>s</var>.</p> <ul> <li><var>t</var> is a string of length <var>N</var> consisting of <code>S</code> and <code>W</code>.</li> <li>If <var>t_i</var> is <code>S</code>, it indicates that the animal numbered <var>i</var> is a sheep. If <var>t_i</var> is <code>W</code>, it indicates that the animal numbered <var>i</var> is a wolf.</li> </ul> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 ooxoox </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>SSSWWS </pre> <p>For example, if the animals numbered <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var> and <var>6</var> are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.</p> <p>Let us remind you: if the neiboring animals are of the same species, a sheep answers <code>o</code> and a wolf answers <code>x</code>. If the neiboring animals are of different species, a sheep answers <code>x</code> and a wolf answers <code>o</code>.</p> <div style="text-align: center;"> <img alt="b34c052fc21c42d2def9b98d6dccd05c.png" src="https://atcoder.jp/img/arc069/b34c052fc21c42d2def9b98d6dccd05c.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 oox </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>Print <code>-1</code> if there is no valid assignment of species.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 oxooxoxoox </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>SSWWSSSWWS </pre></section> </div> </span>
p03262
<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> cities on a number line. The <var>i</var>-th city is located at coordinate <var>x_i</var>.</p> <p>Your objective is to visit all these cities at least once.</p> <p>In order to do so, you will first set a positive integer <var>D</var>.</p> <p>Then, you will depart from coordinate <var>X</var> and perform Move <var>1</var> and Move <var>2</var> below, as many times as you like:</p> <ul> <li>Move <var>1</var>: travel from coordinate <var>y</var> to coordinate <var>y + D</var>.</li> <li>Move <var>2</var>: travel from coordinate <var>y</var> to coordinate <var>y - D</var>.</li> </ul> <p>Find the maximum value of <var>D</var> that enables you to visit all the cities.</p> <p>Here, to visit a city is to travel to the coordinate where that city is located.</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 X \leq 10^9</var></li> <li><var>1 \leq x_i \leq 10^9</var></li> <li><var>x_i</var> are all different.</li> <li><var>x_1, x_2, ..., x_N \neq X</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum value of <var>D</var> that enables you to visit all the cities.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 7 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Setting <var>D = 2</var> enables you to visit all the cities as follows, and this is the maximum value of such <var>D</var>.</p> <ul> <li>Perform Move <var>2</var> to travel to coordinate <var>1</var>.</li> <li>Perform Move <var>1</var> to travel to coordinate <var>3</var>.</li> <li>Perform Move <var>1</var> to travel to coordinate <var>5</var>.</li> <li>Perform Move <var>1</var> to travel to coordinate <var>7</var>.</li> <li>Perform Move <var>1</var> to travel to coordinate <var>9</var>.</li> <li>Perform Move <var>1</var> to travel to coordinate <var>11</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 81 33 105 57 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>24 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>999999999 </pre></section> </div> </span>
p03632
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Alice and Bob are controlling a robot. They each have one switch that controls the robot.<br/> Alice started holding down her button <var>A</var> second after the start-up of the robot, and released her button <var>B</var> second after the start-up.<br/> Bob started holding down his button <var>C</var> second after the start-up, and released his button <var>D</var> second after the start-up.<br/> For how many seconds both Alice and Bob were holding down their buttons?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0≀A&lt;B≀100</var></li> <li><var>0≀C&lt;D≀100</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format: </p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>0 75 25 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>50 </pre> <p>Alice started holding down her button <var>0</var> second after the start-up of the robot, and released her button <var>75</var> second after the start-up.<br/> Bob started holding down his button <var>25</var> second after the start-up, and released his button <var>100</var> second after the start-up.<br/> Therefore, the time when both of them were holding down their buttons, is the <var>50</var> seconds from <var>25</var> seconds after the start-up to <var>75</var> seconds after the start-up.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 33 66 99 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 90 20 80 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>60 </pre></section> </div> </span>
p02920
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have one slime.</p> <p>You can set the <em>health</em> of this slime to any integer value of your choice.</p> <p>A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.</p> <p>Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the <var>2^N</var> slimes that will exist in <var>N</var> seconds equals a multiset <var>S</var>.</p> <p>Here <var>S</var> is a multiset containing <var>2^N</var> (possibly duplicated) integers: <var>S_1,~S_2,~...,~S_{2^N}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 18</var></li> <li><var>1 \leq S_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S_1</var> <var>S_2</var> <var>...</var> <var>S_{2^N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the <var>2^N</var> slimes that will exist in <var>N</var> seconds equals <var>S</var>, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>We will show one way to make the multiset of the healths of the slimes that will exist in <var>2</var> seconds equal to <var>S</var>.</p> <p>First, set the health of the first slime to <var>4</var>.</p> <p>By letting the first slime spawn a slime whose health is <var>3</var>, the healths of the slimes that exist in <var>1</var> second can be <var>4,~3</var>.</p> <p>Then, by letting the first slime spawn a slime whose health is <var>2</var>, and letting the second slime spawn a slime whose health is <var>1</var>, the healths of the slimes that exist in <var>2</var> seconds can be <var>4,~3,~2,~1</var>, which is equal to <var>S</var> as multisets.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre> <p><var>S</var> may contain multiple instances of the same integer.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 1 </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>5 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre></section> </div> </span>
p02189
<h2>Min Element</h2> <p>数列<var>a_1,a_2,..,a_N</var>が䞎えられたす。</p> <p>この数列の最小倀の番号を求めおください。</p> <p>最小倀が耇数の堎所にあるずきは、番号の最も小さいものを答えおください。</p> <h3>入力</h3> <pre> <var>N</var> <var>a_1 a_2...a_N</var> </pre> <h3>出力</h3> <p><var>a_i</var>が数列の最小倀ずなるような<var>i</var>のうち、最も小さいものを出力せよ。</p> <h3>制玄</h3> <ul> <li><var>1 \leq N \leq 10^5 </var></li> <li><var>1 \leq a_i \leq 10^9</var></li> </ul> <h3>入力䟋</h3> <pre> 6 8 6 9 1 2 1 </pre> <h3>出力䟋</h3> <pre> 4 </pre>
p02473
<h2>Difference of Big Integers</h2> <p> Given two integers $A$ and $B$, compute the difference, $A - B$. </p> <h3>Input</h3> <p> Two integers $A$ and $B$ separated by a space character are given in a line. </p> <h3>Output</h3> <p> Print the difference in a line. </p> <h3>Constraints</h3> <ul> <li>$-1 \times 10^{100000} \leq A, B \leq 10^{100000}$</li> </ul> <h3>Sample Input 1</h3> <pre> 5 8 </pre> <h3>Sample Output 1</h3> <pre> -3 </pre> <h3>Sample Input 2</h3> <pre> 100 25 </pre> <h3>Sample Output 2</h3> <pre> 75 </pre> <h3>Sample Input 3</h3> <pre> -1 -1 </pre> <h3>Sample Output 3</h3> <pre> 0 </pre> <h3>Sample Input 4</h3> <pre> 12 -3 </pre> <h3>Sample Output 4</h3> <pre> 15 </pre>
p02023
<h2>I: 砎壊 (Ravage)</h2> <p>サンタクロヌスは、街のむルミネヌションに匕っかかり、壊した。</p> <p>むルミネヌションにはN個の電球があり、$i$ 番目の電球は電圧が $A_i$ 以䞊 $B_i$ 以䞋のずきにしか付かなくなっおしたった。</p> <p>電圧はむルミネヌションのどこでも同じにする必芁がある。</p> <p>電圧を調節するこずで、最倧いく぀の電球を同時に光らせるこずができるか求めよ。</p> <h3>入力</h3> <p>1 行目には敎数 $N$ が䞎えられる。</p> <p>続く $N$ 行のうち $i$ 行目には $A_i, B_i$ が空癜区切りで䞎えられる。</p> <h3>出力</h3> <p>同時に光らせるこずができる電球の個数の最倧倀を出力せよ。</p> <h3>制玄</h3> <ul> <li>$N$ は $1$ 以䞊 $100 \ 000$ 以䞋の敎数</li> <li>$A_1, A_2, A_3, \dots, A_N$ は $1$ 以䞊 $1 \ 000 \ 000 \ 000$ 以䞋の敎数</li> <li>$B_1, B_2, B_3, \dots, B_N$ は $1$ 以䞊 $1 \ 000 \ 000 \ 000$ 以䞋の敎数</li> <li>すべおの電球 $i$ に぀いお、$A_i \leq B_i$ を満たす</li> </ul> <h3>入力䟋1</h3> <pre> 4 1 4 3 6 2 7 5 8 </pre> <h3>出力䟋1</h3> <pre> 3 </pre> <p>電圧が $5$ や $3.14$ のずきに $3$ ぀の電球が぀きたす。</p> <h3>入力䟋2</h3> <pre> 2 1 2 2 3 </pre> <h3>出力䟋2</h3> <pre> 2 </pre>
p02536
<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> cities numbered <var>1</var> through <var>N</var>, and <var>M</var> bidirectional roads numbered <var>1</var> through <var>M</var>. Road <var>i</var> connects City <var>A_i</var> and City <var>B_i</var>.</p> <p>Snuke can perform the following operation zero or more times:</p> <ul> <li>Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities.</li> </ul> <p>After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times).</p> <p>What is the minimum number of roads he must build to achieve the goal?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100,000</var></li> <li><var>1 \leq M \leq 100,000</var></li> <li><var>1 \leq A_i &lt; B_i \leq N</var></li> <li>No two roads connect the same pair of cities.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>A_M</var> <var>B_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Initially, there are three cities, and there is a road between City <var>1</var> and City <var>2</var>.</p> <p>Snuke can achieve the goal by building one new road, for example, between City <var>1</var> and City <var>3</var>. After that,</p> <ul> <li>We can travel between <var>1</var> and <var>2</var> directly.</li> <li>We can travel between <var>1</var> and <var>3</var> directly.</li> <li>We can travel between <var>2</var> and <var>3</var> by following both roads (<var>2</var> - <var>1</var> - <var>3</var>).</li> </ul></section> </div> </span>
p02166
<h1>Problem E: Cyclic Shift Sort</h1> <h2>Problem</h2> <p> 長さ $N$ の順列 $P = \{ P_1, P_2, \ldots, P_N \} $ ず敎数 $K$ が䞎えられる。<br> 以䞋の操䜜を $0$ 回以䞊任意の回数繰り返すこずで、順列 $P$ を単調増加にするこずができるかどうか刀定せよ。 </p> <ul> <li>敎数 $x \ (0 \le x \le N-K)$ を遞ぶ。 $ P_{x+1}, \ldots, P_{x+K} $ を巡回右シフトする</li> </ul> <p> ただし、郚分列 $U=U_1, \ldots, U_M$ の巡回右シフトずは、 $U=U_1, \ldots, U_M$ を $U=U_M, U_1, \ldots, U_{M-1}$ に倉曎するこずを意味する。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $K$ $P_1$ $\ldots$ $P_N$ </pre> <p> 1行目に順列の長さ $N$ 、敎数 $K$ が空癜区切りで䞎えられる。<br> 2行目に順列 $P$ の芁玠が空癜区切りで䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$2 \leq K \leq N \leq 10^5 $</li> <li>$ 1 \leq P_i \leq N \ (1 \leq i \leq N) $</li> <li>$ P_i \neq P_j \ (i \neq j) $</li> <li>入力はすべお敎数</li> </ul> <h2>Output</h2> <p> $P$ を単調増加にするこずができるなら"Yes"を、できないのであれば"No"を $1$ 行に出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 3 3 2 3 1 </pre> <h2>Sample Output 1</h2> <pre> Yes </pre> <p> $ x = 0 $ ずしお操䜜を $1$ 回行うず、 $P$ を単調増加にするこずができる。 </p> <h2>Sample Input 2</h2> <pre> 3 2 1 2 3 </pre> <h2>Sample Output 2</h2> <pre> Yes </pre> <p> $P$ が初めから単調増加である堎合もある。 </p> <h2>Sample Input 3</h2> <pre> 3 3 3 2 1 </pre> <h2>Sample Output 3</h2> <pre> No </pre> <p> どのように操䜜を行なったずしおも、 $P$ を単調増加にするこずはできない。 </p>
p03327
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Decades have passed since the beginning of AtCoder Beginner Contest.</p> <p>The contests are labeled as <code>ABC001</code>, <code>ABC002</code>, <var>...</var> from the first round, but after the <var>999</var>-th round <code>ABC999</code>, a problem occurred: how the future rounds should be labeled?</p> <p>In the end, the labels for the rounds from the <var>1000</var>-th to the <var>1998</var>-th are decided: <code>ABD001</code>, <code>ABD002</code>, <var>...</var>, <code>ABD999</code>.</p> <p>You are given an integer <var>N</var> between <var>1</var> and <var>1998</var> (inclusive). Print the first three characters of the label of the <var>N</var>-th round of AtCoder Beginner Contest.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1998</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the first three characters of the label of the <var>N</var>-th round of AtCoder Beginner Contest.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>ABC </pre> <p>The <var>999</var>-th round of AtCoder Beginner Contest is labeled as <code>ABC999</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>ABD </pre> <p>The <var>1000</var>-th round of AtCoder Beginner Contest is labeled as <code>ABD001</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1481 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>ABD </pre> <p>The <var>1481</var>-th round of AtCoder Beginner Contest is labeled as <code>ABD482</code>.</p></section> </div> </span>
p03777
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Two deer, AtCoDeer and TopCoDeer, are playing a game called <em>Honest or Dishonest</em>. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters <var>a</var> and <var>b</var> as the input. Each of them is either <code>H</code> or <code>D</code>, and carries the following information:</p> <p>If <var>a</var>=<code>H</code>, AtCoDeer is honest; if <var>a</var>=<code>D</code>, AtCoDeer is dishonest. If <var>b</var>=<code>H</code>, AtCoDeer is saying that TopCoDeer is honest; if <var>b</var>=<code>D</code>, AtCoDeer is saying that TopCoDeer is dishonest.</p> <p>Given this information, determine whether TopCoDeer is honest.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>a</var>=<code>H</code> or <var>a</var>=<code>D</code>.</li> <li><var>b</var>=<code>H</code> or <var>b</var>=<code>D</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If TopCoDeer is honest, print <code>H</code>. If he is dishonest, print <code>D</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>H H </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>H </pre> <p>In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>D H </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>D </pre> <p>In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>D D </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>H </pre></section> </div> </span>
p02865
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>How many ways are there to choose two distinct positive integers totaling <var>N</var>, disregarding the order?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^6</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>There is only one way to choose two distinct integers totaling <var>4</var>: to choose <var>1</var> and <var>3</var>. (Choosing <var>3</var> and <var>1</var> is not considered different from this.)</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>999999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>499999 </pre></section> </div> </span>
p00858
<H1><font color="#000">Problem E:</font> Geometric Map</H1> <p> Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_geometricMap"> </center> <p> Figure 4 is an example of a street map, where some line segments represent streets and the others are signs indicating the directions in which cars cannot move. More concretely, <span>AE</span>, <span>AM</span>, <span>MQ</span>, <span>EQ</span>, <span>CP</span> and <span>HJ</span> represent the streets and the others are signs in this map. In general, an end point of a sign touches one and only one line segment representing a street and the other end point is open. Each end point of every street touches one or more streets, but no signs. </p> <p> The sign <span>BF</span>, for instance, indicates that at <span>B</span> cars may move left to right but may not in the reverse direction. In general, cars may not move from the obtuse angle side to the acute angle side at a point where a sign touches a street (note that the angle <span>CBF</span> is obtuse and the angle <span>ABF</span> is acute). Cars may directly move neither from <span>P</span> to <span>M</span> nor from <span>M</span> to <span>P</span> since cars moving left to right may not go through <span>N</span> and those moving right to left may not go through <span>O</span>. In a special case where the angle between a sign and a street is rectangular, cars may not move in either directions at the point. For instance, cars may directly move neither from <span>H</span> to <span>J</span> nor from <span>J</span> to <span>H</span>. </p> <p> You should write a program that finds the shortest path obeying these traffic rules. The length of a line segment between (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) and (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) is &radic;{(<i>x</i><sub>2</sub> − <i>x</i><sub>1</sub>)<sup>2</sup> + (<i>y</i><sub>2</sub> − <i>y</i><sub>1</sub> )<sup>2</sup>} . </p> <H2>Input</H2> <p> The input consists of multiple datasets, each in the following format. </p> <pre> <i>n</i> <i>x<sub>s</sub> y<sub>s</sub></i> <i>x<sub>g</sub> y<sub>g</sub></i> <i>x</i><sub>1</sub><sup>1</sup> <i>y</i><sub>1</sub><sup>1</sup> <i>x</i><sub>2</sub><sup>1</sup> <i>y</i><sub>2</sub><sup>1</sup> . . . <i>x</i><sub>1</sub><sup><i>k</i></sup> <i>y</i><sub>1</sub><sup><i>k</i></sup> <i>x</i><sub>2</sub><sup><i>k</i></sup> <i>y</i><sub>2</sub><sup><i>k</i></sup> . . . <i>x</i><sub>1</sub><sup><i>n</i></sup> <i>y</i><sub>1</sub><sup><i>n</i></sup> <i>x</i><sub>2</sub><sup><i>n</i></sup> <i>y</i><sub>2</sub><sup><i>n</i></sup> </pre> <p> <i>n</i>, representing the number of line segments, is a positive integer less than or equal to 200. </p> <p> (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>) and (<i>x<sub>g</sub></i>, <i>y<sub>g</sub></i>) are the start and goal points, respectively. You can assume that (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>) &ne; (<i>x<sub>g</sub></i>, <i>y<sub>g</sub></i>) and that each of them is located on an end point of some line segment representing a street. You can also assume that the shortest path from (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>) to (<i>x<sub>g</sub></i>, <i>y<sub>g</sub></i>) is unique. </p> <p> (<i>x</i><sub>1</sub><sup><i>k</i></sup>, <i>y</i><sub>1</sub><sup><i>k</i></sup>) and (<i>x</i><sub>2</sub><sup><i>k</i></sup>, <i>y</i><sub>2</sub><sup><i>k</i></sup> ) are the two end points of the kth line segment. You can assume that (<i>x</i><sub>1</sub><sup><i>k</i></sup>, <i>y</i><sub>1</sub><sup><i>k</i></sup>) &ne;(<i>x</i><sub>2</sub><sup><i>k</i></sup>, <i>y</i><sub>2</sub><sup><i>k</i></sup> ). Two line segments never cross nor overlap. That is, if they share a point, it is always one of their end points. </p> <p> All the coordinates are non-negative integers less than or equal to 1000. The end of the input is indicated by a line containing a single zero. </p> <H2>Output</H2> <p> For each input dataset, print every street intersection point on the shortest path from the start point to the goal point, one in an output line in this order, and a zero in a line following those points. Note that a street intersection point is a point where at least two line segments representing streets meet. An output line for a street intersection point should contain its <i>x</i>- and <i>y</i>-coordinates separated by a space. </p> <p> Print <span>-1</span> if there are no paths from the start point to the goal point. </p> <H2>Sample Input</H2> <pre> 8 1 1 4 4 1 1 4 1 1 1 1 4 3 1 3 4 4 3 5 3 2 4 3 5 4 1 4 4 3 3 2 2 1 4 4 4 9 1 5 5 1 5 4 5 1 1 5 1 1 1 5 5 1 2 3 2 4 5 4 1 5 3 2 2 1 4 2 4 1 1 1 5 1 5 3 4 3 11 5 5 1 0 3 1 5 1 4 3 4 2 3 1 5 5 2 3 2 2 1 0 1 2 1 2 3 4 3 4 5 5 1 0 5 2 4 0 4 1 5 5 5 1 2 3 2 4 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 1 3 1 3 4 4 4 0 -1 5 5 5 2 3 1 1 0 0 </pre>
p00272
<H1>チケットの売り䞊げ</H1> <p> 今日は、アむヅ・゚ンタヌテむンメント瀟むチオシのアむドルグルヌプ「アカベココボりシ」のチケット発売日です。チケットには以䞋の皮類がありたす。<br/> <br/> 垭 6000円<br> 垭 4000円<br> 垭 3000円<br> 垭 2000円<br> <br/> 販売責任者のあなたは、ドキドキしながら発売開始を埅っおいたす。いよいよ発売開始。売れ行き絶奜調です </p> <p> 発売開始からしばらく経ったずころで、それたでの泚文をたずめた衚を受け取りたした。衚の各行には、それたでに売れたチケットの皮類ず枚数が曞いおありたす。ただし、チケットの皮類がの順に珟れるずは限りたせん。この衚の行ごずの売䞊金額を求めるプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力デヌタは以䞋の圢匏で䞎えられる。 </p> <pre> <var>t<sub>1</sub></var> <var>n<sub>1</sub></var> <var>t<sub>2</sub></var> <var>n<sub>2</sub></var> <var>t<sub>3</sub></var> <var>n<sub>3</sub></var> <var>t<sub>4</sub></var> <var>n<sub>4</sub></var> </pre> <p> 入力は4行からなる。i行目には、チケットの皮類を衚す敎数 <var>t<sub>i</sub></var> (1 &le; <var>t<sub>i</sub></var> &le; 4)ず枚数を衚す敎数 <var>n<sub>i</sub></var> (0 &le; <var>n<sub>i</sub></var> &le; 10000)が䞎えられる。チケットの皮類を衚す敎数1, 2, 3, 4は、それぞれ垭、垭、垭、垭を衚す。<var>t<sub>1</sub></var>, <var>t<sub>2</sub></var>, <var>t<sub>3</sub></var>, <var>t<sub>4</sub></var> の倀ずしお1から4たでの数は必ず床だけ珟れるが、1, 2, 3, 4の順で䞎えられるずは限らない。 </p> <h2>出力</h2> <p> 行ごずに売䞊金額を出力する。 </p> <h2>入力䟋 1</h2> <pre> 3 10 1 4 4 1 2 5 </pre> <h2>出力䟋 1</h2> <pre> 30000 24000 2000 20000 </pre> <br/> <h2>入力䟋 2</h2> <pre> 1 1 2 0 3 1 4 1 </pre> <h2>出力䟋 2</h2> <pre> 6000 0 3000 2000 </pre>
p00788
<H1><font color="#000">Problem A:</font> Rational Irrationals</H1> <p> Rational numbers are numbers represented by ratios of two integers. For a prime number <i>p</i>, one of the elementary theorems in the number theory is that there is no rational number equal to &radic;<i>p</i>. Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to &radic;<i>p</i> </p> <p> Now, given a positive integer <i>n</i>, we define a set <i>Q<sub>n</sub></i> of all rational numbers whose elements are represented by ratios of two positive integers both of which are less than or equal to <i>n</i>. For example, <i>Q</i><sub>4</sub> is a set of 11 rational numbers {1/1, 1/2, 1/3, 1/4, 2/1, 2/3, 3/1, 3/2, 3/4, 4/1, 4/3}. 2/2, 2/4, 3/3, 4/2 and 4/4 are not included here because they are equal to 1/1, 1/2, 1/1, 2/1 and 1/1, respectively. </p> <p> Your job is to write a program that reads two integers <i>p</i> and <i>n</i> and reports two rational numbers <i>x / y</i> and <i>u / v</i>, where <i>u / v</i> &lt; &radic;<i>p</i> &lt; <i>x / y</i> and there are no other elements of <i>Q<sub>n</sub></i> between <i>u/v</i> and <i>x/y</i>. When <i>n</i> is greater than &radic;<i>p</i>, such a pair of rational numbers always exists. </p> <H2>Input</H2> <p> The input consists of lines each of which contains two positive integers, a prime number <i>p</i> and an integer <i>n</i> in the following format. </p> <pre> <i>p n</i> </pre> <p> They are separated by a space character. You can assume that <i>p</i> and <i>n</i> are less than 10000, and that <i>n</i> is greater than &radic;<i>p</i>. The end of the input is indicated by a line consisting of two zeros. </p> <H2>Output</H2> <p> For each input line, your program should output a line consisting of the two rational numbers <i>x / y</i> and <i>u / v</i> (<i>x / y</i> &gt; <i>u / v</i>) separated by a space character in the following format. </p> <pre> <i>x/y u/v</i> </pre> <p> They should be irreducible. For example, 6/14 and 15/3 are not accepted. They should be reduced to 3/7 and 5/1, respectively. </p> <H2>Sample Input</H2> <pre> 2 5 3 10 5 100 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3/2 4/3 7/4 5/3 85/38 38/17 </pre>
p01930
<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>Big Maze</h3> <p>あなたは Jumbo Amusement Garden略しお「JAG」ず呌ばれる巚倧な遊園地で働いおいるこの遊園地の敷地は広倧でアトラクションもこずごずく巚倧なものが蚭眮される </p> <p>この床JAGに新たな巚倧迷路アトラクション「Big Maze」が導入されるこずになった Big Maze の圢状は平面図で芋るず瞊暪共に <i>N</i> マスの正方圢状の迷路 <i>M</i> 個を隣接する巊右の蟺同士を繋ぎ合わせ瞊 <i>N</i> マス暪 <i>NM</i> マスの長方圢状になる予定である </p> <p><i>M</i> 個の迷路を巊からどの順番で繋ぎ合わせるかはあらかじめ決たっおいるが隣り合う迷路のどの蟺同士を繋ぎ合わせるかは未定である <i>M</i> 個の迷路を繋ぎ合わせる前に各迷路を90 床回転させる事が出来る回転は䜕床でも行うこずができ回数は迷路毎に別々に決めおよい回転させない迷路があっおもかたわない </p> <p>各マスは通行可胜な「通路」か通行䞍可胜な「壁」のいずれかでありBig Maze の内郚での移動は䞊䞋巊右の 4 方向に隣接する通路のマスに限り可胜である </p> <p>Big Maze の巊端の <i>N</i> 箇所に䜍眮しか぀通路であるマスをスタヌト地点ずし右端の <i>N</i> 箇所に䜍眮しか぀通路であるマスをゎヌル地点ずする </p> <p><i>M</i> 個の迷路を繋ぎ合わせる蟺の遞び方によっおはスタヌト地点やゎヌル地点が耇数存圚する堎合や存圚しない堎合もあり埗る たたスタヌト地点からゎヌル地点ぞの経路が耇数存圚する堎合や存圚しない堎合もあり埗る </p> <p>あなたの仕事は 巊から繋ぎ合わせる順番があらかじめ決たっおいる <i>M</i> 個の迷路を適切に回転させ繋ぎ合わせる蟺を䞊手く遞ぶこずでスタヌト地点からゎヌル地点ぞ通路を移動しお到達可胜な瞊 <i>N</i> マス暪 <i>NM</i> マスの長方圢状の Big Maze を䜜るこずが出来るか確認するこずである </p> <h3>Input</h3> <p>入力は耇数のデヌタセットからなり各デヌタセットが連続しお䞎えられる デヌタセットの数は最倧で 50 である 各デヌタセットは次の圢匏で衚される </p><blockquote><i>N</i> <i>M</i><br><i>maze<sub>1</sub></i><br><i>maze<sub>2</sub></i><br><i>...</i><br><i>maze<sub>M</sub></i><br></blockquote> <p>最初の行はふた぀の敎数 <i>N</i><i>M</i> が空癜区切りで䞎えられ瞊暪 <i>N</i> マスの迷路が <i>M</i> 個䞎えられるこずを瀺し<i>1 &le; N &le; 12</i> か぀ <i>1 &le; M &le; 1,</sub>000</i> である </p><blockquote></blockquote> <p>続いお空癜無しの <i>N</i> 文字を 1 行ずする <i>N</i> 行の入力 <i>maze<sub>i</sub></i> が <i>M</i> 回続く ここで<i>1 &le; i &le; M</i> である </p><blockquote></blockquote> <p><i>N</i> 行の入力 <i>maze<sub>i</sub></i> は巊から繋ぎ合わせる順番で数えたずきの <i>i</i> 番目の迷路の情報を衚し以䞋の圢匏で䞎えられる </p><blockquote><i>c<sub>1, 1</sub> c<sub>1, 2</sub> ... c<sub>1, N</sub></i><br><i>c<sub>2, 1</sub> c<sub>2, 2</sub> ... c<sub>2, N</sub></i><br><i>...</i><br><i>c<sub>N, 1</sub> c<sub>N, 2</sub> ... c<sub>N, N</sub></i><br></blockquote> <p>各<i>c<sub>j, k</sub></i> は“.” たたは “#” のいずれか 1 文字で䞊から <i>j</i> 番目か぀巊から <i>k</i> 番目のマスの情報を衚し“.” のずき通路“#”のずき壁である ここで<i>1 &le; j, k &le; N</i> である </p><blockquote></blockquote> <p>入力の終わりは空癜で区切られた 2 個のれロからなる行で瀺される </p><blockquote></blockquote> <h3>Output</h3> <p>各デヌタセットに぀いおスタヌト地点からゎヌル地点ぞ移動可胜な経路が少なくずもひず぀存圚する Big Maze を䜜るこずが可胜なら “Yes”䞍可胜なら “No” を 1 行で出力せよ </p><blockquote></blockquote> <h3>Sample Input</h3> <pre>3 2 #.# ... #.# ### ... ### 3 2 #.# ... #.# ### #.# ### 3 3 #.. ..# ### ..# #.# #.. #.. ..# ### 5 3 ..... ##### ##... ##.## ##... ..... ##### ..... ##### ..... ...## ##.## ...## ##### ..... 3 2 #.# ... #.# #.# #.# #.# 0 0 </pre> <h3>Output for Sample Input</h3> <pre>Yes No Yes Yes Yes</pre> <p>以䞋にサンプルデヌタセットの図を瀺す</p> <br><div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_00" height="160"> </div><br> <br><div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_01" height="160"> </div><br> <br><div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_02" height="160"> </div><br> <br><div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_03" height="160"> </div><br> <br><div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_fig_h_sample_04" height="160"> </div><br>
p00622
<H1><font color="#000000">Problem B:</font> Monster Factory</H1> <p> 株匏䌚瀟南倩堂は, Packet Monster ずいうゲヌム゜フトを発売しおいる. このゲヌムはモンスタヌを捕たえ, 育お, 戊わせるずいう趣旚のもので, 䞖界䞭で倧人気のゲヌムであった. </p> <p> このゲヌムには埓来のゲヌムには無い特城があった. このゲヌムには Red ず Green ずいう2぀のバヌゞョンがあり, それぞれのゲヌムで捕たえられるモンスタヌが異なるのだ. Red でしか捕たえられないモンスタヌを Green で入手するには, 通信亀換ずいうシステムを䜿う. ぀たり, 自分の゜フト内のモンスタヌず友達の゜フト内のモンスタヌを亀換するこずができるのだ. このシステムは Packet Monster の人気に倧きく貢献しおいた. </p> <p> しかし, このゲヌムのパッケヌゞの補造工皋は, 2぀のバヌゞョンのために少々耇雑になった. パッケヌゞを補造しおいる工堎には2぀の生産ラむンがあり, 片方のラむンでは Red を, もう䞀方のラむンでは Green を補造しおいる. 各ラむンで補造されたパッケヌゞは, 工堎内で䞀意な補造番号が割り圓おられ, 䞀箇所に集められる. そしお以䞋のような攪拌かくはん装眮によっお混ぜられ, 出荷されるのだ. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_churn1"> </center> <p> Red のパッケヌゞは䞊偎から, Green のパッケヌゞは巊偎から, ベルトコンベアによっおこの攪拌装眮に届けられる. 攪拌装眮は十字の圢をした2本のベルトコンベアから出来おおり, "push_down", "push_right" ずいう2぀の呜什を受け付ける. "push_down"は「䞊䞋方向に走るベルトコンベアをパッケヌゞ1個分䞋方向に動かせ」, "push_right"は「巊右方向に走るベルトコンベアをパッケヌゞ1個分右方向に動かせ」ずいう呜什である. 攪拌は, Red のパッケヌゞず同じ数の push_down 呜什ず Green のパッケヌゞの数より぀倚い push_right 呜什を, ランダムな順番で実行するこずによっお行われる. ただし, 最初に実行される呜什ず最埌に実行される呜什は "push_right" ず決たっおいる. この制玄の元では, Red のパッケヌゞの数ず攪拌装眮の䞋端に届くパッケヌゞの数が䞀臎し, Green のパッケヌゞの数ず攪拌装眮の右端に届くパッケヌゞの数が䞀臎する. </p> <p> 攪拌されたパッケヌゞは最終的にベルトコンベアの䞋端たたは右端に届き, 届いた順に包装されお出荷される. </p> <p> 以䞋に, 䞀連の攪拌の手続きの䟋を瀺す. 簡単のため, 1぀のパッケヌゞを1文字のアルファベットずしお衚す. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_churn2"> </center> <p> さお, この工堎では䞍良品の远跡などの目的で, ベルトコンベアの䞋端・右端に届いたパッケヌゞずその順番を蚘録しおいる.しかしこの蚘録にはコストが掛かるため, 工堎長は䞋端に届いたパッケヌゞに぀いおのみ蚘録を取るこずを考えた.右端に届いたパッケヌゞは, 䞊端・巊端に送られるパッケヌゞず䞋端に届いたパッケヌゞの蚘録から求められるのではないかず思ったのだ. </p> <p> 工堎長を助けお, 右端に届いたパッケヌゞの蚘録を䜜成するプログラムを䜜っおほしい. </p> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなる. 入力の終わりは - (ハむフン)぀の行で瀺される. </p> <p> 1぀の入力は3行のアルファベットの倧文字・小文字のみを含む文字列からなる. これらはそれぞれ, Red のパッケヌゞ, Green のパッケヌゞ, 䞋端に届いたパッケヌゞを衚す.1文字のアルファベットが1個のパッケヌゞを衚す.倧文字ず小文字は区別されるこずに泚意せよ. </p> <p> どの行にも, 同じ文字が2回以䞊珟れるこずは無い. 1行目ず2行目に共通しお含たれる文字も存圚しない. </p> <p> 問題文䞭で説明されたケヌスは, Sample Inputの1぀目の䟋に察応しおいる. </p> <H2>Output</H2> <p> 右端に届いたパッケヌゞを, 届いた順番のずおりに出力せよ. </p> <H2>Sample Input</H2> <pre> CBA cba cCa X ZY Z - </pre> <H2>Output for the Sample Input</H2> <pre> BbA XY </pre>
p01463
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Runaway Domino</H1> <p> ``Domino effect'' is a famous play using dominoes. A player sets up a chain of dominoes stood. After a chain is formed, the player topples one end of the dominoes. The first domino topples the second domino, the second topples the third and so on. </p> <p> You are playing domino effect. Before you finish to set up a chain of domino, a domino block started to topple, unfortunately. You have to stop the toppling as soon as possible. </p> <p> The domino chain forms a polygonal line on a two-dimensional coordinate system without self intersections. The toppling starts from a certain point on the domino chain and continues toward the both end of the chain. If the toppling starts on an end of the chain, the toppling continue toward the other end. The toppling of a direction stops when you touch the toppling point or the toppling reaches an end of the domino chain. </p> <p> You can assume that: </p> <ul> <li> You are a point without volume on the two-dimensional coordinate system.</li> <li> The toppling stops soon after touching the toppling point.</li> <li> You can step over the domino chain without toppling it.</li> </ul> <p> You will given the form of the domino chain, the starting point of the toppling, your coordinates when the toppling started, the toppling velocity and the your velocity. You are task is to write a program that calculates your optimal move to stop the toppling at the earliest timing and calculates the minimum time to stop the toppling. </p> <H2>Input</H2> <p> The first line contains one integer <var>N</var>, which denotes the number of vertices in the polygonal line of the domino chain <var>(2 \leq N \leq 1000)</var>. Then <var>N</var> lines follow, each consists of two integers <var>x_{i}</var> and <var>y_{i}</var>, which denote the coordinates of the <var>i</var>-th vertex <var>(-10,000 \leq x, y \leq 10000)</var>. The next line consists of three integers <var>x_{t}</var>, <var>y_{t}</var> and <var>v_{t}</var>, which denote the coordinates of the starting point and the velocity of the toppling. The last line consists of three integers <var>x_{p}</var>, <var>y_{p}</var> and <var>v_{p}</var>, which denotes the coordinates of you when the toppling started and the velocity <var>(1 \leq v_{t} \lt v_{p} \leq 10)</var>. You may assume that the starting point of the toppling lies on the polygonal line. </p> <H2>Output</H2> <p> Print the minimum time to stop the toppling. The output must have a relative or absolute error less than <var>10^{-6}</var>. </p> <H2>Sample Input 1</H2> <pre> 2 0 0 15 0 5 0 1 10 10 2 </pre> <H2>Output for the Sample Input 1</H2> <pre> 5.0 </pre> <H2>Sample Input 2</H2> <pre> 3 -10 0 0 0 0 10 -1 0 1 3 0 2 </pre> <H2>Output for the Sample Input 2</H2> <pre> 4.072027 </pre> <H2>Sample Input 3</H2> <pre> 2 0 0 10 0 5 0 1 9 0 3 </pre> <H2>Output for the Sample Input 3</H2> <pre> 2.0 </pre>
p01199
<H1><font color="#000"></font>Flame of Nucleus</H1> <!-- Problem D --> <p> Year 20XX — a nuclear explosion has burned the world. Half the people on the planet have died. Fearful. </p> <p> One city, fortunately, was not directly damaged by the explosion. This city consists of <i>N</i> domes (numbered 1 through <i>N</i> inclusive) and <i>M</i> bidirectional transportation pipelines connecting the domes. In dome <i>i</i>, <i>P<sub>i</sub></i> citizens reside currently and there is a nuclear shelter capable of protecting <i>K<sub>i</sub></i> citizens. Also, it takes <i>D<sub>i</sub></i> days to travel from one end to the other end of pipeline <i>i</i>. </p> <p> It has been turned out that this city will be polluted by nuclear radiation in <i>L</i> days after today. So each citizen should take refuge in some shelter, possibly traveling through the pipelines. Citizens will be dead if they reach their shelters in exactly or more than <i>L</I> days. </p> <p> How many citizens can survive at most in this situation? </p> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case begins with a line consisting of three integers <i>N</i>, <i>M</i> and <i>L</i> (1 &le; <i>N</i> &le; 100, <i>M</i> &ge; 0, 1 &le; <i>L</i> &le; 10000). This is followed by <i>M</i> lines describing the configuration of transportation pipelines connecting the domes. The <i>i</i>-th line contains three integers <i>A<sub>i</sub></i>, <i>B<sub>i</sub></i> and <i>D<sub>i</sub></i> (1 &le; <i>A<sub>i</sub></i> &lt; <i>B<sub>i</sub></i> &le; <i>N</i>, 1 &le; <i>D<sub>i</sub></i> &le; 10000), denoting that the <i>i</i>-th pipeline connects dome <i>A<sub>i</sub></i> and <i>B<sub>i</sub></i>. There is at most one pipeline between any pair of domes. Finally, there come two lines, each consisting of <i>N</i> integers. The first gives <i>P</i><sub>1</sub> , . . ., <i>P<sub>N</sub></i> (0 &le; <i>P<sub>i</sub></i> &le; 10<sup>6</sup>) and the second gives <i>K</i><sub>1</sub> , . . ., <i>K<sub>N</sub></i> (0 &le; <i>K<sub>i</sub></i> &le; 10<sup>6</sup>). </p> <p> The input is terminated by EOF. All integers in each line are separated by a whitespace. </p> <H2>Output</H2> <p> For each test case, print in a line the maximum number of people who can survive. </p> <H2>Sample Input</H2> <pre> 1 0 1 51 50 2 1 1 1 2 1 1000 0 0 1000 4 3 5 1 2 4 1 3 1 3 4 2 0 1000 1000 1000 3000 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 50 0 3000 </pre>
p01033
<h1>Problem F: Coupling</h1> <h2>Problem</h2> <p> 愛接倧孊では毎幎倧芏暡な合コンが行われおいたす。<br> 今幎は<var>N</var>人の男性ず<var>M</var>人の女性が参加したす。<br> それぞれ男性は0から順に<var>N</var>&minus;1たでIDが割り振られおり、女性は0から順に<var>M</var>&minus;1たでIDが割り振られおいたす。 </p> <p> この合コンでは自分の「倧奜きな人」ず「そこそこ奜きな人」のIDを提瀺したす。<br> 男性はそれぞれ女性のIDを、女性はそれぞれ男性のIDを提瀺したす。<br> </p> <p> その埌、以䞋のルヌルに埓っおカップルが成立したす。 </p> <ol> <li>男性は耇数の女性、女性は耇数の男性ずカップルになっおはいけない。</li> <li>互いに「倧奜きな人」ず提瀺した男性ず女性でペアができる。<br>そこから、任意のペアを遞びカップルを䜜るこずができる。</li> <li>片方が「倧奜きな人」、もう片方が「そこそこ奜きな人」ず提瀺した男性ず女性でペアができる。<br> そこから、任意のペアを遞びカップルを䜜るこずができる。</li> <li>互いに「そこそこ奜きな人」ず提瀺した男性ず女性でペアができる。<br> そこから、任意のペアを遞びカップルを䜜るこずができる。</li> <li>ルヌル2で出来たカップル、ルヌル3で出来たカップル、ルヌル4で出来たカップルの順にカップルの数が最倧になるようにカップルが成立する。</li> </ol> <p> サゞ君はこの合コンの䞻催者です。 近幎では参加者の数が倚くなり手動でカップルの数を把握するのが倧倉になっおきたした。そこでプログラマヌであるあなたは、サゞ君の手䌝いをするこずにしたした。䞊蚘のルヌルに埓っおカップルを䜜った時の「倧奜きな人」同士のカップルの数ず「倧奜きな人」ず「そこそこ奜きな人」によるカップルの数ず「そこそこ奜きな人」同士のカップルの数を出力するプログラムを䜜成しおください。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>L1</var> <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>L1</sub></var> <var>b<sub>L1</sub></var> <var>L2</var> <var>c<sub>1</sub></var> <var>d<sub>1</sub></var> <var>c<sub>2</sub></var> <var>d<sub>2</sub></var> : <var>c<sub>L2</sub></var> <var>d<sub>L2</sub></var> <var>L3</var> <var>e<sub>1</sub></var> <var>f<sub>1</sub></var> <var>e<sub>2</sub></var> <var>f<sub>2</sub></var> : <var>e<sub>L3</sub></var> <var>f<sub>L3</sub></var> <var>L4</var> <var>g<sub>1</sub></var> <var>h<sub>1</sub></var> <var>g<sub>2</sub></var> <var>h<sub>2</sub></var> : <var>g<sub>L4</sub></var> <var>h<sub>L4</sub></var> </pre> <p> 1行目にそれぞれ男性の参加者の数ず女性の参加者の数を衚す2぀の敎数<var>N</var>,<var>M</var>が䞎えられる。次に男性偎の倧奜きな人を衚すデヌタの数<var>L1</var>が䞎えられる。続くL1行に<var>a<sub>i</sub></var>ず<var>b<sub>i</sub></var>が空癜区切りで䞎えられる。それぞれ、ID<var>a<sub>i</sub></var>の男性がID<var>b<sub>i</sub></var>の女性を「倧奜き」であるこずを瀺す。 </p> <p> 続く行に男性偎のそこそこ奜きな人を衚すデヌタの数<var>L2</var>が䞎えられる。続くL2行に<var>c<sub>i</sub></var>ず<var>d<sub>i</sub></var>が空癜区切りで䞎えられる。それぞれ、ID<var>c<sub>i</sub></var>の男性がID<var>d<sub>i</sub></var>の女性を「そこそこ奜き」であるこずを瀺す。次に女性偎の倧奜きな人を衚すデヌタの数<var>L3</var>が䞎えられる。続くL3行に<var>e<sub>i</sub></var>ず<var>f<sub>i</sub></var>が空癜区切りで䞎えられる。それぞれ、ID<var>e<sub>i</sub></var>の女性がIDの<var>f<sub>i</sub></var>の男性を「倧奜き」であるこずを瀺す。 </p> <p> 続く行に女性偎のそこそこ奜きな人を衚すデヌタの数<var>L4</var>が䞎えられる。続くL4行に<var>g<sub>i</sub></var>ず<var>h<sub>i</sub></var>が空癜区切りで䞎えられる。それぞれ、ID<var>g<sub>i</sub></var>の女性がID<var>h<sub>i</sub></var>の男性を「そこそこ奜き」であるこずを瀺す。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var>,<var>M</var> &le; 100</li> <li>0 &le; <var>a<sub>i</sub></var>,<var>c<sub>i</sub></var>,<var>f<sub>i</sub></var>,<var>h<sub>i</sub></var> &le; <var>N</var>&minus;1</li> <li>0 &le; <var>b<sub>i</sub></var>,<var>d<sub>i</sub></var>,<var>e<sub>i</sub></var>,<var>g<sub>i</sub></var> &le; <var>M</var>&minus;1</li> <li>0 &le; <var>L1</var>,<var>L2</var>,<var>L3</var>,<var>L4</var> &le; 2000</li> <li><var>L1</var> &gt; 0, <var>L2</var> &gt; 0 においお (<var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>) ≠ (<var>c<sub>j</sub></var>, <var>d<sub>j</sub></var>) ( 0 &le; <var>i</var> &lt; <var>L1</var>, 0 &le; <var>j</var> &lt; <var>L2</var> )</li> <li><var>L3</var> &gt; 0, <var>L4</var> &gt; 0 においお (<var>e<sub>i</sub></var>,<var>f<sub>i</sub></var>) ≠ (<var>g<sub>j</sub></var>, <var>h<sub>j</sub></var>) ( 0 &le; <var>i</var> &lt; <var>L3</var>, 0 &le; <var>j</var> &lt; <var>L4</var> )</li> <li> (<var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>) ≠ (<var>a<sub>j</sub></var>, <var>b<sub>j</sub></var>) ( <var>i</var> ≠ <var>j</var> ) ( 0 &le; <var>i</var> &lt; <var>L1</var>, 0 &le; <var>j</var> &lt; <var>L1</var> )</li> <li> (<var>c<sub>i</sub></var>,<var>d<sub>i</sub></var>) ≠ (<var>c<sub>j</sub></var>, <var>d<sub>j</sub></var>) ( <var>i</var> ≠ <var>j</var> ) ( 0 &le; <var>i</var> &lt; <var>L2</var>, 0 &le; <var>j</var> &lt; <var>L2</var> )</li> <li> (<var>e<sub>i</sub></var>,<var>f<sub>i</sub></var>) ≠ (<var>e<sub>j</sub></var>, <var>f<sub>j</sub></var>) ( <var>i</var> ≠ <var>j</var> ) ( 0 &le; <var>i</var> &lt; <var>L3</var>, 0 &le; <var>j</var> &lt; <var>L3</var> )</li> <li> (<var>g<sub>i</sub></var>,<var>h<sub>i</sub></var>) ≠ (<var>g<sub>j</sub></var>, <var>h<sub>j</sub></var>) ( <var>i</var> ≠ <var>j</var> ) ( 0 &le; <var>i</var> &lt; <var>L4</var>, 0 &le; <var>j</var> &lt; <var>L4</var> )</li> </ul> <h2>Output</h2> <p>問題文のルヌルに埓っおカップルが成立した時の、「倧奜きな人」同士のペアの数ず「倧奜きな人」ず「そこそこ奜きな人」のペアの数ず「そこそこ奜き」同士のペアの数を空癜区切りで1行に出力せよ。</p> <h2>Sample Input 1</h2> <pre> 3 3 3 0 0 1 1 2 2 2 1 0 2 1 3 1 1 2 2 0 1 2 1 0 2 0 </pre> <h2>Sample Output 1</h2> <pre> 2 0 0 </pre> <p> この堎合男性1ず女性1、男性2ず女性2が倧奜き同士でカップルずなり「倧奜き同士」のペア数が2になる。 するず、男性0のこずが「倧奜き」な女性も「そこそこ奜き」な女性もいなくなっおしたいたす。 たた、女性0のこずが「倧奜き」な男性も「そこそこ奜き」な男性もいなくなっおしたうため以降カップルは成立しなくなりたす。 </p> <h2>Sample input 2</h2> <pre>5 5 5 4 1 2 2 1 4 1 3 4 2 5 1 1 1 2 3 3 3 0 3 4 5 2 3 2 2 0 3 0 2 4 1 5 2 0 4 0 1 0 4 3 2 1 </pre> <h2>Sample Output2</h2> <pre>2 1 0</pre>
p01526
<h1>G - 村</h1> <h2>問題文</h2> <p> き぀ねのしえるは䌑暇でずある小さな村を蚪れおいる圌女が驚いたのはその村の衚札がも぀性質である </p> <p> 村には <var>N</var> 個の家屋があるここでは簡単のため村は 2 次元平面であるずし家屋はこの平面䞊の点であるず芋なす それぞれの家屋には衚札が 1 個蚭けられおおりその家の苗字を衚しおいたしえるは村の䞭を蚪問するに぀れおこの村の衚札が次のような性質を持っおいるこずに気付いた </p> <ul> <li>ある実数 <var>R</var> が存圚する</li> <li>もし 2 ぀の家屋の距離が <var>R</var> 以䞋であるならその 2 ぀の家屋は同じ衚札を持぀</li> <li>もし 2 ぀の家屋の距離が <var>3R</var> 以䞊であるならその 2 ぀の家屋は異なる衚札を持぀</li> <li>任意の 2 ぀の家屋の距離は <var>R</var> 以䞋であるか <var>3R</var> 以䞊であるかのどちらかである</li> </ul> <p> ここで家屋同士の距離は平面䞊のナヌクリッド距離によっお蚈枬するものずする </p> <p> しえるはこの村に衚札が党郚で䜕皮類あるのかが気になったがこの村は意倖に広いずいうこずに気付いたので蚈算機を䜿っおこの答えを暡玢するこずにした </p> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる </p> <pre><var>N</var> <var>R</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> ... <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> </pre> <p> <var>N</var> は家屋の個数である<var>R</var> は家屋の配眮の制玄に関する倀である<var></var> <var>(x<sub>i</sub>, y<sub>i</sub>)</var> は家屋 <var>i</var> の座暙を衚す </p> <h2>出力圢匏</h2> <p> 村に存圚する衚札の皮類の数を求めよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; N &le; 2 &times; 10<sup>5</sup></var></li> <li><var>1 &le; R &le; 10<sup>3</sup></li> <li><var>|x<sub>i</sub>|, |y<sub>i</sub>| &le; 10<sup>6</sup></var></li> <li><var>N</var> は敎数である<var>R, x<sub>i</sub>, y<sub>i</sub></var> は実数で小数第 3 䜍たで衚される</li> <li>任意の <var>1 &le; i &lt; j &le; N</var> に察しお <var>d<sub>ij</sub> = &radic;{(x<sub>i</sub> - x<sub>j</sub>)<sup>2</sup> + (y<sub>i</sub> - y<sub>j</sub>)<sup>2</sup>}</var> ずおくずき<var>d<sub>ij</sub> &le; R</var> か <var>3R &le; d<sub>ij</sub></var> のどちらかが満たされる</li> </ul> <p>この問題の刀定には15 点分のテストケヌスのグルヌプが蚭定されおいる このグルヌプに含たれるテストケヌスは䞊蚘の制玄に加えお䞋蚘の制玄も満たす</p> <ul> <li>答えは 10 以䞋である</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 5 3.000 1.000 0.000 0.000 0.000 -1.000 0.000 10.000 0.000 -10.000 0.000 </pre> <h3>出力䟋 1</h3> <pre> 3 </pre> <p> 家屋 1,2,3 ず家屋 4 ず家屋 5 で衚札が異なる党䜓で 3 ぀の衚札が存圚する </p> <h3>入力䟋 2</h3> <pre> 12 1.234 0.500 0.000 -0.500 0.000 0.000 0.000 0.000 -0.500 55.500 55.000 -55.500 55.000 55.000 55.000 55.000 -55.500 99.500 99.000 -99.500 99.000 99.000 99.000 99.000 -99.500 </pre> <h3>出力䟋 2</h3> <pre> 7 </pre> <h3>入力䟋 3</h3> <pre> 5 99.999 0.000 0.000 49.999 0.001 0.000 0.000 -49.999 -0.001 0.000 0.000 </pre> <h3>出力䟋 3</h3> <pre> 1 </pre> <hr> <address>Writer: 楠本充</address> <address>Tester: 小浜翔倪郎</address>
p01176
<H1><font color="#000">Problem F:</font> Controlled Tournament</H1> <p> National Association of Tennis is planning to hold a tennis competition among professional players. The competition is going to be a knockout tournament, and you are assigned the task to make the arrangement of players in the tournament. </p> <p> You are given the detailed report about all participants of the competition. The report contains the results of recent matches between all pairs of the participants. Examining the data, you’ve noticed that it is only up to the opponent whether one player wins or not. </p> <p> Since one of your special friends are attending the competition, you want him to get the best prize. So you want to know the possibility where he wins the gold medal. However it is not so easy to figure out because there are many participants. You have decided to write a program which calculates the number of possible arrangements of tournament in which your friend wins the gold medal. </p> <p> In order to make your trick hidden from everyone, you need to avoid making a factitive tourna- ment tree. So you have to minimize the height of your tournament tree. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the format as described below. </p> <pre> <i>N M</i> <i>R</i><sub>11</sub> <i>R</i><sub>12</sub> . . . <i>R</i><sub>1<i>N</i></sub> <i>R</i><sub>21</sub> <i>R</i><sub>22</sub> . . . <i>R</i><sub>2<i>N</i></sub> ... <i>R</i><sub><i>N</i>1</sub> <i>R</i><sub><i>N</i>2</sub> . . . <i>R</i><sub><i>NN</i></sub> </pre> <p> <i>N</i> (2 &le; <i>N</i> &le; 16) is the number of player, and <i>M</i> (1 &le; <i>M</i> &le; <i>N</i>) is your friend’s ID (numbered from 1). <i>R<sub>ij</sub></i> is the result of a match between the <i>i</i>-th player and the <i>j</i>-th player. When <i>i</i>-th player always wins, <i>R<sub>ij</sub></i> = 1. Otherwise, <i>R<sub>ij</sub></i> = 0. It is guaranteed that the matrix is consistent: for all <i>i</i> &ne; <i>j</i>, <i>R<sub>ij</sub></i> = 0 if and only if <i>R<sub>ji</sub></i> = 1. The diagonal elements <i>R<sub>ii</sub></i> are just given for convenience and are always 0. </p> <p> The end of input is indicated by a line containing two zeros. This line is not a part of any datasets and should not be processed. </p> <H2>Output</H2> <p> For each dataset, your program should output in a line the number of possible tournaments in which your friend wins the first prize. </p> <H2>Sample Input</H2> <pre> 2 1 0 1 0 0 2 1 0 0 1 0 3 3 0 1 1 0 0 1 0 0 0 3 3 0 1 0 0 0 0 1 1 0 3 1 0 1 0 0 0 0 1 1 0 3 3 0 1 0 0 0 1 1 0 0 6 4 0 0 0 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 7 2 0 1 0 0 0 1 0 0 0 1 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 8 6 0 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 1 1 1 1 1 0 1 0 0 1 1 1 0 1 0 1 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 0 0 3 0 1 11 139 78 </pre>
p00337
<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> <p> 集萜の䜍眮ず元々あった道の情報が䞎えられる。境界線䞊に道を眮き、か぀、すべおの集萜が行き来できるようにした堎合の、道の長さの合蚈の最小倀を蚈算するプログラムを䜜成せよ。ただし、集萜は倧きさのない点、道は幅のない線分ずする。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>V</var> <var>R</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>x<sub>V</sub></var> <var>y<sub>V</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>s<sub>2</sub></var> <var>t<sub>2</sub></var> : <var>s<sub>R</sub></var> <var>t<sub>R</sub></var> </pre> <p> 行目に集萜の数 <var>V</var> (3 &le; <var>V</var> &le; 100) ず道の数 <var>R</var> (2 &le; <var>R</var> &le; 1000) が䞎えられる。 </p> <p> 続く <var>V</var> 行に集萜を衚す点の情報が䞎えられる。各行に䞎えられる぀の敎数 <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> (-1000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 1000)は、それぞれ <var>i</var> 番目の集萜の <var>x</var> 座暙、<var>y</var>座暙を衚す。 </p> <p> 続く <var>R</var> 行に元々あった道の情報が䞎えられる。各行に䞎えられる぀の敎数 <var>s<sub>i</sub></var>, <var>t<sub>i</sub></var> (1 &le; <var>s<sub>i</sub></var> &lt; <var>t<sub>i</sub></var> &le; <var>V</var>)は、<var>i</var> 番目の道が <var>s<sub>i</sub></var> 番目の集萜ず <var>t<sub>i</sub></var> 番目の集萜を぀ないでいるこずを衚す。 </p> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li> <var>i</var> &ne; <var>j</var> ならば、<var>i</var> 番目の集萜ず <var>j</var> 番目の集萜の座暙は異なる。</li> <li> どの぀の集萜に぀いおも、それらを盎接結ぶ道は高々぀しか珟れない。</li> <li>぀の異なる道が端点以倖の点を共有するこずはない。</li> <li> ぀以䞊の集萜が同䞀盎線䞊に䞊んでいるこずはない。 </li> </ul> <h2>Output</h2> <p> 条件を満たす道の長さの合蚈の最小倀を行に実数で出力する。ただし、誀差がプラスマむナス 0.001 を超えおはならない。この条件を満たせば小数点以䞋䜕桁衚瀺しおもよい。 </p> <h2>Sample Input 1</h2> <pre> 5 5 0 0 1 1 3 0 3 2 0 2 1 2 2 3 2 4 3 4 1 5 </pre> <h2>Sample Output 1</h2> <pre> 11.4142 </pre> <br/> <h2>Sample Input 2</h2> <pre> 7 6 0 2 3 0 2 2 1 0 4 1 2 3 3 5 1 3 2 4 2 3 3 5 3 7 6 7 </pre> <h2>Sample Output 2</h2> <pre> 18.2521 </pre>
p03848
<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> people, conveniently numbered <var>1</var> through <var>N</var>. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person <var>i</var> is <var>A_i</var>.</p> <p>Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo <var>10^9+7</var>. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print <var>0</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩10^5</var></li> <li><var>0≩A_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>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 the possible orders in which they were standing, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 4 4 0 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four possible orders, as follows:</p> <ul> <li><var>2,1,4,5,3</var></li> <li><var>2,5,4,1,3</var></li> <li><var>3,1,4,5,2</var></li> <li><var>3,5,4,1,2</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 6 4 0 2 4 0 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Any order would be inconsistent with the reports, thus the answer is <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 7 5 1 1 7 3 5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>16 </pre></section> </div> </span>
p01875
<h2>D: Complex Oracle - Complex Oracle -</h2> <h3>問題</h3> <p> ※この問題はリアクティブ問題ですすなわちサヌバヌ偎に甚意されたプログラムず察話的に応答するこずで正答を導くプログラムを䜜成する必芁がありたす たた、サヌバヌ偎のプログラムも蚈算機資源を共有する関係䞊、サヌバヌだけで最倧 3 sec皋床の実行時間、最倧 300 MB皋床のメモリを䜿甚する堎合がありたすので、TLE・MLEにお気を぀けください。 </p> <p>あいずにゃんは若ヶ束高校のプログラミングコンテスト郚、通称ぷろこん郚に所属する2幎生である。芋目麗しい。あいずにゃんはその小さな䜓も無限に存圚するチャヌムポむントの1぀であるが、本人はコンプレックスを感じおいるようだ。そのせいか、䞀列に䞊んでいる人たちを芋るず、それぞれの人の前方にその人より身長が高い人が䜕人䞊んでいるかを瞬時に数えられる胜力を持っおいる。</p> <p>プロコンの名門・埋呜通倧孊䞭等郚卒の゚リヌト競技プログラマであり、ぷろこん郚の郚長であるりっ぀ちゃんは、あいずにゃんのこの胜力を䜿えば、䞊んでいる人たちがそれぞれ䜕番目に背が高いのかを圓おるこずができるのではないかず考えた。</p> <p>今、りっ぀ちゃんは<var>N</var>人が䞊んでいる列をあいずにゃんに芋せおいる。りっ぀ちゃんは、人が<var>N</var>人䞊んでいるこずは知っおいるが、その䞊び順がどうなっおいるかはわからない。りっ぀ちゃんはあいずにゃんに “<var>l</var>番目の人から<var>r</var>番目の人たでコンプレックス床” を教えおもらうこずができる。ここで、<var>l</var>番目の人から<var>r</var>番目の人たでのコンプレックス床ずは、<var>i</var> (<var>l \&le; i \&le; r</var>) 番目の人それぞれに関しお、<var>l</var>番目から<var>i &minus; 1</var>番目たでの間にいる自分 (<var>i</var>) より背が高い人の人数の総和である。(より厳密な定矩は入出力圢匏を参照のこず)</p> <p>(うらやたしいこずに) ぷろこん郚の郚員であるあなたは、(ずおも、ずおも心苊しいが) あいずにゃんをオラクルずしお利甚するこずで身長順を圓おるプログラムを曞くようりっ぀ちゃんに呜じられた。぀らい。せめおあいずにゃんに負担をかけないよう、少ない質問回数で求められるよう頑匵ろう。</p> <h3>入力出力圢匏</h3> <p>サヌバヌは背の順を衚す長さ<var>N</var>の数列<var>p</var>を保持しおいる。これは入力ずしお䞎えられない。<var>p</var>の各芁玠<var>p_i</var>は<var>1</var>以䞊<var>N</var>以䞋であり、それぞれ倀は異なる。<var>p_i</var>が倧きい倀を持぀方が背が高いこずを衚す。</p> <p>サヌバヌはたず、<var>p</var>の長さ<var>N</var>を衚す<var>1</var>぀の敎数からなる<var>1</var>行を入力ずしお解答プログラムに䞎える。</p> <p>次に解答プログラムが<var>2</var>぀の敎数 <var>l, r</var> (<var>1 \&le; l \&le; r \&le; N</var>) からなるク゚リをサヌバヌに送る。ク゚リの出力圢匏は</p> <pre>? <var>l</var> <var>r</var></pre> <p>である。これは䟋えばC/C++だず、</p> <pre>printf("? %d %d\n", l, r); fflush(stdout);</pre> <p>などず曞けばよい。出力の床にフラッシュするこずを掚奚する。</p> <p>するず、サヌバヌ偎は以䞋の倀を衚す<var>1</var>぀の敎数<var>C</var>からなる1行を入力ずしお解答プログラムに䞎える。</p> <pre><var>C = (\{ (i, j) | p_i &gt; p_j</var> <var>{\rm for}</var> <var>l \&le; i&lt;j \&le; r \}の芁玠数)</var></pre> <p>ただし、ク゚リずしお正しくない<var>l, r</var> (<var>l, r</var>が<var>1</var>以䞊<var>N</var>以䞋の数ではない、たたは<var>l&gt;r</var>である) が䞎えられた堎合、サヌバヌは<var>&minus;1</var>を<var>C</var>ずしお返す。</p> <p>この応答を䜕床か繰り返し、解答プログラムが<var>p</var>を掚定できたならば、<var>p</var>を以䞋の圢匏で出力する。</p> <pre>! <var>p_1</var> ... <var>p_N</var></pre> <p>掚定した順列の出力は1床しかできず、この出力が<var>p</var>ず異なる堎合、誀答ずなる。200,000回以内のク゚リで正しい<var>p</var>を出力できた堎合、正答ずなる。</p> <p>各ク゚リで改行を行うよう気を぀けるこず。</p> <h3>入力制玄</h3> <ul> <li><var>1 \&le; N \&le; 100,000</var></li> <li>掚定される長さ<var>N</var>の数列<var>p</var>は順列。すなわち、<var>p_i \in \{1, </var> ... <var>, N\}</var> <var>{\rm for}</var> <var>1 \&le; i \&le; N</var>、および<var>p_i \neq p_j</var> <var>{\rm for}</var> <var>1 \&le; i &lt; j \&le; N</var> を満たす</li> <li>サヌバヌぞのク゚リ回数は200,000回たで</li> <li>サヌバヌから返答される<var>C</var>は32bit敎数型では収たらない倧きさになりうるこずに泚意せよ</li> </ul> <h3>入力出力䟋</h3> <pre> <table width="600" class="withborder"><tbody> <tr><th>サヌバヌの出力 </th><th> サヌバヌぞの入力</th></tr> <tr><td>4 </td><td> </td></tr> <tr><td> </td><td> ? 1 3 </td></tr> <tr><td> 2 </td><td> </td></tr> <tr><td> </td><td> ? 2 4 </td></tr> <tr><td> 1 </td><td> </td></tr> <tr><td> ... </td><td> ... </td></tr> <tr><td> </td><td> ! 4 1 3 2 </td></tr> </tbody></table> </pre>
p00767
<h3>Integral Rectangles</h3> <p> Let us consider rectangles whose height, <i>h</i>, and width, <i>w</i>, are both integers. We call such rectangles <em> integral rectangles</em>. In this problem, we consider only wide integral rectangles, i.e., those with <i>w</i> &gt; <i>h</i>. </p> <p> We define the following ordering of wide integral rectangles. Given two wide integral rectangles, </p> <ol> <li> The one shorter in its diagonal line is smaller, and </li> <li> If the two have diagonal lines with the same length, the one shorter in its height is smaller. </li> </ol> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_integralRectangles-en"> </center> <p> Given a wide integral rectangle, find the smallest wide integral rectangle bigger than the given one. </p> <h3>Input</h3> <p>The entire input consists of multiple datasets. The number of datasets is no more than 100. Each dataset describes a wide integral rectangle by specifying its height and width, namely <i>h</i> and <i>w</i>, separated by a space in a line, as follows. </p> <blockquote> <i>h</i> <i>w</i> </blockquote> <p> For each dataset, <i>h</i> and <i>w</i> (&gt;<i>h</i>) are both integers greater than 0 and no more than 100. </p> <p> The end of the input is indicated by a line of two zeros separated by a space. </p> <h3>Output</h3> <p> For each dataset, print in a line two numbers describing the height and width, namely <i>h</i> and <i>w</i> (&gt; <i>h</i>), of the smallest wide integral rectangle bigger than the one described in the dataset. Put a space between the numbers. No other characters are allowed in the output. </p> <p> For any wide integral rectangle given in the input, the width and height of the smallest wide integral rectangle bigger than the given one are both known to be not greater than 150. </p> <p> In addition, although the ordering of wide integral rectangles uses the comparison of lengths of diagonal lines, this comparison can be replaced with that of squares (self-products) of lengths of diagonal lines, which can avoid unnecessary troubles possibly caused by the use of floating-point numbers. </p> <h3>Sample Input</h3> <pre> 1 2 1 3 2 3 1 4 2 4 5 6 1 8 4 7 98 100 99 100 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 1 3 2 3 1 4 2 4 3 4 1 8 4 7 2 8 3 140 89 109 </pre>
p02074
<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>Have you experienced $10$-by-$10$ grid calculation? It's a mathematical exercise common in Japan. In this problem, we consider the generalization of the exercise, $N$-by-$M$ grid calculation.</p> <p>In this exercise, you are given an $N$-by-$M$ grid (i.e. a grid with $N$ rows and $M$ columns) with an additional column and row at the top and the left of the grid, respectively. Each cell of the additional column and row has a positive integer. Let's denote the sequence of integers on the column and row by $a$ and $b$, and the $i$-th integer from the top in the column is $a_i$ and the $j$-th integer from the left in the row is $b_j$, respectively.</p> <p>Initially, each cell in the grid (other than the additional column and row) is blank. Let $(i, j)$ be the cell at the $i$-th from the top and the $j$-th from the left. The exercise expects you to fill all the cells so that the cell $(i, j)$ has $a_i \times b_j$. You have to start at the top-left cell. You repeat to calculate the multiplication $a_i \times b_j$ for a current cell $(i, j)$, and then move from left to right until you reach the rightmost cell, then move to the leftmost cell of the next row below.</p> <p>At the end of the exercise, you will write a lot, really a lot of digits on the cells. Your teacher, who gave this exercise to you, looks like bothering to check entire cells on the grid to confirm that you have done this exercise. So the teacher thinks it is OK if you can answer the $d$-th <strong><em>digit</em></strong> (not <strong><em>integer</em></strong>, see an example below), you have written for randomly chosen $x$. Let's see an example.</p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/JAGSummer19Day1_H_nmgrid_001.png" width="400pt"></center></p> <p>For this example, you calculate values on cells, which are $8$, $56$, $24$, $1$, $7$, $3$ in order. Thus, you would write digits 8, 5, 6, 2, 4, 1, 7, 3. So the answer to a question $4$ is $2$.</p> <p>You noticed that you can answer such questions even if you haven't completed the given exercise. Given a column $a$, a row $b$, and $Q$ integers $d_1, d_2, \dots, d_Q$, your task is to answer the $d_k$-th digit you would write if you had completed this exercise on the given grid for each $k$. Note that your teacher is not so kind (unfortunately), so may ask you numbers greater than you would write. For such questions, you should answer 'x' instead of a digit. </p> <hr /> <h3>Input</h3> <p>The input consists of a single test case formatted as follows. </p> <blockquote>$N$ $M$ $a_1$ $\ldots$ $a_N$ $b_1$ $\ldots$ $b_M$ $Q$ $d_1$ $\ldots$ $d_Q$</blockquote> <p>The first line contains two integers $N$ ($1 \le N \le 10^5$) and $M$ ($1 \le M \le 10^5$), which are the number of rows and columns of the grid, respectively.</p> <p>The second line represents a sequence $a$ of $N$ integers, the $i$-th of which is the integer at the $i$-th from the top of the additional column on the left. It holds $1 \le a_i \le 10^9$ for $1 \le i \le N$.</p> <p>The third line represents a sequence $b$ of $M$ integers, the $j$-th of which is the integer at the $j$-th from the left of the additional row on the top. It holds $1 \le b_j \le 10^9$ for $1 \le j \le M$.</p> <p>The fourth line contains an integer $Q$ ($1 \le Q \le 3\times 10^5$), which is the number of questions your teacher would ask.</p> <p>The fifth line contains a sequence $d$ of $Q$ integers, the $k$-th of which is the $k$-th question from the teacher, and it means you should answer the $d_k$-th digit you would write in this exercise. It holds $1 \le d_k \le 10^{15}$ for $1 \le k \le Q$.</p> <h3>Output</h3> <p>Output a string with $Q$ characters, the $k$-th of which is the answer to the $k$-th question in one line, where the answer to $k$-th question is the $d_k$-th digit you would write if $d_k$ is no more than the number of digits you would write, otherwise 'x'.</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 8 1 1 7 3 5 1 2 8 9 1000000000000000 </pre></td><td><pre>853xx </pre></td></tr><tr><td><pre>3 4 271 828 18 2845 90 45235 3 7 30 71 8 61 28 90 42 </pre></td><td><pre>7x406x0 </pre></td></tr></table></div></p>
p00049
<H1>血液型</H1> <p> ある孊玚の生埒の出垭番号ず ABO 血液型を保存したデヌタを読み蟌んで、おのおのの血液型の人数を出力するプログラムを䜜成しおください。なお、ABO 血液型には、A 型、B 型、AB 型、O 型の皮類の血液型がありたす。 </p> <H2>Input</H2> <p> カンマで区切られた出垭番号ず血液型の組が、耇数行に枡っお䞎えられたす。出垭番号は 1 以䞊 50 以䞋の敎数、血液型は文字列 "A", "B", "AB" たたは "O" のいずれかです。生埒の人数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 行目に A 型の人数<br/> 行目に B 型の人数<br/> 行目に AB 型の人数<br/> 行目に O 型の人数<br/> を出力したす。 </p> <H2>Sample Input</H2> <pre> 1,B 2,A 3,B 4,AB 5,B 6,O 7,A 8,O 9,AB 10,A 11,A 12,B 13,AB 14,A </pre> <H2>Output for the Sample Input</H2> <pre> 5 4 3 2 </pre>
p02424
<h1>Bit Operation II</h1> <p> Given two non-negative decimal integers $a$ and $b$, calculate their AND (logical conjunction), OR (logical disjunction) and XOR (exclusive disjunction) and print them in binary representation of 32 bits. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $a \; b$ </pre> <h2>Output</h2> <p> Print results of AND, OR and XOR in a line respectively. </p> <h2>Constraints</h2> <ul> <li>$0 \leq a, b \leq 2^{32} - 1$</li> </ul> <h2>Sample Input 1</h2> <pre> 8 10 </pre> <h2>Sample Output 1</h2> <pre> 00000000000000000000000000001000 00000000000000000000000000001010 00000000000000000000000000000010 </pre>
p00419
<h1>山ぞ垰そう</h1> <p>  近幎むズア囜では、山から街に降りおくる動物に悩たされおいる。あなたは動物を山ぞ垰そうず研究を重ね、以䞋のこずを明らかにした。 </p> <ul> <li> それぞれの動物には固有の名前が぀いおいる。</li> <li> 䜓の動物に぀いお、䞀方の動物の名前のどこかの䜍眮に文字を挿入するず、もう䞀方の動物の名前ず䞀臎する堎合、これらをペアにしお山ぞ垰すこずができる。</li> <li> 䞀床山ぞ垰った動物が、再び街に降りおくるこずはない。</li> </ul> <p> あなたは、街に降りおきた動物を、この方法でどのくらい山ぞ垰すこずができるかを蚈算するこずにした。 </p> <p> 街に降りおきた動物の名前が䞎えられたずき、この方法で最倧いく぀のペアを山ぞ垰すこずができるかを求めるプログラムを䜜成せよ。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $N$ $str_1$ $str_2$ : $str_N$ </pre> <p> 行目に動物の数$N$ ($2 \leq N \leq 100,000$)が䞎えられる。続く$N$行に$i$番目の動物の名前を衚す文字列$str_i$が䞎えられる。ただし$str_i$は英小文字ず英倧文字で構成された10文字以䞋の文字列である。たた、すべおの動物の名前は異なる($i \ne j$なら$str_i \ne str_j$)。 </p> <h2>出力</h2> <p> 山ぞ垰すこずができる動物のペアの数の最倧倀を出力する。  </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 4 aedb aeb ebCd cdE </pre> <h3>出力䟋</h3> <pre> 1 </pre> <h3>入力䟋</h3> <pre> 4 bcD bD AbD bc </pre> <h3>出力䟋</h3> <pre> 2 </pre>  
p01658
<h2>C - チョコレヌト</h2> <p> 目の前に <var>M \times N</var> 個のピヌスでできた板チョコがある ピヌスには甘いピヌスず蟛いピヌスの2皮類がありできるだけ倚くの甘いピヌスを食べたい </p> <p> しかし板チョコの食べ方にはルヌルがあり以䞋のルヌルを守らなければならない </p> <ul> <li> あるピヌスを食べるためにはそのピヌスの真䞊に隣接するピヌスが存圚せず加えおそのピヌスの少なくずも巊右どちらかにはピヌスが存圚しない必芁がある </li> </ul> <p> 䟋えば図のような圢のチョコレヌトでは赀く色付けされたピヌスを次に食べるこずができる </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_chocolate"></img> </center> <br/> <p> たた奇劙なこずにあるピヌスを食べるずそのピヌスの䞊䞋巊右に隣接しおいおか぀ただ食べられおいないピヌスの味が倉化する (甘いピヌスは蟛く蟛いピヌスは甘くなっおしたう) </p> <p> 䞊手くチョコレヌトを食べるず最倧でいく぀の甘いピヌスを食べるこずができるだろうか? </p> <div class="io-style"> <h2>入力圢匏</h2> <p>入力は以䞋の圢匏で䞎えられる</p> <pre> <var>M</var> <var>N</var> <var>a_{11}</var> 
 <var>a_{1N}</var> <var>a_{21}</var> 
 <var>a_{2N}</var> : <var>a_{M1}</var> 
 <var>a_{MN}</var> </pre> <p> <var>a_{ij} = 0</var> のずき䞊からi番目巊からj番目のピヌスが蟛く <var>a_{ij} = 1</var> のずき䞊からi番目巊からj番目のピヌスが甘いこずを衚わしおいる </p> <h2>出力圢匏</h2> <p> 食べるこずのできる甘いピヌスの個数の最倧倀を䞀行に出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 \leq NM \leq 100</var></li> <li><var>0 \leq a_{ij} \leq 1</var></li> <li>入力倀はすべお敎数である</li> </ul> </div> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 2 3 1 1 1 1 1 1 </pre> <h3>出力䟋1</h3> <pre> 5 </pre> <h3>入力䟋2</h3> <pre> 4 2 1 0 0 1 0 1 0 1 </pre> <h3>出力䟋2</h3> <pre> 8 </pre>
p03665
<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> bags of biscuits. The <var>i</var>-th bag contains <var>A_i</var> biscuits.</p> <p>Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.</p> <p>He would like to select bags so that the total number of biscuits inside is congruent to <var>P</var> modulo <var>2</var>. How many such ways to select bags there are?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>P = 0</var> or <var>1</var></li> <li><var>1 \leq A_i \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> <var>P</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 number of ways to select bags so that the total number of biscuits inside is congruent to <var>P</var> modulo <var>2</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two ways to select bags so that the total number of biscuits inside is congruent to <var>0</var> modulo <var>2</var>:</p> <ul> <li>Select neither bag. The total number of biscuits is <var>0</var>.</li> <li>Select both bags. The total number of biscuits is <var>4</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 50 </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 0 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre> <p>Two bags are distinguished even if they contain the same number of biscuits.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>45 1 17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>17592186044416 </pre></section> </div> </span>
p02977
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Determine if there exists a tree with <var>2N</var> vertices numbered <var>1</var> to <var>2N</var> satisfying the following condition, and show one such tree if the answer is yes.</p> <ul> <li>Assume that, for each integer <var>i</var> between <var>1</var> and <var>N</var> (inclusive), Vertex <var>i</var> and <var>N+i</var> have the weight <var>i</var>. Then, for each integer <var>i</var> between <var>1</var> and <var>N</var>, the bitwise XOR of the weights of the vertices on the path between Vertex <var>i</var> and <var>N+i</var> (including themselves) is <var>i</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an integer.</li> <li><var>1 \leq N \leq 10^{5}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a tree satisfying the condition in the statement, print <code>Yes</code>; otherwise, print <code>No</code>. Then, if such a tree exists, print the <var>2N-1</var> edges of such a tree in the subsequent <var>2N-1</var> lines, in the following format:</p> <pre><var>a_{1}</var> <var>b_{1}</var> <var>\vdots</var> <var>a_{2N-1}</var> <var>b_{2N-1}</var> </pre> <p>Here each pair (<var>a_i</var>, <var>b_i</var>) means that there is an edge connecting Vertex <var>a_i</var> and <var>b_i</var>. The edges may be printed in any order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes 1 2 2 3 3 4 4 5 5 6 </pre> <ul> <li>The sample output represents the following graph: <div style="text-align: center;"> <img alt="d004b05438497d50637b534e89f7a511.png" src="https://img.atcoder.jp/agc035/d004b05438497d50637b534e89f7a511.png"> </img></div></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <ul> <li>There is no tree satisfying the condition.</li> </ul></section> </div> </span>
p01208
<H1><font color="#000">Problem B:</font> Turn Left</H1> <p> Taro got a driver’s license with a great effort in his campus days, but unfortunately there had been no opportunities for him to drive. He ended up obtaining a gold license. </p> <p> One day, he and his friends made a plan to go on a trip to Kyoto with you. At the end of their meeting, they agreed to go around by car, but there was a big problem; none of his friends was able to drive a car. Thus he had no choice but to become the driver. </p> <p> The day of our departure has come. He is going to drive but would never turn to the right for fear of crossing an opposite lane (note that cars keep left in Japan). Furthermore, he cannot U-turn for the lack of his technique. The car is equipped with a car navigation system, but the system cannot search for a route without right turns. So he asked to you: “I hate right turns, so, could you write a program to find the shortest left-turn-only route to the destination, using the road map taken from this navigation system?” </p> <H2>Input</H2> <p> The input consists of multiple data sets. The first line of the input contains the number of data sets. Each data set is described in the format below: </p> <pre> <i>m n</i> <i>name</i><sub>1</sub> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> ... <i>name</i><sub><i>m</i></sub> <i>x</i><sub><i>m</i></sub> <i>y</i><sub><i>m</i></sub> <i>p</i><sub>1</sub> <i>q</i><sub>1</sub> ... <i>p</i><sub><i>n</i></sub> <i>q</i><sub><i>n</i></sub> <i>src dst</i> </pre> <p> <i>m</i> is the number of intersections. <i>n</i> is the number of roads. <i>name<sub>i</sub></i> is the name of the <i>i</i>-th intersection. (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) are the integer coordinates of the <i>i</i>-th intersection, where the positive <i>x</i> goes to the east, and the positive <i>y</i> goes to the north. <i>p<sub>j</sub></i> and <i>q<sub>j</sub></i> are the intersection names that represent the endpoints of the <i>j</i>-th road. All roads are bidirectional and either vertical or horizontal. <i>src</i> and <i>dst</i> are the names of the source and destination intersections, respectively. </p> <p> You may assume all of the followings: </p> <ul> <li> 2 &le; <i>m</i> &le; 1000, 0 &le; <i>x<sub>i</sub></i> &le; 10000, and 0 &le; <i>y<sub>i</sub></i> &le; 10000;</li> <li> each intersection name is a sequence of one or more alphabetical characters at most 25 character long;</li> <li> no intersections share the same coordinates;</li> <li> no pair of roads have common points other than their endpoints;</li> <li> no road has intersections in the middle;</li> <li> no pair of intersections has more than one road;</li> <li> Taro can start the car in any direction; and</li> <li> the source and destination intersections are different.</li> </ul> <p> Note that there may be a case that an intersection is connected to less than three roads in the input data; the rode map may not include smaller roads which are not appropriate for the non-local people. In such a case, you still have to consider them as intersections when you go them through. </p> <H2>Output</H2> <p> For each data set, print how many times <i>at least</i> Taro needs to pass intersections when he drive the route of the shortest distance without right turns. The source and destination intersections must be considered as “passed” (thus should be counted) when Taro starts from the source or arrives at the destination. Also note that there may be more than one shortest route possible. </p> <p> Print “impossible” if there is no route to the destination without right turns. </p> <H2>Sample Input</H2> <pre> 2 1 KarasumaKitaoji 0 6150 KarasumaNanajo 0 0 KarasumaNanajo KarasumaKitaoji KarasumaKitaoji KarasumaNanajo 3 2 KujoOmiya 0 0 KujoAburanokoji 400 0 OmiyaNanajo 0 1150 KujoOmiya KujoAburanokoji KujoOmiya OmiyaNanajo KujoAburanokoji OmiyaNanajo 10 12 KarasumaGojo 745 0 HorikawaShijo 0 870 ShijoKarasuma 745 870 ShijoKawaramachi 1645 870 HorikawaOike 0 1700 KarasumaOike 745 1700 KawaramachiOike 1645 1700 KawabataOike 1945 1700 KarasumaMarutamachi 745 2445 KawaramachiMarutamachi 1645 2445 KarasumaGojo ShijoKarasuma HorikawaShijo ShijoKarasuma ShijoKarasuma ShijoKawaramachi HorikawaShijo HorikawaOike ShijoKarasuma KarasumaOike ShijoKawaramachi KawaramachiOike HorikawaOike KarasumaOike KarasumaOike KawaramachiOike KawaramachiOike KawabataOike KarasumaOike KarasumaMarutamachi KawaramachiOike KawaramachiMarutamachi KarasumaMarutamachi KawaramachiMarutamachi KarasumaGojo KawabataOike 8 9 NishikojiNanajo 0 0 NishiojiNanajo 750 0 NishikojiGojo 0 800 NishiojiGojo 750 800 HorikawaGojo 2550 800 NishiojiShijo 750 1700 Enmachi 750 3250 HorikawaMarutamachi 2550 3250 NishikojiNanajo NishiojiNanajo NishikojiNanajo NishikojiGojo NishiojiNanajo NishiojiGojo NishikojiGojo NishiojiGojo NishiojiGojo HorikawaGojo NishiojiGojo NishiojiShijo HorikawaGojo HorikawaMarutamachi NishiojiShijo Enmachi Enmachi HorikawaMarutamachi HorikawaGojo NishiojiShijo 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 impossible 13 4 </pre>
p03235
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given <var>P</var>, a permutation of <var>(1,\ 2,\ ...\ N)</var>.</p> <p>A string <var>S</var> of length <var>N</var> consisting of <code>0</code> and <code>1</code> is a <em>good string</em> when it meets the following criterion:</p> <ul> <li>The sequences <var>X</var> and <var>Y</var> are constructed as follows:<ul> <li>First, let <var>X</var> and <var>Y</var> be empty sequences.</li> <li>For each <var>i=1,\ 2,\ ...\ N</var>, in this order, append <var>P_i</var> to the end of <var>X</var> if <var>S_i=</var> <code>0</code>, and append it to the end of <var>Y</var> if <var>S_i=</var> <code>1</code>.</li> </ul> </li> <li>If <var>X</var> and <var>Y</var> have the same number of <em>high</em> elements, <var>S</var> is a good string. Here, the <var>i</var>-th element of a sequence is called <em>high</em> when that element is the largest among the elements from the <var>1</var>-st to <var>i</var>-th element in the sequence.</li> </ul> <p>Determine if there exists a good string. If it exists, find the lexicographically smallest such string.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq P_i \leq N</var></li> <li><var>P_1,\ P_2,\ ...\ P_N</var> are all distinct.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If a good string does not exist, print <code>-1</code>. If it exists, print the lexicographically smallest such string.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 3 1 4 6 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>001001 </pre> <p>Let <var>S=</var> <code>001001</code>. Then, <var>X=(3,\ 1,\ 6,\ 2)</var> and <var>Y=(4,\ 5)</var>. The high elements in <var>X</var> is the first and third elements, and the high elements in <var>Y</var> is the first and second elements. As they have the same number of high elements, <code>001001</code> is a good string. There is no good string that is lexicographically smaller than this, so the answer is <code>001001</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 2 3 4 5 </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>7 1 3 2 5 6 4 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0001101 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>30 1 2 6 3 5 7 9 8 11 12 10 13 16 23 15 18 14 24 22 26 19 21 28 17 4 27 29 25 20 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>000000000001100101010010011101 </pre></section> </div> </span>
p03720
<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> cities and <var>M</var> roads. The <var>i</var>-th road <var>(1≀i≀M)</var> connects two cities <var>a_i</var> and <var>b_i</var> <var>(1≀a_i,b_i≀N)</var> bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N,M≀50</var></li> <li><var>1≀a_i,b_i≀N</var></li> <li><var>a_i ≠ b_i</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>M</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_M</var> <var>b_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer in <var>N</var> lines. In the <var>i</var>-th line <var>(1≀i≀N)</var>, print the number of roads connected to city <var>i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 2 2 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 2 1 1 </pre> <ul> <li>City <var>1</var> is connected to the <var>1</var>-st and <var>3</var>-rd roads.</li> <li>City <var>2</var> is connected to the <var>1</var>-st and <var>2</var>-nd roads.</li> <li>City <var>3</var> is connected to the <var>2</var>-nd road.</li> <li>City <var>4</var> is connected to the <var>3</var>-rd road.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 5 1 2 2 1 1 2 2 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 8 1 2 3 4 1 5 2 8 3 7 5 2 4 1 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 3 2 2 2 1 1 2 </pre></section> </div> </span>
p02832
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> bricks arranged in a row from left to right.</p> <p>The <var>i</var>-th brick from the left <var>(1 \leq i \leq N)</var> has an integer <var>a_i</var> written on it.</p> <p>Among them, you can break at most <var>N-1</var> bricks of your choice.</p> <p>Let us say there are <var>K</var> bricks remaining. Snuke will be satisfied if, for each integer <var>i</var> <var>(1 \leq i \leq K)</var>, the <var>i</var>-th of those brick from the left has the integer <var>i</var> written on it.</p> <p>Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print <code>-1</code> instead.</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 200000</var></li> <li><var>1 \leq a_i \leq N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print <code>-1</code> if his desire is unsatisfiable.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>If we break the leftmost brick, the remaining bricks have integers <var>1</var> and <var>2</var> written on them from left to right, in which case Snuke will be satisfied.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>In this case, there is no way to break some of the bricks to satisfy Snuke's desire.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 3 1 4 1 5 9 2 6 5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 </pre> <p>There may be no need to break the bricks at all.</p></section> </div> </span>
p02998
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> dots in a two-dimensional plane. The coordinates of the <var>i</var>-th dot are <var>(x_i, y_i)</var>.</p> <p>We will repeat the following operation as long as possible:</p> <ul> <li>Choose four integers <var>a</var>, <var>b</var>, <var>c</var>, <var>d</var> <var>(a \neq c, b \neq d)</var> such that there are dots at exactly three of the positions <var>(a, b)</var>, <var>(a, d)</var>, <var>(c, b)</var> and <var>(c, d)</var>, and add a dot at the remaining position.</li> </ul> <p>We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq x_i, y_i \leq 10^5</var></li> <li>If <var>i \neq j</var>, <var>x_i \neq x_j</var> or <var>y_i \neq y_j</var>.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of times we can do the operation.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 5 1 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>By choosing <var>a = 1</var>, <var>b = 1</var>, <var>c = 5</var>, <var>d = 5</var>, we can add a dot at <var>(1, 5)</var>. We cannot do the operation any more, so the maximum number of operations is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 10 10 20 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There are only two dots, so we cannot do the operation at all.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>16 </pre> <p>We can do the operation for all choices of the form <var>a = 1</var>, <var>b = 1</var>, <var>c = i</var>, <var>d = j</var> <var>(2 \leq i,j \leq 5)</var>, and no more. Thus, the maximum number of operations is <var>16</var>.</p></section> </div> </span>
p03370
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Akaki, a patissier, can make <var>N</var> kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut <var>1</var>, Doughnut <var>2</var>, <var>...,</var> Doughnut <var>N</var>. In order to make one Doughnut <var>i</var> <var>(1 ≀ i ≀ N)</var>, she needs to consume <var>m_i</var> grams of Moto. She cannot make a non-integer number of doughnuts, such as <var>0.5</var> doughnuts.</p> <p>Now, she has <var>X</var> grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:</p> <ul> <li>For each of the <var>N</var> kinds of doughnuts, make at least one doughnut of that kind.</li> </ul> <p>At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 100</var></li> <li><var>1 ≀ m_i ≀ 1000</var></li> <li><var>m_1 + m_2 + ... + m_N ≀ X ≀ 10^5</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> <var>m_1</var> <var>m_2</var> <var>:</var> <var>m_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of doughnuts that can be made under the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1000 120 100 140 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>She has <var>1000</var> grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes <var>120 + 100 + 140 = 360</var> grams of Moto. From the <var>640</var> grams of Moto that remains here, she can make additional six Doughnuts <var>2</var>. This is how she can made a total of nine doughnuts, which is the maximum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 360 90 90 90 90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p>Making one doughnut for each of the four kinds consumes all of her Moto.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 3000 150 130 150 130 110 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>26 </pre></section> </div> </span>
p02131
<h1>Problem H: Hth Number</h1> <h2>Problem</h2> <p> 長さ$N$の文字列$S$がある。$S$に含たれる文字はすべお0以䞊9以䞋の数字である。<br> $S$のすべおの郚分文字列から䜜られる数を党列挙しおできた項数$\frac{N\times(N+1)}{2}$の数列を䜜った時、 その数列の䞭で$H$番目に小さい倀を求めよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $H$ $S$ </pre> <p> 入力はすべお敎数で䞎えられる。<br> 1行目に$N$ず$H$が空癜区切りで䞎えられる。<br> 2行目に長さ$N$の文字列$S$が䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq N \leq 10^5$</li> <li>$1 \leq H \leq \frac{N \times (N+1)}{2}$ <li>$|S| = N$ <li>$S$に含たれる文字はすべお0, 1, 2, 3, 4, 5, 6, 7, 8, 9のいずれかである </ul> <h2>Output</h2> <p> $H$番目の倀を1行に出力せよ。<br> (出力の先頭に䜙蚈な0は含んではならない。) </p> <h2>Sample Input 1</h2> <pre> 2 3 00 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <h2>Sample Input 2</h2> <pre> 4 9 0012 </pre> <h2>Sample Output 2</h2> <pre> 12 </pre> <h2>Sample Input 3</h2> <pre> 5 13 10031 </pre> <h2>Sample Output 3</h2> <pre> 100 </pre> <p> Sample Input3の堎合、10031の郚分文字列から䜜られる数は以䞋の通りである。<br> 1, 0, 0, 3, 1<br> 10, 00, 03, 31<br> 100, 003, 031<br> 1003, 0031<br> 10031<br> これらをを小さい順に䞊べるず 0, 0, 0, 1, 1, 3, 3, 3, 10, 31, 31, 31, 100, 1003, 10031 になり、13番目に小さい倀は100である。<br> </p>
p02561
<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>. Some of the squares contain an object. All the remaining squares are empty. The state of the grid is represented by strings <var>S_1,S_2,\cdots,S_N</var>. The square <var>(i,j)</var> contains an object if <var>S_{i,j}=</var> <code>#</code> and is empty if <var>S_{i,j}=</var> <code>.</code>.</p> <p>Consider placing <var>1 \times 2</var> tiles on the grid. Tiles can be placed vertically or horizontally to cover two adjacent empty squares. Tiles must not stick out of the grid, and no two different tiles may intersect. Tiles cannot occupy the square with an object.</p> <p>Calculate the maximum number of tiles that can be placed and any configulation that acheives the maximum.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq M \leq 100</var></li> <li><var>S_i</var> is a string with length <var>M</var> consists of <code>#</code> and <code>.</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>S_1</var> <var>S_2</var> <var>\vdots</var> <var>S_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>On the first line, print the maximum number of tiles that can be placed.</p> <p>On the next <var>N</var> lines, print a configulation that achieves the maximum. Precisely, output the strings <var>t_1,t_2,\cdots,t_N</var> constructed by the following way.</p> <ul> <li><var>t_i</var> is initialized to <var>S_i</var>.</li> <li>For each <var>(i,j)</var>, if there is a tile that occupies <var>(i,j)</var> and <var>(i+1,j)</var>, change <var>t_{i,j}</var>:=<code>v</code>, <var>t_{i+1,j}</var>:=<code>^</code>.</li> <li>For each <var>(i,j)</var>, if there is a tile that occupies <var>(i,j)</var> and <var>(i,j+1)</var>, change <var>t_{i,j}</var>:=<code>&gt;</code>, <var>t_{i,j+1}</var>:=<code>&lt;</code>.</li> </ul> <p>See samples for further information.</p> <p>You may print any configulation that maximizes the number of tiles.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 #.. ..# ... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 #&gt;&lt; vv# ^^. </pre> <p>The following output is also treated as a correct answer.</p> <pre>3 #&gt;&lt; v.# ^&gt;&lt; </pre></section> </div> </span>
p03059
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A biscuit making machine produces <var>B</var> biscuits at the following moments: <var>A</var> seconds, <var>2A</var> seconds, <var>3A</var> seconds and each subsequent multiple of <var>A</var> seconds after activation.</p> <p>Find the total number of biscuits produced within <var>T + 0.5</var> seconds after activation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq A, B, T \leq 20</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>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total number of biscuits produced within <var>T + 0.5</var> seconds after activation.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <ul> <li>Five biscuits will be produced three seconds after activation.</li> <li>Another five biscuits will be produced six seconds after activation.</li> <li>Thus, a total of ten biscuits will be produced within <var>7.5</var> seconds after activation.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>20 20 19 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01064
<h1>Array Update 2</h1> <h2>Problem</h2> <p> 項数 <var>N</var> 、初項 <var>a</var> 、公差<var>d</var>の等差数列 <var>A</var> がある。 以䞋の圢匏で、数列を曞き換える <var>M</var> 個の呜什文が䞎えられるので、䞎えられた順序で <var>M</var> 回 数列 <var>A</var> を曞き換えたずきの数列 <var>A</var> の <var>K</var>項目の倀を求めなさい。 </p> <ul> <li> <var>i</var> 番目の呜什文は3぀の敎数<var> x<sub>i</sub> , y<sub>i</sub> , z<sub>i</sub> </var>で䞎えられる。(1 &le; <var>i</var> &le; <var>M</var>)<br> </li> <li> <var>x<sub>i</sub></var>が0だった堎合、<var>y<sub>i</sub></var>項目から <var>z<sub>i</sub></var>項目たでの区間においお、倀の順序を反転する。<br> </li> <li> <var>x<sub>i</sub></var>が1だった堎合、<var>y<sub>i</sub></var>項目から <var>z<sub>i</sub></var>項目たでの区間においお、それぞれの倀を1増加させる。 <br> </li> <li> <var>x<sub>i</sub></var>が2だった堎合、<var>y<sub>i</sub></var>項目から <var>z<sub>i</sub></var>項目たでの区間においお、それぞれの倀を半分にする小数点以䞋は切り捚おる。<br> </li> </ul> <h2>Input</h2> <pre> <var>N</var> <var>a</var> <var>d</var> <var>M</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var> ... <var>x<sub>M</sub></var> <var>y<sub>M</sub></var> <var>z<sub>M</sub></var> <var>K</var> </pre> <p> 1行目に、1぀の敎数 <var>N</var> が䞎えられる。 2行目に、2぀の敎数 <var>a</var> ず <var>d</var> が空癜区切りで䞎えられる。 3行目に、1぀の敎数 <var>M</var> が䞎えられる。 4行目からの <var>M</var> 行のうち <var>i</var> 行目には <var>i</var> 番目の呜什文を衚す 3 ぀の敎数 <var>x<sub>i</sub>, y<sub>i</sub>, z<sub>i</sub></var> が空癜区切りで䞎えられる。 最埌の行に、1぀の敎数 <var>K</var> が䞎えられる。 </p> <h2>Constraints</h2> <ul> <li>2 &le; <var>N</var> &le; 200000</li> <li>1 &le; <var>a</var> &le; 5</li> <li>1 &le; <var>d</var> &le; 5</li> <li>1 &le; <var>M</var> &le; 200000</li> <li>0 &le; <var>x<sub>i</sub></var> &le; 2 (1 &le; <var>i</var> &le; <var>M</var>)</li> <li>1 &le; <var>y<sub>i</sub></var> &le; <var>N</var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li>1 &le; <var>z<sub>i</sub></var> &le; <var>N</var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li><var>y<sub>i</sub></var> &lt; <var>z<sub>i</sub></var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li>1 &le; <var>K</var> &le; <var>N</var></li> </ul> <h2>Output</h2> <p> 入力で䞎えられた順番で数列<var>A</var>を<var>M</var>回曎新したずきの<var>K</var>項目を出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 4 2 1 3 0 1 2 1 1 4 2 2 4 3 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <p> { 2 , 3 , 4 , 5 }<br><br> ↓ 0 1 2 ... 1項目から2項目たでの区間の倀の順序を反転する<br><br> { 3 , 2 , 4 , 5 }<br><br> ↓ 1 1 4 ... 1項目から4項目たでの区間の倀をそれぞれ1増やす<br><br> { 4 , 3 , 5 , 6 }<br><br> ↓ 2 2 4 ... 2項目から4項目たでの区間の倀をそれぞれ半分にする小数点以䞋切り捚おる<br><br> { 3 , 1 , 2 , 3 }<br><br> よっお3項目の倀は2である。<br> </p> <h2>Sample Input 2</h2> <pre> 5 1 2 3 1 2 3 2 3 5 0 1 5 1 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre> <p> { 1 , 3 , 5 , 7 , 9 }<br><br> ↓ 1 2 3 ... 2項目から3項目たでの区間の倀をそれぞれ1増やす<br><br> { 1 , 4 , 6 , 7 , 9 }<br><br> ↓ 2 3 5 ... 3項目から5項目たでの区間の倀をそれぞれ半分にする小数点以䞋切り捚おる<br><br> { 1 , 4 , 3 , 3 , 4 }<br><br> ↓ 0 1 5 ... 1項目から5項目たでの区間の倀の順序を反転する<br><br> { 4 , 3 , 3 , 4 , 1 }<br><br> よっお1項目の倀は4である。 </p>
p03409
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On a two-dimensional plane, there are <var>N</var> red points and <var>N</var> blue points. The coordinates of the <var>i</var>-th red point are <var>(a_i, b_i)</var>, and the coordinates of the <var>i</var>-th blue point are <var>(c_i, d_i)</var>.</p> <p>A red point and a blue point can form a <em>friendly pair</em> when, the <var>x</var>-coordinate of the red point is smaller than that of the blue point, and the <var>y</var>-coordinate of the red point is also smaller than that of the blue point.</p> <p>At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 \leq N \leq 100</var></li> <li><var>0 \leq a_i, b_i, c_i, d_i &lt; 2N</var></li> <li><var>a_1, a_2, ..., a_N, c_1, c_2, ..., c_N</var> are all different.</li> <li><var>b_1, b_2, ..., b_N, d_1, d_2, ..., d_N</var> are all different.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_N</var> <var>b_N</var> <var>c_1</var> <var>d_1</var> <var>c_2</var> <var>d_2</var> <var>:</var> <var>c_N</var> <var>d_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of friendly pairs.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 0 3 1 1 3 4 2 0 4 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>For example, you can pair <var>(2, 0)</var> and <var>(4, 2)</var>, then <var>(3, 1)</var> and <var>(5, 5)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 0 1 1 5 2 2 3 3 4 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>For example, you can pair <var>(0, 0)</var> and <var>(2, 3)</var>, then <var>(1, 1)</var> and <var>(3, 4)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 2 2 3 3 0 0 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>It is possible that no pair can be formed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 0 0 7 3 2 2 4 8 1 6 8 5 6 9 5 4 9 1 3 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>5 0 0 1 1 5 5 6 6 7 7 2 2 3 3 4 4 8 8 9 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>4 </pre></section> </div> </span>
p01434
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script> <h2>問題文</h2> <p> 委員長の魔女 PATRICIA は蜘蛛のような糞を吐き結界の䞭で暮らしおいる䜿い魔の MATHIEU は委員長の魔女が吐いた糞を匕っぱり自圚に空を飛んでいる糞は空間䞊の線分ずみなすこずにする </p> <p> <i>暁矎ほむら</i>は委員長の魔女に察しお攻撃を仕掛けようずし爆匟ず間違えお花火玉を投げ蟌んでしたったその結果それぞれの糞に぀いお魔女から距離 <var>p_1, ..., p_M</var> の䜍眮にある郚分が切れるだけずなっおしたった花火玉を投げる前それぞれの糞に぀いお糞の <var>2</var> ぀の端点ず魔女はこの順番で同䞀盎線䞊に䞊んでおり端点のどちらか䞀方を䜿い魔が匕っ匵っおいた爆発で糞は切れ䜿い魔が持っおいた郚分ずそこから䞀぀眮きの郚分を残しお糞の䞀郚は消えおしたった <p> <i>ほむら</i>は次の戊略を考えるために残った糞に぀いおの情報が知りたいず思っおいる残った糞の長さの合蚈倀を求めよ <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる </p> <pre><var> N\ M\\ s_1\ t_1\\ ...\\ s_N\ t_N\\ p_1\\ ...\\ p_M\\ </var></pre> <p> <var>N</var> は空間䞊の糞の個数<var>M</var> は花火玉によっお発生した糞の切断の箇所の個数である </p> <p> <var>s_i, t_i</var> は糞の情報であり<var>s_i</var> は䜿い間が匕っ匵っおいた偎の端点<var>t_i</var> はそうでない偎の端点の魔女からの距離である <p> <var>p_i</var> は花火玉によっお切断された䜍眮の情報である <h2>出力圢匏</h2> <p> 花火玉を投げた埌残った糞の長さの合蚈倀を1行に出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; N &le; 10<sup>5</sup></var></li> <li><var>1 &le; M &le; 10<sup>5</sup></var></li> <li><var>1 &le; s_i &le; 10^9</var></li> <li><var>1 &le; t_i &le; 10^9</var></li> <li><var>1 &le; p_i &le; 10^9</var></li> <li>入力倀は党お敎数である</li> <li><var>s_1, ..., s_N, t_1, ..., t_N, p_1, ..., p_M</var> は党お盞異なる</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 2 3 1 8 20 5 3 7 15 </pre> <h3>出力䟋1</h3> <pre>10</pre> <p> 爆発の埌<var>1</var> ぀目のひもは端点の魔女からの距離がそれぞれ <var>(1,3), (7,8)</var> の <var>2</var> ぀のひもに<var>2</var> ぀目のひもは <var>(20, 15), (7, 5)</var> の <var>2</var> ぀のひもに分かれる結果残ったひもの長さの合蚈は <var>2+1+5+2 = 10</var> ずなる </p> <h3>入力䟋 2</h3> <pre> 1 1 100 1 70 </pre> <h3>出力䟋 2</h3> <pre>30</pre> <h3>入力䟋 3</h3> <pre> 6 8 1 10 11 23 99 2 56 58 66 78 88 49 5 15 25 35 45 55 65 75 </pre> <h3>出力䟋 3</h3> <pre>99</pre> <hr> <address>Problem Setter: Flat35</address>
p01967
<h2>A沢山の皮類の林檎 (Many Kinds of Apples)</h2> <h3>Problem Statement</h3> <p>Apple Farmer Mon has two kinds of tasks: "harvest apples" and "ship apples".</p> <p>There are <var>N</var> different species of apples, and <var>N</var> distinguishable boxes. Apples are labeled by the species, and boxes are also labeled, from <var>1</var> to <var>N</var>. The <var>i</var>-th species of apples are stored in the <var>i</var>-th box.</p> <p>For each <var>i</var>, the <var>i</var>-th box can store at most <var>c_i</var> apples, and it is initially empty (no apple exists).</p> <p>Mon receives Q instructions from his boss Kukui, and Mon completely follows in order. Each instruction is either of two types below.</p> <ul> <li> "harvest apples": put <var>d</var> <var>x</var>-th apples into the <var>x</var>-th box.</li> <li> "ship apples": take <var>d</var> <var>x</var>-th apples out from the <var>x</var>-th box.</li> </ul> <p>However, not all instructions are possible to carry out. Now we call an instruction which meets either of following conditions "impossible instruction":</p> <ul> <li> When Mon harvest apples, the amount of apples exceeds the capacity of that box.</li> <li> When Mon tries to ship apples, there are not enough apples to ship.</li> </ul> <p>Your task is to detect the instruction which is impossible to carry out.</p> <h3>Input</h3> <p>Input is given in the following format.</p> <pre> <var>N</var> <var>c_1</var> <var>c_2</var> $\cdots$ <var>c_N</var> <var>Q</var> <var>t_1</var> <var>x_1</var> <var>d_1</var> <var>t_2</var> <var>x_2</var> <var>d_2</var> $\vdots$ <var>t_Q</var> <var>x_Q</var> <var>d_Q</var> </pre> <p>In line 1, you are given the integer <var>N</var>, which indicates the number of species of apples.</p> <p>In line 2, given <var>c_i</var> (<var>1 \leq i \leq N</var>) separated by whitespaces. <var>c_i</var> indicates the capacity of the <var>i</var>-th box.</p> <p>In line 3, given <var>Q</var>, which indicates the number of instructions.</p> <p>Instructions are given successive <var>Q</var> lines. <var>t_i</var> <var>x_i</var> <var>d_i</var> means what kind of instruction, which apple Mon handles in this instruction, how many apples Mon handles, respectively. If <var>t_i</var> is equal to <var>1</var>, it means Mon does the task of "harvest apples", else if <var>t_i</var> is equal to <var>2</var>, it means Mon does the task of "ship apples".</p> <h3>Constraints</h3> <p>All input values are integers, and satisfy following constraints.</p> <ul> <li> <var>1 \leq N \leq 1,000</var></li> <li> <var>1 \leq c_i \leq 100,000</var> (<var>1 \leq i \leq N</var>)</li> <li> <var>1 \leq Q \leq 100,000</var></li> <li> <var>t_i \in \{1, 2\}</var> (<var>1 \leq i \leq Q</var>)</li> <li> <var>1 \leq x_i \leq N</var> (<var>1 \leq i \leq Q</var>)</li> <li> <var>1 \leq d_i \leq 100,000</var> (<var>1 \leq i \leq Q</var>)</li> </ul> <h3>Output</h3> <p>If there is "impossible instruction", output the index of the apples which have something to do with the first "impossible instruction".</p> <p>Otherwise, output <var>0</var>.</p> <h3>Sample Input 1</h3> <pre> 2 3 3 4 1 1 2 1 2 3 2 1 3 2 2 3 </pre> <h3>Sample Output 1</h3> <pre>1</pre> <p>In this case, there are not enough apples to ship in the first box.</p> <h3>Sample Input 2</h3> <pre> 2 3 3 4 1 1 3 2 1 2 1 2 3 1 1 3 </pre> <h3>Sample Output 2</h3> <pre>1</pre> <p>In this case, the amount of apples exceeds the capacity of the first box.</p> <h3>Sample Input 3</h3> <pre> 3 3 4 5 4 1 1 3 1 2 3 1 3 5 2 2 2 </pre> <h3>Sample Output 3</h3> <pre>0</pre> <h3>Sample Input 4</h3> <pre> 6 28 56 99 3 125 37 10 1 1 10 1 1 14 1 3 90 1 5 10 2 3 38 2 1 5 1 3 92 1 6 18 2 5 9 2 1 4 </pre> <h3>Sample Output 4</h3> <pre>3</pre>
p00675
<h1>Problem G: Sports Days</h1> <p> 䌚接倧孊附属小孊校䌚接倧小は日本有数の競技プログラマヌ逊成校ずしお有名である。 もちろん、運動䌚に参加しおいるずきでさえアルゎリズムの修行を欠かせない。 </p> <p> 競技プログラミング郚郚長のあなたはもちろんこの倧䌚でも勝利したい。 今回はある競技に泚目する。 </p> <p> ある競技ずは䌚接倧小で行われおいる䌝統的な競技だ。 校庭にコヌンがn個眮いおある。 コヌンは4色甚意されおいる。 コヌンのいく぀かのペアは癜線で描かれた矢印で結ばれおいる。 矢印は片偎だけに぀いおおり、敎数が䜵蚘されおいる。 </p> <p> 競技者はk人1チヌムずしお行動する。 あるスタヌト地点のコヌンからゎヌル地点のコヌンたで矢印の䞊をその向きに移動する。 ただし、k人それぞれがゎヌル地点たでの経路は異なる必芁がある。 </p> <p> 経路1ず経路2が異なるずいうのは、 </p> <ul> <li>条件1 経路1ず経路2で経由する矢印の本数が等しい堎合、経路1でi番目に経由する矢印ず経路2でi番目に経由する矢印が異なるようなiが存圚するこず。</li> <li>条件2 経路1ず経路2で経由する矢印の本数が異なっおいるこず。</li> </ul> <p> のいずれかを満たせば経路が異なっおいるず蚀える。 </p> <p> さらに、コヌンの蟿り方には犁止された色のパタヌンがあり、スタヌト地点からゎヌル地点たでの経路でそのパタヌンを含んでしたった遞手はリタむアずなる。 ただし、それ以倖の経路はどのような経路を蟿っおもよく、䜕床も同じコヌンスタヌト地点やゎヌル地点のコヌンを含むを通っお良い。 たた、矢印に䜵蚘された数字がスコアずしお加算されおいく。 この競技はより倚くのチヌムメむトがより小さな合蚈スコアでゎヌル地点のコヌンに蟿り぀けたチヌムが勝利ずなる。 </p> <p> 郚長のあなたはもちろんプログラミングでこの問題を解決できるはずだ。 ゎヌルたで移動可胜な最倧の人数を求めよ。 たた、最倧人数で蟿り着いた時の最小スコアを求めよ。 </p> <p> ただし、いくらでもスコアを小さく出来る堎合は -1 を出力せよ。 </p> <h2>Input</h2> <p> 入力は耇数のテストケヌスから成り立っおいる。 テストケヌスの数は20ケヌスを超えない。 </p> <pre> n col<sub>1</sub> col<sub>2</sub> ... col<sub>n</sub> m a<sub>1</sub> b<sub>1</sub> c<sub>1</sub> a<sub>2</sub> b<sub>2</sub> c<sub>2</sub> ... a<sub>m</sub> b<sub>m</sub> c<sub>m</sub> k pattern </pre> <p> n( 2 &le; n &le; 100)はコヌンの数を衚す。 col<sub>i</sub>(1 &le; col<sub>i</sub> &le; 4)はi番目のコヌンの色を瀺す。 m(0 &le; m &le; 1,000) は矢印の数を衚す。 a<sub>i</sub> は矢印の始点のコヌンの番号, b<sub>i</sub>は終点のコヌンの番号を衚し、c<sub>i</sub>はその矢印のスコアを衚す. たた、ひず぀のコヌンから䌞びる矢印は10本たでである。 (1 &le; a<sub>i</sub>, b<sub>i</sub> &le; n, -1,000 &le; c<sub>i</sub> &le; 1,000) kは競技を行うチヌムの人数を瀺す。 (1 &le; k &le; 10) pattern は長さが10以䞋の1~4たでの数字からなる文字列で、 移動が犁止されおいるパタヌンを瀺す。 スタヌト地点のコヌンは1番目のコヌンであり、 n番目のコヌンがゎヌルである。 入力で䞎えられる数(n, col, m, a, b, c, k)はすべお敎数である。 入力の終わりは0を含む1行で瀺される。 </p> <h2>Output</h2> <p> 出力は空癜で区切られた二぀の敎数からなる。 1぀目は到達できる人数で、2぀目はその最小コストである。 もし、いくらでもスコアを小さく出来る堎合は-1のみを含む行を出力せよ。 䞀人も到達できない堎合は0 0を出力せよ。 </p> <h2>Sample Input</h2> <pre> 2 1 1 2 1 2 1 2 1 1 1 1111 2 1 1 2 1 2 1 2 1 1 1 11 2 1 1 2 1 2 1 2 1 1 10 1111 2 1 1 2 1 2 1 2 1 1 10 111111 2 1 1 2 1 2 -1 2 1 0 10 11 2 1 1 2 1 2 -1 2 1 0 10 1111 2 1 1 2 1 2 -1 2 1 0 10 12 2 1 1 2 1 2 -1 2 1 0 10 1111111111 0 </pre> <h2>Sample Output</h2> <pre> 1 1 0 0 1 1 2 4 0 0 1 -1 -1 4 -10 </pre>
p02648
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a rooted binary tree with <var>N</var> vertices, where the vertices are numbered <var>1</var> to <var>N</var>. Vertex <var>1</var> is the root, and the parent of Vertex <var>i</var> (<var>i \geq 2</var>) is Vertex <var>\left[ \frac{i}{2} \right]</var>.</p> <p>Each vertex has one item in it. The item in Vertex <var>i</var> has a value of <var>V_i</var> and a weight of <var>W_i</var>. Now, process the following query <var>Q</var> times:</p> <ul> <li>Given are a vertex <var>v</var> of the tree and a positive integer <var>L</var>. Let us choose some (possibly none) of the items in <var>v</var> and the ancestors of <var>v</var> so that their total weight is at most <var>L</var>. Find the maximum possible total value of the chosen items.</li> </ul> <p>Here, Vertex <var>u</var> is said to be an ancestor of Vertex <var>v</var> when <var>u</var> is an indirect parent of <var>v</var>, that is, there exists a sequence of vertices <var>w_1,w_2,\ldots,w_k</var> (<var>k\geq 2</var>) where <var>w_1=v</var>, <var>w_k=u</var>, and <var>w_{i+1}</var> is the parent of <var>w_i</var> for each <var>i</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 &lt; 2^{18}</var></li> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>1 \leq V_i \leq 10^5</var></li> <li><var>1 \leq W_i \leq 10^5</var></li> <li>For the values <var>v</var> and <var>L</var> given in each query, <var>1 \leq v \leq N</var> and <var>1 \leq L \leq 10^5</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Let <var>v_i</var> and <var>L_i</var> be the values <var>v</var> and <var>L</var> given in the <var>i</var>-th query. Then, Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>V_1</var> <var>W_1</var> <var>:</var> <var>V_N</var> <var>W_N</var> <var>Q</var> <var>v_1</var> <var>L_1</var> <var>:</var> <var>v_Q</var> <var>L_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each integer <var>i</var> from <var>1</var> through <var>Q</var>, the <var>i</var>-th line should contain the response to the <var>i</var>-th query.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 3 4 3 1 1 2 5 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 3 3 </pre> <p>In the first query, we are given only one choice: the item with <var>(V, W)=(1,2)</var>. Since <var>L = 1</var>, we cannot actually choose it, so our response should be <var>0</var>.</p> <p>In the second query, we are given two choices: the items with <var>(V, W)=(1,2)</var> and <var>(V, W)=(2,3)</var>. Since <var>L = 5</var>, we can choose both of them, so our response should be <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 123 119 129 120 132 112 126 109 118 103 115 109 102 100 130 120 105 105 132 115 104 102 107 107 127 116 121 104 121 115 8 8 234 9 244 10 226 11 227 12 240 13 237 14 206 15 227 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>256 255 250 247 255 259 223 253 </pre></section> </div> </span>
p00225
<H1>こぶたぬき぀ねこ</H1> <p> A子さんの家に芪戚のB男君がやっおきたした。圌は3歳で歌が倧奜きです。圌は幌皚園でならった「こぶたぬき぀ねこ」(山本盎玔䜜詞・䜜曲)ずいう歌を䞀生懞呜に歌っおいたす。この歌では、4぀のこずば「こぶた」 「たぬき」 「き぀ね」「ねこ」が順にしりずりになっおいお、さらに最埌の音ず最初の音が同じになっおいたす。B男君は、A子さんに、同じようなしりずりが、B男君が蚀った単語から䜜れるか教えお欲しいず蚀われたした。 </p> <p> そこで、A子さんを助けるために、䞎えられた単語から、その単語をすべお䜿っお、順にしりずりを぀くり、その䞊で、 第1 の単語の最初の文字ず最終の単語の最埌の文字が同じであるようにできるか吊かを刀定するプログラムを䜜成したしょう。 </p> <p> <var>n</var> 個の単語を入力ずし、それらの単語の組からしりずりを䜜成できるか吊かを刀定し、可胜な堎合はOK ず、䞍可胜な堎合は NG ず出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>word<sub>1</sub></var> <var>word<sub>2</sub></var> : <var>word<sub>n</sub></var> </pre> <p> 1 行目に単語の個数 <var>n</var> (2 &le; <var>n</var> &le; 10000) が䞎えられたす。続く <var>n</var> 行に <var>n</var> 個の単語 <var>word<sub>i</sub></var> (32 文字以䞋の半角英小文字だけからなる文字列) が䞎えられたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、刀定結果を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 5 apple yellow georgia king email 7 apple yellow georgia king email wink lucky 0 </pre> <H2>Output for the Sample Input</H2> <pre> NG OK </pre>
p02218
<span class="lang"> <span class="lang-ja"> <h1>G: 䞀番遠い町</h1> <div class="part"> <section> <h3>問題文</h3><p>$N$ 個の町ず $N-1$ 個の道がありたす。</p> <p>すべおの町ず道にはそれぞれ $1$ から $N$, $1$ から $N-1$ の番号が぀いおいたす。</p> <p>道 $i$ は町 $a_i$ ず町 $b_i$ を距離 $d_i$ で双方向に぀ないでいたす。</p> <p>最初はすべおの道が通行可胜な状態であり、どの町からもいく぀かの道を通るこずですべおの町に行くこずができたす。</p> <p>すいばかくんは最初、町 $1$ にいたす。</p> <p>$Q$ 個のク゚リが䞎えられるので順番に凊理しおください。ク゚リは $3$ 皮類あり、以䞋の圢匏で䞎えられたす。</p> <ul> <li>ク゚リ $1$ : <code>1 x</code> ― すいばかくんが町 $x$ に移動する。ただし、このク゚リ時点で、すいばかくんがいる町ず町 $x$ は通行可胜な $1$ ぀の道で盎接぀ながれおいるこずが保蚌される。</li> <li>ク゚リ $2$ : <code>2 y</code> ― 道 $y$ が封鎖される。ただし、このク゚リ時点で、道 $y$ は通行可胜であるこずが保蚌される。</li> <li>ク゚リ $3$ : <code>3 z</code> ― 道 $z$ が通行可胜になる。ただし、このク゚リ時点で、道 $z$ は封鎖されおいるこずが保蚌される。</li> </ul> <p>さらに、各ク゚リを行った盎埌に、すいばかくんがその時点で通行可胜な道のみを䜿っお到達可胜な町のうち、すいばかくんがいる町から䞀番遠い町の番号を昇順ですべお出力しおください。</p> </section> </div> <div class="part"> <section> <h3>制玄</h3><ul> <li>$1 \leq N \leq 2 \times 10^5$</li> <li>$1 \leq a_i, b_i \leq N$, $a_i \neq b_i$</li> <li>$1 \leq d_i \leq 10^6$</li> <li>$1 \leq Q \leq 2 \times 10^5$</li> <li>ク゚リ $1$ においお、$1 \leq x \leq N$ を満たす。たた、このク゚リ時点で、すいばかくんがいる町ず町 $x$ は通行可胜な $1$ ぀の道で盎接぀ながれおいる。</li> <li>ク゚リ $2$ においお、$1 \leq y \leq N-1$ を満たす。たた、このク゚リ時点で、道 $y$ は通行可胜である。</li> <li>ク゚リ $3$ においお、$1 \leq z \leq N-1$ を満たす。たた、このク゚リ時点で、道 $z$ は封鎖されおいる。</li> <li>$i$ 番目のク゚リで出力すべき町の個数を $c_i$ ずするずき、$\sum_{i=1}^{Q}c_i \leq 4 \times 10^5$ を満たす。</li> <li>入力はすべお敎数である。</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>以䞋の圢匏で暙準入力から䞎えられる。</p> <pre>$N$ $a_1$ $b_1$ $d_1$ $a_2$ $b_2$ $d_2$ $:$ $a_{N-1}$ $b_{N-1}$ $d_{N-1}$ $Q$ $Query_1$ $Query_2$ $:$ $Query_Q$ </pre> <p>$Query_i$ は問題文にある $3$ 皮類のク゚リのいずれかの圢匏で䞎えらえる。</p> </section> </div> <div class="part"> <section> <h3>出力</h3><p>$Q$ 行出力せよ。 $i$ 行目には、$i$ 番目ク゚リ埌の出力すべき町の番号が昇順で $v_1$, $v_2$, $...$, $v_c$ の $c$ 個であるずき、以䞋のように空癜区切りで出力せよ。</p> <pre>$c$ $v_1$ $v_2$ $...$ $v_c$ </pre> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力䟋 1</h3><pre>6 2 4 1 1 2 1 4 6 1 2 3 1 4 5 1 5 2 5 2 3 1 2 3 5 1 4 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 1</h3><pre>1 6 2 3 4 3 1 3 4 1 5 2 1 3 </pre> <ul> <li> <p>$1$ ぀目のク゚リで、道 $5$ が封鎖されたす。この盎埌に、すいばかくんが到達可胜な町は $1$, $2$, $3$, $4$, $6$ であり、すいばかくんがいる町 $1$ からの距離はそれぞれ $0$, $1$, $2$, $2$, $3$ なので、答えは町 $6$ になりたす。</p> </li> <li> <p>$2$ ぀目のク゚リで、道 $3$ が封鎖されたす。この盎埌に、すいばかくんが到達可胜な町は $1$, $2$, $3$, $4$ であり、すいばかくんがいる町 $1$ からの距離はそれぞれ $0$, $1$, $2$, $2$ なので、答えは町 $3$, $4$ になりたす。</p> </li> <li> <p>$3$ ぀目のク゚リで、すいばかくんは町 $2$ に移動したす。この盎埌に、すいばかくんが到達可胜な町は $1$, $2$, $3$, $4$ であり、すいばかくんがいる町 $2$ からの距離はそれぞれ $1$, $0$, $1$, $1$ なので、答えは町 $1$, $3$, $4$ になりたす。</p> </li> <li> <p>$4$ ぀目のク゚リで、道 $5$ が通行可胜になりたす。この盎埌に、すいばかくんが到達可胜な町は $1$, $2$, $3$, $4$, $5$ であり、すいばかくんがいる町 $2$ からの距離はそれぞれ $1$, $0$, $1$, $1$, $2$ なので、答えは町 $5$ になりたす。</p> </li> <li> <p>$5$ ぀目のク゚リで、すいばかくんは町 $4$ に移動したす。この盎埌に、すいばかくんが到達可胜な町は $1$, $2$, $3$, $4$, $5$ であり、すいばかくんがいる町 $4$ からの距離はそれぞれ $2$, $1$, $2$, $0$, $1$ なので、答えは町 $1$, $3$ になりたす。</p> </li> </ul> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋 2</h3><pre>5 3 4 1 2 1 1 4 5 1 3 2 1 6 2 2 3 2 1 2 1 3 2 4 1 4 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 2</h3><pre>1 1 1 5 1 5 2 1 5 1 5 2 3 5 </pre></section> </div> </span> </span>