question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p01190 |
<H1><font color="#000"></font>Reading Brackets in English</H1>
<!-- Problem B-->
<p>
Shun and his professor are studying Lisp and S-expressions. Shun is in Tokyo in order to make a presen-
tation of their research. His professor cannot go with him because of another work today.
</p>
<p>
He was making final checks for his slides an hour ago. Then, unfortunately, he found some serious
mistakes! He called his professor immediately since he did not have enough data in his hand to fix the
mistakes.
</p>
<p>
Their discussion is still going on now. The discussion looks proceeding with difficulty. Most of their data
are written in S-expressions, so they have to exchange S-expressions via telephone.
</p>
<p>
Your task is to write a program that outputs S-expressions represented by a given English phrase.
</p>
<H2>Input</H2>
<p>
The first line of the input contains a single positive integer <i>N</i>, which represents the number of test cases.
Then <i>N</i> test cases follow.
</p>
<p>
Each case consists of a line. The line contains an English phrase that represents an S-expression. The
length of the phrase is up to 1000 characters.
</p>
<p>
The rules to translate an S-expression are as follows.
</p>
<ol>
<li> An S-expression which has one element is translated into âa list of <<i>the element of the S-expression</i>>â. (e.g. â(A)â will be âa list of Aâ)</li>
<li> An S-expression which has two elements is translated into âa list of <<i>the first element of the S-expression</i>> and <<i>the second element of the S-expression</i>>â. (e.g. â(A B)â will be âa list of A and Bâ)</li>
<li> An S-expression which has more than three elements is translated into âa list of <<i>the first element of the S-expression</i>>, <<i>the second element of the S-expression</i>>, . . . and <<i>the last element
of the S-expression</i>>â. (e.g. â(A B C D)â will be âa list of A, B, C and Dâ)</li>
<li> The above rules are applied recursively. (e.g. â(A (P Q) B (X Y Z) C)â will be âa list of
A, a list of P and Q, B, a list of X, Y and Z and Câ)</li>
</ol>
<p>
Each atomic element of an S-expression is a string made of less than 10 capital letters. All words (âaâ,
âlistâ, âofâ and âandâ) and atomic elements of S-expressions are separated by a single space character,
but no space character is inserted before comma (â,â). No phrases for empty S-expressions occur in the
input. You can assume that all test cases can be translated into S-expressions, but the possible expressions
may not be unique.
</p>
<H2>Output</H2>
<p>
For each test case, output the corresponding S-expression in a separate line. If the given phrase involves
two or more different S-expressions, output âAMBIGUOUSâ (without quotes).
</p>
<p>
A single space character should be inserted between the elements of the S-expression, while no space
character should be inserted after open brackets (â(â) and before closing brackets (â)â).
</p>
<H2>Sample Input</H2>
<pre>
4
a list of A, B, C and D
a list of A, a list of P and Q, B, a list of X, Y and Z and C
a list of A
a list of a list of A and B
</pre>
<H2>Output for the Sample Input</H2>
<pre>
(A B C D)
(A (P Q) B (X Y Z) C)
(A)
AMBIGUOUS
</pre>
|
p02616 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are <var>N</var> integers <var>A_1,\ldots,A_N</var>.</p>
<p>We will choose exactly <var>K</var> of these elements. Find the maximum possible product of the chosen elements.</p>
<p>Then, print the maximum product modulo <var>(10^9+7)</var>, using an integer between <var>0</var> and <var>10^9+6</var> (inclusive).</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq N \leq 2\times 10^5</var></li>
<li><var>|A_i| \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_1</var> <var>\ldots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum product modulo <var>(10^9+7)</var>, using an integer between <var>0</var> and <var>10^9+6</var> (inclusive).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2
1 2 -3 -4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>The possible products of the two chosen elements are <var>2</var>, <var>-3</var>, <var>-4</var>, <var>-6</var>, <var>-8</var>, and <var>12</var>, so the maximum product is <var>12</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
-1 -2 -3 -4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000000001
</pre>
<p>The possible products of the three chosen elements are <var>-24</var>, <var>-12</var>, <var>-8</var>, and <var>-6</var>, so the maximum product is <var>-6</var>.</p>
<p>We print this value modulo <var>(10^9+7)</var>, that is, <var>1000000001</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 1
-1 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000000
</pre>
<p>The possible products of the one chosen element are <var>-1</var> and <var>1000000000</var>, so the maximum product is <var>1000000000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>999983200
</pre>
<p>Be sure to print the product modulo <var>(10^9+7)</var>.</p></section>
</div>
</span> |
p03904 | <span class="lang-en">
<p>Score : <var>1000</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 will insert at most <var>K</var> commas (<code>,</code>) into this string to separate it into multiple numbers.</p>
<p>Your task is to minimize the maximum number among those produced by inserting commas. Find minimum possible such value.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 ⊠K < |S| ⊠100,000</var></li>
<li><var>S</var> consists of digits between <code>1</code> and <code>9</code>, inclusive.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>100</var> points, <var>|S| ⊠2</var>.</li>
<li>In the test set worth another <var>100</var> points, <var>|S| ⊠16</var>.</li>
<li>In the test set worth another <var>200</var> points, <var>|S| ⊠100</var>.</li>
<li>In the test set worth another <var>200</var> points, <var>|S| ⊠2,000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>K</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
15267315
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>315
</pre>
<p>When the string is separated into <var>152</var>, <var>67</var> and <var>315</var>, the maximum among these is <var>315</var>, which is the minimum possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0
12456174517653111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12456174517653111
</pre>
<p><var>12456174517653111</var> itself is the answer.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
127356176351764127645176543176531763517635176531278461856198765816581726586715987216581
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5317635176
</pre></section>
</div>
</span> |
p01939 |
<h2>BïŒ ãã³ã¡ãããšæ°å - Ebi-chan and Integer Sequences -</h2>
<h3>åé¡</h3>
<p>
ãã³ã¡ããã¯æ°åã奜ãã§ããäžã§ãçå·®æ°åãç¹ã«å¥œãã§ãã
ä»åã¯ä»¥äžã®æ¡ä»¶ãæºããæ°åãäœãããšã«ããŸããã
</p>
<ul>
<li> é·ã <var>n</var> ã®çå·®æ°åã§ãã</li>
<li> æ°åã® <var>i</var> çªç®ã®èŠçŽ ã <var>s_i</var> ãšå®ããæãå
šãŠã® <var>s_i (1 \leq i \leq n)</var> ã <var>0 \leq s_i \leq m</var> ãæºããæŽæ°ã§ãã</li>
</ul>
<p>
äžã®æ¡ä»¶ãæºãããããªæ°åã¯ããã€ããã§ããããïŒ
ãã ãçãã¯éåžžã«å€§ãããªãããšãããã®ã§ã <var>10^9 + 7</var> ã§å²ã£ãäœããåºåããŠãã ããã
</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯äžè¡ã§äžããããã</p>
<pre><var>n</var> <var>m</var></pre>
<p><var>n</var> ã¯æ°åã®é·ãã衚ãã</p>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq n \leq 10^{15}</var></li>
<li> <var>0 \leq m \leq 10^{15}</var></li>
</ul>
<h3>åºå圢åŒ</h3>
<p>æ¡ä»¶ãæºããçå·®æ°åã®æ°ã <var>10^9 + 7</var> ã§å²ã£ãäœããäžè¡ã«åºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>3 9</pre>
<h3>åºåäŸ1</h3>
<pre>50</pre>
<h3>å
¥åäŸ2</h3>
<pre>10000000000 10000000000</pre>
<h3>åºåäŸ2</h3>
<pre>999999942</pre>
<p>å
¥åã¯32bitæŽæ°ã«ã¯åãŸããããªãããšã«æ³šæããŠãã ããã</p> |
p02246 |
<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>15 Puzzle</H1>
<p>
The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space.
</p>
<p>
In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 15 as shown below.
</p>
<pre>
1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15
</pre>
<p>
You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps).
</p>
<pre>
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
</pre>
<p>
Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle.
</p>
<H2>Input</H2>
<p>
The $4 \times 4$ integers denoting the pieces or space are given.
</p>
<H2>Output</H2>
<p>
Print the fewest steps in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>The given puzzle is solvable in at most 45 steps.</li>
</ul>
<H2>Sample Input</H2>
<pre>
1 2 3 4
6 7 8 0
5 10 11 12
9 13 14 15
</pre>
<H2>Sample Output</H2>
<pre>
8
</pre>
|
p00781 |
<H1><font color="#000">Problem B:</font> Lattice Practices</H1>
<p>
Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4 × 4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice1">
</center>
<p>
The cocoon bed can be divided into 10 rectangular boards, each of which has 5 slits:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice2">
</center>
<p>
Note that, except for the slit depth, there is no difference between the left side and the right side of the board (or, between the front and the back); thus, we cannot distinguish a symmetric board from its rotated image as is shown in the following:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice3">
</center>
<p>
Slits have two kinds of depth, either shallow or deep. The cocoon bed should be constructed by fitting five of the boards vertically and the others horizontally, matching a shallow slit with a deep slit.
</p>
<p>
Your job is to write a program that calculates the number of possible configurations to make the lattice. You may assume that there is no pair of identical boards. Notice that we are interested in the number of essentially different configurations and therefore you should not count mirror image configurations and rotated configurations separately as different configurations.
</p>
<p>
The following is an example of mirror image and rotated configurations, showing vertical and horizontal boards separately, where shallow and deep slits are denoted by '1' and '0' respectively.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice4">
</center>
<p>
Notice that a rotation may exchange position of a vertical board and a horizontal board.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets, each in a line. A data set gives the patterns of slits of 10 boards used to construct the lattice. The format of a data set is as follows:
</p>
<pre>
XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX
</pre>
<p>
Each x is either '0' or '1'. '0' means a deep slit, and '1' a shallow slit. A block of five slit descriptions corresponds to a board. There are 10 blocks of slit descriptions in a line. Two adjacent blocks are separated by a space.
</p>
<p>
For example, the first data set in the Sample Input means the set of the following 10 boards:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lattice5">
</center>
<p>
The end of the input is indicated by a line consisting solely of three characters "END".
</p>
<H2>Output</H2>
<p>
For each data set, the number of possible configurations to make the lattice from the given 10 boards should be output, each in a separate line.
</p>
<H2>Sample Input</H2>
<pre>
10000 01000 00100 11000 01100 11111 01110 11100 10110 11110
10101 01000 00000 11001 01100 11101 01110 11100 10110 11010
END
</pre>
<H2>Output for the Sample Input</H2>
<pre>
40
6
</pre>
|
p01893 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>C: 倱ãããã°ã©ã / Lost Graph</h1>
<h2>å顿</h2>
<p>
ããªããš AOR ã€ã«ã¡ããã¯ç«¶æããã°ã©ãã³ã°ã®ã°ã©ãåé¡ã®æºåãããŠããã
å
¥åã±ãŒã¹ã®çæã¯ AOR ã€ã«ã¡ããã®ä»äºã§ããã
ãã®åé¡ã®å
¥åã±ãŒã¹ã¯ $N$ é ç¹ã®æåã°ã©ãã§ããã
é ç¹ã«ã¯ $1$ ãã $N$ ãŸã§ã®çªå·ãä»ããŠããã
蟺ã«ã¯èªå·±ã«ãŒããå«ãŸãããããããªãããå€é蟺ã¯å«ãŸããªãã
</p>
<p>
ãšããããAOR ã€ã«ã¡ããã¯çªç¶é³ä¿¡äžéãšãªã£ãŠããŸããå
ã®ã°ã©ããæã«å
¥ããªããªã£ãŠããŸã£ããæ®ã£ãŠããã®ã¯æ¬¡ã®æ
å ±ã ãã§ããã
</p>
<ul>
<li>
å
¥æ¬¡æ°ã $i$ ã®é ç¹ã®æ°ã¯ $a_i$ åã§ãããã€ãŸãã $i$ ãçµç¹ãšããé ç¹ã®æ°ã¯ $a_i$ åã§ããã
</li>
<li>
åºæ¬¡æ°ã $i$ ã®é ç¹ã®æ°ã¯ $b_i$ åã§ãããã€ãŸãã $i$ ãå§ç¹ãšããé ç¹ã®æ°ã¯ $b_i$ åã§ããã
</li>
</ul>
<p>
æ®ãããæ
å ±ãšççŸããªãæåã°ã©ãã¯ååšããã ãããã
ãããå€å®ããååšãããªã YES ãšåºåããåŸççŸããªãæåã°ã©ãã 1 ã€åºåããã
è€æ°ããå Žåã¯ã©ããåºåããŠããããååšããªããªã NO ãšåºåããã
</p>
<h2>å
¥å</h2>
<p>
$n$<br>
$a_0 \cdots a_n$<br>
$b_0 \cdots b_n$<br>
</p>
<h2>å
¥åã®å¶çŽ</h2>
<p>
$1 \leq n \leq 50$<br>
$0 \leq a_i \leq n$<br>
$0 \leq b_i \leq n$<br>
</p>
<h2>åºå</h2>
<p>
æ¡ä»¶ãæºããã°ã©ããååšããå Žåã¯ä»¥äžã®åœ¢åŒã§åºåããã$e_{ij}$ ã¯ã $i$ ãã $j$ ãžã®æå蟺ãååšãããªãã° 1 ãããªããªã 0 ãšããã
è¡æ«ã«ç©ºçœãåºåããªãããã«æ³šæããã
</p>
<p>
YES<br>
$e_{11} \ e_{12} \cdots e_{1n}$<br>
$e_{21} \ e_{22} \cdots e_{2n}$<br>
$\vdots$<br>
$e_{n1} \ e_{n2} \cdots e_{nn}$<br>
</p>
<p>
ããªãå Žåã¯ä»¥äžã®ãšããã«åºåããã
</p>
<p>
NO
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å1</h3>
<pre>
3
1 2 0 0
1 2 0 0
</pre>
<h3>ãµã³ãã«åºå1</h3>
<pre>
YES
0 1 0
0 0 1
0 0 0
</pre>
<h3>ãµã³ãã«å
¥å2</h3>
<pre>
1
1 0
1 0
</pre>
<h3>ãµã³ãã«åºå2</h3>
<pre>
YES
0
</pre>
<h3>ãµã³ãã«å
¥å3</h3>
<pre>
2
0 2 0
0 2 0
</pre>
<h3>ãµã³ãã«åºå3</h3>
<pre>
YES
0 1
1 0
</pre>
<h3>ãµã³ãã«å
¥å4</h3>
<pre>
4
1 3 0 0 0
3 0 0 1 0
</pre>
<h3>ãµã³ãã«åºå4</h3>
<pre>
YES
0 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0
</pre>
<h3>ãµã³ãã«å
¥å5</h3>
<pre>
1
1 1
0 0
</pre>
<h3>ãµã³ãã«åºå5</h3>
<pre>
NO
</pre> |
p00851 |
<H1><font color="#000">Problem G:</font> Polygons on the Grid</H1>
<p>
The ultimate Tantra is said to have been kept in the most distinguished temple deep in the
sacred forest somewhere in Japan. Paleographers finally identified its location, surprisingly a
small temple in Hiyoshi, after years of eager research. The temple has an underground secret
room built with huge stones. This underground megalith is suspected to be where the Tantra
is enshrined.
</p>
<p>
The room door is, however, securely locked. Legends tell that the key of the door lock was an
integer, that only highest priests knew. As the sect that built the temple decayed down, it is
impossible to know the integer now, and the Agency for Cultural Affairs bans breaking up the
door. Fortunately, a figure of a number of rods that might be used as a clue to guess that secret
number is engraved on the door.
</p>
<p>
Many distinguished scholars have challenged the riddle, but no one could have ever succeeded
in solving it, until recently a brilliant young computer scientist finally deciphered the puzzle.
Lengths of the rods are multiples of a certain unit length. He found that, to find the secret
number, all the rods should be placed on a grid of the unit length to make one convex polygon.
Both ends of each rod must be set on grid points. Elementary mathematics tells that the
polygon's area ought to be an integer multiple of the square of the unit length. The area size of
the polygon with the largest area is the secret number which is needed to unlock the door.
</p>
<p>
For example, if you have five rods whose lengths are 1, 2, 5, 5, and 5, respectively, you can make
essentially only three kinds of polygons, shown in Figure 7. Then, you know that the maximum
area is 19.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_polygonsGrid">
<p>
Figure 7: Convex polygons consisting of five rods of lengths 1, 2, 5, 5, and 5
</p>
</center>
<p>
Your task is to write a program to find the maximum area of convex polygons using all the given
rods whose ends are on grid points.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, followed by a line containing a single zero which indicates
the end of the input. The format of a dataset is as follows.
</p>
<pre>
<i>n</i>
<i>r</i><sub>1</sub> <i>r</i><sub>2</sub> ... <i>r<sub>n</sub></i>
</pre>
<p>
<i>n</i> is an integer which means the number of rods and satisfies 3 ≤ <i>n</i> ≤ 6. <i>r<sub>i</sub></i> means the length of the <i>i</i>-th rod and satisfies 1 ≤ <i>r<sub>i</sub></i> ≤ 300.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing an integer which is the area of the largest convex
polygon. When there are no possible convex polygons for a dataset, output "<span>-1</span>".
</p>
<H2>Sample Input</H2>
<pre>
3
3 4 5
5
1 2 5 5 5
6
195 221 255 260 265 290
6
130 145 169 185 195 265
3
1 1 2
6
3 3 3 3 3 3
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6
19
158253
-1
-1
18
</pre>
|
p01743 |
<p>
<var>m</var> é ç¹ã®å®å
šã°ã©ããããïŒæåïŒå®å
šã°ã©ãã®èŸºã«ã¯è²ã¯å¡ãããŠããªãïŒãã¬ãåã¯ïŒå <var>i</var>(1 ≤ <var>i</var> ≤ <var>n</var>) ã«ã€ããŠæ¬¡ã®æäœãè¡ã£ã: å®å
šã°ã©ããã <var>a<sub>i</sub></var> åã®é ç¹ãéžã³ïŒéžã°ããé ç¹å士ãçµã¶èŸºãã¹ãŠãè² <var>i</var> ã§ã¬ãïŒè€æ°åã®è²ãå¡ããã蟺ã¯ãªãã£ãïŒ<var>m</var> ãšããŠèããããæå°å€ãæ±ããïŒ
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>n</var> ≤ 5</li>
<li> 2 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>9</sup></li>
</ul>
<h2>Input</h2>
<pre>
<var>n</var>
<var>a<sub>1</sub></var>
. . .
<var>a<sub>n</sub></var>
</pre>
<h2>Output</h2>
<p>
<var>m</var> ã®æå°å€ãäžè¡ã«åºåããïŒ
</p>
<h2>Sample Input 1</h2>
<pre>
2
3
3
</pre>
<h2>Sample Output 1</h2>
<pre>
5
</pre>
<p>
ããšãã°ïŒé ç¹1, 2, 3, 4, 5 ãããªãã°ã©ãããã£ãå ŽåïŒæ¬¡ã®ããã«è²ãå¡ãããšãã§ããïŒ
</p>
<ul>
<li> é ç¹1, 2, 3 ãéžã³ãã®éãçµã¶èŸºãè²1 ã§ã¬ãïŒ</li>
<li> é ç¹1, 4, 5 ãéžã³ãã®éãçµã¶èŸºãè²2 ã§ã¬ãïŒ</li>
</ul>
<h2>Sample Input 2</h2>
<pre>
5
2
3
4
5
6
</pre>
<h2>Sample Output 2</h2>
<pre>
12
</pre>
|
p03284 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has decided to distribute <var>N</var> AtCoder Crackers to <var>K</var> users of as evenly as possible.
When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,K \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The crackers can be distributed evenly.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01313 |
<h1><font color="#000">Problem K:</font> Cat Numbers!</h1>
<p>
ããã®ã¢ãªã¹ããã¬ã¹ã¯æ°åŠã®åé¡ãèããã®ãè¶£å³ã«ããŠãããä»åœŒãèããŠããåé¡ã¯ä»¥äžã®ãããªãã®ã§ããã
</p>
<p>
1以äžã®èªç¶æ° <var>A</var>, <var>B</var> (<var>A</var> < <var>B</var>) ã«å¯ŸããŠã<var>A</var> ãã <var>B</var> ãŸã§ã®èªç¶æ°ã®åã <var>C</var>ã<var>A</var> ãš <var>B</var> ãåé²è¡šèšã㊠<var>A</var>, <var>B</var> ã®é ã«çµåãããã®ã <var>D</var> ãšãããšãäž¡è
ãçãããªãããšããããããšãã°1ãã5ãŸã§ã®åã¯15ã2ãã7ãŸã§ã®åã¯27ã7ãã119ãŸã§ã®å㯠7119ããšãã£ãå
·åã§ããããã®ãã㪠<var>A</var> ãš <var>B</var> ã®ãã¢ã®ããšã cat numbers ãšåŒã¶ããšã«ãããã¢ãªã¹ããã¬ã¹ã¯ã<var>A</var> ãš <var>B</var> ã®æ¡æ°ãäžãããããšãã«ãcat numbersãå
šãŠåæãããããšèããã
</p>
<p>
ã¢ãªã¹ããã¬ã¹ã¯ã<var>A</var> ãŸã㯠<var>B</var> ãåºå®ããå Žåã«è§£ãååšãããã©ããã確ãããæ¹æ³ã¯æãã€ããã®ã§ãå°ããæ¡æ°ã«å¯ŸããŠã¯çããåŸãããšãã§ãããããããæ¡æ°ã倧ãããªãã«ãããã£ãŠèšç®ãããã®ã倧å€ã«ãªããéäžã§ããããããŠæãåºããŠããŸã£ããããã§ãããªãã«ãé¡ãããããã¢ãªã¹ããã¬ã¹ã«ä»£ãã£ãŠãæå®ãããæ¡æ°ã®cat numbersãå
šãŠåæããããã°ã©ã ãæžããŠã»ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯1è¡ã®ã¿ãããªãã<var>A</var> ã®æ¡æ° <var>a</var> ããã³ <var>B</var> ã®æ¡æ° <var>b</var> ã1ã€ã®ç©ºçœæåã§åºåãããŠäžãããããããã㯠1 ≤ <var>a</var> ≤ <var>b</var> ≤ 16 ãæºããã
</p>
<h2>Output</h2>
<p>
æå®ãããæ¡æ°ã®cat numbersãã<var>A</var> ãå°ãããã®ããé ã«åºåããã<var>A</var> ãåããã®ãè€æ°ããå Žåã¯ã<var>B</var> ãå°ãããã®ããåºåãããåè¡ã«ã¯1ã€ã®cat numbersã«ããã <var>A</var> ãš <var>B</var> ã1ã€ã®ç©ºçœæåã§åºåã£ããã®ãåºåããããŸããæ¡ä»¶ã«åãcat numbersãååšããªãå Žå㯠"No cats." ãš1è¡ã«åºåããã
<h2>Notes on Submission</h2>
<p>
äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã
</p>
<h2>Sample Input</h2>
<pre>
4
1 1
1 3
1 4
2 2
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1 5
2 7
7 119
No cats.
13 53
18 63
33 88
35 91
</pre>
|
p00152 |
<H1>ããŠãªã³ã°</H1>
<p>
ã¯ã©ã¹ã®ã¬ã¯ãªãšãŒã·ã§ã³ãšããŠããŠãªã³ã°ãè¡ãããšã«ãªããŸãããåå è
ããšã®æçæ
å ±ãå
¥åãšããåŸç¹ã®é«ãé ã«æçžŸæ
å ±ãåºåããããã°ã©ã ãäœæããŠãã ããããªããåç¹ã®å Žåã¯åŠç±çªå·ã®è¥ãé ã«åºåããŠãã ããããã ãåå è
㯠3 åä»¥äž 40 å以äžãšãã1人åœãã1ã²ãŒã ãã€æçããŠãããã®ãšããŸãã
</p>
<p>
ããŠãªã³ã°ãšã¯ããã¬ã€ã€ãŒã«å¯ŸããŠé ç¹ãåããŠæ£äžè§åœ¢ã«äžŠã¹ãããã10 æ¬ã®ãã³ãããããŠããŒã«ã転ããããã³ãåãã¹ããŒãã§ãã 1 åç®ã®æçã§ãã¹ãŠè»¢åããå Žåãã¹ãã©ã€ã¯ãšèšãããã®æçã®ã¿ã§æ¬¡ã®ãã¬ãŒã ã«é²ã¿ãŸããã¹ãã©ã€ã¯ã§ãªãå Žåã¯ãæ®ã£ããã³ããã®ãŸãŸã«ã㊠2 åç®ã®æçãè¡ããŸãã2 åç®ã®æçã§ãã¹ãŠè»¢åããå Žåãã¹ãã¢ãšèšããŸãã2 åç®ã®æççµäºåŸã次ã®ãã¬ãŒã ã«é²ã¿ãŸãã
</p>
<p>
1 ã²ãŒã 㯠10 ã®ãã¬ãŒã ããæ§æããã第 1 ãã第 9 ã®åãã¬ãŒã 㯠2 åæçã§ããŸããåãã¬ãŒã ã®éå§æç¹ã§ã¯ã10 æ¬ã®ãã³ããã¹ãŠç«ã£ãç¶æ
ã§çšæãããŸãã第 10 ãã¬ãŒã ã¯ãã¹ãã©ã€ã¯ãããã¯ã¹ãã¢ãåºãå Žåã«ã¯èš 3 åã®æçãããã以å€ã®å Žå㯠2 åã®æçãè¡ããã²ãŒã çµäºãšãªããŸãã
</p>
<center>
ã¹ã³ã¢äŸïŒ<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bowling1">
<br><br>
ã¹ã³ã¢äŸïŒïŒæé«åŸç¹300ç¹ã®å ŽåïŒ<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bowling2"><br>
</center>
<br/>
<p>ã¹ã³ã¢èšç®ã®æ¹æ³</p>
<ul>
<li> åãã¬ãŒã ã«ãããŠã¹ãã¢ãã¹ãã©ã€ã¯ããªãå Žåã¯ã 2 åã®æçã§åãããã³ã®æ¬æ°ããã®ãã¬ãŒã ã®åŸç¹ãšãªããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 4 ãã¬ãŒã ãšç¬¬ 8 ãã¬ãŒã ïŒ</li>
<li>ã¹ãã¢ãåºããå Žåãåããæ¬æ°ã§ãã 10 ç¹ã«å ããæ¬¡ã®æçã§åãããã³ã®æ¬æ°ããã®ãã¬ãŒã ã®åŸç¹ã«å ç®ãããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 1 ãã¬ãŒã ãšç¬¬ 2 ãã¬ãŒã ã®é¢ä¿ãªã©ïŒã¹ã³ã¢äŸïŒã®ç¬¬ 1 ãã¬ãŒã ã§ã¯ç¬¬ 2 ãã¬ãŒã ã® 1 æã§åãã 10 æ¬ïŒç¹ïŒãå ãã 20 ç¹ãåŸç¹ãšãªããŸãã第 3 ãã¬ãŒã ãåæ§ã®èšç®æ¹æ³ã§ãã</li>
<li>ã¹ãã©ã€ã¯ãåºããå Žåãåããæ¬æ°ã§ãã 10 ç¹ã«å ããç¶ã 2 åã®æçã§åãããã³ã®æ¬æ°ãå ç®ãããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 2 ãã¬ãŒã ãšç¬¬ 3 ãã¬ãŒã ã®é¢ä¿ãªã©ïŒãã¡ããç¶ã 2 æäžã«ã¹ãã©ã€ã¯ã®å ŽåããããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 5 ãã¬ãŒã ãšç¬¬ 6ã7 ãã¬ãŒã ã®é¢ä¿ãªã©ïŒ</li>
<li>第 10 ãã¬ãŒã ã®ã¿ãã¹ãã¢ãã¹ãã©ã€ã¯ãåºããå Žåã3 æããŠåãããã³ã®ç·æ°ã第 10 ãã¬ãŒã ã®åŸç¹ãšããŠå ç®ãããŸãã</li>
<li>åãã¬ãŒã ã®åŸç¹ã®åèšã 1 ã²ãŒã ã®åŸç¹ãšãªããæé«åŸç¹ã¯ 300 ç¹ãšãªããŸãã</li>
</ul>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã</p>
<pre>
<var>m</var>
<var>score<sub>1</sub></var>
<var>score<sub>2</sub></var>
:
<var>score<sub>m</sub></var>
</pre>
<p>
1è¡ç®ã«åå è
æ° <var>m</var> ïŒ3 ≤ <var>m</var> ≤ 40ïŒãç¶ã<var>m</var> è¡ã«<var>i</var> 人ç®ã®åå è
æ
å ± <var>score<sub>i</sub></var> ãäžããããŸããååå è
æ
å ±ã¯ïŒè¡ãã€æ¬¡ã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>id</var> <var>s<sub>1</sub></var> <var>s<sub>2</sub></var> ... <var>s<sub>n</sub></var>
</pre>
<p>
å
é ã«åŠç±çªå·<var>id</var> (0 ≤ <var>id</var> ≤ 9999)ãç¶ããŠç¬¬ <var>j</var> æã®è»¢åãã³æ° <var>s<sub>j</sub></var> (0 ≤ <var>s<sub>j</sub></var> ≤ 10) ãäžããããŸããç·æçæ° <var>n</var> ã¯ã12 ä»¥äž 21 以äžã§ãããåŸç¹èšç®ã«å¿
èŠãªãã³æ°ãéäžè¶³ãªãäžãããããã®ãšããŸãã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãåŠç±çªå·ãšåŸç¹ããåŸç¹ã®é«ãé ïŒåç¹ã®å Žåã¯åŠç±çªå·ã®è¥ãé ïŒã«åºåããŸããåŠç±çªå·ãšåŸç¹ãïŒã€ã®ç©ºçœã§åºåã£ãŠïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
3
1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0
1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9
1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4
3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10
3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1
3335 10 10 10 10 10 10 10 10 10 10 10 10
3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1200 127
1010 123
1101 60
3335 300
3321 200
3340 175
3332 122
</pre>
|
p00502 |
<H1>æãæ¥ã
(Hot days) </H1>
<br/>
<h2> åé¡</h2>
<p>
æ¥æ¬ãå¬ã§ãããã®ææïŒååçã«ãããªãŒã¹ãã©ãªã¢ã§ã¯æãæ¥ãç¶ããŠããïŒãªãŒã¹ãã©ãªã¢ã«äœã IOI åã¯ïŒãã D æ¥éã®å€©æ°äºå ±ãããšã«ïŒçãæã®èšç»ãç«ãŠãããšã«ããïŒi æ¥ç® (1 ⊠i ⊠D) ã®æé«æ°æž©ã¯ T<sub>i</sub> 床ã§ãããšäºå ±ãããŠããïŒ
</p>
<p>
IOI å㯠N çš®é¡ã®æãæã£ãŠããïŒãããã«ã¯ 1 ãã N ãŸã§ã®çªå·ãã€ããŠããïŒæ j (1 ⊠j ⊠N) ã¯æé«æ°æž©ã A<sub>j</sub> åºŠä»¥äž B<sub>j</sub> 床以äžã®æ¥ã«çãã®ã«é©ããŠããïŒãŸãïŒããããã®æã«ã¯ã掟æãããšãã°ããæŽæ°ãå®ãŸã£ãŠããïŒæ j ã®æŽŸæã㯠C<sub>j</sub> ã§ããïŒ
</p>
<p>
D æ¥éã®ããããã«å¯ŸãïŒIOI åã¯ïŒæé«æ°æž©ã倩æ°äºå ±ã«åŸã£ããšãã«çãã®ã«é©ããæã®ãã¡ 1 ã€ãçãæãšããŠéžã¶ïŒåãæãäœåºŠéžãã§ããããïŒD æ¥éã§äžåºŠãéžã°ããªãæããã£ãŠãããïŒ
</p>
<p>
䌌ãŠããæãé£ç¶ããŠçãããšããªãã¹ãé¿ããããšæã£ã IOI åã¯ïŒé£ç¶ããæ¥ã«çãæã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã®åèšãã§ããã ã倧ããããããšèããïŒããªãã¡ïŒi æ¥ç®ã«æ x<sub>i</sub> ãéžãã ãšããŠïŒå€ |C<sub>x<sub>1</sub></sub> - C<sub>x<sub>2</sub></sub>| + |C<sub>x<sub>2</sub></sub> - C<sub>x<sub>3</sub></sub>| + ⊠+ |C<sub>x<sub>D-1</sub></sub> - C<sub>x<sub>D</sub></sub>| ãæå€§ã«ãããïŒãã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥å㯠1 + D + N è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯ïŒ2 ã€ã®æŽæ° D, N (2 ⊠D ⊠200ïŒ1 ⊠N ⊠200) ã空çœãåºåããšããŠæžãããŠããïŒD ã¯æã®èšç»ãç«ãŠãæ¥æ°ïŒN 㯠IOI åãæã£ãŠããæã®çš®é¡ã®æ°ã衚ãïŒ
</p>
<p>
ç¶ã D è¡ã®ãã¡ã® i è¡ç® (1 ⊠i ⊠D) ã«ã¯ïŒ1 ã€ã®æŽæ° T<sub>i</sub> (0 ⊠T<sub>i</sub> ⊠60) ãæžãããŠããïŒããã¯ïŒi æ¥ç®ã®æé«æ°æž©ã T<sub>i</sub> 床ã§ãããšäºå ±ãããŠããããšã衚ãïŒ
</p>
<p>
ç¶ã N è¡ã®ãã¡ã® j è¡ç® (1 ⊠j ⊠N) ã«ã¯ïŒ3 ã€ã®æŽæ° A<sub>j</sub>, B<sub>j</sub>, C<sub>j</sub> (0 ⊠A<sub>j</sub> ⊠B<sub>j</sub> ⊠60ïŒ0 ⊠C<sub>j</sub> ⊠100) ãæžãããŠããïŒãããã¯ïŒæ j ã¯æé«æ°æž©ã A<sub>j</sub> åºŠä»¥äž B<sub>j</sub> 床以äžã®æ¥ã«çãã®ã«é©ããŠããïŒæŽŸæãã C<sub>j</sub> ã§ããããšã衚ãïŒ
</p>
<p>
æé«æ°æž©ã倩æ°äºå ±ã«åŸã£ããšãã«çãã®ã«é©ããæãïŒD æ¥éã®ã©ã®æ¥ã«å¯ŸããŠã 1 ã€ä»¥äžååšããããšãä¿èšŒãããŠããïŒ
</p>
<h2> åºå</h2>
<p>
é£ç¶ããæ¥ã«çãæã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã®åèšïŒããªãã¡ïŒå€ |C<sub>x<sub>1</sub></sub> - C<sub>x<sub>2</sub></sub>| + |C<sub>x<sub>2</sub></sub> - C<sub>x<sub>3</sub></sub>| + ⊠+ |C<sub>x<sub>D-1</sub></sub> - C<sub>x<sub>D</sub></sub>| ã®æå€§å€ã 1 è¡ã§åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
3 4
31
27
35
20 25 30
23 29 90
21 35 60
28 33 40
</pre>
<h3>åºåäŸ 1</h3>
<pre>
80
</pre>
<p>
å
¥åºåäŸ 1 ã«ãããŠïŒ1 æ¥ç®ã®æã®åè£ã¯æ 3 ãšæ 4 ã§ããïŒ2 æ¥ç®ã®æã®åè£ã¯æ 2 ãšæ 3 ã§ããïŒ3 æ¥ç®ã®æã®åè£ã¯æ 3 ã®ã¿ã§ããïŒ1 æ¥ç®ã«æ 4 ãïŒ2 æ¥ç®ã«æ 2 ãïŒ3 æ¥ç®ã«æ 3 ãéžã¶ïŒããªãã¡ïŒx<sub>1</sub> = 4ïŒx<sub>2</sub> = 2ïŒx<sub>3</sub> = 3 ãšããïŒãã®ãšãïŒ1 æ¥ç®ãš 2 æ¥ç®ã®æã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã¯ |40 - 90| = 50 ã§ããïŒ2 æ¥ç®ãš 3 æ¥ç®ã®æã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã¯ |90 - 60| = 30 ã§ããïŒåèšã¯ 80 ãšãªãïŒãããæå€§å€ã§ããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
5 2
26
28
32
29
34
30 35 0
25 30 100
</pre>
<h3>åºåäŸ 2</h3>
<pre>
300
</pre>
<p>
å
¥åºåäŸ 2 ã«ãããŠïŒ1 æ¥ç®ã«ã¯æ 2 ãïŒ2 æ¥ç®ã«ã¯æ 2 ãïŒ3 æ¥ç®ã«ã¯æ 1 ãïŒ4 æ¥ç®ã«ã¯æ 2 ãïŒ5 æ¥ç®ã«ã¯æ 1 ãéžã°ãªããã°ãªããªãïŒãã®ãšãïŒæ±ããå€ã¯ |100 - 100| + |100 - 0| + |0 - 100| + |100 - 0| = 300 ãšãªãïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00017 |
<H1>Caesar Cipher</H1>
<p>
In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would become 'c', 'y' would become 'z', 'z' would become 'a', and so on. In that case, a text:
<pre>
this is a pen
</pre>
<p>
is would become:
</p>
<pre>
uijt jt b qfo
</pre>
<p>
Write a program which reads a text encrypted by Caesar Chipher and prints the corresponding decoded text. The number of shift is secret and it depends on datasets, but you can assume that the decoded text includes any of the following words: "the", "this", or "that".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset consists of texts in a line. Input ends with EOF. The text consists of lower-case letters, periods, space, and end-of-lines. Only the letters have been encrypted. A line consists of at most 80 characters.
</p>
<p>
You may assume that you can create one decoded text which includes any of "the", "this", or "that" from the given input text.
</p>
<p>
The number of datasets is less than or equal to 20.
</p>
<H2>Output</H2>
<p>
Print decoded texts in a line.
</p>
<H2>Sample Input</H2>
<pre>
xlmw mw xli tmgxyvi xlex m xsso mr xli xvmt.
</pre>
<H2>Output for the Sample Input</H2>
<pre>
this is the picture that i took in the trip.
</pre>
|
p02180 | <h1>F: å鿢ã</h1>
<h2>åé¡</h2>
<p>
$1$ ãã $N$ ãŸã§ã®çªå·ãä»ãããã $N$ 人ã®äººã«å¯ŸããŠïŒããéšå±ã®å
¥é宀èšé²ã $M$ åäžããããïŒ <br>
$i$ çªç®ã®å
¥é宀èšé²ã¯ $A_i\ B_i\ C_i$ ã® $3$ ã€ã®æŽæ°ãããªãïŒããã¯ä»¥äžã瀺ããŠããïŒ<br>
<ul>
<li>$C_i = 1$ ã®ãšãïŒæå» $A_i$ ã« $B_i$ ãããéšå±ã«å
¥å®€ããããšã衚ã.</li>
<li>$C_i = 0$ ã®ãšãïŒæå» $A_i$ ã« $B_i$ ãããéšå±ããé宀ããããšã衚ã.</li>
</ul>
</p>
<p>
$i$ çªç®($1 \leq i \leq N$)ã®äººã«ã€ããŠïŒæå» $T$ ãŸã§ã«éšå±ã§äžç·ã«éãããæéãæãé·ã人ãçããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åå€ã¯å
šãп޿°ã§ãã.</li>
<li>$2 \leq N,\ M \leq 10^5$</li>
<li>$1 \leq T \leq 10^9$</li>
<li>$1 \leq A_i \leq T$</li>
<li>$A_i \leq A_{i+1}$</li>
<li>$1 \leq B_i \leq N$</li>
<li>$(A_i = A_j$ ã〠$B_i = B_j$) ãªãã° $i=j$</li>
<li>$0 \leq C_i \leq 1$</li>
<li>æå» $0$ ã«ã¯éšå±ã«èª°ãããªã</li>
<li>å
¥é宀ãççŸããå
¥åã¯äžããããªã</li>
<li><b>éšå±ã« $100$ 人ããå€ãã®äººãããããšã¯ãªã</b></li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. </p>
<p>
$N\ M\ T$<br>
$A_1\ B_1\ C_1$<br>
âŠ<br>
$A_M\ B_M\ C_M$<br>
</p>
<h2>åºå</h2>
<p>
$i$ è¡ç®ã«ã¯ $i$ çªç®ã®äººã«ã€ããŠïŒæå» $T$ ãŸã§ã«éšå±ã§äžç·ã«éãããæéãæãé·ã人ãåºåããïŒ<br>
ãã ãïŒèªå以å€ã§äžç·ã«éãããæéãæãé·ã人ãè€æ°äººããå Žåã¯ïŒæãå°ããçªå·ã®äººãåºåããïŒ<br>
ãŸãïŒåè¡ã®æ«å°Ÿã«æ¹è¡ãåºåããïŒ
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
3 6 10
1 1 1
2 2 1
4 3 1
5 1 0
6 2 0
6 3 0
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
2
1
2
</pre>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
3 2 5
1 1 1
2 2 1
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
2
1
1
</pre>
<p>
$3$ çªç®ã®äººã¯ïŒ$1$ çªç®ã®äººãšã $2$ çªç®ã®äººãšãäžç·ã«ããæéã $0$ ãªã®ã§ïŒæãå°ãã $1$ ãåºåãã.
</p>
|
p00447 |
<H1>æåº§æ¢ã </H1>
<h2>åé¡</h2>
<p>
ããªãã¯æç©ºã®åçã®äžããæåº§ãæ¢ããŠããïŒåçã«ã¯å¿
ãïŒæ¢ãããæåº§ãšåã圢ã»åãã»å€§ããã®å³åœ¢ãã¡ããã©äžã€å«ãŸããŠããïŒãã ãïŒåçã®äžã«ã¯æåº§ãæ§æããæä»¥å€ã«äœåãªæãåã£ãŠããå¯èœæ§ãããïŒ
</p>
<p>
äŸãã°ïŒå³ 1 ã®æåº§ã¯å³ 2 ã®åçã«å«ãŸããŠããïŒäžžã§å²ãã§ç€ºããïŒïŒäžããããæåº§ã®æã®åº§æšã x æ¹åã« 2ïŒ y æ¹åã« â3 ã ãå¹³è¡ç§»åãããšåçã®äžã®äœçœ®ã«ãªãïŒ
</p>
<p>
æ¢ãããæåº§ã®åœ¢ãšåçã«åã£ãŠããæã®äœçœ®ãäžãããããšãïŒæåº§ã®åº§æšãåçã®äžã®åº§æšã«å€æããããã«å¹³è¡ç§»åããã¹ãéãçããããã°ã©ã ãæžãïŒ
</p>
<table style="margin-left: 30px; margin-right: 30px; text-align: center;">
<col><col>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_constellation1" width="270" height="270"></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_constellation2" width="270" height="270"></td></tr>
<tr><td>å³ 1: æ¢ãããæåº§</td><td>å³ 2: æç©ºã®åç</td></tr>
</table>
<br>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
å
¥åã® 1 è¡ç®ã«ã¯æ¢ãããæåº§ãæ§æããæã®åæ° <i>m</i> ãæžãããŠããïŒç¶ã <i>m</i> è¡ã«ã¯æ¢ãããæåº§ãæ§æãã <i>m</i> åã®æã® x 座æšãš y 座æšãç€ºãæŽæ°ã空çœåºåãã§æžãããŠããïŒ <i>m</i>+2 è¡ç®ã«ã¯åçã«åã£ãŠããæã®åæ° <i>n</i> ãæžãããŠããïŒç¶ã <i>n</i> è¡ã«ã¯åçã«åã£ãŠãã <i>n</i> åã®æã® x 座æšãš y 座æšãç€ºãæŽæ°ã空çœåºåãã§æžãããŠããïŒ
</p>
<p>
æåº§ãæ§æãã <i>m</i> åã®æã®äœçœ®ã¯ãã¹ãŠç°ãªãïŒãŸãïŒåçã«åã£ãŠãã <i>n</i> åã®æã®äœçœ®ã¯ãã¹ãŠç°ãªãïŒ 1 ≤ <i>m</i> ≤ 200ïŒ 1 ≤ <i>n</i> ≤ 1000 ã§ããïŒæã® x 座æšãš y 座æšã¯ãã¹ãŠ 0 ä»¥äž 1000000 以äžã§ããïŒ
</p>
<p>
<i>m</i> ã 0ãã®ãšãå
¥åã®çµããã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
<!--æåºããåºåãã¡ã€ã«-->åããŒã¿ã»ããã®åºå㯠1 è¡ãããªãïŒ 2 åã®æŽæ°ã空çœåºåãã§æžãïŒãããã¯æ¢ãããæåº§ã®åº§æšãã©ãã ãå¹³è¡ç§»åããã°åçã®äžã®åº§æšã«ãªããã衚ãïŒæåã®æŽæ°ã x æ¹åã«å¹³è¡ç§»åããéïŒæ¬¡ã®æŽæ°ã y æ¹åã«å¹³è¡ç§»åããéã§ããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0
</pre>
<h3>åºåäŸ</h3>
<pre>
2 -3
-384281 179674
</pre>
<p>
å
¥åºåäŸã®ïŒã€ç®ã¯äžã®å³ã«å¯Ÿå¿ããŠããïŒ
</p>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02929 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>2N</var> squares arranged from left to right. You are given a string of length <var>2N</var> representing the color of each of the squares.</p>
<p>The color of the <var>i</var>-th square from the left is black if the <var>i</var>-th character of <var>S</var> is <code>B</code>, and white if that character is <code>W</code>.</p>
<p>You will perform the following operation exactly <var>N</var> times: choose two distinct squares, then invert the colors of these squares and the squares between them. Here, to invert the color of a square is to make it white if it is black, and vice versa. </p>
<p>Throughout this process, you cannot choose the same square twice or more. That is, each square has to be chosen exactly once.</p>
<p>Find the number of ways to make all the squares white at the end of the process, modulo <var>10^9+7</var>.</p>
<p>Two ways to make the squares white are considered different if and only if there exists <var>i</var> <var>(1 \leq i \leq N)</var> such that the pair of the squares chosen in the <var>i</var>-th operation is different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>|S| = 2N</var></li>
<li>Each character of <var>S</var> is <code>B</code> or <code>W</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 number of ways to make all the squares white at the end of the process, modulo <var>10^9+7</var>. If there are no such ways, print <var>0</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
BWWB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four ways to make all the squares white, as follows:</p>
<ul>
<li>Choose Squares <var>1, 3</var> in the first operation, and choose Squares <var>2, 4</var> in the second operation.</li>
<li>Choose Squares <var>2, 4</var> in the first operation, and choose Squares <var>1, 3</var> in the second operation.</li>
<li>Choose Squares <var>1, 4</var> in the first operation, and choose Squares <var>2, 3</var> in the second operation.</li>
<li>Choose Squares <var>2, 3</var> in the first operation, and choose Squares <var>1, 4</var> in the second operation.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
BWBBWWWB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>288
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
WWWWWWWWWW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p00914 |
<H1><font color="#000">Problem A: </font>Equal Sum Sets</H1>
<p>
Let us consider sets of positive integers less than or equal to <var>n</var>. Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set.
</p>
<p>
Specifying the number of set elements and their sum to be <var>k</var> and <var>s</var>, respectively, sets satisfying the conditions are limited. When <var>n</var> = 9, <var>k</var> = 3 and <var>s</var> = 23, {6, 8, 9} is the only such set. There may be more than one such set, in general, however. When <var>n</var> = 9, <var>k</var> = 3 and <var>s</var> = 22, both {5, 8, 9} and {6, 7, 9} are possible.
</p>
<p>
You have to write a program that calculates the number of the sets that satisfy the given conditions.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. The number of datasets does not exceed 100.
</p>
<p>
Each of the datasets has three integers <var>n</var>, <var>k</var> and <var>s</var> in one line, separated by a space. You may assume 1 ≤ <var>n</var> ≤ 20, 1 ≤ <var>k</var> ≤ 10 and 1 ≤ <var>s</var> ≤ 155.
</p>
<p>
The end of the input is indicated by a line containing three zeros.
</p>
<H2>Output</H2>
<p>
The output for each dataset should be a line containing a single integer that gives the number of the sets that satisfy the conditions. No other characters should appear in the output.
</p>
<p>
You can assume that the number of sets does not exceed 2<sup>31</sup> - 1.
</p>
<H2>Sample Input</H2>
<pre>
9 3 23
9 3 22
10 3 28
16 10 107
20 8 102
20 10 105
20 10 155
3 4 3
4 2 11
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
2
0
20
1542
5448
1
0
0
</pre> |
p01606 |
<h2>Sliding GCD</h2>
<h2>Problem Statement</h2>
<p>èªç¶æ°ã®éå <var>S</var> ã«å¯ŸããŠïŒéå <var>\{ GCD(T) | T â S, T ã¯ç©ºã§ãªã \}</var> ã®èŠçŽ æ°ã <var>f(S)</var> ãšããïŒ</p>
<p>ããã§ïŒ<var>GCD(T)</var> 㯠<var>T</var> ã«å«ãŸãããã¹ãŠã®æ°ãå²ãåããããªæå€§ã®æŽæ°ã§ããïŒ<br />
ç¹ã«ïŒ<var>T</var> ãäžã€ã®æŽæ° <var>a</var> ã®ã¿ãããªããšã㯠<var>GCD(\{a\}) = a</var> ã§ããããšã«æ³šæããïŒ</p>
<p><var>i = 1, 2, . . ., N - W+1</var> ã«å¯Ÿã㊠<var>f(\{i, i+1, . . ., i+W - 1\})</var> ãæ±ããïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ</p>
<pre><var>N</var> <var>W</var></pre>
<h2>Constraints</h2>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1 ⊠W ⊠N ⊠10^5</var></li></ul>
<h2>Output</h2>
<p><var>i = 1, 2, . . ., N-W+1</var> ã®ãšãã® <var>f(\{i, i+1, . . ., i+W-1\})</var> ã®å€ãåè§ã¹ããŒã¹åºåãã§ 1 è¡ã«åºåããïŒ</p>
<h2>Sample Input 1</h2>
<pre>10 2</pre>
<h2>Output for the Sample Input 1</h2>
<pre>2 3 3 3 3 3 3 3 3</pre>
<p><var>GCD(\{1\}) = 1, GCD(\{2\}) = 2, GCD(\{1,2\}) = 1</var> ãšãªããã <var>f(\{1,2\}) = 2</var> ã§ããïŒ</p>
<h2>Sample Input 2</h2>
<pre>30 7</pre>
<h2>Output for the Sample Input 2</h2>
<pre>7 8 9 10 10 11 11 11 11 12 11 12 10 12 12 11 10 12 12 12 10 11 11 13</pre>
|
p02883 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi will take part in an eating contest. Teams of <var>N</var> members will compete in this contest, and Takahashi's team consists of <var>N</var> players numbered <var>1</var> through <var>N</var> from youngest to oldest. The <em>consumption coefficient</em> of Member <var>i</var> is <var>A_i</var>.</p>
<p>In the contest, <var>N</var> foods numbered <var>1</var> through <var>N</var> will be presented, and the <em>difficulty</em> of Food <var>i</var> is <var>F_i</var>. The details of the contest are as follows:</p>
<ul>
<li>A team should assign one member to each food, and should not assign the same member to multiple foods.</li>
<li>It will take <var>x \times y</var> seconds for a member to finish the food, where <var>x</var> is the consumption coefficient of the member and <var>y</var> is the difficulty of the dish.</li>
<li>The score of a team is the longest time it takes for an individual member to finish the food.</li>
</ul>
<p>Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by <var>1</var>, as long as it does not go below <var>0</var>. However, for financial reasons, the <var>N</var> members can do at most <var>K</var> sets of training in total.</p>
<p>What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?</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 2 \times 10^5</var></li>
<li><var>0 \leq K \leq 10^{18}</var></li>
<li><var>1 \leq A_i \leq 10^6\ (1 \leq i \leq N)</var></li>
<li><var>1 \leq F_i \leq 10^6\ (1 \leq 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>...</var> <var>A_N</var>
<var>F_1</var> <var>F_2</var> <var>...</var> <var>F_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the minimum possible score of the team.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
4 2 1
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>They can achieve the score of <var>2</var>, as follows:</p>
<ul>
<li>Member <var>1</var> does <var>4</var> sets of training and eats Food <var>2</var> in <var>(4-4) \times 3 = 0</var> seconds.</li>
<li>Member <var>2</var> does <var>1</var> set of training and eats Food <var>3</var> in <var>(2-1) \times 1 = 1</var> second.</li>
<li>Member <var>3</var> does <var>0</var> sets of training and eats Food <var>1</var> in <var>(1-0) \times 2 = 2</var> seconds.</li>
</ul>
<p>They cannot achieve a score of less than <var>2</var>, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 8
4 2 1
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>They can choose not to do exactly <var>K</var> sets of training.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>12
</pre></section>
</div>
</span> |
p03791 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are developing frog-shaped robots, and decided to race them against each other.</p>
<p>First, you placed <var>N</var> robots onto a number line.
These robots are numbered <var>1</var> through <var>N</var>.
The current coordinate of robot <var>i</var> is <var>x_i</var>.
Here, all <var>x_i</var> are integers, and <var>0 < x_1 < x_2 < ... < x_N</var>.</p>
<p>You will repeatedly perform the following operation:</p>
<ul>
<li>Select a robot on the number line. Let the coordinate of the robot be <var>x</var>. Select the destination coordinate, either <var>x-1</var> or <var>x-2</var>, that is not occupied by another robot. The robot now jumps to the selected coordinate.</li>
</ul>
<p>When the coordinate of a robot becomes <var>0</var> or less, the robot is considered finished and will be removed from the number line immediately.
You will repeat the operation until all the robots finish the race.</p>
<p>Depending on your choice in the operation, the <var>N</var> robots can finish the race in different orders.
In how many different orders can the <var>N</var> robots finish the race?
Find the answer modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †10^5</var></li>
<li><var>x_i</var> is an integer.</li>
<li><var>0 < x_1 < x_2 < ... < x_N †10^9</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In a test set worth <var>500</var> points, <var>N †8</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_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different orders in which the <var>N</var> robots can finish the race, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four different orders in which the three robots can finish the race:</p>
<ul>
<li><var>(</var>Robot <var>1 â</var> Robot <var>2 â</var> Robot <var>3)</var></li>
<li><var>(</var>Robot <var>1 â</var> Robot <var>3 â</var> Robot <var>2)</var></li>
<li><var>(</var>Robot <var>2 â</var> Robot <var>1 â</var> Robot <var>3)</var></li>
<li><var>(</var>Robot <var>2 â</var> Robot <var>3 â</var> Robot <var>1)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
<p>There are six different orders in which the three robots can finish the race:</p>
<ul>
<li><var>(</var>Robot <var>1 â</var> Robot <var>2 â</var> Robot <var>3)</var></li>
<li><var>(</var>Robot <var>1 â</var> Robot <var>3 â</var> Robot <var>2)</var></li>
<li><var>(</var>Robot <var>2 â</var> Robot <var>1 â</var> Robot <var>3)</var></li>
<li><var>(</var>Robot <var>2 â</var> Robot <var>3 â</var> Robot <var>1)</var></li>
<li><var>(</var>Robot <var>3 â</var> Robot <var>1 â</var> Robot <var>2)</var></li>
<li><var>(</var>Robot <var>3 â</var> Robot <var>2 â</var> Robot <var>1)</var></li>
</ul>
<p>For example, the order <var>(</var>Robot <var>3 â</var> Robot <var>2 â</var> Robot <var>1)</var> can be achieved as shown in the figure below:</p>
<div style="text-align: center;">
<img alt="a55aed48a00614569d4844f39807e2fb.png" src="https://atcoder.jp/img/mujin/a55aed48a00614569d4844f39807e2fb.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
1 2 3 5 7 11 13 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10080
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>13
4 6 8 9 10 12 14 15 16 18 20 21 22
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>311014372
</pre>
<p>Remember to print the answer modulo <var>10^9+7</var>.
This case is not included in the test set for the partial score.</p></section>
</div>
</span> |
p01256 |
<H1><font color="#000">Problem G:</font> Time Trial</H1>
<p>
Some people like finishing computer games in an extremely short time. Terry A. Smith is one of such
and prefers role playing games particularly.
</p>
<p>
He is now trying to find a shorter play for one of the key events in a role playing game. In this event,
a player is presented a kind of puzzle on a grid map with three rocks and three marked squares. The
objective is to have all the rocks placed on the marked squares by controlling the hero of this game
appropriately.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_timeTrial">
<p>Figure 1: Example Map</p>
</center>
<p>
The hero can move to the four adjacent squares, that is, to the north, east, south, and west, unless his move
is blocked by walls or rocks. He can never enter squares occupied by walls. On the other hand, when he
is moving to a square occupied by a rock, he pushes the rock in his moving direction. Nonetheless, he
cannot push the rock if the next square is occupied by a wall or another rock and his move is blocked in
this case. Also, he can only move one rock at a time. It is allowed to have rocks pass through marked
squares.
</p>
<p>
Terry thinks he can reduce his playing time by finding the optimal way to move the rocks and then playing
the event accordingly. However, it is too hard for him to find the solution of this puzzle by hand. So you
are asked by him to write a program that finds the smallest number of steps for the maps given as the
input. Here, each move from a square to its adjacent square is counted as one step.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset has the following format:
</p>
<pre>
<i>W H</i>
<i>Row</i><sub>1</sub>
...
<i>Row<sub>H</sub></i>
</pre>
<p>
<i>W</i> and <i>H</i> are the width and height of the map (4 ≤ <i>W</i>, <i>H</i> ≤ 16). <i>Row</i><sub>i</sub> denotes the <i>i</i>-th row of the map
and consists of <i>W</i> characters. Each character represents a square and is one of the following: â<span>#</span>â (wall), â<span>.</span>â (floor), â<span>*</span>â (rock), â<span>_</span>â (marked square), and â<span>@</span>â (hero). Each map contains exactly three rocks, three
marked squares, and one hero. The outermost squares are always occupied by walls. You may assume
that the number of non-wall squares does not exceed fifty. It is also guaranteed that there is at least one
solution for every map.
</p>
<p>
The input is terminated by a line with two zeros. This line is not part of any datasets and should not be
processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the smallest number of steps in a line.
</p>
<H2>Sample Input</H2>
<pre>
7 6
#######
#.._..#
#.*.*.#
#.@.*.#
#_..._#
#######
10 13
##########
####___###
####...###
####...###
#####.####
#.....#..#
#.#*.*.*.#
#...###..#
###.#.#.##
###.#.#.##
###.....##
###..@..##
##########
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
15
118
</pre>
|
p03545 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Sitting in a station waiting room, Joisino is gazing at her train ticket.</p>
<p>The ticket is numbered with four digits <var>A</var>, <var>B</var>, <var>C</var> and <var>D</var> in this order, each between <var>0</var> and <var>9</var> (inclusive).</p>
<p>In the formula <var>A</var> <var>op1</var> <var>B</var> <var>op2</var> <var>C</var> <var>op3</var> <var>D</var> <var>=</var> <var>7</var>, replace each of the symbols <var>op1</var>, <var>op2</var> and <var>op3</var> with <code>+</code> or <code>-</code> so that the formula holds.</p>
<p>The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0â€A,B,C,Dâ€9</var></li>
<li>All input values are integers.</li>
<li>It is guaranteed that there is a solution.</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>ABCD</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the formula you made, including the part <code>=7</code>.</p>
<p>Use the signs <code>+</code> and <code>-</code>.</p>
<p>Do not print a space between a digit and a sign.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1222
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1+2+2+2=7
</pre>
<p>This is the only valid solution.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0290
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0-2+9+0=7
</pre>
<p><var>0 - 2 + 9 - 0 = 7</var> is also a valid solution.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3242
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3+2+4-2=7
</pre></section>
</div>
</span> |
p01578 |
<H1><font color="#000">Problem I:</font> Sort by Hand</H1>
<p>
It's time to arrange the books on your bookshelf. There are <i>n</i> books in the shelf and each book has a unique number; you want to sort the books according to the numbers. You know that the quick sort and the merge sort are fast sorting methods, but it is too hard for you to simulate them by hand - they are efficient for computers, but not for humans. Thus, you decided to sort the books by inserting the book with the number <i>i</i> into the <i>i</i>-th position. How many insertions are required to complete this task?
</p>
<H2>Input</H2>
<p>
The first line of the input is <i>n</i> (1 ≤ <i>n</i> ≤ 20), which is the number of books. The second line contains <i>n</i> integers <i>v</i><sub>1</sub>, ... , <i>v<sub>n</sub></i> (1 ≤ <i>v<sub>i</sub></i> ≤ <i>n</i>), where <i>v<sub>i</sub></i> indicates the number of the book at the <i>i</i>-th position before the sorting. All <i>v<sub>i</sub></i>'s are distinct.
</p>
<H2>Output</H2>
<p>
Print the minimum number of insertions in a line. If it is impossible for him to complete the sort, print "impossible" (without quotes).
</p>
<H2>Sample Input 1</H2>
<pre>
3
1 2 3
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
0
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
3
2 1 3
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
1
</pre>
<br/>
<H2>Sample Input 3</H2>
<pre>
3
3 2 1
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
2
</pre>
<br/>
<H2>Sample Input 4</H2>
<pre>
20
4 14 11 13 17 10 1 12 2 6 16 15 8 7 19 18 3 5 9 20
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>
14
</pre>
|
p01082 |
<h1>Problem K: Escape of Lappin the Phantom Thief</h1>
<h2>Problem</h2>
<p>
æªçã©ããã³ã¯å®ç³ãçã¿ã«ãã£ãŠãããç°¡åã«å®ç³ãæã«ããããšãã§ããããå®ç³ã«ã¯ã»ã³ãµãŒãä»èŸŒãŸããŠãããèŠåããããã«å²ãŸããŠããŸã£ãã
</p>
<p>
èŠåããããã¯å®ç³ã«åãã£ãŠç§»åããããã«ä»çµãŸããŠãããã»ã³ãµãŒã¯ç°¡åã«å€ãããã«ãªãã£ãã®ã§ãå®ç³ã眮ããŠéèµ°ããããšã«ãããå®ç³ãã§ããã ãèŠåããããããé ãã«çœ®ããŠãéããããã®æé皌ããããããšã«ããã
</p>
<p>
æ·å°ã¯<var>n</var> × <var>m</var>ã®ãã¹ãããªãé·æ¹åœ¢ã®åœ¢ãããŠããŠãé害ç©ã¯ãªãã
<var>k</var>äœã®èŠåããããã¯ããããããã¹(<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>)(0 ≤ <var>x<sub>i</sub></var> ≤ <var>n</var>−1, 0 ≤ <var>y<sub>i</sub></var> ≤ <var>m</var>−1)ã«é
眮ãããŠãããäžäžå·Šå³ã®ãã¹ã«åäœæéã§ç§»åã§ããã
èŠåããããã¯å®ç³ããããã¹ã«æççµè·¯ã§ç§»åããã
</p>
<p>
æ·å°å
ã«èªç±ã«å®ç³ã眮ãããšãã1å°ä»¥äžã®èŠåãããããå®ç³ã®ãããã¹ã«å°éãããŸã§ã«ãããç§»åæéã®æå€§å€ãæ±ããã
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var> <var>k</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
...
<var>x<sub>k</sub></var> <var>y<sub>k</sub></var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«<var>n</var>, <var>m</var>, <var>k</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ä»¥é<var>k</var>è¡ã«èŠåããããã®ãããã¹ã®åº§æš(<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>)ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>n</var>, <var>m</var> ≤ 5 × 10<sup>4</sup></li>
<li>1 ≤ <var>k</var> ≤ min(10<sup>5</sup>, <var>n</var> × <var>m</var>)</li>
<li>0 ≤ <var>x<sub>i</sub></var> ≤ <var>n</var>−1</li>
<li>0 ≤ <var>y<sub>i</sub></var> ≤ <var>m</var>−1</li>
<li>äžãããã座æšã¯ãã¹ãŠç°ãªã</li>
</ul>
<h2>Output</h2>
<p>
èŠåãããããå°éãããŸã§ã«ãæãæéããããå Žæãžã®ç§»åæéã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
20 10 1
0 0
</pre>
<h2>Sample Output 1</h2>
<pre>
28
</pre>
<h2>Sample Input 2</h2>
<pre>
20 10 2
0 0
17 5
</pre>
<h2>Sample Output 2</h2>
<pre>
15
</pre>
<h2>Sample Input 3</h2>
<pre>
20 10 3
0 0
17 5
6 9
</pre>
<h2>Sample Output 3</h2>
<pre>
11
</pre> |
p03115 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an infinitely large triangular grid, as shown below.
Each point with integer coordinates contains a lamp.</p>
<p><img alt="" src="https://img.atcoder.jp/wtf19/f617c94527a62ed72fe7db12b6d1f6b0.png"/></p>
<p>Initially, only the lamp at <var>(X, 0)</var> was on, and all other lamps were off.
Then, Snuke performed the following operation zero or more times:</p>
<ul>
<li>Choose two integers <var>x</var> and <var>y</var>.
Toggle (on to off, off to on) the following three lamps: <var>(x, y), (x, y+1), (x+1, y)</var>.</li>
</ul>
<p>After the operations, <var>N</var> lamps <var>(x_1, y_1), \cdots, (x_N, y_N)</var> are on, and all other lamps are off.
Find <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>-10^{17} \leq x_i, y_i \leq 10^{17}</var></li>
<li><var>(x_i, y_i)</var> are pairwise distinct.</li>
<li>The input is consistent with the statement, and you can uniquely determine <var>X</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>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 <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
-2 1
-2 2
0 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-1
</pre>
<p>The following picture shows one possible sequence of operations:</p>
<p><img alt="" src="https://img.atcoder.jp/wtf19/cff6dc4d81e995e9300ccbaca5bf85de.png"/></p></section>
</div>
</span> |
p01128 |
<h1>Railroad Conflict</h1>
<p>
Nate U. Smith ã¯å€§éœåžåã®ééäŒç€Ÿãçµå¶ããŠããïŒãã®å€§éœåžåã«ã¯ïŒåœŒã®ééäŒç€Ÿä»¥å€ã«ã©ã€ãã«ã®ééäŒç€ŸãããïŒ2 瀟ã¯äºãã«ç«¶åé¢ä¿ã«ããïŒ
</p>
<p>
ãã®å€§éœåžåã§ã¯ïŒåè»ã®éè¡ã容æã«ããããïŒå
šãŠã®è·¯ç·ã¯äž¡ç«¯ã®é§
ãçµãã ç·åãçµè·¯ãšããŠããïŒãŸãïŒèžåçã®èšçœ®ããããããïŒå
šãŠã®è·¯ç·ã¯é«æ¶ãŸãã¯å°äžã«æ·èšãããŠããïŒæ¢åè·¯ç·ã¯ïŒå
šç·ã«ããã£ãŠé«æ¶ãèµ°ããïŒãŸãã¯å
šç·ã«ããã£ãŠå°äžãèµ°ããã®ããããã§ããïŒ
</p>
<p>
ãšããã§ïŒæè¿ïŒãã®å€§éœåžåã«ãã 2 ã€ã®è¡åº AïŒB ããããã«éçºãããŠããããšããïŒNate ã®äŒç€Ÿã§ã¯ãããã®è¡åºã®éã«æ°ããè·¯ç·ãèšããããšã決æããïŒãã®æ°è·¯ç·ã¯ïŒåŸæ¥ã®è·¯ç·ãšåæ§ã« AïŒB ã䞡端ãšããç·åãçµè·¯ãšããããïŒçµè·¯ã®éäžã«ã¯å¥ã®è·¯ç·ãããããšããïŒé«æ¶ãããã¯å°äžã®ããããã«å
šç·ãæ·èšããããšã¯äžå¯èœã§ããïŒããã§ïŒè·¯ç·ã®äžéšã髿¶ã«ïŒæ®ãã®éšåãå°äžã«æ·èšããããšã«ããïŒãã®ãšãïŒæ°è·¯ç·ãèªç€Ÿã®æ¢åè·¯ç·ãšäº€ãããšããã§ã¯ïŒæ°è·¯ç·ãšæ¢åè·¯ç·ãšã®éã®ä¹ãç¶ãã䟿å©ã«ããããïŒæ¢åè·¯ç·ã髿¶ãªãã°æ°è·¯ç·ã髿¶ã«ïŒæ¢åè·¯ç·ãå°äžãªãã°æ°è·¯ç·ãå°äžãèµ°ãããã«ããïŒãŸãïŒæ°è·¯ç·ãä»ç€Ÿã®æ¢åè·¯ç·ãšäº€ãããšããã§ã¯ïŒä»ç€Ÿã«ãã劚害ããããããïŒæ¢åè·¯ç·ã髿¶ãªãã°æ°è·¯ç·ã¯å°äžã«ïŒæ¢åè·¯ç·ãå°äžãªãã°æ°è·¯ç·ã¯é«æ¶ãèµ°ãããã«ããïŒA é§
ããã³ B é§
ããããã髿¶ãããã¯å°äžã®ãããã«èšãããã¯ç¹ã«åããªãïŒ
</p>
<p>
åœç¶ã®ããšãªããïŒæ°è·¯ç·ã髿¶ããå°äžã«ïŒãããã¯å°äžãã髿¶ã«ç§»ããšããã«ã¯åºå
¥å£ãèšããªããã°ãªããªãïŒãšãããïŒåºå
¥å£ãèšããããã«ã¯è²»çšããããããïŒæ°è·¯ç·ã«èšããåºå
¥å£ã®åæ°ã¯æå°éã«æãããïŒããã«ã¯ïŒããã°ã©ãã§ããããªãã®å©ããèŠãããšèãã Nate ã¯ïŒããªãã圌ã®äŒç€Ÿã«åŒã³åºããïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒA é§
ïŒB é§
ã®äœçœ®ïŒãããŠæ¢åè·¯ç·ã«é¢ããæ
å ±ãäžãããããšãã«ïŒæ°è·¯ç·ã«ãããŠæäœéèšããªããã°ãªããªãåºå
¥å£ã®åæ°ãæ±ããããã°ã©ã ãäœæããããšã§ããïŒ
</p>
<p>
以äžã®å³ã¯ïŒãµã³ãã«ãšããŠäžããå
¥åããã³åºåã®å
容ã瀺ãããã®ã§ããïŒ
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_rail1"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_rail2">
</p>
<h3>Input</h3>
<p>
å
¥åã®å
é è¡ã«ã¯åäžã®æ£ã®æŽæ°ãå«ãŸãïŒããã¯ããŒã¿ã»ããã®åæ°ã衚ãïŒããããã®ããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ
<blockquote>
<i>xa</i> <i>ya</i> <i>xb</i> <i>yb</i><br>
<i>n</i><br>
<i>xs</i><sub>1</sub> <i>ys</i><sub>1</sub> <i>xt</i><sub>1</sub> <i>yt</i><sub>1</sub> <i>o</i><sub>1</sub> <i>l</i><sub>1</sub><br>
<i>xs</i><sub>2</sub> <i>ys</i><sub>2</sub> <i>xt</i><sub>2</sub> <i>yt</i><sub>2</sub> <i>o</i><sub>2</sub> <i>l</i><sub>2</sub><br>
...<br>
<i>xs</i><sub><i>n</i></sub> <i>ys</i><sub><i>n</i></sub> <i>xt</i><sub><i>n</i></sub> <i>yt</i><sub><i>n</i></sub> <i>o</i><sub><i>n</i></sub> <i>l</i><sub><i>n</i></sub><br>
</blockquote>
ãã ãïŒ(<i>xa</i>,<i>ya</i>) ããã³ (<i>xb</i>,<i>yb</i>) ã¯ãããã A é§
ïŒB é§
ã®åº§æšã衚ãïŒ<i>N</i> ã¯æ¢åè·¯ç·ã®æ°ã衚ã 100 以äžã®æ£ã®æŽæ°ã§ããïŒ(<i>xs</i><sub><i>i</i></sub>,<i>ys</i><sub><i>i</i></sub>) ããã³ (<i>ys</i><sub><i>i</i></sub>,<i>yt</i><sub><i>i</i></sub>) 㯠<i>i</i> çªç®ã®æ¢åè·¯ç·ã«ãããå§ç¹ããã³çµç¹ã®åº§æšã衚ãïŒ<i>o</i><sub><i>i</i></sub> 㯠<i>i</i> çªç®ã®æ¢åè·¯ç·ã®ææè
ãè¡šãæŽæ°ã§ããïŒãã㯠1 ãŸã㯠0 ã®ããããã§ããïŒ1 ã¯ãã®è·¯ç·ãèªç€Ÿææã§ããããšãïŒ0 ã¯ä»ç€Ÿææã§ããããšããããã衚ãïŒ<i>l</i><sub>i</sub> 㯠<i>i</i> çªç®ã®æ¢åè·¯ç·ã髿¶ãŸãã¯å°äžã®ãããã«ããããè¡šãæŽæ°ã§ããïŒããã 1 ãŸã㯠0 ã®ããããã§ããïŒ1 ã¯ãã®è·¯ç·ã髿¶ã«ããããšãïŒ0 ã¯å°äžã«ããããšããããã衚ãïŒ
</p>
<p>
å
¥åäžã«çŸãã x 座æšããã³ y 座æšã®å€ã¯ -10000 ãã 10000 ã®ç¯å²ã«ããïŒäž¡ç«¯ãç¯å²ã«å«ãŸããïŒïŒãŸãïŒããããã®ããŒã¿ã»ããã«ãããŠïŒæ°è·¯ç·ãå«ããå
šãŠã®è·¯ç·ã«å¯ŸããŠïŒä»¥äžã®æ¡ä»¶ãæºãããšä»®å®ããŠããïŒããã§ 2 ç¹ãéåžžã«è¿ããšã¯ïŒãã® 2 ç¹éã®è·é¢ã 10<sup>-9</sup> 以äžã§ããããšã衚ãïŒ
<ul>
<li>ãã亀ç¹ã®éåžžã«è¿ãã«å¥ã®äº€ç¹ãããããšã¯ãªãïŒ</li>
<li>ããè·¯ç·ã®ç«¯ç¹ã®éåžžã«è¿ããå¥ã®è·¯ç·ãéãããšã¯ãªãïŒ</li>
<li>2 ã€ã®è·¯ç·ã®äžéšãŸãã¯å
šéšãéãªãããšã¯ãªãïŒ</li>
</ul>
</p>
<h3>Output</h3>
<p>
ããããã®ããŒã¿ã»ããã«å¯ŸããŠïŒæäœéèšããªããã°ãªããªãåºå
¥å£ã®åæ°ã 1 è¡ã«åºåããªããïŒ
</p>
<h3>Sample Input</h3>
<pre>
2
-10 1 10 1
4
-6 2 -2 -2 0 1
-6 -2 -2 2 1 0
6 2 2 -2 0 0
6 -2 2 2 1 1
8 12 -7 -3
8
4 -5 4 -2 1 1
4 -2 4 9 1 0
6 9 6 14 1 1
-7 6 7 6 0 0
1 0 1 10 0 0
-5 0 -5 10 0 1
-7 0 7 0 0 1
-1 0 -1 -5 0 1
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
3
</pre>
|
p00369 | <H1>Paper Fortune</H1>
<p>
If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written.
</p>
<p>
Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your dream comes true. Cut up the string into more than one segment and compare their values. The difference between the largest and smallest value will give you the number of years before your wish will be fulfilled. Therefore, the result varies depending on the way you cut up the string. For example, if you are given a string 11121314 and divide it into segments, say, as 1,11,21,3,14, then the difference between the largest and smallest is 21 - 1 = 20. Another division 11,12,13,14 produces 3 (i.e. 14 - 11) years. Any random division produces a game of luck. However, you can search the minimum number of years using a program.
</p>
<p>
Given a string of numerical characters, write a program to search the minimum years before your wish will be fulfilled.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>n</var>
</pre>
<p>
An integer <var>n</var> is given. Its number of digits is from 2 to 100,000, and each digit ranges from 1 to 9.
</p>
<h2>Output</h2>
<p>
Output the minimum number of years before your wish will be fulfilled.
</p>
<h2>Sample Input 1</h2>
<pre>
11121314
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
123125129
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre>
<h2>Sample Input 3</h2>
<pre>
119138
</pre>
<h2>Sample Output 3</h2>
<pre>
5
</pre>
|
p02354 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>The Smallest Window I</H1>
<p>
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0.
</p>
<h2>Constraints</h2>
<ul>
<li> $1 \leq N \leq 10^5$ </li>
<li> $1 \leq S \leq 10^9$</li>
<li> $1 \leq a_i \leq 10^4$</li>
</ul>
<h2>Input</h2>
<p>The input is given in the following format.</p>
<p>
$N$ $S$<br>
$a_1$ $a_2$ ... $a_N$<br>
</p>
<h2>Output</h2>
<p>
Print the smallest sub-array size in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
6 4
1 2 1 2 3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
6 6
1 2 1 2 3 2
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<h2>Sample Input 3</h2>
<pre>
3 7
1 2 3
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
|
p00693 |
<h1>
Cyber Guardian
</h1>
<p>In the good old days, the Internet was free from fears and
terrorism. People did not have to worry about any cyber criminals or mad
computer scientists. Today, however, you are facing atrocious crackers
wherever you are, unless being disconnected. You have to protect
yourselves against their attacks.</p>
<p>Counting upon your excellent talent for software construction and
strong sense of justice, you are invited to work as a cyber
guardian. Your ultimate mission is to create a perfect firewall system
that can completely shut out any intruders invading networks and protect
children from harmful information exposed on the Net. However, it is
extremely difficult and none have ever achieved it before. As the first
step, instead, you are now requested to write a software simulator
under much simpler assumptions.</p>
<p>In general, a firewall system works at the entrance of a local network
of an organization (e.g., a company or a university) and enforces its local
administrative policy. It receives both inbound and outbound packets
(note: data transmitted on the Net are divided into small segments
called packets) and carefully inspects them one by one whether or not
each of them is legal. The definition of the legality may
vary from site to site or depend upon the local administrative
policy of an organization. Your simulator should accept data representing
not only received packets but also the local administrative policy.</p>
<p>For simplicity in this problem we assume that each network packet
consists of three fields: its source address, destination address, and
message body. The source address specifies the computer or appliance
that transmits the packet and the destination address specifies the
computer or appliance to which the packet is transmitted. An address
in your simulator is represented as eight digits such as 03214567 or
31415926, instead of using the standard notation of IP addresses
such as 192.168.1.1. Administrative policy is described in
filtering rules, each of which specifies some collection of
source-destination address pairs and defines those packets with the
specified address pairs either legal or illegal. </p>
<h2>Input</h2>
<p>The input consists of several data sets, each of which represents
filtering rules and received packets in the following format:</p>
<dir>
<i>n</i> <i>m</i><br>
<i>rule</i><sub>1</sub><br>
<i>rule</i><sub>2</sub><br>
<dir>...</dir><br>
<i>rule<sub>n</sub></i><br>
<i>packet</i><sub>1</sub><br>
<i>packet</i><sub>2</sub><br>
<dir>...</dir><br>
<i>packet</i><sub>m</sub><br>
</dir>
<p>The first line consists of two non-negative integers <i>n</i> and
<i>m</i>. If both <i>n</i> and <i>m</i> are zeros, this means the end
of input. Otherwise, <i>n</i> lines, each representing a filtering
rule, and <i>m</i> lines, each representing an arriving packet, follow
in this order. You may assume that <i>n</i> and <i>m</i> are less than
or equal to 1,024.</p>
<p>Each <i>rule<sub>i</sub></i> is in one of the following formats:</p>
<dir>
<p>permit <i>source-pattern</i> <i>destination-pattern</i></p>
<p>deny <i>source-pattern</i> <i>destination-pattern</i></p>
</dir>
<p>A <i>source-pattern</i> or <i>destination-pattern</i> is a
character string of length eight, where each character is either a
digit ('0' to '9') or a wildcard character '?'. For instance,
"1????5??" matches any address whose first and fifth digits are '1'
and '5', respectively. In general, a wildcard character matches any
single digit while a digit matches only itself.</p>
<p>With the keywords "permit" and "deny", filtering rules specify
legal and illegal packets, respectively. That is,
if the source and destination addresses of a packed are matched with
<i>source-pattern</i> and <i>destination-pattern</i>, respectively, it
is <i>permitted</i> to pass the firewall or the request is
<i>denied</i> according to the keyword. Note that a permit rule
and a deny rule can contradict since they may share the same source
and destination address pair. For the purpose of conflict resolution,
we define a priority rule: <i>rule<sub>i</sub></i> has a higher priority over
<i>rule<sub>j</sub></i> if and only if <i>i</i> > <i>j</i>. For
completeness, we define the default rule: any packet is illegal unless
being explicitly specified legal by some given rule.</p>
<p>A packet is in the following format:</p>
<dir>
<p><i>source-address</i> <i>destination-address</i> <i>message-body</i></p>
</dir>
<p>Each of the first two is a character string of length eight that
consists solely of digits. The last one is a character string
consisting solely of alphanumeric characters ('a' to 'z', 'A' to 'Z',
and '0' to '9'). Neither whitespaces nor special characters can occur
in a message body. You may assume that it is not empty and that its
length is at most 50. </p>
<p>You may also assume that there is exactly one
space character between any two adjacent fields in an input line
representing a rule or a packet.</p>
<h2>Output</h2>
<p>For each data set, print the number of legal packets in the first
line, followed by all legal packets in the same order as they occur in
the data set. Each packet must be written exactly in one line. If the
data set includes two packets consisting of the same source and
destination addresses and the same message body, you should consider
them different packets and so they must be written in different
lines. Any extra whitespaces or extra empty lines must not be
written. </p>
<h2>Sample Input</h2>
<pre>2 5
permit 192168?? ?12??34?
deny 19216899 012343?5
19216711 11233340 HiIamACracker
19216891 01234345 Hello
19216899 01234345 HiIamAlsoACracker
19216809 11200340 World
00000000 99999999 TheEndOfTheWorld
1 2
permit 12345678 23456789
19216891 01234345 Hello
12345678 23456789 Hello
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
2
19216891 01234345 Hello
19216809 11200340 World
1
12345678 23456789 Hello
</pre>
|
p01981 | <h3>æ¹å
</h3>
<p>å¹³æ31幎4æ30æ¥ããã£ãŠçŸè¡ã®å
å·ã§ããå¹³æãçµäºãïŒãã®ç¿æ¥ããæ°ããå
å·ãå§ãŸãããšã«ãªã£ãïŒå¹³ææåŸã®æ¥ã®ç¿æ¥ã¯æ°å
å·å
幎5æ1æ¥ã«ãªãïŒ</p>
<p>ACM-ICPC OB/OGã®äŒ (Japanese Alumni Group; JAG) ãéçºããã·ã¹ãã ã§ã¯ïŒæ¥ä»ãåæŠïŒå
å·ãšããã«ç¶ã幎æ°ã«ãã£ãŠå¹Žã衚çŸããæ¥æ¬ã®æŠïŒãçšã㊠"å¹³æ <i>y</i> 幎 <i>m</i> æ <i>d</i> æ¥" ãšãã圢åŒã§ããŒã¿ããŒã¹ã«ä¿åãããŠããïŒãã®ä¿å圢åŒã¯å€æŽããããšãã§ããªãããïŒJAGã¯å
å·ã倿Žãããªããšä»®å®ããŠåæŠã§è¡šããæ¥ä»ãããŒã¿ããŒã¹ã«ä¿åãïŒåºåã®éã«æ¥ä»ãæ£ããå
å·ãçšãã圢åŒã«å€æããããšã«ããïŒ</p>
<p>ããªãã®ä»äºã¯JAGã®ããŒã¿ããŒã¹ã«ä¿åãããŠããæ¥ä»ãïŒå¹³æãŸãã¯æ°å
å·ãçšããæ¥ä»ã«å€æããããã°ã©ã ãæžãããšã§ããïŒæ°å
å·ã¯ãŸã çºè¡šãããŠããªãããïŒ"?" ãçšããŠè¡šãããšã«ããïŒ</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>g</i> <i>y</i> <i>m</i> <i>d</i></blockquote>
<p><i>g</i> ã¯å
å·ã衚ãæååã§ããïŒ <i>g=</i>HEISEI ãæãç«ã€ïŒ<i>y, m, d</i> ã¯æŽæ°ã§ããïŒããããå¹ŽïŒæïŒæ¥ã衚ãïŒ<i>1 ≤ y ≤ 100, 1 ≤ m ≤ 12, 1 ≤ d ≤ 31</i> ãæãç«ã€ïŒ</p>
<p>2æ30æ¥ãªã©ã®åæŠã«ååšããªãæ¥ä»ã¯ããŒã¿ã»ãããšããŠäžããããªãïŒåæŠãšããŠæ£ãã倿ãããšãã«ïŒå¹³æãããåã®å
å·ãçšããå¿
èŠãããæ¥ä»ãããŒã¿ã»ãããšããŠäžããããªãïŒ</p>
<p>å
¥åã®çµãã㯠'#' äžã€ã®ã¿ãããªãè¡ã§ããããããïŒããŒã¿ã»ããã®åæ°ã¯ 100 åãè¶
ããªãïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«ã€ããŠïŒå€æåŸã®å
å·ïŒå¹ŽïŒæïŒæ¥ã空çœã§åºåã£ãŠ 1 è¡ã«åºåããïŒå€æåŸã®å
å·ã "å¹³æ" ã§ããå Žå㯠"HEISEI" ãå
å·ãšããŠçšãïŒæ°å
å·ã§ããã° "?" ãçšããïŒ</p>
<p>éåžžïŒå
å·ã®ç¬¬ 1 幎ç®ã¯å
幎ãšè¡šèšãããïŒæ¬åé¡ã®åºåã§ã¯ãã®èŠåãç¡èŠãïŒ1 ã幎ãšããŠåºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>HEISEI 1 1 8
HEISEI 31 4 30
HEISEI 31 5 1
HEISEI 99 12 31
HEISEI 38 8 30
HEISEI 98 2 22
HEISEI 2 3 26
HEISEI 28 4 23
#
</pre><h3>Output for the Sample Input</h3><pre>HEISEI 1 1 8
HEISEI 31 4 30
? 1 5 1
? 69 12 31
? 8 8 30
? 68 2 22
HEISEI 2 3 26
HEISEI 28 4 23
</pre>
|
p00739 |
<h1><font color="#000000">Problem F:</font> ICPC: Intelligent Congruent Partition of Chocolate</h1>
<!-- end en only -->
<!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> -->
<!-- begin en only -->
<p>
The twins named Tatsuya and Kazuya love chocolate.
They have found a bar of their favorite chocolate in a very strange shape.
The chocolate bar looks to have been eaten partially by Mam.
They, of course, claim to eat it and then
will cut it into two pieces for their portions.
Since they want to be sure that the chocolate bar is fairly divided,
they demand that the shapes of the two pieces are <I>congruent</I>
and that each piece is <I>connected</I>.
</p>
<p>
The chocolate bar consists of many square shaped blocks of chocolate
connected to the adjacent square blocks of chocolate at their edges.
The whole chocolate bar is also connected.
</p>
<p>
Cutting the chocolate bar along with some edges of square blocks,
you should help them to divide it into two congruent and connected pieces of
chocolate. That is, one piece fits into the other
after it is rotated, turned over and moved properly.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F1" width=150 ><br>
<!-- begin en only -->
Figure F-1: A partially eaten chocolate bar with 18 square blocks of chocolate
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
For example, there is a partially eaten chocolate bar
with 18 square blocks of chocolate as depicted in Figure F-1.
Cutting it along with some edges of square blocks,
you get two pieces of chocolate
with 9 square blocks each as depicted in Figure F-2.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F2" width=200 ><br>
<!-- begin en only -->
Figure F-2: Partitioning of the chocolate bar in Figure F-1
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
You get two congruent and connected pieces as the result.
One of them consists of 9 square blocks hatched with horizontal lines
and the other with vertical lines.
Rotated clockwise with a right angle and turned over on a horizontal line,
the upper piece exactly fits into the lower piece.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F3" width=120 ><br>
<!-- begin en only -->
Figure F-3: A shape that cannot be partitioned
into two congruent and connected pieces
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
Two square blocks touching only at their corners
are regarded as they are not connected to each other.
Figure F-3 is an example shape that cannot be partitioned into
two congruent and connected pieces.
Note that, without the connectivity requirement,
this shape can be partitioned into two congruent pieces
with three squares (Figure F-4).
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F4" width=120 ><br>
<!-- begin en only -->
Figure F-4: Two congruent but disconnected pieces
<!-- end en only -->
</center>
<!-- begin en only -->
<p>
Your job is to write a program that judges whether a given bar
of chocolate can be partitioned into such two
congruent and connected pieces or not.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input is a sequence of datasets.
The end of the input is indicated by
a line containing two zeros separated by a space.
Each dataset is formatted as follows.
</p>
<!-- end en only -->
<p>
<blockquote>
<i>w h</i><br>
<i>r</i>(1, 1) ... <i>r</i>(1, <i>w</i>)<br>
<i>r</i>(2, 1) ... <i>r</i>(2, <i>w</i>)<br>
... <br>
<i>r</i>(<i>h</i>, 1) ... <i>r</i>(<i>h</i>, <i>w</i>)<br>
</blockquote>
</p>
<!-- begin en only -->
<p>
The integers <i>w</i> and <i>h</i> are the width and the height of
a chocolate bar, respectively.
You may assume 2 ≤ <i>w</i> ≤ 10 and 2 ≤
<i>h</i> ≤ 10.
Each of the following <i>h</i> lines consists of <i>w</i> digits
delimited by a space.
The digit <i>r</i>(<i>i</i>, <i>j</i>) represents the existence of a square block of
chocolate at the position
(<i>i</i>, <i>j</i>) as follows.
<ul>
<li> '0': There is no chocolate (i.e., already eaten). </li>
<li> '1': There is a square block of chocolate. </li>
</ul>
</p>
<p>
You can assume that there are at most 36 square blocks of
chocolate in the bar, i.e.,
the number of digit '1's representing square blocks of chocolate
is at most 36 in each dataset.
You can also assume that there is at least one square block of chocolate in
each row and each column.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
You can assume that the chocolate bar is connected.
Since Mam does not eat chocolate bars making holes in them,
you can assume that there is no dataset that represents
a bar in a shape with hole(s) as depicted in Figure F-5.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008F5" width=120 ><br>
<!-- begin en only -->
Figure F-5: A partially eaten chocolate bar with a hole
(You can assume that there is no dataset like this example)
<!-- end en only -->
</center>
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a line containing one of two uppercase character
strings "YES" or "NO".
"YES" means the chocolate bar indicated by the dataset can be
partitioned into two congruent and connected
pieces, and "NO" means it cannot be partitioned into such
two pieces.
No other characters should be on the output line.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
2 2
1 1
1 1
3 3
0 1 0
1 1 0
1 1 1
4 6
1 1 1 0
1 1 1 1
1 1 1 0
1 1 1 0
0 1 1 0
1 1 1 0
7 5
0 0 1 0 0 1 1
0 1 1 1 1 1 0
0 1 1 1 1 1 0
1 1 1 1 1 1 0
1 0 0 0 1 1 0
9 7
0 0 1 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0
1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1
0 0 0 1 1 0 0 0 0
0 0 0 1 0 0 0 0 0
9 7
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0
7 6
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 0
1 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
10 10
0 1 1 1 1 1 1 1 1 1
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 1 0
1 1 1 1 1 1 1 1 1 0
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
YES
NO
YES
YES
YES
NO
NO
YES
</pre>
|
p02704 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are an integer <var>N</var> and arrays <var>S</var>, <var>T</var>, <var>U</var>, and <var>V</var>, each of length <var>N</var>.
Construct an <var>NÃN</var> matrix <var>a</var> that satisfy the following conditions:</p>
<ul>
<li><var>a_{i,j}</var> is an integer.</li>
<li><var>0 \leq a_{i,j} \lt 2^{64}</var>.</li>
<li>If <var>S_{i} = 0</var>, the bitwise AND of the elements in the <var>i</var>-th row is <var>U_{i}</var>.</li>
<li>If <var>S_{i} = 1</var>, the bitwise OR of the elements in the <var>i</var>-th row is <var>U_{i}</var>.</li>
<li>If <var>T_{i} = 0</var>, the bitwise AND of the elements in the <var>i</var>-th column is <var>V_{i}</var>.</li>
<li>If <var>T_{i} = 1</var>, the bitwise OR of the elements in the <var>i</var>-th column is <var>V_{i}</var>.</li>
</ul>
<p>However, there may be cases where no matrix satisfies the conditions.</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 500 </var></li>
<li><var> 0 \leq S_{i} \leq 1 </var></li>
<li><var> 0 \leq T_{i} \leq 1 </var></li>
<li><var> 0 \leq U_{i} \lt 2^{64} </var></li>
<li><var> 0 \leq V_{i} \lt 2^{64} </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>S_{2}</var> <var>...</var> <var>S_{N}</var>
<var>T_{1}</var> <var>T_{2}</var> <var>...</var> <var>T_{N}</var>
<var>U_{1}</var> <var>U_{2}</var> <var>...</var> <var>U_{N}</var>
<var>V_{1}</var> <var>V_{2}</var> <var>...</var> <var>V_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists a matrix that satisfies the conditions, print one such matrix in the following format:</p>
<pre><var>a_{1,1}</var> <var>...</var> <var>a_{1,N}</var>
<var>:</var>
<var>a_{N,1}</var> <var>...</var> <var>a_{N,N}</var>
</pre>
<p>Note that any matrix satisfying the conditions is accepted.</p>
<p>If no matrix satisfies the conditions, print <var>-1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0 1
1 0
1 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 1
1 0
</pre>
<p>In Sample Input <var>1</var>, we need to find a matrix such that:</p>
<ul>
<li>the bitwise AND of the elements in the <var>1</var>-st row is <var>1</var>;</li>
<li>the bitwise OR of the elements in the <var>2</var>-nd row is <var>1</var>;</li>
<li>the bitwise OR of the elements in the <var>1</var>-st column is <var>1</var>;</li>
<li>the bitwise AND of the elements in the <var>2</var>-nd column is <var>0</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 1
1 0
15 15
15 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>15 11
15 11
</pre></section>
</div>
</span> |
p03816 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has decided to play a game using cards.
He has a deck consisting of <var>N</var> cards. On the <var>i</var>-th card from the top, an integer <var>A_i</var> is written.</p>
<p>He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, <var>N</var> is odd, which guarantees that at least one card can be kept.</p>
<p>Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 ⊠N ⊠10^{5}</var></li>
<li><var>N</var> is odd.</li>
<li><var>1 ⊠A_i ⊠10^{5}</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The 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_3</var> ... <var>A_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 1 3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>One optimal solution is to perform the operation once, taking out two cards with <var>1</var> and one card with <var>2</var>. One card with <var>1</var> and another with <var>2</var> will be eaten, and the remaining card with <var>1</var> will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: <var>1</var>, <var>3</var> and <var>7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre></section>
</div>
</span> |
p02211 | <h2>ãããã ããŒããã</h2>
<p>square1001åãšE869120åã¯çžŠ $H$ è¡ã暪 $W$ åã®ã°ãªããã®äžçã«è¿·ã蟌ãã§ããŸããŸãã!</p>
<p>ãã®äžçã®ç¥ã¯èšããŸããã</p>
<p>ããªã³ãŽã $K$ åéããŠäºäººãåºäŒã£ããšãããããã°å
ã®äžçã«åž°ããã§ããããã</p>
<p>ãã®èšèãèããsquare1001åã¯ããªã³ãŽã $K$ å以äžéããŠE869120åããããã¹ãžåããããšã«ããŸããã</p>
<br>
<p>ããã§ãã°ãªããã®åãã¹ã¯æ¬¡ã®ããã«è¡šãããŸãã</p>
<p>'s'ïŒsquare1001åããããã¹ã§ãã</p>
<p>'e'ïŒE869120åããããã¹ã§ãã</p>
<p>'a'ïŒãªã³ãŽã1ã€èœã¡ãŠãããã¹ã§ãããã®ãã¹ãåããŠèšªãããšãã«ãªã³ãŽã1ã€åŸãããšãã§ããŸãã<strong>ãã®ã°ãªããäžã«ãã®ãã¹ã¯20å以äžãããããŸããã</strong></p>
<p>'#'ïŒå£ã§ãããã®ãã¹ã«èšªããããšã¯ã§ããŸããã</p>
<p>'.'ïŒäœããªããã¹ã§ãããã®ãã¹ã«èšªããããšãã§ããŸãã</p>
<br>
<p>square1001åã¯èªåããããã¹ããäžäžå·Šå³ã«é£ãåããã¹ãžã®ç§»åãç¹°ãè¿ãããšã§ãç®çãéæããããšããŸãããã ããã°ãªããããå€ã«åºãããšã¯ã§ããŸããã</p>
<p>square1001åãç®çãéæããããã«å¿
èŠãªç§»ååæ°ã®æå°å€ãæ±ããŠãã ããã</p>
<p>ãã ããE869120åãåãããšã¯ãªããã®ãšããŸãããŸããsquare1001åã¯ãªã³ãŽã $K$ åä»¥äžæã¡éã¶èœåããããã®ãšããŸãã</p>
<p>ãŸããç®æšãéæã§ããªããšãã¯ã-1ããåºåããŠãã ããã</p>
<h3>å
¥å</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<p>ã°ãªããã®äžãã $i$ ãã¹ç®ãå·Šãã $j$ ãã¹ç®ã®æåã $A_{i, j}$ ãšããã</p>
<pre>
$H$ $W$ $K$
$A_{1,1} A_{1,2} A_{1,3} \cdots A_{1,W}$
$A_{2,1} A_{2,2} A_{2,3} \cdots A_{2,W}$
$A_{3,1} A_{3,2} A_{3,3} \cdots A_{3,W}$
$\ldots$
$A_{H,1} A_{H,2} A_{H,3} \cdots A_{H,W}$
</pre>
<h3>åºå</h3>
<p>square1001åãç®çãéæãããŸã§ã«å¿
èŠãªç§»ååæ°ã®æå°å€ãæ±ããŠãã ããããã ããäžå¯èœãªå Žåã¯ã-1ããåºåããŠãã ããã</p>
<p>ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$1 \leq H \leq 1000$</li>
<li>$1 \leq W \leq 1000$</li>
<li>$1 \leq K \leq 20$</li>
<li>$H, W, K$ ã¯æŽæ°ã§ããã</li>
<li>$A_{i, j}$ 㯠's'ã'e'ã'a'ã'#'ã'.'ã®ããããã§ããã</li>
<li>ã°ãªããã« 's'ã'e'ã¯ãããããã 1 ã€ã®ã¿å«ãŸããã</li>
<li>ã°ãªããã«å«ãŸãã 'a' ã®æ°ã¯ $K$ åä»¥äž $20$ å以äžã§ããã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
5 5 2
s..#a
.#...
a#e.#
...#a
.#...
</pre>
<h3>åºåäŸ1</h3>
<pre>
14
</pre>
<h3>å
¥åäŸ2</h3>
<pre>
7 7 3
.......
.s...a.
a##...a
..###..
.a#e#.a
#.###..
a..#..a
</pre>
<h3>åºåäŸ2</h3>
<pre>
-1
</pre>
<p>ç®çãéæäžå¯èœãªå Žåã¯ã-1ããåºåããŠãã ããã</p>
<h3>å
¥åäŸ3</h3>
<pre>
12 12 10
.#####......
.##.....#...
....a.a#a..#
.#..#a......
##.....a#s..
#..a###.##.#
.e#.#.#.#a..
..#a#.....#.
#..##a......
.a...a.a..#.
a....#a.aa..
...a.#...#a.
</pre>
<h3>åºåäŸ3</h3>
<pre>
30
</pre> |
p00386 | <h1>Meeting in a City</h1>
ã<p>
You are a teacher at Iazu High School is the Zuia Kingdom. There are $N$ cities and $N-1$ roads connecting them that allow you to move from one city to another by way of more than one road. Each of the roads allows bidirectional traffic and has a known length.
</p>
<p>
As a part of class activities, you are planning the following action assignment for your students. First, you come up with several themes commonly applicable to three different cities. Second, you assign each of the themes to a group of three students. Then, each student of a group is assigned to one of the three cities and conducts a survey on it. Finally, all students of the group get together in one of the $N$ cities and compile their results.
</p>
<p>
After a theme group has completed its survey, the three members move from the city on which they studied to the city for getting together. The longest distance they have to travel for getting together is defined as the cost of the theme. You want to select the meeting city so that the cost for each theme becomes minimum.
</p>
<p>
Given the number of cities, road information and $Q$ sets of three cities for each theme, make a program to work out the minimum cost for each theme.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $Q$
$u_1$ $v_1$ $w_1$
$u_2$ $v_2$ $w_2$
$...$
$u_{N-1}$ $v_{N-1}$ $w_{N-1}$
$a_1$ $b_1$ $c_1$
$a_2$ $b_2$ $c_2$
$...$
$a_Q$ $b_Q$ $c_Q$
</pre>
<p>
The first line provides the number of cities in the Zuia Kingdom $N$ ($3 \leq N \leq 100,000$) and the number of themes $Q$ ($1 \leq Q \leq 100,000$). Each of the subsequent $N-1$ lines provides the information regarding the $i$-th road $u_i,v_i,w_i$ ($ 1 \leq u_i < v_i \leq N, 1 \leq w_i \leq 10,000$), indicating that the road connects cities $u_i$ and $v_i$, and the road distance between the two is $w_i$. Each of the $Q$ lines that follows the above provides the three cities assigned to the $i$-th theme: $a_i,b_i,c_i$ ($1 \leq a_i < b_i < c_i \leq N$).
</p>
<h2>Output</h2>
<p>
For each theme, output the cost in one line.
â</p>
<h2>Sample Input 1</h2>
<pre>
5 4
1 2 3
2 3 4
2 4 2
4 5 3
1 3 4
1 4 5
1 2 3
2 4 5
</pre>
<h2>Sample Output 1</h2>
<pre>
4
5
4
3
</pre>
<p>
In the first theme, traveling distance from City 3 (the student conducts survey) to City 2 (meeting venue) determines the cost 4. As no other meeting city can provide smaller cost, you should output 4. In the second theme, you can minimize the cost down to 5 by selecting City 2 or City 4 as the meeting venue.
</p>
<h2>Sample Input 2</h2>
<pre>
5 3
1 2 1
2 3 1
3 4 1
4 5 1
1 2 3
1 3 5
1 2 4
</pre>
<h2>Sample Output 2</h2>
<pre>
1
2
2
</pre>
<h2>Sample Input 3</h2>
<pre>
15 15
1 2 45
2 3 81
1 4 29
1 5 2
5 6 25
4 7 84
7 8 56
4 9 2
4 10 37
7 11 39
1 12 11
11 13 6
3 14 68
2 15 16
10 13 14
13 14 15
2 14 15
7 12 15
10 14 15
9 10 15
9 14 15
8 13 15
5 6 13
11 13 15
12 13 14
2 3 10
5 13 15
10 11 14
6 8 11
</pre>
<h2>Sample Output 3</h2>
<pre>
194
194
97
90
149
66
149
140
129
129
194
111
129
194
140
</pre>
|
p02641 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are an integer <var>X</var> and an integer sequence of length <var>N</var>: <var>p_1, \ldots, p_N</var>.</p>
<p>Among the integers not contained in the sequence <var>p_1, \ldots, p_N</var> (not necessarily positive), find the integer nearest to <var>X</var>, that is, find the integer whose absolute difference with <var>X</var> is the minimum. If there are multiple such integers, report the smallest such integer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X \leq 100</var></li>
<li><var>0 \leq N \leq 100</var></li>
<li><var>1 \leq p_i \leq 100</var></li>
<li><var>p_1, \ldots, p_N</var> are all distinct.</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>N</var>
<var>p_1</var> <var>...</var> <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 5
4 7 10 6 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>Among the integers not contained in the sequence <var>4, 7, 10, 6, 5</var>, the one nearest to <var>6</var> is <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 5
4 7 10 6 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
<p>Among the integers not contained in the sequence <var>4, 7, 10, 6, 5</var>, the ones nearest to <var>10</var> are <var>9</var> and <var>11</var>. We should print the smaller one, <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100
</pre>
<p>When <var>N = 0</var>, the second line in the input will be empty. Also, as seen here, <var>X</var> itself can be the answer.</p></section>
</div>
</span> |
p03953 | <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> rabbits on a number line.
The rabbits are conveniently numbered <var>1</var> through <var>N</var>.
The coordinate of the initial position of rabbit <var>i</var> is <var>x_i</var>.</p>
<p>The rabbits will now take exercise on the number line, by performing <em>sets</em> described below.
A set consists of <var>M</var> <em>jumps</em>. The <var>j</var>-th jump of a set is performed by rabbit <var>a_j</var> (<var>2â€a_jâ€N-1</var>).
For this jump, either rabbit <var>a_j-1</var> or rabbit <var>a_j+1</var> is chosen with equal probability (let the chosen rabbit be rabbit <var>x</var>), then rabbit <var>a_j</var> will jump to the symmetric point of its current position with respect to rabbit <var>x</var>.</p>
<p>The rabbits will perform <var>K</var> sets in succession.
For each rabbit, find the expected value of the coordinate of its eventual position after <var>K</var> sets are performed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3â€Nâ€10^5</var></li>
<li><var>x_i</var> is an integer.</li>
<li><var>|x_i|â€10^9</var></li>
<li><var>1â€Mâ€10^5</var></li>
<li><var>2â€a_jâ€N-1</var></li>
<li><var>1â€Kâ€10^{18}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
<var>M</var> <var>K</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.
The <var>i</var>-th line should contain the expected value of the coordinate of the eventual position of rabbit <var>i</var> after <var>K</var> sets are performed.
The output is considered correct if the absolute or relative error is at most <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
-1 0 2
1 1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-1.0
1.0
2.0
</pre>
<p>Rabbit <var>2</var> will perform the jump.
If rabbit <var>1</var> is chosen, the coordinate of the destination will be <var>-2</var>.
If rabbit <var>3</var> is chosen, the coordinate of the destination will be <var>4</var>.
Thus, the expected value of the coordinate of the eventual position of rabbit <var>2</var> is <var>0.5Ã(-2)+0.5Ã4=1.0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 -1 1
2 2
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1.0
-1.0
1.0
</pre>
<p><var>x_i</var> may not be distinct.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
0 1 3 6 10
3 10
2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0.0
3.0
7.0
8.0
10.0
</pre></section>
</div>
</span> |
p03400 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Some number of chocolate pieces were prepared for a training camp.
The camp had <var>N</var> participants and lasted for <var>D</var> days.
The <var>i</var>-th participant (<var>1 \leq i \leq N</var>) ate one chocolate piece on each of the following days in the camp: the <var>1</var>-st day, the <var>(A_i + 1)</var>-th day, the <var>(2A_i + 1)</var>-th day, and so on.
As a result, there were <var>X</var> chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.</p>
<p>Find the number of chocolate pieces prepared at the beginning of the camp.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq D \leq 100</var></li>
<li><var>1 \leq X \leq 100</var></li>
<li><var>1 \leq A_i \leq 100</var> (<var>1 \leq i \leq N</var>)</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>D</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>Find the number of chocolate pieces prepared at the beginning of the camp.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
7 1
2
5
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>The camp has <var>3</var> participants and lasts for <var>7</var> days.
Each participant eats chocolate pieces as follows:</p>
<ul>
<li>The first participant eats one chocolate piece on Day <var>1</var>, <var>3</var>, <var>5</var> and <var>7</var>, for a total of four.</li>
<li>The second participant eats one chocolate piece on Day <var>1</var> and <var>6</var>, for a total of two.</li>
<li>The third participant eats one chocolate piece only on Day <var>1</var>, for a total of one.</li>
</ul>
<p>Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is <var>1 + 4 + 2 + 1 = 8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
8 20
1
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>29
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
30 44
26
18
81
18
6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>56
</pre></section>
</div>
</span> |
p01597 |
<H2>Problem G: Nezumi's Treasure</h2>
<p>There were a mouse and a cat living in a field. The mouse stole a dried
fish the cat had loved. The theft was found soon later. The mouse started
running as chased by the cat for the dried fish.</p>
<p>There were a number of rectangular obstacles in the field. The mouse
always went straight ahead as long as possible, but he could not jump over or
pass through these obstacles. When he was blocked by an obstacle, he turned
leftward to the direction he could go forward, and then he started again to run
in that way. Note that, at the corner, he might be able to keep going without
change of the direction.</p>
<p>He found he was going to pass the same point again and again while chased by
the cat. He then decided to hide the dried fish at the first point where he
was blocked by an obstacle twice from that time.
In other words, he decided to hide it at the first turn
after he entered into an infinite loop.
He thought he could come there again
after the chase ended.</p>
<p>For example, in the following figure,
he first went along the blue line and turned left at point B.
Then he went along the red lines counter-clockwise,
and entered into an infinite loop.
In this case, he hid dried fish at NOT point B but at point A,
because when he reached point B on line C for the second time,
he just passed and didn't turn left.</p>
<div align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_nezumi_fig3"><br>
Example of dried fish point</div>
<p>Finally the cat went away, but he remembered neither where he thought of
hiding the dried fish nor where he actually hid it. Yes, he was losing <i>his</i>
dried fish.</p>
<p>You are a friend of the mouse and talented programmer. Your task is to
write a program that counts the number of possible points the mouse hid the
dried fish, where information about the obstacles is given. The mouse should be
considered as a point.</p>
<h2>Input</h2>
<p>The input begins with a line with one integer <var>N</var> (4 <= <var>N</var>
<= 40,000), which denotes the number of obstacles. Then <var>N</var> lines
follow. Each line describes one obstacle with four integers <var>X<sub>i,1</sub></var>,
<var>Y<sub>i,1</sub></var>, <var>X<sub>i,2</sub></var>, and <var>Y<sub>i,2</sub></var>
(-100,000,000 <= <var>X<sub>i,1</sub></var>, <var>Y<sub>i,1</sub></var>, <var>X<sub>i,2</sub></var>,
<var>Y<sub>i,2</sub></var> <= 100,000,000). <var>(X<sub>i,1</sub>, Y<sub>i,1</sub>)</var>
and <var>(X<sub>i,2</sub>, Y<sub>i,2</sub>)</var> represent the coordinates of
the lower-left and upper-right corners of the obstacle respectively. As usual, <var>X</var>-axis
and <var>Y</var>-axis go right and upward respectively.</p>
<p>No pair of obstacles overlap.</p>
<h2>Output</h2>
<p>Print the number of points the mouse could hide the dried fish. You can
assume this number is positive (i.e. nonzero).</p>
<h2>Sample Input 1</h2>
<pre>4
0 0 2 1
3 0 4 2
0 2 1 4
2 3 4 4</pre>
<h2>Output for the Sample Input 1</h2>
<pre>4</pre>
<h2>Sample Input 2</h2>
<pre>8
0 0 2 1
2 2 4 3
5 3 7 4
7 5 9 6
0 2 1 4
2 4 3 6
6 0 7 2
8 2 9 4</pre>
<h2>Output for the Sample Input 2</h2>
<pre>8</pre>
|
p03050 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke received a positive integer <var>N</var> from Takahashi.
A positive integer <var>m</var> is called a <em>favorite number</em> when the following condition is satisfied:</p>
<ul>
<li>The quotient and remainder of <var>N</var> divided by <var>m</var> are equal, that is, <var>\lfloor \frac{N}{m} \rfloor = N \bmod m</var> holds.</li>
</ul>
<p>Find all favorite numbers and print the sum of those.</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^{12}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>There are two favorite numbers: <var>3</var> and <var>7</var>. Print the sum of these, <var>10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2499686339916
</pre>
<p>Watch out for overflow.</p></section>
</div>
</span> |
p02092 |
<h2>E: Red Black Balloons</h2>
<h3>Story</h3>
<p>Homura-chan's dream comes true. It means ICPC Asia regional contest 20xx will be held in Sapporo! Homura-chan has been working hard for the preparation. And finally, it's the previous day of the contest. Homura-chan started to stock balloons to be delivered to contestants who get accepted. However, she noticed that there were only two colors of balloons: red and black.</p>
<h3>Problem Statement</h3>
<p>ICPC Asia regional contest in Sapporo plans to provide <var>N</var> problems to contestants. Homura-chan is a professional of contest preparation, so she already knows how many contestants would get acceptance for each problem (!!), <var>a_i</var> contestants for the <var>i</var>-th problem. You can assume the prediction is perfectly accurate. Ideally, Homura-chan would assign a distinct color of a balloon to each problem respectively. But you know, she has only two colors red and black now. Thus, Homura-chan comes up with the idea to differentiate the size of balloons in <b><var>K</var> levels</b>, that is, each problem has a balloon with a distinct pair of (color, size).</p>
<p>Homura-chan now has <var>r_i</var> red balloons with size <var>i</var> (<var>1 \leq i \leq K</var>) and <var>b_j</var> black balloons with size <var>j</var> (<var>1 \leq j \leq K</var>). Suppose we assign a pair <var>(c_i, s_i)</var> of a color <var>c_i</var> (red or black) and a size <var>s_i</var> to the <var>i</var>-th problem, for each <var>i</var>. As noted, we have to assign distinct pairs to each problem, more precisely, <var>(c_i, s_i) \neq (c_j, s_j)</var> holds for <var>i \neq j</var>. Moreover, the number of balloons with <var>(c_i, s_i)</var> must be no less than <var>a_i</var>. In the case that there are no such assignments, Homura-chan can change the size of balloons by her magic power. Note that Homura-chan doesn't know magic to change the color of balloons, so it's impossible.</p>
<p>Your task is to write a program computing the minimum number of balloons whose size is changed by Homura-chan's magic to realize an assignment satisfying the above-mentioned conditions. If there is no way to achieve such an assignment even if Homura-chan changes the size of balloons infinitely, output <code>-1</code> instead.</p>
<h3>Input</h3>
<pre>
<var>N</var> <var>K</var>
<var>a_1 ... a_N</var>
<var>r_1 ... r_K</var>
<var>b_1 ... b_K</var>
</pre>
<h3>Constraints</h3>
<ul>
<li> <var>1 \leq N,K \leq 60</var></li>
<li> <var>N \leq 2K</var></li>
<li> <var>1 \leq a_i \leq 50</var> <var>(1 \leq i \leq N) </var></li>
<li> <var>1 \leq r_j,b_j \leq 50</var> <var>(1 \leq j \leq K) </var></li>
<li> Inputs consist only of integers.</li>
</ul>
<h3>Output</h3>
<p>Output the minimum number of balloons whose size is changed to achieve an assignment in a line. If there are no ways to achieve assignments, output <code>-1</code> instead.</p>
<h3>Sample Input 1</h3>
<pre>
3 2
6 5 4
8 1
7 1
</pre>
<h3>Output for Sample Input 1</h3>
<pre>3</pre>
<p>Homura-chan changes the size of three red balloons from 1 to 2. Then she can assign (black,1) to the problem 1, (red,1) to the problem 2, and (red,2) to the problem 3.</p>
<h3>Sample Input 2</h3>
<pre>
2 1
50 50
2
3
</pre>
<h3>Output for Sample Input 2</h3>
<pre>-1</pre>
<h3>Sample Input 3</h3>
<pre>
4 3
3 10 28 43
40 18 2
26 7 11
</pre>
<h3>Output for Sample Input 3</h3>
<pre>5</pre>
|
p02568 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an array <var>a_0, a_1, ..., a_{N-1}</var> of length <var>N</var>. Process <var>Q</var> queries of the following types.</p>
<ul>
<li><code>0 l r b c</code>: For each <var>i = l, l+1, \dots, {r - 1}</var>, set <var>a_i \gets b \times a_i + c</var>.</li>
<li><code>1 l r</code>: Print <var>\sum_{i = l}^{r - 1} a_i \bmod 998244353</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N, Q \leq 500000</var></li>
<li><var>0 \leq a_i, c < 998244353</var></li>
<li><var>1 \leq b < 998244353</var></li>
<li><var>0 \leq l < r \leq N</var></li>
<li>All values in Input are integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Q</var>
<var>a_0</var> <var>a_1</var> ... <var>a_{N - 1}</var>
<var>\textrm{Query}_0</var>
<var>\textrm{Query}_1</var>
:
<var>\textrm{Query}_{Q - 1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each query of the latter type, print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 7
1 2 3 4 5
1 0 5
0 2 4 100 101
1 0 3
0 1 3 102 103
1 2 5
0 2 5 104 105
1 0 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>15
404
41511
4317767
</pre></section>
</div>
</span> |
p00555 |
<h1>äŒæ©ã¹ããŒã¹ (Refreshment Area)</h1>
<h2>åé¡</h2>
<p>
äžççãªããã°ã©ãã³ã°ã³ã³ãã¹ããæ¥æ¬ã§éå¬ãããããšã«ãªãïŒçŸåšäŒå Žã®èšå¶ãè¡ãããŠããïŒãã®äŒå Žã¯ååæ¹åã« N ãã¹ïŒæ±è¥¿æ¹åã« M ãã¹ã®ãã¹ç®ç¶ã«åºåãããŠããïŒããã€ãã®ãã¹ã«ã¯ç«¶æçšã®æ©æã眮ãããŠããïŒ
</p>
<p>
ãã®ã³ã³ãã¹ãã§ã¯ïŒéžæãç«¶æäžã«äŒæ©ããããã«ïŒè»œé£ã飲ã¿ç©ãªã©ã眮ããäŒæ©ã¹ããŒã¹ã 1 ç®æäŒå Žå
ã«èšããããšã«ãªã£ãïŒäŒæ©ã¹ããŒã¹ã¯ååæ¹åãŸãã¯æ±è¥¿æ¹åã«é£ç¶ãã D ãã¹ã§ãªããã°ãªããªãïŒãã ãïŒæ©æã®çœ®ããããã¹ç®ã«äŒæ©ã¹ããŒã¹ãèšããããšã¯ã§ããªãïŒ
</p>
<p>
äŒå Žå
ã«äŒæ©ã¹ããŒã¹ãèšããæ¹æ³ã¯äœéãããããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠1 + N è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯ 3 åã®æŽæ° N, M, D (1 ⊠N ⊠100, 1 ⊠M ⊠100, 2 ⊠D ⊠100) ã空çœãåºåããšããŠæžãããŠããïŒäŒå Žãååæ¹åã« N ãã¹ïŒæ±è¥¿æ¹åã« M ãã¹ã®ãã¹ç®ç¶ã«åºåãããŠããïŒäŒæ©ã¹ããŒã¹ãååæ¹åãŸãã¯æ±è¥¿æ¹åã«é£ç¶ãã D ãã¹ãããªãããšã衚ãïŒ
</p>
<p>
ç¶ã N è¡ã«ã¯ãããã M æåãããªãæååãæžãããŠããïŒäŒå Žã®æ
å ±ã衚ãïŒ
N è¡ã®ãã¡ã® i è¡ç®ã® j æåç® (1 ⊠i ⊠N, 1 ⊠j ⊠M) ã¯ïŒäŒå Žã®ãã¹ç®ã®åãã i è¡ç®ïŒè¥¿ãã j åç®ã®ãã¹ã®ç¶æ
ã衚ã '#' ãŸã㯠'.' ã®ããããã®æåã§ããïŒ'#' ã¯ãã®ãã¹ã«æ©æã眮ãããŠããããšãïŒ'.' ã¯ãã®ãã¹ã«æ©æã眮ãããŠããªãããšã衚ãïŒ
</p>
<h2>åºå</h2>
<p>
äŒå Žå
ã«äŒæ©ã¹ããŒã¹ãèšããæ¹æ³ã¯äœéããããã 1 è¡ã§åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
3 5 2
...#.
#...#
....#
</pre>
<h3>åºåäŸ 1</h3>
<pre>
12
</pre>
<br/>
<h3>å
¥åäŸ 2</h3>
<pre>
4 7 5
.#.....
.....##
.......
#......
</pre>
<h3>åºåäŸ 2</h3>
<pre>
7
</pre>
<p>
å
¥åºåäŸ 1 ã§ã¯ïŒäžã®å³ã«ç€ºãããã«ïŒäŒæ©ã¹ããŒã¹ãèšããæ¹æ³ã¯å
šéšã§ 12 éãããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_2017-yo-t3-fig01" width="600" alt="picture" width="900">
</center>
<br/>
<br/>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2016/2017-yo/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 16 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2016/2017 äºéžç«¶æèª²é¡ã</a>
</p>
</div> |
p02138 | <h1>Problem B: U&U</h1>
<h2>Problem</h2>
<p>
$2$ã€ã®ããŒã ãããŒã UKUãšããŒã ããããããæåãããŒã UKUã«ã¯$N$人ãããŒã ããã«ã¯$M$人ã®äººãããã
ããŒã UKUãšããŒã ããã¯ãU&Uããšããã²ãŒã ãè¡ãããšã«ããããU&Uãã¯$2$ã€ã®ããŒã ã§å
±éã®ã¹ã³ã¢ãæã£ãŠãããäºãã«ååãããå
±éã®ã¹ã³ã¢ãæå°åããããšãç®çã§ããããU&Uãã¯æåããã¹ãŠã®äººã®äœåã$2$ã§ãå
±éã®ã¹ã³ã¢ã¯$0$ã®ç¶æ
ã§ä»¥äžã®ãããªæé ã§é²ããããã
</p>
<ol>
<li>ããŒã UKUã®äººã¯1人ãã€ãããŒã ããã®èª°ã$1$人ã«å¯ŸããŠã¡ããã©$1$åã®æ»æãè¡ãã
æ»æãåãã人ã¯äœåã$1$æžããäœåã$0$ã«ãªã£ãå Žåãã®ããŒã ããæããã
ãã®ãšãããŒã ããã®äººæ°ã$0$人ã«ãªã£ãããã²ãŒã ãçµäºããã
ããŒã UKUã®ãã¹ãŠã®äººãã¡ããã©$1$åã®æ»æãçµããæç¹ã§ã²ãŒã ãçµäºããŠãªããã°å
±éã®ã¹ã³ã¢ã«$1$ãå ç®ããã$2$.ã«é²ã
</li>
<li>
åæ§ã«ãããŒã ããã®äººã$1$人ãã€ãããŒã UKUã®èª°ã$1$人ã«å¯ŸããŠã¡ããã©$1$åã®æ»æãè¡ãã
æ»æãåãã人ã¯äœåã$1$æžããäœåã$0$ã«ãªã£ãå Žåãã®ããŒã ããæããã
ãã®ãšãããŒã UKUã®äººæ°ã$0$人ã«ãªã£ãããã²ãŒã ãçµäºããã
ããŒã ããã®ãã¹ãŠã®äººãã¡ããã©$1$åã®æ»æãçµããæç¹ã§ã²ãŒã ãçµäºããŠãªããã°å
±éã®ã¹ã³ã¢ã«$1$ãå ç®ããã$1$.ã«æ»ã
</li>
</ol>
<p>
ããŒã UKUã®äººæ°ãšããŒã ããã®äººæ°ãäžãããããšãããU&Uãã²ãŒã çµäºæã®å
±éã®ã¹ã³ã¢ãšããŠãããããã®ã®æå°å€ãããšããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $M$
</pre>
<p>
ããŒã UKUã®äººæ°ãè¡šãæŽæ°$N$ãšããŒã ããã®äººæ°ãè¡šãæŽæ°$M$ã空çœåºåãã§äžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \le N, M \le 10^{18}$</li>
<li>$N$ãš$M$ã¯æŽæ°</li>
</ul>
<h2>Output</h2>
<p>æå°ã®ã¹ã³ã¢ã$1$è¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
20 10
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
10 20
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<h2>Sample Input 3</h2>
<pre>
64783 68943
</pre>
<h2>Sample Output 3</h2>
<pre>
4
</pre>
<h2>Sample Input 4</h2>
<pre>
1000000000000000000 1000000000000000000
</pre>
<h2>Sample Output 4</h2>
<pre>
2
</pre>
|
p00105 |
<H1>Book Index</H1>
<p>
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
</p>
<p>
You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once.
</p>
<p>
The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
</p>
<!--
<p>
æ¬ã®æåŸã«ã¯çŽ¢åŒãèšããããŠããŸããæ¬ã®äžããæœåºããããèªå¥ããšãããŒãžçªå·ãã®çµãèªã¿åããæ¬ã®çŽ¢åŒãšããŠãèªå¥ããšãã®èªå¥ã衚ãããããŒãžçªå·ã®ãªã¹ãããåºåããŠçµäºããããã°ã©ã ãäœæããŠäžããããã ãã1ã€ã®èªå¥ã®é·ãã¯30æå以å
ãšããããŒãžçªå·ã¯1,000以äžãšããŸããå
¥åã«å«ãŸããèªå¥ãšããŒãžçªå·ã®çµã¯100以äžãšãã1ã€ã®èªå¥ã¯åãããŒãžçªå·ã«è€æ°åçŸããªããã®ãšããŸãããŸããåºåã«é¢ããŠã¯ãèªå¥ã®é çªã¯ã¢ã«ãã¡ãããé ãšããããŒãžçªå·ã¯å°ããé (æé )ãšããŸãã
</p>
-->
<H2>Input</H2>
<pre>
<i>word page_number</i>
:
:
</pre>
<H2>Output</H2>
<pre>
<i>word</i>
<i>a_list_of_the_page_number</i>
<i>word</i>
<i>a_list_of_the_Page_number</i>
:
:
</pre>
<H2>Sample Input</H2>
<pre>
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
</pre>
<H2>Output for the Sample Input</H2>
<pre>
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
</pre>
</div>
|
p02991 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ken loves <em>ken-ken-pa</em> (Japanese version of hopscotch). Today, he will play it on a directed graph <var>G</var>.
<var>G</var> consists of <var>N</var> vertices numbered <var>1</var> to <var>N</var>, and <var>M</var> edges. The <var>i</var>-th edge points from Vertex <var>u_i</var> to Vertex <var>v_i</var>.</p>
<p>First, Ken stands on Vertex <var>S</var>. He wants to reach Vertex <var>T</var> by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing.</p>
<p>Determine if he can reach Vertex <var>T</var> by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex <var>T</var>. Note that visiting Vertex <var>T</var> in the middle of a ken-ken-pa does not count as reaching Vertex <var>T</var> by repeating ken-ken-pa.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>0 \leq M \leq \min(10^5, N (N-1))</var></li>
<li><var>1 \leq u_i, v_i \leq N(1 \leq i \leq M)</var></li>
<li><var>u_i \neq v_i (1 \leq i \leq M)</var></li>
<li>If <var>i \neq j</var>, <var>(u_i, v_i) \neq (u_j, v_j)</var>.</li>
<li><var>1 \leq S, T \leq N</var></li>
<li><var>S \neq T</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>u_1</var> <var>v_1</var>
<var>:</var>
<var>u_M</var> <var>v_M</var>
<var>S</var> <var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Ken cannot reach Vertex <var>T</var> from Vertex <var>S</var> by repeating ken-ken-pa, print <var>-1</var>.
If he can, print the minimum number of ken-ken-pa needed to reach vertex <var>T</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
1 2
2 3
3 4
4 1
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Ken can reach Vertex <var>3</var> from Vertex <var>1</var> in two ken-ken-pa, as follows: <var>1 \rightarrow 2 \rightarrow 3 \rightarrow 4</var> in the first ken-ken-pa, then <var>4 \rightarrow 1 \rightarrow 2 \rightarrow 3</var> in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2
2 3
3 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Any number of ken-ken-pa will bring Ken back to Vertex <var>1</var>, so he cannot reach Vertex <var>2</var>, though he can pass through it in the middle of a ken-ken-pa.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 0
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>Vertex <var>S</var> and Vertex <var>T</var> may be disconnected.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6 8
1 2
2 3
3 4
4 5
5 1
1 4
1 5
4 6
1 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>2
</pre></section>
</div>
</span> |
p03683 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> dogs and <var>M</var> monkeys. He wants them to line up in a row.</p>
<p>As a Japanese saying goes, these dogs and monkeys are on bad terms. <em>("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)</em> Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.</p>
<p>How many such arrangements there are? Find the count modulo <var>10^9+7</var> (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N,M †10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible arrangements, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>We will denote the dogs by <code>A</code> and <code>B</code>, and the monkeys by <code>C</code> and <code>D</code>. There are eight possible arrangements: <code>ACBD</code>, <code>ADBC</code>, <code>BCAD</code>, <code>BDAC</code>, <code>CADB</code>, <code>CBDA</code>, <code>DACB</code> and <code>DBCA</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 8
</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>100000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>530123477
</pre></section>
</div>
</span> |
p01344 |
<H1><font color="#000">Problem F: </font> Bouldering</H1>
<p>
Bouldering is a style of rock climbing. Boulderers are to climb up the rock with bare hands without supporting ropes. Your friend supposed that it should be interesting and exciting, so he decided to come to bouldering gymnasium to practice bouldering. Since your friend has not tried bouldering yet, he chose beginnerâs course. However, in the beginnerâs course, he found that some of two stones have too distant space between them, which might result his accidentally failure of grabbing certain stone and falling off to the ground and die! He gradually becomes anxious and wonders whether the course is actually for the beginners. So, he asked you to write the program which simulates the way he climbs up and checks whether he can climb up to the goal successfully.
</p>
<p>
For the sake of convenience, we assume that a boulderer consists of 5 line segments, representing his body, his right arm, his left arm, his right leg, and his left leg.
</p>
<p>
One of his end of the body is connected to his arms on their end points. And the other end of the body is connected to his legs on their end points, too. The maximum length of his body, his arms, and his legs are <i>A</i>, <i>B</i> and <i>C</i> respectively. He climbs up the wall by changing the length of his body parts from 0 to their maximum length, and by twisting them in any angle (in other word, 360 degrees). Refer the following figure representing the possible body arrangements.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bouldering1"><br>
<b>Figure 2: An example of possible body arrangements.</b>
</center>
<P>
5 line segments representing his body, arms and legs. The length of his body, arms and legs are 8, 3 and 4 respectively. The picture describes his head as a filled circle for better understanding, which has no meaning in this problem.
</p>
<p>
A boulderer climbs up the wall by grabbing at least three different rocks on the wall with his hands and feet. In the initial state, he holds 4 rocks with his hands and feet. Then he changes one of the holding rocks by moving his arms and/or legs. This is counted as one movement. His goal is to grab a rock named âdestination rockâ with one of his body parts. The rocks are considered as points with negligible size. You are to write a program which calculates the minimum number of movements required to grab the destination rock.
</p>
<H2>Input</H2>
<p>
The input data looks like the following lines:
</p>
<p>
<i>n</i><br>
<i>A B C</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub><br>
<i>x</i><sub>3</sub> <i>y</i><sub>3</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub><br>
</p>
<p>
The first line contains <i>n</i> (5 ≤ <i>n</i> ≤ 30), which represents the number of rocks.
</p>
<p>
The second line contains three integers <i>A</i>, <i>B</i>, <i>C</i> (1 ≤ <i>A</i>, <i>B</i>, <i>C</i> ≤ 50), which represent the length of body, arms, and legs of the climber respectively.
</p>
<p>
The last <i>n</i> lines describes the location of the rocks. The <i>i</i>-th contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> (0 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 100), representing the <i>x</i> and <i>y</i>-coordinates of the <i>i</i>-th rock.
</p>
<p>
In the initial state, the boulderer is grabbing the 1st rock with his right hand, 2nd with his left hand, 3rd with his right foot, and 4th with left foot.
</p>
<p>
You may assume that the first 4 rocks are close to each other so that he can grab them all in the way described above.
</p>
<p>
The last rock is the destination rock.
</p>
<H2>Output</H2>
<p>
Your program should output the minimum number of movements to reach the destination stone.
</p>
<p>
If it is impossible to grab the destination stone, output -1.
</p>
<p>
You may assume that, if <i>A</i>, <i>B</i>, <i>C</i> would be changed within 0.001, the answer would not change.
</p>
<p>
Following figures represent just an example of how the boulderer climbs up to the destination in minimum number of movements. Note that the minimum number of movements can be obtained, by taking different way of climbing up, shortening the parts, rotating parts etc.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bouldering2"><br>
<b>Figure 3: An example of minimum movement for sample input 1.</b>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bouldering3"><br>
<b>Figure 4: An example of minimum movement for sample input 2.</b>
</center>
<H2>Sample Input 1</H2>
<pre>
6
4 3 3
10 17
15 14
10 15
11 12
16 18
15 22
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
3
</pre>
<H2>Sample Input 2</H2>
<pre>
7
4 2 4
11 18
14 18
10 14
13 14
14 17
17 21
16 26
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
3
</pre>
<H2>Sample Input 3</H2>
<pre>
6
2 2 4
12 22
13 21
14 15
10 16
16 24
10 35
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
-1
</pre>
<H2>Sample Input 4</H2>
<pre>
6
2 3 3
11 22
12 20
10 15
11 17
13 23
16 22
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>
-1
</pre>
|
p03379 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>When <var>l</var> is an odd number, the median of <var>l</var> numbers <var>a_1, a_2, ..., a_l</var> is the <var>(\frac{l+1}{2})</var>-th largest value among <var>a_1, a_2, ..., a_l</var>.</p>
<p>You are given <var>N</var> numbers <var>X_1, X_2, ..., X_N</var>, where <var>N</var> is an even number.
For each <var>i = 1, 2, ..., N</var>, let the median of <var>X_1, X_2, ..., X_N</var> excluding <var>X_i</var>, that is, the median of <var>X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N</var> be <var>B_i</var>.</p>
<p>Find <var>B_i</var> for each <var>i = 1, 2, ..., N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200000</var></li>
<li><var>N</var> is even.</li>
<li><var>1 \leq X_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>X_1</var> <var>X_2</var> ... <var>X_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.
The <var>i</var>-th line should contain <var>B_i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 4 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
3
3
4
</pre>
<ul>
<li>Since the median of <var>X_2, X_3, X_4</var> is <var>4</var>, <var>B_1 = 4</var>.</li>
<li>Since the median of <var>X_1, X_3, X_4</var> is <var>3</var>, <var>B_2 = 3</var>.</li>
<li>Since the median of <var>X_1, X_2, X_4</var> is <var>3</var>, <var>B_3 = 3</var>.</li>
<li>Since the median of <var>X_1, X_2, X_3</var> is <var>4</var>, <var>B_4 = 4</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
5 5 4 4 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
4
4
4
4
4
</pre></section>
</div>
</span> |
p00806 |
<H1><font color="#000">Problem D:</font> 77377</H1>
<p>
At the risk of its future, International Cellular Phones Corporation (ICPC) invests its resources in developing new mobile phones, which are planned to be equipped with Web browser, mailer, instant messenger, and many other advanced communication tools. Unless members of ICPC can complete this stiff job, it will eventually lose its market share.
</p>
<p>
You are now requested to help ICPC to develop intriguing text input software for small mobile terminals. As you may know, most phones today have twelve buttons, namely, ten number buttons from "<span>0</span>" to "<span>9</span>" and two special buttons "<span>*</span>" and "<span>#</span>". Although the company is very ambitious, it has decided to follow today's standards and conventions. You should not change the standard button layout, and should also pay attention to the following standard button assignment.
</p>
<table border=0>
<tr>
<td width="80">button</td><td width="80"> letters</td><td width="80"> button </td><td width="80">letters</td>
</tr>
<tr>
<td>2 </td><td> a, b, c </td><td> 6 </td><td> m, n, o</td>
</tr>
<tr>
<td>3 </td><td> d, e, f </td><td> 7 </td><td> p, q, r, s</td>
</tr>
<tr>
<td>4 </td><td> g, h, i </td><td>8 </td><td> t, u, v</td>
</tr>
<tr>
<td>5 </td><td> j, k, l </td><td> 9 </td><td> w, x, y, z</td>
</tr>
</table>
<p>
This means that you can only use eight buttons for text input.
</p>
<p>
Most users of current ICPC phones are rushed enough to grudge wasting time on even a single button press. Your text input software should be economical of users' time so that a single button press is suffcient for each character input. In consequence, for instance, your program should accept a sequence of button presses "<span>77377</span>" and produce the word "<span>press</span>". Similarly, it should translate "<span>77377843288866</span>" into "press the button".
</p>
<p>
Ummm... It seems impossible to build such text input software since more than one English letter is represented by a digit!. For instance, "<span>77377</span>" may represent not only "press" but also any one of 768 (= 4 × 4 × 3 × 4 × 4) character strings. However, we have the good news that the new model of ICPC mobile phones has enough memory to keep a dictionary. You may be able to write a program that filters out <i>false words</i>, i.e., strings not listed in the dictionary.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets, each of which represents a dictionary and a sequence of button presses in the following format.
</p>
<pre>
<i>n</i>
<i>word</i><sub>1</sub>
.
.
.
<i>word<sub>n</sub></i>
<i>sequence</i>
</pre>
<p>
<i>n</i> in the first line is a positive integer, representing the number of words in the dictionary. The next <i>n</i> lines, each representing a word in the dictionary, only contain lower case letters from `<span>a</span>' to `<span>z</span>'. The order of words in the dictionary is arbitrary (not necessarily in the lexicographic order). No words occur more than once in the dictionary. The last line, sequence, is the sequence of button presses, and only contains digits from `<span>2</span>' to `<span>9</span>'.
</p>
<p>
You may assume that a dictionary has at most one hundred words and that the length of each word is between one and fifty, inclusive. You may also assume that the number of input digits in the <i>sequence</i> is between one and three hundred, inclusive.
</p>
<p>
A line containing a zero indicates the end of the input.
</p>
<H2>Output</H2>
<p>
For each data set, your program should print all sequences that can be represented by the input sequence of button presses. Each sequence should be a sequence of words in the dictionary, and should appear in a single line. The order of lines does not matter.
</p>
<p>
Two adjacent words in a line should be separated by a single space character and the last word should be followed by a single period (`<span>.</span>').
</p>
<p>
Following those output lines, your program should also print a terminating line consisting solely of two hyphens (`<span>--</span>'). If there are no corresponding sequences of words, your program should only print the terminating line.
</p>
<p>
You may assume that for each data set the number of output lines is at most twenty, excluding the terminating line.
</p>
<H2>Sample Input</H2>
<pre>
5
push
press
the
button
bottom
77377843288866
4
i
am
going
go
42646464
3
a
b
c
333
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
press the button.
--
i am going.
i am go go i.
--
--
</pre>
|
p01714 |
<h1>åé¡ C : Apples </h1>
<h2>å顿</h2>
<p>
ãããšããã«éã®è
ã«èªä¿¡ããã€çåž«ãããŸããïŒ
çåž«ã¯ããæ¥ïŒããŠã£ãªã¢ã ãã«ãšããã¹ã€ã¹äººãïŒæ¯åã®é ã«ããããä¹ããŠé ãããç¢ã§æã¡èœãšãããã©ãŒãã³ã¹ã§æåã«ãªã£ãããšããã話ãèããŸããïŒ
ãããèããŠ"èªåã®ã»ãããã£ãšåã!!"ãšæã£ãçåž«ã¯åããŠãã人ã®äžã«ããããä¹ããŠæã¡ã¬ãããã©ãŒãã³ã¹ãèãã€ããŸããïŒ
</p>
<p>
çåž«ã¯åºå Žã« <var>N</var> 人ã®äººãéãïŒããããã®äººã®äžã«ããããä¹ããŸããïŒ
<var>i</var> çªç®ã®äººã¯æå» <var>t=0</var> ã®ãšãïŒåº§æš <var>(x_i,  y_i)</var> ã«ããŸãïŒ
ããããåäœæéãããé床ãã¯ãã« <var>(u_i,  v_i)</var> ã«ãããã£ãŠæ©ããŸãïŒ
ããªãã¡ïŒæå» <var>t  ≥  0</var> ã®ãšãïŒ<var>i</var> çªç®ã®äººã¯åº§æš <var>(x_i + t \times u_i  ,   y_i + t \times v_i)</var> ã«ããŸãïŒ
ããã§ïŒäººã
ã¯ååå°ããã®ã§ïŒåã座æšã«è€æ°ã®äººããããïŒåã座æšã§ããéã£ããã§ãããšä»®å®ããŸãïŒ
</p>
<p>
çåž«ã¯äººã
ãé©åãããããã«ïŒäžçºã®åŒŸäžžã§ã§ããã ãå€ãã®ããããæã¡èœãšãããšã«ããŸããïŒ
ç垫㯠<var>t ≥ 0</var> ã§ãããããªä»»æã®æå»ã«ïŒä»»æã®åº§æšããä»»æã®æ¹åã«åããŠåŒŸäžžãæŸã€ããšãã§ããŸãïŒ
æŸããã匟䞞ã¯ç¡éã®éãã§çŽç·è»éã§ç§»åãïŒãããã«åœãã£ãå Žå貫éããŠç§»åããŸãïŒ
匟䞞ãäžçºã ãæã€ãšãïŒæå€§ã§äœåã®ããããæã¡èœãšãããèšç®ããŠãã ããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã
<pre>
<var>N</var>
<var>x_0</var> <var>y_0</var> <var>u_0</var> <var>v_0</var>
<var>...</var>
<var>x_{N-1}</var> <var>y_{N-1}</var> <var>u_{N-1}</var> <var>v_{N-1}</var>
</pre>
<h2>åºå圢åŒ</h2>
<p>
æã¡èœãšãããããã®æå€§åæ°ã1è¡ã«åºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ N ≤ 200</var></li>
<li><var>0 ≤   |x_i|,   |y_i|   ≤ 10</var></li>
<li><var>0 ≤   |u_i|,   |v_i|   ≤ 3</var></li>
<li>å
¥åå€ã¯ãã¹ãп޿°ã§ããã</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5
0 0 0 0
1 0 -1 1
-1 0 1 -1
1 1 -1 1
-1 -1 1 -1
</pre>
<h3>åºåäŸ 1</h3>
<pre>
5
</pre>
<p>
æå»ïŒã«ïŒäººãïœè»žäžã«äžŠã¶ã®ã§æå€§ïŒã€ã®ããããæã¡èœãšããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
5
0 0 0 0
1 0 1 0
-1 0 -1 0
1 1 1 1
-1 -1 -1 -1
</pre>
<h3>åºåäŸ 2</h3>
<pre>
3
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
15
-10 9 2 1
2 10 0 -1
-10 -4 0 -3
-2 8 0 -1
0 -10 -1 -2
-8 5 0 -1
-7 -8 -3 1
10 -6 -2 -3
9 -6 1 0
10 -5 3 1
10 1 0 -3
-4 7 0 -1
10 -9 2 2
2 -5 -1 1
9 -10 3 1
</pre>
<h3>åºåäŸ 3</h3>
<pre>
5
</pre>
|
p03729 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three strings <var>A</var>, <var>B</var> and <var>C</var>. Check whether they form a <em>word chain</em>.</p>
<p>More formally, determine whether both of the following are true:</p>
<ul>
<li>The last character in <var>A</var> and the initial character in <var>B</var> are the same.</li>
<li>The last character in <var>B</var> and the initial character in <var>C</var> are the same.</li>
</ul>
<p>If both are true, print <code>YES</code>. Otherwise, print <code>NO</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>A</var>, <var>B</var> and <var>C</var> are all composed of lowercase English letters (<code>a</code> - <code>z</code>).</li>
<li><var>1 †|A|, |B|, |C| †10</var>, where <var>|A|</var>, <var>|B|</var> and <var>|C|</var> are the lengths of <var>A</var>, <var>B</var> and <var>C</var>, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> or <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>rng gorilla apple
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>They form a word chain.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>yakiniku unagi sushi
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p><var>A</var> and <var>B</var> form a word chain, but <var>B</var> and <var>C</var> do not.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>a a a
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>aaaaaaaaab aaaaaaaaaa aaaaaaaaab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>NO
</pre></section>
</div>
</span> |
p01201 |
<H1><font color="#000"></font>Exact Arithmetic</H1>
<!-- Problem H -->
<p>
Let <i>X</i> be a set of all rational numbers and all numbers of form <i>q</i>√<i>r</i>, where <i>q</i> is a non-zero rational number and <i>r</i>
is an integer greater than 1. Here <i>r</i> must not have a quadratic number except for 1 as its divisor. Also, let <i>X</i><sup>*</sup> be a
set of all numbers which can be expressed as a sum of one or more elements in <i>X</i>.
</p>
<p>
A machine <i>Y</i> is a stack-based calculator which operates on the values in <i>X</i><sup>*</sup> and has the instructions shown in the table below.
</p>
<center>
<table border="1" cellspacing="0" cellpadding="4">
<tr>
<td><p>push <i>n</i></p></td>
<td><p>Pushes an integer specified in the operand onto the stack.</p></td>
</tr>
<tr>
<td><p>add</p></td>
<td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> + <i>x</i><sub>1</sub>).</p></td>
</tr>
<tr>
<td><p>sub</p></td>
<td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> - <i>x</i><sub>1</sub> ).</p></td>
</tr>
<tr>
<td><p>mul</p></td>
<td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> × <i>x</i><sub>1</sub> ).
</p></td>
</tr>
<tr>
<td><p>div</p></td>
<td><p>Pops two values <i>x</i><sub>1</sub> and <i>x</i><sub>2</sub> from the top of the stack in this order, then pushes (<i>x</i><sub>2</sub> ÷ <i>x</i><sub>1</sub>).
<i>x</i><sub>1</sub> must be a non-zero value in <i>X</i> (<i>not</i> <i>X</i><sup>*</sup>).
</p></td>
</tr>
<tr>
<td><p>sqrt</p></td>
<td><p>Pops one value <i>x</i> from the stack and pushes the square root of <i>x</i>. <i>x</i> must be a non-negative rational number.
</p></td>
</tr>
<tr>
<td><p>disp</p></td>
<td><p>Pops one value <i>x</i> from the stack, and outputs the string representation of the value <i>x</i> to the display. The representation rules are stated later.
</p></td>
</tr>
<tr>
<td><p>stop</p></td>
<td><p>Terminates calculation. The stack must be empty when this instruction is called.
</p></td>
</tr>
</table>
<p>Table 1: Instruction Set for the Machine Y</p>
</center>
<p>
A sufficient number of values must exist in the stack on execution of every instruction. In addition, due to the
limitation of the machine Y, no more values can be pushed when the stack already stores as many as 256 values.
Also, there exist several restrictions on values to be pushed onto the stack:
</p>
<ul>
<li> For rational numbers, neither numerator nor denominator in the irreducible form may exceed 32,768 in its absolute value.</li>
<li> For any element in <i>X</i> of the form <i>q</i>√<i>r</i> = (<i>a</i>/<i>b</i>)√<i>r</i>, |<i>a</i>√<i>r</i>| ≤ 32,768 and |<i>b</i>| ≤ 32,768.</li>
<li> For any element in <i>X</i><sup>*</sup>, each term in the sum must satisfy the above conditions.
</ul>
<p>
The rules for the string representations of the values (on the machine Y) are as follows:
</p>
<ul>
<li> A rational number is represented as either an integer or an irreducible fraction with a denominator greater
than 1. A fraction is represented as "<<i>numerator</i>>/<<i>denominator</i>>". A sign symbol - precedes in case of a negative number.</li>
<li> A number of the form <i>q</i>√<i>r</i> is represented as "<<i>string representation of q</i>><sup>*</sup>sqrt(<i>r</i>)" except for the case
with <i>q</i> = ±1, in which the number is represented as "sqrt(<i>r</i>)" (<i>q</i> = 1) or "-sqrt(<i>r</i>)" (<i>q</i> = -1).</li>
<li> For the sum of two or more elements of <i>X</i>, string representations of all the (non-zero) elements are con-
nected using the binary operator +. In this case, all terms with the same rooted number are merged into a
single term, and the terms must be shown in the ascending order of its root component. For the purpose of
this rule, all rational numbers are regarded to accompany √1.</li>
<li> There is exactly one space character before and after each of the binary operator +. No space character appears at any other place.</li>
</ul>
<p>
The followings are a few examples of valid string representations:
</p>
<pre>
0
1
-1/10
2*sqrt(2) + 1/2*sqrt(3) + -1/2*sqrt(5)
1/2 + sqrt(10) + -sqrt(30)
</pre>
<p>
Your task is to write a program that simulates the machine Y.
</p>
<H2>Input</H2>
<p>
The input is a sequence of instructions. Each line contains a single instruction. You may assume that every
instruction is called in a legal way. The instruction stop appears only once, at the end of the entire input.
</p>
<H2>Output</H2>
<p>
Output the strings which the machine Y will display. Write each string in a line.
</p>
<H2>Sample Input</H2>
<pre>
push 1
push 2
sqrt
div
push 1
push 3
sqrt
div
add
disp
push 8
sqrt
push 3
push 2
sqrt
mul
add
disp
stop
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1/2*sqrt(2) + 1/3*sqrt(3)
5*sqrt(2)
</pre>
|
p04003 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke's town has a subway system, consisting of <var>N</var> stations and <var>M</var> railway lines. The stations are numbered <var>1</var> through <var>N</var>. Each line is operated by a company. Each company has an identification number.</p>
<p>The <var>i</var>-th ( <var>1 \leq i \leq M</var> ) line connects station <var>p_i</var> and <var>q_i</var> bidirectionally. There is no intermediate station. This line is operated by company <var>c_i</var>.</p>
<p>You can change trains at a station where multiple lines are available.</p>
<p>The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is <var>1</var> yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of <var>1</var> yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again.</p>
<p>Snuke is now at station <var>1</var> and wants to travel to station <var>N</var> by subway. Find the minimum required fare.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>0 \leq M \leq 2Ã10^5</var></li>
<li><var>1 \leq p_i \leq N</var> <var>(1 \leq i \leq M)</var></li>
<li><var>1 \leq q_i \leq N</var> <var>(1 \leq i \leq M)</var></li>
<li><var>1 \leq c_i \leq 10^6</var> <var>(1 \leq i \leq M)</var></li>
<li><var>p_i \neq q_i</var> <var>(1 \leq i \leq M)</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>p_1</var> <var>q_1</var> <var>c_1</var>
:
<var>p_M</var> <var>q_M</var> <var>c_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum required fare. If it is impossible to get to station <var>N</var> by subway, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2 1
2 3 1
3 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Use company <var>1</var>'s lines: <var>1</var> â <var>2</var> â <var>3</var>. The fare is <var>1</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 11
1 3 1
1 4 2
2 3 1
2 5 1
3 4 3
3 6 3
3 7 3
4 8 4
5 6 1
6 7 5
7 8 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>First, use company <var>1</var>'s lines: <var>1</var> â <var>3</var> â <var>2</var> â <var>5</var> â <var>6</var>. Then, use company <var>5</var>'s lines: <var>6</var> â <var>7</var> â <var>8</var>. The fare is <var>2</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre></section>
</div>
</span> |
p00943 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem I
Routing a Marathon Race</h2>
<p>
As a member of the ICPC (Ibaraki Committee of Physical Competitions), you are responsible for planning the route of a marathon event held in the City of Tsukuba. A great number of runners, from beginners to experts, are expected to take part.
</p>
<p>
You have at hand a city map that lists all the street segments suited for the event and all the junctions on them. The race is to start at the junction in front of Tsukuba High, and the goal is at the junction in front of City Hall, both of which are marked on the map.
</p>
<p>
To avoid congestion and confusion of runners of divergent skills, the route should not visit the same junction twice. Consequently, although the street segments can be used in either direction, they can be included at most once in the route. As the main objective of the event is in recreation and health promotion of citizens, time records are not important and the route distance can be arbitrarily decided.
</p>
<p>
A number of personnel have to be stationed at every junction on the route. Junctions <i>adjacent</i> to them, i.e., junctions connected directly by a street segment to the junctions on the route, also need personnel staffing to keep casual traffic from interfering the race. The same number of personnel is required when a junction is on the route and when it is adjacent to one, but different junctions require different numbers of personnel depending on their sizes and shapes, which are also indicated on the map.
</p>
<p>
The municipal authorities are eager in reducing the costs including the personnel expense for
events of this kind. Your task is to write a program that plans a route with the minimum
possible number of personnel required and outputs that number.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case representing a summary city map, formatted as follows.<br>
<br>
$n$ $m$<br>
$c_1$<br>
...<br>
$c_n$<br>
$i_1$ $j_1$<br>
...<br>
$i_m$ $j_m$<br>
<br>
The first line of a test case has two positive integers, $n$ and $m$. Here, $n$ indicates the number of junctions in the map $(2 \leq n \leq 40)$, and $m$ is the number of street segments connecting adjacent junctions. Junctions are identified by integers 1 through $n$.
</p>
<p>
Then comes $n$ lines indicating numbers of personnel required. The $k$-th line of which, an integer $c_k$ $(1 \leq c_k \leq 100)$, is the number of personnel required for the junction $k$.
</p>
<p>
The remaining $m$ lines list street segments between junctions. Each of these lines has two integers $i_k$ and $j_k$, representing a segment connecting junctions $i_k$ and $j_k$ $(i_k \ne j_k)$. There is at most one street segment connecting the same pair of junctions.
</p>
<p>
The race starts at junction 1 and the goal is at junction $n$. It is guaranteed that there is at least one route connecting the start and the goal junctions.
</p>
<h3>Output</h3>
<p>
Output an integer indicating the minimum possible number of personnel required.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_RoutingAMarathonRace"><br>
<p>
Figure I.1. The Lowest-Cost Route for Sample Input 1
</p>
</center>
<p>
Figure I.1 shows the lowest-cost route for Sample Input 1. The arrows indicate the route and the circles painted gray are junctions requiring personnel assignment. The minimum number of required personnel is 17 in this case.
</p>
<h3>Sample Input 1</h3>
<pre>6 6
3
1
9
4
3
6
1 2
1 4
2 6
5 4
6 5
3 2</pre>
<h3>Sample Output 1</h3>
<pre>17</pre>
|
p01651 |
<h2>Problem Statement</h2>
<p>
Let <var>b_i(x)</var> be the <var>i</var>-th least significant bit of <var>x</var>, i.e. the <var>i</var>-th least significant digit of <var>x</var> in base 2 (<var>i \geq 1</var>).
For example, since <var>6 = (110)_2</var>, <var>b_1(6) = 0</var>, <var>b_2(6) = 1</var>, <var>b_3(6) = 1</var>, <var>b_4(6) = 0</var>, <var>b_5(6) = 0</var>, and so on.
</p>
<p>
Let <var>A</var> and <var>B</var> be integers that satisfy <var>1 \leq A \leq B \leq 10^{18}</var>,
and <var>k_i</var> be the number of integers <var>x</var> such that <var>A \leq x \leq B</var> and <var>b_i(x) = 1</var>.
</p>
<p>
Your task is to write a program that determines <var>A</var> and <var>B</var> for a given <var>\{k_i\}</var>.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets.
The number of datasets is no more than 100,000.
Each dataset has the following format:
</p>
<pre>
<var>n</var>
<var>k_1</var>
<var>k_2</var>
...
<var>k_n</var>
</pre>
<p>
The first line of each dataset contains an integer <var>n</var> (<var>1 \leq n \leq 64</var>).
Then <var>n</var> lines follow, each of which contains <var>k_i</var> (<var>0 \leq k_i \leq 2^{63} - 1</var>).
For all <var>i > n</var>, <var>k_i = 0</var>.
</p>
<p>
The input is terminated by <var>n = 0</var>.
Your program must not produce output for it.
</p>
<h2>Output</h2>
<p>
For each dataset, print one line.
</p>
<ul>
<li> If <var>A</var> and <var>B</var> can be uniquely determined, output <var>A</var> and <var>B</var>. Separate the numbers by a single space.</li>
<li> If there exists more than one possible pair of <var>A</var> and <var>B</var>, output <code>Many</code> (without quotes).</li>
<li> Otherwise, i.e. if there exists no possible pair, output <code>None</code> (without quotes).</li>
</ul>
<h2>Sample Input</h2>
<pre>
3
2
2
1
49
95351238128934
95351238128934
95351238128932
95351238128936
95351238128936
95351238128936
95351238128960
95351238128900
95351238128896
95351238129096
95351238128772
95351238129096
95351238129096
95351238126156
95351238131712
95351238131712
95351238149576
95351238093388
95351238084040
95351237962316
95351238295552
95351237911684
95351237911684
95351235149824
95351233717380
95351249496652
95351249496652
95351226761216
95351226761216
95351082722436
95351082722436
95352054803020
95352156464260
95348273971200
95348273971200
95354202286668
95356451431556
95356451431556
95346024826312
95356451431556
95356451431556
94557999988736
94256939803780
94256939803780
102741546035788
87649443431880
87649443431880
140737488355328
32684288648324
64
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
11
0
0
1
1
1
0
1
1
1
1
1
63
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
4
1
1
1
1
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1 4
123456789101112 314159265358979
None
2012 2012
None
Many
</pre> |
p03396 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Yui loves shopping. She lives in Yamaboshi City and there is a train service in the city. The city can be modelled as a very long number line. Yui's house is at coordinate <var>0</var>.</p>
<p>There are <var>N</var> shopping centres in the city, located at coordinates <var>x_{1}, x_{2}, ..., x_{N}</var> respectively. There are <var>N + 2</var> train stations, one located at coordinate <var>0</var>, one located at coordinate <var>L</var>, and one located at each shopping centre.</p>
<p>At time <var>0</var>, the train departs from position <var>0</var> to the positive direction. The train travels at a constant speed of <var>1</var> unit per second. At time <var>L</var>, the train will reach the last station, the station at coordinate <var>L</var>. The train immediately moves in the opposite direction at the same speed. At time <var>2L</var>, the train will reach the station at coordinate <var>0</var> and it immediately moves in the opposite direction again. The process repeats indefinitely.</p>
<p>When the train arrives at a station where Yui is located, Yui can board or leave the train immediately. At time <var>0</var>, Yui is at the station at coordinate <var>0</var>. </p>
<p>Yui wants to go shopping in all <var>N</var> shopping centres, in any order, and return home after she finishes her shopping. She needs to shop for <var>t_{i}</var> seconds in the shopping centre at coordinate <var>x_{i}</var>. <strong>She must finish her shopping in one shopping centre before moving to the next shopping centre.</strong> Yui can immediately start shopping when she reaches a station with a shopping centre and she can immediately board the train when she finishes shopping.</p>
<p>Yui wants to spend the minimum amount of time to finish her shopping. Can you help her determine the minimum number of seconds required to complete her shopping?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300000</var></li>
<li><var>1 \leq L \leq 10^{9}</var></li>
<li><var>0 < x_{1} < x_{2} < ... < x_{N} < L</var></li>
<li><var>1 \leq t_{i} \leq 10^{9}</var></li>
<li>All values in the input are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>1000</var> points will be awarded for passing the testset satisfying <var>1 \leq N \leq 3000</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>L</var>
<var>x_{1}</var> <var>x_{2}</var> <var>...</var> <var>x_{N}</var>
<var>t_{1}</var> <var>t_{2}</var> <var>...</var> <var>t_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum time (in seconds) required for Yui to finish shopping at all <var>N</var> shopping centres and return home.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 10
5 8
10 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>40
</pre>
<p>Here's one possible way for Yui to finish her shopping :</p>
<ul>
<li>
<p>Travel to the station at coordinate <var>8</var> with the train. She arrives at coordinate <var>8</var> at time <var>8</var>.</p>
</li>
<li>
<p>Shop in the shopping centre at coordinate <var>8</var>. She finishes her shopping at time <var>12</var>.</p>
</li>
<li>
<p>The train arrives at coordinate <var>8</var> at time <var>12</var>. She boards the train which is currently moving in the negative direction.</p>
</li>
<li>
<p>She arrives at coordinate <var>5</var> at time <var>15</var>. She finishes her shopping at time <var>25</var>.</p>
</li>
<li>
<p>The train arrives at coordinate <var>5</var> at time <var>25</var>. She boards the train which is currently moving in the positive direction.</p>
</li>
<li>
<p>She arrives at coordinate <var>L = 10</var> at time <var>30</var>. The train starts moving in the negative direction immediately.</p>
</li>
<li>
<p>She arrives at coordinate <var>0</var> at time <var>40</var>, ending the trip.</p>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 10
5 8
10 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>60
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 100
10 19 28 47 68
200 200 200 200 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1200
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8 1000000000
2018 123456 1719128 1929183 9129198 10100101 77777777 120182018
99999999 1000000000 1000000000 11291341 1 200 1 123812831
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>14000000000
</pre>
<p>Beware of overflow issues.</p></section>
</div>
</span> |
p00410 | <h1>ãã³ãžã§ã³ïŒ</h1>
ã
<p>
ããªãã¯æåãªåéºå®¶ã§ããããã§ã«ïŒã€ã®ãã³ãžã§ã³ãå¶èŠãããããªãã¯ããã€ãã®éè·¯ãšå®ç©åº«ãèšãããæ°ããªãã³ãžã§ã³ã®å°å³ãå
¥æãããå°å³ã«ã¯ããããã®å®ç©åº«ã«ãã財å®ã®äŸ¡å€ãæžãããŠããã
</p>
<p>
ããªãã¯ãä»»æã®å®ç©åº«ãããã³ãžã§ã³ã«äŸµå
¥ããä»»æã®å®ç©åº«ãããã³ãžã§ã³ãè±åºããããšãã§ããã䟵å
¥ããè±åºãŸã§ã®éã«ãéè·¯ãéã£ãŠå®ç©åº«ã®éãäœåºŠãç§»åããŠã蚪ããå®ç©åº«ã®è²¡å®ãæã«å
¥ããããšãã§ãããå°å³ã«ããã°ãåéè·¯ã¯åæ¹åã«éãããšãã§ããã©ã®å®ç©åº«ããã©ã®å®ç©åº«ã«ãïŒæ¬ä»¥äžã®éè·¯ãçµç±ããŠãã©ãã€ãããšãã§ãããããããéè·¯ã¯äžåºŠéããšäºåºŠç®ä»¥éã¯äžåºŠç®ãšåãåãã«ããéãããšãã§ããªããªããå®ç©åº«ã®è²¡å®ã¯ããããæåã«èšªãããšãã ãæã«å
¥ããããšãã§ããããã®ãšããæã«ãã財å®ã®äŸ¡å€ã®ç·åãæå€§ã«ãããã
</p>
<p>
å°å³ã®æ
å ±ãäžãããããšãã䟵å
¥ããè±åºãŸã§ã®éã«æã«ãããããšã®ã§ãã財å®ã®äŸ¡å€ã®ç·åã®æå€§å€ãæ±ããããã°ã©ã ãäœæããããã ããå®ç©åº«ã«ã¯1ããNãŸã§ã®çªå·ãå²ãåœãŠãããŠãããã®ãšããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$N$ $M$
$v_1$
$v_2$
:
$v_N$
$s_1$ $t_1$
$s_2$ $t_2$
:
$s_M$ $t_M$
</pre>
<p>
ïŒè¡ç®ã«å®ç©åº«ã®æ°$N$ ($2 \leq N \leq 10^5$)ãšéè·¯ã®æ°$M$ ($1 \leq M \leq 2 \times 10^5$)ãäžãããããç¶ã$N$è¡ã«ã$i$çªç®ã®å®ç©åº«ã«çœ®ãããŠãã財å®ã®äŸ¡å€$v_i$ ($1 \leq v_i \leq 1000$)ãäžãããããç¶ã$M$è¡ã«ãããããã®éè·¯ã®äž¡ç«¯ã«æ¥ç¶ãããŠããå®ç©åº«ã®çªå·$s_i$,$t_i$ ($1 \leq s_i,t_i \leq N, s_i \ne t_i$)ãäžããããããã ããåãå®ç©åº«å士ãã€ãªãéè·¯ã¯ïŒåºŠä»¥äžäžããããªãã
</p>
<h2>åºå</h2>
<p>
åŸãããšãã§ãã財å®ã®äŸ¡å€ã®ç·åã®æå€§å€ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
5 4
2
1
3
6
4
1 2
2 3
2 4
4 5
</pre>
<h3>åºåäŸ</h3>
<pre>
14
</pre>
|
p00040 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ã¢ãã£ã³æå·</H1>
<p>
ç°¡åãªæå·æ³ã®äžã€ã«ãã¢ãã£ã³æå·ãšãããã®ããããŸãããŸããã¢ã«ãã¡ããã aãz ã a = 0, b = 1, c = 2,..., x = 23, y = 24, z = 25 ãš 0ã25 ã®æ°åã«çœ®ãæããŸãããããŠã以äžã®åŒã§ãåæã®ã¢ã«ãã¡ãããã眮æããŸãã
</p>
<center>
<!--
<p>
F(γ) = (αã»Î³ïŒÎ²) mod 26
</p>
-->
<p>
$F(\gamma) = (\alpha \cdot \gamma + \beta)$ mod $26$
</p>
</center>
<p>
ãã ããmod 26 㯠26 ã§å²ã£ãäœãã衚ããŸããäŸãã°ã$\alpha = 3, \beta = 2$ ã®ãšããã¢ã«ãã¡ãããã® 'a' (=0) ã¯ã$F(0) = (3 \cdot 0 + 2)$ mod $26 = 2$ ã§ 'c' ã«ãã¢ã«ãã¡ãããã® 'n' (=13) 㯠$F(13) = (3 \cdot 13 + 2)$ mod $26 = 15$ ã§ 'p' ã«çœ®æãããŸãã
ãã®ãšãã$\gamma$ ã«å¯Ÿãã $F(\gamma)$ ãå¿
ã 1 察 1 ã§å¯Ÿå¿ä»ããããããã«ã$\alpha$ ãš $\beta$ ã¯æ
éã«éžã°ããŠãããã®ãšããŸãïŒ$\alpha$ ãš 26 ãäºãã«çŽ ã§ããããšãæ¡ä»¶ïŒã$\alpha = 4, \beta = 7$ ã®ãšãã®ããã«ã$F('a') = 7, F('n') = 7$ ãšã'a' ã 'n' ãåã 'h' ã«çœ®æããããããªããšã¯ãããŸããããŸããã¢ã«ãã¡ããã以å€ã®æåã¯çœ®æãããŸããã
</p>
<p>
æå·åãããæååãå
ã®æç« ã«åŸ©å·ãããã®ãåºåããããã°ã©ã ãäœæããŠãã ãããå
ã®æç« ã«ã¯ãããŒã¯ãŒããšããŠ
</p>
<pre>
that
this
</pre>
<p>
ã®ãããããå¿
ãå«ãŸããŠãããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããïŒè¡ç®ã«ããŒã¿ã»ããæ° $n$ ($n \leq 30$) ãäžããããŸããç¶ã㊠$n$ è¡ã®ããŒã¿ãäžããããŸããåããŒã¿ã»ããã«è±å°æåãšç©ºçœãããªã 256 æå以å
ã®æå·åãããæç« ãïŒè¡ã«äžããããŸãã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠã埩å·ããå
ã®æç« ãïŒè¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
1
y eazqyp pnop pngtg ye obmpngt xmybp mr lygw
</pre>
<H2>Output for the Sample Input</H2>
<pre>
i submit that there is another point of view
</pre>
|
p02587 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> strings of lowercase English letters: <var>S_1, S_2, \cdots, S_N</var>.</p>
<p>Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of his choice.</p>
<p>The cost of using the string <var>S_i</var> once is <var>C_i</var>, and the cost of using it multiple times is <var>C_i</var> multiplied by that number of times.</p>
<p>Find the minimum total cost needed to choose strings so that Takahashi can make a palindrome.</p>
<p>If there is no choice of strings in which he can make a palindrome, print <var>-1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>1 \leq |S_i| \leq 20</var></li>
<li><var>S_i</var> consists of lowercase English letters.</li>
<li><var>1 \leq C_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S_1</var> <var>C_1</var>
<var>S_2</var> <var>C_2</var>
<var>:</var>
<var>S_N</var> <var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total cost needed to choose strings so that Takahashi can make a palindrome, or <var>-1</var> if there is no such choice.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
ba 3
abc 4
cbaa 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>We have <code>ba</code>, <code>abc</code>, and <code>cbaa</code>.</p>
<p>For example, we can use <code>ba</code> once and <code>abc</code> once for a cost of <var>7</var>, then concatenate them in the order <code>abc</code>, <code>ba</code> to make a palindrome.
Also, we can use <code>abc</code> once and <code>cbaa</code> once for a cost of <var>9</var>, then concatenate them in the order <code>cbaa</code>, <code>abc</code> to make a palindrome.</p>
<p>We cannot make a palindrome for a cost less than <var>7</var>, so we should print <var>7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
abcab 5
cba 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre>
<p>We can choose <code>abcab</code> once and <code>cba</code> twice, then concatenate them in the order <code>abcab</code>, <code>cba</code>, <code>cba</code> to make a palindrome for a cost of <var>11</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
ab 5
cba 3
a 12
ab 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre>
<p>We can choose <code>a</code> once, which is already a palindrome, but it is cheaper to concatenate <code>ab</code> and <code>cba</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2
abc 1
ab 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>-1
</pre>
<p>We cannot make a palindrome, so we should print <var>-1</var>.</p></section>
</div>
</span> |
p02790 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are <var>1</var>-digit positive integers <var>a</var> and <var>b</var>. Consider these two strings: the concatenation of <var>b</var> copies of the digit <var>a</var>, and the concatenation of <var>a</var> copies of the digit <var>b</var>. Which of these is lexicographically smaller?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a \leq 9</var></li>
<li><var>1 \leq b \leq 9</var></li>
<li><var>a</var> and <var>b</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3333
</pre>
<p>We have two strings <code>444</code> and <code>3333</code>. Between them, <code>3333</code> is the lexicographically smaller.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7777777
</pre></section>
</div>
</span> |
p03882 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>There are <var>N</var> cities in a two-dimensional plane.
The coordinates of the <var>i</var>-th city is <var>(x_i, y_i)</var>.
Initially, the amount of water stored in the <var>i</var>-th city is <var>a_i</var> liters.</p>
<p>Snuke can carry any amount of water from a city to another city.
However, water leaks out a bit while he carries it.
If he carries <var>l</var> liters of water from the <var>s</var>-th city to the <var>t</var>-th city, only <var>max(l-d_{s,t}, 0)</var> liters of water remains when he arrives at the destination.
Here <var>d_{s,t}</var> denotes the (Euclidean) distance between the <var>s</var>-th city and the <var>t</var>-th city.
He can perform arbitrary number of operations of this type.</p>
<p>Snuke wants to maximize the minimum amount of water among the <var>N</var> cities.
Find the maximum <var>X</var> such that he can distribute at least <var>X</var> liters of water to each city.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †15</var></li>
<li><var>0 †x_i, y_i, a_i †10^9</var></li>
<li>All values in the input are integers.</li>
<li>No two cities are at the same position.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var> <var>a_1</var>
:
<var>x_N</var> <var>y_N</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum of the minimum amount of water among the <var>N</var> cities.
The absolute error or the relative error must be at most <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 0 10
2 0 5
0 5 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6.500000000000
</pre>
<p>The optimal solution is to carry <var>3.5</var> liters of water from the 1st city to the 2nd city.
After the operation, both the 1st and the 2nd cities will have <var>6.5</var> liters of water, and the 3rd city will have <var>8</var> liters of water.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
335279264 849598327 822889311
446755913 526239859 548830120
181424399 715477619 342858071
625711486 448565595 480845266
647639160 467825612 449656269
160714711 336869678 545923679
61020590 573085537 816372580
626006012 389312924 135599877
547865075 511429216 605997004
561330066 539239436 921749002
650693494 63219754 786119025
849028504 632532642 655702582
285323416 611583586 211428413
990607689 590857173 393671555
560686330 679513171 501983447
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>434666178.237122833729
</pre></section>
</div>
</span> |
p00257 |
<H1>ãããããäœã</H1>
<p>
倪éåã¯ãåäŸäŒã®å¬ãã§ã¿ããªã§éã¹ãããã«ãããããäœããŸãããã²ãŒã ããããããããããã«ãããµãã ãããšããããã以å€ã®ããããã®ãã¹ã®ããã€ãã«ãïŒã€é²ããããïŒã€æ»ããã®ããã«æç€ºãæžã蟌ãã§ãããŸãããã«ãŒã¬ãããåããŠåºãæ°ã ãé²ã¿ãæ¢ãŸã£ããã¹ã«æç€ºãæžã蟌ãã§ããã°ããã®æç€ºã«åŸã£ãŠç§»åããŸãããã ããæç€ºã«åŸã£ãŠé²ãã å
ã®ãã¹ã®æç€ºã«ã¯åŸããŸããã
</p>
<p>
ã«ãŒã¬ããã¯ïŒããããæ°ãŸã§ã®éã®æ°ãç確çã§åºãããšãã§ãããã®ãšããŸãããŸãããããããã«éãããã倧ããªæ°ãåºããšãããæç€ºã«åŸããšãããããããå
ã«é²ãã§ããŸããšãã¯ãããããã«ç§»åããŸããæç€ºã«åŸã£ãŠæ»ããšãã«ããµãã ããããåã«æ»ã£ãŠããŸããšãã¯ããµãã ããã«æ»ãããšã«ããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_makingSugoroku">
</center>
<br/>
<p>
ãšããããã«ãŒã¬ãããšãã¹ã®æç€ºã«ãã£ãŠã¯ãããããã«ãã©ãã€ããªãå ŽåãåºãŠããŠããŸããŸããããšãã°ãå³ã®ãããªãããããäœã£ããšããŸããããïŒãšïŒããåºãªãã«ãŒã¬ããã䜿ããšãïŒïŒïŒã®é ã«åºãã°ãããããã«è¡ããŸãããã¯ããã«ïŒãåºãããã®åŸã¯äœãåºãŠãæ°žä¹
ã«ãããããã«ã¯ãã©ãçããŸããã倪éåã¯ããããšã¯ç¥ããã«èª¿åã«ä¹ã£ãŠãã¡ãã¡ã®ãã¹ã«æç€ºãæžã蟌ãã§ããŸããŸããã
</p>
<p>
ããã§ã倪éåã«ä»£ãã£ãŠãã«ãŒã¬ãããšãã¹ã®æç€ºã«ãã£ãŠã¯ããããããã«ãã©ãçããªãå Žåãçãããã©ããå€å®ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
max
n
d<sub>1</sub>
d<sub>2</sub>
.
.
.
d<sub>n</sub>
</pre>
<p>
ïŒè¡ç®ã«ã«ãŒã¬ãããåºãæ°ã®æå€§å€ max (2 ≤ max ≤ 250) ãäžããããïŒè¡ç®ã«ããµãã ãããšããããã以å€ã®ãã¹ã®æ° n (2 ≤ n ≤ 250) ãäžãããããç¶ã n è¡ã«åãã¹ã®æç€ºãè¡šãæ° d<sub>i</sub>(-n ≤ d<sub>i</sub> ≤ n) ãäžãããããd<sub>i</sub> ããŒãã®ãšãã¯æç€ºãæžããŠããªãããšããæ£ã®æ°ã®ãšã㯠|d<sub>i</sub>| é²ãæç€ºããè² ã®æ°ã®ãšã㯠|d<sub>i</sub>| æ»ãæç€ºã衚ãïŒããã§ã|x| 㯠x ã®çµ¶å¯Ÿå€ã衚ãïŒãå
¥åãããå€ã¯ãã¹ãп޿°ã§ããã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããªãã
</p>
<h2>åºå</h2>
<p>
åããŒã¿ã»ããããšã«å€å®çµæãïŒè¡ã«åºåãããã«ãŒã¬ãããšãã¹ã®æç€ºã«ãã£ãŠã¯ããããããã«ãã©ãçããªãå Žåãçãããšãã¯ãNGããããã§ãªããã°ãOKããåºåããã
</p>
<h2>å
¥åäŸ</h2>
<pre>
3
3
-2
1
0
2
4
2
0
-1
-2
2
2
-2
-2
0
</pre>
<h2>åºåäŸ</h2>
<pre>
OK
NG
NG
</pre>
|
p00607 |
<H1><font color="#000000">Problem C:</font> Emacs-like Editor</H1>
<p>
Emacs is a text editor which is widely used by many programmers.
</p>
<p>
The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be moved right, left, down, and up by pushing <span>f</span>, <span>b</span>, <span>n</span>, <span>p</span> with the Control Key respectively. In addition, cut-and-paste can be performed without the mouse.
</p>
<p>
Your task is to write a program which simulates key operations in the Emacs-like editor. The program should read a text and print the corresponding edited text.
</p>
<p>
The text consists of several lines and each line consists of zero or more alphabets and space characters. A line, which does not have any character, is a blank line.
</p>
<p>
The editor has a cursor which can point out a character or the end-of-line in the corresponding line. The cursor can also point out the end-of-line in a blank line.
</p>
<p>
In addition, the editor has a buffer which can hold either a string (a sequence of characters) or a linefeed.
</p>
<p>
The editor accepts the following set of commands (If the corresponding line is a blank line, the word "the first character" should be "the end-of-line"):
</p>
<ul>
<li>
<span>a</span><br>
Move the cursor to the first character of the current line.
</li>
<li>
<span>e</span><br>
Move the cursor to the end-of-line of the current line.
</li>
<li>
<span>p</span><br>
Move the cursor to the first character of the next upper line, if it exists.<br>
If there is no line above the current line, move the cursor to the first character of the current line.
</li>
<li>
<span>n</span><br>
Move the cursor to the first character of the next lower line, if it exists.<br>
If there is no line below the current line, move the cursor to the first character of the current line.
</li>
<li>
<span>f</span><br>
Move the cursor by one character to the right, unless the cursor points out the end-of-line.<br>
If the cursor points out the end-of-line and there is a line below the current line, move the cursor to the first character of the next lower line. Otherwise, do nothing.
</li>
<li>
<span>b</span><br>
Move the cursor by one character to the left, unless the cursor points out the first character.<br>
If the cursor points out the first character and there is a line above the current line, move the cursor to the end-of-line of the next upper line. Otherwise, do nothing.
</li>
<li>
<span>d</span><br>
If the cursor points out a character, delete the character (Characters and end-of-line next to the deleted character are shifted to the left).<br>
If the cursor points out the end-of-line and there is a line below, the next lower line is appended to the end-of-line of the current line (Lines below the current line are shifted to the upper). <br>Otherwise, do nothing.
</li>
<li>
<span>k</span><br>
If the cursor points out the end-of-line and there is a line below the current line, perform the command <span>d</span> mentioned above, and record a linefeed on the buffer.<br>
If the cursor does not point out the end-of-line, cut characters between the cursor (inclusive) and the end-of-line, and record them on the buffer. <!--Move the cursor to the end-of-line of the original line.--> After this operation, the cursor indicates the end-of-line of the current line.
</li>
<li>
<span>y</span><br>
If the buffer is empty, do nothing.<br>
If the buffer is holding a linefeed, insert the linefeed at the cursor. The cursor moves to the first character of the new line.<br>
If the buffer is holding characters, insert the characters at the cursor. The cursor moves to the character or end-of-line which is originally pointed by the cursor.
</li>
</ul>
<p>
The cursor position just after reading the text is the beginning of the first line, and the initial buffer is empty.
</p>
<H2>Input</H2>
<p>
The input consists of only one data-set which includes two parts. The first part gives a text consisting of several lines. The end of the text is indicated by a line (without quotes):
<pre>
"END_OF_TEXT"
</pre>
<p>
This line should not be included in the text.
</p>
<p>
Next part gives a series of commands. Each command is given in a line. The end of the commands is indicated by a character '<span>-</span>'.
</p>
<H2>Output</H2>
<p>
For the input text, print the text edited by the commands.
</p>
<H2>Constraints</H2>
<ul>
<li>The number of lines in the text given as input ≤ 10</li>
<li>The number of characters in a line given as input ≤ 20 </li>
<li>The number of commands ≤ 300 </li>
<li>The maximum possible number of lines in the text during operations ≤ 100 </li>
<li>The maximum possible number of characters in a line during operations ≤ 1000 </li>
</ul>
<H2>Sample Input</H2>
<pre>
hyo
ni
END_OF_TEXT
f
d
f
f
k
p
p
e
y
a
k
y
y
n
y
-
</pre>
<H2>Output for the Sample Input</H2>
<pre>
honihoni
honi
</pre>
|
p03928 | <span class="lang-en">
<p>Score : <var>2100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a board with an <var>N \times N</var> grid, and <var>N \times N</var> tiles.</p>
<p>Each side of a square that is part of the perimeter of the grid is attached with a socket.
That is, each side of the grid is attached with <var>N</var> sockets, for the total of <var>4 \times N</var> sockets.
These sockets are labeled as follows:</p>
<ul>
<li>The sockets on the top side of the grid: <var>U1, U2, ..., UN</var> from left to right</li>
<li>The sockets on the bottom side of the grid: <var>D1, D2, ..., DN</var> from left to right</li>
<li>The sockets on the left side of the grid: <var>L1, L2, ..., LN</var> from top to bottom</li>
<li>The sockets on the right side of the grid: <var>R1, R2, ..., RN</var> from top to bottom</li>
</ul>
<figure id="socket_id">
<img src="https://atcoder.jp/img/code-festival-2016-final/916ffede6e718801d689f189e658a9bb.png">
<figcaption>Figure: The labels of the sockets</figcaption>
</img></figure>
<p>Snuke can insert a tile from each socket into the square on which the socket is attached.
When the square is already occupied by a tile, the occupying tile will be pushed into the next square, and when the next square is also occupied by another tile, that another occupying tile will be pushed as well, and so forth.
Snuke cannot insert a tile if it would result in a tile pushed out of the grid.
The behavior of tiles when a tile is inserted is demonstrated in detail at Sample Input/Output <var>1</var>.</p>
<p>Snuke is trying to insert the <var>N \times N</var> tiles one by one from the sockets, to reach the state where every square contains a tile.
Here, he must insert exactly <var>U_i</var> tiles from socket <var>Ui</var>, <var>D_i</var> tiles from socket <var>Di</var>, <var>L_i</var> tiles from socket <var>Li</var> and <var>R_i</var> tiles from socket <var>Ri</var>.
Determine whether it is possible to insert the tiles under the restriction. If it is possible, in what order the tiles should be inserted from the sockets?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ300</var></li>
<li><var>U_i,D_i,L_i</var> and <var>R_i</var> are non-negative integers.</li>
<li>The sum of all values <var>U_i,D_i,L_i</var> and <var>R_i</var> is equal to <var>N \times N</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li><var>2000</var> points will be awarded for passing the test set satisfying <var>NâŠ40</var>.</li>
<li>Additional <var>100</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>U_1</var> <var>U_2</var> <var>...</var> <var>U_N</var>
<var>D_1</var> <var>D_2</var> <var>...</var> <var>D_N</var>
<var>L_1</var> <var>L_2</var> <var>...</var> <var>L_N</var>
<var>R_1</var> <var>R_2</var> <var>...</var> <var>R_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to insert the tiles so that every square will contain a tile, print the labels of the sockets in the order the tiles should be inserted from them, one per line. If it is impossible, print <code>NO</code> instead. If there exists more than one solution, print any of those.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 0 1
1 1 0
3 0 1
0 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>L1
L1
L1
L3
D1
R2
U3
R3
D2
</pre>
<p>Snuke can insert the tiles as shown in the figure below. An arrow indicates where a tile is inserted from, a circle represents a tile, and a number written in a circle indicates how many tiles are inserted before and including the tile.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/252110b5818dc7d972f77d90f99cb8cb.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
2 0
2 0
0 0
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p01915 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>K: AOR ã€ã«ã¡ããã®æçžŸ</h1>
<h2>åé¡</h2>
<p>
AOR ã€ã«ã¡ãã㯠$N$ åã®ã¬ããŒãã®ç¹æ°ã®ã¿ã§æçžŸã決ãŸãææ¥ãåããŠããã
AOR ã€ã«ã¡ããã¯åãææ¥ãåããŠããåéã $M$ 人ããŠãèªåãèŠæãªããŒãã®ã¬ããŒãã¯ããã®ããŒããåŸæãªåéã®ã¬ããŒããåãããšã§ããã®åéãšåãç¹æ°ãåãããšãã§ããã
ãã ããä»äººã®ã¬ããŒããåããŠããããšãå
çã«æ°ä»ãããŠã¯ãããªãã®ã§ã $N$ åã®ãã¡å°ãªããšã $K$ åã¯ä»äººã®ã¬ããŒããåãããèªåã§ã¬ããŒããä»äžããªããŠã¯ãªããªãã
ãŸãã AOR ã€ã«ã¡ããã¯åéã«è¿·æããããããªããšæã£ãã®ã§åé $i$ ã«å¯ŸããŠã¬ããŒããåãã®ã¯ $T_i$ å以äžã«ããããšã«ããã
AOR ã€ã«ã¡ãããèªåã§ã¬ããŒããä»äžãããšãã®ç¹æ°ãšãåéãã¬ããŒããä»äžããæã®ç¹æ°ãäžãããããšãã«ã AOR ã€ã«ã¡ãããåãããšã®ã§ããåèšç¹æ°ã®æå€§å€ãçããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le N \le 100$</li>
<li>$0 \le M \le 100$</li>
<li>$0 \le K \le N$</li>
<li>$0 \le a_i \le 100$</li>
<li>$0 \le b_{ij} \le 100$</li>
<li>$0 \le T_i \le N$</li>
</ul>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã
</p>
<p>
$N \ M \ K$<br>
$a_1 \ \cdots \ a_N$<br>
$b_{11} \ \cdots \ b_{1N}$<br>
$\vdots$<br>
$b_{M1} \ \cdots \ b_{MN}$<br>
$T_1 \ \cdots \ T_M$<br>
<br>
$a_i$ ã¯AORã€ã«ã¡ããã $i$ çªç®ã®ã¬ããŒããä»äžããæã®ç¹æ°ãã$b_{ij}$ ã¯åé $i$ ã $j$ çªç®ã®ã¬ããŒããä»äžããæã®ç¹æ°ã衚ãã
</p>
<h2>åºå</h2>
<p>
AOR ã€ã«ã¡ãããåãããšã®ã§ããåèšç¹æ°ã®æå€§å€ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
3 2 2
50 65 70
80 100 80
90 65 45
1 1
</pre>
<h3>åºåäŸ 1</h3>
<pre>
225
</pre>
<p>
AOR ã€ã«ã¡ãã㯠1 åã ãä»äººã®ã¬ããŒããåãããšãã§ããã®ã§ãåé 2 ã® 1 ã€ãã®ã¬ããŒããåãããšã§ã AOR ã€ã«ã¡ããã¯æé«ç¹æ°ãåãããšãã§ããã
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
3 0 3
0 0 0
</pre>
<h3>åºåäŸ 2</h3>
<pre>
0
</pre>
<p>
AOR ã€ã«ã¡ããã«ã¯åéãããªããããã¬ããŒããåãããšã¯ã§ããªãã
</p> |
p03181 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1, 2, \ldots, N</var>.
For each <var>i</var> (<var>1 \leq i \leq N - 1</var>), the <var>i</var>-th edge connects Vertex <var>x_i</var> and <var>y_i</var>.</p>
<p>Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other black vertex by passing through only black vertices.</p>
<p>You are given a positive integer <var>M</var>.
For each <var>v</var> (<var>1 \leq v \leq N</var>), answer the following question:</p>
<ul>
<li>Assuming that Vertex <var>v</var> has to be black, find the number of ways in which the vertices can be painted, modulo <var>M</var>.</li>
</ul>
</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>2 \leq M \leq 10^9</var></li>
<li><var>1 \leq x_i, y_i \leq N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_{N - 1}</var> <var>y_{N - 1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.
The <var>v</var>-th (<var>1 \leq v \leq N</var>) line should contain the answer to the following question:</p>
<ul>
<li>Assuming that Vertex <var>v</var> has to be black, find the number of ways in which the vertices can be painted, modulo <var>M</var>.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 100
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
4
3
</pre>
<p>There are seven ways to paint the vertices, as shown in the figure below.
Among them, there are three ways such that Vertex <var>1</var> is black, four ways such that Vertex <var>2</var> is black and three ways such that Vertex <var>3</var> is black.</p>
<p><img alt="" src="https://img.atcoder.jp/dp/subtree_0_muffet.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 100
1 2
1 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
5
5
5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 2
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
0
1
1
1
0
1
0
1
1
</pre>
<p>Be sure to print the answers modulo <var>M</var>.</p></section>
</div>
</span> |
p01446 |
<H1><font color="#000">Problem J:</font> Blue Forest</H1>
<p>
John is playing a famous console game named 'Tales of Algorithmers.' Now he is facing the last dungeon called 'Blue Forest.' To find out the fastest path to run through the very complicated dungeon, he tried to draw up the dungeon map.
</p>
<p>
The dungeon consists of several floors. Each floor can be described as a connected simple plane graph. Vertices of the graph are identified by X-Y coordinate, and the length of an edge is calculated by Euclidean distance. A vertex may be equipped with a one-way warp gate. If John chooses to use the gate, it brings John to another vertex in a possibly different floor. The distance between a warp gate and its destination is considered as 0.
</p>
<p>
One vertex has at most one warp gate, though some vertices might be the destination of multiple warp gates.
</p>
<p>
He believed he made one map for each floor, however after drawing maps of all the floors, he
noticed that he might have made a few mistakes. He might have drawn the same floor several times, and might have forgotten to mark some warp gates in the maps. However, he was sure he marked all warp gates at least once. So if the maps of same floor are unified to one map, all the warp gates must be described there. Luckily there are no floors which have the same shape
as the other floors, so if two (or more) maps can be unified, they must be the maps of the same floor. Also, there is no floor which is circular symmetric (e.g. a regular triangle and a square).
</p>
<p>
Map A and map B can be unified if map B can be transformed to map A using only rotation and parallel translation. Since some of the warp gates on maps might be missing, you should not consider the existence of warp gates when checking unification. If it is possible to unify map A and map B, a vertex on map A and the corresponding vertex on map B are considered as 'identical' vertices. In other words, you should treat warp gates on map B as those on map A where the warp gates are located on the corresponding vertices on map A. Destinations of warp gates should be treated similarly. After that you can forget map B. It is guaranteed that if both map A and map B have warp gates which are on the identical vertices, the destinations of them are also identical.
</p>
<p>
Remember, your task is to find the shortest path from the entrance to the exit of the dungeon, using the unified maps.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is in the following format.
</p>
<p>
<i>n</i><br>
<i>component</i><sub>1</sub></br>
<i>component</i><sub>2</sub></br>
...<br>
<i>component</i><sub><i>n</i></sub></br>
<i>sl sn</i><br>
<i>dl dn</i><br>
</p>
<p>
<i>n</i> is a positive integer indicating the number of maps. <i>component<sub>i</sub></i> describes the <i>i</i>-th map in the following format.
</p>
<p>
<i>A</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub><br>
...<br>
<i>x</i><sub><i>A</i></sub> <i>y</i><sub><i>A</i></sub><br>
<i>B</i><br>
<i>s</i><sub>1</sub> <i>d</i><sub>1</sub><br>
<i>s</i><sub>2</sub> <i>d</i><sub>2</sub><br>
...<br>
<i>s</i><sub><i>B</i></sub> <i>d</i><sub><i>B</i></sub><br>
<i>C</i>
<i>sn</i><sub>1</sub> <i>dl</i><sub>1</sub> <i>dn</i><sub>1</sub><br>
<i>sn</i><sub>2</sub> <i>dl</i><sub>2</sub> <i>dn</i><sub>2</sub><br>
...<br>
<i>sn</i><sub><i>C</i></sub> <i>dl</i><sub><i>C</i></sub> <i>dn</i><sub><i>C</i></sub><br>
</p>
<p>
<i>A</i> denotes the number of vertices in the map. Each of the following <i>A</i> lines contains two integers
<i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> representing the coordinates of the <i>i</i>-th vertex in the 2-dimensional plane. <i>B</i> denotes the number of the edges connecting the vertices in the map. Each of the following <i>B</i> lines contains two integers representing the start and the end vertex of each edge. Vertices on the same map are numbered from 1.
</p>
<p>
<i>C</i> denotes the number of warp gates. Each of the following <i>C</i> lines has three integers describing a warp gate. The first integer is the vertex where the warp gate is located. The second and the third integer are the indices of the map and the vertex representing the destination of the warp gate, respectively. Similarly to vertices, maps are also numbered from 1.
</p>
<p>
After the description of all maps, two lines follow. The rst line contains two integers <i>sl</i> and <i>dl</i> , meaning that the entrance of the dungeon is located in the <i>sl</i>-th map, at the vertex <i>dl</i>. The last line has two integers <i>sn</i> and <i>dn</i>, similarly describing the location of the exit.
</p>
<p>
The values in each dataset satisfy the following conditions:
</p>
<ul>
<li> 1 ≤ <i>n</i> ≤ 50,</li>
<li> 3 ≤ <i>A</i> ≤ 20,</li>
<li> <i>A</i> - 1 ≤ <i>B</i> ≤ <i>A</i>(<i>A</i> - 1)/2,</li>
<li> 0 ≤ <i>C</i> ≤ <i>A</i>, and</li>
<li> -10,000 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 10,000.</li>
</ul>
<H2>Output</H2>
<p>
For each dataset, print the distance of the shortest path from the entrance to the exit. The
output should not contain an absolute error greater than 10<sup>-1</sup>. If there is no route, print -1.
</p>
<H2>Sample Input</H2>
<pre>
2
5
0 0
10 0
20 0
30 0
30 10
4
1 2
2 3
3 4
4 5
2
1 2 4
3 2 2
5
-10 0
0 0
0 -10
0 -20
0 -30
4
1 2
2 3
3 4
4 5
1
4 1 3
1 1
2 1
4
3
4 3
0 0
5 0
2
1 2
2 3
0
3
0 0
3 4
0 5
2
1 2
1 3
1
2 3 4
4
0 13
0 0
13 0
13 13
4
1 2
1 4
2 3
2 4
0
4
5 12
0 0
-7 17
-12 5
4
1 2
2 3
2 4
4 3
0
1 1
4 1
4
3
0 0
2 0
0 4
2
1 2
1 3
0
3
0 0
-2 0
0 4
2
1 2
1 3
1
1 4 1
3
0 0
1 0
0 2
2
1 2
1 3
1
1 4 1
3
0 0
2 0
0 4
2
1 2
2 3
0
1 1
4 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
10.0000000000
41.3847763109
-1.000000000
</pre>
|
p01016 | <h1>Problem A: Password</h1>
<p>
倪éåã¯ãèªåã®ããœã³ã³ãæã£ãŠããŠããã°ã€ã³æã®ãã¹ã¯ãŒããèšå®ããŠãããããããäžæ³šæã«ã倪éåã¯ãã®ãã¹ã¯ãŒããå¿ããŠããŸã£ããããã§ããã¹ã¯ãŒããã¡ã¢ããçŽãããããšãæãåºããçŽãèŠã€ãã倪éåã¯ãããèŠãŠé©ããããªããšçŽã¯åããŠããŠæçããååšããããšããã©ããã«æ±ãããããèªããªããªã£ãŠããã®ã ã倪éåã¯ãã®ã¡ã¢ãåèã«ãã¹ã¯ãŒããæšæž¬ããããšã«ããã
</p>
<h2>Problem</h2>
<p>
äºã€ã®æååA, BãäžãããããæååAã®äžã«æååBãå«ãŸããŠãããã©ãããå€å®ããå«ãŸããŠããå Žåã¯"Yes"ããããã§ãªããã°"No"ãåºåããã
æååAã«ã¯ã¢ã«ãã¡ãããã®å€§æåã®ã¿ãå«ãŸããŠãããæååBã«ã¯ã¢ã«ãã¡ãããã®å€§æåã«å ããŠã'_'(åè§ã¢ã³ããŒããŒ)ãå«ãŸããŠãããåè§ã¢ã³ããŒããŒã¯ä»»æã®ïŒæåã衚ãã
</p>
<h2>Input</h2>
<p>
æåå A<br>
æåå B
</p>
<h2>Constraints</h2>
<ul>
<li>A,Bã®æååã®é·ãã¯ã©ã¡ãã1æå以äž1000æå以äžã§ããã</li>
<li>Bã®æååã®é·ããAã®æååã®é·ããè¶
ããããšã¯ãªãã</li>
</ul>
<h2>Output</h2>
<p>
"Yes"ãŸãã¯"No"ã1è¡ã§åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
ABCDE
ABC
</pre>
<h2>Sample Output 1</h2>
<pre>
Yes
</pre>
<h2>Sample Input 2</h2>
<pre>
KUSATSU
KSATSU
</pre>
<h2>Sample Output 2</h2>
<pre>
No
</pre>
<h2>Sample Input 3</h2>
<pre>
ABCABC
ACBA_B
</pre>
<h2>Sample Output 3</h2>
<pre>
No
</pre>
<h2>Sample Input 4</h2>
<pre>
RUPCUAPC
__PC
</pre>
<h2>Sample Output 4</h2>
<pre>
Yes
</pre>
<h2>Sample Input 5</h2>
<pre>
AIZU
_A
</pre>
<h2>Sample Output 5</h2>
<pre>
No
</pre>
|
p01503 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem I:
Tampopo Machine
</h2>
<p>
"Today is another day of endless, tedious work to put a tampopo on sashimi..."
</p>
<p>
Yaruo works in a sashimi (sliced raw fish) factory. His job is to put tampopos on sashimi packages everyday. Tired of this menial job, he decided to develop a tampopo machine to do the job instead of him.
</p>
<p>
The tampopo machine has the following properties. Sashimi packages are put on a conveyor belt and move from left to right. The width of a package is $W$ and the interval between two adjacent packages is $D$. The machine has $N$ magic hands placed above the conveyor belt at regular intervals of $M$. These magic hands put tampopos every $T$ seconds.
</p>
<p>
In initial state, the right end of the first package is under the leftmost magic hand. The magic hands start putting a tampopo as soon as he turns on the power of the machine. The conveyor belt moves one unit length per one second.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_tampopoMachine" width="480"><br>
</center>
<br>
<p>
Unfortunately, after building the machine, Yaruo noticed that there exist some packages with no tampopos. Calculate the ratio of packages with no tampopos for him.
</p>
<p>
When a magic hand puts a tampopo on the left or right end of a package, you can assume that the tampopo is on the package.
</p>
<h3>Input</h3>
<p>
The input consists of 5 integers, $W$, $D$, $N$, $M$ and $T$ which are described in the problem statement.<br>
($1 \leq W, D, N, M, T \leq 1,000,000,000$)
</p>
<h3>Output</h3>
<p>
Output the ratio of packages with no tampopos in a line. The absolute error should be less than or equal to $10^{-9}$.
</p>
<h3>Sample Input 1</h3>
<pre>1 1 1 1 1</pre>
<h3>Sample Output 1</h3>
<pre>0.000000000000</pre>
<h3>Sample Input 2</h3>
<pre>1 2 3 4 5</pre>
<h3>Sample Output 2</h3>
<pre>0.200000000000</pre>
<h3>Sample Input 3</h3>
<pre>3 2 2 1 6</pre>
<h3>Sample Output 3</h3>
<pre>0.166666666667</pre> |
p01153 |
<H1><font color="#000">Problem G:</font> Gather on the Clock</H1>
<p>
There is a self-playing game called <i>Gather on the Clock</i>.
</p>
<p>
At the beginning of a game, a number of cards are placed on a ring. Each card is labeled by a
value.
</p>
<p>
In each step of a game, you pick up any one of the cards on the ring and put it on the next one
in clockwise order. You will gain the score by the difference of the two values. You should deal
with the two cards as one card in the later steps. You repeat this step until only one card is left
on the ring, and the score of the game is the sum of the gained scores.
</p>
<p>
Your task is to write a program that calculates the maximum score for the given initial state,
which specifies the values of cards and their placements on the ring.
</p>
<p>
The figure shown below is an example, in which the initial state is illustrated on the left, and
the subsequent states to the right. The picked cards are 1, 3 and 3, respectively, and the score
of this game is 6.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gatherOnTheClock">
<p>Figure 6: An illustrative play of Gather on the Clock</p>
</center>
<H2>Input</H2>
<p>
The input consists of multiple test cases. The first line contains the number of cases. For each
case, a line describing a state follows. The line begins with an integer <i>n</i> (2 ≤ <i>n</i> ≤ 100), the
number of cards on the ring, and then <i>n</i> numbers describing the values of the cards follow. Note
that the values are given in clockwise order. You can assume all these numbers are non-negative
and do not exceed 100. They are separated by a single space character.
</p>
<H2>Output</H2>
<p>
For each case, output the maximum score in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
4 0 1 2 3
6 1 8 0 3 5 9
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6
34
</pre>
|
p03494 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> positive integers written on a blackboard: <var>A_1, ..., A_N</var>.</p>
<p>Snuke can perform the following operation when all integers on the blackboard are even:</p>
<ul>
<li>Replace each integer <var>X</var> on the blackboard by <var>X</var> divided by <var>2</var>.</li>
</ul>
<p>Find the maximum possible number of operations that Snuke can perform.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 200</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of operations that Snuke can perform.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
8 12 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Initially, <var>[8, 12, 40]</var> are written on the blackboard.
Since all those integers are even, Snuke can perform the operation.</p>
<p>After the operation is performed once, <var>[4, 6, 20]</var> are written on the blackboard.
Since all those integers are again even, he can perform the operation.</p>
<p>After the operation is performed twice, <var>[2, 3, 10]</var> are written on the blackboard.
Now, there is an odd number <var>3</var> on the blackboard, so he cannot perform the operation any more.</p>
<p>Thus, Snuke can perform the operation at most twice.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
5 6 8 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Since there is an odd number <var>5</var> on the blackboard already in the beginning, Snuke cannot perform the operation at all.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
382253568 723152896 37802240 379425024 404894720 471526144
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p00312 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ã«ãšã«ã¯ãŸã£ããåž°ã</H1>
<p>
äžå¹ã®ã«ãšã«ã巣穎ã«åž°ãããšããŠããŸãã巣穎ã¯ã«ãšã«ã® <var>D</var> ã»ã³ãã¡ãŒãã«åæ¹ã«ãã£ãŠãã«ãšã«ã¯å·£ç©Žã«åãã£ãŠãŸã£ããé²ã¿ãŸããã«ãšã«ãã§ããè¡åã¯ã以äžã®ïŒã€ã ãã§ãã
</p>
<ul>
<li> 倧ãžã£ã³ãïŒ<var>L</var> ã»ã³ãã¡ãŒãã«åæ¹ã«é²ãïŒ</li>
<li> å°ãžã£ã³ãïŒïŒã»ã³ãã¡ãŒãã«åæ¹ã«é²ãïŒ</li>
</ul>
<p>
ã«ãšã«ã¯å·£ç©Žãè·³ã³è¶ãããšãªããã¡ããã©å·£ç©Žã«çå°ããããšãããã£ãŠããŸãã
</p>
<p>
ã«ãšã«ã巣穎ã«åž°ãããã«ãæäœäœåè·³ã¶å¿
èŠãããããæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>D</var> <var>L</var>
</pre>
<p>
å
¥åã¯ïŒè¡ã§ããã巣穎ãŸã§ã®è·é¢ <var>D</var> (1 ≤ <var>D</var> ≤ 10000) ãšå€§ãžã£ã³ãã§ã«ãšã«ãé²ãè·é¢ <var>L</var> (2 ≤ <var>L</var> ≤ 10000) ãäžããããã
</p>
<h2>Output</h2>
<p>
ã«ãšã«ãæäœäœåè·³ã¶å¿
èŠããããããïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
10 5
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
7 4
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre> |
p00742 |
<h1><font color="#000000">Problem C:</font> Verbal Arithmetic</h1>
<p>
Let's think about <i>verbal arithmetic.</i>
</p>
<p>
The material of this puzzle is a summation
of non-negative integers represented in a decimal format,
for example, as follows.
</p>
<pre>
905 + 125 = 1030
</pre>
<p>
In verbal arithmetic, every digit appearing in the equation is masked with an alphabetic character. A problem which has the above equation as one of its answers, for example, is the following.
</p>
<pre>
ACM + IBM = ICPC
</pre>
<p>
Solving this puzzle means finding possible digit assignments
to the alphabetic characters in the verbal equation.
</p>
<p>
The rules of this puzzle are the following.
</p>
<ul>
<li>
Each integer in the equation is expressed in terms of one or more
digits '0'-'9', but all the digits are masked with some alphabetic
characters 'A'-'Z'.
</li>
<li>
The same alphabetic character appearing in multiple places
of the equation masks the same digit.
Moreover, all appearances of the same digit are masked with a single
alphabetic character.
That is, different alphabetic characters mean different digits.
</li>
<li>
The most significant digit must not be '0',
except when a zero is expressed as a single digit '0'.
That is, expressing numbers as "00" or "0123" is not permitted.
</li>
</ul>
<p>
There are 4 different digit assignments for the verbal equation above
as shown in the following table.
</p>
<table border>
<tr><th>Mask</th><th>A</th><th>B</th><th>C</th><th>I</th><th>M</th><th>P</th></tr>
<tr><td>Case 1</td><td>9</td><td>2</td><td>0</td><td>1</td><td>5</td><td>3</td></tr>
<tr><td>Case 2</td><td>9</td><td>3</td><td>0</td><td>1</td><td>5</td><td>4</td></tr>
<tr><td>Case 3</td><td>9</td><td>6</td><td>0</td><td>1</td><td>5</td><td>7</td></tr>
<tr><td>Case 4</td><td>9</td><td>7</td><td>0</td><td>1</td><td>5</td><td>8</td></tr>
</table>
<p>
Your job is to write a program which solves this puzzle.
</p>
<h3>Input</h3>
<p>The input consists of a number of datasets.
The end of the input is indicated by a line containing a zero.
<!-- end en only -->
<!-- begin en only -->
<p>
The number of datasets is no more than 100.
Each dataset is formatted as follows.
</blockquote>
<!-- end en only -->
<blockquote>
<i>N</i> <br />
<i>STRING</i> <sub>1</sub> <br />
<i>STRING</i> <sub>2</sub> <br />
... <br />
<i>STRING</i> <sub><i>N</i></sub> <br />
</blockquote>
<!-- begin en only -->
<p>
The first line of a dataset contains an integer <i>N </i>
which is the number of integers appearing in the equation.
Each of the following <i>N </i> lines contains a string
composed of uppercase alphabetic characters 'A'-'Z'
which mean masked digits.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>Each dataset expresses the following equation.</p>
<!-- end en only -->
<blockquote>
<i>STRING</i> <sub>1</sub> + <i>STRING</i> <sub>2</sub> + ... + <i>STRING</i> <sub><i>N</i> -1</sub> = <i>STRING</i> <sub><i>N</i></sub>
</blockquote>
<!-- begin en only -->
<p>
The integer <i>N </i> is greater than 2 and less than 13.
The length of <i>STRING</i> <sub><i>i</i></sub> is greater than 0
and less than 9.
The number of different alphabetic characters appearing
in each dataset is greater than 0 and less than 11.
</p>
<!-- end en only -->
<h3>Output</h3>
<p>
For each dataset, output a single line containing
the number of different digit assignments that satisfy the equation.
</p>
<p>
The output must not contain any superfluous characters.
</p>
<h3>Sample Input</h3>
<pre>
3
ACM
IBM
ICPC
3
GAME
BEST
GAMER
4
A
B
C
AB
3
A
B
CD
3
ONE
TWO
THREE
3
TWO
THREE
FIVE
3
MOV
POP
DIV
9
A
B
C
D
E
F
G
H
IJ
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
4
1
8
30
0
0
0
40320
</pre>
|
p01850 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h3>çŸäººäžéŠ</h3>
<p>çŸäººäžéŠã¯æ¥æ¬ã®äŒçµ±çãªã²ãŒã ã§ããïŒ ãã®ã²ãŒã ã§ã¯ <i>N</i> æã®ã«ãŒããçšãããïŒããããã®ã«ãŒãã«ã¯1ã€ã®æååãæžãããŠããïŒçްããã«ãŒã«ã¯çç¥ãããïŒ Aå㯠<i>N</i> æã®ã«ãŒãã«æžãããŠããæååãäœããã®é åºã§ããããã¡ããã©1åãã€èªãããšã«ãªã£ãïŒ
</p>
<p>çŸäººäžéŠã§ã¯ãã®æ¥é èŸãéåžžã«éèŠã§ããïŒçŸäººäžéŠã§äœ¿çšãããæååãšããŠæ¥é èŸã¯äŒŒãŠããèšèãå€ãïŒ é£ç¶ããŠäŒŒããããªæååãèªããšAåãæ··ä¹±ããŠããŸãïŒ ããã§Aåã¯ïŒé£ç¶ããäºã€ã®ã«ãŒãã®æååã®æ¥é èŸãã§ããã ãç°ãªãããã«ïŒã«ãŒããäžŠã¹æ¿ããããšèããïŒ
</p>
<p>Aåã®ç®æšã¯ïŒãå±±æã®èªã¿ãããããšåŒã°ããææšãæå°åãããããªå±±æãæ±ããããšã§ããïŒããã§å±±æãšã¯ïŒãã®çŸäººäžéŠã§èªãŸãã <i>N</i> æã®ã«ãŒããäžŠã¹æ¿ãããã®ãæãïŒå±±æã®èªã¿ããããšã¯ïŒå±±æå
ã«ãã飿¥ããã«ãŒãã®é¡äŒŒåºŠã®ç·åãèšãïŒ2 æã®ã«ãŒãã®é¡äŒŒåºŠã¯ãããã«æžãããæååã©ããã®æé·å
±éæ¥é èŸã®é·ããšããŠå®çŸ©ãããïŒãªãïŒæåå <i>t</i> ãš <i>u</i> ã®æé·å
±éæ¥é èŸãšã¯ïŒ<i>t</i> ãš <i>u</i> äž¡æ¹ã®æ¥é èŸã§ãããããªæååã®ãã¡ïŒæé·ã®ãã®ãæãïŒ
</p>
<p>äŸãã°ïŒ2 æã®ã«ãŒãã«æžãããæååããããã "<samp>jag</samp>" ãš "<samp>japan</samp>" ã§ããã°ïŒãããã®ã«ãŒãã®é¡äŒŒåºŠã¯ 2 ã§ããïŒäžæ¹ïŒ"<samp>wan</samp>" ãš "<samp>nyan</samp>" ã§ããã°é¡äŒŒåºŠã¯ 0 ã§ããïŒ
</p>
<p>ãšããã§ïŒãå±±æã®èªã¿ãããããæå°ãšãªãå±±æã¯è€æ°ååšãããããããªãïŒAåã¯ïŒæå°è§£ãšããŠããããå±±æã®ãã¡ïŒèŸæžé æå°ã®å±±æãæ±ãããïŒããã§ïŒå±±æ <i>P</i> ãš <i>Q</i> ã«ã€ã㊠<i>P</i> ãèŸæžé ã§å°ãããšã¯ïŒããæ£ã®æŽæ° <i>i</i> ãååšããŠïŒ1 çªç®ãã <i>i-1</i> çªç®ã®ã«ãŒããŸã§ã¯ããããåäžã®ã«ãŒãã§ããïŒã〠<i>i</i> çªç®ã®ã«ãŒãã®æååã¯èŸæžé ã«ãããŠå±±æ <i>P</i> ã®ã«ãŒãã®ã»ããå°ããããšãèšãïŒ
</p>
<p>ããªãã®ä»äºã¯ïŒãå±±æã®èªã¿ãããããæå°ã«ãããããªå±±æã®äžã§ïŒèŸæžé æå°ãšãªããã®ãæ±ããããšã§ããïŒ
</p>
<h3>Input</h3>
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ
</p>
<blockquote><i>N</i><br><i>s<sub>1</sub></i><br>...<br><i>s<sub>N</sub></i></blockquote>
<p>1è¡ç®ã«ã¯ã«ãŒãã®ææ°ãè¡šãæŽæ° <i>N</i> (<i>1 †N †100,000</i>) ãäžããããïŒ
ç¶ã <i>N</i> è¡ã«ã¯ã«ãŒãã«æžããã1æå以äžã®æååãæžãããŠããïŒ 1è¡ã¯è±å°æåã®ã¿ã§æ§æãããïŒãŸãïŒåäžã»ããå
ã«ãããŠïŒå <i>s<sub>i</sub></i> ã¯äºãã«ç°ãªãããšãä¿èšŒãããŠããïŒ
ããã«ïŒ<i>s<sub>i</sub></i> ã®é·ãã®åèšã¯ 400,000 以äžã§ããããšãä¿èšŒãããŠããïŒ
</p>
<p>å
¥åã®çµããã¯ïŒ 1ã€ã®ãŒããããªãè¡ã§ç€ºãïŒ
</p>
<h3>Output</h3>
<p>åããŒã¿ã»ããã«ã€ããŠïŒãå±±æã®èªã¿ãããããæå°ãšãªãå±±æã®äžã§èŸæžé æå°ã®å±±æã®æ
å ±ãïŒ<i>N</i> è¡ã«åºåããïŒå
·äœçã«ã¯ïŒãã®ãããªå±±æã® <i>i</i> çªç®ã®ã«ãŒãã«æžãããæååãïŒ<i>i</i> è¡ç®ã«åºåããããšã«ãªãïŒ
</p>
<h3>Sample Input</h3>
<pre>3
icpc
icfp
topcoder
4
apple
application
appointment
acmicpc
3
a
aa
aaa
4
a
aza
azb
b
0</pre>
<h3>Output for Sample Input</h3>
<pre>icfp
topcoder
icpc
apple
acmicpc
application
appointment
aa
a
aaa
a
aza
b
azb</pre>
<p>
èŸæžé ã®å®çŸ©ã«æ³šæããããšïŒä»åã®å®çŸ©ã§ã¯ïŒæååãé£çµããæã«èŸæžé æå°ã«ãªããšããããšãæå³ããããã§ã¯ãªãïŒäŸãã°ïŒ3çªç®ã®å
¥åäŸã§ã¯ [aaa,a,aa] ããå±±æã®èªã¿ãããããæå°ãšãªãè§£ã®äžã€ã§ããïŒé£çµããã°åãæååã«ãªãããïŒèŸæžé æå°ã®è§£ã«èŠãããããããªãïŒããããªããïŒä»åã®å®çŸ©ã§ã¯å
é ã®æåå "aa" ãš "aaa" ãåªå
çã«æ¯èŒãããããïŒèŸæžé æå°ã®è§£ã¯ [aa,a,aaa] ãšãªãïŒ
</p>
|
p02285 | <H1>Binary Search Tree III</H1>
<p>
Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II.
</p>
<ul>
<li><span>insert </span> $k$: Insert a node containing $k$ as key into $T$.</li>
<li><span>find </span>$k$: Report whether $T$ has a node containing $k$. </li>
<li><span>delete </span>$k$: Delete a node containing $k$.</li>
<li><span>print</span>: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively.</li>
</ul>
<p>
The operation delete $k$ for deleting a given node $z$ containing key $k$ from $T$ can be implemented by an algorithm which considers the following cases:
</p>
<ol>
<li> If $z$ has no children, we modify its parent $z.p$ to replace $z$ with NIL as its child (delete $z$).</li>
<li> If $z$ has only a single child, we "splice out" $z$ by making a new link between its child and its parent.</li>
<li> If $z$ has two children, we splice out $z$'s successor $y$ and replace $z$'s key with $y$'s key.</li>
</ol>
<H2>Input</H2>
<p>
In the first line, the number of operations $m$ is given. In the following $m$ lines, operations represented by <span>insert </span>$k$, <span>find </span>$k$, <span>delete </span>$k$ or <span>print</span> are given.
</p>
<H2>Output</H2>
<p>
For each <span>find </span>$k$ operation, print "<span>yes</span>" if $T$ has a node containing $k$, "<span>no</span>" if not.
</p>
<p>
In addition, for each <span>print</span> operation, print a list of keys obtained by inorder tree walk and preorder tree walk in a line respectively. Put a space character <u>before each key</u>
<H2>Constraints</H2>
<ul>
<li>The number of operations $\leq 500,000$</li>
<li>The number of print operations $\leq 10$.</li>
<li>$-2,000,000,000 \leq key \leq 2,000,000,000$</li>
<li>The height of the binary tree does not exceed 100 if you employ the above pseudo code.</li>
<li>The keys in the binary search tree are all different.</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
18
insert 8
insert 2
insert 3
insert 7
insert 22
insert 1
find 1
find 2
find 3
find 4
find 5
find 6
find 7
find 8
print
delete 3
delete 7
print
</pre>
<H2>Sample Output 1</H2>
<pre>
yes
yes
yes
no
no
no
yes
yes
1 2 3 7 8 22
8 2 1 3 7 22
1 2 8 22
8 2 1 22
</pre>
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p>
|
p03247 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is introducing a <strong>robot arm</strong> with the following properties to his factory:</p>
<ul>
<li>The robot arm consists of <var>m</var> <strong>sections</strong> and <var>m+1</var> <strong>joints</strong>. The sections are numbered <var>1</var>, <var>2</var>, ..., <var>m</var>, and the joints are numbered <var>0</var>, <var>1</var>, ..., <var>m</var>. Section <var>i</var> connects Joint <var>i-1</var> and Joint <var>i</var>. The length of Section <var>i</var> is <var>d_i</var>.</li>
<li>For each section, its <strong>mode</strong> can be specified individually. There are four modes: <code>L</code>, <code>R</code>, <code>D</code> and <code>U</code>. The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint <var>i</var> will be determined as follows (we denote its coordinates as <var>(x_i, y_i)</var>):<ul>
<li><var>(x_0, y_0) = (0, 0)</var>.</li>
<li>If the mode of Section <var>i</var> is <code>L</code>, <var>(x_{i}, y_{i}) = (x_{i-1} - d_{i}, y_{i-1})</var>.</li>
<li>If the mode of Section <var>i</var> is <code>R</code>, <var>(x_{i}, y_{i}) = (x_{i-1} + d_{i}, y_{i-1})</var>.</li>
<li>If the mode of Section <var>i</var> is <code>D</code>, <var>(x_{i}, y_{i}) = (x_{i-1}, y_{i-1} - d_{i})</var>.</li>
<li>If the mode of Section <var>i</var> is <code>U</code>, <var>(x_{i}, y_{i}) = (x_{i-1}, y_{i-1} + d_{i})</var>.</li>
</ul>
</li>
</ul>
<p>Snuke would like to introduce a robot arm so that the position of Joint <var>m</var> can be matched with all of the <var>N</var> points <var>(X_1, Y_1), (X_2, Y_2), ..., (X_N, Y_N)</var> by properly specifying the modes of the sections.
Is this possible?
If so, find such a robot arm and how to bring Joint <var>m</var> to each point <var>(X_j, Y_j)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>-10^9 \leq X_i \leq 10^9</var></li>
<li><var>-10^9 \leq Y_i \leq 10^9</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In the test cases worth <var>300</var> points, <var>-10 \leq X_i \leq 10</var> and <var>-10 \leq Y_i \leq 10</var> hold.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>X_1</var> <var>Y_1</var>
<var>X_2</var> <var>Y_2</var>
<var>:</var>
<var>X_N</var> <var>Y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print <code>-1</code>.</p>
<pre><var>m</var>
<var>d_1</var> <var>d_2</var> <var>...</var> <var>d_m</var>
<var>w_1</var>
<var>w_2</var>
<var>:</var>
<var>w_N</var>
</pre>
<p><var>m</var> and <var>d_i</var> are the configurations of the robot arm. Refer to the problem statement for what each of them means.
Here, <var>1 \leq m \leq 40</var> and <var>1 \leq d_i \leq 10^{12}</var> must hold. Also, <var>m</var> and <var>d_i</var> must all be integers.</p>
<p><var>w_j</var> is a string of length <var>m</var> that represents the way to bring Joint <var>m</var> of the robot arm to point <var>(X_j, Y_j)</var>.
The <var>i</var>-th character of <var>w_j</var> should be one of the letters <code>L</code>, <code>R</code>, <code>D</code> and <code>U</code>, representing the mode of Section <var>i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
-1 0
0 3
2 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1 2
RL
UU
DR
</pre>
<p>In the given way to bring Joint <var>m</var> of the robot arm to each <var>(X_j, Y_j)</var>, the positions of the joints will be as follows:</p>
<ul>
<li>To <var>(X_1, Y_1) = (-1, 0)</var>: First, the position of Joint <var>0</var> is <var>(x_0, y_0) = (0, 0)</var>. As the mode of Section <var>1</var> is <code>R</code>, the position of Joint <var>1</var> is <var>(x_1, y_1) = (1, 0)</var>. Then, as the mode of Section <var>2</var> is <code>L</code>, the position of Joint <var>2</var> is <var>(x_2, y_2) = (-1, 0)</var>.</li>
<li>To <var>(X_2, Y_2) = (0, 3)</var>: <var>(x_0, y_0) = (0, 0), (x_1, y_1) = (0, 1), (x_2, y_2) = (0, 3)</var>.</li>
<li>To <var>(X_3, Y_3) = (2, -1)</var>: <var>(x_0, y_0) = (0, 0), (x_1, y_1) = (0, -1), (x_2, y_2) = (2, -1)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 0
1 0
2 0
3 0
4 0
</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
1 1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
1 1
RU
UR
</pre>
<p>There may be duplicated points among <var>(X_j, Y_j)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
-7 -3
7 3
-3 -7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
3 1 4 1 5
LRDUL
RDULR
DULRD
</pre></section>
</div>
</span> |
p00892 |
<H1><font color="#000">Problem I:</font> Intersection of Two Prisms</H1>
<p>
Suppose that <i>P</i><sub>1</sub> is an infinite-height prism whose axis is parallel to the <i>z</i>-axis, and <i>P</i><sub>2</sub> is also an infinite-height prism whose axis is parallel to the <i>y</i>-axis. <i>P</i><sub>1</sub> is defined by the polygon <i>C</i><sub>1</sub> which is the cross section of <i>P</i><sub>1</sub> and the <i>xy</i>-plane, and <i>P</i><sub>2</sub> is also defined by the polygon <i>C</i><sub>2</sub> which is the cross section of <i>P</i><sub>2</sub> and the <i>x</i>z-plane.
</p>
<p>
Figure I.1 shows two cross sections which appear as the first dataset in the sample input, and
Figure I.2 shows the relationship between the prisms and their cross sections.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_intersectionOfTwoPrisms1"><br>
<p>Figure I.1: Cross sections of Prisms</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_intersectionOfTwoPrisms2"><br>
<p>Figure I.2: Prisms and their cross sections</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_intersectionOfTwoPrisms3"><br>
<p>Figure I.3: Intersection of two prisms</p>
</center>
<p>
Figure I.3 shows the intersection of two prisms in Figure I.2, namely, <i>P</i><sub>1</sub> and <i>P</i><sub>2</sub>.
</p>
<p>
Write a program which calculates the volume of the intersection of two prisms.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The number of datasets is less than 200.
</p>
<p>
Each dataset is formatted as follows.
</p>
<p>
<i>m n</i><br>
<i>x</i><sub>11</sub> <i>y</i><sub>11</sub><br>
<i>x</i><sub>12</sub> <i>y</i><sub>12</sub> <br>
.<br>
.<br>
.<br>
<i>x</i><sub>1<i>m</i></sub> <i>y</i><sub>1<i>m</i></sub> <br>
<i>x</i><sub>21</sub> <i>z</i><sub>21</sub><br>
<i>x</i><sub>22</sub> <i>z</i><sub>22</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub>2<i>n</i></sub> <i>z</i><sub>2<i>n</i></sub><br>
</p>
<p>
<i>m</i> and <i>n</i> are integers (3 ≤ <i>m</i> ≤ 100, 3 ≤ <i>n</i> ≤ 100) which represent the numbers of the vertices of the polygons, <i>C</i><sub>1</sub> and <i>C</i><sub>2</sub>, respectively.
</p>
<p>
<i>x</i><sub>1<i>i</i></sub>, <i>y</i><sbu>1<i>i</i></sub>, <i>x</i><sub>2<i>j</i></sub> and <i>z</i><sub>2<i>j</i></sub> are integers between -100 and 100, inclusive. (<i>x</i><sub>1<i>i</i></sub>, <i>y</i><sub>1<i>i</i></sub>) and (<i>x</i><sub>2<i>j</i></sub> , <i>z</i><sub>2<i>j</i></sub>) mean the <i>i</i>-th and <i>j</i>-th vertices' positions of <i>C</i><sub>1</sub> and <i>C</i><sub>2</sub> respectively.
</p>
<p>
The sequences of these vertex positions are given in the counterclockwise order either on the <i>xy</i>-plane or the <i>xz</i>-plane as in Figure I.1.
</p>
<p>
You may assume that all the polygons are <i>convex</i>, that is, all the interior angles of the polygons are less than 180 degrees. You may also assume that all the polygons are <i>simple</i>, that is, each polygon's boundary does not cross nor touch itself.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, output the volume of the intersection of the two prisms, <i>P</i><sub>1</sub> and <i>P</i><sub>2</sub>, with a decimal representation in a line.
</p>
<p>
None of the output values may have an error greater than 0.001. The output should not contain any other extra characters.
</p>
<H2>Sample Input</H2>
<pre>
4 3
7 2
3 3
0 2
3 1
4 2
0 1
8 1
4 4
30 2
30 12
2 12
2 2
15 2
30 8
13 14
2 8
8 5
13 5
21 7
21 9
18 15
11 15
6 10
6 8
8 5
10 12
5 9
15 6
20 10
18 12
3 3
5 5
10 3
10 10
20 8
10 15
10 8
4 4
-98 99
-99 -99
99 -98
99 97
-99 99
-98 -98
99 -99
96 99
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4.708333333333333
1680.0000000000005
491.1500000000007
0.0
7600258.4847715655
</pre>
|
p01780 |
<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>A - Breadth-First Search by Foxpower</h2>
<h3>Problem Statement</h3>
<p>
Fox Ciel went to JAG Kingdom by bicycle, but she forgot a place where she parked her bicycle. So she needs to search it from a bicycle-parking area before returning home.
</p>
<p>
The parking area is formed as a unweighted rooted tree $T$ with $n$ vertices, numbered $1$ through $n$. Each vertex has a space for parking one or more bicycles. Ciel thought that she parked her bicycle near the vertex $1$, so she decided to search it from there by the breadth-first search. That is, she searches it at the vertices in the increasing order of their distances from the vertex $1$. If multiple vertices have the same distance, she gives priority to the vertices in the order of searching at their parents. If multiple vertices have the same parent, she searches at the vertex with minimum number at first.
</p>
<p>
Unlike a computer, she can't go to a next vertex by random access. Thus, if she goes to the vertex $j$ after the vertex $i$, she needs to walk the distance between the vertices $i$ and $j$. BFS by fox power perhaps takes a long time, so she asks you to calculate the total moving distance in the worst case starting from the vertex $1$.
</p>
<h3>Input</h3>
<p>
The input is formatted as follows.
</p>
<blockquote>$n$<br>$p_2$ $p_3$ $p_4$ $\cdots$ $p_n$</blockquote>
<p>
The first line contains an integer $n$ ($1 \le n \le 10^5$), which is the number of vertices on the unweighted rooted tree $T$.
The second line contains $n-1$ integers $p_i$ ($1 \le p_i < i$), which are the parent of the vertex $i$.
The vertex $1$ is a root node, so $p_1$ does not exist.
</p>
<h3>Output</h3>
<p>
Print the total moving distance in the worst case in one line.
</p>
<h3>Sample Input 1</h3>
<pre>4
1 1 2</pre>
<h3>Output for the Sample Input 1</h3>
<pre>6</pre>
<h3>Sample Input 2</h3>
<pre>4
1 1 3</pre>
<h3>Output for the Sample Input 2</h3>
<pre>4</pre>
<h3>Sample Input 3</h3>
<pre>11
1 1 3 3 2 4 1 3 2 9</pre>
<h3>Output for the Sample Input 3</h3>
<pre>25</pre> |
p02905 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an integer sequence of length <var>N</var>: <var>A_0,A_1,\cdots,A_{N-1}</var>.</p>
<p>Find the following sum (<var>\mathrm{lcm}(a, b)</var> denotes the least common multiple of <var>a</var> and <var>b</var>):</p>
<ul>
<li><var>\sum_{i=0}^{N-2} \sum_{j=i+1}^{N-1} \mathrm{lcm}(A_i,A_j)</var></li>
</ul>
<p>Since the answer may be enormous, compute it modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 200000</var></li>
<li><var>1 \leq A_i \leq 1000000</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\ A_1\ \cdots\ A_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 4 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>22
</pre>
<p><var>\mathrm{lcm}(2,4)+\mathrm{lcm}(2,6)+\mathrm{lcm}(4,6)=4+6+12=22</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
1 2 3 4 6 8 12 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>313
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
356822 296174 484500 710640 518322 888250 259161 609120 592348 713644
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>353891724
</pre></section>
</div>
</span> |
p00938 |
<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
Wall Clocks</h2>
<p>
You are the manager of a chocolate sales team. Your team customarily takes tea breaks every two hours, during which varieties of new chocolate products of your company are served. Everyone looks forward to the tea breaks so much that they frequently give a glance at a wall clock.
</p>
<p>
Recently, your team has moved to a new office. You have just arranged desks in the office. One team member asked you to hang a clock on the wall in front of her desk so that she will not be late for tea breaks. Naturally, everyone seconded her.
</p>
<p>
You decided to provide an enough number of clocks to be hung in the field of view of everyone. Your team members will be satisfied if they have at least one clock (regardless of the orientation of the clock) in their view, or, more precisely, within 45 degrees left and 45 degrees right (both ends inclusive) from the facing directions of their seats. In order to buy as few clocks as possible, you should write a program that calculates the minimum number of clocks needed to
meet everyone's demand.
</p>
<p>
The office room is rectangular aligned to north-south and east-west directions. As the walls are tall enough, you can hang clocks even above the door and can assume one's eyesight is not blocked by other members or furniture. You can also assume that each clock is a point (of size zero), and so you can hang a clock even on a corner of the room.
</p>
<p>
For example, assume that there are two members. If they are sitting facing each other at positions shown in Figure D.1(A), you need to provide two clocks as they see distinct sections of the wall. If their seats are arranged as shown in Figure D.1(B), their fields of view have a common point on the wall. Thus, you can meet their demands by hanging a single clock at the point. In Figure D.1(C), their fields of view have a common wall section. You can meet their demands with a single clock by hanging it anywhere in the section. Arrangements (A), (B), and (C) in Figure D.1 correspond to Sample Input 1, 2, and 3, respectively.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case, formatted as follows.<br>
<br>
$n$ $w$ $d$<br>
$x_1$ $y_1$ $f_1$<br>
...<br>
$x_n$ $y_n$ $f_n$<br>
<br>
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_WallClocks" width="680"><br>
<p>Figure D.1. Arrangements of seats and clocks. Gray area indicates field of view.</p>
</center>
<p>
All numbers in the test case are integers. The first line contains the number of team members $n$ $(1 \leq n \leq 1,000)$ and the size of the office room $w$ and $d$ $(2 \leq w, d \leq 100,000)$. The office room has its width $w$ east-west, and depth $d$ north-south. Each of the following $n$ lines indicates the position and the orientation of the seat of a team member. Each member has a seat at a distinct position $(x_i, y_i)$ facing the direction $f_i$, for $i = 1, ..., n$. Here $1 \leq x_i \leq w - 1, 1 \leq y_i \leq d - 1$, and $f_i$ is one of <span>N</span>, <span>E</span>, <span>W</span>, and <span>S</span>, meaning north, east, west, and south, respectively. The position $(x, y)$ means $x$ distant from the west wall and $y$ distant from the south wall.
</p>
<h3>Output</h3>
<p>
Print the minimum number of clocks needed.
</p>
<h3>Sample Input 1</h3>
<pre>2 10 6
4 4 E
6 4 W</pre>
<h3>Sample Output 1</h3>
<pre>2</pre>
<h3>Sample Input 2</h3>
<pre>2 10 6
2 4 E
6 4 W</pre>
<h3>Sample Output 2</h3>
<pre>1</pre>
<h3>Sample Input 3</h3>
<pre>2 10 6
3 2 S
6 4 W</pre>
<h3>Sample Output 3</h3>
<pre>1</pre>
<h3>Sample Input 4</h3>
<pre>6 10 6
1 5 N
7 1 N
8 2 E
9 1 S
4 4 S
3 3 W</pre>
<h3>Sample Output 4</h3>
<pre>3</pre>
<h3>Sample Input 5</h3>
<pre>4 10 6
4 3 W
2 4 N
4 4 W
3 3 S</pre>
<h3>Sample Output 5</h3>
<pre>2</pre>
<h3>Sample Input 6</h3>
<pre>4 100000 40000
25000 25000 S
20000 30000 S
75000 25000 S
80000 30000 S</pre>
<h3>Sample Output 6</h3>
<pre>1</pre>
|
p03617 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You've come to your favorite store Infinitesco to buy some ice tea.</p>
<p>The store sells ice tea in bottles of different volumes at different costs.
Specifically, a <var>0.25</var>-liter bottle costs <var>Q</var> yen, a <var>0.5</var>-liter bottle costs <var>H</var> yen, a <var>1</var>-liter bottle costs <var>S</var> yen, and a <var>2</var>-liter bottle costs <var>D</var> yen.
The store has an infinite supply of bottles of each type.</p>
<p>You want to buy exactly <var>N</var> liters of ice tea. How many yen do you have to spend?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq Q, H, S, D \leq 10^8</var></li>
<li><var>1 \leq N \leq 10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>Q</var> <var>H</var> <var>S</var> <var>D</var>
<var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest number of yen you have to spend to buy exactly <var>N</var> liters of ice tea.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>20 30 70 90
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>150
</pre>
<p>Buy one <var>2</var>-liter bottle and two <var>0.5</var>-liter bottles. You'll get <var>3</var> liters for <var>90 + 30 + 30 = 150</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10000 1000 100 10
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
<p>Even though a <var>2</var>-liter bottle costs just <var>10</var> yen, you need only <var>1</var> liter.
Thus, you have to buy a <var>1</var>-liter bottle for <var>100</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 100 1000 10000
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>40
</pre>
<p>Now it's better to buy four <var>0.25</var>-liter bottles for <var>10 + 10 + 10 + 10 = 40</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>12345678 87654321 12345678 87654321
123456789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1524157763907942
</pre></section>
</div>
</span> |
p02456 | <h1>Set: Delete</h1>
<p>
For a set $S$ of integers, perform a sequence of the following operations. Note that <u>each value in $S$ must be unique</u>.
</p>
<ul>
<li>insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.</li>
<li>find($x$): Report the number of $x$ in $S$ (0 or 1).</li>
<li>delete($x$): Delete $x$ from $S$.</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $x$
</pre>
<p>or</p>
<pre>
1 $x$
</pre>
<p>or</p>
<pre>
2 $x$
</pre>
<p>
where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent insert, find and delete operations respectively.
</p>
<h2>Output</h2>
<p>
For each insert operation, print the number of elements in $S$.<br>
For each find operation, print the number of specified elements in $S$.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq q \leq 200,000$</li>
<li>$0 \leq x \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
8
0 1
0 2
0 3
2 2
1 1
1 2
1 3
0 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1
2
3
1
0
1
3
</pre>
|
p00191 |
<H1>èæš</H1>
<p>
æ€ç©åŠè
ã®ãµããŒå士ã¯èæšçšã®ç¹æ®è¥æãäœçš®é¡ãçºæããŸããããã®è¥æãèæšã«äžãããšãç¬ãéã«èæšã®å€§ãããå€ãããŸãã
äœããè¥æã«ä»¥äžã®ããã«å¯äœçšãããããšã倿ããŸããã
</p>
<ul>
<li>1 åç®ã«äžããè¥æã ãã§ã¯ãèæšã®å€§ãããå€ãããŸããã</li>
<li>2 åç®ä»¥éã¯ããã®åã«äžããè¥æãšããã®çŽåã«äžããè¥æãšã®çµã¿åããã«ãã£ãŠèæšã«åœ±é¿ãäžããŸããè¯ã圱é¿ãäžãããšèæšã䌞ã³ãæªã圱é¿ãäžãããšèæšãçž®ãã§ããŸãããšããããŸãã</li>
</ul>
<p>
詊ãã«ããµããŒå士㯠3 çš®é¡ã®è¥æ (è¥æ 1ã2ã3) ã«å¯Ÿããããæç¹ã§äžããè¥æ (ä»åã®è¥æ) ãšãã®çŽåã«äžããè¥æ (çŽåã®è¥æ) ã®çµã¿åããã«ããèæšã®æé·åºŠåãã調ã¹ã以äžã®ãæé·åºŠè¡šããäœæããŸããã
</p>
<table>
<tr>
<td style="vertical-align:top">
<p>
å³è¡šã® 1 è¡ç®ã¯ä»åäžããè¥æã®çªå·ã§ã1 åç®ã¯ãã®çŽåã«äžããè¥æã®çªå·ã§ããä»ã®æ°åã¯çŽåã«äžããè¥æãšä»åäžããè¥æã®çµã¿åããã«ããèæšã®æé·åºŠ (æé·åŸå¯Ÿæé·åã®å€§ããã®æ¯ç) ã瀺ããŸããæé·åºŠ > 1.0 ã®å Žåã¯èæšã䌞ã³ããæé·åºŠ < 1.0 ã®å Žåã¯èæšãçž®ãããšã瀺ããŸããäŸãã°è¥æ 1 ã®åŸã«è¥æ 2 ãäžãããšèæšã®å€§ããã 3 åã«ãªãããè¥æ 1 ã®åŸã«è¥æ 3 ãäžãããšèæšã®å€§ãããååã«çž®ãã§ããŸããŸãã
</p>
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_babyTree1">
</td>
</tr>
</table>
<br/>
<p>
èæšã«äžããè¥æã®åæ°ãå¶éãããå Žåãèæšãã§ããã ã倧ããè²ãŠãã«ã¯ã©ã®è¥æãã©ã®ãããªé ã§äžããã°ããã§ãããã?ãæé·åºŠè¡šãããã®çãæããŠãããŸããäŸãšããŠäžã®è¡šã«ããè¥æã 3 åã ãäžããå Žåã以äžã®ããã«è¥æ 3 â è¥æ 1 â è¥æ 2 ã®é ã«ããããšæãèæšãæé·ããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_babyTree2">
</center>
<br/>
<ul>
<li> 1 åç®ã®è¥æ (è¥æ 3) ã§ã¯èæšã®å€§ããã¯å€ãããŸããã</li>
<li> 2 åç®ã®è¥æ (è¥æ 1) ã§ã¯ã衚ããè¥æ 3 åŸã®è¥æ 1 ã§ã®æé·åºŠã 3.0 ãªã®ã§ãèæšã®å€§ããã¯ååã® 3.0 åã«ãªããŸãã</li>
<li> 3 åç®ã®è¥æ (è¥æ 2) ã§ã¯ã衚ããè¥æ 1 åŸã®è¥æ 2 ã§ã®æé·åºŠã 3.0 ãªã®ã§ãèæšã®å€§ããã¯ããã«ååã® 3.0 åã§ãæåã® 3.0 × 3.0 ã® 9.0 åã«ãªããŸãã</li>
</ul>
<p>
ä»åºŠã¯ããµããŒå士ã¯çºæãã <var>n</var> çš®é¡ã®è¥æãå
šéšèª¿ã¹ãŠãäžã®ãããªãæé·åºŠè¡šããäœããããŸããããéåžžã«å€§ããªè¡šã«ãªã£ãŠããŸããè¥æã®çš®é¡ãšäžããé çªã決ããã®ã«å€§å€èŠåŽããŠããŸãã
</p>
<p>
ããã§å士ã«ä»£ããã<var>n</var> çš®é¡ã®è¥æã®çµã¿åããã«ããèæšã®ãæé·åºŠè¡šãäžã®æé·åºŠå€éšåãå
¥åãšããè¥æã <var>m</var> åäžããåŸã®æå€§ã®èæšã®å€§ãããæ±ããããã°ã©ã ãäœæããŠãã ããããã ããåãã®èæšã®å€§ããã 1 ãšãã1 åç®ã«äžããè¥æã®æé·åºŠã¯ã©ã®è¥æã§ã 1.0 ãšããŸãããªããè¥æã¯ 1 ãã <var>n</var> ãŸã§çªå·ä»ããããŠããŸãã
<!--åºåããèæšã®å€§ããã¯ãå°æ°ç¹ç¬¬ 3 äœãåæšäºå
¥ããŠãå°æ°ç¹ç¬¬ 2 äœãŸã§æ±ããŠãã ããã-->
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var> <var>m</var>
<var>g<sub>11</sub></var> <var>g<sub>12</sub></var> ... <var>g<sub>1n</sub></var>
<var>g<sub>21</sub></var> <var>g<sub>22</sub></var> ... <var>g<sub>2n</sub></var>
:
<var>g<sub>n1</sub></var> <var>g<sub>n2</sub></var> ... <var>g<sub>nn</sub></var>
</pre>
<p>
1 è¡ç®ã«è¥æã®çš®é¡æ° <var>n</var> (2 ≤ <var>n</var> ≤ 100)ã è¥æãäžããåæ° <var>m</var> (1 ≤ <var>m</var> ≤ 100) ãäžããããŸãã
</p>
<p>
ç¶ã<var>n</var> è¡ã«ãè¥æ <var>i</var> ã®åŸã«è¥æ <var>j</var> ãäžããæã®èæšã®æé·åºŠ <var>g<sub>ij</sub></var> (0.0 ≤ <var>g<sub>ij</sub></var> ≤ 10.0, 宿°) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«ãæå€§ã®èæšã®å€§ãããïŒè¡ã«åºåããŸããåºåããèæšã®å€§ããã¯ãå°æ°ç¹ç¬¬ 3 äœãåæšäºå
¥ããŠãå°æ°ç¹ç¬¬ 2 äœãŸã§æ±ããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
3 3
1.3 3.0 0.5
2.4 2.1 1.0
3.0 0.8 1.2
2 2
1.0 1.0
1.0 1.0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
9.00
1.00
</pre>
|
p02006 | <h1>Problem C. Santa's Gift</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
Santa is going to pack gifts into a bag for a family. There are $N$ kinds of gifts. The size and the price of the $i$-th gift ($1 \leq i \leq N$) are $s_i$ and $p_i$, respectively. The size of the bag is $C$, thus Santa can pack gifts so that the total size of the gifts does not exceed $C$. Children are unhappy if they are given multiple items of the same kind gift, so Santa has to choose at most one gift of the same kind per child.
</p>
<p>
In addition, if a child did not receive a gift that the other children in the same family receive, he/she will complain about that. Hence Santa must distribute gifts fairly to all the children of a family, by giving the same set of gifts to each child. In other words, for a family with $k$ children, Santa must pack zero or $k$ items for each kind of gifts. Santa gives one bag to one family, therefore, the total size of the gifts for each family does not exceed $C$.
</p>
<p>
Santa wants to maximize the total price of packed items for a family but does not know the number of children in the family he is going to visit yet. The number seems at most $M$. To prepare all the possible cases, calculate the maximum total price of items for a family with $k$ children for each $1 \leq k \leq M$.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$C$ $N$ $M$
$s_1$ $p_1$
$...$
$s_N$ $p_N$
</pre>
<p>
The first line contains three integers $C$, $N$ and $M$, where $C$ ($1 \leq C \leq 10^4$) is the size of the bag, $N$ ($1 \leq N \leq 10^4$) is the number of kinds of the gifts, and $M$ ($1 \leq M \leq 10^4$) is the maximum number of children in the family. The $i$-th line of the following $N$ lines contains two integers $s_i$ and $p_i$ ($1 \leq s_i, p_i \leq 10^4$), where $s_i$ and $p_i$ are the size and the price of the $i$-th gift, respectively.
</p>
<h2>Output</h2>
<p>
The output should consist of $M$ lines. In the $k$-th line, print the maximum total price of gifts for a family with $k$ children.
</p>
<h2>Examples</h2>
<h2>Sample Input 1</h2>
<pre>
6 3 2
1 2
2 10
3 5
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
17
24
</pre>
<h2>Sample Input 2</h2>
<pre>
200 5 5
31 41
59 26
53 58
97 93
23 84
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
235
284
375
336
420
</pre>
<h2>Sample Input 3</h2>
<pre>
1 1 2
1 1
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
1
0
</pre>
<h2>Sample Input 4</h2>
<pre>
2 2 2
1 1
2 100
</pre>
<h2>Output for Sample Input 4</h2>
<pre>
100
2
</pre>
|
p00484 |
<H1>倿¬å±(Books) </H1>
<p>
ããªãã®çºã«ã¯JOI 倿¬åºãšããèèã®å€æ¬å±ãããïŒããªãã¯JOI 倿¬åºãããå©çšããŠããïŒããããã®æ¬ã«ã¯åºæºäŸ¡æ Œãå®ãŸã£ãŠããïŒJOI 倿¬åºã«è¡ãã°ãã®äŸ¡æ Œã§è²·ãåã£ãŠããããïŒ
</p>
<p>
JOI 倿¬åºã§ã¯ïŒæ¬ãå°èª¬,挫ç»,éèªãªã©10 çš®é¡ã®ãžã£ã³ã«ã«åé¡ããŠæ±ã£ãŠããïŒãžã£ã³ã«ã«ã¯1ãã10 ãŸã§ã®çªå·ãä»ããããŠããïŒJOI 倿¬åºã«ã¯ïŒåããžã£ã³ã«ã®æ¬ããŸãšããŠè²·ãåã£ãŠããããšé«å€ã§è²·ãåã£ãŠããããšãããµãŒãã¹ãããïŒå
·äœçã«ã¯ïŒåããžã£ã³ã«ã®æ¬ããŸãšããŠT åè²·ãåã£ãŠãããå ŽåïŒãã®ãžã£ã³ã«ã®æ¬ã®äžåãããã®è²·åäŸ¡æ ŒãåºæºäŸ¡æ ŒããT - 1 åé«ããªãïŒäŸãã°ïŒåããžã£ã³ã«ã§åºæºäŸ¡æ Œ100 åïŒ120 åïŒ150 åã®æ¬ããŸãšããŠJOI 倿¬åºã«å£²ã£ããšãããšïŒè²·åäŸ¡æ Œã¯ãããã102 åïŒ122 åïŒ152 åãšãªãïŒ
</p>
<p>
ããŠïŒããªãã¯äžèº«äžã®éœåã§æ¥éœåŒè¶ããããããšã«ãªã£ãïŒããªãã¯N åã®æ¬ãæã£ãŠãããïŒæ°ããäœå±
ã«ãã¹ãŠã®æ¬ãæã£ãŠããããšã¯å°é£ãªããïŒ<i>N</i> åã®æ¬ã®ãã¡<i>K</i> åãJOI 倿¬åºã«å£²ãããšã«ããïŒ
</p>
<h2>課é¡</h2>
<p>
<i>N</i> åã®æ¬ããããã®åºæºäŸ¡æ Œãšãžã£ã³ã«ã®çªå·ãäžãããããšãïŒåèšè²·åäŸ¡æ Œã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å¶é</h2>
<p>
2 ≤ <i>N</i> ≤ 2000 ããªããæã£ãŠããæ¬ã®åæ°<br>
1 ≤ <i>K</i> < <i>N</i> JOI 倿¬åºã«å£²ãæ¬ã®åæ°<br>
1 ≤ <i>C<sub>i</sub></i> ≤ 100000 = 10<sup>5</sup> <i>i</i> çªç®ã®æ¬ã®åºæºäŸ¡æ Œ<br>
1 ≤ <i>G<sub>i</sub></i> ≤ 10 <i>i</i> çªç®ã®æ¬ã®ãžã£ã³ã«ã®çªå·
</ul>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯æŽæ°<i>N</i>, <i>K</i> ã空çœãåºåããšããŠæžãããŠããïŒããªãã®æã£ãŠããæ¬ã®åæ°ã<i>N</i> ã§ïŒãã®ãã¡<i>K</i> åãJOI 倿¬åºã«å£²ãããšã衚ãïŒ
</li>
<li> ç¶ã<i>N</i> è¡ã«ã¯ããªãã®æã£ãŠããæ¬ã®æ
å ±ãæžãããŠããïŒ<i>i</i> + 1 è¡ç®(1 ≤ <i>i</i> ≤ <i>N</i>) ã«ã¯ïŒæŽæ°<i>C<sub>i</sub></i>,<i>G<sub>i</sub></i>ã空çœãåºåããšããŠæžãããŠããïŒ<i>i</i> çªç®ã®æ¬ã®åºæºäŸ¡æ Œã<i>C<sub>i</sub></i> ã§ïŒãžã£ã³ã«ã®çªå·ã<i>G<sub>i</sub></i> ã§ããããšã衚ãïŒ</li>
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒåèšè²·åäŸ¡æ Œã®æå€§å€ãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ
</p>
<h2>æ¡ç¹åºæº</h2>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡ïŒ<br>
é
ç¹ã®20% åã«ã€ããŠã¯ïŒ<i>N</i> ≤ 20 ãæºããïŒ<br>
é
ç¹ã®20% åã«ã€ããŠã¯ïŒãã¹ãŠã®æ¬ã®ãžã£ã³ã«ã¯1 ãŸãã¯2 ã§ããïŒ<br>
é
ç¹ã®10% åã«ã€ããŠã¯ïŒããã2 ã€ã®æ¡ä»¶ã®äž¡æ¹ãæºããïŒ<br>
é
ç¹ã®30% åã«ã€ããŠã¯ïŒããã2 ã€ã®æ¡ä»¶ã®å°ãªããšãäžæ¹ãæºããïŒ<br>
</p>
<h2>å
¥åºåã®äŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
7 4
14 1
13 2
12 3
14 2
8 2
16 3
11 2
</pre>
<h3>åºåäŸ</h3>
<pre>
60
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒ2 çªç®ïŒ4 çªç®ïŒ6 çªç®ïŒ7 çªç®ã®4 åã®æ¬ã売ã£ããšãïŒãžã£ã³ã«2 ã®æ¬ã®è²·åäŸ¡æ Œã1 åããã2 åé«ããªãã®ã§ïŒãããã®æ¬ã®è²·åäŸ¡æ Œã¯ä»¥äžã®ããã«ãªãïŒ
</p>
<table style="margin-left: 50px; margin-right: 50px;">
<tr>
<th width="100" align="left">çªå·</th>
<th width="100" align="left">åºæºäŸ¡æ Œ</th>
<th width="100" align="left">ãžã£ã³ã«</th>
<th width="100" align="left">è²·åäŸ¡æ Œ</th>
</tr>
<tr>
<td>
<pre>
2
4
6
7
</pre>
</td>
<td>
<pre>
13
14
16
11
</pre>
</td>
<td>
<pre>
2
2
3
2
</pre>
</td>
<td>
<pre>
15
16
16
13
</pre>
</td>
</tr>
</table>
<p>
ãã£ãŠåèšè²·åäŸ¡æ Œã¯15 + 16 + 16 + 13 = 60 åã§ããïŒãã®ãšãåèšè²·åäŸ¡æ Œã¯æå€§ãšãªãïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02143 | <h1>Problem G: Painting</h1>
<h2>Problem</h2>
<p>é·ã$N$ã®æ°å$X$ãäžãããããåæç¶æ
ã§ã¯$X$ã®èŠçŽ ã¯å
šãŠ$0$ã§ãããå ããŠã$M$åã®æŽæ°ã®ãã¢$(A_i, B_i)$ãäžãããããåãã¢ã«å¯Ÿã以äžã®æäœãè¡ããæçµçãªæ°å$X$ãåºåããã</p>
<li>æŽæ°$j$ $(1 \le j \le N)$ã«å¯Ÿãã$(A_i+j)$ã$B_i$ã§å²ã£ãäœãã$X_j$ã«å ããã</li>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $M$
$A_1$ $B_1$
$A_2$ $B_2$
:
$A_M$ $B_M$
</pre>
<p>
$1$è¡ç®ã«ãäžããããæ°åã®èŠçŽ æ°$N$ããã¢ã®æ°$M$ã空çœåºåãã§äžããããã<br>
ç¶ã$M$è¡ã«ã$i$çªç®ã®ãã¢$(A_i, B_i)$ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \le N, M \le 10^5$</li>
<li>$0 \le A_i < B_i \le 10^9 (1 \le i \le M)$</li>
<li>äžããããå
¥åã¯å
šãп޿°ã§ãã</li>
</ul>
<h2>Output</h2>
<p>æäœåŸã®æ°åã$N$è¡ã§åºåããã$j$è¡ç®ã«$X_j$ãåºåããã</p>
<h2>Sample Input 1</h2>
<pre>
5 3
1 4
3 7
0 1000
</pre>
<h2>Sample Output 1</h2>
<pre>
7
10
9
5
8
</pre>
<h2>Sample Input 2</h2>
<pre>
14 12
1 4
2 3
0 5
1 4
1 2
0 8
0 2
0 10
0 1
0 8
3 10
1 10
</pre>
<h2>Sample Output 2</h2>
<pre>
15
24
25
31
35
44
32
25
24
15
16
25
31
40
</pre>
|
p03302 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two integers <var>a</var> and <var>b</var>.
Determine if <var>a+b=15</var> or <var>a\times b=15</var> or neither holds.</p>
<p>Note that <var>a+b=15</var> and <var>a\times b=15</var> do not hold at the same time.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a,b \leq 15</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>a+b=15</var>, print <code>+</code>;
if <var>a\times b=15</var>, print <code>*</code>;
if neither holds, print <code>x</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>+
</pre>
<p><var>4+11=15</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>*
</pre>
<p><var>3\times 5=15</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>x
</pre>
<p><var>1+1=2</var> and <var>1\times 1=1</var>, neither of which is <var>15</var>.</p></section>
</div>
</span> |
p01295 |
<H1><font color="#000">Problem C:</font>Champernowne Constant</H1>
<p>
Champernown constant is an irrational number represented in decimal by "<span>0.</span>" followed by
concatenation of all positive integers in the increasing order. The first few digits of this constant
are: 0.123456789101112...
</p>
<p>
Your task is to write a program that outputs the <i>K</i> digits of Chapnernown constant starting at
the <i>N</i>-th place for given two natural numbers <i>K</i> and <i>N</i>.
</p>
<H2>Input</H2>
<p>
The input has multiple lines. Each line has two positive integers <i>N</i> and <i>K</i> (<i>N</i> ≤ 10<sup>9</sup>, <i>K</i> ≤ 100)
separated by a space.
</p>
<p>
The end of input is indicated by a line with two zeros. This line should not be processed.
</p>
<H2>Output</H2>
<p>
For each line, output a line that contains the <i>K</i> digits.
</p>
<H2>Sample Input</H2>
<pre>
4 5
6 7
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
45678
6789101
</pre>
|
p02840 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an integer sequence <var>A</var> of length <var>N</var>, where <var>A_1 = X, A_{i+1} = A_i + D (1 \leq i < N )</var> holds.</p>
<p>Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.</p>
<p>Let <var>S</var> and <var>T</var> be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible values of <var>S - T</var> are there?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>-10^8 \leq X, D \leq 10^8</var></li>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible values of <var>S - T</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p><var>A</var> is <var>(4, 6, 8)</var>.</p>
<p>There are eight ways for (Takahashi, Aoki) to take the elements: <var>((), (4, 6, 8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8), (6))), ((6, 8), (4)))</var>, and <var>((4, 6, 8), ())</var>.</p>
<p>The values of <var>S - T</var> in these ways are <var>-18, -10, -6, -2, 2, 6, 10</var>, and <var>18</var>, respectively, so there are eight possible values of <var>S - T</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 -3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p><var>A</var> is <var>(3, 0)</var>. There are two possible values of <var>S - T</var>: <var>-3</var> and <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 14 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>49805
</pre></section>
</div>
</span> |
p03752 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
Max Score: <var>350</var> Points <br/>
<section>
<h3>Problem Statement</h3>
There are <var>N</var> buildings along the line. The <var>i</var>-th building from the left is colored in color <var>i</var>, and its height is currently <var>a_i</var> meters. <br/>
Chokudai is a mayor of the city, and he loves colorful thigs. And now he wants to see at least <var>K</var> buildings from the left. <br/>
<br/>
You can increase height of buildings, but it costs <var>1</var> yens to increase <var>1</var> meters. It means you cannot make building that height is not integer. <br/>
You cannot decrease height of buildings. <br/>
Calculate the minimum cost of satisfying Chokudai's objective. <br/>
Note: "Building <var>i</var> can see from the left" means there are no <var>j</var> exists that (height of building <var>j</var>) ⥠(height of building <var>i</var>) and <var>j < i</var>. <br/>
</section>
</div>
<div class="io-style">
<div class="part">
<section>
<h3>Input Format</h3>
<pre>
<var>N</var> <var>K</var>
<var>a_1</var> <var>a_2</var> <var>a_3</var> ... <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output Format</h3>
Print the minimum cost in one line. In the end put a line break.<br/>
</section>
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 †K †N †15</var></li>
<li><var>1 †a_i †10^9</var></li>
</ul>
</section>
<section>
<h3>Scoring</h3>
Subtask 1 [<var>120</var> points] <br/>
<ul>
<li><var>N = K</var></li>
</ul>
Subtask 2 [<var>90</var> points] <br/>
<ul>
<li><var>N †5</var></li>
<li><var>a_i †7</var></li>
</ul>
Subtask 3 [<var>140</var> points] <br/>
<ul>
<li>There are no additional constraints.</li>
</ul>
</section>
</div>
</div>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
5 5
3949 3774 3598 3469 3424
</pre>
</section>
<section>
<h3>Sample Output 1</h3>
<pre>
1541
</pre>
The optimal solution is (height of buildings from the left) <var>= [3949, 3950, 3951, 3952, 3953]</var>.<br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
5 3
7 4 2 6 4
</pre>
</section>
<section>
<h3>Sample Output 2</h3>
<pre>
7
</pre>
The optimal solution is (height of buildings from the left) <var>= [7, 8, 2, 9, 4]</var>.<br/>
</section>
</div>
</span> |
p01041 |
<h1>Problem E: Distinct Dictionary</h1>
<h2>Background</h2>
<p>
èŸæžããããªãæããè
ãããã圌ãã¯èªåã ãã®èŸæžãäœãããšã倧奜ãã§ããã
ããã§ããªãã¯åœŒãã®èŸæžã«ãèªç±ã«ã«ã¹ã¿ãã€ãºããæ©èœãä»ãå ããŠãããããšã«ããã
</p>
<h2>Problem</h2>
<p>
åãã«ãäœã®åèªãå
¥ã£ãŠããªã空ã®èŸæžãååšããã
<var>N</var>åã®æåå<var>S<sub>id</sub></var>ãš<var>Q</var>åã®ã¯ãšãªãäžããããã
åã¯ãšãªã¯ã¯ãšãªã®çš®é¡<var>k</var>ãšæååãæã<var>id</var>ã§äžããããã
ã¯ãšãªã®çš®é¡ã¯ä»¥äžã®3ã€ã§ããã
</p>
<ul>
<li><var>k</var>=1ã®ãšã<var>S<sub>id</sub></var>ãèŸæžã«è¿œå ããã</li>
<li><var>k</var>=2ã®ãšã<var>S<sub>id</sub></var>ãèŸæžããåé€ããã</li>
<li><var>k</var>=3ã®ãšãèŸæžã«è¿œå ãããæååã®äžã§<var>S<sub>id</sub></var>ãå
é ããã®éšåæååã«å«ã¿äžã€èŸæžé æå°ã®æååã®<var>id</var>ãåºåãããç¡ãå Žåã¯-1ãåºåããã</li>
</ul>
<p>
åã¯ãšãªã«çããããã°ã©ã ãæžããŠã»ããã
</p>
<p>
泚æïŒ
å
¥åã®ãµã€ãºã倧ããã®ã§é«éãªå
¥åã«å¯Ÿå¿ãã圢åŒãæšå¥šããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>S<sub>1</sub></var>
<var>S<sub>2</sub></var>
.
.
.
<var>S<sub>N</sub></var>
<var>Q</var>
<var>k<sub>1</sub></var> <var>id<sub>1</sub></var>
<var>k<sub>2</sub></var> <var>id<sub>2</sub></var>
.
.
.
<var>k<sub>Q</sub></var> <var>id<sub>Q</sub></var>
</pre>
<p>
1è¡ç®ã«ã1ã€ã®æŽæ°<var>N</var>ãäžããããã2è¡ç®ãã<var>N</var>+1è¡ã«ã<var>N</var>åã®æåå<var>S<sub>id</sub></var>ãäžããããã
<var>N</var>+2è¡ç®ã«ã¯ãšãªã®æ°<var>Q</var>ãäžããããç¶ã<var>Q</var>è¡ã«åã¯ãšãªã®çš®é¡ã衚ã<var>k</var>ãšæååãæã<var>id</var>ãäžãããã
</p>
<h2>Constraints</h2>
<ul>
<li>æååã¯å
šãŠç°ãªãã</li>
<li><var>N</var>åã®æåå<var>S<sub>id</sub></var>ã®é·ãã®åèšã¯10<sup>6</sup>ãè¶
ããªãã</li>
<li>æ¢ã«èŸæžã«è¿œå ãããŠããæååãåã³è¿œå ããããããªå
¥åã¯ååšããªãã</li>
<li>èŸæžã«è¿œå ãããŠããªãæååãåé€ãããããªå
¥åã¯ååšããªãã</li>
<li>äžããããæååã«å«ãŸããæåã¯è±å°æåã®ã¿ã§ããã</li>
<li>1 ≤ <var>N</var> ≤ 10<sup>5</sup></li>
<li>1 ≤ <var>id</var> ≤ <var>N</var></li>
<li>1 ≤ <var>Q</var> ≤ 10<sup>5</sup></li>
<li>1 ≤ |<var>S<sub>id</sub></var>| ≤ 10<sup>5</sup> (ãã ãã|<var>s</var>|ã¯æåå<var>s</var>ã®é·ãã衚ãã)</li>
</ul>
<h2>Output</h2>
<p>
ã¯ãšãªããšã«è§£çãäžè¡ã«åºåããã
</p>
<h2>Sample Input1</h2>
<pre>
3
apple
app
banana
9
1 1
3 1
3 2
3 3
2 1
1 2
3 1
3 2
3 3
</pre>
<h2>Sample Output1</h2>
<pre>
1
1
-1
-1
2
-1
</pre>
<h2>Sample Input2</h2>
<pre>
7
aaaab
aaa
aaaa
aaaaaabc
abbbbbc
ab
abbb
13
1 1
3 2
1 4
3 2
1 3
3 2
2 3
3 3
1 5
1 7
3 6
2 5
3 6
</pre>
<h2>Sample Output2</h2>
<pre>
1
4
3
4
7
7
</pre>
|
p03586 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Process the <var>Q</var> queries below.</p>
<ul>
<li>You are given two integers <var>A_i</var> and <var>M_i</var>. Determine whether there exists a positive integer <var>K_i</var> not exceeding <var>2 Ã 10^{18}</var> such that <var>A_i^{K_i} â¡ K_i</var> <var>(mod</var> <var>M_i)</var>, and find one if it exists.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq Q \leq 100</var></li>
<li><var>0 \leq A_i \leq 10^9(1 \leq i \leq Q)</var></li>
<li><var>1 \leq M_i \leq 10^9(1 \leq i \leq Q)</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>Q</var>
<var>A_1</var> <var>M_1</var>
:
<var>A_Q</var> <var>M_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>In the <var>i</var>-th line, print <var>-1</var> if there is no integer <var>K_i</var> that satisfies the condition.
Otherwise, print an integer <var>K_i</var> not exceeding <var>2 Ã 10^{18}</var> such that <var>A_i^{K_i} â¡ K_i</var> <var>(mod</var> <var>M_i)</var>. If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 4
3 8
9 6
10 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
11
9
2
</pre>
<p>It can be seen that the condition is satisfied: <var>2^4 = 16 â¡ 4</var> <var>(mod</var> <var>4)</var>, <var>3^{11} = 177147 â¡ 11</var> <var>(mod</var> <var>8)</var>, <var>9^9 = 387420489 â¡ 9</var> <var>(mod</var> <var>6)</var> and <var>10^2 = 100 â¡ 2</var> <var>(mod</var> <var>7)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
177 168
2028 88772
123456789 987654321
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7953
234831584
471523108231963269
</pre></section>
</div>
</span> |
p01411 |
<H1>E: Entangled with Lottery</H1>
<p>
ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ
</p>
<p>
仿¥ã®ä¿®è¡ã¯ïŒãã¿ã ãããå©çšããŠïŒæªæ¥ãèªãåãã€ããŠéæ°ãé«ããããšãããã®ã§ããïŒãã¡ããçŽæã«é Œãã ãã§ãªãïŒç¶¿å¯ãªç¢ºçèšç®ãæ¬ ãããªãïŒ
</p>
<p>
ä»åèãããã¿ã ããã¯ïŒé·ã <i>H</i> + 1 ã»ã³ãã¡ãŒãã«ã®çžŠæ£ <i>N</i> æ¬ãããªãïŒãããã¯æ£ã®äžéšãèŠãŠïŒ<i>N</i> æ¬ã®ãã¡ 1 æ¬ãéžã¶ããšã«ãªãïŒæ£ã®äžéšã«ã¯ïŒå·Šãã <i>P</i> æ¬ç®ã®æ£ã®å Žæã«ã®ã¿ãåœããããšæžãããŠããïŒãã¿ã ããã«ã¯ããã€ãã®æšªæ£ãå«ãŸããïŒæšªæ£ã®é
眮ã«é¢ããŠïŒä»¥äžã®æ¡ä»¶ãèãããïŒ
</p>
<ul>
<li>åæšªæ£ã¯ïŒ<i>a</i> ã 1 ä»¥äž <i>H</i> 以äžã®æŽæ°ãšããŠïŒçžŠæ£ã®äžç«¯ãã <i>a</i> ã»ã³ãã¡ãŒãã«ã®é«ãã«ããïŒ</li>
<li>åæšªæ£ã¯ïŒé£ãåã£ã 2 æ¬ã®çžŠæ£ã®ã¿ãçµã¶ïŒ</li>
<li>åãé«ãã«ã¯è€æ°ã®æšªæ£ã¯ååšããªãïŒ</li>
</ul>
<p>
ãããã¯ãããã®æ¡ä»¶ãæºããããã« <i>M</i> æ¬ã®æšªæ£ãåŒããïŒããã«ããããã¯èšæ¶åãè¯ãã®ã§ïŒåœããã®äœçœ®ã暪æ£ã®äœçœ®ããã¹ãŠèŠããŠããŸã£ãŠããïŒãã¿ã ãããæ¥œãããªãïŒããã§åéã®ããã«ããã«æšªæ£ã远å ããŠãããããšã«ããïŒ
</p>
<p>
ãŸãïŒãããã¯åœãããçã£ãŠ <i>N</i> æ¬ã®æ£ã®ãã¡ 1 æ¬ãéžã¶ïŒãã®åŸïŒããã¯ä»¥äžã®æäœãã¡ããã© <i>K</i> åè¡ãïŒ
</p>
<ul>
<li>暪æ£ã远å ããŠãäžã§æå®ãããæ¡ä»¶ãæºãããããªå Žæã®ãã¡ 1 ç®æãç¡äœçºã«éžã¶ïŒããã§ïŒã©ã®å Žæãç確çã§éžã°ãããã®ãšããïŒéžãã å Žæã«æšªæ£ã远å ããïŒ</li>
</ul>
<p>
ãããŠïŒããããéžãã æ£ãåœããã§ãã£ãããå€å®ããïŒæ£ã®èŸ¿ãæ¹ã¯éåžžã®ãã¿ã ãããšåæ§ã§ãã (暪æ£ã«åºäŒããã³ã«é£ã®çžŠæ£ã«ç§»ã)ïŒãããã¯ïŒå¯èœãªéãåœãããšãªã確çãé«ããããïŒ
</p>
<H2>Input</H2>
<pre>
<i>H</i> <i>N</i> <i>P</i> <i>M</i> <i>K</i>
<i>A</i><sub>1</sub> <i>B</i><sub>1</sub>
...
<i>A</i><sub><i>M</i></sub> <i>B</i><sub><i>M</i></sub>
</pre>
<p>
<i>A</i><sub><i>i</i></sub>, <i>B</i><sub><i>i</i></sub> (1 ≤ <i>i</i> ≤ <i>M</i>) ã¯ããããåŒããæšªæ£ã®ãã¡ <i>i</i> çªç®ã®ãã®ãïŒçžŠæ£ã®äžç«¯ãã <i>A</i><sub><i>i</i></sub> ã»ã³ãã¡ãŒãã«ã®é«ãã«ããïŒå·Šãã <i>B</i><sub><i>i</i></sub> æ¬ç®ã®çžŠæ£ãšå·Šãã <i>B</i><sub><i>i</i></sub> + 1 æ¬ç®ã®çžŠæ£ãçµã¶ããšãè¡šãæŽæ°ã§ããïŒ
</p>
<p>
2 ≤ <i>H</i> ≤ 500ïŒ2 ≤ <i>N</i> ≤ 100ïŒ1 ≤ <i>P</i> ≤ <i>N</i>ïŒ1 ≤ <i>M</i> ≤ 100ïŒ1 ≤ <i>K</i> ≤ 100ïŒ<i>M</i> + <i>K</i> ≤ <i>H</i>ïŒ1 ≤ <i>A</i><sub>1</sub> < <i>A</i><sub>2</sub> < ... < <i>A</i><sub><i>M</i></sub> ≤ <i>H</i>ïŒ1 ≤ <i>B</i><sub><i>i</i></sub> ≤ <i>N</i> - 1 ãæºããïŒ
</p>
<H2>Output</H2>
<p>
åœãããšãªã確çãæå€§ãšãªãããã«ããããæ£ãéžãã ãšãã®ïŒåœãããšãªã確çã 1 è¡ã«åºåããïŒ10<sup>-6</sup> 以äžã®çµ¶å¯Ÿèª€å·®ã蚱容ãããïŒ
</p>
<H2>Sample Input 1</H2>
<pre>
9 4 3 2 1
2 1
7 3
</pre>
<H2>Sample Output 1</H2>
<pre>
0.571428571
</pre>
<H2>Sample Input 2</H2>
<pre>
9 4 3 2 3
2 1
7 3
</pre>
<H2>Sample Output 2</H2>
<pre>
0.375661376
</pre> |
p00650 |
<H1>Problem D: The House of Huge Family</H1>
<p>
Mr. Dango's family has an extremely huge number of members.
Once it had about 100 members, and now it has as many as population of a city.
It is jokingly guessed that the member might fill this planet in the near future.
</p>
<p>
Mr. Dango's family, the huge family, is getting their new house.
Scale of the house is as large as that of town.
</p>
<p>
They all had warm and gracious personality and were close each other.
However, in this year the two members of them became to hate each other.
Since the two members had enormous influence in the family, they were split into two groups.
</p>
<p>
They hope that the two groups don't meet each other in the new house.
Though they are in the same building, they can avoid to meet each other by adjusting passageways.
</p>
<p>
Now, you have a figure of room layout. Your task is written below.
</p>
<p>
You have to decide the two groups each room should belong to.
Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group.
All of the rooms need to belong to exactly one group.
And any group has at least one room.
</p>
<p>
To do the task, you can cancel building passageway.
Because the house is under construction, to cancel causes some cost.
You'll be given the number of rooms and information of passageway.
You have to do the task by the lowest cost.
</p>
<p>
Please answer the lowest cost.
</p>
<p>
By characteristics of Mr. Dango's family, they move very slowly.
So all passageways are escalators.
Because of it, the passageways are one-way.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets.
Each dataset is given in the following format.
</p>
<pre>
<i>n</i> <i>m</i>
<i>X<sub>1</sub> Y<sub>1</sub> C<sub>1</sub></i>
...
<i>X<sub>m</sub> Y<sub>m</sub> C<sub>m</sub></i>
</pre>
<p>
All numbers in each datasets are integers.
The integers in each line are separated by a space.
</p>
<p>
The first line of each datasets contains two integers.
<i>n</i> is the number of rooms in the house, m is the number of passageways in the house.
Each room is indexed from 0 to <i>n</i>-1.
</p>
<p>
Each of following <i> m </i> lines gives the details of the passageways in the house.
Each line contains three integers.
The first integer <i>X<sub>i</sub></i> is an index of the room, the starting point of the passageway.
The second integer <i>Y<sub>i</sub></i> is an index of the room, the end point of the passageway.
The third integer <i>C<sub>i</sub></i> is the cost to cancel construction of the passageway.
The passageways, they are escalators, are one-way.
The last dataset is followed by a line containing two zeros (separated by a space).
</p>
<H2>Constraints</h2>
<ul>
<li>2 ≤ <i> n </i> ≤ 100</li>
<li>-10,000 ≤ <i>C<sub>i</sub></i> ≤ 10,000</li>
<li><i>Y<sub>1</sub></i> ... <i>Y<sub>m</sub></i> can't be duplicated integer by each other.</li>
</ul>
<h2>Output</h2>
<p>
For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers.
</p>
<h2>Sample input</h2>
<pre>
3 2
0 1 2
1 2 1
2 1
0 1 100
2 1
0 1 0
2 1
0 1 -1
0 0
</pre>
<h2>Sample output</h2>
<pre>
1
100
0
-1
</pre>
|
p01942 |
<h2>EïŒ ããçŒããã¹ã¿ãŒãšé£ã¹çã - Taiyaki-Master and Eater</h2>
<h3>ç©èª</h3>
<p>ã€ãããã¯ããçŒããäœãã®ããšãŠãäžæãããã³ã¡ããã¯ãããªã€ããããäœãããçŒãã倧奜ãã ãã<var>2</var> äººã¯æ¯é±ããçŒããäœã£ãŠé£ã¹ãŠå¹žãã«éãããŠããããããçŒããäœã£ãŠãããã°ã§é£ã¹çãã®ãã³ã¡ããã«ã€ãŸã¿é£ãããããŠããŸãã®ãã€ãããã®æè¿ã®æ©ã¿ã ã</p>
<p>åŠæ ¡ç¥ã§ããçŒããäœãããšã«ãªã£ãã€ãããã¯ããã€ãã®ããã«ãã³ã¡ããã«ã€ãŸã¿é£ããããŠããã売äžãå¿é
ãªã®ã§ãèªåãæ³šç®ããŠããç¯å²ã®ããçŒãã®æ§åãç¥ãããšãã§ããã°ãããªãšæã£ããåŠæ ¡ç¥ãæåããããã«ãã€ããããå©ããŠããããã</p>
<h3>åé¡</h3>
<p>瞊 <var>H</var>ãæšª <var>W</var> ã®é·æ¹åœ¢ç¶ã®ããçŒããã¬ãŒãããããããçŒããã»ããããŠããçŒãäžãããŸã§ã« <var>T</var> åãããããã®ãã¬ãŒãã¯ããçŒããäžåºŠã«æå€§ <var>HW</var> åçŒãããšãã§ãããã¬ãŒãã®äžãã <var>i</var> <var>(1 \leq i \leq H)</var> çªç®ã§å·Šãã <var>j</var> <var>(1 \leq j \leq W)</var> çªç®ã®å Žæã§çŒããŠããããçŒã㯠<var>(i, j)</var> ã§è¡šãããã</p>
<p>次㮠<var>3</var> çš®é¡ã®ã€ãã³ããåèš <var>Q</var> åçºçããããªããåæç¶æ
ã§ã¯ããçŒãã¯ãããã®å Žæã«ãã»ãããããŠããªãã</p>
<ul>
<li>æå» <var>t</var> ã«ã€ãããã <var>(h, w)</var> ã«ããçŒãã <var>1</var> ã€ã»ããããããã®ããçŒã㯠<var>T</var> åã§çŒãäžãããæå» <var>t+T</var> ã®æç¹ã§é£ã¹ãããšãã§ããããã«ãªãããã ãããã§ã«ããçŒããã»ãããããŠããå Žæã«ããçŒããã»ããããããšã¯ãªãã</li>
<li>æå» <var>t</var> ã«ããã³ã¡ããã <var>(h, w)</var> ã«ããããçŒããã€ãŸã¿é£ãããããšããããã ãã<b>ã€ãŸã¿é£ãã§ããã®ã¯ãã§ã«çŒãäžãã£ãããçŒãã®ã¿ã§ãã</b>ãã€ãŸã¿é£ãããåŸã¯ãã®å ŽæããããçŒããç¡ããªã (ããªãã¡ãããçŒããã»ãããããŠããªãç¶æ
ã«ãªã)ãããçŒããçŒãäžãã£ãŠããªãããŸãã¯ããçŒãããªãå Žæã«ãã€ãŸã¿é£ãã®ã€ãã³ããçºçããå Žåãããããšã«æ³šæããã</li>
<li>å·Šäžã <var>(h_1, w_1)</var>ãå³äžã <var>(h_2, w_2)</var> ãšãªããããªé·æ¹åœ¢é åå
(<var>(h_1, w_1)</var> ããã³ <var>(h_2, w_2)</var> ãå«ã) ã®ããçŒãã«ã€ããŠãæ¬¡ã®æ°ãæå» <var>t</var> ã®æç¹ã§ããããããã€ã§ããããã€ããããã«ãŠã³ãããã</li>
<ul>
<li>ãã§ã«çŒãäžãã£ãããçŒãã®æ°</li>
<li>ãŸã çŒãäžãã£ãŠããªãããçŒãã®æ°</li>
</ul>
</ul>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>H</var> <var>W</var> <var>T</var> <var>Q</var>
<var>t_1</var> <var>c_1</var> <var>h_{11}</var> <var>w_{11}</var> <var>(h_{12}</var> <var>w_{12})</var>
<var>t_2</var> <var>c_2</var> <var>h_{21}</var> <var>w_{21}</var> <var>(h_{22}</var> <var>w_{22})</var>
<var>âŠ</var>
<var>t_Q</var> <var>c_Q</var> <var>h_{Q1}</var> <var>w_{Q1}</var> <var>(h_{Q2}</var> <var>w_{Q2})</var>
</pre>
<p>å
¥åã¯å
šãп޿°ã§äžããããã</p>
<p><var>1</var> è¡ç®ã«ã¯ãããçŒããã¬ãŒãã®çžŠ <var>H</var>ã æšª <var>W</var>ã ããçŒããã»ããããŠããçŒãããããŸã§ã®æé <var>T</var>ã ã€ãã³ãã®æ° <var>Q</var> ãäžããããã</p>
<p><var>1+i</var> <var>(1 \leq i \leq Q)</var> è¡ç®ã«ã¯ãæå» <var>t_i</var> ã§çºçããã€ãã³ãã®å
容ãäžããããã</p>
<ul>
<li><var>c_i</var> ã¯ã€ãã³ãã®çš®é¡ã衚ãããã®å€ã <var>0</var> ãªãã°ããçŒããã»ããããã€ãã³ãã <var>1</var> ãªãã°ã€ãŸã¿é£ããããã€ãã³ãã <var>2</var> ãªãã°ããçŒããã«ãŠã³ãããã€ãã³ããæãã</li>
<li><var>h_{i1}</var> <var>(1 \leq h_{i1} \leq H)</var>ã<var>w_{i1}</var> <var>(1 \leq w_{i1} \leq W)</var> ã¯ã<var>c_i = 0, 1</var> ã«ãããŠæ¬¡ã®ãããªæå³ã§ããã</li>
<ul>
<li><var>c_i = 0</var> ã®ãšãã<var>(h_{i1}, w_{i1})</var> ã®å Žæã«ããçŒãã1ã€ã»ããããã</li>
<li><var>c_i = 1</var> ã®ãšãã<var>(h_{i1}, w_{i1})</var> ã®å Žæã«çŒãäžãã£ãç¶æ
ã®ããçŒããããã°ã€ãŸã¿é£ããããããã§ãªããã°äœãããªãã</li>
</ul>
<li><var>h_{i2}</var>ã<var>w_{i2}</var> ã¯ã<var>c_i = 2</var> ã®ãšãã®ã¿äžããããã</li>
<ul>
<li><var>c_i = 2</var> ã®ãšããå·Šäžã <var>(h_{i1}, w_{i1})</var>ã å³äžã <var>(h_{i2}, w_{i2})</var> ãšããé·æ¹åœ¢é åå
ã®ããçŒãã«ã€ããŠã«ãŠã³ãããã</li>
</ul>
</ul>
<p>å
¥åºåãéåžžã«å€ããªãããšãäºæ³ããããããå
¥åºåã«é
ã颿°ã䜿ã£ãŠããå Žåã¯æ³šæããŠãã ããã</p>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq H \leq 2 \times 10^3</var></li>
<li> <var>1 \leq W \leq 2 \times 10^3</var></li>
<li> <var>1 \leq T \leq 10^9</var></li>
<li> <var>1 \leq Q \leq 10^5</var></li>
<li> <var>1 \leq t_i \leq 10^9</var></li>
<li> <var>i \lt j</var> ãªãã°ã <var>t_i \lt t_j</var></li>
<li> <var>0 \leq c_i \leq 2</var></li>
<li> <var>1 \leq h_{i1} \leq h_{i2} \leq H</var></li>
<li> <var>1 \leq w_{i1} \leq w_{i2} \leq W</var></li>
</ul>
<h3>åºå圢åŒ</h3>
<p>(<var>c_i = 2</var> <var>(1 \leq i \leq Q)</var> ã®åæ°) ã <var>n</var> ãšãããããçŒãã®ã«ãŠã³ãã®çµæããæ¬¡ã®æžãæ¹ã«åŸã£ãŠã€ãã³ãã®çºçæéãæ©ãé ã« <var>n</var> è¡ã«åºåããã</p>
<pre>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>âŠ</var>
<var>a_n</var> <var>b_n</var>
</pre>
<ul>
<li><var>a_i</var> ã¯ãé åå
ã«ãããçŒãäžãã£ãããçŒãã®æ°ãã§ããã</li>
<li><var>b_i</var> ã¯ãé åå
ã«ããããŸã çŒãäžãã£ãŠããªãããçŒãã®æ°ãã§ããã</li>
<li>æ«å°Ÿã®æ¹è¡ãå¿ããªãããšã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
3 3 3 6
1 0 1 1
2 2 1 1 2 2
3 1 1 1
4 0 2 1
5 2 1 1 2 2
6 2 2 1 3 3
</pre>
<h3>åºåäŸ1</h3>
<pre>
0 1
1 1
0 1
</pre>
<p>ãã®å
¥åºåäŸã§ã¯ä»¥äžã®ã€ãã³ããçºçããŠããã</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t01" type="image/png" width="300"></img>
<ul>
<li>æå» <var>1</var> åã«ã<var>(1, 1)</var> ã«ããçŒããã»ããããããã®ããçŒãã¯æå» <var>4</var> åã«çŒãäžããã</li>
</ul>
<img data="IMAGE3/ACPC2017Day3/HUPC2017/aizu17-e-t02.png" type="image/png" width="300"></img>
<ul>
<li>æå» <var>2</var> åã«ãå·Šäž <var>(1, 1)</var>ãå³äž <var>(2, 2)</var> ã®é·æ¹åœ¢é åã«ããããçŒããã«ãŠã³ãããã<var>(1, 1)</var> ã«ã»ããããããçŒãã¯ãŸã çŒãäžãã£ãŠããªãããã<code>0 1</code> ãåºåããã</li>
</ul>
<ul>
<li>æå» <var>3</var> åã«ã<var>(1, 1)</var> ã«ããããçŒããã€ãŸã¿é£ãããããšãããããŸã çŒãäžãã£ãŠããªãã®ã§äœãããªãã</li>
</ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t04" type="image/png" width="300"></img>
<ul>
<li>æå» <var>4</var> åã«ã<var>(2, 1)</var> ã«ããçŒããã»ããããããã®ããçŒãã¯æå» <var>7</var> åã«çŒãäžããã</li>
</ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t05" type="image/png" width="300"></img>
<ul>
<li>æå» <var>5</var> åã«ãå·Šäž <var>(1, 1)</var>ãå³äž <var>(2, 2)</var> ã®é·æ¹åœ¢é åã«ããããçŒããã«ãŠã³ãããã<var>(1, 1)</var> ã®ããçŒãã¯çŒãäžãã£ãŠããã <var>(2, 1)</var> ã®ããçŒãã¯ãŸã çŒãäžãã£ãŠããªãããã<code>1 1</code> ãåºåããã</li>
</ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day3_HUPC2017_aizu17-e-t06" type="image/png" width="300"></img>
<ul>
<li>æå» <var>6</var> åã«ãå·Šäž <var>(2, 1)</var>ãå³äž <var>(3, 3)</var> ã®é·æ¹åœ¢é åã«ããããçŒããã«ãŠã³ãããã<var>(2, 1)</var> ã®ããçŒãã¯ãŸã çŒãäžãã£ãŠããªãããã<code>0 1</code> ãåºåããã</li>
</ul> |
p02397 |
<H1>Swapping Two Numbers</H1>
<p>
Write a program which reads two integers <var>x</var> and <var>y</var>, and prints them in ascending order.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of two integers <var>x</var> and <var>y</var> separated by a single space.
</p>
<p>
The input ends with two 0 (when both <var>x</var> and <var>y</var> are zero). Your program should not process for these terminal symbols.
</p>
<H2>Output</H2>
<p>
For each dataset, print <var>x</var> and <var>y</var> in ascending order in a line. Put a single space between <var>x</var> and </var>y</var>.
</p>
<h2>Constraints</h2>
<ul>
<li> 0 ≤ <var>x</var>, <var>y</var> ≤ 10000</li>
<li> the number of datasets ≤ 3000</li>
</ul>
<H2>Sample Input</H2>
<pre>
3 2
2 2
5 3
0 0
</pre>
<H2>Sample Output</H2>
<pre>
2 3
2 2
3 5
</pre> |
p00200 |
<h1>鿥ã®çéå笊</h1>
<p>
倪éåã¯å€äŒã¿ã«é»è»ã§é·æ
ãããèšç»ãç«ãŠãŠããŸããããã髿 ¡çã®èº«ã§ãã倪éåãäžãµæãããªãå€äŒã¿ã§å¯èœãªéãé ãã«æ
ãããã«ã¯ãåºæ¥ãã ãå®ãè¡ãæ¹ãšåºæ¥ãã ãæ©ãè¡ãæ¹ãããããèŠã€ããªããã°ããŸãèšç»ãç«ãŠãããŸããã倪éåãçŽ æµãªæ
ãæºå«ã§ããããã«ã倪éåã®èšç»ã®å©ãã«ãªãããã°ã©ã ãäœã£ãŠãããŸãããã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_trip">
</center>
<br><br>
<p>
ç·è·¯ã®æ
å ±ãé§
ã®æ°ãå
¥åãšããåãåããã«å¿ããŠãæå°éé¡ãŸãã¯æçæéãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var> <var>m</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>cost<sub>1</sub></var> <var>time<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>cost<sub>2</sub></var> <var>time<sub>2</sub></var>
:
<var>a<sub>n</sub></var> <var>b<sub>n</sub></var> <var>cost<sub>n</sub></var> <var>time<sub>n</sub></var>
<var>k</var>
<var>p<sub>1</sub></var> <var>q<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>p<sub>2</sub></var> <var>q<sub>2</sub></var> <var>r<sub>2</sub></var>
:
<var>p<sub>k</sub></var> <var>q<sub>k</sub></var> <var>r<sub>k</sub></var>
</pre>
<p>
1 è¡ç®ã«ç·è·¯ã®æ
å ±ã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 3000)ãšé§
ã®æ° <var>m</var> (1 ≤ <var>m</var> ≤ 100) ãäžããããŸãã
</p>
<p>
ç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®è·¯ç·ã®æ
å ±ãäžããããŸããåè·¯ç·ã®æ
å ±ãšããŠãè·¯ç·ãã€ãªãïŒã€ã®é§
ã®çªå· <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> ≤ <var>m</var>)ãæé <var>cost<sub>i</sub></var> (1 ≤ <var>cost<sub>i</sub></var> ≤ 1000)ãç§»åæé <var>time<sub>i</sub></var> (1 ≤ <var>time<sub>i</sub></var> ≤ 1000) ãäžããããŸãããã ããåé§
㯠1 ãã <var>m</var> ãŸã§é çªã«çªå·ãä»ããããŠãããã®ãšããŸãã
ãªãã<var>a<sub>i</sub></var> ãš <var>b<sub>i</sub></var> ãç·è·¯ã§ã€ãªãã£ãŠããã°ã<var>a<sub>i</sub></var> ãã <var>b<sub>i</sub></var>ã <var>b<sub>i</sub></var> ãã<var>a<sub>i</sub></var> ã®äž¡æ¹ã®ç§»åãåãæéãšæéã§å¯èœãšããŸãã
</p>
<p>
ç¶ãè¡ã«åãåããã®æ° <var>k</var> (1 ≤ <var>k</var> ≤ 200) ãäžããããŸããç¶ã <var>k</var> è¡ã« <var>i</var> çªç®ã®åãåãããäžããããŸããåååãããšããŠãåºçºé§
<var>p<sub>i</sub></var> ãå°çé§
<var>q<sub>i</sub></var> ãåºåããå€ã®çš®é¡ <var>r<sub>i</sub></var> (0 ãŸã㯠1)ãäžããããŸãããªããåãåããã«ã¯å¿
ãçµè·¯ããããã®ãšããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããªãã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ãæå°éé¡ãããã¯æçæéãïŒè¡ã«åºåããŸãã<var>r<sub>i</sub></var> ã 0 ã®æã¯æå°éé¡ãã 1 ã®æã¯æçæéãåºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
6 5
1 2 200 10
1 4 400 15
1 3 250 25
2 4 100 10
4 5 150 20
3 5 300 20
2
1 5 0
1 5 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
450
35
</pre>
|
p00715 |
<H1>
<font color="#000">Problem F:</font> Name the Crossing
</H1>
<P>
The city of Kyoto is well-known for its Chinese plan: streets are
either North-South or East-West. Some streets are numbered, but most
of them have real names.
<br>
Crossings are named after the two streets crossing there,
e.g. Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo
street. But there is a problem: which name should come first?
At first the order seems quite arbitrary: one says Kawaramachi-Sanjo
(North-South first) but Shijo-Kawaramachi (East-West first). With some
experience, one realizes that actually there
seems to be an "order" on the streets, for instance in the above
Shijo is "stronger" than Kawaramachi, which in turn is "stronger" than
Sanjo.
One can use this order to deduce the names of other crossings.
</P>
<P>
You are given as input a list of known crossing names X-Y.
Streets are either North-South or East-West, and only orthogonal streets
may cross.
</P>
<P>
As your list is very incomplete, you start by completing it using
the following rule:
</P>
<ul>
<li>
two streets A and B have <i>equal strength</i> if (1) to (3) are
all true:
<ol>
<li> they both cross the same third street C in the input </li>
<li> there is no street D such that D-A and B-D appear in the input </li>
<li> there is no street E such that A-E and E-B appear in the input </li>
</ol>
</li>
</ul>
<P>
We use this definition to extend our strength relation:
</P>
<ul>
<li>
A is <i>stronger</i> than B, when there is a
sequence A = A<sub>1</sub>, A<sub>2</sub>, ..., A<sub><i>n</i></sub> = B,
with <i>n</i> at least 2, <br>
where, for any <i>i</i> in 1 .. <i>n</i>-1, either
A<sub><i>i</i></sub>-A<sub><i>i</i>+1</sub> is an input crossing or
A<sub><i>i</i></sub> and A<sub><i>i</i>+1</sub> have equal strength.
</li>
</ul>
<P>
Then you are asked whether some other possible crossing names X-Y are
valid. You should answer affirmatively if you can infer the validity of a
name, negatively if you cannot. Concretely:
</P>
<ul>
<li>
YES if you can infer that the two streets are orthogonal, and X
is stronger than Y
</li>
<li>
NO otherwise
</li>
</ul>
<H2>Input</H2>
<P>
The input is a sequence of data sets, each of the form
</P>
<blockquote>
<pre><i>N
Crossing<sub>1</sub>
...
Crossing<sub>N</sub>
M
Question<sub>1</sub>
...
Question<sub>M</sub>
</i></pre>
</blockquote>
<P>
Both <i>Crossing</i>s and <i>Question</i>s are of the form
</P>
<blockquote>
<i>X-Y</i>
</blockquote>
<P>
where <i>X</i> and <i>Y</i> are strings of alphanumerical characters,
of lengths no more than 16. There is no white space, and case matters
for alphabetical characters.
<br>
<i>N</i> and <i>M</i> are between 1 and 1000 inclusive, and there are
no more than 200 streets in a data set.
</P>
<P>
The last data set is followed by a line containing a zero.
</P>
<H2>Output</H2>
<P>
The output for each data set should be composed of <i>M</i>+1 lines,
the first one containing the number of streets
in the <i>Crossing</i> part of the input, followed by the answers to
each question, either YES or NO without any spaces.
</P>
<H2>Sample Input</H2>
<PRE>
7
Shijo-Kawaramachi
Karasuma-Imadegawa
Kawaramachi-Imadegawa
Nishioji-Shijo
Karasuma-Gojo
Torimaru-Rokujo
Rokujo-Karasuma
6
Shijo-Karasuma
Imadegawa-Nishioji
Nishioji-Gojo
Shijo-Torimaru
Torimaru-Gojo
Shijo-Kawabata
4
1jo-Midosuji
Midosuji-2jo
2jo-Omotesando
Omotesando-1jo
4
Midosuji-1jo
1jo-Midosuji
Midosuji-Omotesando
1jo-1jo
0
</PRE>
<H2>Output for the Sample Input</H2>
<PRE>
8
YES
NO
YES
NO
YES
NO
4
YES
YES
NO
NO
</PRE>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.