question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p03522
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a sequence <var>A</var> of length <var>N</var>.</p> <p>On this sequence, we can perform the following two kinds of operations:</p> <ul> <li> <p>Swap two adjacent elements.</p> </li> <li> <p>Select one element, and increment it by <var>1</var>.</p> </li> </ul> <p>We will repeatedly perform these operations so that <var>A</var> will be a non-decreasing sequence. Find the minimum required number of operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 200000</var></li> <li><var>1 ≀ A_i ≀ 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>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>:</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required to turn <var>A</var> into a non-decreasing sequence.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 1 8 8 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>We can turn <var>A</var> into a non-decreasing sequence in two operations:</p> <ul> <li>Initially, <var>A = \{4, 1, 8, 8, 7\}</var>.</li> <li>Swap the first two elements. Now, <var>A = \{1, 4, 8, 8, 7\}</var>.</li> <li>Increment the last element by <var>1</var>. Now, <var>A = \{1, 4, 8, 8, 8\}</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>20 8 2 9 7 4 6 7 9 7 4 7 4 4 3 6 2 3 4 4 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>62 </pre></section> </div> </span>
p03488
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive <var>x</var>-axis direction.</p> <p>This robot will be given an instruction sequence <var>s</var>. <var>s</var> consists of the following two kinds of letters, and will be executed in order from front to back.</p> <ul> <li><code>F</code> : Move in the current direction by distance <var>1</var>.</li> <li><code>T</code> : Turn <var>90</var> degrees, either clockwise or counterclockwise.</li> </ul> <p>The objective of the robot is to be at coordinates <var>(x, y)</var> after all the instructions are executed. Determine whether this objective is achievable.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>s</var> consists of <code>F</code> and <code>T</code>.</li> <li><var>1 \leq |s| \leq 8</var> <var>000</var></li> <li><var>x</var> and <var>y</var> are integers.</li> <li><var>|x|, |y| \leq |s|</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> <var>x</var> <var>y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the objective is achievable, print <code>Yes</code>; if it is not, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>FTFFTFFF 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>FTFFTFFF -2 -2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre> <p>The objective can be achieved by, for example, turning clockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>FF 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>TF 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>FFTTFF 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>Yes </pre> <p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning counterclockwise in the second <code>T</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>TTTT 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>No </pre></section> </div> </span>
p03172
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> children, numbered <var>1, 2, \ldots, N</var>.</p> <p>They have decided to share <var>K</var> candies among themselves. Here, for each <var>i</var> (<var>1 \leq i \leq N</var>), Child <var>i</var> must receive between <var>0</var> and <var>a_i</var> candies (inclusive). Also, no candies should be left over.</p> <p>Find the number of ways for them to share candies, modulo <var>10^9 + 7</var>. Here, two ways are said to be different when there exists a child who receives a different number of candies.</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 100</var></li> <li><var>0 \leq K \leq 10^5</var></li> <li><var>0 \leq a_i \leq K</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways for the children to share candies, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are five ways for the children to share candies, as follows:</p> <ul> <li><var>(0, 1, 3)</var></li> <li><var>(0, 2, 2)</var></li> <li><var>(1, 0, 3)</var></li> <li><var>(1, 1, 2)</var></li> <li><var>(1, 2, 1)</var></li> </ul> <p>Here, in each sequence, the <var>i</var>-th element represents the number of candies that Child <var>i</var> receives.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 10 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There may be no ways for the children to share candies.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p>There is one way for the children to share candies, as follows:</p> <ul> <li><var>(0, 0)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 100000 100000 100000 100000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>665683269 </pre> <p>Be sure to print the answer modulo <var>10^9 + 7</var>.</p></section> </div> </span>
p02011
<h1>Problem H. Enlarge Circles</h1> <!-- Time Limit: 2 sec Memory Limit: 512 MB --> <p> You are given $N$ distinct points on the 2-D plane. For each point, you are going to make a single circle whose center is located at the point. Your task is to maximize the sum of perimeters of these $N$ circles so that circles do not overlap each other. Here, "overlap" means that two circles have a common point which is not on the circumference of at least either of them. Therefore, the circumferences can be touched. Note that you are allowed to make a circle with radius $0$. </p> <h2>Input</h2> <p> The input consists of a single test case in the following format. </p> <pre> $N$ $x_1$ $y_1$ $\vdots$ $x_N$ $y_N$ </pre> <p> The first line contains an integer $N$, which is the number of points ($2 \leq N \leq 200$). Each of the following $N$ lines gives the coordinates of a point. Integers $x_i$ and $y_i$ ($-100 \leq x_i, y_i \leq 100$) in the $i$-th line of them give the $x$- and $y$-coordinates, respectively, of the $i$-th point. These points are distinct, in other words, $(x_i,y_i) \ne (x_j, y_j)$ is satisfied if $i$ and $j$ are different. </p> <h2>Output</h2> <p> Output the maximized sum of perimeters. The output can contain an absolute or a relative error no more than $10^{-6}$. </p> <h2>Examples</h2> <h2>Sample Input 1</h2> <pre> 3 0 0 3 0 5 0 </pre> <h2>Output for Sample Input 1</h2> <pre> 31.415926535 </pre> <h2>Sample Input 2</h2> <pre> 3 0 0 5 0 0 5 </pre> <h2>Output for Sample Input 2</h2> <pre> 53.630341225 </pre> <h2>Sample Input 3</h2> <pre> 9 91 -18 13 93 73 -34 15 2 -46 0 69 -42 -23 -13 -87 41 38 68 </pre> <h2>Output for Sample Input 3</h2> <pre> 1049.191683488 </pre>
p00186
<H1>䌚接地鶏</H1> <p> 2008 幎 4 月に、䌚接若束垂は長さ20 m 85 cm のやきずり䜜りに挑戊しお成功したした。このずき䜿われた鶏肉が、䌚接特産の䌚接地鶏です。䌚接地鶏はずおもおいしいのですが、飌育がむずかしいので生産量が少なく、倀段が高いのが難点です。<!--珟圚、生産拡倧のための努力が進められおいるので、そのうちみなさんの䜏む町でも目にする日が来るかもしれたせん。--> </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_chicken"><br/> <br/> </center> <p> 今日は䞀郎君の家に、遠くから芪戚が遊びに来たす。お母さんは鶏肉の氎炊きを䜜っお芪戚をもおなすこずにしたした。近くのお肉屋さんでは䌚接地鶏ずふ぀うの鶏肉の 2 皮類の鶏肉を売っおいたす。お母さんは、以䞋のような指瀺を䞀郎君に䞎えお、お肉屋さんに行っお鶏肉を買っおくるように 頌みたした。 </p> <ul> <li>鶏肉が足りなくなるず困るので、決められた量以䞊の鶏肉を買う。</li> <li>予算の蚱す範囲で䌚接地鶏をできるだけ倚く買う(䌚接地鶏は必ず買うこず)。</li> <li>䌚接地鶏を買った残りでふ぀うの鶏肉をできるだけ倚く買う(予算が足りなければ買わない)。</li> </ul> <p> 䞀郎君がお肉屋さんに行くず、䌚接地鶏が品薄のため䞀人が買える量を制限しおいたした。䞀郎君が、お母さんから䞎えられたすべおの指瀺を守っお買い物をするずき、䞀郎君が買う䌚接地鶏ず普通の鶏肉の量はそれぞれ䜕グラムになるでしょう? </p> <p> 買うべき鶏肉の量の䞋限 <var>q<sub>1</sub></var>、予算 <var>b</var>、このお肉屋さんでの䌚接地鶏 100 グラムの倀段 <var>c<sub>1</sub></var>、ふ぀うの鶏肉 100 グラムの倀段 <var>c<sub>2</sub></var>、䌚接地鶏を䞀人が買える量の䞊限 <var>q<sub>2</sub></var> を入力ずし、䞀郎君が買う䌚接地鶏ずふ぀うの鶏肉の量を 100 グラム単䜍で出力するプログラムを䜜成しおください。ただし、このお肉屋さんではお母さんの指瀺通りに買えない堎合には、「NA」ず出力しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>q<sub>1</sub></var> <var>b</var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> <var>q<sub>2</sub></var> </pre> <p> 鶏肉の量を衚すデヌタ <var>q<sub>1</sub></var> ず <var>q<sub>2</sub></var> は100 グラム単䜍で指定されたす。たた、<var>b</var>、<var>c<sub>1</sub></var>、<var>c<sub>2</sub></var>、<var>q<sub>1</sub></var>、<var>q<sub>2</sub></var> は 1 以䞊 1,000,000 以䞋の敎数ずしたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に、䞀郎君が賌入する䌚接地鶏の量ずふ぀うの鶏肉の量(半角空癜区切り) たたは「NA」を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 48 9297 240 126 32 20 3010 157 141 7 30 117002 5680 962 15 8 1673 1712 190 22 64 8478 87 54 307 23 5477 117 92 12 50 7558 1396 187 17 279 88677 4522 514 14 0 </pre> <H2>Output for the Sample Input</H2> <pre> 28 20 7 13 15 33 NA 97 0 12 44 NA NA </pre>
p02441
<h1>Count</h1> <p> For a given sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$, perform the following operations. </p> <ul> <li>count($b, e, k$): print the number of the specific values $k$ in $a_b, a_{b+1}, ..., a_{e-1}$. </ul> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1, ..., \; a_{n-1}$ $q$ $b_1 \; e_1 \; k_1$ $b_2 \; e_2 \; k_2$ : $b_q \; e_q \; k_q$ </pre> <p> The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $b_i \; b_e \; k_i$ are given as queries. </p> <h2>Output</h2> <p> For each query, print the number of specified values. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 1,000$</li> <li>$-1,000,000,000 \leq a_i, k_i \leq 1,000,000,000$</li> <li>$1 \leq q \leq 1,000$</li> <li>$0 \leq b < e \leq n$</li> </ul> <h2>Sample Input 1</h2> <pre> 9 1 4 1 4 2 1 3 5 6 3 0 9 1 1 6 1 3 7 5 </pre> <h2>Sample Output 1</h2> <pre> 3 2 0 </pre>
p03600
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network:</p> <ul> <li>People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.</li> <li>Different roads may have had different lengths, but all the lengths were positive integers.</li> </ul> <p>Snuke the archeologist found a table with <var>N</var> rows and <var>N</var> columns, <var>A</var>, in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom.</p> <p>Determine whether there exists a road network such that for each <var>u</var> and <var>v</var>, the integer <var>A_{u, v}</var> at the <var>u</var>-th row and <var>v</var>-th column of <var>A</var> is equal to the length of the shortest path from City <var>u</var> to City <var>v</var>. If such a network exist, find the shortest possible total length of the roads.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300</var></li> <li>If <var>i ≠ j</var>, <var>1 \leq A_{i, j} = A_{j, i} \leq 10^9</var>.</li> <li><var>A_{i, i} = 0</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var> <var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var> <var>...</var> <var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>If there exists no network that satisfies the condition, print <code>-1</code>. If it exists, print the shortest possible total length of the roads.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 1 3 1 0 2 3 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The network below satisfies the condition:</p> <ul> <li>City <var>1</var> and City <var>2</var> is connected by a road of length <var>1</var>.</li> <li>City <var>2</var> and City <var>3</var> is connected by a road of length <var>2</var>.</li> <li>City <var>3</var> and City <var>1</var> is not connected by a road.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 1 3 1 0 1 3 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>As there is a path of length <var>1</var> from City <var>1</var> to City <var>2</var> and City <var>2</var> to City <var>3</var>, there is a path of length <var>2</var> from City <var>1</var> to City <var>3</var>. However, according to the table, the shortest distance between City <var>1</var> and City <var>3</var> must be <var>3</var>.</p> <p>Thus, we conclude that there exists no network that satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 0 21 18 11 28 21 0 13 10 26 18 13 0 23 13 11 10 23 0 17 28 26 13 17 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>82 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 0 1000000000 1000000000 1000000000 0 1000000000 1000000000 1000000000 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3000000000 </pre></section> </div> </span>
p02912
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is going to buy <var>N</var> items one by one.</p> <p>The price of the <var>i</var>-th item he buys is <var>A_i</var> yen (the currency of Japan).</p> <p>He has <var>M</var> discount tickets, and he can use any number of them when buying an item.</p> <p>If <var>Y</var> tickets are used when buying an item priced <var>X</var> yen, he can get the item for <var>\frac{X}{2^Y}</var> (rounded down to the nearest integer) yen.</p> <p>What is the minimum amount of money required to buy all the items?</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 10^5</var></li> <li><var>1 \leq 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>M</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 amount of money required to buy all the items.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 2 13 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>We can buy all the items for <var>9</var> yen, as follows:</p> <ul> <li>Buy the <var>1</var>-st item for <var>2</var> yen without tickets.</li> <li>Buy the <var>2</var>-nd item for <var>3</var> yen with <var>2</var> tickets.</li> <li>Buy the <var>3</var>-rd item for <var>4</var> yen with <var>1</var> ticket.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 1 9 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 100000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>We can buy the item priced <var>1000000000</var> yen for <var>0</var> yen with <var>100000</var> tickets.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>9500000000 </pre></section> </div> </span>
p01797
<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 H Kimagure Cleaner</h2> <p> Ichiro won the newest model cleaner as a prize of a programming contest. This cleaner automatically moves around in a house for cleaning. Because Ichiro's house is very large, it can be modeled as an infinite two-dimensional Cartesian plane, whose axes are called $X$ and $Y$. The positive direction of the $Y$-axis is to the left if you face the positive direction of the $X$-axis. </p> <p> The cleaner performs a sequence of actions for cleaning. Each action consists of a turn and a run. In an action, first the cleaner turns right or left by 90 degrees, and then runs straight by an integer length to the direction that the cleaner faces. At the end of a day, the cleaner reports the log of its actions in the day to Ichiro, in order to inform him where it has cleaned and where it hasn't. </p> <p> Unlike common cleaners, this cleaner has human-like artificial intelligence. Therefore, the cleaner is very forgetful (like humans) and it is possible that the cleaner forgets the direction of a turn, or the cleaner only remembers the length of a run as a very rough range. However, in order to pretend to be operating correctly, the cleaner has to recover the complete log of actions after finishing the cleaning. </p> <p> The cleaner was initially at the point $(0, 0)$, facing the positive direction of $X$-axis. You are given the cleaner's location after cleaning, $(X, Y)$, and an incomplete log of the cleaner's actions that the cleaner remembered. Please recover a complete log from the given incomplete log. The actions in the recovered log must satisfy the following constraints: </p> <ul> <li> The number of actions must be the same as that in the incomplete log.</li> <li> The direction of the $i$-th turn must be the same as that in the incomplete log if it is recorded in the incomplete log.</li> <li> The length of the $i$-th run must be within the range of the length specified in the incomplete log.</li> <li> The cleaner must be at $(X, Y)$ after finishing all actions. The direction of the cleaner after cleaning is not important and you do not have to care about it, because the cleaner can turn freely after cleaning, though it cannot run after cleaning. You are not required to recover the actual path, because Ichiro only checks the format of the log and the location of the cleaner after cleaning.</li> </ul> <h3>Input</h3> <p> The input consists of a single test case. The first line contains three integers $N$ $(1 \leq N \leq 50)$, $X$, and $Y$ $(-10^9 \leq X, Y \leq 10^9)$. $N$ represents the number of actions in the incomplete log. $X$ and $Y$ represent the cleaner's location $(X, Y)$ after cleaning. The $i$-th line of the following $N$ lines contains a character $D_i$ and two integers $LL_i$ and $LU_i$. $D_i$ represents the direction of the $i$-th turn: '<span>L</span>', '<span>R</span>', and '<span>?</span>' represents left, right, and not recorded respectively. $LL_i$ and $LU_i$ represent a lower and upper bound of the length of the $i$-th run, respectively. You can assume $1 \leq LL_i \leq LU_i \leq 55,555,555$. </p> <h3>Output</h3> <p> Display the recovered log. In the first line, display N, the number of actions in the log. In the $i$-th line of the following $N$ lines, display the direction of the $i$-th turn in a character and the length of the $i$-th run separated by a single space. Represent a right turn by a single character '<span>R</span>', and a left turn by a single character '<span>L</span>'. The recovered log must satisfy the constraints in the problem. If there are multiple logs that satisfy the constraints, you can display any of them. Display $-1$ in a line if there is no log that satisfies the constraints. </p> <h3>Sample Input 1</h3> <pre>2 -3 4 L 2 5 ? 3 5</pre> <h3>Output for the Sample Input 1</h3> <pre>2 L 4 L 3</pre> <h3>Sample Input 2</h3> <pre>5 3 -4 ? 1 5 ? 1 5 ? 1 5 ? 1 5 ? 1 5</pre> <h3>Output for the Sample Input 2</h3> <pre>5 L 1 R 2 R 4 L 1 R 1</pre>
p00885
<H1><font color="#000">Problem B:</font> Balloon Collecting</H1> <p> "Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player can control the vehicle to move left or right, or simply stay. When one of the balloons reaches the ground, the vehicle and the balloon must reside at the same position, otherwise the balloon will burst and the game ends. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_balloonCollecting"> <p> Figure B.1: Robot vehicle and falling balloons </p> </center> <p> The goal of the game is to store all the balloons into the house at the left end on the game field. The vehicle can carry at most three balloons at a time, but its speed changes according to the number of the carrying balloons. When the vehicle carries <i>k</i> balloons (<i>k</i> = 0, 1, 2, 3), it takes <i>k</i>+1 units of time to move one unit distance. The player will get higher score when the total moving distance of the vehicle is shorter. </p> <p> Your mission is to help the game designer check game data consisting of a set of balloons. Given a landing position (as the distance from the house) and a landing time of each balloon, you must judge whether a player can capture all the balloons, and answer the minimum moving distance needed to capture and store all the balloons. The vehicle starts from the house. If the player cannot capture all the balloons, you must identify the first balloon that the player cannot capture. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is formatted as follows. </p> <p> <i>n</i><br> <i>p</i><sub>1</sub> <i>t</i><sub>1</sub><br> .<br> .<br> .<br> <i>p</i><sub><i>n</i></sub> <i>t</i><sub><i>n</i></sub><br> </p> <p> The first line contains an integer n, which represents the number of balloons (0 &lt; <i>n</i> &le; 40). Each of the following <i>n</i> lines contains two integers <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>n</i>) separated by a space. <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> represent the position and the time when the <i>i</i>-th balloon reaches the ground (0 &lt; <i>p<sub>i</sub></i> &le; 100, 0 &lt; <i>t<sub>i</sub></I> &le; 50000). You can assume <i>t<sub>i</sub></i> &lt; <i>t<sub>j</sub></i> for <i>i</i> &lt; <i>j</i>. The position of the house is 0, and the game starts from the time 0. </p> <p> The sizes of the vehicle, the house, and the balloons are small enough, and should be ignored. The vehicle needs 0 time for catching the balloons or storing them into the house. The vehicle can start moving immediately after these operations. </p> <p> The end of the input is indicated by a line containing a zero. </p> <H2>Output</H2> <p> For each dataset, output one word and one integer in a line separated by a space. No extra characters should occur in the output. </p> <ul> <li> If the player can capture all the balloons, output "OK" and an integer that represents the minimum moving distance of the vehicle to capture and store all the balloons. </li> <li> If it is impossible for the player to capture all the balloons, output "NG" and an integer <i>k</i> such that the <i>k</i>-th balloon in the dataset is the first balloon that the player cannot capture. </li> </ul> <H2>Sample Input</H2> <pre> 2 10 100 100 270 2 10 100 100 280 3 100 150 10 360 40 450 3 100 150 10 360 40 440 2 100 10 50 200 2 100 100 50 110 1 15 10 4 1 10 2 20 3 100 90 200 0 </pre> <H2>Output for the Sample Input</H2> <pre> OK 220 OK 200 OK 260 OK 280 NG 1 NG 2 NG 1 OK 188 </pre>
p03250
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have decided to give an allowance to your child depending on the outcome of the game that he will play now.</p> <p>The game is played as follows:</p> <ul> <li>There are three "integer panels", each with a digit between <var>1</var> and <var>9</var> (inclusive) printed on it, and one "operator panel" with a <code>+</code> printed on it.</li> <li>The player should construct a formula of the form <var>X + Y</var>, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)</li> <li>Then, the amount of the allowance will be equal to the resulting value of the formula.</li> </ul> <p>Given the values <var>A, B</var> and <var>C</var> printed on the integer panels used in the game, find the maximum possible amount of the allowance.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq A, B, C \leq 9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible amount of the allowance.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>53 </pre> <p>The amount of the allowance will be <var>53</var> when the panels are arranged as <code>52+1</code>, and this is the maximum possible amount.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 9 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>108 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>82 </pre></section> </div> </span>
p01778
<h2>G: Dungeon of Cards / カヌドの迷宮</h2> <h3>物語</h3> <p>ここは䞍思議の囜あじふらいあじふらい蟺境の地に䜍眮するカヌドの迷宮には金銀財宝が眠るず䌝えられおいる奜奇心旺盛なあいずにゃんはこの蚀い䌝えを聞くやいなや友人のりィを連れおカヌドの迷宮を目指す旅に出るこずにした</p> <p>翌日旅の蚈画を立おるためにあいずにゃんがりィの家を蚪れるずりィは䜕やら考え蟌んでいるようだったどうやら甚意呚到なりィはカヌドの迷宮に関する重芁な情報を入手したようだそれはカヌドの迷宮には <var>N</var> 枚の扉がありそれぞれの扉を開けるためにカヌドが必芁になるずいうこずだ</p> <p>カヌドの迷宮ぞの道䞭には扉を開くためのカヌドを扱う店があるりィはここでカヌドを調達しようず考えおいるらしいが問題なのは予算であるあいずにゃんずりィは決しおお金持ちではないのでカヌドにお金をかけすぎおしたうず道䞭の食料を十分に確保できない可胜性があるのだ</p> <p>幞い <var>N</var> 枚の扉の情報はこれたで迷宮に挑んだ人々の蚘録から知るこずができたこれなら効率の良いカヌドの買い方を蚈算できるかもしれないしかし人で考えるには少し難しいそこであいずにゃんずりィはあじふらいに䜏む優秀なプログラマであるあなたに䟝頌をするこずにした</p> <h3>問題</h3> <p><var>N</var> 枚の扉ず <var>M</var> 枚のカヌドがある扉・カヌドずもに枚に぀き英倧文字アルファベット ('A'-'Z') 1぀ず1桁の数字 ('0'-'9') が描かれおいる扉にカヌドをかざすずカヌドに描かれたアルファベットもしくは数字のどちらか䞀方でも扉のものず䞀臎しおいればその扉を開けるこずができるこのずきカヌドはなくならないため同じカヌドを䜕床でも䜿いたわすこずができるたたカヌドにはそれぞれ倀段が付いおいる</p> <p><var>N</var> 枚の扉ず <var>M</var> 枚のカヌドの情報を元にすべおの扉を開けるこずができるカヌドの買い方のうち芁する金額が最小ずなる堎合の金額を蚈算するプログラムを䜜成せよ</p> <h3>入力圢匏</h3> <p>入力は以䞋の圢匏からなる</p> <pre> <var>N</var> <var>a_1</var> <var>b_1</var> ... <var>a_N</var> <var>b_N</var> <var>M</var> <var>c_1</var> <var>d_1</var> <var>e_1</var> ... <var>c_M</var> <var>d_M</var> <var>e_M</var> </pre> <p>1行目では扉の枚数を衚す敎数 <var>N</var> が䞎えられる続く <var>N</var> 行のうち<var>i</var> 行目では <var>i</var> 番目の扉に曞かれた英倧文字アルファベット <var>a_i</var> ず1桁の数字 <var>b_i</var> が䞎えられる</p> <p>続く1行では店で扱われおいるカヌドの枚数 <var>M</var> が䞎えられる続く <var>M</var> 行のうち<var>j</var> 行目では <var>j</var> 番目のカヌドに曞かれた英倧文字アルファベット <var>c_j</var> ず1桁の数字 <var>d_j</var>䟡栌 <var>e_j</var> が䞎えられる</p> <p> 入力は以䞋の制玄を満たす <ul> <li> <var>1 &le; N, M &le; 10{,}000</var> </li> <li> <var>a_i, c_j</var> はアルファベット倧文字 ('A'-'Z') 1文字 </li> <li> <var>b_i, d_j</var>は1桁の数字 ('0'-'9') 1文字 </li> <li> <var>1 &le; e_j &le; 1{,}000</var> </li> <li> <var>N, M, e_j</var> はすべお敎数 </li> </ul> </p> <h3>出力圢匏</h3> <p>迷宮の扉をすべお開けるために必芁なカヌドを揃えるための最小予算を1行に出力せよどのようにカヌドを買っおも党おの扉を開けられない堎合-1を1行に出力せよ</p> <h3>入力䟋</h3> <pre> 4 D 1 D 2 A 3 D 4 4 A 1 7 D 4 5 D 3 6 B 3 3 </pre> <h3>出力䟋</h3> <pre>6</pre> <h3>入力䟋2</h3> <pre> 4 D 1 D 2 A 3 D 4 4 A 1 7 D 4 5 D 3 10 B 3 3 </pre> <h3>出力䟋2</h3> <pre>8</pre> <h3>入力䟋3</h3> <pre> 5 D 1 D 2 A 3 Z 0 D 4 4 A 1 7 D 4 5 D 3 6 B 3 3 </pre> <h3>出力䟋3</h3> <pre>-1</pre>
p03745
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an array <var>A</var> of length <var>N</var>. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide <var>A</var> into?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li>Each <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 possible number of subarrays after division of <var>A</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 1 2 3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>One optimal solution is to divide the array into <var>[1,2,3]</var> and <var>[2,2,1]</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 1 2 1 2 1 2 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 2 3 2 1 999999999 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p02857
<span class="lang-en"> <p>Score: <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p><font color="red"><strong>This is an interactive task.</strong></font></p> <p>We have <var>2N</var> balls arranged in a row, numbered <var>1, 2, 3, ..., 2N</var> from left to right, where <var>N</var> is an odd number. Among them, there are <var>N</var> red balls and <var>N</var> blue balls.</p> <p>While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most <var>210</var> questions of the following form:</p> <ul> <li>You choose any <var>N</var> of the <var>2N</var> balls and ask whether there are more red balls than blue balls or not among those <var>N</var> balls.</li> </ul> <p>Now, let us begin.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 99</var></li> <li><var>N</var> is an odd number.</li> </ul> <hr/> </section> </div> <div class="part"> <section> <h3>Input and Output</h3> <p>First, receive the number of balls of each color, <var>N</var>, from Standard Input:</p> <pre><var>N</var> </pre> <p>Then, ask questions until you find out the color of every ball. A question should be printed to Standard Output in the following format:</p> <pre>? <var>A_1</var> <var>A_2</var> <var>A_3</var> <var>...</var> <var>A_N</var> </pre> <p>This means that you are asking about the <var>N</var> balls <var>A_1, A_2, A_3, ..., A_N</var>, where <var>1 \leq A_i \leq 2N</var> and <var>A_i \neq A_j (i \neq j)</var> must hold.</p> <p>The response <var>T</var> to this question will be given from Standard Input in the following format:</p> <pre><var>T</var> </pre> <p>Here <var>T</var> is one of the following strings:</p> <ul> <li><code>Red</code>: Among the <var>N</var> balls chosen, there are more red balls than blue balls.</li> <li><code>Blue</code>: Among the <var>N</var> balls chosen, there are more blue balls than red balls.</li> <li><code>-1</code>: You printed an invalid question (including the case you asked more than <var>210</var> questions), or something else that was invalid.</li> </ul> <p>If the judge returns <code>-1</code>, your submission is already judged as incorrect. The program should immediately quit in this case.</p> <p>When you find out the color of every ball, print your guess to Standard Output in the following format:</p> <pre>! <var>c_1</var><var>c_2</var><var>c_3</var><var>...</var><var>c_{2N}</var> </pre> <p>Here <var>c_i</var> should be the character representing the color of Ball <var>i</var>; use <code>R</code> for red and <code>B</code> for blue.</p> </section> </div> <div class="part"> <section> <h3>Notice</h3> <ul> <li><font color="red"><strong>Flush Standard Output each time you print something.</strong></font> Failure to do so may result in <code>TLE</code>.</li> <li>Immediately terminate your program after printing your guess (or receiving the <code>-1</code> response). Otherwise, the verdict will be indeterminate.</li> <li>If your program prints something invalid, the verdict will be indeterminate.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input and Output</h3> <table class="table-striped table-bordered table-condensed"> <tr align="center"> <th align="center">Input</th> <th align="center">Output</th> </tr> <tr align="center"> <td><code>3</code></td> <td></td> </tr> <tr align="center"> <td></td> <td><code>? 1 2 3</code></td> </tr> <tr align="center"> <td><code>Red</code></td> <td></td> </tr> <tr align="center"> <td></td> <td><code>? 2 4 6</code></td> </tr> <tr align="center"> <td><code>Blue</code></td> <td></td> </tr> <tr align="center"> <td></td> <td><code>! RRBBRB</code></td> </tr> </table> <p>In this sample, <var>N = 3</var>, and the colors of Ball <var>1, 2, 3, 4, 5, 6</var> are red, red, blue, blue, red, blue, respectively.</p> <ul> <li>In the first question, there are two red balls and one blue ball among the balls <var>1, 2, 3</var>, so the judge returns <code>Red</code>.</li> <li>In the second question, there are one red ball and two blue balls among the balls <var>2, 4, 6</var>, so the judge returns <code>Blue</code>.</li> </ul></section> </div> </span>
p01282
<H1><font color="#000">Problem J:</font> Revenge of the Round Table</H1> <p> Two contries A and B have decided to make a meeting to get acquainted with each other. <i>n</i> ambassadors from A and B will attend the meeting in total. </p> <p> A round table is prepared for in the meeting. The ambassadors are getting seated at the round table, but they have agreed that more than k ambassadors from the same country does not sit down at the round table in a row for deeper exchange. </p> <p> Your task is to write a program that reports the number of possible arrangements when rotations are not counted. Your program should report the number modulo <i>M</i> = 1000003. </p> <p> Let us provide an example. Suppose <i>n</i> = 4 and <i>k</i> = 2. When rotations are counted as different arrangements, the following six arrangements are possible. </p> <pre> AABB ABBA BBAA BAAB ABAB BABA </pre> <p> However, when rotations are regarded as same, the following two arrangements are possible. </p> <pre> AABB ABAB </pre> <p> Therefore the program should report 2. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset consists of two integers <i>n</i> (1 &le; <i>n</i> &le; 1000) and <i>k</i> (1 &le; k &le; 1000) in one line. </p> <p> It does not always hold <i>k</i> &lt; <i>n</i>. This means the program should consider cases in which the ambassadors from only one country attend the meeting. </p> <p> The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the number of possible arrangements modulo <i>M</i> = 1000003 in one line. </p> <H2>Sample Input</H2> <pre> 3 1 3 2 3 3 4 2 10 5 1000 500 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 2 4 2 90 570682 </pre>
p01328
<h1><font color="#000">Problem H:</font> 迷い猫、走った</h1> <p>掋菓子専門店ストレむキャッツではたくさんの猫が飌われおいる。猫の数があたりにも倚いため、この店のスタッフである垌は逌やりに困っおいた。 いく぀かの堎所に逌を眮いおも、猫は貪欲なので最も近い逌に向かっおしたい、䞀぀の逌入れにたくさんの猫が集䞭しおしたう。 あなたは垌のために、できるだけ猫が集䞭しない逌の配眮を求める問題を解くこずにした。</p> <p>問題を簡単にするため、猫は平面䞊の y&gt;0 の郚分にいお逌を眮くたで動かないずする。 猫は N 個の集団に分かれおいお、䞀箇所に䜕匹もいるかもしれない。 逌入れは y=0 䞊の M 点に固定しおあり、この䞭からいく぀か遞んで逌を入れるこずになる。 逌を入れるず、猫は(ナヌクリッド距離で)䞀番近い逌の入った逌入れに向かうが、同じ距離に二぀あるずきはx座暙が小さいほうに向かうものずする。</p> <p>この条件の䞋で、最も猫が集たっおいる逌入れの猫の数を最小化しなさい。 </p> <h2>Input</h2> 入力は以䞋のような圢匏で䞎えられる。 <pre> N M x<sub>1</sub> y<sub>1</sub> C<sub>1</sub> ... x<sub>N</sub> y<sub>N</sub> C<sub>N</sub> x<sub>1</sub> ... x<sub>M</sub> </pre> <p>入力の1行目には、2぀の敎数 N, M がスペヌス文字で区切られお䞎えられる。これらは、問題文で指定したずおりである。0 &le; N &le; 1000 および 1 &le; M &le; 1000 を満たす。</p> <p>続く N 行には、それぞれの猫の集団に぀いお1行に1぀ず぀、集団の䜍眮の x, y 座暙を衚す敎数の組 (-10000 &le; x &le; 10000, 0 &lt; y &le; 10000)ず䜕匹集たっおいるかを衚す敎数C(1 &le; C &le; 100000)が䞎えられる。</p> <p>その埌のM行には、それぞれの逌入れに぀いお1行に1぀ず぀、逌入れの䜍眮のx座暙を衚す敎数(-10000 &le; x &le; 10000)が䞎えられる。 同じ点に、二぀以䞊の逌入れが存圚するこずはない。 </p> <h2>Output</h2> <p>最も猫が集たっおいる逌入れの猫の数の最小倀を出力せよ。 </p> <h2>Notes on Test Cases</h2> <p> 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 </p> <p> N, M がずもに 0 のずき入力の終わりを瀺したす。 </p> <h2>Sample Input</h2> <pre> 3 3 -1 1 1 0 1 1 1 1 1 -3 0 3 5 5 7 3 5 -9 2 7 4 9 6 10 5 9 -9 7 9 0 -1 -2 -9 -8 0 0 </pre> <h2>Output for Sample Input</h2> <pre> 2 20 </pre>
p03315
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is always an integer in Takahashi's mind.</p> <p>Initially, the integer in Takahashi's mind is <var>0</var>. Takahashi is now going to eat four symbols, each of which is <code>+</code> or <code>-</code>. When he eats <code>+</code>, the integer in his mind increases by <var>1</var>; when he eats <code>-</code>, the integer in his mind decreases by <var>1</var>.</p> <p>The symbols Takahashi is going to eat are given to you as a string <var>S</var>. The <var>i</var>-th character in <var>S</var> is the <var>i</var>-th symbol for him to eat.</p> <p>Find the integer in Takahashi's mind after he eats all the symbols.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>The length of <var>S</var> is <var>4</var>.</li> <li>Each character in <var>S</var> is <code>+</code> or <code>-</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the integer in Takahashi's mind after he eats all the symbols.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>+-++ </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <ul> <li>Initially, the integer in Takahashi's mind is <var>0</var>.</li> <li>The first integer for him to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>1</var>.</li> <li>The second integer to eat is <code>-</code>. After eating it, the integer in his mind becomes <var>0</var>.</li> <li>The third integer to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>1</var>.</li> <li>The fourth integer to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>2</var>.</li> </ul> <p>Thus, the integer in Takahashi's mind after he eats all the symbols is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>-+-- </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>---- </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-4 </pre></section> </div> </span>
p02154
<h1>Problem F: Equilateral Triangle</h1> <h2>Problem</h2> <p>$N$個の頂点からなる凞倚角圢が䞎えられる。</p> <p>その凞倚角圢の党おの頂点を含む正䞉角圢を考えるずき、その正䞉角圢の䞀蟺の長さの最小倀を求めよ。</p> <p></p> <h2>Input</h2> <p>入力は以䞋の圢匏ですべお敎数で䞎えられる。</p> <pre> $N$ $px_1$ $py_1$ $px_2$ $py_2$ $\vdots$ $px_N$ $py_N$ </pre> <p> $1$行目には凞倚角圢の頂点数を衚す敎数$N$が䞎えられる。<br> 続く$N$行には凞倚角圢の各頂点の情報が反時蚈呚りの順で䞎えられる。<br> $1+i$行目には$i$番目の頂点の座暙を衚す$px_i$,$py_i$が空癜区切りで䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$3 \le N \le 10000$</li> <li>$-10^9 \le px_i, py_i \le 10^9$</li> <li>凞倚角圢の頂点のうちどの3点を遞んでも、同䞀盎線䞊には存圚しない</li> </ul> <h2>Output</h2> <p> 条件を満たす正䞉角圢の䞀蟺の長さの最小倀を出力せよ。<br> ただし、$10^{-5}$ たでの絶察誀差たたは盞察誀差は蚱容される。 </p> <h2>Sample Input 1</h2> <pre> 4 2 3 1 2 2 1 3 2 </pre> <h2>Sample Output 1</h2> <pre> 3.04720672 </pre> <h2>Sample Input 2</h2> <pre> 7 -96469 25422 -55204 -45592 -29140 -72981 98837 -86795 92303 63297 19059 96012 -67980 70342 </pre> <h2>Sample Output 2</h2> <pre> 310622.35426197 </pre>
p00169
<H1>ブラックゞャック</H1> <p> ブラックゞャックはカゞノで行われるカヌドゲヌムの䞀皮で、1 〜 13 たでの数が曞かれたカヌドを䜿っおゲヌムが行われたす。各カヌドの点数は次のように決たっおいたす。 </p> <ul> <li>1 は 1 点あるいは 11 点</li> <li>2 から 9 たでは、曞かれおいる数の通りの点数</li> <li>10 から 13 たでは、10 点</li> </ul> <p> このゲヌムには芪を含めた䜕人かの参加者がおり、それぞれが䜕枚かのカヌドの組を持っおいたす。このカヌドの組のこずを手ず呌びたす。手の点数はカヌドの点数の合蚈です。その蚈算は次のように行うものずしたす。 </p> <ul> <li>カヌドの点数の合蚈が 21 より倧きくなるずきは、手の点数を 0 点ずする</li> <li>カヌドの点数ずしお、1 は 1 点ず蚈算しおも 11 点ず蚈算しおもよいが、手の点数が最倧ずなる方を遞ぶこずずする</li> </ul> <p> 配られたカヌドの情報を入力ずし、手の点数を出力するプログラムを䜜成しおください。 </p> <!-- ただし、1぀の手に含たれるカヌドの枚数 n は1以䞊21以䞋ずし、同じ数が曞かれたカヌドを䜕枚でも 含むこずができるものずしたす。--> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>n</sub></var> </pre> <p> 行に <var>i</var> 番目のカヌドに曞かれおいる敎数 <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; 13) が空癜区切りで行に䞎えられたす。カヌドの数 <var>n</var> は 100 を超えたせん。 </p> <p> デヌタセットの数は 200 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに手の点数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 1 7 7 7 7 7 8 12 1 10 1 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 11 21 0 21 12 </pre>
p00493
<H1>ゞグザグ数 (Zig-Zag Numbers) </H1> <h2> 問題</h2> <p> 正の敎数を (先頭に 0 を぀けずに) 10 進法で曞いお桁の数字を順番に芋おいくず増加ず枛少を亀互に繰り返しおいるずきその数は「ゞグザグ数」であるず呌ぶこずにしようたずえば2947 は桁の数字が 2 → 9 → 4 → 7 ず増加 → 枛少 → 増加 の順になっおいるのでゞグザグ数であるたた71946 は 枛少 → 増加 → 枛少 → 増加 の順なのでゞグザグ数である䞀方123 や 71446 や 71442 や 88 はゞグザグ数ではないなお1 桁の正の敎数はゞグザグ数であるず考えるこずずする </p> <p> A 以䞊 B 以䞋の M の倍数のうちゞグザグ数の個数を 10000 で割った䜙りを求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は 3 行からなり1 行に 1 ぀ず぀正の敎数が曞かれおいる </p> <p> 1 行目の敎数は A を2 行目の敎数は B を3 行目の敎数は M を衚すこれらは 1 ≩ A ≩ B ≩ 10<sup>500</sup>1 ≩ M ≩ 500 を満たす </p> <p> ※ A や B の倀は通垞の敎数を衚すデヌタ型には収たらない可胜性があるこずに泚意せよ </p> <h2> 出力</h2> <p> A 以䞊 B 以䞋の M の倍数のうちゞグザグ数の個数を 10000 で割った䜙りを 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 100 200 5 </pre> <h3>出力䟋 1</h3> <pre> 13 </pre> <p> 入出力䟋 1 においお100 以䞊 200 以䞋の 5 の倍数であるゞグザグ数は105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195 の 13 個である </p> <h3>入力䟋 2</h3> <pre> 6 1234567 3 </pre> <h3>出力䟋 2</h3> <pre> 246 </pre> <p> 入出力䟋 2 においお6 以䞊 1234567 以䞋の 3 の倍数であるゞグザグ数は 50246 個あるのでそれを 10000 で割った䜙りである 246 を出力する </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00539
<h2>JOI 公園 (JOI Park)</h2> <p> 20XX 幎に IOI 囜で行われるオリンピックに備えIOI 囜にある JOI 公園を敎備するこずになったJOI公園には <var>N</var> 個の広堎があり広堎には 1 から <var>N</var> の番号が぀いおいる広堎を繋ぐ <var>M</var> 本の道があり道には 1 から <var>M</var> の番号が぀いおいる道 <var>i</var> (1 &le; <var>i</var> &le; <var>M</var>) は広堎 <var>A<sub>i</sub></var> ず広堎 <var>B<sub>i</sub></var> を双方向に繋いでおり長さは <var>D<sub>i</sub></var> であるどの広堎からどの広堎ぞもいく぀かの道を蟿っお行くこずができる </p> <p> 敎備蚈画ではたず0 以䞊の敎数 <var>X</var> を遞び広堎 1 からの距離が <var>X</var> 以䞋であるような広堎 (広堎 1 を含む) どうしをすべお盞互に地䞋道で結ぶただし広堎 <var>i</var> ず広堎 <var>j</var> の距離ずは広堎 <var>i</var> から広堎 <var>j</var> に行くずきに通る道の長さの和の最小倀である敎備蚈画では地䞋道の敎備コストに関する敎数 <var>C</var> が定たっおいる地䞋道の敎備にかかるコストは <var>C &times; X</var> である </p> <p> 次に地䞋道で結ばれた広堎どうしを結ぶ道をすべお撀去する道の撀去にコストはかからない最埌に撀去されずに残った道をすべお補修する長さ <var>d</var> の道を補修するためにかかるコストは <var>d</var> である敎備蚈画実斜前の JOI 公園には地䞋道はないJOI 公園の敎備にかかるコストの和の最小倀を求めよ </p> <h3>課題</h3> <p> JOI 公園の広堎の情報ず地䞋道の敎備コストに関する敎数が䞎えられたずきJOI 公園の敎備にかかる コストの和の最小倀を求めるプログラムを䜜成せよ </p> <h3>入力</h3> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li> 1 行目には敎数 <var>N</var>, <var>M</var>,<var>C</var> が空癜を区切りずしお曞かれおいるこれは広堎が <var>N</var> 個道が <var>M</var> 本あり地䞋道の敎備コストに関する敎数が <var>C</var> であるこずを衚す</li> <li> 続く <var>M</var> 行のうちの <var>i</var> 行目 (1 &le; <var>i</var> &le; <var>M</var>) には敎数 <var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>, <var>D<sub>i</sub></var> が空癜を区切りずしお曞かれおいるこれは道 <var>i</var> が広堎 <var>A<sub>i</sub></var> ず広堎 <var>B<sub>i</sub></var> を繋ぎ長さが <var>D<sub>i</sub></var> であるこずを衚す </li> </ul> <h3>出力</h3> <p> 暙準出力にJOI 公園の敎備にかかるコストの和の最小倀を衚す敎数を 1 行で出力せよ </p> <h3>制限</h3> <p> すべおの入力デヌタは以䞋の条件を満たす</p> <ul> <li> 2 &le; <var>N</var> &le; 100 000</li> <li> 1 &le; <var>M</var> &le; 200 000</li> <li> 1 &le; <var>C</var> &le; 100 000</li> <li> 1 &le; <var>A<sub>i</sub></var> &le; <var>N</var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li> 1 &le; <var>B<sub>i</sub></var> &le; <var>N</var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li> <var>A<sub>i</sub></var> &ne; <var>B<sub>i</sub></var> (1 &le; <var>i</var> &le; <var>M</var>)</li> <li> (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) &ne; (<var>A<sub>j</sub></var>, <var>B<sub>j</sub></var>) および (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) &ne; (<var>B<sub>j</sub></var>, <var>A<sub>j</sub></var>) (1 &le; <var>i</var> &lt; <var>j</var> &le; <var>M</var>)</li> <li> 1 &le; <var>D<sub>i</sub></var> &le; 100 000 (1 &le; <var>i</var> &le; <var>M</var>)</li> <li> 䞎えられる入力デヌタにおいおはどの広堎からどの広堎ぞもいく぀かの道を蟿るこずにより行けるこずが保蚌されおいる</li> </ul> <h3>入出力䟋</h3> <h3>入力䟋 1 </h3> <pre> 5 5 2 2 3 1 3 1 2 2 4 3 1 2 4 2 5 5 </pre> <h3>出力䟋 1</h3> <pre> 14 </pre> <p> この入力䟋では<var>X</var> = 3 ずしお広堎 1 からの距離が 3 以䞋であるような広堎 (広堎 1, 広堎 2, 広堎 3) どうしをすべお盞互に地䞋道で結んだずき敎備にかかるコストの和は 2 &times; 3 + 3 + 5 = 14 ずなるこれが最小倀である </p> <h3>入力䟋 2</h3> <pre> 5 4 10 1 2 3 2 3 4 3 4 3 4 5 5 </pre> <h3>出力䟋 2</h3> <pre> 15 </pre> <p> この入力䟋ではX = 0 のずき敎備にかかるコストの和が最小になる </p> <h3>入力䟋 3 </h3> <pre> 6 5 2 1 2 2 1 3 4 1 4 3 1 5 1 1 6 5 </pre> <h3>出力䟋 3</h3> <pre> 10 </pre> <p> この入力䟋では<var>X</var> = 5 ずしおすべおの広堎を盞互に地䞋道で結んだずき敎備にかかるコストの和が最小になる </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p01001
<h1>Problem C: General of Taiko</h1> <h2>Problem</h2> <p> ずあるゲヌムセンタヌには、曲に合わせお流れおくる譜面通りに和倪錓を叩くゲヌムがありたす。 譜面は長さ<var> L </var>のセルからなり、各セルには䜕もない、たたはノヌトず呌ばれるプレむダヌがずるべき行動を衚した蚘号がありたす。 ノヌトは2皮類ありそれぞれ、和倪錓の面を叩く「トン」、和倪錓の瞁を叩く「コツ」がありたす。 これらのノヌトに合わせお和倪錓を叩くず埗点を埗るこずができたす。 この埗点の合蚈が10000点以䞊であればクリアずなりたす。 </p> <p> このずき、プレむダヌが曲をクリアできる確率を求めなさい。ただし、プレむダヌは垞に最適な行動をずるこずにしたす。 </p> <p> プレむダヌが譜面通りに和倪錓を叩く粟床は11段階あり、それぞれ、 0%, 10%, 20%, ..., 90%, 100%の確率で譜面通りに和倪錓を叩くこずができたす。 </p> <p> 䞊蚘の二皮類の動䜜は右腕ず巊腕どちらででも行うこずができたす。 プレむダヌの情報ずしお、それぞれの腕で行った堎合の粟床の安定率を衚す倀が16皮類、䞋蚘のように䞎えられたす。 </p> <pre> <var>lt</var>_<var>lt</var> <var>lt</var>_<var>rt</var> <var>lt</var>_<var>lk</var> <var>lt</var>_<var>rk</var> <var>rt</var>_<var>lt</var> <var>rt</var>_<var>rt</var> <var>rt</var>_<var>lk</var> <var>rt</var>_<var>rk</var> <var>lk</var>_<var>lt</var> <var>lk</var>_<var>rt</var> <var>lk</var>_<var>lk</var> <var>lk</var>_<var>rk</var> <var>rk</var>_<var>lt</var> <var>rk</var>_<var>rt</var> <var>rk</var>_<var>lk</var> <var>rk</var>_<var>rk</var> </pre> <p> ただし、<var> lt </var> は巊腕でトン, <var> rt </var> は右腕でトン, <var> lk </var> は巊腕でコツ, <var> rk </var> は右腕でコツの動䜜を衚したす。 䟋えば、<var> lt</var>_<var>rk </var>は巊腕でトンのあずに右腕でコツを行った時の粟床の安定の床合いを衚し、この倀によっお巊腕でトンのあずに右腕でコツを行うずきの粟床が、䞋蚘のように倉化したす。 </p> <pre> プレむダヌの粟床 = max(0, (粟床の安定率 - 10) * 10 + 䞀぀前の粟床) (%) </pre> <p> 曲の情報は以䞋のずおりです。 曲の長さを衚す<var> L </var>、譜面を衚す<var> L </var>個の数字<var> s<sub>i</sub> </var>(0 &le;<var> i </var>&lt; <var> L </var>)で瀺される。譜面の先頭は<var> s<sub>0</sub> </var>である。 <var> s<sub>i</sub> </var>の倀は以䞋の3぀です。 </p> <pre> 0 ... ノヌトなし 1 ... トン 2 ... コツ </pre> <p> プレむダヌが最初に和倪錓を叩くずきの粟床は100%です。 たた、プレむダヌは譜面を無芖するこずができたす。 ノヌトがなかったり、ノヌトを無芖した堎合、プレむダヌの粟床は100%になりたす。 </p> <p> 各ノヌトに合わせお和倪錓を叩いたずきの埗点は䞋蚘のようになりたす。 </p> <pre> 埗点 =<var> A </var>+<var> B </var>* min(コンボ数, 10) </pre> <p> この問題におけるコンボ数ずは、連続しおノヌトに合わせお和倪錓を叩けた数です。 プレむダヌがノヌトに合わせお叩いた堎合、䞊蚘の匏を元に埗点が入り、その埌にコンボ数が1増えたす。 ノヌトに合わせお和倪錓を叩けなかった堎合、コンボが途切れ、コンボ数が0になりたす。 </p> <h2>Input</h2> <p> 入力は耇数のデヌタセットからなりたす。 各デヌタセットは以䞋のずおりです。 </p> <pre> <var>lt</var>_<var>lt</var> <var>lt</var>_<var>rt</var> <var>lt</var>_<var>lk</var> <var>lt</var>_<var>rk</var> <var>rt</var>_<var>lt</var> <var>rt</var>_<var>rt</var> <var>rt</var>_<var>lk</var> <var>rt</var>_<var>rk</var> <var>lk</var>_<var>lt</var> <var>lk</var>_<var>rt</var> <var>lk</var>_<var>lk</var> <var>lk</var>_<var>rk</var> <var>rk</var>_<var>lt</var> <var>rk</var>_<var>rt</var> <var>rk</var>_<var>lk</var> <var>rk</var>_<var>rk</var> <var>L</var> <var>s<sub>0</sub></var> <var>s<sub>1</sub></var> <var>s<sub>2</sub></var> 
 <var>s<sub>L - 1</sub></var> <var>A</var> <var>B</var> </pre> <p> 入力の終わりは負の敎数4぀からなりたす。 </p> <h2>Constraints</h2> <p> 入力は以䞋の条件を満たしたす。 </p> <ul> <li>0 &lt;<var> L </var>&le; 100</li> <li>0 &le; 粟床の安定率 &le; 10</li> <li>粟床の安定率は敎数</li> <li>0 &lt;<var> A </var>, <var> B </var>&le; 10000</li> <li><var> A </var>ず<var> B </var>はずもに100の倍数</li> <li>デヌタセットの数は100個以䞋</li> </ul> <h2>Output</h2> <p> 各入力に察しお、クリアできる確率を1行で出力しなさい。 ただし、出力は0.001以䞋の誀差を含んでも良いです。 </p> <h2>Sample Input</h2> <pre> 9 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 5 1 1 1 1 1 1000 500 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 5 1 0 2 0 1 1000 2000 3 8 6 10 0 1 6 8 10 2 4 7 8 6 6 8 19 2 2 0 2 2 0 2 1 0 1 2 0 1 2 0 1 0 2 2 200 100 -1 -1 -1 -1 </pre> <h2>Sample Output</h2> <pre> 0.3024000000 0.0000000000 0.5120000000 </pre>
