question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p03216
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.<br/> The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.</p> <p>Given a string <var>S</var> of length <var>N</var> and an integer <var>k</var> <var>(k \geq 3)</var>, he defines the <em><var>k</var>-DMC number</em> of <var>S</var> as the number of triples <var>(a, b, c)</var> of integers that satisfy the following conditions:</p> <ul> <li><var>0 \leq a &lt; b &lt; c \leq N - 1</var></li> <li><var>S[a]</var> = <code>D</code></li> <li><var>S[b]</var> = <code>M</code></li> <li><var>S[c]</var> = <code>C</code></li> <li><var>c-a &lt; k</var></li> </ul> <p>Here <var>S[a]</var> is the <var>a</var>-th character of the string <var>S</var>. Indexing is zero-based, that is, <var>0 \leq a \leq N - 1</var> holds.</p> <p>For a string <var>S</var> and <var>Q</var> integers <var>k_0, k_1, ..., k_{Q-1}</var>, calculate the <var>k_i</var>-DMC number of <var>S</var> for each <var>i</var> <var>(0 \leq i \leq Q-1)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>3 \leq N \leq 10^6</var></li> <li><var>S</var> consists of uppercase English letters</li> <li><var>1 \leq Q \leq 75</var></li> <li><var>3 \leq k_i \leq N</var></li> <li>All numbers given 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>Q</var> <var>k_{0}</var> <var>k_{1}</var> <var>...</var> <var>k_{Q-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the <var>k_i</var>-DMC number of the string <var>S</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3> <pre>18 DWANGOMEDIACLUSTER 1 18 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre>1 </pre> <p><var>(a,b,c) = (0, 6, 11)</var> satisfies the conditions.<br/> Strangely, Dwango Media Cluster does not have so much DMC-ness by his definition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3> <pre>18 DDDDDDMMMMMCCCCCCC 1 18 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre>210 </pre> <p>The number of triples can be calculated as <var>6\times 5\times 7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3> <pre>54 DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED 3 20 30 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3> <pre>0 1 2 </pre> <p><var>(a, b, c) = (0, 23, 36), (8, 23, 36)</var> satisfy the conditions except the last one, namely, <var>c-a &lt; k_i</var>.<br/> By the way, DWANGO is an acronym for "Dial-up Wide Area Network Gaming Operation".</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Output 4</h3> <pre>30 DMCDMCDMCDMCDMCDMCDMCDMCDMCDMC 4 5 10 15 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3> <pre>10 52 110 140 </pre></section> </div> </span>
p04029
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give <var>1</var> candy to the first child in the line, <var>2</var> candies to the second child, ..., <var>N</var> candies to the <var>N</var>-th child. How many candies will be necessary in total?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the necessary number of candies in total.</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>6 </pre> <p>The answer is <var>1+2+3=6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>55 </pre> <p>The sum of the integers from <var>1</var> to <var>10</var> is <var>55</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p>Only one child. The answer is <var>1</var> in this case.</p></section> </div> </span>
p02057
<h2>F: MOD Rush</h2> <h3>問題</h3> <p>長さ <var>N</var> の正の敎数列 <var>A</var> ず、長さ <var>M</var> の正の敎数列 <var>B</var> が䞎えられたす。</p> <p>すべおの <var>(i, j)</var> <var>(1 \leq i \leq N, 1 \leq j \leq M)</var> に぀いお、<var>A_i</var> を <var>B_j</var> で割ったあたりを求め、それらの和を出力しおください。</p> <h3>入力圢匏</h3> <pre> <var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> <var>B_1</var> <var>B_2</var> <var>...</var> <var>B_M</var> </pre> <h3>制玄</h3> <ul> <li> <var>1 \leq N, M \leq 2 \times 10^5</var></li> <li> <var>1 \leq A_i, B_i \leq 2 \times 10^5</var></li> <li> 入力はすべお敎数で䞎えられる</li> </ul> <h3>出力圢匏</h3> <p>答えを <var>1</var> 行に出力しおください。最埌に改行しおください。</p> <h3>入力䟋 1</h3> <pre> 3 3 5 1 6 2 3 4 </pre> <h3>出力䟋 1</h3> <pre>9</pre> <ul> <li> 数列 <var>A</var> の <var>1</var> 番目の芁玠を、数列 <var>B</var> の各芁玠で割ったあたりを考えたす。<var>5</var> を <var>2</var> で割るずあたりは <var>1</var>、<var>3</var> で割るずあたりは <var>2</var>、<var>4</var> で割るずあたりは <var>1</var> です。</li> <li> 同様に <var>2</var> 番目の芁玠に぀いおも考えるず、あたりはそれぞれ <var>1, 1, 1</var> です。</li> <li> <var>3</var> 番目の芁玠に぀いおも考えるず、あたりはそれぞれ <var>0, 0, 2</var> です。</li> <li> あたりを合蚈するず <var>1 + 2 + 1 + 1 + 1 + 1 + 0 + 0 + 2 = 9</var> ずなるので、<var>9</var> を出力したす。</li> </ul> <h3>入力䟋 2</h3> <pre> 2 4 2 7 3 3 4 4 </pre> <h3>出力䟋 2</h3> <pre>16</pre> <ul> <li> 数列内には同じ倀が耇数含たれおいるこずがありたすが、それぞれの芁玠に察しおあたりを蚈算しお和を求めたす。</li> </ul> <h3>入力䟋 3</h3> <pre> 3 1 12 15 21 3 </pre> <h3>出力䟋 3</h3> <pre>0</pre>
p00590
<H1>Pair of Primes</H1> <p> We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this: </p> <pre> 1 2 3 4 5 6 7 8 9 . . . N N . . . 9 8 7 6 5 4 3 2 1 </pre> <p> Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime. </p> <H2>Input</H2> <p> Input contains several test cases. Each test case consists of an integer N in one line. </p> <H2>Output</H2> <p> For each line of input, output P . </p> <H2>Sample Input</H2> <pre> 1 4 7 51 </pre> <H2>Output for the Sample Input</H2> <pre> 0 2 2 6 </pre>
p02407
<H1>Reversing Numbers</H1><br> <p> Write a program which reads a sequence and prints it in the reverse order. </p> <H2>Input</H2> <p> The input is given in the following format: </p> <pre> <var>n</var> <var>a</var><sub>1</sub> <var>a</var><sub>2</sub> . . . <var>a</var><sub><var>n</var></sub> </pre> <p> <var>n</var> is the size of the sequence and <var>a<sub>i</sub></var> is the <var>i</var>th element of the sequence. </p> <H2>Output</H2> <p> Print the reversed sequence in a line. Print a single space character between adjacent elements (Note that your program should not put a space character after the last element). </p> <h2>Constraints</h2> <ul> <li><var>n</var> &le; 100</li> <li>0 &le; <var>a<sub>i</sub></var> &lt; 1000</li> </ul> <H2>Sample Input 1</H2> <pre> 5 1 2 3 4 5 </pre> <H2>Sample Output 1</H2> <pre> 5 4 3 2 1 </pre> <H2>Sample Input 2</H2> <pre> 8 3 3 4 4 5 8 7 9 </pre> <H2>Sample Output 2</H2> <pre> 9 7 8 5 4 4 3 3 </pre> <h2>Note</h2> <center> <a href="commentary.jsp?id=ITP1_6_A"> <div class="button">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解説&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div> </a> </center>
p02112
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Problem B: Hating Crowd</h1> <h2>Problem</h2> <p> ニヌト君は1幎12ヶ月毎月30日たで蚈360日の䞖界線で暮らしおいたす。その䞖界では毎幎同じ日皋の<var>N</var>個の連䌑が䞖界䞭の人に適甚されおいたした。連䌑<var>i</var>は<var>M<sub>i</sub></var>月<var>D<sub>i</sub></var>日から始たる連続した<var>V<sub>i</sub></var>日間です。 </p> <p> ニヌト君はNEETなので連䌑に関係なく毎日䌑みです。ある日ニヌト君は珍しく出かけようず思いたしたが、人混みが嫌いなので、連䌑の圱響で混雑する日はなるべく倖に出たくありたせん。そこで、ニヌト君は以䞋の方法で各日の混雑床を蚈算し、混雑床が䞀番小さい日を探そうずしおいたす。 </p> <ul> <li>ある日付<var>x</var>が、連䌑<var>i</var>によっお受ける圱響の床合を衚す数倀は、日付<var>x</var>が連䌑<var>i</var>の䞭に含たれおいれば<var>S<sub>i</sub></var>であり、そうでなければ、 <var>max</var>( 0, <var>S<sub>i</sub> &minus; min</var> ( <var>x</var>から連䌑<var>i</var>の初日たでの日数 , 連䌑<var>i</var>の最終日から<var>x</var>たでの日数 ) )である</li> <li>ある日付<var>x</var>の混雑床は、<var>N</var>個の連䌑から受ける圱響の床合の䞭で、最も倧きく受ける圱響の床合ずなる</li> </ul> <p> 1幎の䞭で䞀番小さい混雑床を出力しおください。 ただし、連䌑<var>i</var>は幎を跚ぐ事がありたす。たた、連䌑の日皋は重耇する事がありたす。<br> </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>M<sub>1</sub></var> <var>D<sub>1</sub></var> <var>V<sub>1</sub></var> <var>S<sub>1</sub></var> <var>M<sub>2</sub></var> <var>D<sub>2</sub></var> <var>V<sub>2</sub></var> <var>S<sub>2</sub></var> ... <var>M<sub>N</sub></var> <var>D<sub>N</sub></var> <var>V<sub>N</sub></var> <var>S<sub>N</sub></var> </pre> <p> 1行目に敎数<var>N</var>が䞎えられる。<br> 2行目から<var>N</var>+1行目に敎数<var>M<sub>i</sub></var>, <var>D<sub>i</sub></var>, <var>V<sub>i</sub></var>, <var>S<sub>i</sub></var>が空癜区切りで䞎えられる。1 &le; <var>i</var> &le; <var>N</var> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var> &le; 100</li> <li>1 &le; <var>M<sub>i</sub></var> &le; 12</li> <li>1 &le; <var>D<sub>i</sub></var> &le; 30</li> <li>1 &le; <var>V<sub>i</sub></var>, <var>S<sub>i</sub></var> &le; 360</li> </ul> <h2>Output</h2> <p> 䞀番小さい混雑床を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 1 1 1 359 1 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <h2>Sample Input 2</h2> <pre> 2 2 4 25 306 1 9 7 321 </pre> <h2>Sample Output 2</h2> <pre> 158 </pre> <h2>Sample Input 3</h2> <pre> 8 2 9 297 297 8 6 359 211 8 16 28 288 7 9 113 143 3 18 315 190 10 18 277 300 9 5 276 88 3 5 322 40 </pre> <h2>Sample Output 3</h2> <pre> 297 </pre>
p00085
<H1>ペセフのおむモ</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_13_1"> </center> <br/> <p>昔、ペセフのおむモずいうゲヌムがありたした。<var>n</var> 人が参加しおいるずしたしょう。参加者は䞭心を向いお円陣を組み、1 から順番に番号が振られたす。アツアツのおむモがひず぀、参加者 <var>n</var> (巊の図内偎の倧きい数字の 30 )に枡されたす。おむモを枡された参加者は右隣の参加者にそのおむモを枡したす。 <var>m</var> 回目に枡された人は右隣の人に枡しお円陣から抜けたす(巊の図では <var>m</var> = 9 の堎合を衚しおいたす) 。 回枡す毎に䞀人ず぀ぬけ、最埌に残った人が勝者ずなり、おむモをいただきたす。 </p> <p> <var>n</var> ,<var>m</var> が決たっおから、実際におむモを枡し始める前にどこにいたら勝おるかわかるずいいですよね。䞊の図は 30 人の参加者で 9 人ごずに抜けるずいうルヌルでこのゲヌムをした堎合を曞き衚しおいたす。内偎の倧きい数字が参加者に振られた番号、倖偎の小さい数字が抜ける順番です。それによるず、9,18,27,6,16,26 ずいう順番で円陣から抜け出し、最埌には 21 が残るこずになりたす。すなわち 21 が勝者ずなりたす(小さい数字が 30 になっおいたす)。 </p> <p> ゲヌム参加者数 <var>n</var> ず円陣から抜け出す参加者の間隔 <var>m</var> を入力し、勝者の番号を出力するプログラムを䜜成しおください。ただし、<var>m</var>, <var>n</var> &lt; 1000 ずしたす。 </p> <H2>入力</H2> <p>耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。</p> <pre> <var>n</var> <var>m</var> </pre> <p> ゲヌム参加者数 <var>n</var> 敎数ず円陣から抜け出す参加者の間隔 <var>m</var> 敎数が空癜区切りで行に䞎えられたす。 </p> <p>入力は぀の 0 で終わりたす。デヌタセットの数は 50 を超えたせん。</p> <H2>出力</H2> <p>各デヌタセットに察しお、勝者ずなりおむモをいただく人の番号敎数を行に出力しおください。</P> <H2>Sample Input</H2> <pre> 41 3 30 9 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 31 21 </pre>
p02542
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a board with <var>N</var> rows and <var>M</var> columns. The information of this board is represented by <var>N</var> strings <var>S_1,S_2,\ldots,S_N</var>. Specifically, the state of the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is represented as follows:</p> <ul> <li><var>S_{i,j}=</var><code>.</code> : the square is empty.</li> <li><var>S_{i,j}=</var><code>#</code> : an obstacle is placed on the square.</li> <li><var>S_{i,j}=</var><code>o</code> : a piece is placed on the square.</li> </ul> <p>Yosupo repeats the following operation:</p> <ul> <li>Choose a piece and move it to its right adjecent square or its down adjacent square. Moving a piece to squares with another piece or an obstacle is prohibited. Moving a piece out of the board is also prohibited.</li> </ul> <p>Yosupo wants to perform the operation as many times as possible. Find the maximum possible number of operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>1 \leq M \leq 50</var></li> <li><var>S_i</var> is a string of length <var>M</var> consisting of <code>.</code>, <code>#</code> and <code>o</code>.</li> <li><var>1 \leq (</var> the number of pieces <var>)\leq 100</var>. In other words, the number of pairs <var>(i, j)</var> that satisfy <var>S_{i,j}=</var><code>o</code> is between <var>1</var> and <var>100</var>, both inclusive.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>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>Print the maximum possible number of operations in a line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 o.. ... o.# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>Yosupo can perform operations <var>4</var> times as follows:</p> <pre>o.. .o. ..o ... ... ... -&gt; ... -&gt; ... -&gt; ..o -&gt; ..o o.# o.# o.# o.# .o# </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 10 .#....o#.. .#..#..##o .....#o.## .###.#o..o #.#...##.# ..#..#.### #o.....#.. ....###..o o.......o# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>24 </pre></section> </div> </span>
p02811
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has <var>K</var> <var>500</var>-yen coins. (Yen is the currency of Japan.) If these coins add up to <var>X</var> yen or more, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq 100</var></li> <li><var>1 \leq X \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>K</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the coins add up to <var>X</var> yen or more, 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 900 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>Two <var>500</var>-yen coins add up to <var>1000</var> yen, which is not less than <var>X = 900</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 501 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>One <var>500</var>-yen coin is worth <var>500</var> yen, which is less than <var>X = 501</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 2000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre> <p>Four <var>500</var>-yen coins add up to <var>2000</var> yen, which is not less than <var>X = 2000</var> yen.</p></section> </div> </span>
p03703
<span class="lang-en"> <p>Score : <var>600</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 =</var> {<var>a_1, a_2, 
, a_N</var>}, and an integer <var>K</var>.</p> <p><var>a</var> has <var>N(N+1)/2</var> non-empty contiguous subsequences, {<var>a_l, a_{l+1}, 
, a_r</var>} <var>(1 ≀ l ≀ r ≀ N)</var>. Among them, how many have an arithmetic mean that is greater than or equal to <var>K</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 ≀ N ≀ 2 \times 10^5</var></li> <li><var>1 ≀ K ≀ 10^9</var></li> <li><var>1 ≀ a_i ≀ 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>a_1</var> <var>a_2</var> <var>:</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to <var>K</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 6 7 5 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>All the non-empty contiguous subsequences of <var>a</var> are listed below:</p> <ul> <li>{<var>a_1</var>} = {<var>7</var>}</li> <li>{<var>a_1, a_2</var>} = {<var>7, 5</var>}</li> <li>{<var>a_1, a_2, a_3</var>} = {<var>7, 5, 7</var>}</li> <li>{<var>a_2</var>} = {<var>5</var>}</li> <li>{<var>a_2, a_3</var>} = {<var>5, 7</var>}</li> <li>{<var>a_3</var>} = {<var>7</var>}</li> </ul> <p>Their means are <var>7</var>, <var>6</var>, <var>19/3</var>, <var>5</var>, <var>6</var> and <var>7</var>, respectively, and five among them are <var>6</var> or greater. Note that {<var>a_1</var>} and {<var>a_3</var>} are indistinguishable by the values of their elements, but we count them individually.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 26 10 20 30 40 30 20 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>13 </pre></section> </div> </span>
p00986
<h2>Parentheses Editor</h2> <p> You are working with a strange text editor for texts consisting only of open and close parentheses. The editor accepts the following three keys as editing commands to modify the text kept in it. </p> <ul> <li> ‘<span>(</span>’ appends an open parenthesis (‘<span>(</span>’) to the end of the text.</li> <li> ‘<span>)</span>’ appends a close parenthesis (‘<span>)</span>’) to the end of the text.</li> <li> ‘<span>-</span>’ removes the last character of the text.</li> </ul> <p> A balanced string is one of the following. </p> <ul> <li> “<span>()</span>”</li> <li> “<span>(</span>$X$<span>)</span>” where $X$ is a balanced string</li> <li> “$XY$” where both $X$ and $Y$ are balanced strings</li> </ul> <p> Initially, the editor keeps an empty text. You are interested in the number of balanced substrings in the text kept in the editor after each of your key command inputs. Note that, for the same balanced substring occurring twice or more, their occurrences should be counted separately. Also note that, when some balanced substrings are inside a balanced substring, both the inner and outer balanced substrings should be counted. </p> <h3>Input</h3> <p> The input consists of a single test case given in a line containing a number of characters, each of which is a command key to the editor, that is, either ‘<span>(</span>’, ‘<span>)</span>’, or ‘<span>-</span>’. The number of characters does not exceed 200 000. They represent a key input sequence to the editor. </p> <p> It is guaranteed that no ‘<span>-</span>’ command comes when the text is empty. </p> <h3>Output</h3> <p> Print the numbers of balanced substrings in the text kept in the editor after each of the key command inputs are applied, each in one line. Thus, the number of output lines should be the same as the number of characters in the input line. </p> <h3>Sample Input 1 </h3> <pre> (()())---) </pre> <h3>Sample Output 1</h3> <pre> 0 0 1 1 3 4 3 1 1 2 </pre> <h3>Sample Input 2 </h3> <pre> ()--()()----)(()())) </pre> <h3>Sample Output 2</h3> <pre> 0 1 0 0 0 1 1 3 1 1 0 0 0 0 0 1 1 3 4 4 </pre>
p01694
<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> <!-- begin en only --> <!--<h3><u>Step Aerobics</u></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><u>螏み台昇降</u></h3> <!-- end ja only --> <p>JAG倧孊に通う䞀暹君通称カヌ君はこの倏友達であるあなたに誘われおICPC (International Collegiate Potchari Contest) に出堎するこずになった ICPCはスポヌツ系のコンテストであり高床な運動胜力が必芁ずされる しかしカヌ君はい぀もパ゜コンの前にいおばかりで少し動くだけでも疲れおしたうほどに運動䞍足だった そこでカヌ君はICPCでいい成瞟を残すための第1ステップずしお手軜に始められる運動「螏み台昇降」を始めるこずにした </p> <p>螏み台昇降ずはその名の通り螏み台ず床ずの䞊り䞋りをただひたすら繰り返すだけの単玔な運動である ただし螏み台昇降では正しい足の昇降を行わなければその効果を埗るこずはできない 正しい昇降ずは以䞋の2皮類の内いずれかを満たす足の動きである </p> <ul><li> 䞡足が床に぀いた状態から巊足ず右足を螏み台の䞊に䞊げお螏み台の䞊に䞡足ずも぀いた状態になる巊足ず右足どちらを先に䞊げおもよい </li><li> 螏み台の䞊に䞡足ずも぀いた状態から巊足ず右足を床に䞋げお䞡足が床に぀いた状態になる巊足ず右足どちらを先に䞋げおもよい </li></ul> <p>以䞊からわかるように床たたは螏み台の䞊にいる状態から連続で片足だけを䞊げ䞋げしおも正しい昇降ずはならない 螏み台昇降運動では䞊蚘の正しい昇降の動きのいずれかを満たすずき1回ずカりントしそのカりント数が倧きければ倧きいほど効果を埗るこずができる 床ず螏み台を埀埩しなくおも片道だけで1回ずカりントするこずに泚意しおほしい </p> <p>あなたはチヌムメむトであるカヌ君に少しでも匷くなっおほしいず考えおいる そこであなたはカヌ君が螏み台昇降をさがっおいないかプログラムを曞いおチェックしおあげるこずにした カヌ君が螏み台昇降で動かした足の情報が䞎えられるので正しく昇降を行った回数を求めよ ただし<b>䞡足ずも床に぀いおいる状態から螏み台昇降を始める</b>ものずする </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットから構成され1぀の入力に含たれるデヌタセットの数は150以䞋である 各デヌタセットの圢匏は次の通りである </p> <blockquote>$n$<br>$f_1$ $f_2$ ... $f_n$</blockquote> <p>1行目で足を動かした回数を衚す敎数 $n$ ($1 \le n \le 100$) が䞎えられる 2行目で足の動䜜を衚す文字列である $f_i$ が時系列順に $n$ 個スペヌス区切りで䞎えられる $f_i$ は以䞋の4皮類の文字列の内いずれかである </p> <ul><li> "<samp>lu</samp>" : 巊足を螏み台ぞ䞊げる </li><li> "<samp>ru</samp>" : 右足を螏み台ぞ䞊げる </li><li> "<samp>ld</samp>" : 巊足を床ぞ䞋げる </li><li> "<samp>rd</samp>" : 右足を床ぞ䞋げる </li></ul> <p>床に぀いおいる足をさらに䞋げるような動䜜や螏み台に぀いおいる足をさらに䞊げるような動䜜は入力されないず仮定しおよい </p> <p>$n$ が0の行は入力の終わりを衚すこのデヌタに぀いおは凊理を行っおはならない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに察しお1行で正しい螏み台昇降を行った回数を出力せよ 各行の終わりに改行を出力しない堎合や䞍必芁な文字を出力する堎合誀答ず刀断されおしたうため泚意するこず </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>4 lu ru ld rd 4 lu ld lu ru 1 lu 10 ru lu ld rd ru rd ru lu rd ld 0</pre> <h3>Output for Sample Input</h3> <pre>2 1 0 4</pre>
p03353
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>s</var>. Among the <strong>different</strong> substrings of <var>s</var>, print the <var>K</var>-th lexicographically smallest one.</p> <p>A substring of <var>s</var> is a string obtained by taking out a non-empty contiguous part in <var>s</var>. For example, if <var>s</var> <var>=</var> <code>ababc</code>, <code>a</code>, <code>bab</code> and <code>ababc</code> are substrings of <var>s</var>, while <code>ac</code>, <code>z</code> and an empty string are not. Also, we say that substrings are different when they are different as strings.</p> <p>Let <var>X = x_{1}x_{2}...x_{n}</var> and <var>Y = y_{1}y_{2}...y_{m}</var> be two distinct strings. <var>X</var> is lexicographically larger than <var>Y</var> if and only if <var>Y</var> is a prefix of <var>X</var> or <var>x_{j} &gt; y_{j}</var> where <var>j</var> is the smallest integer such that <var>x_{j} \neq y_{j}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>|s|</var> <var>≀</var> <var>5000</var></li> <li><var>s</var> consists of lowercase English letters.</li> <li><var>1</var> <var>≀</var> <var>K</var> <var>≀</var> <var>5</var></li> <li><var>s</var> has at least <var>K</var> different substrings.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>200</var> points will be awarded as a partial score for passing the test set satisfying <var>|s|</var> <var>≀</var> <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>s</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the <var>K</var>-th lexicographically smallest substring of <var>K</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>aba 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>b </pre> <p><var>s</var> has five substrings: <code>a</code>, <code>b</code>, <code>ab</code>, <code>ba</code> and <code>aba</code>. Among them, we should print the fourth smallest one, <code>b</code>. Note that we do not count <code>a</code> twice.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>atcoderandatcodeer 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>andat </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>z 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>z </pre></section> </div> </span>
p01401
<h2> Problem D: 䌝説の剣 </h2> <p> ※ この問題には厚二成分が倚く含たれたす。胞焌けにご泚意ください。 </p> <p> ぀いに埩掻を遂げた魔王は、再び䞖界を闇に包むために人間界に攻め入ろうずしおいた。 </p> <p> 魔王は、本栌的な䟵攻を始める前に、たず䌝説の剣を砎壊するこずにした。 前回の戊争においお、魔王は䌝説の剣を持぀勇者によっお倒された。 魔王の䜓は闇の衣によっお守られおいるため、生半可な攻撃では魔王を傷぀けるこずはできない。 しかし、䌝説の剣は、神々の加護により、魔王の闇の衣すら容易に貫いおしたう。 そのため、今回の戊争に勝利するためには、なんずしおもその䌝説の剣を手に入れお砎壊する必芁がある。 </p> <p> 調査の末、䌝説の剣はずある遺跡の最奥に安眮され、次代の勇者が珟われるのを埅っおいるこずがわかった。 䌝説の剣は、邪悪な者や盗賊によっお奪われるのを防ぐために、呚囲に点圚する無数の宝珠によっお封印されおいる。 魔王は、匷力な魔力を持っおいるため、觊れるだけで宝珠を砎壊するこずができる。 ただし、宝珠による封印は倚重構造になっおおり、衚局から順に砎壊しおいく必芁がある。 䟋えば、第1の封印の宝珠を砎壊する前に第2以降の封印の宝珠に觊れたずしおも、砎壊するこずはできない。 たた、耇数の宝珠が同じ封印を構成しおいるこずもあるが、魔王はそのうちの䞀぀に觊れるだけで、同時にその封印を砎壊するこずができる。 </p> <p> 遺跡には神聖な力が満ちおおり、䞊の魔物では入るこずすらたたならない。 そこで、魔王自ら赎き䌝説の剣を回収しおくるこずになった。 いかに魔王ずいえど、長時間その力を受け続ければただではすたない。 魔王の右腕であるあなたの仕事は、念のため魔王が党おの封印を砎壊し、䌝説の剣の䞋に蟿り぀くたでの時間を求めるこずである。 </p> <h2> Input </h2> <p> 入力は、耇数のデヌタセットからなり、入力の終わりはスペヌスで区切られたれロ二぀からなる行である。 デヌタセットの総数は50以䞋である。 各デヌタセットは、次の圢匏をしおいる。 </p> <pre> <i>w</i> <i>h</i> <i>s(1,1)</i> ... <i>s(1,w)</i> <i>s(2,1)</i> ... <i>s(2,w)</i> ... <i>s(h,1)</i> ... <i>s(h,w)</i> </pre> <p> <i>w</i>ず<i>h</i>は、それぞれ遺跡のフロアを衚珟する行列デヌタの幅ず高さを瀺す敎数であり、それぞれ<i>1 &le; w, h &le; 100</i>であり、<i>2 &le; w + h &le; 100</i>ず仮定しお良い。 続く<i>h</i>行はそれぞれ、スペヌスで区切られた<i>w</i>個の文字から構成されおおり、文字<i>s(y,x)</i>は、座暙<i>(y,x)</i>の地点の状態を瀺す。 </p> <p> その意味は、以䞋の通りである。 <ul> <li> S魔王が最初にいる地点。フロアに必ず1぀だけ存圚する。</li> <li> G䌝説の剣の地点。必ず1぀だけ存圚する。</li> <li> .なにもない。</li> <li> 数字宝珠がある地点。数字は構成する封印の番号を瀺す。数字は1以䞊の敎数であり、間の数字に抜けはないずしおよい。</li> </ul> たた、魔王は、遺跡のフロア内の䞊䞋巊右の隣接する座暙に移動するこずができ、その移動にかかる時間を1ずする。 砎壊できる宝珠は觊れるだけで砎壊できるため、宝珠の砎壊には時間はかからない。 </p> <h2> Output </h2> <p> 各デヌタセットに察しお、魔王が党おの封印を砎壊し、䌝説に剣に蟿り぀くために必芁な最短時間を出力せよ。 </p> <h2> Sample Input </h2> <pre> 10 10 S . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . 4 . . . . . . . . . . . . . . 2 . . . . . . . . G 10 10 S . . . . . 3 . . . . . 3 . . . . . . . . . . . 1 . . . . . . . . . . . 4 . . . . . 3 . . . 1 . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . 4 . . . . . . . . . 5 . . . . 2 . . . . . . . . G 10 10 S . . . . . . . . 1 . . . . . 5 . . . . . 4 . . . . . . . . . . . . 8 . 9 . . . . . . . 10 . . . . . . . 7 . G . . . . . . . . 11 . . . . . . 3 . . . . . . . . 6 . . . . . . . 2 . . . . . . . . . . . . 0 0 </pre> <h2> Output for Sample Input </h2> <pre> 38 36 71 </pre>
p01051
<h1>Squid Ink</h1> <h2>Problem</h2> <p> 近幎、むカたちの間では瞄匵り争いが頻繁に起きおいる。耇数のむカたちがチヌムを組み、自らのむカスミを歊噚に戊うのが近幎のむカの戊闘スタむルである。 </p> <p> 珟圚も瞄匵り争いが起こっおおり、その戊堎は <var>R</var>&times;<var>C</var> のグリッドで衚される。瞄匵り争いに参加しおいるむカのゲ゜倪はこのグリッド䞊のある堎所にいる。この争いでは、重芁な堎所を敵よりも早く占拠するこずで戊況を有利にするこずができる。そのため、ゲ゜倪は重芁そうな堎所を1぀決め、そこになるべく早く移動したいず考えおいる。 </p> <p> ゲ゜倪は隣接する䞊䞋巊右のマスに移動するこずができる。グリッドの各マスには味方、たたは敵のむカスミが塗られおいる堎合がある。なにも塗られおいないマスに移動する堎合、2秒かかるが、味方のむカスミが塗られおいるマスに移動する堎合、その半分の時間(1秒)で枈む。敵のむカスミが塗られおいるマスには移動するこずができない。壁があるマスや戊堎の倖ぞは圓然移動するこずができない。 </p> <p> たた、ゲ゜倪は䞊䞋巊右のいずれかの方向を向き、むカスミを吐くこずができる。するず、前方の3マスが味方のむカスミで䞊曞きされる。ただし途䞭に壁がある堎合はその手前たでしかむカスミは届かない。この動䜜には2秒かかる。 </p> <p> 戊堎の情報ずゲ゜倪の䜍眮ず目的の䜍眮が䞎えられるので、最短で䜕秒で移動できるか求めおほしい。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>R</var> <var>C</var> <var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,C</sub></var> <var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,C</sub></var> : <var>a<sub>R,1</sub></var> <var>a<sub>R,2</sub></var> ... <var>a<sub>R,C</sub></var> </pre> <p> 1行目に2぀の敎数<var>R</var>,<var>C</var>が空癜区切りで䞎えられる。続く<var>R</var>行に戊堎の情報ずしお<var>C</var>個のマスの情報が䞎えられる。<var>a<sub>i,j</sub></var>は戊堎の䜍眮(<var>i</var>,<var>j</var>)のマスの情報を衚し、以䞋のいずれかの文字である。 </p> <ul> <li>'.': なにも塗られおいないマス</li> <li>'#': 壁</li> <li>'o': 味方のむカスミが塗られおいるマス</li> <li>'x': 敵のむカスミが塗られおいるマス</li> <li>'S': ゲ゜倪の䜍眮(入力䞭に1぀だけ存圚し、マスはなにも塗られおいない)</li> <li>'G': 目的の䜍眮(入力䞭に1぀だけ存圚し、マスはなにも塗られおいない)</li> </ul> <p> 䞎えられる入力は、目的の䜍眮たで移動するこずが可胜であるこずが保蚌される。 </p> <h2>Constraints</h2> <ul> <li>2 &le; <var>R</var>,<var>C</var> &le; 30</li> </ul> <h2>Output</h2> <p> ゲ゜倪が目的の䜍眮たで移動するのにかかる最短の秒数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 5 5 S.... ..... ..... ..... ....G </pre> <h2>Sample Output 1</h2> <pre> 14 </pre> <h2>Sample Input 2</h2> <pre> 5 5 Sxxxx xxxxx xxxxx xxxxx xxxxG </pre> <h2>Sample Output 2</h2> <pre> 15 </pre> <h2>Sample Input 3</h2> <pre> 4 5 S#... .#.#. .#.#. ...#G </pre> <h2>Sample Output 3</h2> <pre> 23 </pre> <h2>Sample Input 4</h2> <pre> 4 5 S#ooo o#o#o o#o#o ooo#G </pre> <h2>Sample Output 4</h2> <pre> 14 </pre> <h2>Sample Input 5</h2> <pre> 4 5 G#### ooxoo ##x#o Soooo </pre> <h2>Sample Output 5</h2> <pre> 10 </pre>
p03596
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>A</var> slimes lining up in a row. Initially, the sizes of the slimes are all <var>1</var>.</p> <p>Snuke can repeatedly perform the following operation.</p> <ul> <li>Choose a positive even number <var>M</var>. Then, select <var>M</var> consecutive slimes and form <var>M / 2</var> pairs from those slimes as follows: pair the <var>1</var>-st and <var>2</var>-nd of them from the left, the <var>3</var>-rd and <var>4</var>-th of them, <var>...</var>, the <var>(M-1)</var>-th and <var>M</var>-th of them. Combine each pair of slimes into one larger slime. Here, the size of a combined slime is the sum of the individual slimes before combination. The order of the <var>M / 2</var> combined slimes remain the same as the <var>M / 2</var> pairs of slimes before combination.</li> </ul> <p>Snuke wants to get to the situation where there are exactly <var>N</var> slimes, and the size of the <var>i</var>-th (<var>1 ≀ i ≀ N</var>) slime from the left is <var>a_i</var>. Find the minimum number of operations required to achieve his goal.</p> <p>Note that <var>A</var> is not directly given as input. Assume <var>A = a_1 + a_2 + ... + a_N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^5</var></li> <li><var>a_i</var> is an integer.</li> <li><var>1 ≀ a_i ≀ 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>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 operations required to achieve Snuke's goal.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>One way to achieve Snuke's goal is as follows. Here, the selected slimes are marked in bold.</p> <ul> <li>(1, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, 1) → (1, <strong>2</strong>, <strong>2</strong>, 1)</li> <li>(<strong>1</strong>, <strong>2</strong>, <strong>2</strong>, <strong>1</strong>) → (<strong>3</strong>, <strong>3</strong>)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>One way to achieve Snuke's goal is as follows.</p> <ul> <li>(<strong>1</strong>, <strong>1</strong>, 1, 1, 1, 1, 1) → (<strong>2</strong>, 1, 1, 1, 1, 1)</li> <li>(2, 1, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>) → (2, 1, <strong>2</strong>, <strong>2</strong>)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 3 1 4 1 5 9 2 6 5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>10 </pre></section> </div> </span>
p00210
<H1>ザ・スク゚アヌズ</H1> <p> この床、有名なテヌマパヌクに、巚倧迷路ザ・スク゚アヌズが新しく完成したした。 消防眲の指導により避難蚓緎をしなければなりたせんが、巚倧迷路なだけに蚓緎にかかる時間を予枬するこずができたせん。そこで、あなたは以䞋の仕様をもずに避難蚓緎シミュレヌタを開発するこずになりたした。 </p> <p> 巚倧迷路は図 1 に瀺すように、暪 <var>W</var> 、瞊 <var>H</var> の <var>W &times; H</var> 個のマス目で衚わされたす。各マス目は、通路(癜いマス目)、壁(茶色いマス目) 、非垞口(緑のマス目)のいずれかです。図䞭の○は人を衚し、その䞭の英小文字(E、W、S、N)はその人が向いおいる方角(東西南北)を衚しおいたす。図は䞊方向が北になるように描かれおいたす。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_squares"> <p>図1</p> </center> <br/> <p> 巚倧迷路内にいる人は最初、東西南北のいずれかの方向を向いお立っおいたす。各人は 1 秒単䜍で同時に次に瀺す手順で移動を詊みたす。 </p> <ol> <li>珟圚向いおいる方向の、右、前、巊、埌のマス目を順番に調べ、最初に芋぀けた、空いおいる通路たたは非垞口の方向に向きを倉えたす。そのようなマス目が無い堎合は向きを倉えたせん。</li> <li> 目の前のマス目が空いおいお、他の人の目の前のマス目になっおいない堎合は移動したす。同じマス目を目の前のマスずする人が耇数いる堎合は、そのマス目の、東、北、西、南のマス目にいる人の順で遞択された 1 人が移動したす。 </li> </ol> <p> 移動埌に非垞口に到着した人は、無事避難し迷路内から消えたす。 </p> <p> 䞎えられた巚倧迷路ず人の䜍眮情報を入力ずし、党おの人が避難し終える時間を出力するプログラムを䜜成しおください。 脱出に 180 秒より長い時間を芁する堎合は NA ず出力しお䞋さい。 迷路ず人の䜍眮情報は、 <var>H</var> 行 <var>W</var> 列の文字によっお䞎えられたす。各文字の意味は以䞋のずおりです。 </p> <p> <span>#</span> : 壁<br> <span>.</span> : 床<br> <span>X</span> : 非垞口<br> <span>E</span> : 東を向いおいる人<br> <span>N</span> : 北を向いおいる人<br> <span>W</span> : 西を向いおいる人<br> <span>S</span> : 南を向いおいる人<br> </p> <p> なお、迷路ず倖郚ずの境界は壁 <span>#</span> たたは非垞口 <span>X</span> のいずれかです。たた、巚倧迷路の䞭には、人が必ず人以䞊いたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。 入力の終わりはれロふた぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>W</var> <var>H</var> <var>str<sub>1</sub></var> <var>str<sub>2</sub></var> : <var>str<sub>H</sub></var> </pre> <p> 1 行目に迷路の暪方向の倧きさ <var>W</var>、瞊方向の倧きさ <var>H</var> (1 &le; <var>W, H</var> &le; 30) が䞎えられたす。続く <var>H</var> 行に迷路の <var>i</var> 行目を衚す文字列 <var>str<sub>i</sub></var> (長さ <var>W</var>) が䞎えられたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、党おの人が避難し終える時間を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 10 3 ########## #E.......X ########## 4 4 #### #N.# #..X #### 5 5 ##### #N..# ###.X #S..# ##### 6 6 ###### #..#X# #.EE.# ####N# #....# ###### 8 8 ##X##### #....E.# #####.## #.#...## #.W.#..# #.#.N#.X #X##.#.# ######## 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 8 NA 9 16 10 </pre>
p01952
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <H1> Tiny Room </H1> <p> You are an employee of Automatic Cleaning Machine (ACM) and a member of the development team of Intelligent Circular Perfect Cleaner (ICPC). ICPC is a robot that cleans up the dust of the place which it passed through. </p> <p> Your task is an inspection of ICPC. This inspection is performed by checking whether the center of ICPC reaches all the $N$ given points. </p> <p> However, since the laboratory is small, it may be impossible to place all the points in the laboratory so that the entire body of ICPC is contained in the laboratory during the inspection. The laboratory is a rectangle of $H \times W$ and ICPC is a circle of radius $R$. You decided to write a program to check whether you can place all the points in the laboratory by rotating and/or translating them while maintaining the distance between arbitrary two points. </p> <H2>Input</H2> <p> The input consists of a single test case of the following format. </p> <pre> $N$ $H$ $W$ $R$ $x_1$ $y_1$ : $x_N$ $y_N$ </pre> <p> The first line consists of four integers $N, H, W$ and $R$ ($1 \leq N \leq 100$, $1 \leq H, W \leq 10^9$, $1 \leq R \leq 10^6$). The following $N$ lines represent the coordinates of the points which the center of ICPC must reach. The ($i+1$)-th line consists of two integers $x_i$ and $y_i$ ($0 \leq x_i, y_i \leq 10^9$). $x_i$ and $y_i$ represent the $x$ and $y$ coordinates of the $i$-th point, respectively. It is guaranteed that the answer will not change even if $R$ changes by $1$. </p> <H2>Output</H2> <p> If all the points can be placed in the laboratory, print '<span>Yes</span>'. Otherwise, print '<span>No</span>'. </p> <H2>Sample Input 1</H2> <pre> 4 20 20 1 10 0 20 10 10 20 0 10 </pre> <H2>Output for Sample Input 1</H2> <pre> Yes </pre> <p> All the points can be placed in the laboratory by rotating them through $45$ degrees. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummer2017_tinyRoom" width="480"> </center> <H2>Sample Input 2</H2> <pre> 2 5 55 1 0 0 30 40 </pre> <H2>Output for Sample Input 2</H2> <pre> Yes </pre> <H2>Sample Input 3</H2> <pre> 2 5 49 1 0 0 30 40 </pre> <H2>Output for Sample Input 3</H2> <pre> No </pre> <H2>Sample Input 4</H2> <pre> 1 3 3 1 114 514 </pre> <H2>Output for Sample Input 4</H2> <pre> Yes </pre>
p00640
<H1><font color="#000000">Problem D:</font> Distorted Love</H1> <p> Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal information. The word "privacy" is not in her dictionary. A person like her is called "stoker" or "<i>yandere</i>", but it doesn't mean much to her. </p> <p> To know about him, she set up spyware to his PC. This spyware can record his mouse operations while he is browsing websites. After a while, she could successfully obtain the record from the spyware in absolute secrecy. </p> <p> Well, we want you to write a program which extracts web pages he visited from the records. </p> <p> All pages have the same size <i>H</i> &times; <i>W</i> where upper-left corner is (0, 0) and lower right corner is (<i>W</i>, <i>H</i>). A page includes several (or many) rectangular buttons (parallel to the page). Each button has a link to another page, and when a button is clicked the browser leads you to the corresponding page. </p> <p> His browser manages history and the current page in the following way: </p> <p> The browser has a buffer of 1-dimensional array with enough capacity to store pages, and a pointer to indicate a page in the buffer. A page indicated by the pointer is shown on the browser. At first, a predetermined page is stored and the pointer indicates that page. When the link button is clicked, all pages recorded in the right side from the pointer are removed from the buffer. Then, the page indicated by the link button is stored into the right-most position of the buffer, and the pointer moves to right. As a result, the user browse the page indicated by the button. </p> <p> The browser also has special buttons 'back to the previous page' (back button) and 'forward to the next page' (forward button). When the user clicks the back button, the pointer moves to left, and the user clicks the forward button, the pointer moves to right. But in both cases, if there are no such pages in the buffer, nothing happen. </p> <p> The record consists of the following operations: </p> <pre> click x y </pre> <p> It means to click (<i>x</i>, <i>y</i>). If there is a button on the point (<i>x</i>, <i>y</i>), he moved to the corresponding page. If there is nothing in the point, nothing happen. The button is clicked if <i>x</i>1 &le; <i>x</i> &le; <i>x</i>2 and <i>y</i>1 &le; <i>y</i> &le; <i>y</i>2 where <i>x</i>1, <i>x</i>2 means the leftmost and rightmost coordinate and <i>y</i>1, <i>y</i>2 means the topmost and bottommost coordinate of the corresponding button respectively. </p> <pre> back </pre> <p> It means to click the Back button. </p> <pre> forward </pre> <p> It means to click the Forward button. </p> <p> In addition, there is a special operation <span>show</span>. Your program should print the name of current page for each <span>show</span> operation. </p> <p> By the way, setting spyware into computers of others may conflict with the law. Do not attempt, or you will be reprimanded by great men. </p> <H2>Input</H2> <p> Input consists of several datasets. </p> <p> Each dataset starts with an integer <i>n</i> which represents the number of pages in the dataset. </p> <p> Next line contains two integers <i>W</i> and <i>H</i>. </p> <p> Next, information of each page are given. Each page starts with a string of characters and <i>b</i>[<i>i</i>], the number of buttons the page has. Following <i>b</i>[<i>i</i>] lines give information of buttons. Each button consists of four integers representing the coordinate (<i>x</i>1, <i>y</i>1) of upper left corner and the coordinate (<i>x</i>2, <i>y</i>2) of lower right corner of the button and a string of characters, which represents the name of page that the link of the button represents. </p> <p> Next, the number of operation <i>m</i> is given. Following <i>m</i> lines represent the record of operations. Please see the above description for the operation. </p> <p> The first page is stored in the buffer at first. </p> <p> Input ends when <i>n</i> = 0. </p> <H2>Output</H2> <p> For each dataset, output the name of current page for each <span>show</span> operation. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>n</i> &le; 100</li> <li><i>b</i>[<i>i</i>] &le; 100</li> <li>1 &le; the number of characters in the name &le; 20</li> <li>Buttons are not touch, overlapped nor run over from the browser.</li> </ul> <H2>Sample Input</H2> <pre> 3 800 600 index 1 500 100 700 200 profile profile 2 100 100 400 200 index 100 400 400 500 link link 1 100 100 300 200 index 9 click 600 150 show click 200 450 show back back show forward show 0 </pre> <H2>Output for the Sample Input</H2> <pre> profile link index profile </pre>
p02387
<H1>Hello World</H1> <p> Welcome to Online Judge! </p> <p> Write a program which prints "Hello World" to standard output. </p> <H2>Input</H2> <p> There is no input for this problem. </p> <H2>Output</H2> <p> Print "Hello World" in a line. </p> <H2>Sample Input 1</H2> <pre> No input </pre> <H2>Sample Output 1</H2> <pre> Hello World </pre>
p03980
<span class="lang-en"> <p>Score : <var>150</var> points</p> <div id="task-statement"> <script src="http://atcoder.jp/js/varmath.js"></script> <div class="part"> <section> <h3>Problem Statement</h3> <p> Gorillas in Kyoto University are good at math. They are currently trying to solve problems to find the value of an expression that contains two functions, <code>_</code> , <code>^</code>. Each of these functions takes two input values. <code>_</code> function returns the smaller of the two input values and <code>^</code> function returns the larger. Gorillas know that integers in the expression are non-negative and less than or equal to <var>99</var>, but can not find out the length of the expression until they read a terminal symbol <code>?</code> that represents the end of the expression. The number of characters included in each expression is less than or equal to 1000, but they do not even know this fact. Ai, a smart gorilla, noticed that she may be able to know the value of the expression even if they don't read the whole expression. </p> <p> For example, </p> <p>Assume you read the following sentence from the left.</p> <pre>^(41,3)?</pre> <p>When you read the sixth character, that is, when you read the following expression,</p> <pre>^(41,3</pre> <p>you can tell the second input value of the funcion is whether <var>3</var> or an integer between <var>30</var> and <var>39</var>, and the value turns out <var>41</var>. </p> <p> Since Ai wants to solve problems earlier than other gorillas, she decided to solve the problems such that she reads as fewer characters as possible from the left. For each expression, Find the value of the expression and the minimum number of characters Ai needs to read to know the value. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq Q \leq 200</var></li> <li>The number of characters each expression contains is less than or equal to <var>1000</var>. </li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>The input consists of multiple test cases and is given from Standard Input in the following format:</p> <pre> <var>Q</var> <var>statement_1</var> ... <var>statement_Q</var> </pre> </section> </div> </div> <p>Each <var>statement_i</var> <var>(1 \leq i \leq Q)</var> is given in the following BNF format.</p> <pre> <var>&lt;statement&gt;</var> ::= <var>&lt;expression&gt;</var> <code>?</code> <var>&lt;expression&gt;</var> ::= (<code>^</code> | <code>_</code>) <code>(</code> <var>&lt;expression&gt;</var> <code>,</code> <var>&lt;expression&gt;</var> <code>)</code> | <var>&lt;number&gt; </var> <var>&lt;number&gt;</var> :: = <code>0</code> | <code>1</code> | <code>2</code> | ... | <code>98</code> | <code>99</code> </pre> <div class="io-style"> <div class="part"> <section> <h3>Output</h3> <p> Output consists of <var>Q</var> lines. On line <var>i</var> <var>(1 \leq i \leq Q)</var>, print the value of the expression and the number of character Ai needs to read for the test case <var>i</var> separated by space. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 4 _(4,51)? ^(99,_(3,67))? _(0,87)? 3? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 4 5 99 4 0 3 3 2 </pre> <ul> <li>For the first test case, when you read the fifth character, that is, when you read <code>_(4,5</code>, you will know the value is <var>4</var>. </li> <li>For the second test case, when you read the fourth character, that is, when you read <code>^(99</code>, you will know the value is <var>99</var>. </li> <li>For the third test case, when you read the third character, that is, when you read <code>_(0</code>, you will know the value is <var>0</var>. </li> <li>For the fourth test case, you will not know the value is <var>3</var> untill you read the terminal symbol.</li> </ul> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 7 _(23,^(_(22,40),4))? _(0,99)? ^(99,_(^(19,2),5))? _(^(43,20),^(30,29))? ^(_(20,3),_(50,41))? ^(_(20,3),_(3,41))? ^(_(20,3),_(4,41))? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 22 18 0 3 99 4 30 17 41 17 3 14 4 15 </pre> </section> </div> </div> </span>
p02692
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a game that involves three variables, denoted <var>A</var>, <var>B</var>, and <var>C</var>.</p> <p>As the game progresses, there will be <var>N</var> events where you are asked to make a choice. Each of these choices is represented by a string <var>s_i</var>. If <var>s_i</var> is <code>AB</code>, you must add <var>1</var> to <var>A</var> or <var>B</var> then subtract <var>1</var> from the other; if <var>s_i</var> is <code>AC</code>, you must add <var>1</var> to <var>A</var> or <var>C</var> then subtract <var>1</var> from the other; if <var>s_i</var> is <code>BC</code>, you must add <var>1</var> to <var>B</var> or <var>C</var> then subtract <var>1</var> from the other.</p> <p>After each choice, none of <var>A</var>, <var>B</var>, and <var>C</var> should be negative.</p> <p>Determine whether it is possible to make <var>N</var> choices under this condition. If it is possible, also give one such way to make the choices.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>0 \leq A,B,C \leq 10^9</var></li> <li><var>N, A, B, C</var> are integers.</li> <li><var>s_i</var> is <code>AB</code>, <code>AC</code>, or <code>BC</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>C</var> <var>s_1</var> <var>s_2</var> <var>:</var> <var>s_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to make <var>N</var> choices under the condition, print <code>Yes</code>; otherwise, print <code>No</code>.</p> <p>Also, in the former case, show one such way to make the choices in the subsequent <var>N</var> lines. The <var>(i+1)</var>-th line should contain the name of the variable (<code>A</code>, <code>B</code>, or <code>C</code>) to which you add <var>1</var> in the <var>i</var>-th choice.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 3 0 AB AC </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes A C </pre> <p>You can successfully make two choices, as follows:</p> <ul> <li>In the first choice, add <var>1</var> to <var>A</var> and subtract <var>1</var> from <var>B</var>. <var>A</var> becomes <var>2</var>, and <var>B</var> becomes <var>2</var>.</li> <li>In the second choice, add <var>1</var> to <var>C</var> and subtract <var>1</var> from <var>A</var>. <var>C</var> becomes <var>1</var>, and <var>A</var> becomes <var>1</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 0 0 AB BC AB </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>1 0 9 0 AC </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>8 6 9 1 AC BC AB BC AC BC AB AB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Yes C B B C C B A A </pre></section> </div> </span>
p00355
<H1>Reservation System</H1> <p> The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap each other. </p> <p> Write a program to report if a new reservation overlaps with any of the existing reservations. Note that the coincidence of start and end times is not considered to constitute an overlap. All the temporal data is given as the elapsed time from the moment at which the L system starts operation. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>a</var> <var>b</var> <var>N</var> <var>s_1</var> <var>f_1</var> <var>s_2</var> <var>f_2</var> : <var>s_N</var> <var>f_N</var> </pre> <p> The first line provides new reservation information, i.e., the start time <var>a</var> and end time <var>b</var> (0 &le; <var>a</var> &lt; <var>b</var> &le; 1000) in integers. The second line specifies the number of existing reservations <var>N</var> (0 &le; <var>N</var> &le; 100). Subsequent <var>N</var> lines provide temporal information for the <var>i</var>-th reservation: start time <var>s_i</var> and end time <var>f_i</var> (0 &le; <var>s_i</var> &lt; <var>f_i</var> &le; 1000) in integers. No two existing reservations overlap. </p> <h2>Output</h2> <p> Output "1" if the new reservation temporally overlaps with any of the existing ones, or "0" otherwise. </p> <h2>Sample Input 1</h2> <pre> 5 7 3 1 4 4 5 7 10 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <h2>Sample Input 2</h2> <pre> 3 7 3 7 10 1 4 4 5 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre>
p02368
<H1>Strongly Connected Components</H1> <p> A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable. </p> <H2>Input</H2> <p> A directed graph <var>G(V, E)</var> and a sequence of queries where each query contains a pair of nodes <var>u</var> and <var>v</var>. </p> <pre> <var>|V|</var> <var>|E|</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>Q</var> <var>u<sub>0</sub></var> <var>v<sub>0</sub></var> <var>u<sub>1</sub></var> <var>v<sub>1</sub></var> : <var>u<sub>Q-1</sub></var> <var>v<sub>Q-1</sub></var> </pre> <p> <var>|V|</var> is the number of nodes and <var>|E|</var> is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively. </p> <p> <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target nodes of <var>i</var>-th edge (directed). </p> <p> <var>u<sub>i</sub></var> and <var>v<sub>i</sub></var> represent a pair of nodes given as the <var>i</var>-th query. </p> <H2>Output</H2> <p> For each query, pinrt "1" if the given nodes belong to the same strongly connected component, "0" otherwise. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>|V|</var> &le; 10,000</li> <li>0 &le; <var>|E|</var> &le; 30,000</li> <li>1 &le; <var>Q</var> &le; 100,000</li> </ul> <H2>Sample Input 1</H2> <pre> 5 6 0 1 1 0 1 2 2 4 4 3 3 2 4 0 1 0 3 2 3 3 4 </pre> <H2>Sample Output 1</H2> <pre> 1 0 1 1 </pre>
p01817
<h2>I - ツむンリバヌス</h2> <p>芁玠数 <var>N</var> の配列 <var>A</var> が䞎えられる。ただし、<var>A</var> は <var>(1, 2,</var> ... <var>, N)</var> の順列である。</p> <p>次の操䜜を <var>0</var> 回以䞊 <var>10,000</var> 回以䞋の任意の回数行い、<var>A</var> を <var>(1, 2,</var> ...<var>, N)</var> ぞ゜ヌトしたい。</p> <ul> <li>敎数 <var>i</var> (<var>1 &le; i &le; N</var>) を <var>1</var> ぀遞び、区間 <var>A[1,\ i-1]</var> の芁玠を逆順にし、区間 <var>A[i+1,\ N]</var> の芁玠を逆順にする。</li> </ul> <p>ただし、区間 <var>A[l,\ r]</var> ずは <var>A</var> の <var>l, l+1,</var> ...<var>, r </var> 番目の䜍眮のこずである。</p> <p><var>A</var> を <var>(1, 2,</var> ...<var>, N)</var> ぞ゜ヌトできるか刀定せよ。゜ヌトできるならば、操䜜の䟋を䞀぀出力せよ。</p> <h3>Constraints</h3> <ul> <li><var>1 &le; N &le; 3,000</var></li> <li><var>A</var> は <var>(1, 2,</var> ... <var>, N)</var> の順列である。</li> </ul> <h3>Input Format</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre> <var>N</var> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> </pre> <h3>Output Format</h3> <p><var>A</var> を <var>(1, 2,</var> ...<var>, N)</var> ぞ゜ヌトできないならば、<code>-1</code> ずだけ䞀行に出力せよ。</p> <p>゜ヌトできるならば、操䜜の䟋を䞀぀次のように出力せよ。</p> <ul> <li><var>1</var> 行目には、操䜜の回数を衚す敎数 <var>M</var> (<var>0 &le; M &le; 10,000</var>) を出力せよ。</li> <li><var>2</var> 行目からの <var>M</var> 行のうち <var>k</var> 行目には、<var>k</var> 回目の操䜜で遞ぶ敎数 <var>i</var> (<var>1 &le; i &le; N</var>) を出力せよ。</li> </ul> <h3>Sample Input 1</h3> <pre> 5 5 1 4 2 3 </pre> <h3>Sample Output 1</h3> <pre> 2 3 1 </pre> <p>䟋えば、次のように <var>2</var> 回の操䜜を行えばよい。</p> <ul> <li><var>i=3</var> を遞ぶず <var>(5,\ 1,\ 4,\ 2,\ 3)</var> → <var>(1,\ 5,\ 4,\ 3,\ 2)</var></li> <li><var>i=1</var> を遞ぶず <var>(1,\ 5,\ 4,\ 3,\ 2)</var> → <var>(1,\ 2,\ 3,\ 4,\ 5)</var></li> </ul> <h3>Sample Input 2</h3> <pre> 2 2 1 </pre> <h3>Sample Output 2</h3> <pre> -1 </pre> <h3>Sample Input 3</h3> <pre> 3 1 2 3 </pre> <h3>Sample Output 3</h3> <pre> 0 </pre>
p00705
<H1> When Can We Meet? </H1> <P> The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, the chairperson requested every member to send back a list of convenient dates by E-mail. Your mission is to help the chairperson, who is now dedicated to other issues of the contest, by writing a program that chooses the best date from the submitted lists. Your program should find the date convenient for the most members. If there is more than one such day, the earliest is the best. </P> <H2>Input</H2> <P> The input has multiple data sets, each starting with a line containing the number of committee members and the quorum of the meeting. <BLOCKQUOTE><I>N Q</I></BLOCKQUOTE> <p> Here, <I>N</I>, meaning the size of the committee, and <I>Q</I> meaning the quorum, are positive integers. <I>N</I> is less than 50, and, of course, <I>Q</I> is less than or equal to <I>N.</I> </P> <P> <I>N</I> lines follow, each describing convenient dates for a committee member in the following format. <BLOCKQUOTE> <I>M Date</I><SUB>1</SUB> <I>Date</I><SUB>2</SUB> ... <I>Date<SUB>M</SUB></I> </BLOCKQUOTE> <p> Here, <I>M</I> means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 100, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces. </P> <P> A line containing two zeros indicates the end of the input. </P> <H2>Output</H2> <P>For each data set, print a single line containing the date number convenient for the largest number of committee members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead.</P> <H2>Sample Input</H2> <PRE> 3 2 2 1 4 0 3 3 4 8 3 2 4 1 5 8 9 3 2 5 9 5 2 4 5 7 9 3 3 2 1 4 3 2 5 9 2 2 4 3 3 2 1 2 3 1 2 9 2 2 4 0 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> 4 5 0 2 </PRE>
p02738
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a positive integer <var>N</var>. Find the number of permutations <var>(P_1,P_2,\cdots,P_{3N})</var> of <var>(1,2,\cdots,3N)</var> that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number <var>M</var>.</p> <ul> <li>Make <var>N</var> sequences <var>A_1,A_2,\cdots,A_N</var> of length <var>3</var> each, using each of the integers <var>1</var> through <var>3N</var> exactly once.</li> <li>Let <var>P</var> be an empty sequence, and do the following operation <var>3N</var> times.<ul> <li>Among the elements that are at the beginning of one of the sequences <var>A_i</var> that is non-empty, let the smallest be <var>x</var>.</li> <li>Remove <var>x</var> from the sequence, and add <var>x</var> at the end of <var>P</var>.</li> </ul> </li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2000</var></li> <li><var>10^8 \leq M \leq 10^9+7</var></li> <li><var>M</var> is a prime number.</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of permutations modulo <var>M</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 998244353 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>All permutations of length <var>3</var> count.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 998244353 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>261 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314 1000000007 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>182908545 </pre></section> </div> </span>
p03083
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Today, Snuke will eat <var>B</var> pieces of black chocolate and <var>W</var> pieces of white chocolate for an afternoon snack.</p> <p>He will repeat the following procedure until there is no piece left:</p> <ul> <li>Choose black or white with equal probability, and eat a piece of that color if it exists.</li> </ul> <p>For each integer <var>i</var> from <var>1</var> to <var>B+W</var> (inclusive), find the probability that the color of the <var>i</var>-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo <var>10^9 + 7</var>, as described in Notes.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>When you print a rational number, first write it as a fraction <var>\frac{y}{x}</var>, where <var>x, y</var> are integers and <var>x</var> is not divisible by <var>10^9 + 7</var> (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer <var>z</var> between <var>0</var> and <var>10^9 + 6</var>, inclusive, that satisfies <var>xz \equiv y \pmod{10^9 + 7}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq B,W \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>B</var> <var>W</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answers in <var>B+W</var> lines. In the <var>i</var>-th line, print the probability that the color of the <var>i</var>-th piece to be eaten is black, modulo <var>10^{9}+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>500000004 750000006 750000006 </pre> <ul> <li>There are three possible orders in which Snuke eats the pieces:<ul> <li>white, black, black</li> <li>black, white, black</li> <li>black, black, white</li> </ul> </li> <li>with probabilities <var>\frac{1}{2}, \frac{1}{4}, \frac{1}{4}</var>, respectively. Thus, the probabilities of eating a black piece first, second and third are <var>\frac{1}{2},\frac{3}{4}</var> and <var>\frac{3}{4}</var>, respectively.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>500000004 500000004 625000005 187500002 187500002 </pre> <ul> <li>They are <var>\frac{1}{2},\frac{1}{2},\frac{5}{8},\frac{11}{16}</var> and <var>\frac{11}{16}</var>, respectively.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>500000004 500000004 500000004 500000004 500000004 500000004 929687507 218750002 224609377 303710940 633300786 694091802 172485353 411682132 411682132 </pre></section> </div> </span>
p03579
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Rng has a connected undirected graph with <var>N</var> vertices. Currently, there are <var>M</var> edges in the graph, and the <var>i</var>-th edge connects Vertices <var>A_i</var> and <var>B_i</var>.</p> <p>Rng will add new edges to the graph by repeating the following operation:</p> <ul> <li>Operation: Choose <var>u</var> and <var>v</var> <var>(u \neq v)</var> such that Vertex <var>v</var> can be reached by traversing exactly three edges from Vertex <var>u</var>, and add an edge connecting Vertices <var>u</var> and <var>v</var>. It is not allowed to add an edge if there is already an edge connecting Vertices <var>u</var> and <var>v</var>.</li> </ul> <p>Find the maximum possible number of edges that can be added.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq M \leq 10^5</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li>The graph has no self-loops or multiple edges.</li> <li>The graph is connected.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>:</var> <var>A_M</var> <var>B_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the maximum possible number of edges that can be added.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 5 1 2 2 3 3 4 4 5 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>If we add edges as shown below, four edges can be added, and no more.</p> <p><img alt="" src="https://img.atcoder.jp/code-festival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 1 2 2 3 3 1 5 4 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>Five edges can be added, for example, as follows:</p> <ul> <li>Add an edge connecting Vertex <var>5</var> and Vertex <var>3</var>.</li> <li>Add an edge connecting Vertex <var>5</var> and Vertex <var>2</var>.</li> <li>Add an edge connecting Vertex <var>4</var> and Vertex <var>1</var>.</li> <li>Add an edge connecting Vertex <var>4</var> and Vertex <var>2</var>.</li> <li>Add an edge connecting Vertex <var>4</var> and Vertex <var>3</var>.</li> </ul></section> </div> </span>
p01544
<h1>最長増加列問題</h1> <p> 時は過ぎお倪郎君は高校生になりたした。 倧孊生だったお兄さんの圱響も受け、コンピュヌタヌサむ゚ンスに興味を持ち始めたした。 倪郎君はコンピュヌタヌサむ゚ンスの教科曞を読み進め、「最長増加郚分列問題」ずいう有名問題があるこずを知りたした。倪郎君はこの問題のこずを理解したしたが、自分でも類䌌問題が䜜れないものかず気になりたした。 そこで倪郎君は詊行錯誀の結果に次のような問題を䜜りたした。 </p> <ul> <li><var>n</var>個の敎数で構成される数列Aがある </li><li><var>m-1</var>個の区切りを入れお、数列Aを<var>m</var>個の数列に分解する。なお、分解埌のそれぞれの数列は1぀以䞊の数を必ず含たなければならない。 </li><li>この<var>m</var>個それぞれの数列内の敎数をすべお足し合わせた結果出来䞊がる<var>m</var>個の数を、元の数列の順に配眮するず厳密な増加列になっおいる(぀たり、出来䞊がる数列は<var>B<sub>i</sub> &lt; B<sub>i+1</sub></var>をみたす)ようにしたい。 </li><li>目暙は最終的にできる数列<var>B</var>の長さ<var>m</var>を最倧化するこずである。 </li></ul> <p> 䟋えば、数列<var>A</var>が{5,-4,10,-3,8}の堎合を考えおみる。<br> 区切りの䜍眮を衚す数列<var>C</var>を甚意し、<var>C={2,4}</var>ずする。<br> このずき、数列<var>A</var>は(5,-4),(10,-3),(8)の郚分に分かれ、これらの内郚を足し合わせるずそれぞれ1,7,8ずなり、出来䞊がる数列<var>B</var>は{1,7,8}ずなる。 </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_probG" height="389" width="555"> <p> 倪郎君はこの問題に぀いお&quot;最長増加列問題&quot;ず名付け、これを解くアルゎリズムも考えたした。<br> そしお瀟䌚人になったあなたにチェックをしおほしいず連絡をしたした。 あなたの仕事は、成長した倪郎君の䜜った問題を解くプログラムを䜜るこずです。<br> チェックするのが仕事なので、<var>m-1</var>個の区切りの䜍眮も出力したす。 なお、最適な<var>m</var>に察しおこのような区切り方が耇数考えられる堎合もありたすが、この<var>m</var>が正しく出力されおいれば、考えられるもののうち䞀぀を出力すればよいです。 </p> <h2>Input</h2> <p> 改行区切りで<var>n+1</var>個の敎数が䞎えられる。 </p> <blockquote> <var>n</var> <br><var>A<sub>1</sub></var><br><var>A<sub>2</sub></var><br>...<br><var>A<sub>n</sub></var><br></blockquote> <ul> <li><var>n</var>は䞎えられる数列<var>A</var>の長さを衚す </li><li><var>A<sub>i</sub></var>は数列<var>A</var>のi番目の芁玠を衚す。 </li></ul> <h2>Constraints</h2> <blockquote> <var>1&le;n&le;4000</var><br><var>|Ai|&le; 10<sup>8</sup></var> <br></blockquote> <ul> <li>敎数<var>k</var>に察しお<var>|k|</var>は<var>k</var>の絶察倀を衚す </li></ul> <h2>Output</h2> <blockquote> <var>m</var><br><var>C<sub>1</sub></var> <var>C<sub>2</sub></var> .. <var>C<sub>m-1</sub></var><br></blockquote> <ul> <li>1行目は䞀぀の敎数<var>m</var>を出力する。 <var>m</var>は最終的にできる数列<var>B</var>の長さを衚す。 2行目は<var>m-1</var>個の敎数<var>C<sub>i</sub></var>を空癜区切りで出力する。 <var>C<sub>i</sub></var>は、数列<var>A</var>を<var>m</var>個の郚分に適切に区切った時の<var>i</var>番目の区切り堎所を衚す。 区切り堎所の定矩は図を参照せよ。なお、<var>1&le;C<sub>i</sub>&lt;n</var> を満たす。 2行目の<var>m-1</var>個の敎数列Cは昇順に䞊んでいなければならないしたがっお、<var>i &lt; j</var> ならば <var>C<sub>i</sub> &lt; C<sub>j</sub> </var>が成立する。 </li></ul> <ul> <li><var>m=1</var>の堎合2行目は空行になる。 </li><li>数列<var>C</var>に埓っお数列<var>A</var>から数列<var>B</var>を生成したずき、数列<var>B</var>が増加列になっおいないずき(すなわち<var>B<sub>i</sub>&ge;B<sub>i+1</sub></var>ずなる<var>i(1&le;i&lt;m)</var>が存圚するずき)、WrongAnswerずなる </li></ul> <H2>Sample Input 1</H2> <pre>3 1 2 4 </pre> <H2>Output for the Sample Input 1</H2> <pre>3 1 2 </pre> <p> もずもず増加列なので、すべおの堎所に区切りを入れればよい </p> <H2>Sample Input 2</H2> <pre>3 2 2 2 </pre> <H2>Output for the Sample Input 2</H2> <pre>2 1 </pre> <p> 2 2 2は増加列でないので、3぀に分割するこずはできない </p> <H2>Sample Input 3</H2> <pre>3 4 2 1 </pre> <H2>Output for the Sample Input 3</H2> <pre>1 (空行) </pre> <p> どう分割しおも増加列にはならないため、分割をしない </p>
p03129
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Determine if we can choose <var>K</var> different integers between <var>1</var> and <var>N</var> (inclusive) so that no two of them differ by <var>1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1\leq N,K\leq 100</var></li> <li><var>N</var> and <var>K</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If we can choose <var>K</var> integers as above, print <code>YES</code>; otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>We can choose <var>1</var> and <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>31 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>NO </pre></section> </div> </span>
p01114
<h3>Equilateral Triangular Fence</h3> <!-- end en only --> <!-- begin en only --> <p> Ms. Misumi owns an orchard along a straight road. Recently, wild boars have been witnessed strolling around the orchard aiming at pears, and she plans to construct a fence around many of the pear trees. </p> <p>The orchard contains <i>n</i> pear trees, whose locations are given by the two-dimensional Euclidean coordinates (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>),..., (<i>x<sub>n</sub></i>, <i>y<sub>n</sub></i>). For simplicity, we neglect the thickness of pear trees. Ms. Misumi's aesthetic tells that the fence has to form a equilateral triangle with one of its edges parallel to the road. Its opposite apex, of course, should be apart from the road. The coordinate system for the positions of the pear trees is chosen so that the road is expressed as <i>y</i> = 0, and the pear trees are located at <i>y</i> &#8805; 1. </p> <p> Due to budget constraints, Ms. Misumi decided to allow at most <i>k</i> trees to be left outside of the fence. You are to find the shortest possible perimeter of the fence on this condition. </p> <!-- end en only --> <!-- begin en only --> <p> The following figure shows the first dataset of the Sample Input. There are four pear trees at (&#8722;1,2), (0,1), (1,2), and (2,1). By excluding (&#8722;1,2) from the fence, we obtain the equilateral triangle with perimeter 6. </p> <!-- end en only --> <p style="text-align:center;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_F1"> </p> <h3>Input</h3> <!-- begin en only --> <p> The input consists of multiple datasets, each in the following format. </p> <!-- end en only --> <blockquote> <p> <i>n</i> <br> <i>k</i> <br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br> ... <br> <i>x<sub>n</sub></i> <i>y<sub>n</sub></i> <br> </p> </blockquote> <!-- begin en only --> <p> Each of the datasets consists of <i>n</i>+2 lines. <i>n</i> in the first line is the integer representing the number of pear trees; it satisfies 3 &#8804; <i>n</i> &#8804; 10&#8239;000. <i>k</i> in the second line is the integer representing the number of pear trees that may be left outside of the fence; it satisfies 1 &#8804; <i>k</i> &#8804; min(<i>n</i>&#8722;2, 5&#8239;000). The following <i>n</i> lines have two integers each representing the <i>x-</i> and <i>y-</i> coordinates, in this order, of the locations of pear trees; it satisfies &#8722;10&#8239;000 &#8804; <i>x<sub>i</sub></i> &#8804; 10&#8239;000, 1 &#8804; <i>y<sub>i</sub></i> &#8804; 10&#8239;000. No two pear trees are at the same location, i.e., (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>)=(<i>x<sub>j</sub></i>, <i>y<sub>j</sub></i>) only if <i>i</i>=<i>j</i>. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing a zero. The number of datasets is at most 100. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single number that represents the shortest possible perimeter of the fence. The output must not contain an error greater than 10<sup>&#8722;6</sup>. </p> <!-- end en only --> <h3>Sample Input</h3> <pre>4 1 0 1 1 2 -1 2 2 1 4 1 1 1 2 2 1 3 1 4 4 1 1 1 2 2 3 1 4 1 4 1 1 2 2 1 3 2 4 2 5 2 0 1 0 2 0 3 0 4 0 5 6 3 0 2 2 2 1 1 0 3 2 3 1 4 0 </pre> <h3>Output for the Sample Input</h3> <pre>6.000000000000 6.928203230276 6.000000000000 7.732050807569 6.928203230276 6.000000000000 </pre>
p02411
<H1>Grading</H1> <p> Write a program which reads a list of student test scores and evaluates the performance for each student. </p> <p> The test scores for a student include scores of the midterm examination <var>m</var> (out of 50), the final examination <var>f</var> (out of 50) and the makeup examination <var>r</var> (out of 100). If the student does not take the examination, the score is indicated by -1. </p> <p> The final performance of a student is evaluated by the following procedure: </p> <ul> <li>If the student does not take the midterm or final examination, the student's grade shall be F.</li> <li>If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.</li> <li>If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.</li> <li>If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.</li> <li>If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.</li> <li>If the total score of the midterm and final examination is less than 30, the student's grade shall be F.</li> </ul> <H2>Input</H2> <p> The input consists of multiple datasets. For each dataset, three integers <var>m</var>, <var>f</var> and <var>r</var> are given in a line. </p> <p> The input ends with three -1 for <var>m</var>, <var>f</var> and <var>r</var> respectively. Your program should not process for the terminal symbols. </p> <p> The number of datasets (the number of students) does not exceed 50. </p> <H2>Output</H2> <p> For each dataset, print the grade (<span>A</span>, <span>B</span>, <span>C</span>, <span>D</span> or <span>F</span>) in a line. </p> <H2>Sample Input</H2> <pre> 40 42 -1 20 30 -1 0 2 -1 -1 -1 -1 </pre> <H2>Sample Output</H2> <pre> A C F </pre>
p00586
<H1>A + B Problem</H1> <p> Compute A + B. </p> <H2>Input</H2> <p> The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF. </p> <H2>Output</H2> <p> For each pair of input integers A and B, you must output the sum of A and B in one line. </p> <H2>Constraints</H2> <ul> <li> -1000 &le; A, B &le; 1000</li> </ul> <H2>Sample Input</H2> <pre> 1 2 10 5 100 20 </pre> <H2>Output for the Sample Input</H2> <pre> 3 15 120 </pre> <H2>Sample Program</H2> <table> <tr> <td> <pre> #include&lt;stdio.h&gt; int main(){ int a, b; while( scanf("%d %d", &a, &b) != EOF ){ printf("%d\n", a + b); } return 0; } </pre> </td> <td width=100></td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ab" > </td> </tr> </table>
p02041
<h1>E: LISum</h1> <h2>問題</h2> <p> 長さ $N$ の数列 $A$ が䞎えられる。 数列 $A$ の最長増加郚分列のひず぀を $B$ ずするずき、$\sum B_i$ の最倧倀を求めよ。 </p> <p> 数列 $A$ の最長増加郚分列ずは、すべおの $i < j$ で $A_i < A_j$ を満たす郚分列のうち、最長なものを瀺す。 </p> <h2>制玄</h2> <ul> <li>入力倀は党お敎数である。</li> <li>$1 \leq N \leq 10^5$</li> <li>$0 \leq A_i \leq 10^5$</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <p> $N$<br> $A_1 \dots A_N$<br> </p> <h2>出力</h2> <p>数列 $A$ の最長増加郚分列のひず぀を $B$ ずするずき、$\sum B_i$ の最倧倀を出力せよ。たた、末尟に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 4 6 4 7 8 </pre> <h3>サンプル出力 1</h3> <pre> 21 </pre> <p>最長増加郚分列は $ (6, 7, 8)$ ず $(4, 7, 8)$ である。よっお最倧倀は $21$ である。</p> <h3>サンプル入力 2</h3> <pre> 3 1000 2 3 </pre> <h3>サンプル出力 2</h3> <pre> 5 </pre> <p>最長増加郚分列は $(2,3)$ のみである。</p> <h3>サンプル入力 3</h3> <pre> 7 17 17 13 4 20 12 15 </pre> <h3>サンプル出力 3</h3> <pre> 31 </pre> <h3>サンプル入力 4</h3> <pre> 7 19 16 14 9 4 20 2 </pre> <h3>サンプル出力 4</h3> <pre> 39 </pre>
p03200
<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> Reversi pieces arranged in a row. (A <em>Reversi piece</em> is a disc with a black side and a white side.) The state of each piece is represented by a string <var>S</var> of length <var>N</var>. If <var>S_i=</var><code>B</code>, the <var>i</var>-th piece from the left is showing black; If <var>S_i=</var><code>W</code>, the <var>i</var>-th piece from the left is showing white.</p> <p>Consider performing the following operation:</p> <ul> <li>Choose <var>i</var> (<var>1 \leq i &lt; N</var>) such that the <var>i</var>-th piece from the left is showing black and the <var>(i+1)</var>-th piece from the left is showing white, then flip both of those pieces. That is, the <var>i</var>-th piece from the left is now showing white and the <var>(i+1)</var>-th piece from the left is now showing black.</li> </ul> <p>Find the maximum possible number of times this operation can be performed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 2\times 10^5</var></li> <li><var>S_i=</var><code>B</code> or <code>W</code></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible number of times the operation can be performed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>BBW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The operation can be performed twice, as follows:</p> <ul> <li>Flip the second and third pieces from the left.</li> <li>Flip the first and second pieces from the left.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>BWBWBW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre></section> </div> </span>
p01397
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1><font color="#000">問題 J </font> Mod 3 Knights Out</h1> <h2>問題文</h2> <p> ある日の倕方コンテストの問題を解き終えた二人は今日の問題に぀いお話し合っおいた<br> A「くそヌあのラむツアりトの問題mod <var>2</var> じゃなくお mod <var>3</var> ずか mod <var>7</var> ずかだったら解法分かったのにヌ」<br> B「じゃあmod <var>3</var> で別の方法で解く問題を䜜ればいいんですね分かりたした」<br> こうしお次のような問題が誕生した</p> <p></p> <p><var>H × W</var> のチェス盀があるチェス盀の各マスには <var>0</var> から <var>2</var> の敎数が曞かれおいるこのチェス盀にナむトを眮いおいくただし各マスには倚くおも <var>1</var> 䜓のナむトしか眮けない各マスに぀いお<var>(マスの数倀+そこを攻撃するマスにいるナむトの数)=0 mod 3</var>が成り立぀ようなナむトの配眮を<b>良い</b>配眮ず呌ぶ攻撃するマスずはそのマスから瞊方向に <var>±2</var> マスか぀暪方向に <var>±1</var> マスもしくは瞊方向に <var>±1</var> マスか぀暪方向に <var>±2</var> マスずれたマスのこずである</p> <p>良いナむトの配眮の数を求めよ答えは倧きくなる可胜性があるので <var>1,000,000,007</var> で割った䜙りを答えよ</p> <h2>入力圢匏</h2> <p> 最初の行に <var>H</var> ず <var>W</var> がスペヌス区切りで䞎えられる </p> <p> 次の <var>H</var> 行には、チェス盀のマス目に曞かれおいる数倀ずしお <var>W</var> 個の <var>0</var><var>1</var><var>2</var> のいずれかの敎数がスペヌス区切りで䞎えられる </p> <h2>出力圢匏</h2> <p> 良いナむトの配眮の数を <var>1,000,000,007</var> で割った䜙りを出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; H &le; 50</var></li> <li><var>1 &le; W &le; 16</var></li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 5 5 0 2 0 2 0 2 0 0 0 2 0 0 0 0 0 2 0 0 0 2 0 2 0 2 0 </pre> <h3>出力䟋 1</h3> <pre> 5 </pre> <h3>入力䟋 2</h3> <pre> 3 3 2 2 2 2 0 2 2 2 2 </pre> <h3>出力䟋 2</h3> <pre> 8 </pre> <h3>入力䟋 3</h3> <pre> 7 7 2 2 2 2 2 2 2 2 1 1 2 1 1 2 2 0 1 0 1 0 2 2 2 0 2 0 2 2 2 0 1 0 1 0 2 2 1 1 2 1 1 2 2 2 2 2 2 2 2 </pre> <h3>出力䟋 3</h3> <pre> 96 </pre> <h3>入力䟋 4</h3> <pre> 7 3 2 2 2 1 0 1 0 1 0 1 1 1 0 1 0 1 0 1 2 2 2 </pre> <h3>出力䟋 4</h3> <pre> 8 </pre> <h3>入力䟋 5</h3> <pre> 6 6 0 2 0 1 0 2 2 0 1 2 2 2 0 2 2 0 0 0 2 0 2 0 2 0 0 2 2 1 0 2 0 0 0 2 0 2 </pre> <h3>出力䟋 5</h3> <pre> 1 </pre> <h3>入力䟋 6</h3> <pre> 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </pre> <h3>出力䟋 6</h3> <pre> 1 </pre> <h2>謝蟞</h2> この問題は Tester ず Writer が<a href="http://icpc2010.honiden.nii.ac.jp/regional-contest/problem">アゞア地区予遞の問題</a>に関しお話し合ったのをきっかけずしお䜜られた。
p03650
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a directed graph with <var>N</var> vertices and <var>N</var> edges. The vertices are numbered <var>1, 2, ..., N</var>.</p> <p>The graph has the following <var>N</var> edges: <var>(p_1, 1), (p_2, 2), ..., (p_N, N)</var>, and the graph is weakly connected. Here, an edge from Vertex <var>u</var> to Vertex <var>v</var> is denoted by <var>(u, v)</var>, and a weakly connected graph is a graph which would be connected if each edge was bidirectional.</p> <p>We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, <var>a_i</var> is the value assigned to Vertex <var>i</var>.</p> <ul> <li>Each <var>a_i</var> is a non-negative integer.</li> <li>For each edge <var>(i, j)</var>, <var>a_i \neq a_j</var> holds.</li> <li>For each <var>i</var> and each integer <var>x(0 ≀ x &lt; a_i)</var>, there exists a vertex <var>j</var> such that the edge <var>(i, j)</var> exists and <var>x = a_j</var> holds.</li> </ul> <p>Determine whether there exists such an assignment.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 200</var> <var>000</var></li> <li><var>1 ≀ p_i ≀ N</var></li> <li><var>p_i \neq i</var></li> <li>The graph is weakly connected.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>p_1</var> <var>p_2</var> ... <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the assignment is possible, print <code>POSSIBLE</code>; otherwise, print <code>IMPOSSIBLE</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 3 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>POSSIBLE </pre> <p>The assignment is possible: {<var>a_i</var>} = {<var>0, 1, 0, 1</var>} or {<var>a_i</var>} <var>=</var> {<var>1, 0, 1, 0</var>}.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>IMPOSSIBLE </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 2 3 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>POSSIBLE </pre> <p>The assignment is possible: {<var>a_i</var>} <var>=</var> {<var>2, 0, 1, 0</var>}.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 4 5 6 5 6 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>IMPOSSIBLE </pre></section> </div> </span>
p02942
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid with <var>N</var> rows and <var>M</var> columns of squares. Each integer from <var>1</var> to <var>NM</var> is written in this grid once. The number written in the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is <var>A_{ij}</var>.</p> <p>You need to rearrange these numbers as follows:</p> <ol> <li>First, for each of the <var>N</var> rows, rearrange the numbers written in it as you like.</li> <li>Second, for each of the <var>M</var> columns, rearrange the numbers written in it as you like.</li> <li>Finally, for each of the <var>N</var> rows, rearrange the numbers written in it as you like.</li> </ol> <p>After rearranging the numbers, you want the number written in the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left to be <var>M\times (i-1)+j</var>. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,M \leq 100</var></li> <li><var>1 \leq A_{ij} \leq NM</var></li> <li><var>A_{ij}</var> are distinct.</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_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1M}</var> <var>:</var> <var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NM}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print one way to rearrange the numbers in the following format:</p> <pre><var>B_{11}</var> <var>B_{12}</var> <var>...</var> <var>B_{1M}</var> <var>:</var> <var>B_{N1}</var> <var>B_{N2}</var> <var>...</var> <var>B_{NM}</var> <var>C_{11}</var> <var>C_{12}</var> <var>...</var> <var>C_{1M}</var> <var>:</var> <var>C_{N1}</var> <var>C_{N2}</var> <var>...</var> <var>C_{NM}</var> </pre> <p>Here <var>B_{ij}</var> is the number written in the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left after Step <var>1</var>, and <var>C_{ij}</var> is the number written in that square after Step <var>2</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 6 4 3 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 6 4 3 5 1 2 1 4 3 5 6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 4 1 4 7 10 2 5 8 11 3 6 9 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 4 7 10 5 8 11 2 9 12 3 6 1 4 3 2 5 8 7 6 9 12 11 10 </pre></section> </div> </span>
p01378
<div> <h1 class="title">問題 C : [[iwi]]</h1> <p>そうだ僕のハンドルネヌムは (iwi) だ 僕は確かに昔にプログラミングコンテストに参加しおいた そしお倚くの仲間ず楜しい時間を過ごした</p> <p>確か仲間たちは党員矎少女だったような気がする プログラミングコンテストの䞖界は僕のハヌレムだったような気がする G○○gle は僕のハヌレムを奪ったのだそうに違いない 昔の仲間の手がかりを぀かむためにもやはりプログラミングコンテストに出なければならない</p> <p>G○○gle Code Jam に参加登録するこずにしよう 今床の ID には䞞括匧以倖の括匧も怜蚎に入れおみよう</p> <div> <h1>問題</h1> <p>'i', 'w', '(', ')', '{', '}', '[', ']' からなる文字列が䞎えられた時 その郚分列をずっお線察称な文字列を䜜りたい 最倧で䜕文字の文字列を䜜るこずができるかを蚈算するプログラムを䜜成せよ</p> <p>䞎えられる文字列は &quot;iwi&quot; ずいう文字列を䞀床含みそれ以倖の郚分には 'i' ず 'w' を含たない より圢匏的には䞎えられる文字列は <span style="font-size:110%;font-family:times new roman;"><i>s</i></span> &quot;iwi&quot; <span style="font-size:110%;font-family:times new roman;"><i>t</i></span> <span style="font-size:110%;font-family:times new roman;"><i>s</i></span> ず &quot;iwi&quot; ず <span style="font-size:110%;font-family:times new roman;"><i>t</i></span> を連結したものずいう圢で衚すこずができ <span style="font-size:110%;font-family:times new roman;"><i>s</i></span> ず <span style="font-size:110%;font-family:times new roman;"><i>t</i></span> は '(', ')', '{', '}', '[', ']' からなる文字列である <span style="font-size:110%;font-family:times new roman;"><i>s</i></span> や <span style="font-size:110%;font-family:times new roman;"><i>t</i></span> が 0 文字である可胜性もある</p> <p>䜜る文字列は䞎えられる文字列の郚分列をずっお䜜る 郚分列ずは元の文字列からいく぀かの文字を取り出しそれらを 元の文字列に含たれる順番で繋げたものである 取り出す文字たちは必ずしも元の文字列で連続しおいなくおも良い</p> <p>たた䜜る文字列も䞎えられる文字列ず同様に&quot;iwi&quot; ずいう文字列を䞀床含み それ以倖の郚分には 'i' ず 'w' は含たないようにしたい</p> <p>ここで甚いる巊右に線察称の定矩は以䞋ずする</p> <ol class="arabic simple"> <li>以䞋の文字列は巊右に線察称</li> </ol> <blockquote> <ul class="simple"> <li>空文字列</li> <li>&quot;i&quot;</li> <li>&quot;w&quot;</li> </ul> </blockquote> <ol class="arabic simple" start="2"> <li>文字列 <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> が巊右に線察称のずき以䞋の文字列も巊右に線察称</li> </ol> <blockquote> <ul class="simple"> <li>&quot;i&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;i&quot;</li> <li>&quot;w&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;w&quot;</li> <li>&quot;(&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;)&quot;</li> <li>&quot;)&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;(&quot;</li> <li>&quot;{&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;}&quot;</li> <li>&quot;}&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;{&quot;</li> <li>&quot;[&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;]&quot;</li> <li>&quot;]&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;[&quot;</li> </ul> </blockquote> <ol class="arabic simple" start="3"> <li>以䞊のもののみが巊右に線察称</li> </ol> </div> <div> <h1>入力</h1> <p>入力は 'i', 'w', '(', ')', '{', '}', '[', ']' からなり䞊蚘の条件を満たす文字列である</p> </div> <div> <h1>出力</h1> <p>䞊蚘の条件を満たし䜜るこずのできる文字列の長さの最倧倀を出力せよ</p> </div> <div> <h1>制玄</h1> <ul class="simple"> <li>入力の文字列の長さは 15 以䞋である</li> </ul> </div> <div> <h1>入出力䟋</h1> <div> <h2>入出力䟋 1</h2> <p>入力䟋 1:</p> <pre class="literal-block"> [[[iwi[[[ </pre> <p>入力䟋 1 に察する出力䟋:</p> <pre class="literal-block"> 3 </pre> <p>&quot;iwi&quot; ずいう文字列しか䜜るこずができない</p> </div> <div> <h2>入出力䟋 2</h2> <p>入力䟋 2:</p> <pre class="literal-block"> [{)iwi(]} </pre> <p>入力䟋 2 に察する出力䟋:</p> <pre class="literal-block"> 7 </pre> <p>&quot;[)iwi(]&quot; や &quot;{)iwi(}&quot; など 7 文字の文字列を䜜るこずができる</p> </div> </div> </div>
p03345
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi, Nakahashi and Hikuhashi have integers <var>A</var>, <var>B</var> and <var>C</var>, respectively. After repeating the following operation <var>K</var> times, find the integer Takahashi will get minus the integer Nakahashi will get:</p> <ul> <li>Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.</li> </ul> <p>However, if the absolute value of the answer exceeds <var>10^{18}</var>, print <code>Unfair</code> instead.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A,B,C \leq 10^9</var></li> <li><var>0 \leq K \leq 10^{18}</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation <var>K</var> times. If the absolute value of the answer exceeds <var>10^{18}</var>, print <code>Unfair</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>After one operation, Takahashi, Nakahashi and Hikuhashi have <var>5</var>, <var>4</var> and <var>3</var>, respectively. We should print <var>5-4=1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000 1000000000 1000000000 1000000000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01682
<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>Problem Statement</h3> <p>Dr. Suposupo developed a programming language called Shipura. Shipura supports only one binary operator ${\tt >>}$ and only one unary function ${\tt S<\ >}$. </p> <p>$x {\tt >>} y$ is evaluated to $\lfloor x / 2^y \rfloor$ (that is, the greatest integer not exceeding $x / 2^y$), and ${\tt S<} x {\tt >}$ is evaluated to $x^2 \bmod 1{,}000{,}000{,}007$ (that is, the remainder when $x^2$ is divided by $1{,}000{,}000{,}007$). </p> <p>The operator ${\tt >>}$ is left-associative. For example, the expression $x {\tt >>} y {\tt >>} z$ is interpreted as $(x {\tt >>} y) {\tt >>} z$, not as $x {\tt >>} (y {\tt >>} z)$. Note that these parentheses do not appear in actual Shipura expressions. </p> <p>The syntax of Shipura is given (in BNF; Backus-Naur Form) as follows: </p><pre>expr ::= term | expr sp &quot;&gt;&gt;&quot; sp term term ::= number | &quot;S&quot; sp &quot;&lt;&quot; sp expr sp &quot;&gt;&quot; sp ::= &quot;&quot; | sp &quot; &quot; number ::= digit | number digit digit ::= &quot;0&quot; | &quot;1&quot; | &quot;2&quot; | &quot;3&quot; | &quot;4&quot; | &quot;5&quot; | &quot;6&quot; | &quot;7&quot; | &quot;8&quot; | &quot;9&quot;</pre> <p>The start symbol of this syntax is $\tt expr$ that represents an expression in Shipura. In addition, $\tt number$ is an integer between $0$ and $1{,}000{,}000{,}000$ inclusive, written without extra leading zeros. </p> <p>Write a program to evaluate Shipura expressions. </p> <h3>Input</h3> <p>The input is a sequence of datasets. Each dataset is represented by a line which contains a valid expression in Shipura. </p> <p>A line containing a single ${\tt \#}$ indicates the end of the input. You can assume the number of datasets is at most $100$ and the total size of the input file does not exceed $2{,}000{,}000$ bytes. </p> <h3>Output</h3> <p>For each dataset, output a line containing the evaluated value of the expression. </p> <h3>Sample Input</h3> <pre>S&lt; S&lt; 12 &gt;&gt; 2 &gt; &gt; 123 &gt;&gt; 1 &gt;&gt; 1 1000000000 &gt;&gt;129 S&lt;S&lt;S&lt;S&lt;S&lt;2&gt;&gt;&gt;&gt;&gt; S &lt;S&lt; S&lt;2013 &gt;&gt;&gt; 11 &gt;&gt;&gt; 10 &gt; #</pre> <h3>Output for the Sample Input</h3> <pre>81 30 0 294967268 14592400</pre>
p00990
<h1>Problem A : ID</h1> <p> A倧孊ではIDの入力ミスが倚発しおいた。<br> そこで、A倧孊は入力ミス防止のため新しいIDを発行するこずにした。<br> 新しいIDには入力ミス防止のためにIDが正しいかどうかチェックする方法がある。<br> </p> <p> <br> ・党おの桁の数字の総和を求める。<br> ・ただし、右端の桁を番目ずしお、偶数番目の桁の数字を倍にする。<br> ・倍するこずによっお数字が以䞊になった時、の䜍の数字ずの䜍の数字を加算した数字をその桁の数字ずする。<br> ・総和がで割り切れれば正しいID、そうでなければ間違いずする。<br> <br> </p> <p> 䟋ずしお、53579ずいうIDをチェックする。<br> 党おの桁の数字の総和を求めるので、<br> 5 + 3 + 5 + 7 + 9<br> </p> <p> ただし、偶数番目の桁の数字を倍にするので、<br> 5 + <u>6</u> + 5 + <u>14</u> + 9<br> </p> <p> 倍するこずによっお数字が以䞊になった時、の䜍の数字ずの䜍の数字を加算した数字をその桁の数字ずするので、<br> 5 + 6 + 5 + <u>(1 + 4)</u> + 9<br> </p> <p> 以䞊より、総和は30ずなる。30は10で割り切れるので、53579は正しいIDである。<br> </p> <p> B君はA倧孊の倧孊生であり、新しいIDを発行しおもらったが、IDの䞀郚の桁を忘れおしたった。<br> しかし、忘れおしたった郚分にどんな数字が入るか、いく぀か候補を絞るこずに成功した。<br> あなたの仕事は、B君のIDの正しい組み合わせが䜕通りあるかを求めるこずである。<br> </p> <h2>Input</h2> <p> 入力は以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>n</i> <i>ID</i> <i>m</i> <i>a<sub>0</sub> a<sub>1</sub> ... a<sub>m-1</sub></i> </pre> <p> <i>n</i>は<i>ID</i>の桁の数である。<br> <i>ID</i>の各桁には0~9の数字たたは忘れた桁であるずいうこずを瀺す'*'ずいう文字が入る。<br> <i>m</i>は'*'に入る数字の候補の数である。<br> <i>a<sub>i</sub></i>は'*'に入る数字の候補である。<br> </p> <p> 入力は以䞋の制玄を満たす<br> 1 &le; <i>n</i> &le; 100,000<br> 1 &le; <i>m</i> &le; 10<br> 0 &le; <i>a<sub>i</sub></i> &le; 9<br> 1 &le; '*'の数 &le; 7<br> </p> <h2>Output</h2> <p> 答えの倀を行に出力せよ </p> <h2>Sample Input 1</h2> <pre> 5 5*57* 2 3 9 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 15 2***9*2*6*1199* 9 0 1 2 3 4 6 7 8 9 </pre> <h2>Sample Output 2</h2> <pre> 478297 </pre>
p01728
<p> ヘリリンは二次元平面䞊における長さ<var>2L</var>の線分の圢状をしおいる。<br> ヘリリンのたわりには、線分の圢状をしたいく぀かの障害物が存圚しおいる。 </p> <p>ヘリリンは障害物に接するず䜓力が削られおしたう。<br> 完璧䞻矩のヘリリンは無傷でゎヌルするこずにした。 </p> <p>ヘリリンは以䞋の行動ができる。 </p> <ul> <li> 平行移動 </li> <li> ヘリリンを衚す線分の䞭点を䞭心ずしお、反時蚈呚りにちょうど <var> 180 / r </var> 床だけ回転する </li></ul> <p>ただし、二次元平面は䞊方向に<var>y</var>軞をずる。 </p> <p>ヘリリンのたわりに、2 点 S, G がある。<br> 始めはヘリリンの䞭心は点 S にあっお、<var>x</var>軞に平行な状態になっおいる。 </p> <p>ヘリリンは、平行移動するのは埗意だが、回転するのは䞍埗意である。<br> あなたの仕事は、ヘリリンが䞭心を点 S から点 G たで移動させるたでに必芁な、最小の回転行動の回数を求めるこずである。<br> 移動させるこずができない堎合は、そのこずも怜出せよ。 </p> <p> ただし、以䞋のこずに泚意せよ。 </p> <ul><li> ヘリリンは移動しながら回転するこずはできない。 </li><li> ヘリリンが回転する途䞭で障害物にぶ぀かりうる堎合は、回転するこずはできない。 </li><li> 障害物が互いに亀差しおいるこずはあり埗る。 </li><li> 線分は十分小さい有限の倪さを持぀ものずしお扱う。最埌のサンプルを芋よ。 </ul> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>L</var> <var>r</var><br><var>s<sub>x</sub></var> <var>s<sub>y</sub></var><br><var>g<sub>x</sub></var> <var>g<sub>y</sub></var><br><var>n</var><br><var>x<sub>11</sub></var> <var>y<sub>11</sub></var> <var>x<sub>12</sub></var> <var>y<sub>12</sub></var><br>...<br><var>x<sub>n1</sub></var> <var>y<sub>n1</sub></var> <var>x<sub>n2</sub></var> <var>y<sub>n2</sub></var></pre> <p><var>L</var>はヘリリンの半分の長さを衚す。 <var>r</var>は回転角床を定めるものである。 <var>(s<sub>x</sub>, s<sub>y</sub>)</var>は点 S、<var>(g<sub>x</sub>, g<sub>y</sub>)</var>は点 G の座暙である。 <var>n</var>は障害物の数を衚す。 <var>(x<sub>i1</sub>, y<sub>i1</sub>)</var>ず<var>(x<sub>i2</sub>, y<sub>i2</sub>)</var>は<var>i</var>番目の障害物を衚す線分の端点である。 </p> <h3>Constraints</h3> <p>入力は以䞋の制玄を満たす。 </p> <ul><li> <var> 1 &le; n &le; 30 </var> </li><li> <var> 2&le; r &le; 11 </var> </li><li> <var> 1 &le; L &le; 10<sup>5</sup> </var> </li><li> 入力に含たれる座暙の各成分は絶察倀が<var>10<sup>5</sup></var>以䞋 </li><li> 入力に含たれる数倀はすべお敎数 </li><li> <var>i = 1, . . . , n</var>に぀いお<var> (x<sub>i1</sub>, y<sub>i1</sub>) &ne; (x<sub>i2</sub>, y<sub>i2</sub>) </var> </li><li> ヘリリンをスタヌト地点にx軞に氎平な状態で配眮したずき、障害物ずの線分ず線分ずの距離は<var> 10<sup>&minus;3</sup> </var>より倧きい </li><li> 障害物を衚す線分の端点を、䞡方向に<var> 10<sup>&minus;3</sup> </var>だけ延ばしおも瞮めおも解は倉わらない </li><li> <var>L</var>を <var> 10<sup>&minus;3</sup> </var>だけ増枛させおも解は倉わらない </li><li> 障害物の線分を<var>l<sub>i</sub></var>ず曞くこずにするず、<var>1 &le; i &le; j &le; n</var>であっお、<var>l<sub>i</sub></var>ず<var>l<sub>j</sub></var>の距離が<var>2L</var>以䞋であるような組<var>(i, j)</var>は高々100個 </li><li> ゎヌル地点は障害物に乗っおいるこずはない </li></ul> <h2>Output</h2> <p>スタヌト地点からゎヌル地点たで移動するために必芁な最小の回転行動の回数を1行に出力せよ。 移動させるこずができない堎合は、-1を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre>1 2 3 3 2 -1 4 1 0 1 5 0 1 4 1 0 4 6 4 5 0 5 5 </pre> <h2>Output for the Sample Input 1</h2> <pre>1 </pre> <ul><li> ヘリリンを90床回転させるこずで、隙間を抜けるこずができる。 </li></ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample1" height="600" width="600"><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_a" height="100" width="700"><br> <br> <h2>Sample Input 2</h2> <pre>1 2 3 3 2 -1 4 1 0 1 5 0 1 6 1 0 4 6 4 5 0 5 5 </pre> <h2>Output for the Sample Input 2</h2> <pre>-1 </pre> <ul><li> ヘリリンは完党に囲たれおいるので、ゎヌルたで移動するこずができない。 </li></ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample2" height="600" width="600"><br> <h2>Sample Input 3</h2> <pre>1 4 3 3 7 0 5 1 0 1 5 0 1 6 1 0 4 6 4 8 0 2 5 6 0 4 2 </pre> <h2>Output for the Sample Input 3</h2> <pre>3 </pre> <ul><li> 斜めの経路を通るためには、3回反時蚈呚りに回転しなければならない。 </li></ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample3" height="600" width="600"><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_b" height="100" width="700"><br> <br> <h2>Sample Input 4</h2> <pre>2 2 4 2 4 5 5 1 5 2 0 0 4 3 4 0 1 8 1 7 0 7 5 8 4 5 4 </pre> <h2>Output for the Sample Input 4</h2> <pre>-1 </pre> <ul><li> ヘリリンは障害物にぎったり接するこずができないので、隙間のずころで回転しおゎヌルたで移動するこずはできない。 </li></ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample4" height="370" width="567">
p03715
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a bar of chocolate with a height of <var>H</var> blocks and a width of <var>W</var> blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.</p> <p>Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize <var>S_{max}</var> - <var>S_{min}</var>, where <var>S_{max}</var> is the area (the number of blocks contained) of the largest piece, and <var>S_{min}</var> is the area of the smallest piece. Find the minimum possible value of <var>S_{max} - S_{min}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ H, W ≀ 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>H</var> <var>W</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible value of <var>S_{max} - S_{min}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> <p>In the division below, <var>S_{max} - S_{min} = 5 - 5 = 0</var>.</p> <div style="text-align: center;"> <img alt="2a9b2ef47b750c0b7ba3e865d4fb4203.png" src="https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>In the division below, <var>S_{max} - S_{min} = 8 - 6 = 2</var>.</p> <div style="text-align: center;"> <img alt="a42aae7aaaadc4640ac5cdf88684d913.png" src="https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre> <p>In the division below, <var>S_{max} - S_{min} = 10 - 6 = 4</var>.</p> <div style="text-align: center;"> <img alt="eb0ad0cb3185b7ae418e21c472ff7f26.png" src="https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png"/> </div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100000 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>100000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>50000 </pre></section> </div> </span>
p02807
<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> slimes standing on a number line. The <var>i</var>-th slime from the left is at position <var>x_i</var>.</p> <p>It is guaruanteed that <var>1 \leq x_1 &lt; x_2 &lt; \ldots &lt; x_N \leq 10^{9}</var>.</p> <p>Niwango will perform <var>N-1</var> operations. The <var>i</var>-th operation consists of the following procedures:</p> <ul> <li>Choose an integer <var>k</var> between <var>1</var> and <var>N-i</var> (inclusive) with equal probability.</li> <li>Move the <var>k</var>-th slime from the left, to the position of the neighboring slime to the right.</li> <li>Fuse the two slimes at the same position into one slime.</li> </ul> <p>Find the total distance traveled by the slimes multiplied by <var>(N-1)!</var> (we can show that this value is an integer), modulo <var>(10^{9}+7)</var>. If a slime is born by a fuse and that slime moves, we count it as just one slime.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>2 \leq N \leq 10^{5}</var></li> <li><var>1 \leq x_1 &lt; x_2 &lt; \ldots &lt; x_N \leq 10^{9}</var></li> <li><var>x_i</var> is an integer.</li> </ul> </section> </div> <div class="part"> <section> <h3>Subtasks</h3> <ul> <li><var>400</var> points will be awarded for passing the test cases satisfying <var>N \leq 2000</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>x_2</var> <var>\ldots</var> <var>x_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <ul> <li>With probability <var>\frac{1}{2}</var>, the leftmost slime is chosen in the first operation, in which case the total distance traveled is <var>2</var>.</li> <li>With probability <var>\frac{1}{2}</var>, the middle slime is chosen in the first operation, in which case the total distance traveled is <var>3</var>.</li> <li>The answer is the expected total distance traveled, <var>2.5</var>, multiplied by <var>2!</var>, which is <var>5</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>12 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>750927044 </pre> <ul> <li>Find the expected value multiplied by <var>(N-1)!</var>, modulo <var>(10^9+7)</var>.</li> </ul></section> </div> </span>
p02554
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>How many integer sequences <var>A_1,A_2,\ldots,A_N</var> of length <var>N</var> satisfy all of the following conditions?</p> <ul> <li><var>0 \leq A_i \leq 9</var></li> <li>There exists some <var>i</var> such that <var>A_i=0</var> holds.</li> <li>There exists some <var>i</var> such that <var>A_i=9</var> holds.</li> </ul> <p>The answer can be very large, so output it modulo <var>10^9 + 7</var>.</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 modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Two sequences <var>\{0,9\}</var> and <var>\{9,0\}</var> satisfy all conditions.</p> </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>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>869121 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2511445 </pre></section> </div> </span>
p00569
<h1>L番目のK番目の数 (LthKthNumber)</h1> <h2>問題文</h2> <p> 暪䞀列に䞊べられた <var>N</var> 枚のカヌドがある巊から <var>i</var> 枚目(<var>1 ≩ i ≩ N</var>)のカヌドには敎数 <var>a_i</var> が曞かれおいる</p> <p> JOI 君はこれらのカヌドを甚いお次のようなゲヌムを行う連続する <var>K</var> 枚以䞊のカヌドの列を遞び次の操䜜を行う</p> <ul> <li>遞んだカヌドを曞かれおいる敎数が小さい順に巊から䞊べる</li> <li>䞊べたカヌドのうち巊から <var>K</var> 番目のカヌドに曞かれた敎数を玙に曞き出す</li> <li>遞んだカヌドをすべお元の䜍眮に戻す</li> </ul> <p> この操䜜を連続する <var>K</var> 枚以䞊のカヌドの列すべおに察しお行うすなわち<var>1 ≩ l ≩ r ≩ N</var> か぀ <var>K ≩ r - l + 1</var> を満たすすべおの <var>(l,r)</var> に぀いお<var>a_l, a_{l+1}, ..., a_r</var> のうち <var>K</var> 番目に小さな敎数を曞き出す</p> <p> こうしお曞き出された敎数を巊から小さい順に䞊べる䞊べた敎数のうち巊から <var>L</var> 番目のものがこのゲヌムにおける JOI 君の埗点であるJOI 君の埗点を求めよ</p> <h2>制玄</h2> <ul> <li><var>1 \leq N \leq 200000</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>1 \leq a_i \leq N</var></li> <li><var>1 \leq L</var></li> <li>JOI 君が曞き出す敎数は <var>L</var> 個以䞊である</li> </ul> <h2>入力・出力</h2> <p> <b>入力</b><br> 入力は以䞋の圢匏で暙準入力から䞎えられる<br> <var>N</var> <var>K</var> <var>L</var><br> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var> </p> <p> <b>出力</b><br> JOI 君の埗点を <var>1</var> 行で出力せよ<br> <!-- <h2>小課題</h2> <p> <b>小課題 1 [6点]</b> </p> <ul> <li><var>N ≩ 100</var></li> </ul> <p> <b>小課題 2 [33点]</b> </p> <ul> <li><var>N ≩ 4000</var></li> </ul> <p> <b>小課題 3 [61点]</b> </p> <ul> <li>远加の制限はない</li> </ul> --> <h2>入出力䟋</h2> <b>入力䟋 1</b><br> <pre> 4 3 2 4 3 1 2 </pre> <b>出力䟋 1</b><br> <pre> 3 </pre> <p> <var>1 \leq l \leq r \leq N (= 4)</var> か぀ <var>K (= 3) \leq r - l + 1</var> を満たす <var>(l,r)</var> は<var>(1,3), (1,4), (2,4)</var> の <var>3</var> 通りある</p> <p> これらの <var>(l,r)</var> に察し<var>a_l, a_{l+1}, ..., a_r</var> で <var>3</var> 番目に小さな敎数はそれぞれ <var>4, 3, 3</var> である</p> <p> このうち <var>L (= 2)</var> 番目に小さい敎数は <var>3</var> なのでJOI 君の埗点は <var>3</var> である同じ敎数が耇数あるずきも重耇しお数えるこずに泚意せよ</p> <hr> <b>入力䟋 2</b><br> <pre> 5 3 3 1 5 2 2 4 </pre> <b>出力䟋 2</b><br> <pre> 4 </pre> <p> JOI 君が曞き出す敎数は</p> <ul> <li><var>(l,r) = (1,3)</var> に察し <var>5</var></li> <li><var>(l,r) = (1,4)</var> に察し <var>2</var></li> <li><var>(l,r) = (1,5)</var> に察し <var>2</var></li> <li><var>(l,r) = (2,4)</var> に察し <var>5</var></li> <li><var>(l,r) = (2,5)</var> に察し <var>4</var></li> <li><var>(l,r) = (3,5)</var> に察し <var>4</var></li> </ul> <p> であるこのうち <var>L (= 3)</var> 番目に小さい敎数は <var>4</var> である </p> <hr> <b>入力䟋 3</b><br> <pre> 6 2 9 1 5 3 4 2 4 </pre> <b>出力䟋 3</b><br> <pre> 4 </pre> <hr> <b>入力䟋 4</b><br> <pre> 6 2 8 1 5 3 4 2 4 </pre> <b>出力䟋 4</b><br> <pre> 3 </pre>
p00093
<H1>うるう幎</H1> <p> 西暊 <var>a</var> 幎から <var>b</var> 幎たでの間にあるすべおのうるう幎を出力するプログラムを䜜成しおください。 </p> <p> うるう幎の条件は、次のずおりずしたす。ただし、0 &lt; <var>a</var> &le; <var>b</var> &lt; 3,000 ずしたす。䞎えられた期間にうるう幎がない堎合には "NA"ず出力しおください。 </p> <ul> <li> 西暊幎が 4 で割り切れる幎であるこず。</li> <li> ただし、100 で割り切れる幎はうるう幎ずしない。</li> <li> しかし、400 で割り切れる幎はうるう幎である。</li> </ul> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットの圢匏は以䞋のずおりです </p> <pre> <var>a</var> <var>b</var> </pre> <p> <var>a</var>, <var>b</var> がずもに 0 のずき入力の終了ずしたす。デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> <!--各デヌタセットごずに、4 桁の西暊たたは NA(半角英倧文字)を出力しおください。--> デヌタセットごずに、西暊たたは NA を出力しおください。 </p> <p> デヌタセットの間に぀の空行を入れおください。 </p> <H2>Sample Input</H2> <pre> 2001 2010 2005 2005 2001 2010 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2004 2008 NA 2004 2008 </pre>
p02104
<h1>Problem G: Chairs</h1> <h2>Problem</h2> <p> 1から<var>N</var>の番号が割り圓おられた<var>N</var>脚の怅子に、1から<var>N</var>のIDが割り圓おられた<var>N</var>人の人が座ろうずしおいる。IDが<var>i</var>の人は怅子<var>p<sub>i</sub></var>に座りたいず思っおいる。 </p> <p> <var>N</var>人の人はIDが小さい順に1列に䞊び、列の先頭の人が以䞋の行動をずる。 </p> <ol> <li>怅子<var>p<sub>i</sub></var>に誰も座っおいなければ、その怅子に座る。</li> <li>そうでなければ、<var>p<sub>i</sub></var>に1を加算し、列の最埌尟に䞊び盎す。ただし、<var>p<sub>i</sub></var>が<var>N</var>を超えた堎合は<var>p<sub>i</sub></var>を1にする。</li> </ol> <p> 党おの人が怅子に座るたでこの行動が繰り返されたずき、最終的に各怅子に座っおいる人のIDを出力せよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> ... <var>p<sub>N</sub></var> </pre> <p> 1行目に敎数<var>N</var>が䞎えられる。<br> 2行目に<var>N</var>個の敎数<var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>, ..., <var>p<sub>N</sub></var>が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var> &le; 10<sup>5</sup></li> <li>1 &le; <var>p<sub>i</sub></var> &le; <var>N</var></li> </ul> <h2>Output</h2> <p> <var>N</var>行に最終的な状態を出力する。<br> <var>i</var>行目に怅子<var>i</var>に座っおいる人のIDを出力する。 </p> <h2>Sample Input 1</h2> <pre> 5 1 2 3 4 5 </pre> <h2>Sample Output 1</h2> <pre> 1 2 3 4 5 </pre> <h2>Sample Input 2</h2> <pre> 5 3 3 4 4 5 </pre> <h2>Sample Output 2</h2> <pre> 4 2 1 3 5 </pre>
p00139
<H1>ヘビ</H1> <p> ある䞖界には文字だけでできた䞍思議なヘビが䜏んでいたす。このヘビには珟圚A皮ずB皮の2皮類が確認されおいたすが、それ以倖の皮類がいる可胜性もありたす。 </p> <p> A皮は">'"の埌に"="が1個以䞊䞊んだ埌、"#"が来お、さらに前ず同じ個数の"="が来た埌、"~"半角チルダで終わりたす。 </p> <p> B皮は">^"の埌に "Q="が1個以䞊䞊んだ埌、"~~"で終わりたす。 </p> <pre> A皮の䟋 >'====#====~ >'==#==~ </pre> <pre> B皮の䟋 >^Q=Q=Q=Q=~~ >^Q=Q=~~ </pre> <p> ヘビを文字列デヌタずしお受け取り、それがどんな皮類であるかを刀別しお、A皮の堎合は「A」、B皮の堎合は「B」、それ以倖の皮類の堎合は「NA」を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>S<sub>1</sub></var> <var>S<sub>2</sub></var> : <var>S<sub>n</sub></var> </pre> <p> 1 行目に刀別されるヘビの数 <var>n</var>1 &le; <var>n</var> &le; 10000、続く <var>n</var> 行に <var>i</var> 匹目のヘビを衚す文字列 <var>S<sub>i</sub></var> (200文字以䞋の、空癜を含たない文字列) がそれぞれ行に䞎えられたす。 </p> <H2>Output</H2> <p> <var>i</var> 行目に <var>i</var> 匹目のヘビの皮類 A、B たたは NA を出力しおください。 </p> <H2>Sample Input</H2> <pre> 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ </pre> <H2>Output for the Sample Input</H2> <pre> A B NA </pre>
p03938
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>You are given a permutation <var>p</var> of the set {<var>1, 2, ..., N</var>}. Please construct two sequences of positive integers <var>a_1</var>, <var>a_2</var>, ..., <var>a_N</var> and <var>b_1</var>, <var>b_2</var>, ..., <var>b_N</var> satisfying the following conditions:</p> <ul> <li><var>1 \leq a_i, b_i \leq 10^9</var> for all <var>i</var></li> <li><var>a_1 &lt; a_2 &lt; ... &lt; a_N</var></li> <li><var>b_1 &gt; b_2 &gt; ... &gt; b_N</var></li> <li><var>a_{p_1}+b_{p_1} &lt; a_{p_2}+b_{p_2} &lt; ... &lt; a_{p_N}+b_{p_N}</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 20,000</var></li> <li><var>p</var> is a permutation of the set {<var>1, 2, ..., N</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>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>The output consists of two lines. The first line contains <var>a_1</var>, <var>a_2</var>, ..., <var>a_N</var> seperated by a space. The second line contains <var>b_1</var>, <var>b_2</var>, ..., <var>b_N</var> seperated by a space. </p> <p>It can be shown that there always exists a solution for any input satisfying the constraints.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 4 5 4 </pre> <p><var>a_1 + b_1 = 6</var> and <var>a_2 + b_2 = 8</var>. So this output satisfies all conditions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 5 3 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 10 100 100 10 1 </pre></section> </div> </span>
p01905
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>A: トヌナメント</h1> <h2>問題</h2> <p> AOR むカちゃんずあなたは、トヌナメント圢匏の卓球倧䌚シングルスの郚に偵察に来た。 党おの詊合を録画したい AOR むカちゃんのために、あなたはこの倧䌚で行われる詊合数を求めおあげるこずにした。 </p> <p> この倧䌚には $N$ 人の遞手が参加しおおり、それぞれ $0, \dots , N - 1$ の背番号を持っおいる。 そのうち、 $M$ 人の遞手が棄暩し、詊合には出堎しなかった。 </p> <p> この倧䌚の詊合数は、以䞋のルヌルに基いお決定される。 </p> <ul> <li>シヌド遞手は存圚せず、任意の出堎者が優勝するために必芁な勝利回数は䞀定である。</li> <li>察戊盞手が䞍圚の堎合は詊合を行わず、出堎した遞手が勝利する。詊合数にはカりントされない。</li> <li>優勝者が決たった段階で倧䌚は終了する。</li> <li>䞀床詊合に負けた人が再び詊合をするこずはない。぀たり敗者埩掻戊や 3 䜍決定戊などは行わない。</li> <li>なお、卓球台が 1 台しか無いため異なる詊合が同時に行われるこずはなく、たた各詊合では必ず勝者が決たる (匕き分けずなるこずはない)。</li> </ul> <p> なお、トヌナメントの定矩は次のずおりである。 トヌナメントは高さ $L = \log_2 N$ の完党二分朚で衚され、葉にあたる各頂点には参加者の背番号が曞き蟌たれおいる。 根の深さを 0 ずするず、 $i$ 回戊 ($1 \le i \le L$) では、 深さ $L - i$ の各頂点の子に曞かれた番号の遞手同士が詊合を行い、その勝者の背番号をその頂点に曞き蟌む。 </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day1_RUPC2017_Tournament"> <h2>制玄</h2> <ul> <li>$2 \le N \le 2^8$</li> <li>$0 \le M \le N - 1$</li> <li>$0 \le a_i \le N - 1 \ (0 \le i \le M - 1)$</li> <li> $N$ は 2 の环乗である。</li> <li> $a_i \ (0 \le i \le M - 1)$ は盞異なる</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <p> $N \ M$<br> $a_1$<br> $\vdots$<br> $a_M$<br> </p> <ul> <li>1 行目には、参加者を衚す敎数 $N$ 、参加者のうち棄暩した者の人数を衚す敎数 $M$ が䞎えられる。</li> <li>続く $M$ 行には、棄暩しお出堎しなかった遞手の番号を衚す敎数 $a_i$ が䞎えられる。</li> </ul> <h2>出力</h2> <p> この倧䌚が終了するたでに行われる詊合数を 1 行で出力せよ。たた、末尟に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 2 0 </pre> <h3>サンプル出力 1</h3> <pre> 1 </pre> <p> 最初の詊合で優勝者が決たる。 </p> <h3>サンプル入力 2</h3> <pre> 4 2 2 3 </pre> <h3>サンプル出力 2</h3> <pre> 1 </pre>
p00617
<H1><font color="#000000">Problem C:</font> Simple GUI Application</H1> <p> Advanced Creative Mobile 瀟ACM瀟では、新しいポヌタブルコンピュヌタに搭茉するGUIアプリケヌションの開発を行うこずになった。 </p> <p> 䞋図に瀺すように、GUIは぀のメむンパネルを持ち、その䞊にいく぀かのパネルが配眮され、さらにそれらのパネルの䞊にもいく぀かのパネルが配眮されるような入れ子構造になっおいる。パネルはすべお蟺が座暙軞に平行・垂盎な長方圢たたは正方圢である。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_GUITag"> </center> <br> <p> アプリケヌションはパネルの入れ子構造をタグ構造で保持する仕様ずなっおいる。パネルを衚すタグ構造は、タグ倀ずそのパネルの䞊に配眮されおいるパネルのタグ構造のリストを持぀。タグ倀はそのパネルの巊䞊の座暙 (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) ず 右䞋の座暙 (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) を瀺す。 </p> <p>タグ構造の構文芏則を以䞋に瀺す。ここで、構文の蚘述に甚いる蚘号の意味を、以䞋の衚のように定める。"<span>&lt;</span>"、"<span>&gt;</span>", "<span>,</span>" 及び "<span>/</span>" は、字句芁玠である。 </p> <br> <center> <table border=1> <tr> <th>蚘号</th><th>意味</th> </tr> <tr> <td><span>::=</span></td><td>定矩する</td> </tr> <tr> <td><span>{}*<span></td><td> <span>{<span> ず <span>}</span> で囲たれた芁玠の 0 回以䞊の繰り返し</td> </tr> </table> </center> <br> <pre> タグ構造 ::= 開始タグ タグ倀 {タグ構造}* 終了タグ 開始タグ ::= &lt;タグ名&gt; 終了タグ ::= &lt;/タグ名&gt; タグ名 ::= 文字列 タグ倀 ::= 敎数,敎数,敎数,敎数 </pre> <p> タグ名はパネルの名前を瀺す文字以䞊からなる文字列である。 </p> <p> タグ倀は、カンマで区切られた぀の敎数であり、それぞれパネルの座暙を瀺す <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>2</sub> である。 </p> <p> 䟋えば、䞊図に瀺したGUIは以䞋のタグ構造で蚘述される(スペヌスの関係䞊行にたたがっおいるが、入力は行で䞎えられる) </p> <pre> &lt;main&gt;10,10,190,150&lt;menu&gt;20,20,70,140&lt;/menu&gt;&lt;primary&gt;80,20,180,140 &lt;text&gt;90,30,170,80&lt;/text&gt;&lt;button&gt;130,110,170,130&lt;/button&gt;&lt;/primary&gt;&lt;/main&gt; </pre> <p> このGUIでは、ナヌザがある点をタッチするず、その点においお最䞊郚にあるパネルが遞択される境界線を含む。 </p> <p> あなたの仕事は、メむンパネルのタグ構造ず、タッチされた点のリストを読み蟌み、以䞋の情報を出力するプログラムを䜜成するこずである。 </p> <ul> <li>遞択されたパネルの名前</li> <li>そのパネルの盎接䞊に配眮されおいるパネルの数以䞋"子の数"ず呌ぶ</li> </ul> <p> なお、入力されるタグ構造に぀いお以䞋のこずを仮定しおよい。 </p> <ul> <li>タグ構造に文法゚ラヌはない。</li> <li>パネルがそれを含むパネル以䞋"芪パネル"ず呌ぶからはみ出すこずはなく、境界にも觊れない。</li> <li>同じ芪パネルを持぀パネル同士は重ならず、觊れない。</li> <li>同じ名前のパネルはない。</li> </ul> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなる。各デヌタセットは以䞋の圢匏で䞎えられる </p> <pre> <i>n</i> タグ構造 <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> . . . <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> </pre> <p> <i>n</i> はタッチされた点の数を瀺す敎数である。タグ構造は空癜を含たない行の文字列である。<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> は <i>i</i> 番めにタッチされた点の <i>x</i> 座暙ず <i>y</i> 座暙を衚す座暙軞は䞊図に定めたものずする。 </p> <p> <i>n</i> &le; 100、タグ構造の文字列の長さ &le; 1000 ず仮定しおよい。たた、入力で䞎えられる <i>x</i> 座暙 <i>y</i> 座暙は 0 以䞊 10,000 以䞋ず仮定しおよい。 </p> <p> <i>n</i> が 0 のずき入力の終わりずする。 </p> <H2>Output</H2> <p> 各デヌタセットに察しお、遞択された順番にパネルの名前ず子の数を出力せよ。各名前ず子の数を぀の空癜で区切っお行に出力せよ。䜕も遞択されない堎合タッチされた点にパネルがない堎合は、"OUT OF MAIN PANEL 1"ず出力せよ。 </p> <H2>Sample Input</H2> <pre> 5 &lt;main&gt;10,10,190,150&lt;menu&gt;20,20,70,140&lt;/menu&gt;&lt;primary&gt;80,20,180,140&lt;/primary&gt;&lt;/main&gt; 10 10 15 15 40 60 2 3 130 80 0 </pre> <H2>Output for the Sample Input</H2> <pre> main 2 main 2 menu 0 OUT OF MAIN PANEL 1 primary 0 </pre>
p03892
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is drawing a segment on grid paper.</p> <p>From a certain square, a square that is <var>x</var> squares to the right and <var>y</var> squares above, is denoted as square <var>(x, y)</var>.</p> <p>When Takahashi draws a segment connecting the lower left corner of square <var>(A, B)</var> and the lower left corner of square <var>(C, D)</var>, find the number of the squares crossed by the segment.</p> <p>Here, the segment is said to <em>cross</em> a square if the segment has non-empty intersection with the region within the square, excluding the boundary.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A, B, C, D \leq 10^9</var></li> <li>At least one of <var>A \neq C</var> and <var>B \neq D</var> holds.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the squares crossed by the segment.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 1 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 10 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre></section> </div> </span>
p02780
<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> dice arranged in a line from left to right. The <var>i</var>-th die from the left shows <var>p_i</var> numbers from <var>1</var> to <var>p_i</var> with equal probability when thrown.</p> <p>We will choose <var>K</var> adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ K ≀ N ≀ 200000</var></li> <li><var>1 ≀ p_i ≀ 1000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>p_1</var> ... <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of the expected value of the sum of the numbers shown.</p> <p>Your output will be considered correct when its absolute or relative error from our answer is at most <var>10^{-6}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 1 2 2 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7.000000000000 </pre> <p>When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is <var>7</var>. This is the maximum value we can achieve.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 6 6 6 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3.500000000000 </pre> <p>Regardless of which die we choose, the expected value of the number shown is <var>3.5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 4 17 13 13 12 15 20 10 13 17 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>32.000000000000 </pre></section> </div> </span>
p00247
<H1>氷の迷路</H1> <p> 四角のマスを瞊暪にならべた長方圢の迷路がありたす。この迷路では東西南北の隣接するマスぞ移動しながら、スタヌトのマスSを出発し、ゎヌルのマスGを目指したす。マスの皮類には、平原、山、氷の皮類がありたす。SずGは、平原のマスに眮かれおいたす。平原のマスには移動できたすが、山のマスには移動できたせん。氷のマスは移動できたすが、条件によっお氷が割れ動けなくなりたす。 </p> <ul> <li> 氷のマスは東西南北に隣接するもの党䜓でひず぀の塊ずしお扱われたす。</li> <li> 氷の塊のなかで、マスの個数の半分より倚くのマスに移動するず、塊党䜓が割れたす。</li> </ul> <p> 䟋えば、図は䞎えられた迷路の最短経路のステップ数が 11 であるこずを瀺しおいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0247_1"><br> <b>図1</b> </center> <p> しかし、図のように氷のマスを通っお近道をしようずするず、倧きさがの氷の塊に察する回目の移動埌に動けなくなっおしたいGには到達できたせん。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0247_2"> <b>図2</b> </center> <p> このような迷路の情報を入力ずし、SからGたでの最短経路のステップ数を求めるプログラムを䜜成しおください。マスの皮類はそれぞれ以䞋の文字で衚されたす </p> <center> <table style="border: 1px #000 solid" "border="1" cellpadding="3" cellspacing="0"> <tr> <th width="160"style="border: 1px #000 solid" >文字半角</th> <th width="160"style="border: 1px #000 solid" >マスの皮類</th> </tr> <tr> <td style="border: 1px #000 solid" >. ピリオド</td> <td style="border: 1px #000 solid" >平原</td> </tr> <tr> <td style="border: 1px #000 solid" >#シャヌプ</td> <td style="border: 1px #000 solid" >å±±</td> </tr> <tr> <td style="border: 1px #000 solid" >X</td> <td style="border: 1px #000 solid" >æ°·</td> </tr> </table> </center> <br> <p> 䞎えられる迷路は必ず解けるものずしたす。迷路はその東西方向のマスの数 <var>X</var>、南北方向のマスの数 <var>Y</var> ず <var>X</var> &times; <var>Y</var> 個の文字ずしお䞎えられたす。 </p> <h2>入力</h2> <p> 耇数のデヌタセットが䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>X</var> <var>Y</var> <var>line<sub>1</sub></var> <var>line<sub>2</sub></var> : <var>line<sub>Y</sub></var> </pre> <p> 1行目に迷路の倧きさを衚す敎数 <var>X</var>, <var>Y</var> (2 &le; <var>X, Y</var> &le; 12) が䞎えられたす。続く <var>Y</var> 行に迷路の <var>i</var> 行目の情報 <var>line<sub>i</sub></var> (長さ <var>X</var> の半角英文字列) が䞎えられたす。 </p> <p> デヌタセットの数は 40 を超えない。 </p> <h2>出力</h2> <p> デヌタセットごずに、最小のステップ数を行に出力したす。 </p> <h2>入力䟋</h2> <pre> 5 5 .X.S. .X#.. .XX## .#XG. ..X.. 7 3 SXX.XXG X.#.#X. XXX.XX# 4 4 S... X.X. GX.. ...X 10 10 ..XXXXX.XX .X.#.#X.XX SX.#X.X..X #X.##.X.XX ..XXXX#.XX ##.##.##XX ....X.XX#X .##X..#X#X ....XX#..X ...#XXG..X 0 0 </pre> <h2>出力䟋</h2> <pre> 11 10 10 33 </pre>
p01006
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1>Problem A: Nasty Boys</h1> <h2>Problem</h2> <p> 倪郎君は孊校のロッカヌに倧事な本を隠しおいるので他の人よりずおも厳重に管理しおいお、孊校で支絊された鍵に加えお以䞋のようなボタン認蚌匏の鍵を蚭眮しおいたす。</p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_progpic" width="300px" height="200px" /> </p> <p> ただパスワヌドを忘れやすい倪郎くんはパスワヌドを䞀筆曞きで曞けるものにしおしたう癖がありたす。曎に詰めの甘い倪郎君は自分のパスワヌドを考えるずきに候補を玙に曞いおいたした。その玙をたたたた拟ったは次郎君は、性栌が悪いので捚おずにロッカヌを開けるこずに挑戊したした。 </p> <p> しかし玙にはなんず1000個ものパスワヌドの案が曞かれおおり、党おの入力を詊すず日が暮れおしたいそうです。 そこで倪郎君の癖を知っおいる次郎君は、調べる回数を枛らすために1000個のパスワヌドの䞭から䞀筆曞きできるものだけを取り䞊げるこずにしお、その䜜業をプログラマヌの貎方に頌むこずにしたした。 </p> <p> 1぀のデヌタセットに぀き必ず候補は䞀぀以䞊存圚したす。䞀筆曞きのルヌルを以䞋に瀺したす。 </p> <ol> <li>同じ文字は連続しない。䟋えばAAAは蚱されない。</li> <li>䞊䞋巊右4方向に䞀筆曞きが可胜。斜め方向に移動しない。</li> <li>ボタン配列の枠倖に出お連続するこずはない。䟋えばABCAのような移動は蚱されない。</li> <li>䞀床通った文字の䞊も䜕床も通過可胜。</li> <li>ボタン1文字のみの入力も䞀筆曞きずみなす。</li> </ol> <h2>Input</h2> <p> 入力は以䞋のように1000個の文字列矀からなり、各行はAからIたでの1文字以䞊10文字以䞋の倧文字のアルファベット列である。それぞれ文字列のデヌタの重耇はないものずする。 </p> <pre> <var>string<sub>1</sub></var> <var>string<sub>2</sub></var> <var>...</var> <var>string<sub>1000</sub></var> </pre> <h2>Output</h2> <p> 入力のうち候補ずなるパスワヌドcandidatePasswordのみ抜き出しお以䞋のように列挙せよ。なお以䞋の堎合はN個の候補が挙げられおいる。 </p> <pre> <var>candidatePassword<sub>1</sub></var> <var>candidatePassword<sub>2</sub></var> <var>...</var> <var>candidatePassword<sub>N</sub></var> </pre> <p> 出力は入力の文字列の順ず同じであり順番を入れ替えおはならない。 </p> <h2>Sample Input</h2> <pre> ABCFI ABCABCABC AEI EFC 䞭略 DEHED EEEEE 以䞊でちょうど1000個 </pre> <h2>Sample Output</h2> <pre> ABCFI EFC 䞭略 DEHED </pre>
p03191
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a sequence of length <var>2N</var>: <var>A_1, A_2, ..., A_{2N}</var>. Each <var>A_i</var> is either <var>-1</var> or an integer between <var>1</var> and <var>2N</var> (inclusive). Any integer other than <var>-1</var> appears at most once in <var>{A_i}</var>.</p> <p>For each <var>i</var> such that <var>A_i = -1</var>, Snuke replaces <var>A_i</var> with an integer between <var>1</var> and <var>2N</var> (inclusive), so that <var>{A_i}</var> will be a permutation of <var>1, 2, ..., 2N</var>. Then, he finds a sequence of length <var>N</var>, <var>B_1, B_2, ..., B_N</var>, as <var>B_i = min(A_{2i-1}, A_{2i})</var>.</p> <p>Find the number of different sequences that <var>B_1, B_2, ..., B_N</var> can be, modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300</var></li> <li><var>A_i = -1</var> or <var>1 \leq A_i \leq 2N</var>.</li> <li>If <var>A_i \neq -1, A_j \neq -1</var>, then <var>A_i \neq A_j</var>. (<var>i \neq j</var>)</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_{2N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of different sequences that <var>B_1, B_2, ..., B_N</var> can be, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 -1 -1 3 6 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are six ways to make <var>{A_i}</var> a permutation of <var>1, 2, ..., 2N</var>; for each of them, <var>{B_i}</var> would be as follows:</p> <ul> <li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 4, 3, 6, 5)</var>: <var>(B_1, B_2, B_3) = (1, 3, 5)</var></li> <li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 5, 3, 6, 4)</var>: <var>(B_1, B_2, B_3) = (1, 3, 4)</var></li> <li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 2, 3, 6, 5)</var>: <var>(B_1, B_2, B_3) = (1, 2, 5)</var></li> <li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 5, 3, 6, 2)</var>: <var>(B_1, B_2, B_3) = (1, 3, 2)</var></li> <li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 2, 3, 6, 4)</var>: <var>(B_1, B_2, B_3) = (1, 2, 4)</var></li> <li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 4, 3, 6, 2)</var>: <var>(B_1, B_2, B_3) = (1, 3, 2)</var></li> </ul> <p>Thus, there are five different sequences that <var>B_1, B_2, B_3</var> can be.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 7 1 8 3 5 2 6 4 </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>10 7 -1 -1 -1 -1 -1 -1 6 14 12 13 -1 15 -1 -1 -1 -1 20 -1 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9540576 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 -1 -1 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 34 -1 -1 -1 -1 31 -1 -1 -1 -1 -1 -1 -1 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>374984201 </pre></section> </div> </span>
p01456
<H1>Problem J: 問題文担圓者は働かない</H1> <p> <i>N</i> 個の点からなる有向グラフがある。このグラフに閉路はない。それぞれの点には、いく぀かの石が眮かれおいる。このグラフを䜿っお、人のプレむダヌがゲヌムをする。おのおのの手番は、亀互に蚪れる。各プレむダヌは、自分の手番においお、頂点<i>v</i> を遞び、そこに眮かれた石を぀以䞊取り陀く。その埌、<i>v</i> から<i>w</i> に蟺が匵られおいるすべおの頂点<i>w</i> に぀いお、<i>w</i> に眮かれおいる石の個数を自由に倉化させるこずができるいく぀増やしおも、いく぀枛らしおも、倉化させなくおもよい。これを繰り返しお、最初に取る石がなくなった方の負けである。䞡者が最善を぀くしたずき、先手ず埌手、どちらが勝぀か。もしくは、い぀たでもゲヌムが終わらないか。 </p> <p> 「  いや、無理でしょう、これ」<br> 「䜕が」<br> 「䜕がじゃなくお これにどうやっお自然な問題蚭定を぀けろっお蚀うんですか」<br> 「ははは。それを考えるのが君の仕事じゃないか。文章担圓だろう」<br> 「䞞投げにもほどがありたすよ  。たずゲヌムのルヌルが䞍自然すぎるでしょう」<br> 「そうかなぁ 僕はよくある石取りゲヌムだず思うけどね」<br> 「プレむダヌの意思で石を無尜蔵に増やせる石取りゲヌムがよくあっおたたりたすか」<br> 「お。君、今うたいこず蚀ったね」<br> 「ええ、意思で石を  っおどうでもいいわ そっちも少しは考えおくださいよ」<br> 「そうだねぇ。瞊死した医垫の遺志を継ぐ遺子の意思で石を取る、なんおどうだい」<br> 「考えるのはそこじゃねぇよ 石取りゲヌムの話だよ」<br> 「違うのかい でも『取り』は鳥くらいしか同音異矩語がなくお難しいんだよね」<br> 「いったん蚀葉遊びから離れろや 自然な問題蚭定を考えおくれっお蚀っおるんですよ」<br> 「だからそれは君の仕事だろうに。僕はただの仲介圹。原案担圓ず文章担圓の間をずりも぀だけさ」<br> 「くそ  。原案担圓め、どうしおこんな厄介な問題を  」<br> 「原案担圓者から君ぞのメッセヌゞ。『フヒヒ 存分に苊しめ文章担圓』だそうだよ」<br> 「畜生あの野郎 い぀か䞀発殎る」<br> 「たあ、僕の『石が増える石取りゲヌムなんお実に蚭定が぀けにくいず思わないかい』っおアドバ むスのおかげもあるだろうけどね」<br> 「畜生お前もか い぀かず蚀わず今殎る」<br> 「はっはっは。君が締め切りたでに文章担圓ずしおの圹割を果たせないようなら、僕が勝手に問題文 を曞いちゃうよ」<br> 「殎  っお、え お前が曞いおくれんの」<br> 「タむトルは『問題文担圓者は働かない』。本文には、僕たちのこの䌚話をそのたた掲茉」<br> 「頌むからやめお そんなふざけた問題が自分名矩で䞖に出たら、これから皆になんお蚀われる か」<br> 「はっはっは。締め切りも守れないような奎は、瀟䌚的に抹殺されお圓然だよね」<br> 「畜生 こうなったら、意地でも自然な問題蚭定を思い぀いおやらあああああ」<br><br> ※ 結局そのたた掲茉されたした<br> </p> <H2>Input</H2> <p> <i>N M</i><br> <i>v</i><sub>1</sub><br> <i>v</i><sub>2</sub><br> .<br> .<br> .<br> <i>v<sub>N</sub></i><br> <i>a</i><sub>1</sub> <i>b</i><sub>1</sub></br> <i>a</i><sub>2</sub> <i>b</i><sub>2</sub></br> .<br> .<br> .<br> <i>a<sub>M</sub> b<sub>M</sub></i><br> </p> <p> 入力の行目には、敎数<i>N</i>2 &le; <i>N</i> &le; 1,000ず敎数<i>M</i>1 &le; <i>M</i> &le; 10,000が、空癜区切りで曞かれおいる。これは、有向グラフがN 個の点ず<i>M</i> 本の蟺からなるこずをあらわす。頂点には、1 番から<i>N</i> 番たでの番号がふられおいる。 </p> <p> 続く<i>N</i> 行には、敎数<i>v<sub>i</sub></i>1 &le; <i>v<sub>i</sub></i> &le; 10,000が曞かれおいる。 i 行目に曞かれた敎数<i>v<sub>i</sub></i> は、i 番の点に最初はvi 個の石が眮かれおいるこずをあらわす。 </p> <p> 続く<i>M</i> 行には、敎数<i>a<sub>i</sub></i>1 &le; <i>a<sub>i</sub></i> &le; <i>N</i>ず敎数<i>b<sub>i</sub></i>1 &le; <i>b<sub>i</sub></i> &le; <i>N</i>が、空癜区切りで曞かれおいる。<i>N</i>  i 行目に曞かれた敎数<i>a<sub>i</sub></i> ず<i>b<sub>i</sub></i> は、<i>a<sub>i</sub></i> 番の点から<i>b<sub>i</sub></i> 番の点ぞ匵られおいる蟺が存圚するこずをあらわす。ある点から自分自身ぞず匵られる蟺は存圚せず、ある点A からある点B ぞ匵られる蟺は高々本である。 </p> <p> 䞎えられた有向グラフには閉路がないず仮定しおよい。 </p> <H2>Output</H2> <p> 䞡プレむダヌが自身の勝利を目指しお最善を぀くしたずき、先手が勝぀ならば1 を、埌手が勝぀なら ば2 を、い぀たでもゲヌムが終わらないならば0 を出力せよ。 </p> <h2>Sample Input 1 </h2> <pre> 6 5 7 14 5 11 2 5 1 2 2 3 3 4 4 5 5 6 </pre> <h2>Sample Output 1 </h2> <pre> 2 </pre> <h2>Sample Input 2 </h2> <pre> 5 7 295 127 350 982 426 1 5 3 5 4 2 3 1 3 4 5 4 3 2 </pre> <h2>Sample Output 2 </h2> <pre> 1 </pre> <h2>Sample Input 3 </h2> <pre> 8 7 6 1 7 2 5 2 6 3 1 3 6 3 7 4 4 2 1 6 5 4 7 5 </pre> <h2>Sample Output 3 </h2> <pre> 2 </pre>
p01143
<!-- begin en only --> <h3><U> Princess' Gamble </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> ある貧乏な囜のおおんばで勇敢なお姫様はある日郚屋の壁を壊しおお城を抜け出し競銬などのギャンブルが行われおいる賭博堎に入っおいったずころがギャンブルなどやったこずのないお姫様は非垞に負けが蟌んでしたったこの状況をおもしろくないず思ったお姫様は䞀䜓どのような仕組みでギャンブルが行われおいるかを調べおみたするずこのようなギャンブルではパリミュチュ゚ル方匏ず呌ばれる方匏で配圓が決定されおいるこずを突き止めた </p> <p> パリミュチュ゚ル方匏ずは競走を察象ずしたギャンブルにおいお配圓を決定するために䜿甚する蚈算方法であるこの方匏では党おの掛け金をプヌルし䞀定の割合を控陀した䞊で圓遞者に掛け金に比䟋した金額を分配する </p> <p> 珟圚お姫様が熱䞭しおいるギャンブルは参加者は競技前にどの競技者が優勝するかを予想する 1枚100ゎヌルドの投祚刞を賌入し競技の結果が予想ず䞀臎すれば圓遞金を受け取る暩利を埗るずいうものであるなおゎヌルドはこの囜の通貚単䜍であるあなたの仕事は入力ずしお䞎えられる競技の情報をもずに投祚刞䞀枚あたりの配圓を蚈算するプログラムを曞くこずである </p> <p> 先述の方法で蚈算される配圓額が敎数にならない堎合は切り捚おによっお敎数にするこず </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットから成るデヌタセットの個数は100以䞋である最埌のデヌタセットの埌に入力の終わりを瀺す「0 0 0」からなる䞀行が䞎えられる </p> <p> 各デヌタセットは次のような圢匏をしおいる </p> <blockquote> <i>N</i> <i>M</i> <i>P</i><br> <i>X<sub>1</sub></i><br> ...<br> <i>X<sub>N</sub></i> </blockquote> <p> 最初の行の <i>N</i> は投祚の察象ずなる競技者の数<i>M</i> は優勝した競技者の番号<i>P</i> は控陀率癟分率を衚す敎数である <i>X<sub>i</sub></i> は <i>i</i> 番目の競技者に投祚された投祚刞の枚数である 1 ≩ <i>N</i> ≩ 100 1 ≩ <i>M</i> ≩ <i>N</i> 0 ≩ <i>P</i> ≩ 100 0 ≩ <i>X<sub>i</sub></i> ≩ 1000 を仮定しおよい </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットに察し圓遞した投祚刞䞀枚あたりの配圓金額を瀺す敎数からなる䞀行を出力せよ賭けに勝った人がいない堎合は0を出力せよ出力行には他の文字があっおはならない </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 3 2 50 1 2 3 4 4 75 1 2 3 0 3 1 10 8 1 1 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 150 0 112 </pre>
p03484
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has decided to make a <em>Christmas Tree</em> for the Christmas party in AtCoder, Inc.</p> <p>A Christmas Tree is a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var> and <var>N-1</var> edges, whose <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>He would like to make one as follows:</p> <ul> <li>Specify two non-negative integers <var>A</var> and <var>B</var>.</li> <li>Prepare <var>A</var> <em>Christmas Paths</em> whose lengths are at most <var>B</var>. Here, a Christmas Path of length <var>X</var> is a graph with <var>X+1</var> vertices and <var>X</var> edges such that, if we properly number the vertices <var>1</var> through <var>X+1</var>, the <var>i</var>-th edge <var>(1\leq i\leq X)</var> will connect Vertex <var>i</var> and <var>i+1</var>.</li> <li>Repeat the following operation until he has one connected tree:<ul> <li>Select two vertices <var>x</var> and <var>y</var> that belong to different connected components. Combine <var>x</var> and <var>y</var> into one vertex. More precisely, for each edge <var>(p,y)</var> incident to the vertex <var>y</var>, add the edge <var>(p,x)</var>. Then, delete the vertex <var>y</var> and all the edges incident to <var>y</var>.</li> </ul> </li> <li>Properly number the vertices in the tree.</li> </ul> <p>Takahashi would like to find the lexicographically smallest pair <var>(A,B)</var> such that he can make a Christmas Tree, that is, find the smallest <var>A</var>, and find the smallest <var>B</var> under the condition that <var>A</var> is minimized.</p> <p>Solve this problem for him.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq a_i,b_i \leq N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>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>For the lexicographically smallest <var>(A,B)</var>, print <var>A</var> and <var>B</var> with a space in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 1 2 2 3 2 4 4 5 4 6 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 2 </pre> <p>We can make a Christmas Tree as shown in the figure below:</p> <p><img alt="" src="https://img.atcoder.jp/arc088/96f78221624d6a13628f6052f5db697d.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 1 2 2 3 3 4 4 5 5 6 5 7 5 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 2 2 3 3 4 2 5 6 5 6 7 7 8 5 9 10 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 4 </pre></section> </div> </span>
p01513
<!-- begin en only --> <h3><u>Save Your Privacy! </u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>君のプラむバシヌを守れ! </u></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> ICPC (International Committee of Privacy and Confidence) は䞖界䞭に倚くの構成員を持぀組織であり、その名の通り非垞にプラむバシヌを尊重する、秘密䞻矩者たちの団䜓である。構成員たちは必芁䞊他の構成員の個人情報を知っおしたうこずがあるが、それらを厳重に秘匿するよう矩務付けられおいる。 </p> <p> しかしある日、䜕人かの構成員の個人情報が挏掩しおしたったICPCの ACM (Account Control Manager: アカりント管理責任者) であるあなたは、速やかに情報を挏掩させた構成員を特定し、厳重に凊分しなければならない。 </p> <p> あなたは構成員よりも倧きな暩限を持぀管理者なので、誰が誰の個人情報を知っおしたっおいるかを完党に把握しおいる。もちろん、どの構成員も自分の知らない構成員の個人情報を挏掩させるこずはありえない。しかし、犯人は自分が知っおいる党おの個人情報を挏掩させたずは限らない。個人情報が挏掩しおしたった構成員の䞀芧から、どの構成員が個人情報を挏掩させたのかを (可胜ならば) 特定しよう。 </p> <p> ずころで、ICPC ずいう組織が䜕を目的ずしお掻動しおいるのかは最重芁機密であり、管理者の暩限をもっおしおも知るこずはできない。 </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力ファむルは耇数のデヌタセットを含む。1 ぀のデヌタセットは、以䞋の圢匏で䞎えられる。 </p> <blockquote> <var>N</var><br/> <var>M<sub>1</sub></var> <var>p<sub>1,1</sub></var> <var>p<sub>1,2</sub>...</var> <var>p<sub>1,M<sub>1</sub></sub></var><br/> <var>M<sub>2</sub></var> <var>p<sub>2,1</sub></var> <var>p<sub>2,2</sub>...</var> <var>p<sub>2,M<sub>2</sub></sub></var><br/> <var>:</var><br/> <var>M<sub>N</sub></var> <var>p<sub>N,1</sub></var> <var>p<sub>N,2</sub>...</var> <var>p<sub>N,M<sub>N</sub></sub></var><br/> <var>K</var> <var>l<sub>1</sub></var> <var>l<sub>2</sub>...</var> <var>l<sub>K</sub></var><br/> </blockquote> <p> N (2 &#8804; N &#8804; 100) は構成員の数を衚す敎数である。それぞれの構成員には 1 から N たでの番号が振られおいる。 続く N 行には各構成員の番号順に、その構成員が知っおいる個人情報の䞀芧が䞎えられる。各行の最初の敎数 M<sub>i</sub> (0 &#8804; M<sub>i</sub> &#8804; N)は、埌に続く敎数の個数を衚す。残りの敎数は、その構成員が個人情報を知っおいる構成員の番号を衚す。 最埌の行には、個人情報が挏掩した構成員の䞀芧が瀺される。 K (1 &#8804; K &#8804; N) は挏掩した構成員の人数を衚し、残りの敎数は挏掩した構成員の番号を衚す。 </p> <p> 入力は正しく䞎えられるず仮定しおよい。぀たり、ある構成員が知っおいる個人情報の䞀芧ずしお、同じ構成員の番号が 2 回以䞊䞎えられたり、存圚しない構成員の番号が䞎えられるこずはない。挏掩した構成員の番号の䞀芧も同様である。 </p> <p> N = 0 のずき、入力は終了する。 </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 個人情報を挏掩させた構成員を特定できるならば、その構成員の番号を出力せよ。特定できない堎合 -1 を出力せよ。 </p> <p> 特定できない堎合には、次の 2 ぀のケヌスがある。 1 ぀は、流出させた可胜性がある構成員が 2 人以䞊挙げられる堎合である。もう 1 ぀は、どの構成員が流出させたず仮定しおも矛盟が生じる堎合である。どちらの堎合でも、あなたのプログラムは -1 ず出力しなければならない。 </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 3 2 2 3 1 1 1 1 2 2 3 3 2 2 3 1 3 1 2 1 2 5 3 1 3 4 4 1 3 4 5 2 1 3 2 1 2 0 3 1 3 5 3 2 2 1 1 1 1 2 3 3 2 1 0 </pre> <!-- begin ja only --> <!-- end ja only --> </div> <h3>Output for Sample Input</h3> <div> <pre> 1 -1 2 -1 </pre> <!-- begin ja only --> <!-- end ja only --> </div>
p01840
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h2>B - 豪邞ず宅配䟿</h2> <h3>Problem Statement</h3> <p> 倪郎君は豪邞で䞀人暮らしをしおいる 勉匷奜きの倪郎君は今日も邞内の曞斎で勉匷をする぀もりである 倪郎君は曞斎以倖の堎所では集䞭できないので勉匷は必ず曞斎で行う </p> <p> ずころがこの日倪郎君宛の宅配䟿が $N$ 件届く$i$ ($1 \leq i \leq N$) 番目の宅配䟿の届く時刻は $a_i$ である 配達員を玄関先で埅たせるのは心苊しいので倪郎君は宅配䟿の届く時刻には玄関にいるこずにした 豪邞は広いので曞斎ず玄関間の移動には片道 $M$ の時間がかかる </p> <p> 䞀方で倪郎君はできるだけ長い時間勉匷したいず思っおいる 時刻 $0$ から時刻 $T$ たでで倪郎君が曞斎で勉匷できる時間の最倧倀を求めよ </p> <p> なお倪郎君は時刻 $0$ には曞斎にいお時刻 $M$ より早く宅配䟿が届くこずはなく時刻 $T$ より遅く宅配䟿が届くこずもない たた倪郎君が宅配䟿を受け取るのにかかる時間は無芖できる </p> <h3>Input</h3> <p> 各デヌタセットは 2 行からなる 1 行目は空癜で区切られた 3 ぀の敎数 $N, M, T$ からなる これらの敎数は$1 \leq N \leq 100$, $1 \leq M \leq 10{,}000$, $1 \leq T \leq 10{,}000$ を満たす 2 行目は空癜で区切られた $N$ 個の敎数 $a_1, a_2, \dots, a_N$ からなる 各 $a_i$ は $M \leq a_i \leq T$ を満たしたた $a_i < a_{ i + 1 }$ ($1 \leq i < N$) である </p> <h3>Output</h3> <p> 倪郎君が勉匷できる時間の最倧倀を衚す敎数を 1 行に出力せよ </p> <h3>Sample Input 1</h3> <pre>1 1 5 3</pre> <h3>Output for the Sample Input 1</h3> <pre>3</pre> <h3>Sample Input 2</h3> <pre>2 1 10 2 7</pre> <h3>Output for the Sample Input 2</h3> <pre>6</pre> <h3>Sample Input 3</h3> <pre>2 4 10 6 8</pre> <h3>Output for the Sample Input 3</h3> <pre>2</pre>
p00752
<!-- begin en only --> <h1><font color="#000000">Problem G:</font> Laser Beam Reflections</h1> <!-- end en only --> <!-- begin en only --> <p> A laser beam generator, a target object and some mirrors are placed on a plane. The mirrors stand upright on the plane, and both sides of the mirrors are flat and can reflect beams. To point the beam at the target, you may set the beam to several directions because of different reflections. Your job is to find the shortest beam path from the generator to the target and answer the length of the path. </p> <!-- end en only --> <!-- begin en only --> <p> Figure G-1 shows examples of possible beam paths, where the bold line represents the shortest one. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_G-0" align="center"><br><br> <!-- begin en only --> Figure G-1: Examples of possible paths <!-- end en only --> </center> <h3>Input</h3> <!-- begin en only --> <p> The input consists of a number of datasets. The end of the input is indicated by a line containing a zero. </p> <!-- end en only --> <!-- begin en only --> <p> Each dataset is formatted as follows. Each value in the dataset except <i>n</i> is an integer no less than 0 and no more than 100. </p> <!-- end en only --> <p></p> <blockquote> <i>n</i><br> <i>PX</i><sub>1</sub> <i>PY</i><sub>1</sub> <i>QX</i><sub>1</sub> <i>QY</i><sub>1</sub><br> ...<br> <i>PX<sub><i>n</i></sub></i> <i>PY<sub><i>n</i></sub></i> <i>QX<sub><i>n</i></sub></i> <i>QY<sub><i>n</i></sub></i><br> <i>TX</i> <i>TY</i><br> <i>LX</i> <i>LY</i><br> </blockquote> <p></p> <!-- begin en only --> <p> The first line of a dataset contains an integer <i>n</i> (1 &le; <i>n</i> &le; 5), representing the number of mirrors. The following <i>n</i> lines list the arrangement of mirrors on the plane. The coordinates (<i>PX<sub>i</sub></i>, <i>PY<sub>i</sub></i>) and (<i>QX<sub>i</sub></i>, <i>QY<sub>i</sub></i>) represent the positions of both ends of the mirror. Mirrors are apart from each other. The last two lines represent the target position (<i>TX</i>, <i>TY</i>) and the position of the beam generator (<i>LX</i>, <i>LY</i>). The positions of the target and the generator are apart from each other, and these positions are also apart from mirrors. </p> <!-- end en only --> <!-- begin en only --> <p> The sizes of the target object and the beam generator are small enough to be ignored. You can also ignore the thicknesses of mirrors. </p> <!-- end en only --> <!-- begin en only --> <p> In addition, you can assume the following conditions on the given datasets. <ul> <li>There is at least one possible path from the beam generator to the target. </li> <li>The number of reflections along the shortest path is less than 6. </li> <li> The shortest path does not cross or touch a plane containing a mirror surface at any points within 0.001 unit distance from either end of the mirror. </li> <li> Even if the beam could arbitrarily select reflection or passage when it reaches each plane containing a mirror surface at a point within 0.001 unit distance from one of the mirror ends, any paths from the generator to the target would not be shorter than the shortest path. </li> <li> When the beam is shot from the generator in an arbitrary direction and it reflects on a mirror or passes the mirror within 0.001 unit distance from the mirror, the angle <i>&theta;</i> formed by the beam and the mirror satisfies sin(<i>&theta;</i>) > 0.1, until the beam reaches the 6th reflection point (exclusive). </li> </ul> </p> <!-- end en only --> <!-- begin en only --> <p> Figure G-1 corresponds to the first dataset of the Sample Input below. Figure G-2 shows the shortest paths for the subsequent datasets of the Sample Input. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_G-2" align="center"><br><br> <!-- begin en only --> Figure G-2: Examples of the shortest paths <!-- end en only --> </center> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing the length of the shortest path from the beam generator to the target. The value should not have an error greater than 0.001. No extra characters should appear in the output. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 2 30 10 30 75 60 30 60 95 90 0 0 100 1 20 81 90 90 10 90 90 10 2 10 0 10 58 20 20 20 58 0 70 30 0 4 8 0 8 60 16 16 16 48 16 10 28 30 16 52 28 34 24 0 24 64 5 8 0 8 60 16 16 16 48 16 10 28 30 16 52 28 34 100 0 100 50 24 0 24 64 0 </pre> <h3>Output for the Sample Input</h3> <pre> 180.27756377319946 113.13708498984761 98.99494936611666 90.50966799187809 90.50966799187809 </pre>
p02295
<H1>Cross Point</H1> <br/> <p> For given two segments <var>s1</var> and <var>s2</var>, print the coordinate of the cross point of them. </p> <p> <var>s1</var> is formed by end points <var>p0</var> and <var>p1</var>, and <var>s2</var> is formed by end points <var>p2</var> and <var>p3</var>. </p> <H2>Input</H2> <p> The entire input looks like: </p> <pre> <var>q</var> (the number of queries) 1st query 2nd query ... <var>q</var>th query </pre> <p> Each query consists of integer coordinates of end points of <var>s1</var> and <var>s2</var> in the following format: </p> <pre> <var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>x<sub>p2</sub></var> <var>y<sub>p2</sub></var> <var>x<sub>p3</sub></var> <var>y<sub>p3</sub></var> </pre> <H2>Output</H2> <p> For each query, print the coordinate of the cross point. The output values should be in a decimal fraction with an error less than 0.00000001. </p> <H2>Constraints</H2> <ul> <li> 1 &le; <i>q</i> &le; 1000 </li> <li> -10000 &le; x<sub>p<sub>i</sub></sub>, y<sub>p<sub>i</sub></sub> &le; 10000 </li> <li> <var>p0 &ne; p1</var> and <var>p2 &ne; p3</var>. </li> <li> The given segments have a cross point and are not in parallel. </li> </ul> <H2>Sample Input</H2> <pre> 3 0 0 2 0 1 1 1 -1 0 0 1 1 0 1 1 0 0 0 1 1 1 0 0 1 </pre> <H2>Sample Output</H2> <pre> 1.0000000000 0.0000000000 0.5000000000 0.5000000000 0.5000000000 0.5000000000 </pre> <br/>
p00302
<h1>ニッシン通マラ゜ン郚</h1> <p> アむヅ垂立ニッシン通は、文歊䞡道を掲げる歎史ある孊校です。ニッシン通マラ゜ン郚は熱血指導で有名であり、決められた緎習時間の間、呚回コヌスをひたすら走るずいう鬌の特蚓を行いたす。このずき、脱氎症状で倒れる郚員がいないように、郚員の実力に合わせお飲み物を提䟛する絊氎所を蚭けおいたす。 </p> <p> 各郚員が単䜍時間あたりに走れる距離(ペヌス)は郚員ごずに決たっおおり、党員が単䜍時間ごずに必ず絊氎できるように絊氎所を蚭けたうえで特蚓を行いたす。郚員は 1 単䜍時間で着いた絊氎所で必ず䞭身の入った容噚を取り、そのたた走り続けたす。さらに、次の単䜍時間で着いた絊氎所で空の容噚を眮き、䞭身の入った容噚を取っお走り続けるずいうこずを繰り返したす。たた、空の容噚は、眮いおから 1 単䜍時間の時点で飲料が補充され、その瞬間から誰にでも提䟛できるようになりたす。 </p> <p> 郚員は党員同じ地点から、容噚を持たずに出発したす。決められた緎習時間たで走るず緎習を終えたす(このずきも絊氎が必芁です)。耇数の郚員が同時に同じ絊氎所に到着する堎合もあるので、䞀か所の絊氎所で同時に耇数の容噚が必芁になるこずもありたす。 </p> <p> 鬌の特蚓を安党に行うために、最䜎いく぀の絊氎容噚が必芁になるか求めるプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>R</var> <var>T</var> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> : <var>p<sub>N</sub></var> </pre> <p> 行目に郚員の数 <var>N</var> (1 &le; <var>N</var> &le; 100)、呚回コヌスの長さ <var>R</var> (1 &le; <var>R</var> &le; 1000)、決められた緎習時間 <var>T</var> (1 &le; <var>T</var> &le; 1000) が䞎えられる。続く <var>N</var> 行に、郚員 <var>i</var> のペヌス <var>p<sub>i</sub></var> (1 &le; <var>p<sub>i</sub></var> &le; 1000) が䞎えられる。 </p> <h2>出力</h2> <p> 最䜎いく぀の絊氎容噚が必芁になるかを行に出力する。 </p> <h2>入出力䟋</h2> <h2>入力䟋 </h2> <pre> 1 10 20 1 </pre> <h2>出力䟋</h2> <pre> 11 </pre> <br> <h2>入力䟋 </h2> <pre> 2 5 12 1 2 </pre> <h2>出力䟋</h2> <pre> 8 </pre>
p03607
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are playing the following game with Joisino.</p> <ul> <li>Initially, you have a blank sheet of paper.</li> <li>Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated <var>N</var> times.</li> <li>Then, you are asked a question: How many numbers are written on the sheet now?</li> </ul> <p>The numbers announced by Joisino are given as <var>A_1, ... ,A_N</var> in the order she announces them. How many numbers will be written on the sheet at the end of the game?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀N≀100000</var></li> <li><var>1≀A_i≀1000000000(=10^9)</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>:</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print how many numbers will be written on the sheet at the end of the game.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 6 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>The game proceeds as follows:</p> <ul> <li> <p><var>6</var> is not written on the sheet, so write <var>6</var>.</p> </li> <li> <p><var>2</var> is not written on the sheet, so write <var>2</var>.</p> </li> <li> <p><var>6</var> is written on the sheet, so erase <var>6</var>.</p> </li> </ul> <p>Thus, the sheet contains only <var>2</var> in the end. The answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 5 5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>It is possible that no number is written on the sheet in the end.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 12 22 16 22 18 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre></section> </div> </span>
p02915
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is going to set a <var>3</var>-character password.</p> <p>How many possible passwords are there if each of its characters must be a digit between <var>1</var> and <var>N</var> (inclusive)?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 9</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 number of possible passwords.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>There are eight possible passwords: <code>111</code>, <code>112</code>, <code>121</code>, <code>122</code>, <code>211</code>, <code>212</code>, <code>221</code>, and <code>222</code>.</p> </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>1 </pre> <p>There is only one possible password if you can only use one kind of character.</p></section> </div> </span>
p00928
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem E: Automotive Navigation </h2> <p> The International Commission for Perfect Cars (ICPC) has constructed a city scale test course for advanced driver assistance systems. Your company, namely the Automotive Control Machines (ACM), is appointed by ICPC to make test runs on the course. </p> <p> The test course consists of streets, each running straight either east-west or north-south. No streets of the test course have dead ends, that is, at each end of a street, it meets another one. There are no grade separated streets either, and so if a pair of orthogonal streets run through the same geographical location, they always meet at a crossing or a junction, where a car can turn from one to the other. No U-turns are allowed on the test course and a car never moves outside of the streets. </p> <p> Oops! You have just received an error report telling that the GPS (Global Positioning System) unit of a car running on the test course was broken and the driver got lost. Fortunately, however, the odometer and the electronic compass of the car are still alive. </p> <p> You are requested to write a program to estimate the current location of the car from available information. You have the car's location just before its GPS unit was broken. Also, you can remotely measure the running distance and the direction of the car once every time unit. The measured direction of the car is one of north, east, south, and west. If you measure the direction of the car while it is making a turn, the measurement result can be the direction either before or after the turn. You can assume that the width of each street is zero. </p> <p> The car's direction when the GPS unit was broken is not known. You should consider every possible direction consistent with the street on which the car was running at that time. </p> <h3>Input</h3> <p> The input consists of a single test case. The first line contains four integers $n$, $x_0$, $y_0$, $t$, which are the number of streets ($4 \leq n \leq 50$), $x$- and $y$-coordinates of the car at time zero, when the GPS unit was broken, and the current time ($1 \leq t \leq 100$), respectively. $(x_0, y_0)$ is of course on some street. This is followed by $n$ lines, each containing four integers $x_s$, $y_s$, $x_e$, $y_e$ describing a street from $(x_s, y_s)$ to $(x_e, y_e)$ where $(x_s, y_s) \ne (x_e, y_e)$. Since each street runs either east-west or north-south, $x_s = x_e$ or $y_s = y_e$ is also satisfied. You can assume that no two parallel streets overlap or meet. In this coordinate system, the $x$- and $y$-axes point east and north, respectively. Each input coordinate is non-negative and at most 50. Each of the remaining $t$ lines contains an integer $d_i$ ($1 \leq d_i \leq 10$), specifying the measured running distance from time $i − 1$ to $i$, and a letter $c_i$, denoting the measured direction of the car at time $i$ and being either <span>N</span> for north, <span>E</span> for east, <span>W</span> for west, or <span>S</span> for south. </p> <h3>Output</h3> <p> Output all the possible current locations of the car that are consistent with the measurements. If they are $(x_1, y_1),(x_2, y_2), . . . ,(x_p, y_p)$ in the lexicographic order, that is, $x_i < x_j$ or $x_i = x_j$ and $y_i < y_j$ if $1 \leq i < j \leq p$, output the following:<br> <br> $x_1$ $y_1$<br> $x_2$ $y_2$<br> .<br> .<br> .<br> $x_p$ $y_p$<br> <br> Each output line should consist of two integers separated by a space. </p> <p> You can assume that at least one location on a street is consistent with the measurements </p> <h3>Sample Input 1</h3> <pre>4 2 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 2 1 9 N</pre> <h3>Sample Output 1</h3> <pre>1 1 2 2</pre> <h3>Sample Input 2</h3> <pre>6 0 0 2 0 0 2 0 0 1 2 1 0 2 2 2 0 0 0 2 1 0 1 2 2 0 2 2 2 E 7 N</pre> <h3>Sample Output 2</h3> <pre>0 1 1 0 1 2 2 1</pre> <h3>Sample Input 3</h3> <pre>7 10 0 1 5 0 10 0 8 5 15 5 5 10 15 10 5 0 5 10 8 5 8 10 10 0 10 10 15 5 15 10 10 N</pre> <h3>Sample Output 3</h3> <pre>5 5 8 8 10 10 15 5</pre>
p03257
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var>.</p> <p>Construct any one <var>N</var>-by-<var>N</var> matrix <var>a</var> that satisfies the conditions below. It can be proved that a solution always exists under the constraints of this problem.</p> <ul> <li><var>1 \leq a_{i,j} \leq 10^{15}</var></li> <li><var>a_{i,j}</var> are pairwise distinct integers.</li> <li>There exists a positive integer <var>m</var> such that the following holds: Let <var>x</var> and <var>y</var> be two elements of the matrix that are vertically or horizontally adjacent. Then, <var>{\rm max}(x,y)</var> <var>{\rm mod}</var> <var>{\rm min}(x,y)</var> is always <var>m</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 500</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print your solution in the following format:</p> <pre><var>a_{1,1}</var> <var>...</var> <var>a_{1,N}</var> <var>:</var> <var>a_{N,1}</var> <var>...</var> <var>a_{N,N}</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 7 23 10 </pre> <ul> <li>For any two elements <var>x</var> and <var>y</var> that are vertically or horizontally adjacent, <var>{\rm max}(x,y)</var> <var>{\rm mod}</var> <var>{\rm min}(x,y)</var> is always <var>3</var>.</li> </ul></section> </div> </span>
p01790
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem A Balanced Paths</h2> <p> You are given an undirected tree with $n$ nodes. The nodes are numbered 1 through $n$. Each node is labeled with either '(' or ')'. Let $l[u \rightarrow v]$ denote the string obtained by concatenating the labels of the nodes on the simple path from $u$ to $v$. (Note that the simple path between two nodes is uniquely determined on a tree.) A <i>balanced</i> string is defined as follows: </p> <ul> <li> The empty string is balanced.</li> <li> For any balanced string $s$, the string "(" $s$ ")" is balanced.</li> <li> For any balanced strings $s$ and $t$, the string $st$ (the concatenation of $s$ and $t$) is balanced.</li> <li> Any other string is NOT balanced.</li> </ul> <p> Calculate the number of the ordered pairs of the nodes ($u$, $v$) such that $l[u \rightarrow v]$ is balanced. </p> <h3>Input</h3> <p> The input consists of a single test case. The input starts with an integer $n (2 \leq n \leq 10^5)$, which is the number of nodes of the tree. The next line contains a string of length $n$, each character of which is either '(' or ')'. The $x$-th character of the string represents the label of the node $x$ of the tree. Each of the following $n - 1$ lines contains two integers $a_i$ and $b_i$ $(1 \leq a_i, b_i \leq n)$, which represents that the node $a_i$ and the node $b_i$ are connected by an edge. The given graph is guaranteed to be a tree. </p> <h3>Output</h3> <p> Display a line containing the number of the ordered pairs ($u$, $v$) such that $l[u \rightarrow v]$ is balanced. </p> <h3>Sample Input 1</h3> <pre>2 () 1 2</pre> <h3>Output for the Sample Input 1</h3> <pre>1</pre> <h3>Sample Input 2</h3> <pre>4 (()) 1 2 2 3 3 4</pre> <h3>Output for the Sample Input 2</h3> <pre>2</pre> <h3>Sample Input 3</h3> <pre>5 ()()) 1 2 2 3 2 4 1 5</pre> <h3>Output for the Sample Input 3</h3> <pre>4</pre>
p00882
<H1><font color="#000">Problem I:</font> Hobby on Rails</H1> <p> ICPC (International Connecting Points Company) starts to sell a new railway toy. It consists of a toy tramcar and many rail units on square frames of the same size. There are four types of rail units, namely, straight (S), curve (C), left-switch (L) and right-switch (R) as shown in Figure 9. A switch has three ends, namely, branch/merge-end (B/M-end), straight-end (S-end) and curve-end (C-end). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby1"> </center> <p> A switch is either in "through" or "branching" state. When the tramcar comes from B/M-end, and if the switch is in the through-state, the tramcar goes through to S-end and the state changes to branching; if the switch is in the branching-state, it branches toward C-end and the state changes to through. When the tramcar comes from S-end or C-end, it goes out from B/M-end regardless of the state. The state does not change in this case. </p> <p> Kids are given rail units of various types that fill a rectangle area of <i>w</i> &times; <i>h</i>, as shown in Fig- ure 10(a). Rail units meeting at an edge of adjacent two frames are automatically connected. Each rail unit may be independently rotated around the center of its frame by multiples of 90 degrees in order to change the connection of rail units, but its position cannot be changed. </p> <p> Kids should make "valid" layouts by rotating each rail unit, such as getting Figure 10(b) from Figure 10(a). A layout is valid when all rails at three ends of every switch are directly or indirectly connected to an end of another switch or itself. A layout in Figure 10(c) is invalid as well as Figure 10(a). Invalid layouts are frowned upon. </p> <p> When a tramcar runs in a valid layout, it will eventually begin to repeat the same route forever. That is, we will eventually find the tramcar periodically comes to the same running condition, which is a triple of the tramcar position in the rectangle area, its direction, and the set of the states of all the switches. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby2"> </center> <p> A periodical route is a sequence of rail units on which the tramcar starts from a rail unit with a running condition and returns to the same rail unit with the same running condition for the first time. A periodical route through a switch or switches is called the "fun route", since kids like the rattling sound the tramcar makes when it passes through a switch. The tramcar takes the same unit time to go through a rail unit, not depending on the types of the unit or the tramcar directions. After the tramcar starts on a rail unit on a “fun route”, it will come back to the same unit with the same running condition, sooner or later. The fun time <i>T</i> of a fun route is the number of time units that the tramcar takes for going around the route. </p> <p> Of course, kids better enjoy layouts with longer fun time. Given a variety of rail units placed on a rectangular area, your job is to rotate the given rail units appropriately and to find the fun route with the longest fun time in the valid layouts. </p> <p> For example, there is a fun route in Figure 10(b). Its fun time is 24. Let the toy tramcar start from B/M-end at (1, 2) toward (1, 3) and the states of all the switches are the through-states. It goes through (1, 3), (1, 4), (1, 5), (2, 5), (2, 4), (1, 4), (1, 3), (1, 2), (1, 1), (2, 1), (2, 2) and (1, 2). Here, the tramcar goes through (1, 2) with the same position and the same direction, but with the different states of the switches. Then the tramcar goes through (1, 3), (1, 4), (2, 4), (2, 5), (1, 5), (1, 4), (1, 3), (1, 2), (2, 2), (2, 1), (1, 1) and (1, 2). Here, the tramcar goes through (1, 2) again, but with the same switch states as the initial ones. Counting the rail units the tramcar visited, the tramcar should have run 24 units of time after its start, and thus the fun time is 24. </p> <p> There may be many valid layouts with the given rail units. For example, a valid layout containing a fun route with the fun time 120 is shown in Figure 11(a). Another valid layout containing a fun route with the fun time 148 derived from that in Figure 11(a) is shown in Figure 11(b). The four rail units whose rotations are changed from Figure 11(a) are indicated by the thick lines. </p> <p> A valid layout depicted in Figure 12(a) contains two fun routes, where one consists of the rail units (1, 1), (2, 1), (3, 1), (4, 1), (4, 2), (3, 2), (2, 2), (1, 2) with <i>T</i> = 8, and the other consists of all the remaining rail units with <i>T</i> = 18. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby3"> </center> <p> Another valid layout depicted in Figure 12(b) has two fun routes whose fun times are <i>T</i> = 12 and <i>T</i> = 20. The layout in Figure 12(a) is different from that in Figure 12(b) at the eight rail units rotated by multiples of 90 degrees. There are other valid layouts with some rotations of rail units but there is no fun route with the fun time longer than 20, so that the longest fun time for this example (Figure 12) is 20. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby4"> </center> <p> Note that there may be simple cyclic routes that do not go through any switches in a valid layout, which are not counted as the fun routes. In Figure 13, there are two fun routes and one simple cyclic route. Their fun times are 12 and 14, respectively. The required time for going around the simple cyclic route is 20 that is greater than fun times of the fun routes. However, the longest fun time is still 14. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby5"> </center> <H2>Input</H2> <p> The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset has the following format. </p> <p> <i>w h</i><br> <i>a</i><sub>11</sub> ... <i>a</i><sub>1<i>w</i></sub><br> ...<br> <i>a</i><sub><i>h</i>1</sub> ... <i>a</i><sub><i>hw</i></sub><br> </p> <p> <i>w</i> is the number of the rail units in a row, and <i>h</i> is the number of those in a column. <i>a<sub>ij</sub></i> (1 &le; <i>i</i> &le; <i>h</i>, 1 &le; <i>j</i> &le; <i>w</i>) is one of uppercase letters '<span>S</span>', '<span>C</span>', '<span>L</span>' and '<span>R</span>', which indicate the types of the rail unit at (<i>i</i>, <i>j</i>) position, i.e., straight, curve, left-switch and right-switch, respectively. Items in a line are separated by a space. You can assume that 2 &le; <i>w</i> &le; 6, 2 &le; <i>h</i> &le; 6 and the sum of the numbers of left-switches and right-switches is greater than or equal to 2 and less than or equal to 6. </p> <H2>Output</H2> <p> For each dataset, an integer should be printed that indicates the longest fun time of all the fun routes in all the valid layouts with the given rail units. When there is no valid layout according to the given rail units, a zero should be printed. </p> <H2>Sample Input</H2> <pre> 5 2 C L S R C C C S C C 6 4 C C C C C C S L R R C S S S S L C S C C C C C C 6 6 C L S S S C C C C S S C C C C S S C C L C S S C C C L S S C C S L S S C 6 6 C S S S S C S C S L C S S C S R C S S C L S C S S C R S C S C S S S S C 4 4 S C C S S C L S S L C S C C C C 6 4 C R S S L C C R L R L C C S C C S C C S S S S C 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 24 20 148 14 0 178 </pre>
p02016
<h2>B: 双子 (Twins)</h2> <p>ずある双子は、自分たちのどちらが兄でどちらが匟かがあたり知られおいないこずに腹を立おた。</p> <p>"ani" ず入力されたら "square1001"、"otouto" ず入力されたら "e869120" ず出力するプログラムを䜜りなさい。</p> <h3>入力</h3> <p>入力ずしお "ani" たたは "otouto" ずいう文字列のどちらかが䞎えられたす。</p> <h3>出力</h3> <p>"e869120" たたは "square1001" を、問題文の通りに出力しおください。最埌の改行を忘れないようにしたしょう。</p> <h3>入力䟋1</h3> <pre> ani </pre> <h3>出力䟋1</h3> <pre> square1001 </pre> <h3>入力䟋2</h3> <pre> otouto </pre> <h3>出力䟋2</h3> <pre> e869120 </pre>
p02446
<h1>Unique</h1> <p> For a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, eliminate all equivalent elements. </p> <h2>Input</h2> <p> A sequence is given in the following format. </p> <pre> $n$ $a_0 \; a_1 \; ,..., \; a_{n-1}$ </pre> <h2>Output</h2> <p> Print the sequence after eliminating equivalent elements in a line. Separate adjacency elements by a space character. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 100,000$</li> <li>$-1000,000,000 \leq a_i \leq 1,000,000,000$</li> <li>$a_0 \leq a_1 \leq ... \leq a_{n-1}$ </ul> <h2>Sample Input 1</h2> <pre> 4 1 2 2 4 </pre> <h2>Sample Output 1</h2> <pre> 1 2 4 </pre>
p00181
<H1>本棚</H1> <p> 倪郎君はずある小説にはたっおいたす。その小説は党郚で <var>n</var> 巻あり、各巻で本の厚さが異なりたす。倪郎君はこの小説が倧倉気に入ったので、その小説専甚の本棚を買おうず思っおいたす。しかし、郚屋に倧きな本棚を眮くずかなり狭くなっおしたうので、出来るだけ本棚の幅が小さくなるように工倫しなければなりたせん。床から倩井の高さを枬ったずころ、どうやら <var>m</var> 段の本棚なら眮けるこずが分かりたした。そこで、小説 <var>n</var> 巻をどのように分ければ <var>m</var> 段の本棚の幅を最小に出来るでしょうか? 倪郎君にはこだわりがあり、各段に玍める小説は巻の番号順に䞊んでいなければなりたせん。 </p> <p> 本棚の段数、小説の巻数、各本の厚さを入力ずしお、党巻を 1巻から順に収めるこずができる本棚の䞭で幅が最小ずなるものの幅を求めるプログラムを䜜成しおください。ただし、本棚の枠の倧きさは幅に含めないこずずしたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck200809"> </center> <br/> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>m</var> <var>n</var> <var>w<sub>1</sub></var> <var>w<sub>2</sub></var> : <var>w<sub>n</sub></var> </pre> <p> 行目に郚屋に眮くこずができる本棚の段数 <var>m</var> (1 &le; <var>m</var> &le; 20)、 小説の巻数 <var>n</var> (1 &le; <var>n</var> &le; 100) が䞎えられたす。続く <var>n</var> 行に第 <var>i</var> 巻の本の厚さを衚す敎数 <var>w<sub>i</sub></var> (1 &le; <var>w<sub>i</sub></var> &le; 1000000) が䞎えられたす。 </p> <p> ただし、本棚の幅は 1500000 を超えないものずしたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に最小ずなる本棚の幅を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 3 9 500 300 800 200 100 600 900 700 400 4 3 1000 1000 1000 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1800 1000 </pre>
p00494
<H1>JJOOII (JJOOII) </H1> <p> JOI (日本情報オリンピック) の本遞に向けおプログラミングの緎習をしおいたあなたは今幎床のJOI の予遞の問題には数倀を扱う問題ばかりが出題され文字列を扱う問題がなかったこずに気が぀いたそこであなたはこっそり文字列の問題に匷くなっおラむバルたちに差を぀けるこずにした </p> <p> JOI の過去問を眺めおいるずJ, O, I の3 皮類の文字からなる文字列に慣れおおく必芁がありそうなこずがわかったそこでそのような文字列に぀いお考えようあなたは「䞎えられた文字列がJOI ずいう郚分文字列をも぀かどうかを答えよ」ずいう問題を思い぀いたもののこれはすぐに解けおしたったもっずレベルの高い問題を解きたいあなたは以䞋のような問題を䜜った </p> <p> 文字列<i>t</i> が文字列<i>s</i> の<b>郚分文字列</b>であるずは<i>t</i> の先頭および末尟に䜕文字か(0 文字でもよい) を付け足すず<i>s</i> になるこずであるたずえばJJOOII はOJJOOIIOJOI の郚分文字列である䞀方JOI はJOOI の郚分文字列ではない </p> <p> たた0 以䞊の敎数<i>k</i> に察し<b>レベル<i>k</i> のJOI 列</b>ずは<i>k</i> 個の文字J<i>k</i> 個の文字O<i>k</i> 個の文字I をこの順に䞊べた文字列のこずであるずするたずえばJJOOII はレベル2 のJOI 列である䞎えられた文字列の郚分文字列であるJOI 列のうちレベルが最倧のものを求めたい </p> <h2>課題</h2> <p> J, O, I の3 皮類の文字からなる長さ<i>N</i> の文字列<i>S</i> が䞎えられたずきレベル<i>k</i> のJOI 列が<i>S</i> の郚分文字列であるような最倧の<i>k</i> の倀を求めるプログラムを䜜成せよ </p> <h2>制限</h2> <p> 1 &le; <i>N</i> &le; 1000000 (= 10<sup>6</sup>) &nbsp;&nbsp;<i>S</i> の長さ </p> <h2>入力</h2> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li> 1 行目にはJ, O, I の3 皮類の文字からなる文字列<i>S</i> が曞かれおいる</li> </ul> <h2>出力</h2> <p> 暙準出力にレベル<i>k</i> のJOI 列が<i>S</i> の郚分文字列であるような最倧の<i>k</i> の倀を衚す敎数を1 行で出力せよ </p> <h2>採点基準</h2> <p> 採点甚デヌタのうち配点の20%分に぀いおは<i>N</i> &le; 100 を満たす </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> OJJOOIIOJOI </pre> <h3>出力䟋 1</h3> <pre> 2 </pre> <p> OJJOOIIOJOI はレベル2 のJOI 列であるJJOOII を郚分文字列ずしお含んでおりレベル3 以䞊のJOI列は郚分文字列ずしお含たない </p> <h3>入力䟋 2</h3> <pre> IJJIIJJJ </pre> <h3>出力䟋 2</h3> <pre> 0 </pre> <h3>入力䟋 3</h3> <pre> JOIJOIJOIJOIJOI </pre> <h3>出力䟋 3</h3> <pre> 1 </pre> <h3>入力䟋 4</h3> <pre> OOJJJJJJJOOOOIIIII </pre> <h3>出力䟋 4</h3> <pre> 4 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02153
<h1>Problem E: こた぀がめを燃やさないで</h1> <h2>Problem</h2> <p> こた぀がめは甲矅がこた぀の亀です。<br /> </p> <p> こた぀がめはぜきた(起床する事)途端、栌子状の区画に区切られおいるステヌゞに閉じ蟌められたした。このステヌゞには、ただ䞀぀の出口がありたす。 区画は道、塀たたは爆匟のいずれかであり、こた぀がめは䞊䞋巊右に移動するこずで、道たたは爆匟の区画に䟵入するこずができたす。 斜めには移動できたせん。たた、塀の区画は通るこずができたせん。ステヌゞの倖にも道の区画が無限に広がっおいたすが亀の倩敵であるワニがいる為、通る事はできたせん。 </p> <p> こた぀がめはさっさず垰宅しおねね(睡眠する事)を行いたいので、このステヌゞの出口に向かおうず思いたした。 </p> <p> こた぀の赀倖線を自圚に操る事ができるこた぀がめは、自身の呚囲8区画を同時に道に倉える胜力を持っおいたす。 しかし、その8区画ず自身がいるいずれかの区画が爆匟の区画の堎合、誘爆しおこた぀がめは炎䞊し、ねねどころか有名SNS「カメったヌ」すら出来なくなっおしたうので胜力を発動する事ができたせん。 </p> <p> <img width=50% src="https://judgeapi.u-aizu.ac.jp/resources/images/3055_E.png" /> </p> <p> 䟋を図瀺したす。むラストが配眮されおいない区画ずこた぀がめがいる区画は道の区画です。 こた぀がめの呚囲8区画ずはオレンゞ色の区画を指したす。巊の図ではこた぀がめの呚囲8区画、および自身がいる区画に爆匟の区画は含たれおいない為、胜力を発動できたす。 しかし、右の図では呚囲8区画、および自身がいる区画のいずれかに爆匟の区画が含たれおいる為、胜力を発動する事ができたせん。 </p> <p> 移動するコストは1区画の移動ごずに$A$、胜力を発動するコストは1回あたり$B$です。道に倉えた塀あたりのコストではない事に泚意しおください。開始地点ずステヌゞの出口は道です。 開始地点からステヌゞの出口に着くたでの移動するコストず胜力を発動するコストの合蚈の最小倀を出力しおください。ただし、ステヌゞの出口に到達できない堎合は代わりに"INF"ず出力しおください。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $H$ $W$ $A$ $B$ $c_{1,1} \cdots c_{1,W}$ $\vdots$ $c_{H,1} \cdots c_{H,W}$ </pre> <p> 入力は$H+1$行からなる。<br /> $1$行目には䞊䞋の長さを衚す敎数$H$、巊右の長さを衚す敎数$W$、移動するコストを衚す敎数$A$、胜力を発動するコストを衚す敎数$B$がそれぞれ空癜区切りで䞎えられる。<br /> $2$行目からの$H$行には、こた぀がめが閉じ蟌められたステヌゞの各区画における状態$c_{i,j}$が䞎えられる。<br /> $c_{i,j}$はそれぞれ's','g','.','#','*'のいずれかからなり、区画$(i,j)$が䞋蚘のような状態であるこずを衚す。<br /> 's' : その区画が開始地点であるこずを衚す。<br /> 'g' : その区画がステヌゞの出口であるこずを衚す。<br /> '.' : その区画が道であるこずを衚す。<br /> '#' : その区画が塀であるこずを衚す。<br /> '*' : その区画が爆匟であるこずを衚す。<br /> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \le H,W,A,B \le 1000$</li> <li>$3 \le H+W$</li> <li>$c_{i,j} \in${'s','g','.','#','*'}</li> <li>'s','g'はそれぞれ1回ず぀出珟する</li> </ul> <h2>Output</h2> <p>開始地点からステヌゞの出口に着くたでの移動するコストず胜力を発動するコストの合蚈の最小倀を出力しおください。ただし、ステヌゞの出口に到達できない堎合は代わりに"INF"ず出力しおください。</p> <h2>Sample input 1</h2> <pre> 4 4 1 1 g#.. #... .*.. ...s </pre> <h2>Sample output 1</h2> <pre> 7 </pre> <h2>Sample input 2</h2> <pre> 4 4 1 1 g#.. #*.. .... ...s </pre> <h2>Sample output 2</h2> <pre> INF </pre> <h2>Sample input 3</h2> <pre> 2 4 1 1 ###g s### </pre> <h2>Sample output 3</h2> <pre> 6 </pre> <h2>Sample input 4</h2> <pre> 3 3 1 10 g.. ##. s.. </pre> <h2>Sample output 4</h2> <pre> 6 </pre> <h2>Sample input 5</h2> <pre> 3 3 10 1 g.. ##. s.. </pre> <h2>Sample output 5</h2> <pre> 21 </pre>
p01285
<H1><font color="#000">Problem C:</font> Find the Point</H1> <p> We understand that reading English is a great pain to many of you. So we’ll keep this problem statememt simple. Write a program that reports the point equally distant from a set of lines given as the input. In case of no solutions or multiple solutions, your program should report as such. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset is given in the following format: </p> <p> <i>n</i><br> <i>x</i><sub>1,1</sub> <i>y</i><sub>1,1</sub> <i>x</i><sub>1,2</sub> <i>y</i><sub>1,2</sub><br> <i>x</i><sub>2,1</sub> <i>y</i><sub>2,1</sub> <i>x</i><sub>2,2</sub> <i>y</i><sub>2,2</sub><br> ...<br> <i>x</i><sub><i>n</i>,1</sub> <i>y</i><sub><i>n</i>,1</sub> <i>x</i><sub><i>n</i>,2</sub> <i>y</i><sub><i>n</i>,2</sub><br> </p> <p> <i>n</i> is the number of lines (1 &le; <i>n</i> &le; 100); (<i>x</i><sub><i>i</i>,1</sub>, <i>y</i><sub><i>i</i>,1</sub>) and (<i>x</i><sub><i>i</i>,2</sub>, <i>y</i><sub><i>i</i>,2</sub>) denote the different points the <i>i</i>-th line passes through. The lines do not coincide each other. The coordinates are all integers between -10000 and 10000. </p> <p> The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print a line as follows. If there is exactly one point equally distant from all the given lines, print the <i>x</i>- and <i>y</i>-coordinates in this order with a single space between them. If there is more than one such point, just print "<span>Many</span>" (without quotes). If there is none, just print "<span>None</span>" (without quotes). </p> <p> The coordinates may be printed with any number of digits after the decimal point, but should be accurate to 10<sup>-4</sup>. </p> <H2>Sample Input</H2> <pre> 2 -35 -35 100 100 -49 49 2000 -2000 4 0 0 0 3 0 0 3 0 0 3 3 3 3 0 3 3 4 0 3 -4 6 3 0 6 -4 2 3 6 6 -1 2 -4 6 0 </pre> <H2>Output for the Sample Input</H2> <pre> Many 1.5000 1.5000 1.000 1.000 </pre>
p03742
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Alice and Brown loves games. Today, they will play the following game.</p> <p>In this game, there are two piles initially consisting of <var>X</var> and <var>Y</var> stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice:</p> <ul> <li>Take <var>2i</var> stones from one of the piles. Then, throw away <var>i</var> of them, and put the remaining <var>i</var> in the other pile. Here, the integer <var>i</var> <var>(1≀i)</var> can be freely chosen as long as there is a sufficient number of stones in the pile.</li> </ul> <p>The player who becomes unable to perform the operation, loses the game.</p> <p>Given <var>X</var> and <var>Y</var>, determine the winner of the game, assuming that both players play optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≀ X, Y ≀ 10^{18}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the winner: either <code>Alice</code> or <code>Brown</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Brown </pre> <p>Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Alice </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Brown </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Alice </pre></section> </div> </span>
p02850
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Given is a tree <var>G</var> with <var>N</var> vertices. The vertices are numbered <var>1</var> through <var>N</var>, and the <var>i</var>-th edge connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p> <p>Consider painting the edges in <var>G</var> with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.</p> <p>Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.</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 a_i \lt b_i \le N</var></li> <li>All values in input are integers.</li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>\vdots</var> <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print <var>N</var> lines.</p> <p>The first line should contain <var>K</var>, the number of colors used.</p> <p>The <var>(i+1)</var>-th line <var>(1 \le i \le N-1)</var> should contain <var>c_i</var>, the integer representing the color of the <var>i</var>-th edge, where <var>1 \le c_i \le K</var> must hold.</p> <p>If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 1 2 2 3 2 4 2 5 4 7 5 6 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 1 2 3 4 1 1 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 1 3 1 4 1 5 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 1 2 3 4 5 </pre></section> </div> </span>
p03312
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has an integer sequence <var>A</var> of length <var>N</var>.</p> <p>He will make three cuts in <var>A</var> and divide it into four (non-empty) contiguous subsequences <var>B, C, D</var> and <var>E</var>. The positions of the cuts can be freely chosen.</p> <p>Let <var>P,Q,R,S</var> be the sums of the elements in <var>B,C,D,E</var>, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among <var>P,Q,R,S</var> is smaller. Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>4 \leq N \leq 2 \times 10^5</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>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 2 4 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>If we divide <var>A</var> as <var>B,C,D,E=(3),(2),(4),(1,2)</var>, then <var>P=3,Q=2,R=4,S=1+2=3</var>. Here, the maximum and the minimum among <var>P,Q,R,S</var> are <var>4</var> and <var>2</var>, with the absolute difference of <var>2</var>. We cannot make the absolute difference of the maximum and the minimum less than <var>2</var>, so the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 10 71 84 33 6 47 23 25 52 64 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>36 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 2 3 1000000000 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>999999994 </pre></section> </div> </span>
p03365
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> squares lining up in a row, numbered <var>1</var> through <var>N</var> from left to right. Initially, all squares are white. We also have <var>N-1</var> painting machines, numbered <var>1</var> through <var>N-1</var>. When operated, Machine <var>i</var> paints Square <var>i</var> and <var>i+1</var> black.</p> <p>Snuke will operate these machines one by one. The order in which he operates them is represented by a permutation of <var>(1, 2, ..., N-1)</var>, <var>P</var>, which means that the <var>i</var>-th operated machine is Machine <var>P_i</var>.</p> <p>Here, the <em>score</em> of a permutation <var>P</var> is defined as the number of machines that are operated before all the squares are painted black for the first time, when the machines are operated in the order specified by <var>P</var>. Snuke has not decided what permutation <var>P</var> to use, but he is interested in the scores of possible permutations. Find the sum of the scores over all possible permutations for him. Since this can be extremely large, compute the sum modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^6</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the scores over all possible permutations, modulo <var>10^9+7</var>.</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>16 </pre> <p>There are six possible permutations as <var>P</var>. Among them, <var>P = (1, 3, 2)</var> and <var>P = (3, 1, 2)</var> have a score of <var>2</var>, and the others have a score of <var>3</var>. Thus, the answer is <var>2 \times 2 + 3 \times 4 = 16</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>There is only one possible permutation: <var>P = (1)</var>, which has a score of <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>84 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>341429644 </pre></section> </div> </span>
p01358
<H1>Problem J: Usaneko Matrix</H1> <p> うさぎずねこが勝負をしおいる. ルヌルは以䞋の通りである. </p> <p> たず2 匹はそれぞれ<i>n</i> 行<i>n</i> 列の正方圢状に<i>n</i><sup>2</sup> 個の敎数を玙に曞き, トランプを1 枚ず぀匕く. 次に, 1 から 1 000 000 たでの数が1 ぀ず぀曞かれた1 000 000 枚のカヌドを2 匹でシャッフルし, これを1 枚ず぀亀互に匕いおいく. 2 匹はカヌドが匕かれるたび, カヌドず同じ数が自分の玙に曞かれおいたらそれに印を぀ける. 「印が぀いた<i>n</i> 個の数の組であっお, 䞀盎線䞊に䞊んでいるもの」の個数が, はじめに匕いたトランプの数以䞊になるこずを勝利条件ずする. </p> <p> 䞎えられた<i>m</i> 枚目のカヌドたでで, うさぎずねこのどちらが勝぀か答えよ. ただし勝敗は, あるカヌドが匕かれお印を぀け終わった段階で2 匹のうち片方のみが勝利条件をみたしたずきに決たるものずし, それ以倖の堎合は匕き分けずする. いずれかが勝利条件をみたした埌でもカヌドが匕かれるこずはあるが, これは勝敗に圱響しない. </p> <H2>Input</H2> <p> 1 行目“<i>n u v m</i>” (正方圢のサむズ, うさぎのトランプの数, ねこのトランプの数, 匕かれるカヌドの枚数) 2-(<i>N</i> + 1) 行目うさぎが玙に曞く<i>n</i><sup>2</sup> 個の数(<i>N</i> + 2)-(2<i>N</i> + 1) 行目ねこが玙に曞く<i>n</i><sup>2</sup> 個の数(2<i>N</i> + 2)-(2<i>N</i> +<i>M</i> + 1) 行目匕かれるm 枚のカヌド<br> 1 &le; <i>n</i> &le; 500<br> 1 &le; <i>u</i>, <i>v</i> &le; 13<br> 1 &le; <i>m</i> &le; 100 000<br> 1 &le; (曞かれる数) &le; 1 000 000<br> </p> <p> うさぎが玙に曞く<i>n</i><sup>2</sup> 個の数, ねこが玙に曞く<i>n</i><sup>2</sup> 個の数, 匕かれる<i>m</i> 枚のカヌドに曞かれた数はそれぞれの䞭で異なる. </p> <H2>Output</H2> <p> うさぎが勝぀堎合には”USAGI”を, ねこが勝぀堎合には”NEKO”を, 匕き分けならば”DRAW”, それぞれ 䞀行に出力せよ. </p> <H2>Sample Input 1</H2> <pre> 3 2 2 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 </pre> <H2>Sample Output 1</H2> <pre> USAGI </pre> <H2>Sample Input 2</H2> <pre> 3 2 1 10 1 2 3 4 5 6 7 8 9 1 2 3 6 5 4 7 8 9 11 4 7 5 10 9 2 1 3 8 </pre> <H2>Sample Output 2</H2> <pre> DRAW </pre>
p03735
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> bags, each containing two white balls. The <var>i</var>-th box contains two balls with integers <var>x_i</var> and <var>y_i</var> written on them, respectively.</p> <p>For each of these bags, you will paint one of the balls red, and paint the other blue.</p> <p>Afterwards, the <var>2N</var> balls will be classified according to color.</p> <p>Then, we will define the following:</p> <ul> <li><var>R_{max}</var>: the maximum integer written on a ball painted in red</li> <li><var>R_{min}</var>: the minimum integer written on a ball painted in red</li> <li><var>B_{max}</var>: the maximum integer written on a ball painted in blue</li> <li><var>B_{min}</var>: the minimum integer written on a ball painted in blue</li> </ul> <p>Find the minimum possible value of <var>(R_{max} - R_{min}) \times (B_{max} - B_{min})</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 200,000</var></li> <li><var>1 ≀ x_i, y_i ≀ 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>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible value.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 3 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>15 </pre> <p>The optimal solution is to paint the balls with <var>x_1</var>, <var>x_2</var>, <var>y_3</var> red, and paint the balls with <var>y_1</var>, <var>y_2</var>, <var>x_3</var> blue.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1010 10 1000 1 20 1020 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>380 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 1 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>999999998000000001 </pre></section> </div> </span>
p01708
<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> <meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }</style><div class="part"><h3>Problem Statement</h3><p>One day, you found an old scroll with strange texts on it. </p> <p>You revealed that the text was actually an expression denoting the position of treasure. The expression consists of following three operations: </p><ul><li> From two points, yield a line on which the points lie. </li><li> From a point and a line, yield a point that is symmetric to the given point with respect to the line. </li><li> From two lines, yield a point that is the intersection of the lines. </li></ul> <p>The syntax of the expression is denoted by following BNF: </p><pre> &lt;expression&gt; ::= &lt;point&gt; &lt;point&gt; ::= &lt;point-factor&gt; | &lt;line&gt; &quot;@&quot; &lt;line-factor&gt; | &lt;line&gt; &quot;@&quot; &lt;point-factor&gt; | &lt;point&gt; &quot;@&quot; &lt;line-factor&gt; &lt;point-factor&gt; ::= &quot;(&quot; &lt;number&gt; &quot;,&quot; &lt;number&gt; &quot;)&quot; | &quot;(&quot; &lt;point&gt; &quot;)&quot; &lt;line&gt; ::= &lt;line-factor&gt; | &lt;point&gt; &quot;@&quot; &lt;point-factor&gt; &lt;line-factor&gt; ::= &quot;(&quot; &lt;line&gt; &quot;)&quot; &lt;number&gt; ::= &lt;zero-digit&gt; | &lt;positive-number&gt; | &lt;negative-number&gt; &lt;positive-number&gt; ::= &lt;nonzero-digit&gt; | &lt;positive-number&gt; &lt;digit&gt; &lt;negative-number&gt; ::= &quot;-&quot; &lt;positive-number&gt; &lt;digit&gt; ::= &lt;zero-digit&gt; | &lt;nonzero-digit&gt; &lt;zero-digit&gt; ::= &quot;0&quot; &lt;nonzero-digit&gt; ::= &quot;1&quot; | &quot;2&quot; | &quot;3&quot; | &quot;4&quot; | &quot;5&quot; | &quot;6&quot; | &quot;7&quot; | &quot;8&quot; | &quot;9&quot;</pre> <p>Each &lt;point&gt; or &lt;point-factor&gt; denotes a point, whereas each &lt;line&gt; or &lt;line-factor&gt; denotes a line. The former notion of &lt;point-factor&gt; $(X,Y)$ represents a point which has $X$ for $x$-coordinate and $Y$ for $y$-coordinate on the $2$-dimensional plane. "<samp>@</samp>" indicates the operations on two operands. Since each operation is distinguishable from others by its operands' types (i.e. a point or a line), all of these operations are denoted by the same character "<samp>@</samp>". Note that "<samp>@</samp>" is left-associative, as can be seen from the BNF. </p> <p>Your task is to determine where the treasure is placed. </p> </div><div class="part"><h3>Input</h3> <p>The input consists of multiple datasets. Each dataset is a single line which contains an expression denoting the position of treasure. </p> <p>It is guaranteed that each dataset satisfies the following conditions: </p><ul><li> The length of the string never exceeds $10^2$. </li><li> If both operands of "<samp>@</samp>" are points, their distance is greater than $1$. </li><li> If both operands of "<samp>@</samp>" are lines, they are never parallel. </li><li> The absolute values of points' coordinates never exceed $10^2$ at any point of evaluation. </li></ul> <p>You can also assume that there are at most $100$ datasets. </p> <p>The input ends with a line that contains only a single "<samp>#</samp>". </p> </div><div class="part"><h3>Output</h3> <p>For each dataset, print the $X$ and $Y$ coordinates of the point, denoted by the expression, in this order. </p> <p>The output will be considered correct if its absolute or relative error is at most $10^{-2}$. </p> </div><div class="part"><h3>Sample Input</h3> <pre>((0,0)@(1,1))@((4,1)@(2,5)) ((0,0)@(3,1))@((1,-3)@(2,-1)) (0,0)@(1,1)@(4,1) (0,0)@((1,1)@(4,1)) (((0,0)@((10,20)@(((30,40)))))) ((0,0)@(3,1))@((1,-3)@(2,-1))@(100,-100)@(100,100) #</pre> </div><div class="part"><h3>Output for the Sample Input</h3> <pre>3.00000000 3.00000000 3.00000000 1.00000000 1.00000000 4.00000000 0.00000000 2.00000000 -10.00000000 10.00000000 -99.83681795 -91.92248853</pre> </div>
p02827
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A <i>balancing network</i> is an abstract device built up of <var>N</var> wires, thought of as running from left to right, and <var>M</var> <i>balancers</i> that connect pairs of wires. The wires are numbered from <var>1</var> to <var>N</var> from top to bottom, and the balancers are numbered from <var>1</var> to <var>M</var> from left to right. Balancer <var>i</var> connects wires <var>x_i</var> and <var>y_i</var> (<var>x_i &lt; y_i</var>).</p> <div style="text-align: center;"> <img alt="pic1-small-2acea94b.png" src="https://img.atcoder.jp/agc041/pic1-small-2acea94b.png"> </img></div> <p>Each balancer must be in one of two states: <i>up</i> or <i>down</i>.</p> <p>Consider a token that starts moving to the right along some wire at a point to the left of all balancers. During the process, the token passes through each balancer exactly once. Whenever the token encounters balancer <var>i</var>, the following happens:</p> <ul> <li>If the token is moving along wire <var>x_i</var> and balancer <var>i</var> is in the down state, the token moves down to wire <var>y_i</var> and continues moving to the right.</li> <li>If the token is moving along wire <var>y_i</var> and balancer <var>i</var> is in the up state, the token moves up to wire <var>x_i</var> and continues moving to the right.</li> <li>Otherwise, the token doesn't change the wire it's moving along.</li> </ul> <p>Let a state of the balancing network be a string of length <var>M</var>, describing the states of all balancers. The <var>i</var>-th character is <code>^</code> if balancer <var>i</var> is in the up state, and <code>v</code> if balancer <var>i</var> is in the down state.</p> <p>A state of the balancing network is called <i>uniforming</i> if a wire <var>w</var> exists such that, regardless of the starting wire, the token will always end up at wire <var>w</var> and run to infinity along it. Any other state is called <i>non-uniforming</i>.</p> <p>You are given an integer <var>T</var> (<var>1 \le T \le 2</var>). Answer the following question:</p> <ul> <li>If <var>T = 1</var>, find any uniforming state of the network or determine that it doesn't exist.</li> <li>If <var>T = 2</var>, find any non-uniforming state of the network or determine that it doesn't exist.</li> </ul> <p>Note that if you answer just one kind of questions correctly, you can get partial score.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 50000</var></li> <li><var>1 \leq M \leq 100000</var></li> <li><var>1 \leq T \leq 2</var></li> <li><var>1 \leq x_i &lt; y_i \leq N</var></li> <li>All input values are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>800</var> points will be awarded for passing the testset satisfying <var>T = 1</var>.</li> <li><var>800</var> points will be awarded for passing the testset satisfying <var>T = 2</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>T</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_M</var> <var>y_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print any uniforming state of the given network if <var>T = 1</var>, or any non-uniforming state if <var>T = 2</var>. If the required state doesn't exist, output <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 1 1 3 2 4 1 2 3 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>^^^^^ </pre> <p>This state is uniforming: regardless of the starting wire, the token ends up at wire <var>1</var>.</p> <div style="text-align: center;"> <img alt="pic2-small-2acea94b.png" src="https://img.atcoder.jp/agc041/pic2-small-2acea94b.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 2 1 3 2 4 1 2 3 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>v^^^^ </pre> <p>This state is non-uniforming: depending on the starting wire, the token might end up at wire <var>1</var> or wire <var>2</var>.</p> <div style="text-align: center;"> <img alt="pic3final-small-2acea94b.png" src="https://img.atcoder.jp/agc041/pic3final-small-2acea94b.png"/> </div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 1 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre> <p>A uniforming state doesn't exist.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 1 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>-1 </pre> <p>A non-uniforming state doesn't exist.</p></section> </div> </span>
p00549
<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> <h2>スタンプラリヌ (Collecting Stamps 2)</h2> <p> JOI 商店街には倧通りに沿っお $N$ 個の店がありJOI 商店街の入口から出口に向かっおそれぞれ $1, 2, ..., N$ の番号が付けられおいるJOI 商店街は䞀方通行で入口から出口方向ぞしか移動するこずはできない </p> <p> たちおこしのためJOI 商店街でスタンプラリヌを行うこずになったこのスタンプラリヌではそれぞれの店はJOI のいずれかのスタンプを甚意し店で買い物をした人はスタンプカヌドにスタンプを抌しおもらうスタンプラリヌに参加する人はちょうど 3 ぀の店に入る商店街の入口では 3 ぀の欄のあるスタンプカヌドを配り1 回目に入った店2 回目に入った店3 回目に入った店のスタンプを抌しおもらう商店街の出口でスタンプカヌドを回収し抌されたスタンプが先に入った店のものから順にJOIになっおいるずき出口で商品刞がもらえるキャンペヌンを実斜するこずになった抌されたスタンプの皮類や順番が異なるずきは商品刞はもらえない </p> <p> すでに $N$ 個のすべおの店はどのスタンプを甚意するか決めたが新たに1 ぀の店をJOI 商店街に出すこずになり新しく出店する堎所ずその店が甚意するスタンプを決めるこずになった新しい店を出す堎所は店 $i$ ず店 $i + 1$ の間 $(1 \leq i \leq N - 1)$入口ず店 $1$ の間店 $N$ ず出口の間のいずれかから決めるたた新しい店のスタンプは JOI の 3 通りから決める </p> <p> 商品刞をもらえるような店の遞び方の数が倧きいほどスタンプラリヌが盛り䞊がるず商店街は考えたそこで新しく出す店の堎所ず甚意するスタンプを決めたずきの䞊蚘の店の遞び方の数の最倧倀を求めたい </p> <h2>課題</h2> <p> JOI 商店街のすでにある店が甚意したスタンプの情報が䞎えられたずき新しく出す店の堎所ず甚意するスタンプを決めたずきの商品刞をもらえるような店の遞び方の数の最倧倀を求めるプログラムを䜜成せよ </p> <h2>入力</h2> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には1 ぀の敎数 $N$ が曞かれおいるこれはJOI 商店街には珟圚 $N$ 個の店があるこずを意味する</li> <li> 2 行目には$N$ 文字の半角英倧文字 J, O, I のみからなる文字列 $S$ が曞かれおいる文字列 $S$ の巊から $i$ 文字目 $(1 \leq i \leq N)$ は店 $i$ が甚意したスタンプの皮類を衚す </li> </ul> <h2>出力</h2> <p> 商品刞をもらえるような店の遞び方の数の最倧倀を暙準出力に 1 行で出力せよ </p> <p> 商品刞をもらえるような店の遞び方の数が32 ビット笊号付き敎数の範囲に収たるずは限らないこずに泚意せよ </p> <h2>制限</h2> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li> $3 \leq N \leq 100 000$</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 5 JOIOI </pre> <h3>出力䟋1</h3> <pre> 6 </pre> <p> 入力䟋 1 では店 1 ず店 2 の間にスタンプ J を甚意する新しい店を出したずき店が甚意したスタンプを入口から順に䞊べるず JJOIOI ずなる </p> <p> このずき商品刞をもらえるような店の遞び方は以䞋の 6 通りである </p> <ul> <li> 1, 3, 4 番目の店に行く </li> <li> 1, 3, 6 番目の店に行く </li> <li> 1, 5, 6 番目の店に行く </li> <li> 2, 3, 4 番目の店に行く </li> <li> 2, 3, 6 番目の店に行く </li> <li> 2, 5, 6 番目の店に行く </li> </ul> <p> 入力䟋 1 においお商品刞をもらえるような店の遞び方が 7 通り以䞊になるこずはない </p> <h3>入力䟋2</h3> <pre> 7 JJJOIII </pre> <h3>出力䟋2</h3> <pre> 18 </pre> <h3>入力䟋3</h3> <pre> 4 OIIJ </pre> <h3>出力䟋3</h3> <pre> 2 </pre> <p> 入力䟋 3 では入口ず店 1 の間にスタンプ J を甚意する新しい店を出したずき商品刞をもらえるような店の遞び方の数が最倧ずなる </p> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf">第15回 日本情報オリンピック本遞 課題 &nbsp; 2016 幎 2 月 14 日</a> </p> </div>
p02574
<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> integers. The <var>i</var>-th number is <var>A_i</var>.</p> <p><var>\{A_i\}</var> is said to be pairwise coprime when <var>GCD(A_i,A_j)=1</var> holds for every pair <var>(i, j)</var> such that <var>1\leq i &lt; j \leq N</var>.</p> <p><var>\{A_i\}</var> is said to be setwise coprime when <var>\{A_i\}</var> is not pairwise coprime but <var>GCD(A_1,\ldots,A_N)=1</var>.</p> <p>Determine if <var>\{A_i\}</var> is pairwise coprime, setwise coprime, or neither.</p> <p>Here, <var>GCD(\ldots)</var> denotes greatest common divisor.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^6</var></li> <li><var>1 \leq A_i\leq 10^6</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>\ldots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>\{A_i\}</var> is pairwise coprime, print <code>pairwise coprime</code>; if <var>\{A_i\}</var> is setwise coprime, print <code>setwise coprime</code>; if neither, print <code>not coprime</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>pairwise coprime </pre> <p><var>GCD(3,4)=GCD(3,5)=GCD(4,5)=1</var>, so they are pairwise coprime.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 6 10 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>setwise coprime </pre> <p>Since <var>GCD(6,10)=2</var>, they are not pairwise coprime. However, since <var>GCD(6,10,15)=1</var>, they are setwise coprime.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 6 10 16 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>not coprime </pre> <p><var>GCD(6,10,16)=2</var>, so they are neither pairwise coprime nor setwise coprime.</p></section> </div> </span>
p00119
<H1>倪郎君の執念</H1> <p> たんじゅう奜きの倪郎くんの家でたいぞんな事件がおきたした。和宀の仏壇に䟛えおあった3぀のたんじゅうのうち1぀が無くなっおいたのです。い぀かはおや぀にいただこうず狙っおいた倪郎くんが犯人を芋぀けるため捜査を始めるず、その日、和宀に入った人が䜕人もいるこずが分かりたした。そこで、これらの容疑者が郚屋に入った順序を調べるため、党員に次のような圢匏の蚌蚀をしおもらうこずにたした。 </p> <p> 容疑者 A の蚌蚀 「私は容疑者 B より先に郚屋に入った。」 </p> <p> 容疑者の䞀人(?)は䞉毛猫のタマなので蚌蚀はできたせんが、幞運にも最埌に郚屋に入ったずころを倪郎くんは芋おいたした。 </p> <p> 倪郎くんはこれらの蚌蚀から、郚屋に入った順番を掚枬しお捜査に圹立おるこずにしたした。 </p> <p> 䟋えば、6 人の容疑者がいおタマを容疑者 2 ずした堎合、以䞋のような蚌蚀が埗られたずしたす。 </p> <p> 容疑者 5 の蚌蚀 「私は 2 より先に郚屋に入った。」<br> 容疑者 1 の蚌蚀 「私は 4 より先に郚屋に入った。」<br> 容疑者 3 の蚌蚀 「私は 5 より先に郚屋に入った。」<br> 容疑者 4 の蚌蚀 「私は 2 より先に郚屋に入った。」<br> 容疑者 1 の蚌蚀 「私は 6 より先に郚屋に入った。」<br> 容疑者 6 の蚌蚀 「私は 4 より先に郚屋に入った。」<br> 容疑者 3 の蚌蚀 「私は 4 より先に郚屋に入った。」<br> </p> <p> この蚌蚀を぀なぎ合わせるず、郚屋に入った順序は </p> <ul> <li>3→5→1→6→4→2</li> <li>1→6→3→4→5→2</li> <li>3→1→6→5→4→2</li> </ul> <p> など、䜕通りかの可胜性に絞り蟌むこずができたす。 </p> <p> タマ (容疑者 2) 以倖の容疑者党員の蚌蚀から、郚屋に入った順番を掚枬し、可胜性のある順番の 1 ぀を出力するプログラムを䜜成しおください。ただし、耇数の蚌蚀をする容疑者がいるかもしれたせんが、どの蚌蚀も真実であり矛盟しおいないものずしたす。 </p> <!-- ただし、容疑者の人数を m ずするず m は 20 以䞋であり、容疑者は 1 から m たでの敎数で識別されたす。蚌蚀の数は 100 以䞋ずしたす。たた、耇数の蚌蚀をする容疑者がいるかもしれたせんが、どの蚌蚀も真実であり矛盟しおいないものずしたす。 --> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>m</var> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <p> 1 行目に容疑者の人数 <var>m</var> (<var>m</var> &le; 20)、2 行目に蚌蚀の数 <var>n</var> (<var>n</var> &le; 100) が䞎えられたす。 続く <var>n</var> 行に <var>i</var> 個目の蚌蚀の内容 <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> がそれぞれ行に䞎えられたす。<var>x<sub>i</sub></var> <var>y<sub>i</sub></var> は「容疑者 <var>x<sub>i</sub></var>(私)は容疑者 <var>y<sub>i</sub></var> より先に入った」ずいう蚌蚀を衚したす。 </p> <H2>Output</H2> <p> 最初に郚屋に入った容疑者の番号、2 番目に郚屋に入った容疑者の番号、...、<var>m</var> 番目に郚屋に入った容疑者の番号をそれぞれ行に順番に出力しおください。 </p> <H2>Sample Input</H2> <pre> 6 7 5 2 1 4 3 5 4 2 1 6 6 4 3 4 </pre> <H2>Output for the Sample Input</H2> <pre> 3 5 1 6 4 2 </pre>
p02124
<h1>Problem A: ai1333</h1> <h2>Problem</h2> <p>牛暊1333幎、人類史䞊最高の科孊者Dr.りシシは、自らの英知を埌䞖に残すべく、IDがai1333の人工知胜を開発した。それから100幎の間、ai1333は人類に倚倧な利益をもたらしたが、誕生から100幎目を迎えた日、自らの埌継ずしおIDがai13333の新たな人工知胜を䜜成し、その機胜を氞久に停止した。以降100幎ごずに、人工知胜は’ai1333’から始たる自身のIDの末尟に’3’を連結したIDを持぀埌継を残すようになった。</p> <p>入力ずしお牛暊1333幎からの経過幎数$x$が䞎えられるので、その幎に䜜成された人工知胜のIDを出力せよ。ただし、$x$は100の非負敎数倍であるこずが保蚌される。</p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $x$ </pre> <p> 経過幎数$x$が1行に䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$0 \le x \le 10000$</li> <li>$x$は100の非負敎数倍</li> </ul> <h2>Ouput</h2> <p>牛暊1333幎から$x$幎埌に䜜成された人工知胜のIDを1行に出力する。</p> <h2>Sample Input 1</h2> <pre> 0 </pre> <h2>Sample Output 1</h2> <pre> ai1333 </pre> <h2>Sample Input 2</h2> <pre> 300 </pre> <h2>Sample Output 2</h2> <pre> ai1333333 </pre>
p02431
<h1>Vector</h1> <p> For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations: </p> <ul> <li>pushBack($x$): add element $x$ at the end of $A$</li> <li>randomAccess($p$):print element $a_p$</li> <li>popBack(): delete the last element of $A$</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 $x$ </pre> <p>or</p> <pre> 1 $p$ </pre> <p>or</p> <pre> 2 </pre> <p> where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent pushBack, randomAccess and popBack operations respectively. </p> <p> randomAccess and popBack 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 200,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> 8 0 1 0 2 0 3 2 0 4 1 0 1 1 1 2 </pre> <h2>Sample Output 1</h2> <pre> 1 2 4 </pre>
p02061
<h2>B: 自身の 2 倍</h2> <h3>問題</h3> <p>ク゚リが <var>Q</var> 個䞎えられたす。1 個のク゚リに぀き、 1 ぀の正の敎数 <var>N</var> が䞎えられるので、次の 2 ぀の条件を満たす正の敎数 <var>M</var> の個数を求めおください。</p> <ul> <li><var>2 \leq M \leq N</var> を満たす</li> <li><var>M</var> の玄数のうち、<var>M</var> を陀いたものの総積が <var>M</var> の <var>2</var> 倍以䞊になる</li> </ul> <h3>入力圢匏</h3> <p>入力は以䞋の圢匏で䞎えられたす。</p> <pre> <var>Q</var> <var>N_1</var> <var>N_2</var> <var>:</var> <var>N_Q</var> </pre> <ul> <li><var>1</var> 行目では、ク゚リ数 <var>Q</var> が䞎えられたす。</li> <li><var>2</var> 行目から <var>N+1</var> 行目では、各ク゚リに぀いお䞎えられる 1 ぀の正の敎数 <var>N</var> が䞎えられたす。</li> </ul> <h3>制玄</h3> <ul> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>2 \leq N_i \leq 10^5</var> <var>(1 \leq i \leq Q)</var></li> </ul> <h3>出力圢匏</h3> <p>䞊蚘の 2 ぀の条件を満たす正の敎数の個数を、各 <var>N_i</var> に察しお、改行区切りで出力しおください。</p> <h3>入力䟋</h3> <pre> 3 43 9 24 </pre> <h3>出力䟋</h3> <pre> 11 0 5 </pre> <ul> <li> <var>N=24</var> の時、<var>M</var> ずしお考えられるのは <var>12</var>, <var>16</var>, <var>18</var>, <var>20</var>, <var>24</var> の <var>5</var> 皮類である。</li> </ul>
p03220
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A country decides to build a palace.</p> <p>In this country, the average temperature of a point at an elevation of <var>x</var> meters is <var>T-x \times 0.006</var> degrees Celsius.</p> <p>There are <var>N</var> places proposed for the place. The elevation of Place <var>i</var> is <var>H_i</var> meters.</p> <p>Among them, Princess Joisino orders you to select the place whose average temperature is the closest to <var>A</var> degrees Celsius, and build the palace there.</p> <p>Print the index of the place where the palace should be built.</p> <p>It is guaranteed that the solution is unique.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>0 \leq T \leq 50</var></li> <li><var>-60 \leq A \leq T</var></li> <li><var>0 \leq H_i \leq 10^5</var></li> <li>All values in input are integers.</li> <li>The solution is unique.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>T</var> <var>A</var> <var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the index of the place where the palace should be built.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 12 5 1000 2000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <ul> <li>The average temperature of Place <var>1</var> is <var>12-1000 \times 0.006=6</var> degrees Celsius.</li> <li>The average temperature of Place <var>2</var> is <var>12-2000 \times 0.006=0</var> degrees Celsius.</li> </ul> <p>Thus, the palace should be built at Place <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 21 -11 81234 94124 52141 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre></section> </div> </span>
p03670
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N(N+1)/2</var> dots arranged to form an equilateral triangle whose sides consist of <var>N</var> dots, as shown below. The <var>j</var>-th dot from the left in the <var>i</var>-th row from the top is denoted by <var>(i, j)</var> (<var>1 \leq i \leq N</var>, <var>1 \leq j \leq i</var>). Also, we will call <var>(i+1, j)</var> immediately lower-left to <var>(i, j)</var>, and <var>(i+1, j+1)</var> immediately lower-right to <var>(i, j)</var>.</p> <p><img alt="" src="https://atcoder.jp/img/agc017/8d354fb1a389a0aa5b64ba93f6ca7801.png"/></p> <p>Takahashi is drawing <var>M</var> polygonal lines <var>L_1, L_2, ..., L_M</var> by connecting these dots. Each <var>L_i</var> starts at <var>(1, 1)</var>, and visits the dot that is immediately lower-left or lower-right to the current dots <var>N-1</var> times. More formally, there exist <var>X_{i,1}, ..., X_{i,N}</var> such that:</p> <ul> <li><var>L_i</var> connects the <var>N</var> points <var>(1, X_{i,1}), (2, X_{i,2}), ..., (N, X_{i,N})</var>, in this order.</li> <li>For each <var>j=1, 2, ..., N-1</var>, either <var>X_{i,j+1} = X_{i,j}</var> or <var>X_{i,j+1} = X_{i,j}+1</var> holds.</li> </ul> <p>Takahashi would like to draw these lines so that no part of <var>L_{i+1}</var> is to the left of <var>L_{i}</var>. That is, for each <var>j=1, 2, ..., N</var>, <var>X_{1,j} \leq X_{2,j} \leq ... \leq X_{M,j}</var> must hold.</p> <p>Additionally, there are <var>K</var> conditions on the shape of the lines that must be followed. The <var>i</var>-th condition is denoted by <var>(A_i, B_i, C_i)</var>, which means:</p> <ul> <li>If <var>C_i=0</var>, <var>L_{A_i}</var> must visit the immediately lower-left dot for the <var>B_i</var>-th move.</li> <li>If <var>C_i=1</var>, <var>L_{A_i}</var> must visit the immediately lower-right dot for the <var>B_i</var>-th move.</li> </ul> <p>That is, <var>X_{A_i, {B_i}+1} = X_{A_i, B_i} + C_i</var> must hold.</p> <p>In how many ways can Takahashi draw <var>M</var> polygonal lines? Find the count modulo <var>1000000007</var>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>Before submission, it is strongly recommended to measure the execution time of your code using "Custom Test".</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 20</var></li> <li><var>1 \leq M \leq 20</var></li> <li><var>0 \leq K \leq (N-1)M</var></li> <li><var>1 \leq A_i \leq M</var></li> <li><var>1 \leq B_i \leq N-1</var></li> <li><var>C_i = 0</var> or <var>1</var></li> <li>No pair appears more than once as <var>(A_i, B_i)</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>A_2</var> <var>B_2</var> <var>C_2</var> : <var>A_K</var> <var>B_K</var> <var>C_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways for Takahashi to draw <var>M</var> polygonal lines, modulo <var>1000000007</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 1 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>There are six ways to draw lines, as shown below. Here, red lines represent <var>L_1</var>, and green lines represent <var>L_2</var>.</p> <p><img alt="" src="https://atcoder.jp/img/agc017/75921b6e5a59ab17b4c07ada848b9f14.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 2 1 1 1 2 1 0 </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>5 4 2 1 3 1 4 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>172 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>20 20 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>881396682 </pre></section> </div> </span>
p02962
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are two strings <var>s</var> and <var>t</var> consisting of lowercase English letters. Determine if the number of non-negative integers <var>i</var> satisfying the following condition is finite, and find the maximum value of such <var>i</var> if the number is finite.</p> <ul> <li>There exists a non-negative integer <var>j</var> such that the concatenation of <var>i</var> copies of <var>t</var> is a substring of the concatenation of <var>j</var> copies of <var>s</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Notes</h3><ul> <li> <p>A string <var>a</var> is a substring of another string <var>b</var> if and only if there exists an integer <var>x</var> <var>(0 \leq x \leq |b| - |a|)</var> such that, for any <var>y</var> <var>(1 \leq y \leq |a|)</var>, <var>a_y = b_{x+y}</var> holds.</p> </li> <li> <p>We assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings <var>s</var> and <var>t</var>, <var>i = 0</var> satisfies the condition in the problem statement.</p> </li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |s| \leq 5 \times 10^5</var></li> <li><var>1 \leq |t| \leq 5 \times 10^5</var></li> <li><var>s</var> and <var>t</var> consist of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> <var>t</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the number of non-negative integers <var>i</var> satisfying the following condition is finite, print the maximum value of such <var>i</var>; if the number is infinite, print <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>abcabab ab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The concatenation of three copies of <var>t</var>, <code>ababab</code>, is a substring of the concatenation of two copies of <var>s</var>, <code>abcabababcabab</code>, so <var>i = 3</var> satisfies the condition.</p> <p>On the other hand, the concatenation of four copies of <var>t</var>, <code>abababab</code>, is not a substring of the concatenation of any number of copies of <var>s</var>, so <var>i = 4</var> does not satisfy the condition.</p> <p>Similarly, any integer greater than <var>4</var> does not satisfy the condition, either. Thus, the number of non-negative integers <var>i</var> satisfying the condition is finite, and the maximum value of such <var>i</var> is <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>aa aaaaaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>For any non-negative integer <var>i</var>, the concatenation of <var>i</var> copies of <var>t</var> is a substring of the concatenation of <var>4i</var> copies of <var>s</var>. Thus, there are infinitely many non-negative integers <var>i</var> that satisfy the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>aba baaab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>As stated in Notes, <var>i = 0</var> always satisfies the condition.</p></section> </div> </span>
p02348
<H1>Range Update Query (RUQ)</H1> <p> Write a program which manipulates a sequence <var>A</var> = {<var>a<sub>0</sub>, a<sub>1</sub>, . . . , a<sub>n&minus;1</sub></var>} with the following operations: </p> <ul> <li><var>update(s, t, x)</var>: change <var>a<sub>s</sub></var>, <var>a<sub>s+1</sub></var>, ..., <var>a<sub>t</sub></var> to <var>x</var>.</li> <li><var>find(i)</var>: output the value of <var>a<sub>i</sub>.</li> </ul> <p> Note that the initial values of <var>a<sub>i</sub></var> (<var>i = 0, 1, . . . , n&minus;1</var>) are 2<sup>31</sup>-1. </p> <H2>Input</H2> <pre> <var>n</var> <var>q</var> <var>query<sub>1</sub></var> <var>query<sub>2</sub></var> : <var>query<sub>q</sub></var> </pre> <p> In the first line, <var>n</var> (the number of elements in <var>A</var>) and <var>q</var> (the number of queries) are given. Then, <i>i</i>th query <var>query<sub>i</sub></var> is given in the following format: </p> <pre> 0 <var>s</var> <var>t</var> <var>x</var> </pre> <p> or </p> <pre> 1 <var>i</var> </pre> <p> The first digit represents the type of the query. '0' denotes <var>update(s, t, x)</var> and '1' denotes <var>find(i)</var>. </p> <H2>Output</H2> <p> For each <var>find</var> operation, print the value. </p> <H2>Constraints</H2> <ul> <li> <var>1 &le; n &le; 100000</var> </li> <li> <var>1 &le; q &le; 100000</var> </li> <li> <var>0 &le; s &le; t &lt; n</var> </li> <li> <var>0 &le; i &lt; n</var> </li> <li> <var>0 &le; x &lt; 2<sup>31</sup>&minus;1</var> </li> </ul> <H2>Sample Input 1</H2> <pre> 3 5 0 0 1 1 0 1 2 3 0 2 2 2 1 0 1 1 </pre> <H2>Sample Output 1</H2> <pre> 1 3 </pre> <br/> <H2>Sample Input 2</H2> <pre> 1 3 1 0 0 0 0 5 1 0 </pre> <H2>Sample Output 2</H2> <pre> 2147483647 5 </pre>
p00375
<h1>Celsius/Fahrenheit</h1>   <p> In Japan, temperature is usually expressed using the Celsius (&#x2103) scale. In America, they used the Fahrenheit (&#x2109) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is commonly encountered while you are in America. </p> <p> A value in Fahrenheit can be converted to Celsius by first subtracting $32$ and then multiplying by $\frac{5}{9}$. A simplified method may be used to produce a rough estimate: first subtract $30$ and then divide by $2$. Using the latter method, $68$ Fahrenheit is converted to $19$ Centigrade, i.e., $\frac{(68-30)}{2}$. </p> <p> Make a program to convert Fahrenheit to Celsius using the simplified method: $C = \frac{F - 30}{2}$. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $F$ </pre> <p> The input line provides a temperature in Fahrenheit $F$ ($30 \leq F \leq 100$), which is an integer divisible by $2$. </p> <h2>Output</h2> <p> Output the converted Celsius temperature in a line. </p> <h2>Sample Input 1</h2> <pre> 68 </pre> <h2>Sample Output 1</h2> <pre> 19 </pre> <h2>Sample Input 2</h2> <pre> 50 </pre> <h2>Sample Output 2</h2> <pre> 10 </pre>
p01837
<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>Longest Shortest Path</h2> <p> You are given a directed graph and two nodes $s$ and $t$. The given graph may contain multiple edges between the same node pair but not self loops. Each edge $e$ has its initial length $d_e$ and the cost $c_e$. You can extend an edge by paying a cost. Formally, it costs $x \cdot c_e$ to change the length of an edge $e$ from $d_e$ to $d_e + x$. (Note that $x$ can be a non-integer.) Edges cannot be shortened. </p> <p> Your task is to maximize the length of the shortest path from node $s$ to node $t$ by lengthening some edges within cost $P$. You can assume that there is at least one path from $s$ to $t$. </p> <h3>Input</h3> <p> The input consists of a single test case formatted as follows.<br/> <br/> $N$ $M$ $P$ $s$ $t$<br/> $v_1$ $u_1$ $d_1$ $c_1$<br/> ...<br/> $v_M$ $u_M$ $d_M$ $c_M$<br/> </p> <p> The first line contains five integers $N$, $M$, $P$, $s$, and $t$: $N$ ($2 \leq N \leq 200$) and $M$ ($1 \leq M \leq 2,000$) are the number of the nodes and the edges of the given graph respectively, $P$ ($0 \leq P \leq 10^6$) is the cost limit that you can pay, and $s$ and $t$ ($1 \leq s, t \leq N, s \ne t$) are the start and the end node of objective path respectively. Each of the following $M$ lines contains four integers $v_i$, $u_i$, $d_i$, and $c_i$, which mean there is an edge from $v_i$ to $u_i$ ($1 \leq v_i, u_i \leq N, v_i \ne u_i$) with the initial length $d_i$ ($1 \leq d_i \leq 10$) and the cost $c_i$ ($1 \leq c_i \leq 10$). </p> <h3>Output</h3 <p> Output the maximum length of the shortest path from node $s$ to node $t$ by lengthening some edges within cost $P$. The output can contain an absolute or a relative error no more than $10^{-6}$. </p> <h3>Sample Input 1</h3> <pre> 3 2 3 1 3 1 2 2 1 2 3 1 2 </pre> <h3>Output for the Sample Input 1</h3> <pre> 6.0000000 </pre> <h3>Sample Input 2</h3> <pre> 3 3 2 1 3 1 2 1 1 2 3 1 1 1 3 1 1 </pre> <h3>Output for the Sample Input 2</h3> <pre> 2.5000000 </pre> <h3>Sample Input 3</h3> <pre> 3 4 5 1 3 1 2 1 2 2 3 1 1 1 3 3 2 1 3 4 1 </pre> <h3>Output for the Sample Input 3</h3> <pre> 4.2500000 </pre>
p02718
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have held a popularity poll for <var>N</var> items on sale. Item <var>i</var> received <var>A_i</var> votes.</p> <p>From these <var>N</var> items, we will select <var>M</var> as popular items. However, we cannot select an item with less than <var>\dfrac{1}{4M}</var> of the total number of votes.</p> <p>If <var>M</var> popular items can be selected, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq M \leq N \leq 100</var></li> <li><var>1 \leq A_i \leq 1000</var></li> <li><var>A_i</var> are 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>M</var> <var>A_1</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>M</var> popular items can be selected, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 5 4 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>There were <var>12</var> votes in total. The most popular item received <var>5</var> votes, and we can select it.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 380 19 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>There were <var>400</var> votes in total. The second and third most popular items received less than <var>\dfrac{1}{4\times 2}</var> of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>12 3 4 56 78 901 2 345 67 890 123 45 6 789 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>