question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p02478
<a href="https://onlinejudge.u-aizu.ac.jp/resources/icpcooc2018/practice/C.pdf" target='_blank'>Problem is available from here.</a>
p00150
<H1>Twin Prime</H1> <p> Prime numbers are widely applied for cryptographic and communication technology. A twin prime is a prime number that differs from another prime number by 2. For example, (5, 7) and (11, 13) are twin prime pairs. </p> <p> In this problem, we call the greater number of a twin prime "size of the twin prime." </p> <p> Your task is to create a program which reads an integer <i>n</i> and prints a twin prime which has the maximum size among twin primes less than or equals to <i>n</i> </p> <p> You may assume that 5 &le; <i>n</i> &le; 10000. </p> <H2>Input</H2> <p> The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows: </p> <pre> <i>n</i> (integer) </pre> <H2>Output</H2> <p> For each dataset, print the twin prime <i>p</i> and <i>q</i> (<i>p</i> &lt; <i>q</i>). <i>p</i> and <i>q</i> should be separated by a single space. </p> <H2>Sample Input</H2> <pre> 12 100 200 300 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 7 71 73 197 199 281 283 </pre>
p00500
<H1>数圓おゲヌム (Unique number) </H1> <br/> <h2> 問題</h2> <p> JOI 君は友達ずゲヌムをするこずにしたこのゲヌムには N 人のプレむダヌが参加する1 回のゲヌムのルヌルは次のようなものである </p> <p> それぞれのプレむダヌは 1 以䞊 100 以䞋の奜きな敎数をカヌドに曞いお提出する各プレむダヌは自分ず同じ数を曞いた人が他にいなかった堎合自分の曞いた数ず同じ埗点を埗る自分ず同じ数を曞いた人が他にいた堎合は埗点を埗られない </p> <p> JOI 君たちはこのゲヌムを 3 回行った各プレむダヌが 3 回のゲヌムにおいお曞いた数が䞎えられたずき各プレむダヌが 3 回のゲヌムで埗た合蚈埗点を求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は 1 + N 行からなる </p> <p> 1 行目には敎数 N (2 ≩ N ≩ 200) が曞かれおおりプレむダヌの人数を衚す </p> <p> 続く N 行のうちの i 行目 (1 ≩ i ≩ N) には 3 ぀の 1 以䞊 100 以䞋の敎数が空癜を区切りずしお曞かれおおりそれぞれ i 人目のプレむダヌが 1 回目2 回目3 回目のゲヌムで曞いた数を衚す </p> <h2> 出力</h2> <p> 出力は N 行からなる </p> <p> i 行目 (1 ≩ i ≩ N) には i 人目のプレむダヌが 3 回のゲヌムで埗た合蚈埗点を衚す敎数を出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 5 100 99 98 100 97 92 63 89 63 99 99 99 89 97 98 </pre> <h3>出力䟋 1</h3> <pre> 0 92 215 198 89 </pre> <p> 入力䟋 1 では各プレむダヌが 3 回のゲヌムで埗た埗点の詳现は次のようになる </p> <table style="margin-left: 50px; margin-right: 50px;" class="withborder"> <tr><td>プレむダヌ 1 0 + 0 + 0 = 0</td></tr> <tr><td>プレむダヌ 2 0 + 0 + 92 = 92</td></tr> <tr><td>プレむダヌ 3 63 + 89 + 63 = 215</td></tr> <tr><td>プレむダヌ 4 99 + 0 + 99 = 198</td></tr> <tr><td>プレむダヌ 5 89 + 0 + 0 = 89</td></tr> </table> <br> <h3>入力䟋 2</h3> <pre> 3 89 92 77 89 92 63 89 63 77 </pre> <h3>出力䟋 2</h3> <pre> 0 63 63 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p01741
<p> マンハッタンでは道路がx 座暙たたはy 座暙が敎数のずころに通っおいるすぬけ君の家ずすめけ君の家はどちらも道路䞊にあり盎線距離(ナヌクリッド距離) はちょうど <var>d</var> であるすぬけ君の家からすめけ君の家たで道路に沿っお移動するずきの最短距離ずしお考えられる最倧倀を求めよ </p> <h2>Constraints</h2> <ul> <li> 0 &lt; <var>d</var> &le; 10</li> <li><var>d</var> は小数点以䞋ちょうど䞉桁たで䞎えられる</li> </ul> <h2>Input</h2> <pre> <var>d</var> </pre> <h2>Output</h2> <p> 答えを䞀行に出力せよ絶察誀差たたは盞察誀差が <var>10<sup>&minus;9</sup></var> 以䞋のずき正答ず刀定される </p> <h2>Sample Input 1</h2> <pre> 1.000 </pre> <h2>Sample Output 1</h2> <pre> 2.000000000000 </pre> <h2>Sample Input 2</h2> <pre> 2.345 </pre> <h2>Sample Output 2</h2> <pre> 3.316330803765 </pre>
p00853
<H1><font color="#000">Problem I:</font> Enjoyable Commutation</H1> <p> Isaac is tired of his daily trip to his ofice, using the same shortest route everyday. Although this saves his time, he must see the same scenery again and again. He cannot stand such a boring commutation any more. </p> <p> One day, he decided to improve the situation. He would change his route everyday at least slightly. His new scheme is as follows. On the first day, he uses the shortest route. On the second day, he uses the second shortest route, namely the shortest except one used on the first day. In general, on the <i>k</i>-th day, the <i>k</i>-th shortest route is chosen. Visiting the same place twice on a route should be avoided, of course. </p> <p> You are invited to help Isaac, by writing a program which finds his route on the <i>k</i>-th day. The problem is easily modeled using terms in the graph theory. Your program should find the <i>k</i>-th shortest path in the given directed graph. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each in the following format. </p> <pre> <i>n m k a b</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>d</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>d</i><sub>2</sub> ... <i>x</i><sub><i>m</i></sub> <i>y</i><sub><i>m</i></sub> <i>d</i><sub><i>m</i></sub> </pre> <p> Every input item in a dataset is a non-negative integer. Two or more input items in a line are separated by a space. </p> <p> <i>n</i> is the number of nodes in the graph. You can assume the inequality 2 &le; <i>n</i> &le; 50. <i>m</i> is the number of (directed) edges. <i>a</i> is the start node, and <i>b</i> is the goal node. They are between 1 and <i>n</i>, inclusive. You are required to find the <i>k</i>-th shortest path from <i>a</i> to <i>b</i>. You can assume 1 &le; <i>k</i> &le; 200 and <i>a</i> &ne; <i>b</i>. </p> <p> The <i>i</i>-th edge is from the node <i>x<sub>i</sub></i> to <i>y<sub>i</sub></i> with the length <i>d<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>m</i>). Both <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> are between 1 and <i>n</i>, inclusive. <i>d<sub>i</sub></i> is between 1 and 10000, inclusive. You can directly go from <i>x<sub>i</sub></i> to <i>y<sub>i</sub></i>, but not from <i>y<sub>i</sub></i> to <i>x<sub>i</sub></i> unless an edge from <i>y<sub>i</sub></i> to <i>x<sub>i</sub></i> is explicitly given. The edge connecting the same pair of nodes is unique, if any, that is, if <i>i</i> &ne; <i>j</i>, it is never the case that <i>x<sub>i</sub></i> equals <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> equals <i>y<sub>j</sub></i>. Edges are not connecting a node to itself, that is, <i>x<sub>i</sub></i> never equals <i>y<sub>i</sub></i> . Thus the inequality 0 &le; <i>m</i> &le; <i>n</i>(<i>n</i> - 1) holds. </p> <p> Note that the given graph may be quite unrealistic as a road network. Both the cases <i>m</i> = 0 and <i>m</i> = <i>n</i>(<i>n</i> - 1) are included in the judges' data. </p> <p> The last dataset is followed by a line containing five zeros (separated by a space). </p> <H2>Output</H2> <p> For each dataset in the input, one line should be output as specified below. An output line should not contain extra characters such as spaces. </p> <p> If the number of distinct paths from <i>a</i> to <i>b</i> is less than <i>k</i>, the string <span>None</span> should be printed. Note that the first letter of <span>None</span> is in uppercase, while the other letters are in lowercase. </p> <p> If the number of distinct paths from <i>a</i> to <i>b</i> is <i>k</i> or more, the node numbers visited in the <i>k</i>-th shortest path should be printed in the visited order, separated by a hyphen (minus sign). Note that <i>a</i> must be the first, and <i>b</i> must be the last in the printed line. </p> <p> In this problem the term <i>shorter</i> (thus <i>shortest</i> also) has a special meaning. A path <i>P</i> is defined to be shorter than <i>Q</i>, if and only if one of the following conditions holds. </p> <ol> <li> The length of <i>P</i> is less than the length of <i>Q</i>. The length of a path is defined to be the sum of lengths of edges on the path.</li> <li> The length of <i>P</i> is equal to the length of <i>Q</i>, and <i>P</i>'s sequence of node numbers comes earlier than <i>Q</i>'s in the dictionary order. Let's specify the latter condition more precisely. Denote <i>P</i>'s sequence of node numbers by <i>p</i><sub>1</sub>, <i>p</i><sub>2</sub>,..., <i>p<sub>s</sub></i>, and <i>Q</i>'s by <i>q</i><sub>1</sub>, <i>q</i><sub>2</sub>,..., <i>q<sub>t</sub></i>. <i>p</i><sub>1</sub> = <i>q</i><sub>1</sub> = <i>a</i> and <i>p<sub>s</sub></i> = <i>q<sub>t</sub></i> = <i>b</i> should be observed. The sequence <i>P</i> comes earlier than <i>Q</i> in the dictionary order, if for some <i>r</i> (1 &le; <i>r</i> &le; <i>s</i> and <i>r</i> &le; <i>t</i>), <i>p</i><sub>1</sub> = <i>q</i><sub>1</sub>,..., <i>p</i><sub><i>r</i>-1</sub> = <i>q</i><sub><i>r</i>-1</sub>, and <i>p<sub>r</sub></i> &lt; <i>q<sub>r</sub></i> (<i>p<sub>r</sub></i> is numerically smaller than <i>q<sub>r</sub></i>). </ol> <p> A path visiting the same node twice or more is not allowed. </p> <H2>Sample Input</H2> <pre> 5 20 10 1 5 1 2 1 1 3 2 1 4 1 1 5 3 2 1 1 2 3 1 2 4 2 2 5 2 3 1 1 3 2 2 3 4 1 3 5 1 4 1 1 4 2 1 4 3 1 4 5 2 5 1 1 5 2 1 5 3 1 5 4 1 4 6 1 1 4 2 4 2 1 3 2 1 2 1 1 4 3 2 3 1 3 4 1 3 3 5 1 3 1 2 1 2 3 1 1 3 1 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1-2-4-3-5 1-2-3-4 None </pre> <p> In the case of the first dataset, there are 16 paths from the node 1 to 5. They are ordered as follows (The number in parentheses is the length of the path). </p> <pre> 1 (3) 1-2-3-5 9 (5) 1-2-3-4-5 2 (3) 1-2-5 10 (5) 1-2-4-3-5 3 (3) 1-3-5 11 (5) 1-2-4-5 4 (3) 1-4-3-5 12 (5) 1-3-4-5 5 (3) 1-4-5 13 (6) 1-3-2-5 6 (3) 1-5 14 (6) 1-3-4-2-5 7 (4) 1-4-2-3-5 15 (6) 1-4-3-2-5 8 (4) 1-4-2-5 16 (8) 1-3-2-4-5 </pre>
p03286
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given an integer <var>N</var>, find the base <var>-2</var> representation of <var>N</var>.</p> <p>Here, <var>S</var> is the base <var>-2</var> representation of <var>N</var> when the following are all satisfied:</p> <ul> <li><var>S</var> is a string consisting of <code>0</code> and <code>1</code>.</li> <li>Unless <var>S =</var> <code>0</code>, the initial character of <var>S</var> is <code>1</code>.</li> <li>Let <var>S = S_k S_{k-1} ... S_0</var>, then <var>S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N</var>.</li> </ul> <p>It can be proved that, for any integer <var>M</var>, the base <var>-2</var> representation of <var>M</var> is uniquely determined.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>Every value in input is integer.</li> <li><var>-10^9 \leq N \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the base <var>-2</var> representation of <var>N</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>-9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1011 </pre> <p>As <var>(-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9</var>, <code>1011</code> is the base <var>-2</var> representation of <var>-9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>123456789 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>11000101011001101110100010101 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01311
<h1><font color="#000">Problem I:</font> 倏ぞの扉</h1> <p>な぀めは倧のねこ奜きである。な぀めの家ではずっずねこを飌っおおらず、ねこ奜きなな぀めはい぀も野良ねこず遊んでいた。しかし、今回な぀めは決心し、自分の家でねこを䞀匹飌うこずにした。な぀めはねこを家に迎え、レノンず名付けおかわいがり始めた。</p> <p>な぀めの家はたくさんの郚屋ず、それらを぀なぐたくさんの扉からなっおおり、扉は次の2皮類がある。</p> <dl> <dt>人間甚の普通の扉</dt> <dd>な぀めは開けるこずができるが、レノンが自分で開けるこずはできない。な぀めずレノンの䞡方が通るこずができる。䞀床開ければ、その埌は開いたたたにしおおける。</dd> <dt>ねこ甚の小さな扉</dt> <dd>レノンが自分であけお自由に通るこずができる。ただし小さいために、な぀めが通るこずはできない。</dd> </dl> <p>レノンは倏が倧奜きである。だから、冬になり家の倖がたっしろな雪で芆われおしたう頃になるず、圌の機嫌はずおも悪くなっおしたった。しかし、圌は家にたくさんあるドアのうち、あるひず぀の扉が「倏」ぞず぀ながっおいるず信じおいるようだった。な぀めはその扉を「倏ぞの扉」ず呌んでいる。そしお、寒くお䞍機嫌になっおくるず、レノンはきたっおその扉の向こうぞ行きたがるのである。</p> <p>冬のある日、レノンがたた「倏ぞの扉」の奥ぞ行こうず思い立った。しかし、レノンがひずりで扉を開けお、倏ぞの扉の奥ぞ行けるずは限らない。その時はもちろん、な぀めはレノンの手䌝いをしなければならない。぀たり、な぀めしか開けるこずの出来ない扉をいく぀か開いお、レノンが「倏ぞの扉」の向こう偎ぞ行けるようにしおあげるのだ。</p> <p>最初、家の䞭の党おの扉は閉たっおいる。家の郚屋の接続関係、な぀めおよびレノンの初期䜍眮が䞎えられる。な぀めずレノンが最適な戊略をずった時、レノンが「倏ぞの扉」の先ぞいくために<strong>な぀めが開けなければならない扉</strong>の最小数を蚈算しなさい。</p> <p>以䞋の図は、サンプル入力の䟋を図瀺したものである。</p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_summer" alt="サンプル入力の1番目" > <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_summer2" alt="サンプル入力の2番目" > <br> 図: サンプル入力の初期状態 </center> <h2>Input</h2> <p> 入力の1行目には、郚屋の数 <var>n</var> ず扉の数 <var>m</var> が1぀の空癜文字で区切っお䞎えられる。郚屋にはそれぞれ 0 から <var>n</var> の番号が割り振られおおり、0は「倏ぞの扉」の先をあらわす。2行目はな぀めが最初にいる郚屋の番号ずレノンが最初にいる郚屋の番号が、1぀の空癜文字で区切っお䞎えられる。どちらの郚屋番号も1以䞊であり、最初から「倏ぞの扉」の先にいるこずはない。続く <var>m</var> 行には、<var>m</var> 枚の扉の情報がそれぞれ1行ず぀䞎えられる。各行はふた぀の郚屋IDず扉の皮類を衚す1文字のアルファベットからなり、1぀の空癜文字で区切られおいる。扉は指定されたふた぀の郚屋を繋いでおり、皮類はアルファベットが <code>N</code> のずき人間甚の普通の扉、<code>L</code> のずきねこ甚の小さな扉である。扉が同じ郚屋同士を繋ぐこずはない。郚屋IDが0のものを含む扉が「倏ぞの扉」であり、これは入力䞭に必ずただ1぀存圚する。1 &lt;= n, m &lt;= 100000を満たす。 <h2>Output</h2> <p> な぀めが開けなければならない扉の最小数を、1行で出力せよ。 </p> <h2>Notes on Submission</h2> <p> 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 </p> <h2>Sample Input</h2> <pre> 2 4 6 1 2 1 2 N 2 3 N 3 4 N 4 1 N 1 4 L 4 0 L 4 6 1 2 1 2 N 2 3 N 3 4 N 4 1 N 1 4 L 4 0 N </pre> <h2>Output for the Sample Input</h2> <pre> 1 3 </pre>
p03906
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The currency used in Takahashi Kingdom is <em>Myon</em>. There are <var>1</var>-, <var>10</var>-, <var>100</var>-, <var>1000</var>- and <var>10000</var>-Myon coins, and so forth. Formally, there are <var>10^n</var>-Myon coins for any non-negative integer <var>n</var>.</p> <p>There are <var>N</var> items being sold at Ex Store. The price of the <var>i</var>-th <var>(1≩i≩N)</var> item is <var>A_i</var> Myon.</p> <p>Takahashi is going to buy some, at least one, possibly all, of these <var>N</var> items. He hates receiving change, so he wants to bring coins to the store so that he can pay the total price without receiving change, no matter what items he chooses to buy. Also, since coins are heavy, he wants to bring as few coins as possible.</p> <p>Find the minimum number of coins he must bring to the store. It can be assumed that he has an infinite supply of coins.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩20,000</var></li> <li><var>1≩A_i≩10^{12}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>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 coins Takahashi must bring to the store, so that he can pay the total price without receiving change, no matter what items he chooses to buy.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 43 24 37 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>16 </pre> <p>There are seven possible total prices: <var>24, 37, 43, 61, 67, 80,</var> and <var>104</var>. With seven <var>1</var>-Myon coins, eight <var>10</var>-Myon coins and one <var>100</var>-Myon coin, Takahashi can pay any of these without receiving change.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 49735011221 970534221705 411566391637 760836201000 563515091165 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>105 </pre></section> </div> </span>
p02614
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid of <var>H</var> rows and <var>W</var> columns of squares. The color of the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left <var>(1 \leq i \leq H, 1 \leq j \leq W)</var> is given to you as a character <var>c_{i,j}</var>: the square is white if <var>c_{i,j}</var> is <code>.</code>, and black if <var>c_{i,j}</var> is <code>#</code>.</p> <p>Consider doing the following operation:</p> <ul> <li>Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.</li> </ul> <p>You are given a positive integer <var>K</var>. How many choices of rows and columns result in exactly <var>K</var> black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H, W \leq 6</var></li> <li><var>1 \leq K \leq HW</var></li> <li><var>c_{i,j}</var> is <code>.</code> or <code>#</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>K</var> <var>c_{1,1}c_{1,2}...c_{1,W}</var> <var>c_{2,1}c_{2,2}...c_{2,W}</var> <var>:</var> <var>c_{H,1}c_{H,2}...c_{H,W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the number of choices of rows and columns satisfying the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 2 ..# ### </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>Five choices below satisfy the condition.</p> <ul> <li>The <var>1</var>-st row and <var>1</var>-st column</li> <li>The <var>1</var>-st row and <var>2</var>-nd column</li> <li>The <var>1</var>-st row and <var>3</var>-rd column</li> <li>The <var>1</var>-st and <var>2</var>-nd column</li> <li>The <var>3</var>-rd column</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 4 ..# ### </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>One choice, which is choosing nothing, satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 2 3 ## ## </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>6 6 8 ..##.. .#..#. #....# ###### #....# #....# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>208 </pre></section> </div> </span>
p00629
<H1><font color="#000000">Problem 03:</font> Selecting Teams Advanced to Regional</H1> <p> 日本で毎幎開催される囜際倧孊察抗プログラミングコンテストのアゞア地区予遞に出堎するためには、厳しい囜内予遞を突砎しなければなりたせん。 </p> <p> 倧孊察抗ずは蚀っおも、぀の孊校から耇数のチヌムが参戊したす。そこで、できるだけ倚くの孊校がアゞア地区予遞に出堎できるように、突砎チヌムの遞抜には以䞋の遞抜ルヌルが適甚されたす </p> <p> 該圓チヌムを <i>A</i> ずし、成瞟の優秀な順番に次のルヌルを適甚したす </p> <ul> <li>ルヌル 1<br> その時点での遞抜チヌム数が 10 に満たない堎合<br> <i>A</i> ず同じ所属でその時点で遞抜されたチヌムの数が 3 に満たなければ、<i>A</i> は遞抜されたす。 </li> <li>ルヌル 2<br> その時点での遞抜チヌム数が 20 に満たない堎合<br> <i>A</i> ず同じ所属でその時点で遞抜されたチヌムの数が 2 に満たなければ、<i>A</i> は遞抜されたす。 </li> <li>ルヌル 3<br> その時点での遞抜チヌム数が 26 に満たない堎合<br> <i>A</i> ず同じ所属でその時点で遞抜されたチヌムがなければ、<i>A</i> は遞抜さたす。 </li> </ul> <p> たた、成瞟の順番は次のルヌルで決定されたす </p> <ul> <li>より倚くの問題を解いたチヌムが䞊䜍ずなりたす。</li> <li>解いた問題数が同じ堎合は、ペナルティが小さいチヌムが䞊䜍ずなりたす。</li> </ul> <p> 各チヌムのID敎数、所属敎数、正解数敎数、ペナルティ敎数を入力し、遞抜チヌムのIDを遞抜順に出力するプログラムを䜜成しお䞋さい。 チヌムは成瞟順に䞎えられるずは限らないので、順䜍付けした埌、遞抜ルヌルを適甚しなければならないこずに泚意しお䞋さい。 </p> <p> この問題では、正解数ずペナルティが同じチヌムがあった堎合はIDが小さい方を䞊䜍ずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが入力ずしお䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす<br><br> <i>n</i> (チヌム数敎数)<br> I<sub>1</sub> U<sub>1</sub> A<sub>1</sub> P<sub>1</sub> (1番目のチヌムのID、所属、正解数、ペナルティ空癜区切りの぀の敎数)<br> I<sub>2</sub> U<sub>2</sub> A<sub>2</sub> P<sub>2</sub> (2番目のチヌムのID、所属、正解数、ペナルティ空癜区切りの぀の敎数)<br> .<br> .<br> I<sub><i>n</i></sub> U<sub><i>n</i></sub> A<sub><i>n</i></sub> P<sub><i>n</i></sub> (n番目のチヌムのID、所属、正解数、ペナルティ空癜区切りの぀の敎数)<br> </p> <p> n は 300 以䞋であり、I<sub><i>i</i></sub>, U<sub><i>i</i></sub> は 1 以䞊 1000 以䞋ずしたす。぀のデヌタセットに、同じ ID のチヌムは無いず仮定しおかたいたせん。 </p> <p> A<sub><i>i</i></sub> は 10 以䞋、P<sub><i>i</i></sub> は 100,000 以䞋ずしたす。 </p> <p> <i>n</i> が 0 のずき、入力の終わりずしたす。 </p> <H2>Output</H2> <p> 各デヌタセットに぀いお、遞抜チヌムのIDを遞抜された順に出力しお䞋さい。1぀のIDを1行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 6 1 1 6 200 2 1 6 300 3 1 6 400 4 2 5 1200 5 1 5 1400 6 3 4 800 3 777 1 5 300 808 2 4 20 123 3 6 500 2 2 1 3 100 1 1 3 100 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 3 4 6 123 777 808 1 2 </pre>
p02244
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>8 Queens Problem</H1> <p> The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_13_A_8queens"> </center><br> <p> For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem. </p> <H2>Input</H2> <p> In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0. </p> <H2>Output</H2> <p> Print a $8 \times 8$ chess board by strings where a square with a queen is represented by '<span>Q</span>' and an empty square is represented by '<span>.</span>'. </p> <H2>Constraints</H2> <ul> <li>There is exactly one solution</li> </ul> <H2>Sample Input 1</H2> <pre> 2 2 2 5 3 </pre> <H2>Sample Output 1</H2> <pre> ......Q. Q....... ..Q..... .......Q .....Q.. ...Q.... .Q...... ....Q... </pre>
p00279
<H1>ハッピヌ゚ンド問題</H1> <p> 「ハッピヌ゚ンド問題」ず呌ばれる数孊の未解決問題に関連したプログラムを曞いおみたしょう。平面䞊に䞎えられた<var>N</var>個の点から、ちょうど<var>k</var>個の点を結んでできる凞倚角圢のうち、最も面積の小さいものを芋぀けるプログラムを䜜成しおください。ただし、N個の点の座暙を䞎えられた埌、質問ずしお凞倚角圢の角の個数<var>k</var>がいく぀か䞎えられたす。 </p> <p> 補足ハッピヌ゚ンド問題に぀いお<br/> 平面䞊にどの点も同じ盎線䞊に乗らないように<var>N</var>個の点を眮きたす。そのずき、どのように点を眮いおも、k個の点をうたく遞ぶずk個の角をも぀凞倚角圢が必ず䜜れるず予想されおいたす。 今のずころ、䞉角圢ならば<var>N</var>=3、四角圢ならば<var>N</var>=5、五角圢ならば<var>N</var>=9、六角圢ならば<var>N</var>=17であればよいこずが、幎たでに蚌明されおいたす。たた、䞉角圢以䞊のすべおのk角圢に察しお、<var>N</var>=1+2<sup><var>k</var>-2</sup>ずいう予想がありたすが、いただ蚌明されおいたせん。これは幎にわたり研究が進められおいる難問です。<br/> この問題には、「ハッピヌ゚ンド問題」ずいう玠敵な名前が぀けられおいたす。ある男女がこの問題を研究しおいるうちに仲良くなっお、぀いに結婚したこずにちなんで、友人の数孊者が名付けたそうです。ロマンチックですね。 </p> <h2>入力</h2> <p> 入力は1぀のデヌタセットからなる。入力デヌタは以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> : <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>Q</var> <var>k<sub>1</sub></var> : <var>k<sub>Q</sub></var> </pre> <p> 行目に平面䞊の点の個数<var>N</var>(3 &le; <var>N</var> &le; 40)が䞎えられる。続く<var>N</var>行に各点の座暙が䞎えられる。各点には1から<var>N</var>たでの番号が、入力される順番に付けられおいる。<var>x<sub>i</sub></var>ず<var>y<sub>i</sub></var>(-10000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 10000)は<var>i</var>番目の点のそれぞれ<var>x</var>座暙ず<var>y</var>座暙を衚す敎数である。<var>x</var>軞の正方向は右向き, <var>y</var>軞の正方向は䞊向きに取るものずする。 </p> <p> 続く行に質問の数<var>Q</var>(1 &le; <var>Q</var> &le; <var>N</var>)が䞎えられる。続く<var>Q</var>行に質問が䞎えられる。<var>k<sub>i</sub></var>(3 &le; <var>k<sub>i</sub></var> &le; <var>N</var>)は<var>i</var>番目の質問である凞倚角圢の角の個数を衚す。 </p> <p> なお、入力は以䞋の条件を満たすものずする。 </p> <ul> <li> 入力される点の座暙はすべお異なる。 </li> <li> どの点も同じ盎線䞊には乗らない。</li> <li> 各質問に察しお面積最小の凞倚角圢は぀であり、番目に小さい凞倚角圢ずの面積の差は 0.0001以䞊。</li> </ul> <h2>出力</h2> <p> 質問ごずに、面積が最小の凞倚角圢の党頂点を1行に出力する。凞倚角圢の頂点で最も䞋にあるものの䞭で最も巊にある頂点から順に、反時蚈呚りで頂点の番号を出力する。頂点の番号の間は空癜1぀で区切る。行の終わりには空癜文字を出力しない。ただし、凞倚角圢が䜜れない堎合はNAず出力する。 </p> <h2>入力䟋 1</h2> <pre> 5 0 0 3 0 5 2 1 4 0 3 3 3 4 5 </pre> <h2>出力䟋 1</h2> <pre> 1 4 5 1 2 4 5 1 2 3 4 5 </pre> <br/> <h2>入力䟋 2</h2> <pre> 6 0 0 3 0 5 2 1 4 0 3 3 2 4 3 4 5 6 </pre> <h2>出力䟋 2</h2> <pre> 6 3 5 6 3 4 5 1 2 6 4 5 NA </pre>
p01891
<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: キャベツ / Cabbage</h1> <h2>問題文</h2> <p> AOR むカちゃんは葉が $N$ 枚あるキャベツを手に入れた。 このキャベツの葉には倖偎から順に $1,\ldots,N$ の番号が぀いおいお、$i$ 番目の葉の汚れ具合は $D_i$ である。 この倀が倧きいほど汚れ具合が酷いこずを衚す。 AOR むカちゃんはこのキャベツの葉を料理に䜿うため、廃棄する候補の汚い葉を以䞋の手順に埓っお遞ぶこずにした。 </p> <ol> <li> 廃棄候補を空に初期化する。 </li> <li> ただ調べおいない最も倖偎の葉に泚目する。党お調べ終わっおいる堎合は終了する。 </li> <li> その葉の汚れ具合が $A$ 以䞊であれば廃棄候補に加え、 2. に戻る。そうでなければ終了する。 </li> </ol> </ol> <p> しかし、この操䜜を行った結果、料理に䜿える葉が極端に少なくなっおしたう堎合があるこずに気が぀いた。 そこで、䞊蚘の操䜜埌に捚おる葉を考えなおし、以䞋の操䜜を行うこずにした。 </p> <ol> <li> 廃棄候補でない葉が $M$ 枚未満であれば 2. に進む。そうでなければ終了する。 </li> <li> 廃棄候補の葉のうちただ調べおいない最も内偎の葉に泚目する。廃棄候補の葉がない堎合は終了する。 </li> <li> その葉の汚れ具合が $B$ 以䞋であれば廃棄候補から倖し、 2. に戻る。 そうでなければ廃棄候補に残っおいる葉を党お廃棄し、終了する。 </li> </ol> </ol> <p> これらの操䜜を行ったずき、最終的に捚おる葉の枚数を求めよ。 </p> <h2>入力</h2> <p> $N \ M \ A \ B$<br> $D_{1} \ D_{2} \ \cdots \ D_{N}$<br> </p> <h2>入力の制玄</h2> <p> $1 \leq N \leq 1000$<br> $0 \leq M \leq N$<br> $1 \leq A \leq B \leq 1000$<br> $1 \leq D_{i} \leq 1000$<br> </p> <h2>出力</h2> <p> 最終的に捚おる葉の数を出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力1</h3> <pre> 5 3 6 9 9 7 5 3 1 </pre> <h3>サンプル出力1</h3> <pre> 2 </pre> <p> 䞀枚目ず二枚目を捚おる。 </p> <h3>サンプル入力2</h3> <pre> 5 3 6 9 5 4 3 2 1 </pre> <h3>サンプル出力2</h3> <pre> 0 </pre> <p> 䞀枚目から捚おない。 </p> <h3>サンプル入力3</h3> <pre> 5 3 6 9 10 8 6 4 2 </pre> <h3>サンプル出力3</h3> <pre> 1 </pre> <p> 䞉枚目たで捚おようずするが考え盎し、二枚目ず䞉枚目を捚おないこずにした。 </p> <h3>サンプル入力4</h3> <pre> 5 3 6 9 5 10 8 6 4 </pre> <h3>サンプル出力4</h3> <pre> 0 </pre> <p> 二枚目が汚れおいるこずを AOR むカちゃんは知らない。 </p> <h3>サンプル入力5</h3> <pre> 5 0 6 9 9 9 8 8 7 </pre> <h3>サンプル出力5</h3> <pre> 5 </pre> <p> 党郚捚おおも気にしない。 </p>
p00783
<H1><font color="#000">Problem D:</font> Napoleon's Grumble</H1> <p> Legend has it that, after being defeated in Waterloo, Napoleon Bonaparte, in retrospect of his days of glory, talked to himself "Able was I ere I saw Elba." Although, it is quite doubtful that he should have said this in English, this phrase is widely known as a typical <i>palindrome</i>. </p> <p> A palindrome is a symmetric character sequence that looks the same when read backwards, right to left. In the above Napoleon's grumble, white spaces appear at the same positions when read backwards. This is not a required condition for a palindrome. The following, ignoring spaces and punctuation marks, are known as the first conversation and the first palindromes by human beings. </p> <pre> "Madam, I'm Adam." "Eve." <i>(by Mark Twain)</i> </pre> <p> Write a program that finds palindromes in input lines. </p> <H2>Input</H2> <p> A multi-line text is given as the input. The input ends at the end of the file. </p> <p> There are at most 100 lines in the input. Each line has less than 1,024 Roman alphabet characters. </p> <H2>Output</H2> <p> Corresponding to each input line, a line consisting of <i>all</i> the character sequences that are palindromes in the input line should be output. However, trivial palindromes consisting of only one or two characters should not be reported. </p> <p> On finding palindromes, any characters in the input except Roman alphabets, such as punctuation characters, digits, space, and tabs, should be ignored. Characters that differ only in their cases should be looked upon as the same character. Whether or not the character sequences represent a proper English word or sentence does not matter. </p> <p> Palindromes should be reported all in uppercase characters. When two or more palindromes are reported, they should be separated by a space character. You may report palindromes in any order. </p> <p> If two or more occurrences of the same palindromes are found in the same input line, report only once. When a palindrome overlaps with another, even when one is completely included in the other, both should be reported. However, palindromes appearing in the center of another palindrome, whether or not they also appear elsewhere, should not be reported. For example, for an input line of "AAAAAA", two palindromes "AAAAAA" and "AAAAA" should be output, but not "AAAA" nor "AAA". For "AABCAAAAAA", the output remains the same. </p> <p> One line should be output corresponding to one input line. If an input line does not contain any palindromes, an empty line should be output. </p> <H2>Sample Input</H2> <pre> As the first man said to the first woman: "Madam, I'm Adam." She responded: "Eve." </pre> <H2>Output for the Sample Input</H2> <pre> TOT MADAMIMADAM MADAM ERE DED EVE </pre> <p> Note that the second line in the output is empty, corresponding to the second input line containing no palindromes. Also note that some of the palindromes in the third input line, namely "ADA", "MIM", "AMIMA", "DAMIMAD", and "ADAMIMADA", are not reported because they appear at the center of reported ones. "MADAM" <i>is</i> reported, as it does not appear in the center, but only once, disregarding its second occurrence. </p>
p01038
<h1>Problem B: Mountain Climbing</h1> <h2>Problem</h2> <p> なりよし君は山登りの蚈画を立おおいたす。蚈画はずおも倧切です。高原・盆地が倚いのか、峰・窪地が倚いのか、山腹があるのか、状況によっお甚意する荷物も倉わっおきたす。 </p> <p> なりよし君が持っおいる登山ガむドブックには、今回登山に利甚する道の䞀定の距離毎の暙高がスタヌト地点からゎヌル地点たで順に曞かれおいたす。 </p> <p> ガむドブックに曞かれおいる暙高をスタヌト地点からゎヌル地点たで順に <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>N</sub></var>ずし、高原、盆地、山腹、峰、窪地を次のように定矩したす: </p> <ul> <li>高原<br/> <var>a<sub>i-1</sub></var> &lt; <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> &gt; <var>a<sub>j+1</sub></var> (<var>1</var> &lt; <var>i</var> &lt; <var>j</var> &lt; <var>N</var>) </li> <li>盆地<br /> <var>a<sub>i-1</sub></var> &gt; <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> &lt; <var>a<sub>j+1</sub></var> (<var>1</var> &lt; <var>i</var> &lt; <var>j</var> &lt; <var>N</var>) </li> <li>山腹<br /> <var>a<sub>i-1</sub></var> &lt; <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> &lt; <var>a<sub>j+1</sub></var> (<var>1</var> &lt; <var>i</var> &lt; <var>j</var> &lt; <var>N</var>)<br /> もしくは <var>a<sub>i-1</sub></var> &gt; <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> &gt; <var>a<sub>j+1</sub></var> (<var>1</var> &lt; <var>i</var> &lt; <var>j</var> &lt; <var>N</var>)<br /> </li> <li>å³°<br /> <var>a<sub>i-1</sub></var> &lt; <var>a<sub>i</sub></var> &gt; <var>a<sub>i+1</sub></var> (<var>1</var> &lt; <var>i</var> &lt; <var>N</var>)<br /> </li> <li>窪地<br /> <var>a<sub>i-1</sub></var> &gt; <var>a<sub>i</sub></var> &lt; <var>a<sub>i+1</sub></var> (<var>1</var> &lt; <var>i</var> &lt; <var>N</var>)<br /> </li> </ul> <figure> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_kougen.png" /> <figcaption>高原</figcaption> </figure> <figure> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_bonchi.png" /> <figcaption>盆地</figcaption> </figure> <figure> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sanpuku1.png" /> <figcaption>山腹</figcaption> </figure> <figure> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sanpuku2.png" /> <figcaption>山腹</figcaption> </figure> <figure> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_mine.png" /> <figcaption>å³°</figcaption> </figure> <figure> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_kubochi.png" /> <figcaption>窪地</figcaption> </figure> <br /> <p> あなたは、なりよし君の為に、高原・盆地・山腹・峰・窪地、それぞれの数を蚈算するプログラムを曞くこずにしたした。 </p> <h2>Input</h2> <p> 入力は次のような圢匏で䞎えられる: </p> <pre> <var>N</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> <var>a<sub>3</sub></var>...<var>a<sub>N</sub></var> </pre> <p> <var>N</var>は䞎えられる暙高の数を衚す敎数である。 <var>a<sub>i</sub></var>は暙高を衚す敎数である( 1 &le; i &le; <var>N</var> )。それぞれ空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var> &le; 100000</li> <li>-100000 &le; <var>a<sub>i</sub></var> &le; 100000</li> </ul> <h2>Output</h2> <p>高原の数、盆地の数、山腹、峰、窪地の数を順番に空癜区切りで䞀行に出力せよ。</p> <h2>Sample Input 1</h2> <pre> 5 1 2 3 4 3 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sample01.png" /> <h2>Sample Output 1</h2> <pre> 0 0 0 1 0 </pre> <h2>Sample Input 2</h2> <pre> 12 10 5 15 15 20 20 12 12 8 3 3 5 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sample02.png" /> <h2>Sample Output 2</h2> <pre> 1 1 2 0 1 </pre>
p03005
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is distributing <var>N</var> balls to <var>K</var> persons.</p> <p>If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq N \leq 100</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible difference in the number of balls received.</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>1 </pre> <p>The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.</p> <p>Thus, the maximum possible difference in the number of balls received is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre> <p>For example, if we give <var>1, 4, 1, 1, 1</var> balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be <var>3</var>, which is the maximum result.</p></section> </div> </span>
p01468
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h2>問題文</h2> <p>$N$ 本の線分 $s_1, s_2, ..., s_N$ が䞎えられる。このずき、 dist$(s_i, s_j)$, ( $1 \leq i,j \leq N, i \ne j $ ) のずりうる最小倀を求めよ。 dist$(s_i, s_j)$ は</p> <ul><li>$\sqrt{(x_i-x_j)^2 + (y_i-y_j)^2}$, ( $(x_i,y_i)$ は $s_i$ 䞊の点、$(x_j,y_j)$ は $s_j$ 䞊の点)</li></ul> <p>のずりうる最小倀で定矩される。</p> <p>以䞋はSample Inputのデヌタセットを図瀺したものである。</p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample0" width="240" height="240"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample1" width="240" height="240"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample2" width="240" height="240"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample3" width="240" height="240"> </p> <h2>入力</h2> <p>入力は以䞋の圢匏に埓う。䞎えられる数は党お敎数である。</p> <pre> $N$ $x_{1,1}$ $y_{1,1}$ $x_{1,2}$ $y_{1,2}$ $x_{2,1}$ $y_{2,1}$ $x_{2,2}$ $y_{2,2}$ $...$ $x_{N,1}$ $y_{N,1}$ $x_{N,2}$ $y_{N,2}$ </pre> <p>$s_i$は$(x_{i,1}, y_{i,1})$$(x_{i,2}, y_{i,2})$を端点ずする線分である。</p> <h2>制玄</h2> <ul><li>$2 \leq N \leq 10^5$</li> <li>$0 \leq x_{i,j}, y_{i,j} \leq 100$</li> <li>$(x_{i,1}, y_{i,1}) \neq (x_{i,2}, y_{i,2})$</li></ul> <h2>出力</h2> <p>最小倀を1行に出力せよ。出力される倀には$10^{-5}$より倧きな誀差があっおはならない。</p> <h2>Sample Input 1</h2> <pre>4 2 0 2 25 0 30 15 20 16 20 5 15 23 0 23 30</pre> <h2>Output for the Sample Input 1</h2> <pre>0.41380294</pre> <h2>Sample Input 2</h2> <pre>6 0 0 0 5 1 3 3 5 6 0 6 10 7 4 10 4 11 1 11 3 7 0 10 0</pre> <h2>Output for the Sample Input 2</h2> <pre>1.00000000</pre> <h2>Sample Input 3</h2> <pre>6 5 5 5 45 7 45 19 45 7 30 19 30 21 34 21 44 26 45 36 28 45 45 26 5</pre> <h2>Output for the Sample Input 3</h2> <pre>0.83553169</pre> <h2>Sample Input 4</h2> <pre>11 10 10 10 90 10 90 35 90 10 60 35 60 35 60 35 90 40 10 40 90 37 45 60 45 60 10 60 45 65 10 65 90 65 90 90 90 65 60 90 65 90 60 90 90 </pre> <h2>Output for the Sample Input 4</h2> <pre>0.00000000</pre>
p03455
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer the deer found two positive integers, <var>a</var> and <var>b</var>. Determine whether the product of <var>a</var> and <var>b</var> is even or odd.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>a,b</var> <var>≀</var> <var>10000</var></li> <li><var>a</var> and <var>b</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the product is odd, print <code>Odd</code>; if it is even, print <code>Even</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Even </pre> <p>As <var>3 × 4 = 12</var> is even, print <code>Even</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 21 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Odd </pre> <p>As <var>1 × 21 = 21</var> is odd, print <code>Odd</code>.</p></section> </div> </span>
p01192
<H1><font color="#000"></font>Greedy, Greedy.</H1> <!-- Problem D--> <p> Once upon a time, there lived a dumb king. He always messes things up based on his whimsical ideas. This time, he decided to renew the kingdom’s coin system. Currently the kingdom has three types of coins of values 1, 5, and 25. He is thinking of replacing these with another set of coins. </p> <p> Yesterday, he suggested a coin set of values 7, 77, and 777. “They look so fortunate, don’t they?” said he. But obviously you can’t pay, for example, 10, using this coin set. Thus his suggestion was rejected. </p> <p> Today, he suggested a coin set of values 1, 8, 27, and 64. “They are all cubic numbers. How beautiful!” But another problem arises: using this coin set, you have to be quite careful in order to make changes efficiently. Suppose you are to make changes for a value of 40. If you use a greedy algorithm, i.e. continuously take the coin with the largest value until you reach an end, you will end up with seven coins: one coin of value 27, one coin of value 8, and five coins of value 1. However, you can make changes for 40 using five coins of value 8, which is fewer. This kind of inefficiency is undesirable, and thus his suggestion was rejected again. </p> <p> Tomorrow, he would probably make another suggestion. It’s quite a waste of time dealing with him, so let’s write a program that automatically examines whether the above two conditions are satisfied. </p> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case is given in a line with the format </p> <pre> <i>n</i> <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> . . . <i>c</i><sub><i>n</i></sub> </pre> <p> where <i>n</i> is the number of kinds of coins in the suggestion of the king, and each <i>c<sub>i</sub></i> is the coin value. </p> <p> You may assume 1 &le; <i>n</i> &le; 50 and 0 &lt; <i>c</i><sub>1</sub> &lt; <i>c</i><sub>2</sub> &lt; . . . &lt; <i>c</i><sub><i>n</i></sub> &lt; 1000. </p> <p> The input is terminated by a single zero. </p> <H2>Output</H2> <p> For each test case, print the answer in a line. The answer should begin with “Case #<i>i</i>: ”, where <i>i</i> is the test case number starting from 1, followed by </p> <ul> <li> “Cannot pay some amount” if some (positive integer) amount of money cannot be paid using the given coin set,</li> <li> “Cannot use greedy algorithm” if any amount can be paid, though not necessarily with the least possible number of coins using the greedy algorithm,</li> <li> “OK” otherwise.</li> </ul> <H2>Sample Input</H2> <pre> 3 1 5 25 3 7 77 777 4 1 8 27 64 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case #1: OK Case #2: Cannot pay some amount Case #3: Cannot use greedy algorithm </pre>
p01487
<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 B: RabbitWalking </h2> <p> うさぎの䜏んでいる郜垂には, $V$ 個の亀差点ず $E$ 本の道がある. 亀差点は 1-indexed で番号が付けられおいる. $i$ 番目の道は亀差点 $a_i$ ず亀差点 $b_i$ を bidirectional に぀ないでいる. </p> <p> うさぎは, 散歩ず奇数が奜きであるうさぎはある亀差点から出発し, 道を奇数本蟿り, 出発した頂点に戻るような経路に沿っお散歩したいず思っおいる </p> <p> この郜垂の垂長であるねこは, 郜垂内の移動を効率化するために異なる2 ぀の亀差点を結ぶ道をたくさん远加しようずしおいるただしある亀差点の組に察しお敷蚭するこずが出来る道は高々1本たでであるたた ねこはいたずら奜きなので道を奇数本蟿り, 出発した頂点に戻るような経路が含たれないようにしたいず思っおいる </p> <p> 最倧で䜕本道を付け加えられるか求めよ. ただし最初からうさぎの芁求が満たされおいる堎合は-1 を出力せよ. </p> <h3>Constraints</h3> <ul> <li>$V$ will be between 1 and 100,000, inclusive.</li> <li>$E$ will be between 0 and 100,000, inclusive.</li> <li>$a_i$ and $b_i$ will be distinct.</li> <li>No two roads connect the same pair of intersections.</li> </ul> <h3>Input</h3> <p> 入力は以䞋の圢匏で䞎えられる:<br> <br> $V$ $E$<br> $a_1$ $b_1$<br> ...<br> $a_E$ $b_E$<br> <br> </p> <h3>Output</h3> <p> 道を远加できる本数の最倧倀を衚す敎数を 1 行に出力せよ. 最初からうさぎの芁求が満たされおいる堎合は -1 を出力せよ. </p> <h3>Sample Input 1</h3> <pre>8 5 1 2 6 5 6 4 1 3 4 7</pre> <h3>Sample Output 1</h3> <pre>11</pre> <h3>Sample Input 2</h3> <pre>5 8 2 1 2 4 1 3 5 4 4 1 2 3 3 5 2 5</pre> <h3>Sample Output 2</h3> <pre>-1</pre>
p03140
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given three strings <var>A, B</var> and <var>C</var>. Each of these is a string of length <var>N</var> consisting of lowercase English letters.</p> <p>Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:</p> <ul> <li>Operation: Choose one of the strings <var>A, B</var> and <var>C</var>, and specify an integer <var>i</var> between <var>1</var> and <var>N</var> (inclusive). Change the <var>i</var>-th character from the beginning of the chosen string to some other lowercase English letter.</li> </ul> <p>What is the minimum number of operations required to achieve the objective?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li>Each of the strings <var>A, B</var> and <var>C</var> is a string of length <var>N</var>.</li> <li>Each character in each of the strings <var>A, B</var> and <var>C</var> is a lowercase English letter.</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 west east wait </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>In this sample, initially <var>A =</var> <code>west</code>、<var>B =</var> <code>east</code>、<var>C =</var> <code>wait</code>. We can achieve the objective in the minimum number of operations by performing three operations as follows:</p> <ul> <li>Change the second character in <var>A</var> to <code>a</code>. <var>A</var> is now <code>wast</code>.</li> <li>Change the first character in <var>B</var> to <code>w</code>. <var>B</var> is now <code>wast</code>.</li> <li>Change the third character in <var>C</var> to <code>s</code>. <var>C</var> is now <code>wast</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 different different different </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>If <var>A, B</var> and <var>C</var> are already equal in the beginning, the number of operations required is <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 zenkoku touitsu program </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>13 </pre></section> </div> </span>
p03510
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In a long narrow forest stretching east-west, there are <var>N</var> beasts. Below, we will call the point that is <var>p</var> meters from the west end Point <var>p</var>. The <var>i</var>-th beast from the west <var>(1 ≀ i ≀ N)</var> is at Point <var>x_i</var>, and can be sold for <var>s_i</var> yen (the currency of Japan) if captured.</p> <p>You will choose two integers <var>L</var> and <var>R</var> <var>(L ≀ R)</var>, and throw a net to cover the range from Point <var>L</var> to Point <var>R</var> including both ends, <var>[L, R]</var>. Then, all the beasts in the range will be captured. However, the net costs <var>R - L</var> yen and your profit will be <var>(</var>the sum of <var>s_i</var> over all captured beasts <var>i) - (R - L)</var> yen.</p> <p>What is the maximum profit that can be earned by throwing a net only once?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 2 × 10^5</var></li> <li><var>1 ≀ x_1 &lt; x_2 &lt; ... &lt; x_N ≀ 10^{15}</var></li> <li><var>1 ≀ s_i ≀ 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>x_1</var> <var>s_1</var> <var>x_2</var> <var>s_2</var> <var>:</var> <var>x_N</var> <var>s_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>When the maximum profit is <var>X</var> yen, print the value of <var>X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 10 20 40 50 60 30 70 40 90 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>90 </pre> <p>If you throw a net covering the range <var>[L = 40, R = 70]</var>, the second, third and fourth beasts from the west will be captured, generating the profit of <var>s_2 + s_3 + s_4 - (R - L) = 90</var> yen. It is not possible to earn <var>91</var> yen or more.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 10 2 40 5 60 3 70 4 90 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>The positions of the beasts are the same as Sample 1, but the selling prices dropped significantly, so you should not aim for two or more beasts. By throwing a net covering the range <var>[L = 40, R = 40]</var>, you can earn <var>s_2 - (R - L) = 5</var> yen, and this is the maximum possible profit.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 100 3 200 999999999999999 150 1000000000000000 150 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>299 </pre></section> </div> </span>
p00296
<h1>バトンリレヌゲヌム</h1> <p> アカベ高校では、毎幎党校生埒が参加するゲヌムを行っおいたす。たず、校庭に <var>N</var> 人の党校生埒が円圢に䞊びたす。図のように、各生埒は 0 から <var>N</var>-1 たでの番号が曞かれたれッケンを付けおいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_button" width="280"> </center> <br> <p> ゲヌムではバトンを本䜿い、最初はれッケン 0 番の生埒がバトンを持っおいたす。そこから、以䞋の手順を <var>M</var> 回繰り返したす。たず、珟時点でバトンを持っおいる生埒が適圓な正の敎数 <var>a</var> を宣蚀したす。<var>a</var> が偶数のずきは時蚈回り、奇数のずきは反時蚈回りに隣の生埒にバトンを枡しおいき、<var>a</var> 番目にバトンを受け取った生埒が脱萜したす。脱萜した生埒は、時蚈回りで隣の生埒にバトンを枡し、円から抜けたす。 </p> <p> ゲヌムが終わった埌に円に残った生埒は、攟課埌の掃陀が幎間免陀されたす。しかし、ここ数幎は生埒数が増えたため、党校生埒を集めるのが難しくなっおきおいたす。そこで、競技プログラミング郚のあなたは、シミュレヌションで掃陀が免陀される生埒を求めるプログラムを䜜成するよう頌たれたした。 </p> <p> 指定した生埒が掃陀を免陀されおいるかどうかを質問したずき、それに答えるプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>Q</var> <var>a</var><sub>1</sub> <var>a</var><sub>2</sub> ... <var>a<sub>M</sub></var> <var>q</var><sub>1</sub> <var>q</var><sub>2</sub> ... <var>q<sub>Q </sub></var> </pre> <p> 入力は行であり、行目に生埒の人数 <var>N</var> (10 &le; <var>N</var> &le; 200000)、繰り返し回数 <var>M</var> (5 &le; <var>M</var> &lt; <var>N</var>)、生埒が掃陀を免陀されるかどうかを問い合わせる質問の個数 <var>Q</var> (1 &le; <var>Q</var> &le; 1000) が䞎えられる。続く行に、<var>i</var> 回目の繰り返しで最初にバトンを持っおいる生埒が宣蚀する敎数<var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; 100) が䞎えられる。続く行に、質問ずしおれッケン番号 <var>q<sub>i</sub></var> (0 &le; <var>q</var> &lt; <var>N</var>) が䞎えられる。 </p> <h2>出力</h2> <p> 質問ごずに、れッケン番号 <var>q<sub>i</sub></var> の生埒が掃陀を免陀されるかどうかを <var>i</var> 行目に出力する。掃陀が免陀されるなら 1 を、されないなら 0 を出力する。 </p> <h2>入出力䟋</h2> <br> <h2>入力䟋 </h2> <pre> 10 5 3 2 6 5 18 3 3 0 5 </pre> <h2>出力䟋</h2> <pre> 1 0 1 </pre>
p03843
<span class="lang-en"> <p>Score : <var>1900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices. The vertices are numbered <var>1</var> through <var>N</var>. For each <var>1 ≀ i ≀ N - 1</var>, the <var>i</var>-th edge connects vertices <var>a_i</var> and <var>b_i</var>. The lengths of all the edges are <var>1</var>.</p> <p>Snuke likes some of the vertices. The information on his favorite vertices are given to you as a string <var>s</var> of length <var>N</var>. For each <var>1 ≀ i ≀ N</var>, <var>s_i</var> is <code>1</code> if Snuke likes vertex <var>i</var>, and <code>0</code> if he does not like vertex <var>i</var>.</p> <p>Initially, all the vertices are white. Snuke will perform the following operation exactly once:</p> <ul> <li>Select a vertex <var>v</var> that he likes, and a non-negative integer <var>d</var>. Then, paint all the vertices black whose distances from <var>v</var> are at most <var>d</var>.</li> </ul> <p>Find the number of the possible combinations of colors of the vertices after the operation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 2×10^5</var></li> <li><var>1 ≀ a_i, b_i ≀ N</var></li> <li>The given graph is a tree.</li> <li><var>|s| = N</var></li> <li><var>s</var> consists of <code>0</code> and <code>1</code>.</li> <li><var>s</var> contains at least one occurrence of <code>1</code>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li>In the test set worth <var>1300</var> points, <var>s</var> consists only of <code>1</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_{N - 1}</var> <var>b_{N - 1}</var> <var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the possible combinations of colors of the vertices after the operation.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 1 3 1 4 1100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The following four combinations of colors of the vertices are possible:</p> <div style="text-align: center;"> <img alt="334d566ec1f4f38d23cd580044f1cd07.png" src="https://atcoder.jp/img/agc008/334d566ec1f4f38d23cd580044f1cd07.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 2 1 3 1 4 4 5 11111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>11 </pre> <p>This case satisfies the additional constraint for the partial score.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 1 3 1 4 2 5 2 6 100011 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p02751
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have a grid with <var>(2^N - 1)</var> rows and <var>(2^M-1)</var> columns. You are asked to write <var>0</var> or <var>1</var> in each of these squares. Let <var>a_{i,j}</var> be 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.</p> <p>For a quadruple of integers <var>(i_1, i_2, j_1, j_2)</var> such that <var>1\leq i_1 \leq i_2\leq 2^N-1, 1\leq j_1 \leq j_2\leq 2^M-1</var>, let <var>S(i_1, i_2, j_1, j_2) = \displaystyle \sum_{r=i_1}^{i_2}\sum_{c=j_1}^{j_2}a_{r,c}</var>. Then, let the <em>oddness</em> of the grid be the number of quadruples <var>(i_1, i_2, j_1, j_2)</var> such that <var>S(i_1, i_2, j_1, j_2)</var> is odd.</p> <p>Find a way to fill in the grid that maximizes its oddness.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> and <var>M</var> are integers between <var>1</var> and <var>10</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print numbers to write in the grid so that its oddness is maximized, in the following format:</p> <pre><var>a_{1,1}a_{1,2}\cdots a_{1,2^M-1}</var> <var>a_{2,1}a_{2,2}\cdots a_{2,2^M-1}</var> <var>\vdots</var> <var>a_{2^N-1,1}a_{2^N-1,2}\cdots a_{2^N-1,2^M-1}</var> </pre> <p>If there are multiple solutions, you can print any of them.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>111 </pre> <p>For this grid, <var>S(1, 1, 1, 1)</var>, <var>S(1, 1, 2, 2)</var>, <var>S(1, 1, 3, 3)</var>, and <var>S(1, 1, 1, 3)</var> are odd, so it has the oddness of <var>4</var>.</p> <p>We cannot make the oddness <var>5</var> or higher, so this is one of the ways that maximize the oddness.</p></section> </div> </span>
p02301
<H1>Diameter of a Convex Polygon</H1> <br/> <p> Find the diameter of a convex polygon <var>g</var>. In other words, find a pair of points that have maximum distance between them. </p> <H2>Input</H2> <pre> <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> The first integer <var>n</var> is the number of points in <var>g</var>. </p> <p> In the following lines, the coordinate of the <var>i</var>-th point <var>p<sub>i</sub></var> is given by two real numbers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. The coordinates of points are given in the order of counter-clockwise visit of them. Each value is a real number with at most 6 digits after the decimal point. </p> <H2>Output</H2> <p> Print the diameter of <var>g</var> in a line. The output values should be in a decimal fraction with an error less than 0.000001. </p> <H2>Constraints</H2> <ul> <li> 3 &le; <var>n</var> &le; 80000 </li> <li> -100 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 100 </li> <li>No point in the <var>g</var> will occur more than once.</li> </ul> <H2>Sample Input 1</H2> <pre> 3 0.0 0.0 4.0 0.0 2.0 2.0 </pre> <H2>Sample Output 1</H2> <pre> 4.00 </pre> <H2>Sample Input 2</H2> <pre> 4 0.0 0.0 1.0 0.0 1.0 1.0 0.0 1.0 </pre> <H2>Sample Output 2</H2> <pre> 1.414213562373 </pre>
p00453
<H1> ぎょんぎょん川枡り </H1> <h2>問題</h2> <p> ある川で,䞀方の岞から石の䞊を次々ず飛び移っお反察偎の岞たで行くずいう少々危険なゲヌムがはやっおいる. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hyonhyon1"> </center> <br> <p> 今,図 4-1 のように,石はマス目の䞊に存圚するず考える.行の数は n である. 図 4-1 では n = 5 である. </p> <p> このゲヌムでは,䞀方の岞から始めお,通垞のゞャンプたたは m 回以䞋の䞀行飛ばしのゞャンプをしお反察偎の岞たで枡る.通垞のゞャンプずは,今いる行の䞀぀先の行の岞たたは石のどれかに飛び移るこずであり,䞀行飛ばしのゞャンプずは,今いる行の二぀先の行の岞たたは石のどれかに飛び移るこずである.始める岞の䞀぀先の行は 1 行目,二぀先の行は 2 行目であり,n − 1 行目の二぀先の行,及び n 行目の䞀぀先の行は反察偎の岞であるずする. </p> <p> さお,このゲヌムをできるだけ安党に成し遂げるために,ゞャンプの危険床ずいうものを考えるこずにした.それぞれの石には,滑りやすさが定たっおいる.石から石ぞ飛び移る際のゞャンプの危険床は,通垞のゞャンプであっおも,䞀行飛ばしのゞャンプであっおも, </p> <p> (今いる石の滑りやすさ + 飛び移る先の石の滑りやすさ)&times;(暪の移動距離) </p> <p> で定める.ただし,暪の移動距離ずは,列の番号の差である.たた,岞から石ぞ,あるいは石から岞ぞ飛び移るゞャンプの危険床は 0 ずする. </p> <p> 入力ずしお n, m,それぞれの石の䜍眮ず滑りやすさが䞎えられたずき,反察偎の岞たで到達する際のゞャンプの危険床の合蚈の最小倀を求めるプログラムを䜜成せよ.䞎えられる入力デヌタは必ず反察偎の岞たで到達するこずができるようになっおおり,同じマス目に石は 2 個以䞊存圚しない. </p> <h2>入力</h2> <p> <!-- 入力ファむルのファむル名は input.txt である.--> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 入力の 1 行目には,空癜を区切りずしお 2 個の敎数 n,m が曞かれおいる.これは,行の数ず,䞀行飛ばしのゞャンプの蚱される回数を衚す.n,m はそれぞれ 2 &le; n &le; 150, 0 &le; m &le; (n+1)/2 を満たす. </p> <p> 続く n 行には,それぞれの行にある石の情報が曞かれおいる.i+1 行目 (1 &le; i &le; n)には,1 ぀の敎数 k<sub>i</sub> (0 &le; k<sub>i</sub> &le; 10) ず,それに続き 2 &times; ki 個の敎数が空癜で区切られ曞かれおいる.これらは,始める岞から数えお i 番目の行にある石の情報を衚す. </p> <p> ki はその行に存圚する石の個数を衚し,それに続く 2 &times; ki 個の敎数に぀いおは,2 &times; j - 1 個目 (1 &le; j &le; k<sub>i</sub> ) の敎数 x<sub>i,j</sub> はその行の j 個目の石の列の番号を,2 &times; j個目の敎数 d<sub>i,j</sub> はその行の j 個目の石の滑りやすさをそれぞれ衚す.x<sub>i,j</sub> ,d<sub>i,j</sub> はそれぞれ 1 &le; x<sub>i,j</sub>, d<sub>i,j</sub> &le;1000 を満たす. </p> <p> 採点甚デヌタのうち, 配点の 20% 分に぀いおは, n &le; 6 を満たし,配点の別の 20%分に぀いおは, m = 0 を満たす. </p> <p> n, m がずもに 0 のずき入力の終了を瀺す. デヌタセットの数は 10 を超えない </p> <h2>出力</h2> <p> <!-- 出力ファむルのファむル名は output.txt である. output.txt は,反察偎の岞たで到達する際のゞャンプの危険床の合蚈の最小倀を衚す 1 ぀の敎数を含む 1 行からなる. --> デヌタセットごずに, 反察偎の岞たで到達する際のゞャンプの危険床の合蚈の最小倀を衚す 1 ぀の敎数を1 行に出力する. </p> <h2>䟋</h2> <p> 図 4-2 においお,石に曞かれた数字はそれぞれの石の滑りやすさを衚すずする. 矢印で瀺された順番で石を枡るずき,それぞれのゞャンプの危険床は,順番に 0, (2 + 2) &times; 1 = 4,(2 + 1) &times; 1 = 3,(1 + 4) &times; 2 = 10,0 であり,合蚈は 17 ずなる. このずき,ゞャンプの危険床の合蚈は最小ずなる. この䟋は぀目の入出力䟋に察応しおいる. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hyonhyon2"> </center> <br> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 5 1 2 1 3 2 2 1 3 2 1 1 7 1 2 1 1 4 4 5 0 2 1 3 2 2 1 3 2 1 1 7 1 2 1 1 4 4 0 0 </pre> <h3>出力䟋</h3> <pre> 17 40 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02194
<h2>Zero AND Subsets</h2> <p>非負敎数の倚重集合<var>a_1,a_2,..,a_N</var>が䞎えられたす。</p> <p>この集合の空でない郚分集合であっお、倀のbitwiseANDが<var>0</var>になるものはいく぀ありたすか。</p> <p>答えを<var>10^9+7</var>で割った䜙りを求めおください。</p> <h3>入力</h3> <pre> <var>N</var> <var>a_1 a_2...a_N</var> </pre> <h3>出力</h3> <p>答えを<var>10^9+7</var>で割った䜙りを出力せよ。</p> <h3>制玄</h3> <ul> <li><var>1 \leq N \leq 10^5 </var></li> <li><var>0 \leq a_i \leq 2^{20}-1</var></li> </ul> <h3>入力䟋</h3> <pre> 6 8 6 9 1 2 1 </pre> <h3>出力䟋</h3> <pre> 51 </pre>
p00003
<H1>Is it a Right Triangle?</H1> <p> Write a program which judges wheather given length of three side form a right triangle. Print "<span>YES</span>" if the given sides (integers) form a right triangle, "<span>NO</span>" if not so. </p> <H2>Input</H2> <p> Input consists of several data sets. In the first line, the number of data set, <var>N</var> is given. Then, <var>N</var> lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space. </p> <h2>Constraints</h2> <ul> <li> 1 &le; length of the side &le; 1,000</li> <li> <var>N</var> &le; 1,000</li> </ul> <H2>Output</H2> <p> For each data set, print "<span>YES</span>" or "<span>NO</span>". </p> <H2>Sample Input</H2> <pre> 3 4 3 5 4 3 6 8 8 8 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO NO </pre>
p01242
<H1><font color="#000">Problem I:</font> Revenge of Voronoi</H1> <p> A discrete Voronoi diagram is a derivation of a Voronoi diagram. It is represented as a set of pixels. Each of the generatrices lies on the center of some pixel. Each pixel belongs to the generatrix nearest from the center of the pixel in the sense of Manhattan distance. The Manhattan distance <i>d</i> between two points (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) and (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) is given by the following formula: </p> <center> <p> <i>d</i> = |<i>x</i><sub>1</sub> - <i>x</i><sub>2</sub>| + |<i>y</i><sub>1</sub> - <i>y</i><sub>2</sub>| </p> </center> <p> Your task is to find a set of generatrices which generates a given discrete Voronoi diagram. In the given diagram, each generatrix is given a unique lowercase letter as its identifier, and each pixel is represented by the identifier of the generatrix the pixel belongs to. If a pixel has multiple generatrices at the same distance from its center, it belongs to the generatrix with the most preceding identifier among them (i.e. the smallest character code). </p> <H2>Input</H2> <p> The input consists of multiple test cases. </p> <p> Each test case begins with a line containing two integers <i>W</i> (1 &le; <i>W</i> &le; 32) and <i>H</i> (1 &le; <i>H</i> &le; 32), which denote the width and height of the discrete Voronoi diagram. </p> <p> The following <i>H</i> lines, each of which consists of <i>W</i> letters, give one discrete Voronoi diagram. Each letter represents one pixel. </p> <p> The end of input is indicated by a line with two zeros. This is not a part of any test cases. </p> <H2>Output</H2> <p> For each test case, print the case number and the coordinates of generatrices as shown in the sample output. Each generatrix line should consist of its identifier, <i>x</i>-coordinate, and <i>y</i>-coordinate. Generatrices should be printed in alphabetical order of the identifiers. Each coordinate is zero-based where (0, 0) indicates the center of the top-left corner pixel of the diagram. </p> <p> You may assume that every test case has at least one solution. If there are multiple solutions, any one is acceptable. </p> <p> Print a blank line after every test case including the last one. </p> <H2>Sample Input</H2> <pre> 4 3 ooxx ooxx ooxx 4 1 null 4 4 aabb aabb ccdd ccdd 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: o 0 0 x 2 0 Case 2: l 2 0 n 0 0 u 1 0 Case 3: a 0 0 b 2 0 c 0 2 d 2 2 </pre>
p02897
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is an integer <var>N</var>.</p> <p>Takahashi chooses an integer <var>a</var> from the positive integers not greater than <var>N</var> with equal probability.</p> <p>Find the probability that <var>a</var> is odd.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the probability that <var>a</var> is odd. Your output will be considered correct when its absolute or relative error from the judge's output is at most <var>10^{-6}</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>0.5000000000 </pre> <p>There are four positive integers not greater than <var>4</var>: <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>. Among them, we have two odd numbers: <var>1</var> and <var>3</var>. Thus, the answer is <var>\frac{2}{4} = 0.5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0.6000000000 </pre> </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.0000000000 </pre></section> </div> </span>
p03785
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Every day, <var>N</var> passengers arrive at Takahashi Airport. The <var>i</var>-th passenger arrives at time <var>T_i</var>.</p> <p>Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to <var>C</var> passengers. Naturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport. Also, a passenger will get angry if he/she is still unable to take a bus <var>K</var> units of time after the arrival of the airplane. For that reason, it is necessary to arrange buses so that the <var>i</var>-th passenger can take a bus departing at time between <var>T_i</var> and <var>T_i + K</var> (inclusive).</p> <p>When setting the departure times for buses under this condition, find the minimum required number of buses. Here, the departure time for each bus does not need to be an integer, and there may be multiple buses that depart at the same time.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100000</var></li> <li><var>1 \leq C \leq 10^9</var></li> <li><var>1 \leq K \leq 10^9</var></li> <li><var>1 \leq T_i \leq 10^9</var></li> <li><var>C</var>, <var>K</var> and <var>T_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>C</var> <var>K</var> <var>T_1</var> <var>T_2</var> <var>:</var> <var>T_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum required number of buses.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 5 1 2 3 6 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>For example, the following three buses are enough:</p> <ul> <li>A bus departing at time <var>4.5</var>, that carries the passengers arriving at time <var>2</var> and <var>3</var>.</li> <li>A bus departing at time <var>6</var>, that carries the passengers arriving at time <var>1</var> and <var>6</var>.</li> <li>A bus departing at time <var>12</var>, that carries the passenger arriving at time <var>12</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 3 7 6 2 8 10 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre></section> </div> </span>
p04040
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p> <p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p> <p>Find the number of ways she can travel to the bottom-right cell.</p> <p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var> 1 ≩ H, W ≩ 100,000</var></li> <li><var> 1 ≩ A &lt; H</var></li> <li><var> 1 ≩ B &lt; W</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>H</var> <var>W</var> <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 7 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3570 </pre> <p>There are <var>12</var> forbidden cells.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100000 100000 99999 99999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100000 100000 44444 55555 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>738162020 </pre></section> </div> </span>
p00900
<H1><font color="#000">Problem G: </font>Captain Q&prime;s Treasure</H1> <p> You got an old map, which turned out to be drawn by the infamous pirate &ldquo;Captain Q&rdquo;. It shows the locations of a lot of treasure chests buried in an island. </p> <p> The map is divided into square sections, each of which has a digit on it or has no digit. The digit represents the number of chests in its 9 neighboring sections (the section itself and its 8 neighbors). You may assume that there is at most one chest in each section. </p> <p> Although you have the map, you can't determine the sections where the chests are buried. Even the total number of chests buried in the island is unknown. However, it is possible to calculate the minimum number of chests buried in the island. Your mission in this problem is to write a program that calculates it. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is formatted as follows. </p> <p> <i>h w<br> map</i> </p> <p> The first line of a dataset consists of two positive integers <i>h</i> and <i>w</i>. <i>h</i> is the height of the map and w is the width of the map. You may assume 1&le;<i>h</i>&le;15 and 1&le;<i>w</i>&le;15. </p> <p> The following h lines give the map. Each line consists of w characters and corresponds to a horizontal strip of the map. Each of the characters in the line represents the state of a section as follows. </p> <p> &lsquo;.&rsquo;: The section is not a part of the island (water). No chest is here. </p> <p> &lsquo;*&rsquo;: The section is a part of the island, and the number of chests in its 9 neighbors is not known. </p> <p> &lsquo;0&rsquo;-&lsquo;9&rsquo;: The section is a part of the island, and the digit represents the number of chests in its 9 neighbors. </p> <p> You may assume that the map is not self-contradicting, i.e., there is at least one arrangement of chests. You may also assume the number of sections with digits is at least one and at most 15. </p> <p> A line containing two zeros indicates the end of the input. </p> <H2>Output</H2> <p> For each dataset, output a line that contains the minimum number of chests. The output should not contain any other character. </p> <H2>Sample Input</H2> <pre> 5 6<br>*2.2**<br>..*...<br>..2...<br>..*...<br>*2.2**<br>6 5<br>.*2*.<br>..*..<br>..*..<br>..2..<br>..*..<br>.*2*.<br>5 6<br>.1111.<br>**...*<br>33....<br>**...0<br>.*2**.<br>6 9<br>....1....<br>...1.1...<br>....1....<br>.1..*..1.<br>1.1***1.1<br>.1..*..1.<br>9 9<br>*********<br>*4*4*4*4*<br>*********<br>*4*4*4*4*<br>*********<br>*4*4*4*4*<br>*********<br>*4*4*4***<br>*********<br>0 0 </pre> <H2>Output for the Sample Input</H2> <pre>6<br>5<br>5<br>6<br>23</pre>
p01612
<h2>瀟員旅行</h2> <h2>Problem Statement</h2> <p>あなたの䌚瀟には<var>n</var>人の瀟員が存圚する<var>m</var>個の瀟員<var>(a_i,b_i)</var>の組に぀いお<var>a_i</var>は<var>b_i</var>の䞊叞である</p> <p>瀟員<var>x</var>が瀟員<var>y</var>の実質的な䞊叞であるずは次のうち少なくずも䞀方が成り立぀こずをいう<br /></p> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>x</var>が<var>y</var>の䞊叞である</li> <li><var>y</var>の実質的な䞊叞である瀟員<var>z</var>が存圚しお<var>x</var>は<var>z</var>の䞊叞である</li></ul> <p>あなたの䌚瀟で自分自身が自分の実質的な䞊叞であるような瀟員は存圚しない</p> <p>あなたの䌚瀟では瀟員が党員参加する瀟員旅行が蚈画されおいる党瀟員の芁求により旅通での郚屋割りは「よい郚屋割り」でなければならない<br /> ある郚屋割りが「よい郚屋割り」であるずは以䞋の䞡方が満たされるこずをいう<br /></p> <ul class="list1" style="padding-left:16px;margin-left:16px"><li>各瀟員はどこかの郚屋に割り振られる</li> <li>瀟員<var>x</var>ず瀟員<var>y</var>が同じ郚屋に割り振られおいるずき<var>x</var>は<var>y</var>の実質的な䞊叞でない</li></ul> <p>幹事の瀟員は非垞に優秀なので「よい郚屋割り」でか぀必芁な郚屋の数が最小になるように郚屋割りを行ったしかし残念なこずに予算が䞍足しおいるどうしおも必芁な郚屋の数を枛らさなければならないらしい<br /> そこで人事郚で働くあなたは䞊叞-郚䞋の関係を䞀぀だけ解消するこずによっお「よい郚屋割り」を埗るために必芁な郚屋の数を枛らすこずにした<br /> さおどの関係を解消すればよいのだろう</p> <h2>Input</h2> <p>入力は以䞋の圢匏に埓う䞎えられる数は党お敎数である</p> <pre><var>n</var> <var>m</var> <var>a_1</var> <var>b_1</var> <var>...</var> <var>a_m</var> <var>b_m</var></pre> <h2>Constraints</h2> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>2≩n≩10^5</var></li> <li><var>1≩m≩2 \times 10^5</var></li> <li><var>1≩a_i&lt;b_i≩n</var></li> <li><var>i \neq j</var>ならば<var>(a_i, b_i) \neq (a_j, b_j)</var></li></ul> <h2>Output</h2> <p>次を満たすような<var>i</var>を昇順に1行ず぀出力せよ</p> <ul class="list1" style="padding-left:16px;margin-left:16px"><li>「<var>a_i</var>が<var>b_i</var>の䞊叞である」ずいう関係を解消したずき「よい郚屋割り」を埗るために必芁な郚屋の数を枛らすこずができる</li></ul> <p>そのような<var>i</var>が存圚しない堎合は-1を1行に出力せよ</p> <h2>Sample Input 1</h2> <pre>5 4 1 2 2 3 3 4 3 5</pre> <h2>Output for the Sample Input 1</h2> <pre>1 2</pre>
p01307
<h1><font color="#000">Problem E:</font> 足し算ゲヌム</h1> <p> ねこのファヌブルは足し算を甚いた簡単なゲヌムを思い぀き、同じくねこで友達のオヌドリヌず䞀緒にやっおみるこずにした。 </p> <p> ゲヌムのルヌルは次のようなものである。たず最初に、適圓な正の敎数を遞び、そこからスタヌトする。各プレヌダヌは、その数のうち隣り合う2぀の桁を遞択しお和を蚈算し、もずの2぀の数字ず眮き換える。たずえば、「1234」の十の䜍ず癟の䜍を遞ぶず、次の数は「154」ずなる。「5555」の十の䜍ず癟の䜍を遞んだ堎合は「5105」ずなる。このような操䜜を数が1桁になるたで亀互に繰り返し、操䜜ができなくなったプレヌダヌが負けずなる。 </p> <p> ゲヌム開始時の敎数の倀が䞎えられる。先攻であるファヌブルず埌攻であるオヌドリヌがいずれも最適な戊略を取るずき、どちらが勝぀のかを刀定するプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は、ゲヌム開始時の数を衚す1000桁以䞋の正の敎数が1぀曞かれた1行のみからなる。なお、最䞊䜍の桁は0ではない。 </p> <h2>Output</h2> <p> ファヌブルが勝぀なら "Fabre wins."、オヌドリヌが勝぀なら "Audrey wins." ず1行に出力せよ。最埌にピリオドを぀ける必芁があるこずに泚意するこず。 </p> <h2>Notes on Submission</h2> <p> 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 </p> <h2>Sample Input</h2> <pre> 3 1234 5555 9 </pre> <h2>Output for the Sample Input</h2> <pre> Audrey wins. Fabre wins. Audrey wins. </pre>
p03290
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A programming competition site <em>AtCode</em> provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer <var>i</var> between <var>1</var> and <var>D</var> (inclusive), there are <var>p_i</var> problems with a score of <var>100i</var> points. These <var>p_1 + 
 + p_D</var> problems are all of the problems available on AtCode.</p> <p>A user of AtCode has a value called <em>total score</em>. The total score of a user is the sum of the following two elements:</p> <ul> <li>Base score: the sum of the scores of all problems solved by the user.</li> <li>Perfect bonuses: when a user solves all problems with a score of <var>100i</var> points, he/she earns the perfect bonus of <var>c_i</var> points, aside from the base score <var>(1 ≀ i ≀ D)</var>.</li> </ul> <p>Takahashi, who is the new user of AtCode, has not solved any problem. His objective is to have a total score of <var>G</var> or more points. At least how many problems does he need to solve for this objective?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ D ≀ 10</var></li> <li><var>1 ≀ p_i ≀ 100</var></li> <li><var>100 ≀ c_i ≀ 10^6</var></li> <li><var>100 ≀ G</var></li> <li>All values in input are integers.</li> <li><var>c_i</var> and <var>G</var> are all multiples of <var>100</var>.</li> <li>It is possible to have a total score of <var>G</var> or more points.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>D</var> <var>G</var> <var>p_1</var> <var>c_1</var> <var>:</var> <var>p_D</var> <var>c_D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of problems that needs to be solved in order to have a total score of <var>G</var> or more points. Note that this objective is always achievable (see Constraints).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 700 3 500 5 800 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>In this case, there are three problems each with <var>100</var> points and five problems each with <var>200</var> points. The perfect bonus for solving all the <var>100</var>-point problems is <var>500</var> points, and the perfect bonus for solving all the <var>200</var>-point problems is <var>800</var> points. Takahashi's objective is to have a total score of <var>700</var> points or more.</p> <p>One way to achieve this objective is to solve four <var>200</var>-point problems and earn a base score of <var>800</var> points. However, if we solve three <var>100</var>-point problems, we can earn the perfect bonus of <var>500</var> points in addition to the base score of <var>300</var> points, for a total score of <var>800</var> points, and we can achieve the objective with fewer problems.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2000 3 500 5 800 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> <p>This case is similar to Sample Input 1, but the Takahashi's objective this time is <var>2000</var> points or more. In this case, we inevitably need to solve all five <var>200</var>-point problems, and by solving two <var>100</var>-point problems additionally we have the total score of <var>2000</var> points.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 400 3 500 5 800 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre> <p>This case is again similar to Sample Input 1, but the Takahashi's objective this time is <var>400</var> points or more. In this case, we only need to solve two <var>200</var>-point problems to achieve the objective.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 25000 20 1000 40 1000 50 1000 30 1000 1 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>66 </pre> <p>There is only one <var>500</var>-point problem, but the perfect bonus can be earned even in such a case. </p></section> </div> </span>
p02878
<span class="lang-en"> <p>Score : <var>2200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have two indistinguishable pieces placed on a number line. Both pieces are initially at coordinate <var>0</var>. (They can occupy the same position.)</p> <p>We can do the following two kinds of operations:</p> <ul> <li>Choose a piece and move it to the right (the positive direction) by <var>1</var>.</li> <li>Move the piece with the smaller coordinate to the position of the piece with the greater coordinate. If two pieces already occupy the same position, nothing happens, but it still counts as doing one operation.</li> </ul> <p>We want to do a total of <var>N</var> operations of these kinds in some order so that one of the pieces will be at coordinate <var>A</var> and the other at coordinate <var>B</var>. Find the number of ways to move the pieces to achieve it. The answer can be enormous, so compute the count modulo <var>998244353</var>.</p> <p>Two ways to move the pieces are considered different if and only if there exists an integer <var>i</var> (<var>1 \leq i \leq N</var>) such that the set of the coordinates occupied by the pieces after the <var>i</var>-th operation is different in those two ways.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^7</var></li> <li><var>0 \leq A \leq B \leq N</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to move the pieces to achieve our objective, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>Shown below are the four ways to move the pieces, where <var>(x,y)</var> represents the state where the two pieces are at coordinates <var>x</var> and <var>y</var>.</p> <ul> <li><var>(0,0)→(0,0)→(0,1)→(0,2)→(0,3)→(1,3)</var></li> <li><var>(0,0)→(0,0)→(0,1)→(0,2)→(1,2)→(1,3)</var></li> <li><var>(0,0)→(0,0)→(0,1)→(1,1)→(1,2)→(1,3)</var></li> <li><var>(0,0)→(0,1)→(1,1)→(1,1)→(1,2)→(1,3)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 0 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>10 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>197 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1000000 100000 200000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>758840509 </pre></section> </div> </span>
p00845
<H1><font color="#000">Problem A:</font> How I Wonder What You Are!</H1> <p> One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be limited, you may find much less at a time. </p> <p> Children may ask the same questions to their parents on a planet of some solar system billions of light-years away from the Earth. Their telescopes are similar to ours with circular sight fields, but alien kids have many eyes and can look into different directions at a time through many telescopes. </p> <p> Given a set of positions of stars, a set of telescopes and the directions they are looking to, your task is to count up how many stars can be seen through these telescopes. </p> <H2>Input</H2> <p> The input consists of one or more datasets. The number of datasets is less than 50. Each dataset describes stars and the parameters of the telescopes used. </p> <p> The first line of a dataset contains a positive integer <i>n</i> not exceeding 500, meaning the number of stars. Each of the <i>n</i> lines following it contains three decimal fractions, <i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, and <i>s<sub>z</sub></i>. They give the position (<i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, <i>s<sub>z</sub></i>) of the star described in Euclidean coordinates. You may assume -1000 &le; <i>s<sub>x</sub></i> &le; 1000, -1000 &le; <i>s<sub>y</sub></i> &le; 1000, -1000 &le; <i>s<sub>z</sub></i> &le; 1000 and (<i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, <i>s<sub>z</sub></i>) &ne; (0, 0, 0). </p> <p> Then comes a line containing a positive integer <i>m</i> not exceeding 50, meaning the number of telescopes. Each of the following <i>m</i> lines contains four decimal fractions, <i>t<sub>x</sub></i>, <i>t<sub>y</sub></i>, <i>t<sub>z</sub></i>, and <i>&phi;</i>, describing a telescope. </p> <p> The first three numbers represent the direction of the telescope. All the telescopes are at the origin of the coordinate system (0, 0, 0) (we ignore the size of the planet). The three numbers give the point (<i>t<sub>x</sub></i>, <i>t<sub>y</sub></i>, <i>t<sub>z</sub></i>) which can be seen in the center of the sight through the telescope. You may assume -1000 &le; <i>t<sub>x</sub></i> &le; 1000, -1000 &le; <i>t<sub>y</sub></i> &le; 1000, -1000 &le; <i>t<sub>z</sub></i> &le; 1000 and (<i>t<sub>x</sub></i>, <i>t<sub>y</sub></i>, <i>t<sub>z</sub></i>) &ne; (0, 0, 0). </p> <p> The fourth number <i>&phi;</i> (0 &le; <i>&phi;</i> &le; <i>&pi;</i>/2) gives the angular radius, in radians, of the sight field of the telescope. </p> <p> Let us defie that <i>&theta;<sub>i,j</sub></i> is the angle between the direction of the <i>i</i>-th star and the center direction of the <i>j</i>-th telescope and <i>&phi;<sub>j</sub></i>is the angular radius of the sight field of the <i>j</i>-th telescope. The <i>i</i>-th star is observable through the <i>j</i>-th telescope if and only if <i>&theta;<sub>i,j</sub></i> is less than . You may assume that |<i>&theta;<sub>i,j</sub></i> - <i>&phi;<sub>j</sub></i>| &gt; 0.00000001 for all pairs of <i>i</i> and <i>j</i>. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_howIWonder"><br/> <p>Figure 1: Direction and angular radius of a telescope</p> </center> <p> The end of the input is indicated with a line containing a single zero. </p> <H2>Output</H2> <p> For each dataset, one line containing an integer meaning the number of stars observable through the telescopes should be output. No other characters should be contained in the output. Note that stars that can be seen through more than one telescope should not be counted twice or more. </p> <H2>Sample Input</H2> <pre> 3 100 0 500 -500.243 -200.1 -300.5 0 300 200 2 1 1 1 0.65 -1 0 0 1.57 3 1 0 0 0 1 0 0 0 1 4 1 -1 -1 0.9553 -1 1 -1 0.9554 -1 -1 1 0.9553 -1 1 -1 0.9554 3 1 0 0 0 1 0 0 0 1 4 1 -1 -1 0.9553 -1 1 -1 0.9553 -1 -1 1 0.9553 -1 1 -1 0.9553 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 1 0 </pre>
p01757
<p> 今幎も党囜プログラミング遞手暩倧䌚の時期がやっおきた党囜倧䌚の参加暩を賭けた地区倧䌚は <var>2<sup>n</sup></var> チヌムが1 察1 の勝ち残り匏トヌナメント方匏で察決する </p> <p> トヌナメント衚にはチヌム番号 <var>0, . . . 2<sup>n</sup> &minus; 1</var> が割り振られおおり1 回戊から <var>n</var> 回戊たでの察決手順は次の通りである </p> <ol> <li> 1 回戊ではチヌム番号が <var>l</var> のチヌムずチヌム番号が <var>l</var> + 1 のチヌムが察決する(<var>l</var> &equiv; 0 (mod 2)) </li> <li> <var>i + 1</var> 回戊(<var>1 &le; i &lt; n</var>) では「チヌム番号が <var>l</var> 以䞊 <var>l + 2<sup>i</sup></var> 未満のチヌムのうち <var>i</var> 回戊たでの察決で 1 回も負けおいないチヌム」ず「チヌム番号が <var>l + 2<sup>i</sup></var> 以䞊 <var>l + 2<sup>i+1</sup></var> 未満のチヌムのうち <var>i</var> 回戊たでの察決で䞀回も負けおいないチヌム」が察決する(<var>l</var> &equiv; 0 (mod 2<sup><var>i</var>+1</sup>)) </ol> <p> <var>n</var> 回戊たで終わるず各チヌムの順䜍は 2<sup><var>n</var> &minus; (そのチヌムが勝った回数)</sup> 䜍で確定するなおこの察決には匕き分けが存圚しないため察決したチヌムのいずれか䞀方が勝ちもう䞀方が負ける </p> <p> 晎れお地区倧䌚の代衚に遞ばれた私達は他の地区倧䌚の結果をマネヌゞャヌに調べおもらうこずにしたここで調べおもらった結果が「マネヌゞャヌから受け取った順䜍衚」であった「マネヌゞャヌから受け取った順䜍衚」をより詳现に説明するず長さ 2<sup><var>n</var></sup> の数列で <var>i ( 0 &le; i &le; 2<sup>n</sup> &minus; 1 )</var> 番目の芁玠にチヌム番号 <var>i</var> のチヌムの順䜍が曞かれおいるものである </p> <p> だが「マネヌゞャヌから受け取った順䜍衚」には同じ順䜍が倧量に䞊んでいたトヌナメントのルヌル䞊同じ順䜍が倧量に䞊ぶなんおありえないはずだそこで「マネヌゞャヌから受け取った順䜍衚」を「無矛盟な順䜍衚」にするために順䜍を倉曎するチヌム数の最小倀を蚈算しおどのくらい順䜍衚が間違っおいるかをマネヌゞャヌに教えおあげよう「無矛盟な順䜍衚」ずは順䜍が確定したトヌナメントの結果ずしお起こりうる順䜍衚のこずを衚す </p> <h3>Input</h3> <p> 入力には「マネヌゞャヌから受け取った順䜍衚」が以䞋の圢匏で䞎えられる </p> <pre> <var>n</var> <var>m</var> <var>a<sub>0</sub></var> <var>a<sub>1</sub></var> . . . <var>a<sub>m</sub></var> <var>b<sub>0</sub></var> <var>b<sub>1</sub></var> . . . <var>b<sub>m&minus;1</sub></var> </pre> <ul> <li> 1 行目は <var>n, m</var> の2 個の敎数からなり 2<sup><var>n</var></sup> は「地区倧䌚の参加チヌム数」<var>m</var> は「『マネヌゞャヌから受け取った順䜍衚』で連続した順䜍が䞊んでいる区間の個数」を衚す</li> <li> 2 行目は <var>a<sub>i</sub>(0 &le; i &le; m)</var> の <var>m + 1</var> 個の敎数からなり各 <var>a<sub>i</sub></var> は「『マネヌゞャヌから受け取った順䜍衚』で連続した順䜍が䞊んでいる区間の区切り䜍眮」を衚す </li> <li> 3 行目は <var>b<sub>i</sub>(0 &le; i &lt; m)</var> の <var>m</var> 個の敎数からなり各2<sup><var>b<sub>i</sub></var></sup> は「『マネヌゞャヌから受け取った順䜍衚』におけるチヌム番号が <var>a<sub>i</sub></var> 以䞊 <var>a<sub>i+1</sub></var> 未満のチヌムの順䜍」を衚す </li> </ul> <h3>Constraints</h3> <ul> <li> 1 &le; <var>n</var> &le; 30</li> <li> 1 &le; <var>m</var> &le; 10,000</li> <li> <var>0 = a<sub>0</sub> &lt; a<sub>1</sub> &le; . . . &le; a<sub>m&minus;1</sub> &lt; a<sub>m</sub> = 2<sup>n</sup></var></li> <li> 0 &le; <var>b<sub>i</sub></var> &le; <var>n</var></li> </ul> <h3>Output</h3> <p> 「マネヌゞャヌから受け取った順䜍衚」を「無矛盟な順䜍衚」にするために順䜍を倉曎するチヌム数の最小倀を1 行に出力せよ </p> <h3>Sample Input 1</h3> <pre> 1 1 0 2 1 </pre> <h3>Output for the Sample Input 1</h3> <pre> 1 </pre> <p> 参加チヌム数が2 の「無矛盟な順䜍衚」は{"チヌム番号 0 のチヌムの順䜍", "チヌム番号 1 のチヌムの順䜍"} ずしお {1, 2} ず {2, 1} の2 通りがある順䜍衚 {2, 2} を「無矛盟な順䜍衚」に修正するためにはいずれかのチヌムの順䜍を 1 に倉曎しなければならない </p> <h3>Sample Input 2</h3> <pre> 2 3 0 1 2 4 0 1 2 </pre> <h3>Output for the Sample Input 2</h3> <pre> 2 </pre> <h3>Sample Input 3</h3> <pre> 2 3 0 1 3 4 0 2 1 </pre> <h3>Output for the Sample Input 3</h3> <pre> 0 </pre> <h3>Sample Input 4</h3> <pre> 4 5 0 1 2 4 8 16 0 1 2 3 4 </pre> <h3>Output for the Sample Input 4</h3> <pre> 10 </pre>
p00516
<H1>問題 2:  投祚 (Vote) </H1> <br/> <h2>問題</h2> <p> 20XX幎に東京で䞖界的なスポヌツ倧䌚が開かれるこずになったプログラミングコンテストはスポヌツずしお䞖界で楜したれおおり競技ずしお採甚される可胜性がある採甚される競技を決める審査委員䌚に぀いお調べたずころ次のようなこずが分かった </p> <ul> <li> 審査委員䌚のために候補ずなる N 個の競技を面癜い方から順番に䞊べたリストが䜜成されたリストの䞊から i 番目には i 番目に面癜い競技が曞かれおいるそれを競技 i ずするさらに競技 i の開催に必芁な費甚 A<sub>i</sub> が曞かれおいる </li> <li>たた審査委員䌚は委員 1 から委員 M たでの M 人の委員で構成されおいる委員 j は自分の審査基準 B<sub>j</sub> をもっおおり開催に必芁な費甚が B<sub>j</sub> 以䞋の競技のうち最も面癜いものに 1 祚を投祚した </li> <li> どの委員の審査基準に察しおも少なくずも 1 ぀の競技は開催に必芁な費甚が審査基準以䞋であったしたがっお委員は党員 1 祚を投祚した </li> <li> 最も倚く祚を獲埗した競技は 1 ぀だけであった </li> </ul> <p> 競技のリストず委員の情報が䞎えられたずき最も倚く祚を獲埗した競技の番号を求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は 1 + N + M 行からなる </p> <p> 1 行目には敎数 N, M (1 &le; N &le; 10001 &le; M &le; 1000) が曞かれおおりそれぞれ競技の数委員の数を衚す </p> <p> 続く N 行のうちの i 行目 (1 &le; i &le; N) には敎数 A<sub>i</sub> (1 &le; A<sub>i</sub> &le; 1000) が曞かれおおり 競技 i の開催に必芁な費甚 A<sub>i</sub> を衚す </p> <p> 続く M 行のうちの j 行目 (1 &le; j &le; M) には敎数 B<sub>j</sub> (1 &le; B<sub>j</sub> &le; 1000) が曞かれおおり委員 j の審査基準 B<sub>j</sub> を衚す </p> <p> 䞎えられる入力デヌタにおいおはどの委員も必ず 1 祚を投祚し最も倚く祚を獲埗した競技は 1 ぀であるこずが保蚌されおいる </p> <h2>出力</h2> <p> 最も倚く祚を獲埗した競技の番号を 1 行で出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 4 3 5 3 1 4 4 3 2 </pre> <h3>出力䟋 1</h3> <pre> 2 </pre> <p> 入出力䟋 1 では競技は 4 ぀あり委員は 3 人いるリストの 4 ぀の競技にかかる費甚はそれぞれ 5, 3, 1, 4 である </p> <ul> <li>委員 1 の審査基準は 4 である費甚が 4 以䞋の競技のうち最も面癜いものは競技 2 である</li> <li>委員 2 の審査基準は 3 である費甚が 3 以䞋の競技のうち最も面癜いものは競技 2 である</li> <li>委員 3 の審査基準は 2 である費甚が 2 以䞋の競技のうち最も面癜いものは競技 3 である</li> </ul> <p> よっお競技 2 が 2 祚競技 3 が 1 祚を獲埗する最も倚く祚を獲埗した競技は競技 2 であるので2 を出力する </p> <h3>入力䟋 2</h3> <pre> 6 6 3 1 4 1 5 9 2 6 5 3 5 9 </pre> <h3>出力䟋 2</h3> <pre> 1 </pre> <p> 入出力䟋 2 では競技 1 が 5 祚競技 2 が 1 祚を獲埗する最も倚く祚を獲埗した競技は競技 1 なので1 を出力する </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00146
<H1>ルパン四䞖</H1> <p> 怪盗「ルパン四䞖」は䌚接藩士を末裔ずする矎女「富士峰子」より、䌚接若束垂に䌚接藩が残した軍資金が眠っおいるこずを聞かされる。ルパンの長幎の仲間である「石川越ェ門」の報告によれば、軍資金は千䞡箱に収められいく぀かの蔵に保管されおいる。蔵に芋匵りはいないが厳重に斜錠されおいる。しかし、越ェ門は圌が父から䌝授された秘䌝「鋌鉄斬り」の技を繰り出せば瞬時に蔵を砎れるずいう。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lupin"> </center> <br/> <p> 残った問題は千䞡箱の運搬だ。䜓力のないルパンず越ェ門は千䞡箱を䞀぀も持おない。そこで、頌りになる男「無限倧介」に運搬を頌んだ。<!--倧介は米俵を䜿った蚓緎を重ね、超人的な運搬胜力を身に぀けた。--> すべおの千䞡箱を運び出すために、ルパンは以䞋のような蚈画を立案した。 </p> <p> たず、ルパンの運転で最初の蔵ぞ行き、越ェ門ず倧介を降ろす。 </p> <ul> <li>越ェ門が蔵を砎る</li> <li>倧介がすべおの千䞡箱を運び出す</li> <li>その千䞡箱を持ったたたルパンが決めた次の蔵ぞ向かう</li> </ul> <p> これを繰り返し、最埌の蔵たで砎り千䞡箱を運び出す。その間にルパンはヘリコプタヌを準備し最埌の蔵で二人ず千䞡箱を運び䞊げ脱出する。倧介はどんなに重いものも運搬できるが、荷物の重さに応じお移動速床は遅くなる。ルパンは、このこずを考慮しお蔵を砎る順番を決めなければならない。 </p> <p> ルパンに代わっお、最初の蔵を砎っおから最埌の蔵に蟿り぀くたでの移動時間が最小ずなるような蔵を砎る順番を出力するプログラムを䜜成しおください。ただし、 </p> <ul> <li>蔵はすべお鶎ヶ城からたっすぐ北に走る通りに面しおいる。蔵の数は高々 15 個であり、城からの距離は高々 10000 メヌトル以䞋である。</li> <li>千䞡箱の重さはいずれもひず぀ 20 キログラムである。それぞれの蔵に収められおいる千䞡箱の個数は 10000 個以䞋である。</li> <li>蔵から蔵ぞの移動は、通りに沿っお地䞋に蚭眮されおいる地䞋道を䜿う。</li> <li>倧介は <var>w</var> キログラムの荷物を運ぶのに、分速 2,000(70 + <var>w</var>) メヌトルで移動する。</li> <!--<li>富士峰子は蚈画を劚害する恐れがあるので事前に睡眠薬を飲たせお眠らせる。このほかの劚害に぀いおも、遺挏なく察凊する。</li>--> </ul> <p> 入力デヌタは、それぞれの蔵に぀いお蔵の番号100 以䞋の敎数ず城からの距離メヌトルずその蔵に保管されおいる千䞡箱の個数が䞎えられる。 </p> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>s<sub>1</sub></var> <var>d<sub>1</sub></var> <var>v<sub>1</sub></var> <var>s<sub>2</sub></var> <var>d<sub>2</sub></var> <var>v<sub>2</sub></var> : <var>s<sub>n</sub></var> <var>d<sub>n</sub></var> <var>v<sub>n</sub></var> </pre> <p> 1 行目に蔵の個数 <var>n</var><var>n</var> &le; 15、続く <var>n</var> 行に第 <var>i</var> の蔵の情報が䞎えられたす。蔵の情報ずしお、蔵の番号 <var>s<sub>i</sub></var> (1 &le; <var>s<sub>i</sub></var> &le; 100)、城からの距離 <var>d<sub>i</sub></var> (1 &le; <var>d<sub>i</sub></var> &le; 10000)、 千䞡箱の数 <var>v<sub>i</sub></var> (1 &le; <var>v<sub>i</sub></var> &le; 10000) が行に䞎えられたす。 </p> <H2>Output</H2> <p> 蔵を砎る順番を行に出力しおください。蔵の番号を空癜で区切っおください。 </p> <H2>Sample Input 1</H2> <pre> 2 1 100 1 2 200 2 </pre> <H2>Output for the Sample Input 1</H2> <pre> 1 2 </pre> <H2>Sample Input 2</H2> <pre> 3 11 100 1 13 200 20 12 300 3 </pre> <H2>Output for the Sample Input 2</H2> <pre> 11 12 13 </pre> <H2>Sample Input 3</H2> <pre> 5 13 199 1 51 1000 1 37 350 10 27 300 2 99 200 1000 </pre> <H2>Output for the Sample Input 3</H2> <pre> 51 37 27 13 99 </pre>
p01184
<H1><font color="#000">Problem D:</font> International Party</H1> <p> Isaac H. Ives is attending an international student party (maybe for girl-hunting). Students there enjoy talking in groups with excellent foods and drinks. However, since students come to the party from all over the world, groups may not have a language spoken by all students of the group. In such groups, some student(s) need to work as interpreters, but intervals caused by interpretation make their talking less exciting. </p> <p> Needless to say, students want exciting talks. To have talking exciting as much as possible, Isaac proposed the following rule: the number of languages used in talking should be as little as possible, and not exceed five. Many students agreed with his proposal, but it is not easy for them to find languages each student should speak. So he calls you for help. </p> <p> Your task is to write a program that shows the minimum set of languages to make talking possible, given lists of languages each student speaks. </p> <H2>Input</H2> <p> The input consists of a series of data sets. </p> <p> The first line of each data set contains two integers <i>N</i> (1 &le; <i>N</i> &le; 30) and <i>M</i> (2 &le; <i>M</i> &le; 20) separated by a blank, which represent the numbers of languages and students respectively. The following <i>N</i> lines contain language names, one name per line. The following <i>M</i> lines describe students in the group. The <i>i</i>-th line consists of an integer <i>K<sub>i</sub></i> that indicates the number of languages the <i>i</i>-th student speaks, and <i>K<sub>i</sub></i> language names separated by a single space. Each language name consists of up to twenty alphabetic letters. </p> <p> A line that contains two zeros indicates the end of input and is not part of a data set. </p> <H2>Output</H2> <p> Print a line that contains the minimum number <i>L</i> of languages to be spoken, followed by <i>L</i> language names in any order. Each language name should be printed in a separate line. In case two or more sets of the same size is possible, you may print any one of them. If it is impossible for the group to enjoy talking with not more than five languages, you should print a single line that contains “Impossible” (without quotes). </p> <p> Print an empty line between data sets. </p> <H2>Sample Input</H2> <pre> 3 4 English French Japanese 1 English 2 French English 2 Japanese English 1 Japanese 2 2 English Japanese 1 English 1 Japanese 6 7 English Dutch German French Italian Spanish 1 English 2 English Dutch 2 Dutch German 2 German French 2 French Italian 2 Italian Spanish 1 Spanish 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 English Japanese Impossible Impossible </pre>
p03443
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a bridge that connects the left and right banks of a river. There are <var>2 N</var> doors placed at different positions on this bridge, painted in some colors. The colors of the doors are represented by integers from <var>1</var> through <var>N</var>. For each <var>k</var> (<var>1 \leq k \leq N</var>), there are exactly two doors painted in Color <var>k</var>.</p> <p>Snuke decides to cross the bridge from the left bank to the right bank. He will keep on walking to the right, but the following event will happen while doing so:</p> <ul> <li>At the moment Snuke touches a door painted in Color <var>k</var> (<var>1 \leq k \leq N</var>), he teleports to the right side of the other door painted in Color <var>k</var>.</li> </ul> <p>It can be shown that he will eventually get to the right bank.</p> <p>For each <var>i</var> (<var>1 \leq i \leq 2 N - 1</var>), the section between the <var>i</var>-th and <var>(i + 1)</var>-th doors from the left will be referred to as Section <var>i</var>. After crossing the bridge, Snuke recorded whether or not he walked through Section <var>i</var>, for each <var>i</var> (<var>1 \leq i \leq 2 N - 1</var>). This record is given to you as a string <var>s</var> of length <var>2 N - 1</var>. For each <var>i</var> (<var>1 \leq i \leq 2 N - 1</var>), if Snuke walked through Section <var>i</var>, the <var>i</var>-th character in <var>s</var> is <code>1</code>; otherwise, the <var>i</var>-th character is <code>0</code>.</p> <div style="text-align: center;"> <img src="https://img.atcoder.jp/cookie/970b981380ffad7745008433034c0885.png"> <p>Figure: A possible arrangement of doors for Sample Input 3</p> </img></div> <p>Determine if there exists an arrangement of doors that is consistent with the record. If it exists, construct one such arrangement.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>|s| = 2 N - 1</var></li> <li><var>s</var> consists of <code>0</code> and <code>1</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is no arrangement of doors that is consistent with the record, print <code>No</code>. If there exists such an arrangement, print <code>Yes</code> in the first line, then print one such arrangement in the second line, in the following format:</p> <pre><var>c_1</var> <var>c_2</var> <var>...</var> <var>c_{2 N}</var> </pre> <p>Here, for each <var>i</var> (<var>1 \leq i \leq 2 N</var>), <var>c_i</var> is the color of the <var>i</var>-th door from the left.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 010 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes 1 1 2 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 001 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 10110 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes 1 3 2 1 2 3 </pre> <p>The figure below is identical to the one in the statement.</p> <p><img alt="" src="https://img.atcoder.jp/cookie/970b981380ffad7745008433034c0885.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 10101 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>6 00111011100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>Yes 1 6 1 2 3 4 4 2 3 5 6 5 </pre></section> </div> </span>
p03013
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a staircase with <var>N</var> steps. Takahashi is now standing at the foot of the stairs, that is, on the <var>0</var>-th step. He can climb up one or two steps at a time.</p> <p>However, the treads of the <var>a_1</var>-th, <var>a_2</var>-th, <var>a_3</var>-th, <var>\ldots</var>, <var>a_M</var>-th steps are broken, so it is dangerous to set foot on those steps.</p> <p>How many are there to climb up to the top step, that is, the <var>N</var>-th step, without setting foot on the broken steps? Find the count modulo <var>1\ 000\ 000\ 007</var>.</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 M \leq N-1</var></li> <li><var>1 \leq a_1 &lt; a_2 &lt; </var> <var>...</var> <var> &lt; a_M \leq N-1</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>a_2</var> <var> .</var> <var> .</var> <var> .</var> <var>a_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to climb up the stairs under the condition, modulo <var>1\ 000\ 000\ 007</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four ways to climb up the stairs, as follows:</p> <ul> <li><var>0 \to 1 \to 2 \to 4 \to 5 \to 6</var></li> <li><var>0 \to 1 \to 2 \to 4 \to 6</var></li> <li><var>0 \to 2 \to 4 \to 5 \to 6</var></li> <li><var>0 \to 2 \to 4 \to 6</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 2 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There may be no way to climb up the stairs without setting foot on the broken steps.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 5 1 23 45 67 89 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>608200469 </pre> <p>Be sure to print the count modulo <var>1\ 000\ 000\ 007</var>.</p></section> </div> </span>
p00795
<H1><font color="#000">Problem H:</font> Co-occurrence Search</H1> <p> A huge amount of information is being heaped on WWW. Albeit it is not well-organized, users can browse WWW as an unbounded source of up-to-date information, instead of consulting established but a little out-of-date encyclopedia. However, you can further exploit WWW by learning more about keyword search algorithms. </p> <p> For example, if you want to get information on recent comparison between Windows and UNIX, you may expect to get relevant description out of a big bunch of Web texts, by extracting texts that contain both keywords "Windows" and "UNIX" close together. </p> <p> Here we have a simplified version of this co-occurrence keyword search problem, where the text and keywords are replaced by a string and key characters, respectively. A character string S of length <i>n</i> (1 &le; <i>n</i> &le; 1,000,000) and a set <i>K</i> of <i>k</i> distinct key characters <i>a</i><sub>1</sub>, ..., <i>a<sub>k</sub></i> (1 &le; <i>k</i> &le; 50) are given. Find every shortest substring of <i>S</i> that contains all of the key characters <i>a</i><sub>1</sub>, ..., <i>a<sub>k</sub></i>. </p> <H2>Input</H2> <p> The input is a text file which contains only printable characters (ASCII codes 21 to 7E in hexadecimal) and newlines. No white space such as space or tab appears in the input. </p> <p> The text is a sequence of the shortest string search problems described above. Each problem consists of character string <i>S<sub>i</sub></i> and key character set <i>K<sub>i</sub></i> (<i>i</i> = 1, 2, ..., <i>p</i>). Every <i>S<sub>i</sub></i> and <i>K<sub>i</sub></i> is followed by an empty line. However, any single newline between successive lines in a string should be ignored; that is, newlines are not part of the string. For various technical reasons, every line consists of at most 72 characters. Each key character set is given in a single line. The input is terminated by consecutive empty lines; <i>p</i> is not given explicitly. </p> <H2>Output</H2> <p> All of <i>p</i> problems should be solved and their answers should be output in order. However, it is not requested to print all of the shortest substrings if more than one substring is found in a problem, since found substrings may be too much to check them all. Only the number of the substrings together with their representative is requested instead. That is, for each problem <i>i</i>, the number of the shortest substrings should be output followed by the first (or the leftmost) shortest substring <i>s</i><sub><i>i</i>1</sub>, obeying the following format: </p> <pre> <i> the number of the shortest substrings for the i-th problem empty line the first line of s<sub>i1</sub> the second line of s<sub>i1</sub> ... the last line of s<sub>i1</sub> empty line for the substring termination </i> </pre> <p> where each line of the shortest substring <i>s</i><sub><i>i</i>1</sub> except for the last line should consist of exactly 72 characters and the last line (or the single line if the substring is shorter than or equal to 72 characters, of course) should not exceed 72 characters. </p> <p> If there is no such substring for a problem, the output will be a 0 followed by an empty line; no more successive empty line should be output because there is no substring to be terminated. </p> <H2>Sample Input</H2> <pre> Thefirstexampleistrivial. mfv AhugeamountofinformationisbeingheapedonWWW.Albeititisnot well-organized,userscanbrowseWWWasanunboundedsourceof up-to-dateinformation,insteadofconsultingestablishedbutalittle out-of-dateencyclopedia.However,youcanfurtherexploitWWWby learningmoreaboutkeywordsearchalgorithms.Forexample,ifyou wanttogetinformationonrecentcomparisonbetweenWindowsandUNIX, youmayexpecttogetrelevantdescriptionoutofabigbunchofWeb texts,byextractingtextsthatcontainbothkeywords"Windows"and"UNIX" closetogether. bWn 3.1415926535897932384626433832795028841971693993751058209749445923078164 pi Wagner,Bach,Beethoven,Chopin,Brahms,Hindemith,Ives,Suk,Mozart,Stravinsky Weary ASCIIcharacterssuchas+,*,[,#,<,},_arenotexcludedinagivenstringas thisexampleillustratesbyitself.Youshouldnotforgetthem.Onemorefact youshouldnoticeisthatuppercaselettersandlowercaselettersare distinguishedinthisproblem.Don'tidentify"g"and"G",forexmaple. However,weareafraidthatthisexamplegivesyoutoomuchhint! ![GsC_l ETAONRISHDLFCMUGYPWBVKXJQZ ABCDEFGHIJKLMNOPQRSTUVWXYZ </pre> <H2>Output for the Sample Input</H2> <pre> 1 firstexampleistriv 7 nWWW.Alb 0 1 Wagner,Bach,Beethoven,Chopin,Brahms,Hindemith,Ives,Suk,Mozart,Stravinsky 1 CIIcharacterssuchas+,*,[,#,<,},_arenotexcludedinagivenstringasthisexampl eillustratesbyitself.Youshouldnotforgetthem.Onemorefactyoushouldnoticeis thatuppercaselettersandlowercaselettersaredistinguishedinthisproblem.Don 'tidentify"g"and"G",forexmaple.However,weareafraidthatthisexamplegivesyo utoomuchhint! 1 ETAONRISHDLFCMUGYPWBVKXJQZ </pre>
p01887
<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>Pipe Fitter and the Fierce Dogs</h2> <p> You, a proud pipe fitter of ICPC (International Community for Pipe Connection), undertake a new task. The area in which you will take charge of piping work is a rectangular shape with $W$ blocks from west to east and $H$ blocks from north to south. We refer to the block at the $i$-th from west and the $j$-th from north as $(i, j)$. The westernmost and northernmost block is $(1, 1)$, and the easternmost and southernmost block is $(W,H)$. To make the area good scenery, the block $(i, j)$ has exactly one house if and only if both of $i$ and $j$ are odd numbers. </p> <p> Your task is to construct a water pipe network in the area such that every house in the area is supplied water through the network. A water pipe network consists of pipelines. A pipeline is made by connecting one or more pipes, and a pipeline with l pipes is constructed as follows: </p> <ol> <li> choose a first house, and connect the house to an underground water source with a <i>special pipe</i>.</li> <li> choose an $i$-th house ($2 \leq i \leq l$), and connect the $i$-th house to the ($i - 1$)-th house with a <i>common pipe</i>. In this case, there is a condition to choose a next $i$-th house because the area is slope land. Let $(x, y)$ be the block of the ($i - 1$)-th house. An $i$-th house must be located at either $(x - 2, y + 2)$, $(x, y + 2)$, or $(x + 2, y + 2)$. A common pipe connecting two houses must be located at $(x - 1, y + 1)$, $(x, y + 1)$, or $(x + 1, y + 1)$, respectively. </ol> <p> In addition, you should notice the followings when you construct several pipelines: </p> <ul> <li> For each house, exactly one pipeline is through the house.</li> <li> Multiple pipes can be located at one block.</li> </ul> <p> In your task, common pipes are common, so you can use any number of common pipes. On the other hand, special pipes are special, so the number of available special pipes in this task is restricted under ICPC regulation. </p> <p> Besides the restriction of available special pipes, there is another factor obstructing your pipe work: fierce dogs. Some of the blocks which do not contain a house seem to be home of fierce dogs. Each dog always stays at his/her home block. Since several dogs must not live at the same block as their home, you can assume each block is home of only one dog, or not home of any dogs. </p> <p> The figure below is an example of a water pipe network in a 5 $\times$ 5 area with 4 special pipes. This corresponds to the first sample. <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2016_pipeFitter"><br/> </center> <br/> <p> Locating a common pipe at a no-dog block costs 1 unit time, but locating a common pipe at a dog-living block costs 2 unit time because you have to fight against the fierce dog. Note that when you locate multiple pipes at the same block, each pipe-locating costs 1 unit time for no-dog blocks and 2 for dog-living blocks, respectively. By the way, special pipes are very special, so locating a special pipe costs 0 unit time. </p> <p> You, a proud pipe fitter, want to accomplish this task as soon as possible. Fortunately, you get a list of blocks which are home of dogs. You have frequently participated in programming contests before being a pipe fitter. Hence, you decide to make a program determining whether or not you can construct a water pipe network such that every house is supplied water through the network with a restricted number of special pipes, and if so, computing the minimum total time cost to construct it. </p> <h3>Input</h3> <p> The input consists of a single test case.<br/> <br/> $W$ $H$ $K$<br/> $N$<br/> $x_1$ $y_1$<br/> $x_2$ $y_2$<br/> ...<br/> $x_N$ $y_N$ </p> <p> All numbers in a test case are integers. The first line contains three integers $W$, $H$, and $K$. $W$ and $H$ represent the size of the rectangle area. $W$ is the number of blocks from west to east ($1 \leq W < 10,000$), and $H$ is the number of blocks from north to south ($1 \leq H < 10,000$). $W$ and $H$ must be odd numbers. $K$ is the number of special pipes that you can use in this task ($1 \leq K \leq 100,000,000$). The second line has an integer $N$ ($0 \leq N \leq 100,000$), which is the number of dogs in the area. Each of the following $N$ lines contains two integers $x_i$ and $y_i$, which indicates home of the $i$-th fierce dog is the block $(x_i, y_i)$. These numbers satisfy the following conditions: </p> <ul> <li> $1 \leq x_i \leq W, 1 \leq y_i \leq H$.</li> <li> At least one of $x_i$ and $y_i$ is even number.</li> <li> $i \ne j$ implies $(x_i, y_i) \ne (x_j, y_j)$. That is, two or more dogs are not in the same block.</li> </ul> <h3>Output</h3> <p> If we can construct a water pipe network such that every house is supplied water through the network with a restricted number of special pipes, print the minimum total time cost to construct it. If not, print -1. </p> <h3>Sample Input 1</h3> <pre> 5 5 4 6 3 2 4 2 5 2 1 4 3 4 5 4 </pre> <h3>Output for the Sample Input 1</h3> <pre> 6 </pre> <h3>Sample Input 2</h3> <pre> 5 3 1 0 </pre> <h3>Output for the Sample Input 2</h3> <pre> -1 </pre> <h3>Sample Input 3</h3> <pre> 9 5 100 5 2 1 1 2 3 4 4 3 2 2 </pre> <h3>Output for the Sample Input 3</h3> <pre> 0 </pre> <h3>Sample Input 4</h3> <pre> 5 5 3 4 1 2 5 2 1 4 5 4 </pre> <h3>Output for the Sample Input 4</h3> <pre> 8 </pre> <h3>Sample Input 5</h3> <pre> 9 5 5 10 2 1 2 2 3 2 5 2 8 2 4 3 2 4 3 4 5 4 8 4 </pre> <h3>Output for the Sample Input 5</h3> <pre> 10 </pre>
p02252
<h1>Fractional Knapsack Problem</h1> <p>You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.</p> <p>When you put some items into the knapsack, the following conditions must be satisfied:</p> <ul> <li>The total value of the items is as large as possible.</li> <li>The total weight of the selected items is at most $W$.</li> <li>You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$</li> </ul> <p>Find the maximum total value of items in the knapsack.</p> <h2>Input</h2> <pre> $N$ $W$ $v_1$ $w_1$ $v_2$ $w_2$ : $v_N$ $w_N$ </pre> <p>The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.</p> <h2>Output</h2> <p>Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.</p> <h2>Constraints</h2> <ul> <li>$1 \le N \le 10^5$</li> <li>$1 \le W \le 10^9$</li> <li>$1 \le v_i \le 10^9 (1 \le i \le N)$</li> <li>$1 \le w_i \le 10^9 (1 \le i \le N)$</li> </ul> <h2>Sample Input 1</h2> <pre> 3 50 60 10 100 20 120 30 </pre> <h2>Sample Output 1</h2> <pre> 240 </pre> <p>When you put 10 of item $1$, 20 of item $2$ and 20 of item $3$, the total value is maximized.</p> <h2>Sample Input 2</h2> <pre> 3 50 60 13 100 23 120 33 </pre> <h2>Sample Output 2</h2> <pre> 210.90909091 </pre> <p>When you put 13 of item $1$, 23 of item $2$ and 14 of item $3$, the total value is maximized. Note some outputs can be a real number.</p> <h2>Sample Input 3</h2> <pre> 1 100 100000 100000 </pre> <h2>Sample Output 3</h2> <pre> 100 </pre>
p02602
<span class="lang-en"> <p>Score: <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>M-kun is a student in Aoki High School, where a year is divided into <var>N</var> terms.<br/> There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:</p> <ul> <li>For the first through <var>(K-1)</var>-th terms: not given.</li> <li>For each of the <var>K</var>-th through <var>N</var>-th terms: the multiplication of the scores in the last <var>K</var> exams, including the exam in the graded term.</li> </ul> <p>M-kun scored <var>A_i</var> in the exam at the end of the <var>i</var>-th term.<br/> For each <var>i</var> such that <var>K+1 \leq i \leq N</var>, determine whether his grade for the <var>i</var>-th term is <strong>strictly</strong> greater than the grade for the <var>(i-1)</var>-th term.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>2 \leq N \leq 200000</var></li> <li><var>1 \leq K \leq N-1</var></li> <li><var>1 \leq A_i \leq 10^{9}</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>A_1</var> <var>A_2</var> <var>A_3</var> <var>\ldots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer in <var>N-K</var> lines.<br/> The <var>i</var>-th line should contain <code>Yes</code> if the grade for the <var>(K+i)</var>-th term is greater than the grade for the <var>(K+i-1)</var>-th term, and <code>No</code> otherwise.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 96 98 95 100 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes No </pre> <p>His grade for each term is computed as follows:</p> <ul> <li><var>3</var>-rd term: <var>(96 \times 98 \times 95) = 893760</var></li> <li><var>4</var>-th term: <var>(98 \times 95 \times 100) = 931000</var></li> <li><var>5</var>-th term: <var>(95 \times 100 \times 20) = 190000</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 1001 869120 1001 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>Note that the output should be <code>No</code> if the grade for the <var>3</var>-rd term is equal to the grade for the <var>2</var>-nd term.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>15 7 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes Yes No Yes Yes No Yes Yes </pre></section> </div> </span>
p03910
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The problem set at <em>CODE FESTIVAL 20XX Finals</em> consists of <var>N</var> problems.</p> <p>The score allocated to the <var>i</var>-th <var>(1≩i≩N)</var> problem is <var>i</var> points.</p> <p>Takahashi, a contestant, is trying to score exactly <var>N</var> points. For that, he is deciding which problems to solve.</p> <p>As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.</p> <p>Determine the set of problems that should be solved.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩10^7</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>200</var> points will be awarded for passing the test set satisfying <var>1≩N≩1000</var>.</li> <li>Additional <var>100</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Among the sets of problems with the total score of <var>N</var>, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line.</p> <p>If there exists more than one such set, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 3 </pre> <p>Solving only the <var>4</var>-th problem will also result in the total score of <var>4</var> points, but solving the <var>1</var>-st and <var>3</var>-rd problems will lower the highest score of a solved problem.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 4 </pre> <p>The set <var>\{3,4\}</var> will also be accepted.</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></section> </div> </span>
p02317
<H1>Longest Increasing Subsequence</H1> <br/> <p> For a given sequence <var>A = {a<sub>0</sub>, a<sub>1</sub>, ... , a<sub>n-1</sub>}</var>, find the length of the longest increasing subsequnece (LIS) in <var>A</var>. </p> <p> An increasing subsequence of <var>A</var> is defined by a subsequence <var>{a<sub>i<sub>0</sub></sub>, a<sub>i<sub>1</sub></sub>, ... , a<sub>i<sub>k</sub></sub>}</var> where <var>0 &le; i<sub>0</sub> &lt; i<sub>1</sub> &lt; ... &lt; i<sub>k</sub> &lt; n</var> and <var>a<sub>i<sub>0</sub></sub> &lt; a<sub>i<sub>1</sub></sub> &lt; ... &lt; a<sub>i<sub>k</sub></sub>. </p> <H2>Input</H2> <pre> <var>n</var> <var>a<sub>0</sub></var> <var>a<sub>1</sub></var> : <var>a<sub>n-1</sub></var> <var> </pre> <p> In the first line, an integer <var>n</var> is given. In the next <var>n</var> lines, elements of <var>A</var> are given. </p> <H2>Output</H2> <p> The length of the longest increasing subsequence of <var>A</var>. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>n</var> &le; 100000</li> <li>0 &le; <var>a<sub>i</sub></var> &le; 10<sup>9</sup></li> </ul> <H2>Sample Input 1</H2> <pre> 5 5 1 3 2 4 </pre> <H2>Sample Output 1</H2> <pre> 3 </pre> <br/> <H2>Sample Input 2</H2> <pre> 3 1 1 1 </pre> <H2>Sample Output 2</H2> <pre> 1 </pre> <br/>
p02747
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>A Hitachi string is a concatenation of one or more copies of the string <code>hi</code>.</p> <p>For example, <code>hi</code> and <code>hihi</code> are Hitachi strings, while <code>ha</code> and <code>hii</code> are not.</p> <p>Given a string <var>S</var>, determine whether <var>S</var> is a Hitachi string.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>The length of <var>S</var> is between <var>1</var> and <var>10</var> (inclusive).</li> <li><var>S</var> is a string consisting of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If <var>S</var> is a Hitachi string, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>hihi </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p><code>hihi</code> is the concatenation of two copies of <code>hi</code>, so it is a Hitachi string.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>hi </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>ha </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre></section> </div> </span>
p03855
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> cities. There are also <var>K</var> roads and <var>L</var> railways, extending between the cities. The <var>i</var>-th road bidirectionally connects the <var>p_i</var>-th and <var>q_i</var>-th cities, and the <var>i</var>-th railway bidirectionally connects the <var>r_i</var>-th and <var>s_i</var>-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.</p> <p>We will say city <var>A</var> and <var>B</var> are <em>connected by roads</em> if city <var>B</var> is reachable from city <var>A</var> by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define <em>connectivity by railways</em> similarly.</p> <p>For each city, find the number of the cities connected to that city by both roads and railways.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≩ N ≩ 2*10^5</var></li> <li><var>1 ≩ K, L≩ 10^5</var></li> <li><var>1 ≩ p_i, q_i, r_i, s_i ≩ N</var></li> <li><var>p_i &lt; q_i</var></li> <li><var>r_i &lt; s_i</var></li> <li>When <var>i ≠ j</var>, <var>(p_i, q_i) ≠ (p_j, q_j)</var></li> <li>When <var>i ≠ j</var>, <var>(r_i, s_i) ≠ (r_j, s_j)</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>K</var> <var>L</var> <var>p_1</var> <var>q_1</var> : <var>p_K</var> <var>q_K</var> <var>r_1</var> <var>s_1</var> : <var>r_L</var> <var>s_L</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> integers. The <var>i</var>-th of them should represent the number of the cities connected to the <var>i</var>-th city by both roads and railways.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 1 2 2 3 3 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 2 1 </pre> <p>All the four cities are connected to each other by roads.</p> <p>By railways, only the second and third cities are connected. Thus, the answers for the cities are <var>1, 2, 2</var> and <var>1</var>, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 2 1 2 2 3 1 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 2 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 4 4 1 2 2 3 2 5 6 7 3 5 4 5 3 4 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 1 2 1 2 2 2 </pre></section> </div> </span>
p01868
<!-- - - - - - begin nicebody - - - - - --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>D: スキャナヌ / Scanner</h1> <h2>問題文</h2> <p> ここに $N$ 枚の玙がある。あなたは $3$ 台のスキャナヌを䞊列に甚いるこずで、 党おの玙をスキャンしたいず考えおいる。それぞれの玙はスキャンにかかる時間が決たっおおり、 $i$ 番目の玙をスキャンするのにかかる時間は $T_i$ である。 玙をスキャンする順番は任意であるが、$1$ 台のスキャナヌで耇数の玙を同時にスキャンするこずはできない。 </p> <p> 党おの玙のスキャンが終了し、スキャンを行っおいるスキャナヌがなくなるたでにかかる時間を最小化しなさい。 </p> <h2>入力</h2> <p> $N$<br> $T_1$<br> $T_2$<br> $T_3$<br> $\vdots$<br> $T_N$<br> </p> <h2>制玄</h2> <p> $1 \leq N \leq 50$<br> $1 \leq T_i \leq 50$<br> 入力は党お敎数<br> </p> <h2>出力</h2> <p> 答えを $1$ 行で出力しおください </p> <h2>サンプル</h2> <h3>サンプル入力1</h3> <pre> 4 1 1 1 1 </pre> <h3>サンプル出力1</h3> <pre> 2 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_D1"> <h3>サンプル入力2</h3> <pre> 9 15 20 27 4 10 7 34 30 36 </pre> <h3>サンプル出力2</h3> <pre> 61 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_D2"> <h3>サンプル入力3</h3> <pre> 6 20 18 46 16 9 48 </pre> <h3>サンプル出力3</h3> <pre> 55 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_D3">
p00280
<h1>テニス</h1> <p> ゞョり君ずダ゚さんは昌䌑みにテニスをしたす。ただし、昌䌑みは時間が限られおいるので、短い時間で終わるように、埗点に぀いお以䞋の぀のルヌルで行いたす。 </p> <ul> <li> 盞手が点以䞋のずきに先に点ずれば勝ち。</li> <li> 察の同点になったずきは、その盎埌に連続しお点ずった方が勝ち。</li> <li> 察の埌に双方が点ず぀ずったずきは匕き分け。</li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_tennis" width="600"> </center> <p> 以䞋の図は、ゞョり君ずダ゚さんの詊合で起こり埗るすべおの状況を衚しおいたす。䞞の䞭の巊の数がゞョり君の埗点、右がダ゚さんの埗点です。ず曞いた矢印はゞョり君が点ずったこずを、ず曞いた矢印はダ゚さんが点ずったこずを衚したす。 </p> <p> ゞョり君ずダ゚さんの埗点が䞎えられたずき、詊合開始からその埗点状況になるたでに、䞊の図で通り埗るすべおの経路を列挙するプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は぀のデヌタセットからなる。入力デヌタは以䞋の圢匏で䞎えられる。 </p> <pre> <var>j</var> <var>y</var> </pre> <p> <var>j</var> (0 &le; <var>j</var> &le; 6) がゞョり君の埗点、<var>y</var> (0 &le; <var>y</var> &le; 6) がダ゚さんの埗点である。ただし、<var>j</var> ず <var>y</var> がずもに 0 であるこずはない。たた、<var>j</var> が 6 のずきは <var>y</var> は 4、<var>y</var> が 6 のずきは <var>j</var> は 4 である。 </p> <h2>出力</h2> <p> 䞊の図で、詊合開始0-0ず曞かれた䞞から䞎えられた埗点が曞かれた䞞たでのすべおの経路を出力する。経路は図の矢印に添えられた英字(A,B)の列で衚し、蟞曞匏順序英和蟞曞で単語が䞊んでいる順番になるように䞊べる。぀の経路を行に出力する。経路の前埌には空癜を出力しない。 </p> <h2>入出力䟋</h2> <br> <h2>入力䟋1</h2> <pre> 2 2 </pre> <h2>出力䟋1</h2> <pre> AABB ABAB ABBA BAAB BABA BBAA </pre> <h2>入力䟋2</h2> <pre> 5 1 </pre> <h2>出力䟋2</h2> <pre> AAAABA AAABAA AABAAA ABAAAA BAAAAA </pre>
p03506
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Consider an infinite <var>N</var>-ary tree as shown below:</p> <div style="text-align: center;"> <img src="https://img.atcoder.jp/relay2/c76baa50b0acf28062688597724a54b9.png"> <p>Figure: an infinite <var>N</var>-ary tree for the case <var>N = 3</var></p> </img></div> <p>As shown in the figure, each vertex is indexed with a unique positive integer, and for every positive integer there is a vertex indexed with it. The root of the tree has the index <var>1</var>. For the remaining vertices, vertices in the upper row have smaller indices than those in the lower row. Among the vertices in the same row, a vertex that is more to the left has a smaller index.</p> <p>Regarding this tree, process <var>Q</var> queries. The <var>i</var>-th query is as follows:</p> <ul> <li>Find the index of the lowest common ancestor (see Notes) of Vertex <var>v_i</var> and <var>w_i</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Notes</h3><ul> <li>In a rooted tree, the <em>lowest common ancestor</em> (LCA) of Vertex <var>v</var> and <var>w</var> is the farthest vertex from the root that is an ancestor of both Vertex <var>v</var> and <var>w</var>. Here, a vertex is considered to be an ancestor of itself. For example, in the tree shown in Problem Statement, the LCA of Vertex <var>5</var> and <var>7</var> is Vertex <var>2</var>, the LCA of Vertex <var>8</var> and <var>11</var> is Vertex <var>1</var>, and the LCA of Vertex <var>3</var> and <var>9</var> is Vertex <var>3</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^9</var></li> <li><var>1 ≀ Q ≀ 10^5</var></li> <li><var>1 ≀ v_i &lt; w_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>Q</var> <var>v_1</var> <var>w_1</var> <var>:</var> <var>v_Q</var> <var>w_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line <var>(1 ≀ i ≀ Q)</var> must contain the index of the lowest common ancestor of Vertex <var>v_i</var> and <var>w_i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 5 7 8 11 3 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 3 </pre> <p>The queries in this case correspond to the examples shown in Notes.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100000 2 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 1 </pre></section> </div> </span>
p03156
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have written <var>N</var> problems to hold programming contests. The <var>i</var>-th problem will have a score of <var>P_i</var> points if used in a contest.</p> <p>With these problems, you would like to hold as many contests as possible under the following condition:</p> <ul> <li>A contest has three problems. The first problem has a score not greater than <var>A</var> points, the second has a score between <var>A + 1</var> and <var>B</var> points (inclusive), and the third has a score not less than <var>B + 1</var> points.</li> </ul> <p>The same problem should not be used in multiple contests. At most how many contests can be held?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 100</var></li> <li><var>1 \leq P_i \leq 20</var> (<var>1 \leq i \leq N</var>)</li> <li><var>1 \leq A &lt; B &lt; 20</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</var> <var>B</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>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 5 15 1 10 16 2 7 20 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Two contests can be held by putting the first, second, third problems and the fourth, fifth, sixth problems together.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 3 8 5 5 5 10 10 10 15 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>No contest can be held, because there is no problem with a score of <var>A = 3</var> or less.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 5 6 5 6 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre></section> </div> </span>
p01491
<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 F: RabbitLunch </h2> <p> うさぎは昌食ににんじんずキりむを1 個ず぀食べる. うさぎはずおも個性的なので, 食べるにんじんの皮類もキりむの皮類も同じであるような, 異なる2 匹のうさぎが存圚しおはならない. </p> <p> にんじんは $M$ 皮類ある. $i$ 皮類目のにんじんは $m_i$ 個ある. キりむは $N$ 皮類ある. $i$ 皮類目のキりむは $n_i$ 個ある. 最倧䜕匹のうさぎが昌食をずれるか求めよ. </p> <p> $m_i$ ず $n_i$ は次の挞化匏を甚いお生成せよ. </p> <ul> <li> $m_0 = m0$ </li> <li> $m_{i+1} = (m_i * 58 + md )$ mod $(N + 1)$</li> <li> $n_0 = n0$</li> <li> $n_{i+1} = (n_i * 58 + nd )$ mod $(M + 1)$</li> </ul> <h3>Constraints</h3> <ul> <li>$M$ will be between 1 and 2,500,000, inclusive.</li> <li>$N$ will be between 1 and 2,500,000, inclusive.</li> <li>$m0$ and $md$ will be between 0 and $N$, inclusive.</li> <li>$n0$ and $nd$ will be between 0 and $M$, inclusive.</li> </ul> <h3>Input</h3> <p> 入力は以䞋の圢匏で䞎えられる:<br> <br> $M$ $N$ $m0$ $md$ $n0$ $nd$<br> <br> </p> <h3>Output</h3> <p> 昌食をずれるうさぎの匹数の最倧倀を衚す敎数を 1 行に出力せよ. </p> <h3>Sample Input 1</h3> <pre>2 3 1 3 1 0</pre> <h3>Sample Output 1</h3> <pre>2</pre> <h3>Sample Input 2</h3> <pre>5 8 1 2 3 4</pre> <h3>Sample Output 2</h3> <pre>19</pre>
p03382
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>{\rm comb}(n,r)</var> be the number of ways to choose <var>r</var> objects from among <var>n</var> objects, disregarding order. From <var>n</var> non-negative integers <var>a_1, a_2, ..., a_n</var>, select two numbers <var>a_i &gt; a_j</var> so that <var>{\rm comb}(a_i,a_j)</var> is maximized. If there are multiple pairs that maximize the value, any of them is accepted.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq n \leq 10^5</var></li> <li><var>0 \leq a_i \leq 10^9</var></li> <li><var>a_1,a_2,...,a_n</var> are pairwise 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>a_1</var> <var>a_2</var> <var>...</var> <var>a_n</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>a_i</var> and <var>a_j</var> that you selected, with a space in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 6 9 4 2 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>11 6 </pre> <p><var>\rm{comb}(a_i,a_j)</var> for each possible selection is as follows:</p> <ul> <li><var>\rm{comb}(4,2)=6</var> </li> <li><var>\rm{comb}(6,2)=15</var> </li> <li><var>\rm{comb}(6,4)=15</var> </li> <li><var>\rm{comb}(9,2)=36</var> </li> <li><var>\rm{comb}(9,4)=126</var> </li> <li><var>\rm{comb}(9,6)=84</var> </li> <li><var>\rm{comb}(11,2)=55</var> </li> <li><var>\rm{comb}(11,4)=330</var> </li> <li><var>\rm{comb}(11,6)=462</var> </li> <li><var>\rm{comb}(11,9)=55</var></li> </ul> <p>Thus, we should print <var>11</var> and <var>6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 100 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>100 0 </pre></section> </div> </span>
p00957
<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> <h2>Problem A Secret of Chocolate Poles </h2> <p> Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. </p> <p> Each pole should satisfy the following conditions for her secret mission, which we cannot tell. </p> <ul> <li> A pole should consist of at least one disk.</li> <li> The total thickness of disks in a pole should be less than or equal to $l$ cm.</li> <li> The top disk and the bottom disk of a pole should be dark.</li> <li> A disk directly upon a white disk should be dark and vice versa.</li> </ul> <p> As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_chocolatePoles"> <p> Figure A.1. Six chocolate poles corresponding to Sample Input 1 </p> </center> <p> Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. </p> <h3>Input</h3> <p> The input consists of a single test case in the following format. </p> <pre> $l$ $k$ </pre> <p> Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. </p> <h3>Output</h3> <p> Output the number of possible distinct patterns. </p> <h3>Sample Input 1</h3> <pre> 5 3 </pre> <h3>Sample Output 1</h3> <pre> 6 </pre> <h3>Sample Input 2</h3> <pre> 9 10 </pre> <h3>Sample Output 2</h3> <pre> 5 </pre> <h3>Sample Input 3</h3> <pre> 10 10 </pre> <h3>Sample Output 3</h3> <pre> 6 </pre> <h3>Sample Input 4</h3> <pre> 20 5 </pre> <h3>Sample Output 4</h3> <pre> 86 </pre> <h3>Sample Input 5</h3> <pre> 100 2 </pre> <h3>Sample Output 5</h3> <pre> 3626169232670 </pre>
p01645
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [['\\(','\\)']] } }); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> <h1 class="ndoc-heading1">Problem L: The Return of FizzBuzz</h1> <p class="ndoc-top">ICPC World Finals 7日目</p> <p class="ndoc-top">いよいよ明日はICPC World Finalsの本番である。 ティヌ氏はあるオンラむンゞャッゞ(Aru Online Judge)で緎習をするこずにした。 問題䞀芧を眺めおいるずFizzBuzzずいう問題が目に぀いた。 この問題は、FizzBuzzゲヌムで埗られる発蚀のn文字目から20文字を出力するずいうものだ。</p> <p class="ndoc-top"> ふぅ。あっずいう間に解けおしたった。 これでは簡単すぎた。 入力ず出力を逆にした問題を䜜っおみるこずにしよう。</p> <h2 class="ndoc-heading2">問題</h2> <p class="ndoc-top"> FizzBuzzずは、1以䞊の敎数を順に、以䞋のルヌルに埓っお発蚀しおいくゲヌムである。</p> <ul class="ndoc-indent"> <li>3で割り切れる時には「Fizz」</li> <li>5で割り切れる時には「Buzz」</li> <li>3ず5の䞡方で割り切れる時には「FizzBuzz」</li> <li>それ以倖の時はその数字</li> </ul> ゲヌムの進行状況を以䞋に瀺す。 <p class="ndoc-top">1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 
</p> <p class="ndoc-top">埗られた発蚀を結合するこずで埗られる無限長の文字列をFizzBuzz Stringず呌ぶ。 ある文字列\(s\)が䞎えられる。 \(s\)がFizzBuzz Stringの郚分文字列ずしお出珟するかを刀定し、 出珟する堎合には最初に出珟するむンデックスを求めよ。</p> <h2 class="ndoc-heading2">入力</h2> <pre> n s<sub>1</sub> s<sub>2</sub> 
 s<sub>n</sub> </pre> <p>入力は耇数のテストケヌスからなる。 1行目にテストケヌス数\(n\)が䞎えられる。 2行目から\( n+1 \)行目は各テストケヌスに察応し、 文字列\( s_{i} \)が1行で䞎えられる。</p> <h2 class="ndoc-heading2">出力</h2> <p class="ndoc-top">\(i\)番目の文字列\( s_{i} \)に぀いお、 \( s_{i} \)がFizzBuzz Stringの郚分文字列ずしお出珟する堎合には最初に出珟するむンデックスを(1-indexで)、 出珟しない堎合には"-1"を\(i\)行目に出力せよ。</p> <h2 class="ndoc-heading2">制玄</h2> <ul class="ndoc-indent"> <li>\( 1 \leq n \leq 20 \)</li> <li>文字列は文字\( \{ 0,1,\cdots,8,9 ,\mbox{F},\mbox{B},\mbox{i},\mbox{u},\mbox{z} \} (1 \leq i \leq n) \)からなる。</li> <li>文字列の長さは1以䞊15以䞋である。</li> </ul> <h2 class="ndoc-heading2">入出力䟋</h2> <h3 class="ndoc-heading3">入力1</h3> <pre> 6 78Fizz 98FizzBuzz101 FizzBu izzFiz 111111111111111 123456789 </pre> <h3 class="ndoc-heading3">出力1</h3> <pre> 16 304 18 -1 7703703700 7795884765 </pre> <p>入力䟋は6぀のテストケヌスからなる。 それぞれ以䞋の発蚀に察応する。</p> <ul> <li>