p01451
<H1>Problem E: 街を駆ける道</H1> <p> ネヌノァ王囜には、トタタ族ずツテテ族、皮類の民族が暮らしおいる。トタタ族の最倧の特城は、 酢豚にパむナップルを入れお食べるこずである。だがツテテ族は、パむナップルに酢豚を入れお食べ る。こんな぀の民族がお互いに仲良くやっおいけるはずもなく、トタタ族ずツテテ族は、䜕癟幎も の昔からずっずいがみ合いを続けおきた。 </p> <p> そんなある日、ネヌノァ王のもずに、぀の民族から嘆願曞が届いた。それによるずトタタ族は、自 分たちが暮らす街ず街のあいだを結ぶ道を建蚭しおほしいらしい。䞀方でツテテ族も、自分たち が暮らす街ず街のあいだを結ぶ道を建蚭しおほしいらしい。 </p> <p> ぀の民族が衝突するのを防ぐため、トタタ族が通る道ずツテテ族が通る道を亀差させるこずはでき ない。たた、技術的な制玄により、぀の街のあいだを䞀盎線に結ぶような道しか建蚭するこずはで きない。぀たり、必芁ならば街ず街を盎接道で結ばずに、いく぀かのトタタ族の街を経由しお街 ず街を間接的に結ぶこずになるだろうもちろん、ツテテ族の街を経由しおはならない。その 際、トタタ族の街を結ぶ道どうしは亀差しおいおもよい。街ず街に぀いおも同様である。 </p> <p> 道を建蚭するには、その長さに比䟋したコストがかかる。なので、条件をみたし぀぀、できるだけ建 蚭する道の長さの合蚈が短くなるようにしたい。さお、長さの最小倀はいく぀になるだろうか。 </p> <H2>Input</H2> <p> <i>N<sub>A</sub> N<sub>B</sub></i><br> <i>x</i><sub><i>A</i>,1</sub> <i>y</i><sub><i>A</i>,1</sub><br> <i>x</i><sub><i>A</i>,2</sub> <i>y</i><sub><i>A</i>,2</sub><br> .<br> .<br> .<br> <i>x</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub> <i>y</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub><br> <i>x</i><sub><i>B</i>,1</sub> <i>y</i><sub><i>B</i>,1</sub><br> <i>x</i><sub><i>B</i>,2</sub> <i>y</i><sub><i>B</i>,2</sub><br> .<br> .<br> .<br> <i>x</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub> <i>y</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub><br> </p> <p> 入力の行目には、敎数<i>N<sub>A</sub></i>2 &le; <i>N<sub>A</sub></i> &le; 1,000ず敎数<i>N<sub>B</sub></i>2 &le; <i>N<sub>B</sub></i> &le; 1,000が、空癜区切りで曞かれおいる。これは、ネヌノァ王囜にはトタタ族が暮らす街がNA 個、ツテテ族が暮らす街がNB 個あるこずをあらわす。初期状態では、どこにも道は建蚭されおいない。 </p> <p> 続く<i>N<sub>A</sub></i> 行には、敎数<i>x<sub>A,i</sub></i>-10,000 &le; <i>x<sub>A,i</sub></i> &le; 10,000ず敎数<i>y<sub>A,i</sub></i>-10,000 &le; <i>y<sub>A,i</sub></i> &le; 10,000が、空癜区切りで曞かれおいる。ネヌノァ王囜の地理は次元盎亀座暙平面であらわされ、 i 行目に曞かれた敎数<i>x<sub>A,i</sub></i> ず<i>y<sub>A,i</sub></i> は、トタタ族が暮らすi 番目の街の䜍眮座暙が(<i>x<sub>A,i</sub></i>, <i>y<sub>A,i</sub></i>) であるこずをあらわす。(<i>x<sub>A,1</sub></i>, <i>y<sub>A,1</sub></i>) ず(<i>x<sub>A,2</sub></i>, <i>y<sub>A,2</sub></i>) が、結ぶべき぀の街の座暙である。 </p> <p> 続く<i>N<sub>B</sub></i> 行には、敎数<i>x<sub>B,i</sub></i>-10,000 &le; <i>x<sub>B,i</sub></i> &le; 10,000ず敎数<i>y<sub>B,i</sub></i>-10,000 &le; <i>y<sub>B,i</sub></i> &le; 10,000が、空癜区切りで曞かれおいる。 <i>N<sub>A</sub></i>  i 行目に曞かれた敎数<i>x<sub>B,i</sub></i> ず<i>y<sub>B,i</sub></i> は、ツテテ族が暮らすi 番目の街の䜍眮座暙が(<i>x<sub>B,i</sub></i>, <i>y<sub>B,i</sub></i>) であるこずをあらわす。(<i>x<sub>B,1</sub></i>, <i>y<sub>B,1</sub></i>) ず(<i>x<sub>B,2</sub></i>, <i>y<sub>B,2</sub></i>) が、結ぶべき぀の街の座暙である。 </p> <p> どの぀の街の座暙も異なっおおり、どの぀の街も同䞀盎線䞊にないず仮定しおよい。 </p> <H2>Output</H2> <p> 問題文の条件をみたすように道を建蚭したずき、道の長さの合蚈の最小倀を出力せよ。ここで蚀う 「長さ」ずは、ナヌクリッド距離のこずである。ただし、どうやっおも条件をみたす道を建蚭できな いずきは、代わりに-1 を出力せよ。出力は誀差を含んでいおもよいが、真の倀ずの盞察誀差が10<sup>-9</sup>未満でなければならない。 </p> <h2>Sample Input 1</h2> <pre> 2 2 0 0 1 1 2 0 2 -1 </pre> <h2>Sample Output 1</h2> <pre> 2.414213562373 </pre> <h2>Sample Input 2</h2> <pre> 2 3 4 0 0 0 2 3 2 -2 3 1 </pre> <h2>Sample Output 2</h2> <pre> -1 </pre> <h2>Sample Input 3</h2> <pre> 5 2 -2 1 1 2 -1 3 -1 5 1 4 0 4 0 0 </pre> <h2>Sample Output 3</h2> <pre> 12.359173603117 </pre>
p03196
<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> integers <var>a_1, a_2, ..., a_N</var> not less than <var>1</var>. The values of <var>a_1, a_2, ..., a_N</var> are not known, but it is known that <var>a_1 \times a_2 \times ... \times a_N = P</var>.</p> <p>Find the maximum possible greatest common divisor of <var>a_1, a_2, ..., a_N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^{12}</var></li> <li><var>1 \leq P \leq 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> <var>P</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 24 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The greatest common divisor would be <var>2</var> when, for example, <var>a_1=2, a_2=6</var> and <var>a_3=2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>As <var>a_i</var> are positive integers, the only possible case is <var>a_1 = a_2 = a_3 = a_4 = a_5 = 1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>111 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 972439611840 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>206 </pre></section> </div> </span>
p01902
<link rel="stylesheet" href="css/description.css" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script> <h2>E: 鬌畜ババ抜き - Unbalanced Old Maid -</h2> <h3>物語</h3> <p>高坂さんず園田さんず南さんは子䟛の頃からの仲良し3人組だ。3人は沖瞄に修孊旅行に行くも、台颚が来おしたい、海で遊ぶこずができないのでババ抜きをするこずにした。</p> <p> 園田さんは勝負事には匷いが、ポヌカヌフェむスが苊手なため、自分のカヌドが匕かれるずきに無意識にかわいらしい顔芞を披露しおしたう。園田さんを愛しお止たない高坂さんず南さんは、園田さんの顔芞を芋るだけで園田さんの手札が分かっおしたうため、園田さんのカヌドを匕くずきは、自分が有利になるように匕くこずができる。 䞀方、高坂さんず南さんは特に顔芞をしたりはしないので、手札がばれるこずはない。 よっお、高坂さんず南さんのカヌドを匕く人はそれぞれ、高坂さんず南さんが持っおいるカヌドの䞭から等確率で1枚匕く。 </p> <p>どう考えおも䞍利な園田さんは、ババ抜きでなかなか勝おないこずに違和感を芚えおいる。 䜿甚するカヌドの皮類数<var>n</var>ず初期の手札が䞎えられたずき、園田さんが負けずならない確率を求めおあげよう。</p> <h3>問題文</h3> <p>高坂さん、園田さん、南さんの3人は、以䞋の状況でババ抜きを行う。</p> <ul> <li>䜿甚するカヌドは、1から<var>n</var>たでの敎数が曞かれた<var>n</var>皮類のカヌドそれぞれ4枚ず぀ずゞョヌカヌ1枚の合蚈<var>4n+1</var>枚である。</li> <li>最初の手札が䞎えられたずき、3人はそれぞれ自分の手札に同䞀の敎数が曞かれたカヌドのペア2枚組があるならば、そのようなペアを党お捚おる。</li> <li>3人は「高坂さんが南さんの手札からカヌドを匕く」、「園田さんが高坂さんの手札からカヌドを匕く」「南さんが園田さんの手札からカヌドを匕く」ずいう順番タヌンで以䞋の操䜜を繰り返す。このババ抜きでは、カヌドを匕いた人が、次に匕かれるずいうルヌルであるこずに泚意せよ。</li> <ol> <li>䞀人がゞョヌカヌのみを持ち、その人以倖の2人の手札が空のずき、ババ抜きは終了し、ゞョヌカヌを持っおいる人が負けずなる。</li> <li>カヌドを匕く順番の人の手札が空のずき、タヌンを次の人ずし、1.に戻る。</li> <li>そうでなければ、カヌドを匕く順番の人は決められた盞手からカヌドを1枚匕く。ただし、盞手の手札が空のずき、ただ残っおいるもう1人からカヌドを匕く。</li> <li>匕いたカヌドず同じ敎数が曞かれたカヌドがカヌドを匕いた人の手札にあれば、その2枚を捚おる。</li> <li>タヌンを次の人ずし、1.ぞ戻る。</li> </ol> <li>ただし、園田さんのカヌドを匕く人南さんか高坂さんは、以䞋の戊略でカヌド匕く。</li> <ol> <li>もし自分のカヌドず園田さんのカヌドで同じ敎数が曞かれたカヌドがあれば、それらのうち最小の敎数が曞かれたカヌドを匕く</li> <li>そうでないずき、園田さんがゞョヌカヌでないカヌドを持っおいれば、それらのうち最小の敎数が曞かれたカヌドを匕く</li> <li>そうでないなら、園田さんはゞョヌカヌしか持っおいないので、ゞョヌカヌを匕く</li> </ol> <li>高坂さんず南さんのカヌドを匕く人は、それぞれ高坂さんず南さんが持っおいるカヌドの䞭から等確率で1枚匕く。</li> </ul> <p>䜿甚するカヌドの皮類数<var>n</var>ず3人の初期の手札が䞎えられたずき、園田さんが負けずならない確率を求めおあげよう。</p> <h3>入力圢匏</h3> <p>入力は4行からなり、以䞋の圢匏で䞎えられる。</p> <pre> <var>n</var> <var>m_1</var> <var>c_{1,1}</var> ... <var>c_{1,m_1}</var> <var>m_2</var> <var>c_{2,1}</var> ... <var>c_{2,m_2}</var> <var>m_3</var> <var>c_{3,1}</var> ... <var>c_{3,m_3}</var> </pre> <p> 1行目にゞョヌカヌ以倖のカヌドの皮類数<var>n</var>が䞎えられる。 続く入力は3行からなり、2行目に高坂さんの手札、3行目に園田さんの手札、4行目に南さんの手札の情報が䞎えられる。 <var>i+1 (1 &le; i &le; 3)</var>行目では行頭に手持ちの枚数<var>m_i</var>、続けお手持ちのカヌドを衚す<var>m_i</var>個の敎数<var>c_{i,j} (1 &le; j &le; m_i)</var>が空癜区切りで䞎えられる。 <var>0</var>はゞョヌカヌ、<var>1</var>から<var>n</var>はカヌドに曞かれた敎数を衚す。 </p> <h3>制玄</h3> <ul> <li><var>1 &le; n &le; 100</var></li> <li><var>m_1+m_2+m_3 = 4n+1</var></li> <li>3人の手札で0はちょうど1぀、<var>1</var>から<var>n</var>はちょうど4回ず぀珟れる</li> <li><var>0 &le; c_{i,j} &le; n</var> (<var>1 &le; i &le; 3</var>, <var>1 &le; j &le; m_i</var>)</li> </ul> <h3>出力圢匏</h3> <p>園田さんが負けずならない確率を1行に出力せよ。答えには<var>10^{&minus;6}</var>を超える絶察誀差があっおはならない。</p> <h3>入力䟋1</h3> <pre> 1 1 1 3 0 1 1 1 1 </pre> <h3>出力䟋1</h3> <pre>0.0</pre> <p> 高坂さんが南さんのカヌド1を匕き、高坂さんず南さんは手札が空になる。 園田さんはどうしおも勝぀こずはできない。 </p> <h3>入力䟋2</h3> <pre> 1 2 1 1 1 1 2 0 1 </pre> <h3>出力䟋2</h3> <pre>0.5</pre> <p>はじめの高坂さんのタヌンは、高坂さんの手札が既に空なので䜕もしない。次の園田さんのタヌンでは、園田さんは南さんの手札のうちそれぞれ0.5の確率でカヌド1かゞョヌカヌを匕く。カヌド1を匕いたずき、園田さんの手札は空ずなり勝利する。䞀方ゞョヌカヌを匕いたずきは、次の南さんのタヌンで、南さんは確実にカヌド1を匕くので園田さんが負けずなる。</p> <h3>入力䟋3</h3> <pre> 2 3 0 1 2 3 1 2 2 3 1 1 2 </pre> <h3>出力䟋3</h3> <pre>0.5</pre> <h3>入力䟋4</h3> <pre> 2 2 0 1 6 2 2 2 1 1 1 1 2 </pre> <h3>出力䟋4</h3> <pre>0.6666666667</pre>
p00610
<H1><font color="#000000">Problem F:</font> Cleaning Robot 2.0</H1> <p> Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. </p> <p> First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has <i>N</i> &times; <i>N</i> rooms arranged in a square likewise. Then he laid either black or white carpet on each room. </p> <p> Since still enough money remained, he decided to spend them for development of a new robot. And finally he completed. </p> <p> The new robot operates as follows: </p> <ul> <li>The robot is set on any of <i>N</i> &times; <i>N</i> rooms, with directing any of north, east, west and south.</li> <li>The robot detects color of carpets of lefthand, righthand, and forehand adjacent rooms if exists. If there is exactly one room that its carpet has the same color as carpet of room where it is, the robot changes direction to and moves to and then cleans the room. Otherwise, it halts. Note that halted robot doesn't clean any longer. Following is some examples of robot's movement. <br> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cleaningRobot2"> <p>Figure 1. An example of the room</p> </center> <br> In Figure 1, <ul> <li>robot that is on room (1,1) and directing north directs east and goes to (1,2).</li> <li>robot that is on room (0,2) and directing north directs west and goes to (0,1).</li> <li>robot that is on room (0,0) and directing west halts.</li> </ul> </li> <li>Since the robot powered by contactless battery chargers that are installed in every rooms, unlike the previous robot, it never stops because of running down of its battery. It keeps working until it halts.</li> </ul> <p> Doctor's house has become larger by the renovation. Therefore, it is not efficient to let only one robot clean. Fortunately, he still has enough budget. So he decided to make a number of same robots and let them clean simultaneously. </p> <p> The robots interacts as follows: </p> <ul> <li> No two robots can be set on same room.</li> <li> It is still possible for a robot to detect a color of carpet of a room even if the room is occupied by another robot.</li> <li> All robots go ahead simultaneously.</li> <li> When robots collide (namely, two or more robots are in a single room, or two robots exchange their position after movement), they all halt. Working robots can take such halted robot away.</li> </ul> <p> On every room dust stacks slowly but constantly. To keep his house pure, he wants his robots to work so that dust that stacked on any room at any time will eventually be cleaned. </p> <p> After thinking deeply, he realized that there exists a carpet layout such that no matter how initial placements of robots are, this condition never can be satisfied. Your task is to output carpet layout that there exists at least one initial placements of robots that meets above condition. Since there may be two or more such layouts, please output the <i>K</i>-th one lexicographically. </p> <H2>Input</H2> <p> Input file contains several data sets. One data set is given in following format: </p> <pre> <i>N K</i> </pre> <p> Here, <i>N</i> and <i>K</i> are integers that are explained in the problem description. </p> <p> The end of input is described by a case where <i>N</i> = <i>K</i> = 0. You should output nothing for this case. </p> <H2>Output</H2> <p> Print the <i>K</i>-th carpet layout if exists, "<span>No</span>" (without quotes) otherwise. </p> <p> The carpet layout is denoted by <i>N</i> lines of string that each has exactly <i>N</i> letters. A room with black carpet and a room with white carpet is denoted by a letter '<span>E</span>' and '<span>.</span>' respectively. Lexicographically order of carpet layout is defined as that of a string that is obtained by concatenating the first row, the second row, ..., and the <i>N</i>-th row in this order. </p> <p> Output a blank line after each data set. </p> <p> </p> <H2>Constraints</H2> <ul> <li>Judge data consists of at most 100 data sets.</li> <li>1 &le; <i>N</i> &lt; 64</li> <li>1 &le; <i>K</i> &lt; 2<sup>63</sup></li> </ul> <H2>Sample Input</H2> <pre> 2 1 2 3 6 4 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> .. .. No ..EEEE ..E..E EEE..E E..EEE E..E.. EEEE.. </pre>
p00240
<H1>金利蚈算</H1> <p> 金利は銀行に預けおいるお金に付き、その蚈算方法や利率は銀行によっお様々です。利息ず元金を合わせたものを元利ず呌びたすが、元利の蚈算方法ずしお、利息を元金に組み入れずに蚈算する「単利」ず利息を元金に組み入れお蚈算する「耇利」ずいうものがあり、より倚くの元利を埗るためにはこの差異を理解しおいなければなりたせん。元利の蚈算方法は以䞋のようになりたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0240_1"><br> <br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0240_2"> </center> <br> <!-- <p> できれば、わずかな金利でもより倚くお金を増やしたいず思うものです。盞沢さんの家庭では、今たで預けおいた銀行は金利が䜎い事に気づき、新しい銀行に乗り換えようずしおいたす。しかし、盞沢さん䞀家は金利のこずに぀いおあたり詳しく知らなかったので、金利に詳しいあなたに助けを求めおきたした。比范すべき銀行の数は倚いうえ、盞沢さん䞀家以倖にも助けを求められそうです。䜜業を効率化するためにより良い銀行を蚈算するプログラムを䜜成しおおきたしょう。 </p> --> <p> 銀行の数、お金を預ける幎数、各銀行の情報銀行番号、金利の皮類、幎利率パヌセントを入力ずし、最も元利が高くなる銀行番号を出力するプログラムを䜜成しおください。ただし、最も元利が高くなる銀行は䞀぀だけです。 </p> <h2>入力</h2> <p> 耇数のデヌタセットが䞎えられたす。入力の終わりはれロひず぀で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>y</var> <var>b<sub>1</sub></var> <var>r<sub>1</sub></var> <var>t<sub>1</sub></var> <var>b<sub>2</sub></var> <var>r<sub>2</sub></var> <var>t<sub>2</sub></var> : <var>b<sub>n</sub></var> <var>r<sub>n</sub></var> <var>t<sub>n</sub></var> </pre> <p> 1行目に銀行の数 <var>n</var> (1 &le; <var>n</var> &le; 50)、2行目にお金を預ける幎数 <var>y</var> (1 &le; <var>y</var> &le; 30)が䞎えられたす。続く<var>n</var> 行に <var>i</var> 番目の銀行の銀行番号 <var>b<sub>i</sub></var>、幎利率を衚す敎数 <var>r<sub>i</sub></var> (1 &le; <var>r<sub>i</sub></var> &le; 100)、 金利の皮類 <var>t<sub>i</sub></var> (1 たたは 2) が䞎えられたす。金利の皮類 <var>t<sub>i</sub></var> は、単利の堎合は1、耇利の堎合は2で䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <h2>出力</h2> <p> デヌタセットごずに、最も元利が高くなる銀行番号を行に出力したす。 </p> <h2>入力䟋</h2> <pre> 2 8 1 5 2 2 6 1 2 9 1 5 2 2 6 1 0 </pre> <h2>出力䟋</h2> <pre> 2 1 </pre>
p03895
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi recorded his daily life for the last few days as a integer sequence of length <var>2N</var>, as follows:</p> <ul> <li><var>a_1, b_1, a_2, b_2, ... , a_N, b_N</var></li> </ul> <p>This means that, starting from a certain time <var>T</var>, he was:</p> <ul> <li>sleeping for exactly <var>a_1</var> seconds</li> <li>then awake for exactly <var>b_1</var> seconds</li> <li>then sleeping for exactly <var>a_2</var> seconds</li> <li>:</li> <li>then sleeping for exactly <var>a_N</var> seconds</li> <li>then awake for exactly <var>b_N</var> seconds</li> </ul> <p>In this record, he waked up <var>N</var> times.</p> <p>Takahashi is wondering how many times he waked up early during the recorded period.</p> <p>Here, he is said to <em>wake up early</em> if he wakes up between <var>4:00</var> AM and <var>7:00</var> AM, inclusive.</p> <p>If he wakes up more than once during this period, each of these awakenings is counted as waking up early.</p> <p>Unfortunately, he forgot the time <var>T</var>.</p> <p>Find the maximum possible number of times he waked up early during the recorded period.</p> <p>For your information, a day consists of <var>86400</var> seconds, and the length of the period between <var>4:00</var> AM and <var>7:00</var> AM is <var>10800</var> seconds.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq a_i, b_i \leq 10^5</var></li> <li><var>a_i</var> and <var>b_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>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>Print the maximum possible number of times he waked up early during the recorded period.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 28800 57600 28800 57600 57600 28800 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 28800 57600 4800 9600 6000 1200 600 600 300 600 5400 600 6000 5760 6760 2880 6000 12000 9000 600 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre></section> </div> </span>
p02787
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ibis is fighting with a monster.</p> <p>The <em>health</em> of the monster is <var>H</var>.</p> <p>Ibis can cast <var>N</var> kinds of spells. Casting the <var>i</var>-th spell decreases the monster's health by <var>A_i</var>, at the cost of <var>B_i</var> Magic Points.</p> <p>The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.</p> <p>Ibis wins when the health of the monster becomes <var>0</var> or below.</p> <p>Find the minimum total Magic Points that have to be consumed before winning.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H \leq 10^4</var></li> <li><var>1 \leq N \leq 10^3</var></li> <li><var>1 \leq A_i \leq 10^4</var></li> <li><var>1 \leq B_i \leq 10^4</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>H</var> <var>N</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total Magic Points that have to be consumed before winning.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>9 3 8 3 4 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>First, let us cast the first spell to decrease the monster's health by <var>8</var>, at the cost of <var>3</var> Magic Points. The monster's health is now <var>1</var>.</p> <p>Then, cast the third spell to decrease the monster's health by <var>2</var>, at the cost of <var>1</var> Magic Point. The monster's health is now <var>-1</var>.</p> <p>In this way, we can win at the total cost of <var>4</var> Magic Points.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 6 1 1 2 3 3 9 4 27 5 81 6 243 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>100 </pre> <p>It is optimal to cast the first spell <var>100</var> times.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>139815 </pre></section> </div> </span>
p02292
<H1>Counter-Clockwise</H1> <br/> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_CGL_CGL_1_C"> </center> <p> For given three points <var>p0, p1, p2</var>, print </p> <pre> COUNTER_CLOCKWISE </pre> <p> if <var>p0, p1, p2</var> make a counterclockwise turn (1), </p> <pre> CLOCKWISE </pre> <p> if <var>p0, p1, p2</var> make a clockwise turn (2), </p> <pre> ONLINE_BACK </pre> <p> if <var>p2</var> is on a line <var>p2, p0, p1</var> in this order (3), </p> <pre> ONLINE_FRONT </pre> <p> if <var>p2</var> is on a line <var>p0, p1, p2</var> in this order (4), </p> <pre> ON_SEGMENT </pre> <p> if <var>p2</var> is on a segment <var>p0p1</var> (5). </p> <H2>Input</H2> <pre> <var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>q</var> <var>x<sub>p2<sub>0</sub></sub></var> <var>y<sub>p2<sub>0</sub></sub></var> <var>x<sub>p2<sub>1</sub></sub></var> <var>y<sub>p2<sub>1</sub></sub></var> ... <var>x<sub>p2<sub>q-1</sub></sub></var> <var>y<sub>p2<sub>q-1</sub></sub></var> </pre> <p> In the first line, integer coordinates of <var>p0</var> and <var>p1</var> are given. Then, <var>q</var> queries are given for integer coordinates of <var>p2</var>. </p> <H2>Output</H2> <p> For each query, print the above mentioned status. </p> <H2>Constraints</H2> <ul> <li> <var>1 &le; q &le; 1000</var> </li> <li> <var>-10000 &le; x<sub>i</sub>, y<sub>i</sub> &le; 10000</var> </li> <li> <var>p0</var> and <var>p1</var> are not identical. </li> </ul> <H2>Sample Input 1</H2> <pre> 0 0 2 0 2 -1 1 -1 -1 </pre> <H2>Sample Output 1</H2> <pre> COUNTER_CLOCKWISE CLOCKWISE </pre> <br/> <H2>Sample Input 2</H2> <pre> 0 0 2 0 3 -1 0 0 0 3 0 </pre> <H2>Sample Output 2</H2> <pre> ONLINE_BACK ON_SEGMENT ONLINE_FRONT </pre> <br/>
p01847
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h3>カヌテン</h3> <p>もうすぐ倏がやっおくるあなたは倏に向けお郚屋の暡様替えをするこずにした今幎の倏はずおも日差しが匷いこずが予想されおおりたぶしいのが苊手なあなたには蟛い季節になりそうだそこであなたは郚屋の明るさを調節するために郚屋の窓にカヌテンを取り付けようず考えた </p> <p>取り付けるカヌテンは長方圢であり蟺が地面に察しお垂盎もしくは平行であるように取り付けるたたあなたの郚屋の窓は非垞に特殊な圢をしおおり各蟺が地面に平行たたは垂盎であるような <i>N</i> 角圢で衚されるそのためカヌテンを取り付けたずきにカヌテンに芆われおいない窓の面積がどのくらいになるのかを求めるのは難しい郚屋の明るさを調節するためにもカヌテンを取り付ける䜍眮を決めた時にどのくらい窓が芆えるかを知るこずは重芁であるそこであなたは窓ずカヌテンの蚭眮䜍眮ず圢状が䞎えられたずきにカヌテンに芆われおいない窓の面積を求めるプログラムを䜜るこずにした </p> <p>䟋ずしお次のような窓ずカヌテンの蚭眮の仕方を考えるこの堎合はカヌテンに隠れおいない窓の面積は 8 ずなるこの䟋はサンプル入力の 3 ケヌス目に察応する </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_window" witdh="400" height="400"><br/> </center> <h3>Input</h3> <p>入力は耇数デヌタセットからなる 各デヌタセットは次の圢匏で䞎えられる </p> <blockquote><i>N</i><br><i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br>:<br>:<br><i>x<sub>N</sub></i> <i>y<sub>N</sub></i><br><i>a<sub>1</sub></i> <i>b<sub>1</sub></i><br><i>a<sub>2</sub></i> <i>b<sub>2</sub></i><br><i>a<sub>3</sub></i> <i>b<sub>3</sub></i><br><i>a<sub>4</sub></i> <i>b<sub>4</sub></i></blockquote> <p>最初の行には窓の持぀頂点数を衚す敎数 <i>N</i> が䞎えられる (<i>4 &le; N &le; 100</i>)続く <i>N</i> 行には窓の盞異なる頂点のx座暙を衚す敎数 <i>x<sub>i</sub></i> ずy座暙を衚す敎数 <i>y<sub>i</sub></i> が䞎えられる (<i>-20,000 &le; x<sub>i</sub>, y<sub>i</sub> &le; 20,000, 1 &le; i &le; N</i>)ここでy軞の正の向きはx軞の正の向きから90床分反時蚈回りに回転させた方向ずするさらに続く 4 行にはカヌテンの盞異なる頂点のx座暙を衚す敎数 <i>a<sub>j</sub></i> ず y座暙を衚す敎数 <i>b<sub>j</sub></i> が䞎えられる (<i>-20,000 &le; a<sub>j</sub>, b<sub>j</sub> &le; 20,000, 1 &le; j &le; 4</i>)窓カヌテンずもにそれぞれの頂点は反時蚈回り順に䞎えられるたた窓カヌテンを衚す図圢はそれぞれ自己亀差がない図圢である </p> <p>入力の終わりは1぀の 0 からなる行で瀺す </p> <h3>Output</h3> <p>各デヌタセットに぀いおカヌテンに芆われおいない窓の面積を 1 行に出力せよただし面積は必ず敎数倀になるこずに泚意せよ </p> <h3>Sample Input</h3> <pre>4 0 0 10 0 10 10 0 10 0 0 5 0 5 10 0 10 6 0 0 10 0 10 5 5 5 5 10 0 10 2 0 8 0 8 10 2 10 12 1 1 1 3 -1 3 -1 1 -3 1 -3 -1 -1 -1 -1 -3 1 -3 1 -1 3 -1 3 1 2 2 -2 2 -2 -2 2 -2 4 20000 20000 -20000 20000 -20000 -20000 20000 -20000 1000 1000 -1000 1000 -1000 -1000 1000 -1000 4 1000 1000 -1000 1000 -1000 -1000 1000 -1000 20000 20000 -20000 20000 -20000 -20000 20000 -20000 4 0 0 10 0 10 10 0 10 20 0 30 0 30 10 20 10 0</pre> <h3>Output for Sample Input</h3> <pre>50 30 8 1596000000 0 100</pre>
p00755
<h3><U>Identically Colored Panels Connection</U></h3> <!-- end en only --> <div> <!-- please enclose each h3 level section with div --> <!-- begin en only --> <p> Dr. Fukuoka has invented fancy panels. Each panel has a square shape of a unit size and has one of the six colors, namely, yellow, pink, red, purple, green and blue. The panel has two remarkable properties. One property is that, when two or more panels with the same color are placed adjacently, their touching edges melt a little and they are fused each other. The fused panels are united into a polygonally shaped panel. The other property is that the color of a panel can be changed to one of six colors by giving an electrical shock. The resulting color can be controlled by its waveform. The electrical shock to an already united panel changes the color of the whole to a specified single color. </p> <p> Since he wants to investigate the strength with respect to the color and the size of a united panel compared to unit panels, he tries to unite panels into a polygonal panel with a specified color. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_1" align="center" width="200" height="120"><br> </center> <!-- begin en only --> <center> Figure C-1: panels and their initial colors<br><br> </center> <!-- end en only --> <!-- begin en only --> <p> Since many panels are simultaneously synthesized and generated on a base plate through some complex chemical processes, the fabricated panels are randomly colored and they are arranged in a rectangular shape on the base plate (Figure C-1). Note that the two purple (color 4) panels in Figure C-1 are already united at the initial state since they are adjacent to each other. </p> <p> Installing electrodes to a panel, and changing its color several times by giving electrical shocks according to an appropriate sequence for a specified target color, he can make a united panel merge the adjacent panels to unite them step by step and can obtain a larger panel with the target color. Unfortunately, panels will be broken when they are struck by the sixth electrical shock. That is, he can change the color of a panel or a united panel only five times. </p> <!-- end en only --> <!-- begin en only --> <p> Let us consider a case where the panel at the upper left corner of the panel configuration (Figure C-1) is attached with the electrodes. First, changing the color of the panel from yellow to blue, the two adjacent panels are fused into a united panel (Figure C-2). </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_2" align="center" width="200" height="120"><br> </center> <!-- begin en only --> <center> Figure C-2: Change of the color of the panel at the upper left corner, from yellow (color 1) to blue (color 6).<br><br> </center> <!-- end en only --> </p> <!-- begin en only --> <p> Second, changing the color of the upper left united panel from blue to red, a united red panel that consists of three unit panels is newly formed (Figure C-3). Then, changing the color of the united panel from red to purple, panels are united again to form a united panel of five unit panels (Figure C-4). </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_3" align="center" width="200" height="120"><br> </center> <!-- begin en only --> <center> Figure C-3: Change of the color of the panel at the upper left corner, from blue (color 6) to red (color 3). <br><br> </center> <!-- end en only --> </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_4" align="center" width="200" height="120"><br> </center> <!-- begin en only --> <center> Figure C-4: Change of the color of the panel at the upper left corner, from red (color 3) to purple (color 4). <br><br> </center> <!-- end en only --> </p> <!-- begin en only --> <p> Furthermore, through making a pink united panel in Figure C-5 by changing the color from purple to pink, then, the green united panel in Figure C-6 is obtained by changing the color from pink to green. The green united panel consists of ten unit panels. </p> <!-- end en only --> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_5" align="center" width="200" height="120"><br> </center> <!-- begin en only --> <center> Figure C-5: Change of the color of the panel at the upper left corner, from purple (color 4) to pink (color 2).<br><br> </center> <!-- end en only --> </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_6" align="center" width="200" height="120"><br> </center> <!-- begin en only --> <center> Figure C-6: Change of the color of the panel at the upper left corner, from pink (color 2) to green (color 5).<br><br> </center> <!-- end en only --> </p> <!-- begin en only --> <p> In order to check the strength of united panels with various sizes and colors, he needs to unite as many panels as possible with the target color. Your job is to write a program that finds a sequence to change the colors five times in order to get the largest united panel with the target color. Note that the electrodes are fixed to the panel at the upper left corner. </p> <!-- end en only --> </div> <h3>Input</h3> <div> <!-- begin en only --> <p> The input consists of multiple datasets, each being in the following format. </p> <!-- end en only --> <blockquote> <i>h</i> <i>w</i> <i>c</i><br> <i>p</i><sub>1,1</sub> <i>p</i><sub>1,2</sub> ... <i>p</i><sub>1,<i>w</i></sub><br> <i>p</i><sub>2,1</sub> <i>p</i><sub>2,2</sub> ... <i>p</i><sub>2,<i>w</i></sub><br> ...<br> <i>p</i><sub><i>h</i>,1</sub> <i>p</i><sub><i>h</i>,2</sub> ... <i>p</i><sub><i>h</i>,<i>w</i></sub><br> </blockquote> <!-- begin en only --> <i>h</i> and <i>w</i> are positive integers no more than 8 that represent the height and the width of the given rectangle. <i>c</i> is a positive integer no more than 6 that represents the target color of the finally united panel. <i>p</i><sub><i>i</i>,<i>j</i></sub> is a positive integer no more than 6 that represents the initial color of the panel at the position (<i>i</i>, <i>j</i>). <p>The end of the input is indicated by a line that consists of three zeros separated by single spaces. </p> <!-- end en only --> </div> <h3>Output</h3> <div> <!-- begin en only --> <p> For each dataset, output the largest possible number of unit panels in the united panel at the upper left corner with the target color after five times of color changes of the panel at the upper left corner. No extra characters should occur in the output. </p> <!-- end en only --> </div> <h3>Sample Input</h3> <div> <pre> 3 5 5 1 6 3 2 5 2 5 4 6 1 1 2 4 1 5 4 5 6 1 5 6 1 2 1 4 6 3 2 1 5 2 3 2 1 1 2 3 2 1 1 5 1 1 8 6 1 2 3 4 5 1 2 3 8 1 1 1 2 3 4 5 1 2 3 8 8 6 5 2 5 2 6 5 4 2 4 2 2 2 5 2 2 2 4 4 4 2 5 2 2 2 6 4 5 2 2 2 6 6 6 6 5 5 2 2 6 6 6 2 5 4 2 2 6 6 2 4 4 4 6 2 2 6 2 2 2 5 5 2 2 2 8 8 2 3 3 5 4 1 6 2 3 2 3 6 4 3 6 2 2 4 1 6 6 6 4 4 4 2 5 3 6 3 6 3 5 3 1 3 4 1 5 6 3 1 6 6 3 5 1 5 3 2 4 2 2 2 6 5 3 4 1 3 6 1 5 5 4 0 0 0 </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 10 18 1 5 6 64 33 </pre> </div>
p02768
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Akari has <var>n</var> kinds of flowers, one of each kind.</p> <p>She is going to choose one or more of these flowers to make a bouquet.</p> <p>However, she hates two numbers <var>a</var> and <var>b</var>, so the number of flowers in the bouquet cannot be <var>a</var> or <var>b</var>.</p> <p>How many different bouquets are there that Akari can make?</p> <p>Find the count modulo <var>(10^9 + 7)</var>.</p> <p>Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>2 \leq n \leq 10^9</var></li> <li><var>1 \leq a &lt; b \leq \textrm{min}(n, 2 \times 10^5)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>n</var> <var>a</var> <var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of bouquets that Akari can make, modulo <var>(10^9 + 7)</var>. (If there are no such bouquets, print <code>0</code>.)</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>In this case, Akari can choose <var>2</var> or <var>4</var> flowers to make the bouquet.</p> <p>There are <var>6</var> ways to choose <var>2</var> out of the <var>4</var> flowers, and <var>1</var> way to choose <var>4</var>, so there are a total of <var>7</var> different bouquets that Akari can make.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000000000 141421 173205 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>34076506 </pre> <p>Print the count modulo <var>(10^9 + 7)</var>.</p></section> </div> </span>
p00305
<h1>枠</h1> <p> 画像の䞭から有益な情報を抜出する画像認識はコンピュヌタサむ゚ンスの䞭でも重芁な研究テヌマのひず぀です。デゞタルカメラ、運転支揎システム、防犯システムなどに幅広く応甚されおいたす。 </p> <p> このような研究のおかげで、私たちは画像解析を行うための倚くの゜フトりェアやプログラム集を䜿い様々な凊理を行うこずができたす。䞀方、自力でプログラムを曞いお解析するこずで、その仕組みを知り、楜しい時間を過ごすこずができたす。ここでは、䞀颚倉わった画像認識をしおみたしょう。 </p> <p> 画像ずしお次のような各ピクセルが敎数の倀を持぀ <var>N</var> &times; <var>N</var> のピクセルが入力ずしお䞎えられたす。この画像の䞭から、線の倪さがピクセルの長方圢の枠わくを぀抜出したす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame1" width="380"> </center> <br> <p> 枠が芆うピクセルの倀の和が最倧ずなるような枠を抜出しお、その和を報告するプログラムを䜜成しお 䞋さい。ただし、䞋の図のように、瞊、暪のピクセル数が぀や぀の堎合も枠ずみなすものずしたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame2" width="560"> </center> <br> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>p<sub>1,1</sub></var> <var>p<sub>1,2</sub></var> ... <var>p<sub>1,N</sub></var> <var>p<sub>2,1</sub></var> <var>p<sub>2,2</sub></var> ... <var>p<sub>2,N</sub></var> : <var>p<sub>N,1</sub></var> <var>p<sub>N,2</sub></var> ... <var>p<sub>N,N</sub></var> </pre> <p> 行目に瞊ず暪のピクセル数 <var>N</var> (1 &le; <var>N</var> &le; 300) が䞎えられる。続く <var>N</var> 行に、<var>i</var> 行 <var>j</var> 列目のピクセルの倀を衚す敎数 <var>p<sub>i,j</sub></var> (-1000 &le; <var>p<sub>i,j</sub></var> &le; 1000)が䞎えられる。 </p> <h2>出力</h2> <p> ピクセル倀の和が最倧ずなるような枠の、ピクセル倀の和を行に出力する。 </p> <h2>入出力䟋</h2> <br> <h2>入力䟋</h2> <pre> 5 2 0 0 2 0 0 1 0 2 0 0 0 0 -1 0 0 4 0 3 0 -1 0 0 1 0 </pre> <h2> 出力䟋 </h2> <pre> 12 </pre> <h2>入力䟋</h2> <pre> 3 0 0 0 0 -1 0 0 0 0 </pre> <h2>出力䟋</h2> <pre> 0 </pre>
p02338
<!--<h1>写像12盾 その8:ボヌルに区別あり・箱に区別なし・箱の䞭身は1぀以䞋</h1>--> <h1>Balls and Boxes 8</h1> <table border=""> <tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr> <tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr> <tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr> <tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td style="background-color:#aff">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 distinguished from the other.</li> <li>Each box is <b>not</b> distinguished from the other.</li> <li>Each ball can go into only one box and no one remains outside of the boxes.</li> <li>Each box can contain at most one ball.</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 10 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 200 100 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre>
p03483
<span class="lang-en"> <p>Score : <var>800</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. Determine whether we can turn <var>S</var> into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 2 × 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>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 we cannot turn <var>S</var> into a palindrome, print <code>-1</code>. Otherwise, print the minimum required number of operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>eel </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>We can turn <var>S</var> into a palindrome by the following operation:</p> <ul> <li>Swap the <var>2</var>-nd and <var>3</var>-rd characters. <var>S</var> is now <code>ele</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>ataatmma </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p>We can turn <var>S</var> into a palindrome by the following operation:</p> <ul> <li>Swap the <var>5</var>-th and <var>6</var>-th characters. <var>S</var> is now <code>ataamtma</code>.</li> <li>Swap the <var>4</var>-th and <var>5</var>-th characters. <var>S</var> is now <code>atamatma</code>.</li> <li>Swap the <var>3</var>-rd and <var>4</var>-th characters. <var>S</var> is now <code>atmaatma</code>.</li> <li>Swap the <var>2</var>-nd and <var>3</var>-rd characters. <var>S</var> is now <code>amtaatma</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>snuke </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre> <p>We cannot turn <var>S</var> into a palindrome.</p></section> </div> </span>
p03179
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>N</var> be a positive integer. You are given a string <var>s</var> of length <var>N - 1</var>, consisting of <code>&lt;</code> and <code>&gt;</code>.</p> <p>Find the number of permutations <var>(p_1, p_2, \ldots, p_N)</var> of <var>(1, 2, \ldots, N)</var> that satisfy the following condition, modulo <var>10^9 + 7</var>:</p> <ul> <li>For each <var>i</var> (<var>1 \leq i \leq N - 1</var>), <var>p_i &lt; p_{i + 1}</var> if the <var>i</var>-th character in <var>s</var> is <code>&lt;</code>, and <var>p_i &gt; p_{i + 1}</var> if the <var>i</var>-th character in <var>s</var> is <code>&gt;</code>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an integer.</li> <li><var>2 \leq N \leq 3000</var></li> <li><var>s</var> is a string of length <var>N - 1</var>.</li> <li><var>s</var> consists of <code>&lt;</code> and <code>&gt;</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of permutations that satisfy the condition, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 &lt;&gt;&lt; </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are five permutations that satisfy the condition, as follows:</p> <ul> <li><var>(1, 3, 2, 4)</var></li> <li><var>(1, 4, 2, 3)</var></li> <li><var>(2, 3, 1, 4)</var></li> <li><var>(2, 4, 1, 3)</var></li> <li><var>(3, 4, 1, 2)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 &lt;&lt;&lt;&lt; </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>There is one permutation that satisfies the condition, as follows:</p> <ul> <li><var>(1, 2, 3, 4, 5)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>20 &gt;&gt;&gt;&gt;&lt;&gt;&gt;&gt;&lt;&gt;&gt;&lt;&gt;&gt;&gt;&lt;&lt;&gt;&gt; </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>217136290 </pre> <p>Be sure to print the number modulo <var>10^9 + 7</var>.</p></section> </div> </span>
p01144
<!-- begin en only --> <h3><U> Princess' Marriage </U></h3> <!-- end en only --> <!-- begin ja only --> <h3><U> お姫様の嫁入り </U></h3> <!-- end ja only --> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> ある貧乏な囜のおおんばで勇敢なお姫様はギャンブルの配圓がパリミュチュ゚ル方匏で決定される事を知るこずによりギャンブルに぀いお詳しくなった気がしおギャンブルでの勝利を確信したその結果今たでよりも曎に倚額のお金を぀ぎ蟌み囜民が玍めた皎金をすべお倱うほどの負けを喫しおしたったこの事態を重く受け止めた王様はお姫様を隣の囜ぞ嫁がせるこずにしたこうするこずによりお姫様を日頃の行いを反省させ同時に隣囜ずの亀友を深めお財政揎助をしおもらおうず考えたからである </p> <p> お姫様ず隣囜の王子様はお互いの事が気に入りたた䞡囜の王様間でも政略結婚に関する同意がなされたお姫様はなけなしのお金を手に意気揚々ず隣の囜ぞ出かけた䞀方でお姫様が嫁ぐ動機は王様の䞀方的な利益远及のためであり快くないず考える隣囜の王子様の偎近はお姫様を亡き者にするために道の途䞭に無数の刺客達を攟った </p> <p> お姫様が通る道はすでに決められおいるお姫様の通る道には合蚈 <i>L</i> 個の宿堎がある䟿宜䞊出発地点および到着地点も宿堎ずし各宿堎を <i>S<sub>1</sub></i>, <i>S<sub>2</sub></i>, ... <i>S<sub>L</sub></i> ず呌ぶこずにするお姫様は最初に <i>S<sub>1</sub></i> におり昇順に (<i>S<sub>2</sub></i>, <i>S<sub>3</sub></i> ... ずいう順番で) 宿堎を蚪れお最終的に <i>S<sub>L</sub></i> ぞ行くものずする宿堎では金銭を払っお護衛を雇うこずができお金がある限り奜きな距離だけ契玄しおお姫様を守らせるこずができる護衛を雇う費甚は距離1に぀き金1であるお姫様は通る区間内を郚分的に守っおもらうこずも出来るこずに泚意せよ<i>S<sub>i</sub></i>ず<i>S<sub>i+1</sub></i>間の距離は<i>D<sub>i</sub></i><i>S<sub>i</sub></i>ず<i>S<sub>i+1</sub></i>間で距離1に぀き刺客に襲われる回数の期埅倀は<i>P<sub>i</sub></i>で䞎えられおいる </p> <p> お姫様が予算<i>M</i>を持っおいお刺客に襲われる回数の期埅倀が最小になるように護衛を雇ったずきの目的地たでに刺客に襲われる回数の期埅倀を求めよ </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋のような圢匏をずる </p> <blockquote> <i>N</i> <i>M</i><br> <i>D<sub>1</sub></i> <i>P<sub>1</sub></i><br> <i>D<sub>2</sub></i> <i>P<sub>2</sub></i><br> ...<br> <i>D<sub>N</sub></i> <i>P<sub>N</sub></i> </blockquote> 各デヌタセットの最初の行には二぀の敎数が䞎えられそれぞれ区間の数 <i>N</i>(1≩<i>N</i>≩10,000) ずお姫差が持぀予算 <i>M</i>(0≩<i>M</i>≩1,000,000,000) を衚す次の <i>N</i> 行はお姫様が通る道の情報を衚す各行は二぀の敎数が含たれおおり<i>i</i>行目は区間の距離 <i>D<sub>i</sub></i>(1≩<i>D<sub>i</sub></i>≩10,000) ずその間を単䜍距離移動したずきに襲われる回数の期埅倀 <i>P<sub>i</sub></i>(0≩<i>P<sub>i</sub></i><=10) からなる 入力の終端は <i>N</i>=0, <i>M</i>=0 ずなるデヌタセットであらわされるこのデヌタセットに察しおは蚈算結果を出力しおはならない <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセット毎にお姫様が目的地たでに刺客に襲われる回数の期埅倀を出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 5 140 </pre>
p03529
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider the following game:</p> <ul> <li>The game is played using a row of <var>N</var> squares and many stones.</li> <li>First, <var>a_i</var> stones are put in Square <var>i\ (1 \leq i \leq N)</var>.</li> <li>A player can perform the following operation as many time as desired: "Select an integer <var>i</var> such that Square <var>i</var> contains exactly <var>i</var> stones. Remove all the stones from Square <var>i</var>, and add one stone to each of the <var>i-1</var> squares from Square <var>1</var> to Square <var>i-1</var>."</li> <li>The final score of the player is the total number of the stones remaining in the squares.</li> </ul> <p>For a sequence <var>a</var> of length <var>N</var>, let <var>f(a)</var> be the minimum score that can be obtained when the game is played on <var>a</var>.</p> <p>Find the sum of <var>f(a)</var> over all sequences <var>a</var> of length <var>N</var> where each element is between <var>0</var> and <var>K</var> (inclusive). Since it can be extremely large, find the answer modulo <var>1000000007 (= 10^9+7)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq K \leq N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of <var>f(a)</var> modulo <var>1000000007 (= 10^9+7)</var>.</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>10 </pre> <p>There are nine sequences of length <var>2</var> where each element is between <var>0</var> and <var>2</var>. For each of them, the value of <var>f(a)</var> and how to achieve it is as follows:</p> <ul> <li><var>f(\{0,0\})</var>: <var>0</var> (Nothing can be done)</li> <li><var>f(\{0,1\})</var>: <var>1</var> (Nothing can be done)</li> <li><var>f(\{0,2\})</var>: <var>0</var> (Select Square <var>2</var>, then Square <var>1</var>)</li> <li><var>f(\{1,0\})</var>: <var>0</var> (Select Square <var>1</var>)</li> <li><var>f(\{1,1\})</var>: <var>1</var> (Select Square <var>1</var>)</li> <li><var>f(\{1,2\})</var>: <var>0</var> (Select Square <var>1</var>, Square <var>2</var>, then Square <var>1</var>)</li> <li><var>f(\{2,0\})</var>: <var>2</var> (Nothing can be done)</li> <li><var>f(\{2,1\})</var>: <var>3</var> (Nothing can be done)</li> <li><var>f(\{2,2\})</var>: <var>3</var> (Select Square <var>2</var>)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>20 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>983853488 </pre></section> </div> </span>
p01514
<!-- begin en only --> <h3><u>You Are the Judge </u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>審刀は君だ </u></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> あなたはプログラミングコンテスト iCPC の審刀だ。今日も䜕事もなく詊合が終わり、埌は結果を出力するだけだず思いきや、突然システムが停止しおしたった  </p> <p> これでは結果が出力できない でも、倧䞈倫。我々にはログがある。 </p> <p> あなたは優れたプログラマヌであり、か぀お iCPC で茝かしい成瞟を残したこずもある。 </p> <p> そこであなたはシステムログから各チヌムの成瞟を割り出し、チヌムの順䜍衚を出力するプログラムを䜜成するこずにした。 </p> <p> 入力ずしおチヌムの数、問題の数、システムログが䞎えられる。 </p> <p> シムテムログは以䞋の 2 皮類のレコヌドからなる。 </p> <table> <thead><tr><th style="padding: .5em; background: #069; color: #fff">レコヌド</th><th style="padding: .5em; background: #069; color: #fff">内容</th><th style="padding: .5em; background: #069; color: #fff">効果</th></tr></thead> <tbody><tr><td style="padding: .5em; background: #0cf">tID pID time CORRECT</td><td style="padding: .5em; background: #0cf"> 時刻 time に、チヌム tID が 問題 pID に正解するプログラムを送信。 </td><td style="padding: .5em; background: #0cf"> チヌム tID の正解数に1が加算される。<br>チヌム tID のペナルティに、(チヌム tID の問題 pID に察する誀答数*1200+time)が加算される。<br> 以埌, チヌム tID の問題 pID に察する解答は棄华され、システムログにも送信履歎が残らない。 </td></tr></tbody> <tbody><tr><td style="padding: .5em; background: #0cf">tID pID time WRONG</td><td style="padding: .5em; background: #0cf"> 時刻 time に、チヌム tID が 問題 pID に誀答するプログラムを送信。 </td><td style="padding: .5em; background: #0cf"> チヌム tID の 問題 pID に察する誀答数に1が加算される。 </td></tr></tbody> </table> <p> ※䞊蚘のシステムログはこの問題のために簡略化されたものであり、本番のICPCで芋られるシステムログず異なるこずに留意せよ </p> <p> iCPCにおける順䜍付けのルヌルは以䞋の通りである。 </p> <ul> <li>より倚くの問題を解いたチヌムは順䜍が䞊になる</li> <li>解いた問題が同じ堎合、ペナルティの少ないチヌムのほうが順䜍が䞊になる</li> <li>解いた問題もペナルティも同じ堎合、チヌム番号が小さいほうのチヌムが順䜍が䞊になる</li> </ul> <p> 入力より䞎えられるコンテストの情報・システムログから各チヌムの成瞟を割り出し、チヌムの順䜍衚を出力せよ。 </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は耇数のデヌタセットからなる。各デヌタセットは以䞋の圢匏で䞎えられる。 </p> <blockquote> <var>T</var> <var>P</var> <var>R</var><br/> <var>tID<sub>1</sub></var> <var>pID<sub>1</sub></var> <var>time<sub>1</sub></var> <var>message<sub>1</sub></var><br/> <var>tID<sub>2</sub></var> <var>pID<sub>2</sub></var> <var>time<sub>2</sub></var> <var>message<sub>2</sub></var><br/> <var>...</var><br/> <var>tID<sub>R</sub></var> <var>pID<sub>R</sub></var> <var>time<sub>R</sub></var> <var>message<sub>R</sub></var><br/> </blockquote> <p> デヌタセットの1行目には 参加チヌム数 T 、問題数 P、システムログのレコヌド数 R が含たれる。 </p> <p> 続くR行にはシステムログの各レコヌドが含たれる。 </p> <p> システムログのレコヌドずしお、チヌム番号 tID<sub>i</sub>、問題番号 pID<sub>i</sub>、詊合開始からの経過時間 time<sub>i</sub>、メッセヌゞの皮類 message<sub>i</sub> が含たれる。 </p> <p> 入力は以䞋の制玄を満たす。 </p> <ul> <li>1 &#8804; T &#8804; 50</li> <li>1 &#8804; P &#8804; 10</li> <li>1 &#8804; R &#8804; 500</li> <li>1 &#8804; tID<sub>i</sub> &#8804; T</li> <li>1 &#8804; pID<sub>i</sub> &#8804; P</li> <li>1 &#8804; time<sub>i</sub> &#8804; 10800</li> <li>message<sub>i</sub> は CORRECT, WRONGのいずれか</li> <li>システムログのレコヌドは、時刻の小さいものから順に䞎えられ、耇数のレコヌドの時刻が同じになるこずはない</li> </ul> <p> 入力の終わりはスペヌスで区切られた3個の0で䞎えられる。 </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 䞎えられたシステムログより各チヌムの成瞟・順䜍を割り出し、順䜍が䞊のチヌムから順に、チヌム番号、正解数、ペナルティ を出力せよ。 </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 3 3 5 3 1 800 WRONG 1 1 1200 CORRECT 3 1 1400 CORRECT 1 2 2400 CORRECT 1 3 3600 CORRECT 5 2 5 3 1 1000 WRONG 5 2 2000 CORRECT 3 1 2800 CORRECT 4 1 4000 CORRECT 5 1 5000 CORRECT 6 3 15 2 1 10 WRONG 3 3 15 WRONG 3 3 20 CORRECT 1 1 50 CORRECT 4 2 60 WRONG 1 2 70 WRONG 4 1 80 CORRECT 1 2 90 WRONG 1 2 150 CORRECT 3 1 160 WRONG 3 1 180 CORRECT 3 2 210 WRONG 5 3 500 CORRECT 4 2 720 CORRECT 5 1 1500 CORRECT 0 0 0 </pre> <!-- begin ja only --> <!-- end ja only --> </div> <h3>Output for Sample Input</h3> <div> <pre> 1 3 7200 3 1 2600 2 0 0 5 2 7000 3 1 4000 4 1 4000 1 0 0 2 0 0 4 2 2000 5 2 2000 1 2 2600 3 2 2600 2 0 0 6 0 0 </pre> <!-- begin ja only --> <!-- end ja only --> </div>
p03207
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In some other world, today is the day before Christmas Eve.</p> <p>Mr. Takaha is buying <var>N</var> items at a department store. The regular price of the <var>i</var>-th item <var>(1 \leq i \leq N)</var> is <var>p_i</var> yen (the currency of Japan).</p> <p>He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining <var>N-1</var> items cost their regular prices. What is the total amount he will pay?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10</var></li> <li><var>100 \leq p_i \leq 10000</var></li> <li><var>p_i</var> is an even number.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>p_1</var> <var>p_2</var> <var>:</var> <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total amount Mr. Takaha will pay.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4980 7980 6980 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>15950 </pre> <p>The <var>7980</var>-yen item gets the discount and the total is <var>4980 + 7980 / 2 + 6980 = 15950</var> yen.</p> <p>Note that outputs such as <code>15950.0</code> will be judged as Wrong Answer.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4320 4320 4320 4320 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>15120 </pre> <p>Only one of the four items gets the discount and the total is <var>4320 / 2 + 4320 + 4320 + 4320 = 15120</var> yen.</p></section> </div> </span>
p04038
<span class="lang-en"> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke loves colorful balls. He has a total of <var>N×K</var> balls, <var>K</var> in each of his favorite <var>N</var> colors. The colors are numbered <var>1</var> through <var>N</var>.</p> <p>He will arrange all of the balls in a row from left to right, in arbitrary order. Then, for each of the <var>N</var> colors, he will paint the leftmost ball of that color into color <var>0</var>, a color different from any of the <var>N</var> original colors.</p> <p>After painting, how many sequences of the colors of the balls are possible? Find this number modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀N,K≀2,000</var></li> </ul> </section> </div> <hr> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the possible sequences of the colors of the balls after painting, modulo <var>10^9+7</var>.</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>4 </pre> <p>The following <var>4</var> sequences are possible:</p> <ul> <li><var>(0,1,0,2)</var></li> <li><var>(0,0,1,2)</var></li> <li><var>(0,2,0,1)</var></li> <li><var>(0,0,2,1)</var></li> </ul> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>The following <var>1</var> sequence is possible:</p> <ul> <li><var>(0,0,0)</var></li> </ul> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>14 </pre> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2000 2000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>546381702 </pre></section> </div> </hr></hr></hr></hr></hr></span>
p03657
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is giving cookies to his three goats.</p> <p>He has two cookie tins. One contains <var>A</var> cookies, and the other contains <var>B</var> cookies. He can thus give <var>A</var> cookies, <var>B</var> cookies or <var>A+B</var> cookies to his goats (he cannot open the tins).</p> <p>Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A,B \leq 100</var></li> <li>Both <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 it is possible to give cookies so that each of the three goats can have the same number of cookies, print <code>Possible</code>; otherwise, print <code>Impossible</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Possible </pre> <p>If Snuke gives nine cookies, each of the three goats can have three cookies.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Impossible </pre> <p>Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.</p></section> </div> </span>
p02945
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have two integers: <var>A</var> and <var>B</var>.</p> <p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>-100 \leq A,\ B \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>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>-13 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>-10 </pre> <p>The largest number among <var>A + B = -10</var>, <var>A - B = -16</var>, and <var>A \times B = -39</var> is <var>-10</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 -33 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>34 </pre> <p>The largest number among <var>A + B = -32</var>, <var>A - B = 34</var>, and <var>A \times B = -33</var> is <var>34</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>13 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>39 </pre> <p>The largest number among <var>A + B = 16</var>, <var>A - B = 10</var>, and <var>A \times B = 39</var> is <var>39</var>.</p></section> </div> </span>
p00978
<h2>Sixth Sense</h2> <p> Ms. Future is gifted with precognition. Naturally, she is excellent at some card games since she can correctly foresee every player's actions, except her own. Today, she accepted a challenge from a reckless gambler Mr. Past. They agreed to play a simple two-player trick-taking card game. </p> <p> Cards for the game have a number printed on one side, leaving the other side blank making indistinguishable from other cards. </p> <p> A game starts with the same number, say $n$, of cards being handed out to both players, without revealing the printed number to the opponent. </p> <p> A game consists of $n$ tricks. In each trick, both players pull one card out of her/his hand. The player pulling out the card with the larger number takes this trick. Because Ms. Future is extremely good at this game, they have agreed to give tricks to Mr. Past when both pull out cards with the same number. Once a card is used, it can never be used later in the same game. The game continues until all the cards in the hands are used up. The objective of the game is to take as many tricks as possible. </p> <p> Your mission of this problem is to help Ms. Future by providing a computer program to determine the best playing order of the cards in her hand. Since she has the sixth sense, your program can utilize information that is not available to ordinary people before the game. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $p_1$ ... $p_n$ $f_1$ ... $f_n$ </pre> <p> $n$ in the first line is the number of tricks, which is an integer between 2 and 5000, inclusive. The second line represents the Mr. Past's playing order of the cards in his hand. In the $i$-th trick, he will pull out a card with the number $p_i$ ($1 \leq i \leq n$). The third line represents the Ms. Future's hand. $f_i$ ($1 \leq i \leq n$) is the number that she will see on the $i$-th received card from the dealer. Every number in the second or third line is an integer between 1 and 10 000, inclusive. These lines may have duplicate numbers. </p> <h3>Output</h3> <p> The output should be a single line containing $n$ integers $a_1 ... a_n$ separated by a space, where $a_i$ ($1 \leq i \leq n$) is the number on the card she should play at the $i$-th trick for maximizing the number of taken tricks. If there are two or more such sequences of numbers, output the lexicographically greatest one among them. </p> <h3>Sample Input 1</h3> <pre> 5 1 2 3 4 5 1 2 3 4 5 </pre> <h3> Sample Output 1</h3> <pre> 2 3 4 5 1 </pre> <h3>Sample Input 2</h3> <pre> 5 3 4 5 6 7 1 3 5 7 9 </pre> <h3>Sample Output 2</h3> <pre> 9 5 7 3 1 </pre> <h3>Sample Input 3</h3> <pre> 5 3 2 2 1 1 1 1 2 2 3 </pre> <h3>Sample Output 3</h3> <pre> 1 3 1 2 2 </pre> <h3>Sample Input 4</h3> <pre> 5 3 4 10 4 9 2 7 3 6 9 </pre> <h3> Sample Output 4</h3> <pre> 9 7 3 6 2 </pre>
p01390
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1><font color="#000">問題 C </font> しりずり</h1> <h2>問題文</h2> <p>なんずなく暇だったのでしりずりの AI を䜜っお AI ずしりずりをするこずにしたしりずりずは <var>2</var> 人で遊ぶゲヌムで䞡者の間でただ䞀床も発蚀されおおらず(最初の手番を陀いお) 先頭の文字が盎前の単語の最埌の文字ずなっおいる単語を亀互に蚀い合うゲヌムである</p> <p>今回 AI に単語の刀定を実装するのが面倒だったので単語の定矩はアルファベットの小文字からなる文字列党おずした</p> <p>しかし AI が完成したあたりでしりずりをするのは面倒くさくなっおきたのでプログラムを曞いお自分の代わりに AI ず察戊させるこずにしたプログラムを曞くのは良いのだが目暙が無いのは぀たらないのでなるべく早く AI に勝぀プログラムを曞くこずにしたすなわちなるべく少ないやりずりで AI に䞍正な応答をさせるプログラムを曞くのである</p> <p>なおプログラムが先手で AI が埌手である</p> <h2>入出力</h2> <p>プログラムはしりずりの単語を発蚀するずAI の返答を聞くこずができる 䟋えば C/C++ で <tt>abc</tt> ず単語を発蚀するには</p> <pre>printf("?abc\n"); fflush(stdout);</pre> <p>ずする次に</p> <pre>scanf("%s", str);</pre> <p>ずするず <var>str</var> に AI の返答が入る</p> <p>最終的に AI の誀りを指摘するには <tt>!OUT</tt> ず出力するこず誀りを指摘するのは間違った発蚀の盎埌でなければならない誀りを指摘した時点でプログラムを終了させ䞍芁な出力は䞀切行っおはいけない誀りの指摘が正しければプログラムは正解 (<i>Accepted</i>) ず刀定される単語の応答が䞍適切であったりAI ぞの誀りの指摘が正しくない堎合AI の誀りを指摘しなかった堎合は誀答 (<i>Wrong Answer</i>) ず刀定される</p> <h2>制玄</h2> <ul> <li>プログラムの䜿っお良い単語の長さは <var>1</var> 文字以䞊 <var>10</var> 文字以䞋である</li> <li>AI の䜿う単語の長さは <var>1</var> 文字以䞊 <var>2</var> 文字以䞋である</li> <li>プログラムは最倧で <var>50</var> 回たで発蚀するこずが出来るそれを超えるず誀答 (<i>Query Limit Exceeded</i>) ずなる</li> <li>AIプログラム䞡者ずも単語に䜿っお良い文字はアルファベットの小文字のみである </li> <li>AI の返答はアルファベットの小文字のみからなる</li> <li>最初の手番ではプログラムはどのアルファベットからしりずりを開始しおも良い</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <p> 以䞋の䟋はプログラムの入出力の䟋である巊の列がプログラムの出力右の列がプログラムぞの入力 (AI の発蚀) を衚す最初にプログラムは <tt>abcdefghij</tt> ずいう単語を蚀っおいるその応答ずしお AI は <tt>jk</tt> ず返しおる<var>3</var> 回目の応答の際に AI はすでに䜿われおいる <tt>jk</tt> ずいう単語を発しおいるのでそれに察しおプログラムは <tt>!OUT</tt> ず蚀っお AI の誀りを指摘しおいる </p> <div class="reactive-example"> <table class="withborder"> <tr><th>プログラムの出力</th><th>プログラムぞの入力</th></tr> <tr><td>?abcdefghij</td><td></td></tr> <tr><td></td><td>jk</td></tr> <tr><td>?kkkk</td><td></td></tr> <tr><td></td><td>kl</td></tr> <tr><td>?lj</td><td></td></tr> <tr><td></td><td>jk</td></tr> <tr><td>!OUT</td><td></td></tr> </table> </div> <br> <h3>入力䟋 2</h3> <p> 以䞋の䟋ではAI が <tt>aaa</tt> ずいう単語に察しお <tt>bb</tt> ずしりずりにならない返答をしおいるため <tt>!OUT</tt> ず返しおいる </p> <div class="reactive-example"> <table class="withborder"> <tr><th>プログラムの出力</th><th>プログラムぞの入力</th></tr> <tr><td>?aaa</td><td></td></tr> <tr><td></td><td>bb</td></tr> <tr><td>!OUT</td><td></td></tr> </table> </div> <br>
p02416
<H1>Sum of Numbers</H1><br> <p> Write a program which reads an integer and prints sum of its digits. </p> <H2>Input</H2> <p> The input consists of multiple datasets. For each dataset, an integer <var>x</var> is given in a line. The number of digits in <var>x</var> does not exceed 1000. </p> <p> The input ends with a line including single zero. Your program should not process for this terminal symbol. </p> <H2>Output</H2> <p> For each dataset, print the sum of digits in <var>x</var>. </p> <H2>Sample Input</H2> <pre> 123 55 1000 0 </pre> <H2>Sample Output</H2> <pre> 6 10 1 </pre>
p02046
<h3>避けるべし</h3> <!-- begin ja only --> <p>あなたはいた䞊䞋巊右に広倧に広がるマス目の原点に圓たる䜍眮 <i>(0, 0)</i> にいるマスの䜍眮は<i>x</i>座暙ず<i>y</i>座暙で衚され右に1マス動くこずが<i>x</i>座暙が1぀増えるこずに察応し䞊に1マス動くこずが<i>y</i>座暙が1぀増えるこずに察応するあなたはこれから目的地であるマス <i>(x, y)</i> を目指しお出発するずころだあなたは 1 歩で䞊䞋巊右斜めの 8 方向に隣接するマスに移動するこずができる</p> <p>さあ目的地に向かっお移動開始だずあなたは意気蟌んでいるずころかもしれないがちょっず埅っおほしい䞀぀だけ先に忠告しおおくこずがあるそれはこのマス目に朜む謎の人物回り蟌みのプロ・廻小宮の存圚だ廻小宮はあなたが 1 歩移動したのを確認するずあなたが進んだ方向のさらに 1 歩先のマスに瞬時に移動し邪魔をしおくるより正確に蚀えばあなたがマス <i>(x<sub>s</sub>, y<sub>s</sub>) </i>から <i>(x<sub>t</sub>, y<sub>t</sub>)</i> に移動するずき廻小宮は <i>(x<sub>t</sub> + (x<sub>t</sub> - x<sub>s</sub>), y<sub>t</sub> + (y<sub>t</sub> - y<sub>s</sub>))</i> に移動する明らかに異様な雰囲気を醞し出す廻小宮ダツの間合いに入り蟌むのは危険だ回り蟌たれた盎埌は仕方ないずしお次に移動する先のマスあるいはその 8 方向に隣接するマスのどれかに廻小宮がすでにいるずダツの間合いに入り蟌んでしたうこずになるのでこれはどうしおも避けたい</p> <p>䞊蚘のように廻小宮の間合いを避け぀぀目的地に蟿り着くためには最小で䜕歩必芁だろうかあなたの仕事はこの最小歩数を求めるプログラムを曞くこずだただし廻小宮は初期状態ではどのマスにも存圚せず最初の 1 歩目以降から䞊蚘のルヌルに埓ったマスに珟れるものずする</p> <p>最初のサンプルではあなたは <i>(2, 0)</i> を目指す䟋えば最初に右暪のマス<i>(1, 0)</i> に移動しおしたうず廻小宮が <i>(2, 0)</i> に回り蟌んでくるため次にそのマスぞず移動するこずができない䞀方最初に右斜め䞊の <i>(1, 1)</i> に移動するず廻小宮の䜍眮は <i>(2, 2)</i> ずなり <i>(2, 0)</i> が廻小宮の間合いではないため次の 1 歩で <i>(2, 0)</i> に移動するこずができる</p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2019_C" width="600pt"></center></p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットからなる 各デヌタセットは 2 ぀の敎数 <i>x</i>, <i>y</i> からなる 1 行で衚されるこれは目的地のマスが䜍眮 <i>(x, y)</i> であるこずを衚し<i>|x|, |y| &le; 10<sup>9</sup></i> を満たす</p> <p>入力の終わりは EOF (ファむルの終端) で衚される 党デヌタセットの総数は 50 を超えない</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>条件を満たすように移動を繰り返すずきマス <i>(0, 0)</i> からマス <i>(x, y)</i> に移動するために必芁な最小歩数を 1 行に出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>2 0 2 2 1 -1 0 0 0 -5 173 207 </pre><h3>Output for the Sample Input</h3><pre>2 4 1 0 6 379 </pre>
p00581
<h1>勇者ビ倪郎(Bitaro the Brave)</h1> <p> 勇者のビ倪郎は魔王ず察峙するこずずなった </p> <p> ビ倪郎は瞊$H$ 行暪$W$ 列のマス目䞊に宝石(Jewel)オヌブ(Orb)金塊(Ingot) を配眮し魔法を発動するこずによっお魔王に攻撃をしようずしおいる以䞋マス目のうち䞊から$i$ 行目($1 \leq i \leq H$)巊から$j$ 列目($1 \leq j \leq W$) のマスをマス($i, j$) ず衚す </p> <p> ビ倪郎は今それぞれのマスにこれら3 皮類のうち1 個を配眮した今から魔法を発動しようずしおいるがこの魔法の嚁力はマス目䞊の宝石オヌブ金塊の配眮によっお決たる具䜓的には次の条件を満たす敎数($i, j, k, l$) ($1 \leq i < k \leq H, 1 \leq j < l \leq W$) の組の個数が魔法の嚁力である<br/> <br/> 条件マス($i, j$) には宝石がマス($i, l$) にはオヌブがマス($k, j$) には金塊が眮かれおいる<br/> </p> <p> ビ倪郎はこの魔法の嚁力が気になっおいる </p> <p> マス目䞊の宝石オヌブ金塊の配眮が䞎えられたずきビ倪郎が発動する魔法の嚁力を求めるプログラムを䜜成せよ </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で暙準入力から䞎えられる </p> <pre> $H$ $W$ $S_1$ : $S_H$ </pre> <p> $S_i$ ($1 \leq i \leq H$) は長さ$W$ の文字列でその$j$ 文字目($1 \leq j \leq W$) がJ のずきはマス($i, j$) に宝石がO の ずきはマス($i, j$) にオヌブがI のずきはマス($i, j$) に金塊が眮かれおいるこずを衚す </p> <h2>出力</h2> <p> 暙準出力に魔法の嚁力を衚す敎数を1 行で出力せよ </p> <h2>制玄</h2> <ul> <li>$2 \leq H \leq 3 000$</li> <li>$2 \leq W \leq 3 000$</li> <li>$S_i$ は長さ$W$ の文字列である($1 \leq i \leq H$)</li> <li>$S_i$ の各文字はJOI のいずれかである($1 \leq i \leq H$)</li> </ul> <!-- 小課題 1. (20 点) H ≩ 100W ≩ 100 2. (30 点) H ≩ 500W ≩ 500 3. (50 点) 远加の制玄はない --> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 3 4 JOIJ JIOO IIII </pre> <h3>出力䟋1</h3> <pre> 3 </pre> <p>この入力䟋では($i, j, k, l$) = (1, 1, 3, 2), (2, 1, 3, 3), (2, 1, 3, 4) の3 個の組が条件を満たすので答えは3 である </p> <h3>入力䟋2 </h3> <pre> 4 4 JJOO JJOO IIJO IIIJ </pre> <h3>出力䟋2</h3> <pre> 17 </pre> <br/> <p> <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> <br/> <a href="https://www.ioi-jp.org/joi/2018/2019-ho/index.html">情報オリンピック日本委員䌚䜜 『第18 回日本情報オリンピック(JOI 2018/2019) 本遞』</a> </p>
p00094
<H1>坪面積の蚈算</H1> <p> 土地の面積を衚珟する「○○坪」ずいう単䜍を聞いたこずはないでしょうか 叀来、人の歊士が日に食べるお米を䜜る面積を蚀いたした。 </p> <p> <var>a</var>m&times; <var>b</var>mの土地がありたす。<var>a</var> ず <var>b</var> を入力し、その土地の坪面積 <var>S</var>坪を出力するプログラムを䜜成しおください。 1 坪 = 3.305785 [m<sup>2</sup>] ずし、<var>a</var> ず <var>b</var> は 100 以䞋の敎数ずしたす。 </p> <H2>入力</H2> <pre> <var>a</var> <var>b</var> </pre> <p> ぀の空癜で区切られた <var>a</var> ず <var>b</var> が行に䞎えられる。 </p> <H2>出力</H2> <p> 坪面積 <var>S</var> を行に出力する。0.0001 以䞋の誀差が蚱される。 </p> <H2>入力䟋1</H2> <pre> 15 25 </pre> <H2>出力䟋1</H2> <pre> 113.437508 </pre>
p02553
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are integers <var>a,b,c</var> and <var>d</var>. If <var>x</var> and <var>y</var> are integers and <var>a \leq x \leq b</var> and <var>c\leq y \leq d</var> hold, what is the maximum possible value of <var>x \times y</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>-10^9 \leq a \leq b \leq 10^9</var></li> <li><var>-10^9 \leq c \leq d \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>a</var> <var>b</var> <var>c</var> <var>d</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>1 2 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>If <var>x = 1</var> and <var>y = 1</var> then <var>x \times y = 1</var>. If <var>x = 2</var> and <var>y = 1</var> then <var>x \times y = 2</var>. Therefore, the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 -4 -2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-6 </pre> <p>The answer can be negative.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>-1000000000 0 -1000000000 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000000000000 </pre></section> </div> </span>
p02103
<h1>Problem F: Great Devil Sakanikia</h1> <h2>Problem</h2> <p> 倧悪魔サカヌニャは今日も倩敵の猫に襲われおいた。<br> い぀もやられおいる蚳にはいかないので、秘密兵噚を賌入した。<br> この秘密兵噚は、巚倧な岩を生成するこずで猫の移動経路を塞ぎ、猫がこちらに近づけないようにするこずができる。<br> </p> <p> 今、サカヌニャず䞀匹の猫がマス(0,0),(<var>n</var>&minus;1,0),(<var>n</var>&minus;1,<var>m</var>&minus;1),(0,<var>m</var>&minus;1)で囲たれた長方圢の閉区間内にいる。<br> マス(0,0)に猫、マス(<var>n</var>&minus;1,<var>m</var>&minus;1)にサカヌニャがいる。<br> 猫は䞊䞋巊右の隣接したマスに移動するこずができるが、区間倖に出るこずはできない。<br> いく぀かのマスは、穎や障害物の圱響で䟵入するこずができない。<br> サカヌニャは、あるマスに1぀岩を生成するこずでそのマスに猫が䟵入できなくするこずができる。<br> ただし、マス(0,0)ずマス(<var>n</var>&minus;1,<var>m</var>&minus;1)に岩を生成するこずはできない。 </p> <p> マス(0,0)からマス(<var>n</var>&minus;1,<var>m</var>&minus;1)たでの移動経路を塞ぐために必芁な、生成する岩の数の最小倀を求めよ。 </p> <h2>Input</h2> <pre> <var>n</var> <var>m</var> <var>k</var> <var>x</var><sub>1</sub> <var>y</var><sub>1</sub> ... <var>x<sub>k</sub></var> <var>y<sub>k</sub></var> </pre> <p> 入力はすべお敎数で䞎えられる。<br> 1行目にマスの倧きさを衚す぀の敎数<var>n</var>ず<var>m</var>、䟵入できないマスの数<var>k</var>が空癜区切りで䞎えられる。<br> 2行目から<var>k</var>行に䟵入できないマスの座暙が䞎えられる。 </p> <h2>Constraints</h2> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li>2 &le; <var>n</var>,<var>m</var> &le; 10<sup>5</sup></li> <li>0 &le; <var>k</var> &le; min(<var>n</var>&times;<var>m</var>&minus;2,10<sup>5</sup>)</li> <li>0 &le; <var>x<sub>i</sub></var> &le; <var>n</var> &minus; 1</li> <li>0 &le; <var>y<sub>i</sub></var> &le; <var>m</var> &minus; 1</li> <li>(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>) &ne; (<var>x<sub>j</sub></var>,<var>y<sub>j</sub></var>) (<var>i</var> &ne; <var>j</var>)</li> <li>(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>) &ne; (0,0) &ne; (<var>n</var>&minus;1,<var>m</var>&minus;1)</li> </ul> <h2>Output</h2> <p> マス(0,0)からマス(<var>n</var>&minus;1,<var>m</var>&minus;1)たでの移動経路を塞ぐために必芁な、生成する岩の数の最小倀を1行に出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 3 5 2 0 2 2 2 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 5 5 3 0 2 2 2 4 1 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre>
p01685
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>Problem Statement</h3> <p>You have a rectangular board with square cells arranged in $H$ rows and $W$ columns. The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right. The cell at the row $i$ and the column $j$ is denoted by $(i, j)$. Each cell on the board is colored in either Black or White. </p> <p>You will paint the board as follows: </p><ol><li><p> Choose a cell $(i, j)$ and a color $c$, each uniformly at random, where $1 \le i \le H$, $1 \le j \le W$, and $c \in \{{\rm Black}, {\rm White}\}$. </p></li><li><p> Paint the cells $(i', j')$ with the color $c$ for any $1 \le i' \le i$ and $1 \le j' \le j$. </p></li></ol> <p>Here's an example of the painting operation. You have a $3 \times 4$ board with the coloring depicted in the left side of the figure below. If your random choice is the cell $(2, 3)$ and the color Black, the board will become as shown in the right side of the figure. $6$ cells will be painted with Black as the result of this operation. Note that we count the cells "painted" even if the color is not actually changed by the operation, like the cell $(1, 2)$ in this example. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2013_fig_overwrite" height="175" width="640" /><br/> Fig: An example of the painting operation </center> <br/> <p>Given the initial coloring of the board and the desired coloring, you are supposed to perform the painting operations repeatedly until the board turns into the desired coloring. Write a program to calculate the expected total number of painted cells in the sequence of operations. </p> <h3>Input</h3> <p>The input consists of several datasets. The number of datasets is at most $100$. </p> <p>The first line of each dataset contains two integers $H$ and $W$ ($1 \le H, W \le 5$), the numbers of rows and columns of the board respectively. Then given are two coloring configurations of the board, where the former is the initial coloring and the latter is the desired coloring. A coloring configuration is described in $H$ lines, each of which consists of $W$ characters. Each character is either B or W, denoting a Black cell or a White cell, respectively. There is one blank line between two configurations, and also after each dataset. You can assume that the resulting expected value for each dataset will not exceed $10^9$. </p> <p>The input is terminated by a line with two zeros, and your program should not process this as a dataset. </p> <h3>Output</h3> <p>For each dataset, your program should output the expected value in a line. The absolute error or the relative error in your answer must be less than $10^{-6}$. </p> <h3>Sample Input</h3> <pre>1 2 BB WW 2 1 B W B W 2 2 BW BW WW WW 3 4 BBBB BBBB BBBB WWWW WWWW WWWW 5 5 BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBWB BBBBB BWBBB BBBBB 0 0</pre> <h3>Output for the Sample Input</h3> <pre>6.0000000000 0.0000000000 12.8571428571 120.0000000000 23795493.8449918639</pre>
p00997
<h1>Problem H : Dungeon (II)</h1> <p> あなたはずあるゲヌムの開発に携わっおいる。 そのゲヌムはランダムに生成されたダンゞョンをプレむダヌが探玢するずいうものである。 ゲヌムの仕様ずしお、プレむダヌに予めダンゞョンの危険床を提瀺し、生成されたダンゞョンを探玢するのか、それずも新しくダンゞョンを生成しなおすかを、遞択できるようにしたい。 </p> <p> このゲヌムで生成されるダンゞョンには<i>n</i> 個の郚屋が存圚しおおり、0から <i>n-1</i> たでの番号が割り振られおいる。 郚屋ず郚屋は通路で結ばれおいる。郚屋ず郚屋を結ぶ通路は、合蚈で <i>n-1</i> 本存圚しおいる。 通路はどちらの方向ぞも進むこずができる。 たた、郚屋ず郚屋の間には距離が蚭定されおいる。 生成されたダンゞョンではいく぀かの通路を経由しお、ある郚屋から他のすべおの郚屋ぞ行くこずが可胜である。 そしお、プレむダヌがゲヌムを行う際に、぀の異なる郚屋がスタヌト地点ずゎヌル地点ずしお遞ばれる。 </p> <p> あなたはダンゞョンの評䟡を行うために、危険床の評䟡方法を決めるこずにした。 たず、ある郚屋から別の郚屋たでに移動する際の危険床を、郚屋間を最短で移動するために䜿う通路の䞭で、最もコスト高い通路の倀ずする。 そしお、ダンゞョンの危険床を、<i>i</i> &lt; <i>j</i> ずなる郚屋のペアの間を移動する際の危険床の総和ずするこずにした。 </p> <p> ランダムに生成されたダンゞョンのが入力ずしお䞎えられる。 たず、<i>i</i> &lt; <i>j</i> ずなるすべおの郚屋のペアに぀いお、移動する際の危険床を蚈算しお欲しい。 そしお、その総和を問題の答えずしお出力せよ。 </p> <h2>Input</h2> <p> 入力は以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>n</i> <i>a<sub>1</sub></i> <i>b<sub>1</sub></i> <i>c<sub>1</sub></i> . . . <i>a<sub>n-1</sub></i> <i>b<sub>n-1</sub></i> <i>c<sub>n-1</sub></i> </pre> <p> <i>a<sub>i</sub></i> <i>b<sub>i</sub></i> <i>c<sub>i</sub></i> は 郚屋 <i>a<sub>i</sub></i> ず <i>b<sub>i</sub></i> を結ぶ通路の距離が<i>c<sub>i</sub></i>であるこずを衚す。 </p> <p> 入力は以䞋の制玄を満たす<br> 2 &le; <i>n</i> &le; 200,000 <br> 0 &le; <i>a<sub>i</sub></i>,<i>b<sub>i</sub></i> &lt; <i>n</i><br> 0 &le; <i>c<sub>i</sub></i> &le; 100,000<br> </p> <h2>Output</h2> <p> 答えの倀を1行に出力せよ </p> <h2>Sample Input 1</h2> <pre> 4 0 1 3 1 2 5 1 3 2 </pre> <h2>Sample Output 1</h2> <pre> 23 </pre> <h2>Sample Input 2</h2> <pre> 6 0 2 5 2 1 1 2 3 10 3 5 4 3 4 2 </pre> <h2>Sample Output 2</h2> <pre> 111 </pre>
p03342
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an integer sequence <var>A</var> of length <var>N</var>.</p> <p>Find the number of the pairs of integers <var>l</var> and <var>r</var> (<var>1 \leq l \leq r \leq N</var>) that satisfy the following condition:</p> <ul> <li><var>A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r</var></li> </ul> <p>Here, <var>xor</var> denotes the bitwise exclusive OR.</p> <p><details> <summary style="display:list-item">Definition of XOR</summary></details></p> <p>The XOR of integers <var>c_1, c_2, ..., c_m</var> is defined as follows:</p> <ul> <li>Let the XOR be <var>X</var>. In the binary representation of <var>X</var>, the digit in the <var>2^k</var>'s place (<var>0 \leq k</var>; <var>k</var> is an integer) is <var>1</var> if there are an odd number of integers among <var>c_1, c_2, ...c_m</var> whose binary representation has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> if that number is even.</li> </ul> <p>For example, let us compute the XOR of <var>3</var> and <var>5</var>. The binary representation of <var>3</var> is <var>011</var>, and the binary representation of <var>5</var> is <var>101</var>, thus the XOR has the binary representation <var>110</var>, that is, the XOR is <var>6</var>.</p> <p></p></section></div></span>
p03712
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a image with a height of <var>H</var> pixels and a width of <var>W</var> pixels. Each pixel is represented by a lowercase English letter. The pixel at the <var>i</var>-th row from the top and <var>j</var>-th column from the left is <var>a_{ij}</var>.</p> <p>Put a box around this image and output the result. The box should consist of <code>#</code> and have a thickness of <var>1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ H, W ≀ 100</var></li> <li><var>a_{ij}</var> is a lowercase English letter.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>a_{11}</var> <var>...</var> <var>a_{1W}</var> <var>:</var> <var>a_{H1}</var> <var>...</var> <var>a_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the image surrounded by a box that consists of <code>#</code> and has a thickness of <var>1</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 abc arc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>##### #abc# #arc# ##### </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 z </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>### #z# ### </pre></section> </div> </span>
p02800
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have an <var>H \times W</var> grid, where each square is painted white or black in the initial state. Given are strings <var>A_1, A_2, ..., A_H</var> representing the colors of the squares in the initial state. For each pair <var>(i, j)</var> (<var>1 \leq i \leq H</var>, <var>1 \leq j \leq W</var>), if the <var>j</var>-th character of <var>A_i</var> is <code>.</code>, the square at the <var>i</var>-th row and <var>j</var>-th column is painted white; if that character is <code>#</code>, that square is painted black.</p> <p>Among the <var>2^{HW}</var> ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo <var>998,244,353</var>.</p> <ul> <li>Choose one row, then paint all the squares in that row white.</li> <li>Choose one row, then paint all the squares in that row black.</li> <li>Choose one column, then paint all the squares in that column white.</li> <li>Choose one column, then paint all the squares in that column black.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H, W \leq 10</var></li> <li><var>|A_i| = W</var> (<var>1 \leq i \leq H</var>)</li> <li>All strings <var>A_i</var> consist of <code>.</code> and <code>#</code>.</li> <li><var>H</var> and <var>W</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>H</var> <var>W</var> <var>A_1</var> <var>A_2</var> <var>\vdots</var> <var>A_H</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>2 2 #. .# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>15 </pre> <p>For example, if we paint the second row black, the grid becomes:</p> <pre>#. ## </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 ... ... ... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>230 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 4 #... ...# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>150 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 7 ....... ....... .#..... ..#.... .#.#... ....... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>203949910 </pre></section> </div> </span>
p00217
<H1>りォヌキング</H1> <p> 䌚接リバヌサむドホスピタルでは、リハビリず健康増進のため、入院患者が䞀日二回のりォヌキングを行っおいたす。元気に退院するために、りォヌキングで䜓力を回埩しようず頑匵る人が日に日に増えきたこずから、院長が「䞀日で䞀番長い距離を歩いた人にプレれントをあげよう!」ずいう䌁画を立ち䞊げたした。 </p> <!-- <p> 䌚接リバヌサむドホスピタルでは、リハビリず健康増進のため、入院患者が䞀日二回のりォヌキングを行っおいたす。元気に退院するために、りォヌキングで䜓力を回埩しようず頑匵る人が日に日に増えおいきたした。健康になるに぀れ、気持ちも明るく笑顔も芋られるようになったこずから、院長先生が、 「䞀日で䞀番長い距離を歩いた人にプレれントをあげよう!」ずいう䌁画を立ち䞊げたした。 </p> --> <p> 患者の数 <var>n</var> (1 &le; <var>n</var> &le; 10000)、それぞれの患者の番号 <var>p<sub>i</sub></var> (1 &le; <var>p<sub>i</sub></var> &le; 10000)、䞀回目に歩いた距離 <var>d1<sub>i</sub></var>、二回目に歩いた距離 <var>d2<sub>i</sub></var> (0 &le; <var>d1<sub>i</sub></var>, <var>d2<sub>i</sub></var> &le; 5000) を入力ずし、歩いた距離の合蚈が最も長い患者の番号ずその距離を出力するプログラムを䜜成しおください。ただし、䞀日に歩いた距離が同じ患者はいないものずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>p<sub>1</sub></var> <var>d1<sub>1</sub></var> <var>d2<sub>1</sub></var> <var>p<sub>2</sub></var> <var>d1<sub>2</sub></var> <var>d2<sub>2</sub></var> : <var>p<sub>n</sub></var> <var>d1<sub>n</sub></var> <var>d2<sub>n</sub></var> </pre> <p> 入力はすべお敎数で䞎えられたす。デヌタセットの数は50 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、最も長い合蚈距離を歩いた患者の番号ずその歩いた距離を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 5 263 2345 2504 1 3210 1985 5000 1501 4132 10000 503 3107 51 1758 2690 3 345 5000 2396 7 3910 1590 6789 2525 3616 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5000 5633 345 7396 </pre>
p02380
<H1>Triangle</H1><br> <p> For given two sides of a triangle <i>a</i> and <i>b</i> and the angle <i>C</i> between them, calculate the following properties: </p> <ul> <li><var>S</var>: Area of the triangle</li> <li><var>L</var>: The length of the circumference of the triangle</li> <li><var>h</var>: The height of the triangle with side <var>a</var> as a bottom edge</li> </ul> <H2>Input</H2> <p> The length of <i>a</i>, the length of <i>b</i> and the angle <i>C</i> are given in integers. </p> <H2>Output</H2> <p> Print <var>S</var>, <var>L</var> and <var>h</var> in a line respectively. The output should not contain an absolute error greater than 10<sup>-4</sup>. </p> <H2>Sample Input</H2> <pre> 4 3 90 </pre> <H2>Sample Output</H2> <pre> 6.00000000 12.00000000 3.00000000 </pre>
p03968
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer the deer has <var>N</var> square tiles. The tiles are numbered <var>1</var> through <var>N</var>, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the <var>1000</var> colors, which are represented by the integers <var>0</var> between <var>999</var>. The top-left, top-right, bottom-right and bottom-left corner of the tile with the number <var>i</var> are painted in color <var>C_{i,0}, C_{i,1}, C_{i,2}</var> and <var>C_{i,3}</var>, respectively, when seen in the direction of the number written on the tile (See Figure <var>1</var>).</p> <div style="text-align: center;"> <img src="https://atcoder.jp/img/arc062/b8ec940254d280135500dab6d00d4370.png"> <p>Figure <var>1</var>: The correspondence between the colors of a tile and the input</p> </img></div> <p>AtCoDeer is constructing a cube using six of these tiles, under the following conditions:</p> <ul> <li>For each tile, the side with the number must face outward.</li> <li>For each vertex of the cube, the three corners of the tiles that forms it must all be painted in the same color.</li> </ul> <p>Help him by finding the number of the different cubes that can be constructed under the conditions. Since each tile has a number written on it, two cubes are considered different if the set of the used tiles are different, or the tiles are used in different directions, even if the formation of the colors are the same. (Each tile can be used in one of the four directions, obtained by <var>90°</var> rotations.) Two cubes are considered the same only if rotating one in the three dimensional space can obtain an exact copy of the other, including the directions of the tiles.</p> <div style="text-align: center;"> <img src="https://atcoder.jp/img/arc062/8c7552f20698dab0aad52bba476fe6d7.png"> <p>Figure <var>2</var>: The four directions of a tile</p> </img></div> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>6≩N≩400</var></li> <li><var>0≩C_{i,j}≩999 (1≩i≩N , 0≩j≩3)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>C_{1,0}</var> <var>C_{1,1}</var> <var>C_{1,2}</var> <var>C_{1,3}</var> <var>C_{2,0}</var> <var>C_{2,1}</var> <var>C_{2,2}</var> <var>C_{2,3}</var> <var>:</var> <var>C_{N,0}</var> <var>C_{N,1}</var> <var>C_{N,2}</var> <var>C_{N,3}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different cubes that can be constructed under the conditions.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 0 1 2 3 0 4 6 1 1 6 7 2 2 7 5 3 6 4 5 7 4 0 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>The cube below can be constructed.</p> <p><img alt="" src="https://atcoder.jp/img/arc062/094fbca5395bfaaea28c98c51230693b.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>144 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 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> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>122880 </pre></section> </div> </span>
p01955
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <H1> Permutation Period </H1> <p> You have a permutation $p$ of $N$ integers. Initially $p_i = i$ holds for $1 \leq i \leq N$. For each $j$ ($1 \leq j \leq N$), let's denote $p_{j}^0 = j$ and $p_{j}^k = p_{p_j}^{k-1}$ for any $k\geq 1$. The <i>period</i> of $p$ is defined as the minimum positive integer $k$ which satisfies $p_{j}^k = j$ for every $j$ ($1 \leq j \leq N$). </p> <p> You are given $Q$ queries. The $i$-th query is characterized by two distinct indices $x_i$ and $y_i$. For each query, swap $p_{x_i}$ and $p_{y_i}$ and then calculate the period of updated $p$ modulo $10^9 + 7$ in the given order. </p> <p> It can be proved that the period of $p$ always exists. </p> <H2>Input</H2> <p> The input consists of a single test case of the following format. </p> <pre> $N$ $Q$ $x_1$ $y_1$ ... $x_Q$ $y_Q$ </pre> <p> The first line consists of two integers $N$ and $Q$ ($2 \leq N \leq 10^5, 1 \leq Q \leq 10^5$). The ($i+1$)-th line consists of two integers $x_i$ and $y_i$ ($1 \leq x_i, y_i \leq N, x_i \ne y_i$). </p> <H2>Output</H2> <p> Print the answer in one line for each query. </p> <H2>Sample Input 1</H2> <pre> 5 4 2 5 2 4 1 3 1 2 </pre> <H2>Output for Sample Input 1</H2> <pre> 2 3 6 5 </pre> <p> $p$ changes as follows: $[1,2,3,4,5] \rightarrow [1,5,3,4,2] \rightarrow [1,4,3,5,2] \rightarrow [3,4,1,5,2] \rightarrow [4,3,1,5,2]$. </p> <H2>Sample Input 2</H2> <pre> 2 2 1 2 1 2 </pre> <H2>Output for Sample Input 2</H2> <pre> 2 1 </pre> <p> $p$ changes as follows: $[1,2] \rightarrow [2,1] \rightarrow [1,2]$. </p> <H2>Sample Input 3</H2> <pre> 10 10 5 6 5 9 8 2 1 6 8 1 7 1 2 6 8 1 7 4 8 10 </pre> <H2>Output for Sample Input 3</H2> <pre> 2 3 6 4 6 7 12 7 8 9 </pre>
p00647
<h1>Problem A: It's our delight!!</h1> <p> You are a student of University of Aizu. And you work part-time at a restaurant. </p> <p> Staffs of the restaurant are well trained to be delighted to provide more delicious products faster. </p> <p> The speed providing products particularly depends on skill of the staff. So, the manager of the restaurant want to know how long it takes to provide products. </p> <p> Though some restaurants employ a system which calculates how long it takes to provide products automatically, the restaurant where you work employs a system which calculates it manually. </p> <p> You, a student of University of Aizu, want to write a program to calculate it, and you hope that your program makes the task easier. You are given the checks in a day. If the length of time it takes to provide the products of a check is shorter than or equal to 8 minutes, it is "ok" check. Write a program to output the ratio of "ok" checks to the total in percentage. </p> <h2>Input</h2> <p> The input consists of multiple datasets. The last dataset is followed by a line containing a single zero. You don't have to process this data. The first line of each dataset contains a single integer <i>n</i>. <p> <i>n</i> (0 &lt; <i> n </i> &le; 100) is the number of checks. Each of following <i> n </i> lines gives the details of a check in the following format. <pre> <i>hh:mm MM</i> </pre> <p> <i>hh:mm</i> is the clock time to print the check. <i>MM</i> is minute of the clock time to provide products. The clock time is expressed according to the 24 hour clock.<br> For example, "eleven one PM" is expressed by "23:01".<br> You can assume that the all of products are provided within fifteen minutes. The restaurant is open from AM 11:00 to AM 02:00. After AM 02:00, no check is printed. Also at AM 02:00, no check is printed. </p> <h2>Output</h2> <p> Your program has to print in the following format for each dataset. </p> <pre> lunch <i>L</i> dinner <i>D</i> midnight <i>M</i> </pre> <p> <i> L </i> is ratio of "ok" check printed to the total in lunch time. <i> D </i> is ratio of "ok" check printed to the total in dinner time. <i> M </i> is ratio of "ok" check printed to the total in midnight time. You can truncate digits number after the decimal point of the ratio on the percentage. Lunch, dinner, and midnight times are defined as follows: </p> <pre> Lunch time is 11:00 ~ 14:59. Dinner time is 18:00 ~ 20:59. Midnight time is 21:00 ~ 01:59. </pre> <p> If a check is not printed in the three range of time, you don't have to process it. If no check is in the range of time, you should print "no guest". </p> <h2>Sample input</h2> <pre> 5 12:57 59 20:12 15 12:19 21 18:52 03 16:09 14 0 </pre> <h2>Sample output</h2> <pre> lunch 100 dinner 50 midnight no guest </pre> <h2>Hint</h2> <p> If you want to read three integers in the following format,<br> integer:integer(space)integer<br> you can read them by scanf("%d%*c%d%d",&a, &b, &c); in C. </p> <!-- <hr> <div class="dat" style="font-size:10pt"> The University of Aizu Programming Contest 2011<br> Problemsetter: Tetsuya Shiota<br> </div> -->
p01406
<h2> Problem I: カスタムペむント職人 </h2> <p> slipはずあるレヌシングゲヌムの動画が奜きである。 ずいっおも、車が走っおいる動画が奜きであるわけではなく、このゲヌムに搭茉されたカスタムペむントカヌ䜜成ずいう機胜によっお、車䜓をカスタマむズする動画が奜きなのである。 これは、円や倚角圢などずいった基本的な幟䜕孊図圢を重ねあわせるこずで、車䜓にカスタムペむントができる機胜である。 </p> <p> このカスタムペむントによっお様々なアヌトを創りだす、いわゆる職人ず呌ばれる人々がいる。 職人達の手にかかれば、車䜓にガリガリしたアむスキャンディヌのキャラクタヌや、アむドルをプロデュヌスしお楜しむゲヌムのキャラクタヌを創りだすこずなど造䜜もない事である。 職人の車は、オヌクションで高倀で取匕をされるほどである。 </p> <p> その䞭でも、slipがお気に入りの職人がいる。 その職人は、扇圢の図圢のみで様々なアヌトを創り出しおいる。 その職人は扇圢を䜕枚も重ねあわせるこずで、自由自圚に圢を創り出しおいる。 </p> <p> ある日slipは、職人が䜜るアヌトにおいお、扇圢が䞀番倚く重なっおいる郚分で䜕枚あるのか気になりだした。 そこで、手䜜業で数えようず思ったのだが、枚数が倚かったために諊めおしたった。 </p> <p> そこで、勝手に友人ず思っおいるあなたに、プログラムを䜜っおもらうこずにした。 あなたの仕事は、䞎えられた扇圢の䜍眮情報から、最倧䜕枚の重なりがあるのか調べるこずである。 ここでは、扇圢同士が接しおいる堎合も重なっおいるものずする。 </p> <h2> Input </h2> <p> デヌタセットの入力は以䞋の圢匏である。 </p> <pre> <i>n</i> <i>m<sub>1</sub></i> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>r<sub>1</sub></i> <i>s<sub>1</sub></i> <i>t<sub>1</sub></i> <i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>r<sub>2</sub></i> <i>s<sub>2</sub></i> <i>t<sub>2</sub></i> ... <i>x<sub>i</sub></i> <i>y<sub>i</sub></i> <i>r<sub>i</sub></i> <i>s<sub>i</sub></i> <i>t<sub>i</sub></i> ... <i>x<sub>m<sub>1</sub></sub></i> <i>y<sub>m<sub>1</sub></sub></i> <i>r<sub>m<sub>1</sub></sub></i> <i>s<sub>m<sub>1</sub></sub></i> <i>t<sub>m<sub>1</sub></sub></i> ... <i>m<sub>i</sub></i> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>r<sub>1</sub></i> <i>s<sub>1</sub></i> <i>t<sub>1</sub></i> <i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>r<sub>2</sub></i> <i>s<sub>2</sub></i> <i>t<sub>2</sub></i> ... <i>x<sub>m<sub>i</sub></sub></i> <i>y<sub>m<sub>i</sub></sub></i> <i>r<sub>m<sub>i</sub></sub></i> <i>s<sub>m<sub>i</sub></sub></i> <i>t<sub>m<sub>i</sub></sub></i> <i>m<sub>t</sub></i> ... <i>x<sub>m<sub>t</sub></sub></i> <i>y<sub>m<sub>t</sub></sub></i> <i>r<sub>m<sub>t</sub></sub></i> <i>s<sub>m<sub>t</sub></sub></i> <i>t<sub>m<sub>t</sub></sub></i> </pre> <p> <i>n</i>(<i>0 &lt; n &le; 50</i>)はテストケヌスの個数、 <i>m<sub>i</sub></i>(<i>0 &lt; m<sub>i</sub> &le; 16</i>)は貌られおいる扇圢の枚数、 <i>x<sub>i</sub></i>(<i>0 &le; x<sub>i</sub> &le; 500</i>)は扇圢の頂点のx座暙、 <i>y<sub>i</sub></i>(<i>0 &le; y<sub>i</sub> &le; 500</i>)は扇圢の頂点のy座暙、 <i>r<sub>i</sub></i>(<i>0 &lt; r<sub>i</sub> &le; 100</i>)は扇圢の半埄、 <i>s<sub>i</sub></i>(<i>0 &le; s<sub>i</sub> &lt; 360</i>)は扇圢の䞭心角の開始角床(degree)、 <i>t<sub>i</sub></i>(<i>0 &le; t<sub>i</sub> &lt; 360</i>)は扇圢の䞭心角の終了角床(degree) を衚す。 </p> <p> たたすべお敎数である。 ここで䞎えられる扇圢は必ずしも<i>s &lt; t</i>ずは限らない。 <i>s &lt; t</i>ず<i>s &gt; t</i>の堎合の図をそれぞれ図1,2に衚す。 </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I1"> </td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I2"> </td> </tr> <tr> <td> <center>図1</center> </td> <td> <center>図2</center> </td> </tr> </table> </center> <p> ただし入力には図3のように、線ず線がぎったりに重なる入力は無いものずする。 </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I3"> </td> </tr> <tr> <td> <center>図3</center> </td> </tr> </table> </center> <h2> Output </h2> <p> 各デヌタセットに察し、扇圢が重なっおいる郚分の最倧枚数を衚瀺せよ。 </p> <h2> Sample Input </h2> <pre> 3 3 17 12 7 340 180 26 22 10 150 270 27 13 5 100 230 3 0 0 8 0 90 10 10 8 180 0 50 50 5 180 270 2 10 10 5 0 270 0 0 30 0 90 </pre> <h2> Output for Sample Input </h2> <pre> 3 2 2 </pre> <h2> Hint </h2> <p> ここでサンプルの1぀目は図4のように配眮されおいる </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I4"> </td> </tr> <tr> <td> <center>図4</center> </td> </tr> </table> </center>
p03591
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ringo is giving a present to Snuke.</p> <p>Ringo has found out that Snuke loves <em>yakiniku</em> (a Japanese term meaning grilled meat. <em>yaki</em>: grilled, <em>niku</em>: meat). He supposes that Snuke likes grilled things starting with <code>YAKI</code> in Japanese, and does not like other things.</p> <p>You are given a string <var>S</var> representing the Japanese name of Ringo's present to Snuke. Determine whether <var>S</var> starts with <code>YAKI</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 10</var></li> <li><var>S</var> consists of uppercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>S</var> starts with <code>YAKI</code>, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>YAKINIKU </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p><code>YAKINIKU</code> starts with <code>YAKI</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>TAKOYAKI </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p><code>TAKOYAKI</code> (a Japanese snack. <em>tako</em>: octopus) does not start with <code>YAKI</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>YAK </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre></section> </div> </span>
p01056
<h1>Lights of Apartment</h1> <h2>Problem</h2> <p> ゚ヌちゃんずリカちゃんずハルトくんはマンションに遊びに来た。<br> 3人は党おの郚屋の電気を管理できる郚屋に忍び蟌みいたずらをするこずにした。<br><br> このマンションは<var>n</var>個の立方䜓が1列に䞊んでいる圢をしおいる。<br> 各立方䜓は西から順に1蟺の長さが1ず぀増えおいお(1,2,3,...,<var>n</var>)、<var>i</var>番目の立方䜓は<var>i</var>階あり、各階に瞊<var>i</var>×暪<var>i</var>個の郚屋がある。<br> 2番目以降の立方䜓の西偎は1぀西の立方䜓の東偎ず接しおいお、党おの立方䜓の南偎は真っ盎ぐな道路に面しおいる。<br> </p> <br> <left> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015UOA_I" width="360" ><br> </left> <br> <p> 初め党おの郚屋に電気が぀いおいる。<br> 3人はそれぞれ次の行動をした。<br> </p> <ul> <li>゚ヌちゃんは西から<var>k</var>番目の党おの郚屋の電気を消した。</li> <li>リカちゃんは南から<var>k</var>番目の党おの郚屋の電気を消した。</li> <li>ハルトくんは<var>k</var>階の党おの郚屋の電気を消した。</li> </ul> <p> このようないたずらが <var>m</var> 回行われた埌に電気が぀いおいる郚屋の数を求めよ。 </p> <h2>Input</h2> <pre> <var>n</var> <var>m</var> <var>q<sub>1</sub></var> <var>k<sub>1</sub></var> ... <var>q<sub>m</sub></var> <var>k<sub>m</sub></var> </pre> <p> 入力は党お敎数で䞎えられる。<br> 1行目に立方䜓の数<var>n</var>、行動の数<var>m</var>が䞎えられる。<br> 2行目以降<var>m</var>行に行動した人の番号<var>q</var>ず<var>k</var>が䞎えられる。<br><br> <var>q<sub>i</sub></var>が0の堎合゚ヌちゃん、 1の堎合リカちゃん、2の堎合ハルトくんが行動したこずを衚す。 </p> <p> 3人は郚屋がない堎所の電気を消そうずするこずもある。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>n</var>,<var>m</var> &le; 50000</li> <li>0 &le; <var>q<sub>i</sub></var> &le; 2</li> <li>1 &le; <var>k<sub>i</sub></var> &le; 2×10<sup>9</sup></li> <li>同じ行動は䞀床しか䞎えられない</li> </ul> <h2>Output</h2> <p> 電気が぀いおいる郚屋の数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 1 0 4 </pre> <h2>Sample Output 1</h2> <pre> 27 </pre> <h2>Sample Input 2</h2> <pre> 3 2 2 2 2 3 </pre> <h2>Sample Output 2</h2> <pre> 14 </pre>
p01543
<h1>たるかいお</h1> <p> 倪郎君は小孊生で、チラシの裏に萜曞きをしおいたす。 ある時、倪郎君は次のゲヌムを思い぀きたした。 </p> <ul> <li><var>n&times;n</var>の栌子状のマス目を曞いおおきたす。 </li><li>それぞれのマス目の初期状態は、䞞印が曞かれおいるか、曞かれおいないかのどちらか䞀方です。 </li><li>これらの䞞印を消したり曞いたりしお最終的にどの䞀列を芋おも必ずちょうど1぀のみの䞞印が、どの䞀行を芋おも必ず1぀のみの䞞印が存圚するようにするこずが目暙であり、この状態にすればゲヌムをクリアしたこずになりたす。 </li></ul> <p> 倪郎君はこのゲヌムを思い぀きたしたが、倪郎君はこのゲヌムをクリアするのに倧倉時間がかかっおしたいたす。そこで、倧孊生であるあなたに助けを求めたした。 倪郎君の兄であり倧孊生であるあなたの仕事は以䞋の通りです。<br> 厳密な状況を考えるために、あるマス目に䞞印を曞き蟌むコスト、あるマス目にある䞞印を消すコストをあなたは導き出したした。このコストを甚いおこのゲヌムをクリアするためにかかる操䜜のコストを最小化するような手順を考える。 このずき、最小のコストおよびそのコストを達成するような手順を出力するプログラムを曞いおください。 出力に぀いおは、最小コストを達成する手順なら、どのような操䜜、順番でも出力しおもよいものずする。 </p> <h2>Input</h2> <blockquote> <var>n</var><br><var>W<sub>11</sub></var> <var>W<sub>12</sub></var> .. <var>W<sub>1n</sub></var><br><var>W<sub>21</sub></var> <var>W<sub>22</sub></var> .. <var>W<sub>2n</sub></var><br>..<br><var>W<sub>n1</sub></var> <var>W<sub>n2</sub></var> .. <var>W<sub>nn</sub></var><br><var>E<sub>11</sub></var> <var>E<sub>12</sub></var> .. <var>E<sub>1n</sub></var><br><var>E<sub>21</sub></var> <var>E<sub>22</sub></var> .. <var>E<sub>2n</sub></var><br>..<br><var>E<sub>n1</sub></var> <var>E<sub>n2</sub></var> .. <var>E<sub>nn</sub></var><br><var>F<sub>1</sub></var>(<var>n</var>文字)<br><var>F<sub>2</sub></var>(<var>n</var>文字)<br>..<br><var>F<sub>n</sub></var>(<var>n</var>文字)<br></blockquote> <ul> <li><var>n</var>は倪郎君の䜜ったマス目が䞀蟺にいく぀あるかを衚す </li><li><var>W<sub>ij</sub></var>は䞊から<var>i</var>番目、巊から<var>j</var>番目のマス目に䞞印を曞き蟌むコストを衚す </li><li><var>E<sub>ij</sub></var>は䞊から<var>i</var>番目、巊から<var>j</var>番目のマス目に曞かれおある䞞印を消すコストを衚す </li><li><var>F<sub>i</sub></var>は䞊から<var>i</var>番目の行のマス目の初期状態を衚す </li><li><var>F<sub>i</sub></var>の巊から<var>j</var>文字目に぀いお <ul> <li>'o'のずき、䞊から<var>i</var>番目、巊から<var>j</var>番目のマス目に䞞印が曞かれおあるこずを衚す。 </li><li>'.'のずき、䞊から<var>i</var>番目、巊から<var>j</var>番目のマス目が空癜であるこずを衚す。 </li></ul> </li></ul> <h2>Constraints</h2> <blockquote> <var>1&le; n &le; 100</var><br><var>1&le; W<sub>ij</sub> &le; 1000</var><br><var>1&le; E<sub>ij</sub> &le; 1000 </var><br></blockquote> <ul> <li><var>F<sub>i</sub></var>は文字列であり、その長さは<var>n</var>である </li><li><var>F<sub>i</sub></var>は'o'ず'.'のみで構成されおいる </li></ul> <h2>Output</h2> <blockquote> <var>mincost</var><br><var>cnt</var><br><var>R<sub>1</sub></var> <var>C<sub>1</sub></var> <var>operate<sub>1</sub></var><br><var>R<sub>2</sub></var> <var>C<sub>2</sub></var> <var>operate<sub>2</sub></var><br>..<br><var>R<sub>cnt</sub></var> <var>C<sub>cnt</sub></var> <var>operate<sub>cnt</sub></var><br></blockquote> <ul> <li><var>mincost</var>は、倪郎君のゲヌムをクリアするために必芁な最小コストを衚す。 </li><li><var>mincost</var>は曞き蟌み操䜜、消去操䜜で発生するコストの総和で蚈算される。 </li><li><var>cnt</var> : <var>mincost</var>のコストを達成する操䜜を行った回数を衚す </li><li><var>k</var>回目<var>(1&le;k&le;cnt)</var>に実行する操䜜は<var>k+2</var>行目に蚘述する </li><li><var>k</var>回目<var>(1&le;k&le;cnt)</var>の操䜜に察しお <ul> <li>䞊から<var>i</var>番目のマス目、巊から<var>j</var>番目のマス目に察しお行ったものずするず </li><li><var>R<sub>k</sub&ge;i , C<sub>k</sub&ge;j</var>である。 </li><li>この操䜜が䞞印を消す操䜜であるならば<var>operate<sub>k</sub></var> = &quot;erase&quot;ずせよ </li><li>この操䜜が䞞印を曞き蟌む操䜜であるならば<var>operate<sub>k</sub></var> = &quot;write&quot;ずせよ </li><li><var>R<sub>k</sub>,C<sub>k</sub>,operate<sub>k</sub></var>は䞀行に空癜区切りで出力しなければならない </li></ul> </li><li>䞞印の曞かれおあるマス目に察しお䞞印を蚘述する操䜜、および䞞印が曞かれおいないマス目に察しお䞞印を消去する操䜜をした堎合はWrongAnswerである </li><li><var>cnt</var>個の操䜜にかかるコストの総和が<var>mincost</var>に䞀臎しないずきはWrongAnswerである </li></ul> <H2>Sample Input 1</H2> <pre>3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 o.o ... .o. </pre> <H2>Output for the Sample Input 1</H2> <pre>2 2 1 3 erase 2 3 write </pre> <p> 䞊から1番目、巊から3番目のマス目の䞞印を消去し、 䞊から2番目、巊から3番目のマス目に䞞印を曞き加えれば目暙は達成できる。 このずきコストは2のみしかかからず、これが最小のコストである。 </p> <H2>Sample Input 2</H2> <pre>4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 oooo oooo oooo oooo </pre> <H2>Output for the Sample Input 2</H2> <pre>30 12 1 1 erase 1 2 erase 1 3 erase 2 1 erase 2 2 erase 2 4 erase 3 1 erase 3 3 erase 3 4 erase 4 2 erase 4 3 erase 4 4 erase </pre> <p> コスト(1+2+3+4)*3だけ消去凊理をすればクリアずなりたす。 </p> <H2>Sample Input 3</H2> <pre>3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 o.. .o. ..o </pre> <H2>Output for the Sample Input 3</H2> <pre>0 0 </pre> <p> すでに目暙は達成されおいるため、コスト及び操䜜回数はずもに0ずなる。 </p>
p03084
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In Takaha-shi, the capital of Republic of AtCoder, there are <var>N</var> roads extending east and west, and <var>M</var> roads extending north and south. There are no other roads. The <var>i</var>-th east-west road from the north and the <var>j</var>-th north-south road from the west cross at the intersection <var>(i, j)</var>. Two east-west roads do not cross, nor do two north-south roads. The distance between two adjacent roads in the same direction is <var>1</var>.</p> <p>Each road is one-way; one can only walk in one direction. The permitted direction for each road is described by a string <var>S</var> of length <var>N</var> and a string <var>T</var> of length <var>M</var>, as follows:</p> <ul> <li>If the <var>i</var>-th character in <var>S</var> is <code>W</code>, one can only walk westward along the <var>i</var>-th east-west road from the north;</li> <li>If the <var>i</var>-th character in <var>S</var> is <code>E</code>, one can only walk eastward along the <var>i</var>-th east-west road from the north;</li> <li>If the <var>i</var>-th character in <var>T</var> is <code>N</code>, one can only walk northward along the <var>i</var>-th north-south road from the west;</li> <li>If the <var>i</var>-th character in <var>T</var> is <code>S</code>, one can only walk southward along the <var>i</var>-th south-west road from the west.</li> </ul> <p>Process the following <var>Q</var> queries:</p> <ul> <li>In the <var>i</var>-th query, <var>a_i, b_i, c_i</var> and <var>d_i</var> are given. What is the minimum distance to travel to reach the intersection <var>(c_i, d_i)</var> from the intersection <var>(a_i, b_i)</var> by walking along the roads?</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100000</var></li> <li><var>2 \leq M \leq 100000</var></li> <li><var>2 \leq Q \leq 200000</var></li> <li><var>|S| = N</var></li> <li><var>S</var> consists of <code>W</code> and <code>E</code>.</li> <li><var>|T| = M</var></li> <li><var>T</var> consists of <code>N</code> and <code>S</code>.</li> <li><var>1 \leq a_i \leq N</var></li> <li><var>1 \leq b_i \leq M</var></li> <li><var>1 \leq c_i \leq N</var></li> <li><var>1 \leq d_i \leq M</var></li> <li><var>(a_i, b_i) \neq (c_i, d_i)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>Q</var> <var>S</var> <var>T</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var> <var>a_2</var> <var>b_2</var> <var>c_2</var> <var>d_2</var> <var>:</var> <var>a_Q</var> <var>b_Q</var> <var>c_Q</var> <var>d_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>In the <var>i</var>-th line, print the response to the <var>i</var>-th query. If the intersection <var>(c_i, d_i)</var> cannot be reached from the intersection <var>(a_i, b_i)</var> by walking along the roads, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 4 EEWW NSNNS 4 1 1 4 1 3 1 2 4 2 3 2 3 3 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 11 5 4 </pre> <p>The permitted direction for each road is shown in the following figure (north upward):</p> <p><img alt="" src="https://img.atcoder.jp/exawizards2019/bfb8c54cc4098353946320d8c263807e.png"/></p> <p>For each of the four queries, a route that achieves the minimum travel distance is as follows:</p> <p><img alt="" src="https://img.atcoder.jp/exawizards2019/d1918596004a23a20aa138e591e0ee99.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 2 EEE SSS 1 1 3 3 3 3 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 -1 </pre> <p>The travel may be impossible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 7 10 EEEEEWEWW NSSSNSN 4 6 9 2 3 7 6 7 7 5 3 5 1 1 8 1 4 3 5 4 7 4 6 4 2 5 8 6 6 6 2 7 2 4 7 5 7 2 9 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9 -1 4 9 2 3 7 7 6 -1 </pre></section> </div> </span>
p01113
<h3>Floating-Point Numbers</h3> <!-- end en only --> <!-- begin en only --> <p> In this problem, we consider floating-point number formats, data representation formats to approximate real numbers on computers. </p> <!-- end en only --> <!-- begin en only --> <p> Scientific notation is a method to express a number, frequently used for numbers too large or too small to be written tersely in usual decimal form. In scientific notation, all numbers are written in the form <i>m</i> &times; 10<sup><i>e</i></sup>. Here, <i>m</i> (called <i>significand</i>) is a number greater than or equal to 1 and less than 10, and <i>e</i> (called <i>exponent</i>) is an integer. For example, a number 13.5 is equal to 1.35 &times; 10<sup>1</sup>, so we can express it in scientific notation with significand 1.35 and exponent 1. </p> <!-- end en only --> <!-- begin en only --> <p> As binary number representation is convenient on computers, let's consider <i>binary scientific notation</i> with base two, instead of ten. In binary scientific notation, all numbers are written in the form <i>m</i> &times; 2<sup><i>e</i></sup>. Since the base is two, <i>m</i> is limited to be less than 2. For example, 13.5 is equal to 1.6875 &times; 2<sup>3</sup>, so we can express it in binary scientific notation with significand 1.6875 and exponent 3. The significand 1.6875 is equal to 1 + 1/2 + 1/8 + 1/16, which is 1.1011<sub>2</sub> in binary notation. Similarly, the exponent 3 can be expressed as 11<sub>2</sub> in binary notation. </p> <!-- end en only --> <!-- begin en only --> <p> A floating-point number expresses a number in binary scientific notation in finite number of bits. Although the accuracy of the significand and the range of the exponent are limited by the number of bits, we can express numbers in a wide range with reasonably high accuracy. </p> <!-- end en only --> <!-- begin en only --> <p> In this problem, we consider a 64-bit floating-point number format, simplified from one actually used widely, in which only those numbers greater than or equal to 1 can be expressed. Here, the first 12 bits are used for the exponent and the remaining 52 bits for the significand. Let's denote the 64 bits of a floating-point number by <i>b</i><sub>64</sub>...<i>b</i><sub>1</sub>. With <i>e</i> an unsigned binary integer (<i>b</i><sub>64</sub>...<i>b</i><sub>53</sub>)<sub>2</sub>, and with <i>m</i> a binary fraction represented by the remaining 52 bits plus one (1.<i>b</i><sub>52</sub>...<i>b</i><sub>1</sub>)<sub>2</sub>, the floating-point number represents the number <i>m</i> &times; 2<sup><i>e</i></sup>. </p> <!-- end en only --> <!-- begin en only --> <p> We show below the bit string of the representation of 13.5 in the format described above. </p> <p style="text-align:center;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_E1-en"> </p> <!-- end en only --> <!-- begin en only --> <p> In floating-point addition operations, the results have to be approximated by numbers representable in floating-point format. Here, we assume that the approximation is by truncation. When the sum of two floating-point numbers <i>a</i> and <i>b</i> is expressed in binary scientific notation as <i>a</i> + <i>b</i> = <i>m</i> &times; 2<sup>e</sup> (1 &#8804; <i>m</i> &lt; 2, 0 &#8804; <i>e</i> &lt; 2<sup>12</sup>), the result of addition operation on them will be a floating-point number with its first 12 bits representing <i>e</i> as an unsigned integer and the remaining 52 bits representing the first 52 bits of the binary fraction of <i>m</i>. </p> <!-- end en only --> <!-- begin en only --> <p> A disadvantage of this approximation method is that the approximation error accumulates easily. To verify this, let's make an experiment of adding a floating-point number many times, as in the pseudocode shown below. Here, <i>s</i> and <i>a</i> are floating-point numbers, and the results of individual addition are approximated as described above. </p> <!-- end en only --> <pre><i>s</i> := <i>a</i> for <i>n</i> times { <i>s</i> := <i>s</i> + <i>a</i> } </pre> <!-- begin en only --> <p> For a given floating-point number <i>a</i> and a number of repetitions <i>n</i>, compute the bits of the floating-point number <i>s</i> when the above pseudocode finishes. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of at most 1000 datasets, each in the following format. </p> <!-- end en only --> <blockquote> <p> <i>n</i> <br> <i>b</i><sub>52</sub>...<i>b</i><sub>1</sub> <br> </p> </blockquote> <!-- begin en only --> <p> <i>n</i> is the number of repetitions. (1 &#8804; <i>n</i> &#8804; 10<sup>18</sup>) For each <i>i</i>, <i>b</i><sub><i>i</i></sub> is either 0 or 1. As for the floating-point number <i>a</i> in the pseudocode, the exponent is 0 and the significand is <i>b</i><sub>52</sub>...<i>b</i><sub>1</sub>. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing a zero. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, the 64 bits of the floating-point number <i>s</i> after finishing the pseudocode should be output as a sequence of 64 digits, each being <tt>0</tt> or <tt>1</tt> in one line. </p> <!-- end en only --> <h3>Sample Input</h3> <pre>1 0000000000000000000000000000000000000000000000000000 2 0000000000000000000000000000000000000000000000000000 3 0000000000000000000000000000000000000000000000000000 4 0000000000000000000000000000000000000000000000000000 7 1101000000000000000000000000000000000000000000000000 100 1100011010100001100111100101000111001001111100101011 123456789 1010101010101010101010101010101010101010101010101010 1000000000000000000 1111111111111111111111111111111111111111111111111111 0 </pre> <h3>Output for the Sample Input</h3> <pre>0000000000010000000000000000000000000000000000000000000000000000 0000000000011000000000000000000000000000000000000000000000000000 0000000000100000000000000000000000000000000000000000000000000000 0000000000100100000000000000000000000000000000000000000000000000 0000000000111101000000000000000000000000000000000000000000000000 0000000001110110011010111011100001101110110010001001010101111111 0000000110111000100001110101011001000111100001010011110101011000 0000001101010000000000000000000000000000000000000000000000000000 </pre>
p00352
<H1>Handsel</H1> <!-- New Year’s gift money --> <p> Alice and Brown are brothers in a family and each receives pocket money in celebration of the coming year. They are very close and share the total amount of the money fifty-fifty. The pocket money each receives is a multiple of 1,000 yen. </p> <p> Write a program to calculate each one’s share given the amount of money Alice and Brown received. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>a</var> <var>b</var> </pre> <p> A line of data is given that contains two values of money: <var>a</var> (1000 &le; <var>a</var> &le; 50000) for Alice and <bar>b</var> (1000 &le; <var>b</var> &le; 50000) for Brown. </p> <h2>Output</h2> <p> Output the amount of money each of Alice and Brown receive in a line. </p> <h2>Sample Input 1</h2> <pre> 1000 3000 </pre> <h2>Sample Output 1</h2> <pre> 2000 </pre> <h2>Sample Input 2</h2> <pre> 5000 5000 </pre> <h2>Sample Output 2</h2> <pre> 5000 </pre> <h2>Sample Input 3</h2> <pre> 1000 2000 </pre> <h2>Sample Output 3</h2> <pre> 1500 </pre>
p03987
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>One day, Snuke was given a permutation of length <var>N</var>, <var>a_1, a_2, ..., a_N</var>, from his friend.</p> <p>Find the following:</p> <p><img src="https://atcoder.jp/img/agc005/520049e1a049bb9810b398b35d7dcb7f.png" style="height: 50px;"/></p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ N ≩ 200,000</var></li> <li><var>(a_1, a_2, ..., a_N)</var> is a permutation of <var>(1, 2, ..., N)</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>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 answer.</p> <p>Note that the answer may not fit into a 32-bit integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 3 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>19 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 5 4 8 1 2 6 7 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>85 </pre></section> </div> </span>
p02695
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are positive integers <var>N</var>, <var>M</var>, <var>Q</var>, and <var>Q</var> quadruples of integers ( <var>a_i</var> , <var>b_i</var> , <var>c_i</var> , <var>d_i</var> ).</p> <p>Consider a sequence <var>A</var> satisfying the following conditions:</p> <ul> <li><var>A</var> is a sequence of <var>N</var> positive integers.</li> <li><var>1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M</var>.</li> </ul> <p>Let us define a score of this sequence as follows:</p> <ul> <li>The score is the sum of <var>d_i</var> over all indices <var>i</var> such that <var>A_{b_i} - A_{a_i} = c_i</var>. (If there is no such <var>i</var>, the score is <var>0</var>.)</li> </ul> <p>Find the maximum possible score of <var>A</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>2 ≀ N ≀ 10</var></li> <li><var>1 \leq M \leq 10</var></li> <li><var>1 \leq Q \leq 50</var></li> <li><var>1 \leq a_i &lt; b_i \leq N</var> ( <var>i = 1, 2, ..., Q</var> )</li> <li><var>0 \leq c_i \leq M - 1</var> ( <var>i = 1, 2, ..., Q</var> )</li> <li><var>(a_i, b_i, c_i) \neq (a_j, b_j, c_j)</var> (where <var>i \neq j</var>)</li> <li><var>1 \leq d_i \leq 10^5</var> ( <var>i = 1, 2, ..., Q</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>Q</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var> <var>:</var> <var>a_Q</var> <var>b_Q</var> <var>c_Q</var> <var>d_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible score of <var>A</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 3 1 3 3 100 1 2 2 10 2 3 2 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>110 </pre> <p>When <var>A = \{1, 3, 4\}</var>, its score is <var>110</var>. Under these conditions, no sequence has a score greater than <var>110</var>, so the answer is <var>110</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 6 10 2 4 1 86568 1 4 0 90629 2 3 0 90310 3 4 1 29211 3 4 3 78537 3 4 2 8580 1 2 1 96263 1 4 2 2156 1 2 0 94325 1 4 3 94328 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>357500 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 1 1 10 9 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre></section> </div> </span>
p01810
<h2>監獄</h2> <p>無限人の囚人たちがいる。はじめ、囚人たちは <var>0, 1, 2,</var> ... ず番号が振られおいる。</p> <p>次の操䜜を <var>N</var> 回行う。</p> <ul> <li><var>0</var> 番目の囚人を釈攟し、<var>k, 2k, 3k,</var> ... 番目の囚人たちを凊刑する。</li> <li>その埌、残った囚人たちに番号を振り盎す。このずき、元の番号が小さい囚人から順に <var>0, 1, 2, </var> ... ず番号を振る。</li> </ul> <p><var>N</var> 回目の操䜜で釈攟される囚人がはじめに振られおいた番号を求めよ。</p> <h3>Constraints</h3> <ul> <li><var>1</var> &le; <var>N</var> &le; <var>10^5</var></li> <li><var>2</var> &le; <var>k</var> &le; <var>10^5</var></li> <li>答えは <var>10^{18}</var> 以䞋である。</li> </ul> <h3>Input Format</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre> <var>N</var> <var>k</var> </pre> <h3>Output Format</h3> <p>答えを䞀行に出力せよ。</p> <h3>Sample Input 1</h3> <pre> 4 2 </pre> </section> <h3>Sample Output 1</h3> <pre> 7 </pre> <h3>Sample Input 2</h3> <pre> 1 3 </pre> <h3>Sample Output 2</h3> <pre> 0 </pre> <h3>Sample Input 3</h3> <pre> 100000 100000 </pre> <h3>Sample Output 3</h3> <pre> 99999 </pre>
p00702
<h1> Kanglish : Analysis on Artificial Language </h1> <p>The late Prof. Kanazawa made an artificial language named Kanglish, which is similar to English, for studying mythology. Words and sentences of Kanglish are written with its own special characters called "Kan-characters". The size of the set of the Kan-characters is 38, i.e., there are 38 different Kan-characters in the set. Since Kan-characters cannot be directly stored in a computer because of the lack of a coded character set, Prof. Kanazawa devised a way to represent each Kan-character as an alphabetical letter or an ordered combination of two alphabetical letters. Thus, each Kan-character is represented as one of the following 26 letters </p><blockquote>"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", and "z", </blockquote>or one of the following 12 combinations of letters <blockquote>"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", and "ts". </blockquote> <p> In addition, the Kan-characters are ordered according to the above alphabetical representation. The order is named Kan-order in which the Kan-character represented by "a" is the first one, that by "b" is the second, that by "z" is the 26th, that by "ld" is the 27th, and that by "ts" is the 38th (the last). </p> <p></p> <p>The representations of words in Kanglish are separated by spaces. Each sentence is written in one line, so there are no periods or full stops in Kanglish. All alphabetical letters are in lower case, i.e., there are no capitalizations. </p> <p>We currently have many documents written in Kanglish with the alphabetical representation. However, we have lost most of Prof. Kanazawa's work on how they can be translated. To recognize his work, we have decided to first analyze them statistically. The first analysis is to check sequences of consecutive Kan-characters in words. </p> <p>For example, a substring "ic" in a word "quice" indicates an ordered pair of two adjacent Kan-characters that are represented by "i" and "c". For simplicity, we make a rule that, in the alphabetical representation of a word, a Kan-character is recognized as the longest possible alphabetical representation from left to right. Thus, a substring "ncw" should be considered as a pair of "nc" and "w". It does not consist of "n" and "cw", nor "n", "c", and "w". </p> <p>For each Kan-character, there are 38 possible pairs of that Kan-character and another Kan-character, e.g. "aa", "ab", ..., "az", "ald", ..., "ats". Thus, mathematically, there is a total of 1444 (i.e., 38x38) possible pairs, including pairs such as "n" and "cw", which is actually not allowed according to the above rule. </p> <p>Your job is to write a program that counts how many times each pair occurs in input data. For example, in the sentence </p><pre> qua ist qda quang quice</pre> <p> the Kan-character represented by "qu" appears three times. There are two occurrences of the pair of "qu" and "a", and one occurrence of the pair of "qu" and "i". Note that the alphabetical letter "q" appears four times in the example sentence, but the Kan-character represented by "q" occurs only once, because "qu" represents another Kan-character that is different from the Kan-character represented by "q". <p></p> <p>For simplicity, a newline at the end of a line is considered as a space. Thus in the above example, "e" is followed by a space. </p> <h2>Input</h2><pre><i>n</i> <i>line</i><sub>1</sub> <i>line</i><sub>2</sub> ... <i>line</i><sub><i>n</i></sub> </pre> <p>The first line of the input is an integer <i>n</i>, which indicates the number of lines that follow. Each line except for the first line represents one Kanglish sentence. You may assume that <i>n</i> &lt;= 1000 and that each line has at most 59 alphabetical letters including spaces. </p> <h2>Output</h2><pre>a <i>kc</i><sub>1</sub> <i>m</i><sub>1</sub> b <i>kc</i><sub>2</sub> <i>m</i><sub>2</sub> c <i>kc</i><sub>3</sub> <i>m</i><sub>3</sub> ... ts <i>kc</i><sub>38</sub> <i>m</i><sub>38</sub> </pre> <p>The output consists of 38 lines for the whole input lines. Each line of the output has two strings and an integer. In the <i>i</i>-th line in the output, the first string is the alphabetical representation of the <i>i</i>-th Kan-character in the Kan-order. For example, the first string of the first line is "a", that of the third line is "c", and that of the 37th line is "cw". The first string is followed by a space. </p> <p>The second string in the <i>i</i>-th line (denoted by <i>kc<sub>i</sub></i> above) shows the alphabetical representation of a Kan-character that most often occurred directly after the first Kan-character. If there are two or more such Kan-characters, the first one in the Kan-order should be printed. The second string is followed by a space. </p> <p>The integer (denoted by <i>m<sub>i</sub></i> above) in the <i>i</i>-th line shows the number of times that the second Kan-character occurred directly after the first Kan-character. In other words, the integer shows the number of times that ``the ordered pair of the first Kan-character and the second Kan-character'' appeared in the input. The integer is followed by a newline. </p> <p>Suppose the 28th output line is as follows: </p><blockquote><pre>mb e 4</pre></blockquote> <p> "mb" is output because it is the 28th character in the Kanglish alphabet. "e 4" means that the pair "mbe" appeared 4 times in the input, and that there were no pairs beginning with "mb" that appeared more than 4 times. <p></p> <p>Note that if the <i>i</i>-th Kan-character does not appear in the input, or if the <i>i</i>-th Kan-character is not followed by any other Kan-characters but spaces, the second string in the <i>i</i>-th output line should be "a" and the third item should be zero. </p> <p>Although the output does not include spaces, Kan-characters that appear with a space in-between is not considered as a pair. Thus, in the following example </p><blockquote><pre>abc def</pre></blockquote> <p> "d" is not counted as occurring after "c". <p></p> <h2>Sample Input</h2> <pre> 3 nai tiruvantel ar varyuvantel i valar tielyama nu vilya qua ist qda quang ncw psts svampti tsuldya jay quadal ciszeriol </pre> <h2>Output for the Sample Input</h2> <pre> a r 3 b a 0 c i 1 d a 2 e l 3 f a 0 g a 0 h a 0 i s 2 j a 1 k a 0 l y 2 m a 1 n a 1 o l 1 p a 0 q d 1 r i 1 s t 1 t i 3 u v 2 v a 5 w a 0 x a 0 y a 3 z e 1 ld y 1 mb a 0 mp t 1 nc w 1 nd a 0 ng a 0 nt e 2 nw a 0 ps ts 1 qu a 3 cw a 0 ts u 1 </pre>
p00597
<H1><font color="#000000">Problem C:</font> Finding the Largest Carbon Compound Given Its Longest Chain</H1> <p> An bydrocarbon is an organic compound which contains only carbons and hydrogens. An isomer is a compound that has the same number of carbons but different structures. Heptane, for example, is a hydrocarbon with 7 carbons. It has nine isomers. The structural formula of three are shown in Figure 1. Carbons are represented by the letter C, and bonds between carbons are represented by a straight line. In all figures, hydrogens are not represented for simplicity. Each carbon can be connected to a maximum of 4 carbons. </p> <center> <table> <tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_longestchain1"></td></tr> </table> <table> <tr><td>Figure 1: These three examples of isomers of heptane have the same number of carbons but different structures.</td></tr> </table> </center> <br/> <p> Let define a chain in an isomer as a sequence of connected carbons without branches. An isomer can have many chains of the same length. Figure 2 shows the longest chain of carbons for each of the represented isomer. Note that there can be many instances of longest chain in an isomer. </p> <center> <table> <tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_longestchain2"></td></tr> </table> <table> <tr><td>Figure 2: The figures shows one instance of longest chain of carbons in each isomer. The first and the second isomers show longest chains of 5 carbons. The longest chain in the third isomer has 4 carbons.</td></tr> </table> </center> <br/> <p> Your task is to identify the number of carbons of the largest possible carbon compound whose longest carbon chain has <i>n</i> (1 &le; <i>n</i> &le; 30) carbons. </p> <H2>Input</H2> <p> Each input contains a list of number of carbons, i.e. the length of a carbon chain. </p> <p> The number of input lines is less than or equal to 30. </p> <H2>Output</H2> <p> For each number n in input, identify the number of carbons of the largest possible carbon compound whose longest carbon chain has n carbons. </p> <H2>Sample Input</H2> <pre> 1 4 </pre> <H2>Output for the Sample Input</H2> <pre> 1 8 </pre>
p02050
<h3>Kは倚角圢のケむ</h3> <!-- begin ja only --> <p>「<i>1</i> 番じゃなきゃダメですか<i>K</i> 番じゃダメなんでしょうか」</p> <p>これがケむ氏の座右の銘である最近ケむ氏はもっぱら倚角圢に興味があるようで目の前に広がる広倧な二次元平面䞊に眮かれた <i>N</i> 個の点を芋おそこから倚角圢を圢成する方法に぀いお思いを銳せおいるケむ氏はどうやらこの <i>N</i> 個の点のうちいく぀かの点を遞んで自由な順番で繋げるこずで遞んだ点を頂点ずする倚角圢を構成するこずにしたようだただし倚角圢は以䞋の条件を満たす必芁がある</p> <ul> <li>単玔倚角圢であるすなわち3 ぀以䞊の頂点を持ち連続しない任意の 2 蟺が亀点を持たない</li> <li>遞ばれた点以倖も含む <i>N</i> 個すべおの点をその内郚たたは呚䞊に含む</li> </ul> <p>ケむ氏は己の信念に埓っおこのような倚角圢のうち呚長すなわち党おの蟺の長さの和が <i>K</i> 番目に短い倚角圢を枇望しおいる</p> <p>あなたの仕事はケむ氏を手䌝うため条件を満たす倚角圢のうち呚長の昇順に䞊べたずきに <i>K</i> 番目ずなる倚角圢を求めその呚長を出力するプログラムを曞くこずだただしそのような倚角圢が <i>K</i> 個以䞊存圚しないこずもあるそのようなずきにはケむ氏の無念の気持ちを慮り぀぀申し蚳ない気持ちを蟌めながら <i>-1</i> ず出力する必芁がある</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットからなる 各デヌタセットは次の圢匏で衚される</p> <blockquote><i>N</i> <i>K</i> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i> ... <i>x<sub>N</sub></i> <i>y<sub>N</sub></i></blockquote> <p>デヌタセットの1行目には二次元平面䞊の点の数 <i>N</i> ず求める呚長の順䜍 <i>K</i> が䞎えられる <i>N</i>, <i>K</i> はずもに敎数であり<i>3 &le; N &le; 25</i>, <i>1 &le; K &le; 10</i> が成り立぀続く <i>N</i> 行では各点の二次元平面䞊の座暙が䞎えられる<i>N</i> 行のうち <i>i</i> 行目には <i>i</i> 番目の点の <i>x</i> 座暙 <i>x<sub>i</sub></i> ず <i>y</i> 座暙 <i>y<sub>i</sub></i> がずもに敎数で䞎えられすべおの <i>1 &le; i &le; N</i> に぀いお <i>-100 &le; x<sub>i</sub>, y<sub>i</sub> &le; 100</i> が成り立぀どの盞異なる 3 点を遞んでもその 3 点すべおを通るような盎線は存圚しないず仮定しおよいたた入力においお呚長の昇順に䞊べたずきに <i>K</i> 番目ずなる問題文䞭に述べた条件を満たす倚角圢は存圚するならば䞀意に定たるず仮定しおよい</p> <p>入力の終わりは2 個のれロだけからなる行で衚される 党デヌタセットの総数は 50 を超えない</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>䞎えられた点集合からいく぀かの点を遞び単玔倚角圢を䜜るずき構成可胜な単玔倚角圢のうち <i>K</i> 番目に呚長が短い倚角圢の呚長を 1 行に出力せよそのような倚角圢が存圚しない堎合は -1 を出力せよ結果は <i>10<sup>-4</sup></i> 以䞊の誀差を含んではいけない</p> <!-- end ja only --> <h3>Sample Input</h3><pre>5 2 1 1 1 4 2 2 3 1 3 5 3 1 0 2 1 0 -1 0 3 2 0 2 1 0 -1 0 9 10 8 1 9 19 2 10 1 1 4 17 7 13 3 4 6 13 9 21 0 0 </pre><h3>Output for the Sample Input</h3><pre>11.812559200041266 6.472135954999580 -1 52.202878812480016 </pre>
p02400
<H1>Circle</H1> <p> Write a program which calculates the area and circumference of a circle for given radius <var>r</var>. </p> <H2>Input</H2> <p> A real number <var>r</var> is given. </p> <H2>Output</H2> <p> Print the area and circumference of the circle in a line. Put a single space between them. The output should not contain an absolute error greater than 10<sup>-5</sup>. </p> <h2>Constraints</h2> <ul> <li> 0 &lt; <var>r</var> &lt; 10000</sup></li> </ul> <H2>Sample Input 1</H2> <pre> 2 </pre> <H2>Sample Output 1</H2> <pre> 12.566371 12.566371 </pre> <H2>Sample Input 2</H2> <pre> 3 </pre> <H2>Sample Output 2</H2> <pre> 28.274334 18.849556 </pre>
p01386
<div> <h1 class="title">問題 K : 巡回セヌルスマン問題</h1> <p>2011 幎のあの頃ただプログラミングコンテストはずおも平和であり 我々はルヌルを粟読せずに気軜にコンテストに参加しおいた しかしそこに G○○gle の陰謀は迫っおいた ある日G○○gle によっお秘密裏に買収されおいた T○pC○der のコンテストは 人知れずうちにルヌルが改倉されおおり呜がけのプログラミングコンテストずなっおいた そしお僕はそこで䜕も知らず たっ先に kita_masa のプログラムのオヌバヌフロヌを突いたのだ </p> <dl class="docutils"> <dt>(iwi)</dt> <dd>「うう ああ 」</dd> <dt>wata</dt> <dd>「今やるべきこずは自分を攻めるこずではないチャンスを無駄にする気か」</dd> </dl> <p> そういえば今こい぀は郚屋に居る党おの人間を䞀瞬にしお倒しおいた どうなっおいるんだ</p> <dl class="docutils"> <dt>wata</dt> <dd>「たず知っおいるかもしれないが G○○gle は NP 完党問題を含む倚くの蚈算困難ず蚀われおきた問題に察する倚項匏時間の効率的なアルゎリズムを持っおいるP vs NP 問題を解決したが敢えおそれを秘匿するこずによっおここたで成長したのだ」</dd> <dt>(iwi)</dt> <dd>「もしやずは思っおいたがやはりか  しかしお前は今G○○gle の人間を䞀瞬にしお倒したもしやお前も 」</dd> <dt>wata</dt> <dd>「残念ながら違うしかし お前なら分かるはずだろう」</dd> </dl> <p> なるほど!! そういうこずか 圌は倧孊時代指数時間のアルゎリズムを高速にするこずに興味を持っおいた 䟋え指数時間であっおも指数の底が極めお小さければ 珟実的なむンスタンスに察しお十分に高速な可胜性がある</p> <dl class="docutils"> <dt>wata</dt> <dd>「そういうこずだ䟋えば今僕は巡回セヌルスマン問題の <span style="font-size:110%;font-family:times new roman;"><i>O</i><sup>*</sup>(1.0001<sup><i>n</i></sup>)</span> 時間のアルゎリズムを完成させようずしおいる」</dd> </dl> <p>凄たじい想像以䞊だ </p> <dl class="docutils"> <dt>wata</dt> <dd>「完成させるにあたっおグラフアルゎリズムに詳しいお前の力が必芁だ 手を貞しおくれるな」</dd> <dt>(iwi)</dt> <dd>「ああ勿論だたかせろ!!」</dd> </dl> <div> <h1>問題</h1> <p>グラフが䞎えられる グラフは<span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 個の頂点を持ち頂点には <span style="font-size:110%;font-family:times new roman;">1</span> から <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> の番号が付いおいる たたグラフは <span style="font-size:110%;font-family:times new roman;"><i>M</i></span> 個の蟺を持ち蟺は有向 (䞀方通行) で それぞれ距離が決たっおいる</p> <p>頂点 <span style="font-size:110%;font-family:times new roman;">1</span> から出発し頂点 <span style="font-size:110%;font-family:times new roman;">2,&nbsp;3,&nbsp;
,&nbsp;<i>N</i></span> をこの順番に蚪れ頂点 <span style="font-size:110%;font-family:times new roman;">1</span> ぞ戻る経路を考える ここで「この順番に蚪れる」ずいうのは経路に含たれる頂点の郚分列に <span style="font-size:110%;font-family:times new roman;">2,&nbsp;3,&nbsp;
,&nbsp;<i>N</i></span> が含たれるずいうこずである ぀たりスタヌト地点の頂点 <span style="font-size:110%;font-family:times new roman;">1</span> から頂点 <span style="font-size:110%;font-family:times new roman;">2</span> ぞの移動は 盎接の移動であっおも他の頂点を経由した移動であっおもよく 次の頂点 <span style="font-size:110%;font-family:times new roman;">2</span> から頂点 <span style="font-size:110%;font-family:times new roman;">3</span>ぞの移動 さらにその次の頂点 <span style="font-size:110%;font-family:times new roman;">3</span> から頂点 <span style="font-size:110%;font-family:times new roman;">4</span>ぞの移動等に関しおも同様である 同じ頂点や同じ蟺を 2 床通っおも構わない</p> <p>グラフが䞎えられた時 頂点 <span style="font-size:110%;font-family:times new roman;">1</span> から出発し頂点 <span style="font-size:110%;font-family:times new roman;">2,&nbsp;3,&nbsp;
,&nbsp;<i>N</i></span> をこの順番に蚪れ頂点 <span style="font-size:110%;font-family:times new roman;">1</span> ぞ戻る経路のうち 最短のものの長さを出力するプログラムを䜜成せよ 経路の長さずは経路に含たれる蟺の距離の和である 耇数回含たれる蟺に関しおは含たれる回数の分だけ距離を加えよ</p> </div> <div> <h1>入力</h1> <p>入力の最初の行は 2 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>N</i>,&nbsp;<i>M</i></span> を含む これはグラフの頂点数ず蟺数を衚す</p> <p>続く <span style="font-size:110%;font-family:times new roman;"><i>M</i></span> 行は蟺の情報を衚す これらの行のうちの <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> 行目は 3 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub>,&nbsp;<i>b</i><sub><i>i</i></sub>,&nbsp;<i>c</i><sub><i>i</i></sub></span> が曞かれおおり 蟺 <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> は頂点 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub></span> から頂点 <span style="font-size:110%;font-family:times new roman;"><i>b</i><sub><i>i</i></sub></span> を結びその距離は <span style="font-size:110%;font-family:times new roman;"><i>c</i><sub><i>i</i></sub></span> であるこずを衚す</p> </div> <div> <h1>出力</h1> <p>条件を満たす経路のうち最短のものの長さを出力せよ ただし条件を満たす経路が存圚しない堎合は-1 を出力せよ</p> </div> <div> <h1>制玄</h1> <ul class="simple"> <li><span style="font-size:110%;font-family:times new roman;">2&nbsp;&le;&nbsp;<i>N</i>&nbsp;&le;&nbsp;10<sup>5</sup></span></li> <li><span style="font-size:110%;font-family:times new roman;">0&nbsp;&le;&nbsp;<i>M</i>&nbsp;&le;&nbsp;<i>N</i>&nbsp;+&nbsp;500</span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>a</i><sub><i>i</i></sub>,&nbsp;<i>b</i><sub><i>i</i></sub>&nbsp;&le;&nbsp;<i>N</i></span><span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub>&nbsp;&ne;&nbsp;<i>b</i><sub><i>i</i></sub></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>c</i><sub><i>i</i></sub>&nbsp;&le;&nbsp;10<sup>3</sup></span></li> </ul> </div> <div> <h1>入出力䟋</h1> <div> <h2>入出力䟋 1</h2> <p>入力䟋 1:</p> <pre class="literal-block"> 5 5 1 2 10 2 3 20 3 4 30 4 5 40 5 1 50 </pre> <p>入力䟋 1 に察する出力の䟋:</p> <pre class="literal-block"> 150 </pre> </div> <div> <h2>入出力䟋 2</h2> <p>入力䟋 2:</p> <pre class="literal-block"> 5 5 1 5 10 5 4 20 4 3 30 3 2 40 2 1 50 </pre> <p>入力䟋 2 に察する出力の䟋:</p> <pre class="literal-block"> 600 </pre> </div> </div> </div>
p02953
<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> squares arranged in a row from left to right. The height of the <var>i</var>-th square from the left is <var>H_i</var>.</p> <p>For each square, you will perform either of the following operations once:</p> <ul> <li>Decrease the height of the square by <var>1</var>.</li> <li>Do nothing.</li> </ul> <p>Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.</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 H_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>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 1 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>You can achieve the objective by decreasing the height of only the second square from the left by <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Yes </pre></section> </div> </span>
p03641
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>N</var> be a positive even number.</p> <p>We have a permutation of <var>(1, 2, ..., N)</var>, <var>p = (p_1, p_2, ..., p_N)</var>. Snuke is constructing another permutation of <var>(1, 2, ..., N)</var>, <var>q</var>, following the procedure below.</p> <p>First, let <var>q</var> be an empty sequence. Then, perform the following operation until <var>p</var> becomes empty:</p> <ul> <li>Select two adjacent elements in <var>p</var>, and call them <var>x</var> and <var>y</var> in order. Remove <var>x</var> and <var>y</var> from <var>p</var> (reducing the length of <var>p</var> by <var>2</var>), and insert <var>x</var> and <var>y</var>, preserving the original order, at the beginning of <var>q</var>.</li> </ul> <p>When <var>p</var> becomes empty, <var>q</var> will be a permutation of <var>(1, 2, ..., N)</var>.</p> <p>Find the lexicographically smallest permutation that can be obtained as <var>q</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an even number.</li> <li><var>2 ≀ N ≀ 2 × 10^5</var></li> <li><var>p</var> is a permutation of <var>(1, 2, ..., 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>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation, with spaces in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 2 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 1 2 4 </pre> <p>The solution above is obtained as follows:</p> <table> <thead> <tr> <th align="center"><var>p</var></th> <th align="center"><var>q</var></th> </tr> </thead> <tbody> <tr> <td align="center"><var>(3, 2, 4, 1)</var></td> <td align="center"><var>()</var></td> </tr> <tr> <td align="center">↓</td> <td align="center">↓</td> </tr> <tr> <td align="center"><var>(3, 1)</var></td> <td align="center"><var>(2, 4)</var></td> </tr> <tr> <td align="center">↓</td> <td align="center">↓</td> </tr> <tr> <td align="center"><var>()</var></td> <td align="center"><var>(3, 1, 2, 4)</var></td> </tr> </tbody> </table> </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>1 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 4 6 3 2 8 5 7 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 1 2 7 4 6 8 5 </pre> <p>The solution above is obtained as follows:</p> <table> <thead> <tr> <th align="center"><var>p</var></th> <th align="center"><var>q</var></th> </tr> </thead> <tbody> <tr> <td align="center"><var>(4, 6, 3, 2, 8, 5, 7, 1)</var></td> <td align="center"><var>()</var></td> </tr> <tr> <td align="center">↓</td> <td align="center">↓</td> </tr> <tr> <td align="center"><var>(4, 6, 3, 2, 7, 1)</var></td> <td align="center"><var>(8, 5)</var></td> </tr> <tr> <td align="center">↓</td> <td align="center">↓</td> </tr> <tr> <td align="center"><var>(3, 2, 7, 1)</var></td> <td align="center"><var>(4, 6, 8, 5)</var></td> </tr> <tr> <td align="center">↓</td> <td align="center">↓</td> </tr> <tr> <td align="center"><var>(3, 1)</var></td> <td align="center"><var>(2, 7, 4, 6, 8, 5)</var></td> </tr> <tr> <td align="center">↓</td> <td align="center">↓</td> </tr> <tr> <td align="center"><var>()</var></td> <td align="center"><var>(3, 1, 2, 7, 4, 6, 8, 5)</var></td> </tr> </tbody> </table></section> </div> </span>
p03211
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a string <var>S</var> consisting of digits <code>1</code>, <code>2</code>, <var>...</var>, <code>9</code>. Lunlun, the Dachshund, will take out three consecutive digits from <var>S</var>, treat them as a single integer <var>X</var> and bring it to her master. (She cannot rearrange the digits.)</p> <p>The master's favorite number is <var>753</var>. The closer to this number, the better. What is the minimum possible (absolute) difference between <var>X</var> and <var>753</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is a string of length between <var>4</var> and <var>10</var> (inclusive).</li> <li>Each character in <var>S</var> is <code>1</code>, <code>2</code>, <var>...</var>, or <code>9</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible difference between <var>X</var> and <var>753</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1234567876 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>34 </pre> <p>Taking out the seventh to ninth characters results in <var>X = 787</var>, and the difference between this and <var>753</var> is <var>787 - 753 = 34</var>. The difference cannot be made smaller, no matter where <var>X</var> is taken from.</p> <p>Note that the digits cannot be rearranged. For example, taking out <code>567</code> and rearranging it to <code>765</code> is not allowed.</p> <p>We cannot take out three digits that are not consecutive from <var>S</var>, either. For example, taking out the seventh digit <code>7</code>, the ninth digit <code>7</code> and the tenth digit <code>6</code> to obtain <code>776</code> is not allowed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>35753 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>If <code>753</code> itself can be taken out, the answer is <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1111111111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>642 </pre> <p>No matter where <var>X</var> is taken from, <var>X = 111</var>, with the difference <var>753 - 111 = 642</var>.</p></section> </div> </span>
p02816
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are two sequences <var>a=\{a_0,\ldots,a_{N-1}\}</var> and <var>b=\{b_0,\ldots,b_{N-1}\}</var> of <var>N</var> non-negative integers each.</p> <p>Snuke will choose an integer <var>k</var> such that <var>0 \leq k &lt; N</var> and an integer <var>x</var> not less than <var>0</var>, to make a new sequence of length <var>N</var>, <var>a'=\{a_0',\ldots,a_{N-1}'\}</var>, as follows:</p> <ul> <li><var>a_i'= a_{i+k \mod N}\ XOR \ x</var></li> </ul> <p>Find all pairs <var>(k,x)</var> such that <var>a'</var> will be equal to <var>b</var>.</p> <details> <summary>What is <var>\mbox{ XOR }</var>?</summary> <p> The XOR of integers <var>A</var> and <var>B</var>, <var>A \mbox{ XOR } B</var>, is defined as follows: <ul> <li>When <var>A \mbox{ XOR } B</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if either <var>A</var> or <var>B</var>, but not both, has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> otherwise.</li> </ul> For example, <var>3 \mbox{ XOR } 5 = 6</var>. (In base two: <var>011 \mbox{ XOR } 101 = 110</var>.) </p> </details> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>0 \leq a_i,b_i &lt; 2^{30}</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_0</var> <var>a_1</var> <var>...</var> <var>a_{N-1}</var> <var>b_0</var> <var>b_1</var> <var>...</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print all pairs <var>(k, x)</var> such that <var>a'</var> and <var>b</var> will be equal, using one line for each pair, in ascending order of <var>k</var> (ascending order of <var>x</var> for pairs with the same <var>k</var>).</p> <p>If there are no such pairs, the output should be empty.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 2 1 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 3 </pre> <p>If <var>(k,x)=(1,3)</var>,</p> <ul> <li> <p><var>a_0'=(a_1\ XOR \ 3)=1</var></p> </li> <li> <p><var>a_1'=(a_2\ XOR \ 3)=2</var></p> </li> <li> <p><var>a_2'=(a_0\ XOR \ 3)=3</var></p> </li> </ul> <p>and we have <var>a' = b</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 0 0 0 0 2 2 2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 2 1 2 2 2 3 2 4 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 0 1 3 7 6 4 1 5 4 6 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 2 5 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 1 2 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre></pre> <p>No pairs may satisfy the condition.</p></section> </div> </span>
p03704
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For a positive integer <var>n</var>, we denote the integer obtained by reversing the decimal notation of <var>n</var> (without leading zeroes) by <var>rev(n)</var>. For example, <var>rev(123) = 321</var> and <var>rev(4000) = 4</var>.</p> <p>You are given a positive integer <var>D</var>. How many positive integers <var>N</var> satisfy <var>rev(N) = N + D</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>D</var> is an integer.</li> <li><var>1 ≀ D &lt; 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>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the positive integers <var>N</var> such that <var>rev(N) = N + D</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>63 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two positive integers <var>N</var> such that <var>rev(N) = N + 63</var>: <var>N = 18</var> and <var>29</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>75 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There are no positive integers <var>N</var> such that <var>rev(N) = N + 75</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>864197532 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1920 </pre></section> </div> </span>
p01739
<p> You are a programmer who loves pretty girl games (a sub-genre of dating simulation games). A game, which is titled "Floatable Heart" and was released last Friday, has arrived at your home just now. This game has multiple stories. When you complete all of those stories, you can get a special figure of the main heroine, Megumi. So, you want to hurry to play the game! But, let's calm down a bit and think how to complete all of the stories in the shortest time first. </p> <p> In fact, you have the special skill that allows you to know the structure of branching points of games. By using the skill, you have found out that there are <var>n</var> branching points in this game and <var>i</var>-th branching point has <var>k_{i}</var> choices. This game is so complicated that multiple routes get to <var>i</var>-th branching point probably. You also noticed that it takes <var>c_{ij}</var> minutes to proceed from <var>i</var>-th branching point to another branching point (or an ending), if you select <var>j</var>-th choice of <var>i</var>-th branching point. Of course you need to select all the choices on all the branching points and read stories between a branching point and another branching point (or an ending) to complete all of those stories. In addition, you can assume it only takes negligible time to return to the beginning of the game ("reset") and to play from the beginning to the first branching point. </p> <p> The game's manual says that this game has an additional feature called "Quick Save", and the feature allows you to record the point where you are currently playing and return there at any time later. However, this feature is not working for some bug. Thus you have to restart from the first branching point every time, if you reach an ending or quit the game on the way. Any patch to fix this bug has not been yet published. This is an imposed tribulation for the fastest players. </p> <p>Well, let's estimate how long it will take for completing all of the stories in the shortest time. </p> <h3>Input</h3> <p>A data set is given in the following format. </p><pre> <var>n</var> <var>k_{1}</var> <var>t_{11}</var> <var>c_{12}</var> ... <var>t_{1k_{1}}</var> <var>c_{1k_{1}}</var> : : <var>k_{n}</var> <var>t_{n1}</var> <var>c_{n2}</var> ... <var>t_{nk_{n}}</var> <var>c_{nk_{n}}</var> </pre> <p>The first line of the data set contains one integer <var>n</var> (<var>2 \leq n \leq 1{,}000</var>), which denotes the number of the branching points in this game. The following <var>n</var> lines describe the branching points. The <var>i</var>-th line describes the branching point of ID number <var>i</var>. The first integer <var>k_{i}</var> (<var>0 \leq k_{i} \leq 50</var>) is the number of choices at the <var>i</var>-th branching point. <var>k_{i} &ge; 0</var> means that the <var>i</var>-th branching point is an ending. Next <var>2k_{i}</var> integers <var>t_{ij}</var> (<var>1 \leq t_{ij} \leq n</var>) and <var>c_{ij}</var> (<var>0 \leq c_{ij} \leq 300</var>) are the information of choices. <var>t_{ij}</var> denotes the ID numbers of the next branching points when you select the <var>j</var>-th choice. <var>c_{ij}</var> denotes the time to read the story between the <var>i</var>-th branching point and the <var>t_{ij}</var>-th branching point. The branching point with ID 1 is the first branching point. You may assume all the branching point and endings are reachable from the first branching point. You may also assume that there is no loop in the game, that is, no branching point can be reached more than once without a reset. </p> <h3>Output</h3> <p>Print the shortest time in a line. </p> <h3>Sample Input 1</h3> <pre>2 1 2 2 0 </pre> <h3>Output for the Sample Input 1</h3> <pre>2 </pre> <h3>Sample Input 2</h3> <pre>6 2 2 1 3 2 2 4 3 5 4 2 5 5 6 6 0 0 0 </pre> <h3>Output for the Sample Input 2</h3> <pre>24 </pre> <h3>Sample Input 3</h3> <pre>6 3 2 100 3 10 3 10 1 4 100 1 4 10 3 5 1 5 1 6 1 0 0 </pre> <h3>Output for the Sample Input 3</h3> <pre>243 </pre>
p03354
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a permutation of the integers from <var>1</var> through <var>N</var>, <var>p_1</var>, <var>p_2</var>, .., <var>p_N</var>. We also have <var>M</var> pairs of two integers between <var>1</var> and <var>N</var> (inclusive), represented as <var>(x_1,y_1)</var>, <var>(x_2,y_2)</var>, .., <var>(x_M,y_M)</var>. AtCoDeer the deer is going to perform the following operation on <var>p</var> as many times as desired so that the number of <var>i</var> (<var>1</var> <var>≀</var> <var>i</var> <var>≀</var> <var>N</var>) such that <var>p_i = i</var> is maximized:</p> <ul> <li>Choose <var>j</var> such that <var>1</var> <var>≀</var> <var>j</var> <var>≀</var> <var>M</var>, and swap <var>p_{x_j}</var> and <var>p_{y_j}</var>.</li> </ul> <p>Find the maximum possible number of <var>i</var> such that <var>p_i = i</var> after operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2</var> <var>≀</var> <var>N</var> <var>≀</var> <var>10^5</var></li> <li><var>1</var> <var>≀</var> <var>M</var> <var>≀</var> <var>10^5</var></li> <li><var>p</var> is a permutation of integers from <var>1</var> through <var>N</var>.</li> <li><var>1</var> <var>≀</var> <var>x_j,y_j</var> <var>≀</var> <var>N</var></li> <li><var>x_j</var> <var>≠</var> <var>y_j</var></li> <li>If <var>i</var> <var>≠</var> <var>j</var>, <var>\{x_i,y_i\}</var> <var>≠</var> <var>\{x_j,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>M</var> <var>p_1</var> <var>p_2</var> <var>..</var> <var>p_N</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 maximum possible number of <var>i</var> such that <var>p_i = i</var> after operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 5 3 1 4 2 1 3 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>If we perform the operation by choosing <var>j=1</var>, <var>p</var> becomes <code>1 3 5 4 2</code>, which is optimal, so the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 3 2 1 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>If we perform the operation by, for example, choosing <var>j=1</var>, <var>j=2</var>, <var>j=1</var> in this order, <var>p</var> becomes <code>1 2 3</code>, which is obviously optimal. Note that we may choose the same <var>j</var> any number of times.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 8 5 3 6 8 7 10 9 1 2 4 3 1 4 1 5 9 2 5 6 5 3 5 8 9 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 1 1 2 3 4 5 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 </pre> <p>We do not have to perform the operation. </p></section> </div> </span>
p01369
<!-- begin en only --> <h3><U>koukyoukoukokukikou</U></h3> <!-- end en only --> <!-- begin ja only --> <!-- 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> ACM-ICPC を愛する誰もが手から喉が出るほど欲しがるもの それが Accepted 略しお AC しかし 実のずころ それが通じるのはごく限られた人たちだけで 䞖間䞀般には "koukyoukoukokukikou" の略称に過ぎない </p> <P> ずころで 䞀般的なキヌボヌドのキヌ配眮(図A-1)をQWERTY配列ず呌ぶのに察し それずは別のDvorak配列ず呌ばれるキヌ配眮も考案されおいる Dvorak配列ではよく䜿われるキヌがホヌムポゞションにあるので より速くタむプできるず T氏(ä»®) は匷硬に䞻匵しおいる </p> <p style="text-align: center;"> <a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011A-1" width="50%"> </a><br/> 図A-1 QWERTY配列 </p> <p> その T 氏(ä»®)はこの文字列を芋おいおあるこずに気付いた "koukyoukoukokukikou" は Dvorak 配列を䜿うず片手だけでタむプできるこずに しかし 同時に残念な事実にも気付いた QWERTY 配列でも片手だけでタむプできるのだ </p> <p> T 氏(ä»®)は他に Dvorak 配列を䜿うず片手だけでタむプできる文字列がないか興味を持った しかし できれば QWERTY 配列を䜿ったずきに片手だけでタむプできお欲しくない そのために 各文字列に察しお QWERTY 配列で文字をタむプするずきに䜿う手が入れ替わる回数を求めるプログラムを䜜るこずにした そういえば T 氏(ä»®)は QWERTY 配列をほずんど忘れおしたっおいたのであった 代わりにプログラムを曞いおあげるずしよう </p> <p> なお QWERTY 配列でそれぞれのキヌが巊右どちらの手でタむプされるものなのかわからなくなったずきは 䞋の図A-2を参照すればよいだろう </p> <p style="text-align: center;"> <a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011A-2" width="50%"> </a><br/> 図A-2 それぞれの手でタむプされる範囲 </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は各行にタむプする手が入れ替わる回数をカりントすべき文字列が1個ず぀含たれる 文字列はアルファベット小文字のみからなっおいお32文字以䞋である 入力の終わりは"#"のみからなる行で瀺される この"#"はカりントする察象の文字列ではない </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 入力された各文字列に぀いお敎数を1぀ず぀各行に出力せよ 出力すべき敎数は QWERTY 配列を䜿ったずきに 文字をタむプする手が入れ替わる回数である 出力に䜙蚈な文字を含めおはいけない </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> koukyoukoukokukikou abrakadabra acmicpc japaque helloworld # </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 0 2 4 5 7 </pre> </div>
p00981
<h2>Wall Painting</h2> <p> Here stands a wall made of a number of vertical panels. The panels are not painted yet. </p> <p> You have a number of robots each of which can paint panels in a single color, either red, green, or blue. Each of the robots, when activated, paints panels between a certain position and another certain position in a certain color. The panels painted and the color to paint them are fixed for each of the robots, but which of them are to be activated and the order of their activation can be arbitrarily decided. </p> <p> You’d like to have the wall painted to have a high <i>aesthetic value</i>. Here, the aesthetic value of the wall is defined simply as the sum of aesthetic values of the panels of the wall, and the aesthetic value of a panel is defined to be: </p> <ul> <li> 0, if the panel is left unpainted.</li> <li> The bonus value specified, if it is painted only in a single color, no matter how many times it is painted.</li> <li> The penalty value specified, if it is once painted in a color and then overpainted in one or more different colors.</li> </ul> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $m$ $x$ $y$ $c_1$ $l_1$ $r_1$ . . . $c_m$ $l_m$ $r_m$ </pre> <p> Here, $n$ is the number of the panels ($1 \leq n \leq 10^9$) and $m$ is the number of robots ($1 \leq m \leq 2 \times 10^5$). $x$ and $y$ are integers between $1$ and $10^5$, inclusive. $x$ is the bonus value and $-y$ is the penalty value. The panels of the wall are consecutively numbered $1$ through $n$. The $i$-th robot, when activated, paints all the panels of numbers $l_i$ through $r_i$ ($1 \leq l_i \leq r_i \leq n$) in color with color number $c_i$ ($c_i \in \{1, 2, 3\}$). Color numbers 1, 2, and 3 correspond to red, green, and blue, respectively. </p> <h3>Output</h3> <p> Output a single integer in a line which is the maximum achievable aesthetic value of the wall.</p> <h3>Sample Input 1 </h3> <pre> 8 5 10 5 1 1 7 3 1 2 1 5 6 3 1 4 3 6 8 </pre> <h3>Sample Output 1</h3> <pre> 70 </pre> <h3>Sample Input 2 </h3> <pre> 26 3 9 7 1 11 13 3 1 11 3 18 26 </pre> <h3>Sample Output 2</h3> <pre> 182 </pre> <h3>Sample Input 3 </h3> <pre> 21 10 10 5 1 10 21 3 4 16 1 1 7 3 11 21 3 1 16 3 3 3 2 1 17 3 5 18 1 7 11 2 3 14 </pre> <h3>Sample Output 3</h3> <pre> 210 </pre> <h3>Sample Input 4 </h3> <pre> 21 15 8 7 2 12 21 2 1 2 3 6 13 2 13 17 1 11 19 3 3 5 1 12 13 3 2 2 1 12 15 1 5 17 1 2 3 1 1 9 1 8 12 3 8 9 3 2 9 </pre> <h3>Sample Output 4</h3> <pre> 153 </pre>
p01693
<h2>G - Derangement / 完党順列</h2> <h3>Story</h3> <p>Dのひずは順列に関する研究をしおいる。あるずきDのひずは、&quot;完党順列 (Derangement)&quot;ずいう順列のクラスを芋぀けた。「完党な順列ずかなんかかっこいいしかもDからはじたる」ず廚二病をこじらせたDのひずは、䞎えられた順列をすべお完党順列に曞き換えおしたおうず考えた。</p> <h3>Problem</h3> <p>長さ<var>n</var>の順列<var>p</var> <var>=</var> <var>(p_1</var> <var>p_2</var> <var>...</var> <var>p_n)</var>が䞎えられる。<var>i</var>番目の芁玠ず<var>j</var>番目の芁玠を入れ替える操䜜には<var>(p_i+p_j) \times |i-j|</var>のコストを芁する。このずき、䞊蚘の入れ替え操䜜のみを甚いお<var>p</var>を完党順列にするために必芁な最小のコストを求めよ。</p> <p>ただし、順列<var>q</var>が完党順列であるずは、<var>1 \leq i \leq n</var>に぀いお、<var>q_i \neq i</var>が成り立぀こずを蚀う。たずえば、<var>(5</var> <var>3</var> <var>1</var> <var>2</var> <var>4)</var>は完党順列であるが、<var>(3</var> <var>2</var> <var>5</var> <var>4</var> <var>1)</var>は<var>4</var>番目の数が<var>4</var>なので完党順列ではない。</p> <h3>Input</h3> <p>入力は以䞋の圢匏からなる。</p> <pre><var>n</var> <var>p_1</var> <var>p_2</var> ... <var>p_n</var></pre> <p><var>1</var>行目は順列の長さ<var>n</var>を衚す敎数<var>1</var>぀からなる。 <var>2</var>行目は<var>n</var>個の敎数からなり、<var>i</var>番目の敎数は順列<var>p</var>の<var>i</var>番目の芁玠を衚す。それぞれは空癜<var>1</var>文字で区切られおいる。</p> <p>制玄:</p> <ul> <li><var>2 \leq n \leq 100</var></li> <li><var>1 \leq p_i \leq n, i \neq j ⇔ p_i \neq p_j</var></li> </ul> <h3>Output</h3> <p><var>p</var>を完党順列に䞊び替えるための最小コストを<var>1</var>行に出力せよ。行の最埌では必ず改行を行うこず。</p> <h3>Sample Input 1</h3> <pre>5 1 2 3 5 4</pre> <h3>Sample Output 1</h3> <pre>7</pre> <p>1ず2を入れ替えた埌、1ず3を入れ替えるず、(2 3 1 5 4)ずなり完党順列である。</p> <h3>Sample Input 2</h3> <pre>5 5 3 1 2 4</pre> <h3>Sample Output 2</h3> <pre>0</pre> <p>始めから完党順列である。</p> <h3>Sample Input 3</h3> <pre>10 1 3 4 5 6 2 7 8 9 10</pre> <h3>Sample Output 3</h3> <pre>38</pre>
p00128
<h1>そろばん</h1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_abacus1"> </center> <br/> <p> そろばんを習い始める友人からのお願いで、あなたはそろばんの珠の䞊び を衚瀺するプログラムを䜜成するこずになりたした。ある数字を入力ずしお、そろばんの珠の䞊びを出力するプログラムを䜜成しおください。ただし、衚瀺するそろばんの桁数は 5 桁ずし、0 から 9 たでの珠の配眮はそれぞれ '<span>*</span>' (半角アスタリスク)、'<span> </span>' (半角空癜)、'<span>=</span>' (半角むコヌル) を甚いお以䞋のように衚すものずしたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_abacus2"> </center> <br/> <H2>Input</H2> <p> 耇数のテストケヌスが䞎えられたす。各テストケヌスずしお 5 桁たでの数字敎数が  行に䞎えられたす。 </p> <p> テストケヌスの数は 1024 を超えたせん。 </p> <H2>Output</H2> <p> 各テストケヌス぀いおそろばんの珠の配眮を出力しおください。テストケヌスの間に行の空行を入れおください。 </p> <H2>Sample Input</H2> <pre> 2006 1111 </pre> <H2>Output for the Sample Input</H2> <pre> **** * ===== * * **** * *** ***** ***** ***** ===== **** * ***** ***** ***** </pre>
p02115
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Problem E: Piano</h1> <h2>Problem</h2> <p> がっちょ君はピアノを匟こうずしおいる。ピアノは右偎にある鍵盀ほど高い音が出る。がっちょ君はある楜譜を持っおおり、その楜譜に埓っお匟く。 </p> <p> 楜譜には、ある時刻にどの鍵盀を匟くべきかを瀺す音笊が時系列順に蚘茉されおいる。この楜譜には和音(耇数の鍵盀を抌したずきに出る音)は珟れず、音の長さも考えないこずにする。 </p> <p> がっちょ君はピアノを匟くずき、以䞋のルヌルに埓う。 </p> <ul> <li>片手のみで匟く</li> <li>指䞀本で鍵盀ひず぀を匟く</li> <li>最初の音はどの指でも匟ける</li> <li>盎前の音より高い音を匟くずき、盎前の音を匟いた指よりもひず぀以䞊右にある指を䜿う</li> <li>盎前の音より䜎い音を匟くずき、盎前の音を匟いた指よりもひず぀以䞊巊にある指を䜿う</li> <li>盎前の音ず同じ高さの音を匟くずき、盎前の音を匟いた指ず同じ指を䜿う</li> </ul> <p> がっちょ君が䜿う楜譜が䞎えられるので、ルヌルに埓っおその楜譜を挔奏しきるには、挔奏する方の腕に最小䜕本の指が必芁かを求めよ。ただし、必芁な指は6本以䞊になるこずがあるこずに泚意せよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var> </pre> <p> 1行目に、楜譜に曞かれおいる音笊の総数を衚す敎数<var>N</var>が䞎えられる。 <br>続く2行目から<var>N</var>+1行目たでに、時刻<var>i</var>(1 &le; <var>i</var> &le; <var>N</var>)に匟くべき鍵盀が最も巊の鍵盀から䜕番目かを衚す敎数<var>a<sub>i</sub></var>が䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var> &le; 10<sup>5</sup></li> <li>0 &le; <var>a<sub>i</sub></var> &le; 10<sup>9</sup></li> </ul> <h2>Output</h2> <p> がっちょ君が䞊蚘ルヌルに埓っお匟くために必芁な最小の指の本数を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 3 2 5 1 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <p> この堎合、図1の&#9312;、&#9313; 、&#9314; の順で鍵盀を匟く。指が2本あるず、巊偎の指で鍵盀2を、右偎の指で鍵盀5を、たた巊偎の指で鍵盀1を匟くこずができる。 </p> <center> <figure> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day2_aizu2017_keyboard" alt="Sample1の図解"> <legend>図1: Sample1 の図解</legend> </figure> </center> <h2>Sample Input 2</h2> <pre> 5 4 5 2 1 3 </pre> <h2>Sample Output 2</h2> <pre> 3 </pre> <h2>Sample Input 3</h2> <pre> 3 4 4 4 </pre> <h2>Sample Output 3</h2> <pre> 1 </pre>
p00578
<h1>日本沈没 (Japan Sinks)</h1> <!--  時間制限 : 2sec / メモリ制限 : 256MB--> <h2>問題文</h2> <p> 日本列島は现長い列島である日本列島は平行な境界線により <var>N</var> 個の区画に分けられおいる区画には端から順に <var>1</var> から <var>N</var> の番号が付けられおいる区画 <var>i</var> (<var>1 ≩ i ≩ N</var>) の高さは <var>A_i</var> である </p> <p> 日本列島は海に囲たれおおり海面の高さは堎所によらず䞀定である高さが海面の高さより高い区画を<strong>陞地</strong>ず呌ぶ </p> <p> 陞地が連続しおいる郚分のこずを<strong>å³¶</strong>ず呌ぶより正確に曞くず以䞋の通りである敎数 <var>l</var>, <var>r</var> (<var>1 ≩ l ≩ r ≩ N</var>) に぀いお日本列島のうち区画 <var>l</var>区画 <var>l+1</var><var>...</var>区画 <var>r</var> からなる郚分を<strong>領域</strong> [<var>l, r</var>] ずいう以䞋の条件を満たす領域 [<var>l, r</var>] を島ずいう </p> <ul> <li>区画 <var>l</var>区画 <var>l+1</var><var>...</var>区画 <var>r</var> はすべお陞地である</li> <li><var>l>1</var> ならば区画 <var>l-1</var> は陞地ではない</li> <li><var>r&lt;N</var> ならば区画 <var>r+1</var> は陞地ではない</li> </ul> <p> 海面の䞊昇により日本列島は少しず぀沈没しおいる珟圚の海面の高さは <var>0</var> であるがこれは時間が経぀に぀れお埐々に䞊がり぀いには日本党䜓が海になっおしたう </p> <p> JOI 君は海面の高さが䞊昇するず日本の島の数が増枛するこずに気付いた珟圚から日本に陞地がなくなるたでの間 (珟圚も含む) における島の数の最倧倀を求めたい </p> <h2>制玄</h2> <ul> <li><var>1 ≩ N ≩ 100000 (= 10^5)</var></li> <li><var>0 ≩ A_i ≩ 1000000000 (= 10^9)</var> (<var>1 ≩ i ≩ N</var>)</li> </ul> <h2>入力・出力</h2> <p> <b>入力</b><br> 入力は以䞋の圢匏で暙準入力から䞎えられる<br> <var>N</var><br> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </p> <p> <b>出力</b><br> 珟圚から日本に陞地がなくなるたでの間 (珟圚も含む) における島の数の最倧倀を 1 行で出力せよ </p> <!-- <h2>小課題</h2> <p> </p> <p style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <li>(<var>7</var> 点) <var>N ≩ 2000</var>, <var>A_i ≩ 2000</var> (<var>1 ≩ i ≩ N</var>)</li> <li>(<var>8</var> 点) <var>N ≩ 2000</var></li> <li>(<var>85</var> 点) 远加の制玄はない</li> </ol> </p> --> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 6 0 1 2 1 3 2 </pre> <h3>出力䟋 1</h3> <pre> 2 </pre> <ul> <li>海面の高さが <var>0</var> 以䞊 <var>1</var> 未満のずき区画 <var>2, 3, 4, 5, 6</var> が陞地である領域 [<var>2, 6</var>] が唯䞀の島なので島の数は <var>1</var> である</li> <li>海面の高さが <var>1</var> 以䞊 <var>2</var> 未満のずき区画 <var>3, 5, 6</var> が陞地である領域 [<var>3, 3</var>] ず領域 [<var>5, 6</var>] が島なので島の数は <var>2</var> である</li> <li>海面の高さが <var>2</var> 以䞊 <var>3</var> 未満のずき区画 <var>5</var> のみが陞地である領域 [<var>5, 5</var>] が唯䞀の島なので島の数は <var>1</var> である</li> <li>海面の高さが <var>3</var> になるず陞地はなくなり島の数は <var>0</var> になる</li> </ul> <p> よっお島の数の最倧倀は <var>2</var> なので<var>2</var> を出力する </p> <h3>入力䟋 2</h3> <pre> 6 3 2 3 0 2 0 </pre> <h3>出力䟋 2</h3> <pre> 2 </pre> <ul> <li>海面の高さが <var>0</var> 以䞊 <var>2</var> 未満のずき区画 <var>1, 2, 3, 5</var> が陞地である領域 [<var>1, 3</var>] ず領域 [<var>5, 5</var>] が島なので島の数は <var>2</var> である</li> <li>海面の高さが <var>2</var> 以䞊 <var>3</var> 未満のずき区画 <var>1, 3</var> が陞地である領域 [<var>1, 1</var>] ず領域 [<var>3, 3</var>] が島なので島の数は <var>2</var> である</li> <li>海面の高さが <var>3</var> になるず陞地はなくなり島の数は <var>0</var> になる</li> </ul> <p> よっお島の数の最倧倀は <var>2</var> なので<var>2</var> を出力する </p> <h3>入力䟋 3</h3> <pre> 10 4 1 2 1 2 3 5 4 3 2 </pre> <h3>出力䟋 3</h3> <pre> 3 </pre> <br/> <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/2018/2019-yo/index.html">情報オリンピック日本委員䌚䜜 『第 18 回日本情報オリンピック JOI 2018/2019 予遞競技課題』</a> </p> </div>
p02545
<span class="lang-en"> <p>Score : <var>1800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are integer sequences <var>A</var> and <var>B</var> of length <var>3N</var>. Each of these two sequences contains three copies of each of <var>1, 2, \dots, N</var>. In other words, <var>A</var> and <var>B</var> are both arrangements of <var>(1, 1, 1, 2, 2, 2, \dots, N, N, N)</var>.</p> <p>Tak can perform the following operation to the sequence <var>A</var> arbitrarily many times:</p> <ul> <li>Pick a value from <var>1, 2, \dots, N</var> and call it <var>x</var>. <var>A</var> contains exactly three copies of <var>x</var>. Remove the middle element of these three. After that, append <var>x</var> to the beginning or the end of <var>A</var>.</li> </ul> <p>Check if he can turn <var>A</var> into <var>B</var>. If he can, print the minimum required number of operations to achieve that.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 33</var></li> <li><var>A</var> and <var>B</var> are both arrangements of <var>(1, 1, 1, 2, 2, 2, \dots, N, N, N)</var>.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> ... <var>A_{3N}</var> <var>B_1</var> <var>B_2</var> ... <var>B_{3N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Tak can turn <var>A</var> into <var>B</var>, print the minimum required number of operations to achieve that. Otherwise, print <var>-1</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 3 1 1 3 2 2 1 3 1 2 2 3 1 2 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>For example, Tak can perform operations as follows:</p> <ul> <li><code>2 3 1 1 3 2 2 1 3</code> (The initial state)</li> <li><code>2 2 3 1 1 3 2 1 3</code> (Pick <var>x = 2</var> and append it to the beginning)</li> <li><code>2 2 3 1 3 2 1 3 1</code> (Pick <var>x = 1</var> and append it to the end)</li> <li><code>1 2 2 3 1 3 2 3 1</code> (Pick <var>x = 1</var> and append it to the beginning)</li> <li><code>1 2 2 3 1 2 3 1 3</code> (Pick <var>x = 3</var> and append it to the end)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 2 3 3 1 1 1 2 2 3 3 2 2 1 1 1 3 3 2 </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>8 3 6 7 5 4 8 4 1 1 3 8 7 3 8 2 4 7 5 2 2 6 5 6 1 7 5 8 1 3 6 7 5 4 8 1 3 3 8 2 4 2 6 5 6 1 4 7 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>7 </pre></section> </div> </span>
p00082
<H1>メリヌゎヌランド</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_10_1"> </center><br/> <p> 遊園地にあるメリヌゎヌランドはご存じでしょう。倧きな円盀の䞊に銬や銬車などの乗り物が固定されおいお、円盀が回転するず同時に乗り物が䞊䞋に揺れる、定番の遊具です。ある遊園地のメリヌゎヌランドは、人乗りの銬車が台、人乗りの車台、人乗りの銬が台、蚈台の乗り物が図のような順序で備えられおいたす。そしお、遊園地においでのお客様は、図に瀺す乗り堎〜のどこかで埅぀ようになっおいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_10_2"> </center><br/> <p> この遊園地のメリヌゎヌランドは、かならず乗り物が乗り堎にぎったりず合う䜍眮に停止したす。そしお、〜のそれぞれで埅っおいるお客さたは、目の前にずたった乗り物に乗るこずになっおいたす。急いで他の乗り堎ぞ移動しおそこから乗るずいうこずはできたせん。効率よく、お客さたにたのしんでいただくためには、メリヌゎヌランドの停止する䜍眮をうたく調敎しお、乗れないお客さたをできるだけ少なくするようにしなければなりたせん。 </p> <p> 乗り堎〜で埅っおいるお客さたの人数を読み蟌んで、どの䜍眮にどの乗り物が来るように止めれば乗れないお客さたが最も少なくなるかを出力するプログラムを䜜成しおください。 <!--なお、乗れなくなるお客さたが最小ずなるずめ方が䜕通りもある堎合は、そのうちの䞀぀だけ出力するようにしおください。--> </p> <H2>入力</H2> <p> 入力は耇数のデヌタセットからなりたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>p<sub>0</sub></var> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> <var>p<sub>3</sub></var> <var>p<sub>4</sub></var> <var>p<sub>5</sub></var> <var>p<sub>6</sub></var> <var>p<sub>7</sub></var> </pre> <p> 乗り堎 0, 1, ..., 7 で埅っおいるお客様の人数を衚す敎数 <var>p<sub>0</sub></var>, <var>p<sub>1</sub></var>,... , <var>p<sub>7</sub></var> ( 0 &le; <var>p<sub>i</sub></var> &le; 10,000) が空癜区切りで行に䞎えられたす。 </p> <H2>出力</H2> <p> メリヌゎヌランドの乗り物の銬車を 4、車を 2、銬を 1 で衚すこずずしたす。乗り堎 0, 1, ... , 7 にずめる乗り物を、それぞれ <var>c<sub>0</sub></var>, <var>c<sub>1</sub></var>,..., <var>c<sub>7</sub></var> ずしたす。デヌタセットごずに、<var>c<sub>0</sub></var>, <var>c<sub>1</sub></var>,..., <var>c<sub>7</sub></var> を空癜区切りで 1 行に出力したす。 </p> <p> なお、乗れなくなるお客さたが最小ずなるずめ方が耇数ある堎合は、<var>c<sub>0</sub>c<sub>1</sub>c<sub>2</sub>c<sub>3</sub>c<sub>4</sub>c<sub>5</sub>c<sub>6</sub>c<sub>7</sub></var> を 8 桁の敎数 <var>V</var> ずみなし、<var>V</var> が最小ずなるずめ方を遞ぶものずしたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Sample Input</H2> <pre> 2 3 1 4 0 1 0 1 4 2 3 2 2 2 1 1 </pre> <H2>Output for the Sample Input</H2> <pre> 1 4 1 4 1 2 1 2 4 1 4 1 2 1 2 1 </pre>
p01040
<h1>Problem D: Friday the 13th</h1> <h2>Problem</h2> <p> 今幎も「立呜通倧孊競技プログラミング合宿」が開催されるこずずなった。僕は毎幎開催されるこの合宿をずおも楜しみにしおいる。しかし、欲望に耐え切れず合宿前に散財しおしたい、お金に䜙裕が無くなっおしたった。そこで僕は、立呜通倧孊の最寄り駅である南草接たで移動するのに最も安く枈む青春18きっぷを䜿うこずにした。この切笊は安く枈む代わりに乗り換えが倚く発生し、移動に䞞1日䜿わなければならないのでずおも疲れる。そんな移動をする日が13日の金曜日であるこずに気づいたのは䌚接若束駅を出発した埌だった。僕は12時間、䞍安を感じながら電車に揺られるはめになった。 </p> <p> 今日は合宿2日目、2015幎3月15日、日曜日である。13日は特に䜕事もなく南草接に到着したが、僕はもうこのような䞍安を味わいたくないず思った。そこで2日目のゞャッゞである僕は、指定された期間内に存圚する13日の金曜日の数を求める問題を出題し、プログラムを䜜成しおもらうこずにした。 </p> <p> 閏(うるう)幎の定矩は以䞋の通りである。 </p> <ul> <li>西暊幎が4で割り切れる幎は閏幎である。</li> <li>ただし、100で割り切れる幎は閏幎でない。</li> <li>ただし、400で割り切れる幎は閏幎である。</li> </ul> <h2>Input</h2> <p> 空癜で区切られた6぀の敎数<var>Y<sub>1</sub></var>, <var>M<sub>1</sub></var>, <var>D<sub>1</sub></var>, <var>Y<sub>2</sub></var>, <var>M<sub>2</sub></var>, <var>D<sub>2</sub></var>が1行で䞎えられる。 </p> <h2>Constraints</h2> <p> 入力は以䞋の制玄を満たす。 </p> <ul> <li>1 &le; <var>Y<sub>1</sub></var> &le; <var>Y<sub>2</sub></var> &le; 10<sup>18</sup></li> <li>1 &le; <var>M<sub>i</sub></var> &le; 12</li> <li>1 &le; <var>D<sub>i</sub></var> &le; 31 (<var>M<sub>i</sub></var> = 1, 3, 5, 7, 8, 10, 12)</li> <li>1 &le; <var>D<sub>i</sub></var> &le; 30 (<var>M<sub>i</sub></var> = 4, 6, 9, 11)</li> <li>1 &le; <var>D<sub>i</sub></var> &le; 28 (<var>M<sub>i</sub></var> = 2 か぀ <var>Y<sub>i</sub></var>幎は閏幎でない)</li> <li>1 &le; <var>D<sub>i</sub></var> &le; 29 (<var>M<sub>i</sub></var> = 2 か぀ <var>Y<sub>i</sub></var>幎は閏幎である)</li> <li><var>Y<sub>1</sub></var>幎<var>M<sub>1</sub></var>月<var>D<sub>1</sub></var>日は<var>Y<sub>2</sub></var>幎<var>M<sub>2</sub></var>月<var>D<sub>2</sub></var>日より0日以䞊前の日付である</li> </ul> <h2>Output</h2> <p> <var>Y<sub>1</sub></var>幎<var>M<sub>1</sub></var>月<var>D<sub>1</sub></var>日から<var>Y<sub>2</sub></var>幎<var>M<sub>2</sub></var>月<var>D<sub>2</sub></var>日たでの間に存圚する13日の金曜日の数を1行に出力せよ。 </p> <h2>Sample Input1</h2> <pre> 2015 3 13 2015 3 13 </pre> <h2>Sample Output1</h2> <pre> 1 </pre> <h2>Sample Input2</h2> <pre> 2015 2 14 2015 3 15 </pre> <h2>Sample Output2</h2> <pre> 1 </pre> <h2>Sample Input3</h2> <pre> 1234 5 6 789012345678901234 5 6 </pre> <h2>Sample Output3</h2> <pre> 1357101234567708000 </pre>
p03587
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke prepared <var>6</var> problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not.</p> <p>You are given a string <var>S</var> of length <var>6</var>. If the <var>i</var>-th character of <var>s</var> is <code>1</code>, it means that the <var>i</var>-th problem prepared by Snuke is accepted to be used; <code>0</code> means that the problem is not accepted.</p> <p>How many problems prepared by Snuke are accepted to be used in the contest?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>The length of <var>S</var> is <var>6</var>.</li> <li><var>S</var> consists of <code>0</code> and <code>1</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>Print the number of problems prepared by Snuke that are accepted to be used in the contest.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>111100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The first, second, third and fourth problems are accepted, for a total of four.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>001001 </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>000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01410
<H1>D: Dangerous Tower</H1> <p> ICPC で良い成瞟を収めるには修行が欠かせないうさぎは ICPC で勝ちたいので今日も修行をするこずにした </p> <p> 今日の修行は積み朚を䞁寧に積み䞊げるこずによっお決しおミスタむピングをしないほどの手先の噚甚さを手に入れようずいうものであるせっかく積み朚がたくさんあるので高い塔を䜜ろう </p> <p> 積み朚は <i>N</i> 個あり<i>i</i> 番目 (1 &le; <i>i</i> &le; <i>N</i>) の積み朚は 1 &times; <i>A</i><sub><i>i</i></sub> &times; <i>B</i><sub><i>i</i></sub> の盎方䜓の圢をしおいる長さ 1 の蟺は奥行き方向に甚いお長さ <i>A</i><sub><i>i</i></sub>, <i>B</i><sub><i>i</i></sub> の蟺を暪方向ず高さ方向に 1 ぀ず぀割り圓おるこずにした積み朚を積み䞊げるずき䞊の段の積み朚は䞋の段の積み朚より暪の長さが厳密に短くなければならない積み朚は奜きな順番に䜿うこずができたた䜿わない積み朚があっおもよいこのような制玄䞋で䜜るこずが可胜な最も高い塔を䜜りたい </p> <H2>Input</H2> <pre> <i>N</i> <i>A</i><sub>1</sub> <i>B</i><sub>1</sub> ... <i>A</i><sub><i>N</i></sub> <i>B</i><sub><i>N</i></sub> </pre> <p> 1 &le; <i>N</i> &le; 1,0001 &le; <i>A</i><sub><i>i</i></sub><i>B</i><sub><i>i</i></sub> &le; 1,000,000 を満たす入力の倀はすべお敎数である </p> <H2>Output</H2> <p> 塔の高さの最倧倀を 1 行に出力せよ </p> <H2>Sample Input 1</H2> <pre> 3 10 40 10 40 20 30 </pre> <H2>Sample Output 1</H2> <pre> 80 </pre> <H2>Sample Input 2</H2> <pre> 4 1 2 2 3 3 4 4 1 </pre> <H2>Sample Output 2</H2> <pre> 11 </pre>
p00651
<h1>Problem E: Legend of Storia</h1> <p> In Storia Kingdom, there is an artifact called "Perfect Sphere" made by a great meister Es. This is handed down for generations in the royal palace as a treasure. Es left a memo and filled mysterious values in it. Within achievements of researches, it has been revealed that the values denote coordinate values. However it is still unknown the definition of the coordinate system. </p> <p> By the way, you are a person who lived in age of Es lived. The values which meister Es left are defined by following. Es set an moving object in the artifact sphere. Surprisingly, that is rigid body and perpetual organization. The object rotates inside the sphere and it is always touching the inside surface of the sphere. This value is a coordinate of the tangent point by the object and the sphere, but it is not a three dimensional value. The object is a plate and this is a simple polygon. Here, "simple" means "non self-intersected". This rotates while touching a great circle of the sphere. Here, assume that the great circle is a circle <i>O</i> centered in the origin in the xy plane. (It is two-dimensional Cartesian coordinate system, the direction of positive x-value is right and the direction of positive y-value is up). This plate touches the circle <i>O</i> with a single point at the beginning of the movement. And it rotates in counterclockwise as the current touching point is the rotation fulcrum. When another point <i>X</i> of the plate touches the circle <i>O</i> newly, the plate continue to rotate as described above, but in the next rotation, the rotation fulcrum point is changed. This will be the point <i>X</i>. If two or more points can be interpreted as the point <i>X</i>, the point <i>X</i> is a most distant point from the currently touching point <i>X'</i>. Here, that distance is the length of the arc of the circle <i>O</i> from the point <i>X'</i> to the point <i>X</i> in clockwise. </p> <p> Es asked you, an excellent assistant, to write a program that enumerates <i>Q</i> tangent points (fulcrum points while the movement) by the plate and the circle <i>O</i> while the movement of the plate described above in the chronological order. Of course, one and the previous one must be distinct points. Following figures show you examples of the movement of the plate inside the circle <i>O</i>. <br> 1<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E1"><br> 2<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E2"><br> 3<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E3"><br> 4<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E4"><br> </p> <h2>Input</h2> <p> Input consists of multiple datasets.<br> A dataset is given in a following format. </p> <pre> <i>N</i> <i>R</i> <i>Q</i> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>x<sub>2</sub></i> <i>y<sub>2</sub></i> ... <i>x<sub>N</sub></i> <i>y<sub>N</sub></i> </pre> <p> <i>N</i>, <i>R</i>, <i>Q</i> are integers that represent the number of points of the plate, the radius of the circle, and the number of points Es needs respectively.<br> Following <i>N</i> lines contain 2<i>N</i> integers that represent coordinates of the plate's points ( <i>x<sub>k</sub></i> , <i>y<sub>k</sub></i> ) in the circle.(1&le;<i>k</i>&le;<i>N</i>)<br> </p> <ul> You can assume following conditions. <li>Points of the plate are given in counterclockwise.</li> <li>No three points are co-linear.</li> <li><i>N</i>-1 points of the plate are given inside of the circle (distances between the center of the circle and these points are less than <i>R</i>). And 1 point is on the circle edge.</li> <i>N</i>=<i>R</i>=<i>Q</i>=0 shows the end of input. </ul> </p> <h2>Constraints</h2> <p> The number of datasets is less than or equal to 400.<br> 3&le;<i>N</i>&le;25<br> 1&le;<i>R</i>&le;1000<br> 0&le;<i>Q</i>&le;100 </p> <h2>Output</h2> <p> For each dataset, output (<i>Px</i> <i>Py</i>:real number) in <i>Q</i> in the following format. </p> <pre> <i>Px<sub>1</sub></i> <i>Px<sub>1</sub></i> <i>Px<sub>2</sub></i> <i>Py<sub>2</sub></i> ... <i>Px<sub>N+1</sub></i> <i>Py<sub>N+1</sub></i> </pre> <p> These answers must satisfy |<i>Tx<sub>i</sub></i>-<i>Px<sub>i</sub></i>|&le;0.0001 and |<i>Ty<sub>i</sub></i>-<i>Py<sub>i</sub></i>|&le;0.0001.<br> Here, <i>Px<sub>i</sub></i>, <i>Py<sub>i</sub></i>(1&le;<i>i</i>&le;<i>Q</i>) are your output and <i>Tx<sub>i</sub></i>,<i>Ty<sub>i</sub></i>(1&le;<i>i</i>&le;<i>Q</i>) are judge's output. </p> <h2>Sample Input</h2> <pre> 4 10 8 0 -10 3 -7 0 -4 -3 -7 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> -4.146082488326 -9.100000000000 -7.545870128753 -6.562000000000 -9.587401146004 -2.842840000000 -9.903199956975 1.388031200000 -8.436422775690 5.369056784000 -5.451089494781 8.383652146880 -1.484560104812 9.889190123322 2.749190104024 9.614673877565 </pre>
p01943
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], skipTags: ["script","noscript","style","textarea","code"]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h2>F 掛け算は楜しい - Multiplication Is Interesting -</h2> <h3>物語</h3> <p>男子高生の難波列くんは、圌女の誕生日に数列をプレれントしようず考えおいる。圌女は掛け算が倧奜きな女の子なので、難波くんは圌女にできるだけ倚くの掛け算を楜しんおもらえるような数列をプレれントしたいず思っおいる。しかし、蚈算結果が <var>2^{20}</var> を超える倀になるず圌女の機嫌が途端に悪くなっおしたう通垞の人類は <var>2^{20}</var>ずいう膚倧な数を蚈算できないため、これでも圌女は随分ず寛倧な人であるず蚀える。圌女の機嫌を損なわないように、できるだけ倚くの掛け算を楜しんでもらえる数列を難波くんが䜜ったので、あなたの仕事はその数列が圌女を十分に楜したせられるか怜蚌するプログラムを䜜るこずである。぀たり、あなたの仕事は数列の連続する郚分列の䞭で、郚分列の総積が <var>K</var> を超えない最長の郚分列の長さを答えるプログラムを䜜るこずである。</p> <h3>問題</h3> <p>長さ <var>N</var> の非負実数列 <var>S = s_1, s_2, ..., s_N</var> ず 非負実数 <var>K</var> がある。 あなたの仕事は、以䞋の条件を満たす <var>S</var> の連続する郚分列のうち、次の条件を満たす最長の郚分列の長さを求めるこずである。このずき、郚分列の長さは <var>1</var> 以䞊でなければならない。</p> <ul> <li> <var>S</var> の連続する郚分列 $T = s_\ell, \ldots, s_r$ に぀いお $\prod_{i = \ell, \ldots, r} s_i \leq$ <var>K</var>を満たす。</li> </ul> <p>もし条件を満たす郚分列が䞀぀も存圚しないずきは、 <var>0</var> を出力せよ。</p> <h3>入力圢匏</h3> <p>入力は次の圢匏で䞎えられる</p> <pre> <var>N</var> <var>K</var> <var>s_1</var> <var>s_2</var> $\dots$ <var>s_N</var> </pre> <p><var>1</var> 行目には数列の長さ <var>N</var> ず 郚分列の総積の䞊限 <var>K</var> が䞎えられる。続く <var>N</var> 行のうち、 <var>i</var> 行目では非負実数列 <var>S</var> の <var>i</var> 番目の実数 <var>s_i</var> が䞎えられる。</p> <h3>制玄</h3> <ul> <li> <var>1 \leq N \leq 100,000</var> </li> <li> <var>0 \leq s_i \leq 2.00</var> </li> <li> <var>0 \leq K \leq 1,048,576</var></li> <li> <var>N</var> は敎数、<var>K</var> ず <var>s_i</var> は小数点第 <var>3</var> 䜍以䞋を含たない実数である</li> </ul> <h3>出力圢匏</h3> <p><var>S</var> の郚分列の総積が <var>K</var> を超えない最長の郚分列の長さを <var>1</var> 行に出力せよ。</p> <h3>入力䟋1</h3> <pre> 6 2.01 1.10 1.44 0.91 2.00 1.12 1.55 </pre> <h3>出力䟋1</h3> <pre>3</pre> <h3>入力䟋2</h3> <pre> 8 12.22 2.00 2.00 2.00 1.91 2.00 2.00 2.00 0.01 </pre> <h3>出力䟋2</h3> <pre>8</pre>
p02396
<H1>Print Test Cases</H1> <p> In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. </p> <p> Write a program which reads an integer <var>x</var> and print it as is. Note that multiple datasets are given for this problem. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset consists of an integer <var>x</var> in a line. </p> <p> The input ends with an integer 0. You program should not process (print) for this terminal symbol. </p> <H2>Output</H2> <p> For each dataset, print <var>x</var> in the following format: </p> <pre> Case i: x </pre> <p> where <var>i</var> is the case number which starts with 1. Put a single space between "Case" and <var>i</var>. Also, put a single space between ':' and <var>x</var>. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>x</var> &le; 10000</li> <li>The number of datasets &le; 10000</li> </ul> <H2>Sample Input</H2> <pre> 3 5 11 7 8 19 0 </pre> <H2>Sample Output</H2> <pre> Case 1: 3 Case 2: 5 Case 3: 11 Case 4: 7 Case 5: 8 Case 6: 19 </pre>
p00201
<h1>錬金マスタヌ</h1> <p> あなたは぀いに魔法の釜、錬金釜を手に入れたした。錬金釜に耇数のアむテムを入れるず、新しいア むテムを䜜るこずができたす。新しく䜜ったアむテムは、他のアむテムを䜜るために錬金釜ぞ入れるこずもできたす。アむテムを䜜るために必芁なアむテムのリストを蚘したものを錬金レシピず呌ぶこずにしたす。以䞋の 3 ぀は錬金レシピの䟋です。 </p> <ol> <li> 朚片ず糞でラケットができる。</li> <li> お米ず氎でおにぎりができる。</li> <li> ラケットずマむクずおにぎりでギタヌができる。</li> </ol> <p> アむテムはお金を䜿っお手にいれるこずもできたすが、錬金釜で䜜った方が安くすむ堎合もありたす。䟋えば、各アむテムの賌入䟡栌が以䞋のように䞎えられおいるずしたす。 </p> <center> <table border=1 cellpadding=8 cellspacing=2> <tr><td width=140>アむテム名</td><td width=140> 賌入䟡栌(円)</td></tr> <tr><td> 朚片 </td><td> 3,000</td></tr> <tr><td> 糞 </td><td> 800</td></tr> <tr><td> お米 </td><td> 36</td></tr> <tr><td> æ°Ž </td><td> 0</td></tr> <tr><td> ラケット </td><td> 5,000</td></tr> <tr><td> マむク </td><td> 9,800</td></tr> <tr><td> おにぎり </td><td> 140</td></tr> <tr><td> ギタヌ </td><td> 98,000</td></tr> </tr> </table> <br/> </center> <p> ラケットは 5,000 円で賌入できたすが、朚片ず糞を賌入しお錬金すれば 3,800 円で手に入れられたす。曎に、錬金を重ねるこずによりずおもお埗にアむテムを手に入れられたす。図 1 は䞊蚘 3 ぀の錬金レシピ䟋を組み合わせたものです。ギタヌは 98,000 円で賌入できたすが、朚片、糞、お米、氎、マむクを賌入しお錬金すれば、たったの 13,636 円で手に入れられたす。 </p> <br><br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_recipe"> <p>図 1</p> </center> <br><br> <p> あなたは冒険を楜に進めるため、なるべく安く目的のアむテムを手に入れようず考えたした。 アむテムのリスト、錬金レシピのリスト、指定されたアむテムを入力ずし、指定されたアむテムを䜜るために必芁な金額の最小倀を出力するプログラムを䜜成しお䞋さい。 </p> <!-- <p> アむテムリストに含たれるアむテムの皮類 <var>n</var> は 1 以䞊 100 以䞋の敎数ずし、各アむテムを賌入する堎合の倀段 <var>p</var> は 0 以䞊 1000000 以䞋ずしたす。アむテムの名前 <var>i</var> は 1 文字以䞊 100 文字以䞋のアルファベットからなる半角文字列です。錬金レシピの皮類 <var>m</var> は 0 以䞊 100 以䞋の敎数です。 1぀の錬金レシピはアむテムの名前 <var>o</var>、それを䜜るために必芁なアむテムの個数 <var>k</var> 、 <var>k</var> 個のアむテム名 <var>q</var> のリストによっお䞎えられたす。<var>k</var> は 100 以䞋ずしたす。 </p> --> <p> 各アむテムの数量に限りはないものずしたす。アむテムは耇数のレシピに䜿われるこずがありたすが、1 ぀のアむテムを䜜るためのレシピはたかだか 1 ぀です。たた、あるアむテムを起点ずしおレシピをたどっおいったずき、そのアむテムが再びレシピに珟れるこずはありたせん。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>s<sub>1</sub></var> <var>p<sub>1</sub></var> <var>s<sub>2</sub></var> <var>p<sub>2</sub></var> : <var>s<sub>n</sub></var> <var>p<sub>n</sub></var> <var>m</var> <var>o<sub>1</sub></var> <var>k<sub>1</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>1</sub></sub></var> <var>o<sub>2</sub></var> <var>k<sub>2</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>2</sub></sub></var> : <var>o<sub>m</sub></var> <var>k<sub>m</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>m</sub></sub></var> <var>t</var> </pre> <p> 1 行目にリストに含たれるアむテムの皮類数 <var>n</var> (1 &le; <var>n</var> &le; 100) が䞎えられたす。続く <var>n</var> 行に <var>i</var> 番目のアむテムの名前 <var>s<sub>i</sub></var> (1 文字以䞊 100 文字以䞋のアルファベットからなる半角文字列) ずそれを賌入する堎合の倀段 <var>p<sub>i</sub></var> (0 &le; <var>p<sub>i</sub></var> &le; 1000000)が䞎えられたす。 </p> <p> 続く行に錬金レシピの数 <var>m</var> (0 &le; <var>m</var> &le; 100) が䞎えられたす。続く <var>m</var> 行に <var>i</var> 番目のレシピの情報が䞎えられたす。各レシピずしお、アむテムの名前 <var>o<sub>i</sub></var>、それを䜜るために必芁なアむテムの個数 <var>k<sub>i</sub></var> (1 &le; <var>k<sub>i</sub></var> &le; 100) 、 <var>k<sub>i</sub></var> 個のアむテム名 <var>q<sub>1</sub></var>, <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>i</sub></var> が䞎えられたす。 </p> <p> 最埌の行に指定されたアむテム名 <var>t</var> が䞎えられたす。 </p> <p> デヌタセットの数は 30 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、最小の倀段を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 8 wood 3000 string 800 rice 36 water 0 racket 5000 microphone 9800 onigiri 140 guitar 98000 3 racket 2 wood string onigiri 2 rice water guitar 3 racket microphone onigiri guitar 1 computer 300000 0 computer 0 </pre> <H2>Output for the Sample Input</H2> <pre> 13636 300000 </pre>
p02729
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have <var>N+M</var> balls, each of which has an integer written on it.<br/> It is known that: </p> <ul> <li>The numbers written on <var>N</var> of the balls are even.</li> <li>The numbers written on <var>M</var> of the balls are odd.</li> </ul> <p>Find the number of ways to choose two of the <var>N+M</var> balls (disregarding order) so that the sum of the numbers written on them is even.<br/> It can be shown that this count does not depend on the actual values written on the balls.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>0 \leq N,M \leq 100</var></li> <li><var>2 \leq N+M</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>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>For example, let us assume that the numbers written on the three balls are <var>1,2,4</var>.</p> <ul> <li>If we choose the two balls with <var>1</var> and <var>2</var>, the sum is odd;</li> <li>If we choose the two balls with <var>1</var> and <var>4</var>, the sum is odd;</li> <li>If we choose the two balls with <var>2</var> and <var>4</var>, the sum is even.</li> </ul> <p>Thus, the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>13 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>81 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>0 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>3 </pre></section> </div> </span>