question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00365
<H1>Age Difference</H1> <!-- Difference in ages--> <p> A trick of fate caused Hatsumi and Taku to come to know each other. To keep the encounter in memory, they decided to calculate the difference between their ages. But the difference in ages varies depending on the day it is calculated. While trying again and again, they came to notice that the difference of their ages will hit a maximum value even though the months move on forever. </p> <p> Given the birthdays for the two, make a program to report the maximum difference between their ages. The age increases by one at the moment the birthday begins. If the birthday coincides with the 29<sup>th</sup> of February in a leap year, the age increases at the moment the 1<sup>st</sup> of March arrives in non-leap years. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>y_1</var> <var>m_1</var> <var>d_1</var> <var>y_2</var> <var>m_2</var> <var>d_2</var> </pre> <p> The first and second lines provide Hatsumi’s and Taku’s birthdays respectively in year <var>y_i</var> (1 &le; <var>y_i</var> &le; 3000), month <var>m_i</var> (1 &le; <var>m_i</var> &le; 12), and day <var>d_i</var> (1 &le; <var>d_i</var> &le; D<sub>max</sub>) format. Where <var>D<sub>max</sub></var> is given as follows: </p> <ul> <li> 28 when February in a non-leap year</li> <li> 29 when February in a leap-year</li> <li> 30 in April, June, September, and November</li> <li> 31 otherwise.</li> </ul> <p> It is a leap year if the year represented as a four-digit number is divisible by 4. Note, however, that it is a non-leap year if divisible by 100, and a leap year if divisible by 400. </p> <h2>Output</h2> <p> Output the maximum difference between their ages. </p> <h2>Sample Input 1</h2> <pre> 1999 9 9 2001 11 3 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <p> In this example, the difference of ages between them in 2002 and subsequent years is 3 on the 1<sup>st</sup> of October, but 2 on the 1<sup>st</sup> of December. </p> <h2>Sample Input 2</h2> <pre> 2008 2 29 2015 3 1 </pre> <h2>Sample Output 2</h2> <pre> 8 </pre> <p> In this example, the difference of ages will become 8 on the 29<sup>th</sup> of February in and later years than 2016. </p>
p01124
<!--<h2>Problem H</h2>--> <!-- begin en only --> <h3>Addition on Convex Polygons</h3> <!-- end en only --> <!-- begin en only --> <p> Mr. Convexman likes convex polygons very much. During his study on convex polygons, he has come up with the following elegant addition on convex polygons.</p> <!-- end en only --> <!-- begin en only --> <p> The sum of two points in the <i>xy</i>-plane, (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) and (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) is defined as (<i>x</i><sub>1</sub> + <i>x</i><sub>2</sub>, <i>y</i><sub>1</sub> + <i>y</i><sub>2</sub>). A polygon is treated as the set of all the points on its boundary and in its inside. Here, the sum of two polygons <i>S</i><sub>1</sub> and <i>S</i><sub>2</sub>, <i>S</i><sub>1</sub> + <i>S</i><sub>2</sub>, is defined as the set of all the points <i>v</i><sub>1</sub> + <i>v</i><sub>2</sub> satisfying <i>v</i><sub>1</sub> &isin; <i>S</i><sub>1</sub> and <i>v</i><sub>2</sub> &isin; <i>S</i><sub>2</sub>. Sums of two convex polygons, thus defined, are always convex polygons! The multiplication of a non-negative integer and a polygon is defined inductively by 0<i>S</i> = {(0, 0)} and, for a positive integer <i>k</i>, <i>kS</i> = (<i>k</i> - 1)<i>S</i> + <i>S</i>. In this problem, line segments and points are also considered as convex polygons. </p> <!-- end en only --> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_H.png" width="80%"></center> <!-- begin en only --> <p> Mr. Convexman made many convex polygons based on two convex polygons <i>P</i> and <i>Q</i> to study properties of the addition, but one day, he threw away by mistake the piece of paper on which he had written down the vertex positions of the two polygons and the calculation process. What remains at hand are only the vertex positions of two convex polygons <i>R</i> and <i>S</i> that are represented as linear combinations of <i>P</i> and <i>Q</i> with non-negative integer coefficients: <blockquote> <i>R</i> = <i>aP</i> + <i>bQ</i>, and<br> <i>S</i> = <i>cP</i> + <i>dQ</i>. </blockquote> Fortunately, he remembers that the coordinates of all vertices of <i>P</i> and <i>Q</i> are integers and the coefficients <i>a</i>, <i>b</i>, <i>c</i> and <i>d</i> satisfy <i>ad</i> - <i>bc</i> = 1. </p> <!-- end en only --> <!-- begin en only --> <p> Mr. Convexman has requested you, a programmer and his friend, to make a program to recover <i>P</i> and <i>Q</i> from <i>R</i> and <i>S</i>, that is, he wants you to, for given convex polygons <i>R</i> and <i>S</i>, compute non-negative integers <i>a</i>, <i>b</i>, <i>c</i>, <i>d</i> (<i>ad</i> - <i>bc</i> = 1) and two convex polygons <i>P</i> and <i>Q</i> with vertices on integer points satisfying the above equation. The equation may have many solutions. Make a program to compute the minimum possible sum of the areas of <i>P</i> and <i>Q</i> satisfying the equation. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of at most 40 datasets, each in the following format. </p> <!-- end en only --> <p> <blockquote> <i>n</i> <i>m</i> <br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br> ... <br> <i>x<sub>n</sub></i> <i>y<sub>n</sub></i> <br> <i>x'</i><sub>1</sub> <i>y'</i><sub>1</sub> <br> ... <br> <i>x'<sub>m</sub></i> <i>y'<sub>m</sub></i> <br> </blockquote> </p> <!-- begin en only --> <p> <i>n</i> is the number of vertices of the convex polygon <i>R</i>, and <i>m</i> is that of <i>S</i>. <i>n</i> and <i>m</i> are integers and satisfy 3 &le; <i>n</i> &le; 1000 and 3 &le; <i>m</i> &le; 1000. (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) represents the coordinates of the <i>i</i>-th vertex of the convex polygon <i>R</i> and (<i>x'<sub>i</sub></i>, <i>y'<sub>i</sub></i>) represents that of <i>S</i>. <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>x'<sub>i</sub></i> and <i>y'<sub>i</sub></i> are integers between &minus;10<sup>6</sup> and 10<sup>6</sup>, inclusive. The vertices of each convex polygon are given in counterclockwise order. Three different vertices of one convex polygon do not lie on a single line. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing two zeros. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing an integer representing the double of the sum of the areas of <i>P</i> and <i>Q</i>. Note that the areas are always integers when doubled because the coordinates of each vertex of <i>P</i> and <i>Q</i> are integers. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 5 3 0 0 2 0 2 1 1 2 0 2 0 0 1 0 0 1 4 4 0 0 5 0 5 5 0 5 0 0 2 0 2 2 0 2 3 3 0 0 1 0 0 1 0 1 0 0 1 1 3 3 0 0 1 0 1 1 0 0 1 0 1 1 4 4 0 0 2 0 2 2 0 2 0 0 1 0 1 2 0 2 4 4 0 0 3 0 3 1 0 1 0 0 1 0 1 1 0 1 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 3 2 2 1 0 2 </pre>
p03119
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke participated in a magic show.</p> <p>A magician prepared <var>N</var> identical-looking boxes. He put a treasure in one of the boxes, closed the boxes, shuffled them, and numbered them <var>1</var> through <var>N</var>.</p> <p>Since the boxes are shuffled, now Snuke has no idea which box contains the treasure. Snuke wins the game if he opens a box containing the treasure. You may think that if Snuke opens all boxes at once, he can always win the game. However, there are some tricks:</p> <ul> <li>Snuke must open the boxes one by one. After he opens a box and checks the content of the box, he must close the box before opening the next box.</li> <li>He is only allowed to open Box <var>i</var> at most <var>a_i</var> times.</li> <li>The magician may secretly move the treasure from a closed box to another closed box, using some magic trick. For simplicity, assume that the magician never moves the treasure while Snuke is opening some box. However, he can move it at any other time (before Snuke opens the first box, or between he closes some box and opens the next box).</li> <li>The magician can perform the magic trick at most <var>K</var> times.</li> </ul> <p>Can Snuke always win the game, regardless of the initial position of the treasure and the movements of the magician?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 50</var></li> <li><var>1 \leq K \leq 50</var></li> <li><var>1 \leq a_i \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>a_1</var> <var>a_2</var> <var>\cdots</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the answer is no, print a single <code>-1</code>.</p> <p>Otherwise, print one possible move of Snuke in the following format:</p> <pre><var>Q</var> <var>x_1</var> <var>x_2</var> <var>\cdots</var> <var>x_Q</var> </pre> <p>It means that he opens boxes <var>x_1, x_2, \cdots, x_Q</var> in this order.</p> <p>In case there are multiple possible solutions, you can output any.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 1 1 2 1 2 2 1 </pre> <p>If Snuke opens the boxes <var>7</var> times in the order <var>1 \rightarrow 1 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 2 \rightarrow 1</var>, he can always find the treasure regardless of its initial position and the movements of the magician.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 50 5 10 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre></section> </div> </span>
p01574
<H1><font color="#000">Problem D: </font> Dial Key</H1> <p> You are a secret agent from the Intelligence Center of Peacemaking Committee. You've just sneaked into a secret laboratory of an evil company, Automated Crime Machines. </p> <p> Your mission is to get a confidential document kept in the laboratory. To reach the document, you need to unlock the door to the safe where it is kept. You have to unlock the door in a correct way and with a great care; otherwise an alarm would ring and you would be caught by the secret police. </p> <p> The lock has a circular dial with <i>N</i> lights around it and a hand pointing to one of them. The lock also has <i>M</i> buttons to control the hand. Each button has a number <i>L<sub>i</sub></i> printed on it. </p> <p> Initially, all the lights around the dial are turned off. When the <i>i</i>-th button is pressed, the hand revolves clockwise by <i>L<sub>i</sub></i> lights, and the pointed light is turned on. You are allowed to press the buttons exactly <i>N</i> times. The lock opens only when you make all the lights turned on. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_dialKey"> </center> <p> For example, in the case with <i>N</i> = 6, <i>M</i> = 2, <i>L</i><sub>1</sub> = 2 and <i>L</i><sub>2</sub> = 5, you can unlock the door by pressing buttons 2, 2, 2, 5, 2 and 2 in this order. </p> <p> There are a number of doors in the laboratory, and some of them don’t seem to be unlockable. Figure out which lock can be opened, given the values <i>N</i>, <i>M</i>, and <i>L<sub>i</sub></i>'s. </p> <H2>Input</H2> <p> The input starts with a line containing two integers, which represent <i>N</i> and <i>M</i> respectively. <i>M</i> lines follow, each of which contains an integer representing <i>L<sub>i</sub></i>. </p> <p> It is guaranteed that 1 &le; <i>N</i> &le; 10<sup>9</sup>, 1 &le; <i>M</i> &le; 10<sup>5</sup>, and 1 &le; <i>L<sub>i</sub></i> &le; <i>N</i> for each <i>i</i> = 1, 2, ... <i>N</i>. </p> <H2>Output</H2> <p> Output a line with "Yes" (without quotes) if the lock can be opened, and "No" otherwise. </p> <H2>Sample Input 1</H2> <pre> 6 2 2 5 </pre> <H2>Output for the Sample Input 1</H2> <pre> Yes </pre> <br/> <H2>Sample Input 2</H2> <pre> 3 1 1 </pre> <H2>Output for the Sample Input 2</H2> <pre> Yes </pre> <br/> <H2>Sample Input 3</H2> <pre> 4 2 2 4 </pre> <H2>Output for the Sample Input 3</H2> <pre> No </pre>
p03549
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is <code>YES</code> or <code>NO</code>.</p> <p>When he checked the detailed status of the submission, there were <var>N</var> test cases in the problem, and the code received TLE in <var>M</var> of those cases.</p> <p>Then, he rewrote the code to correctly solve each of those <var>M</var> cases with <var>1/2</var> probability in <var>1900</var> milliseconds, and correctly solve each of the other <var>N-M</var> cases without fail in <var>100</var> milliseconds.</p> <p>Now, he goes through the following process:</p> <ul> <li>Submit the code.</li> <li>Wait until the code finishes execution on all the cases.</li> <li>If the code fails to correctly solve some of the <var>M</var> cases, submit it again.</li> <li>Repeat until the code correctly solve all the cases in one submission.</li> </ul> <p>Let the expected value of the total execution time of the code be <var>X</var> milliseconds. Print <var>X</var> (as an integer).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq M \leq {\rm min}(N, 5)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>X</var>, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, <var>X</var> is an integer not exceeding <var>10^9</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3800 </pre> <p>In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with <var>1/2</var> probability in <var>1900</var> milliseconds.</p> <p>The code will succeed in one attempt with <var>1/2</var> probability, in two attempts with <var>1/4</var> probability, and in three attempts with <var>1/8</var> probability, and so on.</p> <p>Thus, the answer is <var>1900 \times 1/2 + (2 \times 1900) \times 1/4 + (3 \times 1900) \times 1/8 + ... = 3800</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>18400 </pre> <p>The code will take <var>1900</var> milliseconds in each of the <var>2</var> cases, and <var>100</var> milliseconds in each of the <var>10-2=8</var> cases. The probability of the code correctly solving all the cases is <var>1/2 \times 1/2 = 1/4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>608000 </pre></section> </div> </span>
p01061
<h1>Community Integration</h1> <!-- <p>安倍拟菜々「えぇっ生たれ故郷のあの村、○○垂に合䜵されおたんですか 20幎前に」</p> --> <h2>Problem</h2> <p> <var>N</var>個の村がある。それぞれの村には1から<var>N</var>たでの番号が぀いおいる。昚今の合䜵ブヌムにより、いく぀かの村が合䜵されるこずになった。合䜵された2぀以䞊の村は新しい1぀の垂ずなり、どの村ずも合䜵されない村は村のたたである。 </p> <p> あなたは、ある2぀の村が合䜵埌に同じ垂になる、ずいう情報を耇数䞎えられる。その情報の組み合わせによっお、3぀以䞊の村が1぀の垂になるこずもありうる。 </p> <p> 合䜵埌に同じ垂になる村同士の情報が䞎えられたずき、合䜵埌の垂の数ず村の数の差の絶察倀を出力せよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>M</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> ... <var>a<sub>i</sub></var> <var>b<sub>i</sub></var> ... <var>a<sub>M</sub></var> <var>b<sub>M</sub></var> </pre> <p> 1行目に村の数<var>N</var>ず合䜵に぀いおの情報の数<var>M</var>が空癜区切りで䞎えられる。<br> 2行目から<var>M</var>+1行目に、合䜵に぀いおの情報を衚す぀の敎数<var>a<sub>i</sub></var>ず<var>b<sub>i</sub></var>が空癜区切りで䞎えらる。各情報は<var>a<sub>i</sub></var>番目の村ず<var>b<sub>i</sub></var>番目の村が合䜵埌に同じ垂になるこずを瀺す。ただし、<var>a<sub>i</sub></var>=<var>b<sub>i</sub></var>を満たすような入力は䞎えられない。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>N</var> &le; 1,000</li> <li>0 &le; <var>M</var> &le; 100</li> <li>1 &le; <var>a<sub>i</sub></var> &le; <var>N</var></li> <li>1 &le; <var>b<sub>i</sub></var> &le; <var>N</var></li> </ul> <h2>Output</h2> <p> 村の数ず垂の数の差の絶察倀を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 1 1 2 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <h2>Sample Input 2</h2> <pre> 4 2 1 4 2 3 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> <h2>Sample Input 3</h2> <pre> 5 0 </pre> <h2>Sample Output 3</h2> <pre> 5 </pre> <h2>Sample Input 4</h2> <pre> 3 3 1 2 2 3 3 1 </pre> <h2>Sample Output 4</h2> <pre> 1 </pre> <p> このケヌスではすべおの村が1぀の垂に合䜵されるこずを衚し、その垂の䞭で合䜵される2぀の村を぀なぐ぀なぎ方の党通りが入力ずしお䞎えられおいる。 </p> <h2>Sample Input 5</h2> <pre> 3 2 1 2 2 3 </pre> <h2>Sample Output 5</h2> <pre> 1 </pre> <p> このケヌスでは合䜵される3぀の村を぀なぐ぀なぎ方の党通りが入力ずしお䞎えられおいるわけではないが、぀ながっおいる村をたどればすべおの村にたどり着くこずができるので、すべおの村が䞀぀の垂に合䜵される。 </p> <h2>Sample Input 6</h2> <pre> 5 4 1 2 2 3 3 4 4 5 </pre> <h2>Sample Output 6</h2> <pre> 1 </pre> <h2>Sample Input 7</h2> <pre> 10 5 3 4 1 2 9 6 2 6 2 9 </pre> <h2>Sample Output 7</h2> <pre> 2 </pre>
p01431
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script> <h2>問題文</h2> <p> 萜曞きの魔女 ALBERTINE は <var>W</var> 列 <var>H</var> 行の正方圢のセルからなる長方圢の結界の入り口に萜曞きをしおいるこの䞖界では萜曞きは必ずセルを癜色か黒色で塗るこずによっお成り立぀ </p> <p> すでに䜿い魔 ANJA の手によっお萜曞きの䞀郚が描かれおいるのだが萜曞きの魔女は残りすべおのセルを塗り萜曞きを完成させたい萜曞きの魔女にはあるこだわりがあるそのこだわりずは次のようなものである </p> <ul> <li><var>2</var> ぀の異なるセルが蟺を共有するずき<var>2</var> ぀のセルは隣接しおいるず呌ぶこずにする完成された萜曞きにおいおは任意の <var>2</var> ぀の黒いセルに぀いお片方からもう片方ぞの隣接した黒いセルをたどるパスがちょうど <var>1</var> ぀だけ存圚しおいなければならない</li> <li>どの <var>2</var> ぀の癜色のセルも隣接しおはならない</li> </ul> <p> たた萜曞きの魔女は黒色が奜きなのでこだわりを満たした状態でなおか぀最も黒色のセルが倚い萜曞きを完成させたい果たしお萜曞きの魔女は最倧で䜕個のセルが黒色に塗られたこだわりの萜曞きを描くこずができるだろうか </p> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる </p> <pre><var> H\ W\\ c_{11} c_{12} ... c_{1W}\\ c_{21} c_{22} ... c_{2W}\\ ...\\ c_{H1} c_{H2} ... c_{HW}\\ </var></pre> <p> <var>H</var> は結界の入り口の瞊幅<var>W</var> は結界の入り口の暪幅を衚す <p> <var>c_{ij}</var> は各セルの状態を衚す文字であり䞊から <var>i</var> 行目巊から <var>j</var> 列目のセルの状態を衚すセルに黒色が塗られおいる堎合は <var>c_{ij}</var> は <code>'#'</code> ずなり癜色が塗られおいる堎合は <code>'.'</code>ただ色が塗られおいない堎合はそうでない堎合は <code>'?'</code> ずなる </p> <h2>出力圢匏</h2> <p> 魔女のこだわりを満たした状態でずりうる黒色のセルの個数の最倧倀を <var>1</var> 行で出力せよ </p> <p> もしどのように塗っおも魔女のこだわりを満たすように出来ない堎合<code>-1</code> ず出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; H &le; 11</var></li> <li><var>1 &le; W &le; 11</var></li> <li><var>c_{ij}</var> は <code>'#'</code>, <code>'.'</code>, <code>'?'</code> のいずれかである</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre>3 4 .##. #??# .#?#</pre> <h3>出力䟋1</h3> <pre>8</pre> <h3>入力䟋 2</h3> <pre>5 5 ##?## #???# ????? #???# ##?##</pre> <h3>出力䟋 2</h3> <pre>19</pre> <h3>入力䟋 3</h3> <pre>9 2 ## .. ?? ?? ?? ?? ?? ?? ??</pre> <h3>出力䟋 3</h3> <pre>-1</pre> <h3>入力䟋 4</h3> <pre>7 9 ??#####?? ?#?????#? ?#?????#? ?#??#??#? ?#???#?#? ??#####?? ???????#?</pre> <h3>出力䟋 4</h3> <pre>44</pre> <h3>入力䟋 5</h3> <pre>11 11 ??????????? ???####???? ???#???#??? ???#???#??? ???#???#??? ???####???? ???#???#??? ???#???#??? ???#???#??? ???####???? ???????????</pre> <h3>出力䟋 5</h3> <pre>86</pre> <hr> <address>Problem Setter: Flat35</address>
p00670
<h1>Problem B: Spellcasters</h1> <p> n 人の魔法䜿いがいる。圌らには 1 から n たでの番号があり、i 番目の魔法䜿いは魔力 r<sub>i</sub> ( 1 &le; i &le; n ) を持っおいる。いた圌らは匷力な魔法䜿いず察峙しおおり、その敵の魔力は S である。n 人の魔法䜿いは協力しお戊うのが埗意で、特に 2 人で協力しお戊うこずを奜む。2 人の魔法䜿いが協力した堎合、魔力は単玔にその和ずなり、匷力な魔法などを駆䜿しおある皋床匷い敵にも勝おるようになる。あなたの仕事は魔力 S を持぀敵に察しお勝぀こずができる魔法䜿いのペア (i, j) ( i &ne; j か぀ 1 &le; i &le; n か぀ 1 &le; j &le; n ) の総数を出力するこずである。ただし (i, j) ず (j, i) は同じ組ずしお数える。䞀方の魔力が他方の魔力よりも倧きいずき、倧きい魔力を持っおいる偎が勝぀。等しい堎合は盞打ちで勝ったこずにならない。 </p> <h2>Input</h2> <p> 入力は耇数のテストケヌスからなる。 各テストケヌスは以䞋の圢匏に埓う。 </p> <pre> n S r<sub>1</sub> r<sub>2</sub> 
 r<sub>n</sub> </pre> <p> 各倉数の意味は問題文䞭の通りである。 入力の終わりは、ふた぀の0が䞀文字の空癜で区切られる䞀行で瀺される。 </p> <h2>Constraints</h2> <ul> <li>入力はすべお敎数</li> <li>1 &le; n &le; 20,000</li> <li>1 &le; r<sub>i</sub> &le; 100 ( 1 &le; i &le; n )</li> <li>1 &le; S &le; 100</li> <li>テストケヌスの数は 100 を超えない。</li> </ul> <h2>Output</h2> <p> 条件を満たす組 (i, j) (i &ne; j) の総数を各ケヌスに付き 1 行に出力せよ。 </p> <h2>Sample Input</h2> <pre> 3 7 1 3 10 0 0 </pre> <h2>Sample Output</h2> <pre> 2 </pre>
