question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p01822 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h3>Problem E:
Enclose Points</h3>
<p>
There are $N$ points and $M$ segments on the $xy$-plane. Each segment connects two of these
points and they don't intersect each other except at the endpoints. You are also given $Q$ points
as queries. Your task is to determine for each query point whether you can make a polygon that
encloses the query point using some of the given segments. Note that the polygon should not
necessarily be convex.
</p>
<h3>Input</h3>
<p>
Each input is formatted as follows.<br>
<br>
$N$ $M$ $Q$<br>
$x_1$ $y_1$<br>
...<br>
$x_N$ $y_N$<br>
$a_1$ $b_1$<br>
...<br>
$a_M$ $b_M$<br>
$qx_1$ $qy_1$<br>
...<br>
$qx_Q$ $qy_Q$<br>
<br>
</p>
<p>
The first line contains three integers $N$ ($2 \leq N \leq 100,000$), $M$ ($1 \leq M \leq 100,000$), and $Q$
($1 \leq Q \leq 100,000$), which represent the number of points, the number of segments, and the
number of queries, respectively. Each of the following $N$ lines contains two integers $x_i$ and $y_i$
($-100,000 \leq x_i, y_i \leq 100,000$), the coordinates of the $i$-th point. The points are guaranteed to be
distinct, that is, $(x_i, y_i) \ne (x_j, y_j)$ when $i \ne j$. Each of the following $M$ lines contains two integers
$a_i$ and $b_i$ ($1 \leq a_i < b_i \leq N$), which indicate that the $i$-th segment connects the $a_i$-th point and
the $b_i$-th point. Assume that those segments do not intersect each other except at the endpoints.
Each of the following $Q$ lines contains two integers $qx_i$ and $qy_i$ ($-100,000 \leq qx_i, qy_i \leq 100,000$),
the coordinates of the $i$-th query point.
</p>
<p>
You can assume that, for any pair of query point and segment, the distance between them is at
least $10^{-4}$.
</p>
<h3>Output</h3>
<p>
The output should contain $Q$ lines. Print "Yes" on the $i$-th line if there is a polygon that
contains the $i$-th query point. Otherwise print "No" on the $i$-th line.
</p>
<h3>Sample Input</h3>
<pre>
4 5 3
-10 -10
10 -10
10 10
-10 10
1 2
1 3
1 4
2 3
3 4
-20 0
1 0
20 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
No
Yes
No
</pre>
<h3>Sample Input</h3>
<pre>
8 8 5
-20 -20
20 -20
20 20
-20 20
-10 -10
10 -10
10 10
-10 10
1 2
1 4
2 3
3 4
5 6
5 8
6 7
7 8
-25 0
-15 0
0 0
15 0
25 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
No
Yes
Yes
Yes
No
</pre>
<h3>Sample Input</h3>
<pre>
8 8 5
-20 -10
-10 -10
-10 10
-20 10
10 -10
20 -10
20 10
10 10
1 2
2 3
3 4
1 4
5 6
6 7
7 8
5 8
-30 0
-15 0
0 0
15 0
30 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
No
Yes
No
Yes
No
</pre>
|
p00730 |
<h1><font color="#000">Problem C:</font> Cut the Cake</h1>
<!-- end en only -->
<p>
Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest <i>pâtissiers</i> in the world.
Those who are invited to his birthday party are <i>gourmets</i> from around the world.
They are eager to see and eat his extremely creative cakes.
Now a large box-shaped cake is being carried into the party.
It is not beautifully decorated and looks rather simple, but it must be delicious beyond anyone's imagination.
Let us cut it into pieces with a knife and serve them to the guests attending the party.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The cake looks rectangular, viewing from above (Figure C-1).
As exemplified in Figure C-2, the cake will iteratively be cut into pieces, where on each cut exactly a single piece is cut into two smaller pieces.
Each cut surface must be orthogonal to the bottom face and must be orthogonal or parallel to a side face.
So, every piece shall be rectangular looking from above and every side face vertical.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_c-1"><br><br>
<!-- begin en only -->
Figure C-1: The top view of the cake
<!-- end en only -->
</center>
<center>
<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_c-2"><br><br>
<!-- begin en only -->
Figure C-2: Cutting the cake into pieces
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
Piece sizes in Figure C-2 vary significantly and it may look unfair, but you don't have to worry.
Those guests who would like to eat as many sorts of cakes as possible often prefer smaller pieces.
Of course, some prefer larger ones.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>Your mission of this problem is to write a computer program that simulates the cutting process of the cake and reports the size of each piece.
</p>
<!-- end en only -->
<h2>Input</h2>
<!-- begin en only -->
<p>
The input is a sequence of datasets, each of which is of the following format.
</p>
<!-- end en only -->
<blockquote>
<i>n</i> <i>w</i> <i>d</i><br>
<i>p</i><sub>1</sub> <i>s</i><sub>1</sub><br>
...<br>
<i>p<sub>n</sub></i> <i>s<sub>n</sub></i><br>
</blockquote>
<!-- begin en only -->
<p>
The first line starts with an integer <i>n</i> that is between 0 and 100 inclusive.
It is the number of cuts to be performed.
The following <i>w</i> and <i>d</i> in the same line are integers between 1 and 100 inclusive.
They denote the width and depth of the cake, respectively.
Assume in the sequel that the cake is placed so that <i>w</i> and <i>d</i> are the lengths in the east-west and north-south directions, respectively.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Each of the following <i>n</i> lines specifies a single cut, cutting one and only one piece into two.
<i>p<sub>i</sub></i> is an integer between 1 and <i>i</i> inclusive and is the identification number of the piece that is the target of the <i>i</i>-th cut.
Note that, just before the <i>i</i>-th cut, there exist exactly <i>i</i> pieces.
Each piece in this stage has a unique identification number that is one of 1, 2, ..., <i>i</i> and is defined as follows:
</p>
<!-- end en only -->
<!-- begin en only -->
<ul>
<li>
The earlier a piece was born, the smaller its identification number is.
<li>
Of the two pieces born at a time by the same cut, the piece with the smaller area (looking from above) has the smaller identification number.
If their areas are the same, you may define as you like the order between them, since your choice in this case has no influence on the final answer.
</ul>
<!-- end en only -->
<!-- begin en only -->
<p>
Note that identification numbers are adjusted after each cut.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
<i>s<sub>i</sub></i> is an integer between 1 and 1000 inclusive and specifies the starting point of the <i>i</i>-th cut.
From the northwest corner of the piece whose identification number is <i>p<sub>i</sub></i>, you can reach the starting point by traveling <i>s<sub>i</sub></i> in the clockwise direction around the piece.
You may assume that the starting point determined in this way cannot be any one of the four corners of the piece.
The <i>i</i>-th cut surface is orthogonal to the side face on which the starting point exists.
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line with three zeros.
</p>
<!-- end en only -->
<h2>Output</h2>
<!-- begin en only -->
<p>
For each dataset, print in a line the areas looking from above of all the pieces that exist upon completion of the <i>n</i> cuts specified in the dataset.
They should be in ascending order and separated by a space.
When multiple pieces have the same area, print it as many times as the number of the pieces.
</p>
<!-- end en only -->
<h2>Sample Input</h2>
<pre>
3 5 6
1 18
2 19
1 2
3 4 1
1 1
2 1
3 1
0 2 5
0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
4 4 6 16
1 1 1 1
10
</pre>
|
p00360 | <H1>Swapping Characters</H1>
<p>
You are given a string and a number <var>k</var>. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to <var>k</var> times. Write a program to report the lexicographically smallest string among them.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>s</var>
<var>k</var>
</pre>
<p>
The first line provides a string <var>s</var>. The second line provides the maximum number of swapping operations <var>k</var> (0 ≤ <var>k</var> ≤ 10<sup>9</sup>). The string consists solely of lower-case alphabetical letters and has a length between 1 and 2 × 10<sup>5</sup>.
</p>
<h2>Output</h2>
<p>
Output the lexicographically smallest string.
</p>
<h2>Sample Input 1</h2>
<pre>
pckoshien
3
</pre>
<h2>Sample Output 1</h2>
<pre>
ckopshien
</pre>
<h2>Sample Input 2</h2>
<pre>
pckoshien
10
</pre>
<h2>Sample Output 2</h2>
<pre>
cekophsin
</pre>
|
p01988 | <h3>NINJA GAME</h3>
<!-- begin ja only -->
<p>æ°äœã²ãŒã "NIN<strong><em>JA G</em></strong>AME" ãã€ãã«çºå£²ãšãªã£ãïŒãã®ã²ãŒã ã§ã¯ãã¬ã€ã€ãŒã¯äºæ¬¡å
ãããäžã®å¿è
ãæäœããŠç§»åãè¡ãïŒäºæ¬¡å
ããã㯠<i>x</i> 軞ïŒãŸã㯠<i>y</i> 軞ã®ã©ã¡ããäžæ¹ã«å¹³è¡ãªèŸºã®ã¿ãããªãïŒèªå·±äº€å·®ã®ãªãå€è§åœ¢ã§è¡šãããïŒããŸïŒå€è§åœ¢ã®å
éšã«ååšããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžãšç§»åããå¿
èŠãããïŒ</p>
<p>ç§»åã¯äžäžå·Šå³ãšæã45°ã®8æ¹åãå¯èœã§ïŒããããã®å¯Ÿå¿ããã³ãã³ããå
¥åãããšïŒæå®ããæ¹åã«èªåã§é²ã¿ç¶ããïŒãã®èªåç§»åã®æäžã®ä»»æã®ã¿ã€ãã³ã°ã§å¥ã®ã³ãã³ããå
¥åããå ŽåïŒå³åº§ã«ç§»åæ¹åã®è»¢æãå¯èœã§ããïŒããªãã®ç®æšã¯ïŒãã®ã²ãŒã ã§ã®å®çžŸãè§£é€ããããïŒæå°ã®ã³ãã³ãå
¥ååæ°ã§ã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ã«ç§»åããããšã§ããïŒ</p>
<p>ããã§æ°ãä»ããå¿
èŠãããã®ã¯ïŒãã£ã©ãå¿è
ã§ããã®ã§ïŒå£äŒãã®ç§»åãå¯èœã§ãããšããããšã ïŒããã§å£äŒãã®ç§»åãããšã¯ïŒå€è§åœ¢ã®èŸºäžãç§»åããããšã§ããïŒãã ãïŒãã¡ããå€è§åœ¢ã®å€éšã«åºãããšã¯ã§ããªãïŒå£äŒãã®ç§»åäžã«ãã®å£ã«å¯ŸãåçŽæ¹åã«ç§»åããããšããå Žåã¯ãã以äžç§»åã§ããã«æ¢ãŸãã®ã ãïŒäžæ¹ã§å£äŒãã®ç§»åäžã«æãæ¹åã«ç§»åããããšããå ŽåïŒå£ãšå¹³è¡ãªæ¹åãžã®å£äŒãã®èªåç§»åãç¶ãïŒå£ããªããªã£ããšããã§å
ã®æãæ¹åã«ãŸãèªåç§»åãç¶ããïŒäŸãã°äžå³ã®ããã« <i>y</i> 軞ã«å¹³è¡ãªå£ã« <i>x</i> è»žæ£æ¹åãš <i>y</i> è»žè² æ¹åãããªãæãæ¹åããã¶ã€ãã£ãå ŽåïŒã¶ã€ãã£ãåŸã¯å£ã«æ²¿ã£ãŠ <i>y</i> è»žè² æ¹åã«é²ã¿ïŒå£ããªããªã£ããšããã§ãŸã <i>x</i> è»žæ£æ¹åãš <i>y</i> è»žè² æ¹åãããªãæãæ¹åãžãšé²ã¿å§ããïŒ</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H1.png"></center></p>
<p>ããã§ïŒæãæ¹åã«ç§»åããªããè§ã«ã¶ã€ãã£ããšãã®æåã¯ä»¥äžã®ããã«ãªãïŒ(a) ã®ããã«äž¡æ¹åã«å£ãå²ãŸããŠããå Žåã¯ããã§æ¢ãŸãïŒæ¹å転æãããªããã°åããªãïŒ(b) ã (c) ã®ããã«è§ãéãéããŠãã®ãŸãŸé²ããå Žåã¯ïŒæãæ¹åã«èªåç§»åãç¶ããïŒ(d) ã®ããã«äž¡æ¹åã«é²ããå ŽåïŒå¥œããªæ¹åãéžãã§é²ãããã®ãšããŠããïŒå³ã§ã¯ç§»åã衚ãç¢å°ã§å£ãé ããããå°ãå
éšåŽã«å¯ããŠå³ç€ºããŠãããïŒãããå®éã«ã¯èŸºäžãç§»åããããšã衚ãå³ã§ããïŒ</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H2.png"></center></p>
<p>ãŸãïŒäžäžå·Šå³æ¹åã®ç§»åäžã«è§ã«ã¶ã€ãã£ããšãã®æåã¯ä»¥äžã®ããã«ãªãïŒ(e), (f), (g) ã®ãããªå Žåã¯ãã®ãŸãŸã®æ¹åã«èªåç§»åãç¶ããïŒ(h) ã®ããã«å£ã«åçŽã«ã¶ã€ãã£ãå Žåã¯ããã§æ¢ãŸãïŒæ¹å転æãããªããã°åããªãïŒãã ãïŒåæ§ã«ç§»åã衚ãç¢å°ãå£ããå°ãå
éšåŽã«å¯ããŠãããïŒå®éã«ã¯èŸºäžãç§»åããããšã衚ãå³ã§ããïŒ</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H3.png"></center></p>
<p>äžèšã®ç§»åã«é¢ããæåã«åŸã£ãäžã§ïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ã«å°éããããã«å
¥åããå¿
èŠãããã³ãã³ãã®æ°ã®æå°å€ãæ±ããããã°ã©ã ãäœæããŠã»ããïŒäŸãã°äžå³ã«ãããæå°ã®ã³ãã³ãå
¥ååæ°ã¯ïŒå³äžã«ç€ºãããã«2ã§ããïŒããã¯3ã€ç®ã®ãµã³ãã«å
¥åã«å¯Ÿå¿ããŠããïŒ</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H4.png"></center></p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ
ããŒã¿ã»ããã®æ°ã¯æå€§ã§ 100 ã§ããïŒ
åããŒã¿ã»ããã¯ïŒæ¬¡ã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>N</i>
<i>sx</i> <i>sy</i> <i>gx</i> <i>gy</i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i>
<i>...</i>
<i>x<sub>N</sub></i> <i>y<sub>N</sub></i></blockquote>
<p>ããŒã¿ã»ããã® 1 è¡ç®ã¯ãããã衚ãå€è§åœ¢ã®é ç¹æ°ã衚ã1ã€ã®æŽæ° <i>N</i> (<i>4 ≤ N ≤ 100</i>) ãããªãïŒ2è¡ç®ã¯4ã€ã®æŽæ° <i>sx</i>, <i>sy</i>, <i>gx</i>, <i>gy</i> (<i>-10,000 ≤ sx, sy, gx, gy ≤ 10,000</i>) ãããªãïŒã¹ã¿ãŒãå°ç¹ã®åº§æšã <i>(sx, sy)</i>ïŒãŽãŒã«å°ç¹ã®åº§æšã <i>(gx, gy)</i> ã§ããããšã衚ããŠããïŒç¶ã <i>N</i> è¡ã§ã¯å€è§åœ¢ã®åé ç¹ãåæèšåãé ã«äžããããïŒãã®ãã¡ <i>i</i> è¡ç®ã¯2ã€ã®æŽæ° <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> (<i>-10,000 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 10,000</i>) ãããªãïŒ<i>i</i> çªç®ã®é ç¹ã®åº§æšã <i>(x<sub>i</sub>, y<sub>i</sub>)</i> ã§ããããšã衚ãïŒããã§ïŒäžããããã¹ã¿ãŒãå°ç¹ïŒãŽãŒã«å°ç¹ïŒå€è§åœ¢ã¯ä»¥äžã®å¶çŽãæºããïŒ</p>
<ul>
<li>å
šãŠã®èŸºã¯ <i>x</i> 軞ã <i>y</i> 軞ã®ããããäžæ¹ã«å¯ŸããŠå¹³è¡ã§ããïŒ</li>
<li>äžããããå€è§åœ¢ã¯èªå·±äº€å·®ãæããªãïŒããªãã¡ïŒå蟺ã¯ç«¯ç¹ä»¥å€ã§ä»ã®èŸºãšäº€å·®ããïŒç°ãªã <i>i, j</i> ã«ã€ã㊠<i>(x<sub>i</sub>, y<sub>i</sub>) ≠ (x<sub>j</sub>, y<sub>j</sub>)</i> ã§ããïŒ</li>
<li><i>(sx, sy)</i> ãš <i>(gx, gy)</i> ã¯ãšãã«ãã®å€è§åœ¢ã®å
éš (蟺äžãå«ãŸãªã) ã«ããããšãä¿èšŒãããïŒ</li>
<li>ã¹ã¿ãŒããšãŽãŒã«ã¯ç°ãªãïŒããªãã¡ <i>(sx, sy) ≠ (gx, gy)</i> ã§ããããšãä¿èšŒãããïŒ</li>
</ul>
<p>å
¥åã®çµãã㯠1 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸãïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ã«èŸ¿ãçãããã«å¿
èŠãªæå°ã®ã³ãã³ãå
¥åã®åæ°ã 1 è¡ã§åºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>8
1 1 2 2
0 2
0 0
2 0
2 1
3 1
3 3
1 3
1 2
12
-9 5 9 -9
0 0
0 -13
3 -13
3 -10
10 -10
10 10
-1 10
-1 13
-4 13
-4 10
-10 10
-10 0
12
3 57 53 2
0 0
64 0
64 18
47 18
47 39
64 39
64 60
0 60
0 44
33 44
33 30
0 30
0
</pre><h3>Output for the Sample Input</h3><pre>1
1
2
</pre>
<p>
1ã€ç®ã®å
¥åã¯äžå³ (1)ïŒ2ã€ç®ã®å
¥åã¯äžå³ (2) ã«å¯Ÿå¿ããïŒ
</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2018_H5.png"></center>
|
p01121 | <!--<h2>Problem E</h2>-->
<!-- begin en only -->
<h3>Cube Surface Puzzle</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
Given a set of six pieces, “Cube Surface Puzzle” is to construct a hollow cube with filled surface.
Pieces of a puzzle is made of a number of small unit cubes laid grid-aligned on a plane.
For a puzzle constructing a cube of its side length <i>n</i>,
unit cubes are on either of the following two areas.
<ul>
<li>
Core (blue): A square area with its side length <i>n</i>−2.
Unit cubes fill up this area.</li>
<li>Fringe (red): The area of width 1 unit forming the outer fringe of the core.
Each unit square in this area may be empty or with a unit cube on it.</li>
</ul>
Each piece is connected with faces of its unit cubes.
Pieces can be arbitrarily rotated and either side of the pieces can
be inside or outside of the constructed cube.
The unit cubes on the core area should come in the centers of the
faces of the constructed cube.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Consider that we have six pieces in Fig. E-1 (The first dataset of Sample Input).
Then, we can construct a cube as shown in Fig. E-2.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_E1.png" width="80%">
<figcaption style="padding-top: 10px" align="center">
<!-- begin en only -->
Fig. E-1 Pieces from the first dataset of Sample Input
<!-- end en only -->
</figcaption>
</center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_E2.png" width="80%">
<figcaption style="padding-top: 10px" align="center">
<!-- begin en only -->
Fig. E-2 Constructing a cube
<!-- end en only -->
</figcaption>
</center>
<!-- begin en only -->
<p>
Mr. Hadrian Hex has collected a number of cube surface puzzles.
One day, those pieces were mixed together and he
cannot find yet from which six pieces he can construct a cube.
Your task is to write a program to help Mr. Hex, which judges whether we can construct a cube for a given set of pieces.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of at most 200 datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<p>
<i>n</i><br>
<i>x</i><sub>1,1</sub><i>x</i><sub>1,2</sub> … <i>x</i><sub>1,<i>n</i></sub><br>
<i>x</i><sub>2,1</sub><i>x</i><sub>2,2</sub> … <i>x</i><sub>2,<i>n</i></sub><br>
…<br>
<i>x</i><sub>6<i>n</i>,1</sub><i>x</i><sub>6<i>n</i>,2</sub> … <i>x</i><sub>6<i>n</i>,<i>n</i></sub>
</p>
</blockquote>
<!-- begin en only -->
<p>
The first line contains an integer <i>n</i> denoting the length of one side of the cube to be constructed (3 ≤ <i>n</i> ≤ 9, <i>n</i> is odd).
The following 6<i>n</i> lines give the six pieces.
Each piece is described in <i>n</i> lines.
Each of the lines corresponds to one grid row and each of the characters in
the line, either ‘X’ or ‘.’, indicates whether or not a unit cube is on
the corresponding unit square: ‘X’ means a unit cube is on the column and ‘.’ means none is there.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The core area of each piece is centered in the data for the piece.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing a zero.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output “<tt>Yes</tt>” if we can construct a cube, or “<tt>No</tt>” if we cannot.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
5
..XX.
.XXX.
XXXXX
XXXXX
X....
....X
XXXXX
.XXX.
.XXX.
.....
..XXX
XXXX.
.XXXX
.XXXX
...X.
...X.
.XXXX
XXXX.
XXXX.
.X.X.
XXX.X
.XXXX
XXXXX
.XXXX
.XXXX
XX...
.XXXX
XXXXX
XXXXX
XX...
5
..XX.
.XXX.
XXXXX
XXXX.
X....
....X
XXXXX
.XXX.
.XXX.
.....
.XXXX
XXXX.
.XXXX
.XXXX
...X.
...X.
.XXXX
XXXX.
XXXX.
.X.X.
XXX.X
.XXXX
XXXXX
.XXXX
.XXXX
XX...
XXXXX
XXXXX
.XXXX
XX...
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
Yes
No
</pre>
|
p01571 |
<H1><font color="#000">Problem A:</font> Adhoc Translation</H1>
<p>
One day, during daily web surfing, you encountered a web page which was written in a language you've never seen. The character set of the language was the same as your native language; moreover, the grammar and words seemed almost the same. Excitedly, you started to "decipher" the web page. The first approach you tried was to guess the meaning of each word by selecting a similar word from a dictionary of your native language. The closer two words (although from the different languages) are, the more similar meaning they will have.
</p>
<p>
You decided to adopt edit distance for the measurement of similarity between two words. The edit distance between two character sequences is defined as the minimum number of insertions, deletions and substitutions required to morph one sequence into the other. For example, the pair of "point" and "spoon" has the edit distance of 3: the latter can be obtained from the former by deleting 't', substituting 'i' to 'o', and finally inserting 's' at the beginning.
</p>
<p>
You wanted to assign a word in your language to each word in the web text so that the entire assignment has the minimum edit distance. The edit distance of an assignment is calculated as the total sum of edit distances between each word in the text and its counterpart in your language. Words appearing more than once in the text should be counted by the number of appearances.
</p>
<p>
The translation must be consistent across the entire text; you may not match different words from your dictionary for different occurrences of any word in the text. Similarly, different words in the text should not have the same meaning in your language.
</p>
<p>
Suppose the web page says "qwerty asdf zxcv" and your dictionary contains the words "qwert", "asf", "tyui", "zxcvb" and "ghjk". In this case, you can match the words in the page as follows, and the edit distance of this translation is 3: "qwert" for "qwerty", "asf" for "asdf" and "zxcvb" for "zxcv".
</p>
<p>
Write a program to calculate the minimum possible edit distance among all translations, for given a web page text and a word set in the dictionary.
</p>
<H2>Input</H2>
<p>
The first line of the input contains two integers <i>N</i> and <i>M</i>.
</p>
<p>
The following <i>N</i> lines represent the text from the web page you've found. This text contains only lowercase alphabets and white spaces. Then <i>M</i> lines, each containing a word, describe the dictionary to use. Every word consists of lowercase alphabets only, and does not contain more than 20 characters.
</p>
<p>
It is guaranteed that 1 ≤ <i>N</i> ≤ 100 and 1 ≤ <i>M</i> ≤ 400. Also it is guaranteed that the dictionary is made up of many enough words, which means the number of words in the dictionary is no less than the kinds of words in the text to translate. The length of each line in the text does not exceed 1000.
</p>
<H2>Output</H2>
<p>
Output the minimum possible edit distance in a line.
</p>
<H2>Sample Input 1</H2>
<pre>
1 5
qwerty asdf zxcv
qwert
asf
tyui
zxcvb
ghjk
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
3
</pre>
|
p01766 |
<h1 id="a-soccer-ãµãã«ãŒ">A : Soccer / ãµãã«ãŒ</h1>
<h2 id="å顿">å顿</h2>
<p>AåœãšBåœã®éã§AIãµãã«ãŒã®è©Šåããããããªãã®æå
ã«ã¯ãããæå»ã«ããŒã«ãæã£ãŠããéžæãšãã®äœçœ®ãèšé²ãã衚ãããã衚㯠<var>N</var> è¡ãããªããäžãã <var>i</var> çªç®ã®è¡ã¯æ¬¡ã«ç€ºãèŠçŽ ãããªãã</p>
<ul>
<li>ãã¬ãŒã æ° <var>f_i</var></li>
<li>ããŒã«ãæã£ãŠããéžæã®èçªå· <var>a_i</var></li>
<li>ãã®éžæãå±ããããŒã <var>t_i</var></li>
<li>ãã®éžæã®äœçœ®ã衚ãåº§æš <var>x_i , y_i</var></li>
</ul>
<p>ãã¬ãŒã æ°ãšã¯ãã²ãŒã ã®éå§æå»ã« <var>0</var> ã«èšå®ããã <var>1</var>/<var>60</var> ç§ããšã« <var>1</var> å ç®ãããæŽæ°ã®ããšã§ãããäŸãã°ãã²ãŒã éå§ããã¡ããã© <var>1.5</var> ç§åŸã®ãã¬ãŒã æ°ã¯ <var>90</var> ã§ããã èçªå·ã¯åããŒã å
ã® <var>11</var> 人ã®éžæã«äžæã«ãµãããæŽæ°ã§ãããããã«ã衚äžã®é£ç¶ãã <var>2</var> ã€ã®èšé²ã«ãããŠãåãããŒã ã®ç°ãªãèçªå·ã®éžæãããŒã«ãæã£ãŠãããšãããã®éã«ããã¹ããè¡ããããšãããèšé²ã«ååšããªããã¬ãŒã ã¯èæ
®ããªããŠããã</p>
<p>ããŠããšã³ãžãã¢ã§ããããªãã®ä»äºã¯ãåããŒã ã®éžæéã§è¡ããããã¹ã®ãã¡ã æãè·é¢(ãŠãŒã¯ãªããè·é¢)ãé·ããã®ã®è·é¢ãšãããã«ããã£ãæéãæ±ããããšã§ããã è·é¢ãæé·ãšãªããã¹ãè€æ°ããå Žåã¯ãããã£ãæéãæãçããã®ãåºåããã</p>
<h2 id="å
¥å">å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã<var>t_i=0</var> ã®ãšãAåœã <var>t_i=1</var> ã®ãšãBåœã衚ãã</p>
<pre><var>N</var>
<var>f_0</var> <var>a_0</var> <var>t_0</var> <var>x_0</var> <var>y_0</var>
<var>âŠ</var>
<var>f_{N−1}</var> <var>a_{N−1}</var> <var>t_{N−1}</var> <var>x_{N−1}</var> <var>y_{N−1}</var>
</pre>
<h2 id="å¶çŽ">å¶çŽ</h2>
<ul>
<li>å
¥åã¯ãã¹ãп޿°ã§ãã</li>
<li><var>1 \≤ N \≤ 100</var></li>
<li><var>0 \≤ f_i \lt f_{i+1} \≤ 324\,000</var></li>
<li><var> 1 \≤ a_i \≤ 11</var></li>
<li><var> t_i = 0,1</var></li>
<li><var> 0 \≤ x_i \≤ 120</var></li>
<li><var> 0 \≤ y_i \≤ 90</var></li>
</ul>
<h2 id="åºå">åºå</h2>
<p>Aåœã®æé·ã®ãã¹ã«ããã£ãè·é¢ãšæéãBåœã®æé·ã®ãã¹ã«ããã£ãè·é¢ãšæéãããããã1è¡ã«åºåãããæéã¯ç§åäœãšããè·é¢ãæéãšãã« <var>10^{−3}</var> 以äžã®çµ¶å¯Ÿèª€å·®ã¯èš±ãããããã¹ãäžåºŠãè¡ãããªãã£ãå Žåã¯ãšãã« <var>−1</var> ãšåºåããã</p>
<h2 id="ãµã³ãã«">ãµã³ãã«</h2>
<h3 id="ãµã³ãã«å
¥å1">ãµã³ãã«å
¥å1</h3>
<pre>5
0 1 0 3 4
30 1 0 3 4
90 2 0 6 8
120 1 1 1 1
132 2 1 2 2
</pre>
<h3 id="ãµã³ãã«åºå1">ãµã³ãã«åºå1</h3>
<pre>5.00000000 1.00000000
1.41421356 0.20000000
</pre>
<p>Aåœã¯é·ã <var>5</var> ã®ãã¹ã <var>30</var> ãã¬ãŒã ã®æå»ã« <var>60</var> ãã¬ãŒã <var>=1</var> ç§ã§ããBåœã¯é·ã <var>â2</var> ã®ãã¹ã <var>120</var> ãã¬ãŒã ã®æå»ã« <var>12</var> ãã¬ãŒã <var>=0.2</var> ç§ã§ãããããããããããã®æé·ã®ãã¹ã§ããã</p>
<h3 id="ãµã³ãã«å
¥å2">ãµã³ãã«å
¥å2</h3>
<pre>2
0 1 0 0 0
10 1 1 0 0
</pre>
<h3 id="ãµã³ãã«åºå2">ãµã³ãã«åºå2</h3>
<pre>-1 -1
-1 -1
</pre>
<h3 id="ãµã³ãã«å
¥å3">ãµã³ãã«å
¥å3</h3>
<pre>3
0 1 0 0 0
30 2 0 1 1
40 1 0 2 2
</pre>
<h3 id="ãµã³ãã«åºå3">ãµã³ãã«åºå3</h3>
<pre>1.4142135624 0.1666666667
-1 -1
</pre>
<h3 id="ãµã³ãã«å
¥å4">ãµã³ãã«å
¥å4</h3>
<pre>3
0 1 0 0 0
10 2 0 1 1
40 1 0 3 3
</pre>
<h3 id="ãµã³ãã«åºå4">ãµã³ãã«åºå4</h3>
<pre>2.8284271247 0.5000000000
-1 -1
</pre> |
p02849 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has come to an integer shop to buy an integer.</p>
<p>The shop sells the integers from <var>1</var> through <var>10^9</var>. The integer <var>N</var> is sold for <var>A \times N + B \times d(N)</var> yen (the currency of Japan), where <var>d(N)</var> is the number of digits in the decimal notation of <var>N</var>.</p>
<p>Find the largest integer that Takahashi can buy when he has <var>X</var> yen. If no integer can be bought, print <var>0</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A \leq 10^9</var></li>
<li><var>1 \leq B \leq 10^9</var></li>
<li><var>1 \leq X \leq 10^{18}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the greatest integer that Takahashi can buy. If no integer can be bought, print <var>0</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 7 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>The integer <var>9</var> is sold for <var>10 \times 9 + 7 \times 1 = 97</var> yen, and this is the greatest integer that can be bought.
Some of the other integers are sold for the following prices:</p>
<ul>
<li><var>10: 10 \times 10 + 7 \times 2 = 114</var> yen</li>
<li><var>100: 10 \times 100 + 7 \times 3 = 1021</var> yen</li>
<li><var>12345: 10 \times 12345 + 7 \times 5 = 123485</var> yen</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 1 100000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000000000
</pre>
<p>He can buy the largest integer that is sold. Note that input may not fit into a <var>32</var>-bit integer type.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000000000 1000000000 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1234 56789 314159265
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>254309
</pre></section>
</div>
</span> |
p00874 |
<H1><font color="#000">Problem A:</font> Cubist Artwork</H1>
<p>
<i>International Center for Picassonian Cubism</i> is a Spanish national museum of cubist artworks,
dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed
in front of the facade of the museum building. The artwork is a collection of cubes that are
piled up on the ground and is intended to amuse visitors, who will be curious how the shape of
the collection of cubes changes when it is seen from the front and the sides.
</p>
<p>
The artwork is a collection of cubes with edges of one foot long and is built on a flat ground
that is divided into a grid of one foot by one foot squares. Due to some technical reasons, cubes
of the artwork must be either put on the ground, fitting into a unit square in the grid, or put
on another cube in the way that the bottom face of the upper cube exactly meets the top face
of the lower cube. No other way of putting cubes is possible.
</p>
<p>
You are a member of the judging committee responsible for selecting one out of a plenty of
artwork proposals submitted to the competition. The decision is made primarily based on
artistic quality but the cost for installing the artwork is another important factor. Your task is
to investigate the installation cost for each proposal. The cost is proportional to the number of
cubes, so you have to figure out the minimum number of cubes needed for installation.
</p>
<p>
Each design proposal of an artwork consists of the front view and the side view (the view seen
from the right-hand side), as shown in Figure 1.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork1"><br>
<p>Figure 1: An example of an artwork proposal</p>
</center>
<p>
The front view (resp., the side view) indicates the maximum heights of piles of cubes for each
column line (resp., row line) of the grid.
</p>
<p>
There are several ways to install this proposal of artwork, such as the following figures.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork2"><br>
</center>
<p>
In these figures, the dotted lines on the ground indicate the grid lines. The left figure makes use
of 16 cubes, which is not optimal. That is, the artwork can be installed with a fewer number
of cubes. Actually, the right one is optimal and only uses 13 cubes. Note that, a single pile of
height three in the right figure plays the roles of two such piles in the left one.
</p>
<p>
Notice that swapping columns of cubes does not change the side view. Similarly, swapping
rows does not change the front view. Thus, such swaps do not change the costs of building the
artworks.
</p>
<p>
For example, consider the artwork proposal given in Figure 2.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork3"><br>
<p>Figure 2: Another example of artwork proposal</p>
</center>
<p>
An optimal installation of this proposal of artwork can be achieved with 13 cubes, as shown
in the following figure, which can be obtained by exchanging the rightmost two columns of the
optimal installation of the artwork of Figure 1.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubistArtwork4"><br>
</center>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The end of the input is indicated by a line containing two
zeros separated by a space. Each dataset is formatted as follows.
</p>
<p>
<i>w d</i><br>
<i>h</i><sub>1</sub> <i>h</i><sub>2</sub> ... <i>h<sub>w</sub></i><br>
<i>h'</i><sub>1</sub> <i>h'</i><sub>2</sub> ... <i>h'<sub>d</sub></i><br>
</p>
<p>
The integers <i>w</i> and <i>d</i> separated by a space are the numbers of columns and rows of the grid,
respectively. You may assume 1 ≤ <i>w</i> ≤ 10 and 1 ≤ <i>d</i> ≤ 10. The integers separated by a space
in the second and third lines specify the shape of the artwork. The integers <i>h<sub>i</sub></i> (1 ≤ <i>h<sub>i</sub></i> ≤ 20,
1 ≤ <i>i</i> ≤ <i>w</i>) in the second line give the front view, i.e., the maximum heights of cubes per each
column line, ordered from left to right (seen from the front). The integers <i>h<sub>i</sub></i> (1 ≤ <i>h<sub>i</sub></i> ≤ 20,
1 ≤ <i>i</i> ≤ <i>d</i>) in the third line give the side view, i.e., the maximum heights of cubes per each row
line, ordered from left to right (seen from the right-hand side).
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing the minimum number of cubes. The output should
not contain any other extra characters.
</p>
<p>
You can assume that, for each dataset, there is at least one way to install the artwork.
</p>
<H2>Sample Input</H2>
<pre>
5 5
1 2 3 4 5
1 2 3 4 5
5 5
2 5 4 1 3
4 1 5 3 2
5 5
1 2 3 4 5
3 3 3 4 5
3 3
7 7 7
7 7 7
3 3
4 4 4
4 3 4
4 3
4 2 2 4
4 2 1
4 4
2 8 8 8
2 3 8 3
10 10
9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9
10 9
20 1 20 20 20 20 20 18 20 20
20 20 20 20 7 20 20 20 20
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
15
15
21
21
15
13
32
90
186
</pre>
|
p01336 |
<h1><font color="#000">Problem D:</font>THE BYDOLM@STER</h1>
<h2>Description</h2>
<!-- <div style="float:right"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/uvcs_static_image_03D_2" alt="ããã±ã©ããã¹" width=400 height=260></div> -->
<p>THE BYDOLM@STER(ãã€ãã«ãã¹ã¿ãŒ)ãšã¯1rem瀟ãã2010/4/1ã«EXIDNAã§çºå£²ãäºå®ãããŠããè²æã·ãã¥ã¬ãŒã·ã§ã³ã²ãŒã ã§ãããäžå¿æã£ãŠãããã仿åãã«ãããã¯ãŒã¯æ¥ç¶ãµãŒãã¹ã忢ããæã¢ãŒã±ãŒãã²ãŒã ãšã¯ãã¶ãé¢ä¿ãç¡ãã<br>
ãã®ã²ãŒã ã¯ãã€ãã«ãã¡ãããããã¥ãŒã¹ãããŠããã(ç·šé)ã®ã¡ã³ããŒãéžæããã¡ã³ããŒãã¡ãšã®ã¬ãã¹ã³ãã³ãã¥ãã±ãŒã·ã§ã³ãéããŠã圌女(圌)ãããã€ãã«ã®é ç¹ãããããã€ãã«ã«è²ãŠäžããã²ãŒã ã§ããã<!--å³ã®åçã¯ããããã€ãã«ã®å
ã®äžäœãâããã±ã©ããã¹âã®ãã£ã®ã¥ã¢ã§ããã--><br>
åãã€ãã«ã«ã¯èœåå€ãšããŠããŒã«ã«ããã³ã¹ãã«ãã¯ã¹ã®3ã€ã®ãã©ã¡ãŒã¿ãæã¡ããŠãããã®èœåå€ã¯ãŠãããã«å±ããŠããå
šãŠã®ãã€ãã«ã®ãã©ã¡ãŒã¿ã®åèšå€ãšãªãããŠãããã®3ã€ã®èœåå€ã®ãã¡æå€§ã®ç©ããŠãããã®ã©ã³ã¯ãšãªãã<br>
ãŠãããã«äººæ°å¶éã¯ç¡ããã¡ã³ããŒã®äººæ°ã1äœã§ãã3äœã§ãã100äœã§ããŠããããšããŠæŽ»åã§ããããã¡ããåããã€ãã«ãè€æ°éãããšåºæ¥ããããã€ãã«ãéãããã«ã¯è²»çšããããã®ã§ãããèæ
®ã«å
¥ããªããã°ãªããªãã<br>
ãããã¥ãŒãµãŒã§ããããªãã¯æé«ã®ãŠããããäœãããã«ããã°ã©ã ãæžããŠèšç®ããããšã«ããã</p>
<h2>Input</h2>
<p>å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã<br>
åãã¹ãã±ãŒã¹ã®1è¡ç®ã«ã¯ãã€ãã«ã®æ°Nãšäœ¿çšå¯èœãªè²»çšMãäžããããã(1<=N,M<=300)
次ã®2*Nè¡ã«ã¯åãã€ãã«ã«é¢ããŠã®æ
å ±ãæžãããŠããã<br>
ãã€ãã«ã®æ
å ±ã®1è¡ç®ã«ã¯ãã€ãã«ã®ååããã€ãã«ã®ååã¯ã¢ã«ãã¡ããããšç©ºçœããæãã30æåã以äžã§ããããŸãåäžåã®ãã€ãã«ã¯ååšããªãã<br>
2è¡ç®ã«ã¯æŽæ°CãVãDãLãäžãããããCã¯ãã®ãã€ãã«ã1äœéçšããã³ã¹ããVã¯ããŒã«ã«ãDã¯ãã³ã¹ãLã¯ã«ãã¯ã¹ã®èœåå€ã衚ãã(1<=C,V,D,L<=300)<br>
å
¥åã¯EOFã§çµããã</p>
<h2>Output</h2>
<p>äžããããè²»çšã®äžã§äœãããŠãããã®ã©ã³ã¯ã®æå€§å€ãçããã<br>
ãŠããããäœããªãå Žåã¯0ãåºåããã</p>
<h2>Sample Input</h2>
<pre>
3 10
Dobkeradops
7 5 23 10
PataPata
1 1 2 1
dop
5 3 11 14
2 300
Bydo System Alpha
7 11 4 7
Green Inferno
300 300 300 300
</pre>
<h2>Output for Sample Input</h2>
<pre>
29
462
</pre>
|
p00177 |
<H1>ïŒéœåžéã®è·é¢</H1>
<p>
å°çäžã®2 éœåžã®åç·¯ãšæ±çµãå
¥åãšããå°è¡šè·é¢ãèšç®ããŠåºåããããã°ã©ã ãäœæããŠãã ããããã ããå°çã¯ååŸ 6,378.1 km ã®çãšãã2 ç¹éã®å°è¡šè·é¢ãšã¯ãã®çé¢ã«æ²¿ã£ãæçè·é¢ã§ãããŸããååçã§ãåç·¯ã¯çšããã«åç·¯ 0 ~ -90 床ãçšããã°ãªãããžååç·ã®è¥¿ã§ã西çµã¯çšããã«æ±çµ 180 ~ 360 床ãçšããããšãšããŸããå°è¡šè·é¢ã¯ km åäœã§æ±ããå°æ°ç¹ä»¥äžã¯åæšäºå
¥ããæŽæ°å€ãšããŠåºåããŠãã ããã
</p>
<p>
以äžã«äž»èŠéœåžã®åç·¯ãæ±çµã®äŸã瀺ããŸãã
</p>
<center>
<table>
<tr><th width="120">å°å</th><th width="100"> åç·¯(床)</th><th width="100"> æ±çµ(床)</th></tr>
<tr><th>æ±äº¬</th><th> 35.68</th><th> 139.77</th></tr>
<tr><th> ã·ã³ã¬ããŒã«</th><th> 1.37</th><th> 103.92</th></tr>
<tr><th> ã·ãããŒ</th><th> -33.95 </th><th>151.18</th></tr>
<tr><th> ã·ã«ãŽ </th><th> 41.78</th><th> 272.25</th></tr>
<tr><th>ããšãã¹ã¢ã€ã¬ã¹ </th><th> -34.58</th><th> 301.52</th></tr>
<tr><th> ãã³ãã³ </th><th> 51.15</th><th> 359.82</th></tr>
</table>
</center>
<br/>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯-1 åã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>a</var> <var>b</var> <var>c</var> <var>d</var>
</pre>
<p>
1 è¡ã«ç¬¬ 1 ã®éœåžã®åç·¯ <var>a</var>ã第 1 ã®éœåžã®æ±çµ <var>b</var>ã第 2 ã®éœåžã®åç·¯ <var>c</var>ã第 2 ã®éœåžã®æ±çµ <var>d</var> ã空çœåºåãã§äžããããŸããå
¥åã¯ãã¹ãŠå®æ°ã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 30 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã« 2 éœåžã®å°è¡šè·é¢ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
35.68 139.77 51.15 359.82
1.37 103.92 41.78 272.25
51.15 359.82 -34.58 301.52
-1 -1 -1 -1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
9609
15092
11112
</pre>
|
p00527 |
<h2>IOI åè»ã§è¡ãã(Take the 'IOI' train)</h2>
<p>
IOI åœã§ã¯ãã®ãã³æ°ãã«ééãæ·èšããïŒIOI åœã®ééãèµ°ãåè»ã¯ããã€ãã®è»äž¡ãé£çµããããã®ã§ããïŒè»äž¡ã«ã¯ <span>I</span>, <span>O</span> ã® 2 çš®é¡ãããïŒè»äž¡ã¯ããããç°ãªãçš®é¡ã®è»äž¡ãšããé£çµã§ããªãïŒãŸãïŒåè»ã«é転åžãèšããé¢ä¿äžïŒåè»ã®äž¡ç«¯ã®è»äž¡ã¯çš®é¡ <span>I</span> ã§ãªããã°ãªããªãïŒåè»ã¯è»äž¡ã®çš®é¡ã衚ãæåãé ã«ã€ãªããæååã§è¡šããïŒåè»ã®é·ãã¯ãã®æååã®é·ãã§ãããšããïŒããšãã°ïŒ <span>IOIOI</span> ã®é ã«è»äž¡ãé£çµãããšé·ã 5 ã®åè»ãç·šæã§ãïŒãŸãè»äž¡ <span>I</span> ã¯åç¬ã§é·ã 1 ã®åè»ã§ããïŒè»äž¡ã <span>OIOI</span> ã <span>IOOI</span> ãšãã£ãé ã«äžŠã¹ãŠãåè»ãç·šæããããšã¯ã§ããªãïŒ
</p>
<p>
ããã€ãã®è»äž¡ã 2 ã€ã®è»åº«ã«æ ŒçŽãããŠããïŒããããã®è»åº«ã®äžã«ã¯è»äž¡ãäžåã«äžŠãã§ããïŒåè»ãç·šæãããšãã¯è»åº«ããè»äž¡ãåºããŠããŠè»åº«åã§é£çµããŠããïŒè»åº«ããåºããè»äž¡ã¯æãè»åº«ã®å
¥ãå£ã«è¿ãè»äž¡ã®ã¿ã§ãããïŒã©ã¡ãã®è»åº«ããè»äž¡ãåºããã®é çªã«ã€ããŠã¯èªç±ã§ããïŒ
</p>
<p>
åè»ãç·šæããåã«ïŒè»äž¡ã奜ããªã ãè»åº«ããåºããŠå¥ã®åŸ
æ©çšã¬ãŒã«ã«ç§»ãããšãã§ããïŒäžåºŠåŸ
æ©çšã¬ãŒã«ã«ç§»ããè»äž¡ã¯ä»åŸåè»ãç·šæããããã«äœ¿ãããšã¯ã§ããªãïŒãŸãïŒäžåºŠåè»ã®ç·šæãå§ãããšãã®ç·šæãçµãããŸã§ã®éã¯è»äž¡ãè»åº«ããåŸ
æ©çšã¬ãŒã«ã«ç§»ãããšã¯ã§ããªãïŒ
</p>
<p>
åè»ãç·šæãããšãïŒè»åº«å
ã®å
šãŠã®è»äž¡ã䜿ãåãå¿
èŠã¯ãªãïŒããªãã¡ïŒåè»ã®ç·šæãçµããåŸïŒè»åº«å
ã«äœ¿ãããªãã£ãè»äž¡ãæ®ã£ãŠããŠãæ§ããªãïŒ
</p>
<p>
IOI åœã§ã¯ééã«ä¹ã人ããšãŠããããããããšèããããŠããã®ã§ïŒã§ããã ãé·ãåè»ãç·šæãããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_2">
</center>
<br>
<p>
å³: åè»ãç·šæããŠããéäžã§ããïŒãã®ãšãè»åº«ã«ããè»äž¡ãåŸ
æ©çšã¬ãŒã«ã«ç§»ãããšã¯ã§ããªãïŒãã®å³ã¯å
¥åºåäŸ1 ã«å¯Ÿå¿ããŠããïŒ
</p>
<h3>課é¡</h3>
<p>
è»åº«ã«æ ŒçŽãããè»äž¡ã®æ
å ±ãäžãããããšãïŒç·šæã§ããåè»ã®é·ãã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒããããã®è»åº«ã«æ ŒçŽãããè»äž¡ã®å㯠2 çš®é¡ã®æå<span>I</span>, <span>O</span> ã®ã¿ãããªãæååã§è¡šããïŒ 2 ã€ã®è»åº«ã®æ
å ±ã¯ããããé·ã <var>M</var> ã®æåå <var>S</var> ããã³é·ã <var>N</var> ã®æåå <var>T</var> ãšããŠäžããããïŒåæåã 1 ã€ã®è»äž¡ã衚ãïŒãã®æåã¯è»äž¡ã®çš®é¡ãšåãã§ããïŒæååã®1 æåç®ã¯æãè»åº«ã®å
¥ãå£ã«è¿ãè»äž¡ã衚ãïŒæ«å°Ÿã®æåãè»åº«ã®æã奥ã«ããè»äž¡ã衚ãïŒ
</p>
<h3>å¶é</h3>
<ul>
<li>1 ≤ <var>M</var> ≤ 2000 æåå <var>S</var> ã®é·ã</li>
<li>1 ≤ <var>N</var> ≤ 2000 æåå <var>T</var> ã®é·ã</li>
</ul>
<h3>å
¥å</h3>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ <var>M</var>, <var>N</var> ã空çœåºåãã§æžãããŠããïŒ</li>
<li> 2 è¡ç®ã«ã¯æåå <var>S</var> ãæžãããŠããïŒ</li>
<li> 3 è¡ç®ã«ã¯æåå <var>T</var> ãæžãããŠããïŒ</li>
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«ïŒç·šæã§ããåè»ã®é·ãã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ åè»ã 1 ã€ãç·šæã§ããªãå Žåã¯ïŒ 0 ãåºåããïŒ
</p>
<h3>å
¥åºåäŸ</h3>
<h3>å
¥åäŸ 1</h3>
<pre>
5 5
OIOOI
OOIOI
</pre>
<h3> åºåäŸ 1</h3>
<pre>
7
</pre>
<p>
<var>S</var> ã«ãã£ãŠè¡šãããè»åº«ãè»åº« S ãšãïŒ<var>T</var> ã«ãã£ãŠè¡šãããè»åº«ãè»åº« T ãšãããïŒãã®ãšãïŒããšãã°è»åº« S ããæåã®1 è»äž¡ïŒè»åº« T ããæåã® 2 è»äž¡ãåºããŠåŸ
æ©ãããåŸïŒè»åº« SïŒè»åº« SïŒè»åº« TïŒè»åº« SïŒè»åº« SïŒè»åº« TïŒè»åº« T ã®é çªã«è»äž¡ãåºãã°ïŒé·ã7 ã®åè» <span>IOIOIOI</span> ãç·šæã§ããïŒ
</p>
<p>
ä»ã«ãïŒè»åº« S ããæåã® 1 è»äž¡ïŒè»åº« T ããæåã® 2 è»äž¡ãåºããŠåŸ
æ©ãããåŸïŒè»åº« TïŒè»åº« TïŒè»åº« SïŒè»åº« SïŒè»åº« TïŒè»åº« SïŒè»åº« S ã®é çªã«è»äž¡ãåºãããšã§ãé·ã 7 ã®åè»ãç·šæã§ããïŒããããé·ãåè»ãç·šæããããšã¯ã§ããªãã®ã§ 7 ãåºåããïŒ
</p>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
5 9
IIIII
IIIIIIIII
</pre>
<h3>åºåäŸ 2</h3>
<pre>
1
</pre>
<p>
1 ã€ã®è»äž¡ã®ã¿ãããªãåè» <span>I</span> ãåè»ãšããŠã®æ¡ä»¶ãæºããããšã«æ³šæããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00032 |
<H1>ãã©ã¹ãã£ãã¯æ¿</H1>
<p>
æ©æ¢°ã«èŸºã»å¯Ÿè§ç·ã®é·ãã®ããŒã¿ãå
¥åãããã©ã¹ãã£ãã¯æ¿ã®åæããããŠããå·¥å ŽããããŸãããã®å·¥å Žã§ã¯ããµã€ãºã¯æ§ã
ã§ãããå¹³è¡å蟺圢ã®åã®ã¿ãåãåºããŠããŸããããªãã¯ãåãåºãããå¹³è¡å蟺圢ã®ãã¡ãé·æ¹åœ¢ãšã²ã圢ã®è£œé åæ°ãæ°ããããã«äžåžããåœããããŸããã
</p>
<p>
ãæ©æ¢°ã«å
¥åããããŒã¿ããèªã¿èŸŒãã§ãé·æ¹åœ¢ãšã²ã圢ã®è£œé åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_plastic"></center>
<br/>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>,<var>c<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>,<var>c<sub>2</sub></var>
:
</pre>
<p>
æ©æ¢°ã«å
¥åããããŒã¿ãè€æ°è¡ã«äžããããŸãã<var>i</var> è¡ç®ã« <var>i</var> çªç®ã®å¹³è¡å蟺圢ã®é£ãåãïŒèŸºã®é·ããè¡šãæŽæ° <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> ãšå¯Ÿè§ç·ã®é·ããè¡šãæŽæ° <var>c<sub>i</sub></var> ãã«ã³ãåºåãã§äžããããŸã (1 ≤ <var>a<sub>i</sub>, b<sub>i</sub>, c<sub>i</sub></var> ≤ 1000, <var>a<sub>i</sub> + b<sub>i</sub></var> > <var>c<sub>i</sub></var>)ãããŒã¿ã®æ°ã¯ 100 ä»¶ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ïŒè¡ç®ã«é·æ¹åœ¢ã®è£œé åæ°ãïŒè¡ç®ã²ã圢ã®è£œé åæ°ãåºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
3,4,5
5,5,8
4,4,4
5,4,3
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
2
</pre>
|
p00462 |
<H1>ãã¶ </H1>
<h2>åé¡</h2>
<p>
JOI ãã¶ã§ã¯,åžã®äžå¿éšãéãå
šé· <i>d</i> ã¡ãŒãã«ã®ç°ç¶ç·ã®æ²¿ç·äžã§ãã¶ã®å®
é
販
売ãè¡ã£ãŠãã.
</p>
<p>
JOI ãã¶ã¯,ç°ç¶ç·äžã« <i>n</i> åã®åºè <i>S</i><sub>1</sub>, ... , <i>S<sub>n</sub></i> ãæã€.æ¬åºã¯ <i>S</i><sub>1</sub> ã§ãã. <i>S</i><sub>1</sub> ãã <i>S<sub>i</sub></i> ãŸã§,æèšåãã«ç°ç¶ç·ãç§»åãããšãã®éã®ãã <i>d<sub>i</sub></i> ã¡ãŒãã«ãšãã. <i>d</i><sub>2</sub>, ... , <i>d<sub>n</sub></i> 㯠1 ä»¥äž <i>d</i> - 1 以äžã®æŽæ°ã§ãã. <i>d</i><sub>2</sub> , ... , <i>d<sub>n</sub></i> ã¯å
šãŠç°ãªã. ãã¶ã®æ³šæãåãããš, ãã¶ãå·ããªãããã«, å®
é
å
ãŸã§ã®ç§»åè·é¢ããã£ãšãçãåºèã§ãã¶ãçŒãå®
é
ãã.
</p>
<p>
å®
é
å
ã®äœçœ®ã¯ 0 ä»¥äž <i>d</i> - 1 以äžã®æŽæ° <i>k</i> ã§è¡šããã.ããã¯, æ¬åº <i>S</i><sub>1</sub> ããå®
é
å
ãŸã§ã«æèšåãã§ç°ç¶ç·ãç§»åãããšãã®éã®ãã <i>k</i> ã¡ãŒãã«ã§ããããšãæå³ãã. ãã¶ã®å®
é
ã¯ç°ç¶ç·ã«æ²¿ã£ãŠè¡ãã, ãã以å€ã®éãéãããšã¯èš±ãããªã. ãã ã, ç°ç¶ç·äžã¯æèšåãã«ç§»åããŠãåæèšåãã«ç§»åããŠããã.
</p>
<p>
äŸãã°,åºèã®äœçœ®ãšå®
é
å
ã®äœçœ®ãäžå³ã®ããã«ãªã£ãŠããå Žå (ãã®äŸã¯ãå
¥åºåã®äŸãã®äŸ 1 ãšå¯Ÿå¿ããŠãã),
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pizza">
</center>
<br>
<p>
å®
é
å
1 ã«ãã£ãšãè¿ãåºè㯠<i>S</i><sub>2</sub> ãªã®ã§, åºè <i>S</i><sub>2</sub> ããå®
é
ãã.ãã®ãšã, åºèããã®ç§»åè·é¢ã¯ 1 ã§ãã.ãŸã, å®
é
å
2 ã«ãã£ãšãè¿ãåºè㯠<i>S</i><sub>1</sub> (æ¬åº) ãªã®ã§, åºè <i>S</i><sub>1</sub> (æ¬åº) ããå®
é
ãã.ãã®ãšã,åºèããã®ç§»åè·é¢ã¯ 2 ã§ãã.
</p>
<p>
ç°ç¶ç·ã®å
šé· <i>d</i>, JOI ãã¶ã®åºèã®åæ° <i>n</i>, 泚æã®åæ° <i>m</i>, æ¬åºä»¥å€ã®äœçœ®ã衚ã <i>n</i> - 1 åã®æŽæ° <i>d</i><sub>2</sub>, ... , <i>d<sub>n</sub></i> , å®
é
å
ã®å Žæãè¡šãæŽæ° <i>k</i><sub>1</sub>, ... , <i>k<sub>m</sub></i> ãäžãããããšã, åæ³šæã«å¯Ÿããå®
é
æã®ç§»åè·é¢ (ããªãã¡,æå¯åºèããå®
é
å
ãŸã§ã®éã®ã) ã®å
šæ³šæã«ãããç·åãæ±ããããã°ã©ã ãäœæãã.
</p>
<h2>å
¥å</h2>
<p>
<!-- å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠input.txt ã§ãã.<br>-->
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
1 è¡ç®ã«ã¯ç°ç¶ç·ã®å
šé·ãè¡šãæ£æŽæ° <i>d</i> (2 ≤ <i>d</i> ≤ 1000000000 = 10<sup>9</sup> ), 2 è¡ç®ã«ã¯åºèã®åæ°ãè¡šãæ£æŽæ° <i>n</i> (2 ≤ <i>n</i> ≤ 100000), 3 è¡ç®ã«ã¯æ³šæã®åæ°ãè¡šãæ£æŽæ° <i>m</i> (1 ≤ <i>m</i> ≤ 10000) ãæžãããŠãã. 4 è¡ç®ä»¥éã® <i>n</i> - 1 è¡ã«ã¯æ¬åºä»¥å€ã®åºèã®äœçœ®ãè¡šãæŽæ° <i>d</i><sub>2</sub>, <i>d</i><sub>3</sub>, ... , <i>d</i><sub>n</sub> (1 ≤ <i>d<sub>i</sub></i> ≤ <i>d</i> - 1) ããã®é ã«æžãããŠãã, <i>n</i> + 3 è¡ç®ä»¥éã® <i>m</i> è¡ã«ã¯å®
é
å
ã®å Žæãè¡šãæŽæ° <i>k</i><sub>1</sub>, <i>k</i><sub>2</sub>, ... , <i>k<sub>m</sub></i> (0 ≤ <i>k<sub>i</sub></i> ≤ <i>d</i> - 1) ããã®é ã«æžãããŠãã.
</p>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡,é
ç¹ã® 40% åã«ã€ããŠã¯, n ≤ 10000 ãæºãã. ãŸã,é
ç¹ã® 40% åã«ã€ããŠã¯, æ±ããç§»åè·é¢ã®ç·åãš <i>d</i> ã®å€ã¯ãšãã« 1000000 以äžã§ãã. ããã«,å
šãŠã®æ¡ç¹çšããŒã¿ã«ãããŠ, æ±ããç§»åè·é¢ã®ç·å㯠1000000000 = 10<sup>9</sup>以äžã§ãã.
</p>
<p>
<i>d</i> ã 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
<!--
åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠output.txt ã§ãã.<br>
output.txt ã¯,å®
é
æã®ç§»åè·é¢ã®ç·åã衚ã 1 ã€ã®æŽæ°ã®ã¿ãå«ã 1 è¡ãããªã.
-->
ããŒã¿ã»ããããšã«,å®
é
æã®ç§»åè·é¢ã®ç·åã衚ã 1 ã€ã®æŽæ°ã1 è¡ã«åºåãã.
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0
</pre>
<h3>åºåäŸ</h3>
<pre>
3
3
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div> |
p00198 |
<h1>ç«æ¹äœã®äœå</h1>
<p>
èžè¡å®¶åå·ã¯ <var>n</var> ç¹ã®äœåãåºå±ããããã«äŸé ŒãããŸãããããã§ãç«æ¹äœã® 6 é¢ããã³ãã§è²ä»ããããã®ãäœåãšããŠåºå±ããããšã«ããŸãããäœåã¯ãRedãYellowãBlueãMagentaãGreenãCyan ã® 6 è²å
šãŠã䜿ãããŠããŠãåé¢ã¯ 1 è²ã§å¡ãã€ã¶ãããŠããŸããåå·ã¯åœ¢ãåãç«æ¹äœã®äœåã§ãè²ã®é
眮ã®ä»æ¹ãå€ããç°ãªãäœåãšã㊠<var>n</var> ç¹äœæããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_shinagawa1"><br/>
</center>
<br/>
<p>
圌ã®å人ã§ããããªãã¯ãå人ã®ããã¿ã§äœåãåºå±åã«é²èЧãããŠããããŸããããããã§ããããšã«æ°ãä»ããŸããããããã®äœåã®äžã«ç°ãªãè²ä»ãããããŠããããã«èŠããŠããå®ã¯åãè²ã®çµã¿åãããããç«æ¹äœãååšããŠããã®ã§ãããã®ãŸãŸã§ã¯ã <var>n</var> ç¹ã®äœåãåºå±ããããšã§ããªããªã£ãŠããŸããŸãã
</p>
<p>
äœæããäœåã®æ°ãšåäœåã®è²ã®æ
å ±ãå
¥åãšããåºå±ããããã«ããšäœç¹å¿
èŠããåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
ç«æ¹äœã®åé¢ã®è²ã¯ c1 ãã c6 ãŸã§ã®èšå·ã§è¡šããã 以äžã®ãããªé
眮ãšãªã£ãŠããŸãããŸããc1 ãã c6 ã®ãããã㯠RedãYellowãBlueãMagentaãGreenãCyan ã®ãããã 1 è²ãšãªããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_shinagawa2"><br/>
</center>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>cube<sub>1</sub></var>
<var>cube<sub>2</sub></var>
:
<var>cube<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«äœåã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 30)ãç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®äœåã®æ
å ±ãäžããããŸããåäœåã®æ
å ±ã¯æ¬¡ã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
c1 c2 c3 c4 c5 c6
</pre>
<p>
äœåã®è²ã®é
眮 c<sub><var>i</var></sub> ã空çœåºåãã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ãåºå±ããã®ã«ããšäœç¹ã®äœåãå¿
èŠããïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
3
Cyan Yellow Red Magenta Green Blue
Cyan Yellow Red Magenta Green Blue
Red Yellow Magenta Blue Green Cyan
4
Red Magenta Blue Green Yellow Cyan
Red Yellow Magenta Blue Green Cyan
Magenta Green Red Cyan Yellow Blue
Cyan Green Yellow Blue Magenta Red
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
1
</pre>
|
p01623 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script
<!--
<h3><u>Sinking islands</u></h3>
-->
<!-- end en only -->
<!-- begin ja only -->
<h1><u>æ²ã¿ããå³¶</u></h1>
<!-- end ja only -->
<!-- begin en only -->
<!--
<p>
English text is not available in this practice contest.
</p>
-->
<!-- end en only -->
<!-- begin ja only -->
<p>
ãšããæµ·åã«ïŒãã¹ã諞島ãšåŒã°ããçŸããèªç¶ãšè±ããªè³æºã«æµãŸããå³¶ã
ãããïŒ
æ°åãæž©æã§ããããïŒäººã
ã¯ããã§é·ãã«æž¡ã£ãŠå¹³åãªæ®ãããå¶ãã§ããïŒ
ãããïŒæè¿ã«ãªã£ãŠå€§å€ãªäºå®ã倿ããïŒ
å°æ®»å€åã«ãã£ãŠïŒãã¹ã諞島ã®å³¶ã
ãé ãããæ²æ²¡ããŠããŸããšããã®ã ïŒ<br>
</p>
<p>
ãã®äºæ
ã«å¯Ÿå¿ããããïŒåå³¶ã®ä»£è¡šãããªãå¯Ÿçæ¬éšãçµæãããïŒ
ãŸãïŒèª¿æ»éã®åãã«ããåå³¶ããã€æ²æ²¡ããŠããŸãããæããã«ãªã£ãïŒ
ãŸãïŒãã¹ãè«žå³¶ã®æè¡ãçµéããããšã§ïŒããã€ãã®å³¶ã®éã«ã¯æ©ãæ¶ããããããšãåãã£ãïŒ
ãã®çµæïŒå³¶ã®éã«æ©ãæ¶ãïŒåå³¶ã®äœæ°ãç¹å®ã®å³¶ã«é¿é£ã§ããããã«ããããšã«æ±ºãŸã£ãïŒ<br>
</p>
<p>
çŸæ®µéã§ïŒã©ã®å³¶ãé¿é£å
ã«ãããã¯æ±ºãŸã£ãŠããªããããïŒ
ãã®ããïŒæåã¯ã©ã®å³¶ãé¿é£å
ã«ãªã£ãŠãè¯ãããïŒã©ã®å³¶ãããããã€ãã®æ©ãæž¡ãããšã§ä»ã®å
šãŠã®å³¶ã«è¡ããããã«æ©ãæ¶ããïŒ
æéã®çµéã«ãã£ãŠå³¶ãæ²ãã ãšãïŒäž¡ç«¯ã®å³¶ãäžæ¹ã§ãæ²ãã æ©ã¯éè¡ã§ããªããªãïŒ
ãã®ãšãïŒæåã®æ©ã®æ¶ãæ¹ã«ãã£ãŠã¯ïŒããå³¶ãã蟿ãã€ããªããããªå³¶ãã§ããŠããŸãå ŽåãããïŒ
ãã®å Žåã¯ïŒæ°ãã«æ©ãæ¶ããããšã§ïŒãŸã æ²ãã§ããªãå³¶ã
ã®éã§ç§»åçµè·¯ã確ä¿ã§ããããã«ããïŒ
ã©ã®ããã«æ©ãæ¶ããŠãç§»åçµè·¯ã確ä¿ã§ããªããªã£ãå Žåã¯ïŒãã以äžã®æ©ã®å»ºèšã¯è¡ããªãïŒ
å¯Ÿçæ¬éšã¯ïŒãããŸã§ã«é¿é£å
ãæ±ºãïŒäœæ°ã®é¿é£ãå®äºãããªããŠã¯ãªããªãã ããïŒ
ãªãïŒçŸæç¹ã§æ¢ã«ç§»åçµè·¯ã確ä¿ããããã«æ©ãæ¶ããäºãåºæ¥ãªãå Žåã¯ïŒæ©ã®å»ºèšã¯äžåè¡ããªãïŒ
å¯Ÿçæ¬éšã¯æ°ããªæ¡ãç·Žãããšã«ãªãã ããïŒ<br>
</p>
<p>
ãšããã§ïŒæ©ã¯æ¶ããäœçœ®ã«ãã£ãŠå»ºèšè²»çšã決ãŸã£ãŠããïŒ
é¿é£ã«ã¯äœããšè²»çšããããã®ã§ïŒå¯Ÿçæ¬éšã§ã¯æ©ã®å»ºèšè²»çšã®åèšããªãã¹ãå°ãããªãããã«æ©ãæ¶ããããšèããŠããããã ïŒ
ãã®ããã«ã¯ã©ã®ããã«æ©ãæ¶ããã°è¯ãã ãããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒåããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ
</p>
<pre>
<var>N</var> <var>M</var>
<var>h<sub>1</sub></var>
<var>h<sub>2</sub></var>
<var>...</var>
<var>h<sub>N</sub></var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var>
<var>...</var>
<var>a<sub>M</sub></var> <var>b<sub>M</sub></var> <var>c<sub>M</sub></var>
</pre>
<p>
N ã¯å³¶ã®æ°ãè¡šãæŽæ°ã§ããïŒ2 ä»¥äž 200 以äžãšä»®å®ããŠè¯ãïŒ
ãŸãïŒåå³¶ã«ã¯ 1 ãã N ã®æ°åãå²ãæ¯ãããŠããïŒ
M ã¯æ©ã建èšã§ããå³¶ã®ãã¢ã®æ°ã衚ã 1 以äžã®æŽæ°ã§ããïŒ<br>
</p>
<p>
ç¶ã N è¡ã«ã¯åå³¶ããã€æ²æ²¡ãããã瀺ãæ
å ±ãäžããããïŒ
h<sub>i</sub> ã¯å³¶ i ã h<sub>i</sub> æ¥åŸã«æ²ããšããäºãè¡šãæŽæ°ã§ããïŒ1 ä»¥äž 1,000,000 以äžãšä»®å®ããŠè¯ãïŒ
åæã«è€æ°ã®å³¶ãæ²ãå ŽåãããïŒ<br>
</p>
<p>
ç¶ã M è¡ã¯å»ºèšã§ããæ©ã®æ
å ±ã衚ãïŒ
åè¡ã¯ã¹ããŒã¹ã§åºåããã 3 ã€ã®æŽæ°ãå«ã¿ïŒa<sub>i</sub> ãš b<sub>i</sub> ãæ©ã®äž¡ç«¯ã®å³¶ã®çªå·ïŒc<sub>i</sub> ãæ©ã®å»ºèšè²»çšã§ãã(1 ≤ i ≤ M)ïŒ
åæ©ã®å»ºèšè²»çšã¯ 1 ä»¥äž 1,000,000 以äžãšä»®å®ããŠè¯ãïŒ
ãã 2 ã€ã®å³¶ãçµã¶æ©ã 2 ã€ä»¥äžäžããããäºãïŒæ©ã®äž¡ç«¯ãåãå³¶ã§ããäºã¯ãªãïŒ<br>
</p>
<p>
N=M=0 ã¯å
¥åã®çµããã瀺ãïŒããã¯ããŒã¿ã»ããã«ã¯å«ããªãïŒ<br>
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«å¯ŸãïŒæ¡ä»¶ã«åŸã£ãŠæ©ã建èšãããšãã®æå°ã®åèšè²»çšãæ±ãïŒãããã1è¡ã«åºåããªããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
3 3
1
2
3
1 2 1
1 3 1
2 3 10
3 2
100
10000
1000000
1 2 2
1 3 3
6 6
2
3
5
7
11
13
1 3 17
3 5 19
5 1 23
2 4 29
4 6 31
6 2 37
11 16
74
25
3
39
55
18
74
55
74
3
18
1 7 200
9 1 423
2 9 205
6 2 255
2 5 123
4 2 193
2 3 200
10 2 333
2 11 256
3 10 171
4 10 512
1 2 201
8 5 314
6 7 150
11 6 257
7 9 315
20 38
412516
185397
509168
712745
966959
101213
666120
790528
275431
677098
623178
240167
4371
299088
925699
72800
121416
796859
810604
142754
13 5 1000000
3 7 991832
10 1 781938
15 8 455731
1 3 655887
1 20 604802
19 10 452912
15 5 360121
10 15 256967
9 5 682599
8 7 917302
5 18 974821
2 19 790778
17 5 298105
15 11 132405
18 19 745543
2 4 790778
1 2 790778
11 14 269668
15 4 882901
1 14 522591
15 18 424799
9 19 712540
20 5 592132
18 17 770826
19 8 592380
16 5 258739
8 4 794157
3 18 569611
7 19 340021
19 11 803293
8 18 692318
9 6 626882
20 2 592133
2 17 196463
12 14 506077
16 20 928375
12 18 894053
0 0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
<h3>Output for Sample Input</h3>
<pre>
11
5
0
2013
9658580
</pre>
<!-- begin ja only -->
<!-- end ja only -->
|
p00931 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem H:
Cornering at Poles
</h2>
<p>
You are invited to a robot contest. In the contest, you are given a disc-shaped robot that is placed on a flat field. A set of poles are standing on the ground. The robot can move in all directions, but must avoid the poles. However, the robot can make turns around the poles touching them.
</p>
<p>
Your mission is to find the shortest path of the robot to reach the given goal position. The length of the path is defined by the moving distance of the center of the robot. Figure H.1 shows the shortest path for a sample layout. In this figure, a red line connecting a pole pair means that the distance between the poles is shorter than the diameter of the robot and the robot cannot go through between them.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_H1" width="600"><br>
<p>Figure H.1. The shortest path for a sample layout</p>
</center>
<h3>Input</h3>
<p>
The input consists of a single test case.<br>
<br>
$N$ $G_x$ $G_y$<br>
$x_1$ $y_1$<br>
.<br>
.<br>
.<br>
$x_N$ $y_N$<br>
<br>
The first line contains three integers. $N$ represents the number of the poles ($1 \leq N \leq 8$). $(G_x, G_y)$ represents the goal position. The robot starts with its center at $(0, 0)$, and the robot accomplishes its task when the center of the robot reaches the position $(G_x, G_y)$. You can assume that the starting and goal positions are not the same.
</p>
<p>
Each of the following $N$ lines contains two integers. $(x_i, y_i)$ represents the standing position of the $i$-th pole. Each input coordinate of $(G_x, G_y)$ and $(x_i, y_i)$ is between $â1000$ and $1000$, inclusive. The radius of the robot is $100$, and you can ignore the thickness of the poles. No pole is standing within a $100.01$ radius from the starting or goal positions. For the distance $d_{i,j}$ between the $i$-th and $j$-th poles $(i \ne j)$, you can assume $1 \leq d_{i,j} < 199.99$ or $200.01 < d_{i,j}$.
</p>
<p>
Figure H.1 shows the shortest path for Sample Input 1 below, and Figure H.2 shows the shortest paths for the remaining Sample Inputs.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_H2" width="640"><br>
<p>Figure H.2. The shortest paths for the sample layouts</p>
</center>
<h3>Output</h3>
<p>
Output the length of the shortest path to reach the goal. If the robot cannot reach the goal, output 0.0. The output should not contain an error greater than 0.0001.
</p>
<h3>Sample Input 1</h3>
<pre>8 900 0
40 100
70 -80
350 30
680 -20
230 230
300 400
530 130
75 -275</pre>
<h3>Sample Output 1</h3>
<pre>1210.99416</pre>
<h3>Sample Input 2</h3>
<pre>1 0 200
120 0</pre>
<h3>Sample Output 2</h3>
<pre>200.0</pre>
<h3>Sample Input 3</h3>
<pre>3 110 110
0 110
110 0
200 10</pre>
<h3>Sample Output 3</h3>
<pre>476.95048</pre>
<h3>Sample Input 4</h3>
<pre>4 0 200
90 90
-90 90
-90 -90
90 -90</pre>
<h3>Sample Output 4</h3>
<pre>0.0</pre>
<h3>Sample Input 5</h3>
<pre>2 0 -210
20 -105
-5 -105</pre>
<h3>Sample Output 5</h3>
<pre>325.81116</pre>
<h3>Sample Input 6</h3>
<pre>8 680 -50
80 80
80 -100
480 -120
-80 -110
240 -90
-80 100
-270 100
-420 -20</pre>
<h3>Sample Output 6</h3>
<pre>1223.53071</pre>
|
p01273 |
<H1><font color="#000">Problem A:</font> Infected Computer</H1>
<p>
Adam Ivan is working as a system administrator at Soy Group, Inc. He is now facing at a big trouble:
a number of computers under his management have been infected by a computer virus. Unfortunately,
anti-virus system in his company failed to detect this virus because it was very new.
</p>
<p>
Adam has identified the first computer infected by the virus and collected the records of all data packets
sent within his network. He is now trying to identify which computers have been infected. A computer
is infected when receiving any data packet from any infected computer. The computer is not infected, on
the other hand, just by sending data packets to infected computers.
</p>
<p>
It seems almost impossible for him to list all infected computers by hand, because the size of the packet
records is fairly large. So he asked you for help: write a program that can identify infected computers.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>N M</i><br>
<i>t</i><sub>1</sub> <i>s</i><sub>1</sub> <i>d</i><sub>1</sub><br>
<i>t</i><sub>2</sub> <i>s</i><sub>2</sub> <i>d</i><sub>2</sub><br>
...<br>
<i>t<sub>M</sub> s<sub>M</sub> d<sub>M</sub></i><br>
</p>
<p>
<i>N</i> is the number of computers; <i>M</i> is the number of data packets; <i>t<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>M</i>) is the time when the <i>i</i>-th
data packet is sent; <i>s<sub>i</sub></i> and <i>d<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>M</i>) are the source and destination computers of the <i>i</i>-th data packet
respectively. The first infected computer is indicated by the number 1; the other computers are indicated
by unique numbers between 2 and <i>N</i>.
</p>
<p>
The input meets the following constraints: 0 < <i>N</i> ≤ 20000, 0 ≤ <i>M</i> ≤ 20000, and 0 ≤ <i>t<sub>i</sub></i> ≤ 10<sup>9</sup> for
1 ≤ <i>i</i> ≤ <i>N</i>; all <i>t<sub>i</sub></i> 's are different; and the source and destination of each packet are always different.
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the number of computers infected by the computer virus.
</p>
<H2>Sample Input</H2>
<pre>
3 2
1 1 2
2 2 3
3 2
2 3 2
1 2 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
1
</pre>
|
p01789 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>J - Unfair Game</h2>
<h3>Problem Statement</h3>
<p>
Rabbit Hanako and Fox Jiro are great friends going to JAG primary school. Today they decided to play the following game during the lunch break.
</p>
<p>
This game is played by two players with $N$ heaps of some number of stones. The players alternatively take their turn to play the game. Jiro is a kind gentleman, so he yielded the first turn to Hanako. In each turn, the player must take some stones, satisfying the following conditions:
</p>
<ul>
<li>If the player is Hanako, she must take between $1$ to $A$ stones, inclusive, from a heap.</li>
<li>If the player is Jiro, he must take between $1$ to $B$ stones, inclusive, from a heap.</li>
</ul>
<p>
The winner is the player who takes the last stone. Jiro thinks it is rude to go easy on her because he is a perfect gentleman. Therefore, he does him best. Of course, Hanako also does so.
</p>
<p>
Jiro is worried that he may lose the game. Being a cadet teacher working at JAG primary school as well as a professional competitive programmer, you should help him by programming. Your task is to write a program calculating the winner, assuming that they both play optimally.
</p>
<h3>Input</h3>
<p>
The first line contains three integers $N$, $A$, and $B$. $N$ ($1 \leq N \leq 10^5$) is the number of heaps. $A$ and $B$ ($1 \leq A, B \leq 10^9$) are the maximum numbers of stones that Hanako and Jiro can take in a turn, respectively. Then $N$ lines follow, each of which contains a single integer $S_i$ ($1 \leq S_i \leq 10^9$), representing the number of stones in the $i$-th heap at the beginning of the game.
</p>
<h3>Output</h3>
<p>Output a line with "Hanako" if Hanako wins the game or "Jiro" in the other case. </p>
<h3>Sample Input 1</h3>
<pre>3 5 4
3
6
12</pre>
<h3>Output for the Sample Input 1</h3>
<pre>Hanako</pre>
<h3>Sample Input 2</h3>
<pre>4 7 8
8
3
14
5</pre>
<h3>Output for the Sample Input 2</h3>
<pre>Jiro</pre> |
p03864 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> boxes arranged in a row.
Initially, the <var>i</var>-th box from the left contains <var>a_i</var> candies.</p>
<p>Snuke can perform the following operation any number of times:</p>
<ul>
<li>Choose a box containing at least one candy, and eat one of the candies in the chosen box.</li>
</ul>
<p>His objective is as follows:</p>
<ul>
<li>Any two neighboring boxes contain at most <var>x</var> candies in total.</li>
</ul>
<p>Find the minimum number of operations required to achieve the objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †10^5</var></li>
<li><var>0 †a_i †10^9</var></li>
<li><var>0 †x †10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>x</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Eat one candy in the second box.
Then, the number of candies in each box becomes <var>(2, 1, 2)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 1
1 6 1 2 0 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre>
<p>For example, eat six candies in the second box, two in the fourth box, and three in the sixth box.
Then, the number of candies in each box becomes <var>(1, 0, 1, 0, 0, 1)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 9
3 1 4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>The objective is already achieved without performing operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 0
5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>10
</pre>
<p>All the candies need to be eaten.</p></section>
</div>
</span> |
p01859 |
<!--<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>-->
<h2>B: äžå³¶ãããããããïŒ - Match Peas War -</h2>
<h3>åé¡</h3>
<p>äžå³¶ããã
ã£ã»ã»ã»ã</p>
<p>磯éãäžå³¶ïŒå€§äžå€«ãïŒã</p>
<p>äžå³¶ãã»ã»ã»ãªãã ãå«ãªå€¢ãèŠãŠããæ°ããããã</p>
<p>磯éãã©ããªå€¢ã ãïŒã</p>
<p>äžå³¶ãç¡éã«éã¶å€¢ã</p>
<p>磯éãæå³ããããïŒãŸããããïŒäžå³¶ïŒããããããïŒã</p>
<p>äžå³¶ãããã£ãŠãŸããïŒãããããªãããªã»ã»ã»ã</p>
<p>磯éãããã ãïŒããã</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015HokudaiPC_are" type="image/jpeg" width="300"></img>
<p>äžå³¶ããã£ïŒãããããªããïŒããããããã</p>
<p>磯éããããããïŒãŸãã¯ãããããã ãªïŒã</p>
<p>ãªã«ããïŒå
¬åã§2人ã®åäŸãéãã§ããããã§ãïŒæããããæããŸããïŒãšããã§ïŒããªãã¯ããããã»ã°ãªãŒã³ããŒã¹ã»æŠäºããªã©ãšåŒã°ããæéã³ãç¥ã£ãŠããŸããïŒãã®åç§°ã«ãã³ãšããªãã£ããšããŠãïŒãã£ãšïŒåäŸæä»£ã«å¹ŸåºŠãšãªãéãã ããšãããã§ãããïŒ</p>
<p>ããã§ã¯ïŒããããã»ã°ãªãŒã³ããŒã¹ã»æŠäºãã®ã«ãŒã«ãç°¡ç¥åããæéã³ãèãïŒãããããšåä»ããŸãïŒããããã¯æ¬¡ã®ãããª2人ãã¬ã€ã®éã³ã§ãïŒ</p>
<pre>
(1)ïŒåãã¬ã€ã€ãŒãäž¡æã®æã1æ¬ãã€ç«ãŠãç¶æ
ããéã³ãéå§ããïŒ
(2)ïŒå
æã®ãã¬ã€ã€ãŒããé çªã«ä»¥äžã®(3)ã(5)ãè¡ãïŒ
(3)ïŒãã¬ã€ã€ãŒã¯ïŒèªèº«ã®ã©ã¡ããäžæ¹ã®æã§çžæã®ã©ã¡ããäžæ¹ã®æã«è§ŠããïŒ
(4)ïŒè§Šããããæã¯ïŒè§Šããæã«ç«ã£ãŠããæã®æ¬æ°ã ã远å ã§æãç«ãŠãïŒ
ããã§ïŒ5æ¬ä»¥äžã®æãç«ã€ã¹ãç¶æ³ã«ãªã£ãæã¯éå ŽããïŒ
ïŒéå Žããæã¯ïŒä»åŸè§Šãããè§Šãããããšãã«éžã°ããããšã¯ãªãïŒïŒ
(5)ïŒäž¡æãšãéå Žãããã¬ã€ã€ãŒããããã©ãã確èªããïŒãããªãã°ïŒäž¡ãã¬ã€ã€ãŒã¯(6)ã«åŸãïŒ
(6)ïŒéã³ãçµäºããïŒãã®ãšãïŒå°ãªããšãäžæ¹ã®æãæ®ã£ãŠãããã¬ã€ã€ãŒãåè
ã§ããïŒ
</pre>
<p>磯éãããŒãïŒåããã ãïŒã</p>
<p>ããïŒã©ãããïŒç£¯éåãå
æã«ãªã£ãããã§ããïŒ2人ã®éã³ã®è¡ãæ«ãèŠå®ã£ãŠã¿ãŸãããïŒ</p>
<p>磯éããããåã¯ïŒå³æã«2æ¬ïŒå·Šæã«1æ¬ã§ã¯ããããïŒã</p>
<p>äžå³¶ããããªãåã¯ïŒå³æã«2æ¬ïŒå·Šæã«2æ¬ã§ãããïŒã</p>
<p>ã¡ãã£ãšåŸ
ãŠïŒãªãã ãã®ã«ãŒã«ã¯−</p>
<p>ã©ãããïŒç£¯éåãã¡ã®éã§ã¯ïŒéã³éå§æã«åæã«ç«ã£ãŠããæã®æ¬æ°ã1 ã 4æ¬ã®ãã¡èªç±ã«æ±ºããããããã§ãïŒããŒã«ã«ã«ãŒã«ã£ãŠãã€ã§ããïŒ</p>
<p>ããããã®ãããªé¡ã®éã³ã¯ïŒå
æåŸæã§ã©ã¡ããå¿
åãªã®ããç°¡åã«èª¿ã¹ãããšãã§ããŸãïŒãããïŒããããã«ç£¯éåãã¡ã®ããŒã«ã«ã«ãŒã«ãåãå
¥ãããšïŒå
æåŸæã®åæãå€ãã£ãŠãããã§ãïŒãšãŠãæ°ã«ãªããŸããïŒçãããèå³ãããããªã®ã§ã¯ïŒãããããªãã°ïŒå®éã«èª¿æ»ããŠã¿ãŸãããïŒ</p>
<p>磯éåãšäžå³¶åãããŒã«ã«ã«ãŒã«ãåãå
¥ããããããã§éã¶ãšããŸãïŒç£¯éåãå
æãšä»®å®ããŠïŒç£¯éåã®å·Šæã«ã¯<var>L_i</var>æ¬ïŒå³æã«ã¯<var>R_i</var>æ¬ã®æãïŒäžå³¶åã®å·Šæã«ã¯<var>L_n</var>æ¬ïŒå³æã«ã¯<var>R_n</var>æ¬ã®æãç«ã£ãŠãããšããŸãïŒ2人ãšãæé©ãªè¡åãéžæããå ŽåïŒã©ã¡ããåã€ããå€å®ããŠãã ããïŒ</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ</p>
<pre>
<var>L_i</var> <var>R_i</var>
<var>L_n</var> <var>R_n</var>
</pre>
<p>1è¡ç®ã«ã¯ç£¯éåã®æã®åæç¶æ
ã衚ã<var>L_i</var>ïŒ<var>R_i</var>ã空çœåºåãã§äžããããïŒ<var>L_i</var>ã¯å·Šæã§ç«ã£ãŠããæã®æ¬æ°ïŒ<var>R_i</var>ã¯å³æã§ç«ã£ãŠããæã®æ¬æ°ã§ããïŒ</p>
<p>2è¡ç®ã«ã¯äžå³¶åã®æã®åæç¶æ
ã衚ã<var>L_n</var>ïŒ<var>R_n</var>ã空çœåºåãã§äžããããïŒ<var>L_n</var>ã¯å·Šæã§ç«ã£ãŠããæã®æ¬æ°ïŒ<var>R_n</var>ã¯å³æã§ç«ã£ãŠããæã®æ¬æ°ã§ããïŒ</p>
<p>ãŸãïŒå
¥åã¯ä»¥äžã®å¶çŽãæºããïŒ</p>
<pre><var>1 ≤ L_i, R_i, L_n, R_n ≤ 4</var></pre>
<h3>åºå圢åŒ</h3>
<p>磯éåãåã€å Žåã¯âISONOâãïŒäžå³¶åãåã€å Žåã¯âNAKAJIMAâã1è¡ã«åºåããïŒ</p>
<h3>å
¥åäŸ1</h3>
<pre>
3 2
2 2
</pre>
<h3>åºåäŸ1</h3>
<pre>NAKAJIMA</pre>
<h3>å
¥åäŸ2</h3>
<pre>
3 2
2 3
</pre>
<h3>åºåäŸ2</h3>
<pre>ISONO</pre>
<h3>å
¥åäŸ3</h3>
<pre>
1 1
1 1
</pre>
<h3>åºåäŸ3</h3>
<pre>NAKAJIMA</pre>
<p>ããããã¯åŸæã§åžžå</p> |
p02776 | <span class="lang-en">
<p>Score: <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>After being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom.</p>
<p>Fortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs.</p>
<p>There are <var>N</var> bombs, numbered <var>1</var> to <var>N</var>, planted in our country. Bomb <var>i</var> is planted at the coordinate <var>A_i</var>. It is currently activated if <var>B_i=1</var>, and deactivated if <var>B_i=0</var>.</p>
<p>The device has <var>M</var> cords numbered <var>1</var> to <var>M</var>. If we cut Cord <var>j</var>, the states of all the bombs planted between the coordinates <var>L_j</var> and <var>R_j</var> (inclusive) will be switched - from activated to deactivated, and vice versa.</p>
<p>Determine whether it is possible to deactivate all the bombs at the same time. If the answer is yes, output a set of cords that should be cut.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9\ (1 \leq i \leq N)</var></li>
<li><var>A_i</var> are pairwise distinct.</li>
<li><var>B_i</var> is <var>0</var> or <var>1</var>. <var>(1 \leq i \leq N)</var></li>
<li><var>1 \leq M \leq 2 \times 10^5</var></li>
<li><var>1 \leq L_j \leq R_j \leq 10^9\ (1 \leq j \leq M)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>
<var>L_1</var> <var>R_1</var>
<var>:</var>
<var>L_M</var> <var>R_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If it is impossible to deactivate all the bombs at the same time, print <code>-1</code>. If it is possible to do so, print a set of cords that should be cut, as follows:</p>
<pre><var>k</var>
<var>c_1</var> <var>c_2</var> <var>\dots</var> <var>c_k</var>
</pre>
<p>Here, <var>k</var> is the number of cords (possibly <var>0</var>), and <var>c_1, c_2, \dots, c_k</var> represent the cords that should be cut. <var>1 \leq c_1 < c_2 < \dots < c_k \leq M</var> must hold.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
5 1
10 1
8 0
1 10
4 5
6 7
8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1 4
</pre>
<p>There are two activated bombs at the coordinates <var>5, 10</var>, and one deactivated bomb at the coordinate <var>8</var>.</p>
<p>Cutting Cord <var>1</var> switches the states of all the bombs planted between the coordinates <var>1</var> and <var>10</var>, that is, all of the three bombs.</p>
<p>Cutting Cord <var>4</var> switches the states of all the bombs planted between the coordinates <var>8</var> and <var>9</var>, that is, Bomb <var>3</var>.</p>
<p>Thus, we can deactivate all the bombs by cutting Cord <var>1</var> and Cord <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2
2 0
3 1
5 1
7 0
1 4
4 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Cutting any set of cords will not deactivate all the bombs at the same time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 2
5 0
10 0
8 0
6 9
66 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>All the bombs are already deactivated, so we do not need to cut any cord.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>12 20
536130100 1
150049660 1
79245447 1
132551741 0
89484841 1
328129089 0
623467741 0
248785745 0
421631475 0
498966877 0
43768791 1
112237273 0
21499042 142460201
58176487 384985131
88563042 144788076
120198276 497115965
134867387 563350571
211946499 458996604
233934566 297258009
335674184 555985828
414601661 520203502
101135608 501051309
90972258 300372385
255474956 630621190
436210625 517850028
145652401 192476406
377607297 520655694
244404406 304034433
112237273 359737255
392593015 463983307
150586788 504362212
54772353 83124235
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
1 7 8 9 11
</pre>
<p>If there are multiple sets of cords that deactivate all the bombs when cut, any of them can be printed.</p></section>
</div>
</span> |
p02326 |
<H1>Largest Square</H1>
<p>
Given a matrix (<var>H</var> × <var>W</var>) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
</p>
<H2>Input</H2>
<pre>
<var>H</var> <var>W</var>
<var>c</var><sub>1,1</sub> <var>c</var><sub>1,2</sub> ... <var>c<sub>1,W</sub></var>
<var>c</var><sub>2,1</sub> <var>c</var><sub>2,2</sub> ... <var>c<sub>2,W</sub></var>
:
<var>c<sub>H,1</sub></var> <var>c<sub>H,2</sub></var> ... <var>c<sub>H,W</sub></var>
</pre>
<p>
In the first line, two integers <var>H</var> and <var>W</var> separated by a space character are given. In the following <var>H</var> lines, <var>c</var><sub><var>i</var>,<var>j</var></sub>, elements of the <var>H</var> × <var>W</var> matrix, are given.
</p>
<H2>Output</H2>
<p>
Print the area (the number of 0s) of the largest square.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>H</var>, <var>W</var> ≤ 1,400</li>
</ul>
<H2>Sample Input</H2>
<pre>
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
</pre>
<H2>Sample Output</H2>
<pre>
4
</pre>
|
p03167 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns.
Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p>
<p>For each <var>i</var> and <var>j</var> (<var>1 \leq i \leq H</var>, <var>1 \leq j \leq W</var>), Square <var>(i, j)</var> is described by a character <var>a_{i, j}</var>.
If <var>a_{i, j}</var> is <code>.</code>, Square <var>(i, j)</var> is an empty square; if <var>a_{i, j}</var> is <code>#</code>, Square <var>(i, j)</var> is a wall square.
It is guaranteed that Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</p>
<p>Taro will start from Square <var>(1, 1)</var> and reach <var>(H, W)</var> by repeatedly moving right or down to an adjacent empty square.</p>
<p>Find the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>.
As the answer can be extremely large, find the count modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>H</var> and <var>W</var> are integers.</li>
<li><var>2 \leq H, W \leq 1000</var></li>
<li><var>a_{i, j}</var> is <code>.</code> or <code>#</code>.</li>
<li>Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{1, 1}</var><var>\ldots</var><var>a_{1, W}</var>
<var>:</var>
<var>a_{H, 1}</var><var>\ldots</var><var>a_{H, W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
...#
.#..
....
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There are three paths as follows:</p>
<p><img alt="" src="https://img.atcoder.jp/dp/grid_0_0_muffet.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2
..
#.
..
.#
..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There may be no paths.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5
..#..
.....
#...#
.....
..#..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>24
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>345263555
</pre>
<p>Be sure to print the count modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p03537 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo has a string <var>S</var>.</p>
<p>He can perform the following <var>N</var> kinds of operations any number of times in any order.</p>
<ul>
<li>Operation <var>i</var>: For each of the characters from the <var>L_i</var>-th through the <var>R_i</var>-th characters in <var>S</var>, replace it with its succeeding letter in the English alphabet. (That is, replace <code>a</code> with <code>b</code>, replace <code>b</code> with <code>c</code> and so on.) For <code>z</code>, we assume that its succeeding letter is <code>a</code>.</li>
</ul>
<p>Ringo loves palindromes and wants to turn <var>S</var> into a palindrome.
Determine whether this is possible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq L_i \leq R_i \leq |S|</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>N</var>
<var>L_1</var> <var>R_1</var>
<var>L_2</var> <var>R_2</var>
<var>:</var>
<var>L_N</var> <var>R_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if it is possible to turn <var>S</var> into a palindrome; print <code>NO</code> if it is impossible.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>bixzja
2
2 3
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>For example, if we perform Operation <var>1</var>, <var>2</var> and <var>1</var> in this order, <var>S</var> changes as <code>bixzja</code> â <code>bjyzja</code> â <code>bjzakb</code> â <code>bkaakb</code> and becomes a palindrome.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abc
1
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>cassert
4
1 2
3 4
1 1
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre></section>
</div>
</span> |
p03022 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke found a random number generator.
It generates an integer between <var>0</var> and <var>2^N-1</var> (inclusive).
An integer sequence <var>A_0, A_1, \cdots, A_{2^N-1}</var> represents the probability that each of these integers is generated. The integer <var>i</var> (<var>0 \leq i \leq 2^N-1</var>) is generated with probability <var>A_i / S</var>, where <var>S = \sum_{i=0}^{2^N-1} A_i</var>. The process of generating an integer is done independently each time the generator is executed.</p>
<p>Snuke has an integer <var>X</var>, which is now <var>0</var>.
He can perform the following operation any number of times:</p>
<ul>
<li>Generate an integer <var>v</var> with the generator and replace <var>X</var> with <var>X \oplus v</var>, where <var>\oplus</var> denotes the bitwise XOR.</li>
</ul>
<p>For each integer <var>i</var> (<var>0 \leq i \leq 2^N-1</var>), find the expected number of operations until <var>X</var> becomes <var>i</var>, and print it modulo <var>998244353</var>.
More formally, represent the expected number of operations as an irreducible fraction <var>P/Q</var>. Then, there exists a unique integer <var>R</var> such that <var>R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353</var>, so print this <var>R</var>.</p>
<p>We can prove that, for every <var>i</var>, the expected number of operations until <var>X</var> becomes <var>i</var> is a finite rational number, and its integer representation modulo <var>998244353</var> can be defined.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 18</var></li>
<li><var>1 \leq A_i \leq 1000</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_0</var> <var>A_1</var> <var>\cdots</var> <var>A_{2^N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>2^N</var> lines.
The <var>(i+1)</var>-th line (<var>0 \leq i \leq 2^N-1</var>) should contain the expected number of operations until <var>X</var> becomes <var>i</var>, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
4
4
4
</pre>
<p><var>X=0</var> after zero operations, so the expected number of operations until <var>X</var> becomes <var>0</var> is <var>0</var>.</p>
<p>Also, from any state, the value of <var>X</var> after one operation is <var>0</var>, <var>1</var>, <var>2</var> or <var>3</var> with equal probability.
Thus, the expected numbers of operations until <var>X</var> becomes <var>1</var>, <var>2</var> and <var>3</var> are all <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
499122180
4
499122180
</pre>
<p>The expected numbers of operations until <var>X</var> becomes <var>0</var>, <var>1</var>, <var>2</var> and <var>3</var> are <var>0</var>, <var>7/2</var>, <var>4</var> and <var>7/2</var>, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
468683018
635850749
96019779
657074071
24757563
745107950
665159588
551278361
143136064
557841197
185790407
988018173
247117461
129098626
789682908
</pre></section>
</div>
</span> |
p03188 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For an <var>n \times n</var> grid, let <var>(r, c)</var> denote the square at the <var>(r+1)</var>-th row from the top and the <var>(c+1)</var>-th column from the left.
A <em>good</em> coloring of this grid using <var>K</var> colors is a coloring that satisfies the following:</p>
<ul>
<li>Each square is painted in one of the <var>K</var> colors.</li>
<li>Each of the <var>K</var> colors is used for some squares.</li>
<li>Let us number the <var>K</var> colors <var>1, 2, ..., K</var>. For any colors <var>i</var> and <var>j</var> (<var>1 \leq i \leq K, 1 \leq j \leq K</var>), every square in Color <var>i</var> has the same number of adjacent squares in Color <var>j</var>. Here, the squares adjacent to square <var>(r, c)</var> are <var>((r-1)\; mod\; n, c), ((r+1)\; mod\; n, c), (r, (c-1)\; mod\; n)</var> and <var>(r, (c+1)\; mod\; n)</var> (if the same square appears multiple times among these four, the square is counted that number of times).</li>
</ul>
<p>Given <var>K</var>, choose <strong><var>n</var> between <var>1</var> and <var>500</var></strong> (inclusive) freely and construct a good coloring of an <var>n \times n</var> grid using <var>K</var> colors.
It can be proved that this is always possible under the constraints of this problem,</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq 1000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Output should be in the following format:</p>
<pre><var>n</var>
<var>c_{0,0}</var> <var>c_{0,1}</var> <var>...</var> <var>c_{0,n-1}</var>
<var>c_{1,0}</var> <var>c_{1,1}</var> <var>...</var> <var>c_{1,n-1}</var>
<var>:</var>
<var>c_{n-1,0}</var> <var>c_{n-1,1}</var> <var>...</var> <var>c_{n-1,n-1}</var>
</pre>
<p><var>n</var> should represent the size of the grid, and <var>1 \leq n \leq 500</var> must hold.
<var>c_{r,c}</var> should be an integer such that <var>1 \leq c_{r,c} \leq K</var> and represent the color for the square <var>(r, c)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
1 1 1
1 1 1
2 2 2
</pre>
<ul>
<li>Every square in Color <var>1</var> has three adjacent squares in Color <var>1</var> and one adjacent square in Color <var>2</var>.</li>
<li>Every square in Color <var>2</var> has two adjacent squares in Color <var>1</var> and two adjacent squares in Color <var>2</var>.</li>
</ul>
<p>Output such as the following will be judged incorrect:</p>
<pre>2
1 2
2 2
</pre>
<pre>3
1 1 1
1 1 1
1 1 1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
1 2 3
4 5 6
7 8 9
</pre></section>
</div>
</span> |
p03472 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have <var>N</var> katana (swords), Katana <var>1</var>, Katana <var>2</var>, <var>âŠ</var>, Katana <var>N</var>, and can perform the following two kinds of attacks in any order:</p>
<ul>
<li>Wield one of the katana you have. When you wield Katana <var>i</var> <var>(1 †i †N)</var>, the monster receives <var>a_i</var> points of damage. The same katana can be wielded any number of times.</li>
<li>Throw one of the katana you have. When you throw Katana <var>i</var> <var>(1 †i †N)</var> at the monster, it receives <var>b_i</var> points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.</li>
</ul>
<p>The monster will vanish when the total damage it has received is <var>H</var> points or more. At least how many attacks do you need in order to vanish it in total?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^5</var></li>
<li><var>1 †H †10^9</var></li>
<li><var>1 †a_i †b_i †10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>H</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_N</var> <var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total number of attacks required to vanish the monster.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 10
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>You have one katana. Wielding it deals <var>3</var> points of damage, and throwing it deals <var>5</var> points of damage. By wielding it twice and then throwing it, you will deal <var>3 + 3 + 5 = 11</var> points of damage in a total of three attacks, vanishing the monster.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 10
3 5
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>In addition to the katana above, you also have another katana. Wielding it deals <var>2</var> points of damage, and throwing it deals <var>6</var> points of damage. By throwing both katana, you will deal <var>5 + 6 = 11</var> points of damage in two attacks, vanishing the monster.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 1000000000
1 1
1 10000000
1 30000000
1 99999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>860000004
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 500
35 44
28 83
46 62
31 79
40 43
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>9
</pre></section>
</div>
</span> |
p03921 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On a planet far, far away, <var>M</var> languages are spoken. They are conveniently numbered <var>1</var> through <var>M</var>.</p>
<p>For <em>CODE FESTIVAL 20XX</em> held on this planet, <var>N</var> participants gathered from all over the planet.</p>
<p>The <var>i</var>-th <var>(1âŠiâŠN)</var> participant can speak <var>K_i</var> languages numbered <var>L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}</var>.</p>
<p>Two participants <var>A</var> and <var>B</var> can <em>communicate</em> with each other if and only if one of the following conditions is satisfied:</p>
<ul>
<li>There exists a language that both <var>A</var> and <var>B</var> can speak.</li>
<li>There exists a participant <var>X</var> that both <var>A</var> and <var>B</var> can communicate with.</li>
</ul>
<p>Determine whether all <var>N</var> participants can communicate with all other participants.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2âŠNâŠ10^5</var></li>
<li><var>1âŠMâŠ10^5</var></li>
<li><var>1âŠK_iâŠM</var></li>
<li><var>(</var>The sum of all <var>K_i)âŠ10^5</var></li>
<li><var>1âŠL_{i,j}âŠM</var></li>
<li><var>L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}</var> are pairwise distinct.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded for passing the test set satisfying the following: <var>NâŠ1000</var>, <var>MâŠ1000</var> and <var>(</var>The sum of all <var>K_i)âŠ1000</var>.</li>
<li>Additional <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>K_1</var> <var>L_{1,1}</var> <var>L_{1,2}</var> <var>...</var> <var>L_{1,{}K_1}</var>
<var>K_2</var> <var>L_{2,1}</var> <var>L_{2,2}</var> <var>...</var> <var>L_{2,{}K_2}</var>
<var>:</var>
<var>K_N</var> <var>L_{N,1}</var> <var>L_{N,2}</var> <var>...</var> <var>L_{N,{}K_N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If all <var>N</var> participants can communicate with all other participants, print <code>YES</code>. Otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 6
3 1 2 3
2 4 2
2 4 6
1 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>Any two participants can communicate with each other, as follows:</p>
<ul>
<li>Participants <var>1</var> and <var>2</var>: both can speak language <var>2</var>.</li>
<li>Participants <var>2</var> and <var>3</var>: both can speak language <var>4</var>.</li>
<li>Participants <var>1</var> and <var>3</var>: both can communicate with participant <var>2</var>.</li>
<li>Participants <var>3</var> and <var>4</var>: both can speak language <var>6</var>.</li>
<li>Participants <var>2</var> and <var>4</var>: both can communicate with participant <var>3</var>.</li>
<li>Participants <var>1</var> and <var>4</var>: both can communicate with participant <var>2</var>.</li>
</ul>
<p>Note that there can be languages spoken by no participant.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
2 1 2
2 1 2
1 3
2 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>For example, participants <var>1</var> and <var>3</var> cannot communicate with each other.</p></section>
</div>
</span> |
p02633 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer <var>K</var> such that Takahashi will be at the starting position again after he does the following action <var>K</var> times:</p>
<ul>
<li>Go one meter in the direction he is facing. Then, turn <var>X</var> degrees counter-clockwise.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X \leq 179</var></li>
<li><var>X</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of times Takahashi will do the action before he is at the starting position again.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>90
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Takahashi's path is a square.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>360
</pre></section>
</div>
</span> |
p02799 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a connected undirected graph with <var>N</var> vertices and <var>M</var> edges.
Edge <var>i</var> in this graph (<var>1 \leq i \leq M</var>) connects Vertex <var>U_i</var> and Vertex <var>V_i</var> bidirectionally.
We are additionally given <var>N</var> integers <var>D_1, D_2, ..., D_N</var>.</p>
<p>Determine whether the conditions below can be satisfied by assigning a color - white or black - to each vertex and an integer weight between <var>1</var> and <var>10^9</var> (inclusive) to each edge in this graph.
If the answer is yes, find one such assignment of colors and integers, too.</p>
<ul>
<li>There is at least one vertex assigned white and at least one vertex assigned black.</li>
<li>For each vertex <var>v</var> (<var>1 \leq v \leq N</var>), the following holds.<ul>
<li>The minimum cost to travel from Vertex <var>v</var> to a vertex whose color assigned is different from that of Vertex <var>v</var> by traversing the edges is equal to <var>D_v</var>.</li>
</ul>
</li>
</ul>
<p>Here, the cost of traversing the edges is the sum of the weights of the edges traversed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100,000</var></li>
<li><var>1 \leq M \leq 200,000</var></li>
<li><var>1 \leq D_i \leq 10^9</var></li>
<li><var>1 \leq U_i, V_i \leq N</var></li>
<li>The given graph is connected and has no self-loops or multiple edges.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var>
<var>U_1</var> <var>V_1</var>
<var>U_2</var> <var>V_2</var>
<var>\vdots</var>
<var>U_M</var> <var>V_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there is no assignment satisfying the conditions, print a single line containing <code>-1</code>.</p>
<p>If such an assignment exists, print one such assignment in the following format:</p>
<pre><var>S</var>
<var>C_1</var>
<var>C_2</var>
<var>\vdots</var>
<var>C_M</var>
</pre>
<p>Here,</p>
<ul>
<li>the first line should contain the string <var>S</var> of length <var>N</var>. Its <var>i</var>-th character (<var>1 \leq i \leq N</var>) should be <code>W</code> if Vertex <var>i</var> is assigned white and <code>B</code> if it is assigned black.</li>
<li>The <var>(i + 1)</var>-th line (<var>1 \leq i \leq M</var>) should contain the integer weight <var>C_i</var> assigned to Edge <var>i</var>.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 5
3 4 3 5 7
1 2
1 3
3 2
4 2
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>BWWBB
4
3
1
5
2
</pre>
<p>Assume that we assign the colors and integers as the sample output, and let us consider Vertex <var>5</var>, for example. To travel from Vertex <var>5</var>, which is assigned black, to a vertex that is assigned white with the minimum cost, we should make these moves: Vertex <var>5</var> <var>\to</var> Vertex <var>4</var> <var>\to</var> Vertex <var>2</var>. The total cost of these moves is <var>7</var>, which satisfies the condition. We can also verify that the condition is satisfied for other vertices.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 7
1 2 3 4 5
1 2
1 3
1 4
2 3
2 5
3 5
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 6
1 1 1 1
1 2
1 3
1 4
2 3
2 4
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>BBBW
1
1
1
2
1
1
</pre></section>
</div>
</span> |
p02263 |
<p>
Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free.
</p>
<p>
Write a program which reads an expression in the Reverse Polish notation and prints the computational result.
</p>
<p>
An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations.
</p>
<H2>Input</H2>
<p>
An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.
</p>
<p>
You can assume that +, - and * are given as the operator and an operand is a positive integer less than 10<sup>6</sup>
</p>
<H2>Output</H2>
<p>
Print the computational result in a line.
</p>
<H2>Constraints</H2>
<p>
2 ≤ the number of operands in the expression ≤ 100<br>
1 ≤ the number of operators in the expression ≤ 99<br>
-1 × 10<sup>9</sup> ≤ values in the stack ≤ 10<sup>9</sup><br>
</p>
<H2>Sample Input 1</H2>
<pre>
1 2 +
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
<H2>Sample Input 2</H2>
<pre>
1 2 + 3 4 - *
</pre>
<H2>Sample Output 2</H2>
<pre>
-3
</pre>
<h2>Notes</h2>
<a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a>
|
p00570 | <h1>ã¹ããŒã(Stove)</h1>
<p>
JOI åã®éšå±ã«ã¯ã¹ããŒããããïŒJOI åèªèº«ã¯å¯ãã«åŒ·ãã®ã§ã²ãšãã§éšå±ã«ãããšãã¯ã¹ããŒããã€ããå¿
èŠã¯ãªããïŒæ¥å®¢ããããšãã¯ã¹ããŒããã€ããå¿
èŠãããïŒ
</p>
<p>
ãã®æ¥ïŒJOI åã®ããšã«ã¯<var>N</var> äººã®æ¥å®¢ãããïŒ<var>i</var> çªç®(<var>1 \leq i \leq N</var>) ã®æ¥å®¢ã¯æå»<var>T_i</var> ã«å°çãïŒæå»<var>T_i + 1</var>ã«éåºããïŒåæã«è€æ°äººã®æ¥å®¢ãããããšã¯ãªãïŒ
</p>
<p>
JOI åã¯ä»»æã®æå»ã«ã¹ããŒããã€ãããæ¶ãããã§ããïŒãã ãïŒã¹ããŒããã€ãã床ã«ãããã1æ¬æ¶è²»ããïŒJOI åã¯ãããã<var>K</var> æ¬ããæã£ãŠããªãã®ã§ïŒ<var>K</var> åãŸã§ããã¹ããŒããã€ããããšãã§ããªãïŒäžæ¥ã®ã¯ããã«ã¹ããŒãã¯æ¶ããŠããïŒ
</p>
<p>
ã¹ããŒããã€ããŠãããšãã®åã ãçæãæ¶è²»ããã®ã§ïŒã¹ããŒããã€ãããæ¶ãããããæå»ãããŸãå®ããŠïŒã¹ããŒããã€ããŠããæéã®åèšãæå°åãããïŒ
</p>
<h2>課é¡</h2>
<p>
JOI åã®éšå±ãžã®æ¥å®¢ã®æ
å ±ãšïŒJOI åã®æã£ãŠãããããã®æ¬æ°ãäžãããããšãïŒã¹ããŒããã€ããŠããæéã®åèšã®æå°å€ãæ±ããïŒ
</p>
<h3>å
¥å</h3>
<p>æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒ2 ã€ã®æŽæ°<var>N, K</var> ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒJOI åã®éšå±ã«<var>N</var> äººã®æ¥å®¢ãããïŒJOI åã¯<var>K</var> æ¬ã®ããããæã£ãŠããããšã衚ãïŒ</li>
<li> ç¶ã<var>N</var> è¡ã®ãã¡ã®<var>i</var> è¡ç®(<var>1 \leq i \leq N</var>) ã«ã¯ïŒæŽæ°<var>T_i</var> ãæžãããŠããïŒããã¯ïŒ<var>i</var> çªç®ã®æ¥å®¢ãæå»<var>T_i</var>ã«å°çãïŒæå»<var>T_i + 1</var> ã«éåºããããšã衚ãïŒ</li>
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«ïŒã¹ããŒããã€ããŠããæéã®åèšã®æå°å€ã1 è¡ã§åºåããïŒ
</p>
<h3>å¶é</h3>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li> <var>1 \leq N \leq 100 000ïŒ</var></li>
<li> <var>1 \leq K \leq NïŒ</var></li>
<li> <var>1 \leq T_i \leq 1 000 000 000 (1 \leq i \leq N)ïŒ</var></li>
<li> <var>T_i < T_{i+1} (1 \leq i \leq N - 1)</var>ïŒ</li>
</ul>
<!--
å°èª²é¡
å°èª²é¡1 [20 ç¹]
以äžã®æ¡ä»¶ãæºããïŒ
N ⊠20ïŒ
1 ⊠Ti ⊠20 (1 ⊠i ⊠N)ïŒ
å°èª²é¡2 [30 ç¹]
N ⊠5000 ãæºããïŒ
å°èª²é¡3 [50 ç¹]
远å ã®å¶éã¯ãªãïŒ
-->
<h3>åå
¥åºåäŸ</h3>
<h3>å
¥åäŸ1</h3>
<pre>
3 2
1
3
6
</pre>
<h3>åºåäŸ1</h3>
<pre>
4
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒJOI åã®éšå±ãžã®æ¥å®¢ã3 人ããïŒä»¥äžã®ããã«ã¹ããŒããã€ãããæ¶ããããããšïŒæ¥å®¢ãããéã¯ã¹ããŒããã€ããŠããïŒã¹ããŒããã€ããåæ°ã¯2 åã§ããïŒã¹ããŒããã€ããŠããæéã®åèšã¯(4 - 1) + (7 - 6) = 4 ã§ããïŒ
</p>
<ul>
<li> 1 çªç®ã®æ¥å®¢ãå°çããæå»1 ã«ã¹ããŒããã€ããïŒ</li>
<li> 2 çªç®ã®æ¥å®¢ãéåºããæå»4 ã«ã¹ããŒããæ¶ãïŒ</li>
<li> 3 çªç®ã®æ¥å®¢ãå°çããæå»6 ã«ã¹ããŒããã€ããïŒ</li>
<li> 3 çªç®ã®æ¥å®¢ãéåºããæå»7 ã«ã¹ããŒããæ¶ãïŒ</li>
</ul>
<p>
ã¹ããŒããã€ããŠããæéã®åèšã4 æªæºã«ããããšã¯ã§ããªãã®ã§ïŒçããšããŠ4 ãåºåããïŒ
</p>
<h3>å
¥åäŸ2</h3>
<pre>
3 1
1
2
6
</pre>
<h3>åºåäŸ2</h3>
<pre>
6
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒJOI åã¯1 åããã¹ããŒããã€ããããšãã§ããªãã®ã§ïŒ1 çªç®ã®æ¥å®¢ãå°çããæå»1 ã«ã¹ããŒããã€ãïŒ3 çªç®ã®æ¥å®¢ãéåºããæå»7 ã«ã¹ããŒããæ¶ãã°ããïŒ
</p>
<p>
æ¥å®¢ãéåºããæå»ãšïŒãã®æ¬¡ã®æ¥å®¢ãå°çããæå»ãäžèŽããå Žåãããããšã«æ³šæããïŒ
</p>
<h3>å
¥åäŸ3</h3>
<pre>
3 3
1
3
6
</pre>
<h3>åºåäŸ3</h3>
<pre>
3
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒJOI åã¯æ¥å®¢ãå°çãã床ã«ã¹ããŒããã€ãïŒæ¥å®¢ãéåºãã床ã«ã¹ããŒããæ¶ãã°ããïŒ
</p>
<h3>å
¥åäŸ4</h3>
<pre>
10 5
1
2
5
6
8
11
13
15
16
20
</pre>
<h3>åºåäŸ4</h3>
<pre>
12
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2017/2018-ho/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第17 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2017/2018) æ¬éžã</a>
</p>
|
p00120 |
<H1>ããã£ã·ãš</H1>
<p>
ã±ãŒãå±ãããããŸã¡ãŸã¡ãªå€§ããã®ããŒã«ã±ãŒããããããäœããŸãããããªãã¯ããã®ã±ãŒããç®±ã«äžŠã¹ãä»äºãä»»ãããŸããã
</p>
<p>
ããŒã«ã±ãŒãã¯ãšãŠããããããã®ã§ãä»ã®ããŒã«ã±ãŒããäžã«ä¹ããšã€ã¶ããŠããŸããŸããã§ããããå³(a) ã®ããã«å
šãŠã®ããŒã«ã±ãŒãã¯å¿
ãç®±ã®åºé¢ã«æ¥ããŠããããã«äžŠã¹ãªããã°ãªããŸãããäžŠã¹æ¿ãããšå¿
èŠãªå¹
ãå€ãããŸãã
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_patisserie1"></td></tr>
<tr><th>å³(a)</th></tr>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_patisserie2"></td></tr>
<tr><th>å³(b)</th></tr>
</table>
</center>
</br>
<p>
<var>n</var> åã®ããŒã«ã±ãŒãã®ååŸ <var>r<sub>1</sub></var>, <var>r<sub>2</sub></var>, ..., <var>r<sub>n</sub></var> ãšç®±ã®é·ããèªã¿èŸŒã¿ãããããã«ã€ããŠãç®±ã®äžã«ããŸãåãŸããã©ããå€å®ãã䞊ã¹ãé çªã工倫ãããšç®±ã«å
¥ãå Žå㯠"OK"ãã©ã䞊ã¹ãŠãå
¥ããªãå Žåã«ã¯ "NA"ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
ããŒã«ã±ãŒãã®æé¢ã¯åã§ãããç®±ã®å£ã®é«ãã¯ååã«é«ããã®ãšããŸãã ãã ããããŒã«ã±ãŒãã®ååŸã¯ 3 ä»¥äž 10 以äžã®æŽæ°ãšããŸããã€ãŸããã±ãŒãã®ååŸã«æ¥µç«¯ãªå·®ã¯ãªããå³(b) ã®ããã«å€§ããªã±ãŒãã®éã«å°ããªã±ãŒããã¯ãŸã蟌ãã§ããŸãããšã¯ãããŸããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>W</var> <var>r<sub>1</sub></var> <var>r<sub>2</sub></var> ... <var>r<sub>n</sub></var>
</pre>
<p>
æåã«ç®±ã®é·ããè¡šãæŽæ° <var>W</var> (1 ≤ <var>W</var> ≤ 1,000) ãäžããããŸãã ç¶ããŠã空çœåºåãã§åããŒã«ã±ãŒãã®ååŸãè¡šãæŽæ° <var>r<sub>i</sub></var> (3 ≤ <var>r<sub>i</sub></var> ≤ 10) ãäžããããŸããã±ãŒãã®åæ° <var>n</var> 㯠12 以äžã§ãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã« OK ãŸã㯠NA ãïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
</pre>
<H2>Output for the Sample Input</H2>
<pre>
OK
OK
OK
NA
</pre>
|
p01361 |
<H1><font color="#000">Problem C:</font> Dungeon Quest II</H1>
<p>
The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king
and all of his soldiers were destroyed by the hero and the peace is there now.
</p>
<p>
One day, however, the hero was worrying about the rebirth of the devil king, so he decided to
ask security agency to patrol inside the cave.
</p>
<p>
The information of the cave is as follows:
</p>
<ul>
<li> The cave is represented as a two-dimensional field which consists of rectangular grid of
cells.</li>
<li> The cave has <i>R</i> × <i>C</i> cells where <i>R</i> is the number of rows and <i>C</i> is the number of columns.</li>
<li> Some of the cells in the cave contains a trap, and those who enter the trapping cell will
lose his hit points.</li>
<li> The type of traps varies widely: some of them reduce hit points seriously, and others give
less damage.</li>
</ul>
<p>
The following is how the security agent patrols:
</p>
<ul>
<li> The agent will start his patrol from upper left corner of the cave.<br>
- There are no traps at the upper left corner of the cave.</li>
<li> The agent will patrol by tracing the steps which are specified by the hero.<br>
- The steps will be provided such that the agent never go outside of the cave during
his patrol.</li>
<li> The agent will bring potions to regain his hit point during his patrol.</li>
<li> The agent can use potions just before entering the cell where he is going to step in.</li>
<li> The type of potions also varies widely: some of them recover hit points so much, and
others are less effective.<br>
- Note that agentâs hit point can be recovered up to <i>HP<sub>max</sub></i> which means his maximum
hit point and is specified by the input data.</li>
<li> The agent can use more than one type of potion at once.</li>
<li> If the agent's hit point becomes less than or equal to 0, he will die.</li>
</ul>
<p>
Your task is to write a program to check whether the agent can finish his patrol without dying.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is given in the following format:
</p>
<p>
<i>HP<sub>init</sub> HP<sub>max</sub></i><br>
<i>R C</i><br>
<i>a</i><sub>1,1</sub> <i>a</i><sub>1,2</sub> ... <i>a</i><sub>1,<i>C</i></sub><br>
<i>a</i><sub>2,1</sub> <i>a</i><sub>2,2</sub> ... <i>a</i><sub>2,<i>C</i></sub><br>
.<br>
.<br>
.<br>
<i>a</i><sub><i>R</i>,1</sub> <i>a</i><sub><i>R</i>,2</sub> ... <i>a</i><sub><i>R</i>,<i>C</i></sub><br>
<i>T</i><br>
[<span>A-Z</span>] <i>d</i><sub>1</sub><br>
[<span>A-Z</span>] <i>d</i><sub>2</sub><br>
.<br>
.<br>
.<br>
[<span>A-Z</span>] <i>d</i><sub><i>T</i></sub><br>
<i>S</i><br>
[<span>UDLR</span>] <i>n</i><sub>1</sub><br>
[<span>UDLR</span>] <i>n</i><sub>2</sub><br>
.<br>
.<br>
.<br>
[<span>UDLR</span>] <i>n</i><sub><i>S</i></sub><br>
<i>P</i><br>
<i>p</i><sub>1</sub><br>
<i>p</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>p</i><sub><i>P</i></sub><br>
</p>
<p>
The first line of a dataset contains two integers <i>HP<sub>init</sub></i> and <i>HP<sub>max</sub></i> (0 < <i>HP<sub>init</sub></i> ≤ <i>HP<sub>max</sub></i> ≤ 1000),
meaning the agent's initial hit point and the agentâs maximum hit point respectively.
</p>
<p>
The next line consists of <i>R</i> and <i>C</i> (1 ≤ <i>R</i>, <i>C</i> ≤ 100). Then, <i>R</i> lines which made of <i>C</i> characters
representing the information of the cave follow. The character <i>a<sub>i,j</sub></i> means there are the trap of
type <i>a<sub>i,j</sub></i> in <i>i</i>-th row and <i>j</i>-th column, and the type of trap is denoted as an uppercase alphabetic
character [<span>A-Z</span>].
</p>
<p>
The next line contains an integer <i>T</i>, which means how many type of traps to be described.
The following <i>T</i> lines contains a uppercase character [<span>A-Z</span>] and an integer <i>d<sub>i</sub></i> (0 ≤ <i>d<sub>i</sub></i> ≤ 1000),
representing the type of trap and the amount of damage it gives.
</p>
<p>
The next line contains an integer <i>S</i> (0 ≤ <i>S</i> ≤ 1000) representing the number of sequences which
the hero specified as the agent's patrol route. Then, <i>S</i> lines follows containing a character and
an integer <i>n<sub>i</sub></i> ( ∑<sup><i>S</i></sup><sub><i>i</i>=1</sub> <i>n<sub>i</sub></i> ≤ 1000), meaning the direction where the agent advances and the number
of step he takes toward that direction. The direction character will be one of '<span>U</span>', '<span>D</span>', '<span>L</span>', '<span>R</span>' for
Up, Down, Left, Right respectively and indicates the direction of the step.
</p>
<p>
Finally, the line which contains an integer <i>P</i> (0 ≤ <i>P</i> ≤ 12) meaning how many type of potions
the agent has follows. The following <i>P</i> lines consists of an integer <i>p<sub>i</sub></i> (0 < <i>p<sub>i</sub></i> ≤ 1000) which
indicated the amount of hit point it recovers.
The input is terminated by a line with two zeros. This line should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print in a line "<span>YES</span>" if the agent finish his patrol successfully, or "<span>NO</span>" otherwise.
</p>
<p>
If the agent's hit point becomes less than or equal to 0 at the end of his patrol, the output
should be "<span>NO</span>".
</p>
<H2>Sample Input</H2>
<pre>
1 10
3 3
AAA
ABA
CCC
3
A 0
B 5
C 9
3
D 2
R 1
U 2
5
10
10
10
10
10
100 100
10 10
THISISAPEN
THISISAPEN
THISISAPEN
THISISAPEN
THISISAPEN
THISISAPEN
THISISAPEN
THISISAPEN
THISISAPEN
THISISAPEN
8
T 0
H 1
I 2
S 3
A 4
P 5
E 6
N 7
9
R 1
D 3
R 8
D 2
L 9
D 2
R 9
D 2
L 9
2
20
10
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
p00989 | <h2>Draw in Straight Lines</h2>
<P>
You plan to draw a black-and-white painting on a rectangular canvas. The painting will be a grid array of pixels, either black or white. You can paint black or white lines or dots on the initially white canvas.
</p>
<p>
You can apply a sequence of the following two operations in any order.
</p>
<ul>
<li> Painting pixels on a horizontal or vertical line segment, single pixel wide and two or more pixel long, either black or white. This operation has a cost proportional to the length (the number of pixels) of the line segment multiplied by a specified coefficient in addition to a specified constant cost.
</li>
<li> Painting a single pixel, either black or white. This operation has a specified constant cost.
</li>
</ul>
<p>
You can overpaint already painted pixels as long as the following conditions are satisfied.
</p>
<ul>
<li> The pixel has been painted at most once before. Overpainting a pixel too many times results in too thick layers of inks, making the picture look ugly. Note that painting a pixel with the same color is also counted as overpainting. For instance, if you have painted a pixel with black twice, you can paint it neither black nor white anymore.
</li>
<li> The pixel once painted white should not be overpainted with the black ink. As the white ink takes very long to dry, overpainting the same pixel black would make the pixel gray, rather than black. The reverse, that is, painting white over a pixel already painted black, has no problem.
</li>
</ul>
<p>
Your task is to compute the minimum total cost to draw the specified image.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains five integers $n$, $m$, $a$, $b$, and $c$, where $n$ ($1 \leq n \leq 40$) and $m$ ($1 \leq m \leq 40$) are the height and the width of the canvas in the number of pixels, and $a$ ($0 \leq a \leq 40$), $b$ ($0 \leq b \leq 40$), and $c$ ($0 \leq c \leq 40$) are constants defining painting costs as follows. Painting a line segment of length $l$ costs $al + b$ and painting a single pixel costs $c$. These three constants satisfy $c \leq a + b$.
</p>
<p>
The next $n$ lines show the black-and-white image you want to draw. Each of the lines contains a string of length $m$. The $j$-th character of the $i$-th string is â<span>#</span>â if the color of the pixel in the $i$-th row and the $j$-th column is to be black, and it is â<span>.</span>â if the color is to be white.
</p>
<h3>Output</h3>
<p>
Output the minimum cost.
</p>
<h3>Sample Input 1 </h3>
<pre>
3 3 1 2 3
.#.
###
.#.
</pre>
<h3>Sample Output 1</h3>
<pre>
10
</pre>
<h3>Sample Input 2 </h3>
<pre>
2 7 0 1 1
###.###
###.###
</pre>
<h3>Sample Output 2</h3>
<pre>
3
</pre>
<h3>Sample Input 3 </h3>
<pre>
5 5 1 4 4
..#..
..#..
##.##
..#..
..#..
</pre>
<h3>Sample Output 3</h3>
<pre>
24
</pre>
<h3>Sample Input 4 </h3>
<pre>
7 24 1 10 10
###...###..#####....###.
.#...#...#.#....#..#...#
.#..#......#....#.#.....
.#..#......#####..#.....
.#..#......#......#.....
.#...#...#.#.......#...#
###...###..#........###.
</pre>
<h3>Sample Output 4</h3>
<pre>
256
</pre>
|
p01731 |
<p>Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view.
</p>
<p>Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread.
</p>
<p>Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole.
</p>
<p>Let us take an example. Suppose: a user made an opening post with a message <code>hoge</code>; another user replied to it with <code>fuga</code>; yet another user also replied to the opening post with <code>piyo</code>; someone else replied to the second post (i.e. <code>fuga</code>â) with <code>foobar</code>; and the fifth user replied to the same post with <code>jagjag</code>.
The tree of this thread would look like:
</p>
<pre>hoge
ââfuga
âãââfoobar
âãââjagjag
ââpiyo
</pre>
<p>For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like:
</section>
<pre>hoge
.fuga
..foobar
..jagjag
.piyo
</pre>
<p>Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread.
</p>
<h3>Input</h3>
<p>Input contains a single dataset in the following format:
</p>
<pre>
<var>n</var>
<var>k_1</var>
<var>M_1</var>
<var>k_2</var>
<var>M_2</var>
:
:
<var>k_n</var>
<var>M_n</var>
</pre>
<p>The first line contains an integer <var>n</var> (<var>1 ≤ n ≤ 1,000</var>), which is the number of posts in the thread.
Then <var>2n</var> lines follow.
Each post is represented by two lines:
the first line contains an integer <var>k_i</var> (<var>k_1 = 0</var>, <var>1 ≤ k_i < i</var> for <var>2 ≤ i ≤ n</var>) and indicates the <var>i</var>-th post is a reply to the <var>k_i</var>-th post;
the second line contains a string <var>M_i</var> and represents the message of the <var>i</var>-th post.
<var>k_1</var> is always 0, which means the first post is not replying to any other post, i.e. it is an opening post.
</p>
<p>Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters.
</p>
<h3>Output</h3>
<p>Print the given <var>n</var> messages as specified in the problem statement.
</p>
<h3>Sample Input 1</h3>
<pre>1
0
icpc
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>icpc
</pre>
<h3>Sample Input 2</h3>
<pre>5
0
hoge
1
fuga
1
piyo
2
foobar
2
jagjag
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>hoge
.fuga
..foobar
..jagjag
.piyo
</pre>
<h3>Sample Input 3</h3>
<pre>8
0
jagjag
1
hogehoge
1
buhihi
2
fugafuga
4
ponyoponyo
5
evaeva
4
nowawa
5
pokemon
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>jagjag
.hogehoge
..fugafuga
...ponyoponyo
....evaeva
....pokemon
...nowawa
.buhihi
</pre>
<h3>Sample Input 4</h3>
<pre>6
0
nakachan
1
fan
2
yamemasu
3
nennryou2
4
dannyaku4
5
kouzai11
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>nakachan
.fan
..yamemasu
...nennryou2
....dannyaku4
.....kouzai11
</pre>
<h3>Sample Input 5</h3>
<pre>34
0
LoveLive
1
honoka
2
borarara
2
sunohare
2
mogyu
1
eri
6
kasikoi
7
kawaii
8
eriichika
1
kotori
10
WR
10
haetekurukotori
10
ichigo
1
umi
14
love
15
arrow
16
shoot
1
rin
18
nyanyanya
1
maki
20
6th
20
star
22
nishikino
1
nozomi
24
spiritual
25
power
1
hanayo
27
darekatasukete
28
chottomattete
1
niko
30
natsuiro
30
nikkonikkoni
30
sekaino
33
YAZAWA
</pre>
<h3>Output for the Sample Input 5</h3>
<pre>LoveLive
.honoka
..borarara
..sunohare
..mogyu
.eri
..kasikoi
...kawaii
....eriichika
.kotori
..WR
..haetekurukotori
..ichigo
.umi
..love
...arrow
....shoot
.rin
..nyanyanya
.maki
..6th
..star
...nishikino
.nozomi
..spiritual
...power
.hanayo
..darekatasukete
...chottomattete
.niko
..natsuiro
..nikkonikkoni
..sekaino
...YAZAWA
</pre>
<h3>Sample Input 6</h3>
<pre>6
0
2ch
1
1ostu
1
2get
1
1otsu
1
1ostu
3
pgr
</pre>
<h3>Output for the Sample Input 6</h3>
<pre>2ch
.1ostu
.2get
..pgr
.1otsu
.1ostu
</pre>
|
p00823 |
<H1><font color="#000">Problem E:</font> Molecular Formula</H1>
<p>
Your mission in this problem is to write a computer program that manipulates molecular for-
mulae in <i>virtual chemistry</i>. As in real chemistry, each molecular formula represents a molecule
consisting of one or more atoms. However, it may not have chemical reality.
</p>
<p>
The following are the definitions of atomic symbols and molecular formulae you should consider.
</p>
<ul>
<li> An atom in a molecule is represented by an atomic symbol, which is either a single capital
letter or a capital letter followed by a small letter. For instance H and He are atomic
symbols.
</li>
<li>
A molecular formula is a non-empty sequence of atomic symbols. For instance, HHHeHHHe
is a molecular formula, and represents a molecule consisting of four Hâs and two Heâs.
</li>
<li>
For convenience, a repetition of the same sub-formula <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_molecularFormula1"> where <i>n</i> is an integer
between 2 and 99 inclusive, can be abbreviated to (<i>X</i>)<i>n</i>. Parentheses can be omitted if
X is an atomic symbol. For instance, HHHeHHHe is also written as H2HeH2He, (HHHe)2,
(H2He)2, or even ((H)2He)2.</li>
</ul>
<p>
The set of all molecular formulae can be viewed as a formal language. Summarizing the above
description, the syntax of molecular formulae is defined as follows.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_molecularFormula2">
</center>
<p>
Each atom in our virtual chemistry has its own atomic weight. Given the weights of atoms,
your program should calculate the weight of a molecule represented by a molecular formula.
The molecular weight is defined by the sum of the weights of the constituent atoms. For
instance, assuming that the atomic weights of the atoms whose symbols are H and He are 1 and
4, respectively, the total weight of a molecule represented by (H2He)2 is 12.
</p>
<H2>Input</H2>
<p>
The input consists of two parts. The first part, the Atomic Table, is composed of a number of
lines, each line including an atomic symbol, one or more spaces, and its atomic weight which is a positive integer no more than 1000. No two lines include the same atomic symbol.
</p>
<p>
The first part ends with a line containing only the string END OF FIRST PART.
</p>
<p>
The second part of the input is a sequence of lines. Each line is a molecular formula, not
exceeding 80 characters, and contains no spaces. A molecule contains at most 10<sup>5</sup> atoms. Some
atomic symbols in a molecular formula may not appear in the Atomic Table.
</p>
<p>
The sequence is followed by a line containing a single zero, indicating the end of the input.
</p>
<H2>Output</H2>
<p>
The output is a sequence of lines, one for each line of the second part of the input. Each line
contains either an integer, the molecular weight for a given molecular formula in the correspond-
ing input line if all its atomic symbols appear in the Atomic Table, or UNKNOWN otherwise. No
extra characters are allowed.
</p>
<H2>Sample Input</H2>
<pre>
H 1
He 4
C 12
O 16
F 19
Ne 20
Cu 64
Cc 333
END_OF_FIRST_PART
H2C
(MgF)2As
Cu(OH)2
H((CO)2F)99
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
14
UNKNOWN
98
7426
</pre>
|
p04026 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given a string <var>t</var>, we will call it <em>unbalanced</em> if and only if the length of <var>t</var> is at least <var>2</var>, and more than half of the letters in <var>t</var> are the same. For example, both <code>voodoo</code> and <code>melee</code> are unbalanced, while neither <code>noon</code> nor <code>a</code> is.</p>
<p>You are given a string <var>s</var> consisting of lowercase letters. Determine if there exists a (contiguous) substring of <var>s</var> that is unbalanced. If the answer is positive, show a position where such a substring occurs in <var>s</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ⊠|s| ⊠10^5</var></li>
<li><var>s</var> consists of lowercase letters.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded for passing the test set satisfying <var>2 ⊠N ⊠100</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists no unbalanced substring of <var>s</var>, print <code>-1 -1</code>.</p>
<p>If there exists an unbalanced substring of <var>s</var>, let one such substring be <var>s_a s_{a+1} ... s_{b}</var> <var>(1 ⊠a < b ⊠|s|)</var>, and print <code><var>a</var> <var>b</var></code>. If there exists more than one such substring, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>needed
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 5
</pre>
<p>The string <var>s_2 s_3 s_4 s_5</var> <var>=</var> <code>eede</code> is unbalanced. There are also other unbalanced substrings. For example, the output <code>2 6</code> will also be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>atcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1 -1
</pre>
<p>The string <code>atcoder</code> contains no unbalanced substring.</p></section>
</div>
</span> |
p01224 |
<h1><font color="#000">Problem B:</font> å®å
šæ°</h1>
<p>
ããæŽæ° <var>N</var> ã«å¯ŸãïŒãã®æ°èªèº«ãé€ãçŽæ°ã®åã <var>S</var>
ãšããïŒ
<var>N</var> = <var>S</var> ã®ãšã
<var>N</var> ã¯å®å
šæ° (perfect number)ïŒ
<var>N</var> > <var>S</var> ã®ãšã
<var>N</var> ã¯äžè¶³æ° (deficient number)ïŒ
<var>N</var> < <var>S</var> ã®ãšã
<var>N</var> ã¯éå°æ° (abundant number) ãšåŒã°ããïŒ
äžããããæŽæ°ãïŒå®å
šæ°ã»äžè¶³æ°ã»éå°æ°ã®ã©ãã§ãããã
å€å®ããããã°ã©ã ãäœæããïŒ
</p>
<p>
ããã°ã©ã ã®å®è¡æéãå¶éæéãè¶ããªãããã«æ³šæããããšïŒ
</p>
<h2>Input</h2>
<p>
å
¥åã¯ããŒã¿ã»ããã®äžŠã³ãããªãïŒ
ããŒã¿ã»ããã®æ°ã¯ 100 以äžã§ããïŒ
</p>
<p>
åããŒã¿ã»ããã¯æŽæ° <var>N</var>
(0 < <var>N</var> ≤ 100000000) ã®ã¿ãå«ã1è¡ãããªãïŒ
</p>
<p>
æåŸã®ããŒã¿ã»ããã®åŸã«ïŒå
¥åã®çµããã瀺ã 0 ãšæžããã1è¡ãããïŒ
</p>
<h2>Output</h2>
<p>
åããŒã¿ã»ããã«å¯ŸãïŒ
æŽæ° <var>N</var> ãå®å
šæ°ãªãã° “<code>perfect number</code>”ïŒ
äžè¶³æ°ãªãã° “<code>deficient number</code>”ïŒ
éå°æ°ãªãã° “<code>abundant number</code>” ãšããæååã
1è¡ã«åºåããïŒ
</p>
<h2>Sample Input</h2>
<pre>
1
2
3
4
6
12
16
28
33550336
99999998
99999999
100000000
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
deficient number
deficient number
deficient number
deficient number
perfect number
abundant number
deficient number
perfect number
perfect number
deficient number
deficient number
abundant number
</pre>
|
p03219 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a train going from Station <var>A</var> to Station <var>B</var> that costs <var>X</var> yen (the currency of Japan).</p>
<p>Also, there is a bus going from Station <var>B</var> to Station <var>C</var> that costs <var>Y</var> yen.</p>
<p>Joisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station <var>A</var> to Station <var>B</var> by train and then travels from Station <var>B</var> to Station <var>C</var> by bus.</p>
<p>How much does it cost to travel from Station <var>A</var> to Station <var>C</var> if she uses this ticket?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X,Y \leq 100</var></li>
<li><var>Y</var> is an even number.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it costs <var>x</var> yen to travel from Station <var>A</var> to Station <var>C</var>, print <var>x</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>81 58
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>110
</pre>
<ul>
<li>The train fare is <var>81</var> yen.</li>
<li>The train fare is <var>58</var> â <var>2=29</var> yen with the <var>50</var>% discount.</li>
</ul>
<p>Thus, it costs <var>110</var> yen to travel from Station <var>A</var> to Station <var>C</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 54
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>31
</pre></section>
</div>
</span> |
p01674 |
<h2>H - Rings</h2>
<h3>Problem Statement</h3>
<p>
There are two circles with radius 1 in 3D space. Please check two circles are connected as chained rings.
</p>
<h3>Input</h3>
<p>
The input is formatted as follows.
</p>
<pre>
<var>{c_x}_1</var> <var>{c_y}_1</var> <var>{c_z}_1</var>
<var>{v_x}_{1,1}</var> <var>{v_y}_{1,1}</var> <var>{v_z}_{1,1}</var> <var>{v_x}_{1,2}</var> <var>{v_y}_{1,2}</var> <var>{v_z}_{1,2}</var>
<var>{c_x}_2</var> <var>{c_y}_2</var> <var>{c_z}_2</var>
<var>{v_x}_{2,1}</var> <var>{v_y}_{2,1}</var> <var>{v_z}_{2,1}</var> <var>{v_x}_{2,2}</var> <var>{v_y}_{2,2}</var> <var>{v_z}_{2,2}</var>
</pre>
<p>
First line contains three real numbers(<var>-3 \leq {c_x}_i, {c_y}_i, {c_z}_i \leq 3</var>).
It shows a circle's center position.
Second line contains six real numbers(<var>-1 \leq {v_x}_{i,j}, {v_y}_{i,j}, {v_z}_{i,j} \leq 1</var>).
A unit vector (<var>{v_x}_{1,1}, {v_y}_{1,1}, {v_z}_{1,1}</var>) is directed to the circumference of the circle from center of the circle.
The other unit vector (<var>{v_x}_{1,2}, {v_y}_{1,2}, {v_z}_{1,2}</var>) is also directed to the circumference of the circle from center of the circle.
These two vectors are orthogonalized.
Third and fourth lines show the other circle information in the same way of first and second lines.
There are no cases that two circles touch.
</p>
<h3>Output</h3>
<p>
If two circles are connected as chained rings, you should print "YES". The other case, you should print "NO". (quotes for clarity)
</p>
<h3>Sample Input 1</h3>
<pre>
0.0 0.0 0.0
1.0 0.0 0.0 0.0 1.0 0.0
1.0 0.0 0.5
1.0 0.0 0.0 0.0 0.0 1.0
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
YES
</pre>
<h3>Sample Input 2</h3>
<pre>
0.0 0.0 0.0
1.0 0.0 0.0 0.0 1.0 0.0
0.0 3.0 0.0
0.0 1.0 0.0 -1.0 0.0 0.0
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
NO
</pre>
<h3>Sample Input 3</h3>
<pre>
1.2 2.3 -0.5
1.0 0.0 0.0 0.0 1.0 0.0
1.1 2.3 -0.4
1.0 0.0 0.0 0.0 0.70710678 0.70710678
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
YES
</pre>
<h3>Sample Input 4</h3>
<pre>
1.2 2.3 -0.5
1.0 0.0 0.0 0.0 1.0 0.0
1.1 2.7 -0.1
1.0 0.0 0.0 0.0 0.70710678 0.70710678
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
NO
</pre> |
p03649 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of length <var>N</var> consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes <var>N-1</var> or smaller. (The operation is the same as the one in Problem D.)</p>
<ul>
<li>Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by <var>N</var>, and increase each of the other elements by <var>1</var>.</li>
</ul>
<p>It can be proved that the largest element in the sequence becomes <var>N-1</var> or smaller after a finite number of operations.</p>
<p>You are given the sequence <var>a_i</var>. Find the number of times we will perform the above operation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †50</var></li>
<li><var>0 †a_i †10^{16} + 1000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> ... <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of times the operation will be performed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 0 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>7
27 0 0 0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>10
1000 193 256 777 0 1 1192 1234567891011 48 425
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>1234567894848
</pre></section>
</div>
</span> |
p00966 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>Problem J
String Puzzle
</h2>
<p>
<i>Amazing Coding Magazine</i> is popular among young programmers for its puzzle solving contests offering catchy digital gadgets as the prizes. The magazine for programmers naturally encourages the readers to solve the puzzles by writing programs. Let's give it a try!
</p>
<p>
The puzzle in the latest issue is on deciding some of the letters in a string (<i>the secret string</i>, in what follows) based on a variety of hints. The figure below depicts an example of the given hints.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_stringPuzzle" width="480">
</center>
<p>
The first hint is the number of letters in the secret string. In the example of the figure above, it is nine, and the nine boxes correspond to nine letters. The letter positions (boxes) are numbered starting from 1, from the left to the right.
</p>
<p>
The hints of the next kind simply tell the letters in the secret string at some specic positions. In the example, the hints tell that the letters in the 3rd, 4th, 7th, and 9th boxes are <span>C</span>, <span>I</span>, <span>C</span>, and <span>P</span., respectively.
</p>
<p>
The hints of the final kind are on duplicated substrings in the secret string. The bar immediately
below the boxes in the figure is partitioned into some sections corresponding to substrings of the secret string. Each of the sections may be connected by a line running to the left with another bar also showing an extent of a substring. Each of the connected pairs indicates that substrings of the two extents are identical. One of this kind of hints in the example tells that the letters in boxes 8 and 9 are identical to those in boxes 4 and 5, respectively. From this, you can easily deduce that the substring is <span>IP</span>.
</p>
<p>
Note that, not necessarily all of the identical substring pairs in the secret string are given in the hints; some identical substring pairs may not be mentioned.
</p>
<p>
Note also that two extents of a pair may overlap each other. In the example, the two-letter substring in boxes 2 and 3 is told to be identical to one in boxes 1 and 2, and these two extents share the box 2.
</p>
<p>
In this example, you can decide letters at all the positions of the secret string, which are "<span>CCCIPCCIP</span>". In general, the hints may not be enough to decide all the letters in the secret string.
</p>
<p>
The answer of the puzzle should be letters at the specified positions of the secret string. When the letter at the position specified cannot be decided with the given hints, the symbol <span>?</span> should be answered.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$n$ $a$ $b$ $q$
$x_1$ $c_1$
...
$x_a$ $c_a$
$y_1$ $h_1$
...
$y_b$ $h_b$
$z_1$
...
$z_q$
</pre>
<p>
The first line contains four integers $n$, $a$, $b$, and $q$. $n$ ($1 \leq n \leq 10^9$) is the length of the secret string, $a$ ($0 \leq a \leq 1000$) is the number of the hints on letters in specified positions, $b$ ($0 \leq b \leq 1000$) is the number of the hints on duplicated substrings, and $q$ ($1 \leq q \leq 1000$) is the number of positions asked.
</p>
<p>
The $i$-th line of the following a lines contains an integer $x_i$ and an uppercase letter $c_i$ meaning that the letter at the position $x_i$ of the secret string is $c_i$. These hints are ordered in their positions, i.e., $1 \leq x_1 < ... < x_a \leq n$.
</p>
<p>
The $i$-th line of the following $b$ lines contains two integers, $y_i$ and $h_i$. It is guaranteed that they satisfy $2 \leq y_1 < ... < y_b \leq n$ and $0 \leq h_i < y_i$. When $h_i$ is not 0, the substring of the secret string starting from the position $y_i$ with the length $y_{i+1} - y_i$ (or $n+1-y_i$ when $i = b$) is identical to the substring with the same length starting from the position $h_i$. Lines with $h_i = 0$ does not tell any hints except that $y_i$ in the line indicates the end of the substring specified in the line immediately above.
</p>
<p>
Each of the following $q$ lines has an integer $z_i$ ($1 \leq z_i \leq n$), specifying the position of the letter in the secret string to output.
</p>
<p>
It is ensured that there exists at least one secret string that matches all the given information. In other words, the given hints have no contradiction.
</p>
<h3>Output</h3>
<p>
The output should be a single line consisting only of $q$ characters. The character at position $i$ of the output should be the letter at position $z_i$ of the the secret string if it is uniquely determined from the hints, or <span>?</span> otherwise.
</p>
<h3>Sample Input 1</h3>
<pre>
9 4 5 4
3 C
4 I
7 C
9 P
2 1
4 0
6 2
7 0
8 4
8
1
9
6
</pre>
<h3>Sample Output 1</h3>
<pre>
ICPC
</pre>
<h3>Sample Input 2</h3>
<pre>
1000000000 1 1 2
20171217 A
3 1
42
987654321
</pre>
<h3>Sample Output 2</h3>
<pre>
?A
</pre> |
p02408 | <H1>Finding Missing Cards</H1>
<p>
Taro is going to play a card game. However, now he has only <var>n</var> cards, even though there should be 52 cards (he has no Jokers).
</p>
<p>
The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
</p>
<H2>Input</H2>
<p>
In the first line, the number of cards <var>n</var> (<var>n</var> ≤ 52) is given.
</p>
<p>
In the following <var>n</var> lines, data of the <var>n</var> cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
</p>
<H2>Output</H2>
<p>
Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line.
Arrange the missing cards in the following priorities:
</p>
<ul>
<li>Print cards of spades, hearts, clubs and diamonds in this order.</li>
<li>If the suits are equal, print cards with lower ranks first.</li>
</ul>
<H2>Sample Input</H2>
<pre>
47
S 10
S 11
S 12
S 13
H 1
H 2
S 6
S 7
S 8
S 9
H 6
H 8
H 9
H 10
H 11
H 4
H 5
S 2
S 3
S 4
S 5
H 12
H 13
C 1
C 2
D 1
D 2
D 3
D 4
D 5
D 6
D 7
C 3
C 4
C 5
C 6
C 7
C 8
C 9
C 10
C 11
C 13
D 9
D 10
D 11
D 12
D 13
</pre>
<H2>Sample Output</H2>
<pre>
S 1
H 3
H 7
C 12
D 8
</pre>
<h2>Note</h2>
<center>
<a href="commentary.jsp?id=ITP1_6_B">
<div class="button"> 解説 </div>
</a>
</center>
|
p00435 |
<H1>ã·ãŒã¶ãŒæå·</H1>
<h2>åé¡</h2>
<p>
ã¬ã€ãŠã¹ã»ãŠãªãŠã¹ã»ã«ãšãµã«ïŒGaius Julius Caesar)ïŒè±èªèªã¿ã§ãžã¥ãªã¢ã¹ã»ã·ãŒã¶ãŒïŒJulius CaesarïŒã¯ïŒå€ä»£ããŒãã®è»äººã§ããæ¿æ²»å®¶ã§ããïŒã«ãšãµã«ã¯ïŒç§å¯ã®æçŽãæžããšãã«ïŒ 'A' ã 'D' ã«ïŒ 'B' ã 'E' ã«ïŒ 'C' ã 'F' ã«ïŒãšããããã«3ã€ããããŠè¡šèšãããšããèšé²ãæ®ã£ãŠããïŒ
</p>
<p>
倧æåã®ã¢ã«ãã¡ããã26æåã ããããªãæååãïŒã«ãšãµã«ãããããã«3æåãã€ãããå€æãæœãåŸãããæååãããïŒãã®ãããªæååãå
ã®æååã«æ»ãããã°ã©ã ãäœæããïŒ
</p>
<p>
åæåã®å€æåãšå€æåŸã®å¯Ÿå¿ã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<table style="margin-left:28px; margin-bottom:28px">
<tr>
<td width="80">倿å</td>
<td width="30">A</td>
<td width="30">B</td>
<td width="30">C</td>
<td width="30">D</td>
<td width="30">E</td>
<td width="30">F</td>
<td width="30">G</td>
<td width="30">H</td>
<td width="30">I</td>
<td width="30">J</td>
<td width="30">K</td>
<td width="30">L</td>
<td width="30">M</td>
<td width="30">N</td>
<td width="30">O</td>
<td width="30">P</td>
<td width="30">Q</td>
<td width="30">R</td>
<td width="30">S</td>
<td width="30">T</td>
<td width="30">U</td>
<td width="30">V</td>
<td width="30">W</td>
<td width="30">X</td>
<td width="30">Y</td>
<td width="30">Z</td>
</tr>
<tr>
<td>倿åŸ</td>
<td>D</td>
<td>E</td>
<td>F</td>
<td>G</td>
<td>H</td>
<td>I</td>
<td>J</td>
<td>K</td>
<td>L</td>
<td>M</td>
<td>N</td>
<td>O</td>
<td>P</td>
<td>Q</td>
<td>R</td>
<td>S</td>
<td>T</td>
<td>U</td>
<td>V</td>
<td>W</td>
<td>X</td>
<td>Y</td>
<td>Z</td>
<td>A</td>
<td>B</td>
<td>C </td>
</tr>
</table>
<p>
äŸãã°ïŒãã®æ¹æ³ã§æåå JOI ã倿ãããš MRL ãåŸããïŒãã®æ¹æ³ã§å€æãããæåå FURDWLD ã®å
ã®æåå㯠CROATIA ã§ããïŒ
</p>
<H2>å
¥å</H2>
<p>
å
¥åã¯1è¡ã ããããªãïŒãã®1è¡ã¯å€§æåã®ã¢ã«ãã¡ãããã®ã¿ã§æ§æãããæååã1ã€å«ãïŒ
</p>
<p>
å
¥åãããæååã®é·ã㯠1000 以äžã§ããïŒ
</p>
<H2>åºå</H2>
<p>
<!--æåºããåºåãã¡ã€ã«ã¯ãå
¥åãããæååãå
ã«æ»ããæååã ããå«ã1è¡ãåºåããã-->
å
¥åãããæååãå
ã«æ»ããæååã ããå«ã1è¡ãåºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>MRL</pre>
<h3>åºåäŸ 1</h3>
<pre>
JOI
</pre>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>FURDWLD</pre>
<h3>åºåäŸ 2</h3>
<pre>CROATIA</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02058 | <h2>G: Tree</h2>
<h3>åé¡</h3>
<p><var>N</var> é ç¹ãããªãæšãäžããããŸããæšã®åé ç¹ã«ã¯ <var>1</var> ãã <var>N</var> ã®çªå·ãå²ãæ¯ãããŠããŸãããŸãã<var>Nâ1</var> æ¬ã®èŸºã®ãã¡ã <var>i\ (= 1, 2, ..., N-1)</var> æ¬ç®ã®èŸºã¯é ç¹ <var>u_i</var> ãšé ç¹ <var>v_i</var> ãšãçµãã§ããŸãã</p>
<p>ãã®æšã® <var>K</var> åã®ç©ºã§ãªãéšåã°ã©ãã®çµã§ãã£ãŠãåéšåã°ã©ããããããé£çµã§ãã©ã®äºã€ã®çžç°ãªãéšåã°ã©ããé ç¹ãå
±æããªããã®ã®åæ°ãæ±ããããã°ã©ã ãäœæããŠãã ããããã ãçãããšãŠã倧ãããªãããšãããããã<var>998244353</var> ã§å²ã£ãããŸããçããŠãã ããã</p>
<p>ãªãã<var>K</var> åã®éšåã°ã©ããããªãéåãåäžã®ãã®ã¯ã<var>K</var> åã®éšåã°ã©ãã®é åºãç°ãªããã®ãåäžèŠãããã®ãšããŸãã</p>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>N</var> <var>K</var>
<var>u_1</var> <var>v_1</var>
<var>:</var>
<var>u_{N-1}</var> <var>v_{N-1}</var>
</pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>2 \leq N \leq 10^{5}</var></li>
<li> <var>1 \leq K \leq min ( N, 300 )</var></li>
<li> <var>1 \leq u_i, v_i \leq N</var></li>
<li> <var>u_i \neq v_i</var></li>
<li> <var>i \neq j</var> ã«å¯Ÿã㊠<var>(u_i, v_i) \neq (u_j, v_j)</var></li>
<li> å
¥åã¯ãã¹ãп޿°ã§äžããããã</li>
<li> äžããããã°ã©ãã¯æšã§ããããšãä¿èšŒãããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>çããè¡šãæŽæ°ãäžè¡ã«åºåããŠãã ããã<var>998244353</var> ã§å²ã£ãããŸããåºåããããšã«æ³šæããŠãã ããã</p>
<h3>å
¥åäŸ 1</h3>
<pre>
3 2
1 2
1 3
</pre>
<h3>åºåäŸ 1</h3>
<pre>5</pre>
<p>以äžã® <var>5</var> éãããããŸã:</p>
<ul>
<li> <var>\{ 1 \}</var> ãš <var>\{ 2 \}</var></li>
<li> <var>\{ 1 \}</var> ãš <var>\{ 3 \}</var></li>
<li> <var>\{ 2 \}</var> ãš <var>\{ 3 \}</var></li>
<li> <var>\{ 1, 2 \}</var> ãš <var>\{ 3 \}</var></li>
<li> <var>\{ 1, 3 \}</var> ãš <var>\{ 2 \}</var></li>
</ul>
<h3>å
¥åäŸ 2</h3>
<pre>
4 4
1 2
1 3
1 4
</pre>
<h3>åºåäŸ 2</h3>
<pre>1</pre>
<p><var>( \{ 1 \}, \{ 2 \}, \{ 3 \}, \{ 4 \} )</var> ã® <var>1</var> éããããããŸããã</p>
<h3>å
¥åäŸ 3</h3>
<pre>
7 4
1 7
2 1
7 4
3 4
5 7
6 3
</pre>
<h3>åºåäŸ 3</h3>
<pre>166</pre>
|
p00065 |
<H1>ååŒ</H1>
<p>
ååŒå
ã®é¡§å®¢çªå·ãšååŒæ¥ãæããšã«èšé²ããããŒã¿ããããŸãã仿ã®ããŒã¿ãšå
æã®ããŒã¿ãèªã¿èŸŒãã§ãå
æããïŒã¶æé£ç¶ã§ååŒã®ããäŒç€Ÿã®é¡§å®¢çªå·ãšååŒã®ãã£ãåæ°ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããæã
ã®ååŒå
æ°ã¯ 1,000 瀟以å
ã§ãã
</p>
<H2>Input</H2>
<p>
仿ã®ããŒã¿ãšãå
æã®ããŒã¿ãïŒè¡ã®ç©ºè¡ã§åºåãããŠäžããããŸããããããã®ããŒã¿ã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>c<sub>1</sub></var>,<var>d<sub>1</sub></var>
<var>c<sub>2</sub></var>,<var>d<sub>2</sub></var>
...
...
</pre>
<p>
<var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 1,000) ã¯é¡§å®¢çªå·ãè¡šãæŽæ°ã <var>d<sub>i</sub></var> (1 ≤ <var>d<sub>i</sub></var> ≤ 31) ã¯ååŒæ¥ãè¡šãæŽæ°ã§ãã
</p>
<H2>Output</H2>
<p>
ïŒã¶æé£ç¶ã§ååŒã®ããäŒç€Ÿã«ã€ããŠã顧客çªå·ãå°ããé ã«é¡§å®¢çªå·ãšååŒåæ°ã®ç·æ°ã空çœã§åºåã£ãŠåºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
123,10
56,12
34,14
123,3
56,4
123,5
</pre>
<H2>Output for the Sample Input</H2>
<pre>
56 2
123 3
</pre>
|
p03560 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K \leq 10^5</var></li>
<li><var>K</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest possible sum of the digits in the decimal notation of a positive multiple of <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><var>12=6Ã2</var> yields the smallest sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>41
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p><var>11111=41Ã271</var> yields the smallest sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>79992
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>36
</pre></section>
</div>
</span> |
p03130 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are four towns, numbered <var>1,2,3</var> and <var>4</var>.
Also, there are three roads. The <var>i</var>-th road connects different towns <var>a_i</var> and <var>b_i</var> bidirectionally.
No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.</p>
<p>Determine if we can visit all the towns by traversing each of the roads exactly once.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a_i,b_i \leq 4(1\leq i\leq 3)</var></li>
<li><var>a_i</var> and <var>b_i</var> are different. <var>(1\leq i\leq 3)</var></li>
<li>No two roads connect the same pair of towns.</li>
<li>Any town can be reached from any other town using the roads.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>a_3</var> <var>b_3</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If we can visit all the towns by traversing each of the roads exactly once, print <code>YES</code>; otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>We can visit all the towns in the order <var>1,3,2,4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
2 4
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 1
3 2
4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre></section>
</div>
</span> |
p03999 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of digits between <code>1</code> and <code>9</code>, inclusive.
You can insert the letter <code>+</code> into some of the positions (possibly none) between two letters in this string.
Here, <code>+</code> must not occur consecutively after insertion.</p>
<p>All strings that can be obtained in this way can be evaluated as formulas.</p>
<p>Evaluate all possible formulas, and print the sum of the results.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10</var></li>
<li>All letters in <var>S</var> are digits between <code>1</code> and <code>9</code>, inclusive.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the evaluated value over all possible formulas.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>125
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>176
</pre>
<p>There are <var>4</var> formulas that can be obtained: <code>125</code>, <code>1+25</code>, <code>12+5</code> and <code>1+2+5</code>. When each formula is evaluated,</p>
<ul>
<li><var>125</var></li>
<li><var>1+25=26</var></li>
<li><var>12+5=17</var></li>
<li><var>1+2+5=8</var></li>
</ul>
<p>Thus, the sum is <var>125+26+17+8=176</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12656242944
</pre></section>
</div>
</span> |
p02371 |
<H1>Diameter of a Tree</H2>
<br/>
<p>
Given a tree <var>T</var> with non-negative weight, find the diameter of the tree.
</p>
<p>
The diameter of a tree is the maximum distance between two nodes in a tree.
</p>
<H2>Input</H2>
<pre>
<var>n</var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>w<sub>2</sub></var>
:
<var>s<sub>n-1</sub></var> <var>t<sub>n-1</sub></var> <var>w<sub>n-1</sub></var>
</pre>
<p>
The first line consists of an integer <var>n</var> which represents the number of nodes in the tree. Every node has a unique ID from 0 to <var>n</var>-1 respectively.
</p>
<p>
In the following <var>n</var>-1 lines, edges of the tree are given.
<var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent end-points of the <var>i</var>-th edge (undirected) and <var>w<sub>i</sub></var> represents the weight (distance) of the <var>i</var>-th edge.
</p>
<H2>Output</H2>
<p>
Print the diameter of the tree in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>n</var> ≤ 100,000</li>
<li> 0 ≤ <var>w<sub>i</sub></var> ≤ 1,000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4
0 1 2
1 2 1
1 3 3
</pre>
<H2>Sample Output 1</H2>
<pre>
5
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4
0 1 1
1 2 2
2 3 4
</pre>
<H2>Sample Output 2</H2>
<pre>
7
</pre> |
p03833 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> barbecue restaurants along a street.
The restaurants are numbered <var>1</var> through <var>N</var> from west to east, and the distance between restaurant <var>i</var> and restaurant <var>i+1</var> is <var>A_i</var>.</p>
<p>Joisino has <var>M</var> tickets, numbered <var>1</var> through <var>M</var>.
Every barbecue restaurant offers barbecue meals in exchange for these tickets.
Restaurant <var>i</var> offers a meal of <em>deliciousness</em> <var>B_{i,j}</var> in exchange for ticket <var>j</var>.
Each ticket can only be used once, but any number of tickets can be used at a restaurant.</p>
<p>Joisino wants to have <var>M</var> barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location.
Her eventual <em>happiness</em> is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)".
Find her maximum possible eventual happiness.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>2â€Nâ€5Ã10^3</var></li>
<li><var>1â€Mâ€200</var></li>
<li><var>1â€A_iâ€10^9</var></li>
<li><var>1â€B_{i,j}â€10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_{N-1}</var>
<var>B_{1,1}</var> <var>B_{1,2}</var> <var>...</var> <var>B_{1,M}</var>
<var>B_{2,1}</var> <var>B_{2,2}</var> <var>...</var> <var>B_{2,M}</var>
<var>:</var>
<var>B_{N,1}</var> <var>B_{N,2}</var> <var>...</var> <var>B_{N,M}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print Joisino's maximum possible eventual happiness.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
1 4
2 2 5 1
1 3 3 2
2 2 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
</pre>
<p>The eventual happiness can be maximized by the following strategy: start from restaurant <var>1</var> and use tickets <var>1</var> and <var>3</var>, then move to restaurant <var>2</var> and use tickets <var>2</var> and <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 3
1 2 3 4
10 1 1
1 1 1
1 10 1
1 1 1
1 1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>20
</pre></section>
</div>
</span> |
p02721 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has decided to work on <var>K</var> days of his choice from the <var>N</var> days starting with tomorrow.</p>
<p>You are given an integer <var>C</var> and a string <var>S</var>. Takahashi will choose his workdays as follows:</p>
<ul>
<li>After working for a day, he will refrain from working on the subsequent <var>C</var> days.</li>
<li>If the <var>i</var>-th character of <var>S</var> is <code>x</code>, he will not work on Day <var>i</var>, where Day <var>1</var> is tomorrow, Day <var>2</var> is the day after tomorrow, and so on.</li>
</ul>
<p>Find all days on which Takahashi is bound to work.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq K \leq N</var></li>
<li><var>0 \leq C \leq N</var></li>
<li>The length of <var>S</var> is <var>N</var>.</li>
<li>Each character of <var>S</var> is <code>o</code> or <code>x</code>.</li>
<li>Takahashi can choose his workdays so that the conditions in Problem Statement are satisfied.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var> <var>C</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print all days on which Takahashi is bound to work in ascending order, one per line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>11 3 2
ooxxxoxxxoo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>Takahashi is going to work on <var>3</var> days out of the <var>11</var> days. After working for a day, he will refrain from working on the subsequent <var>2</var> days.</p>
<p>There are four possible choices for his workdays: Day <var>1,6,10</var>, Day <var>1,6,11</var>, Day <var>2,6,10</var>, and Day <var>2,6,11</var>.</p>
<p>Thus, he is bound to work on Day <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2 3
ooxoo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
5
</pre>
<p>There is only one possible choice for his workdays: Day <var>1,5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 1 0
ooooo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre></pre>
<p>There may be no days on which he is bound to work.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>16 4 3
ooxxoxoxxxoxoxxo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>11
16
</pre></section>
</div>
</span> |
p00209 |
<H1>åçã«åã£ãŠããæ¯è²ã¯?</H1>
<p>
A åã¯äŒæŽ¥ã«èгå
ã«ãã£ãŠããŸããã宿æ³ããããã«ã®çªããã¯äŒæŽ¥çå°ãäžæã§ããŸããæ¯è²ãçºããŠãããšãåºã«åçã®åã端ãèœã¡ãŠããã®ã«æ°ãã€ããŸãããã©ãããçªããå€ã®æ¯è²ãæ®ã£ãããã§ãããã©ã®èŸºããæ®ã£ãã®ããªããšãA åã¯çªã®å€ã®æ¯è²ãšåçãåã倧ããã«ãªãããã«åçãããããŠãåçãšçªã®å€ã®æ¯è²ãäžèŽããå Žæãæ¢ãå§ããŸããã
</p>
<p>
ããã§ã¯ãA åããã£ãŠããããšãã³ã³ãã¥ãŒã¿ã§ãã£ãŠã¿ãŸããããçªã®å€ã®æ¯è²ã <var>n × n</var> ãã¹ã®æ£æ¹åœ¢ã«åå²ããŸã (<var>n</var> ãæ¯è²ã®å€§ãããšåŒã³ãŸã)ãåãã¹ã«ã¯ããã®ãã¹ã®ç»åã®æ
å ±ã衚ã 0 以äžã®æŽæ°ãæžãããŠããŸãããã¹ã®äœçœ®ã¯åº§æš (<var>x, y</var>) ã§è¡šããŸããåãã¹ã®åº§æšã¯ä»¥äžã®éãã«ãªããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_reflectedScene1"><br/>
</center>
<br/>
<p>
åçã®åã端ã¯ã<var>m × m</var> ãã¹ã®æ£æ¹åœ¢ã§è¡šãããŸã (<var>m</var> ãåçã®åã端ã®å€§ãããšåŒã³ãŸã) ããã®æ£æ¹åœ¢ã®äžã§ãåã端ã®éšåã®ãã¹ã«ã¯ç»åã®æ
å ±ããåã端ã«å«ãŸããªãéšåã®ãã¹ã«ã¯ -1 ãæžãããŠããŸããããšãã°ãäžå³ã§ã¯ãè²ãå¡ãããŠããéšåãå®éã®åçã®åã端ã®åœ¢ã衚ããŠããŸããåã端ã«ç©ŽãéããŠããããšã¯ãããŸãããå¿
ã 1 ã€ã«ã€ãªãã£ãŠããŸãã (0 以äžã®å€ããã€ãã¹ãé ç¹ã ãã§æ¥ããŠãããšãã¯ãã€ãªãã£ãŠããªããã®ãšã¿ãªããŸãã) ãŸããå€ -1 ã®ãã¹ã瞊ãŸãã¯æšª 1 åã«ç«¯ãã端ãŸã§äžŠã¶ããšã¯ãããŸããã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_reflectedScene2">
</center>
<br>
<p>
çªããèŠããæ¯è²ã®äžã§ãåçã®åã端ã 0ã90ã180ã270 床å転ããããããããšäžèŽããé åãæ¢ããŸããããšãã°ãæ¯è²ãäžå³ã®ããã«è¡šããããšããäžå³ã®åã端ãåæèšåãã«90 床å転ããããšãè²ãå¡ãããé åã«äžèŽããŸãã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_reflectedScene3">
</center>
<br>
<p>
çªããèŠããæ¯è²ãšåçã®åãç«¯ã®æ
å ±ãå
¥åãšããæ¯è²ã®äžã§ãåã端ã 0ã90ã180ã270 床å転ããããããããšäžèŽããé åã®æãäžç«¯ã«è¿ããã¹ã®ãã¡ãæã巊端ã«è¿ããã¹ã®åº§æšãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
äžèŽããé åãè€æ°ããå Žåã¯ããããã®é åå
ã«ãããã¹ã®äžã§ãæãäžç«¯ã«è¿ããã¹ã®ãã¡ãæã巊端ã«è¿ããã¹ã®åº§æšãåºåããŠãã ãããäžèŽããé åããªããšãã¯ãNA ãšåºåããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var> <var>m</var>
<var>w<sub>11</sub></var> <var>w<sub>12</sub></var> ... <var>w<sub>1n</sub></var>
<var>w<sub>21</sub></var> <var>w<sub>22</sub></var> ... <var>w<sub>2n</sub></var>
:
<var>w<sub>n1</sub></var> <var>w<sub>n2</sub></var> ... <var>w<sub>nn</sub></var>
<var>p<sub>11</sub></var> <var>p<sub>12</sub></var> ... <var>p<sub>1m</sub></var>
<var>p<sub>21</sub></var> <var>p<sub>22</sub></var> ... <var>p<sub>2m</sub></var>
:
<var>p<sub>m1</sub></var> <var>p<sub>m2</sub></var> ... <var>p<sub>mm</sub></var>
</pre>
<p>
1 è¡ç®ã«<var>n, m</var> (1 ≤ <var>n</var> ≤ 100, 1 ≤ <var>m</var> ≤ 50, <var>m</var> ≤ <var>n</var>) ãäžããããŸãã
</p>
<p>
ç¶ã <var>n</var> è¡ã«çªããèŠããæ¯è²ã®æ
å ± <var>w<sub>ij</sub></var> (0 ≤ <var>w<sub>ij</sub></var> ≤ 15)ãç¶ã <var>m</var> è¡ã«åçã®åã端ã®ããŒã¿ã®æ
å ± <var>p<sub>ij</sub></var> (-1 ≤ <var>p<sub>ij</sub></var> ≤ 15) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ããã¹ã®äœçœ®ã®åº§æšãŸã㯠NA ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
8 4
2 1 3 1 1 5 1 3
2 3 2 4 1 0 2 1
0 3 1 2 1 1 4 2
1 2 3 2 1 1 5 4
0 2 0 1 1 3 2 1
1 3 1 2 2 4 3 2
5 1 2 1 4 1 1 5
4 1 1 0 1 2 2 1
2 -1 -1 -1
0 3 -1 -1
-1 2 2 4
-1 1 -1 1
5 3
1 0 2 3 5
2 3 7 2 1
2 5 4 2 2
8 9 0 3 3
3 6 0 4 7
-1 -1 2
-1 3 5
0 4 -1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4 2
NA
</pre>
|
p02234 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Matrix-chain Multiplication</H1>
<p>
The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$.
</p>
<p>
Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication $M_1M_2...M_n$.
</p>
<H2>Input</H2>
<p>
In the first line, an integer $n$ is given. In the following $n$ lines, the dimension of matrix $M_i$ ($i = 1...n$) is given by two integers $r$ and $c$ which respectively represents the number of rows and columns of $M_i$.
</p>
<H2>Output</H2>
<p>
Print the minimum number of scalar multiplication in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>$1 \leq n \leq 100$</li>
<li>$1 \leq r, c \leq 100$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
6
30 35
35 15
15 5
5 10
10 20
20 25
</pre>
<H2>Sample Output 1</H2>
<pre>
15125
</pre>
|
p03976 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<blockquote>
<p>
Kyoto University Programming Contest is a programming contest voluntarily held by some Kyoto University students.
This contest is abbreviated as <b>K</b>yoto <b>U</b>niversity <b>P</b>rogramming <b>C</b>ontest and called KUPC.
</p>
<p>
source: <a href="http://www.kupc.jp/index.html"><i>Kyoto University Programming Contest Information</i></a>
</p>
</blockquote>
<p>
The problem-preparing committee met to hold this year's KUPC and <var>N</var> problems were proposed there.
The problems are numbered from <var>1</var> to <var>N</var> and the name of <var>i</var>-th problem is <var>P_i</var>.
However, since they proposed too many problems, they decided to divide them into some sets for several contests.
</p>
<p>
They decided to divide this year's KUPC into several KUPCs by dividing problems under the following conditions.
<ul>
<li> One KUPC provides <var>K</var> problems. </li>
<li> Each problem appears at most once among all the KUPCs. </li>
<li> All the first letters of the problem names in one KUPC must be different. </li>
</ul>
</p>
<p>
You, one of the committee members, want to hold as many KUPCs as possible.
Write a program to find the maximum number of KUPCs that can be held this year.
</p>
<h3>Constraints</h3>
<ul>
<li> <var>1 \leq N \leq 10^4</var></li>
<li> <var>1 \leq K \leq 26</var></li>
<li> <var>1 \leq |P_i| \leq 10</var></li>
<li> All characters in <var>P_i</var> are capital letters.</li>
</ul>
<p>
Note that, for each <var>i</var> and <var>j</var> <var>(1 \leq i < j \leq N)</var>,
<var>P_i \neq P_j</var> are not necessarily satisfied.
</p>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>The input is given from Standard Input in the following format:</p>
<pre>
<var>N</var> <var>K</var>
<var>P_1</var>
:
<var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>
Print the maximum number of KUPCs that can be held on one line.
</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
9 3
APPLE
ANT
ATCODER
BLOCK
BULL
BOSS
CAT
DOG
EGG
</pre>
<p>For example, three KUPCs can be held by dividing the problems as follows. </p>
<ul>
<li> First: <code>APPLE</code>, <code>BLOCK</code>, <code>CAT</code></li>
<li> Second: <code>ANT</code>, <code>BULL</code>, <code>DOG</code></li>
<li> Third: <code>ATCODER</code>, <code>BOSS</code>, <code>EGG</code></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
3 2
KU
KYOUDAI
KYOTOUNIV
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
0
</pre>
<p>No KUPC can be held.</p>
</section>
</div>
</span> |
p00659 |
<H1>Problem A: Popularity Estimation</H1>
<p>
ããªãã¯ãšããã¢ãã¡ãŒã·ã§ã³å¶äœäŒç€Ÿã®äŒç»éšé·ã§ãããæšä»ã®ã¢ãã¡ãŒã·ã§ã³å¶äœäŒç€Ÿãå¶äœãããã®ã¯ãã¢ãã¡ãŒã·ã§ã³ãã®ãã®ã«ãšã©ãŸããªããé¢é£ååãäŸãã°ç»å Žãã£ã©ã¯ã¿ãŒã®ãã£ã®ã¥ã¢ããã£ã©ã¯ã¿ãŒãœã³ã°CDãªã©ããéèŠãªåçæºãªã®ã§ããããã®åçãã©ãã ã䌞ã°ãããã¯ãã²ãšãã«äŒç»éšé·ã®ããªãã«ããã£ãŠããã®ã§ãã£ãã
</p>
<p>
åœããåã®ããšã ãããããã£ãé¢é£ååã¯éé²ã«çºå£²ããã°ãããšãããã®ã§ã¯ãªããååã®éçºã«ã¯å€ãã®æéãšäºç®ãå¿
èŠãªããã ãã¢ãã¡ã®ç»å Žãã£ã©ã¯ã¿ãŒã®ãã£ã®ã¥ã¢ãçºå£²ããã«ããŠããå€ãã®å£²äžãèŠèŸŒãŸããã人æ°ããããã£ã©ã¯ã¿ãŒã®ãã®ã«éããªããã°ãªããªãã
</p>
<p>
ãã£ã©ã¯ã¿ãŒã®äººæ°åºŠãæž¬ãææ®µã®äžã€ããäººæ°æç¥šã§ãããããªããä»ãŸã§ããã€ãã®äººæ°æç¥šãäŒç»ããŠããããã©ãããèŠèŽè
ã¯ãã®äŒç»ã«äžæºãæ±ãã€ã€ããããã ã人æ°åºŠã枬ãä»ã®ææ³ã®ç¢ºç«ãæ¥åã§ããã
</p>
<p>
ããã§ããªãã¯ãã²ãšã€ã®ä»®èª¬ãç«ãŠãããããã£ã©ã¯ã¿ãŒã®äººæ°åºŠã¯ããã®ã¢ãã¡æ¬ç·šäžã«ãããç»å Žæéã®ç·åã«æ¯äŸããããšãããã®ã ãããªãã¯ãã®ä»®èª¬ãæ€èšŒãããããããããã®ãã£ã©ã¯ã¿ãŒã®ç»å Žæéãéèšããããã°ã©ã ãæžãããšã«ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã
åã±ãŒã¹ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>n</i>
<i>name<sub>0</sub></i> <i>m<sub>0</sub></i> <i>d<sub>0,0</sub></i> ... <i>d<sub>0,m<sub>0</sub>-1</sub></i>
<i>name<sub>1</sub></i> <i>m<sub>1</sub></i> <i>d<sub>1,0</sub></i> ... <i>d<sub>1,m<sub>1</sub>-1</sub></i>
.
.
.
<i>name<sub>n-1</sub></i> <i>m<sub>n-1</sub></i> <i>d<sub>n-1,0</sub></i> ... <i>d<sub>n-1,m<sub>n-1</sub>-1</sub></i>
</pre>
<p>
<i>n</i> ã¯ãã£ã©ã¯ã¿ãŒã®äººæ°ã衚ãã<br>
<i>name<sub>i</sub></i> ã¯ãã£ã©ã¯ã¿ãŒã®ååã衚ãã<br>
<i>m<sub>i</sub></i> ã¯ãã£ã©ã¯ã¿ãŒãæ ã£ãŠããæå»ã®çš®é¡ã衚ãã<br>
<i>m<sub>i</sub></i> ã®åŸã«ã¯<i>m<sub>i</sub></i> åã®æŽæ°<i>d<sub>i,j</sub></i> ãäžããããã<br>
<i>d<sub>i,j</sub></i>ã¯ãã£ã©ã¯ã¿ãŒãæ ã£ãŠããæå»ã衚ãã<br>
å
¥åã®çµããã¯<i>n=0</i> ãããªãè¡ã«ãã£ãŠäžãããã<br>
</p>
<p>
ããæå»ã«1人ã®ãã£ã©ã¯ã¿ãŒã®ã¿ãç»é¢ã«æ ã£ãŠããå Žåããã®ãã£ã©ã¯ã¿ãŒã¯nãã€ã³ããåŸãããšãåºæ¥ãã<br>
åæå»ã«æ ããã£ã©ã¯ã¿ãŒã1人å¢ããæ¯ã«ããã®æå»ã«æ ã£ãŠãããã£ã©ã¯ã¿ãŒãåŸããããã€ã³ãã¯1æžãã<br>
n人ã®ãã£ã©ã¯ã¿ãŒãåæå»ã«æ ã£ãŠããå Žåãn人ã®äººããããã«1ãã€ã³ããå ç®ãããã<br>
</p>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºããã<br>
2 ≤ <i>n</i> ≤ 20<br>
0 ≤ <i>m<sub>i</sub></i> ≤ 30<br>
0 ≤ <i>d<sub>i,j</sub></i> < 30<br>
<i>i</i> çªç®ã®ãã£ã©ã¯ã¿ãŒã«ã€ããŠ<i>d<sub>i,j</sub></i> ã¯ãã¹ãŠç°ãªãã<br>
<i>name<sub>i</sub></i> ã¯ã¢ã«ãã¡ãããã®å€§æåãŸãã¯å°æåã®ã¿ãå«ã¿ãé·ãã¯10以äžã§ããã
</p>
<h2>Output</h2>
<p>
æå°ã®ãã€ã³ããæã€ãã£ã©ã¯ã¿ãŒã®ãã€ã³ããšãã®ååã1ã€ã®ç©ºçœã§åºåã£ãŠåºåããã<br>
æå°ã®ãã€ã³ããæã€ãã£ã©ã¯ã¿ãŒãè€æ°ããå Žåã¯ååãèŸæžé ã§æå°ã®äººãéžã¶ããšã
</p>
<h2>Sample input</h2>
<pre>
4
akzakr 2 1 8
fnmyi 5 2 3 4 6 9
tsnukk 5 2 3 4 7 9
yskwcnt 6 3 4 7 8 9 10
4
akzakr 1 2
fnmyi 3 10 11 12
tsnukk 2 1 8
yskwcnt 2 1 8
5
knmmdk 2 13 19
akmhmr 4 13 15 19 22
mksyk 6 3 7 12 13 15 19
skrkyk 3 1 4 8
tmemm 3 1 17 24
5
knmmdk 5 5 6 16 18 26
akmhmr 9 3 4 7 11 14 15 17 18 20
mksyk 5 6 13 25 27 28
skrkyk 4 3 16 23 24
tmemm 3 6 12 20
14
hrkamm 6 4 6 8 10 20 22
mkhsi 6 1 10 12 15 22 27
hbkgnh 2 4 9
chyksrg 8 3 4 12 15 16 20 25 28
mktkkc 6 0 1 8 15 17 20
tknsj 6 6 8 18 19 25 26
yyitktk 3 3 12 18
ykhhgwr 5 3 9 10 11 24
amftm 7 2 6 8 12 13 14 17
mmftm 4 6 12 16 18
rtkakzk 3 14 15 21
azsmur 7 1 2 4 12 15 18 20
iormns 2 4 20
ktrotns 6 7 12 14 17 20 25
14
hrkamm 2 4 21
mkhsi 6 2 3 8 11 18 20
hbkgnh 4 4 16 28 29
chyksrg 5 0 3 9 17 22
mktkkc 2 7 18
tknsj 3 3 9 23
yyitktk 3 10 13 25
ykhhgwr 2 18 26
amftm 3 13 18 22
mmftm 4 1 20 24 27
rtkakzk 2 1 10
azsmur 5 2 5 10 14 17
iormns 3 9 15 16
ktrotns 5 7 12 16 17 20
0
</pre>
<H2>Sample output</H2>
<pre>
7 akzakr
4 akzakr
6 knmmdk
12 tmemm
19 iormns
24 mktkkc
</pre>
<hr>
The University of Aizu Programming Contest 2011 Summer<br>
åæ¡: Tomoya Sakai<br>
å顿: Takashi Tayama<br>
</p> |
p02664 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a string <var>S</var> consisting of the uppercase English letters <code>P</code> and <code>D</code>, let the <em>doctoral and postdoctoral quotient</em> of <var>S</var> be the total number of occurrences of <code>D</code> and <code>PD</code> in <var>S</var> as contiguous substrings. For example, if <var>S =</var> <code>PPDDP</code>, it contains two occurrences of <code>D</code> and one occurrence of <code>PD</code> as contiguous substrings, so the doctoral and postdoctoral quotient of <var>S</var> is <var>3</var>.</p>
<p>We have a string <var>T</var> consisting of <code>P</code>, <code>D</code>, and <code>?</code>.</p>
<p>Among the strings that can be obtained by replacing each <code>?</code> in <var>T</var> with <code>P</code> or <code>D</code>, find one with the maximum possible doctoral and postdoctoral quotient.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |T| \leq 2 \times 10^5</var></li>
<li><var>T</var> consists of <code>P</code>, <code>D</code>, and <code>?</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each <code>?</code> in <var>T</var> with <code>P</code> or <code>D</code>.
If there are multiple such strings, you may print any of them.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>PD?D??P
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>PDPDPDP
</pre>
<p>This string contains three occurrences of <code>D</code> and three occurrences of <code>PD</code> as contiguous substrings, so its doctoral and postdoctoral quotient is <var>6</var>, which is the maximum doctoral and postdoctoral quotient of a string obtained by replacing each <code>?</code> in <var>T</var> with <code>P</code> or <code>D</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>P?P?
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>PDPD
</pre></section>
</div>
</span> |
p03425 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people. The name of the <var>i</var>-th person is <var>S_i</var>.</p>
<p>We would like to choose three people so that the following conditions are met:</p>
<ul>
<li>The name of every chosen person begins with <code>M</code>, <code>A</code>, <code>R</code>, <code>C</code> or <code>H</code>.</li>
<li>There are no multiple people whose names begin with the same letter.</li>
</ul>
<p>How many such ways are there to choose three people, disregarding order?</p>
<p>Note that the answer may not fit into a <var>32</var>-bit integer type.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>S_i</var> consists of uppercase English letters.</li>
<li><var>1 \leq |S_i| \leq 10</var></li>
<li><var>S_i \neq S_j (i \neq j)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S_1</var>
<var>:</var>
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there are <var>x</var> ways to choose three people so that the given conditions are met, print <var>x</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can choose three people with the following names:</p>
<ul>
<li>
<p><code>MASHIKE</code>, <code>RUMOI</code>, <code>HABORO</code></p>
</li>
<li>
<p><code>MASHIKE</code>, <code>RUMOI</code>, <code>HOROKANAI</code></p>
</li>
</ul>
<p>Thus, we have two ways.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
ZZ
ZZZ
Z
ZZZZZZZZZZ
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Note that there may be no ways to choose three people so that the given conditions are met.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
</pre></section>
</div>
</span> |
p01418 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Sleeping Time</H1>
<p>
Miki is a high school student.
She has a part time job, so she cannot take enough sleep on weekdays.
She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her.
She is now trying to figure that out with the following algorithm:
</p>
<ol>
<li> Begin with the numbers <var>K</var>, <var>R</var> and <var>L</var>.</li>
<li>She tries to sleep for <var>H=(R+L)/2</var> hours.</li>
<li>If she feels the time is longer than or equal to the optimal length, then update <var>L</var> with <var>H</var>. Otherwise, update <var>R</var> with <var>H</var>.</li>
<li>After repeating step 2 and 3 for <var>K</var> nights, she decides her optimal sleeping time to be <var>T' = (R+L)/2</var>.</li>
</ol>
<p>
If her feeling is always correct, the steps described above should give her a very accurate optimal sleeping time.
But unfortunately, she makes mistake in step 3 with the probability <var>P</var>.
</p>
<p>
Assume you know the optimal sleeping time <var>T</var> for Miki.
You have to calculate the probability <var>PP</var> that the absolute difference of <var>T'</var> and <var>T</var> is smaller or equal to <var>E</var>.
It is guaranteed that the answer remains unaffected by the change of <var>E</var> in <var>10^{-10}</var>.
</p>
<H2>Input</H2>
<p>
The input follows the format shown below
</p>
<p>
<var>K</var> <var>R</var> <var>L</var><br/>
<var>P</var><br/>
<var>E</var><br/>
<var>T</var><br/>
</p>
<p>
Where the integers <var>0 \leq K \leq 30</var>, <var>0 \leq R \leq L \leq 12</var> are the parameters for the algorithm described above.
The decimal numbers on the following three lines of the input gives the parameters for the estimation. You can assume <var>0 \leq P \leq 1</var>, <var>0 \leq E \leq 12</var>, <var>0 \leq T \leq 12</var>.
</p>
<H2>Output</H2>
<p>
Output <var>PP</var> in one line.
The output should not contain an error greater than <var>10^{-5}</var>.
</p>
<H2>Sample Input 1</H2>
<pre>
3 0 2
0.10000000000
0.50000000000
1.00000000000
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
0.900000
</pre>
<H2>Sample Input 2</H2>
<pre>
3 0 2
0.10000000000
0.37499999977
1.00000000000
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
0.810000
</pre>
<H2>Sample Input 3</H2>
<pre>
3 0 2
0.10000000000
0.00000100000
0.37500000000
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
0.729000
</pre>
<H2>Sample Input 4</H2>
<pre>
3 0 2
0.20000000000
0.00000100000
0.37500000000
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>
0.512000
</pre>
|
p03075 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In AtCoder city, there are five antennas standing in a straight line. They are called Antenna <var>A, B, C, D</var> and <var>E</var> from west to east, and their coordinates are <var>a, b, c, d</var> and <var>e</var>, respectively.<br/>
Two antennas can communicate directly if the distance between them is <var>k</var> or less, and they cannot if the distance is greater than <var>k</var>.<br/>
Determine if there exists a pair of antennas that cannot communicate <strong>directly</strong>.<br/>
Here, assume that the distance between two antennas at coordinates <var>p</var> and <var>q</var> (<var>p < q</var>) is <var>q - p</var>. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>a, b, c, d, e</var> and <var>k</var> are integers between <var>0</var> and <var>123</var> (inclusive).</li>
<li><var>a < b < c < d < e</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var>
<var>b</var>
<var>c</var>
<var>d</var>
<var>e</var>
<var>k</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <code>:(</code> if there exists a pair of antennas that cannot communicate <strong>directly</strong>, and print <code>Yay!</code> if there is no such pair.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
2
4
8
9
15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yay!
</pre>
<p>In this case, there is no pair of antennas that cannot communicate directly, because:</p>
<ul>
<li>the distance between <var>A</var> and <var>B</var> is <var>2 - 1</var> = <var>1</var></li>
<li>the distance between <var>A</var> and <var>C</var> is <var>4 - 1</var> = <var>3</var></li>
<li>the distance between <var>A</var> and <var>D</var> is <var>8 - 1</var> = <var>7</var></li>
<li>the distance between <var>A</var> and <var>E</var> is <var>9 - 1</var> = <var>8</var></li>
<li>the distance between <var>B</var> and <var>C</var> is <var>4 - 2</var> = <var>2</var></li>
<li>the distance between <var>B</var> and <var>D</var> is <var>8 - 2</var> = <var>6</var></li>
<li>the distance between <var>B</var> and <var>E</var> is <var>9 - 2</var> = <var>7</var></li>
<li>the distance between <var>C</var> and <var>D</var> is <var>8 - 4</var> = <var>4</var></li>
<li>the distance between <var>C</var> and <var>E</var> is <var>9 - 4</var> = <var>5</var></li>
<li>the distance between <var>D</var> and <var>E</var> is <var>9 - 8</var> = <var>1</var></li>
</ul>
<p>and none of them is greater than <var>15</var>. Thus, the correct output is <code>Yay!</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
18
26
35
36
18
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>:(
</pre>
<p>In this case, the distance between antennas <var>A</var> and <var>D</var> is <var>35 - 15</var> = <var>20</var> and exceeds <var>18</var>, so they cannot communicate directly.
Thus, the correct output is <code>:(</code>.</p></section>
</div>
</span> |
p01048 |
<h1>Divisor</h1>
<h2>Problem</h2>
<p>
12以äžã®èªç¶æ° <var>N</var> ãäžããããã®ã§ãçŽæ°ã®åæ°ãã¡ããã© <var>N</var> åã§ãããããªæå°ã®èªç¶æ°ãæ±ããã
</p>
<h2>Input</h2>
<p>
1ã€ã®èªç¶æ° <var>N</var> ã 1 è¡ã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>N</var> ≤ 12</li>
</ul>
<h2>Output</h2>
<p>
çŽæ°ã®åæ°ãã¡ããã© <var>N</var> åã§ãããããªæå°ã®èªç¶æ°ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
2
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
<h2>Sample Input 3</h2>
<pre>
3
</pre>
<h2>Sample Output 3</h2>
<pre>
4
</pre>
|
p00835 |
<H1><font color="#000">Problem I:</font> Crossing Prisms</H1>
<p>
Prof. Bocchan is a mathematician and a sculptor. He likes to create sculptures with mathematics.
</p>
<p>
His style to make sculptures is very unique. He uses two identical prisms. Crossing them at right
angles, he makes a polyhedron that is their intersection as a new work. Since he finishes it up
with painting, he needs to know the surface area of the polyhedron for estimating the amount
of pigment needed.
</p>
<p>
For example, let us consider the two identical prisms in Figure 1. The definition of their cross
section is given in Figure 2. The prisms are put at right angles with each other and their
intersection is the polyhedron depicted in Figure 3. An approximate value of its surface area
is 194.8255.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_crossingPrisms1">
<p>Figure 1: Two identical prisms at right angles</p>
</center>
<p>
Given the shape of the cross section of the two identical prisms, your job is to calculate the
surface area of his sculpture.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, followed by a single line containing only a zero. The
first line of each dataset contains an integer <i>n</i> indicating the number of the following lines, each
of which contains two integers <i>a<sub>i</sub></i> and <i>b<sub>i</sub></i> (<i>i</i> = 1, ... , <i>n</i>).
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_crossingPrisms2">
<p>Figure 2: Outline of the cross section</p>
</center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_crossingPrisms3">
<p>Figure 3: The intersection</p>
</center>
<p>
A closed path formed by the given points (<i>a</i><sub>1</sub>, <i>b</i><sub>1</sub>), (<i>a</i><sub>2</sub>, <i>b</i><sub>2</sub> ), ... , (<i>a<sub>n</sub></i>, <i>b<sub>n</sub></i>), (<i>a</i><sub><i>n</i>+1</sub>, <i>b</i><sub><i>n</i>+1</sub>)(= (<i>a</i><sub>1</sub>, <i>b</i><sub>1</sub>))
indicates the outline of the cross section of the prisms. The closed path is simple, that is, it does
not cross nor touch itself. The right-hand side of the line segment from (<i>a<sub>i</sub></i>, <i>b<sub>i</sub></i>) to (<i>a<sub>i</sub></i>+1 , <i>b<sub>i</sub></i>+1 ) is the inside of the section.
</p>
<p>
You may assume that 3 ≤ <i>n</i> ≤ 4, 0 ≤ <i>a<sub>i</sub></i> ≤ 10 and 0 ≤ <i>b<sub>i</sub></i> ≤ 10 (<i>i</i> = 1, ... , <i>n</i>).
</p>
<p>
One of the prisms is put along the <i>x</i>-axis so that the outline of its cross section at <i>x</i> = <i>ζ</i> is
indicated by points (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> ) = (<i>ζ</i>, <i>a<sub>i</sub></i>, <i>b<sub>i</sub></i>) (0 ≤ <i>ζ</i> ≤ 10, <i>i</i> = 1, ... , <i>n</i>). The other prism is put
along the <i>y</i>-axis so that its cross section at <i>y</i> = <i>η</i> is indicated by points (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i>) = (<i>a<sub>i</sub></i>, <i>η</i>, <i>b<sub>i</sub></i>)
(0 ≤ <i>η</i> ≤ 10, <i>i</i> = 1, ... , <i>n</i>).
</p>
<H2>Output</H2>
<p>
The output should consist of a series of lines each containing a single decimal fraction. Each
number should indicate an approximate value of the surface area of the polyhedron defined by the corresponding dataset. The value may contain an error less than or equal to 0.0001. You
may print any number of digits below the decimal point.
</p>
<H2>Sample Input</H2>
<pre>
4
5 0
0 10
7 5
10 5
4
7 5
10 5
5 0
0 10
4
0 10
10 10
10 0
0 0
3
0 0
0 10
10 0
4
0 10
10 5
0 0
9 5
4
5 0
0 10
5 5
10 10
4
0 5
5 10
10 5
5 0
4
7 1
4 1
0 1
9 5
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
194.8255
194.8255
600.0000
341.4214
42.9519
182.5141
282.8427
149.2470
</pre>
|
p02808 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>There are <var>N</var> children, numbered <var>1,2,\ldots,N</var>.
In the next <var>K</var> days, we will give them some cookies.
In the <var>i</var>-th day, we will choose <var>a_i</var> children among the <var>N</var> with equal probability, and give one cookie to each child chosen. (We make these <var>K</var> choices independently.)</p>
<p>Let us define the <em>happiness</em> of the children as <var>c_1 \times c_2 \times \ldots \times c_N</var>, where <var>c_i</var> is the number of cookies received by Child <var>i</var> in the <var>K</var> days.
Find the expected happiness multiplied by <var>\binom{N}{a_1} \times \binom{N}{a_2} \times \ldots \times \binom{N}{a_K}</var> (we can show that this value is an integer), modulo <var>(10^{9}+7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3>
<p><var>\binom{n}{k}</var> denotes the number of possible choices of <var>k</var> objects out of given distinct <var>n</var> objects, disregarding order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>1 \leq K \leq 20</var></li>
<li><var>1 \leq a_i \leq N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<ul>
<li>On the first day, all the children <var>1</var>, <var>2</var>, and <var>3</var> receive one cookie.</li>
<li>On the second day, two out of the three children <var>1</var>, <var>2</var>, and <var>3</var> receive one cookie.</li>
<li>Their happiness is <var>4</var> in any case, so the expected happiness is <var>4</var>. Print this value multiplied by <var>\binom{3}{3} \times \binom{3}{2}</var>, which is <var>12</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>856 16
399 263 665 432 206 61 784 548 422 313 848 478 827 26 398 63
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>337587117
</pre>
<ul>
<li>Find the expected value multiplied by <var>\binom{N}{a_1} \times \binom{N}{a_2} \times \ldots \times \binom{N}{a_K}</var>, modulo <var>(10^9+7)</var>.</li>
</ul></section>
</div>
</span> |
p01727 |
<p>ããã°ã©ãã³ã°ã³ã³ãã¹ãã®å宿ã§åºãåé¡ã®ã¢ã€ãã£ã¢ãåºãã«å°ã£ãŠããã€ã¯ã¿åã¯ãããæ¥å人ã«çžè«ããã
</p>
<p>ã€ã¯ã¿åãããããã¢ã«ãŽãªãºã ã䜿ããªããšè§£ããªããããªåé¡ãåºããããã§ããã©ããªã«ããããŸããããïŒã
</p>
<p>å人ãããã§ã¯ãããããã®ãèãããããããããªãã§ããã
</p>
<p>ãã®ããã«ããŠãã®å人ã¯ä»¥äžã®ãããªåé¡ã®åæ¡ãšãªãã¢ã€ãã¢ãèããŠãããã
</p>
<p>2鲿°<var>A,B</var>ãäžããããæã以äžã®æ§ãªã¯ãšãªãåŠçããã
<ul>
<li> åºåã¯ãšãª: max{<var>x</var> ã2鲿°ã§è¡šãããšãã®ã1ã®æ° | <var>A ≤ x < A+B</var> }ãåºå
</li>
<li> A倿Žã¯ãšãª: <var>A</var>ã®æäžäœããããã<var>i</var>ãããç®(0-origin)ãå転
</li>
<li> B倿Žã¯ãšãª: <var>B</var>ã®æäžäœããããã<var>i</var>ãããç®(0-origin)ãå転
</li></ul>
<p><var>i</var>ãããç®ãšããã®ã 0-origin ã§è¡šãããŠããããšã«æ³šæããã
ã€ãŸãã<var>A</var>ã®æäžäœããããã0ãããç®ãšã¯æäžäœãããã衚ãã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>A</var> <var>B</var><br><var>Q<sub>1</sub></var><br>...<br><var>Q<sub>N</sub></var></pre>
<p>1è¡ç®ã«ã¯ãšãªã®æ°N,2鲿°A, Bãäžããããã
</p>
<p>2ããN+1è¡ç®ã«ã¯ä»¥äžã®æ§ãªã¯ãšãªãäžããããã
</p>
<ul><li> Q
</li><li> A <var>i</var>
</li><li> B <var>i</var>
</li></ul>
<p>Qãåºåã¯ãšãªããA <var>i</var>,B <var>i</var>ã¯ãããã<var>A</var>ã®æäžäœããããã<var>i</var>ãããç®ã<var>B</var>ã®æäžäœããããã<var>i</var>ãããç®ãå転ããã倿Žã¯ãšãªã衚ããŠããã
</p>
<h3>Constraints</h3>
<p>å
¥åäžã®å倿°ã¯ä»¥äžã®å¶çŽãæºããã
</p>
<ul><li> <var>1 ≤ N < 300,000</var>
</li><li> <var>1 ≤ |A|,|B| ≤ 300,000</var> (<var>|A|</var>ã¯<var>A</var>ã®é·ã)
</li><li> A <var>i</var> ãšããã¯ãšãªã§ã¯ <var>0 ≤ i < |A|</var>
</li><li> B <var>i</var> ãšããã¯ãšãªã§ã¯ <var>0 ≤ i < |B|</var>
</li><li> <var>B</var>ã0ã«ãªãããšã¯ãªã
</li></ul>
<h2>Output</h2>
<p>åºåã¯ãšãªããšã«çãã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>4 10000 00101
Q
A 0
B 1
Q
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>3
4
</pre>
<p>æåã®åºåã¯ãšãªã§ã¯ <var>A=10000</var>, <var>B=00101</var>, <var>A+B=10101</var>ãªã®ã§æ±ãã<var>x</var>ã¯10011
</p>
<p>次ã®åºåã¯ãšãªã§ã¯ <var>A=10001</var>, <var>B=00111</var>, <var>A+B=11000</var>ãªã®ã§æ±ãã<var>x</var>ã¯10111
</p>
<h2>Sample Input 2</h2>
<pre>9 0110111101 0010100111
Q
B 4
Q
A 4
Q
B 9
Q
A 8
Q
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>9
9
9
10
9
</pre> |
p01377 |
<div>
<h1 class="title">åé¡ B : (iwi)</h1>
<p>20XX 幎ã®ä»ïŒGââgle 瀟ã®äžççãªæ¯é
ã«ããïŒäººã
ã®ã³ãã¥ãã±ãŒã·ã§ã³ã¯éãããŠããïŒ
äŸãã°ïŒèªç±ã«äººãšæ
å ±ããããšãããããšã¯åºæ¬çã«èš±ãããŠããªãïŒ
ç¹ã«ïŒéå»ã«ããã°ã©ãã³ã°ã³ã³ãã¹ãã§åã銳ãã匷豪ãã¡ã¯ïŒå±éºãšå€æããïŒ
ãäºããã©ãã©ã«ããïŒå¯ãã«æ³šææ·±ãç£èŠãããŠãããšããïŒ</p>
<p>èªåãïŒãããªäžäººã§ãã£ãïŒãããªæ°ãããïŒ
ãããå®ã¯ïŒèªåã¯èšæ¶ã倱ã£ãŠããŸã£ãŠããã®ã ïŒ
èªåãäœãšåä¹ã£ãŠãããïŒãããããæãåºããªãïŒ
'i' ãšã 'w' ãšãæ¬åŒ§ãšãã䜿ã£ãŠããæ°ããããïŒ
ããã£ãœããã®ãæžãã ããŠã¿ãŠãïŒãã£ããããªãïŒ
ããããã°ïŒä»æãåºããããšã«ã¯ïŒå·Šå³ã«ç·å¯Ÿç§°ã ã£ãæ°ãããã®ã ïŒ</p>
<div>
<h1>åé¡</h1>
<p>'i', 'w', '(', ')' ãããªãæååãäžããããæïŒ
äžéšã®æåãä»ã®æåã«çœ®ãæããŠïŒ'i', 'w', '(', ')' ãããªãå·Šå³ã«ç·å¯Ÿç§°ãªæååã«ãããïŒ
æåã®è¿œå ãåé€ã¯èš±ããïŒ1 æåãå¥ã® 1 æåã«å€ããæäœã®ã¿ãè¡ãããšã«ããïŒ
å°ãªããšãäœæå眮ãæããªããã°ãªããªãããåºåããããã°ã©ã ãäœæããïŒ</p>
<p>ããã§çšããå·Šå³ã«ç·å¯Ÿç§°ã®å®çŸ©ã¯ïŒä»¥äžãšããïŒ</p>
<ol class="arabic simple">
<li>以äžã®æååã¯å·Šå³ã«ç·å¯Ÿç§°ïŒ</li>
</ol>
<blockquote>
<ul class="simple">
<li>空æåå</li>
<li>"i"</li>
<li>"w"</li>
</ul>
</blockquote>
<ol class="arabic simple" start="2">
<li>æåå <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> ãå·Šå³ã«ç·å¯Ÿç§°ã®ãšãïŒä»¥äžã®æååãå·Šå³ã«ç·å¯Ÿç§°ïŒ</li>
</ol>
<blockquote>
<ul class="simple">
<li>"i" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "i"</li>
<li>"w" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "w"</li>
<li>"(" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> ")"</li>
<li>")" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "("</li>
</ul>
</blockquote>
<ol class="arabic simple" start="3">
<li>以äžã®ãã®ã®ã¿ãå·Šå³ã«ç·å¯Ÿç§°ïŒ</li>
</ol>
<p>ããã§ïŒ"i" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "i" ãšã¯ "i" ãš <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> ãš "i" ãé£çµãããã®ã衚ãïŒ
ä»ã®ãã®ãåæ§ã§ããïŒ</p>
</div>
<div>
<h1>å
¥å</h1>
<p>å
¥å㯠'i', 'w', '(', ')' ãããªã 1 ã€ã®æååã§ããïŒ</p>
</div>
<div>
<h1>åºå</h1>
<p>眮ãæããªããã°ãªããªãæåæ°ãè¡šãæŽæ°ãåºåããïŒ</p>
</div>
<div>
<h1>å¶çŽ</h1>
<ul class="simple">
<li>å
¥åã®æååã®é·ã㯠10 以äžã§ããïŒ</li>
</ul>
</div>
<div>
<h1>å
¥åºåäŸ</h1>
<div>
<h2>å
¥åºåäŸ 1</h2>
<p>å
¥åäŸ 1:</p>
<pre class="literal-block">
(iwi)
</pre>
<p>å
¥åäŸ 1 ã«å¯ŸããåºåäŸ:</p>
<pre class="literal-block">
0
</pre>
<p>å
¥åäŸ 1 ã§ã¯æååãã¯ããããå·Šå³ã«ç·å¯Ÿç§°ã§ããïŒ</p>
</div>
<div>
<h2>å
¥åºåäŸ 2</h2>
<p>å
¥åäŸ 2:</p>
<pre class="literal-block">
ii(((((ww
</pre>
<p>å
¥åäŸ 2 ã«å¯ŸããåºåäŸ:</p>
<pre class="literal-block">
5
</pre>
<p>å
¥åäŸ 2 ã§ã¯äŸãã° ww((i))ww çã«å€æŽããã°ããïŒ</p>
</div>
</div>
</div> |
p00136 |
<H1>床æ°ååž</H1>
<p>
å¥åº·èšºæã§çåŸã®èº«é·ãèšæž¬ããŸããã身é·ã®ããŒã¿ãå
¥åãšãã床æ°ååžãäœæããŠåºåããããã°ã©ã ãäœæããŠãã ããã床æ°ååžã®éçŽã¯ 5 cm å»ã¿ã® 6 ã€ã®éçŽãšãã床æ°ã¯äººæ°ã *ïŒåè§ã¢ã¹ã¿ãªã¹ã¯ïŒã§è¡šç€ºããŸãããã ãããã®éçŽã®åºŠæ°ïŒäººæ°ïŒã 0 ã®å ŽåãéçŽã®èŠåºãã®ã¿ãåºåããŠãã ããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>h<sub>1</sub></var>
<var>h<sub>2</sub></var>
:
<var>h<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«çåŸã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 40)ã2 è¡ç®ä»¥éã« <var>i</var> 人ç®ã®èº«é·ã衚ã宿° <var>h<sub>i</sub></var> (150.0 ≤ <var>h<sub>i</sub></var> ≤ 190.0ãå°æ°ç¬¬ 1 äœãŸã§) ããããã 1 è¡ã«äžããããŸãã
</p>
<H2>Output</H2>
<p>
以äžã®åœ¢åŒã§åºŠæ°ååžã衚瀺ããŠãã ããã
</p>
<pre>
1 è¡ç® èŠåºãã1:ãã«ã€ã¥ã㊠165.0 cm æªæºã®äººæ°åã® *
2 è¡ç® èŠåºãã2:ãã«ã€ã¥ã㊠165.0 cm 以äžã 170.0 cmæªæºã®äººæ°åã® *
3 è¡ç® èŠåºãã3:ãã«ã€ã¥ã㊠170.0 cm 以äžã 175.0 cmæªæºã®äººæ°åã® *
4 è¡ç® èŠåºãã4:ãã«ã€ã¥ã㊠175.0 cm 以äžã 180.0 cmæªæºã®äººæ°åã® *
5 è¡ç® èŠåºãã5:ãã«ã€ã¥ã㊠180.0 cm 以äžã 185.0 cmæªæºã®äººæ°åã® *
6 è¡ç® èŠåºãã6:ãã«ã€ã¥ã㊠185.0 cm 以äžã®äººæ°åã® *
</pre>
<H2>Sample Input 1</H2>
<pre>
4
180.3
168.2
165.5
175.3
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
1:
2:**
3:
4:*
5:*
6:
</pre>
<H2>Sample Input 2</H2>
<pre>
21
179.4
171.5
156.6
173.0
169.4
181.2
172.4
170.0
163.6
165.9
173.5
168.2
162.5
172.0
175.1
172.3
167.5
175.9
186.2
168.0
178.6
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
1:***
2:*****
3:*******
4:****
5:*
6:*
</pre>
|
p00566 | <h1>å¹¹ç·éè·¯ (Trunk Road)</h1>
<h2>å顿</h2>
<p>
JOI åžã¯ïŒæ±è¥¿æ¹åã«ãŸã£ããã«äŒžã³ã <var>H</var> æ¬ã®éè·¯ãšïŒååæ¹åã«ãŸã£ããã«äŒžã³ã <var>W</var> æ¬ã®éè·¯ã«ãã£ãŠïŒç¢ç€ã®ç®ã®åœ¢ã«åºåããããŠããïŒéè·¯ãšéè·¯ã®éé㯠<var>1</var> ã§ããïŒJOI åžã§ã¯ïŒããã <var>H+W</var> æ¬ã®éè·¯ããïŒæ±è¥¿æ¹åã« <var>1</var> æ¬ïŒååæ¹åã« <var>1</var> æ¬ïŒåèš <var>2</var> æ¬ã®éè·¯ãå¹¹ç·éè·¯ãšããŠéžã¶ããšã«ãªã£ãïŒ</p>
<p>
åãã <var>i</var> æ¬ç® (<var>1âŠiâŠH</var>) ã®éè·¯ãšïŒè¥¿ãã <var>j</var> æ¬ç® (<var>1âŠjâŠW</var>) ã®éè·¯ã®äº€å·®ç¹ãïŒäº€å·®ç¹ <var>(i,j)</var> ãšããïŒäº€å·®ç¹ <var>(i,j)</var> ãšåãã <var>m</var> æ¬ç® (<var>1âŠmâŠH</var>) ã®éè·¯ã®è·é¢ã¯ <var>|i-m|</var> ã§ããïŒäº€å·®ç¹ <var>(i,j)</var> ãšè¥¿ãã <var>n</var> æ¬ç® (<var>1âŠnâŠW</var>) ã®éè·¯ã®è·é¢ã¯ <var>|j-n|</var> ã§ããïŒ
ãŸãïŒäº€å·®ç¹ <var>(i,j)</var> ã®è¿ãã«ã¯ <var>A_{i,j}</var> 人ã®äœäººãäœãã§ããïŒ</p>
<p>
<var>2</var> æ¬ã®å¹¹ç·éè·¯ãéžãã ãšãã®ïŒJOI åžã®å
šãŠã®äœäººã«å¯ŸããïŒæå¯ãã®äº€å·®ç¹ããè¿ãæ¹ã®å¹¹ç·éè·¯ãžã®è·é¢ã®ç·åã®æå°å€ãæ±ããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>2 ⊠H ⊠25</var></li>
<li><var>2 ⊠W ⊠25</var></li>
<li><var>0 ⊠A_{i,j} ⊠100</var> (<var>1 ⊠i ⊠H</var>, <var>1 ⊠j ⊠W</var>)</li>
</ul>
<h2>å
¥åã»åºå</h2>
<p>
<b>å
¥å</b><br>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ<br>
<var>H</var> <var>W</var><br>
<var>A_{1,1}</var> <var>A_{1,2}</var> ... <var>A_{1,W}</var><br>
:<br>
<var>A_{H,1}</var> <var>A_{H,2}</var> ... <var>A_{H,W}</var>
</p>
<p>
<b>åºå</b><br>
JOI åžã®å
šãŠã®äœäººã«å¯ŸããïŒæå¯ãã®äº€å·®ç¹ããè¿ãæ¹ã®å¹¹ç·éè·¯ãžã®è·é¢ã®ç·åã®æå°å€ãåºåããïŒ</p>
<!--
<h2>å°èª²é¡</h2>
<p>
<b>å°èª²é¡ 1 [10ç¹]</b>
</p>
<ul>
<li><var>A_{i,j} = 1</var> (<var>1 ⊠i ⊠H</var>, <var>1 ⊠j ⊠W</var>)</li>
</ul>
<p>
<b>å°èª²é¡ 2 [90ç¹]</b>
</p>
<ul>
<li>远å ã®å¶éã¯ãªãïŒ</li>
</ul>
-->
<h2>å
¥åºåäŸ</h2>
<b>å
¥åäŸ 1</b><br>
<pre>
3 5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
</pre>
<b>åºåäŸ 1</b><br>
<pre>
8
</pre>
<p>
äŸãã°ïŒåãã <var>2</var> æ¬ç®ã®éè·¯ãšè¥¿ãã <var>1</var> æ¬ç®ã®éè·¯ãå¹¹ç·éè·¯ãšããã°ããïŒ</p>
<hr>
<b>å
¥åäŸ 2</b><br>
<pre>
5 5
1 2 3 1 5
1 22 11 44 3
1 33 41 53 2
4 92 35 23 1
4 2 6 3 5
</pre>
<b>åºåäŸ 2</b><br>
<pre>
164
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2017/2018-yo/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 17 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2017/2018 äºéžç«¶æèª²é¡ã</a>
</p>
|
p00073 |
<H1>åè§ããã®è¡šé¢ç©</H1>
<p>
1 蟺ã <var>x</var> ã®æ£æ¹åœ¢ãåºé¢ãšãããé«ã <var>h</var> ã®åè§ããã®è¡šé¢ç© <var>S</var> ãåºåããããã°ã©ã ãäœæããŠäžããããã ããé ç¹ãšåºé¢ã®äžå¿ãçµã¶ç·åã¯åºé¢ãšçŽäº€ããŠãããšããŸãããŸãã <var>x</var>ã<var>h</var> 㯠100 以äžã®æ£ã®æŽæ°ãšããŸãã
</p>
<H3 class="bar">Input</H3>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>x</var>
<var>h</var>
</pre>
<p>
<var>x, h</var> ãå
±ã« 0 ã®ãšãå
¥åã®çµäºã瀺ããŸãã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ã<var>S</var>ïŒå®æ°ïŒãïŒè¡ã«åºåããŠäžãããåºåã¯0.00001以äžã®èª€å·®ãå«ãã§ãããã
</p>
<H2>Sample Input</H2>
<pre>
6
4
7
9
0
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
96.000000
184.192455
</pre>
|
p00589 |
<!--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>problem</title>
</head>
<body bgcolor="#FFFFFF">
<link rel="stylesheet" href="../problem_e.css" type="text/css" />
-->
<H1>Extraordinary Girl (II)</H1>
<p>
She loves e-mail so much! She sends e-mails by her cellular phone to
her friends when she has breakfast, she talks with other friends, and even
when she works in the library! Her cellular phone has somewhat simple
layout (Figure 1). Pushing button 1 once displays a character (â), pushing
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_1003">
</center>
<p>
it twice in series displays a character (,), and so on, and pushing it 6 times
displays (â) again. Button 2 corresponds to charaters (abcABC), and, for
example, pushing it four times displays (A). Button 3-9 have is similar to
button 1. Button 0 is a special button: pushing it once make her possible
to input characters in the same button in series. For example, she has to
push â20202â to display âaaaâ and â660666â to display ânoâ. In addition,
pushing button 0 n times in series (n > 1) displays n â 1 spaces. She never
pushes button 0 at the very beginning of her input. Here are some examples
of her input and output:
</p>
<pre>
666660666 --> No
44444416003334446633111 --> Iâm fine.
20202202000333003330333 --> aaba f ff
</pre>
<p>
One day, the chief librarian of the library got very angry with her and
hacked her cellular phone when she went to the second floor of the library
to return books in shelves. Now her cellular phone can only display button
numbers she pushes. Your task is to write a program to convert the sequence
of button numbers into correct characters and help her continue her e-mails!
</p>
<H2>Input</H2>
<p>
Input consists of several lines. Each line contains the sequence of button
numbers without any spaces. You may assume one line contains no more
than 10000 numbers. Input terminates with EOF.
</p>
<H2>Output</H2>
<p>
For each line of input, output the corresponding sequence of characters in
one line.
</p>
<H2>Sample Input</H2>
<pre>
666660666
44444416003334446633111
20202202000333003330333
</pre>
<H2>Output for the Sample Input</H2>
<pre>
No
I'm fine.
aaba f ff
</pre>
|
p00423 |
<H1><!-- Card Game--></H1>
<p>
A ãš B ã® 2 人ã®ãã¬ãŒã€ãŒãïŒ 0 ãã 9 ãŸã§ã®æ°åãæžãããã«ãŒãã䜿ã£ãŠã²ãŒã ãè¡ãïŒæåã«ïŒ 2 人ã¯äžãããã n æãã€ã®ã«ãŒããïŒè£åãã«ããŠæšªäžåã«äžŠã¹ãïŒãã®åŸïŒ 2 人ã¯åèªã®å·Šãã 1 æãã€ã«ãŒãã衚åãã«ããŠããïŒæžãããæ°åã倧ããæ¹ã®ã«ãŒãã®æã¡äž»ãïŒãã® 2 æã®ã«ãŒããåãïŒãã®ãšãïŒãã® 2 æã®ã«ãŒãã«æžãããæ°åã®åèšãïŒã«ãŒããåã£ããã¬ãŒã€ãŒã®åŸç¹ãšãªããã®ãšããïŒãã ãïŒéãã 2 æã®ã«ãŒãã«åãæ°åãæžãããŠãããšãã«ã¯ïŒåŒãåããšãïŒåãã¬ãŒã€ãŒãèªåã®ã«ãŒãã 1 æãã€åããã®ãšããïŒ
</p>
<p>
äŸãã°ïŒ AïŒB ã®æã¡æãïŒä»¥äžã®å
¥åäŸ 1 ãã 3 ã®ããã«äžŠã¹ãããŠããå ŽåãèãããïŒãã ãïŒå
¥åãã¡ã€ã«ã¯ n + 1 è¡ãããªãïŒ 1 è¡ç®ã«ã¯åãã¬ãŒã€ã®ã«ãŒãææ° n ãæžãããŠããïŒ i + 1 è¡ç®ïŒi = 1ïŒ2ïŒ... ïŒnïŒã«ã¯ A ã®å·Šãã i æç®ã®ã«ãŒãã®æ°åãš B ã®å·Šãã i æç®ã® ã«ãŒãã®æ°åãïŒç©ºçœãåºåãæåãšããŠãã®é ã§æžãããŠããïŒããªãã¡ïŒå
¥åãã¡ã€ã«ã® 2 è¡ç®ä»¥éã¯ïŒå·ŠåŽã®åã A ã®ã«ãŒãã®äžŠã³ãïŒå³åŽã®åã B ã®ã«ãŒãã®äžŠã³ãïŒãããã衚ããŠããïŒãã®ãšãïŒã²ãŒã çµäºåŸã® A ãš B ã®åŸç¹ã¯ïŒããããïŒå¯Ÿå¿ããåºåäŸã«ç€ºãããã®ãšãªãïŒ
</p>
<p>
ãå
¥åãã¡ã€ã«ã«å¯Ÿå¿ããã²ãŒã ãçµäºãããšãã® A ã®åŸç¹ãš B ã®åŸç¹ãïŒãã®é ã«ç©ºçœãåºåãæåãšã㊠1 è¡ã«åºåããããã°ã©ã ãäœæããªããïŒãã ãïŒ n ≤ 10000 ãšããïŒ
</p>
<!--
<p>
ã¢ããããŒãããåºåãã¡ã€ã«ã«ãããŠã¯ãåºåã®åŸïŒBã®åŸç¹ã®åŸïŒã«æ¹è¡ãå
¥ããããšã
</p>
-->
<table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;">
<tr>
<th width="150" align="left">å
¥åäŸïŒ</th>
<th width="150" align="left">å
¥åäŸïŒ</th>
<th width="150" align="left">å
¥åäŸïŒ</th>
</tr>
<tr><td>3</td><td>3</td><td>3</td></tr>
<tr><td>9 1</td><td>9 1</td><td>9 1</td></tr>
<tr><td>5 4</td><td>5 4</td><td>5 5</td></tr>
<tr><td>0 8</td><td>1 0</td><td>1 8</td></tr>
<tr>
<td>ã</td>
</tr>
<tr>
<th width="150" align="left">åºåäŸïŒ</th>
<th width="150" align="left">åºåäŸïŒ</th>
<th width="150" align="left">åºåäŸïŒ</th>
</tr>
<tr><td>19 8</td><td>20 0</td><td>15 14</td></tr>
</table>
<h3>å
¥å</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒn ã 0 ã®ãšãå
¥åãçµäºããïŒããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h3>åºå</h3>
<p>
ããŒã¿ã»ããããšã«ãA ã®åŸç¹ãš B ã®åŸç¹ãïŒè¡ã«åºåããïŒ
</p>
<h3>å
¥åäŸ</h3>
<pre>
3
9 1
5 4
0 8
3
9 1
5 4
1 0
3
9 1
5 5
1 8
0
</pre>
<h3>åºåäŸ</h3>
<pre>
19 8
20 0
15 14
</pre>
<p>
åããŒã¿ã»ããã®åºåã®åŸïŒBã®åŸç¹ã®åŸïŒã«æ¹è¡ãå
¥ããããšã
</p>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div> |
p00970 | <h2>Emergency Evacuation</h2>
<p>
The Japanese government plans to increase the number of inbound tourists to forty million in the year 2020, and sixty million in 2030. Not only increasing touristic appeal but also developing tourism infrastructure further is indispensable to accomplish such numbers.
</p>
<p>
One possible enhancement on transport is providing cars extremely long and/or wide, carrying many passengers at a time. Too large a car, however, may require too long to evacuate all passengers in an emergency. You are requested to help estimating the time required.
</p>
<p>
The car is assumed to have the following seat arrangement.
</p>
<ul>
<li> A center aisle goes straight through the car, directly connecting to the emergency exit door at the rear center of the car.</li>
<li> The rows of the same number of passenger seats are on both sides of the aisle.</li>
</ul>
<p>
A rough estimation requested is based on a simple step-wise model. All passengers are initially on a distinct seat, and they can make one of the following moves in each step.
</p>
<ul>
<li> Passengers on a seat can move to an adjacent seat toward the aisle. Passengers on a seat adjacent to the aisle can move sideways directly to the aisle.</li>
<li> Passengers on the aisle can move backward by one row of seats. If the passenger is in front of the emergency exit, that is, by the rear-most seat rows, he/she can get off the car.</li>
</ul>
<p>
The seat or the aisle position to move to must be empty; either no other passenger is there before the step, or the passenger there empties the seat by moving to another position in the same step. When two or more passengers satisfy the condition for the same position, only one of them can move, keeping the others wait in their original positions.
</p>
<p>
The leftmost figure of Figure C.1 depicts the seat arrangement of a small car given in Sample Input 1. The car have five rows of seats, two seats each on both sides of the aisle, totaling twenty. The initial positions of seven passengers on board are also shown.
</p>
<p>
The two other figures of Figure C.1 show possible positions of passengers after the first and the second steps. Passenger movements are indicated by fat arrows. Note that, two of the passengers in the front seat had to wait for a vacancy in the first step, and one in the second row had to wait in the next step.
</p>
<p>
Your task is to write a program that gives the smallest possible number of steps for all the passengers to get off the car, given the seat arrangement and passengers' initial positions.
</p>
<div style="text-align:center">
<img width="680" src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2018_emergencyEvacuation"><br/>
Figure C.1
</div>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$r$ $s$ $p$
$i_1$ $j_1$
...
$i_p$ $j_p$
</pre>
<p>
Here, $r$ is the number of passenger seat rows, $s$ is the number of seats on each side of the aisle, and $p$ is the number of passengers. They are integers satisfying $1 \leq r \leq 500$, $1 \leq s \leq 500$, and $1 \leq p \leq 2rs$.
</p>
<p>
The following $p$ lines give initial seat positions of the passengers. The $k$-th line with $i_k$ and $j_k$ means that the $k$-th passenger's seat is in the $i_k$-th seat row and it is the $j_k$-th seat on that row. Here, rows and seats are counted from front to rear and left to right, both starting from one. They satisfy $1 \leq i_k \leq r$ and $1 \leq j_k \leq 2s$. Passengers are on distinct seats, that is, $i_k \ne= i_l$ or $j_k \ne j_l$ holds if $k \ne l$.
</p>
<h3>Output</h3>
<p>
The output should be one line containing a single integer, the minimum number of steps required
for all the passengers to get off the car.
</p>
<h3>Sample Input 1</h3>
<pre>
5 2 7
1 1
1 2
1 3
2 3
2 4
4 4
5 2
</pre>
<h3>Sample Output 1</h3>
<pre>
9
</pre>
<h3>Sample Input 2</h3>
<pre>
500 500 16
1 1
1 2
1 999
1 1000
2 1
2 2
2 999
2 1000
3 1
3 2
3 999
3 1000
499 500
499 501
499 999
499 1000
</pre>
<h3>Sample Output 2</h3>
<pre>
1008
</pre>
|
p01662 |
<h2>G - èªç±ç ç©¶</h2>
<p>
ãã€ãã®æ¬¡éã¯å€äŒã¿ã®èªç±ç ç©¶ã§<em>æå€§ç¬ç«éååé¡</em>ã®ã¢ã«ãŽãªãºã ãèããŠããïŒ
æå€§ç¬ç«éååé¡ã§ã¯ïŒå
¥åãšããŠç¡åã°ã©ã <var>G=(V,E)</var> ãäžããããïŒ
<var>G</var> ã®åé ç¹ãçœãŸãã¯é»ã§å¡ãããŠããïŒã©ã®èŸºã®ç«¯ç¹ãå°ãªããšãäžæ¹ãçœãå¡ãããŠãããšãïŒé»ãé ç¹éåã®ããšã<em>ç¬ç«éå</em>ãšåŒã¶ïŒ
äŸãã°äžå³ã«ãããŠïŒå³ã®å·Šéšã®ãããªã°ã©ããäžããããæïŒå³ã®äžå€®éšã®ããã«è²ãå¡ããšé»ãé ç¹éåã¯ç¬ç«éåã«ãªã£ãŠãããïŒäžæ¹ã§å³ã®å³éšã®ããã«è²ãå¡ã£ãå Žåã¯é»ãé ç¹éåã¯ç¬ç«éåã«ãªã£ãŠããªãïŒ
åé¡ã®ç®çã¯ïŒèŠçŽ æ°ãæå€§ã§ãããããªç¬ç«éåãæ±ããããšã§ããïŒ
䟿å®äžïŒã°ã©ã <var>G</var> ã®æå€§ã®ç¬ç«éåã®å€§ããã <var>A(G)</var> ãšèšãïŒ
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_mofu_fig1">
</p>
<p>
æ®å¿µãªãããã®åé¡ã¯<a href="http://ja.wikipedia.org/wiki/NP%E5%9B%B0%E9%9B%A3">NPå°é£</a>ã§ããããšãç¥ãããŠããïŒå€é
åŒæéã§æé©å€ãæ±ããããšã¯å€åã§ãããã«ãªãïŒ
ããã§ïŒãã€ãã®æ¬¡éã¯çè«çã«ã¯ä¿èšŒããªãããªããšãªãããŸããããããªä¹±æã¢ã«ãŽãªãºã ãèæ¡ããïŒãã®ã¢ã«ãŽãªãºã ã¯æ¬¡ã®ãããªãã®ã§ããïŒ
</p>
<p>
ãæ¬¡éã®ã¢ã«ãŽãªãºã ã<var>N=|V|</var> ãã°ã©ãã®é ç¹æ°ãšããïŒ
æåïŒãã¹ãŠã®é ç¹ã¯çœã§å¡ãããŠããïŒ
ããŸïŒåé ç¹ã« <var>1,2,âŠ,N</var> ã®çªå·ãïŒã©ã®2ã€ã®é ç¹ãäºãã«ç°ãªãçªå·ãæã€ããã«å²ãåœãŠãïŒ
ãã®ãšãïŒ<var>N! = N \times (N-1) \times (N-2) \times ⊠\times 1</var> éãã®å²ãåœãŠæ¹ãååšãããïŒ
ãããã®äžããäžæ§ãªç¢ºçã§ç¡äœçºã«å²ãåœãŠããã®ãšããïŒ
åé ç¹ <var>v</var> ã«ã€ããŠïŒãã <var>v</var> ã«é£æ¥ãããã¹ãŠã®é ç¹ <var>w</var> ã«å¯Ÿã㊠<var>v</var> ã«å²ãåœãŠãããçªå·ã <var>w</var> ããå°ãããšã <var>v</var> ãé»ãå¡ããšããããšãããïŒ
(ãã <var>v</var> ã«é£æ¥ããé ç¹ãååšããªãå ŽåïŒã¢ã«ãŽãªãºã 㯠<var>v</var> ãé»ãå¡ããã®ãšããïŒ) ãããŠïŒé»ãå¡ãããé ç¹ãïŒåé¡ã®è§£ãšããŠåºåããïŒ
</p>
<p>
次éã®ã¢ã«ãŽãªãºã ã®åäœäŸãäžå³ã«ç€ºãïŒ
å³ã®å·Šéšã®ãããªã°ã©ããäžãããããšãïŒåé ç¹ã«çªå·ã(ç¡äœçºã«)å²ãåœãŠïŒããããæ¡ä»¶ãæºããé ç¹ãé»ãå¡ã£ãŠããïŒ
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_mofu_fig2">
</p>
<p>
å®çŸ©ããïŒãã®ã¢ã«ãŽãªãºã ã«ãã£ãŠé»ãå¡ãããé ç¹éåã¯ç¬ç«éåã«ãªã£ãŠããããšããããïŒ
ã¢ã«ãŽãªãºã ãäœãïŒãã£ããèªä¿¡ã«æºã¡ãæ§åã®æ¬¡éã§ãã£ããïŒãããæšªããèŠãŠãããã€ãã®ããããçªã£èŸŒã¿ãå
¥ããŠããïŒ
ãããªã¢ã«ãŽãªãºã ã§ã¯å
šç¶è¯ãè§£ã¯åºãªãïŒãšïŒ
çŽåŸããããšããªããã€ãã®æ¬¡éã«ããã«ïŒãããã¯èŽåœçãªã±ãŒã¹ãèŠããããšã«ããïŒ
</p>
<p>
<var>E(G)</var> ãæ¬¡éã®ã¢ã«ãŽãªãºã ãåºåããé»ãé ç¹éåã®å€§ããã®æåŸ
å€ãšããïŒ
<strong>é ç¹æ°ã40以äž</strong>ã®ç¡åã°ã©ãã§ïŒ<var>A(G)-E(G)</var> ãæå€§ã«ãªããããªãã®ã1ã€äœãïŒãããåºåããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ç¡ãïŒ
</p>
<h2>åºå圢åŒ</h2>
<p>é¡æãæºããã°ã©ããåºåããïŒ
ã°ã©ãã®åºå圢åŒã¯ä»¥äžã«åŸããã®ãšããïŒ
</p>
<pre>
<var>N</var>
<var>s_{11}</var><var>s_{12}</var><var>s_{13}</var>âŠ<var>s_{1n}</var>
<var>s_{21}</var><var>s_{22}</var><var>s_{23}</var>âŠ<var>s_{2n}</var>
<var>s_{31}</var><var>s_{32}</var><var>s_{33}</var>âŠ<var>s_{3n}</var>
<var>âŠ</var>
<var>s_{n1}</var><var>s_{n2}</var><var>s_{n3}</var>âŠ<var>s_{nn}</var>
</pre>
<p>
<var>n</var> ã¯ã°ã©ãã®é ç¹æ°ã§ããïŒ
<var>s_{ij}</var> ã¯ã°ã©ãã®æ¥ç¶é¢ä¿ã衚ãæåã§ããïŒ
é ç¹ <var>i</var> ãš <var>j</var> ã®éã«èŸºãç¡ããšã <var>s_{ij}=</var><code>N</code> ã§ããïŒ
é ç¹ <var>i</var> ãš <var>j</var> ã®éã«èŸºãæããšã <var>s_{ij}=</var><code>Y</code> ã§ãããã®ãšããïŒ
å¶çŽãšã°ã©ãã®æ§è³ªããïŒä»¥äžã®æ¡ä»¶ãæºãããªããã°ãªããªãïŒ
</p>
<ul>
<li><var>1 ≤ N ≤ 40</var></li>
<li><var>s_{ii} = </var><code>N</code></li>
<li><var>s_{ij} = s_{ji}</var></li>
</ul>
<!--
<h2>æ¡ç¹æ¹åŒ</h2>
<p>
ããåºåãããè§£ãæé©è§£ã§ããå ŽåïŒ500ç¹ãåŸãïŒ
æé©è§£ã§ã¯ãªãå ŽåïŒãã®åé¡ã®æé©è§£ã <var>OPT</var> ãšããŠïŒ<var>score = X \times (A(G) - E(G)) / OPT</var> ãšããïŒããã§ <var>X</var> ã¯40以äž50以äžã®åºå®ãããå€ã§ããïŒ
ãã <var>score ≥ 20</var> ãªãã°ïŒ<var>score</var> ç¹ãåŸãïŒ
<var>score < 20</var> ã®å ŽåïŒ0ç¹ãåŸãïŒ
</p>
-->
<h2>å
¥åºåäŸ</h2>
<p>
以äžã«å
¥åºåäŸã瀺ããïŒåé¡ã®æ§è³ªäžïŒæé©è§£ã®åºåãèšãããšã¯ã§ããªãã®ã§ïŒããã§ã¯åºå圢åŒãæºããæé©ã§ã¯ãªãè§£ã®äŸã瀺ãïŒ
</p>
<h3>å
¥åäŸ 1</h3>
<pre>
</pre>
<h3>åºåäŸ 1</h3>
<pre>
3
NYY
YNY
YYN
</pre>
<p>
ãã®åºå㯠3 é ç¹ã®å®å
šã°ã©ãã衚ãïŒãã®ã°ã©ãã§ã¯ <var>A(G) = E(G) = 1</var> ã§ããïŒèŽåœçãªã±ãŒã¹ã«ã¯çšé ãïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
</pre>
<h3>åºåäŸ 2</h3>
<pre>
3
NYN
YNY
NYN
</pre>
<p>
ãã®åºå㯠3 é ç¹ã®ãã¹ã°ã©ãã衚ãïŒãã®ã°ã©ãã§ã¯ <var>A(G) = 2</var>ïŒ<var>E(G) = (1+1+1+1+2+2)/6 = 4/3</var> ãªã®ã§ïŒ
<var>A(G) - E(G) = 2/3</var> ãšãªãïŒ
</p> |
p01398 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h2>
Problem A: ã¹ã¯ããæå·
</h2>
<p>
R倧åŠã®ãšãã2D奜ããªåœŒã¯ã人ã«èŠããããšèµ€é¢ãããããªæ¥ããããæç« ãæ¥é ããããæžããŠããã
ãã®ããã第äžè
ã«èªåã®æžããŠããæç« ãèŠãããªãããã«ã圌ãç¬èªã«èãåºããã¹ã¯ããæå·ãšããææ³ã«ããæç« ãæå·åããŠããã
ã¹ã¯ããæå·ã§ã¯ã次ã®ãããªã¹ãããã<i>N</i>åç¹°ãè¿ããæå·åãè¡ãã
</p>
<ol>
<li>
æååã®<i>a<sub>i</sub></i>çªç®ãš<i>b<sub>i</sub></i>çªç®ãå
¥ãæ¿ãã</li>
<li>
ãã®2ã€ã®æåãã<i>a<sub>i</sub></i>ãš<i>b<sub>i</sub></i>ã®å·®åã ãã¢ã«ãã¡ãããé ã«æ»ã</li>
</ol>
<p>
ãã ããã¢ã«ãã¡ãããé ã§ã'a'ã®åã¯'z'ãšããã
</p>
<p>
äŸãã°ã"aojwo"ãšããæååã«å¯Ÿãã<i>a<sub>1</sub></i>=1ã<i>b<sub>1</sub></i>=4ããšããæå·åæäœãè¡ã£ããšãããšã次ã®ããã«ãªãã
</p>
<ol>
<li>
1çªç®ãš4çªç®ãå
¥ãæ¿ãã("aojwo"â"wojao")</li>
<li>
ãã®2ã€ã®æå'w'ãš'a'ãã1ãš4ã®å·®åïŒ3ã ãã¢ã«ãã¡ãããé ã«æ»ã("wojao"â"tojxo")</li>
<ul>
<li>
'w'ã¯ãã¢ã«ãã¡ãããé ã«3æ»ããšã'w'â'v'â'u'â't'ãšãªã</li>
<li>
'a'ã¯ãã¢ã«ãã¡ãããé ã«3æ»ããšã'a'â'z'â'y'â'x'ãšãªã</li>
</ul>
</ol>
<p>
ãã£ãŠã"aojwo"ã¯ã"tojxo"ãšæå·åãããã
</p>
<p>
ãã®æå·åã«ããåœŒã®æç« ã¯ãåæãããããªãããã«æå·åã§ããã¯ãã ã£ãã®ã ãããããããšãåœŒã¯æå·åã«äœ¿çšããã¹ã¯ããæäœã®éçšãæµåºãããŠããŸã£ãã
ããªãã®ä»äºã¯ãæå·åãããæååãšæå·åã«äœ¿çšããã¹ã¯ããæäœãäžãããããšã"埩å·"ãè¡ãããã°ã©ã ãäœæãã2D奜ããªåœŒãã¯ãããããŠããããšã§ããã
</p>
<h2>
Input
</h2>
<p>
å
¥åã¯ãè€æ°ã®ããŒã¿ã»ãããããªããããŒã¿ã»ããã®ç·æ°ã¯20以äžã§ããã
åããŒã¿ã»ããã¯ã次ã®åœ¢åŒãããŠããã
</p>
<pre>
<i>N</i>
<i>message</i>
<i>a<sub>1</sub></i> <i>b<sub>1</sub></i>
...
<i>a<sub>i</sub></i> <i>b<sub>i</sub></i>
...
<i>a<sub>N</sub></i> <i>b<sub>N</sub></i>
</pre>
<p>
<i>N</i>(<i>0 < N ≤ 100</i>)ã¯ãæå·åãããšãã«ã¹ã¯ããæäœããåæ°ãç€ºãæŽæ°ã§ããã
<i>message</i>ã¯ãæå·åãããããŒã¿ã瀺ãã
æå·ããŒã¿ã¯ãã¢ã«ãã¡ãããã®å°æåã®ã¿ã§æ§æãããæååã§ããã
<i>message</i>ã®é·ãã<i>len</i>ãšãããšãã<i>2 ≤ </i><i>len</i><i> ≤ 100</i>ãšä»®å®ããŠããã
</p>
<p>
<i>a<sub>i</sub></i>ã<i>b<sub>i</sub></i>ã¯ãæå·åã«ãããŠã¹ã¯ãããè¡ã£ã2ã€ã®ã€ã³ããã¯ã¹ã衚ããŠããã
<i>1 ≤ a<sub>i</sub> < b<sub>i</sub> ≤</i> <i>len</i>ãšä»®å®ããŠããã
æå·åã¯ãå
¥åãããé çªã«ã¹ã¯ããæäœããããã®ãšããã
</p>
<p>
å
¥åã®çµäºã¯ã0ã®ã¿ãããªã1è¡ã§ç€ºãããããã®ããŒã¿ã«ã€ããŠã¯ãåŠçããå¿
èŠã¯ãªãã
</p>
<h2>
Output
</h2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠã埩å·ããæååã1è¡ã«åºåããã
</p>
<h2>
Sample Input
</h2>
<pre>
1
tojxo
1 4
5
uhcqmlmkv
4 5
6 9
3 6
1 7
3 6
5
shzxadexonr
8 9
3 9
5 8
4 9
10 11
0
</pre>
<h2>
Output for Sample Input
</h2>
<pre>
aojwo
shinryaku
shitadegeso
</pre>
|
p01232 |
<h1><font color="#000">Problem J:</font> ãã«ããã®æ°åŒ</h1>
<p>
ããªãã®å人ã®èå€åŠè
ãéºè·¡ãçºæããŠããïŒ
ããæ¥ïŒåœŒã¯æªãããªèšå·ã®çŸ
åãå»ãŸããŠããç³ç€ã倧éã«çºèŠããïŒ
圌ã¯ãã®å€§çºèŠã«å€§åã³ãïŒããããŸç³ç€ã«å»ãŸããŠããèšå·ã®è§£èªãå§ããïŒ
äœé±éã«ãããã圌ã®è§£èªã®åªåã®çµæïŒ
ã©ããããããã®ç³ç€ã«ã¯å€æ°ã»æŒç®åã»ã«ãã³ã®çµã¿åããã§æãç«ã£ãŠãã
æ°åŒã®ãããªãã®ãå»ãŸããŠããããšãããã£ãïŒ
çºæããç³ç€ãšéºè·¡ã«é¢ããæç®ã調ã¹ãŠãããã¡ã«åœŒã¯ããã«ïŒ
ããããã®ç³ç€ã§æŒç®åã®çµåèŠåãç°ãªã£ãŠããïŒ
ããããã®ç³ç€ã®å
é ã«æŒç®åã®çµåèŠåãèšãããŠãããããããšãçªããšããïŒ
ãããïŒåœŒã¯æ°åŠãèŠæã§ããããïŒæŒç®åã®çµåèŠåãèŠãŠã
ããã«ã¯æ°åŒãã©ã®ããã«çµåããŠããããããããªãã£ãïŒ
ããã§åœŒã¯ïŒåªããã³ã³ãã¥ãŒã¿ãµã€ãšã³ãã£ã¹ãã§ããããªãã«
ãç³ç€ã«æžãããŠããæ°åŒãã©ã®ããã«çµåããŠãããã調ã¹ãŠã»ããã
ãšäŸé ŒããŠããïŒ
ããªãã¯ïŒåœŒãæå©ãããããšãã§ããã ãããïŒ
</p>
<p>
æ°åŒäžã«çŸããæŒç®åã«ã¯åªå
é äœãå®ããããŠããïŒ
åªå
é äœã®é«ãæŒç®åããé ã«çµåããŠããïŒ
åäžåªå
é äœããã€æŒç®åã«ã¯ããããçµåæ¹åãå®ããããŠããïŒ
å·Šããå³ã«çµåããå Žåã¯å·Šã«ããæŒç®åããé ã«ïŒ
å³ããå·Šã«çµåããå Žåã¯å³ã«ããæŒç®åããé ã«çµåããŠããïŒ
äŸãã°ïŒ <code>+</code> ãã <code>*</code> ã®æ¹ãåªå
é äœãé«ãïŒ
<code>*</code> ãå·Šããå³ã«çµåããå ŽåïŒ
åŒ <code>a+b*c*d</code> 㯠<code>(a+((b*c)*d))</code> ã®ããã«çµåããïŒ
ãµã³ãã«å
¥åã«ãä»ã®äŸãããã€ãæããããŠããã®ã§åç
§ã®ããšïŒ
</p>
<h2>Input</h2>
<p>
å
¥åã«äžããããæ°åŒã¯ïŒä»¥äžã® <var>Expr</var>
ã§å®çŸ©ããããããªæååã§ããïŒ
ãã®å®çŸ©ã«ãããŠïŒ<var>Var</var> ã¯å€æ°ã衚ãïŒ
<var>Op</var> ã¯æŒç®åã衚ãïŒ
</p>
<table>
<tr>
<td><var>Expr</var></td>
<td>::=</td>
<td><var>Var</var></td>
</tr>
<tr>
<td></td>
<td class="bar-cell">|</td>
<td><var>Expr</var> <var>Op</var> <var>Expr</var></td>
</tr>
<tr>
<td></td>
<td class="bar-cell">|</td>
<td>
“<code>(</code>”
<var>Expr</var>
“<code>)</code>”
</td>
</tr>
<tr>
<td><var>Var</var></td>
<td>::=</td>
<td>
“<code>a</code>” |
“<code>b</code>” |
... |
“<code>z</code>”
</td>
</tr>
<tr>
<td><var>Op</var></td>
<td>::=</td>
<td>
“<code>+</code>” |
“<code>-</code>” |
“<code>*</code>” |
“<code>/</code>” |
“<code><</code>” |
“<code>></code>” |
“<code>=</code>” |
“<code>&</code>” |
“<code>|</code>” |
“<code>^</code>”
</td>
</tr>
</table>
<p>
æŒç®åã¯ãã¹ãŠäºé
æŒç®åã§ããïŒåé
æŒç®åããã®ä»ã®æŒç®åã¯ååšããªãïŒ
</p>
<p>
å
¥åã¯ïŒããã€ãã®ããŒã¿ã»ãããããªãïŒ
å
¥åã®å
é è¡ã«ããŒã¿ã»ããæ° <var>D</var> (<var>D</var> ≤ 100)
ãäžãããïŒ
以éã®è¡ã« <var>D</var> åã®ããŒã¿ã»ãããç¶ãïŒ
</p>
<p>
ããããã®ããŒã¿ã»ããã¯ïŒæ¬¡ã®ãããªãã©ãŒãããã§äžããããïŒ
</p>
<p>
ïŒæŒç®åã®çµåèŠåã®å®çŸ©ïŒ<br>
ïŒã¯ãšãªã®å®çŸ©ïŒ
</p>
<p>
æŒç®åã®çµåèŠåã®å®çŸ©ã¯ïŒä»¥äžã®ãããªãã©ãŒãããã§äžããããïŒãã®å®çŸ©ã«ãããŠïŒ<var>G</var> ã¯æŒç®åã°ã«ãŒãã®æ°ãè¡šãæ°ã§ããïŒ
</p>
<p>
<var>G</var><br>
ïŒæŒç®åã°ã«ãŒã1 ã®å®çŸ©ïŒ<br>
ïŒæŒç®åã°ã«ãŒã2 ã®å®çŸ©ïŒ<br>
...<br>
ïŒæŒç®åã°ã«ãŒã<var>G</var> ã®å®çŸ©ïŒ
</p>
<p>
æŒç®åã¯ïŒçµåã®åªå
é äœããšã«ã°ã«ãŒãã«åããããŠããïŒ
åäžã®ã°ã«ãŒãã«å±ããæŒç®åã¯çµåã®åªå
é äœãçããïŒ
ã°ã«ãŒãã®å®çŸ©ãåŸã«çŸããæŒç®åã®æ¹ã
åã«çŸããæŒç®åããçµåã®åªå
é äœãé«ãïŒ
</p>
<p>
ããããã®æŒç®åã°ã«ãŒãã¯ïŒä»¥äžã®ããã«å®çŸ©ãããïŒ
</p>
<p>
<var>A</var> <var>M</var> <var>p</var><sub>1</sub>
<var>p</var><sub>2</sub> ... <var>p</var><sub><var>M</var></sub>
</p>
<p>
<var>A</var> ã¯æŒç®åã®çµåæ¹åã衚ãæåã§ïŒ
“<code>L</code>” ã “<code>R</code>” ã®
ããããã§ããïŒ
“<code>L</code>” ã¯å·Šããå³ã«çµåããããšã衚ãïŒ
“<code>R</code>” ã¯å³ããå·Šã«çµåããããšã衚ãïŒ
<var>M</var> (<var>M</var> > 0)
ã¯æŒç®åã°ã«ãŒãã«å«ãŸããæŒç®åã®æ°ã§ããïŒ
<var>p</var><sub><var>i</var></sub> (1 ≤ <var>i</var> ≤ <var>M</var>)
ã¯ã°ã«ãŒãã«å«ãŸããæŒç®åã衚ãæåã§ããïŒ
åãæŒç®åãã°ã«ãŒãå
ã«2床çŸããããšã¯ãªãïŒãŸãïŒ
ããŒã¿ã»ããå
ã«ã°ã«ãŒãããŸããã£ãŠ
åãæŒç®åã2床çŸããããšããªãïŒ
</p>
<p>
æŒç®åã®å®çŸ©ã«ã¯ïŒäžèšã® <var>Op</var> ã§å®çŸ©ãããæŒç®åã®ã¿ãçŸããïŒ
1ã€ã®ããŒã¿ã»ããã«ãããŠïŒå¿
ã1ã€ä»¥äžã®æŒç®åãå®çŸ©ããããšä»®å®ããŠããïŒ
</p>
<p>
ã¯ãšãªã®å®çŸ©ã¯ä»¥äžã®ãããªãã©ãŒãããã§äžããããïŒ
</p>
<p>
<var>N</var><br>
<var>e</var><sub>1</sub><br>
<var>e</var><sub>2</sub><br>
...<br>
<var>e</var><sub><var>N</var></sub>
</p>
<p>
<var>N</var> (0 < <var>N</var> ≤ 50) ã¯ã¯ãšãªãšããŠäžãããã
æ°åŒã®æ°ã§ããïŒ
<var>e</var><sub><var>i</var></sub>
(1 ≤ <var>i</var> ≤ <var>N</var>)
ã¯äžèšã® <var>Expr</var> ã®å®çŸ©ãæºãããããª
åŒã衚ã空ã§ãªãæååã§ããïŒ
<var>e</var><sub><var>i</var></sub> ã®é·ãã¯ããã ã100æåã§ããïŒ
åœè©²ããŒã¿ã»ããã§å®çŸ©ãããŠããªãæŒç®åã¯åºçŸããªããã®ãšä»®å®ããŠããïŒ
</p>
<h2>Output</h2>
<p>
ããŒã¿ã»ããããšã«ïŒ
ã¯ãšãªãšããŠäžããããããããã®åŒã«ã€ããŠïŒ
åŒäžã®åæŒç®åã«ã€ããŠå¿
ã1ã€ã®ã«ãã³ã®çµãçšããŠ
ãã¹ãŠã®äºé
æŒç®ãæ£ããå²ã¿ïŒ
æŒç®åã®çµåã衚çŸããæååãåºåããïŒ
å
¥åã®åŒã«çŸãã倿°ãæŒç®åã®é åºã倿ŽããŠã¯ãªããªãïŒ
</p>
<p>
ããããã®ããŒã¿ã»ããã®éã«ã¯ç©ºè¡ãåºåããïŒ
åºåã®æ«å°Ÿã«ç©ºè¡ãåºåããŠã¯ãªããªãïŒ
</p>
<h2>Sample Input</h2>
<pre>
2
3
R 1 =
L 2 + -
L 2 * /
6
a+b*c-d
(p-q)/q/d
a+b*c=d-e
t+t+t+t+t
s=s=s=s=s
(((((z)))))
3
R 3 = < >
L 3 & | ^
L 4 + - * /
1
a>b*c=d<e|f+g^h&i<j>k
</pre>
<h2>Output for the Sample Input</h2>
<pre>
((a+(b*c))-d)
(((p-q)/q)/d)
((a+(b*c))=(d-e))
((((t+t)+t)+t)+t)
(s=(s=(s=(s=s))))
z
(a>((b*c)=(d<((((e|(f+g))^h)&i)<(j>k)))))
</pre>
|
p04030 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has <var>3</var> keys on it: the <code>0</code> key, the <code>1</code> key and the backspace key.</p>
<p>To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:</p>
<ul>
<li>The <code>0</code> key: a letter <code>0</code> will be inserted to the right of the string.</li>
<li>The <code>1</code> key: a letter <code>1</code> will be inserted to the right of the string.</li>
<li>The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.</li>
</ul>
<p>Sig has launched the editor, and pressed these keys several times. You are given a string <var>s</var>, which is a record of his keystrokes in order. In this string, the letter <code>0</code> stands for the <code>0</code> key, the letter <code>1</code> stands for the <code>1</code> key and the letter <code>B</code> stands for the backspace key. What string is displayed in the editor now?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠|s| ⊠10</var> (<var>|s|</var> denotes the length of <var>s</var>)</li>
<li><var>s</var> consists of the letters <code>0</code>, <code>1</code> and <code>B</code>.</li>
<li>The correct answer is not an empty string.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string displayed in the editor in the end.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>01B0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>00
</pre>
<p>Each time the key is pressed, the string in the editor will change as follows: <code>0</code>, <code>01</code>, <code>0</code>, <code>00</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0BB1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>Each time the key is pressed, the string in the editor will change as follows: <code>0</code>, <code>(empty)</code>, <code>(empty)</code>, <code>1</code>.</p></section>
</div>
</span> |
p02737 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are simple undirected graphs <var>X</var>, <var>Y</var>, <var>Z</var>, with <var>N</var> vertices each and <var>M_1</var>, <var>M_2</var>, <var>M_3</var> edges, respectively.
The vertices in <var>X</var>, <var>Y</var>, <var>Z</var> are respectively called <var>x_1, x_2, \dots, x_N</var>, <var>y_1, y_2, \dots, y_N</var>, <var>z_1, z_2, \dots, z_N</var>.
The edges in <var>X</var>, <var>Y</var>, <var>Z</var> are respectively <var>(x_{a_i}, x_{b_i})</var>, <var>(y_{c_i}, y_{d_i})</var>, <var>(z_{e_i}, z_{f_i})</var>.</p>
<p>Based on <var>X</var>, <var>Y</var>, <var>Z</var>, we will build another undirected graph <var>W</var> with <var>N^3</var> vertices.
There are <var>N^3</var> ways to choose a vertex from each of the graphs <var>X</var>, <var>Y</var>, <var>Z</var>. Each of these choices corresponds to the vertices in <var>W</var> one-to-one. Let <var>(x_i, y_j, z_k)</var> denote the vertex in <var>W</var> corresponding to the choice of <var>x_i, y_j, z_k</var>.</p>
<p>We will span edges in <var>W</var> as follows:</p>
<ul>
<li>For each edge <var>(x_u, x_v)</var> in <var>X</var> and each <var>w, l</var>, span an edge between <var>(x_u, y_w, z_l)</var> and <var>(x_v, y_w, z_l)</var>.</li>
<li>For each edge <var>(y_u, y_v)</var> in <var>Y</var> and each <var>w, l</var>, span an edge between <var>(x_w, y_u, z_l)</var> and <var>(x_w, y_v, z_l)</var>.</li>
<li>For each edge <var>(z_u, z_v)</var> in <var>Z</var> and each <var>w, l</var>, span an edge between <var>(x_w, y_l, z_u)</var> and <var>(x_w, y_l, z_v)</var>.</li>
</ul>
<p>Then, let the weight of the vertex <var>(x_i, y_j, z_k)</var> in <var>W</var> be <var>1,000,000,000,000,000,000^{(i +j + k)} = 10^{18(i + j + k)}</var>. Find the maximum possible total weight of the vertices in an <a href="https://en.wikipedia.org/wiki/Independent_set_(graph_theory)">independent set</a> in <var>W</var>, and print that total weight modulo <var>998,244,353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100,000</var></li>
<li><var>1 \leq M_1, M_2, M_3 \leq 100,000</var></li>
<li><var>1 \leq a_i, b_i, c_i, d_i, e_i, f_i \leq N</var></li>
<li><var>X</var>, <var>Y</var>, and <var>Z</var> are simple, that is, they have no self-loops and no multiple edges.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>M_1</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>\vdots</var>
<var>a_{M_1}</var> <var>b_{M_1}</var>
<var>M_2</var>
<var>c_1</var> <var>d_1</var>
<var>c_2</var> <var>d_2</var>
<var>\vdots</var>
<var>c_{M_2}</var> <var>d_{M_2}</var>
<var>M_3</var>
<var>e_1</var> <var>f_1</var>
<var>e_2</var> <var>f_2</var>
<var>\vdots</var>
<var>e_{M_3}</var> <var>f_{M_3}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible total weight of an independent set in <var>W</var>, modulo <var>998,244,353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1
1 2
1
1 2
1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>46494701
</pre>
<p>The maximum possible total weight of an independent set is that of the set <var>(x_2, y_1, z_1)</var>, <var>(x_1, y_2, z_1)</var>, <var>(x_1, y_1, z_2)</var>, <var>(x_2, y_2, z_2)</var>. The output should be <var>(3 \times 10^{72} + 10^{108})</var> modulo <var>998,244,353</var>, which is <var>46,494,701</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
3
1 3
1 2
3 2
2
2 1
2 3
1
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>883188316
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000
1
1 2
1
99999 100000
1
1 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>318525248
</pre></section>
</div>
</span> |
p01818 |
<h2>Leapfrog</h2>
<h3>Problem Statement</h3>
<p><var>N</var> åã®ãã¹ãåç¶ã«äžŠãã§ããããã¹ã¯æèšåãã« <var>1,\ 2,\ </var> ... <var>,\ N</var> ãšçªå·ãæ¯ãããŠãããå <var>i</var> (<var>1 ≤ i ≤ N−1</var>) ã«ã€ããŠã<var>i</var> çªç®ã®ãã¹ãš <var>i+1</var> çªç®ã®ãã¹ã¯é£ãåãããŸãã<var>N</var> çªç®ã®ãã¹ãš <var>1</var> çªç®ã®ãã¹ã¯é£ãåãã</p>
<p>ãããã®ãã¡ <var>M</var> åã®ãã¹ã«ã¯ãäºãã«åºå¥ã§ããªãé§ã <var>1</var> åãã€çœ®ãããŠãããã¯ããã<var>x_1,\ x_2,\ </var> ... <var>,\ x_M</var> çªç®ã®ãã¹ã«é§ã眮ãããŠãããæ¬¡ã®æäœãäœåãè¡ãã<var>y_1,\ y_2,\ </var> ... <var>,\ y_M</var> çªç®ã®ãã¹ã«é§ã眮ãããŠããããã«ãããã</p>
<ul><li>æèšåããŸãã¯åæèšåãã«é£ç¶ãã <var>3</var> åã®ãã¹ãéžã³ãé ã« <var>A,\ B,\ C</var> ãšããã<var>A</var> ãš <var>B</var> ã«ããããé§ããã <var>C</var> ã«é§ããªããªãã°ã<var>A</var> ã®é§ã <var>C</var> ãžç§»åããã</li></ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_leapfrog">
</center>
<p><var>y_1,\ y_2,\ </var> ... <var>,\ y_M</var> çªç®ã®ãã¹ã«é§ã眮ãããŠããããã«ã§ãããå€å®ãããã§ãããªãã°ãå¿
èŠãªæäœã®åæ°ã®æå°å€ãæ±ããã</p>
<h3>Constraints</h3>
<ul>
<li><var>3 ≤ N ≤ 3,000</var></li>
<li><var>1 ≤ M ≤ N</var></li>
<li><var>1 ≤ x_1<x_2<</var> ... <var><x_M ≤ N</var></li>
<li><var>1 ≤ y_1<y_2<</var> ... <var><y_M ≤ N</var></li>
</ul>
<h3>Input Format</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
<var>N</var> <var>M</var>
<var>x_1</var> <var>x_2</var> ... <var>x_M</var>
<var>y_1</var> <var>y_2</var> ... <var>y_M</var>
</pre>
<h3>Output Format</h3>
<p><var>y_1,\ y_2,\ </var> ... <var>,\ y_M</var> çªç®ã®ãã¹ã«é§ã眮ãããŠããããã«ã§ãããªãã°ãå¿
èŠãªæäœã®åæ°ã®æå°å€ãäžè¡ã«åºåãããã§ããªããªãã°ã代ããã« <code>-1</code> ãäžè¡ã«åºåããã</p>
<h3>Sample Input 1</h3>
<pre>
7 2
1 2
5 6
</pre>
<h3>Sample Output 1</h3>
<pre>
3
</pre>
<p>次ã®ããã« <var>3</var> åã®æäœãè¡ãã°ããã</p>
<ul>
<li><var>2</var> çªç®ã®ãã¹ã®é§ã <var>7</var> çªç®ã®ãã¹ãžç§»åããã</li>
<li><var>1</var> çªç®ã®ãã¹ã®é§ã <var>6</var> çªç®ã®ãã¹ãžç§»åããã</li>
<li><var>7</var> çªç®ã®ãã¹ã®é§ã <var>5</var> çªç®ã®ãã¹ãžç§»åããã</li>
</ul>
<h3>Sample Input 2</h3>
<pre>
3 1
1
2
</pre>
<h3>Sample Output 2</h3>
<pre>
-1
</pre>
<h3>Sample Input 3</h3>
<pre>
2999 3
1 2 3
2 3 4
</pre>
<h3>Sample Output 3</h3>
<pre>
4491004
</pre> |
p03825 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> zeros and <var>M</var> ones written on a blackboard.
Starting from this state, we will repeat the following operation: select <var>K</var> of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those <var>K</var> numbers.
Here, assume that <var>N + M - 1</var> is divisible by <var>K - 1</var>.</p>
<p>Then, if we repeat this operation until it is no longer applicable, there will be eventually one rational number left on the blackboard.</p>
<p>Find the number of the different possible values taken by this rational number, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠N, M ⊠2000</var></li>
<li><var>2 ⊠K ⊠2000</var></li>
<li><var>N + M - 1</var> is divisible by <var>K - 1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different possible values taken by the rational number that will be eventually left on the blackboard, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five possible values for the number that will be eventually left on the blackboard: <var>\frac{1}{4}</var>, <var>\frac{3}{8}</var>, <var>\frac{1}{2}</var>, <var>\frac{5}{8}</var> and <var>\frac{3}{4}</var>.</p>
<p>For example, <var>\frac{3}{8}</var> can be eventually left if we:</p>
<ul>
<li>Erase <var>0</var> and <var>1</var>, then write <var>\frac{1}{2}</var>.</li>
<li>Erase <var>\frac{1}{2}</var> and <var>1</var>, then write <var>\frac{3}{4}</var>.</li>
<li>Erase <var>0</var> and <var>\frac{3}{4}</var>, then write <var>\frac{3}{8}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>150 150 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>937426930
</pre></section>
</div>
</span> |
p02367 |
<H1>Bridges</H1>
<p>
Find bridges of an undirected graph <var>G(V, E)</var>.
</p>
<p>
A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components.
</p>
<H2>Input</H2>
<pre>
<var>|V|</var> <var>|E|</var>
<var>s<sub>0</sub></var> <var>t<sub>0</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var>
:
<var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var>
</pre>
<p>
, where <var>|V|</var> is the number of nodes and <var>|E|</var> is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively.
</p>
<p>
<var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target nodes of <var>i</var>-th edge (undirected).
</p>
<H2>Output</H2>
<p>
A list of <i>bridges</i> of the graph ordered by name. For each bridge, names of its end-ponints, source and target (source < target), should be printed separated by a space. The sources should be printed ascending order, then the target should also be printed ascending order for the same source.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <var>|V|</var> ≤ 100,000</li>
<li>0 ≤ <var>|E|</var> ≤ 100,000</li>
<li>The graph is connected</li>
<li>There are no parallel edges</li>
<li>There are no self-loops</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 4
0 1
0 2
1 2
2 3
</pre>
<H2>Sample Output 1</H2>
<pre>
2 3
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
5 4
0 1
1 2
2 3
3 4
</pre>
<H2>Sample Output 2</H2>
<pre>
0 1
1 2
2 3
3 4
</pre> |
p03126 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Katsusando loves omelette rice.</p>
<p>Besides, he loves crÚme brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.</p>
<p>To prove that hypothesis, he conducted a survey on <var>M</var> kinds of foods and asked <var>N</var> people whether they like these foods or not.</p>
<p>The <var>i</var>-th person answered that he/she only likes the <var>A_{i1}</var>-th, <var>A_{i2}</var>-th, <var>...</var>, <var>A_{iK_i}</var>-th food.</p>
<p>Find the number of the foods liked by all the <var>N</var> people.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N, M \leq 30</var></li>
<li><var>1 \leq K_i \leq M</var></li>
<li><var>1 \leq A_{ij} \leq M</var></li>
<li>For each <var>i</var> <var>(1 \leq i \leq N)</var>, <var>A_{i1}, A_{i2}, ..., A_{iK_i}</var> are distinct.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>K_1</var> <var>A_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1K_1}</var>
<var>K_2</var> <var>A_{21}</var> <var>A_{22}</var> <var>...</var> <var>A_{2K_2}</var>
<var>:</var>
<var>K_N</var> <var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NK_N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the foods liked by all the <var>N</var> people.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
2 1 3
3 1 2 3
2 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>As only the third food is liked by all the three people, <var>1</var> should be printed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Katsusando's hypothesis turned out to be wrong.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 30
3 5 10 30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p03576 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> points in a two-dimensional plane.<br/>
The coordinates of the <var>i</var>-th point <var>(1 \leq i \leq N)</var> are <var>(x_i,y_i)</var>.<br/>
Let us consider a rectangle whose sides are parallel to the coordinate axes that contains <var>K</var> or more of the <var>N</var> points in its interior.<br/>
Here, points on the sides of the rectangle are considered to be in the interior.<br/>
Find the minimum possible area of such a rectangle. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K \leq N \leq 50</var> </li>
<li><var>-10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)</var> </li>
<li><var>x_iâ x_j (1 \leq i<j \leq N)</var> </li>
<li><var>y_iâ y_j (1 \leq i<j \leq N)</var> </li>
<li>All input values are integers. (Added at 21:50 JST) </li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var> <var>K</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_{N}</var> <var>y_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible area of a rectangle that satisfies the condition. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
1 4
3 3
6 2
8 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>21
</pre>
<p>One rectangle that satisfies the condition with the minimum possible area has the following vertices: <var>(1,1)</var>, <var>(8,1)</var>, <var>(1,4)</var> and <var>(8,4)</var>.<br/>
Its area is <var>(8-1) Ã (4-1) = 21</var>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2
0 0
1 1
2 2
3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3999999996000000001
</pre>
<p>Watch out for integer overflows. </p></section>
</div>
</span> |
p03599 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.</p>
<ul>
<li>Operation 1: Pour <var>100A</var> grams of water into the beaker.</li>
<li>Operation 2: Pour <var>100B</var> grams of water into the beaker.</li>
<li>Operation 3: Put <var>C</var> grams of sugar into the beaker.</li>
<li>Operation 4: Put <var>D</var> grams of sugar into the beaker.</li>
</ul>
<p>In our experimental environment, <var>E</var> grams of sugar can dissolve into <var>100</var> grams of water.</p>
<p>Snuke will make sugar water with the highest possible density.</p>
<p>The beaker can contain at most <var>F</var> grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.</p>
<p>We remind you that the sugar water that contains <var>a</var> grams of water and <var>b</var> grams of sugar is <var>\frac{100b}{a + b}</var> percent.
Also, in this problem, pure water that does not contain any sugar is regarded as <var>0</var> percent density sugar water.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A < B \leq 30</var></li>
<li><var>1 \leq C < D \leq 30</var></li>
<li><var>1 \leq E \leq 100</var></li>
<li><var>100A \leq F \leq 3</var> <var>000</var></li>
<li><var>A</var>, <var>B</var>, <var>C</var>, <var>D</var>, <var>E</var> and <var>F</var> are all integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 10 20 15 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>110 10
</pre>
<p>In this environment, <var>15</var> grams of sugar can dissolve into <var>100</var> grams of water, and the beaker can contain at most <var>200</var> grams of substances.</p>
<p>We can make <var>110</var> grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:</p>
<ul>
<li>If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.</li>
<li>If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed <var>200</var> grams.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 1 2 100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>200 100
</pre>
<p>There are other acceptable outputs, such as:</p>
<pre>400 200
</pre>
<p>However, the output below is not acceptable:</p>
<pre>300 150
</pre>
<p>This is because, in order to make <var>300</var> grams of sugar water containing <var>150</var> grams of sugar, we need to pour exactly <var>150</var> grams of water into the beaker, which is impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>17 19 22 26 55 2802
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2634 934
</pre></section>
</div>
</span> |
p03063 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. Every stone is painted white or black.
A string <var>S</var> represents the color of the stones. The <var>i</var>-th stone from the left is white if the <var>i</var>-th character of <var>S</var> is <code>.</code>, and the stone is black if the character is <code>#</code>.</p>
<p>Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2\times 10^5</var></li>
<li><var>S</var> is a string of length <var>N</var> consisting of <code>.</code> and <code>#</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of stones that needs to be recolored.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
#.#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>It is enough to change the color of the first stone to white.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
#.##.
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9
.........
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03433 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>E869120 has <var>A</var> <var>1</var>-yen coins and infinitely many <var>500</var>-yen coins.<br/>
Determine if he can pay exactly <var>N</var> yen using only these coins.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is an integer between <var>1</var> and <var>10000</var> (inclusive).</li>
<li><var>A</var> is an integer between <var>0</var> and <var>1000</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If E869120 can pay exactly <var>N</var> yen using only his <var>1</var>-yen and <var>500</var>-yen coins, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2018
218
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>We can pay <var>2018</var> yen with four <var>500</var>-yen coins and <var>18</var> <var>1</var>-yen coins, so the answer is <code>Yes</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2763
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>When we have no <var>1</var>-yen coins, we can only pay a multiple of <var>500</var> yen using only <var>500</var>-yen coins. Since <var>2763</var> is not a multiple of <var>500</var>, we cannot pay this amount.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>37
514
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p02388 |
<H1>X Cubic</H1>
<p>
Write a program which calculates the cube of a given integer <var>x</var>.
</p>
<H2>Input</H2>
<p>
An integer <var>x</var> is given in a line.
</p>
<H2>Output</H2>
<p>
Print the cube of <var>x</var> in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>x</var> ≤ 100</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
2
</pre>
<H2>Sample Output 1</H2>
<pre>
8
</pre>
<H2>Sample Input 2</H2>
<pre>
3
</pre>
<H2>Sample Output 2</H2>
<pre>
27
</pre> |
p02672 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><strong>This is an interactive task.</strong></p>
<p>You have to guess a secret password <var>S</var>.
A password is a nonempty string whose length is at most <var>L</var>.
The characters of a password can be lowercase and uppercase english letters (a, b, ... , z, A, B, ... , Z) and digits (0, 1, ... , 9).</p>
<p>In order to guess the secret password <var>S</var> you can ask queries.
A query is made of a valid password <var>T</var>, the answer to such query is the edit distance between <var>S</var> and <var>T</var> (the operations considered for the edit distance are: removal, insertion, substitution).
You can ask at most <var>Q</var> queries.</p>
<p><strong>Note</strong>: For a definition of edit distance (with operations: removal, insertion, substitution), see <a href="https://en.wikipedia.org/w/index.php?title=Levenshtein_distance&oldid=954598393">this wikipedia page</a>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>L = 128</var></li>
<li><var>Q = 850</var></li>
<li>The secret password <var>S</var> is chosen before the beginning of the interaction.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Interaction</h3><p>To ask a query, print on Standard Output (with a newline at the end)</p>
<pre>? <var>T</var>
</pre>
<p>The string <var>T</var> must be a valid password.</p>
<p>The answer <var>ans</var> to each query shall be read from Standard Input in the form:</p>
<pre><var>ans</var>
</pre>
<p>As soon as you have determined the hidden password <var>S</var>, you should print on Standard Output (with a newline at the end)</p>
<pre>! <var>S</var>
</pre>
<p>and terminate your program.</p>
</section>
</div>
<div class="part">
<section>
<h3>Judgement</h3><ul>
<li><font color="red"><strong>After each output, you must flush Standard Output.</strong></font> Otherwise you may get <code>TLE</code>.</li>
<li>After you print (your guess of) the hidden password, the program must be terminated immediately. Otherwise, the behavior of the judge is undefined.</li>
<li>If the password you have determined is wrong, you will get <code>WA</code>.</li>
<li>If you ask a malformed query (for example because the string is not a valid password, or you forget to put <code>?</code>) or if your program crashes or if you ask more than <var>Q</var> queries, the behavior of the judge is undefined (it does not necessarily give <code>WA</code>).</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Samples</h3><p>In the only sample testcase of this problem the hidden password is <code>Atcod3rIsGreat</code>.</p>
<p>The following one is an example of interaction if <var>S=</var><code>Atcod3rIsGreat</code>.</p>
<table class="table table-bordered">
<thead>
<tr>
<th align="left">Input</th>
<th align="left">Output</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"></td>
<td align="left"><var>\texttt{? AtcoderIsBad}</var></td>
</tr>
<tr>
<td align="left"><var>5</var></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left"><var>\texttt{? AtcoderIsGreat}</var></td>
</tr>
<tr>
<td align="left"><var>1</var></td>
<td align="left"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left"><var>\texttt{! Atcod3rIsGreat}</var></td>
</tr>
</tbody>
</table></section>
</div>
</span> |
p03960 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Mr. Takahashi has in his room an art object with <var>H</var> rows and <var>W</var> columns, made up of <var>H \times W</var> blocks.
Each block has a color represented by a lowercase English letter (<code>a</code>-<code>z</code>).
The color of the block at the <var>i</var>-th row and <var>j</var>-th column is <var>c_{i,j}</var>. </p>
<p>Mr. Takahashi would like to dismantle the object, finding it a bit kitschy for his tastes.
The dismantling is processed by repeating the following operation: </p>
<ul>
<li>Choose one of the <var>W</var> columns and push down that column one row.
The block at the bottom of that column disappears.</li>
</ul>
<p>Each time the operation is performed, a cost is incurred.
Since blocks of the same color have a property to draw each other together, the cost of the operation is the number of the pairs of blocks <var>(p, q)</var> such that:</p>
<ul>
<li>The block <var>p</var> is in the selected column.</li>
<li>The two blocks <var>p</var> and <var>q</var> are horizontally adjacent (before pushing down the column).</li>
<li>The two blocks <var>p</var> and <var>q</var> have the same color.</li>
</ul>
<p>Mr. Takahashi dismantles the object by repeating the operation <var>H \times W</var> times to get rid of all the blocks.
Compute the minimum total cost to dismantle the object.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †H †300</var></li>
<li><var>2 †W †300</var></li>
<li>All characters <var>c_{i,j}</var> are lowercase English letters (<code>a</code>-<code>z</code>).</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In test cases worth <var>300</var> points, <var>W = 3</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>c_{1,1}c_{1,2}</var>..<var>c_{1,W}</var>
<var>c_{2,1}c_{2,2}</var>..<var>c_{2,W}</var>
<var>:</var>
<var>c_{H,1}c_{H,2}</var>..<var>c_{H,W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total cost to dismantle the object.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
rrr
brg
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, the total cost of <var>2</var> can be achieved by performing the operation as follows and this is the minimum value.</p>
<div style="text-align: center;">
<img alt="ccb25ed6f1df9367829b68523e1deff4.png" src="https://atcoder.jp/img/code-festival-2016-qualc/ccb25ed6f1df9367829b68523e1deff4.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 3
xya
xya
ayz
ayz
xaz
xaz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The total cost of <var>0</var> can be achieved by first pushing down all blocks of the middle column, then all of the left column, and all of the right column.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2
ay
xa
xy
ay
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>The total cost of <var>0</var> can be achieved by the following operations:</p>
<ul>
<li>pushing down the right column one row;</li>
<li>pushing down the left column one row;</li>
<li>pushing down all of the right column;</li>
<li>and pushing down all of the left column.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 5
aaaaa
abbba
ababa
abbba
aaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>24
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>7 10
xxxxxxxxxx
ccccxxffff
cxxcxxfxxx
cxxxxxffff
cxxcxxfxxx
ccccxxfxxx
xxxxxxxxxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>130
</pre></section>
</div>
</span> |
p02222 | <span class="lang">
<span class="lang-ja">
<h1>L: æšã®åœ©è²</h1>
<div class="part">
<section>
<h3>å顿</h3><p>ã¢ãã¥ãŒãããã¯æšã®çµµãæãã®ããšãŠãããŸãã§ãã</p>
<p>ã¢ãã¥ãŒãããã¯é·ã幎æããããŠé ç¹ã $N$ åã§ããæšã®çµµãæžããŸããã
ãã®æšã®é ç¹ã«ã¯ $1$ ãã $N$ ãŸã§ã®çªå·ãã€ããŠãããé ç¹ $a_i$ ãš $b_i$ $(1 \leq i \leq N-1)$ ã¯çŽæ¥èŸºã§ã€ãªãããŠããŸãã
ãã¹ãŠã®é ç¹ã«ã¯è²ããŸã å¡ãããŠããŸããã</p>
<p>ã¢ãã¥ãŒããããæžãããã®æšã®çµµã¯ããããã®äººãæåãããæåãªçŸè¡é€šã«é£Ÿãããããšã決ãŸããŸããã</p>
<p>ãã®çŸè¡é€šã«ã¯é ã« $N$ 人ã®äººãæ¥å ŽããŸããã¢ãã¥ãŒãããã¯æ¥å Žè
ç¹å
žãšããŠãããããã®äººã« $1$ æãã€æšã®çµµã®ã³ããŒãé
åžããããšã«ããŸããã</p>
<p>ããã«ãæ¥å Žè
ã«æºè¶³ããŠããããããé
åžããæšã®çµµã®é ç¹ãã¹ãŠã«è²ãå¡ãããšã«ããŸããã
$k$ çªç® $(1 \leq k \leq N)$ ã«æ¥å Žãã人ã¯ã以äžã® 2 æ¡ä»¶ãå
±ã«æºããçµµãé
åžããããšãã«ã®ã¿æºè¶³ããŸãã</p>
<ul>
<li>æçè·é¢ã $k$ ã®åæ°ã§ããä»»æã® 2 é ç¹ã¯ãåãè²ã§å¡ãããŠããã </li>
<li>æçè·é¢ã $k$ ã®åæ°ã§ãªãä»»æã® 2 é ç¹ã¯ãç°ãªãè²ã§å¡ãããŠããã </li>
</ul>
<p>ã¢ãã¥ãŒããããæã£ãŠããè²ã®æ°ã¯ç¡éã«ãããŸãããŸããããããã®ã³ããŒã§è²ã®å¡ãæ¹ãéã£ãŠãæ§ããŸããã</p>
<p>ããããã®æ¥å Žè
ã«å¯Ÿãããã®æ¥å Žè
ãæºè¶³ãããããã«é ç¹ãå¡ãããšãã§ãããã©ããå€å®ããŠãã ããã</p>
</section>
</div>
<div class="part">
<section>
<h3>å¶çŽ</h3><ul>
<li>$1 \leq N \leq 10^5$</li>
<li>$1 \leq a_i, b_i \leq N$</li>
<li>å
¥åã¯ãã¹ãп޿°ã§ãã</li>
<li>å
¥åã«ãã£ãŠäžããããã°ã©ããæšã§ããããšã¯ä¿èšŒãããã</li>
</ul>
</section>
</div>
<hr />
<div class="io-style">
<div class="part">
<section>
<h3>å
¥å</h3><p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>$N$
$a_1$ $b_1$
$a_2$ $b_2$
$\vdots$
$a_{N-1}$ $b_{N-1}$
</pre>
<ul>
<li>$1$ è¡ç®ã«ã¯ãæšã®é ç¹æ°ãè¡šãæŽæ° $N$ ãäžããããã</li>
<li>$2$ è¡ç®ãã $N$ è¡ç®ã«ã¯ãæšã®èŸºã®æ
å ±ãäžããããããã®ãã¡ $i+1(1 \leq i \leq N-1)$ è¡ç®ã«ã¯ãé ç¹ $a_i$ ãš $b_i$ ã蟺ã§ã€ãªãã£ãŠããããšã瀺ã 2 ã€ã®æŽæ° $a_i,b_i$ ãäžããããã</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>åºå</h3><p>以äžãæºãã <code>0</code> ãŸã㯠<code>1</code> ãããªãæåå $S = s_1 s_2 \ldots s_N$ ãåºåããã</p>
<ul>
<li>$s_k = 1$ : $k$ çªç®ã®æ¥å Žè
ãæºè¶³ã§ããããäžããããæšã®çµµã®é ç¹ã«åœ©è²ã§ãã</li>
<li>$s_k = 0$ : $k$ çªç®ã®æ¥å Žè
ãæºè¶³ã§ããããäžããããæšã®çµµã®é ç¹ã«åœ©è²ã§ããªã</li>
</ul>
</section>
</div>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 1</h3><pre>7
1 3
2 3
3 4
4 5
4 6
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 1</h3><pre>1100111
</pre>
<p>å
¥åäŸ1ã®æšã¯ä»¥äžã®å³ã®ããã«ãªããŸãã</p>
<p><img alt="sample_picture_1_0" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_coloring_1_0.png" /></p>
<p>äŸãã°ã$k=2$ ã®æã以äžã®ããã«å¡ãã°æ¡ä»¶ãæºãããŸãã</p>
<p><img alt="sample_picture_1_2" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_coloring_1_2.png" /></p>
<p>ãŸãã$k=5$ ã®æã以äžã®ããã«å¡ãã°æ¡ä»¶ãæºãããŸãã </p>
<p><img alt="sample_picture_1_1" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_coloring_1_1.png" /></p>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 2</h3><pre>6
1 2
2 3
3 4
4 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 2</h3><pre>111111
</pre>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ 3</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ 3</h3><pre>1
</pre></section>
</div>
</span>
</span>
|
p00531 |
<h2>æ°Žéæé (Water Rate)</h2>
<h2> åé¡</h2>
<p>
JOI åãäœãã§ããå°åã«ã¯æ°ŽéäŒç€Ÿã X 瀟㚠Y 瀟㮠2 ã€ããïŒ2 ã€ã®äŒç€Ÿã® 1 ã¶æã®æ°Žéæéã¯ïŒ1 ã¶æã®æ°Žéã®äœ¿çšéã«å¿ããŠæ¬¡ã®ããã«æ±ºãŸãïŒ
</p>
<ul>
<li>X ç€ŸïŒ 1 ãªããã« ããã A åãããïŒ</li>
<li>Y ç€ŸïŒ åºæ¬æé㯠B åã§ããïŒäœ¿çšéã C ãªããã«ä»¥äžãªãã°ïŒæéã¯åºæ¬æé B åã®ã¿ããããïŒäœ¿çšéã C ãªããã«ãè¶
ãããšåºæ¬æé B åã«å ããŠè¿œå æéããããïŒè¿œå æéã¯äœ¿çšéã C ãªããã«ã 1 ãªããã«è¶
ããããšã« D åã§ããïŒ</li>
</ul>
<p>
JOI åã®å®¶ã§ã¯ 1 ã¶æã®æ°Žéã®äœ¿çšéã P ãªããã«ã§ããïŒ
</p>
<p>
æ°Žéæéãã§ããã ãå®ããªãããã«æ°ŽéäŒç€Ÿãéžã¶ãšãïŒJOI åã®å®¶ã® 1 ã¶æã®æ°Žéæéãæ±ããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠5 è¡ãããªãïŒ1 è¡ã« 1 ã€ãã€æŽæ°ãæžãããŠããïŒ<br>
1 è¡ç®ã«ã¯ X 瀟㮠1 ãªããã«ãããã®æé A ãæžãããŠããïŒ<br>
2 è¡ç®ã«ã¯ Y 瀟ã®åºæ¬æé B ãæžãããŠããïŒ<br>
3 è¡ç®ã«ã¯ Y ç€Ÿã®æéãåºæ¬æéã®ã¿ã«ãªã䜿çšéã®äžé C ãæžãããŠããïŒ<br>
4 è¡ç®ã«ã¯ Y 瀟㮠1 ãªããã«ãããã®è¿œå æé D ãæžãããŠããïŒ<br>
5 è¡ç®ã«ã¯ JOI åã®å®¶ã® 1 ã¶æã®æ°Žéã®äœ¿çšé P ãæžãããŠããïŒ
</p>
<p>
æžãããŠããæŽæ° A, B, C, D, P ã¯ãã¹ãŠ 1 ä»¥äž 10000 以äžã§ããïŒ
</p>
<h2>åºå</h2>
<p>
JOI åã®å®¶ã® 1 ã¶æã®æ°Žéæéãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
9
100
20
3
10
</pre>
<h3>åºåäŸ 1</h3>
<pre>
90
</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
8
300
100
10
250
</pre>
<h3>åºåäŸ 2</h3>
<pre>
1800
</pre>
<p>
å
¥åºåäŸ 1 ã§ã¯ïŒJOI åã®å®¶ã® 1 ã¶æã®æ°Žéã®äœ¿çšé㯠10 ãªããã«ã§ããïŒ
</p>
<ul>
<li>X ç€Ÿã®æ°Žéæé㯠9 × 10 = 90 åã§ããïŒ</li>
<li>JOI åã®å®¶ã® 1 ã¶æã®æ°Žéã®äœ¿çšé㯠20 ãªããã«ä»¥äžãªã®ã§ïŒY ç€Ÿã®æ°Žéæéã¯åºæ¬æéã® 100 åã§ããïŒ</li>
</ul>
<p>
JOI åã®å®¶ã¯æ°Žéæéãããå®ã X 瀟ãéžã¶ïŒãã®ãšãã® JOI åã®å®¶ã® 1 ã¶æã®æ°Žéæé㯠90 åã§ããïŒ
</p>
<p>
å
¥åºåäŸ 2 ã§ã¯ïŒJOI åã®å®¶ã® 1 ã¶æã®æ°Žéã®äœ¿çšé㯠250 ãªããã«ã§ããïŒ
</p>
<ul>
<li>X ç€Ÿã®æ°Žéæé㯠8 × 250 = 2000 åã§ããïŒ</li>
<li>JOI åã®å®¶ã® 1 ã¶æã®æ°Žéã®äœ¿çšé㯠100 ãªããã«ä»¥äžã§ïŒè¶
éé㯠250 - 100 = 150 ãªããã«ã§ããïŒãã£ãŠïŒY ç€Ÿã®æ°Žéæéã¯åºæ¬æéã® 300 åã«å ã㊠10 × 150 = 1500 åã®è¿œå æéããããïŒåèšã®æ°Žéæé㯠300 + 1500 = 1800 åã§ããïŒ</li>
</ul>
<p>
JOI åã®å®¶ã¯æ°Žéæéãããå®ã Y 瀟ãéžã¶ïŒãã®ãšãã® JOI åã®å®¶ã® 1 ã¶æã®æ°Žéæé㯠1800 åã§ããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00161 |
<H1>äœè²ç¥Sport Meet</H1>
<p>
ç§ã®äœè²ç¥ãè¡ãããŸããçš®ç®ã¯åŸç«¶èµ°ãããŒã«éã³ãé害ç©ç«¶èµ°ããªã¬ãŒã®4çš®ç®ã§ããåå ããŒã 㯠<var>n</var> ããŒã ã§ããã®4çš®ç®ã®åèšã¿ã€ã ãæãå°ããããŒã ããåªåããæ¬¡ã«å°ããããŒã ããæºåªåãããããŠãæäžäœãã2çªç®ã®ããŒã ããããŒããŒè³ããšããŠè¡šåœ°ããããšæããŸãã
</p>
<p>
åããŒã ã®æçžŸãå
¥åãšããŠããåªåãããæºåªåãããããŒããŒè³ãã®ããŒã ãåºåããããã°ã©ã ãäœæããŠãã ããã
ãã ããããŒã ã«ã¯ãããã 1 ãã <var>n</var> ã®ããŒã çªå·ãå²ãåœãŠãããŠããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>record<sub>1</sub></var>
<var>record<sub>2</sub></var>
:
<var>record<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å¯Ÿè±¡ãšãªãããŒã ã®æ° <var>n</var> (4 ≤ <var>n</var> ≤ 100000)ãç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®ããŒã ã®æ
å ±ãäžããããŸããåããŒã ã®æ
å ±ã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>id</var> <var>m1</var> <var>s1</var> <var>m2</var> <var>s2</var> <var>m3</var> <var>s3</var> <var>m4</var> <var>s4</var>
</pre>
<p>
<var>id</var> (1 ≤ <var>id</var> ≤ <var>n</var>)ã¯ããŒã çªå·ã<var>m1</var>, <var>s1</var> ã¯ããããåŸç«¶èµ°ã®ã¿ã€ã ã®åãšç§ã<var>m2</var>, <var>s2</var> ã¯ããããããŒã«éã³ã®ã¿ã€ã ã®åãšç§ã<var>m3</var>, <var>s3</var> ã¯ããããé害ç©ç«¶èµ°ã®ã¿ã€ã ã®åãšç§ã<var>m4</var>, <var>s4</var> ã¯ãããããªã¬ãŒã®ã¿ã€ã ã®åãšç§ã衚ããŸããåãšç§ã¯ãšãã«0 ä»¥äž 59 以äžã®æŽæ°ã§ãããŸããåèšã¿ã€ã ãè€æ°ã®ããŒã ã§åãã«ãªããããªå
¥åã¯ãªããã®ãšããŸãã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ä»¥äžã®åœ¢åŒã§ããŒã çªå·ãåºåããŸãã<br/>
<br/>
1 è¡ç® åªåã®ããŒã çªå·<br/>
2 è¡ç® æºåªåã®ããŒã çªå·<br/>
3 è¡ç® ããŒããŒè³ã®ããŒã çªå·<br/>
</p>
<H2>Sample Input</H2>
<pre>
8
34001 3 20 3 8 6 27 2 25
20941 3 5 2 41 7 19 2 42
90585 4 8 3 12 6 46 2 34
92201 3 28 2 47 6 37 2 58
10001 3 50 2 42 7 12 2 54
63812 4 11 3 11 6 53 2 22
54092 3 33 2 54 6 18 2 19
25012 3 44 2 58 6 45 2 46
4
1 3 23 1 23 1 34 4 44
2 5 12 2 12 3 41 2 29
3 5 24 1 24 2 0 3 35
4 4 49 2 22 4 41 4 23
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
54092
34001
10001
1
3
2
</pre>
|
p01320 |
<h1><font color="#000">Problem G:</font> Magical Island 2</h1>
<!--
<h3><U>鿳島ç©èª2</U></h3>
-->
<p>ãŸã éæ³ãããããŸãã®ããã«ååšããæä»£ã§ããïŒããéå°å£«ã®äžæã¯ïŒéåã«ãã£ãŠäœãããæ£æ¹åœ¢ã®åœ¢ã®å³¶ã«äœãã§ããïŒ</p>
<p>ããæïŒãã®å³¶ã«å±æ©ã蚪ããïŒåžåœã倧éžé匟ééå°ããµã€ã«ãéçºãïŒãã®å³¶ãç
§æºã«åãããŠããã®ã§ããïŒãã®äžçã®éæ³ã¯å°å±æ§ïŒæ°Žå±æ§ïŒç«å±æ§ïŒé¢šå±æ§ãªã©ã«åé¡ã§ãïŒéå°ããµã€ã«ããã®åã€ã®å±æ§ã®ããããã«å±ããŠããïŒå³¶ã®åé
ã«ã¯ããããå°ã®æ°Žæ¶ïŒæ°Žã®æ°Žæ¶ïŒç«ã®æ°Žæ¶ïŒé¢šã®æ°Žæ¶ãé
眮ãããŠããŠïŒæ°Žæ¶ã«éåãéã蟌ãããšã§å¯Ÿå¿ãã屿§ã®éæ³æ»æãé²ãããšããã§ãïŒ</p>
<p>éå°å£«éã¯åžåœãéçºãã倧éžé匟ééå°ããµã€ã«ã«ããæ»æããããããŠéããããšãã§ããïŒãããïŒåžåœã¯æ°ãã«é屿§ã«å±ãã倧éžé匟ééå°ããµã€ã«ãéçºãïŒåã³ãã®å³¶ã«æ»æã仿ããŠããïŒé屿§ã«å±ããéæ³ã¯ãã®å³¶ã«èšçœ®ãããŠããæ°Žæ¶ã§é²ãããšã¯ã§ããªãïŒããã§éå°å£«éã¯ç§è¡ãšããŠãã®å³¶ã«äŒããããå
屿§ã®é²åŸ¡é£ãçšããŠããµã€ã«ãé²ãäºã«ããïŒ</p>
<p>ãã®å
屿§ã®é²åŸ¡é£ã¯ããç¹å®ã®åœ¢ç¶ãããéæ³é£ã倧å°ã«æãããšã«ããçºåããïŒ éæ³é£ã¯ååŸ <i>R</i> ã®ååšã <i>M</i> çåã <i>K</i> åããã«çŽç·ã§çµãã å³åœ¢ã§ããïŒéæ³é£ã¯ä»»æã®å€§ããã§æãããšãã§ãããéæ³ã®çºåã«ã¯æ¹è§ãéèŠãªã®ã§ïŒäžã€ã®è§ãçåãåãããã«æããªããã°ãªããªãïŒé²åŸ¡é£ã®å¹æãåã¶ç¯å²ã¯æãããéæ³é£ã®å
éšïŒå¢çãå«ãïŒãšäžèŽããïŒãŸããã®éæ³ã®è© å±ã«å¿
èŠãªãšãã«ã®ãŒã¯æããéæ³é£ã®ååŸ <i>R</i> ãšçããïŒ</p>
<p>å³G-1㯠<i>M</i> = 4ïŒ <i>K</i> = 1 ã®å Žåã§ããïŒç°è²ã®éšåãéæ¹é£ã®å¹æãåã¶é åã§ããïŒ å³G-2㯠<i>M</i> = 6ïŒ <i>K</i> = 2 ã®å Žåã§ããïŒå³ã®ããã«è€æ°ã®å³åœ¢ãçããå Žåã¯ïŒãããã®å³åœ¢ã®ããããã«å«ãŸããŠããã°é²åŸ¡é£ãšããŠã®å¹æãåã¶ïŒ<br />
</p>
<center>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_G1"><br />
å³G-1: <i>M</i> = 4 ïŒ<i>K</i> = 1 ã®å Žå å°ããäžžãéèœã衚ã<br />
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_G2"><br />
å³G-2: <i>M</i> = 6 ïŒ<i>K</i> = 2 ã®å Žå<br />
</p>
</center>
<p>ããªãã®ä»äºã¯ïŒéèœã®äœçœ®ïŒããã³ <i>M</i> ãš <i>K</i> ã®å€ãäžãããããšãã«ïŒå
šãŠã®éèœãã«ããŒããããã«å¿
èŠãšãªããšãã«ã®ãŒã®æäœéãæ±ããããã°ã©ã ãæžãããšã§ããïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ</p>
<blockquote><i>N</i> <i>M</i> <i>K</i><br />
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br />
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i><br />
...<br />
<i>x<sub>N</sub></i> <i>y<sub>N</sub></i><br />
</blockquote>
<p>æåã®äžè¡ã¯ 3 ã€ã®æŽæ°<i>N</i>, <i>M</i>, <i>K</i> ãããªãïŒ <i>N</i>
ã¯éèœã®æ°ã衚ãïŒ <i>M</i>, <i>K</i> ã«ã€ããŠã¯å顿ã«èšãããšããã§ããïŒ 2 ≤ <i>N</i> ≤ 50ïŒ 3 ≤ <i>M</i> ≤ 50ïŒ 1 ≤ <i>K</i> ≤ (<i>M</i> - 1) / 2ãä»®å®ããŠããïŒ</p>
<p>ç¶ã <i>N</i> è¡ã¯éèœã®äœçœ®ã衚ãïŒ åè¡ã¯äºã€ã®æŽæ° <i>x<sub>i</sub></i> ãš <i>y<sub>i</sub></i>
ãããªãïŒ <i>x<sub>i</sub></i> ãš <i>y<sub>i</sub></i> 㯠<i>i</i> çªç®ã®éèœã®x座æšãšy座æšã衚ãïŒ -1000 ≤ <i>x<sub>i</sub></i>ïŒ <i>y<sub>i</sub></i> ≤ 1000 ãä»®å®ããŠè¯ãïŒyè»žã®æ£æ¹åãåãæã.</p>
<p>å
¥åã®çµããã¯ã¹ããŒã¹ã§åºåããã3åã®ãŒããããªãïŒ</p>
<h2>Output</h2>
<p>åããŒã¿ã»ããã«å¯ŸãïŒéæ³é£ã®æå°ã®ååŸ <i>R</i> ã1è¡ã«åºåããïŒ åºåããå€ã¯10<sup>-6</sup>以äžã®èª€å·®ãå«ãã§ããŠãæ§ããªãïŒå€ã¯å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãæ§ããªãïŒ</p>
<h2>Sample Input</h2>
<pre>
4 4 1
1 0
0 1
-1 0
0 -1
5 6 2
1 1
4 4
2 -4
-4 2
1 5
0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1.000000000
6.797434948
</pre>
|
p00862 |
<H1><font color="#000">Problem I:</font> Most Distant Point from the Sea</H1>
<p>
The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it
is natural to ask a question: "Where is the most distant point from the sea?" The answer to
this question for Honshu was found in 1996. The most distant point is located in former Usuda
Town, Nagano Prefecture, whose distance from the sea is 114.86 km.
</p>
<p>
In this problem, you are asked to write a program which, given a map of an island, finds the
most distant point from the sea in the island, and reports its distance from the sea. In order to
simplify the problem, we only consider maps representable by convex polygons.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset represents a map of an island, which is a convex polygon. The format of a dataset is as follows.
</p>
<pre>
<i>n</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
.
.
.
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub>
</pre>
<p>
Every input item in a dataset is a non-negative integer. Two input items in a line are separated by a space.
</p>
<p>
<i>n</i> in the first line is the number of vertices of the polygon, satisfying 3 ≤ <i>n</i> ≤ 100. Subsequent
<i>n</i> lines are the <i>x</i>- and <i>y</i>-coordinates of the <i>n</i> vertices. Line segments (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) - (<i>x</i><sub><i>i</i>+1</sub>, <i>y</i><sub><i>i</i>+1</sub>) (1 ≤ <i>i</i> ≤ <i>n</i> - 1) and the line segment (<i>x<sub>n</sub></i>, <i>y<sub>n</sub></i>) - (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) form the border of the polygon in counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. All coordinate values are between 0 and 10000, inclusive.
</p>
<p>
You can assume that the polygon is simple, that is, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.
</p>
<p>
The last dataset is followed by a line containing a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset in the input, one line containing the distance of the most distant point from
the sea should be output. An output line should not contain extra characters such as spaces.
</p>
<p>
The answer should not have an error greater than 0.00001 (10<sup>-5</sup> ). You may output any number
of digits after the decimal point, provided that the above accuracy condition is satisfied.
</p>
<H2>Sample Input</H2>
<pre>
4
0 0
10000 0
10000 10000
0 10000
3
0 0
10000 0
7000 1000
6
0 40
100 20
250 40
250 70
100 90
0 70
3
0 0
10000 10000
5000 5001
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5000.000000
494.233641
34.542948
0.353553
</pre>
|
p01770 |
<h1 id="arojams-mask-ã ãžã¥ã©ã®ä»®é¢">E : Arojam's Mask / ä»®é¢</h1>
<h2 id="å顿">å顿</h2>
<p>ããªãã¯åè
ã§ãããåè
ãæ
ãããŠããäžç㯠<var>N</var> åã®è¡ãšãç°ãªãè¡å士ãçµã¶ <var>M</var> æ¬ã®éãããªããé <var>i</var> ã¯è¡ <var>a_i</var> ãšè¡ <var>b_i</var> ãçµã³ãåæ¹åã«ç§»åå¯èœã§ããã</p>
<p>è¡ <var>S</var> ããåºçºããè¡ <var>T</var> ã«ç§»åããããšãåè
ã®ç®çã§ããã <var>S,T</var> ã¯ç°ãªãè¡ã§ãããåè
㯠<var>0</var> æ¥ç®ã«è¡ãåºçºããã¡ããã© <var>1</var> æ¥ãã㊠<var>1</var> æ¬ã®éãéã£ãŠç§»åããããšãã§ãããéã䜿ã£ãç§»åã«ã¯æ¥æ°ã®å¶é <var>R</var> ãããã<var>R</var> æ¥ç®ãè¶
ããããšã¯ã§ããªãã</p>
<p>ãŸããåè
ã¯ä»»æã®è¡ã§ããªã«ãªããå¹ããããšãã§ããããªã«ãªããå¹ããšãæã¯ <var>0</var> æ¥ç®ã«ãäœçœ®ã¯è¡ <var>S</var> ã«æ»ããããã€ãŸãã<var>R</var> åãè¶
ããç§»åãè¡ãå Žåã¯ãæäœäžåºŠã¯ãªã«ãªããå¹ããªããã°ãªããªãã</p>
<p>ããã«ãåè
ãããè¡ã«äœçœ®ãããšãã€ãã³ãããçºçããããšããããã€ãã³ã㯠<var>E</var> çš®é¡ããã<var>i</var> çªç®ã®ã€ãã³ãã¯ãè¡ <var>c_{i}</var> ã§çºçãããã€ãã³ãã¯åè
ãããã«ãããšèªåçã«çºçããæ°ãã«é <var>aâ_i</var> ãš <var>bâ_i</var> ãçµã¶éãçããããã®éã¯ãªã«ãªããå¹ããŠãæ¶ããããšã¯ãªããåãããååšããéãšããå¥ã®ã€ãã³ãã«ãã£ãŠè¿œå ãããéãšãéè€ããªããããçºã§èµ·ããã€ãã³ãã¯é«ã
1ã€ã§ããã</p>
<p>ããŠãåè
ã®ä»æ¥ã®ä»äºã¯ãè¡ <var>T</var> ã«å°éãããŸã§ã«å¿
èŠãªç§»åã®åæ°ãšãªã«ãªããå¹ãåæ°ã®åã®æå°å€ãæ±ããããã°ã©ã ãæžãããšã§ããã</p>
<h2 id="å
¥å">å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre><var>N</var> <var>M</var> <var>E</var> <var>S</var> <var>T</var> <var>R</var>
<var>a_{0}</var> <var>b_{0}</var>
<var>âŠ</var>
<var>a_{M−1}</var> <var>b_{M−1}</var>
<var>aâ_{0}</var> <var>bâ_{0}</var> <var>c_{0}</var>
<var>âŠ</var>
<var>aâ_{E−1}</var> <var>bâ_{E−1}</var> <var>c_{E−1}</var>
</pre>
<h2 id="å¶çŽ">å¶çŽ</h2>
<ul>
<li>å
¥åã¯ãã¹ãп޿°ã§ãã</li>
<li><var>2 \≤ N \≤ 100</var></li>
<li><var>1 \≤ M+E \≤ N(N−1)</var>/<var>2</var></li>
<li><var>0 \≤ E \≤ 4</var></li>
<li><var>0 \≤ R \≤ 100</var></li>
<li><var>0 \≤ S,T,a_i,b_i,aâ_i,bâ_i,c_i \≤ N−1</var></li>
<li><var>S â T</var></li>
<li><var>a_{i} â b_{i}, aâ_{i} â bâ_{i}</var></li>
<li><var>a_{i}</var> ãš <var>b_{i}</var>ã<var>aâ_{i}</var> ãš <var>bâ_{i}</var>ã®å
šãŠã®çµã¯éè€ããªã</li>
<li><var>i â j</var> ãªã <var>c_{i} â c_{j}</var></li>
</ul>
<h2 id="åºå">åºå</h2>
<p>çããäžè¡ã§åºåãããã©ãããŠã <var>T</var> ãžå°éã§ããªãå Žå㯠<var>−1</var> ãåºåããã</p>
<h2 id="ãµã³ãã«">ãµã³ãã«</h2>
<h3 id="ãµã³ãã«å
¥å1">ãµã³ãã«å
¥å1</h3>
<pre>8 5 2 0 5 5
0 1
0 3
0 6
1 2
6 7
3 4 7
4 5 2
</pre>
<h3 id="ãµã³ãã«åºå1">ãµã³ãã«åºå1</h3>
<pre>9
</pre>
<p>äŸãã°ä»¥äžã®ããã«ç§»åããã°ãããã€ãã³ããèµ·ãããŸã§ã¯é(4,5), (3,4)ã¯ååšããªãããšã«æ³šæããã</p>
<ul>
<li>è¡2ã«è¡ããš4ãã5ãžç§»åã§ããããã«ãªã</li>
<li>ãªã«ãªãã䜿çšã0ãžæ»ã</li>
<li>è¡7ã«è¡ããš3ãã4ãžç§»åã§ããããã«ãªã</li>
<li>ãªã«ãªãã䜿çšã0ãžæ»ã</li>
<li>0ãã5ãžãŸã£ããé²ã</li>
</ul>
<div class="figure">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RUPC2015_E1" />
</div>
<h3 id="ãµã³ãã«å
¥å2">ãµã³ãã«å
¥å2</h3>
<pre>7 5 1 0 6 8
0 1
1 2
2 3
3 4
4 5
3 6 5
</pre>
<h3 id="ãµã³ãã«åºå2">ãµã³ãã«åºå2</h3>
<pre>8
</pre>
<p>ãªã«ãªãã1床ãå¹ããªãçµè·¯ãæé©ã§ããã</p>
<h3 id="ãµã³ãã«å
¥å3">ãµã³ãã«å
¥å3</h3>
<pre>4 1 4 1 2 3
3 1
3 2 0
0 1 3
0 3 1
0 2 2
</pre>
<h3 id="ãµã³ãã«åºå3">ãµã³ãã«åºå3</h3>
<pre>5
</pre>
<p>è¡ <var>S</var> ã§ã€ãã³ããèµ·ããããšãããã</p> |
p03258 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a string <var>s</var> consisting of <code>a</code> and <code>b</code>.
Snuke can perform the following two kinds of operation any number of times in any order:</p>
<ul>
<li>Choose an occurrence of <code>aa</code> as a substring, and replace it with <code>b</code>.</li>
<li>Choose an occurrence of <code>bb</code> as a substring, and replace it with <code>a</code>.</li>
</ul>
<p>How many strings <var>s</var> can be obtained by this sequence of operations?
Find the count modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |s| \leq 10^5</var></li>
<li><var>s</var> consists of <code>a</code> and <code>b</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of strings <var>s</var> that can be obtained, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>Six strings can be obtained:</p>
<ul>
<li><code>aaaa</code></li>
<li><code>aab</code></li>
<li><code>aba</code></li>
<li><code>baa</code></li>
<li><code>bb</code></li>
<li><code>a</code></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aabb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>Five strings can be obtained:</p>
<ul>
<li><code>aabb</code></li>
<li><code>aaa</code></li>
<li><code>bbb</code></li>
<li><code>ab</code></li>
<li><code>ba</code></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>ababababa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p>Snuke cannot perform any operation.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>babbabaaba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>35
</pre></section>
</div>
</span> |
p01265 |
<H1><font color="#000">Problem F:</font> Ninja Legend</H1>
<p>
Ninjas are professional spies in the Middle Age of Japan. They have been popular in movies and games
as they have been described with extraordinary physical abilities and unrealistic abilities.
</p>
<p>
You are absorbed in one of ninja games, <i>Ninja Legend</i>. In this game, you control in an exceptionally
talented ninja named <i>Master Ninja</i> and accomplish various missions. In one of the missions, the ninja
intrudes into a mansion and aims to steal as many gold pieces as possible. It is not easy to be done
because there are many pitfalls to evade him. Once he falls into a pitfall, all he can do will be just to wait
for being caught by the owner of this mansion. This definitely means failure of the mission. Thus, you
must control the ninja with a good strategy.
</p>
<p>
The inside of mansion is represented by a grid map as illustrated below. Master Ninja enters at and exits
from the entrance. He can move in the four directions to the floor cells. He can pick up gold blocks when
he moves to the cells where they are placed, but it is also allowed to pick up them in the later visit of
those cells or even to give up them.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ninja1">
<p>Figure 1: Example Map</p>
</center>
<p>
The ninja has a couple of special abilities for dealing with the pitfalls. He has two moving modes: <i>normal
mode and dash mode</i>. He is initially in the normal mode. He gets into the dash mode when he moves
in the same direction by two cells in a row without picking up gold blocks. He gets back to the normal
mode when he changes the direction, picks up a gold block, or runs on a wall as mentioned later. He is
able to jump over a pitfall, or in the dash mode he can jump over two pitfalls in his dashing direction. In
addition, when he is in the dash mode, he can <i>run on a wall</i> to pass over up to four pitfalls in his dashing
direction. For his running, there must be consecutive wall cells adjacent to the passing cells including
the departure and arrival floor cells. Note that he gets back to the normal mode when he runs on a wall
as mentioned previously.
</p>
<p>
In the figure below, the left one shows how the ninja runs on a wall, and the right one illustrates a case in
which he cannot skip over pitfalls by running on a wall.
</p>
<center>
<table cellpadding=8 cellspacing=8>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ninja2"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ninja3"></td>
</tr>
<tr>
<td><p>Figure 2: Running on a Wall</p></td>
<td><p>Figure 3: Non-consecutive Walls</p></td>
</tr>
</table>
</center>
<p>
You want to know the maximum number of gold blocks the ninja can get, and the minimum cost to get
those gold blocks. So you have decided to write a program for it as a programmer. Here, move of the
ninja from a cell to its adjacent cell is considered to take one unit of cost.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets.
</p>
<p>
The first line of each dataset contains two integers <i>H</i> (3 ≤ <i>H</i> ≤ 60) and <i>W</i> (3 ≤ <i>W</i> ≤ 80). <i>H</i> and <i>W</i>
indicate the height and width of the mansion. The following <i>H</i> lines represent the map of the mansion.
Each of these lines consists of <i>W</i> characters. Each character is one of the following: â<span>%</span>â (entrance), â<span>#</span>â
(wall), â<span>.</span>â (floor), â<span>^</span>â (pitfall), â<span>*</span>â (floor with a gold block).
</p>
<p>
You can assume that the number of gold blocks are less than or equal to 15 and every map is surrounded
by wall cells.
</p>
<p>
The end of the input indicated with a line containing two zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, output the maximum number of gold blocks and the minimum cost in one line. Output
two zeros instead if the ninja cannot get any gold blocks. No other characters should be contained in the
output.
</p>
<H2>Sample Input</H2>
<pre>
6 23
#######################
#%.^.^#################
#^^^^^######^^^^^^^^^^#
#^^^...^^^^...^^*^^..*#
#^^^^^^^^^^^^^^^^^^^^^#
#######################
5 16
################
#^^^^^^^^^^^^^^#
#*..^^^.%.^^..*#
#^^#####^^^^^^^#
################
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 44
2 28
</pre>
|
p00927 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem D:
Space Golf
</h2>
<p>
You surely have never heard of this new planet surface exploration scheme, as it is being carried out in a project with utmost secrecy. The scheme is expected to cut costs of conventional rovertype mobile explorers considerably, using projected-type equipment nicknamed "observation bullets".
</p>
<p>
Bullets do not have any active mobile abilities of their own, which is the main reason of their cost-efficiency. Each of the bullets, after being shot out on a launcher given its initial velocity, makes a parabolic trajectory until it touches down. It bounces on the surface and makes another parabolic trajectory. This will be repeated virtually infinitely.
</p>
<p>
We want each of the bullets to bounce precisely at the respective spot of interest on the planet surface, adjusting its initial velocity. A variety of sensors in the bullet can gather valuable data at this instant of bounce, and send them to the observation base. Although this may sound like a conventional target shooting practice, there are several issues that make the problem more difficult.
</p>
<ul>
<li> There may be some obstacles between the launcher and the target spot. The obstacles stand upright and are very thin that we can ignore their widths. Once the bullet touches any of the obstacles, we cannot be sure of its trajectory thereafter. So we have to plan launches to avoid these obstacles.</li>
<li> Launching the bullet almost vertically in a speed high enough, we can easily make it hit the target without touching any of the obstacles, but giving a high initial speed is energyconsuming. Energy is extremely precious in space exploration, and the initial speed of the bullet should be minimized. Making the bullet bounce a number of times may make the bullet reach the target with lower initial speed.</li>
<li> The bullet should bounce, however, no more than a given number of times. Although the body of the bullet is made strong enough, some of the sensors inside may not stand repetitive shocks. The allowed numbers of bounces vary on the type of the observation bullets.</li>
</ul>
<p>
You are summoned engineering assistance to this project to author a smart program that tells the minimum required initial speed of the bullet to accomplish the mission.
</p>
<p>
Figure D.1 gives a sketch of a situation, roughly corresponding to the situation of the Sample
Input 4 given below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2014_D1" width="600"><br>
<p>Figure D.1. A sample situation</p>
</center>
<p>
You can assume the following.
</p>
<ul>
<li> The atmosphere of the planet is so thin that atmospheric resistance can be ignored.</li>
<li> The planet is large enough so that its surface can be approximated to be a completely flat plane.</li>
<li> The gravity acceleration can be approximated to be constant up to the highest points a bullet can reach.</li>
</ul>
<p>
These mean that the bullets fly along a perfect parabolic trajectory.
</p>
<p>
You can also assume the following.
</p>
<ul>
<li> The surface of the planet and the bullets are made so hard that bounces can be approximated as elastic collisions. In other words, loss of kinetic energy on bounces can be ignored. As we can also ignore the atmospheric resistance, the velocity of a bullet immediately after a bounce is equal to the velocity immediately after its launch.</li>
<li> The bullets are made compact enough to ignore their sizes.</li>
<li> The launcher is also built compact enough to ignore its height.</li>
</ul>
<p>
You, a programming genius, may not be an expert in physics. Let us review basics of rigid-body dynamics.
</p>
<p>
We will describe here the velocity of the bullet $v$ with its horizontal and vertical components $v_x$ and $v_y$ (positive meaning upward). The initial velocity has the components $v_{ix}$ and $v_{iy}$, that is, immediately after the launch of the bullet, $v_x = v_{ix}$ and $v_y = v_{iy}$ hold. We denote the horizontal distance of the bullet from the launcher as $x$ and its altitude as $y$ at time $t$.
</p>
<ul>
<li>
The horizontal velocity component of the bullet is kept constant during its flight when atmospheric resistance is ignored. Thus the horizontal distance from the launcher is proportional to the time elapsed.
\[
x = v_{ix}t
\tag{1}
\]
</li>
<li>
The vertical velocity component $v_y$ is gradually decelerated by the gravity. With the gravity acceleration of $g$, the following differential equation holds during the flight.
\[
\frac{dv_y}{dt} = âg
\tag{2}
\]
Solving this with the initial conditions of $v_y = v_{iy}$ and $y = 0$ when $t = 0$, we obtain the
following.
\[
y = â\frac{1}{2} gt^2 + v_{iy}t
\tag{3}
\]
\[
= â(\frac{1}{2}gt â v_{iy})t
\tag{4}
\]
The equation (4) tells that the bullet reaches the ground again when $t = 2v_{iy}/g$. Thus, the distance of the point of the bounce from the launcher is $2v_{ix}v_{iy}/g$. In other words, to make the bullet fly the distance of $l$, the two components of the initial velocity should satisfy $2v_{ix}v_{iy} = lg$.
</li>
<li>
Eliminating the parameter $t$ from the simultaneous equations above, we obtain the following equation that describes the parabolic trajectory of the bullet.
\[
y = â(\frac{g}{2v^2_{ix}})x^2 + (\frac{v_{iy}}{v_{ix}})x
\tag{5}
\]
</li>
</ul>
<p>
For ease of computation, a special unit system is used in this project, according to which the gravity acceleration $g$ of the planet is exactly 1.0.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case with the following format.<br>
<br>
$d$ $n$ $b$<br>
$p_1$ $h_1$<br>
$p_2$ $h_2$<br>
.<br>
.<br>
.<br>
$p_n$ $h_n$<br>
<br>
The first line contains three integers, $d$, $n$, and $b$. Here, $d$ is the distance from the launcher
to the target spot ($1 \leq d \leq 10000$), $n$ is the number of obstacles ($1 \leq n \leq 10$), and $b$ is the maximum number of bounces allowed, not including the bounce at the target spot ($0 \leq b \leq 15$).
</p>
<p>
Each of the following $n$ lines has two integers. In the $k$-th line, $p_k$ is the position of the $k$-th obstacle, its distance from the launcher, and $h_k$ is its height from the ground level. You can assume that $0 < p_1$, $p_k < p_{k+1}$ for $k = 1, . . . , n â 1$, and $p_n < d$. You can also assume that
$1 \leq h_k \leq 10000$ for $k = 1, . . . , n$.
</p>
<h3>Output</h3>
<p>
Output the smallest possible initial speed $v_i$ that makes the bullet reach the target. The initial speed $v_i$ of the bullet is defined as follows.
\[
v_i = \sqrt{v_{ix}^2 + v_{iy}^2}
\]
The output should not contain an error greater than 0.0001
</p>
<h3>Sample Input 1</h3>
<pre>100 1 0
50 100</pre>
<h3>Sample Output 1</h3>
<pre>14.57738</pre>
<h3>Sample Input 2</h3>
<pre>10 1 0
4 2</pre>
<h3>Sample Output 2</h3>
<pre>3.16228</pre>
<h3>Sample Input 3</h3>
<pre>100 4 3
20 10
30 10
40 10
50 10</pre>
<h3>Sample Output 3</h3>
<pre>7.78175</pre>
<h3>Sample Input 4</h3>
<pre>343 3 2
56 42
190 27
286 34</pre>
<h3>Sample Output 4</h3>
<pre>11.08710</pre> |
p03608 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> towns in the State of Atcoder, connected by <var>M</var> bidirectional roads.</p>
<p>The <var>i</var>-th road connects Town <var>A_i</var> and <var>B_i</var> and has a length of <var>C_i</var>.</p>
<p>Joisino is visiting <var>R</var> towns in the state, <var>r_1,r_2,..,r_R</var> (not necessarily in this order).</p>
<p>She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.</p>
<p>If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€Nâ€200</var></li>
<li><var>1â€Mâ€NÃ(N-1)/2</var></li>
<li><var>2â€Râ€min(8,N)</var> (<var>min(8,N)</var> is the smaller of <var>8</var> and <var>N</var>.)</li>
<li><var>r_iâ r_j (iâ j)</var></li>
<li><var>1â€A_i,B_iâ€N, A_iâ B_i</var></li>
<li><var>(A_i,B_i)â (A_j,B_j),(A_i,B_i)â (B_j,A_j) (iâ j)</var></li>
<li><var>1â€C_iâ€100000</var></li>
<li>Every town can be reached from every town by road.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>R</var>
<var>r_1</var> <var>...</var> <var>r_R</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>:</var>
<var>A_M</var> <var>B_M</var> <var>C_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 3
1 2 3
1 2 1
2 3 1
3 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, if she visits the towns in the order of <var>1</var>, <var>2</var>, <var>3</var>, the distance traveled will be <var>2</var>, which is the minimum possible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 2
1 3
2 3 2
1 3 6
1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>The shortest distance between Towns <var>1</var> and <var>3</var> is <var>4</var>. Thus, whether she visits Town <var>1</var> or <var>3</var> first, the distance traveled will be <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 6 3
2 3 4
1 2 4
2 3 3
4 3 1
1 4 1
4 2 2
3 1 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p01635 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: { inlineMath: [['\\(','\\)']] }
});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<h1 class="ndoc-heading1">Problem B: Time Complexity</h1>
<p class="ndoc-top">ICPC World Finals 1æ¥ç®</p>
<p class="ndoc-top">ããã°ã©ãã³ã°ã³ã³ãã¹ãã§ã¯ããã°ã©ã ã®å®è¡æéãææ¡ããäºãéèŠã ã
å®è¡æéã®èŠç©ããã誀ãã æéå¶éããªãŒããŒããŠããŸãã³ãŒããæžããŠããŸããšã ãã®ã¶ãæéããã¹ããŠããŸãã
ICPCã®ããã«ã³ã³ãã¥ãŒã¿ã1å°ãã䜿ããªãããŒã æŠã§ã¯ãªãããã§ããã</p>
<p class="ndoc-top">ããã§ãICPC World
Finalsãåã«æ§ãããã£ãŒæ°ã¯ããã°ã©ã ã®å®è¡æéãæç®ã§æ±ããèšç·Žãå§ããããšã«ããã
ãlogã¯å®æ°ã®ãããªãã®ããªã®ã§ããŸãã¯å€é
åŒã«åãçµããšãããã</p>
<h2 class="ndoc-heading2">åé¡</h2>
<p class="ndoc-top">ããåé¡ã®çããèšç®ããããã°ã©ã ãšããããå®è¡ããã³ã³ãã¥ãŒã¿ãããã
åé¡ã®å
¥åãè¡šãæ£æŽæ°\(n\)ã å
¥å\(n\)ã«å¿ããŠããã°ã©ã äžã§å®è¡ãããåœä»€ã®æ°ã衚ãå€é
åŒ\(f(n)\)ã
ã³ã³ãã¥ãŒã¿ã®1åœä»€ã®å®è¡æé\(T\)[ããç§]ïŒ=\( 10^{-9} \)[ç§]ïŒãäžããããã
å€é
åŒ\(f(n)\)ã®åæ°ã ãåœä»€ãå®è¡ããæã®ããã°ã©ã ã®ç·å®è¡æéã1ç§ã以äžãã§ããããå€å®ãã
1ç§ã以äžãã§ãããªãã°ç·å®è¡æéãæ±ããã</p>
<h2 class="ndoc-heading2">å
¥å</h2>
<pre>
n T
f(n)
</pre>
<p>1è¡ç®ã« åé¡ã®å
¥åãè¡šãæ£æŽæ°\(n\)ãš 1åœä»€ã®å®è¡æé[ããç§]ãè¡šãæŽæ°\(T\)ã空çœåºåãã§äžããããã
2è¡ç®ã«å®è¡ãããåœä»€ã®æ°ã衚ãå€é
åŒ\(f(n)\)ãäžããããã</p>
<p class="ndoc-top">å€é
åŒ\( f(n) \)ã¯ä»¥äžã®BNFã§è¡šãããã</p>
<pre>
<poly> ::= <poly> "+" <mono> | <mono>
<mono> ::= "n^" <num>
<num> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
</pre>
<p class="ndoc-top">ããã§ååé
åŒn^kã¯ã\(n\)ã®\(k\)ä¹ã衚ãã</p>
<h2 class="ndoc-heading2">åºå</h2>
<p class="ndoc-top">
ããã°ã©ã ã®ç·å®è¡æéã1ç§ã以äžãã§ããå Žåã«ã¯ç·å®è¡æéã[ããç§]åäœã§ã1ç§ããè¶
éãããå Žåã«ã¯"TLE"ã1è¡ã«åºåããã</p>
<h2 class="ndoc-heading2">å¶çŽ</h2>
<p class="ndoc-top"></p>
<ul class="ndoc-indent">
<li>\( 1 \leq n \leq 10^{9}(= 1000000000) \)</li>
<li>\( 1 \leq T \leq 10^{9}(= 1000000000) \)</li>
<li>å€é
åŒ\( f(n) \)ã®æ¬¡æ°ã¯0以äž9以äžãåé
åŒã®æ°ã¯1以äž10以äž</li>
</ul>
<h2 class="ndoc-heading2">å
¥åºåäŸ</h2>
<h3 class="ndoc-heading3">å
¥å1</h3>
<pre>
100 100
n^1+n^2+n^3
</pre>
<h3 class="ndoc-heading3">åºå1</h3>
<pre>
101010000
</pre>
<p>ç·å®è¡æéã¯\( (100^{1} + 100^{2} + 100^{3}) \times 100 \)[ããç§]ã§ããã</p>
<h3 class="ndoc-heading3">å
¥å2</h3>
<pre>
1000 1
n^3+n^0
</pre>
<h3 class="ndoc-heading3">åºå2</h3>
<pre>
TLE
</pre>
<p>ç·å®è¡æéã¯\( 1000^{3} + 1000^{0} = 10^{9}+1 \)[ããç§]ã§ããã1[ç§]ãè¶
ããŠããŸãã</p>
<h3 class="ndoc-heading3">å
¥å3</h3>
<pre>
100000000 100000000
n^3
</pre>
<h3 class="ndoc-heading3">åºå3</h3>
<pre>
TLE
</pre>
<p>ç·å®è¡æéã¯\( (10^{8})^{3} \times 10^{8} = 10^{32} \)[ããç§]ã§ããã</p> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.