question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00725 |
<h1><font color="#000">Problem D:</font> Curling 2.0</h1><!-- end en only -->
<p>
On Planet MM-21, after their Olympic games this year, curling is getting popular.
But the rules are somewhat different from ours.
The game is played on an ice game board on which a square mesh is marked.
They use only a single stone.
The purpose of the game is to lead the stone from the start
to the goal with the minimum number of moves.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Fig. D-1 shows an example of a game board.
Some squares may be occupied with blocks.
There are two special squares namely the start and the goal,
which are not occupied with blocks.
(These two squares are distinct.)
Once the stone begins to move, it will proceed until it hits a block.
In order to bring the stone to the goal,
you may have to stop the stone by hitting it against a block,
and throw again.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fig0">
<!-- begin en only -->
<br>
Fig. D-1: Example of board (S: start, G: goal)
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
The movement of the stone obeys the following rules:
</p><ul>
<li> At the beginning, the stone stands still at the start square.
</li><li> The movements of the stone are restricted to x and y directions.
Diagonal moves are prohibited.
</li><li> When the stone stands still, you can make it moving by throwing it.
You may throw it to any direction
unless it is blocked immediately(Fig. D-2(a)).
</li><li> Once thrown, the stone keeps moving to the same direction until
one of the following occurs:
<ul>
<li> The stone hits a block (Fig. D-2(b), (c)).
<ul>
<li> The stone stops at the square next to the block it hit.
</li><li> The block disappears.
</li></ul>
</li><li> The stone gets out of the board.
<ul>
<li> The game ends in failure.
</li></ul>
</li><li> The stone reaches the goal square.
<ul>
<li> The stone stops there and the game ends in success.
</li></ul>
</li></ul>
</li><li> You cannot throw the stone more than 10 times in a game.
If the stone does not reach the goal in 10 moves, the game ends in failure.
</li></ul>
<p></p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_move">
<!-- begin en only -->
<br>
Fig. D-2: Stone movements
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
Under the rules, we would like to know whether the stone at the start
can reach the goal and, if yes, the minimum number of moves required.
</p><p>
With the initial configuration shown in Fig. D-1, 4 moves are required
to bring the stone from the start to the goal.
The route is shown in Fig. D-3(a).
Notice when the stone reaches the goal, the board configuration has changed
as in Fig. D-3(b).
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_solution">
<!-- begin en only -->
<br>
Fig. D-3: The solution for Fig. D-1 and the final board configuration
<!-- end en only -->
<br>
</center>
<h2>Input</h2>
<!-- begin en only -->
<p>The input is a sequence of datasets.
The end of the input is indicated by a line
containing two zeros separated by a space.
The number of datasets never exceeds 100.
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
Each dataset is formatted as follows.
</p>
<blockquote>
<i>the width(=w) and the height(=h) of the board</i> <br>
<i>First row of the board</i> <br>
... <br>
<i>h-th row of the board</i> <br>
</blockquote>
<p>The width and the height of the board satisfy:
2 <= <i>w</i> <= 20, 1 <= <i>h</i> <= 20.
<br>
Each line consists of <i>w</i> decimal numbers delimited by a space.
The number describes the status of the corresponding square.
<blockquote><table>
<tbody><tr><td> 0 </td><td>vacant square</td></tr>
<tr><td> 1 </td><td>block</td></tr>
<tr><td> 2 </td><td>start position</td></tr>
<tr><td> 3 </td><td>goal position</td></tr>
</tbody></table></blockquote>
<!-- end en only -->
<p></p>
<!-- begin en only -->
<p>
The dataset for Fig. D-1 is as follows:
</p>
<!-- end en only -->
<blockquote>
6 6 <br>
1 0 0 2 1 0 <br>
1 1 0 0 0 0 <br>
0 0 0 0 0 3 <br>
0 0 0 0 0 0 <br>
1 0 0 0 0 1 <br>
0 1 1 1 1 1 <br>
</blockquote>
<h2>Output</h2>
<!-- begin en only -->
<p>
For each dataset, print a line having a decimal integer indicating the
minimum number of moves along a route from the start to the goal.
If there are no such routes, print -1 instead.
Each line should not have any character other than
this number.
</p>
<!-- end en only -->
<h2>Sample Input</h2>
<pre>
2 1
3 2
6 6
1 0 0 2 1 0
1 1 0 0 0 0
0 0 0 0 0 3
0 0 0 0 0 0
1 0 0 0 0 1
0 1 1 1 1 1
6 1
1 1 2 1 1 3
6 1
1 0 2 1 1 3
12 1
2 0 1 1 1 1 1 1 1 1 1 3
13 1
2 0 1 1 1 1 1 1 1 1 1 1 3
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1
4
-1
4
10
-1
</pre>
|
p01564 |
<h1>Do use segment tree</h1>
<p>Given a tree with <var>n</var> <var>(1 ≤ n ≤ 200,000)</var> nodes and a list of <var>q</var> <var>(1 ≤ q ≤ 100,000)</var> queries,
process the queries in order and output a value for each output query.
The given tree is connected and each node on the tree has a weight <var>w<sub>i</sub></var> <var>(-10,000 ≤ w<sub>i</sub> ≤ 10,000)</var>.
</p>
<p>Each query consists of a number <var>t<sub>i</sub></var> <var>(t<sub>i</sub> = 1, 2)</var>, which indicates the type of the query , and three numbers <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> and <var>c<sub>i</sub></var> <var>(1 ≤ a<sub>i</sub>, b<sub>i</sub> ≤ n, -10,000 ≤ c<sub>i</sub> ≤ 10,000)</var>.
Depending on the query type, process one of the followings:
</p><ul><li><p> (<var>t<sub>i</sub> = 1</var>: modification query)
Change the weights of all nodes on the shortest path between <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> (both inclusive) to <var>c<sub>i</sub></var>.
</p></li><li><p> (<var>t<sub>i</sub> = 2</var>: output query)
First, create a list of weights on the shortest path between <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> (both inclusive) in order. After that, output the maximum sum of a non-empty continuous subsequence of the weights on the list. <var>c<sub>i</sub></var> is ignored for output queries.
</p></li></ul>
<h2>Input</h2>
<p>The first line contains two integers <var>n</var> and <var>q</var>.
On the second line, there are <var>n</var> integers which indicate <var>w<sub>1</sub></var>, <var>w<sub>2</sub></var>, ... , <var>w<sub>n</sub></var>.
</p>
<p>Each of the following <var>n - 1</var> lines consists of two integers <var>s<sub>i</sub></var> and <var>e<sub>i</sub></var> <var>(1 ≤ s<sub>i</sub>, e<sub>i</sub> ≤ n)</var>,
which means that there is an edge between <var>s<sub>i</sub></var> and <var>e<sub>i</sub></var>.
</p>
<p> Finally the following <var>q</var> lines give the list of queries, each of which contains four integers in the format described above.
Queries must be processed one by one from top to bottom.
</p>
<h2>Output</h2>
<p>For each output query, output the maximum sum in one line.
</p>
<h2>Sample Input 1</h2>
<pre>3 4
1 2 3
1 2
2 3
2 1 3 0
1 2 2 -4
2 1 3 0
2 2 2 0
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>6
3
-4
</pre>
<h2>Sample Input 2</h2>
<pre>7 5
-8 5 5 5 5 5 5
1 2
2 3
1 4
4 5
1 6
6 7
2 3 7 0
2 5 2 0
2 4 3 0
1 1 1 -1
2 3 7 0
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>12
10
10
19
</pre>
<h2>Sample Input 3</h2>
<pre>21 30
10 0 -10 -8 5 -5 -4 -3 1 -2 8 -1 -7 2 7 6 -9 -6 3 4 9
10 3
3 2
3 12
12 4
4 13
4 9
10 21
21 1
1 11
11 14
1 15
10 6
6 17
6 16
6 5
5 18
5 19
10 7
10 8
8 20
1 1 21 -10
1 3 19 10
2 1 13 0
1 4 18 8
1 5 17 -5
2 16 7 0
1 6 16 5
1 7 15 4
2 4 20 0
1 8 14 3
1 9 13 -1
2 9 18 0
1 10 12 2
1 11 11 -8
2 21 15 0
1 12 10 1
1 13 9 7
2 6 14 0
1 14 8 -2
1 15 7 -7
2 10 2 0
1 16 6 -6
1 17 5 9
2 12 17 0
1 18 4 6
1 19 3 -3
2 11 8 0
1 20 2 -4
1 21 1 -9
2 5 19 0
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>20
9
29
27
10
12
1
18
-2
-3
</pre>
|
p03559 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.</p>
<p>He has <var>N</var> parts for each of the three categories. The size of the <var>i</var>-th upper part is <var>A_i</var>, the size of the <var>i</var>-th middle part is <var>B_i</var>, and the size of the <var>i</var>-th lower part is <var>C_i</var>.</p>
<p>To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.</p>
<p>How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9(1\leq i\leq N)</var></li>
<li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li><var>1 \leq C_i \leq 10^9(1\leq i\leq N)</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>...</var> <var>A_N</var>
<var>B_1</var> <var>...</var> <var>B_N</var>
<var>C_1</var> <var>...</var> <var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different altars that Ringo can build.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 5
2 4
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The following three altars can be built:</p>
<ul>
<li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>1</var>-st part</li>
<li>Upper: <var>1</var>-st part, Middle: <var>1</var>-st part, Lower: <var>2</var>-nd part</li>
<li>Upper: <var>1</var>-st part, Middle: <var>2</var>-nd part, Lower: <var>2</var>-nd part</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 1
2 2 2
3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>27
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>87
</pre></section>
</div>
</span> |
p01134 |
<h1><font color="#000000">Problem D:</font> Area Separation</h1>
<p>
Mr. Yamada Springfield Tanaka ã¯ãåœå®¶åºç»æŽçäºæ¥å±å±é·è£äœä»£çãšãã倧任ãä»»ãããŠããã
çŸåšã圌ã®åœã¯å€§èŠæš¡ãªåºç»æŽçã®æäžã§ããããã®åºç»æŽçãã¹ã ãŒãºã«çµããããããšãã§ãããªãã°åœŒã®æé²ã¯ééããªãã§ãããšãããŠããã
</p>
<p>
ãšãããããããªåœŒã®åºäžãå¿«ãæããªãè
ãå€ãããã®ã ã ãããªäººéã® 1 人ã«ãMr.Sato Seabreeze Suzuki ãããã
圌ã¯ãããšããããšã« Mr. Yamada ã®è¶³ãåŒã£åŒµãããšç»çããŠããã ä»åã Mr. Sato ã¯è¶³ãåŒã£åŒµãããã«ãå®éã®åºç»æŽçãæ
åœããŠããçµç¹ã«å§åããããŠãåºç»æŽçã®çµæãéåžžã«åããã«ãããã®ã«ããŠããŸã£ãã
</p>
<p>
ãã®ãããMr. Yamada ã«æž¡ãããçµæã¯ã ããæ£æ¹åœ¢ã®åå°ãã©ã®çŽç·ã§åå²ããããšããæ
å ±ã®ã¿ã«ãªã£ãŠããã
æäœéããã®æ£æ¹åœ¢ã®åå°ãããã€ã«åå²ããããã ãã§ãåãããªããã°ãMr. Yamada ã¯æé²ã©ãããè§£éãããããšééããªãã§ããã
</p>
<p>
ããªãã®ä»äºã¯ã(-100,-100)ã(100,-100)ã(100,100)ã(-100,100) ãé ç¹ãšããæ£æ¹åœ¢é åããäžãããã <i>n</i> æ¬ã®çŽç·ã«ãã£ãŠããã€ã«åå²ãããŠãããã調ã¹ãããã°ã©ã ãæžããŠãMr. Yamada ãè§£éã®å±æ©ããæãããšã§ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã
</p>
<p>
ããããã®ãã¹ãã±ãŒã¹ã®æåã®è¡ã§ã¯ãçŽç·æ°ãè¡šãæŽæ° <i>n</i> ãäžããããïŒ1 <= <i>n</i> <= 100ïŒã ãã®åŸã® <i>n</i> è¡ã«ã¯ãããã 4 ã€ã®æŽæ° <i>x</i><sub>1</sub> ã<i>y</i><sub>1</sub> ã <i>x</i><sub>2</sub> ã<i>y</i><sub>2</sub> ãå«ãŸããã
ãããã®æŽæ°ã¯çŽç·äžã®çžç°ãªã 2 ç¹ (<i>x</i><sub>1</sub> , <i>y</i><sub>1</sub> ) ãš (<i>x</i><sub>2</sub> , <i>y</i><sub>2</sub> ) ã衚ãã
äžãããã 2 ç¹ã¯åžžã«æ£æ¹åœ¢ã®èŸºäžã®ç¹ã§ããããšãä¿èšŒãããŠããã äžãããã <i>n</i> æ¬ã®çŽç·ã¯äºãã«ç°ãªããçŽç·å士ãéãªãããšã¯ãªãã ãŸããçŽç·ãæ£æ¹åœ¢ã®èŸºãšéãªãããšããªãã
</p>
<p>
å
¥åã®çµäºã¯ <i>n</i> = 0 ã§è¡šãããã
</p>
<h2>Output</h2>
<p>
ããããã®ãã¹ãã±ãŒã¹ã«ã€ããŠã<i>n</i> æ¬ã®çŽç·ã«ãã£ãŠåå²ãããé åã®æ°ã 1 è¡ã§åºåããã
</p>
<p>
ãªããè·é¢ã 10<sup>-10</sup> æªæºã® 2 ç¹ã¯äžèŽãããšã¿ãªããŠããã ãŸãã|PQ| < 10<sup>-10</sup>ã|QR| < 10<sup>-10</sup> ã§ã〠|PR| >= 10<sup>-10</sup>ãšãªããããªäº€ç¹ã®çµ PãQãR ã¯ååšããªãã
</p>
<h2>Sample Input</h2>
<pre>
2
-100 -20 100 20
-20 -100 20 100
2
-100 -20 -20 -100
20 100 100 20
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
4
3
</pre>
|
p03109 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> as input. This represents a valid date in the year <var>2019</var> in the <code>yyyy/mm/dd</code> format. (For example, April <var>30</var>, <var>2019</var> is represented as <code>2019/04/30</code>.)</p>
<p>Write a program that prints <code>Heisei</code> if the date represented by <var>S</var> is not later than April <var>30</var>, <var>2019</var>, and prints <code>TBD</code> otherwise.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is a string that represents a valid date in the year <var>2019</var> in the <code>yyyy/mm/dd</code> format.</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 <code>Heisei</code> if the date represented by <var>S</var> is not later than April <var>30</var>, <var>2019</var>, and print <code>TBD</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2019/04/30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Heisei
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2019/11/01
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>TBD
</pre></section>
</div>
</span> |
p01421 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Reverse Roads</H1>
<p>
ICP city has an express company whose trucks run from the crossing <var>S</var> to the crossing <var>T</var>.
The president of the company is feeling upset because all the roads in the city are one-way, and are severely congested.
So, he planned to improve the maximum flow (edge disjoint paths) from the crossing <var>S</var> to the crossing <var>T</var> by reversing the traffic direction on some of the roads.
</p>
<p>
Your task is writing a program to calculate the maximized flow from <var>S</var> to <var>T</var> by reversing some roads, and the list of the reversed roads.
</p>
<H2>Input</H2>
<p>
The first line of a data set contains two integers <var>N</var> (<var>2 \leq N \leq 300</var>) and <var>M</var> (<var>0 \leq M \leq {\rm min} (1\,000,\ N(N-1)/2)</var>).
<var>N</var> is the number of crossings in the city and <var>M</var> is the number of roads.
</p>
<p>
The following <var>M</var> lines describe one-way roads in the city.
The <var>i</var>-th line (<var>1</var>-based) contains two integers <var>X_i</var> and <var>Y_i</var> (<var>1 \leq X_i, Y_i \leq N</var>, <var>X_i \neq Y_i</var>).
<var>X_i</var> is the ID number (<var>1</var>-based) of the starting point of the <var>i</var>-th road and <var>Y_i</var> is that of the terminal point.
The last line contains two integers <var>S</var> and <var>T</var> (<var>1 \leq S, T \leq N</var>, <var>S \neq T</var>, <var>1</var>-based).
</p>
<p>
The capacity of each road is <var>1</var>.
You can assume that <var>i \neq j</var> implies either <var>X_i \neq X_j</var> or <var>Y_i \neq Y_j</var>,
and either <var>X_i \neq Y_j</var> or <var>X_j \neq Y_i</var>.
</p>
<H2>Output</H2>
<p>
In the first line, print the maximized flow by reversing some roads.
In the second line, print the number <var>R</var> of the reversed roads.
In each of the following <var>R</var> lines, print the ID number (<var>1</var>-based) of a reversed road.
You may not print the same ID number more than once.
</p>
<p>
If there are multiple answers which would give us the same flow capacity, you can print any of them.
</p>
<H2>Sample Input 1</H2>
<pre>
2 1
2 1
2 1
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
1
0
</pre>
<H2>Sample Input 2</H2>
<pre>
2 1
1 2
2 1
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
1
1
1
</pre>
<H2>Sample Input 3</H2>
<pre>
3 3
3 2
1 2
3 1
1 3
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
2
2
1
3
</pre>
|
p01071 |
<h1>Monochrome Tile</h1>
<h2>Problem</h2>
<p>
çœãæ£æ¹åœ¢ã®ã¿ã€ã«ã暪æ¹åã« <var>W</var> åã瞊æ¹åã« <var>H</var> åãåèš <var>W</var> × <var>H</var> åæ·ãè©°ããããŠããã
</p>
<p>
倪éåã¯ã <var>i</var> æ¥ç®ã®æã«ãå·Šãã <var>ax<sub>i</sub></var> çªç®ã§äžãã <var>ay<sub>i</sub></var> çªç®ã®ã¿ã€ã«ãå·Šäžã
å·Šãã <var>bx<sub>i</sub></var> çªç®ã§äžãã <var>by<sub>i</sub></var> çªç®ã®ã¿ã€ã«ãå³äžã«ããé·æ¹åœ¢é åã«ååšããŠããã¿ã€ã«ããã¹ãŠçœããã©ããã確èªããã
ãããã¹ãŠã®ã¿ã€ã«ãçœãã£ãå Žåããããã®ã¿ã€ã«ããã¹ãŠé»ãå¡ãã€ã¶ãããã以å€ã®ãšãã¯äœãããªãã
</p>
<p>
<var>N</var> æ¥éã®ããããã®æ¥ã«ãããŠããã®æ¥ã®äœæ¥ãçµäºããæç¹ã§é»ãå¡ãã€ã¶ãããã¿ã€ã«ãäœæããããåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>W</var> <var>H</var>
<var>N</var>
<var>ax<sub>1</sub></var> <var>ay<sub>1</sub></var> <var>bx<sub>1</sub></var> <var>by<sub>1</sub></var>
<var>ax<sub>2</sub></var> <var>ay<sub>2</sub></var> <var>bx<sub>2</sub></var> <var>by<sub>2</sub></var>
...
<var>ax<sub>N</sub></var> <var>ay<sub>N</sub></var> <var>bx<sub>N</sub></var> <var>by<sub>N</sub></var>
</pre>
<p>
1è¡ç®ã«ã2ã€ã®æŽæ° <var>W</var> ãš <var>H</var> ã空çœåºåãã§äžããããã
2è¡ç®ã«ã1ã€ã®æŽæ° <var>N</var> ãäžããããã
3è¡ç®ããã® <var>N</var> è¡ã®ãã¡ <var>i</var> è¡ç®ã«ã¯ <var>i</var> æ¥ç®ã®æã«ç¢ºèªããé·æ¹åœ¢é åã衚ã
4ã€ã®æŽæ° <var>ax<sub>i</sub></var> <var>ay<sub>i</sub></var> <var>bx<sub>i</sub></var> <var>by<sub>i</sub></var> ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>W</var> ≤ 100000</li>
<li>2 ≤ <var>H</var> ≤ 100000</li>
<li>2 ≤ <var>N</var> ≤ 100000</li>
<li>1 ≤ <var>ax<sub>i</sub></var> ≤ <var>bx<sub>i</sub></var> ≤ <var>W</var> (1 ≤ <var>i</var> ≤ <var>N</var> )</li>
<li>1 ≤ <var>ay<sub>i</sub></var> ≤ <var>by<sub>i</sub></var> ≤ <var>H</var> (1 ≤ <var>i</var> ≤ <var>N</var> )</li>
</ul>
<h2>Output</h2>
<p>
<var>N</var> æ¥éã®ããããã®æ¥ã«ãããŠã<var>i</var> æ¥ç®ã®äœæ¥ãçµäºããæç¹ã§é»ãå¡ãã€ã¶ãããã¿ã€ã«ã®ææ°ã <var>i</var> è¡ç®ã«ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
5
1 1 3 3
3 2 4 2
4 3 5 4
1 4 5 4
4 1 4 1
</pre>
<h2>Sample Output 1</h2>
<pre>
9
9
13
13
14
</pre>
<p>
â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡<br>
â¡â¡â¡â¡â¡<br>
<br>
â 1 1 3 3<br>
<br>
â â â â¡â¡<br>
â â â â¡â¡<br>
â â â â¡â¡<br>
â¡â¡â¡â¡â¡<br>
<br>
â 3 2 4 2ãïŒãªã«ãããªãïŒ<br>
<br>
â â â â¡â¡<br>
â â â â¡â¡<br>
â â â â¡â¡<br>
â¡â¡â¡â¡â¡<br>
<br>
â 4 3 5 4<br>
<br>
â â â â¡â¡<br>
â â â â¡â¡<br>
â â â â â <br>
â¡â¡â¡â â <br>
<br>
â 1 4 5 4 ïŒãªã«ãããªãïŒ<br>
<br>
â â â â¡â¡<br>
â â â â¡â¡<br>
â â â â â <br>
â¡â¡â¡â â <br>
<br>
â 4 1 4 1<br>
<br>
â â â â â¡<br>
â â â â¡â¡<br>
â â â â â <br>
â¡â¡â¡â â <br>
<br>
ãã£ãŠåºåã¯ã 9 â 9 â 13 â 13 â 14 ãšãªãã
</p> |
p00230 |
<H1>å¿è
ã®ãã«ç»ã</H1>
<p>
å¿è
ã®ãã€ãããã¯ãæ¯æ¥ææ©ãããå€é
ããŸã§å¿è
ãã«ã®å±äžããçºãèŠåããŠããŸãããã®å¿è
ãã«ã¯ã飿¥ãã 2 ã€ã®åãéæ°ã®ãã«ã§ããããã€ãããã¯èŠåã®ããã«ããã«ãšãã«ã®éããžã£ã³ãããªããå±äžãžåããããšãæ¥èª²ãšããŠããŸãã
</p>
<p>
ãã® 2 ã€ã®ãã«ã¯é »ç¹ã«æž
æãè¡ãããããããã«ç»ãã®å©ããšãªãã¯ãããé害ãšãªãæ»ããããéšåããããŸãã ããããã¯ãããæ»ããããéšåã®äœçœ®ã¯æ¯æ¥å€ãããŸãã ãã®ãããã€ãããã¯ãå±äžãžåããæ¹æ³ãæ¯æ¥èããªããã°ãããŸããã<!--ãã€ãããã¯ãäœåã®ãžã£ã³ãã§å±äžã«ãã©ãçããã§ãããã?-->
</p>
<p>
ãã€ãããã¯äºã€äžŠãã åãéæ°ã®ãã«ã®å£ãè·³ã³ç§»ããªããããã«ã®å±äžãç®æããŸãããžã£ã³ã
ã¯ã©ã¡ããäžæ¹ã®ãã«ã®1éããå§ããããŸããåããåŽã®ãã«ãžãžã£ã³ããããšãã«ã¯ãåãéã»1ã€äžã®éã»2 ã€äžã®éã®ãããããã«é£ã³ç§»ãããšãã§ããŸãã
</p>
<p>
å£ã«ã¯ä»¥äžã® 3 çš®é¡ããããããããã®å£ã«ãžã£ã³ãããåŸã®ç§»åãæ±ºãŸã£ãŠããŸãã
</p>
<ul>
<li>0. æ®éã®å£: äžäžã®ç§»åã¯ããªããæ¬¡ã®ãžã£ã³ãã¯ããããè¡ãã</li>
<li>1. ã¯ãã: ã¯ãã㯠2 ã€ä»¥äžã®éã«ãŸããã£ãŠããã£ãŠãããä»ããã¯ããã®äžçªäžãŸã§ç§»åãããæ¬¡ã®ãžã£ã³ãã¯ããããè¡ãã</li>
<li>2. ãã¹ãå£: æ®éã®å£ãã¯ããã®äžçªäžãŸã§æ»ãèœã¡ããæ¬¡ã®ãžã£ã³ãã¯ããããè¡ãã</li>
</ul>
<p>
ãŸããå£ã¯ 1 éããå±äžã®ããäžã®æäžéãŸã§ãããå±äžãžã¯ãã®ãã«ã®æäžéããã®ã¿è¡ãããšã
ã§ããŸãããŸãããã«ã®æäžéã®å£ã¯ãã¹ãå£ã«ã¯ãªããŸããã
</p>
<p>
2 ã€ã®ãã«ã®éæ° <var>n</var> ãš 2 ã€ã®ãã«ã®å£ã®çš®é¡ãå
¥åãšããæå°ã§äœåç®ã®ãžã£ã³ãã§æäžéãŸã§ãã©ãçããå±äžãŸã§è¡ãããšãã§ããããåºåããããã°ã©ã ãäœæããŠãã ããããªããã©ã¡ãã®ãã«ã®å±äžã«ãã©ãçããŠããããã®ãšããŸãããã ãããã€ããããã©ã¡ãã®ãã«ã®å±äžãžããã©ãçããªãå Žåã¯âNAâãšåºåããŠãã ããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ninjabill"><br/>
<br/>
</center>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>n</sub></var>
<var>b<sub>1</sub></var> <var>b<sub>2</sub></var> ... <var>b<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãã«ã®éæ° <var>n</var> (3 ≤ <var>n</var> ≤ 100) ãäžããããŸããïŒè¡ç®ã«ïŒ ã€ç®ã®ãã«ã® 1 éãã <var>n</var> éãŸã§ã®å£ã®æ
å ± <var>a<sub>i</sub></var>ãïŒè¡ç®ã«ïŒã€ç®ã®ãã«ã® 1 éãã <var>n</var> éãŸã§ã®å£ã®æ
å ± <var>b<sub>i</sub></var> ãäžããããŸãã<var>a<sub>i</sub>, b<sub>i</sub></var> ã¯<var>i</var> éç®ã®å£ã®æ
å ±ã衚ãã0 ãæ®éã®å£ã1 ãã¯ãã(<var>i</var> éãš <var>i</var>+1 éã«ãŸããã)ã2 ããã¹ãå£ã衚ããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 60 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ããžã£ã³ãã®åæ°ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
8
0 0 0 2 2 2 0 0
1 1 1 1 0 0 0 0
4
1 1 2 2
0 0 2 2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
NA
</pre>
|
p01972 | <h2>FïŒ æçè·é¢ã䌞ã°ããã³ã¡ãã (Ebi-chan Lengthens Shortest Paths)</h2>
<h3>Problem</h3>
<p>
Ebi-chan loves directed graphs.
One day, a directed graph with <var>N</var> vertices and <var>M</var> edges dropped from somewhere in front of Ebi-chan!
The vertices and the edges of the graph is labeled with a number from <var>1</var> to <var>N</var> and from <var>1</var> to <var>M</var>, respectively.
Moreover, the <var>i</var>th edge directs from a vertex <var>u_i</var> to a vertex <var>v_i</var> with distance <var>d_i</var>.
</p>
<p>
Ebi-chan thought that, for a pair of vertices <var>s</var> and <var>t</var>, she tries to lengthen the distance of shortest paths from <var>s</var> to <var>t</var>.
Although Ebi-chan should lengthen all edges slightly to easily achieve hers goal, she can not enjoy the directed graph with such way!
So, she decided the following rules of operations that can be done by her.
</p>
<ul>
<li> She can lengthen each edges independently.</li>
<li> When she lengthens an edge, she must select the additional distance from positive integers.</li>
<li> The <var>i</var>th edge takes a cost <var>c_i</var> per additional distance 1.</li>
</ul>
<p>How is the minimum total cost of operations needed to achieve Ebi-chanâs goal?</p>
<h3>Input Format</h3>
<p>An input is given in the following format.</p>
<pre>
<var>N</var> <var>M</var> <var>s</var> <var>t</var>
<var>u_1</var> <var>v_1</var> <var>d_1</var> <var>c_1</var>
$\vdots$
<var>u_M</var> <var>v_M</var> <var>d_M</var> <var>c_M</var>
</pre>
<p>In line <var>1</var>, four integers <var>N</var>, <var>M</var>, <var>s</var>, and <var>t</var> are given in separating by en spaces. <var>N</var> and <var>M</var> is the number of vertices and edges, respectively. Ebi-chan tries to lengthen shortest paths from the vertex <var>s</var> to the vertex <var>t</var>.</p>
<p>Line <var>1 + i</var>, where <var>1 \leq i \leq M</var>, has the information of the <var>i</var>th edge. <var>u_i</var> and <var>v_i</var> are the start and end vertices of the edge, respectively. <var>d_i</var> and <var>c_i</var> represents the original distance and cost of the edge, respectively. These integers are given in separating by en spaces.</p>
<h3>Constraints</h3>
<ul>
<li> <var>2 \leq N \leq 200</var></li>
<li> <var>1 \leq M \leq 2,000</var></li>
<li> <var>1 \leq s, t \leq N, s \neq t</var></li>
<li> <var>1 \leq u_i, v_i \leq N, u_i \neq v_i</var> (<var>1 \leq i \leq M</var>) </li>
<li> For each <var>i, j</var> (<var>1 \leq i < j \leq M</var>), <var>u_i \neq u_j</var> or <var>v_i \neq v_j</var> are satisfied.</li>
<li> <var>1 \leq d_i \leq 10</var> (<var>1 \leq i \leq M</var>)</li>
<li> <var>1 \leq c_i \leq 10</var> (<var>1 \leq i \leq M</var>)</li>
<li> It is guaranteed that there is at least one path from <var>s</var> to <var>t</var>.</li>
</ul>
<h3>Output Format</h3>
<p>Print the minimum cost, that is to lengthen the distance of shortest paths from <var>s</var> to <var>t</var> at least 1, in one line.</p>
<h3>Example 1</h3>
<pre>
3 3 1 3
1 2 1 1
2 3 1 1
1 3 1 1
</pre>
<h3>Output 1</h3>
<pre>1</pre>
<p>Ebi-chan should lengthen 3rd edge with additional distance 1.</p>
<h3>Exapmle 2</h3>
<pre>
8 15 5 7
1 5 2 3
3 8 3 6
8 7 1 3
2 7 6 4
3 7 5 5
8 3 1 3
5 6 3 5
1 7 3 2
4 3 2 4
5 4 4 3
2 3 2 2
2 8 6 5
6 2 1 3
4 2 1 6
6 1 4 2
</pre>
<h3>Output 2</h3>
<pre>8</pre>
|
p00660 |
<H1>Problem B: High & Low Cube</H1>
<p>
åã¯è¿æã®å°åŠçãã¡ãšäžç·ã«å€ç¥ãã«æ¥ãŠãããæãäœã«èšãã°ä¿è·è
圹ã ããåºåºã®çŒããã°ãããçŒããªãããçŒããåããææèãããæã¡äžãè±ç«ã®é³ãªã©ã¯ããã®æ³ã«ãªã£ãŠãå¿ãèžããã®ãããããã奜å¥å¿æºçãªåäŸãã¡ãã¯ãããªãããã«ã仿¥ã¯ãã£ããèŠå®ã£ãŠããªããšã
</p>
<p>
åäŸãã¡ã¯ãšããåºåºã«èå³ãæã£ãããã ã£ããèŠã蟌ãã§ã¿ããšãããã§ã¯åºåºã®ãããããšãµã€ã³ãã䜿ã£ãã²ãŒã ãããŠãåãŠã°æ¯åãè²°ããããšã«ãªã£ãŠããããã®ã²ãŒã ã¯ã High & Low ãšåŒã°ããåçŽãªãã®ã ãåå è
ãšããããã¯1åãã€ãµã€ã³ããæ¯ããããã®åã«åå è
ã¯ãèªåã®åºç®ãããããã®åºç®ãã倧ãããå°ããããäºæ³ãããäºæ³ãåœããã°åå©ã§ãããåãç®ãåºãå Žåã¯ã©ã¡ãããµã€ã³ããæ¯ãçŽãã
</p>
<p>
ãã®ã²ãŒã ã®å°ãåä»ãªãšããã¯ãåå è
ã®ãµã€ã³ããšããããã®ãµã€ã³ããéããã®ã§ãããããããªãããšããç¹ã ãåå è
ã¯ãããããäž¡è
ã®ãµã€ã³ãã®å±éå³ãèŠãããšãã§ããã®ã§ãããããã³ãã«äºæ³ããããšã«ãªãã
</p>
<p>
ã€ãŸããç°¡åãªç¢ºçã®èšç®ã ããšã¯ãã確çã¯é«æ ¡æ°åŠã®ç¯å²ã§ãå°åŠçã«ã¯ã¡ãã£ãšè·ãéããããããªããåäŸãã¡ã®äžã§äžçªå©çºãããªåã§ãããäžã€ç·šã¿ã«ããé«ªãæºãããªããèã蟌ãã§ãããããããåã«å©ããæ±ããŠããããšã ãããããŠãããŸã«ã¯ãªããããããšãããèŠããŠããããã§ã¯ãªããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã<br>
</p>
<p>
åã±ãŒã¹ã§ã¯ããµã€ã³ãã®å±éå³ã21Ã57ã®ã°ãªããã§äžããããã<br>
æåã®21Ã28ïŒ(0,0)ãå·Šäž,(20,27)ãå³äžïŒã®ã°ãªãããåå è
ã®ãµã€ã³ãã衚ãã<br>
æåŸã®21Ã28ïŒ(0,29)ãå·Šäž,(20,56)ãå³äžïŒãããããã®ãµã€ã³ãã衚ãã<br>
</p>
<p>
åå è
ã®ãµã€ã³ãã®åé¢ã¯(0,7)ã(7,0)ã(7,7)ã(7,14)ã(7,21)ã(14,7)ãå·Šäžãšãã7Ã7ã®ãµãã°ãªããã§äžããããŠããã<br>
å±éå³ã«æžãããŠããæ°åã¯ãããããå
ã®æ°åã<br>
å·Šå³å転<br>
å·Šå³å転ããã®ããšã§åæèšåãã«90床å転<br>
å·Šå³å転<br>
å·Šå³å転ããã®ããšã§åæèšåãã«270床å転<br>
å·Šå³å転<br>
äžäžå転ããã®ããšã§å·Šå³å転<br>
ããããã®ã§ããã<br>
</p>
<p>
ããããã®ãµã€ã³ãã®åé¢ã¯(0,36)ã(7,29)ã(7,36)ã(7,43)ã(7,50)ã(14,36)ãå·ŠäžãšããïŒÃïŒã®ãµãã°ãªããã§äžããããŠããã<br>
ããããã®ãµã€ã³ãã®å±éå³ã«æžãããŠããæ°åã¯åå è
ã®ãµã€ã³ããšåãèŠåã§æãããŠããã<br>
</p>
<pre>
ãµã€ã³ãã®åé¢ã«ã¯1ãã9ãŸã§ã®äžã®ã©ãããæžãããŠããã
æ°åã¯ä»¥äžã®ãããª7x7ã®ã°ãªããã§äžããããã
#######
#.....#
#...|.#
#.....#
#...|.#
#..-..#
#######
#######
#..-..#
#...|.#
#..-..#
#.|...#
#..-..#
#######
#######
#..-..#
#...|.#
#..-..#
#...|.#
#..-..#
#######
#######
#.....#
#.|.|.#
#..-..#
#...|.#
#.....#
#######
#######
#..-..#
#.|...#
#..-..#
#...|.#
#..-..#
#######
#######
#..-..#
#.|...#
#..-..#
#.|.|.#
#..-..#
#######
#######
#..-..#
#...|.#
#.....#
#...|.#
#.....#
#######
#######
#..-..#
#.|.|.#
#..-..#
#.|.|.#
#..-..#
#######
#######
#..-..#
#.|.|.#
#..-..#
#...|.#
#..-..#
#######
</pre>
<pre>
ãã ãäžèšã®æ°åã90床ããŸãã¯270床å転ãããæã"|"ãš"-"ã¯å
¥ãæ¿ãã£ãŠããã
</pre>
<p>
å
¥åã®çµããã¯1ã€ã®0ãããªãè¡ã«ãã£ãŠäžãããã
</p>
<p>
å
¥åãšããŠäžãããããµã€ã³ãã¯å¿
ãæ£ããç©ã§ããã
ãŸã決çãã€ããªããããªãµã€ã³ãã¯äžããããªãã
</p>
<h2>Output</h2>
<p>
"HIGH"ã«ãªãå Žåãš"LOW"ã«ãªãå Žåã§ç¢ºçãé«ãã»ãã1è¡ã«åºåããã
äž¡è
ã®ç¢ºçãåãå Žåã¯"HIGH"ãåºåããã
</p>
<h2>Sample input</h2>
<pre>
.......#######......................#######..............
.......#.....#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#.....#......................#..-..#..............
.......#.|...#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
#.-.-.##...|.##.-.-.##.|.|.#.#.....##.|.|.##.-.-.##.|.|.#
#|.|.|##..-..##|.|.|##..-..#.#....|##..-..##|.|.|##..-..#
#...-.##.|...##...-.##.|.|.#.#.-.-.##.|...##...-.##.|...#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#.|.|.#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
#.-.-.##...|.##.-.-.##.|.|.#.#...-.##...|.##.-...##.|.|.#
#|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..#
#.-.-.##.|...##...-.##.|...#.#.-...##.|.|.##.-.-.##.|...#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##.....#
#.-.-.##.|.|.##.-.-.##...|.#.#.....##.|.|.##...-.##.|...#
#|.|.|##..-..##|....##..-..#.#....|##..-..##|.|.|##.....#
#.-.-.##.|.|.##.....##.|.|.#.#.-.-.##.|.|.##.-...##.|...#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|.|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
#.-.-.##...|.##.-.-.##.|.|.#.#.-...##.|.|.##.-...##.|.|.#
#|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..#
#...-.##.|...##.-.-.##.|.|.#.#.-.-.##.|...##.-.-.##.|.|.#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
0
</pre>
<H2>Sample output</H2>
<pre>
LOW
HIGH
HIGH
LOW
</pre>
<hr>
<p>
The University of Aizu Programming Contest 2011 Summer<br>
åæ¡ãå顿: Takashi Tayama<br>
</p> |
p02173 | <h1>Problem L: Space Travel</h1>
<h2>Story</h2>
<p>
é ãæãã¯ããããªãã®é河系ã§ã<br>
æã¯å
ä¹±ã®åµãå¹ãèããããªããå¶æªãªéæ²³åžåœã®è»å¢ãåä¹±è»ã®ç§å¯åºå°ã襲ã£ãã<br>
æãã¹ãåžåœå®å®èŠéã®è¿œæããéããããŠãŒã¯ã»ã¹ã¿ãŒãŠã©ãŒã«ãŒã«ãã£ãŠçããããèªç±ã®æŠå£«ãã¡ã¯ãéæ²³ã®èŸºå¢ã«æ°ããªç§å¯åºå°ãç¯ãããšã«ããã<br>
åä¹±è»ã®äžå¡ã§ãããåè
ã®ããã°ã©ããŒã§ããããªãã«ããããããããã·ã§ã³ã¯ãéæ²³ç³»ã®ããããã®ææããæãé¢ããææãèŠã€ããããšã§ããã
</p>
<h2>Problem</h2>
<p>
éæ²³ç³»ã«ã¯ $N$ åã®ææãããã$M$ åã®ãæ©ããšåŒã°ããç§å¯ã®ã«ãŒããããã<br>
ææã«ã¯ãããã $1,2, \ldots N$ ã®çªå·ããæ©ã«ã¯ãããã $1,2, \ldots M$ ã®çªå·ãã€ããŠããã<br>
åææã®äœçœ®ã¯å®äžæ¬¡å
空éäžã®ç¹ãšããŠè¡šãããææ $p$ 㯠$(x_p,y_p,z_p)$ ã«äœçœ®ããã<br>
$i$ çªç®ã®æ©ã¯ãææ $u_i$ ãã $v_i$ ãžãšåããç§å¯ã®ã«ãŒãã§ããã<br>
$i$ çªç®ã®æ©ã䜿ã£ãŠææ $v_i$ ãã $u_i$ ãžçŽæ¥ç§»åããããšã¯ã§ããªãããšã«æ³šæããã<br>
<br>
ææ $p$ ãš $q$ ã®è·é¢ã以äžã®ããã«å®çŸ©ããã<br>
$\mathrm{d} (p,q) = |x_p - x_q| + |y_p - y_q| + |z_p - z_q|$<br>
<br>
ææ $p$ ãã $0$ å以äžã®æ©ãäŒã£ãŠå°éå¯èœãªææã®éåã $S_p$ ãšããã
å $p$ ã«ã€ããŠã$\displaystyle \max_{s \in S_p} \mathrm{d} (p,s)$ ãæ±ããã<br>
ãã ããåä¹±è»ã¯åžžã«å¶æªãªéæ²³åžåœã®è»å¢ã«çãããŠãããããæ©ä»¥å€ã®ã«ãŒãã§ææéãç§»åããããšã¯ã§ããªãã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $M$
$x_1$ $y_1$ $z_1$
$\vdots$
$x_N$ $y_N$ $z_N$
$u_1$ $v_1$
$\vdots$
$u_M$ $v_M$
</pre>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq N \leq 2 \times 10^5$</li>
<li>$1 \leq M \leq 5 \times 10^5$</li>
<li>$1 \leq u_i , v_i \leq N$</li>
<li>$|x_p|,|y_p|,|z_p| \leq 10^8$</li>
<li>$u_i \neq v_i$</li>
<li>$i \neq j$ ãªã $(u_i,v_i) \neq (u_j,v_j)$</li>
<li>$p \neq q$ ãªã $(x_p,y_p,z_p) \neq (x_q,y_q,z_q)$</li>
<li>å
¥åã¯å
šãп޿°ã§ãã</li>
</ul>
<h2>Output</h2>
<p>
$N$ è¡åºåããã<br>
$i$ è¡ç®ã«ã¯ $\displaystyle \max_{s \in S_i} \mathrm{d} (i,s)$ ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
2 1
1 1 1
2 2 2
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3
0
</pre>
<h2>Sample Input 2</h2>
<pre>
2 2
1 1 1
2 2 2
1 2
2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
3
3
</pre>
<h2>Sample Input 3</h2>
<pre>
6 6
0 8 0
2 3 0
2 5 0
4 3 0
4 5 0
6 0 0
1 3
2 3
3 5
5 4
4 2
4 6
</pre>
<h2>Sample Output 3</h2>
<pre>
14
7
9
5
7
0
</pre>
<h2>Sample Input 4</h2>
<pre>
10 7
-65870833 -68119923 -51337277
-59513976 -24997697 -46968492
-37069671 -90713666 -45043609
-31144219 43731960 -5258464
-27501033 90001758 13168637
-96651565 -67773915 56786711
44851572 -29156912 28758396
16384813 -79097935 7386228
88805434 -79256976 31470860
92682611 32019492 -87335887
6 7
7 9
6 5
1 2
2 4
4 1
9 8
</pre>
<h2>Sample Output 4</h2>
<pre>
192657310
138809442
0
192657310
0
270544279
99779950
0
96664294
0
</pre>
|
p03298 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>2N</var> consisting of lowercase English letters.</p>
<p>There are <var>2^{2N}</var> ways to color each character in <var>S</var> red or blue. Among these ways, how many satisfy the following condition?</p>
<ul>
<li>The string obtained by reading the characters painted red <strong>from left to right</strong> is equal to the string obtained by reading the characters painted blue <strong>from right to left</strong>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 18</var></li>
<li>The length of <var>S</var> is <var>2N</var>.</li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to paint the string that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
cabaacba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four ways to paint the string, as follows:</p>
<ul>
<li><span style="color:red">c</span><span style="color:blue">a</span><span style="color:blue">b</span><span style="color:blue">a</span><span style="color:red">a</span><span style="color:blue">c</span><span style="color:red">b</span><span style="color:red">a</span></li>
<li><span style="color:red">c</span><span style="color:blue">a</span><span style="color:blue">b</span><span style="color:red">a</span><span style="color:blue">a</span><span style="color:blue">c</span><span style="color:red">b</span><span style="color:red">a</span></li>
<li><span style="color:blue">c</span><span style="color:red">a</span><span style="color:red">b</span><span style="color:red">a</span><span style="color:blue">a</span><span style="color:red">c</span><span style="color:blue">b</span><span style="color:blue">a</span></li>
<li><span style="color:blue">c</span><span style="color:red">a</span><span style="color:red">b</span><span style="color:blue">a</span><span style="color:red">a</span><span style="color:red">c</span><span style="color:blue">b</span><span style="color:blue">a</span></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>11
mippiisssisssiipsspiim
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>504
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
abcdefgh
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>18
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>9075135300
</pre>
<p>The answer may not be representable as a <var>32</var>-bit integer.</p></section>
</div>
</span> |
p03762 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On a two-dimensional plane, there are <var>m</var> lines drawn parallel to the <var>x</var> axis, and <var>n</var> lines drawn parallel to the <var>y</var> axis.
Among the lines parallel to the <var>x</var> axis, the <var>i</var>-th from the bottom is represented by <var>y = y_i</var>.
Similarly, among the lines parallel to the <var>y</var> axis, the <var>i</var>-th from the left is represented by <var>x = x_i</var>.</p>
<p>For every rectangle that is formed by these lines, find its area, and print the total area modulo <var>10^9+7</var>.</p>
<p>That is, for every quadruple <var>(i,j,k,l)</var> satisfying <var>1\leq i < j\leq n</var> and <var>1\leq k < l\leq m</var>, find the area of the rectangle formed by the lines <var>x=x_i</var>, <var>x=x_j</var>, <var>y=y_k</var> and <var>y=y_l</var>, and print the sum of these areas modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq n,m \leq 10^5</var></li>
<li><var>-10^9 \leq x_1 < ... < x_n \leq 10^9</var></li>
<li><var>-10^9 \leq y_1 < ... < y_m \leq 10^9</var></li>
<li><var>x_i</var> and <var>y_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var> <var>m</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_n</var>
<var>y_1</var> <var>y_2</var> <var>...</var> <var>y_m</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total area of the rectangles, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 3 4
1 3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>60
</pre>
<p>The following figure illustrates this input:</p>
<p><img alt="sample1-1" src="https://atcoder.jp/img/arc071/aec4d5cc2e5c73dbee455be237a649a5.png"/></p>
<p>The total area of the nine rectangles A, B, ..., I shown in the following figure, is <var>60</var>.</p>
<p><img alt="sample1-2" src="https://atcoder.jp/img/arc071/f0771c0f7e68af2b00e7513186f585ff.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 5
-790013317 -192321079 95834122 418379342 586260100 802780784
-253230108 193944314 363756450 712662868 735867677
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>835067060
</pre></section>
</div>
</span> |
p02870 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In a two-dimensional plane, there is a square frame whose vertices are at coordinates <var>(0,0)</var>, <var>(N,0)</var>, <var>(0,N)</var>, and <var>(N,N)</var>.
The frame is made of mirror glass. A ray of light striking an edge of the frame (but not a vertex) will be reflected so that the angle of incidence is equal to the angle of reflection.
A ray of light striking a vertex of the frame will be reflected in the direction opposite to the direction it is coming from.</p>
<p>We will define the <em>path</em> for a grid point (a point with integer coordinates) <var>(i,j)</var> (<var>0<i,j<N</var>) strictly within the frame, as follows:</p>
<ul>
<li>The path for <var>(i,j)</var> is the union of the trajectories of four rays of light emitted from <var>(i,j)</var> to <var>(i-1,j-1)</var>, <var>(i-1,j+1)</var>, <var>(i+1,j-1)</var>, and <var>(i+1,j+1)</var>.</li>
</ul>
<div style="text-align: center;">
<img src="https://img.atcoder.jp/nikkei2019-2-qual/f82200c30253b6e06c6043a2c7668735.png">
<p>Figure: an example of a path for a grid point</p>
</img></div>
<p>There is a light bulb at each grid point strictly within the frame. We will assign a state - ON or OFF - to each bulb. The state of the whole set of bulbs are called <em>beautiful</em> if it is possible to turn OFF all the bulbs by repeating the following operation:</p>
<ul>
<li>Choose a grid point strictly within the frame, and switch the states of all the bulbs on its path.</li>
</ul>
<p>Takahashi has set the states of some of the bulbs, but not for the remaining bulbs.
Find the number of ways to set the states of the remaining bulbs so that the state of the whole set of bulbs is beautiful, modulo <var>998244353</var>.
The state of the bulb at the grid point <var>(i,j)</var> is set to be ON if <var>A_{i,j}=</var><code>o</code>, OFF if <var>A_{i,j}=</var><code>x</code>, and unset if <var>A_{i,j}=</var><code>?</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 1500</var></li>
<li><var>A_{ij}</var> is <code>o</code>, <code>x</code>, or <code>?</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1,1}...A_{1,N-1}</var>
<var>:</var>
<var>A_{N-1,1}...A_{N-1,N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
o?o
???
?x?
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The state of the whole set of bulbs will be beautiful if we set the state of each bulb as follows:</p>
<pre>oxo
xox
oxo
</pre>
<p>We can turn OFF all the bulbs by, for example, choosing the point <var>(1, 1)</var> and switching the states of the bulbs at <var>(1,1)</var>, <var>(1,3)</var>, <var>(2,2)</var>, <var>(3,1)</var>, and <var>(3,3)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
o?o?
????
o?x?
????
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
?o???
????o
??x??
o????
???o?
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>32
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>9
????o??x
?????x??
??o?o???
?o?x????
???????x
x?o?o???
????????
x?????x?
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>4
</pre></section>
</div>
</span> |
p03332 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has a tower which is divided into <var>N</var> layers.
Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower.
He defines the <em>beauty of the tower</em> as follows:</p>
<ul>
<li>The beauty of the tower is the sum of the scores of the <var>N</var> layers, where the score of a layer is <var>A</var> if the layer is painted red, <var>A+B</var> if the layer is painted green, <var>B</var> if the layer is painted blue, and <var>0</var> if the layer is uncolored.</li>
</ul>
<p>Here, <var>A</var> and <var>B</var> are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.</p>
<p>Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly <var>K</var>.
How many such ways are there to paint the tower? Find the count modulo <var>998244353</var>.
Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †3Ã10^5</var></li>
<li><var>1 †A,B †3Ã10^5</var></li>
<li><var>0 †K †18Ã10^{10}</var></li>
<li>All values in the 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</var> <var>B</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the ways to paint tiles, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 1 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>40
</pre>
<p>In this case, a red layer worth <var>1</var> points, a green layer worth <var>3</var> points and the blue layer worth <var>2</var> points. The beauty of the tower is <var>5</var> when we have one of the following sets of painted layers:</p>
<ul>
<li><var>1</var> green, <var>1</var> blue</li>
<li><var>1</var> red, <var>2</var> blues</li>
<li><var>2</var> reds, <var>1</var> green</li>
<li><var>3</var> reds, <var>1</var> blue</li>
</ul>
<p>The total number of the ways to produce them is <var>40</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 5 6 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>The beauty of the tower is <var>0</var> only when all the layers are uncolored. Thus, the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>90081 33447 90629 6391049189
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>577742975
</pre></section>
</div>
</span> |
p03627 | <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> sticks with negligible thickness.
The length of the <var>i</var>-th stick is <var>A_i</var>.</p>
<p>Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible area of the rectangle.
If no rectangle can be formed, print <var>0</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
3 1 2 4 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p><var>1 \times 2</var> rectangle can be formed.</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
</pre>
<p>No rectangle can be formed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
3 3 3 3 4 4 4 5 5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>20
</pre></section>
</div>
</span> |
p00908 |
<H1><font color="#000">Problem E: </font> Sliding Block Puzzle</H1>
<p>
In sliding block puzzles, we repeatedly slide pieces (blocks) to open spaces within a frame to establish a goal placement of pieces.
</p>
<p>
A puzzle creator has designed a new puzzle by combining the ideas of sliding block puzzles and mazes. The puzzle is played in a rectangular frame segmented into unit squares. Some squares are pre-occupied by obstacles. There are a number of pieces placed in the frame, one 2 × 2 king piece and some number of 1 × 1 pawn pieces. Exactly two 1 × 1 squares are left open. If a pawn piece is adjacent to an open square, we can slide the piece there. If a whole edge of the king piece is adjacent to two open squares, we can slide the king piece. We cannot move the obstacles. Starting from a given initial placement, the objective of the puzzle is to move the king piece to the upper-left corner of the frame.
</p>
<p>
The following figure illustrates the initial placement of the fourth dataset of the sample input.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_slidingBlockPuzzle"><br/>
<p>
Figure E.1: The fourth dataset of the sample input.
</p>
</center>
<p>
Your task is to write a program that computes the minimum number of moves to solve the puzzle from a given placement of pieces. Here, one move means sliding either king or pawn piece to an adjacent position.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The first line of a dataset consists of two integers <i>H</i> and <i>W</i> separated by a space, where <i>H</i> and <i>W</i> are the height and the width of the frame. The following <i>H</i> lines, each consisting of <i>W</i> characters, denote the initial placement of pieces. In those <i>H</i> lines, '<span>X</span>', '<span>o</span>', '<span>*</span>', and '<span>.</span>' denote a part of the king piece, a pawn piece, an obstacle, and an open square, respectively. There are no other characters in those <i>H</i> lines. You may assume that 3 ≤ <i>H</i> ≤ 50 and 3 ≤ <i>W</i> ≤ 50.
</p>
<p>
A line containing two zeros separated by a space indicates the end of the input.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing the minimum number of moves required to move the king piece to the upper-left corner. If there is no way to do so, output <span>-1</span>.
</p>
<H2>Sample Input</H2>
<pre>
3 3
oo.
oXX
.XX
3 3
XXo
XX.
o.o
3 5
.o*XX
oooXX
oooo.
7 12
oooooooooooo
ooooo*****oo
oooooo****oo
o**ooo***ooo
o***ooooo..o
o**ooooooXXo
ooooo****XXo
5 30
oooooooooooooooooooooooooooooo
oooooooooooooooooooooooooooooo
o***************************oo
XX.ooooooooooooooooooooooooooo
XX.ooooooooooooooooooooooooooo
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
11
0
-1
382
6807
</pre> |
p02935 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have a pot and <var>N</var> ingredients. Each ingredient has a real number parameter called <em>value</em>, and the value of the <var>i</var>-th ingredient <var>(1 \leq i \leq N)</var> is <var>v_i</var>.</p>
<p>When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be <var>(x + y) / 2</var> where <var>x</var> and <var>y</var> are the values of the ingredients consumed, and you can put this ingredient again in the pot.</p>
<p>After you compose ingredients in this way <var>N-1</var> times, you will end up with one ingredient. Find the maximum possible value of this ingredient.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 50</var></li>
<li><var>1 \leq v_i \leq 1000</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>v_1</var> <var>v_2</var> <var>\ldots</var> <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.</p>
<p>Your output will be judged correct when its absolute or relative error from the judge's output is at most <var>10^{-5}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3.5
</pre>
<p>If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values <var>3</var> and <var>4</var> is <var>(3 + 4) / 2 = 3.5</var>.</p>
<p>Printing <code>3.50001</code>, <code>3.49999</code>, and so on will also be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
500 300 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>375
</pre>
<p>You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:</p>
<ul>
<li>Use the ingredients of values <var>500</var> and <var>300</var> to produce an ingredient of value <var>(500 + 300) / 2 = 400</var>. The next composition will use this ingredient and the ingredient of value <var>200</var>, resulting in an ingredient of value <var>(400 + 200) / 2 = 300</var>.</li>
<li>Use the ingredients of values <var>500</var> and <var>200</var> to produce an ingredient of value <var>(500 + 200) / 2 = 350</var>. The next composition will use this ingredient and the ingredient of value <var>300</var>, resulting in an ingredient of value <var>(350 + 300) / 2 = 325</var>.</li>
<li>Use the ingredients of values <var>300</var> and <var>200</var> to produce an ingredient of value <var>(300 + 200) / 2 = 250</var>. The next composition will use this ingredient and the ingredient of value <var>500</var>, resulting in an ingredient of value <var>(250 + 500) / 2 = 375</var>.</li>
</ul>
<p>Thus, the maximum possible value of the last ingredient remaining is <var>375</var>.</p>
<p>Printing <code>375.0</code> and so on will also be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
138 138 138 138 138
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>138
</pre></section>
</div>
</span> |
p03277 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will define the <strong>median</strong> of a sequence <var>b</var> of length <var>M</var>, as follows:</p>
<ul>
<li>Let <var>b'</var> be the sequence obtained by sorting <var>b</var> in non-decreasing order. Then, the value of the <var>(M / 2 + 1)</var>-th element of <var>b'</var> is the median of <var>b</var>. Here, <var>/</var> is integer division, rounding down.</li>
</ul>
<p>For example, the median of <var>(10, 30, 20)</var> is <var>20</var>; the median of <var>(10, 30, 20, 40)</var> is <var>30</var>; the median of <var>(10, 10, 10, 20, 30)</var> is <var>10</var>.</p>
<p>Snuke comes up with the following problem.</p>
<p>You are given a sequence <var>a</var> of length <var>N</var>.
For each pair <var>(l, r)</var> (<var>1 \leq l \leq r \leq N</var>), let <var>m_{l, r}</var> be the median of the contiguous subsequence <var>(a_l, a_{l + 1}, ..., a_r)</var> of <var>a</var>.
We will list <var>m_{l, r}</var> for all pairs <var>(l, r)</var> to create a new sequence <var>m</var>.
Find the median of <var>m</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 \leq a_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the median of <var>m</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
10 30 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>30
</pre>
<p>The median of each contiguous subsequence of <var>a</var> is as follows:</p>
<ul>
<li>The median of <var>(10)</var> is <var>10</var>.</li>
<li>The median of <var>(30)</var> is <var>30</var>.</li>
<li>The median of <var>(20)</var> is <var>20</var>.</li>
<li>The median of <var>(10, 30)</var> is <var>30</var>.</li>
<li>The median of <var>(30, 20)</var> is <var>30</var>.</li>
<li>The median of <var>(10, 30, 20)</var> is <var>20</var>.</li>
</ul>
<p>Thus, <var>m = (10, 30, 20, 30, 30, 20)</var> and the median of <var>m</var> is <var>30</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
10
</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>10
5 9 5 9 8 9 3 5 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p04048 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2âŠNâŠ10^{12}</var></li>
<li><var>1âŠXâŠN-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>NâŠ1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</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>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
p02036 | <h2>G: Donuts Orientation</h2>
<h3>ç©èª</h3>
<p>ã»ãã¡ããã®æè¿ã®ãã€ããŒã ã¯ãèåäœãã ããããããèåãäœã£ãŠã¯ããããåéã«ãããåãããŠãããããããããªã»ãã¡ããã¯ä»åãããŒããã¥ããã«ææŠããããã ã</p>
<p>ããŒããã¥ããã«å€§åãªããšã¯ããã€ããããçå°ãå³ä»ãã¯ãã¡ãããããããèŠãç®ã«ããããã®ãã³ã¬ãŒã·ã§ã³ãå€ããªãã詊è¡é¯èª€ãç¹°ãè¿ããŠãããã¡ã«ãã»ãã¡ããã®ãã³ã¬ãŒã·ã§ã³ãžã®ãã ããã«ç±ãããã£ãŠããããã ããã ããã¬ããããŒãããå€ãã®äººã«é£ã¹ãŠãããããã®ã§ãã»ãã¡ããã¯ããŒãããããããã€ãããããšèããŠããã</p>
<p>ã»ã»ã»ãšããã§ããã ããã®ã¯äžåã«æ§ããªãããã»ãã¡ãããã ããã®ããŒãããååãªæ°çšæããããšã¯ã§ããã®ã ãããïŒ</p>
<h3>åé¡</h3>
<p><var>3</var> 以äžã®æŽæ° <var>N</var> ã«ã€ããŠã以äžã®ããã«ã㊠<var>2N</var> é ç¹ã®ã°ã©ããäœãã</p>
<ul>
<li> ããããã®é ç¹ã«ã€ã㊠<var>1</var> ãã <var>2N</var> ã§çªå·ä»ãããã</li>
<li> åæŽæ° <var>1 \leq a \leq N</var> ã«ã€ããŠãé ç¹ <var>2a-1</var> ãš <var>2a</var> ã®éã«ç¡å蟺ã匵ã</li>
<li> åæŽæ° <var>1 \leq b \leq 2N-2</var> ã«ã€ããŠãé ç¹ <var>b</var> ãš <var>b+2</var> ã®éã«ç¡å蟺ã匵ã</li>
<li> é ç¹ <var>1</var> ãš <var>2N-1</var> ããã³ <var>2</var> ãš <var>2N</var> ã®éã«ç¡å蟺ã匵ã</li>
</ul>
<p>ãã®ã°ã©ãã®å蟺ã«åããã€ããŠãæåã°ã©ããäœããã€ãŸããé ç¹ <var>u</var> ãš <var>v</var> ã®éã«ç¡å蟺ããããªãã°ãããã <var>u</var> ãã <var>v</var> ãžåããæå蟺ã«ãããã<var>v</var> ãã <var>u</var> ãžåããæå蟺ã«ããã</p>
<p>ãã®ããã«ããŠã§ããæåã°ã©ãã§ãã£ãŠããµã€ã¯ã«ãæããªããã®ãäœéãããããç¥ããããçãã¯éåžžã«å€§ãããªããããçŽ æ° <var>M</var> ã§å²ã£ãäœããæ±ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre><var>N</var> <var>M</var></pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>3 \leq N \leq 1,000</var></li>
<li> <var>10^8 \leq M \leq 10^9 + 7</var></li>
<li> <var>M</var> ã¯çŽ æ°ã§ããããšãä¿èšŒããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>æ¡ä»¶ãæºããæåã°ã©ãã®æ°ã <var>M</var> ã§å²ã£ãäœããåºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>3 1000000007</pre>
<h3>åºåäŸ1</h3>
<pre>204</pre>
<p><var>N = 3</var> ãªã®ã§ã<var>6</var> é ç¹ãããªãã°ã©ããäœããæ¡ä»¶ã«åèŽããæåã°ã©ãã®äžäŸã¯ä»¥äžã®éãã§ããã</p>
<object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-g-001.png" type="image/png" width="400"></object>
<p>ãµã€ã¯ã«ãååšããããã以äžã«ç€ºãæåã°ã©ãã¯æ¡ä»¶ãæºãããªãã</p>
<object data="https://judgeapi.u-aizu.ac.jp/resources/images/hupc2019_rupc2019-g-002.png" type="image/png" width="400"></object>
<h3>å
¥åäŸ2</h3>
<pre>128 998244353</pre>
<h3>åºåäŸ2</h3>
<pre>996915100</pre>
<p><var>M</var> ã§å²ã£ãäœããåºåããããšã«æ³šæããã</p>
|
p02466 | <h1>Set Symmetric Difference</h1>
<p>
Find the symmetric difference of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
$m$
$b_0 \; b_1 \; ... \; b_{m-1}$
</pre>
<p>
Elements in $A$ and $B$ are given in ascending order. There are no duplicate elements in each set.
</p>
<h2>Output</h2>
<p>
Print elements in the symmetric difference in ascending order. Print an element in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n, m \leq 200,000$</li>
<li>$0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$</li>
<li>$0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
7
1 2 3 4 5 6 7
4
2 4 6 8
</pre>
<h2>Sample Output 1</h2>
<pre>
1
3
5
7
8
</pre>
|
p01163 |
<H1><font color="#000">Problem A:</font> Space Coconut Crab II</H1>
<p>
A space hunter, Ken Marineblue traveled the universe, looking for the space coconut crab. The
space coconut crab was a crustacean known to be the largest in the universe. It was said that
the space coconut crab had a body of more than 400 meters long and a leg span of no shorter
than 1000 meters long. Although there were numerous reports by people who saw the space
coconut crab, nobody have yet succeeded in capturing it.
</p>
<p>
After years of his intensive research, Ken discovered an interesting habit of the space coconut
crab. Surprisingly, the space coconut crab went back and forth between the space and the
hyperspace by phase drive, which was the latest warp technology. As we, human beings, was
not able to move to the hyperspace, he had to work out an elaborate plan to capture them.
Fortunately, he found that the coconut crab took a long time to move between the hyperspace
and the space because it had to keep still in order to charge a sufficient amount of energy for
phase drive. He thought that he could capture them immediately after the warp-out, as they
moved so slowly in the space.
</p>
<p>
He decided to predict from the amount of the charged energy the coordinates in the space
where the space coconut crab would appear, as he could only observe the amount of the charged
energy by measuring the time spent for charging in the hyperspace. His recent spaceship,
Weapon Breaker, was installed with an artificial intelligence system, CANEL. She analyzed the
accumulated data and found another surprising fact; the space coconut crab always warped out
near to the center of a triangle that satisfied the following conditions:
</p>
<ul>
<li>each vertex of the triangle was one of the planets in the universe;</li>
<li>the length of every side of the triangle was a prime number; and</li>
<li>the total length of the three sides of the triangle was equal to <i>T</i>, the time duration the
space coconut crab had spent in charging energy in the hyperspace before moving to the
space.</li>
</ul>
<p>
CANEL also devised the method to determine the three planets comprising the triangle from
the amount of energy that the space coconut crab charged and the lengths of the triangle sides.
However, the number of the candidate triangles might be more than one.
</p>
<p>
Ken decided to begin with calculating how many different triangles were possible, analyzing
the data he had obtained in the past research. Your job is to calculate the number of different
triangles which satisfies the conditions mentioned above, for each given <i>T</i>.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset comes with a line that contains a single
positive integer <i>T</i> (1 ≤ <i>T</i> ≤ 30000).
</p>
<p>
The end of input is indicated by a line that contains a zero. This should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the number of different possible triangles in a line. Two triangles are
different if and only if they are not congruent.
</p>
<H2>Sample Input</H2>
<pre>
10
12
15
777
4999
5000
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
1
2
110
2780
0
</pre>
|
p01499 |
<H1><font color="#000">Problem E: </font>Rabbit Game Playing</H1>
<p>
Honestly, a rabbit does not matter.
</p>
<p>
There is a rabbit playing a stage system action game. In this game, every stage has a difficulty level. The rabbit, which always needs challenges, basically wants to play more difficult stages than he has ever played. However, he sometimes needs rest too. So, to compromise, he admitted to play <i>T</i> or less levels easier stages than the preceding one.
</p>
<p>
How many ways are there to play all the stages at once, while honoring the convention above? Maybe the answer will be a large number. So, let me know the answer modulo 1,000,000,007.
</p>
<H2>Input</H2>
<p>
The first line of input contains two integers <i>N</i> and <i>T</i> (1 ≤ <i>N</i> ≤ 100,000, 1 ≤ <i>T</i> ≤ 10,000). <i>N</i> is the number of stages, and <i>T</i> is the compromise level.
</p>
<p>
The following <i>N</i> lines describe the difficulty levels of each stage. The <i>i</i>-th line contains one integer <i>D<sub>i</sub></i> (1 ≤ <i>D<sub>i</sub></i> ≤ 100,000), which is the difficulty level of the <i>i</i>-th stage.
</p>
<H2>Output</H2>
<p>
Calculate how many ways to play all the stages at once there are. Print the answer modulo 1,000,000,007 in a line.
</p>
<H2>Sample Input 1</H2>
<pre>
3 1
1
2
3
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
4
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
5 3
9
2
6
8
8
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
24
</pre>
<br/>
<H2>Sample Input 3</H2>
<pre>
5 7
9
9
9
1
5
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
48
</pre>
<br/> |
p01533 |
<h1> Acrophobia</h1>
<h2> C: 髿ææç</h2>
<p>
髿ãããã¯ïŒè¶
売ãã£åã¢ã€ãã«ã§ããïŒ
ãããªåœŒå¥³ã«ã¯ïŒ1ã€èŠæãªãã®ãããïŒ
é«ããšããã ã»ã»ã»ïŒåœŒå¥³ã¯ïŒæ¥µåºŠã®é«æææçãªã®ã§ããïŒ
圌女ã¯ä»åïŒãããã¥ãŒãµãŒã®äžæéã«ããïŒãã©ãšãã£çªçµã§æ¬¡ã®ãããªãã£ã¬ã³ãžã«ææŠããããšã«ãªã£ãŠããŸã£ãïŒ
</p>
<p>
ä»åã®ãã±ã¯ïŒãšããå¿è
屿·ã®ãšããäžå®€ã§è¡ãããïŒ
ãã®éšå±ã®åºã«ã¯ïŒæ£æ¹åœ¢ã®ã¿ã€ã«ãæ·ãè©°ããããŠããïŒããã€ãã®ã¿ã€ã«ãæãèœã¡ãŠç©Žã«ãªã£ãŠããïŒ
ãã®ç©Žããèœã¡ããšæ°ã¡ãŒãã«äžã®æ± ã«ãŸã£ããããŸã§ããïŒ
ãããã®ãã£ã¬ã³ãžå
容ã¯ïŒãã®éšå±ã®æå®ãããå Žæããã¹ã¿ãŒããïŒéšå±ã®äžã«çœ®ãããå
šãŠã®å·»ç©ãååãïŒãŽãŒã«å°ç¹ãŸã§æã£ãŠããããšã§ããïŒ
</p>
<p>
ãããã¯ïŒéšå±ã®äžã以äžã®ã«ãŒã«ã«åŸã£ãŠç§»åã§ããïŒ
</p>
<ul>
<li> ããã¿ã€ã«ããé£ã®ã¿ã€ã«ãžç§»åãããšãïŒäžäžå·Šå³ã®ã¿ã€ã«ã«ã®ã¿ç§»åããããšãã§ããïŒ</li>
<li> 穎ã«è¿ããªãå ŽåïŒé£ã®ã¿ã€ã«ãžç§»åããããã«ã¯ïŒ1ç§ã ãæéããããïŒ</li>
<li> 穎ã«è¿ã¥ããå ŽåïŒãããã¯æãã£ãŠããŸãå³C-1ã®ããã«ç§»åæéããããïŒäŸãã°ïŒå³äžã®ç¢å°ã®ããã«ïŒ[2][2]ãã[1][2]ãžç§»åããããã«ã¯ïŒ3ç§ãããïŒ</li>
<li> è€æ°ã®ç©Žãè¿ãã«ããå ŽåïŒæãè¿ãã«ãã穎ã«å¯ŸããŠæããïŒ</li>
<li> å·»ç©ãåãããã«ãããæéã¯ïŒ0ãšä»®å®ããŠããïŒ</li>
</ul>
<p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day1_C" width="300">
</td>
</tr>
<tr>
<td>
<center>
å³C-1: 穎ã®è¿ãã®ç§»åæé
</center>
</td>
</tr>
</table>
</center>
</p>
<p>
ãããã¯ïŒãªãã¹ãæ©ããã®ãã£ã¬ã³ãžãçµããããããšèããŠããïŒ
ããªãã®ä»äºã¯ïŒãã®ãã£ã¬ã³ãžãçµäºããããã®æçæéãæ±ããããã°ã©ã ãæžãïŒããããå©ããŠãããããšã§ããïŒ
</p>
<h2> Input</h2>
<p>
å¿è
屿·ã®åºæ
å ±ãäžããããïŒ
</p>
<p>
ãŸãïŒ1è¡ç®ã«éšå±ã®å€§ããã衚ãïŒ<i>W</i>ãš<i>H</i>ãã¹ããŒã¹åºåãã§å
¥åããã(2 <= <i>W</i>, <i>H</i> <= 100)ïŒ
ç¶ã<i>H</i>è¡ã®åè¡ã«ã¯ïŒ<i>W</i>æåã®æååãå
¥åãããïŒ
åºæ
å ±ã衚ãæåã«ã¯ïŒä»¥äžã®çš®é¡ãããïŒ
</p>
<ul>
<li> '.' : æ©ããåº</li>
<li> '#' : 穎</li>
<li> 'S' : ããããéå§æã«ç«ã£ãŠããå Žæ</li>
<li> 'G' : ãããã蟿ãã€ãã¹ãå Žæ</li>
<li> 'M' : å·»ç©ã眮ããŠããå Žæ</li>
</ul>
<p>
'S'ãš'G'ãš'M'ã¯ïŒæ©ããåºã§ããïŒ
'S'ãš'G'ã¯ããããïŒéšå±ã®äžã«ã¡ããã©1åååšããïŒå
šãŠã®å·»ç©ãæã£ãŠããªãç¶æ
ã§ãŽãŒã«ãééããŠãæ§ããªãïŒ
'M'ã¯ïŒéšå±ã®äžã«æå°ã§1åïŒæå€§ã§5åååšããïŒ
</p>
<h2> Output</h2>
<p>
å
šãŠã®å·»ç©ãéããŠïŒã¹ã¿ãŒããããŽãŒã«ãžãã©ãçãããã®æçã¿ã€ã ã1è¡ã«åºåããïŒå
¥åããŒã¿ã«ã¯ïŒå¿
ããã®ãããªã«ãŒãããããšä»®å®ããŠããïŒ<br/>
è¡ã®æåŸã«ã¯ïŒæ¹è¡ãåºåããããšïŒ
</p>
<h2> Sample Input 1</h2>
<pre>
3 4
S.M
...
...
M.G
</pre>
<h2> Sample Output 1</h2>
<pre>
9
</pre>
<h2> Sample Input 2</h2>
<pre>
4 4
S..M
....
...#
#..G
</pre>
<h2> Sample Output 2</h2>
<pre>
18
</pre>
<h2> Sample Input 3</h2>
<pre>
11 7
M.........M
...........
...#.S.#...
...........
...#.G.#...
...........
M.........M
</pre>
<h2> Sample Output 3</h2>
<pre>
62
</pre> |
p01860 |
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>-->
<h2>C: è²·ãåºã - Shopping -</h2>
<h3>ç©èª</h3>
<p>磯éã®å§ã§ãããµãŸãšããã¯ïŒãããããããããã§éãã§ãã磯éãšäžå³¶ã®ããã«å€é£ãäœã£ãŠãããããšã«ããŸããïŒããã«ãïŒå·èµåº«ã«ã¯é£æãæ®ãå
ãããç¡ãïŒãµãŸãšããã¯è²·ãåºãã«è¡ãããšã«ããŸããïŒå¹Ÿã€ã飿ãè²·ãããšããŠãããµãŸãšããã§ããïŒå€§å€éœæ°ã§ããããäžåºŠã«äžåã®ã¿ã¬ãžã§äŒèšããŠããŸããŸãïŒãã®ãŸãŸã§ã¯éãã§ãã磯éãšäžå³¶ãè²·ãç©ãçµããåã«åž°ã£ãŠããŠããŸãïŒå€é£ãæºåããããšãåºæ¥ãªããããããŸããïŒããã§ïŒãµãŸãšããã®å人ã§ããããªãã¯ïŒãµãŸãšããã®ããã«ãµãŸãšããã®è²·ãç©ã«ãããæå°ã®æéãæ±ããŠãã ããïŒ</p>
<h3>åé¡</h3>
<p>ãšããã¹ãŒããŒã«<var>N</var>åã®ã¬ãžãããïŒãããã<var>1</var>ã<var>N</var>ãŸã§ã®çªå·ãã€ããŠããïŒ</p>
<p>ãŸãïŒå®¢ã<var>M</var>人å±
ãŠïŒãããã<var>1</var>ã<var>M</var>ãŸã§ã®çªå·ãã€ããŠããïŒ<var>i</var>çªç®ã®å®¢ã¯ïŒæå»<var>a_i</var>ã«<var>c_i</var>çªç®ã®ã¬ãžã«äžŠã³ïŒäŒèšã«<var>b_i</var>ã®æéããããïŒ1人ã®å®¢ã¯äžåºŠã ãäŒèšãããïŒ</p>
<p>ããã§ïŒãã客ã䞊ãã ã¬ãžã«æ¢ã«äººã䞊ãã§ããå ŽåïŒãã®å®¢ã¯æ¢ã«äžŠãã§ãã人å
šå¡ã®äŒèšãçµäºããåŸã«äŒèšãããïŒ<var>i</var>çªç®ã®å®¢ãšïŒ<var>i+1</var>çªç®ã®å®¢ãåãã¬ãžã«äžŠãã§ãããšãããšïŒ<var>i</var>çªç®ã®å®¢ã®äŒèšéå§æå»ã<var>t</var>ã§ãã£ãå ŽåïŒ<var>i</var>çªç®ã®å®¢ã®äŒèšçµäºæå»ã¯<var>t+b_i</var>ïŒ<var>i+1</var>çªç®ã®å®¢ã®äŒèšéå§æå»ã¯<var>t+b_i</var>ïŒãããŠïŒ<var>i+1</var>çªç®ã®å®¢ã®äŒèšçµäºæå»ã¯ïŒ<var>t+b_i+b_{i+1}</var>ãšãªãïŒ</p>
<p>ãµãŸãšããã¯1人ã®å®¢ã§ããïŒãããïŒãµãŸãšããã¯äŸå€çã«<var>K</var>åäŒèšãããïŒãŸãïŒäŒèšã«ãããæéã¯0ïŒããªãã¡ãµãŸãšããã®äŒèšéå§æå»ã<var>t</var>ãšãããšïŒäŒèšçµäºæå»ã¯<var>t</var>ãšãªãïŒæ¬¡ã®å®¢ã®äŒèšéå§æå»ã¯<var>t</var>ãšãªãïŒãã®åŸïŒãµãŸãšãããå床ã¬ãžã«äžŠã¶éïŒäŒèšçµäºæå»<var>t</var>ããåå®ãã«ãããæé<var>D</var>ã ãçµã£ãŠãã䞊ã°ãªããã°ãããªãïŒã€ãŸãïŒå床ã¬ãžã«äžŠã¶ããšãã§ããæå»ã¯<var>t+D</var>ãšãªãïŒ</p>
<p>ãŸãïŒãµãŸãšããã¯æå»<var>S</var>ã«ã¹ãŒããŒã«ãã£ãŠæ¥ãïŒãããŠïŒæå»<var>S</var>ãã<var>D</var>ã ãçµã£ãæå»<var>S+D</var>ã«ïŒåããŠãµãŸãšããã¯ã¬ãžã«äžŠã¶ããšãåºæ¥ãïŒ</p>
<p><var>N</var>ïŒ<var>M</var>ïŒ<var>K</var>ïŒ<var>D</var>ïŒ<var>S</var>ãšïŒ<var>1</var>çªç®ã<var>M</var>çªç®ãŸã§ã®å®¢ã®æ
å ±ãããããäžããããã®ã§ïŒãµãŸãšãããã¹ãŒããŒã«æ¥ãŠããæåŸã®äŒèšãçµãããŸã§ã«ãããæéã®æå°å€ãæ±ããïŒãã®æïŒç°ãªã2人ã®å®¢ãåãæå»ã«åãã¬ãžã«äžŠã¶ããšã¯ç¡ããšãïŒãµãŸãšãããšã»ãã®äººãåæã«ã¬ãžã«äžŠãŒããšããå ŽåïŒãµãŸãšããã¯åžžã«ã»ãã®å®¢ã«é çªãè²ãããšãšããïŒ</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ</p>
<pre>
<var>N</var> <var>M</var> <var>K</var> <var>D</var> <var>S</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
...
<var>a_M</var> <var>b_M</var> <var>c_M</var>
</pre>
<p>1è¡ç®ã«ã¹ãŒããŒã«ããã¬ãžã®æ°<var>N</var>ïŒ<var>1 ≤ N ≤ 10^{15}</var>ïŒïŒèšªããå®¢ã®æ°<var>M</var>(<var>1 ≤ M ≤ 10^5</var>)ïŒãµãŸãšãããã¬ãžãåãåæ°<var>K</var>(<var>1 ≤ K ≤ 10^4</var>)ïŒãµãŸãšããã®åå®ãã«ãããæé<var>D</var>(<var>1 ≤ D ≤ 10^4</var>)ïŒãµãŸãšãããã¹ãŒããŒã«æ¥ãæå»<var>S</var>(<var>1 ≤ S ≤ 10^4</var>)ã空çœåºåãã§äžããããïŒ</p>
<p>ç¶ã<var>M</var>è¡ã«èšªããå®¢ã®æ
å ±ãäžããããïŒ<var>M</var>è¡ã®ãã¡ïŒ<var>i</var>(<var>1 ≤ i ≤ M</var>)è¡ç®ã«ã¯ïŒ<var>i</var>çªç®ã®å®¢ãã¬ãžã«æ¥ãæå»<var>a_i</var>(<var>1 ≤ a_i ≤ 10^4</var>)ïŒäŒèšã«ãããæé<var>b_i</var>(<var>1 ≤ b_i ≤ 10^4</var>)ïŒãã£ãŠæ¥ãã¬ãžã®çªå·<var>c_i</var>(<var>1 ≤ c_i ≤ N</var>)ã空çœåºåãã§äžããããïŒããã§<var>2 ≤ M</var>ã®æïŒå
šãŠã®<var>i</var>(<var>1 ≤ i ≤ M−1</var>)ã«ã€ããŠïŒ<var>a_i ≤ a_{i+1}</var>ãæç«ããïŒ</p>
<p>ãªãïŒå
¥åãéåžžã«å€§ãããªãå ŽåãããããïŒå
¥åã®åãåãã«ã¯é«éãªé¢æ°ãçšããããšãæšå¥šããïŒ</p>
<h3>åºå圢åŒ</h3>
<p>ãµãŸãšãããã¹ãŒããŒã«æ¥ãŠããæåŸã®äŒèšãçµãããŸã§ã«ãããæéã®æå°å€ã1è¡ã§åºåããïŒ</p>
<h3>å
¥åäŸ1</h3>
<pre>
3 9 3 2 3
1 2 3
1 1 2
2 3 1
3 4 2
4 1 3
4 1 1
5 1 1
6 2 3
7 2 2
</pre>
<h3>åºåäŸ1</h3>
<pre>6</pre>
<p>
æé5ã«ã¬ãž3ïŒæé7ã«ã¬ãž1ïŒæé9ã«ã¬ãž2ã«äžŠã¶ïŒ
ãµãŸãšããã®å
¥åºæéãæé3ãªã®ã§åããŠã¬ãžã«äžŠãã§ããæé6ã§3åã®äŒèšãçµäºããïŒ
ãŸãïŒæé9ã«äžŠã¶ã¬ãžã¯ã¬ãž1ïŒãããã¯ã¬ãž3ã§ãæé©è§£ã«ãªã
</p>
<h3>å
¥åäŸ2</h3>
<pre>
3 9 3 1 3
1 2 3
1 1 2
2 3 1
3 4 2
4 1 3
4 1 1
5 1 1
6 2 3
7 2 2
</pre>
<h3>åºåäŸ2</h3>
<pre>5</pre>
<h3>å
¥åäŸ3</h3>
<pre>
1 3 3 2 1
1 1 1
2 2 1
3 2 1
</pre>
<h3>åºåäŸ3</h3>
<pre>9</pre> |
p00772 |
<h3>Rotate and Rewrite</h3>
<p>
Two sequences of integers
A: <i>A</i><sub>1</sub> <i>A</i><sub>2</sub> ... <i>A</i><sub><i>n</i></sub> and
B: <i>B</i><sub>1</sub> <i>B</i><sub>2</sub> ... <i>B</i><sub><i>m</i></sub> and
a set of <em>rewriting rules</em> of the form
"<i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> → <i>y</i>"
are given.
The following transformations on each of the sequences are allowed
an arbitrary number of times in an arbitrary order independently.
</p>
<ul>
<li>
<b>Rotate</b>:
Moving the first element of a sequence to the last.
That is, transforming a sequence <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> ... <i>c</i><sub><i>p</i></sub>
to <i>c</i><sub>2</sub> ... <i>c</i><sub><i>p</i></sub> <i>c</i><sub>1</sub>.
</li>
<li>
<b>Rewrite</b>:
With a rewriting rule
"<i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> → <i>y</i>",
transforming a sequence
<i>c</i><sub>1</sub> <i>c</i><sub>2</sub> ... <i>c</i><sub><i>i</i></sub> <i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> <i>d</i><sub>1</sub> <i>d</i><sub>2</sub> ... <i>d</i><sub><i>j</i></sub>
to
<i>c</i><sub>1</sub> <i>c</i><sub>2</sub> ... <i>c</i><sub><i>i</i></sub> <i>y</i> <i>d</i><sub>1</sub> <i>d</i><sub>2</sub> ... <i>d</i><sub><i>j</i></sub>.
</li>
</ul>
<p>
Your task is to determine whether it is possible to transform the two sequences A and B into the same sequence.
If possible, compute the length of the longest of the sequences after such a transformation.
</p>
<h3>Input</h3>
<p>The input consists of multiple datasets. Each dataset has the following form.</p>
<blockquote>
<i>n m r</i> <br>
<i>A</i><sub>1</sub> <i>A</i><sub>2</sub> ... <i>A</i><sub><i>n</i></sub><br>
<i>B</i><sub>1</sub> <i>B</i><sub>2</sub> ... <i>B</i><sub><i>m</i></sub><br>
<i>R</i><sub>1</sub><br>
...<br>
<i>R</i><sub><i>r</i></sub><br>
</blockquote>
<p>
The first line of a dataset consists of three positive integers <i>n</i>, <i>m</i>, and <i>r,</i>
where
<i>n</i> (<i>n</i> ≤ 25) is the length of the sequence A,
<i>m</i> (<i>m</i> ≤ 25) is the length of the sequence B, and
<i>r</i> (<i>r</i> ≤ 60) is the number of rewriting rules.
The second line contains <i>n</i> integers representing the <i>n</i> elements of A.
The third line contains <i>m</i> integers representing the <i>m</i> elements of B.
Each of the last <i>r</i> lines describes a rewriting rule in the following form.
</p>
<blockquote>
<i>k</i> <i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> <i>y</i><br>
</blockquote>
<p>
The first <i>k</i> is an integer (2 ≤ <i>k</i> ≤ 10), which is the length of the left-hand side of the rule.
It is followed by <i>k</i> integers <i>x</i><sub>1</sub> <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub>,
representing the left-hand side of the rule.
Finally comes an integer <i>y</i>, representing the right-hand side.
</p>
<p>
All of <i>A</i><sub>1</sub>, .., <i>A</i><sub><i>n</i></sub>, <i>B</i><sub>1</sub>, ..., <i>B</i><sub><i>m</i></sub>, <i>x</i><sub>1</sub>, ..., <i>x</i><sub><i>k</i></sub>, and <i>y</i>
are in the range between 1 and 30, inclusive.
</p>
<p>A line "0 0 0" denotes the end of the input.</p>
<h3>Output</h3>
<p>
For each dataset, if it is possible to transform A and B
to the same sequence, print the length of the longest of
the sequences after such a transformation.
Print <code>-1</code> if it is impossible.
</p>
<h3>Sample Input</h3>
<pre>
3 3 3
1 2 3
4 5 6
2 1 2 5
2 6 4 3
2 5 3 1
3 3 2
1 1 1
2 2 1
2 1 1 2
2 2 2 1
7 1 2
1 1 2 1 4 1 2
4
3 1 4 1 4
3 2 4 2 4
16 14 5
2 1 2 2 1 3 2 1 3 2 2 1 1 3 1 2
2 1 3 1 1 2 3 1 2 2 2 2 1 3
2 3 1 3
3 2 2 2 1
3 2 2 1 2
3 1 2 2 2
4 2 1 2 2 2
0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
2
-1
1
9
</pre>
|
p00288 |
<h1>ã¢ã«ãŽãªãºã æ€å®è©Šéš</h1>
<p>
ããªãã¯ã€ãºã¢å°åºã«ãããã¢ã«ãŽãªãºã æ€å®è©Šéšãéå¶ããŠãããéå¶è²»ãæå°ã«ããããšèããŠããŸããéå¶è²»ã¯ãäŒå Žäœ¿çšæããã¹ã®äœ¿çšæãç§»åè£å©éã®ç·åã§ãã
</p>
<p>
ä»å¹Žã¯ <var>N</var> 人ã®åéšè
ç»é²ãããããããã <var>c<sub>i</sub></var> 人ãŸã§åãå
¥ãå¯èœãª <var>M</var> åã®äŒå Žã確ä¿ããŸãããããªãã¯ååéšè
ãå¿
ãã©ããã®äŒå Žã«å²ãåœãŠãªããã°ãªããŸããã1 人以äžå²ãåœãŠãäŒå Žã«ã€ããŠã¯ã人æ°ã«ããããã <var>f<sub>i</sub></var> åã®äŒå Žäœ¿çšæãæ¯æãå¿
èŠããããŸãã
</p>
<p>
ã€ãºã¢å°åºã¯å³ã«ç€ºãããã«æ±è¥¿æ¹åãšååæ¹åã« 1 km ééã§éãèµ°ã£ãŠãããåéšè
ã®å®¶ãšäŒå Žã¯äº€å·®ç¹äžã«ãããšèããŸããååéšè
ã¯å®¶ããäŒå ŽãŸã§éã«æ²¿ã£ãŠåŸæ©ã§ç§»åã§ããŸãããŸãããã®æ€å®è©Šéšã§ã¯ã1 人以äžåéšè
ãåãå
¥ããåäŒå Žã«ã€ã 1 å°ã®ã·ã£ãã«ãã¹ãéè¡ãããã®ã§ãåéšè
ã¯ãã¹ãå©çšããããšãã§ããŸãããã ããèªåãåéšããäŒå Žè¡ãã®ãã¹ã«ããä¹ããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_algorithm" width="600">
</center>
<br>
<p>
åã·ã£ãã«ãã¹ã¯ãäŒå Žããã®æ±è¥¿æ¹åã®è·é¢ãšååæ¹åã®è·é¢ã®åã <var>D</var> 以å
ã®ãã¹ãŠã®äº€å·®ç¹ã«åè»ããŸãïŒå³ã¯ <var>D</var> = 3 ã®å ŽåïŒããã¹ã®äœ¿çšæã¯ <var>D</var> ã«æ¯äŸãã<var>D</var> ã 1 km å¢ãããš <var>B</var> åäžãããŸããã€ãŸããã·ã£ãã«ãã¹ãéè¡ããã«ã¯ 1 äŒå Žããã <var>D × B</var> åã®è²»çšãæ¯æãå¿
èŠããããŸãããªãã<var>D</var> åã³ <var>B</var> ã¯ãã¹ãŠã®äŒå Žã§å
±éã®å€ãçšããŸãã
</p>
<p>
ç§»åè£å©éãšã¯ãååéšè
ã«å¿
èŠãªæäœéã®åŸæ©ã§ã®ç§»åã«å¯ŸããŠéå¶è
ãåéšè
ã«æ¯æãè²»çšã§ã1 km ã«ã€ã㊠1 åãæãå¿
èŠããããŸãã
</p>
<p>
ããªãã¯åéšè
ã®å®¶ãšäŒå Žã®äœçœ®ãäŒå Žã®åãå
¥ãå¯èœäººæ°ãšäœ¿çšæã<var>D</var> ã 1 km å¢ãããšãã«å ç®ãããæé <var>B</var> ã®æ
å ±ãå
¥åããŒã¿ãšããŠæã£ãŠãããååéšè
ãžã®äŒå Žå²ãåœãŠãš <var>D</var> ãæ±ºå®ããããšãã§ããŸãïŒãã ãã<var>D</var> 㯠0 以äžã®æŽæ°)ããã®ãšããéå¶è²»ã®æå°å€ãæ±ããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var> <var>B</var>
<var>ax</var><sub>1</sub> <var>ay</var><sub>1</sub>
<var>ax</var><sub>2</sub> <var>ay</var><sub>2</sub>
:
<var>ax<sub>N</sub></var> <var>ay<sub>N</sub></var>
<var>bx</var><sub>1</sub> <var>by</var><sub>1</sub> <var>c</var><sub>1</sub> <var>f</var><sub>1</sub>
<var>bx</var><sub>2</sub> <var>by</var><sub>2</sub> <var>c</var><sub>2</sub> <var>f</var><sub>2</sub>
:
<var>bx<sub>M</sub></var> <var>by<sub>M</sub></var> <var>c<sub>M</sub></var> <var>f<sub>M</sub></var>
</pre>
<p>
1 è¡ç®ã¯ïŒã€ã®æŽæ°ãããªãã<var>N</var> (1 ≤ <var>N</var> ≤ 100) ã¯åéšè
ã®äººæ°ã<var>M</var> (1 ≤ <var>M</var> ≤ 5) ã¯äŒå Žæ°ã§ããã<var>B</var> (0 ≤ <var>B</var> ≤ 1000) ã¯ã·ã£ãã«ãã¹ãéè¡ããéã«ã<var>D</var>ã 1 km å¢ãããšãã«å ç®ãããæéã§ãããç¶ã <var>N</var> è¡ã«ååéšè
ã®å®¶ã®åº§æšãäžããããã<var>ax<sub>i</sub></var>, <var>ay<sub>i</sub></var> (-1000 ≤ <var>ax<sub>i</sub></var>, <var>ay<sub>i</sub></var> ≤ 1000) ã¯ããããåéšè
<var>i</var> ã®å®¶ã® <var>x</var> 座æšãš <var>y</var> 座æšã瀺ããç¶ã <var>M</var> è¡ã«åäŒå Žã®æ
å ±ãäžããããã<var>bx<sub>i</sub></var>, <var>by<sub>i</sub></var> (-1000 ≤ <var>bx<sub>i</sub></var>, <var>by<sub>i</sub></var> ≤ 1000) ã¯ããããäŒå Ž <var>i</var> ã® <var>x</var> 座æšãš <var>y</var> 座æšã瀺ãã<var>c<sub>i</sub></var>(1 ≤ <var>c<sub>i</sub></var> ≤ 100) ã¯äŒå Ž <var>i</var> ã®åãå
¥ãå¯èœäººæ°ã<var>f<sub>i</sub></var> (0 ≤ <var>f<sub>i</sub></var> ≤ 100000) ã¯äŒå Ž <var>i</var> ã®äœ¿çšæã瀺ãããã ãã<var>c<sub>1</sub></var> ãã<var>c<sub>M</sub></var> ãŸã§ã®åèšã¯ <var>N</var> 以äžã§ããã
</p>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããšèããŠããã
</p>
<ul>
<li> 䜿çšããäŒå Žã決ãããšãã<var>D = i</var> ã«ããããããã®äŒå Žãžã®åéšè
ã®å²ãåœãŠæ¹ã®ãã¡ç§»åè£å©éãæå°ãšãªããšãã®éé¡ã <var>F</var>(<var>i</var>) ãšããããã®ãšãã<var>F</var>(<var>i</var>+2) - <var>F</var>(<var>i</var>+1) ≥ <var>F</var>(<var>i</var>+1)-<var>F</var>(<var>i</var>) ãæç«ããã</li>
</ul>
<p>
ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«è©Šéšã®éå¶è²»ã®æå°å€ã 1 è¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<br>
<h2>å
¥åäŸ</h2>
<pre>
1 1 1
0 0
0 0 1 0
1 1 0
0 0
-3 0 2 3
1 3 1
0 0
-3 0 2 3
0 -5 2 0
4 0 2 1
4 3 1
0 0
0 0
0 0
0 0
-3 0 2 3
0 -5 2 0
4 0 2 1
6 3 1
0 0
0 0
0 0
0 0
0 0
0 0
-3 0 2 3
0 -5 2 0
4 0 2 1
6 3 2
0 0
0 0
0 0
0 0
0 0
0 0
-3 0 2 3
0 -5 2 0
4 0 2 1
10 5 1
0 0
2 0
4 0
8 0
100 0
100 0
100 0
100 0
100 0
100 0
-3 0 1 0
1 0 1 0
3 0 2 0
15 0 1 0
105 0 6 0
10 5 2
0 0
2 0
4 0
8 0
100 0
100 0
100 0
100 0
100 0
100 0
-3 0 1 0
1 0 1 0
3 0 2 0
15 0 1 0
105 0 6 0
0 0 0
</pre>
<h2>åºåäŸ</h2>
<pre>
0
3
5
11
18
28
20
38
</pre> |
p00322 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>è«é£ãç®</H1>
<p>
è¶³ãç®ã¯çç®ã§ç°¡åã«èšç®ã§ããŸããããããããã€ãã®æ°åãæ¬ ããŠããããæ¬ ããŠããæ°åãåããã®ã¯ç°¡åã§ããããïŒ äŸãã°ã以äžã®ãããªçç®ã«ãããŠãïŒããïŒã®æ°åãäžåºŠããçŸããªããšããæ¡ä»¶ããããšãããšïŒ¥ã®ãã¹ã«å
¥ãæ°åã¯ããã€ã«ãªãã§ãããïŒ ãã®å Žåãã«å
¥ãã®ã¯ïŒïŒïŒ¥ã«å
¥ãã®ã¯ïŒãæ£è§£ãšãªããŸãããã®ããã«ãæ°åãããã€ãæ¬ ããŠããæŒç®ãè«é£ãç®ãšåŒã³ãŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_calculation1"><br/>
</center>
<br/>
<p>
ïŒããïŒã®æ°åãäžåºŠããçŸããªããšããæ¡ä»¶ã¯ãã®ãŸãŸã§ã以äžã®ããã«ãã£ãšããããã®æ°åãæ¬ ããŠããããæ£è§£ãšãªãæ°åã®åãæ¹ã¯äžéããããªãã®ã§ããããïŒ å®ã¯ãå¿
ãäžéãã«æ±ºãŸããšã¯éããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_calculation2"><br/>
</center>
<br/>
<p>
äžã®å³ã®ãããªåœ¢ãããè«é£ãç®ã®ãããã®åãã¹ã®æ
å ±ãäžãããããšããæ£ããåãæ¹ãäœéãããããåºåããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var> <var>G</var> <var>H</var> <var>I</var>
</pre>
<p>
ïŒè¡ã«ãè«é£ãç®ã® <var></var> ãã <var></var> ã®ãã¹ã«å
¥ã£ãŠããæ°åã®æ
å ±ãäžããããããã ããäžããããå€ã -1 ã®ãšãã¯ããã®ãã¹ã®æ°åãæ¬ ããŠããããšã衚ãã-1 以å€ã®å€ã¯ã1 ãã 9 ã®æŽæ°ã®ããããã§ããããã®éã«éè€ã¯ãªãã
</p>
<h2>Output</h2>
<p>
æ£ããåãæ¹ãäœéãããããïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
7 6 -1 1 -1 9 2 3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
7 6 5 1 8 9 2 3 4
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
-1 -1 -1 -1 -1 -1 8 4 6
</pre>
<h2>Sample Output 3</h2>
<pre>
12
</pre>
<br/>
<h2>Sample Input 4</h2>
<pre>
-1 -1 -1 -1 -1 -1 -1 -1 -1
</pre>
<h2>Sample Output 4</h2>
<pre>
168
</pre>
|
p01925 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h3>ã¯ã€ãº</h3>
<p>ããªãã¯ã¯ã€ãºçªçµã®ãã£ã¬ã¯ã¿ãŒã§ããïŒ
ã¯ã€ãºçªçµã«ã¯è§£çè
ãšã㊠<i>N</i> 人ãåºæŒäºå®ã§ããïŒãããã 1 ãã <i>N</i> ãŸã§çªå·ä»ããããŠããïŒ
</p>
<p>åé¡ã¯ <i>M+1</i> ååºé¡ããäºå®ã§ããïŒããããã®åé¡ã¯ 1 ãã <i>M+1</i> ãŸã§çªå·ä»ããããŠããïŒ
åé¡ã¯çªå·é ã«åºé¡ããïŒããããæ©æŒãã§æåã«æ£è§£ãã人ã«ã®ã¿åŸç¹ãå
¥ãïŒ<i>i</i> åç®ã®åé¡ã®åŸç¹ã¯æŽæ° <i>S<sub>i</sub></i> ã§ããïŒ
<i>M+1</i> åç®ã®åé¡ãçµããæç¹ã§ç·ååŸç¹ãæå€§ã®äººãåªåããïŒ
ãã ãïŒæå€§åŸç¹ã®äººãè€æ°äººååšããå ŽåïŒåªåè
ã¯ååšããªãïŒ
</p>
<p>çŸåš <i>M</i> åç®ãŸã§é
ç¹ã決ããã®ã§ïŒ<i>M+1</i> åç®ã®é
ç¹ã決ããããšèããŠããïŒ
æåŸã®åé¡ã¯ïŒèª°ã§ãé転ã§ããç¹æ°ã«ããã®ãã¯ã€ãºçªçµã®ãçŽæã§ããïŒ
ãããïŒãã®å Žã§è§£çè
ãã¡ã®ç·ååŸç¹ãèŠãŠåé¡ã®ç¹æ°ã決ãããšïŒè§£çè
ãã¡ã®ããæ°ãåãå¯èœæ§ãããïŒããã§ïŒ ã©ããªç¹æ°ç¶æ³ã§ãå
šå¡ã«é転ã®ãã£ã³ã¹ããããããªç¹æ°èšå®ããããããèããããšã«ããïŒ
</p>
<p>幞ãïŒ1 ãã <i>M</i> åç®ãŸã§ã¯ããããæ£è§£ããå¯èœæ§ãããè§£çè
ãåãã£ãŠããïŒ<i>M+1</i> åç®ã¯å
šå¡ãæ£è§£ããå¯èœæ§ã®ããåé¡ã§ããïŒæ£è§£ããå¯èœæ§ãããè§£çè
ã®äžã§ïŒæ©æŒãã§æ£è§£ãã1åã®ã¿ãåé¡ã®åŸç¹ <i>S<sub>i</sub></i> ãåŸãïŒåé¡ãžã®è§£çã¯æ£è§£ããè§£çè
ãçŸããæç¹ã§ç· ãåããïŒåãè§£çè
ã¯äœåºŠã§ãè§£çãè¡ãããšãã§ããããïŒããåé¡ã®åŸç¹ <i>S<sub>i</sub></i> ã誰ãåŸãããªãå Žåã¯èæ
®ããªããŠããïŒãŸãïŒè€æ°äººã®è§£çè
ãããåé¡ã®åŸç¹ <i>S<sub>i</sub></i> ãéè€ããŠç²åŸãããïŒåŸç¹ãåãåã£ããããããšããªãïŒ
</p>
<p>ååã®é
ç¹ãšæ£è§£å¯èœãªè§£çè
ã®æ
å ±ãåºã«ïŒ èµ·ããããã©ã®ãããªåŸç¹ç¶æ³ã«ãããŠãïŒæåŸã®åé¡ãæ£è§£ããã°å¿
ã誰ã§ãåªåã§ããããã«æåŸã®åé¡ã®ç¹æ° <i>S<sub>M+1</sub></i> ãèšå®ãããïŒ æ¡ä»¶ãæºããæŽæ° <i>S<sub>M+1</sub></i> ãšããŠæå°ã®å€ãæ±ããïŒ
</p>
<h3>Input</h3>
<blockquote></blockquote>
<p>å
¥åããŒã¿ã»ããã¯è€æ°ã®ã±ãŒã¹ããæ§æãããïŒåã±ãŒã¹ã¯æ¬¡ã®ãããªåœ¢åŒã§ããïŒ
</p><blockquote><i>N</i> <i>M</i><br><i>S<sub>1</sub></i> <i>k<sub>1</sub></i> <i>c<sub>1,1</sub></i> ... <i>c<sub>1,k<sub>1</sub></sub></sub></i><br>...<br><i>S<sub>M</sub></i> <i>k<sub>M</sub></i> <i>c<sub>M,1</sub></i> ... <i>c<sub>M,k<sub>M</sub></sub></sub></i></blockquote>
<p>1 è¡ç®ã«ã¯ïŒè§£çè
ã®æ° <i>N</i> ãšæåŸã®åé¡ãé€ããåé¡ã®åæ° <i>M</i> ãäžããããïŒ
ç¶ã <i>M</i> è¡ã«ã¯ïŒåé¡ 1 ã <i>M</i> ã«ã€ããŠã®è§£çã§ããå¯èœæ§ã®ããè§£çè
ã®æ
å ±ãäžããããïŒãã®ãã¡ <i>i</i> è¡ç®ã«ã¯ïŒ<i>i</i> åç®ã®åŸç¹ <i>S<sub>i</sub></i> ãšïŒ<i>i</i> åç®ã«æ£è§£ããå¯èœæ§ãããè§£çè
ã®äººæ° <i>k<sub>i</sub></i> ãäžãããïŒãŸããã®çŽåŸã« <i>k<sub>i</sub></i> åã®æ° <i>c<sub>i,1</sub> ... c<sub>i,k<sub>i</sub></sub></i> ãäžããããïŒ<i>c<sub>i,j</sub></i> (<i>1 ≤ j ≤ k<sub>i</sub></i>) ã¯ãããã ïŒ<i>i</i> åç®ã«æ£è§£ããå¯èœæ§ãããè§£çè
ã®çªå·ã衚ãïŒ
</p>
<p>å
¥åã®çµãã㯠2 ã€ã®ãŒããããªãè¡ã§ç€ºãïŒããŒã¿ã»ããã®åæ°ã¯æå€§ã§ã 30 åãè¶
ããªãïŒ
</p>
<p>å
¥åã§äžããããæ°å€ã¯å
šãп޿°ã§ããïŒä»¥äžã®æ¡ä»¶ãæºããïŒ
</p><ul><li> <i>2 ≤ N ≤ 10,</sub>000</i>
</li><li> <i>1 ≤ M ≤ 1,</sub>000</i>
</li><li> <i>1 ≤ S<sub>i</sub> ≤ 100</i>
</li><li> <i>1 ≤ k<sub>i</sub> ≤ N</i>
</li><li> <i>1 ≤ c<sub>i,1</sub> < ... < c<sub>i,k<sub>i</sub></sub> ≤ N</i>
</li><li> <i>Σk<sub>i</sub> ≤ 100,000</i>
</li></ul>
<p>ãã ãïŒåºåãã¹ã <i>S<sub>M+1</sub></i> ã¯ãã®ç¯å²ãè¶
ããå Žåãããããšã«æ³šæããïŒ
</p>
<h3>Output</h3>
<p>åããŒã¿ã»ããã«ã€ããŠæ¡ä»¶ãæºãããããªæåŸã®åé¡ã®ç¹æ° <i>S<sub>M+1</sub></i> ã®æå°å€ã 1 è¡ã«åºåããïŒ
</p>
<h3>Sample Input</h3>
<pre>3 2
5 2 1 3
8 2 2 3
2 3
8 2 1 2
3 1 1
5 1 2
2 5
100 1 1
100 1 1
100 1 1
100 1 1
100 1 1
3 4
5 1 1
5 1 2
100 2 1 3
100 2 2 3
0 0</pre>
<h3>Output for Sample Input</h3>
<pre>14
11
501
196</pre>
|
p03918 | <span class="lang-en">
<p>Score : <var>2100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a board with an <var>N \times N</var> grid, and <var>N \times N</var> tiles.</p>
<p>Each side of a square that is part of the perimeter of the grid is attached with a socket.
That is, each side of the grid is attached with <var>N</var> sockets, for the total of <var>4 \times N</var> sockets.
These sockets are labeled as follows:</p>
<ul>
<li>The sockets on the top side of the grid: <var>U1, U2, ..., UN</var> from left to right</li>
<li>The sockets on the bottom side of the grid: <var>D1, D2, ..., DN</var> from left to right</li>
<li>The sockets on the left side of the grid: <var>L1, L2, ..., LN</var> from top to bottom</li>
<li>The sockets on the right side of the grid: <var>R1, R2, ..., RN</var> from top to bottom</li>
</ul>
<figure id="socket_id">
<img src="https://atcoder.jp/img/code-festival-2016-final/916ffede6e718801d689f189e658a9bb.png">
<figcaption>Figure: The labels of the sockets</figcaption>
</img></figure>
<p>Snuke can insert a tile from each socket into the square on which the socket is attached.
When the square is already occupied by a tile, the occupying tile will be pushed into the next square, and when the next square is also occupied by another tile, that another occupying tile will be pushed as well, and so forth.
Snuke cannot insert a tile if it would result in a tile pushed out of the grid.
The behavior of tiles when a tile is inserted is demonstrated in detail at Sample Input/Output <var>1</var>.</p>
<p>Snuke is trying to insert the <var>N \times N</var> tiles one by one from the sockets, to reach the state where every square contains a tile.
Here, he must insert exactly <var>U_i</var> tiles from socket <var>Ui</var>, <var>D_i</var> tiles from socket <var>Di</var>, <var>L_i</var> tiles from socket <var>Li</var> and <var>R_i</var> tiles from socket <var>Ri</var>.
Determine whether it is possible to insert the tiles under the restriction. If it is possible, in what order the tiles should be inserted from the sockets?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ300</var></li>
<li><var>U_i,D_i,L_i</var> and <var>R_i</var> are non-negative integers.</li>
<li>The sum of all values <var>U_i,D_i,L_i</var> and <var>R_i</var> is equal to <var>N \times N</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li><var>2000</var> points will be awarded for passing the test set satisfying <var>NâŠ40</var>.</li>
<li>Additional <var>100</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>U_1</var> <var>U_2</var> <var>...</var> <var>U_N</var>
<var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var>
<var>L_1</var> <var>L_2</var> <var>...</var> <var>L_N</var>
<var>R_1</var> <var>R_2</var> <var>...</var> <var>R_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to insert the tiles so that every square will contain a tile, print the labels of the sockets in the order the tiles should be inserted from them, one per line. If it is impossible, print <code>NO</code> instead. If there exists more than one solution, print any of those.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 0 1
1 1 0
3 0 1
0 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>L1
L1
L1
L3
D1
R2
U3
R3
D2
</pre>
<p>Snuke can insert the tiles as shown in the figure below. An arrow indicates where a tile is inserted from, a circle represents a tile, and a number written in a circle indicates how many tiles are inserted before and including the tile.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/252110b5818dc7d972f77d90f99cb8cb.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
2 0
2 0
0 0
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p00637 |
<H1><font color="#000000">Problem A:</font> Citation Format</H1>
<p>
To write a research paper, you should definitely follow the structured format. This format, in many cases, is strictly defined, and students who try to write their papers have a hard time with it.
</p>
<p>
One of such formats is related to citations. If you refer several pages of a material, you should enumerate their page numbers in ascending order. However, enumerating many page numbers waste space, so you should use the following abbreviated notation:
</p>
<p>
When you refer all pages between page <i>a</i> and page <i>b</i> (<i>a</i> < <i>b</i>), you must use the notation "<i>a</i>-<i>b</i>". For example, when you refer pages 1, 2, 3, 4, you must write "1-4" not "1 2 3 4". You must not write, for example, "1-2 3-4", "1-3 4", "1-3 2-4" and so on. When you refer one page and do not refer the previous and the next page of that page, you can write just the number of that page, but you must follow the notation when you refer successive pages (more than or equal to 2). Typically, commas are used to separate page numbers, in this problem we use space to separate the page numbers.
</p>
<p>
You, a kind senior, decided to write a program which generates the abbreviated notation for your junior who struggle with the citation.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets.
</p>
<p>
The first line of the dataset indicates the number of pages <i>n</i>.
</p>
<p>
Next line consists of <i>n</i> integers. These integers are arranged in ascending order and they are differ from each other.
</p>
<p>
Input ends when <i>n</i> = 0.
</p>
<H2>Output</H2>
<p>
For each dataset, output the abbreviated notation in a line. Your program should not print extra space. Especially, be careful about the space at the end of line.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 50</li>
</ul>
<H2>Sample Input</H2>
<pre>
5
1 2 3 5 6
3
7 8 9
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1-3 5-6
7-9
</pre>
|
p00267 |
<H1>å¯ãããå±ã®ã€ããå</H1>
<p>
ãã±ããã¢ã³ã¹ã¿ãŒãšããã²ãŒã ããããŸããã¢ã³ã¹ã¿ãŒãæãŸããè²ãŠãæŠãããã亀æãããããã²ãŒã ã§ãæ¥æ¬äžã§å€§æµè¡ããŠããŸãããã¡ããããããã®ã¯ã©ã¹ã§ããã ãããããããã®ã²ãŒã ã§ã¿ããªãšéã¹ãããã«ã¢ã³ã¹ã¿ãŒãè²ãŠãŠãããã©ãæ²ããããšã«å¯ŸæŠããçžæãããŸããããããã¯ç©æ¥µçã«äººã«è©±ããããã®ãåŸæãªã¿ã€ãã§ã¯ãªãããã§ããã ãã仿¥ããã¯ã©ã¹ã¡ã€ããèªã£ãŠãããã®ãåŸ
ã¡ãªãããç¬ãå¯ããã¢ã³ã¹ã¿ãŒã®ã¬ãã«ãäžããŠããŸãã
</p>
<p>
ãããŠã€ãã«ãåŸ
ã¡æãã§ããç¬éã蚪ããŸãããã¯ã©ã¹ã¡ã€ãã®äžäººã察æŠããªãããšãããã«è©±ãæã¡ãããŠããã®ã§ããã圌女ã¯èªæ
¢æ°ã«ã圌女ã®ã¢ã³ã¹ã¿ãŒãã¡ãèŠããŠãããŸããã
</p>
<p>
äžè¬çãªãã±ããã¢ã³ã¹ã¿ãŒã®å¯ŸæŠã«ãŒã«ã§ã¯ãåãã¬ã€ã€ãŒãããããN å¹ã®ã¢ã³ã¹ã¿ãŒãçšæããäºãã«1 å¹ãã€æŠãããŸããåã¢ã³ã¹ã¿ãŒã«ã¯æé·ã®åºŠåãã瀺ããã¬ãã«ããšããæ°å€ããããã¬ãã«ã倧ããã¢ã³ã¹ã¿ãŒãå¿
ãåã¡ãŸããåã¬ãã«ã®ãšãã¯åŒãåãã§ããäžåºŠæŠã£ãã¢ã³ã¹ã¿ãŒã¯ãããä»¥äžæŠãããããšãã§ããŸãããããããŠäžå¯Ÿäžã®æŠããN åè¡ã£ãããšãéåæ°ã®åå©ãåãããã¬ã€ã€ãŒãåè
ãšãªããŸãã
</p>
<p>
ãããã¯ã圌女ã®ã¢ã³ã¹ã¿ãŒãèŠãç¬éãå«ãªäºæãããŸããã圌女ã®ã¢ã³ã¹ã¿ãŒã¯ã©ããããšãŠã匷ãããªã®ã§ããããããšæŠã£ãŠãããã®ãªãè² ããŠãããŸããŸãããã§ããããŸãã«ãã²ã©ãè² ãæ¹ããããã"ããã€ãšæŠã£ãŠãé¢çœããªããª"ãšãæãããŠãããéãã§ãããªããªãããããªãããªãããã¯ããšãŠãå«ã§ããã ããã<br/>
ãããããããããŸã ã¢ã³ã¹ã¿ãŒãN 广ã£ãŠãªããŠã
</p>
<p>
åãã€ããŸããã
</p>
<p>
N ååè² ã§ã¯åã¡ç®ããªããŠããããããå°ãªãæ°ã®ã¢ã³ã¹ã¿ãŒã§åè² ããç¹å¥ã«ãŒã«ãªããããããããåãŠããããããŸããããã£ãã¯è² ããã£ãŠããŸããªããšèšã£ããã©ããã£ã±ãåãŠããå¬ããã§ãã
</p>
<p>
圌女ã¯ãã®ç¹å¥ã«ãŒã«ãåãå
¥ããŠãããŸãããã€ãŸããäºäººãæã£ãŠããã¢ã³ã¹ã¿ãŒãããäºãã« k å¹éžãã§äžå¹ãã€é çªã«æŠãããéåæ°ã®(ã€ãŸããk/2 ãã倧ããªæ°ã®) åå©ãåããæ¹ãåã¡ãšãªããŸãã
</p>
<p>
ãã£ããããã¯ã圌女ã®ã¢ã³ã¹ã¿ãŒã®ã¬ãã«ãç¥ã£ãŠããŸããŸããã圌女ãã©ã®ã¢ã³ã¹ã¿ãŒãéžã³ãã©ããªé çªã§åºããŠããã®ãã¯ããããŸãããã§ãã察æŠãããã¢ã³ã¹ã¿ãŒã®æ°kãããããããŸã決ããã°ã圌女ãã©ããªéžæãããããšããããåã€ããšãã§ãããããããŸããã
</p>
<p>
çããã«ãé¡ãã§ããã¢ã³ã¹ã¿ãŒã®æ° N ãšãäºäººãæã£ãŠããã¢ã³ã¹ã¿ãŒã®ã¬ãã«ãå
¥åãããšã圌女ãã©ããªéžæãããããšããããåãŠããããªæå°ã®ã¢ã³ã¹ã¿ãŒã®æ° k ãåºåããããã°ã©ã ãäœæããŠäžããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
N
a<sub>1</sub> a<sub>2</sub> ... a<sub>N</sub>
b<sub>1</sub> b<sub>2</sub> ... b<sub>N</sub>
</pre>
<p>
ïŒè¡ç®ã«ã¢ã³ã¹ã¿ãŒã®æ° N (1 ≤ N ≤ 40000) ãäžãããããïŒè¡ç®ã«èªåã®ã¢ã³ã¹ã¿ãŒã®ã¬ãã« a<sub>i</sub> (1 ≤ a<sub>i</sub> ≤ 100000) ãïŒã€ã®ç©ºçœåºåãã§äžãããããïŒè¡ç®ã«ã¯ã©ã¹ã¡ã€ãã®ã¢ã³ã¹ã¿ãŒã®ã¬ãã« b<sub>i</sub> (1 ≤ b<sub>i</sub> ≤ 100000) ãïŒã€ã®ç©ºçœåºåãã§äžããããã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããªãã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãk (1 ≤ k < N) ãååšããã°æå°å€ãïŒè¡ã«åºåããããããk ãååšããªãããk ã N ã«çãããã° NA ãšåºåããã
</p>
<h2>å
¥åäŸ</h2>
<pre>
10
4 9 1 9 5 9 2 3 2 1
8 7 6 5 10 5 5 4 7 6
5
4 3 2 5 1
4 4 4 4 4
4
4 1 3 2
4 3 2 1
0
</pre>
<h2>åºåäŸ</h2>
<pre>
3
1
NA
</pre>
<p>
ïŒã€ç®ã®ããŒã¿ã»ããã§ã¯ããããã¯ïŒå¹ã§ã®å¯ŸæŠãææ¡ããã¬ãã«ã [9, 9, 9] ã®ã¢ã³ã¹ã¿ãŒãéžã¹ã°è¯ããçžæã®ã¬ãã« 10 以å€ã®ã©ã®ã¢ã³ã¹ã¿ãŒã«ãåãŠãã®ã§ãå°ãªããšãïŒåã§ãããïŒå¹ã§ã®å¯ŸæŠã§ã¯ ïŒåïŒæã«ãªãå¯èœæ§ããããããã¯éåæ°ã®åå©ãšã¯èšããªãã®ã§ã2 ã¯çãã«ãªããªãã
</p>
<p>
ïŒã€ç®ã®ããŒã¿ã»ããã§ã¯ããããã¯æåŒ·ã®ã¢ã³ã¹ã¿ãŒãïŒå¹éžã¹ã°è¯ãã
</p>
<p>
ïŒã€ç®ã®ããŒã¿ã»ããã§ã¯ãããããã©ã® k å¹ãéžã³ãã©ã®é çªã§åºãããšããŠãã圌女ãå
šãåãã¢ã³ã¹ã¿ãŒãåãé çªã§åºããŠããŠåŒãåãã«ãªãå¯èœæ§ãããããããã£ãŠãã圌女ãã©ããªéžæãããããšããããåã€ããšãã§ããããšã¯èšãåããªãã
</p>
|
p01026 | <h1>Problem K: Witch Craft Moves</h1>
<h2>Problem</h2>
<p>
äŒæŽ¥éæ³åŠæ ¡ã¯ãéæ³ã䜿ããè
ãéãåŠæ ¡ã§ããã
äŒæŽ¥éæ³åŠæ ¡ã«ã¯1~<var>N</var>ãŸã§ã®çªå·ãã€ããæå®€ãšæå®€å士ãã€ãªãå»äžããããæå®€ãå»äžã¯äœåºŠã§ãéãããšãã§ããããŸããäŒæŽ¥éæ³åŠæ ¡ã«ã¯ä»»æã®æå®€<var>u</var>,<var>v</var>éã0å以äžã®æå®€ãšå»äžãäžåºŠãã€éã£ãŠç§»åããããšãã§ãããããªçµè·¯ããã 1ã€ããã
åæå®€ã«ã¯éæ³é£ãèšçœ®ããŠããããã®éæ¹é£ã«ãã£ãŠãæå®€ã«å
¥ã床ã«å
¥ã£ãè
ã®éåã墿žãããããŠããŸãã®ã ãçåŸã®ç§»åãå©ããããã«ä»¥äžã®äºã€ã®è³ªåã«å¿ããŠã»ããã
</p>
<p>
質å1<br/>
0 A B<br/>
æå®€<var>A</var>ãã<var>B</var>ãžç§»åãããšãã®éåã®æ®éãåºåããŠã»ãããæå®€<var>A</var>ãš<var>B</var>ã§ã®å¢æžãå«ãããŸãããã®è³ªåéå§æç¹ã§ã®éåã®éã¯æ¯å0ã§ããã
</p>
<p>
質å2<br/>
1 A C<br/>
æå®€<var>A</var>ã®éåã®å¢æžéã<var>C</var>ã ãå€åãããã
</p>
<h2>Input</h2>
<pre>
<var>N</var>
<var>cost<sub>1</sub></var>
:
<var>cost<sub>N</sub></var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
:
<var>a<sub>N-1</sub></var> <var>b<sub>N-1</sub></var>
<var>Q</var>
<var>query<sub>1</sub></var>
:
<var>query<sub>Q</sub></var>
</pre>
<p>
å
¥åã®æåã«æå®€ã®æ°<var>N</var>ãäžãããããç¶ã<var>N</var>è¡ã«åæå®€ã«å
¥ã£ããšãã®éåã墿žããéãäžããããã<var>i</var>è¡ç®ã®å€ã<var>i</var>çªã®æå®€ã®æ
å ±ã«å¯Ÿå¿ãããç¶ã<var>N-1</var>è¡ã«å»äžã®æ
å ±ãäžããããã<var>j</var>è¡ç®ã®å»äžã¯<var>a<sub>j</sub></var>çªç®ãš<var>b<sub>j</sub></var>çªç®ã®æå®€ãã€ãªãããšã衚ããæ¬¡ã«è³ªåã®æ°<var>Q</var>ãäžãããããç¶ã<var>Q</var>è¡ã«äžèšã®åœ¢åŒã§è³ªåãäžããããã
</p>
<h2>Output</h2>
<p>å質å1ã«ã€ããŠãçããïŒè¡ã«åºåããã</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var>≤ 2000</li>
<li>1 ≤ <var>A<sub>i<sub></var>≤ 2000</li>
<li>1 ≤ <var>B<sub>i<sub></var>≤ 2000</li>
<li>1 ≤ <var>a<sub>j<sub></var>,<var>b<sub>j</sub> ≤ N</var></li>
<li>1 ≤ <var>Q</var>≤ 1000000</li>
<li>-10000 ≤ <var>C<sub>i<sub></var>≤ 10000</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
7
1
2
3
4
5
6
7
1 2
1 3
3 4
3 5
5 6
5 7
10
0 1 7
0 2 7
1 1 15
0 1 7
0 2 7
0 1 1
1 1 -15
0 1 7
0 2 7
0 1 1
</pre>
<h2>Sample Output 1</h2>
<pre>
16
18
31
33
16
16
18
1
</pre>
|
p01476 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>å顿</h2>
<p>宿°å€æ° $X_1, X_2, ...$ ããããäœããã®åæå€ãå²ãæ¯ãããŠããã
ãããã $Q$ åã®æ
å ±ãé çªã«äžãããããäžããããæ
å ±ã¯ä»¥äžã®2çš®é¡ã®ããããã§ããã</p>
<ul><li>min $\{X_{a_i}, X_{a_i+1}, ..., X_{b_i}\} = y_i$ ã§ããã</li>
<li>倿° $X_{a_i}, X_{a_i+1}, ..., X_{b_i}$ ã« $y_i$ ã代å
¥ããã</li></ul>
<p>ããã $Q$ åã®æ
å ±ãççŸããªãããã«å倿°ã®åæå€ãéžã¹ããã©ããå€å®ããã</p>
<h2>å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã</p>
<pre>$Q$
$t_1$ $a_1$ $b_1$ $y_1$
$t_2$ $a_2$ $b_2$ $y_2$
$...$
$t_Q$ $a_Q$ $b_Q$ $y_Q$</pre>
<ol><li>$t_i=0$ ã®ãšããmin$\{X_{a_i}, X_{a_i+1}, ..., X_{b_i}\} = y_i$ ã§ããããšã瀺ããŠããã</li>
<li>$t_i=1$ ã®ãšãã$X_{a_i}, X_{a_i+1}, ..., X_{b_i}$ ã« $y_i$ ã代å
¥ããããšã瀺ããŠããã</li></ol>
<h2>å¶çŽ</h2>
<ul><li>$1 \leq Q \leq 5 \times 10^4$</li>
<li>$0 \leq t_i \leq 1$</li>
<li>$1 \leq a_i \leq b_i \leq 10^9$</li>
<li>$1 \leq y_i \leq 10^9$</li></ul>
<h2>åºå</h2>
<p>å
šãŠã®æ
å ±ãççŸããªããããªåæå€ãååšããã°"YES"ããããã§ãªããã°"NO"ã1è¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>5
0 1 2 8
0 2 3 9
0 2 2 11
1 2 2 7
0 1 3 7</pre>
<h2>Output for the Sample Input 1</h2>
<pre>YES</pre>
<p>åæå€ãã$\{X_1, X_2, X_3\} = \{8, 11, 9\}$ ãšããããã®ãšãã</p>
<ol><li> min$\{X_1, X_2\} = $min$\{8, 11\} = 8$</li>
<li>min$\{X_2, X_3\} = $min$\{11, 9\} = 9$</li>
<li>min$\{X_2\} = $min$\{11\} = 11$</li>
<li>$X_2 = 7$</li>
<li>min$\{X_1, X_2, X_3\} = $min$\{8, 7, 9\} = 7$</li></ol>
<p>ãšãªãå
šãŠã®æ
å ±ãšççŸããªãã</p>
<h2>Sample Input 2</h2>
<pre>2
1 10 100 333
0 100 1000 555</pre>
<h2>Output for the Sample Input 2</h2>
<pre>NO</pre>
<p>1ã€ç®ã®æ
å ±ã§ $X_{10}$ ãã $X_{100}$ ã®å€ã $333$ ã«ãªã£ãããšãåããã
2ã€ç®ã®æ
å ±ã¯ min$\{X_{100},...,X_{1000}\}=555$ ãšãªãããšã瀺ããŠãããããã㯠$X_{100}=333$ ã§ããããšããççŸãçããã</p>
|
p01319 |
<h1><font color="#000">Problem F:</font> Canal: Water Going Up and Down</h1>
<!--
<h3><U>ééåŒéæ²³: äžäžã«åãæ°Žé¢</U></h3>
-->
<p>ACMåœã«ã¯äžå€®ãæ±è¥¿ã«æµããå·ãããïŒãã®å·ã¯è¥¿ã®é£åœããACMåœãéãæ±ã®é£åœãžãšæµããŠããïŒACMåœå
ã®å
šé·ã¯ <i>K</i> kmã§ããïŒãã®å·ã«ããã€ãã®ééãèšçœ®ãïŒéæ²³ãšããŠå©çšããããšãèšç»ãããŠããïŒ</p>
<p>ééãšã¯ïŒç°ãªã2ã€ã®æ°Žäœéãè¹ãç§»åããããã®ä»çµã¿ã§ããïŒééã¯äžæµåŽãšäžæµåŽã«ããããæ°Žéãæã¡ïŒãããã®éã«é宀ãšåŒã°ããå°ããªæ°Žåãæã€ïŒãã®é宀ã«è¹ãå
¥ããåŸã«æ³šæ°Žãããã¯ææ°Žãè¡ãïŒéå®€ã®æ°Žäœãäžäžãããããšã§è¹ãäžäžãããïŒä»¥äžã«ãã®æš¡åŒå³ã瀺ãïŒ</p>
<center>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_F1" /><br />
å³ F-1: ééã®æš¡åŒå³</p>
</center>
<p>ãã®å·ã®å·å¹
ã¯ããŸãåºããªãããïŒè¥¿ããæ±ãžäžæ¹éè¡ã®éæ²³ãšãªãããšã決ãŸã£ãŠããïŒèšèšã®æ
åœè
ã¯ïŒéæ²³ãå¹çè¯ãéçšããããïŒäºæ³ãããè¹ã®èªè¡ã¹ã±ãžã¥ãŒã«ã«åãããŠééã®èšçœ®å Žæãªã©ãæé©ã«ããããšèããŠããïŒ</p>
<p>ããªãã¯èšèšæ
åœè
ã«éãããŠããããã°ã©ããŒã§ããïŒããªãã®ä»äºã¯ïŒééã®æ
å ±ãšè€æ°ã®è¹ã®èªè¡ã¹ã±ãžã¥ãŒã«ãäžãããããšãïŒå
šãŠã®è¹ãå·ãééãããŸã§ã®æéãã·ãã¥ã¬ãŒã·ã§ã³ã«ããæ±ããããã°ã©ã ãæžãããšã§ããïŒ</p>
<p>åééã¯ä»¥äžã®æ
å ±ã«ãã£ãŠè¡šãããïŒ</p>
<ul>
<li>ACMåœè¥¿ç«¯ããã®è·é¢ <i>X</i> (km)</li>
<li>æ°Žäœã®åãæ¿ãã«å¿
èŠãªæ°Žã®å®¹ç© <i>L</i> (L)</li>
<li>åäœæéãããã®æå€§æ³šæ°Žé <i>F</i> (L/h)</li>
<li>åäœæéãããã®æå€§ææ°Žé <i>D</i> (L/h)</li>
<li>ééã®è¥¿åŽã®æ°Žäœãšæ±åŽã®æ°Žäœã®äžäžé¢ä¿</li>
</ul>
<p>䟿å®äžïŒã·ãã¥ã¬ãŒã·ã§ã³ã«ãããŠïŒå·ã¯ACMåœå€ã«ãããŠãåæ§ã«ç¡éã«ç¶ããŠãããã®ãšããïŒ</p>
<p>ã·ãã¥ã¬ãŒã·ã§ã³ã®éå§æç¹ã«ãããŠïŒå
šãŠã®éå®€ã®æ°Žäœã¯æ±åŽãšè¥¿åŽã®æ°Žäœã®ãã¡ïŒäœãæ¹ã«ããïŒãŸãïŒèªè¡ã¹ã±ãžã¥ãŒã«ã«å«ãŸããè¹ã¯ïŒACMåœã®è¥¿ç«¯ãå
é å°ç¹ãšããŠïŒå
¥åã§äžããããé ã«æ±ãã西ã«åãã£ãŠ1kmããã«äžŠãã§ãããã®ãšããïŒ äŸ¿å®äžïŒå
é ã®è¹ã®åæäœçœ®ã0kmå°ç¹ãšããïŒ</p>
<p>ã·ãã¥ã¬ãŒã·ã§ã³éå§ãšãšãã«è¹ã¯æ±ã«åãã£ãŠèªè¡ãå§ããïŒãã®ãšãïŒããè¹ã®ååŸ1kmæªæºã«ä»ã®è¹ãå
¥ã£ãŠã¯ãªããªãïŒ
åè¹ã«ã¯ããããæå€§è¹é <i>V</i> (km/h)ãèšå®ãããŠããïŒè¹ã¯äžç¬ã§ä»»æã®è¹éã«éãïŒããã«äžç¬ã§éæ¢ããããšããã§ããïŒåºæ¬çã«è¹ã¯æå€§è¹éã§èªè¡ãããïŒå
è¡ããè¹ããåŸç¶ã®è¹ã®ã»ããæå€§è¹éãéãïŒãã€åŸç¶ã®è¹ãå
è¡ããè¹ã®1kmæåã«è¿œãã€ããå Žåã¯ïŒåŸç¶ã®è¹ã¯å
è¡ããè¹ãšåãè¹éã§èªè¡ããïŒè¹åã³ééã®å€§ããã¯ç¡èŠã§ãããã®ãšããïŒ</p>
<p>è¹ã¯ïŒééã®è¥¿åŽã®æ°Žäœãšéå®€ã®æ°Žäœãçãããšãã®ã¿ïŒãã®ééã«å
¥ãããšãã§ããïŒåæ§ã«ïŒééã®æ±åŽã®æ°Žäœãšéå®€ã®æ°Žäœãçãããšãã®ã¿ïŒãã®ééããåºãããšãã§ããïŒåéå®€ã®æ°Žäœã¯ïŒäžã«è¹ãããªãå Žåã¯ïŒãã®ééã®è¥¿åŽã®æ°ŽäœãšäžèŽãããŸã§äžæãŸãã¯äžéããïŒãŸãïŒè¹ãããå Žåã¯ïŒãã®ééã®æ±åŽã®æ°ŽäœãšäžèŽãããŸã§å€äœããïŒééã®äžåºŠ1kmå
ã§è¹ãåæ³ããŠããå Žåã§ãïŒè¹ã¯ééããåºãããšãã§ããïŒãã ãïŒãã®ãšãïŒè¹ã¯å
è¡ããè¹ãçºé²ãããŸã§ééããåºããšããã§åæ³ããªããã°ãªããªãïŒ</p>
<p>è¹ã¯ACMåœã®æ±ç«¯ãééããåŸïŒå¯èœãªéãã®é床ã§ç¡éé ãŸã§èªè¡ããïŒå
šãŠã®è¹ãACMåœã®æ±ç«¯ãééãçµããæç¹ã§ã·ãã¥ã¬ãŒã·ã§ã³ã¯çµäºããïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ</p>
<blockquote><i>N</i> <i>M</i> <i>K</i><br />
<i>X<sub>1</sub></i> <i>L<sub>1</sub></i> <i>F<sub>1</sub></i> <i>D<sub>1</sub></i>
<i>UD<sub>1</sub></i><br />
<i>X<sub>2</sub></i> <i>L<sub>2</sub></i> <i>F<sub>2</sub></i> <i>D<sub>2</sub></i>
<i>UD<sub>2</sub></i><br />
...<br />
<i>X<sub>N</sub></i> <i>L<sub>N</sub></i> <i>F<sub>N</sub></i> <i>D<sub>N</sub></i>
<i>UD<sub>N</sub></i><br />
<i>V<sub>1</sub></i><br />
<i>V<sub>2</sub></i><br />
...<br />
<i>V<sub>M</sub></i><br />
</blockquote>
<p>æåã®1è¡ã¯3ã€ã®æŽæ° <i>N</i>, <i>M</i>, <i>K</i> ãããªãïŒ <i>N</i> (1 ≤ <i>N</i> ≤ 100) ã¯ééã®æ°ïŒ <i>M</i> (1 ≤ <i>M</i> ≤ 100) ã¯è¹ã®æ°ïŒ <i>K</i> (2 ≤ <i>K</i> ≤ 1000) ã¯å·ã®ACMåœå
ã«ãããå
šé·ããããã衚ãïŒ</p>
<p>ç¶ã <i>N</i> è¡ã¯ééã®æ
å ±ã衚ãïŒ åè¡ã¯5ã€ã®æŽæ° <i>X<sub>i</sub></i>, <i>L<sub>i</sub></i>, <i>F<sub>i</sub></i>, <i>D<sub>i</sub></i>, <i>UD<sub>i</sub></i> ãããªãïŒ <i>X<sub>i</sub></i> (1 ≤ <i>X<sub>i</sub></i> ≤ <i>K</i> - 1) ã¯éé <i>i</i> ã®ACMåœè¥¿ç«¯ããã®äœçœ®(km)ïŒ <i>L<sub>i</sub></i> (1 ≤ <i>L<sub>i</sub></i> ≤ 1000) ã¯éé <i>i</i> ã®æ°Žäœã®åãæ¿ãã«å¿
èŠãªæ°Žã®å®¹ç©(L)ïŒ <i>F<sub>i</sub></i> (1 ≤ <i>F<sub>i</sub></i> ≤ 1000) ã¯éé <i>i</i> ã®åäœæéãããã®æå€§æ³šæ°Žé(L/h)ïŒ <i>D<sub>i</sub></i> (1 ≤ <i>D<sub>i</sub></i> ≤ 1000) ã¯éé <i>i</i> ã®åäœæéãããã®æå€§ææ°Žé(L/h)ïŒ <i>UD<sub>i</sub></i> (<i>UD<sub>i</sub></i> ∈ {0, 1})ã¯éé <i>i</i> ã®è¥¿åŽã®æ°Žäœãšæ±åŽã®æ°Žäœã®äžäžé¢ä¿ããããã衚ãïŒ
<i>UD<sub>i</sub></i> ã 0 ã®å ŽåïŒéé <i>i</i> ã¯è¥¿åŽããæ±åŽãæ°Žäœãé«ãããšã衚ãïŒäžæ¹ <i>UD<sub>i</sub></i> ã 1 ã®å ŽåïŒéé <i>i</i> ã¯è¥¿åŽããæ±åŽãæ°Žäœãäœãããšã衚ãïŒ</p>
<p>ç¶ã <i>M</i> è¡ã«ã¯ïŒåè¡ã« <i>i</i> çªç®ã®è¹ã®æå€§è¹é(km/h)ãè¡šãæŽæ° <i>V<sub>i</sub></i> (1 ≤ <i>V<sub>i</sub></i> ≤ 1000) ãäžããããïŒ</p>
<p>éé㯠<i>X<sub>i</sub></i> ã®å€ã®å°ããé ã§äžããããïŒãŸãïŒåäžã®äœçœ®ã«è€æ°ã®ééãèšçœ®ãããããšã¯ãªãïŒ</p>
<p>å
¥åã®çµãã¯ã¹ããŒã¹ã§åºåããã3åã®ãŒããããªãïŒ</p>
<h2>Output</h2>
<p>åããŒã¿ã»ããã«å¯ŸãïŒã·ãã¥ã¬ãŒã·ã§ã³éå§ããçµäºãŸã§ã®æå»ã1è¡ã§åºåããïŒåºåããå€ã¯10<sup>-6</sup>以äžã®èª€å·®ãå«ãã§ããŠãæ§ããªãïŒå€ã¯å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãæ§ããªãïŒ</p>
<h2>Sample Input</h2>
<pre>
1 1 100
50 200 20 40 0
1
2 4 100
7 4 1 4 1
19 5 1 4 0
5
3
7
9
1 2 3
1 1 1 1 0
1
3
1 2 10
5 10 1 1 1
2
3
0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
110
46.6666666667
5
41.6666666667
</pre>
|
p03324 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.<br/>
As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by <var>100</var> <strong>exactly</strong> <var>D</var> times.</p>
<p>Find the <var>N</var>-th smallest integer that would make Ringo happy.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>D</var> is <var>0</var>, <var>1</var> or <var>2</var>.</li>
<li><var>N</var> is an integer between <var>1</var> and <var>100</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>D</var> <var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the <var>N</var>-th smallest integer that can be divided by <var>100</var> exactly <var>D</var> times.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>The integers that can be divided by <var>100</var> exactly <var>0</var> times (that is, not divisible by <var>100</var>) are as follows: <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var>, <var>6</var>, <var>7</var>, ...<br/>
Thus, the <var>5</var>-th smallest integer that would make Ringo happy is <var>5</var>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1100
</pre>
<p>The integers that can be divided by <var>100</var> exactly once are as follows: <var>100</var>, <var>200</var>, <var>300</var>, <var>400</var>, <var>500</var>, <var>600</var>, <var>700</var>, <var>800</var>, <var>900</var>, <var>1 \ 000</var>, <var>1 \ 100</var>, ...<br/>
Thus, the integer we are seeking is <var>1 \ 100</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 85
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>850000
</pre>
<p>The integers that can be divided by <var>100</var> exactly twice are as follows: <var>10 \ 000</var>, <var>20 \ 000</var>, <var>30 \ 000</var>, ...<br/>
Thus, the integer we are seeking is <var>850 \ 000</var>.</p></section>
</div>
</span> |
p02866 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer sequence <var>D_1,...,D_N</var> of <var>N</var> elements. Find the number, modulo <var>998244353</var>, of trees with <var>N</var> vertices numbered <var>1</var> to <var>N</var> that satisfy the following condition:</p>
<ul>
<li>For every integer <var>i</var> from <var>1</var> to <var>N</var>, the distance between Vertex <var>1</var> and Vertex <var>i</var> is <var>D_i</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><ul>
<li>A tree of <var>N</var> vertices is a connected undirected graph with <var>N</var> vertices and <var>N-1</var> edges, and the distance between two vertices are the number of edges in the shortest path between them.</li>
<li>Two trees are considered different if and only if there are two vertices <var>x</var> and <var>y</var> such that there is an edge between <var>x</var> and <var>y</var> in one of those trees and not in the other.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq D_i \leq N-1</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>D_1</var> <var>D_2</var> <var>...</var> <var>D_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>4
0 1 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, a tree with edges <var>(1,2)</var>, <var>(1,3)</var>, and <var>(2,4)</var> satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
0 3 2 1 2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>24
</pre></section>
</div>
</span> |
p01749 |
<p>
ãã¬ãåã¯ïŒ"<var>s</var> ã§<var>t</var> <var>t</var>" ãšããããžã£ã¬ãæãã€ãããïŒå¿ããŠããŸã£ãïŒãã¬ãåã¯ä»¥äžã®ããšãèŠããŠããïŒ
</p>
<ul>
<li> <var>s</var> ã®é·ã㯠<var>N</var> ã§ããïŒ</li>
<li> <var>t</var> ã®é·ã㯠<var>M</var> ã§ããïŒ</li>
<li> <var>t</var> 㯠<var>s</var> ã®éšåæååã§ããïŒ(<var>s</var> ã®é£ç¶ãã <var>M</var> æåã§ <var>t</var> ãšäžèŽããŠããéšåãååšããïŒ)</li>
</ul>
<p>
<var>(s, t)</var> ãšããŠèããããçµã¿åããã®åæ°ã 1,000,000,007 ã§å²ã£ãããŸããæ±ããïŒãã ãïŒæå㯠<var>A</var> çš®é¡ååšãããã®ãšããïŒ
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>N</var> ≤ 200 </li>
<li> 1 ≤ <var>M</var> ≤ 50</li>
<li> <var>M</var> ≤ <var>N</var></li>
<li> 1 ≤ <var>A</var> ≤ 1000</li>
</ul>
<h2>Input</h2>
<Pre>
<var>N</var> <var>M</var> <var>A</var>
</pre>
<h2>Output</h2>
<p>
æ¡ä»¶ãæºããæååã®çµ <var>(s, t)</var> ã®åæ°ã 1,000,000,007 ã§å²ã£ãããŸããåºåããïŒ
</p>
<h2>Sample Input 1</h2>
<pre>
3 2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
14
</pre>
<h2>Sample Input 2</h2>
<pre>
200 50 1000
</pre>
<h2>Sample Output 2</h2>
<pre>
678200960
</pre>
|
p03774 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> students and <var>M</var> checkpoints on the <var>xy</var>-plane.<br/>
The coordinates of the <var>i</var>-th student <var>(1 \leq i \leq N)</var> is <var>(a_i,b_i)</var>, and the coordinates of the checkpoint numbered <var>j</var> <var>(1 \leq j \leq M)</var> is <var>(c_j,d_j)</var>.<br/>
When the teacher gives a signal, each student has to go to the nearest checkpoint measured in <em>Manhattan distance</em>. <br/>
The Manhattan distance between two points <var>(x_1,y_1)</var> and <var>(x_2,y_2)</var> is <var>|x_1-x_2|+|y_1-y_2|</var>.<br/>
Here, <var>|x|</var> denotes the absolute value of <var>x</var>.<br/>
If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.<br/>
Which checkpoint will each student go to?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 50</var></li>
<li><var>-10^8 \leq a_i,b_i,c_j,d_j \leq 10^8</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>M</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_N</var> <var>b_N</var>
<var>c_1</var> <var>d_1</var>
<var>:</var>
<var>c_M</var> <var>d_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.<br/>
The <var>i</var>-th line <var>(1 \leq i \leq N)</var> should contain the index of the checkpoint for the <var>i</var>-th student to go.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
2 0
0 0
-1 0
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1
</pre>
<p>The Manhattan distance between the first student and each checkpoint is:</p>
<ul>
<li>For checkpoint <var>1</var>: <var>|2-(-1)|+|0-0|=3</var></li>
<li>For checkpoint <var>2</var>: <var>|2-1|+|0-0|=1</var></li>
</ul>
<p>The nearest checkpoint is checkpoint <var>2</var>. Thus, the first line in the output should contain <var>2</var>.</p>
<p>The Manhattan distance between the second student and each checkpoint is:</p>
<ul>
<li>For checkpoint <var>1</var>: <var>|0-(-1)|+|0-0|=1</var></li>
<li>For checkpoint <var>2</var>: <var>|0-1|+|0-0|=1</var></li>
</ul>
<p>When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
1
2
</pre>
<p>There can be multiple checkpoints at the same coordinates.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
4
3
2
1
</pre></section>
</div>
</span> |
p02535 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke likes integers that are greater than or equal to <var>A</var>, and less than or equal to <var>B</var>.
Takahashi likes integers that are greater than or equal to <var>C</var>, and less than or equal to <var>D</var>.</p>
<p>Does there exist an integer liked by both people?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A \leq B \leq 10^{18}</var></li>
<li><var>0 \leq C \leq D \leq 10^{18}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Yes</code> or <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 30 20 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>For example, both like <var>25</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 20 30 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre></section>
</div>
</span> |
p00508 |
<H1>åé¡ ïŒ</H1>
<br/>
<p>
ãå¹³é¢äžã® n åã®ç¹ P<sub>1</sub>, ..., P<sub>n</sub> ãäžãããããšãïŒ
è·é¢ãæå°ã®ïŒç¹ãæ±ãããïŒ
</p>
<p>
ãå
¥åãã¡ã€ã«ã®ïŒè¡ç®ã«ã¯æŽæ° n ãæžããŠããïŒ
ïŒè¡ç®ãã n+1 è¡ç®ã®ããããã«ã¯ïŒ
ïŒã€ã®æ£æŽæ° x, y ãïŒã€ã®åè§ç©ºçœæåãåºåããšããŠæžããŠããïŒ
i+1 è¡ç®ã® x, y ã¯ãããã P<sub>i</sub> ã® x 座æšïŒ
P<sub>i</sub> ã® y 座æšã§ããïŒ
ããã n ç¹ã®äžããæãè¿ãïŒç¹ãéžãã ãšãïŒ
ãã®ïŒç¹éã®è·é¢ã®ïŒä¹ãåºåããïŒ
</p>
<!--
<p>
ããã ãïŒ
2âŠnâŠ10<sup>8</sup> ã〠-10000âŠxâŠ10000, -10000âŠyâŠ10000 ãšãïŒ
ïŒã€ã®å
¥åãã¡ã€ã«ã®ãã¡ïŒã€ã§ã¯ nâŠ100 ã§ããïŒ
ãŸãïŒã©ã®å
¥åãã¡ã€ã«ã«ãããŠãïŒå
šãŠã®åº§æšã¯ç°ãªããã®ãšããïŒ
</p>
-->
<p>
ããã ãïŒ
2≤n≤500000 ã〠-10000≤x≤10000, -10000≤y≤10000 ãšãïŒ
ïŒã€ã®å
¥åãã¡ã€ã«ã®ãã¡ïŒã€ã§ã¯ n≤100 ã§ããïŒ
ãŸãïŒã©ã®å
¥åãã¡ã€ã«ã«ãããŠãïŒå
šãŠã®åº§æšã¯ç°ãªããã®ãšããïŒ
</p>
<p>
<!--ãå
¥åãã¡ã€ã«ã®æ¹è¡ã³ãŒã㯠CR+LF ã§ããïŒ
ãŸãïŒ-->
åºåãã¡ã€ã«ã«ãããŠã¯ïŒ
åºåã®æåŸã®è¡ã«ãæ¹è¡ã³ãŒããå
¥ããããšïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
2
0 0
1 1
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
2
</pre>
<br>
<h3>å
¥åäŸïŒ</h3>
<pre>
3
5 5
0 0
-3 -4
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
25
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02165 | <h1>Problem D: Blaster</h1>
<h2>Problem</h2>
<p>
ãªããšãããªãã¯æŽçªã®äžã«éã蟌ããããŠããŸããŸããïŒ<br>
å£ã厩ãããã§ãããã®ã§ããããã1ã€ãããªãåºå£ã«ãã©ãçããŸã§ã«ã¯æ²¢å±±ã®å²©ãéªéãããŠããŸãã<br>
<br>
ããããªããšãããªãã®ããé£ã«ç匟ã®èªå販売æ©ãããããšã«æ°ãã€ããŸããã<br>
ããã«ãæŽçªã«ã¯ããã€ãã®ããã©ã¹ã¿ãŒããèœã¡ãŠããããã§ãã<br>
ãã®2ã€ã®éå
·ã掻çšããã°ãåºå£ãŸã§è±åºã§ãããã§ãã<br>
</p>
<hr style="border:2px dotted #000000;">
<h4>ã¢ã€ãã ã®èª¬æ</h4>
<p>
æŽçªå
ã§äœ¿çšã§ããã¢ã€ãã ãšããŠããç匟ãããã©ã¹ã¿ãŒãã®2çš®é¡ããããŸãã<br>
</p>
<ul>
<li>ç匟ã¯ã䜿çšããããšã§1ãã¹åã®å²©ãç Žå£ã§ããã¢ã€ãã ã§ãã<br>
<li>ãã©ã¹ã¿ãŒã¯ã䜿çšããããšã§èªèº«ã®æ£é¢äžçŽç·ã«ãã岩ãå
šãŠç Žå£ããããšã®ã§ããã¢ã€ãã ã§ãã<br>
</ul>
<p>
察象ãšãªã岩ãç Žå£ãããšã岩ã¯ç ãæ£ããåºããšãªããŸãã<br>
ç匟ããã©ã¹ã¿ãŒã¯äœ¿ãåãã§ãåã¢ã€ãã ããšã«äœ¿çšã§ããåæ°ã¯ãããã1åã®ã¿ã§ãã<br>
ãŸãããã©ã¹ã¿ãŒã䜿çšããããšã§ãä»ã®ãã©ã¹ã¿ãŒãç Žå£ããããšã¯ãããŸããã<br>
</p>
<hr style="border:2px dotted #000000;">
<h4>æŽçªã®ãã£ãŒã«ã</h4>
<p>
å¶ç¶ææã¡ã«ãã£ããããŒã³ãé£ã°ããŠãæŽçªã®æ§åãç¥ãããšãåºæ¥ãŸããã<br>
<br>
æŽçªã®ãã£ãŒã«ããäžããããŸãã<br>
ãã£ãŒã«ãã¯ä»¥äžã®ãããªã¢ã¹ããŒã¢ãŒãã§äžãããŸãã<br>
</p>
<pre>
_###
##B#
B##_
</pre>
<p>
ãã£ãŒã«ãã¯ãäžäžã« $H$ ãã¹ãå·Šå³ã« $W$ ãã¹ã®å¹
ãæã€ $H \times W$ ã®ãã¹ãããªãé·æ¹åœ¢ã§ãã<br>
$i$ è¡ $j$ åç®ã®ãã¹ã $(i,j)$ ãšè¡šããŸãã <br>
<br>
åãã¹ã«ã¯ãåºãå£ããã©ã¹ã¿ãŒã®ããããããããŸãã<br>
ãã©ã¹ã¿ãŒã®ãã¹ã«ã¯ãåºã®äžã«ã¡ããã©1ã€ã®ãã©ã¹ã¿ãŒãèœã¡ãŠããããšã瀺ããŸãã<br>
ãªãããã£ãŒã«ãã®å€åŽã¯ç匟ããã©ã¹ã¿ãŒã§ãç Žå£ã§ããªãå£ã§å²ãŸããŠããŸãã<br>
ãã£ãŒã«ãã®å€åŽã«åºãããšã¯åºæ¥ãŸããã<br>
</p>
<hr style="border:2px dotted #000000;">
<h4>è±åºãŸã§ã®è¡å</h4>
<p>
ããªãã¯ã以äžã®è¡åãä»»æã®åæ°åãããšãåºæ¥ãŸãã<br>
</p>
<ul>
<li>飿¥ãããã¹ã®ãä»»æã®åºãžé²ãã</li>
<li>飿¥ãããã¹ã«ããä»»æã®ãã©ã¹ã¿ãŒãååŸãããååŸåŸããã©ã¹ã¿ãŒãååŸãããã¹ã¯åºãšãªãã</li>
<li>飿¥ãããã¹ã«ãã岩ããç匟ã1ã€æ¶è²»ããŠç Žå£ããã</li>
<li>çŸåšã®ãã¹ãããäžäžå·Šå³å¥œããªæ¹åãåããŠãææããŠãããã©ã¹ã¿ãŒã1ã€äœ¿çšããã</li>
</ul>
<p>
ããã§ããã¹ $(i,j)$ ãš $(k,l)$ ã飿¥ãããšã¯ã $|i-k|+|j-l|=1$ ã§ããããšããããŸãã<br>
ãã©ã¹ã¿ãŒã¯ååã«è»œããããè¡åäžããã€ã§ãååŸããããšãåºæ¥ãŸãã<br>
äœããã¢ã€ãã ã®èª¬æã«èšèŒããŠãããšãããååŸããåæ°åã®åæ°ãããã©ã¹ã¿ãŒã䜿çšããããšã¯åºæ¥ãªãã®ã§ã泚æããŠãã ããã<br>
<br>
æåããã¹ $(1,1)$ ã«ããŸãã<br>
è±åºãšã¯ããã¹ $(H,W)$ ã«å°éããããšãèšããŸãã<br>
</p>
<hr style="border:2px dotted #000000;">
<h4>ããã·ã§ã³</h4>
<p>
ããªãã¯ãç匟ã®èªå販売æ©ãã倧éã®ç匟ãè²·ãã°åé¡ãªãè±åºã§ããããšã«æ°ã¥ããŸããã<br>
幞ããç匟ã®èªå販売æ©ã«ã¯ $10^{100}$ åã®åšåº«ãããè±åºããã«ã¯ååããã§ãã<br>
ããããç匟ã¯éåžžã«é«äŸ¡ã§ããããããŸã沢山買ããããããŸããã<br>
æã«å
¥ããæŽçªã®æ§åãããè±åºããã«ã¯æå°ã§ããã€ã®ç匟ãè²·ãå¿
èŠãããããç¥ããããªããŸããã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$H$ $W$
$c_{1,1}$$\cdots$$c_{1,W}$
$\vdots$
$c_{H,1}$$\cdots$$c_{H,W}$
</pre>
<p>
1è¡ç®ã« $H,W$ ã空çœåºåãã«äžããããŸãã<br>
2è¡ç®ãããç¶ã $H$ è¡ã«ãã£ãŒã«ãã®æ
å ±ãã¢ã¹ããŒã¢ãŒãã§äžããããŸãã<br>
<br>
ãã£ãŒã«ãã®æ
å ±ã¯ãããããã®æåããšã«ä»¥äžã®æå³ãæã¡ãŸãã<br>
</p>
<ul>
<li>$c_{i,j}$ ã '#' ã®ãšãã $(i,j)$ ã«å²©ãããããšã瀺ãã
<li>$c_{i,j}$ ã '_' ã®ãšãã $(i,j)$ ã«åºãããããšã瀺ãã
<li>$c_{i,j}$ ã 'B' ã®ãšãã $(i,j)$ ã«ãã©ã¹ã¿ãŒãã¡ããã©1ã€ããããšã瀺ãã
</ul>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$2 \leq H,W \leq 1000 $</li>
<li>$H,W$ ã¯æŽæ°ã§ãã</li>
<li>$c_{1,1},c_{H,W}$ ã¯ãå¿
ã'_'ã§ããã</li>
</ul>
<h2>Output</h2>
<p>
1è¡ã«è±åºã«å¿
èŠãªçåŒŸã®æ°ãåºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
8 5
_###_
_#_B#
_####
____#
###_#
#####
###_#
####_
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<p>
ãã®å Žåã®è±åºæ¹æ³ã¯ã
</p>
<ul>
<li>ãã¹ $(3,4)$ ã«ãã岩ãç匟ã§ç Žå£ãã</li>
<li>ãã¹ $(2,4)$ ã«ãããã©ã¹ã¿ãŒãååŸãã</li>
<li>ãã¹ $(2,4)$ ã§äžæ¹åã«ãã©ã¹ã¿ãŒã䜿çšãã</li>
<li>è±åºïŒ
</ul>
<p>
ãã®ããã«ãç匟 $1$ ã€ã§è±åºããããšãåºæ¥ãŸãã<br>
ãªãããã©ã¹ã¿ãŒã䜿çšããçŽåŸã®ãã£ãŒã«ãã¯ã以äžã®ããã«ãªã£ãŠããŸãã<br>
</p>
<pre>
_###_
_#__#
_##_#
____#
###_#
###_#
###_#
###__
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5
_____
_____
_____
_____
_____
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<p>
éªéãã岩ããã©ã¹ã¿ãŒããããŸãããç®ã®é¯èŠã ã£ãã®ã§ããããã<br>
ç匟ãäžã€ãè²·ãããšãªããè±åºã§ããå ŽåããããŸãã<br>
</p>
<h2>Sample Input 3</h2>
<pre>
4 5
_####
##B##
_####
_###_
</pre>
<h2>Sample Output 3</h2>
<pre>
2
</pre>
<p>ãã¹ $(2,1),(2,2)$ ã«ãã岩ãç Žå£ããã°ãç匟 $2$ ã€ã ãã§è±åºå¯èœã§ãã</p>
<h2>Sample Input 4</h2>
<pre>
4 5
_#B##
#####
##B##
####_
</pre>
<h2>Sample Output 4</h2>
<pre>
1
</pre> |
p00158 |
<H1>ã³ã©ããã®äºæ³</H1>
<p>
æ£ã®æŽæ° <var>n</var> ã«å¯Ÿãã
</p>
<ul>
<li><var>n</var> ãå¶æ°ã®æã¯ 2 ã§å²ãã</li>
<li><var>n</var> ã奿°ã®æã¯ 3 åãã1 ãè¶³ãã</li>
</ul>
<p>
ãšããæäœãç¹°ãè¿ããšçµæã 1 ã«ãªããŸããä»»æã®æ£ã®æŽæ° <var>n</var> ã«å¯ŸããŠãã®æäœãç¹°ãè¿ããšå¿
ã 1 ã«ãªãã§ããããšããã®ããã³ã©ããã®äºæ³ããšåŒã°ããåé¡ã§ãããã®åé¡ã¯æ¥æ¬ã§ã¯ããè§è°·ã®åé¡ããšããŠãç¥ãããŠããæªè§£æ±ºã®åé¡ã§ããã³ã³ãã¥ãŒã¿ãå©çšããŠéåžžã«å€§ããªæ° 3 × 2<sup>53</sup> = 27,021,597,764,222,976 以äžã«ã€ããŠã¯åäŸããªãããšãç¥ãããŠããŸãããæ°åŠçã«ã¯èšŒæãããŠããŸããã
</p>
<p>
æŽæ° <var>n</var> ãå
¥åãšããçµæã 1 ã«ãªããŸã§ã«ç¹°ãè¿ãããæäœã®åæ°ãåºåããããã°ã©ã ãäœæããŠãã ãããæŽæ° <var>n</var> 㯠1 以äžã§ãã€äžèšã®èšç®ãç¹°ãè¿ãéäžã®å€ã 1000000 以äžãšãªãçšåºŠã®æŽæ°ãšããŸããããšãã°ãå
¥åãšã㊠3 ãåãåã£ãå Žåã¯ãæäœåã¯
</p>
<pre>
3 â 10 â 5 â 16 â 8 â 4 â 2 â 1
</pre>
<p>
ã«ãªãã®ã§ãæäœã®åæ°ïŒäžã®ç¢å°ã®åæ°ïŒã§ãã 7 ãåºåããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ãããšããŠïŒã€ã®æŽæ° <var>n</var> (<var>n</var> ≤ 1000000) ãïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶ããªãã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«æäœã®åæ°ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
3
10
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7
6
</pre>
|
p02470 |
<H1>Euler's Phi Function</H1>
<br/>
<p>
For given integer <var>n</var>, count the totatives of <var>n</var>, that is, the positive integers less than or equal to <var>n</var> that are relatively prime to <var>n</var>.
</p>
<H2>Input</H2>
<pre>
<var>n</var>
</pre>
<p>
An integer <var>n</var> (1 ≤ <var>n</var> ≤ 1000000000).
</p>
<H2>Output</H2>
<p>
The number of totatives in a line.
</p>
<H2>Sample Input 1</H2>
<pre>
6
</pre>
<H2>Sample Output 1</H2>
<pre>
2
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
1000000
</pre>
<H2>Sample Output 2</H2>
<pre>
400000
</pre>
<br/> |
p02020 | <h2>F: è¶äŒ (Tea Party)</h2>
<p>ããããã¯ãäŒç€Ÿã§ãè¶äŒãéãããšã«ããã</p>
<p>ãåºã«ã¯ $N$ ã»ããã®ãã³ã売ãããŠããŠããããã $A_1, A_2, A_3, \dots, A_N$ æå
¥ã£ãŠããã</p>
<p>ããããã¯äºã€ã®ãã³ã 1 çµã«ããŠããµã³ããŠã£ãããäœãããšèããã</p>
<p>ããããã¯å åž³é¢ãªã®ã§ãè²·ã£ããã³ãäžæãäœããªãããã«ãããã</p>
<p>æå€§ã§ããã€ã®ãµã³ããŠã£ãããäœãããèšç®ããã</p>
<h3>å
¥å</h3>
<p>1 è¡ç®ã«ã¯ãæŽæ° $N$ ãäžããããã</p>
<p>2 è¡ç®ã«ã¯ã$N$ åã®æŽæ° $A_1, A_2, A_3, \dots, A_N$ ã空çœåºåãã§äžããããã</p>
<h3>åºå</h3>
<p>äœãããµã³ããŠã£ããã®æå€§ã®åæ°ãåºåããããã ããæåŸã«æ¹è¡ãå
¥ããããšã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$N$ 㯠$1$ ä»¥äž $100$ 以äžã®æŽæ°</li>
<li>$A_1, A_2, A_3, \dots, A_N$ 㯠$1$ ä»¥äž $100$ 以äžã®æŽæ°</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
5
2 3 5 6 7
</pre>
<h3>åºåäŸ1</h3>
<pre>
10
</pre>
<p>1, 3, 4, 5 çªç®ã®ã»ãããè²·ããšããã³ã $20$ ææã«å
¥ããŸãã</p>
<p>ãã¹ãŠã®ã»ãããè²·ã£ãŠããŸããšãã³ã $23$ æã«ãªã£ãŠãäœã£ãŠããŸããŸãã</p>
<h3>å
¥åäŸ2</h3>
<pre>
4
3 5 6 8
</pre>
<h3>åºåäŸ2</h3>
<pre>
11
</pre>
|
p02889 | <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> towns numbered <var>1</var> to <var>N</var> and <var>M</var> roads. The <var>i</var>-th road connects Town <var>A_i</var> and Town <var>B_i</var> bidirectionally and has a length of <var>C_i</var>.</p>
<p>Takahashi will travel between these towns by car, passing through these roads. The fuel tank of his car can contain at most <var>L</var> liters of fuel, and one liter of fuel is consumed for each unit distance traveled. When visiting a town while traveling, he can full the tank (or choose not to do so). Travel that results in the tank becoming empty halfway on the road cannot be done.</p>
<p>Process the following <var>Q</var> queries:</p>
<ul>
<li>The tank is now full. Find the minimum number of times he needs to full his tank while traveling from Town <var>s_i</var> to Town <var>t_i</var>. If Town <var>t_i</var> is unreachable, print <var>-1</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 \leq N \leq 300</var></li>
<li><var>0 \leq M \leq \frac{N(N-1)}{2}</var></li>
<li><var>1 \leq L \leq 10^9</var></li>
<li><var>1 \leq A_i, B_i \leq N</var></li>
<li><var>A_i \neq B_i</var></li>
<li><var>\left(A_i, B_i\right) \neq \left(A_j, B_j\right)</var> (if <var>i \neq j</var>)</li>
<li><var>\left(A_i, B_i\right) \neq \left(B_j, A_j\right)</var> (if <var>i \neq j</var>)</li>
<li><var>1 \leq C_i \leq 10^9</var></li>
<li><var>1 \leq Q \leq N\left(N-1\right)</var></li>
<li><var>1 \leq s_i, t_i \leq N</var></li>
<li><var>s_i \neq t_i</var></li>
<li><var>\left(s_i, t_i\right) \neq \left(s_j, t_j\right)</var> (if <var>i \neq j</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>L</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>:</var>
<var>A_M</var> <var>B_M</var> <var>C_M</var>
<var>Q</var>
<var>s_1</var> <var>t_1</var>
<var>:</var>
<var>s_Q</var> <var>t_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines.</p>
<p>The <var>i</var>-th line should contain the minimum number of times the tank needs to be fulled while traveling from Town <var>s_i</var> to Town <var>t_i</var>. If Town <var>t_i</var> is unreachable, the line should contain <var>-1</var> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2 5
1 2 3
2 3 3
2
3 2
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
1
</pre>
<p>To travel from Town <var>3</var> to Town <var>2</var>, we can use the second road to reach Town <var>2</var> without fueling the tank on the way.</p>
<p>To travel from Town <var>1</var> to Town <var>3</var>, we can first use the first road to get to Town <var>2</var>, full the tank, and use the second road to reach Town <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 0 1
1
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>There may be no road at all.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 4 4
1 2 2
2 3 2
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 3
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
0
1
2
0
0
1
2
0
0
0
1
1
1
0
0
2
2
1
0
</pre></section>
</div>
</span> |
p03261 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is practicing <em>shiritori</em> alone again today.</p>
<p>Shiritori is a game as follows:</p>
<ul>
<li>In the first turn, a player announces any one word.</li>
<li>In the subsequent turns, a player announces a word that satisfies the following conditions:<ul>
<li>That word is not announced before.</li>
<li>The first character of that word is the same as the last character of the last word announced.</li>
</ul>
</li>
</ul>
<p>In this game, he is practicing to announce as many words as possible in ten seconds.</p>
<p>You are given the number of words Takahashi announced, <var>N</var>, and the <var>i</var>-th word he announced, <var>W_i</var>, for each <var>i</var>. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an integer satisfying <var>2 \leq N \leq 100</var>.</li>
<li><var>W_i</var> is a string of length between <var>1</var> and <var>10</var> (inclusive) consisting 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>N</var>
<var>W_1</var>
<var>W_2</var>
<var>:</var>
<var>W_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If every word announced by Takahashi satisfied the conditions, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
hoge
english
hoge
enigma
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>No
</pre>
<p>As <code>hoge</code> is announced multiple times, the rules of shiritori was not observed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
abc
arc
agc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> |
p02923 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares arranged in a row from left to right.</p>
<p>The height of the <var>i</var>-th square from the left is <var>H_i</var>.</p>
<p>You will land on a square of your choice, then repeat moving to the adjacent square <strong>on the right</strong> as long as the height of the next square is not greater than that of the current square.</p>
<p>Find the maximum number of times you can move.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq H_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of times you can move.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
10 4 8 7 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>By landing on the third square from the left, you can move to the right twice.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
4 4 5 6 6 5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>By landing on the fourth square from the left, you can move to the right three times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03631 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a three-digit positive integer <var>N</var>.<br/>
Determine whether <var>N</var> is a <em>palindromic number</em>.<br/>
Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>100â€Nâ€999</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>N</var> is a palindromic number, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>575
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><var>N=575</var> is also <var>575</var> when read backward, so it is a palindromic number. You should print <code>Yes</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>123
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>N=123</var> becomes <var>321</var> when read backward, so it is not a palindromic number. You should print <code>No</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>812
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p00334 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>圢ç¶ããŒã¿åŠç </H1>
<p>
ã³ã³ãã¥ãŒã¿ã°ã©ãã£ã¯ã¹ã§ã¯ãäžæ¬¡å
ã®åœ¢ç¶ã衚çŸããæ¹æ³ãšããŠãããªãŽã³ã¢ãã«ã䜿ãããŸããããªãŽã³ã¢ãã«ãšã¯ãé ç¹åº§æšãšããããã®é ç¹ã®ã€ãªãæ¹ãäžããŠé¢ãäœãã¢ãã«ã§ãã
</p>
<p>
äžè¬ã®ããªãŽã³ã¢ãã«ã§ã¯ãä»»æã®å€è§åœ¢ãæ±ããŸãããä»åã¯äžè§åœ¢ãããªãããªãŽã³ã¢ãã«ãèããããšã«ããŸããä»»æã®ããªãŽã³ã¢ãã«ã¯äžè§åœ¢ã衚ã颿
å ±ã®éãŸããšããŠè¡šãããšãã§ããŸãã
</p>
<p>
äžã€ã®é¢æ
å ±ã¯ãïŒã€ã®é ç¹ã䞊ã¹ãŠè¡šããŸãããã ããäžŠã³æ¹ãç°ãªãã ãã§åãïŒç¹ãããªãå Žåã¯ãåã颿
å ±ã衚ãããšã«ããŸããäŸãã°ãäžå³ã®åé¢äœã§ãé ç¹ïŒ,ïŒ,ïŒãç¹ãã§ã§ããé¢ã¯ãé ç¹ïŒ,ïŒ,ïŒããé ç¹ïŒ,ïŒ,ïŒãªã©ã®ããã«è¡šãããšãã§ããŸãããã®ããã«ãåã颿
å ±ãè€æ°ãããšç¡é§ã«ãªãã®ã§ãïŒã€ã«ãŸãšããŠããŸã£ãæ¹ãè¯ãã§ãããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_shape_data" width="280">
</center>
<br/>
<p>
颿
å ±ãäžãããããšããéè€ããé¢ãç¡ããããã«æ¶ããªããã°ãªããªã颿
å ±ã®åæ°ãæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>p<sub>11</sub></var> <var>p<sub>12</sub></var> <var>p<sub>13</sub></var>
<var>p<sub>21</sub></var> <var>p<sub>22</sub></var> <var>p<sub>23</sub></var>
:
<var>p<sub>N1</sub></var> <var>p<sub>N2</sub></var> <var>p<sub>N3</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ãããªãŽã³ã¢ãã«ã®é¢æ
å ±ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> çªç®ã®é¢ãäœãããã«äœ¿ãé ç¹ã®çªå· <var>p<sub>ij</sub></var> (1 ≤ <var>p<sub>ij</sub></var> ≤ 1000) ãäžããããããã ããäžã€ã®é¢ã«ã€ããŠãåãé ç¹ãïŒåºŠä»¥äžäœ¿ãããšã¯ãªãïŒ<var>p<sub>i1</sub></var> ≠ <var>p<sub>i2</sub></var> ã〠<var>p<sub>i2</sub></var> ≠ <var>p<sub>i3</sub></var> ã〠<var>p<sub>i1</sub></var> ≠ <var>p<sub>i3</sub></var> ã§ããïŒã
</p>
<h2>Output</h2>
<p>
éè€ããé¢ãç¡ããããã«æ¶ããªããã°ãªããªã颿
å ±ã®åæ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4
1 3 2
1 2 4
1 4 3
2 3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<p>
å
¥åºåäŸïŒã§ã¯ãïŒã€ç®ãšïŒã€ç®ãšïŒã€ç®ã®é¢ã¯é ç¹1, 3, 2ã䜿ã£ãŠäžè§åœ¢ãäœã£ãŠããŠãç¹ã®é çªãç°ãªãã ããªã®ã§éè€ããŠãããã€ãŸããéè€ããé¢ã®ãã¡ïŒã€ã®é¢ãæ¶ãã°éè€ããé¢ã¯ç¡ããªãã
</p> |
p02309 |
<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>Cross Points of Circles</H1>
<p>
For given two circles $c1$ and $c2$, print the coordinates of the cross points of them.
</p>
<H2>Input</H2>
<p>
The input is given in the following format.
</p>
<p>
$c1x\; c1y\; c1r$ <br>
$c2x\; c2y\; c2r$ <br>
</p>
<p>
$c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle.
$c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle.
All input values are given in integers.
</p>
<H2>Output</H2>
<p>
Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules.
</p>
<ul>
<li>If there is one cross point, print two coordinates with the same values.</li>
<li>Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first.</li>
</ul>
<p>
The output values should be in a decimal fraction with an error less than 0.000001.
</p>
<H2>Constraints</H2>
<ul>
<li>The given circle have at least one cross point and have different center coordinates.</li>
<li>$-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$</li>
<li>$1 \leq c1r, c2r \leq 10,000$</li>
</ul>
<H2>Sample Input and Output</H2>
<br>
<H2>Sample Input 1</H2>
<pre>
0 0 2
2 0 2
</pre>
<H2>Sample Output 1</H2>
<pre>
1.00000000 -1.73205080 1.00000000 1.73205080
</pre>
<br>
<H2>Sample Input 2</H2>
<pre>
0 0 2
0 3 1
</pre>
<H2>Sample Output 2</H2>
<pre>
0.00000000 2.00000000 0.00000000 2.00000000
</pre> |
p00764 |
<h1>Chain-Confined Path</h1>
<!-- end en only -->
<!-- begin en only -->
<p>
There is a chain consisting of multiple circles on a plane.
The first (last) circle of the chain only intersects with the next (previous) circle,
and each intermediate circle intersects only with the two neighboring circles.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Your task is to find the shortest path that satisfies the following conditions.
<ul>
<li>The path connects the centers of the first circle and the last circle.</li>
<li>The path is confined in the chain, that is, all the points on the path are located within or on at least one of the circles.</li>
</ul>
Figure E-1 shows an example of such a chain and the corresponding shortest path.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1183_1"><br><br>
<!-- begin en only -->
Figure E-1: An example chain and the corresponding shortest path<br>
<!-- end en only -->
</center>
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of multiple datasets.
Each dataset represents the shape of a chain in the following format.
</p>
<!-- end en only -->
<blockquote>
<i>n</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>r</i><sub>1</sub> <br>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>r</i><sub>2</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>
</blockquote>
<!-- begin en only -->
<p>
The first line of a dataset contains an integer <i>n</i> (3 ≤ <i>n</i> ≤ 100)
representing the number of the circles.
Each of the following <i>n</i> lines contains three integers separated by a single space.
(<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>)
and <i>r</i><sub><i>i</i></sub> represent
the center position and the radius of the <i>i</i>-th circle <i>C</i><sub><i>i</i></sub>.
You can assume that 0 ≤ <i>x</i><sub><i>i</i></sub> ≤ 1000,
0 ≤ <i>y</i><sub><i>i</i></sub> ≤ 1000, and
1 ≤ <i>r</i><sub><i>i</i></sub> ≤ 25.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
You can assume that <i>C</i><sub><i>i</i></sub> and
<i>C</i><sub><i>i</i>+1</sub> (1 ≤ <i>i</i> ≤ <i>n</i>−1) intersect at two separate points.
When <i>j</i> ≥ <i>i</i>+2, <i>C</i><sub><i>i</i></sub> and <i>C</i><sub><i>j</i></sub> are apart and either of them does not contain the other.
In addition, you can assume that any circle does not contain the center of any other circle.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Figure E-1 corresponds to the first dataset of Sample Input below.
Figure E-2 shows the shortest paths for the subsequent datasets of Sample Input.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1183_2"><br><br>
<!-- begin en only -->
Figure E-2: Example chains and the corresponding shortest paths<br>
<!-- end en only -->
</center>
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single line containing the length of the shortest chain-confined path between the centers of the first circle and the last circle.
The value should not have an error greater than 0.001.
No extra characters should appear in the output.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
10
802 0 10
814 0 4
820 1 4
826 1 4
832 3 5
838 5 5
845 7 3
849 10 3
853 14 4
857 18 3
3
0 0 5
8 0 5
8 8 5
3
0 0 5
7 3 6
16 0 5
9
0 3 5
8 0 8
19 2 8
23 14 6
23 21 6
23 28 6
19 40 8
8 42 8
0 39 5
11
0 0 5
8 0 5
18 8 10
8 16 5
0 16 5
0 24 5
3 32 5
10 32 5
17 28 8
27 25 3
30 18 5
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
58.953437
11.414214
16.0
61.874812
63.195179
</pre>
|
p02759 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi wants to print a document with <var>N</var> pages double-sided, where two pages of data can be printed on one sheet of paper.</p>
<p>At least how many sheets of paper does he need?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an integer.</li>
<li><var>1 \leq N \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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>By printing the <var>1</var>-st, <var>2</var>-nd pages on the <var>1</var>-st sheet, <var>3</var>-rd and <var>4</var>-th pages on the <var>2</var>-nd sheet, and <var>5</var>-th page on the <var>3</var>-rd sheet, we can print all the data on <var>3</var> sheets of paper.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>50
</pre></section>
</div>
</span> |
p01876 |
<h2>E: Arai's - Arai's -</h2>
<h3>åé¡</h3>
<p>ã¹ã¯ãŒã«ã¢ã€ãã«æä»£ãããåœæ°ç人æ°ãèªã£ãŠãã女æ§ã¢ã€ãã«ã°ã«ãŒãArai'sãä»ã§ã¯ãããããã®ããããããããæå±ããå€§èŠæš¡ãªã°ã«ãŒããšããŠãäžçã¬ãã«ã§æŽ»èºããŠããããããŠä»æ¥ãæ°ããªããããžã§ã¯ãã®å§åãæ±ºå®ããã圌女ãã¡ã¯ãå°ããªãŠããããããã€ãçµæããããšã§ããããªã売äžã®åäžã詊ã¿ãããšã«ãªã£ãã®ã§ããã</p>
<p>Arai'sã«ã¯ãèäºãããã<var>A</var>人ïŒãæ°äºãããã<var>B</var>人åšç±ããŠãããåèšã§<var>A+B</var>人ã®ããããããããããªããæ°ãŠãããã¯ããèäºãããäžäººãšãæ°äºãããäžäººã®ãã¢ã§æ§æãããïŒããã§ãåãããããããããè€æ°ã®ãŠãããã«æå±ããŠãã¯ãããªããïŒãã ãããããèäºããããäžéšã®ãæ°äºãããã®ããšãè¯ãæã£ãŠããªãããã«ãåæ§ã«ãããæ°äºããããäžéšã®ãèäºãããã®ããšãè¯ãæã£ãŠããªããããããããããã¡ã¯ãŠããããçµãéã«ãè¯ãæã£ãŠããªããããããããããã¢ãšããŠèªããŠããããäžæ¹ã§ãèªããŠãããªããã°ãŠããããçµãããšã¯ã§ããªãã</p>
<p>Arai'sã®ãããŒãžã£ãŒã§ããããªãã¯ããªãã¹ãããããã®ãŠããããäœããããšèããŠããããã¡ã³ããŒã®äº€åé¢ä¿ãããã®éçãæããŠãããããã§ããªãã¯ãããããããããã¡ãšåå¥ã«é¢è«ãããŠããããçµãŸããããããããããã«ã€ããŠã®ãè¯ãåãèãããããšãèãããé¢è«ããããããããããã¯ãåã«èããããããããããèŠçŽãããŠãããã®ãã¢ãšããŠèªããããã«ãªãã</p>
<p>ããããããªãã¯ããã»ã©æéããšãããšãã§ããªããããæå€§<var>K</var>åãŸã§ããåãèãããããšãã§ããªããããªãã¯éãããæéã®äžã§ãçµæã§ãããŠãããã®æ°ãæå€§åããããšè©Šã¿ããããªããçµæã§ãããŠãããã®æ°ã®æå€§å€ãæ±ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>A</var> <var>B</var> <var>K</var>
<var>a_1</var>
...
<var>a_A</var>
<var>b_1</var>
...
<var>b_B</var>
</pre>
<p>1è¡ç®ã«ã¯ããèäºãããã®äººæ°<var>A</var>ãšãæ°äºãããã®äººæ°<var>B</var> (<var>1 \≤ A, B \≤ 200</var>ã§ãã<var>A</var>, <var>B</var>ã¯æŽæ°)ãåãèãããããšãã§ãã人æ°<var>K</var> (<var>0 \≤ K \≤ 200</var>ã§ãã<var>K</var>ã¯æŽæ°)ã空çœåºåãã§äžããããã</p>
<p>ç¶ã<var>A</var>è¡ã«ã¯ãããããé·ã<var>B</var>ã®<var>0</var>ãš<var>1</var>ã®ã¿ãããªãæååãäžããããããã®ãã¡<var>i</var>è¡ç®ã®æåå<var>a_i</var>ã®<var>j</var>æåç®ã<var>1</var>ã§ãããšãã<var>i</var>çªç®ã®ãèäºãããã¯<var>j</var>çªç®ã®ãæ°äºããããè¯ãæã£ãŠããªãã</p>
<p>ç¶ã<var>B</var>è¡ã«ã¯ãããããé·ã<var>A</var>ã®<var>0</var>ãš<var>1</var>ã®ã¿ãããªãæååãäžããããããã®ãã¡<var>i</var>è¡ç®ã®æåå<var>b_i</var>ã®<var>j</var>æåç®ã<var>1</var>ã§ãããšãã<var>i</var>çªç®ã®ãæ°äºãããã¯<var>j</var>çªç®ã®ãèäºããããè¯ãæã£ãŠããªãã</p>
<h3>åºå圢åŒ</h3>
<p>ããªããçµæã§ãããŠãããæ°ã®æå€§å€ã1è¡ã«åºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>
3 3 4
111
111
111
111
111
111
</pre>
<h3>åºåäŸ1</h3>
<pre>2</pre>
<h3>å
¥åäŸ2</h3>
<pre>
3 3 2
101
100
010
001
011
111
</pre>
<h3>åºåäŸ2</h3>
<pre>3</pre>
<h3>å
¥åäŸ3</h3>
<pre>
5 6 3
101101
110110
010111
110110
110111
01010
10101
11101
01011
11011
11011
</pre>
<h3>åºåäŸ3</h3>
<pre>4</pre> |
p03518 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a sequence <var>p</var>, which is a permutation of <var>(0,1,2, ...,N-1)</var>.
The <var>i</var>-th element (<var>0</var>-indexed) in <var>p</var> is <var>p_i</var>.</p>
<p>He can perform <var>N-1</var> kinds of operations labeled <var>1,2,...,N-1</var> any number of times in any order.
When the operation labeled <var>k</var> is executed, the procedure represented by the following code will be performed:</p>
<pre>for(int i=k;i<N;i++)
swap(p[i],p[i-k]);
</pre>
<p>He would like to sort <var>p</var> in increasing order using between <var>0</var> and <var>10^{5}</var> operations (inclusive).
Show one such sequence of operations.
It can be proved that there always exists such a sequence of operations under the constraints in this problem.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200</var></li>
<li><var>0 \leq p_i \leq N-1</var></li>
<li><var>p</var> is a permutation of <var>(0,1,2,...,N-1)</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>300</var> points, <var>N \leq 7</var>.</li>
<li>In the test set worth another <var>400</var> points, <var>N \leq 30</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_0</var> <var>p_1</var> <var>...</var> <var>p_{N-1}</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 following <var>m</var> lines, print the label of the <var>i</var>-th executed operation.
The solution will be accepted if <var>m</var> is at most <var>10^5</var> and <var>p</var> is in increasing order after the execution of the <var>m</var> operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
4 2 0 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
2
3
1
2
</pre>
<ul>
<li>Each operation changes <var>p</var> as shown below:</li>
</ul>
<div style="text-align: center;">
<img alt="9f3b51eb1fe742848f407bdeb7b772e1.png" src="https://atcoder.jp/img/asaporo2/9f3b51eb1fe742848f407bdeb7b772e1.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
1 0 4 3 5 6 2 8 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
3
6
1
3
5
2
4
7
8
6
3
</pre></section>
</div>
</span> |
p01525 |
<h1>F - Acceleration of Network</h1>
<p>
ã€ã³ã¿ãŒããããšèšãåºå€§ãªæµ·ã¯å°ããã€é»ãå¡ãã€ã¶ãããŠãã£ãã<br>
ãããã®åä¹±ãDDOSæ»æã®åµããŠã£ã«ã¹ã®èå»¶ã<br>
äœåºŠãäœåºŠãç¹°ãè¿ãããã¯ã©ãã«ãŒãšã®æŠäºã§ã人ãã€ã³ã¿ãŒããããããããã«ãªã£ãã<br>
<br>
äººã®æã§ã¯ãã€ã³ã¿ãŒãããã¯ã©ãã«ããªããªãã<br>
ã ãã人ã¯ããšãã§ããªãæéããããŠ<br>
ã€ã³ã¿ãŒãããã埩æ§ã§ãããå°å¥³ããé ã£ãã<br>
<br>
å°å¥³ã¯ãã€ã³ã¿ãŒãããã®æåœãã¯ãããã<br>
æãŠããªãåºãã€ã³ã¿ãŒãããã®äžçãã©ãã«ãããããšé 匵ã£ãã<br>
<br>
ãŸã å°å¥³ã²ãšãã§ã¯æã察ç·ãç¹ãäºãããããã§ããªããã©ã<br>
é·ãé·ãæããããŠã€ã³ã¿ãŒããããå°ã埩æ§ããã°ã<br>
ã¿ããªãšäžç·ã«é 匵ããã ãããšããæåŸ
ããããŠã
</p>
<h2>å顿</h2>
<p>
å°å¥³ã¯ãã€ãŠã€ã³ã¿ãŒãããã«ååšãã <var>N</var> åã®ãµãŒãã¹ã埩æ§ããããã«æ¥ã
é 匵ã£ãŠããïŒ
çŸåšã 0 æ¥ç®ãšããïŒ
ã€ã³ã¿ãŒããããã©ã®çšåºŠåŸ©æ§ããŠãããã<i>埩æ§åºŠ</i>ãšããææšã§è¡šãïŒçŸåšã®åŸ©æ§åºŠã¯ 0 ã§ãããšããïŒ
å°å¥³ã¯æ¯æ¥äœæ¥ããïŒåŸ©æ§åºŠã 1 æ¥ã«ã€ã 1 ãã€äžããŠããïŒ
ä»»æã®ãŸã 埩æ§ããŠããªããµãŒãã¹ <var>i</var> ã¯ïŒåŸ©æ§åºŠã <var>w<sub>i</sub></var> 以äžã«ãªããšèªåçã«åŸ©æ§ããïŒ
ãµãŒãã¹ <var>i</var> ã埩æ§ãããšïŒã¿ããªãæäŒã£ãŠãããããšã«ããïŒåŸ©æ§ããæ¬¡ã®æ¥ãã <var>x<sub>i</sub></var> æ¥éã ãäœæ¥ãã¯ãã©ãïŒåŸ©æ§åºŠã®å¢å ãå éããïŒ
ãµãŒãã¹ã«ã¯ 3 ã€ã®çš®é¡ãããïŒçš®é¡ã«ãã£ãŠåŸ©æ§åºŠãã©ã®çšåºŠå¢å ããã®ããç°ãªãïŒ
ãµãŒãã¹ã®çš®é¡ã <var>0, 1, 2</var> ã®çªå·ã§è¡šããšããïŒ
ãµãŒãã¹ <var>i</var> ã®çš®é¡ã t<sub>i</sub> (∈ {0, 1, 2}) ãšãããšïŒ
ãµãŒãã¹ <var>i</var> ã埩æ§ããŠãã <var>d-1</var> æ¥ç®ãã <var>d</var> æ¥ç®ã«ãã㊠<var>(1 ≤ d ≤ x<sub>i</sub>)</var>ïŒ
<var>t<sub>i</sub>=0</var> ã®å Žå㯠<var>1</var>ïŒ
<var>t<sub>i</sub>=1</var> ã®å Žå㯠<var>d</var>ïŒ
ãã㊠<var>t<sub>i</sub>=2</var> ã®å Žå㯠<var>d<sup>2</sup></var> ã ãïŒå°å¥³ã®äœæ¥ãšã¯å¥ã«åŸ©æ§åºŠãå¢å ããïŒ
ãŸãïŒåæã«è€æ°ã®ãµãŒãã¹ã埩æ§ããŠããå ŽåïŒããããã®ãµãŒãã¹ã¯ç¬ç«ã«äžŠè¡ããŠåŸ©æ§åºŠãå¢å ãããïŒ
</p>
<p>
å°å¥³ã¯ãµãŒãã¹ã埩æ§ãããŸã§ã«ãšãã§ããªãæéãããããšæã£ãã®ã§ïŒçŸåšããäœæ¥ç®ã«ãµãŒãã¹ã埩æ§ããã調ã¹ãããšã«ããïŒ
ãŸãããæ¥ã«ã¡ <var>y<sub>j</sub></var> ã«åŸ©æ§åºŠããããã«ãªã£ãŠããããæ°ã«ãªã£ãã®ã§ïŒããã <var>Q</var> æ¥åã ã調ã¹ãããšã«ããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ</p>
<pre>
<var>N</var> <var>Q</var>
<var>w<sub>1</sub></var> <var>t<sub>1</sub></var> <var>x<sub>1</sub></var>
<var>...</var>
<var>w<sub>N</sub></var> <var>t<sub>N</sub></var> <var>x<sub>N</sub></var>
<var>y<sub>1</sub></var>
<var>...</var>
<var>y<sub>Q</sub></var>
</pre>
<h2>åºå圢åŒ</h2>
<p>
æåã« <var>N</var> è¡åºåãïŒ<var>i</var> è¡ç®ã«ã¯ãµãŒãã¹ <var>i</var> ã®åŸ©æ§ããæ¥ã«ã¡ãåºåããïŒæ¬¡ã« <var>Q</var> è¡åºåãïŒ<var>j</var> è¡ç®ã«ã¯ <var>y<sub>j</sub></var> æ¥ç®ã«åŸ©æ§åºŠããããã«ãªã£ãŠããããåºåããïŒ
ãµãŒãã¹ã埩æ§ããæ¥ã«ã¡ã <var>3,652,425</var> ãè¶
ããå Žåã¯<code>Many years later</code>ãšåºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>0 ≤ N ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ Q ≤ 10<sup>5</sup></var></li>
<li><var>0 ≤ w<sub>i</sub> < 2<sup>60</sup></var></li>
<li><var>w<sub>i</sub> ≤ w<sub>i+1</sub> (1 ≤ i < N)</var></li>
<li><var>t<sub>i</sub> ∈ {0, 1, 2}</var></li>
<li><var>1 ≤ x<sub>i</sub> ≤ 10<sup>4</sup></var></li>
<li><var>0 ≤ y<sub>j</sub> ≤ 3,652,425</var></li>
<li><var>y<sub>j</sub> < y<sub>j+1</sub> (1 ≤ j < Q)</var></li>
<li>å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ</li>
</ul>
<p>
ãã®åé¡ã®å€å®ã«ã¯ïŒ15 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ
</p>
<ul>
<li><var>N,Q,w<sub>i</sub>,y<sub>j</sub> ≤ 1,000</var></li>
</ul>
<h3>泚æ</h3>
<ul>
<li>0 æ¥ç®ã®åŸ©æ§åºŠã¯ 0 ã§ããïŒ</li>
<li><var>w<sub>i</sub>=0</var> ã®æïŒãµãŒãã¹ <var>i</var> 㯠0 æ¥ç®ã«åŸ©æ§ããïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
3 11
1 0 2
4 1 3
7 2 4
0
1
2
3
4
5
6
7
8
9
10
</pre>
<h3>åºåäŸ1</h3>
<pre>
1
3
4
0
1
3
5
7
11
19
29
46
47
48
</pre>
<h3>å
¥åäŸ2</h3>
<pre>
5 5
10000 0 20
10000 1 30
10000 0 40
10000 2 70
30000 2 10000
5000
10000
15000
20000
25000
</pre>
<h3>åºåäŸ2</h3>
<pre>
10000
10000
10000
10000
10039
5000
10000
40711690801
329498273301
333383477320
</pre>
<h3>å
¥åäŸ3</h3>
<pre>
2 2
3652425 0 1
3652426 2 10000
3652424
3652425
</pre>
<h3>åºåäŸ3</h3>
<pre>
3652425
Many years later
3652424
3652425
</pre>
<p>2ã€ç®ã®ãµãŒãã¹ã¯åŸ©æ§ããæ¥ã«ã¡ã <var>3,652,425</var> æ¥ãè¶
ããŠããã®ã§<code>Many years later</code>ãšåºåããŠããïŒ</p>
<hr>
<address>Writer : æ£®æ§æ</address>
<address>Tester : ç°æåç¯</address>
|
p03148 | <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> pieces of sushi. Each piece has two parameters: "kind of topping" <var>t_i</var> and "deliciousness" <var>d_i</var>.
You are choosing <var>K</var> among these <var>N</var> pieces to eat.
Your "satisfaction" here will be calculated as follows:</p>
<ul>
<li>The satisfaction is the sum of the "base total deliciousness" and the "variety bonus".</li>
<li>The base total deliciousness is the sum of the deliciousness of the pieces you eat.</li>
<li>The variety bonus is <var>x*x</var>, where <var>x</var> is the number of different kinds of toppings of the pieces you eat.</li>
</ul>
<p>You want to have as much satisfaction as possible.
Find this maximum satisfaction.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq N \leq 10^5</var></li>
<li><var>1 \leq t_i \leq N</var></li>
<li><var>1 \leq d_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>K</var>
<var>t_1</var> <var>d_1</var>
<var>t_2</var> <var>d_2</var>
<var>.</var>
<var>.</var>
<var>.</var>
<var>t_N</var> <var>d_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum satisfaction that you can obtain.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
1 9
1 7
2 6
2 5
3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>26
</pre>
<p>If you eat Sushi <var>1,2</var> and <var>3</var>:</p>
<ul>
<li>The base total deliciousness is <var>9+7+6=22</var>.</li>
<li>The variety bonus is <var>2*2=4</var>.</li>
</ul>
<p>Thus, your satisfaction will be <var>26</var>, which is optimal.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 4
1 1
2 1
3 1
4 6
4 5
4 5
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>25
</pre>
<p>It is optimal to eat Sushi <var>1,2,3</var> and <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 5
5 1000000000
2 990000000
3 980000000
6 970000000
6 960000000
4 950000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4900000016
</pre>
<p>Note that the output may not fit into a <var>32</var>-bit integer type.</p></section>
</div>
</span> |
p01175 |
<H1><font color="#000">Problem E:</font> Optimal Rest</H1>
<p>
Music Macro Language (MML) is a language for textual representation of musical scores. Although there are various dialects of MML, all of them provide a set of commands to describe
scores, such as commands for notes, rests, octaves, volumes, and so forth.
</p>
<p>
In this problem, we focus on rests, i.e. intervals of silence. Each rest command consists of a
command specifier âRâ followed by a duration specifier. Each duration specifier is basically one
of the following numbers: â1â, â2â, â4â, â8â, â16â, â32â, and â64â, where â1â denotes a whole (1), â2â
a half (1/2), â4â a quarter (1/4), â8â an eighth (1/8), and so on. This number is called the base
duration, and optionally followed by one or more dots. The first dot adds the duration by the
half of the base duration. For example, â4.â denotes the duration of â4â (a quarter) plus â8â (an
eighth, i.e. the half of a quarter), or simply 1.5 times as long as â4â. In other words, âR4.â is
equivalent to âR4R8â. In case with two or more dots, each extra dot extends the duration by the
half of the previous one. Thus â4..â denotes the duration of â4â plus â8â plus â16â, â4...â denotes
the duration of â4â plus â8â plus â16â plus â32â, and so on. The duration extended by dots cannot
be shorter than â64â. For exapmle, neither â64.â nor â16...â will be accepted since both of the
last dots indicate the half of â64â (i.e. the duration of 1/128).
</p>
<p>
In this problem, you are required to write a program that finds the shortest expressions equivalent
to given sequences of rest commands.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. The first line of the input contains the number of
datasets <i>N</i>. Then, <i>N</i> datasets follow, each containing a sequence of valid rest commands in one
line. You may assume that no sequence contains more than 100,000 characters.
</p>
<H2>Output</H2>
<p>
For each dataset, your program should output the shortest expression in one line. If there are
multiple expressions of the shortest length, output the lexicographically smallest one.
</p>
<H2>Sample Input</H2>
<pre>
3
R2R2
R1R2R4R8R16R32R64
R1R4R16
</pre>
<H2>Output for the Sample Input</H2>
<pre>
R1
R1......
R16R1R4
</pre>
|
p01460 | <script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Matrix Operation</H1>
<p>
You are a student looking for a job.
Today you had an employment examination for an IT company.
They asked you to write an efficient program to perform several operations.
First, they showed you an <var>N \times N</var> square matrix and a list of operations.
All operations but one modify the matrix, and the last operation outputs the character in a specified cell.
Please remember that you need to output the final matrix after you finish all the operations.
</p>
<p>
Followings are the detail of the operations:
</p>
<dl>
<dt> WR r c v </dt><dd> (Write operation) write a integer v into the cell (r,c) (<var>1 \leq v \leq 1,000,000</var>)</dd>
<dt> CP r1 c1 r2 c2 </dt><dd> (Copy operation) copy a character in the cell (r1,c1) into the cell (r2,c2)</dd>
<dt> SR r1 r2 </dt><dd> (Swap Row operation) swap the r1-th row and r2-th row</dd>
<dt> SC c1 c2 </dt><dd> (Swap Column operation) swap the c1-th column and c2-th column</dd>
<dt> RL </dt><dd> (Rotate Left operation) rotate the whole matrix in counter-clockwise direction by 90 degrees</dd>
<dt> RR </dt><dd> (Rotate Right operation) rotate the whole matrix in clockwise direction by 90 degrees</dd>
<dt> RH </dt><dd> (Reflect Horizontal operation) reverse the order of the rows</dd>
<dt> RV </dt><dd> (Reflect Vertical operation) reverse the order of the columns</dd>
</dl>
<p>
</p>
<H2>Input</H2>
<p>
First line of each testcase contains nine integers.
First two integers in the line, N and Q, indicate the size of matrix and the number of queries, respectively <var>(1 \leq N,Q \leq 40,000)</var>.
Next three integers, A B, and C, are coefficients to calculate values in initial matrix <var>(1 \leq A,B,C \leq 1,000,000)</var>,
and they are used as follows: <var>A_{r,c} = (r * A + c * B) mod C</var> where r and c are row and column indices, respectively <var>(1\leq r,c\leq N)</var>.
Last four integers, D, E, F, and G, are coefficients to compute the final hash value mentioned in the next section <var>(1 \leq D \leq E \leq N, 1 \leq F \leq G \leq N, E - D \leq 1,000, G - F \leq 1,000)</var>.
Each of next Q lines contains one operation in the format as described above.
</p>
<H2>Output</H2>
<p>
Output a hash value h computed from the final matrix B by using following pseudo source code.
</p>
<pre>
h <- 314159265
for r = D...E
for c = F...G
h <- (31 * h + B_{r,c}) mod 1,000,000,007
</pre>
<p>
where "<-" is a destructive assignment operator, "for i = S...T" indicates a loop for i from S to T (both inclusive), and "mod" is a remainder operation.
</p>
<H2>Sample Input 1</H2>
<pre>
2 1 3 6 12 1 2 1 2
WR 1 1 1
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
676573821
</pre>
<H2>Sample Input 2</H2>
<pre>
2 1 3 6 12 1 2 1 2
RL
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
676636559
</pre>
<H2>Sample Input 3</H2>
<pre>
2 1 3 6 12 1 2 1 2
RH
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
676547189
</pre>
<H2>Sample Input 4</H2>
<pre>
39989 6 999983 999979 999961 1 1000 1 1000
SR 1 39989
SC 1 39989
RL
RH
RR
RV
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>
458797120
</pre>
|
p01030 | <h1>Problem C: Changing Grids</h1>
<h2>Background</h2>
<p>
AåãšBåã¯ããChanging Gridsããšããã²ãŒã ã«ç±äžããŠããããã®ã²ãŒã ã¯2人çšã§ããã¬ã€ã€ãŒ1ãã¹ããŒãžãæ§æãããã¬ã€ã€ãŒ2ããã®ã¹ããŒãžã«ææŠããŽãŒã«ãç®æããšãããã®ã§ããã
</p>
<p>
ä»ãAåãšBåã¯ãã®ã²ãŒã ãäœåºŠããã¬ã€ããŠããããAåã®é£åã§Båã¯1床ãåã€ããšãã§ããŠããªããããã§ããªãã¯ãBåã«ãã®ã²ãŒã ãæ»ç¥ããããã®ãã³ããæããŠãããããšã«ããã
</p>
<h2>Problem</h2>
<p>
æå»<var>T</var><sub>0</sub> = 0ã«ããã瞊<var>H</var>׿šª<var>W</var>ã®å€§ããã®äºæ¬¡å
ã°ãªããã®ç¶æ
ã<var>Area</var><sub>0</sub>ãšããŠäžãããããæ¬¡ã«ããã®ã°ãªããã®ç¶æ
ã¯æå»<var>T<sub>i</sub></var>ã«ãããŠãç¶æ
<var>Area<sub>i</sub></var>ã«åãæ¿ããããã®åãæ¿ããéçšã¯<var>N</var>åç¹°ãè¿ããããåæç¶æ
ã®ã°ãªããã«ã¯ã¹ã¿ãŒãã®äœçœ®'S'ãšãŽãŒã«ã®äœçœ®'G'ãäžãããããããããã®ã°ãªããã«ãããŠãŽãŒã«ãžèŸ¿ãçããå Žåã¯ããã®ãšãã®æå°æ©æ°ãåºåãããŽãŒã«ãžèŸ¿ãçããªãå Žåã¯ã'-1'ãåºåããããªãã以äžã®æ¡ä»¶ãæºããå¿
èŠãããã<br>
</p>
<ul>
<li><var>Area<sub>i</sub></var>ã¯ä»¥äžã®èŠçŽ ã§æ§æãããŠããã</li>
<ul>
<li>â.âã¯äœããªãç§»åå¯èœãªãã¹</li>
<li>â#âã¯é害ç©ã§ãããç§»åäžå¯èœãªãã¹</li>
<li>'S'ã¯ã¹ã¿ãŒãäœçœ®ã衚ããã¹</li>
<li>'G'ã¯ãŽãŒã«äœçœ®ã衚ããã¹</li>
</ul>
<li>ãã¬ã€ã€ãŒã¯çŸåšãããã¹ã®é£æ¥ããŠããäžäžå·Šå³ã®ãããã1ãã¹ã«ç§»åããããŸãã¯çŸåšãããã¹ã«çãŸãã®ã«1ç§ãããããã ããé害ç©ã®ãã¹ãã°ãªããã®ç¯å²å€ã«ã¯ç§»åã§ããªãã</li>
<li>æ©æ°ã¯ãçŸåšãã¬ã€ã€ãŒããããã¹ããäžäžå·Šå³ã®ãã¹ãž1ãã¹é²ããš1å¢å ããããã®å Žã«çãŸãå Žåã«ã¯å¢å ããªãã</li>
<li>å
šãŠã®ã°ãªããã®å€§ããã¯çžŠ<var>H</var>׿šª<var>W</var>ã§ããã</li>
<li>1ãã¹ç§»åããŸãã¯ãã®å Žã«çãŸã£ãåŸã«ã°ãªãããåãæ¿ããéãæ¬¡ã®ã°ãªããã«ãããŠé害ç©ãååšããªããã¹ã§ããã°ä»ã®ã°ãªããã®ç¶æ
ã«é¢ãããç§»åãå¯èœã§ããã</li>
<li>å
šãŠã®ã°ãªããã«ãããŠãåæã®ã°ãªããã«äžãããããŽãŒã«äœçœ®ã«å°éããå ŽåãŽãŒã«ãšã¿ãªãã</li>
</ul>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>H</var> <var>W</var>
<var>Area</var><sub>0</sub>
<var>N</var>
<var>T</var><sub>1</sub>
<var>Area</var><sub>1</sub>
<var>T</var><sub>2</sub>
<var>Area</var><sub>2</sub>
.
.
<var>T<sub>N</sub></var>
<var>Area<sub>N</sub></var>
</pre>
<p>
1è¡ç®ã«2ã€ã®æŽæ°<var>H,W</var>ã空çœåºåãã§äžãããããããã¯ãããããäºæ¬¡å
ã°ãªããã®çžŠãšæšªã®å€§ããã衚ãã2è¡ç®ãã<var>H</var>+1è¡ç®ãŸã§ã®åè¡ã«åæç¶æ
ã®äºæ¬¡å
ã°ãªããã®ç¶æ
ãäžããããã<var>H</var>+2è¡ç®ã«æŽæ°<var>N</var>ãäžãããããããã¯ãäºæ¬¡å
ã°ãªããã®å€åããåæ°ã衚ãã<var>H</var>+3è¡ç®ä»¥éã«<var>N</var>åã®äºæ¬¡å
ã°ãªããã®åãæ¿ããæå»<var>T<sub>i</sub></var>ãšãã®ç¶æ
ãäžããããããã ãã<var>T<sub>i</sub></var>ã¯å
šãп޿°ã§ããã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li>2 ≤ <var>H,W</var> ≤ 20</li>
<li>1 ≤ <var>N</var> ≤ 15</li>
<li>1 ≤ <var>T<sub>i</sub></var> ≤ 200 (<var>T</var><sub>1</sub> < <var>T</var><sub>2</sub> < ... < <var>T<sub>N</sub></var>)</li>
<li>ã¹ã¿ãŒãäœçœ®'S'ãšãŽãŒã«äœçœ®'G'ã¯ããããåæã®äºæ¬¡å
ã°ãªããã«1ã€ã ãååšããã</li>
</ul>
<h2>Output</h2>
<p>
ã¹ã¿ãŒããããŽãŒã«ãžå°éããããã®æå°ã®æ©æ°ãåºåããããã ãããŽãŒã«ã«å°éã§ããªãå Žåã¯'-1'ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
2 2
S.
.G
1
3
##
##
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
1çªç®ã®ã°ãªããã«åãæ¿ããæå»<var>T</var><sub>1</sub>ã¯3ã§ãããæéå
ã«ãã¬ã€ã€ãŒã¯ã¹ã¿ãŒããããŽãŒã«ãŸã§ã®æçæ©æ°ã2æ©ã§èŸ¿ãçãããšãå¯èœãªã®ã§2ãåºåããã
</p>
<h2>Sample Input 2</h2>
<pre>
2 2
S.
.G
1
2
##
##
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre>
<h2>Sample Input 3</h2>
<pre>
2 3
S##
##G
4
2
###
.##
3
###
#.#
5
###
##.
7
###
###
</pre>
<h2>Sample Output 3</h2>
<pre>
3
</pre>
<h2>Sample Input 4</h2>
<pre>
4 3
S..
...
.G.
...
4
2
###
#.#
###
#.#
4
###
#..
#..
###
6
###
#.#
###
#..
8
###
#..
#..
###
</pre>
<h2>Sample Output 4</h2>
<pre>
3
</pre>
<h2>Sample Input 5</h2>
<pre>
3 3
S##
###
##G
1
1
...
...
...
</pre>
<h2>Sample Output 5</h2>
<pre>
4
</pre>
|
p00271 |
<H1>æ°æž©ã®å·®</H1>
<p>
éžæã®çãããããœã³ã³ç²ååã«ãããããã€ãã³ãã«åå ããã«ã¯äœèª¿ç®¡çã倧åã§ããæ°æž©ã倧ããå€åããå£ç¯ã®å€ããç®ã«ã¯äœã«è² æ
ããããã颚éªãã²ãããããšèšãããŠããŸããäžçªæ°ãä»ããªããã°ãããªãæ¥ã¯ãæé«æ°æž©ãšæäœæ°æž©ã®å·®ãæã倧ããæ¥ã§ããïŒæ¥ã®æé«æ°æž©ãšæäœæ°æž©ãïŒæ¥åäžãããããšããããããã®æ¥ã«ã€ããŠæé«æ°æž©ããæäœæ°æž©ãåŒããå€ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<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>7</sub></var> <var>b<sub>7</sub></var>
</pre>
<p>
å
¥åã¯7è¡ãããªããiè¡ç®ã«ã¯<var>i</var>æ¥ç®ã®æé«æ°æž© <var>a<sub>i</sub></var>(-40 ≤ <var>a<sub>i</sub></var> ≤ 40)ãšæäœæ°æž© <var>b<sub>i</sub></var>(-40 ≤ <var>b<sub>i</sub></var> ≤ 40)ãè¡šãæŽæ°ãäžããããããã¹ãŠã®æ¥ã«ãããŠãæé«æ°æž© <var>a<sub>i</sub></var> ã¯å¿
ãæäœæ°æž© <var>b<sub>i</sub></var> 以äžãšãªã£ãŠããã
</p>
<h2>åºå</h2>
<p>
7æ¥åã®æ°æž©ã®å·®ã7è¡ã«åºåããã
</p>
<h2>å
¥åäŸ</h2>
<pre>
30 19
39 20
19 18
25 20
22 21
23 10
10 -10
</pre>
<h2>åºåäŸ</h2>
<pre>
11
19
1
5
1
13
20
</pre> |
p01899 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>
<h2>B: å±±æç·ã²ãŒã - Yamanote-line Game -</h2>
<h3>è±ïŒïŒïŒç¥è</h3>
<p>å±±æç·ã¯äŸ¿å©ã§ããã ãªããªãã°ã130åæãã ãã§æéã®èš±ãéãäœåšã§ãä¹ã£ãŠããããããã ããã ããå笊ã§ä¹è»ããå Žåã¯ãåç¬Šã®æå¹æéã«æ°ãã€ããªããã°ãªããªããICã«ãŒããªãå®å¿ãããããã®å±±æç·ã®ç¹æ§ãå©çšããŠãæ±äº¬è¿éã«ã¯é»è»ã«æºãããªããæ°ç ã貪ã茩ãååšãããã¡ãªã¿ã«ããã®åé¡ã®äœåè
ã¯ãã£ãããšããªããé§
å¡ã«ãã¬ãããšã¯çšã ãããããã¬ããããã©ãããããªã®ã§ããªã¹ã¹ã¡ã¯ããªãã</p>
<h3>å顿</h3>
<p>å±±æç·ã®ç¹æ§ãå©çšããã²ãŒã ããããã ããã§ã¯äžè¬åã®ããã<var>1</var>ãã<var>N</var>ã§çªå·ä»ãããã<var>N</var>åã®é§
ãããã<var>1</var>, <var>2</var>, ..., <var>N</var>ã®é ã§é§
ãåäžã«äžŠã³ãåé§
ãããããã®é§
ãžè¡ãã«ã<var>d</var>åã§ä¹è»å¯èœãªè·¯ç·ãšããŠå±±æç·ã¢ãããèããããšã«ãããã²ãŒã ã¯ä»¥äžã®ã«ãŒã«ã«åŸãã</p>
<ul>
<li>奜ããªé§
ãã¹ã¿ãŒãå°ç¹ã«éžã³<var>d</var>åã§å±±æç·ã¢ããã«ä¹è»ããã</li>
<li>ãã®åŸãä»»æã®é§
ã§éè»ãå床ä¹è»ããããšãç¹°ãè¿ãã</li>
<li>ã¹ã¿ãŒãããé§
ã§éè»ããæç¹ã§ã²ãŒã çµäºãšãªãã</li>
<li><var>i</var>çªç®ã®é§
ã§éãããš<var>p_i</var>åã®å ±é
¬ãåŸãããšãã§ããïŒ</li>
<li>ãã ãã1åºŠå ±é
¬ãåŸãé§
ã§ååºŠå ±é
¬ãåŸãããšã¯ã§ããªãã</li>
<li>ãŸããéè»ããåŸã«å床山æç·ã¢ããã«ä¹è»ããã«ã¯<var>d</var>åãããã</li>
</ul>
<p>ããŠãããªãã¯æå€§ã§äœåå²ããããšãã§ããã ãããããã²ãææŠããŠã¿ãŠæ¬²ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>N</var> <var>d</var>
<var>p_1</var> <var>p_2</var> ⊠<var>p_N</var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ãããªãã
1è¡ç®ã«ã¯ãå±±æç·ã¢ããã®é§
ã®æ°<var>N</var>ãšä¹è»è³<var>d</var>ã空çœåºåãã§äžããããã
2è¡ç®ã«ã¯ãåé§
ã§ããããå ±é
¬ã空çœåºåãã§äžãããã<var>i</var>çªç®ã®å€<var>p_i</var>ã¯é§
<var>i</var>ã®å ±é
¬ã衚ããŠããã
</p>
<h3>å¶çŽ</h3>
<ul>
<li><var>3 ≤ N ≤ 1{,}000</var></li>
<li><var>1 ≤ d ≤ 1{,}000</var></li>
<li><var>1 ≤ p_i ≤ 1{,}000</var> (<var>1 ≤ i ≤ N</var>)</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>ã²ãŒã ã§åŸãããéé¡ã®æå€§å€ã1è¡ã«åºåããã1å以äžã®éé¡ãåŸãããšãã§ããªãå Žåã¯"kusoge"ãš1è¡ã«åºåãããåºåã®æåŸã¯æ¹è¡ãäœèšãªæåãå«ãã§ã¯ãªããªãã</p>
<h3>å
¥åäŸ1</h3>
<pre>
5 130
130 170 100 120 140
</pre>
<h3>åºåäŸ1</h3>
<pre>50</pre>
<h3>å
¥åäŸ2</h3>
<pre>
3 100
100 90 65
</pre>
<h3>åºåäŸ2</h3>
<pre>kusoge</pre>
<h3>å
¥åäŸ3</h3>
<pre>
6 210
300 270 400 330 250 370
</pre>
<h3>åºåäŸ3</h3>
<pre>660</pre>
<h3>å
¥åäŸ4</h3>
<pre>
4 540
100 460 320 280
</pre>
<h3>åºåäŸ4</h3>
<pre>kusoge</pre> |
p00621 |
<H1><font color="#000000">Problem A:</font> Sleeping Cats </H1>
<p>
Jackã¯åœŒã®äœãå®¶ããšãŠãæ°ã«å
¥ã£ãŠãã. 圌ã®å®¶ã®å¡ã®äžã§æ¯æ¥ã®ããã«æãããããããã¡ãæŒå¯ãããŠããããã . Jackã¯ããããšãŠã奜ãã ã£ã.
</p>
<p>
Jackã¯, å€äŒã¿ã®èªç±ç ç©¶ãšããŠãããã¡ã®èг坿¥èšãä»ããããšã«ãã. ãã°ãã芳å¯ããŠãããã¡ã«, 圌ã¯ãããã¡ã®é¢çœãç¹åŸŽã«æ°ä»ãã.
</p>
<p>
å¡ã¯ W[å°º] ã®å¹
ããã, ããã«ãããã¡ã¯äžŠãã§æŒå¯ããã. ããããã®ãããã¡ã¯äœã®å€§ãããéãã®ã§, æŒå¯ã«å¿
èŠãšããå¹
ããŸãç°ãªã. æŒå¯ããã«ããããã¯, èªåãå¯ãããå Žæãããã°, ããã§æŒå¯ããã. ãã ã, ãã®ãããªå Žæãè€æ°ããå Žåã¯ããå·ŠåŽã§æŒå¯ãã, ååãªå¹
ãç¡ããã°è«ŠããŠåž°ã£ãŠããŸã. ãã°ããæŒå¯ãããããã¯ãèµ·ãããšå¡ããé£ã³éããŠã©ãããžãšè¡ã£ãŠããŸã.
</p>
<p>
Jackã¯ãããã¡ã芳å¯ããŠ, ãã®è¡åãããŒãã«æžãçãã. ããã, ãšãŠãå€ãã®ãããæŒå¯ãããŠããã®ã§, ãã®èšé²ãéèšããã®ã¯ãšãŠã倧å€ã§ãã. ããã°ã©ã ãæžããŠ, ãããã¡ãæŒå¯ãããå Žæãæ±ããã®ãæäŒã£ãŠã»ãã.
</p>
<H2>Input</H2>
<p>
å
¥åãã¡ã€ã«ã¯, è€æ°ã®ããŒã¿ã»ãããå«ã. ããããã®ããŒã¿ã»ããã®æåã®è¡ã¯2ã€ã®æŽæ°ãå«ã¿, ããããå¡ã®å¹
W ãš, åŸã«ç¶ãè¡æ° Q ã衚ã.
</p>
<p>
以äžã®Qè¡ã«, ããã®èгå¯èšé²ãäžãããã. åè¡ã¯, 以äžã®ããããã®æžåŒã«åŸã.
</p>
<p><span>s</span> [id] [w]</p>
<p><span>w</span> [id]</p>
<p>
åè
ã¯, ããã® sleep èšé²ã§ãã, ãããæŒå¯ããã«æ¥ãããšã衚ã. id ã¯ããã®ååãè¡šãæŽæ°ã§ãã, w ã¯ãã®ãããæŒå¯ã«å¿
èŠãšããå¹
[å°º]ã§ãã.
</p>
<p>
åŸè
ã¯, ããã® wakeup èšé²ã§ãã, ååãidã§ãããããèµ·ããããšã衚ã.
</p>
<p>
ãã®èšé²ã¯, æç³»åé ã«äžãããã.
</p>
<p>
ã©ã®ããã2åä»¥äžæŒå¯ãããããšã¯ãªã.
ãŸã, Jackã®èšé²ã«ççŸã¯ç¡ããã®ãšãã. ã€ãŸã, ããããã® sleep èšé²ã«å¯ŸããŠ, ãã®ãããæŒå¯ããããšãåºæ¥ãå Žå, ãŸããã®å Žåã«éã£ãŠ, ãã®ããã® wakeup èšé²ã(ããåŸã®è¡ã«)äžãããã.
</p>
<p>
W, Q ≤ 100 ãšä»®å®ããŠãã.
</p>
<p>
W ãš Q ããšãã« 0 ã®ãšããå
¥åã®çµããã瀺ã. ãã®ããŒã¿ã»ããã«å¯Ÿããåºåãè¡ã£ãŠã¯ãªããªã.
</p>
<H2>Output</H2>
<p>
å
¥åã®sleepèšé²ãäžãããããã³ã«, 1è¡åºåãã.
ãã®è¡ã¯, ãããã®ãããæŒå¯ã§ããå Žå, ãã®äœçœ®ãè¡šãæ°åãå«ãŸãªããã°ãªããªã. ãããå¡ã®å·Šç«¯ãèµ·ç¹ãšã㊠b [å°º] ãã b+w [å°º] ã®å Žæã§æŒå¯ãããªãã°, b ãåºåãã.
ãã®ãããæŒå¯ã§ããªãã£ãå Žå, "<span>impossible</span>" ãšåºåãã.
</p>
<p>
ããŒã¿ã»ããã®çµããã«, "END"ãšåºåãã.
</p>
<H2>Sample Input</H2>
<pre>
4 6
s 0 2
s 1 3
s 2 1
w 0
s 3 3
s 4 2
3 3
s 0 1
s 1 1
s 2 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
impossible
2
impossible
0
END
0
1
2
END
</pre>
|
p01933 |
<!-- - - - - - begin nicebody - - - - - -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} });
</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>C: ãã€ãŒãæ°</h1>
<h2>åé¡</h2>
<p>AORã€ã«ã¡ãããå©çšããSNSã§ããã€ã«ã£ããŒã§ã¯ãæçš¿ã®ããšããã€ãŒããšåŒã¶ã</p>
<p>ãããŠãã€ã«ã£ããŒã§ã¯ããã€ãŒããžã®è¿ä¿¡ãå€ããªããšèŠèªæ§ãæªããªãããšãæžå¿µãããããããããã€ãŒããæ¬¡ã®èŠåã®ãããããæºãããšãã«ç»é¢ã«ãã®ãã€ãŒãã衚瀺ãã仿§ã«ãªã£ãŠããã</p>
<ul>
<li>èŠåïŒ. ã©ã®ãã€ãŒããžãè¿ä¿¡ããŠããªã</li>
<li>èŠåïŒ. ã©ã®ãã€ãŒããããè¿ä¿¡ãããŠããªã</li>
<li>èŠåïŒ. èŠåïŒãé©çšããããã€ãŒãããè¿ä¿¡å
ãé ã«èŸ¿ã£ããšãã $K$ åæªæºã§èŸ¿ãçãã</li>
</ul>
<p>ãªããåããã€ãŒãã¯éè€ããŠè¡šç€ºãããããšã¯ãªãã</p>
<p>ããŸã $N$ åã®ãã€ãŒããããã $A_i$ ã $0$ ã®ãšã $i$ çªç®ã®ãã€ãŒãã¯è¿ä¿¡ã§ãªããã€ãŒãã§ã $A_i$ ã $0$ ã§ãªããšã $i$ çªç®ã®ãã€ãŒã㯠$A_i$ çªç®ã®ãã€ãŒããžã®è¿ä¿¡ã®ãã€ãŒãã§ããã</p>
<p>ç»é¢ã«è¡šç€ºããããã€ãŒãæ°ãçããã</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le N \le 10^5$</li>
<li>$1 \le K \le 10^5$</li>
<li>$0 \le A_i \lt i (i = 1, 2, \dots, N)$</li>
<li>ãã€ãŒãã¯æç³»åé ã«äžããããã</li>
<li>å
¥åã¯å
šãп޿°ã§äžããããã</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<p>$N \ K$<br>$A_1$<br>$A_2$<br>$\vdots$<br>$A_N$</p>
<h2>åºå</h2>
<p>ç»é¢ã«è¡šç€ºããããã€ãŒãæ°ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>6 3
0
0
2
3
4
5
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>5
</pre>
<p>ãã®æã衚瀺ããããã€ãŒãã¯ãå³ã®éããã€ãŒãã§ããã ãã£ãŠããã®äŸã®è§£ã¯ $5$ ã§ããã</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day1_rupc2017_c" height="400" />
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>12 2
0
1
0
3
4
3
6
7
0
9
10
11
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>10
</pre>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>5 10
0
0
0
0
0
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>5
</pre>
<!-- - - - - - end nicebody - - - - - --> |
p02132 | <h1>Problem I: Explosion</h1>
<h2>Problem</h2>
<p>
倧éçããã¿ãã¯å°äžã«çåãã$N$人ã®åè
ãåãããšèããŠããã<br>
ããã¿ãã¯$M$åãŸã§ççºéæ³ãå±ããããšãã§ããã<br>
ççºéæ³ã¯ä»»æã®åº§æšãäžå¿ã«ååŸ$r$以å
ã«ååšããŠããåè
ãæ¶æ»
ãããéæ³ã§ããã<br>
åè
ã¯ãšãŠãç©ããŠãããã倧ããã¯èæ
®ããªããŠããã<br>
$M$åã®ççºéæ³ã¯å
šãŠåã倧ããã®ååŸã§å±ãããã®ãšããã<br>
åè
ãå
šæ»
ãããã®ã«å¿
èŠæå°éã®ååŸã®éæ³ã䜿ãããšã«ããã<br>
ççºéæ³ã®ååŸã®å€§ãããæå°åããã<br>
<h2>Input</h2>
<pre>
$N$ $M$
$x_1$ $y_1$
...
$x_N$ $y_N$
</pre>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã<br>
1è¡ç®ã« åè
ã®æ° $N$ ãå±ããççºã®æ° $M$ ãæŽæ°ã§äžããããã<br>
2è¡ç®ä»¥éã«ããããã®åè
$i$ã®åº§æš $x_i$ $,$ $y_i$ ãæŽæ°ã§äžããããã<br>
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li>$1 \leq M \leq N \leq 14$</li>
<li>$0 \leq x_i $,$ y_i \leq 10^5$</li>
</ul>
<h2>Output</h2>
<p>
ççºéæ³ã®ååŸã®æå°å€ã宿°ã§åºåããã<br>
$10^{-3}$ãè¶
ãã絶察誀差ãå«ãã§ã¯ãªããªãã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
5 2
0 0
5 5
10 10
100 100
200 200
</pre>
<h2>Sample Output 1</h2>
<pre>
70.710678118755
</pre>
<h2>Sample Input 2</h2>
<pre>
10 5
321 675
4312 6534
312 532
412 6543
21 43
654 321
543 0
32 5
41 76
5 1
</pre>
<h2>Sample Output 2</h2>
<pre>
169.824909833728
</pre>
<h2>Sample Input 3</h2>
<pre>
14 3
312 342
4893 432
321 4
389 4
23 543
0 0
1 1
2 2
432 12
435 32
1 5
2 10
100 100
20 50
</pre>
<h2>Sample Output 3</h2>
<pre>
218.087711712613
</pre>
<h2>Sample Input 4</h2>
<pre>
5 2
0 0
0 0
0 0
0 0
0 0
</pre>
<h2>Sample Output 4</h2>
<pre>
0.000000000001
</pre>
|
p02098 |
<h1>Problem A: The Mean of Angles</h1>
<h2>Problem</h2>
<p>
äžãããã2ã€ã®è§åºŠ<var>θ<sub>1</sub></var>,<var>θ<sub>2</sub></var> ã®ã¡ããã©éã®è§åºŠãæ±ãããããã§ãã¡ããã©éã®è§åºŠããäžå³ã®ããã«ã<var>θ<sub>1</sub></var> + <var>t</var> = <var>θ<sub>2</sub></var> − <var>t</var> ãæºãã<var>t</var>ã®ãã¡çµ¶å¯Ÿå€ãæãå°ãããã®ã<var>tâ</var>ãšãããšãã®<var>θ<sub>1</sub></var> + <var>tâ</var>ããšå®çŸ©ããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day2_UAPC_A_angle" alt="A image of angles" title="ã¡ããã©éã®è§åºŠ">
</center>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>θ<sub>1</sub></var>
<var>θ<sub>2</sub></var>
</pre>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>è§åºŠã¯åºŠæ°æ³(degree)ã§è¡šããã</li>
<li>0 ≤ <var>θ<sub>1</sub></var>, <var>θ<sub>2</sub></var> < 360</li>
<li><var>θ<sub>1</sub></var>, <var>θ<sub>2</sub></var>ã¯æŽæ°</li>
<li>|<var>θ<sub>1</sub></var> − <var>θ<sub>2</sub></var>| ≠ 180</li>
<li>è§£çã[0,0.0001]ãŸãã¯[359.999, 360)ã«ãªããããªå
¥åã¯äžããããªã</li>
</ul>
<h2>Output</h2>
<p>
<var>θ<sub>1</sub></var>,<var>θ<sub>2</sub></var>ã®ã¡ããã©éã®è§åºŠãåºŠæ°æ³ã§[0,360)ã®ç¯å²ã§1è¡ã«åºåããããã ã0.0001ãè¶
ãã誀差ãå«ãã§ã¯ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
10
20
</pre>
<h2>Sample Output 1</h2>
<pre>
15.0
</pre>
<h2>Sample Input 2</h2>
<pre>
20
350
</pre>
<h2>Sample Output 2</h2>
<pre>
5.0
</pre> |
p02562 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a grid of <var>N</var> rows and <var>M</var> columns. The square at the <var>i</var>-th row and <var>j</var>-th column will be denoted as <var>(i,j)</var>.
A nonnegative integer <var>A_{i,j}</var> is written for each square <var>(i,j)</var>.</p>
<p>You choose some of the squares so that each row and column contains at most <var>K</var> chosen squares.
Under this constraint, calculate the maximum value of the sum of the integers written on the chosen squares.
Additionally, calculate a way to choose squares that acheives the maximum.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>1 \leq K \leq N</var></li>
<li><var>0 \leq A_{i,j} \leq 10^9</var></li>
<li>All values in Input are integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_{1,1}</var> <var>A_{1,2}</var> <var>\cdots</var> <var>A_{1,N}</var>
<var>A_{2,1}</var> <var>A_{2,2}</var> <var>\cdots</var> <var>A_{2,N}</var>
<var>\vdots</var>
<var>A_{N,1}</var> <var>A_{N,2}</var> <var>\cdots</var> <var>A_{N,N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>On the first line, print the maximum value of the sum of the integers written on the chosen squares.</p>
<p>On the next <var>N</var> lines, print a way that achieves the maximum.</p>
<p>Precisely, output the strings <var>t_1,t_2,\cdots,t_N</var>, that satisfies <var>t_{i,j}=</var><code>X</code> if you choose <var>(i,j)</var> and <var>t_{i,j}=</var><code>.</code> otherwise.</p>
<p>You may print any way to choose squares that maximizes the sum.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
5 3 2
1 4 8
7 6 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>19
X..
..X
.X.
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
10 10 1
10 10 1
1 1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>50
XX.
XX.
..X
</pre></section>
</div>
</span> |
p02831 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi is organizing a party.</p>
<p>At the party, each guest will receive one or more snack pieces.</p>
<p>Takahashi predicts that the number of guests at this party will be <var>A</var> or <var>B</var>.</p>
<p>Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.</p>
<p>We assume that a piece cannot be divided and distributed to multiple guests.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq A, B \leq 10^5</var></li>
<li><var>A \neq B</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with <var>A</var> guests and <var>B</var> guests.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>123 456
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>18696
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9999900000
</pre></section>
</div>
</span> |
p03723 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi, Aoki and Snuke love cookies. They have <var>A</var>, <var>B</var> and <var>C</var> cookies, respectively. Now, they will exchange those cookies by repeating the action below:</p>
<ul>
<li>Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.</li>
</ul>
<p>This action will be repeated until there is a person with odd number of cookies in hand.</p>
<p>How many times will they repeat this action?
Note that the answer may not be finite.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †A,B,C †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>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of times the action will be performed by the three people, if this number is finite.
If it is infinite, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 12 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Initially, Takahashi, Aoki and Snuke have <var>4</var>, <var>12</var> and <var>20</var> cookies. Then,</p>
<ul>
<li>After the first action, they have <var>16</var>, <var>12</var> and <var>8</var>.</li>
<li>After the second action, they have <var>10</var>, <var>12</var> and <var>14</var>.</li>
<li>After the third action, they have <var>13</var>, <var>12</var> and <var>11</var>.</li>
</ul>
<p>Now, Takahashi and Snuke have odd number of cookies, and therefore the answer is <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>14 14 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>454 414 444
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p03689 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given four integers: <var>H</var>, <var>W</var>, <var>h</var> and <var>w</var> (<var>1 †h †H</var>, <var>1 †w †W</var>).
Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:</p>
<ul>
<li>The matrix has <var>H</var> rows and <var>W</var> columns.</li>
<li>Each element of the matrix is an integer between <var>-10^9</var> and <var>10^9</var> (inclusive).</li>
<li>The sum of all the elements of the matrix is positive.</li>
<li>The sum of all the elements within every subrectangle with <var>h</var> rows and <var>w</var> columns in the matrix is negative.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †h †H †500</var></li>
<li><var>1 †w †W †500</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>H</var> <var>W</var> <var>h</var> <var>w</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there does not exist a matrix that satisfies all of the conditions, print <code>No</code>.</p>
<p>Otherwise, print <code>Yes</code> in the first line, and print a matrix in the subsequent lines in the following format:</p>
<pre><var>a_{11}</var> <var>...</var> <var>a_{1W}</var>
<var>:</var>
<var>a_{H1}</var> <var>...</var> <var>a_{HW}</var>
</pre>
<p>Here, <var>a_{ij}</var> represents the <var>(i,\ j)</var> element of the matrix.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
1 1 1
1 -4 1
1 1 1
</pre>
<p>The sum of all the elements of this matrix is <var>4</var>, which is positive.
Also, in this matrix, there are four subrectangles with <var>2</var> rows and <var>2</var> columns as shown below. For each of them, the sum of all the elements inside is <var>-1</var>, which is negative.</p>
<div style="text-align: center;">
<img alt="bbdb651fa1f05996886da9f0c4d8090a.png" src="https://atcoder.jp/img/agc016/bbdb651fa1f05996886da9f0c4d8090a.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 4 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 4 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
2 -5 8 7
3 -5 -4 -5
2 1 -1 7
</pre></section>
</div>
</span> |
p03373 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are <var>A</var> yen, <var>B</var> yen and <var>C</var> yen (yen is the currency of Japan), respectively.</p>
<p>Nakahashi needs to prepare <var>X</var> A-pizzas and <var>Y</var> B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †A, B, C †5000</var></li>
<li><var>1 †X, Y †10^5</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum amount of money required to prepare <var>X</var> A-pizzas and <var>Y</var> B-pizzas.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1500 2000 1600 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7900
</pre>
<p>It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1500 2000 1900 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8500
</pre>
<p>It is optimal to directly buy three A-pizzas and two B-pizzas.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1500 2000 500 90000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100000000
</pre>
<p>It is optimal to buy <var>200000</var> AB-pizzas and rearrange them into <var>100000</var> A-pizzas and <var>100000</var> B-pizzas. We will have <var>10000</var> more A-pizzas than necessary, but that is fine.</p></section>
</div>
</span> |
p02974 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let us define the <em>oddness</em> of a permutation <var>p</var> = {<var>p_1,\ p_2,\ ...,\ p_n</var>} of {<var>1,\ 2,\ ...,\ n</var>} as <var>\sum_{i = 1}^n |i - p_i|</var>.</p>
<p>Find the number of permutations of {<var>1,\ 2,\ ...,\ n</var>} of oddness <var>k</var>, modulo <var>10^9+7</var>.</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 50</var></li>
<li><var>0 \leq k \leq n^2</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var> <var>k</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of permutations of {<var>1,\ 2,\ ...,\ n</var>} of oddness <var>k</var>, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are six permutations of {<var>1,\ 2,\ 3</var>}. Among them, two have oddness of <var>2</var>: {<var>2,\ 1,\ 3</var>} and {<var>1,\ 3,\ 2</var>}.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>39 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>74764168
</pre></section>
</div>
</span> |
p00949 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem D
Hidden Anagrams
</h2>
<p>
An <i>anagram</i> is a word or a phrase that is formed by rearranging the letters of another. For instance, by rearranging the letters of "William Shakespeare," we can have its anagrams "I am a weakish speller," "I'll make a wise phrase," and so on. Note that when $A$ is an anagram of $B$, $B$ is an anagram of $A$.
</p>
<p>
In the above examples, differences in letter cases are ignored, and word spaces and punctuation symbols are freely inserted and/or removed. These rules are common but not applied here; only exact matching of the letters is considered.
</p>
<p>
For two strings $s_1$ and $s_2$ of letters, if a substring $s'_1$ of $s_1$ is an anagram of a substring $s'_2$ of $s_2$, we call $s'_1$ a <i>hidden anagram</i> of the two strings, $s_1$ and $s_2$. Of course, $s'_2$ is also a <i>hidden anagram</i> of them.
</p>
<p>
Your task is to write a program that, for given two strings, computes the length of the longest hidden anagrams of them.
</p>
<p>
Suppose, for instance, that "anagram" and "grandmother" are given. Their substrings "nagr" and "gran" are hidden anagrams since by moving letters you can have one from the other. They are the longest since any substrings of "grandmother" of lengths five or more must contain "d" or "o" that "anagram" does not. In this case, therefore, the length of the longest hidden anagrams is four. Note that a substring must be a sequence of letters occurring <i>consecutively</i> in the original string and so "nagrm" and "granm" are not hidden anagrams.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case in two lines.<br/>
<br/>
$s_1$<br/>
$s_2$<br/>
</p>
<p>
$s_1$ and $s_2$ are strings consisting of lowercase letters (a through z) and their lengths are between 1 and 4000, inclusive.
</p>
<h3>Output</h3>
<p>
Output the length of the longest hidden anagrams of $s_1$ and $s_2$. If there are no hidden anagrams, print a zero.
</p>
<h3>Sample Input 1</h3>
<pre>anagram
grandmother</pre>
<h3>Sample Output 1</h3>
<pre>4</pre>
<br/>
<h3>Sample Input 2</h3>
<pre>williamshakespeare
iamaweakishspeller</pre>
<h3>Sample Output 2</h3>
<pre>18</pre>
<br/>
<h3>Sample Input 3</h3>
<pre>aaaaaaaabbbbbbbb
xxxxxabababxxxxxabab</pre>
<h3>Sample Output 3</h3>
<pre>6</pre>
<br/>
<h3>Sample Input 4</h3>
<pre>abababacdcdcd
efefefghghghghgh</pre>
<h3>Sample Output 4</h3>
<pre>0</pre>
|
p03666 | <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> squares in a row.
The leftmost square contains the integer <var>A</var>, and the rightmost contains the integer <var>B</var>. The other squares are empty.</p>
<p>Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:</p>
<ul>
<li>For any two adjacent squares, the (absolute) difference of the two integers in those squares is between <var>C</var> and <var>D</var> (inclusive).</li>
</ul>
<p>As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares.
Determine whether it is possible to fill the squares under the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 500000</var></li>
<li><var>0 \leq A \leq 10^9</var></li>
<li><var>0 \leq B \leq 10^9</var></li>
<li><var>0 \leq C \leq D \leq 10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if it is possible to fill the squares under the condition; print <code>NO</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 1 5 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>For example, fill the squares with the following integers: <var>1</var>, <var>-1</var>, <var>3</var>, <var>7</var>, <var>5</var>, from left to right.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 7 6 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>48792 105960835 681218449 90629745 90632170
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>491995 412925347 825318103 59999126 59999339
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>YES
</pre></section>
</div>
</span> |
p03236 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><strong>Problem F and F2 are the same problem, but with different constraints and time limits.</strong></p>
<p>We have a board divided into <var>N</var> horizontal rows and <var>N</var> vertical columns of square cells.
The cell at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is called Cell <var>(i,j)</var>.
Each cell is either empty or occupied by an obstacle.
Also, each empty cell has a digit written on it.
If <var>A_{i,j}=</var> <code>1</code>, <code>2</code>, ..., or <code>9</code>, Cell <var>(i,j)</var> is empty and the digit <var>A_{i,j}</var> is written on it.
If <var>A_{i,j}=</var> <code>#</code>, Cell <var>(i,j)</var> is occupied by an obstacle.</p>
<p>Cell <var>Y</var> is <em>reachable</em> from cell <var>X</var> when the following conditions are all met:</p>
<ul>
<li>Cells <var>X</var> and <var>Y</var> are different.</li>
<li>Cells <var>X</var> and <var>Y</var> are both empty.</li>
<li>One can reach from Cell <var>X</var> to Cell <var>Y</var> by repeatedly moving right or down to an adjacent empty cell.</li>
</ul>
<p>Consider all pairs of cells <var>(X,Y)</var> such that cell <var>Y</var> is reachable from cell <var>X</var>.
Find the sum of the products of the digits written on cell <var>X</var> and cell <var>Y</var> for all of those pairs.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 500</var></li>
<li><var>A_{i,j}</var> is one of the following characters: <code>1</code>, <code>2</code>, ... <code>9</code> and <code>#</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1,1}A_{1,2}...A_{1,N}</var>
<var>A_{2,1}A_{2,2}...A_{2,N}</var>
<var>:</var>
<var>A_{N,1}A_{N,2}...A_{N,N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the products of the digits written on cell <var>X</var> and cell <var>Y</var> for all pairs <var>(X,Y)</var> such that cell <var>Y</var> is reachable from cell <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
11
11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five pairs of cells <var>(X,Y)</var> such that cell <var>Y</var> is reachable from cell <var>X</var>, as follows:</p>
<ul>
<li><var>X=(1,1)</var>, <var>Y=(1,2)</var></li>
<li><var>X=(1,1)</var>, <var>Y=(2,1)</var></li>
<li><var>X=(1,1)</var>, <var>Y=(2,2)</var></li>
<li><var>X=(1,2)</var>, <var>Y=(2,2)</var></li>
<li><var>X=(2,1)</var>, <var>Y=(2,2)</var></li>
</ul>
<p>The product of the digits written on cell <var>X</var> and cell <var>Y</var> is <var>1</var> for all of those pairs, so the answer is <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1111
11#1
1#11
1111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>47
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
76##63##3#
8445669721
75#9542133
3#285##445
749632##89
2458##9515
5952578#77
1#3#44196#
4355#99#1#
#298#63587
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>36065
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
4177143673
7#########
5#1716155#
6#4#####5#
2#3#597#6#
6#9#8#3#5#
5#2#899#9#
1#6#####6#
6#5359657#
5#########
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>6525
</pre></section>
</div>
</span> |
p04009 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns.
The state of the cell at the <var>i</var>-th (<var>1â€iâ€H</var>) row and <var>j</var>-th (<var>1â€jâ€W</var>) column is represented by a letter <var>a_{ij}</var>, as follows:</p>
<ul>
<li><code>.</code> : This cell is empty.</li>
<li><code>o</code> : This cell contains a robot.</li>
<li><code>E</code> : This cell contains the exit. <code>E</code> occurs exactly once in the whole grid.</li>
</ul>
<p>Snuke is trying to salvage as many robots as possible, by performing the following operation some number of times:</p>
<ul>
<li>Select one of the following directions: up, down, left, right. All remaining robots will move one cell in the selected direction, except when a robot would step outside the grid, in which case the robot will explode and immediately disappear from the grid. If a robot moves to the cell that contains the exit, the robot will be salvaged and immediately removed from the grid.</li>
</ul>
<p>Find the maximum number of robots that can be salvaged.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€H,Wâ€100</var></li>
<li><var>a_{ij}</var> is <code>.</code>, <code>o</code> or <code>E</code>.</li>
<li><code>E</code> occurs exactly once in the whole grid.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{11}</var><var>...</var><var>a_{1W}</var>
<var>:</var>
<var>a_{H1}</var><var>...</var><var>a_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of robots that can be salvaged.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
o.o
.Eo
ooo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>For example, select left, up, right.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
E.
..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 4
o...
o...
oooE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre>
<p>Select right, right, right, down, down.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 11
ooo.ooo.ooo
o.o.o...o..
ooo.oE..o..
o.o.o.o.o..
o.o.ooo.ooo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>12
</pre></section>
</div>
</span> |
p02077 | <style type="text/css">
blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
display: block;
margin: 10px 0 10px 30px;
font-size: 16px;
line-height: 18px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}
table.ioexample {
width: 100%;
border-collapse: collapse;
}
table.ioexample td {
width: 50%;
border: 1px solid rgba(0, 0, 0, 0.15);
vertical-align: top;
padding: 5px;
}
.no-page-break {
page-break-inside: avoid;
}
.page-break {
page-break-before: always;
}
</style>
<h3>Problem Statement</h3>
<p>JAG land is a country, which is represented as an $M \times M$ grid. Its top-left cell is $(1, 1)$ and its bottom-right cell is $(M, M)$.</p>
<p>Suddenly, a bomber invaded JAG land and dropped bombs to the country. Its bombing pattern is always fixed and represented by an $N \times N$ grid. Each symbol in the bombing pattern is either <code>X</code> or <code>.</code>. The meaning of each symbol is as follows.</p>
<ul>
<li><code>X</code>: Bomb </li>
<li><code>.</code>: Empty</li>
</ul>
<p>Here, suppose that a bomber is in $(br, bc)$ in the land and drops a bomb. The cell $(br + i - 1, bc + j - 1)$ will be damaged if the symbol in the $i$-th row and the $j$-th column of the bombing pattern is <code>X</code> ($1 \le i, j \le N$).</p>
<p>Initially, the bomber reached $(1, 1)$ in JAG land. The bomber repeated to move to either of $4$-directions and then dropped a bomb just $L$ times. During this attack, the values of the coordinates of the bomber were between $1$ and $M - N + 1$, inclusive, while it dropped bombs. Finally, the bomber left the country.</p>
<p>The moving pattern of the bomber is described as $L$ characters. The $i$-th character corresponds to the $i$-th move and the meaning of each character is as follows.</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>Your task is to write a program to analyze the damage situation in JAG land. To investigate damage overview in the land, calculate the number of cells which were damaged by the bomber at least $K$ times.</p>
<hr />
<h3>Input</h3>
<p>The input consists of a single test case in the format below.</p>
<blockquote>$N$ $M$ $K$ $L$
$B_{1}$
$\vdots$
$B_{N}$
$S$</blockquote>
<p>The first line contains four integers $N$, $M$, $K$ and $L$($1 \le N < M \le 500$, $1 \le K \le L \le 2 \times 10^{5}$).
The following $N$ lines represent the bombing pattern.
$B_i$ is a string of length $N$. Each character of $B_i$ is either <code>X</code> or <code>.</code>. The last line denotes the moving pattern.
$S$ is a string of length $L$, which consists of either <code>U</code>, <code>D</code>, <code>L</code> or <code>R</code>.
It's guaranteed that the values of the coordinates of the bomber are between $1$ and $M - N + 1$, inclusive, while it drops bombs in the country.</p>
<h3>Output</h3>
<p>Print the number of cells which were damaged by the bomber at least $K$ times.</p>
<p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>2 3 2 4
XX
X.
RDLU
</pre></td><td><pre>3
</pre></td></tr><tr><td><pre>7 8 3 5
.XXX.X.
X..X.X.
...XX.X
XX.XXXX
..XXXX.
X.X....
..XXXXX
DRULD
</pre></td><td><pre>26
</pre></td></tr></table></div></p>
|
p02427 | <h1>Enumeration of Subsets I</h1>
<p>
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
</pre>
<h2>Output</h2>
<p>
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
</p>
<pre>
$d$: $e_0$ $e_1$ ...
</pre>
<p>
Print '<span>:</span>' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 18$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4
</pre>
<h2>Sample Output 1</h2>
<pre>
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3
</pre>
<p>
Note that if the subset is empty, your program should not output a space character after '<span>:</span>'.
</p>
|
p01122 | <!--<h2>Problem F</h2>-->
<!-- begin en only -->
<h3>Flipping Colors</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
You are given an undirected complete graph.
Every pair of the nodes in the graph is connected by an edge,
colored either red or black.
Each edge is associated with an integer value called <em>penalty.</em>
</p>
<p>
By repeating certain operations on the given graph,
a “spanning tree” should be formed with only the red edges.
That is, the number of red edges should be made exactly one less than
the number of nodes, and all the nodes should be made connected
only via red edges, directly or indirectly.
If two or more such trees can be formed,
one with the least sum of penalties of red edges should be chosen.
</p>
<p>
In a single operation step, you choose one of the nodes and flip the colors
of <i>all</i> the edges connected to it:
Red ones will turn to black, and black ones to red.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_F1.png" width="664px" height="214px">
<figcaption style="padding-top: 10px" align="center">
<!-- begin en only -->
Fig. F-1 The first dataset of Sample Input and its solution
<!-- end en only -->
</figcaption>
</center>
<!-- begin en only -->
<p>
For example, the leftmost graph of Fig. F-1 illustrates the first
dataset of Sample Input.
By flipping the colors of all the edges connected to the node 3, and
then flipping all the edges connected to the node 2,
you can form a spanning tree made of red edges as shown in the
rightmost graph of the figure.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of multiple datasets, each in the following format.
</p>
<!-- end en only -->
<p>
<blockquote>
<i>n</i> <br>
<i>e</i><sub>1,2</sub> <i>e</i><sub>1,3</sub> ... <i>e</i><sub>1,<i>n</i>-1</sub> <i>e</i><sub>1,<i>n</i></sub><br>
<i>e</i><sub>2,3</sub> <i>e</i><sub>2,4</sub> ... <i>e</i><sub>2,<i>n</i></sub><br>
... <br>
<i>e</i><sub><i>n</i>-1,<i>n</i></sub>
</blockquote>
</p>
<!-- begin en only -->
<p>
The integer <i>n</i> (2 ≤ <i>n</i> ≤ 300) is the number of nodes.
The nodes are numbered from 1 to <i>n</i>.
The integer <i>e</i><sub><i>i</i>,<i>k</i></sub> (1 ≤ |<i>e</i><sub><i>i</i>,<i>k</i></sub>| ≤ 10<sup>5</sup>)
denotes the penalty and the initial color of the edge between the node <i>i</i> and the node <i>k</i>.
Its absolute value |<i>e</i><sub><i>i</i>,<i>k</i></sub>| represents the penalty of the edge.
<i>e</i><sub><i>i</i>,<i>k</i></sub> > 0 means that the edge is initially red,
and <i>e</i><sub><i>i</i>,<i>k</i></sub> < 0 means it is black.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing a zero.
The number of datasets does not exceed 50.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, print the sum of edge penalties of the red spanning tree
with the least sum of edge penalties obtained by the above-described operations.
If a red spanning tree can never be made by such operations, print <tt>-1</tt>.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
4
3 3 1
2 6
-4
3
1 -10
100
5
-2 -2 -2 -2
-1 -1 -1
-1 -1
1
4
-4 7 6
2 3
-1
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
7
11
-1
9
</pre>
|
p01572 |
<H1><font color="#000">Problem B:</font> Artistic Art Museum</H1>
<p>
Mr. Knight is a chief architect of the project to build a new art museum. One day, he was struggling to determine the design of the building. He believed that a brilliant art museum must have an artistic building, so he started to search for a good motif of his building. The art museum has one big theme: "nature and human beings." To reflect the theme, he decided to adopt a combination of a cylinder and a prism, which symbolize nature and human beings respectively (between these figures and the theme, there is a profound relationship that only he knows).
</p>
<p>
Shortly after his decision, he remembered that he has to tell an estimate of the cost required to build to the financial manager. He unwillingly calculated it, and he returned home after he finished his report. However, you, an able secretary of Mr. Knight, have found that one field is missing in his report: the length of the fence required to surround the building. Fortunately you are also a good programmer, so you have decided to write a program that calculates the length of the fence.
</p>
<p>
To be specific, the form of his building is union of a cylinder and a prism. You may consider the twodimensional projection of the form, i.e. the shape of the building is considered to be union of a circle <i>C</i> and a polygon <i>P</i>. The fence surrounds the outside of the building. The shape of the building may have a hole in it, and the fence is not needed inside the building. An example is shown in the figure below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_artisticArtMuseum">
</center>
<H2>Input</H2>
<p>
The input contains one test case.
</p>
<p>
A test case has the following format:
</p>
<p>
<i>R</i><br/>
<i>N</i> <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<sub>n</sub> y<sub>n</sub></i><br/>
</p>
<p>
<i>R</i> is an integer that indicates the radius of <i>C</i> (1 ≤ R ≤ 1000), whose center is located at the origin. <i>N</i> is the number of vertices of <i>P</i>, and (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) is the coordinate of the <i>i</i>-th vertex of <i>P</i>. <i>N</i>, <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> are all integers satisfying the following conditions: 3 ≤ <i>N</i> ≤ 100,|<i>x<sub>i</sub></i>| ≤ 1000 and |<i>y<sub>i</sub></i>| ≤ 1000.
</p>
<p>
You may assume that <i>C</i> and <i>P</i> have one or more intersections.
</p>
<H2>Output</H2>
<!--
<p>
Print the length of the fence required to surround the building. The output value should have four fractional digits, and may not contain an absolute error more than 10<sup>-4</sup>.
</p>
-->
<p>
Print the length of the fence required to surround the building. The output value should be in a decimal fraction may not contain an absolute error more than 10<sup>-4</sup>.
</p>
<p>
It is guaranteed that the answer does not change by more than 10<sup>-6</sup> when <i>R</i> is changed by up to 10<sup>-9</sup>.
</p>
<H2>Sample Input 1</H2>
<pre>
2
8 -1 2 1 2 1 -3 2 -3 2 3 -2 3 -2 -3 -1 -3
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
22.6303
</pre>
<br/>
|
p01088 |
<h2>500-yen Saving</h2>
<p>
"500-yen Saving" is one of Japanese famous methods to save money. The
method is quite simple; whenever you receive a 500-yen coin in your
change of shopping, put the coin to your 500-yen saving box.
Typically, you will find more than one million yen in your saving box
in ten years.
</p>
<p>
Some Japanese people are addicted to the 500-yen saving. They try
their best to collect 500-yen coins efficiently by using 1000-yen bills
and some coins effectively in their purchasing. For example, you will give
1320 yen (one 1000-yen bill, three 100-yen coins and two 10-yen coins)
to pay 817 yen, to receive one 500-yen coin (and three 1-yen coins)
in the change.
</p>
<p>
A friend of yours is one of these 500-yen saving addicts. He is
planning a sightseeing trip and wants to visit a number of souvenir
shops along his way. He will visit souvenir shops one by one
according to the trip plan. Every souvenir shop sells only one kind of
souvenir goods, and he has the complete list of their prices. He
wants to collect as many 500-yen coins as possible through buying
at most one souvenir from a shop. On his departure,
he will start with sufficiently many 1000-yen bills and no coins at
all. The order of shops to visit cannot be changed. As far as he can
collect the same number of 500-yen coins, he wants to cut his expenses
as much as possible.
</p>
<p>
Let's say that he is visiting shops with their souvenir prices of 800
yen, 700 yen, 1600 yen, and 600 yen, in this order. He can collect at
most two 500-yen coins spending 2900 yen, the least expenses to collect
two 500-yen coins, in this case. After skipping the first shop, the
way of spending 700-yen at the second shop is by handing over a
1000-yen bill and receiving three 100-yen coins. In the next shop,
handing over one of these 100-yen coins and two 1000-yen bills for
buying a 1600-yen souvenir will make him receive one 500-yen coin. In
almost the same way, he can obtain another 500-yen coin at the last
shop. He can also collect two 500-yen coins buying at the first shop,
but his total expenditure will be at least 3000 yen because he needs
to buy both the 1600-yen and 600-yen souvenirs in this case.
</p>
<p>
You are asked to make a program to help his collecting 500-yen coins
during the trip. Receiving souvenirs' prices listed in the order
of visiting the shops, your program is to find the maximum number of
500-yen coins that he can collect during his trip, and the minimum
expenses needed for that number of 500-yen coins.
</p>
<p>
For shopping, he can use an arbitrary number of 1-yen, 5-yen, 10-yen,
50-yen, and 100-yen coins he has, and arbitrarily many 1000-yen bills.
The shop always returns the exact change, i.e., the difference between
the amount he hands over and the price of the souvenir. The shop has
sufficient stock of coins and the change is always composed of the
smallest possible number of 1-yen, 5-yen, 10-yen, 50-yen, 100-yen, and
500-yen coins and 1000-yen bills. He may use more money than the
price of the souvenir, even if he can put the exact money, to obtain
desired coins as change; buying a souvenir of 1000 yen, he can hand
over one 1000-yen bill and five 100-yen coins and receive a 500-yen
coin. Note that using too many coins does no good; handing over ten
100-yen coins and a 1000-yen bill for a souvenir of 1000 yen, he will
receive a 1000-yen bill as the change, not two 500-yen coins.
</p>
<h3>Input</h3>
<p>
The input consists of at most 50 datasets, each in the following format.
</p>
<blockquote>
<i>n</i> <br>
<i>p</i><sub>1</sub><br>
...<br>
<i>p<sub>n</sub></i> <br>
</blockquote>
<p>
<i>n</i> is the number of souvenir shops, which is a positive integer not
greater than 100.
<i>p<sub>i</sub></i> is the price of the souvenir of the <i>i</i>-th souvenir shop.
<i>p<sub>i</sub></i> is a positive integer not greater than 5000.
</p>
<p>
The end of the input is indicated by a line with a single zero.
</p>
<h3>Output</h3>
<p>
For each dataset, print a line containing two integers <i>c</i> and <i>s</i> separated by a space.
Here, <i>c</i> is the maximum number of 500-yen coins that he can get during his
trip, and <i>s</i> is the minimum expenses that he need to pay to get <i>c</i>
500-yen coins.
</p>
<h3>Sample Input</h3>
<pre>4
800
700
1600
600
4
300
700
1600
600
4
300
700
1600
650
3
1000
2000
500
3
250
250
1000
4
1251
667
876
299
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>2 2900
3 2500
3 3250
1 500
3 1500
3 2217
</pre>
|
p00733 |
<h1><font color="#000000">Problem F: </font>Dr. Podboq or: How We Became Asymmetric</h1>
<p>
After long studying how embryos of organisms become asymmetric during
their development, Dr. Podboq, a famous biologist, has reached his new
hypothesis. Dr. Podboq is now preparing a poster for the coming
academic conference, which shows a tree representing the development
process of an embryo through repeated cell divisions starting from one
cell. Your job is to write a program that transforms given trees into
forms satisfying some conditions so that it is easier for the audience
to get the idea.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A tree representing the process of cell divisions has a form described
below.
</p>
<ul>
<li>The starting cell is represented by a circle placed at the top.</li>
<li>Each cell either terminates the division activity or divides into
two cells. Therefore, from each circle representing a cell, there are
either no branch downward, or two branches down to its
two child cells.</li>
</ul>
<p>
Below is an example of such a tree.
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-1" border="1" /><br />
<!-- begin en only -->
Figure F-1: A tree representing a process of cell divisions
<!-- end en only -->
</center>
</p>
<!-- begin en only -->
<p>
According to Dr. Podboq's hypothesis, we can determine which cells
have stronger or weaker asymmetricity by looking at the structure of
this tree representation. First, his hypothesis defines "left-right
similarity" of cells as follows:
</p>
<ol>
<li>The left-right similarity of a cell that did not divide further is
0.</li> <li>For a cell that did divide further, we collect the partial
trees starting from its child or descendant cells, and count how
many kinds of structures they have. Then, the left-right similarity of
the cell is defined to be the ratio of the number of structures
that appear both in
the right child side and the left child side. We regard two trees
have the same structure if we can make them have exactly the same shape by
interchanging two child cells of arbitrary cells.</li>
</ol>
<p>
For example, suppose we have a tree shown below:
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-2" border="1" /><br />
<!-- begin en only -->
Figure F-2: An example tree
<!-- end en only -->
</center>
</p>
<!-- begin en only -->
<p>
The left-right similarity of the cell A is computed as follows.
First, within the descendants of the cell B, which is the left child
cell of A, the following three kinds of structures appear. Notice that
the rightmost structure appears three times, but when we count the number
of structures, we count it only once.
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-3" border="1" /><br />
<!-- begin en only -->
Figure F-3: Structures appearing within the descendants of the cell B
<!-- end en only -->
</center>
</p>
<!-- begin en only -->
<p>
On the other hand, within the descendants of the cell C, which is the
right child cell of A, the following four kinds of structures appear.
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-4" border="1" /><br />
<!-- begin en only -->
Figure F-4: Structures appearing within the descendants of the cell C
<!-- end en only -->
</center>
</p>
<!-- begin en only -->
<p>
Among them, the first, second, and third ones within the B side are
regarded as the same structure as the second, third, and fourth ones
within the C side, respectively. Therefore, there are four structures
in total, and three among them are common to the left side and the
right side, which means the left-right similarity of A is 3/4.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Given the left-right similarity of each cell, Dr. Podboq's hypothesis
says we can determine which of the cells <i>X</i> and <i>Y</i> has
stronger asymmetricity by the following rules.
</p>
<ol>
<li>If <i>X</i> and <i>Y</i> have different left-right similarities, the
one with lower left-right similarity has stronger asymmetricity.
<li>Otherwise, if neither <i>X</i> nor <i>Y</i> has child cells, they
have completely equal asymmetricity.
<li>Otherwise, both <i>X</i> and <i>Y</i> must have two child cells. In this case,
we compare the child cell of <i>X</i> with stronger (or equal)
asymmetricity (than the other child cell of <i>X</i>) and the child
cell of <i>Y</i> with stronger (or equal) asymmetricity (than the other child cell
of <i>Y</i>), and the one having a child with stronger asymmetricity
has stronger asymmetricity.</li>
<li>If we still have a tie, we compare the other child cells of <i>X</i>
and <i>Y</i> with weaker (or equal) asymmetricity, and the one having a child with
stronger asymmetricity has stronger asymmetricity.</li>
<li>If we still have a tie again, <i>X</i> and <i>Y</i> have
completely equal asymmetricity.</li>
</ol>
<p>
When we compare child cells in some rules above, we recursively apply
this rule set.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Now, your job is to write a program that transforms a given tree
representing a process of cell divisions, by interchanging two child cells
of arbitrary cells, into a tree where the following conditions are
satisfied.
</p>
<ol>
<li>For every cell <i>X</i> which is the starting cell of the given
tree or a left child cell of some parent cell, if <i>X</i> has two
child cells, the one at left has stronger (or equal) asymmetricity than the one
at right.</li>
<li>For every cell <i>X</i> which is a right child cell of some parent
cell, if <i>X</i> has two child cells, the one at right has stronger (or equal)
asymmetricity than the one at left.</li>
</ol>
<p>
In case two child cells have equal asymmetricity, their order is
arbitrary because either order would results in trees of the same shape.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
For example, suppose we are given the tree in Figure F-2. First we
compare B and C, and because B has lower left-right similarity, which means stronger asymmetricity, we
keep B at left and C at right. Next, because B is the left child cell
of A, we compare two child cells of B, and the one with stronger
asymmetricity is positioned at left. On the other hand, because C is
the right child cell of A, we compare two child cells of C, and the one
with stronger asymmetricity is positioned at right. We examine the
other cells in the same way, and the tree is finally transformed into
the tree shown below.
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-5" border="1" /><br />
<!-- begin en only -->
Figure F-5: The example tree after the transformation
<!-- end en only -->
</center>
</p>
<!-- begin en only -->
<p>
Please be warned that the only operation allowed in the transformation
of a tree is to interchange two child cells of some parent cell. For
example, you are not allowed to transform the tree in Figure F-2 into the tree
below.
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_f-6" border="1" /><br />
<!-- begin en only -->
Figure F-6: An example of disallowed transformation
<!-- end en only -->
</center>
</p>
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of <i>n</i> lines (1≤<i>n</i>≤100) describing
<i>n</i> trees followed by a line only containing a single zero which
represents the end of the input. Each tree includes at least 1 and at
most 127 cells. Below is an example of a tree description.
</p>
<!-- end en only -->
<blockquote>
<tt>((x (x x)) x)</tt>
</blockquote>
<!-- begin en only -->
<p>
This description represents the tree shown in Figure F-1. More
formally, the description of a tree is in either of the following two formats.
</p>
<blockquote>
"<tt>(</tt>" <description of a tree starting at the left child> <single space> <description of a tree starting at the right child> ")"
</blockquote>
<p>or</p>
<blockquote>
"<tt>x</tt>"
</blockquote>
<p>
The former is the description of a tree whose starting cell has two
child cells, and the latter is the description of a tree whose starting
cell has no child cell.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each tree given in the input, print a line describing the result
of the tree transformation. In the output, trees should be described in
the same formats as the input, and the tree descriptions must
appear in the same order as the input. Each line should have no extra
character other than one tree description.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
(((x x) x) ((x x) (x (x x))))
(((x x) (x x)) ((x x) ((x x) (x x))))
(((x x) ((x x) x)) (((x (x x)) x) (x x)))
(((x x) x) ((x x) (((((x x) x) x) x) x)))
(((x x) x) ((x (x x)) (x (x x))))
((((x (x x)) x) (x ((x x) x))) ((x (x x)) (x x)))
((((x x) x) ((x x) (x (x x)))) (((x x) (x x)) ((x x) ((x x) (x x)))))
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
((x (x x)) ((x x) ((x x) x)))
(((x x) ((x x) (x x))) ((x x) (x x)))
(((x ((x x) x)) (x x)) ((x x) ((x x) x)))
(((x ((x ((x x) x)) x)) (x x)) ((x x) x))
((x (x x)) ((x (x x)) ((x x) x)))
(((x (x x)) (x x)) ((x ((x x) x)) ((x (x x)) x)))
(((x (x x)) ((x x) ((x x) x))) (((x x) (x x)) (((x x) (x x)) (x x))))
</pre>
|
p01821 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem D:
Identity Function</h2>
<p>
You are given an integer $N$, which is greater than 1.<br>
Consider the following functions:
</p>
<ul>
<li> $f(a) = a^N$ mod $N$ </li>
<li> $F_1(a) = f(a)$</li>
<li> $F_{k+1}(a) = F_k(f(a))$ $(k = 1,2,3,...)$</li>
</ul>
<p>
Note that we use mod to represent the integer modulo operation. For a non-negative integer $x$
and a positive integer $y$, $x$ mod $y$ is the remainder of $x$ divided by $y$.
</p>
<p>
Output the minimum positive integer $k$ such that $F_k(a) = a$ for all positive integers $a$ less than
$N$. If no such $k$ exists, output -1.
</p>
<h3>Input</h3>
<p>
The input consists of a single line that contains an integer $N$ ($2 \leq N \leq 10^9$), whose meaning is
described in the problem statement.
</p>
<h3>Output</h3>
<p>
Output the minimum positive integer $k$ such that $F_k(a) = a$ for all positive integers $a$ less than
$N$, or -1 if no such $k$ exists.
</p>
<h3>Sample Input</h3>
<pre>
3
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
</pre>
<h3>Sample Input</h3>
<pre>
4
</pre>
<h3>Output for the Sample Input</h3>
<pre>
-1
</pre>
<h3>Sample Input</h3>
<pre>
15
</pre>
<h3>Output for the Sample Input</h3>
<pre>
2
</pre>
|
p00363 | <!--<H1>Letâs Make a Flag</H1>-->
<h1>Flag</h1>
<p>
AHK Education, the educational program section of Aizu Broadcasting Cooperation, broadcasts a childrenâs workshop program called "Let's Play and Make." Todayâs theme is "Make your own flag." A child writes his first initial in the center of their rectangular flag.
</p>
<p>
Given the flag size and the initial letter to be placed in the center of it, write a program to draw the flag as shown in the figure below.
</p>
<pre>
+-------+
|.......|
|...A...|
|.......|
+-------+
</pre>
<p>
The figure has "A" in the center of a flag with size 9 (horizontal) × 5 (vertical).
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>W</var> <var>H</var> <var>c</var>
</pre>
<p>
The input line provides the flag dimensions <var>W</var> (width) and <var>H</var> (height) (3 ≤ <var>W,H</var> ≤ 21), and the initial letter <var>c</var>. Both <var>W</var> and <var>H</var> are odd numbers, and <var>c</var> is a capital letter.
</p>
<h2>Output</h2>
<p>
Draw the flag of specified size with the initial in its center using the following characters: "<span>+</span>" for the four corners of the flag, "<span>-</span>" for horizontal lines, "<span>|</span>" for vertical lines, and "<span>.</span>" for the background (except for the initial in the center).
</p>
<h2>Sample Input 1</h2>
<pre>
3 3 B
</pre>
<h2>Sample Output 1</h2>
<pre>
+-+
|B|
+-+
</pre>
<h2>Sample Input 2</h2>
<pre>
11 7 Z
</pre>
<h2>Sample Output 2</h2>
<pre>
+---------+
|.........|
|.........|
|....Z....|
|.........|
|.........|
+---------+
</pre>
|
p00699 |
<H1>
Nets of Dice
</H1>
<P>
In mathematics, some plain words have special meanings.
The word "<I>net</I>" is one of such technical terms.
In mathematics, the word "<I>net</I>" is sometimes used to
mean a plane shape
which can be folded into some solid shape.
</P>
<P>
The following are a solid shape (Figure 1) and one of its <I>net</I> (Figure 2).
</P>
<TABLE>
<TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_prism"></TD><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netprism"></TD></TR>
<TR><TD ALIGN=center>Figure 1: a prism</TD><TD ALIGN=center>Figure 2: a net of a prism</TD></TR>
</TABLE>
<P>
Nets corresponding to a solid shape are not unique.
For example, Figure 3 shows three of the nets of a cube.
</P>
<TABLE>
<TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netcube"></TD></TR>
<TR><TD ALIGN=center>Figure 3: examples of nets of a cube</TD></TR>
</TABLE>
<P>
In this problem, we consider nets of dice.
The definition of a die is as follows.
<OL>
<LI> A die is a cube, each face marked with a number between one and six.
<LI> Numbers on faces of a die are different from each other.
<LI> The sum of two numbers on the opposite faces is always 7.
</OL>
<p>
Usually, a die is used in pair with another die.
The plural form of the word "die" is "dice".
</P>
<P>
Some examples of proper nets of dice are shown in Figure 4,
and those of improper ones are shown in Figure 5.
</P>
<TABLE>
<TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netdice2"></TD></TR>
<TR><TD ALIGN=center>Figure 4: examples of proper nets of dice</TD></TR>
</TABLE>
<TABLE>
<TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_netdice3"></TD></TR>
<TR><TD ALIGN=center>Figure 5: examples of improper nets</TD></TR>
</TABLE>
<P>
The reasons why each example in Figure 5 is improper are as follows.
<DL>
<DD>(a) The sum of two numbers on the opposite faces is not always 7.
<DD>(b) Some faces are marked with the same number.
<DD>(c) This is not a net of a cube. Some faces overlap each other.
<DD>(d) This is not a net of a cube.
Some faces overlap each other and one face of a cube is not covered.
<DD>(e) This is not a net of a cube.
The plane shape is cut off into two parts.
The face marked with '2' is isolated.
<DD>(f) This is not a net of a cube.
The plane shape is cut off into two parts.
<DD>(g) There is an extra face marked with '5'.
</DL>
</P>
<P>
Notice that there are two kinds of dice.
For example, the solid shapes formed from
the first two examples in Figure 4
are mirror images of each other.
</P>
<P>
Any net of a die can be expressed on a sheet of 5x5 mesh like the one in Figure 6.
In the figure, gray squares are the parts to be cut off.
When we represent the sheet of mesh by numbers as in Figure 7,
squares cut off are marked with zeros.
</P>
<TABLE>
<TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_mesh"></TD><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_matrix"></TD></TR>
<TR><TD ALIGN=center>Figure 6: 5x5 mesh</TD><TD ALIGN=center>Figure 7: representation by numbers</TD></TR>
</TABLE>
<P>
Your job is to write a program which tells
the proper nets of a die from the improper ones automatically.
</P>
<H2>Input</H2>
<P>
The input consists of multiple sheets of 5x5 mesh.
</P>
<TABLE>
<TR><TD><I>N</I></TD></TR>
<TR><TD><I>Mesh</I><SUB>0</SUB></TD></TR>
<TR><TD><I>Mesh</I><SUB>1</SUB></TD></TR>
<TR><TD>...</TD></TR>
<TR><TD><I>Mesh</I><SUB><I>N</I>-1</SUB></TD></TR>
</TABLE>
<P>
<I>N</I> is the number of sheets of mesh.
Each <I>Mesh<SUB>i</SUB></I> gives a sheet of mesh
on which a net of a die is expressed.
<I>Mesh<SUB>i</SUB></I> is in the following format.
</P>
<TABLE>
<TR>
<TD><I>F</I><SUB>00</SUB></TD>
<TD><I>F</I><SUB>01</SUB></TD>
<TD><I>F</I><SUB>02</SUB></TD>
<TD><I>F</I><SUB>03</SUB></TD>
<TD><I>F</I><SUB>04</SUB></TD>
</TR>
<TR>
<TD><I>F</I><SUB>10</SUB></TD>
<TD><I>F</I><SUB>11</SUB></TD>
<TD><I>F</I><SUB>12</SUB></TD>
<TD><I>F</I><SUB>13</SUB></TD>
<TD><I>F</I><SUB>14</SUB></TD>
</TR>
<TR>
<TD><I>F</I><SUB>20</SUB></TD>
<TD><I>F</I><SUB>21</SUB></TD>
<TD><I>F</I><SUB>22</SUB></TD>
<TD><I>F</I><SUB>23</SUB></TD>
<TD><I>F</I><SUB>24</SUB></TD>
</TR>
<TR>
<TD><I>F</I><SUB>30</SUB></TD>
<TD><I>F</I><SUB>31</SUB></TD>
<TD><I>F</I><SUB>32</SUB></TD>
<TD><I>F</I><SUB>33</SUB></TD>
<TD><I>F</I><SUB>34</SUB></TD>
</TR>
<TR>
<TD><I>F</I><SUB>40</SUB></TD>
<TD><I>F</I><SUB>41</SUB></TD>
<TD><I>F</I><SUB>42</SUB></TD>
<TD><I>F</I><SUB>43</SUB></TD>
<TD><I>F</I><SUB>44</SUB></TD>
</TR>
</TABLE>
<P>
Each <I>F<SUB>ij</SUB></I> is an integer between 0 and 6.
They are separated by a space character.
</P>
<H2>Output</H2>
<p>
For each <I>Mesh<SUB>i</SUB></I>,
the truth value, <I>true</I> or <I>false</I>,
should be output, each in a separate line.
When the net of a die expressed on the <I>Mesh<SUB>i</SUB></I> is proper,
output "true".
Otherwise, output "false".
</p>
<H2>Sample Input</H2>
<PRE>
6
0 0 0 0 0
0 0 0 0 6
0 2 4 5 3
0 0 1 0 0
0 0 0 0 0
0 0 3 0 0
0 0 2 0 0
0 0 4 1 0
0 0 0 5 0
0 0 0 6 0
0 0 0 3 0
0 0 2 5 0
0 4 1 0 0
0 0 6 0 0
0 0 0 0 0
0 6 2 0 0
0 0 4 0 0
0 1 5 0 0
0 0 3 0 0
0 0 0 0 0
0 0 0 0 6
0 2 4 5 3
0 0 1 0 0
0 0 0 0 0
0 0 0 1 0
0 0 0 0 6
0 2 4 5 3
0 0 0 0 0
0 0 0 0 0
0 0 0 1 0
</PRE>
<H2>Output for the Sample Input</H2>
<PRE>
true
true
false
false
false
false
</PRE>
|
p00676 |
<h1>KND is So Sexy</h1>
<h2>Problem</h2>
<p>KNDåã¯äŒæŽ¥å€§åŠã«åšç±ããåŠçããã°ã©ãã§ããã圌ã®èžå
ã¯ãšãŠãã»ã¯ã·ãŒãªããšã§ç¥ãããŠããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day3_A">
</center>
<br/>
<p>
ç°¡åã®ããã«èžå
ããèŠããèã®éšåãå³ã«ããäºç蟺äžè§åœ¢ABCã§è¡šãããããæã«ã¯ããã¿ãçããŠãããããé·ããçãã2蟺AC,BC(ãããã®é·ãã<var>l</var>ãšãã)ã«ã¯å®éã«ã¯ããã«é·ã<var>x</var>åäœè£ããããã¯ã ããéšåã®é¢ç©ãå¢ããããããããã åãåŒã£åŒµãããšã§æ°ãã«ãµãã€ã®äžè§åœ¢ADC,BECãäœãããšã«ããããç¹D,Eã¯äžè§åœ¢ABCã®å€åŽã«ååšããããã®æ°ãããµãã€ã®äžè§åœ¢ã¯ããã¿ã«ãã£ãŠçãããã®ã§ã蟺BEãšèŸºECã®é·ãã®åããã³èŸºADãšèŸºDCã®é·ãã®åã¯<var>l</var>+<var>x</var>ã§ãªããã°ãªããªããããªãã¯ããã3ã€ã®äžè§åœ¢ã®é¢ç©ã®å<var>M</var>ãæå€§ã«ãªãããã«ç¹D,Eãæ±ºãããKNDåã®é£äººã§ããããªãã¯åœŒã®èžå
ãã©ãçšã»ã¯ã·ãŒãªã®ãã調ã¹ãããã«ã<var>a</var>,<var>l</var>,<var>x</var>ãå
¥åãšããŠæããã®ããèã®æå€§ã®é¢ç©(<var>M</var>)ãèšç®ããããã°ã©ã ãäœæããããšã«ããã</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã
ã²ãšã€ã®ãã¹ãã±ãŒã¹ã¯ä»¥äžã®åœ¢åŒã§äžããããã
å
¥åã®çµãããEOFã§ç€ºãã
</p>
<pre>
a l x
</pre>
<p>
ããã§ã
</p>
<ul>
<li><var>a</var>:äžè§åœ¢ABCã®èŸºABã®é·ã</li>
<li><var>l</var>:äžè§åœ¢ABCã®2蟺AC,BCã®é·ã</li>
<li><var>x</var>:2蟺AC,BCã«ããããã¿</li>
</ul>
<p>
ã§ããã</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>å
¥åã¯ãã¹ãп޿°ã</li>
<li>1 ≤ <var>a</var> ≤ 1000</li>
<li>1 ≤ <var>l</var> ≤ 1000</li>
<li>1 ≤ <var>x</var> ≤ 1000</li>
</ul>
<h2>Output</h2>
<p>åãã¹ãã±ãŒã¹ã«ã€ãæå€§ã®é¢ç©ã1è¡ã«åºåããããã®å€ã¯ãžã£ããžåºåã®å€ãš10<sup>-5</sup>ãã倧ããå·®ãæã£ãŠã¯ãªããªãã</p>
<h2>Sample Input</h2>
<pre>
2 2 1
2 3 1
3 2 3
2 3 5
</pre>
<h2>Sample Output</h2>
<pre>
3.9681187851
6.7970540913
6.5668891783
13.9527248554
</pre>
<!-- 2012/07/09/15:19:55 --> |
p03959 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range.
The mountain range consists of <var>N</var> mountains, extending from west to east in a straight line as Mt. <var>1</var>, Mt. <var>2</var>, ..., Mt. <var>N</var>.
Mr. Takahashi traversed the range from the west and Mr. Aoki from the east. </p>
<p>The height of Mt. <var>i</var> is <var>h_i</var>, but they have forgotten the value of each <var>h_i</var>.
Instead, for each <var>i</var> (<var>1 †i †N</var>), they recorded the maximum height of the mountains climbed up to the time they reached the peak of Mt. <var>i</var> (including Mt. <var>i</var>).
Mr. Takahashi's record is <var>T_i</var> and Mr. Aoki's record is <var>A_i</var>. </p>
<p>We know that the height of each mountain <var>h_i</var> is a positive integer.
Compute the number of the possible sequences of the mountains' heights, modulo <var>10^9 + 7</var>.</p>
<p>Note that the records may be incorrect and thus there may be no possible sequence of the mountains' heights.
In such a case, output <var>0</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^5</var></li>
<li><var>1 †T_i †10^9</var></li>
<li><var>1 †A_i †10^9</var></li>
<li><var>T_i †T_{i+1}</var> (<var>1 †i †N - 1</var>)</li>
<li><var>A_i ⥠A_{i+1}</var> (<var>1 †i †N - 1</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>T_1</var> <var>T_2</var> <var>...</var> <var>T_N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible sequences of the mountains' heights, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 3 3 3 3
3 3 2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The possible sequences of the mountains' heights are:</p>
<ul>
<li><var>1, 3, 2, 2, 2</var> </li>
<li><var>1, 3, 2, 1, 2</var> </li>
<li><var>1, 3, 1, 2, 2</var> </li>
<li><var>1, 3, 1, 1, 2</var> </li>
</ul>
<p>for a total of four sequences.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 1 1 2 2
3 2 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The records are contradictory, since Mr. Takahashi recorded <var>2</var> as the highest peak after climbing all the mountains but Mr. Aoki recorded <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>884111967
</pre>
<p>Don't forget to compute the number modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
17
17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1
</pre>
<p>Some mountain ranges consist of only one mountain.</p></section>
</div>
</span> |
p01964 |
<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>
Revenge of the Endless BFS
</H1>
<p>
Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on a <i>directed</i> graph. An example of pseudo code of BFS is as follows:
</p>
<pre>
1: $current \leftarrow \{start\_vertex\}$
2: $visited \leftarrow current$
3: while $visited \ne$ the set of all the vertices
4: $found \leftarrow \{\}$
5: for $u$ in $current$
6: for each $v$ such that there is an edge from $u$ to $v$
7: $found \leftarrow found \cup \{v\}$
8: $current \leftarrow found \setminus visited$
9: $visited \leftarrow visited \cup found$
</pre>
<p>
However, Mr. Endo apparently forgot to manage visited vertices in his code. More precisely, he wrote the following code:
</p>
<pre>
1: $current \leftarrow \{start\_vertex\}$
2: while $current \ne$ the set of all the vertices
3: $found \leftarrow \{\}$
4: for $u$ in $current$
5: for each $v$ such that there is an edge from $u$ to $v$
6: $found \leftarrow found \cup \{v\}$
7: $current \leftarrow found$
</pre>
<p>
You may notice that for some graphs, Mr. Endo's program will not stop because it keeps running infinitely. Notice that it does not necessarily mean the program cannot explore all the vertices within finite steps. Your task here is to make a program that determines whether Mr. Endo's program will stop within finite steps for a given directed graph in order to point out the bug to him. Also, calculate the minimum number of loop iterations required for the program to stop if it is finite. Since the answer might be huge, thus print the answer modulo $10^9 +7$, which is a prime number.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$ $M$
$u_1$ $v_1$
:
$u_M$ $v_M$
</pre>
<p>
The first line consists of two integers $N$ ($2 \leq N \leq 500$) and $M$ ($1 \leq M \leq 200,000$), where $N$ is the number of vertices and $M$ is the number of edges in a given directed graph, respectively. The $i$-th line of the following $M$ lines consists of two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq N$), which means there is an edge from $u_i$ to $v_i$ in the given graph. The vertex $1$ is the start vertex, i.e. $start\_vertex$ in the pseudo codes. You can assume that the given graph also meets the following conditions.
</p>
<ul>
<li>The graph has no self-loop, i.e., $u_i \ne v_i$ for all $1 \leq i \leq M$.</li>
<li>The graph has no multi-edge, i.e., $(u_i, v_i) \le (u_j, v_j)$ for all $1 \leq i < j \leq M$.</li>
<li>For each vertex $v$, there is at least one path from the start vertex $1$ to $v$.</li>
</ul>
<H2>Output</H2>
<p>
If Mr. Endo's wrong BFS code cannot stop within finite steps for the given input directed graph, print '-1' in a line. Otherwise, print the minimum number of loop iterations required to stop modulo $10^9+7$.
</p>
<H2>Sample Input 1</H2>
<pre>
4 4
1 2
2 3
3 4
4 1
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
-1
</pre>
<H2>Sample Input 2</H2>
<pre>
4 5
1 2
2 3
3 4
4 1
1 3
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
7
</pre>
<H2>Sample Input 3</H2>
<pre>
5 13
4 2
2 4
1 2
5 4
5 1
2 1
5 3
4 3
1 5
4 5
2 3
5 2
1 3
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
3
</pre>
|
p00226 |
<H1>ãããã¢ã³ããããŒ</H1>
<p>
倪éåãšè±åããã¯ãããã¢ã³ããããŒã§éã¶ããšã«ããŸããããããã¢ã³ããããŒã®ã«ãŒã«ã¯ã以äžã®éãã§ãã
</p>
<ul>
<li> åºé¡è
ãšåçè
ã«åãããŠè¡ãã</li>
<li> åºé¡è
ã¯ãéè€ããæ°ãå«ãŸãªã 4 æ¡ã®æ°å(æ£è§£)ãæ±ºããã</li>
<li> åçè
ã¯ããã® 4 æ¡ã®æ°å(åç)ãèšãåœãŠãã</li>
<li> åçã«å¯ŸããŠãåºé¡è
ã¯ããããšãããŒã®æ°ã§ãã³ããäžããã</li>
<li> åçãšæ£è§£ãæ¯ã¹ãŠãæ°ãšæ¡äœçœ®ã®äž¡æ¹ãåãã§ããããšãããããšåŒã³ãæ°ã ããåãã§æ¡äœçœ®ãç°ãªãããšããããŒãšåŒã¶ãããšãã°ãæ£è§£ã 1234 ã§ãåçã 1354 ãªããåºé¡è
ã¯ã2 ãããã1 ãããŒããšãããã³ããäžããæ£è§£ãŸã§ãããç¹°ãè¿ãã</li>
<li> åºé¡è
ãšåçè
ã¯äº€ä»£ããŠã²ãŒã ãè¡ããããå°ãªãåçã§æ£è§£ãèšãåœãŠãæ¹ãåã¡ãšããã</li>
</ul>
<p>
倪éåãšè±åããã¯ããããã®æ°ãšãããŒã®æ°ããã®éœåºŠå€æããããšãå°ãé¢åã«æããŠããããã§ãããããªäºäººã®ããã«ããããã®æ°ãšãããŒã®æ°ãå³åº§ã«åããããã°ã©ã ãäœæããŠãããŸãããã
</p>
<p>
æ£è§£ <var>r</var> ãšåç <var>a</var> ãå
¥åãšãããããã®æ°ãšãããŒã®æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã<var>r</var>ã<var>a</var> ã¯ãããã 0 ãã 9 ã®æ°å 4 ã€ãããªãæ°åã®åã§ãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ãããšããŠã<var>r</var> ãš <var>a</var> ã空çœåºåãã§ïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 12000 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ããããã®æ°ãšãããŒã®æ°ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
1234 5678
1234 1354
1234 1234
1230 1023
0123 1234
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 0
2 1
4 0
1 3
0 3
</pre>
|
p01067 |
<h1>Circles and Ray</h1>
<h2>Problem</h2>
<p>
2次å
å¹³é¢äžã«ããããäºãã«å
±ééšåããããªã <var>N</var> åã®åãäžããããã
ãŸããåã«ã¯ãããã1ãã <var>N</var> ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã
</p>
<p>
ããªãã¯ã端ç¹ã1çªç®ã®åã®ååšäžã«ãããããªåçŽç·ãä»»æã®æ°ã ãèšçœ®ããããšãã§ããã
ã©ã®åã1æ¬ä»¥äžã®åçŽç·ãšã®å
±ééšåãæã£ãŠããããã«ããããã«ã¯ãæäœäœæ¬ã®åçŽç·ãèšçœ®ããªããã°ãªããªãããæ±ããªããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>r<sub>2</sub></var>
...
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>r<sub>N</sub></var>
</pre>
<p>
1è¡ç®ã«ã1ã€ã®æŽæ° <var>N</var> ãäžããããã
2è¡ç®ããã® <var>N</var> è¡ã®ãã¡ <var>i</var> è¡ç®ã«ã¯ <var>i</var> çªç®ã®åã®x座æšãy座æšãååŸã衚ã3ã€ã®æŽæ° <var>x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub></var> ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>N</var> ≤ 16</li>
<li>-100 ≤ <var>x<sub>i</sub></var> ≤ 100 (1 ≤ <var>i</var> ≤ <var>N</var>)</li>
<li>-100 ≤ <var>y<sub>i</sub></var> ≤ 100 (1 ≤ <var>i</var> ≤ <var>N</var>)</li>
<li>1 ≤ <var>r<sub>i</sub></var> ≤ 100 (1 ≤ <var>i</var> ≤ <var>N</var>)</li>
</ul>
<h2>Output</h2>
<p>
ã©ã®åã1æ¬ä»¥äžã®åçŽç·ãšã®å
±ééšåãæã£ãŠããããã«ããããã«ã¯æäœäœæ¬ã®åçŽç·ãèšçœ®ããªããã°ãªããªãããåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3
0 0 2
3 3 1
6 1 1
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
4
1 2 3
12 2 2
7 6 2
1 9 3
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<h2>Sample Input 3</h2>
<pre>
5
0 0 5
0 10 1
10 0 1
-10 0 1
0 -10 1
</pre>
<h2>Sample Output 3</h2>
<pre>
4
</pre>
|
p01437 |
<H1><font color="#000">Problem A:</font>Infnity Maze</H1>
<p>
Dr. Fukuoka has placed a simple robot in a two-dimensional maze. It moves within the maze and never goes out of the maze as there is no exit.
</p>
<p>
The maze is made up of <i>H</i> × <i>W</i> grid cells as depicted below. The upper side of the maze faces north. Consequently, the right, lower and left sides face east, south and west respectively. Each cell is either empty or wall and has the coordinates of (<i>i</i>, <i>j</i>) where the north-west corner has (1, 1). The row <i>i</i> goes up toward the south and the column <i>j</i> toward the east.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_infinity_maze">
</center>
<p>
The robot moves on empty cells and faces north, east, south or west. It goes forward when there is an empty cell in front, and rotates 90 degrees to the right when it comes in front of a wall cell or on the edge of the maze. It cannot enter the wall cells. It stops right after moving forward by <i>L</i> cells.
</p>
<p>
Your mission is, given the initial position and direction of the robot and the number of steps, to write a program to calculate the final position and direction of the robot.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows.
</p>
<p>
<i>H W L</i><br>
<i>c</i><sub>1,1</sub><i>c</i><sub>1,2</sub>...<i>c</i><sub>1,<i>W</i></sub><br>
.<br>
.<br>
.<br>
<i>c</i><sub><i>H</i>,1</sub><i>c</i><sub><i>H</i>,2</sub>...<i>c</i><sub><i>H</i>,<i>W</i></sub><br>
</p>
<p>
The first line of a dataset contains three integers <i>H</i>, <i>W</i> and <i>L</i> (1 ≤ <i>H</i>, <i>W</i> ≤ 100, 1 ≤ <i>L</i> ≤ 10<sup>18</sup>).
</p>
<p>
Each of the following <i>H</i> lines contains exactly <i>W</i> characters. In the <i>i</i>-th line, the <i>j</i>-th character <i>c<sub>i,j</sub></i> represents a cell at (<i>i</i>, <i>j</i>) of the maze. "<span>.</span>" denotes an empty cell. "<span>#</span>" denotes a wall cell. "<span>N</span>", "<span>E</span>", "<span>S</span>", "<span>W</span>" denote a robot on an empty cell facing north, east, south and west respectively; it indicates the initial position and direction of the robot.
</p>
<p>
You can assume that there is at least one empty cell adjacent to the initial position of the robot.
</p>
<p>
The end of input is indicated by a line with three zeros. This line is not part of any dataset.
</p>
<H2>Output</H2>
<p>
For each dataset, output in a line the final row, column and direction of the robot, separated by a single space. The direction should be one of the following: "<span>N</span>" (north), "<span>E</span>" (east), "<span>S</span>" (south) and "<span>W</span>" (west).
</p>
<p>
No extra spaces or characters are allowed.
</p>
<H2>Sample Input</H2>
<pre>
3 3 10
E..
.#.
...
5 5 19
####.
.....
.#S#.
...#.
#.##.
5 5 6
#.#..
#....
##.#.
#..S.
#....
5 4 35
..##
....
.##.
.#S.
...#
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 3 E
4 5 S
4 4 E
1 1 N
</pre>
|
p00932 |
<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 I:
Sweet War
</h2>
<p>
There are two countries, Imperial Cacao and Principality of Cocoa. Two girls, Alice (the Empress of Cacao) and Brianna (the Princess of Cocoa) are friends and both of them love chocolate very much.
</p>
<p>
One day, Alice found a transparent tube filled with chocolate balls (Figure I.1). The tube has only one opening at its top end. The tube is narrow, and the chocolate balls are put in a line. Chocolate balls are identified by integers 1, 2, . . ., $N$ where $N$ is the number of chocolate balls. Chocolate ball 1 is at the top and is next to the opening of the tube. Chocolate ball 2 is next to chocolate ball 1, . . ., and chocolate ball $N$ is at the bottom end of the tube. The chocolate balls can be only taken out from the opening, and therefore the chocolate balls must be taken out in the increasing order of their numbers.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_I1" width="360"><br>
<p>Figure I.1. Transparent tube filled with chocolate balls</p>
</center>
<p>
Alice visited Brianna to share the tube and eat the chocolate balls together. They looked at the chocolate balls carefully, and estimated that the $nutrition value$ and the $deliciousness$ of chocolate ball $i$ are $r_i$ and $s_i$, respectively. Here, each of the girls wants to maximize the sum of the deliciousness of chocolate balls that she would eat. They are sufficiently wise to resolve this
conflict peacefully, so they have decided to play a game, and eat the chocolate balls according to the rule of the game as follows:
</p>
<ol>
<li> Alice and Brianna have initial energy levels, denoted by nonnegative integers $A$ and $B$, respectively.</li>
<li> Alice and Brianna takes one of the following two actions in turn:
<ul>
<li> <b>Pass</b>: she does not eat any chocolate balls. She gets a little hungry $-$ specifically, her energy level is decreased by 1. She cannot pass when her energy level is 0.</li>
<li><b>Eat</b>: she eats the topmost chocolate ball $-$ let this chocolate ball $i$ (that is, the chocolate ball with the smallest number at that time). Her energy level is increased by $r_i$, the nutrition value of chocolate ball $i$ (and NOT decreased by 1). Of course, chocolate ball $i$ is removed from the tube.
</li>
</ul>
<li> Alice takes her turn first.</li>
<li> The game ends when all chocolate balls are eaten.</li>
</ol>
<p>
You are a member of the staff serving for Empress Alice. Your task is to calculate the sums of deliciousness that each of Alice and Brianna can gain, when both of them play optimally.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The test case is formatted as follows.
<br>
<br>
$N$ $A$ $B$<br>
$r_1$ $s_1$<br>
$r_2$ $s_2$<br>
.<br>
.<br>
.<br>
$r_N$ $s_N$<br><br>
The first line contains three integers, $N$, $A$ and $B$. $N$ represents the number of chocolate balls. $A$ and $B$ represent the initial energy levels of Alice and Brianna, respectively. The following $N$ lines describe the chocolate balls in the tube. The chocolate balls are numbered from 1 to $N$, and each of the lines contains two integers, $r_i$ and $s_i$ for $1 \leq i \leq N$. $r_i$ and $s_i$ represent the nutrition value and the deliciousness of chocolate ball $i$, respectively. The input satisfies
</p>
<ul>
<li> $1 \leq N \leq 150$,</li>
<li> $0 \leq A, B, r_i \leq 10^9$,</li>
<li> $0 \leq s_i$, and</li>
<li> $\sum^N_{i=1} s_i \leq 150$</li>
</ul>
<h3>Output</h3>
<p>
Output two integers that represent the total deliciousness that Alice and Brianna can obtain when they play optimally
</p>
<h3>Sample Input 1</h3>
<pre>2 5 4
5 7
4 8</pre>
<h3>Sample Output 1</h3>
<pre>8 7</pre>
<h3>Sample Input 2</h3>
<pre>3 50 1
49 1
0 10
0 1</pre>
<h3>Sample Output 2</h3>
<pre>10 2</pre>
<h3>Sample Input 3</h3>
<pre>4 3 2
1 5
2 46
92 40
1 31</pre>
<h3>Sample Output 3</h3>
<pre>77 45</pre>
<h3>Sample Input 4</h3>
<pre>5 2 5
56 2
22 73
2 2
1 55
14 18</pre>
<h3>Sample Output 4</h3>
<pre>57 93</pre>
|
p01620 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<!-- begin en only -->
<!--<h3><u>King's Inspection</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>
é»è»ã®é§
ã¯52åãããããããã«å€§æåãå°æåã®ã¢ã«ãã¡ããã1æåã®ååãã€ããŠããïŒéãªã£ãŠããååã¯ãªãïŒã
ãã®é»è»ã®è·¯ç·ã¯ç°ç¶ã«ãªã£ãŠããŠãaã®é§
ã®æ¬¡ã¯bã®é§
ãbã®é§
ã®æ¬¡ã¯cã®é§
ãšé ã«äžŠãã§ããŠzé§
ã®æ¬¡ã¯Aé§
ããã®æ¬¡ã¯Bã®é§
ãšé ã«é²ã¿ãZé§
ã®æ¬¡ã¯aé§
ã«ãªã£ãŠå
ã«æ»ãã
åç·ã§ãããéæ¹åã«é²ãé»è»ã¯èµ°ã£ãŠããªãã
</p>
<p>
ããæ¥ãæ°è瀟ã®èšè
ãçæ§ã蚪ããé§
ã®é çªã®ãªã¹ããæã«å
¥ããã
</p>
<p>
ãdcdkIlkPâŠã
</p>
<p>
æåã«dé§
ã蚪ããæ¬¡ã«cé§
ãæ¬¡ã«dé§
ãšé ã«èšªããŠãããšãããããã§ãåãåœã®çæ§ã远跡åæã§ãããšæã£ãç¢å
ãæãã¬ããšãçºèŠããããã®ãªã¹ãã¯ããã察çã®ããæå·åãããŠããã®ã ïŒèšè
ã®ä»²éãããã®æå·ãè§£ãéµãå
¥æãããšãããæ©éãã®èšè
ã¯éµãè²ã£ãŠãããããªã¹ãã®ä¿®æ£ã«ãšãããã£ããéµã¯ããã€ãã®æ°åã®åã§æ§æãããŠããã
</p>
<p>
ã3 1 4 5 3ã
</p>
<p>
ãã®æ°åã®æå³ãããšããã¯ãã¯ããã«èšªããé§
ã¯ããªã¹ãã«æžããŠããé§
ã®3ã€åã®é§
ã
2çªç®ã«èšªããé§
ã¯ãªã¹ãã®2çªç®ã®é§
ã®åã®é§
ããšãã颚ã«ãå®é蚪ããé§
ããªã¹ãã®é§
ã®äœé§
åãã瀺ããŠããã
èšè
ã¯ä¿®æ£ã«åãããã£ããã蚪ããé§
ã®ãªã¹ãã®æ°ããããéµã®æ°ã®æ¹ãå°ãããã©ãããã®ããšä»²éã«èãããšãããæåŸã®éµãã€ãã£ããããŸãã¯ããã®éµããé ã«äœ¿ã£ãŠããã°ãããããã
ãããŠèšè
ã¯ãããããªã¹ããä¿®æ£ããããšãã§ããã
</p>
<p>
ãabZfFijLâŠã
</p>
<p>
ããã§ããæãç©ã¯ç¡ãã ãããããæã£ãç¢å
ãããã«æãã¬äºæ
ãçºèŠããã
åãçæ§ã¯äœæ¥éãæ»åšããããã«ããããã®æ¥çšããšã«ãªã¹ããšéµãååšããã®ã ã
èšè
ã¯äžåžããããã¹ãŠã®ãªã¹ãã埩å·ããããã«æç€ºãããããéãéã ãã«ã圌äžäººã§ã¯çµãããªãã
ããªãã®ä»äºã¯åœŒãå©ãããã®ãªã¹ãã®åŸ©å·ãèªåã§è¡ãããã°ã©ã ãäœæããããšã§ããã
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æããããåããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããã
</p>
<pre>
<var>n</var>
<var>k1</var> <var>k2...</var> <var>kn</var>
<var>s</var>
</pre>
<p>
n ã¯éµã®æ°ãè¡šãæŽæ°ã§ããã1ä»¥äž 100 以äžãšä»®å®ããŠè¯ãã
ç¶ãè¡ã«ã¯éµã®ãªã¹ããèšèŒãããŠãããk<sub>i</sub>ã¯içªç®ã®éµã瀺ãã1以äž52以äžãšä»®å®ããŠè¯ãã
sã¯ã¢ã«ãã¡ããã倧æåã»å°æåãããªãæååã§ã蚪ããé§
ã®ãªã¹ãã瀺ãã1æå以äž100æå以äžã§ãããšä»®å®ããŠè¯ãã
n=0 ã¯å
¥åã®çµããã瀺ããããã¯ããŒã¿ã»ããã«ã¯å«ããªãã
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«å¯Ÿãã埩å·ããããªã¹ããå1è¡ã«åºåããã
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
2
1 2
bdd
3
3 2 1
DDDA
5
3 1 4 5 3
dcdkIlkP
0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
<h3>Output for Sample Input</h3>
<pre>
abc
ABCx
abZfFijL
</pre>
<!-- begin ja only -->
<!-- end ja only -->
|
p01270 |
<h1><font color="#000">Problem D:</font> Restrictive Filesystem</h1>
<p>
ããªãã¯æ°åèšé²åªäœã®éçºããŒã ã«æå±ããããã°ã©ããŒã§ããïŒãã®èšé²åªäœã¯ããŒã¿ã®èªã¿èŸŒã¿åã³æ¶å»ã¯ã©ã³ãã ã¢ã¯ã»ã¹ãå¯èœã§ããïŒäžæ¹ïŒããŒã¿ãæžã蟌ããšãã¯ïŒåžžã«å
é ããé çªã«ã¢ã¯ã»ã¹ããŠããïŒæåã«èŠã€ãã£ã空ãé åã«ããæžã蟌ãããšãã§ããªãïŒ
</p>
<p>
ããªãã¯ãã®èšé²åªäœçšã®ãã¡ã€ã«ã·ã¹ãã ã®æ§ç¯ãå§ããïŒãã®ãã¡ã€ã«ã·ã¹ãã ã§ã¯ïŒèšé²åªäœã®å¶éããïŒããŒã¿ã¯å
é ã®ç©ºãé åããé ã«æžã蟌ãŸããïŒæžã蟌ã¿ã®éäžã§å¥ã®ããŒã¿ãååšããé åã«è³ã£ãå Žåã¯ïŒæ®ãã®ããŒã¿ããã®åŸãã®ç©ºãé åããæžã蟌ãã§ããïŒ
</p>
<p>
ããŒã¿ã®æžã蟌ã¿ã¯ã»ã¯ã¿ãšåŒã°ããåäœã§è¡ãããïŒã»ã¯ã¿ã«ã¯ 0 ããå§ãŸãçªå·ãå²ãåœãŠãããŠããïŒãã®çªå·ã¯èšæ¶åªäœäžã®ç©ççãªäœçœ®ãæãïŒã»ã¯ã¿çªå·ã¯ïŒèšæ¶åªäœã®å
é ããåŸæ¹ã«åãã£ãŠé ã« 0ïŒ1ïŒ2ïŒ3ïŒâŠ ãšå²ãåœãŠãããŠããïŒ
</p>
<p>
ãã¡ã€ã«ã·ã¹ãã ã«ã¯ïŒæžã蟌ã¿ïŒåé€ïŒã»ã¯ã¿ã®åç
§ãšãã 3 ã€ã®ã³ãã³ããååšããïŒ
</p>
<p>
ããªãã®ä»äºã¯ãã®ãã¡ã€ã«ã·ã¹ãã ã®æåãåçŸããäžã§ïŒåç
§ã³ãã³ããå®è¡ããããšã察象ã»ã¯ã¿ã«ã¯ã©ã®ãã¡ã€ã«ãé
眮ãããŠãããåºåããããã°ã©ã ãæžãããšã§ããïŒãªãïŒåæç¶æ
ã§ã¯èšé²åªäœã«ã¯äœãæžã蟌ãŸããŠããªãïŒ
</p>
<p>
äŸãã°ïŒSample Input ã®æåã®äŸãèŠãŠã¿ããïŒæåã®åœä»€ã§ã¯ 0 ãšããèå¥åãæã£ããµã€ãºã 2 ã§ãããã¡ã€ã«ãæžã蟌ãïŒåæç¶æ
ã§ã¯èšé²åªäœã«ã¯äœãæžã蟌ãŸããŠããªãïŒããªãã¡å
šãŠã®ã»ã¯ã¿ã空ãé åã§ããããïŒå
é ã«ãã 2 ã€ã®ã»ã¯ã¿ïŒããªãã¡ 0 çªç®ã®ã»ã¯ã¿ãš 1 çªç®ã®ã»ã¯ã¿ã«æžã蟌ã¿ãè¡ãããïŒãããã£ãŠïŒæžã蟌ã¿ã®åŸã®èšæ¶åªäœã¯æ¬¡ã®ããã«ãªã£ãŠããïŒ
</p>
<pre>
ïŒ ïŒ ç©º 空 空 空 空 空 âŠ
</pre>
<p>
2 çªç®ã®åœä»€ã«ãã£ãŠïŒ1 ãšããèå¥åãæã€ãã¡ã€ã«ã 2 çªç®ãš 3 çªç®ã®ã»ã¯ã¿ã«æžã蟌ãŸããïŒãã®åŸã®èšæ¶åªäœã®ç¶æ
ã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<pre>
ïŒ ïŒ ïŒ ïŒ ç©º 空 空 空 âŠ
</pre>
<p>
3 çªç®ã®åœä»€ã«ãã£ãŠïŒ0 ã®èå¥åãæã€ãã¡ã€ã«ãåé€ãããïŒèšæ¶åªäœã®ç¶æ
ã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<pre>
空 空 ïŒ ïŒ ç©º 空 空 空 âŠ
</pre>
<p>
4 çªç®ã®åœä»€ã«ãã£ãŠïŒ2 ãšããèå¥åãæã€ãã¡ã€ã«ã 0 çªç®ïŒ1 çªç®ïŒ4 çªç®ïŒ5 çªç®ã®ã»ã¯ã¿ã«æžã蟌ãïŒ
</p>
<pre>
ïŒ ïŒ ïŒ ïŒ ïŒ ïŒ ç©º 空 âŠ
</pre>
<p>
æåŸã®åœä»€ã§ã¯ïŒ3 çªç®ã®ã»ã¯ã¿ãåç
§ãããïŒããŸïŒ3 çªç®ã®ã»ã¯ã¿ã«ã¯ 1 ãšããèå¥åã®ãã¡ã€ã«ãé
眮ãããŠããã®ã§ïŒããªãã®ããã°ã©ã 㯠1 ãšåºåããªããã°ãªããªãïŒ
</p>
<h3>Input</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ
</p>
<blockquote>
<i>N</i><br>
<i>Command</i><sub>1</sub><br>
<i>Command</i><sub>2</sub><br>
...<br>
<i>Command</i><sub><i>N</i></sub>
</blockquote>
<p>
<i>N</i> ã¯å®è¡ãããã³ãã³ãã®æ° (1 ≤ <i>N</i> ≤ 10,000)ïŒ<i>Command</i><sub><i>i</i></sub> 㯠<i>i</i> çªç®ã«å®è¡ãããã³ãã³ãããããã衚ãïŒ
</p>
<p>
åã³ãã³ãã¯ïŒã³ãã³ãåãš 1 ã€ãŸã㯠2 ã€ã®åŒæ°ãããªãïŒã³ãã³ãå㯠1 ã€ã®æåã®ã¿ãããªãïŒãWãïŒãDãïŒãRãã®ããããã§ããïŒã³ãã³ããšåŒæ°ã®éïŒããã³åŒæ°ãšåŒæ°ã®éã¯ãããã 1 ã€ã®ã¹ããŒã¹ã§åºåãããïŒ
</p>
<p>
ãWãã¯æžã蟌ã¿ã®ã³ãã³ãã衚ãïŒ2 ã€ã®åŒæ° <i>I</i> (0 ≤ <i>I</i> ≤ 10<sup>9</sup>) ãš <i>S</i> (1 ≤ <i>S</i> ≤ 10<sup>9</sup>) ãäžããããïŒããããïŒæžã蟌ããã¡ã€ã«ã®èå¥åãšãã®ãã¡ã€ã«ãèšæ¶ããã®ã«å¿
èŠãšããã»ã¯ã¿ã®æ°ã瀺ãïŒ
</p>
<p>
ãDãã¯åé€ã®ã³ãã³ãã衚ãïŒ1 ã€ã®åŒæ° <i>I</i> (0 ≤ <i>I</i> ≤ 10<sup>9</sup>) ãäžããããïŒåé€ãããã¡ã€ã«ã®èå¥åã瀺ãïŒ
</p>
<p>
ãRãã¯åç
§ã®ã³ãã³ãã衚ãïŒ1 ã€ã®åŒæ° <i>P</i> (0 ≤ <i>P</i> ≤ 10<sup>9</sup>) ãäžããããïŒåç
§ããã»ã¯ã¿ã®çªå·ã瀺ãïŒ
</p>
<p>
10<sup>9</sup> ããã倧ããªçªå·ãæã€ã»ã¯ã¿ã«ã¯ã¢ã¯ã»ã¹ããå¿
èŠã¯ãªããšä»®å®ããŠããïŒãŸãïŒåããã¡ã€ã«èå¥åãæã€ãã¡ã€ã«ãè€æ°åæžã蟌ãããšã¯ãªãããšãä¿èšŒãããŠããïŒ
</p>
<p>
å
¥åã®çµããã¯ïŒ1 ã€ã® 0 ãå«ã 1 è¡ã§ç€ºãããïŒ
</p>
<h3>Output</h3>
<p>
åããŒã¿ã»ããã«ã€ããŠïŒåç
§ã®ã³ãã³ããçŸããããšã«ïŒãã®ã³ãã³ãã«ãã£ãŠåç
§ããããã¡ã€ã«ã®èå¥åã 1 è¡ã«åºåããïŒåç
§ããã»ã¯ã¿ã«ãã¡ã€ã«ãæžã蟌ãŸããŠããªãã£ãå Žåã¯ïŒãã¡ã€ã«èå¥åã®ä»£ããã« -1 ãåºåããïŒ
</p>
<p>
åããŒã¿ã»ããã®åŸã«ã¯ç©ºè¡ãå
¥ããããšïŒ
</p>
<h3>Sample Input</h3>
<pre>
6
W 0 2
W 1 2
D 0
W 2 4
R 3
R 1
1
R 1000000000
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
2
-1
</pre>
|
p00898 |
<H1><font color="#000">Problem E: </font>Driving an Icosahedral Rover</H1>
<p>
After decades of fruitless efforts, one of the expedition teams of ITO (Intersolar Tourism Organization) finally found a planet that would surely provide one of the best tourist attractions
within a ten light-year radius from our solar system. The most attractive feature of the planet,
besides its comfortable gravity and calm weather, is the area called <i>Mare Triangularis</i>. Despite
the name, the area is not covered with water but is a great plane. Its unique feature is that it is
divided into equilateral triangular sections of the same size, called <i>trigons</i>. The <i>trigons</i> provide
a unique impressive landscape, a must for tourism. It is no wonder the board of ITO decided
to invest a vast amount on the planet.
</p>
<p>
Despite the expected secrecy of the staff, the Society of Astrogeology caught this information
in no time, as always. They immediately sent their president's letter to the Institute of Science
and Education of the Commonwealth Galactica claiming that authoritative academic inspections
were to be completed before any commercial exploitation might damage the nature.
</p>
<p>
Fortunately, astrogeologists do not plan to practice all the possible inspections on all of the
<i>trigons</i>; there are far too many of them. Inspections are planned only on some characteristic
<i>trigons</i> and, for each of them, in one of twenty different scientific aspects.
</p>
<p>
To accelerate building this new tourist resort, ITO's construction machinery team has already succeeded in putting their brand-new
invention in practical use. It is a rover vehicle of the shape of an <i>icosahedron</i>, a regular polyhedron with twenty faces of equilateral triangles.
The machine is customized
so that each of the twenty faces exactly fits each of the <i>trigons</i>.
Controlling the high-tech <i>gyromotor</i> installed inside its body, the rover can roll onto one of the three <i>trigons</i> neighboring the one its bottom is
on.
</p>
<center>
<table width="480">
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1319_1">
</td>
<tr>
<td>
<b>Figure E.1: The Rover on Mare Triangularis</b>
</td>
</tr>
</table>
</center>
<p>
Each of the twenty faces has its own function. The set of equipments installed on the bottom
face touching the ground can be applied to the <i>trigon</i> it is on. Of course, the rover was meant to accelerate construction of the luxury hotels to host rich interstellar travelers, but, changing
the installed equipment sets, it can also be used to accelerate academic inspections.
</p>
<p>
You are the driver of this rover and are asked to move the vehicle onto the <i>trigon</i> specified by
the leader of the scientific commission with the smallest possible steps. What makes your task
more difficult is that the designated face installed with the appropriate set of equipments has to
be the bottom. The direction of the rover does not matter.
</p>
<center>
<table width="480">
<tr>
<td align="justify">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1319_2">
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1319_3">
</td>
<tr>
<td>
<b>Figure E.2:The Coordinate System </b>
</td>
<td align="center">
<b>
Figure E.3: Face Numbering</b>
</td>
</tr>
</table>
</center>
<p>
The <i>trigons</i> of <i>Mare Triangularis</i> are given two-dimensional coordinates as shown in Figure E.2.
Like maps used for the Earth, the <i>x</i> axis is from the west to the east, and the <i>y</i> axis is from the
south to the north. Note that all the trigons with its coordinates (<i>x , y</i>) has neighboring trigons
with coordinates (<i>x</i> - 1 , <i>y</i>) and (<i>x</i> + 1 , <i>y</i>). In addition to these, when <i>x</i> + <i>y</i> is even, it has a
neighbor (<i>x</i> , <i>y</i> + 1); otherwise, that is, when <i>x</i> + <i>y</i> is odd, it has a neighbor (<i>x , y</i> - 1).
</p>
<p>
Figure E.3 shows a development of the skin of the rover. The top face of the development
makes the exterior. That is, if the numbers on faces of the development were actually marked
on the faces of the rover, they should been readable from its outside. These numbers are used
to identify the faces.
</p>
<p>
When you start the rover, it is on the <i>trigon</i> (0,0) and the face 0 is touching the ground. The
rover is placed so that rolling towards north onto the <i>trigon</i> (0,1) makes the face numbered 5
to be at the bottom.
</p>
<p>
As your first step, you can choose one of the three adjacent <i>trigons</i>, namely those with coordinates (-1,0), (1,0),
and (0,1), to visit. The bottom will be the face numbered 4, 1, and 5,
respectively. If you choose to go to (1,0) in the first rolling step, the second step can bring
the rover to either of (0,0), (2,0), or (1,-1). The bottom face will be either of 0, 6, or 2,
correspondingly. The rover may visit any of the <i>trigons</i> twice or more, including the start and the goal <i>trigons</i>, when appropriate.
</p>
<p>
The theoretical design section of ITO showed that the rover can reach any goal <i>trigon</i> on the
specified bottom face within a finite number of steps.
</p>
<H2>Input</H2>
<p>
The input consists of a number of datasets. The number of datasets does not exceed 50.
</p>
<p>
Each of the datasets has three integers <i>x</i>, <i>y</i>, and <i>n</i> in one line, separated by a space. Here, (x,y)
specifies the coordinates of the <i>trigon</i> to which you have to move the rover, and <i>n</i> specifies the
face that should be at the bottom.
</p>
<p>
The end of the input is indicated by a line containing three zeros.
</p>
<H2>Output</H2>
<p>
The output for each dataset should be a line containing a single integer that gives the minimum
number of steps required to set the rover on the specified <i>trigon</i> with the specified face touching
the ground. No other characters should appear in the output.
</p>
<p>
You can assume that the maximum number of required steps does not exceed 100. <i>Mare Triangularis</i>
is broad enough so that any of its edges cannot be reached within that number of
steps.
</p>
<H2>Sample Input</H2>
<pre>
0 0 1
3 5 2
-4 1 3
13 -13 2
-32 15 9
-50 50 0
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6
10
9
30
47
100
</pre> |
p00031 |
<H1>Weight</H1>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_weight"></center>
<br/>
<p>
ç¥æ¯ã倩秀ã䜿ã£ãŠããŸãã倩秀ã¯ãäºã€ã®ç¿ã®äž¡æ¹ã«åãç®æ¹ã®ãã®ãèŒãããšé£åããããã§ãªãå Žåã«ã¯ãéãæ¹ã«åŸããŸãã10 åã®åé
ã®éãã¯ã軜ãé ã« 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g ã§ãã
</p>
<p>
ç¥æ¯ã¯ãã1kg ããããŸã§ã°ã©ã åäœã§éããã®ããããšèšããŸããããããã詊ãã«ãããã«ãããžã¥ãŒã¹ã®éããéã£ãŠãããšèšã£ãŠã¿ããšãç¥æ¯ã¯å·Šã®ç¿ã«ãžã¥ãŒã¹ããå³ã®ç¿ã« 8g ãš64g ãš128g ã®åé
ãèŒããŠé£åãããŠããããåé
ã®ç®æ¹ã®åèšã¯ 200g ã ããããžã¥ãŒã¹ã®ç®æ¹ã¯ 200g ããã©ããæ£ããã§ãããïŒããšçããŸããã
</p>
<p>
å·Šã®ç¿ã«èŒããåç©ã®éããäžããã®ã§ã倩秀ã§äžããããéã¿ã®åç©ãšé£åããããšãã«ãå³ã®ç¿ã«èŒããåé
ã軜ãé ã«åºåããããã°ã©ã ãäœæããŠäžããããã ããéãã¹ãåç©ã®éãã¯ããã¹ãŠã®åé
ã®éãã®åèš (=1023g) 以äžãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«ãå·Šã®ç¿ã«èŒããåç©ã®éããïŒè¡ã«äžããããŸããå
¥åã®æåŸãŸã§åŠçããŠäžãããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠãå³ã®ç¿ã«èŒããåé
ïŒæé ïŒãïŒã€ã®ç©ºçœã§åºåã£ãŠãïŒè¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
5
7
127
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 4
1 2 4
1 2 4 8 16 32 64
</pre>
<H2>Hint</H2>
<p>
åé
ã®éã㯠2 ã® <var>n</var> ä¹ ( <var>n</var> = 0, 1, .... 9 )g ã§ãã
</p>
|
p00461 |
<H1> IOIOI </H1>
<h2>åé¡</h2>
<p>
æŽæ° <i>n</i> (1 ≤ <i>n</i>) ã«å¯Ÿã, <i>n</i> + 1 åã® <span>I</span> ãš <i>n</i> åã® <span>O</span> ã <span>I</span> ããå§ããŠäº€äºã«äžŠã¹ãŠã§ããæååã <i>P<sub>n</sub></I> ãšãã.ããã§ <span>I</span> ãš <span>O</span> ã¯ããããè±å€§æåã®ã¢ã€ãšãªãŒã§ãã.
</p>
<br><center>
<table>
<tr><td width="40"><i>P</i><sub>1</sub></td><td><span>IOI</span></td></tr>
<tr><td><i>P</i><sub>2</sub></td><td><span>IOIOI</span></td></tr>
<tr><td><i>P</i><sub>3</sub></td><td><span>IOIOIOI</span></td></tr>
<tr><td></td><td>.<td></tr>
<tr><td></td><td>.<td></tr>
<tr><td></td><td>.<td></tr>
<tr><td><i>P</i><sub><i>n</i></sub></td><td><span>IOIOIO ... OI</span> (<span>O</span> ã <i>n</i> å)</td></tr>
</table>
<br>
<p>
å³ 1-1 æ¬åã§èããæåå <i>P<sub>n</sub></i>
</p>
</center>
<br>
<p>
æŽæ° <i>n</i> ãš, I ãš O ã®ã¿ãããªãæåå <i>s</i> ãäžããããæ, <i>s</i> ã®äžã« <i>P<sub>n</sub></i> ãäœã¶æå«ãŸããŠããããåºåããããã°ã©ã ãäœæãã.
</p>
<h2>äŸ</h2>
<p>
<i>n</i> ã 1, <i>s</i> ã <span>OOIOIOIOIIOII</span> ã®å Žå, <i>P</i><sub>1</sub> 㯠<span>IOI</span> ã§ãã,äžå³ 1-2 ã«ç€ºãã 4ã¶æã«å«ãŸããŠãã.ãã£ãŠ,åºå㯠4 ã§ãã.
</p>
<center>
<span>
OO<u>IOI</u>OIOIIOII<br>
OOIO<u>IOI</u>OIIOII<br>
OOIOIO<u>IOI</u>IOII<br>
OOIOIOIOI<u>IOI</u>I<br>
</span>
</center>
<br>
<center>
å³ 1-2 <i>n</i> ã 1, <i>s</i> ã <span>OOIOIOIOIIOII</span> ã®å Žåã®äŸ
</center>
<br>
<p>
<i>n</i> ã 2, <i>s</i> ã <span>OOIOIOIOIIOII</span> ã®å Žå, <i>P</i><sub>2</sub> 㯠<span>IOIOI</span> ã§ãã,äžå³ 1-3 ã«ç€ºãã 2ã¶æã«å«ãŸããŠãã.ãã£ãŠ,åºå㯠2 ã§ãã.
</p>
<center>
<span>
OO<u>IOIOI</u>OIIOII<br>
OOIO<u>IOIOI</u>IOII<br>
</span>
</center>
<br>
<center>
å³ 1-3 <i>n</i> ã 2, <i>s</i> ã <span>OOIOIOIOIIOII</span> ã®å Žåã®äŸ
</center>
<br>
<h2>å
¥å</h2>
<p>
<!-- å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠input.txt ã§ãã.<br>-->
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
1 è¡ç®ã«ã¯æŽæ° <i>n</i> (1 ≤ <i>n</i> ≤ 1000000) ãæžãããŠãã.<br>
2 è¡ç®ã«ã¯æŽæ° <i>m</i> (1 ≤ <i>m</i> ≤ 1000000) ãæžãããŠãã. <i>m</i> 㯠<i>s</i> ã®æåæ°ã衚ã.<br>
3 è¡ç®ã«ã¯æåå <i>s</i> ãæžãããŠãã. <i>s</i> 㯠<span>I</span> ãš <span>O</span> ã®ã¿ãããªã.
</p>
<p>
å
šãŠã®æ¡ç¹çšããŒã¿ã§, 2<i>n</i> + 1 ≤ <i>m</i> ã§ãã.æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 50% åã«ã€ããŠã¯, <i>n</i> ≤ 100, <i>m</i> ≤ 10000 ãæºãã.
</p>
<p>
<i>n</i> ã 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
<!-- åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠output.txt ã§ãã.<br>
output.txt ã¯,æåå <i>s</i> ã«æåå <i>P<sub>n</sub></i> ãäœã¶æå«ãŸãããã衚ã 1 ã€ã®æŽæ°ãå«ã 1 è¡ãããªã.
-->
ããŒã¿ã»ããããšã«,æåå <i>s</i> ã«æåå <i>P<sub>n</sub></i> ãäœã¶æå«ãŸãããã衚ã 1 ã€ã®æŽæ°ã1 è¡ã«åºåãã. <i>s</i> ã« <i>P<sub>n</sub></i> ãå«ãŸããŠããªãå Žåã¯,æŽæ°ãšã㊠<span>0</span> ãåºåãã.
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
1
13
OOIOIOIOIIOII
2
13
OOIOIOIOIIOII
0
</pre>
<h3>åºåäŸ</h3>
<pre>
4
2
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02149 | <h1>Problem A: Lunch</h1>
<h2>Problem</h2>
<p>
ããæ¥ãå·æããã¯åŠé£ã§æŒé£ãé£ã¹ãããšããŠããŸãã
åŠé£ã«ã¯Aã©ã³ããBã©ã³ããCã©ã³ãã®3çš®é¡ã®æ¥æ¿ããã®ã©ã³ãã¡ãã¥ãŒããããŸãã<br>
å·æããã¯é£ãããåãªã®ã§3çš®é¡ã®æ¥æ¿ããã®ã©ã³ãã¡ãã¥ãŒããã¹ãŠ1ã€ãã€é£ã¹ãããšæã£ãŠããŸãã<br>
ããããå·æããã¯å¥åº·ã«æ°ã䜿ã£ãŠæåããã«ããªãŒã®åèšãæå°ã«ãªãããã«1çš®é¡ã®ã©ã³ãã¡ãã¥ãŒãææ
¢ããç°ãªã2çš®é¡ã®ã©ã³ãã¡ãã¥ãŒãé£ã¹ãããšã«ããŸããã<br>
ããæ¥ã®Aã©ã³ããBã©ã³ããCã©ã³ãã®ã«ããªãŒãäžããããæãå·æãããææ
¢ããããšã«ãªãã©ã³ãã¡ãã¥ãŒãæ±ããŠãã ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$a$ $b$ $c$
</pre>
<p>
3ã€ã®æŽæ°$a$, $b$, $c$ã空çœåºåãã§äžããããããããããããæ¥ã®Aã©ã³ããBã©ã³ããCã©ã³ãã®ã«ããªãŒã衚ããŠããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq a, b, c \leq 5000 $</li>
<li>$a \neq b, b \neq c, c \neq a$</li>
</ul>
<h2>Output</h2>
<p>
å·æãããææ
¢ããããšã«ãªãã¡ãã¥ãŒåã1è¡ã«åºåããã<br>
Aã©ã³ããææ
¢ããå Žåã¯"A"<br>
Bã©ã³ããææ
¢ããå Žåã¯"B"<br>
Cã©ã³ããææ
¢ããå Žåã¯"C"<br>
ãšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1000 900 850
</pre>
<h2>Sample Output 1</h2>
<pre>
A
</pre>
<h2>Sample Input 2</h2>
<pre>
1000 800 1200
</pre>
<h2>Sample Output 2</h2>
<pre>
C
</pre>
|
p00174 |
<H1>ãããã³ãã³</H1>
<p>
AåãBãããCåã§ä¹
ãã¶ãã«éã¶ããšã«ãªããŸããã AåãšBããããã¬ã€ã€ãŒãCåã審å€ã«ãªããããã³ãã³ã®ã·ã³ã°ã«ã¹ã®ã²ãŒã ãããŸããã3äººã§æ±ºããã«ãŒã«ã¯ä»¥äžã®éãã§ãã
</p>
<ul>
<li>3 ã²ãŒã ãè¡ããŸãã</li>
<li>11 ç¹ãå
åãã人ãããã®ã²ãŒã ã®åè
ãšãªããŸãã</li>
<li>第 1 ã²ãŒã ã®æåã®ãµãŒãã¯Aåããå§ãŸããŸãããæ¬¡ã®ãµãŒãã¯çŽåã®ãã€ã³ããåã£ã人ãè¡ããŸãã</li>
<li>第 2 ã²ãŒã ã第 3 ã²ãŒã ã¯åã®ã²ãŒã ãåã£ã人ãæåã®ãµãŒããè¡ããŸãã</li>
<li>10 - 10 ã«ãªã£ãŠä»¥é㯠2 ç¹å·®ãã€ãã人ãåè
ãšãªããŸãã</li>
</ul>
<p>
å
šãŠã®ã²ãŒã ãçµãããåŸç¹ãèŠãããšããã®ã§ããã審å€ã®CåãåŸç¹ãèšé²ããã®ãå¿ããŠããŸããããããããµãŒããæã£ã人ããã¡ããšèšé²ããŠããŸããããµãŒãé ã®èšé²ããåŸç¹ãèšç®ããããã°ã©ã ãäœæããŠãã ããããã ããäºäººãæã£ããµãŒãã®åæ°ã®åèšã¯ 100 以äžãšãããµãŒãé ã®èšé²ã¯ããµãŒããæã£ã人ã衚ã "A" ãŸã㯠"B" ã®æååã§è¡šãããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸ
ããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>record<sub>1</sub></var>
<var>record<sub>2</sub></var>
<var>record<sub>3</sub></var>
</pre>
<p>
<var>i</var> è¡ç®ã«ç¬¬ <var>i</var> ã²ãŒã ã®ãµãŒãé ã衚ãæååãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«ã<var>i</var> è¡ç®ã«ç¬¬ <var>i</var> ã²ãŒã ã®Aåã®åŸç¹ãšBããã®åŸç¹ã空çœåºåãã§åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
ABAABBBAABABAAABBAA
AABBBABBABBAAABABABAAB
BABAABAABABABBAAAB
AABABAAABBAABBBABAA
AAAAAAAAAAA
ABBBBBBBBBB
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
11 8
10 12
11 7
11 8
11 0
0 11
</pre>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.