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> 大学対抗とは言っても、1つの学校から複数のチームが参戦します。そこで、できるだけ多くの学校がアジア地区予選に出場できるように、突破チームの選抜には以下の選抜ルールが適用されます: </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、所属、正解数、ペナルティ:空白区切りの4つの整数)<br> I<sub>2</sub> U<sub>2</sub> A<sub>2</sub> P<sub>2</sub> (2番目のチームのID、所属、正解数、ペナルティ:空白区切りの4つの整数)<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、所属、正解数、ペナルティ:空白区切りの4つの整数)<br> </p> <p> n は 300 以下であり、I<sub><i>i</i></sub>, U<sub><i>i</i></sub> は 1 以上 1000 以下とします。1つのデータセットに、同じ 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/> 平面上にどの3点も同じ直線上に乗らないように<var>N</var>個の点を置きます。そのとき、どのように点を置いても、k個の点をうまく選ぶとk個の角をもつ凸多角形が必ず作れると予想されています。 今のところ、三角形ならば<var>N</var>=3、四角形ならば<var>N</var>=5、五角形ならば<var>N</var>=9、六角形ならば<var>N</var>=17であればよいことが、2006年までに証明されています。また、三角形以上のすべてのk角形に対して、<var>N</var>=1+2<sup><var>k</var>-2</sup>という予想がありますが、いまだ証明されていません。これは100年にわたり研究が進められている難問です。<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> 1行目に平面上の点の個数<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> 続く1行に質問の数<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> どの3点も同じ直線上には乗らない。</li> <li> 各質問に対して面積最小の凸多角形は1つであり、2番目に小さい凸多角形との面積の差は 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> ゲームではバトンを1本使い、最初はゼッケン 0 番の生徒がバトンを持っています。そこから、以下の手順を <var>M</var> 回繰り返します。まず、現時点でバトンを持っている生徒が適当な正の整数 <var>a</var> を宣言します。<var>a</var> が偶数のときは時計回り、奇数のときは反時計回りに隣の生徒にバトンを渡していき、<var>a</var> 番目にバトンを受け取った生徒が脱落します。脱落した生徒は、時計回りで隣の生徒にバトンを渡し、円から抜けます。 </p> <p> ゲームが終わった後に円に残った生徒は、放課後の掃除が1年間免除されます。しかし、ここ数年は生徒数が増えたため、全校生徒を集めるのが難しくなってきています。そこで、競技プログラミング部のあなたは、シミュレーションで掃除が免除される生徒を求めるプログラムを作成するよう頼まれました。 </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> 入力は3行であり、1行目に生徒の人数 <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) が与えられる。続く1行に、<var>i</var> 回目の繰り返しで最初にバトンを持っている生徒が宣言する整数<var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; 100) が与えられる。続く1行に、質問としてゼッケン番号 <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 となる. このとき,ジャンプの危険度の合計は最小となる. この例は1つ目の入出力例に対応している. </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) が1行に与えられます。 </p> <H2>Output</H2> <p> 蔵を破る順番を1行に出力してください。蔵の番号を空白で区切ってください。 </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> ジョウ君とヤエさんは昼休みにテニスをします。ただし、昼休みは時間が限られているので、短い時間で終わるように、得点について以下の3つのルールで行います。 </p> <ul> <li> 相手が3点以下のときに先に5点とれば勝ち。</li> <li> 4対4の同点になったときは、その直後に連続して2点とった方が勝ち。</li> <li> 4対4の後に双方が1点ずつとったときは引き分け。</li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_tennis" width="600"> </center> <p> 以下の図は、ジョウ君とヤエさんの試合で起こり得るすべての状況を表しています。丸の中の左の数がジョウ君の得点、右がヤエさんの得点です。Aと書いた矢印はジョウ君が1点とったことを、Bと書いた矢印はヤエさんが1点とったことを表します。 </p> <p> ジョウ君とヤエさんの得点が与えられたとき、試合開始からその得点状況になるまでに、上の図で通り得るすべての経路を列挙するプログラムを作成してください。 </p> <h2>入力</h2> <p> 入力は1つのデータセットからなる。入力データは以下の形式で与えられる。 </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)の列で表し、辞書式順序(英和辞書で単語が並んでいる順番)になるように並べる。1つの経路を1行に出力する。経路の前後には空白を出力しない。 </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) が空白区切りで1行に与えられます。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、<var>s</var> を1行に出力します。 </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>タイルを塗る色を、赤(図の番号1)、黄(図の番号2)、青(図の番号3)の順に変えていき、青の次はまた赤から始める。</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> 1行に$x$と$y$ ($-10^6 \leq x,y \leq 10^6$)が与えられる。 </p> <h2>出力</h2> <p> タイルの色が赤のとき1、黄のとき2、青のとき3を1行に出力する。 </p> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 0 0 </pre> <h3>出力例1</h3> <pre> 1 </pre> <h3>入力例2</h3> <pre> -4 5 </pre> <h3>出力例2</h3> <pre> 2 </pre> <h3>入力例3</h3> <pre> 8 -14 </pre> <h3>出力例3</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> 複数のデータセットが与えられます。各データセットとして、1つの文字列(表に含まれる文字からなる 200 文字以下の文字列)が1行に与えられます。入力の終わりまで処理してください。データセットの数は 200 を超えません。 </p> <H2>Output</H2> <p> 各データセットごとに、変換後の文字列を1行に出力してください。 </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> 三度の飯よりゲーム好きのだいご君は暇さえあればゲームばかりしていました。ですが、だいご君も高校3年生。クラスはもう受験モードに入っています。受験勉強をするからには、当然ゲームで遊べる時間が短くなってしまいます。まずは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> 1行目に1日の目標時間 <var>t</var> (0 &le; <var>t</var> &le; 22)、 2行目に勉強の回数 <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 または足りない時間を1行に出力します。 </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>