, Buzz, Fizz, 7, 8, Fizz, Buzz, 
</li> <li>
, Fizz, 97, 98, Fizz, Buzz, 101, Fizz, 
</li> <li>
, 7, 8, Fizz, Buzz, 11, 12, 
</li> <li>存圚しない</li> <li>
, 1111111109, FizzBuzz, 1111111111, 1111111112, Fizz, 1111111114, 
</li> <li>
, 1123456787, Fizz, 1123456789, Buzz, Fizz, 
</li> </ul> </body> </html>
p03678
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will call a string that can be obtained by concatenating two equal strings an <em>even</em> string. For example, <code>xyzxyz</code> and <code>aaaaaa</code> are even, while <code>ababab</code> and <code>xyzxy</code> are not.</p> <p>For a non-empty string <var>S</var>, we will define <var>f(S)</var> as the shortest even string that can be obtained by appending one or more characters to the end of <var>S</var>. For example, <var>f(</var><code>abaaba</code><var>)=</var><code>abaababaab</code>. It can be shown that <var>f(S)</var> is uniquely determined for a non-empty string <var>S</var>.</p> <p>You are given an even string <var>S</var> consisting of lowercase English letters. For each letter in the lowercase English alphabet, find the number of its occurrences from the <var>l</var>-th character through the <var>r</var>-th character of <var>f^{10^{100}} (S)</var>.</p> <p>Here, <var>f^{10^{100}} (S)</var> is the string <var>f(f(f( ... f(S) ... )))</var> obtained by applying <var>f</var> to <var>S</var> <var>10^{100}</var> times.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq |S| \leq 2\times 10^5</var></li> <li><var>1 \leq l \leq r \leq 10^{18}</var></li> <li><var>S</var> is an even string consisting of lowercase English letters.</li> <li><var>l</var> and <var>r</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>S</var> <var>l</var> <var>r</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>26</var> integers in a line with spaces in between. The <var>i</var>-th integer should be the number of the occurrences of the <var>i</var>-th letter in the lowercase English alphabet from the <var>l</var>-th character through the <var>r</var>-th character of <var>f^{10^{100}} (S)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>abaaba 6 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 2 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> <p>Since <var>f(</var><code>abaaba</code><var>)=</var><code>abaababaab</code>, the first ten characters in <var>f^{10^{100}}(S)</var> is also <code>abaababaab</code>. Thus, the sixth through the tenth characters are <code>abaab</code>. In this string, <code>a</code> appears three times, <code>b</code> appears twice and no other letters appear, and thus the output should be <var>3</var> and <var>2</var> followed by twenty-four <var>0</var>s.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>xx 1 1000000000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>vgxgpuamkvgxgvgxgpuamkvgxg 1 1000000000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0 </pre></section> </div> </span>
p04017
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>N</var> hotels are located on a straight line. The coordinate of the <var>i</var>-th hotel <var>(1 \leq i \leq N)</var> is <var>x_i</var>.</p> <p>Tak the traveler has the following two personal principles:</p> <ul> <li>He never travels a distance of more than <var>L</var> in a single day.</li> <li>He never sleeps in the open. That is, he must stay at a hotel at the end of a day.</li> </ul> <p>You are given <var>Q</var> queries. The <var>j</var>-th <var>(1 \leq j \leq Q)</var> query is described by two distinct integers <var>a_j</var> and <var>b_j</var>. For each query, find the minimum number of days that Tak needs to travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel following his principles. It is guaranteed that he can always travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel, in any given input.</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 L \leq 10^9</var></li> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>1 \leq x_i &lt; x_2 &lt; ... &lt; x_N \leq 10^9</var></li> <li><var>x_{i+1} - x_i \leq L</var></li> <li><var>1 \leq a_j,b_j \leq N</var></li> <li><var>a_j \neq b_j</var></li> <li><var>N,\,L,\,Q,\,x_i,\,a_j,\,b_j</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>200</var> points will be awarded for passing the test set satisfying <var>N \leq 10^3</var> and <var>Q \leq 10^3</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var> <var>L</var> <var>Q</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> : <var>a_Q</var> <var>b_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines. The <var>j</var>-th line <var>(1 \leq j \leq Q)</var> should contain the minimum number of days that Tak needs to travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>9 1 3 6 13 15 18 19 29 31 10 4 1 8 7 3 6 7 8 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 2 1 2 </pre> <p>For the <var>1</var>-st query, he can travel from the <var>1</var>-st hotel to the <var>8</var>-th hotel in <var>4</var> days, as follows:</p> <ul> <li>Day <var>1</var>: Travel from the <var>1</var>-st hotel to the <var>2</var>-nd hotel. The distance traveled is <var>2</var>.</li> <li>Day <var>2</var>: Travel from the <var>2</var>-nd hotel to the <var>4</var>-th hotel. The distance traveled is <var>10</var>.</li> <li>Day <var>3</var>: Travel from the <var>4</var>-th hotel to the <var>7</var>-th hotel. The distance traveled is <var>6</var>.</li> <li>Day <var>4</var>: Travel from the <var>7</var>-th hotel to the <var>8</var>-th hotel. The distance traveled is <var>10</var>.</li> </ul></section> </div> </span>
p01215
<H1><font color="#000">Problem I:</font> Pythagoraslope</H1> <p> Alice, your girlfriend, is a student at an art school. She is in the final year, and now working hard to build a facture for fulfilling the requirement to graduate. Her work is a large pinball with many straight slopes. Before starting to build, she has made several plans, but is unsure if they work as expected. So she asked you, a professional programmer, for help. </p> <p> You have modeled this situation by a two dimensional plane with some line segments on it. In this model, there is gravitation downward, i.e., in the decreasing direction of <i>y</i>-coordinate. Your task is to write a program that simulates the pinball, and compute the last position where the ball crosses the <i>x</i>-axis. </p> <p> You may assume coefficient of restitution between the slopes and the ball is 0, i.e., when the ball collides a slope, it instantly loses the velocity component orthogonal to the slope. And since her pinball is so large, you may also assume that the volume of the ball is negligible. </p> <H2>Input</H2> <p> The input consists of multiple data sets. Each data set is given in the format below. </p> <pre> <i>N</i> <i>g</i> <i>x y</i> <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> ... <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> </pre> <p> where <i>N</i> (<i>N</i> &le; 100) is the number of slopes, <i>g</i> is gravity acceleration, and (<i>x</i>, <i>y</i>) is the initial position of the ball. Each of the following <i>N</i> lines represents a slope, which is a line segment between (<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>). </p> <p> You may assume that: </p> <ul> <li> all coordinates are more than or equal to 1, and less than or equal to 10,000;</li> <li> <i>x</i><sub><i>i</i>,1</sub> &ne; <i>x</i><sub><i>i</i>,2</sub> and <i>y</i><sub><i>i</i>,1</sub> &ne; <i>y</i><sub><i>i</i>,2</sub> for all 1 &le; <i>i</i> &le; <i>N</i>;</li> <li> no two line segments cross each other;</li> <li> extending or shrinking a slope by the length of 0.0001 does not change the ball’s trail, that is, do not change the set of slopes where the ball passes;</li> <li> the ball never collides to a slope at the angle of 90 &plusmn; 0.0001 degrees from the slope; and</li> <li> the initial position of the ball never lies on any slope.</li> </ul> </p> <p> The end of the input is indicated by a line containing a single zero. This is not a part of the data sets, and you must not process it. </p> <H2>Output</H2> <p> For each data set, output the <i>x</i>-coordinate of the final crossing point of the ball’s trail and the <i>x</i>-axis. Your program may print any number of digits after the decimal point, but the output must not contain an error greater than 10<sup>-4</sup> (= 0.0001). </p> <H2>Sample Input</H2> <pre> 3 1 120 1000 100 100 180 20 170 10 270 30 270 40 400 20 0 </pre> <H2>Output for the Sample Input</H2> <pre> 403.87458314 </pre>
p03228
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In the beginning, Takahashi has <var>A</var> cookies, and Aoki has <var>B</var> cookies. They will perform the following operation alternately, starting from Takahashi:</p> <ul> <li>If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.</li> </ul> <p>Find the numbers of cookies Takahashi and Aoki respectively have after performing <var>K</var> operations in total.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A,B \leq 10^9</var></li> <li><var>1 \leq K \leq 100</var></li> <li><var>A,B</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>A</var> <var>B</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing <var>K</var> operations in total.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 3 </pre> <p>The process will go as follows:</p> <ul> <li>In the beginning, Takahashi and Aoki have <var>5</var> and <var>4</var> cookies, respectively.</li> <li>Takahashi eats one cookie and gives two cookies to Aoki. They now have <var>2</var> and <var>6</var> cookies, respectively.</li> <li>Aoki gives three cookies to Takahashi. They now have <var>5</var> and <var>3</var> cookies, respectively.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314159265 358979323 84 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>448759046 224379523 </pre></section> </div> </span>
p02593
<span class="lang-en"> <p>Score : <var>2200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given positions <var>(X_i, Y_i)</var> of <var>N</var> enemy rooks on an infinite chessboard. No two rooks attack each other (at most one rook per row or column).</p> <p>You're going to replace one rook with a king and then move the king repeatedly to beat as many rooks as possible.</p> <p>You can't enter a cell that is being attacked by a rook. Additionally, you <strong>can't move diagonally to an empty cell</strong> (but you can beat a rook diagonally).</p> <p>(So this king moves like a superpawn that beats diagonally in 4 directions and moves horizontally/vertically in 4 directions.)</p> <p>For each rook, consider replacing it with a king, and find the minimum possible number of moves needed to beat the maximum possible number of rooks.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200\,000</var></li> <li><var>1 \leq X_i, Y_i \leq 10^6</var></li> <li><var>X_i \neq X_j</var></li> <li><var>Y_i \neq Y_j</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format.</p> <pre><var>N</var> <var>X_1</var> <var>Y_1</var> <var>X_2</var> <var>Y_2</var> <var>\vdots</var> <var>X_N</var> <var>Y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line is for scenario of replacing the rook at <var>(X_i, Y_i)</var> with your king. This line should contain one integer: the minimum number of moves to beat <var>M_i</var> rooks where <var>M_i</var> denotes the maximum possible number of beaten rooks in this scenario (in infinite time).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 1 8 6 10 2 7 4 4 9 3 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 0 7 5 0 0 </pre> <p>See the drawing below. If we replace rook 3 with a king, we can beat at most two other rooks. The red path is one of optimal sequences of moves: beat rook 1, then keep going down and right until you can beat rook 4. There are 7 steps and that's the third number in the output.</p> <p align="center"><img alt="path" src="https://img.atcoder.jp/agc047/rooks_path_small3.png"/></p> <p align="center"><em>x-coordinate increases from left to right, while y increases bottom to top.</em></p> <p>Starting from rook 2, 5 or 6, we can't beat any other rook. The optimal number of moves is 0.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 5 100 100 70 20 81 70 800 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>985 985 1065 1034 0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 2 5 4 4 13 12 12 13 14 17 17 19 22 22 16 18 19 27 25 26 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 2 9 9 3 3 24 5 0 25 </pre></section> </div> </span>
p02069
<style type="text/css"> blockquote { font-family: Menlo, Monaco, "Courier New", monospace; display: block; margin: 10px 0 10px 30px; font-size: 16px; line-height: 18px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; } table.ioexample { width: 100%; border-collapse: collapse; } table.ioexample td { width: 50%; border: 1px solid rgba(0, 0, 0, 0.15); vertical-align: top; padding: 5px; } .no-page-break { page-break-inside: avoid; } .page-break { page-break-before: always; } </style> <h3>Problem Statement</h3> <p>You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers:</p> <ul> <li>The minimum integer $x$ such that you can select $x$ intervals from the given $N$ intervals so that the union of the selected intervals is $[0, L)$.</li> <li>The minimum integer $y$ such that for all possible combinations of $y$ intervals from the given $N$ interval, it <em>does</em> cover $[0, L)$.</li> </ul> <p>We ask you to write a program to compute these two numbers.</p> <hr /> <h3>Input</h3> <p>The input consists of a single test case formatted as follows. </p> <blockquote>$N$ $L$ $l_1$ $r_1$ $l_2$ $r_2$ $\vdots$ $l_N$ $r_N$</blockquote> <p>The first line contains two integers $N$ ($1 \leq N \leq 2 \times 10^5$) and $L$ ($1 \leq L \leq 10^{12}$), where $N$ is the number of intervals and $L$ is the length of range to be covered, respectively. The $i$-th of the following $N$ lines contains two integers $l_i$ and $r_i$ ($0 \leq l_i &lt; r_i \leq L$), representing the range of the $i$-th interval $[l_i, r_i)$. You can assume that the union of all the $N$ intervals is $[0, L)$</p> <h3>Output</h3> <p>Output two integers $x$ and $y$ mentioned in the problem statement, separated by a single space, in a line.</p> <p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>3 3 0 2 1 3 1 2 </pre></td><td><pre>2 3 </pre></td></tr><tr><td><pre>2 4 0 4 0 4 </pre></td><td><pre>1 1 </pre></td></tr><tr><td><pre>5 4 0 2 2 4 0 3 1 3 3 4 </pre></td><td><pre>2 4 </pre></td></tr></table></div></p>
p00054
<H1>小数䜍の和</H1> <p> <var>a</var>, <var>b</var>, <var>n</var> は、いずれも正の敎数であるずしたす。分数 <var>a</var> / <var>b</var> の小数第 <var>i</var> 䜍の数を <var>f(i)</var> ずしたす (0 &le; <var>f(i)</var> &le; 9)。このずき、<var>i = 1</var> から <var>n</var> たでの <var>f(i)</var> の和を <var>s</var> ずしたす。<br/> <br/> <var>s = f(1) + f(2) +</var> ... <var>+ f(n)</var><br/> </p> <p> <var>a</var>, <var>b</var>, <var>n</var> を読み蟌んで、 <var>s</var> を出力しお終了するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなりたす。各デヌタセットずしお、3 ぀の敎数 <var>a</var> (1 &le; <var>a</var> &le; 1000), <var>b</var> (1 &le; <var>b</var> &le; 10000), <var>n</var> (1 &le; <var>n</var> &le; 100) が空癜区切りで行に䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、<var>s</var> を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 1 2 3 2 3 4 5 4 3 4 3 2 </pre> <H2>Output for the Sample Input</H2> <pre> 5 24 7 6 </pre>
p02439
<h1>Min-Max</h1> <p> For given three integers $a, b, c$, print the minimum value and the maximum value. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $a \; b \; c\;$ </pre> <p> Three integers $a, b, c$ are given in a line. </p> <h2>Output</h2> <p> Print the minimum and maximum values separated by a space in a line. </p> <h2>Constraints</h2> <ul> <li>$-1,000,000,000 \leq a, b, c \leq 1,000,000,000$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 5 3 </pre> <h2>Sample Output 1</h2> <pre> 3 5 </pre>
p00404
<h1>床</h1>   <p> ヒデペ博士の家の床には正方圢のタむルが敷き぀められおいたす。芞術に造詣が深いヒデペ博士は、赀、黄、青の塗料を䜿っおタむルに色を塗るこずにしたした。はじめに郚屋の適圓なタむルをひず぀遞び、以䞋の方法で色を塗っおいきたす。 </p> <ul> <li>タむルを塗る色を、赀図の番号、黄図の番号、青図の番号の順に倉えおいき、青の次はたた赀から始める。</li> <li>すでに色を塗った領域の隣に正方圢を远加し、そこに色を塗る。それらを合わせた領域が長方圢になるようにする。正方圢を远加する方向は、東、北、西、南の順に倉えおいき、南の次はたた東から始める図では、䞊方向が北、右方向が東である。</li> </ul> <br/> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/PCK2019_floor" width="800"/> </center> <br/><br/> <p> 最初に赀く塗ったタむルから東西方向に$x$個、南北方向に$y$個移動したずころにあるタむルは、䜕色に塗られおいるでしょうか。ただし、東の方向を$x$の正の方向、北の方向を$y$の正の方向ずしたす。 </p> <p> $x$ず$y$を入力し、タむルの色を出力するプログラムを䜜成せよ。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $x$ $y$ </pre> <p> 行に$x$ず$y$ ($-10^6 \leq x,y \leq 10^6$)が䞎えられる。 </p> <h2>出力</h2> <p> タむルの色が赀のずき1、黄のずき2、青のずき3を行に出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 0 0 </pre> <h3>出力䟋</h3> <pre> 1 </pre> <h3>入力䟋</h3> <pre> -4 5 </pre> <h3>出力䟋</h3> <pre> 2 </pre> <h3>入力䟋</h3> <pre> 8 -14 </pre> <h3>出力䟋</h3> <pre> 3 </pre>
p00111
<H1>博士の暗号</H1> <p> 博 士 : ?D-C'KOPUA </p> <p> ピヌタヌ : どうしたんですか、デビッド博士? わけのわからないこずを叫ぶのにはもう慣れたしたが、 今日は文章にすらなっおいたせんよ。 </p> <p> 博 士 : ほれ。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes1"> </center> <br/> <p> ピヌタヌ : なんですか? この衚は......ああ、予遞の問題にこんなのがありたした。衚を䜿っお文字を眮き換え るず文字数が枛るんですよね。たさか予遞ず本遞で同じ問題を出しお手を抜こうっお気じゃないでし ょうね。 </p> <p> 博 士 : 逆じゃよ。 </p> <p> ピヌタヌ : 逆? なるほど、今床は短くした文字列を元に戻そうっお問題ですか。ずいうこずは「?D-C'KOPUA」の 文字を、この衚を䜿っお「文字」から「笊号」に眮きかえるんですね......できたしたよ。 </p> <pre> 11111 00011 11101 00010 11110 01010 01110 01111 10100 00000 </pre> <p> 博 士 : うむ。次はこれじゃ。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes2"> </center> <br/> <p> ピヌタヌ : そうそう、こんな衚もありたしたね。これを逆に䜿うんだから「笊号」から「文字」に眮き換えればいい んですね。でも、最初は「11111」ですが衚にありたせんよ? </p> <p> 博 士 : そういうずきは、もっず短くするか、埌ろず぀なげるかしおみるのだよ。 </p> <p> ピ ヌ タ ヌ : じゃあ短くしお......あ、 「111」ならありたす。じゃあ最初は「P」ですね。そうするず残りは「11」ですが、 これはぎったり合うのがないから次の「00011」から 1 文字借りお「110」にすればいいんですね。 </p> <p> 博 士 : そうそう。぀たり「E」だね。 </p> <p> ピ ヌ タ ヌ : それで残るのが「0011」なので、これも次から借りお「00111」にしお「T」ず......。党郚できたした。最 埌の「0000」は捚おちゃえばいいんですよね? </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes3"> </center> <br/> <p> 博 士 : そうじゃ、よろしい。次はこれじゃ。 </p> <pre> ?D-C'?-C'-LMGZN?FNJKN- WEYN?P'QMRWLPZLKKTPOVRGDI </pre> <p> 博 士 : さらにこれじゃ。 </p> <pre> ?P'QNPY?IXX?IXXK.BI -G?R'RPP'RPOVWDMW?SWUVG'-LCMGQ </pre> <p> 博 士 : 仕䞊げにこうじゃ。 </p> <pre> ?P'QMDUEQ GADKOQ ?SWUVG'-LCMG?X?IGX,PUL.?UL.VNQQI </pre> <p> ピ ヌ タ ヌ : しっかし面倒だなあ。博士、今床は自分でプログラムを䜜っお䞋さいよ。 </p> <p> ずいうこずで、博士のかわりに、䞊の文章を眮き換えるプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットずしお、぀の文字列衚に含たれる文字からなる 200 文字以䞋の文字列が行に䞎えられたす。入力の終わりたで凊理しおください。デヌタセットの数は 200 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットごずに、倉換埌の文字列を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> ?D-C'KOPUA </pre> <H2>Output for the Sample Input</H2> <pre> PETER POTTER </pre> <!-- <p> Judge error has been fixed on 2009/10/12. We are very sorry for the inconvenience. </p> -->
p00541
<h2>城壁 (Rampart)</h2> <p> 歎史孊者である JOI 教授はか぀お存圚した IOI 王囜に぀いお研究しおいる </p> <p> 過去の調査によるずIOI 王囜は瞊 <var>H</var> 行暪 <var>W</var> 列のマスに区切られた長方圢の圢をしおいたIOI 王囜の銖郜は防衛のために城壁で囲われおいた </p> <p> IOI 王囜の銖郜を囲う城壁は次のような圢をしおいる城壁には倧きさず呌ばれる倀が定たっおいる倧きさ <var>s</var> (<var>s</var> &ge; 3) の城壁ずは<var>s</var> &times; <var>s</var> の正方圢の領域から倖呚以倖の (<var>s</var> − 2) &times; (<var>s</var> − 2) の正方圢の領域を陀いたものである </p> <p> 調査によるず銖郜を囲う城壁の倧きさは <var>L</var> 以䞊であったたたIOI 王囜のいく぀かのマスには城壁が存圚しなかったこずがわかっおいる </p> <p> JOI 教授はさらなる研究のために城壁ずしおありうるものが䜕通りあるかを知りたい </p> <h3>課題</h3> <p> IOI 王囜の倧きさず城壁の倧きさの最小倀城壁が存圚しなかったこずが分かっおいるマスの情報が䞎えられたずき城壁ずしおありうるものは䜕通りあるかを求めるプログラムを䜜成せよ </p> <h3>入力</h3> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li> 1 行目には敎数 <var>H</var>, <var>W</var>, <var>L</var>, <var>P</var> が空癜を区切りずしお曞かれおいるこれはIOI 王囜は瞊 <var>H</var> 行暪 <var>W</var> 列のマスに区切られた長方圢の圢をしおおり城壁の倧きさは <var>L</var> 以䞊であり城壁が存圚しなかったこずがわかっおいるマスが <var>P</var> マス存圚するこずを衚す</li> <li> 続く <var>P</var> 行のうちの <var>i</var> 行目 (1 &le; <var>i</var> &le; <var>P</var>) には敎数 <var>A<sub>i</sub></var>, <var>B<sub>i</sub></var> が空癜を区切りずしお曞かれおいるこれはIOI 王囜の䞊から <var>A<sub>i</sub></var> 行目巊から <var>B<sub>i</sub></var> 列目のマスには城壁が存圚しなかったこずがわかっおいるこずを衚す </ul> <h3>出力</h3> <p> 暙準出力に城壁ずしおありうるものは䜕通りあるかを衚す敎数を 1 行で出力せよ. </p> <h3>制限</h3> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li> 1 &le; <var>H</var> &le; 4 000 </li> <li> 1 &le; <var>W</var> &le; 4 000</li> <li> 3 &le; <var>L</var> &le; <var>H</var> か぀ 3 &le; <var>L</var> &le; <var>W</var></li> <li> 0 &le; <var>P</var> &le; 100 000</li> <li> 1 &le; <var>A<sub>i</sub></var> &le; <var>H</var> (1 &le; <var>i</var> &le; <var>P</var>)</li> <li> 1 &le; <var>B<sub>i</sub></var> &le; <var>W</var> (1 &le; <var>i</var> &le; <var>P</var>)</li> <li> (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) &ne; (<var>A<sub>j</sub></var>, <var>B<sub>j</sub></var>) (1 &le; <var>i</var> &lt; <var>j</var> &le; <var>P</var>)</li> </ul> <h3>入出力䟋</h3> <h3>入力䟋 1 </h3> <pre> 5 5 3 2 2 2 4 3 </pre> <h3>出力䟋 1</h3> <pre> 4 </pre> <p> この入力䟋の堎合城壁ずしおありうるものは以䞋の 4 通りが考えられるただし&times; で瀺したマスは城壁が存圚しなかったこずがわかっおいるマスである </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_rampart"> </center> <br> <h3>入力䟋 2</h3> <pre> 7 8 4 3 2 2 3 7 6 5 </pre> <h3> 出力䟋 2</h3> <pre> 13 </pre> <h3>入力䟋 3 </h3> <pre> 4000 4000 1234 4 1161 3028 596 1892 3731 2606 702 1530 </pre> <h3>出力䟋 3</h3> <pre> 7050792912 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02086
<h1>I: Palindrome Compliment</h1> <h2>問題文</h2> <p>小池くんはチヌムメむトをよく耒めたす。 圌はチヌムメむトである束厎くんを文字列 $S$ で耒めたす。その圢匏は以䞋の条件を満たしたす。</p> <ul> <li>$Hoge, Zaki, O$ は小文字アルファベットのみからなる文字列</li> <li>$S = Hoge + Zaki + Hoge + O$ ($+$ は文字列の結合を衚す)</li> <li>$S$ は回文</li> </ul> <p>小池くんは$Hoge$の長さを$N$ずしたずきに、束厎くんの耒め方が䜕通りあるのか気になりたした。 3人目のチヌムメンバヌにしおred coderであるあなたは小池くんの代わりに答えを蚈算するこずになりたした。</p> <p>文字列 $Zaki, O$ ず 敎数 $N$ が䞎えられるので、ありえる組み合わせの数を求めおください なお、答えは非垞に倧きくなる可胜性があるので、$10^9 + 7$ で割った 䜙りを出力しおください。</p> <h2>制玄</h2> <ul> <li>$Zaki$ ず $O$ は小文字アルファベットからなる文字列</li> <li>$1 \leq |Zaki| \leq 10^5$</li> <li>$1 \leq |O| \leq 10^5$</li> <li>$1 \leq N \leq 10^9$</li> </ul> <h2>入力</h2> <p>入力は以䞋の圢匏で暙準入力から䞎えられたす。</p> <pre>$Zaki$ $O$ $N$</pre> <h2>出力</h2> <p>答えを1行に出力しおください。</p> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre>zaki o 4 </pre> <h3>出力䟋1</h3> <pre>0 </pre> <h3>入力䟋2</h3> <pre>aab aa 3 </pre> <h3>出力䟋2</h3> <pre>26 </pre> <h3>入力䟋3</h3> <pre>aaa aaaa 3 </pre> <h3>出力䟋3</h3> <pre>1 </pre>
p00812
<H1><font color="#000">Problem B:</font> Equals are Equals</H1> <p> Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink. </p> <p> His headache came from the ``creativity'' of his students. They provided him a variety of ways to answer each problem. He has his own answer to each problem, which is correct, of course, and the best from his aesthetic point of view. </p> <p> Some of his students wrote algebraic expressions equivalent to the expected answer, but many of them look quite different from Mr. Simpson's answer in terms of their literal forms. Some wrote algebraic expressions not equivalent to his answer, but they look quite similar to it. Only a few of the students' answers were exactly the same as his. </p> <p> It is his duty to check if each expression is mathematically equivalent to the answer he has prepared. This is to prevent expressions that are equivalent to his from being marked as ``incorrect'', even if they are not acceptable to his aesthetic moral. </p> <p> He had now spent five days checking the expressions. Suddenly, he stood up and yelled, ``I've had enough! I must call for help.'' </p> <p> Your job is to write a program to help Mr. Simpson to judge if each answer is equivalent to the ``correct'' one. Algebraic expressions written on the papers are multi-variable polynomials over variable symbols <i>a</i>, <i>b</i>,..., <i>z</i> with integer coefficients, e.g., (<i>a</i> + <i>b</i><sup>2</sup>)(<i>a</i> - <i>b</i><sup>2</sup>), <i>ax</i><sup>2</sup> +2<i>bx</i> + <i>c</i> and (<i>x</i><sup>2</sup> +5<i>x</i> + 4)(<i>x</i><sup>2</sup> + 5<i>x</i> + 6) + 1. </p> <p> Mr. Simpson will input every answer expression as it is written on the papers; he promises you that an algebraic expression he inputs is a sequence of terms separated by additive operators `<span>+</span>' and `<span>-</span>', representing the sum of the terms with those operators, if any; a term is a juxtaposition of multiplicands, representing their product; and a multiplicand is either (a) a non-negative integer as a digit sequence in decimal, (b) a variable symbol (one of the lowercase letters `<span>a</span>' to `<span>z</span>'), possibly followed by a symbol `<span>^</span>' and a non-zero digit, which represents the power of that variable, or (c) a parenthesized algebraic expression, recursively. Note that the operator `<span>+</span>' or `<span>-</span>' appears only as a binary operator and not as a unary operator to specify the sing of its operand. </p> <p> He says that he will put one or more space characters before an integer if it immediately follows another integer or a digit following the symbol `<span>^</span>'. He also says he may put spaces here and there in an expression as an attempt to make it readable, but he will never put a space between two consecutive digits of an integer. He remarks that the expressions are not so complicated, and that any expression, having its `<span>-</span>'s replaced with `<span>+</span>'s, if any, would have no variable raised to its 10th power, nor coefficient more than a billion, even if it is fully expanded into a form of a sum of products of coefficients and powered variables. </p> <H2>Input</H2> <p> The input to your program is a sequence of blocks of lines. A block consists of lines, each containing an expression, and a terminating line. After the last block, there is another terminating line. A terminating line is a line solely consisting of a period symbol. </p> <p> The first expression of a block is one prepared by Mr. Simpson; all that follow in a block are answers by the students. An expression consists of lowercase letters, digits, operators `<span>+</span>', `<span>-</span>' and `<span>^</span>', parentheses `<span>(</span>' and `<span>)</span>', and spaces. A line containing an expression has no more than 80 characters. </p> <H2>Output</H2> <p> Your program should produce a line solely consisting of ``<span>yes</span>'' or ``<span>no</span>'' for each answer by the students corresponding to whether or not it is mathematically equivalent to the expected answer. Your program should produce a line solely containing a period symbol after each block. </p> <H2>Sample Input</H2> <pre> a+b+c (a+b)+c a- (b-c)+2 . 4ab (a - b) (0-b+a) - 1a ^ 2 - b ^ 2 2 b 2 a . 108 a 2 2 3 3 3 a 4 a^1 27 . . </pre> <H2>Output for the Sample Input</H2> <pre> yes no . no yes . yes yes . </pre>
p01700
<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>Golf</u></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><u>ゎルフ</u></h3> <!-- end ja only --> <!-- begin en only --> <!-- end en only --> <!-- begin ja only --> <p>クロセは超䞀流の腕を持ったバトルプログラマヌでありプログラミングコンテスト界隈でその名を知らぬ者はいない アルゎリズムデヌタマむニングハッキングAI  ありずあらゆる倧䌚を総なめにしおきた そんなクロセが次の目暙に据えた競技は「コヌドゎルフ」である </p> <p>コヌドゎルフずは䞎えられた問題に察し正答を返すプログラムの「゜ヌスコヌドの短さ」を競う競技である コヌドゎルフにおいおは異なるプログラミング蚀語間で公平な比范が難しいため䜿甚蚀語が限定されるこずが倚い クロセが次に狙っおいる倧䌚「ICPC (International Competition of Program Compactness)」では 「AJAGOL」ず呌ばれるプログラミング蚀語のみが䜿甚できるルヌルずなっおいる コヌドを1バむトでも短くするためクロセが初めに泚目したのは「定数宣蚀」の短瞮だった </p> <p>AJAGOLはいにしえの36bitアヌキテクチャに最適化しお蚭蚈された䌝統ある蚀語である 敎数を衚珟するために36bit笊号無し敎数型が甚意されおおり$0$ 以䞊 $2^{36}-1$ 以䞋の敎数を扱うこずができる さおAJAGOLの定数は通垞数字[0-9]を任意の個数甚いた十進数で宣蚀される たた挔算子ずしお以䞋の衚の挔算子を甚いるこずができる </p> <table style="align:center"border="1"><thead><tr><th style="width:80px">優先順䜍</th><th style="width:80px">挔算子</th><th style="width:120px">結合性</th><th style="width:240px">意味</th></tr> </thead> <tbody><tr><td>1</td><td>( , )</td><td>-</td><td>括匧</td></tr> <tr><td>2</td><td>^</td><td>右結合</td><td>冪乗: a^b := $a^b$</td></tr> <tr><td>3</td><td>*</td><td>巊結合</td><td>乗算: a*b := $a \times b$</td></tr> <tr><td>3</td><td>/</td><td>巊結合</td><td>陀算: a/b := $ \lfloor a \div b \rfloor$</td></tr> <tr><td>4</td><td>+</td><td>巊結合</td><td>加算: a+b := $a + b$</td></tr> <tr><td>4</td><td>-</td><td>巊結合</td><td>枛算: a-b := $a - b$</td></tr> </tbody> </table> <br> <p>ここで優先順䜍の倀が小さい挔算ほど優先的に蚈算され同じ倀のずきには結合性に埓った順序で蚈算される 䟋えば "<samp>2^2^3+8/3*2</samp>" ずいう蚈算匏は2^2^3+8/3*2 = 2^8+8/3*2 = 256+8/3*2 = 256+2*2 = 256+4 = 260 ずいう順序で蚈算される たた挔算途䞭の倀が $[0, 2^{36}-1]$ に収たらない蚈算やれロ陀算れロのれロ乗はAJAGOLでは実行時゚ラヌずなるため避ける必芁がある 䟋えば "<samp>2^36-100</samp>""<samp>1111/0</samp>""<samp>(2-2)^0</samp>" などは実行時゚ラヌずなる </p> <p>超䞀流のバトルプログラマヌであるクロセはこれらの挔算子を甚いるこずにより通垞よりも短い定数宣蚀が可胜であるこずを芋抜いた 䟋えば117649は蚀わずず知れた $7^6$ であるがAJAGOLの冪乗挔算子を甚いるこずで "<samp>7^6</samp>" ず3バむトで曞くこずができる これは通垞の "<samp>117649</samp>" ずいう宣蚀で必芁ずなる6バむトよりも3バむト短い よっおAJAGOLによるコヌドゎルフでは117649を定数ずしお甚いたい堎合には "<samp>7^6</samp>" ず宣蚀するのが基本ずなる </p> <p>定数宣蚀の短瞮はコヌドゎルフにおいお最も基本的なテクニックの1぀であるがあくたで小手先のテクニックずも蚀える このようなずころに倚倧な時間を掛けおいおは本質的なコヌドの短瞮に時間を割けなくなっおしたう そこでクロセは非負敎数を十進数で入力したずきそれを衚珟するAJAGOL定数宣蚀ずしお最も短いものを調べるこずにした </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットからなる 各デヌタセットは敎数 $N$ ($0 \leq N \leq 2^{36}-1$) を含む1行で䞎えられる 入力の終了は $-1$ のみを含む1行で衚される </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに察し䞎えられた敎数 $N$ を衚珟する最も短いAJAGOL定数宣蚀の長さを1行で出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>117649 1 125000 1610612736 68719476636 -1</pre> <h3>Output for Sample Input</h3> <pre>3 1 4 6 11</pre>
p01350
<H1>Problem B: Carrot Tour </H1> <p> うさぎがある囜を旅行しおいる. この囜には1 から<i>n</i> の番号が぀いた<i>n</i> 個の郜垂があり, うさぎは今郜垂1にいる. 郜垂<i>i</i> は座暙平面䞊の1 点(<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) ずみなす. </p> <p> うさぎは以䞋の条件をみたすように旅をする. </p> <ul> <li> 移動経路は折れ線であり, その各郚分は異なる2 郜垂を結ぶ線分でなければならない.</li> <li> 移動経路の党長は<i>r</i> 以䞋でなければならない. 経路のうち重なった郚分も, 通った回数分数える.</li> <li> 移動する方向が倉わるずき, 曲がる角床は<i>&theta;</i> 以䞋でなければならない. 最初の移動方向に制限はない.</li> </ul> <p> うさぎがある郜垂から別の郜垂ぞ移動をするず, 移動先の郜垂でニンゞンを1 本もらえる. 同じ郜垂を耇数回蚪れるこずは可胜であり, 蚪れるたびにニンゞンをもらえる. うさぎがこの旅で手に入れるこずのできるニンゞンの本数の最倧倀を求めよ. </p> <H2>Input</H2> <p> 入力の䞀行目には䞀぀の敎数<i>n</i> が, 二行目には二぀の実数<i>r</i>, <i>&theta;</i> がスペヌスで区切られお䞎えられる. </p> <p> 1 &le; <i>n</i> &le; 20<br> 0 &lt; <i>r</i> &lt; 10<sup>4</sup><br> 0&deg; &lt; <i>&theta;</i> &lt; 180&deg;<br> </p> <p> 続く<i>n</i> 行には, 敎数<i>x<sub>i</sub></i>, <i>y</sub>i</sub></i> がスペヌスで区切られお䞎えられる </p> <p> -10 000 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> &le; 10 000 </p> <p> <i>r</i>, <i>&theta;</i> を&plusmn;10<sup>−3</sup> 以内で倉化させおも答えは倉わらない.<br> どの2 ぀の郜垂の䜍眮も異なる. </p> <H2>Output</H2> <p> うさぎがこの旅で手に入れるこずのできるニンゞンの本数の最倧倀を䞀行に出力せよ. </p> <H2>Sample Input 1</H2> <pre> 5 100.1 90.1 0 0 0 10 5 5 10 0 10 10 </pre> <H2>Sample Output 1</H2> <pre> 10 </pre>
p02985
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices and <var>N-1</var> edges. The vertices are numbered <var>1</var> to <var>N</var>, and the <var>i</var>-th edge connects Vertex <var>a_i</var> and <var>b_i</var>.</p> <p>You have coloring materials of <var>K</var> colors. For each vertex in the tree, you will choose one of the <var>K</var> colors to paint it, so that the following condition is satisfied:</p> <ul> <li>If the distance between two different vertices <var>x</var> and <var>y</var> is less than or equal to two, <var>x</var> and <var>y</var> have different colors.</li> </ul> <p>How many ways are there to paint the tree? Find the count modulo <var>1\ 000\ 000\ 007</var>.</p> <p><details> <summary style="display: list-item; outline: none;">What is tree?</summary> A tree is a kind of graph. For detail, please see: <a href="https://ja.wikipedia.org/wiki/%E6%9C%A8_(%E6%95%B0%E5%AD%A6)">Wikipedia "Tree (graph theory)"</a></details></p> <p></p></section></div></span>
p03697
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given two integers <var>A</var> and <var>B</var> as the input. Output the value of <var>A + B</var>.</p> <p>However, if <var>A + B</var> is <var>10</var> or greater, output <code>error</code> instead.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>A</var> and <var>B</var> are integers.</li> <li><var>1 ≀ A, B ≀ 9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>A + B</var> is <var>10</var> or greater, print the string <code>error</code> (case-sensitive); otherwise, print the value of <var>A + B</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>error </pre></section> </div> </span>
p00668
<H1>Problem J: The Incubator</H1> <p> サラリヌマンの朝は早い。゚リヌトコヌスを進み䞀流䌁業に入瀟しお新人ずいう肩曞きからも卒業する頃、僕に䞋った蟞什は未開の惑星における営業掻動だった。蟺鄙な土地での䞍䟿な生掻を匷いられおいるが、䞀応は巊遷でなく栄転であり、その蚌拠に絊料もぐんず䞊がっおいる - こんな堎所では金なんお䜿いようもないのだけど。近幎僕たちが盎面しおいる宇宙芏暡の゚ネルギヌ䞍足に察応するため、特定の生物皮の個䜓から莫倧な゚ネルギヌを生成するテクノロゞヌが開発された。その特定の生物皮ずいうのが、この蟺鄙な惑星の固有皮なのだ。この生物が絶滅しないように保護し぀぀、適床に゚ネルギヌを回収しおいくのが僕の仕事だ。 </p> <p> ゚ネルギヌの回収は、いく぀かのステップからなる。たずは、゚ネルギヌの回収に䜿甚する個䜓を遞別する。個䜓によっお埗られる゚ネルギヌの量は倧きく異なるのだ。次に、遞別された芋蟌みのある個䜓に、むンキュベヌションずいう特別な凊理を行う。むンキュベヌトされた個䜓は膚倧な゚ネルギヌの源ずなる䜕かをを絶えず蓄えたり吐き出したりするので、個䜓にできるだけ倚くの゚ネルギヌの源ずなる䜕かが蓄えられおいる瞬間を狙っお、円環の理に導く。するずお埅ちかねの゚ネルギヌが手に入る、ずいう仕組みだ。 </p> <p> ゚リヌトサラリヌマンに課せられるノルマは厳しい。しかし、僕にずっお数十䞇のむンキュベヌトされた個䜓を管理するのは朝飯前だ。今日は月末なので本瀟に月報を提出しなければならないが、今月はずおも良い個䜓に遭遇したこずもあっお、過去最高の成瞟になりそうだ。 </p> <p> ず喜んでいたのも束の間、最埌の最埌でひどいミスをやらかしおしたった。SQL文を打ち間違えお、今月の成果を蚘録しおいるデヌタベヌスのテヌブル 1 ぀をたるごずふっ飛ばしおしたったのだ。あれがなければ、今月の成果は党く無しずいうこずになっおしたう。降栌、巊遷、あるいは解雇もありえるかもしれない。 </p> <p> 最埌の頌みの綱は、䜜業のたびにこために぀けおいたログファむルだ。僕はい぀も、個䜓をむンキュベヌトするたびに䞀意な敎数の番号を振り、むンキュベヌトされた個䜓たちの番号を 1 ぀の配列に保存しおいる。僕の営業掻動は、次のような行動からなる。 </p> <ol> <li>個䜓をむンキュベヌトし、その個䜓に番号 x を割り圓お、その個䜓の番号を配列の末尟に远加する。</li> <li>配列の n 番目の番号が瀺す個䜓を円環の理に導く。</li> <li>番号 x の個䜓を円環の理に導く。</li> <li>残念ながら僕は最倧 <i>lim</i> 䜓の個䜓しか管理できない。個䜓をむンキュベヌトしたずき、もしむンキュベヌト枈みの個䜓が <i>lim</i> を超えたならば、昔にむンキュベヌトした個䜓から順に <i>lim</i> 以䞋になるたで円環の理に導く。</li> </ol> <p> 僕はこれら 4 ぀の営業掻動を行うたびに、欠かさずログファむルに蚘入しおいる。しかし、4 の掻動だけはログファむルに䞀切蚘入しおいない。そうしおも特に曖昧なずころは残らないためだ。 </p> <p> い぀も僕は、個䜓の番号の配列の操䜜を愚盎に行なっおいる。しかし今床ばかりは、愚盎に操䜜しながらログファむルを走査しおいおは間に合いそうにない。月報の提出期限は 5 時間埌に迫っおいる。 </p> <p> そこで、君たちにお願いがあるんだ。ログファむルから僕の営業掻動を再珟するプログラムを曞いおほしい。もし曞いおくれたら、お瀌に君たちの願い事を䜕でも 1 ぀叶えおあげよう。䜕だっお構わない。どんな願いこずだっお叶えおあげられるよ。 </p> <h2>Input</h2> <p> 入力は耇数のケヌスからなる。 各ケヌスは以䞋のフォヌマットで䞎えられる。 </p> <pre> ここには入力のフォヌマットを曞く。 <i>q</i> <i>lim</i> <i>query<sub>0</sub></i> <i>x<sub>0</sub></i> . . . <i>query<sub>q-1</sub></i> <i>x<sub>q-1</sub></i> </pre> <p> <i>query<sub>i</sub></i> が0の時、むンキュベヌトした個䜓に <i>x<sub>i</sub></i> の番号を割り圓おたこずを衚す。 <br> <i>query<sub>i</sub></i> が1の時、配列の <i>x<sub>i</sub></i> 番目の番号が瀺す個䜓を円環の理に導く。<br> <i>query<sub>i</sub></i> が2の時、その時点で配列に含たれおいる䞭で <i>x<sub>i</sub></i> 番目の個䜓の番号を出力する<br> <i>query<sub>i</sub></i> が3の時、番号が <i>x<sub>i</sub></i> の個䜓を円環の理に導く。<br> <i>q</i> = 0 か぀ <i>lim</i> = 0の時入力の終わりを衚す。<br> </p> <p> <i>lim</i> は32bit signed integerで衚すこずができる正の敎数である。<br> すべおのク゚リヌに぀いお、<i>x<sub>i</sub></i> は0以䞊の敎数で32bit signed integerで衚すこずができる。<br> 0のク゚リヌに぀いお、<i>x<sub>i</sub></i> は32bit signed integerの範囲に収たる非負敎数で衚される。<br> 1,2のク゚リヌに぀いお、<i>x<sub>i</sub></i> の倀は1以䞊の敎数である。たた存圚しない配列の番号が指定されるこずはない<br> 3のク゚リヌに぀いお、存圚しない個䜓番号が入力に含たれるこずはない。<br> たた䞀床消去された個䜓の番号が倀が同じテストケヌス内で、別の個䜓に割り圓おられるこずはない。<br> </p> <p> ゞャッゞデヌタは次の2぀のうち少なくずも片方を満たす。<br> 1 &le; q &le; 400,000 か぀テストケヌスの数が5個以䞋<br> 1 &le; q &le; 10,000 か぀テストケヌスの数は50個以䞋<br> </p> <h2>Output</h2> <p> 入力のク゚リヌが2の堎合、x番目の個䜓番号を出力する<br> 各ケヌスの最埌には"end"を出力する<br> </p> <h2>Sample input</h2> <pre> 22 5 0 0 0 1 0 2 0 3 0 4 2 1 2 2 2 3 2 4 2 5 0 5 2 1 0 6 2 2 3 3 2 2 2 2 1 2 2 2 2 1 2 2 2 3 30 5 0 383594529 1 1 0 868094164 0 708344471 0 4102559 0 944076771 0 320398558 1 1 0 949521499 0 1035499529 0 585547493 0 915496840 0 721553343 0 405934659 0 814301872 1 1 2 3 0 919753364 1 1 0 69231610 2 2 0 373477673 0 842917649 0 961543702 0 907959899 2 1 2 2 2 3 2 4 2 5 30 5 0 726736645 0 1 0 344304573 0 241734870 3 726736645 1 3 2 1 0 586879203 2 3 0 511883046 0 481344051 0 154183395 0 435126242 0 185906768 1 1 0 383123551 0 20253038 1 5 2 1 2 2 0 163044554 3 435126242 0 105612613 0 725050544 0 559442328 2 1 2 2 2 3 2 4 2 5 0 0 </pre> <H2>Sample output</H2> <pre> 0 1 2 3 4 1 3 4 4 5 2 5 6 end 405934659 405934659 69231610 373477673 842917649 961543702 907959899 end 1 586879203 154183395 435126242 383123551 163044554 105612613 725050544 559442328 end </pre> <hr> <p> The University of Aizu Programming Contest 2011 Summer<br> 原案: Tomoya Sakai<br> 問題文: Takashi Tayama<br> </p>
p02655
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> boxes numbered <var>1</var> to <var>N</var>, and <var>M</var> balls numbered <var>1</var> to <var>M</var>. Currently, Ball <var>i</var> is in Box <var>A_i</var>.</p> <p>You can do the following operation:</p> <ul> <li>Choose a box containing two or more balls, pick up one of the balls from that box, and put it into another box.</li> </ul> <p>Since the balls are very easy to break, you cannot move Ball <var>i</var> more than <var>C_i</var> times in total. Within this limit, you can do the operation any number of times.</p> <p>Your objective is to have Ball <var>i</var> in Box <var>B_i</var> for every <var>i</var> (<var>1 \leq i \leq M</var>). Determine whether this objective is achievable. If it is, also find the minimum number of operations required to achieve it.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq M \leq 10^5</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li><var>1 \leq C_i \leq 10^5</var></li> <li>In the situation where the objective is achieved, every box contains one or more balls. That is, for every <var>i</var> (<var>1 \leq i \leq N</var>), there exists <var>j</var> such that <var>B_j=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>A_1</var> <var>B_1</var> <var>C_1</var> <var>A_2</var> <var>B_2</var> <var>C_2</var> <var>\vdots</var> <var>A_M</var> <var>B_M</var> <var>C_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the objective is unachievable, print <var>-1</var>; if it is achievable, print the minimum number of operations required to achieve it.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 1 2 1 1 1 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>We can achieve the objective in three operations, as follows:</p> <ul> <li>Pick up Ball <var>1</var> from Box <var>1</var> and put it into Box <var>2</var>.</li> <li>Pick up Ball <var>2</var> from Box <var>2</var> and put it into Box <var>1</var>.</li> <li>Pick up Ball <var>3</var> from Box <var>1</var> and put it into Box <var>3</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 1 2 1 2 1 1 </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>5 5 1 2 1 2 1 1 1 3 2 4 5 1 5 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 </pre></section> </div> </span>
p03947
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Two foxes Jiro and Saburo are playing a game called <em>1D Reversi</em>. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.</p> <p>In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string <var>S</var>. There are |S| (the length of <var>S</var>) stones on the board, and each character in <var>S</var> represents the color of the <var>i</var>-th (<var>1 ≩ i ≩ |S|</var>) stone from the left. If the <var>i</var>-th character in <var>S</var> is <code>B</code>, it means that the color of the corresponding stone on the board is black. Similarly, if the <var>i</var>-th character in <var>S</var> is <code>W</code>, it means that the color of the corresponding stone is white.</p> <p>Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ |S| ≩ 10^5</var></li> <li>Each character in <var>S</var> is <code>B</code> or <code>W</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The 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 minimum number of new stones that Jiro needs to place for his purpose.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>BBBWW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.</p> <p>In either way, Jiro's purpose can be achieved by placing one stone.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>WWWWWW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>If all stones are already of the same color, no new stone is necessary.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>WBWBWBWBWB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9 </pre></section> </div> </span>
p00392
<h1>Common-Prime Sort</h1> <p> You are now examining a unique method to sort a sequence of numbers in increasing order. The method only allows swapping of two numbers that have a common prime factor. For example, a sequence [6, 4, 2, 3, 7] can be sorted using the following steps. <br/> <span>Step 0: 6 4 2 3 7</span> (given sequence)<br/> <span>Step 1: 2 4 6 3 7</span> (elements 6 and 2 swapped)<br/> <span>Step 2: 2 6 4 3 7</span> (elements 4 and 6 swapped)<br/> <span>Step 3: 2 3 4 6 7</span> (elements 6 and 3 swapped)<br/> </p> <p> Depending on the nature of the sequence, however, this approach may fail to complete the sorting. You have given a name "Coprime sort" to this approach and are now examining if a given sequence is coprime-sortable. </p> <p> Make a program to determine if a given sequence can be sorted in increasing order by iterating an arbitrary number of swapping operations of two elements that have a common prime number. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $a_1$ $a_2$ $...$ $a_N$ </pre> <p> The first line provides the number of elements included in the sequence $N$ ($2 \leq N \leq 10^5$). The second line provides an array of integers $a_i$ ($2 \leq a_i \leq 10^5$) that constitute the sequence. </p> <h2>Output</h2> <p> Output "<span>1</span>" if the sequence is coprime-sortable in increasing order, or "<span>0</span>" otherwise. </p> <h2>Sample Input 1</h2> <pre> 5 6 4 2 3 7 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 7 2 9 6 5 6 7 3 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre>
p00238
<!-- <p> 䞉床の飯よりゲヌム奜きのだいご君は暇さえあればゲヌムばかりしおいたした。ですが、だいご君も高校幎生。クラスはもう受隓モヌドに入っおいたす。受隓勉匷をするからには、圓然ゲヌムで遊べる時間が短くなっおしたいたす。たずは1日に勉匷をする時間を決めお、残った時間をゲヌムなどに䜿うこずにしたしたが、だいご君は今たで蚈画を守れたためしがありたせんでした。芋かねたあなたは、だいご君の勉匷時間を管理するプログラムを曞くこずにしたした。 </p> 1日にやらなければならない勉匷の目暙時間をt、勉匷を開始した時刻をs、終了した時刻をfずおきたす。 --> <p> 勉匷を開始した時刻ず終了した時刻の情報を基に、1日で勉匷した時間の合蚈が <var>t</var> 以䞊であるかをチェックし、達しおいない堎合は足りない時間を求めるプログラムを䜜成したす。時間は1時間を1単䜍ずし、分や秒は考えないものずしたす。時刻は24時間衚蚘で1時間単䜍で衚したす。 </p> <p> 1日の勉匷の目暙時間ず、実際に勉匷した時間の情報勉匷の回数 <var>n</var>、それぞれの勉匷の開始時刻 <var>s</var> ず終了時刻 <var>f</var>を入力ずし、勉匷時間の合蚈が目暙に達しおいるかを調べ、達しおいれば "OK" を、達しおいない堎合は足りない時間を出力するプログラムを䜜成しおください。ただし、それぞれ行った勉匷時間は重耇したせん。 </p> <center> 䟋 <table style="border: 1px #000 solid" cellpadding="3" cellspacing="3"> <tr> <td style="border: 1px #000 solid">目暙時間</td> <td style="border: 1px #000 solid">勉匷した時間</td> <td style="border: 1px #000 solid">刀定</td> </tr> <tr> <td style="border: 1px #000 solid">10時間</td> <td style="border: 1px #000 solid"> 6時〜11時  5時間<br> 12時〜15時  3時間<br> 18時〜22時  4時間</td> <td style="border: 1px #000 solid">OK</td> </tr> <tr> <td style="border: 1px #000 solid">14時間</td> <td style="border: 1px #000 solid">6時〜11時  5時間<br> 13時〜20時  7時間<br></td> <td style="border: 1px #000 solid">2時間䞍足</td> </tr> </table> </center> <br> <h2>入力</h2> <p> 耇数のデヌタセットの䞊びが䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>t</var> <var>n</var> <var>s<sub>1</sub></var> <var>f<sub>1</sub></var> <var>s<sub>2</sub></var> <var>f<sub>2</sub></var> : <var>s<sub>n</sub></var> <var>f<sub>n</sub></var> </pre> <p> 行目に日の目暙時間 <var>t</var> (0 &le; <var>t</var> &le; 22)、 行目に勉匷の回数 <var>n</var> (1 &le; <var>n</var> &le; 10)が䞎えられたす。続く <var>n</var> 行に <var>i</var> 回目の勉匷の開始時刻 <var>s<sub>i</sub></var> ず終了時刻 <var>f</var> (6 &le; <var>s<sub>i</sub></var>, <var>f<sub>i</sub></var> &le; 22) が䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <h2>出力</h2> <p> デヌタセットごずに、OK たたは足りない時間を行に出力したす。 </p> <h2>入力䟋</h2> <pre> 10 3 6 11 12 15 18 22 14 2 6 11 13 20 0 </pre> <h2>出力䟋</h2> <pre> OK 2 </pre>
p02205
<h2>たしざんひきざん (Calculation Training)</h2> <p>square1001 君は E869120 君に、誕生日プレれントずしお二぀の数字 $A$ ず $B$ をプレれントしたした。</p> <p>E869120 君はこの二぀の数字を䜿っお、蚈算トレヌニングをするこずにしたした。</p> <p>具䜓的には、E869120君は次の操䜜をちょうど $N$ 回これらの数に行いたす。</p> <ul> <li>奇数回目の操䜜のずき、$A$ を $A-B$ で眮き換える</li> <li>偶数回目の操䜜のずき、$B$ を $A+B$ で眮き換える</li> </ul> <br> <p>E869120君が $N$ 回の操䜜をした埌、$A$ ず $B$ の倀がそれぞれいく぀になっおいるか求めおください。</p> <h3>入力</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre> $N$ $A$ $B$ </pre> <h3>出力</h3> <p>E869120君が $N$ 回の操䜜をした埌の $A$ ず $B$ の倀を、この順に空癜区切りで出力しおください。</p> <p>ただし、最埌には改行を入れるこず。</p> <h3>制玄</h3> <ul> <li>$1 \leq N \leq 1000000000000000000 \ (= 10^{18})$</li> <li>$1 \leq A \leq 1000000000 \ (= 10^9)$</li> <li>$1 \leq B \leq 1000000000 \ (= 10^9)$</li> <li>入力は党お敎数である。</li> </ul> <h3>入力䟋1</h3> <pre> 3 3 4 </pre> <h3>出力䟋1</h3> <pre> -4 3 </pre> <p>$(A, B)$ の倀は $(3,4) → (-1,4) → (-1,3) → (-4,3)$ ず倉化したす。</p> <h3>入力䟋2</h3> <pre> 8 6 9 </pre> <h3>出力䟋2</h3> <pre> 3 -6 </pre>
p03044
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge in the tree connects Vertex <var>u_i</var> and Vertex <var>v_i</var>, and its length is <var>w_i</var>. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:</p> <ul> <li>For any two vertices painted in the same color, the distance between them is an even number.</li> </ul> <p>Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq u_i &lt; v_i \leq N</var></li> <li><var>1 \leq w_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>u_1</var> <var>v_1</var> <var>w_1</var> <var>u_2</var> <var>v_2</var> <var>w_2</var> <var>.</var> <var>.</var> <var>.</var> <var>u_{N - 1}</var> <var>v_{N - 1}</var> <var>w_{N - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a coloring of the vertices that satisfies the condition, in <var>N</var> lines. The <var>i</var>-th line should contain <code>0</code> if Vertex <var>i</var> is painted white and <code>1</code> if it is painted black.</p> <p>If there are multiple colorings that satisfy the condition, 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 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 0 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 5 2 2 3 10 1 3 8 3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 0 1 0 1 </pre></section> </div> </span>
p01079
<h1>Problem H: Hogemon Get</h1> <h2>Problem</h2> <p> がっちょ君は人気のゲヌムHogemon Getに熱䞭しおいる。がっちょ君が䜏んでいる䌚接囜はそれぞれ1から<var>N</var>の番号が぀いおいる<var>N</var>個の町からなる。たた、䌚接囜には<var>M</var>本の道があり、すべおの道は異なる2぀の町を結んでいる。がっちょ君は道を双方向に移動するこずができるが、道以倖を通っお、ある町から別の町に行くこずはできない。</p> <p> Hogemon Getでは、町<var>i</var>でボヌルを<var>d<sub>i</sub></var>個入手するこずができる。ただし、ある町で再びボヌルを入手するためには、最埌にその町でボヌルを入手しおから15分以䞊経過しおいる必芁がある。なお、がっちょ君は町1、町<var>N</var>を含むすべおの町を䜕床でも蚪れるこずができる。 </p> <p> がっちょ君は最初、町1にいお、町<var>N</var>に<var>R</var>分以内で移動しなければならない。぀たり、<var>R</var>分埌に町<var>N</var>にいる必芁がある。がっちょ君は移動の際に、最倧でいく぀のボヌルを入手するこずができるだろうか。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>M</var> <var>R</var> <var>d<sub>1</sub></var> <var>d<sub>2</sub></var> ... <var>d<sub>N</sub></var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var> ... <var>a<sub>M</sub></var> <var>b<sub>M</sub></var> <var>c<sub>M</sub></var> </pre> <p> 入力はすべお敎数である。<br> 1行目に町の個数<var>N</var>,道の本数<var>M</var>,制限時間<var>R</var>が空癜区切りで䞎えられる。<br> 2行目に町<var>i</var>(<var>i</var>=1,2,...,<var>N</var>)に蚪れるこずで入手するこずができるボヌルの個数<var>d<sub>i</sub></var>が空癜区切りで䞎えられる。<br> 3行目から<var>M</var>+2行目に道<var>j</var>(<var>j</var>=1,2,...,<var>M</var>)の情報<var>a<sub>j</sub></var>,<var>b<sub>j</sub></var>,<var>c<sub>j</sub></var>が空癜区切りで䞎えられる。<var>j</var>番目の道は町<var>a<sub>j</sub></var>ず町<var>b<sub>j</sub></var>の間を<var>c<sub>j</sub></var>分で移動できるこずを衚す。 </p> <h2>Constraints</h2> <ul> <li>3 &le; <var>N</var> &le; 30</li> <li><var>N</var>-1 &le; <var>M</var> &le; min(<var>N</var>&times;(<var>N</var>-1)/2, 300) <li>10 &le; <var>R</var> &le; 1000</li> <li>0 &le; <var>d<sub>i</sub></var> &le; 10</li> <li><var>d<sub>1</sub></var>&nbsp;=&nbsp;<var>d<sub>N</sub></var>&nbsp;=&nbsp;0</li> <li>1 &le; <var>a<sub>j</sub></var> &lt; <var>b<sub>j</sub></var> &le; <var>N</var></li> <li>5 &le; <var>c<sub>j</sub></var> &le; 100</li> <li>町1から町<var>N</var>ぞは<var>R</var>分以内で移動できるこずが保蚌されおいる</li> <li>ある2぀の町の組に察しお2本以䞊の道があるこずはない</li> </ul> <h2>Output</h2> <p> 町1から町<var>N</var>ぞ<var>R</var>分以内に移動するたでに入手するこずができる最倧のボヌルの個数を1行で出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 5 4 40 0 1 1 1 0 1 2 5 2 3 5 3 4 5 4 5 5 </pre> <h2>Sample Output 1</h2> <pre> 6 </pre> <div style="width: 500px;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_H_figure1" alt="図1" style="width: 500px;"> </div> <br> <table border="1"> <tr><td width="100">経過時間(分)</td><td width="100">町の番号</td><td width="120">ボヌルの数(個)</td></tr> <tr><td>0</td><td>1</td><td>0</td></tr> <tr> <td>5</td><td>2</td><td>1</td></tr> <tr> <td>10</td><td>3</td><td>2</td></tr> <tr> <td>15</td><td>4</td><td>3</td></tr> <tr> <td>20</td><td>3</td><td>3</td></tr> <tr> <td>25</td><td>2</td><td>4</td></tr> <tr> <td>30</td><td>3</td><td>5</td></tr> <tr> <td>35</td><td>4</td><td>6</td></tr> <tr> <td>40</td><td>5</td><td>6</td></tr> </table> <p> ※経過時間20分の町3では最埌に町3でボヌルを入手しおから15分経過しおいないのでボヌルを入手するこずができない。 </p> <h2>Sample Input 2</h2> <pre> 4 3 100 0 3 1 0 1 2 5 2 3 30 3 4 5 </pre> <h2>Sample Output 2</h2> <pre> 16 </pre> <div style="width: 500px;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_H_figure2" alt="図2" style="width: 500px;"> </div> <br> <table border="1"> <tr><td width="100">経過時間(分)</td><td width="100">町の番号</td><td width="120">ボヌルの数(個)</td></tr> <tr style="text-align:right" ><td>0</td><td>1</td><td>0</td></tr> <tr> <td>5</td><td>2</td><td>3</td></tr> <tr> <td>20</td><td>2</td><td>6</td></tr> <tr> <td>35</td><td>2</td><td>9</td></tr> <tr> <td>50</td><td>2</td><td>12</td></tr> <tr> <td>65</td><td>2</td><td>15</td></tr> <tr> <td>95</td><td>3</td><td>16</td></tr> <tr> <td>100</td><td>4</td><td>16</td></tr> </table> <br/> <h2>Sample Input 3</h2> <pre> 5 4 50 0 1 1 10 0 1 2 10 2 3 10 2 4 10 4 5 10 </pre> <h2>Sample Output 3</h2> <pre> 22 </pre>
p01583
<H1><font color="#000">Problem C:</font> Craftsman</H1> <p> Takeshi, a famous craftsman, accepts many offers from all over Japan. However, the tools which he is using now has become already too old. So he is planning to buy new tools and to replace the old ones before next use of the tools. Some offers may incur him monetary cost, if the offer requires the tools to be replaced. Thus, it is not necessarily best to accept all the orders he has received. Now, you are one of his disciples. Your task is to calculate the set of orders to be accepted, that maximizes his earning for a given list of orders and prices of tools. His earning may shift up and down due to sale income and replacement cost. </p> <p> He always purchases tools from his friend's shop. The shop discounts prices for some pairs of items when the pair is purchased at the same time. You have to take the discount into account. The total price to pay may be not equal to the simple sum of individual prices. </p> <p> You may assume that all the tools at the shop are tough enough. Takeshi can complete all orders with replaced tools at this time. Thus you have to buy at most one tool for each kind of tool. </p> <H2>Input</H2> <p> The input conforms to the following format: </p> <p> <i>N M P</i><br/> <i>X</i><sub>1</sub> <i>K</i><sub>1</sub> <i>I</i><sub>1,1</sub> ... <i>I</i><sub>1, <i>K</i><sub>1</sub></sub><br/> ...<br/> <i>X</i><sub><i>N</i></sub> <i>K</i><sub><i>N</i></sub> <i>I</i><sub><i>N</i>,1</sub> ... <i>I</i><sub><i>N</i>, <i>K</i><sub><i>N</i></sub></sub><br/> <i>Y</i><sub>1</sub><br/> ...<br/> <i>Y<sub>M</sub></i><br/> <i>J</i><sub>1,1</sub> <i>J</i><sub>1,2</sub> <i>D</i><sub>1</sub><br/> ...<br/> <i>J</i><sub><i>P</i>,1</sub> <i>J</i><sub><i>P</i>,2</sub> <i>D<sub>P</sub></i><br/> </p> <p> where <i>N</i>, <i>M</i>, <i>P</i> are the numbers of orders, tools sold in the shop and pairs of discountable items, respectively. </p> <p> The following <i>N</i> lines specify the details of orders. <i>X<sub>i</sub></i> is an integer indicating the compensation for the <i>i</i>-th order, and <i>K<sub>i</sub></i> is the number of tools required to complete the order. The remaining part of each line describes the tools required for completing the order. Tools are specified by integers from 1 through <i>M</i>. </p> <p> The next <i>M</i> lines are the price list at the shop of Takeshi's friend. An integer <i>Y<sub>i</sub></i> represents the price of the <i>i</i>-th tool. </p> <p> The last <i>P</i> lines of each test case represent the pairs of items to be discounted. When Takeshi buys the <i>J</i><sub><i>i</i>,1</sub>-th and the <i>J</i><sub><i>i</i>,2</sub>-th tool at the same time, he has to pay only <i>D<sub>i</sub></i> yen, instead of the sum of their individual prices. It is guaranteed that no tool appears more than once in the discount list, and that max{<i>Y<sub>i</sub></i>, <i>Y<sub>j</sub></i>} &lt; <i>D<sub>i,j</sub></i> &lt; <i>Y<sub>i</sub></i> + <i>Y<sub>j</sub></i> for every discount prices, where <i>D<sub>i,j</sub></i> is the discount price of <i>i</i>-th and <i>j</i>-th tools bought at the same time. </p> <p> Also it is guaranteed that 1 &le; <i>N</i> &le; 100, 2 &le; <i>M</i> &le; 100, 1 &le; <i>K<sub>i</sub></i> &le; 100, 1 &le; <i>P</i> &le; <i>M</i>/2 and 1 &le; <i>X<sub>i</sub></i>, <i>Y<sub>i</sub></i> &le; 1000. </p> <H2>Output</H2> <p> Output the maximum possible earning of Takeshi to the standard output. </p> <H2>Sample Input and Output</H2> <H2>Input #1</H2> <pre> 3 4 2 100 2 1 2 100 1 3 100 1 4 20 20 50 150 1 2 30 3 4 180 </pre> <H2>Output #1</H2> <pre> 120 </pre> <br/> <H2>Input #2</H2> <pre> 1 2 1 100 1 2 20 40 1 2 51 </pre> <H2>Output #2</H2> <pre> 60 </pre> <br/>
p03414
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a directed graph with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>1, 2, ..., N</var>, and the edges are numbered <var>1, 2, ..., M</var>. Edge <var>i</var> points from Vertex <var>a_i</var> to Vertex <var>b_i</var>.</p> <p>For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph.</p> <p>Here, the reversion of Edge <var>i</var> means deleting Edge <var>i</var> and then adding a new edge that points from Vertex <var>b_i</var> to Vertex <var>a_i</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 1000</var></li> <li><var>1 \leq M \leq 200,000</var></li> <li><var>1 \leq a_i, b_i \leq N</var></li> <li><var>a_i \neq b_i</var></li> <li>If <var>i \neq j</var>, then <var>a_i \neq a_j</var> or <var>b_i \neq b_j</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>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>Print <var>M</var> lines. In the <var>i</var>-th line, if the reversion of Edge <var>i</var> would change the number of the strongly connected components in the graph, print <code>diff</code>; if it would not, print <code>same</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 1 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>same diff same </pre> <p>The number of the strongly connected components is <var>3</var> without reversion of edges, but it will become <var>1</var> if Edge <var>2</var> is reversed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 1 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>diff diff </pre> <p>Reversion of an edge may result in multiple edges in the graph.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 9 3 2 3 1 4 1 4 2 3 5 5 3 3 4 1 2 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>same same same same same diff diff diff diff </pre></section> </div> </span>
p01429
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script> <h2>問題文</h2> <p> 䞖の䞭の少女たちはキュゥべえず契玄し願いを叶えおもらいそれずひきかえに魔法少女ずなる䜿う魔法の圢・効果は願いに匷く圱響を受ける魔法少女<i>さやか</i>ちゃんは最近キュゥべえず契玄した新米魔法少女である<i>さやか</i>の願いは「事故のため指が動かなくなり音楜を挔奏するのを諊めおいた男の子を助けるこず」であったので䜜る魔方陣は音笊が茪の䞊に䞊んだ圢をしおいる </p> <p><i>さやか</i>は <var>N</var> 個の音笊を持っおおりそれらを茪の䞊に䞊べるこずによっお魔方陣を䜜る音笊をどのような順番で䞊べるかは圌女の自由である魔方陣を䜜るために粟神力が消費されその量は音笊の配眮によっお以䞋のように決たる </p> <ul> <li>たず <var>M</var> 個の正の敎数からなる<b>音楜的矎しさ</b> <var>S_1,\ ...,\ S_M</var> が定められおいる</li> <li>各音笊は音皋を持っおおり音皋は <var>1</var> から <var>M</var> の敎数 <var>K_1,\ ...,\ K_N</var> で衚される</li> <li>音皋が <var>a,\ b\ (a&le;b)</var> であるような 2 ぀の音笊の間の<b>反発力</b>ずは <var>[(S_a\ +\ ...\ +\ S_b) / L]</var> で定められる量であるここで<var>L</var> は入力で䞎えられる定数であり実数 <var>x</var> に察しお <var>[x]</var> は <var>x</var> を越えない最倧の敎数を衚すものずする</li> <li><i>さやか</i>の消費する粟神力は各2぀の隣り合う音笊 (<var>N</var> 組存圚する) の間の反発力の合蚈倀である</li> </ul> <p> 䟋えば音楜的矎しさがそれぞれ <var>\{100,\ 200,\ 300,\ 400,\ 500\}</var> で音皋が <var>\{1,\ 3,\ 5,\ 4\}</var> である音笊をこの順番で䞊べお魔方陣を䜜った時消費される粟神力は <var>37\ (=[(100+200+300)/99]+[(300+400+500)/99]+[(500+400)/99]+[(400+300+200+100)/99])</var> ずなる </p> <p> 䜿うべき音笊の音皋の組み合わせず各音皋の音楜的矎しさが䞎えられるので消費される粟神力の最小倀を求めよ </p> <h2>入力圢匏</h2> <p>入力は以䞋の圢匏で䞎えられる</p> <pre><var> N\ M\ L\\ K_1\ K_2\ 
\ K_N\\ S_1\ S_2\ 
\ S_M </var></pre> <p><var>N</var> は<i>さやか</i>の持っおいる音笊の数<var>M</var> は音楜的矎しさの倀の個数<var>L</var> は反発力を定めるのに䜿われる定数である</p> <p><var>K_i</var> は音笊の音皋を衚し<var>S_j</var> は音楜的矎しさを衚す</p> <h2>出力圢匏</h2> 消費される粟神力の最小倀を <var>1</var> 行に出力せよ <h2>制玄</h2> <ul> <li><var>3 &le; N &le; 2,000</var></li> <li><var>1 &le; M &le; 10<sup>5</sup></var></li> <li><var>1 &le; L &le; 10<sup>5</sup></var></li> <li><var>1 &le; K_i &le; M</var></li> <li><var>1 &le; S_j &le; 10<sup>5</sup></var></li> <li>入力倀は党お敎数である</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 4 5 99 1 4 5 3 100 200 300 400 500 </pre> <h3>出力䟋1</h3> <pre>37</pre> <h3>入力䟋 2</h3> <pre> 3 1 99 1 1 1 100 </pre> <h3>出力䟋 2</h3> <pre>3</pre> <hr> <address>Problem Setter: Flat35</address>
p03101
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>H</var> rows and <var>W</var> columns of white square cells.</p> <p>You will choose <var>h</var> of the rows and <var>w</var> of the columns, and paint all of the cells contained in those rows or columns.</p> <p>How many white cells will remain?</p> <p>It can be proved that this count does not depend on what rows and columns are chosen.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq H, W \leq 20</var></li> <li><var>1 \leq h \leq H</var></li> <li><var>1 \leq w \leq W</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>h</var> <var>w</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of white cells that will remain.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>There are <var>3</var> rows and <var>2</var> columns of cells. When two rows and one column are chosen and painted in black, there is always one white cell that remains.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 4 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01096
<h3>Daruma Otoshi</h3> <p> You are playing a variant of a game called "Daruma Otoshi (Dharma Block Striking)". </p> <p> At the start of a game, several wooden blocks of the same size but with varying weights are stacked on top of each other, forming a tower. Another block symbolizing Dharma is placed atop. You have a wooden hammer with its head thicker than the height of a block, but not twice that. </p> <p> You can choose any two adjacent blocks, except Dharma on the top, differing at most 1 in their weight, and push both of them out of the stack with a single blow of your hammer. The blocks above the removed ones then fall straight down, without collapsing the tower. You cannot hit a block pair with weight difference of 2 or more, for that makes too hard to push out blocks while keeping the balance of the tower. There is no chance in hitting three blocks out at a time, for that would require superhuman accuracy. </p> <p> The goal of the game is to remove as many blocks as you can. Your task is to decide the number of blocks that can be removed by repeating the blows in an optimal order. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2016_D1" width="80%"> <p> Figure D1. Striking out two blocks at a time </p> </center> <p> In the above figure, with a stack of four blocks weighing 1, 2, 3, and 1, in this order from the bottom, you can hit middle two blocks, weighing 2 and 3, out from the stack. The blocks above will then fall down, and two blocks weighing 1 and the Dharma block will remain. You can then push out the remaining pair of weight-1 blocks after that. </p> <h3>Input</h3> <p> The input consists of multiple datasets. The number of datasets is at most 50. Each dataset is in the following format. </p> <p> <i>n</i> <br> <i>w</i><sub>1</sub> <i>w</i><sub>2</sub> &hellip; <i>w</i><sub><i>n</i></sub> <br> </p> <p> <i>n</i> is the number of blocks, except Dharma on the top. <i>n</i> is a positive integer not exceeding 300. <i>w</i><sub><i>i</i></sub> gives the weight of the <i>i</i>-th block counted from the bottom. <i>w</i><sub><i>i</i></sub> is an integer between 1 and 1000, inclusive. </p> <p> The end of the input is indicated by a line containing a zero. </p> <h3>Output</h3> <p> For each dataset, output in a line the maximum number of blocks you can remove. </p> <h3>Sample Input</h3> <pre> 4 1 2 3 4 4 1 2 3 1 5 5 1 2 3 6 14 8 7 1 4 3 5 4 1 6 8 10 4 6 5 5 1 3 5 1 3 0 </pre> <h3>Output for the Sample Input</h3> <pre> 4 4 2 12 0 </pre>
p03551
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is <code>YES</code> or <code>NO</code>.</p> <p>When he checked the detailed status of the submission, there were <var>N</var> test cases in the problem, and the code received TLE in <var>M</var> of those cases.</p> <p>Then, he rewrote the code to correctly solve each of those <var>M</var> cases with <var>1/2</var> probability in <var>1900</var> milliseconds, and correctly solve each of the other <var>N-M</var> cases without fail in <var>100</var> milliseconds.</p> <p>Now, he goes through the following process:</p> <ul> <li>Submit the code.</li> <li>Wait until the code finishes execution on all the cases.</li> <li>If the code fails to correctly solve some of the <var>M</var> cases, submit it again.</li> <li>Repeat until the code correctly solve all the cases in one submission.</li> </ul> <p>Let the expected value of the total execution time of the code be <var>X</var> milliseconds. Print <var>X</var> (as an integer).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq M \leq {\rm min}(N, 5)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>X</var>, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, <var>X</var> is an integer not exceeding <var>10^9</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3800 </pre> <p>In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with <var>1/2</var> probability in <var>1900</var> milliseconds.</p> <p>The code will succeed in one attempt with <var>1/2</var> probability, in two attempts with <var>1/4</var> probability, and in three attempts with <var>1/8</var> probability, and so on.</p> <p>Thus, the answer is <var>1900 \times 1/2 + (2 \times 1900) \times 1/4 + (3 \times 1900) \times 1/8 + ... = 3800</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>18400 </pre> <p>The code will take <var>1900</var> milliseconds in each of the <var>2</var> cases, and <var>100</var> milliseconds in each of the <var>10-2=8</var> cases. The probability of the code correctly solving all the cases is <var>1/2 \times 1/2 = 1/4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>608000 </pre></section> </div> </span>
p02710
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge in this tree connects Vertex <var>a_i</var> and <var>b_i</var>. Additionally, each vertex is painted in a color, and the color of Vertex <var>i</var> is <var>c_i</var>. Here, the color of each vertex is represented by an integer between <var>1</var> and <var>N</var> (inclusive). The same integer corresponds to the same color; different integers correspond to different colors.</p> <p>For each <var>k=1, 2, ..., N</var>, solve the following problem:</p> <ul> <li>Find the number of simple paths that visit a vertex painted in the color <var>k</var> one or more times.</li> </ul> <p><strong>Note:</strong> The simple paths from Vertex <var>u</var> to <var>v</var> and from <var>v</var> to <var>u</var> are not distinguished.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq c_i \leq N</var></li> <li><var>1 \leq a_i,b_i \leq N</var></li> <li>The given graph is a tree.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>c_1</var> <var>c_2</var> <var>...</var> <var>c_N</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answers for <var>k = 1, 2, ..., N</var> in order, each in its own line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 1 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 4 0 </pre> <p>Let <var>P_{i,j}</var> denote the simple path connecting Vertex <var>i</var> and <var>j</var>.</p> <p>There are <var>5</var> simple paths that visit a vertex painted in the color <var>1</var> one or more times:<br/> <var>P_{1,1}\,,\,</var> <var>P_{1,2}\,,\,</var> <var>P_{1,3}\,,\,</var> <var>P_{2,3}\,,\,</var> <var>P_{3,3}</var> </p> <p>There are <var>4</var> simple paths that visit a vertex painted in the color <var>2</var> one or more times:<br/> <var>P_{1,2}\,,\,</var> <var>P_{1,3}\,,\,</var> <var>P_{2,2}\,,\,</var> <var>P_{2,3}</var> </p> <p>There are no simple paths that visit a vertex painted in the color <var>3</var> one or more times. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 1 2 3 4 5 1 2 2 3 3 4 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 8 10 5 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>8 2 7 2 5 4 1 7 5 3 1 1 2 2 7 4 5 5 6 6 8 7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>18 15 0 14 23 0 23 0 </pre></section> </div> </span>
p03802
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke loves flags.</p> <p>Snuke is placing <var>N</var> flags on a line.</p> <p>The <var>i</var>-th flag can be placed at either coordinate <var>x_i</var> or coordinate <var>y_i</var>.</p> <p>Snuke thinks that the flags look nicer when the smallest distance between two of them, <var>d</var>, is larger. Find the maximum possible value of <var>d</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 10^{4}</var></li> <li><var>1 ≀ x_i, y_i ≀ 10^{9}</var></li> <li><var>x_i</var> and <var>y_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_N</var> <var>y_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 3 2 5 1 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The optimal solution is to place the first flag at coordinate <var>1</var>, the second flag at coordinate <var>5</var> and the third flag at coordinate <var>9</var>. The smallest distance between two of the flags is <var>4</var> in this case.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 2 2 2 2 2 2 2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There can be more than one flag at the same position.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>22 93 6440 78 6647 862 11 8306 9689 798 99 801 521 188 206 6079 971 4559 209 50 94 92 6270 5403 560 803 83 1855 99 42 504 75 484 629 11 92 122 3359 37 28 16 648 14 11 269 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>17 </pre></section> </div> </span>
p00687
<H1> Unable Count</H1> <BLOCKQUOTE> <P><I>I would, if I could,<BR> If I couldn't how could I?<BR> I couldn't, without I could, could I?<BR> Could you, without you could, could ye?<BR> Could ye? could ye?<BR> Could you, without you could, could ye?</I></P></BLOCKQUOTE> <P>It is true, as this old rhyme says, that we can only DO what we can DO and we cannot DO what we cannot DO. Changing some of DOs with COUNTs, we have another statement that we can only COUNT what we can DO and we cannot COUNT what we cannot DO, which looks rather false. We could count what we could do as well as we could count what we couldn't do. Couldn't we, if we confine ourselves to finite issues?</P> <P>Surely we can count, in principle, both what we can do and what we cannot do, if the object space is finite. Yet, sometimes we cannot count in practice what we can do or what we cannot do. Here, you are challenged, in a set of all positive integers up to (and including) a given bound <I>n</I>, to count all the integers that cannot be represented by a formula of the form <I>a</I>*<I>i</I>+<I>b</I>*<I>j</I>, where <I>a</I> and <I>b</I> are given positive integers and <I>i</I> and <I>j</I> are variables ranging over non-negative integers. You are requested to report only the result of the count, i.e. how many integers are not representable. For example, given <i>n</i> = 7, <i>a</i> = 2, <i>b</i> = 5, you should answer 2, since 1 and 3 cannot be represented in a specified form, and the other five numbers are representable as follows:</P> <PRE> 2 = 2*1 + 5*0, 4 = 2*2 + 5*0, 5 = 2*0 + 5*1, 6 = 2*3 + 5*0, 7 = 2*1 + 5*1. </PRE> <H2>Input</H2> <P>The input is a sequence of lines. Each line consists of three integers, <I>n, a</I> and <I>b, </I>in this order,<I> </I>separated by a space<I>.</I> The integers <I>n</I>, <I>a</I> and <I>b</I> are all positive and at most one million, except those in the last line. The last line consists of three zeros.</P> <H2>Output</H2> <P>For each input line except the last one, your program should write out a line that contains only the result of the count.</P> <H2>Sample Input</H2> <pre> 10 2 3 10 2 5 100 5 25 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 80 </pre>
p01995
<h2>G: 回文郚分列 (Palindromic Subsequences)</h2> <h3>問題</h3> <p>英小文字のみからなる文字列 <var>S</var> が䞎えられるので、この文字列 <var>S</var> の<b>連続ずは限らない</b>郚分列であっお、回文であるものは䜕皮類あるかを求めおください。</p> <p>ここで、<var>S</var> の連続ずは限らない郚分列ずは、元の文字列 <var>S</var> から <b><var>1</var> 文字以䞊</b> <var>|S|</var> 文字以䞋を任意に遞択し (遞択するそれぞれの文字の䜍眮は非連続でも良い)、それらを元の順番通りに連結させおできた文字列のこずを指したす。この問題においお、空文字列は郚分列ずしお認められないこずに泚意しおください。</p> <p>たた、文字列 <var>X</var> が回文であるずは、元の文字列 <var>X</var> ず、<var>X</var> を反転した文字列 <var>X’</var> が等しいこずを指したす。</p> <p>さらに、異なる郚分列のずりかたの結果<b>同じ回文が生成されたずしおも、それは重耇しお数えない</b>こずに泚意しおください。䟋えば <var>S = </var> <code>acpc</code> である堎合、 <var>2</var> 文字目のみからなる郚分列ず、<var>4</var> 文字目のみからなる郚分列はどちらも回文 <code>c</code> ですが、これは耇数回数えず、合わせお䞀床だけ数えるこずずしたす。</p> <p>答えは非垞に倧きくなるこずがあるので、 <var>1,000,000,007</var> で割った䜙りを出力しおください。</p> <h3>入力圢匏</h3> <pre><var>S</var></pre> <h3>制玄</h3> <ul> <li> <var>1 \leq |S| \leq 2,000</var></li> <li> <var>S</var> に含たれる文字は英小文字のみである</li> </ul> <h3>出力圢匏</h3> <ul> <li> 答えを <var>1,000,000,007</var> で割った䜙りを <var>1</var> 行で出力しおください。</li> </ul> <h3>入力䟋1</h3> <pre>acpc</pre> <h3>出力䟋1</h3> <pre>5</pre> <p>文字列 <code>acpc</code> の連続ずは限らない郚分列であっお回文であるものは、 <code>a</code>, <code>c</code>, <code>cc</code>, <code>cpc</code>, <code>p</code> の <var>5</var> 皮類です。郚分列の皮類数を数えるこずに泚意しおください。</p> <h3>入力䟋2</h3> <pre>z</pre> <h3>出力䟋2</h3> <pre>1</pre> <p>条件を満たす郚分列は <code>z</code> のみです。空文字列は郚分列ずしお認められないこずに泚意しおください。</p> <h3>入力䟋3</h3> <pre>madokamagica</pre> <h3>出力䟋3</h3> <pre>28</pre>
p02340
<!--<h1>写像12盾 その10:ボヌルに区別なし・箱に区別なし・入れ方に制限なし</h1>--> <h1>Balls and Boxes 10</h1> <table border=""> <tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr> <tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr> <tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr> <tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr> <tr><th>Indistinguishable</th><th>Indistinguishable</th><td style="background-color:#aff">10</td><td>11</td><td>12</td></tr> </table> <h2>Problem</h2> <p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p> <p>Find the number of ways to put the balls under the following conditions:</p> <ul> <li>Each ball is <b>not</b> distinguished from the other.</li> <li>Each box is <b>not</b> distinguished from the other.</li> <li>Each ball can go into only one box and no one remains outside of the boxes.</li> <li>Each box can contain an arbitrary number of balls (including zero).</li> </ul> <p>Note that you must print this count modulo $10^9+7$.</p> <h2>Input</h2> <pre> $n$ $k$ </pre> <p>The first line will contain two integers $n$ and $k$.</p> <h2>Output</h2> <p>Print the number of ways modulo $10^9+7$ in a line.</p> <h2>Constraints</h2> <ul> <li>$1 \le n \le 1000$</li> <li>$1 \le k \le 1000$</li> </ul> <h2>Sample Input 1</h2> <pre> 5 3 </pre> <h2>Sample Output 1</h2> <pre> 5 </pre> <h2>Sample Input 2</h2> <pre> 10 5 </pre> <h2>Sample Output 2</h2> <pre> 30 </pre> <h2>Sample Input 3</h2> <pre> 100 100 </pre> <h2>Sample Output 3</h2> <pre> 190569292 </pre>
p03223
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given <var>N</var> integers; the <var>i</var>-th of them is <var>A_i</var>. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.</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 \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>:</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the absolute differences between the adjacent elements after arranging the given integers in a row in any order you like.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 6 8 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>21 </pre> <p>When the integers are arranged as <var>3,8,1,6,2</var>, the sum of the absolute differences between the adjacent elements is <var>|3 - 8| + |8 - 1| + |1 - 6| + |6 - 2| = 21</var>. This is the maximum possible sum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 1 4 1 5 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>25 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 5 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p03389
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given three integers <var>A</var>, <var>B</var> and <var>C</var>. Find the minimum number of operations required to make <var>A</var>, <var>B</var> and <var>C</var> all equal by repeatedly performing the following two kinds of operations in any order:</p> <ul> <li>Choose two among <var>A</var>, <var>B</var> and <var>C</var>, then increase both by <var>1</var>.</li> <li>Choose one among <var>A</var>, <var>B</var> and <var>C</var>, then increase it by <var>2</var>.</li> </ul> <p>It can be proved that we can always make <var>A</var>, <var>B</var> and <var>C</var> all equal by repeatedly performing these operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq A,B,C \leq 50</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required to make <var>A</var>, <var>B</var> and <var>C</var> all equal.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>We can make <var>A</var>, <var>B</var> and <var>C</var> all equal by the following operations:</p> <ul> <li>Increase <var>A</var> and <var>C</var> by <var>1</var>. Now, <var>A</var>, <var>B</var>, <var>C</var> are <var>3</var>, <var>5</var>, <var>5</var>, respectively.</li> <li>Increase <var>A</var> by <var>2</var>. Now, <var>A</var>, <var>B</var>, <var>C</var> are <var>5</var>, <var>5</var>, <var>5</var>, respectively.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 6 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>31 41 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>23 </pre></section> </div> </span>
p02961
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Jumbo Takahashi will play golf on an infinite two-dimensional grid.</p> <p>The ball is initially at the origin <var>(0, 0)</var>, and the goal is a grid point (a point with integer coordinates) <var>(X, Y)</var>. In one stroke, Jumbo Takahashi can perform the following operation:</p> <ul> <li>Choose a grid point whose Manhattan distance from the current position of the ball is <var>K</var>, and send the ball to that point.</li> </ul> <p>The game is finished when the ball reaches the goal, and the score will be the number of strokes so far. Jumbo Takahashi wants to finish the game with the lowest score possible.</p> <p>Determine if the game can be finished. If the answer is yes, find one way to bring the ball to the goal with the lowest score possible.</p> <p><details><summary>What is Manhattan distance?</summary><div></div></details></p> <p>The Manhattan distance between two points <var>(x_1, y_1)</var> and <var>(x_2, y_2)</var> is defined as <var>|x_1-x_2|+|y_1-y_2|</var>.</p> <p></p></section></div></span>