question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01484
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body> <h1> Icy Composer</h1> <p> Time Limit: 8 sec / Memory Limit: 64 MB </p> <h2> F: 氷の䜜曲家</h2> <p> 岡郚錬倪郎(愛称オカレン)は西掋音楜の第䞀人者である 圌は5歳から䜜曲を行うこずができた倩才であり圌が䜜詞・䜜曲した『攻城の槌』はずおも有名である 才胜あふれるオカレンだが残念なこずに圌はレストランで食べた魚にあたっお亡くなっおいる </p> <p> ・・・少なくずもこの䞖界線ではそういうこずになっおいる 䞖界線ずは䜕か 䞀぀の歎史は䞀぀の䞖界線に察応する 我々が歩んできた歎史ずは無限に存圚する䞖界線のうちの䞀぀に過ぎず 別の䞖界線ではたた違った歎史が刻たれおいる </p> <p> オカレンは自らを埅ちうける過酷な未来に立ち向かうために別の䞖界線ぞず旅立぀こずを決意したのだった オカレンが目指す䞖界線はかの有名な䞖界線「ヒャダむンズゲヌト」である 「ヒャダむンズゲヌト」では党おの魚は氷の魔法を甚いお新鮮なたた冷凍保存されるため魚にあたる人はいない </p> <p> 䞖界線はアルファベットの小文字からなる文字列で衚される 「ヒャダむンズゲヌト」を衚す文字列は既に解明されおいるが非垞に長い文字列で衚される これを簡朔に衚蚘するため文字列 <i>seq</i> の <i>N</i> 回の繰り返しを <i>N</i>(<i>seq</i>) ず圧瞮しお衚す ここで <i>N</i> は1以䞊の自然数であり <i>seq</i> は小文字からなる文字列か圧瞮しお衚された文字列たたはそれらをいく぀か連結した文字列である </p> <p> 䟋えば以䞋の衚蚘は文字列 bbbababababxbbbababababx を衚す </p> <pre> 2(3(b)4(ab)x) </pre> <p> オカレンは圌のも぀「魔県リヌディングヒャダむナヌ」によっお圌がいる䞖界線から次に移動できる䞖界線を読みずるこずができる 圌がいる䞖界線は「ヒャダむンズゲヌト」から遠く離れおいるため盎接「ヒャダむンズゲヌト」ぞ移動するこずはできない オカレンは「ヒャダむンズゲヌト」にできるだけ近づくために「ヒャダむンズゲヌト」に察する類䌌床が高い䞖界線ぞず移動するこずにした </p> <p> 「ヒャダむンズゲヌト」を衚す文字列を <i>x</i> ある䞖界線を衚す文字列を<i>y</i>ずした堎合 <i>x</i>に察する<i>y</i>の類䌌床は <i>y</i> の郚分文字列のうち <i>x</i> にも郚分文字列ずしお珟れるものの数である ただし <i>y</i> の郚分文字列ずしお同じ文字列が耇数回珟れたずしおもそれらは別々に数えるものずする 類䌌床が同じ䞖界線が耇数ある堎合は先に入力ずしお䞎えられた䞖界線の方が類䌌床が高いずみなすものずする </p> <p> 諞君には䞖界線「ヒャダむンズゲヌト」を衚す文字列ずオカレンが次に移動できる䞖界線に察応する文字列が耇数䞎えられたずきに「ヒャダむンズゲヌト」に察する類䌌床が最も高い䞖界線を求めおもらいたい </p> <p> 健闘を祈る<br/> ゚ル・プサむ・コンガリィ </p> <h2> Input</h2> <p> 入力は以䞋の圢匏で䞎えられる </p> <pre> <i>n</i> <i>m</i> <i>k</i> <i>s</i> <i>t<sub>1</sub></i> <i>t<sub>2</sub></i> ... <i>t<sub>k</sub></i> </pre> <p> 入力圢匏の各倉数の意味は以䞋の通りである </p> <ul> <li> <i>n</i> はヒャダむンズゲヌトを衚す文字列 <i>s</i> の長さ (1 &lt;= <i>n</i> &lt;= 250)</li> <li> <i>m</i> はオカレンが移動できる䞖界線を衚す文字列の長さ (1 &lt;= <i>m</i> &lt;= 400)</li> <li> <i>k</i> はオカレンが移動できる䞖界線を衚す文字列の数 (1 &lt;= <i>k</i> &lt;= 5)</li> <li> <i>s</i> はヒャダむンズゲヌトを衚す文字列</li> <li> <i>t<sub>i</sub></i> はオカレンが移動できる䞖界線を衚す文字列 (1 &lt;= <i>i</i> &lt;= <i>k</i>)</li> </ul> <h2> Output</h2> <p> 文字列 <i>s</i> に最も類䌌する文字列 <i>t<sub>i</sub></i> の番号 <i>i</i> ず類䌌床を空癜区切りで䞀行で出力せよ </p> <h2> Sample Input 1</h2> <pre> 5 3 2 aaaaa aaa aab </pre> <h2> Sample Output 1</h2> <pre> 1 6 </pre> <h2> Sample Input 2</h2> <pre> 10 3 3 2(ab)3(bc) abc bcb cbc </pre> <h2> Sample Output 2</h2> <pre> 2 6 </pre> <h2> Sample Input 3</h2> <pre> 13 24 1 2(3(b)4(ab)x) bbbababababxbbbababababx </pre> <h2> Sample Output 3</h2> <pre> 1 300 </pre> <h2> Sample Input 4</h2> <pre> 12 7 5 hyadainsgate hyadain mahyado behoimi megante moshyas </pre> <h2> Sample Output 4</h2> <pre> 1 28 </pre> <h2> Sample Input 5</h2> <pre> 44 6 5 sh1000(1000(1000(1000(ee))))t100(a)paz100(u) sheeta pazuuu romusk apalou rlaput </pre> <h2> Sample Output 5</h2> <pre> 2 21 </pre> </body> </html>
p03143
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a connected undirected graph with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>1</var> to <var>N</var>, and the edges are numbered <var>1</var> to <var>M</var>. Also, each of these vertices and edges has a specified weight. Vertex <var>i</var> has a weight of <var>X_i</var>; Edge <var>i</var> has a weight of <var>Y_i</var> and connects Vertex <var>A_i</var> and <var>B_i</var>.</p> <p>We would like to remove zero or more edges so that the following condition is satisfied:</p> <ul> <li>For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.</li> </ul> <p>Find the minimum number of edges that need to be removed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>N-1 \leq M \leq 10^5</var></li> <li><var>1 \leq X_i \leq 10^9</var></li> <li><var>1 \leq A_i &lt; B_i \leq N</var></li> <li><var>1 \leq Y_i \leq 10^9</var></li> <li><var>(A_i,B_i) \neq (A_j,B_j)</var> (<var>i \neq j</var>)</li> <li>The given graph is connected.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var> <var>A_1</var> <var>B_1</var> <var>Y_1</var> <var>A_2</var> <var>B_2</var> <var>Y_2</var> <var>:</var> <var>A_M</var> <var>B_M</var> <var>Y_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the minimum number of edges that need to be removed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 2 3 5 7 1 2 7 1 3 9 2 3 12 3 4 18 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Assume that we removed Edge <var>3</var> and <var>4</var>. In this case, the connected component containing Edge <var>1</var> contains Vertex <var>1, 2</var> and <var>3</var>, and the sum of the weights of these vertices is <var>2+3+5=10</var>. The weight of Edge <var>1</var> is <var>7</var>, so the condition is satisfied for Edge <var>1</var>. Similarly, it can be seen that the condition is also satisfied for Edge <var>2</var>. Thus, a graph satisfying the condition can be obtained by removing two edges.</p> <p>The condition cannot be satisfied by removing one or less edges, so the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 10 4 4 1 1 1 7 3 5 19 2 5 20 4 5 8 1 6 16 2 3 9 3 6 16 3 4 1 2 6 20 2 4 19 1 2 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 9 81 16 73 7 2 61 86 38 90 28 6 8 725 3 10 12 1 4 558 4 9 615 5 6 942 8 9 918 2 7 720 4 7 292 7 10 414 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p03513
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> islands floating in Ringo Sea, and <var>M</var> travel agents operate ships between these islands. For convenience, we will call these islands Island <var>1,</var> <var>2,</var> <var>
,</var> <var>N,</var> and call these agents Agent <var>1,</var> <var>2,</var> <var>
,</var> <var>M</var>.</p> <p>The sea currents in Ringo Sea change significantly each day. Depending on the state of the sea on the day, Agent <var>i</var> <var>(1 ≀ i ≀ M)</var> operates ships from Island <var>a_i</var> to <var>b_i</var>, or Island <var>b_i</var> to <var>a_i</var>, but not both at the same time. Assume that the direction of the ships of each agent is independently selected with equal probability.</p> <p>Now, Takahashi is on Island <var>1</var>, and Hikuhashi is on Island <var>2</var>. Let <var>P</var> be the probability that Takahashi and Hikuhashi can travel to the same island in the day by ships operated by the <var>M</var> agents, ignoring the factors such as the travel time for ships. Then, <var>P × 2^M</var> is an integer. Find <var>P × 2^M</var> modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 15</var></li> <li><var>1 ≀ M ≀ N(N-1)/2</var></li> <li><var>1 ≀ a_i &lt; b_i ≀ N</var></li> <li>All pairs <var>(a_i, b_i)</var> are distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_M</var> <var>b_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the value <var>P × 2^M</var> modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 3 2 3 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <div style="text-align: center;"> <img alt="36cba65088d9b1224a6ce9665aa44048.png" src="https://img.atcoder.jp/relay2/36cba65088d9b1224a6ce9665aa44048.png"> </img></div> <p>The <var>2^M = 8</var> scenarios shown above occur with equal probability, and Takahashi and Hikuhashi can meet on the same island in <var>6</var> of them. Thus, <var>P = 6/2^M</var> and <var>P × 2^M = 6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 1 3 2 4 3 4 3 5 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>18 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 6 1 2 2 3 3 4 4 5 5 6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>64 </pre></section> </div> </span>
p03006
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> balls in a two-dimensional plane. The <var>i</var>-th ball is at coordinates <var>(x_i, y_i)</var>.</p> <p>We will collect all of these balls, by choosing two integers <var>p</var> and <var>q</var> such that <var>p \neq 0</var> or <var>q \neq 0</var> and then repeating the following operation:</p> <ul> <li>Choose a ball remaining in the plane and collect it. Let <var>(a, b)</var> be the coordinates of this ball. If we collected a ball at coordinates <var>(a - p, b - q)</var> in the previous operation, the cost of this operation is <var>0</var>. Otherwise, including when this is the first time to do this operation, the cost of this operation is <var>1</var>.</li> </ul> <p>Find the minimum total cost required to collect all the balls when we optimally choose <var>p</var> and <var>q</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>|x_i|, |y_i| \leq 10^9</var></li> <li>If <var>i \neq j</var>, <var>x_i \neq x_j</var> or <var>y_i \neq y_j</var>.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total cost required to collect all the balls.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>If we choose <var>p = 1, q = 1</var>, we can collect all the balls at a cost of <var>1</var> by collecting them in the order <var>(1, 1)</var>, <var>(2, 2)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 4 4 6 7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>If we choose <var>p = -3, q = -2</var>, we can collect all the balls at a cost of <var>1</var> by collecting them in the order <var>(7, 8)</var>, <var>(4, 6)</var>, <var>(1, 4)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 1 1 2 2 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre></section> </div> </span>
p03456
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer the deer has found two positive integers, <var>a</var> and <var>b</var>. Determine whether the concatenation of <var>a</var> and <var>b</var> in this order is a square number.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>a,b</var> <var>≀</var> <var>100</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 concatenation of <var>a</var> and <var>b</var> in this order is a square number, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 21 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>As <var>121</var> <var>=</var> <var>11</var> × <var>11</var>, it is a square number.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p><var>100100</var> is not a square number.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>12 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre></section> </div> </span>
p01191
<H1><font color="#000"></font>Grated Radish</H1> <!-- Problem B--> <p> Grated radish (daikon-oroshi) is one of the essential spices in Japanese cuisine. As the name shows, it’s made by grating white radish. </p> <p> You are developing an automated robot for grating radish. You have finally finished developing mechan- ical modules that grates radish according to given instructions from the microcomputer. So you need to develop the software in the microcomputer that controls the mechanical modules. As the first step, you have decided to write a program that simulates the given instructions and predicts the resulting shape of the radish. </p> <H2>Input</H2> <p> The input consists of a number of test cases. The first line on each case contains two floating numbers <i>R</i> and <i>L</i> (in centimeters), representing the radius and the length of the cylinder-shaped radish, respectively. The white radish is placed in the <i>xyz</i>-coordinate system in such a way that cylinder’s axis of rotational symmetry lies on the <i>z</i> axis. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gratedRadish"> <p>Figure 1: The placement of the white radish</p> </center> <p> The next line contains a single integer <i>N</i>, the number of instructions. The following <i>N</i> lines specify instructions given to the grating robot. Each instruction consists of two floating numbers <i>&theta;</i> and <i>V</i>, where <i>&theta;</i> is the angle of grating plane in degrees, and <i>V</i> (in cubic centimeters) is the volume of the grated part of the radish. </p> <p> You may assume the following conditions: </p> <ul> <li> the direction is measured from positive <i>x</i> axis (0 degree) to positive <i>y</i> axis (90 degrees),</li> <li> 1 &le; <i>R</i> &le; 5 (in centimeters),</li> <li> 1 &le; <i>L</i> &le; 40 (in centimeters),</li> <li> 0 &le; <i>&theta;</i> &lt; 360, and</li> <li> the sum of <i>V</i>’s is the smaller than the volume of the given white radish.</li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gratedRadish2"> <p>Figure 2: An example of grating</p> </center> <H2>Output</H2> <p> For each test case, print out in one line two numbers that indicate the shape of the base side (the side parallel to <i>xy</i>-plane) of the remaining radish after the entire grating procedure is finished, where the first number of the total length is the linear (straight) part and the second is the total length of the curved part. </p> <p> You may output an arbitrary number of digits after the decimal points, provided that difference from the true answer is smaller than 10<sup>-6</sup> centimeters. </p> <H2>Sample Input</H2> <pre> 2 1 2 1 42 3.141592653589793 5 20 3 0 307.09242465218927 180 307.09242465218927 90 728.30573874452591 </pre> <H2>Output for the Sample Input</H2> <pre> 2.0 3.141592653589793 8.660254038 5.235987756 </pre>
p02617
<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 and <var>N-1</var> edges, respectively numbered <var>1, 2,\cdots, N</var> and <var>1, 2, \cdots, N-1</var>. Edge <var>i</var> connects Vertex <var>u_i</var> and <var>v_i</var>.</p> <p>For integers <var>L, R</var> (<var>1 \leq L \leq R \leq N</var>), let us define a function <var>f(L, R)</var> as follows:</p> <ul> <li>Let <var>S</var> be the set of the vertices numbered <var>L</var> through <var>R</var>. <var>f(L, R)</var> represents the number of connected components in the subgraph formed only from the vertex set <var>S</var> and the edges whose endpoints both belong to <var>S</var>.</li> </ul> <p>Compute <var>\sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq u_i, v_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>u_1</var> <var>v_1</var> <var>u_2</var> <var>v_2</var> <var>:</var> <var>u_{N-1}</var> <var>v_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>\sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>We have six possible pairs <var>(L, R)</var> as follows:</p> <ul> <li>For <var>L = 1, R = 1</var>, <var>S = \{1\}</var> and we have <var>1</var> connected component.</li> <li>For <var>L = 1, R = 2</var>, <var>S = \{1, 2\}</var> and we have <var>2</var> connected components.</li> <li>For <var>L = 1, R = 3</var>, <var>S = \{1, 2, 3\}</var> and we have <var>1</var> connected component, since <var>S</var> contains both endpoints of each of the edges <var>1, 2</var>.</li> <li>For <var>L = 2, R = 2</var>, <var>S = \{2\}</var> and we have <var>1</var> connected component.</li> <li>For <var>L = 2, R = 3</var>, <var>S = \{2, 3\}</var> and we have <var>1</var> connected component, since <var>S</var> contains both endpoints of Edge <var>2</var>.</li> <li>For <var>L = 3, R = 3</var>, <var>S = \{3\}</var> and we have <var>1</var> connected component.</li> </ul> <p>The sum of these is <var>7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 5 3 5 7 8 9 1 9 9 10 8 4 7 4 6 10 7 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>113 </pre></section> </div> </span>
p01938
<h2>A A-Z-</h2> <h3>問題</h3> <p><var>26</var> マスの円環状のボヌドがあり、各マスには倧文字のアルファベット <var>1</var> 文字が、アルファベット順に時蚈回りに曞かれおいたす。すなわち、 'A' のマスの時蚈回り隣は 'B' のマスで、 'B' のマスの隣は 'C' のマスで、・・・、 'Z' のマスの時蚈回り隣は 'A' のマスです。</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-a-01" type="image/png" width="300"></img> <p>たた、ボヌドには 'A' のマスに駒が <var>1</var> ぀眮かれおいたす。</p> <p> あなたは、文字列 <var>S</var> を受け取り、 <var>S</var> の先頭から <var>1</var> 文字ず぀芋お駒を操䜜したす。 <var>i</var> 回目の操䜜は以䞋のようになりたす。 </p> <ul> <li>その時点で駒のあるマスから <var>S</var> の <var>i</var> 文字目のアルファベットのマスを目指しお、駒を時蚈回りに <var>1</var> マスず぀移動させる。このずき少なくずも <var>1</var> マスは移動するずする。したがっお、䟋えば 'A' のマスから 'A' のマスに移動する際は、ボヌドを <var>1</var> 呚しなくおはならない。</li> </ul> <p>䞊蚘の操䜜の結果、駒が 'A' のマスを䜕回螏んだかを答えおください。なお「 'A' のマスを螏む」ずは、 'Z' のマスから 'A' のマスに駒を進めるこずを蚀いたす。</p> <h3>入力圢匏</h3> <p>入力は <var>1</var> 行で䞎えられる。</p> <pre><var>S</var></pre> <p><var>S</var> はあなたが受け取る文字列を衚す。</p> <h3>制玄</h3> <ul> <li> <var>1 \leq |S| \leq 100</var></li> <li> <var>S</var> は英倧文字のみで構成される。</li> </ul> <h3>出力圢匏</h3> <p>'A' のマスを䜕回螏んだかを <var>1</var> 行で出力せよ。</p> <h3>入力䟋1</h3> <pre>AIZU</pre> <h3>出力䟋1</h3> <pre>2</pre> <ul> <li>A -&gt; A (ここで 1 回)</li> <li>A -&gt; I (ここたで 1 回)</li> <li>I -&gt; Z (ここたで 1 回)</li> <li>Z -&gt; U (ここたで 2 回)</li> </ul> <h3>入力䟋2</h3> <pre>HOKKAIDO</pre> <h3>出力䟋2</h3> <pre>4</pre>
p03905
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an undirected connected graph with <var>N</var> vertices numbered <var>1</var> through <var>N</var>. The lengths of all edges in this graph are <var>1</var>. It is known that for each <var>i (1≩i≩N)</var>, the distance between vertex <var>1</var> and vertex <var>i</var> is <var>A_i</var>, and the distance between vertex <var>2</var> and vertex <var>i</var> is <var>B_i</var>. Determine whether there exists such a graph. If it exists, find the minimum possible number of edges in it.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≩N≩10^5</var></li> <li><var>0≩A_i,B_i≩N-1</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a graph satisfying the conditions, print the minimum possible number of edges in such a graph. Otherwise, print <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 0 1 1 0 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The figure below shows two possible graphs. The graph on the right has fewer edges.</p> <p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/dd1e04d837fd7fc1be56b231cd8c2a17.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 1 1 0 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>Such a graph does not exist.</p></section> </div> </span>
p02247
<H1>Naive String Search</H1> <p> Find places where a string <var>P</var> is found within a text <var>T</var>. Print all indices of <var>T</var> where <var>P</var> found. The indices of <var>T</var> start with 0. </p> <H2>Input</H2> <p> In the first line, a text <var>T</var> is given. In the second line, a string <var>P</var> is given. </p> <H2>output</H2> <p> Print an index of <var>T</var> where <var>P</var> found in a line. Print the indices in ascending order. </p> <H2>Constraints</H2> <ul> <li> 1 &le; length of <var>T</var> &le; 1000 </li> <li> 1 &le; length of <var>P</var> &le; 1000 </li> <li>The input consists of alphabetical characters and digits</li> </ul> <H2>Sample Input 1</H2> <pre> aabaaa aa </pre> <H2>Sample Output 1</H2> <pre> 0 3 4 </pre> <H2>Sample Input 2</H2> <pre> xyzz yz </pre> <H2>Sample Output 2</H2> <pre> 1 </pre> <H2>Sample Input 3</H2> <pre> abc xyz </pre> <H2>Sample Output3</H2> <pre> </pre> <p> The ouput should be empty. </p>
p00780
<H1><font color="#000">Problem A:</font>Goldbach's Conjecture</H1> <p> <b>Goldbach's Conjecture:</b> For any even number <i>n</i> greater than or equal to 4, there exists at least one pair of prime numbers <i>p</i><sub>1</sub> and <i>p</i><sub>2</sub> such that <i>n</i> = <i>p</i><sub>1</sub> + <i>p</i><sub>2</sub>. </p> <p> This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of all the pairs of prime numbers satisfying the condition in the conjecture for a given even number. </p> <p> A sequence of even numbers is given as input. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are intereseted in the number of essentially different pairs and therefore you should not count (<i>p</i><sub>1</sub>, <i>p</i><sub>2</sub>) and (<i>p</i><sub>2</sub>, <i>p</i><sub>1</sub>) separately as two different pairs. </p> <H2>Input</H2> <p> An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 2<sup>15</sup>. The end of the input is indicated by a number 0. </p> <H2>Output</H2> <p> Each output line should contain an integer number. No other characters should appear in the output. </p> <H2>Sample Input</H2> <pre> 6 10 12 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 1 </pre>
p01892
<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>B: むカったヌ / SNS</h1> <h2>問題文</h2> <p> AOR むカちゃんは最近少し機嫌が悪い。 どうやら、”むカったヌ”のフォロヌ数ずフォロワヌ数の比が気に入らないようだ 。珟圚、AOR むカちゃんのフォロヌ数は $A$ 人、フォロワヌ数は $B$ 人であり、比は $A:B$ である。 </p> <p> そこで、AOR むカちゃんはフォロヌ数ずフォロワヌ数の比が気に入った敎数比になるように、<b><u>フォロヌ数</u></b>を増枛させるこずにした。 なお気に入った敎数比ずは、比に含たれるどちらの倀も $1$ 以䞊 $N$ 以䞋の敎数ずなるように衚せる比である。 </p> <p> しかし、AOR むカちゃんはできるだけフォロヌ数を倉曎したくないので、倉曎前ずの差の絶察倀をできるだけ小さくしたい。 AOR むカちゃんの機嫌を良くするために、少なくずもフォロヌ数をいく぀倉曎する必芁があるかを求めるプログラムを䜜成せよ。 </p> <h2>入力</h2> <p> $A \ B \ N$<br> </p> <h2>入力の制玄</h2> <p> $1 \le A, \ B \le 10^{12}$<br> $1 \leq N \leq 100 $<br> </p> <h2>出力</h2> <p> 気に入った敎数比にできる、$A$ の倉化量の絶察倀の最小倀を出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力1</h3> <pre> 19 30 3 </pre> <h3>サンプル出力1</h3> <pre> 1 </pre> <h3>サンプル入力2</h3> <pre> 3 7 7 </pre> <h3>サンプル出力2</h3> <pre> 0 </pre> <h3>サンプル入力3</h3> <pre> 3 7 1 </pre> <h3>サンプル出力3</h3> <pre> 4 </pre> <h3>サンプル入力4</h3> <pre> 102 30 3 </pre> <h3>サンプル出力4</h3> <pre> 12 </pre> <p> フォロヌを $12$ 人枛らすこずで $90:30 \ (=3:1)$ になり、比の倧きい方の数字が $3$ 以䞋ずなりたす。<br> このずき、倉化量は $12$ です。 </p> <h3>サンプル入力5</h3> <pre> 3 4 2 </pre> <h3>サンプル出力5</h3> <pre> 1 </pre> <p> 䞀人フォロヌを倖すず $2:4 \ (=1:2)$ に、フォロヌするず $4:4 \ (=1:1)$ になり、どちらも増枛の絶察倀は $1$ でそれが答えです。 </p> <h3>サンプル入力6</h3> <pre> 1 100 2 </pre> <h3>サンプル出力6</h3> <pre> 49 </pre> <p> 最䜎でも $1$ 人はフォロヌしおいなければいけない事に泚意しおください。 </p>
p00515
<H1>問題 1: 平均点 (Average Score) </H1> <br/> <h2>問題</h2> <p> JOI 高校の授業には倪郎君次郎君䞉郎君四郎君花子さんの 5 人の生埒が参加した </p> <p> この授業では期末詊隓を実斜した期末詊隓は5 人党員が受隓した期末詊隓の点数が 40 点以䞊の生埒は期末詊隓の点数がそのたた成瞟になった期末詊隓の点数が 40 点未満の生埒は党員補習を受け成瞟が 40 点になった </p> <p> 5 人の生埒の期末詊隓の点数が䞎えられたずき5 人の成瞟の平均点を蚈算するプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は 5 行からなり1 行に 1 ぀ず぀敎数が曞かれおいる <br> 1 行目には 倪郎君の期末詊隓の点数が曞かれおいる <br> 2 行目には 次郎君の期末詊隓の点数が曞かれおいる <br> 3 行目には 䞉郎君の期末詊隓の点数が曞かれおいる <br> 4 行目には 四郎君の期末詊隓の点数が曞かれおいる <br> 5 行目には 花子さんの期末詊隓の点数が曞かれおいる <br> </p> <p> 生埒の期末詊隓の点数はすべお 0 点以䞊 100 点以䞋の敎数である <br> 生埒の期末詊隓の点数はすべお 5 の倍数である <br> 5 人の生埒の成瞟の平均点は必ず敎数になる </p> <h2> 出力</h2> <p> 5 人の生埒の成瞟の平均点をあらわす敎数を 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 10 65 100 30 95 </pre> <h3>出力䟋 1</h3> <pre> 68 </pre> <p> 入出力䟋 1 では倪郎君ず四郎君の期末詊隓の点数は 40 点未満なので倪郎君ず四郎君の成瞟は 40 点になる次郎君ず䞉郎君ず花子さんの期末詊隓の点数は 40 点以䞊なので次郎君の成瞟は 65 点䞉郎君の成瞟は 100 点花子さんの成瞟は 95 点ずなる5 人の成瞟の合蚈は 340 なので平均点は 68 点ずなる </p> <h3>入力䟋 2</h3> <pre> 40 95 0 95 50 </pre> <h3>出力䟋 2</h3> <pre> 64 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02178
<h1>D: Walking</h1> <h2>問題</h2> <p> $1$ から $N$ の番号が぀けられおいる $N$ 個の島がある.<br> それぞれの島は $N-1$ 個の橋によっお、どの $2$ ぀の島も䜕本かの橋を枡っお互いに移動するこずができる.<br> それぞれの橋には耐久床があり、入力が䞎えられた時点での $i$ 番目の橋の耐久床は $w_i$ である.<br> それぞれの島にはお宝が $1$ ぀ず぀眮いおおり、島に滞圚しおいるずきにお宝を拟うこずができる. </p> <p> 珟圚島 $S$ にいるyebiくんは、島 $E$ にある博物通に党おのお宝を運びたい.<br> yebiくんは✝魔力✝を持っおいるので、島 $v$ に蚪問するたびに、 $v$ から出る党おの橋の耐久床が $T$ 枛少する.<br> 橋の耐久床が $0$ 以䞋になったずき、橋は厩壊し、それ以降には枡るこずができなくなる.<br> yebiくんは博物通に党おのお宝を届けるこずができるか<br> ただし、yebiくんは力持ちなので同時にいく぀でもお宝を持ち運ぶこずができる.<br> </p> <h2>制玄</h2> <ul> <li>入力倀は党お敎数である</li> <li>$2 \leq N \leq 10^5$</li> <li>$1 \leq S, E \leq N$</li> <li>$0 \leq T \leq 10^9$</li> <li>$1 \leq w_i \leq 10^9$</li> <li>$1 \leq a_i, b_i \leq N$</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる </p> <p> $N\ T\ S\ E$<br> $a_1\ b_1\ w_1$<br> :<br> :<br> $a_{N-1}\ b_{N-1}\ w_{N-1}$ </p> <h2>出力</h2> <p> 博物通に党おのお宝を届けるこずができるなら "Yes"、そうでなければ "No" を出力せよ.<br> たた、末尟に改行を出力せよ.<br> </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 4 10 1 4 1 2 52 1 3 68 3 4 45 </pre> <h3>サンプル出力 1</h3> <pre> Yes </pre> <h3>サンプル入力 2</h3> <pre> 4 10 1 4 1 2 15 1 3 60 3 4 10 </pre> <h3>サンプル出力 2</h3> <pre> No </pre> <h3>サンプル入力 3</h3> <pre> 3 0 1 3 1 2 5 2 3 5 </pre> <h3>サンプル出力 3</h3> <pre> Yes </pre> <P> yebiくんの魔力は貧匱すぎお、橋の耐久床を枛らすこずはできない. </P>
p00145
<H1>カヌド</H1> <p> 正の敎数が曞かれた䞀組のカヌドがありたす。カヌドを積んで山をいく぀か䜜り、それらを暪䞀列に䞊べたす。その䞭から隣り合った 2 ぀のカヌドの山を遞び、右偎の山の䞊に巊偎の山をそのたた重ねたす。この操䜜をカヌドの山が䞀぀になるたで繰り返しおいきたす。 </p> <p> 2 ぀のカヌドの山を重ねる時にそれらの䞀番䞊ず䞋のカヌドに曞かれた数をすべお掛け合わせたす。こうしお埗られた数をカヌドの重ね合わせのコストず呌ぶこずにしたす。カヌドの山を䞀぀にするためのコストはすべおの重ね合わせのコストを足し合わせたものずしたす。 </p> <p> どのような順番でカヌドの山を重ねるかでコストは倉わりたす。たずえば、3 ぀のカヌドの山がある堎合を考えたす。それらの䞀番䞊ず䞋のカヌドに曞かれた数が巊偎の山から順にそれぞれ 3 ず 5, 2 ず 8, 5 ず4 だったずしたす。このずきはじめに巊ず真ん䞭の山を重ねたずきのコストは、3 × 5 × 2 × 8 = 240 です。この重ね合わせによっお、䞀番䞊のカヌドが 3 で䞀番䞋のカヌドが 8 である山ができたす。 </p> <p> この山を右の山の䞊に重ねるず、そのコストは 3 × 8 × 5 × 4 = 480 になりたす。したがっお、この順番でカヌドの山を䞀぀にたずめたずきのコストは 240 + 480 = 720 です。図1 </p> <p> 䞀方、はじめに真ん䞭ず右の山を重ねおから最埌に巊の山を重ねるこずにするず、そのずきのコストは 2 × 8 × 5 × 4 + 3 × 5 × 2 × 4 = 440 になりたす。したがっお埌の堎合のように重ねた方がコストが小さくなりたす。図2 </p> <center> <table border=0> <tr> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cards1"></td> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cards2"></td> </tr> </table> </center> <br/> <p> カヌドの山の個数ずそれぞれの山の䞀番䞊ず䞋のカヌドに曞かれた数を入力ずし、カヌドの山を䞀぀にたずめるのに必芁な最小のコストを出力するプログラムを䜜成しおください。ただし、山の個数は 100 個以䞋ずし、入力されるデヌタはどのような順番でコストを蚈算しおも 2<sup>31</sup>-1 を超えるこずはありたせん。 </p> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> : <var>a<sub>n</sub></var> <var>b<sub>n</sub></var> </pre> <p> 1 行目にカヌドの山の個数 <var>n</var>(<var>n</var> &le; 100)、続く <var>n</var> 行に巊から <var>i</var> 番目の山の 1 番䞊のカヌドに曞かれた数 <var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; 200) ず 1 番䞋のカヌドに曞かれた数 <var>b<sub>i</sub></var> (1 &le; <var>b<sub>i</sub></var> &le; 200) が䞎えられたす。 </p> <H2>Output</H2> <p> カヌドの山を䞀぀にたずめるのに必芁な最小のコストを行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 3 3 5 2 8 5 4 </pre> <H2>Output for the Sample Input</H2> <pre> 440 </pre>
p01304
<h1><font color="#000">Problem B:</font> 平安京りォヌキング</h1> <p> 平安京は、道が栌子状になっおいる町ずしお知られおいる。 </p> <p> 平安京に䜏んでいるねこのホクサむは、パトロヌルのために毎日自宅から町はずれの秘密の堎所たで行かなければならない。しかし、毎日同じ道を通るのは飜きるし、埌を付けられる危険もあるので、ホクサむはできるだけ毎日異なる経路を䜿いたい。その䞀方で、ホクサむは面倒臭がりなので、目的地から遠ざかるような道は通りたくない。 </p> <p> 平安京のあちこちの道にはマタタビが萜ちおいお、ホクサむはマタタビが萜ちおいる道を通るこずができない。そのような道を通るずめろめろになっおしたうからである。幞いなこずに、亀差点にはマタタビは萜ちおいない。 </p> <p> ホクサむは、自宅から秘密の堎所たでの可胜な経路の数を知りたい。ここで、ホクサむの自宅は (0, 0) にあり、秘密の堎所は(<var>g</var><sub><var>x</var></sub>, <var>g</var><sub><var>y</var></sub>)にある。道は <var>x</var> = <var>i</var> (<var>i</var> は敎数), <var>y</var> = <var>j</var> (<var>j</var> は敎数) に栌子状に敷かれおいる。 </p> <h2>Input</h2> <p> 入力の1行目には、秘密の堎所の座暙 (<var>g</var><sub><var>x</var></sub>, <var>g</var><sub><var>y</var></sub>) が䞎えられる。これらはいずれも1以䞊15以䞋の敎数で、空癜1個で区切られお䞎えられる。 2行目にはマタタビが萜ちおいる区間の数 <var>p</var> (0 &le; <var>p</var> &le; 100) が䞎えられ、続く<var>p</var>行にはマタタビが萜ちおいる区間が1行に1区間ず぀䞎えられる。 <var>p</var>個の区間は互いに異なる。 1区間は <var>x</var><sub>1</sub> <var>y</var><sub>1</sub> <var>x</var><sub>2</sub> <var>y</var><sub>2</sub> の圢で衚され、(<var>x</var><sub>1</sub>, <var>y</var><sub>1</sub>) ず (<var>x</var><sub>2</sub>, <var>y</var><sub>2</sub>) を端点ずする、<var>x</var>軞たたは<var>y</var>軞に平行な長さ1の線分である。 <var>x</var><sub>1</sub>, <var>x</var><sub>2</sub> は [0, <var>g</var><sub><var>x</var></sub>] の範囲にあり、<var>y</var><sub>1</sub>, <var>y</var><sub>2</sub> は [0, <var>g</var><sub><var>y</var></sub>] の範囲にある。 </p> <h2>Output</h2> <p> 可胜な経路の数を出力せよ。可胜な経路が1぀もない堎合は "Miserable Hokusai!" ず1行に出力せよ。 </p> <h2>Notes on Submission</h2> <p> 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 </p> <h2>Sample Input</h2> <pre> 4 2 2 0 1 1 2 0 0 0 1 0 0 1 0 4 3 4 1 0 0 0 3 3 4 3 4 1 4 0 0 2 0 3 15 15 0 </pre> <h2>Output for the Sample Input</h2> <pre> 6 Miserable Hokusai! 5 155117520 </pre> <hr>
p03339
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string <var>S</var> of length <var>N</var>. The <var>i</var>-th person from the west is facing east if <var>S_i =</var> <code>E</code>, and west if <var>S_i =</var> <code>W</code>.</p> <p>You will appoint one of the <var>N</var> people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.</p> <p>The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 3 \times 10^5</var></li> <li><var>|S| = N</var></li> <li><var>S_i</var> is <code>E</code> or <code>W</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of people who have to change their directions.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 WEEWW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Assume that we appoint the third person from the west as the leader. Then, the first person from the west needs to face east and has to turn around. The other people do not need to change their directions, so the number of people who have to change their directions is <var>1</var> in this case. It is not possible to have <var>0</var> people who have to change their directions, so the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>12 WEWEWEEEWWWE </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 WWWWWEEE </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p03293
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given string <var>S</var> and <var>T</var> consisting of lowercase English letters.</p> <p>Determine if <var>S</var> equals <var>T</var> after <em>rotation</em>.</p> <p>That is, determine if <var>S</var> equals <var>T</var> after the following operation is performed some number of times:</p> <p>Operation: Let <var>S = S_1 S_2 ... S_{|S|}</var>. Change <var>S</var> to <var>S_{|S|} S_1 S_2 ... S_{|S|-1}</var>.</p> <p>Here, <var>|X|</var> denotes the length of the string <var>X</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq |S| \leq 100</var></li> <li><var>|S| = |T|</var></li> <li><var>S</var> and <var>T</var> consist of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>S</var> equals <var>T</var> after <em>rotation</em>, print <code>Yes</code>; if it does not, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>kyoto tokyo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <ul> <li>In the first operation, <code>kyoto</code> becomes <code>okyot</code>.</li> <li>In the second operation, <code>okyot</code> becomes <code>tokyo</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>abc arc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p><code>abc</code> does not equal <code>arc</code> after any number of operations.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>aaaaaaaaaaaaaaab aaaaaaaaaaaaaaab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
p01754
<p> 2014 幎春ある孊生は無事倧孊に合栌し䞀人暮らしを始める事ずなったここで問題ずなるのが倕食をどうするかである圌はこれから <var>N</var> 日間の倕食の蚈画を立おる事にした </p> <p> 圌は <var>N</var> 日間で埗られる幞犏床の合蚈を出来る限り倧きくしたいもちろん矎味しいものや奜きなものを食べるほど幞犏床は高い </p> <p> 圌の倕食の遞択肢は2 ぀近くの食堂に向かうか自炊をするかのどちらかである </p> <p> 食堂で埗られる幞犏床はその日のメニュヌによっお倉わるメニュヌは日替わりだが毎日䞀皮類のみで<var>N</var> 日間のメニュヌは党お既に公開されおいるなので圌は <var>i</var> 日目 (1 &le; <var>i</var> &le; <var>N</var>) に食堂に行けば <var>C<sub>i</sub></var> の幞犏床を埗られるずいう情報を党お知っおいる </p> <p> 自炊で埗られる幞犏床はその自炊の開始時点での<b>自炊パワヌ</b>に定数 <var>P</var> を掛けたものである<b>自炊パワヌ</b>は初期倀が <var>Q</var> であり毎日食堂に行けば-1自炊をすれば+1その日の食事の終了時に倉動する </p> <p> 圌のために幞犏床の総和の最倧倀を求めよう </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で <var>N + 1</var> 行で䞎えられる </p> <pre> <var>N</var> <var>P</var> <var>Q</var> <var>C<sub>1</sub></var> <var>C<sub>2</sub></var> : <var>C<sub>N</sub></var> </pre> <ul> <li> 1 行目は 3 ぀の敎数 <var>N, P, Q</var> が䞎えられそれぞれ日数自炊の幞犏床を算出するための定数自炊パワヌの初期倀である</li> <li> 2 行目から <var>N + 1</var> 行目にはそれぞれ敎数が 1 ぀ず぀䞎えられ<var>i + 1</var> 行目では <var>i</var> 日目に食堂に行った時に埗られる幞犏床が䞎えられる </li> </ul> <h2>Constraints</h2> <ul> <li> 1 &le; <var>N</var> &le; 500,000 </li> <li> 0 &le; <var>P</var> &le; 500,000</li> <li> <var>|Q|</var> &le; 500,000</li> <li> <var>|C<sub>i</sub>|</var> &le; 500,000</li> </ul> <h2>Output</h2> <p> 幞犏床の取りうる最倧倀を䞀行に出力せよ </p> <h2>Sample Input 1</h2> <pre> 1 1 1 2 </pre> <h2>Output for the Sample Input 1</h2> <pre> 2 </pre> <ul> <li> 考えるべき予定は1 日だけである食堂に行けば2自炊するず1 の幞犏床なので答えは2 ずなる</li> </ul> <h2>Sample Input 2</h2> <pre> 3 2 1 3 3 3 </pre> <h2>Output for the Sample Input 2</h2> <pre> 12 </pre> <ul> <li>このケヌスでは毎日自炊をするのが最適で幞犏床は <var>2 &times; 1 + 2 &times; 2 + 2 &times; 3 = 12</var> ずなる </li> </ul> <h2>Sample Input 3</h2> <pre> 3 1 -1 2 -3 2 </pre> <h2>Output for the Sample Input 3</h2> <pre> 2 </pre> <ul> <li> 2 日目のみで自炊をするこずが最善ずなる</li> </ul> <h2>Sample Input 4</h2> <pre> 3 1 -10 -10 -10 -10 </pre> <h2>Output for the Sample Input 4</h2> <pre> -27 </pre> <ul> <li> 答えが負になるこずもあるいくらたずくおも倕食は食べなければならない</li> </ul>
p03769
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will call a string <var>x</var> <em>good</em> if it satisfies the following condition:</p> <ul> <li>Condition: <var>x</var> can be represented as a concatenation of two copies of another string <var>y</var> of length at least <var>1</var>.</li> </ul> <p>For example, <code>aa</code> and <code>bubobubo</code> are good; an empty string, <code>a</code>, <code>abcabcabc</code> and <code>abba</code> are not good.</p> <p>Eagle and Owl created a puzzle on good strings. Find one string <var>s</var> that satisfies the following conditions. It can be proved that such a string always exists under the constraints in this problem.</p> <ul> <li><var>1 ≀ |s| ≀ 200</var></li> <li>Each character of <var>s</var> is one of the <var>100</var> characters represented by the integers <var>1</var> through <var>100</var>.</li> <li>Among the <var>2^{|s|}</var> subsequences of <var>s</var>, exactly <var>N</var> are good strings.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^{12}</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>In the first line, print <var>|s|</var>, the length of <var>s</var>. In the second line, print the elements in <var>s</var> in order, with spaces in between. Any string that satisfies the above conditions will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 1 1 1 1 </pre> <p>There are two good strings that appear as subsequences of <var>s</var>: <var>(1,1)</var> and <var>(1,1,1,1)</var>. There are six occurrences of <var>(1,1)</var> and one occurrence of <var>(1,1,1,1)</var>, for a total of seven.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>299 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>23 32 11 11 73 45 8 11 83 83 8 45 32 32 10 100 73 32 83 45 73 32 11 10 </pre></section> </div> </span>
p00846
<H1><font color="#000">Problem B:</font> How I Mathematician Wonder What You Are!</H1> <p> After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician, uses a big astronomical telescope and lets his image processing program count stars. The hardest part of the program is to judge if a shining object in the sky is really a star. As a mathematician, the only way he knows is to apply a mathematical definition of <i>stars</i>. </p> <p> The mathematical defiition of a star shape is as follows: A planar shape <i>F</i> is <i>star-shaped</i> if and only if there is a point C &isin; <i>F</i> such that, for any point P &isin; <i>F</i>, the line segment CP is contained in <i>F</i>. Such a point C is called a center of <i>F</i>. To get accustomed to the definition, let's see some examples below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_howIMath"> <p> Figure 2: Star shapes (the first row) and non-star shapes (the second row) </p> </center> <p> The firrst two are what you would normally call stars. According to the above definition, however, all shapes in the first row are star-shaped. The two in the second row are not. For each star shape, a center is indicated with a dot. Note that a star shape in general has infinitely many centers. For example, for the third quadrangular shape, all points in it are centers. </p> <p> Your job is to write a program that tells whether a given polygonal shape is star-shaped or not. </p> <H2>Input</H2> <p> The input is a sequence of datasets followed by a line containing a single zero. Each dataset specifies a polygon, and is formatted as follows. </p> <pre> <i>n</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> ... <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> </pre> <p> The first line is the number of vertices, <i>n</i>, which satisfies 4 &le; <i>n</i> &le; 50. Subsequent <i>n</i> lines are the <i>x</i>- and <i>y</i>-coordinates of the <i>n</i> vertices. They are integers and satisfy 0 &le; <i>x<sub>i</sub></i> &le; 10000 and 0 &le; <i>y<sub>i</sub></i> &le; 10000 (<i>i</i> = 1, ..., <i>n</i>). Line segments (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>)-(<i>x</i><sub><i>i</i>+1</sub>, <i>y</i><sub><i>i</i>+1</sub>) (<i>i</i> = 1, ..., <i>n</i> - 1) and the line segment (<i>x<sub>n</sub></i>, <i>y<sub>n</sub></i>)-(<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) form the border of the polygon in the counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. </p> <p> You may assume that the polygon is <i>simple</i>, that is, its border never crosses or touches itself. You may also assume that no three edges of the polygon meet at a single point even when they are infinitely extended. </p> <H2>Output</H2> <p> For each dataset, output "1" if the polygon is star-shaped and "0" otherwise. Each number must be in a separate line and the line should not contain any other characters. </p> <H2>Sample Input</H2> <pre> 6 66 13 96 61 76 98 13 94 4 0 45 68 8 27 21 55 14 93 12 56 95 15 48 38 46 51 65 64 31 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 0 </pre>
p01241
<H1><font color="#000">Problem H:</font> Finding the Top RPS Player</H1> <p> A company “ACM Foods” is preparing for opening its chain shop in a certain area, but another company “ICPC Pizza” is also planning to set up its branch shop in the same area. In general, two competitive shops gain less incomes if they are located so close to each other. Thus, if both “ACM Foods” and “ICPC Pizza” went on opening, they would be damaged financially. So, they had a discussion on this matter and made the following agreement: only one of them can branch its shop in the area. It is determined by Rock-Paper-Scissors (RPS) which to branch the shop. </p> <p> ACM Foods is facing financial difficulties and strongly desires to open their new shop in that area. The executives have decided to make every effort for finding out a very strong RPS player. They believes that players who win consecutive victories must be strong players. In order to find such a player for sure, they have decided their simple strategy. </p> <p> In this strategy, many players play games of RPS repeatedly, but the games are only played between players with the same number of consecutive wins. At the beginning, all the players have no wins, so any pair of players can play a game. The games can be played by an arbitrary number of pairs simultaneously. Let us call a set of simultaneous games as a <i>turn</i>. After the first turn, some players will have one win, and the other players will remain with no wins. In the second turn, some games will be played among players with one win, and some other games among players with no wins. For the former games, the winners will have two <i>consecutive</i> wins, and the losers will lose their first wins and have no consecutive wins. For the latter games, the winners will have one win, and the losers will remain with no wins. Therefore, after the second turn, the players will be divided into three groups: players with two consecutive wins, players with one win, and players with no wins. Again, in the third turn, games will be played among players with two wins, among with one win, and among with no wins. The following turns will be conducted so forth. After a sufficient number of turns, there should be a player with the desired number of consecutive wins. </p> <p> The strategy looks crazy? Oh well, maybe they are confused because of their financial difficulties. </p> <p> Of course, this strategy requires an enormous amount of plays. The executives asked you, as an employee of ACM Foods, to estimate how long the strategy takes. Your task is to write a program to count the minimum number of turns required to find a player with <i>M</i> consecutive wins among <i>N</i> players. </p> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case consists of two integers <i>N</i> (2 &le; <i>N</i> &le; 20) and <i>M</i> (1 &le; <i>M</i> &lt; <i>N</i>) in one line. </p> <p> The input is terminated by the line containing two zeroes. </p> <H2>Output</H2> <p> For each test case, your program must output the case number followed by one integer which indicates the minimum number of turns required to find a person with <i>M</i> consecutive wins. </p> <H2>Sample Input</H2> <pre> 2 1 10 5 15 10 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 1 Case 2: 11 Case 3: 210 </pre>
p03786
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke found <var>N</var> strange creatures. Each creature has a fixed color and size. The color and size of the <var>i</var>-th creature are represented by <var>i</var> and <var>A_i</var>, respectively.</p> <p>Every creature can absorb another creature whose size is at most twice the size of itself. When a creature of size <var>A</var> and color <var>B</var> absorbs another creature of size <var>C</var> and color <var>D</var> (<var>C \leq 2 \times A</var>), they will merge into one creature of size <var>A+C</var> and color <var>B</var>. Here, depending on the sizes of two creatures, it is possible that both of them can absorb the other.</p> <p>Snuke has been watching these creatures merge over and over and ultimately become one creature. Find the number of the possible colors of this creature.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100000</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>A_i</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> 
 <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the possible colors of the last remaining creature after the <var>N</var> creatures repeatedly merge and ultimately become one creature.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The possible colors of the last remaining creature are colors <var>1</var> and <var>3</var>. For example, when the creature of color <var>3</var> absorbs the creature of color <var>2</var>, then the creature of color <var>1</var> absorbs the creature of color <var>3</var>, the color of the last remaining creature will be color <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>There may be multiple creatures of the same size.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 40 1 30 2 7 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p04043
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Iroha loves <em>Haiku</em>. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with <var>5</var>, <var>7</var> and <var>5</var> syllables, in this order.</p> <p>To create a Haiku, Iroha has come up with three different phrases. These phrases have <var>A</var>, <var>B</var> and <var>C</var> syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩A,B,C≩10</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>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to construct a Haiku by using each of the phrases once, print <code>YES</code> (case-sensitive). Otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>Using three phrases of length <var>5</var>, <var>5</var> and <var>7</var>, it is possible to construct a Haiku.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 7 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre></section> </div> </span>
p02894
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are <var>N</var> points on the circumference of a circle centered at <var>(0,0)</var> in an <var>xy</var>-plane. The coordinates of the <var>i</var>-th point are <var>(\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L}))</var>.</p> <p>Three distinct points will be chosen uniformly at random from these <var>N</var> points. Find the expected <var>x</var>- and <var>y</var>-coordinates of the center of the circle inscribed in the triangle formed by the chosen points.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 3000</var></li> <li><var>N \leq L \leq 10^9</var></li> <li><var>0 \leq T_i \leq L-1</var></li> <li><var>T_i&lt;T_{i+1}</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>L</var> <var>T_1</var> <var>:</var> <var>T_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the expected <var>x</var>- and <var>y</var>-coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 0 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0.414213562373095 -0.000000000000000 </pre> <p>The three points have the coordinates <var>(1,0)</var>, <var>(0,1)</var>, and <var>(0,-1)</var>. The center of the circle inscribed in the triangle formed by these points is <var>(\sqrt{2}-1,0)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 8 1 3 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-0.229401949926902 -0.153281482438188 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 100 2 11 35 42 54 69 89 91 93 99 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0.352886583546338 -0.109065017701873 </pre></section> </div> </span>
p01611
<h2>K-th String</h2> <h2>Problem Statement</h2> <p>長さ<var>N</var>の文字列<var>S</var>に察する接尟蟞配列<var>SA</var>を以䞋の手順で埗られる<var>N</var>以䞋の正敎数の順列ずしお定矩する<br /> <var>S</var>の<var>i</var>文字目から<var>j</var>文字目たでの郚分文字列を<var>S[i..j]</var>ず衚すただし添字は1-indexedである</p> <ol class="list1" style="padding-left:16px;margin-left:16px"><li>各接尟蟞<var>S[i..N] (i=1,2,...,N)</var>を蟞曞匏順序昇順で敎列する</li> <li>敎列した各接尟蟞の開始䜍眮<var>i</var>を順に䞊べる</li></ol> <p>たずえば<var>S</var>=&quot;mississippi&quot;の接尟蟞配列<var>SA</var>は以䞋のようになる</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_K_mississippi"> <br/> <br/> <!-- <pre> i | S[i] | SA[i] | S[SA[i]..N-1] ----+------+-------+----------------- 1 | m | 11 | i 2 | i | 8 | ippi 3 | s | 5 | issippi 4 | s | 2 | ississippi 5 | i | 1 | mississippi 6 | s | 10 | pi 7 | s | 9 | ppi 8 | i | 7 | sippi 9 | p | 4 | sissippi 10 | p | 6 | ssippi 11 | i | 3 | ssissippi</pre> --> <p>入力ずしお長さ<var>N</var>の文字列に察する接尟蟞配列<var>SA</var>が䞎えられる<br /> <var>SA</var>が埗られるような文字列のうち蟞曞匏順序で<var>K</var>番目(1-indexed)のものを求めよ<br /> ただし元の文字列はアルファベット順に'a'から数えお高々<var>A</var>個の文字のみからなる</p> <h2>Input</h2> <p>入力は以䞋の圢匏に埓う䞎えられる数は党お敎数である</p> <pre><var>N</var> <var>A</var> <var>K</var> <var>SA_1</var> <var>SA_2</var> ... <var>SA_N</var></pre> <h2>Constraints</h2> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1≩N≩10^5</var></li> <li><var>1≩A≩26</var></li> <li><var>1≩K≩10^{18}</var></li> <li><var>1≩SA_i≩N</var></li> <li><var>i \neq j</var> ならば <var>SA_i \neq SA_j</var></li></ul> <h2>Output</h2> <p><var>SA</var>が埗られるような蟞曞匏順序で<var>K</var>番目の文字列を1行に出力せよ<br /> <var>K</var>番目の文字列が存圚しない堎合&quot;Impossible&quot;ず出力せよ</p> <h2>Sample Input 1</h2> <pre>3 4 2 2 1 3</pre> <h2>Output for the Sample Input 1</h2> <pre>bad</pre> <p><var>A</var>=4の堎合<var>SA</var>={2,1,3}ずなる文字列は&quot;bac&quot;,&quot;bad&quot;,&quot;cad&quot;,&quot;cbd&quot;の4通り<br /> したがっお蟞曞匏順序で2番目の&quot;bad&quot;が答えずなる</p> <h2>Sample Input 2</h2> <pre>18 26 10275802967 10 14 9 13 7 8 2 6 11 18 12 1 4 3 16 5 17 15</pre> <h2>Output for the Sample Input 2</h2> <pre>ritsumeicampdaytwo</pre>
p00903
<H1><font color="#000">Problem J:</font>Round Trip</H1> <p> Jim is planning to visit one of his best friends in a town in the mountain area. First, he leaves his hometown and goes to the destination town. This is called the go phase. Then, he comes back to his hometown. This is called the return phase. You are expected to write a program to find the minimum total cost of this trip, which is the sum of the costs of the go phase and the return phase. </p> <p> There is a network of towns including these two towns. Every road in this network is one-way, i.e., can only be used towards the specified direction. Each road requires a certain cost to travel. </p> <p> In addition to the cost of roads, it is necessary to pay a specified fee to go through each town on the way. However, since this is the visa fee for the town, it is not necessary to pay the fee on the second or later visit to the same town. </p> <p> The altitude (height) of each town is given. On the go phase, the use of descending roads is inhibited. That is, when going from town <i>a</i> to <i>b</i>, the altitude of <i>a</i> should not be greater than that of <i>b</i>. On the return phase, the use of ascending roads is inhibited in a similar manner. If the altitudes of <i>a</i> and <i>b</i> are equal, the road from <i>a</i> to <i>b</i> can be used on both phases. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each in the following format. </p> <p> <i>n m<br> d<sub>2</sub> e<sub>2</sub><br> d<sub>3</sub> e<sub>3</sub><br> .<br> .<br> .<br> d<sub>n-1</sub> e<sub>n-1</sub><br> a<sub>1</sub> b<sub>1</sub> c<sub>1</sub><br> a<sub>2</sub> b<sub>2</sub> c<sub>2</sub><br> .<br> .<br> .<br> a<sub>m</sub> b<sub>m</sub> c<sub>m</sub> </i> </p> <p> Every input item in a dataset is a non-negative integer. Input items in a line are separated by a space. </p> <p> <i>n</i> is the number of towns in the network. <i>m</i> is the number of (one-way) roads. You can assume the inequalities 2 &le; <i>n</i> &le; 50 and 0 &le; <i>m</i> &le; <i>n</i>(<i>n</i>&minus;1) hold. Towns are numbered from 1 to <i>n</i>, inclusive. The town 1 is Jim's hometown, and the town <i>n</i> is the destination town. </p> <p> <i>d<sub>i</sub></i> is the visa fee of the town <i>i</i>, and <i>e<sub>i</sub></i> is its altitude. You can assume 1 &le; <i>d<sub>i</sub></i> &le; 1000 and 1&le;<i>e<sub>i</sub></i> &le; 999 for 2&le;<i>i</i>&le;<i>n</i>&minus;1. The towns 1 and <i>n</i> do not impose visa fee. The altitude of the town 1 is 0, and that of the town n is 1000. Multiple towns may have the same altitude, but you can assume that there are no more than 10 towns with the same altitude. </p> <p> The <i>j</i>-th road is from the town <i>a<sub>j</sub></i> to <i>b<sub>j</sub></i> with the cost <i>c<sub>j</sub></i> (1 &le; <i>j</i> &le; <i>m</i>). You can assume 1 &le; <i>a<sub>j</sub></i> &le; <i>n</i>, 1 &le; <i>b<sub>j</sub></i> &le; <i>n</i>, and 1 &le; <i>c<sub>j</sub></i> &le; 1000. You can directly go from <i>a<sub>j</sub></i> to <i>b<sub>j</sub></i>, but not from <i>b<sub>j</sub></i> to <i>a<sub>j</sub></i> unless a road from <i>b<sub>j</sub></i> to <i>a<sub>j</sub></i> is separately given. There are no two roads connecting the same pair of towns towards the same direction, that is, for any <i>i</i> and <i>j</i> such that <i>i</i> &ne; <i>j</i>, <i>a<sub>i</sub></i> &ne; <i>a<sub>j</sub></i> or <i>b<sub>i</sub></i> &ne; <i>b<sub>j</sub></i>. There are no roads connecting a town to itself, that is, for any <i>j</i>, <i>a<sub>j</sub></i> &ne; <i>b<sub>j</sub></i>. </p> <p> The last dataset is followed by a line containing two zeros (separated by a space). </p> <H2>Output</H2> <p> For each dataset in the input, a line containing the minimum total cost, including the visa fees, of the trip should be output. If such a trip is not possible, output &ldquo;-1&rdquo;. </p> <H2>Sample Input</H2> <pre> 3 6 3 1 1 2 1 2 3 1 3 2 1 2 1 1 1 3 4 3 1 4 3 6 5 1 1 2 1 2 3 1 3 2 1 2 1 1 1 3 4 3 1 4 4 5 3 1 3 1 1 2 5 2 3 5 3 4 5 4 2 5 3 1 5 2 1 2 1 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 7 8 36 -1 </pre>
p00450
<H1> 碁石ならべ </H1> <h2>問題</h2> <p> 癜ず黒の碁石をテヌブルの䞊にならべお遊ぶ.たずテヌブルの巊端に碁石を眮く.次に巊から 2 番目の堎所に碁石を眮く.これを n 回繰り返しお n 個の碁石を暪䞀列にならべる.ただし,新しく i 番目の碁石を眮く際には,次のルヌルに埓っおテヌブル䞊の碁石を眮き換える. </p> <ul> <li> i が奇数の堎合: テヌブルに眮いおあった碁石は眮き換えず,新しい碁石を巊 から i 番目に眮く.</li> <li> i が偶数の堎合: 新しく巊から i 番目に眮く碁石の色ずテヌブル䞊の右端の碁 石の色が同じ堎合は,テヌブル䞊の碁石は眮き換えず,新しい碁石を巊から i 番目に眮く.そうでない堎合,すなわち,新しく巊から i 番目に眮く碁石の色 ずテヌブル䞊の右端の碁石の色が異なる堎合は,たずテヌブル䞊の右端の連続 した同色の碁石を党お取り陀き,i 番目の碁石ず同色の碁石に眮き換える.そ しおテヌブルの右端に i 番目の碁石を眮く.</li> </ul> <p> 䟋えば,最初の 7 個の碁石を眮いた時点で, </p> <p> ○○●●○○○ </p> <p> ずなっおいたずする. (○は癜の碁石を,●は黒の碁石を衚す. ) </p> <ul> <li> 8 番目の碁石が癜(○)の堎合は,右端の碁石ず同色なので,そのたた眮く.し たがっお,テヌブル䞊の碁石は<br> <p>○○●●○○○○</p> ずなる. </li> <li> 8 番目の碁石が黒(●)の堎合は,右端の碁石(○)ず色が異なるので,たず テヌブルの右端にある 3 個の連続した癜い碁石(○)を取り陀き,黒い碁石 (●)に眮き換える.そしお右端に 8 番目の碁石を眮く.したがっお,テヌブ ル䞊の碁石は<br> <p> ○○●●●●●● </p> ずなる. </li> </ul> <p> 入力ずしお眮く碁石の順番が䞎えられたずき,n 個の碁石をならべ終わった埌,テヌ ブル䞊に眮いおある癜い碁石の個数を求めるプログラムを䜜成せよ. </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> <!-- 入力ファむルのファむル名は input.txt である.--> 1 行目には正敎数 n (1 &le; n &le; 100000) が曞かれおいる.2 行目以降の第 i + 1 行目 (1 &le; i &le; n) には,i 番目に眮く碁石の色を衚す敎数 c<sub>i</sub> が曞かれおおり,c<sub>i</sub> が 0 なら i 番目に眮く碁石の色が癜であるこずを,1 なら i 番目に眮く碁石の色が黒であるこずを衚す. </p> <p> 採点甚デヌタのうち, 配点の 50% 分に぀いおは, n &le; 10000 を満たす. </p> <p> n が 0 のずき入力の終了を瀺す. デヌタセットの数は 10 を超えない </p> <h2>出力</h2> <p> <!-- 出力ファむルのファむル名は output.txt である. output.txt は,n 個の碁石をならべ終わった埌にテヌブル䞊に眮いおある癜い碁石の個数だけを含む 1 行からなる. --> デヌタセットごずに, n 個の碁石をならべ終わった埌にテヌブル䞊に眮いおある癜い碁石の個数を 1 行に出力する. </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 8 1 0 1 1 0 0 0 0 8 1 0 1 1 0 0 0 1 0 </pre> <h3>出力䟋</h3> <pre> 6 2 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02197
<h2>双子 (Twins)</h2> <p>square1001君ずE869120君は双子です。</p> <p>このうち先に生たれた方を出力しお䞋さい。</p> <h3>入力</h3> <p>入力は䞎えられない。</p> <h3>出力</h3> <p>正解の文字列を䞀行に出力せよ。</p> <p>ただし、最埌には改行を入れるこず。</p> <h3>出力䟋1</h3> <pre> square1001 </pre>
p00000
<H1>QQ</H1> <p> Write a program which prints multiplication tables in the following format: </p> <pre> 1x1=1 1x2=2 . . 9x8=72 9x9=81 </pre> <H2>Input</H2> <p> No input. </p> <H2>Output</H2> <pre> 1x1=1 1x2=2 . . 9x8=72 9x9=81 </pre> <H2>Template for C</H2> <pre> #include&lt;stdio.h&gt; int main(){ return 0; } </pre> <H2>Template for C++</H2> <pre> #include&lt;iostream&gt; using namespace std; int main(){ return 0; } </pre> <H2>Template for Java</H2> <pre> class Main{ public static void main(String[] a){ } } </pre>
p03505
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><em>ButCoder Inc.</em> runs a programming competition site called <em>ButCoder</em>. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is <var>0</var>, and a user whose rating reaches <var>K</var> or higher is called <em>Kaiden</em> ("total transmission"). Note that a user's rating may become negative.</p> <p>Hikuhashi is a new user in ButCoder. It is estimated that, his rating increases by <var>A</var> in each of his odd-numbered contests (first, third, fifth, ...), and decreases by <var>B</var> in each of his even-numbered contests (second, fourth, sixth, ...).</p> <p>According to this estimate, after how many contests will he become Kaiden for the first time, or will he never become Kaiden?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ K, A, B ≀ 10^{18}</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>K</var> <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is estimated that Hikuhashi will never become Kaiden, print <code>-1</code>. Otherwise, print the estimated number of contests before he become Kaiden for the first time.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4000 2000 500 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>Each time Hikuhashi participates in a contest, his rating is estimated to change as <var>0</var> → <var>2000</var> → <var>1500</var> → <var>3500</var> → <var>3000</var> → <var>5000</var> → <var>
</var> After his fifth contest, his rating will reach <var>4000</var> or higher for the first time.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4000 500 2000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>Each time Hikuhashi participates in a contest, his rating is estimated to change as <var>0</var> → <var>500</var> → <var>-1500</var> → <var>-1000</var> → <var>-3000</var> → <var>-2500</var> → <var>
</var> He will never become Kaiden.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000000000000 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1999999999999999997 </pre> <p>The input and output values may not fit into <var>32</var>-bit integers.</p></section> </div> </span>
p01538
<h1>かけざん</h1> <p> 倪郎君はかけざんを習いたおの小孊生です。なんずなく、圌はかけざんを気に入っおいるので、数字を芋かけるずかけざんをしたくなりたす。そんな圌はここのずころ、次のような凊理を0以䞊の敎数に斜すこずが奜きなようです。 (凊理の流れ) </p> <ul> <li>手順1. ある0以䞊の敎数nが10進数衚瀺で䞀けたならばそこで凊理を終了する。そうでなければ手順2に進む </li><li>手順2. 10以䞊の敎数nを10進数衚瀺をするずどこかの桁の間に切れ目を入れお二぀の数字に分解するこずが可胜である(䟋えば2012-&gt; 20,12)。このような切り方ずしおありうるものに察しお,埗られた二぀の数字を掛け合わせお最も倧きいものを次のnずしお手順1に戻る。(詳しくは䞋蚘の&quot;手順2に関する補足を参照&quot;) </li></ul> <p> 倪郎君はこの凊理を気に入っおいるようですが、䜕回手順2の操䜜を繰り返せばよいのか倧きい数字だず予想ができず、もしかしたら無限回行われなければならないかもしれないず思っおいたす。そこで、倪郎君の兄であり倧孊生であるあなたに0以䞊の敎数nに察しおこの手順2を䜕回しなければならないかを聞いおきたした。 </p> <p> あなたの仕事は、Q個の0以䞊の敎数<var>N<sub>1</sub></var>..<var>N<sub>Q</sub></var>が䞎えられるので、それぞれの敎数で凊理の終了たでに䜕回の手順2が斜されるかを求めるこずです。その際にもし無限回の手順が必芁ならば、-1を出力しおください。 </p> <h3>手順2に関する補足</h3> <p> 切り分けた結果、桁の初めに0が぀くものも考慮に入れる必芁がありたす。<br> 䟋えばn=1024のずき、1*024 , 10*24 , 102*4をそれぞれ蚈算するずそれぞれ24,240,408ずなるため、408が遞ばれ、これが次のnずなりたす。 </p> <h2>Input</h2> <blockquote> <var>Q</var><br><var>N<sub>1</sub></var><br><var>N<sub>2</sub></var><br>...<br><var>N<sub>Q</sub></var><br></blockquote> <ul> <li><var>Q</var>は䞎えられる0以䞊の敎数の個数を衚す </li><li><var>N<sub>i</sub></var>は倪郎君が気になっおいる0以䞊の敎数で,i番目のものを衚す </li></ul> <h2>Constraints</h2> <blockquote> <var>1&le;Q&le;100</var><br><var>0&le;N<sub>i</sub>&le;10<sup>6</sup></var><br></blockquote> <h2>Output</h2> <p> <var>Q</var>個の敎数を改行区切りで出力せよ </p> <blockquote> <var>R<sub>1</sub></var><br><var>R<sub>2</sub></var><br>..<br><var>R<sub>Q</sub></var><br></blockquote> <ul> <li><var>R<sub>i</sub></var>は、<var>N<sub>i</sub></var>に察しお凊理を終了するたでに手順2を実行する回数を衚す </li><li><var>N<sub>i</sub></var>に察しお手順2を無限回だけ実行する必芁がある堎合は<var>R<sub>i</sub></var> は -1ずなる </li></ul> <H2>Sample Input 1</H2> <pre>3 9 99 123 </pre> <H2>Output for the Sample Input 1</H2> <pre>0 2 3 </pre> <p> 9は1桁の数なので、手順2が実行されるこずはありたせん。 99は2桁であり、手順2を斜せば9,9ずしか分割できずその次の数は81ずなる。 81も2桁の数であり、手順2を斜せば8,1ずしか分割できずその次の数は8ずなる。 1桁の数になったので凊理が終了し、答えは2。 123は3桁の数なので、手順2を斜したす。 この堎合は12,3ず1,23の二぀の分け方があり、それぞれでかけざんをするず36,23ずなるので、 36が次の数ずしお遞ばれたす。 </p> <H2>Sample Input 2</H2> <pre>2 999999 1000000 </pre> <H2>Output for the Sample Input 2</H2> <pre>12 1 </pre>
p03155
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.</p> <p>The bulletin board is in the form of a grid with <var>N</var> rows and <var>N</var> columns, and the notice will occupy a rectangular region with <var>H</var> rows and <var>W</var> columns.</p> <p>How many ways are there to choose where to put the notice so that it completely covers exactly <var>HW</var> squares?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H, W \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>H</var> <var>W</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 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two ways to put the notice, as follows:</p> <pre>### ... ### ### ... ### </pre> <p>Here, <code>#</code> represents a square covered by the notice, and <code>.</code> represents a square not covered.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p01168
<H1><font color="#000">Problem F:</font> Lying about Your Age</H1> <p> You have moved to a new town. As starting a new life, you have made up your mind to do one thing: lying about your age. Since no person in this town knows your history, you don’t have to worry about immediate exposure. Also, in order to ease your conscience somewhat, you have decided to claim ages that represent your real ages when interpreted as the base-<i>M</i> numbers (2 &le; <i>M</i> &le; 16). People will misunderstand your age as they interpret the claimed age as a decimal number (i.e. of the base 10). </p> <p> Needless to say, you don’t want to have your real age revealed to the people in the future. So you should claim only one age each year, it should contain digits of decimal numbers (i.e. ‘0’ through ‘9’), and it should always be equal to or greater than that of the previous year (when interpreted as decimal). </p> <p> How old can you claim you are, after some years? </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset is a single line that contains three integers <i>A</i>, <i>B</i>, and <i>C</i>, where <i>A</i> is the present real age (in decimal), <i>B</i> is the age you presently claim (which can be a non-decimal number), and <i>C</i> is the real age at which you are to find the age you will claim (in decimal). It is guaranteed that 0 &le; <i>A</i> &lt; <i>C</i> &le; 200, while <i>B</i> may contain up to eight digits. No digits other than ‘0’ through ‘9’ appear in those numbers. </p> <p> The end of input is indicated by <i>A</i> = <i>B</i> = <i>C</i> = -1, which should not be processed. </p> <H2>Output</H2> <p> For each dataset, print in a line the minimum age you can claim when you become <i>C</i> years old. In case the age you presently claim cannot be interpreted as your real age with the base from 2 through 16, print -1 instead. </p> <H2>Sample Input</H2> <pre> 23 18 53 46 30 47 -1 -1 -1 </pre> <H2>Output for the Sample Input</H2> <pre> 49 -1 </pre>
p01492
<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 G: CarrotBreeding </h2> <p> にんじんは繁殖の奜きな怍物である. </p> <p> うさぎが畑でにんじんを飌うこずにした. 畑は (0, 0) ず (1000000000, 1000000000) を察角線ずする正方圢 (boundary を含む) である. うさぎは, 2 個以䞊のにんじんを通るすべおの盎線に沿っお毎日1 回ず぀氎をたくこずにした. </p> <p> このにんじんたちは, 毎日 $N$ 回ず぀氎をたかれるのが繁殖に最適だず考えおいるので, そのような条件を満たすようにうさぎの畑に䞊ぶこずにした. にんじんは畑内郚の栌子点にしか䞊ぶこずができない. たた, そのような条件を満たす䞊び方が耇数ある堎合は, 最もにんじんの個数が少ないものを遞ぶこずにした. </p> <p> 条件を満たすにんじんの配眮を1 ぀出力せよ. そのような配眮が存圚しない堎合には -1 ず出力せよ. </p> <h3>Constraints</h3> <ul> <li>$N$ will be between 1 and 1,000,000, inclusive.</li> </ul> <h3>Input</h3> <p> 入力は以䞋の圢匏で䞎えられる:<br> <br> $N$ <br> </p> <h3>Output</h3> <p> 条件を満たす配眮が存圚しない堎合, -1 ず䞀行に出力せよ.<br> 存圚する堎合, にんじんの本数を $K$ ずするず, 以䞋の圢匏で出力せよ:<br> <br> $K$<br> $x_1$ $y_1$<br> ...<br> $x_K$ $y_K$<br> </p> <h3>Sample Input 1</h3> <pre>4</pre> <h3>Sample Output 1</h3> <pre>4 0 0 1 0 2 0 1 1</pre> <h3>Sample Input 2</h3> <pre>6</pre> <h3>Sample Output 2</h3> <pre>4 0 0 0 1 1 0 1 1</pre>
p00329
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>あみだくじ</H1> <p> PCK 君はみんなでゲヌム倧䌚をしおいたす。このゲヌム倧䌚では、倧䌚の最埌にあみだくじで順䜍を入れ替えたす。倧䌚には <var>N</var> 人のプレむダヌが参加しおおり、あみだくじには <var>N</var> 本の瞊棒がありたす。 </p> <p> あみだくじは、図のように <var>N</var> - 1 段の郚品からできおおり、それぞれ 1 から <var>N</var>-1 の番号が割り圓おられおいたす。各郚品は、あみだくじの䞀郚を暪方向に切り取った郚分です。各郚品にはいく぀かの暪棒が匕かれおいたすが、郚品の䞭の暪棒はすべお同じ高さにありたす。暪棒同士が぀ながるこずはありたせん。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_amida"><br/> </center> <br/> <p> 倧䌚の最埌に、順䜍の高い人から右から巊の順に瞊棒が割り圓おられたす。PCK 君は珟時点で最䞋䜍なので、巊端からスタヌトです。䟋えば、䞊図の組み立お方では、䜍だったPCK 君は、このあみだくじによっお䜍右から番目の棒に浮䞊するこずができたす。 </p> <p> このゲヌムでは、最䞋䜍の人にあみだくじを組み立おる暩利が䞎えられたす。PCK 君はうたくあみだくじの郚品の順番を決めお、逆転優勝を狙っおいたす。ただし、郚品を回転するこずはできたせん。 </p> <p> ※補足あみだくじのたどり方に぀いお<br/> あみだくじのある瞊棒の䞊端から出発しお䞊から䞋ぞ進む。ただし、暪棒がある地点ではその暪棒で぀ながった別の瞊棒に移動する。これを、瞊棒の䞋端にたどり着くたで繰り返す。 </p> <p> ゲヌムの参加人数ずあみだくじの郚品の情報を入力し、PCK 君が優勝できるかどうか刀定するプログラムを䜜成せよ。優勝できる堎合、そのあみだくじの郚品の䞊びを぀出力せよ。ただし、そのような䞊べ方が耇数ある堎合は、䞎えられた郚品の番号で蟞曞順最小のものを出力せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>b<sub>1,1</sub></var> <var>b<sub>1,2</sub></var> ... <var>b<sub>1,N&minus;1</sub></var> <var>b<sub>2,1</sub></var> <var>b<sub>2,2</sub></var> ... <var>b<sub>2,N&minus;1</sub></var> : <var>b<sub>N&minus;1,1</sub></var> <var>b<sub>N&minus;1,2</sub></var> ... <var>b<sub>N&minus;1,N&minus;1</sub></var> </pre> <p> 行目に倧䌚の参加者数 <var>N</var> (2 &le; <var>N</var> &le; 500) が䞎えられる。続く <var>N</var>-1 行に <var>i</var> 番目の郚品の暪棒の情報が䞎えられる。<var>b<sub>i,j</sub></var> が 1 であるずき、<var>i</var> 番目の郚品の、巊から <var>j</var> 本目の瞊棒から <var>j</var>+1 番目の瞊棒ぞ暪棒が匕かれおいるこずを衚す。<var>b<sub>i,j</sub></var> が 0 であるずき、<var>i</var> 番目の郚品の、巊から <var>j</var> 本目の瞊棒から <var>j</var>+1 番目の瞊棒ぞ暪棒は匕かれおいないこずを衚す。<var>b<sub>i,j</sub></var> が 1 であるずき、<var>b<sub>i,j+1</sub></var> が 1 ずなるような郚品は䞎えられない。たた、暪棒の総数は 10000 を越えない。 </p> <h2>Output</h2> <p> PCK 君が優勝できる堎合行目に「yes」ず出力する。続く <var>N</var>-1 行に、あみだくじの䞊から順に、郚品の番号の䞊びを出力する。そのような䞊びが耇数ある堎合、蟞曞順最小である䞊びを出力する。PCK 君が優勝できない堎合、行に「no」ず出力する。 </p> <h2>Sample Input 1</h2> <pre> 6 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 </pre> <h2>Sample Output 1</h2> <pre> yes 1 3 2 4 5 </pre> <br/> <h2>Sample Input 2</h2> <pre> 5 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 1 </pre> <h2>Sample Output 2</h2> <pre> yes 4 1 3 2 </pre> <p> 4 1 3 2 ず 4 2 3 1 の通りの組み立お方が可胜だが、蟞曞順で小さい方の 4 1 3 2 を出力する。 </p> <br/> <h2>Sample Input 3</h2> <pre> 5 1 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 </pre> <h2>Sample Output 3</h2> <pre> no </pre>
p02314
<H1>Coin Changing Problem</H1> <br/> <p> Find the minimum number of coins to make change for <var>n</var> cents using coins of denominations <var>d<sub>1</sub></var>, <var>d<sub>2</sub></var>,.., <var>d</var><sub><var>m</var></sub>. The coins can be used any number of times. </p> <H2>Input</H2> <pre> <var>n</var> <var>m</var> <var>d<sub>1</sub></var> <var>d<sub>2</sub></var> ... <var>d</var><sub><var>m</var></sub> </pre> <p> Two integers <var>n</var> and <var>m</var> are given in the first line. The available denominations are given in the second line. </p> <H2>Output</H2> <p> Print the minimum number of coins in a line. </p> <H2>Constraints</H2> <ul> <li> 1 &le; <var>n</var> &le; 50000 </li> <li> 1 &le; <var>m</var> &le; 20 </li> <li> 1 &le; denomination &le; 10000 </li> <li> The denominations are all different and contain 1. </li> </ul> <H2>Sample Input 1</H2> <pre> 55 4 1 5 10 50 </pre> <H2>Sample Output 1</H2> <pre> 2 </pre> <br/> <H2>Sample Input 2</H2> <pre> 15 6 1 2 7 8 12 50 </pre> <H2>Sample Output 2</H2> <pre> 2 </pre> <br/> <H2>Sample Input 3</H2> <pre> 65 6 1 2 7 8 12 50 </pre> <H2>Sample Output 3</H2> <pre> 3 </pre>
p03856
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters. Another string <var>T</var> is initially empty. Determine whether it is possible to obtain <var>S = T</var> by performing the following operation an arbitrary number of times:</p> <ul> <li>Append one of the following at the end of <var>T</var>: <code>dream</code>, <code>dreamer</code>, <code>erase</code> and <code>eraser</code>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩|S|≩10^5</var></li> <li><var>S</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>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>If it is possible to obtain <var>S = T</var>, print <code>YES</code>. Otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>erasedream </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>Append <code>erase</code> and <code>dream</code> at the end of <var>T</var> in this order, to obtain <var>S = T</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>dreameraser </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>YES </pre> <p>Append <code>dream</code> and <code>eraser</code> at the end of <var>T</var> in this order, to obtain <var>S = T</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>dreamerer </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre></section> </div> </span>
p00779
<h3>Don't Cross the Circles!</h3> <p> There are one or more circles on a plane. Any two circles have different center positions and/or different radiuses. A circle may intersect with another circle, but no three or more circles have areas nor points shared by all of them. A circle may completely contain another circle or two circles may intersect at two separate points, but you can assume that the circumferences of two circles never touch at a single point. </p> <p> Your task is to judge whether there exists a path that connects the given two points, <i>P</i> and <i>Q</i>, without crossing the circumferences of the circles. You are given one or more point pairs for each layout of circles. </p> <p> In the case of Figure G-1, we can connect <i>P</i> and <i>Q</i><sub>1</sub> without crossing the circumferences of the circles, but we cannot connect <i>P</i> with <i>Q</i><sub>2</sub>, <i>Q</i><sub>3</sub>, or <i>Q</i><sub>4</sub> without crossing the circumferences of the circles. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_domestic2014_G0"><br> <p>Figure G-1: Sample layout of circles and points</p> </center> <br> <h3>Input</h3> <p> The input consists of multiple datasets, each in the following format. </p> <blockquote> <i>n</i> <i>m</i><br> <i>Cx</i><sub>1</sub> <i>Cy</i><sub>1</sub> <i>r</i><sub>1</sub> <br> ...<br> <i>Cx</i><sub><i>n</i></sub> <i>Cy</i><sub><i>n</i></sub> <i>r</i><sub><i>n</i></sub> <br> <i>Px</i><sub>1</sub> <i>Py</i><sub>1</sub> <i>Qx</i><sub>1</sub> <i>Qy</i><sub>1</sub> <br> ...<br> <i>Px</i><sub><i>m</i></sub> <i>Py</i><sub><i>m</i></sub> <i>Qx</i><sub><i>m</i></sub> <i>Qy</i><sub><i>m</i></sub> <br> </blockquote> <p> The first line of a dataset contains two integers <i>n</i> and <i>m</i> separated by a space. <i>n</i> represents the number of circles, and you can assume 1 &#8804; <i>n</i> &#8804; 100. <i>m</i> represents the number of point pairs, and you can assume 1 &#8804; <i>m</i> &#8804; 10. Each of the following <i>n</i> lines contains three integers separated by a single space. (<i>Cx</i><sub><i>i</i></sub>, <i>Cy</i><sub><i>i</i></sub>) and <i>r</i><sub><i>i</i></sub> represent the center position and the radius of the <i>i</i>-th circle, respectively. Each of the following <i>m</i> lines contains four integers separated by a single space. These four integers represent coordinates of two separate points <i>P</i><sub><i>j</i></sub> = (<i>Px</i><sub><i>j</i></sub>, <i>Py</i><sub><i>j</i></sub>) and <i>Q</i><sub><i>j</i></sub> =(<i>Qx</i><sub><i>j</i></sub>, <i>Qy</i><sub><i>j</i></sub>). These two points <i>P</i><sub><i>j</i></sub> and <i>Q</i><sub><i>j</i></sub> form the <i>j</i>-th point pair. You can assume 0 &#8804; <i>Cx</i><sub><i>i</i></sub> &#8804; 10000, 0 &#8804; <i>Cy</i><sub><i>i</i></sub> &#8804; 10000, 1 &#8804; <i>r</i><sub><i>i</i></sub> &#8804; 1000, 0 &#8804; <i>Px</i><sub><i>j</i></sub> &#8804; 10000, 0 &#8804; <i>Py</i><sub><i>j</i></sub> &#8804; 10000, 0 &#8804; <i>Qx</i><sub><i>j</i></sub> &#8804; 10000, 0 &#8804; <i>Qy</i><sub><i>j</i></sub> &#8804; 10000. In addition, you can assume <i>P</i><sub><i>j</i></sub> or <i>Q</i><sub><i>j</i></sub> are not located on the circumference of any circle. </p> <p> The end of the input is indicated by a line containing two zeros separated by a space. </p> <p> Figure G-1 shows the layout of the circles and the points in the first dataset of the sample input below. Figure G-2 shows the layouts of the subsequent datasets in the sample input. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_domestic2014_G1"><br> <p>Figure G-2: Sample layout of circles and points</p> </center> <br> <h3>Output</h3> <p> For each dataset, output a single line containing the <i>m</i> results separated by a space. The <i>j</i>-th result should be "YES" if there exists a path connecting <i>P</i><sub><i>j</i></sub> and <i>Q</i><sub><i>j</i></sub>, and "NO" otherwise. </p> <h3>Sample Input</h3> <pre>5 3 0 0 1000 1399 1331 931 0 1331 500 1398 0 400 2000 360 340 450 950 1600 380 450 950 1399 1331 450 950 450 2000 1 2 50 50 50 0 10 100 90 0 10 50 50 2 2 50 50 50 100 50 50 40 50 110 50 40 50 0 0 4 1 25 100 26 75 100 26 50 40 40 50 160 40 50 81 50 119 6 1 100 50 40 0 50 40 50 0 48 50 50 3 55 55 4 55 105 48 50 55 55 50 20 6 270 180 50 360 170 50 0 0 50 10 0 10 0 90 50 0 180 50 90 180 50 180 180 50 205 90 50 180 0 50 65 0 20 75 30 16 90 78 36 105 30 16 115 0 20 128 48 15 128 100 15 280 0 30 330 0 30 305 65 42 0 20 10 20 0 20 10 0 50 30 133 0 50 30 133 30 90 40 305 20 90 40 240 30 16 2 0 0 50 0 90 50 0 180 50 90 180 50 180 180 50 205 90 50 180 0 50 65 0 20 115 0 20 90 0 15 280 0 30 330 0 30 305 65 42 75 40 16 90 88 36 105 40 16 128 35 250 30 90 50 305 20 0 0 </pre> <h3>Output for the Sample Input</h3> <pre>YES NO NO YES NO NO NO NO YES YES NO NO YES NO NO NO NO </pre>
p02744
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In this problem, we only consider strings consisting of lowercase English letters.</p> <p>Strings <var>s</var> and <var>t</var> are said to be <strong>isomorphic</strong> when the following conditions are satisfied:</p> <ul> <li><var>|s| = |t|</var> holds.</li> <li>For every pair <var>i, j</var>, one of the following holds:<ul> <li><var>s_i = s_j</var> and <var>t_i = t_j</var>.</li> <li><var>s_i \neq s_j</var> and <var>t_i \neq t_j</var>.</li> </ul> </li> </ul> <p>For example, <code>abcac</code> and <code>zyxzx</code> are isomorphic, while <code>abcac</code> and <code>ppppp</code> are not.</p> <p>A string <var>s</var> is said to be in <strong>normal form</strong> when the following condition is satisfied:</p> <ul> <li>For every string <var>t</var> that is isomorphic to <var>s</var>, <var>s \leq t</var> holds. Here <var>\leq</var> denotes lexicographic comparison.</li> </ul> <p>For example, <code>abcac</code> is in normal form, but <code>zyxzx</code> is not since it is isomorphic to <code>abcac</code>, which is lexicographically smaller than <code>zyxzx</code>.</p> <p>You are given an integer <var>N</var>. Print all strings of length <var>N</var> that are in normal form, in lexicographically ascending order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Assume that there are <var>K</var> strings of length <var>N</var> that are in normal form: <var>w_1, \ldots, w_K</var> in lexicographical order. Output should be in the following format:</p> <pre><var>w_1</var> <var>:</var> <var>w_K</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>a </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>aa ab </pre></section> </div> </span>
p00283
<h1>巚暹の刻み手</h1> <p> あなたは <var>N</var> 皮類の道具を䜿っお、目の前の巚暹を切り倒そうずしおいたす。はじめは、暹の耐久力は <var>D</var>、あなたの経隓倀は 0 ですが、道具 <var>i</var> で回暹を叩くず暹の耐久力は <var>a<sub>i</sub></var> 枛り、あなたは <var>e<sub>i</sub></var> の経隓倀を埗たす。ただし、道具 <var>i</var> を䜿うためには、あなたは <var>r<sub>i</sub></var> 以䞊の経隓倀を持っおいなければなりたせん。暹の耐久力が 0 以䞋になるず暹は倒れたす。 </p> <p> 暹の耐久力ず道具に぀いおの情報が䞎えられたずき、暹を切り倒すには最䜎䜕回暹を叩かなければいけないかを求めるプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる。入力の終わりはれロ぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 </p> <pre> <var>D</var> <var>N</var> <var>a<sub>1</sub></var> <var>e<sub>1</sub></var> <var>r<sub>1</sub></var> <var>a<sub>2</sub></var> <var>e<sub>2</sub></var> <var>r<sub>2</sub></var> : <var>a<sub>N</sub></var> <var>e<sub>N</sub></var> <var>r<sub>N</sub></var> </pre> <p> 1 行目に暹の耐久力を衚す敎数 <var>D</var> (1 &le; <var>D</var> &le; 100) ず道具の皮類の数 <var>N</var>(1 &le; <var>N</var> &le; 100) が䞎えられる。続く <var>N</var> 行に道具 1 から <var>N</var> たでの情報が䞎えられる。<var>a<sub>i</sub></var> (0 &le; <var>a<sub>i</sub></var> &le; 100) ず <var>e<sub>i</sub></var> (0 &le; <var>e<sub>i</sub></var> &le; 100) は、道具iを回䜿うこずで枛る暹の耐久力ずあなたが埗るこずのできる経隓倀をそれぞれ衚す。<var>r<sub>i</sub></var> (0 &le; <var>r<sub>i</sub></var> &le; 100) は道具を䜿うために必芁な経隓倀を衚す。<var>a<sub>i</sub></var>, <var>e<sub>i</sub></var>, <var>r<sub>i</sub></var> はすべお敎数である。<br> <br> デヌタセットの数は 50 を超えない。 </p> <h2>出力</h2> <p> 暹を切り倒すのに必芁な、暹を叩く最小の回数を行に出力する。ただし、暹を切り倒すこずが䞍可胜な堎合は <span>NA</span> ず出力する。 </p> <h2>入出力䟋</h2> <br> <h2>入力䟋</h2> <pre> 15 4 1 1 0 1 2 2 5 10 5 8 1 15 60 4 5 2 0 8 8 2 3 5 0 49 0 18 100 1 1 1 1 0 0 </pre> <h2>出力䟋</h2> <pre> 6 4 NA </pre>
p01884
<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>Similarity of Subtrees</h2> <p> Define the depth of a node in a rooted tree by applying the following rules recursively: </p> <ul> <li> The depth of a root node is 0.</li> <li> The depths of child nodes whose parents are with depth $d$ are $d + 1$.</li> </ul> <p> Let $S(T, d)$ be the number of nodes of $T$ with depth $d$. Two rooted trees $T$ and $T'$ are similar if and only if $S(T, d)$ equals $S(T', d)$ for all non-negative integer $d$. </p> <p> You are given a rooted tree $T$ with $N$ nodes. The nodes of $T$ are numbered from 1 to $N$. Node 1 is the root node of $T$. Let $T_i$ be the rooted subtree of $T$ whose root is node $i$. Your task is to write a program which calculates the number of pairs $(i, j)$ such that $T_i$ and $T_j$ are similar and $i < j$. </p> <h3>Input</h3> <p> The input consists of a single test case.<br/> <br/> $N$<br/> $a_1$ $b_1$<br/> $a_2$ $b_2$<br/> ...<br/> $a_{N-1}$ $b_{N-1}$ </p> <p> The first line contains an integer $N$ ($1 \leq N \leq 100,000$), which is the number of nodes in a tree. The following $N -1$ lines give information of branches: the $i$-th line of them contains $a_i$ and $b_i$, which indicates that a node $a_i$ is a parent of a node $b_i$. ($1 \leq a_i, b_i \leq N, a_i \ne b_i$) The root node is numbered by 1. It is guaranteed that a given graph is a rooted tree, i.e. there is exactly one parent for each node except the node 1, and the graph is connected. </p> <h3>Output</h3> <p> Print the number of the pairs $(x, y)$ of the nodes such that the subtree with the root $x$ and the subtree with the root $y$ are similar and $x < y$. </p> <h3>Sample Input 1</h3> <pre> 5 1 2 1 3 1 4 1 5 </pre> <h3>Output for the Sample Input 1</h3> <pre> 6 </pre> <h3>Sample Input 2</h3> <pre> 6 1 2 2 3 3 4 1 5 5 6 </pre> <h3>Output for the Sample Input 2</h3> <pre> 2 </pre> <h3>Sample Input 3</h3> <Pre> 13 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 6 10 7 11 8 12 11 13 </pre> <h3>Output for the Sample Input 3</h3> <pre> 14 </pre>
p00796
<H1><font color="#000">Problem A:</font> Lost in Space</H1> <p> William Robinson was completely puzzled in the music room; he could not find his triangle in his bag. He was sure that he had prepared it the night before. He remembered its clank when he had stepped on the school bus early that morning. No, not in his dream. His triangle was quite unique: no two sides had the same length, which made his favorite peculiar jingle. He insisted to the music teacher, Mr. Smith, that his triangle had probably been stolen by those aliens and thrown away into deep space. </p> <p> Your mission is to help Will find his triangle in space. His triangle has been made invisible by the aliens, but candidate positions of its vertices are somehow known. You have to tell which three of them make his triangle. Having gone through worm-holes, the triangle may have changed its size. However, even in that case, all the sides are known to be enlarged or shrunk equally, that is, the transformed triangle is <i>similar</i> to the original. </p> <H2>Input</H2> <p> The very first line of the input has an integer which is the number of data sets. Each data set gives data for one incident such as that of Will’s. At least one and at most ten data sets are given. </p> <p> The first line of each data set contains three decimals that give lengths of the sides of the original triangle, measured in centimeters. Three vertices of the original triangle are named P, Q, and R. Three decimals given in the first line correspond to the lengths of sides QR, RP, and PQ, in this order. They are separated by one or more space characters. </p> <p> The second line of a data set has an integer which is the number of points in space to be considered as candidates for vertices. At least three and at most thirty points are considered. </p> <p> The rest of the data set are lines containing coordinates of candidate points, in light years. Each line has three decimals, corresponding to x, y, and z coordinates, separated by one or more space characters. Points are numbered in the order of their appearances, starting from one. </p> <p> Among all the triangles formed by three of the given points, only one of them is <i>similar</i> to the original, that is, ratios of the lengths of any two sides are equal to the corresponding ratios of the original allowing an error of less than 0.01 percent. Other triangles have some of the ratios different from the original by at least 0.1 percent. </p> <p> The origin of the coordinate system is not the center of the earth but the center of our galaxy. Note that negative coordinate values may appear here. As they are all within or close to our galaxy, coordinate values are less than one hundred thousand light years. You don’t have to take relativistic effects into account, i.e., you may assume that we are in a Euclidean space. You may also assume in your calculation that one light year is equal to 9.461 &times 10<sup>12</sup> kilometers. </p> <p> A succeeding data set, if any, starts from the line immediately following the last line of the preceding data set. </p> <H2>Output</H2> <p> For each data set, one line should be output. That line should contain the point numbers of the three vertices of the similar triangle, separated by a space character. They should be reported in the order P, Q, and then R. </p> <H2>Sample Input</H2> <pre> 2 50.36493 81.61338 79.96592 5 -10293.83 -4800.033 -5296.238 14936.30 6964.826 7684.818 -4516.069 25748.41 -27016.06 18301.59 -11946.25 5380.309 27115.20 43415.93 -71607.81 11.51547 13.35555 14.57307 5 -56292.27 2583.892 67754.62 -567.5082 -756.2763 -118.7268 -1235.987 -213.3318 -216.4862 -317.6108 -54.81976 -55.63033 22505.44 -40752.88 27482.94 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 4 3 4 2 </pre>
p02251
<h1>Change-Making Problem</h1> <p>You want to make change for $n$ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and/or 25 cents coins respectively, find the minimum number of coins you need.</p> <h2>Input</h2> <pre> $n$ </pre> <p>The integer $n$ is given in a line.</p> <h2>出力</h2> <p>Print the minimum number of coins you need in a line.</p> <h2>Constraints</h2> <ul> <li>$1 \le n \le 10^9$</li> </ul> <h2>Sample Input 1</h2> <pre> 100 </pre> <h2>Sample Output 1</h2> <pre> 4 </pre> <h2>Sample Input 2</h2> <pre> 54321 </pre> <h2>Sample Output 2</h2> <pre> 2175 </pre>
p03913
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Rng is baking cookies.</p> <p>Initially, he can bake one cookie per second.</p> <p>He can also eat the cookies baked by himself. When there are <var>x</var> cookies not yet eaten, he can choose to eat all those cookies. After he finishes eating those cookies, the number of cookies he can bake per second becomes <var>x</var>. Note that a cookie always needs to be baked for <var>1</var> second, that is, he cannot bake a cookie in <var>1/x</var> seconds when <var>x &gt; 1</var>. When he choose to eat the cookies, he must eat all of them; he cannot choose to eat only part of them. It takes him <var>A</var> seconds to eat the cookies regardless of how many, during which no cookies can be baked.</p> <p>He wants to give <var>N</var> cookies to Grandma. Find the shortest time needed to produce at least <var>N</var> cookies not yet eaten.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩10^{12}</var></li> <li><var>0≩A≩10^{12}</var></li> <li><var>A</var> is an integer.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>500</var> points will be awarded for passing the test set satisfying <var>N≩10^6</var> and <var>A≩10^6</var>.</li> <li>Additional <var>500</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the shortest time needed to produce at least <var>N</var> cookies not yet eaten.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>It is possible to produce <var>8</var> cookies in <var>7</var> seconds, as follows:</p> <ul> <li>After <var>1</var> second: <var>1</var> cookie is done.</li> <li>After <var>2</var> seconds: <var>1</var> more cookie is done, totaling <var>2</var>. Now, Rng starts eating those <var>2</var> cookies.</li> <li>After <var>3</var> seconds: He finishes eating the cookies, and he can now bake <var>2</var> cookies per second.</li> <li>After <var>4</var> seconds: <var>2</var> cookies are done.</li> <li>After <var>5</var> seconds: <var>2</var> more cookies are done, totaling <var>4</var>.</li> <li>After <var>6</var> seconds: <var>2</var> more cookies are done, totaling <var>6</var>.</li> <li>After <var>7</var> seconds: <var>2</var> more cookies are done, totaling <var>8</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000000000000 1000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000000000 </pre></section> </div> </span>
p02601
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>M-kun has the following three cards:</p> <ul> <li>A red card with the integer <var>A</var>.</li> <li>A green card with the integer <var>B</var>.</li> <li>A blue card with the integer <var>C</var>.</li> </ul> <p>He is a genius magician who can do the following operation at most <var>K</var> times:</p> <ul> <li>Choose one of the three cards and multiply the written integer by <var>2</var>.</li> </ul> <p>His magic is successful if both of the following conditions are satisfied after the operations:</p> <ul> <li>The integer on the green card is <strong>strictly</strong> greater than the integer on the red card.</li> <li>The integer on the blue card is <strong>strictly</strong> greater than the integer on the green card.</li> </ul> <p>Determine whether the magic can be successful.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq A, B, C \leq 7</var></li> <li><var>1 \leq K \leq 7</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If the magic can be successful, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 2 5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>The magic will be successful if, for example, he does the following operations:</p> <ul> <li>First, choose the blue card. The integers on the red, green, and blue cards are now <var>7</var>, <var>2</var>, and <var>10</var>, respectively.</li> <li>Second, choose the green card. The integers on the red, green, and blue cards are now <var>7</var>, <var>4</var>, and <var>10</var>, respectively.</li> <li>Third, choose the green card. The integers on the red, green, and blue cards are now <var>7</var>, <var>8</var>, and <var>10</var>, respectively.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>He has no way to succeed in the magic with at most three operations.</p></section> </div> </span>
p01187
<H1><font color="#000">Problem G:</font> Make Friendships</H1> <p> Isaac H. Ives attended an international student party and made a lot of girl friends (as many other persons expected). To strike up a good friendship with them, he decided to have dates with them. However, it is hard for him to schedule dates because he made so many friends. Thus he decided to find the best schedule using a computer program. The most important criterion in scheduling is how many different girl friends he will date. Of course, the more friends he will date, the better the schedule is. However, though he has the ability to write a program finding the best schedule, he doesn’t have enough time to write it. </p> <p> Your task is to write a program to find the best schedule instead of him. </p> <H2>Input</H2> <p> The input consists of a series of data sets. The first line of each data set contains a single positive integer <i>N</i> (<i>N</i> &le; 1,000) that represents the number of persons Isaac made friends with in the party. The next line gives Isaac’s schedule, followed by <i>N</i> lines that give his new friends’ schedules. Each schedule consists of a positive integer <i>M</i> that represents the number of available days followed by <i>M</i> positive integers each of which represents an available day. </p> <p> The input is terminated by a line that contains a single zero. This is not part of data sets and should not be processed. </p> <H2>Output</H2> <p> For each data set, print a line that contains the maximum number of girl friends Isaac can have dates with. </p> <H2>Sample Input</H2> <pre> 3 3 1 3 5 2 1 4 4 1 2 3 6 1 3 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 </pre>
p03440
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a forest with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>0</var> through <var>N-1</var>. The edges are given in the format <var>(x_i,y_i)</var>, which means that Vertex <var>x_i</var> and <var>y_i</var> are connected by an edge.</p> <p>Each vertex <var>i</var> has a value <var>a_i</var>. You want to add edges in the given forest so that the forest becomes connected. To add an edge, you choose two different vertices <var>i</var> and <var>j</var>, then span an edge between <var>i</var> and <var>j</var>. This operation costs <var>a_i + a_j</var> dollars, and afterward neither Vertex <var>i</var> nor <var>j</var> can be selected again.</p> <p>Find the minimum total cost required to make the forest connected, or print <code>Impossible</code> if it is impossible.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 100,000</var></li> <li><var>0 ≀ M ≀ N-1</var></li> <li><var>1 ≀ a_i ≀ 10^9</var></li> <li><var>0 ≀ x_i,y_i ≀ N-1</var></li> <li>The given graph is a forest.</li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_0</var> <var>a_1</var> <var>..</var> <var>a_{N-1}</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_M</var> <var>y_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total cost required to make the forest connected, or print <code>Impossible</code> if it is impossible.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 5 1 2 3 4 5 6 7 3 0 4 0 1 2 1 3 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>If we connect vertices <var>0</var> and <var>5</var>, the graph becomes connected, for the cost of <var>1 + 6 = 7</var> dollars.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 3 1 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Impossible </pre> <p>We can't make the graph connected.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 0 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>The graph is already connected, so we do not need to add any edges.</p></section> </div> </span>
p03010
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Diverta City is a new city consisting of <var>N</var> towns numbered <var>1, 2, ..., N</var>.</p> <p>The mayor Ringo is planning to connect every pair of two different towns with a bidirectional road. The length of each road is undecided.</p> <p>A <em>Hamiltonian path</em> is a path that starts at one of the towns and visits each of the other towns exactly once. The reversal of a Hamiltonian path is considered the same as the original Hamiltonian path.</p> <p>There are <var>N! / 2</var> Hamiltonian paths. Ringo wants all these paths to have distinct total lengths (the sum of the lengths of the roads on a path), to make the city diverse.</p> <p>Find one such set of the lengths of the roads, under the following conditions:</p> <ul> <li>The length of each road must be a positive integer.</li> <li>The maximum total length of a Hamiltonian path must be at most <var>10^{11}</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is a integer between <var>2</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print a set of the lengths of the roads that meets the objective, in the following format:</p> <pre><var>w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N}</var> <var>w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N}</var> <var>:</var> <var>:</var> <var>:</var> <var>w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N}</var> </pre> <p>where <var>w_{i, j}</var> is the length of the road connecting Town <var>i</var> and Town <var>j</var>, which must satisfy the following conditions:</p> <ul> <li><var>w_{i, i} = 0</var></li> <li><var>w_{i, j} = w_{j, i} \ (i \neq j)</var></li> <li><var>1 \leq w_{i, j} \leq 10^{11} \ (i \neq j)</var></li> </ul> <p>If there are multiple sets of lengths of the roads that meet the objective, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 6 15 6 0 21 15 21 0 </pre> <p>There are three Hamiltonian paths. The total lengths of these paths are as follows: </p> <ul> <li><var>1 → 2 → 3</var>: The total length is <var>6 + 21 = 27</var>.</li> <li><var>1 → 3 → 2</var>: The total length is <var>15 + 21 = 36</var>.</li> <li><var>2 → 1 → 3</var>: The total length is <var>6 + 15 = 21</var>.</li> </ul> <p>They are distinct, so the objective is met.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 111 157 193 111 0 224 239 157 224 0 258 193 239 258 0 </pre> <p>There are <var>12</var> Hamiltonian paths, with distinct total lengths.</p></section> </div> </span>
p01703
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }</style><div class="part"><h3>Problem Statement</h3><p><i>Infinite Chronicle -Princess Castle-</i> is a simple role-playing game. There are $n + 1$ checkpoints, numbered $0$ through $n$, and for each $i = 1, 2, \ldots, n$, there is a unique one-way road running from checkpoint $i - 1$ to $i$. The game starts at checkpoint $0$ and ends at checkpoint $n$. Evil monsters will appear on the roads and the hero will have battles against them. You can save your game progress at any checkpoint; if you lose a battle, you can restart the game from the checkpoint where you have saved for the last time. At the beginning of the game, the progress is automatically saved at checkpoint $0$ with no time. </p> <p>Rabbit Hanako is fond of this game and now interested in speedrunning. Although Hanako is an expert of the game, she cannot always win the battles because of random factors. For each $i$, she estimated the probability $p_i$ to win all the battles along the road from checkpoint $i - 1$ to $i$. Everytime she starts at checkpoint $i - 1$, after exactly one miniutes, she will be at checkpoint $i$ with probability $p_i$ and where she saved for the last time with probability $1 - p_i$. </p> <p>What puzzles Hanako is that it also takes one minute (!) to save your progress at a checkpoint, so it might be a good idea to pass some checkpoints without saving in order to proceed quickly. The task is to compute the minimum possible expected time needed to complete the game. </p> </div><div class="part"><h3>Input</h3> <p>The input consists of multiple datasets. The number of datasets is no more than $50$. Each dataset has two lines: the first line contains an integer $n$ ($1 \le n \le 10^5$), representing the number of roads, and the second line contains $n$ numbers $p_1, p_2, \ldots, p_n$ ($0 \lt p_i \le 1$), representing the winning probabilities. Each $p_i$ has exactly two digits after the decimal point. The end of input is denoted as a line containing only a single zero. </p> </div><div class="part"><h3>Output</h3> <p>For each dataset, display the minimum expected time in minutes with a relative error of at most $10^{-8}$ in a line. </p> </div><div class="part"><h3>Sample Input</h3> <pre>2 0.50 0.40 2 0.70 0.60 4 0.99 1.00 1.00 0.01 0</pre> </div><div class="part"><h3>Output for the Sample Input</h3> <pre>5.5000000000 4.0476190476 104.0101010101</pre> </div>
p00811
<H1><font color="#000">Problem A:</font> Calling Extraterrestrial Intelligence Again</H1> <p> A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November l6, l974. The message consisted of l679 bits and was meant to be translated to a rectangular picture with 23 &times; 73 pixels. Since both 23 and 73 are prime numbers, 23 &times; 73 is the unique possible size of the translated rectangular picture each edge of which is longer than l pixel. Of course, there was no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic. </p> <p> We are planning a similar project. Your task in the project is to find the most suitable width and height of the translated rectangular picture. The term ``most suitable'' is defined as follows. An integer m greater than 4 is given. A positive fraction <i>a</i>/<i>b</i> less than or equal to 1 is also given. The area of the picture should not be greater than <i>m</i>. Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than <i>a</i>/<i>b</i> nor greater than 1. You should maximize the area of the picture under these constraints. </p> <p> In other words, you will receive an integer <i>m</i> and a fraction <i>a</i>/<i>b</i> . It holds that <i>m</i> &gt; 4 and 0 &lt; <i>a</i>/<i>b</i> &le; 1 . You should find the pair of prime numbers <i>p</i>, <i>q</i> such that <i>pq</i> &le; <i>m</i> and <i>a</i>/<i>b</i> &le; <i>p</i>/<i>q</i> &le; 1 , and furthermore, the product <i>pq</i> takes the maximum value among such pairs of two prime numbers. You should report <i>p</i> and <i>q</i> as the "most suitable" width and height of the translated picture. </p> <H2>Input</H2> <p> The input is a sequence of at most 2000 triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicates the end of the input and should not be treated as data to be processed. </p> <p> The integers of each input triplet are the integer <i>m</i>, the numerator <i>a</i>, and the denominator <i>b</i> described above, in this order. You may assume 4 &lt; <i>m</i> &lt; 100000 and 1 &le; <i>a</i> &le; <i>b</i> &le; 1000. </p> <H2>Output</H2> <p> The output is a sequence of pairs of positive integers. The <i>i</i>-th output pair corresponds to the <i>i</i>-th input triplet. The integers of each output pair are the width <i>p</i> and the height <i>q</i> described above, in this order. </p> <p> Each output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output. </p> <H2>Sample Input</H2> <pre> 5 1 2 99999 999 999 1680 5 16 1970 1 1 2002 4 11 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 2 313 313 23 73 43 43 37 53 </pre>
p01353
<H1>Problem E: Rabbit Plays Games!</H1> <p> うさぎがずあるロヌルプレむングゲヌムで遊んでいる. 城に入る盎前で, 敵に埅ち䌏せされおいた </p> <p> うさぎが操䜜する䞻人公1 人ず, <i>n</i> 䜓の敵ずの戊闘ずなった. 各キャラクタヌには4 ぀の胜力倀, 䜓力<i>h<sub>i</sub></i>, 攻撃力<i>a<sub>i</sub></i>, 防埡力<i>d<sub>i</sub></i>, 敏捷<i>s<sub>i</sub></i> が定められおいる. <i>i</i> = 0 は䞻人公の情報, 1 &le; <i>i</i> &le; <i>n</i> は各敵の情報を衚す. </p> <p> 戊闘はタヌン制である. 各タヌン, 生き残っおいるキャラクタヌが, 敏捷の倀が高い順に攻撃を行う. 敵は必ず䞻人公を攻撃する. 䞻人公は敵1 䜓を攻撃するが, どの敵を攻撃するかは毎タヌンごずに䞻人公が遞べる.攻撃力<i>a</i> のキャラクタヌが防埡力<i>d</i> のキャラクタヌに攻撃するずき, max{<i>a</i> − <i>d</i>, 0} のダメヌゞが䞎えられる. 受けたダメヌゞの合蚈が䜓力の倀以䞊になったキャラクタヌは盎ちに戊闘䞍胜になっおしたう. 䞻人公が戊闘䞍胜になったずき, あるいは敵がすべお戊闘䞍胜になったずき, 戊闘は終了する. </p> <H2>Input</H2> <p> 1 &le; <i>n</i> &le; 40 000<br> 1 &le; <i>h<sub>i</sub></i>, <i>a<sub>i</sub></i>, <i>d<sub>i</sub></i>, <i>s<sub>i</sub></i> &le; 1 000 000 000 (敎数)<br> <i>s<sub>i</sub></i> はすべお異なる.<br> </p> <H2>Output</H2> <p> 䞻人公が必ず戊闘䞍胜になっおしたうずき, −1 を出力せよ. そうでないずき, 䞻人公が受けるダメヌゞの合蚈の最小倀を䞀行に出力せよ. </p> <H2>Sample Input 1</H2> <pre> 2 10 3 1 2 2 4 1 3 2 2 1 1 </pre> <H2>Sample Output 1</H2> <pre> 4 </pre> <H2>Sample Input 2</H2> <pre> 1 1 1 1 1 10000 10000 10000 10000 </pre> <H2>Sample Output 2</H2> <pre> -1 </pre>
p03694
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.<br/> There are <var>N</var> houses along <em>TopCoDeer street</em>. The <var>i</var>-th house is located at coordinate <var>a_i</var>. He has decided to deliver gifts to all these houses.<br/> Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 100</var></li> <li><var>0 ≀ a_i ≀ 1000</var></li> <li><var>a_i</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum distance to be traveled. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 3 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>The travel distance of <var>7</var> can be achieved by starting at coordinate <var>9</var> and traveling straight to coordinate <var>2</var>.<br/> It is not possible to do with a travel distance of less than <var>7</var>, and thus <var>7</var> is the minimum distance to be traveled. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 3 1 4 1 5 9 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> <p>There may be more than one house at a position. </p></section> </div> </span>
p02986
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge in this tree connects Vertex <var>a_i</var> and Vertex <var>b_i</var>, and the color and length of that edge are <var>c_i</var> and <var>d_i</var>, respectively. Here the color of each edge is represented by an integer between <var>1</var> and <var>N-1</var> (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.</p> <p>Answer the following <var>Q</var> queries:</p> <ul> <li>Query <var>j</var> (<var>1 \leq j \leq Q</var>): assuming that the length of every edge whose color is <var>x_j</var> is changed to <var>y_j</var>, find the distance between Vertex <var>u_j</var> and Vertex <var>v_j</var>. (The changes of the lengths of edges do not affect the subsequent queries.)</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>1 \leq a_i, b_i \leq N</var></li> <li><var>1 \leq c_i \leq N-1</var></li> <li><var>1 \leq d_i \leq 10^4</var></li> <li><var>1 \leq x_j \leq N-1</var></li> <li><var>1 \leq y_j \leq 10^4</var></li> <li><var>1 \leq u_j &lt; v_j \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>Q</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_{N-1}</var> <var>d_{N-1}</var> <var>x_1</var> <var>y_1</var> <var>u_1</var> <var>v_1</var> <var>:</var> <var>x_Q</var> <var>y_Q</var> <var>u_Q</var> <var>v_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 answer to Query <var>j</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 1 2 1 10 1 3 2 20 2 4 4 30 5 2 1 40 1 100 1 4 1 100 1 5 3 1000 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>130 200 60 </pre> <p>The graph in this input is as follows:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/ca75688b08f73eb63a30ce6daa54a781.png"/></p> <p>Here the edges of Color <var>1</var> are shown as solid red lines, the edge of Color <var>2</var> is shown as a bold green line, and the edge of Color <var>4</var> is shown as a blue dashed line.</p> <ul> <li>Query <var>1</var>: Assuming that the length of every edge whose color is <var>1</var> is changed to <var>100</var>, the distance between Vertex <var>1</var> and Vertex <var>4</var> is <var>100 + 30 = 130</var>.</li> <li>Query <var>2</var>: Assuming that the length of every edge whose color is <var>1</var> is changed to <var>100</var>, the distance between Vertex <var>1</var> and Vertex <var>5</var> is <var>100 + 100 = 200</var>.</li> <li>Query <var>3</var>: Assuming that the length of every edge whose color is <var>3</var> is changed to <var>1000</var> (there is no such edge), the distance between Vertex <var>3</var> and Vertex <var>4</var> is <var>20 + 10 + 30 = 60</var>. Note that the edges of Color <var>1</var> now have their original lengths.</li> </ul></section> </div> </span>
p00112
<h1>ミルクショップ</h1> <p> 鈎朚さんは䌚接地域に新しく搟りたおミルクの移動販売のお店を開きたした。その日買い求めに来るお客さんは党員持ち垰るためのボトルを持っお既にお店に䞊んでいお、それ以䞊増えないものずしたす。お客さんはそれぞれ1回だけしか泚文したせん。タンクの蛇口が䞀぀しかないので、䞀人ず぀順番に販売しなければなりたせん。そこで、鈎朚さんはなるべく䞊んでいるお客さんの埅ち時間を少なくしたいず考えおいたす。 </p> <p> お客さんの人数ずお客さんが牛乳を泚ぎきるのに芁する時間が入力ずしお䞎えられたす。あなたはお客さんの「䞀人䞀人の埅ち時間の合蚈」(以䞋「埅ち時間の合蚈」ずする)を最小にするための泚文の順序を鈎朚さんに代わっお調べ、そのずきの「埅ち時間の合蚈」を出力しお終了するプログラムを䜜成しおください。ただし、お客さんは 10,000 人以䞋で 1 人あたりに芁する時間は 60 分以䞋ずしたす。 </p> <p> 䟋えば、お客さんの人数が 5 人で、各お客さんが芁する時間が順に 2,6,4,3,9 分の堎合、そのたたの順序だず「埅ち時間の合蚈」は 37 分になりたす。次の䟋では、最初の列の順の 2 人目ず 3 人目を入れ替えおいたす。この堎合、「埅ち時間の合蚈」は 35 分になりたす。最適な順序だず 31 分で枈みたす。 </p> <table> <tr><td width="110"></td><td>埅ち時間</td><td></td></tr> <tr><td>1 人目 2 分</td><td> 0 分</td><td></td></tr> <tr><td>2 人目 6 分</td><td> 2 分</td><td></td></tr> <tr><td>3 人目 4 分</td><td> 8 分</td><td></td></tr> <tr><td>4 人目 3 分</td><td> 12 分</td><td></td></tr> <tr><td>5 人目 9 分</td><td> 15 分</td><td></td></tr> <tr><td></td><td> 37 分</td><td> ← 「埅ち時間の合蚈」</td></tr> </table> <br/> <p> 2 人目ず 3 人目を入れ替えた䟋 </p> <table> <tr><td width="110"></td><td>埅ち時間</td><td></td></tr> <tr><td>1 人目 2 分</td><td align="right"> 0 分</td><td></td></tr> <tr><td>2 人目 4 分</td><td> 2 分</td><td></td></tr> <tr><td>3 人目 6 分</td><td> 6 分</td><td></td></tr> <tr><td>4 人目 3 分</td><td> 12 分</td><td></td></tr> <tr><td>5 人目 9 分</td><td> 15 分</td><td></td></tr> <tr><td> </td><td> 35 分</td><td> ← 「埅ち時間の合蚈」</td></tr> </table> <br/> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>t<sub>1</sub></var> <var>t<sub>2</sub></var> : <var>t<sub>n</sub></var> </pre> <p> 1 行目にお客さんの人数 <var>n</var> (<var>n</var> &le; 10,000) が䞎えられたす。続く <var>n</var> 行に <var>i</var> 人目のお客さんが芁する時間を衚す敎数 <var>t<sub>i</sub></var> (0 &le; <var>t<sub>i</sub></var> &le; 60) がそれぞれ行に䞎えられたす。 </p> <p> 入力は぀の 0 を含む行で終わりたす。デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットごずに、埅ち時間の合蚈(敎数)を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 5 2 6 4 3 9 0 </pre> <H2>Output for the Sample Input</H2> <pre> 31 </pre>
p00542
<h1>科目遞択 (Selecting Subjects)</h1> <h2> 問題</h2> <p> JOI 君は物理化孊生物地孊歎史地理の 6 科目のテストを受けた それぞれのテストは 100 点満点で採点された </p> <p> JOI 君は物理化孊生物地孊の 4 科目から 3 科目を遞択し歎史地理の 2 科目から 1 科目を遞択する </p> <p> テストの合蚈点が最も高くなるように科目を遞ぶずき JOI 君の遞んだ科目のテストの合蚈点を求めよ </p> <h2> 入力</h2> <p> 入力は 6 行からなり1 行に 1 ぀ず぀敎数が曞かれおいる </p> <p> 1 行目には JOI 君の物理のテストの点数 A が曞かれおいる<br> 2 行目には JOI 君の化孊のテストの点数 B が曞かれおいる<br> 3 行目には JOI 君の生物のテストの点数 C が曞かれおいる<br> 4 行目には JOI 君の地孊のテストの点数 D が曞かれおいる<br> 5 行目には JOI 君の歎史のテストの点数 E が曞かれおいる<br> 6 行目には JOI 君の地理のテストの点数 F が曞かれおいる </p> <p> 曞かれおいる敎数 A, B, C, D, E, F はすべお 0 以䞊 100 以䞋である </p> <h2> 出力</h2> <p> JOI 君が遞んだ科目のテストの合蚈点を 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 100 34 76 42 10 0 </pre> <h3>出力䟋 1</h3> <pre> 228</pre> <h3>入力䟋 2</h3> <pre> 15 21 15 42 15 62 </pre> <h3>出力䟋 2</h3> <pre> 140</pre> <p> 入出力䟋 1 ではJOI 君が物理生物地孊歎史の 4 科目を遞ぶずきテストの合蚈点が最高になる </p> <p> 物理生物地孊歎史の点数はそれぞれ 100, 76, 42, 10 なので遞んだ科目のテストの合蚈点は 228 である </p> <p> 入出力䟋 2 ではJOI 君が化孊生物地孊地理の 4 科目を遞ぶずきテストの合蚈点が最高になる </p> <p> 化孊生物地孊地理の点数はそれぞれ 21, 15, 42, 62 なので遞んだ科目のテストの合蚈点は 140 である </p> <p> 入出力䟋 2 ではJOI 君が物理化孊地孊地理の 4 科目を遞ぶ堎合でも遞んだテストの合蚈点は 140 である </p> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2015/2016-yo/index.html">情報オリンピック日本委員䌚䜜 『第 15 回日本情報オリンピック JOI 2015/2016 予遞競技課題』</a> </p> </div>
p02085
<h1>H: Permutation Score</h1> <h2>問題文</h2> <p>束厎くんは順列が倧奜きです。今日は順列によっお定たる「サむクル森」に぀いお考えるこずにしたした。</p> <p>$1$ から $k$ たでの順列 $p = (p_1, \ldots, p_k)$ に察し「$p$ によっお定たるサむクル森」ずは、以䞋の2条件を満たすグラフ $G(p)$ を指したす:</p> <ul> <li>$G(p)$ は $k$ 頂点からなり、それぞれの頂点には $1$ から $k$ の番号が付けられおいる。</li> <li>$i=1, \ldots, k$ に぀いお、頂点 $i$ ず頂点 $p_i$ の間に蟺が匵られおいる自己ルヌプおよび倚重蟺を蚱し、必ず $k$ 本の蟺を匵る。逆に、$G(p)$にはそれら $k$ 本以倖の蟺は存圚しない。</li> </ul> <p>順列 $p$ のスコア $f(p)$ を、「$G(p)$ の連結成分の倧きさの総積」ずしお定矩したす。䟋えば $p = (2, 1, 4, 3)$ ならば $f(p) = 4$、$p = (2, 3, 1, 4)$ ならば $f(p) = 3$です。</p> <p>正敎数 $N$ が䞎えられたす。長さ $N$ の順列は $N!$ 通り考えられたすが、これら党おの順列のスコアの分散はいく぀になるか求めおください。</p> <p>党おの順列のスコアの分散ずは以䞋のように定矩されたす:</p> <ol> <li>たず、$P$ を $N!$ 個の順列党おからなる集合ずしたす。</li> <li>スコアの平均を$a = \frac{1}{N!} \sum_{p \in P} f(p)$ ずおきたす。</li> <li>この時、党おの順列のスコアの分散は $\frac{1}{N!} \sum_{p \in P} (f(p) - a)^2$ ずしお定矩されたす。</li> </ol> <p>入力の制玄䞋においお、求める倀は以䞋の条件を満たす有理数 $\frac{q}{p}$ ずしお衚せるこずが蚌明できたす:</p> <ul> <li>$p$ ず $q$ は互いに玠な非負敎数である。</li> <li>$p$ は $10^9+7$ の倍数にならず、$p \cdot r \equiv q (\bmod 10^9+7)$ なる敎数 $r$が存圚する。</li> </ul> <p>分散の倀の代わりに $r \bmod 10^9+7$を出力しおください。</p> <h2>制玄</h2> <ul> <li>入力は党お敎数</li> <li>$1 \leq N \leq 10^5$</li> </ul> <h2>入力</h2> <p>入力は以䞋の圢匏で暙準入力から䞎えられたす。</p> <pre>$N$</pre> <h2>出力</h2> <p>問題文䞭で指定された倀 $r \bmod 10^9+7$ を1行に出力しおください。</p> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre>1 </pre> <h3>出力䟋1</h3> <pre>0 </pre> <p>長さ1の順列は1぀のみであり、分散は0になりたす。</p> <h3>入力䟋2</h3> <pre>3 </pre> <h3>出力䟋2</h3> <pre>472222226 </pre> <p>分散の倀は $\frac{17}{36}$ですが、問題文䞭の指瀺に埓っお $17 \times 27777778 \bmod 10^9+7 = 472222226$ を出力しおください。</p> <h3>入力䟋3</h3> <pre>10 </pre> <h3>出力䟋3</h3> <pre>309669455 </pre>
p02590
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let’s take a prime <var>P = 200\,003</var>. You are given <var>N</var> integers <var>A_1, A_2, \ldots, A_N</var>. Find the sum of <var>((A_i \cdot A_j) \bmod P)</var> over all <var>N \cdot (N-1) / 2</var> unordered pairs of elements (<var>i &lt; j</var>).</p> <p>Please note that the sum isn't computed modulo <var>P</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200\,000</var></li> <li><var>0 \leq A_i &lt; P = 200\,003</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format.</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print one integer — the sum over <var>((A_i \cdot A_j) \bmod P)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2019 0 2020 200002 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>474287 </pre> <p>The non-zero products are:</p> <ul> <li><var>2019 \cdot 2020 \bmod P = 78320</var></li> <li><var>2019 \cdot 200002 \bmod P = 197984</var></li> <li><var>2020 \cdot 200002 \bmod P = 197983</var></li> </ul> <p>So the answer is <var>0 + 78320 + 197984 + 0 + 0 + 197983 = 474287</var>. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 1 2 2 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>600013 </pre></section> </div> </span>
p00057
<H1>領域の数</H1> <p> 無限に広い平面の䞊に、無限に長い盎線を数本匕くず、この平面はいく぀かの領域に分割されたす。たずえば、盎線を本匕くず、平面は぀の領域に分割されたす。同じ数の盎線を匕いおも、匕き方によっお埗られる領域の数は異なりたす。たずえば、2 本の盎線を平行に匕けば埗られる領域は 3 ぀になり、互いに垂盎に匕けば埗られる領域は 4 ぀になりたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_area"> </center> <br/> <p> <var>n</var> 本の盎線を匕くこずで埗られる最倧の領域の数を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットに <var>n</var> (1 &le; <var>n</var> &le; 10,000) が行に䞎えられたす。入力の最埌たで凊理しお䞋さい。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットに察しお、最倧の分割数を行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 1 3 </pre> <H2>Output for the Sample Input</H2> <pre> 2 7 </pre>
p00407
<h1>倩空の城ツルガ</h1>  <p> 倩空の城ツルガはアむヅ囜の䞊空に浮かんでいる。アむヅ囜では、倩空の城ツルガによっお日光がさえぎられる日もある。日光が圓たらない日があった堎所の䜏人には、その日数に応じお補償金を支払っおいる。アむヅ囜の補償金支払い担圓者であるあなたは、倩空の城ツルガの日ごずの䜍眮ず補償金の申請があった堎所のリストから、その日にその堎所で日光が圓たらなかったこずを確かめる必芁がある。 </p> <p> 倩空の城ツルガの堎所ずアむヅ囜の地䞊のある堎所が䞎えられたずき、その日にその堎所が圱に入っおいたかどうかを刀定するプログラムを䜜成せよ。圱の䞭に入っおいたかどうかは、ある特定の時刻で刀定するので、倩空の城ツルガや倪陜の移動に぀いおは考えなくお良い。倪陜の䜍眮は$x=y=0,z=10^6$にある倧きさのない点であり、倩空の城ツルガは$z=100$の平面にある凞倚角圢、地䞊の堎所は$z=0$にある倧きさのない点ずする。たた、ある地点ず倪陜を結ぶ盎線を倩空の城ツルガがさえぎるずき、その地点は圱に入るものずする。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $N$ $xt_1$ $yt_1$ $xt_2$ $yt_2$ : $xt_N$ $yt_N$ $Q$ $xa_1$ $ya_1$ $xa_2$ $ya_2$ : $xa_Q$ $ya_Q$ </pre> <p> 行目に倩空の城ツルガの領域を衚す点の数$N$ ($3 \leq N \leq 3 \times 10^4$)が䞎えられる。続く$N$行に、領域を構成する頂点の座暙$xt_i$,$yt_i$ ($-10^8 \leq xt_i,yt_i \leq 10^8$)が領域の重心の呚りに反時蚈回りに敎数で䞎えられる。ただし、同じ座暙をも぀頂点は䞎えられない$i \ne j$に぀いお、$xt_i \ne xt_j$ たたは $yt_i \ne yt_j$。たた、領域の面積は0より倧きいず考えお良い。続く行に、補償金の申請があった堎所の数$Q$ ($1 \leq Q \leq 6 \times 10^4$)が䞎えられる。続く$Q$行に、補償金の申請があった堎所の座暙$xa_i$,$ya_i$ ($-10^8 \leq xa_i,ya_i \leq 10^8$)が敎数で䞎えられる。ただし、補償金の申請があった堎所の座暙は、倩空の城ツルガの圱の茪郭線から距離$10^{-3}$以䞊離れおいるず考えお良い。 </p> <h2>出力</h2> <p> 補償金の申請があった各堎所に぀いお、圱に入っおいたら「1」、入っおいなかったら「0」を行に出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 6 0 0 4 0 6 3 5 5 1 5 0 3 5 2 2 6 6 3 1 5 1 -1 -1 </pre> <h3>出力䟋</h3> <pre> 1 0 1 0 0 </pre> <h3>入力䟋</h3> <pre> 4 100000 100000 101000 100000 101000 101000 100000 101000 2 100005 100005 101005 101005 </pre> <h3>出力䟋</h3> <pre> 0 1 </pre>
p03381
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>When <var>l</var> is an odd number, the median of <var>l</var> numbers <var>a_1, a_2, ..., a_l</var> is the <var>(\frac{l+1}{2})</var>-th largest value among <var>a_1, a_2, ..., a_l</var>.</p> <p>You are given <var>N</var> numbers <var>X_1, X_2, ..., X_N</var>, where <var>N</var> is an even number. For each <var>i = 1, 2, ..., N</var>, let the median of <var>X_1, X_2, ..., X_N</var> excluding <var>X_i</var>, that is, the median of <var>X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N</var> be <var>B_i</var>.</p> <p>Find <var>B_i</var> for each <var>i = 1, 2, ..., N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200000</var></li> <li><var>N</var> is even.</li> <li><var>1 \leq X_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>X_1</var> <var>X_2</var> ... <var>X_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain <var>B_i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 3 3 4 </pre> <ul> <li>Since the median of <var>X_2, X_3, X_4</var> is <var>4</var>, <var>B_1 = 4</var>.</li> <li>Since the median of <var>X_1, X_3, X_4</var> is <var>3</var>, <var>B_2 = 3</var>.</li> <li>Since the median of <var>X_1, X_2, X_4</var> is <var>3</var>, <var>B_3 = 3</var>.</li> <li>Since the median of <var>X_1, X_2, X_3</var> is <var>4</var>, <var>B_4 = 4</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 5 5 4 4 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 4 4 4 4 4 </pre></section> </div> </span>
p01646
<h2>Problem Statement</h2> <p> We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary into a computer. </p> <p> How the words are ordered in the dictionary, especially whether they are ordered lexicographically, is an interesting topic to many people. As a good programmer, you are requested to write a program to judge whether we can consider the words to be sorted in a lexicographical order. </p> <p> Note: In a lexicographical order, a word always precedes other words it is a prefix of. For example, <code>ab</code> precedes <code>abc</code>, <code>abde</code>, and so on. </p> <h2>Input</h2> <p> The input consists of multiple datasets. Each dataset is formatted as follows: </p> <pre> <var>n</var> <var>string_1</var> ... <var>string_n</var> </pre> <p> Each dataset consists of <var>n+1</var> lines. The first line of each dataset contains an integer that indicates <var>n</var> (<var>1 \leq n \leq 500</var>). The <var>i</var>-th line of the following <var>n</var> lines contains <var>string_i</var>, which consists of up to 10 English lowercase letters. </p> <p> The end of the input is <code>0</code>, and this should not be processed. </p> <h2>Output</h2> <p> Print either <code>yes</code> or <code>no</code> in a line for each dataset, in the order of the input. If all words in the dataset can be considered to be ordered lexicographically, print <code>yes</code>. Otherwise, print <code>no</code>. </p> <h2>Sample Input</h2> <pre> 4 cba cab b a 3 bca ab a 5 abc acb b c c 5 abc acb c b b 0 </pre> <h2>Output for the Sample Input</h2> <pre> yes no yes no </pre>
p02969
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>It is known that the area of a regular dodecagon inscribed in a circle of radius <var>a</var> is <var>3a^2</var>.</p> <p>Given an integer <var>r</var>, find the area of a regular dodecagon inscribed in a circle of radius <var>r</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq r \leq 100</var></li> <li><var>r</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>r</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the area of the regular dodecagon.</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>48 </pre> <p>The area of the regular dodecagon is <var>3 \times 4^2 = 48</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>675 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>80 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>19200 </pre></section> </div> </span>
p00954
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem I Skinny Polygon </h2> <p> You are asked to find a polygon that satisfies all the following conditions, given two integers, $x_{bb}$ and $y_{bb}$. </p> <ul> <li> The number of vertices is either 3 or 4.</li> <li> Edges of the polygon do not intersect nor overlap with other edges, i.e., they do not share any points with other edges except for their endpoints.</li> <li> The $x$- and $y$-coordinates of each vertex are integers. </li> <li> The $x$-coordinate of each vertex is between 0 and $x_{bb}$, inclusive. Similarly, the $y$-coordinate is between 0 and $y_{bb}$, inclusive.</li> <li> At least one vertex has its $x$-coordinate 0.</li> <li> At least one vertex has its $x$-coordinate $x_{bb}$.</li> <li> At least one vertex has its $y$-coordinate 0.</li> <li> At least one vertex has its $y$-coordinate $y_{bb}$.</li> <li> <b>The area of the polygon does not exceed 25000.</b></li> </ul> <p> The polygon may be non-convex. </p> <h3>Input</h3> <p> The input consists of multiple test cases. The first line of the input contains an integer $n$, which is the number of the test cases ($1 \leq n \leq 10^5$). Each of the following $n$ lines contains a test case formatted as follows.<br/> <br/> $x_{bb}$ $y_{bb}$<br/> <br/> $x_{bb}$ and $y_{bb}$ ($2 \leq x_{bb} \leq 10^9, 2 \leq y_{bb} \leq 10^9$) are integers stated above. </p> <h3>Output</h3> <p> For each test case, output description of one polygon satisfying the conditions stated above, in the following format.<br/> <br/> $v$<br/> $x_1$ $y_1$<br/> . <br/> . <br/> . <br/> $x_v$ $y_v$<br/> </p> <p> Here, $v$ is the number of vertices, and each pair of $x_i$ and $y_i$ gives the coordinates of the $i$-th vertex, $(x_i, y_i)$. The first vertex $(x_1, y_1)$ can be chosen arbitrarily, and the rest should be listed either in clockwise or in counterclockwise order. </p> <p> When more than one polygon satisfies the conditions, any one of them is acceptable. You can prove that, with the input values ranging as stated above, there is at least one polygon satisfying the conditions. </p> <h3>Sample Input 1</h3> <pre>2 5 6 1000000000 2</pre> <h3>Sample Output 1</h3> <pre>4 5 6 0 6 0 0 5 0 3 1000000000 0 0 2 999999999 0</pre>
p04014
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For integers <var>b (b \geq 2)</var> and <var>n (n \geq 1)</var>, let the function <var>f(b,n)</var> be defined as follows:</p> <ul> <li><var>f(b,n) = n</var>, when <var>n &lt; b</var></li> <li><var>f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b)</var>, when <var>n \geq b</var></li> </ul> <p>Here, <var>{\rm floor}(n / b)</var> denotes the largest integer not exceeding <var>n / b</var>, and <var>n \ {\rm mod} \ b</var> denotes the remainder of <var>n</var> divided by <var>b</var>.</p> <p>Less formally, <var>f(b,n)</var> is equal to the sum of the digits of <var>n</var> written in base <var>b</var>. For example, the following hold:</p> <ul> <li><var>f(10,\,87654)=8+7+6+5+4=30</var></li> <li><var>f(100,\,87654)=8+76+54=138</var></li> </ul> <p>You are given integers <var>n</var> and <var>s</var>. Determine if there exists an integer <var>b (b \geq 2)</var> such that <var>f(b,n)=s</var>. If the answer is positive, also find the smallest such <var>b</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq n \leq 10^{11}</var></li> <li><var>1 \leq s \leq 10^{11}</var></li> <li><var>n,\,s</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>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists an integer <var>b (b \geq 2)</var> such that <var>f(b,n)=s</var>, print the smallest such <var>b</var>. If such <var>b</var> does not exist, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>87654 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>87654 138 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>100 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>87654 45678 </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>31415926535 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>31415926535 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>1 31415926535 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>-1 </pre></section> </div> </span>
p01216
<H1><font color="#000">Problem A:</font> Election</H1> <p> Giselle has just made a vote for a national election. In her country, members of the legislature are elected by a system called mixed member proportional representation (MMP). Basically, half the members are elected from constituencies, and the other half are elected from party lists by proportional representation. Each voter has two votes, one for a constituency representative and one for a party. </p> <p> In each constituency, the representative is chosen by a single-winner voting system called the first-past- the-post. This system is very simple: the candidate who earns the highest number of votes wins the seat. There are constituencies equal to half the number of seats, and they are determined in accordance with geographical areas. </p> <p> Each party is allocated the seats according to the percentage of votes cast for that party. Only parties that have either at least five percent of the total party votes or at least three constituency seats are eligible for the seats; the parties that satisfy neither of these prerequisites are excluded on the following procedure. The number of seats for each eligible party is determined based on the value given by: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_election"> </center> <p> Note that the multiplier in the above formula is the number of <i>overall</i> seats, not party-list seats (i.e. not half the members). Each party receives the seats equal to the integer part of this value. There usually remain some seats, and they are allocated to the parties in decreasing order of the fraction parts, where each party receive at most one extra seat. If two or more parties have the same fraction parts, the party that gained a greater number of votes gets higher preference. </p> <p> The number of seats allocated by the above procedure counts both the constituency seats and the party- list seats. Each party is therefore entitled to add members from the list just as many as the number of its allocated seats minus the number of its constituency seats. Those members are chosen in the order predetermined by the party. If some candidates in the party list already have the seats for constituency representatives (this happens because each constituency candidate is allowed to also be included in the list), they are not counted and the next candidates down are added instead. </p> <p> The candidates who won in constituencies never forfeit their seats. It sometimes happens that the number of constituencies where a party won exceeds the number of seats allocated for the party vote. In this case, <i>all</i> winners in constituencies receive the seats in the legislature, although no more members will be elected from the party list. The same still applies to the candidates in the parties ineligible to be allocated the seats. Note that this raises the total number of seats. The seats added for this reason are called <i>overhang seats</i>. <p> <p> Now, let us take an example. Suppose three parties A, B, and C are competing for eight seats, where the party A has earned one constituency seat and 9,000 party votes, the party B one and 8,000, and the party C two and 3,000. The total number of party votes is 9000 + 8000 + 3000 = 20000, thus the five-percent threshold is 20000 × (5/100) = 1000. From this threshold, all parties are eligible to be allocated the seats. The formula gives (8 &times; 9000)/20000 = 3.6, (8 &times; 8000)/20000 = 3.2, and (8 &times; 3000)/20000 = 1.2, so the parties A, B, and C receive three seats, three, and one respectively. There is one remaining seat, and it goes to the party A for the largest fraction part 0.6 ( = 3.6 − 3). In conclusion, the party A gains four seats in total, and since this party won one constituency seat, there are three more members to be chosen from the party A’s list. Similarly, there are two more members from the party B’s list. On the other hand, the party C receives only one seat despite winning in two constituencies. So no members will be chosen from the party C’s list and one overhang seat occurs. The total number of elected members therefore will be nine. This example corresponds to the first case of the sample input and output. </p> <p> You are required to write a program that determines which candidates win the seats. </P> <H2>Input</H2> <p> The input consists of multiple data sets. Each data set has the following format: </p> <pre> <i>N M</i> <i>Party</i><sub>1</sub> <i>Party</i><sub>2</sub> ... <i>Party</i><sub><i>M</i></sub> <i>Constituency</i><sub>1</sub> <i>Constituency</i><sub>2</sub> ... <i>Constituency</i><sub><i>N</i>/2</sub> </pre> <p> <i>N</i> is a positive even integer that represents the number of seats. <i>M</i> is a positive integer that represents the number of parties. <i>Party<sub>i</sub></i> is the description of the <i>i</i>-th party. <i>Constituency<sub>i</sub></i> is the description of the <i>i</i>-th constituency. </p> <p> Each party description is given in the following format: </p> <pre> <i>PartyName C V</i> <i>Name</i><sub>1</sub> <i>Name</i><sub>2</sub> ... <i>Name</i><sub><i>C</i></sub> </pre> <p> <i>PartyName</i> is the name of the party. <i>C</i> is a positive integer that represents the number of candidates in the party list. <i>V</i> is a non-negative integer that represents the number of votes cast for that party. <i>Name<sub>i</sub></i> is the name of the candidate with the <i>i</i>-th highest priority in the party list. </p> <p> Each constituency description is given in the following format: </p> <pre> <i>C</i> <i>Name</i><sub>1</sub> <i>Party</i><sub>1</sub> <i>V</i><sub>1</sub> <i>Name</i><sub>2</sub> <i>Party</i><sub>2</sub> <i>V</i><sub>2</sub> ... <i>Name</i><sub><i>C</i></sub> <i>Party</i><sub><i>C</i></sub> <i>V</i><sub><i>C</i></sub> </pre> <p> <i>C</i> is a positive integer, equal to or greater than two, that represents the number of candidates in the constituency. <i>Name<sub>i</sub></i> is the name of the <i>i</i>-th candidate in the constituency. <i>Party<sub>i</sub></i> is the name of the party that the <i>i</i>-th candidate belongs. <i>V<sub>i</sub></i> is a non-negative integer that represents the number of votes cast for the <i>i</i>-th candidate. </p> <p> The input is terminated with a line that contains two zeros. This line should not be processed. </p> <p> You may assume all the followings: </p> <ul> <li> The name of each party is a string up to ten characters that begins with an uppercase character and consists of only uppercase and numeric characters. The name of each candidate is a string up to twenty characters that begins with a lowercase character and consists of only lowercase and numeric characters. No multiple parties or candidates have the same name.</li> <li> The number of parties, the number of seats, and the total number of different candidates do not exceed 20, 200, and 1,000 respectively. Neither the total number of party votes nor the total number of votes in each constituency exceeds 10,000,000.</li> <li> No two or more parties receive the same number of party votes. Also, in each constituency, no two or more candidates receive the same number of constituency votes.</li> <li> Each party list contains enough candidates, that is, the party can always choose the required number of candidates from the list.</li> <li> Every candidate belongs to just one of the parties. No candidate is allowed to compete in more than one constituency. Note that, however, each candidate may appear up to twice in a data set, one in a party list and one in a constituency description.</li> <li> The number of data sets in the input does not exceed fifty.</li> </ul> <H2>Output</H2> <p> For each data set, print names of all elected persons, one name per line, in lexicographical order according to the ASCII code. Print an empty line between two consecutive data sets. </p> <H2>Sample Input</H2> <pre> 8 3 A 6 9000 a1 a2 a3 a4 a5 a6 B 6 8000 b1 b2 b3 b4 b5 b6 C 4 3000 c1 c2 c3 c4 2 a7 A 2000 b2 B 4000 3 a8 A 1500 c3 C 500 b1 B 1000 2 c2 C 2328 a3 A 2327 2 b5 B 2345 c5 C 4000 43 A 3 2500 a1 a2 a3 B 3 1500 b1 b2 b3 C 1 150 c1 2 a4 A 1500 b4 B 1000 2 a5 A 700 b5 B 800 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> a1 a2 a3 a8 b1 b2 b3 c2 c5 a1 a2 a4 b5 </pre>
p03801
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke loves constructing integer sequences.</p> <p>There are <var>N</var> piles of stones, numbered <var>1</var> through <var>N</var>. The pile numbered <var>i</var> consists of <var>a_i</var> stones.</p> <p>Snuke will construct an integer sequence <var>s</var> of length <var>Σa_i</var>, as follows:</p> <ol> <li>Among the piles with the largest number of stones remaining, let <var>x</var> be the index of the pile with the smallest index. Append <var>x</var> to the end of <var>s</var>.</li> <li>Select a pile with one or more stones remaining, and remove a stone from that pile.</li> <li>If there is a pile with one or more stones remaining, go back to step 1. Otherwise, terminate the process.</li> </ol> <p>We are interested in the lexicographically smallest sequence that can be constructed. For each of the integers <var>1,2,3,...,N</var>, how many times does it occur in the lexicographically smallest sequence?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^{5}</var></li> <li><var>1 ≀ a_i ≀ 10^{9}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>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 <var>N</var> lines. The <var>i</var>-th line should contain the number of the occurrences of the integer <var>i</var> in the lexicographically smallest sequence that can be constructed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 </pre> <p>The lexicographically smallest sequence is constructed as follows:</p> <ul> <li>Since the pile with the largest number of stones remaining is pile <var>2</var>, append <var>2</var> to the end of <var>s</var>. Then, remove a stone from pile <var>2</var>.</li> <li>Since the piles with the largest number of stones remaining are pile <var>1</var> and <var>2</var>, append <var>1</var> to the end of <var>s</var> (we take the smallest index). Then, remove a stone from pile <var>2</var>.</li> <li>Since the pile with the largest number of stones remaining is pile <var>1</var>, append <var>1</var> to the end of <var>s</var>. Then, remove a stone from pile <var>1</var>.</li> </ul> <p>The resulting sequence is <var>(2,1,1)</var>. In this sequence, <var>1</var> occurs twice, and <var>2</var> occurs once.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 1 2 1 3 2 4 2 5 8 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 7 0 4 0 3 0 2 3 0 </pre></section> </div> </span>
p02713
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find <var>\displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}</var>.</p> <p>Here <var>\gcd(a,b,c)</var> denotes the greatest common divisor of <var>a</var>, <var>b</var>, and <var>c</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq 200</var></li> <li><var>K</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the value of <var>\displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p><var>\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)</var> <var>+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)</var> <var>=1+1+1+1+1+1+1+2=9</var></p> <p>Thus, the answer is <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10813692 </pre></section> </div> </span>
p01996
<h1>A: テスト</h1> <h2>問題</h2> <p> $N$ 個の垭が䞀盎線䞊に䞊んでいる教宀で $M$ 人の生埒がテストを受けるこずになった。 垭には、前から $1 \dots N$ の番号が振られおおり、垭 $1$ ぀に぀き生埒 $1$ 人が座れる。 </p> <p> いた、 各生埒は、 $A_1, \dots, A_M$ 番の垭に座っおいる。 </p> <p> テストを始めるためには、以䞋の条件を満たさなければならない。 <ul> <li> $1 \dots M$ 番のどの垭にも生埒が座っおいる。</li> </ul> </p> <p> そこで、条件を満たすたで次の操䜜を繰り返すこずにした。 <ul> <li>最も埌ろに座っおいる生埒を移動させ、空いおいる垭のうち最も前に座らせる。</li> </ul> </p> <p> 条件を満たすために必芁な操䜜回数を求めよ。 </p> <h2>制玄</h2> <ul> <li>入力倀は党お敎数である。</li> <li>$1 \leq N \leq 1000$</li> <li>$1 \leq M \leq N$</li> <li>$1 \leq A_i \leq N$</li> <li>$1 \leq i < j \leq M$ ならば $A_i < A_j$</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <p> $N\ M$<br> $A_1 \dots A_M$<br> </p> <h2>出力</h2> <p>条件を満たすために必芁な操䜜回数を出力せよ。たた、末尟に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 6 4 1 4 5 6 </pre> <h3>サンプル出力 1</h3> <pre> 2 </pre> <h3>サンプル入力 2</h3> <pre> 10 3 1 2 3 </pre> <h3>サンプル出力 2</h3> <pre> 0 </pre>
p00684
<H1>Calculation of Expressions</H1> <P>Write a program to calculate values of arithmetic expressions which may involve complex numbers. Details of the expressions are described below.</P> <P>In this problem, basic elements of expressions are non-negative integer numbers and the special symbol &quot;<TT>i</TT>&quot;. Integer numbers are sequences of digits of arbitrary length and are in decimal notation. &quot;<TT>i</TT>&quot; denotes the unit imaginary number <I>i</I>, i.e. <I>i</I><SUP> 2</SUP> = -1.</P> <P>Operators appearing in expressions are <TT>+</TT> (addition), <TT>-</TT> (subtraction), and <TT>*</TT> (multiplication). Division is excluded from the repertoire of the operators. All three operators are only used as binary operators. Unary plus and minus operators (e.g., <TT>-100</TT>) are also excluded from the repertoire. Note that the multiplication symbol <TT>*</TT> may not be omitted in any case. For example, the expression 1+3<I>i</I> in mathematics should be written as <TT>1+3*i</TT>.</P> <P>Usual formation rules of arithmetic expressions apply. Namely, (1) The operator <TT>*</TT> binds its operands stronger than the operators <TT>+</TT> and <TT>-</TT>. (2) The operators <TT>+</TT> and <TT>-</TT> have the same strength in operand binding. (3) Two operators of the same strength bind from left to right. (4) Parentheses are used to designate specific order of binding.</P> <P>The consequence of these rules can easily be understood from the following examples.</P> <BLOCKQUOTE> <BLOCKQUOTE> <P>(1) <TT>3+4*5</TT> is <TT>3+(4*5)</TT>, not <TT>(3+4)*5</TT><BR> (2) <TT>5-6+7</TT> is <TT>(5-6)+7</TT>, not <TT>5-(6+7)</TT><BR> (3) <TT>1+2+3</TT> is <TT>(1+2)+3</TT>, not <TT>1+(2+3)<BR> </TT></P> </BLOCKQUOTE> </BLOCKQUOTE> <P>Your program should successively read expressions, calculate them and print their results. Overflow should be detected.</P> <P>Whenever an abnormal value is yielded as a result of applying an operator appearing in the given expression, your program should report that the calculation failed due to overflow. By &quot;an abnormal value&quot;, we mean a value whose real part or imaginary part is greater than 10000 or less than -10000. Here are examples:</P> <P ALIGN=CENTER><TABLE BORDER="1" CELLSPACING="2" CELLPADDING="0"> <TR> <TD WIDTH="50%"><TT>10000+1+(0-10)</TT></TD> <TD WIDTH="50%">overflow, not 9991</TD></TR> <TR> <TD WIDTH="50%"><TT>(10*i+100)*(101+20*i)</TT></TD> <TD WIDTH="50%">9900+3010<I>i </I>, not overflow</TD></TR> <TR> <TD WIDTH="50%"><TT>4000000-4000000</TT></TD> <TD WIDTH="50%">overflow, not 0</TD></TR> </TABLE> </P> <P>Note that the law of associativity does not necessarily hold in this problem. For example, in the first example, overflow is detected by interpreting the expression as <TT>(10000+1)+(0-10)</TT> following the binding rules, whereas overflow could not be detected if you interpreted it as <TT>10000+(1+(0-10))</TT>. Moreover, overflow detection should take place for resulting value of each operation.</P> <P>In the second example, a value which exceeds 10000 appears in the calculation process of one multiplication if you use the mathematical rule</P> <BLOCKQUOTE> <P>(<I>a</I>+<I>b i</I>)(<I>c</I>+<I>d</I> <I>i</I>)=(<I>ac</I>-<I>bd</I>)+(<I>ad</I>+<I>bc</I>)<I>i </I>.</P> </BLOCKQUOTE> <P>But the yielded result 9900+3010<I>i </I>does not contain any number which exceeds 10000 and, therefore, overflow should not be reported.</P> <P></P> <H2>Input</H2> <P>A sequence of lines each of which contains an expression is given as input. Each line consists of less than 100 characters and does not contain any blank spaces. You may assume that all expressions given in the sequence are syntactically correct.</P> <H2>Output</H2> <P>Your program should produce output for each expression line by line. If overflow is detected, output should be a character string &quot;<TT>overflow</TT>&quot;. Otherwise, output should be the resulting value of calculation in the following fashion.</P> <UL> <LI><TT>0</TT> , if the result is 0+0<I>i</I>. <LI><TT>-123</TT> , if the result is -123+0<I>i</I>. <LI><TT>45i</TT> , if the result is 0+45<I>i</I>. <LI><TT>3+1i</TT> , if the result is 3+<I>i</I>. <LI><TT>123-45i</TT> , if the result is 123-45<I>i</I>. </UL> <P>Output should not contain any blanks, surplus <TT>0</TT>, <TT>+</TT>, or <TT>-</TT>.</P> <H2>Sample Input</H2> <pre> (1-10*i)+00007+(3+10*i) 3+4*i*(4+10*i) (102+10*i)*(99+10*i) 2*i+3+9999*i+4 </pre> <H2>Output for the Sample Input</H2> <pre> 11 -37+16i 9998+2010i overflow </pre>
p02343
<H1>Disjoint Set</H1> <p> Write a program which manipulates a disjoint set <var>S = {S<sub>1</sub>, S<sub>2</sub>, . . . , S<sub>k</sub>}</var>. </p> <p> First of all, the program should read an integer <var>n</var>, then make a disjoint set where each element consists of 0, 1, ... <var>n&minus;1</var> respectively. </p> <p> Next, the program should read an integer <var>q</var> and manipulate the set for <var>q</var> queries. There are two kinds of queries for different operations: </p> <ul> <li><var>unite(x, y)</var>: unites sets that contain <var>x</var> and <var>y</var>, say <var>S<sub>x</sub></var> and <var>S<sub>y</sub></var>, into a new set. <li><var>same(x, y)</var>: determine whether <var>x</var> and <var>y</var> are in the same set.</li> </ul> <H2>Input</H2> <pre> <var>n</var> <var>q</var> <var>com<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>com<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> ... <var>com<sub>q</sub></var> <var>x<sub>q</sub></var> <var>y<sub>q</sub></var> </pre> <p> In the first line, <var>n</var> and <var>q</var> are given. Then, <var>q</var> queries are given where <var>com</var> represents the type of queries. '0' denotes <var>unite</var> and '1' denotes <var>same</var> operation. </p> <H2>Output</H2> <p> For each <var>same</var> operation, print <span>1</span> if <var>x</var> and <var>y</var> are in the same set, otherwise <span>0<span>, in a line. </p> <H2>Constraints</H2> <ul> <li> <var>1 &le; n &le; 10000 </li> <li> <var>1 &le; q &le; 100000 </li> <li> <var>x &ne; y</var> </li> </ul> <H2>Sample Input</H2> <pre> 5 12 0 1 4 0 2 3 1 1 2 1 3 4 1 1 4 1 3 2 0 1 3 1 2 4 1 3 0 0 0 4 1 0 2 1 3 0 </pre> <H2>Sample Output</H2> <pre> 0 0 1 1 1 0 1 1 </pre>
p03102
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> pieces of source code. The characteristics of the <var>i</var>-th code is represented by <var>M</var> integers <var>A_{i1}, A_{i2}, ..., A_{iM}</var>.</p> <p>Additionally, you are given integers <var>B_1, B_2, ..., B_M</var> and <var>C</var>.</p> <p>The <var>i</var>-th code correctly solves this problem if and only if <var>A_{i1} B_1 + A_{i2} B_2 + ... + A_{iM} B_M + C &gt; 0</var>.</p> <p>Among the <var>N</var> codes, find the number of codes that correctly solve 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, M \leq 20</var></li> <li><var>-100 \leq A_{ij} \leq 100</var></li> <li><var>-100 \leq B_i \leq 100</var></li> <li><var>-100 \leq C \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>C</var> <var>B_1</var> <var>B_2</var> <var>...</var> <var>B_M</var> <var>A_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1M}</var> <var>A_{21}</var> <var>A_{22}</var> <var>...</var> <var>A_{2M}</var> <var>\vdots</var> <var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NM}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of codes among the given <var>N</var> codes that correctly solve this problem.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 -10 1 2 3 3 2 1 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Only the second code correctly solves this problem, as follows:</p> <ul> <li>Since <var>3 \times 1 + 2 \times 2 + 1 \times 3 + (-10) = 0 \leq 0</var>, the first code does not solve this problem.</li> <li><var>1 \times 1 + 2 \times 2 + 2 \times 3 + (-10) = 1 &gt; 0</var>, the second code solves this problem.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 -4 -2 5 100 41 100 40 -3 0 -6 -2 18 -13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 3 0 100 -100 0 0 100 100 100 100 100 -100 100 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>All of them are <em>Wrong Answer</em>. Except yours.</p></section> </div> </span>
p01095
<h3>Bamboo Blossoms</h3> <p> The bamboos live for decades, and at the end of their lives, they flower to make their seeds. Dr. ACM, a biologist, was fascinated by the bamboos in blossom in his travel to Tsukuba. He liked the flower so much that he was tempted to make a garden where the bamboos bloom annually. Dr. ACM started research of improving breed of the bamboos, and finally, he established a method to develop bamboo breeds with controlled lifetimes. With this method, he can develop bamboo breeds that flower after arbitrarily specified years. </p> <p> Let us call bamboos that flower <i>k</i> years after sowing "<i>k</i>-year-bamboos." <i>k</i> years after being sowed, <i>k</i>-year-bamboos make their seeds and then die, hence their next generation flowers after another <i>k</i> years. In this way, if he sows seeds of <i>k</i>-year-bamboos, he can see bamboo blossoms every <i>k</i> years. For example, assuming that he sows seeds of 15-year-bamboos, he can see bamboo blossoms every 15 years; 15 years, 30 years, 45 years, and so on, after sowing. </p> <p> Dr. ACM asked you for designing his garden. His garden is partitioned into blocks, in each of which only a single breed of bamboo can grow. Dr. ACM requested you to decide which breeds of bamboos should he sow in the blocks in order to see bamboo blossoms in at least one block for as many years as possible. </p> <p> You immediately suggested to sow seeds of one-year-bamboos in all blocks. Dr. ACM, however, said that it was difficult to develop a bamboo breed with short lifetime, and would like a plan using only those breeds with long lifetimes. He also said that, although he could wait for some years until he would see the first bloom, he would like to see it in every following year. Then, you suggested a plan to sow seeds of 10-year-bamboos, for example, in different blocks each year, that is, to sow in a block this year and in another block next year, and so on, for 10 years. Following this plan, he could see bamboo blossoms in one block every year except for the first 10 years. Dr. ACM objected again saying he had determined to sow in all blocks this year. </p> <p> After all, you made up your mind to make a sowing plan where the bamboos bloom in at least one block for as many consecutive years as possible after the first <i>m</i> years (including this year) under the following conditions: <ul> <li>the plan should use only those bamboo breeds whose lifetimes are <i>m</i> years or longer, and <li>Dr. ACM should sow the seeds in all the blocks only this year. </ul> </p> <h3>Input</h3> <p> The input consists of at most 50 datasets, each in the following format. </p> <p> <i>m</i> <i>n</i><br> </p> <p> An integer <i>m</i> (2 &le; <i>m</i> &le; 100) represents the lifetime (in years) of the bamboos with the shortest lifetime that Dr. ACM can use for gardening. An integer <i>n</i> (1 &le; <i>n</i> &le; 500,000) represents the number of blocks. </p> <p> The end of the input is indicated by a line containing two zeros. </p> <h3>Output</h3> <p> No matter how good your plan is, a "dull-year" would eventually come, in which the bamboos do not flower in any block. For each dataset, output in a line an integer meaning how many years from now the first dull-year comes after the first <i>m</i> years. </p> <p> Note that the input of <i>m</i> = 2 and <i>n</i> = 500,000 (the last dataset of the Sample Input) gives the largest answer. </p> <h3>Sample Input</h3> <pre> 3 1 3 4 10 20 100 50 2 500000 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 4 11 47 150 7368791 </pre>
p03552
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a deck consisting of <var>N</var> cards. Each card has an integer written on it. The integer on the <var>i</var>-th card from the top is <var>a_i</var>.</p> <p>Two people X and Y will play a game using this deck. Initially, X has a card with <var>Z</var> written on it in his hand, and Y has a card with <var>W</var> written on it in his hand. Then, starting from X, they will alternately perform the following action:</p> <ul> <li>Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.</li> </ul> <p>The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.</p> <p>X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 \leq N \leq 2000</var></li> <li><var>1 \leq Z, W, a_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Z</var> <var>W</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 score.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 100 100 10 1000 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>900 </pre> <p>If X draws two cards first, Y will draw the last card, and the score will be <var>|1000 - 100| = 900</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 100 1000 10 100 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>900 </pre> <p>If X draws all the cards first, the score will be <var>|1000 - 100| = 900</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 1 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>999999999 </pre></section> </div> </span>
p03047
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has <var>N</var> integers: <var>1,2,\ldots,N</var>. He will choose <var>K</var> of them and give those to Takahashi.</p> <p>How many ways are there to choose <var>K</var> consecutive integers?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq K \leq N \leq 50</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</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 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two ways to choose two consecutive integers: <var>(1,2)</var> and <var>(2,3)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>13 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>11 </pre></section> </div> </span>
p01580
<H1><font color="#000">Problem K:</font> Up Above the World So High</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 in a spaceship billions of light-years away from the Earth. Their telescopes are similar to ours with circular sight field. It can be rotated freely, that is, the sight vector can take an arbitrary value. </p> <p> Given a set of positions of stars and the spec of a telescope, your task is to determine the maximum number of stars that can be seen through the telescope at a time. </p> <H2>Input</H2> <p> The first line of a test case contains a positive integer <i>N</i> not exceeding 100, meaning the number of stars. Each of the <i>N</i> lines following it contains three integers, <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 that -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>&psi;</i> (0 &lt; <i>&psi;</i> &lt; 90), which represents the angular radius, in degrees, of the sight field of the telescope. The telescope is at the origin of the coordinate system (0, 0, 0). </p> <p> You may assume that change of the angular radius <i>&psi;</i> by less than 0.01 degrees does not affect the answer, and that &ang;POQ is greater than 0.01 degrees for any pair of distinct stars P and Q and the origin O. </p> <H2>Output</H2> <p> One line containing an integer meaning the maximum number of stars observable through the telescope should be output. No other characters should be contained in the output. </p> <H2>Sample Input 1</H2> <pre> 2 1 0 0 0 1 0 40 </pre> <H2>Output for the Sample Input 1</H2> <pre> 1 </pre> <br/> <H2>Sample Input 2</H2> <pre> 2 1 0 0 0 1 0 50 </pre> <H2>Output for the Sample Input 2</H2> <pre> 2 </pre> <h2>Note</h2> <p> This problem statement is taken from "How I Wonder What You Are!" in ACM-ICPC Asia Regional Contest 2006, Yokohoma, with small but substantial changes. </p>
p03417
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive <var>N</var> rows and <var>M</var> columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.</p> <p>We will perform the following operation once for each square contains a card:</p> <ul> <li>For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.</li> </ul> <p>It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,M \leq 10^9</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of cards that face down after all the operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> <p>We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>After all the operations, all cards except at both ends face down.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314 1592 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>496080 </pre></section> </div> </span>
p03944
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a rectangle in the <var>xy</var>-plane, with its lower left corner at <var>(0, 0)</var> and its upper right corner at <var>(W, H)</var>. Each of its sides is parallel to the <var>x</var>-axis or <var>y</var>-axis. Initially, the whole region within the rectangle is painted white.</p> <p>Snuke plotted <var>N</var> points into the rectangle. The coordinate of the <var>i</var>-th (<var>1 ≩ i ≩ N</var>) point was <var>(x_i, y_i)</var>.</p> <p>Then, he created an integer sequence <var>a</var> of length <var>N</var>, and for each <var>1 ≩ i ≩ N</var>, he painted some region within the rectangle black, as follows:</p> <ul> <li>If <var>a_i = 1</var>, he painted the region satisfying <var>x &lt; x_i</var> within the rectangle.</li> <li>If <var>a_i = 2</var>, he painted the region satisfying <var>x &gt; x_i</var> within the rectangle.</li> <li>If <var>a_i = 3</var>, he painted the region satisfying <var>y &lt; y_i</var> within the rectangle.</li> <li>If <var>a_i = 4</var>, he painted the region satisfying <var>y &gt; y_i</var> within the rectangle.</li> </ul> <p>Find the area of the white region within the rectangle after he finished painting.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ W, H ≩ 100</var></li> <li><var>1 ≩ N ≩ 100</var></li> <li><var>0 ≩ x_i ≩ W</var> (<var>1 ≩ i ≩ N</var>)</li> <li><var>0 ≩ y_i ≩ H</var> (<var>1 ≩ i ≩ N</var>)</li> <li><var>W</var>, <var>H</var> (21:32, added), <var>x_i</var> and <var>y_i</var> are integers.</li> <li><var>a_i</var> (<var>1 ≩ i ≩ N</var>) is <var>1, 2, 3</var> or <var>4</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>W</var> <var>H</var> <var>N</var> <var>x_1</var> <var>y_1</var> <var>a_1</var> <var>x_2</var> <var>y_2</var> <var>a_2</var> <var>:</var> <var>x_N</var> <var>y_N</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the area of the white region within the rectangle after Snuke finished painting.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 2 2 1 1 3 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>The figure below shows the rectangle before Snuke starts painting.</p> <div style="text-align: center;"> <img alt="e19e673abcd0882783f635cce9d2f94d.png" src="https://atcoder.jp/img/abc047/e19e673abcd0882783f635cce9d2f94d.png"> </img></div> <p>First, as <var>(x_1, y_1) = (2, 1)</var> and <var>a_1 = 1</var>, he paints the region satisfying <var>x &lt; 2</var> within the rectangle:</p> <div style="text-align: center;"> <img alt="f25cd04bbac23c4e5426d70511a9762f.png" src="https://atcoder.jp/img/abc047/f25cd04bbac23c4e5426d70511a9762f.png"> </img></div> <p>Then, as <var>(x_2, y_2) = (3, 3)</var> and <var>a_2 = 4</var>, he paints the region satisfying <var>y &gt; 3</var> within the rectangle:</p> <div style="text-align: center;"> <img alt="46b0c06fd9eee4f148e1f441f7abca53.png" src="https://atcoder.jp/img/abc047/46b0c06fd9eee4f148e1f441f7abca53.png"/> </div> <p>Now, the area of the white region within the rectangle is <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 4 3 2 1 1 3 3 4 1 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>It is possible that the whole region within the rectangle is painted black.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 5 1 6 1 4 1 3 6 9 4 9 4 2 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>64 </pre></section> </div> </span>
p01979
<h1>F: ごちうさ数</h1> <h2>問題</h2> <p> ごちうさが倧奜きなAORむカちゃんは「ごちうさ数」を定矩した。 ごちうさ数ずは、 $10$ 進衚蚘においお「 $51?3$ 」を含む自然数のこずである。<br> $?$ は $0$ 〜 $9$ のどの数字であっおもよい。 </p> <p> $N$ 以䞋の自然数のうち、ごちうさ数の個数を求めよ。 </p> <h2>制玄</h2> <ul> <li>$1 \le N &lt; 10^{18}$</li> </ul> <h2>入力</h2> <p> $N$<br> </p> <h2>出力</h2> <p> ごちうさ数の個数を䞀行で出力せよ。たた末尟に改行を出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 5124 </pre> <h3>サンプル出力 1</h3> <pre> 3 </pre> <p> $5124$ 以䞋のごちうさ数は、$5103$ , $5113$ , $5123$ の 䞉぀である。 </p> <h3>サンプル入力 2</h3> <pre> 60000 </pre> <h3>サンプル出力 2</h3> <pre> 160 </pre> <h3>サンプル入力 3</h3> <pre> 100000 </pre> <h3>サンプル出力 3</h3> <pre> 200 </pre> <!-- - - - - - end nicebody - - - - - -->
p02656
<span class="lang-en"> <p>Score : <var>1800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has <var>X+Y</var> balls. <var>X</var> of them have an integer <var>A</var> written on them, and the other <var>Y</var> of them have an integer <var>B</var> written on them.</p> <p>Snuke will divide these balls into some number of groups. Here, every ball should be contained in exactly one group, and every group should contain one or more balls.</p> <p>A group is said to be <strong>good</strong> when the sum of the integers written on the balls in that group is a multiple of an integer <var>C</var>. Find the maximum possible number of good groups.</p> <p>Solve <var>T</var> test cases for each input file.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq T \leq 2 \times 10^4</var></li> <li><var>1 \leq A,X,B,Y,C \leq 10^9</var></li> <li><var>A \neq B</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. The first line is as follows:</p> <pre><var>T</var> </pre> <p>Then, <var>T</var> test cases follow. Each test case is given in the following format:</p> <pre><var>A</var> <var>X</var> <var>B</var> <var>Y</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each test case, print a line containing the maximum possible number of good groups.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 3 4 4 5 2 1 1 5 3 3 1 4 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 2 0 </pre> <p>In the first test case, we can have two good groups by making the following groups: <var>\{3,3,4\}</var> and <var>\{3,4,4,4\}</var>.</p> <p>In the second test case, we can have two good groups by making the following groups: <var>\{2,1\}, \{1,1,1\},</var> and <var>\{1\}</var>.</p></section> </div> </span>
p00391
<h1>Treasure Map</h1> <p> Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequences of numbers seem to give a clue to the whereabouts of the treasure the ancestor buried. </p> <p> Mr. Kobou’s ancestor divided the area where he buried his treasure in a reticular pattern and used only some of the grid sections. The two series of numbers indicate the locations: the $i$-th member of the first series indicates the number of locations in the $i$-th column (form left) of the grid sections where a part of the treasure is buried, and the $j$-th member of the second indicates the same information regarding the $j$-th row from the top. No more than one piece of treasure is buried in one grid section. An example of a 5 &times; 4 case is shown below. If the pieces of treasure are buried in the grid sections noted as "<span>#</span>" the two series of numbers become "0,2,2,1,1" and "1,1,1,3". </p> <center> <table border="1" style="border-collapse: collapse" cellpadding="8"> <tr> <td> </td><td>0</td><td>2</td><td>2</td><td>1</td><td>1</td> </tr> <tr> <td>1</td><td> </td><td> </td><td>#</td><td> </td><td> </td> </tr> <tr> <td>1</td><td> </td><td>#</td><td> </td><td> </td><td> </td> </tr> <tr> <td>1</td><td> </td><td> </td><td> </td><td> </td><td>#</td> </tr> <tr> <td>3</td><td> </td><td>#</td><td>#</td><td>#</td><td> </td> </tr> </table> </center> <br/> <p> Mr. Kobou’s ancestor seems to be a very careful person. He slipped some pieces of paper with completely irrelevant information into the bundle. For example, a set of number series "3,2,3,0,0" and "4,2,0,0,2" does not match any combination of 5 &times; 5 matrixes. So, Mr. Kobou has first to exclude these pieces of garbage information. </p> <p> Given the set of information written on the pieces of paper, make a program to judge if the information is relevant. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $W$ $H$ $a_1$ $a_2$ $...$ $a_W$ $b_1$ $b_2$ $...$ $b_H$ </pre> <p> The first line provides the number of horizontal partitions $W$ ($1 \leq W \leq 1000$) and vertical partitions $H$ ($1 \leq H \leq 1000$). The second line provides the $i$-th member of the first number series $a_i$ ($0 \leq a_i \leq H$) written on the paper, and the third line the $j$-th member of the second series $b_j$ ($0 \leq b_j \leq W$). </p> <h2>Output</h2> <p> Output "<span>1</span>" if the information written on the paper is relevant, or "<span>0</span>" otherwise. </p> <h2>Sample Input 1 </h2> <pre> 5 4 0 2 2 1 1 1 1 1 3 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 5 5 3 2 3 0 0 4 2 0 0 2 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre>
p02206
<h2>賞金 (Prize)</h2> <p>Segtree くんは、 $N$ 人のチヌムでプログラミングコンテストに出堎し、 $K$ 円の賞金を埗たした今、この賞金を分配しようずしおいたす。</p> <p>Segtree くんを含む $N$ 人のチヌムメンバヌそれぞれには、実力順に $1$ から $N$ たでの番号が぀けられおいたす。Segtree くんは $1$ 番です。</p> <p>$i$ 番のチヌムメむト $(i \geq 2)$ の埗る賞金額が「$i - 1$ 番のチヌムメむトの埗た賞金額の半分を敎数に切り捚おた倀」より少ないず、その人は怒っおしたいたす。</p> <p>怒る人が䞀人もいないように $K$ 円の賞金を分配するずき、Segtree くんがもらえる賞金の最倧倀を求めおください。</p> <h3>入力</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre> N K </pre> <h3>出力</h3> <p>Segtree くんがもらえる賞金の最倧倀を出力しおください。</p> <p>ただし、最埌には改行を入れるこず。</p> <h3>制玄</h3> <ul> <li>$1 \leq N,K \leq 10^{18}$</li> <li>入力は党お敎数である。</li> </ul> <h3>入力䟋1</h3> <pre> 1 1 </pre> <h3>出力䟋1</h3> <pre> 1 </pre> <h3>入力䟋2</h3> <pre> 819875141880895728 349993004923078537 </pre> <h3>出力䟋2</h3> <pre> 174996502461539284 </pre>
p03899
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> panels arranged in a row in Takahashi's house, numbered <var>1</var> through <var>N</var>. The <var>i</var>-th panel has a number <var>A_i</var> written on it. Takahashi is playing by throwing balls at these panels.</p> <p>Takahashi threw a ball <var>K</var> times. Let the panel hit by a boll in the <var>i</var>-th throw be panel <var>p_i</var>. He set the score for the <var>i</var>-th throw as <var>i \times A_{p_i}</var>.</p> <p>He was about to calculate the total score for his throws, when he realized that he forgot the panels hit by balls, <var>p_1,p_2,...,p_K</var>. The only fact he remembers is that for every <var>i</var> <var>(1 ≩ i ≩ K-1)</var>, <var>1 ≩ p_{i+1}-p_i ≩ M</var> holds. Based on this fact, find the maximum possible total score for his throws.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ M ≩ N ≩ 100,000</var></li> <li><var>1 ≩ K ≩ min(300,N)</var></li> <li><var>1 ≩ A_i ≩ 10^{9}</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li>In the test set worth <var>100</var> points, <var>M = N</var>.</li> <li>In the test set worth another <var>200</var> points, <var>N ≩ 300</var> and <var>K ≩ 30</var>.</li> <li>In the test set worth another <var>300</var> points, <var>K ≩ 30</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>M</var> <var>K</var> <var>A_1</var> <var>A_2</var> 
 <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible total score for Takahashi's throws.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 3 10 2 8 10 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>56 </pre> <p>The total score is maximized when panels <var>1,3</var> and <var>4</var> are hit, in this order.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 2 5 2 10 5 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>28 </pre> <p>This case satisfies the additional constraint <var>M = N</var> for a partial score.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 3 5 3 7 2 6 9 4 8 5 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5000000078 </pre></section> </div> </span>
