question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01822
<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> <h3>Problem E: Enclose Points</h3> <p> There are $N$ points and $M$ segments on the $xy$-plane. Each segment connects two of these points and they don't intersect each other except at the endpoints. You are also given $Q$ points as queries. Your task is to determine for each query point whether you can make a polygon that encloses the query point using some of the given segments. Note that the polygon should not necessarily be convex. </p> <h3>Input</h3> <p> Each input is formatted as follows.<br> <br> $N$ $M$ $Q$<br> $x_1$ $y_1$<br> ...<br> $x_N$ $y_N$<br> $a_1$ $b_1$<br> ...<br> $a_M$ $b_M$<br> $qx_1$ $qy_1$<br> ...<br> $qx_Q$ $qy_Q$<br> <br> </p> <p> The first line contains three integers $N$ ($2 \leq N \leq 100,000$), $M$ ($1 \leq M \leq 100,000$), and $Q$ ($1 \leq Q \leq 100,000$), which represent the number of points, the number of segments, and the number of queries, respectively. Each of the following $N$ lines contains two integers $x_i$ and $y_i$ ($-100,000 \leq x_i, y_i \leq 100,000$), the coordinates of the $i$-th point. The points are guaranteed to be distinct, that is, $(x_i, y_i) \ne (x_j, y_j)$ when $i \ne j$. Each of the following $M$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i < b_i \leq N$), which indicate that the $i$-th segment connects the $a_i$-th point and the $b_i$-th point. Assume that those segments do not intersect each other except at the endpoints. Each of the following $Q$ lines contains two integers $qx_i$ and $qy_i$ ($-100,000 \leq qx_i, qy_i \leq 100,000$), the coordinates of the $i$-th query point. </p> <p> You can assume that, for any pair of query point and segment, the distance between them is at least $10^{-4}$. </p> <h3>Output</h3> <p> The output should contain $Q$ lines. Print "Yes" on the $i$-th line if there is a polygon that contains the $i$-th query point. Otherwise print "No" on the $i$-th line. </p> <h3>Sample Input</h3> <pre> 4 5 3 -10 -10 10 -10 10 10 -10 10 1 2 1 3 1 4 2 3 3 4 -20 0 1 0 20 0 </pre> <h3>Output for the Sample Input</h3> <pre> No Yes No </pre> <h3>Sample Input</h3> <pre> 8 8 5 -20 -20 20 -20 20 20 -20 20 -10 -10 10 -10 10 10 -10 10 1 2 1 4 2 3 3 4 5 6 5 8 6 7 7 8 -25 0 -15 0 0 0 15 0 25 0 </pre> <h3>Output for the Sample Input</h3> <pre> No Yes Yes Yes No </pre> <h3>Sample Input</h3> <pre> 8 8 5 -20 -10 -10 -10 -10 10 -20 10 10 -10 20 -10 20 10 10 10 1 2 2 3 3 4 1 4 5 6 6 7 7 8 5 8 -30 0 -15 0 0 0 15 0 30 0 </pre> <h3>Output for the Sample Input</h3> <pre> No Yes No Yes No </pre>
p00730
<h1><font color="#000">Problem C:</font> Cut the Cake</h1> <!-- end en only --> <p> Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest <i>p&acirc;tissiers</i> in the world. Those who are invited to his birthday party are <i>gourmets</i> from around the world. They are eager to see and eat his extremely creative cakes. Now a large box-shaped cake is being carried into the party. It is not beautifully decorated and looks rather simple, but it must be delicious beyond anyone's imagination. Let us cut it into pieces with a knife and serve them to the guests attending the party. </p> <!-- end en only --> <!-- begin en only --> <p> The cake looks rectangular, viewing from above (Figure C-1). As exemplified in Figure C-2, the cake will iteratively be cut into pieces, where on each cut exactly a single piece is cut into two smaller pieces. Each cut surface must be orthogonal to the bottom face and must be orthogonal or parallel to a side face. So, every piece shall be rectangular looking from above and every side face vertical. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_c-1"><br><br> <!-- begin en only --> Figure C-1: The top view of the cake <!-- end en only --> </center> <center> <br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_c-2"><br><br> <!-- begin en only --> Figure C-2: Cutting the cake into pieces <!-- end en only --> </center> <!-- begin en only --> <p> Piece sizes in Figure C-2 vary significantly and it may look unfair, but you don't have to worry. Those guests who would like to eat as many sorts of cakes as possible often prefer smaller pieces. Of course, some prefer larger ones. </p> <!-- end en only --> <!-- begin en only --> <p>Your mission of this problem is to write a computer program that simulates the cutting process of the cake and reports the size of each piece. </p> <!-- end en only --> <h2>Input</h2> <!-- begin en only --> <p> The input is a sequence of datasets, each of which is of the following format. </p> <!-- end en only --> <blockquote> <i>n</i>&nbsp;&nbsp;<i>w</i>&nbsp;&nbsp;<i>d</i><br> <i>p</i><sub>1</sub>&nbsp;&nbsp;<i>s</i><sub>1</sub><br> ...<br> <i>p<sub>n</sub></i>&nbsp;&nbsp;<i>s<sub>n</sub></i><br> </blockquote> <!-- begin en only --> <p> The first line starts with an integer <i>n</i> that is between 0 and 100 inclusive. It is the number of cuts to be performed. The following <i>w</i> and <i>d</i> in the same line are integers between 1 and 100 inclusive. They denote the width and depth of the cake, respectively. Assume in the sequel that the cake is placed so that <i>w</i> and <i>d</i> are the lengths in the east-west and north-south directions, respectively. </p> <!-- end en only --> <!-- begin en only --> <p> Each of the following <i>n</i> lines specifies a single cut, cutting one and only one piece into two. <i>p<sub>i</sub></i> is an integer between 1 and <i>i</i> inclusive and is the identification number of the piece that is the target of the <i>i</i>-th cut. Note that, just before the <i>i</i>-th cut, there exist exactly <i>i</i> pieces. Each piece in this stage has a unique identification number that is one of 1, 2, ..., <i>i</i> and is defined as follows: </p> <!-- end en only --> <!-- begin en only --> <ul> <li> The earlier a piece was born, the smaller its identification number is. <li> Of the two pieces born at a time by the same cut, the piece with the smaller area (looking from above) has the smaller identification number. If their areas are the same, you may define as you like the order between them, since your choice in this case has no influence on the final answer. </ul> <!-- end en only --> <!-- begin en only --> <p> Note that identification numbers are adjusted after each cut. </p> <!-- end en only --> <!-- begin en only --> <p> <i>s<sub>i</sub></i> is an integer between 1 and 1000 inclusive and specifies the starting point of the <i>i</i>-th cut. From the northwest corner of the piece whose identification number is <i>p<sub>i</sub></i>, you can reach the starting point by traveling <i>s<sub>i</sub></i> in the clockwise direction around the piece. You may assume that the starting point determined in this way cannot be any one of the four corners of the piece. The <i>i</i>-th cut surface is orthogonal to the side face on which the starting point exists. <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line with three zeros. </p> <!-- end en only --> <h2>Output</h2> <!-- begin en only --> <p> For each dataset, print in a line the areas looking from above of all the pieces that exist upon completion of the <i>n</i> cuts specified in the dataset. They should be in ascending order and separated by a space. When multiple pieces have the same area, print it as many times as the number of the pieces. </p> <!-- end en only --> <h2>Sample Input</h2> <pre> 3 5 6 1 18 2 19 1 2 3 4 1 1 1 2 1 3 1 0 2 5 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 4 4 6 16 1 1 1 1 10 </pre>
p00360
<H1>Swapping Characters</H1> <p> You are given a string and a number <var>k</var>. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to <var>k</var> times. Write a program to report the lexicographically smallest string among them. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>s</var> <var>k</var> </pre> <p> The first line provides a string <var>s</var>. The second line provides the maximum number of swapping operations <var>k</var> (0 &le; <var>k</var> &le; 10<sup>9</sup>). The string consists solely of lower-case alphabetical letters and has a length between 1 and 2 &times; 10<sup>5</sup>. </p> <h2>Output</h2> <p> Output the lexicographically smallest string. </p> <h2>Sample Input 1</h2> <pre> pckoshien 3 </pre> <h2>Sample Output 1</h2> <pre> ckopshien </pre> <h2>Sample Input 2</h2> <pre> pckoshien 10 </pre> <h2>Sample Output 2</h2> <pre> cekophsin </pre>
p01988
<h3>NINJA GAME</h3> <!-- begin ja only --> <p>新䜜ゲヌム "NIN<strong><em>JA G</em></strong>AME" が぀いに発売ずなったこのゲヌムではプレむダヌは二次元マップ䞊の忍者を操䜜しお移動を行う二次元マップは <i>x</i> 軞たたは <i>y</i> 軞のどちらか䞀方に平行な蟺のみからなる自己亀差のない倚角圢で衚されるいた倚角圢の内郚に存圚するスタヌト地点からゎヌル地点ぞず移動する必芁がある</p> <p>移動は䞊䞋巊右ず斜め45°の8方向が可胜でいずれかの察応するコマンドを入力するず指定した方向に自動で進み続けるこの自動移動の最䞭の任意のタむミングで別のコマンドを入力した堎合即座に移動方向の転換が可胜であるあなたの目暙はこのゲヌムでの実瞟を解陀するため最小のコマンド入力回数でスタヌト地点からゎヌル地点に移動するこずである</p> <p>ここで気を付ける必芁があるのはキャラが忍者であるので壁䌝いの移動が可胜であるずいうこずだここで壁䌝いの移動するずは倚角圢の蟺䞊を移動するこずであるただしもちろん倚角圢の倖郚に出るこずはできない壁䌝いの移動䞭にその壁に察し垂盎方向に移動しようずする堎合はそれ以䞊移動できずに止たるのだが䞀方で壁䌝いの移動䞭に斜め方向に移動しようずする堎合壁ず平行な方向ぞの壁䌝いの自動移動が続き壁がなくなったずころで元の斜め方向にたた自動移動を続ける䟋えば䞋図のように <i>y</i> 軞に平行な壁に <i>x</i> 軞正方向ず <i>y</i> 軞負方向からなる斜め方向からぶ぀かった堎合ぶ぀かった埌は壁に沿っお <i>y</i> 軞負方向に進み壁がなくなったずころでたた <i>x</i> 軞正方向ず <i>y</i> 軞負方向からなる斜め方向ぞず進み始める</p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H1.png"></center></p> <p>ここで斜め方向に移動しながら角にぶ぀かったずきの挙動は以䞋のようになる(a) のように䞡方向に壁が囲たれおいる堎合はそこで止たり方向転換をしなければ動けない(b) や (c) のように角を通り過ぎおそのたた進める堎合は斜め方向に自動移動を続ける(d) のように䞡方向に進める堎合奜きな方向を遞んで進めるものずしおよい図では移動を衚す矢印で壁が隠れるため少し内郚偎に寄せお図瀺しおいるがこれも実際には蟺䞊を移動するこずを衚す図である</p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H2.png"></center></p> <p>たた䞊䞋巊右方向の移動䞭に角にぶ぀かったずきの挙動は以䞋のようになる(e), (f), (g) のような堎合はそのたたの方向に自動移動を続ける(h) のように壁に垂盎にぶ぀かった堎合はそこで止たり方向転換をしなければ動けないただし同様に移動を衚す矢印を壁から少し内郚偎に寄せおいるが実際には蟺䞊を移動するこずを衚す図である</p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H3.png"></center></p> <p>䞊蚘の移動に関する挙動に埓った䞊でスタヌト地点からゎヌル地点に到達するために入力する必芁があるコマンドの数の最小倀を求めるプログラムを䜜成しおほしい䟋えば䞋図における最小のコマンド入力回数は図䞭に瀺すように2であるこれは3぀目のサンプル入力に察応しおいる</p> <p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H4.png"></center></p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットからなる デヌタセットの数は最倧で 100 である 各デヌタセットは次の圢匏で衚される</p> <blockquote><i>N</i> <i>sx</i> <i>sy</i> <i>gx</i> <i>gy</i> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>...</i> <i>x<sub>N</sub></i> <i>y<sub>N</sub></i></blockquote> <p>デヌタセットの 1 行目はマップを衚す倚角圢の頂点数を衚す1぀の敎数 <i>N</i> (<i>4 &le; N &le; 100</i>) からなる2行目は4぀の敎数 <i>sx</i>, <i>sy</i>, <i>gx</i>, <i>gy</i> (<i>-10,000 &le; sx, sy, gx, gy &le; 10,000</i>) からなりスタヌト地点の座暙が <i>(sx, sy)</i>ゎヌル地点の座暙が <i>(gx, gy)</i> であるこずを衚しおいる続く <i>N</i> 行では倚角圢の各頂点が反時蚈回り順に䞎えられるこのうち <i>i</i> 行目は2぀の敎数 <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> (<i>-10,000 &le; x<sub>i</sub>, y<sub>i</sub> &le; 10,000</i>) からなり<i>i</i> 番目の頂点の座暙が <i>(x<sub>i</sub>, y<sub>i</sub>)</i> であるこずを衚すここで䞎えられるスタヌト地点ゎヌル地点倚角圢は以䞋の制玄を満たす</p> <ul> <li>党おの蟺は <i>x</i> 軞か <i>y</i> 軞のいずれか䞀方に察しお平行である</li> <li>䞎えられる倚角圢は自己亀差を持たないすなわち各蟺は端点以倖で他の蟺ず亀差せず異なる <i>i, j</i> に぀いお <i>(x<sub>i</sub>, y<sub>i</sub>) &ne; (x<sub>j</sub>, y<sub>j</sub>)</i> である</li> <li><i>(sx, sy)</i> ず <i>(gx, gy)</i> はずもにこの倚角圢の内郚 (蟺䞊を含たない) にあるこずが保蚌される</li> <li>スタヌトずゎヌルは異なるすなわち <i>(sx, sy) &ne; (gx, gy)</i> であるこずが保蚌される</li> </ul> <p>入力の終わりは 1 ぀のれロからなる行で衚される</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに察しスタヌト地点からゎヌル地点に蟿り着くために必芁な最小のコマンド入力の回数を 1 行で出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>8 1 1 2 2 0 2 0 0 2 0 2 1 3 1 3 3 1 3 1 2 12 -9 5 9 -9 0 0 0 -13 3 -13 3 -10 10 -10 10 10 -1 10 -1 13 -4 13 -4 10 -10 10 -10 0 12 3 57 53 2 0 0 64 0 64 18 47 18 47 39 64 39 64 60 0 60 0 44 33 44 33 30 0 30 0 </pre><h3>Output for the Sample Input</h3><pre>1 1 2 </pre> <p> 1぀目の入力は䞋図 (1)2぀目の入力は䞋図 (2) に察応する </p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H5.png"></center>
p01121
<!--<h2>Problem E</h2>--> <!-- begin en only --> <h3>Cube Surface Puzzle</h3> <!-- end en only --> <!-- begin en only --> <p> Given a set of six pieces, &ldquo;Cube Surface Puzzle&rdquo; is to construct a hollow cube with filled surface. Pieces of a puzzle is made of a number of small unit cubes laid grid-aligned on a plane. For a puzzle constructing a cube of its side length <i>n</i>, unit cubes are on either of the following two areas. <ul> <li> Core (blue): A square area with its side length <i>n</i>&minus;2. Unit cubes fill up this area.</li> <li>Fringe (red): The area of width 1 unit forming the outer fringe of the core. Each unit square in this area may be empty or with a unit cube on it.</li> </ul> Each piece is connected with faces of its unit cubes. Pieces can be arbitrarily rotated and either side of the pieces can be inside or outside of the constructed cube. The unit cubes on the core area should come in the centers of the faces of the constructed cube. </p> <!-- end en only --> <!-- begin en only --> <p> Consider that we have six pieces in Fig. E-1 (The first dataset of Sample Input). Then, we can construct a cube as shown in Fig. E-2. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_E1.png" width="80%"> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. E-1 Pieces from the first dataset of Sample Input <!-- end en only --> </figcaption> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_E2.png" width="80%"> <figcaption style="padding-top: 10px" align="center"> <!-- begin en only --> Fig. E-2 Constructing a cube <!-- end en only --> </figcaption> </center> <!-- begin en only --> <p> Mr. Hadrian Hex has collected a number of cube surface puzzles. One day, those pieces were mixed together and he cannot find yet from which six pieces he can construct a cube. Your task is to write a program to help Mr. Hex, which judges whether we can construct a cube for a given set of pieces. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of at most 200 datasets, each in the following format. </p> <!-- end en only --> <blockquote> <p> <i>n</i><br> <i>x</i><sub>1,1</sub><i>x</i><sub>1,2</sub> &hellip; <i>x</i><sub>1,<i>n</i></sub><br> <i>x</i><sub>2,1</sub><i>x</i><sub>2,2</sub> &hellip; <i>x</i><sub>2,<i>n</i></sub><br> &hellip;<br> <i>x</i><sub>6<i>n</i>,1</sub><i>x</i><sub>6<i>n</i>,2</sub> &hellip; <i>x</i><sub>6<i>n</i>,<i>n</i></sub> </p> </blockquote> <!-- begin en only --> <p> The first line contains an integer <i>n</i> denoting the length of one side of the cube to be constructed (3 &le; <i>n</i> &le; 9, <i>n</i> is odd). The following 6<i>n</i> lines give the six pieces. Each piece is described in <i>n</i> lines. Each of the lines corresponds to one grid row and each of the characters in the line, either &lsquo;X&rsquo; or &lsquo;.&rsquo;, indicates whether or not a unit cube is on the corresponding unit square: &lsquo;X&rsquo; means a unit cube is on the column and &lsquo;.&rsquo; means none is there. </p> <!-- end en only --> <!-- begin en only --> <p> The core area of each piece is centered in the data for the piece. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing a zero. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output &ldquo;<tt>Yes</tt>&rdquo; if we can construct a cube, or &ldquo;<tt>No</tt>&rdquo; if we cannot. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 5 ..XX. .XXX. XXXXX XXXXX X.... ....X XXXXX .XXX. .XXX. ..... ..XXX XXXX. .XXXX .XXXX ...X. ...X. .XXXX XXXX. XXXX. .X.X. XXX.X .XXXX XXXXX .XXXX .XXXX XX... .XXXX XXXXX XXXXX XX... 5 ..XX. .XXX. XXXXX XXXX. X.... ....X XXXXX .XXX. .XXX. ..... .XXXX XXXX. .XXXX .XXXX ...X. ...X. .XXXX XXXX. XXXX. .X.X. XXX.X .XXXX XXXXX .XXXX .XXXX XX... XXXXX XXXXX .XXXX XX... 0 </pre> <h3>Output for the Sample Input</h3> <pre> Yes No </pre>
p01571
<H1><font color="#000">Problem A:</font> Adhoc Translation</H1> <p> One day, during daily web surfing, you encountered a web page which was written in a language you've never seen. The character set of the language was the same as your native language; moreover, the grammar and words seemed almost the same. Excitedly, you started to "decipher" the web page. The first approach you tried was to guess the meaning of each word by selecting a similar word from a dictionary of your native language. The closer two words (although from the different languages) are, the more similar meaning they will have. </p> <p> You decided to adopt edit distance for the measurement of similarity between two words. The edit distance between two character sequences is defined as the minimum number of insertions, deletions and substitutions required to morph one sequence into the other. For example, the pair of "point" and "spoon" has the edit distance of 3: the latter can be obtained from the former by deleting 't', substituting 'i' to 'o', and finally inserting 's' at the beginning. </p> <p> You wanted to assign a word in your language to each word in the web text so that the entire assignment has the minimum edit distance. The edit distance of an assignment is calculated as the total sum of edit distances between each word in the text and its counterpart in your language. Words appearing more than once in the text should be counted by the number of appearances. </p> <p> The translation must be consistent across the entire text; you may not match different words from your dictionary for different occurrences of any word in the text. Similarly, different words in the text should not have the same meaning in your language. </p> <p> Suppose the web page says "qwerty asdf zxcv" and your dictionary contains the words "qwert", "asf", "tyui", "zxcvb" and "ghjk". In this case, you can match the words in the page as follows, and the edit distance of this translation is 3: "qwert" for "qwerty", "asf" for "asdf" and "zxcvb" for "zxcv". </p> <p> Write a program to calculate the minimum possible edit distance among all translations, for given a web page text and a word set in the dictionary. </p> <H2>Input</H2> <p> The first line of the input contains two integers <i>N</i> and <i>M</i>. </p> <p> The following <i>N</i> lines represent the text from the web page you've found. This text contains only lowercase alphabets and white spaces. Then <i>M</i> lines, each containing a word, describe the dictionary to use. Every word consists of lowercase alphabets only, and does not contain more than 20 characters. </p> <p> It is guaranteed that 1 &le; <i>N</i> &le; 100 and 1 &le; <i>M</i> &le; 400. Also it is guaranteed that the dictionary is made up of many enough words, which means the number of words in the dictionary is no less than the kinds of words in the text to translate. The length of each line in the text does not exceed 1000. </p> <H2>Output</H2> <p> Output the minimum possible edit distance in a line. </p> <H2>Sample Input 1</H2> <pre> 1 5 qwerty asdf zxcv qwert asf tyui zxcvb ghjk </pre> <H2>Output for the Sample Input 1</H2> <pre> 3 </pre>
p01766
<h1 id="a-soccer-サッカヌ">A : Soccer / サッカヌ</h1> <h2 id="問題文">問題文</h2> <p>A囜ずB囜の間でAIサッカヌの詊合をした。あなたの手元には、ある時刻にボヌルを持っおいた遞手ずその䜍眮を蚘録した衚がある。衚は <var>N</var> 行からなり、䞊から <var>i</var> 番目の行は次に瀺す芁玠からなる。</p> <ul> <li>フレヌム数 <var>f_i</var></li> <li>ボヌルを持っおいる遞手の背番号 <var>a_i</var></li> <li>その遞手が属するチヌム <var>t_i</var></li> <li>その遞手の䜍眮を衚す座暙 <var>x_i , y_i</var></li> </ul> <p>フレヌム数ずは、ゲヌムの開始時刻に <var>0</var> に蚭定され、 <var>1</var>/<var>60</var> 秒ごずに <var>1</var> 加算される敎数のこずである。䟋えば、ゲヌム開始からちょうど <var>1.5</var> 秒埌のフレヌム数は <var>90</var> である。 背番号は各チヌム内の <var>11</var> 人の遞手に䞀意にふられる敎数である。さらに、衚䞭の連続する <var>2</var> ぀の蚘録においお、同じチヌムの異なる背番号の遞手がボヌルを持っおいるずき、その間に「パス」が行われたずする。蚘録に存圚しないフレヌムは考慮しなくおよい。</p> <p>さお、゚ンゞニアであるあなたの仕事は、各チヌムの遞手間で行われたパスのうち、 最も距離(ナヌクリッド距離)が長いものの距離ず、それにかかった時間を求めるこずである。 距離が最長ずなるパスが耇数ある堎合は、かかった時間が最も短いものを出力せよ。</p> <h2 id="入力">入力</h2> <p>入力は以䞋の圢匏で䞎えられる。<var>t_i=0</var> のずきA囜、 <var>t_i=1</var> のずきB囜を衚す。</p> <pre><var>N</var> <var>f_0</var> <var>a_0</var> <var>t_0</var> <var>x_0</var> <var>y_0</var> <var>
</var> <var>f_{N&minus;1}</var> <var>a_{N&minus;1}</var> <var>t_{N&minus;1}</var> <var>x_{N&minus;1}</var> <var>y_{N&minus;1}</var> </pre> <h2 id="制玄">制玄</h2> <ul> <li>入力はすべお敎数である</li> <li><var>1 \&le; N \&le; 100</var></li> <li><var>0 \&le; f_i \lt f_{i+1} \&le; 324\,000</var></li> <li><var> 1 \&le; a_i \&le; 11</var></li> <li><var> t_i = 0,1</var></li> <li><var> 0 \&le; x_i \&le; 120</var></li> <li><var> 0 \&le; y_i \&le; 90</var></li> </ul> <h2 id="出力">出力</h2> <p>A囜の最長のパスにかかった距離ず時間、B囜の最長のパスにかかった距離ず時間を、それぞれ1行に出力せよ。時間は秒単䜍ずし、距離、時間ずもに <var>10^{&minus;3}</var> 以䞋の絶察誀差は蚱される。パスが䞀床も行われなかった堎合はずもに <var>&minus;1</var> ず出力せよ。</p> <h2 id="サンプル">サンプル</h2> <h3 id="サンプル入力1">サンプル入力1</h3> <pre>5 0 1 0 3 4 30 1 0 3 4 90 2 0 6 8 120 1 1 1 1 132 2 1 2 2 </pre> <h3 id="サンプル出力1">サンプル出力1</h3> <pre>5.00000000 1.00000000 1.41421356 0.20000000 </pre> <p>A囜は長さ <var>5</var> のパスを <var>30</var> フレヌムの時刻に <var>60</var> フレヌム <var>=1</var> 秒でし、B囜は長さ <var>√2</var> のパスを <var>120</var> フレヌムの時刻に <var>12</var> フレヌム <var>=0.2</var> 秒でした。これらがそれぞれの最長のパスである。</p> <h3 id="サンプル入力2">サンプル入力2</h3> <pre>2 0 1 0 0 0 10 1 1 0 0 </pre> <h3 id="サンプル出力2">サンプル出力2</h3> <pre>-1 -1 -1 -1 </pre> <h3 id="サンプル入力3">サンプル入力3</h3> <pre>3 0 1 0 0 0 30 2 0 1 1 40 1 0 2 2 </pre> <h3 id="サンプル出力3">サンプル出力3</h3> <pre>1.4142135624 0.1666666667 -1 -1 </pre> <h3 id="サンプル入力4">サンプル入力4</h3> <pre>3 0 1 0 0 0 10 2 0 1 1 40 1 0 3 3 </pre> <h3 id="サンプル出力4">サンプル出力4</h3> <pre>2.8284271247 0.5000000000 -1 -1 </pre>
p02849
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has come to an integer shop to buy an integer.</p> <p>The shop sells the integers from <var>1</var> through <var>10^9</var>. The integer <var>N</var> is sold for <var>A \times N + B \times d(N)</var> yen (the currency of Japan), where <var>d(N)</var> is the number of digits in the decimal notation of <var>N</var>.</p> <p>Find the largest integer that Takahashi can buy when he has <var>X</var> yen. If no integer can be bought, print <var>0</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq A \leq 10^9</var></li> <li><var>1 \leq B \leq 10^9</var></li> <li><var>1 \leq X \leq 10^{18}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the greatest integer that Takahashi can buy. If no integer can be bought, print <var>0</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 7 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>The integer <var>9</var> is sold for <var>10 \times 9 + 7 \times 1 = 97</var> yen, and this is the greatest integer that can be bought. Some of the other integers are sold for the following prices:</p> <ul> <li><var>10: 10 \times 10 + 7 \times 2 = 114</var> yen</li> <li><var>100: 10 \times 100 + 7 \times 3 = 1021</var> yen</li> <li><var>12345: 10 \times 12345 + 7 \times 5 = 123485</var> yen</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 100000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000000 </pre> <p>He can buy the largest integer that is sold. Note that input may not fit into a <var>32</var>-bit integer type.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000 1000000000 100 </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>1234 56789 314159265 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>254309 </pre></section> </div> </span>
p00874
<H1><font color="#000">Problem A:</font> Cubist Artwork</H1> <p> <i>International Center for Picassonian Cubism</i> is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the museum building. The artwork is a collection of cubes that are piled up on the ground and is intended to amuse visitors, who will be curious how the shape of the collection of cubes changes when it is seen from the front and the sides. </p> <p> The artwork is a collection of cubes with edges of one foot long and is built on a flat ground that is divided into a grid of one foot by one foot squares. Due to some technical reasons, cubes of the artwork must be either put on the ground, fitting into a unit square in the grid, or put on another cube in the way that the bottom face of the upper cube exactly meets the top face of the lower cube. No other way of putting cubes is possible. </p> <p> You are a member of the judging committee responsible for selecting one out of a plenty of artwork proposals submitted to the competition. The decision is made primarily based on artistic quality but the cost for installing the artwork is another important factor. Your task is to investigate the installation cost for each proposal. The cost is proportional to the number of cubes, so you have to figure out the minimum number of cubes needed for installation. </p> <p> Each design proposal of an artwork consists of the front view and the side view (the view seen from the right-hand side), as shown in Figure 1. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork1"><br> <p>Figure 1: An example of an artwork proposal</p> </center> <p> The front view (resp., the side view) indicates the maximum heights of piles of cubes for each column line (resp., row line) of the grid. </p> <p> There are several ways to install this proposal of artwork, such as the following figures. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork2"><br> </center> <p> In these figures, the dotted lines on the ground indicate the grid lines. The left figure makes use of 16 cubes, which is not optimal. That is, the artwork can be installed with a fewer number of cubes. Actually, the right one is optimal and only uses 13 cubes. Note that, a single pile of height three in the right figure plays the roles of two such piles in the left one. </p> <p> Notice that swapping columns of cubes does not change the side view. Similarly, swapping rows does not change the front view. Thus, such swaps do not change the costs of building the artworks. </p> <p> For example, consider the artwork proposal given in Figure 2. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork3"><br> <p>Figure 2: Another example of artwork proposal</p> </center> <p> An optimal installation of this proposal of artwork can be achieved with 13 cubes, as shown in the following figure, which can be obtained by exchanging the rightmost two columns of the optimal installation of the artwork of Figure 1. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork4"><br> </center> <H2>Input</H2> <p> The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows. </p> <p> <i>w d</i><br> <i>h</i><sub>1</sub> <i>h</i><sub>2</sub> ... <i>h<sub>w</sub></i><br> <i>h'</i><sub>1</sub> <i>h'</i><sub>2</sub> ... <i>h'<sub>d</sub></i><br> </p> <p> The integers <i>w</i> and <i>d</i> separated by a space are the numbers of columns and rows of the grid, respectively. You may assume 1 &le; <i>w</i> &le; 10 and 1 &le; <i>d</i> &le; 10. The integers separated by a space in the second and third lines specify the shape of the artwork. The integers <i>h<sub>i</sub></i> (1 &le; <i>h<sub>i</sub></i> &le; 20, 1 &le; <i>i</i> &le; <i>w</i>) in the second line give the front view, i.e., the maximum heights of cubes per each column line, ordered from left to right (seen from the front). The integers <i>h<sub>i</sub></i> (1 &le; <i>h<sub>i</sub></i> &le; 20, 1 &le; <i>i</i> &le; <i>d</i>) in the third line give the side view, i.e., the maximum heights of cubes per each row line, ordered from left to right (seen from the right-hand side). </p> <H2>Output</H2> <p> For each dataset, output a line containing the minimum number of cubes. The output should not contain any other extra characters. </p> <p> You can assume that, for each dataset, there is at least one way to install the artwork. </p> <H2>Sample Input</H2> <pre> 5 5 1 2 3 4 5 1 2 3 4 5 5 5 2 5 4 1 3 4 1 5 3 2 5 5 1 2 3 4 5 3 3 3 4 5 3 3 7 7 7 7 7 7 3 3 4 4 4 4 3 4 4 3 4 2 2 4 4 2 1 4 4 2 8 8 8 2 3 8 3 10 10 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 9 20 1 20 20 20 20 20 18 20 20 20 20 20 20 7 20 20 20 20 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 15 15 21 21 15 13 32 90 186 </pre>
p01336
<h1><font color="#000">Problem D:</font>THE BYDOLM@STER</h1> <h2>Description</h2> <!-- <div style="float:right"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/uvcs_static_image_03D_2" alt="ドブケラドプス" width=400 height=260></div> --> <p>THE BYDOLM@STER(バむドルマスタヌ)ずは1rem瀟より2010/4/1にEXIDNAで発売が予定されおいる育成シミュレヌションゲヌムである。䞀応断っおおくが、今月初めにネットワヌク接続サヌビスが停止した某アヌケヌドゲヌムずはたぶん関係が無い。<br> このゲヌムはバむドルたちからプロデュヌスするナニット(線隊)のメンバヌを遞択し、メンバヌたちずのレッスンやコミュニケヌションを通じお、圌女(圌)らをバむドルの頂点、トップバむドルに育お䞊げるゲヌムである。<!--右の写真はトップバむドルの内の䞀䜓、”ドブケラドプス”のフィギュアである。--><br> 各バむドルには胜力倀ずしおボヌカル、ダンス、ルックスの3぀のパラメヌタを持ち、ナニットの胜力倀はナニットに属しおいる党おのバむドルのパラメヌタの合蚈倀ずなる。ナニットの3぀の胜力倀のうち最倧の物がナニットのランクずなる。<br> ナニットに人数制限は無く、メンバヌの人数が1䜓でも、3䜓でも、100䜓でもナニットずしお掻動できる。もちろん同じバむドルを耇数雇うこず出来るが、バむドルを雇うためには費甚がかかるのでこれを考慮に入れなければならない。<br> プロデュヌサヌであるあなたは最高のナニットを䜜るためにプログラムを曞いお蚈算するこずにした。</p> <h2>Input</h2> <p>入力は耇数のテストケヌスからなる。<br> 各テストケヌスの1行目にはバむドルの数Nず䜿甚可胜な費甚Mが䞎えられる。(1&lt;=N,M&lt;=300) 次の2*N行には各バむドルに関しおの情報が曞かれおいる。<br> バむドルの情報の1行目にはバむドルの名前。バむドルの名前はアルファベットず空癜から成り、30文字を以䞋である。たた同䞀名のバむドルは存圚しない。<br> 2行目には敎数C、V、D、Lが䞎えられる。Cはそのバむドルを1䜓雇甚するコスト、Vはボヌカル、Dはダンス、Lはルックスの胜力倀を衚す。(1<=C,V,D,L<=300)<br> 入力はEOFで終わる。</p> <h2>Output</h2> <p>䞎えられた費甚の䞭で䜜れるナニットのランクの最倧倀を答えよ。<br> ナニットが䜜れない堎合は0を出力せよ。</p> <h2>Sample Input</h2> <pre> 3 10 Dobkeradops 7 5 23 10 PataPata 1 1 2 1 dop 5 3 11 14 2 300 Bydo System Alpha 7 11 4 7 Green Inferno 300 300 300 300 </pre> <h2>Output for Sample Input</h2> <pre> 29 462 </pre>
p00177
<H1>郜垂間の距離</H1> <p> 地球䞊の2 郜垂の北緯ず東経を入力ずし、地衚距離を蚈算しお出力するプログラムを䜜成しおください。ただし、地球は半埄 6,378.1 km の球ずし、2 点間の地衚距離ずはこの球面に沿った最短距離です。たた、南半球でも南緯は甚いずに北緯 0 ~ -90 床を甚い、グリニッゞ子午線の西でも西経は甚いずに東経 180 ~ 360 床を甚いるこずずしたす。地衚距離は km 単䜍で求め、小数点以䞋は四捚五入し、敎数倀ずしお出力しおください。 </p> <p> 以䞋に䞻芁郜垂の北緯、東経の䟋を瀺したす。 </p> <center> <table> <tr><th width="120">地名</th><th width="100"> 北緯(床)</th><th width="100"> 東経(床)</th></tr> <tr><th>東京</th><th> 35.68</th><th> 139.77</th></tr> <tr><th> シンガポヌル</th><th> 1.37</th><th> 103.92</th></tr> <tr><th> シドニヌ</th><th> -33.95 </th><th>151.18</th></tr> <tr><th> シカゎ </th><th> 41.78</th><th> 272.25</th></tr> <tr><th>ブ゚ノスアむレス </th><th> -34.58</th><th> 301.52</th></tr> <tr><th> ロンドン </th><th> 51.15</th><th> 359.82</th></tr> </table> </center> <br/> <br/> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりは-1 四぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>a</var> <var>b</var> <var>c</var> <var>d</var> </pre> <p> 1 行に第 1 の郜垂の北緯 <var>a</var>、第 1 の郜垂の東経 <var>b</var>、第 2 の郜垂の北緯 <var>c</var>、第 2 の郜垂の東経 <var>d</var> が空癜区切りで䞎えられたす。入力はすべお実数で䞎えられたす。 </p> <p> デヌタセットの数は 30 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に 2 郜垂の地衚距離を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 35.68 139.77 51.15 359.82 1.37 103.92 41.78 272.25 51.15 359.82 -34.58 301.52 -1 -1 -1 -1 </pre> <H2>Output for the Sample Input</H2> <pre> 9609 15092 11112 </pre>
p00527
<h2>IOI 列車で行こう(Take the 'IOI' train)</h2> <p> IOI 囜ではこのたび新たに鉄道を敷蚭したIOI 囜の鉄道を走る列車はいく぀かの車䞡が連結されたものであり車䞡には <span>I</span>, <span>O</span> の 2 皮類がある車䞡はそれぞれ異なる皮類の車䞡ずしか連結できないたた列車に運転垭を蚭ける関係䞊列車の䞡端の車䞡は皮類 <span>I</span> でなければならない列車は車䞡の皮類を衚す文字を順に぀なげた文字列で衚され列車の長さはその文字列の長さであるずするたずえば <span>IOIOI</span> の順に車䞡を連結するず長さ 5 の列車を線成できたた車䞡 <span>I</span> は単独で長さ 1 の列車である車䞡を <span>OIOI</span> や <span>IOOI</span> ずいった順に䞊べおも列車を線成するこずはできない </p> <p> いく぀かの車䞡が 2 ぀の車庫に栌玍されおいるそれぞれの車庫の䞭には車䞡が䞀列に䞊んでいる列車を線成するずきは車庫から車䞡を出しおきお車庫前で連結しおいく車庫から出せる車䞡は最も車庫の入り口に近い車䞡のみであるがどちらの車庫から車䞡を出すかの順番に぀いおは自由である </p> <p> 列車を線成する前に車䞡を奜きなだけ車庫から出しお別の埅機甚レヌルに移すこずができる䞀床埅機甚レヌルに移した車䞡は今埌列車を線成するために䜿うこずはできないたた䞀床列車の線成を始めるずその線成が終わるたでの間は車䞡を車庫から埅機甚レヌルに移すこずはできない </p> <p> 列車を線成するずき車庫内の党おの車䞡を䜿い切る必芁はないすなわち列車の線成を終えた埌車庫内に䜿われなかった車䞡が残っおいおも構わない </p> <p> IOI 囜では鉄道に乗る人がずおもたくさんいるず考えられおいるのでできるだけ長い列車を線成したい </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_2"> </center> <br> <p> 図: 列車を線成しおいる途䞭でありこのずき車庫にある車䞡を埅機甚レヌルに移すこずはできないこの図は入出力䟋1 に察応しおいる </p> <h3>課題</h3> <p> 車庫に栌玍された車䞡の情報が䞎えられたずき線成できる列車の長さの最倧倀を求めるプログラムを䜜成せよそれぞれの車庫に栌玍された車䞡の列は 2 皮類の文字<span>I</span>, <span>O</span> のみからなる文字列で衚され 2 ぀の車庫の情報はそれぞれ長さ <var>M</var> の文字列 <var>S</var> および長さ <var>N</var> の文字列 <var>T</var> ずしお䞎えられる各文字が 1 ぀の車䞡を衚しその文字は車䞡の皮類ず同じである文字列の1 文字目は最も車庫の入り口に近い車䞡を衚し末尟の文字が車庫の最も奥にある車䞡を衚す </p> <h3>制限</h3> <ul> <li>1 &le; <var>M</var> &le; 2000 &nbsp;&nbsp;&nbsp;&nbsp; 文字列 <var>S</var> の長さ</li> <li>1 &le; <var>N</var> &le; 2000 &nbsp;&nbsp;&nbsp;&nbsp; 文字列 <var>T</var> の長さ</li> </ul> <h3>入力</h3> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li> 1 行目には <var>M</var>, <var>N</var> が空癜区切りで曞かれおいる</li> <li> 2 行目には文字列 <var>S</var> が曞かれおいる</li> <li> 3 行目には文字列 <var>T</var> が曞かれおいる</li> </ul> <h3>出力</h3> <p> 暙準出力に線成できる列車の長さの最倧倀を衚す敎数を 1 行で出力せよ 列車が 1 ぀も線成できない堎合は 0 を出力せよ </p> <h3>入出力䟋</h3> <h3>入力䟋 1</h3> <pre> 5 5 OIOOI OOIOI </pre> <h3> 出力䟋 1</h3> <pre> 7 </pre> <p> <var>S</var> によっお衚される車庫を車庫 S ずし<var>T</var> によっお衚される車庫を車庫 T ずしようこのずきたずえば車庫 S から最初の1 車䞡車庫 T から最初の 2 車䞡を出しお埅機させた埌車庫 S車庫 S車庫 T車庫 S車庫 S車庫 T車庫 T の順番に車䞡を出せば長さ7 の列車 <span>IOIOIOI</span> を線成できる </p> <p> 他にも車庫 S から最初の 1 車䞡車庫 T から最初の 2 車䞡を出しお埅機させた埌車庫 T車庫 T車庫 S車庫 S車庫 T車庫 S車庫 S の順番に車䞡を出すこずでも長さ 7 の列車を線成できるこれより長い列車を線成するこずはできないので 7 を出力する </p> <br> <h3>入力䟋 2</h3> <pre> 5 9 IIIII IIIIIIIII </pre> <h3>出力䟋 2</h3> <pre> 1 </pre> <p> 1 ぀の車䞡のみからなる列車 <span>I</span> も列車ずしおの条件を満たすこずに泚意せよ </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00032
<H1>プラスティック板</H1> <p> 機械に蟺・察角線の長さのデヌタを入力し、プラスティック板の型抜きをしおいる工堎がありたす。この工堎では、サむズは様々ですが、平行四蟺圢の型のみを切り出しおいたす。あなたは、切り出される平行四蟺圢のうち、長方圢ずひし圢の補造個数を数えるように䞊叞から呜じられたした。 </p> <p> 「機械に入力するデヌタ」を読み蟌んで、長方圢ずひし圢の補造個数を出力するプログラムを䜜成しおください。 </p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_plastic"></center> <br/> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>,<var>c<sub>1</sub></var> <var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>,<var>c<sub>2</sub></var> : </pre> <p> 機械に入力するデヌタが耇数行に䞎えられたす。<var>i</var> 行目に <var>i</var> 番目の平行四蟺圢の隣り合う蟺の長さを衚す敎数 <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> ず察角線の長さを衚す敎数 <var>c<sub>i</sub></var> がカンマ区切りで䞎えられたす (1 &le; <var>a<sub>i</sub>, b<sub>i</sub>, c<sub>i</sub></var> &le; 1000, <var>a<sub>i</sub> + b<sub>i</sub></var> &gt; <var>c<sub>i</sub></var>)。デヌタの数は 100 件を超えたせん。 </p> <H2>Output</H2> <p> 行目に長方圢の補造個数、行目ひし圢の補造個数を出力したす。 </p> <H2>Sample Input</H2> <pre> 3,4,5 5,5,8 4,4,4 5,4,3 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 </pre>
p00462
<H1>ピザ </H1> <h2>問題</h2> <p> JOI ピザでは,垂の䞭心郚を通る党長 <i>d</i> メヌトルの環状線の沿線䞊でピザの宅配販 売を行っおいる. </p> <p> JOI ピザは,環状線䞊に <i>n</i> 個の店舗 <i>S</i><sub>1</sub>, ... , <i>S<sub>n</sub></i> を持぀.本店は <i>S</i><sub>1</sub> である. <i>S</i><sub>1</sub> から <i>S<sub>i</sub></i> たで,時蚈回りに環状線を移動したずきの道のりを <i>d<sub>i</sub></i> メヌトルずおく. <i>d</i><sub>2</sub>, ... , <i>d<sub>n</sub></i> は 1 以䞊 <i>d</i> - 1 以䞋の敎数である. <i>d</i><sub>2</sub> , ... , <i>d<sub>n</sub></i> は党お異なる. ピザの泚文を受けるず, ピザが冷めないように, 宅配先たでの移動距離がもっずも短い店舗でピザを焌き宅配する. </p> <p> 宅配先の䜍眮は 0 以䞊 <i>d</i> - 1 以䞋の敎数 <i>k</i> で衚される.これは, 本店 <i>S</i><sub>1</sub> から宅配先たでに時蚈回りで環状線を移動したずきの道のりが <i>k</i> メヌトルであるこずを意味する. ピザの宅配は環状線に沿っお行われ, それ以倖の道を通るこずは蚱されない. ただし, 環状線䞊は時蚈回りに移動しおも反時蚈回りに移動しおもよい. </p> <p> 䟋えば,店舗の䜍眮ず宅配先の䜍眮が䞋図のようになっおいる堎合 (この䟋は「入出力の䟋」の䟋 1 ず察応しおいる), </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pizza"> </center> <br> <p> 宅配先 1 にもっずも近い店舗は <i>S</i><sub>2</sub> なので, 店舗 <i>S</i><sub>2</sub> から宅配する.このずき, 店舗からの移動距離は 1 である.たた, 宅配先 2 にもっずも近い店舗は <i>S</i><sub>1</sub> (本店) なので, 店舗 <i>S</i><sub>1</sub> (本店) から宅配する.このずき,店舗からの移動距離は 2 である. </p> <p> 環状線の党長 <i>d</i>, JOI ピザの店舗の個数 <i>n</i>, 泚文の個数 <i>m</i>, 本店以倖の䜍眮を衚す <i>n</i> - 1 個の敎数 <i>d</i><sub>2</sub>, ... , <i>d<sub>n</sub></i> , 宅配先の堎所を衚す敎数 <i>k</i><sub>1</sub>, ... , <i>k<sub>m</sub></i> が䞎えられたずき, 各泚文に察する宅配時の移動距離 (すなわち,最寄店舗から宅配先たでの道のり) の党泚文にわたる総和を求めるプログラムを䜜成せよ. </p> <h2>入力</h2> <p> <!-- 入力ファむルのファむル名は input.txt である.<br>--> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 1 行目には環状線の党長を衚す正敎数 <i>d</i> (2 &le; <i>d</i> &le; 1000000000 = 10<sup>9</sup> ), 2 行目には店舗の個数を衚す正敎数 <i>n</i> (2 &le; <i>n</i> &le; 100000), 3 行目には泚文の個数を衚す正敎数 <i>m</i> (1 &le; <i>m</i> &le; 10000) が曞かれおいる. 4 行目以降の <i>n</i> - 1 行には本店以倖の店舗の䜍眮を衚す敎数 <i>d</i><sub>2</sub>, <i>d</i><sub>3</sub>, ... , <i>d</i><sub>n</sub> (1 &le; <i>d<sub>i</sub></i> &le; <i>d</i> - 1) がこの順に曞かれおおり, <i>n</i> + 3 行目以降の <i>m</i> 行には宅配先の堎所を衚す敎数 <i>k</i><sub>1</sub>, <i>k</i><sub>2</sub>, ... , <i>k<sub>m</sub></i> (0 &le; <i>k<sub>i</sub></i> &le; <i>d</i> - 1) がこの順に曞かれおいる. </p> <p> 採点甚デヌタのうち,配点の 40% 分に぀いおは, n &le; 10000 を満たす. たた,配点の 40% 分に぀いおは, 求める移動距離の総和ず <i>d</i> の倀はずもに 1000000 以䞋である. さらに,党おの採点甚デヌタにおいお, 求める移動距離の総和は 1000000000 = 10<sup>9</sup>以䞋である. </p> <p> <i>d</i> が 0 のずき入力の終了を瀺す. デヌタセットの数は 10 を超えない </p> <h2>出力</h2> <p> <!-- 出力ファむルのファむル名は output.txt である.<br> output.txt は,宅配時の移動距離の総和を衚す 1 ぀の敎数のみを含む 1 行からなる. --> デヌタセットごずに,宅配時の移動距離の総和を衚す 1 ぀の敎数を1 行に出力する. </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 8 3 2 3 1 4 6 20 4 4 12 8 16 7 7 11 8 0 </pre> <h3>出力䟋</h3> <pre> 3 3 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00198
<h1>立方䜓の䜜品</h1> <p> 芞術家品川は <var>n</var> 点の䜜品を出展するように䟝頌されたした。そこで、立方䜓の 6 面をペンキで色付けしたものを䜜品ずしお出展するこずにしたした。䜜品は、Red、Yellow、Blue、Magenta、Green、Cyan の 6 色党おが䜿われおいお、各面は 1 色で塗り぀ぶされおいたす。品川は圢が同じ立方䜓の䜜品でも色の配眮の仕方を倉え、異なる䜜品ずしお <var>n</var> 点䜜成したした。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_shinagawa1"><br/> </center> <br/> <p> 圌の友人であるあなたは、友人のよしみで䜜品を出展前に閲芧させおもらいたしたが、そこであるこずに気が付きたした。それらの䜜品の䞭に異なる色付けをされおいるように芋えおも、実は同じ色の組み合わせをした立方䜓が存圚しおいたのです。このたたでは、 <var>n</var> 点の䜜品を出展するこずできなくなっおしたいたす。 </p> <p> 䜜成した䜜品の数ず各䜜品の色の情報を入力ずし、出展するためにあず䜕点必芁かを出力するプログラムを䜜成しおください。 </p> <p> 立方䜓の各面の色は c1 から c6 たでの蚘号で衚され、 以䞋のような配眮ずなっおいたす。たた、c1 から c6 のそれぞれは Red、Yellow、Blue、Magenta、Green、Cyan のいずれか 1 色ずなりたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_shinagawa2"><br/> </center> <br/> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。 入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>cube<sub>1</sub></var> <var>cube<sub>2</sub></var> : <var>cube<sub>n</sub></var> </pre> <p> 行目に䜜品の数 <var>n</var> (1 &le; <var>n</var> &le; 30)、続く <var>n</var> 行に <var>i</var> 番目の䜜品の情報が䞎えられたす。各䜜品の情報は次の圢匏で䞎えられたす。 </p> <pre> c1 c2 c3 c4 c5 c6 </pre> <p> 䜜品の色の配眮 c<sub><var>i</var></sub> が空癜区切りで䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、出展するのにあず䜕点の䜜品が必芁かを行に出力したす。 </p> <H2>Sample Input</H2> <pre> 3 Cyan Yellow Red Magenta Green Blue Cyan Yellow Red Magenta Green Blue Red Yellow Magenta Blue Green Cyan 4 Red Magenta Blue Green Yellow Cyan Red Yellow Magenta Blue Green Cyan Magenta Green Red Cyan Yellow Blue Cyan Green Yellow Blue Magenta Red 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 1 </pre>
p01623
<script src="./IMAGE/varmath.js" charset="UTF-8"></script <!-- <h3><u>Sinking islands</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> ずある海域にミスト諞島ず呌ばれる矎しい自然ず豊かな資源に恵たれた島々がある 気候も枩暖であるため人々はそこで長きに枡っお平和な暮らしを営んできた しかし最近になっお倧倉な事実が刀明した 地殻倉動によっおミスト諞島の島々が遠からず沈没しおしたうずいうのだ<br> </p> <p> この事態に察応するため各島の代衚からなる察策本郚が結成された たず調査隊の働きにより各島がい぀沈没しおしたうかが明らかになった たたミスト諞島の技術を結集するこずでいく぀かの島の間には橋が架けられるこずも分かった その結果島の間に橋を架け各島の䜏民が特定の島に避難できるようにするこずに決たった<br> </p> <p> 珟段階でどの島を避難先にするかは決たっおいないらしい そのため最初はどの島が避難先になっおも良いようどの島からもいく぀かの橋を枡るこずで他の党おの島に行けるように橋を架ける 時間の経過によっお島が沈んだずき䞡端の島が䞀方でも沈んだ橋は通行できなくなる このずき最初の橋の架け方によっおはある島から蟿り぀けないような島ができおしたう堎合がある この堎合は新たに橋を架けるこずでただ沈んでいない島々の間で移動経路が確保できるようにする どのように橋を架けおも移動経路が確保できなくなった堎合はそれ以䞊の橋の建蚭は行わない 察策本郚はそれたでに避難先を決め䜏民の避難を完了させなくおはならないだろう なお珟時点で既に移動経路を確保するように橋を架ける事が出来ない堎合は橋の建蚭は䞀切行わない 察策本郚は新たな案を緎るこずになるだろう<br> </p> <p> ずころで橋は架ける䜍眮によっお建蚭費甚が決たっおいる 避難には䜕かず費甚がかかるので察策本郚では橋の建蚭費甚の合蚈がなるべく小さくなるように橋を架けたいず考えおいるようだ そのためにはどのように橋を架ければ良いだろうか </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットから構成される各デヌタセットの圢匏は次の通りである </p> <pre> <var>N</var> <var>M</var> <var>h<sub>1</sub></var> <var>h<sub>2</sub></var> <var>...</var> <var>h<sub>N</sub></var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var> <var>...</var> <var>a<sub>M</sub></var> <var>b<sub>M</sub></var> <var>c<sub>M</sub></var> </pre> <p> N は島の数を衚す敎数であり2 以䞊 200 以䞋ず仮定しお良い たた各島には 1 から N の数字が割り振られおいる M は橋を建蚭できる島のペアの数を衚す 1 以䞊の敎数である<br> </p> <p> 続く N 行には各島がい぀沈没するかを瀺す情報が䞎えられる h<sub>i</sub> は島 i が h<sub>i</sub> 日埌に沈むずいう事を衚す敎数であり1 以䞊 1,000,000 以䞋ず仮定しお良い 同時に耇数の島が沈む堎合もある<br> </p> <p> 続く M 行は建蚭できる橋の情報を衚す 各行はスペヌスで区切られた 3 ぀の敎数を含みa<sub>i</sub> ず b<sub>i</sub> が橋の䞡端の島の番号c<sub>i</sub> が橋の建蚭費甚である(1 &#8804; i &#8804; M) 各橋の建蚭費甚は 1 以䞊 1,000,000 以䞋ず仮定しお良い ある 2 ぀の島を結ぶ橋が 2 ぀以䞊䞎えられる事や橋の䞡端が同じ島である事はない<br> </p> <p> N=M=0 は入力の終わりを瀺すこれはデヌタセットには含めない<br> </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットに察し条件に埓っお橋を建蚭するずきの最小の合蚈費甚を求めそれぞれ1行に出力しなさい </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 3 3 1 2 3 1 2 1 1 3 1 2 3 10 3 2 100 10000 1000000 1 2 2 1 3 3 6 6 2 3 5 7 11 13 1 3 17 3 5 19 5 1 23 2 4 29 4 6 31 6 2 37 11 16 74 25 3 39 55 18 74 55 74 3 18 1 7 200 9 1 423 2 9 205 6 2 255 2 5 123 4 2 193 2 3 200 10 2 333 2 11 256 3 10 171 4 10 512 1 2 201 8 5 314 6 7 150 11 6 257 7 9 315 20 38 412516 185397 509168 712745 966959 101213 666120 790528 275431 677098 623178 240167 4371 299088 925699 72800 121416 796859 810604 142754 13 5 1000000 3 7 991832 10 1 781938 15 8 455731 1 3 655887 1 20 604802 19 10 452912 15 5 360121 10 15 256967 9 5 682599 8 7 917302 5 18 974821 2 19 790778 17 5 298105 15 11 132405 18 19 745543 2 4 790778 1 2 790778 11 14 269668 15 4 882901 1 14 522591 15 18 424799 9 19 712540 20 5 592132 18 17 770826 19 8 592380 16 5 258739 8 4 794157 3 18 569611 7 19 340021 19 11 803293 8 18 692318 9 6 626882 20 2 592133 2 17 196463 12 14 506077 16 20 928375 12 18 894053 0 0 </pre> <!-- begin ja only --> <!-- end ja only --> <h3>Output for Sample Input</h3> <pre> 11 5 0 2013 9658580 </pre> <!-- begin ja only --> <!-- end ja only -->
p00931
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem H: Cornering at Poles </h2> <p> You are invited to a robot contest. In the contest, you are given a disc-shaped robot that is placed on a flat field. A set of poles are standing on the ground. The robot can move in all directions, but must avoid the poles. However, the robot can make turns around the poles touching them. </p> <p> Your mission is to find the shortest path of the robot to reach the given goal position. The length of the path is defined by the moving distance of the center of the robot. Figure H.1 shows the shortest path for a sample layout. In this figure, a red line connecting a pole pair means that the distance between the poles is shorter than the diameter of the robot and the robot cannot go through between them. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_H1" width="600"><br> <p>Figure H.1. The shortest path for a sample layout</p> </center> <h3>Input</h3> <p> The input consists of a single test case.<br> <br> $N$ $G_x$ $G_y$<br> $x_1$ $y_1$<br> .<br> .<br> .<br> $x_N$ $y_N$<br> <br> The first line contains three integers. $N$ represents the number of the poles ($1 \leq N \leq 8$). $(G_x, G_y)$ represents the goal position. The robot starts with its center at $(0, 0)$, and the robot accomplishes its task when the center of the robot reaches the position $(G_x, G_y)$. You can assume that the starting and goal positions are not the same. </p> <p> Each of the following $N$ lines contains two integers. $(x_i, y_i)$ represents the standing position of the $i$-th pole. Each input coordinate of $(G_x, G_y)$ and $(x_i, y_i)$ is between $−1000$ and $1000$, inclusive. The radius of the robot is $100$, and you can ignore the thickness of the poles. No pole is standing within a $100.01$ radius from the starting or goal positions. For the distance $d_{i,j}$ between the $i$-th and $j$-th poles $(i \ne j)$, you can assume $1 \leq d_{i,j} < 199.99$ or $200.01 < d_{i,j}$. </p> <p> Figure H.1 shows the shortest path for Sample Input 1 below, and Figure H.2 shows the shortest paths for the remaining Sample Inputs. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_H2" width="640"><br> <p>Figure H.2. The shortest paths for the sample layouts</p> </center> <h3>Output</h3> <p> Output the length of the shortest path to reach the goal. If the robot cannot reach the goal, output 0.0. The output should not contain an error greater than 0.0001. </p> <h3>Sample Input 1</h3> <pre>8 900 0 40 100 70 -80 350 30 680 -20 230 230 300 400 530 130 75 -275</pre> <h3>Sample Output 1</h3> <pre>1210.99416</pre> <h3>Sample Input 2</h3> <pre>1 0 200 120 0</pre> <h3>Sample Output 2</h3> <pre>200.0</pre> <h3>Sample Input 3</h3> <pre>3 110 110 0 110 110 0 200 10</pre> <h3>Sample Output 3</h3> <pre>476.95048</pre> <h3>Sample Input 4</h3> <pre>4 0 200 90 90 -90 90 -90 -90 90 -90</pre> <h3>Sample Output 4</h3> <pre>0.0</pre> <h3>Sample Input 5</h3> <pre>2 0 -210 20 -105 -5 -105</pre> <h3>Sample Output 5</h3> <pre>325.81116</pre> <h3>Sample Input 6</h3> <pre>8 680 -50 80 80 80 -100 480 -120 -80 -110 240 -90 -80 100 -270 100 -420 -20</pre> <h3>Sample Output 6</h3> <pre>1223.53071</pre>
p01273
<H1><font color="#000">Problem A:</font> Infected Computer</H1> <p> Adam Ivan is working as a system administrator at Soy Group, Inc. He is now facing at a big trouble: a number of computers under his management have been infected by a computer virus. Unfortunately, anti-virus system in his company failed to detect this virus because it was very new. </p> <p> Adam has identified the first computer infected by the virus and collected the records of all data packets sent within his network. He is now trying to identify which computers have been infected. A computer is infected when receiving any data packet from any infected computer. The computer is not infected, on the other hand, just by sending data packets to infected computers. </p> <p> It seems almost impossible for him to list all infected computers by hand, because the size of the packet records is fairly large. So he asked you for help: write a program that can identify infected computers. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> <i>N M</i><br> <i>t</i><sub>1</sub> <i>s</i><sub>1</sub> <i>d</i><sub>1</sub><br> <i>t</i><sub>2</sub> <i>s</i><sub>2</sub> <i>d</i><sub>2</sub><br> ...<br> <i>t<sub>M</sub> s<sub>M</sub> d<sub>M</sub></i><br> </p> <p> <i>N</i> is the number of computers; <i>M</i> is the number of data packets; <i>t<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>M</i>) is the time when the <i>i</i>-th data packet is sent; <i>s<sub>i</sub></i> and <i>d<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>M</i>) are the source and destination computers of the <i>i</i>-th data packet respectively. The first infected computer is indicated by the number 1; the other computers are indicated by unique numbers between 2 and <i>N</i>. </p> <p> The input meets the following constraints: 0 &lt; <i>N</i> &le; 20000, 0 &le; <i>M</i> &le; 20000, and 0 &le; <i>t<sub>i</sub></i> &le; 10<sup>9</sup> for 1 &le; <i>i</i> &le; <i>N</i>; all <i>t<sub>i</sub></i> 's are different; and the source and destination of each packet are always different. </p> <p> The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the number of computers infected by the computer virus. </p> <H2>Sample Input</H2> <pre> 3 2 1 1 2 2 2 3 3 2 2 3 2 1 2 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 1 </pre>
p01789
<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>J - Unfair Game</h2> <h3>Problem Statement</h3> <p> Rabbit Hanako and Fox Jiro are great friends going to JAG primary school. Today they decided to play the following game during the lunch break. </p> <p> This game is played by two players with $N$ heaps of some number of stones. The players alternatively take their turn to play the game. Jiro is a kind gentleman, so he yielded the first turn to Hanako. In each turn, the player must take some stones, satisfying the following conditions: </p> <ul> <li>If the player is Hanako, she must take between $1$ to $A$ stones, inclusive, from a heap.</li> <li>If the player is Jiro, he must take between $1$ to $B$ stones, inclusive, from a heap.</li> </ul> <p> The winner is the player who takes the last stone. Jiro thinks it is rude to go easy on her because he is a perfect gentleman. Therefore, he does him best. Of course, Hanako also does so. </p> <p> Jiro is worried that he may lose the game. Being a cadet teacher working at JAG primary school as well as a professional competitive programmer, you should help him by programming. Your task is to write a program calculating the winner, assuming that they both play optimally. </p> <h3>Input</h3> <p> The first line contains three integers $N$, $A$, and $B$. $N$ ($1 \leq N \leq 10^5$) is the number of heaps. $A$ and $B$ ($1 \leq A, B \leq 10^9$) are the maximum numbers of stones that Hanako and Jiro can take in a turn, respectively. Then $N$ lines follow, each of which contains a single integer $S_i$ ($1 \leq S_i \leq 10^9$), representing the number of stones in the $i$-th heap at the beginning of the game. </p> <h3>Output</h3> <p>Output a line with &quot;Hanako&quot; if Hanako wins the game or &quot;Jiro&quot; in the other case. </p> <h3>Sample Input 1</h3> <pre>3 5 4 3 6 12</pre> <h3>Output for the Sample Input 1</h3> <pre>Hanako</pre> <h3>Sample Input 2</h3> <pre>4 7 8 8 3 14 5</pre> <h3>Output for the Sample Input 2</h3> <pre>Jiro</pre>
p03864
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> boxes arranged in a row. Initially, the <var>i</var>-th box from the left contains <var>a_i</var> candies.</p> <p>Snuke can perform the following operation any number of times:</p> <ul> <li>Choose a box containing at least one candy, and eat one of the candies in the chosen box.</li> </ul> <p>His objective is as follows:</p> <ul> <li>Any two neighboring boxes contain at most <var>x</var> candies in total.</li> </ul> <p>Find the minimum number of operations required to achieve the objective.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 10^5</var></li> <li><var>0 ≀ a_i ≀ 10^9</var></li> <li><var>0 ≀ x ≀ 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required to achieve the objective.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Eat one candy in the second box. Then, the number of candies in each box becomes <var>(2, 1, 2)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 1 6 1 2 0 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>11 </pre> <p>For example, eat six candies in the second box, two in the fourth box, and three in the sixth box. Then, the number of candies in each box becomes <var>(1, 0, 1, 0, 0, 1)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 9 3 1 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>The objective is already achieved without performing operations.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 0 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>10 </pre> <p>All the candies need to be eaten.</p></section> </div> </span>
p01859
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>--> <h2>B: 䞭島、あれやろうぜ - Match Peas War -</h2> <h3>問題</h3> <p>䞭島「うぅっ・・・」</p> <p>磯野「䞭島倧䞈倫か」</p> <p>䞭島「・・・なんだか嫌な倢を芋おいた気がするよ」</p> <p>磯野「どんな倢だい」</p> <p>䞭島「無限に遊ぶ倢」</p> <p>磯野「意味わからんたぁいいや䞭島あれやろうぜ」</p> <p>䞭島「あれっおたさかあれじゃないよな・・・」</p> <p>磯野「あれだよあれ」</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_are" type="image/jpeg" width="300"></img> <p>䞭島「おっいいじゃないかやろうやろう」</p> <p>磯野「それじゃあたずはじゃんけんだな」</p> <p>なにやら公園で2人の子䟛が遊んでいるようです懐かしさを感じたすねずころであなたは『マッチ・グリヌンピヌス・戊争』などず呌ばれる手遊びを知っおいたすかその名称にピンずこなかったずしおもきっず子䟛時代に幟床ずなく遊んだこずがあるでしょう</p> <p>ここでは『マッチ・グリヌンピヌス・戊争』のルヌルを簡略化した手遊びを考え『あれ』ず名付けたす『あれ』は次のような2人プレむの遊びです</p> <pre> (1)各プレむダヌが䞡手の指を1本ず぀立おた状態から遊びを開始する (2)先手のプレむダヌから順番に以䞋の(3)〜(5)を行う (3)プレむダヌは自身のどちらか䞀方の手で盞手のどちらか䞀方の手に觊れる (4)觊れられた手は觊れた手に立っおいる指の本数だけ远加で指を立おる ここで5本以䞊の指が立぀べき状況になった手は退堎する 退堎した手は今埌觊れたり觊れられるずきに遞ばれるこずはない (5)䞡手ずも退堎したプレむダヌがいるかどうか確認するいるならば䞡プレむダヌは(6)に埓う (6)遊びを終了するこのずき少なくずも䞀方の手が残っおいるプレむダヌが勝者である </pre> <p>磯野「よヌし僕からだね」</p> <p>おやどうやら磯野君が先手になったようですね2人の遊びの行く末を芋守っおみたしょう</p> <p>磯野「じゃあ僕は右手に2本巊手に1本ではじめるよ」</p> <p>䞭島「それなら僕は右手に2本巊手に2本でいくよ」</p> <p>ちょっず埅おなんだそのルヌルは&minus;</p> <p>どうやら磯野君たちの間では遊び開始時に各手に立っおいる指の本数を1 〜 4本のうち自由に決められるようですロヌカルルヌルっおや぀ですね</p> <p>『あれ』のような類の遊びは先手埌手でどちらが必勝なのかを簡単に調べるこずができたすしかし『あれ』に磯野君たちのロヌカルルヌルを取り入れるず先手埌手の勝敗が倉わっおきそうですずおも気になりたすね皆さんも興味がおありなのではもしそうならば実際に調査しおみたしょう</p> <p>磯野君ず䞭島君がロヌカルルヌルを取り入れた『あれ』で遊ぶずしたす磯野君が先手ず仮定しお磯野君の巊手には<var>L_i</var>本右手には<var>R_i</var>本の指が䞭島君の巊手には<var>L_n</var>本右手には<var>R_n</var>本の指が立っおいるずしたす2人ずも最適な行動を遞択する堎合どちらが勝぀かを刀定しおください</p> <h3>入力圢匏</h3> <p>入力は以䞋の圢匏で䞎えられる</p> <pre> <var>L_i</var> <var>R_i</var> <var>L_n</var> <var>R_n</var> </pre> <p>1行目には磯野君の手の初期状態を衚す<var>L_i</var><var>R_i</var>が空癜区切りで䞎えられる<var>L_i</var>は巊手で立っおいる指の本数<var>R_i</var>は右手で立っおいる指の本数である</p> <p>2行目には䞭島君の手の初期状態を衚す<var>L_n</var><var>R_n</var>が空癜区切りで䞎えられる<var>L_n</var>は巊手で立っおいる指の本数<var>R_n</var>は右手で立っおいる指の本数である</p> <p>たた入力は以䞋の制玄を満たす</p> <pre><var>1 &le; L_i, R_i, L_n, R_n &le; 4</var></pre> <h3>出力圢匏</h3> <p>磯野君が勝぀堎合は“ISONO”を䞭島君が勝぀堎合は“NAKAJIMA”を1行に出力せよ</p> <h3>入力䟋1</h3> <pre> 3 2 2 2 </pre> <h3>出力䟋1</h3> <pre>NAKAJIMA</pre> <h3>入力䟋2</h3> <pre> 3 2 2 3 </pre> <h3>出力䟋2</h3> <pre>ISONO</pre> <h3>入力䟋3</h3> <pre> 1 1 1 1 </pre> <h3>出力䟋3</h3> <pre>NAKAJIMA</pre> <p>『あれ』は埌手で垞勝</p>
p02776
<span class="lang-en"> <p>Score: <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>After being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom.</p> <p>Fortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs.</p> <p>There are <var>N</var> bombs, numbered <var>1</var> to <var>N</var>, planted in our country. Bomb <var>i</var> is planted at the coordinate <var>A_i</var>. It is currently activated if <var>B_i=1</var>, and deactivated if <var>B_i=0</var>.</p> <p>The device has <var>M</var> cords numbered <var>1</var> to <var>M</var>. If we cut Cord <var>j</var>, the states of all the bombs planted between the coordinates <var>L_j</var> and <var>R_j</var> (inclusive) will be switched - from activated to deactivated, and vice versa.</p> <p>Determine whether it is possible to deactivate all the bombs at the same time. If the answer is yes, output a set of cords that should be cut.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq A_i \leq 10^9\ (1 \leq i \leq N)</var></li> <li><var>A_i</var> are pairwise distinct.</li> <li><var>B_i</var> is <var>0</var> or <var>1</var>. <var>(1 \leq i \leq N)</var></li> <li><var>1 \leq M \leq 2 \times 10^5</var></li> <li><var>1 \leq L_j \leq R_j \leq 10^9\ (1 \leq j \leq M)</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>:</var> <var>A_N</var> <var>B_N</var> <var>L_1</var> <var>R_1</var> <var>:</var> <var>L_M</var> <var>R_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If it is impossible to deactivate all the bombs at the same time, print <code>-1</code>. If it is possible to do so, print a set of cords that should be cut, as follows:</p> <pre><var>k</var> <var>c_1</var> <var>c_2</var> <var>\dots</var> <var>c_k</var> </pre> <p>Here, <var>k</var> is the number of cords (possibly <var>0</var>), and <var>c_1, c_2, \dots, c_k</var> represent the cords that should be cut. <var>1 \leq c_1 &lt; c_2 &lt; \dots &lt; c_k \leq M</var> must hold.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 5 1 10 1 8 0 1 10 4 5 6 7 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 </pre> <p>There are two activated bombs at the coordinates <var>5, 10</var>, and one deactivated bomb at the coordinate <var>8</var>.</p> <p>Cutting Cord <var>1</var> switches the states of all the bombs planted between the coordinates <var>1</var> and <var>10</var>, that is, all of the three bombs.</p> <p>Cutting Cord <var>4</var> switches the states of all the bombs planted between the coordinates <var>8</var> and <var>9</var>, that is, Bomb <var>3</var>.</p> <p>Thus, we can deactivate all the bombs by cutting Cord <var>1</var> and Cord <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 2 0 3 1 5 1 7 0 1 4 4 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>Cutting any set of cords will not deactivate all the bombs at the same time.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 2 5 0 10 0 8 0 6 9 66 99 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>All the bombs are already deactivated, so we do not need to cut any cord.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>12 20 536130100 1 150049660 1 79245447 1 132551741 0 89484841 1 328129089 0 623467741 0 248785745 0 421631475 0 498966877 0 43768791 1 112237273 0 21499042 142460201 58176487 384985131 88563042 144788076 120198276 497115965 134867387 563350571 211946499 458996604 233934566 297258009 335674184 555985828 414601661 520203502 101135608 501051309 90972258 300372385 255474956 630621190 436210625 517850028 145652401 192476406 377607297 520655694 244404406 304034433 112237273 359737255 392593015 463983307 150586788 504362212 54772353 83124235 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 1 7 8 9 11 </pre> <p>If there are multiple sets of cords that deactivate all the bombs when cut, any of them can be printed.</p></section> </div> </span>
p02326
<H1>Largest Square</H1> <p> Given a matrix (<var>H</var> &times; <var>W</var>) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s. </p> <H2>Input</H2> <pre> <var>H</var> <var>W</var> <var>c</var><sub>1,1</sub> <var>c</var><sub>1,2</sub> ... <var>c<sub>1,W</sub></var> <var>c</var><sub>2,1</sub> <var>c</var><sub>2,2</sub> ... <var>c<sub>2,W</sub></var> : <var>c<sub>H,1</sub></var> <var>c<sub>H,2</sub></var> ... <var>c<sub>H,W</sub></var> </pre> <p> In the first line, two integers <var>H</var> and <var>W</var> separated by a space character are given. In the following <var>H</var> lines, <var>c</var><sub><var>i</var>,<var>j</var></sub>, elements of the <var>H</var> &times; <var>W</var> matrix, are given. </p> <H2>Output</H2> <p> Print the area (the number of 0s) of the largest square. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>H</var>, <var>W</var> &le; 1,400</li> </ul> <H2>Sample Input</H2> <pre> 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 </pre> <H2>Sample Output</H2> <pre> 4 </pre>
p03167
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p> <p>For each <var>i</var> and <var>j</var> (<var>1 \leq i \leq H</var>, <var>1 \leq j \leq W</var>), Square <var>(i, j)</var> is described by a character <var>a_{i, j}</var>. If <var>a_{i, j}</var> is <code>.</code>, Square <var>(i, j)</var> is an empty square; if <var>a_{i, j}</var> is <code>#</code>, Square <var>(i, j)</var> is a wall square. It is guaranteed that Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</p> <p>Taro will start from Square <var>(1, 1)</var> and reach <var>(H, W)</var> by repeatedly moving right or down to an adjacent empty square.</p> <p>Find the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>. As the answer can be extremely large, find the count modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>H</var> and <var>W</var> are integers.</li> <li><var>2 \leq H, W \leq 1000</var></li> <li><var>a_{i, j}</var> is <code>.</code> or <code>#</code>.</li> <li>Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>a_{1, 1}</var><var>\ldots</var><var>a_{1, W}</var> <var>:</var> <var>a_{H, 1}</var><var>\ldots</var><var>a_{H, W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 ...# .#.. .... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are three paths as follows:</p> <p><img alt="" src="https://img.atcoder.jp/dp/grid_0_0_muffet.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 .. #. .. .# .. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There may be no paths.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 5 ..#.. ..... #...# ..... ..#.. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>24 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>20 20 .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>345263555 </pre> <p>Be sure to print the count modulo <var>10^9 + 7</var>.</p></section> </div> </span>
p03537
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ringo has a string <var>S</var>.</p> <p>He can perform the following <var>N</var> kinds of operations any number of times in any order.</p> <ul> <li>Operation <var>i</var>: For each of the characters from the <var>L_i</var>-th through the <var>R_i</var>-th characters in <var>S</var>, replace it with its succeeding letter in the English alphabet. (That is, replace <code>a</code> with <code>b</code>, replace <code>b</code> with <code>c</code> and so on.) For <code>z</code>, we assume that its succeeding letter is <code>a</code>.</li> </ul> <p>Ringo loves palindromes and wants to turn <var>S</var> into a palindrome. Determine whether this is possible.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 10^5</var></li> <li><var>S</var> consists of lowercase English letters.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq L_i \leq R_i \leq |S|</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>N</var> <var>L_1</var> <var>R_1</var> <var>L_2</var> <var>R_2</var> <var>:</var> <var>L_N</var> <var>R_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>YES</code> if it is possible to turn <var>S</var> into a palindrome; print <code>NO</code> if it is impossible.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>bixzja 2 2 3 3 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>For example, if we perform Operation <var>1</var>, <var>2</var> and <var>1</var> in this order, <var>S</var> changes as <code>bixzja</code> → <code>bjyzja</code> → <code>bjzakb</code> → <code>bkaakb</code> and becomes a palindrome.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>abc 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>cassert 4 1 2 3 4 1 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre></section> </div> </span>
p03022
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke found a random number generator. It generates an integer between <var>0</var> and <var>2^N-1</var> (inclusive). An integer sequence <var>A_0, A_1, \cdots, A_{2^N-1}</var> represents the probability that each of these integers is generated. The integer <var>i</var> (<var>0 \leq i \leq 2^N-1</var>) is generated with probability <var>A_i / S</var>, where <var>S = \sum_{i=0}^{2^N-1} A_i</var>. The process of generating an integer is done independently each time the generator is executed.</p> <p>Snuke has an integer <var>X</var>, which is now <var>0</var>. He can perform the following operation any number of times:</p> <ul> <li>Generate an integer <var>v</var> with the generator and replace <var>X</var> with <var>X \oplus v</var>, where <var>\oplus</var> denotes the bitwise XOR.</li> </ul> <p>For each integer <var>i</var> (<var>0 \leq i \leq 2^N-1</var>), find the expected number of operations until <var>X</var> becomes <var>i</var>, and print it modulo <var>998244353</var>. More formally, represent the expected number of operations as an irreducible fraction <var>P/Q</var>. Then, there exists a unique integer <var>R</var> such that <var>R \times Q \equiv P \mod 998244353,\ 0 \leq R &lt; 998244353</var>, so print this <var>R</var>.</p> <p>We can prove that, for every <var>i</var>, the expected number of operations until <var>X</var> becomes <var>i</var> is a finite rational number, and its integer representation modulo <var>998244353</var> can be defined.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 18</var></li> <li><var>1 \leq A_i \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>N</var> <var>A_0</var> <var>A_1</var> <var>\cdots</var> <var>A_{2^N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>2^N</var> lines. The <var>(i+1)</var>-th line (<var>0 \leq i \leq 2^N-1</var>) should contain the expected number of operations until <var>X</var> becomes <var>i</var>, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 4 4 4 </pre> <p><var>X=0</var> after zero operations, so the expected number of operations until <var>X</var> becomes <var>0</var> is <var>0</var>.</p> <p>Also, from any state, the value of <var>X</var> after one operation is <var>0</var>, <var>1</var>, <var>2</var> or <var>3</var> with equal probability. Thus, the expected numbers of operations until <var>X</var> becomes <var>1</var>, <var>2</var> and <var>3</var> are all <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 499122180 4 499122180 </pre> <p>The expected numbers of operations until <var>X</var> becomes <var>0</var>, <var>1</var>, <var>2</var> and <var>3</var> are <var>0</var>, <var>7/2</var>, <var>4</var> and <var>7/2</var>, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 468683018 635850749 96019779 657074071 24757563 745107950 665159588 551278361 143136064 557841197 185790407 988018173 247117461 129098626 789682908 </pre></section> </div> </span>
p03188
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For an <var>n \times n</var> grid, let <var>(r, c)</var> denote the square at the <var>(r+1)</var>-th row from the top and the <var>(c+1)</var>-th column from the left. A <em>good</em> coloring of this grid using <var>K</var> colors is a coloring that satisfies the following:</p> <ul> <li>Each square is painted in one of the <var>K</var> colors.</li> <li>Each of the <var>K</var> colors is used for some squares.</li> <li>Let us number the <var>K</var> colors <var>1, 2, ..., K</var>. For any colors <var>i</var> and <var>j</var> (<var>1 \leq i \leq K, 1 \leq j \leq K</var>), every square in Color <var>i</var> has the same number of adjacent squares in Color <var>j</var>. Here, the squares adjacent to square <var>(r, c)</var> are <var>((r-1)\; mod\; n, c), ((r+1)\; mod\; n, c), (r, (c-1)\; mod\; n)</var> and <var>(r, (c+1)\; mod\; n)</var> (if the same square appears multiple times among these four, the square is counted that number of times).</li> </ul> <p>Given <var>K</var>, choose <strong><var>n</var> between <var>1</var> and <var>500</var></strong> (inclusive) freely and construct a good coloring of an <var>n \times n</var> grid using <var>K</var> colors. It can be proved that this is always possible under the constraints of this problem,</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq 1000</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>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Output should be in the following format:</p> <pre><var>n</var> <var>c_{0,0}</var> <var>c_{0,1}</var> <var>...</var> <var>c_{0,n-1}</var> <var>c_{1,0}</var> <var>c_{1,1}</var> <var>...</var> <var>c_{1,n-1}</var> <var>:</var> <var>c_{n-1,0}</var> <var>c_{n-1,1}</var> <var>...</var> <var>c_{n-1,n-1}</var> </pre> <p><var>n</var> should represent the size of the grid, and <var>1 \leq n \leq 500</var> must hold. <var>c_{r,c}</var> should be an integer such that <var>1 \leq c_{r,c} \leq K</var> and represent the color for the square <var>(r, c)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 1 1 1 1 1 1 2 2 2 </pre> <ul> <li>Every square in Color <var>1</var> has three adjacent squares in Color <var>1</var> and one adjacent square in Color <var>2</var>.</li> <li>Every square in Color <var>2</var> has two adjacent squares in Color <var>1</var> and two adjacent squares in Color <var>2</var>.</li> </ul> <p>Output such as the following will be judged incorrect:</p> <pre>2 1 2 2 2 </pre> <pre>3 1 1 1 1 1 1 1 1 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 1 2 3 4 5 6 7 8 9 </pre></section> </div> </span>
p03472
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have <var>N</var> katana (swords), Katana <var>1</var>, Katana <var>2</var>, <var>
</var>, Katana <var>N</var>, and can perform the following two kinds of attacks in any order:</p> <ul> <li>Wield one of the katana you have. When you wield Katana <var>i</var> <var>(1 ≀ i ≀ N)</var>, the monster receives <var>a_i</var> points of damage. The same katana can be wielded any number of times.</li> <li>Throw one of the katana you have. When you throw Katana <var>i</var> <var>(1 ≀ i ≀ N)</var> at the monster, it receives <var>b_i</var> points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.</li> </ul> <p>The monster will vanish when the total damage it has received is <var>H</var> points or more. At least how many attacks do you need in order to vanish it in total?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^5</var></li> <li><var>1 ≀ H ≀ 10^9</var></li> <li><var>1 ≀ a_i ≀ b_i ≀ 10^9</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>H</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_N</var> <var>b_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total number of attacks required to vanish the monster.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 10 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>You have one katana. Wielding it deals <var>3</var> points of damage, and throwing it deals <var>5</var> points of damage. By wielding it twice and then throwing it, you will deal <var>3 + 3 + 5 = 11</var> points of damage in a total of three attacks, vanishing the monster.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 10 3 5 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>In addition to the katana above, you also have another katana. Wielding it deals <var>2</var> points of damage, and throwing it deals <var>6</var> points of damage. By throwing both katana, you will deal <var>5 + 6 = 11</var> points of damage in two attacks, vanishing the monster.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1000000000 1 1 1 10000000 1 30000000 1 99999999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>860000004 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 500 35 44 28 83 46 62 31 79 40 43 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>9 </pre></section> </div> </span>
p03921
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On a planet far, far away, <var>M</var> languages are spoken. They are conveniently numbered <var>1</var> through <var>M</var>.</p> <p>For <em>CODE FESTIVAL 20XX</em> held on this planet, <var>N</var> participants gathered from all over the planet.</p> <p>The <var>i</var>-th <var>(1≩i≩N)</var> participant can speak <var>K_i</var> languages numbered <var>L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}</var>.</p> <p>Two participants <var>A</var> and <var>B</var> can <em>communicate</em> with each other if and only if one of the following conditions is satisfied:</p> <ul> <li>There exists a language that both <var>A</var> and <var>B</var> can speak.</li> <li>There exists a participant <var>X</var> that both <var>A</var> and <var>B</var> can communicate with.</li> </ul> <p>Determine whether all <var>N</var> participants can communicate with all other participants.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≩N≩10^5</var></li> <li><var>1≩M≩10^5</var></li> <li><var>1≩K_i≩M</var></li> <li><var>(</var>The sum of all <var>K_i)≩10^5</var></li> <li><var>1≩L_{i,j}≩M</var></li> <li><var>L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}</var> are pairwise distinct.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>200</var> points will be awarded for passing the test set satisfying the following: <var>N≩1000</var>, <var>M≩1000</var> and <var>(</var>The sum of all <var>K_i)≩1000</var>.</li> <li>Additional <var>200</var> points will be awarded for passing the test set without additional constraints.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K_1</var> <var>L_{1,1}</var> <var>L_{1,2}</var> <var>...</var> <var>L_{1,{}K_1}</var> <var>K_2</var> <var>L_{2,1}</var> <var>L_{2,2}</var> <var>...</var> <var>L_{2,{}K_2}</var> <var>:</var> <var>K_N</var> <var>L_{N,1}</var> <var>L_{N,2}</var> <var>...</var> <var>L_{N,{}K_N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If all <var>N</var> participants can communicate with all other participants, print <code>YES</code>. Otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 6 3 1 2 3 2 4 2 2 4 6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>Any two participants can communicate with each other, as follows:</p> <ul> <li>Participants <var>1</var> and <var>2</var>: both can speak language <var>2</var>.</li> <li>Participants <var>2</var> and <var>3</var>: both can speak language <var>4</var>.</li> <li>Participants <var>1</var> and <var>3</var>: both can communicate with participant <var>2</var>.</li> <li>Participants <var>3</var> and <var>4</var>: both can speak language <var>6</var>.</li> <li>Participants <var>2</var> and <var>4</var>: both can communicate with participant <var>3</var>.</li> <li>Participants <var>1</var> and <var>4</var>: both can communicate with participant <var>2</var>.</li> </ul> <p>Note that there can be languages spoken by no participant.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 2 1 2 2 1 2 1 3 2 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p>For example, participants <var>1</var> and <var>3</var> cannot communicate with each other.</p></section> </div> </span>
p02633
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer <var>K</var> such that Takahashi will be at the starting position again after he does the following action <var>K</var> times:</p> <ul> <li>Go one meter in the direction he is facing. Then, turn <var>X</var> degrees counter-clockwise.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X \leq 179</var></li> <li><var>X</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>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of times Takahashi will do the action before he is at the starting position again.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>Takahashi's path is a square.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>360 </pre></section> </div> </span>
p02799
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a connected undirected graph with <var>N</var> vertices and <var>M</var> edges. Edge <var>i</var> in this graph (<var>1 \leq i \leq M</var>) connects Vertex <var>U_i</var> and Vertex <var>V_i</var> bidirectionally. We are additionally given <var>N</var> integers <var>D_1, D_2, ..., D_N</var>.</p> <p>Determine whether the conditions below can be satisfied by assigning a color - white or black - to each vertex and an integer weight between <var>1</var> and <var>10^9</var> (inclusive) to each edge in this graph. If the answer is yes, find one such assignment of colors and integers, too.</p> <ul> <li>There is at least one vertex assigned white and at least one vertex assigned black.</li> <li>For each vertex <var>v</var> (<var>1 \leq v \leq N</var>), the following holds.<ul> <li>The minimum cost to travel from Vertex <var>v</var> to a vertex whose color assigned is different from that of Vertex <var>v</var> by traversing the edges is equal to <var>D_v</var>.</li> </ul> </li> </ul> <p>Here, the cost of traversing the edges is the sum of the weights of the edges traversed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100,000</var></li> <li><var>1 \leq M \leq 200,000</var></li> <li><var>1 \leq D_i \leq 10^9</var></li> <li><var>1 \leq U_i, V_i \leq N</var></li> <li>The given graph is connected and has no self-loops or multiple edges.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var> <var>U_1</var> <var>V_1</var> <var>U_2</var> <var>V_2</var> <var>\vdots</var> <var>U_M</var> <var>V_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is no assignment satisfying the conditions, print a single line containing <code>-1</code>.</p> <p>If such an assignment exists, print one such assignment in the following format:</p> <pre><var>S</var> <var>C_1</var> <var>C_2</var> <var>\vdots</var> <var>C_M</var> </pre> <p>Here,</p> <ul> <li>the first line should contain the string <var>S</var> of length <var>N</var>. Its <var>i</var>-th character (<var>1 \leq i \leq N</var>) should be <code>W</code> if Vertex <var>i</var> is assigned white and <code>B</code> if it is assigned black.</li> <li>The <var>(i + 1)</var>-th line (<var>1 \leq i \leq M</var>) should contain the integer weight <var>C_i</var> assigned to Edge <var>i</var>.</li> </ul> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 3 4 3 5 7 1 2 1 3 3 2 4 2 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>BWWBB 4 3 1 5 2 </pre> <p>Assume that we assign the colors and integers as the sample output, and let us consider Vertex <var>5</var>, for example. To travel from Vertex <var>5</var>, which is assigned black, to a vertex that is assigned white with the minimum cost, we should make these moves: Vertex <var>5</var> <var>\to</var> Vertex <var>4</var> <var>\to</var> Vertex <var>2</var>. The total cost of these moves is <var>7</var>, which satisfies the condition. We can also verify that the condition is satisfied for other vertices.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 7 1 2 3 4 5 1 2 1 3 1 4 2 3 2 5 3 5 4 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>4 6 1 1 1 1 1 2 1 3 1 4 2 3 2 4 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>BBBW 1 1 1 2 1 1 </pre></section> </div> </span>
p02263
<p> Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free. </p> <p> Write a program which reads an expression in the Reverse Polish notation and prints the computational result. </p> <p> An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations. </p> <H2>Input</H2> <p> An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. </p> <p> You can assume that +, - and * are given as the operator and an operand is a positive integer less than 10<sup>6</sup> </p> <H2>Output</H2> <p> Print the computational result in a line. </p> <H2>Constraints</H2> <p> 2 &le; the number of operands in the expression &le; 100<br> 1 &le; the number of operators in the expression &le; 99<br> -1 &times; 10<sup>9</sup> &le; values in the stack &le; 10<sup>9</sup><br> </p> <H2>Sample Input 1</H2> <pre> 1 2 + </pre> <H2>Sample Output 1</H2> <pre> 3 </pre> <H2>Sample Input 2</H2> <pre> 1 2 + 3 4 - * </pre> <H2>Sample Output 2</H2> <pre> -3 </pre> <h2>Notes</h2> <a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a>
p00570
<h1>ストヌブ(Stove)</h1> <p> JOI 君の郚屋にはストヌブがあるJOI 君自身は寒さに匷いのでひずりで郚屋にいるずきはストヌブを぀ける必芁はないが来客があるずきはストヌブを぀ける必芁がある </p> <p> この日JOI 君のもずには<var>N</var> 人の来客がある<var>i</var> 番目(<var>1 \leq i \leq N</var>) の来客は時刻<var>T_i</var> に到着し時刻<var>T_i + 1</var>に退出する同時に耇数人の来客があるこずはない </p> <p> JOI 君は任意の時刻にストヌブを぀けたり消したりできるただしストヌブを぀ける床にマッチを1本消費するJOI 君はマッチを<var>K</var> 本しか持っおいないので<var>K</var> 回たでしかストヌブを぀けるこずができない䞀日のはじめにストヌブは消えおいる </p> <p> ストヌブを぀けおいるずその分だけ燃料を消費するのでストヌブを぀けたり消したりする時刻をうたく定めおストヌブが぀いおいる時間の合蚈を最小化したい </p> <h2>課題</h2> <p> JOI 君の郚屋ぞの来客の情報ずJOI 君の持っおいるマッチの本数が䞎えられたずきストヌブが぀いおいる時間の合蚈の最小倀を求めよ </p> <h3>入力</h3> <p>暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には2 ぀の敎数<var>N, K</var> が空癜を区切りずしお曞かれおいるこれはJOI 君の郚屋に<var>N</var> 人の来客がありJOI 君は<var>K</var> 本のマッチを持っおいるこずを衚す</li> <li> 続く<var>N</var> 行のうちの<var>i</var> 行目(<var>1 \leq i \leq N</var>) には敎数<var>T_i</var> が曞かれおいるこれは<var>i</var> 番目の来客が時刻<var>T_i</var>に到着し時刻<var>T_i + 1</var> に退出するこずを衚す</li> </ul> <h3>出力</h3> <p> 暙準出力にストヌブが぀いおいる時間の合蚈の最小倀を1 行で出力せよ </p> <h3>制限</h3> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li> <var>1 \leq N \leq 100 000</var></li> <li> <var>1 \leq K \leq N</var></li> <li> <var>1 \leq T_i \leq 1 000 000 000 (1 \leq i \leq N)</var></li> <li> <var>T_i < T_{i+1} (1 \leq i \leq N - 1)</var></li> </ul> <!-- 小課題 小課題1 [20 点] 以䞋の条件を満たす N ≩ 20 1 ≩ Ti ≩ 20 (1 ≩ i ≩ N) 小課題2 [30 点] N ≩ 5000 を満たす 小課題3 [50 点] 远加の制限はない --> <h3>問入出力䟋</h3> <h3>入力䟋1</h3> <pre> 3 2 1 3 6 </pre> <h3>出力䟋1</h3> <pre> 4 </pre> <p> この入力䟋ではJOI 君の郚屋ぞの来客が3 人ある以䞋のようにストヌブを぀けたり消したりするず来客がある間はストヌブが぀いおおりストヌブを぀ける回数は2 回でありストヌブが぀いおいる時間の合蚈は(4 - 1) + (7 - 6) = 4 である </p> <ul> <li> 1 番目の来客が到着する時刻1 にストヌブを぀ける</li> <li> 2 番目の来客が退出する時刻4 にストヌブを消す</li> <li> 3 番目の来客が到着する時刻6 にストヌブを぀ける</li> <li> 3 番目の来客が退出する時刻7 にストヌブを消す</li> </ul> <p> ストヌブを぀けおいる時間の合蚈を4 未満にするこずはできないので答えずしお4 を出力する </p> <h3>入力䟋2</h3> <pre> 3 1 1 2 6 </pre> <h3>出力䟋2</h3> <pre> 6 </pre> <p> この入力䟋ではJOI 君は1 回しかストヌブを぀けるこずができないので1 番目の来客が到着する時刻1 にストヌブを぀け3 番目の来客が退出する時刻7 にストヌブを消せばよい </p> <p> 来客が退出する時刻ずその次の来客が到着する時刻が䞀臎する堎合があるこずに泚意せよ </p> <h3>入力䟋3</h3> <pre> 3 3 1 3 6 </pre> <h3>出力䟋3</h3> <pre> 3 </pre> <p> この入力䟋ではJOI 君は来客が到着する床にストヌブを぀け来客が退出する床にストヌブを消せばよい </p> <h3>入力䟋4</h3> <pre> 10 5 1 2 5 6 8 11 13 15 16 20 </pre> <h3>出力䟋4</h3> <pre> 12 </pre> <br/> <p> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> <br/> <a href="https://www.ioi-jp.org/joi/2017/2018-ho/index.html">情報オリンピック日本委員䌚䜜 『第17 回日本情報オリンピック(JOI 2017/2018) 本遞』</a> </p>
p00120
<H1>パティシ゚</H1> <p> ケヌキ屋さんが、たちたちな倧きさのロヌルケヌキをたくさん䜜りたした。あなたは、このケヌキを箱に䞊べる仕事を任されたした。 </p> <p> ロヌルケヌキはずおもやわらかいので、他のロヌルケヌキが䞊に乗るず぀ぶれおしたいたす。ですから、図(a) のように党おのロヌルケヌキは必ず箱の底面に接しおいるように䞊べなければなりたせん。䞊べ替えるず必芁な幅も倉わりたす。 </p> <center> <table> <tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_patisserie1"></td></tr> <tr><th>図(a)</th></tr> <tr><td></td></tr> <tr><td></td></tr> <tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_patisserie2"></td></tr> <tr><th>図(b)</th></tr> </table> </center> </br> <p> <var>n</var> 個のロヌルケヌキの半埄 <var>r<sub>1</sub></var>, <var>r<sub>2</sub></var>, ..., <var>r<sub>n</sub></var> ず箱の長さを読み蟌み、それぞれに぀いお、箱の䞭にうたく収たるかどうか刀定し、䞊べる順番を工倫するず箱に入る堎合は "OK"、どう䞊べおも入らない堎合には "NA"を出力するプログラムを䜜成しおください。 </p> <p> ロヌルケヌキの断面は円であり、箱の壁の高さは十分に高いものずしたす。 ただし、ロヌルケヌキの半埄は 3 以䞊 10 以䞋の敎数ずしたす。぀たり、ケヌキの半埄に極端な差はなく、図(b) のように倧きなケヌキの間に小さなケヌキがはたり蟌んでしたうこずはありたせん。 </p> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなりたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>W</var> <var>r<sub>1</sub></var> <var>r<sub>2</sub></var> ... <var>r<sub>n</sub></var> </pre> <p> 最初に箱の長さを衚す敎数 <var>W</var> (1 &le; <var>W</var> &le; 1,000) が䞎えられたす。 続いお、空癜区切りで各ロヌルケヌキの半埄を衚す敎数 <var>r<sub>i</sub></var> (3 &le; <var>r<sub>i</sub></var> &le; 10) が䞎えられたす。ケヌキの個数 <var>n</var> は 12 以䞋です。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに OK たたは NA を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 30 4 5 6 30 5 5 5 50 3 3 3 10 10 49 3 3 3 10 10 </pre> <H2>Output for the Sample Input</H2> <pre> OK OK OK NA </pre>
p01361
<H1><font color="#000">Problem C:</font> Dungeon Quest II</H1> <p> The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king and all of his soldiers were destroyed by the hero and the peace is there now. </p> <p> One day, however, the hero was worrying about the rebirth of the devil king, so he decided to ask security agency to patrol inside the cave. </p> <p> The information of the cave is as follows: </p> <ul> <li> The cave is represented as a two-dimensional field which consists of rectangular grid of cells.</li> <li> The cave has <i>R</i> &times; <i>C</i> cells where <i>R</i> is the number of rows and <i>C</i> is the number of columns.</li> <li> Some of the cells in the cave contains a trap, and those who enter the trapping cell will lose his hit points.</li> <li> The type of traps varies widely: some of them reduce hit points seriously, and others give less damage.</li> </ul> <p> The following is how the security agent patrols: </p> <ul> <li> The agent will start his patrol from upper left corner of the cave.<br> - There are no traps at the upper left corner of the cave.</li> <li> The agent will patrol by tracing the steps which are specified by the hero.<br> - The steps will be provided such that the agent never go outside of the cave during his patrol.</li> <li> The agent will bring potions to regain his hit point during his patrol.</li> <li> The agent can use potions just before entering the cell where he is going to step in.</li> <li> The type of potions also varies widely: some of them recover hit points so much, and others are less effective.<br> - Note that agent’s hit point can be recovered up to <i>HP<sub>max</sub></i> which means his maximum hit point and is specified by the input data.</li> <li> The agent can use more than one type of potion at once.</li> <li> If the agent's hit point becomes less than or equal to 0, he will die.</li> </ul> <p> Your task is to write a program to check whether the agent can finish his patrol without dying. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is given in the following format: </p> <p> <i>HP<sub>init</sub> HP<sub>max</sub></i><br> <i>R C</i><br> <i>a</i><sub>1,1</sub> <i>a</i><sub>1,2</sub> ... <i>a</i><sub>1,<i>C</i></sub><br> <i>a</i><sub>2,1</sub> <i>a</i><sub>2,2</sub> ... <i>a</i><sub>2,<i>C</i></sub><br> .<br> .<br> .<br> <i>a</i><sub><i>R</i>,1</sub> <i>a</i><sub><i>R</i>,2</sub> ... <i>a</i><sub><i>R</i>,<i>C</i></sub><br> <i>T</i><br> [<span>A-Z</span>] <i>d</i><sub>1</sub><br> [<span>A-Z</span>] <i>d</i><sub>2</sub><br> .<br> .<br> .<br> [<span>A-Z</span>] <i>d</i><sub><i>T</i></sub><br> <i>S</i><br> [<span>UDLR</span>] <i>n</i><sub>1</sub><br> [<span>UDLR</span>] <i>n</i><sub>2</sub><br> .<br> .<br> .<br> [<span>UDLR</span>] <i>n</i><sub><i>S</i></sub><br> <i>P</i><br> <i>p</i><sub>1</sub><br> <i>p</i><sub>2</sub><br> .<br> .<br> .<br> <i>p</i><sub><i>P</i></sub><br> </p> <p> The first line of a dataset contains two integers <i>HP<sub>init</sub></i> and <i>HP<sub>max</sub></i> (0 &lt; <i>HP<sub>init</sub></i> &le; <i>HP<sub>max</sub></i> &le; 1000), meaning the agent's initial hit point and the agent’s maximum hit point respectively. </p> <p> The next line consists of <i>R</i> and <i>C</i> (1 &le; <i>R</i>, <i>C</i> &le; 100). Then, <i>R</i> lines which made of <i>C</i> characters representing the information of the cave follow. The character <i>a<sub>i,j</sub></i> means there are the trap of type <i>a<sub>i,j</sub></i> in <i>i</i>-th row and <i>j</i>-th column, and the type of trap is denoted as an uppercase alphabetic character [<span>A-Z</span>]. </p> <p> The next line contains an integer <i>T</i>, which means how many type of traps to be described. The following <i>T</i> lines contains a uppercase character [<span>A-Z</span>] and an integer <i>d<sub>i</sub></i> (0 &le; <i>d<sub>i</sub></i> &le; 1000), representing the type of trap and the amount of damage it gives. </p> <p> The next line contains an integer <i>S</i> (0 &le; <i>S</i> &le; 1000) representing the number of sequences which the hero specified as the agent's patrol route. Then, <i>S</i> lines follows containing a character and an integer <i>n<sub>i</sub></i> ( &sum;<sup><i>S</i></sup><sub><i>i</i>=1</sub> <i>n<sub>i</sub></i> &le; 1000), meaning the direction where the agent advances and the number of step he takes toward that direction. The direction character will be one of '<span>U</span>', '<span>D</span>', '<span>L</span>', '<span>R</span>' for Up, Down, Left, Right respectively and indicates the direction of the step. </p> <p> Finally, the line which contains an integer <i>P</i> (0 &le; <i>P</i> &le; 12) meaning how many type of potions the agent has follows. The following <i>P</i> lines consists of an integer <i>p<sub>i</sub></i> (0 &lt; <i>p<sub>i</sub></i> &le; 1000) which indicated the amount of hit point it recovers. The input is terminated by a line with two zeros. This line should not be processed. </p> <H2>Output</H2> <p> For each dataset, print in a line "<span>YES</span>" if the agent finish his patrol successfully, or "<span>NO</span>" otherwise. </p> <p> If the agent's hit point becomes less than or equal to 0 at the end of his patrol, the output should be "<span>NO</span>". </p> <H2>Sample Input</H2> <pre> 1 10 3 3 AAA ABA CCC 3 A 0 B 5 C 9 3 D 2 R 1 U 2 5 10 10 10 10 10 100 100 10 10 THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN 8 T 0 H 1 I 2 S 3 A 4 P 5 E 6 N 7 9 R 1 D 3 R 8 D 2 L 9 D 2 R 9 D 2 L 9 2 20 10 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO </pre>
p00989
<h2>Draw in Straight Lines</h2> <P> You plan to draw a black-and-white painting on a rectangular canvas. The painting will be a grid array of pixels, either black or white. You can paint black or white lines or dots on the initially white canvas. </p> <p> You can apply a sequence of the following two operations in any order. </p> <ul> <li> Painting pixels on a horizontal or vertical line segment, single pixel wide and two or more pixel long, either black or white. This operation has a cost proportional to the length (the number of pixels) of the line segment multiplied by a specified coefficient in addition to a specified constant cost. </li> <li> Painting a single pixel, either black or white. This operation has a specified constant cost. </li> </ul> <p> You can overpaint already painted pixels as long as the following conditions are satisfied. </p> <ul> <li> The pixel has been painted at most once before. Overpainting a pixel too many times results in too thick layers of inks, making the picture look ugly. Note that painting a pixel with the same color is also counted as overpainting. For instance, if you have painted a pixel with black twice, you can paint it neither black nor white anymore. </li> <li> The pixel once painted white should not be overpainted with the black ink. As the white ink takes very long to dry, overpainting the same pixel black would make the pixel gray, rather than black. The reverse, that is, painting white over a pixel already painted black, has no problem. </li> </ul> <p> Your task is to compute the minimum total cost to draw the specified image. </p> <h3>Input</h3> <p> The input consists of a single test case. The first line contains five integers $n$, $m$, $a$, $b$, and $c$, where $n$ ($1 \leq n \leq 40$) and $m$ ($1 \leq m \leq 40$) are the height and the width of the canvas in the number of pixels, and $a$ ($0 \leq a \leq 40$), $b$ ($0 \leq b \leq 40$), and $c$ ($0 \leq c \leq 40$) are constants defining painting costs as follows. Painting a line segment of length $l$ costs $al + b$ and painting a single pixel costs $c$. These three constants satisfy $c \leq a + b$. </p> <p> The next $n$ lines show the black-and-white image you want to draw. Each of the lines contains a string of length $m$. The $j$-th character of the $i$-th string is ‘<span>#</span>’ if the color of the pixel in the $i$-th row and the $j$-th column is to be black, and it is ‘<span>.</span>’ if the color is to be white. </p> <h3>Output</h3> <p> Output the minimum cost. </p> <h3>Sample Input 1 </h3> <pre> 3 3 1 2 3 .#. ### .#. </pre> <h3>Sample Output 1</h3> <pre> 10 </pre> <h3>Sample Input 2 </h3> <pre> 2 7 0 1 1 ###.### ###.### </pre> <h3>Sample Output 2</h3> <pre> 3 </pre> <h3>Sample Input 3 </h3> <pre> 5 5 1 4 4 ..#.. ..#.. ##.## ..#.. ..#.. </pre> <h3>Sample Output 3</h3> <pre> 24 </pre> <h3>Sample Input 4 </h3> <pre> 7 24 1 10 10 ###...###..#####....###. .#...#...#.#....#..#...# .#..#......#....#.#..... .#..#......#####..#..... .#..#......#......#..... .#...#...#.#.......#...# ###...###..#........###. </pre> <h3>Sample Output 4</h3> <pre> 256 </pre>
p01731
<p>Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. </p> <p>Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. </p> <p>Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. </p> <p>Let us take an example. Suppose: a user made an opening post with a message <code>hoge</code>; another user replied to it with <code>fuga</code>; yet another user also replied to the opening post with <code>piyo</code>; someone else replied to the second post (i.e. <code>fuga</code>”) with <code>foobar</code>; and the fifth user replied to the same post with <code>jagjag</code>. The tree of this thread would look like: </p> <pre>hoge ├─fuga │ ├─foobar │ └─jagjag └─piyo </pre> <p>For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like: </section> <pre>hoge .fuga ..foobar ..jagjag .piyo </pre> <p>Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread. </p> <h3>Input</h3> <p>Input contains a single dataset in the following format: </p> <pre> <var>n</var> <var>k_1</var> <var>M_1</var> <var>k_2</var> <var>M_2</var> : : <var>k_n</var> <var>M_n</var> </pre> <p>The first line contains an integer <var>n</var> (<var>1 &le; n &le; 1,000</var>), which is the number of posts in the thread. Then <var>2n</var> lines follow. Each post is represented by two lines: the first line contains an integer <var>k_i</var> (<var>k_1 = 0</var>, <var>1 &le; k_i < i</var> for <var>2 &le; i &le; n</var>) and indicates the <var>i</var>-th post is a reply to the <var>k_i</var>-th post; the second line contains a string <var>M_i</var> and represents the message of the <var>i</var>-th post. <var>k_1</var> is always 0, which means the first post is not replying to any other post, i.e. it is an opening post. </p> <p>Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters. </p> <h3>Output</h3> <p>Print the given <var>n</var> messages as specified in the problem statement. </p> <h3>Sample Input 1</h3> <pre>1 0 icpc </pre> <h3>Output for the Sample Input 1</h3> <pre>icpc </pre> <h3>Sample Input 2</h3> <pre>5 0 hoge 1 fuga 1 piyo 2 foobar 2 jagjag </pre> <h3>Output for the Sample Input 2</h3> <pre>hoge .fuga ..foobar ..jagjag .piyo </pre> <h3>Sample Input 3</h3> <pre>8 0 jagjag 1 hogehoge 1 buhihi 2 fugafuga 4 ponyoponyo 5 evaeva 4 nowawa 5 pokemon </pre> <h3>Output for the Sample Input 3</h3> <pre>jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi </pre> <h3>Sample Input 4</h3> <pre>6 0 nakachan 1 fan 2 yamemasu 3 nennryou2 4 dannyaku4 5 kouzai11 </pre> <h3>Output for the Sample Input 4</h3> <pre>nakachan .fan ..yamemasu ...nennryou2 ....dannyaku4 .....kouzai11 </pre> <h3>Sample Input 5</h3> <pre>34 0 LoveLive 1 honoka 2 borarara 2 sunohare 2 mogyu 1 eri 6 kasikoi 7 kawaii 8 eriichika 1 kotori 10 WR 10 haetekurukotori 10 ichigo 1 umi 14 love 15 arrow 16 shoot 1 rin 18 nyanyanya 1 maki 20 6th 20 star 22 nishikino 1 nozomi 24 spiritual 25 power 1 hanayo 27 darekatasukete 28 chottomattete 1 niko 30 natsuiro 30 nikkonikkoni 30 sekaino 33 YAZAWA </pre> <h3>Output for the Sample Input 5</h3> <pre>LoveLive .honoka ..borarara ..sunohare ..mogyu .eri ..kasikoi ...kawaii ....eriichika .kotori ..WR ..haetekurukotori ..ichigo .umi ..love ...arrow ....shoot .rin ..nyanyanya .maki ..6th ..star ...nishikino .nozomi ..spiritual ...power .hanayo ..darekatasukete ...chottomattete .niko ..natsuiro ..nikkonikkoni ..sekaino ...YAZAWA </pre> <h3>Sample Input 6</h3> <pre>6 0 2ch 1 1ostu 1 2get 1 1otsu 1 1ostu 3 pgr </pre> <h3>Output for the Sample Input 6</h3> <pre>2ch .1ostu .2get ..pgr .1otsu .1ostu </pre>
p00823
<H1><font color="#000">Problem E:</font> Molecular Formula</H1> <p> Your mission in this problem is to write a computer program that manipulates molecular for- mulae in <i>virtual chemistry</i>. As in real chemistry, each molecular formula represents a molecule consisting of one or more atoms. However, it may not have chemical reality. </p> <p> The following are the definitions of atomic symbols and molecular formulae you should consider. </p> <ul> <li> An atom in a molecule is represented by an atomic symbol, which is either a single capital letter or a capital letter followed by a small letter. For instance H and He are atomic symbols. </li> <li> A molecular formula is a non-empty sequence of atomic symbols. For instance, HHHeHHHe is a molecular formula, and represents a molecule consisting of four H’s and two He’s. </li> <li> For convenience, a repetition of the same sub-formula <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_molecularFormula1"> where <i>n</i> is an integer between 2 and 99 inclusive, can be abbreviated to (<i>X</i>)<i>n</i>. Parentheses can be omitted if X is an atomic symbol. For instance, HHHeHHHe is also written as H2HeH2He, (HHHe)2, (H2He)2, or even ((H)2He)2.</li> </ul> <p> The set of all molecular formulae can be viewed as a formal language. Summarizing the above description, the syntax of molecular formulae is defined as follows. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_molecularFormula2"> </center> <p> Each atom in our virtual chemistry has its own atomic weight. Given the weights of atoms, your program should calculate the weight of a molecule represented by a molecular formula. The molecular weight is defined by the sum of the weights of the constituent atoms. For instance, assuming that the atomic weights of the atoms whose symbols are H and He are 1 and 4, respectively, the total weight of a molecule represented by (H2He)2 is 12. </p> <H2>Input</H2> <p> The input consists of two parts. The first part, the Atomic Table, is composed of a number of lines, each line including an atomic symbol, one or more spaces, and its atomic weight which is a positive integer no more than 1000. No two lines include the same atomic symbol. </p> <p> The first part ends with a line containing only the string END OF FIRST PART. </p> <p> The second part of the input is a sequence of lines. Each line is a molecular formula, not exceeding 80 characters, and contains no spaces. A molecule contains at most 10<sup>5</sup> atoms. Some atomic symbols in a molecular formula may not appear in the Atomic Table. </p> <p> The sequence is followed by a line containing a single zero, indicating the end of the input. </p> <H2>Output</H2> <p> The output is a sequence of lines, one for each line of the second part of the input. Each line contains either an integer, the molecular weight for a given molecular formula in the correspond- ing input line if all its atomic symbols appear in the Atomic Table, or UNKNOWN otherwise. No extra characters are allowed. </p> <H2>Sample Input</H2> <pre> H 1 He 4 C 12 O 16 F 19 Ne 20 Cu 64 Cc 333 END_OF_FIRST_PART H2C (MgF)2As Cu(OH)2 H((CO)2F)99 0 </pre> <H2>Output for the Sample Input</H2> <pre> 14 UNKNOWN 98 7426 </pre>
p04026
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given a string <var>t</var>, we will call it <em>unbalanced</em> if and only if the length of <var>t</var> is at least <var>2</var>, and more than half of the letters in <var>t</var> are the same. For example, both <code>voodoo</code> and <code>melee</code> are unbalanced, while neither <code>noon</code> nor <code>a</code> is.</p> <p>You are given a string <var>s</var> consisting of lowercase letters. Determine if there exists a (contiguous) substring of <var>s</var> that is unbalanced. If the answer is positive, show a position where such a substring occurs in <var>s</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≩ |s| ≩ 10^5</var></li> <li><var>s</var> consists of lowercase letters.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>200</var> points will be awarded for passing the test set satisfying <var>2 ≩ N ≩ 100</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>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists no unbalanced substring of <var>s</var>, print <code>-1 -1</code>.</p> <p>If there exists an unbalanced substring of <var>s</var>, let one such substring be <var>s_a s_{a+1} ... s_{b}</var> <var>(1 ≩ a &lt; b ≩ |s|)</var>, and print <code><var>a</var> <var>b</var></code>. If there exists more than one such substring, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>needed </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 5 </pre> <p>The string <var>s_2 s_3 s_4 s_5</var> <var>=</var> <code>eede</code> is unbalanced. There are also other unbalanced substrings. For example, the output <code>2 6</code> will also be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>atcoder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 -1 </pre> <p>The string <code>atcoder</code> contains no unbalanced substring.</p></section> </div> </span>
p01224
<h1><font color="#000">Problem B:</font> 完党数</h1> <p> ある敎数 <var>N</var> に察しその数自身を陀く玄数の和を <var>S</var> ずする <var>N</var> = <var>S</var> のずき <var>N</var> は完党数 (perfect number) <var>N</var> &gt; <var>S</var> のずき <var>N</var> は䞍足数 (deficient number) <var>N</var> &lt; <var>S</var> のずき <var>N</var> は過剰数 (abundant number) ず呌ばれる 䞎えられた敎数が完党数・䞍足数・過剰数のどれであるかを 刀定するプログラムを䜜成せよ </p> <p> プログラムの実行時間が制限時間を越えないように泚意するこず </p> <h2>Input</h2> <p> 入力はデヌタセットの䞊びからなる デヌタセットの数は 100 以䞋である </p> <p> 各デヌタセットは敎数 <var>N</var> (0 &lt; <var>N</var> &le; 100000000) のみを含む1行からなる </p> <p> 最埌のデヌタセットの埌に入力の終わりを瀺す 0 ず曞かれた1行がある </p> <h2>Output</h2> <p> 各デヌタセットに察し 敎数 <var>N</var> が完党数ならば &ldquo;<code>perfect number</code>&rdquo; 䞍足数ならば &ldquo;<code>deficient number</code>&rdquo; 過剰数ならば &ldquo;<code>abundant number</code>&rdquo; ずいう文字列を 1行に出力せよ </p> <h2>Sample Input</h2> <pre> 1 2 3 4 6 12 16 28 33550336 99999998 99999999 100000000 0 </pre> <h2>Output for the Sample Input</h2> <pre> deficient number deficient number deficient number deficient number perfect number abundant number deficient number perfect number perfect number deficient number deficient number abundant number </pre>
p03219
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a train going from Station <var>A</var> to Station <var>B</var> that costs <var>X</var> yen (the currency of Japan).</p> <p>Also, there is a bus going from Station <var>B</var> to Station <var>C</var> that costs <var>Y</var> yen.</p> <p>Joisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station <var>A</var> to Station <var>B</var> by train and then travels from Station <var>B</var> to Station <var>C</var> by bus.</p> <p>How much does it cost to travel from Station <var>A</var> to Station <var>C</var> if she uses this ticket?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X,Y \leq 100</var></li> <li><var>Y</var> is an even number.</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>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it costs <var>x</var> yen to travel from Station <var>A</var> to Station <var>C</var>, print <var>x</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>81 58 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>110 </pre> <ul> <li>The train fare is <var>81</var> yen.</li> <li>The train fare is <var>58</var> ⁄ <var>2=29</var> yen with the <var>50</var>% discount.</li> </ul> <p>Thus, it costs <var>110</var> yen to travel from Station <var>A</var> to Station <var>C</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 54 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>31 </pre></section> </div> </span>
p01674
<h2>H - Rings</h2> <h3>Problem Statement</h3> <p> There are two circles with radius 1 in 3D space. Please check two circles are connected as chained rings. </p> <h3>Input</h3> <p> The input is formatted as follows. </p> <pre> <var>{c_x}_1</var> <var>{c_y}_1</var> <var>{c_z}_1</var> <var>{v_x}_{1,1}</var> <var>{v_y}_{1,1}</var> <var>{v_z}_{1,1}</var> <var>{v_x}_{1,2}</var> <var>{v_y}_{1,2}</var> <var>{v_z}_{1,2}</var> <var>{c_x}_2</var> <var>{c_y}_2</var> <var>{c_z}_2</var> <var>{v_x}_{2,1}</var> <var>{v_y}_{2,1}</var> <var>{v_z}_{2,1}</var> <var>{v_x}_{2,2}</var> <var>{v_y}_{2,2}</var> <var>{v_z}_{2,2}</var> </pre> <p> First line contains three real numbers(<var>-3 \leq {c_x}_i, {c_y}_i, {c_z}_i \leq 3</var>). It shows a circle's center position. Second line contains six real numbers(<var>-1 \leq {v_x}_{i,j}, {v_y}_{i,j}, {v_z}_{i,j} \leq 1</var>). A unit vector (<var>{v_x}_{1,1}, {v_y}_{1,1}, {v_z}_{1,1}</var>) is directed to the circumference of the circle from center of the circle. The other unit vector (<var>{v_x}_{1,2}, {v_y}_{1,2}, {v_z}_{1,2}</var>) is also directed to the circumference of the circle from center of the circle. These two vectors are orthogonalized. Third and fourth lines show the other circle information in the same way of first and second lines. There are no cases that two circles touch. </p> <h3>Output</h3> <p> If two circles are connected as chained rings, you should print "YES". The other case, you should print "NO". (quotes for clarity) </p> <h3>Sample Input 1</h3> <pre> 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.5 1.0 0.0 0.0 0.0 0.0 1.0 </pre> <h3>Output for the Sample Input 1</h3> <pre> YES </pre> <h3>Sample Input 2</h3> <pre> 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 3.0 0.0 0.0 1.0 0.0 -1.0 0.0 0.0 </pre> <h3>Output for the Sample Input 2</h3> <pre> NO </pre> <h3>Sample Input 3</h3> <pre> 1.2 2.3 -0.5 1.0 0.0 0.0 0.0 1.0 0.0 1.1 2.3 -0.4 1.0 0.0 0.0 0.0 0.70710678 0.70710678 </pre> <h3>Output for the Sample Input 3</h3> <pre> YES </pre> <h3>Sample Input 4</h3> <pre> 1.2 2.3 -0.5 1.0 0.0 0.0 0.0 1.0 0.0 1.1 2.7 -0.1 1.0 0.0 0.0 0.0 0.70710678 0.70710678 </pre> <h3>Output for the Sample Input 4</h3> <pre> NO </pre>
p03649
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a sequence of length <var>N</var> consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes <var>N-1</var> or smaller. (The operation is the same as the one in Problem D.)</p> <ul> <li>Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by <var>N</var>, and increase each of the other elements by <var>1</var>.</li> </ul> <p>It can be proved that the largest element in the sequence becomes <var>N-1</var> or smaller after a finite number of operations.</p> <p>You are given the sequence <var>a_i</var>. Find the number of times we will perform the above operation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 50</var></li> <li><var>0 ≀ a_i ≀ 10^{16} + 1000</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>a_2</var> ... <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of times the operation will be performed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 0 3 </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 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>7 27 0 0 0 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>10 1000 193 256 777 0 1 1192 1234567891011 48 425 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>1234567894848 </pre></section> </div> </span>
p00966
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <h2>Problem J String Puzzle </h2> <p> <i>Amazing Coding Magazine</i> is popular among young programmers for its puzzle solving contests offering catchy digital gadgets as the prizes. The magazine for programmers naturally encourages the readers to solve the puzzles by writing programs. Let's give it a try! </p> <p> The puzzle in the latest issue is on deciding some of the letters in a string (<i>the secret string</i>, in what follows) based on a variety of hints. The figure below depicts an example of the given hints. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_stringPuzzle" width="480"> </center> <p> The first hint is the number of letters in the secret string. In the example of the figure above, it is nine, and the nine boxes correspond to nine letters. The letter positions (boxes) are numbered starting from 1, from the left to the right. </p> <p> The hints of the next kind simply tell the letters in the secret string at some speci c positions. In the example, the hints tell that the letters in the 3rd, 4th, 7th, and 9th boxes are <span>C</span>, <span>I</span>, <span>C</span>, and <span>P</span., respectively. </p> <p> The hints of the final kind are on duplicated substrings in the secret string. The bar immediately below the boxes in the figure is partitioned into some sections corresponding to substrings of the secret string. Each of the sections may be connected by a line running to the left with another bar also showing an extent of a substring. Each of the connected pairs indicates that substrings of the two extents are identical. One of this kind of hints in the example tells that the letters in boxes 8 and 9 are identical to those in boxes 4 and 5, respectively. From this, you can easily deduce that the substring is <span>IP</span>. </p> <p> Note that, not necessarily all of the identical substring pairs in the secret string are given in the hints; some identical substring pairs may not be mentioned. </p> <p> Note also that two extents of a pair may overlap each other. In the example, the two-letter substring in boxes 2 and 3 is told to be identical to one in boxes 1 and 2, and these two extents share the box 2. </p> <p> In this example, you can decide letters at all the positions of the secret string, which are "<span>CCCIPCCIP</span>". In general, the hints may not be enough to decide all the letters in the secret string. </p> <p> The answer of the puzzle should be letters at the specified positions of the secret string. When the letter at the position specified cannot be decided with the given hints, the symbol <span>?</span> should be answered. </p> <h3>Input</h3> <p> The input consists of a single test case in the following format. </p> <pre> $n$ $a$ $b$ $q$ $x_1$ $c_1$ ... $x_a$ $c_a$ $y_1$ $h_1$ ... $y_b$ $h_b$ $z_1$ ... $z_q$ </pre> <p> The first line contains four integers $n$, $a$, $b$, and $q$. $n$ ($1 \leq n \leq 10^9$) is the length of the secret string, $a$ ($0 \leq a \leq 1000$) is the number of the hints on letters in specified positions, $b$ ($0 \leq b \leq 1000$) is the number of the hints on duplicated substrings, and $q$ ($1 \leq q \leq 1000$) is the number of positions asked. </p> <p> The $i$-th line of the following a lines contains an integer $x_i$ and an uppercase letter $c_i$ meaning that the letter at the position $x_i$ of the secret string is $c_i$. These hints are ordered in their positions, i.e., $1 \leq x_1 < ... < x_a \leq n$. </p> <p> The $i$-th line of the following $b$ lines contains two integers, $y_i$ and $h_i$. It is guaranteed that they satisfy $2 \leq y_1 < ... < y_b \leq n$ and $0 \leq h_i < y_i$. When $h_i$ is not 0, the substring of the secret string starting from the position $y_i$ with the length $y_{i+1} - y_i$ (or $n+1-y_i$ when $i = b$) is identical to the substring with the same length starting from the position $h_i$. Lines with $h_i = 0$ does not tell any hints except that $y_i$ in the line indicates the end of the substring specified in the line immediately above. </p> <p> Each of the following $q$ lines has an integer $z_i$ ($1 \leq z_i \leq n$), specifying the position of the letter in the secret string to output. </p> <p> It is ensured that there exists at least one secret string that matches all the given information. In other words, the given hints have no contradiction. </p> <h3>Output</h3> <p> The output should be a single line consisting only of $q$ characters. The character at position $i$ of the output should be the letter at position $z_i$ of the the secret string if it is uniquely determined from the hints, or <span>?</span> otherwise. </p> <h3>Sample Input 1</h3> <pre> 9 4 5 4 3 C 4 I 7 C 9 P 2 1 4 0 6 2 7 0 8 4 8 1 9 6 </pre> <h3>Sample Output 1</h3> <pre> ICPC </pre> <h3>Sample Input 2</h3> <pre> 1000000000 1 1 2 20171217 A 3 1 42 987654321 </pre> <h3>Sample Output 2</h3> <pre> ?A </pre>
p02408
<H1>Finding Missing Cards</H1> <p> Taro is going to play a card game. However, now he has only <var>n</var> cards, even though there should be 52 cards (he has no Jokers). </p> <p> The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond. </p> <H2>Input</H2> <p> In the first line, the number of cards <var>n</var> (<var>n</var> &le; 52) is given. </p> <p> In the following <var>n</var> lines, data of the <var>n</var> cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13. </p> <H2>Output</H2> <p> Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities: </p> <ul> <li>Print cards of spades, hearts, clubs and diamonds in this order.</li> <li>If the suits are equal, print cards with lower ranks first.</li> </ul> <H2>Sample Input</H2> <pre> 47 S 10 S 11 S 12 S 13 H 1 H 2 S 6 S 7 S 8 S 9 H 6 H 8 H 9 H 10 H 11 H 4 H 5 S 2 S 3 S 4 S 5 H 12 H 13 C 1 C 2 D 1 D 2 D 3 D 4 D 5 D 6 D 7 C 3 C 4 C 5 C 6 C 7 C 8 C 9 C 10 C 11 C 13 D 9 D 10 D 11 D 12 D 13 </pre> <H2>Sample Output</H2> <pre> S 1 H 3 H 7 C 12 D 8 </pre> <h2>Note</h2> <center> <a href="commentary.jsp?id=ITP1_6_B"> <div class="button">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解説&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div> </a> </center>
p00435
<H1>シヌザヌ暗号</H1> <h2>問題</h2> <p> ガむりス・ナリりス・カ゚サルGaius Julius Caesar)英語読みでゞュリアス・シヌザヌJulius Caesarは叀代ロヌマの軍人であり政治家であるカ゚サルは秘密の手玙を曞くずきに 'A' を 'D' に 'B' を 'E' に 'C' を 'F' にずいうように3぀ずらしお衚蚘したずいう蚘録が残っおいる </p> <p> 倧文字のアルファベット26文字だけからなる文字列をカ゚サルがしたように3文字ず぀ずらす倉換を斜し埗られた文字列があるこのような文字列を元の文字列に戻すプログラムを䜜成せよ </p> <p> 各文字の倉換前ず倉換埌の察応は次のようになる </p> <table style="margin-left:28px; margin-bottom:28px"> <tr> <td width="80">倉換前</td> <td width="30">A</td> <td width="30">B</td> <td width="30">C</td> <td width="30">D</td> <td width="30">E</td> <td width="30">F</td> <td width="30">G</td> <td width="30">H</td> <td width="30">I</td> <td width="30">J</td> <td width="30">K</td> <td width="30">L</td> <td width="30">M</td> <td width="30">N</td> <td width="30">O</td> <td width="30">P</td> <td width="30">Q</td> <td width="30">R</td> <td width="30">S</td> <td width="30">T</td> <td width="30">U</td> <td width="30">V</td> <td width="30">W</td> <td width="30">X</td> <td width="30">Y</td> <td width="30">Z</td> </tr> <tr> <td>倉換埌</td> <td>D</td> <td>E</td> <td>F</td> <td>G</td> <td>H</td> <td>I</td> <td>J</td> <td>K</td> <td>L</td> <td>M</td> <td>N</td> <td>O</td> <td>P</td> <td>Q</td> <td>R</td> <td>S</td> <td>T</td> <td>U</td> <td>V</td> <td>W</td> <td>X</td> <td>Y</td> <td>Z</td> <td>A</td> <td>B</td> <td>C </td> </tr> </table> <p> 䟋えばこの方法で文字列 JOI を倉換するず MRL が埗られこの方法で倉換された文字列 FURDWLD の元の文字列は CROATIA である </p> <H2>入力</H2> <p> 入力は1行だけからなりその1行は倧文字のアルファベットのみで構成される文字列を1぀含む </p> <p> 入力される文字列の長さは 1000 以䞋である </p> <H2>出力</H2> <p> <!--提出する出力ファむルは、入力された文字列を元に戻した文字列だけを含む1行を出力する。--> 入力された文字列を元に戻した文字列だけを含む1行を出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre>MRL</pre> <h3>出力䟋 1</h3> <pre> JOI </pre> <br> <h3>入力䟋 2</h3> <pre>FURDWLD</pre> <h3>出力䟋 2</h3> <pre>CROATIA</pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02058
<h2>G: Tree</h2> <h3>問題</h3> <p><var>N</var> 頂点からなる朚が䞎えられたす。朚の各頂点には <var>1</var> から <var>N</var> の番号が割り振られおいたす。たた、<var>N−1</var> 本の蟺のうち、 <var>i\ (= 1, 2, ..., N-1)</var> 本目の蟺は頂点 <var>u_i</var> ず頂点 <var>v_i</var> ずを結んでいたす。</p> <p>この朚の <var>K</var> 個の空でない郚分グラフの組であっお、各郚分グラフがいずれも連結で、どの二぀の盞異なる郚分グラフも頂点を共有しないものの個数を求めるプログラムを䜜成しおください。ただし答えがずおも倧きくなるこずがあるため、<var>998244353</var> で割ったあたりを答えおください。</p> <p>なお、<var>K</var> 個の郚分グラフからなる集合が同䞀のものは、<var>K</var> 個の郚分グラフの順序が異なるものも同䞀芖するものずしたす。</p> <h3>入力圢匏</h3> <pre> <var>N</var> <var>K</var> <var>u_1</var> <var>v_1</var> <var>:</var> <var>u_{N-1}</var> <var>v_{N-1}</var> </pre> <h3>制玄</h3> <ul> <li> <var>2 \leq N \leq 10^{5}</var></li> <li> <var>1 \leq K \leq min ( N, 300 )</var></li> <li> <var>1 \leq u_i, v_i \leq N</var></li> <li> <var>u_i \neq v_i</var></li> <li> <var>i \neq j</var> に察しお <var>(u_i, v_i) \neq (u_j, v_j)</var></li> <li> 入力はすべお敎数で䞎えられる。</li> <li> 䞎えられるグラフは朚であるこずが保蚌される。</li> </ul> <h3>出力圢匏</h3> <p>答えを衚す敎数を䞀行に出力しおください。<var>998244353</var> で割ったあたりを出力するこずに泚意しおください。</p> <h3>入力䟋 1</h3> <pre> 3 2 1 2 1 3 </pre> <h3>出力䟋 1</h3> <pre>5</pre> <p>以䞋の <var>5</var> 通りがありたす:</p> <ul> <li> <var>\{ 1 \}</var> ず <var>\{ 2 \}</var></li> <li> <var>\{ 1 \}</var> ず <var>\{ 3 \}</var></li> <li> <var>\{ 2 \}</var> ず <var>\{ 3 \}</var></li> <li> <var>\{ 1, 2 \}</var> ず <var>\{ 3 \}</var></li> <li> <var>\{ 1, 3 \}</var> ず <var>\{ 2 \}</var></li> </ul> <h3>入力䟋 2</h3> <pre> 4 4 1 2 1 3 1 4 </pre> <h3>出力䟋 2</h3> <pre>1</pre> <p><var>( \{ 1 \}, \{ 2 \}, \{ 3 \}, \{ 4 \} )</var> の <var>1</var> 通りしかありたせん。</p> <h3>入力䟋 3</h3> <pre> 7 4 1 7 2 1 7 4 3 4 5 7 6 3 </pre> <h3>出力䟋 3</h3> <pre>166</pre>
p00065
<H1>取匕</H1> <p> 取匕先の顧客番号ず取匕日を月ごずに蚘録したデヌタがありたす。今月のデヌタず先月のデヌタを読み蟌んで、先月からヶ月連続で取匕のある䌚瀟の顧客番号ず取匕のあった回数を出力するプログラムを䜜成しおください。ただし、月々の取匕先数は 1,000 瀟以内です。 </p> <H2>Input</H2> <p> 今月のデヌタず、先月のデヌタが行の空行で区切られお䞎えられたす。それぞれのデヌタは以䞋のような圢匏で䞎えられたす。 </p> <pre> <var>c<sub>1</sub></var>,<var>d<sub>1</sub></var> <var>c<sub>2</sub></var>,<var>d<sub>2</sub></var> ... ... </pre> <p> <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; 1,000) は顧客番号を衚す敎数、 <var>d<sub>i</sub></var> (1 &le; <var>d<sub>i</sub></var> &le; 31) は取匕日を衚す敎数です。 </p> <H2>Output</H2> <p> ヶ月連続で取匕のある䌚瀟に぀いお、顧客番号が小さい順に顧客番号ず取匕回数の総数を空癜で区切っお出力したす。 </p> <H2>Sample Input</H2> <pre> 123,10 56,12 34,14 123,3 56,4 123,5 </pre> <H2>Output for the Sample Input</H2> <pre> 56 2 123 3 </pre>
p03560
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find the smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq K \leq 10^5</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 smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p><var>12=6×2</var> yields the smallest sum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>41 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p><var>11111=41×271</var> yields the smallest sum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>79992 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>36 </pre></section> </div> </span>
p03130
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are four towns, numbered <var>1,2,3</var> and <var>4</var>. Also, there are three roads. The <var>i</var>-th road connects different towns <var>a_i</var> and <var>b_i</var> bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.</p> <p>Determine if we can visit all the towns by traversing each of the roads exactly once.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq a_i,b_i \leq 4(1\leq i\leq 3)</var></li> <li><var>a_i</var> and <var>b_i</var> are different. <var>(1\leq i\leq 3)</var></li> <li>No two roads connect the same pair of towns.</li> <li>Any town can be reached from any other town using the roads.</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_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>a_3</var> <var>b_3</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If we can visit all the towns by traversing each of the roads exactly once, print <code>YES</code>; otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 1 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>We can visit all the towns in the order <var>1,3,2,4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 2 4 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 3 2 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre></section> </div> </span>
p03999
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of digits between <code>1</code> and <code>9</code>, inclusive. You can insert the letter <code>+</code> into some of the positions (possibly none) between two letters in this string. Here, <code>+</code> must not occur consecutively after insertion.</p> <p>All strings that can be obtained in this way can be evaluated as formulas.</p> <p>Evaluate all possible formulas, and print the sum of the results.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 10</var></li> <li>All letters in <var>S</var> are digits between <code>1</code> and <code>9</code>, inclusive.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the evaluated value over all possible formulas.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>125 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>176 </pre> <p>There are <var>4</var> formulas that can be obtained: <code>125</code>, <code>1+25</code>, <code>12+5</code> and <code>1+2+5</code>. When each formula is evaluated,</p> <ul> <li><var>125</var></li> <li><var>1+25=26</var></li> <li><var>12+5=17</var></li> <li><var>1+2+5=8</var></li> </ul> <p>Thus, the sum is <var>125+26+17+8=176</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9999999999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>12656242944 </pre></section> </div> </span>
p02371
<H1>Diameter of a Tree</H2> <br/> <p> Given a tree <var>T</var> with non-negative weight, find the diameter of the tree. </p> <p> The diameter of a tree is the maximum distance between two nodes in a tree. </p> <H2>Input</H2> <pre> <var>n</var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>1</sub></var> <var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>w<sub>2</sub></var> : <var>s<sub>n-1</sub></var> <var>t<sub>n-1</sub></var> <var>w<sub>n-1</sub></var> </pre> <p> The first line consists of an integer <var>n</var> which represents the number of nodes in the tree. Every node has a unique ID from 0 to <var>n</var>-1 respectively. </p> <p> In the following <var>n</var>-1 lines, edges of the tree are given. <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent end-points of the <var>i</var>-th edge (undirected) and <var>w<sub>i</sub></var> represents the weight (distance) of the <var>i</var>-th edge. </p> <H2>Output</H2> <p> Print the diameter of the tree in a line. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>n</var> &le; 100,000</li> <li> 0 &le; <var>w<sub>i</sub></var> &le; 1,000</li> </ul> <H2>Sample Input 1</H2> <pre> 4 0 1 2 1 2 1 1 3 3 </pre> <H2>Sample Output 1</H2> <pre> 5 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 0 1 1 1 2 2 2 3 4 </pre> <H2>Sample Output 2</H2> <pre> 7 </pre>
p03833
<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> barbecue restaurants along a street. The restaurants are numbered <var>1</var> through <var>N</var> from west to east, and the distance between restaurant <var>i</var> and restaurant <var>i+1</var> is <var>A_i</var>.</p> <p>Joisino has <var>M</var> tickets, numbered <var>1</var> through <var>M</var>. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant <var>i</var> offers a meal of <em>deliciousness</em> <var>B_{i,j}</var> in exchange for ticket <var>j</var>. Each ticket can only be used once, but any number of tickets can be used at a restaurant.</p> <p>Joisino wants to have <var>M</var> barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual <em>happiness</em> is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>2≀N≀5×10^3</var></li> <li><var>1≀M≀200</var></li> <li><var>1≀A_i≀10^9</var></li> <li><var>1≀B_{i,j}≀10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_{N-1}</var> <var>B_{1,1}</var> <var>B_{1,2}</var> <var>...</var> <var>B_{1,M}</var> <var>B_{2,1}</var> <var>B_{2,2}</var> <var>...</var> <var>B_{2,M}</var> <var>:</var> <var>B_{N,1}</var> <var>B_{N,2}</var> <var>...</var> <var>B_{N,M}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print Joisino's maximum possible eventual happiness.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>11 </pre> <p>The eventual happiness can be maximized by the following strategy: start from restaurant <var>1</var> and use tickets <var>1</var> and <var>3</var>, then move to restaurant <var>2</var> and use tickets <var>2</var> and <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 1 2 3 4 10 1 1 1 1 1 1 10 1 1 1 1 1 1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>20 </pre></section> </div> </span>
p02721
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has decided to work on <var>K</var> days of his choice from the <var>N</var> days starting with tomorrow.</p> <p>You are given an integer <var>C</var> and a string <var>S</var>. Takahashi will choose his workdays as follows:</p> <ul> <li>After working for a day, he will refrain from working on the subsequent <var>C</var> days.</li> <li>If the <var>i</var>-th character of <var>S</var> is <code>x</code>, he will not work on Day <var>i</var>, where Day <var>1</var> is tomorrow, Day <var>2</var> is the day after tomorrow, and so on.</li> </ul> <p>Find all days on which Takahashi is bound to work.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>0 \leq C \leq N</var></li> <li>The length of <var>S</var> is <var>N</var>.</li> <li>Each character of <var>S</var> is <code>o</code> or <code>x</code>.</li> <li>Takahashi can choose his workdays so that the conditions in Problem Statement are satisfied.</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>C</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print all days on which Takahashi is bound to work in ascending order, one per line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>11 3 2 ooxxxoxxxoo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>Takahashi is going to work on <var>3</var> days out of the <var>11</var> days. After working for a day, he will refrain from working on the subsequent <var>2</var> days.</p> <p>There are four possible choices for his workdays: Day <var>1,6,10</var>, Day <var>1,6,11</var>, Day <var>2,6,10</var>, and Day <var>2,6,11</var>.</p> <p>Thus, he is bound to work on Day <var>6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 3 ooxoo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 5 </pre> <p>There is only one possible choice for his workdays: Day <var>1,5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 0 ooooo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre></pre> <p>There may be no days on which he is bound to work.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>16 4 3 ooxxoxoxxxoxoxxo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>11 16 </pre></section> </div> </span>
p00209
<H1>写真に写っおいる景色は?</H1> <p> A 君は䌚接に芳光にやっおきたした。宿泊したホテルの窓からは䌚接盆地が䞀望できたす。景色を眺めおいるず、床に写真の切れ端が萜ちおいるのに気が぀きたした。どうやら窓から倖の景色を撮ったようです。「どの蟺りを撮ったのかな」ず、A 君は窓の倖の景色ず写真が同じ倧きさになるように写真をかざしお、写真ず窓の倖の景色が䞀臎する堎所を探し始めたした。 </p> <p> それでは、A 君がやっおいるこずをコンピュヌタでやっおみたしょう。窓の倖の景色を <var>n &times; n</var> マスの正方圢に分割したす (<var>n</var> を景色の倧きさず呌びたす)。各マスには、そのマスの画像の情報を衚す 0 以䞊の敎数が曞かれおいたす。マスの䜍眮は座暙 (<var>x, y</var>) で衚したす。各マスの座暙は以䞋の通りになりたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_reflectedScene1"><br/> </center> <br/> <p> 写真の切れ端は、<var>m &times; m</var> マスの正方圢で衚されたす (<var>m</var> を写真の切れ端の倧きさず呌びたす) 。この正方圢の䞭で、切れ端の郚分のマスには画像の情報が、切れ端に含たれない郚分のマスには -1 が曞かれおいたす。たずえば、䞋図では、色が塗られおいる郚分が実際の写真の切れ端の圢を衚しおいたす。切れ端に穎が開いおいるこずはありたすが、必ず 1 ぀に぀ながっおいたす。 (0 以䞊の倀をも぀マスが頂点だけで接しおいるずきは、぀ながっおいないものずみなしたす。) たた、倀 -1 のマスが瞊たたは暪 1 列に端から端たで䞊ぶこずはありたせん。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_reflectedScene2"> </center> <br> <p> 窓から芋える景色の䞭で、写真の切れ端を 0、90、180、270 床回転させたいずれかず䞀臎する領域を探したす。たずえば、景色が䞋図のように衚わせるずき、䞊図の切れ端を反時蚈回りに90 床回転させるず、色が塗られた領域に䞀臎したす。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_reflectedScene3"> </center> <br> <p> 窓から芋える景色ず写真の切れ端の情報を入力ずし、景色の䞭で、切れ端を 0、90、180、270 床回転させたいずれかず䞀臎する領域の最も䞊端に近いマスのうち、最も巊端に近いマスの座暙を出力するプログラムを䜜成しおください。 </p> <p> 䞀臎する領域が耇数ある堎合は、それらの領域内にあるマスの䞭で、最も䞊端に近いマスのうち、最も巊端に近いマスの座暙を出力しおください。䞀臎する領域がないずきは、NA ず出力したす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>m</var> <var>w<sub>11</sub></var> <var>w<sub>12</sub></var> ... <var>w<sub>1n</sub></var> <var>w<sub>21</sub></var> <var>w<sub>22</sub></var> ... <var>w<sub>2n</sub></var> : <var>w<sub>n1</sub></var> <var>w<sub>n2</sub></var> ... <var>w<sub>nn</sub></var> <var>p<sub>11</sub></var> <var>p<sub>12</sub></var> ... <var>p<sub>1m</sub></var> <var>p<sub>21</sub></var> <var>p<sub>22</sub></var> ... <var>p<sub>2m</sub></var> : <var>p<sub>m1</sub></var> <var>p<sub>m2</sub></var> ... <var>p<sub>mm</sub></var> </pre> <p> 1 行目に<var>n, m</var> (1 &le; <var>n</var> &le; 100, 1 &le; <var>m</var> &le; 50, <var>m</var> &le; <var>n</var>) が䞎えられたす。 </p> <p> 続く <var>n</var> 行に窓から芋える景色の情報 <var>w<sub>ij</sub></var> (0 &le; <var>w<sub>ij</sub></var> &le; 15)、続く <var>m</var> 行に写真の切れ端のデヌタの情報 <var>p<sub>ij</sub></var> (-1 &le; <var>p<sub>ij</sub></var> &le; 15) が䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、マスの䜍眮の座暙たたは NA を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 8 4 2 1 3 1 1 5 1 3 2 3 2 4 1 0 2 1 0 3 1 2 1 1 4 2 1 2 3 2 1 1 5 4 0 2 0 1 1 3 2 1 1 3 1 2 2 4 3 2 5 1 2 1 4 1 1 5 4 1 1 0 1 2 2 1 2 -1 -1 -1 0 3 -1 -1 -1 2 2 4 -1 1 -1 1 5 3 1 0 2 3 5 2 3 7 2 1 2 5 4 2 2 8 9 0 3 3 3 6 0 4 7 -1 -1 2 -1 3 5 0 4 -1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4 2 NA </pre>
p02234
<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>Matrix-chain Multiplication</H1> <p> The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$. </p> <p> Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication $M_1M_2...M_n$. </p> <H2>Input</H2> <p> In the first line, an integer $n$ is given. In the following $n$ lines, the dimension of matrix $M_i$ ($i = 1...n$) is given by two integers $r$ and $c$ which respectively represents the number of rows and columns of $M_i$. </p> <H2>Output</H2> <p> Print the minimum number of scalar multiplication in a line. </p> <H2>Constraints</H2> <ul> <li>$1 \leq n \leq 100$</li> <li>$1 \leq r, c \leq 100$</li> </ul> <H2>Sample Input 1</H2> <pre> 6 30 35 35 15 15 5 5 10 10 20 20 25 </pre> <H2>Sample Output 1</H2> <pre> 15125 </pre>
p03976
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <blockquote> <p> Kyoto University Programming Contest is a programming contest voluntarily held by some Kyoto University students. This contest is abbreviated as <b>K</b>yoto <b>U</b>niversity <b>P</b>rogramming <b>C</b>ontest and called KUPC. </p> <p> source: <a href="http://www.kupc.jp/index.html"><i>Kyoto University Programming Contest Information</i></a> </p> </blockquote> <p> The problem-preparing committee met to hold this year's KUPC and <var>N</var> problems were proposed there. The problems are numbered from <var>1</var> to <var>N</var> and the name of <var>i</var>-th problem is <var>P_i</var>. However, since they proposed too many problems, they decided to divide them into some sets for several contests. </p> <p> They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions. <ul> <li> One KUPC provides <var>K</var> problems. </li> <li> Each problem appears at most once among all the KUPCs. </li> <li> All the first letters of the problem names in one KUPC must be different. </li> </ul> </p> <p> You, one of the committee members, want to hold as many KUPCs as possible. Write a program to find the maximum number of KUPCs that can be held this year. </p> <h3>Constraints</h3> <ul> <li> <var>1 \leq N \leq 10^4</var></li> <li> <var>1 \leq K \leq 26</var></li> <li> <var>1 \leq |P_i| \leq 10</var></li> <li> All characters in <var>P_i</var> are capital letters.</li> </ul> <p> Note that, for each <var>i</var> and <var>j</var> <var>(1 \leq i &lt; j \leq N)</var>, <var>P_i \neq P_j</var> are not necessarily satisfied. </p> </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>P_1</var> : <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p> Print the maximum number of KUPCs that can be held on one line. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 9 3 APPLE ANT ATCODER BLOCK BULL BOSS CAT DOG EGG </pre> <p>For example, three KUPCs can be held by dividing the problems as follows. </p> <ul> <li> First: <code>APPLE</code>, <code>BLOCK</code>, <code>CAT</code></li> <li> Second: <code>ANT</code>, <code>BULL</code>, <code>DOG</code></li> <li> Third: <code>ATCODER</code>, <code>BOSS</code>, <code>EGG</code></li> </ul> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 3 2 KU KYOUDAI KYOTOUNIV </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 0 </pre> <p>No KUPC can be held.</p> </section> </div> </span>
p00659
<H1>Problem A: Popularity Estimation</H1> <p> あなたはずあるアニメヌション制䜜䌚瀟の䌁画郚長である。昚今のアニメヌション制䜜䌚瀟が制䜜するものは、アニメヌションそのものにずどたらない。関連商品、䟋えば登堎キャラクタヌのフィギュアやキャラクタヌ゜ングCDなども、重芁な収益源なのである。この収益をどれだけ䌞ばせるかは、ひずえに䌁画郚長のあなたにかかっおいるのであった。 </p> <p> 圓たり前のこずだが、こういった関連商品は闇雲に発売すればいいずいうものではない。商品の開発には倚くの時間ず予算が必芁なためだ。アニメの登堎キャラクタヌのフィギュアを発売するにしおも、倚くの売䞊が芋蟌たれる、人気があるキャラクタヌのものに限らなければならない。 </p> <p> キャラクタヌの人気床を枬る手段の䞀぀が、人気投祚である。あなたも今たでいく぀かの人気投祚を䌁画しおきたが、どうやら芖聎者はこの䌁画に䞍満を抱き぀぀あるようだ。人気床を枬る他の手法の確立が急務である。 </p> <p> そこであなたは、ひず぀の仮説を立おた。あるキャラクタヌの人気床は、そのアニメ本線䞭における登堎時間の総和に比䟋する、ずいうものだ。あなたはこの仮説を怜蚌するため、それぞれのキャラクタヌの登堎時間を集蚈するプログラムを曞くこずにした。 </p> <h2>Input</h2> <p> 入力は耇数のケヌスからなる。 各ケヌスは以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>n</i> <i>name<sub>0</sub></i> <i>m<sub>0</sub></i> <i>d<sub>0,0</sub></i> ... <i>d<sub>0,m<sub>0</sub>-1</sub></i> <i>name<sub>1</sub></i> <i>m<sub>1</sub></i> <i>d<sub>1,0</sub></i> ... <i>d<sub>1,m<sub>1</sub>-1</sub></i> . . . <i>name<sub>n-1</sub></i> <i>m<sub>n-1</sub></i> <i>d<sub>n-1,0</sub></i> ... <i>d<sub>n-1,m<sub>n-1</sub>-1</sub></i> </pre> <p> <i>n</i> はキャラクタヌの人数を衚す。<br> <i>name<sub>i</sub></i> はキャラクタヌの名前を衚す。<br> <i>m<sub>i</sub></i> はキャラクタヌが映っおいた時刻の皮類を衚す。<br> <i>m<sub>i</sub></i> の埌には<i>m<sub>i</sub></i> 個の敎数<i>d<sub>i,j</sub></i> が䞎えられる。<br> <i>d<sub>i,j</sub></i>はキャラクタヌが映っおいた時刻を衚す。<br> 入力の終わりは<i>n=0</i> からなる行によっお䞎えられる<br> </p> <p> ある時刻に1人のキャラクタヌのみが画面に映っおいた堎合、そのキャラクタヌはnポむントを埗るこずが出来る。<br> 同時刻に映るキャラクタヌが1人増える毎に、その時刻に映っおいたキャラクタヌが埗られるポむントは1枛る。<br> n人のキャラクタヌが同時刻に映っおいた堎合、n人の人それぞれに1ポむントが加算される。<br> </p> <p> 入力は以䞋の制玄を満たす。<br> 2 &le; <i>n</i> &le; 20<br> 0 &le; <i>m<sub>i</sub></i> &le; 30<br> 0 &le; <i>d<sub>i,j</sub></i> &lt; 30<br> <i>i</i> 番目のキャラクタヌに぀いお<i>d<sub>i,j</sub></i> はすべお異なる。<br> <i>name<sub>i</sub></i> はアルファベットの倧文字たたは小文字のみを含み、長さは10以䞋である。 </p> <h2>Output</h2> <p> 最小のポむントを持぀キャラクタヌのポむントずその名前を1぀の空癜で区切っお出力せよ。<br> 最小のポむントを持぀キャラクタヌが耇数いる堎合は名前が蟞曞順で最小の人を遞ぶこず。 </p> <h2>Sample input</h2> <pre> 4 akzakr 2 1 8 fnmyi 5 2 3 4 6 9 tsnukk 5 2 3 4 7 9 yskwcnt 6 3 4 7 8 9 10 4 akzakr 1 2 fnmyi 3 10 11 12 tsnukk 2 1 8 yskwcnt 2 1 8 5 knmmdk 2 13 19 akmhmr 4 13 15 19 22 mksyk 6 3 7 12 13 15 19 skrkyk 3 1 4 8 tmemm 3 1 17 24 5 knmmdk 5 5 6 16 18 26 akmhmr 9 3 4 7 11 14 15 17 18 20 mksyk 5 6 13 25 27 28 skrkyk 4 3 16 23 24 tmemm 3 6 12 20 14 hrkamm 6 4 6 8 10 20 22 mkhsi 6 1 10 12 15 22 27 hbkgnh 2 4 9 chyksrg 8 3 4 12 15 16 20 25 28 mktkkc 6 0 1 8 15 17 20 tknsj 6 6 8 18 19 25 26 yyitktk 3 3 12 18 ykhhgwr 5 3 9 10 11 24 amftm 7 2 6 8 12 13 14 17 mmftm 4 6 12 16 18 rtkakzk 3 14 15 21 azsmur 7 1 2 4 12 15 18 20 iormns 2 4 20 ktrotns 6 7 12 14 17 20 25 14 hrkamm 2 4 21 mkhsi 6 2 3 8 11 18 20 hbkgnh 4 4 16 28 29 chyksrg 5 0 3 9 17 22 mktkkc 2 7 18 tknsj 3 3 9 23 yyitktk 3 10 13 25 ykhhgwr 2 18 26 amftm 3 13 18 22 mmftm 4 1 20 24 27 rtkakzk 2 1 10 azsmur 5 2 5 10 14 17 iormns 3 9 15 16 ktrotns 5 7 12 16 17 20 0 </pre> <H2>Sample output</H2> <pre> 7 akzakr 4 akzakr 6 knmmdk 12 tmemm 19 iormns 24 mktkkc </pre> <hr> The University of Aizu Programming Contest 2011 Summer<br> 原案: Tomoya Sakai<br> 問題文: Takashi Tayama<br> </p>
p02664
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For a string <var>S</var> consisting of the uppercase English letters <code>P</code> and <code>D</code>, let the <em>doctoral and postdoctoral quotient</em> of <var>S</var> be the total number of occurrences of <code>D</code> and <code>PD</code> in <var>S</var> as contiguous substrings. For example, if <var>S =</var> <code>PPDDP</code>, it contains two occurrences of <code>D</code> and one occurrence of <code>PD</code> as contiguous substrings, so the doctoral and postdoctoral quotient of <var>S</var> is <var>3</var>.</p> <p>We have a string <var>T</var> consisting of <code>P</code>, <code>D</code>, and <code>?</code>.</p> <p>Among the strings that can be obtained by replacing each <code>?</code> in <var>T</var> with <code>P</code> or <code>D</code>, find one with the maximum possible doctoral and postdoctoral quotient.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |T| \leq 2 \times 10^5</var></li> <li><var>T</var> consists of <code>P</code>, <code>D</code>, and <code>?</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each <code>?</code> in <var>T</var> with <code>P</code> or <code>D</code>. If there are multiple such strings, you may print any of them.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>PD?D??P </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>PDPDPDP </pre> <p>This string contains three occurrences of <code>D</code> and three occurrences of <code>PD</code> as contiguous substrings, so its doctoral and postdoctoral quotient is <var>6</var>, which is the maximum doctoral and postdoctoral quotient of a string obtained by replacing each <code>?</code> in <var>T</var> with <code>P</code> or <code>D</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>P?P? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>PDPD </pre></section> </div> </span>
p03425
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> people. The name of the <var>i</var>-th person is <var>S_i</var>.</p> <p>We would like to choose three people so that the following conditions are met:</p> <ul> <li>The name of every chosen person begins with <code>M</code>, <code>A</code>, <code>R</code>, <code>C</code> or <code>H</code>.</li> <li>There are no multiple people whose names begin with the same letter.</li> </ul> <p>How many such ways are there to choose three people, disregarding order?</p> <p>Note that the answer may not fit into a <var>32</var>-bit integer type.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>S_i</var> consists of uppercase English letters.</li> <li><var>1 \leq |S_i| \leq 10</var></li> <li><var>S_i \neq S_j (i \neq 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>S_1</var> <var>:</var> <var>S_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there are <var>x</var> ways to choose three people so that the given conditions are met, print <var>x</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 MASHIKE RUMOI OBIRA HABORO HOROKANAI </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>We can choose three people with the following names:</p> <ul> <li> <p><code>MASHIKE</code>, <code>RUMOI</code>, <code>HABORO</code></p> </li> <li> <p><code>MASHIKE</code>, <code>RUMOI</code>, <code>HOROKANAI</code></p> </li> </ul> <p>Thus, we have two ways.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 ZZ ZZZ Z ZZZZZZZZZZ </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Note that there may be no ways to choose three people so that the given conditions are met.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 CHOKUDAI RNG MAKOTO AOKI RINGO </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7 </pre></section> </div> </span>
p01418
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Sleeping Time</H1> <p> Miki is a high school student. She has a part time job, so she cannot take enough sleep on weekdays. She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her. She is now trying to figure that out with the following algorithm: </p> <ol> <li> Begin with the numbers <var>K</var>, <var>R</var> and <var>L</var>.</li> <li>She tries to sleep for <var>H=(R+L)/2</var> hours.</li> <li>If she feels the time is longer than or equal to the optimal length, then update <var>L</var> with <var>H</var>. Otherwise, update <var>R</var> with <var>H</var>.</li> <li>After repeating step 2 and 3 for <var>K</var> nights, she decides her optimal sleeping time to be <var>T' = (R+L)/2</var>.</li> </ol> <p> If her feeling is always correct, the steps described above should give her a very accurate optimal sleeping time. But unfortunately, she makes mistake in step 3 with the probability <var>P</var>. </p> <p> Assume you know the optimal sleeping time <var>T</var> for Miki. You have to calculate the probability <var>PP</var> that the absolute difference of <var>T'</var> and <var>T</var> is smaller or equal to <var>E</var>. It is guaranteed that the answer remains unaffected by the change of <var>E</var> in <var>10^{-10}</var>. </p> <H2>Input</H2> <p> The input follows the format shown below </p> <p> <var>K</var> <var>R</var> <var>L</var><br/> <var>P</var><br/> <var>E</var><br/> <var>T</var><br/> </p> <p> Where the integers <var>0 \leq K \leq 30</var>, <var>0 \leq R \leq L \leq 12</var> are the parameters for the algorithm described above. The decimal numbers on the following three lines of the input gives the parameters for the estimation. You can assume <var>0 \leq P \leq 1</var>, <var>0 \leq E \leq 12</var>, <var>0 \leq T \leq 12</var>. </p> <H2>Output</H2> <p> Output <var>PP</var> in one line. The output should not contain an error greater than <var>10^{-5}</var>. </p> <H2>Sample Input 1</H2> <pre> 3 0 2 0.10000000000 0.50000000000 1.00000000000 </pre> <H2>Output for the Sample Input 1</H2> <pre> 0.900000 </pre> <H2>Sample Input 2</H2> <pre> 3 0 2 0.10000000000 0.37499999977 1.00000000000 </pre> <H2>Output for the Sample Input 2</H2> <pre> 0.810000 </pre> <H2>Sample Input 3</H2> <pre> 3 0 2 0.10000000000 0.00000100000 0.37500000000 </pre> <H2>Output for the Sample Input 3</H2> <pre> 0.729000 </pre> <H2>Sample Input 4</H2> <pre> 3 0 2 0.20000000000 0.00000100000 0.37500000000 </pre> <H2>Output for the Sample Input 4</H2> <pre> 0.512000 </pre>
p03075
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In AtCoder city, there are five antennas standing in a straight line. They are called Antenna <var>A, B, C, D</var> and <var>E</var> from west to east, and their coordinates are <var>a, b, c, d</var> and <var>e</var>, respectively.<br/> Two antennas can communicate directly if the distance between them is <var>k</var> or less, and they cannot if the distance is greater than <var>k</var>.<br/> Determine if there exists a pair of antennas that cannot communicate <strong>directly</strong>.<br/> Here, assume that the distance between two antennas at coordinates <var>p</var> and <var>q</var> (<var>p &lt; q</var>) is <var>q - p</var>. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>a, b, c, d, e</var> and <var>k</var> are integers between <var>0</var> and <var>123</var> (inclusive).</li> <li><var>a &lt; b &lt; c &lt; d &lt; e</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> <var>c</var> <var>d</var> <var>e</var> <var>k</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print <code>:(</code> if there exists a pair of antennas that cannot communicate <strong>directly</strong>, and print <code>Yay!</code> if there is no such pair.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 2 4 8 9 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yay! </pre> <p>In this case, there is no pair of antennas that cannot communicate directly, because:</p> <ul> <li>the distance between <var>A</var> and <var>B</var> is <var>2 - 1</var> = <var>1</var></li> <li>the distance between <var>A</var> and <var>C</var> is <var>4 - 1</var> = <var>3</var></li> <li>the distance between <var>A</var> and <var>D</var> is <var>8 - 1</var> = <var>7</var></li> <li>the distance between <var>A</var> and <var>E</var> is <var>9 - 1</var> = <var>8</var></li> <li>the distance between <var>B</var> and <var>C</var> is <var>4 - 2</var> = <var>2</var></li> <li>the distance between <var>B</var> and <var>D</var> is <var>8 - 2</var> = <var>6</var></li> <li>the distance between <var>B</var> and <var>E</var> is <var>9 - 2</var> = <var>7</var></li> <li>the distance between <var>C</var> and <var>D</var> is <var>8 - 4</var> = <var>4</var></li> <li>the distance between <var>C</var> and <var>E</var> is <var>9 - 4</var> = <var>5</var></li> <li>the distance between <var>D</var> and <var>E</var> is <var>9 - 8</var> = <var>1</var></li> </ul> <p>and none of them is greater than <var>15</var>. Thus, the correct output is <code>Yay!</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 18 26 35 36 18 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>:( </pre> <p>In this case, the distance between antennas <var>A</var> and <var>D</var> is <var>35 - 15</var> = <var>20</var> and exceeds <var>18</var>, so they cannot communicate directly. Thus, the correct output is <code>:(</code>.</p></section> </div> </span>
p01048
<h1>Divisor</h1> <h2>Problem</h2> <p> 12以䞋の自然数 <var>N</var> が䞎えられるので、玄数の個数がちょうど <var>N</var> 個であるような最小の自然数を求めよ。 </p> <h2>Input</h2> <p> 1぀の自然数 <var>N</var> が 1 行で䞎えられる。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>N</var> &le; 12</li> </ul> <h2>Output</h2> <p> 玄数の個数がちょうど <var>N</var> 個であるような最小の自然数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 1 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 2 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> <h2>Sample Input 3</h2> <pre> 3 </pre> <h2>Sample Output 3</h2> <pre> 4 </pre>
p00835
<H1><font color="#000">Problem I:</font> Crossing Prisms</H1> <p> Prof. Bocchan is a mathematician and a sculptor. He likes to create sculptures with mathematics. </p> <p> His style to make sculptures is very unique. He uses two identical prisms. Crossing them at right angles, he makes a polyhedron that is their intersection as a new work. Since he finishes it up with painting, he needs to know the surface area of the polyhedron for estimating the amount of pigment needed. </p> <p> For example, let us consider the two identical prisms in Figure 1. The definition of their cross section is given in Figure 2. The prisms are put at right angles with each other and their intersection is the polyhedron depicted in Figure 3. An approximate value of its surface area is 194.8255. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_crossingPrisms1"> <p>Figure 1: Two identical prisms at right angles</p> </center> <p> Given the shape of the cross section of the two identical prisms, your job is to calculate the surface area of his sculpture. </p> <H2>Input</H2> <p> The input consists of multiple datasets, followed by a single line containing only a zero. The first line of each dataset contains an integer <i>n</i> indicating the number of the following lines, each of which contains two integers <i>a<sub>i</sub></i> and <i>b<sub>i</sub></i> (<i>i</i> = 1, ... , <i>n</i>). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_crossingPrisms2"> <p>Figure 2: Outline of the cross section</p> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_crossingPrisms3"> <p>Figure 3: The intersection</p> </center> <p> A closed path formed by the given points (<i>a</i><sub>1</sub>, <i>b</i><sub>1</sub>), (<i>a</i><sub>2</sub>, <i>b</i><sub>2</sub> ), ... , (<i>a<sub>n</sub></i>, <i>b<sub>n</sub></i>), (<i>a</i><sub><i>n</i>+1</sub>, <i>b</i><sub><i>n</i>+1</sub>)(= (<i>a</i><sub>1</sub>, <i>b</i><sub>1</sub>)) indicates the outline of the cross section of the prisms. The closed path is simple, that is, it does not cross nor touch itself. The right-hand side of the line segment from (<i>a<sub>i</sub></i>, <i>b<sub>i</sub></i>) to (<i>a<sub>i</sub></i>+1 , <i>b<sub>i</sub></i>+1 ) is the inside of the section. </p> <p> You may assume that 3 &le; <i>n</i> &le; 4, 0 &le; <i>a<sub>i</sub></i> &le; 10 and 0 &le; <i>b<sub>i</sub></i> &le; 10 (<i>i</i> = 1, ... , <i>n</i>). </p> <p> One of the prisms is put along the <i>x</i>-axis so that the outline of its cross section at <i>x</i> = <i>&zeta;</i> is indicated by points (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> ) = (<i>&zeta;</i>, <i>a<sub>i</sub></i>, <i>b<sub>i</sub></i>) (0 &le; <i>&zeta;</i> &le; 10, <i>i</i> = 1, ... , <i>n</i>). The other prism is put along the <i>y</i>-axis so that its cross section at <i>y</i> = <i>&eta;</i> is indicated by points (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i>) = (<i>a<sub>i</sub></i>, <i>&eta;</i>, <i>b<sub>i</sub></i>) (0 &le; <i>&eta;</i> &le; 10, <i>i</i> = 1, ... , <i>n</i>). </p> <H2>Output</H2> <p> The output should consist of a series of lines each containing a single decimal fraction. Each number should indicate an approximate value of the surface area of the polyhedron defined by the corresponding dataset. The value may contain an error less than or equal to 0.0001. You may print any number of digits below the decimal point. </p> <H2>Sample Input</H2> <pre> 4 5 0 0 10 7 5 10 5 4 7 5 10 5 5 0 0 10 4 0 10 10 10 10 0 0 0 3 0 0 0 10 10 0 4 0 10 10 5 0 0 9 5 4 5 0 0 10 5 5 10 10 4 0 5 5 10 10 5 5 0 4 7 1 4 1 0 1 9 5 0 </pre> <H2>Output for the Sample Input</H2> <pre> 194.8255 194.8255 600.0000 341.4214 42.9519 182.5141 282.8427 149.2470 </pre>
p02808
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There are <var>N</var> children, numbered <var>1,2,\ldots,N</var>. In the next <var>K</var> days, we will give them some cookies. In the <var>i</var>-th day, we will choose <var>a_i</var> children among the <var>N</var> with equal probability, and give one cookie to each child chosen. (We make these <var>K</var> choices independently.)</p> <p>Let us define the <em>happiness</em> of the children as <var>c_1 \times c_2 \times \ldots \times c_N</var>, where <var>c_i</var> is the number of cookies received by Child <var>i</var> in the <var>K</var> days. Find the expected happiness multiplied by <var>\binom{N}{a_1} \times \binom{N}{a_2} \times \ldots \times \binom{N}{a_K}</var> (we can show that this value is an integer), modulo <var>(10^{9}+7)</var>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3> <p><var>\binom{n}{k}</var> denotes the number of possible choices of <var>k</var> objects out of given distinct <var>n</var> objects, disregarding order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>1 \leq K \leq 20</var></li> <li><var>1 \leq a_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>K</var> <var>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <ul> <li>On the first day, all the children <var>1</var>, <var>2</var>, and <var>3</var> receive one cookie.</li> <li>On the second day, two out of the three children <var>1</var>, <var>2</var>, and <var>3</var> receive one cookie.</li> <li>Their happiness is <var>4</var> in any case, so the expected happiness is <var>4</var>. Print this value multiplied by <var>\binom{3}{3} \times \binom{3}{2}</var>, which is <var>12</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>856 16 399 263 665 432 206 61 784 548 422 313 848 478 827 26 398 63 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>337587117 </pre> <ul> <li>Find the expected value multiplied by <var>\binom{N}{a_1} \times \binom{N}{a_2} \times \ldots \times \binom{N}{a_K}</var>, modulo <var>(10^9+7)</var>.</li> </ul></section> </div> </span>
p01727
<p>プログラミングコンテストの合宿で出す問題のアむディアが出ずに困っおいたむクタ君は、ある日友人に盞談した。 </p> <p>むクタ君「こういうアルゎリズムを䜿わないず解けないような問題が出したいんですけど、なにかありたせんかね」 </p> <p>友人「それではこういうものを考えたらいいんじゃないですか」 </p> <p>このようにしおその友人は以䞋のような問題の原案ずなるアむデアを考えおくれた。 </p> <p>2進数<var>A,B</var>が䞎えられた時、以䞋の様なク゚リを凊理せよ。 <ul> <li> 出力ク゚リ: max{<var>x</var> を2進数で衚したずきの、1の数 | <var>A &le; x < A+B</var> }を出力 </li> <li> A倉曎ク゚リ: <var>A</var>の最䞋䜍ビットから<var>i</var>ビット目(0-origin)を反転 </li> <li> B倉曎ク゚リ: <var>B</var>の最䞋䜍ビットから<var>i</var>ビット目(0-origin)を反転 </li></ul> <p><var>i</var>ビット目ずいうのが 0-origin で衚されおいるこずに泚意せよ。 ぀たり、<var>A</var>の最䞋䜍ビットから0ビット目ずは最䞋䜍ビットを衚す。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>A</var> <var>B</var><br><var>Q<sub>1</sub></var><br>...<br><var>Q<sub>N</sub></var></pre> <p>1行目にク゚リの数N,2進数A, Bが䞎えられる。 </p> <p>2からN+1行目には以䞋の様なク゚リが䞎えられる。 </p> <ul><li> Q </li><li> A <var>i</var> </li><li> B <var>i</var> </li></ul> <p>Qが出力ク゚リを、A <var>i</var>,B <var>i</var>はそれぞれ<var>A</var>の最䞋䜍ビットから<var>i</var>ビット目、<var>B</var>の最䞋䜍ビットから<var>i</var>ビット目を反転させる倉曎ク゚リを衚しおいる。 </p> <h3>Constraints</h3> <p>入力䞭の各倉数は以䞋の制玄を満たす。 </p> <ul><li> <var>1 &le; N < 300,000</var> </li><li> <var>1 &le; |A|,|B| &le; 300,000</var> (<var>|A|</var>は<var>A</var>の長さ) </li><li> A <var>i</var> ずいうク゚リでは <var>0 &le; i < |A|</var> </li><li> B <var>i</var> ずいうク゚リでは <var>0 &le; i < |B|</var> </li><li> <var>B</var>が0になるこずはない </li></ul> <h2>Output</h2> <p>出力ク゚リごずに答えを1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre>4 10000 00101 Q A 0 B 1 Q </pre> <h2>Output for the Sample Input 1</h2> <pre>3 4 </pre> <p>最初の出力ク゚リでは <var>A=10000</var>, <var>B=00101</var>, <var>A+B=10101</var>なので求める<var>x</var>は10011 </p> <p>次の出力ク゚リでは <var>A=10001</var>, <var>B=00111</var>, <var>A+B=11000</var>なので求める<var>x</var>は10111 </p> <h2>Sample Input 2</h2> <pre>9 0110111101 0010100111 Q B 4 Q A 4 Q B 9 Q A 8 Q </pre> <h2>Output for the Sample Input 2</h2> <pre>9 9 9 10 9 </pre>
p01377
<div> <h1 class="title">問題 B : (iwi)</h1> <p>20XX 幎の今G○○gle 瀟の䞖界的な支配により人々のコミュニケヌションは限られおおり 䟋えば自由に人ず情報をやりずりするこずは基本的に蚱されおいない 特に過去にプログラミングコンテストで名を銳せた匷豪たちは危険ず刀断され お互いバラバラにされ密かに泚意深く監芖されおいるずいう</p> <p>自分もそんな䞀人であったような気がする しかし実は自分は蚘憶を倱っおしたっおいるのだ 自分が䜕ず名乗っおいたかそれすらも思い出せない 'i' ずか 'w' ずか括匧ずかを䜿っおいた気がするが それっぜいものを曞きだしおみおもしっくりこない そういえば今思い出したこずには巊右に線察称だった気がするのだ</p> <div> <h1>問題</h1> <p>'i', 'w', '(', ')' からなる文字列が䞎えられた時 䞀郚の文字を他の文字に眮き換えお'i', 'w', '(', ')' からなる巊右に線察称な文字列にしたい 文字の远加や削陀は蚱さず1 文字を別の 1 文字に倉える操䜜のみを行うこずにする 少なくずも䜕文字眮き換えなければならないかを出力するプログラムを䜜成せよ</p> <p>ここで甚いる巊右に線察称の定矩は以䞋ずする</p> <ol class="arabic simple"> <li>以䞋の文字列は巊右に線察称</li> </ol> <blockquote> <ul class="simple"> <li>空文字列</li> <li>&quot;i&quot;</li> <li>&quot;w&quot;</li> </ul> </blockquote> <ol class="arabic simple" start="2"> <li>文字列 <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> が巊右に線察称のずき以䞋の文字列も巊右に線察称</li> </ol> <blockquote> <ul class="simple"> <li>&quot;i&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;i&quot;</li> <li>&quot;w&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;w&quot;</li> <li>&quot;(&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;)&quot;</li> <li>&quot;)&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;(&quot;</li> </ul> </blockquote> <ol class="arabic simple" start="3"> <li>以䞊のもののみが巊右に線察称</li> </ol> <p>ここで&quot;i&quot; <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> &quot;i&quot; ずは &quot;i&quot; ず <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> ず &quot;i&quot; を連結したものを衚す 他のものも同様である</p> </div> <div> <h1>入力</h1> <p>入力は 'i', 'w', '(', ')' からなる 1 ぀の文字列である</p> </div> <div> <h1>出力</h1> <p>眮き換えなければならない文字数を衚す敎数を出力せよ</p> </div> <div> <h1>制玄</h1> <ul class="simple"> <li>入力の文字列の長さは 10 以䞋である</li> </ul> </div> <div> <h1>入出力䟋</h1> <div> <h2>入出力䟋 1</h2> <p>入力䟋 1:</p> <pre class="literal-block"> (iwi) </pre> <p>入力䟋 1 に察する出力䟋:</p> <pre class="literal-block"> 0 </pre> <p>入力䟋 1 では文字列がはじめから巊右に線察称である</p> </div> <div> <h2>入出力䟋 2</h2> <p>入力䟋 2:</p> <pre class="literal-block"> ii(((((ww </pre> <p>入力䟋 2 に察する出力䟋:</p> <pre class="literal-block"> 5 </pre> <p>入力䟋 2 では䟋えば ww((i))ww 等に倉曎すればよい</p> </div> </div> </div>
p00136
<H1>床数分垃</H1> <p> 健康蚺断で生埒の身長を蚈枬したした。身長のデヌタを入力ずし、床数分垃を䜜成しお出力するプログラムを䜜成しおください。床数分垃の階玚は 5 cm 刻みの 6 ぀の階玚ずし、床数は人数を *半角アスタリスクで衚瀺したす。ただし、その階玚の床数人数が 0 の堎合、階玚の芋出しのみを出力しおください。 </p> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>h<sub>1</sub></var> <var>h<sub>2</sub></var> : <var>h<sub>n</sub></var> </pre> <p> 1 行目に生埒の数 <var>n</var> (1 &le; <var>n</var> &le; 40)、2 行目以降に <var>i</var> 人目の身長を衚す実数 <var>h<sub>i</sub></var> (150.0 &le; <var>h<sub>i</sub></var> &le; 190.0、小数第 1 䜍たで) がそれぞれ 1 行に䞎えられたす。 </p> <H2>Output</H2> <p> 以䞋の圢匏で床数分垃を衚瀺しおください。 </p> <pre> 1 行目 芋出し「1:」に぀づいお 165.0 cm 未満の人数分の * 2 行目 芋出し「2:」に぀づいお 165.0 cm 以䞊〜 170.0 cm未満の人数分の * 3 行目 芋出し「3:」に぀づいお 170.0 cm 以䞊〜 175.0 cm未満の人数分の * 4 行目 芋出し「4:」に぀づいお 175.0 cm 以䞊〜 180.0 cm未満の人数分の * 5 行目 芋出し「5:」に぀づいお 180.0 cm 以䞊〜 185.0 cm未満の人数分の * 6 行目 芋出し「6:」に぀づいお 185.0 cm 以䞊の人数分の * </pre> <H2>Sample Input 1</H2> <pre> 4 180.3 168.2 165.5 175.3 </pre> <H2>Output for the Sample Input 1</H2> <pre> 1: 2:** 3: 4:* 5:* 6: </pre> <H2>Sample Input 2</H2> <pre> 21 179.4 171.5 156.6 173.0 169.4 181.2 172.4 170.0 163.6 165.9 173.5 168.2 162.5 172.0 175.1 172.3 167.5 175.9 186.2 168.0 178.6 </pre> <H2>Output for the Sample Input 2</H2> <pre> 1:*** 2:***** 3:******* 4:**** 5:* 6:* </pre>
p00566
<h1>幹線道路 (Trunk Road)</h1> <h2>問題文</h2> <p> JOI 垂は東西方向にたっすぐに䌞びる <var>H</var> 本の道路ず南北方向にたっすぐに䌞びる <var>W</var> 本の道路によっお碁盀の目の圢に区分けされおいる道路ず道路の間隔は <var>1</var> であるJOI 垂ではこれら <var>H+W</var> 本の道路から東西方向に <var>1</var> 本南北方向に <var>1</var> 本合蚈 <var>2</var> 本の道路を幹線道路ずしお遞ぶこずになった</p> <p> 北から <var>i</var> 本目 (<var>1≩i≩H</var>) の道路ず西から <var>j</var> 本目 (<var>1≩j≩W</var>) の道路の亀差点を亀差点 <var>(i,j)</var> ずする亀差点 <var>(i,j)</var> ず北から <var>m</var> 本目 (<var>1≩m≩H</var>) の道路の距離は <var>|i-m|</var> であり亀差点 <var>(i,j)</var> ず西から <var>n</var> 本目 (<var>1≩n≩W</var>) の道路の距離は <var>|j-n|</var> である たた亀差点 <var>(i,j)</var> の近くには <var>A_{i,j}</var> 人の䜏人が䜏んでいる</p> <p> <var>2</var> 本の幹線道路を遞んだずきのJOI 垂の党おの䜏人に察する最寄りの亀差点から近い方の幹線道路ぞの距離の総和の最小倀を求めよ</p> <h2>制玄</h2> <ul> <li><var>2 ≩ H ≩ 25</var></li> <li><var>2 ≩ W ≩ 25</var></li> <li><var>0 ≩ A_{i,j} ≩ 100</var> (<var>1 ≩ i ≩ H</var>, <var>1 ≩ j ≩ W</var>)</li> </ul> <h2>入力・出力</h2> <p> <b>入力</b><br> 入力は以䞋の圢匏で暙準入力から䞎えられる<br> <var>H</var> <var>W</var><br> <var>A_{1,1}</var> <var>A_{1,2}</var> ... <var>A_{1,W}</var><br> :<br> <var>A_{H,1}</var> <var>A_{H,2}</var> ... <var>A_{H,W}</var> </p> <p> <b>出力</b><br> JOI 垂の党おの䜏人に察する最寄りの亀差点から近い方の幹線道路ぞの距離の総和の最小倀を出力せよ</p> <!-- <h2>小課題</h2> <p> <b>小課題 1 [10点]</b> </p> <ul> <li><var>A_{i,j} = 1</var> (<var>1 ≩ i ≩ H</var>, <var>1 ≩ j ≩ W</var>)</li> </ul> <p> <b>小課題 2 [90点]</b> </p> <ul> <li>远加の制限はない</li> </ul> --> <h2>入出力䟋</h2> <b>入力䟋 1</b><br> <pre> 3 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 </pre> <b>出力䟋 1</b><br> <pre> 8 </pre> <p> 䟋えば北から <var>2</var> 本目の道路ず西から <var>1</var> 本目の道路を幹線道路ずすればよい</p> <hr> <b>入力䟋 2</b><br> <pre> 5 5 1 2 3 1 5 1 22 11 44 3 1 33 41 53 2 4 92 35 23 1 4 2 6 3 5 </pre> <b>出力䟋 2</b><br> <pre> 164 </pre> <br/> <p> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> <br/> <a href="https://www.ioi-jp.org/joi/2017/2018-yo/index.html">情報オリンピック日本委員䌚䜜 『第 17 回日本情報オリンピック JOI 2017/2018 予遞競技課題』</a> </p>
p00073
<H1>四角すいの衚面積</H1> <p> 1 蟺が <var>x</var> の正方圢を底面ずする、高さ <var>h</var> の四角すいの衚面積 <var>S</var> を出力するプログラムを䜜成しお䞋さい。ただし、頂点ず底面の䞭心を結ぶ線分は底面ず盎亀しおいるずしたす。たた、 <var>x</var>、<var>h</var> は 100 以䞋の正の敎数ずしたす。 </p> <H3 class="bar">Input</H3> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>x</var> <var>h</var> </pre> <p> <var>x, h</var> が共に 0 のずき入力の終了を瀺したす。 </p> <H2>Output</H2> <p> 各デヌタセットごずに、<var>S</var>実数を行に出力しお䞋さい。出力は0.00001以䞋の誀差を含んでもよい。 </p> <H2>Sample Input</H2> <pre> 6 4 7 9 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 96.000000 184.192455 </pre>
p00589
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>problem</title> </head> <body bgcolor="#FFFFFF"> <link rel="stylesheet" href="../problem_e.css" type="text/css" /> --> <H1>Extraordinary Girl (II)</H1> <p> She loves e-mail so much! She sends e-mails by her cellular phone to her friends when she has breakfast, she talks with other friends, and even when she works in the library! Her cellular phone has somewhat simple layout (Figure 1). Pushing button 1 once displays a character (’), pushing </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_1003"> </center> <p> it twice in series displays a character (,), and so on, and pushing it 6 times displays (’) again. Button 2 corresponds to charaters (abcABC), and, for example, pushing it four times displays (A). Button 3-9 have is similar to button 1. Button 0 is a special button: pushing it once make her possible to input characters in the same button in series. For example, she has to push “20202” to display “aaa” and “660666” to display “no”. In addition, pushing button 0 n times in series (n > 1) displays n − 1 spaces. She never pushes button 0 at the very beginning of her input. Here are some examples of her input and output: </p> <pre> 666660666 --> No 44444416003334446633111 --> I’m fine. 20202202000333003330333 --> aaba f ff </pre> <p> One day, the chief librarian of the library got very angry with her and hacked her cellular phone when she went to the second floor of the library to return books in shelves. Now her cellular phone can only display button numbers she pushes. Your task is to write a program to convert the sequence of button numbers into correct characters and help her continue her e-mails! </p> <H2>Input</H2> <p> Input consists of several lines. Each line contains the sequence of button numbers without any spaces. You may assume one line contains no more than 10000 numbers. Input terminates with EOF. </p> <H2>Output</H2> <p> For each line of input, output the corresponding sequence of characters in one line. </p> <H2>Sample Input</H2> <pre> 666660666 44444416003334446633111 20202202000333003330333 </pre> <H2>Output for the Sample Input</H2> <pre> No I'm fine. aaba f ff </pre>
p00423
<H1><!-- Card Game--></H1> <p> A ず B の 2 人のプレヌダヌが 0 から 9 たでの数字が曞かれたカヌドを䜿っおゲヌムを行う最初に 2 人は䞎えられた n 枚ず぀のカヌドを裏向きにしお暪䞀列に䞊べるその埌 2 人は各自の巊から 1 枚ず぀カヌドを衚向きにしおいき曞かれた数字が倧きい方のカヌドの持ち䞻がその 2 枚のカヌドを取るこのずきその 2 枚のカヌドに曞かれた数字の合蚈がカヌドを取ったプレヌダヌの埗点ずなるものずするただし開いた 2 枚のカヌドに同じ数字が曞かれおいるずきには匕き分けずし各プレヌダヌが自分のカヌドを 1 枚ず぀取るものずする </p> <p> 䟋えば AB の持ち札が以䞋の入力䟋 1 から 3 のように䞊べられおいる堎合を考えようただし入力ファむルは n + 1 行からなり 1 行目には各プレヌダのカヌド枚数 n が曞かれおおり i + 1 行目i = 12... nには A の巊から i 枚目のカヌドの数字ず B の巊から i 枚目の カヌドの数字が空癜を区切り文字ずしおこの順で曞かれおいるすなわち入力ファむルの 2 行目以降は巊偎の列が A のカヌドの䞊びを右偎の列が B のカヌドの䞊びをそれぞれ衚しおいるこのずきゲヌム終了埌の A ず B の埗点はそれぞれ察応する出力䟋に瀺したものずなる </p> <p>  入力ファむルに察応するゲヌムが終了したずきの A の埗点ず B の埗点をこの順に空癜を区切り文字ずしお 1 行に出力するプログラムを䜜成しなさいただし n &le; 10000 ずする </p> <!-- <p> アップロヌドする出力ファむルにおいおは、出力の埌Bの埗点の埌に改行を入れるこず。 </p> --> <table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;"> <tr> <th width="150" align="left">入力䟋</th> <th width="150" align="left">入力䟋</th> <th width="150" align="left">入力䟋</th> </tr> <tr><td>3</td><td>3</td><td>3</td></tr> <tr><td>9 1</td><td>9 1</td><td>9 1</td></tr> <tr><td>5 4</td><td>5 4</td><td>5 5</td></tr> <tr><td>0 8</td><td>1 0</td><td>1 8</td></tr> <tr> <td> </td> </tr> <tr> <th width="150" align="left">出力䟋</th> <th width="150" align="left">出力䟋</th> <th width="150" align="left">出力䟋</th> </tr> <tr><td>19 8</td><td>20 0</td><td>15 14</td></tr> </table> <h3>入力</h3> <p> 入力は耇数のデヌタセットからなるn が 0 のずき入力が終了するデヌタセットの数は 5 を超えない </p> <h3>出力</h3> <p> デヌタセットごずに、A の埗点ず B の埗点を行に出力する </p> <h3>入力䟋</h3> <pre> 3 9 1 5 4 0 8 3 9 1 5 4 1 0 3 9 1 5 5 1 8 0 </pre> <h3>出力䟋</h3> <pre> 19 8 20 0 15 14 </pre> <p> 各デヌタセットの出力の埌Bの埗点の埌に改行を入れるこず。 </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00970
<h2>Emergency Evacuation</h2> <p> The Japanese government plans to increase the number of inbound tourists to forty million in the year 2020, and sixty million in 2030. Not only increasing touristic appeal but also developing tourism infrastructure further is indispensable to accomplish such numbers. </p> <p> One possible enhancement on transport is providing cars extremely long and/or wide, carrying many passengers at a time. Too large a car, however, may require too long to evacuate all passengers in an emergency. You are requested to help estimating the time required. </p> <p> The car is assumed to have the following seat arrangement. </p> <ul> <li> A center aisle goes straight through the car, directly connecting to the emergency exit door at the rear center of the car.</li> <li> The rows of the same number of passenger seats are on both sides of the aisle.</li> </ul> <p> A rough estimation requested is based on a simple step-wise model. All passengers are initially on a distinct seat, and they can make one of the following moves in each step. </p> <ul> <li> Passengers on a seat can move to an adjacent seat toward the aisle. Passengers on a seat adjacent to the aisle can move sideways directly to the aisle.</li> <li> Passengers on the aisle can move backward by one row of seats. If the passenger is in front of the emergency exit, that is, by the rear-most seat rows, he/she can get off the car.</li> </ul> <p> The seat or the aisle position to move to must be empty; either no other passenger is there before the step, or the passenger there empties the seat by moving to another position in the same step. When two or more passengers satisfy the condition for the same position, only one of them can move, keeping the others wait in their original positions. </p> <p> The leftmost figure of Figure C.1 depicts the seat arrangement of a small car given in Sample Input 1. The car have five rows of seats, two seats each on both sides of the aisle, totaling twenty. The initial positions of seven passengers on board are also shown. </p> <p> The two other figures of Figure C.1 show possible positions of passengers after the first and the second steps. Passenger movements are indicated by fat arrows. Note that, two of the passengers in the front seat had to wait for a vacancy in the first step, and one in the second row had to wait in the next step. </p> <p> Your task is to write a program that gives the smallest possible number of steps for all the passengers to get off the car, given the seat arrangement and passengers' initial positions. </p> <div style="text-align:center"> <img width="680" src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2018_emergencyEvacuation"><br/> Figure C.1 </div> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $r$ $s$ $p$ $i_1$ $j_1$ ... $i_p$ $j_p$ </pre> <p> Here, $r$ is the number of passenger seat rows, $s$ is the number of seats on each side of the aisle, and $p$ is the number of passengers. They are integers satisfying $1 \leq r \leq 500$, $1 \leq s \leq 500$, and $1 \leq p \leq 2rs$. </p> <p> The following $p$ lines give initial seat positions of the passengers. The $k$-th line with $i_k$ and $j_k$ means that the $k$-th passenger's seat is in the $i_k$-th seat row and it is the $j_k$-th seat on that row. Here, rows and seats are counted from front to rear and left to right, both starting from one. They satisfy $1 \leq i_k \leq r$ and $1 \leq j_k \leq 2s$. Passengers are on distinct seats, that is, $i_k \ne= i_l$ or $j_k \ne j_l$ holds if $k \ne l$. </p> <h3>Output</h3> <p> The output should be one line containing a single integer, the minimum number of steps required for all the passengers to get off the car. </p> <h3>Sample Input 1</h3> <pre> 5 2 7 1 1 1 2 1 3 2 3 2 4 4 4 5 2 </pre> <h3>Sample Output 1</h3> <pre> 9 </pre> <h3>Sample Input 2</h3> <pre> 500 500 16 1 1 1 2 1 999 1 1000 2 1 2 2 2 999 2 1000 3 1 3 2 3 999 3 1000 499 500 499 501 499 999 499 1000 </pre> <h3>Sample Output 2</h3> <pre> 1008 </pre>
p01662
<h2>G - 自由研究</h2> <p> き぀ねの次郎は倏䌑みの自由研究で<em>最倧独立集合問題</em>のアルゎリズムを考えおいる 最倧独立集合問題では入力ずしお無向グラフ <var>G=(V,E)</var> が䞎えられる <var>G</var> の各頂点が癜たたは黒で塗られおおりどの蟺の端点も少なくずも䞀方が癜く塗られおいるずき黒い頂点集合のこずを<em>独立集合</em>ず呌ぶ 䟋えば䞋図においお図の巊郚のようなグラフが䞎えられた時図の䞭倮郚のように色を塗るず黒い頂点集合は独立集合になっおいるが䞀方で図の右郚のように色を塗った堎合は黒い頂点集合は独立集合になっおいない 問題の目的は芁玠数が最倧であるような独立集合を求めるこずである 䟿宜䞊グラフ <var>G</var> の最倧の独立集合の倧きさを <var>A(G)</var> ず蚘す </p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_mofu_fig1"> </p> <p> 残念ながらこの問題は<a href="http://ja.wikipedia.org/wiki/NP%E5%9B%B0%E9%9B%A3">NP困難</a>であるこずが知られおおり倚項匏時間で最適倀を求めるこずは倚分できそうにない そこでき぀ねの次郎は理論的には保蚌がないがなんずなくうたくいきそうな乱択アルゎリズムを考案したそのアルゎリズムは次のようなものである </p> <p> 【次郎のアルゎリズム】<var>N=|V|</var> をグラフの頂点数ずする 最初すべおの頂点は癜で塗られおいる いた各頂点に <var>1,2,
,N</var> の番号をどの2぀の頂点も互いに異なる番号を持぀ように割り圓おる このずき<var>N! = N \times (N-1) \times (N-2) \times 
 \times 1</var> 通りの割り圓お方が存圚するが これらの䞭から䞀様な確率で無䜜為に割り圓おるものずする 各頂点 <var>v</var> に぀いおもし <var>v</var> に隣接するすべおの頂点 <var>w</var> に察しお <var>v</var> に割り圓おられた番号が <var>w</var> より小さいずき <var>v</var> を黒く塗るずいうこずをする (もし <var>v</var> に隣接する頂点が存圚しない堎合アルゎリズムは <var>v</var> を黒く塗るものずする) そしお黒く塗られた頂点を問題の解ずしお出力する </p> <p> 次郎のアルゎリズムの動䜜䟋を䞋図に瀺す 図の巊郚のようなグラフが䞎えられたずき各頂点に番号を(無䜜為に)割り圓おそこから条件を満たす頂点を黒く塗っおいる </p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_mofu_fig2"> </p> <p> 定矩からこのアルゎリズムによっお黒く塗られる頂点集合は独立集合になっおいるこずがわかる アルゎリズムを䜜りすっかり自信に満ちた様子の次郎であったがそれを暪から芋おいたき぀ねのしえるが突っ蟌みを入れおきた そんなアルゎリズムでは党然良い解は出ないず 玍埗しようずしないき぀ねの次郎にためにしえるは臎呜的なケヌスを芋せるこずにした </p> <p> <var>E(G)</var> を次郎のアルゎリズムが出力する黒い頂点集合の倧きさの期埅倀ずする <strong>頂点数が40以䞋</strong>の無向グラフで<var>A(G)-E(G)</var> が最倧になるようなものを1぀䜜りそれを出力せよ </p> <h2>入力圢匏</h2> <p> 入力は無い </p> <h2>出力圢匏</h2> <p>題意を満たすグラフを出力せよ グラフの出力圢匏は以䞋に埓うものずする </p> <pre> <var>N</var> <var>s_{11}</var><var>s_{12}</var><var>s_{13}</var>
<var>s_{1n}</var> <var>s_{21}</var><var>s_{22}</var><var>s_{23}</var>
<var>s_{2n}</var> <var>s_{31}</var><var>s_{32}</var><var>s_{33}</var>
<var>s_{3n}</var> <var>
</var> <var>s_{n1}</var><var>s_{n2}</var><var>s_{n3}</var>
<var>s_{nn}</var> </pre> <p> <var>n</var> はグラフの頂点数である <var>s_{ij}</var> はグラフの接続関係を衚す文字である 頂点 <var>i</var> ず <var>j</var> の間に蟺が無いずき <var>s_{ij}=</var><code>N</code> であり 頂点 <var>i</var> ず <var>j</var> の間に蟺が有るずき <var>s_{ij}=</var><code>Y</code> であるものずする 制玄ずグラフの性質から以䞋の条件を満たさなければならない </p> <ul> <li><var>1 &le; N &le; 40</var></li> <li><var>s_{ii} = </var><code>N</code></li> <li><var>s_{ij} = s_{ji}</var></li> </ul> <!-- <h2>採点方匏</h2> <p> もし出力された解が最適解である堎合500点を埗る 最適解ではない堎合この問題の最適解を <var>OPT</var> ずしお<var>score = X \times (A(G) - E(G)) / OPT</var> ずするここで <var>X</var> は40以䞊50以䞋の固定された倀である もし <var>score &ge; 20</var> ならば<var>score</var> 点を埗る <var>score &lt; 20</var> の堎合0点を埗る </p> --> <h2>入出力䟋</h2> <p> 以䞋に入出力䟋を瀺すが問題の性質䞊最適解の出力を蚘すこずはできないのでここでは出力圢匏を満たす最適ではない解の䟋を瀺す </p> <h3>入力䟋 1</h3> <pre> </pre> <h3>出力䟋 1</h3> <pre> 3 NYY YNY YYN </pre> <p> この出力は 3 頂点の完党グラフを衚すこのグラフでは <var>A(G) = E(G) = 1</var> であり臎呜的なケヌスには皋遠い </p> <h3>入力䟋 2</h3> <pre> </pre> <h3>出力䟋 2</h3> <pre> 3 NYN YNY NYN </pre> <p> この出力は 3 頂点のパスグラフを衚すこのグラフでは <var>A(G) = 2</var><var>E(G) = (1+1+1+1+2+2)/6 = 4/3</var> なので <var>A(G) - E(G) = 2/3</var> ずなる </p>
p01398
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h2> Problem A: スワップ暗号 </h2> <p> R倧孊のずある2D奜きな圌は、人に芋られるず赀面するような恥ずかしい文章を日頃からよく曞いおいる。 そのため、第䞉者に自分の曞いおいる文章を芋られないために、圌が独自に考え出したスワップ暗号ずいう手法により文章を暗号化しおいる。 スワップ暗号では、次のようなステップを<i>N</i>回繰り返し、暗号化を行う。 </p> <ol> <li> 文字列の<i>a<sub>i</sub></i>番目ず<i>b<sub>i</sub></i>番目を入れ替える</li> <li> この2぀の文字を、<i>a<sub>i</sub></i>ず<i>b<sub>i</sub></i>の差分だけアルファベット順に戻す</li> </ol> <p> ただし、アルファベット順で、'a'の前は'z'ずする。 </p> <p> 䟋えば、"aojwo"ずいう文字列に察し、<i>a<sub>1</sub></i>=1、<i>b<sub>1</sub></i>=4、ずいう暗号化操䜜を行ったずするず、次のようになる。 </p> <ol> <li> 1番目ず4番目を入れ替える("aojwo"→"wojao")</li> <li> この2぀の文字'w'ず'a'を、1ず4の差分3だけアルファベット順に戻す("wojao"→"tojxo")</li> <ul> <li> 'w'は、アルファベット順に3戻すず、'w'→'v'→'u'→'t'ずなる</li> <li> 'a'は、アルファベット順に3戻すず、'a'→'z'→'y'→'x'ずなる</li> </ul> </ol> <p> よっお、"aojwo"は、"tojxo"ず暗号化される。 </p> <p> この暗号化により圌の文章は、原文がわからないように暗号化できるはずだったのだが、あろうこずか圌は暗号化に䜿甚したスワップ操䜜の過皋を流出させおしたった。 あなたの仕事は、暗号化された文字列ず暗号化に䜿甚したスワップ操䜜が䞎えられたずき"埩号"を行うプログラムを䜜成し、2D奜きな圌をはずかしめおやるこずである。 </p> <h2> Input </h2> <p> 入力は、耇数のデヌタセットからなる。デヌタセットの総数は20以䞋である。 各デヌタセットは、次の圢匏をしおいる。 </p> <pre> <i>N</i> <i>message</i> <i>a<sub>1</sub></i> <i>b<sub>1</sub></i> ... <i>a<sub>i</sub></i> <i>b<sub>i</sub></i> ... <i>a<sub>N</sub></i> <i>b<sub>N</sub></i> </pre> <p> <i>N</i>(<i>0 &lt; N &le; 100</i>)は、暗号化するずきにスワップ操䜜した回数を瀺す敎数である。 <i>message</i>は、暗号化されたデヌタを瀺す。 暗号デヌタは、アルファベットの小文字のみで構成される文字列である。 <i>message</i>の長さを<i>len</i>ずしたずき、<i>2 &le; </i><i>len</i><i> &le; 100</i>ず仮定しおよい。 </p> <p> <i>a<sub>i</sub></i>、<i>b<sub>i</sub></i>は、暗号化においおスワップを行った2぀のむンデックスを衚しおいる。 <i>1 &le; a<sub>i</sub> &lt; b<sub>i</sub> &le;</i> <i>len</i>ず仮定しおよい。 暗号化は、入力された順番にスワップ操䜜をしたものずする。 </p> <p> 入力の終了は、0のみからなる1行で瀺される。このデヌタに぀いおは、凊理する必芁はない。 </p> <h2> Output </h2> <p> 各デヌタセットに察しお、埩号した文字列を1行に出力せよ。 </p> <h2> Sample Input </h2> <pre> 1 tojxo 1 4 5 uhcqmlmkv 4 5 6 9 3 6 1 7 3 6 5 shzxadexonr 8 9 3 9 5 8 4 9 10 11 0 </pre> <h2> Output for Sample Input </h2> <pre> aojwo shinryaku shitadegeso </pre>
p01232
<h1><font color="#000">Problem J:</font> いにしえの数匏</h1> <p> あなたの友人の考叀孊者が遺跡を発掘しおいた ある日圌は怪しげな蚘号の矅列が刻たれおいる石盀を倧量に発芋した 圌はこの倧発芋に倧喜びしすぐさた石盀に刻たれおいる蚘号の解読を始めた 䜕週間にもわたる圌の解読の努力の結果 どうやらこれらの石盀には倉数・挔算子・カッコの組み合わせで成り立っおいる 数匏のようなものが刻たれおいるこずがわかった 発掘した石盀ず遺跡に関わる文献を調べおいくうちに圌はさらに それぞれの石盀で挔算子の結合芏則が異なっおおり それぞれの石盀の先頭に挔算子の結合芏則が蚘されおいるらしいこずを突きずめた しかし圌は数孊が苊手であるため挔算子の結合芏則を芋おも すぐには数匏がどのように結合しおいるかがわからなかった そこで圌は優れたコンピュヌタサむ゚ンティストであるあなたに 「石盀に曞かれおいる数匏がどのように結合しおいるかを調べおほしい」 ず䟝頌しおきた あなたは圌を手助けするこずができるだろうか </p> <p> 数匏䞭に珟れる挔算子には優先順䜍が定められおおり 優先順䜍の高い挔算子から順に結合しおいく 同䞀優先順䜍をも぀挔算子にはそれぞれ結合方向が定められおおり 巊から右に結合する堎合は巊にある挔算子から順に 右から巊に結合する堎合は右にある挔算子から順に結合しおいく 䟋えば <code>+</code> より <code>*</code> の方が優先順䜍が高く <code>*</code> が巊から右に結合する堎合 匏 <code>a+b*c*d</code> は <code>(a+((b*c)*d))</code> のように結合する サンプル入力にも他の䟋がいく぀か挙げられおいるので参照のこず </p> <h2>Input</h2> <p> 入力に䞎えられる数匏は以䞋の <var>Expr</var> で定矩されるような文字列である この定矩においお<var>Var</var> は倉数を衚し <var>Op</var> は挔算子を衚す </p> <table> <tr> <td><var>Expr</var></td> <td>::=</td> <td><var>Var</var></td> </tr> <tr> <td></td> <td class="bar-cell">|</td> <td><var>Expr</var> <var>Op</var> <var>Expr</var></td> </tr> <tr> <td></td> <td class="bar-cell">|</td> <td> &ldquo;<code>(</code>&rdquo; <var>Expr</var> &ldquo;<code>)</code>&rdquo; </td> </tr> <tr> <td><var>Var</var></td> <td>::=</td> <td> &ldquo;<code>a</code>&rdquo; | &ldquo;<code>b</code>&rdquo; | ... | &ldquo;<code>z</code>&rdquo; </td> </tr> <tr> <td><var>Op</var></td> <td>::=</td> <td> &ldquo;<code>+</code>&rdquo; | &ldquo;<code>-</code>&rdquo; | &ldquo;<code>*</code>&rdquo; | &ldquo;<code>/</code>&rdquo; | &ldquo;<code>&lt;</code>&rdquo; | &ldquo;<code>&gt;</code>&rdquo; | &ldquo;<code>=</code>&rdquo; | &ldquo;<code>&amp;</code>&rdquo; | &ldquo;<code>|</code>&rdquo; | &ldquo;<code>^</code>&rdquo; </td> </tr> </table> <p> 挔算子はすべお二項挔算子であり単項挔算子やその他の挔算子は存圚しない </p> <p> 入力はいく぀かのデヌタセットからなる 入力の先頭行にデヌタセット数 <var>D</var> (<var>D</var> &le; 100) が䞎えられ 以降の行に <var>D</var> 個のデヌタセットが続く </p> <p> それぞれのデヌタセットは次のようなフォヌマットで䞎えられる </p> <p> 挔算子の結合芏則の定矩<br> ク゚リの定矩 </p> <p> 挔算子の結合芏則の定矩は以䞋のようなフォヌマットで䞎えられるこの定矩においお<var>G</var> は挔算子グルヌプの数を衚す数である </p> <p> <var>G</var><br> 挔算子グルヌプ1 の定矩<br> 挔算子グルヌプ2 の定矩<br> ...<br> 挔算子グルヌプ<var>G</var> の定矩 </p> <p> 挔算子は結合の優先順䜍ごずにグルヌプに分けられおいる 同䞀のグルヌプに属する挔算子は結合の優先順䜍が等しく グルヌプの定矩が埌に珟れる挔算子の方が 前に珟れる挔算子より結合の優先順䜍が高い </p> <p> それぞれの挔算子グルヌプは以䞋のように定矩される </p> <p> <var>A</var> <var>M</var> <var>p</var><sub>1</sub> <var>p</var><sub>2</sub> ... <var>p</var><sub><var>M</var></sub> </p> <p> <var>A</var> は挔算子の結合方向を衚す文字で &ldquo;<code>L</code>&rdquo; か &ldquo;<code>R</code>&rdquo; の いずれかである &ldquo;<code>L</code>&rdquo; は巊から右に結合するこずを衚し &ldquo;<code>R</code>&rdquo; は右から巊に結合するこずを衚す <var>M</var> (<var>M</var> &gt; 0) は挔算子グルヌプに含たれる挔算子の数であり <var>p</var><sub><var>i</var></sub> (1 &le; <var>i</var> &le; <var>M</var>) はグルヌプに含たれる挔算子を衚す文字である 同じ挔算子がグルヌプ内に2床珟れるこずはなくたた デヌタセット内にグルヌプをたたがっお 同じ挔算子が2床珟れるこずもない </p> <p> 挔算子の定矩には䞊蚘の <var>Op</var> で定矩された挔算子のみが珟れる 1぀のデヌタセットにおいお必ず1぀以䞊の挔算子が定矩されるず仮定しおよい </p> <p> ク゚リの定矩は以䞋のようなフォヌマットで䞎えられる </p> <p> <var>N</var><br> <var>e</var><sub>1</sub><br> <var>e</var><sub>2</sub><br> ...<br> <var>e</var><sub><var>N</var></sub> </p> <p> <var>N</var> (0 &lt; <var>N</var> &le; 50) はク゚リずしお䞎えられる 数匏の数である <var>e</var><sub><var>i</var></sub> (1 &le; <var>i</var> &le; <var>N</var>) は䞊蚘の <var>Expr</var> の定矩を満たすような 匏を衚す空でない文字列である <var>e</var><sub><var>i</var></sub> の長さはたかだか100文字であり 圓該デヌタセットで定矩されおいない挔算子は出珟しないものず仮定しおよい </p> <h2>Output</h2> <p> デヌタセットごずに ク゚リずしお䞎えられたそれぞれの匏に぀いお 匏䞭の各挔算子に぀いお必ず1぀のカッコの組を甚いお すべおの二項挔算を正しく囲み 挔算子の結合を衚珟した文字列を出力せよ 入力の匏に珟れる倉数や挔算子の順序を倉曎しおはならない </p> <p> それぞれのデヌタセットの間には空行を出力せよ 出力の末尟に空行を出力しおはならない </p> <h2>Sample Input</h2> <pre> 2 3 R 1 = L 2 + - L 2 * / 6 a+b*c-d (p-q)/q/d a+b*c=d-e t+t+t+t+t s=s=s=s=s (((((z))))) 3 R 3 = &lt; &gt; L 3 & | ^ L 4 + - * / 1 a&gt;b*c=d&lt;e|f+g^h&amp;i&lt;j&gt;k </pre> <h2>Output for the Sample Input</h2> <pre> ((a+(b*c))-d) (((p-q)/q)/d) ((a+(b*c))=(d-e)) ((((t+t)+t)+t)+t) (s=(s=(s=(s=s)))) z (a&gt;((b*c)=(d&lt;((((e|(f+g))^h)&amp;i)&lt;(j&gt;k))))) </pre>
p04030
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has <var>3</var> keys on it: the <code>0</code> key, the <code>1</code> key and the backspace key.</p> <p>To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:</p> <ul> <li>The <code>0</code> key: a letter <code>0</code> will be inserted to the right of the string.</li> <li>The <code>1</code> key: a letter <code>1</code> will be inserted to the right of the string.</li> <li>The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.</li> </ul> <p>Sig has launched the editor, and pressed these keys several times. You are given a string <var>s</var>, which is a record of his keystrokes in order. In this string, the letter <code>0</code> stands for the <code>0</code> key, the letter <code>1</code> stands for the <code>1</code> key and the letter <code>B</code> stands for the backspace key. What string is displayed in the editor now?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ |s| ≩ 10</var> (<var>|s|</var> denotes the length of <var>s</var>)</li> <li><var>s</var> consists of the letters <code>0</code>, <code>1</code> and <code>B</code>.</li> <li>The correct answer is not an empty string.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the string displayed in the editor in the end.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>01B0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>00 </pre> <p>Each time the key is pressed, the string in the editor will change as follows: <code>0</code>, <code>01</code>, <code>0</code>, <code>00</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0BB1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>Each time the key is pressed, the string in the editor will change as follows: <code>0</code>, <code>(empty)</code>, <code>(empty)</code>, <code>1</code>.</p></section> </div> </span>
p02737
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are simple undirected graphs <var>X</var>, <var>Y</var>, <var>Z</var>, with <var>N</var> vertices each and <var>M_1</var>, <var>M_2</var>, <var>M_3</var> edges, respectively. The vertices in <var>X</var>, <var>Y</var>, <var>Z</var> are respectively called <var>x_1, x_2, \dots, x_N</var>, <var>y_1, y_2, \dots, y_N</var>, <var>z_1, z_2, \dots, z_N</var>. The edges in <var>X</var>, <var>Y</var>, <var>Z</var> are respectively <var>(x_{a_i}, x_{b_i})</var>, <var>(y_{c_i}, y_{d_i})</var>, <var>(z_{e_i}, z_{f_i})</var>.</p> <p>Based on <var>X</var>, <var>Y</var>, <var>Z</var>, we will build another undirected graph <var>W</var> with <var>N^3</var> vertices. There are <var>N^3</var> ways to choose a vertex from each of the graphs <var>X</var>, <var>Y</var>, <var>Z</var>. Each of these choices corresponds to the vertices in <var>W</var> one-to-one. Let <var>(x_i, y_j, z_k)</var> denote the vertex in <var>W</var> corresponding to the choice of <var>x_i, y_j, z_k</var>.</p> <p>We will span edges in <var>W</var> as follows:</p> <ul> <li>For each edge <var>(x_u, x_v)</var> in <var>X</var> and each <var>w, l</var>, span an edge between <var>(x_u, y_w, z_l)</var> and <var>(x_v, y_w, z_l)</var>.</li> <li>For each edge <var>(y_u, y_v)</var> in <var>Y</var> and each <var>w, l</var>, span an edge between <var>(x_w, y_u, z_l)</var> and <var>(x_w, y_v, z_l)</var>.</li> <li>For each edge <var>(z_u, z_v)</var> in <var>Z</var> and each <var>w, l</var>, span an edge between <var>(x_w, y_l, z_u)</var> and <var>(x_w, y_l, z_v)</var>.</li> </ul> <p>Then, let the weight of the vertex <var>(x_i, y_j, z_k)</var> in <var>W</var> be <var>1,000,000,000,000,000,000^{(i +j + k)} = 10^{18(i + j + k)}</var>. Find the maximum possible total weight of the vertices in an <a href="https://en.wikipedia.org/wiki/Independent_set_(graph_theory)">independent set</a> in <var>W</var>, and print that total weight modulo <var>998,244,353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100,000</var></li> <li><var>1 \leq M_1, M_2, M_3 \leq 100,000</var></li> <li><var>1 \leq a_i, b_i, c_i, d_i, e_i, f_i \leq N</var></li> <li><var>X</var>, <var>Y</var>, and <var>Z</var> are simple, that is, they have no self-loops and no multiple edges.</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_1</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>\vdots</var> <var>a_{M_1}</var> <var>b_{M_1}</var> <var>M_2</var> <var>c_1</var> <var>d_1</var> <var>c_2</var> <var>d_2</var> <var>\vdots</var> <var>c_{M_2}</var> <var>d_{M_2}</var> <var>M_3</var> <var>e_1</var> <var>f_1</var> <var>e_2</var> <var>f_2</var> <var>\vdots</var> <var>e_{M_3}</var> <var>f_{M_3}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible total weight of an independent set in <var>W</var>, modulo <var>998,244,353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 1 2 1 1 2 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>46494701 </pre> <p>The maximum possible total weight of an independent set is that of the set <var>(x_2, y_1, z_1)</var>, <var>(x_1, y_2, z_1)</var>, <var>(x_1, y_1, z_2)</var>, <var>(x_2, y_2, z_2)</var>. The output should be <var>(3 \times 10^{72} + 10^{108})</var> modulo <var>998,244,353</var>, which is <var>46,494,701</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 3 1 2 3 2 2 2 1 2 3 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>883188316 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100000 1 1 2 1 99999 100000 1 1 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>318525248 </pre></section> </div> </span>
p01818
<h2>Leapfrog</h2> <h3>Problem Statement</h3> <p><var>N</var> 個のマスが円状に䞊んでいる。マスは時蚈回りに <var>1,\ 2,\ </var> ... <var>,\ N</var> ず番号が振られおいる。各 <var>i</var> (<var>1 &le; i &le; N&minus;1</var>) に぀いお、<var>i</var> 番目のマスず <var>i+1</var> 番目のマスは隣り合う。たた、<var>N</var> 番目のマスず <var>1</var> 番目のマスは隣り合う。</p> <p>これらのうち <var>M</var> 個のマスには、互いに区別できない駒が <var>1</var> 個ず぀眮かれおいる。はじめ、<var>x_1,\ x_2,\ </var> ... <var>,\ x_M</var> 番目のマスに駒が眮かれおいる。次の操䜜を䜕回か行い、<var>y_1,\ y_2,\ </var> ... <var>,\ y_M</var> 番目のマスに駒が眮かれおいるようにしたい。</p> <ul><li>時蚈回りたたは反時蚈回りに連続する <var>3</var> 個のマスを遞び、順に <var>A,\ B,\ C</var> ずおく。<var>A</var> ず <var>B</var> にそれぞれ駒があり <var>C</var> に駒がないならば、<var>A</var> の駒を <var>C</var> ぞ移動する。</li></ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_leapfrog"> </center> <p><var>y_1,\ y_2,\ </var> ... <var>,\ y_M</var> 番目のマスに駒が眮かれおいるようにできるか刀定せよ。できるならば、必芁な操䜜の回数の最小倀を求めよ。</p> <h3>Constraints</h3> <ul> <li><var>3 &le; N &le; 3,000</var></li> <li><var>1 &le; M &le; N</var></li> <li><var>1 &le; x_1&lt;x_2&lt;</var> ... <var>&lt;x_M &le; N</var></li> <li><var>1 &le; y_1&lt;y_2&lt;</var> ... <var>&lt;y_M &le; N</var></li> </ul> <h3>Input Format</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre> <var>N</var> <var>M</var> <var>x_1</var> <var>x_2</var> ... <var>x_M</var> <var>y_1</var> <var>y_2</var> ... <var>y_M</var> </pre> <h3>Output Format</h3> <p><var>y_1,\ y_2,\ </var> ... <var>,\ y_M</var> 番目のマスに駒が眮かれおいるようにできるならば、必芁な操䜜の回数の最小倀を䞀行に出力せよ。できないならば、代わりに <code>-1</code> を䞀行に出力せよ。</p> <h3>Sample Input 1</h3> <pre> 7 2 1 2 5 6 </pre> <h3>Sample Output 1</h3> <pre> 3 </pre> <p>次のように <var>3</var> 回の操䜜を行えばよい。</p> <ul> <li><var>2</var> 番目のマスの駒を <var>7</var> 番目のマスぞ移動する。</li> <li><var>1</var> 番目のマスの駒を <var>6</var> 番目のマスぞ移動する。</li> <li><var>7</var> 番目のマスの駒を <var>5</var> 番目のマスぞ移動する。</li> </ul> <h3>Sample Input 2</h3> <pre> 3 1 1 2 </pre> <h3>Sample Output 2</h3> <pre> -1 </pre> <h3>Sample Input 3</h3> <pre> 2999 3 1 2 3 2 3 4 </pre> <h3>Sample Output 3</h3> <pre> 4491004 </pre>
p03825
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> zeros and <var>M</var> ones written on a blackboard. Starting from this state, we will repeat the following operation: select <var>K</var> of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those <var>K</var> numbers. Here, assume that <var>N + M - 1</var> is divisible by <var>K - 1</var>.</p> <p>Then, if we repeat this operation until it is no longer applicable, there will be eventually one rational number left on the blackboard.</p> <p>Find the number of the different possible values taken by this rational number, modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ N, M ≩ 2000</var></li> <li><var>2 ≩ K ≩ 2000</var></li> <li><var>N + M - 1</var> is divisible by <var>K - 1</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are five possible values for the number that will be eventually left on the blackboard: <var>\frac{1}{4}</var>, <var>\frac{3}{8}</var>, <var>\frac{1}{2}</var>, <var>\frac{5}{8}</var> and <var>\frac{3}{4}</var>.</p> <p>For example, <var>\frac{3}{8}</var> can be eventually left if we:</p> <ul> <li>Erase <var>0</var> and <var>1</var>, then write <var>\frac{1}{2}</var>.</li> <li>Erase <var>\frac{1}{2}</var> and <var>1</var>, then write <var>\frac{3}{4}</var>.</li> <li>Erase <var>0</var> and <var>\frac{3}{4}</var>, then write <var>\frac{3}{8}</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>150 150 14 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>937426930 </pre></section> </div> </span>
p02367
<H1>Bridges</H1> <p> Find bridges of an undirected graph <var>G(V, E)</var>. </p> <p> A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components. </p> <H2>Input</H2> <pre> <var>|V|</var> <var>|E|</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> </pre> <p> , where <var>|V|</var> is the number of nodes and <var>|E|</var> is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively. </p> <p> <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target nodes of <var>i</var>-th edge (undirected). </p> <H2>Output</H2> <p> A list of <i>bridges</i> of the graph ordered by name. For each bridge, names of its end-ponints, source and target (source &lt; target), should be printed separated by a space. The sources should be printed ascending order, then the target should also be printed ascending order for the same source. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>|V|</var> &le; 100,000</li> <li>0 &le; <var>|E|</var> &le; 100,000</li> <li>The graph is connected</li> <li>There are no parallel edges</li> <li>There are no self-loops</li> </ul> <H2>Sample Input 1</H2> <pre> 4 4 0 1 0 2 1 2 2 3 </pre> <H2>Sample Output 1</H2> <pre> 2 3 </pre> <br/> <H2>Sample Input 2</H2> <pre> 5 4 0 1 1 2 2 3 3 4 </pre> <H2>Sample Output 2</H2> <pre> 0 1 1 2 2 3 3 4 </pre>
p03126
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Katsusando loves omelette rice.</p> <p>Besides, he loves crÚme brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.</p> <p>To prove that hypothesis, he conducted a survey on <var>M</var> kinds of foods and asked <var>N</var> people whether they like these foods or not.</p> <p>The <var>i</var>-th person answered that he/she only likes the <var>A_{i1}</var>-th, <var>A_{i2}</var>-th, <var>...</var>, <var>A_{iK_i}</var>-th food.</p> <p>Find the number of the foods liked by all the <var>N</var> people.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N, M \leq 30</var></li> <li><var>1 \leq K_i \leq M</var></li> <li><var>1 \leq A_{ij} \leq M</var></li> <li>For each <var>i</var> <var>(1 \leq i \leq N)</var>, <var>A_{i1}, A_{i2}, ..., A_{iK_i}</var> are distinct.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K_1</var> <var>A_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1K_1}</var> <var>K_2</var> <var>A_{21}</var> <var>A_{22}</var> <var>...</var> <var>A_{2K_2}</var> <var>:</var> <var>K_N</var> <var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NK_N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the foods liked by all the <var>N</var> people.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 2 1 3 3 1 2 3 2 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>As only the third food is liked by all the three people, <var>1</var> should be printed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 4 2 3 4 5 4 1 3 4 5 4 1 2 4 5 4 1 2 3 5 4 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Katsusando's hypothesis turned out to be wrong.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 30 3 5 10 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p03576
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> points in a two-dimensional plane.<br/> The coordinates of the <var>i</var>-th point <var>(1 \leq i \leq N)</var> are <var>(x_i,y_i)</var>.<br/> Let us consider a rectangle whose sides are parallel to the coordinate axes that contains <var>K</var> or more of the <var>N</var> points in its interior.<br/> Here, points on the sides of the rectangle are considered to be in the interior.<br/> Find the minimum possible area of such a rectangle. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq K \leq N \leq 50</var> </li> <li><var>-10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)</var> </li> <li><var>x_i≠x_j (1 \leq i&lt;j \leq N)</var> </li> <li><var>y_i≠y_j (1 \leq i&lt;j \leq N)</var> </li> <li>All input values are integers. (Added at 21:50 JST) </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>:</var> <var>x_{N}</var> <var>y_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible area of a rectangle that satisfies the condition. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 1 4 3 3 6 2 8 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>21 </pre> <p>One rectangle that satisfies the condition with the minimum possible area has the following vertices: <var>(1,1)</var>, <var>(8,1)</var>, <var>(1,4)</var> and <var>(8,4)</var>.<br/> Its area is <var>(8-1) × (4-1) = 21</var>. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 0 0 1 1 2 2 3 3 </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>4 3 -1000000000 -1000000000 1000000000 1000000000 -999999999 999999999 999999999 -999999999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3999999996000000001 </pre> <p>Watch out for integer overflows. </p></section> </div> </span>
p03599
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.</p> <ul> <li>Operation 1: Pour <var>100A</var> grams of water into the beaker.</li> <li>Operation 2: Pour <var>100B</var> grams of water into the beaker.</li> <li>Operation 3: Put <var>C</var> grams of sugar into the beaker.</li> <li>Operation 4: Put <var>D</var> grams of sugar into the beaker.</li> </ul> <p>In our experimental environment, <var>E</var> grams of sugar can dissolve into <var>100</var> grams of water.</p> <p>Snuke will make sugar water with the highest possible density.</p> <p>The beaker can contain at most <var>F</var> grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted.</p> <p>We remind you that the sugar water that contains <var>a</var> grams of water and <var>b</var> grams of sugar is <var>\frac{100b}{a + b}</var> percent. Also, in this problem, pure water that does not contain any sugar is regarded as <var>0</var> percent density sugar water.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A &lt; B \leq 30</var></li> <li><var>1 \leq C &lt; D \leq 30</var></li> <li><var>1 \leq E \leq 100</var></li> <li><var>100A \leq F \leq 3</var> <var>000</var></li> <li><var>A</var>, <var>B</var>, <var>C</var>, <var>D</var>, <var>E</var> and <var>F</var> are all integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>Print two integers separated by a space. The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 2 10 20 15 200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>110 10 </pre> <p>In this environment, <var>15</var> grams of sugar can dissolve into <var>100</var> grams of water, and the beaker can contain at most <var>200</var> grams of substances.</p> <p>We can make <var>110</var> grams of sugar water by performing Operation 1 once and Operation 3 once. It is not possible to make sugar water with higher density. For example, the following sequences of operations are infeasible:</p> <ul> <li>If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.</li> <li>If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed <var>200</var> grams.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 1 2 100 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>200 100 </pre> <p>There are other acceptable outputs, such as:</p> <pre>400 200 </pre> <p>However, the output below is not acceptable:</p> <pre>300 150 </pre> <p>This is because, in order to make <var>300</var> grams of sugar water containing <var>150</var> grams of sugar, we need to pour exactly <var>150</var> grams of water into the beaker, which is impossible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>17 19 22 26 55 2802 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2634 934 </pre></section> </div> </span>
p03063
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. Every stone is painted white or black. A string <var>S</var> represents the color of the stones. The <var>i</var>-th stone from the left is white if the <var>i</var>-th character of <var>S</var> is <code>.</code>, and the stone is black if the character is <code>#</code>.</p> <p>Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2\times 10^5</var></li> <li><var>S</var> is a string of length <var>N</var> consisting of <code>.</code> and <code>#</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of stones that needs to be recolored.</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 </pre> <p>It is enough to change the color of the first stone to white.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 #.##. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 ......... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p03433
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>E869120 has <var>A</var> <var>1</var>-yen coins and infinitely many <var>500</var>-yen coins.<br/> Determine if he can pay exactly <var>N</var> yen using only these coins.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is an integer between <var>1</var> and <var>10000</var> (inclusive).</li> <li><var>A</var> is an integer between <var>0</var> and <var>1000</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If E869120 can pay exactly <var>N</var> yen using only his <var>1</var>-yen and <var>500</var>-yen coins, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2018 218 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>We can pay <var>2018</var> yen with four <var>500</var>-yen coins and <var>18</var> <var>1</var>-yen coins, so the answer is <code>Yes</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2763 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>When we have no <var>1</var>-yen coins, we can only pay a multiple of <var>500</var> yen using only <var>500</var>-yen coins. Since <var>2763</var> is not a multiple of <var>500</var>, we cannot pay this amount.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>37 514 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
p02388
<H1>X Cubic</H1> <p> Write a program which calculates the cube of a given integer <var>x</var>. </p> <H2>Input</H2> <p> An integer <var>x</var> is given in a line. </p> <H2>Output</H2> <p> Print the cube of <var>x</var> in a line. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>x</var> &le; 100</li> </ul> <H2>Sample Input 1</H2> <pre> 2 </pre> <H2>Sample Output 1</H2> <pre> 8 </pre> <H2>Sample Input 2</H2> <pre> 3 </pre> <H2>Sample Output 2</H2> <pre> 27 </pre>
p02672
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><strong>This is an interactive task.</strong></p> <p>You have to guess a secret password <var>S</var>. A password is a nonempty string whose length is at most <var>L</var>. The characters of a password can be lowercase and uppercase english letters (a, b, ... , z, A, B, ... , Z) and digits (0, 1, ... , 9).</p> <p>In order to guess the secret password <var>S</var> you can ask queries. A query is made of a valid password <var>T</var>, the answer to such query is the edit distance between <var>S</var> and <var>T</var> (the operations considered for the edit distance are: removal, insertion, substitution). You can ask at most <var>Q</var> queries.</p> <p><strong>Note</strong>: For a definition of edit distance (with operations: removal, insertion, substitution), see <a href="https://en.wikipedia.org/w/index.php?title=Levenshtein_distance&amp;oldid=954598393">this wikipedia page</a>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>L = 128</var></li> <li><var>Q = 850</var></li> <li>The secret password <var>S</var> is chosen before the beginning of the interaction.</li> </ul> </section> </div> <div class="part"> <section> <h3>Interaction</h3><p>To ask a query, print on Standard Output (with a newline at the end)</p> <pre>? <var>T</var> </pre> <p>The string <var>T</var> must be a valid password.</p> <p>The answer <var>ans</var> to each query shall be read from Standard Input in the form:</p> <pre><var>ans</var> </pre> <p>As soon as you have determined the hidden password <var>S</var>, you should print on Standard Output (with a newline at the end)</p> <pre>! <var>S</var> </pre> <p>and terminate your program.</p> </section> </div> <div class="part"> <section> <h3>Judgement</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 (your guess of) the hidden password, the program must be terminated immediately. Otherwise, the behavior of the judge is undefined.</li> <li>If the password you have determined is wrong, you will get <code>WA</code>.</li> <li>If you ask a malformed query (for example because the string is not a valid password, or you forget to put <code>?</code>) or if your program crashes or if you ask more than <var>Q</var> queries, the behavior of the judge is undefined (it does not necessarily give <code>WA</code>).</li> </ul> </section> </div> <div class="part"> <section> <h3>Samples</h3><p>In the only sample testcase of this problem the hidden password is <code>Atcod3rIsGreat</code>.</p> <p>The following one is an example of interaction if <var>S=</var><code>Atcod3rIsGreat</code>.</p> <table class="table table-bordered"> <thead> <tr> <th align="left">Input</th> <th align="left">Output</th> </tr> </thead> <tbody> <tr> <td align="left"></td> <td align="left"><var>\texttt{? AtcoderIsBad}</var></td> </tr> <tr> <td align="left"><var>5</var></td> <td align="left"></td> </tr> <tr> <td align="left"></td> <td align="left"><var>\texttt{? AtcoderIsGreat}</var></td> </tr> <tr> <td align="left"><var>1</var></td> <td align="left"></td> </tr> <tr> <td align="left"></td> <td align="left"><var>\texttt{! Atcod3rIsGreat}</var></td> </tr> </tbody> </table></section> </div> </span>
p03960
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Mr. Takahashi has in his room an art object with <var>H</var> rows and <var>W</var> columns, made up of <var>H \times W</var> blocks. Each block has a color represented by a lowercase English letter (<code>a</code>-<code>z</code>). The color of the block at the <var>i</var>-th row and <var>j</var>-th column is <var>c_{i,j}</var>. </p> <p>Mr. Takahashi would like to dismantle the object, finding it a bit kitschy for his tastes. The dismantling is processed by repeating the following operation: </p> <ul> <li>Choose one of the <var>W</var> columns and push down that column one row. The block at the bottom of that column disappears.</li> </ul> <p>Each time the operation is performed, a cost is incurred. Since blocks of the same color have a property to draw each other together, the cost of the operation is the number of the pairs of blocks <var>(p, q)</var> such that:</p> <ul> <li>The block <var>p</var> is in the selected column.</li> <li>The two blocks <var>p</var> and <var>q</var> are horizontally adjacent (before pushing down the column).</li> <li>The two blocks <var>p</var> and <var>q</var> have the same color.</li> </ul> <p>Mr. Takahashi dismantles the object by repeating the operation <var>H \times W</var> times to get rid of all the blocks. Compute the minimum total cost to dismantle the object.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ H ≀ 300</var></li> <li><var>2 ≀ W ≀ 300</var></li> <li>All characters <var>c_{i,j}</var> are lowercase English letters (<code>a</code>-<code>z</code>).</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li>In test cases worth <var>300</var> points, <var>W = 3</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>c_{1,1}c_{1,2}</var>..<var>c_{1,W}</var> <var>c_{2,1}c_{2,2}</var>..<var>c_{2,W}</var> <var>:</var> <var>c_{H,1}c_{H,2}</var>..<var>c_{H,W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total cost to dismantle the object.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 rrr brg </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>For example, the total cost of <var>2</var> can be achieved by performing the operation as follows and this is the minimum value.</p> <div style="text-align: center;"> <img alt="ccb25ed6f1df9367829b68523e1deff4.png" src="https://atcoder.jp/img/code-festival-2016-qualc/ccb25ed6f1df9367829b68523e1deff4.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 xya xya ayz ayz xaz xaz </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>The total cost of <var>0</var> can be achieved by first pushing down all blocks of the middle column, then all of the left column, and all of the right column.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 2 ay xa xy ay </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>The total cost of <var>0</var> can be achieved by the following operations:</p> <ul> <li>pushing down the right column one row;</li> <li>pushing down the left column one row;</li> <li>pushing down all of the right column;</li> <li>and pushing down all of the left column.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 5 aaaaa abbba ababa abbba aaaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>24 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>7 10 xxxxxxxxxx ccccxxffff cxxcxxfxxx cxxxxxffff cxxcxxfxxx ccccxxfxxx xxxxxxxxxx </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>130 </pre></section> </div> </span>
p02222
<span class="lang"> <span class="lang-ja"> <h1>L: 朚の圩色</h1> <div class="part"> <section> <h3>問題文</h3><p>モデュヌロさんは朚の絵を描くのがずおもうたいです。</p> <p>モデュヌロさんは長い幎月をかけお頂点が $N$ 個である朚の絵を曞きたした。 この朚の頂点には $1$ から $N$ たでの番号が぀いおおり、頂点 $a_i$ ず $b_i$ $(1 \leq i \leq N-1)$ は盎接蟺で぀ながれおいたす。 すべおの頂点には色がただ塗られおいたせん。</p> <p>モデュヌロさんが曞いたこの朚の絵はたくさんの人を感動させ、有名な矎術通に食られるこずが決たりたした。</p> <p>この矎術通には順に $N$ 人の人が来堎したす。モデュヌロさんは来堎者特兞ずしお、それぞれの人に $1$ 枚ず぀朚の絵のコピヌを配垃するこずにしたした。</p> <p>さらに、来堎者に満足しおもらうため、配垃する朚の絵の頂点すべおに色を塗るこずにしたした。 $k$ 番目 $(1 \leq k \leq N)$ に来堎する人は、以䞋の 2 条件を共に満たす絵が配垃されたずきにのみ満足したす。</p> <ul> <li>最短距離が $k$ の倍数である任意の 2 頂点は、同じ色で塗られおいる。 </li> <li>最短距離が $k$ の倍数でない任意の 2 頂点は、異なる色で塗られおいる。 </li> </ul> <p>モデュヌロさんが持っおいる色の数は無限にありたす。たた、それぞれのコピヌで色の塗り方が違っおも構いたせん。</p> <p>それぞれの来堎者に察し、その来堎者を満足させるように頂点を塗るこずができるかどうか刀定しおください。</p> </section> </div> <div class="part"> <section> <h3>制玄</h3><ul> <li>$1 \leq N \leq 10^5$</li> <li>$1 \leq a_i, b_i \leq N$</li> <li>入力はすべお敎数である</li> <li>入力によっお䞎えられるグラフが朚であるこずは保蚌される。</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre>$N$ $a_1$ $b_1$ $a_2$ $b_2$ $\vdots$ $a_{N-1}$ $b_{N-1}$ </pre> <ul> <li>$1$ 行目には、朚の頂点数を衚す敎数 $N$ が䞎えられる。</li> <li>$2$ 行目から $N$ 行目には、朚の蟺の情報が䞎えられる。このうち $i+1(1 \leq i \leq N-1)$ 行目には、頂点 $a_i$ ず $b_i$ が蟺で぀ながっおいるこずを瀺す 2 ぀の敎数 $a_i,b_i$ が䞎えられる。</li> </ul> </section> </div> <div class="part"> <section> <h3>出力</h3><p>以䞋を満たす <code>0</code> たたは <code>1</code> からなる文字列 $S = s_1 s_2 \ldots s_N$ を出力せよ。</p> <ul> <li>$s_k = 1$ : $k$ 番目の来堎者が満足できるよう䞎えられた朚の絵の頂点に圩色できる</li> <li>$s_k = 0$ : $k$ 番目の来堎者が満足できるよう䞎えられた朚の絵の頂点に圩色できない</li> </ul> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力䟋 1</h3><pre>7 1 3 2 3 3 4 4 5 4 6 6 7 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 1</h3><pre>1100111 </pre> <p>入力䟋1の朚は以䞋の図のようになりたす。</p> <p><img alt="sample_picture_1_0" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_coloring_1_0.png" /></p> <p>䟋えば、$k=2$ の時、以䞋のように塗れば条件を満たしたす。</p> <p><img alt="sample_picture_1_2" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_coloring_1_2.png" /></p> <p>たた、$k=5$ の時、以䞋のように塗れば条件を満たしたす。 </p> <p><img alt="sample_picture_1_1" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_coloring_1_1.png" /></p> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋 2</h3><pre>6 1 2 2 3 3 4 4 5 5 6 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 2</h3><pre>111111 </pre> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋 3</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 3</h3><pre>1 </pre></section> </div> </span> </span>
p00531
<h2>氎道料金 (Water Rate)</h2> <h2> 問題</h2> <p> JOI 君が䜏んでいる地域には氎道䌚瀟が X 瀟ず Y 瀟の 2 ぀ある2 ぀の䌚瀟の 1 ヶ月の氎道料金は1 ヶ月の氎道の䜿甚量に応じお次のように決たる </p> <ul> <li>X 瀟 1 リットル あたり A 円かかる</li> <li>Y 瀟 基本料金は B 円である䜿甚量が C リットル以䞋ならば料金は基本料金 B 円のみがかかる䜿甚量が C リットルを超えるず基本料金 B 円に加えお远加料金がかかる远加料金は䜿甚量が C リットルを 1 リットル超えるごずに D 円である</li> </ul> <p> JOI 君の家では 1 ヶ月の氎道の䜿甚量が P リットルである </p> <p> 氎道料金ができるだけ安くなるように氎道䌚瀟を遞ぶずきJOI 君の家の 1 ヶ月の氎道料金を求めよ </p> <h2>入力</h2> <p> 入力は 5 行からなり1 行に 1 ぀ず぀敎数が曞かれおいる<br> 1 行目には X 瀟の 1 リットルあたりの料金 A が曞かれおいる<br> 2 行目には Y 瀟の基本料金 B が曞かれおいる<br> 3 行目には Y 瀟の料金が基本料金のみになる䜿甚量の䞊限 C が曞かれおいる<br> 4 行目には Y 瀟の 1 リットルあたりの远加料金 D が曞かれおいる<br> 5 行目には JOI 君の家の 1 ヶ月の氎道の䜿甚量 P が曞かれおいる </p> <p> 曞かれおいる敎数 A, B, C, D, P はすべお 1 以䞊 10000 以䞋である </p> <h2>出力</h2> <p> JOI 君の家の 1 ヶ月の氎道料金を衚す敎数を 1 行で出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 9 100 20 3 10 </pre> <h3>出力䟋 1</h3> <pre> 90 </pre> <h3>入力䟋 2</h3> <pre> 8 300 100 10 250 </pre> <h3>出力䟋 2</h3> <pre> 1800 </pre> <p> 入出力䟋 1 ではJOI 君の家の 1 ヶ月の氎道の䜿甚量は 10 リットルである </p> <ul> <li>X 瀟の氎道料金は 9 &times; 10 = 90 円である</li> <li>JOI 君の家の 1 ヶ月の氎道の䜿甚量は 20 リットル以䞋なのでY 瀟の氎道料金は基本料金の 100 円である</li> </ul> <p> JOI 君の家は氎道料金がより安い X 瀟を遞ぶそのずきの JOI 君の家の 1 ヶ月の氎道料金は 90 円である </p> <p> 入出力䟋 2 ではJOI 君の家の 1 ヶ月の氎道の䜿甚量は 250 リットルである </p> <ul> <li>X 瀟の氎道料金は 8 &times; 250 = 2000 円である</li> <li>JOI 君の家の 1 ヶ月の氎道の䜿甚量は 100 リットル以䞊で超過量は 250 - 100 = 150 リットルであるよっおY 瀟の氎道料金は基本料金の 300 円に加えお 10 &times; 150 = 1500 円の远加料金がかかり合蚈の氎道料金は 300 + 1500 = 1800 円である</li> </ul> <p> JOI 君の家は氎道料金がより安い Y 瀟を遞ぶそのずきの JOI 君の家の 1 ヶ月の氎道料金は 1800 円である </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00161
<H1>䜓育祭Sport Meet</H1> <p> 秋の䜓育祭が行われたす。皮目は埒競走、ボヌル運び、障害物競走、リレヌの4皮目です。参加チヌムは <var>n</var> チヌムで、この4皮目の合蚈タむムが最も小さいチヌムが「優勝」、次に小さいチヌムが「準優勝」、そしお、最䞋䜍より2番目のチヌムを「ブヌビヌ賞」ずしお衚地したいず思いたす。 </p> <p> 各チヌムの成瞟を入力ずしお、「優勝」、「準優勝」、「ブヌビヌ賞」のチヌムを出力するプログラムを䜜成しおください。 ただし、チヌムにはそれぞれ 1 から <var>n</var> のチヌム番号が割り圓おられおいたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>record<sub>1</sub></var> <var>record<sub>2</sub></var> : <var>record<sub>n</sub></var> </pre> <p> 行目に察象ずなるチヌムの数 <var>n</var> (4 &le; <var>n</var> &le; 100000)、続く <var>n</var> 行に <var>i</var> 番目のチヌムの情報が䞎えられたす。各チヌムの情報は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>id</var> <var>m1</var> <var>s1</var> <var>m2</var> <var>s2</var> <var>m3</var> <var>s3</var> <var>m4</var> <var>s4</var> </pre> <p> <var>id</var> (1 &le; <var>id</var> &le; <var>n</var>)はチヌム番号、<var>m1</var>, <var>s1</var> はそれぞれ埒競走のタむムの分ず秒、<var>m2</var>, <var>s2</var> はそれぞれボヌル運びのタむムの分ず秒、<var>m3</var>, <var>s3</var> はそれぞれ障害物競走のタむムの分ず秒、<var>m4</var>, <var>s4</var> はそれぞれリレヌのタむムの分ず秒を衚したす。分ず秒はずもに0 以䞊 59 以䞋の敎数です。たた、合蚈タむムが耇数のチヌムで同じになるような入力はないものずしたす。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに以䞋の圢匏でチヌム番号を出力したす。<br/> <br/> 1 行目 優勝のチヌム番号<br/> 2 行目 準優勝のチヌム番号<br/> 3 行目 ブヌビヌ賞のチヌム番号<br/> </p> <H2>Sample Input</H2> <pre> 8 34001 3 20 3 8 6 27 2 25 20941 3 5 2 41 7 19 2 42 90585 4 8 3 12 6 46 2 34 92201 3 28 2 47 6 37 2 58 10001 3 50 2 42 7 12 2 54 63812 4 11 3 11 6 53 2 22 54092 3 33 2 54 6 18 2 19 25012 3 44 2 58 6 45 2 46 4 1 3 23 1 23 1 34 4 44 2 5 12 2 12 3 41 2 29 3 5 24 1 24 2 0 3 35 4 4 49 2 22 4 41 4 23 0 </pre> <H2>Output for the Sample Input</H2> <pre> 54092 34001 10001 1 3 2 </pre>
p01320
<h1><font color="#000">Problem G:</font> Magical Island 2</h1> <!-- <h3><U>魔法島物語2</U></h3> --> <p>ただ魔法があたりたえのように存圚した時代であるある魔導士の䞀族は魔力によっお䜜られた正方圢の圢の島に䜏んでいた</p> <p>ある時この島に危機が蚪れた垝囜が倧陞間匟道魔導ミサむルを開発しこの島を照準に合わせおきたのであるこの䞖界の魔法は地属性氎属性火属性颚属性などに分類でき魔導ミサむルもその四぀の属性のいずれかに属しおいた島の四隅にはそれぞれ地の氎晶氎の氎晶火の氎晶颚の氎晶が配眮されおいお氎晶に魔力を送り蟌むこずで察応する属性の魔法攻撃を防ぐこずがきでる</p> <p>魔導士達は垝囜が開発した倧陞間匟道魔導ミサむルによる攻撃をかろうじお退けるこずができたしかし垝囜は新たに闇属性に属する倧陞間匟道魔導ミサむルを開発し再びこの島に攻撃を仕掛けおきた闇属性に属する魔法はこの島に蚭眮されおいる氎晶で防ぐこずはできないそこで魔導士達は秘術ずしおこの島に䌝えられる光属性の防埡陣を甚いおミサむルを防ぐ事にした</p> <p>この光属性の防埡陣はある特定の圢状をした魔法陣を倧地に描くこずにより発動する 魔法陣は半埄 <i>R</i> の円呚を <i>M</i> 等分し <i>K</i> 個おきに盎線で結んだ図圢である魔法陣は任意の倧きさで描くこずができるが魔法の発動には方角が重芁なので䞀぀の角が真北を向くように描かなければならない防埡陣の効果が及ぶ範囲は描かれた魔法陣の内郚境界を含むず䞀臎するたたこの魔法の詠唱に必芁な゚ネルギヌは描いた魔法陣の半埄 <i>R</i> ず等しい</p> <p>図G-1は <i>M</i> = 4 <i>K</i> = 1 の堎合である灰色の郚分が魔方陣の効果が及ぶ領域である 図G-2は <i>M</i> = 6 <i>K</i> = 2 の堎合である図のように耇数の図圢が生じる堎合はそれらの図圢のいずれかに含たれおいれば防埡陣ずしおの効果が及ぶ<br /> </p> <center> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_G1"><br /> 図G-1: <i>M</i> = 4 <i>K</i> = 1 の堎合 小さい䞞が集萜を衚す<br /> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_G2"><br /> 図G-2: <i>M</i> = 6 <i>K</i> = 2 の堎合<br /> </p> </center> <p>あなたの仕事は集萜の䜍眮および <i>M</i> ず <i>K</i> の倀が䞎えられたずきに党おの集萜をカバヌするために必芁ずなる゚ネルギヌの最䜎量を求めるプログラムを曞くこずである</p> <h2>Input</h2> <p>入力は耇数のデヌタセットからなる 各デヌタセットは以䞋の圢匏で䞎えられる</p> <blockquote><i>N</i> <i>M</i> <i>K</i><br /> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br /> <i>x<sub>2</sub></i> <i>y<sub>2</sub></i><br /> ...<br /> <i>x<sub>N</sub></i> <i>y<sub>N</sub></i><br /> </blockquote> <p>最初の䞀行は 3 ぀の敎数<i>N</i>, <i>M</i>, <i>K</i> からなる <i>N</i> は集萜の数を衚す <i>M</i>, <i>K</i> に぀いおは問題文に蚘したずおりである 2 &le; <i>N</i> &le; 50 3 &le; <i>M</i> &le; 50 1 &le; <i>K</i> &le; (<i>M</i> - 1) / 2を仮定しおよい</p> <p>続く <i>N</i> 行は集萜の䜍眮を衚す 各行は二぀の敎数 <i>x<sub>i</sub></i> ず <i>y<sub>i</sub></i> からなる <i>x<sub>i</sub></i> ず <i>y<sub>i</sub></i> は <i>i</i> 番目の集萜のx座暙ずy座暙を衚す -1000 &le; <i>x<sub>i</sub></i> <i>y<sub>i</sub></i> &le; 1000 を仮定しお良いy軞の正方向が北を指す.</p> <p>入力の終わりはスペヌスで区切られた3個のれロからなる</p> <h2>Output</h2> <p>各デヌタセットに察し魔法陣の最小の半埄 <i>R</i> を1行に出力せよ 出力する倀は10<sup>-6</sup>以䞋の誀差を含んでいおも構わない倀は小数点以䞋䜕桁衚瀺しおも構わない</p> <h2>Sample Input</h2> <pre> 4 4 1 1 0 0 1 -1 0 0 -1 5 6 2 1 1 4 4 2 -4 -4 2 1 5 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 1.000000000 6.797434948 </pre>
p00862
<H1><font color="#000">Problem I:</font> Most Distant Point from the Sea</H1> <p> The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: "Where is the most distant point from the sea?" The answer to this question for Honshu was found in 1996. The most distant point is located in former Usuda Town, Nagano Prefecture, whose distance from the sea is 114.86 km. </p> <p> In this problem, you are asked to write a program which, given a map of an island, finds the most distant point from the sea in the island, and reports its distance from the sea. In order to simplify the problem, we only consider maps representable by convex polygons. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows. </p> <pre> <i>n</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> . . . <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> </pre> <p> Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space. </p> <p> <i>n</i> in the first line is the number of vertices of the polygon, satisfying 3 &le; <i>n</i> &le; 100. Subsequent <i>n</i> lines are the <i>x</i>- and <i>y</i>-coordinates of the <i>n</i> vertices. Line segments (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) - (<i>x</i><sub><i>i</i>+1</sub>, <i>y</i><sub><i>i</i>+1</sub>) (1 &le; <i>i</i> &le; <i>n</i> - 1) and the line segment (<i>x<sub>n</sub></i>, <i>y<sub>n</sub></i>) - (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive. </p> <p> You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one. </p> <p> The last dataset is followed by a line containing a single zero. </p> <H2>Output</H2> <p> For each dataset in the input, one line containing the distance of the most distant point from the sea should be output. An output line should not contain extra characters such as spaces. </p> <p> The answer should not have an error greater than 0.00001 (10<sup>-5</sup> ). You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. </p> <H2>Sample Input</H2> <pre> 4 0 0 10000 0 10000 10000 0 10000 3 0 0 10000 0 7000 1000 6 0 40 100 20 250 40 250 70 100 90 0 70 3 0 0 10000 10000 5000 5001 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5000.000000 494.233641 34.542948 0.353553 </pre>
p01770
<h1 id="arojams-mask-ムゞュラの仮面">E : Arojam&#39;s Mask / 仮面</h1> <h2 id="問題文">問題文</h2> <p>あなたは勇者である。勇者が旅をしおいる䞖界は <var>N</var> 個の街ず、異なる街同士を結ぶ <var>M</var> 本の道からなる。道 <var>i</var> は街 <var>a_i</var> ず街 <var>b_i</var> を結び、双方向に移動可胜である。</p> <p>街 <var>S</var> から出発し、街 <var>T</var> に移動するこずが勇者の目的である。 <var>S,T</var> は異なる街である。勇者は <var>0</var> 日目に街を出発し、ちょうど <var>1</var> 日かけお <var>1</var> 本の道を通っお移動するこずができる。道を䜿った移動には日数の制限 <var>R</var> があり、<var>R</var> 日目を超えるこずはできない。</p> <p>たた、勇者は任意の街で「オカリナを吹く」こずもできる。オカリナを吹くず、時は <var>0</var> 日目に、䜍眮は街 <var>S</var> に戻される。぀たり、<var>R</var> 回を超える移動を行う堎合は、最䜎䞀床はオカリナを吹かなければならない。</p> <p>さらに、勇者がある街に䜍眮するず「むベント」が発生するこずがある。むベントは <var>E</var> 皮類あり、<var>i</var> 番目のむベントは、街 <var>c_{i}</var> で発生する。むベントは勇者がそこにいるず自動的に発生し、新たに道 <var>a’_i</var> ず <var>b’_i</var> を結ぶ道が生じる。この道はオカリナを吹いおも消えるこずはなく、初めから存圚する道ずも、別のむベントによっお远加される道ずも重耇しない。ある町で起こるむベントは高々1぀である。</p> <p>さお、勇者の今日の仕事は、街 <var>T</var> に到達するたでに必芁な移動の回数ずオカリナを吹く回数の和の最小倀を求めるプログラムを曞くこずである。</p> <h2 id="入力">入力</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre><var>N</var> <var>M</var> <var>E</var> <var>S</var> <var>T</var> <var>R</var> <var>a_{0}</var> <var>b_{0}</var> <var>
</var> <var>a_{M&minus;1}</var> <var>b_{M&minus;1}</var> <var>a’_{0}</var> <var>b’_{0}</var> <var>c_{0}</var> <var>
</var> <var>a’_{E&minus;1}</var> <var>b’_{E&minus;1}</var> <var>c_{E&minus;1}</var> </pre> <h2 id="制玄">制玄</h2> <ul> <li>入力はすべお敎数である</li> <li><var>2 \&le; N \&le; 100</var></li> <li><var>1 \&le; M+E \&le; N(N&minus;1)</var>/<var>2</var></li> <li><var>0 \&le; E \&le; 4</var></li> <li><var>0 \&le; R \&le; 100</var></li> <li><var>0 \&le; S,T,a_i,b_i,a’_i,b’_i,c_i \&le; N&minus;1</var></li> <li><var>S ≠ T</var></li> <li><var>a_{i} ≠ b_{i}, a’_{i} ≠ b’_{i}</var></li> <li><var>a_{i}</var> ず <var>b_{i}</var>、<var>a’_{i}</var> ず <var>b’_{i}</var>の党おの組は重耇しない</li> <li><var>i ≠ j</var> なら <var>c_{i} ≠ c_{j}</var></li> </ul> <h2 id="出力">出力</h2> <p>答えを䞀行で出力せよ。どうしおも <var>T</var> ぞ到達できない堎合は <var>&minus;1</var> を出力せよ。</p> <h2 id="サンプル">サンプル</h2> <h3 id="サンプル入力1">サンプル入力1</h3> <pre>8 5 2 0 5 5 0 1 0 3 0 6 1 2 6 7 3 4 7 4 5 2 </pre> <h3 id="サンプル出力1">サンプル出力1</h3> <pre>9 </pre> <p>䟋えば以䞋のように移動すればよい。むベントを起こすたでは道(4,5), (3,4)は存圚しないこずに泚意せよ。</p> <ul> <li>街2に行くず4から5ぞ移動できるようになる</li> <li>オカリナを䜿甚し0ぞ戻る</li> <li>街7に行くず3から4ぞ移動できるようになる</li> <li>オカリナを䜿甚し0ぞ戻る</li> <li>0から5ぞたっすぐ進む</li> </ul> <div class="figure"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RUPC2015_E1" /> </div> <h3 id="サンプル入力2">サンプル入力2</h3> <pre>7 5 1 0 6 8 0 1 1 2 2 3 3 4 4 5 3 6 5 </pre> <h3 id="サンプル出力2">サンプル出力2</h3> <pre>8 </pre> <p>オカリナを1床も吹かない経路が最適である。</p> <h3 id="サンプル入力3">サンプル入力3</h3> <pre>4 1 4 1 2 3 3 1 3 2 0 0 1 3 0 3 1 0 2 2 </pre> <h3 id="サンプル出力3">サンプル出力3</h3> <pre>5 </pre> <p>街 <var>S</var> でむベントが起こるこずもある。</p>
p03258
<span class="lang-en"> <p>Score : <var>1300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a string <var>s</var> consisting of <code>a</code> and <code>b</code>. Snuke can perform the following two kinds of operation any number of times in any order:</p> <ul> <li>Choose an occurrence of <code>aa</code> as a substring, and replace it with <code>b</code>.</li> <li>Choose an occurrence of <code>bb</code> as a substring, and replace it with <code>a</code>.</li> </ul> <p>How many strings <var>s</var> can be obtained by this sequence of operations? Find the count modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |s| \leq 10^5</var></li> <li><var>s</var> consists of <code>a</code> and <code>b</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of strings <var>s</var> that can be obtained, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>aaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>Six strings can be obtained:</p> <ul> <li><code>aaaa</code></li> <li><code>aab</code></li> <li><code>aba</code></li> <li><code>baa</code></li> <li><code>bb</code></li> <li><code>a</code></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>aabb </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>Five strings can be obtained:</p> <ul> <li><code>aabb</code></li> <li><code>aaa</code></li> <li><code>bbb</code></li> <li><code>ab</code></li> <li><code>ba</code></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>ababababa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p>Snuke cannot perform any operation.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>babbabaaba </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>35 </pre></section> </div> </span>
p01265
<H1><font color="#000">Problem F:</font> Ninja Legend</H1> <p> Ninjas are professional spies in the Middle Age of Japan. They have been popular in movies and games as they have been described with extraordinary physical abilities and unrealistic abilities. </p> <p> You are absorbed in one of ninja games, <i>Ninja Legend</i>. In this game, you control in an exceptionally talented ninja named <i>Master Ninja</i> and accomplish various missions. In one of the missions, the ninja intrudes into a mansion and aims to steal as many gold pieces as possible. It is not easy to be done because there are many pitfalls to evade him. Once he falls into a pitfall, all he can do will be just to wait for being caught by the owner of this mansion. This definitely means failure of the mission. Thus, you must control the ninja with a good strategy. </p> <p> The inside of mansion is represented by a grid map as illustrated below. Master Ninja enters at and exits from the entrance. He can move in the four directions to the floor cells. He can pick up gold blocks when he moves to the cells where they are placed, but it is also allowed to pick up them in the later visit of those cells or even to give up them. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ninja1"> <p>Figure 1: Example Map</p> </center> <p> The ninja has a couple of special abilities for dealing with the pitfalls. He has two moving modes: <i>normal mode and dash mode</i>. He is initially in the normal mode. He gets into the dash mode when he moves in the same direction by two cells in a row without picking up gold blocks. He gets back to the normal mode when he changes the direction, picks up a gold block, or runs on a wall as mentioned later. He is able to jump over a pitfall, or in the dash mode he can jump over two pitfalls in his dashing direction. In addition, when he is in the dash mode, he can <i>run on a wall</i> to pass over up to four pitfalls in his dashing direction. For his running, there must be consecutive wall cells adjacent to the passing cells including the departure and arrival floor cells. Note that he gets back to the normal mode when he runs on a wall as mentioned previously. </p> <p> In the figure below, the left one shows how the ninja runs on a wall, and the right one illustrates a case in which he cannot skip over pitfalls by running on a wall. </p> <center> <table cellpadding=8 cellspacing=8> <tr> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ninja2"></td> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ninja3"></td> </tr> <tr> <td><p>Figure 2: Running on a Wall</p></td> <td><p>Figure 3: Non-consecutive Walls</p></td> </tr> </table> </center> <p> You want to know the maximum number of gold blocks the ninja can get, and the minimum cost to get those gold blocks. So you have decided to write a program for it as a programmer. Here, move of the ninja from a cell to its adjacent cell is considered to take one unit of cost. </p> <H2>Input</H2> <p> The input consists of multiple datasets. </p> <p> The first line of each dataset contains two integers <i>H</i> (3 &le; <i>H</i> &le; 60) and <i>W</i> (3 &le; <i>W</i> &le; 80). <i>H</i> and <i>W</i> indicate the height and width of the mansion. The following <i>H</i> lines represent the map of the mansion. Each of these lines consists of <i>W</i> characters. Each character is one of the following: ‘<span>%</span>’ (entrance), ‘<span>#</span>’ (wall), ‘<span>.</span>’ (floor), ‘<span>^</span>’ (pitfall), ‘<span>*</span>’ (floor with a gold block). </p> <p> You can assume that the number of gold blocks are less than or equal to 15 and every map is surrounded by wall cells. </p> <p> The end of the input indicated with a line containing two zeros. </p> <H2>Output</H2> <p> For each dataset, output the maximum number of gold blocks and the minimum cost in one line. Output two zeros instead if the ninja cannot get any gold blocks. No other characters should be contained in the output. </p> <H2>Sample Input</H2> <pre> 6 23 ####################### #%.^.^################# #^^^^^######^^^^^^^^^^# #^^^...^^^^...^^*^^..*# #^^^^^^^^^^^^^^^^^^^^^# ####################### 5 16 ################ #^^^^^^^^^^^^^^# #*..^^^.%.^^..*# #^^#####^^^^^^^# ################ 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 44 2 28 </pre>
p00927
<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 D: Space Golf </h2> <p> You surely have never heard of this new planet surface exploration scheme, as it is being carried out in a project with utmost secrecy. The scheme is expected to cut costs of conventional rovertype mobile explorers considerably, using projected-type equipment nicknamed "observation bullets". </p> <p> Bullets do not have any active mobile abilities of their own, which is the main reason of their cost-efficiency. Each of the bullets, after being shot out on a launcher given its initial velocity, makes a parabolic trajectory until it touches down. It bounces on the surface and makes another parabolic trajectory. This will be repeated virtually infinitely. </p> <p> We want each of the bullets to bounce precisely at the respective spot of interest on the planet surface, adjusting its initial velocity. A variety of sensors in the bullet can gather valuable data at this instant of bounce, and send them to the observation base. Although this may sound like a conventional target shooting practice, there are several issues that make the problem more difficult. </p> <ul> <li> There may be some obstacles between the launcher and the target spot. The obstacles stand upright and are very thin that we can ignore their widths. Once the bullet touches any of the obstacles, we cannot be sure of its trajectory thereafter. So we have to plan launches to avoid these obstacles.</li> <li> Launching the bullet almost vertically in a speed high enough, we can easily make it hit the target without touching any of the obstacles, but giving a high initial speed is energyconsuming. Energy is extremely precious in space exploration, and the initial speed of the bullet should be minimized. Making the bullet bounce a number of times may make the bullet reach the target with lower initial speed.</li> <li> The bullet should bounce, however, no more than a given number of times. Although the body of the bullet is made strong enough, some of the sensors inside may not stand repetitive shocks. The allowed numbers of bounces vary on the type of the observation bullets.</li> </ul> <p> You are summoned engineering assistance to this project to author a smart program that tells the minimum required initial speed of the bullet to accomplish the mission. </p> <p> Figure D.1 gives a sketch of a situation, roughly corresponding to the situation of the Sample Input 4 given below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_D1" width="600"><br> <p>Figure D.1. A sample situation</p> </center> <p> You can assume the following. </p> <ul> <li> The atmosphere of the planet is so thin that atmospheric resistance can be ignored.</li> <li> The planet is large enough so that its surface can be approximated to be a completely flat plane.</li> <li> The gravity acceleration can be approximated to be constant up to the highest points a bullet can reach.</li> </ul> <p> These mean that the bullets fly along a perfect parabolic trajectory. </p> <p> You can also assume the following. </p> <ul> <li> The surface of the planet and the bullets are made so hard that bounces can be approximated as elastic collisions. In other words, loss of kinetic energy on bounces can be ignored. As we can also ignore the atmospheric resistance, the velocity of a bullet immediately after a bounce is equal to the velocity immediately after its launch.</li> <li> The bullets are made compact enough to ignore their sizes.</li> <li> The launcher is also built compact enough to ignore its height.</li> </ul> <p> You, a programming genius, may not be an expert in physics. Let us review basics of rigid-body dynamics. </p> <p> We will describe here the velocity of the bullet $v$ with its horizontal and vertical components $v_x$ and $v_y$ (positive meaning upward). The initial velocity has the components $v_{ix}$ and $v_{iy}$, that is, immediately after the launch of the bullet, $v_x = v_{ix}$ and $v_y = v_{iy}$ hold. We denote the horizontal distance of the bullet from the launcher as $x$ and its altitude as $y$ at time $t$. </p> <ul> <li> The horizontal velocity component of the bullet is kept constant during its flight when atmospheric resistance is ignored. Thus the horizontal distance from the launcher is proportional to the time elapsed. \[ x = v_{ix}t \tag{1} \] </li> <li> The vertical velocity component $v_y$ is gradually decelerated by the gravity. With the gravity acceleration of $g$, the following differential equation holds during the flight. \[ \frac{dv_y}{dt} = −g \tag{2} \] Solving this with the initial conditions of $v_y = v_{iy}$ and $y = 0$ when $t = 0$, we obtain the following. \[ y = −\frac{1}{2} gt^2 + v_{iy}t \tag{3} \] \[ = −(\frac{1}{2}gt − v_{iy})t \tag{4} \] The equation (4) tells that the bullet reaches the ground again when $t = 2v_{iy}/g$. Thus, the distance of the point of the bounce from the launcher is $2v_{ix}v_{iy}/g$. In other words, to make the bullet fly the distance of $l$, the two components of the initial velocity should satisfy $2v_{ix}v_{iy} = lg$. </li> <li> Eliminating the parameter $t$ from the simultaneous equations above, we obtain the following equation that describes the parabolic trajectory of the bullet. \[ y = −(\frac{g}{2v^2_{ix}})x^2 + (\frac{v_{iy}}{v_{ix}})x \tag{5} \] </li> </ul> <p> For ease of computation, a special unit system is used in this project, according to which the gravity acceleration $g$ of the planet is exactly 1.0. </p> <h3>Input</h3> <p> The input consists of a single test case with the following format.<br> <br> $d$ $n$ $b$<br> $p_1$ $h_1$<br> $p_2$ $h_2$<br> .<br> .<br> .<br> $p_n$ $h_n$<br> <br> The first line contains three integers, $d$, $n$, and $b$. Here, $d$ is the distance from the launcher to the target spot ($1 \leq d \leq 10000$), $n$ is the number of obstacles ($1 \leq n \leq 10$), and $b$ is the maximum number of bounces allowed, not including the bounce at the target spot ($0 \leq b \leq 15$). </p> <p> Each of the following $n$ lines has two integers. In the $k$-th line, $p_k$ is the position of the $k$-th obstacle, its distance from the launcher, and $h_k$ is its height from the ground level. You can assume that $0 < p_1$, $p_k < p_{k+1}$ for $k = 1, . . . , n − 1$, and $p_n < d$. You can also assume that $1 \leq h_k \leq 10000$ for $k = 1, . . . , n$. </p> <h3>Output</h3> <p> Output the smallest possible initial speed $v_i$ that makes the bullet reach the target. The initial speed $v_i$ of the bullet is defined as follows. \[ v_i = \sqrt{v_{ix}^2 + v_{iy}^2} \] The output should not contain an error greater than 0.0001 </p> <h3>Sample Input 1</h3> <pre>100 1 0 50 100</pre> <h3>Sample Output 1</h3> <pre>14.57738</pre> <h3>Sample Input 2</h3> <pre>10 1 0 4 2</pre> <h3>Sample Output 2</h3> <pre>3.16228</pre> <h3>Sample Input 3</h3> <pre>100 4 3 20 10 30 10 40 10 50 10</pre> <h3>Sample Output 3</h3> <pre>7.78175</pre> <h3>Sample Input 4</h3> <pre>343 3 2 56 42 190 27 286 34</pre> <h3>Sample Output 4</h3> <pre>11.08710</pre>
p03608
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> towns in the State of Atcoder, connected by <var>M</var> bidirectional roads.</p> <p>The <var>i</var>-th road connects Town <var>A_i</var> and <var>B_i</var> and has a length of <var>C_i</var>.</p> <p>Joisino is visiting <var>R</var> towns in the state, <var>r_1,r_2,..,r_R</var> (not necessarily in this order).</p> <p>She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.</p> <p>If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N≀200</var></li> <li><var>1≀M≀N×(N-1)/2</var></li> <li><var>2≀R≀min(8,N)</var> (<var>min(8,N)</var> is the smaller of <var>8</var> and <var>N</var>.)</li> <li><var>r_i≠r_j (i≠j)</var></li> <li><var>1≀A_i,B_i≀N, A_i≠B_i</var></li> <li><var>(A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)</var></li> <li><var>1≀C_i≀100000</var></li> <li>Every town can be reached from every town by road.</li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>R</var> <var>r_1</var> <var>...</var> <var>r_R</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>:</var> <var>A_M</var> <var>B_M</var> <var>C_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 3 1 2 3 1 2 1 2 3 1 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>For example, if she visits the towns in the order of <var>1</var>, <var>2</var>, <var>3</var>, the distance traveled will be <var>2</var>, which is the minimum possible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 2 1 3 2 3 2 1 3 6 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p>The shortest distance between Towns <var>1</var> and <var>3</var> is <var>4</var>. Thus, whether she visits Town <var>1</var> or <var>3</var> first, the distance traveled will be <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 6 3 2 3 4 1 2 4 2 3 3 4 3 1 1 4 1 4 2 2 3 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p01635
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [['\\(','\\)']] } }); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> <h1 class="ndoc-heading1">Problem B: Time Complexity</h1> <p class="ndoc-top">ICPC World Finals 1日目</p> <p class="ndoc-top">プログラミングコンテストではプログラムの実行時間を把握する事が重芁だ。 実行時間の芋積もりを誀り、 時間制限をオヌバヌしおしたうコヌドを曞いおしたうず、 そのぶん時間をロスしおしたう。 ICPCのようにコンピュヌタが1台しか䜿えないチヌム戊ではなおさらである。</p> <p class="ndoc-top">そこで、ICPC World Finalsを前に控えたティヌ氏はプログラムの実行時間を暗算で求める蚓緎を始めるこずにした。 「logは定数のようなもの」なので、たずは倚項匏に取り組むずしよう。</p> <h2 class="ndoc-heading2">問題</h2> <p class="ndoc-top">ある問題の答えを蚈算するプログラムず、それを実行するコンピュヌタがある。 問題の入力を衚す正敎数\(n\)、 入力\(n\)に応じおプログラム䞭で実行される呜什の数を衚す倚項匏\(f(n)\)、 コンピュヌタの1呜什の実行時間\(T\)[ナノ秒]=\( 10^{-9} \)[秒]が䞎えられる。 倚項匏\(f(n)\)の回数だけ呜什を実行した時のプログラムの総実行時間が1秒「以䞋」であるかを刀定し、 1秒「以䞋」であるならば総実行時間を求めよ。</p> <h2 class="ndoc-heading2">入力</h2> <pre> n T f(n) </pre> <p>1行目に 問題の入力を衚す正敎数\(n\)ず 1呜什の実行時間[ナノ秒]を衚す敎数\(T\)が空癜区切りで䞎えられる。 2行目に実行される呜什の数を衚す倚項匏\(f(n)\)が䞎えられる。</p> <p class="ndoc-top">倚項匏\( f(n) \)は以䞋のBNFで衚される。</p> <pre> &lt;poly&gt; ::= &lt;poly&gt; "+" &lt;mono&gt; | &lt;mono&gt; &lt;mono&gt; ::= "n^" &lt;num&gt; &lt;num&gt; ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" </pre> <p class="ndoc-top">ここで各単項匏n^kは、\(n\)の\(k\)乗を衚す。</p> <h2 class="ndoc-heading2">出力</h2> <p class="ndoc-top"> プログラムの総実行時間が1秒「以䞋」である堎合には総実行時間を[ナノ秒]単䜍で、1秒を「超過」する堎合には"TLE"を1行に出力せよ。</p> <h2 class="ndoc-heading2">制玄</h2> <p class="ndoc-top"></p> <ul class="ndoc-indent"> <li>\( 1 \leq n \leq 10^{9}(= 1000000000) \)</li> <li>\( 1 \leq T \leq 10^{9}(= 1000000000) \)</li> <li>倚項匏\( f(n) \)の次数は0以䞊9以䞋、単項匏の数は1以䞊10以䞋</li> </ul> <h2 class="ndoc-heading2">入出力䟋</h2> <h3 class="ndoc-heading3">入力1</h3> <pre> 100 100 n^1+n^2+n^3 </pre> <h3 class="ndoc-heading3">出力1</h3> <pre> 101010000 </pre> <p>総実行時間は\( (100^{1} + 100^{2} + 100^{3}) \times 100 \)[ナノ秒]である。</p> <h3 class="ndoc-heading3">入力2</h3> <pre> 1000 1 n^3+n^0 </pre> <h3 class="ndoc-heading3">出力2</h3> <pre> TLE </pre> <p>総実行時間は\( 1000^{3} + 1000^{0} = 10^{9}+1 \)[ナノ秒]であり、1[秒]を超えおしたう。</p> <h3 class="ndoc-heading3">入力3</h3> <pre> 100000000 100000000 n^3 </pre> <h3 class="ndoc-heading3">出力3</h3> <pre> TLE </pre> <p>総実行時間は\( (10^{8})^{3} \times 10^{8} = 10^{32} \)[ナノ秒]である。</p>