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 ≤ <var>y_i</var> ≤ 3000), month <var>m_i</var> (1 ≤ <var>m_i</var> ≤ 12), and day <var>d_i</var> (1 ≤ <var>d_i</var> ≤ 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> ∈ <i>S</i><sub>1</sub> and
<i>v</i><sub>2</sub> ∈ <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 ≤ <i>n</i> ≤ 1000 and 3 ≤ <i>m</i> ≤ 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 −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 ≤ <i>N</i> ≤ 10<sup>9</sup>, 1 ≤ <i>M</i> ≤ 10<sup>5</sup>, and 1 ≤ <i>L<sub>i</sub></i> ≤ <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 ≤ <var>N</var> ≤ 1,000</li>
<li>0 ≤ <var>M</var> ≤ 100</li>
<li>1 ≤ <var>a<sub>i</sub></var> ≤ <var>N</var></li>
<li>1 ≤ <var>b<sub>i</sub></var> ≤ <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 ≤ H ≤ 11</var></li>
<li><var>1 ≤ W ≤ 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 ≤ i ≤ n ) ãæã£ãŠãããããŸåœŒãã¯åŒ·åãªéæ³äœ¿ããšå¯Ÿå³ããŠããããã®æµã®éå㯠S ã§ãããn 人ã®éæ³äœ¿ãã¯ååããŠæŠãã®ãåŸæã§ãç¹ã« 2 人ã§ååããŠæŠãããšã奜ãã2 人ã®éæ³äœ¿ããååããå Žåãéåã¯åçŽã«ãã®åãšãªãã匷åãªéæ³ãªã©ãé§äœ¿ããŠããçšåºŠåŒ·ãæµã«ãåãŠãããã«ãªããããªãã®ä»äºã¯éå S ãæã€æµã«å¯ŸããŠåã€ããšãã§ããéæ³äœ¿ãã®ã㢠(i, j) ( i ≠ j ã〠1 ≤ i ≤ n ã〠1 ≤ j ≤ 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 ≤ n ≤ 20,000</li>
<li>1 ≤ r<sub>i</sub> ≤ 100 ( 1 ≤ i ≤ n )</li>
<li>1 ≤ S ≤ 100</li>
<li>ãã¹ãã±ãŒã¹ã®æ°ã¯ 100 ãè¶
ããªãã</li>
</ul>
<h2>Output</h2>
<p>
æ¡ä»¶ãæºããçµ (i, j) (i ≠ 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 ≤ N ≤ 1000 ïŒ1 ≤ M ≤ 1000 ïŒã空çœãåºåããšããŠæžãããŠããïŒ
N ã¯ããããã®ãã¹ç®ã®åæ°ãïŒ M ã¯äžãããããµã€ã³ãã®ç®ã®åæ°ã衚ãïŒ
</p>
<p>
ç¶ã N è¡ã«ã¯ -999 ä»¥äž 999 以äžã®æŽæ°ãïŒã€ãã€æžãããŠããïŒ
1+i è¡ç® ïŒ 1 ≤ i ≤ N ïŒ ã®æŽæ°ã¯ïŒããããã® i çªç®ã®ãã¹ã®æç€ºã衚ãïŒ
æžãããŠããæŽæ°ã X ãšããïŒ
X=0 ã®ãšãã¯ãäœãããªãããïŒ X>0 ã®ãšãã¯ã X ãã¹é²ãããïŒX<0 ã®ãšãã¯ã |X| ãã¹æ»ããã®æç€ºã衚ãïŒãã ãïŒ |X| 㯠X ã®çµ¶å¯Ÿå€ã衚ãïŒ
</p>
<p>
ç¶ã M è¡ã«ã¯ 1 ä»¥äž 6 以äžã®æŽæ°ãïŒã€ãã€æžãããŠããïŒ 1+N+j è¡ç® ïŒ 1 ≤ j ≤ 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 <= x, y <= 10,000 ã§ãããšä»®å®ããŠããã
</p>
<p>
N(1 <= N <= 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 <= M <= 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>
è±åºç¹ãŸã§èŸ¿ãçããªãå Žåã¯ã"impossible"ãšåºåããã
</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 ≤ <i>k</i> ≤ <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 ≤ <i>n</i> ≤ 8). <i>ball</i><sub><i>i</i>,1</sub> and <i>ball</i><sub><i>i</i>,2</sub> , for 1 ≤ <i>i</i> ≤ <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>θ</i> (in radian) has its arc length <i>s</i> = <i>rθ</i> and its
chord length <i>c</i> = <i>r</i>√(2 - 2cos<i>θ</i>). Its area size is <i>A</i> = <i>r</i><sup>2</sup>(<i>θ</i> - sin<i>θ</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>θ</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> < <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 ≤ <i>n</i> ≤ 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 ≤ <i>r<sub>i</sub></i> ≤ 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 ≤ <var>n</var> ≤ 15) ãšãã¢ã®æ° <var>m</var> (1 ≤ <var>m</var> ≤ 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 ≤ <var>k<sub>i</sub></var> ≤ 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>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<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>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<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 < y_i \leq n</var>ã§ããããŸãã<var>1 \leq i < 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 < a < c, 0 \leq b < c, v_0 < 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 ≤ <var>|V|</var> ≤ 15</li>
<li> 0 ≤ <var>d<sub>i</sub></var> ≤ 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> ≤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> > <i>b</i><sub>1</sub> ãŸãã¯, ããæŽæ° <i>i</i> > 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> > <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 ≤ <i>N</i> ≤ 100, 1 ≤ <i>D</i> ≤ 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 ≤ <i>Lspeed<sub>i</sub></i>, <i>Rspeed<sub>i</sub></i> ≤ 360, 1 ≤ <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 ≤ k ≤ m)ã¯ã"L++", "L--", "R++", "R--"ã®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 ≤ k ≤ 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 ≤ n ≤ 3Ã10<sup>5</sup>
</p></li><li><p> 1 ≤ m ≤ 3Ã10<sup>5</sup>
</p></li><li><p> q<sub>k</sub>(1 ≤ k ≤ m)ã¯ã"L++"ã"L--"ã"R++"ã"R--"ã®ãããã
</p></li><li><p> 1 ≤ l[k] ≤ r[k] ≤ n (1 ≤ k ≤ 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ã§ãããéšåæååã¯"ab"ã§ãã
</p></li><li><p>l[2]=1, r[2]=3ã§ãããéšåæååã¯"abc"ã§ãã
</p></li><li><p>l[3]=2, r[3]=3ã§ãããéšåæååã¯"bc"ã§ãã
</p></li><li><p>l[4]=1, r[4]=3ã§ãããéšåæååã¯"abc"ã§ãã
</p></li></ul>
<p>ãã£ãŠãçæãããæååã¯{"ab","abc","bc"}ã®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ã§ãããéšåæååã¯"ab"ã§ãã
</p></li><li><p>l[2]=2, r[2]=2ã§ãããéšåæååã¯"b"ã§ãã
</p></li><li><p>l[3]=2, r[3]=3ã§ãããéšåæååã¯"ba"ã§ãã
</p></li><li><p>l[4]=3, r[4]=3ã§ãããéšåæååã¯"a"ã§ãã
</p></li><li><p>l[5]=3, r[5]=4ã§ãããéšåæååã¯"ab"ã§ãã
</p></li><li><p>l[6]=4, r[6]=4ã§ãããéšåæååã¯"b"ã§ãã
</p></li></ul>
<p>ãã£ãŠãçæãããæååã¯{"a","ab","b","ba"}ã®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} $ $( 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 ≤ <var>W</var>, <var>H</var> ≤ 10<sup>9</sup>) ãšè»ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 200000) ãäžãããããç¶ã <var>N</var> è¡ã« <var>i</var> çªç®ã®è»ã®æ±è¥¿æ¹åã®äœçœ® <var>x<sub>i</sub></var> (1 ≤ <var>x<sub>i</sub></var> ≤ <var>W</var>)ãååæ¹åã®äœçœ® <var>y<sub>i</sub></var> (1 ≤ <var>y<sub>i</sub></var> ≤ <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<=<i>i</i><=<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<=<i>i</i><=<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 < tx</var> and <var>sy < 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 < tx †1000</var> </li>
<li><var>-1000 †sy < 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 ≤ <i>N</i> ≤ 6), <i>M</i> (2 ≤ <i>M</i> ≤ 10<sup>9</sup> ), and <i>L</i> (1 ≤ <i>L</i> ≤ 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) − 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 ≤ 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>
<expr> ::= <num>
| "(" <expr> ")"
| <expr> "+" <expr>
| <expr> "-" <expr>
| <expr> "*" <expr>
| <expr> "/" <expr>
<num> ::= <digit> | <num> <digit>
<digit> ::= "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 æå × 8 è¡ã®ãã¿ãŒã³ãå³åãã« 90 床ã180 床ã270 床å転ãããŠåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
8 æå × 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 < 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 ≤ <var>n</var> ≤ 1000000) ã¯åå è
ã®æ°ã<var>q</var> (1 ≤ <var>q</var> ≤ 100000)ã¯ã€ãã³ãã®æ°ã衚ãã<var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ <var>n</var>) <var>v<sub>i</sub></var> ( -100 ≤ <var>v<sub>i</sub></var> ≤ 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 <var>9</var> 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 <var>10:40</var>" 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 < i_2 < ... < i_M \leq L</var> and <var>A_{i_1} < A_{i_2} < ... < 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 ≤ <var>|V|</var> ≤ 1000</li>
<li> 0 ≤ <var>|E|</var> ≤ 2000</li>
<li> -10000 ≤ <var>d<sub>i</sub></var> ≤ 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 > 0</var> or <var>b_i > 0</var>.</li>
<li>For each <var>i, j</var> (<var>1 \leq i < 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 ≤ <i>N</i> ≤ 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 ≤ <i>N</i> ≤ 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> < <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> ≤ <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 ≤ <var>N</var> ≤ 1000 and 1 ≤ <var>A<sub>i</sub></var> ≤ 500 for 1 ≤ <var>i</var> ≤ <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 ≤ m ≤ 10) ãšæŽæ° n (1 ≤ n ≤ 10) ã空çœã§åºåãããŠæžãããŠããïŒ
2 è¡ç®ãã n+1 è¡ç®ãŸã§ã®åè¡ã«ã¯ïŒ0ïŒ1ïŒ2 ã®ãããããïŒ
空çœã§åºåãã㊠m åæžãããŠããïŒåã
ãååºç»ã®ç¶æ
ã衚ããŠããïŒ
åãã i çªç®ïŒè¥¿ãã j çªç®ã®åºç»ã (i,j) ãšèšè¿°ããããšã«ãããš
(1 ≤ i ≤ n, 1 ≤ j ≤ 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 ≤ i ≤ N) 㯠D<sub>i</sub> ã§ããïŒ
</p>
<p>
貿æåã§ãã JOI åã¯ïŒéœåž 0 ããåºçºããŠïŒéœåžãé çªã«çµç±ãïŒéœåž N ãŸã§çµ¹ãéã¶ããšã«ãªã£ãïŒéœåž 0 ããéœåž N ãŸã§ M æ¥ä»¥å
ã«ç§»åããªããã°ãªããªãïŒJOI åã¯ïŒããããã®æ¥ã®è¡åãšããŠïŒä»¥äžã® 2 ã€ã®ãã¡ãããã 1 ã€ãéžã¶ïŒ
</p>
<ul>
<li>ç§»åïŒ çŸåšã®éœåžãã 1 ã€æ±ã®éœåžãž 1 æ¥ãããŠç§»åããïŒçŸåšéœåž i - 1 (1 ≤ i ≤ N) ã«ããå Žåã¯ïŒéœåž i ã«ç§»åããïŒ</li>
<li>åŸ
æ©ïŒ ç§»åãè¡ããïŒçŸåšããéœåžã§ 1 æ¥åŸ
æ©ããïŒ</li>
</ul>
<p>
ç§»åã¯å€§å€ã§ããïŒç§»åãããã³ã«ç²åŽåºŠãæºãŸã£ãŠããïŒã·ã«ã¯ããŒãã§ã¯æ¥æ¯ã«å€©åã®å€åãããïŒå€©åãæªãæ¥ã»ã©ç§»åã«ã¯èŠåŽãèŠããïŒ
</p>
<p>
JOI åãçµ¹ãéã¶ã®ã«äœ¿ãã M æ¥éã®ãã¡ j æ¥ç® (1 ≤ j ≤ M) ã®å€©åã®æªã㯠C<sub>j</sub> ã§ããããšãåãã£ãŠããïŒéœåž i - 1 ããéœåž i (1 ≤ i ≤ N) ã« j æ¥ç® (1 ≤ j ≤ M) ã«ç§»åããå ŽåïŒç²åŽåºŠã D<sub>i</sub> × C<sub>j</sub> ã ãæºãŸã£ãŠããŸãïŒç§»åãè¡ããåŸ
æ©ããŠããæ¥ã¯ç²åŽåºŠã¯æºãŸããªãïŒ
</p>
<p>
JOI åã¯ïŒããããã®æ¥ã®è¡åãããŸãéžã¶ããšã§ïŒã§ããã ãç²åŽåºŠãæºããã«ç§»åãããïŒJOI åã M æ¥ä»¥å
ã«éœåž N ã«ç§»åãããšãã®ïŒç§»åãéå§ããŠããçµäºãããŸã§ã«æºãŸãç²åŽåºŠã®åèšã®æå°å€ãæ±ããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠1 + N + M è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯ïŒ2 ã€ã®æŽæ° N, M (1 ≤ N ≤ M ≤ 1000) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒã·ã«ã¯ããŒãã N + 1 åã®éœåžãããªãïŒJOI åãçµ¹ãéœåž 0 ããéœåž N ãŸã§ M æ¥ä»¥å
ã«éã°ãªããã°ãªããªãããšã衚ãïŒ
</p>
<p>
ç¶ã N è¡ã®ãã¡ã® i è¡ç® (1 ≤ i ≤ N) ã«ã¯ïŒæŽæ° D<sub>i</sub> (1 ≤ D<sub>i</sub> ≤ 1000) ãæžãããŠããïŒããã¯ïŒéœåž i - 1 ãšéœåž i ã®éã®è·é¢ã D<sub>i</sub> ã§ããããšã衚ãïŒ
</p>
<p>
ç¶ã M è¡ã®ãã¡ã® j è¡ç® (1 ≤ j ≤ M) ã«ã¯ïŒæŽæ° C<sub>j</sub> (1 ≤ C<sub>j</sub> ≤ 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 × 30 = 300 ã§ããïŒ</li>
<li>3 æ¥ç®ã«éœåž 1 ããéœåž 2 ãžç§»åããïŒãã®ãšãæºãŸãç²åŽåºŠã¯ 25 × 15 = 375 ã§ããïŒ</li>
<li>4 æ¥ç®ã¯åŸ
æ©ããïŒ</li>
<li>5 æ¥ç®ã«éœåž 2 ããéœåž 3 ãžç§»åããïŒãã®ãšãæºãŸãç²åŽåºŠã¯ 15 × 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>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.