p01962
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <H1> Coin Slider </H1> <p> You are playing a coin puzzle. The rule of this puzzle is as follows: </p> <p> There are $N$ coins on a table. The $i$-th coin is a circle with $r_i$ radius, and its center is initially placed at ($sx_i, sy_i$). Each coin also has a target position: you should move the $i$-th coin so that its center is at ($tx_i, ty_i$). You can move coins one by one and can move each coin at most once. When you move a coin, it must move from its initial position to its target position along the straight line. In addition, coins cannot collide with each other, including in the middle of moves. </p> <p> The score of the puzzle is the number of the coins you move from their initial position to their target position. Your task is to write a program that determines the maximum score for a given puzzle instance. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $N$ $r_1$ $sx_1$ $sy_1$ $tx_1$ $ty_1$ : $r_N$ $sx_N$ $sy_N$ $tx_1$ $ty_N$ </pre> <p> The first line contains an integer $N$ ($1 \leq N \leq 16$), which is the number of coins used in the puzzle. The $i$-th line of the following $N$ lines consists of five integers: $r_i, sx_i, sy_i, tx_i,$ and $ty_i$ ($1 \leq r_i \leq 1,000, -1,000 \leq sx_i, sy_i, tx_i, ty_i \leq 1,000, (sx_i, sy_i) \ne (tx_i, ty_i)$). They describe the information of the $i$-th coin: $r_i$ is the radius of the $i$-th coin, $(sx_i, sy_i)$ is the initial position of the $i$-th coin, and $(tx_i, ty_i)$ is the target position of the $i$-th coin. </p> <p> You can assume that the coins do not contact or are not overlapped with each other at the initial positions. You can also assume that the maximum score does not change even if the radius of each coin changes by $10^{-5}$. </p> <H2>Output</H2> <p> Print the maximum score of the given puzzle instance in a line. </p> <H2>Sample Input 1</H2> <pre> 3 2 0 0 1 0 2 0 5 1 5 4 1 -10 -5 10 </pre> <H2>Output for Sample Input 1</H2> <pre> 2 </pre> <H2>Sample Input 2</H2> <pre> 3 1 0 0 5 0 1 0 5 0 0 1 5 5 0 5 </pre> <H2>Output for Sample Input 2</H2> <pre> 3 </pre> <H2>Sample Input 3</H2> <pre> 4 1 0 0 5 0 1 0 5 0 0 1 5 5 0 5 1 5 0 0 0 </pre> <H2>Output for Sample Input 3</H2> <pre> 0 </pre> <p> In the first example, the third coin cannot move because it is disturbed by the other two coins. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2017_coinSlider" width="640"> </center>
p00220
<H1>博士が愛した進数</H1> <p> 「君の靎のサむズはいく぀かね」 <br/> <br/> 初察面の私に、いきなり博士は尋ねたした。<br/> <br/> 「 23.5 です」<br/> 「ほお、実にきりのいい数字だ。2 の 4 乗に 2 の 2 乗ず 2 の 1 乗ず 2 の 0 乗ず 2 の -1 乗を 加えた数だ」<br/> <br/> 続けお博士は尋ねたした。<br/> <br/> 「君、身長はいく぀かね」<br/> 「はい、158.1 です」<br/> <br/> 博士は腕組みをしお目を閉じたした。しばらくの沈黙の埌、口を開きたした。<br/> <br/> 「ナァ~」<br/> <br/> その埌䞀緒に過ごした時間の䞭で、博士の行動がだんだん理解できるようになりたした。 </p> <p> たず、 私が博士の求めに応じお実数を蚀いたす。実数が敎数郚 8 桁以内で小数郚 4 桁以内の 2 進数で衚される堎合、博士は 2 進数ぞの倉換結果を満足げに語りたす。そうでない堎合、悲しげに「ナァ~」 ず鳎きたす。これは、私が負の実数を蚀うたで繰り返されるのです。 </p> <p> さお、博士は幎霢ずずもにだんだんに長い蚈算が難しくなっおきたした。そこで、みなさんが博士に代わっお、実数を入力し 2 進数に倉換・出力するプログラムを䜜っおあげおください。ただし、2 進衚珟が制限桁数 (敎数郚 8 桁以内 + 小数郚 4 桁以内) に収たらない堎合は、NA (半角英字) を出力しおください。入力される実数は敎数郚 8 桁以内、小数郚 4 桁以内に収たるものずし、出力する 2 進衚珟は敎数郚 8 桁、小数郚 4 桁で出力しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりは負の実数ひず぀の行で瀺されたす。 各デヌタセットずしお぀の実数 <var>n</var> が行に䞎えられたす。 </p> <p> デヌタセットの数は 1200 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに 2 進数ぞの倉換結果を出力したす。 </p> <H2>Sample Input</H2> <pre> 23.5 158.1 -1.0 </pre> <H2>Output for the Sample Input</H2> <pre> 00010111.1000 NA </pre>
p00037
<H1>栌子䞊の経路</H1> <p> 䞊から芋るず図 1 のような圢の栌子状の広堎がありたす。この栌子の各蟺に「壁」があるかないかを 0 ず 1 の䞊びで衚したす。点 A に立っお壁に右手を぀き、壁に右手を぀いたたた、矢印の方向に歩き続けお再び点 A に戻っおくるたでの経路を出力するプログラムを䜜成しおください。 </p> <center> <table> <tr><th> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pathOnGrid1"> </t></tr> </table> <table> <tr><th> 図1 </th></tr> </table> </center> <br/> <H2>Input</H2> <p> 入力は行からなり、以䞋の図 2 に瀺すように、壁がある堎合を 1、ない堎合を 0 ずしお、以䞋の圢匏で䞎えられたす。 <br><br> 1 行目は䞀番䞊の暪線の壁の有無を巊から 0 ず 1 で衚した文字列<br> 2 行目はその䞋の瞊線の壁の有無を巊から0 ず1 で衚した文字列<br> 3 行目は䞊から2 本目の暪線の壁の有無を巊から0 ず1 で衚した文字列<br> ...<br> 9 行目は䞀番䞋の暪線の壁の有無を巊から0 ず1 で衚した文字列<br> </p> <center> <table> <tr><th> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pathOnGrid2"> </th></tr> <tr><th> 図2 (壁あるずころを倪線で衚しおいたす)  (察応する数字のならび) </th></tr> </table> </center> <br/> <p> ただし、図の倪線に瀺すように、点 A から右に 1 区画分は必ず壁があるものずしたす。すなわち、1 行目の 1 文字目は垞に 1 です。 </p> <H2>Output</H2> <p> 「図の巊方向に䞀区画分進む」を '<span>L</span>'、「図の右方向に䞀区画分進む」を '<span>R</span>'、「図の䞊方向に䞀区画分進む」を '<span>U</span>'、「図の䞋方向に䞀区画分進む」を '<span>D</span>' で衚わし、進む順に '<span>L</span>', '<span>R</span>', '<span>U</span>', '<span>D</span>' を行に䞊べお出力したす。 </p> <H2>Sample Input</H2> <pre> 1111 00001 0110 01011 0010 01111 0010 01001 0111 </pre> <H2>Output for the Sample Input</H2> <pre> RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL </pre>
p00467
<H1>すごろく</H2> <h2> 問題</h2> <p> JOI さんは䞀人ですごろく遊びをしおいる このすごろくには䞀盎線䞊に N 個のマスがありそれぞれ移動の指瀺が曞かれおいるスタヌト地点は 1 マス目でありゎヌルはNマス目である JOI さんはゎヌルするたで次を繰り返す </p> <p> サむコロを振っお出た目の数だけ珟圚のマスから進みそのマスの指瀺に埓う 指瀺に埓っお移動した先のマスの指瀺には埓わない </p> <p> ちょうど N マス目に止たる時だけでなく移動先が N マス目を超える堎合もゎヌルずなる </p> <p> すごろくの盀面ず M 回分のサむコロの出る目が䞎えられたずきサむコロを䜕回振ったずころでゎヌルするかを出力するプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 各デヌタセットは 1+N+M 行からなる </p> <p> 入力の 1 行目には぀の敎数 N,M 2 &le; N &le; 1000 1 &le; M &le; 1000 が空癜を区切りずしお曞かれおいる N はすごろくのマス目の個数を M は䞎えられるサむコロの目の個数を衚す </p> <p> 続く N 行には -999 以䞊 999 以䞋の敎数が぀ず぀曞かれおいる 1+i 行目  1 &le; i &le; N  の敎数はすごろくの i 番目のマスの指瀺を衚す 曞かれおいる敎数を X ずする X=0 のずきは「䜕もしない」を X>0 のずきは「 X マス進む」をX<0 のずきは「 |X| マス戻る」の指瀺を衚すただし |X| は X の絶察倀を衚す </p> <p> 続く M 行には 1 以䞊 6 以䞋の敎数が぀ず぀曞かれおおり 1+N+j 行目  1 &le; j &le; M の数は j 回目に出るサむコロの目を衚す </p> <p> ただし 2 行目ず 1+N 行目の数は必ず 0 である 1 マス目よりも前のマスに移動させる指瀺が曞かれおいるマスはない たたどの採点甚入力デヌタにおいおもサむコロを振る回数が M 以䞋でゎヌルできる </p> <p> N, M がずもに 0 のずき入力の終了を瀺す.デヌタセットの数は 5 を超えない </p> <h2> 出力</h2> <p> デヌタセットごずにサむコロを䜕回振ったずころでゎヌルするかを衚す敎数を 1 行に出力する </p> <h2> 入出力䟋</h2> <h3>入力䟋</h3> <pre> 10 5 0 0 5 6 -3 8 1 8 -4 0 1 3 5 1 5 10 10 0 -1 -1 4 4 -5 0 1 -6 0 1 5 2 4 6 5 5 4 1 6 0 0 </pre> <h3>出力䟋</h3> <pre> 5 6 </pre> <p>次の図は1぀目の入力䟋を衚す<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2010-yo-t2-fig01"> </p> <p>次の図は2぀目の入力䟋を衚す<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2010-yo-t2-fig02"> </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00934
<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 K: $L_{\infty}$ Jumps </h2> <p> Given two points $(p, q)$ and $(p', q')$ in the XY-plane, the $L_{\infty}$ <i>distance</i> between them is defined as $max(|p − p'|, |q − q'|)$. In this problem, you are given four integers $n$, $d$, $s$, $t$. Suppose that you are initially standing at point $(0, 0)$ and you need to move to point $(s, t)$. For this purpose, you perform jumps exactly $n$ times. In each jump, you must move exactly $d$ in the $L_{\infty}$ distance measure. In addition, the point you reach by a jump must be a lattice point in the XY-plane. That is, when you are standing at point $(p, q)$, you can move to a new point $(p', q')$ by a single jump if $p'$ and $q'$ are integers and $max(|p − p'|, |q − q'|) = d$ holds. </p> <p> Note that you cannot stop jumping even if you reach the destination point $(s, t)$ before you perform the jumps $n$ times. </p> <p> To make the problem more interesting, suppose that some cost occurs for each jump. You are given $2n$ additional integers $x_1$, $y_1$, $x_2$, $y_2$, . . . , $x_n$, $y_n$ such that $max(|x_i|, |y_i|) = d$ holds for each $1 \leq i \leq n$. The cost of the $i$-th (1-indexed) jump is defined as follows: Let $(p, q)$ be a point at which you are standing before the $i$-th jump. Consider a set of lattice points that you can jump to. Note that this set consists of all the lattice points on the edge of a certain square. We assign integer 1 to point $(p + x_i, q + y_i)$. Then, we assign integers $2, 3, . . . , 8d$ to the remaining points in the set in the counter-clockwise order. (Here, assume that the right direction is positive in the $x$-axis and the upper direction is positive in the $y$-axis.) These integers represent the costs when you perform a jump to these points. </p> <p> For example, Figure K.1 illustrates the points reachable by your $i$-th jump when $d = 2$ and you are at $(3, 1)$. The numbers represent the costs for $x_i = −1$ and $y_i = −2$. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_K1" width="400"><br> <p>Figure K.1. Reachable points and their costs</p> </center> <p> Compute and output the minimum required sum of the costs for the objective. </p> <h3>Input</h3> <p> The input consists of a single test case.<br> <br> $n$ $d$ $s$ $t$<br> $x_1$ $y_1$<br> $x_2$ $y_2$<br> .<br> .<br> .<br> $x_n$ $y_n$<br> <br> The first line contains four integers. $n$ ($1 \leq n \leq 40$) is the number of jumps to perform. $d$ ($1 \leq d \leq 10^{10}$) is the $L_{\infty}$ distance which you must move by a single jump. $s$ and $t$ ($|s|, |t| \leq nd$) are the $x$ and $y$ coordinates of the destination point. It is guaranteed that there is at least one way to reach the destination point by performing $n$ jumps. </p> <p> Each of the following $n$ lines contains two integers, $x_i$ and $y_i$ with $max(|x_i|, |y_i|) = d$. </p> <h3>Output</h3> <p> Output the minimum required cost to reach the destination point. </p> <h3>Sample Input 1</h3> <pre>3 2 4 0 2 2 -2 -2 -2 2</pre> <h3>Sample Output 1</h3> <pre>15</pre> <h3>Sample Input 2</h3> <pre>4 1 2 -2 1 -1 1 0 1 1 -1 0</pre> <h3>Sample Output 2</h3> <pre>10</pre> <h3>Sample Input 3</h3> <pre>6 5 0 2 5 2 -5 2 5 0 -3 5 -5 4 5 5</pre> <h3>Sample Output 3</h3> <pre>24</pre> <h3>Sample Input 4</h3> <pre>5 91 -218 -351 91 91 91 91 91 91 91 91 91 91</pre> <h3>Sample Output 4</h3> <pre>1958</pre> <h3>Sample Input 5</h3> <pre>1 10000000000 -10000000000 -2527532346 8198855077 10000000000</pre> <h3>Sample Output 5</h3> <pre>30726387424</pre>
p02909
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...</p> <p>Given is a string <var>S</var> representing the weather in the town today. Predict the weather tomorrow.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>S</var> is <code>Sunny</code>, <code>Cloudy</code>, or <code>Rainy</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 a string representing the expected weather tomorrow, in the same format in which input is given.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>Sunny </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Cloudy </pre> <p>In Takahashi's town, a sunny day is followed by a cloudy day.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>Rainy </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Sunny </pre></section> </div> </span>
p01626
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <!-- <h3><u>Mirror Labyrinth</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> 誇り高き勇者であるあなたは、぀いに魔王の元ぞ蟿り着こうずしおいた。しかし、魔王がいる玉座の間に蟿り着くためには、魔王が甚意した最終マップをクリアしなければならない。 </p> <p> このマップにおいおは、党おのものが、䞊空から芋た二次元平面図のように倉化しおしたう。人間は、このマップにおいおは、ただの点に倉圢しおしたう。マップは、1本の盎線によっお、2぀の区域に区切られおいる。そしお、ある䞀方の区域に人がいるずき、もう䞀方の区域の、盎線に察しお線察称ずなる䜍眮に、人の鏡像が映し出される。 </p> <p> 2぀の区域それぞれには、耇数の建物が存圚する。建物ず蚀っおも、このマップでは、いく぀かの点を繋いで出来䞊がる倚角圢であり、蟺で囲たれた内偎、および蟺䞊が建物の内郚ずなる。建物は、人ずは違い、別の区域に鏡像を䜜り出すこずはない。 </p> <p> あなたがこのマップに䟵入するず、魔王の魔法により、いずれかの建物の内郚に拘束される。あなたは、拘束されおいる建物の内郚に1぀だけ存圚する脱出点に移動するこずでしか、マップをクリアするこずはできない。さらに、あなたは、魔王に呪いをかけられ、自身の動きを制限されおいる。その制限ずは、あなたのいる䜍眮、およびあなたの鏡像の䜍眮が、いずれかの建物内郚に存圚しなければならないずいうものである。この制限さえ守れば、あなたは自由に建物内郚を移動するこずができる。 </p> <p> さお、あなたは、䞀刻も早くこのマップをクリアし、䞖界を滅がさんずする魔王を打ち倒さなければならない。あなたの初期䜍眮が䞎えられたずき、脱出点ぞ移動するための最短路の距離を求めよ。ただし、脱出点ぞ移動できない堎合は、氞遠マップから脱出するこずができず、朜ち果おおいくのみである。 </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットから構成される。 各デヌタセットの圢匏は次の通りである。 </p> <pre> <var>N</var> <var>BUILDING<sub>1</sub></var> <var>...</var> <var>BUILDING<sub>N</sub></var> <var>SX</var> <var>SY</var> <var>GX</var> <var>GY</var> <var>LX<sub>1</sub></var> <var>LY<sub>1</sub></var> <var>LX<sub>2</sub></var> <var>LY<sub>2</sub></var> </pre> <p> 入力は、党お敎数倀である。 たた、座暙情報は、党お -10,000 &lt;= x, y &lt;= 10,000 であるず仮定しおよい。 </p> <p> N(1 &lt;= N &lt;= 100)は、建物の数である。その次に、N個の建物の情報が入力される。 BUILDING<sub>i</sub>は、次の圢匏で入力される倚角圢である。 </p> <pre> <var>M</var> <var>X<sub>1</sub></var> <var>Y<sub>1</sub></var> <var>...</var> <var>X<sub>M</sub></var> <var>Y<sub>M</sub></var> </pre> <p> M(3 &lt;= M &lt;= 50)は、倚角圢の頂点数を衚す。 続いおM個の頂点、(X<sub>i</sub>, Y<sub>i</sub>)が反時蚈回りで入力される。 (X<sub>i</sub>, Y<sub>i</sub>)ず(X<sub>i+1</sub>, Y<sub>i+1</sub>)の頂点を繋いだ線分が倚角圢の䞀蟺である。 ただし、M番目の頂点ずは、1番目の頂点が繋がる。 倚角圢の連続する3぀の頂点は、䞀盎線䞊に䞊ばないものず仮定しおよい。 たた、倚角圢の各蟺は、隣り合う蟺以倖ずは、接觊・亀差するこずはないように入力される。 各倚角圢は、他の倚角圢に、接觊・亀差・内包するこずはない。 </p> <p> 建物の情報が入力された埌、始点(SX, SY)、脱出点(GX, GY)の情報が入力される。 始点ず脱出点は、共に同じ建物の内郚に存圚する。 ただし、始点ず脱出点の鏡像は、必ずしも建物の内郚に存圚するずは限らないため泚意しおほしい。 この堎合は、もちろんマップをクリアするこずはできない。 始点ず脱出点は、必ず異なる䜍眮に存圚する。 </p> <p> 最埌に、盎線の情報が入力される。 盎線は、盎線䞊に存圚する2぀の点(LX<sub>1</sub>, LY<sub>1</sub>)ず(LX<sub>2</sub>, LY<sub>2</sub>)により衚される。 この2぀の点は、必ず異なる䜍眮に存圚する。 盎線は、いずれの建物ずも、接觊・亀差しないものず仮定しおよい。 </p> <p> 入力の終わりは、0が1぀だけの行で䞎えられる。 </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットごずに、始点から脱出点たでの最短距離を出力せよ。 解答の誀差は 0.00000001 (10<sup>-8</sup>) を超えおはならない。 粟床に関する条件を満たしおいれば、小数点以䞋は䜕桁数字を出力しおも構わない。 </p> <p> 脱出点たで蟿り着けない堎合は、&quot;impossible&quot;ず出力せよ。 </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 2 3 1 1 2 2 1 2 3 -1 1 -1 2 -2 2 1 1 2 2 0 0 0 1 2 10 1 1 7 1 7 5 5 5 5 3 6 3 6 2 3 2 3 5 1 5 10 -1 1 -1 5 -3 5 -3 3 -2 3 -2 2 -5 2 -5 5 -7 5 -7 1 2 4 6 4 0 0 0 1 2 7 -7 0 -5 0 -4 3 -3 0 -1 0 -1 4 -7 4 3 1 0 7 0 7 4 3 1 5 2 0 0 0 1 0 </pre> <!-- begin ja only --> <!-- end ja only --> <h3>Output for Sample Input</h3> <pre> 1.4142135623730951 8.0 impossible </pre> <!-- begin ja only --> <p> 以䞋の図はそれぞれサンプルの配眮を瀺しおいる。 図G-1、G-2では、赀の経路が勇者自身の経路を瀺し、青の経路が勇者の鏡像の経路を瀺す。 図G-3では、始点から脱出点たで蟿り着くこずはできない。 </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_mirrorLabyrinth_sample0" height="79" width="196"> </center> </center> <center> <p> <i>図G-1: 1番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_mirrorLabyrinth_sample1" height="216" width="596"> </center> </center> <center> <p> <i>図G-2: 2番目のサンプル</i> </p> </center> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_mirrorLabyrinth_sample2" height="221" width="596"> </center> </center> <center> <p> <i>図G-3: 3番目のサンプル</i> </p> </center> <!-- end ja only -->
p01276
<H1><font color="#000">Problem D:</font> Double Sorting</H1> <p> Here we describe a typical problem. There are <i>n</i> balls and <i>n</i> boxes. Each ball is labeled by a unique number from 1 to <i>n</i>. Initially each box contains one of these balls. We can swap two balls in adjacent boxes. We are to sort these balls in increasing order by swaps, i.e. move the ball labeled by 1 to the first box, labeled by 2 to the second box, and so forth. The question is how many swaps are needed. </p> <p> Now let us consider the situation where the balls are doubled, that is, there are 2<i>n</i> balls and <i>n</i> boxes, exactly two balls are labeled by <i>k</i> for each 1 &le; <i>k</i> &le; <i>n</i>, and the boxes contain two balls each. We can swap two balls in adjacent boxes, one ball from each box. We are to move the both balls labeled by 1 to the first box, labeled by 2 to the second box, and so forth. The question is again how many swaps are needed. </p> <p> Here is one interesting fact. We need 10 swaps to sort [5; 4; 3; 2; 1] (the state with 5 in the first box, 4 in the second box, and so forth): swapping 5 and 4, then 5 and 3, 5 and 2, 5 and 1, 4 and 3, 4 and 2, 4 and 1, 3 and 2, 3 and 1,and finally 2 and 1. Then how many swaps we need to sort [5, 5; 4, 4; 3, 3; 2, 2; 1, 1] (the state with two 5’s in the first box, two 4’s in the second box, and so forth)? Some of you might think 20 swaps - this is not true, but the actual number is 15. </p> <p> Write a program that calculates the number of swaps for the two-ball version and verify the above fact. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> <i>n</i><br> <i>ball</i><sub>1,1</sub> <i>ball</i><sub>1,2</sub><br> <i>ball</i><sub>2,1</sub> <i>ball</i><sub>2,2</sub><br> ...<br> <i>ball</i><sub><i>n</i>,1</sub> <i>ball</i><sub><i>n</i>,2</sub><br> </p> <p> <i>n</i> is the number of boxes (1 &le; <i>n</i> &le; 8). <i>ball</i><sub><i>i</i>,1</sub> and <i>ball</i><sub><i>i</i>,2</sub> , for 1 &le; <i>i</i> &le; <i>n</i>, are the labels of two balls initially contained by the <i>i</i>-th box. </p> <p> The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the minumum possible number of swaps. </p> <H2>Sample Input</H2> <pre> 5 5 5 4 4 3 3 2 2 1 1 5 1 5 3 4 2 5 2 3 1 4 8 8 3 4 2 6 4 3 5 5 8 7 1 2 6 1 7 0 </pre> <H2>Output for the Sample Input</H2> <pre> 15 9 21 </pre>
p00871
<H1><font color="#000">Problem H:</font> Top Spinning</H1> <p> Spinning tops are one of the most popular and the most traditional toys. Not only spinning them, but also making one’s own is a popular enjoyment. </p> <p> One of the easiest way to make a top is to cut out a certain shape from a cardboard and pierce an axis stick through its center of mass. Professionally made tops usually have three dimensional shapes, but in this problem we consider only two dimensional ones. </p> <p> Usually, tops have rotationally symmetric shapes, such as a circle, a rectangle (with 2-fold rotational symmetry) or a regular triangle (with 3-fold symmetry). Although such symmetries are useful in determining their centers of mass, they are not definitely required; an asymmetric top also spins quite well if its axis is properly pierced at the center of mass. </p> <p> When a shape of a top is given as a path to cut it out from a cardboard of uniform thickness, your task is to find its center of mass to make it spin well. Also, you have to determine whether the center of mass is on the part of the cardboard cut out. If not, you cannot pierce the axis stick, of course. </p> <!-- Java Specific: Submitted Java programs may not use classes implementing the interface “java.awt.Shape”. You may use them for your debugging purposes. --> <H2>Input</H2> <p> The input consists of multiple datasets, each of which describes a counterclockwise path on a cardboard to cut out a top. A path is indicated by a sequence of command lines, each of which specifies a line segment or an arc. </p> <p> In the description of commands below, the <i>current</i> position is the position to start the next cut, if any. After executing the cut specified by a command, the <i>current position</i> is moved to the end position of the cut made. </p> <p> The commands given are one of those listed below. The command name starts from the first column of a line and the command and its arguments are separated by a space. All the command arguments are integers. </p> <pre> start <i>x</i> <i>y</i> </pre> <p> Specifies the start position of a path. This command itself does not specify any cutting; it only sets the <i>current position</i> to be (<i>x</i>, <i>y</i>). </p> <pre> line <i>x y</i> </pre> <p> Specifies a linear cut along a straight line from the <i>current position</i> to the position (<i>x</i>, <i>y</i>), which is not identical to the <i>current position</i>. </p> <pre> arc <i>x y r</i> </pre> <p> Specifies a round cut along a circular arc. The arc starts from the <i>current position</i> and ends at (<i>x</i>, <i>y</i>), which is not identical to the <i>current position</i>. The arc has a radius of |<i>r</i>|. When <i>r</i> is negative, the center of the circle is to the left side of the direction of this round cut; when it is positive, it is to the right side (Figure 1). The absolute value of <i>r</i> is greater than the half distance of the two ends of the arc. Among two arcs connecting the start and the end positions with the specified radius, the arc specified is one with its central angle less than 180 degrees. </p> <pre> close </pre> <p> Closes a path by making a linear cut to the initial start position and terminates a dataset. If the <i>current position</i> is already at the start position, this command simply indicates the end of a dataset. </p> <p> The figure below gives an example of a command sequence and its corresponding path. Note that, in this case, the given radius -<i>r</i> is negative and thus the center of the arc is to the left of the arc. The arc command should be interpreted as shown in this figure and, not the other way around on the same circle. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_topSpinning1"> <p>Figure 1: A partial command sequence and the path specified so far</p> </center> <p> A dataset starts with a start command and ends with a close command. </p> <p> The end of the input is specified by a line with a command end. </p> <p> There are at most 100 commands in a dataset and at most 100 datasets are in the input. Absolute values of all the coordinates and radii are less than or equal to 100. </p> <p> You may assume that the path does not cross nor touch itself. You may also assume that paths will never expand beyond edges of the cardboard, or, in other words, the cardboard is virtually infinitely large. </p> <H2>Output</H2> <p> For each of the dataset, output a line containing <i>x</i>- and <i>y</i>-coordinates of the center of mass of the top cut out by the path specified, and then a character ‘+’ or ‘-’ indicating whether this center is on the top or not, respectively. Two coordinates should be in decimal fractions. There should be a space between two coordinates and between the <i>y</i>-coordinate and the character ‘+’ or ‘-’. No other characters should be output. The coordinates may have errors less than 10<sup>-3</sup> . You may assume that the center of mass is at least 10<sup>-3</sup> distant from the path. </p> <H2>Hints</H2> <p> An important nature of mass centers is that, when an object <i>O</i> can be decomposed into parts <i>O</i><sub>1</sub> , . . . , <i>O</i><sub><i>n</i></sub> with masses <i>M</i><sub>1</sub> , . . . , <i>M</i><sub><i>n</i></sub> , the center of mass of <i>O</i> can be computed by: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_topSpinning2"> </center> <p> where <i>G<sub>k</sub></i> is the vector pointing the center of mass of <i>O<sub>k</sub></i>. </p> <p> A circular segment with its radius <i>r</i> and angle <i>&theta;</i> (in radian) has its arc length <i>s</i> = <i>r&theta;</i> and its chord length <i>c</i> = <i>r</i>&radic;(2 - 2cos<i>&theta;</i>). Its area size is <i>A</i> = <i>r</i><sup>2</sup>(<i>&theta;</i> - sin<i>&theta;</i>)/2 and its center of mass <i>G</i> is <i>y</i> = 2<i>r</i><sup>3</sup>sin<sup>3</sup>(<i>&theta;</i>/2)/(3<i>A</i>) distant from the circle center. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_topSpinning3"> <p>Figure 2: Circular segment and its center of mass</p> </center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_topSpinning4"> <p>Figure 3: The first sample top</p> </center> <H2>Sample Input</H2> <pre> start 0 0 arc 2 2 -2 line 2 5 arc 0 3 -2 close start -1 1 line 2 1 line 2 2 line -2 2 arc -3 1 -1 line -3 -2 arc -2 -3 -1 line 2 -3 line 2 -2 line -1 -2 line -1 -1 arc -1 0 2 close start 0 0 line 3 0 line 5 -1 arc 4 -2 -1 line 6 -2 line 6 1 line 7 3 arc 8 2 -1 line 8 4 line 5 4 line 3 5 arc 4 6 -1 line 2 6 line 2 3 line 1 1 arc 0 2 -1 close end </pre> <H2>Output for the Sample Input</H2> <pre> 1.00000 2.50000 + -1.01522 -0.50000 - 4.00000 2.00000 + </pre>
p01763
<h1>D : Chopsticks / 箞</h1> <h1>Problem</h1> <p>お箞は 2 本 1 セット(1 膳)で甚いるものである。しかしあるずき䞀人暮らしの倧孊生であるいあづ君は箞立おに入っおいるお箞が奇数本であるこずに気が぀いた。これは明らかにおかしい。い぀の間にか䜕本か無くしおしたったのである。 困ったいあづ君は、今埌このようなこずが無いように箞の本数を毎日蚘録するこずにした。</p> <p>ずころが、いあづ君が決めた蚘録の方法は少し倉わっおいる。 それは、たず<em>M</em> 個の自然数 <em>A<sub>1</sub></em>, ... , <em>A<SUB>M</SUB></em> を決めた埌、 箞の本数をそれらで割った䜙りを毎日蚘録するずいうものである。 䟋えばある日に残っおいる箞の本数が <em>T</em> のずき、 その日の蚘録ずしお <em>T</em> % <em>A<sub>1</sub></em> , ... , <em>T</em> % <em>A<SUB>M</SUB></em> を付ける。 ただ、たたにいく぀か蚘録し忘れたり、間違った蚘録を付けたりするこずもあるようだ。 (<em>x</em> % <em>y</em> は <em>x</em> を <em>y</em> で割った䜙りである。)</p> <p>ここでいあづ君は倧事なこずに気づいた。 これだず最終日に䜕本残っおいるか 1 ぀に決たらない</p> <p>ポゞティブないあづ君は、 <em>D</em> 日分の蚘録をもずに、 <em>D</em> 日目の蚘録を぀けた盎埌に残っおいる箞の本数の最倧倀を求めるプログラムを曞くこずにした。</p> <h1>Input</h1> <p>入力は次のような圢匏で䞎えられる</p> <p><em>N</em> <em>M</em> <em>D</em><br><em>A<sub>1</sub></em> <em>A<sub>2</sub></em> ... <em>A<SUB>M</SUB></em><br><em>R<sub>11</sub></em> <em>R<sub>12</sub></em> ... <em>R<sub>1M</sub></em><br><em>R<sub>21</sub></em> <em>R<sub>22</sub></em> ... <em>R<sub>2M</sub></em><br>...<br><em>R<SUB>D1</SUB></em> <em>R<sub>12</sub></em> ... <em>R<SUB>DM</SUB></em></p> <ul> <li><em>N</em>, <em>M</em>, <em>D</em> は、それぞれ蚘録を開始する盎前にあったお箞の本数、䜙りを求めるのに䜿う敎数の個数、蚘録を぀けた日数である。<em>A<sub>1</sub></em> <em>A<sub>2</sub></em> ... <em>A<SUB>M</SUB></em> は䜙りを求めるのに䜿う敎数である。</li> <li>2 + <em>d</em> 行目の <em>R<sub>d1</sub></em>, <em>R<sub>d2</sub></em>, ... ,<em>R<sub>dM</sub></em> は、<em>d</em> 日目に残っおいるお箞の本数を <em>A<sub>1</sub></em>, <em>A<sub>2</sub></em>, ... ,<em>A<SUB>M</SUB></em> のそれぞれで割った䜙りである。<em>R<sub>di</sub></em> = -1 のずきは、その蚘録を付け忘れたこずを意味する。</li> </ul> <h1>Constraints</h1> <ul> <li>入力は党お敎数である。</li> <li>1 ≩ <em>N</em> ≩ 1,000,000,000</li> <li>1 ≩ <em>M</em> ≩ 10</li> <li>1 ≩ <em>D</em> ≩ 100</li> <li>2 ≩ <em>A<sub>i</sub></em> ≩ 100</li> <li><em>i</em> ≠ <em>j</em> のずき <em>A<sub>i</sub></em> ≠ <em>A<sub>j</sub></em></li> <li>0 ≩ <em>R<sub>ij</sub></em> &lt; <em>A<sub>i</sub></em></li> <li><em>i</em> 日目に存圚する箞の数は、<em>i</em> - 1 日目に存圚しおいた箞の数ず同等か、それより少なくなる。</li> </ul> <h1>Output</h1> <p><em>D</em> 日目に残っおいるず考えられる箞の数の最倧倀を 1 行で出力せよ。 蚘録に明らかに間違いがある堎合は -1 を出力せよ。</p> <h1>Samples</h1> <h2>Sample Input 1</h2> <pre>3 3 2 2 3 4 1 0 3 0 2 2</pre> <h2>Sample Output 1</h2> <pre>2</pre> <p>0 日目に 3 本あった箞は、 1 日目に 3 本、 2 日目に 2 本になったず考えられる。</p> <h2>Sample Input 2</h2> <pre>3 3 2 2 3 4 0 0 0 0 0 1</pre> <h2>Sample Output 2</h2> <pre>-1</pre> <p>0 日目に 3 本あった箞は、 1 日目に 0 本になったず考えられる。ずころが 2 日目の 4 で割った䜙りが1になっおいる。</p> <h2>Sample Input 3</h2> <pre>3 3 2 2 3 4 1 0 3 -1 -1 -1</pre> <h2>Sample Output 3</h2> <pre>3</pre> <p>0 日目に 3 本あった箞は、 1 日目も 3 本あったず考えられる。2 日目は蚘録し忘れおしたった。</p>
p01299
<H1><font color="#000">Problem G:</font>Neko's Treasure</H1> <p> Maki is a house cat. One day she fortunately came at a wonderful-looking dried fish. Since she felt not hungry on that day, she put it up in her bed. However there was a problem; a rat was living in her house, and he was watching for a chance to steal her food. To secure the fish during the time she is asleep, she decided to build some walls to prevent the rat from reaching her bed. </p> <p> Maki's house is represented as a two-dimensional plane. She has hidden the dried fish at (<i>x<sub>t</sub></i>, <i>y<sub>t</sub></i>). She knows that the lair of the rat is located at (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i> ). She has some candidate locations to build walls. The <i>i</i>-th candidate is described by a circle of radius <i>r<sub>i</sub></i> centered at (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>). She can build walls at as many candidate locations as she wants, unless they touch or cross each other. You can assume that the size of the fish, the rat’s lair, and the thickness of walls are all very small and can be ignored. </p> <p> Your task is to write a program which determines the minimum number of walls the rat needs to climb over until he can get to Maki's bed from his lair, assuming that Maki made an optimal choice of walls. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset corresponds to a single situation and has the following format: </p> <p> <i>n</i><br> <i>x<sub>s</sub> y<sub>s</sub> x<sub>t</sub> y<sub>t</sub></i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>r</i><sub>1</sub><br> ...<br> <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>r</i><sub><i>n</i></sub><br> </p> <p> <i>n</i> is the number of candidate locations where to build walls (1 &le; <i>n</i> &le; 1000). (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i> ) and (<i>x<sub>t</sub></i> , <i>y<sub>t</sub></i> ) denote the coordinates of the rat's lair and Maki's bed, respectively. The <i>i</i>-th candidate location is a circle which has radius <i>r<sub>i</sub></i> (1 &le; <i>r<sub>i</sub></i> &le; 10000) and is centered at (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) (<i>i</i> = 1, 2, ... , <i>n</i>). All coordinate values are integers between 0 and 10000 (inclusive). </p> <p> All candidate locations are distinct and contain neither the rat's lair nor Maki's bed. The positions of the rat's lair and Maki's bed are also distinct. </p> <p> The input is terminated by a line with "<span>0</span>". This is not part of any dataset and thus should not be processed. </p> <H2>Output</H2> <p> For each dataset, print a single line that contains the minimum number of walls the rat needs to climb over. </p> <H2>Sample Input</H2> <pre> 3 0 0 100 100 60 100 50 100 100 10 80 80 50 4 0 0 100 100 50 50 50 150 50 50 50 150 50 150 150 50 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 0 </pre>
p01333
<h1><font color="#000">Problem A:</font> Summer of KMC</h1> <h2>Description</h2> <p>KMCはコミックマヌケットず呌ばれる同人即売䌚で毎幎CDを販売しおいる。 コミックマヌケットでCDを売るこずになったFであったが、Fの人気により、KMCの売り堎には人が殺到し、お釣りの蚈算が远い぀かない状態ずなった。そこでFは金額を入力するず即座にお釣りを出力するプログラムを曞くこずにした。</p> <p>KMCが釣り銭ずしお甚意しおいるのは、100円玉ず500円玉ず1000円札のみである。これらの硬貚・札は無限にあるものず考えお良い。お釣りは、硬貚・札の個数が最小になるように遞ぶ。たた、KMCが販売するCDの倀段は100の倍数であり、賌入者が支払う金額も100の倍数である。</p> <h2>Input</h2> <p>入力は耇数のテストケヌスから成る。</p> <p>各テストケヌスは2぀の正敎数A, Bから成る。AはCDの倀段であり、Bは賌入者が支払った金額である。A, Bは100の倍数であり、100000000を超えない。たた、A ≩ B である。</p> <p>入力は0 0で終わる。</p> <h2>Output</h2> <p>各テストケヌスに察しお、お釣りずしお差し出すべき 100円玉、500円玉、1000円札の個数・枚数を䞀行でこの順番に出力する。各数字の間にはスペヌスを1぀入れる。</p> <h2>Sample Input</h2> <pre>500 1000 100 10000 400 700 600 5000 10000 10000 0 0 </pre> <h2>Output for Sample Input</h2> <pre>0 1 0 4 1 9 3 0 0 4 0 4 0 0 0 </pre>
p00172
<H1>博士の研究宀</H1> <p> 䌚接倧孊の鶎賀博士はずおも研究熱心なこずで有名です。圌の研究宀には耇数の孊生がいたすが、圌は毎日倜遅くたで研究をするので必ず最埌に垰宅したす。圌の研究宀にはドアで぀ながった耇数の郚屋があり、最埌に研究宀を出る人がすべおの郚屋の明かりを消しお垰宅するこずになっおいたす。 </p> <p> 最近、倧孊では省゚ネに力を入れおいるため、すべおの明かりが消えおいるか厳しくチェックされたす。困ったこずに圌は誰もが認める極床の臆病者で、明かりの消えた郚屋には決しお入るこずができたせん。そこで、圌はある郚屋の照明のON/OFFを他の郚屋から操䜜できるように研究宀の照明蚭備を改造したした。 </p> <p> ずころが、予算の郜合で぀の郚屋からコントロヌルできる郚屋が限られおいたす。その䞊、垰宅時の各郚屋の明かりの状態も日によっお異なるため、党おの明かりを消しお出口たでたどり぀くのに毎日かなりの時間が掛かっおいたす。そこで、研究員のあなたが博士を助けるためにプログラムを䜜成するこずになりたした。 </p> <p> 研究宀の郚屋情報、各郚屋の明かりの点灯情報、各郚屋の照明スむッチの情報を入力ずし、博士がすべおの明かりを消しお垰宅できるかどうかを出力するプログラムを䜜成しおください。ただし、郚屋の数 <var>n</var> は 1 以䞊 15 以䞋の敎数、ドアの数 <var>m</var> は 1 以䞊 30 以䞋の敎数、照明の点灯情報 <var>l</var> は 0 たたは 1 の敎数でそれぞれ消灯ず点灯を衚し、各郚屋には 1 以䞊 <var>n</var> 以䞋の敎数で番号が付䞎されおいるものずしたす。出口は番号 <var>n</var> の郚屋に存圚し、博士は垞に郚屋 1 からスタヌトするものずしたす。 </p> <p> なお、出力は、博士の取るべき行動に応じお以䞋の 3 通りに分けお出力したす。 </p> <p><b>ケヌス</b>. 出口以倖の党おの明かりを消しお出口にたどり぀ける堎合経路の過皋で出口を通っおもよい。 </p> <pre> You can go home in X steps. </pre> <p> ず出力したす。ここで X は郚屋の移動、スむッチのON/OFF をそれぞれステップずした堎合の、博士の郚屋から出口にたどり着くたでの最短のステップ数です。さらに、以䞋の文字列に埓い博士の郚屋から出口たでの経路博士のずるべき行動を X 行で出力したす。 </p> <ul> <li>郚屋 R ぞ移動する堎合 <pre> Move to room R. </pre> </li> <li>郚屋 R の照明を消す堎合 <pre> Switch off room R. </pre> </li> <li>郚屋 R の照明を点灯する堎合 <pre> Switch on room R. </pre> </li> </ul> <p> ここで、R は郚屋の番号を衚したす。博士がある郚屋に移動した盎埌、耇数のスむッチを操䜜しお次の郚屋に移動する堎合は操䜜する郚屋番号が小さいほうから出力しおください。この条件を満たす限り、耇数の解がある堎合は、どれを出力しおもかたいたせん。この情報をもずに、博士は無事垰宅するこずができたす。 </p> <p> <b>ケヌス2</b>. 出口にたどり着くこずはできるが、出口のある郚屋以倖の党おの明かりを消すこずが できない堎合。 </p> <pre> You can not switch off all lights. </pre> <p> ず出力する。この堎合、博士は省゚ネを守らなかったずしお倧孊に眰せられたす。 </p> <p> <b>ケヌス3</b>. どうあがいおも出口にたどり着けない堎合。 <pre> Help me! </pre> <p> ず出力する。この堎合、博士は譊備員に緊急救助を求めたす。 </p> <p> 簡単な䟋を瀺したす。この䟋では、研究宀は 4 ぀の郚屋で構成され、郚屋 1 ず 2、2 ず 3、2 ず 4 がそれぞれ繋がっおいたす。たた、郚屋 1 及び 4 から郚屋 2、3 の照明を操䜜するこずができ、郚屋 3 から郚屋 1、2、4 の照明を操䜜するこずができたす。最初、郚屋 2、3、4 の照明が消えた状態で、博士が郚屋 1 にいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_researchRoom"><br/> <br/> </center> <p> この状況では、博士が取るべき行動は次のようになりたす。 </p> <pre> 郚屋2ず3の照明をonにする。 郚屋2に移動する。 郚屋3に移動する。 郚屋1の照明をoffにし、郚屋4の照明をonにする。 郚屋2に移動する。 郚屋4に移動する。 郚屋2ず3の照明をoffにする。 </pre> <p> これで博士は郚屋 4 以倖の照明を消すこずができ、垰宅するこずができたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロ2぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>m</var> <var>s<sub>1</sub></var> <var>t<sub>1<sub></var> <var>s<sub>2</sub></var> <var>t<sub>2<sub></var> : <var>s<sub>m</sub></var> <var>t<sub>m<sub></var> <var>l<sub>1</sub></var> <var>l<sub>2</sub></var> ... <var>l<sub>n</sub></var> <var>k<sub>1</sub></var> <var>r<sub>1</sub></var> <var>r<sub>2</sub></var> ... <var>r<sub>k<sub>1</sub></sub></var> <var>k<sub>2</sub></var> <var>r<sub>1</sub></var> <var>r<sub>2</sub></var> ... <var>r<sub>k<sub>2</sub></sub></var> : <var>k<sub>n</sub></var> <var>r<sub>1</sub></var> <var>r<sub>2</sub></var> ... <var>r<sub>k<sub>n</sub></sub></var> </pre> <p> 行目に郚屋の数 <var>n</var> (1 &le; <var>n</var> &le; 15) ずドアの数 <var>m</var> (1 &le; <var>m</var> &le; 30) が空癜区切りで䞎えられたす。続く <var>m</var> 行に <var>i</var> 個目のドアの情報が䞎えられたす。<var>s<sub>i</sub></var> <var>t<sub>i</sub></var> は郚屋 <var>s<sub>i</sub></var> ず郚屋 <var>t<sub>i</sub></var> がドアで繋がっおいるこずを衚したす。 </p> <p> 続く行に、郚屋 <var>i</var> の照明の点灯情報 <var>l<sub>i</sub></var> (0 たたは 1) が空癜区切りで䞎えられたす。 </p> <p> 続く <var>n</var> 行に郚屋 <var>i</var> のスむッチ情報が䞎えられたす。<var>k<sub>i</sub></var> (0 &le; <var>k<sub>i</sub></var> &le; 12) は郚屋 <var>i</var> のスむッチの数、<var>r<sub>1</sub></var> ... <var>r<sub>k<sub>i</sub></sub></var> は照明を操䜜できる郚屋の番号を衚したす。 </p> <p> デヌタセットの数は100 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、䞊蚘の 3 通りの結果に応じお以䞋の圢匏で出力したす。 </p> <p>ケヌス 1 の堎合<br/> <br/> 1行目: You can go home in X steps.<br/> 2行目: 1぀目の博士が取るべき行動<br/> 3行目: 2぀目の博士が取るべき行動<br/> :<br/> X+1 行目: X 個目の博士が取るべき行動<br/> </p> <p>ケヌス 2 の堎合<br/> <br/> 1 行目: You can not switch off all lights.<br/> </p> <p>ケヌス 3 の堎合<br/> <br/> 1 行目: Help me!<br/> </pre> <H2>Sample Input</H2> <pre> 4 3 1 2 2 3 2 4 1 0 0 0 2 2 3 0 3 1 2 4 2 2 3 4 3 1 2 2 3 2 4 1 0 0 0 2 2 3 0 3 1 2 4 1 3 4 3 1 2 2 3 2 4 1 0 0 0 2 2 3 0 2 1 2 2 2 3 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> You can go home in 10 steps. Switch on room 2. Switch on room 3. Move to room 2. Move to room 3. Switch off room 1. Switch on room 4. Move to room 2. Move to room 4. Switch off room 2. Switch off room 3. You can not switch off all lights. Help me! </pre>
p00488
<H1>ランチ (Lunch) </H1> <h2>問題</h2> <p> JOI パスタ店ではランチのおすすめパスタず搟りたおゞュヌスのセットメニュヌが奜評であるこのセットメニュヌを泚文するずきはその日の 3 皮類のパスタず 2 皮類のゞュヌスから 1 ぀ず぀遞ぶパスタずゞュヌスの倀段の合蚈から 50 円を匕いた金額が代金ずなる </p> <p> ある日のパスタずゞュヌスの倀段が䞎えられたずきその日のセットメニュヌの代金の最小倀を求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は 5 行からなり1 行に 1 ぀ず぀正の敎数が曞かれおいる<br> 1 行目の敎数は 1 ぀目のパスタの倀段である<br> 2 行目の敎数は 2 ぀目のパスタの倀段である<br> 3 行目の敎数は 3 ぀目のパスタの倀段である<br> 4 行目の敎数は 1 ぀目のゞュヌスの倀段である<br> 5 行目の敎数は 2 ぀目のゞュヌスの倀段である<br> ただし䞎えられる入力デヌタにおいおは党おのパスタずゞュヌスの倀段は 100 円以䞊 2000 円以䞋であるこずが保蚌されおいる </p> <h2>出力</h2> <p> その日のセットメニュヌの代金の最小倀を 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 800 700 900 198 330 </pre> <h3>出力䟋 1</h3> <pre> 848 </pre> <p> 入出力䟋 1 では2 ぀目のパスタず 1 ぀目のゞュヌスを組み合わせた堎合の 700 + 198 - 50 = 848 がその日のセットメニュヌの代金の最小倀である </p> <h3>入力䟋 2</h3> <pre> 1999 1999 100 189 100 </pre> <h3>出力䟋 2</h3> <pre> 150 </pre> <p> 入出力䟋 2 では3 ぀目のパスタず 2 ぀目のゞュヌスを組み合わせた堎合の 100 + 100 - 50 = 150 がその日のセットメニュヌの代金の最小倀である </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00522
<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> IOI 饅頭(IOI Manju) </H1> <br/> <p> Incredible Okashi Inc. は「途方もなくおいしいお菓子(incredible okashi)」を補䜜しおいる䌚瀟であるここでは略しおIOI 瀟ず呌ぶIOI 瀟は特補のIOI 饅頭を䜜ったのでそれを販売するこずになったIOI 瀟は$M$ 皮類の饅頭を1 個ず぀䜜った䜜られた$M$ 個の饅頭はすべお同じ倧きさであるがひず぀ひず぀異なる味なので䟡栌は様々であり$i$ 番目$(1 \leq i \leq M)$ の饅頭の䟡栌は$P_i$ 円である </p> <p> ずころであなたはJust Odd Inventions 瀟を知っおいるだろうか この䌚瀟の業務は「ただ奇劙な発明(just odd inventions)」をするこずであるここでは略しおJOI 瀟ず呌ぶIOI 瀟は饅頭を詰めるための高玚な箱をJOI 瀟に発泚するこずになったJOI 瀟の補䜜する饅頭甚の箱は$N$ 皮類あり $j$ 番目$(1 \leq j \leq N)$の箱は最倧で$C_j$ 個の饅頭を詰められる倧きさであり販売䟡栌は$E_j$ 円であるこれらの$N$ 皮類の箱のうちの䜕皮類か(0 皮類以䞊$N$ 皮類以䞋) を1 個ず぀発泚し饅頭をそれらの箱に詰め分けおセットで販売するこずになった各饅頭セットの䟡栌はそれに含たれる饅頭の䟡栌の合蚈である </p> <p> すべおの饅頭セットが売れるずした堎合IOI 瀟が埗るこずができる利益の最倧倀はいくらだろうかここで利益ずは販売した饅頭セットの䟡栌の合蚈から発泚した箱の䟡栌の合蚈を匕いた倀であるなお箱に詰めなかった饅頭に぀いおはIOI 瀟のスタッフがおいしくいただくため利益には圱響しないものずする </p> <h2>課題</h2> <p> 各饅頭の䟡栌ず各箱の倧きさず䟡栌が䞎えられたずきIOI 瀟が埗るこずができる利益の最倧倀を求めるプログラムを䜜成せよ </p> <h2>入力</h2> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li>1 行目には敎数 $M, N$ が空癜を区切りずしお曞かれおおり饅頭が $M$ 個箱が $N$ 皮類あるこずを衚す</li> <li>続く $M$ 行のうちの $i$ 行目 $(1 \leq i \leq M)$ には敎数 $P_i$ が曞かれおおり$i$ 番目の饅頭の䟡栌が $P_i$ 円であるこずを衚す</li> <li>続く$N$ 行のうちの $j$ 行目 $(1 \leq j \leq N)$ には敎数 $C_j$, $E_j$ が空癜を区切りずしお曞かれおおり $j$ 番目の箱は最倧で $C_j$ 個の饅頭を詰められる倧きさであり䟡栌が $E_j$ 円であるこずを衚す</li> </ul> <h2>出力</h2> <p> 暙準出力にIOI 瀟が埗られる利益の最倧倀を円単䜍で衚す敎数を1 行で出力せよ </p> <h2>制限</h2> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li>$1 \leq M \leq 10000$</li> <li>$1 \leq N \leq 500$</li> <li>$1 \leq P_i \leq 10000 (1 \leq i \leq M)$</li> <li>$1 \leq C_j \leq 10000 (1 \leq j \leq N)$</li> <li>$1 \leq E_j \leq 10000 (1 \leq j \leq N)$</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1 </h3> <pre> 4 3 180 160 170 190 2 100 3 120 4 250 </pre> <h3>出力䟋 1 </h3> <pre> 480 </pre> <p> この䟋では1 番目の箱(100 円) ず2 番目の箱(120 円) を発泚したずえば1 番目の箱に1 番目の饅頭ず2 番目の饅頭を詰めお $180 + 160 = 340$ 円のセットずしお販売2 番目の箱に3 番目の饅頭ず4 番目の饅頭を詰めお $170 + 190 = 360$ 円のセットずしお販売するずIOI 瀟の利益は $700 - 220 = 480$ 円ずなる </p> <br> <h3>入力䟋 2 </h3> <pre> 2 2 1000 2000 1 6666 1 7777 </pre> <h3>出力䟋 2 </h3> <pre> 0 </pre> <p> この䟋では利益を最倧化するためには箱を党く買わないのがよい </p> <br> <h3>入力䟋 3 </h3> <pre> 10 4 200 250 300 300 350 400 500 300 250 200 3 1400 2 500 2 600 1 900 </pre> <h3>出力䟋 3 </h3> <pre> 450 </pre> <br> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p03027
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider the following arithmetic progression with <var>n</var> terms:</p> <ul> <li><var>x, x + d, x + 2d, \ldots, x + (n-1)d</var></li> </ul> <p>What is the product of all terms in this sequence? Compute the answer modulo <var>1\ 000\ 003</var>.</p> <p>You are given <var>Q</var> queries of this form. In the <var>i</var>-th query, compute the answer in case <var>x = x_i, d = d_i, n = n_i</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>0 \leq x_i, d_i \leq 1\ 000\ 002</var></li> <li><var>1 \leq n_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>Q</var> <var>x_1</var> <var>d_1</var> <var>n_1</var> <var>:</var> <var>x_Q</var> <var>d_Q</var> <var>n_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines.</p> <p>In the <var>i</var>-th line, print the answer for the <var>i</var>-th query.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 7 2 4 12345 67890 2019 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9009 916936 </pre> <p>For the first query, the answer is <var>7 \times 9 \times 11 \times 13 = 9009</var>. Don't forget to compute the answer modulo <var>1\ 000\ 003</var>.</p></section> </div> </span>
p03477
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A balance scale tips to the left if <var>L&gt;R</var>, where <var>L</var> is the total weight of the masses on the left pan and <var>R</var> is the total weight of the masses on the right pan. Similarly, it balances if <var>L=R</var>, and tips to the right if <var>L&lt;R</var>.</p> <p>Takahashi placed a mass of weight <var>A</var> and a mass of weight <var>B</var> on the left pan of a balance scale, and placed a mass of weight <var>C</var> and a mass of weight <var>D</var> on the right pan.</p> <p>Print <code>Left</code> if the balance scale tips to the left; print <code>Balanced</code> if it balances; print <code>Right</code> if it tips to the right.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1\leq A,B,C,D \leq 10</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>Left</code> if the balance scale tips to the left; print <code>Balanced</code> if it balances; print <code>Right</code> if it tips to the right.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 8 7 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Left </pre> <p>The total weight of the masses on the left pan is <var>11</var>, and the total weight of the masses on the right pan is <var>8</var>. Since <var>11&gt;8</var>, we should print <code>Left</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 4 5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Balanced </pre> <p>The total weight of the masses on the left pan is <var>7</var>, and the total weight of the masses on the right pan is <var>7</var>. Since <var>7=7</var>, we should print <code>Balanced</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 7 6 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Right </pre> <p>The total weight of the masses on the left pan is <var>8</var>, and the total weight of the masses on the right pan is <var>10</var>. Since <var>8&lt;10</var>, we should print <code>Right</code>.</p></section> </div> </span>
p02636
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var> consisting of <code>0</code> and <code>1</code>. Find the number of strings, modulo <var>998244353</var>, that can result from applying the following operation on <var>S</var> zero or more times:</p> <ul> <li>Remove the two characters at the beginning of <var>S</var>, erase one of them, and reinsert the other somewhere in <var>S</var>. This operation can be applied only when <var>S</var> has two or more characters.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 300</var></li> <li><var>S</var> consists of <code>0</code> and <code>1</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of strings, modulo <var>998244353</var>, that can result from applying the operation on <var>S</var> zero or more times.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>0001 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>Eight strings, <code>0001</code>, <code>001</code>, <code>010</code>, <code>00</code>, <code>01</code>, <code>10</code>, <code>0</code>, and <code>1</code>, can result.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>110001 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>24 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>11101111011111000000000110000001111100011111000000001111111110000000111111111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>697354558 </pre></section> </div> </span>
p01919
<link rel="stylesheet" href="css/description.css" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/varmath2017.js" charset="UTF-8"></script> <h2>D歪みの囜 - Country In Distortion -</h2> <h3>物語</h3> <p>アリスはすっかり退屈しおいたした。い぀も䞀緒に遊んでいる癜りサギが、トランプ城ぞ出かけおいるからです。あヌあ、こんなこずなら䞀緒に出かければよかったわ。ずアリスは思いたした。けれども、ここは歪みの囜。そうやすやすず出かけおは、ひどく疲れおしたいたす。どういうこずかずいうず—</p> <p>癜りサギは困っおいたした。トランプ城ぞの道䞭、ちょっずだけ道を間違えおしたったのです。困ったなあ。䞀床戻っお、道を良く知っおいるアリスに案内しおもらうこずにしよう。ず癜りサギは考えたした。それにしおも、癜りサギはずっおも疲れおいるみたい。癜りサギは懐䞭時蚈を芋ながら、</p> <p>「なんだっおこの囜の道は、通る床に長さが倉わったように感じるんだこの道、さっきは100メヌトルくらいに感じたけど、今床は1キロはあるんじゃないかそれも、通り抜けるのにかかる時間はほずんど倉わっおないっお蚀うのに」</p> <p> ず叫んでいたす。そう、ここは歪みの囜。たさに、時々刻々ず道が歪み続ける䞍思議な囜なのです。 やっずの思いでアリスの家に着いた癜りサギが開口䞀番、 </p> <p>「ごめんよアリス。トランプ城たで、道案内をお願いできるかい。」</p> <p>ず蚀うず、退屈のあたりオフトゥンに突っ䌏しおしおいたアリスは元気に飛び起きたした。</p> <p>「もちろんよ䞀緒に行きたしょう」</p> <p>嬉しい䞀方で、疲れた様子の癜りサギを芋おでも、あたりに疲れおしたうのは悪いわね。ず思ったアリスは、家の奥から歪みの囜の地図を取り出しおきたした。</p> <p>「さあ、トランプ城たでの疲れない道のりを探すわ」</p> <h3>問題</h3> <p> <var>n</var>頂点ず<var>m</var>蟺からなる無向グラフが䞎えられる。各蟺<var>i</var>の移動にかかる時間は<var>t_i</var>で衚される。たた、初めの䜓感移動速床ずしお<var>v_0</var>が䞎えられる。その埌、蟺を1本通る床に䜓感移動速床が倉化する。蟺を<var>j</var>本通った埌の䜓感移動速床は、敎数<var>a, b, c</var>をパラメヌタずしお以䞋の匏で䞎えられる。</p> <pre><var>v_j = (a \times v_{j-1} + b)</var> <var>mod</var> <var>c</var></pre> <p>蟺<var>i</var>を速床<var>v_j</var>で通るず䜓感移動距離が<var>t_i \times v_j</var>ずなる。なお、歪みの囜では䜓感移動速床が0でも移動可胜であり、そのずきの䜓感移動距離は0である。</p> <p> 今、頂点<var>1</var>から出発し頂点<var>n</var>を経由しお頂点<var>1</var>に戻っおくるような経路を考える。考えうる経路の䞭で䜓感移動距離の総和を最小化せよ。</p> <h3>入力圢匏</h3> <pre> <var>n</var> <var>m</var> <var>x_1</var> <var>y_1</var> <var>t_1</var> ... <var>x_m</var> <var>y_m</var> <var>t_m</var> <var>v_0</var> <var>a</var> <var>b</var> <var>c</var> </pre> <p> 入力は党お敎数からなる。 1行目には、グラフの頂点数ず蟺数を衚す<var>n,m</var>がこの順で空癜区切りで䞎えられる。 続く<var>m</var>行のうち<var>i</var>行目には、<var>i</var>番目の蟺が接続する2頂点<var>x_i,y_i</var>ず、通過するのにかかる時間<var>t_i</var>がこの順で空癜区切りで䞎えられる。 <var>m+2</var>行目には、初速床を衚す<var>v_0</var>が䞎えられる。 <var>m+3</var>行目には、速床の蚈算匏のパラメヌタ<var>a,b,c</var>がこの順に空癜区切りで䞎えられる。 </p> <h3>制玄</h3> <ul> <li>各倀は敎数である。</li> <li><var>2 \leq n \leq 500</var></li> <li><var>1 \leq m \leq min\{5000, n(n - 1) / 2\}</var></li> <li>各<var>i=1,...,m</var>に぀いお<var>1 \leq x_i &lt; y_i \leq n</var>である。たた、<var>1 \leq i &lt; j \leq m</var>を満たす<var>i, j</var>に぀いお、<var>x_i \neq x_j</var>たたは<var>y_i \neq y_j</var>である。぀たり自己ルヌプおよび倚重蟺はない。</li> <li>各<var>i=1,...,m</var>に぀いお<var>1 \leq t_i \leq 10^8</var></li> <li><var>0 \leq v_0 \leq 49</var></li> <li><var>0 &lt; a &lt; c, 0 \leq b &lt; c, v_0 &lt; c \leq 50</var></li> <li>グラフは連結である。すなわち任意の2頂点間に経路があるこずが保蚌される。</li> </ul> <h3>出力圢匏</h3> <p>䜓感移動距離の総和の最小倀を1行に出力せよ。</p> <h3>入力䟋1</h3> <pre> 4 4 1 2 3 2 3 1 2 4 5 3 4 2 5 4 5 6 </pre> <h3>出力䟋1</h3> <pre>34</pre> <h3>入力䟋2</h3> <pre> 6 5 1 2 1 2 3 100 3 4 2 4 5 200 5 6 1 3 4 5 9 </pre> <h3>出力䟋2</h3> <pre>341</pre> <p>通過するのに時間がかかる蟺 (2,3) ず (4,5) を通る前に、短い時間で通れる道を埀埩しお、なるべく速床を萜ずした方が䜓感移動距離は短い。</p> <h3>入力䟋3</h3> <pre> 10 9 1 2 74150933 2 3 13214145 3 4 45636411 4 5 90778512 5 6 85676138 6 7 60913535 7 8 43917556 8 9 47519690 9 10 56593754 33 37 41 47 </pre> <h3>出力䟋3</h3> <pre>23049391759</pre> <p>䜓感移動距離が非垞に長くなる堎合もある。</p>
p03924
<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> towns in Takahashi Kingdom. They are conveniently numbered <var>1</var> through <var>N</var>.</p> <p>Takahashi the king is planning to go on a tour of inspection for <var>M</var> days. He will determine a sequence of towns <var>c</var>, and visit town <var>c_i</var> on the <var>i</var>-th day. That is, on the <var>i</var>-th day, he will travel from his current location to town <var>c_i</var>. If he is already at town <var>c_i</var>, he will stay at that town. His location just before the beginning of the tour is town <var>1</var>, the capital. The tour ends at town <var>c_M</var>, without getting back to the capital. </p> <p>The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town <var>a</var> to town <var>b</var>, there will be a newly paved one-way road from town <var>a</var> to town <var>b</var>.</p> <p>Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns <var>c</var> satisfy this condition?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≩N≩300</var></li> <li><var>1≩M≩300</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of sequences of towns satisfying the condition, modulo <var>1000000007 (=10^9+7)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>As shown below, the condition is satisfied only when <var>c = (2,3,1)</var> or <var>c = (3,2,1)</var>. Sequences such as <var>c = (2,3,2)</var>, <var>c = (2,1,3)</var>, <var>c = (1,2,2)</var> do not satisfy the condition.</p> <p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/199a3fd8d2aed75750901a206c8b7e76.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>150 300 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>734286322 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>300 150 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p02266
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h2>Areas on the Cross-Section Diagram</h2> <p> Your task is to simulate a flood damage. </p> <p> For a given cross-section diagram, reports areas of flooded sections. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_3_D"><br> </center> <br/> <p> Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively. </p> <h2>Input</h2> <p> A string, which represents slopes and flatlands by '<span>/</span>', '<span>\</span>' and '<span>_</span>' respectively, is given in a line. For example, the region of the above example is given by a string "<span>\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\</span>". </p> <h2>output</h2> <p> Report the areas of floods in the following format: </p> <p> $A$<br> $k$ $L_1$ $L_2$ ... $L_k$ </p> <p> In the first line, print the total area $A$ of created floods. </p> <p> In the second line, print the number of floods $k$ and areas $L_i (i = 1, 2, ..., k)$ for each flood from the left side of the cross-section diagram. Print a space character before $L_i$. </p> <h2>Constraints</h2> <ul> <li>$1 \leq$ length of the string $\leq 20,000$</li> </ul> <h2>Sample Input 1</h2> <pre> \\// </pre> <h2>Sample Output 1</h2> <pre> 4 1 4 </pre> <br/> <h2>Sample Input 2</h2> <pre> \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\ </pre> <h2>Sample Output 2</h2> <pre> 35 5 4 2 1 19 9 </pre>
p02289
<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>Priority Queue</H1> <p> A priority queue is a data structure which maintains a set $S$ of elements, each of with an associated value (key), and supports the following operations: </p> <ul> <li>$insert(S, k)$: insert an element $k$ into the set $S$</li> <li>$extractMax(S)$: remove and return the element of $S$ with the largest key</li> </ul> <p> Write a program which performs the $insert(S, k)$ and $extractMax(S)$ operations to a priority queue $S$. The priority queue manages a set of integers, which are also keys for the priority. </p> <H2>Input</H2> <p> Multiple operations to the priority queue $S$ are given. Each operation is given by "<span>insert </span>$k$", "<span>extract</span>" or "<span>end</span>" in a line. Here, $k$ represents an integer element to be inserted to the priority queue. </p> <p> The input ends with "<span>end</span>" operation. </p> <H2>Output</H2> <p> For each "<span>extract</span>" operation, print the element extracted from the priority queue $S$ in a line. </p> <H2>Constraints</H2> <ul> <li>The number of operations $\leq 2,000,000$</li> <li>$0 \leq k \leq 2,000,000,000$</li> </ul> <H2>Sample Input 1</H2> <pre> insert 8 insert 2 extract insert 10 extract insert 11 extract extract end </pre> <H2>Sample Output 1</H2> <pre> 8 10 11 2 </pre>
p02773
<span class="lang-en"> <p>Score: <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have <var>N</var> voting papers. The <var>i</var>-th vote <var>(1 \leq i \leq N)</var> has the string <var>S_i</var> written on it.</p> <p>Print all strings that are written on the most number of votes, in lexicographical order.</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_i</var> <var>(1 \leq i \leq N)</var> are strings consisting of lowercase English letters.</li> <li>The length of <var>S_i</var> <var>(1 \leq i \leq N)</var> is between <var>1</var> and <var>10</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S_1</var> <var>:</var> <var>S_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print all strings in question in lexicographical order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 beat vet beet bed vet bet beet </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>beet vet </pre> <p><code>beet</code> and <code>vet</code> are written on two sheets each, while <code>beat</code>, <code>bed</code>, and <code>bet</code> are written on one vote each. Thus, we should print the strings <code>beet</code> and <code>vet</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>buffalo </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 bass bass kick kick bass kick kick </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>kick </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 ushi tapu nichia kun </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>kun nichia tapu ushi </pre></section> </div> </span>
p03861
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given nonnegative integers <var>a</var> and <var>b</var> (<var>a ≀ b</var>), and a positive integer <var>x</var>. Among the integers between <var>a</var> and <var>b</var>, inclusive, how many are divisible by <var>x</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≀ a ≀ b ≀ 10^{18}</var></li> <li><var>1 ≀ x ≀ 10^{18}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> <var>x</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the integers between <var>a</var> and <var>b</var>, inclusive, that are divisible by <var>x</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 8 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are three integers between <var>4</var> and <var>8</var>, inclusive, that are divisible by <var>2</var>: <var>4</var>, <var>6</var> and <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> <p>There are six integers between <var>0</var> and <var>5</var>, inclusive, that are divisible by <var>1</var>: <var>0</var>, <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var> and <var>5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 9 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>There are no integer between <var>9</var> and <var>9</var>, inclusive, that is divisible by <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1000000000000000000 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>333333333333333333 </pre> <p>Watch out for integer overflows.</p></section> </div> </span>
p02323
<H1>Traveling Salesman Problem </H1> <br/> <p> For a given weighted directed graph <var>G(V, E)</var>, find the distance of the shortest route that meets the following criteria: </p> <ul> <li>It is a closed cycle where it ends at the same point it starts.</li> <li>It visits each vertex exactly once.</li> </ul> <H2>Input</H2> <pre> <var>|V|</var> <var>|E|</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>d<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>d<sub>|E|-1</sub></var> </pre> <p> <var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in the graph. The graph vertices 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 vertices of <var>i</var>-th edge (directed) and <var>d<sub>i</sub></var> represents the distance between <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> (the <var>i</var>-th edge). </p> <H2>Output</H2> <p> Print the shortest distance in a line. If there is no solution, print -1. </p> <h2>Constraints</h2> <ul> <li> 2 &le; <var>|V|</var> &le; 15</li> <li> 0 &le; <var>d<sub>i</sub></var> &le; 1,000</li> <li> There are no multiedge</li> </ul> <H2>Sample Input 1</H2> <pre> 4 6 0 1 2 1 2 3 1 3 9 2 0 1 2 3 6 3 2 4 </pre> <H2>Sample Output 1</H2> <pre> 16 </pre> <br/> <H2>Sample Input 2</H2> <pre> 3 3 0 1 1 1 2 1 0 2 1 </pre> <H2>Sample Output 2</H2> <pre> -1 </pre>
p03498
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has an integer sequence, <var>a</var>, of length <var>N</var>. The <var>i</var>-th element of <var>a</var> (<var>1</var>-indexed) is <var>a_{i}</var>.</p> <p>He can perform the following operation any number of times:</p> <ul> <li>Operation: Choose integers <var>x</var> and <var>y</var> between <var>1</var> and <var>N</var> (inclusive), and add <var>a_x</var> to <var>a_y</var>.</li> </ul> <p>He would like to perform this operation between <var>0</var> and <var>2N</var> times (inclusive) so that <var>a</var> satisfies the condition below. Show one such sequence of operations. It can be proved that such a sequence of operations always exists under the constraints in this problem.</p> <ul> <li>Condition: <var>a_1 \leq a_2 \leq ... \leq a_{N}</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 50</var></li> <li><var>-10^{6} \leq a_i \leq 10^{6}</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>a_1</var> <var>a_2</var> <var>...</var> <var>a_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Let <var>m</var> be the number of operations in your solution. In the first line, print <var>m</var>. In the <var>i</var>-th of the subsequent <var>m</var> lines, print the numbers <var>x</var> and <var>y</var> chosen in the <var>i</var>-th operation, with a space in between. The output will be considered correct if <var>m</var> is between <var>0</var> and <var>2N</var> (inclusive) and <var>a</var> satisfies the condition after the <var>m</var> operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 -2 5 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 2 3 3 3 </pre> <ul> <li>After the first operation, <var>a = (-2,5,4)</var>.</li> <li>After the second operation, <var>a = (-2,5,8)</var>, and the condition is now satisfied.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 -1 -3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 1 </pre> <ul> <li>After the first operation, <var>a = (-4,-3)</var> and the condition is now satisfied.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 0 0 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <ul> <li>The condition is satisfied already in the beginning.</li> </ul></section> </div> </span>
p03162
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.</p> <p>The vacation consists of <var>N</var> days. For each <var>i</var> (<var>1 \leq i \leq N</var>), Taro will choose one of the following activities and do it on the <var>i</var>-th day:</p> <ul> <li>A: Swim in the sea. Gain <var>a_i</var> points of happiness.</li> <li>B: Catch bugs in the mountains. Gain <var>b_i</var> points of happiness.</li> <li>C: Do homework at home. Gain <var>c_i</var> points of happiness.</li> </ul> <p>As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.</p> <p>Find the maximum possible total points of happiness that Taro gains.</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, b_i, c_i \leq 10^4</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> <var>a_2</var> <var>b_2</var> <var>c_2</var> <var>:</var> <var>a_N</var> <var>b_N</var> <var>c_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible total points of happiness that Taro gains.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 10 40 70 20 50 80 30 60 90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>210 </pre> <p>If Taro does activities in the order C, B, C, he will gain <var>70 + 50 + 90 = 210</var> points of happiness.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 100 10 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>100 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 6 7 8 8 8 3 2 5 2 7 8 6 4 6 8 2 3 4 7 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>46 </pre> <p>Taro should do activities in the order C, A, B, A, C, B, A.</p></section> </div> </span>
p03532
<span class="lang-en"> <p>Score : <var>1900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ringo has a tree with <var>N</var> vertices. The <var>i</var>-th of the <var>N-1</var> edges in this tree connects Vertex <var>A_i</var> and Vertex <var>B_i</var> and has a weight of <var>C_i</var>. Additionally, Vertex <var>i</var> has a weight of <var>X_i</var>.</p> <p>Here, we define <var>f(u,v)</var> as the distance between Vertex <var>u</var> and Vertex <var>v</var>, plus <var>X_u + X_v</var>.</p> <p>We will consider a complete graph <var>G</var> with <var>N</var> vertices. The cost of its edge that connects Vertex <var>u</var> and Vertex <var>v</var> is <var>f(u,v)</var>. Find the minimum spanning tree of <var>G</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200,000</var></li> <li><var>1 \leq X_i \leq 10^9</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li><var>1 \leq C_i \leq 10^9</var></li> <li>The given graph is a tree.</li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>A_2</var> <var>B_2</var> <var>C_2</var> <var>:</var> <var>A_{N-1}</var> <var>B_{N-1}</var> <var>C_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the cost of the minimum spanning tree of <var>G</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 3 5 1 1 2 1 2 3 2 3 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>22 </pre> <p>We connect the following pairs: Vertex <var>1</var> and <var>2</var>, Vertex <var>1</var> and <var>4</var>, Vertex <var>3</var> and <var>4</var>. The costs are <var>5</var>, <var>8</var> and <var>9</var>, respectively, for a total of <var>22</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 44 23 31 29 32 15 1 2 10 1 3 12 1 4 16 4 5 8 4 6 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>359 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1000000000 1000000000 2 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3000000000 </pre></section> </div> </span>
p01221
<H1><font color="#000">Problem F:</font> Two-finger Programming</H1> <p> Franklin Jenkins is a programmer, but he isn’t good at typing keyboards. So he always uses only ‘f’ and ‘j’ (keys on the home positions of index fingers) for variable names. He insists two characters are enough to write programs, but naturally his friends don’t agree with him: they say it makes programs too long. </p> <p> He asked you to show any program can be converted into not so long one with the <i>f-j names</i>. Your task is to answer the shortest length of the program after all variables are renamed into the f-j names, for each given program. </p> <p> Given programs are written in the language specified below. </p> <p> A block (a region enclosed by curly braces: ‘{’ and ‘}’) forms a scope for variables. Each scope can have zero or more scopes inside. The whole program also forms the global scope, which contains all scopes on the top level (i.e., out of any blocks). </p> <p> Each variable belongs to the innermost scope which includes its declaration, and is valid from the decla- ration to the end of the scope. Variables are never redeclared while they are valid, but may be declared again once they have become invalid. The variables that belong to different scopes are regarded as differ- ent even if they have the same name. Undeclared or other invalid names never appear in expressions. </p> <p> The tokens are defined by the rules shown below. All whitespace characters (spaces, tabs, linefeeds, and carrige-returns) before, between, and after tokens are ignored. </p> <pre> <i>token</i>: <i>identifier</i> | <i>keyword</i> | <i>number</i> | <i>operator</i> | <i>punctuation</i> <i>identifier</i>: [a-z]+ (one or more lowercase letters) <i>keyword</i>: [A-Z]+ (one or more uppercase letters) <i>number</i>: [0-9]+ (one or more digits) <i>operator</i>: ‘=’ | ‘+’ | ‘-’ | ‘*’ | ‘/’ | ‘&’ | ‘|’ | ‘^’ | ‘<’ | ‘>’ <i>punctuation</i>: ‘{’ | ‘}’ | ‘(’ | ‘)’ | ‘;’ </pre> <p> The syntax of the language is defined as follows. </p> <pre> <i>program</i>: <i>statement-list</i> <i>statement-list</i>: <i>statement</i> <i>statement-list statement</i> <i>statement</i>: <i>variable-declaration</i> <i>if-statement</i> <i>while-statement</i> <i>expression-statement</i> <i>block-statement</i> <i>variable-declaration</i>: “VAR” <i>identifier</i> ‘;’ <i>if-statement</i>: “IF” ‘(’ <i>expression</i> ‘)’ <i>block-statement</i> <i>while-statement</i>: “WHILE” ‘(’ <i>expression</i> ‘)’ <i>block-statement</i> <i>expression-statement</i>: <i>expression</i> ‘;’ <i>block-statement</i>: ‘{’ <i>statement-listoptional</i> ‘}’ <i>expression</i>: <i>identifier</i> <i>number</i> <i>expression operator expression</i> </pre> <H2>Input</H2> <p> The input consists of multiple data sets. </p> <p> Each data set gives a well-formed program according to the specification above. The first line contains a positive integer <i>N</i>, which indicates the number of lines in the program. The following <i>N</i> lines contain the program body. </p> <p> There are no extra characters between two adjacent data sets. </p> <p> A single line containing a zero indicates the end of the input, and you must not process this line as part of any data set. </p> <p> Each line contains up to 255 characters, and all variable names are equal to or less than 16 characters long. No program contains more than 1000 variables nor 100 scopes (including the global scope). </p> <H2>Output</H2> <p> For each data set, output in one line the minimum program length after all the variables are renamed into the f-j name. Whitespace characters must not counted for the program length. You are not allowed to perform any operations on the programs other than renaming the variables. </p> <H2>Sample Input</H2> <pre> 14 VAR ga; VAR gb; IF(ga > gb) { VAR saa; VAR sab; IF(saa > ga) { saa = sab; } } WHILE(gb > ga) { VAR sba; sba = ga; ga = gb; } 7 VAR thisisthelongest; IF(thisisthelongest / 0) { VARone; one = thisisthelongest + 1234567890123456789012345; } VAR another; 32 = another; 0 </pre> <H2>Output for the Sample Input</H2> <pre> 73 59 </pre> <br><br> <p>The two programs should be translated as follows:</p> <pre> VAR f; VAR ff; IF(f > ff) { VAR j; VAR fj; IF(j > f) { j = fj; } } WHILE(ff > f) { VAR j; j = f; f = ff; } VAR j; IF(j / 0) { VARf; f = j + 1234567890123456789012345; } VAR f; 32 = f; </pre>
p04023
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got an integer sequence from his mother, as a birthday present. The sequence has <var>N</var> elements, and the <var>i</var>-th of them is <var>i</var>. Snuke performs the following <var>Q</var> operations on this sequence. The <var>i</var>-th operation, described by a parameter <var>q_i</var>, is as follows:</p> <ul> <li>Take the first <var>q_i</var> elements from the sequence obtained by concatenating infinitely many copy of the current sequence, then replace the current sequence with those <var>q_i</var> elements.</li> </ul> <p>After these <var>Q</var> operations, find how many times each of the integers <var>1</var> through <var>N</var> appears in the final sequence.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ N ≩ 10^5</var></li> <li><var>0 ≩ Q ≩ 10^5</var></li> <li><var>1 ≩ q_i ≩ 10^{18}</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>q_1</var> : <var>q_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line <var>(1 ≩ i ≩ N)</var> should contain the number of times integer <var>i</var> appears in the final sequence after the <var>Q</var> operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 6 4 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 3 3 2 0 </pre> <p>After the first operation, the sequence becomes: <var>1,2,3,4,5,1</var>.</p> <p>After the second operation, the sequence becomes: <var>1,2,3,4</var>.</p> <p>After the third operation, the sequence becomes: <var>1,2,3,4,1,2,3,4,1,2,3</var>.</p> <p>In this sequence, integers <var>1,2,3,4,5</var> appear <var>3,3,3,2,0</var> times, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 10 9 13 18 8 10 10 9 19 22 27 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 4 4 3 3 2 2 2 0 0 </pre></section> </div> </span>
p00963
<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 G Rendezvous on a Tetrahedron </h2> <p> One day, you found two worms $P$ and $Q$ crawling on the surface of a regular tetrahedron with four vertices $A$, $B$, $C$ and $D$. Both worms started from the vertex $A$, went straight ahead, and stopped crawling after a while. </p> <p> When a worm reached one of the edges of the tetrahedron, it moved on to the adjacent face and kept going without changing the angle to the crossed edge (Figure G.1). </p> <p> Write a program which tells whether or not $P$ and $Q$ were on the same face of the tetrahedron when they stopped crawling. </p> <p> You may assume that each of the worms is a point without length, area, or volume. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_tetrahedron1" width="480"> <p> Figure G.1. Crossing an edge</p> </center> <p> Incidentally, lengths of the two trails the worms left on the tetrahedron were exact integral multiples of the unit length. Here, the unit length is the edge length of the tetrahedron. Each trail is more than 0:001 unit distant from any vertices, except for its start point and its neighborhood. This means that worms have crossed at least one edge. Both worms stopped at positions more than 0:001 unit distant from any of the edges. </p> <p> The initial crawling direction of a worm is specified by two items: the edge $XY$ which is the first edge the worm encountered after its start, and the angle $d$ between the edge $AX$ and the direction of the worm, in degrees. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_tetrahedron2" width="480"> <p>Figure G.2. Trails of the worms corresponding to Sample Input 1</p> </center> <p> Figure G.2 shows the case of Sample Input 1. In this case, $P$ went over the edge $CD$ and stopped on the face opposite to the vertex $A$, while $Q$ went over the edge $DB$ and also stopped on the same face. </p> <h3>Input</h3> <p> The input consists of a single test case, formatted as follows. </p> <pre> $X_PY_P$ $d_P$ $l_P$ $X_QY_Q$ $d_Q$ $l_Q$ </pre> <p> $X_WY_W$ ($W = P,Q$) is the first edge the worm $W$ crossed after its start. $X_WY_W$ is one of <span>BC</span>, <span>CD</span> or <span>DB</span>. </p> <p> An integer $d_W$ ($1 \leq d_W \leq 59$) is the angle in degrees between edge $AX_W$ and the initial direction of the worm $W$ on the face $\triangle AX_WY_W$. </p> <p> An integer $l_W$ ($1 \leq l_W \leq 20$) is the length of the trail of worm $W$ left on the surface, in unit lengths. </p> <h3>Output</h3> <p> Output <span>YES</span> when and only when the two worms stopped on the same face of the tetrahedron. Otherwise, output <span>NO</span>. </p> <h3>Sample Input 1</h3> <pre> CD 30 1 DB 30 1 </pre> <h3>Sample Output 1</h3> <pre> YES </pre> <h3>Sample Input 2</h3> <pre> BC 1 1 DB 59 1 </pre> <h3>Sample Output 2</h3> <pre> YES </pre> <h3>Sample Input 3</h3> <pre> BC 29 20 BC 32 20 </pre> <h3>Sample Output 3</h3> <pre> NO </pre>
p01671
<h2>E - Minimum Spanning Tree</h2> <h3>Problem Statement</h3> <p> You are given an undirected weighted graph <var>G</var> with <var>n</var> nodes and <var>m</var> edges. Each edge is numbered from <var>1</var> to <var>m</var>. </p> <p> Let <var>G_i</var> be an graph that is made by erasing <var>i</var>-th edge from <var>G</var>. Your task is to compute the cost of minimum spanning tree in <var>G_i</var> for each <var>i</var>. </p> <h3>Input</h3> <p> The dataset is formatted as follows. </p> <pre> <var>n</var> <var>m</var> <var>a_1</var> <var>b_1</var> <var>w_1</var> ... <var>a_m</var> <var>b_m</var> <var>w_m</var> </pre> <p> The first line of the input contains two integers <var>n</var> (<var>2 \leq n \leq 100{,}000</var>) and <var>m</var> (<var>1 \leq m \leq 200{,}000</var>). <var>n</var> is the number of nodes and <var>m</var> is the number of edges in the graph. Then <var>m</var> lines follow, each of which contains <var>a_i</var> (<var>1 \leq a_i \leq n</var>), <var>b_i</var> (<var>1 \leq b_i \leq n</var>) and <var>w_i</var> (<var>0 \leq w_i \leq 1{,}000{,}000</var>). This means that there is an edge between node <var>a_i</var> and node <var>b_i</var> and its cost is <var>w_i</var>. It is guaranteed that the given graph is simple: That is, for any pair of nodes, there is at most one edge that connects them, and <var>a_i \neq b_i</var> for all <var>i</var>. </p> <h3>Output</h3> <p> Print the cost of minimum spanning tree in <var>G_i</var> for each <var>i</var>, in <var>m</var> line. If there is no spanning trees in <var>G_i</var>, print "-1" (quotes for clarity) instead. </p> <h3>Sample Input 1</h3> <pre> 4 6 1 2 2 1 3 6 1 4 3 2 3 1 2 4 4 3 4 5 </pre> <h3>Output for the Sample Input 1</h3> <pre> 8 6 7 10 6 6 </pre> <h3>Sample Input 2</h3> <pre> 4 4 1 2 1 1 3 10 2 3 100 3 4 1000 </pre> <h3>Output for the Sample Input 2</h3> <pre> 1110 1101 1011 -1 </pre> <h3>Sample Input 3</h3> <pre> 7 10 1 2 1 1 3 2 2 3 3 2 4 4 2 5 5 3 6 6 3 7 7 4 5 8 5 6 9 6 7 10 </pre> <h3>Output for the Sample Input 3</h3> <pre> 27 26 25 29 28 28 28 25 25 25 </pre> <h3>Sample Input 4</h3> <pre> 3 1 1 3 999 </pre> <h3>Output for the Sample Input 4</h3> <pre> -1 </pre>
p00430
<H1></H1> <p> 同じ倧きさの正方圢の玙が <i>n</i> 枚ある.これらの玙の䞋郚を氎平に揃えお䜕列かに䞊べる.ただし,隣り合う列は巊偎が右偎より䜎くならないように䞊べなければならない.䟋えば, <i>n</i> = 5 のずきは,次のような 7 通りの䞊べ方が可胜である. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ioi2006ho3"> </center> <br> <p> これらを,各列に䞊んだ正方圢の個数の列で衚すこずにする.䟋えば, <i>n</i> = 5 の ずきは,それぞれ,<br> <br> (5) (4, 1) (3, 2) (3, 1, 1) (2, 2, 1) (2, 1, 1, 1) (1, 1, 1, 1, 1)<br> <br> ず衚わされる. </p> <p> <i>n</i> を入力したずき, 蟞曞匏順序で党お出力するプログラムを䜜成せよ.<i>n</i> &le;30 ずする.ただし, 蟞曞匏順序ずは2぀の䞊べ方 (<i>a</i><sub>1</sub>, <i>a</i><sub>2</sub> , ..., <i>a</i><sub><i>s</i></sub>) が䞊べ方 (<i>b</i><sub>1</sub>, <i>b</i><sub>2</sub>, ..., <i>b<sub>t</sub></i> ) に察しお, <i>a</i><sub>1</sub> &gt; <i>b</i><sub>1</sub> たたは, ある敎数 <i>i</i> &gt; 1 が存圚しお <i>a</i><sub>1</sub> = <i>b</i><sub>1</sub> , ..., <i>a</i><sub><i>i</i>-1</sub> = <i>b</i><sub><i>i</i>-1</sub> か぀ <i>a<sub>i</sub></i> &gt; <i>b<sub>i</sub></i> が成り立぀ずき (<i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, ..., <i>a<sub>s</sub></i>) が (<i>b</i><sub>1</sub> , <i>b</i><sub>2</sub>, ..., <i>b<sub>t</sub></i>) より先に出力されるように䞊べるこずである. </p> <!-- <p> 入力ファむルのファむル名は “input.txt” である.“input.txt” は 1 行からなり,1 行目に <i>n</i> が曞かれおいる. </p> <p> 出力ファむルのファむル名は “output.txt” である.“output.txt” には䞊べ方を蟞曞匏順序で 1 行に1通りず぀曞き最埌に改行を入れるこず. 䞊べ方は (<i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, ..., <i>a<sub>s</sub></i>) の出力は敎数 <i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, . . . , <i>a<sub>s</sub></i> をこの順番に空癜で区切っお出力するこず. </p> --> <p> 入力デヌタ は 1 行からなり,1 行目に <i>n</i> が曞かれおいる. </p> <p> 出力には䞊べ方を蟞曞匏順序で 1 行に1通りず぀曞き最埌に改行を入れるこず. 䞊べ方は (<i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, ..., <i>a<sub>s</sub></i>) の出力は敎数 <i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, . . . , <i>a<sub>s</sub></i> をこの順番に空癜で区切っお出力するこず. </p> <table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;"> <tr> <th width="150" align="left">入力䟋</th> </tr> <tr><td></td></tr> <tr><td>5</td></tr> <tr> <td> </td> </tr> <tr> <th width="150" align="left">出力䟋</th> </tr> <tr> <td>5<br> 4 1<br> 3 2<br> 3 1 1<br> 2 2 1<br> 2 1 1 1<br> 1 1 1 1 1<br> </td> </tr> </table> <h3>入力</h3> <p> 入力は耇数のデヌタセットからなるn が 0 のずき入力が終了するデヌタセットの数は 5 を超えない </p> <h3>出力</h3> <p> デヌタセットごずに、蟞曞匏順序で党お出力する </p> <H2>入力䟋</H2> <pre> 5 5 0 </pre> <H2>出力䟋</H2> <pre> 5 4 1 3 2 3 1 1 2 2 1 2 1 1 1 1 1 1 1 1 5 4 1 3 2 3 1 1 2 2 1 2 1 1 1 1 1 1 1 1 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00060
<H1>カヌドゲヌ ム</H1> <p> 「1」から「10」たでの数字が曞かれたカヌドが各 1 枚、党郚で 10 枚ありたす。このカヌドは、衚偎には数字が曞かれ、裏偎には䜕も曞かれおいたせん。このカヌドを䜿っお、あなたず盞手の 2 名で以䞋のルヌルでゲヌ ムを行いたす。 </p> <ol> <li> あなたず盞手には、衚を䞊にしお 1 枚、裏を䞊にしお 1 枚、蚈 2 枚のカヌドが配られおいたす。あなたは盞手の衚のカヌドの数字を芋るこずができたすが、裏のカヌドの数字は芋えたせん。 </li> <li> 配られたカヌドの数字の合蚈が 20 以䞋で、か぀盞手の数字の合蚈より倧きいずきに勝ちずなりたす。 䟋えば、あなたのカヌドが「7」「8」 (合蚈 15) 、盞手のカヌドが「9」「10」 (合蚈 19) のずきは、盞手の勝ちです。 </li> <li> あなたず盞手は最倧であず 1 枚カヌドを匕くこずができたす。それを匕かなくおも構いたせん。 </li> </ol> <p> ここで、あず 1 枚のカヌドを匕くかどうかを決定する目安ずしお、カヌドを匕いたずきに合蚈が 20 以䞋に なる確率を考え、その確率が 50% 以䞊のずきはカヌドを匕くこずずしたしょう。この確率を蚈算するずきには、あなたの 2 枚のカヌドず盞手の衚のカヌドの蚈3枚のカヌドの情報を利甚するこずができたす。぀たり、各カヌドは 1 枚ず぀しかないので、それらのカヌドを匕くこずはないこずになりたす。 </p> <p> あなたの 2 枚のカヌドず盞手の衚のカヌドを読み蟌んで、それぞれに぀いお、あず 1 枚匕いたずきに合蚈が 20 以䞋になる確率が 50% 以䞊のずきは YES、そうでないなら NO を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなりたす。 1 枚目のあなたのカヌドの数字を C1 、2 枚目のあなたのカヌドの数字を C2 、盞手の衚になっおいるカヌドの数字を C3 ずするず、各デヌタセットは以䞋の圢匏で䞎えられたす。 <pre> C1 C2 C3 </pre> <H2>Output</H2> <p> 各デヌタセットに察しお、<span>YES</span> たたは <span>NO</span> を行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 1 2 3 5 6 9 8 9 10 </pre> <H2>Output for the Sample Input</H2> <pre> YES YES NO </pre>
p00575
<h1>゜ヌシャルゲヌム (Social Game)</h1> <!--  時間制限 : 2sec / メモリ制限 : 256MB--> <h2> 問題文</h2> <p> JOI 君は明日から新たに゜ヌシャルゲヌムを始めるこずにした </p> <p> この゜ヌシャルゲヌムでは<var>1</var> 日に぀き <var>1</var> 回たでログむンするこずができログむンするたびに <var>A</var> 枚のコむンが埗られる </p> <p> たた月曜日から日曜日たで <var>7</var> 日連続でログむンするずそのたびに远加で <var>B</var> 枚のコむンが埗られる </p> <p> これ以倖にコむンがもらえるこずはない </p> <p> 明日は月曜日であるJOI 君が少なくずも <var>C</var> 枚のコむンを埗るためにログむンしなければならない回数の最小倀を求めよ </p> <h2> 制玄</h2> <ul> <li><var>1 ≩ A ≩ 1000</var></li> <li><var>0 ≩ B ≩ 1000</var></li> <li><var>1 ≩ C ≩ 1000000 (= 10^6)</var></li> </ul> <h2> 入力・出力</h2> <p> <b>入力</b><br> 入力は以䞋の圢匏で暙準入力から䞎えられる<br> <var>A</var> <var>B</var> <var>C</var> </p> <p> <b>出力</b><br> JOI 君が少なくずも <var>C</var> 枚のコむンを埗るためにログむンしなければならない回数の最小倀を出力せよ </p> <!-- <h2> 小課題</h2> <p style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> </p> <p style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <li>(<var>40</var> 点) <var>B = 0</var></li> <li>(<var>60</var> 点) 远加の制玄はない</li> </ol> </p> --> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 3 0 10 </pre> <h3>出力䟋 1</h3> <pre> 4 </pre> <ul> <li><var>1</var> 回のログむンあたり <var>3</var> 枚のコむンが埗られ<var>10</var> 枚のコむンを集めたい</li> <li>JOI 君は月曜日から連続 <var>4</var> 日間ログむンするこずで <var>12</var> 枚のコむンが埗られる</li> <li><var>3</var> 回以䞋のログむンで <var>10</var> 枚以䞊のコむンを埗るこずはできないのでJOI 君がログむンしなければならない回数の最小倀は <var>4</var> である埓っお<var>4</var> を出力する</li> </ul> </p> <h3>入力䟋 2</h3> <pre> 1 2 10 </pre> <h3>出力䟋 2</h3> <pre> 8 </pre> <ul> <li><var>1</var> 回のログむンあたり <var>1</var> 枚のコむンが埗られるそれずは別に1 週間連続でログむンするこずで <var>2</var> 枚のコむンが埗られる<var>10</var> 枚のコむンを集めたい</li> <li>月曜日から日曜日たで連続でログむンするず日々のコむン <var>7</var> 枚に加えお<var>2</var> 枚のコむンが埗られるため合蚈 <var>9</var> 枚のコむンが埗られる埓っお曎にもう <var>1</var> 回ログむンするこずにより<var>10</var> 枚のコむンが埗られる</li> <li><var>7</var> 回以䞋のログむンで <var>10</var> 枚以䞊のコむンを埗るこずはできないのでJOI 君がログむンしなければならない回数の最小倀は <var>8</var> である埓っお<var>8</var> を出力する</li> </ul> <br/> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2018/2019-yo/index.html">情報オリンピック日本委員䌚䜜 『第 18 回日本情報オリンピック JOI 2018/2019 予遞競技課題』</a> </p> </div>
p02548
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a positive integer <var>N</var>. How many tuples <var>(A,B,C)</var> of positive integers satisfy <var>A \times B + C = N</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var> 2 \leq N \leq 10^6</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</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>3 </pre> <p>There are <var>3</var> tuples of integers that satisfy <var>A \times B + C = 3</var>: <var>(A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>473 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>13969985 </pre></section> </div> </span>
p00125
<h1>日数</h1> <p> 2 ぀の日付を入力ずし、その 2 ぀の日付けの間の日数を出力するプログラムを䜜成しおください。 </p> <p> 日付 1 (<var>y<sub>1</sub>, m<sub>1</sub>, d<sub>1</sub></var>) は日付 2 (<var>y<sub>2</sub>, m<sub>2</sub>, d<sub>2</sub></var>) ず同じか、あるいはそれ以前の日付ずしたす。日付 1 は日数に含め、日付 2 は含めたせん。たた、うるう幎を考慮にいれお蚈算しおください。うるう幎の条件は次のずおりずしたす。 </p> <ul> <li>西暊幎が 4 で割り切れる幎であるこず。</li> <li>ただし、100 で割り切れる幎はうるう幎ずしない。</li> <li>しかし、400 で割り切れる幎はうるう幎である。</li> </ul> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットの圢匏は以䞋のずおりです </p> <pre> <var>y<sub>1</sub></var> <var>m<sub>1</sub></var> <var>d<sub>1</sub></var> <var>y<sub>2</sub></var> <var>m<sub>2</sub></var> <var>d<sub>2</sub></var> </pre> <p> <var>y<sub>1</sub></var>, <var>m<sub>1</sub></var>, <var>d<sub>1</sub></var>, <var>y<sub>2</sub></var>, <var>m<sub>2</sub></var>, <var>d<sub>2</sub></var> のいずれかが負の数のずき入力の終わりずしたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、日数を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 2006 9 2 2006 9 3 2006 9 2 2006 11 11 2004 1 1 2005 1 1 2000 1 1 2006 1 1 2000 1 1 2101 1 1 -1 -1 -1 -1 -1 -1 </pre> <H2>Output for the Sample Input</H2> <pre> 1 70 366 2192 36890 </pre>
p02118
<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>Problem H: Sequence</h1> <h2>Problem</h2> <p>項数$L$の等差数列が$N$個ある。$i$番目の等差数列の初項は$a_i$で公差は$d_i$である。1番目の数列から順番に1番目の数列, 2番目の数列, ..., $N$番目の数列ず䞊べ、そうしおできた数列を$A$ずする。その埌、$A$から長さ$K$の任意の区間を遞んで、新たに数列$B$を䜜るずき、数列$B$の和を最倧化せよ。</p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <p> $N$ $L$ $K$<br> $a_1$ $d_1$<br> $a_2$ $d_2$<br> ...<br> $a_N$ $d_N$<br> </p> <p> 1行目に3぀の敎数$N$, $L$, $K$が空癜区切りで䞎えられる。<br> 続く$N$行に、$i$個目の等差数列の情報$a_i$, $d_i$が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq N \leq 10^5$</li> <li>$1 \leq L \leq 10^5$</li> <li>$1 \leq K \leq N\times L$</li> <li>$0 \leq a_i \leq 10^5$</li> <li>$1 \leq d_i \leq 10^3$</li> <li>入力はすべお敎数</li> </ul> <h2>Output</h2> <p> 数列$B$の和の最倧倀を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 3 3 5 0 3 2 2 4 1 </pre> <h2>Sample Output 1</h2> <pre> 25 </pre> <p>数列$A$は$0,3,6,2,4,6,4,5,6$ずなる。この数列の第5項から第9項たでを数列$B$ずすれば、数列$B$の和は25ずなり、これが最倧である。</p> <h2>Sample Input 2</h2> <pre> 3 3 5 0 10 8 1 11 1 </pre> <h2>Sample Output 2</h2> <pre> 58 </pre>
p03359
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.<br/> For example, May <var>3</var>, <var>2018</var> is written as <var>2018</var>-<var>5</var>-<var>3</var>, or <var>5</var>-<var>3</var> without the year. </p> <p>In this country, a date is called <em>Takahashi</em> when the month and the day are equal as numbers. For example, <var>5</var>-<var>5</var> is Takahashi.<br/> How many days from <var>2018</var>-<var>1</var>-<var>1</var> through <var>2018</var>-<var>a</var>-<var>b</var> are Takahashi?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>a</var> is an integer between <var>1</var> and <var>12</var> (inclusive).</li> <li><var>b</var> is an integer between <var>1</var> and <var>31</var> (inclusive).</li> <li><var>2018</var>-<var>a</var>-<var>b</var> is a valid date in Gregorian calendar.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of days from <var>2018</var>-<var>1</var>-<var>1</var> through <var>2018</var>-<var>a</var>-<var>b</var> that are Takahashi.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are five days that are Takahashi: <var>1</var>-<var>1</var>, <var>2</var>-<var>2</var>, <var>3</var>-<var>3</var>, <var>4</var>-<var>4</var> and <var>5</var>-<var>5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>There is only one day that is Takahashi: <var>1</var>-<var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>11 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>11 </pre> <p>There are eleven days that are Takahashi: <var>1</var>-<var>1</var>, <var>2</var>-<var>2</var>, <var>3</var>-<var>3</var>, <var>4</var>-<var>4</var>, <var>5</var>-<var>5</var>, <var>6</var>-<var>6</var>, <var>7</var>-<var>7</var>, <var>8</var>-<var>8</var>, <var>9</var>-<var>9</var>, <var>10</var>-<var>10</var> and <var>11</var>-<var>11</var>.</p></section> </div> </span>
p01364
<H1><font color="#000">Problem F:</font> Two-Wheel Buggy</H1> <p> International Car Production Company (ICPC), one of the largest automobile manufacturers in the world, is now developing a new vehicle called "Two-Wheel Buggy". As its name suggests, the vehicle has only two wheels. Quite simply, "Two-Wheel Buggy" is made up of two wheels (the left wheel and the right wheel) and a axle (a bar connecting two wheels). The figure below shows its basic structure. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_buggy1" width="20%"> <p> Figure 7: The basic structure of the buggy </p> </center> <p> Before making a prototype of this new vehicle, the company decided to run a computer simula- tion. The details of the simulation is as follows. </p> <p> In the simulation, the buggy will move on the x-y plane. Let <i>D</i> be the distance from the center of the axle to the wheels. At the beginning of the simulation, the center of the axle is at (0, 0), the left wheel is at (-<i>D</i>, 0), and the right wheel is at (<i>D</i>, 0). The radii of two wheels are 1. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_buggy2" width="40%"> <p> Figure 8: The initial position of the buggy </p> </center> <p> The movement of the buggy in the simulation is controlled by a sequence of instructions. Each instruction consists of three numbers, <i>Lspeed</i>, <i>Rspeed</i> and <i>time</i>. <i>Lspeed</i> and <i>Rspeed</i> indicate the rotation speed of the left and right wheels, respectively, expressed in degree par second. time indicates how many seconds these two wheels keep their rotation speed. If a speed of a wheel is positive, it will rotate in the direction that causes the buggy to move forward. Conversely, if a speed is negative, it will rotate in the opposite direction. For example, if we set <i>Lspeed</i> as -360, the left wheel will rotate 360-degree in one second in the direction that makes the buggy move backward. We can set Lspeed and Rspeed differently, and this makes the buggy turn left or right. Note that we can also set one of them positive and the other negative (in this case, the buggy will spin around). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_buggy3" width="40%"> <p> Figure 9: Examples </p> </center> <p> Your job is to write a program that calculates the final position of the buggy given a instruction sequence. For simplicity, you can can assume that wheels have no width, and that they would never slip. </p> <H2>Input</H2> <p> The input consists of several datasets. Each dataset is formatted as follows. </p> <p> <i>N D</i><br> <i>Lspeed</i><sub>1</sub> <i>Rspeed</i><sub>1</sub> <i>time</i><sub>1</sub><br> .<br> .<br> .<br> <i>Lspeed<sub>i</sub></i> <i>Rspeed<sub>i</sub></i> <i>time<sub>i</sub></i><br> .<br> .<br> .<br> <i>Lspeed<sub>N</sub></i> <i>Rspeed<sub>N</sub></i> <i>time<sub>N</sub></i><br> </p> <p> The first line of a dataset contains two positive integers, <i>N</i> and <i>D</i> (1 &le; <i>N</i> &le; 100, 1 &le; <i>D</i> &le; 10). <i>N</i> indicates the number of instructions in the dataset, and <i>D</i> indicates the distance between the center of axle and the wheels. The following <i>N</i> lines describe the instruction sequence. The <i>i</i>-th line contains three integers, <i>Lspeed<sub>i</sub></i>, <i.Rspeed<sub>i</sub></i>, and <i>time<sub>i</sub></i> (-360 &le; <i>Lspeed<sub>i</sub></i>, <i>Rspeed<sub>i</sub></i> &le; 360, 1 &le; <i>time<sub>i</sub></i> ), describing the <i>i</i>-th instruction to the buggy. You can assume that the sum of timei is at most 500. </p> <p> The end of input is indicated by a line containing two zeros. This line is not part of any dataset and hence should not be processed. </p> <H2>Output</H2> <p> For each dataset, output two lines indicating the final position of the center of the axle. The first line should contain the <i>x</i>-coordinate, and the second line should contain the <i>y</i>-coordinate. The absolute error should be less than or equal to 10<sup>-3</sup> . No extra character should appear in the output. </p> <H2>Sample Input</H2> <pre> 1 1 180 90 2 1 1 180 180 20 2 10 360 -360 5 -90 360 8 3 2 100 60 9 -72 -72 10 -45 -225 5 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3.00000 3.00000 0.00000 62.83185 12.00000 0.00000 -2.44505 13.12132 </pre>
p00826
<H1><font color="#000">Problem H:</font> Monster Trap</H1> <p> Once upon a time when people still believed in magic, there was a great wizard Aranyaka Gondlir. After twenty years of hard training in a deep forest, he had finally mastered ultimate magic, and decided to leave the forest for his home. </p> <p> Arriving at his home village, Aranyaka was very surprised at the extraordinary desolation. A gloom had settled over the village. Even the whisper of the wind could scare villagers. It was a mere shadow of what it had been. </p> <p> What had happened? Soon he recognized a sure sign of an evil monster that is immortal. Even the great wizard could not kill it, and so he resolved to seal it with magic. Aranyaka could cast a spell to create a monster trap: once he had drawn a line on the ground with his magic rod, the line would function as a barrier wall that any monster could not get over. Since he could only draw straight lines, he had to draw several lines to complete a monster trap, i.e., magic barrier walls enclosing the monster. If there was a gap between barrier walls, the monster could easily run away through the gap. </p> <p> For instance, a complete monster trap without any gaps is built by the barrier walls in the left figure, where “M” indicates the position of the monster. In contrast, the barrier walls in the right figure have a loophole, even though it is almost complete. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_monsterTrap"> </center> <p> Your mission is to write a program to tell whether or not the wizard has successfully sealed the monster. </p> <H2>Input</H2> <p> The input consists of multiple data sets, each in the following format. </p> <pre> <i>n</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x'</i><sub>1</sub> <i>y'</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>x'</i><sub>2</sub> <i>y'</i><sub>2</sub> ... <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>x'</i><sub><i>n</i></sub> <i>y'</i><sub><i>n</i></sub> </pre> <p> The first line of a data set contains a positive integer n, which is the number of the line segments drawn by the wizard. Each of the following <i>n</i> input lines contains four integers <i>x</i>, <i>y</i>, <i>x'</i>, and <i>y'</i>, which represent the <i>x</i>- and <i>y</i>-coordinates of two points (<i>x</i>, <i>y</i>) and (<i>x'</i>, <i>y'</i> ) connected by a line segment. You may assume that all line segments have non-zero lengths. You may also assume that <i>n</i> is less than or equal to 100 and that all coordinates are between -50 and 50, inclusive. </p> <p> For your convenience, the coordinate system is arranged so that the monster is always on the origin (0, 0). The wizard never draws lines crossing (0, 0). </p> <p> You may assume that any two line segments have at most one intersection point and that no three line segments share the same intersection point. You may also assume that the distance between any two intersection points is greater than 10<sup>-5</sup>. </p> <p> An input line containing a zero indicates the end of the input. </p> <H2>Output</H2> <p> For each data set, print “yes” or “no” in a line. If a monster trap is completed, print “yes”. Otherwise, i.e., if there is a loophole, print “no”. </p> <H2>Sample Input</H2> <pre> 8 -7 9 6 9 -5 5 6 5 -10 -5 10 -5 -6 9 -9 -6 6 9 9 -6 -1 -2 -3 10 1 -2 3 10 -2 -3 2 -3 8 -7 9 5 7 -5 5 6 5 -10 -5 10 -5 -6 9 -9 -6 6 9 9 -6 -1 -2 -3 10 1 -2 3 10 -2 -3 2 -3 0 </pre> <H2>Output for the Sample Input</H2> <pre> yes no </pre>
p03709
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is an expert of Clone Jutsu, a secret art that creates copies of his body.</p> <p>On a number line, there are <var>N</var> copies of Takahashi, numbered <var>1</var> through <var>N</var>. The <var>i</var>-th copy is located at position <var>X_i</var> and starts walking with velocity <var>V_i</var> in the positive direction at time <var>0</var>.</p> <p>Kenus is a master of Transformation Jutsu, and not only can he change into a person other than himself, but he can also transform another person into someone else.</p> <p>Kenus can select some of the copies of Takahashi at time <var>0</var>, and transform them into copies of Aoki, another Ninja. The walking velocity of a copy does not change when it transforms. From then on, whenever a copy of Takahashi and a copy of Aoki are at the same coordinate, that copy of Takahashi transforms into a copy of Aoki.</p> <p>Among the <var>2^N</var> ways to transform some copies of Takahashi into copies of Aoki at time <var>0</var>, in how many ways will all the copies of Takahashi become copies of Aoki after a sufficiently long time? Find the count modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 200000</var></li> <li><var>1 ≀ X_i,V_i ≀ 10^9(1 ≀ i ≀ N)</var></li> <li><var>X_i</var> and <var>V_i</var> are integers.</li> <li>All <var>X_i</var> are distinct.</li> <li>All <var>V_i</var> are distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X_1</var> <var>V_1</var> : <var>X_N</var> <var>V_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the ways that cause all the copies of Takahashi to turn into copies of Aoki after a sufficiently long time, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 5 6 1 3 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>All copies of Takahashi will turn into copies of Aoki after a sufficiently long time if Kenus transforms one of the following sets of copies of Takahashi into copies of Aoki: <var>(2)</var>, <var>(3)</var>, <var>(1,2)</var>, <var>(1,3)</var>, <var>(2,3)</var> and <var>(1,2,3)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 7 2 9 8 16 10 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre></section> </div> </span>
p01734
<p> Ayimok is a wizard. </p> <p> His daily task is to arrange magical tiles in a line, and then cast a magic spell. </p> <p> Magical tiles and their arrangement follow the rules below: </p> <ul> <li> Each magical tile has the shape of a trapezoid with a height of 1.</li> <li> Some magical tiles may overlap with other magical tiles.</li> <li> Magical tiles are arranged on the 2D coordinate system.</li> <li> Magical tiles' upper edge lay on a horizontal line, where its y coordinate is 1.</li> <li> Magical tiles' lower edge lay on a horizontal line, where its y coordinate is 0.</li> </ul> <p> He has to remove these magical tiles away after he finishes casting a magic spell. One day, he found that removing a number of magical tiles is so tiresome, so he decided to simplify its process. </p> <p> Now, he has learned "Magnetization Spell" to remove magical tiles efficiently. The spell removes a set of magical tiles at once. Any pair of two magical tiles in the set must overlap with each other. </p> <p> For example, in Fig. 1, he can cast Magnetization Spell on all of three magical tiles to remove them away at once, since they all overlap with each other. (Note that the heights of magical tiles are intentionally changed for easier understandings.) </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day4_trapezoid-fig1" height="360" width="480"><br> Fig. 1: Set of magical tiles which can be removed at once<br> </center> <br> <p>However, in Fig. 2, he can not cast Magnetization Spell on all of three magical tiles at once, since tile 1 and tile 3 are not overlapped. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day4_trapezoid-fig2" height="360" width="480"><br> Fig. 2: Set of magical tiles which can NOT be removed at once<br> <br> </center> <p> He wants to remove all the magical tiles with the minimum number of Magnetization Spells, because casting the spell requires magic power exhaustively. </p> <p>Let's consider Fig. 3 case. He can remove all of magical tiles by casting Magnetization Spell three times; first spell for tile 1 and 2, second spell for tile 3 and 4, and third spell for tile 5 and 6. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day4_trapezoid-fig3" height="360" width="480"><br> Fig. 3: One way to remove all magical tiles (NOT the minimum number of spells casted)<br> <br> </center> <p> Actually, he can remove all of the magical tiles with casting Magnetization Spell just twice; first spell for tile 1, 2 and 3, second spell for tile 4, 5 and 6. And it is the minimum number of required spells for removing all magical tiles. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day4_trapezoid-fig4" height="360" width="480"><br> Fig. 4: The optimal way to remove all magical tiles(the minimum number of spells casted)<br> <br> </center> <p>Given a set of magical tiles, your task is to create a program which outputs the minimum number of casting Magnetization Spell to remove all of these magical tiles away. </p> <p>There might be a magical tile which does not overlap with other tiles, however, he still needs to cast Magnetization Spell to remove it. </p> <h3>Input</h3> <p>Input follows the following format: </p> <pre> <var>N</var> <var>xLower_{11}</var> <var>xLower_{12}</var> <var>xUpper_{11}</var> <var>xUpper_{12}</var> <var>xLower_{21}</var> <var>xLower_{22}</var> <var>xUpper_{21}</var> <var>xUpper_{22}</var> <var>xLower_{31}</var> <var>xLower_{32}</var> <var>xUpper_{31}</var> <var>xUpper_{32}</var> : : <var>xLower_{N1}</var> <var>xLower_{N2}</var> <var>xUpper_{N1}</var> <var>xUpper_{N2}</var> </pre> <p>The first line contains an integer <var>N</var>, which means the number of magical tiles. </p> <p>Then, <var>N</var> lines which contain the information of magical tiles follow. </p> <p>The <var>(i+1)</var>-th line includes four integers <var>xLower_{i1}</var>, <var>xLower_{i2}</var>, <var>xUpper_{i1}</var>, and <var>xUpper_{i2}</var>, which means <var>i</var>-th magical tile's corner points are located at <var>(xLower_{i1}, 0)</var>, <var>(xLower_{i2}, 0)</var>, <var>(xUpper_{i1}, 1)</var>, <var>(xUpper_{i2}, 1)</var>. </p> <p>You can assume that no two magical tiles will share their corner points. That is, all <var>xLower_{ij}</var> are distinct, and all <var>xUpper_{ij}</var> are also distinct. The input follows the following constraints: </p> <ul><li> <var>1 \leq N \leq 10^5</var> </li><li> <var>1 \leq xLower_{i1} < xLower_{i2} \leq 10^9</var> </li><li> <var>1 \leq xUpper_{i1} < xUpper_{i2} \leq 10^9</var> </li><li> All <var>xLower_{ij}</var> are distinct. </li><li> All <var>xUpper_{ij}</var> are distinct. </li></ul> <h3>Output</h3> <p>Your program must output the required minimum number of casting Magnetization Spell to remove all the magical tiles. </p> <h3>Sample Input 1</h3> <pre>3 26 29 9 12 6 10 15 16 8 17 18 19 </pre> <h3>Output for the Sample Input 1</h3> <pre>1 </pre> <h3>Sample Input 2</h3> <pre>3 2 10 1 11 5 18 9 16 12 19 15 20 </pre> <h3>Output for the Sample Input 2</h3> <pre>2 </pre> <h3>Sample Input 3</h3> <pre>6 2 8 1 14 6 16 3 10 3 20 11 13 17 28 18 21 22 29 25 31 23 24 33 34 </pre> <h3>Output for the Sample Input 3</h3> <pre>2 </pre>
p02231
UF with standard input (K = 100)
p02661
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> integers <var>X_1, X_2, \cdots, X_N</var>, and we know that <var>A_i \leq X_i \leq B_i</var>. Find the number of different values that the median of <var>X_1, X_2, \cdots, X_N</var> can take.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>The median of <var>X_1, X_2, \cdots, X_N</var> is defined as follows. Let <var>x_1, x_2, \cdots, x_N</var> be the result of sorting <var>X_1, X_2, \cdots, X_N</var> in ascending order.</p> <ul> <li>If <var>N</var> is odd, the median is <var>x_{(N+1)/2}</var>;</li> <li>if <var>N</var> is even, the median is <var>(x_{N/2} + x_{N/2+1}) / 2</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq A_i \leq B_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>:</var> <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <ul> <li> <p>If <var>X_1 = 1</var> and <var>X_2 = 2</var>, the median is <var>\frac{3}{2}</var>;</p> </li> <li> <p>if <var>X_1 = 1</var> and <var>X_2 = 3</var>, the median is <var>2</var>;</p> </li> <li> <p>if <var>X_1 = 2</var> and <var>X_2 = 2</var>, the median is <var>2</var>;</p> </li> <li> <p>if <var>X_1 = 2</var> and <var>X_2 = 3</var>, the median is <var>\frac{5}{2}</var>.</p> </li> </ul> <p>Thus, the median can take three values: <var>\frac{3}{2}</var>, <var>2</var>, and <var>\frac{5}{2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 100 100 10 10000 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9991 </pre></section> </div> </span>
p03973
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>N</var> people are waiting in a single line in front of the Takahashi Store. The cash on hand of the <var>i</var>-th person from the front of the line is a positive integer <var>A_i</var>.</p> <p>Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer <var>P</var> indicating its price, and shows this product to customers in order, starting from the front of the line. This step is repeated as described below.</p> <p>At each step, when a product is shown to a customer, if price <var>P</var> is equal to or less than the cash held by that customer at the time, the customer buys the product and Mr. Takahashi ends the current step. That is, the cash held by the first customer in line with cash equal to or greater than <var>P</var> decreases by <var>P</var>, and the next step begins.</p> <p>Mr. Takahashi can set the value of positive integer <var>P</var> independently at each step.</p> <p>He would like to sell as many products as possible. However, if a customer were to end up with <var>0</var> cash on hand after a purchase, that person would not have the fare to go home. Customers not being able to go home would be a problem for Mr. Takahashi, so he does not want anyone to end up with <var>0</var> cash.</p> <p>Help out Mr. Takahashi by writing a program that determines the maximum number of products he can sell, when the initial cash in possession of each customer is given.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ | N | ≩ 100000</var></li> <li><var>1 ≩ A_i ≩ 10^9(1 ≩ i ≩ N)</var></li> <li>All inputs are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Inputs are provided from Standard Inputs in the following form.</p> <pre><var>N</var> <var>A_1</var> : <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Output an integer representing the maximum number of products Mr. Takahashi can sell.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>As values of <var>P</var>, select in order <var>1, 4, 1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>18 </pre></section> </div> </span>
p03420
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi had a pair of two positive integers not exceeding <var>N</var>, <var>(a,b)</var>, which he has forgotten. He remembers that the remainder of <var>a</var> divided by <var>b</var> was greater than or equal to <var>K</var>. Find the number of possible pairs that he may have had.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>0 \leq K \leq N-1</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>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible pairs that he may have had.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>There are seven possible pairs: <var>(2,3),(5,3),(2,4),(3,4),(2,5),(3,5)</var> and <var>(4,5)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>100 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>31415 9265 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>287927211 </pre></section> </div> </span>
p03070
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given <var>N</var> integers. The <var>i</var>-th integer is <var>a_i</var>. Find the number, modulo <var>998244353</var>, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:</p> <ul> <li>Let <var>R</var>, <var>G</var> and <var>B</var> be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths <var>R</var>, <var>G</var> and <var>B</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 300</var></li> <li><var>1 \leq a_i \leq 300(1\leq i\leq N)</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>:</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number, modulo <var>998244353</var>, of ways to paint each of the integers red, green or blue so that the condition is satisfied.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>18 </pre> <p>We can only paint the integers so that the lengths of the sides of the triangle will be <var>1</var>, <var>2</var> and <var>2</var>, and there are <var>18</var> such ways.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 3 2 3 5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>150 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>20 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>563038556 </pre></section> </div> </span>
p01558
<h1>Substring</h1> <p>長さnの文字列s=s<sub>1</sub>,s<sub>2</sub>,
,s<sub>n</sub>およびm個のク゚リが䞎えられる。 各ク゚リq<sub>k</sub> (1 &le; k &le; m)は、&quot;L++&quot;, &quot;L--&quot;, &quot;R++&quot;, &quot;R--&quot;の4皮類のいずれかであり、 k番目のク゚リq<sub>k</sub>に察しおl[k]ずr[k]を以䞋で定矩する。 </p> <ul><li><p> L++l[k]=l[k-1]+1,r[k]=r[k-1] </p></li><li><p> L--l[k]=l[k-1]-1,r[k]=r[k-1] </p></li><li><p> R++l[k]=l[k-1],r[k]=r[k-1]+1 </p></li><li><p> R--l[k]=l[k-1],r[k]=r[k-1]-1 </p></li></ul> <p>䜆し、l[0]=r[0]=1である。 </p> <p>この時、m個の郚分文字列 s<sub>l[k]</sub>, s<sub>l[k]+1</sub>, 
, s<sub>r[k]-1</sub>, s<sub>r[k]</sub> (1 &le; k &le; m) に぀いお、䜕皮類の文字列が䜜られるかを答えよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる </p><blockquote> n m<br>s<br>q<sub>1</sub><br>q<sub>2</sub><br>
<br>q<sub>m</sub><br></blockquote> <h2>Constraints</h2> <ul><li><p> 文字列sは小文字アルファベットからなる </p></li><li><p> 1 &le; n &le; 3×10<sup>5</sup> </p></li><li><p> 1 &le; m &le; 3×10<sup>5</sup> </p></li><li><p> q<sub>k</sub>(1 &le; k &le; m)は、&quot;L++&quot;、&quot;L--&quot;、&quot;R++&quot;、&quot;R--&quot;のいずれか </p></li><li><p> 1 &le; l[k] &le; r[k] &le; n (1 &le; k &le; m) </p></li></ul> <h2>Output</h2> <p>問題の解を1行に出力せよ </p> <h2>Sample Input 1</h2> <pre>5 4 abcde R++ R++ L++ L-- </pre> <h2>Output for the Sample Input 1</h2> <pre>3 </pre><ul><li><p>l[1]=1, r[1]=2であり、郚分文字列は&quot;ab&quot;である </p></li><li><p>l[2]=1, r[2]=3であり、郚分文字列は&quot;abc&quot;である </p></li><li><p>l[3]=2, r[3]=3であり、郚分文字列は&quot;bc&quot;である </p></li><li><p>l[4]=1, r[4]=3であり、郚分文字列は&quot;abc&quot;である </p></li></ul> <p>よっお、生成される文字列は{&quot;ab&quot;,&quot;abc&quot;,&quot;bc&quot;}の3皮類である。 </p> <h2>Sample Input 2</h2> <pre>4 6 abab R++ L++ R++ L++ R++ L++ </pre> <h2>Output for the Sample Input 2</h2> <pre>4 </pre><ul><li><p>l[1]=1, r[1]=2であり、郚分文字列は&quot;ab&quot;である </p></li><li><p>l[2]=2, r[2]=2であり、郚分文字列は&quot;b&quot;である </p></li><li><p>l[3]=2, r[3]=3であり、郚分文字列は&quot;ba&quot;である </p></li><li><p>l[4]=3, r[4]=3であり、郚分文字列は&quot;a&quot;である </p></li><li><p>l[5]=3, r[5]=4であり、郚分文字列は&quot;ab&quot;である </p></li><li><p>l[6]=4, r[6]=4であり、郚分文字列は&quot;b&quot;である </p></li></ul> <p>よっお、生成される文字列は{&quot;a&quot;,&quot;ab&quot;,&quot;b&quot;,&quot;ba&quot;}の4皮類である。 </p> <h2>Sample Input 3</h2> <pre>10 13 aacacbabac R++ R++ L++ R++ R++ L++ L++ R++ R++ L-- L-- R-- R-- </pre> <h2>Output for the Sample Input 3</h2> <pre>11 </pre>
p03565
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>E869120 found a chest which is likely to contain treasure.<br/> However, the chest is locked. In order to open it, he needs to enter a string <var>S</var> consisting of lowercase English letters.<br/> He also found a string <var>S'</var>, which turns out to be the string <var>S</var> with some of its letters (possibly all or none) replaced with <code>?</code>. </p> <p>One more thing he found is a sheet of paper with the following facts written on it: </p> <ul> <li>Condition 1: The string <var>S</var> contains a string <var>T</var> as a contiguous substring.</li> <li>Condition 2: <var>S</var> is the lexicographically smallest string among the ones that satisfy Condition 1.</li> </ul> <p>Print the string <var>S</var>.<br/> If such a string does not exist, print <code>UNRESTORABLE</code>. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S'|, |T| \leq 50</var></li> <li><var>S'</var> consists of lowercase English letters and <code>?</code>.</li> <li><var>T</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>T'</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the string <var>S</var>.<br/> If such a string does not exist, print <code>UNRESTORABLE</code> instead. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>?tc???? coder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>atcoder </pre> <p>There are <var>26</var> strings that satisfy Condition 1: <code>atcoder</code>, <code>btcoder</code>, <code>ctcoder</code>,..., <code>ztcoder</code>. Among them, the lexicographically smallest is <code>atcoder</code>, so we can say <var>S = </var><code>atcoder</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>??p??d?? abc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>UNRESTORABLE </pre> <p>There is no string that satisfies Condition 1, so the string <var>S</var> does not exist.</p></section> </div> </span>
p01108
<h3><u>Equivalent Deformation</u></h3> <p> Two triangles <i>T</i><sub>1</sub> and <i>T</i><sub>2</sub> with the same area are on a plane. Your task is to perform the following operation to <i>T</i><sub>1</sub> several times so that it is exactly superposed on <i>T</i><sub>2</sub>. Here, vertices of <i>T</i><sub>1</sub> can be on any of the vertices of <i>T</i><sub>2</sub>. Compute the minimum number of operations required to superpose <i>T</i><sub>1</sub> on <i>T</i><sub>2</sub>. </p> <p> (Operation): Choose one vertex of the triangle and move it to an arbitrary point on a line passing through the vertex and parallel to the opposite side. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_H"> <br> An operation example </center> <p> The following figure shows a possible sequence of the operations for the first dataset of the sample input. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_H2"> </center> <h3>Input</h3> <p> The input consists of at most 2000 datasets, each in the following format. </p> <pre> <i>x</i><sub>11</sub> <i>y</i><sub>11</sub> <i>x</i><sub>12</sub> <i>y</i><sub>12</sub> <i>x</i><sub>13</sub> <i>y</i><sub>13</sub> <i>x</i><sub>21</sub> <i>y</i><sub>21</sub> <i>x</i><sub>22</sub> <i>y</i><sub>22</sub> <i>x</i><sub>23</sub> <i>y</i><sub>23</sub> </pre> <p> <i>x<sub>ij</sub></i> and <i>y<sub>ij</sub></i> are the <i>x-</i> and <i>y-</i>coordinate of the <i>j</i>-th vertex of <i>T<sub>i</sub></i>. </p> <p> The following holds for the dataset. </p><ul> <li>All the coordinate values are integers with at most 1000 of absolute values.</li> <li><i>T</i><sub>1</sub> and <i>T</i><sub>2</sub> have the same positive area size.</li> <li><b>The given six vertices are all distinct points.</b></li> </ul> <p></p> <p> An empty line is placed between datasets. </p> <p> The end of the input is indicated by EOF. </p> <h3>Output</h3> <p> For each dataset, output the minimum number of operations required in one line. <b>If five or more operations are required, output <tt>Many</tt> instead.</b> </p> <p> Note that, vertices may have non-integral values after they are moved. </p> <p> You can prove that, for any input satisfying the above constraints, the number of operations required is bounded by some constant. </p> <h3>Sample Input</h3> <pre>0 1 2 2 1 0 1 3 5 2 4 3 0 0 0 1 1 0 0 3 0 2 1 -1 -5 -4 0 1 0 15 -10 14 -5 10 0 -8 -110 221 -731 525 -555 -258 511 -83 -1000 -737 66 -562 533 -45 -525 -450 -282 -667 -439 823 -196 606 -768 -233 0 0 0 1 1 0 99 1 100 1 55 2 354 -289 89 -79 256 -166 131 -196 -774 -809 -519 -623 -990 688 -38 601 -360 712 384 759 -241 140 -59 196 629 -591 360 -847 936 -265 109 -990 -456 -913 -787 -884 -1000 -1000 -999 -999 -1000 -998 1000 1000 999 999 1000 998 -386 -83 404 -83 -408 -117 -162 -348 128 -88 296 -30 -521 -245 -613 -250 797 451 -642 239 646 309 -907 180 -909 -544 -394 10 -296 260 -833 268 -875 882 -907 -423 </pre> <h3>Output for the Sample Input</h3> <pre>4 3 3 3 3 4 4 4 4 Many Many Many Many </pre>
p03135
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In order to pass the entrance examination tomorrow, Taro has to study for <var>T</var> more hours.</p> <p>Fortunately, he can <em>leap</em> to World B where time passes <var>X</var> times as fast as it does in our world (World A).</p> <p>While <var>(X \times t)</var> hours pass in World B, <var>t</var> hours pass in World A.</p> <p>How many hours will pass in World A while Taro studies for <var>T</var> hours in World B?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq T \leq 100</var></li> <li><var>1 \leq X \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>T</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of hours that will pass in World A.</p> <p>The output will be regarded as correct when its absolute or relative error from the judge's output is at most <var>10^{-3}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2.6666666667 </pre> <p>While Taro studies for eight hours in World B where time passes three times as fast, <var>2.6666...</var> hours will pass in World A.</p> <p>Note that an absolute or relative error of at most <var>10^{-3}</var> is allowed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>99 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>99.0000000000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0.0100000000 </pre></section> </div> </span>
p02374
<H1>Range Query on a Tree</H1> <p> Write a program which manipulates a weighted rooted tree $T$ with the following operations: </p> <ul> <li>$add(v,w)$: add $w$ to the edge which connects node $v$ and its parent<br> <li>$getSum(u)$: report the sum of weights of all edges from the root to node $u$<br> </ul> <p> The given tree $T$ consists of $n$ nodes and every node has a unique ID from $0$ to $n-1$ respectively where ID of the root is $0$. Note that all weights are initialized to zero. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <p> $n$<br> $node_0$<br> $node_1$<br> $node_2$<br> $:$<br> $node_{n-1}$<br> $q$<br> $query_1$<br> $query_2$<br> $:$<br> $query_{q}$<br> </p> <p> The first line of the input includes an integer $n$, the number of nodes in the tree. </p> <p> In the next $n$ lines,the information of node $i$ is given in the following format: </p> <pre> <var>k<sub>i</sub></var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>k</sub></var> </pre> <p> $k_i$ is the number of children of node $i$, and $c_1$ $c_2$ ... $c_{k_i}$ are node IDs of 1st, ... $k$th child of node $i$. </p> <p> In the next line, the number of queries $q$ is given. In the next $q$ lines, $i$th query is given in the following format: </p> <pre> 0 <var>v</var> <var>w</var> </pre> <p> or </p> <pre> 1 <var>u</var> </pre> <p> The first integer represents the type of queries.'0' denotes $add(v, w)$ and '1' denotes $getSum(u)$. </p> <h2>Constraints</h2> <ul> <li>All the inputs are given in integers</li> <li>$ 2 \leq n \leq 100000 $</li> <li>$ c_j < c_{j+1} $ &nbsp; $( 1 \leq j \leq k-1 )$</li> <li>$ 2 \leq q \leq 200000 $</li> <li>$ 1 \leq u,v \leq n-1 $</li> <li>$ 1 \leq w \leq 10000 $</li> </ul> <h2>Output</h2> <p> For each $getSum$ query, print the sum in a line. </p> <h2>Sample Input 1</h2> <pre> 6 2 1 2 2 3 5 0 0 0 1 4 7 1 1 0 3 10 1 2 0 4 20 1 3 0 5 40 1 4 </pre> <h2>Sample Output 1</h2> <pre> 0 0 10 60 </pre> <h2>Sample Input 2</h2> <pre> 4 1 1 1 2 1 3 0 6 0 3 1000 0 2 1000 0 1 1000 1 1 1 2 1 3 </pre> <h2>Sample Output 2</h2> <pre> 1000 2000 3000 </pre> <br> <h2>Sample Input 3</h2> <pre> 2 1 1 0 4 0 1 1 1 1 0 1 1 1 1 </pre> <h2>Sample Output 3</h2> <pre> 1 2 </pre>
p00349
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>蟻</H1> <p> 倧きなチェス盀䞊に、それぞれから <var>N</var> たでの番号が割り振られた <var>N</var> 匹の蟻がいたす。図のように、チェス盀は H×W のマスからなる長方圢で、北西角を癜ずしお、癜マスず黒マスが亀互に䞊んでいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_ant" width="360"><br/> </center> <br/> <p> 最初、どの蟻もチェス盀のマスの䞭にいお、東たたは南を向いおいたす。぀のマスの䞭に匹以䞊の蟻がいるこずはありたせん。 </p> <p> 今、蟻たちが䞀斉に動き出したす。すべおの蟻は 1 単䜍時間に向いおいる方向のマスに぀移動したす。ただし、移動先がチェス盀の倖の堎合、萜䞋しおチェス盀から姿を消したす。 </p> <p> チェス盀䞊で匹の蟻が同じマスに入るず、それらの蟻は以䞋のような行動をずりたす </p> <ul> <li> そのマスの色が癜ならば、東方向に進んでいた蟻は南方向ぞ、南方向に進んでいた蟻は東方向ぞ向きを倉える。</li> <li> そのマスの色が黒ならば、それぞれの蟻は進む方向を維持する。</li> </ul> <br/> <p> チェス盀の倧きさず蟻の情報が䞎えられたずき、萜䞋する順番に蟻の番号を報告するプログラムを䜜成せよ。ただし、同じ時刻に耇数の蟻が萜䞋する堎合は、番号がより小さい方を先に報告する。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>W</var> <var>H</var> <var>N</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>d<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>d<sub>2</sub></var> : <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>d<sub>N</sub></var> </pre> <p> 行目にチェス盀の東西方向のマスの数 <var>W</var> ず南北方向のマスの数 <var>H</var> (2 &le; <var>W</var>, <var>H</var> &le; 10<sup>9</sup>) ず蟻の数 <var>N</var> (1 &le; <var>N</var> &le; 200000) が䞎えられる。続く <var>N</var> 行に <var>i</var> 番目の蟻の東西方向の䜍眮 <var>x<sub>i</sub></var> (1 &le; <var>x<sub>i</sub></var> &le; <var>W</var>)、南北方向の䜍眮 <var>y<sub>i</sub></var> (1 &le; <var>y<sub>i</sub></var> &le; <var>H</var>)、向きを衚す文字 <var>d<sub>i</sub></var>東向きの堎合「E」、南向きの堎合「S」が䞎えられる。ここで、チェス盀の北西角のマスを (1,1)、<var>x</var> が増加する方向を東、<var>y</var> が増加する方向を南ずする。 </p> <h2>Output</h2> <p> 萜䞋する順番に、蟻の番号を行ず぀出力する。 </p> <h2>Sample Input 1</h2> <pre> 3 3 3 2 1 S 1 2 E 2 2 E </pre> <h2>Sample Output 1</h2> <pre> 3 1 2 </pre> <h2>Sample Input 2</h2> <pre> 5 4 3 3 1 S 2 2 E 1 3 E </pre> <h2>Sample Output 2</h2> <pre> 2 3 1 </pre>
p02724
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi loves gold coins. He gains <var>1000</var> <em>happiness points</em> for each <var>500</var>-yen coin he has and gains <var>5</var> happiness points for each <var>5</var>-yen coin he has. (Yen is the currency of Japan.)</p> <p>Takahashi has <var>X</var> yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?</p> <p>(We assume that there are six kinds of coins available: <var>500</var>-yen, <var>100</var>-yen, <var>50</var>-yen, <var>10</var>-yen, <var>5</var>-yen, and <var>1</var>-yen coins.)</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq X \leq 10^9</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 maximum number of happiness points that can be earned.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1024 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2020 </pre> <p>By exchanging his money so that he gets two <var>500</var>-yen coins and four <var>5</var>-yen coins, he gains <var>2020</var> happiness points, which is the maximum number of happiness points that can be earned.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>He is penniless - or yenless.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2000000000 </pre> <p>He is a billionaire - in yen.</p></section> </div> </span>
p00719
<h1><font color="#000">Problem D:</font> Traveling by Stagecoach</h1> <p> Once upon a time, there was a traveler. </p> <p> He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in this problem is to write a program which determines the route for him. </p> <p> There are several cities in the country, and a road network connecting them. If there is a road between two cities, one can travel by a stagecoach from one of them to the other. A coach ticket is needed for a coach ride. The number of horses is specified in each of the tickets. Of course, with more horses, the coach runs faster. </p> <p> At the starting point, the traveler has a number of coach tickets. By considering these tickets and the information on the road network, you should find the best possible route that takes him to the destination in the shortest time. The usage of coach tickets should be taken into account. </p> <p> The following conditions are assumed. </p> <ul><li> A coach ride takes the traveler from one city to another directly connected by a road. In other words, on each arrival to a city, he must change the coach. </li> <li> Only one ticket can be used for a coach ride between two cities directly connected by a road. </li> <li> Each ticket can be used only once. </li> <li> The time needed for a coach ride is the distance between two cities divided by the number of horses. </li> <li> The time needed for the coach change should be ignored. </li></ul> <h2>Input</h2> <p> The input consists of multiple datasets, each in the following format. The last dataset is followed by a line containing five zeros (separated by a space). </p> <blockquote> <i>n m p a b</i><br> <i>t</i><sub>1</sub> <i>t</i><sub>2</sub> ... <i>t<sub>n</sub></i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>z</i><sub>1</sub><br> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>z</i><sub>2</sub><br> ...<br> <i>x<sub>p</sub></i> <i>y<sub>p</sub></i> <i>z<sub>p</sub></i><br> </blockquote> <p> Every input item in a dataset is a non-negative integer. If a line contains two or more input items, they are separated by a space. </p> <p> <i>n</i> is the number of coach tickets. You can assume that the number of tickets is between 1 and 8. <i>m</i> is the number of cities in the network. You can assume that the number of cities is between 2 and 30. <i>p</i> is the number of roads between cities, which may be zero. </p> <p> <i>a</i> is the city index of the starting city. <i>b</i> is the city index of the destination city. <i>a</i> is not equal to <i>b</i>. You can assume that all city indices in a dataset (including the above two) are between 1 and <i>m</i>. </p> <p> The second line of a dataset gives the details of coach tickets. <i>t<sub>i</sub></i> is the number of horses specified in the <i>i</i>-th coach ticket (1&lt;=<i>i</i>&lt;=<i>n</i>). You can assume that the number of horses is between 1 and 10. </p> <p> The following <i>p</i> lines give the details of roads between cities. The <i>i</i>-th road connects two cities with city indices <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i>, and has a distance <i>z<sub>i</sub></i> (1&lt;=<i>i</i>&lt;=<i>p</i>). You can assume that the distance is between 1 and 100. </p> <p> No two roads connect the same pair of cities. A road never connects a city with itself. Each road can be traveled in both directions. </p> <h2>Output</h2> <p> For each dataset in the input, one line should be output as specified below. An output line should not contain extra characters such as spaces. </p> <p> If the traveler can reach the destination, the time needed for the best route (a route with the shortest time) should be printed. The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. </p> <p> If the traveler cannot reach the destination, the string "<tt>Impossible</tt>" should be printed. One cannot reach the destination either when there are no routes leading to the destination, or when the number of tickets is not sufficient. Note that the first letter of "<tt>Impossible</tt>" is in uppercase, while the other letters are in lowercase. </p> <h2>Sample Input</h2> <pre> 3 4 3 1 4 3 1 2 1 2 10 2 3 30 3 4 20 2 4 4 2 1 3 1 2 3 3 1 3 3 4 1 2 4 2 5 2 4 3 4 1 5 5 1 2 10 2 3 10 3 4 10 1 2 0 1 2 1 8 5 10 1 5 2 7 1 8 4 5 6 3 1 2 5 2 3 4 3 4 7 4 5 3 1 3 25 2 4 23 3 5 22 1 4 45 2 5 51 1 5 99 0 0 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 30.000 3.667 Impossible Impossible 2.856 </pre> <!-- <p> Since the number of digits after the decimal point is not specified, the above result is not the only solution. For example, the following result is also acceptable. </p> <pre> 30.0 3.66667 Impossible Impossible 2.85595 </pre> -->
p03836
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Dolphin resides in two-dimensional Cartesian plane, with the positive <var>x</var>-axis pointing right and the positive <var>y</var>-axis pointing up.<br/> Currently, he is located at the point <var>(sx,sy)</var>. In each second, he can move up, down, left or right by a distance of <var>1</var>.<br/> Here, both the <var>x</var>- and <var>y</var>-coordinates before and after each movement must be integers.<br/> He will first visit the point <var>(tx,ty)</var> where <var>sx &lt; tx</var> and <var>sy &lt; ty</var>, then go back to the point <var>(sx,sy)</var>, then visit the point <var>(tx,ty)</var> again, and lastly go back to the point <var>(sx,sy)</var>.<br/> Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points <var>(sx,sy)</var> and <var>(tx,ty)</var>.<br/> Under this condition, find a shortest path for him. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>-1000 ≀ sx &lt; tx ≀ 1000</var> </li> <li><var>-1000 ≀ sy &lt; ty ≀ 1000</var> </li> <li><var>sx,sy,tx</var> and <var>ty</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>sx</var> <var>sy</var> <var>tx</var> <var>ty</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a string <var>S</var> that represents a shortest path for Dolphin.<br/> The <var>i</var>-th character in <var>S</var> should correspond to his <var>i</var>-th movement.<br/> The directions of the movements should be indicated by the following characters: </p> <ul> <li><code>U</code>: Up</li> <li><code>D</code>: Down</li> <li><code>L</code>: Left</li> <li><code>R</code>: Right</li> </ul> <p>If there exist multiple shortest paths under the condition, print any of them.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>0 0 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>UURDDLLUUURRDRDDDLLU </pre> <p>One possible shortest path is:</p> <ul> <li>Going from <var>(sx,sy)</var> to <var>(tx,ty)</var> for the first time: <var>(0,0)</var> → <var>(0,1)</var> → <var>(0,2)</var> → <var>(1,2)</var></li> <li>Going from <var>(tx,ty)</var> to <var>(sx,sy)</var> for the first time: <var>(1,2)</var> → <var>(1,1)</var> → <var>(1,0)</var> → <var>(0,0)</var></li> <li>Going from <var>(sx,sy)</var> to <var>(tx,ty)</var> for the second time: <var>(0,0)</var> → <var>(-1,0)</var> → <var>(-1,1)</var> → <var>(-1,2)</var> → <var>(-1,3)</var> → <var>(0,3)</var> → <var>(1,3)</var> → <var>(1,2)</var></li> <li>Going from <var>(tx,ty)</var> to <var>(sx,sy)</var> for the second time: <var>(1,2)</var> → <var>(2,2)</var> → <var>(2,1)</var> → <var>(2,0)</var> → <var>(2,-1)</var> → <var>(1,-1)</var> → <var>(0,-1)</var> → <var>(0,0)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>-2 -2 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>UURRURRDDDLLDLLULUUURRURRDDDLLDL </pre></section> </div> </span>
p00076
<H1>宝探し II</H1> <p> 蔵を片付けおいたら、先祖の宝のありかぞの行き方を蚘した叀文曞が芋぀かりたした。この叀文曞にはおおよそ次のような事が曞かれおいたした。 </p> <pre class=exp> 1. たず、町倖れの井戞から、真東に 1m の地点に立ち、たっすぐ井戞の方向を向け。 2. 右回りに 90 床向きを倉え、1m 盎進したら、たっすぐ井戞の方向を向け。 3. 右回りに 90 床向きを倉え、1m 盎進したら、たっすぐ井戞の方向を向け。 4. 〃 5. 〃 6.  </pre> <p> 2 行目以降は、党く同じこずが曞かれおいたした。あなたは、宝を探そうず思いたしたが、厄介なこずに気が぀きたした。昔ず違い建物が邪魔をしおいお、たっすぐ井戞の方向をむこうにも井戞が芋えなかったり 1m 盎進しようにも盎進できなかったりしたす。さらに、この叀文曞ずきたら、1000 行近くあり、叀文曞どおりの䜜業をするこずは、かなりの時間ず䜓力が芁りたす。しかしながら、幞運なこずに、あなたはコンピュヌタを利甚するこずができたす。 </p> <p>叀文曞に曞かれおいる行数 <var>n</var> を入力しお、宝のありかを出力するプログラムを䜜成しおください。ただし、 <var>n</var> は 2 以䞊 1,000 以䞋の正の敎数ずしたす。 </p> <H2>入力</H2> <p>耇数のデヌタセットが䞎えられたす。各デヌタセットずしお、叀文曞の行数を衚す぀の敎数 <var>n</var> が行に䞎えられたす。 </p> <p>入力は -1 で終わりたす。デヌタセットの数は 50 を超えたせん。</p> <H2>出力</H2> <p> 町倖れの井戞から東に <var>x</var> (m)北に <var>y</var> (m)の䜍眮に宝があるずしお、 各デヌタセットごずに以䞋の圢匏で出力しお䞋さい。</p> <pre> <var>x</var> <var>y</var> </pre> <p> 出力は実数ずし、0.01 以䞋の誀差を含んでもよい。 </pre> <H2>Sample Input</H2> <pre> 3 6 -1 </pre> <H2>Output for the Sample Input</H2> <pre> 0.29 1.71 -2.31 0.80 </pre> <H2>参考</H2> <p><var>n</var> =2, 3, 4, 5, 6 の宝の䜍眮</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_04_1">
p00426
<H1></H1> <p> 倧きさが異なる n 個のコップず 3 ぀のトレむお盆ABC がありそれらのコップは 3 ぀のトレむの䞊にそれぞれ䜕個かず぀䞀山に重ねお眮かれおいるただしどのトレむにおいおもそのトレむの䞭で䞀番小さいコップが䞀番䞋に 2 番目に小さいコップがその䞊に 3 番目に小さいコップがその䞊にず小さい順に䌏せお重ねおある䟋えば䞋図の右偎は n = 5 個のコップがトレむ ABC にそれぞれ 2 個0 個3 個重ねお眮かれおいる状態を瀺しおいる </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t4-fig1"> </center> <br/> <p> このようにコップの初期状態が䞎えられたずき次の芏則 1 〜 3 を守りながらすべおのコップを A たたは C のどちらかのトレむに移動させるには䜕回移動を行えばよいかを求めたい </p> <p> 芏則 1 1 回に 1 ぀のコップだけを移動させるこずができるそれはそのトレむにあるコップの䞭で䞀番䞊のコップ぀たり䞀番倧きいコップである </p> <p> 芏則 2倧きいコップの䞊に小さいコップを重ねおはいけない </p> <p> 芏則 3コップ 1 個の盎接移動はトレむ A から BB から AB から CC から B のみが蚱され A から C ぞの盎接移動や C から A ぞの盎接移動は蚱されない </p> <p>  n 個のコップの初期状態ず敎数 m が䞎えられたずき m 回以内の移動で A たたは C のどちらかのトレむにすべおのコップをたずめお重ねるこずができるかどうかを刀定し可胜な堎合には移動回数の最小倀を䞍可胜な堎合には -1 を出力するプログラムを䜜成しなさい </p> <p>  入力ファむルの 1 行目には n ず m がこの順に空癜を区切り文字ずしお曞いおある 1 ≩ n ≩ 15 であり 1 ≩ m ≩ 15000000 である 2 行目3 行目4 行目には 1 から n たでの敎数を䜕個かず぀ 3 ぀のグルヌプに分けおそれぞれのグルヌプ内で小さい順昇順に䞊べたものが曞いおあるただし各行の先頭それらの敎数の前にはそれらの個数が曞いおある 2 行目に曞かれおいる敎数先頭の 1 ぀を陀くはトレむ A の䞊に重ねられおいる各コップの倧きさを衚す同様に 3 行目に曞かれおいる敎数先頭の 1 ぀を陀くはトレむ B の䞊に重ねられおいる各コップの倧きさを衚し 4 行目に曞かれおいる敎数先頭の぀を陀くはトレむ C の䞊に重ねられおいる各コップの倧きさを衚す </p> <!-- <p> アップロヌドする出力ファむルにおいおは出力移動回数たたは -1の埌に改行を入れるこず </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> <th width="150" align="left">入力䟋</th> </tr> <tr><td></td><td></td></tr> <tr><td>3 10</td><td>4 20 </td><td>2 5</td><td>3 3</td></tr> <tr><td>0</td><td>2 1 2</td><td>2 1 2</td><td>0</td></tr> <tr><td>1 1</td><td>1 3</td><td>0</td><td>1 1</td></tr> <tr><td>2 2 3</td><td>1 4</td><td>0</td><td>2 2 3</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> <th width="150" align="left">出力䟋</th> </tr> <tr><td>9</td><td>3</td><td>0</td><td>-1</td></tr> </table> <h3>入力</h3> <p> 入力は耇数のデヌタセットからなるn, m がずもに 0 のずき入力が終了するデヌタセットの数は 5 を超えない </p> <h3>出力</h3> <p> デヌタセットごずに、移動回数たたは -1 を行に出力する </p> <H2>入力䟋</H2> <pre> 3 10 0 1 1 2 2 3 4 20 2 1 2 1 3 1 4 2 5 2 1 2 0 0 3 3 0 1 1 2 2 3 0 0 </pre> <H2>出力䟋</H2> <pre> 9 3 0 -1 </pre> <p> 各デヌタセットの出力移動回数たたは -1の埌に改行を入れるこず </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p01667
<h2>A - Everlasting Zero</h2> <h3>Problem Statement</h3> <p> You are very absorbed in a famous role-playing game (RPG), "Everlasting -Zero-". An RPG is a game in which players assume the roles of characters in a fictional setting. While you play the game, you can forget your "real life" and become a different person. </p> <p> To play the game more effectively, you have to understand two notions, a <em>skill point</em> and a <em>special command</em>. A character can boost up by accumulating his experience points. When a character boosts up, he can gain skill points. </p> <p> You can arbitrarily allocate the skill points to the character's skills to enhance the character's abilities. If skill points of each skill meets some conditions simultaneously (e.g., the skill points of some skills are are greater than or equal to the threshold values and those of others are less than or equal to the values) , the character learns a special command. One important thing is that once a character learned the command, he will never forget it. And once skill points are allocated to the character, you cannot revoke the allocation. In addition, the initial values of each skill is <var>0</var>. </p> <p> The system is so complicated that it is difficult for ordinary players to know whether a character can learn all the special commands or not. Luckily, in the "real" world, you are a great programmer, so you decided to write a program to tell whether a character can learn all the special commnads or not. If it turns out to be feasible, you will be more absorbed in the game and become happy. </p> <h3>Input</h3> <p> The input is formatted as follows. </p> <pre> <var>M</var> <var>N</var> <var>K_1</var> <var>s_{1,1}</var> <var>cond_{1,1}</var> <var>t_{1,1}</var> <var>s_{1,2}</var> <var>cond_{1,2}</var> <var>t_{1,2}</var> ... <var>s_{1,K_1}</var> <var>cond_{1,K_1}</var> <var>t_{1,K_1}</var> <var>K_2</var> ... <var>K_M</var> <var>s_{M,1}</var> <var>cond_{M,1}</var> <var>t_{M,1}</var> <var>s_{M,2}</var> <var>cond_{M,2}</var> <var>t_{M,2}</var> ... <var>s_{M,K_M}</var> <var>cond_{M,K_M}</var> <var>t_{M,K_M}</var> </pre> <p> The first line of the input contains two integers (<var>M</var>, <var>N</var>), where <var>M</var> is the number of special commands (<var>1 \leq M \leq 100</var>), <var>N</var> is the number of skills (<var>1 \leq N \leq 100</var>). All special commands and skills are numbered from <var>1</var>. </p> <p> Then <var>M</var> set of conditions follows. The first line of a condition set contains a single integer <var>K_i</var> (<var>0 \leq K_i \leq 100</var>), where <var>K_i</var> is the number of conditions to learn the <var>i</var>-th command. The following <var>K_i</var> lines describe the conditions on the skill values. <var>s_{i,j}</var> is an integer to identify the skill required to learn the command. <var>cond_{i,j}</var> is given by string "<=" or ">=". If <var>cond_{i,j}</var> is "<=", the skill point of <var>s_{i,j}</var>-th skill must be less than or equal to the threshold value <var>t_{i,j}</var> (<var>0 \leq t_{i,j} \leq 100</var>). Otherwise, i.e. if <var>cond_{i,j}</var> is ">=", the skill point of <var>s_{i,j}</var> must be greater than or equal to <var>t_{i,j}</var>. </p> <h3>Output</h3> <p> Output "Yes" (without quotes) if a character can learn all the special commands in given conditions, otherwise "No" (without quotes). </p> <h3>Sample Input 1</h3> <pre> 2 2 2 1 >= 3 2 <= 5 2 1 >= 4 2 >= 3 </pre> <h3>Output for the Sample Input 1</h3> <pre> Yes </pre> <h3>Sample Input 2</h3> <pre> 2 2 2 1 >= 5 2 >= 5 2 1 <= 4 2 <= 3 </pre> <h3>Output for the Sample Input 2</h3> <pre> Yes </pre> <h3>Sample Input 3</h3> <pre> 2 2 2 1 >= 3 2 <= 3 2 1 <= 2 2 >= 5 </pre> <h3>Output for the Sample Input 3</h3> <pre> No </pre> <h3>Sample Input 4</h3> <pre> 1 2 2 1 <= 10 1 >= 15 </pre> <h3>Output for the Sample Input 4</h3> <pre> No </pre> <h3>Sample Input 5</h3> <pre> 5 5 3 2 <= 1 3 <= 1 4 <= 1 4 2 >= 2 3 <= 1 4 <= 1 5 <= 1 3 3 >= 2 4 <= 1 5 <= 1 2 4 >= 2 5 <= 1 1 5 >= 2 </pre> <h3>Output for the Sample Input 5</h3> <pre> Yes </pre>
p02948
<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> one-off jobs available. If you take the <var>i</var>-th job and complete it, you will earn the reward of <var>B_i</var> after <var>A_i</var> days from the day you do it.</p> <p>You can take and complete at most one of these jobs in a day.</p> <p>However, you cannot retake a job that you have already done.</p> <p>Find the maximum total reward that you can earn no later than <var>M</var> days from today.</p> <p>You can already start working today.</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 M \leq 10^5</var></li> <li><var>1 \leq A_i \leq 10^5</var></li> <li><var>1 \leq B_i \leq 10^4</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>\vdots</var> <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum total reward that you can earn no later than <var>M</var> days from today.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 4 3 4 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>You can earn the total reward of <var>5</var> by taking the jobs as follows:</p> <ul> <li>Take and complete the first job today. You will earn the reward of <var>3</var> after four days from today.</li> <li>Take and complete the third job tomorrow. You will earn the reward of <var>2</var> after two days from tomorrow, that is, after three days from today.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 1 2 1 3 1 4 2 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p00975
<h2>Four-Coloring</h2> <p> You are given a planar embedding of a connected graph. Each vertex of the graph corresponds to a distinct point with integer coordinates. Each edge between two vertices corresponds to a straight line segment connecting the two points corresponding to the vertices. As the given embedding is planar, the line segments corresponding to edges do not share any points other than their common endpoints. The given embedding is organized so that inclinations of all the line segments are multiples of 45 degrees. In other words, for two points with coordinates ($x_u, y_u$) and ($x_v, y_v$) corresponding to vertices $u$ and $v$ with an edge between them, one of $x_u = x_v$, $y_u = y_v$, or $|x_u - x_v| = |y_u - y_v|$ holds. </p> <div style="text-align:center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2018_fourColoring"><br> Figure H.1. Sample Input 1 and 2 </div> <br> <p> Your task is to color each vertex in one of the four colors, {1, 2, 3, 4}, so that no two vertices connected by an edge are of the same color. According to the famous four color theorem, such a coloring is always possible. Please find one. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $m$ $x_1$ $y_1$ ... $x_n$ $y_n$ $u_1$ $v_1$ ... $u_m$ $v_m$ </pre> <p> The first line contains two integers, $n$ and $m$. $n$ is the number of vertices and $m$ is the number of edges satisfying $3 \leq n \leq m \leq 10 000$. The vertices are numbered 1 through $n$. Each of the next $n$ lines contains two integers. Integers on the $v$-th line, $x_v$ ($0 \leq x_v \leq 1000$) and $y_v$ ($0 \leq y_v \leq 1000$), denote the coordinates of the point corresponding to the vertex $v$. Vertices correspond to distinct points, i.e., ($x_u, y_u$) $\ne$ ($x_v, y_v$) holds for $u \ne v$. Each of the next $m$ lines contains two integers. Integers on the $i$-th line, $u_i$ and $v_i$, with $1 \leq u_i < v_i \leq n$, mean that there is an edge connecting two vertices $u_i$ and $v_i$. </p> <h3>Output</h3> <p> The output should consist of $n$ lines. The $v$-th line of the output should contain one integer $c_v \in \{1, 2, 3, 4\}$ which means that the vertex $v$ is to be colored $c_v$. The output must satisfy $c_u \ne c_v$ for every edge connecting $u$ and $v$ in the graph. If there are multiple solutions, you may output any one of them. </p> <h3>Sample Input 1</h3> <pre> 5 8 0 0 2 0 0 2 2 2 1 1 1 2 1 3 1 5 2 4 2 5 3 4 3 5 4 5 </pre> <h3> Sample Output 1</h3> <pre> 1 2 2 1 3 </pre> <h3>Sample Input 2</h3> <pre> 6 10 0 0 1 0 1 1 2 1 0 2 1 2 1 2 1 3 1 5 2 3 2 4 3 4 3 5 3 6 4 6 5 6 </pre> <h3> Sample Output 2</h3> <pre> 1 2 3 4 2 1 </pre>
p04035
<span class="lang-en"> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> pieces of ropes, numbered <var>1</var> through <var>N</var>. The length of piece <var>i</var> is <var>a_i</var>.</p> <p>At first, for each <var>i (1≀i≀N-1)</var>, piece <var>i</var> and piece <var>i+1</var> are tied at the ends, forming one long rope with <var>N-1</var> knots. Snuke will try to untie all of the knots by performing the following operation repeatedly:</p> <ul> <li>Choose a (connected) rope with a total length of at least <var>L</var>, then untie one of its knots.</li> </ul> <p>Is it possible to untie all of the <var>N-1</var> knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N≀10^5</var></li> <li><var>1≀L≀10^9</var></li> <li><var>1≀a_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>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>L</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>If it is not possible to untie all of the <var>N-1</var> knots, print <code>Impossible</code>.</p> <p>If it is possible to untie all of the knots, print <code>Possible</code>, then print another <var>N-1</var> lines that describe a possible order to untie the knots. The <var>j</var>-th of those <var>N-1</var> lines should contain the index of the knot that is untied in the <var>j</var>-th operation. Here, the index of the knot connecting piece <var>i</var> and piece <var>i+1</var> is <var>i</var>.</p> <p>If there is more than one solution, output any.</p> </section> </div> </div> <hr> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 50 30 20 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Possible 2 1 </pre> <p>If the knot <var>1</var> is untied first, the knot <var>2</var> will become impossible to untie.</p> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 21 10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Impossible </pre> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 50 10 20 30 40 50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Possible 1 2 3 4 </pre> <p>Another example of a possible solution is <var>3</var>, <var>4</var>, <var>1</var>, <var>2</var>.</p></section> </div> </hr></hr></hr></hr></span>
p01237
<H1><font color="#000">Problem D:</font> Life Game</H1> <p> You are working at a production plant of biological weapons. You are a maintainer of a terrible virus weapon with very high reproductive power. The virus has a tendency to build up regular hexagonal colonies. So as a whole, the virus weapon forms a hexagonal grid, each hexagon being a colony of the virus. The grid itself is in the regular hexagonal form with <i>N</i> colonies on each edge. </p> <p> The virus self-propagates at a constant speed. Self-propagation is performed simultaneously at all colonies. When it is done, for each colony, the same number of viruses are born at every neighboring colony. Note that, after the self-propagation, if the number of viruses in one colony is more than or equal to the limit density <i>M</i>, then the viruses in the colony start self-attacking, and the number reduces modulo <i>M</i>. </p> <p> Your task is to calculate the total number of viruses after <i>L</i> periods, given the size <i>N</i> of the hexagonal grid and the initial number of viruses in each of the colonies. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lifeGame"> </center> <H2>Input</H2> <p> The input consists of multiple test cases. </p> <p> Each case begins with a line containing three integers <i>N</i> (1 &le; <i>N</i> &le; 6), <i>M</i> (2 &le; <i>M</i> &le; 10<sup>9</sup> ), and <i>L</i> (1 &le; <i>L</i> &le; 10<sup>9</sup> ). The following 2<i>N</i> - 1 lines are the description of the initial state. Each non-negative integer (smaller than <i>M</i>) indicates the initial number of viruses in the colony. The first line contains the number of viruses in the <i>N</i> colonies on the topmost row from left to right, and the second line contains those of <i>N</i> + 1 colonies in the next row, and so on. </p> <p> The end of the input is indicated by a line “0 0 0”. </p> <H2>Output</H2> <p> For each test case, output the test case number followed by the total number of viruses in all colonies after <i>L</i> periods. </p> <H2>Sample Input</H2> <pre> 3 3 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 8 Case 2: 18 </pre>
p01722
<p> むクタ君は速いプログラムが倧奜きである。最近は、陀算のプログラムを高速にしようずしおいる。しかしなかなか速くならないので、「垞識的に考えお兞型的」な入力に察しおのみ高速にすればよいず考えた。むクタ君が解こうずしおいる問題は次のようなものである。 </p> <p> 䞎えられた非負敎数<var>n</var>に察し、10進法で<var>p(n) &minus; 1</var>桁の正敎数<var>11</var>...<var>1</var>を<var>p(n)</var>で割ったあたりを求めよ。ただし<var>p(n)</var>は<var>2<sup>2<sup>{</sup> . . . <sup>2</sup></sup>}</var>2が<var>n</var>個より倧きい最小の玠数を衚すずする。<var>p(0) = 2</var>ずする。 </p> <p>あなたの仕事は、むクタ君より速くプログラムを完成させるこずである。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>n</var> </pre> <p>問題の入力の非負敎数<var>n</var>があたえられる。 </p> <h3>Constraints</h3> <p>入力䞭の各倉数は以䞋の制玄を満たす。 </p><ul><li> <var>0 &le; n < 1000</var> </li></ul> <h2>Output</h2> <p>問題の解を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre>0 </pre> <h2>Output for the Sample Input 1</h2> <pre>1 </pre> <ul><li><var>n=0</var>のずき、<var>p(n) = 2</var> なので、1 mod 2 = 1 が解ずなる。 </li></ul> <h2>Sample Input 2</h2> <pre>1 </pre> <h2>Output for the Sample Input 2</h2> <pre>2 </pre> <ul><li><var>n=1</var>のずき、<var>p(n) = 3</var> なので、11 mod 3 = 2が解ずなる。 </li></ul> <h2>Sample Input 3</h2> <pre>2 </pre> <h2>Output for the Sample Input 3</h2> <pre>1 </pre>
p00830
<H1><font color="#000">Problem D:</font> Pathological Paths</H1> <p> Professor Pathfinder is a distinguished authority on the structure of hyperlinks in the World Wide Web. For establishing his hypotheses, he has been developing software agents, which automatically traverse hyperlinks and analyze the structure of the Web. Today, he has gotten an intriguing idea to improve his software agents. However, he is very busy and requires help from good programmers. You are now being asked to be involved in his development team and to create a small but critical software module of his new type of software agents. </p> <p> Upon traversal of hyperlinks, Pathfinder’s software agents incrementally generate a map of visited portions of the Web. So the agents should maintain the list of traversed hyperlinks and visited web pages. One problem in keeping track of such information is that two or more different URLs can point to the same web page. For instance, by typing any one of the following five URLs, your favorite browsers probably bring you to the same web page, which as you may have visited is the home page of the ACM ICPC Ehime contest. </p> <pre> http://www.ehime-u.ac.jp/ICPC/ http://www.ehime-u.ac.jp/ICPC http://www.ehime-u.ac.jp/ICPC/../ICPC/ http://www.ehime-u.ac.jp/ICPC/./ http://www.ehime-u.ac.jp/ICPC/index.html </pre> <p> Your program should reveal such aliases for Pathfinder’s experiments. </p> <p> Well, . . . but it were a real challenge and to be perfect you might have to embed rather compli- cated logic into your program. We are afraid that even excellent programmers like you could not complete it in five hours. So, we make the problem a little simpler and subtly unrealis- tic. You should focus on the path parts (i.e. <span>/ICPC/, /ICPC, /ICPC/../ICPC/, /ICPC/./</span>, and <span>/ICPC/index.html</span> in the above example) of URLs and ignore the scheme parts (e.g. <span>http://</span>), the server parts (e.g. <span>www.ehime-u.ac.jp</span>), and other optional parts. You should carefully read the rules described in the sequel since some of them may not be based on the reality of today’s Web and URLs. </p> <p> Each path part in this problem is an absolute pathname, which specifies a path from the root directory to some web page in a hierarchical (tree-shaped) directory structure. A pathname always starts with a slash (/), representing the root directory, followed by path segments delim- ited by a slash. For instance, <span>/ICPC/index.html</span> is a pathname with two path segments <span>ICPC</span> and <span>index.html</span>. </p> <p> All those path segments but the last should be directory names and the last one the name of an ordinary file where a web page is stored. However, we have one exceptional rule: an ordinary file name <span>index.html</span> at the end of a pathname may be omitted. For instance, a pathname <span>/ICPC/index.html</span> can be shortened to <span>/ICPC/</span>, if <span>index.html</span> is an existing ordinary file name. More precisely, if <span>ICPC</span> is the name of an existing directory just under the root and index.html is the name of an existing ordinary file just under the <span>/ICPC</span> directory, <span>/ICPC/index.html</span> and <span>/ICPC/</span> refer to the same web page. Furthermore, the last slash following the last path segment can also be omitted. That is, for instance, <span>/ICPC/</span> can be further shortened to <span>/ICPC</span>. However, <span>/index.html</span> can only be abbreviated to / (a single slash). </p> <p> You should pay special attention to path segments consisting of a single period (.) or a double period (..), both of which are always regarded as directory names. The former represents the directory itself and the latter represents its parent directory. Therefore, if <span>/ICPC/</span> refers to some web page, both <span>/ICPC/./</span> and <span>/ICPC/../ICPC/</span> refer to the same page. Also <span>/ICPC2/../ICPC/</span> refers to the same page if <span>ICPC2</span> is the name of an existing directory just under the root; otherwise it does not refer to any web page. Note that the root directory does not have any parent directory and thus such pathnames as <span>/../</span> and <span>/ICPC/../../index.html</span> cannot point to any web page. </p> <p> Your job in this problem is to write a program that checks whether two given pathnames refer to existing web pages and, if so, examines whether they are the same. </p> <H2>Input</H2> <p> The input consists of multiple datasets. The first line of each dataset contains two positive integers <i>N</i> and <i>M</i>, both of which are less than or equal to 100 and are separated by a single space character. </p> <p> The rest of the dataset consists of <i>N</i> + 2<i>M</i> lines, each of which contains a syntactically correct pathname of at most 100 characters. You may assume that each path segment enclosed by two slashes is of length at least one. In other words, two consecutive slashes cannot occur in any pathname. Each path segment does not include anything other than alphanumerical characters (i.e. ‘a’-‘z’, ‘A’-‘Z’, and ‘0’-‘9’) and periods (‘.’). </p> <p> The first <i>N</i> pathnames enumerate all the web pages (ordinary files). Every existing directory name occurs at least once in these pathnames. You can assume that these pathnames do not include any path segments consisting solely of single or double periods and that the last path segments are ordinary file names. Therefore, you do not have to worry about special rules for <span>index.html</span> and single/double periods. You can also assume that no two of the <i>N</i> pathnames point to the same page. </p> <p> Each of the following <i>M</i> pairs of pathnames is a question: do the two pathnames point to the same web page? These pathnames may include single or double periods and may be terminated by a slash. They may include names that do not correspond to existing directories or ordinary files. </p> <p> Two zeros in a line indicate the end of the input. </p> <H2>Output</H2> <p> For each dataset, your program should output the <i>M</i> answers to the <i>M</i> questions, each in a separate line. Each answer should be “<span>yes</span>” if both point to the same web page, “<span>not found</span>” if at least one of the pathnames does not point to any one of the first <i>N</i> web pages listed in the input, or “<span>no</span>” otherwise. </p> <H2>Sample Input</H2> <pre> 5 6 /home/ACM/index.html /ICPC/index.html /ICPC/general.html /ICPC/japanese/index.html /ICPC/secret/confidential/2005/index.html /home/ACM/ /home/ICPC/../ACM/ /ICPC/secret/ /ICPC/secret/index.html /ICPC /ICPC/../ICPC/index.html /ICPC /ICPC/general.html /ICPC/japanese/.././ /ICPC/japanese/./../ /home/ACM/index.html /home/ACM/index.html/ 1 4 /index.html/index.html / /index.html/index.html /index.html /index.html/index.html /.. /index.html/../.. /index.html/ /index.html/index.html/.. 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> not found not found yes no yes not found not found yes not found not found </pre>
p01372
<!-- begin en only --> <!--<h3><U>6÷2(1+2)</U></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><U>6÷2(1+2)</U></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> 数孊科の孊生であるきたたさ君は数孊はずおも埗意なのだが算数はあたり埗意ではない 特に挔算子の優先順䜍が苊手で カッコの䞭を先に蚈算するずいうのはわかるのだが "+" ず "*" のどちらを優先したら良いかずか耇数の挔算子が䞊んでいるずきに巊から蚈算したら良いのか右から蚈算したら良いのか芚えおおらず その時の気分で奜きな順番で蚈算をしおいる䟋えば"1*1-1+1"ずいう数匏を前から"((1*1)-1)+1"ずいう順番で蚈算する堎合もあれば真ん䞭から"(1*(1-1))+1"ずいう順番で蚈算する堎合さえある たた分数や小数も苊手で割り算では垞に絶察倀の小さい方に䞞め小数郚を切り捚おお敎数にしおしたう 割る数がれロであった堎合にはきたたさ君はどこかで間違えたず思っおもう䞀床最初から蚈算しなおすこずにしおいる </p> <p> きたたさ君はどんな順番で蚈算しおも最終的な蚈算結果は同じになるず䞻匵しおいるのであなたにはそれが間違いであるず瀺すために䞎えられた数匏に察しお きたたさ君の蚈算結果が䜕通りあり埗るかを求めるプログラムを曞いお欲しい ただし挔算の順番が異なっおいおも最終的な答えが同じならば䞀぀ず数えるものずし たた䞎えられる数匏は少なくずも䞀぀はれロ割が発生しない挔算順序が存圚しいかなる挔算順序で蚈算した堎合でも蚈算結果ず途䞭で珟れる数の絶察倀は垞に 10<sup>9</sup> 以䞋であるこずが保蚌されおいる </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力はひず぀以䞊の行からなり入力の各行は数匏ひず぀を含む数匏の文法は以䞋の BNF で䞎えられる </p> <pre> &lt;expr&gt; ::= &lt;num&gt; | "(" &lt;expr&gt; ")" | &lt;expr&gt; "+" &lt;expr&gt; | &lt;expr&gt; "-" &lt;expr&gt; | &lt;expr&gt; "*" &lt;expr&gt; | &lt;expr&gt; "/" &lt;expr&gt; &lt;num&gt; ::= &lt;digit&gt; | &lt;num&gt; &lt;digit&gt; &lt;digit&gt; ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" </pre> <p> すべおの数匏はこの構文芏則に埓うたた入力行の長さは 200 文字を超えないひず぀の数匏が含む挔算子 ( "+" , "-" , "*" , "/" ) の数は 10 個を超えない </p> <p> 入力の終わりは "#" ひず぀だけからなる行によっお瀺される </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> それぞれの数匏に぀いおきたたさ君の蚈算結果が䜕通りあり埗るかを出力せよ出力は数匏ひず぀ごずに 1 行ずする </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 6/2*(1+2) 1-1-1 (1-1-1)/2 # </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 2 2 1 </pre> </div>
p01688
<h2>B - Doctor Course Is Recommended / D進どうですか</h2> <h3>Story</h3> <p>DのひずはD進を決意したので、博士埌期課皋入孊詊隓を受けるこずにした。筆蚘詊隓はマヌクシヌト圢匏であった。自身の専門分野の問題ばかりだったので、Dのひずはすぐにすべおの正答を導くこずができた。しかし、ここで倧きな問題に気づいた。Dのひずは宗教䞊の理由から、解答甚玙には'D'ずしか曞くこずができなかったのだ。たた、'D'ず曞くためには尋垞ではない集䞭力を䜿うため'D'ず曞くこずのできる個数も決たっおいる。Dのひずが本圓にD進するこずができるか調べるため、解答・配点を螏たえ、䞊蚘の条件を満たした䞊で埗られる最倧の埗点を求めおみよう。</p> <h3>Problem</h3> <p>'A','B','C','D','E'の<var>5</var>択からなるマヌクシヌト問題がある。<var>1</var>぀の解答欄は空欄<var>1</var>マス、もしくは<var>2</var>マスから構成されおおり、それぞれの解答欄に぀いお、マス党おが想定されおいる解答ず等しいずき、解答欄に割り圓おられた点数を埗る。解答欄毎の解答ず配点が䞎えられる。<var>D</var>個のマスたで'D'ずマヌクし、残りのマスを空マスにしなければならないずき、埗られる点数の最倧倀を求めよ。</p> <h3>Input</h3> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre><var>D</var> <var>x</var> <var>a_1</var> <var>p_1</var> <var>...</var> <var>a_x</var> <var>p_x</var> <var>y</var> <var>b_1</var><var>c_1</var> <var>q_1</var> <var>...</var> <var>b_y</var><var>c_y</var> <var>q_y</var></pre> <p><var>1</var>行目は、'D'ず曞くこずのできる最倧回数を衚す<var>1</var>぀の敎数<var>D</var>からなる。 <var>2</var>行目は、空欄<var>1</var>マスからなる解答欄の個数を衚す<var>1</var>぀の敎数<var>x</var>からなる。 続く<var>x</var>行は、空欄<var>1</var>マスからなる解答欄の情報が䞎えられる。 <var>i+2</var>行目(<var>1 \leq i \leq x</var>)は空欄<var>1</var>マスからなる<var>i</var>番目の解答欄の正答を衚す文字<var>a_i</var>、配点を衚す敎数<var>p_i</var>が空癜区切りで曞かれおいる。 <var>x+3</var>行目は、空欄<var>2</var>マスからなる解答欄の個数を衚す<var>1</var>぀の敎数<var>y</var>からなる。 続く<var>y</var>行は、空欄<var>2</var>マスからなる解答欄の情報が䞎えられる。 <var>j+x+3</var>行目(<var>1 \leq j \leq y</var>)は空欄<var>2</var>マスからなる<var>j</var>番目の解答欄の正答を衚す<var>2</var>぀の文字<var>b_j</var>ず<var>c_j</var>、配点を衚す敎数<var>q_j</var>からなる。 <var>b_j</var>ず<var>c_j</var>の間に空癜は存圚しないが、<var>c_j</var>ず<var>q_j</var>の間は空癜で区切られおいる。</p> <p>制玄:</p> <!--<blockquote>--> <ul> <li><var>1 \leq D \leq 13</var> (=0xD)</li> <li><var>0 \leq x</var>, <var>0 \leq y</var>, <var>1 \leq x + 2y \leq 20</var></li> <li><var>a_i</var>, <var>b_j</var>, <var>c_j</var> <var>\in \{A,B,C,D,E\}</var></li> <li><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_eq" alt="sum" align="middle"/></li> </ul> <!--</blockquote>--> <h3>Output</h3> <p>䞊蚘の制玄を満たしお埗られる最倧埗点を1行に出力せよ。行の最埌では必ず改行を行うこず。</p> <h3>Sample Input 1</h3> <pre>2 3 D 30 D 50 D 20 0</pre> <h3>Sample Output 1</h3> <pre>80</pre> <p>1,2番目の解答欄にDず蚘入し、3番目の解答欄を空癜ずするこずで最倧埗点80が埗られる。</p> <h3>Sample Input 2</h3> <pre>4 0 2 DB 60 DD 40</pre> <h3>Sample Output 2</h3> <pre>40</pre> <p>2぀のマスからなる解答欄は䞡方ずも正解しなければ埗点が埗られない。</p> <h3>Sample Input 3</h3> <pre>13 2 C 15 A 23 2 BD 42 EE 20</pre> <h3>Sample Output 3</h3> <pre>0</pre> <p>D進だめです。</p> <h3>Sample Input 4</h3> <pre>3 3 D 10 D 15 D 45 1 DD 30</pre> <h3>Sample Output 4</h3> <pre>75</pre> <h3>Sample Input 5</h3> <pre>3 3 D 25 D 20 D 25 1 DD 30</pre> <h3>Sample Output 5</h3> <pre>70</pre>
p00133
<H1>パタヌンの回転</H1> <p> 8 文字 &times; 8 行のパタヌンを右回りに 90 床、180 床、270 床回転させお出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 8 文字 &times; 8 行からなるパタヌンが䞎えられたす。文字は、英数字、半角シャヌプ '#' 、アスタリスク '*' からなりたす。 </p> <H2>Output</H2> <p> 次の圢匏で、回転させたパタヌンを出力しおください。 </p> <pre> 90半角数字固定 90床回転させたパタヌン 180半角数字固定 180床回転させたパタヌン 270半角数字固定 270床回転させたパタヌン </pre> <H2>Sample Input</H2> <pre> #******* #******* #******* #******* #******* #******* #******* ######## </pre> <H2>Output for the Sample Input</H2> <pre> 90 ######## #******* #******* #******* #******* #******* #******* #******* 180 ######## *******# *******# *******# *******# *******# *******# *******# 270 *******# *******# *******# *******# *******# *******# *******# ######## </pre>
p00563
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>Rope</h1> <p> JOI is a baby playing with a rope. The rope has length $N$, and it is placed as a straight line from left to right. The rope consists of $N$ cords. The cords are connected as a straight line. Each cord has length 1 and thickness 1. In total, $M$ colors are used for the rope. The color of the $i$-th cord from left is $C_i$ ($1 \leq C_i \leq M$). </p> <p> JOI is making the rope shorter. JOI repeats the following procedure until the length of the rope becomes 2. </p> <ul> <li> Let $L$ be the length of the rope. Choose an integer $j$ ($1 \leq j &lt; L$). Shorten the rope by combining cords so that the point of length $j$ from left on the rope becomes the leftmost point. More precisely, do the following: <ul> <li> If $j \leq L/2$, for each $i$ ($1 \leq i \leq j$), combine the $i$-th cord from left with the ($2j - i + 1$)-th cord from left. By this procedure, the rightmost point of the rope becomes the rightmost point. The length of the rope becomes $L - j$.</li> <li> If $j > L/2$, for each $i$ ($2j - L + 1 \leq i \leq j$), combine the $i$-th cord from left with the ($2j - i + 1$)-th cord from left. By this procedure, the leftmost point of the rope becomes the rightmost point. The length of the rope becomes $j$. </li> </ul> </li> <li> If a cord is combined with another cord, the colors of the two cords must be the same. We can change the color of a cord before it is combined with another cord. The cost to change the color of a cord is equal to the thickness of it. After adjusting the colors of two cords, they are combined into a single cord; its thickness is equal to the sum of thicknesses of the two cords. </li> </ul> <p> JOI wants to minimize the total cost of procedures to shorten the rope until it becomes length 2. For each color, JOI wants to calculate the minimum total cost of procedures to shorten the rope so that the final rope of length 2 contains a cord with that color. </p> <p> Your task is to solve this problem instead of JOI. </p> <h3>Task</h3> <p> Given the colors of the cords in the initial rope, write a program which calculates, for each color, the minimum total cost of procedures to shorten the rope so that the final rope of length 2 contains a cord with that color. </p> <h3>Input</h3> <p> Read the following data from the standard input. </p> <ul> <li> The first line of input contains two space separated integers $N$, $M$. This means the rope consists of $N$ cords, and $M$ colors are used for the cords.</li> <li> The second line contains $N$ space separated integers $C_1, C_2, ... ,C_N$. This means the color of the $i$-th cord from left is $C_i$ ($1 \leq C_i \leq M$).</li> </ul> <h3>Output</h3> <p> Write $M$ lines to the standard output. The $c$-th line ($1 \leq c \leq M$) contains the minimum total cost of procedures to shorten the rope so that the final rope of length 2 contains a cord with color $c$. </p> <h3>Constraints</h3> <p> All input data satisfy the following conditions. </p> <ul> <li>$ 2 \leq N \leq 1 000 000 $</li> <li>$ 1 \leq M \leq N$</li> <li>$ 1 \leq C_i \leq M (1 \leq i \leq N)$</li> <li>For each $c$ with $1 \leq c \leq M$, there exists an integer $i$ with $C_i = c$.</li> </ul> <h3>Sample Input and Output</h3> <h3>Sample Input 1</h3> <pre> 5 3 1 2 3 3 2 </pre> <h3>Sample Output 1</h3> <pre> 2 1 1 </pre> <p> By the following procedures, we can shorten the rope so that the final rope of length 2 contains a cord with color 1. The total cost is 2. </p> <ul> <li> Change the color of the second cord from left to 1. Shorten the rope so that the point of length 1 from left on the rope becomes the leftmost point. The colors of cords become 1, 3, 3, 2. The thicknesses of cords become 2, 1, 1, 1.</li> <li> Change the color of the 4-th cord from left to 1. Shorten the rope so that the point of length 2 from left on the rope becomes the leftmost point. The colors of cords become 3, 1. The thicknesses of cords become 2, 3.</li> </ul> <p> By the following procedures, we can shorten the rope so that the final rope of length 2 contains a cord with color 2, 3. The total cost is 1. </p> <ul> <li> Shorten the rope so that the point of length 3 from left on the rope becomes the leftmost point. The colors of cords become 3, 2, 1. The thicknesses of cords become 2, 2, 1.</li> <li> Change the color of the third cord from left to 2. Shorten the rope so that the point of length 2 from left on the rope becomes the leftmost point. The colors of cords become 2, 3. The thicknesses of cords become 3, 2.</li> </ul> <h3>Sample Input 2</h3> <pre> 7 3 1 2 2 1 3 3 3 </pre> <h3>Sample Output 2</h3> <pre> 2 2 2 </pre> <p> By the following procedures, we can shorten the rope so that the final rope of length 2 contains a cord with color 1. The total cost is 2. </p> <ul> <li> Shorten the rope so that the point of length 2 from left on the rope becomes the leftmost point.</li> <li> Change the color of the leftmost cord to 1. Shorten the rope so that the point of length 1 from left on the rope becomes the leftmost point. Note that the cost to change the color is 2 because the thickness of the cord is 2.</li> <li> Shorten the rope so that the point of length 3 from left on the rope becomes the leftmost point.</li> <li> Shorten the rope so that the point of length 1 from left on the rope becomes the leftmost point.</li> </ul> <h3>Sample Input 3</h3> <pre> 10 3 2 2 1 1 3 3 2 1 1 2 </pre> <h3>Sample Output 3</h3> <pre> 3 3 4 </pre> <p> Before shortening the rope, we may change the colors of several cords. </p> <br/> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creatie Commonse License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2016/2017-ho/index.html">The 16th Japanese Olympiad in Informatics (JOI 2016/2017) Final Round</a> </p> </div>
p00099
<H1>ワカサギ釣り倧䌚 2</H1> <p> 桧原湖でワカサギ釣り倧䌚が行われたした。今回はキャッチリリヌスが掚奚されおいるようです。 </p> <p> 参加者番号ず釣った匹数たたはリリヌスした匹数を぀のむベントずしお順番に読み蟌み、各むベントの盎埌に最も倚くのワカサギを手元に獲埗しおいる参加者番号ず匹数を出力するプログラムを䜜成しおください。最も倚く獲埗しおいる参加者が耇数いる堎合あるいは党おの参加者が 0 匹の堎合は、その䞭で参加者番号が最も小さい䞀人を出力しおください。 </p> <H2>入力</H2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>n</var> <var>q</var> <var>a<sub>1</sub></var> <var>v<sub>1</sub></var> <var>a<sub>2</sub></var> <var>v<sub>2</sub></var> : <var>a<sub>q</sub></var> <var>v<sub>q</sub></var> </pre> <p> <var>n</var> (1 &le; <var>n</var> &le; 1000000) は参加者の数、<var>q</var> (1 &le; <var>q</var> &le; 100000)はむベントの数を衚す。<var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; <var>n</var>) &nbsp; <var>v<sub>i</sub></var> ( -100 &le; <var>v<sub>i</sub></var> &le; 100) は、<var>i</var> 番目のむベントで参加者 <var>a<sub>i</sub></var> が <var>v<sub>i</sub></var> 匹獲埗あるいはリリヌスしたこずを瀺す。<var>v<sub>i</sub></var> は正の倀が獲埗、負の倀がリリヌスを瀺し、0 が䞎えられるこずはない。 </p> <H2>出力</H2> <p> 各むベントごずに、最も倚くのワカサギを手元に獲埗しおいる参加者の参加者番号ず匹数を぀の空癜区切りで行に出力する。 </p> <H2>入力䟋1</H2> <pre> 3 5 1 4 2 5 1 3 3 6 2 7 </pre> <H2>出力䟋1</H2> <pre> 1 4 2 5 1 7 1 7 2 12 </pre> <H2>入力䟋2</H2> <pre> 3 5 1 4 2 5 2 -3 3 4 1 -1 </pre> <H2>出力䟋2</H2> <pre> 1 4 2 5 1 4 1 4 3 4 </pre>
p03066
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find the number, modulo <var>998244353</var>, of sequences of length <var>N</var> consisting of <var>0</var>, <var>1</var> and <var>2</var> such that none of their contiguous subsequences totals to <var>X</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 3000</var></li> <li><var>1 \leq X \leq 2N</var></li> <li><var>N</var> and <var>X</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number, modulo <var>998244353</var>, of sequences that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>14 </pre> <p><var>14</var> sequences satisfy the condition: <var>(0,0,0),(0,0,1),(0,0,2),(0,1,0),(0,1,1),(0,2,0),(0,2,2),(1,0,0),(1,0,1),(1,1,0),(2,0,0),(2,0,2),(2,2,0)</var> and <var>(2,2,2)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1179 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1024 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>9 13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>18402 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>314 159 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>459765451 </pre></section> </div> </span>
p03436
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem statement</h3> <p>We have an <var>H \times W</var> grid whose squares are painted black or white. The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is denoted as <var>(i, j)</var>.<br/> Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square <var>(1, 1)</var>. The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square <var>(H, W)</var> passing only white squares.<br/> Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square <var>(1, 1)</var> and <var>(H, W)</var>. Also, changes of color must all be carried out before the beginning of the game.<br/> When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print <var>-1</var> if the game cannot be completed, that is, Kenus can never reach square <var>(H, W)</var> regardless of how Snuke changes the color of the squares. </p> <p>The color of the squares are given to you as characters <var>s_{i, j}</var>. If square <var>(i, j)</var> is initially painted by white, <var>s_{i, j}</var> is <code>.</code>; if square <var>(i, j)</var> is initially painted by black, <var>s_{i, j}</var> is <code>#</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>H</var> is an integer between <var>2</var> and <var>50</var> (inclusive).</li> <li><var>W</var> is an integer between <var>2</var> and <var>50</var> (inclusive).</li> <li><var>s_{i, j}</var> is <code>.</code> or <code>#</code> <var>(1 \leq i \leq H, 1 \leq j \leq W)</var>.</li> <li><var>s_{1, 1}</var> and <var>s_{H, W}</var> are <code>.</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>s_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W}</var> <var>s_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W}</var> <var>:</var> <var>:</var> <var>s_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the maximum possible score that Snuke can achieve, or print <var>-1</var> if the game cannot be completed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 ..# #.. ... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The score <var>2</var> can be achieved by changing the color of squares as follows:</p> <p><img alt="Explanation of Sample 1" src="https://img.atcoder.jp/abc088/bc944898899615e35f898654b68cd517.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 37 ..................................... ...#...####...####..###...###...###.. ..#.#..#...#.##....#...#.#...#.#...#. ..#.#..#...#.#.....#...#.#...#.#...#. .#...#.#..##.#.....#...#.#.###.#.###. .#####.####..#.....#...#..##....##... .#...#.#...#.#.....#...#.#...#.#...#. .#...#.#...#.##....#...#.#...#.#...#. .#...#.####...####..###...###...###.. ..................................... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>209 </pre></section> </div> </span>
p03965
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of <var>N</var> turns. In each turn, each player plays one of the two <em>gestures</em>, <em>Rock</em> and <em>Paper</em>, as in Rock-paper-scissors, under the following condition:</p> <p>(※) After each turn, (the number of times the player has played Paper)<var>≩</var>(the number of times the player has played Rock).</p> <p>Each player's score is calculated by (the number of turns where the player wins) <var>-</var> (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.</p> <p><em>(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)</em></p> <p>With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the <var>N</var> turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.</p> <p>The gesture that TopCoDeer will play in each turn is given by a string <var>s</var>. If the <var>i</var>-th <var>(1≩i≩N)</var> character in <var>s</var> is <code>g</code>, TopCoDeer will play Rock in the <var>i</var>-th turn. Similarly, if the <var>i</var>-th <var>(1≩i≩N)</var> character of <var>s</var> in <code>p</code>, TopCoDeer will play Paper in the <var>i</var>-th turn.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩10^5</var></li> <li><var>N=|s|</var></li> <li>Each character in <var>s</var> is <code>g</code> or <code>p</code>.</li> <li>The gestures represented by <var>s</var> satisfy the condition (※).</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 AtCoDeer's maximum possible score.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>gpg </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> <p>Playing the same gesture as the opponent in each turn results in the score of <var>0</var>, which is the maximum possible score.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>ggppgggpgg </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>For example, consider playing gestures in the following order: Rock, Paper, Rock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three victories and suffers one defeat, resulting in the score of <var>2</var>, which is the maximum possible score.</p></section> </div> </span>
p01958
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <H1> Prime-Factor Prime </H1> <p> A positive integer is called a "prime-factor prime" when the number of its prime factors is prime. For example, $12$ is a prime-factor prime because the number of prime factors of $12 = 2 \times 2 \times 3$ is $3$, which is prime. On the other hand, $210$ is not a prime-factor prime because the number of prime factors of $210 = 2 \times 3 \times 5 \times 7$ is $4$, which is a composite number. </p> <p> In this problem, you are given an integer interval $[l, r]$. Your task is to write a program which counts the number of prime-factor prime numbers in the interval, i.e. the number of prime-factor prime numbers between $l$ and $r$, inclusive. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $l$ $r$ </pre> <p> A line contains two integers $l$ and $r$ ($1 \leq l \leq r \leq 10^9$), which presents an integer interval $[l, r]$. You can assume that $0 \leq r-l < 1,000,000$. </p> <H2>Output</H2> <p> Print the number of prime-factor prime numbers in $[l,r]$. </p> <H2>Sample Input 1</H2> <pre> 1 9 </pre> <H2>Output for Sample Input 1</H2> <pre> 4 </pre> <H2>Sample Input 2</H2> <pre> 10 20 </pre> <H2>Output for Sample Input 2</H2> <pre> 6 </pre> <H2>Sample Input 3</H2> <pre> 575 57577 </pre> <H2>Output for Sample Input 3</H2> <pre> 36172 </pre> <H2>Sample Input 4</H2> <pre> 180 180 </pre> <H2>Output for Sample Input 4</H2> <pre> 1 </pre> <H2>Sample Input 5</H2> <pre> 9900001 10000000 </pre> <H2>Output for Sample Input 5</H2> <pre> 60997 </pre> <H2>Sample Input 6</H2> <pre> 999000001 1000000000 </pre> <H2>Output for Sample Input 6</H2> <pre> 592955 </pre> <p> In the first example, there are 4 prime-factor primes in $[l,r]$: $4,6,8,$ and $9$. </p>
p02677
<span class="lang-en"> <p>Score: <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Consider an analog clock whose hour and minute hands are <var>A</var> and <var>B</var> centimeters long, respectively.</p> <p>An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands <var>12</var> hours and <var>1</var> hour to make one full rotation, respectively.</p> <p>At <var>0</var> o'clock, the two hands overlap each other. <var>H</var> hours and <var>M</var> minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>All values in input are integers.</li> <li><var>1 \leq A, B \leq 1000</var></li> <li><var>0 \leq H \leq 11</var></li> <li><var>0 \leq M \leq 59</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>H</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 9 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5.00000000000000000000 </pre> <p>The two hands will be in the positions shown in the figure below, so the answer is <var>5</var> centimeters.</p> <p><img alt="The clock at &lt;var&gt;9&lt;/var&gt; o'clock" src="https://img.atcoder.jp/ghi/when_a_nameless_star_falls_into_the_sky.png" title="The clock at 9 o'clock"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 4 10 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4.56425719433005567605 </pre> <p>The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.</p> <p><img alt="The clock at &lt;var&gt;10:40&lt;/var&gt;" src="https://img.atcoder.jp/ghi/when_flower_petals_flutter.png" title="The clock at 10:40"/></p></section> </div> </span>
p02227
UnionFindランダム生成
p03820
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has decided to play with <var>N</var> cards and a deque (that is, a double-ended queue). Each card shows an integer from <var>1</var> through <var>N</var>, and the deque is initially empty.</p> <p>Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from <var>1</var> to <var>N</var>. Then, he will perform the following action <var>N</var> times: take out the card from the beginning or the end of the deque and eat it.</p> <p>Afterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the <var>K</var>-th element is <var>1</var>. Print the answer modulo <var>10^{9} + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ K ≩ N ≩ 2{,}000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer modulo <var>10^{9} + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>There is one sequence satisfying the condition: <var>1,2</var>. One possible way to obtain this sequence is the following:</p> <ul> <li>Insert both cards, <var>1</var> and <var>2</var>, at the end of the deque.</li> <li>Eat the card at the beginning of the deque twice.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>17 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>262144 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2000 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>674286644 </pre></section> </div> </span>
p02732
<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> balls. The <var>i</var>-th ball has an integer <var>A_i</var> written on it.<br/> For each <var>k=1, 2, ..., N</var>, solve the following problem and print the answer. </p> <ul> <li>Find the number of ways to choose two distinct balls (disregarding order) from the <var>N-1</var> balls other than the <var>k</var>-th ball so that the integers written on them are equal.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>3 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq A_i \leq N</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>For each <var>k=1,2,...,N</var>, print a line containing the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 1 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 2 3 2 3 </pre> <p>Consider the case <var>k=1</var> for example. The numbers written on the remaining balls are <var>1,2,1,2</var>.<br/> From these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.<br/> Thus, the answer for <var>k=1</var> is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 0 0 0 </pre> <p>No two balls have equal numbers written on them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 3 3 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6 6 6 6 6 </pre> <p>Any two balls have equal numbers written on them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 1 2 1 4 2 1 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>5 7 5 7 7 5 7 5 </pre></section> </div> </span>
p02698
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices, whose <var>i</var>-th edge connects Vertex <var>u_i</var> and Vertex <var>v_i</var>. Vertex <var>i</var> has an integer <var>a_i</var> written on it. For every integer <var>k</var> from <var>1</var> through <var>N</var>, solve the following problem:</p> <ul> <li>We will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex <var>1</var> to Vertex <var>k</var>, in the order they appear. Find the length of the longest increasing subsequence of this sequence.</li> </ul> <p>Here, the longest increasing subsequence of a sequence <var>A</var> of length <var>L</var> is the subsequence <var>A_{i_1} , A_{i_2} , ... , A_{i_M}</var> with the greatest possible value of <var>M</var> such that <var>1 \leq i_1 &lt; i_2 &lt; ... &lt; i_M \leq L</var> and <var>A_{i_1} &lt; A_{i_2} &lt; ... &lt; A_{i_M}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq a_i \leq 10^9</var></li> <li><var>1 \leq u_i , v_i \leq N</var></li> <li><var>u_i \neq v_i</var></li> <li>The given graph is a tree.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var> <var>u_1</var> <var>v_1</var> <var>u_2</var> <var>v_2</var> <var>:</var> <var>u_{N-1}</var> <var>v_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>k</var>-th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex <var>1</var> to Vertex <var>k</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 1 2 5 3 4 6 7 3 2 4 1 2 2 3 3 4 4 5 3 6 6 7 1 8 8 9 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 3 3 4 4 5 2 2 3 </pre> <p>For example, the sequence <var>A</var> obtained from the shortest path from Vertex <var>1</var> to Vertex <var>5</var> is <var>1,2,5,3,4</var>. Its longest increasing subsequence is <var>A_1, A_2, A_4, A_5</var>, with the length of <var>4</var>.</p></section> </div> </span>
p02362
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Single Source Shortest Path (Negative Edges)</H1> <br/> <H2>Input</H2> <p> An edge-weighted graph <var>G</var> (<var>V</var>, <var>E</var>) and the source <var>r</var>. </p> <pre> |<var>V</var>| |<var>E</var>| <var>r</var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>d<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>d<sub>|E|-1</sub></var> </pre> <p> <var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in <var>G</var>. The graph vertices are named with the numbers 0, 1,..., <var>|V|-1</var> respectively. <var>r</var> is the source of the graph. </p> <p> <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target vertices of <var>i</var>-th edge (directed) and <var>d<sub>i</sub></var> represents the cost of the <var>i</var>-th edge. </p> <H2>Output</H2> <p> If the graph contains a negative cycle (a cycle whose sum of edge costs is a negative value) which is reachable from the source <var>r</var>, print <pre> NEGATIVE CYCLE </pre> <p> in a line. </p> <p> Otherwise, print </p> <pre> <var>c<sub>0</sub></var> <var>c<sub>1</sub></var> : <var>c<sub>|V|-1</sub></var> </pre> <p> The output consists of <var>|V|</var> lines. Print the cost of the shortest path from the source <var>r</var> to each vertex 0, 1, ... <var>|V|-1</var> in order. If there is no path from the source to a vertex, print "<span>INF</span>". </p> <H2>Constraints</H2> <ul> <li> 1 &le; <var>|V|</var> &le; 1000</li> <li> 0 &le; <var>|E|</var> &le; 2000</li> <li> -10000 &le; <var>d<sub>i</sub></var> &le; 10000</li> <li> There are no parallel edges</li> <li> There are no self-loops</li> </ul> <H2>Sample Input 1</H2> <pre> 4 5 0 0 1 2 0 2 3 1 2 -5 1 3 1 2 3 2 </pre> <H2>Sample Output 1</H2> <pre> 0 2 -3 -1 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 6 0 0 1 2 0 2 3 1 2 -5 1 3 1 2 3 2 3 1 0 </pre> <H2>Sample Output 2</H2> <pre> NEGATIVE CYCLE </pre> <br/> <H2>Sample Input 3</H2> <pre> 4 5 1 0 1 2 0 2 3 1 2 -5 1 3 1 2 3 2 </pre> <H2>Sample Output 3</H2> <pre> INF 0 -5 -3 </pre>
p03123
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has <var>R</var> red balls and <var>B</var> blue balls. He distributes them into <var>K</var> boxes, so that no box is empty and no two boxes are identical. Compute the maximum possible value of <var>K</var>.</p> <p>Formally speaking, let's number the boxes <var>1</var> through <var>K</var>. If Box <var>i</var> contains <var>r_i</var> red balls and <var>b_i</var> blue balls, the following conditions must be satisfied:</p> <ul> <li>For each <var>i</var> (<var>1 \leq i \leq K</var>), <var>r_i &gt; 0</var> or <var>b_i &gt; 0</var>.</li> <li>For each <var>i, j</var> (<var>1 \leq i &lt; j \leq K</var>), <var>r_i \neq r_j</var> or <var>b_i \neq b_j</var>.</li> <li><var>\sum r_i = R</var> and <var>\sum b_i = B</var> (no balls can be left outside the boxes).</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq R, B \leq 10^{9}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>R</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of <var>K</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>The following picture shows one possible way to achieve <var>K = 5</var>:</p> <p><img alt="" src="https://img.atcoder.jp/wtf19/9ea9530037df204a84029678052ab593.png"/></p></section> </div> </span>
p03089
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has an empty sequence <var>a</var>.</p> <p>He will perform <var>N</var> operations on this sequence.</p> <p>In the <var>i</var>-th operation, he chooses an integer <var>j</var> satisfying <var>1 \leq j \leq i</var>, and insert <var>j</var> at position <var>j</var> in <var>a</var> (the beginning is position <var>1</var>).</p> <p>You are given a sequence <var>b</var> of length <var>N</var>. Determine if it is possible that <var>a</var> is equal to <var>b</var> after <var>N</var> operations. If it is, show one possible sequence of operations that achieves it.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq b_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>b_1</var> <var>\dots</var> <var>b_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is no sequence of <var>N</var> operations after which <var>a</var> would be equal to <var>b</var>, print <code>-1</code>. If there is, print <var>N</var> lines. In the <var>i</var>-th line, the integer chosen in the <var>i</var>-th operation should be printed. If there are multiple solutions, any of them is accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 1 2 </pre> <p>In this sequence of operations, the sequence <var>a</var> changes as follows:</p> <ul> <li>After the first operation: <var>(1)</var></li> <li>After the second operation: <var>(1,1)</var></li> <li>After the third operation: <var>(1,2,1)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p><var>2</var> cannot be inserted at the beginning of the sequence, so this is impossible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 1 1 1 2 2 1 2 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 2 3 1 2 2 1 1 </pre></section> </div> </span>
p03573
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given three integers, <var>A</var>, <var>B</var> and <var>C</var>.<br/> Among them, two are the same, but the remaining one is different from the rest.<br/> For example, when <var>A=5,B=7,C=5</var>, <var>A</var> and <var>C</var> are the same, but <var>B</var> is different.<br/> Find the one that is different from the rest among the given three integers. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>-100 \leq A,B,C \leq 100</var> </li> <li><var>A</var>, <var>B</var> and <var>C</var> are integers.</li> <li>The input satisfies the condition in the statement.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format: </p> <pre><var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Among <var>A</var>, <var>B</var> and <var>C</var>, print the integer that is different from the rest.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 7 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>This is the same case as the one in the statement.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> <p>In this case, <var>C</var> is the one we seek.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>-100 100 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-100 </pre></section> </div> </span>
p01260
<H1><font color="#000">Problem A:</font> Girls' Party</H1> <p> Issac H. Ives hosted a party for girls. He had some nice goods and wanted to distribute them to the girls as the presents. However, there were not enough number of presents and thus he needed to decide who would take them. He held a game for that purpose. </p> <p> Before the game, Issac had all the girls divided into two teams: he named his close friends Bella and Gabriella as two leaders and asked other girls to join either Bella or Gabriella. After the two teams were formed, Issac asked the girls to form one big circle. </p> <p> The rule of the game was as follows. The game consisted of a number of rounds. In each round, the girls called numbers from 1 to <i>N</i> in clockwise order (<i>N</i> was a number fixed before the game started). The girl calling the number <i>N</i> was told to get out of the circle and excluded from the rest of the game. Then the next round was started from the next girl, that is, the girls called the numbers again, and the one calling N left the circle. This was repeated until only the members of either team remained. The remaining team won the game. </p> <p> As the game went on, Bella found far more girls of her team excluded than those of Gabriella’s team. Bella complained it, and requested Issac to make the next round begin with a call of zero instead of one. Issac liked her idea as he was a computer scientist, and accepted her request. After that round, many girls of Gabriella’s team came to leave the circle, and eventually Bella’s team won the game and got the presents from Issac. </p> <p> Now let’s consider the following situation. There are two teams led by Bella and Gabriella respectively, where they does not necessarily have the same numbers of members. Bella is allowed to change the starting number from one to zero at up to one round (regardless the starting girl belongs to her team or not). We want to know how many girls of Bella’s team at most can remain in the circle. You are requested to write a program for it. </p> <H2>Input</H2> <p> The input is a sequence of datasets. The first line of the input contains the number of datasets. The number of datasets does not exceed 200. </p> <p> Each dataset consists of a line with a positive integer <i>N</i> (1 &le; <i>N</i> &le; 2<sup>30</sup>) and a string that specifies the clockwise order of the girls. Each character of the string is either ‘<span>B</span>’ (that denotes a member of Bella’s team) or ‘<span>G</span>’ (Gabriella’s team). The first round begins with the girl indicated by the first character of the string. The length of the string is between 2 and 200 inclusive. </p> <H2>Output</H2> <p> For each dataset, print in a line the maximum possible number of the girls of Bella’s team remaining in the circle, or “<span>0</span>” (without quotes) if there are no ways for Bella’s team to win the game. </p> <H2>Sample Input</H2> <pre> 6 1 GB 3 GBGBBB 9 BBBGBBBGGG 9 GGBGBBGBBB 7 GBGGGGBGGG 3 BBBBBGBBBB </pre> <H2>Output for the Sample Input</H2> <pre> 1 4 4 1 0 8 </pre>
p00888
<H1><font color="#000">Problem E:</font> The Two Men of the Japanese Alps</H1> <p> Two experienced climbers are planning a first-ever attempt: they start at two points of the equal altitudes on a mountain range, move back and forth on a single route keeping their altitudes equal, and finally meet with each other at a point on the route. A wise man told them that if a route has no point lower than the start points (of the equal altitudes) there is at least a way to achieve the attempt. This is the reason why the two climbers dare to start planning this fancy attempt. </p> <p> The two climbers already obtained altimeters (devices that indicate altitude) and communication devices that are needed for keeping their altitudes equal. They also picked up a candidate route for the attempt: the route consists of consequent line segments without branches; the two starting points are at the two ends of the route; there is no point lower than the two starting points of the equal altitudes. An illustration of the route is given in Figure E.1 (this figure corresponds to the first dataset of the sample input). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_theTwoMenOfTheJapaneseAlps"> <p> Figure E.1: An illustration of a route </p> </center> <p> The attempt should be possible for the route as the wise man said. The two climbers, however, could not find a pair of move sequences to achieve the attempt, because they cannot keep their altitudes equal without a complex combination of both forward and backward moves. For example, for the route illustrated above: a climber starting at <i>p</i><sub>1</sub> (say <i>A</i>) moves to <i>s</i>, and the other climber (say <i>B</i>) moves from <i>p</i><sub>6</sub> to <i>p</i><sub>5</sub>; then <i>A</i> moves back to <i>t</i> while <i>B</i> moves to <i>p</i><sub>4</sub>; finally <i>A</i> arrives at <i>p</i><sub>3</sub> and at the same time <i>B</i> also arrives at <i>p</i><sub>3</sub>. Things can be much more complicated and thus they asked you to write a program to find a pair of move sequences for them. </p> <p> There may exist more than one possible pair of move sequences, and thus you are requested to find the pair of move sequences with the shortest length sum. Here, we measure the length along the route surface, i.e., an uphill path from (0, 0) to (3, 4) has the length of 5. </p> <H2>Input</H2> <p> The input is a sequence of datasets. </p> <p> The first line of each dataset has an integer indicating the number of points <i>N</i> (2 &le; <i>N</i> &le; 100) on the route. Each of the following <i>N</i> lines has the coordinates (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) (<i>i</i> = 1, 2, ... , <i>N</i>) of the points: the two start points are (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) and (<i>x<sub>N</sub></i>, <i>y<sub>N</sub></i>); the line segments of the route connect (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) and (<i>x</i><sub><i>i</i>+1</sub>, <i>y</i><sub><i>i</i>+1</sub>) for <i>i</i> = 1, 2, ... , <i>N</i> - 1. Here, <i>x</i><sub><i>i</i></sub> is the horizontal distance along the route from the start point <i>x</i><sub>1</sub>, and <i>y<sub>i</sub></i> is the altitude relative to the start point <i>y</i><sub>1</sub>. All the coordinates are non-negative integers smaller than 1000, and inequality <i>x<sub>i</sub></i> &lt; <i>x</i><sub><i>i</i>+1</sub> holds for <i>i</i> = 1, 2, .. , <i>N</i> - 1, and 0 = <i>y</i><sub>1</sub> = <i>y<sub>N</sub></i> &le; <i>y<sub>i</sub></i> for <i>i</i> = 2, 3, ... , <i>N</i> - 1. </p> <p> The end of the input is indicated by a line containing a zero. </p> <H2>Output</H2> <p> For each dataset, output the minimum sum of lengths (along the route) of move sequences until the two climbers meet with each other at a point on the route. Each output value may not have an error greater than 0.01. </p> <H2>Sample Input</H2> <pre> 6 0 0 3 4 9 12 17 6 21 9 33 0 5 0 0 10 0 20 0 30 0 40 0 10 0 0 1 2 3 0 6 3 9 0 11 2 13 0 15 2 16 2 18 0 7 0 0 150 997 300 1 450 999 600 2 750 998 900 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 52.5 40.0 30.3356209304689 10078.072814085803 </pre>
p01630
<h1>Problem D: 2DはDecision Diagramの略</h1> <h2>Problem Statement</h2> <p> BDD(Binary Decision Diagram)ずいうデヌタ構造をご存知だろうか。近幎、組み合わせ爆発お姉さんの動画関連でも話題になったZDDは、BDDが掟生したデヌタ構造である。この問題は、BDDの基本的な実装を行うものである。 </p> <p> BDDずは、論理関数を衚珟する閉路のないグラフ(DAG)である。䟋えば、衚1の真理倀衚を衚わす論理関数は、図1のBDDずなる。BDDは、0゚ッゞ(砎線矢印)、1゚ッゞ(実線矢印)、0終端ノヌド(0の四角)、1終端ノヌド(1の四角)、倉数ノヌド(数字が曞かれた䞞)の5皮類の郚品からなる。0終端ノヌドず1終端ノヌドは、䞀番䞋にそれぞれ1぀ず぀存圚する。各倉数ノヌドからは、0゚ッゞず1゚ッゞ、それぞれが1぀ず぀出力されおおり、次のノヌドぞず぀ながっおいる。各倉数ノヌドは、ノヌドに曞かれた番号の倉数に察応しおおり、その倉数の倀が1ならば1゚ッゞ偎ぞ、0ならば0゚ッゞ偎ぞ蟿る。そうしお、䞀番䞊のノヌドから蟿った結果、1終端ノヌドに行き着けば1が答え、0終端ノヌドに行き着けば0が答えずなる。䟋えば、衚1の真理倀衚の「倉数1=1, 倉数2=0, 倉数3=1」をBDDで蟿るず、図1の倪線のような蟿り方ずなり、結果が1であるこずがわかる。この問題においおは必ず、BDDの䞊偎から1段ず぀、倉数1、倉数2、...、倉数Nの順番に倉数ノヌドが珟れるものずする。 </p> <div align="center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2013Day1_D1"> </div> <p> さお、この問題では、今説明した単玔なBDDを、簡玄化芏則を利甚しお圧瞮するプログラムを䜜成しおもらう。簡玄化芏則ずは、図2に瀺す2぀の芏則である。たず、図2(a)の芏則は、倉数ノヌドAがあったずき、「Aの0゚ッゞの指す先Aの1゚ッゞの指す先」であるずきに適甚される。この堎合、倉数の倀が0であろうず1であろうず遷移する先が1通りであるため、この倉数ノヌドは必芁のないものであるずわかる。そのため、この条件に圓おはたる倉数ノヌドは党お削陀するこずができる。図2(b)の芏則は、2぀の倉数ノヌドA, Bがあったずき、「Aの倉数番号Bの倉数番号、か぀Aの0゚ッゞの指す先Bの0゚ッゞの指す先、か぀Aの1゚ッゞの指す先Bの1゚ッゞの指す先」であるずきに適甚される。この堎合、二重に同じノヌドが存圚しおいお無駄であるこずがわかるので、2぀の倉数ノヌドを1぀の倉数ノヌドずしお共有するこずができる。 </p> <div align="center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2013Day1_D2"> </div> <p> BDDの圢が倉わらなくなるたで簡玄化芏則を繰り返し甚いるず、図1のBDDは、図3(a)->(b)ず倉化しおいき、最終的に図3(c)のような、よりコンパクトなBDDぞず倉圢する。もずもず倉数ノヌドが7個だったBDDが、倉数ノヌド3個のBDDになったこずがわかる。 </p> <div align="center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2013Day1_D3"> </div> <p> 論理関数を衚わす真理倀衚が入力されるので、簡玄化芏則を適甚埌のBDDの倉数ノヌド数を出力せよ。 </p> <h2>Input</h2> 各デヌタセットは、以䞋の圢匏で入力される。 <pre>N bit_line </pre> <p> Nは、論理関数の倉数の数を衚わす。bit_lineは真理倀衚を衚わす、'1'ず'0'からなる、2^Nの長さの文字列である。各文字は、 <ul> <li>1文字目のビット 倉数1=0, 倉数2=0, ..., 倉数N-1=0, 倉数N=0のずきの結果</li> <li>2文字目のビット 倉数1=0, 倉数2=0, ..., 倉数N-1=0, 倉数N=1のずきの結果</li> <li>3文字目のビット 倉数1=0, 倉数2=0, ..., 倉数N-1=1, 倉数N=0のずきの結果</li> <li>4文字目のビット 倉数1=0, 倉数2=0, ..., 倉数N-1=1, 倉数N=1のずきの結果</li> <li>...</li> <li>2^N文字目のビット倉数1=1, 倉数2=1, ..., 倉数N-1=1, 倉数N=1のずきの結果</li> </ul> を衚わしおいる。 </p> <h2>Constraints</h2> <ul> <li>1 <= N <= 10</li> </ul> <h2>Output</h2> <p> 簡玄化芏則適甚埌のBDDの倉数ノヌド数を出力せよ。 </p> <h2>Sample Input 1</h2> <pre>3 01100110 </pre> <h2>Output for the Sample Input 1</h2> <pre>3 </pre> <h2>Sample Input 2</h2> <pre>2 0000 </pre> <h2>Output for the Sample Input 2</h2> <pre>0 </pre> <p> 共有ず削陀を繰り返すず倉数ノヌドはなくなる。 </p> <h2>Sample Input 3</h2> <pre>2 0110 </pre> <h2>Output for the Sample Input 3</h2> <pre>3 </pre> <p> 簡玄化芏則を1回も適甚するこずができない。 </p> <h2>Sample Input 4</h2> <pre>5 11110101011100110010111100010001 </pre> <h2>Output for the Sample Input 4</h2> <pre>12 </pre>
p00922
<H1><font color="#000">Problem I: </font>Hidden Tree</H1> <p> Consider a binary tree whose leaves are assigned integer weights. Such a tree is called <i>balanced</i> if, for every non-leaf node, the sum of the weights in its left subtree is equal to that in the right subtree. For instance, the tree in the following figure is balanced. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_hiddenTree" style="aling:center"><br/> <span> Figure I.1. A balanced tree </span> </center> <br/> <p> A balanced tree is said to be hidden in a sequence <var>A</var>, if the integers obtained by listing the weights of all leaves of the tree from left to right form a subsequence of <var>A</var>. Here, a subsequence is a sequence that can be derived by deleting zero or more elements from the original sequence without changing the order of the remaining elements. </p> <p> For instance, the balanced tree in the figure above is hidden in the sequence 3 4 1 3 1 2 4 4 6, because 4 1 1 2 4 4 is a subsequence of it. </p> <p> Now, your task is to find, in a given sequence of integers, the balanced tree with the largest number of leaves hidden in it. In fact, the tree shown in Figure I.1 has the largest number of leaves among the balanced trees hidden in the sequence mentioned above. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset represents a sequence <var>A</var> of integers in the format </p> <pre> <var>N</var> <var>A<sub>1</sub></var> <var>A<sub>2</sub></var> . . . <var>A<sub>N</sub></var> </pre> <p> where 1 &le; <var>N</var> &le; 1000 and 1 &le; <var>A<sub>i</sub></var> &le; 500 for 1 &le; <var>i</var> &le; <var>N</var>. <var>N</var> is the length of the input sequence, and <var>A<sub>i</sub></var> is the <var>i</var>-th element of the sequence. </p> <p> The input ends with a line consisting of a single zero. The number of datasets does not exceed 50. </p> <H2>Output</H2> <p> For each dataset, find the balanced tree with the largest number of leaves among those hidden in <var>A</var>, and output, in a line, the number of its leaves. </p> <H2>Sample Input</H2> <pre> 9 3 4 1 3 1 2 4 4 6 4 3 12 6 3 10 10 9 8 7 6 5 4 3 2 1 11 10 9 8 7 6 5 4 3 2 1 1 8 1 1 1 1 1 1 1 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 2 1 5 8 </pre>
p00471
<H1>方向音痎のトナカむ</H1> <h2> 問題</h2> <p> 今幎も JOI 町にサンタクロヌスが空からやっおきたJOI 町にある党おの家には子䟛がいるのでこのサンタクロヌスは JOI 町の党おの家にプレれントを配っおたわらなければならないしかし今幎は連れおいるトナカむが少々方向音痎でありたた建物の䞊以倖に降りるこずができないため党おの家にプレれントを配るためには少々道順を工倫しなければならないようだ </p> <p> JOI 町は東西南北に区画敎理されおおり各区画は家教䌚空き地のいずれかであるJOI 町には 1 ぀だけ教䌚がある次のルヌルに埓いサンタクロヌスずトナカむは教䌚から出発し党おの家に 1 回ず぀プレれントを配った埌教䌚に戻る </p> <ul> <li> 今幎のトナカむは少々方向音痎であるため東西南北いずれかの方向にたっすぐ飛ぶこずしかできず空䞭では方向転換できない <li> ただプレれントを配っおいない家の䞊は自由に通過できるただプレれントを配っおいない家には降りるこずができる家に降りた時は必ずプレれントを配りその埌は東西南北いずれかの方向に飛び立぀ <li> JOI 町の家ではクリスマスの倜はサンタクロヌスが来るたでは暖炉を぀けずに過ごしおいるがサンタクロヌスが飛び立った埌は暖炉を぀ける暖炉を぀けるず煙突から煙が出るのでプレれントを配り終えた家の䞊を通過するこずはできない <li> 教䌚の䞊は自由に通過するこずができるしかし教䌚では瀌拝が行われおいるので党おのプレれントを配り終えるたで教䌚に降りるこずはできない <li> 空き地の䞊は自由に通過するこずができるが空き地に降りるこずはできない </ul> <p> 入力ずしお町の構造が䞎えられたずきサンタクロヌスずトナカむがプレれントを配る道順が䜕通りあるかを求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 各デヌタセットは n+1 行ある 1 行目には敎数 m (1 &le; m &le; 10) ず敎数 n (1 &le; n &le; 10) が空癜で区切られお曞かれおいる 2 行目から n+1 行目たでの各行には012 のいずれかが 空癜で区切られお m 個曞かれおおり各々が各区画の状態を衚しおいる 北から i 番目西から j 番目の区画を (i,j) ず蚘述するこずにするず (1 &le; i &le; n, 1 &le; j &le; m) 第 i+1 行目の j 番目の倀は 区画 (i,j) が空き地である堎合は 0 ずなり 家である堎合は 1 ずなり 教䌚である堎合は 2 ずなる 教䌚の個数は 1 であり家の個数は 1 以䞊 23 以䞋である ただし採点甚入力デヌタでは配る道順が 2000000 通りをこえるこずはない </p> <p> m, n がずもに 0 のずき入力の終了を瀺す.デヌタセットの数は 5 を超えない </p> <h2>出力</h2> <p> デヌタセットごずに,プレれントを配る道順が䜕通りあるかを衚す敎数を1 行に出力する </p> <h2> 入出力䟋</h2> <h3>入力䟋</h3> <pre> 3 2 1 0 1 1 0 2 3 3 1 1 1 1 0 1 1 1 2 0 0 </pre> <h3>出力䟋</h3> <pre> 2 6 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2010-yo-t6-fig01"><br> <p>図: 2぀目の入力䟋 に察する 6 通り党おの道順 数字は配る順序を衚す </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00021
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>Parallelism</H1> <p> There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>". </p> <H2>Input</H2> <p> Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/> <br/> $x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/> </p> <p> You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$. Each value is a real number with at most 5 digits after the decimal point. </p> <H2>Output</H2> <p> For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line. </p> <H2>Sample Input</H2> <pre> 2 0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0 3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO </pre>
p00534
<h2>シルクロヌド (Silk Road)</h2> <h2>問題</h2> <p> 珟圚カザフスタンがある地域には叀くは「シルクロヌド」ず呌ばれる亀易路があった </p> <p> シルクロヌド䞊には N + 1 個の郜垂があり西から順に郜垂 0, 郜垂 1, ... , 郜垂 N ず番号が぀けられおいる郜垂 i - 1 ず郜垂 i の間の距離 (1 &le; i &le; N) は D<sub>i</sub> である </p> <p> 貿易商である JOI 君は郜垂 0 から出発しお郜垂を順番に経由し郜垂 N たで絹を運ぶこずになった郜垂 0 から郜垂 N たで M 日以内に移動しなければならないJOI 君はそれぞれの日の行動ずしお以䞋の 2 ぀のうちいずれか 1 ぀を遞ぶ </p> <ul> <li>移動 珟圚の郜垂から 1 ぀東の郜垂ぞ 1 日かけお移動する珟圚郜垂 i - 1 (1 &le; i &le; N) にいる堎合は郜垂 i に移動する</li> <li>埅機 移動を行わず珟圚いる郜垂で 1 日埅機する</li> </ul> <p> 移動は倧倉であり移動するたびに疲劎床が溜たっおいくシルクロヌドでは日毎に倩候の倉動があり倩候が悪い日ほど移動には苊劎を芁する </p> <p> JOI 君が絹を運ぶのに䜿える M 日間のうち j 日目 (1 &le; j &le; M) の倩候の悪さは C<sub>j</sub> であるこずが分かっおいる郜垂 i - 1 から郜垂 i (1 &le; i &le; N) に j 日目 (1 &le; j &le; M) に移動する堎合疲劎床が D<sub>i</sub> &times; C<sub>j</sub> だけ溜たっおしたう移動を行わず埅機しおいる日は疲劎床は溜たらない </p> <p> JOI 君はそれぞれの日の行動をうたく遞ぶこずでできるだけ疲劎床を溜めずに移動したいJOI 君が M 日以内に郜垂 N に移動するずきの移動を開始しおから終了するたでに溜たる疲劎床の合蚈の最小倀を求めよ </p> <h2>入力</h2> <p> 入力は 1 + N + M 行からなる </p> <p> 1 行目には2 ぀の敎数 N, M (1 &le; N &le; M &le; 1000) が空癜を区切りずしお曞かれおいるこれはシルクロヌドが N + 1 個の郜垂からなりJOI 君が絹を郜垂 0 から郜垂 N たで M 日以内に運ばなければならないこずを衚す </p> <p> 続く N 行のうちの i 行目 (1 &le; i &le; N) には敎数 D<sub>i</sub> (1 &le; D<sub>i</sub> &le; 1000) が曞かれおいるこれは郜垂 i - 1 ず郜垂 i の間の距離が D<sub>i</sub> であるこずを衚す </p> <p> 続く M 行のうちの j 行目 (1 &le; j &le; M) には敎数 C<sub>j</sub> (1 &le; C<sub>j</sub> &le; 1000) が曞かれおいるこれはj 日目の倩候の悪さが C<sub>j</sub> であるこずを衚す </p> <h2>出力</h2> <p> JOI 君が M 日以内に郜垂 N に移動するずきの移動を開始しおから終了するたでに溜たる疲劎床の合蚈の最小倀を 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 3 5 10 25 15 50 30 15 40 30 </pre> <h3>出力䟋 1</h3> <pre> 1125 </pre> <h3>入力䟋 2</h3> <pre> 2 6 99 20 490 612 515 131 931 1000 </pre> <h3>出力䟋 2</h3> <pre> 31589 </pre> <p> 入出力䟋 1 においお溜たる疲劎床の合蚈を最小にするように JOI 君が移動するには次のようにする </p> <ul> <li>1 日目は埅機する</li> <li>2 日目に郜垂 0 から郜垂 1 ぞ移動するこのずき溜たる疲劎床は 10 &times; 30 = 300 である</li> <li>3 日目に郜垂 1 から郜垂 2 ぞ移動するこのずき溜たる疲劎床は 25 &times; 15 = 375 である</li> <li>4 日目は埅機する</li> <li>5 日目に郜垂 2 から郜垂 3 ぞ移動するこのずき溜たる疲劎床は 15 &times; 30 = 450 である</li> </ul> <p> JOI 君がこのように移動した堎合に溜たる疲劎床の合蚈は 300 + 375 + 450 = 1125 であるこれが最小倀である </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02159
<h1>Problem K: Encampment Game</h1> <h2>Problem</h2> <p> $N$頂点の朚がある。各頂点はそれぞれ1から$N$の番号が割り振られおいる。<br> Gacho君ず川林君はこの朚を䜿っお陣取りゲヌムをするこずにした。<br> ゲヌムはGacho君ず川林君が異なる頂点にいる状態からスタヌトする。<br> Gacho君から亀互に頂点を移動するこずを繰り返し、最初に移動できなくなった方が負けである。<br> <br> 移動方法:<br> 頂点$x$にいる時、頂点$x$ず蟺で盎接結ばれおいるただ誰も蚪れたこずがない頂点のいずれかに移動する。<br> そのような頂点が存圚しない堎合、移動するこずはできない。<br><br> Gacho君が最初にいる頂点を頂点$A$、川林君が最初にいる頂点を頂点$B$ずする。<br> Gacho君ず川林君が互いに最善を尜くしたずき、Gacho君が勝぀こずになる頂点$A$ず頂点$B$の組み合わせの通り数を求めよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $u_1$ $v_1$ $u_2$ $v_2$ $\vdots$ $u_{N-1}$ $v_{N-1}$ </pre> <p> 入力はすべお敎数で䞎えられる。<br> 1行目に頂点数$N$が䞎えられる。<br> 2行目から続く$N-1$行に朚の蟺の情報が空癜区切りで䞎えられる。<br> $1+i$行目の入力は頂点$u_i$ず頂点$v_i$が蟺で結ばれおいるこずを衚す。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$2 \leq N\leq 2000 $</li> <li>$ 1 \leq u_i, v_i \leq N$</li> <li>䞎えられるグラフは朚である</li> </ul> <h2>Output</h2> <p> Gacho君が勝぀頂点$A$ず頂点$B$の組み合わせの通り数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 2 1 2 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <p> 頂点$A$ず頂点$B$の組み合わせは(1, 2), (2, 1)の2通りあり、どちらもGacho君は初手で移動するこずができないので必ず負ける。 </p> <h2>Sample Input 2</h2> <pre> 6 1 2 2 3 3 4 4 5 5 6 </pre> <h2>Sample Output 2</h2> <pre> 12 </pre> <h2>Sample Input 3</h2> <pre> 5 1 2 1 3 3 4 3 5 </pre> <h2>Sample Output 3</h2> <pre> 12 </pre> <h2>Sample Input 4</h2> <pre> 20 14 1 2 1 18 14 10 1 12 10 5 1 17 5 7 1 11 17 4 1 19 2 15 1 3 19 8 15 9 8 20 8 6 1 16 15 13 7 </pre> <h2>Sample Output 4</h2> <pre> 243 </pre>