p02271
<H1>Exhaustive Search</H1> <p> Write a program which reads a sequence <i>A</i> of <i>n</i> elements and an integer <i>M</i>, and outputs "<span>yes</span>" if you can make <i>M</i> by adding elements in <i>A</i>, otherwise "<span>no</span>". You can use an element only once. </p> <p> You are given the sequence <i>A</i> and <i>q</i> questions where each question contains <i>M<sub>i</sub></i>. </p> <H2>Input</H2> <p> In the first line <i>n</i> is given. In the second line, <i>n</i> integers are given. In the third line <i>q</i> is given. Then, in the fourth line, <i>q</i> integers (<i>M<sub>i</sub></i>) are given. </p> <H2>Output</H2> <p> For each question <i>M<sub>i</sub></i>, print <span>yes</span> or <span>no</span>. </p> <H2>Constraints</H2> <ul> <li>n &le; 20</li> <li> q &le; 200 </li> <li>1 &le; elements in A &le; 2000</li> <li>1 &le; M<sub>i</sub> &le; 2000</li> </ul> <H2>Sample Input 1</H2> <pre> 5 1 5 7 10 21 8 2 4 17 8 22 21 100 35 </pre> <H2>Sample Output 1</H2> <pre> no no yes yes yes yes no no </pre> <H2>Notes</H2> <p> You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: </p> <p> solve(0, M) <br> solve(1, M-{sum created from elements before 1st element}) <br> solve(2, M-{sum created from elements before 2nd element}) <br> ... </p> <p> The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. </p> <p> For example, the following figure shows that 8 can be made by A[0] + A[2]. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_5_A"> </center> <!-- <a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a> -->
p03933
<span class="lang-en lang-child hidden-lang"> <div id="task-statement"> <div class="part"> Max Score: $850$ Points <br/> <section> <h3>Problem statement</h3> There is a circle which radius is 1. <br/> There are $N$ vertices on the circle's circumference. <br/> The vertices divides into $N$ equal parts over the circumference. <br/> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-3/4ed4ec92efd07ab59a34520d6e7f1c02.png" width="300"/> </div> <br/> You can choose $3$ distinct vertices, and you can make a triangle. <br/> There are $\frac{N(N - 1)(N - 2)}{6}$ ways choosing vertices. The question is: Calculate the area of $K$-th smallest triangle in $\frac{N(N-1)(N-2)}{6}$ triangles. <br/> If the area is same, you can order in any order. <br/> <br/> If $N = 4, K = 3$, the result is following:<br/> <ul class="simple"> <li>If you select vertices $1$, $2$, and $3$, the area of triangle $= 1$.</li> <li>If you select vertices $1$, $2$, and $4$, the area of triangle $= 1$.</li> <li>If you select vertices $1$, $3$, and $4$, the area of triangle $= 1$.</li> <li>If you select vertices $2$, $3$, and $4$, the area of triangle $= 1$.</li> </ul> As a result, the 3rd smallest triangle's area $= 1$.<br/> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> The input is given from Standard Input in the following format: <br/> <blockquote>$N \ K$ </blockquote> </section> </div> <div class="part"> <section> <h3>Output</h3> <ul> <li>Please output the $K$-th triangle area.</li> <li>Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than $10^{−9}$.</li> </ul> </section> <section> <h3>Constraints</h3> <ul> <li>$3 \le N \le 200,000$</li> <li>$1 \le K \le \frac{N(N-1)(N-2)}{6}$</li> </ul> </section> <section> <h3>Subtasks</h3> Subtask 1 [ $160$ points ] <br/> <ul> <li>$N \le 100$</li> </ul> Subtask 2 [ $240$ points ] <br/> <ul> <li>$N \le 1000$</li> </ul> Subtask 3 [ $450$ points ] <br/> <ul> <li>$N \le 200,000$</li> </ul> </section> </div> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 1.0000000000000 </pre> This example is already explained in the problem statement. <br/> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 6 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 0.86602540378 </pre> There are $6$ ways to choose a triangle which area is $\frac{\sqrt{3}}{4}$. <br/> There are $10$ ways to choose a triangle which area is $\frac{\sqrt{3}}{2}$. <br/> There are $2$ ways to choose a triangle which area is $\frac{3 \sqrt{3}}{4}$. <br/> Therefore, the 9th smallest triangle's area is $\frac{\sqrt{3}}{2}$. <br/> </section> </div> <div class="part"> <section> <h3>Sample Input 3</h3> <pre> 12 220 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3> <pre> 1.29903810568 </pre> </section> </div> Writer: E869120<br/> </div> </span>
p02621
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given an integer <var>a</var> as input, print the value <var>a + a^2 + a^3</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq a \leq 10</var></li> <li><var>a</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the value <var>a + a^2 + a^3</var> as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>14 </pre> <p>When <var>a = 2</var>, we have <var>a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14</var>.</p> <p>Print the answer as an input. Outputs such as <code>14.0</code> will be judged as incorrect.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1110 </pre></section> </div> </span>
p03460
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer is thinking of painting an infinite two-dimensional grid in a <em>checked pattern of side <var>K</var></em>. Here, a checked pattern of side <var>K</var> is a pattern where each square is painted black or white so that each connected component of each color is a <var>K</var> <var>×</var> <var>K</var> square. Below is an example of a checked pattern of side <var>3</var>:</p> <div style="text-align: center;"> <img alt="cba927b2484fad94fb5ff7473e9aadef.png" src="https://img.atcoder.jp/arc089/cba927b2484fad94fb5ff7473e9aadef.png"> </img></div> <p>AtCoDeer has <var>N</var> desires. The <var>i</var>-th desire is represented by <var>x_i</var>, <var>y_i</var> and <var>c_i</var>. If <var>c_i</var> is <code>B</code>, it means that he wants to paint the square <var>(x_i,y_i)</var> black; if <var>c_i</var> is <code>W</code>, he wants to paint the square <var>(x_i,y_i)</var> white. At most how many desires can he satisfy at the same time?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>N</var> <var>≀</var> <var>10^5</var></li> <li><var>1</var> <var>≀</var> <var>K</var> <var>≀</var> <var>1000</var></li> <li><var>0</var> <var>≀</var> <var>x_i</var> <var>≀</var> <var>10^9</var></li> <li><var>0</var> <var>≀</var> <var>y_i</var> <var>≀</var> <var>10^9</var></li> <li>If <var>i</var> <var>≠</var> <var>j</var>, then <var>(x_i,y_i)</var> <var>≠</var> <var>(x_j,y_j)</var>.</li> <li><var>c_i</var> is <code>B</code> or <code>W</code>.</li> <li><var>N</var>, <var>K</var>, <var>x_i</var> and <var>y_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>x_1</var> <var>y_1</var> <var>c_1</var> <var>x_2</var> <var>y_2</var> <var>c_2</var> <var>:</var> <var>x_N</var> <var>y_N</var> <var>c_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of desires that can be satisfied at the same time.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 0 1 W 1 2 W 5 3 B 5 4 B </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>He can satisfy all his desires by painting as shown in the example above.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1000 0 0 B 0 1 W </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 2 1 2 B 2 1 W 2 2 B 1 0 B 0 6 W 4 5 W </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p03030
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have decided to write a book introducing good restaurants. There are <var>N</var> restaurants that you want to introduce: Restaurant <var>1</var>, Restaurant <var>2</var>, <var>...</var>, Restaurant <var>N</var>. Restaurant <var>i</var> is in city <var>S_i</var>, and your assessment score of that restaurant on a <var>100</var>-point scale is <var>P_i</var>. No two restaurants have the same score.</p> <p>You want to introduce the restaurants in the following order:</p> <ul> <li>The restaurants are arranged in lexicographical order of the names of their cities.</li> <li>If there are multiple restaurants in the same city, they are arranged in descending order of score.</li> </ul> <p>Print the identification numbers of the restaurants in the order they are introduced in the book.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 100</var></li> <li><var>S</var> is a string of length between <var>1</var> and <var>10</var> (inclusive) consisting of lowercase English letters.</li> <li><var>0 ≀ P_i ≀ 100</var></li> <li><var>P_i</var> is an integer.</li> <li><var>P_i ≠ P_j</var> <var>(1 ≀ i &lt; j ≀ N)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S_1</var> <var>P_1</var> <var>:</var> <var>S_N</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line (<var>1 ≀ i ≀ N</var>) should contain the identification number of the restaurant that is introduced <var>i</var>-th in the book.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 khabarovsk 20 moscow 10 kazan 50 kazan 35 moscow 60 khabarovsk 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 4 6 1 5 2 </pre> <p>The lexicographical order of the names of the three cities is <code>kazan</code> <var>&lt;</var> <code>khabarovsk</code> <var>&lt;</var> <code>moscow</code>. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order <var>3,4,6,1,5,2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 yakutsk 10 yakutsk 20 yakutsk 30 yakutsk 40 yakutsk 50 yakutsk 60 yakutsk 70 yakutsk 80 yakutsk 90 yakutsk 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 9 8 7 6 5 4 3 2 1 </pre></section> </div> </span>
p01518
<!-- begin en only --> <h3><u>Dog Food </u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>ドッグフヌド </u></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> あなたは, 賢い犬を遞ぶコンテストの䞻催者である 皮目の1぀に以䞋のようなものがある </p> <p> この皮目は平面的な広堎の䞊で行われる 広堎には杭がいく぀か立っおおりそのうちの1぀ず犬はロヌプで結ばれおいる杭やロヌプの倪さは無芖できるものずするロヌプが結ばれおいる杭の座暙を(00)犬の䜍眮を(DxDy)ずする たたロヌプが結ばれおいる杭以倖の杭の本数を本ずしそれらの座暙を(x<sub>1</sub>y<sub>1</sub>)... (x<sub>n</sub>y<sub>n</sub>)ずする 初期状態でロヌプはピンず匵られた状態であるすなわちロヌプの長さはちょうど(DxDy)ず(00)の距離に等しくその2぀の端は原点の杭ず犬にそれぞれ結び付けられおいる (FxFy)にはドッグフヌドがおかれおおりこの地点がゎヌルであるこの条件䞋で短い走行距離でゎヌルに蟿り぀けた犬ほど賢いず考えられる 堎合によっおは図F-1のように盎接ゎヌルに向かうず別の杭にロヌプが匕っかかりロヌプの長さが足りなくなっおゎヌルにたどり぀けないため杭を迂回する必芁があるこずに泚意せよ この䟋はサンプルの1番目の入力を衚しおいる </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_ukai"> </center> </center> <center> <p> <i>図 F-1: 杭を迂回する必芁がある䟋</i> </p> </center> <p> 優秀なプログラマヌでもあるあなたは犬がゎヌルにたどり着けるかどうかたたたどり着けるずしたら最短距離はどうなるのかをあらかじめ蚈算しおおくこずにした </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は1぀以䞊のデヌタセットからなる1぀のデヌタセットは次の圢匏をしおいるデヌタセット䞭の倀は党お敎数である </p> <blockquote> <var>n</var><br/> <var>Dx</var> <var>Dy</var><br/> <var>Fx</var> <var>Fx</var><br/> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var><br/> <var>...</var><br/> <var>x<sub>n</sub></var> <var>y<sub>n</sub></var><br/> </blockquote> <p> n はロヌプが繋がっおいない杭の本数を衚す Dx, Dy は犬の初期䜍眮の座暙を衚す Fx, Fy はゎヌルの䜍眮を衚す x<sub>i</sub>, y<sub>i</sub> はロヌプが繋がっおいない杭の座暙を衚す </p> <p> デヌタセットに぀いお぀ぎの制玄が成立しおいる </p> <ul> <li>1 &#8804; n &#8804; 8</li> <li>-100 &#8804; Dx, Dy, Fx, Fy, x<sub>i</sub>, y<sub>i</sub> &#8804; 100</li> <li>線分(0,0), (Dx,Dy)䞊に杭は存圚しない.</li> <li>(0,0), (Dx, Dy), (Fx, Fy), (x<sub>1</sub>, y<sub>1</sub>), (x<sub>2</sub>, y<sub>2</sub>)... (x<sub>n</sub>, y<sub>n</sub>) はすべお異なる座暙である.</li> </ul> <p> たた以䞋のこずを仮定しおよい. </p> <ul> <li>(Dx,Dy) が原点方向に察しお, ε(|ε| &lt; 0.00001)だけ倉化したずき, 結果が 0.0005 より倧きく倉化するこずはない</li> </ul> <p> 入力の終わりは0を1぀だけ含む行で衚される </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 各デヌタセットに぀いおゎヌルにたどり着ける堎合は最短距離をたどり着けない堎合は-1を 1 行に出力せよ 出力には, 0.001を超える誀差があっおはならない. </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 1 -4 -8 3 -8 0 -6 1 0 6 4 0 1 4 1 4 0 0 6 1 4 4 95 0 0 90 55 64 33 31 5 4 15 43 8 100 100 99 -100 60 50 6 5 12 10 24 20 30 0 70 0 -30 -10 -90 -30 0 </pre> <!-- begin ja only --> <p> 図F-2, F-3, F-4 はそれぞれサンプルの2番目から4番目の配眮を瀺しおいる </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample0"> </center> </center> <center> <p> <i>図 F-2: 2番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample1"> </center> </center> <center> <p> <i>図 F-3: 3番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_sample2"> </center> </center> <center> <p> <i>図 F-4: 4番目のサンプル</i> </p> </center> <!-- end ja only --> </div> <h3>Output for Sample Input</h3> <div> <pre> 8.0776872 7.2360679 -1 140.2870005 273.9090890 </pre> <!-- begin ja only --> <!-- end ja only --> </div>
p03525
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In CODE FESTIVAL XXXX, there are <var>N+1</var> participants from all over the world, including Takahashi.</p> <p>Takahashi checked and found that the <em>time gap</em> (defined below) between the local times in his city and the <var>i</var>-th person's city was <var>D_i</var> hours. The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is <var>d</var> o'clock at the moment when the local time in city A is <var>0</var> o'clock, then the time gap between these two cities is defined to be <var>min(d,24-d)</var> hours. Here, we are using <var>24</var>-hour notation. That is, the local time in the <var>i</var>-th person's city is either <var>d</var> o'clock or <var>24-d</var> o'clock at the moment when the local time in Takahashi's city is <var>0</var> o'clock, for example.</p> <p>Then, for each pair of two people chosen from the <var>N+1</var> people, he wrote out the time gap between their cities. Let the smallest time gap among them be <var>s</var> hours.</p> <p>Find the maximum possible value of <var>s</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 50</var></li> <li><var>0 \leq D_i \leq 12</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>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of <var>s</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 7 12 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>For example, consider the situation where it is <var>7</var>, <var>12</var> and <var>16</var> o'clock in each person's city at the moment when it is <var>0</var> o'clock in Takahashi's city. In this case, the time gap between the second and third persons' cities is <var>4</var> hours.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 11 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>Note that Takahashi himself is also a participant.</p></section> </div> </span>
p01148
<!-- begin en only --> <h3><U> Princess, a Strategist </U></h3> <!-- end en only --> <!-- begin ja only --> <h3><U> お姫様は戊略家 </U></h3> <!-- end ja only --> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> ある貧乏な囜の勇敢なお姫様はお城を抜け出しお叀の秘宝を手に入れる冒険に出かける算段をしおいるずころが叀の秘宝の呚囲は耇数のガヌディアンによっお守られおおり普通の方法では蟿り着くこずができないそこでお姫様は埓者であるあなたを囮にしガヌディアン達の泚意を惹き぀けおいる間に秘宝を取っお来るずいう䜜戊を考えたそのような事をされおは呜がいく぀あっおも足りないしかしお姫様の呜什に埓わないわけにもいかないそこでたずあなたはあらかじめ偵察をしどのように動けばガヌディアンの攻撃をかわし぀぀泚意を匕き぀けられるのかを念入りに調査したあなたの仕事はこれらの調査結果をもずに囮であるあなたずガヌディアンの発射する匟䞞の衝突がい぀そしお䜕回起こったのか蚈算するプログラムを曞くこずである </p> <p> たず簡単のためフィヌルドずしお十分に高い堎所から芋䞋ろした二次元平面を考えるそしおあなたはガヌディアンの攻撃から身を守るために鎧を装備しおいるそのためあなたの圢は倚角圢でであるものず考えお良いなおこの倚角圢の各線分は䞀切亀差したり重なったりしないたたあなたの移動に぀いおは以䞋のこずを仮定しお良い </p> <ul> <li>等速盎線運動しかしない <ul> <li>加速枛速方向転換は党お䞀瞬で行われる </li> <li>回転しないため向きは初期状態から䞀切倉わらない</li> </ul> </li> <li>倚角圢の党おの郚分は垞に <i>y</i> 座暙が正の䜍眮にある</li> </ul> <p> たたガヌディアンの発射する匟䞞に぀いおは以䞋のこずを仮定しお良い </p> <ul> <li>ガヌディアンが発射する匟䞞の倪さは無芖できる </li> <li>ガヌディアンが発射する匟䞞は有限の長さをも぀ </li> <li>長さ <i>l</i> の匟䞞が先頭座暙 (<i>x</i>, 0) から速床ベクトル (<i>v</i><sub><i>x</i></sub>, <i>v</i><sub><i>y</i></sub>) をもっお発射されたずするず匟䞞の末尟座暙は以䞋の地点にある泚匟䞞が発射される瞬間の匟䞞の先頭の <i>y</i> 座暙はすべお0である<br> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_formula" alt="(x - (l * vx / sqrt(vx^2 + vy^2)), 0 - (l * vy / sqrt(vx^2 + vy^2))"></center> <ul> <li> たずえば(4, 0) の地点から速床ベクトル (3, 4) の長さ 10 の匟䞞が発射されるケヌスでは匟䞞の末尟は(-2, -8) にある</li> </ul> </li> <li> 敵キャラクタヌが発射する匟䞞同士の衝突は党お無芖される </li> </ul> <p> あなたずガヌディアンの発射した匟䞞の衝突の定矩を以䞋に述べるあなたを構成する倚角圢ずガヌディアンの発射する線分の共有点が初めお発生した時刻を匟䞞の衝突時刻ずするガヌディアンの発射した匟䞞にあなたが衝突したずしおもあなたはダメヌゞを受けるだけで移動には䜕の支障もきたさないものずしあなたに衝突した匟䞞は衝突した瞬間に消滅するものずするなおあなたが初期䜍眮から任意の方向に 10<sup>-6</sup> の範囲で平行移動したずしおも衝突時間は高々 10<sup>-5</sup> しか倉化しないこずが保蚌されおいる </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットからなる </p> <p> それぞれのデヌタセットは次のような圢匏で䞎えられる </p> <blockquote> <i>N</i> <i>M</i> <i>B</i><br> <i>X</i><sub>1</sub> <i>Y</i><sub>1</sub><br> ...<br> <i>X</i><sub><i>N</i></sub> <i>Y</i><sub><i>N</i></sub><br> <i>T</i><sub>1</sub> <i>VX</i><sub>1</sub> <i>VY</i><sub>1</sub><br> ...<br> <i>T</i><sub><i>M</i></sub> <i>VX</i><sub><i>M</i></sub> <i>VY</i><sub><i>M</i></sub><br> <i>T'</i><sub>1</sub> <i>X'</i><sub>1</sub> <i>VX'</i><sub>1</sub> <i>VY'</i><sub>1</sub> <i>L</i><sub>1</sub><br> ...<br> <i>T'</i><sub><i>B</i></sub> <i>X'</i><sub><i>B</i></sub> <i>VX'</i><sub><i>B</i></sub> <i>VY'</i><sub><i>B</i></sub> <i>L</i><sub><i>B</i></sub> </blockquote> <p> 各デヌタセットの先頭には3぀の非負敎数 <i>N</i> (3 ≩ <i>N</i> ≩ 20) <i>M</i> (0 ≩ <i>M</i> ≩ 100) <i>B</i> (0 ≩ <i>B</i> ≩ 100) が䞎えられる これらはそれぞれあなたである倚角圢の頂点の数あなたの移動に関する情報の数およびガヌディアンの発射した匟䞞の数を衚す </p> <p> 続く <i>N</i> 行ではあなたを衚す倚角圢の頂点の時刻0での座暙が順に列挙される (<i>X</i><sub><i>i</i></sub>, <i>Y</i><sub><i>i</i></sub>) (1 ≩ <i>i</i> ≩ <i>N</i>) はそれぞれ倚角圢の <i>i</i> 番目の頂点の座暙を衚す これらの倀はすべお敎数であり -10,000 ≩ <i>X</i><sub><i>i</i></sub> ≩ 10,000 0  <i>Y</i><sub><i>i</i></sub> ≩ 10,000 を満たす </p> <p> 続く <i>M</i> 行では あなたの移動を衚す指瀺が <i>M</i> 個䞎えられる <i>i</i>番目 (1 ≩ <i>i</i> ≩ <i>M</i>) の移動指瀺は 3぀の敎数 <i>T</i><sub><i>i</i></sub>, <i>VX</i><sub><i>i</i></sub>, <i>VY</i><sub><i>i</i></sub> から成り立っおおり これは 時刻 <i>T</i><sub><i>i</i>-1</sub> から <i>T</i><sub><i>i</i></sub> たでの間あなたの速床ベクトルを (<i>VX</i><sub><i>i</i></sub>, <i>VY</i><sub><i>i</i></sub>) に維持するずいうこずを意味する ただし 0 = <i>T</i><sub>0</sub>  <i>T</i><sub>1</sub>  <i>T</i><sub>2</sub>  ...  <i>T</i><sub><i>M</i></sub> ≩ 10,000 -100 ≩ <i>VX</i><sub><i>i</i></sub> ≩ 100 -100 ≩ <i>VY</i><sub><i>i</i></sub> ≩ 100 である あなたがすべおの移動指瀺を終えた埌すなわち時刻 <i>T</i><sub><i>M</i></sub> 以降は移動を停止し その堎にずどたり続けるものずする あなたが停止した以降にも匟䞞ずの衝突が発生する可胜性があり 出力に際しおはそのような衝突も考慮する必芁があるこずに泚意せよ </p> <p> 続く <i>B</i> 行ではガヌディアンの発射する <i>B</i> 個の匟䞞に関する情報が蚘述されおいる <i>i</i> 番目 (1 ≩ <i>i</i> ≩ <i>B</i>) の匟䞞に関する情報は5぀の敎数 <i>T'</i><sub><i>i</i></sub> <i>X'</i><sub><i>i</i></sub> <i>VX'</i><sub><i>i</i></sub> <i>VY'</i><sub><i>i</i></sub> および <i>L</i><sub><i>i</i></sub> で衚されこれは時刻 <i>T'</i><sub><i>i</i></sub> に座暙 (<i>X'</i><sub><i>i</i></sub>, 0) から速床ベクトル (<i>VX'</i><sub><i>i</i></sub>, <i>VY'</i><sub><i>i</i></sub>) をも぀長さ <i>L</i><sub><i>i</i></sub> の匟䞞が発射されるこずを意味する これらの倀は 0 ≩ <i>T'</i><sub>1</sub> ≩ <i>T'</i><sub>2</sub> ≩ ... ≩ <i>T'</i><sub><i>B</i></sub> ≩ 10,000 -10,000 ≩ <i>X'</i><sub><i>i</i></sub> ≩ 10,000 -100 ≩ <i>VX'</i><sub><i>i</i></sub> ≩ 100 0  <i>VY'</i><sub><i>i</i></sub> ≩ 100 0  <i>L</i><sub><i>i</i></sub> ≩ 100 を満たす </p> <p> 最埌のデヌタセットの埌ろにデヌタセットの終了を意味する "0 0 0" ず曞かれた1行が䞎えられる これはデヌタセットの䞀郚ではない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットに察する出力の先頭にあなたがガヌディアンの発射した匟䞞に衝突した回数 <i>n</i> を出力せよ続く <i>n</i> 行ではあなたがガヌディアンの発射した匟䞞に衝突した時刻を昇順に誀差高々 0.001 の粟床で出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 4 1 1 1 1 1 2 -1 2 -1 1 2 1 0 0 1 0 1 2 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 1 1.000 </pre>
p03175
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1, 2, \ldots, N</var>. For each <var>i</var> (<var>1 \leq i \leq N - 1</var>), the <var>i</var>-th edge connects Vertex <var>x_i</var> and <var>y_i</var>.</p> <p>Taro has decided to paint each vertex in white or black. Here, it is not allowed to paint two adjacent vertices both in black.</p> <p>Find the number of ways in which the vertices can be painted, modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq x_i, y_i \leq N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_{N - 1}</var> <var>y_{N - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways in which the vertices can be painted, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are five ways to paint the vertices, as follows:</p> <p><img alt="" src="https://img.atcoder.jp/dp/indep_0_muffet.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 1 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> <p>There are nine ways to paint the vertices, as follows:</p> <p><img alt="" src="https://img.atcoder.jp/dp/indep_1_muffet.png"/></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>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 8 5 10 8 6 5 1 5 4 8 2 10 3 6 9 2 1 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>157 </pre></section> </div> </span>
p02334
<!--<h1>写像12盾 その4:ボヌルに区別なし・箱に区別あり・入れ方に制限なし</h1>--> <h1>Balls and Boxes 4</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 style="background-color:#aff">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>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 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> 21 </pre> <h2>Sample Input 2</h2> <pre> 10 5 </pre> <h2>Sample Output 2</h2> <pre> 1001 </pre> <h2>Sample Input 3</h2> <pre> 100 100 </pre> <h2>Sample Output 3</h2> <pre> 703668401 </pre>
p00309
<h1>アカベコ囜王の配慮</h1> <p> アカベコ囜の囜王には人の王子がいたす。囜王は自分が退䜍するずきに囜を぀に分割し、それぞれの王子に䞀぀ず぀囜を治めさせるこずにしたした。新しい囜の名前はアカ囜ずベコ囜です。アカベコ囜には <var>N</var> 個の町ず、぀の町を繋ぐ <var>M</var> 本の道がありたす。囜王は、以䞋の手順でアカベコ囜の町ず䞀郚の道を぀の囜に配分するこずにしたした。<br> <br> (1)&nbsp;&nbsp; 町を぀遞び、それぞれアカ囜ずベコ囜に配分する。<br> (2)&nbsp;&nbsp; すでに配分された町sを遞ぶ。さらに、町 <var>s</var> から本の道で繋がっおいる、ただ配分されおいない町 <var>t</var> を遞ぶ。そしお、町 <var>s</var>、<var>t</var> 間の道ず町 <var>t</var> を、町 <var>s</var> が配分された囜に配分する。<br> (3)&nbsp;&nbsp; (2)を、行えなくなるたで繰り返す。 </p> <p> 実は人の王子はあたり仲が良くないので、囜王は぀の囜の距離をなるべく倧きくしたいず考えおいたす。ここで、぀の囜の距離ずは、アカ囜の町ずベコ囜の町を繋ぐ道の䞭で、最も短い道の長さです。 </p> <p> アカベコ囜の町ず道の情報が䞎えられたずき、分配埌のアカ囜ずベコ囜の距離の最倧倀ず、そのような距離になる配分が䜕通りあるかを求めるプログラムを䜜成しおください。ただし、぀の配分結果は、アカ囜ずベコ囜に異なる町か道が配分された堎合に区別されたす。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var> <var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>d<sub>2</sub></var> : <var>s<sub>M</sub></var> <var>t<sub>M</sub></var> <var>d<sub>M</sub></var> </pre> <p> 行目は぀の敎数からなる。<var>N</var> (2 &le; <var>N</var> &le; 100) は町の数、<var>M</var> (<var>N</var>-1 &le; <var>M</var> &le; <var>N</var>(<var>N</var>-1)/2) は道の数を衚す。続く<var>M</var> 行に぀の町を繋ぐ道が䞎えられる。<var>s<sub>i</sub></var> ず <var>t<sub>i</sub></var> (1 &le; <var>s<sub>i</sub></var> &ne; <var>t<sub>i</sub></var> &le; <var>N</var>) は <var>i</var> 番目の道が繋ぐ぀の町の番号を衚す。<var>d<sub>i</sub></var> (1 &le; <var>d<sub>i</sub></var> &le; 10<sup>9</sup>) は <var>i</var> 番目の道の長さを衚す。 </p> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li> どの぀の町もいく぀かの道を䜿い行き来が可胜である。</li> <li> どの぀の町の間にも本以䞊の道はない。</li> <li> 同じ長さの道は本以䞋である。</li> </ul> <h2>出力</h2> <p> 分配埌のアカ囜ずベコ囜の距離の最倧倀ず組み合わせの数を、空癜区切りで行に出力する。ただし、分配埌の組み合わせの数は非垞に倧きくなりうるので、代わりに 1,000,000,007 で割った䜙りを出力する。 </p> <h2>入出力䟋 </h2> <h2>入力䟋 </h2> <pre> 6 7 1 2 1 2 3 2 3 1 3 4 5 4 5 6 5 6 4 6 1 4 7 </pre> <h2>出力䟋</h2> <pre> 7 18 </pre>
p03876
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>Construct an <var>N</var>-gon that satisfies the following conditions:</p> <ul> <li>The polygon is simple (see notes for the definition).</li> <li>Each edge of the polygon is parallel to one of the coordinate axes.</li> <li>Each coordinate is an integer between <var>0</var> and <var>10^9</var>, inclusive.</li> <li>The vertices are numbered <var>1</var> through <var>N</var> in counter-clockwise order.</li> <li>The internal angle at the <var>i</var>-th vertex is exactly <var>a_i</var> degrees.</li> </ul> <p>In case there are multiple possible answers, you can output any.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>A polygon is called simple if each edge has a positive length, and no two edges have a common point (except for adjacent edges touching at a vertex).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 ≀ N ≀ 1000</var></li> <li><var>a_i</var> is either <var>90</var> or <var>270</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_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>In case the answer exists, print the answer in the following format:</p> <pre><var>x_1</var> <var>y_1</var> : <var>x_N</var> <var>y_N</var> </pre> <p>Here <var>(x_i, y_i)</var> are the coordinates of the <var>i</var>-th vertex.</p> <p>In case the answer doesn't exist, print a single <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 90 90 270 90 90 90 270 90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 0 2 0 2 1 3 1 3 2 1 2 1 1 0 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 90 90 90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre></section> </div> </span>
p02764
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi wants to grill <var>N</var> pieces of meat on a grilling net, which can be seen as a two-dimensional plane. The coordinates of the <var>i</var>-th piece of meat are <var>\left(x_i, y_i\right)</var>, and its <em>hardness</em> is <var>c_i</var>.</p> <p>Takahashi can use one heat source to grill the meat. If he puts the heat source at coordinates <var>\left(X, Y\right)</var>, where <var>X</var> and <var>Y</var> are real numbers, the <var>i</var>-th piece of meat will be ready to eat in <var>c_i \times \sqrt{\left(X - x_i\right)^2 + \left(Y-y_i\right)^2}</var> seconds.</p> <p>Takahashi wants to eat <var>K</var> pieces of meat. Find the time required to have <var>K</var> or more pieces of meat ready if he put the heat source to minimize this time.</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 60</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>-1000 \leq x_i , y_i \leq 1000</var></li> <li><var>\left(x_i, y_i\right) \neq \left(x_j, y_j\right) \left(i \neq j \right)</var></li> <li><var>1 \leq c_i \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>x_1</var> <var>y_1</var> <var>c_1</var> <var>\vdots</var> <var>x_N</var> <var>y_N</var> <var>c_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> <p>It will be considered correct if its absolute or relative error from our answer is at most <var>10^{-6}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 -1 0 3 0 0 3 1 0 2 1 1 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2.4 </pre> <p>If we put the heat source at <var>\left(-0.2, 0\right)</var>, the <var>1</var>-st, <var>2</var>-nd, and <var>3</var>-rd pieces of meat will be ready to eat within <var>2.4</var> seconds. This is the optimal place to put the heat source.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 5 -879 981 26 890 -406 81 512 859 97 362 -955 25 128 553 17 -885 763 2 449 310 57 -656 -204 11 -270 76 40 184 170 16 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7411.2252 </pre></section> </div> </span>
p00759
<h3><U>A Broken Door</U></h3> <!-- end en only --> <div> <!-- please enclose each h3 level section with div --> <!-- begin en only --> <p> There is a rectangular maze consisting of a number of square rooms arranged in grid. The maze is surrounded by walls except for its entry and exit. The entry to the maze is at the leftmost part of the upper side of the rectangular area, that is, the upper side of the uppermost leftmost room of the maze is open. The exit is located at the rightmost part of the lower side, likewise. </p> <!-- end en only --> <!-- begin en only --> <p> There is a wall between each pair of vertically or horizontally adjacent rooms. Such a wall has either a door with a card key lock, or no door at all. If you insert a card to a door, the door opens and you can pass the door. The opened door will close immediately, and the inserted card won't return. You can open any door with any card. You cannot go through a wall that has no door. </p> <!-- end en only --> <!-- begin en only --> <p> When a maze map is given, you can easily determine how many cards are needed to pass through the maze from the entry to the exit. In the maze in Figure G-1, you can pass through it with ten cards, following the path represented by the green arrows (<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_0">) in Figure G-2. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_1" align="center" width="274" width="274"><br> <!-- begin en only --> Figure G-1: A map of a maze<br> <!-- end en only --> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_2" align="center" width="274"><br> <!-- begin en only --> Figure G-2: One of the shortest paths<br> <!-- end en only --> </center> <!-- begin en only --> <p> Now, you are informed that one of the doors is broken and can't be passed. But you don't know which door is broken. If you insert a card to a broken door, the inserted card immediately returns. However, you can't tell a broken door from a working door just by its appearance. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_3" align="center" width="274"><br> <!-- begin en only --> Figure G-3: A maze that potentially can't be passed through<br> <!-- end en only --> </center> <!-- begin en only --> <p> If the door marked with a red X (<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_x">) in Figure G-3 is broken, you have no way to pass through the maze from the entry to the exit. However, you can pass the maze in Figure G-1 whichever door is broken. When you intend to follow the shortest path in Figure G-2, and find that the door marked with a red X in Figure G-4 is broken, you might follow the path represented as green arrows. In this case, you need twenty cards. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_4" align="center" width="274"><br> <!-- begin en only --> Figure G-4: A maze with a broken door<br> <!-- end en only --> </center> <!-- begin en only --> <p> However, you can pass through the maze with less cards. You should follow the path in Figure G-5, until you find the broken door. The path is not the shortest path because it needs twelve cards at least. After you've found a broken door on the path, you should follow the shortest path to the exit that doesn't use the broken door. With this strategy, you can pass the maze with sixteen cards whichever door is broken. Figure G-6 shows one of the worst cases of this strategy; it needs sixteen cards. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_5" align="center" width="274"><br> <!-- begin en only --> Figure G-5: The path before you find the broken door<br> <!-- end en only --> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1178_6" align="center" width="274"><br> <!-- begin en only --> Figure G-6: One of the worst cases of the strategy<br> <!-- end en only --> </center> <!-- begin en only --> <p> You are requested to write a program that prints the minimum number of cards to pass the maze whichever door is broken. </p> <!-- end en only --> </div> <h3>Input</h3> <div> <!-- begin en only --> <p> The input consists of one or more datasets, each of which represents a maze. The number of datasets is no more than 100. </p> <!-- end en only --> <!-- begin en only --> <p> The first line of a dataset contains two integer numbers, the height <i>h</i> and the width <i>w</i> of the rectangular maze, in this order. You may assume that 2 &le; h, w &le; 30. </p> <!-- end en only --> <!-- begin en only --> <p> The following 2 &times; <i>h</i> &minus; 1 lines of a dataset describe whether there are doors between rooms or not. The first line starts with a space and the rest of the line contains <i>w</i> &minus; 1 integers, 1 or 0, separated by a space. These indicate whether doors connect horizontally adjoining rooms in the first row. An integer 0 indicates a door is placed, and 1 indicates no door is there. The second line starts without a space and contains <i>w</i> integers, 1 or 0, separated by a space. These indicate whether doors connect vertically adjoining rooms in the first and the second rows. An integer 0/1 indicates a door is placed or not. The following lines indicate placing of doors between horizontally and vertically adjoining rooms, alternately, in the same manner. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing two zeros. </p> <!-- end en only --> </div> <h3>Output</h3> <div> <!-- begin en only --> <p> For each dataset, output a line having an integer indicating the minimum number of cards needed. If there exists no path to pass through the maze when a certain door is broken, output a line containing &minus;1. The line should not contain any character other than this number. </p> <!-- end en only --> </div> <h3>Sample Input</h3> <div> <pre> 4 8 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 4 8 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 0 0 0 0 3 3 0 0 0 1 0 0 1 0 0 0 0 0 2 4 1 0 1 0 0 0 0 0 1 0 6 12 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 20 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 16 -1 4 10 -1 32 40 </pre> </div>
p01261
<H1><font color="#000">Problem B:</font> Bitwise Kingdom</H1> <p> In the Bitwise Kingdom, located somewhere in the universe, there are exactly 2<sup><i>N</i></sup> citizens living and each of them has a unique identification string that represents his or her class in the society. An identification string is a binary string of length <i>N</i> which consists of characters ‘<span>0</span>’ or ‘<span>1</span>’. The order of classes is defined among the citizens by the following criteria: </p> <ol> <li>Citizens identified by a string containing a greater number of ones are ranked higher. For example, “011” indicates a higher class than “100”.</li> <li> Among those who have identification strings with the same number of ones, citizens identified by a lexicographically greater identification string are ranked higher. For example, “110” indicates a higher class than “101”.</li> </ol> <p> For example, if <i>N</i> = 3, there are 8 (= 2<sup>3</sup>) people in the country, and their identification strings are “000”, “001”, “010”, “100”, “011”, “101”, “110”, and “111” (from the lowest class to the highest). </p> <p> You are given two numbers <i>N</i> (1 &le; <i>N</i> &le; 60) and <i>M</i> (1 &le; <i>M</i> &le; 2<sup><i>N</i></sup>), and you want to resolve the identification string of the person of the <i>M</i>-th lowest class among 2<sup><i>N</i></sup> citizens. Can you write a program to solve this problem? </p> <H2>Input</H2> <p> The input consists of multiple datasets. </p> <p> Each dataset consists of a line which contains two integers <i>N</i> and <i>M</i> in this order, separated with a single space. The input does not contain any other extra characters such as leading or trailing spaces. </p> <p> The end of input is indicated by a line with two zeros. This line is not part of any datasets. </p> <H2>Output</H2> <p> For each dataset, print the identification string of the person of the <i>M</i>-th lowest class in one line. Your program may not omit any leading zeros in the answer. </p> <H2>Sample Input</H2> <pre> 3 3 3 5 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 010 011 </pre>
p00889
<H1><font color="#000">Problem F:</font> Find the Multiples</H1> <p> You are given a sequence <i>a</i><sub>0</sub><i>a</i><sub>1</sub>...<i>a</i><sub><i>N</i>-1</sub> digits and a prime number <i>Q</i>. For each <i>i</i> &le; <i>j</i> with <i>a<sub>i</sub></i> &ne; 0, the subsequence <i>a</i><sub><i>i</i></sub><i>a</i><sub></i>i</i>+1</sub>...<i>a<sub>j</sub></i> can be read as a decimal representation of a positive integer. Subsequences with leading zeros are not considered. Your task is to count the number of pairs (<i>i</i>, <i>j</i>) such that the corresponding subsequence is a multiple of <i>Q</i>. </p> <H2>Input</H2> <p> The input consists of at most 50 datasets. Each dataset is represented by a line containing four integers <i>N</i>, <i>S</i>, <i>W</i>, and <i>Q</i>, separated by spaces, where 1 &le; <i>N</i> &le; 10<sup>5</sup>, 1 &le; <i>S</i> &le; 10<sup>9</sup>, 1 &le; <i>W</i> &le; 10<sup>9</sup>, and <i>Q</i> is a prime number less than 10<sup>8</sup>. The sequence <i>a</i><sub>0</sub>...<i>a</i><sub><i>N</i>-1</sub> of length <i>N</i> is generated by the following code, in which ai is written as <span>a[i]</span>. </p> <pre> int g = S; for(int i=0; i&lt;N; i++) { a[i] = (g/7) % 10; if( g%2 == 0 ) { g = (g/2); } else { g = (g/2) ^ W; } } </pre> <p> <b>Note:</b> the operators <span>/</span>, <span>%</span>, and <span>^</span> are the integer division, the modulo, and the bitwise exclusiveor, respectively. The above code is meant to be a random number generator. The intended solution does not rely on the way how the sequence is generated. </p> <p> The end of the input is indicated by a line containing four zeros separated by spaces. </p> <H2>Output</H2> <p> For each dataset, output the answer in a line. You may assume that the answer is less than 2<sup>30</sup>. </p> <H2>Sample Input</H2> <pre> 3 32 64 7 4 35 89 5 5 555 442 3 5 777 465 11 100000 666 701622763 65537 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 4 6 3 68530 </pre> <p> In the first dataset, the sequence is 421. We can find two multiples of <i>Q</i> = 7, namely, 42 and 21. </p> <p> In the second dataset, the sequence is 5052, from which we can find 5, 50, 505, and 5 being the multiples of <i>Q</i> = 5. Notice that we don't count 0 or 05 since they are not a valid representation of positive integers. Also notice that we count 5 twice, because it occurs twice in different positions. </p> <p> In the third and fourth datasets, the sequences are 95073 and 12221, respectively. </p>
p01631
<h1>Problem E: 英語の勉匷</h1> <h2>Problem Statement</h2> <p> 䌚接合宿に参加予定の高槻さんは勉匷熱心で、最近は英語の勉匷をがんばっおいる。圌女は、携垯を䜿っお次のようなゲヌムをプレむするこずで、少しでも倚く英単語を芚えようずしおいる。圌女が持っおいる携垯は、指で画面を操䜜するタッチパネル匏である。 </p> <p> 携垯の画面には、4 * 4のマス目が描かれおおり、各マスにはアルファベット倧文字が曞かれおいる。このゲヌムは、制限時間T秒の間に、マス目の䞭に隠されおいる英単語をたくさん芋぀け、発芋できた英単語の皮類により点数を競うものである。 </p> <p> 1぀の単語を芋぀ける手順は、次のようになる。たず、単語の1文字目に察応する開始マスを決めお、そこに指を眮く。そしお、今指を眮いおいるマス目から、䞊䞋巊右・斜めの、隣接する8方向のマスのいずれかに向かっお、指でなぞっおいく。ただし、開始マスから珟圚のマスたですでに蟿ったこずがあるマスは、通るこずができない。単語の終了マスに達したら、そこで指を離す。その瞬間、開始マスから終了マスたで指でなぞった単語1぀の点数が加点される。x文字の単語1぀をなぞるためには、x秒の時間がかかる。ある単語をなぞっおから、次の単語をなぞるための指の移動時間は無芖しおよい。 </p> <p> 入力では、加点察象ずなる単語の蟞曞も入力される。この蟞曞の各単語には、点数が振られおいる。蟞曞の䞭に曞かれおいる単語を指でなぞるず、その単語に察応する点数が加算される。ただし、開始マスから終了マスたで、党く同じ指のなぞり方をした単語は、最初の1回しか点数加算されない。蟞曞に曞かれおいない単語を指でなぞっおも加点はされない。 </p> <p> 蟞曞ずゲヌムの盀面が䞎えられるので、制限時間内に埗られる最倧の点数を出力せよ。 </p> <h2>Input</h2> <p> 各デヌタセットは、以䞋の圢匏で入力される。 </p> <pre>N word1 score1 word2 score2 ... wordN scoreN line1 line2 line3 line4 T </pre> <p> Nは、蟞曞に含たれる単語の数を衚わす敎数である。続いおN行にわたっお、蟞曞が入力される。wordiは1぀の単語を衚わすアルファベット倧文字で構成される文字列、scoreiはwordiの単語を指でなぞったずきに埗られる点数を衚わす敎数である。蟞曞の䞭に、同じ単語が2回以䞊珟れるこずはない。 </p> <p> 続いお4行にわたっお、各マス目の文字が入力される。lineiは、4文字のアルファベット倧文字だけで構成される文字列である。lineiの巊からj文字目は、i行目の巊からj番目の文字に察応する。 </p> <p> 䞀番最埌に、制限時間を衚わす敎数Tが入力される。 </p> <h2>Constraints</h2> <ul> <li>1 <= N <= 100</li> <li>1 <= wordiの文字列長 <= 8</li> <li>1 <= scorei <= 100</li> <li>1 <= T <= 10000</li> </ul> <h2>Output</h2> <p> 制限時間内に取埗できる最高の点数を1行で出力せよ。 </p> <h2>Sample Input 1</h2> <pre>6 AIZU 10 LINER 6 LINE 4 ALL 2 AS 1 CIEL 10 ASLA CILI IRZN ELEU 21 </pre> <h2>Output for the Sample Input 1</h2> <pre>40 </pre> <p> 図1に操䜜䟋を瀺す。䟋えば、次のようになぞるず40点ずなる。 <ul> <li>"CIEL"は、文字列の長さが4であるため4秒かけお10点。</li> <li>"AIZU"は、違うなぞり方をすれば、2぀発芋できるため、8秒かけお20点。</li> <li>"LINER"を5秒かけお6点。</li> <li>"LINE"を4秒かけお4点。</li> </ul> 合蚈21秒かけお、40点ずなる。 </p> <div align="center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2013Day1_E1"> </div>