question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p02658
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given <var>N</var> integers <var>A_1, ..., A_N</var>, compute <var>A_1 \times ... \times A_N</var>.</p> <p>However, if the result exceeds <var>10^{18}</var>, print <code>-1</code> instead.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>0 \leq A_i \leq 10^{18}</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the value <var>A_1 \times ... \times A_N</var> as an integer, or <code>-1</code> if the value exceeds <var>10^{18}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1000000000000000000 </pre> <p>We have <var>1000000000 \times 1000000000 = 1000000000000000000</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 101 9901 999999000001 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>We have <var>101 \times 9901 \times 999999000001 = 1000000000000000001</var>, which exceeds <var>10^{18}</var>, so we should print <code>-1</code> instead.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01977
<h1>D: 水槽</h1> <h2>問題</h2> <p> AORイカちゃんは縦 $1$ 横 $N$ の大きさの水槽をもらった。水槽は水を入れるのに十分な高さがある。 水槽には $N-1$ 個の仕切りがあり $N$ 個の区画に等間隔に区切られている。 ここに水を注いだところ、各区画の水の高さは $a_i$ になった。 </p> <p> AORイカちゃんはいくつか仕切りを取り除き、区画の数を $M$ 個以下にすることにした。 仕切りを取り除き終わった時、各区画の水の高さの総和の最大値を求めよ。 </p> <p> なお、仕切りの厚さは無視できるものとする。 </p> <h2>制約</h2> <ul> <li>$1 \le N \le 500$</li> <li>$1 \le M \le N$</li> <li>$1 \le a_i \le 10^9$</li> <li>入力は全て整数</li> </ul> <h2>入力</h2> <p> $N \ M$<br> $a_1 \cdots a_N$<br> </p> <h2>出力</h2> <p> 各区画の水の高さの総和の最大値を一行で出力せよ。また末尾に改行を出力せよ。 相対誤差または絶対誤差が $10^{-6}$ 以下であれば許容される。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 5 3 9 1 2 3 9 </pre> <h3>サンプル出力 1</h3> <pre> 20.000000 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/rupc2018_day1_d_aquarium" width="30%"> <p> $a_2$ と $a_3$ 、$a_3$ と $a_4$ の間の仕切りをとると、その区画の水の高さは $\frac{(1 + 2 + 3)}{3} = 2$ となる。 各区画の水の高さは $9 \ 2 \ 9$ となりこれが最大である。 </p> <h3>サンプル入力 2</h3> <pre> 4 1 14 4 9 7 </pre> <h3>サンプル出力 2</h3> <pre> 8.500000 </pre> <h3>サンプル入力 3</h3> <pre> 8 3 11 18 9 20 4 18 12 14 </pre> <h3>サンプル出力 3</h3> <pre> 44.666667 </pre> <!-- - - - - - end nicebody - - - - - -->
p00370
<H1>Lake Survery</H1> <p> The Onogawa Expedition is planning to conduct a survey of the Aizu nature reserve. The expedition planner wants to take the shortest possible route from the start to end point of the survey, while the expedition has to go around the coast of the Lake of Onogawa en route. The expedition walks along the coast of the lake, but can not wade across the lake. </p> <p> Based on the base information including the start and end point of the survey and the area of Lake Onogawa as convex polygon data, make a program to find the shortest possible route for the expedition and calculate its distance. Note that the expedition can move along the polygonal lines passing through the nodes, but never enter within the area enclosed by the polygon. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>x_s</var> <var>y_s</var> <var>x_g</var> <var>y_g</var> <var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_N</var> <var>y_N</var> </pre> <p> The first line provides the start point of the survey <var>x_s,y_s</var> (0&le;<var>x_s,y_s</var>&le;10<sup>4</sup>), and the second line provides the end point <var>x_g,y_g</var> (0 &le; <var>x_g,y_g</var> &le; 10<sup>4</sup>) all in integers. The third line provides the number of apexes <var>N</var> (3 &le; <var>N</var> &le; 100) of the polygon that represents the lake, and each of the subsequent <var>N</var> lines provides the coordinate of the <var>i</var>-th apex <var>x_i,y_i</var> (0 &le; <var>x_i,y_i</var> &le; 10<sup>4</sup>) in counter-clockwise order. These data satisfy the following criteria: </p> <ul> <li>Start and end points of the expedition are not within the area enclosed by the polygon nor on boundaries.</li> <li>Start and end points of the expedition are not identical, i.e., <var>x_s &ne; x_g</var> or <var>y_s &ne; y_g</var>.</li> <li>No duplicate coordinates are given, i.e., if <var>i &ne; j</var> then <var>x_i &ne; x_r</var> or <var>y_i &ne; y_j</var>.</li> <li>The area enclosed by the polygon has a positive value.</li> <li>Any three coordinates that define an area are not aligned on a line.</li> </ul> <h2>Output</h2> <p> Output the distance of the shortest possible expedition route. Any number of decimal places can be selected as long as the error does not exceed &plusmn; 10<sup>-3</sup>. </p> <h2>Sample Input 1</h2> <pre> 0 0 4 0 4 1 1 2 1 3 3 1 2 </pre> <h2>Sample Output 1</h2> <pre> 4.472136 </pre> <h2>Sample Input 2</h2> <pre> 4 4 0 0 4 1 1 3 1 3 3 1 3 </pre> <h2>Sample Output 2</h2> <pre> 6.32455 </pre>
p01998
<h1>C: 素数</h1> <h2>問題</h2> <p> ある日、素数が大好きなそすうさ君は $p + q$ が素数となるペア $(p, q)$ で遊んでいた。 そすうさ君は突然、このペアのうち、 $p$ と $q$ がともに $N$ 以下の素数であるペアがいくつあるか気になりだした。 そすうさ君に代わって個数を求めよ。 </p> <h2>制約</h2> <ul> <li>入力値は全て整数である。</li> <li>$1 \leq N \leq 10^7$</li> </ul> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる。 </p> <p> $N$ </p> <h2>出力</h2> <p>ペアの個数を出力せよ。また、末尾に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 3 </pre> <h3>サンプル出力 1</h3> <pre> 2 </pre> <p> ペアは $(2, 3), (3, 2)$ の二つである。 </p> <h3>サンプル入力 2</h3> <pre> 20 </pre> <h3>サンプル出力 2</h3> <pre> 8 </pre>
p00720
<h1><font color="#000">Problem E:</font> Earth Observation with a Mobile Robot Team</h1> <p> A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication devices and can exchange observational data with ones nearby. They also have large capacity memory units, on which they record data observed by themselves and those received from others. </p> <p> Figure 1 illustrates the current positions of three robots A, B, and C and the geographic coverage of their wireless devices. Each circle represents the wireless coverage of a robot, with its center representing the position of the robot. In this figure, two robots A and B are in the positions where A can transmit data to B, and vice versa. In contrast, C cannot communicate with A or B, since it is too remote from them. Still, however, once B moves towards C as in Figure 2, B and C can start communicating with each other. In this manner, B can relay observational data from A to C. Figure 3 shows another example, in which data propagate among several robots instantaneously. </p> <center> <table> <tr> <td ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_earth1"></td> </tr> <tr> <td ALIGN="center">Figure 1: The initial configuration of three robots</td> </tr> </table> </center> <center> <table> <tr> <td ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_earth2"></td> </tr> <tr> <td ALIGN="center">Figure 2: Mobile relaying</td> </tr> </table> </center> <center> <table> <tr> <td ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_earth3"></td> </tr> <tr> <td ALIGN="center">Figure 3: Instantaneous relaying among multiple robots</td> </tr> </table> </center> <p> As you may notice from these examples, if a team of robots move properly, observational data quickly spread over a large number of them. Your mission is to write a program that simulates how information spreads among robots. Suppose that, regardless of data size, the time necessary for communication is negligible. </p> <h2>Input</h2> <p> The input consists of multiple datasets, each in the following format. </p> <blockquote> <i>N</i> <i>T</i> <i>R</i><br> <i>nickname and travel route of the first robot</i><br> <i>nickname and travel route of the second robot</i><br> ...<br> <i>nickname and travel route of the N-th robot</i><br> </blockquote> <p> The first line contains three integers <i>N</i>, <i>T</i>, and <i>R</i> that are the number of robots, the length of the simulation period, and the maximum distance wireless signals can reach, respectively, and satisfy that 1 &lt;=<i>N</i> &lt;= 100, 1 &lt;= <i>T</i> &lt;= 1000, and 1 &lt;= <i>R</i> &lt;= 10. </p> <p> The <i>nickname and travel route</i> of each robot are given in the following format. </p> </p> <blockquote> <i>nickname</i><br> <i>t</i><sub>0</sub> <i>x</i><sub>0</sub> <i>y</i><sub>0</sub><br> <i>t</i><sub>1</sub> <i>vx</i><sub>1</sub> <i>vy</i><sub>1</sub><br> <i>t</i><sub>2</sub> <i>vx</i><sub>2</sub> <i>vy</i><sub>2</sub><br> ...<br> <i>t</i><sub><i>k</i></sub> <i>vx</i><sub><i>k</i></sub> <i>vy</i><sub><i>k</i> </sub><br> </blockquote> <p> <i>Nickname</i> is a character string of length between one and eight that only contains lowercase letters. No two robots in a dataset may have the same nickname. Each of the lines following <i>nickname</i> contains three integers, satisfying the following conditions. </p> <blockquote> 0 = <i>t</i><sub>0</sub> &lt; <i>t</i><sub>1</sub> &lt; ... &lt; <i>t</i><sub><i>k</i></sub> = <i>T</i><br> -10 &lt;= <i>vx</i><sub>1</sub>, <i>vy</i><sub>1</sub>, ..., <i>vx</i><sub><i>k</i></sub>, <i>vy</i><sub><i>k</i></sub>&lt;= 10<br> </blockquote> <p> A robot moves around on a two dimensional plane. (<i>x</i><sub>0</sub>, <i>y</i><sub>0</sub>) is the location of the robot at time 0. From time <i>t</i><sub><i>i</i>-1</sub> to <i>t</i><sub><i>i</i></sub> (0 &lt; <i>i</i> &lt;= <i>k</i>), the velocities in the <i>x</i> and <i>y</i> directions are <i>vx</i><sub><i>i</i></sub> and <i>vy</i><sub><i>i</i></sub>, respectively. Therefore, the travel route of a robot is piecewise linear. Note that it may self-overlap or self-intersect. </p> <p> You may assume that each dataset satisfies the following conditions. </p> <ul> <li> The distance between any two robots at time 0 is not exactly <i>R.</i> <li> The <i>x</i>- and <i>y</i>-coordinates of each robot are always between -500 and 500, inclusive. <li> Once any robot approaches within <i>R</i> + 10<sup>-6</sup> of any other, the distance between them will become smaller than <i>R</i> - 10<sup>-6</sup> while maintaining the velocities. <li> Once any robot moves away up to <i>R</i> - 10<sup>-6</sup> of any other, the distance between them will become larger than <i>R</i> + 10<sup>-6</sup> while maintaining the velocities. <li> If any pair of robots mutually enter the wireless area of the opposite ones at time <i>t</i> and any pair, which may share one or two members with the aforementioned pair, mutually leave the wireless area of the opposite ones at time <i>t'</i>, the difference between <i>t</i> and <i>t'</i> is no smaller than 10<sup>-6</sup> time unit, that is, |<i>t</i> - <i>t'</i> | &gt;= 10<sup>-6</sup>. </ul> <p> A dataset may include two or more robots that share the same location at the same time. However, you should still consider that they can move with the designated velocities. </p> <p> The end of the input is indicated by a line containing three zeros. </p> <h2>Output</h2> <p> For each dataset in the input, your program should print the nickname of each robot that have got until time <i>T</i> the observational data originally acquired by the first robot at time 0. Each nickname should be written in a separate line in dictionary order without any superfluous characters such as leading or trailing spaces. </p> <h2>Sample Input</h2> <pre> 3 5 10 red 0 0 0 5 0 0 green 0 5 5 5 6 1 blue 0 40 5 5 0 0 3 10 5 atom 0 47 32 5 -10 -7 10 1 0 pluto 0 0 0 7 0 0 10 3 3 gesicht 0 25 7 5 -7 -2 10 -1 10 4 100 7 impulse 0 -500 0 100 10 1 freedom 0 -491 0 100 9 2 destiny 0 -472 0 100 7 4 strike 0 -482 0 100 8 3 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> blue green red atom gesicht pluto freedom impulse strike </pre>
p01832
<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>Shifting a Matrix</h2> <p> You are given $N \times N$ matrix $A$ initialized with $A_{i,j} = (i - 1)N + j$, where $A_{i,j}$ is the entry of the $i$-th row and the $j$-th column of $A$. Note that $i$ and $j$ are 1-based. </p> <p> You are also given an operation sequence which consists of the four types of shift operations: left, right, up, and down shifts. More precisely, these operations are defined as follows: </p> <ul> <li> Left shift with $i$: circular shift of the $i$-th row to the left, i.e., setting previous $A_{i,k}$ to new $A_{i,k-1}$ for $2 \leq k \leq N$, and previous $A_{i,1}$ to new $A_{i,N}$.</li> <li> Right shift with $i$: circular shift of the $i$-th row to the right, i.e., setting previous $A_{i,k}$ to new $A_{i,k+1}$ for $1 \leq k \leq N - 1$, and previous $A_{i,N}$ to new $A_{i,1}$.</li> <li> Up shift with $j$: circular shift of the $j$-th column to the above, i.e., setting previous $A_{k,j}$ to new $A_{k-1,j}$ for $2 \leq k \leq N$, and previous $A_{1,j}$ to new $A_{N,j}$.</li> <li> Down shift with $j$: circular shift of the $j$-th column to the below, i.e., setting previous $A_{k,j}$ to new $A_{k+1,j}$ for $1 \leq k \leq N - 1$, and previous $A_{N,j}$ to new $A_{1,j}$. </ul> <p> An operation sequence is given as a string. You have to apply operations to a given matrix from left to right in a given string. Left, right, up, and down shifts are referred as 'L', 'R', 'U', and 'D' respectively in a string, and the following number indicates the row/column to be shifted. For example, "R25" means we should perform right shift with 25. In addition, the notion supports repetition of operation sequences. An operation sequence surrounded by a pair of parentheses must be repeated exactly $m$ times, where $m$ is the number following the close parenthesis. For example, "(L1R2)10" means we should repeat exactly 10 times the set of the two operations: left shift with 1 and right shift with 2 in this order. </p> <p> Given operation sequences are guaranteed to follow the following BNF: </p> <pre> &lt;sequence&gt; := &lt;sequence&gt;&lt;repetition&gt; | &lt;sequence&gt;&lt;operation&gt; | &lt;repetition&gt; | &lt;operation&gt; &lt;repetition&gt; := '('&lt;sequence&gt;')'&lt;number&gt; &lt;operation&gt; := &lt;shift>&lt;number&gt; &lt;shift&gt; := 'L' | 'R' | 'U' | 'D' &lt;number&gt; := &lt;nonzero_digit&gt; |&lt;number&gt;&lt;digit&gt; &lt;digit&gt; := '0' | &lt;nonzero_digit&gt; &lt;nonzero_digit&gt; := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' </pre> <p> Given $N$ and an operation sequence as a string, make a program to compute the $N \times N$ matrix after operations indicated by the operation sequence. </p> <h3>Input</h3> <p> The input consists of a single test case. The test case is formatted as follows.<br/> <br/> $N$ $L$<br/> $S$<br/> </p> <p> The first line contains two integers $N$ and $L$, where $N$ ($1 \leq N \leq 100$) is the size of the given matrix and $L$ ($2 \leq L \leq 1,000$) is the length of the following string. The second line contains a string $S$ representing the given operation sequence. You can assume that $S$ follows the above BNF. You can also assume numbers representing rows and columns are no less than 1 and no more than $N$, and the number of each repetition is no less than 1 and no more than $10^9$ in the given string. </p> <h3>Output</h3> <p> Output the matrix after the operations in $N$ lines, where the $i$-th line contains single-space separated $N$ integers representing the $i$-th row of $A$ after the operations. </p> <h3>Sample Input 1</h3> <pre> 3 2 R1 </pre> <h3>Output for the Sample Input 1</h3> <pre> 3 1 2 4 5 6 7 8 9 </pre> <h3>Sample Input 2</h3> <pre> 3 7 (U2)300 </pre> <h3>Output for the Sample Input 2</h3> <pre> 1 2 3 4 5 6 7 8 9 </pre> <h3>Sample Input 3</h3> <pre> 3 7 (R1D1)3 </pre> <h3>Output for the Sample Input 3</h3> <pre> 3 4 7 1 5 6 2 8 9 </pre>
p01561
<h1>A Two Floors Dungeon</h1> <p>It was the last day of the summer camp you strayed into the labyrinth on the way to Komaba Campus, the University of Tokyo. The contest has just begun. Your teammates must impatiently wait for you. So you have to escape from this labyrinth as soon as possible.<br> The labyrinth is represented by a grid map. Initially, each grid except for walls and stairs is either on the first floor or on the second floor. Some grids have a switch which can move up or down some of the grids (the grids on the first floor move to the second floor, and the grids on the second floor to the first floor).<br> In each step, you can take one of the following actions:<br> </p><ul><li><p> Move to an adjacent grid (includes stairs) on the same floor you are now in. </p></li><li><p> Move to another floor (if you are in the stairs grid). </p></li><li><p> Operate the switch (if you are in a grid with a switch). </p></li></ul> <p>Luckily, you have just found a map of the labyrinth for some unknown reason. Let's calculate the minimum step to escape from the labyrinth, and go to the place your teammates are waiting!<br> </p> <h2>Input</h2> <p>The format of the input is as follows.<br> </p><blockquote> <var>W</var> <var>H</var><br><var>M<sub>11</sub>M<sub>12</sub>M<sub>13</sub>...M<sub>1W</sub></var><br><var>M<sub>21</sub>M<sub>22</sub>M<sub>23</sub>...M<sub>2W</sub></var><br>........<br><var>M<sub>H1</sub>M<sub>H2</sub>M<sub>H3</sub>...M<sub>HW</sub></var><br><var>S</var><br><var>MS<sub>111</sub>MS<sub>112</sub>MS<sub>113</sub>...MS<sub>11W</sub></var><br><var>MS<sub>121</sub>MS<sub>122</sub>MS<sub>123</sub>...MS<sub>12W</sub></var><br>........<br><var>MS<sub>1H1</sub>MS<sub>1H2</sub>MS<sub>1H3</sub>...MS<sub>1HW</sub></var><br><var>MS<sub>211</sub>MS<sub>212</sub>MS<sub>213</sub>...MS<sub>21W</sub></var><br><var>MS<sub>221</sub>MS<sub>222</sub>MS<sub>223</sub>...MS<sub>22W</sub></var><br>........<br><var>MS<sub>2H1</sub>MS<sub>2H2</sub>MS<sub>2H3</sub>...MS<sub>2HW</sub></var><br><var>MS<sub>S11</sub>MS<sub>S12</sub>MS<sub>S13</sub>...MS<sub>S1W</sub></var><br><var>MS<sub>S21</sub>MS<sub>S22</sub>MS<sub>S23</sub>...MS<sub>S2W</sub></var><br>........<br><var>MS<sub>SH1</sub>MS<sub>SH2</sub>MS<sub>SH3</sub>...MS<sub>SHW</sub></var><br></blockquote> <p>The first line contains two integers <var>W</var> (<var>3 &le; W &le; 50</var>) and <var>H</var> (<var>3 &le; H &le; 50</var>). They represent the width and height of the labyrinth, respectively.<br> The following <var>H</var> lines represent the initial state of the labyrinth. Each of <var>M<sub>ij</sub></var> is one of the following symbols:<br> </p><ul><li> '#' representing a wall, </li><li> '|' representing stairs, </li><li> '_' representing a grid which is initially on the first floor, </li><li> '^' representing a grid which is initially on the second floor, </li><li> a lowercase letter from 'a' to 'j' representing a switch the grid has, and the grid is initially on the first floor, </li><li> an uppercase letter from 'A' to 'J' representing a switch the grid has, and the grid is initially on the second floor, </li><li> '%' representing the grid you are initially in (which is initially on the first floor) or </li><li> '&amp;' representing the exit of the labyrinth (which is initially on the first floor). </li></ul> <p>The next line contains one integer <var>S</var> (<var>0 &le; S &le; 10</var>), and then the following <var>SH</var> lines represent the information of the switches. Each of <var>MS<sub>kij</sub></var> is one of:<br> </p><ul><li> '#' if <var>M<sub>ij</sub></var> is a '#', </li><li> '|' if <var>M<sub>ij</sub></var> is a '|', </li><li> '*' if the grid is moved by the switch represented by the <var>k</var>-th alphabet letter, or </li><li> '.' otherwise. </li></ul> <p>Note that the grid which contains a switch may be moved by operating the switch. In this case, you will move together with the grid.<br> You may assume each of the '%' (start) and '&amp;' (goal) appears exacyly once, that the map is surround by walls, and that each alphabet in the map is any of the letters from 'A' (or 'a') to <var>S</var>-th alphabet letter.<br> </p> <h2>Output</h2> <p>Print the minimum step to reach the goal in one line. If there is no solution, print &quot;-1&quot;. </p> <h2>Sample Input 1</h2> <pre>6 6 ###### #_|A%# #B#_|# #^BBa# #B&amp;A## ###### 2 ###### #*|*.# #.#.|# #*.**# #...## ###### ###### #*|*.# #*#.|# #..**# #..*## ###### </pre> <h2>Output for the Sample Input 1</h2> <pre>21 </pre> <h2>Sample Input 2</h2> <pre>8 3 ######## #%||Aa&amp;# ######## 2 ######## #*||*..# ######## ######## #.||*.*# ######## </pre> <h2>Output for the Sample Input 2</h2> <pre>7 </pre> <h2>Sample Input 3</h2> <pre>3 4 ### #%# #&amp;# ### 0 </pre> <h2>Output for the Sample Input 3</h2> <pre>1 </pre> <h2>Sample Input 4</h2> <pre>3 5 ### #%# #^# #&amp;# ### 0 </pre> <h2>Output for the Sample Input 4</h2> <pre>-1 </pre>
p01131
<h1><font color="#000000">Problem A:</font> Keitai Message</h1> <p> Alice さんは Miku さんに携帯電話でメールを送ろうとしている。 </p> <p> 携帯電話には入力に使えるボタンは数字のボタンしかない。 そこで、文字の入力をするために数字ボタンを何度か押して文字の入力を行う。携帯電話の数字ボタンには、次の文字が割り当てられており、ボタン 0 は確定ボタンが割り当てられている。この携帯電話では 1 文字の入力が終わったら必ず確定ボタンを押すことになっている。 </p> <ul> <li>1: . , ! ? (スペース) <li>2: a b c <li>3: d e f <li>4: g h i <li>5: j k l <li>6: m n o <li>7: p q r s <li>8: t u v <li>9: w x y z <li>0: 確定ボタン </ul> <p> 例えば、ボタン 2、ボタン 2、ボタン 0 と押すと、文字が 'a' → 'b' と変化し、ここで確定ボタンが押されるので、文字 b が出力される。 同じ数字を続けて入力すると変化する文字はループする。すなわち、ボタン 2 を 5 回押して、次にボタン 0 を押すと、文字が 'a' → 'b' → 'c' → 'a' → 'b' と変化し、ここで確定ボタンを押されるから 'b' が出力される。 </p> <p> 何もボタンが押されていないときに確定ボタンを押すことはできるが、その場合には何も文字は出力されない。 </p> <p> あなたの仕事は、Alice さんが押したボタンの列から、Alice さんが作ったメッセージを再現することである。 </p> <h2>Input</h2> <p> 最初の行にテストケースの数が与えられる。 続いて各テストケースについて、最大で長さ 1024 の数字列が1行で与えられる。 </p> <h2>Output</h2> <p> Alice さんが作ったメッセージの文字列をそれぞれのテストケースについて 1 行ごとに出力せよ。 ただし、出力は 1 文字以上 76 文字未満であると仮定してよい。 </p> <h2>Sample Input</h2> <pre> 5 20 220 222220 44033055505550666011011111090666077705550301110 000555555550000330000444000080000200004440000 </pre> <h2>Output for the Sample Input</h2> <pre> a b b hello, world! keitai </pre>
p02930
<span class="lang-en"> <p>Score: <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>AtCoder's head office consists of <var>N</var> rooms numbered <var>1</var> to <var>N</var>. For any two rooms, there is a direct passage connecting these rooms.</p> <p>For security reasons, Takahashi the president asked you to set a <strong>level</strong> for every passage, which is a positive integer and must satisfy the following condition:</p> <ul> <li>For each room <var>i\ (1 \leq i \leq N)</var>, if we leave Room <var>i</var>, pass through some passages whose levels are all equal and get back to Room <var>i</var>, the number of times we pass through a passage is always even.</li> </ul> <p>Your task is to set levels to the passages so that the highest level of a passage is minimized.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is an integer between <var>2</var> and <var>500</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print one way to set levels to the passages so that the objective is achieved, as follows:</p> <pre><var>a_{1,2}</var> <var>a_{1,3}</var> <var>...</var> <var>a_{1,N}</var> <var>a_{2,3}</var> <var>...</var> <var>a_{2,N}</var> <var>.</var> <var>.</var> <var>.</var> <var>a_{N-1,N}</var> </pre> <p>Here <var>a_{i,j}</var> is the level of the passage connecting Room <var>i</var> and Room <var>j</var>.</p> <p>If there are multiple solutions, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 </pre> <p>The following image describes this output:</p> <p><img alt="" src="https://img.atcoder.jp/jsc2019-qual/D-sample.png"/></p> <p>For example, if we leave Room <var>2</var>, traverse the path <var>2 \to 3 \to 2 \to 3 \to 2 \to 1 \to 2</var> while only passing passages of level <var>1</var> and get back to Room <var>2</var>, we pass through a passage six times.</p></section> </div> </span>
p03622
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are participating in a quiz with <var>N + M</var> questions and Yes/No answers.</p> <p>It's known in advance that there are <var>N</var> questions with answer Yes and <var>M</var> questions with answer No, but the questions are given to you in random order.</p> <p>You have no idea about correct answers to any of the questions. You answer questions one by one, and for each question you answer, you get to know the correct answer immediately after answering.</p> <p>Suppose you follow a strategy maximizing the expected number of correct answers you give.</p> <p>Let this expected number be <var>P/Q</var>, an irreducible fraction. Let <var>M = 998244353</var>. It can be proven that a unique integer <var>R</var> between <var>0</var> and <var>M - 1</var> exists such that <var>P = Q \times R</var> modulo <var>M</var>, and it is equal to <var>P \times Q^{-1}</var> modulo <var>M</var>, where <var>Q^{-1}</var> is the modular inverse of <var>Q</var>. Find <var>R</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N, M \leq 500,000</var></li> <li>Both <var>N</var> and <var>M</var> are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>1500</var> points will be awarded for passing the testset satisfying <var>N = M</var> and <var>1 \leq N, M \leq 10^5</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Let <var>P/Q</var> be the expected number of correct answers you give if you follow an optimal strategy, represented as an irreducible fraction. Print <var>P \times Q^{-1}</var> modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>499122178 </pre> <p>There are two questions. You may answer randomly to the first question, and you'll succeed with 50% probability. Then, since you know the second answer is different from the first one, you'll succeed with 100% probability.</p> <p>The expected number of your correct answers is <var>3</var> / <var>2</var>. Thus, <var>P = 3</var>, <var>Q = 2</var>, <var>Q^{-1} = 499122177</var> (modulo <var>998244353</var>), and <var>P \times Q^{-1} = 499122178</var> (again, modulo <var>998244353</var>).</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>831870297 </pre> <p>The expected number of your correct answers is <var>17</var> / <var>6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>770074220 </pre> <p>The expected number of your correct answers is <var>169</var> / <var>35</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>208827570 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>42 23 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>362936761 </pre></section> </div> </span>
p03788
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has a lot of peculiar devices. These cylindrical devices receive balls from left and right. Each device is in one of the two states A and B, and for each state, the device operates as follows:</p> <ul> <li>When a device in state A receives a ball from either side (left or right), the device throws out the ball from the same side, then immediately goes into state B.</li> <li>When a device in state B receives a ball from either side, the device throws out the ball from the other side, then immediately goes into state A.</li> </ul> <p>The transition of the state of a device happens momentarily and always completes before it receives another ball.</p> <p>Takahashi built a contraption by concatenating <var>N</var> of these devices. In this contraption,</p> <ul> <li>A ball that was thrown out from the right side of the <var>i</var>-th device from the left (<var>1 \leq i \leq N-1</var>) immediately enters the <var>(i+1)</var>-th device from the left side.</li> <li>A ball that was thrown out from the left side of the <var>i</var>-th device from the left (<var>2 \leq i \leq N</var>) immediately enters the <var>(i-1)</var>-th device from the right side.</li> </ul> <p>The initial state of the <var>i</var>-th device from the left is represented by the <var>i</var>-th character in a string <var>S</var>. From this situation, Takahashi performed the following <var>K</var> times: put a ball into the leftmost device from the left side, then wait until the ball comes out of the contraption from either end. Here, it can be proved that the ball always comes out of the contraption after a finite time. Find the state of each device after <var>K</var> balls are processed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 200,000</var></li> <li><var>1 \leq K \leq 10^9</var></li> <li><var>|S|=N</var></li> <li>Each character in <var>S</var> is either <code>A</code> or <code>B</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a string that represents the state of each device after <var>K</var> balls are processed. The string must be <var>N</var> characters long, and the <var>i</var>-th character must correspond to the state of the <var>i</var>-th device from the left.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 ABAAA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>BBAAA </pre> <p>In this input, we put a ball into the leftmost device from the left side, then it is returned from the same place.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 ABAAA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>ABBBA </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 123456789 AABB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>BABA </pre></section> </div> </span>
p03272
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an <var>N</var>-car train.</p> <p>You are given an integer <var>i</var>. Find the value of <var>j</var> such that the following statement is true: "the <var>i</var>-th car from the front of the train is the <var>j</var>-th car from the back."</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq i \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>i</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>4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The second car from the front of a <var>4</var>-car train is the third car from the back.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>15 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre></section> </div> </span>
p02033
<h2>D: 矢 / Arrow</h2> <h3>問題</h3> <p>rodea 君は 1 次元座標系の中におり、<var>x = 0</var> の場所に立っている。この位置から、<var>x = N</var> の位置にある的を目がけて、 常に速さ <var>1</var> で移動する正の整数の長さの矢を投げる。しかし、rodea 君は非力なため、 区間 <var>0 \leq x \leq N</var> の中に合計 <var>M</var> 個の送風機を置くことにしている。</p> <p>ここで、矢の先端から根元までの位置に <var>1</var> つの送風機も含まれない場合を「損失」と定義する。損失の判定は、矢の先端が <var>x = 1, 2, 3,</var> $\ldots$<var>, N</var> に到達した際に行う(つまり、合計 <var>N</var> 回行う)。</p> <p>このとき、以下のクエリを <var>Q</var> 回処理せよ。</p> <ul> <li> 「損失」許容可能な回数 <var>l_i</var> が与えられる。すなわち、<var>N</var> 回の判定において、「損失」が合計 <var>l_i</var> 回以下なら矢を的に届けることが可能である。このときの、矢を的に届けるために必要な最短の矢の長さを求める。</li> </ul> <h3>入力形式</h3> <pre> <var>N</var> <var>M</var> <var>m_1</var> <var>m_2</var> $\ldots$ <var>m_M</var> <var>Q</var> <var>l_1</var> <var>l_2</var> $\ldots$ <var>l_Q</var> </pre> <p><var>1</var> 行目に距離 <var>N</var> と送風機の個数 <var>M</var> が空白区切りで与えられる。</p> <p><var>2</var> 行目に、<var>M</var> 個の送風機それぞれの位置が与えられる。<var>m_i=j</var> のとき、 <var>i</var> 番目の送風機は <var>x=j-1</var> と <var>x=j</var> の丁度中間に位置している。</p> <p><var>3</var> 行目にクエリの個数 <var>Q</var> が与えられ、<var>4</var> 行目に「損失」許容可能な回数 <var>l_i</var> が <var>Q</var> 個与えられる。</p> <h3>制約</h3> <ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq M \leq N</var></li> <li><var>1 \leq m_1 &lt; m_2 &lt;</var> $\ldots$<var> &lt; m_M \leq N</var></li> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>0 \leq l_i \leq 10^5</var> (<var>1 \leq i \leq Q</var>)</li> </ul> <h3>出力形式</h3> <p>与えられる <var>Q</var> 個の <var>l_i</var> に対して考えられる最短の矢の長さを、順に改行して出力せよ。</p> <p>ただし、条件を満たす正の整数の長さの矢が存在しない場合は <var>-1</var> を出力するものとする。</p> <h3>入力例1</h3> <pre> 5 1 2 1 3 </pre> <h3>出力例1</h3> <pre>2</pre> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-d-001.jsp" type="image/jpeg" width="500"></object> <p>矢の先端が <var>x = 1</var> に到達したとき、先端から根元までに送風機は含まれないので、「損失」回数は <var>1</var> になる。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-d-002.jpg" type="image/jpeg" width="500"></object> <p>矢の先端が <var>x = 2</var> に到達したとき、先端から根元までに送風機は含まれるので、「損失」回数は <var>1</var> のままである。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-d-003.jpg" type="image/jpeg" width="500"></object> <p>矢の先端が <var>x = 3</var> に到達したとき、先端から根元までに送風機は含まれるので、「損失」回数は <var>1</var> のままである。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-d-004.jpg" type="image/jpeg" width="500"></object> <p>矢の先端が <var>x = 4</var> に到達したとき、先端から根元までに送風機は含まれないので、「損失」回数は <var>2</var> になる。</p> <object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-d-005.jpg" type="image/jpeg" width="500"></object> <p>矢の先端が <var>x = 5</var> に到達したとき、先端から根元までに送風機は含まれないので、「損失」回数は <var>3</var> になる。</p> <p>長さ <var>2</var> より短い矢を投げる場合、「損失」回数が <var>3</var> よりも多くなるため、長さ <var>2</var> の矢を投げるときが条件を満たす最短の矢の長さである。</p> <h3>入力例2</h3> <pre> 11 3 2 5 9 3 1 4 8 </pre> <h3>出力例2</h3> <pre> 4 3 1 </pre>
p02199
<h2>走れ双子 (Run, Twins)</h2> <p>E869120君は、家から学校へ向かって分速 $P$ メートルで走り出しました。</p> <p>square1001君は、E869120君が家を出発してから $A$ 分後にE869120君の忘れ物に気が付き、分速 $Q$ メートルで追いかけました。</p> <p>その後、E869120君は、E869120君が家を出発してから $B$ 分後に忘れものに気が付き、分速 $R$ メートルで道を引き返しました。</p> <p>E869120君が家を出発してから何分後に双子は出会うでしょうか?</p> <p>ただし、$B$ 分後までにE869120君とsquare1001君が出会うことはありません。</p> <p>また、E869120君とsquare1001君の家から学校までは一本道であり、近道や別の道はないものとします。</p> <h3>入力</h3> <p>入力は以下の形式で標準入力から与えられる。</p> <pre> $A$ $B$ $P$ $Q$ $R$ </pre> <h3>出力</h3> <p>E869120君が家を出発してからE869120君とsquare1001君が出会うまでの時間を出力せよ。</p> <p>ただし、最後には改行を入れること。</p> <p>なお、想定解答との絶対誤差又は相対誤差が $10^{-3}$ 以内であれば正解として扱われる。</p> <h3>制約</h3> <ul> <li>$1 \leq A \leq B \leq 100$</li> <li>$1 \leq Q \leq P \leq 100$</li> <li>$1 \leq R \leq 100$</li> <li>入力は全て整数である。</li> </ul> <h3>入力例1</h3> <pre> 14 86 9 1 20 </pre> <h3>出力例1</h3> <pre> 119.428571428571 </pre> <h3>入力例2</h3> <pre> 1 4 15 9 2 </pre> <h3>出力例2</h3> <pre> 7.000000000000 </pre> <h3>入力例3</h3> <pre> 67 87 7 4 51 </pre> <h3>出力例3</h3> <pre> 96.618181818182 </pre>
p02463
<h1>Set Union</h1> <p> Find the union of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ </pre> <p> Elements of $A$ and $B$ are given in ascending order respectively. There are no duplicate elements in each set. </p> <h2>Output</h2> <p> Print elements in the union in ascending order. Print an element in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n, m \leq 200,000$</li> <li>$0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$</li> <li>$0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$</li> </ul> <h2>Sample Input 1</h2> <pre> 3 1 5 8 2 5 9 </pre> <h2>Sample Output 1</h2> <pre> 1 5 8 9 </pre>
p02176
<h1>B: Shortest Crypt</h1> <h2>問題</h2> <p> xryuseixくんの学校では暗号が流行している. 格子状の街に住んでいるxryuseixくんは集合場所を決める新しい暗号を考えた. </p> <p> 暗号文は $N$ 文字の文字列 $S$ からなり, $S_i$ の文字によって現在地からの移動方向を決める. 移動方向に関しては以下の通りである.<br> <ul> <li>A ~ M : 北に1マス進む.</li> <li>N ~ Z : 南に1マス進む.</li> <li>a ~ m : 東に1マス進む.</li> <li>n ~ z : 西に1マス進む.</li> </ul> </p> <p> さて,ここでxryuseixくんは, yryuseiyちゃんにデートの集合場所を暗号文で教えようと思ったのだが, 暗号文が冗長なことに気づいた. </p> <p> 例えば,「ANA」という暗号文があったとしよう. これは北に $1$ マス進み, 南へ $1$ マス進んだのち北へ $1$ マス進む. これは北に $1$ マス進む暗号文と等価なので,「ANA」=「A」と, 簡潔にできる. xryuseixくんはyryuseiyちゃんに遠回りをさせないよう,暗号文を簡潔にしようと思った. </p> <p> そこであなたはxryuseixくんに変わって, 暗号文を簡潔にするプログラムを書くことになった. なお, 「暗号文を簡潔にする」とは,「元の暗号文と同じ目的地へ行く最も短い暗号文を作る」ということである. </p> <h2>制約</h2> <ul> <li> $N$ は整数であり, $S_i$ は大文字または小文字のアルファベットである.</li> <li>$1 \leq N \leq 10^{5}$</li> </ul> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる. </p> <p> $N$<br> $S$<br> </p> <h2>出力</h2> <p> $1$ 行目に簡潔にした後の暗号文の長さ, $2$ 行目にその暗号文を出力せよ. 答えとしてありうる暗号文が複数存在する場合, どれを出力してもよい. また各行の末尾に改行を出力せよ. </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 5 ANazA </pre> <h3>サンプル出力 1</h3> <pre> 1 A </pre> <h3>サンプル入力 2</h3> <pre> 7 ACMICPC </pre> <h3>サンプル出力 2</h3> <pre> 5 HIJKL </pre> <h3>サンプル入力 3</h3> <pre> 4 AIZU </pre> <h3>サンプル出力 3</h3> <pre> 0 </pre> <P> 簡潔にした暗号文(空の文字列)のあとに改行が必要なことに注意. </P>
p02875
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a positive even number <var>N</var>.</p> <p>Find the number of strings <var>s</var> of length <var>N</var> consisting of <code>A</code>, <code>B</code>, and <code>C</code> that satisfy the following condition:</p> <ul> <li><var>s</var> can be converted to the empty string by repeating the following operation:<ul> <li>Choose two consecutive characters in <var>s</var> and erase them. However, choosing <code>AB</code> or <code>BA</code> is not allowed.</li> </ul> </li> </ul> <p>For example, <code>ABBC</code> satisfies the condition for <var>N=4</var>, because we can convert it as follows: <code>ABBC</code> → (erase <code>BB</code>) → <code>AC</code> → (erase <code>AC</code>) → <code>(empty)</code>.</p> <p>The answer can be enormous, so compute the count modulo <var>998244353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^7</var></li> <li><var>N</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of strings that satisfy the conditions, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>Except <code>AB</code> and <code>BA</code>, all possible strings satisfy the conditions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>50007 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>210055358 </pre></section> </div> </span>
p00848
<H1><font color="#000">Problem D:</font> Sum of Different Primes</H1> <p> A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers <i>n</i> and <i>k</i>, you should count the number of ways to express <i>n</i> as a sum of <i>k</i> different primes. Here, two ways are considered to be the same if they sum up the same set of the primes. For example, 8 can be expressed as 3 + 5 and 5+ 3 but they are not distinguished. </p> <p> When <i>n</i> and <i>k</i> are 24 and 3 respectively, the answer is two because there are two sets {2, 3, 19} and {2, 5, 17} whose sums are equal to 24. There are no other sets of three primes that sum up to 24. For <i>n</i> = 24 and <i>k</i> = 2, the answer is three, because there are three sets {5, 19}, {7,17} and {11, 13}. For <i>n</i> = 2 and <i>k</i> = 1, the answer is one, because there is only one set {2} whose sum is 2. For <i>n</i> = 1 and <i>k</i> = 1, the answer is zero. As 1 is not a prime, you shouldn't count {1}. For <i>n</i> = 4 and <i>k</i> = 2, the answer is zero, because there are no sets of two diffrent primes whose sums are 4. </p> <p> Your job is to write a program that reports the number of such ways for the given <i>n</i> and <i>k</i>. </p> <H2>Input</H2> <p> The input is a sequence of datasets followed by a line containing two zeros separated by a space. A dataset is a line containing two positive integers <i>n</i> and <i>k</i> separated by a space. You may assume that <i>n</i> &le; 1120 and <i>k</i> &le; 14. </p> <H2>Output</H2> <p> The output should be composed of lines, each corresponding to an input dataset. An output line should contain one non-negative integer indicating the number of ways for <i>n</i> and <i>k</i> specified in the corresponding dataset. You may assume that it is less than 2<sup>31</sup>. </p> <H2>Sample Input</H2> <pre> 24 3 24 2 2 1 1 1 4 2 18 3 17 1 17 3 17 4 100 5 1000 10 1120 14 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 3 1 0 0 2 1 0 1 55 200102899 2079324314 </pre>
p03767
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>3N</var> participants in <em>AtCoder Group Contest</em>. The <em>strength</em> of the <var>i</var>-th participant is represented by an integer <var>a_i</var>. They will form <var>N</var> teams, each consisting of three participants. No participant may belong to multiple teams.</p> <p>The strength of a team is defined as the second largest strength among its members. For example, a team of participants of strength <var>1</var>, <var>5</var>, <var>2</var> has a strength <var>2</var>, and a team of three participants of strength <var>3</var>, <var>2</var>, <var>3</var> has a strength <var>3</var>.</p> <p>Find the maximum possible sum of the strengths of <var>N</var> teams.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 10^5</var></li> <li><var>1 ≤ a_i ≤ 10^{9}</var></li> <li><var>a_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_{3N}</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 5 2 8 5 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p>The following is one formation of teams that maximizes the sum of the strengths of teams:</p> <ul> <li>Team <var>1</var>: consists of the first, fourth and fifth participants.</li> <li>Team <var>2</var>: consists of the second, third and sixth participants.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10000000000 </pre> <p>The sum of the strengths can be quite large.</p></section> </div> </span>
p03337
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given two integers <var>A</var> and <var>B</var>. Find the largest value 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><var>-1000 \leq A,B \leq 1000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the largest value 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>3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p><var>3+1=4</var>, <var>3-1=2</var> and <var>3 \times 1=3</var>. The largest among them is <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 -2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> <p>The largest is <var>4 - (-2) = 6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p00632
<H1><font color="#000000">Problem 06:</font> Ghost Buster!</H1> <p> 一般人には知る由も無いことだが、この街は幽霊で溢れている。そのほとんどは無害なのだが、困ったことに、人を呪う悪霊も少なからずいるのだ。 </p> <p> あるところに、そんな悪霊と戦う少女がいた。彼女は昼間は何食わぬ顔で高校に通いながらも、夜になると街中を歩き回り、彷徨える魂を見付けては成仏させるのだ。 </p> <p> 幽霊を成仏させるためにはまずその幽霊に接近する必要があるのだが、それは簡単なことではない。幽霊は物をすり抜けられるからだ。幽霊は民家に壁から侵入して勝手口から出て行ったり、信号の無い大通りを悠々と横断したりする。人間である彼女にはそんなことはできないので、幽霊を追跡するのはとても難しいのだ。 </p> <p> 彼女は経験上、幽霊が規則的な動きをすることを知っていた。そこで彼女は、この情報を活用して幽霊を追跡することを考えた。 </p> <p> 彼女のいる街は、(<i>H</i> &times; <i>W</i>)マスのグリッドとして表される。彼女も幽霊も、1分間に1回、次の5つの行動 </p> <ul> <li>東へ1マス進む</li> <li>西へ1マス進む</li> <li>南へ1マス進む</li> <li>北へ1マス進む</li> <li>その場に留まる</li> </ul> <p> のうちどれか1つを行うことができる。ただし、彼女は街の周囲に結界を張ったので、彼女も幽霊も街の外に出ることはできない。また、そのような行動をしようとした場合、代わりにその場に留まる。 </p> <p> それぞれのマスは '<span>#</span>' または '<span>.</span>' という文字によって表され、前者は幽霊だけが進入できるマスを、後者は両者が進入できるマスを表す。 </p> <p> 幽霊の行動パターンは、L個の行動の列として与えられる。幽霊はこれらの行動を最初から順番に実行していき、全ての行動を実行し終わるとまた最初の行動に戻り、順に実行し続ける。 </p> <p> 彼女と幽霊が N 分後に同じマスにいたならば、彼女と幽霊は時刻 N で遭遇したと言うことが出来る。幽霊は放っておくとどんな被害をもたらすか分からないので、彼女は出来るだけ早い時刻に幽霊を捕まえたい。なので、彼女は頼れる先輩であるあなたに、彼女と幽霊が遭遇できる最も早い時刻とその遭遇場所を求めるプログラムを書いてほしいと思っている。 </p> <p> さあ、彼女を助けて、彼女のありがたい言葉で彷徨える魂を極楽浄土へと導くのだ! </p> <H2>Input</H2> <p> 複数のデータセットが与えられる。 各データセットの形式を以下に示す。 <br> <p> <i>H W</i> (グリッドの南北方向のマスの数、グリッドの東西方向のマスの数: 空白区切りの2つの整数)<br> <i>H × W</i> の文字 (マスの種類:'<span>.</span>', '<span>#</span>', '<span>A</span>', または '<span>B</span>')<br> <i>pattern</i> (幽霊の行動パタン:文字列)<br> </p> <p> '<span>A</span>' は少女の初期位置、'<span>B</span>' は幽霊の初期位置を示す。両者の初期位置は、 '<span>.</span>' のマスの上にある。 </p> <p> <i>pattern</i> は '<span>5</span>', '<span>2</span>', '<span>4</span>', '<span>6</span>', '<span>8</span>' から成る文字列で、各文字の意味は以下の通りである: </p> <table border=1 cellspacing=4 cellpadding=4> <tr><td>'<span>5</span>'</td><td>その場に留まる</td></tr> <tr><td>'<span>8</span>'</td><td>北に1マス進む</td></tr> <tr><td>'<span>6</span>'</td><td>東に1マス進む</td></tr> <tr><td>'<span>4</span>'</td><td>西に1マス進む</td></tr> <tr><td>'<span>2</span>'</td><td>南に1マス進む</td></tr> </table> <p> 例えば、<i>pattern</i> が "<span>8544</span>" の場合、幽霊は「北に1マス進む」「その場に留まる」「西に1マス進む」「西に1マス進む」の行動パタンを繰り返す。 </p> <p> <i>H</i>, <i>W</i> は 1 以上 20 以下であり、<i>pattern</i> の長さは 10 以下である。 </p> <p> <i>H</i>, <i>W</i> がともに 0 のとき、入力は終了する。 </p> <H2>Output</H2> <p> もし少女が幽霊と遭遇できるならば、最も早い遭遇時刻と、その遭遇場所の南北方向の座標、東西方向の座標を空白で区切って1行に出力せよ。グリッドの最北西を座標(0, 0)とし、最南東を座標(<i>H</i>-1, <i>W</i>-1) とする。</p> <p> どのように行動しても絶対に遭遇できない場合は、 "<span>impossible</span>" と出力せよ。 </p> <H2>Sample Input</H2> <pre> 4 7 A#...#B .#.#.#. .#.#.#. ...#... 5 4 7 A#...#B .#.#.#. .#.#.#. ...#... 2 4 7 A#...#B .#.#.#. .#.#.#. ...#... 4 4 7 A#...#B .#.#.#. .#.#.#. ...#... 442668 1 10 A#.......B 55555554 1 10 A#.......B 55555555 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 18 0 6 15 3 6 6 0 0 14 0 4 72 0 0 impossible </pre>
p01920
<link rel="stylesheet" href="css/description.css" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/varmath2017.js" charset="UTF-8"></script> <h2>E:バイナリ列 - Binary Sequence -</h2> <h3>物語</h3> <p> わしはバイナリ大好きBonald.Brvin.Bnuthじゃ! オフトゥンフォード大学でバイナリ列の性質を研究しておってのお、Bnuthおじさんと呼ばれて、親しまれておるぞい! ちなみに、わしの名前「Bonald.Brvin.Bnuth」をASCIIコードからバイナリ化すると「1000010 1101111 1101110 1100001 1101100 1100100 101110 1000010 1110010 1110110 1101001 1101110 101110 1000010 1101110 1110101 1110100 1101000」になるぞい! 楽しいのお! </p> <p> 今日は、弟子が何やら面白そうな実験をすると言うからのお、朝から楽しみなんじゃ! どれどれ、どんなことをするんじゃの? </p> <p> なんと!バイナリ列を書き換え続けることで、何らかの性質を見出したいとな! ふむ!これは、重要な発見の匂いがぷんぷんするぞい! さあ、さあ、実験を始めようではないか! より詳細な設定を文章としてまとめておくぞい! </p> <h3>問題</h3> <p>長さ<var>n</var>のバイナリ列<var>x = (x_1, ..., x_n)</var> (<var>x_i \in \{0,1\}</var>, <var>i = 1,...,n</var>) が与えられる。バイナリ列<var>x</var>に対して2つの関数<var>f(x)</var>と<var>g(x)</var>を以下のように定義する。</p> <pre> <var>f(x) = &Sigma;_{i=1}^{n} x_i = x_1 + x_2 + ... + x_n</var> <var>g(x) = &Sigma;_{i=1}^{n-1} x_i x_{i+1} = x_1 x_2 + x_2 x_3 + ... x_{n-1} x_n</var> </pre> <p>今、バイナリ列<var>x</var>に対して以下のような変更操作を<var>q</var>回行う。<var>j</var>回目の変更操作は<var>l_j, r_j, b_j</var> (<var>1 \leq l_j \leq r_j \leq n</var>, <var>b_j \in \{0,1\}</var>, <var>j = 1,...,q</var>) で与えられ、これはバイナリ列<var>x</var>の<var>l_j</var>番目から<var>r_j</var>番目を<var>b_j</var>に置き換える操作に対応する。各変更操作の後で<var>f(x) - g(x)</var>を求めよ。</p> <h3>入力形式</h3> <pre> <var>n</var> <var>x</var> <var>q</var> <var>l_1 r_1 b_1</var> <var>...</var> <var>l_q r_q b_q</var> </pre> <p> 1行目にはバイナリ列の長さを表す整数<var>n</var>が与えられる。 2行目にはバイナリ列<var>x</var>を表せす文字列が与えられる。 3行目にはクエリの回数を表す整数<var>q</var>が与えられる。 続く<var>q</var>行のうち<var>i</var>行目には、<var>i</var>回目のクエリに関する情報<var>l_i, r_i, b_i</var>がこの順で空白区切りで与えられる。 </p> <h3>制約</h3> <ul> <li><var>2 \leq n \leq 100000</var></li> <li><var>x</var>は’0’、’1’からなる文字列</li> <li><var>|x| = n</var></li> <li><var>1 \leq q \leq 100000</var></li> <li><var>1 \leq l_j \leq r_j \leq n</var>, <var>b_j \in \{0,1\}</var>, <var>j = 1,...,q</var></li> </ul> <h3>出力形式</h3> <p>各<var>i=1,...,q</var>について、<var>i</var>行目に<var>i</var>回目のクエリを処理した後の<var>f(x) - g(x)</var>の値を出力せよ。</p> <h3>入力例1</h3> <pre> 10 0101100110 3 3 3 1 1 6 0 2 5 1 </pre> <h3>出力例1</h3> <pre> 2 1 2 </pre> <h3>入力例2</h3> <pre> 8 00111100 3 8 8 1 4 5 0 7 8 1 </pre> <h3>出力例2</h3> <pre> 2 3 2 </pre>
p00262
<H1>ブロックの三角形</H1> <p> 図a のように積まれたブロックに対し、以下の並べ替え操作を繰り返す。 </p> <ol> <li> 一番下のブロック全て(図a 中の白のブロック)を右端に新しく積み上げる(残りのブロックは自動的に1段下に落ち、図b のようになる)。</li> <li> ブロックの間に隙間ができたら、左に詰めて隙間をなくす(図 b から図c のようになる)。</li> </ol> <p> 1 以上の整数 k に対して、k&times;(k+1)/2 で表される数 (例:1, 3, 6, 10, ...)を三角数という。ブロックの総数が三角数の場合、上記の並べ替えを繰り返すと、左端の高さが1 で右に向かって1つずつ高くなっていくような三角形になると予想されている(図d は総数が15 個の場合)。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_triangleOfBlocks"> </center> <br/> <p> ブロックの最初の並びが与えられたとき、あらかじめ決められた回数以下の操作で、上で説明したようなブロックの三角形ができるとき、三角形が得られるまでの最小の操作回数を出力するプログラムを作成してください。 </p> <h2>入力</h2> <p> 入力は複数のデータセットからなる。入力の終わりはゼロ1つの行で示される。各データセットは以下の形式で与えられる。 </p> <pre> N b<sub>1</sub> b<sub>2</sub> ... b<sub>N</sub> </pre> <p> 各データセットは2行であり、ブロックの最初の並びを表す。N (1 &le; N &le; 100)は、一番下の段にあるブロックの数を示す。b<sub>i</sub>(1 &le; bi &le; 10000) は左から i 番目の位置に積まれているブロックの数を示す。b<sub>i</sub> と b<sub>i+1</sub> は1つの空白で区切られている。ブロックの総数は 3 以上である。 </p> <p> データセットの数は 20 を超えない。 </p> <h2>出力</h2> <p> データセットごとに、三角形ができるまでに行った並べ替え操作の回数を1行に出力する。ただし、三角形が作れない場合や、操作回数が 10000 回を超える場合は -1 を出力する。 </p> <h2>入力例</h2> <pre> 6 1 4 1 3 2 4 5 1 2 3 4 5 10 1 1 1 1 1 1 1 1 1 1 9 1 1 1 1 1 1 1 1 1 12 1 4 1 3 2 4 3 3 2 1 2 2 1 5050 3 10000 10000 100 0 </pre> <h2>出力例</h2> <pre> 24 0 10 -1 48 5049 -1 </pre> <p> 最初のデータセットが、図に示した場合に対応する。<br/> 4つ目のデータセットが、ブロックの総数が三角数でないため、三角形が作れない場合に対応する。<br/> 最後のデータセットが、ブロックの総数は三角数だが、操作回数が 10000 回を超える場合に対応する。 </p>
p00798
<H1><font color="#000">Problem C:</font> Push!!</H1> <p> Mr. Schwarz was a famous powerful pro wrestler. He starts a part time job as a warehouseman. His task is to move a cargo to a goal by repeatedly pushing the cargo in the warehouse, of course, without breaking the walls and the pillars of the warehouse. </p> <p> There may be some pillars in the warehouse. Except for the locations of the pillars, the floor of the warehouse is paved with square tiles whose size fits with the cargo. Each pillar occupies the same area as a tile. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_push"> </center> <p> Initially, the cargo is on the center of a tile. With one push, he can move the cargo onto the center of an adjacent tile if he is in proper position. The tile onto which he will move the cargo must be one of (at most) four tiles (i.e., east, west, north or south) adjacent to the tile where the cargo is present. </p> <p> To push, he must also be on the tile adjacent to the present tile. He can only push the cargo in the same direction as he faces to it and he cannot pull it. So, when the cargo is on the tile next to a wall (or a pillar), he can only move it along the wall (or the pillar). Furthermore, once he places it on a corner tile, he cannot move it anymore. </p> <p> He can change his position, if there is a path to the position without obstacles (such as the cargo and pillars) in the way. The goal is not an obstacle. In addition, he can move only in the four directions (i.e., east, west, north or south) and change his direction only at the center of a tile. </p> <p> As he is not so young, he wants to save his energy by keeping the number of required pushes as small as possible. But he does not mind the count of his pedometer, because walking is very light exercise for him. </p> <p> Your job is to write a program that outputs the minimum number of pushes required to move the cargo to the goal, if ever possible. </p> <H2>Input</H2> <p> The input consists of multiple maps, each representing the size and the arrangement of the warehouse. A map is given in the following format. </p> <pre> <i>w h</i> <i>d</i><sub>11</sub> <i>d</i><sub>12</sub> <i>d</i><sub>13</sub> ... <i>d</i><sub>1<i>w</i></sub> <i>d</i><sub>21</sub> <i>d</i><sub>22</sub> <i>d</i><sub>23</sub> ... <i>d</i><sub>2<i>w</i></sub> ... <i>d</i><sub><i>h</i>1</sub> <i>d</i><sub><i>h</i>2</sub> <i>d</i><sub><i>h</i>3</sub> ... <i>d</i><sub><i>h</i><i>w</i></sub> </pre> <p> The integers w and h are the lengths of the two sides of the floor of the warehouse in terms of widths of floor tiles. <i>w</i> and <i>h</i> are less than or equal to 7. The integer <i>d<sub>ij</sub></i> represents what is initially on the corresponding floor area in the following way. </p> <p> 0: nothing (simply a floor tile)</p> <p> 1: a pillar</p> <p> 2: the cargo</p> <p> 3: the goal</p> <p> 4: the warehouseman (Mr. Schwarz)</p> <p> Each of the integers 2, 3 and 4 appears exactly once as <i>d<sub>ij</sub></i> in the map. Integer numbers in an input line are separated by at least one space character. The end of the input is indicated by a line containing two zeros. </p> <H2>Output</H2> <p> For each map, your program should output a line containing the minimum number of pushes. If the cargo cannot be moved to the goal, -1 should be output instead. </p> <H2>Sample Input</H2> <pre> 5 5 0 0 0 0 0 4 2 0 1 1 0 1 0 0 0 1 0 0 0 3 1 0 0 0 0 5 3 4 0 0 0 0 2 0 0 0 0 0 0 0 0 3 7 5 1 1 4 1 0 0 0 1 1 2 1 0 0 0 3 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 6 6 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 4 0 0 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 -1 11 8 </pre>
p01023
<h1>Problem H: Caterpillar</h1> <p> とある天空都市に住む大学生のGは、芋虫のいも太郎を飼っている。 彼は、いも太郎に最短歩数で全てのえさを順番に食べるように躾けをした。彼の友人であるあなたは、彼からいも太郎が本当に躾けられているかどうかを調べて欲しいと依頼されたので、プログラムを書くことにした。 </p> <h2>Problem</h2> <p> 複数の障害物とエサがグリッド状のエリア内に存在する。頭と 5 つの胴体を持つ芋虫がこのエリアを探索する。芋虫が順番に最後までエサを食べたときの最小の歩数を求めよ。 ただし全てのエサを食べることが不可能な場合は -1 を出力すること。なお、エサの上に芋虫の頭が重なったとき、エサを食べることができる。 </p> <p> エリアは以下の文字で構成される。 </p> <ul> <li>何もないマス -> ‘.’</li> <li>障害物 -> ‘#’</lin> <li>エサ -> ‘1’, ‘2’, ..., ‘9’</li> <li>芋虫の初期位置 -> 頭 ‘S’, 胴体 ‘a’, ‘b’, ‘c’, ‘d’, ‘e’</li> </ul> <p> 芋虫は頭 ’S’ から 5 つの胴体 ‘a’, ‘b’, ‘c’, ‘d’, ‘e’ と 順に上下左右の 4 方向に隣接して、それらが連なって構成される。 例えば、芋虫の構成を表したとき、以下の (1) は正しい芋虫の構成であるが、 (2) や (3) のような構成はありえない。 </p> <pre> (1) 正しい .bc Sad ..e (2) eが存在しない Sab .dc (3) "Sab" と "cde" とで芋虫が切断されている Sab cde </pre> <p> (1) のような正しい芋虫の構成は、入力で与えられた状態から任意の回数の芋虫の移動の間、一貫して保たれる。 つまり、芋虫の頭が、隣接している 4 つのマスのうちのいずれかの空いているマスに一歩進むと、その後に続いて 1 番目の胴体は頭が元あったマスへ動き、2 番目の胴体は 1 番目の胴体が元あったマスへ、 3 番目は 2 番目の元へ‥… というように頭の軌跡をたどるように胴体が動く。以下は、1マス左へ動くときの例である。 </p> <pre> 移動前 移動後 ...... ...... ...bc. ...cd. ..Sad. .Sabe. ....e. ...... </pre> <p> 芋虫の移動できる場所は以下のように定められている。 </p> <ul> <li>芋虫は自分の胴体、障害物、エリア外を移動することは出来ない。ただしエサの上を、そのエサを食べずに移動することは出来る。</li> <li>移動前に胴体が進む先にあった場合でも、移動後に頭と胴体が重ならないならば移動できる。</li> </ul> <h2>Input</h2> <pre> <var>H</var> <var>W</var> <var>N</var> <var>area</var> </pre> <p> 入力は <var>H + 1</var> 行で与えられる。1行目には 3つの整数 <var>H</var>, <var>W</var>, <var>N</var> (<var>2 &le; H &le; 10, 2 &le; W &le; 10, 1 &le; N &le; 9</var>) が書かれている。<var>H</var>はエリアの高さ、<var>W</var>は幅、<var>N</var>がエサの個数を表す ( このとき <var>6 + N &le; H &times; W</var> が必ず成立する ) 。 </p> <p> 2 行目から <var>H + 1</var> 行目までの各行には ´S´,´1´, 2´ , … ´9´,´a´,´b´,´c´,´d´,´e´,´#´,´.´ からなる <var>W</var> 文字の文字列が書かれており,各々がエリアの各区画の状態を表している。また ´S´,´a´,´b´,´c´,´d´,´e´ は芋虫の初期状態を表している。初期状態の芋虫に覆われるようにしてエサや障害物は存在しない。また、芋虫の初期位置およびエサの位置は正しく入力されることが保証されている。 </p> <h2>Output</h2> <p> 芋虫がエサを順番通りに食べたときの最小の歩数、またそれが不可能なら -1 を出力せよ。 </p> <h2>Sample Input1</h2> <pre> 5 8 3 #....... #.####2# #.#.3..# #.###### .1Sabcde </pre> <h2>Sample Output1</h2> <pre> 14 </pre> <h2>Sample Input2</h2> <pre> 2 6 2 .1.baS .2.cde </pre> <h2>Sample Output2</h2> <pre> 7 </pre> <h2>Sample Input3</h2> <pre> 2 6 2 .1#baS .2.cde </pre> <h2>Sample Output3</h3> <pre> -1 </pre>
p01473
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h2>問題文</h2> <p>文字列 $S$ が与えられる。$S$ のすべてのアナグラムのうち、回文になっているものの個数を求めよ。</p> <p>文字列 $X$ が $Y$ のアナグラムであるとは、$X$ が $Y$ と等しいか、$X$ の文字を並び替えたら $Y$ に等しくなることをいう。例えば文字列abcdに対して、abcdやcbdaなどはアナグラムであるが、abedやcabやabcddなどはアナグラムでない。</p> <p>文字列 $X$ が回文であるとは、$X$ を逆から読んだものが $X$ 自身と等しくなることをいう。例えばabcやabは回文でなく、aやabccbaなどは回文である。</p> <h2>入力</h2> <p>入力は以下の形式に従う。</p> <pre>$S$</pre> <h2>制約</h2> <ul><li>$1 \leq |S| \leq 40$ ( $|S|$ は文字列 $S$ の長さ)</li> <li>$S$ は小文字の英字のみを含む。</li> <li>答は $2^{63}$ 未満であることが保証される。</li></ul> <h2>出力</h2> <p>個数を1行に出力せよ。</p> <h2>Sample Input 1</h2> <pre>ab</pre> <h2>Output for the Sample Input 1</h2> <pre>0</pre> <p>abのアナグラムはabとbaの二つがあるが、どちらも回文になっていない。</p> <h2>Sample Input 2</h2> <pre>abba</pre> <h2>Output for the Sample Input 2</h2> <pre>2</pre> <p>abbaとbaabの二つの文字列が回文かつアナグラムになっている。</p>
p01189
<H1><font color="#000">Problem I:</font> Roads in a City</H1> <p> Roads in a city play important roles in development of the city. Once a road is built, people start their living around the road. A broader road has a bigger capacity, that is, people can live on a wider area around the road. </p> <p> Interstellar Conglomerate of Plantation and Colonization (ICPC) is now planning to develop roads on a new territory. The new territory is a square and is completely clear. ICPC has already made several plans, but there are some difficulties in judging which plan is the best. </p> <p> Therefore, ICPC has collected several great programmers including you, and asked them to write programs that compute several metrics for each plan. Fortunately your task is a rather simple one. You are asked to compute the area where people can live from the given information about the locations and the capacities of the roads. </p> <p> The following figure shows the first plan given as the sample input. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_roadsInACity"> <p>Figure 1: The first plan given as the sample input</p> </center> <H2>Input</H2> <p> The input consists of a number of plans. The first line of each plan denotes the number <i>n</i> of roads (<i>n</i> &le; 50), and the following <i>n</i> lines provide five integers <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>, and <i>r</i>, separated by a space. (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub> ) and (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) denote the two endpoints of a road (-15 &le; <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>2</sub> &le; 15), and the value <i>r</i> denotes the capacity that is represented by the maximum distance from the road where people can live (<i>r</i> &le; 10). </p> <p> The end of the input is indicated by a line that contains only a single zero. </p> <p> The territory is located at -5 &le; <i>x</i>, <i>y</i> &le; 5. You may assume that each road forms a straight line segment and that any lines do not degenerate. </p> <H2>Output</H2> <p> Print the area where people can live in one line for each plan. You may print an arbitrary number of digits after the decimal points, provided that difference from the exact answer is not greater than 0.01. </p> <H2>Sample Input</H2> <pre> 2 0 -12 0 0 2 0 0 12 0 2 0 </pre> <H2>Output for the Sample Input</H2> <pre> 39.14159 </pre>
p01166
<H1><font color="#000">Problem D:</font> So Sleepy</H1> <p> You have an appointment to meet a friend of yours today, but you are so sleepy because you didn’t sleep well last night. </p> <p> As you will go by trains to the station for the rendezvous, you can have a sleep on a train. You can start to sleep as soon as you get on a train and keep asleep just until you get off. However, because of your habitude, you can sleep only on one train on your way to the destination. </p> <p> Given the time schedule of trains as well as your departure time and your appointed time, your task is to write a program which outputs the longest possible time duration of your sleep in a train, under the condition that you can reach the destination by the appointed time. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset looks like below: </p> <pre> <i>S T</i> <i>D Time<sub>D</sub> A Time<sub>A</sub></i> <i>N</i><sbu>1</sub> <i>K</i><sub>1,1</sub> <i>Time</i><sub>1,1</sub> ... <i>K</i><sub>1,<i>N</i><sub>1</sub></sub> <i>Time</i><sub>1,<i>N</i><sub>1</sub></sub> <i>N<sub>2</sub></i> <i>K</i><sub>2,1</sub> <i>Time</i><sub>2,1</sub> ... <i>K</i><sub>2,<i>N</i><sub>2</sub></sub> <i>Time</i><sub>2,<i>N</i><sub>2</sub></sub> ... <i>N<sub>T</sub></i> <i>K</i><sub><i>T</i>,1</sub> <i>Time</i><sub><i>T</i>,1</sub> ... <i>K</i><sub><i>T</i>,<i>N</i><sub><i>T</i></sub></sub> <i>Time</i><sub><i>T</i>,<i>N</i><sub><i>T</i></sub></sub> </pre> <p> The first line of each dataset contains S (1 &le; S &le; 1000) and <i>T</i> (0 &le; <i>T</i> &le; 100), which denote the numbers of stations and trains respectively. The second line contains the departure station (<i>D</i>), the departure time (<i>Time<sub>D</sub></i> ), the appointed station (<i>A</i>), and the appointed time (<i>Time<sub>A</sub></i> ), in this order. Then <i>T</i> sets of time schedule for trains follow. On the first line of the <i>i</i>-th set, there will be <i>N<sub>i</sub></i> which indicates the number of stations the <i>i</i>-th train stops at. Then <i>N<sub>i</sub></i> lines follow, each of which contains the station identifier (<i>K<sub>i,j</sub></i> ) followed by the time when the train stops at (i.e. arrives at and/or departs from) that station (<i>Time<sub>i,j</sub></i> ). </p> <p> Each station has a unique identifier, which is an integer between 1 and <i>S</i>. Each time is given in the format <i>hh</i>:<i>mm</i>, where <i>hh</i> represents the two-digit hour ranging from “00” to “23”, and <i>mm</i> represents the two-digit minute from “00” to “59”. The input is terminated by a line that contains two zeros. </p> <p> You may assume the following: </p> <ul> <li> each train stops at two stations or more; </li> <li> each train never stops at the same station more than once;</li> <li> a train takes at least one minute from one station to the next;</li> <li> all the times that appear in each dataset are those of the same day; and</li> <li> as being an expert in transfer, you can catch other trains that depart at the time just you arrive the station.</li> </ul> <H2>Output</H2> <p> For each dataset, your program must output the maximum time in minutes you can sleep if you can reach to the destination station in time, or “impossible” (without the quotes) otherwise. </p> <H2>Sample Input</H2> <pre> 3 1 1 09:00 3 10:00 3 1 09:10 2 09:30 3 09:40 3 2 1 09:00 1 10:00 3 1 09:10 2 09:30 3 09:40 3 3 09:20 2 09:30 1 10:00 1 0 1 09:00 1 10:00 1 0 1 10:00 1 09:00 3 1 1 09:00 3 09:35 3 1 09:10 2 09:30 3 09:40 4 3 1 09:00 4 11:00 3 1 09:10 2 09:20 4 09:40 3 1 10:30 3 10:40 4 10:50 4 1 08:50 2 09:30 3 10:30 4 11:10 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 30 30 0 impossible impossible 60 </pre>
p01536
<h1> Transparent Mahjong</h1> <h2> F: 透明な麻雀牌</h2> <p> あなたは,闇に舞い降りた天災と噂されるギャンブラーの鷹巣さんと麻雀で対局することになった. 鷹巣さんは天災と噂されるだけあって,鷹巣牌という奇怪な麻雀牌を用いた対局を提案してきた. </p> <p> 麻雀とは,プレイヤーが互いに手牌という複数枚の牌を持ち合い,自分の手牌を相手よりもはやく,アガリの形にすることで勝利が確定するゲームである. 麻雀の牌の表側には,その牌が何であるかが描かれており,牌の裏側には,何も描かれていない. よって,あなたが麻雀で対局するときは,あなたの手牌の表側をあなたの側に,裏側を対局者の側に向けるとよい. こうすることで,あなたの手牌が何であるかは,あなたのみが知ることができる. 麻雀の醍醐味は,プレイヤーが互の手配を読み合い,それを楽しむことにある. </p> <p> しかしながら,鷹巣牌は透明な麻雀牌である. 鷹巣牌は透明であるため,プレイヤーは互いに相手の手牌を知ることができる. これでは,手配の読み合いを楽しむことができない. </p> <p> 「もはや,これは麻雀ではない.」と,鷹巣牌を用いることに納得できないあなたは,鷹巣さんとの紆余曲折を経た協議の結果,鷹巣牌と普通の麻雀牌を混ぜて対局することになった. </p> <p> 手始めに,あなたは,鷹巣さんの手牌のアガリ牌が何であるかを予想することにした. 鷹巣さんの手牌は,鷹巣牌と普通の牌から構成される. 問題の簡単のため,鷹巣牌と普通の牌は,1から12の12種類各4枚からなるものとする. </p> <p> 3<i>n</i>+2枚の牌からなる手牌について,次の3つの条件が満たされるとき,その手牌はアガリである. </p> <ul> <li> 同じ数字を組み合わせた牌の組が1つ存在する</li> <li> 残りの3<i>n</i>枚の牌は,3個の数字の組合せの<i>n</i>グループになる</li> <li> それぞれのグループは,同じ数字を3つ組み合わせたものか,3つの連続する数字を組み合わせたものである</li> </ul> <p> 例えば, </p> <pre> 1 1 1 3 3 3 5 5 5 7 7 7 8 9 </pre> <p> のような14枚の牌は,全て鷹巣牌で構成されている. この場合,次のように2つの牌の組合せ1つと4つのグループを作ることができ,アガリである. </p> <pre> (1 1 1) (3 3 3) (5 5 5) (7 7) (7 8 9) </pre> <p> 次に,普通の牌と鷹巣牌が混ざった手牌の例を挙げる. </p> <pre> 1 1 1 3 3 3 5 5 5 7 7 7 * * </pre> <p> のような14枚の牌は,12枚の鷹巣牌と2枚の普通の牌(*)で構成されている. この場合,次のように2つの普通の牌が8と9であるかもしれないので,2つの牌の組合せ1つと4つのグループを作ることができ,アガリであるかもしれない. </p> <pre> (1 1 1) (3 3 3) (5 5 5) (7 7) (7 [8] [9]) </pre> <p> 同じ例について,次のように2つの普通の牌が8と8であるかもしれないので,以下のような形のアガリであるかもしれない. </p> <pre> (1 1 1) (3 3 3) (5 5 5) (7 7 7) ([8] [8]) </pre> <p> しかし,7という同じ牌は4枚までしか使えないので,以下のような形のアガリであることはない. </p> <pre> (1 1 1) (3 3 3) (5 5 5) (7 7 7) ([7] [7]) </pre> <p> 鷹巣さんの3<i>n</i>+1枚の手牌が入力として与えられたときに, 鷹巣さんの手牌に1枚の牌を加えて,3<i>n</i>+2枚の手牌を作ることを考える. このときに,3<i>n</i>+2枚の手牌がアガリになり得るような加える1枚の牌(アガリ牌)を全て求めよ. </p> <h2> Input</h2> <p> 入力は,次の形式で与えられる. </p> <pre> <i>n</i> <i>牌<sub>1</sub></i> <i>牌<sub>2</sub></i> ... <i>牌<sub>3n+1</sub></i> </pre> <p> 入力データは次の条件を満たす <i>n</i>は,0 &lt;= <i>n</i> &lt;= 15を満たす. 各牌は,鷹巣牌か普通の牌である.鷹巣牌の場合は,1以上12以下の整数で表され,普通の牌の場合は,文字*で表される. </p> <h2> Output</h2> <p> アガリ牌の一覧を昇順に出力せよ.アガリ牌を1つ出力する度に改行を出力せよ. あがり牌がない場合は,-1を1行に表示せよ. </p> <h2> Sample Input 1</h2> <pre> 4 1 1 1 3 3 3 5 5 5 7 7 7 9 </pre> <h2> Sample Output 1</h2> <pre> 8 9 </pre> <h2> Sample Input 2</h2> <pre> 4 1 2 2 3 3 4 5 6 7 8 8 8 9 </pre> <h2> Sample Output 2</h2> <pre> 1 4 7 9 10 </pre> <h2> Sample Input 3</h2> <pre> 4 1 1 1 4 4 4 7 7 7 8 8 9 * </pre> <h2> Sample Output 3</h2> <pre> 6 7 8 9 10 11 </pre> <h2> Sample Input 4</h2> <pre> 4 1 * * * * * * * * * * * * </pre> <h2> Sample Output 4</h2> <pre> 1 2 3 4 5 6 7 8 9 10 11 12 </pre> <h2> Sample Input 5</h2> <pre> 1 3 * 1 4 </pre> <h2> Sample Output 5</h2> <pre> 1 2 4 5 </pre>
p00777
<h3>Bridge Removal</h3> <p> ICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the project is to remove all the bridges connecting the islands. </p> <p> There are <i>n</i> islands and <i>n</i>-1 bridges. The bridges are built so that all the islands are reachable from all the other islands by crossing one or more bridges. The bridge removal team can choose any island as the starting point, and can repeat either of the following steps. </p> <ul> <li>Move to another island by crossing a bridge that is connected to the current island.</li> <li>Remove one bridge that is connected to the current island, and stay at the same island after the removal.</li> </ul> <p> Of course, a bridge, once removed, cannot be crossed in either direction. Crossing or removing a bridge both takes time proportional to the length of the bridge. Your task is to compute the shortest time necessary for removing all the bridges. Note that the island where the team starts can differ from where the team finishes the work. </p> <h3>Input</h3> <p> The input consists of at most 100 datasets. Each dataset is formatted as follows. </p> <blockquote> <i>n</i><br> <i>p</i><sub>2</sub> <i>p</i><sub>3</sub> ... <i>p<sub>n</sub></i> <br> <i>d</i><sub>2</sub> <i>d</i><sub>3</sub> ... <i>d<sub>n</sub></i> </blockquote> <p> The first integer <i>n</i> (3 &#8804; <i>n</i> &#8804; 800) is the number of the islands. The islands are numbered from 1 to <i>n</i>. The second line contains <i>n</i>-1 island numbers <i>p<sub>i</sub></i> (1 &#8804; <i>p<sub>i</sub></i> &lt; <i>i</i>), and tells that for each <i>i</i> from 2 to <i>n</i> the island <i>i</i> and the island <i>p<sub>i</sub></i> are connected by a bridge. The third line contains <i>n</i>-1 integers <i>d<sub>i</sub></i> (1 &#8804; <i>d<sub>i</sub></i> &#8804; 100,000) each denoting the length of the corresponding bridge. That is, the length of the bridge connecting the island <i>i</i> and <i>p<sub>i</sub></i> is <i>d<sub>i</sub></i>. It takes <i>d<sub>i</sub></i> units of time to cross the bridge, and also the same units of time to remove it. Note that, with this input format, it is assured that all the islands are reachable each other by crossing one or more bridges. </p> <p> The input ends with a line with a single zero. </p> <h3>Output</h3> <p> For each dataset, print the minimum time units required to remove all the bridges in a single line. Each line should not have any character other than this number. </p> <h3>Sample Input</h3> <pre>4 1 2 3 10 20 30 10 1 2 2 1 5 5 1 8 8 10 1 1 20 1 1 30 1 1 3 1 1 1 1 0 </pre> <h3>Output for the Sample Input</h3> <pre>80 136 2 </pre>
p03858
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> pinholes on the <var>xy</var>-plane. The <var>i</var>-th pinhole is located at <var>(x_i,y_i)</var>.</p> <p>We will denote the Manhattan distance between the <var>i</var>-th and <var>j</var>-th pinholes as <var>d(i,j)(=|x_i-x_j|+|y_i-y_j|)</var>.</p> <p>You have a peculiar pair of compasses, called <em>Manhattan Compass</em>. This instrument always points at two of the pinholes. The two legs of the compass are indistinguishable, thus we do not distinguish the following two states: the state where the compass points at the <var>p</var>-th and <var>q</var>-th pinholes, and the state where it points at the <var>q</var>-th and <var>p</var>-th pinholes.</p> <p>When the compass points at the <var>p</var>-th and <var>q</var>-th pinholes and <var>d(p,q)=d(p,r)</var>, one of the legs can be moved so that the compass will point at the <var>p</var>-th and <var>r</var>-th pinholes.</p> <p>Initially, the compass points at the <var>a</var>-th and <var>b</var>-th pinholes. Find the number of the pairs of pinholes that can be pointed by the compass.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦10^5</var></li> <li><var>1≦x_i, y_i≦10^9</var></li> <li><var>1≦a &lt; b≦N</var></li> <li>When <var>i ≠ j</var>, <var>(x_i, y_i) ≠ (x_j, y_j)</var></li> <li><var>x_i</var> and <var>y_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a</var> <var>b</var> <var>x_1</var> <var>y_1</var> : <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the pairs of pinholes that can be pointed by the compass.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 1 1 4 3 6 1 5 5 4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>Initially, the compass points at the first and second pinholes.</p> <p>Since <var>d(1,2) = d(1,3)</var>, the compass can be moved so that it will point at the first and third pinholes.</p> <p>Since <var>d(1,3) = d(3,4)</var>, the compass can also point at the third and fourth pinholes.</p> <p>Since <var>d(1,2) = d(2,5)</var>, the compass can also point at the second and fifth pinholes.</p> <p>No other pairs of pinholes can be pointed by the compass, thus the answer is <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 2 3 1 3 5 3 3 5 8 4 4 7 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 1 2 1 5 4 3 8 2 4 7 8 8 3 3 6 6 4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7 </pre></section> </div> </span>
p01865
<!-- - - - - - begin nicebody - - - - - --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>A: 秤 / Steelyard</h1> <h2>問題文</h2> <p> 情太くんは長さ $2L$ の棒を使って下の図のような秤を作った. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_A1"> <p> 棒には等間隔に $2L+1$ 個の穴があけられ,左から順に $-L, -L+1, \cdots, -1, 0, 1, \cdots, L-1, L$ という番号が付けられている.そして $0$ 番の穴の場所を天井から紐で吊るしてある. </p> <p> 情太くんは,秤の穴に $N$ 個のおもりを吊るした.$i$ 番目のおもりを吊るした穴の番号は $x_i$ で,おもりの重さは $w_i$ である.おもりが $1$ つも吊るされない穴や,複数のおもりが吊るされる穴も存在しうる. </p> <p> 情太くんが吊るしたおもりによっては,秤が傾いているかもしれない.姉の立子さんは,追加でいくつかの重りを吊るすことで秤を水平にしたい (おもりの座標と重さ積の総和が $0$ になるとき秤は水平になる).条件を満たすおもりの吊るし方を $1$ つ出力しなさい.候補が複数ある場合はどれを出力してもよい. </p> <h2>入力</h2> <p> $L$<br> $N$<br> $x_1 \ w_1$<br> $\vdots$<br> $x_N \ w_N$<br> </p> <h2>入力の制約</h2> <p> $1 \leq L \leq 30$<br> $1 \leq N \leq 30$<br> $|x_i| \leq L$<br> $1 \leq w_i \leq 30$<br> 全て整数<br> </p> <h2>出力</h2> <p> 答えは次のような形式で出力せよ. $1$ 行目の $N’$ は立子さんが吊るしたおもりの数である. $1+i$ 行目の $x_i’, w_i’$ は,それぞれ立子さんが吊るしたおもりの位置と重さである. </p> <p> $N'$<br> $x_1' \ w_1'$<br> $\vdots$<br> $x_N' \ w_N'$<br> </p> <h2>出力の制約</h2> <p> 立子さんが追加で吊り下げるおもりは,以下の条件を満たす必要がある. </p> <p> $0 \leq N' \leq 50000$<br> $|x_i'| \leq L$<br> $1 \leq w_i' \leq 50000$<br> 全て整数<br> </p> <h2>サンプル</h2> <h3>サンプル入力1</h3> <pre> 3 3 1 1 2 1 3 1 </pre> <h3>サンプル出力1</h3> <pre> 1 -3 2 </pre> <p> 他にも,例えば以下のような出力も正解として扱われる. </p> <pre> 2 -3 1 -3 1 </pre> <p> これらを図示すると次のようになる. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_A2"> <h3>サンプル入力2</h3> <pre> 3 3 1 1 0 2 -1 3 </pre> <h3>サンプル出力2</h3> <pre> 1 2 1 </pre> <h3>サンプル入力3</h3> <pre> 10 4 1 2 2 3 -7 1 -1 1 </pre> <h3>サンプル出力3</h3> <pre> 0 </pre> <p> 秤は最初から釣り合っていることもある. </p> <!-- - - - - - end nicebody - - - - - -->
p00327
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>消える数列、消えない数列</H1> <p> ただお君は頭の体操をするために、数列を使ったゲームをしています。このゲームでは、はじめに、1から9までの数字がランダムに並んだ列が与えられます。ただお君は、数列からその一部分を消していきます。ルールは、以下の通りです。 </p> <ul> <li> 数列から、同じ数字が2つ以上並んでいる部分を適当に選ぶ。その部分を含み、連続して現れている同じ数字をすべて消す。</li> <li> 消した部分の右側に数列が残っていた場合は、それを左に詰めて、数列を1つにまとめる。</li> <li> 上の2つの操作を繰り返した結果、すべての数字が消えればゲームクリアとなる。</li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_array"><br/> </center> <br/> <p> 例えば、上の図のような 1,2,3,3,2,2,1,2,2 という数列の場合、<br/> 左から数えて、3番目、4番目の3を消すと 1,2,2,2,1,2,2 <br/> 左から数えて、2番目から4番目の2を消すと 1,1,2,2<br/> 左から数えて、1番目と2番目の1を消すと 2,2<br/> 左から数えて、1番目と2番目の2を消すと、ゲームクリアとなります。 </p> <p> ただし、どのように数字を消してもクリアできない数列があります。たとえば、1,2,3,3,1,2 や 1,2,3,1,2,3 などの数列です。短い数列であれば、ただお君でもクリアできるかどうかがすぐに分かり、クリアできないと分かれば違う数列にチャレンジできますが、長い数列になるとそう簡単にはいきません。 </p> <p> 与えられた数列が上のゲームをクリアできるかどうか判定するプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>N</sub></var> </pre> <p> 1行目の <var>N</var> (1 &le; <var>N</var> &le; 100) は、数列の長さを表す整数である。2行目には1つの空白で区切られた <var>N</var> 個の整数 <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; 9) が与えられる。<var>c<sub>i</sub></var> は数列の <var>i</var> 番目の数字を示す。 </p> <h2>Output</h2> <p> 上に示されたルールで数列を消すことができる場合は「yes」、できない場合は「no」を出力する。 </p> <h2>Sample Input 1</h2> <pre> 8 1 2 3 3 2 1 2 2 </pre> <h2>Sample Output 1</h2> <pre> yes </pre> <br/> <h2>Sample Input 2</h2> <pre> 7 1 2 2 1 1 3 3 </pre> <h2>Sample Output 2</h2> <pre> yes </pre> <br/> <h2>Sample Input 3</h2> <pre> 16 9 8 8 7 7 6 5 4 4 5 1 1 2 2 3 3 </pre> <h2>Sample Output 3</h2> <pre> no </pre> <br/> <h2>Sample Input 4</h2> <pre> 5 1 1 2 2 1 </pre> <h2>Sample Output 4</h2> <pre> yes </pre>
p00448
<H1> おせんべい </H1> <h2>問題</h2> <p> IOI製菓では,創業以来の伝統の製法で煎餅(せんべい)を焼いている.この伝統の製法は,炭火で一定時間表側を焼き,表側が焼けると裏返して,炭火で一定時間裏側を焼くというものである.この伝統を守りつつ,煎餅を機械で焼いている.この機械は縦 R (1 &le; R &le; 10) 行, 横 C (1 &le; C &le; 10000) 列の長方形状に煎餅を並べて焼く.通常は自動運転で,表側が焼けたら一斉に煎餅を裏返し裏側を焼く. </p> <p> ある日,煎餅を焼いていると,煎餅を裏返す直前に地震が起こり何枚かの煎餅が裏返ってしまった.幸いなことに炭火の状態は適切なままであったが,これ以上表側を焼くと創業以来の伝統で定められている焼き時間を超えてしまい,煎餅の表側が焼けすぎて商品として出荷できなくなる.そこで,急いで機械をマニュアル操作に変更し,まだ裏返っていない煎餅だけを裏返そうとした.この機械は,横の行を何行か同時に裏返したり縦の列を何列か同時に裏返したりすることはできるが,残念なことに,煎餅を1枚ごと裏返すことはできない. </p> <p> 裏返すのに時間がかかると,地震で裏返らなかった煎餅の表側が焼けすぎて商品として出荷できなくなるので,横の何行かを同時に1回裏返し,引き続き,縦の何列かを同時に1回裏返して,表側を焼きすぎずに両面を焼くことのできる煎餅,つまり,「出荷できる煎餅」の枚数をなるべく多くすることにした.横の行を1行も裏返さない,あるいは,縦の列を1列も裏返さない場合も考えることにする.出荷できる煎餅の枚数の最大値を出力するプログラムを書きなさい. </p> <p> 地震の直後に,煎餅が次の図のような状態になったとする.黒い丸が表側が焼ける状態を,白い丸が裏側が焼ける状態を表している. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_osenbei1"> <p> 1行目を裏返すと次の図のような状態になる. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_osenbei2"> <p> さらに, 1列目と5列目を裏返すと次の図のような状態になる.この状態では,出荷できる煎餅は9枚である. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_osenbei3"> <h2>ヒント</h2> <p> R の上限 10 は C の上限 10000 に比べて小さいことに注意せよ. </p> <h2>入力</h2> <p> 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. </p> <p> 入力の1行目には2つの整数 R, C (1 &le; R &le; 10, 1 &le; C &le; 10 000) が空白を区切りとして書かれている.続く R 行は地震直後の煎餅の状態を表す. (i+1) 行目 (1 &le; i &le; R) には, C 個の整数 a<sub>i,1</sub>, a<sub>i,2</sub>, ……, a<sub>i,C</sub> が空白を区切りとして書かれており, a<sub>i,j</sub> は i 行 j 列 の煎餅の状態を表している. a<sub>i,j</sub> が 1 なら表側が焼けることを, 0 なら裏側が焼けることを表す. </p> <p> C, R がともに 0 のとき入力の終了を示す. データセットの数は 5 を超えない. </p> <h2>出力</h2> <p> <!--提出する出力ファイルは,出荷できる煎餅の最大枚数だけを含む1行からなる.--> データセットごとに,出荷できる煎餅の最大枚数を1行に出力する. </p> <h2>入出力例</h2> <h3>入力例</h3> <pre> 2 5 0 1 0 1 0 1 0 0 0 1 3 6 1 0 0 0 1 0 1 1 1 0 1 0 1 0 1 1 0 1 0 0 </pre> <h3>出力例</h3> <pre> 9 15 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p02475
<h2>Division of Big Integers</h2> <p> Given two integers $A$ and $B$, compute the quotient, $\frac{A}{B}$. Round down to the nearest decimal. </p> <h3>Input</h3> <p> Two integers $A$ and $B$ separated by a space character are given in a line. </p> <h3>Output</h3> <p> Print the quotient in a line. </p> <h3>Constraints</h3> <ul> <li>$-1 \times 10^{1000} \leq A, B \leq 10^{1000}$</li> <li>$B \ne 0$</li> </ul> <h3>Sample Input 1</h3> <pre> 5 8 </pre> <h3>Sample Output 1</h3> <pre> 0 </pre> <h3>Sample Input 2</h3> <pre> 100 25 </pre> <h3>Sample Output 2</h3> <pre> 4 </pre> <h3>Sample Input 3</h3> <pre> -1 3 </pre> <h3>Sample Output 3</h3> <pre> 0 </pre> <h3>Sample Input 4</h3> <pre> 12 -3 </pre> <h3>Sample Output 4</h3> <pre> -4 </pre>
p00018
<H1>Sorting Five Numbers</H1> <p> Write a program which reads five numbers and sorts them in descending order. </p> <H2>Input</H2> <p> Input consists of five numbers <var>a</var>, <var>b</var>, <var>c</var>, <var>d</var> and <var>e</var> (-100000 &le; <var>a</var>, <var>b</var>, <var>c</var>, <var>d</var>,<var>e</var> &le; 100000). The five numbers are separeted by a space. </p> <H2>Output</H2> <p> Print the ordered numbers in a line. Adjacent numbers should be separated by a space. </p> <H2>Sample Input</H2> <pre> 3 6 9 7 5 </pre> <H2>Output for the Sample Input</H2> <pre> 9 7 6 5 3 </pre>
p02025
<h2>K: 救済 (Angel Relief)</h2> <p>天使の天真さんは、ある街を救うことにした。</p> <p>この街は南北 $H$ 区画 × 東西 $W$ 区画に分けられた長方形の形をしており、各区画に家がある。</p> <p>北から数えて $X$ 番目、西から数えて $Y$ 番目の区画を $(X, Y)$ で表す。</p> <p>区画 $(i, j)$ にある家には $A_{i, j}$ 人の人が住んでいる。</p> <p>天真さんは、辺が南北または東西に平行または垂直な長方形のエリアを選び、その中に住んでいる人全員を<b>ひとりずつ</b>救済する。</p> <p>天真さんは、考えられるすべての長方形でこの操作を行う。</p> <p>天真さんが人を救済する回数の合計を求めよ。</p> <h3>入力</h3> <p>1 行目に、整数 $H, W$ が空白区切りで与えられる。</p> <p>続く $H$ 行のうち $i$ 行目には、整数 $A_{i, 1}, A_{i, 2}, A_{i, 3}, \dots, A_{i, W}$ が空白区切りで与えられる。</p> <h3>出力</h3> <p>天真さんが人を救済する回数の合計を出力せよ。</p> <h3>制約</h3> <ul> <li>$H, W$ は $1$ 以上 $500$ 以下の整数</li> <li>$A_{i, j}$ はすべて $1$ 以上 $9$ 以下の整数である。</li> </ul> <h3>入力例1</h3> <pre> 2 2 1 2 4 8 </pre> <h3>出力例1</h3> <pre> 60 </pre> <p>例えば、左上を $(1, 1)$、右下を $(2, 2)$ となるように長方形のエリアを選ぶと、そこにいる $15$ 人をひとりずつ救済するので、合計 $15$ 回の救済を行う。</p> <p>$9$ 通りの長方形のエリアに対して、それぞれ $1, 2, 3, 4, 5, 8, 10, 12, 15$ 回の救済を行うので、合計で $60$ 回である。</p> <h3>入力例2</h3> <pre> 2 3 1 2 3 4 5 6 </pre> <h3>出力例2</h3> <pre> 140 </pre>
p03264
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find the number of ways to choose a pair of an even number and an odd number from the positive integers between <var>1</var> and <var>K</var> (inclusive). The order does not matter.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2\leq K\leq 100</var></li> <li><var>K</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to choose a pair of an even number and an odd number from the positive integers between <var>1</var> and <var>K</var> (inclusive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Two pairs can be chosen: <var>(2,1)</var> and <var>(2,3)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 </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>11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>30 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>625 </pre></section> </div> </span>
p01259
<H1><font color="#000">Problem J:</font> Tile Puzzle</H1> <p> You are visiting Ancient and Contemporary Museum. Today there is held an exhibition on the history of natural science. You have seen many interesting exhibits about ancient, medieval, and modern science and mathematics, and you are in a resting space now. </p> <p> You have found a number of panels there. Each of them is equipped with <i>N</i> &times; <i>N</i> electric tiles arranged in a square grid. Each tile is lit in one of the following colors: black (unlit), red, green, yellow, blue, magenta, and cyan. Initially all the tiles are in black. When a tile is touched on, that tile and the eight adjacent tiles will change their colors as follows: black -&gt; red, red -&gt; green, green -&gt; yellow, yellow -&gt; blue, blue -&gt; magenta, magenta -&gt; cyan, and cyan -&gt; black. Here, the leftmost and rightmost columns are considered adjacent, and so as the uppermost and lowermost rows. There is a goal pattern for each panel, and you are to change the colors of the tiles as presented in the goal pattern. For example, if you are given the goal pattern shown in the figure below for a panel of 4 &times; 4, you will touch on the upper-left tile once and then on the lower-right tile twice (note that this might not be the only way). </p> <p> Since you are good at programming, you guess you can find the solution using your computer. So your job in this problem is to write a program for it. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tilePuzzle"> <p>Figure 1: Example Goal Pattern</p> </center> <H2>Input</H2> <p> The input contains a series of datasets. Each dataset is given in the following format: </p> <pre> <i>N</i> <i>Row</i><sub>1</sub> ... <i>Row<sub>N</sub></i> </pre> <p> <i>N</i> indicates the size (i.e. the number of rows and columns) of the electrical panel (3 &le; <i>N</i> &le; 15). <i>Row<sub>i</sub></i> describes the goal pattern of the <i>i</i>-th row and contains exactly <i>N</i> numbers separated by a space. The <i>j</i>-th number indicates the color of the <i>j</i>-th column, and it is one of the following: 0 (denoting black), 1 (red), 2 (green), 3 (yellow), 4 (blue), 5 (magenta), and 6 (cyan). </p> <p> The input is terminated by a line containing a single zero. This line is not part of any datasets. </p> <H2>Output</H2> <p> For each dataset, your program should produce the output of <i>N</i> lines. The <i>i</i>-th line should correspond to the <i>i</i>-th row and contain exactly <i>N</i> numbers separated by a space, where the <i>j</i>-th number should be the number of touches on the tile of the <i>j</i>-th column. The number should be in the range from 0 to 6 inclusive. </p> <p> If there is more than one solution, your program may output any of them. If it is impossible to make the goal pattern, your program should output a single line containing “<span>-1</span>” (without quotes) instead of the <i>N</i> lines. </p> <p> A blank line should follow the output for every dataset (including the last one). </p> <H2>Sample Input</H2> <pre> 4 3 1 2 3 1 1 0 1 2 0 2 2 3 1 2 3 5 3 3 3 0 0 3 3 3 0 0 3 3 0 4 4 0 0 4 4 4 0 0 4 4 4 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 </pre>
p03634
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices.<br/> Here, a <em>tree</em> is a kind of graph, and more specifically, a connected undirected graph with <var>N-1</var> edges, where <var>N</var> is the number of its vertices.<br/> The <var>i</var>-th edge <var>(1≤i≤N-1)</var> connects Vertices <var>a_i</var> and <var>b_i</var>, and has a length of <var>c_i</var>.</p> <p>You are also given <var>Q</var> queries and an integer <var>K</var>. In the <var>j</var>-th query <var>(1≤j≤Q)</var>:</p> <ul> <li>find the length of the shortest path from Vertex <var>x_j</var> and Vertex <var>y_j</var> via Vertex <var>K</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3≤N≤10^5</var> </li> <li><var>1≤a_i,b_i≤N (1≤i≤N-1)</var> </li> <li><var>1≤c_i≤10^9 (1≤i≤N-1)</var> </li> <li>The given graph is a tree.</li> <li><var>1≤Q≤10^5</var> </li> <li><var>1≤K≤N</var> </li> <li><var>1≤x_j,y_j≤N (1≤j≤Q)</var> </li> <li><var>x_j≠y_j (1≤j≤Q)</var> </li> <li><var>x_j≠K,y_j≠K (1≤j≤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>a_1</var> <var>b_1</var> <var>c_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_{N-1}</var> <var>Q</var> <var>K</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_{Q}</var> <var>y_{Q}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the responses to the queries in <var>Q</var> lines.<br/> In the <var>j</var>-th line <var>j(1≤j≤Q)</var>, print the response to the <var>j</var>-th query.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 1 1 3 1 2 4 1 3 5 1 3 1 2 4 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 2 4 </pre> <p>The shortest paths for the three queries are as follows:</p> <ul> <li>Query <var>1</var>: Vertex <var>2</var> → Vertex <var>1</var> → Vertex <var>2</var> → Vertex <var>4</var> : Length <var>1+1+1=3</var> </li> <li>Query <var>2</var>: Vertex <var>2</var> → Vertex <var>1</var> → Vertex <var>3</var> : Length <var>1+1=2</var> </li> <li>Query <var>3</var>: Vertex <var>4</var> → Vertex <var>2</var> → Vertex <var>1</var> → Vertex <var>3</var> → Vertex <var>5</var> : Length <var>1+1+1+1=4</var> </li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 1 2 1 1 3 3 1 4 5 1 5 7 1 6 9 1 7 11 3 2 1 3 4 5 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 14 22 </pre> <p>The path for each query must pass Vertex <var>K=2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 5 6 1000000000 6 7 1000000000 7 8 1000000000 8 9 1000000000 9 10 1000000000 1 1 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>17000000000 </pre></section> </div> </span>
p01609
<h2>One</h2> <h2>Problem Statement</h2> <p>電車の窓から美しい山並みが見える.<br /> 窓は,左下隅の座標が <var>(0, 0)</var>,右上隅の座標が <var>(W, H)</var> の長方形である.<br /> 窓からは <var>N</var> つの山が見えており,<var>i</var> 番目の山は上に凸な放物線 <var>y = a_i (x-p_i)^2 + q_i</var> の形をしている.<br /> 山と空との境界線の長さを求めよ.</p> <p>次の三つの図は Sample Input に対応している.太線で示されている部分が山と空との境界線である.</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_I_sample1"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_I_sample2"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_I_sample3"> <h2>Input</h2> <p>入力は以下の形式に従う.与えられる数は全て整数である.</p> <pre><var>W</var> <var>H</var> <var>N</var> <var>a_1</var> <var>p_1</var> <var>q_1</var> <var>...</var> <var>a_N</var> <var>p_N</var> <var>q_N</var></pre> <h2>Constraints</h2> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1 ≦ W, H ≦ 100</var></li> <li><var>1 ≦ N ≦ 50</var></li> <li><var>-100 ≦ a_i ≦ -1</var></li> <li><var>0 ≦ p_i ≦ W</var></li> <li><var>1 ≦ q_i ≦ H</var></li> <li><var>i \neq j</var> ならば <var>(a_i, p_i, q_i) \neq (a_j, p_j, q_j)</var></li></ul> <h2>Output</h2> <p>山と空との境界線の長さを 1 行に出力せよ.<br /> 出力する値は,真の値との絶対誤差または相対誤差が <var>10^{-6}</var> 未満でなければならない.</p> <h2>Sample Input 1</h2> <pre>20 20 1 -1 10 10</pre> <h2>Output for the Sample Input 1</h2> <pre>21.520346288593280</pre> <h2>Sample Input 2</h2> <pre>20 20 2 -1 10 10 -2 10 5</pre> <h2>Output for the Sample Input 2</h2> <pre>21.520346288593280</pre> <h2>Sample Input 3</h2> <pre>15 100 2 -2 5 100 -2 10 100</pre> <h2>Output for the Sample Input 3</h2> <pre>126.921542730127873</pre>
p02926
<span class="lang-en"> <p>Score: <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>E869120 is initially standing at the origin <var>(0, 0)</var> in a two-dimensional plane.</p> <p>He has <var>N</var> engines, which can be used as follows:</p> <ul> <li>When E869120 uses the <var>i</var>-th engine, his <var>X</var>- and <var>Y</var>-coordinate change by <var>x_i</var> and <var>y_i</var>, respectively. In other words, if E869120 uses the <var>i</var>-th engine from coordinates <var>(X, Y)</var>, he will move to the coordinates <var>(X + x_i, Y + y_i)</var>.</li> <li>E869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines.</li> </ul> <p>He wants to go as far as possible from the origin. Let <var>(X, Y)</var> be his final coordinates. Find the maximum possible value of <var>\sqrt{X^2 + Y^2}</var>, the distance from the origin.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 100</var></li> <li><var>-1 \ 000 \ 000 \leq x_i \leq 1 \ 000 \ 000</var></li> <li><var>-1 \ 000 \ 000 \leq y_i \leq 1 \ 000 \ 000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the maximum possible final distance from the origin, as a real value. Your output is considered correct when the relative or absolute error from the true answer is at most <var>10^{-10}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 10 5 -5 -5 -5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10.000000000000000000000000000000000000000000000000 </pre> <p>The final distance from the origin can be <var>10</var> if we use the engines in one of the following three ways:</p> <ul> <li>Use Engine <var>1</var> to move to <var>(0, 10)</var>.</li> <li>Use Engine <var>2</var> to move to <var>(5, -5)</var>, and then use Engine <var>3</var> to move to <var>(0, -10)</var>.</li> <li>Use Engine <var>3</var> to move to <var>(-5, -5)</var>, and then use Engine <var>2</var> to move to <var>(0, -10)</var>.</li> </ul> <p>The distance cannot be greater than <var>10</var>, so the maximum possible distance is <var>10</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 1 1 0 0 1 -1 0 0 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2.828427124746190097603377448419396157139343750753 </pre> <p>The maximum possible final distance is <var>2 \sqrt{2} = 2.82842...</var>. One of the ways to achieve it is:</p> <ul> <li>Use Engine <var>1</var> to move to <var>(1, 1)</var>, and then use Engine <var>2</var> to move to <var>(2, 1)</var>, and finally use Engine <var>3</var> to move to <var>(2, 2)</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 1 2 2 3 3 4 4 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>21.213203435596425732025330863145471178545078130654 </pre> <p>If we use all the engines in the order <var>1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 5</var>, we will end up at <var>(15, 15)</var>, with the distance <var>15 \sqrt{2} = 21.2132...</var> from the origin.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 0 0 0 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1.414213562373095048801688724209698078569671875376 </pre> <p>There can be useless engines with <var>(x_i, y_i) = (0, 0)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>1 90447 91000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>128303.000000000000000000000000000000000000000000000000 </pre> <p>Note that there can be only one engine.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>2 96000 -72000 -72000 54000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>120000.000000000000000000000000000000000000000000000000 </pre> <p>There can be only two engines, too.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 7</h3><pre>10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 7</h3><pre>148.660687473185055226120082139313966514489855137208 </pre></section> </div> </span>
p03321
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In the State of Takahashi in AtCoderian Federation, there are <var>N</var> cities, numbered <var>1, 2, ..., N</var>. <var>M</var> bidirectional roads connect these cities. The <var>i</var>-th road connects City <var>A_i</var> and City <var>B_i</var>. Every road connects two distinct cities. Also, for any two cities, there is at most one road that <strong>directly</strong> connects them.</p> <p>One day, it was decided that the State of Takahashi would be divided into two states, Taka and Hashi. After the division, each city in Takahashi would belong to either Taka or Hashi. It is acceptable for all the cities to belong Taka, or for all the cities to belong Hashi. Here, the following condition should be satisfied:</p> <ul> <li>Any two cities in the same state, Taka or Hashi, are directly connected by a road.</li> </ul> <p>Find the minimum possible number of roads whose endpoint cities belong to the same state. If it is impossible to divide the cities into Taka and Hashi so that the condition is satisfied, print <code>-1</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 700</var></li> <li><var>0 \leq M \leq N(N-1)/2</var></li> <li><var>1 \leq A_i \leq N</var></li> <li><var>1 \leq B_i \leq N</var></li> <li><var>A_i \neq B_i</var></li> <li>If <var>i \neq j</var>, at least one of the following holds: <var>A_i \neq A_j</var> and <var>B_i \neq B_j</var>.</li> <li>If <var>i \neq j</var>, at least one of the following holds: <var>A_i \neq B_j</var> and <var>B_i \neq A_j</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>:</var> <var>A_M</var> <var>B_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 1 2 1 3 3 4 3 5 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>For example, if the cities <var>1, 2</var> belong to Taka and the cities <var>3, 4, 5</var> belong to Hashi, the condition is satisfied. Here, the number of roads whose endpoint cities belong to the same state, is <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>In this sample, the condition cannot be satisfied regardless of which cities belong to each state.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 3 1 2 1 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 39 7 2 7 1 5 6 5 8 9 10 2 8 8 7 3 10 10 1 8 10 2 3 7 4 3 9 4 10 3 4 6 1 6 7 9 5 9 7 6 9 9 4 4 6 7 5 8 3 2 5 9 2 10 7 8 6 8 9 7 3 5 3 4 5 6 3 2 10 5 10 4 2 6 2 8 4 10 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>21 </pre></section> </div> </span>
p03771
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> oases on a number line. The coordinate of the <var>i</var>-th oases from the left is <var>x_i</var>.</p> <p>Camel hopes to visit all these oases. Initially, the volume of the hump on his back is <var>V</var>. When the volume of the hump is <var>v</var>, water of volume at most <var>v</var> can be stored. Water is only supplied at oases. He can get as much water as he can store at a oasis, and the same oasis can be used any number of times.</p> <p>Camel can travel on the line by either walking or jumping:</p> <ul> <li>Walking over a distance of <var>d</var> costs water of volume <var>d</var> from the hump. A walk that leads to a negative amount of stored water cannot be done.</li> <li>Let <var>v</var> be the amount of water stored at the moment. When <var>v&gt;0</var>, Camel can jump to any point on the line of his choice. After this move, the volume of the hump becomes <var>v/2</var> (rounded down to the nearest integer), and the amount of stored water becomes <var>0</var>.</li> </ul> <p>For each of the oases, determine whether it is possible to start from that oasis and visit all the oases.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≤ N,V ≤ 2 × 10^5</var></li> <li><var>-10^9 ≤ x_1 &lt; x_2 &lt; ... &lt; x_N ≤ 10^9</var></li> <li><var>V</var> and <var>x_i</var> are all 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>V</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain <code>Possible</code> if it is possible to start from the <var>i</var>-th oasis and visit all the oases, and <code>Impossible</code> otherwise.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 3 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Possible Possible Possible </pre> <p>It is possible to start from the first oasis and visit all the oases, as follows:</p> <ul> <li>Walk from the first oasis to the second oasis. The amount of stored water becomes <var>0</var>.</li> <li>Get water at the second oasis. The amount of stored water becomes <var>2</var>.</li> <li>Jump from the second oasis to the third oasis. The amount of stored water becomes <var>0</var>, and the volume of the hump becomes <var>1</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 2 -10 -4 -2 0 2 4 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Impossible Possible Possible Possible Possible Possible Impossible </pre> <p>A oasis may be visited any number of times.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>16 19 -49 -48 -33 -30 -21 -14 0 15 19 23 44 52 80 81 82 84 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Possible Possible Possible Possible Possible Possible Possible Possible Possible Possible Possible Possible Impossible Impossible Impossible Impossible </pre></section> </div> </span>
p02863
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is at an all-you-can-eat restaurant.</p> <p>The restaurant offers <var>N</var> kinds of dishes. It takes <var>A_i</var> minutes to eat the <var>i</var>-th dish, whose deliciousness is <var>B_i</var>.</p> <p>The restaurant has the following rules:</p> <ul> <li>You can only order one dish at a time. The dish ordered will be immediately served and ready to eat.</li> <li>You cannot order the same kind of dish more than once.</li> <li>Until you finish eating the dish already served, you cannot order a new dish.</li> <li>After <var>T-0.5</var> minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served.</li> </ul> <p>Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant.</p> <p>What is the maximum possible happiness achieved by making optimal choices?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 3000</var></li> <li><var>1 \leq T \leq 3000</var></li> <li><var>1 \leq A_i \leq 3000</var></li> <li><var>1 \leq B_i \leq 3000</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>T</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 maximum possible happiness Takahashi can achieve.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 60 10 10 100 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>110 </pre> <p>By ordering the first and second dishes in this order, Takahashi's happiness will be <var>110</var>.</p> <p>Note that, if we manage to order a dish in time, we can spend any amount of time to eat it.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 60 10 10 10 20 10 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>60 </pre> <p>Takahashi can eat all the dishes within <var>60</var> minutes.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 60 30 10 30 20 30 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>50 </pre> <p>By ordering the second and third dishes in this order, Takahashi's happiness will be <var>50</var>.</p> <p>We cannot order three dishes, in whatever order we place them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 100 15 23 20 18 13 17 24 12 18 29 19 27 23 21 18 20 27 15 22 25 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>145 </pre></section> </div> </span>
p02160
<h1>Problem L: Product</h1> <h2>Problem</h2> <p>会津君は、素数$P$、自然数からなる集合$G$、自然数$A$を使ってゲームをすることにしました。</p> <p>まず、会津君は手元の紙に$1$を書きます。その後、以下の一連の操作を任意の回数行います。</p> <ul> <li>$G$から要素を一つ選ぶ。これを$g$とする。</li> <li>手元の紙に書かれた数と$g$との積を新しく紙に書く。</li> <li>元々紙に書かれていた数を消す。</li> </ul> <p>手元の紙に書かれた数を$P$で割ったあまりと$A$が等しければ会津君の勝ちで、そうでなければ負けです。$P$、$G$、$A$が与えられたときに会津君が勝つことができるか判定してください。</p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $P$ $T$ $Test_1$ $\vdots$ $Test_{T}$ </pre> <p>入力は複数のテストケースからなる。まず$1$行に素数$P$とテストケースの数$T$が与えられる。$P$は全てのテストケースで共通である。続く$T$行に各テストケースが与えられる。</p> <p>各テストケースは以下のように与えられる。</p> <pre> $|G|$ $G_1$ $\dots$ $G_{|G|}$ $A$ </pre> <p>各テストケースでは、$G$の要素数、$G$の各要素、$A$が順番に空白で区切られて与えられる。</p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>入力はすべては整数である。</li> <li>$2 \le P \le 2^{31}-1$</li> <li>$1 \le T,|G| \le 10^5$</li> <li>$1 \le G_i,A \le P-1$</li> <li>$G_i \ne G_j,$ if $i \ne j$</li> <li>全てのテストケースの$|G|$の総和は$10^5$を超えない。</li> </ul> <h2>Output</h2> <p>各テストケースに対して、会津君が勝つことができるならば$1$を、そうでなければ$0$を一行に出力する。</p> <h2>Sample Input 1</h2> <pre> 7 3 1 1 2 1 2 1 3 1 2 4 5 </pre> <h2>Sample Output 1</h2> <pre> 0 1 0 </pre> <h2>Sample Input 2</h2> <pre> 1000000007 8 3 2 9 7 5 3 2 9 5 1000001 3 39 1002 65537 12 2 1000000006 518012930 793649232 10 459268180 313723762 835892239 612038995 90424474 366392946 38051435 854115735 5132833 320534710 421820264 1 1 1 1 1 1000000006 1 1000000006 1 </pre> <h2>Sample Output 2</h2> <pre> 0 1 1 1 0 1 0 1 </pre>
p01465
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Testing Circuits</H1> <p> A Boolean expression is given. In the expression, each variable appears exactly once. Calculate the number of variable assignments that make the expression evaluate to true. </p> <H2>Input</H2> <p> A data set consists of only one line. The Boolean expression is given by a string which consists of digits, x, (, ), |, &amp;, and ~. Other characters such as spaces are not contained. The expression never exceeds 1,000,000 characters. The grammar of the expressions is given by the following BNF. </p> <pre> &lt;expression&gt; ::= &lt;term&gt; | &lt;expression&gt; &quot;|&quot; &lt;term&gt; &lt;term&gt; ::= &lt;factor&gt; | &lt;term&gt; &quot;&amp;&quot; &lt;factor&gt; &lt;factor&gt; ::= &lt;variable&gt; | &quot;~&quot; &lt;factor&gt; | &quot;(&quot; &lt;expression&gt; &quot;)&quot; &lt;variable&gt; ::= &quot;x&quot; &lt;number&gt; &lt;number&gt; ::= &quot;1&quot; | &quot;2&quot; |... | &quot;999999&quot; | &quot;1000000&quot; </pre> <p> The expression obeys this syntax and thus you do not have to care about grammatical errors. When the expression contains N variables, each variable in {x1, x2,..., xN} appears exactly once. </p> <H2>Output</H2> <p> Output a line containing the number of variable assignments that make the expression evaluate to true in modulo 1,000,000,007. </p> <H2>Sample Input 1</H2> <pre> (x1&amp;x2) </pre> <H2>Output for the Sample Input 1</H2> <pre> 1 </pre> <H2>Sample Input 2</H2> <pre> (x1&amp;x2)|(x3&amp;x4)|(~(x5|x6)&amp;(x7&amp;x8)) </pre> <H2>Output for the Sample Input 2</H2> <pre> 121 </pre>
p03458
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer is thinking of painting an infinite two-dimensional grid in a <em>checked pattern of side <var>K</var></em>. Here, a checked pattern of side <var>K</var> is a pattern where each square is painted black or white so that each connected component of each color is a <var>K</var> <var>×</var> <var>K</var> square. Below is an example of a checked pattern of side <var>3</var>:</p> <div style="text-align: center;"> <img alt="cba927b2484fad94fb5ff7473e9aadef.png" src="https://img.atcoder.jp/arc089/cba927b2484fad94fb5ff7473e9aadef.png"> </img></div> <p>AtCoDeer has <var>N</var> desires. The <var>i</var>-th desire is represented by <var>x_i</var>, <var>y_i</var> and <var>c_i</var>. If <var>c_i</var> is <code>B</code>, it means that he wants to paint the square <var>(x_i,y_i)</var> black; if <var>c_i</var> is <code>W</code>, he wants to paint the square <var>(x_i,y_i)</var> white. At most how many desires can he satisfy at the same time?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≤</var> <var>N</var> <var>≤</var> <var>10^5</var></li> <li><var>1</var> <var>≤</var> <var>K</var> <var>≤</var> <var>1000</var></li> <li><var>0</var> <var>≤</var> <var>x_i</var> <var>≤</var> <var>10^9</var></li> <li><var>0</var> <var>≤</var> <var>y_i</var> <var>≤</var> <var>10^9</var></li> <li>If <var>i</var> <var>≠</var> <var>j</var>, then <var>(x_i,y_i)</var> <var>≠</var> <var>(x_j,y_j)</var>.</li> <li><var>c_i</var> is <code>B</code> or <code>W</code>.</li> <li><var>N</var>, <var>K</var>, <var>x_i</var> and <var>y_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>x_1</var> <var>y_1</var> <var>c_1</var> <var>x_2</var> <var>y_2</var> <var>c_2</var> <var>:</var> <var>x_N</var> <var>y_N</var> <var>c_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of desires that can be satisfied at the same time.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 0 1 W 1 2 W 5 3 B 5 4 B </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>He can satisfy all his desires by painting as shown in the example above.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1000 0 0 B 0 1 W </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 2 1 2 B 2 1 W 2 2 B 1 0 B 0 6 W 4 5 W </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p01035
<h1>Problem I: Hard Beans</h1> <h2>Problem</h2> <p> 大津大学では豆が盛んです。 <var>N</var>個の豆が一直線上に並んでいます。 それぞれ0から順に<var>N</var>&minus;1まで番号がふられており、<var>i</var>番目の豆の硬さを<var>a<sub>i</sub></var>とします。 </p> <p> シアン君は理想の豆の硬さを<var>D</var>だと考えています。しかし、シアン君は面倒くさがりなのであまり遠くにある豆を取りに行きたくありません。したがって、シアン君は<var>l</var>番目の豆から<var>r</var>番目の豆の中で硬さが<var>D</var>に最も近い豆を知りたいと思っています。 </p> <p> シアン君は<var>Q</var>個の質問をしてくるので、それぞれの質問に対し閉区間[<var>l</var>,<var>r</var>]番目にある | <var>豆の硬さ</var> &minus; <var>D</var> | の最小値を求めるプログラムを作成してください。(ただし、| <var>a</var> | は <var>a</var>の絶対値を表します。) </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>a<sub>0</sub></var> <var>a<sub>1</sub></var> ... <var>a<sub>N&minus;1</sub></var> <var>Q</var> <var>l<sub>0</sub></var> <var>r<sub>0</sub></var> <var>D<sub>0</sub></var> <var>l<sub>1</sub></var> <var>r<sub>1</sub></var> <var>D<sub>1</sub></var> . . . <var>l<sub>Q&minus;1</sub></var> <var>r<sub>Q&minus;1</sub></var> <var>D<sub>Q&minus;1</sub></var> </pre> <p> 1行目に、1つの整数<var>N</var>が与えられる。2行目に、<var>N</var>つの整数が空白区切りで与えられる。3行目に、クエリの数が1つの整数<var>Q</var>として与えられる。続く4行から3+<var>Q</var>行までにクエリの値<var>l</var>,<var>r</var>,<var>D</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>6</sup> (0 &le; <var>i</var> &le; <var>N</var>&minus;1)</li> <li>1 &le; <var>Q</var> &le; 10<sup>5</sup></li> <li>0 &le; <var>D<sub>i</sub></var> &le; 10<sup>6</sup></li> <li>0 &le; <var>l<sub>i</sub></var> &le; <var>r<sub>i</sub></var> &le; <var>N</var>&minus;1</li> </ul> <h2>Output</h2> <p> 各クエリに対し、<var>D</var>と[<var>l</var>,<var>r</var>]番目の豆の中で硬さ<var>D</var>に最も近い豆の硬さとの差の絶対値を1行に出力せよ。 </p> <h2>Sample Input1</h2> <pre> 3 1 2 3 3 0 2 2 0 2 4 0 0 2 </pre> <h2>Sample Output1</h2> <pre> 0 1 1 </pre> <h2>Sample Input2</h2> <pre> 10 4 5 0 21 9 100 12 9 0 8 5 0 3 20 2 5 100 8 9 9 5 5 10 0 9 20 </pre> <h2>Sample Output2</h2> <pre> 1 0 1 90 1 </pre>
p03008
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The squirrel Chokudai has <var>N</var> acorns. One day, he decides to do some trades in multiple precious metal exchanges to make more acorns.</p> <p>His plan is as follows:</p> <ol> <li>Get out of the nest with <var>N</var> acorns in his hands.</li> <li>Go to Exchange <var>A</var> and do some trades.</li> <li>Go to Exchange <var>B</var> and do some trades.</li> <li>Go to Exchange <var>A</var> and do some trades.</li> <li>Go back to the nest.</li> </ol> <p>In Exchange <var>X</var> <var>(X = A, B)</var>, he can perform the following operations any integer number of times (possibly zero) in any order:</p> <ul> <li>Lose <var>g_{X}</var> acorns and gain <var>1</var> gram of gold.</li> <li>Gain <var>g_{X}</var> acorns and lose <var>1</var> gram of gold.</li> <li>Lose <var>s_{X}</var> acorns and gain <var>1</var> gram of silver.</li> <li>Gain <var>s_{X}</var> acorns and lose <var>1</var> gram of silver.</li> <li>Lose <var>b_{X}</var> acorns and gain <var>1</var> gram of bronze.</li> <li>Gain <var>b_{X}</var> acorns and lose <var>1</var> gram of bronze.</li> </ul> <p>Naturally, he cannot perform an operation that would leave him with a negative amount of acorns, gold, silver, or bronze.</p> <p>What is the maximum number of acorns that he can bring to the nest? Note that gold, silver, or bronze brought to the nest would be worthless because he is just a squirrel.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 5000</var></li> <li><var>1 \leq g_{X} \leq 5000</var></li> <li><var>1 \leq s_{X} \leq 5000</var></li> <li><var>1 \leq b_{X} \leq 5000</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>g_A</var> <var>s_A</var> <var>b_A</var> <var>g_B</var> <var>s_B</var> <var>b_B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of acorns that Chokudai can bring to the nest.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>23 1 1 1 2 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>46 </pre> <p>He can bring <var>46</var> acorns to the nest, as follows:</p> <ul> <li>In Exchange <var>A</var>, trade <var>23</var> acorns for <var>23</var> grams of gold. {acorns, gold, silver, bronze}={ <var>0,23,0,0</var> }</li> <li>In Exchange <var>B</var>, trade <var>23</var> grams of gold for <var>46</var> acorns. {acorns, gold, silver, bronze}={ <var>46,0,0,0</var> }</li> <li>In Exchange <var>A</var>, trade nothing. {acorns, gold, silver, bronze}={ <var>46,0,0,0</var> }</li> </ul> <p>He cannot have <var>47</var> or more acorns, so the answer is <var>46</var>.</p></section> </div> </span>
p02249
<H1>Pattern Search</H1> <p> Find places where a <var>R</var> &times <var>C</var> pattern is found within a <var>H</var> &times; <var>W</var> region. Print top-left coordinates (<var>i</var>, <var>j</var>) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and (<var>H</var>-1, <var>W</var>-1) respectively. </p> <H2>Input</H2> <p> In the first line, two integers <var>H</var> and <var>W</var> are given. In the following <var>H</var> lines, <var>i</var>-th lines of the region are given. </p> <p> In the next line, two integers <var>R</var> and <var>C</var> are given. In the following <var>R</var> lines, <var>i</var>-th lines of the pattern are given. </p> <H2>output</H2> <p> For each sub-region found, print a coordinate <var>i</var> and <var>j</var> separated by a space character in a line. Print the coordinates in ascending order of the row numbers (<var>i</var>), or the column numbers (<var>j</var>) in case of a tie. </p> <H2>Constraints</H2> <ul> <li> 1 &le; <var>H, W</var> &le; 1000 </li> <li> 1 &le; <var>R, C</var> &le; 1000 </li> <li>The input consists of alphabetical characters and digits</li> </ul> <H2>Sample Input 1</H2> <pre> 4 5 00010 00101 00010 00100 3 2 10 01 10 </pre> <H2>Sample Output 1</H2> <pre> 0 3 1 2 </pre>
p00274
<H1>おそろいの景品</H1> <p> ジョウ君とヤエさんは仲の良いカップルです。ジョウ君はカプセル玩具自販機(ガチャポン)の景品を集めており、二人で出かけたときも、ガチャポンを見つけると何度かやってみるほどの熱の入りようです。ヤエさんは楽しそうなジョウ君をそばで見ているだけでしたが、ジョウ君の今度の誕生日プレゼントにガチャポンの景品をひとつあげることにしました。ヤエさんはガチャポン自体にはあまり興味がわきませんでしたが、できればジョウ君とおそろいの景品が欲しいと思っています。 </p> <p> ヤエさんがやってみようと思うガチャポンは、1回のチャレンジで景品がひとつ出ます。品切れのものも含め景品が何種類あるのかと、それぞれの景品がいくつ残っているのかはわかります。しかし、1回のチャレンジでどの景品が出るかはわかりません。そこで、景品が出る順番にかかわらず、ヤエさんが同じ景品を必ず2つ得るために最低限必要なチャレンジの回数を出力するプログラムを作成してください。 </p> <h2>入力</h2> <p> 入力は複数のデータセットからなる。入力の終わりはゼロ1つの行で示される。各データセットは以下の形式で与えられる。 </p> <pre> <var>N</var> <var>k<sub>1</sub></var> <var>k<sub>2</sub></var> ... <var>k<sub>N</sub></var> </pre> <p> 各データセットは2行であり、1行目に景品が何種類あるかを表す整数<var>N</var>(1 &le; <var>N</var> &le; 10000)が与えられる。続く1行に各景品がいくつ残っているのかを表す整数<var>k<sub>i</sub></var>(0 &le; <var>k<sub>i</sub></var> &le; 10000)が与えられる。 </p> <p> データセットの数は100を超えない。 </p> <h2>出力</h2> <p> データセットごとに、同じ景品を必ず2つ得るために最低限必要なチャレンジの回数を出力する。ただし、不可能な場合はNAと出力する。 </p> <h2>入力例</h2> <pre> 2 3 2 3 0 1 1 1 1000 0 </pre> <h2>出力例</h2> <pre> 3 NA 2 </pre> <p> 1つ目のデータセットでは、運良く1種類目か2種類目の景品が連続で出て2回で済む可能性はあるが、同じ種類の景品を必ず2つ得るためには3回チャレンジする必要がある。</br> 2つ目のデータセットでは、2つ以上残っている景品がもともと無いので不可能である。</br> 3つ目のデータセットでは、景品は1種類だけなので2回のチャレンジでその景品が必ず2つ得られる。</br> </p>
p01936
<!-- - - - - - begin nicebody - - - - - --> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>F: Steps</h1> <h2>問題</h2> <p> AORイカちゃんは株式会社AORの視察に訪れた。 株式会社AORは $N$ 階建てのビルであり、地下階は存在しない。 AORイカちゃんは $1$ 階から視察を開始し、ちょうど $M$ 回移動することにした。 $1$ 回の移動で $i$ 階から $i + 1$ 階、あるいは $i - 1$ 階に移動することができる。 ただし、 移動先が $0$ 階や $N + 1$ 階となるように移動することはできない。 </p> <p> AORイカちゃんが全ての階に一度以上訪れる移動方法の通り数を $1000000007 (= 10^9 + 7)$ で割った余りを求めよ。 なお、 $1$ 階にはすでに訪れたものとする。 </p> <h2>制約</h2> <ul> <li>$2 \leq N \leq 10^5$</li> <li>$1 \leq M \leq 10^5$</li> <li>入力は全て整数で与えらえる。</li> </ul> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる。 </p> <p> $N \ M$<br> </p> <h2>出力</h2> <p> 移動方法の通り数を $1000000007 (= 10 ^ 9 + 7)$ で割った余りを出力せよ。また、末尾に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 3 5 </pre> <h3>サンプル出力 1</h3> <pre> 3 </pre> <h3>サンプル入力 2</h3> <pre> 3 1 </pre> <h3>サンプル出力 2</h3> <pre> 0 </pre> <h3>サンプル入力 3</h3> <pre> 4883 5989 </pre> <h3>サンプル出力 3</h3> <pre> 956662807 </pre> <!-- - - - - - end nicebody - - - - - -->
p02619
<span class="lang-en"> <p>(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.)</p> <div class="part"> <section> <h3>Beginner's Guide</h3><p>Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.</p> </section> </div> <div class="part"> <section> <h3>Problem Statement</h3><p>You will be given a contest schedule for <var>D</var> days. For each <var>d=1,2,\ldots,D</var>, calculate the satisfaction at the end of day <var>d</var>.</p> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A.</p> <pre><var>D</var> <var>c_1</var> <var>c_2</var> <var>\cdots</var> <var>c_{26}</var> <var>s_{1,1}</var> <var>s_{1,2}</var> <var>\cdots</var> <var>s_{1,26}</var> <var>\vdots</var> <var>s_{D,1}</var> <var>s_{D,2}</var> <var>\cdots</var> <var>s_{D,26}</var> <var>t_1</var> <var>t_2</var> <var>\vdots</var> <var>t_D</var> </pre> <ul> <li>The constraints and generation methods for the input part are the same as those for Problem A.</li> <li>For each <var>d</var>, <var>t_d</var> is an integer satisfying <var>1\leq t_d \leq 26</var>, and your program is expected to work correctly for any value that meets the constraints.</li> </ul> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Let <var>v_d</var> be the satisfaction at the end of day <var>d</var>. Print <var>D</var> integers <var>v_d</var> to Standard Output in the following format:</p> <pre><var>v_1</var> <var>v_2</var> <var>\vdots</var> <var>v_D</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>18398 35037 51140 65837 79325 </pre> <p>Note that this example is a small one for checking the problem specification. It does not satisfy the constraint <var>D=365</var> and is never actually given as a test case.</p> </section> </div> <div class="part"> <section> <h3>Next Step</h3><p>We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each <var>d=1,2,\ldots,D</var>, we select the contest type that maximizes the satisfaction at the end of day <var>d</var>. You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented!</p> <p>Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs. We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods. For more information, please refer to the editorial that will be published after the contest.</p></section> </div> </span>
p00624
<H1><font color="#000000">Problem D:</font> Dr. Nakamura's Lab.</H1> <p> Dr.中村は偉大な発明者である, 今日も常人には発想出来ない新たな発明に取り掛かっている. 今発明しているのは新たな防犯システムとコンテナである. </p> <p> 防犯システムの方は上に乗った者を識別して招かれざる客だった場合, 電流を流して気絶させるパネルである. このパネルは踏まないように上を通過しても無駄で, 空中のものに対し放電する. しかし, まだ完成には程遠く, 電流は強すぎて調節が不可能で, 一度放電すると充電しない限り使えない. また, 人と物体の区別ができず, そもそも人自体区別できない等欠点をあげればキリがない. </p> <p> コンテナの方は謎の力によって常時地面から浮いており, 運ぶのに便利に作ってある. しかし, これも完成には遠く, 一度押すと何かにぶつかるまで止まらない. </p> <p> Dr.中村は一日の作業を終え, 帰宅しようとしたが未完成のパネルを設置したままだということに気づいた. これを取り外すのは防犯上非常に困難に作ってある上に, これを通らなければ帰れないような位置に設置してしまったのでDr.中村は途方に暮れた. しかし, 素晴らしい頭脳を持つDr.中村は解決案をすぐに思いついた. パネルは一度放電させれば通れるようになるため, コンテナを通過させればパネルの上を通れるようになる, そう考えた. 実際, パネルの上にコンテナを通過させると, コンテナは電流によって消滅してしまう一方でパネルは放電し, 通れるようになる. </p> <p> しかし, 研究室の中は入り組んでおり, うまくコンテナを動かさないとパネルを通過させられない. Dr.中村は助手であるあなたにメールで助けを求めた. あなたの仕事は研究室の情報が与えられた時にDr.中村が出口までたどり着くためのプログラムを作成することである. </p> <p> 研究室は二次元グリッドで与えられ, Dr.中村は一度の移動で上下左右に隣接するセルに移動することが出来る.ただし, 障害物, コンテナ, 放電していないパネルのセルには移動できない. </p> <p> Dr.中村は上下左右に隣接するセルにあるコンテナを押すことができ, コンテナはDr.中村がいる方向と逆の方向に別のコンテナか障害物にぶつかる, あるいは放電されていないパネルの上を通過するまで動く. また, 何かにぶつかり止まった場合, ぶつかる直前のセルで静止する. </p> <p> 出口はコンテナもDr.中村も侵入可能である. コンテナは出口を通っても消滅せず、そのまま通過する. </P> <p> 壁にぶつかって出口をふさぐことはある. この場合は出口に進入できない. </P> <p> あなたのプログラムが要求されていることは, Dr.中村は最少何回の移動で研究室を脱出できるかを出力することのみである. なぜなら, Dr.中村は素晴らしい頭脳の持ち主なのでそれさえわかれば自分で脱出するからである. </p> <H2>Input</H2> <p> 入力は複数のデータセットからなり, 一行目に研究室の縦の長さ H と横の長さ W が与えられる. 2行目以降では研究室の状態が H &times; W 個の文字で表わされる. 各文字が表すものは以下のとおりである: </p> <ul> <li>‘<span>#</span>’障害物を表す.</li> <li>‘<span>@</span>’Dr.中村の初期位置を表す.</li> <li>‘<span>w</span>’パネルを表す.</li> <li>‘<span>c</span>’コンテナを表す.</li> <li>‘<span>.</span>’何も置かれていない空白のセルを表す.</li> <li>‘<span>E</span>’脱出口を表す.</li> </ul> <p> 縦と横の長さがともに 0 のとき入力の終了を表す. これについて処理をする必要はない. </p> <p> 以下のことを仮定してよい. </p> <ul> <li>3 &le; H, W &le; 10</li> <li>研究室の周囲は障害物で囲まれている.</li> <li>パネルとコンテナの数はそれぞれ 3 を越えない.</li> <li>研究室にはただ1つの出口がある.</li> </ul> <H2>Output</H2> <p> 各データセットについて最少の移動回数を1行に出力せよ. なお、Dr.中村が脱出できない場合、”<span>-1</span>”と出力せよ. </p> <H2>Sample Input</H2> <pre> 5 5 ##### ##@## #wc.# #Ew.# ##### 5 5 ##### ##@.# #wc.# #E#.# ##### 3 6 ###### #@.wE# ###### 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 5 -1 </pre>
p00331
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>日の出と日の入り </H1> <p> 太陽が現れることを「日の出」、隠れることを「日の入り」と呼びますが、その厳密な時刻は太陽が地平線に対してどのような位置にある時でしょうか。 </p> <p> 下の図のように、太陽を円、地平線を直線で表すことにします。このとき、太陽の「日の出」「日の入り」の時刻は、太陽を表す円の上端が地平線を表す直線と一致する瞬間とされています。日の出の時刻を過ぎ、円の上端が直線より上にある時間帯が昼間、円が直線の下へ完全に隠れている時間帯が夜間となります。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_1" width="640"> </center><br/> <p> ある時刻の地平線から太陽の中心までの高さと、太陽の半径を入力とし、その時刻が「昼間」か、「日の出または日の入り」か、「夜間」かを出力するプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>H</var> <var>R</var> </pre> <p> 入力は1行からなり、ある時刻の地平線から太陽の中心までの高さを表す整数 <var>H</var> (-1000 &le; <var>H</var> &le; 1000) と半径を表す整数 <var>R</var> (1 &le; <var>R</var> &le; 1000) が与えられる。ただし、<var>H</var> は太陽の中心が地平線上にあるときを 0 として、それより上にあるときは正、下にあるときは負とする。 </p> <h2>Output</h2> <p> 昼間のとき「1」、日の出または日の入りのとき「0」、夜間のとき「-1」を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> -3 3 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_2" width="240"></center> <br/> <h2>Sample Input 2</h2> <pre> 3 3 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_3" width="240"></center> <br/> <h2>Sample Input 3</h2> <pre> -4 3 </pre> <h2>Sample Output 3</h2> <pre> -1 </pre> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sunset_4" width="240"></center>
p01873
<h2>B: 周期数列 - Periodic Sequence -</h2> <h3>問題</h3> <p>H大学の教授を務めているPeriod博士は、万物に潜むとされる周期と呼ばれる性質を研究している。一般的に知られている基本的な周期としては、数列に潜む周期が考えられるだろう。すなわち、長さ<var>N</var>の数列<var>S = S_1, S_2,</var> ... <var>, S_N</var>が以下の性質を満たすならば、周期<var>t</var> (<var>t \&le; N</var>) を持つという事実である。</p> <p><var>1 \&le; i \&le; N &minus; t</var>について、<var>S_i=S_{i+t}</var>である。</p> <p>今、Period博士が着目しているのは、周期を用いてより簡易な記述ができる数列である。例えば、長さ<var>N</var>の数列が周期<var>t</var> (<var>\&le; N</var>) を持つとき、ある整数<var>k</var>を用いて<var>N=kt</var>と書けるならば、その数列は長さ<var>t</var>の数列<var>S_1,</var> ... <var>, S_t</var>が<var>k</var>個連続したものである、と記述できる。Period博士は数列を例のように記述できたとき、その数列は<var>k</var>-partであると言うことにした。</p> <p>Period博士は、<var>k</var>が最も大きい<var>k</var>-partに興味を示している。そこで助手であるあなたは、入力として数列を受け取り、それが<var>k</var>-partであるとき最も大きい<var>k</var>を出力するプログラムの作成を任されることとなった。Period博士の要求に正確に応えるプログラムを作成しよう。</p> <h3>入力形式</h3> <pre> <var>N</var> <var>S_1</var> ... <var>S_N</var> </pre> <p>1行目には、数列の長さを表す整数<var>N</var>が与えられる。2行目には、長さ<var>N</var>の数列の各要素を表す整数<var>S_i</var> (<var>1 \&le; i \&le; N</var>) が空白区切りで与えられる。また、入力は<var>1 \&le; N \&le; 200,000</var>と<var>1 \&le; S_i \&le; 100,000</var> (<var>1 \&le; i \&le; N</var>) を満たす。</p> <h3>出力形式</h3> <p>与えられた数列に対して、<var>k</var>-partであるときの<var>k</var>の最大値を1行に出力せよ。</p> <h3>入力例1</h3> <pre> 6 1 2 3 1 2 3 </pre> <h3>出力例1</h3> <pre>2</pre> <h3>入力例2</h3> <pre> 12 1 2 1 2 1 2 1 2 1 2 1 2 </pre> <h3>出力例2</h3> <pre>6</pre> <h3>入力例3</h3> <pre> 6 1 2 3 4 5 6 </pre> <h3>出力例3</h3> <pre>1</pre>
p00761
<h1>Recurring Decimals</h1> <!-- end en only --> <!-- begin en only --> <p> A decimal representation of an integer can be transformed to another integer by rearranging the order of digits. Let us make a sequence using this fact. </p> <p> A non-negative integer <i>a</i><sub>0</sub> and the number of digits <i>L</i> are given first. Applying the following rules, we obtain <i>a</i><sub><i>i</i>+1</sub> from <i>a</i><sub><i>i</i></sub>. <ol> <li> Express the integer <i>a</i><sub><i>i</i></sub> in decimal notation with <i>L</i> digits. Leading zeros are added if necessary. For example, the decimal notation with six digits of the number 2012 is 002012. </li> <li> Rearranging the digits, find the largest possible integer and the smallest possible integer; In the example above, the largest possible integer is 221000 and the smallest is 000122 = 122. </li> <li> A new integer <i>a</i><sub><i>i</i>+1</sub> is obtained by subtracting the smallest possible integer from the largest. In the example above, we obtain 220878 subtracting 122 from 221000. </li> </ol> </p> <p> When you repeat this calculation, you will get a sequence of integers <i>a</i><sub>0</sub> , <i>a</i><sub>1</sub> , <i>a</i><sub>2</sub> , ... . </p> <p> For example, starting with the integer 83268 and with the number of digits 6, you will get the following sequence of integers <i>a</i><sub>0</sub> , <i>a</i><sub>1</sub> , <i>a</i><sub>2</sub> , ... . </p> <!-- end en only --> <blockquote> <i>a</i><sub>0</sub> = 083268<br> <i>a</i><sub>1</sub> = 886320 &minus; 023688 = 862632<br> <i>a</i><sub>2</sub> = 866322 &minus; 223668 = 642654<br> <i>a</i><sub>3</sub> = 665442 &minus; 244566 = 420876<br> <i>a</i><sub>4</sub> = 876420 &minus; 024678 = 851742<br> <i>a</i><sub>5</sub> = 875421 &minus; 124578 = 750843<br> <i>a</i><sub>6</sub> = 875430 &minus; 034578 = 840852<br> <i>a</i><sub>7</sub> = 885420 &minus; 024588 = 860832<br> <i>a</i><sub>8</sub> = 886320 &minus; 023688 = 862632<br> &nbsp;&nbsp;&nbsp;&hellip;<br> </blockquote> <!-- begin en only --> <p> Because the number of digits to express integers is fixed, you will encounter occurrences of the same integer in the sequence <i>a</i><sub>0</sub> , <i>a</i><sub>1</sub> , <i>a</i><sub>2</sub> , ... eventually. Therefore you can always find a pair of <i>i</i>&nbsp; and <i>j</i>&nbsp; that satisfies the condition <i>a</i><sub><i>i</i></sub> = <i>a</i><sub><i>j</i></sub> &nbsp; (<i>i</i>&nbsp; &gt; <i>j</i>&nbsp; ). In the example above, the pair (<i>i</i>&nbsp;= 8, <i>j</i>&nbsp;= 1) satisfies the condition because <i>a</i><sub>8</sub> = <i>a</i><sub>1</sub> = 862632. </p> <p> Write a program that, given an initial integer <i>a</i><sub>0</sub> and a number of digits <i>L</i>, finds the smallest <i>i</i> that satisfies the condition <i>a</i><sub><i>i</i></sub> = <i>a</i><sub><i>j</i></sub> &nbsp; (<i>i</i>&nbsp; &gt; <i>j</i>&nbsp; ). </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of multiple datasets. A dataset is a line containing two integers <i>a</i><sub>0</sub>&nbsp; and <i>L</i>&nbsp; separated by a space. <i>a</i><sub>0</sub>&nbsp; and <i>L</i>&nbsp; represent the initial integer of the sequence and the number of digits, respectively, where 1 &le; <i>L</i>&nbsp; &le; 6 and 0 &le; <i>a</i><sub>0</sub>&nbsp; &lt; 10<sup><i>L</i></sup> . </p> <p> The end of the input is indicated by a line containing two zeros; it is not a dataset. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, find the smallest number <i>i</i>&nbsp; that satisfies the condition <i>a</i><sub><i>i</i></sub> = <i>a</i><sub><i>j</i></sub> &nbsp; (<i>i</i>&nbsp; &gt; <i>j</i>&nbsp; ) and print a line containing three integers, <i>j</i>&nbsp;, <i>a</i><sub><i>i</i></sub> &nbsp; and <i>i</i>&nbsp; &minus; <i>j</i>. Numbers should be separated by a space. Leading zeros should be suppressed. Output lines should not contain extra characters. </p> <p> You can assume that the above <i>i</i>&nbsp; is not greater than 20. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 2012 4 83268 6 1112 4 0 1 99 2 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 3 6174 1 1 862632 7 5 6174 1 0 0 1 1 0 1 </pre>
p01520
<h1>A - アルデンテ</h1> <h2>問題文</h2> <p> わたしは近所のスーパーで初めてスパゲッティというものを購入した.パッケージの情報によると,このスパゲッティは <var>T</var> 秒茹でると最も理想的な状態に茹で上がるらしい. </p> <p> ところでわたしは電気が嫌いな人間であり,家にはテレビやパソコンはおろか,時計さえ無い. そのためスパゲッティを茹でようにも,時間を測ることができない. 電池式の時計は嫌なので,わたしは代わりに砂時計を買おうと考え,スーパーの砂時計売り場へと向かった. 売り場には <var>N</var> 個の砂時計があった.<var>i</var> 番目の砂時計はちょうど <var>x<sub>i</sub></var> 秒だけ測ることができるようであった. いろいろあって悩ましいが,スパゲッティのために砂時計を何個も買うのは馬鹿らしいのでこの中からちょうど 1 個だけ買おうと思う. </p> <p> しかし皆さんご存知の通り,砂時計というのは一度測り始めると,それから測り終えるまでは途中の時刻というのはまったく分からない. そのため,もし私が <var>i</var> 番目の砂時計を買って使ったとすると,時計を連続して使うことで <var>x<sub>i</sub></var> 秒,<var>2x<sub>i</sub></var> 秒,<var>3x<sub>i</sub></var> 秒,... という時間を測ることができるが,逆にそれ以外の時間は測ることができない. </p> <p> 理想的な茹で上がりに必要な時間は <var>T</var> 秒らしいが,ここでは妥協して <var>E (&lt; T)</var> 秒以内の誤差を許そう. すなわち,どれか 1 つの砂時計を用いて,<var>T&minus;E</var> 秒,<var>T&minus;E+1</var> 秒,<var>T&minus;E+2</var> 秒,... ,<var>T+E&minus;2</var> 秒,<var>T+E&minus;1</var> 秒,<var>T+E</var> 秒のうちのどれかの時間を計測したい. 私は何番目の砂時計を購入して使えばよいだろうか? </p> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる. <pre> <var>N</var> <var>T</var> <var>E</var> <var>x<sub>1</sub></var> ... <var>x<sub>N</sub></var> </pre> <p> <var>N</var> は砂時計の個数である.<var>T</var> はスパゲッティを理想的に茹で上げるのに必要な時間(秒),<var>E</var> は茹で上げに許容する誤差の時間(秒)である. <var>x<sub>i</sub></var> は <var>i</var> 番目の砂時計が 1 回で測ることできるの時間(秒)である. </p> <h2>出力形式</h2> <p>何番目の砂時計を使えばよいか出力せよ.そのような砂時計が複数個ある場合,それらの中からどれか 1 つを出力せよ. どの砂時計を使っても時間が測れない場合は <code>-1</code> を出力せよ. </p> <h2>制約</h2> <ul> <li><var>1 &le; N &le; 100</var></li> <li><var>1 &le; T &le; 1,440</var></li> <li><var>0 &le; E &lt; T</var></li> <li><var>1 &le; x<sub>i</sub> &le; 10^4</var></li> <li>入力値はすべて整数である.</li> </ul> <h2>入出力例</h2> <h3>入力例 1</h3> <pre> 2 10 2 3 4 </pre> <h3>出力例 1</h3> <pre> 2 </pre> <p> 8秒,9秒,10秒,11秒,12秒 のうちのいずれかの時間を計測できればよい. 1 番目の砂時計で測ることのできる時間は 3秒,6秒,9秒,12秒,... であり, 2 番目の砂時計で測ることのできる時間は 4秒,8秒,12秒,16秒,... であるので,どちらの砂時計を用いても目的の時間を計測できる. 出力例 1 では 2 を答えとしているが,1 を答えにしても正解である. </p> <h3>入力例 2</h3> <pre> 3 10 5 16 17 18 </pre> <h3>出力例 2</h3> <pre> -1 </pre> <p> どの砂時計を使っても目的の時間は計測できない. </p> <hr> <address>Writer: 花田裕一朗</address> <address>Tester: 小浜翔太郎</address>
p01170
<H1><font color="#000">Problem H:</font> Robot's Crash</H1> <p> Prof. Jenifer A. Gibson is carrying out experiments with many robots. Since those robots are expensive, she wants to avoid their crashes during her experiments at her all effort. So she asked you, her assistant, as follows. </p> <p> “Suppose that we have <i>n</i> (2 &le; <i>n</i> &le; 100000) robots of the circular shape with the radius of <i>r</i>, and that they are placed on the <i>xy</i>-plane without overlaps. Each robot starts to move straight with a velocity of either <i>v</i> or -<i>v</i> simultaneously, say, at the time of zero. The robots keep their moving infinitely unless I stop them. I’d like to know in advance if some robots will crash each other. The robots crash when their centers get closer than the distance of 2<i>r</i>. I’d also like to know the time of the first crash, if any, so I can stop the robots before the crash. Well, could you please write a program for this purpose?” </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <pre> <i>n</i> <i>vx vy</i> <i>r</i> <i>rx</i><sub>1</sub> <i>ry</i><sub>1</sub> <i>u</i><sub>1</sub> <i>rx</i><sub>2</sub> <i>ry</i><sub>2</sub> <i>u</i><sub>2</sub> ... <i>rx</i><sub><i>n</i></sub> <i>ry</i><sub><i>n</i></sub> <i>u<sub>n</sub></i> </pre> <p> <i>n</i> is the number of robots. (<i>vx</i>, <i>vy</i>) denotes the vector of the velocity <i>v</i>. <i>r</i> is the radius of the robots. (<i>rx</i><sub><i>i</i></sub> , <i>ry</i><sub><i>i</i></sub> ) denotes the coordinates of the center of the <i>i</i>-th robot. <i>u<sub>i</sub></i> denotes the moving direction of the <i>i</i>-th robot, where 1 indicates the <i>i</i>-th robot moves with the velocity (<i>vx</i> , <i>vy</i>), and -1 indicates (-<i>vx</i> , -<i>vy</i>). </p> <p> All the coordinates range from -1200 to 1200. Both <i>vx</i> and <i>vy</i> range from -1 to 1. </p> <p> You may assume all the following hold for any pair of robots: </p> <ul> <li>they must not be placed closer than the distance of (2<i>r</i> + 10<sup>-8</sup> ) at the initial state;</li> <li> they must get closer than the distance of (2<i>r</i> - 10<sup>-8</sup> ) if they crash each other at some point of time; and</li> <li> they must not get closer than the distance of (2<i>r</i> + 10<sup>-8</sup> ) if they don’t crash.</li> </ul> <p> The input is terminated by a line that contains a zero. This should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the first crash time in a line, or “SAFE” if no pair of robots crashes each other. Each crash time should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10<sup>-4</sup>. </p> <H2>Sample Input</H2> <pre> 2 1.0 0.0 0.5 0.0 0.0 1 2.0 0.0 -1 2 1.0 0.0 0.5 0.0 0.0 -1 2.0 0.0 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.500000 SAFE </pre>
p03399
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You planned a trip using trains and buses. The train fare will be <var>A</var> yen (the currency of Japan) if you buy ordinary tickets along the way, and <var>B</var> yen if you buy an unlimited ticket. Similarly, the bus fare will be <var>C</var> yen if you buy ordinary tickets along the way, and <var>D</var> yen if you buy an unlimited ticket.</p> <p>Find the minimum total fare when the optimal choices are made for trains and buses.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A \leq 1</var> <var>000</var></li> <li><var>1 \leq B \leq 1</var> <var>000</var></li> <li><var>1 \leq C \leq 1</var> <var>000</var></li> <li><var>1 \leq D \leq 1</var> <var>000</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total fare.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>600 300 220 420 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>520 </pre> <p>The train fare will be <var>600</var> yen if you buy ordinary tickets, and <var>300</var> yen if you buy an unlimited ticket. Thus, the optimal choice for trains is to buy an unlimited ticket for <var>300</var> yen. On the other hand, the optimal choice for buses is to buy ordinary tickets for <var>220</var> yen.</p> <p>Therefore, the minimum total fare is <var>300 + 220 = 520</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>555 555 400 200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>755 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>549 817 715 603 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1152 </pre></section> </div> </span>
p03663
<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>Snuke has a favorite positive integer, <var>N</var>. You can ask him the following type of question at most <var>64</var> times: "Is <var>n</var> your favorite integer?" Identify <var>N</var>.</p> <p>Snuke is twisted, and when asked "Is <var>n</var> your favorite integer?", he answers "Yes" if one of the two conditions below is satisfied, and answers "No" otherwise:</p> <ul> <li>Both <var>n \leq N</var> and <var>str(n) \leq str(N)</var> hold.</li> <li>Both <var>n &gt; N</var> and <var>str(n) &gt; str(N)</var> hold.</li> </ul> <p>Here, <var>str(x)</var> is the decimal representation of <var>x</var> (without leading zeros) as a string. For example, <var>str(123) =</var> <code>123</code> and <var>str(2000)</var> = <code>2000</code>. Strings are compared lexicographically. For example, <code>11111</code> <var>&lt;</var> <code>123</code> and <code>123456789</code> <var>&lt;</var> <code>9</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^{9}</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Input and Output</h3><p>Write your question to Standard Output in the following format:</p> <pre>? <var>n</var> </pre> <p>Here, <var>n</var> must be an integer between <var>1</var> and <var>10^{18}</var> (inclusive).</p> <p>Then, the response to the question shall be given from Standard Input in the following format:</p> <pre><var>ans</var> </pre> <p>Here, <var>ans</var> is either <code>Y</code> or <code>N</code>. <code>Y</code> represents "Yes"; <code>N</code> represents "No".</p> <p>Finally, write your answer in the following format:</p> <pre>! <var>n</var> </pre> <p>Here, <var>n=N</var> must hold.</p> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Judging</h3><ul> <li><font color="red"><strong>After each output, you must flush Standard Output.</strong></font> Otherwise you may get <code>TLE</code>.</li> <li>After you print the answer, the program must be terminated immediately. Otherwise, the behavior of the judge is undefined.</li> <li>When your output is invalid or incorrect, the behavior of the judge is undefined (it does not necessarily give <code>WA</code>).</li> </ul> </section> </div> <div class="part"> <section> <h3>Sample</h3><p>Below is a sample communication for the case <var>N=123</var>:</p> <table class="table table-bordered"> <thead> <tr> <th>Input</th> <th>Output</th> </tr> </thead> <tbody> <tr> <td></td> <td><code>? 1</code></td> </tr> <tr> <td><code>Y</code></td> <td></td> </tr> <tr> <td></td> <td><code>? 32</code></td> </tr> <tr> <td><code>N</code></td> <td></td> </tr> <tr> <td></td> <td><code>? 1010</code></td> </tr> <tr> <td><code>N</code></td> <td></td> </tr> <tr> <td></td> <td><code>? 999</code></td> </tr> <tr> <td><code>Y</code></td> <td></td> </tr> <tr> <td></td> <td><code>! 123</code></td> </tr> </tbody> </table> <ul> <li>Since <var>1 \leq 123</var> and <var>str(1) \leq str(123)</var>, the first response is "Yes".</li> <li>Since <var>32 \leq 123</var> but <var>str(32) &gt; str(123)</var>, the second response is "No".</li> <li>Since <var>1010 &gt; 123</var> but <var>str(1010) \leq str(123)</var>, the third response is "No".</li> <li>Since <var>999 \geq 123</var> and <var>str(999) &gt; str(123)</var>, the fourth response is "Yes".</li> <li>The program successfully identifies <var>N=123</var> in four questions, and thus passes the case.</li> </ul></section> </div> </div> </span>
p02971
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a sequence of length <var>N</var>: <var>A_1, A_2, ..., A_N</var>. For each integer <var>i</var> between <var>1</var> and <var>N</var> (inclusive), answer the following question:</p> <ul> <li>Find the maximum value among the <var>N-1</var> elements other than <var>A_i</var> in the sequence.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200000</var></li> <li><var>1 \leq A_i \leq 200000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>:</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line (<var>1 \leq i \leq N</var>) should contain the maximum value among the <var>N-1</var> elements other than <var>A_i</var> in the sequence.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 3 4 </pre> <ul> <li>The maximum value among the two elements other than <var>A_1</var>, that is, <var>A_2 = 4</var> and <var>A_3 = 3</var>, is <var>4</var>.</li> <li>The maximum value among the two elements other than <var>A_2</var>, that is, <var>A_1 = 1</var> and <var>A_3 = 3</var>, is <var>3</var>.</li> <li>The maximum value among the two elements other than <var>A_3</var>, that is, <var>A_1 = 1</var> and <var>A_2 = 4</var>, is <var>4</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 5 </pre></section> </div> </span>
p03233
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a directed weighted graph with <var>N</var> vertices. Each vertex has two integers written on it, and the integers written on Vertex <var>i</var> are <var>A_i</var> and <var>B_i</var>.</p> <p>In this graph, there is an edge from Vertex <var>x</var> to Vertex <var>y</var> for all pairs <var>1 \leq x,y \leq N</var>, and its weight is <var>{\rm min}(A_x,B_y)</var>.</p> <p>We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>1 \leq B_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</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 weight of the edges in such a cycle.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 5 4 2 6 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>Consider the cycle <var>1→3→2→1</var>. The weights of those edges are <var>{\rm min}(A_1,B_3)=1</var>, <var>{\rm min}(A_3,B_2)=2</var> and <var>{\rm min}(A_2,B_1)=4</var>, for a total of <var>7</var>. As there is no cycle with a total weight of less than <var>7</var>, the answer is <var>7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 5 2 6 3 7 4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 19 92 64 64 78 48 57 33 73 6 95 73 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>227 </pre></section> </div> </span>
p02588
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given <var>N</var> real values <var>A_1, A_2, \ldots, A_N</var>. Compute the number of pairs of indices <var>(i, j)</var> such that <var>i &lt; j</var> and the product <var>A_i \cdot A_j</var> is integer.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200\,000</var></li> <li><var>0 &lt; A_i &lt; 10^4</var></li> <li><var>A_i</var> is given with at most 9 digits after the decimal.</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>\vdots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of pairs with integer product <var>A_i \cdot A_j</var> (and <var>i &lt; j</var>).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 7.5 2.4 17.000000001 17 16.000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are 3 pairs with integer product:</p> <ul> <li><var>7.5 \cdot 2.4 = 18</var></li> <li><var>7.5 \cdot 16 = 120</var></li> <li><var>17 \cdot 16 = 272</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>11 0.9 1 1 1.25 2.30000 5 70 0.000000001 9999.999999999 0.999999999 1.000000001 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre></section> </div> </span>
p02072
<style type="text/css"> blockquote { font-family: Menlo, Monaco, "Courier New", monospace; display: block; margin: 10px 0 10px 30px; font-size: 16px; line-height: 18px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; } table.ioexample { width: 100%; border-collapse: collapse; } table.ioexample td { width: 50%; border: 1px solid rgba(0, 0, 0, 0.15); vertical-align: top; padding: 5px; } .no-page-break { page-break-inside: avoid; } .page-break { page-break-before: always; } </style> <h3>Problem Statement</h3> <p>In A.D. 2101, war was beginning. The enemy has taken over all of our bases. To recapture the bases, we decided to set up a headquarters. We need to define the location of the headquarters so that all bases are not so far away from the headquarters. Therefore, we decided to choose the location to minimize the sum of the distances from the headquarters to the furthest $K$ bases. The bases are on the 2-D plane, and we can set up the headquarters in any place on this plane even if it is not on a grid point.</p> <p>Your task is to determine the optimal headquarters location from the given base positions.</p> <hr /> <h3>Input</h3> <p>The input consists of a single test case in the format below.</p> <blockquote>$N$ $K$ $x_{1}$ $y_{1}$ $\vdots$ $x_{N}$ $y_{N}$</blockquote> <p>The first line contains two integers $N$ and $K$. The integer $N$ is the number of the bases ($1 \le N \le 200$). The integer $K$ gives how many bases are considered for calculation ($1 \le K \le N$). Each of the following $N$ lines gives the x and y coordinates of each base. All of the absolute values of given coordinates are less than or equal to $1000$, i.e., $-1000 \le x_{i}, y_{i} \le 1000$ is satisfied.</p> <h3>Output</h3> <p>Output the minimum sum of the distances from the headquarters to the furthest $K$ bases. The output can contain an absolute or a relative error no more than $10^{-3}$.</p> <p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>3 1 0 1 1 0 1 1 </pre></td><td><pre>0.70711 </pre></td></tr><tr><td><pre>6 3 1 1 2 1 3 2 5 3 8 5 13 8 </pre></td><td><pre>17.50426 </pre></td></tr><tr><td><pre>9 3 573 -50 -256 158 -751 14 314 207 293 567 59 -340 -243 -22 -268 432 -91 -192 </pre></td><td><pre>1841.20904 </pre></td></tr></table></div></p>
p02422
<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> <h2>Transformation</h2><br> <p> Write a program which performs a sequence of commands to a given string $str$. The command is one of: </p> <ul> <li><span>print a b</span>: print from the <apan>a</span>-th character to the <span>b</span>-th character of $str$</li> <li><span>reverse a b</span>: reverse from the <span>a</span>-th character to the <span>b</span>-th character of $str$</li> <li><span>replace a b p</span>: replace from the <span>a</span>-th character to the <span>b</span>-th character of $str$ with <span>p</span></li> </ul> <p> Note that the indices of $str$ start with 0. </p> <h2>Input</h2> <p> In the first line, a string $str$ is given. $str$ consists of lowercase letters. In the second line, the number of commands <var>q</var> is given. In the next <var>q</var> lines, each command is given in the above mentioned format. </p> <h2>Output</h2> <p> For each <span>print</span> command, print a string in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq $ length of $str \leq 1000$</li> <li>$1 \leq q \leq 100$</li> <li>$0 \leq a \leq b < $ length of $str$</li> <li>for replace command, $b - a + 1 = $ length of $p$</li> </ul> <h2>Sample Input 1</h2> <pre> abcde 3 replace 1 3 xyz reverse 0 2 print 1 4 </pre> <h2>Sample Output 1</h2> <pre> xaze </pre> <h2>Sample Input 2</h2> <pre> xyz 3 print 0 2 replace 0 2 abc print 0 2 </pre> <h2>Sample Output 2</h2> <pre> xyz abc </pre>
p02137
<h1>Problem A: Special Chat</h1> <h2>Problem</h2> <p>人気動画投稿サイト「ZouTube」は今、空前の「バーチャルZouTuber」ブームの真っ只中にある。その中でも、最近特に注目を集めているのは、後輩系バーチャルZouTuber「アイヅマリム(通称:アヅリム)」だ。</p> <p>アヅリムの大ファンであるあなたは、本日のアヅリムのライブ配信で、彼女に「スペシャルチャット」を送るつもりだ。</p> <p>「スペシャルチャット」とは、ZouTubeの提供する「視聴者が配信者にポイントをプレゼントする機能」 だ。視聴者はスペシャルチャット$1$回につき、$500$, $1000$, $5000$, $10000$のいずれかだけポイントを消費して、消費した量と同じ量だけポイントを配信者にプレゼントできる。</p> <p>今あなたが保持しているポイントの総量が与えられたとき、そのポイントを消費して、あなたがアヅリムにプレゼントできるポイントの総量の最大値を求めよ。保持しているポイントの量が消費するポイントの量を下回らない限り、スペシャルチャットは何度でも行うことができる。</p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $P$ </pre> <p> 今あなたが保持しているポイントの総量を表す整数$P$が$1$行に与えられる。<br> </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$1 \le P \le 10^5$</li> </ul> <h2>Output</h2> <p>アヅリムにプレゼントできるポイントの総量の最大値を$1$行に出力する。</p> <h2>Sample Input 1</h2> <pre> 5700 </pre> <h2>Sample Output 1</h2> <pre> 5500 </pre> <h2>Sample Input 2</h2> <pre> 1333 </pre> <h2>Sample Output 2</h2> <pre> 1000 </pre> <h2>Sample Input 3</h2> <pre> 100000 </pre> <h2>Sample Output 3</h2> <pre> 100000 </pre>
p02567
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an array <var>a_0, a_1, ..., a_{N-1}</var> of length <var>N</var>. Process <var>Q</var> queries of the following types.</p> <p>The type of <var>i</var>-th query is represented by <var>T_i</var>.</p> <ul> <li><var>T_i=1</var>: You are given two integers <var>X_i,V_i</var>. Replace the value of <var>A_{X_i}</var> with <var>V_i</var>.</li> <li><var>T_i=2</var>: You are given two integers <var>L_i,R_i</var>. Calculate the maximum value among <var>A_{L_i},A_{L_i+1},\cdots,A_{R_i}</var>.</li> <li><var>T_i=3</var>: You are given two integers <var>X_i,V_i</var>. Calculate the minimum <var>j</var> such that <var>X_i \leq j \leq N, V_i \leq A_j</var>. If there is no such <var>j</var>, answer <var>j=N+1</var> instead.</li> </ul> </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 \leq 10^9</var></li> <li><var>1 \leq Q \leq 2 \times 10^5</var></li> <li><var>1 \leq T_i \leq 3</var></li> <li><var>1 \leq X_i \leq N</var>, <var>0 \leq V_i \leq 10^9</var> (<var>T_i=1,3</var>)</li> <li><var>1 \leq L_i \leq R_i \leq N</var> (<var>T_i=2</var>)</li> <li>All values in Input are 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>Q</var> <var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var> First query Second query <var>\vdots</var> <var>Q</var>-th query </pre> <p>Each query is given in the following format:</p> <p>If <var>T_i=1,3</var>,</p> <pre><var>T_i</var> <var>X_i</var> <var>V_i</var> </pre> <p>If <var>T_i=2</var>,</p> <pre><var>T_i</var> <var>L_i</var> <var>R_i</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query with <var>T_i=2, 3</var>, print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 1 2 3 2 1 2 1 5 3 2 3 1 3 1 2 2 4 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 3 2 6 </pre> <ul> <li>First query: Print <var>3</var>, which is the maximum of <var>(A_1,A_2,A_3,A_4,A_5)=(1,2,3,2,1)</var>.</li> <li>Second query: Since <var>3&gt;A_2</var>, <var>j=2</var> does not satisfy the condition.Since <var>3 \leq A_3</var>, print <var>j=3</var>.</li> <li>Third query: Replace the value of <var>A_3</var> with <var>1</var>. It becomes <var>A=(1,2,1,2,1)</var>.</li> <li>Fourth query: Print <var>2</var>, which is the maximum of <var>(A_2,A_3,A_4)=(2,1,2)</var>.</li> <li>Fifth query: Since there is no <var>j</var> that satisfies the condition, print <var>j=N+1=6</var>.</li> </ul></section> </div> </span>
p03726
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var>. The <var>i</var>-th of the <var>N-1</var> edges connects vertices <var>a_i</var> and <var>b_i</var>.</p> <p>Initially, each vertex is uncolored.</p> <p>Takahashi and Aoki is playing a game by painting the vertices. In this game, they alternately perform the following operation, starting from Takahashi:</p> <ul> <li>Select a vertex that is not painted yet.</li> <li>If it is Takahashi who is performing this operation, paint the vertex white; paint it black if it is Aoki.</li> </ul> <p>Then, after all the vertices are colored, the following procedure takes place:</p> <ul> <li>Repaint every white vertex that is adjacent to a black vertex, in black.</li> </ul> <p>Note that all such white vertices are repainted simultaneously, not one at a time.</p> <p>If there are still one or more white vertices remaining, Takahashi wins; if all the vertices are now black, Aoki wins. Determine the winner of the game, assuming that both persons play optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≤ N ≤ 10^5</var></li> <li><var>1 ≤ a_i,b_i ≤ N</var></li> <li><var>a_i ≠ b_i</var></li> <li>The input graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> : <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>First</code> if Takahashi wins; print <code>Second</code> if Aoki wins.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>First </pre> <p>Below is a possible progress of the game:</p> <ul> <li>First, Takahashi paint vertex <var>2</var> white.</li> <li>Then, Aoki paint vertex <var>1</var> black.</li> <li>Lastly, Takahashi paint vertex <var>3</var> white.</li> </ul> <p>In this case, the colors of vertices <var>1</var>, <var>2</var> and <var>3</var> after the final procedure are black, black and white, resulting in Takahashi's victory.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 2 3 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>First </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 2 3 3 4 2 5 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Second </pre></section> </div> </span>
p00809
<H1><font color="#000">Problem G:</font> Nim</H1> <p> Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones on the table (we know the number of stones exactly). We play in turn and at each turn, you or I can remove one to four stones from the heap. You play first and the one who removed the last stone loses. </p> <p> In this game, you have a winning strategy. To see this, you first remove four stones and leave 96 stones. No matter how I play, I will end up with leaving 92-95 stones. Then you will in turn leave 91 stones for me (verify this is always possible). This way, you can always leave 5<i>k</i> + 1 stones for me and finally I get the last stone, sigh. If we initially had 101 stones, on the other hand, I have a winning strategy and you are doomed to lose. </p> <p> Let's generalize the game a little bit. First, let's make it a team game. Each team has <i>n</i> players and the 2<i>n</i> players are seated around the table, with each player having opponents at both sides. Turns round the table so the two teams play alternately. Second, let's vary the maximum number ofstones each player can take. That is, each player has his/her own maximum number ofstones he/she can take at each turn (The minimum is always one). So the game is asymmetric and may even be unfair. </p> <p> In general, when played between two teams of experts, the outcome of a game is completely determined by the initial number ofstones and the minimum number of stones each player can take at each turn. In other words, either team has a winning strategy. </p> <p> You are the head-coach of a team. In each game, the umpire shows both teams the initial number of stones and the maximum number of stones each player can take at each turn. Your team plays first. Your job is, given those numbers, to instantaneously judge whether your team has a winning strategy. </p> <p> Incidentally, there is a rumor that Captain Future and her officers of Hakodate-maru love this game, and they are killing their time playing it during their missions. You wonder where the stones are?. Well, they do not have stones but do have plenty of balls in the fuel containers!. </p> <H2>Input</H2> <p> The input is a sequence of lines, followed by the last line containing a zero. Each line except the last is a sequence of integers and has the following format. </p> <pre> <i>n S</i> <i>M</i><sub>1</sub> <i>M</i><sub>2</sub> ... <i>M</i><sub>2<i>n</i></sub> </pre> <p> where <i>n</i> is the number of players in a team, <i>S</i> the initial number of stones, and <i>M<sub>i</sub></i> the maximum number of stones i th player can take. 1st, 3rd, 5th, ... players are your team's players and 2nd, 4th, 6th, ... the opponents. Numbers are separated by a single space character. You may assume 1 &le; <i>n</i> &le; 10, 1 &le; <i>M<sub>i</sub></i> &le; 16, and 1 &le; <i>S</i> &le; 2<sup>13</sup>. </p> <H2>Output</H2> <p> The out put should consist of lines each containing either a one, meaning your team has a winning strategy, or a zero otherwise. </p> <H2>Sample Input</H2> <pre> 1 101 4 4 1 100 4 4 3 97 8 7 6 5 4 3 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 1 1 </pre>
p02834
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices. The <var>i</var>-th edge connects Vertex <var>A_i</var> and <var>B_i</var> bidirectionally.</p> <p>Takahashi is standing at Vertex <var>u</var>, and Aoki is standing at Vertex <var>v</var>.</p> <p>Now, they will play a game of tag as follows:</p> <ul> <li> <p><var>1</var>. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.</p> </li> <li> <p><var>2</var>. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.</p> </li> <li> <p><var>3</var>. Go back to step <var>1</var>.</p> </li> </ul> <p>Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.</p> <p>Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.</p> <p>It can be proved that the game is bound to end.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq u,v \leq N</var></li> <li><var>u \neq v</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>u</var> <var>v</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>A_{N-1}</var> <var>B_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of moves Aoki will perform before the end of the game.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 1 1 2 2 3 3 4 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>If both players play optimally, the game will progress as follows:</p> <ul> <li>Takahashi moves to Vertex <var>3</var>.</li> <li>Aoki moves to Vertex <var>2</var>.</li> <li>Takahashi moves to Vertex <var>5</var>.</li> <li>Aoki moves to Vertex <var>3</var>.</li> <li>Takahashi moves to Vertex <var>3</var>.</li> </ul> <p>Here, Aoki performs two moves.</p> <p>Note that, in each move, it is prohibited to stay at the current vertex.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 4 5 1 2 1 3 1 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>9 6 1 1 2 2 3 3 4 4 5 5 6 4 7 7 8 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 </pre></section> </div> </span>
p03376
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Akaki, a patissier, can make <var>N</var> kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut <var>1</var>, Doughnut <var>2</var>, <var>...,</var> Doughnut <var>N</var>. In order to make one Doughnut <var>i</var> <var>(1 ≤ i ≤ N)</var>, she needs to consume <var>m_i</var> grams of Moto. She cannot make a non-integer number of doughnuts, such as <var>0.5</var> doughnuts.</p> <p>The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut <var>1</var>. Specifically, the recipe of Doughnut <var>i</var> <var>(2 ≤ i ≤ N)</var> is a direct modification of the recipe of Doughnut <var>p_i</var> <var>(1 ≤ p_i &lt; i)</var>.</p> <p>Now, she has <var>X</var> grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:</p> <ul> <li>Let <var>c_i</var> be the number of Doughnut <var>i</var> <var>(1 ≤ i ≤ N)</var> that she makes. For each integer <var>i</var> such that <var>2 ≤ i ≤ N</var>, <var>c_{p_i} ≤ c_i ≤ c_{p_i} + D</var> must hold. Here, <var>D</var> is a predetermined value.</li> </ul> <p>At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≤ N ≤ 50</var></li> <li><var>1 ≤ X ≤ 10^9</var></li> <li><var>0 ≤ D ≤ 10^9</var></li> <li><var>1 ≤ m_i ≤ 10^9</var> <var>(1 ≤ i ≤ N)</var></li> <li><var>1 ≤ p_i &lt; i</var> <var>(2 ≤ i ≤ 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>X</var> <var>D</var> <var>m_1</var> <var>m_2</var> <var>p_2</var> <var>:</var> <var>m_N</var> <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of doughnuts that can be made under the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 100 1 15 10 1 20 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>She has <var>100</var> grams of Moto, can make three kinds of doughnuts, and the conditions that must hold are <var>c_1 ≤ c_2 ≤ c_1 + 1</var> and <var>c_1 ≤ c_3 ≤ c_1 + 1</var>. It is optimal to make two Doughnuts <var>1</var>, three Doughnuts <var>2</var> and two Doughnuts <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 100 10 15 10 1 20 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> <p>The amount of Moto and the recipes of the doughnuts are not changed from Sample Input 1, but the last conditions are relaxed. In this case, it is optimal to make just ten Doughnuts <var>2</var>. As seen here, she does not necessarily need to make all kinds of doughnuts.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1000000000 1000000 123 159 1 111 1 135 3 147 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7496296 </pre></section> </div> </span>
p01961
<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> RPG Maker </H1> <p> You are planning to create a map of an RPG. This map is represented by a grid whose size is $H \times W$. Each cell in this grid is either '<span>@</span>', '<span>*</span>', '<span>#</span>', or '<span>.</span>'. The meanings of the symbols are as follows. </p> <ul> <li>'<span>@</span>': The start cell. The story should start from this cell.</li> <li>'<span>*</span>': A city cell. The story goes through or ends with this cell.</li> <li>'<span>#</span>': A road cell.</li> <li>'<span>.</span>': An empty cell.</li> </ul> <p> You have already located the start cell and all city cells under some constraints described in the input section, but no road cells have been located yet. Then, you should decide which cells to set as road cells. </p> <p> Here, you want a "journey" exists on this map. Because you want to remove the branch of the story, the journey has to be unforked. More formally, the journey is a sequence of cells and must satisfy the following conditions: </p> <ol> <li> The journey must contain as many city cells as possible. </li> <li> The journey must consist of distinct non-empty cells in this map.</li> <li> The journey must begin with the start cell.</li> <li> The journey must end with one of the city cells.</li> <li> The journey must contain all road cells. That is, road cells not included in the journey must not exist.</li> <li> The journey must be unforked. In more detail, all road cells and city cells except for a cell at the end of the journey must share edges with the other two cells both of which are also contained in the journey. Then, each of the start cell and a cell at the end of the journey must share an edge with another cell contained in the journey.</li> <li> You do not have to consider the order of the cities to visit during the journey.</li> </ol> <p> Initially, the map contains no road cells. You can change any empty cells to road cells to make a journey satisfying the conditions above. Your task is to print a map which maximizes the number of cities in the journey. </p> <H2>Input</H2> <p> The input consists of a single test case of the following form. </p> <pre> $H$ $W$ $S_1$ $S_2$ : $S_H$ </pre> <p> The first line consists of two integers $N$ and $W$. $H$ and $W$ are guaranteed to satisfy $H = 4n - 1$ and $W = 4m -1$ for some positive integers $n$ and $m$ ($1 \leq n, m \leq 10$). The following $H$ lines represent a map without road cells. The ($i+1$)-th line consists of a string $S_i$ of length $W$. The $j$-th character of $S_i$ is either '<span>*</span>', '<span>@</span>' or '<span>.</span>' if both $i$ and $j$ are odd, otherwise '<span>.</span>'. The number of occurrences of '<span>@</span>' in the grid is exactly one. It is guaranteed that there are one or more city cells on the grid. </p> <H2>Output</H2> <p> Print a map indicating a journey. If several maps satisfy the condition, you can print any of them. </p> <H2>Sample Input 1</H2> <pre> 11 7 ....... ....... *.....* ....... ..@.... ....... *...... ....... ....*.. ....... ....... </pre> <H2>Output for Sample Input 1</H2> <pre> ....... ....... *#####* ......# ..@...# ..#.### *##.#.. #...#.. ####*.. ....... ....... </pre> <H2>Sample Input 2</H2> <pre> 7 11 ........*.. ........... ........... ........... ....*...*.. ........... ..*.@...*.. </pre> <H2>Output for Sample Input 2</H2> <pre> ........*.. ........#.. ........#.. ........#.. ..##*##.*.. ..#...#.#.. ..*#@.##*.. </pre>
p00673
<h1>Problem E: School Excursion</h1> <p> 春、それは修学旅行の時期である。 会津大学附属小学校(会津大小)でも、来年度の修学旅行の計画が建てられていた。 修学旅行は電車で移動することが伝統になっている。 会津若松市内では電車を利用する機会が少ないためだ。 </p> <p> しかし、学校に届いたある苦情により教員たちは頭を悩ませていた。 それは、「ある駅で大人数で乗り換えを行っていたので、その駅を利用する他の乗客に迷惑であった」という内容だった。 とくに、電車を降りたあとホームからの通路で大混雑してしまったという。 </p> <p> それは近年、会津大小の生徒数が急上昇しているからであった。 その原因は日本において競技プログラミングが大流行し、 小学校から競技プログラマーを養成するための訓練を行っている会津大小に生徒が集まったからである。 </p> <p> 会津大小競技プログラミング部長であるあなたは、修学旅行を楽しみにしている。 修学旅行を成功させたいあなたは教員たちに提案をした。 「クラスごとに行動して、同じ駅に同時に到着しないようにしましょう!! 競技プログラミングの知識を応用すれば簡単です!!」 </p> <p> 複数のクラスが同時に同じ駅に到着することがないように移動するとき(同じ駅に複数のクラスが滞在することは可能)、 出発する駅から目的地まで到達できる最大のクラス数を求め、そのときの最小の運賃を求めるプログラムをつくりなさい。 ただし、ある駅で同時に到着する電車と発車する電車が存在する場合、乗り継ぎが可能である。つまり、乗り継ぎに要する時間は無視して良い。 </p> <h2>Input</h2> <p> 入力は複数のデータセットから構成される。 データセットの数は20個以下である。 各データセットの形式は次に示す通りである。 </p> <pre> n m<sub>1</sub> x<sub>1,1</sub> y<sub>1,1</sub> c<sub>1,1</sub> x<sub>1,2</sub> y<sub>1,2</sub> c<sub>1,2</sub> ... x<sub>1,m1</sub> y<sub>1,m1</sub> c<sub>1,m1</sub> m<sub>2</sub> x<sub>2,1</sub> y<sub>2,1</sub> c<sub>2,1</sub> x<sub>2,2</sub> y<sub>2,2</sub> c<sub>2,2</sub> ... x<sub>2,m2</sub> y<sub>2,m2</sub> c<sub>2,m2</sub> ... m<sub>n-1</sub> x<sub>n-1,1</sub> y<sub>n-1,1</sub> c<sub>n-1,1</sub> x<sub>n-1,2</sub> y<sub>n-1,2</sub> c<sub>n-1,2</sub> ... x<sub>n-1,m2</sub> y<sub>n-1,m2</sub> c<sub>n-1,m2</sub> g </pre> <p> n( 2 &le; n &le; 100)は駅の数を表す。 駅の数は出発する駅と目的地の駅、乗り換えする駅を含む。 駅は出発する駅を1番目、最初に乗り換える駅を2番目の駅と数え、目的地をn番目の駅とする。 m<sub>i</sub>はi番目の駅からi+1番目の駅への電車の数を表す。 m<sub>i</sub>(1 &le; m &le; 20)個の電車の情報が続く。 x<sub>i,j</sub> y<sub>i,j</sub> c<sub>i,j</sub> はi番目の駅からi+1番目の駅に向かう電車の出発時刻(x<sub>i,j</sub>)到着時刻(y<sub>i,j</sub>)運賃(c<sub>i,j</sub>)を表す。 (0 &le; x<sub>i,j</sub>, y<sub>i,j</sub> &le; 200000 かつ x<sub>i,j</sub> &le; y<sub>i,j</sub>) (1 &le; c<sub>i,j</sub> &le; 1000) その後g(1&le; g &le; 10)が続く。 gは修学旅行に参加するクラス数を表す。 与えられる数(n,m,x,y,c,g)はすべて整数である。 入力の終了はひとつの0を含む1行で示される。 </p> <h2>Output</h2> <p> 一行に到着可能なクラス数とそのときの最小運賃をこの順に出力せよ。 もし、ただ一つのクラスも到着できない場合は0 0を出力せよ。 </p> <h2>Sample Input</h2> <pre> 2 4 1 2 10 2 2 5 1 3 20 2 3 10 10 3 2 1 2 5 0 3 4 3 10 11 100 2 12 2 12 12 3 10 0 </pre> <h2>Sample Output</h2> <pre> 2 15 2 111 </pre>
p00389
<h1>Pilling Blocks</h1> <p> We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing. </p> <p> We have to build the tower abiding by the following conditions: </p> <ul> <li>Every stage of the tower has one or more blocks on it.</li> <li>Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.</li> </ul> <p> Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $K$ </pre> <p> The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$). </p> <h2>Output</h2> <p> Output the maximum possible number of stages. </p> <h2>Sample Input 1</h2> <pre> 4 2 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <h2>Sample Input 2</h2> <pre> 5 2 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre>
p00223
<H1>迷子の双子</H1> <p> たかゆき君とかずゆき君は仲良しの双子ですが、行動が真逆です。 例えば、たかゆき君が西に行けば、かずゆき君は東へ行き、かずゆき君が北へ行けば、たかゆき君は南へ行きます。 現在 2 人はデパートに来ており、別々の場所にいます。真逆に移動してしまう 2 人ができるだけ早く出会うためにはどうしたらよいでしょうか? </p> <p> デパートは横 <var>W</var> 個 &times; 縦 <var>H</var> 個のマスで構成されるグリッドで表され、2 人は単位時間に東西南北に 1 マス分移動することができます。ただし、グリッドの範囲外や障害物のあるマスに移動することはできません。 </p> <p> 図のように、グリッドのマスの位置は座標 (<var>x</var>, <var>y</var>) で表されます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_straytwins"><br/> </center> <p> グリッドの情報と 2 人の初期位置を入力とし、2 人が出会うまでの最短の時間を出力するプログラムを作成してください。出会うことができない場合や、出会うのに 100 以上の時間を要する場合は、NA と出力してください。グリッドの情報は、<var>H</var> 行 <var>W</var> 列の数字、2 人の位置情報は座標によって与えられます。 </p> <p> 移動後にたかゆき君かかずゆき君のうち、どちらか一方が障害物やグリッドの範囲外に位置してしまうときには、移動ができないので、障害物やグリッドの範囲外に位置する方は元の場所に戻りますが、そうでない方は元の場所に戻ることなく動くことができます。 </p> <p> なお、2 人が出会うとは、移動後に 2 人が同じマスに止まることを言います。2 人がすれ違っても、出会ったことにはなりません。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>W</var> <var>H</var> <var>tx</var> <var>ty</var> <var>kx</var> <var>ky</var> <var>d<sub>11</sub></var> <var>d<sub>21</sub></var> ... <var>d<sub>W1</sub></var> <var>d<sub>12</sub></var> <var>d<sub>22</sub></var> ... <var>d<sub>W2</sub></var> : <var>d<sub>1H</sub></var> <var>d<sub>2H</sub></var> ... <var>d<sub>WH</sub></var> </pre> <p> 1 行目にデパートの大きさ<var>W</var>, <var>H</var> (1 &le; <var>W, H</var> &le; 50) が与えられます。2 行目にたかゆき君の初期位置 <var>tx, ty</var>、3 行目にかずゆき君の初期位置 <var>kx, ky</var> が与えられます。 </p> <p> 続く <var>H</var> 行にデパートの情報が与えられます。<var>d<sub>i,j</sub></var> はマス (<var>i, j</var>) の種類を表し、0 のとき移動可能なマス、1 のとき障害物があるマスを表します。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> 入力データセットごとに、最短の時間を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 6 6 2 4 6 2 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 3 3 1 1 3 3 0 0 0 0 1 0 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 NA </pre>
p01062
<h1>Courage Test</h1> <p> P「今日は肝試し企画の番組の収録だ。」<br><br> O型智絵里「き、きもだめし……」<br><br> 四村かな子「智絵里ちゃん大丈夫?」<br><br> 月野茜「さすがPさん!一行で状況が明晰判明にわかる素晴らしい解説です!さあ!火の玉に向かって走りましょう!」<br><br> P「ルールは簡単、みんなで協力してこのエリアのすべての神社にお参りしてくるだけだ。」<br><br> 茜「オーソドックスですね!早速神社に向かって走りましょう!」<br><br> かな子「でもここ、日本有数の神社密度で行かなくちゃいけない神社がたくさんあるんじゃなかったっけ……」<br><br> かな子「でも茜ちゃんがいれば心強いよ!」<br><br> P「ちなみにスタートは全員違う神社からスタート、合流も禁止だ。それじゃあ智絵里とかな子は初期位置についてくれ」<br><br> 智絵里「うぅ……」<br><br> かな子「お、お菓子を持っていけば大丈夫!」<br><br> 智絵里「頑張る……」<br><br> 茜「プロデューサー!私はどうすれば!」<br><br> P「お前は賑やかしだ」<br><br> 茜「えっ」<br><br> P「座ってろ」<br><br> 茜「」<br><br> </p> <h2>Problem</h2> <p> それぞれ1~<var>n</var>の番号が付けられた<var>n</var>個の神社と<var>n</var>-1本の道がある。各道は神社<var>a<sub>i</sub></var>と神社<var>b<sub>i</sub></var>を繋ぎ、双方向に移動することができる。それぞれの神社は、任意の神社から1本以上の道を経由して到達することができる。また、任意の2つの神社の間の(迂回しない)経路は一意に定まる。 </p> <p> O型智絵里ちゃんと四村かな子ちゃんがそれぞれ神社<var>u</var>と神社<var>v</var>にいる。 </p> <p> 今、2人を任意に移動させることを考える。移動とは、ある神社から1本の道を経由して別の神社に進むことである。 その際、以下のルールを満たしたい。 </p> <ol> <li>2人合わせて全ての神社を訪問する。</li> <li>2人の移動数を同じにする。</li> <li>1つの神社, 道は1人しか通れず、さらに1度しか通ることができない。</li> <li>神社<var>u</var>, <var>v</var>は既に訪れているものとし、通ることはできない。</li> </ol> <p> これらのルールを満たすことができるかどうかを判定し、できる場合は"Yes"を、できない場合は"No"を出力せよ。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> <var>n</var> <var>u</var> <var>v</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> ... <var>a<sub>n&minus;1</sub></var> <var>b<sub>n&minus;1</sub></var> </pre> <p> 1行目に3つの整数<var>n</var>, <var>u</var>, <var>v</var>が空白区切りで与えられる。<br> 2行目から<var>n</var>行目までに、2つの整数<var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>が空白区切りで与えられる。 </p> <h2>Constraints</h2> <ul> <li>2 &le; <var>n</var> &le; 10<sup>5</sup></li> <li>1 &le; <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>u</var>, <var>v</var> &le; <var>n</var></li> <li><var>u</var> &ne; <var>v</var></li> <li><var>a<sub>i</sub></var> &lt; <var>b<sub>i</sub></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>i</var> &ne; <var>j</var>)</li> </ul> <h2>Output</h2> <p> ルールを満たすことができる場合は"Yes"を、できない場合は"No"を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 4 1 4 1 2 2 3 3 4 </pre> <h2>Sample Output 1</h2> <pre> Yes </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_D1" alt="Sample Diagram 1" style="width: 30%;"></p> <h2>Sample Input 2</h2> <pre> 8 3 6 1 2 2 4 3 4 4 5 5 6 6 7 7 8 </pre> <h2>Sample Output 2</h2> <pre> No </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_D2" alt="Sample Diagram 2" style="width: 30%;"></p> <h2>Sample Input 3</h2> <pre> 4 2 3 1 2 2 3 3 4 </pre> <h2>Sample Output 3</h2> <pre> Yes </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_D3" alt="Sample Diagram 3" style="width: 30%;"></p> <h2>Sample Input 4</h2> <pre> 6 1 5 1 2 1 4 2 3 4 5 3 6 </pre> <h2>Sample Output 4</h2> <pre> No </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_D4" alt="Sample Diagram 4" style="width: 30%;"></p>
p01598
<h2>Problem H: Testing Sorting Networks</h2> <p>A <var>N</var> sorting network is a circuit that accepts <var>N</var> numbers as its input, outputs them sorted. Mr. Smith is an engineer of a company that sells various sizes of the circuit.</p> <p>One day, the company got an order of <var>N</var> sorting networks. Unfortunately, they didn't have the circuit for <var>N</var> numbers at the time. The clerk once declined the order for being out of stock, but the client was so urgent that he offered much money if he could get the circuit in a week. The deal escalated to a manager, and she asked Mr. Smith for a solution to produce the <var>N</var> sorting networks by the deadline.</p> <p>He came up with an idea to combine several <var>N/2</var> sorting networks, because he noticed that they have many stocks of the circuits for <var>N/2</var> numbers. He designed a new circuit using the <var>N/2</var> sorting networks, but he was not sure if it would really work as an <var>N</var> sorting network. So, he asked a colleague, you, to check if it was actually an <var>N</var> sorting network.</p> <p>The circuit he designed consists of multiple stages. Each stage of the circuit consists of two <var>N/2</var> sorting networks, which makes each stage accept a sequence of <var>N</var> numbers as inputs and output a sequence of <var>N</var> numbers. From the 1st to the <var>N/2</var>-th input numbers of a stage goes to one of those <var>N/2</var> sorting networks, and from the <var>(N/2+1)</var>-th to the <var>N</var>-th input numbers goes to the other. Similarly, the first half of the output numbers of a stage is the output of the former sorting network and the second half is the output of the latter, both of which are sorted in ascending order. Each output of a stage is connected to exactly one input of the next stage, and no two inputs are connected to the same output line. The input of the last stage is the input of the whole circuit and the output of the first stage is the output of the whole circuit.</p> <h2>Input</h2> <p>The input begins with a line containing a positive even integer <var>N</var> (4 <= <var>N</var> <= 100) and a positive integer <var>D</var> (1 <= <var>D</var> <= 10). <var>N</var> indicates the number of the input and output of the circuit and <var>D</var> indicates the number of the stages of the circuit. The <var>i</var>-th line of the following <var>D-1</var> lines contains <var>N</var> integers <var>w<sub>i<sub>1</sub></sub></var>, <var>w<sub>i<sub>2</sub></sub></var>,..., <var>w<sub>i<sub>N</sub></sub></var> (1 <= <var>w<sub>i<sub>j</sub></sub></var> <= <var>N</var> ), which describes the wiring between the <var>i</var>-th and <var>(i+1)</var>-th stages. <var>w<sub>i<sub>j</sub></sub></var> indicates the <var>j</var>-th input of the <var>i</var>-th stage and the <var>w<sub>i<sub>j</sub></sub></var>-th output of the <var>(i+1)</var>-th stage are wired. You can assume <var>w<sub>i<sub>1</sub></sub></var>, <var>w<sub>i<sub>2</sub></sub></var>,..., <var>w<sub>i<sub>N</sub></sub></var> are unique for each <var>i</var>.</p> <h2>Output</h2> <p>Print a line containing "Yes" if the circuit works as an <var>N</var> sorting network. Print "No" otherwise.</p> <h2>Sample Input 1</h2> <pre>4 4 1 3 4 2 1 4 2 3 1 3 2 4</pre> <h2>Output for the Sample Input 1</h2> <pre>Yes</pre> <h2>Sample Input 2</h2> <pre>4 3 3 1 2 4 1 3 2 4</pre> <h2>Output for the Sample Input 2</h2> <pre>No</pre>
p01432
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script> <h2>問題文</h2> <p>影の魔女 ELSAMARIA はすべてのものに対して祈りを続ける魔女である.影に捕まったあらゆる命はこの魔女の中に引きずり込まれてしまう.</p> <p>影は触手のように動き<i>美樹さやか</i>を引きずり込もうと狙っている.<i>美樹さやか</i>はこの魔女に捕まることなく攻撃するために,魔女にとって予測の難しいでたらめな動きをすることを考えた.具体的には,まず頭の中で <var>1</var> から <var>N</var> までの整数を一様な確率で <var>K</var> 個作り,その合計値の距離だけ今の位置から魔女の方向へジャンプする,ということを繰り返すのである.そして魔女の位置に到達した時に攻撃するのである.</p> <p><i>さやか</i>と魔女はある一直線上にいるとし,最初魔女は座標 <var>0</var>,<i>さやか</i>は座標 <var>S</var> の位置にいるものとする.また魔女は動かないものとする.何度ジャンプした後に魔女に最初の攻撃を与えることができるだろうか.期待値を求めよ.</p> <h2>入力形式</h2> <p>入力は以下の形式で与えられる.</p> <pre><var> S\ N\ K </var></pre> <p><var>S</var> は最初に<i>さやか</i>がいる座標である.<var>N</var> は<i>さやか</i>が頭の中で作る整数の範囲の上限,<var>K</var> は<i>さやか</i>が <var>1</var> 回のジャンプに用いる整数の個数である.</p> <h2>出力形式</h2> <p><i>さやか</i>が魔女の位置に到達するために必要なジャンプの回数の期待値を <var>1</var> 行に出力せよ.もし何度ジャンプしても魔女の位置へ到達できない,もしくは期待値が有限値に収まらない場合は <var>-1</var> と出力せよ.</p> <p>小数点以下何桁でも出力して構わないが,相対誤差あるいは絶対誤差が <var>10<sup>-6</sup></var> 未満になっていなければならない.</p> <h2>制約</h2> <ul> <li><var>-10<sup>9</sup> &le; S &le; 10<sup>9</sup></var></li> <li><var>1 &le; N &le; 10</var></li> <li><var>1 &le; K &le; 10</var></li> <li>入力値は全て整数である.</li> </ul> <h2>入出力例</h2> <h3>入力例 1</h3> <pre>6 6 1</pre> <h3>出力例1</h3> <pre>6.00000000</pre> <h3>入力例 2</h3> <pre>-100 7 5</pre> <h3>出力例 2</h3> <pre>43.60343043</pre> <h3>入力例 3</h3> <pre>756434182 9 10</pre> <h3>出力例 3</h3> <pre>15128783.80867078</pre> <hr> <address>Problem Setter: Flat35</address>
p01127
<h1>X-Ray Screening System</h1> <p> これは 20XX 年の話である.再生発電網による安定したエネルギー供給,および液化合成燃料の発明によって航空旅客数は鰻登りに増加した.しかし,航空機によるテロリズムの脅威は依然として存在するため,高速でかつ高い信頼性をもつ自動手荷物検査システムの重要性が高まっている.検査官が全部の荷物を調べることは実際問題として困難であることから,自動検査において疑わしいと判断された手荷物だけを検査官で改めて調べるという仕組みを整えたいわけである. </p> <p> 航空機業界からの要請を受け,国際客室保護会社(International Cabin Protection Company)では,新たな自動検査システムを開発するため,最近の旅客の手荷物について調査した.調査の結果,最近の旅客の手荷物には次のような傾向があることが判明した. <ul> <li>手荷物は 1 辺だけが短い直方体のような形状をしている.</li> <li>一般の乗客が手荷物に詰めて航空機に持ち込む品物としてはノートパソコン,音楽プレイヤー,携帯ゲーム機,トランプなどがあり,これらはいずれも長方形である.</li> <li>個々の品物は,その長方形の辺が手荷物の辺と平行になるように詰めこまれる.</li> <li>一方,テロリズムに用いられるような武器は,長方形とは非常に異なる形状をもつ.</li> </ul> <p> 上記の調査結果をふまえて,以下のような手荷物検査のためのモデルを考案した.それぞれの手荷物は X 線に対して透明である直方体の容器だとみなす.その中には X 線に対して不透明である複数の品物が入っている.ここで,直方体の 3 辺を x 軸,y 軸,z 軸とする座標系を考え,x 軸と平行な方向に X 線を照射して,y-z 平面に投影された画像を撮影する.撮影された画像は適当な大きさの格子に分割され,画像解析によって,それぞれの格子領域に映っている品物の材質が推定される.この会社には非常に高度の解析技術があり,材質の詳細な違いすらも解析することが可能であることから,品物の材質は互いに異なると考えることができる.なお,複数の品物が x 軸方向に関して重なっているときは,それぞれの格子領域について最も手前にある,すなわち x 座標が最小である品物の材質が得られる.また,2 つ以上の品物の x 座標が等しいことはないと仮定する. </p> <p> あなたの仕事は,画像解析の結果が与えられたときに,長方形ではない(武器であるかもしれない)品物が入っていることが断言できるか,あるいはその手荷物には長方形の品物以外のものは入っていないと推測されるかを判定するプログラムを作成することである. </p> <h3>Input</h3> <p> 入力の先頭行には単一の正の整数が含まれ,これはデータセットの個数を表す.それぞれのデータセットは次の形式で与えられる. <blockquote> <i>H</i> <i>W</i><br> 解析結果その1<br> 解析結果その2<br> ...<br> 解析結果その<i>H</i><br> </blockquote> <i>H</i> は画像の縦の大きさ,<i>W</i> は横の大きさを表す整数である (1 &lt;= <i>h</i> , <i>w</i> &lt;= 50).解析結果の各行は <i>W</i> 文字で構成されており,<i>i</i> 番目の文字は,行の左から <i>i</i> 番目にある格子領域における解析結果を表す.物質が検出された格子領域については,その材質が英大文字(A〜Z)によって表される.このとき,同じ材質であれば同じ文字が,また異なる材質であれば異なる文字が用いられる.物質が検出されなかった格子領域についてはドット(.)で表される. </p> <p> すべてのデータセットについて,材質の種類は 7 種類を超えないことが保証されている. </p> <h3>Output</h3> <p> それぞれのデータセットに対して,長方形以外の品物が確実に入っているときは「SUSPICIOUS」を,そうでないときは「SAFE」をそれぞれ 1 行に出力しなさい. </p> <h3>Sample Input</h3> <pre> 6 1 1 . 3 3 ... .W. ... 10 10 .......... .DDDDCCC.. .DDDDCCC.. .DDDDCCC.. ADDDDCCC.. AAA..CCC.. AAABBBBC.. AAABBBB... ..BBBBB... .......... 10 10 .......... .DDDDDD... .DDDDCCC.. .DDDDCCC.. ADDDDCCC.. AAA..CCC.. AAABBBBC.. AAABBBB... ..BBBBB... .......... 10 10 R..E..C.T. R.EEE.C.T. .EEEEE.... EEEEEEE... .EEEEEEE.. ..EEEEEEE. ...EEEEEEE ....EEEEE. .....EEE.. ......E... 16 50 .................................................. .........AAAAAAAAAAAAAAAA......................... ....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..... ....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..... ....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.... ....PPP..............AAAAA.AAAAAAAAAAAAAAAA....... ....PPP................A....AAA.AAAAAAAAAA........ ....PPP...........IIIIIAAIIAIII.AAAAAAAAAA........ ..CCCCCCCCCCCCC...IIIIIIAAAAAAAAAAAAAAAAAA........ ..CCCCCCCCCCCCC...IIIIIIIIIIIII...AAAAAAAAAA...... ....PPP............................AAAAAAAAAA..... MMMMPPPMMMMMMMMMMMMMMM.............AAAAAAAAAAA.... MMMMPPPMMMMMMMMMMMMMMM..............AAAAAAAAAAA... MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA... MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA... MMMMMMMMMMMMMMMMMMMMMM............................ </pre> <h3>Output for the Sample Input</h3> <pre> SAFE SAFE SAFE SUSPICIOUS SUSPICIOUS SUSPICIOUS </pre>
p01577
<H1><font color="#000">Problem H:</font> Magic Walls</H1> <p> You are a magician and have a large farm to grow magical fruits. </p> <p> One day, you saw a horde of monsters, approaching your farm. They would ruin your magical farm once they reached your farm. Unfortunately, you are not strong enough to fight against those monsters. To protect your farm against them, you decided to build magic walls around your land. </p> <p> You have four magic orbs to build the walls, namely, the orbs of Aquamarine (A), Bloodstone (B), Citrine (C) and Diamond (D). When you place them correctly and then cast a spell, there will be magic walls between the orbs A and B, between B and C, between C and D, and between D and A. The walls are built on the line segments connecting two orbs, and form a quadrangle as a whole. As the monsters cannot cross the magic walls, the inside of the magic walls is protected. </p> <p> Nonetheless, you can protect only a part of your land, since there are a couple of restrictions on building the magic walls. There are <i>N</i> hills in your farm, where the orbs can receive rich power of magic. Each orb should be set on the top of one of the hills. Also, to avoid interference between the orbs, you may not place two or more orbs at the same hill. </p> <p> Now, you want to maximize the area protected by the magic walls. Please figure it out. </p> <H2>Input</H2> <p> The input begins with an integer <i>N</i> (4 &le; <i>N</i> &le; 1500), the number of the hills. Then <i>N</i> line follow. Each of them has two integers <i>x</i> (0 &le; <i>x</i> &le; 50000) and <i>y</i> (0 &le; <i>y</i> &le; 50000), the <i>x</i>- and <i>y</i>-coordinates of the location of a hill. </p> <p> It is guaranteed that no two hills have the same location and that no three hills lie on a single line. </p> <H2>Output</H2> <p> Output the maximum area you can protect. The output value should be printed with one digit after the decimal point, and should be exact. </p> <H2>Sample Input 1</H2> <pre> 5 2 0 0 1 1 3 4 2 3 4 </pre> <H2>Output for the Sample Input 1</H2> <pre> 7.5 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 0 0 0 3 1 1 3 0 </pre> <H2>Output for the Sample Input 2</H2> <pre> 3.0 </pre>
p01824
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem G: Surface Area of Cubes </h2> <p> Taro likes a single player game "Surface Area of Cubes". </p> <p> In this game, he initially has an $A \times B \times C$ rectangular solid formed by $A \times B \times C$ unit cubes (which are all 1 by 1 by 1 cubes). The center of each unit cube is placed at 3-dimentional coordinates $(x, y, z)$ where $x$, $y$, $z$ are all integers ($0 \leq x \leq A-1, 0 \leq y \leq B -1, 0 \leq z \leq C - 1$). Then, $N$ distinct unit cubes are removed from the rectangular solid by the game master. After the $N$ cubes are removed, he must precisely tell the total surface area of this object in order to win the game. </p> <p> Note that the removing operation does not change the positions of the cubes which are not removed. Also, not only the cubes on the surface of the rectangular solid but also the cubes at the inside can be removed. Moreover, the object can be divided into multiple parts by the removal of the cubes. Notice that a player of this game also has to count up the surface areas which are not accessible from the outside. </p> <p> Taro knows how many and which cubes were removed but this game is very difficult for him, so he wants to win this game by cheating! You are Taro's friend, and your job is to make a program to calculate the total surface area of the object on behalf of Taro when you are given the size of the rectangular solid and the coordinates of the removed cubes. </p> <h3>Input</h3> <p> The input is formatted as follows. </p> <p> The first line of a test case contains four integers $A$, $B$, $C$, and $N$ ($1 \leq A, B, C \leq 10^8, 0 \leq N \leq $ min{$1,000, A \times B \times C - 1$}). </p> <p> Each of the next $N$ lines contains non-negative integers $x$, $y$, and $z$ which represent the coordinate of a removed cube. You may assume that these coordinates are distinct. </p> <h3>Output</h3> <p> Output the total surface area of the object from which the $N$ cubes were removed. </p> <h3>Sample Input</h3> <pre> 2 2 2 1 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 24 </pre> <h3>Sample Input</h3> <pre> 1 1 5 2 0 0 1 0 0 3 </pre> <h3>Output for the Sample Input</h3> <pre> 18 </pre> <h3>Sample Input</h3> <pre> 3 3 3 1 1 1 1 </pre> <h3>Output for the Sample Input</h3> <pre> 60 </pre>
p03819
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has decided to play a game, where the player runs a railway company. There are <var>M+1</var> stations on Snuke Line, numbered <var>0</var> through <var>M</var>. A train on Snuke Line stops at station <var>0</var> and every <var>d</var>-th station thereafter, where <var>d</var> is a predetermined constant for each train. For example, if <var>d = 3</var>, the train stops at station <var>0</var>, <var>3</var>, <var>6</var>, <var>9</var>, and so forth.</p> <p>There are <var>N</var> kinds of souvenirs sold in areas around Snuke Line. The <var>i</var>-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations <var>l_i</var>, <var>l_i+1</var>, <var>l_i+2</var>, <var>...</var>, <var>r_i</var>.</p> <p>There are <var>M</var> values of <var>d</var>, the interval between two stops, for trains on Snuke Line: <var>1</var>, <var>2</var>, <var>3</var>, <var>...</var>, <var>M</var>. For each of these <var>M</var> values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of <var>d</var> at station <var>0</var>. Here, assume that it is not allowed to change trains.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≦ N ≦ 3 × 10^{5}</var></li> <li><var>1 ≦ M ≦ 10^{5}</var></li> <li><var>1 ≦ l_i ≦ r_i ≦ M</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>l_1</var> <var>r_1</var> <var>:</var> <var>l_{N}</var> <var>r_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer in <var>M</var> lines. The <var>i</var>-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every <var>i</var>-th station.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 2 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 2 2 </pre> <ul> <li>If one takes a train stopping every station, three kinds of souvenirs can be purchased: kind <var>1</var>, <var>2</var> and <var>3</var>.</li> <li>If one takes a train stopping every second station, two kinds of souvenirs can be purchased: kind <var>1</var> and <var>2</var>.</li> <li>If one takes a train stopping every third station, two kinds of souvenirs can be purchased: kind <var>2</var> and <var>3</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 9 1 7 5 9 5 7 5 9 1 1 6 8 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 6 6 5 4 5 5 3 2 </pre></section> </div> </span>
p00736
<h1><font color="#000000">Problem C:</font> How can I satisfy thee? Let me count the ways...</h1> <!-- end en only --> <!-- begin en only --> <p> Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "true" are represented by 0, 1 and 2 respectively. </p><p> Let "-" be a unary operator (i.e. a symbol representing one argument function) and let both "*" and "+" be binary operators (i.e. symbols representing two argument functions). These operators represent negation (NOT), conjunction (AND) and disjunction (OR) respectively. These operators in three-valued logic can be defined in Table C-1. </p> <!-- end en only --> <CENTER> <!-- begin en only --> Table C-1: Truth tables of three-valued logic operators <!-- end en only --> <br> <TABLE> <TR align=center><TD>-X</TD><TD></TD><TD>(X*Y)</TD><TD></TD><TD>(X+Y)</TD><TR> <TR><TD><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008C1"></TD><TD></TD> <TD><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008C2"></TD><TD></TD> <TD><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008C3"></TD> <TD></TD></TR> </TABLE> </CENTER> <!-- begin en only --> <p> Let P, Q and R be variables ranging over three-valued logic values. For a given formula, you are asked to answer the number of triples (P,Q,R) that satisfy the formula, that is, those which make the value of the given formula 2. A formula is one of the following form (X and Y represent formulas). </p> <ul> <li> Constants: 0, 1 or 2 <li> Variables: P, Q or R <li> Negations: -X <li> Conjunctions: (X*Y) <li> Disjunctions: (X+Y) </ul> <p> Note that conjunctions and disjunctions of two formulas are always parenthesized. </p> <!-- end en only --> <p> <!-- begin en only --> For example, when formula (P*Q) is given as an input, the value of this formula is 2 when and only when (P,Q,R) is (2,2,0), (2,2,1) or (2,2,2). Therefore, you should output 3. <!-- end en only --> </p> <h3>Input</h3> <!-- begin en only --> <p> The input consists of one or more lines. Each line contains a formula. A formula is a string which consists of 0, 1, 2, P, Q, R, -, *, +, (, ). Other characters such as spaces are not contained. The grammar of formulas is given by the following BNF. </p> <!-- end en only --> <pre> &lt;formula&gt; ::= 0 | 1 | 2 | P | Q | R | -&lt;formula&gt; | (&lt;formula&gt;*&lt;formula&gt;) | (&lt;formula&gt;+&lt;formula&gt;) </pre> <!-- begin en only --> <p> All the formulas obey this syntax and thus you do not have to care about grammatical errors. Input lines never exceed 80 characters. </p><p> Finally, a line which contains only a "." (period) comes, indicating the end of the input. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> You should answer the number (in decimal) of triples (P,Q,R) that make the value of the given formula 2. One line containing the number should be output for each of the formulas, and no other characters should be output. </p> <!-- end en only --> <h3>Sample Input</h3> <PRE> (P*Q) (--R+(P*Q)) (P*-P) 2 1 (-1+(((---P+Q)*(--Q+---R))*(-R+-P))) . </PRE> <h3>Output for the Sample Input</h3> <PRE> 3 11 0 27 0 7 </PRE>
p00366
<H1>Electric Metronome</H1> <p> A boy PCK is playing with <var>N</var> electric metronomes. The <var>i</var>-th metronome is set to tick every <var>t_i</var> seconds. He started all of them simultaneously. </p> <p> He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from time to time in certain intervals. To explore this interesting phenomenon more fully, he is now trying to shorten the interval of ticking in unison by adjusting some of the metronomes’ interval settings. Note, however, that the metronomes do not allow any shortening of the intervals. </p> <p> Given the number of metronomes and their preset intervals <var>t_i</var> (sec), write a program to make the tick-in-unison interval shortest by adding a non-negative integer <var>d_i</var> to the current interval setting of the <var>i</var>-th metronome, and report the minimum value of the sum of all <var>d_i</var>. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>N</var> <var>t_1</var> <var>t_2</var> : <var>t_N</var> </pre> <p> The first line provides the number of metronomes <var>N</var> (1 &le; <var>N</var> &le; 10<sup>5</sup>). Each of the subsequent <var>N</var> lines provides the preset ticking interval <var>t_i</var> (1 &le; <var>t_i</var> &le; 10<sup>4</sup>) of the <var>i</var>-th metronome. </p> <h2>Output</h2> <p> Output the minimum value. </p> <h2>Sample Input 1</h2> <pre> 3 3 6 8 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <p> If we have three metronomes each with a ticking interval of 3, 6, and 8 seconds, respectively, simultaneous activation of these will produce a tick in unison every 24 seconds. By extending the interval by 1 second for the first, and 2 seconds for the second metronome, the interval of ticking in unison will be reduced to 8 seconds, which is the shortest possible for the system. </p> <h2>Sample Input 2</h2> <pre> 2 10 10 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre> <p> If two metronomes are both set to 10 seconds, then simultaneous activation will produce a tick in unison every 10 seconds, which is the shortest possible for this system. </p>
p00171
<H1>サイコロパズル</H1> <p> 各面にアルファベット一文字(a 〜 z、A 〜 Z)が描かれたサイコロがあります。 </p> <br><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/dice22Puzzle1"></center><br> <p> このようなサイコロを8つ組み合わせて 2 × 2 × 2 の立方体を作ることを考えます。 </p> <br><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/dice22Puzzle2"></center><br> <p> 組み合わせ方には条件があり、各サイコロの向き合う面は同じアルファベットでかつ一方が小文字、も う一方が大文字でなければなりません。例えば、a と描かれた面に接することができるのは A と描か れた面です。ただし、接するときの文字の向きは問いません。 </p> <br><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/dice22Puzzle3"></center><br> <p> このルールに従い、8つのサイコロの情報を入力とし、立方体を作れるか否かを判定するプログラムを作成してください。立方体を作れる場合は YES(半角英大文字)、作れない場合は NO(半角英大文字)と出力してください。 </p> <p> なお、サイコロの各面の文字を次の図にあるように <var>c1</var> 〜 <var>c6</var> と表すことにします。 また、1つのサイコロに同じ文字が複数回描かれていることは無いものとします(同じアルファベットの大文字と小文字はその限りではありません)。 </p> <br><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/dice22Puzzle4"></center><br> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>s<sub>1</sub></var> <var>s<sub>2</sub></var> : <var>s<sub>8</sub></var> </pre> <p> <var>i</var> 行目に <var>i</var> 個目のサイコロの情報 <var>s<sub>i</sub></var> が与えられます。<var>s<sub>i</sub></var> は長さ 6 の文字列であり <var>j</var> 文字目がサイコロの各面 <var>cj</var> に対応します。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> データセットごとに判定結果(半角英大文字)を1行に出力します。 </p> <H2>Sample Input</H2> <pre> zabZNq BCxmAi ZcbBCj aizXCm QgmABC JHzMop ImoXGz MZTOhp zabZnQ BCxmAi ZcbBCj aizXCm QgmABC JHzMop ImoXGz MZTOhp abcdef ABDCFE FBDCAE abcdef BEACDF bfcaed fabcde DEABCF UnivOf AizuaH zTXZYW piglIt GRULNP higGtH uAzIXZ FizmKZ UnivOf AizuaH piglIt higGtH GRULNP uAzIXZ FizmKZ ZTXzYW 0 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO YES YES NO </pre>
p00521
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1> JOI 紋章(JOI Emblem) </H1> <br/> <p> 情報オリンピック日本委員会では,台湾大会に向かう選手を応援するために新しいJOI 旗を作成することにした.<br> JOI 旗は,正方形が縦に $M$ 行,横に $N$ 列並んだ形をしており,各正方形には J,O,I のいずれかの文字が1 つずつ書かれている. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_joi_emblem_1"> </center><br><br> <p> 情報オリンピック日本委員会はJOI 旗とは別にJOI 紋章というものを決めている.JOI 紋章は,正方形が縦に2 行,横に2 列並んだ形をしており,各正方形にはJ,O,I のいずれかの文字が1 つずつ書かれている. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_joi_emblem_2"> </center><br><br> <p> JOI 旗に含まれるJOI 紋章の個数とは,JOI 旗に含まれる縦2 行,横2 列の領域のうち,その領域のJ,O,I の配置がJOI 紋章と(回転や裏返しをせずに) 一致しているものの個数のことである.条件を満たす縦2 行,横2 列の領域同士が重なっていてもそれらを別々に数えるものとする.<br> 情報オリンピック日本委員会は古いJOI 旗と1 枚の白紙を持っている.白紙はJOI 旗を構成する正方形1 個分の大きさで,J,O,I のうち好きな1 文字を書き込むことができる.情報オリンピック日本委員会は以下のいずれか1 つの操作をして,新しいJOI 旗を作成することにした. </p> <ul> <li>古いJOI 旗に対して何も操作せず,そのまま新しいJOI 旗とする.白紙は使用しない.</li> <li>白紙に1 文字書き込み,古いJOI 旗のいずれかの正方形に重ねて貼り付けることで古いJOI 旗のうち1 箇所を変更する.変更後のJOI 旗を新しいJOI 旗とする.</li> </ul> <p> 情報オリンピック日本委員会は新しいJOI 旗に含まれるJOI 紋章の個数をできるだけ多くしたいと思っている.あなたは新しいJOI 旗に含まれるJOI 紋章の個数の最大値を求めることになった. </p> <h2>課題</h2> <p> 古いJOI 旗とJOI 紋章の情報が与えられたとき,新しいJOI 旗に含まれるJOI 紋章の個数の最大値を求めるプログラムを作成せよ. </p> <h2>入力</h2> <p> 標準入力から以下のデータを読み込め. </p> <ul> <li>1 行目には2 個の整数 $M, N$ が空白を区切りとして書かれている.これはJOI 旗が正方形が縦に$M$行,横に$N$ 列並んだ形であることを表している.</li> <li>続く$M$ 行の各行には,それぞれ$N$ 文字からなる文字列が書かれている.各文字はJ,O,I のいずれかであり,$M$ 行のうち上から$i$ 行目$(1 \leq i \leq M)$ に書かれている文字列の左から$j$ 文字目$(1 \leq j \leq N)$は古いJOI 旗の上から$i$ 行目,左から$j$ 列目の正方形に書かれている文字を表す.</li> <li>続く2 行の各行には,それぞれ2 文字からなる文字列が書かれている.各文字はJ,O,I のいずれかであり,2 行のうち上から$i$ 行目$(1 \leq i \leq 2)$ に書かれている文字列の左から$j$ 文字目$(1 \leq j \leq 2)$ はJOI 紋章の上から$i$ 行目,左から$j$ 列目の正方形に書かれている文字を表す.</li> </ul> <h2>出力</h2> <p> 標準出力に,新しいJOI 旗に含まれるJOI 紋章の個数の最大値を表す整数を1 行で出力せよ. </p> <h2>制約</h2> <p> すべての入力データは以下の条件を満たす. </p> <ul> <li>$2 \leq M \leq 1000$</li> <li>$2 \leq N \leq 1000$</li> </ul> <h2>入出力例</h2> <h3>入力例 1 </h3> <pre> 3 5 JOIJO IJOOO IIJIJ JO IJ </pre> <h3>出力例 1 </h3> <pre> 3 </pre> <p> 古いJOI 旗とJOI 紋章は問題文中の例の通りである.上から2 行目,左から4 列目の正方形を白紙を用いてJ に変更すると,次のような形になる. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_joi_emblem_3"> </center><br><br> <p> このように変更した後のJOI 旗には次に示す3 箇所にJOI 紋章と同じ配置の領域がある. </p> <table> <tr> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_joi_emblem_4" width="80%"></td> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_joi_emblem_5" width="80%"></td> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_joi_emblem_6" width="80%"></td> </tr> </table> <p> JOI 紋章と同じ配置の領域が4 箇所以上となる新しいJOI 旗は存在しないので,新しいJOI 旗に含まれるJOI 紋章の個数の最大値は3 である. </p> <br> <h3>入力例 2 </h3> <pre> 2 6 JOJOJO OJOJOJ OJ JO </pre> <h3>出力例 2 </h3> <pre> 2 </pre> <p> 白紙を使用しなくても最大値が得られる場合があることに注意せよ. </p> <br> <h3>入力例 3 </h3> <pre> 2 2 JI IJ JJ JJ </pre> <h3>出力例 3 </h3> <pre> 0 </pre> <p> この入出力例の場合,考えられるどの新しいJOI 旗においても,JOI 紋章が1 つも含まれない. </p> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p01760
<h1>A : Taps / 蛇口</h1> <h1>Problem</h1> <p>あいづ君の家の浴槽には2つの蛇口 <em>A</em>, <em>B</em> がついており、 ひねるとひねった角度に比例した量の水が出てくる。 出てくる水の温度は <em>A</em> は <em>t<SUB>A</SUB></em> [℃]、<em>B</em> は <em>t<SUB>B</SUB></em> [℃]で一定である。 風呂に入るときにはそれらの量を調節して混ぜあわせることで適度な温度になるようにしている。</p> <p><em>t<SUB>A</SUB></em> [℃] の水 <em>v<SUB>A</SUB></em> [L] と <em>t<SUB>B</SUB></em> [℃]の水 <em>v<SUB>B</SUB></em> [L] を混ぜ合わせた後の温度は、(<em>t<SUB>A</SUB></em> × <em>v<SUB>A</SUB></em> + <em>t<SUB>B</SUB></em> × <em>v<SUB>B</SUB></em>) / (<em>v<SUB>A</SUB></em> + <em>v<SUB>B</SUB></em>) になる。 例えば、<em>t<SUB>A</SUB></em> = 80℃, <em>t<SUB>B</SUB></em> = 20℃ で 40℃ のお湯を張りたいときには、 <em>A</em> から 100mL/s 、 <em>B</em> から 200mL/s ずつ出るように蛇口を調節すればよい。</p> <p>ところが、このごろ蛇口が老朽化してきたため <em>A</em> は <em>d<SUB>A</SUB></em> [mL/s] 、<em>B</em> は <em>d<SUB>B</SUB></em> [mL/s] 単位でしか 出る水の量を調節できなくなってしまった。 すなわち、<em>A</em> から出る水の量が 0, <em>d<SUB>A</SUB></em>, 2×<em>d<SUB>A</SUB></em>, 3×<em>d<SUB>A</SUB></em>, ...[mL/s] という 飛び飛びの値にしか設定できなくなってしまったのである(<em>B</em> も同様)。</p> <p>あいづ君は長年培ってきた勘によって狙った温度ぴったりに 調節できたのだが、それが通用しなくなった。 困ったあいづ君は、自動的に目的の温度 <em>T</em>[℃] に最も近い温度になるような水の出し方に調節するプログラムを書くことにした。 ただし、毎秒出せる水の量には上限があり、 <em>A</em> と <em>B</em> の水の量の和は <em>D</em> [mL/s] 以下でなければならない。 また、水を出さないことにはお風呂に入れないため、毎秒出る水の量は最低でも 1mL/s 以上でなければならない。 つまり、 1 ≦ <em>A</em> から出る水の量 + <em>B</em> から出る水の量 ≦ <em>D</em> を満たす必要がある。</p> <h1>Input</h1> <p>入力は次のような形式で与えられる.</p> <p><em>T</em> <em>D</em><br><em>t<SUB>A</SUB></em> <em>t<SUB>B</SUB></em><br><em>d<SUB>A</SUB></em> <em>d<SUB>B</SUB></em></p> <p>1行目の <em>T</em>, <em>D</em> は、それぞれ目的の温度、水の量の上限を表す。 2行目の <em>t<SUB>A</SUB></em>, <em>t<SUB>B</SUB></em> は、それぞれ <em>A</em> の温度、 <em>B</em> の温度を表す。 3行目の <em>d<SUB>A</SUB></em>, <em>d<SUB>B</SUB></em> は、それぞれ <em>A</em> から出る水の量の単位、 <em>B</em> から出る水の量の単位を表す。</p> <h1>Constraints</h1> <ul> <li>入力は全て整数である。</li> <li>1 ≦ <em>T</em>, <em>t<SUB>A</SUB></em>, <em>t<SUB>B</SUB></em> ≦ 99</li> <li>1 ≦ <em>D</em> ≦ 1000</li> <li>1 ≦ <em>d<SUB>A</SUB></em>, <em>d<SUB>B</SUB></em> ≦ <em>D</em></li> </ul> <h1>Output</h1> <p><em>T</em> に最も近くなるように水を混ぜあわせた後の温度と<em>T</em> との差の大きさの最小値を1行で出力せよ。ただし、10<sup>-4</sup> 以下の誤差は許容される。</p> <h1>Samples</h1> <h2>Sample Input 1</h2> <pre>40 1000 80 20 100 100</pre> <h2>Sample Output 1</h2> <pre>0.0000000000</pre> <p>問題文の例である。</p> <h2>Sample Input 2</h2> <pre>38 1000 80 20 100 95</pre> <h2>Sample Output 2</h2> <pre>0.2222222222</pre> <p>Aの蛇口から 200mL/s、Bの蛇口から 475mL/s の量の水を出したとき、37.7777...℃ となり、これが38℃ に最も近くなる。</p>
p00872
<H1><font color="#000">Problem I:</font> Common Polynomial</H1> <p> Math teacher Mr. Matsudaira is teaching expansion and factoring of polynomials to his students. Last week he instructed the students to write two polynomials (with a single variable x), and to report GCM (greatest common measure) of them as a homework, but he found it boring to check their answers manually. So you are asked to write a program to check the answers. </p> <p> Hereinafter, only those polynomials with integral coefficients, called integral polynomials, are considered. </p> <p> When two integral polynomials <i>A</i> and <i>B</i> are given, an integral polynomial <i>C</i> is a common factor of <i>A</i> and <i>B</i> if there are some integral polynomials <i>X</i> and <i>Y</i> such that <i>A</i> = <i>CX</i> and <i>B</i> = <i>CY</i>. </p> <p> GCM of two integral polynomials is a common factor which has the highest degree (for <i>x</i>, here); you have to write a program which calculates the GCM of two polynomials. </p> <p> It is known that GCM of given two polynomials is unique when constant multiplication factor is ignored. That is, when <i>C</i> and <i>D</i> are both GCM of some two polynomials <i>A</i> and <i>B</i>, <i>p</i> &times <i>C</i> = <i>q</i> &times; <i>D</i> for some nonzero integers <i>p</i> and <i>q</i>. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset constitutes a pair of input lines, each representing a polynomial as an expression defined below. </p> <ol> <li> A <i>primary</i> is a variable x, a sequence of digits 0 - 9, or an expression enclosed within ( ... ). Examples: <pre>x, 99, (x+1)</pre></li> <li> A <i>factor</i> is a primary by itself or a primary followed by an exponent. An exponent consists of a symbol ^ followed by a sequence of digits 0 - 9. Examples: <pre>x^05, 1^15, (x+1)^3</pre></li> <li> A <i>term</i> consists of one or more adjoining factors. Examples: <pre>4x, (x+1)(x-2), 3(x+1)^2</pre></li> <li> An <i>expression</i> is one or more terms connected by either + or -. Additionally, the first term of an expression may optionally be preceded with a minus sign -. Examples: <pre>-x+1, 3(x+1)^2-x(x-1)^2</pre></li> </ol> <p> Integer constants, exponents, multiplications (adjoining), additions (+) and subtractions/negations (-) have their ordinary meanings. A sequence of digits is always interpreted as an integer con- stant. For example, 99 means 99, not 9 &times; 9. </p> <p> Any subexpressions of the input, when fully expanded normalized, have coefficients less than 100 and degrees of x less than 10. Digit sequences in exponents represent non-zero values. </p> <p> All the datasets are designed so that a standard algorithm with 32-bit two’s complement integers can solve the problem without overflows. </p> <p> The end of the input is indicated by a line containing a period. </p> <H2>Output</H2> <p> For each of the dataset, output GCM polynomial expression in a line, in the format below. </p> <pre> <i>c</i><sub>0</sub>x^<i>p</i><sub>0</sub> &plusmn; <i>c</i><sub>1</sub>x^<i>p</i><sub>1</sub> ... &plusmn <i>c</i><sub><i>n</i></sub>x^<i>p</i><sub><i>n</i></sub> </pre> <p> Where <i>c</i><sub><i>i</i></sub> and <i>p</i><sub><i>i</i></sub> (<i>i</i> = 0, . . . , <i>n</i>) are positive integers with <i>p</i><sub>0</sub> &gt; <i>p</i><sub>1</sub> &gt; . . . &gt; <i>p</i><sub><i>n</i></sub>, and the greatest common divisor of {<i>c</i><sub><i>i</i></sub> | <i>i</i> = 0, . . . , <i>n</i>} is 1. </p> <p> Additionally: </p> <ol> <li> When <i>c</i><sub><i>i</i></sub> is equal to 1, it should be omitted unless corresponding <i>p</i><sub><i>i</i></sub> is 0,</li> <li> x^0 should be omitted as a whole, and</li> <li> x^1 should be written as x.</li> </ol> </p> <H2>Sample Input</H2> <pre> -(x^3-3x^2+3x-1) (x-1)^2 x^2+10x+25 x^2+6x+5 x^3+1 x-1 . </pre> <H2>Output for the Sample Input</H2> <pre> x^2-2x+1 x+5 1 </pre>
p01330
<h1><font color="#000">Problem J:</font> 多項式の解の個数</h1> <p>きたまさ君は大学でさまざまな変換について研究している。最近、きたまさ君が興味を持っている変換は次のようなものである。 N+1個の整数 a<sub>0</sub>, ..., a<sub>N</sub> を固定し、整数 z を入力とする。また P を素数とする。</p> <blockquote> t = ( a<sub>N</sub>z<sup>N</sup> + a<sub>N-1</sub>z<sup>N-1</sup> + ... + a<sub>2</sub>z<sup>2</sup> + a<sub>1</sub>z + a<sub>0</sub> ) mod P </blockquote> <p>きたまさ君はこの変換によって t = 0 になってしまう z がいくつもあることに気がついた。 そこで、きたまさ君は友人でありスーパープログラマーでもあるあなたに、変換後に t = 0 になる z が 0〜P-1 にいくつあるかを計算してもらうことにした。 </p> <h2>Input</h2> <p>入力は次の形式で与えられる。</p> <pre>N P a<sub>0</sub> a<sub>1</sub> ... a<sub>N</sub> </pre> <p>入力の1行目には整数Nと素数Pがスペース文字で区切られて与えられる。これらは、問題文で与えられたとおりである。 0 &le; N &le; 100, 2 &le; P &le; 10<sup>9</sup> を満たす。</p> <p>次の1行には a<sub>0</sub>〜a<sub>N</sub> がスペース文字で区切られて与えられる。これらは |a<sub>i</sub>| &le; 10<sup>9</sup> を満たす整数である。また a<sub>N</sub> &ne; 0 である。 </p> <h2>Output</h2> <p>変換後に0になるような z (0 &le; z &lt; P) の個数を出力せよ。 </p> <h2>Notes on Test Cases</h2> <p> 上記入力形式で複数のデータセットが与えられます。各データセットに対して上記出力形式で出力を行うプログラムを作成して下さい。 </p> <p> N, P がともに 0 のとき入力の終わりを示します。 </p> <!-- <h2>Sample Input 1</h2> <pre> 2 3 1 2 1 </pre> <h2>Output for Sample Input 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 2 3 1 2 6 </pre> <h2>Output for Sample Input 2</h2> <pre> 1 </pre> --> <h2>Sample Input </h2> <pre> 2 3 1 2 1 2 3 1 2 6 0 0 </pre> <h2>Output for Sample Input </h2> <pre> 1 1 </pre>
p03618
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have a string <var>A = A_1 A_2 ... A_n</var> consisting of lowercase English letters.</p> <p>You can choose any two indices <var>i</var> and <var>j</var> such that <var>1 \leq i \leq j \leq n</var> and reverse substring <var>A_i A_{i+1} ... A_j</var>.</p> <p>You can perform this operation at most once.</p> <p>How many different strings can you obtain?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |A| \leq 200,000</var></li> <li><var>A</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>A</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of different strings you can obtain by reversing any substring in <var>A</var> at most once.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>aatt </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>You can obtain <code>aatt</code> (don't do anything), <code>atat</code> (reverse <var>A[2..3]</var>), <code>atta</code> (reverse <var>A[2..4]</var>), <code>ttaa</code> (reverse <var>A[1..4]</var>) and <code>taat</code> (reverse <var>A[1..3]</var>).</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>xxxxxxxxxx </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>Whatever substring you reverse, you'll always get <code>xxxxxxxxxx</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>abracadabra </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>44 </pre></section> </div> </span>
p01625
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <!-- <h3><u>Princess Tetra’s Puzzle</u></h3> --> <!-- end en only --> <!-- begin ja only --> <h1><u>テトラ姫のパズル</u></h1> <!-- end ja only --> <!-- begin en only --> <!-- <p> English text is not available in this practice contest. </p> --> <!-- end en only --> <!-- begin ja only --> <p> パレス王国のテトラ姫は無類のパズル好きとして知られており,最近は自身が考案した「テトラパズル」に熱中している. これは,正三角形のマスを敷き詰めたボードと,テトラブロックと呼ばれる 4 枚の正三角形のパネルからなる正四面体のブロックを使ったパズルである. パズルの目的は,ボード上のすべてのテトラブロックを以下の条件をみたすように展開することである.<br> </p> <ul> <li>展開されたテトラブロックが,置かれていたマスおよび,それぞれに指定された異なる 2 つのマスを覆っている</li> <li>どのマスも,2 つ以上のパネルで覆われていない</li> </ul> <p> 図F-1はテトラパズルの問題例および,その解答例である. ★のマスと●のマスにテトラブロックが置かれており,それぞれが☆のマスと○のマスを覆うように指定されている. 解答例において,横線が引かれたマスは★のマスに置かれていたテトラブロックを展開して覆ったマス,縦線のマスは●のマスに置かれたテトラブロックで覆ったマスである.<br> </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_exampleA" height="228" width="528"> </center> </center> <center> <p> <i>図 F-1: テトラパズルの問題例(左)および解答例(右)</i> </p> </center> <p> 図F-2は,上図の問題例における無効な解答例である. 左の例では★のマスの真上のマスが2つのパネルで覆われており,右の例ではそれぞれがテトラブロックを展開して得られる形状でないため,答えとしては認められない. </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_exampleB" height="228" width="528"> </center> </center> <center> <p> <i>図 F-2: 無効な解答例</i> </p> </center> <p> テトラ姫はパズルの面白さを多くの人に知ってもらうべく,来たる夏の祭典に向けてパズルの問題集を作った. そして,王国で二番目のパズル好きとして姫から信頼を置かれているあなたは,問題集のチェック担当に任命された.<br> </p> <p> さて,チェック作業を進めていたあなたは困った事に気が付いた. 問題集には解が存在しないパズルが含まれているようなのだ. なるべく姫の作ったパズルを尊重したいと考えたあなたは,解が存在しないパズルについて,どれか 1 個のテトラブロックをそのテトラブロックが覆うべきマスの情報ごと削除することで,パズルを解けるものに変えることにした. 姫から言い渡されたチェックの締切りまではあと3時間しかない. 問題集を見なおして,手早く修正を済ませてしまおう. </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は複数のデータセットから構成される. 各データセットの形式は次の通りである.<br> </p> <pre> <var>n</var> <var>x<sub>1a</sub></var> <var>y<sub>1a</sub></var> <var>x<sub>1b</sub></var> <var>y<sub>1b</sub></var> <var>x<sub>1c</sub></var> <var>y<sub>1c</sub></var> <var>x<sub>2a</sub></var> <var>y<sub>2a</sub></var> <var>x<sub>2b</sub></var> <var>y<sub>2b</sub></var> <var>x<sub>2c</sub></var> <var>y<sub>2c</sub></var> <var>...</var> <var>x<sub>na</sub></var> <var>y<sub>na</sub></var> <var>x<sub>nb</sub></var> <var>y<sub>nb</sub></var> <var>x<sub>nc</sub></var> <var>y<sub>nc</sub></var> </pre> <p> n (2 &#8804; n &#8804; 5,000) はボードに置かれたテトラブロックの数を表す整数である. 各テトラブロックには 1 から n の番号が割り当てられている.<br> </p> <p> 続く n 行は,それぞれ 1 個のスペースで区切られた 6 個の整数からなる. (x<sub>ia</sub>, y<sub>ia</sub>) は i 番目のテトラブロックが置かれているマスの座標を表し,(x<sub>ib</sub>, y<sub>ib</sub>) および,(x<sub>ic</sub>, y<sub>ic</sub>) は,それぞれ i 番目のテトラブロックを展開した時に覆うべきマスの座標を表す. 与えられる x 座標および y 座標の絶対値は 20,000 以下と仮定して良い. また,与えられる座標は全て互いに異なると仮定して良い. すなわち,同じマスに 2 個以上のテトラブロックが置かれる事や,テトラブロックが置かれているマスが覆うべきマスとして指定される事や,覆うべきマスが重複して指定される事はない.<br> </p> <p> 各マスには図F-3のように座標が割り当てられている.<br> </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_triangle" height="340" width="310"> </center> </center> <center> <p> <i>図 F-3: マスに割り当てられた座標</i> </p> </center> <p> n=0 は入力の終わりを示す.これはデータセットには含めない.<br> </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各データセットについて,テトラブロックを除くことなくパズルが解ける場合は Valid をそれぞれ 1 行に出力しなさい. テトラブロックを 1 個だけ除くことでパズルが解けるようになる場合は Remove を 1 行に出力し,続けて除くことでパズルが解けるようになるテトラブロックの番号を小さいものから順にそれぞれ 1 行に出力しなさい. 2 個以上のテトラブロックを除かないとパズルが解けるようにならない場合は Invalid を1行に出力しなさい. </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 3 2 3 2 2 2 1 2 0 1 -1 2 -1 -2 -1 -1 -1 -2 0 6 -1 0 1 0 0 -1 -2 -1 -3 -2 -4 -2 2 -1 2 0 1 -1 4 -2 3 -2 3 -1 1 1 0 1 -1 1 -3 -1 -1 -1 -2 0 5 -1 2 0 2 1 2 -3 1 -2 1 -2 2 -2 0 -2 -1 -3 0 1 -1 0 -1 -1 -1 1 0 2 0 2 -1 4 -2 0 -2 -1 -3 -1 -1 -1 0 -1 1 -1 2 -1 2 0 3 -1 -1 0 0 0 1 0 5 -2 1 3 -1 2 1 -5 2 -5 3 -4 2 -2 -1 0 -1 -3 -1 4 2 5 2 5 3 1 -1 2 -1 -1 -1 0 </pre> <!-- begin ja only --> <p> 以下の図はそれぞれサンプルの配置を示している. </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_sample0" height="232" width="213"> </center> </center> <center> <p> <i>図 F-4: 1番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_sample1" height="225" width="382"> </center> </center> <center> <p> <i>図 F-5: 2番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_sample2" height="223" width="287"> </center> </center> <center> <p> <i>図 F-6: 3番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_sample3" height="114" width="319"> </center> </center> <center> <p> <i>図 F-7: 4番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_princessTetraPuzzle_sample4" height="278" width="382"> </center> </center> <center> <p> <i>図 F-8: 5番目のサンプル</i> </p> </center> <!-- end ja only --> <h3>Output for Sample Input</h3> <pre> Remove 1 Remove 2 6 Valid Remove 1 2 3 4 Invalid </pre> <!-- begin ja only --> <!-- end ja only -->
p00937
<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 C Sibling Rivalry</h2> <p> You are playing a game with your elder brother. </p> <p> First, a number of circles and arrows connecting some pairs of the circles are drawn on the ground. Two of the circles are marked as the <i>start circle</i> and the <i>goal circle</i>. </p> <p> At the start of the game, you are on the start circle. In each <i>turn</i> of the game, your brother tells you a number, and you have to take that number of <i>steps</i>. At each step, you choose one of the arrows outgoing from the circle you are on, and move to the circle the arrow is heading to. You can visit the same circle or use the same arrow any number of times. </p> <p> Your aim is to stop on the goal circle after the fewest possible turns, while your brother's aim is to prevent it as long as possible. Note that, in each single turn, you <i>must</i> take the exact number of steps your brother tells you. Even when you visit the goal circle during a turn, you have to leave it if more steps are to be taken. </p> <p> If you reach a circle with no outgoing arrows before completing all the steps, then you lose the game. You also have to note that, your brother may be able to repeat turns forever, not allowing you to stop after any of them. </p> <p> Your brother, mean but not too selfish, thought that being allowed to choose arbitrary numbers is not fair. So, he decided to declare three numbers at the start of the game and to use only those numbers. </p> <p> Your task now is, given the configuration of circles and arrows, and the three numbers declared, to compute the smallest possible number of turns within which you can always nish the game, no matter how your brother chooses the numbers. </p> <h3>Input</h3> <p> The input consists of a single test case, formatted as follows.<br> <br> $n$ $m$ $a$ $b$ $c$<br> $u_1$ $v_1$<br> ...<br> $u_m$ $v_m$<br> <br> All numbers in a test case are integers. $n$ is the number of circles $(2 \leq n \leq 50)$. Circles are numbered 1 through $n$. The start and goal circles are numbered 1 and $n$, respectively. $m$ is the number of arrows $(0 \leq m \leq n(n - 1))$. $a$, $b$, and $c$ are the three numbers your brother declared $(1 \leq a, b, c \leq 100)$. The pair, $u_i$ and $v_i$, means that there is an arrow from the circle $u_i$ to the circle $v_i$. It is ensured that $u_i \ne v_i$ for all $i$, and $u_i \ne u_j$ or $v_i \ne v_j$ if $i \ne j$. </p> <h3>Output</h3> <p> Print the smallest possible number of turns within which you can always finish the game. Print <span>IMPOSSIBLE</span> if your brother can prevent you from reaching the goal, by either making you repeat the turns forever or leading you to a circle without outgoing arrows. </p> <h3>Sample Input 1</h3> <pre>3 3 1 2 4 1 2 2 3 3 1</pre> <h3>Sample Output 1</h3> <pre>IMPOSSIBLE</pre> <h3>Sample Input 2</h3> <pre>8 12 1 2 3 1 2 2 3 1 4 2 4 3 4 1 5 5 8 4 6 6 7 4 8 6 8 7 8</pre> <h3>Sample Output 2</h3> <pre>2</pre> <p> For Sample Input 1, your brother may choose 1 first, then 2, and repeat these forever. Then you can never finish. </p> <p> For Sample Input 2 (Figure C.1), if your brother chooses 2 or 3, you can finish with a single turn. If he chooses 1, you will have three options. </p> <ul> <li> Move to the circle 5. This is a bad idea: Your brother may then choose 2 or 3 and make you lose.</li> <li> Move to the circle 4. This is the best choice: From the circle 4, no matter any of 1, 2, or 3 your brother chooses in the next turn, you can finish immediately.</li> <li>Move to the circle 2. This is not optimal for you. If your brother chooses 1 in the next turn, you cannot finish yet. It will take three or more turns in total.</li> </ul> <p> In summary, no matter how your brother acts, you can finish within two turns. Thus the answer is 2. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_SiblingRivalry"><br> <p>Figure C.1. Sample Input 2</p> </center>
p03248
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>s</var> of length <var>n</var>. Does a tree with <var>n</var> vertices that satisfies the following conditions exist?</p> <ul> <li>The vertices are numbered <var>1,2,..., n</var>.</li> <li>The edges are numbered <var>1,2,..., n-1</var>, and Edge <var>i</var> connects Vertex <var>u_i</var> and <var>v_i</var>.</li> <li>If the <var>i</var>-th character in <var>s</var> is <code>1</code>, we can have a connected component of size <var>i</var> by removing one edge from the tree.</li> <li>If the <var>i</var>-th character in <var>s</var> is <code>0</code>, we cannot have a connected component of size <var>i</var> by removing any one edge from the tree.</li> </ul> <p>If such a tree exists, construct one such tree.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq n \leq 10^5</var></li> <li><var>s</var> is a string of length <var>n</var> consisting of <code>0</code> and <code>1</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If a tree with <var>n</var> vertices that satisfies the conditions does not exist, print <code>-1</code>.</p> <p>If a tree with <var>n</var> vertices that satisfies the conditions exist, print <var>n-1</var> lines. The <var>i</var>-th line should contain <var>u_i</var> and <var>v_i</var> with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>-1 </pre> <p>It is impossible to have a connected component of size <var>n</var> after removing one edge from a tree with <var>n</var> vertices.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1110 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 2 3 3 4 </pre> <p>If Edge <var>1</var> or Edge <var>3</var> is removed, we will have a connected component of size <var>1</var> and another of size <var>3</var>. If Edge <var>2</var> is removed, we will have two connected components, each of size <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1010 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 1 3 1 4 </pre> <p>Removing any edge will result in a connected component of size <var>1</var> and another of size <var>3</var>.</p></section> </div> </span>
p01275
<H1><font color="#000">Problem C:</font> Dial Lock</H1> <p> A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened. </p> <p> You are working at a manufacturer of dial locks. Your job is to verify that every manufactured lock is unlocked by its unlocking sequence. In other words, you have to rotate many dials of many many locks. </p> <p> It’s a very hard and boring task. You want to reduce time to open the locks. It’s a good idea to rotate multiple dials at one time. It is, however, a difficult problem to find steps to open a given lock with the fewest rotations. So you decided to write a program to find such steps for given initial and unlocking sequences. </p> <p> Your company’s dial locks are composed of vertically stacked k (1 &le; <i>k</i> &le; 10) cylindrical dials. Every dial has 10 numbers, from 0 to 9, along the side of the cylindrical shape from the left to the right in sequence. The neighbor on the right of 9 is 0. </p> <p> A dial points one number at a certain position. If you rotate a dial to the left by <i>i</i> digits, the dial newly points the <i>i</i>-th right number. In contrast, if you rotate a dial to the right by <i>i</i> digits, it points the <i>i</i>-th left number. For example, if you rotate a dial pointing 8 to the left by 3 digits, the dial newly points 1. </p> <p> You can rotate more than one adjacent dial at one time. For example, consider a lock with 5 dials. You can rotate just the 2nd dial. You can rotate the 3rd, 4th and 5th dials at the same time. But you cannot rotate the 1st and 3rd dials at one time without rotating the 2nd dial. When you rotate multiple dials, you have to rotate them to the same direction by the same digits. </p> <p> Your program is to calculate the fewest number of rotations to unlock, for given initial and unlocking sequences. Rotating one or more adjacent dials to the same direction by the same digits is counted as one rotation. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each datset consists of two lines. The first line contains an integer k. The second lines contain two strings, separated by a space, which indicate the initial and unlocking sequences. </p> <p> The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the minimum number of rotations in one line. </p> <H2>Sample Input</H2> <pre> 4 1357 4680 6 777777 003330 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 </pre>
p00034
<H1>鉄道路線</H1> <p> 複線(上りと下りが別の線路になっていてどこででもすれ違える)の鉄道路線があります。この路線には終端駅を含めて11 の駅があり、それぞれの駅と駅の間は図で示す区間番号で呼ばれています。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_railway"> </center> <br/> <p> この路線の両方の終端駅から列車が同時に出発して、途中で停まらずに走ります。各区間の長さと2 本の列車の速度を読み込んで、それぞれの場合について列車がすれ違う区間の番号を出力するプログラムを作成してください。ただし、ちょうど駅のところですれ違う場合は、両側の区間番号のうち小さいほうの数字を出力します。また、列車の長さ、駅の長さは無視できるものとします。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられる。各データセットは以下のような形式で与えられる。 </p> <pre> <var>l<sub>1</sub></var>,<var>l<sub>2</sub></var>,<var>l<sub>3</sub></var>,<var>l<sub>4</sub></var>,<var>l<sub>5</sub></var>,<var>l<sub>6</sub></var>,<var>l<sub>7</sub></var>,<var>l<sub>8</sub></var>,<var>l<sub>9</sub></var>,<var>l<sub>10</sub></var>,<var>v<sub>1</sub></var>,<var>v<sub>2</sub></var> </pre> <p> <var>l<sub>i</sub></var> (1 &le; <var>l<sub>i</sub></var> &le; 2,000) は区間 <var>i</var> の長さ(km)を表す整数である。<var>v<sub>1</sub></var> は区間 1 側の終端駅を出発した列車の速度(km/h)、<var>v<sub>2</sub></var> は区間 10 側の終端駅を出発した列車の速度(km/h)を表す整数である (1 &le; <var>v<sub>1</sub></var>, <var>v<sub>2</sub></var> &le; 2,000)。 </p> <p> データセットの数は 50 を超えない。 </p> <H2>Output</H2> <p> データセットごとに、列車がすれちがう区間の番号を1行に出力する。 </p> <H2>Sample Input</H2> <pre> 1,1,1,1,1,1,1,1,1,1,40,60 1,1,1,1,1,3,3,3,3,3,50,50 10,10,10,10,10,10,10,10,10,10,50,49 </pre> <H2>Output for the Sample Input</H2> <pre> 4 7 6 </pre>
p02009
<h1>Problem F. Nim without Zero</h1> <!-- Time Limit: 2 sec Memory Limit: 512 MB --> <p> Alice: "Hi, Bob! Let's play Nim!"<br> Bob: "Are you serious? I don't want to play it. I know how to win the game."<br> Alice: "Right, there is an algorithm to calculate the optimal move using XOR. How about changing the rule so that a player loses a game if he or she makes the XOR to $0$?"<br> Bob: "It sounds much better now, but I suspect you know the surefire way to win."<br> Alice: "Do you wanna test me?"<br> This game is defined as follows.<br> </p> <ol> <li> The game starts with $N$ heaps where the $i$-th of them consists of $a_i$ stones.</li> <li> A player takes any positive number of stones from any single one of the heaps in one move.</li> <li> Alice moves first. The two players alternately move.</li> <li> If the XOR sum, $a_1$ XOR $a_2$ XOR $...$ XOR $a_N$, of the numbers of remaining stones of these heaps becomes $0$ as a result of a player's move, the player loses.</li> </ol> <p> Your task is to find which player will win if they do the best move. </p> <h2>Input</h2> <p> The input consists of a single test case in the format below. </p> <pre> $N$ $a_1$ $\vdots$ $a_N$ </pre> <p> The first line contains an integer $N$ which is the number of the heaps ($1 \leq N \leq 10^5$). Each of the following $N$ lines gives the number of stones in each heap ($1 \leq a_i \leq 10^9$). </p> <h2>Output</h2> <p> Output the winner, Alice or Bob, when they do the best move. </p> <h2>Examples</h2> <h2>Sample Input 1</h2> <pre> 2 1 1 </pre> <h2>Output for Sample Input 1</h2> <pre> Alice </pre> <h2>Sample Input 2</h2> <pre> 5 1 2 3 4 5 </pre> <h2>Output for Sample Input 2</h2> <pre> Bob </pre> <h2>Sample Input 3</h2> <pre> 10 1 2 3 4 5 6 7 8 9 10 </pre> <h2>Output for Sample Input 3</h2> <pre> Alice </pre> <p> In the first example, the XOR sum is 0 in the initial state, but the game is going because nobody moves yet. First Alice takes a stone and the XOR sum becomes 1, then Bob takes the last stone and the XOR sum becomes 0. Therefore, Alice will win, and Bob will lose. </p>
p00464
<H1> 散歩 </H1> <h2>問題</h2> <p> JOI 町に住む太郎君は, ある日,健康増進のために散歩を日課にしようと思い立った. 太郎君の住む JOI 町には,図のように,東西方向に走る (<i>H</i> + 1) 本の道路と,南北 方向に走る (<i>W</i> + 1) 本の道路が碁盤目状に通っている.太郎君の家はもっとも北西の 交差点にあり,ここから散歩を開始する. </p> <p> 以降,北から <i>a</i> 番目,西から <i>b</i> 番目の交差点を (<i>a</i>, <i>b</i>) で表す.たとえば,太郎君の家がある交差点は (1, 1) である. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_sanpo1"> <p> 図: JOI 町の図 (<i>H</i> = 3, <i>W</i> = 4 の場合).図の上が北,左が西に対応する. </p> </center> <p> 太郎君は,散歩のルートが日々違ったほうが面白いと考えたので,(1, 1) から (<i>H</i>, <i>W</i>) までの <i>H</i> &times; <i>W</i> 個の交差点に, 「東」または「南」の文字を書き,次のようなルールに従って毎日散歩を行うことにした. </p> <ul> <li> 文字の書かれた交差点にいる場合,その交差点に書かれている文字が「東」な ら「南」に, 「南」なら「東」に文字を書き換え,もともと書かれていた文字の方角にある次の交差点まで進む.</li> <li> もっとも東やもっとも南の道路に到達したら散歩を終了する.</li> </ul> <p> この計画を考えた後,太郎君は,将来の散歩で自分がどのようなルートをたどる ことになるのかが気になった.太郎君のために,太郎君の <i>N</i> 回目の散歩のルートを 予測するプログラムを作成せよ. </p> <h2>入力</h2> <p> <!-- 入力ファイルのファイル名は input.txt である.<br>--> 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. </p> <p> 1 行目には,3 つの正整数が空白区切りで書かれている.これらは,問題文中の 3 つの数値 <i>H</i>, <i>W</i>, <i>N</i> の値である. <i>H</i>, <i>W</i>, <i>N</i> はそれぞれ, 1 &le; <i>H</i> &le; 1000, 1 &le; <i>W</i> &le; 1000, 1 &le; <i>N</i> &le; 10000000 = 10<sup>7</sup> をみたす. 2 行目から <i>H</i> + 1 行目には,それぞれ <i>W</i> 個の整数が空白区切りで書かれている.これらは,太郎君が最初に交差点に書いた文字の情報を表す. <i>i</i> + 1 行目の <i>j</i> 番目の整数が 0 なら,交差点 (<i>i</i>, <i>j</i>) に書かれた文字が「南」であることを, 1 なら, 交差点 (<i>i</i>, <i>j</i>) に書かれた文字が「東」であることを表す. </p> <p> 採点用データのうち,配点の 30%分については, <i>H</i> &le; 100, <i>W</i> &le; 100, <i>N</i> &le; 1000 を満たす. </p> <p> <i>H</i>, <i>W</i>, <i>N</i> がすべて 0 のとき入力の終了を示す. データセットの数は 10 を超えない. </p> <h2>出力</h2> <p> <!-- 出力ファイルのファイル名は output.txt である.<br>--> データセットごとに次の形式で出力する.<br> <i>N</i> 回目の散歩において太郎君が散歩を終了する交差点が (<i>i</i>, <i>j</i>) のとき,<i>i</i> と <i>j</i> をこの順に空白で区切って出力せよ. </p> <h2>入出力の例</h2> <h3>入力例</h3> <pre> 3 4 3 1 0 1 1 0 1 0 0 1 0 1 0 0 0 0 </pre> <h3>出力例</h3> <pre> 1 5 </pre> <p> 上の例では,1 回目から 3 回目の散歩のルートは次の図のようになる. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_sanpo2"> </center> <br> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p02459
<h1>Map: Search</h1> <p> For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that <u>each key in $M$ must be unique</u>. </p> <ul> <li>insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$. If there is an element with $key$, replace the corresponding value with $x$.</li> <li>get($key$): Print the value with the specified $key$.</li> </ul> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $q$ $query_1$ $query_2$ : $query_q$ </pre> <p> Each query $query_i$ is given by </p> <pre> 0 $key$ $x$ </pre> <p>or</p> <pre> 1 $key$ </pre> <p> where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent insert and get operations respectively. </p> <h2>Output</h2> <p> For each get operation, print an integer in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq q \leq 200,000$</li> <li>$1 \leq x \leq 1,000,000,000$</li> <li>$1 \leq $ length of $key$ $ \leq 20$ </li> <li>$key$ consits of lower-case letter</li> <li>For a get operation, the element with the specified key exists in $M$.</li> </ul> <h2>Sample Input 1</h2> <pre> 7 0 blue 4 0 red 1 0 white 5 1 red 1 blue 0 black 8 1 black </pre> <h2>Sample Output 1</h2> <pre> 1 4 8 </pre>