question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00474 |
<H1>つらら</H1>
<h2> 問題</h2>
<p>
カナダに住む JOI 君の家の軒下には,立派なつららが出来ている.せっかくなので,JOI 君はつららについて調べてみることにした.
</p>
<p>
JOI 君の家の軒下には N 本(2 ≤ N ≤ 100000 = 10<sup>5</sup> )のつららが出来ている.これらのつららは一直線上に並んでおり,軒下の左端から i cm(1 ≤ i ≤ N )の位置に i 本目のつららが出来ている.i 本目のつららの長さは最初 ai cm(ai は 1 以上の整数)である.これらのつららは,次のような規則によって伸びていく:
</p>
<ul>
<li> i 本目のつららは,i − 1 本目のつららと i + 1 本目のつららの両方よりも長い場合にのみ,1 時間につき 1 cm ずつ伸びる(ただし,両端のつららに関しては片方の隣のみ考える.すなわち,1 本目のつららは 2 本目のつららより長ければ伸び,N 本目のつららは N − 1 本目のつららより長ければ伸びる).
</li>
<li> どのつららも,L cm(2 ≤ L ≤ 50000)に達した瞬間に,根元から折れる(折れたつららは,以後長さ 0 cm のつららとみなす)
.
</li>
</ul>
<p>
最初の段階で,隣り合う 2 本のつららの長さはすべて異なっている.このとき,十分な時間が経過すれば,N 本すべてのつららが折れて長さ 0 cm となる.JOI 君は,つららがこのような状態になるまでの時間を知りたくなった.
</p>
<p>
N 本のつららの最初の長さとつららの限界の長さ L が与えられると,すべてのつららが折れるまでにかかる時間を求めるプログラムを作成せよ.
</p>
<h2>入力</h2>
<!--
<p>
入力ファイルのファイル名は input.txt である.
</p>
-->
<p>
入力の 1 行目には,つららの本数を表す整数 N とつららの限界の長さを表す整数
L が,空白を区切りとしてこの順に書かれている.入力の i + 1 行目 (1 ≤ i ≤ N) に
は, i 本目のつららの最初の長さを表す整数 ai (1 ≤ ai < L) が書かれている.
</p>
<p>
採点用データのうち,配点の 30% 分については,N ≤
500 かつ L ≤
1000 を満
たす.
</p>
<h2> 出力</h2>
<!--
<p>
出力ファイルのファイル名は output.txt である.
</p>
-->
<p>
<!--output.txt-->出力 は,すべてのつららが折れるまでにかかる時間を表す 1 つの整数のみを含む 1 行からなる.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
4 6
4
2
3
5
</pre>
<h3>出力例 1</h3>
<pre>
8
</pre>
<p>
例 1 の場合,1, 2, 3, 4 本目のつららは,それぞれ 2, 8, 4, 1 時間後に折れる.した
がって,すべてのつららが折れるまでにかかる時間は 8 時間であるので,8 を出力
する.
</p>
<br>
<h3>入力例 2</h3>
<pre>
6 10
3
4
1
9
5
1
</pre>
<h3>出力例 2</h3>
<pre>
15
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02449 | <h1>Permutation</h1>
<p>
For given a sequence $A = \{a_0, a_1, ..., a_{n-1}\}$, print the previous permutation and the next permutation in lexicographic order.
</p>
<h2>Input</h2>
<p>
A sequence is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
</pre>
<h2>Output</h2>
<p>
Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively.
Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 9$</li>
<li>$a_i$ consist of $1, 2, ..., n$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
3
2 1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1 3 2
2 1 3
2 3 1
</pre>
<h2>Sample Input 2</h2>
<pre>
3
3 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
3 1 2
3 2 1
</pre>
|
p00024 |
<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>Physical Experiments</H1>
<p>
Ignoring the air resistance, velocity of a freely falling object $v$ after $t$ seconds and its drop $y$ in $t$ seconds are represented by the following formulas:<br/>
<br/>
$ v = 9.8 t $<br/>
$ y = 4.9 t^2 $<br/>
</p>
<!--
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_physical"></center>
-->
<p>
A person is trying to drop down a glass ball and check whether it will crack. Your task is to write a program to help this experiment.
</p>
<p>
You are given the minimum velocity to crack the ball. Your program should print the lowest possible floor of a building to crack the ball. The height of the $N$ floor of the building is defined by $5 \times N - 5$.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset, a line, consists of the minimum velocity <i>v</i> (0 < <i>v</i> < 200) to crack the ball. The value is given by a decimal fraction, with at most 4 digits after the decimal point. The input ends with EOF. The number of datasets is less than or equal to 50.
</p>
<H2>Output</H2>
<p>
For each dataset, print the lowest possible floor where the ball cracks.
</p>
<H2>Sample Input</H2>
<pre>
25.4
25.4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
8
8
</pre>
|
p02019 | <h2>E-修行</h2>
<p>ねねさんはプログラミングの修行のため、$N$ 個の整数 $V_1, V_2, V_3, \cdots, V_N$ について調べるプログラムを作っている。</p>
<p>指導役のうみこさんに言われて、ねねさんは 2, 3, 6 の倍数の個数を調べるプログラムを書いた。</p>
<p>2 の倍数は $A$ 個、3 の倍数は $B$ 個、6 の倍数は $C$ 個だった。</p>
<p>うみこさんは、次は「2 の倍数でも 3 の倍数でもない数」の個数を調べるようにと言った。</p>
<p>しかし、ねねさんは疲れたので、答えだけを求めてごまかすことにした。</p>
<p></p>
<p>$N, A, B, C$ の値だけをもとに、「2 の倍数でも 3 の倍数でもない数」の個数が分かります。これを求めるプログラムを作ってください。</p>
<h3>入力</h3>
<p>$N, A, B, C$ が空白区切りで与えられる。</p>
<h3>出力</h3>
<p>データの中にある「2 の倍数でも 3の倍数でもない数」の個数を出力せよ。ただし、最後には改行を入れること。</p>
<h3>制約</h3>
<ul>
<li>$N$ は $1$ 以上 $100$ 以下の整数</li>
<li>$A, B, C$ は $0$ 以上 $N$ 以下の整数</li>
<li>$A$ が $N$ より大きいなどという、矛盾するデータは与えられない</li>
</ul>
<h3>入力例1</h3>
<pre>
6 3 2 1
</pre>
<h3>出力例1</h3>
<pre>
2
</pre>
<p>例えばデータが $2, 3, 4, 5, 6, 7$ のときは、$5$ と $7$ のふたつが「2 の倍数でも 3 の倍数でもない数」です。</p>
<h3>入力例2</h3>
<pre>
10 9 9 9
</pre>
<h3>出力例2</h3>
<pre>
1
</pre>
|
p03521 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>ButCoder Inc.</em> is a startup company whose main business is the development and operation of the programming competition site "<em>ButCoder</em>".</p>
<p>There are <var>N</var> members of the company including the president, and each member except the president has exactly one direct boss. Each member has a unique ID number from <var>1</var> to <var>N</var>, and the member with the ID <var>i</var> is called Member <var>i</var>. The president is Member <var>1</var>, and the direct boss of Member <var>i</var> <var>(2 ≤ i ≤ N)</var> is Member <var>b_i</var> <var>(1 ≤ b_i < i)</var>.</p>
<p>All the members in ButCoder have gathered in the great hall in the main office to take a group photo. The hall is very large, and all <var>N</var> people can stand in one line. However, they have been unable to decide the order in which they stand. For some reason, all of them except the president want to avoid standing next to their direct bosses.</p>
<p>How many ways are there for them to stand in a line that satisfy their desires? Find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ N ≤ 2000</var></li>
<li><var>1 ≤ b_i < i</var> <var>(2 ≤ i ≤ N)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>b_2</var>
<var>b_3</var>
<var>:</var>
<var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways for the <var>N</var> members to stand in a line, such that no member except the president is next to his/her direct boss, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1
2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Below, we will write <var>A → B</var> to denote the fact that Member <var>A</var> is the direct boss of Member <var>B</var>.</p>
<p>In this case, the hierarchy of the members is <var>1 → 2 → 3 → 4</var>. There are two ways for them to stand in a line that satisfy their desires:</p>
<ul>
<li><var>2, 4, 1, 3</var></li>
<li><var>3, 1, 4, 2</var></li>
</ul>
<p>Note that the latter is the reverse of the former, but we count them individually.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The hierarchy of the members is <var>1 → 2 → 3</var>. No matter what order they stand in, at least one of the desires of Member <var>2</var> and <var>3</var> is not satisfied, so the answer is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1
1
3
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre>
<p>The hierarchy of the members is shown below:</p>
<p><img alt="" src="https://img.atcoder.jp/cf17-exhibition/88bc845e074e0a3fecd96e2db9f3b1a5.png"/></p>
<p>There are eight ways for them to stand in a line that satisfy their desires:</p>
<ul>
<li><var>1, 4, 5, 2, 3</var></li>
<li><var>1, 5, 4, 2, 3</var></li>
<li><var>3, 2, 4, 1, 5</var></li>
<li><var>3, 2, 4, 5, 1</var></li>
<li><var>3, 2, 5, 1, 4</var></li>
<li><var>3, 2, 5, 4, 1</var></li>
<li><var>4, 1, 5, 2, 3</var></li>
<li><var>5, 1, 4, 2, 3</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>15
1
2
3
1
4
2
7
1
8
2
8
1
8
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>97193524
</pre></section>
</div>
</span> |
p03171 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Taro and Jiro will play the following game against each other.</p>
<p>Initially, they are given a sequence <var>a = (a_1, a_2, \ldots, a_N)</var>.
Until <var>a</var> becomes empty, the two players perform the following operation alternately, starting from Taro:</p>
<ul>
<li>Remove the element at the beginning or the end of <var>a</var>. The player earns <var>x</var> points, where <var>x</var> is the removed element.</li>
</ul>
<p>Let <var>X</var> and <var>Y</var> be Taro's and Jiro's total score at the end of the game, respectively.
Taro tries to maximize <var>X - Y</var>, while Jiro tries to minimize <var>X - Y</var>.</p>
<p>Assuming that the two players play optimally, find the resulting value of <var>X - Y</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 3000</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>\ldots</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the resulting value of <var>X - Y</var>, assuming that the two players play optimally.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
10 80 90 30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The game proceeds as follows when the two players play optimally (the element being removed is written bold):</p>
<ul>
<li>Taro: (10, 80, 90, <strong>30</strong>) → (10, 80, 90)</li>
<li>Jiro: (10, 80, <strong>90</strong>) → (10, 80)</li>
<li>Taro: (10, <strong>80</strong>) → (10)</li>
<li>Jiro: (<strong>10</strong>) → ()</li>
</ul>
<p>Here, <var>X = 30 + 80 = 110</var> and <var>Y = 90 + 10 = 100</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
10 100 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-80
</pre>
<p>The game proceeds, for example, as follows when the two players play optimally:</p>
<ul>
<li>Taro: (<strong>10</strong>, 100, 10) → (100, 10)</li>
<li>Jiro: (<strong>100</strong>, 10) → (10)</li>
<li>Taro: (<strong>10</strong>) → ()</li>
</ul>
<p>Here, <var>X = 10 + 10 = 20</var> and <var>Y = 100</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>4999999995
</pre>
<p>The answer may not fit into a 32-bit integer type.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>6
4 2 9 7 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>2
</pre>
<p>The game proceeds, for example, as follows when the two players play optimally:</p>
<ul>
<li>Taro: (4, 2, 9, 7, 1, <strong>5</strong>) → (4, 2, 9, 7, 1)</li>
<li>Jiro: (<strong>4</strong>, 2, 9, 7, 1) → (2, 9, 7, 1)</li>
<li>Taro: (2, 9, 7, <strong>1</strong>) → (2, 9, 7)</li>
<li>Jiro: (2, 9, <strong>7</strong>) → (2, 9)</li>
<li>Taro: (2, <strong>9</strong>) → (2)</li>
<li>Jiro: (<strong>2</strong>) → ()</li>
</ul>
<p>Here, <var>X = 5 + 1 + 9 = 15</var> and <var>Y = 4 + 7 + 2 = 13</var>.</p></section>
</div>
</span> |
p02330 |
<H1>Coin Combination Problem II</H1>
<p>
You have <var>N</var> coins each of which has a value <var>a<sub>i</sub></var>.
Find the number of combinations that result when you choose <var>K</var> different coins in such a way that the total value of the coins is greater than or equal to <var>L</var> and less than or equal to <var>R</var>.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>K</var> ≤ <var>N</var> ≤ 40 </li>
<li> 1 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>16</sup></li>
<li> 1 ≤ <var>L</var> ≤ <var>R</var> ≤ 10<sup>16</sup></li>
<li> All input values are given in integers</li>
</ul>
<H2>Input</H2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>K</var> <var>L</var> <var>R</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var>
</pre>
<H2>Output</H2>
<p>
Print the number of combinations in a line.
</p>
<H2>Sample Input 1</H2>
<pre>
2 2 1 9
5 1
</pre>
<H2>Sample Output 1</H2>
<pre>
1
</pre>
<H2>Sample Input 2</H2>
<pre>
5 2 7 19
3 5 4 2 2
</pre>
<H2>Sample Output 2</H2>
<pre>
5
</pre> |
p02760 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a bingo card with a <var>3\times3</var> grid. The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left contains the number <var>A_{i, j}</var>.</p>
<p>The MC will choose <var>N</var> numbers, <var>b_1, b_2, \cdots, b_N</var>. If our bingo sheet contains some of those numbers, we will mark them on our sheet.</p>
<p>Determine whether we will have a bingo when the <var>N</var> numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A_{i, j} \leq 100</var></li>
<li><var>A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))</var></li>
<li><var>1 \leq N \leq 10</var></li>
<li><var>1 \leq b_i \leq 100</var></li>
<li><var>b_i \neq b_j (i \neq j)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>A_{1, 3}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>A_{2, 3}</var>
<var>A_{3, 1}</var> <var>A_{3, 2}</var> <var>A_{3, 3}</var>
<var>N</var>
<var>b_1</var>
<var>\vdots</var>
<var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If we will have a bingo, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>We will mark <var>A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}</var>, and complete the diagonal from the top-left to the bottom-right.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>41 7 46
26 89 2
78 92 8
5
6
45
16
57
17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>We will mark nothing.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>We will mark all the squares.</p></section>
</div>
</span> |
p03872 | <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> |
p02275 |
<H1>Counting Sort</H1>
<p>
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail:
</p>
<pre>
Counting-Sort(A, B, k)
1 for i = 0 to k
2 do C[i] = 0
3 for j = 1 to length[A]
4 do C[A[j]] = C[A[j]]+1
5 /* C[i] now contains the number of elements equal to i */
6 for i = 1 to k
7 do C[i] = C[i] + C[i-1]
8 /* C[i] now contains the number of elements less than or equal to i */
9 for j = length[A] downto 1
10 do B[C[A[j]]] = A[j]
11 C[A[j]] = C[A[j]]-1
</pre>
<p>
Write a program which sorts elements of given array ascending order based on the counting sort.
</p>
<H2>Input</H2>
<p>
The first line of the input includes an integer <i>n</i>, the number of elements in the sequence.
</p>
<p>
In the second line, <i>n</i> elements of the sequence are given separated by spaces characters.
</p>
<H2>Output</H2>
<p>
Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 2,000,000</li>
<li>0 ≤ A[<i>i</i>] ≤ 10,000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
7
2 5 1 3 2 3 0
</pre>
<H2>Sample Output 1</H2>
<pre>
0 1 2 2 3 3 5
</pre>
|
p00248 |
<H1>魔法陣</H1>
<p>
人里離れた森の奥深くに、マリーという名の魔女が住んでいました。彼女は魔女なので、食料・水・燃料など、生活に必要なものを魔法によってまかなっています。
</p>
<p>
彼女の魔法は、魔力を込めたいくつかの石と紐を使って、魔法陣を描くことによって発動します。この魔法陣は、石を設置し、いくつかの石のペアを紐で繋ぐことで描かれます。ただし、紐は弛んでいてはいけません。さらに、どの紐も、(両端を除いて) 他の紐や石に触れてはいけません。もちろん、同じ場所に複数の石を置くこともできません。この制約が守られる限り、石と石の位置関係や紐の長さに制限はありません。また、石は十分小さいので点として扱うことができ、紐は十分細いので線分として扱うことができます。さらに、彼女は同じ石のペアを2本以上の紐で繋ぐことも、ある紐の両端を同じ石に結ぶこともありません。
</p>
<p>
マリーは初め、石を彼女の家の平らな壁に貼り付けて魔法陣を描いていました。しかし、彼女はやがて、どうしても作ることのできない魔法陣があることに気付いたのです。しばらくして、彼女は魔法陣を平らな壁、つまり二次元平面の上で作ることができるか判定する方法を編み出しました。ある魔法陣は、次のような部分を含む場合、またその場合に限って、二次元平面上で作ることができないのです。
</p>
<center>
<table>
<tr>
<td align="center" style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0251_1" title="Magic Square" alt="MagicSquare" height="200"><br>
</td>
<td width="80">
</td>
<td align="center" style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0251_2" title="Magic Square" alt="MagicSquare" height="200"><br>
</td>
</tr>
<tr>
<td>
図1 頂点数 5 の完全グラフ<br>
</td>
<td>
</td>
<td>
図2 頂点数 3, 3 の完全二部グラフ<br>
</td>
</tr>
</table>
</center>
<br>
<p>
このような魔法陣を描くために、彼女は石を空中に固定する魔法を編み出しました。三次元空間では、これらの魔法陣も描くことができるのです。それどころか、どんな魔法陣も三次元空間中では描くことができることを彼女は突き止めたのです。
</p>
<p>
さて、ここからが問題です。ある日マリーは、彼女の家の玄関に足元灯の魔法陣を作ることにしました。しかし、彼女は既に狭い玄関にいろいろな魔法陣を設置していたので、足元灯の魔法陣を、残された唯一のスペースである一次元の直線の上に描かなければなりません。彼女が設計したいくつかの足元灯の魔法陣について、それが直線の上に描けるかどうかを判定し、描ける場合 <span>yes</span> と、そうでない場合 <span>no</span> と出力するプログラムを作成して下さい。
</p>
<p>
魔法陣は、石の個数 <var>n</var>、紐の本数 <var>m</var>、<var>m</var> 個の紐の情報で与えられます。紐は、その両端の石の番号 <var>u</var>、<var>v</var> で表されます。石には 1 から <var>n</var> までの番号が与えられ、<var>n</var> は 1 以上 100,000 以下、<var>m</var> は 0 以上 1,000,000 以下とします。
</p>
<h2>入力</h2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。各データセットは以下のとおりです。
</p>
<p>
1 行目 石の個数 <var>n</var> 紐の本数 <var>m</var>(整数 整数;半角空白区切り)<br>
2 行目 第1の紐の情報 <var>u</var> <var>v</var>(整数 整数;半角空白区切り)<br>
3 行目 第2の紐の情報<br>
:<br>
<var>m+1 </var>行目 第 <var>m</var> の紐の情報<br>
</p>
<p>
データセットの数は 20 を超えません。
</p>
<h2>出力</h2>
<p>
入力データセットごとに、yes または no と1行に出力します。
</p>
<h2>入力例</h2>
<pre>
5 4
1 2
2 3
3 4
4 5
4 6
1 2
1 3
1 4
2 3
2 4
3 4
5 0
0 0
</pre>
<h2>出力例</h2>
<pre>
yes
no
yes
</pre> |
p02625 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Count the pairs of length-<var>N</var> sequences consisting of integers between <var>1</var> and <var>M</var> (inclusive), <var>A_1, A_2, \cdots, A_{N}</var> and <var>B_1, B_2, \cdots, B_{N}</var>, that satisfy all of the following conditions:</p>
<ul>
<li><var>A_i \neq B_i</var>, for every <var>i</var> such that <var>1\leq i\leq N</var>.</li>
<li><var>A_i \neq A_j</var> and <var>B_i \neq B_j</var>, for every <var>(i, j)</var> such that <var>1\leq i < j\leq N</var>.</li>
</ul>
<p>Since the count can be enormous, print it modulo <var>(10^9+7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1\leq N \leq M \leq 5\times10^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>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the count 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>2
</pre>
<p><var>A_1=1,A_2=2,B_1=2,B_2=1</var> and <var>A_1=2,A_2=1,B_1=1,B_2=2</var> satisfy the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>18
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>141421 356237
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>881613484
</pre></section>
</div>
</span> |
p00618 |
<H1><font color="#000000">Problem D:</font> Course Planning for Lazy Students</H1>
<p>
会津大学では2009年度より、授業履修に関する新しい制度を開始した。新制度では必修科目を撤廃し、それぞれの進路を考慮して科目を自由に選択できるようになった。
</p>
<p>
しかし、どの科目も無条件で履修できるわけではなく、特定の科目を履修するためには、先修条件を満たしている必要がある。下図に履修計画表の一部の例を示す:
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_coursePlanning">
</center>
<br>
<p>
図の長方形が1つの科目を表し科目名と単位数を含んでいる。図の矢印が先修条件を表す。矢印の意味は、矢印の終点で指されている科目を履修するためには、その矢印の始点を示す科目を修得している必要がある。例えば、Linear Algebra II (線形代数2)を履修するためには、Linear Algebra I (線形代数1)を修得している必要がある。また、Applied Algebra (応用代数)を履修するためには、Linear Algebra I と Discrete Systems (離散系論)の両方を修得している必要がある。
</p>
<p>
さて、履修登録計画において卒業に要する最低限の合計単位数 <i>U</i> を満たす履修科目の組み合わせは、怠慢な学生にとって興味深いものである。
</p>
<p>
あなたの仕事は、与えられた履修計画表と <i>U</i> を読み込み、最低限の履修科目数を報告するプログラムを作成することである。これは計画であるため、履修登録した科目は必ず単位を修得できるものと仮定する。
</p>
<H2>Input</H2>
<p>
入力は複数のデータセットからなる。各データセットは以下の形式で与えられる:
</p>
<blockquote>
<i>n</i> <i>U</i><br>
<i>c</i><sub>0</sub> <i>k</i><sub>0</sub> <i>r</i>0<sub>1</sub> <i>r</i>0<sub>2</sub> ... <i>r</i>0<sub><i>k</i><sub>0</sub></sub><br>
<i>c</i><sub>1</sub> <i>k</i><sub>1</sub> <i>r</i>1<sub>1</sub> <i>r</i>1<sub>2</sub> ... <i>r</i>1<sub><i>k</i><sub>1</sub></sub><br>
.<br>
.<br>
<i>c<sub>n-1</sub></i> <i>k<sub>n-1</sub></i> <i>r(n-1)</i><sub>1</sub> <i>r(n-1)</i><sub>2</sub> ... <i>r(n-1)</i><sub><i>k</i><sub><i>n-1</i></sub></sub><br>
</blockquote>
<p>
<i>n</i> (1 ≤ <i>n</i> ≤ 20) は履修計画表が含む科目の数を示す整数である。科目には 0 から <i>n</i>-1 までの番号が割り当てられているものとし、以下 <i>i</i> 番目の科目を科目 <i>i</i> と呼ぶことにする。
</p>
<p>
<i>U</i> (1 ≤ <i>U</i> ≤ 100) は必要な合計単位数を表す整数である。
</p>
<p>
<i>c<sub>i</sub></i> (1 ≤ <i>c<sub>i</sub></i> ≤ 10)は科目 <i>i</i> の単位数を示す。次の <i>k<sub>i</sub></i> (0 ≤ <i>k<sub>i</sub></i> ≤ 5) は科目 <i>i</i> の先修科目の数を示す。それに続く <i>ri</i><sub>1</sub> <i>ri</i><sub>2</sub> ... <i>ri</i><sub><i>k</i><sub><i>i</i></sub></sub> は科目 <i>i</i> の先修科目の科目番号を示す。
</p>
<!--
<p>
入力で与えられる <i>n</i> は 20 以下と仮定してよい。また、<i>U</i> を満たす科目の組み合わせが必ず存在すると仮定してよい。
</p>
-->
<p>
ある科目から先修条件を表す矢印を1つ以上たどり、再びその科目に戻るような入力は与えられない。また、<i>U</i> を満たす科目の組み合わせが必ず存在すると仮定してよい。
</p>
<p>
<i>n</i> と <i>U</i> がともに 0 のとき入力の終わりを示す。データセットの数は 100 を超えない。
</p>
<H2>Output</H2>
<p>
各データセットについて、最低限必要な科目数を1行に出力せよ。
</p>
<H2>Sample Input</H2>
<pre>
4 4
1 0
3 2 0 2
2 0
2 0
3 6
1 0
3 2 0 2
2 0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
3
</pre>
|
p03937 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>We have a grid of <var>H</var> rows and <var>W</var> columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).</p>
<p>You are given a matrix of characters <var>a_{ij}</var> (<var>1 \leq i \leq H</var>, <var>1 \leq j \leq W</var>). After Shik completes all moving actions, <var>a_{ij}</var> is <code>#</code> if the stone had ever located at the <var>i</var>-th row and the <var>j</var>-th column during the process of moving. Otherwise, <var>a_{ij}</var> is <code>.</code>. Please determine whether it is possible that Shik only uses right and down moves in all steps.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq H, W \leq 8</var></li>
<li><var>a_{i,j}</var> is either <code>#</code> or <code>.</code>.</li>
<li>There exists a valid sequence of moves for Shik to generate the map <var>a</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{11}a_{12}</var><var>...</var><var>a_{1W}</var>
<var>:</var>
<var>a_{H1}a_{H2}</var><var>...</var><var>a_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible that Shik only uses right and down moves, print <code>Possible</code>. Otherwise, print <code>Impossible</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5
##...
.##..
..##.
...##
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Possible
</pre>
<p>The matrix can be generated by a <var>7</var>-move sequence: right, down, right, down, right, down, and right.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 3
###
..#
###
#..
###
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Impossible
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 5
##...
.###.
.###.
...##
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Impossible
</pre></section>
</div>
</span> |
p01459 |
<H1>A Light Road</H1>
<p>
There is an evil creature in a square on N-by-M grid (<var>2 \leq N, M \leq 100</var>),
and you want to kill it using a laser generator located in a different square.
Since the location and direction of the laser generator are fixed,
you may need to use several mirrors to reflect laser beams.
There are some obstacles on the grid and you have a limited number of mirrors.
Please find out whether it is possible to kill the creature,
and if possible, find the minimum number of mirrors.
</p>
<p>
There are two types of single-sided mirrors;
type P mirrors can be placed at the angle of 45 or 225 degrees from east-west direction,
and type Q mirrors can be placed with at the angle of 135 or 315 degrees.
For example, four mirrors are located properly, laser go through like the following.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_lightroad3">
</center>
<p>
Note that mirrors are single-sided,
and thus back side (the side with cross in the above picture) is not reflective.
You have <var>A</var> type P mirrors, and also <var>A</var> type Q mirrors (<var>0 \leq A \leq 10</var>).
Although you cannot put mirrors onto the squares with the creature or the laser generator,
laser beam can pass through the square.
Evil creature is killed if the laser reaches the square it is in.
</p>
<H2>Input</H2>
<p>
Each test case consists of several lines.
</p>
<p>
The first line contains three integers, <var>N</var>, <var>M</var>, and <var>A</var>.
Each of the following <var>N</var> lines contains <var>M</var> characters,
and represents the grid information.
'#', '.', 'S', 'G' indicates obstacle, empty square,
the location of the laser generator, and the location of the evil creature, respectively.
The first line shows the information in northernmost squares
and the last line shows the information in southernmost squares.
You can assume that there is exactly one laser generator and exactly one creature,
and the laser generator emits laser beam always toward the south.
</p>
<H2>Output</H2>
<p>
Output the minimum number of mirrors used if you can kill creature, or -1 otherwise.
</p>
<H2>Sample Input 1</H2>
<pre>
3 3 2
S#.
...
.#G
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
2
</pre>
<H2>Sample Input 2</H2>
<pre>
3 3 1
S#.
...
.#G
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
-1
</pre>
<H2>Sample Input 3</H2>
<pre>
3 3 1
S#G
...
.#.
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
2
</pre>
<H2>Sample Input 4</H2>
<pre>
4 3 2
S..
...
..#
.#G
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>
-1
</pre>
|
p03464 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An adult game master and <var>N</var> children are playing a game on an ice rink.
The game consists of <var>K</var> rounds.
In the <var>i</var>-th round, the game master announces:</p>
<ul>
<li>Form groups consisting of <var>A_i</var> children each!</li>
</ul>
<p>Then the children who are still in the game form as many groups of <var>A_i</var> children as possible.
One child may belong to at most one group.
Those who are left without a group leave the game. The others proceed to the next round.
Note that it's possible that nobody leaves the game in some round.</p>
<p>In the end, after the <var>K</var>-th round, there are exactly two children left, and they are declared the winners.</p>
<p>You have heard the values of <var>A_1</var>, <var>A_2</var>, ..., <var>A_K</var>. You don't know <var>N</var>, but you want to estimate it.</p>
<p>Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of <var>N</var> exist.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq 10^5</var></li>
<li><var>2 \leq A_i \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>K</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print two integers representing the smallest and the largest possible value of <var>N</var>, respectively,
or a single integer <var>-1</var> if the described situation is impossible.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 4 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6 8
</pre>
<p>For example, if the game starts with <var>6</var> children, then it proceeds as follows:</p>
<ul>
<li>In the first round, <var>6</var> children form <var>2</var> groups of <var>3</var> children, and nobody leaves the game.</li>
<li>In the second round, <var>6</var> children form <var>1</var> group of <var>4</var> children, and <var>2</var> children leave the game.</li>
<li>In the third round, <var>4</var> children form <var>1</var> group of <var>3</var> children, and <var>1</var> child leaves the game.</li>
<li>In the fourth round, <var>3</var> children form <var>1</var> group of <var>2</var> children, and <var>1</var> child leaves the game.</li>
</ul>
<p>The last <var>2</var> children are declared the winners.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
3 4 100 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>This situation is impossible.
In particular, if the game starts with less than <var>100</var> children, everyone leaves after the third round.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
2 2 2 2 2 2 2 2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2 3
</pre></section>
</div>
</span> |
p01009 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1>Problem D: Room of Time and Spirit</h1>
<h2>Problem</h2>
<p>
20XX年、とある科学者がバイオテクノロジーによって強力な人造人間を開発してしまった。この人造人間はコンピュータにより、戦闘の達人たちの細胞を組み合わせて作られているため非常に強力である。
<br/>
<br/>
このままでは地球は人造人間に支配されてしまうので、 <var>N</var> 人の戦士たちは人造人間と戦うことにした。しかし今の戦士たちでは到底人造人間に敵わないため、修行をしなければならない。また、<var>N</var> 人の戦士たちはそれぞれ 1 ~ <var>N</var> の番号が付いている。
<br/>
<br/>
この時代、天空都市AIZUには SRLU室と呼ばれる修行のための特殊な部屋が存在した。この部屋での1年は外界の時間の1日と同じであるため、短期間で戦闘力を大幅に上昇することが出来る。同時に部屋に入れる人数の上限は2人である。また、その2人が部屋に入った時、それぞれ戦闘力が上昇する。
<br/>
<br/>
戦士たちは残された時間でどのように部屋に入るか検討するため、あなたに以下のクエリを処理するプログラムの作成を依頼した。
<br/>
<br/>
与えられるクエリは以下の通りである。
<br/>
また以下の説明で出てくる <var>A</var>, <var>B</var> はそれぞれ戦士の番号を表す。<var>A</var> と <var>B</var> が等しい事は無い。
<br/>
<br/>
<b>IN <var>A</var> <var>B</var> <var>C</var></b>
<br/>
<br/>
<var>A</var> と <var>B</var> が部屋に入り、それぞれ <var>C</var> だけ戦闘力が上昇する。この時、(部屋に入る直前の <var>B</var> の戦闘力) - (部屋に入る直前の <var>A</var> の戦闘力) = <var>C</var> が成り立つ。また、この時 <var>B</var> の戦闘力は <var>A</var> の戦闘力より高い事が保証される。
<br/>
<br/>
<b>COMPARE <var>A</var> <var>B</var></b>
<br/>
<br/>
<var>A</var> と <var>B</var> の戦闘力の差 (現在の <var>B</var> の戦闘力) - (現在の <var>A</var> の戦闘力)を出力する。もしその差が特定出来なければ、WARNING と出力せよ。
<br/>
<br/>
<h2>Input</h2>
<pre>
<var>N</var> <var>Q</var>
<var>query<sub>1</sub></var>
.
.
.
<var>query<sub>Q</sub></var>
</pre>
<p>
最初に戦士の人数 <var>N</var> , クエリの数 <var>Q</var> が与えられる。
<br/>
次に <var>Q</var> 回だけクエリが与えられる。
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>2 ≤ <var>N</var> ≤ 100000</li>
<li>1 ≤ <var>Q</var> ≤ 100000</li>
<li>1 ≤ <var>A</var>, <var>B</var> ≤ <var>N</var></li>
<li>1 ≤ <var>C</var> ≤ 5000</li>
</ul>
<h2>Output</h2>
<p>
上記のように与えられたクエリを順番に処理していき、 COMPAREの入力が与えられた際に出力を行う。
</p>
<h2>Sample Input1</h2>
<pre>
3 5
COMPARE 1 2
IN 1 2 5
IN 2 3 3
COMPARE 2 3
COMPARE 1 3
</pre>
<h2>Sample Output1</h2>
<pre>
WARNING
3
11
</pre>
<h2>Sample Input2</h2>
<pre>
4 3
IN 1 4 10
IN 2 3 20
COMPARE 1 2
</pre>
<h2>Sample Output2</h2>
<pre>
WARNING
</pre>
<h2>Sample Input3</h2>
<pre>
3 4
IN 2 1 2
IN 3 1 2
COMPARE 1 3
COMPARE 2 3
</pre>
<h2>Sample Output3</h2>
<pre>
-2
2
</pre>
<h2>Sample Input4</h2>
<pre>
10 4
IN 10 8 2328
IN 8 4 3765
IN 3 8 574
COMPARE 4 8
</pre>
<h2>Sample Output4</h2>
<pre>
-3191
</pre>
<h2>Sample Input5</h2>
<pre>
3 5
IN 1 2 5
IN 1 2 5
IN 2 3 10
COMPARE 1 2
COMPARE 2 3
</pre>
<h2>Sample Output5</h2>
<pre>
15
10
</pre> |
p03034 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an infinitely large pond, which we consider as a number line.
In this pond, there are <var>N</var> lotuses floating at coordinates <var>0</var>, <var>1</var>, <var>2</var>, ..., <var>N-2</var> and <var>N-1</var>.
On the lotus at coordinate <var>i</var>, an integer <var>s_i</var> is written.</p>
<p>You are standing on the lotus at coordinate <var>0</var>. You will play a game that proceeds as follows:</p>
<ul>
<li><var>1</var>. Choose positive integers <var>A</var> and <var>B</var>. Your score is initially <var>0</var>.</li>
<li><var>2</var>. Let <var>x</var> be your current coordinate, and <var>y = x+A</var>. The lotus at coordinate <var>x</var> disappears, and you move to coordinate <var>y</var>.<ul>
<li>If <var>y = N-1</var>, the game ends.</li>
<li>If <var>y \neq N-1</var> and there is a lotus floating at coordinate <var>y</var>, your score increases by <var>s_y</var>.</li>
<li>If <var>y \neq N-1</var> and there is no lotus floating at coordinate <var>y</var>, you drown. Your score decreases by <var>10^{100}</var> points, and the game ends.</li>
</ul>
</li>
<li><var>3</var>. Let <var>x</var> be your current coordinate, and <var>y = x-B</var>. The lotus at coordinate <var>x</var> disappears, and you move to coordinate <var>y</var>.<ul>
<li>If <var>y = N-1</var>, the game ends.</li>
<li>If <var>y \neq N-1</var> and there is a lotus floating at coordinate <var>y</var>, your score increases by <var>s_y</var>.</li>
<li>If <var>y \neq N-1</var> and there is no lotus floating at coordinate <var>y</var>, you drown. Your score decreases by <var>10^{100}</var> points, and the game ends.</li>
</ul>
</li>
<li><var>4</var>. Go back to step <var>2</var>.</li>
</ul>
<p>You want to end the game with as high a score as possible.
What is the score obtained by the optimal choice of <var>A</var> and <var>B</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 10^5</var></li>
<li><var>-10^9 \leq s_i \leq 10^9</var></li>
<li><var>s_0=s_{N-1}=0</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>s_0</var> <var>s_1</var> <var>......</var> <var>s_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the score obtained by the optimal choice of <var>A</var> and <var>B</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
0 2 5 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>If you choose <var>A = 3</var> and <var>B = 2</var>, the game proceeds as follows:</p>
<ul>
<li>Move to coordinate <var>0 + 3 = 3</var>. Your score increases by <var>s_3 = 1</var>.</li>
<li>Move to coordinate <var>3 - 2 = 1</var>. Your score increases by <var>s_1 = 2</var>.</li>
<li>Move to coordinate <var>1 + 3 = 4</var>. The game ends with a score of <var>3</var>.</li>
</ul>
<p>There is no way to end the game with a score of <var>4</var> or higher, so the answer is <var>3</var>. Note that you cannot land the lotus at coordinate <var>2</var> without drowning later.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
0 10 -7 -4 -13 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The optimal strategy here is to land the final lotus immediately by choosing <var>A = 5</var> (the value of <var>B</var> does not matter).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11
0 -4 0 -99 31 14 -15 -39 43 18 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>59
</pre></section>
</div>
</span> |
p01584 |
<H1><font color="#000">Problem D:</font> Divide the Water</H1>
<p>
A scientist Arthur C. McDonell is conducting a very complex chemical experiment. This experiment requires a large number of very simple operations to pour water into every column of the vessel at the predetermined ratio. Tired of boring manual work, he was trying to automate the operation.
</p>
<p>
One day, he came upon the idea to use three-pronged tubes to divide the water flow. For example, when you want to pour water into two columns at the ratio of 1 : 1, you can use one three-pronged tube to split one source into two.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_divideTheWater1">
</center>
<p>
He wanted to apply this idea to split water from only one faucet to the experiment vessel at an arbitrary ratio, but it has gradually turned out to be impossible to set the configuration in general, due to the limitations coming from the following conditions:
</p>
<ol>
<li> The vessel he is using has several columns aligned horizontally, and each column has its specific capacity. He cannot rearrange the order of the columns.</li>
<li>There are enough number of glass tubes, rubber tubes and three-pronged tubes. A three-pronged tube always divides the water flow at the ratio of 1 : 1.</li>
<li> Also there are enough number of fater faucets in his laboratory, but they are in the same height.</li>
<li> A three-pronged tube cannot be used to combine two water flows. Moreover, each flow of water going out of the tubes must be poured into exactly one of the columns; he cannot discard water to the sewage, nor pour water into one column from two or more tubes.</li>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_divideTheWater2">
</center>
<li>
The water flows only downward. So he cannot place the tubes over the faucets, nor under the exit of another tubes. Moreover, the tubes cannot be crossed.
</li>
</ol>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_divideTheWater3">
</center>
<p>
Still, Arthur did not want to give up. Although one-to-many division at an arbitrary ratio is impossible, he decided to minimize the number of faucets used. He asked you for a help to write a program to calculate the minimum number of faucets required to pour water into the vessel, for the number of columns and the ratio at which each column is going to be filled.
</p>
<H2>Input</H2>
<p>
The input consists of an integer sequence.
</p>
<p>
The first integer indicates <i>N</i>, the number of columns in the vessel. Then the following <i>N</i> integers describe the capacity by which each column should be filled. The <i>i</i>-th integer in this part specifies the ratio at which he is going to pour water into the <i>i</i>-th column.
</p>
<p>
You may assume that <i>N</i> ≤ 100, and for all <i>i</i>, <i>v<sub>i</sub></i> ≤ 1000000.
</p>
<H2>Output</H2>
<p>
Output the number of the minimum faucet required to complete the operation.
</p>
<H2>Sample Input and Output</H2>
<H2>Input #1</H2>
<pre>
2 1 1
</pre>
<H2>Output #1</H2>
<pre>
1
</pre>
<br/>
<H2>Input #2</H2>
<pre>
2 3 1
</pre>
<H2>Output #2</H2>
<pre>
2
</pre>
<br/>
<H2>Input #3</H2>
<pre>
2 2 1
</pre>
<H2>Output #3</H2>
<pre>
2
</pre>
<br/>
<H2>Input #4</H2>
<pre>
4 3 1 1 3
</pre>
<H2>Output #4</H2>
<pre>
3
</pre>
<br/>
<H2>Input #5</H2>
<pre>
3 1 2 1
</pre>
<H2>Output #5</H2>
<pre>
3
</pre>
<br/>
<H2>Input #6</H2>
<pre>
5 1 2 3 4 5
</pre>
<H2>Output #6</H2>
<pre>
5
</pre>
<br/>
<H2>Input #7</H2>
<pre>
7 8 8 1 1 2 4 8
</pre>
<H2>Output #7</H2>
<pre>
1
</pre>
<br/>
|
p03043 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a fair <var>N</var>-sided die that shows the integers from <var>1</var> to <var>N</var> with equal probability and a fair coin. He will play the following game with them:</p>
<ol>
<li>Throw the die. The current score is the result of the die.</li>
<li>As long as the score is between <var>1</var> and <var>K-1</var> (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes <var>0</var> if the coin lands tails up.</li>
<li>The game ends when the score becomes <var>0</var> or becomes <var>K</var> or above. Snuke wins if the score is <var>K</var> or above, and loses if the score is <var>0</var>.</li>
</ol>
<p>You are given <var>N</var> and <var>K</var>. Find the probability that Snuke wins the game.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 10^5</var></li>
<li><var>1 ≤ K ≤ 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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the probability that Snuke wins the game. The output is considered correct when 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 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0.145833333333
</pre>
<ul>
<li>If the die shows <var>1</var>, Snuke needs to get four consecutive heads from four coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}</var>.</li>
<li>If the die shows <var>2</var>, Snuke needs to get three consecutive heads from three coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}</var>.</li>
<li>If the die shows <var>3</var>, Snuke needs to get two consecutive heads from two coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}</var>.</li>
</ul>
<p>Thus, the probability that Snuke wins is <var>\frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100000 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0.999973749998
</pre></section>
</div>
</span> |
p03413 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have an integer sequence of length <var>N</var>: <var>a_1, a_2, ..., a_N</var>.</p>
<p>You repeatedly perform the following operation until the length of the sequence becomes <var>1</var>:</p>
<ul>
<li>First, choose an element of the sequence.</li>
<li>If that element is at either end of the sequence, delete the element.</li>
<li>If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements.</li>
</ul>
<p>You would like to maximize the final element that remains in the sequence.</p>
<p>Find the maximum possible value of the final element, and the way to achieve it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>2 \leq N \leq 1000</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>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><ul>
<li>In the first line, print the maximum possible value of the final element in the sequence.</li>
<li>In the second line, print the number of operations that you perform.</li>
<li>In the <var>(2+i)</var>-th line, if the element chosen in the <var>i</var>-th operation is the <var>x</var>-th element from the left in the sequence at that moment, print <var>x</var>.</li>
<li>If there are multiple ways to achieve the maximum value of the final element, any of them may be printed.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 4 3 7 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
3
1
4
2
</pre>
<p>The sequence would change as follows:</p>
<ul>
<li>After the first operation: <var>4, 3, 7, 5</var></li>
<li>After the second operation: <var>4, 3, 7</var></li>
<li>After the third operation: <var>11(4+7)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
100 100 -1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>200
2
3
1
</pre>
<ul>
<li>After the first operation: <var>100, 200(100+100)</var></li>
<li>After the second operation: <var>200</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
-1 -2 -3 1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
3
2
1
2
</pre>
<ul>
<li>After the first operation: <var>-4, 1, 2, 3</var></li>
<li>After the second operation: <var>1, 2, 3</var></li>
<li>After the third operation: <var>4</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>9
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5000000000
4
2
2
2
2
</pre></section>
</div>
</span> |
p00395 | <h1> Maze & Items</h1>
<p>
Maze & Items is a puzzle game in which the player tries to reach the goal while collecting items. The maze consists of $W \times H$ grids, and some of them are inaccessible to the player depending on the items he/she has now. The score the player earns is defined according to the order of collecting items. The objective of the game is, after starting from a defined point, to collect all the items using the least number of moves before reaching the goal. There may be multiple routes that allow the least number of moves. In that case, the player seeks to maximize his/her score.
</p>
<p>
One of the following symbols is assigned to each of the grids. You can move to one of the neighboring grids (horizontally or vertically, but not diagonally) in one time, but you cannot move to the area outside the maze.
</p>
<table border="1" style="border-collapse: collapse" cellpadding="8">
<tr><th>Symbol</th><th>Description</th></tr>
<tr>
<td><span>.</span></td><td>Always accessible</td>
</tr>
<tr>
<td><span>#</span></td><td>Always inaccessible</td>
</tr>
<tr>
<td>Number <span>0</span>, <span>1</span>,.., <span>9</span></td><td>Always accessible and an item (with its specific number) is located in the grid.</td>
</tr>
<tr>
<td>Capital letter <span>A</span>, <span>B</span>, ..., <span>J</span></td><td>Accessible only when the player does NOT have the corresponding item. Each of <span>A</span>, <span>B</span>, ..., <span>J</span> takes a value from <span>0</span> to <span>9</span>.</td>
</tr>
<tr>
<td>Small letter <span>a</span>, <span>b</span>, ..., <span>j</span></td><td> Accessible only when the player DOES have the corresponding item. Each of <span>a</span>, <span>b</span>, ..., <span>j</span> takes one value from <span>0</span> to <span>9</span>.</td>
<tr>
<td><span>S</span></td><td>Starting grid. Always accessible.</td>
</tr>
<tr>
<td><span>T</span></td><td>Goal grid. Always accessible.</td>
</tr>
</table>
<br/>
<p>
The player fails to complete the game if he/she has not collected all the items before reaching the goal. When entering a grid in which an item is located, it’s the player’s option to collect it or not. The player must keep the item once he/she collects it, and it disappears from the maze.
</p>
<p>
Given the state information of the maze and a table that defines the collecting order dependent scores, make a program that works out the minimum number of moves required to collect all the items before reaching the goal, and the maximum score gained through performing the moves.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$W$ $H$
$row_1$
$row_2$
...
$row_H$
$s_{00}$ $s_{01}$ ... $s_{09}$
$s_{10}$ $s_{11}$ ... $s_{19}$
...
$s_{90}$ $s_{91}$ ... $s_{99}$
</pre>
<p>
The first line provides the number of horizontal and vertical grids in the maze $W$ ($4 \leq W \leq 1000$) and $H$ ($4 \leq H \leq 1000$). Each of the subsequent $H$ lines provides the information on the grid $row_i$ in the $i$-th row from the top of the maze, where $row_i$ is a string of length $W$ defined in the table above. A letter represents a grid. Each of the subsequent 10 lines provides the table that defines collecting order dependent scores. An element in the table $s_{ij}$ ($0 \leq s_{ij} \leq 100$) is an integer that defines the score when item $j$ is collected after the item $i$ (without any item between them). Note that $s_{ii} = 0$.
</p>
<p>
The grid information satisfies the following conditions:
</p>
<ul>
<li>Each of <span>S</span>, <span>T</span>, <span>0</span>, <span>1</span>, ..., <span>9</span> appears in the maze once and only once.</li>
<li>Each of <span>A</span>, <span>B</span>, ..., <span>J</span>, <span>a</span>, <span>b</span>, ..., <span>j</span> appears in the maze no more than once.</li>
</ul>
<h2>Output</h2>
<p>
Output two items in a line separated by a space: the minimum number of moves and the maximum score associated with that sequence of moves. Output "<span>-1</span>" if unable to attain the game’s objective.
</p>
<h2>Sample Input 1</h2>
<pre>
12 5
.....S......
.abcdefghij.
.0123456789.
.ABCDEFGHIJ.
.....T......
0 1 0 0 0 0 0 0 0 0
2 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 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
</pre>
<h2>Sample Output 1</h2>
<pre>
26 2
</pre>
<h2>Sample Input 2</h2>
<pre>
4 5
0jSB
###.
1234
5678
9..T
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 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
</pre>
<h2>Sample Output 2</h2>
<pre>
31 0
</pre>
<h2>Sample Input 3</h2>
<pre>
7 7
1.3#8.0
#.###.#
#.###.#
5..S..9
#.#T#.#
#.###.#
4.2#6.7
0 0 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 7 0 0 0 0 0
0 2 0 0 0 0 0 0 0 0
0 0 3 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 8 0 0 0
2 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
</pre>
<h2>Sample Output 3</h2>
<pre>
53 19
</pre>
<h2>Sample Input 4</h2>
<pre>
5 6
..S..
#####
01234
56789
#####
..T..
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 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
</pre>
<h2>Sample Output 4</h2>
<pre>
-1
</pre>
|
p02652 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var>, where each character is <code>0</code>, <code>1</code>, or <code>?</code>.</p>
<p>Consider making a string <var>S'</var> by replacing each occurrence of <code>?</code> with <code>0</code> or <code>1</code> (we can choose the character for each <code>?</code> independently).
Let us define the unbalancedness of <var>S'</var> as follows:</p>
<ul>
<li>(The unbalancedness of <var>S'</var>) <var>= \max \{</var> The absolute difference between the number of occurrences of <code>0</code> and <code>1</code> between the <var>l</var>-th and <var>r</var>-th character of <var>S</var> (inclusive) <var>:\ 1 \leq l \leq r \leq |S|\}</var></li>
</ul>
<p>Find the minimum possible unbalancedness of <var>S'</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^6</var></li>
<li>Each character of <var>S</var> is <code>0</code>, <code>1</code>, or <code>?</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible unbalancedness of <var>S'</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0??
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>We can make <var>S'=</var> <code>010</code> and achieve the minimum possible unbalancedness of <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0??0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>??00????0??0????0?0??00??1???11?1?1???1?11?111???1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p03940 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>Imagine a game played on a line. Initially, the player is located at position <var>0</var> with <var>N</var> candies in his possession, and the exit is at position <var>E</var>. There are also <var>N</var> bears in the game. The <var>i</var>-th bear is located at <var>x_i</var>. The maximum moving speed of the player is <var>1</var> while the bears do not move at all.</p>
<p>When the player gives a candy to a bear, it will provide a coin after <var>T</var> units of time. More specifically, if the <var>i</var>-th bear is given a candy at time <var>t</var>, it will put a coin at its position at time <var>t+T</var>. The purpose of this game is to give candies to all the bears, pick up all the coins, and go to the exit. Note that the player can only give a candy to a bear if the player is at the exact same position of the bear. Also, each bear will only produce a coin once. If the player visits the position of a coin after or at the exact same time that the coin is put down, the player can pick up the coin. Coins do not disappear until collected by the player.</p>
<p>Shik is an expert of this game. He can give candies to bears and pick up coins instantly. You are given the configuration of the game. Please calculate the minimum time Shik needs to collect all the coins and go to the exit.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100,000</var></li>
<li><var>1 \leq T, E \leq 10^9</var></li>
<li><var>0 < x_i < E</var></li>
<li><var>x_i < x_{i+1}</var> for <var>1 \leq i < N</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In test cases worth <var>600</var> points, <var>N \leq 2,000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>E</var> <var>T</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 an integer denoting the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 9 1
1 3 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>The optimal strategy is to wait for the coin after treating each bear. The total time spent on waiting is <var>3</var> and moving is <var>9</var>. So the answer is <var>3 + 9 = 12</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 9 3
1 3 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>16
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 1000000000 1000000000
1 999999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2999999996
</pre></section>
</div>
</span> |
p02202 | <h2>ギャグ (Gag)</h2>
<p>Segtree 君は $N$ 個の「ギャグ」を持っていて、それぞれに「できばえ」 $V_i$ という値が定まっています。</p>
<p>Segtree 君は自由な順番で全てのギャグを公開することにしました。</p>
<p>ここで、 $i$ 番目のギャグを $j$ 番目に公開した時に得られる「うれしさ」は $V_i - j$ と表されます。</p>
<p>Segtree 君が得られる「うれしさ」の和の最大値を求めてください。</p>
<h3>入力</h3>
<p>入力は以下の形式で標準入力から与えられる。</p>
<pre>
$N$
$V_1$ $V_2$ $\ldots$ $V_N$
</pre>
<h3>出力</h3>
<p>「うれしさ」の和の最大値を出力してください。ただし、値が 32bit 整数に収まるとは限りません。</p>
<p>最後には改行を入れること。</p>
<h3>制約</h3>
<ul>
<li>$1 \leq N \leq 10^5$</li>
<li>$1 \leq V_i \leq 10^5$</li>
<li>入力は全て整数である。</li>
</ul>
<h3>入力例1</h3>
<pre>
1
59549
</pre>
<h3>出力例1</h3>
<pre>
59548
</pre>
<h3>入力例2</h3>
<pre>
5
2 1 8 5 7
</pre>
<h3>出力例2</h3>
<pre>
8
</pre>
|
p02717 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have three boxes <var>A</var>, <var>B</var>, and <var>C</var>, each of which contains an integer.<br/>
Currently, the boxes <var>A</var>, <var>B</var>, and <var>C</var> contain the integers <var>X</var>, <var>Y</var>, and <var>Z</var>, respectively.<br/>
We will now do the operations below in order. Find the content of each box afterward. </p>
<ul>
<li>Swap the contents of the boxes <var>A</var> and <var>B</var></li>
<li>Swap the contents of the boxes <var>A</var> and <var>C</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq X,Y,Z \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>X</var> <var>Y</var> <var>Z</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the integers contained in the boxes <var>A</var>, <var>B</var>, and <var>C</var>, in this order, with space in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 1 2
</pre>
<p>After the contents of the boxes <var>A</var> and <var>B</var> are swapped, <var>A</var>, <var>B</var>, and <var>C</var> contain <var>2</var>, <var>1</var>, and <var>3</var>, respectively.<br/>
Then, after the contents of <var>A</var> and <var>C</var> are swapped, <var>A</var>, <var>B</var>, and <var>C</var> contain <var>3</var>, <var>1</var>, and <var>2</var>, respectively. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100 100 100
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>41 59 31
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>31 41 59
</pre></section>
</div>
</span> |
p03805 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected unweighted graph with <var>N</var> vertices and <var>M</var> edges that contains neither self-loops nor double edges.<br/>
Here, a <em>self-loop</em> is an edge where <var>a_i = b_i (1≤i≤M)</var>, and <em>double edges</em> are two edges where <var>(a_i,b_i)=(a_j,b_j)</var> or <var>(a_i,b_i)=(b_j,a_j) (1≤i<j≤M)</var>.<br/>
How many different paths start from vertex <var>1</var> and visit all the vertices exactly once?<br/>
Here, the endpoints of a path are considered visited. </p>
<p>For example, let us assume that the following undirected graph shown in Figure 1 is given.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png"/>
<p>Figure 1: an example of an undirected graph</p>
</div>
<p>The following path shown in Figure 2 satisfies the condition.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png"/>
<p>Figure 2: an example of a path that satisfies the condition</p>
</div>
<p>However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png"/>
<p>Figure 3: an example of a path that does not satisfy the condition</p>
</div>
<p>Neither the following path shown in Figure 4, because it does not start from vertex <var>1</var>.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png"/>
<p>Figure 4: another example of a path that does not satisfy the condition</p>
</div>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦8</var> </li>
<li><var>0≦M≦N(N-1)/2</var> </li>
<li><var>1≦a_i<b_i≦N</var> </li>
<li>The given graph contains neither self-loops nor double edges.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different paths that start from vertex <var>1</var> and visit all the vertices exactly once.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The given graph is shown in the following figure:</p>
<div style="text-align: center;">
<img alt="43c0ac53de20d989d100bf60b3cd05fa.png" src="https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png"/>
</div>
<p>The following two paths satisfy the condition:</p>
<div style="text-align: center;">
<img alt="c4a27b591d364fa479314e3261b85071.png" src="https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>This test case is the same as the one described in the problem statement.</p></section>
</div>
</span> |
p01838 |
<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>Optimal Tournament</h2>
<p>
In 21XX, an annual programming contest "Japan Algorithmist GrandPrix (JAG)" has been one of the most popular mind sport events. You, the chairperson of JAG, are preparing this year's JAG competition.
</p>
<p>
JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament is represented as a binary tree having $N$ leaf nodes, to which the contestants are allocated one-to-one. In each match, two contestants compete. The winner proceeds to the next round, and the loser is eliminated from the tournament. The only contestant surviving over the other contestants is the champion. The final match corresponds to the root node of the binary tree.
</p>
<p>
You know the strength of each contestant, $A_1,A_2, ..., A_N$, which is represented as an integer. When two contestants compete, the one having greater strength always wins. If their strengths are the same, the winner is determined randomly.
</p>
<p>
In the past JAG, some audience complained that there were too many boring one-sided games. To make JAG more attractive, you want to find a good tournament configuration.
</p>
<p>
Let's define the boringness of a match and a tournament. For a match in which the $i$-th contestant and the $j$-th contestant compete, we define the boringness of the match as the difference of the strength of the two contestants, $|A_i - A_j|$. And the boringness of a tournament is defined as the sum of the boringness of all matches in the tournament.
</p>
<p>
Your purpose is to minimize the boringness of the tournament.
</p>
<p>
You may consider any shape of the tournament, including unbalanced ones, under the constraint that the height of the tournament must be less than or equal to $K$. The height of the tournament is defined as the maximum number of the matches on the simple path from the root node to any of the leaf nodes of the binary tree.
</p>
<p>
Figure K-1 shows two possible tournaments for Sample Input 1. The height of the left one is 2, and the height of the right one is 3.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2015_K_1"><br/>
</center>
<p>
Write a program that calculates the minimum boringness of the tournament.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case with the following format.<br/>
<br/>
$N$ $K$<br/>
$A_1$ $A_2$ ... $A_N$<br/>
</p>
<p>
The first line of the input contains two integers $N$ ($2 \leq N \leq 1,000$) and $K$ ($1 \leq K \leq 50$). You can assume that $N \leq 2^K$. The second line contains $N$ integers $A_1, A_2, ..., A_N$. $A_i$ ($1 \leq A_i \leq 100,000$) represents the strength of the $i$-th contestant.
</p>
<h3>Output</h3>
<p>
Output the minimum boringness value achieved by the optimal tournament configuration.
</p>
<h3>Sample Input 1</h3>
<pre>
4 3
1 3 4 7
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
6
</pre>
<h3>Sample Input 2</h3>
<pre>
5 3
1 3 4 7 9
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
10
</pre>
<h3>Sample Input 3</h3>
<pre>
18 7
67 64 52 18 39 92 84 66 19 64 1 66 35 34 45 2 79 34
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
114
</pre> |
p02347 |
<H1>Range Search (kD Tree)</H1>
<p>
The range search problem consists of a set of attributed records <var>S</var> to determine which records from <var>S</var> intersect with a given range.
</p>
<p>
For <var>n</var> points on a plane, report a set of points which are within in a given range. Note that you do not need to consider insert and delete operations for the set.
</p>
<H2>Input</H2>
<pre>
<var>n</var>
<var>x<sub>0</sub></var> <var>y<sub>0</sub></var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
:
<var>x<sub>n-1</sub></var> <var>y<sub>n-1</sub></var>
<var>q</var>
<var>sx<sub>0</sub></var> <var>tx<sub>0</sub></var> <var>sy<sub>0</sub></var> <var>ty<sub>0</sub></var>
<var>sx<sub>1</sub></var> <var>tx<sub>1</sub></var> <var>sy<sub>1</sub></var> <var>ty<sub>1</sub></var>
:
<var>sx<sub>q-1</sub></var> <var>tx<sub>q-1</sub></var> <var>sy<sub>q-1</sub></var> <var>ty<sub>q-1</sub></var>
</pre>
<p>
The first integer <var>n</var> is the number of points. In the following <var>n</var> lines, the coordinate of the <var>i</var>-th point is given by two integers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>.
</p>
<p>
The next integer <var>q</var> is the number of queries. In the following <var>q</var> lines, each query is given by four integers,
<var>sx<sub>i</sub></var>,
<var>tx<sub>i</sub></var>,
<var>sy<sub>i</sub></var>,
<var>ty<sub>i</sub></var>.
</p>
<H2>Output</H2>
<p>
For each query, report IDs of points such that
<var>sx<sub>i</sub></var> ≤ <var>x</var> ≤ <var>tx<sub>i</sub></var> and
<var>sy<sub>i</sub></var> ≤ <var>y</var> ≤ <var>ty<sub>i</sub></var>.
The IDs should be reported in ascending order. Print an ID in a line, and print a blank line at the end of output for the each query.
</p>
<H2>Constraints</H2>
<ul>
<li>0 ≤ <var>n</var> ≤ 500,000</li>
<li>0 ≤ <var>q</var> ≤ 20,000</li>
<li>-1,000,000,000 ≤ <var>x</var>, <var>y</var>, <var>sx</var>, <var>tx</var>, <var>sy</var>, <var>ty</var> ≤ 1,000,000,000</li>
<li><var>sx</var> ≤ <var>tx</var></li>
<li><var>sy</var> ≤ <var>ty</var></li>
<li>For each query, the number of points which are within the range is less than or equal to 100.</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
6
2 1
2 2
4 2
6 2
3 3
5 4
2
2 4 0 4
4 10 2 5
</pre>
<H2>Sample Output 1</H2>
<pre>
0
1
2
4
2
3
5
</pre> |
p00680 |
<h1>KND Factory</h1>
<h2>Problem</h2>
<p>
KND君は会津大学に在籍する学生プログラマである。彼の住む町の周辺には<var> N </var>個の町がある。彼は生クリームが大好きなので毎日生クリームを食べるためにある町に工場を建設した。その工場では毎日<var> F </var>リットルの生クリームが製造される。生クリームは運ぶたびに、移動元の町の気温と移動先の町の気温の絶対差だけ傷んでしまう。困ったことにこの近辺の町の気温は寒暖計によって計測できない。しかしながら調査によって、それぞれの町の気温を変数とした<var> N </var>個の一次方程式からなる<var> N </var>元一次連立方程式を導くことができた。あなたはこれを解くことによって各町の気温を知ることができる。また、ある町から他の町へ生クリームを運搬するにはパイプラインを用いる。パイプラインは一日に送ることのできる生クリームの量が限られている。一日に<var> F </var>リットルの生クリームを工場がある町<var> s </var>からKND君が住む町<var> t </var>へ生クリームをなるべく良い状態で送りたい。町には0から始まる番号がつけられているものとする。方程式の各項は高々ひとつの変数からなり定数項がひとつある。<var> F </var>リットルの生クリームはどのような運び方をしても一日以内で任意の町へ送られる。<br>
</p>
<h2>Input</h2>
<p>入力は複数のテストケースからなる。ひとつのテストケースは以下の形式で与えられる。テストケースの数は入力として与えられる。</p>
<pre>
<var>T</var>
<var>N</var> <var>s</var> <var>t</var> <var>F</var>
<var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,N</sub></var> <var>c<sub>1</sub></var>
<var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,N</sub></var> <var>c<sub>2</sub></var>
...
<var>a<sub>N,1</sub></var> <var>a<sub>N,2</sub></var> ... <var>a<sub>N,N</sub></var> <var>c<sub>N</sub></var>
<var>M<sub>1</sub></var>
<var>d<sub>1,1</sub></var> <var>d<sub>1,2</sub></var> ... <var>d<sub>1,M<sub>1</sub></sub></var>
<var>f<sub>1,1</sub></var> <var>f<sub>1,2</sub></var> ... <var>f<sub>1,M<sub>1</sub></sub></var>
<var>M<sub>2</sub></var>
<var>d<sub>2,1</sub></var> <var>d<sub>2,2</sub></var> ... <var>d<sub>2,M<sub>2</sub></sub></var>
<var>f<sub>2,1</sub></var> <var>f<sub>2,2</sub></var> ... <var>f<sub>2,M<sub>2</sub></sub></var>
...
<var>M<sub>N</sub></var>
<var>d<sub>N,1</sub></var> <var>d<sub>N,2</sub></var> ... <var>d<sub>N,M<sub>2</sub></sub></var>
<var>f<sub>N,1</sub></var> <var>f<sub>N,2</sub></var> ... <var>f<sub>N,M<sub>2</sub></sub></var>
</pre>
<p>ここで、
</p>
<ul>
<li><var>T</var>:テストケースの数</li>
<li><var>N</var>:町の数</li>
<li><var>s</var>:工場のある町</li>
<li><var>t</var>:KND君の住む町</li>
<li><var>F</var>:一日に作られる生クリームの量</li>
<li><var>a<sub>i,j</sub></var>:連立方程式の未知数としてのi番目の方程式中でj番目の町の気温にかかる係数。もし<var>a<sub>i,j</sub></var>=0ならj番目の町の気温はこの方程式に現れないことになる。以下の例も参照してほしい。</li>
<li><var>c<sub>i</sub></var>:i番目の方程式の定数項</li>
<li><var>M<sub>i</sub></var>:i番目の町が持っている生クリームを移動させる機械の数</li>
<li><var>d<sub>i,j</sub></var>:i番目の町が持っているj番目の機械が生クリームを移動させる先の町</li>
<li><var>f<sub>i,j</sub></var>:i番目の町が持っているj番目の機械が生クリームを1日に移動させられるリットル量</li>
</ul>
<p>
である。
</p>
<p>
<var>N</var>元一次連立方程式を表す行列の入力例:<br>
</p>
<pre>
a + b = 6 1 1 0 6
3a + 2b + c = 10 => 3 2 1 10
a - 2b + 3c = 6 1 -2 3 6
</pre>
<p>
a,b,cが町0,1,2の気温を表す。
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>入力はすべて整数。</li>
<li>0 <<var> T </var>≤ 40</li>
<li>2 <<var> N </var>≤ 100</li>
<li>0 ≤<var> s </var><<var> N </var></li>
<li>0 ≤<var> t </var><<var> N </var></li>
<li><var>s</var> ≠ <var>t</var></li>
<li>0 <<var> F </var>≤ 1000</li>
<li>0 ≤<var> M<sub>i</sub> </var>≤<var> N </var></li>
<li>-1000 ≤ <var>a<sub>i,j</sub></var> ≤ 1000</li>
<li>0 ≤<var>f<sub>i,j</sub></var>< 1000</li>
<li>それぞれの町の気温は一意に定まる。</li>
</ul>
<h2>Output</h2>
<p>
各テストケースにつき、一日に<var> F </var>リットルの生クリームを工場がある町<var> s </var>からKND君が住む町<var> t </var>に運んだとき、生クリームの傷みの和を最小化した値を一行で出力せよ。この値はジャッジ出力の値と10<sup>-5</sup>より大きい差を持ってはならない。また、町<var> s </var>から町<var> t </var>へ<var> F </var>リットルの生クリームを一日に運べない場合はimpossibleを一行で出力せよ。
</p>
<h2>Sample Input</h2>
<pre>
3
3 0 2 5
1 1 1 6
3 2 1 10
1 -2 3 6
2
1 2
3 3
1
2
3
0
3 0 2 5
1 1 1 6
3 2 1 10
1 -2 3 6
2
1 2
2 2
1
2
2
0
10 2 7 20
8 9 -5 6 -9 5 1 0 4 9 4
3 -1 -8 0 -5 4 3 0 -3 2 4
-4 5 8 -4 1 -8 -6 3 3 5 -7
-7 0 2 5 8 -5 -9 -8 1 -2 -1
3 8 1 -3 8 2 -5 8 -3 4 -4
-2 5 0 -2 -4 4 -3 9 6 -1 -2
4 1 2 -9 3 5 6 -4 4 -1 -4
-4 6 6 9 -2 1 -9 -3 -7 3 -4
1 -1 6 3 1 -5 9 5 -5 -9 -5
-7 4 6 8 8 4 -4 4 -7 -8 -5
5
1 5 0 6 3
15 17 14 7 15
3
1 5 7
6 8 14
10
3 5 3 5 9 5 9 5 1 4
12 6 16 11 16 7 9 3 13 13
10
9 1 5 6 2 5 8 5 9 4
15 8 8 14 13 13 18 1 12 11
5
3 5 0 4 6
14 15 4 14 11
9
5 0 6 2 7 8 8 6 6
6 5 7 17 17 17 17 19 3
9
7 7 2 7 8 4 7 7 0
4 13 16 10 19 17 19 12 19
3
1 5 1
3 7 16
8
5 7 4 9 1 4 6 8
4 3 6 12 6 19 10 1
4
1 3 6 3
5 15 18 14
</pre>
<h2>Sample Output</h2>
<pre>
10.0000000000
impossible
11.9354380207
</pre> |
p01992 | <h2>D: しりとり圧縮 (Shiritori Compression)</h2>
<h3>問題</h3>
<p>えびちゃんとかにちゃんの二人はしりとりをしました。えびちゃんはしりとりで出た単語のメモを見ています。</p>
<p>えびちゃんは、この単語列 <var>w_1</var>, <var>w_2</var>, <var>...</var>, <var>w_N</var> から冗長な連続部分列を、存在しなくなるまで取り除きたいと思っています。えびちゃんの思う冗長な連続部分列とは以下のように定義されます。</p>
<ul>
<li>以下を満たす <var>i</var>, <var>j</var> が存在したとき、連続部分列 <var>w_i</var>, <var>...</var>, <var>w_{j-1}</var> は冗長です。</li>
<ul>
<li><var>i < j</var> なる添字 <var>i</var>, <var>j</var> について、単語 <var>w_i</var> と <var>w_j</var> の先頭の文字が等しい。</li>
</ul>
</ul>
<p>このとき、えびちゃんは添字 <var>i</var> 以上 <var>j-1</var> 以下の単語を取り除きます。</p>
<p>たとえば、次のような単語列を考えます。</p>
<ul>
<li> apple→editor→random→me→edge</li>
</ul>
<p>これは、次のように圧縮されます。</p>
<ul>
<li> apple→edge</li>
</ul>
<p>editor と edge の先頭の文字が e で一致しているため、editor から edge の直前(me)までの単語が取り除かれます。</p>
<p>えびちゃんの判断基準では、末尾の文字が同じであっても冗長とは見なさないことに注意してください。たとえば、上の圧縮済み単語列において、apple と edge の末尾の文字はどちらも e ですが、このことによって単語が取り除かれることはありません。</p>
<p>また、以下のような例も考えられます。</p>
<ul>
<li> orange→eel→luck</li>
<li> banana→at→tomb→bus→sound→does→some</li>
<li> peach→hero→owl→loop→proof→fish→he</li>
</ul>
<p>これらはそれぞれ次のように圧縮できます。いずれも、最後の単語は保存されることに注意してください。</p>
<ul>
<li> orange→eel→luck</li>
<ul>
<li> すでに圧縮済みです。</li>
</ul>
<li> bus→some</li>
<ul>
<li> banana から bus、sound から some がそれぞれ圧縮可能です。</li>
</ul>
<li> peach→he</li>
<ul>
<li> proof→fish→he と圧縮することもできますが、圧縮後の単語数が異なっていることに注意してください。</li>
</ul>
</ul>
<p>えびちゃんのメモが与えられるので、それらを圧縮して得られる単語列の長さ(単語数)の最小値 <var>L</var> を出力してください。</p>
<p>なお、「同じ単語が複数回現れる」または「ある単語の先頭の文字が直前の単語の末尾の文字と一致していない」ことは起こらないと仮定して構いません。</p>
<h3>入力形式</h3>
<pre>
<var>N</var>
<var>w_1</var>
<var>...</var>
<var>w_N</var>
</pre>
<p>一行目に単語数 <var>N</var> が与えられ、<var>1+i</var> 行目には <var>i</var> 番目の単語が与えられます。</p>
<h3>制約</h3>
<ul>
<li><var>1\leq N\leq 10^5</var></li>
<li><var>1\leq </var> $\sum_{i=1}^N$<var>|w_i| \leq 10^6</var></li>
<li><var>w_i</var> の各文字は英小文字</li>
</ul>
<h3>出力形式</h3>
<p><var>L</var> を一行に出力してください。それ以外の余計な文字は含まれてはいけません。</p>
<h3>入力例1</h3>
<pre>
7
banana
at
tomb
bus
sound
does
some
</pre>
<h3>出力例1</h3>
<pre>2</pre>
<p>上で挙げた例です。</p>
<h3>入力例2</h3>
<pre>
7
peach
hero
owl
loop
proof
fish
he
</pre>
<h3>出力例2</h3>
<pre>2</pre>
<p>上で挙げた別の例です。</p>
|
p03106 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given positive integers <var>A</var> and <var>B</var>.</p>
<p>Find the <var>K</var>-th largest positive integer that divides both <var>A</var> and <var>B</var>.</p>
<p>The input guarantees that there exists such a number.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A, B \leq 100</var></li>
<li>The <var>K</var>-th largest positive integer that divides both <var>A</var> and <var>B</var> exists.</li>
<li><var>K \geq 1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the <var>K</var>-th largest positive integer that divides both <var>A</var> and <var>B</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 12 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Three positive integers divides both <var>8</var> and <var>12</var>: <var>1, 2</var> and <var>4</var>.
Among them, the second largest is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 50 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p03556 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the largest square number not exceeding <var>N</var>. Here, a <em>square number</em> is an integer that can be represented as the square of an integer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^9</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the largest square number not exceeding <var>N</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p><var>10</var> is not square, but <var>9 = 3 × 3</var> is. Thus, we print <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>81
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>81
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>271828182
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>271821169
</pre></section>
</div>
</span> |
p01091 |
<h2>Complex Paper Folding</h2>
<p>
Dr. G, an authority in paper folding and one of the directors of
Intercultural Consortium on Paper Crafts,
believes complexity gives figures beauty.
As one of his assistants, your job is to find the way to fold a paper
to obtain the most complex figure.
Dr. G defines the complexity of a figure by the number of vertices.
With the same number of vertices, one with longer perimeter is more
complex.
To simplify the problem, we consider papers with convex polygon in
their shapes and folding them only once.
Each paper should be folded so that one of its vertices exactly lies
on top of another vertex.
</p><p>
Write a program that, for each given convex polygon, outputs the
perimeter of the most complex polygon obtained by folding it once.
</p>
<p>
Figure 1 (left) illustrates the polygon given in the first dataset of
Sample Input. This happens to be a rectangle.
Folding this rectangle can yield three different polygons illustrated in the Figures 1-a to c by solid
lines.
For this dataset, you should answer the perimeter of the pentagon
shown in Figure 1-a. Though the rectangle in Figure 1-b has longer
perimeter, the number of vertices takes priority.
</p>
<center>
<table border="0">
<tbody><tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G1-1" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G1-2" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G1-3" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G1-4" valign="middle" width="100%"></td></tr>
<tr><td></td>
<td align="center">(a)</td>
<td align="center">(b)</td>
<td align="center">(c)</td></tr>
</tbody></table>
<br>
Figure 1: The case of the first sample input
</center>
<p>
Figure 2 (left) illustrates the polygon given in the second
dataset of Sample Input, which is a triangle. Whichever pair of its vertices are
chosen, quadrangles are obtained as shown in Figures 2-a to c. Among
these, you should answer the longest perimeter, which is that of the
quadrangle shown in Figure 2-a.
</p>
<center>
<table border="0">
<tbody><tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G2-1" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G2-2" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G2-3" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G2-4" valign="middle" width="100%"></td></tr>
<tr><td></td>
<td align="center">(a)</td>
<td align="center">(b)</td>
<td align="center">(c)</td></tr>
</tbody></table>
<br>
Figure 2: The case of the second sample input
</center>
<p>
Although we start with a convex polygon, folding it may result a
concave polygon.
Figure 3 (left) illustrates the polygon given in the third dataset in Sample Input.
A concave hexagon shown in Figure 3 (right) can be obtained
by folding it, which has the largest number of vertices.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G3-1" valign="middle" width="25%">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G3-2" valign="middle" width="25%">
<br>
Figure 3: The case of the third sample input
</center>
<p>
Figure 4 (left) illustrates the polygon given in the fifth dataset in
Sample
Input.
Although the perimeter of the polygon in Figure 4-b is longer than that
of the polygon in Figure 4-a, because the polygon in Figure 4-b is a
quadrangle, the answer should be the perimeter of the pentagon in Figure
4-a.
</p>
<center>
<table border="0">
<tbody><tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G4-1" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G4-2" valign="middle" width="100%"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_G4-3" valign="middle" width="100%"></td></tr>
<tr><td></td>
<td align="center">(a)</td>
<td align="center">(b)</td></tr>
</tbody></table>
<br>
Figure 4: The case of the fifth sample input
</center>
<h3>Input</h3>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<i>n</i> <br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br>
... <br>
<i>x<sub>n</sub></i> <i>y<sub>n</sub></i> <br>
</blockquote>
<p>
<i>n</i> is the number of vertices of the given polygon.
<i>n</i> is a positive integer satisfying 3 ≤ <i>n</i> ≤ 20.
(<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) gives the coordinates of
the <i>i</i>-th vertex.
<i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> are integers
satisfying 0 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> < 1000.
The vertices (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>), ..., (<i>x<sub>n</sub></i>, <i>y<sub>n</sub></i>)
are given in the counterclockwise order on the <i>xy</i>-plane with <i>y</i> axis oriented upwards.
You can assume that all the given polygons are convex.
</p><p>
All the possible polygons obtained by folding the given polygon
satisfy the following conditions.
</p><ul>
<li>Distance between any two vertices is greater than or equal to 0.00001. </li>
<li>For any three consecutive vertices P, Q, and R, the distance between the
point Q and the line passing through the points P and R is greater than or equal to 0.00001. </li>
</ul>
<p>
The end of the input is indicated by a line with a zero.
</p>
<h3>Output</h3>
<p>
For each dataset, output the perimeter of the most complex polygon
obtained through folding the given polygon.
The output value should not have an error greater than 0.00001.
Any extra characters should not appear in the output.
</p>
<h3>Sample Input</h3>
<pre>4
0 0
10 0
10 5
0 5
3
5 0
17 3
7 10
4
0 5
5 0
10 0
7 8
4
0 0
40 0
50 5
0 5
4
0 0
10 0
20 5
10 5
7
4 0
20 0
24 1
22 10
2 10
0 6
0 4
18
728 997
117 996
14 988
1 908
0 428
2 98
6 54
30 28
106 2
746 1
979 17
997 25
998 185
999 573
999 938
995 973
970 993
910 995
6
0 40
0 30
10 0
20 0
40 70
30 70
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>23.090170
28.528295
23.553450
97.135255
34.270510
57.124116
3327.900180
142.111776
</pre>
|
p00053 |
<H1>素数の和</H1>
<p>
<var>p(i)</var> を小さい方から <var>i</var> 番目の素数とします。例えば、7 は、2, 3, 5, 7 と小さい方から 4 番目の素数なので、<var>p(4) = 7</var> です。
</p>
<p>
<var>n</var> が与えられたとき、<var>i = 1</var> から <var>n</var> までの <var>p(i)</var> の和 <var>s</var><br/>
<br/>
<var>s = p(1) + p(2) +</var> .... <var>+ p(n)</var><br/>
<br/>
を出力するプログラムを作成してください。例えば、<var>n = 9</var> のとき、<var>s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 = 100</var> となります。
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。各データセットに整数 <var>n</var> (<var>n</var> ≤ 10000) が与えられます。<var>n</var> が 0 のとき入力の最後とします。データセットの数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
各データセットの <var>n</var> に対して、<var>s</var> を1行に出力して下さい。
</p>
<H2>Sample Input</H2>
<pre>
2
9
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
100
</pre>
|
p02594 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You will turn on the air conditioner if, and only if, the temperature of the room is <var>30</var> degrees Celsius or above.</p>
<p>The current temperature of the room is <var>X</var> degrees Celsius. Will you turn on the air conditioner?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>-40 \leq X \leq 40</var></li>
<li><var>X</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Yes</code> if you will turn on the air conditioner; print <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>25
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre></section>
</div>
</span> |
p00403 | <h1>ねこのあな</h1>
<p>
あなたの家の近所には多くの猫が出入りする横穴があります。中は行き止まりで通り抜けることはできませんが、近所の猫が全部入れるくらいの奥行きがあります。穴の幅は猫がちょうど収まるくらいなので、先に入った猫を後から入った猫が押しのけて奥に向かうことはできません。また、先に入った猫が、後から入ってきた猫を押しのけて出口から出ることもできません。
</p>
<p>
猫好きのあなたは横穴に出入りする猫を順番に記録していきました。記録をはじめたときは横穴の中には一匹も猫はいませんでしたが、やがて猫たちは横穴への出入りを始めました。同じ猫が何度も出入りすることもありました。
</p>
<p>
記録を終えたあなたは、正しく記録できたかプログラムを書いてチェックすることにしました。
</p>
<p>
横穴に出入りした猫のリストが与えられる。リストを先頭から順に見ていったとき、それより後ろを見なくても誤りと判断できる最初の位置を求めるプログラムを作成せよ。ただし、猫は100匹いて、1から100までの番号が与えられているものとする。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
$L$
$c_1$ $c_2$ ... $c_L$
</pre>
<p>
1行目に横穴に出入りした猫のリストの長さ$L$ ($1 \leq L \leq 1000$)が与えられる。続く1行に、$i$番目に横穴に出入りした猫の情報$c_i$ ($-100 \leq c_i \leq 100$, ただし$c_i≠0$)が与えられる。ただし、$i$番目に出入りした猫の番号が$a$で、その猫が横穴に入ったときは$c_i=a$、横穴から出たときは$c_i=-a$である。
</p>
<h2>出力</h2>
<p>
リストを先頭から順に見ていったとき、それより後ろを見なくても誤りと判断できる最初の位置を1行に出力する。誤りがない場合は、「OK」を1行に出力する。
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
4
1 2 -3 -1
</pre>
<h3>出力例1</h3>
<pre>
3
</pre>
<h3>入力例2</h3>
<pre>
6
2 1 2 -2 -1 -2
</pre>
<h3>出力例2</h3>
<pre>
3
</pre>
<h3>入力例3</h3>
<pre>
5
2 1 -1 3 -3
</pre>
<h3>出力例3</h3>
<pre>
OK
</pre>
|
p00950 |
<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 E
Infallibly Crack Perplexing Cryptarithm
</h2>
<p>
You are asked to crack an encrypted equation over binary numbers.
</p>
<p>
The original equation consists only of binary digits ("0" and "1"), operator symbols ("+", "-", and "*"), parentheses ("(" and ")"), and an equal sign ("="). The encryption replaces some occurrences of characters in an original arithmetic equation by letters. Occurrences of one character are replaced, if ever, by the same letter. Occurrences of two different characters are never replaced by the same letter. Note that the encryption does not always replace all the occurrences of the same character; some of its occurrences may be replaced while others may be left as they are. Some characters may be left unreplaced. Any character in the Roman alphabet, in either lowercase or uppercase, may be used as a replacement letter. Note that cases are significant, that is, "a" and "A" are different letters. Note that not only digits but also operator symbols, parentheses and even the equal sign are possibly replaced.
</p>
<p>
The arithmetic equation is derived from the start symbol of $Q$ of the following context-free grammar.<br/>
<br/>
$Q ::= E=E$<br/>
$E ::= T | E+T | E-T$<br/>
$T ::= F | T*F $<br/>
$F ::= N | -F | (E) $<br/>
$N ::= 0 | 1B $<br/>
$B ::= \epsilon | 0B | 1B$<br/>
<br/>
Here, $\epsilon$ means empty.
</p>
<p>
As shown in this grammar, the arithmetic equation should have one equal sign. Each side of the equation is an expression consisting of numbers, additions, subtractions, multiplications, and negations. Multiplication has precedence over both addition and subtraction, while negation precedes multiplication. Multiplication, addition and subtraction are left associative. For example, <span>x-y+z</span> means <span>(x-y)+z</span>, not <span>x-(y+z)</span>. Numbers are in binary notation, represented by a sequence of binary digits, 0 and 1. Multi-digit numbers always start with 1. Parentheses and negations may appear redundantly in the equation, as in <span>((--x+y))+z</span>.
</p>
<p>
Write a program that, for a given encrypted equation, counts the number of different possible original correct equations. Here, an equation should conform to the grammar and it is correct when the computed values of the both sides are equal.
</p>
<p>
For Sample Input 1, C must be = because any equation has one <span>=</span> between two expressions. Then, because <span>A</span> and <span>M</span> should be different, although there are equations conforming to the grammar, none of them can be correct.
</p>
<p>
For Sample Input 2, the only possible correct equation is <span>-0=0</span>.
</p>
<p>
For Sample Input 3 (B-A-Y-L-zero-R), there are three different correct equations, <span>0=-(0)</span>, <span>0=(-0)</span>, and <span>-0=(0)</span>. Note that one of the two occurrences of zero is not replaced with a letter in the encrypted equation.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case which is a string of Roman alphabet characters, binary digits, operator symbols, parentheses and equal signs. The input string has at most 31 characters.
</p>
<h3>Output</h3>
<p>
Print in a line the number of correct equations that can be encrypted into the input string.
</p>
<h3>Sample Input 1</h3>
<pre>ACM</pre>
<h3>Sample Output 1</h3>
<pre>0</pre>
<br/>
<h3>Sample Input 2</h3>
<pre>icpc</pre>
<h3>Sample Output 2</h3>
<pre>1</pre>
<br/>
<h3>Sample Input 3</h3>
<pre>BAYL0R</pre>
<h3>Sample Output 3</h3>
<pre>3</pre>
<br/>
<h3>Sample Input 4</h3>
<pre>-AB+AC-A</pre>
<h3>Sample Output 4</h3>
<pre>1</pre>
<br/>
<h3>Sample Input 5</h3>
<pre>abcdefghi</pre>
<h3>Sample Output 5</h3>
<pre>0</pre>
<br/>
<h3>Sample Input 6</h3>
<pre>111-10=1+10*10</pre>
<h3>Sample Output 6</h3>
<pre>1</pre>
<br/>
<h3>Sample Input 7</h3>
<pre>0=10-1</pre>
<h3>Sample Output 7</h3>
<pre>0</pre>
|
p01642 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: { inlineMath: [['\\(','\\)']] }
});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<h1 class="ndoc-heading1">Problem I: Reverse Game</h1>
<p class="ndoc-top">
あるところにオセロが趣味な女の子がいました。時間があるときに家族とオセロを楽しんでいます。</p>
<p class="ndoc-top">
ある日、女の子はいつものようにオセロで遊ぼうとしました。ところが、みんな忙しくて誰も遊んでくれませんでした。
そこでオセロのボードとこまを使って1人で遊べるゲームを考え出しました。</p>
<h2 class="ndoc-heading2">問題</h2>
<p class="ndoc-top">
縦\( R \)マス、横\( C \)マスのマス目全てにオセロの駒が上面が黒あるいは白になるように配置されている。</p>
<p class="ndoc-top">
以下の図のように「あるマスを選んで、その上下左右斜め方向にある駒を全て裏返す」という操作を繰り返し行うことを考える。
全ての駒の上面を白にするような操作の仕方の個数を求めよ。 ただし、以下の条件を満たす必要がある。</p>
<ul class="ndoc-indent">
<li>同じマスに二度操作を行うことはできない</li>
<li>操作の順序は区別しない</li>
<li>全ての駒の上面が白になってから操作を続けることは可能である</li>
</ul>
<p class="ndoc-top"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_rev" height="300px"></p>
<h2 class="ndoc-heading2">入力</h2>
<p class="ndoc-top">1行目に整数\( R \)と整数\( C \)がそれぞれ空白区切りで与えられる。</p>
<p class="ndoc-top">続けて\( R \)行に、それぞれ\( C \)個の整数値(0か1)が与えられる。\( r \)行目の\(
c \)個目の整数は、マス目(r,c)の状態を表す。</p>
<p class="ndoc-top">1は上面が黒であることを、0は上面が白であることを表す。</p>
<h2 class="ndoc-heading2">出力</h2>
<p class="ndoc-top">盤面の全ての駒の上面を白にすることができるなら、そのような操作の仕方の個数を\(
1000000009 (= 10 ^ 9 + 9) \)で割った余りを1行に出力せよ。</p>
<p class="ndoc-top">盤面の全ての駒の上面を白にすることができないなら、\( 0 \)と1行に出力せよ。</p>
<h2 class="ndoc-heading2">制約</h2>
<ul class="ndoc-indent">
<li>\(1 \leq R \leq 50, 1 \leq C \leq 50\)</li>
</ul>
<h2 class="ndoc-heading2">サンプル入出力</h2>
<h3 class="ndoc-heading3">入力1</h3>
<pre>
1 3
1 1 1
</pre>
<h3 class="ndoc-heading3">出力1</h3>
<pre>
4
</pre>
<p>\( \{(1,1)\}, \{(1,2)\}, \{(1,3)\}, \{(1,1),(1,2),(1,3)\} \)の4通りである。</p>
<h3 class="ndoc-heading3">入力2</h3>
<pre>
1 3
1 0 1
</pre>
<h3 class="ndoc-heading3">出力2</h3>
<pre>
0
</pre>
<h3 class="ndoc-heading3">入力3</h3>
<pre>
2 4
0 1 0 1
1 0 1 0
</pre>
<h3 class="ndoc-heading3">出力3</h3>
<pre>
1
</pre> |
p03385 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>3</var> consisting of <code>a</code>, <code>b</code> and <code>c</code>. Determine if <var>S</var> can be obtained by permuting <code>abc</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>|S|=3</var></li>
<li><var>S</var> consists of <code>a</code>, <code>b</code> and <code>c</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>S</var> can be obtained by permuting <code>abc</code>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>bac
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Swapping the first and second characters in <code>bac</code> results in <code>abc</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>bab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abc
</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>aaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> |
p01212 |
<H1><font color="#000">Problem F:</font> Mysterious Dungeons</H1>
<p>
The Kingdom of Aqua Canora Mystica is a very affluent and peaceful country, but around the
kingdom, there are many evil monsters that kill people. So the king gave an order to you to kill
the master monster.
</p>
<p>
You came to the dungeon where the monster lived. The dungeon consists of a grid of square
cells. You explored the dungeon moving up, down, left and right. You finally found, fought
against, and killed the monster.
</p>
<p>
Now, you are going to get out of the dungeon and return home. However, you found strange
carpets and big rocks are placed in the dungeon, which were not there until you killed the
monster. They are caused by the final magic the monster cast just before its death! Every rock
occupies one whole cell, and you cannot go through that cell. Also, each carpet covers exactly
one cell. Each rock is labeled by an uppercase letter and each carpet by a lowercase. Some of
the rocks and carpets may have the same label.
</p>
<p>
While going around in the dungeon, you observed the following behaviors. When you enter
into the cell covered by a carpet, all the rocks labeled with the corresponding letter (e.g., the
rocks with ‘A’ for the carpets with ‘a’) disappear. After the disappearance, you can enter the
cells where the rocks disappeared, but if you enter the same carpet cell again or another carpet
cell with the same label, the rocks revive and prevent your entrance again. After the revival,
you have to move on the corresponding carpet cell again in order to have those rocks disappear
again.
</p>
<p>
Can you exit from the dungeon? If you can, how quickly can you exit? Your task is to write
a program that determines whether you can exit the dungeon, and computes the minimum
required time.
</p>
<H2>Input</H2>
<p>
The input consists of some data sets.
</p>
<p>
Each data set begins with a line containing two integers, <i>W</i> and <i>H</i> (3 ≤ <i>W</i>, <i>H</i> ≤ 30). In each
of the following <i>H</i> lines, there are <i>W</i> characters, describing the map of the dungeon as <i>W</i> × <i>H</i>
grid of square cells. Each character is one of the following:
</p>
<ul>
<li> ‘@’ denoting your current position,</li>
<li> ‘<’ denoting the exit of the dungeon,</li>
<li> A lowercase letter denoting a cell covered by a carpet with the label of that letter,</li>
<li> An uppercase letter denoting a cell occupied by a rock with the label of that letter,</li>
<li> ‘#’ denoting a wall, and</li>
<li> ‘.’ denoting an empty cell.</li>
</ul>
<p>
Every dungeon is surrounded by wall cells (‘#’), and has exactly one ‘@’ cell and one ‘<’ cell.
There can be up to eight distinct uppercase labels for the rocks and eight distinct lowercase
labels for the carpets.
</p>
<p>
You can move to one of adjacent cells (up, down, left, or right) in one second. You cannot move
to wall cells or the rock cells.
</p>
<p>
A line containing two zeros indicates the end of the input, and should not be processed.
</p>
<H2>Output</H2>
<p>
For each data set, output the minimum time required to move from the ‘@’ cell to the ‘<’ cell,
in seconds, in one line. If you cannot exit, output -1.
</p>
<H2>Sample Input</H2>
<pre>
8 3
########
#<A.@.a#
########
8 3
########
#<AaAa@#
########
8 4
########
#<EeEe@#
#FG.e#.#
########
8 8
########
#mmm@ZZ#
#mAAAbZ#
#mABBBZ#
#mABCCd#
#aABCDD#
#ZZcCD<#
########
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7
-1
7
27
</pre>
|
p04010 | <span class="lang-en">
<p>Score : <var>2200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected graph with <var>N</var> vertices and <var>M</var> edges.
Here, <var>N-1≤M≤N</var> holds and the graph is connected.
There are no self-loops or multiple edges in this graph.</p>
<p>The vertices are numbered <var>1</var> through <var>N</var>, and the edges are numbered <var>1</var> through <var>M</var>.
Edge <var>i</var> connects vertices <var>a_i</var> and <var>b_i</var>.</p>
<p>The color of each vertex can be either white or black.
Initially, all the vertices are white.
Snuke is trying to turn all the vertices black by performing the following operation some number of times:</p>
<ul>
<li>Select a pair of adjacent vertices with the same color, and invert the colors of those vertices. That is, if the vertices are both white, then turn them black, and vice versa.</li>
</ul>
<p>Determine if it is possible to turn all the vertices black. If the answer is positive, find the minimum number of times the operation needs to be performed in order to achieve the objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≤N≤10^5</var></li>
<li><var>N-1≤M≤N</var></li>
<li><var>1≤a_i,b_i≤N</var></li>
<li>There are no self-loops or multiple edges in the given graph.</li>
<li>The given graph is connected.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In the test set worth <var>1500</var> points, <var>M=N-1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to turn all the vertices black, print the minimum number of times the operation needs to be performed in order to achieve the objective.
Otherwise, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 5
1 2
1 3
1 4
2 5
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>For example, it is possible to perform the operations as shown in the following diagram:</p>
<p><img src="/img/agc/004/gatbantar/F_1.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>It is not possible to turn all the vertices black.</p>
<p><img src="/img/agc/004/gatbantar/F_2.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 4
1 2
2 3
3 4
4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
<p>This case is not included in the test set for the partial score.</p>
<p><img src="/img/agc/004/gatbantar/F_3.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6 6
1 2
2 3
3 1
1 4
1 5
1 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>7
</pre>
<p>This case is not included in the test set for the partial score.</p>
<p><img src="/img/agc/004/gatbantar/F_4.png"/></p></section>
</div>
</span> |
p02828 | <span class="lang-en">
<p>Score : <var>2000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let us consider a grid of squares with <var>N</var> rows and <var>N</var> columns.
Arbok has cut out some part of the grid so that, for each <var>i = 1, 2, \ldots, N</var>, the bottommost <var>h_i</var> squares are remaining in the <var>i</var>-th column from the left.
Now, he wants to place rooks into some of the remaining squares.</p>
<p>A rook is a chess piece that occupies one square and can move horizontally or vertically, through any number of unoccupied squares.
A rook can not move through squares that have been cut out by Arbok.</p>
<p>Let's say that a square is covered if it either contains a rook, or a rook can be moved to this square in one move.</p>
<p>Find the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 400</var></li>
<li><var>1 \leq h_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>h_1</var> <var>h_2</var> <var>...</var> <var>h_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to place rooks into some of the remaining squares so that every remaining square is covered, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
</pre>
<p>Any placement with at least two rooks is fine. There are <var>11</var> such placements.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>17
</pre>
<p>The following <var>17</var> rook placements satisfy the conditions (<code>R</code> denotes a rook, <code>*</code> denotes an empty square):</p>
<pre>R * * R * * R R R R R R
**R R** R*R R** *R* **R
R * R * * R * R * * R R
R*R *RR RR* R*R RRR RR*
R R R R R * * R R R
R*R *RR RRR RRR RRR
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 2 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>201
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
4 7 4 8 4 6 8 2 3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>263244071
</pre></section>
</div>
</span> |
p00815 | <H1><font color="#000">Problem E:</font> Map of Ninja House</H1>
<p>
An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated manner, so that any invader would become lost. Each room has at least two doors.
</p>
<p>
The Ninja House can be modeled by a graph, as shown in Figure l. A circle represents a room. Each line connecting two circles represents a door between two rooms.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ninjahouse">
<table>
<tr>
<td align="center" width="300">
Figure l. Graph Model of Ninja House.
</td>
<td align="center" width="300">
Figure 2. Ninja House exploration.
</td>
</tr>
</table>
</center>
<p>
I decided to draw a map, since no map was available. Your mission is to help me draw a map from the record of my exploration.
</p>
<p>
I started exploring by entering a single entrance that was open to the outside. The path I walked is schematically shown in Figure 2, by a line with arrows. The rules for moving between rooms are described below.
</p>
<p>
After entering a room, I first open the rightmost door and move to the next room. However, if the next room has already been visited, I close the door without entering, and open the next rightmost door, and so on. When I have inspected all the doors of a room, I go back through the door I used to enter the room.
</p>
<p>
I have a counter with me to memorize the distance from the first room. The counter is incremented when I enter a new room, and decremented when I go back from a room. In Figure 2, each number in parentheses is the value of the counter when I have entered the room, i.e., the distance from the first room. In contrast, the numbers not in parentheses represent the order of my visit.
</p>
<p>
I take a record of my exploration. Every time I open a door, I record a single number, according to the following rules.
</p>
<ol>
<li> If the opposite side of the door is a new room, I record the number of doors in that room, which is a positive number.</li>
<li> If it is an already visited room, say R, I record ``<i>the distance of R from the first room</i>'' minus ``<i>the distance of the current room from the first room</i>'', which is a negative number.</li>
</ol>
<p>
In the example shown in Figure 2, as the first room has three doors connecting other rooms, I initially record ``3''. Then when I move to the second, third, and fourth rooms, which all have three doors, I append ``3 3 3'' to the record. When I skip the entry from the fourth room to the first room, the distance difference ``-3'' (minus three) will be appended, and so on. So, when I finish this exploration, its record is a sequence of numbers ``3 3 3 3 -3 3 2 -5 3 2 -5 -3''.
</p>
<p>
There are several dozens of Ninja Houses in the city. Given a sequence of numbers for each of these houses, you should produce a graph for each house.
</p>
<H2>Input</H2>
<p>
The first line of the input is a single integer <i>n</i>, indicating the number of records of Ninja Houses I have visited. You can assume that <i>n</i> is less than 100. Each of the following <i>n</i> records consists of numbers recorded on one exploration and a zero as a terminator. Each record consists of one or more lines whose lengths are less than 1000 characters. Each number is delimited by a space or a newline. You can assume that the number of rooms for each Ninja House is less than 100, and the number of doors in each room is less than 40.
</p>
<H2>Output</H2>
<p>
For each Ninja House of <i>m</i> rooms, the output should consist of <i>m</i> lines. The <i>j</i>-th line of each such <i>m</i> lines should look as follows:
</p>
<pre>
<i>i</i> <i>r</i><sub>1</sub> <i>r</i><sub>2</sub> ... <i>r</i><sub><i>k</i><sub><i>i</i></sub></sub>
</pre
<p>
where <i>r</i><sub>1</sub>, ... , <i>r<sub>k<sub>i</sub></sub></i> should be rooms adjoining room <i>i</i>, and <i>k<sub>i</sub></i> should be the number of doors in room <i>i</i>. Numbers should be separated by exactly one space character. The rooms should be numbered from 1 in visited order. <i>r</i><sub>1</sub>, <i>r</i><sub>2</sub>, ... , <i>r<sub>k<sub>i</sub></sub></i> should be in ascending order. Note that the room <i>i</i> may be connected to another room through more than one door. In this case, that room number should appear in <i>r</i><sub>1</sub>, ... , <i>r<sub>k<sub>i</sub></sub></i> as many times as it is connected by different doors.
</p>
<H2>Sample Input</H2>
<pre>
2
3 3 3 3 -3 3 2 -5 3 2 -5 -3 0
3 5 4 -2 4 -3 -2 -2 -1 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 2 4 6
2 1 3 8
3 2 4 7
4 1 3 5
5 4 6 7
6 1 5
7 3 5 8
8 2 7
1 2 3 4
2 1 3 3 4 4
3 1 2 2 4
4 1 2 2 3
</pre>
|
p01707 |
<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>
<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
color: #333333;
display: block;
padding: 8.5px;
margin: 0 0 9px;
font-size: 12px;
line-height: 18px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}</style><div class="part"><h3>Problem Statement</h3><p>One day, my grandmas left $N$ cookies.
My elder sister and I were going to eat them immediately, but there was the instruction.
It said
</p><ul><li> Cookies will go bad; you should eat all of them within $D$ days.
</li><li> Be careful about overeating; you should eat strictly less than $X$ cookies in a day.
</li></ul>
<p>My sister said "<samp>How many ways are there to eat all of the cookies? Let's try counting!</samp>"
</p>
<p>Two ways are considered different if there exists a day such that the numbers of the cookies eaten on that day are different in the two ways.
For example, if $N$, $D$ and $X$ are $5$, $2$ and $5$ respectively, the number of the ways is $4$:
</p><ul><li> Eating $1$ cookie on the first day and $4$ cookies on the second day.
</li><li> Eating $2$ cookies on the first day and $3$ cookies on the second day.
</li><li> Eating $3$ cookies on the first day and $2$ cookies on the second day.
</li><li> Eating $4$ cookies on the first day and $1$ cookie on the second day.
</li></ul>
<p>I noticed the number of the ways would be very huge and my sister would die before counting it.
Therefore, I tried to count it by a computer program to save the life of my sister.
</p>
</div><div class="part"><h3>Input</h3>
<p>The input consists of multiple datasets.
The number of datasets is no more than $100$.
For each dataset, three numbers $N$ ($1 \le N \le 2{,}000$), $D$ ($1 \le D \le 10^{12}$) and $X$ ($1 \le X \le 2{,}000$) are written in a line and separated by a space.
The end of input is denoted by a line that contains three zeros.
</p>
</div><div class="part"><h3>Output</h3>
<p>Print the number of the ways modulo $1{,}000{,}000{,}007$ in a line for each dataset.
</p>
</div><div class="part"><h3>Sample Input</h3>
<pre>5 2 5
3 3 3
5 4 5
4 1 2
1 5 1
1250 50 50
0 0 0</pre>
</div><div class="part"><h3>Output for the Sample Input</h3>
<pre>4
7
52
0
0
563144298</pre>
</div> |
p02982 | <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> points in a <var>D</var>-dimensional space.</p>
<p>The coordinates of the <var>i</var>-th point are <var>(X_{i1}, X_{i2}, ..., X_{iD})</var>.</p>
<p>The distance between two points with coordinates <var>(y_1, y_2, ..., y_D)</var> and <var>(z_1, z_2, ..., z_D)</var> is <var>\sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}</var>.</p>
<p>How many pairs <var>(i, j)</var> <var>(i < j)</var> are there such that the distance between the <var>i</var>-th point and the <var>j</var>-th point is an integer?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 \leq N \leq 10</var></li>
<li><var>1 \leq D \leq 10</var></li>
<li><var>-20 \leq X_{ij} \leq 20</var></li>
<li>No two given points have the same coordinates. That is, if <var>i \neq j</var>, there exists <var>k</var> such that <var>X_{ik} \neq X_{jk}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>D</var>
<var>X_{11}</var> <var>X_{12}</var> <var>...</var> <var>X_{1D}</var>
<var>X_{21}</var> <var>X_{22}</var> <var>...</var> <var>X_{2D}</var>
<var>\vdots</var>
<var>X_{N1}</var> <var>X_{N2}</var> <var>...</var> <var>X_{ND}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of pairs <var>(i, j)</var> <var>(i < j)</var> such that the distance between the <var>i</var>-th point and the <var>j</var>-th point is an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 2
5 5
-2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The number of pairs with an integer distance is one, as follows:</p>
<ul>
<li>The distance between the first point and the second point is <var>\sqrt{|1-5|^2 + |2-5|^2} = 5</var>, which is an integer.</li>
<li>The distance between the second point and the third point is <var>\sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58}</var>, which is not an integer.</li>
<li>The distance between the third point and the first point is <var>\sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5}</var>, which is not an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 1
1
2
3
4
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10
</pre></section>
</div>
</span> |
p03690 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a sequence of length <var>N</var>: <var>a = (a_1, a_2, ..., a_N)</var>.
Here, each <var>a_i</var> is a non-negative integer.</p>
<p>Snuke can repeatedly perform the following operation:</p>
<ul>
<li>Let the XOR of all the elements in <var>a</var> be <var>x</var>. Select an integer <var>i</var> (<var>1 ≤ i ≤ N</var>) and replace <var>a_i</var> with <var>x</var>.</li>
</ul>
<p>Snuke's objective is to match <var>a</var> with another sequence <var>b = (b_1, b_2, ..., b_N)</var>.
Here, each <var>b_i</var> is a non-negative integer.</p>
<p>Determine whether the objective is achievable, and find the minimum necessary number of operations if the answer is positive.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ N ≤ 10^5</var></li>
<li><var>a_i</var> and <var>b_i</var> are integers.</li>
<li><var>0 ≤ a_i, b_i < 2^{30}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
<var>b_1</var> <var>b_2</var> <var>...</var> <var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the objective is achievable, print the minimum necessary number of operations.
Otherwise, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 1 2
3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>At first, the XOR of all the elements of <var>a</var> is <var>3</var>.
If we replace <var>a_1</var> with <var>3</var>, <var>a</var> becomes <var>(3, 1, 2)</var>.</p>
<p>Now, the XOR of all the elements of <var>a</var> is <var>0</var>.
If we replace <var>a_3</var> with <var>0</var>, <var>a</var> becomes <var>(3, 1, 0)</var>, which matches <var>b</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 1 2
0 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 1
0 0
</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>4
0 1 2 3
1 0 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre></section>
</div>
</span> |
p01357 |
<H1>Problem I: Lapin Noir</H1>
<p>
ここは, 地面が正六角形を敷き詰めたマス目になっている街である. 各マスは, 下の図のように2 つの整数で表される.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_lapin1">
</center>
<p>
ねこは(0, 0) のマスへ行こうとしている. いたずら好きの黒うさぎはこのことを知って, ねこの邪魔をしようと考えた.
</p>
<p>
黒うさぎはねこがいるマスへ跳び, その周りの6 マスのうち1 つまたは隣り合う2 つをブロックすることができる. ねこは周りの6 マスのうち, ブロックされていないマスを1 つ選んで進む. ねこが動くたび黒うさぎはねこを追いかけ, またブロックを行うことができる. 黒うさぎが動くと元のブロックは解除される. 下の図はブロックの様子を示している.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_lapin2">
</center>
<p>
この街にはねこの縄張りとなっているマス目がいくつかある. 縄張りは正六角形の周をなすマス目の集合<i>n</i>個の合併として表される. 黒うさぎはねこの縄張りに立ち入ることはできるが, ブロックすることはできない.つまり, ねこは縄張り内であれば自由に動ける.
</p>
<p>
ねこの出発点の候補が<i>k</i> 個あり, マス(<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) (1 ≤ <i>i</i> ≤ <i>k</i>) である. それぞれについて, ねこが必ず目的地(0, 0) に辿り着けるか, あるいは黒うさぎがうまく妨害することによってねこが目的地に辿り着けないかを判定せよ.
</p>
<H2>Input</H2>
<p>
1 行目:1 ≤ <i>n</i> ≤ 40 000 <br>
2 ∼ (<i>n</i> + 1) 行目: ねこの縄張りを表す正六角形の頂点<br>
(<i>n</i> + 2) 行目: 1 ≤ <i>k</i> ≤ 40 000<br>
(<i>n</i> + 3) ∼ (<i>n</i> + <i>k</i> + 2) 行目: ねこの出発点<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>
</p>
<p>
−1 000 000 000 ≤ (各座標) ≤ 1 000 000 000
</p>
<p>
ねこの縄張りを表す正六角形は, 6 頂点の位置が反時計回りに与えられる.
</p>
<H2>Output</H2>
<p>
出発地の候補それぞれについて, ねこが必ず目的地(0,0) に辿り着けるなら”YES”を, あるいは黒うさぎがうまく妨害した場合ねこが目的地に辿り着けないなら”NO”を, 一行ずつ出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
2
1 -1 3 -1 3 1 1 3 -1 3 -1 1
3 0 4 0 4 1 3 2 2 2 2 1
3
1 1
-1 -1
2 4
</pre>
<H2>Sample Output 1</H2>
<pre>
YES
NO
YES
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_lapin3">
</center> |
p00116 |
<H1>長方形探索</H1>
<p>
縦に <var>H</var> 行、横に <var>W</var> 列並べられた、合計 <var>W × H</var> のマス目があります。いくつかのマス目には印がついています。各マス目の印の状態を読み込み、印のついていないマス目だけからなる最大の長方形の面積を出力するプログラムを作成してください。
</p>
<p>
入力データは 1 行 <var>W</var> 文字から構成され、<var>H</var> 行が与えられます。たとえば以下のようなデータが与えられます。
</p>
<pre>
..*....**.
..........
**....***.
....*.....
..*.......
...**.....
.*.*......
..........
..**......
.*..*.....
</pre>
<p>
入力データの一行が、一行のマス目を表現します。入力データの文字列のうち、. (ピリオド) は印のついていないマス目、* (アスタリスク) は印のついているマス目を示しています。入力データの文字列には、ピリオド、アスタリスク、改行以外の文字は含まれません。
</p>
<p>
上記の例では、下図の 0 で示される長方形が最大となります。
</p>
<pre>
..*....**.
..........
**....***.
....*00000
..*..00000
...**00000
.*.*.00000
.....00000
..**.00000
.*..*00000
</pre>
<p>
よって、35 と出力すれば正解になります。なお、すべてのマス目に印がついている場合には、0 を出力してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。各データセットはスペースで区切られた <var>H</var> と <var>W</var> からなる行から始まり、つづいて <var>H × W</var> の長方形が与えられます。<var>H, W</var> はともに 500 以下とします。
</p>
<p>
入力は2つの 0 を含む行で終わります。データセットの数は 20 を超えません。
</p>
<H2>Output</H2>
<p>
各データセットごとに、最大の長方形の面積を1行に出力してください。
</p>
<H2>Sample Input</H2>
<pre>
10 10
...*....**
..........
**....**..
........*.
..*.......
**........
.*........
..........
....*..***
.*....*...
10 10
..*....*..
.*.*...*..
*****..*..
*...*..*..
*...*..*..
..........
****.*...*
..*..*...*
.*...*...*
****..***.
2 3
...
...
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
28
12
6
</pre>
|
p02081 | <h1>D: Nose And Lung</h1>
<h2>問題文</h2>
<p>あなたは謎の敵対的なエイリアンについて研究しています。</p>
<p>エイリアンには鼻の穴が $N$ 個あり、肺が $1$ 個以上あります。
しかし、肺がいくつあるか、および、どの鼻の穴とどの肺が繋がっているかが分かっていません。</p>
<p>あなたはエイリアンに関して、以下の仮説を立てました:</p>
<ul>
<li>それぞれの肺は $1$ 個以上の鼻の穴につながっている</li>
<li>それぞれ鼻の穴は $0$ 個以上の肺につながっている</li>
<li>全ての肺に対して酸素が供給されないと死んでしまう。すなわち、ある肺につながっている全ての鼻の穴を塞がれると、エイリアンは死ぬ</li>
</ul>
<p>政府はあなたの仮説を検証するために、肺と鼻の穴の接続関係がわかっていないエイリアンを $1$ 匹捕獲し、$2^N$ 匹に複製しました。これらのエイリアンで以下のような実験を行いました:</p>
<ul>
<li>$i$ 番目 $(i=0, \ldots, 2^N-1)$ のエイリアンに対しては、 $i$ を二進表記した際の $k$ 桁目が $1$ であるような $k$ 番目の鼻の穴を全て塞ぐ ($k = 0, \ldots, N-1$)。</li>
<li>その結果、エイリアンが生きたままか死んだかを記録する。 </li>
</ul>
<p>あなたはこれらの $2^N$ 個の実験の結果を全て与えられました。
実験の結果が仮説に矛盾していないか判定し、矛盾していない場合には
考えられる肺の最小個数を答えてください。</p>
<h2>制約</h2>
<ul>
<li>全ての入力は整数である</li>
<li>$2 \leq N \leq 20$</li>
<li>$0 \leq a_i \leq 1$</li>
<li>$a_0 = 0$</li>
<li>$a_{2^N-1} = 1$</li>
</ul>
<h2>入力</h2>
<p>入力は標準入力から以下の形式で与えられます。
ただし、$a_i=1$のとき、$i$番目のエイリアンは死亡し、$a_i=0$のとき、$i$番目のエイリアンは生きていることを表します。</p>
<pre>$N$
$a_0$
$:$
$a_{2^N-1}$</pre>
<h2>出力</h2>
<p>実験の結果が仮説に矛盾している場合には $-1$、そうでない場合はエイリアンが持つと考えられる肺の最小個数を答えてください。</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>2
0
1
0
1
</pre>
<h3>出力例1</h3>
<pre>1
</pre>
<p>考えられる肺のつなげ方としては{{1},{1,2}}や{{1}}があり、最小の個数は1個です。</p>
<h3>入力例2</h3>
<pre>3
0
1
1
1
1
0
0
1
</pre>
<h3>出力例2</h3>
<pre>-1
</pre>
<p>2番目の鼻の穴だけを塞いでも3番目の鼻の穴だけを塞いでも死ぬが、両方の穴を塞いだエイリアンは生きているため、仮説に矛盾しています。</p>
|
p00546 |
<h1>ゾンビ島 (Zombie Island)</h1>
<h2> 問題</h2>
<p>
JOI 君が住んでいる島がゾンビに侵略されてしまった.JOI 君は島で一番安全な避難場所として設定されているシェルターに逃げ込むことにした.
</p>
<p>
JOI 君が住んでいる島は町 1 から町 N までの N 個の町からなり,町と町とは道路で結ばれている.島には M 本の道路があり,すべての道路は異なる 2 つの町を結んでいる.JOI 君は道路を双方向に自由に移動できるが,道路以外を通って町から別の町に行くことはできない.
</p>
<p>
いくつかの町はゾンビに支配されており,訪れることが出来ない.ゾンビに支配されている町から S 本以下の道路を使って到達できる町を<b>危険な町</b>という.それ以外の町を<b>危険でない町</b>という.
</p>
<p>
JOI 君の家は町 1 にあり,避難先のシェルターは町 N にある.町 1,町 N はゾンビに支配されていない.島の道路は移動するのに時間がかかるので,JOI 君は町を移動するたびに,移動先の町で一晩宿泊しなければならない.JOI 君は,危険でない町で宿泊する場合は宿泊費が P 円の安い宿に泊まるが,危険な町で宿泊する場合はセキュリティのサービスが優良な宿泊費が Q 円の高級宿に泊まる.JOI 君はできるだけ宿泊費が安くなるように移動して,町 N まで避難したい.町 1 や町 N では宿泊する必要はない.
</p>
<p>
JOI 君が 町 1 から町 N まで移動するときに必要な宿泊費の合計の最小値を求めよ.
</p>
<h2> 入力</h2>
<p>
入力は 2 + K + M 行からなる.
</p>
<p>
1 行目には,4 つの整数 N, M, K, S (2 ≦ N ≦ 100000, 1 ≦ M ≦ 200000, 0 ≦ K ≦ N - 2, 0 ≦ S ≦ 100000) が空白を区切りとして書かれている.これは,島が N 個の町と M 本の道路からなり,N 個の町のうち K 個の町がゾンビに支配されており,ゾンビに支配されている町から S 本以下の道路を使って到達できる町を危険な町と呼ぶことを表す.
</p>
<p>
2 行目には,2 つの整数 P, Q (1 ≦ P < Q ≦ 100000) が空白を区切りとして書かれている.これは,JOI 君が危険でない町では宿泊費が P 円の宿に泊まり,危険な町では宿泊費が Q 円の宿に泊まることを表す.
</p>
<p>
続く K 行のうちの i 行目 (1 ≦ i ≦ K) には,整数 C<sub>i</sub> (2 ≦ C<sub>i</sub> ≦ N - 1) が書かれている.これは,町 C<sub>i</sub> がゾンビに支配されていることを表す.C<sub>1</sub>, ..., C<sub>K</sub> は全て異なる.
</p>
<p>
続く M 行のうちの j 行目 (1 ≦ j ≦ M) には,2 つの整数 A<sub>j</sub>, B<sub>j</sub> (1 ≦ A<sub>j</sub> < B<sub>j</sub> ≦ N) が空白を区切りとして書かれている.これは,町 A<sub>j</sub> と町 B<sub>j</sub> との間に道路が存在することを表す.同じ (A<sub>j</sub>, B<sub>j</sub>) の組が 2 回以上書かれていることはない.
</p>
<p>
与えられる入力データにおいては,町 1 から町 N までゾンビに支配されていない町のみを通って移動できることが保証されている.
</p>
<h2> 出力</h2>
<p>
JOI 君が町 1 から町 N まで移動するときに必要な宿泊費の合計の最小値を 1 行で出力せよ.
</p>
<p>
出力が 32 ビット符号付き整数の範囲に収まるとは限らないことに注意せよ.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
13 21 1 1
1000 6000
7
1 2
3 7
2 4
5 8
8 9
2 5
3 4
4 7
9 10
10 11
5 9
7 12
3 6
4 5
1 3
11 12
6 7
8 11
6 13
7 8
12 13
</pre>
<h3>出力例 1</h3>
<pre>
11000
</pre>
<h3>入力例 2</h3>
<pre>
21 26 2 2
1000 2000
5
16
1 2
1 3
1 10
2 5
3 4
4 6
5 8
6 7
7 9
8 10
9 10
9 11
11 13
12 13
12 15
13 14
13 16
14 17
15 16
15 18
16 17
16 19
17 20
18 19
19 20
19 21
</pre>
<h3>出力例 2</h3>
<pre>
15000
</pre>
<p>
入出力例 1 は,以下の図に対応している.円は町を,線は道路を表す.
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_2016-yo-t5-fig01" alt="sample1" width="350" height="350"></a>
</p>
<p>
この場合,町 3,町 4,町 6,町 8,町 12 が危険な町である.
</p>
<p>
以下のような順番で町を移動すると,宿泊費の合計を最小にできる.
</p>
<ul>
<li>町 1 から町 2 に行く.町 2 で宿泊費が 1000 円の安い宿に宿泊する.</li>
<li>町 2 から町 5 に行く.町 5 で宿泊費が 1000 円の安い宿に宿泊する.</li>
<li>町 5 から町 9 に行く.町 9 で宿泊費が 1000 円の安い宿に宿泊する.</li>
<li>町 9 から町 10 に行く.町 10 で宿泊費が 1000 円の安い宿に宿泊する.</li>
<li>町 10 から町 11 に行く.町 11 で宿泊費が 1000 円の安い宿に宿泊する.</li>
<li>町 11 から町 12 に行く.町 12 で宿泊費が 6000 円の高級宿に宿泊する.</li>
<li>町 12 から町 13 に行く.町 13 では宿泊しない.</li>
</ul>
<p>
JOI 君がこのような経路で移動したとき,宿泊費の合計は 11000 円になるので,11000 を出力する.
</p>
<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/2015/2016-yo/index.html">情報オリンピック日本委員会作 『第 15 回日本情報オリンピック JOI 2015/2016 予選競技課題』</a>
</p>
</div>
|
p00268 |
<H1>ねこまっしぐら2 </H1>
<p>
あるところに大きな古いお屋敷があり、1匹のねこが住み着いていました。図のように、お屋敷は上空から見ると凸多角形になっており、まっすぐな壁で囲まれたいくつかの部屋で造られています。1枚の壁はその両端にある柱によって支えられています。お屋敷はとても古いため、どの壁にもねこが通ることができるくらいの穴が1つ空いています。ねこは壁の穴を通ってお屋敷の部屋と部屋または部屋と外を行き来することができます。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_catsGoingStraightII" width="300">
</center><br/>
<p>
お屋敷のご主人は、ねこに餌をあげるために、口笛を吹いてねこをお屋敷の外へ呼び出します。ねこはとても賢く、ご主人が口笛を吹くと、「最良の選択」でお屋敷の外へ抜け出します。つまり、最も少ない回数だけ穴を通って外へ出ます。
</p>
<p>
ねこはとても気まぐれで、どの部屋にいるか分かりません。そのため、ねこがお屋敷の外へ出るのにかかる時間は日によって異なり、ご主人はどれだけ待てばよいかわからず困っていました。ある時ご主人は、ねこが穴を通り抜けるときに、とても時間がかかっていることに気が付きました。ということは、ねこが外に出るのにかかる時間は穴を通る回数によって決まることになります。ご主人は、ねこが「最良の選択」をした場合の穴を通る回数の最大値が分かれば、ねこがどの部屋にいたとしても、最大どれだけ待てばよいか分かるのではないかと考えました。ご主人はお屋敷の間取りを知っていますが、お屋敷はとても大きく、自分では計算することができません...。
</p>
<p>
お屋敷の間取りを読み込み、ねこが「最良の選択」をした場合、外に出るまでに通る穴の数の最大値を
出力するプログラムを作成して下さい。
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる。入力の終わりはゼロ2つの行で示される。各データセットは以下の形式で与えられる。
</p>
<pre>
C W
x<sub>1</sub> y<sub>1</sub>
x<sub>2</sub> y<sub>2</sub>
:
x<sub>C</sub> y<sub>C</sub>
s<sub>1</sub> t<sub>1</sub>
s<sub>2</sub> t<sub>2</sub>
:
s<sub>W</sub> t<sub>W</sub>
</pre>
<p>
各行で与えられる数値は1つの空白で区切られている。
</p>
<p>
1行目に柱の数 C (3 ≤ C ≤ 100) と壁の数 W (3 ≤ W ≤ 300) が与えられる。続く C 行に柱の座標が与えられる。x<sub>i</sub> (-1000 ≤ x<sub>i</sub> ≤ 1000) は i 番目の柱の x 座標、y<sub>i</sub> (-1000 ≤ y<sub>i</sub> ≤ 1000) は i 番目の柱の y 座標をそれぞれ示す整数である。柱にはそれぞれ 1 から C までの番号が割り当てられている。 続く W 行に壁の情報が与えられる。
</p>
<p>
s<sub>i</sub> (1 ≤ s<sub>i</sub> ≤ C)、t<sub>i</sub> (1 ≤ t<sub>i</sub> ≤ C) は壁の両端を支える柱の番号を示す。
</p>
<p>
入力は以下の条件を満たすと考えてよい。
</p>
<ul>
<li> 異なる柱が同じ位置を占めることはない。</li>
<li> 異なる壁が重なったり、柱以外で交差することはない。</li>
<li> 1つの柱は2つ以上の壁を支えている。</li>
<li> 壁の長さは 0 より大きい。</li>
<li> 柱は壁の両端だけにある。つまり、柱が壁の途中にあることはない。</li>
<li> 壁は異なる2つの部屋、あるいは部屋と外とを仕切る。</li>
<li> 任意の異なる2つの柱を選んだとき、互いの柱には壁をたどって到達できる。</li>
</ul>
<p>
データセットの数は 50 を超えない。
</p>
<h2>出力</h2>
<p>
データセットごとに、ねこが「最良の選択」をした場合、外に出るまでに通る穴の数の最大値を1行に出力する。
</p>
<h2>入力例</h2>
<pre>
4 4
0 0
1 0
1 1
0 1
1 2
1 4
2 3
3 4
12 22
2 0
4 0
8 0
4 2
6 2
8 2
2 4
4 4
6 4
0 6
8 6
0 8
1 2
2 3
1 4
1 7
1 10
2 4
2 5
3 5
3 6
4 5
4 8
5 6
5 9
6 9
6 11
7 10
7 8
8 9
9 11
10 11
10 12
11 12
0 0
</pre>
<h2>出力例</h2>
<pre>
1
3
</pre>
<p>
2つ目のデータセットが、冒頭の図に示したお屋敷の間取りに対応する。図のように、薄く色が塗られた部屋にねこがいるときは、「最良の選択」で外に出るまでに通り抜ける穴の数は3つである。それ以外の部屋にねこがいるときは、2つ以下で外に出られる。したがって、ねこが「最良の選択」をしたとき、外に出るまでに通り抜ける穴の数の最大値は 3 になる。
</p> |
p02255 |
<H1>Insertion Sort</H1>
<p>
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
</p>
<pre>
for i = 1 to A.length-1
key = A[i]
/* insert A[i] into the sorted sequence A[0,...,j-1] */
j = i - 1
while j >= 0 and A[j] > key
A[j+1] = A[j]
j--
A[j+1] = key
</pre>
<p>
Note that, indices for array elements are based on 0-origin.
</p>
<p>
To illustrate the algorithms, your program should trace intermediate result for each step.
</p>
<H2>Input</H2>
<p>
The first line of the input includes an integer N, the number of elements in the sequence.
</p>
<p>
In the second line, <i>N</i> elements of the sequence are given separated by a single space.
</p>
<H2>Output</H2>
<p>
The output consists of <i>N</i> lines. Please output the intermediate sequence in a line for each step. Elements of the sequence should be separated by single space.
</p>
<H2>Constraints</H2>
<p>
1 ≤ <i>N</i> ≤ 100
</p>
<H2>Sample Input 1</H2>
<pre>
6
5 2 4 6 1 3
</pre>
<H2>Sample Output 1</H2>
<pre>
5 2 4 6 1 3
2 5 4 6 1 3
2 4 5 6 1 3
2 4 5 6 1 3
1 2 4 5 6 3
1 2 3 4 5 6
</pre>
<H2>Sample Input 2</H2>
<pre>
3
1 2 3
</pre>
<H2>Sample Output 2</H2>
<pre>
1 2 3
1 2 3
1 2 3
</pre>
<H2>Hint</H2>
<a href="template/ALDS1_1_A_template.c">Template in C</a>
|
p00792 |
<H1><font color="#000">Problem E:</font> Mirror Illusion</H1>
<p>
A rich man has a square room with mirrors for security or just for fun. Each side of the room is eight meters wide. The floor, the ceiling and the walls are not special; however, the room can be equipped with a lot of mirrors on the walls or as vertical partitions.
</p>
<p>
Every mirror is one meter wide, as tall as the wall, double-side, perfectly reflective, and ultimately thin.
</p>
<p>
Poles to fix mirrors are located at the corners of the room, on the walls and inside the room. Their locations are the 81 lattice points at intervals of one meter. A mirror can be fixed between two poles which are one meter distant from each other. If we use the sign "+" to represent a pole, the overview of the room can be illustrated as follows.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_mirror">
</center>
<p>
Let us denote a location on the floor by (<i>x</i>,<i>y</i>) in a rectangular coordinate system. For example, the rectangular coordinates of the four corners of the room are (0,0), (8,0), (0,8) and (8,8), respectively. The location (<i>x</i>,<i>y</i>) is in the room if and only if the conditions 0 ≤ <i>x</i> ≤ 8 and 0 ≤ <i>y</i> ≤ 8 are satisfied. If <i>i</i> and <i>j</i> are integers satisfying the conditions 0 ≤ <i>i</i> ≤ 8 and 0 ≤ <i>j</i> ≤ 8, we can denote by (<i>i</i>,<i>j</i>) the locations of poles.
</p>
<p>
One day a thief intruded into this room possibly by breaking the ceiling. He stood at (0.75,0.25) and looked almost toward the center of the room. Precisely speaking, he looked toward the point (1, 0.5) of the same height as his eyes. So what did he see in the center of his sight? He would have seen one of the walls or himself as follows.
</p>
<ul>
<li>If there existed no mirror, he saw the wall at (8, 7.5)</li>
<li>If there existed one mirror between two poles at (8, 7) and (8, 8), he saw the wall at (7.5, 8). (Let us denote the line between these two poles by (8, 7)-(8, 8).)</li>
<li>If there were four mirrors on (8, 7)-(8, 8), (7, 8)-(8, 8), (0, 0)-(0, 1) and (0, 0)-(1, 0), he saw himself at (0.75, 0.25).</li>
<li>If there were four mirrors on (2, 1)-(2, 2), (1, 2)-(2, 2), (0, 0)-(0, 1) and (0, 0)-(1, 0), he saw himself at (0.75, 0.25)</li>
</ul>
<p>
Your job is to write a program that reports the location at which the thief saw one of the walls or himself with the given mirror arrangements.
</p>
<H2>Input</H2>
<p>
The input contains multiple data sets, each representing how to equip the room with mirrors. A data set is given in the following format.
</p>
<pre>
<i>n</i>
<i>d</i><sub>1</sub> <i>i</i><sub>1</sub> <i>j</i><sub>1</sub>
<i>d</i><sub>2</sub> <i>i</i><sub>2</sub> <i>j</i><sub>2</sub>
. . .
<i>d</i><sub><i>n</i></sub> <i>i</i><sub><i>n</i></sub> <i>j</i><sub><i>n</i></sub>
</pre>
<p>
The first integer <i>n</i> is the number of mirrors, such that 0 ≤ <i>n</i> ≤ 144. The way the <i>k</i>-th (1 ≤ <i>k</i> ≤ <i>n</i>) mirror is fixed is given by <i>d<sub>k</sub></i> and (<i>i<sub>k</sub></i>,<i>j<sub>k</sub></i>). <i>d<sub>k</sub></i> is either 'x' or 'y', which gives the direction of the mirror. If <i>d<sub>k</sub></i> is 'x', the mirror is fixed on (<i>i<sub>k</sub></i>, <i>j<sub>k</sub></i>)-(<i>i<sub>k</sub></i> + 1, <i>j<sub>k</sub></i>). If <i>d<sub>k</sub></i> is 'y', the mirror is fixed on (<i>i<sub>k</sub></i>,<i>j<sub>k</sub></i>) (<i>i<sub>k</sub></i>,<i>j<sub>k</sub></i> + 1). The end of the input is indicated by a negative integer.
</p>
<H2>Output</H2>
<p>
For each data set, your program should output the location (<i>x</i>,<i>y</i>) at which the thief saw one of the walls or himself. The location should be reported in a line containing two integers which are separated by a single space and respectively represent <i>x</i> and <i>y</i> in centimeter as the unit of length. No extra lines nor spaces are allowed.
</p>
<H2>Sample Input</H2>
<pre>
0
1
y 8 7
4
y 8 7
x 7 8
y 0 0
x 0 0
4
y 2 1
x 1 2
y 0 0
x 0 0
-1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
800 750
750 800
75 25
75 25
</pre>
|
p01880 |
<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>Best Matched Pair</h2>
<p>
You are working for a worldwide game company as an engineer in Tokyo. This company holds an annual event for all the staff members of the company every summer. This year's event will take place in Tokyo. You will participate in the event on the side of the organizing staff. And you have been assigned to plan a recreation game which all the participants will play at the same time.
</p>
<p>
After you had thought out various ideas, you designed the rules of the game as below.
</p>
<ul>
<li> Each player is given a positive integer before the start of the game.</li>
<li> Each player attempts to make a pair with another player in this game, and formed pairs compete with each other by comparing the products of two integers.</li>
<li> Each player can change the partner any number of times before the end of the game, but cannot have two or more partners at the same time.</li>
<li> At the end of the game, the pair with the largest product wins the game.</li>
</ul>
<p>
In addition, regarding the given integers, the next condition must be satisfied for making a pair.
</p>
<ul>
<li> The sequence of digits obtained by considering the product of the two integers of a pair as a string must be increasing and consecutive from left to right. For example, 2, 23, and 56789 meet this condition, but 21, 334, 135 or 89012 do not.</li>
</ul>
<p>
Setting the rules as above, you noticed that multiple pairs may be the winners who have the same product depending on the situation. However, you can find out what is the largest product of two integers when a set of integers is given.
</p>
<p>
Your task is, given a set of distinct integers which will be assigned to the players, to compute the largest possible product of two integers, satisfying the rules of the game mentioned above.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case formatted as follows.<br/>
<br/>
$N$<br/>
$a_1$ $a_2$ ... $a_N$<br/>
</p>
<p>
The first line contains a positive integer $N$ which indicates the number of the players of the game. $N$ is an integer between 1 and 1,000. The second line has $N$ positive integers that indicate the numbers given to the players. For $i = 1, 2, ... , N - 1$, there is a space between $a_i$ and $a_{i+1}$. $a_i$ is between 1 and 10,000 for $i = 1, 2, ..., N$, and if $i \ne j$, then $a_i \ne a_j$.
</p>
<h3>Output</h3>
<p>
Print the largest possible product of the two integers satisfying the conditions for making a pair. If any two players cannot make a pair, print -1.
</p>
<h3>Sample Input 1</h3>
<pre>
2
1 2
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
2
</pre>
<h3>Sample Input 2</h3>
<pre>
3
3 22 115
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
345
</pre>
<h3>Sample Input 3</h3>
<pre>
2
1 11
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
-1
</pre>
<h3>Sample Input 4</h3>
<pre>
2
5 27
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
-1
</pre>
<h3>Sample Input 5</h3>
<pre>
2
17 53
</pre>
<h3>Output for the Sample Input 5</h3>
<pre>
-1
</pre>
<h3>Sample Input 6</h3>
<pre>
10
53 43 36 96 99 2 27 86 93 23
</pre>
<h3>Output for the Sample Input 6</h3>
<pre>
3456
</pre> |
p00638 |
<H1><font color="#000000">Problem B:</font> Old Bridges</H1>
<p>
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.
</p>
<p>
Finally he found <i>n</i> islands that had treasures and one island that had nothing. Most of islands had seashore and he can land only on an island which had nothing. He walked around the island and found that there was an old bridge between this island and each of all other <i>n</i> islands.
</p>
<p>
He tries to visit all islands one by one and pick all the treasures up. Since he is afraid to be stolen, he visits with bringing all treasures that he has picked up. He is a strong man and can bring all the treasures at a time, but the old bridges will break if he cross it with taking certain or more amount of treasures.
</p>
<p>
Please write a program that judges if he can collect all the treasures and can be back to the island where he land on by properly selecting an order of his visit.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets.
</p>
<p>
The first line of each dataset contains an integer <i>n</i>.
Next <i>n</i> lines represents information of the islands. Each line has two integers, which means the amount of treasures of the island and the maximal amount that he can take when he crosses the bridge to the islands, respectively.
</p>
<p>
The end of input is represented by a case with <i>n</i> = 0.
</p>
<H2>Output</H2>
<p>
For each dataset, if he can collect all the treasures and can be back, print "<span>Yes</span>" Otherwise print "<span>No</span>"
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 25</li>
</ul>
<H2>Sample Input</H2>
<pre>
3
2 3
3 6
1 2
3
2 3
3 5
1 2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Yes
No
</pre>
|
p02605 | <span class="lang-en">
<p>Score: <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>M-kun is a brilliant air traffic controller.</p>
<p>On the display of his radar, there are <var>N</var> airplanes numbered <var>1, 2, ..., N</var>, all flying at the same altitude.<br/>
Each of the airplanes flies at a constant speed of <var>0.1</var> per second in a constant direction. The current coordinates of the airplane numbered <var>i</var> are <var>(X_i, Y_i)</var>, and the direction of the airplane is as follows:</p>
<ul>
<li>if <var>U_i</var> is <code>U</code>, it flies in the positive <var>y</var> direction;</li>
<li>if <var>U_i</var> is <code>R</code>, it flies in the positive <var>x</var> direction;</li>
<li>if <var>U_i</var> is <code>D</code>, it flies in the negative <var>y</var> direction;</li>
<li>if <var>U_i</var> is <code>L</code>, it flies in the negative <var>x</var> direction.</li>
</ul>
<p>To help M-kun in his work, determine whether there is a pair of airplanes that will collide with each other if they keep flying as they are now.<br/>
If there is such a pair, find the number of seconds after which the first collision will happen.<br/>
We assume that the airplanes are negligibly small so that two airplanes only collide when they reach the same coordinates simultaneously.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 200000</var></li>
<li><var>0 \leq X_i, Y_i \leq 200000</var></li>
<li><var>U_i</var> is <code>U</code>, <code>R</code>, <code>D</code>, or <code>L</code>.</li>
<li>The current positions of the <var>N</var> airplanes, <var>(X_i, Y_i)</var>, are all distinct.</li>
<li><var>N</var>, <var>X_i</var>, and <var>Y_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>X_1</var> <var>Y_1</var> <var>U_1</var>
<var>X_2</var> <var>Y_2</var> <var>U_2</var>
<var>X_3</var> <var>Y_3</var> <var>U_3</var>
<var>:</var>
<var>X_N</var> <var>Y_N</var> <var>U_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If there is a pair of airplanes that will collide with each other if they keep flying as they are now, print an integer representing the number of seconds after which the first collision will happen.<br/>
If there is no such pair, print <code>SAFE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
11 1 U
11 47 D
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>230
</pre>
<p>If the airplanes keep flying as they are now, two airplanes numbered <var>1</var> and <var>2</var> will reach the coordinates <var>(11, 24)</var> simultaneously and collide. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
20 30 U
30 20 R
20 10 D
10 20 L
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>SAFE
</pre>
<p>No pair of airplanes will collide.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
168 224 U
130 175 R
111 198 D
121 188 L
201 116 U
112 121 R
145 239 D
185 107 L
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100
</pre></section>
</div>
</span> |
p03917 | <span class="lang-en">
<p>Score : <var>1900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a grid with <var>H</var> rows and <var>W</var> columns. The square at the <var>i</var>-th row and <var>j</var>-th column contains a character <var>S_{i,j}</var>.</p>
<p>He can perform the following two kinds of operation on the grid:</p>
<ul>
<li>Row-reverse: Reverse the order of the squares in a selected row.</li>
<li>Column-reverse: Reverse the order of the squares in a selected column.</li>
</ul>
<p>For example, reversing the <var>2</var>-nd row followed by reversing the <var>4</var>-th column will result as follows:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/31458935865e5db21bfbcd2eab9511da.png"/></p>
<p>By performing these operations any number of times in any order, how many placements of characters on the grid can be obtained?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦H,W≦200</var></li>
<li><var>S_{i,j}</var> is a lowercase English letter (<code>a</code>-<code>z</code>).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>S_{1,1}</var><var>S_{1,2}</var><var>...</var><var>S_{1,W}</var>
<var>S_{2,1}</var><var>S_{2,2}</var><var>...</var><var>S_{2,W}</var>
<var>:</var>
<var>S_{H,1}</var><var>S_{H,2}</var><var>...</var><var>S_{H,W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of placements of characters on the grid that can be obtained, modulo <var>1000000007 (=10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
cf
cf
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The following <var>6</var> placements of characters can be obtained:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/ddf2925467af2c9734194a886f819a2b.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 12
codefestival
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre></section>
</div>
</span> |
p03444 | <span class="lang-en">
<p>Score : <var>2000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a rooted tree with <var>N</var> vertices.
The vertices are numbered <var>0, 1, ..., N-1</var>.
The root is Vertex <var>0</var>, and the parent of Vertex <var>i</var> <var>(i = 1, 2, ..., N-1)</var> is Vertex <var>p_i</var>.</p>
<p>Initially, an integer <var>a_i</var> is written in Vertex <var>i</var>.
Here, <var>(a_0, a_1, ..., a_{N-1})</var> is a permutation of <var>(0, 1, ..., N-1)</var>.</p>
<p>You can execute the following operation at most <var>25</var> <var>000</var> times. Do it so that the value written in Vertex <var>i</var> becomes <var>i</var>.</p>
<ul>
<li>Choose a vertex and call it <var>v</var>. Consider the path connecting Vertex <var>0</var> and <var>v</var>.</li>
<li>Rotate the values written on the path. That is, For each edge <var>(i, p_i)</var> along the path, replace the value written in Vertex <var>p_i</var> with the value written in Vertex <var>i</var> (just before this operation), and replace the value of <var>v</var> with the value written in Vertex <var>0</var> (just before this operation).</li>
<li>You may choose Vertex <var>0</var>, in which case the operation does nothing.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2000</var></li>
<li><var>0 \leq p_i \leq i-1</var></li>
<li><var>(a_0, a_1, ..., a_{N-1})</var> is a permutation of <var>(0, 1, ..., N-1)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> ... <var>p_{N-1}</var>
<var>a_0</var> <var>a_1</var> ... <var>a_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>In the first line, print the number of operations, <var>Q</var>.
In the second through <var>(Q+1)</var>-th lines, print the chosen vertices in order.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
0 1 2 3
2 4 0 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
3
4
</pre>
<ul>
<li>After the first operation, the values written in Vertex <var>0, 1, .., 4</var> are <var>4, 0, 1, 2, 3</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 1 2 2
4 3 1 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
4
3
1
</pre>
<ul>
<li>After the first operation, the values written in Vertex <var>0, 1, .., 4</var> are <var>3, 1, 0, 2, 4</var>.</li>
<li>After the second operation, the values written in Vertex <var>0, 1, .., 4</var> are <var>1, 0, 2, 3, 4</var>.</li>
</ul></section>
</div>
</span> |
p01479 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<h1> Chicken or the Egg</h1>
<p>
Time Limit: 8 sec / Memory Limit: 64 MB
</p>
<h2> A: 卵が先か鶏が先か</h2>
<p>
2012/2/8 <br/>
卵が先か鶏が先かという問題はいまだかつて誰もわからなかった.
しかし今回の琵琶湖遺跡で発掘で獲得した文書にはその答えが記されているという.<br/>
</p>
<p>
2012/2/9 <br/>
文書はchickenとeggという単語のみで構成されていた.このままでは答えがわからない.
</p>
<p>
2012/2/10 <br/>
さらに文書を読み進めると,文書中の単語の順番は産まれた順番を表していることがわかった.
"eggchicken"とあった場合は,先に鶏が産まれ,その後に鶏が卵を産んだということを示している.
</p>
<p>
2012/2/11 <br/>
"eggchickenchickenegg"という文を見つけた.
この文では,先に卵が産まれ,その卵から鶏が産まれる.
さらに昨日のルールでいくと,この鶏が鶏を産むということになってしまう.
鶏は卵を産まなければならないのに,これはおかしい.
</p>
<p>
2012/2/12 <br/>
調査をする内に,文は同一単語が連続で出てきたときに分割されることがわかった.
"eggchickenchickenegg"であれば,"eggchicken"と"chickenegg"という文に分割される.
複数の文がある場合は,先頭の単語から順番に同じ時代に産まれたことを表すらしい.
さっきの例だと,"eggchicken"の一つ目の単語eggと,"chickenegg"の一つ目の単語chickenは,同じ時代に産まれたことを表すようだ.
さらに,これらを産んだchickenとeggも同じ時代に産まれたことを表す.
ん?これだと結局鶏か卵かどっちが先に産まれたかわからないじゃないか.
</p>
<p>
2012/2/13 <br/>
どうやら同じ時代として産まれたものの内,より文の前方に書かれた方が先に産まれたようだ.
昨日の例だと,chickenの方が文の前方にあるから,結局鶏が最初に産まれたことになるらしい.
解読のルールを理解することができた.これで安心だ.
いや,まだぼう大な量の文書を解読せねばならないのだ.早く解読を急がねば.
</p>
<p>
2012/3/15 <br/>
もう寿命が近いそうだ.手も足もロクに動かない.
この文書も結局時間が足りず解読できなかった.
この際誰でもいいから,去る前にどちらが先だったかを私に教えてくれないだろうか….
</p>
<p>
あなたは親族に依頼を受けてやってきた人です.
おじいさんの最後の願いを叶えるために解読してください.
</p>
<h2> Input</h2>
<p>
文字列 <i>s</i> が1行与えられる. 文字列 <i>s</i> はeggとchickenの二つの単語で構成されており,文字列内に含まれる単語数は1以上1000以下である.
</p>
<h2> Output</h2>
<p>
eggかchickenのいずれかを出力せよ.
</p>
<h2> Sample Input 1</h2>
<pre>
eggchickenegg
</pre>
<h2> Sample Output 1</h2>
<pre>
egg
</pre>
<h2> Sample Input 2</h2>
<pre>
chickeneggeggchicken
</pre>
<h2> Sample Output 2</h2>
<pre>
egg
</pre>
<h2> Sample Input 3</h2>
<pre>
eggeggchicken
</pre>
<h2> Sample Output 3</h2>
<pre>
chicken
</pre>
</body>
</html> |
p01183 |
<H1><font color="#000">Problem C:</font> Tetrahedra</H1>
<p>
Peter P. Pepper is facing a difficulty.
</p>
<p>
After fierce battles with the Principality of Croode, the Aaronbarc Kingdom, for which he serves, had
the last laugh in the end. Peter had done great service in the war, and the king decided to give him a
big reward. But alas, the mean king gave him a hard question to try his intelligence. Peter is given a
number of sticks, and he is requested to form a tetrahedral vessel with these sticks. Then he will be, said
the king, given as much patas (currency in this kingdom) as the volume of the vessel. In the situation,
he has only to form a frame of a vessel.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tetrahedra">
<p>Figure 1: An example tetrahedron vessel</p>
</center>
<p>
The king posed two rules to him in forming a vessel: (1) he need not use all of the given sticks, and (2)
he must not glue two or more sticks together in order to make a longer stick.
</p>
<p>
Needless to say, he wants to obtain as much patas as possible. Thus he wants to know the maximum
patas he can be given. So he called you, a friend of him, and asked to write a program to solve the
problem.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case is given in a line in the format below:
</p>
<pre>
<i>N a<sub>1</sub> a<sub>2</sub> . . . a<sub>N</sub></i>
</pre>
<p>
where <i>N</i> indicates the number of sticks Peter is given, and <i>a<sub>i</sub></i> indicates the length (in centimeters) of
each stick. You may assume 6 ≤ <i>N</i> ≤ 15 and 1 ≤ <i>a<sub>i</sub></i> ≤ 100.
</p>
<p>
The input terminates with the line containing a single zero.
</p>
<H2>Output</H2>
<p>
For each test case, print the maximum possible volume (in cubic centimeters) of a tetrahedral vessel
which can be formed with the given sticks. You may print an arbitrary number of digits after the decimal
point, provided that the printed value does not contain an error greater than 10<sup>-6</sup>.
</p>
<p>
It is guaranteed that for each test case, at least one tetrahedral vessel can be formed.
</p>
<H2>Sample Input</H2>
<pre>
7 1 2 2 2 2 2 2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.942809
</pre>
|
p03014 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns, and there are obstacles on some of the squares.</p>
<p>Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.</p>
<p>Snuke wants to maximize the number of squares lighted by the lamp.</p>
<p>You are given <var>H</var> strings <var>S_i</var> (<var>1 \leq i \leq H</var>), each of length <var>W</var>. If the <var>j</var>-th character (<var>1 \leq j \leq W</var>) of <var>S_i</var> is <code>#</code>, there is an obstacle on the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left; if that character is <code>.</code>, there is no obstacle on that square.</p>
<p>Find the maximum possible number of squares lighted by the lamp.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H \leq 2,000</var></li>
<li><var>1 \leq W \leq 2,000</var></li>
<li><var>S_i</var> is a string of length <var>W</var> consisting of <code>#</code> and <code>.</code>.</li>
<li><code>.</code> occurs at least once in one of the strings <var>S_i</var> (<var>1 \leq i \leq H</var>).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>S_1</var>
<var>:</var>
<var>S_H</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of squares lighted by the lamp.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 6
#..#..
.....#
....#.
#.#...
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>13
</pre></section>
</div>
</span> |
p01029 |
<h1>Problem B: Yu-kun Likes Letters in the English Alphabet</h1>
<h2>Background</h2>
<p>
会津大学付属幼稚園はプログラミングが大好きな子供が集まる幼稚園である。園児の一人であるゆう君は、プログラミングと同じくらい英小文字が大好きだ。
そんなゆう君は紙と丸と線、そして英小文字を使う新しい遊びを考え、その採点用プログラムを書くことにした。
</p>
<h2>Problem</h2>
<p>初期状態として、紙に <var>V</var> 個の丸と <var>E</var> 本の線が書かれている。丸には0から昇順に番号がつけられており、各丸の中には英小文字が1つ書かれているか、何も書かれていない。 各線は異なる2つの丸を結んでいる。1つの丸が26本以上の線で結ばれることはない。
</p>
<p>遊びの手順は以下の通りである。</p>
<ol>
<li>何も書かれていない丸を1つ選ぶ。 そのような丸が存在しない場合はこの処理を終了する。</li>
<li>丸の中に英小文字を1つ書く。 ただし丸が既に英小文字の書かれている丸と線で結ばれている場合、その英小文字と同じ英小文字は書くことはできない。</li>
<li>1. に戻る。</li>
</ol>
<p>
上記の手順に従って全ての丸に英小文字を書いた後、丸の番号が小さい順に丸の中の英小文字を並べ文字列を作る。
こうしてできる文字列を辞書順で最小となるようにしたい。
2つの同じ長さの文字列 <var>s</var>, <var>t</var> があり、 <var>s</var> が <var>t</var> より辞書順で小さいとは次のような場合を言う。
<var>s<sub>i</sub></var> は文字列 <var>s</var> の <var>i</var> 番目の英小文字を、 <var>t<sub>i</sub></var> は文字列 <var>t</var> の <var>i</var> 番目の英小文字を表す。
<var>s<sub>i</sub></var> が <var>t<sub>i</sub></var> と異なるような最小の <var>i</var> について、 <var>s<sub>i</sub></var> が <var>t<sub>i</sub></var> より小さい。
</p>
<p>
紙の初期状態が与えられるので、そこから上記の手順にしたがって作成できる文字列のうち辞書順最小のものを出力せよ。
</p>
<h2>Input</h2>
<pre>
<var>V</var> <var>E</var>
<var>a<sub>0</sub></var> <var>a<sub>1</sub></var> ... <var>a<sub>(V-1)</sub></var>
<var>s<sub>0</sub></var> <var>t<sub>0</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var>
...
<var>s<sub>(E-1)</sub></var> <var>t<sub>(E-1)</sub></var>
</pre>
<p>1行目に丸の数 <var>V</var> と線の数 <var>E</var> が空白区切りで与えられる。</p>
<p>2行目に丸の初期状態が空白区切りで与えられる。</p>
<p><var>a<sub>i</sub></var> が英小文字の場合は <var>i</var> 番目の丸にその英小文字が書かれており、'?'の場合は <var>i</var> 番目の丸には何も書かれていないことを表す。</p>
<p>続く <var>E</var> 行に線の情報が<var>s<sub>i</sub></var> <var>t<sub>i</sub></var> として与えられ、これは<var>s<sub>i</sub></var>番の丸と <var>t<sub>i</sub></var> 番の丸が線で結ばれていることを表す。</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>1 ≤ <var>V</var> ≤ 100,000</li>
<li>0 ≤ <var>E</var> ≤ 200,000</li>
<li><var>a<sub>i</sub></var> は英小文字, または '?' のいずれか ( 0 ≤ <var>i</var> ≤ <var>V-1</var> ) </li>
<li>0 ≤ <var>s<sub>i</sub></var>, <var>t<sub>i</sub></var> ≤ <var>V-1</var> ( <var>s<sub>i</sub></var> < <var>t<sub>i</sub></var> , 0 ≤ <var>i</var> ≤ <var>E-1</var> ) </li>
<li>1つの丸が26本以上の線で結ばれることはない</li>
</ul>
<h2>Output</h2>
<p>問題文中の手順に従って作成可能な文字列のうち、辞書順で最も小さいものを1行に出力せよ</p>
<h2>Sample Input 1</h2>
<pre>
3 3
c ? ?
0 1
0 2
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
cab
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2
c ? ?
0 1
0 2
</pre>
<h2>Sample Output 2</h2>
<pre>
caa
</pre>
<h2>Sample Input 3</h2>
<pre>
7 6
? a ? ? z a ?
0 1
0 2
3 4
4 5
4 6
5 6
</pre>
<h2>Sample Output 3</h2>
<pre>
baaazab
</pre>
<h2>Sample Input 4</h2>
<pre>
5 0
? ? ? ? ?
</pre>
<h2>Sample Output 4</h2>
<pre>
aaaaa
</pre>
|
p03501 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are parking at a parking lot. You can choose from the following two fee plans:</p>
<ul>
<li>Plan <var>1</var>: The fee will be <var>A×T</var> yen (the currency of Japan) when you park for <var>T</var> hours.</li>
<li>Plan <var>2</var>: The fee will be <var>B</var> yen, regardless of the duration.</li>
</ul>
<p>Find the minimum fee when you park for <var>N</var> hours.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N≤20</var></li>
<li><var>1≤A≤100</var></li>
<li><var>1≤B≤2000</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>When the minimum fee is <var>x</var> yen, print the value of <var>x</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 17 120
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>119
</pre>
<ul>
<li>If you choose Plan <var>1</var>, the fee will be <var>7×17=119</var> yen.</li>
<li>If you choose Plan <var>2</var>, the fee will be <var>120</var> yen.</li>
</ul>
<p>Thus, the minimum fee is <var>119</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 20 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
<p>The fee might be the same in the two plans.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 18 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100
</pre></section>
</div>
</span> |
p01496 |
<H1><font color="#000">Problem A: </font>Bicube</H1>
<p>
Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some <i>colorful</i> color (such as red and blue) on the front side. Cutting off the unpainted part, she will have eight opened-up unit cubes. A unit cube here refers to a cube of which each face consists of one square.
</p>
<p>
She is going to build those eight unit cubes with the front side exposed and then a bicube with them. A bicube is a cube of the size 2 × 2 × 2, consisting of eight unit cubes, that satisfies the following conditions:
</p>
<ul>
<li> faces of the unit cubes that comes to the inside of the bicube are all black;</li>
<li> each face of the bicube has a uniform <i>colorful</i> color; and</li>
<li> the faces of the bicube have colors all different.</li>
</ul>
<p>
Your task is to write a program that reads the specification of a sheet of squared paper and decides whether a
bicube can be built with the eight unit cubes resulting from it.
</p>
<H2>Input</H2>
<p>
The input contains the specification of a sheet. The first line contains two integers <i>H</i> and <i>W</i>, which denote the height and width of the sheet (3 ≤ <i>H</i>, <i>W</i> ≤ 50). Then H lines follow, each consisting of <i>W</i> characters. These lines show the squares on the front side of the sheet. A character represents the color of a grid: alphabets and digits ('A' to 'Z', 'a' to 'z', '0' to '9') for colorful squares, a hash ('#') for a black square, and a dot ('.') for an unpainted square. Each alphabet or digit denotes a unique color: squares have the same color if and only if they are represented by the same character.
</p>
<p>
Each component of connected squares forms one opened-up cube. Squares are regarded as connected when they have a common edge; those just with a common vertex are not.
</p>
<H2>Output</H2>
<p>
Print "<span>Yes</span>" if a bicube can be built with the given sheet; "<span>No</span>" otherwise.
</p>
<H2>Sample Input 1</H2>
<pre>
3 40
.a....a....a....a....f....f....f....f...
#bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#be#.
.#....#....#....#....#....#....#....#...
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
Yes
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
5 35
.a....a....a....a....f....f....f...
#bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.
.#..f.#....#....#....#....#....#...
..e##..............................
.b#................................
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
Yes
</pre>
<br/>
<H2>Sample Input 3</H2>
<pre>
3 40
.a....a....a....a....f....f....f....f...
#bc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#eb#.
.#....#....#....#....#....#....#....#...
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
No
</pre>
<br/> |
p03151 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A university student, Takahashi, has to take <var>N</var> examinations and pass all of them.
Currently, his <em>readiness</em> for the <var>i</var>-th examination is <var>A_{i}</var>, and according to his investigation, it is known that he needs readiness of at least <var>B_{i}</var> in order to pass the <var>i</var>-th examination.</p>
<p>Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness.</p>
<p>For Takahashi, find the minimum possible number of indices <var>i</var> such that <var>A_i</var> and <var>C_i</var> are different, for a sequence <var>C_1, C_2, ..., C_{N}</var> that satisfies the following conditions:</p>
<ul>
<li>The sum of the sequence <var>A_1, A_2, ..., A_{N}</var> and the sum of the sequence <var>C_1, C_2, ..., C_{N}</var> are equal.</li>
<li>For every <var>i</var>, <var>B_i \leq C_i</var> holds.</li>
</ul>
<p>If such a sequence <var>C_1, C_2, ..., C_{N}</var> cannot be constructed, print <var>-1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>1 \leq B_i \leq 10^9</var></li>
<li><var>A_i</var> and <var>B_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_{N}</var>
<var>B_1</var> <var>B_2</var> <var>...</var> <var>B_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible number of indices <var>i</var> such that <var>A_i</var> and <var>C_i</var> are different, for a sequence <var>C_1, C_2, ..., C_{N}</var> that satisfies the conditions.
If such a sequence <var>C_1, C_2, ..., C_{N}</var> cannot be constructed, print <var>-1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 3 5
3 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><var>(A_1, A_2, A_3) = (2, 3, 5)</var> and <var>(B_1, B_2, B_3) = (3, 4, 1)</var>. If nothing is done, he cannot pass the first and second exams.
The minimum possible number of indices <var>i</var> such that <var>A_i</var> and <var>C_i</var> are different, <var>3</var>, is achieved when:</p>
<ul>
<li><var>(C_1, C_2, C_3) = (3, 5, 2)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 3 3
2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>In this case, he has to do nothing in order to pass all the exams.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
17 7 1
25 6 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>In this case, no matter what is done, he cannot pass all the exams.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>12
757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604
74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre></section>
</div>
</span> |
p02310 |
<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>Tangent to a Circle</H1>
<p>
Find the tangent lines between a point $p$ and a circle $c$.
</p>
<H2>Input</H2>
<p>
The input is given in the following format.
</p>
<p>
$px \; py$ <br>
$cx \; cy \; r$
</p>
<p>
$px$ and $py$ represents the coordinate of the point $p$. $cx$, $cy$ and $r$ represents the center coordinate and radius of the circle $c$ respectively. All input values are given in integers.
</p>
<H2>Output</H2>
<p>
Print coordinates of the tangent points on the circle $c$ based on the following rules.
</p>
<ul>
<li> Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first.</li>
</ul>
<p>
The output values should be in a decimal fraction with an error less than 0.00001.
</p>
<H2>Constraints</H2>
<ul>
<li>$-1,000 \leq px, py, cx, cy \leq 1,000$</li>
<li>$1 \leq r \leq 1,000$</li>
<li>Distance between $p$ and the center of $c$ is greater than the radius of $c$.</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
0 0
2 2 2
</pre>
<H2>Sample Output 1</H2>
<pre>
0.0000000000 2.0000000000
2.0000000000 0.0000000000
</pre>
<H2>Sample Input 2</H2>
<pre>
-3 0
2 2 2
</pre>
<H2>Sample Output 2</H2>
<pre>
0.6206896552 3.4482758621
2.0000000000 0.0000000000
</pre> |
p00287 |
<h1>壁</h1>
<p>
2XXX年、突然出現した天敵の侵入を防ぐために、人類は壁を作りその中に逃げ込んだ。その結果、人類の活動領域はその壁で囲まれた範囲に限定されてしまった。この領域は、上空から見ると <var>W</var> × <var>H</var> の長方形である。領域内部には <var>x</var> 軸あるいは <var>y</var> 軸に対して平行な壁がいくつか設置されている。活動領域の例を下図に示す。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_wall1" width="360">
</center>
<br>
<p>
人類は活動領域内を自由に移動することができるが、壁を越えるためには一定量の資源を消費しなければならない。ただし、壁を越えることはできるが(図中の (1))、壁の交点を越えること (2)、壁や活動領域の境界の上を移動すること (3)、活動領域外に出ること (4) はできない。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_wall2" width="640">
</center>
<br>
<p>
領域内部の壁の情報といくつかの始点と終点の組を入力し、始点から終点へ移動するために越えなければならない壁の数の最小値を計算するプログラムを作成しなさい。ただし、壁は幅のない線分とします。
</p>
<h2>入力</h2>
<p>
入力は1つのデータセットからなる。入力データは以下の形式で与えられる。
</p>
<pre>
<var>W</var> <var>H</var> <var>M</var>
<var>px</var><sub>1</sub> <var>py</var><sub>1</sub> <var>qx</var><sub>1</sub> <var>qy</var><sub>1</sub>
<var>px</var><sub>2</sub> <var>py</var><sub>2</sub> <var>qx</var><sub>2</sub> <var>qy</var><sub>2</sub>
:
<var>px<sub>M</sub></var> <var>py<sub>M</sub></var> <var>qx<sub>M</sub></var> <var>qy<sub>M</sub></var>
<var>Q</var>
<var>sx</var><sub>1</sub> <var>sy</var><sub>1</sub> <var>gx</var><sub>1</sub> <var>gy</var><sub>1</sub>
<var>sx</var><sub>2</sub> <var>sy</var><sub>2</sub> <var>gx</var><sub>2</sub> <var>gy</var><sub>2</sub>
:
<var>sx<sub>Q</sub></var> <var>sy<sub>Q</sub></var> <var>gx<sub>Q</sub></var> <var>gy<sub>Q</sub></var>
</pre>
<p>
1行目に領域の横の長さと縦の長さを表す整数 <var>W</var>, <var>H</var> (2 ≤ <var>W,H</var> ≤ 1,000,000,000) と壁の数 <var>M</var> (0 ≤ <var>M</var> ≤ 100) が与えられる。
</p>
<p>
続く <var>M</var> 行に壁を表す線分の情報が与えられる。各行に与えられる4つの整数 <var>px<sub>i</sub></var>, <var>py<sub>i</sub></var>, <var>qx<sub>i</sub></var>, <var>qy<sub>i</sub></var> (0 ≤ <var>px<sub>i</sub></var>, <var>qx<sub>i</sub></var> ≤ <var>W</var>, 0 ≤ <var>py<sub>i</sub></var>, <var>qy<sub>i</sub></var> ≤ <var>H</var>) はそれぞれ <var>i</var> 番目の線分の端点の <var>x</var> 座標、<var>y</var> 座標、もうひとつの端点の <var>x</var> 座標、<var>y</var> 座標を表す。
</p>
<p>
続く1行に質問の数 <var>Q</var> (1 ≤ <var>Q</var> ≤ 100) が与えられる。続く <var>Q</var> 行に各質問が与えられる。各質問に含まれる4つの整数 <var>sx<sub>i</sub></var>, <var>sy<sub>i</sub></var>, <var>gx<sub>i</sub></var>, <var>gy<sub>i</sub></var> (0 < <var>sx<sub>i</sub></var>, <var>gx<sub>i</sub></var> < <var>W</var>, 0 < <var>sy<sub>i</sub></var>, <var>gy<sub>i</sub></var> < <var>H</var>) はそれぞれ始点の <var>x</var> 座標、<var>y</var> 座標、終点の <var>x</var> 座標、<var>y</var> 座標を表す。
</p>
<p>入力は以下の条件を満たす。</p>
<ul>
<li> 各線分は <var>x</var> 軸あるいは <var>y</var> 軸に対して平行であり、長さは1以上である。</li>
<li> 2つの互いに平行な線分が同じ点あるいは線分を共有することはない。</li>
<li> スタート地点、ゴール地点は壁上にあることはない。</li>
<li> どの線分も活動領域の境界と線分を共有することはない。</li>
</ul>
<h2>出力</h2>
<p>
質問ごとに、壁を越える回数の最小値を出力する。
</p>
<h2>入出力例</h2>
<br>
<h2>入力例 1</h2>
<pre>
5 6 5
0 2 5 2
0 3 5 3
0 4 3 4
1 4 1 6
3 0 3 6
2
2 5 4 1
2 5 4 5
</pre>
<h2>出力例 1</h2>
<pre>
3
1
</pre>
<h2>入力例 2</h2>
<pre>
4 4 0
1
1 1 2 2
</pre>
<h2>出力例 2</h2>
<pre>
0
</pre>
<h2>入力例 3</h2>
<pre>
4 7 3
0 2 2 2
3 3 4 3
0 5 4 5
3
1 1 1 3
1 1 1 4
1 1 1 6
</pre>
<h2>出力例 3</h2>
<pre>
0
0
1
</pre>
|
p02740 | <span class="lang-en">
<p>Score : <var>2100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> jewelry shops numbered <var>1</var> to <var>N</var>.</p>
<p>Shop <var>i</var> (<var>1 \leq i \leq N</var>) sells <var>K_i</var> kinds of jewels.
The <var>j</var>-th of these jewels (<var>1 \leq j \leq K_i</var>) has a size and price of <var>S_{i,j}</var> and <var>P_{i,j}</var>, respectively, and the shop has <var>C_{i,j}</var> jewels of this kind in stock.</p>
<p>A jewelry box is said to be <em>good</em> if it satisfies all of the following conditions:</p>
<ul>
<li>For each of the jewelry shops, the box contains one jewel purchased there.</li>
<li>All of the following <var>M</var> restrictions are met.<ul>
<li>Restriction <var>i</var> (<var>1 \leq i \leq M</var>): <var>(</var>The size of the jewel purchased at Shop <var>V_i</var><var>)\leq (</var>The size of the jewel purchased at Shop <var>U_i</var><var>)+W_i</var></li>
</ul>
</li>
</ul>
<p>Answer <var>Q</var> questions.
In the <var>i</var>-th question, given an integer <var>A_i</var>, find the minimum total price of jewels that need to be purchased to make <var>A_i</var> good jewelry boxes. If it is impossible to make <var>A_i</var> good jewelry boxes, report that fact.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 30</var></li>
<li><var>1 \leq K_i \leq 30</var></li>
<li><var>1 \leq S_{i,j} \leq 10^9</var></li>
<li><var>1 \leq P_{i,j} \leq 30</var></li>
<li><var>1 \leq C_{i,j} \leq 10^{12}</var></li>
<li><var>0 \leq M \leq 50</var></li>
<li><var>1 \leq U_i,V_i \leq N</var></li>
<li><var>U_i \neq V_i</var></li>
<li><var>0 \leq W_i \leq 10^9</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 3 \times 10^{13}</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>
Description of Shop <var>1</var>
Description of Shop <var>2</var>
<var>\vdots</var>
Description of Shop <var>N</var>
<var>M</var>
<var>U_1</var> <var>V_1</var> <var>W_1</var>
<var>U_2</var> <var>V_2</var> <var>W_2</var>
<var>\vdots</var>
<var>U_M</var> <var>V_M</var> <var>W_M</var>
<var>Q</var>
<var>A_1</var>
<var>A_2</var>
<var>\vdots</var>
<var>A_Q</var>
</pre>
<p>The description of Shop <var>i</var> (<var>1 \leq i \leq N</var>) is in the following format:</p>
<pre><var>K_i</var>
<var>S_{i,1}</var> <var>P_{i,1}</var> <var>C_{i,1}</var>
<var>S_{i,2}</var> <var>P_{i,2}</var> <var>C_{i,2}</var>
<var>\vdots</var>
<var>S_{i,K_i}</var> <var>P_{i,K_i}</var> <var>C_{i,K_i}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines.
The <var>i</var>-th line should contain the minimum total price of jewels that need to be purchased to make <var>A_i</var> good jewelry boxes, or <var>-1</var> if it is impossible to make them.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2
1 10 1
3 1 1
3
1 10 1
2 1 1
3 10 1
2
1 1 1
3 10 1
2
1 2 0
2 3 0
3
1
2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
42
-1
</pre>
<p>Let <var>(i,j)</var> represent the <var>j</var>-th jewel sold at Shop <var>i</var>.
The answer to each query is as follows:</p>
<ul>
<li><var>A_1=1</var>: Making a box with <var>(1,2),(2,2),(3,1)</var> costs <var>1+1+1=3</var>, which is optimal.</li>
<li><var>A_2=2</var>: Making a box with <var>(1,1),(2,1),(3,1)</var> and another with <var>(1,2),(2,3),(3,2)</var> costs <var>(10+10+1)+(1+10+10)=42</var>, which is optimal.</li>
<li><var>A_3=3</var>: We cannot make three good boxes.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
5
86849520 30 272477201869
968023357 28 539131386006
478355090 8 194500792721
298572419 6 894877901270
203794105 25 594579473837
5
730211794 22 225797976416
842538552 9 420531931830
871332982 26 81253086754
553846923 29 89734736118
731788040 13 241088716205
5
903534485 22 140045153776
187101906 8 145639722124
513502442 9 227445343895
499446330 6 719254728400
564106748 20 333423097859
5
332809289 8 640911722470
969492694 21 937931959818
207959501 11 217019915462
726936503 12 382527525674
887971218 17 552919286358
5
444983655 13 487875689585
855863581 6 625608576077
885012925 10 105520979776
980933856 1 711474069172
653022356 19 977887412815
10
1 2 231274893
2 3 829836076
3 4 745221482
4 5 935448462
5 1 819308546
3 5 815839350
5 3 513188748
3 1 968283437
2 3 202352515
4 3 292999238
10
510266667947
252899314976
510266667948
374155726828
628866122125
628866122123
1
628866122124
510266667949
30000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>26533866733244
13150764378752
26533866733296
19456097795056
-1
33175436167096
52
33175436167152
26533866733352
-1
</pre></section>
</div>
</span> |
p03852 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given a lowercase English letter <var>c</var>, determine whether it is a vowel. Here, there are five vowels in the English alphabet: <code>a</code>, <code>e</code>, <code>i</code>, <code>o</code> and <code>u</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>c</var> is a lowercase English letter.</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>c</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>c</var> is a vowel, print <code>vowel</code>. Otherwise, print <code>consonant</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>a
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>vowel
</pre>
<p>Since <code>a</code> is a vowel, print <code>vowel</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>consonant
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>s
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>consonant
</pre></section>
</div>
</span> |
p02890 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi has <var>N</var> cards. The <var>i</var>-th of these cards has an integer <var>A_i</var> written on it.</p>
<p>Takahashi will choose an integer <var>K</var>, and then repeat the following operation some number of times:</p>
<ul>
<li>Choose exactly <var>K</var> cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)</li>
</ul>
<p>For each <var>K = 1,2, \ldots, N</var>, find the maximum number of times Takahashi can do the operation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var> 1 \le N \le 3 \times 10^5 </var></li>
<li><var> 1 \le A_i \le N </var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>\ldots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <var>N</var> integers.
The <var>t</var>-th <var>(1 \le t \le N)</var> of them should be the answer for the case <var>K=t</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
1
0
</pre>
<p>For <var>K = 1</var>, we can do the operation as follows:</p>
<ul>
<li>Choose the first card to eat.</li>
<li>Choose the second card to eat.</li>
<li>Choose the third card to eat.</li>
</ul>
<p>For <var>K = 2</var>, we can do the operation as follows:</p>
<ul>
<li>Choose the first and second cards to eat.</li>
</ul>
<p>For <var>K = 3</var>, we cannot do the operation at all. Note that we cannot choose the first and third cards at the same time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
2
1
1
1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
1
0
0
</pre></section>
</div>
</span> |
p04047 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is having a barbeque party.</p>
<p>At the party, he will make <var>N</var> servings of <em>Skewer Meal</em>.</p>
<div style="text-align: center;">
<img src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/abbq.png">
<p>Example of a serving of Skewer Meal</p>
</img></div>
<p>He has a stock of <var>2N</var> skewers, all of which will be used in Skewer Meal. The length of the <var>i</var>-th skewer is <var>L_i</var>.
Also, he has an infinite supply of ingredients.</p>
<p>To make a serving of Skewer Meal, he picks <var>2</var> skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be <var>x</var>, then the serving can hold the maximum of <var>x</var> ingredients.</p>
<p>What is the maximum total number of ingredients that his <var>N</var> servings of Skewer Meal can hold, if he uses the skewers optimally?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N≦100</var></li>
<li><var>1≦L_i≦100</var></li>
<li>For each <var>i</var>, <var>L_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>L_1</var> <var>L_2</var> <var>...</var> <var>L_{2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum total number of ingredients that Snuke's <var>N</var> servings of Skewer Meal can hold.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 3 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold <var>1</var> and <var>2</var> ingredients, for the total of <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
100 1 2 3 14 15 58 58 58 29
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>135
</pre></section>
</div>
</span> |
p03782 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer has <var>N</var> cards with positive integers written on them. The number on the <var>i</var>-th card <var>(1≤i≤N)</var> is <var>a_i</var>.
Because he loves big numbers, he calls a subset of the cards <em>good</em> when the sum of the numbers written on the cards in the subset, is <var>K</var> or greater.</p>
<p>Then, for each card <var>i</var>, he judges whether it is <em>unnecessary</em> or not, as follows:</p>
<ul>
<li>If, for any good subset of the cards containing card <var>i</var>, the set that can be obtained by eliminating card <var>i</var> from the subset is also good, card <var>i</var> is unnecessary.</li>
<li>Otherwise, card <var>i</var> is NOT unnecessary.</li>
</ul>
<p>Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1≤N≤5000</var></li>
<li><var>1≤K≤5000</var></li>
<li><var>1≤a_i≤10^9 (1≤i≤N)</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N,K≤400</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>a_1</var> <var>a_2</var> ... <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the unnecessary cards.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 6
1 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>There are two good sets: {<var>2,3</var>} and {<var>1,2,3</var>}.</p>
<p>Card <var>1</var> is only contained in {<var>1,2,3</var>}, and this set without card <var>1</var>, {<var>2,3</var>}, is also good. Thus, card <var>1</var> is unnecessary.</p>
<p>For card <var>2</var>, a good set {<var>2,3</var>} without card <var>2</var>, {<var>3</var>}, is not good. Thus, card <var>2</var> is NOT unnecessary.</p>
<p>Neither is card <var>3</var> for a similar reason, hence the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 400
3 1 4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>In this case, there is no good set. Therefore, all the cards are unnecessary.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 20
10 4 3 10 25 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p01245 |
<H1><font color="#000">Problem C:</font> Magical Dungeon</H1>
<p>
Arthur C. Malory is a wandering valiant fighter (in a game world).
</p>
<p>
One day, he visited a small village and stayed overnight. Next morning, the village mayor called on him. The
mayor said a monster threatened the village and requested him to defeat it. He was so kind that he decided to
help saving the village.
</p>
<p>
The mayor told him that the monster seemed to come from the west. So he walked through a forest swept away
in the west of the village and found a suspicious cave. Surprisingly, there was a deep dungeon in the cave. He
got sure this cave was the lair of the monster.
</p>
<p>
Fortunately, at the entry, he got a map of the dungeon. According to the map, the monster dwells in the depth of
the dungeon. There are many rooms connected by paths in the dungeon. All paths are one-way and filled with
magical power. The magical power heals or damages him when he passes a path.
</p>
<p>
The amount of damage he can take is indicated by hit points. He has his maximal hit points at the beginning and
he goes dead if he lost all his hit points. Of course, the dead cannot move nor fight - his death means the failure
of his mission. On the other hand, he can regain his hit points up to his maximal by passing healing paths. The
amount he gets healed or damaged is shown in the map.
</p>
<p>
Now, he wants to fight the monster with the best possible condition. Your job is to maximize his hit points when
he enters the monster’s room. Note that he must fight with the monster once he arrives there. You needn’t care
how to return because he has a magic scroll to escape from a dungeon.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases.
</p>
<p>
The first line of each test case contains two integers <i>N</i> (2 ≤ <i>N</i> ≤ 100) and <i>M</i> (1 ≤ <i>M</i> ≤ 1000). <i>N</i> denotes the
number of rooms and <i>M</i> denotes the number of paths. Rooms are labeled from 0 to <i>N</i> - 1. Each of next <i>M</i> lines
contains three integers <i>f<sub>i</sub></i>, <i>t<sub>i</sub></i> and <i>w<sub>i</sub></i> (|<i>w<sub>i</sub></i>| ≤ 10<sup>7</sup> ), which describe a path connecting rooms. <i>f<sub>i</sub></i> and <i>t<sub>i</sub></i> indicate the
rooms connected with the entrance and exit of the path, respectively. And <i>w<sub>i</sub></i> indicates the effect on Arthur’s hit
points; he regains his hit points if <i>w<sub>i</sub></i> is positive; he loses them otherwise. The last line of the case contains three
integers <i>s</i>, <i>t</i> and <i>H</i> (0 < <i>H</i> ≤ 10<sup>7</sup>). <i>s</i> indicates the entrance room of the dungeon, <i>t</i> indicates the monster’s room
and <i>H</i> indicates Arthur’s maximal hit points. You can assume that <i>s</i> and <i>t</i> are different, but <i>f<sub>i</sub></i> and <i>t<sub>i</sub></i> may be the same.
</p>
<p>
The last test case is followed by a line containing two zeroes.
</p>
<H2>Output</H2>
<p>
For each test case, print a line containing the test case number (beginning with 1) followed by the maximum
possible hit points of Arthur at the monster’s room. If he cannot fight with the monster, print the case number
and “GAME OVER” instead.
</p>
<H2>Sample Input</H2>
<pre>
7 8
0 2 3
2 3 -20
3 4 3
4 1 -5
1 5 1
5 4 5
1 3 2
3 6 -2
0 6 30
7 8
0 2 3
2 3 -20
3 4 3
4 1 -5
1 5 1
5 4 5
1 3 2
3 6 -2
0 6 20
4 4
0 1 -10
1 2 -50
2 1 51
1 3 1
0 3 20
11 14
0 1 -49
1 2 1
2 3 40
3 1 -40
1 4 -9
4 5 40
5 1 -30
1 6 -19
6 7 40
7 1 -20
1 8 -30
8 9 40
9 1 -9
1 10 1
0 10 50
3 4
0 1 -49
1 2 10
2 0 50
2 1 10
0 1 50
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 25
Case 2: GAME OVER
Case 3: 11
Case 4: 31
Case 5: 1
</pre>
|
p03278 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>N</var> be an even number.</p>
<p>There is a tree with <var>N</var> vertices.
The vertices are numbered <var>1, 2, ..., 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>Snuke would like to decorate the tree with ribbons, as follows.</p>
<p>First, he will divide the <var>N</var> vertices into <var>N / 2</var> pairs.
Here, each vertex must belong to exactly one pair.
Then, for each pair <var>(u, v)</var>, put a ribbon through all the edges contained in the shortest path between <var>u</var> and <var>v</var>.</p>
<p>Snuke is trying to divide the vertices into pairs so that the following condition is satisfied: "for every edge, there is at least one ribbon going through it."
How many ways are there to divide the vertices into pairs, satisfying this condition?
Find the count modulo <var>10^9 + 7</var>.
Here, two ways to divide the vertices into pairs are considered different when there is a pair that is contained in one of the two ways but not in the other.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an even number.</li>
<li><var>2 \leq N \leq 5000</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>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 the number of the ways to divide the vertices into pairs, satisfying the condition, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2
2 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are three possible ways to divide the vertices into pairs, as shown below, and two satisfy the condition: the middle one and the right one.</p>
<p><img src="https://img.atcoder.jp/arc101/2d7584d2e0736f746aa9d54e1bf31e28.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2
1 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>There are three possible ways to divide the vertices into pairs, as shown below, and all of them satisfy the condition.</p>
<p><img src="https://img.atcoder.jp/arc101/2de530ed2e64d0161ee6b989d1946261.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2
1 3
3 4
1 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
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>672
</pre></section>
</div>
</span> |
p00907 |
<H1><font color="#000">Problem D: </font> Find the Outlier</H1>
<p>
Professor Abacus has just built a new computing engine for making numerical tables. It was designed to calculate the values of a polynomial function in one variable at several points at a time. With the polynomial function <i>f</i>(<i>x</i>) = <i>x</i><sup>2</sup> + 2<i>x</i> + 1, for instance, a possible expected calculation result is 1 (= <i>f</i>(0)), 4 (= <i>f</i>(1)), 9 (= <i>f</i>(2)), 16 (= <i>f</i>(3)), and 25 (= <i>f</i>(4)).
</p>
<p>
It is a pity, however, the engine seemingly has faulty components and exactly one value among those calculated simultaneously is always wrong. With the same polynomial function as above, it can, for instance, output 1, 4, 12, 16, and 25 instead of 1, 4, 9, 16, and 25.
</p>
<p>
You are requested to help the professor identify the faulty components. As the first step, you should write a program that scans calculation results of the engine and finds the wrong values.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets, each representing a calculation result in the following format.
</p>
<p>
<i>d</i><br/>
<i>v</i><sub>0</sub><br/>
<i>v</i><sub>1</sub><br/>
...<br/>
<i>v</i><sub><i>d</i>+2</sub><br/>
</p>
<p>
Here, <i>d</i> in the first line is a positive integer that represents the degree of the polynomial, namely, the highest exponent of the variable. For instance, the degree of 4<i>x</i><sup>5</sup> + 3<i>x</i> + 0.5 is five and that of 2.4<i>x</i> + 3.8 is one. <i>d</i> is at most five.
</p>
<p>
The following <i>d</i> + 3 lines contain the calculation result of <i>f</i>(0), <i>f</i>(1), ... , and <i>f</i>(<i>d</i> + 2) in this order, where <i>f</i> is the polynomial function. Each of the lines contains a decimal fraction between -100.0 and 100.0, exclusive.
</p>
<p>
You can assume that the wrong value, which is exactly one of <i>f</i>(0), <i>f</i>(1), ... , and <i>f</i>(<i>d</i>+2), has an error greater than 1.0. Since rounding errors are inevitable, the other values may also have errors but they are small and never exceed 10<sup>-6</sup>.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output <i>i</i> in a line when <i>v<sub>i</sub></i> is wrong.
</p>
<H2>Sample Input</H2>
<pre>
2
1.0
4.0
12.0
16.0
25.0
1
-30.5893962764
5.76397083962
39.3853798058
74.3727663177
4
42.4715310246
79.5420238202
28.0282396675
-30.3627807522
-49.8363481393
-25.5101480106
7.58575761381
5
-21.9161699038
-48.469304271
-24.3188578417
-2.35085940324
-9.70239202086
-47.2709510623
-93.5066246072
-82.5073836498
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
1
1
6
</pre> |
p01615 |
<h1>C: Project Management / プロジェクト管理</h1>
<p>あなたは凄腕のプロジェクトマネージャである. 今回は超大規模なプロジェクトのマネジメントを請け負った.</p>
<div align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day3_C_C_fig_arrow" alt="C_fig_arrow.png" />
<p><strong>図1:</strong> アローダイアグラム</p>
</div>
<p>これまでの勘と経験からなんとか <strong>図1</strong> のようなアローダイアグラムを作成した. 各ノードは作業の結合点を表している. また,Sはプロジェクトの開始状態,Tはプロジェクトの終了状態を表す結合点である. 例えば結合点P3において,作業Gは作業Cと作業Eが終了しなければ開始できない. プロジェクトの計画は完璧であり,全ての結合点は,そこから出て再びその結合点に戻る作業経路を持たない. また,全ての作業は前後に結合点を持っており, 開始状態と終了状態以外の結合点は必ず前後に作業を持っている.</p>
<p>しかし,今回のプロジェクトは作業数が多い.</p>
<p>アローダイアグラムにおいて,所要時間が最長となる経路(クリティカルパス)上の作業は, プロジェクトの時間制約に大きく影響する. そこであなたはアローダイアグラム上のクリティカルパスの所要日数を計算するプログラムを書くことにした. ちなみに,このクリティカリパスは必ずアローダイアグラム上に存在する.</p>
<div>
<h1>Input</h1>
<p>入力は次の形式で表される.</p>
<div>
<em>n</em> <em>m</em><br />
<em>a</em><sub>1</sub> <em>b</em><sub>1</sub> <em>c</em><sub>1</sub><br />
...<br />
<em>a</em><sub>m</sub> <em>b</em><sub>m</sub> <em>c</em><sub>m</sub><br />
</div>
<br/>
<p><em>n</em> ( 2 ≦ <em>n</em> ≦ 400 ) は結合点の数, <em>m</em> ( 1 ≦ <em>m</em> ≦ 800 ) は作業の数を表す整数である. このとき,結合点 0 が開始状態の結合点を表し,結合点 <em>n</em> - 1 が終了状態の結合点を表している. <em>a</em><sub>i</sub>, <em>b</em><sub>i</sub>, <em>c</em><sub>i</sub> は1つの空白で区切られた整数であり, 結合点 <em>a</em><sub>i</sub> ( 0 ≦ <em>a</em><sub>i</sub> ≦ <em>n</em> - 2 ) から <em>b</em><sub>i</sub> ( 1 ≦ <em>b</em><sub>i</sub> ≦ <em>n</em> - 1 ) までの作業に <em>c</em><sub>i</sub> ( 1 ≦ <em>c</em><sub>i</sub> ≦ 100 ) 日必要なことを表している. <em>a</em><sub>i</sub> と <em>b</em><sub>i</sub> は常に異なっている. また,同じ <em>a</em><sub>i</sub>, <em>b</em><sub>i</sub> の組みは2度以上現れないと考えて良い.</p>
</div>
<div>
<h1>Output</h1>
<p>クリティカルパスの所要日数を表す整数を1行出力せよ. 出力にはこれら以外の文字があってはならない.</p>
</div>
<div>
<h1>Sample Input 1</h1>
<pre>
7 9
0 1 10
0 2 3
1 3 4
1 4 7
2 3 7
2 5 9
3 4 2
4 6 1
5 6 7
</pre>
</div>
<div>
<h1>Sample Output 1</h1>
<pre>
19
</pre>
</div> |
p03628 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a board with a <var>2 \times N</var> grid.
Snuke covered the board with <var>N</var> dominoes without overlaps.
Here, a domino can cover a <var>1 \times 2</var> or <var>2 \times 1</var> square.</p>
<p>Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoes that are adjacent by side should be painted by different colors.
Here, it is not always necessary to use all three colors.</p>
<p>Find the number of such ways to paint the dominoes, modulo <var>1000000007</var>.</p>
<p>The arrangement of the dominoes is given to you as two strings <var>S_1</var> and <var>S_2</var> in the following manner:</p>
<ul>
<li>Each domino is represented by a different English letter (lowercase or uppercase).</li>
<li>The <var>j</var>-th character in <var>S_i</var> represents the domino that occupies the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 52</var></li>
<li><var>|S_1| = |S_2| = N</var></li>
<li><var>S_1</var> and <var>S_2</var> consist of lowercase and uppercase English letters.</li>
<li><var>S_1</var> and <var>S_2</var> represent a valid arrangement of dominoes.</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of such ways to paint the dominoes, modulo <var>1000000007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
aab
ccb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six ways as shown below:</p>
<p><img alt="" src="https://atcoder.jp/img/arc081/899673bd23529f4fb5e41c6e7d5bc372.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
Z
Z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Note that it is not always necessary to use all the colors.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>958681902
</pre></section>
</div>
</span> |
p02193 | <h2>Range Min of Max Query</h2>
<p>整数の組の列<var>(a_1,b_1), (a_2,b_2),..,(a_N,b_N)</var>が与えられます。</p>
<p>二種類のクエリを処理してください。</p>
<p>一種類目のクエリでは、<var>a_L,a_{L+1},..,a_R</var>に<var>X</var>を加算します。</p>
<p>二種類目のクエリでは、<var>max(a_L,b_L),max(a_{L+1},b_{L+1}),..,max(a_R,b_R)</var>の最小値を求めます。</p>
<h3>入力</h3>
<pre>
<var>N Q</var>
<var>a_1 b_1</var>
<var>a_2 b_2</var>
:
<var>a_N b_N</var>
<var>query_1</var>
<var>query_2</var>
:
<var>query_Q</var>
</pre>
<p><var>i</var>番目のクエリが一種類目のクエリの場合、<var>query_i</var>は<var>1 L_i R_i X_i</var>となります。</p>
<p><var>i</var>番目のクエリが二種類目のクエリの場合、<var>query_i</var>は<var>2 L_i R_i</var>となります。</p>
<h3>出力</h3>
<pre>
<var>ans_1</var>
<var>ans_2</var>
:
<var>ans_k</var>
</pre>
<p>二種類目のクエリに対する答えを順に出力せよ。</p>
<h3>制約</h3>
<ul>
<li><var>1 \leq N,Q \leq 10^5 </var></li>
<li><var>1 \leq a_i,b_i \leq 10^9</var></li>
<li><var>1 \leq L_i \leq R_i \leq N</var></li>
<li><var>-10^9 \leq X_i \leq 10^9</var></li>
</ul>
<h3>入力例</h3>
<pre>
6 6
8 1
6 1
9 4
1 5
2 1
1 4
2 1 3
1 1 3 3
2 1 3
2 4 6
1 4 6 3
2 4 6
</pre>
<h3>出力例</h3>
<pre>
6
9
2
4
</pre>
|
p02469 |
<H1>Least Common Multiple</H1>
<br/>
<p>
Find the least common multiple (LCM) of given <var>n</var> integers.
</p>
<H2>Input</H2>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a</var><sub><var>n</var></sub>
</pre>
<p>
<var>n</var> is given in the first line. Then, <var>n</var> integers are given in the second line.
</p>
<H2>Output</H2>
<p>
Print the least common multiple of the given integers in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>
2 ≤ <var>n</var> ≤ 10
</li>
<li>
1 ≤ <var>a<sub>i</sub></var> ≤ 1000
</li>
<li>
Product of given integers <var>a<sub>i</sub></var>(<var>i = 1, 2, ... n</var>) does not exceed 2<sup>31</sup>-1
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3
3 4 6
</pre>
<H2>Sample Output 1</H2>
<pre>
12
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4
1 2 3 5
</pre>
<H2>Sample Output 2</H2>
<pre>
30
</pre>
|
p00454 |
<H1> ペンキの色 </H1>
<h2>問題</h2>
<p>
情報オリンピックの宣伝のために,長方形のベニヤ板にペンキを塗り看板を制作したい.ベニヤ板には色を塗りたくないところにあらかじめ何枚かの長方形のマスキングテープが貼られている.そこでマスキングテープで区切られた領域ごとに別々の色を使いペンキを塗ることにした.例えば,図 5-1 の場合は 5 色のペンキを使う.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_penki1">
</center>
<br>
<p>
入力としてマスキングテープを貼る位置が与えられた時,使うペンキの色の数を求めるプログラムを作成せよ.ただし,ベニヤ板全体がマスキングテープで覆われることはなく,全てのマスキングテープの辺はベニヤ板のいずれかの辺に平行である.
</p>
<h2>入力</h2>
<p>
<!-- 入力ファイルのファイル名は input.txt である.-->
入力は複数のデータセットからなる.各データセットは以下の形式で与えられる.
</p>
<p>
1 行目にはベニヤ板の幅 w (1 ≤ w ≤ 1000000 となる整数) と高さ h (1 ≤ h ≤ 1000000 となる整数) がこの順に空白区切りで書かれている.
</p>
<p>
2 行目にはマスキングテープの数 n (1 ≤ n ≤ 1000 となる整数) が書かれている.
続く 3 行目以降の 2 + i 行目 (1 ≤ i ≤ n) には,i 番目に貼るマスキングテープの左下の座標 (x<sub>1</sub> , y<sub>1</sub> ) と,右上の座標 (x<sub>2</sub> , y<sub>2</sub> ) が x<sub>1</sub> , y<sub>1</sub> , x<sub>2</sub> , y<sub>2</sub> (0 ≤ x<sub>1</sub> < x<sub>2</sub> ≤ w, 0 ≤ y<sub>1</sub> < y<sub>2</sub> ≤ h となる整数) の順に空白区切りで書かれている.
</p>
<p>
ただし,ベニヤ板の左下の角の座標は (0, 0) で右上の角の座標は (w, h) である. 採点用データのうち, 配点の 30% 分は w ≤ 100, h ≤ 100, n ≤ 100 を満たす.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_penki2">
</center>
<br>
<p>
h, w がともに 0 のとき入力の終了を示す. データセットの数は 20 を超えない.
</p>
<h2>出力</h2>
<p>
<!--
出力ファイルのファイル名は output.txt である.
output.txt は 1 行だけからなり,その 1 行は使うペンキの色数だけを含む.
-->
データセットごとに使うペンキの色数を1行に出力する.
</p>
<h2>入出力例</h2>
<p>次の例は図 5-1 の場合である.</p>
<h3>入力例</h3>
<pre>
15 6
10
1 4 5 6
2 1 4 5
1 0 5 1
6 1 7 5
7 5 9 6
7 0 9 2
9 1 10 5
11 0 14 1
12 1 13 5
11 5 14 6
0 0
</pre>
<h3>出力例</h3>
<pre>
5
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02039 | <h1>C: オセロ</h1>
<h2>問題</h2>
<p>
オセロの盤面を用意する. 盤面は左上が $(1,1)$ , 右下が $(8,8)$ と表記する. ここで用意する盤面は, 以下のように, $(5,4)$ の黒の石がない.
</p>
<pre>
........
........
........
...ox...
....o...
........
........
........
</pre>
<p>
黒石:x 白石:o<br>
8x8の盤面<br>
この状態から, 黒が先手でオセロを開始する.
</p>
<p>
AORイカちゃんは, 以下のルールで $q$ 回遊ぶ.
</p>
<p>
左上を $a$ 行目 $b$ 列目のマス, 右下を $c$ 行目 $d$ 列目のマスとした, マス目に沿った長方形領域が与えられる.
</p>
<p>
AORイカちゃんは, この長方形領域に含まれる石の数を最大化するように, オセロのルール(参考:<a href="https://ja.wikipedia.org/wiki/%E3%82%AA%E3%82%BB%E3%83%AD_(%E9%81%8A%E6%88%AF)">Wikipedia オセロ </a> )にのっとり黒石と白石を交互に置いていく.<br>
これ以上石が置けなくなったとき(白石黒石ともにパスするしかない状態やすべての盤面が埋まった状態のとき), ゲームを終了する.
</p>
<p>
それぞれのゲームで, その領域に含まれる石の数を最大化したときの石の数を出力せよ.<br>
なお, 入力や出力の回数が多くなることがあるため, 入出力には高速な関数を用いることを推奨する.
</p>
<h2>制約</h2>
<ul>
<li>$1 \leq q \leq 10^{5}$</li>
<li>$1 \leq a \leq c \leq 8$</li>
<li>$1 \leq b \leq d \leq 8$</li>
</ul>
<h2>入力形式</h2>
<p> 入力は以下の形式で与えられる. </p>
<p>
$q$<br>
$a_1\ b_1\ c_1\ d_1$<br>
$a_2\ b_2\ c_2\ d_2$<br>
$\vdots$<br>
$a_q\ b_q\ c_q\ d_q$<br>
</p>
<h2>出力</h2>
<p>
それぞれのゲームで, その領域に含まれる, 石の数を最大化したときの石の数を出力せよ. また, 末尾に改行も出力せよ.
</p>
<h2>サンプル</h2>
<h3>サンプル入力 1</h3>
<pre>
3
1 1 8 8
2 4 3 8
8 8 8 8
</pre>
<h3>サンプル出力 1</h3>
<pre>
48
7
1
</pre>
|
p00004 |
<H1>Simultaneous Equation</H1>
<p>
Write a program which solve a simultaneous equation:<br>
<br>
<var> ax + by = c</var><br>
<var> dx + ey = f</var><br>
<br>
The program should print <var>x</var> and <var>y</var> for given <var>a</var>, <var>b</var>, <var>c</var>, <var>d</var>, <var>e</var> and <var>f</var> (-1,000 ≤ <var>a, b, c, d, e, f</var> ≤ 1,000). You can suppose that given equation has a unique solution.
</p>
<H2>Input</H2>
<p>
The input consists of several data sets, 1 line for each data set. In a data set, there will be <var>a, b, c, d, e, f</var> separated by a single space. The input terminates with EOF.
</p>
<H2>Output</H2>
<p>
For each data set, print <var>x</var> and <var>y</var> separated by a single space. Print the solution to three places of decimals. Round off the solution to three decimal places.
</p>
<H2>Sample Input 1</H2>
<pre>
1 2 3 4 5 6
2 -1 -2 -1 -1 -5
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
-1.000 2.000
1.000 4.000
</pre>
<H2>Sample Input 2</H2>
<pre>
2 -1 -3 1 -1 -3
2 -1 -3 -9 9 27
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
0.000 3.000
0.000 3.000
</pre>
|
p00511 |
<H1>問題 2 </H1>
<br/>
<p>
加減乗除の計算をする電卓プログラムを作りなさい.
</p>
<p>
入力データの各行には数と記号 +, -, *, /, = のどれか1つが交互に書いてある.
1行目は数である.
演算 +, -, *, / の優先順位(乗除算 *, / を加減算 +, - よりも先に計算すること)は考えず,入力の順序で計算し,= の行になったら,計算結果を出力する.
入力データの数値は10<sup>8</sup>以下の正の整数とする.
計算中および計算結果は,0または負の数になることもあるが
-10<sup>8</sup>〜10<sup>8</sup> の範囲は超えない.
割り算は切り捨てとする.
したがって,100/3*3= は 99 になる.
</p>
<p>
出力ファイルにおいては,
出力の最後の行にも改行コードを入れること.
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
1
+
1
=
</pre>
<h3>出力例1</h3>
<pre>
2
</pre>
<h3>入力例2</h3>
<pre>
10
-
21
*
5
=
</pre>
<h3>出力例2</h3>
<pre>
-55
</pre>
<h3>入力例3</h3>
<pre>
100
/
3
*
3
=
</pre>
<h3>出力例3</h3>
<pre>
99
</pre>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00141 |
<H1>ぐるぐる模様</H1>
<p>
「ぐるぐる模様」を表示するプログラムを作成することにしました。「ぐるぐる模様」は以下のようなものとします。
</p>
<ul>
<li>1 辺の長さが <var>n</var> の場合、<var>n</var> 行 <var>n</var> 列の文字列として表示する。</li>
<li>左下隅を基点とし,時計回りに回転する渦状の模様とする。</li>
<li>線のある部分は #(半角シャープ)、空白部分は " "(半角空白)で表現する。</li>
<li>線と線の間は空白を置く。</li>
</ul>
<p>
整数 <var>n</var> を入力とし,1 辺の長さが <var>n</var> の「ぐるぐる模様」を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
入力は以下の形式で与えられます。
</p>
<pre>
<var>d</var>
<var>n<sub>1</sub></var>
<var>n<sub>2</sub></var>
:
<var>n<sub>d</sub></var>
</pre>
<p>
1行目にデータセットの数 <var>d</var> (<var>d</var> ≤ 20)、続く <var>d</var> 行に <var>i</var> 個目のぐるぐる模様の辺の長さ <var>n<sub>i</sub></var> (1 ≤ <var>n<sub>i</sub></var> ≤ 100) がそれぞれ1行に与えられます。
</p>
<H2>Output</H2>
<p>
データセットごとに、ぐるぐる模様を出力してください。データセットの間に1行の空行を入れてください。
</p>
<H2>Sample Input</H2>
<pre>
2
5
6
</pre>
<H2>Output for the Sample Input </H2>
<pre>
#####
# #
# # #
# # #
# ###
######
# #
# ## #
# # #
# # #
# ####
</pre>
|
p01300 |
<H1><font color="#000">Problem H:</font> Eleven Lover</H1>
<p>
Edward Leven loves multiples of eleven very much. When he sees a number, he always tries
to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such
subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819.
</p>
<p>
He thinks a number which has many 11-sequences is a <i>good</i> number. He would like to find out
a very <i>good</i> number. As the first step, he wants an easy way to count how many 11-sequences
are there in a given number. Even for him, counting them from a big number is not easy.
Fortunately, one of his friends, you, is a brilliant programmer. He asks you to write a program
to count the number of 11-sequences. Note that an 11-sequence must be a positive number
without leading zeros.
</p>
<H2>Input</H2>
<p>
The input is a sequence of lines each of which contains a number consisting of less than or equal
to 80000 digits.
</p>
<p>
The end of the input is indicated by a line containing a single zero, which should not be processed.
</p>
<H2>Output</H2>
<p>
For each input number, output a line containing the number of 11-sequences.
</p>
<p>
You can assume the answer fits in a 32-bit signed integer.
</p>
<H2>Sample Input</H2>
<pre>
17819
1111
11011
1234567891011121314151617181920
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
4
4
38
</pre>
|
p00842 |
<H1><font color="#000">Problem G:</font> Network Mess</H1>
<p>
Gilbert is the network admin of Ginkgo company. His boss is mad about the messy network
cables on the floor. He finally walked up to Gilbert and asked the lazy network admin to illustrate
how computers and switches are connected. Since he is a programmer, he is very reluctant to
move throughout the office and examine cables and switches with his eyes. He instead opted
to get this job done by measurement and a little bit of mathematical thinking, sitting down in
front of his computer all the time. Your job is to help him by writing a program to reconstruct
the network topology from measurements.
</p>
<p>
There are a known number of computers and an unknown number of switches. Each computer
is connected to one of the switches via a cable and to nothing else. Specifically, a computer
is never connected to another computer directly, or never connected to two or more switches.
Switches are connected via cables to form a tree (a connected undirected graph with no cycles).
No switches are ‘useless.’ In other words, each switch is on the path between at least one pair
of computers.
</p>
<p>
All in all, computers and switches together form a tree whose leaves are computers and whose
internal nodes switches (See Figure 9).
</p>
<p>
Gilbert measures the distances between <i>all pairs of computers</i>. The distance between two com-
puters is simply the number of switches on the path between the two, plus one. Or equivalently,
it is the number of cables used to connect them. You may wonder how Gilbert can actually
obtain these distances solely based on measurement. Well, he can do so by a very sophisticated
statistical processing technique he invented. Please do not ask the details.
</p>
<p>
You are therefore given a matrix describing distances between leaves of a tree. Your job is to
construct the tree from it.
</p>
<H2>Input</H2>
<p>
The input is a series of distance matrices, followed by a line consisting of a single '<span>0</span>'. Each
distance matrix is formatted as follows.
</p>
<pre>
<i>N</i>
<i>a</i><sub>11</sub> <i>a</i><sub>12</sub> ... <i>a</i><sub>1<i>N</i></sub>
<i>a</i><sub>21</sub> <i>a</i><sub>22</sub> ... <i>a</i><sub>2<i>N</i></sub>
. . . .
. . . .
. . . .
<i>a</i><sub><i>N</i>1</sub> <i>a</i><sub><i>N</i>2</sub> ... <i>a</i><sub><i>N</i><i>N</i></sub>
</pre>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_networkMess">
</center>
<br>
<p>
<i>N</i> is the size, i.e. the number of rows and the number of columns, of the matrix. <i>a<sub>ij</sub></i> gives the
distance between the <i>i</i>-th leaf node (computer) and the <i>j</i>-th. You may assume 2 ≤ <i>N</i> ≤ 50 and
the matrix is symmetric whose diagonal elements are all zeros. That is, <i>a<sub>ii</sub></i> = 0 and <i>a<sub>ij</sub></i> = <i>a<sub>ji</sub></i>
for each <i>i</i> and <i>j</i>. Each non-diagonal element <i>a<sub>ij</sub></i> (<i>i</i> ≠ <i>j</i>) satisfies 2 ≤ <i>a<sub>ij</sub></i> ≤ 30. You may assume
there is always a solution. That is, there is a tree having the given distances between leaf nodes.
</p>
<H2>Output</H2>
<p>
For each distance matrix, find a tree having the given distances between leaf nodes. Then output
the degree of each internal node (i.e. the number of cables adjoining each switch), all in a single
line and in ascending order. Numbers in a line should be separated by a single space. A line
should not contain any other characters, including trailing spaces.
</p>
<H2>Sample Input</H2>
<pre>
4
0 2 2 2
2 0 2 2
2 2 0 2
2 2 2 0
4
0 2 4 4
2 0 4 4
4 4 0 2
4 4 2 0
2
0 12
12 0
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2 3 3
2 2 2 2 2 2 2 2 2 2 2
</pre>
|
p01750 |
<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>
<p>
すぬけ君は,誕生日プレゼントとして辺の長さが <var>l<sub>1</sub> × . . . × l<sub>d</sub></var> の <var>d</var> 次元超直方体をもらった.すぬけ君は,この直方体を <var>i</var> 番目の座標の範囲が 0 以上 <var>l<sub>i</sub></var> 以下となるようにおき,<var>x<sub>1</sub> + . . . + x<sub>d</sub> ≤ s</var> をみたす部分を食べてしまった.ただし <var>x<sub>i</sub></var> は <var>i</var> 番目の座標を表す.すぬけ君の食べた部分の体積を <var>V</var> とすると,<var>d!V</var> (<var>V</var> に <var>d</var> の階乗をかけた値) は整数となることが証明できる.<var>d!V</var> を1,000,000,007 で割ったあまりを求めよ.
</p>
<h2>Constraints</h2>
<ul>
<li> 2 ≤ <var>d</var> ≤ 300 </li>
<li> 1 ≤ <var>l<sub>i</sub></var> ≤ 300</li>
<li> 0 ≤ <var>s</var> ≤ $\sum l_{i}$</li>
<li> 入力は全て整数である</li>
</ul>
<h2>Input</h2>
<pre>
<var>d</var>
<var>l<sub>1</sub></var>
. . .
<var>l<sub>d</sub></var>
<var>s</var>
</pre>
<h2>Output</h2>
<p>
<var>d!V</var> を 1,000,000,007 で割ったあまりを出力せよ.
</p>
<h2>Sample Input 1</h2>
<pre>
2
6
3
4
</pre>
<h2>Sample Output 1</h2>
<pre>
15
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummer2014_hyperrectangle" title="Hyperrectangle" alt="Hyperrectangle" width="200">
<h2>Sample Input 2</h2>
<pre>
5
12
34
56
78
90
123
</pre>
<h2>Sample Output 2</h2>
<pre>
433127538
</pre>
|
p03297 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo Mart, a convenience store, sells apple juice.</p>
<p>On the opening day of Ringo Mart, there were <var>A</var> cans of juice in stock in the morning.
Snuke buys <var>B</var> cans of juice here every day in the daytime.
Then, the manager checks the number of cans of juice remaining in stock every night.
If there are <var>C</var> or less cans, <var>D</var> new cans will be added to the stock by the next morning.</p>
<p>Determine if Snuke can buy juice indefinitely, that is, there is always <var>B</var> or more cans of juice in stock when he attempts to buy them.
Nobody besides Snuke buy juice at this store.</p>
<p>Note that each test case in this problem consists of <var>T</var> queries.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq T \leq 300</var></li>
<li><var>1 \leq A, B, C, D \leq 10^{18}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>T</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var> <var>D_1</var>
<var>A_2</var> <var>B_2</var> <var>C_2</var> <var>D_2</var>
<var>:</var>
<var>A_T</var> <var>B_T</var> <var>C_T</var> <var>D_T</var>
</pre>
<p>In the <var>i</var>-th query, <var>A = A_i, B = B_i, C = C_i, D = D_i</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>T</var> lines. The <var>i</var>-th line should contain <code>Yes</code> if Snuke can buy apple juice indefinitely in the <var>i</var>-th query; <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
</pre>
<p>In the first query, the number of cans of juice in stock changes as follows: (D represents daytime and N represents night.)</p>
<p><var>9</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>2</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>11</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>4</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>13</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>6</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>6</var>
<ruby><rb>→</rb><rt>D</rt></ruby> x</p>
<p>In the second query, the number of cans of juice in stock changes as follows:</p>
<p><var>9</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>2</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>11</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>4</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>13</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>6</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>15</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>8</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>8</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>1</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>10</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>3</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>12</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>5</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>14</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>7</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>7</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>0</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>9</var>
<ruby><rb>→</rb><rt>D</rt></ruby> <var>2</var>
<ruby><rb>→</rb><rt>N</rt></ruby> <var>11</var>
<ruby><rb>→</rb><rt>D</rt></ruby> …</p>
<p>and so on, thus Snuke can buy juice indefinitely.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
</pre></section>
</div>
</span> |
p03002 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence of positive integers of length <var>N</var>, <var>A=a_1,a_2,…,a_{N}</var>, and an integer <var>K</var>.
How many contiguous subsequences of <var>A</var> satisfy the following condition?</p>
<ul>
<li>(Condition) The sum of the elements in the contiguous subsequence is at least <var>K</var>.</li>
</ul>
<p>We consider two contiguous subsequences different if they derive from different positions in <var>A</var>, even if they are the same in content.</p>
<p>Note that the answer may not fit into a <var>32</var>-bit integer type.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a_i \leq 10^5</var></li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq K \leq 10^{10}</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of contiguous subsequences of <var>A</var> that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 10
6 1 2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The following two contiguous subsequences satisfy the condition:</p>
<ul>
<li><var>A[1..4]=a_1,a_2,a_3,a_4</var>, with the sum of <var>16</var></li>
<li><var>A[2..4]=a_2,a_3,a_4</var>, with the sum of <var>10</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5
3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Note again that we consider two contiguous subsequences different if they derive from different positions, even if they are the same in content.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 53462
103 35322 232 342 21099 90000 18843 9010 35221 19352
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>36
</pre></section>
</div>
</span> |
p01195 |
<H1><font color="#000"></font>Philosopher's Stone</H1>
<!-- Problem G-->
<p>
In search for wisdom and wealth, Alchemy, the art of transmutation, has long been pursued by people.
The crucial point of Alchemy was considered to find the recipe for <i>philosopher’s stone</i>, which will be a
catalyst to produce gold and silver from common metals, and even medicine giving eternal life.
</p>
<p>
Alchemists owned Alchemical Reactors, symbols of their profession. Each recipe of Alchemy went like
this: gather appropriate materials; melt then mix them in your Reactor for an appropriate period; then
you will get the desired material along with some waste.
</p>
<p>
A long experience presented two natural laws, which are widely accepted among Alchemists. One is the
law of conservation of mass, that is, no reaction can change the total mass of things taking part. Because
of this law, in any Alchemical reaction, mass of product is not greater than the sum of mass of materials.
The other is the law of the directionality in Alchemical reactions. This law implies, if the matter A
produces the matter B, then the matter A can never be produced using the matter B.
</p>
<p>
One night, Demiurge, the Master of Alchemists, revealed the recipe of philosopher’s stone to have every
Alchemist’s dream realized. Since this night, this ultimate recipe, which had been sought for centuries,
has been an open secret.
</p>
<p>
Alice and Betty were also Alchemists who had been seeking the philosopher’s stone and who were told
the ultimate recipe in that night. In addition, they deeply had wanted to complete the philosopher’s stone
earlier than any other Alchemists, so they began to solve the way to complete the recipe in the shortest
time.
</p>
<p>
Your task is write a program that computes the smallest number of days needed to complete the philoso-
pher’s stone, given the recipe of philosopher’s stone and materials in their hands.
</p>
<H2>Input</H2>
<p>
The input consists of a number of test cases.
</p>
<p>
Each test case starts with a line containing a single integer <i>n</i>, then <i>n</i> recipes follow.
</p>
<p>
Each recipe starts with a line containing a string, the name of the product. Then a line with two integers
<i>m</i> and <i>d</i> is given, where <i>m</i> is the number of materials and <i>d</i> is the number of days needed to finish the
reaction. Each of the following <i>m</i> lines specify the name and amount of a material needed for reaction.
</p>
<p>
Those <i>n</i> recipes are followed by a list of materials the two Alchemists initially have. The first line
indicates the size of the list. Then pairs of the material name and the amount are given, each pair in one
line.
</p>
<p>
Every name contains printable characters of the ASCII code, i.e. no whitespace or control characters.
No two recipe will produce the item of the same name. Each test case always include one recipe for
“philosopher’s-stone,” which is wanted to be produced. Some empty lines may occur in the input
for human-readability.
</p>
<H2>Output</H2>
<p>
For each case, output a single line containing the shortest day needed to complete producing the philoso-
pher’s stone, or “impossible” in case production of philosopher’s stone is impossible.
</p>
<p>
As there are two Alchemists, they can control two reaction in parallel. A reaction can start whenever the
materials in recipe and at least one Alchemist is available. Time spent in any acts other than reaction,
such as rests, meals, cleaning reactors, or exchanging items, can be regarded as negligibly small.
</p>
<H2>Sample Input</H2>
<pre>
3
philosopher’s-stone
4 10
tongue 1
tear 1
dunkelheit 1
aroma-materia 1
aroma-materia
4 5
solt 1
holy-water 1
golden-rock 1
neutralizer 2
neutralizer
1 1
red-rock 5
7
tongue 1
tear 1
dunkelheit 1
solt 2
holy-water 3
golden-rock 2
red-rock 10
2
philosopher’s-stone
5 3
ninjin 1
jagaimo 3
tamanegi 1
barmont 12
barmont
3 1
curry 5
komugiko 20
batar 10
7
ninjin 3
jagaimo 2
tamanegi 5
curry 150
komugiko 750
batar 200
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
16
impossible
</pre>
|
p03452 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people standing on the <var>x</var>-axis.
Let the coordinate of Person <var>i</var> be <var>x_i</var>.
For every <var>i</var>, <var>x_i</var> is an integer between <var>0</var> and <var>10^9</var> (inclusive).
It is possible that more than one person is standing at the same coordinate.</p>
<p>You will given <var>M</var> pieces of information regarding the positions of these people.
The <var>i</var>-th piece of information has the form <var>(L_i, R_i, D_i)</var>.
This means that Person <var>R_i</var> is to the right of Person <var>L_i</var> by <var>D_i</var> units of distance, that is, <var>x_{R_i} - x_{L_i} = D_i</var> holds.</p>
<p>It turns out that some of these <var>M</var> pieces of information may be incorrect.
Determine if there exists a set of values <var>(x_1, x_2, ..., x_N)</var> that is consistent with the given pieces of information.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var> <var>000</var></li>
<li><var>0 \leq M \leq 200</var> <var>000</var></li>
<li><var>1 \leq L_i, R_i \leq N</var> (<var>1 \leq i \leq M</var>)</li>
<li><var>0 \leq D_i \leq 10</var> <var>000</var> (<var>1 \leq i \leq M</var>)</li>
<li><var>L_i \neq R_i</var> (<var>1 \leq i \leq M</var>)</li>
<li>If <var>i \neq j</var>, then <var>(L_i, R_i) \neq (L_j, R_j)</var> and <var>(L_i, R_i) \neq (R_j, L_j)</var>.</li>
<li><var>D_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>L_1</var> <var>R_1</var> <var>D_1</var>
<var>L_2</var> <var>R_2</var> <var>D_2</var>
<var>:</var>
<var>L_M</var> <var>R_M</var> <var>D_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists a set of values <var>(x_1, x_2, ..., x_N)</var> that is consistent with all given pieces of information, print <code>Yes</code>; if it does not exist, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2 1
2 3 1
1 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Some possible sets of values <var>(x_1, x_2, x_3)</var> are <var>(0, 1, 2)</var> and <var>(101, 102, 103)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2 1
2 3 1
1 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>If the first two pieces of information are correct, <var>x_3 - x_1 = 2</var> holds, which is contradictory to the last piece of information.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 3
2 1 1
2 3 5
3 4 2
</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>10 3
8 7 100
7 9 100
9 8 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>100 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> |
p03901 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Aoki is in search of Takahashi, who is missing in a one-dimentional world.
Initially, the coordinate of Aoki is <var>0</var>, and the coordinate of Takahashi is known to be <var>x</var>, but his coordinate afterwards cannot be known to Aoki.</p>
<p>Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneously:</p>
<ul>
<li>
<p>Let the current coordinate of Aoki be <var>a</var>, then Aoki moves to a coordinate he selects from <var>a-1</var>, <var>a</var> and <var>a+1</var>.</p>
</li>
<li>
<p>Let the current coordinate of Takahashi be <var>b</var>, then Takahashi moves to the coordinate <var>b-1</var> with probability of <var>p</var> percent, and moves to the coordinate <var>b+1</var> with probability of <var>100-p</var> percent.</p>
</li>
</ul>
<p>When the coordinates of Aoki and Takahashi coincide, Aoki can find Takahashi.
When they pass by each other, Aoki cannot find Takahashi.</p>
<p>Aoki wants to minimize the expected number of turns taken until he finds Takahashi. Find the minimum possible expected number of turns.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> ≦ <var>x</var> ≦ <var>1,000,000,000</var></li>
<li><var>1</var> ≦ <var>p</var> ≦ <var>100</var></li>
<li><var>x</var> and <var>p</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>200</var> points, <var>p=100</var>.</li>
<li>In the test set worth <var>300</var> points, <var>x</var> ≦ <var>10</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>x</var>
<var>p</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible expected number of turns.
The output is considered correct if the absolute or relative error is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2.0000000
</pre>
<p>Takahashi always moves by <var>-1</var>.
Thus, by moving to the coordinate <var>1</var> in the <var>1</var>-st turn and staying at that position in the <var>2</var>-nd turn, Aoki can find Takahashi in <var>2</var> turns.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7.5000000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>101
80
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>63.7500000
</pre></section>
</div>
</span> |
p02613 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.</p>
<p>The problem has <var>N</var> test cases.</p>
<p>For each test case <var>i</var> (<var>1\leq i \leq N</var>), you are given a string <var>S_i</var> representing the verdict for that test case. Find the numbers of test cases for which the verdict is <code>AC</code>, <code>WA</code>, <code>TLE</code>, and <code>RE</code>, respectively.</p>
<p>See the Output section for the output format.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>S_i</var> is <code>AC</code>, <code>WA</code>, <code>TLE</code>, or <code>RE</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_1</var>
<var>\vdots</var>
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Let <var>C_0</var>, <var>C_1</var>, <var>C_2</var>, and <var>C_3</var> be the numbers of test cases for which the verdict is <code>AC</code>, <code>WA</code>, <code>TLE</code>, and <code>RE</code>, respectively. Print the following:</p>
<pre>AC x <var>C_0</var>
WA x <var>C_1</var>
TLE x <var>C_2</var>
RE x <var>C_3</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
AC
TLE
AC
AC
WA
TLE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>AC x 3
WA x 1
TLE x 2
RE x 0
</pre>
<p>We have <var>3</var>, <var>1</var>, <var>2</var>, and <var>0</var> test case(s) for which the verdict is <code>AC</code>, <code>WA</code>, <code>TLE</code>, and <code>RE</code>, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
AC
AC
AC
AC
AC
AC
AC
AC
AC
AC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>AC x 10
WA x 0
TLE x 0
RE x 0
</pre></section>
</div>
</span> |
p01896 |
<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>F: 紙の折りたたみ / Folding Paper</h1>
<h2>問題文</h2>
<p>
高さ $H$ マス、幅 $W$ マスの格子状に区切られた長方形の紙がある。
$0$ から数えて上から $i$ 行目、左から $j$ 列目のマスには整数 $i \times W+j$ が書かれている。 $H=2, W=3$ の例を下の図に示す。
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day1RUPC_image02" width="180" height="120">
<p>
AOR イカちゃんは、この紙に対して次のような操作を順に行った。
</p>
<ol>
<li>
$1$ マス分の面積になるまでマスの区切り線に沿って繰り返し折る。この時の折る線や山谷、順番などは任意である。紙を破らない任意の折り方ができる。
</li>
<li>
$4$ 辺を切り落として $H \times W$ 枚の紙に分割する。
</li>
<li>
上から順にめくっていき、書かれていた整数を並べた数列 $S$ を作る。
</li>
</ol>
<p>
例えば、下の図のように折った後切った場合、$S$ として $4, 3, 0, 5, 2, 1$ が得られる。このように、間に差し込むような折り方も可能である。
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day1RUPC_image00" width="600" height="150">
<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day1RUPC_image01" width="200" height="200">
<p>
あなたは AOR イカちゃんから数列 $S$ を受け取った。
しかし、AOR イカちゃんのことを信用していないので、これが本物か確かめたい。
$S$ と一致するような紙の折り方が存在するなら "YES" を、しないなら "NO" を出力するプログラムを書け。
</p>
<h2>入力</h2>
<p>
$H \ W$<br>
$S_0 \cdots S_{HW-1}$<br>
</p>
<h2>入力の制約</h2>
<p>
$1 \le H, W \le 500$<br>
$S$ は $0$ から $H \times W - 1$ までの整数を $1$ つずつ含む<br>
</p>
<h2>出力</h2>
"YES" または "NO" を $1$ 行で出力せよ。
<h2>サンプル</h2>
<h3>サンプル入力1</h3>
<pre>
1 4
0 1 2 3
</pre>
<h3>サンプル出力1</h3>
<pre>
YES
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day1RUPC_image03" width="600" height="150">
<h3>サンプル入力2</h3>
<pre>
2 3
4 3 0 5 2 1
</pre>
<h3>サンプル出力2</h3>
<pre>
YES
</pre>
<p>
問題文中の例である。
</p>
<h3>サンプル入力3</h3>
<pre>
1 4
0 2 1 3
</pre>
<h3>サンプル出力3</h3>
<pre>
NO
</pre>
<h3>サンプル入力4</h3>
<pre>
2 2
0 1 3 2
</pre>
<h3>サンプル出力4</h3>
<pre>
YES
</pre>
<p>
$2$ 回半分に折る。
</p>
|
p00784 |
<H1><font color="#000">Problem E:</font> Pipeline Scheduling</H1>
<p>
An <i>arithmetic pipeline</i> is designed to process more than one task simultaneously in an overlapping manner. It includes function units and data paths among them. Tasks are processed by <i>pipelining</i>: at each clock, one or more units are dedicated to a task and the output produced for the task at the clock is cascading to the units that are responsible for the next stage; since each unit may work in parallel with the others at any clock, more than one task may be being processed at a time by a single pipeline.
</p>
<p>
In this problem, a pipeline may have a feedback structure, that is, data paths among function units may have directed loops as shown in the next figure.
</p>
<center>
<b>Example of a feed back pipeline</b><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pipeline1">
</center>
<p>
Since an arithmetic pipeline in this problem is designed as special purpose dedicated hardware, we assume that it accepts just a single sort of task. Therefore, the timing information of a pipeline is fully described by a simple table called a <i>reservation table</i>, which specifies the function units that are busy at each clock when a task is processed without overlapping execution.
</p>
<center>
<b>Example of a "reservation table"</b><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pipeline2">
</center>
<p>
In reservation tables, 'X' means "the function unit is busy at that clock" and '.' means "the function unit is not busy at that clock." In this case, once a task enters the pipeline, it is processed by unit0 at the first clock, by unit1 at the second clock, and so on. It takes seven clock cycles to perform a task.
</p>
<p>
Notice that no special hardware is provided to avoid simultaneous use of the same function unit.
</p>
<p>
Therefore, a task must not be started if it would conflict with any tasks being processed. For instance, with the above reservation table, if two tasks, say task 0 and task 1, were started at clock 0 and clock 1, respectively, a conflict would occur on unit0 at clock 5. This means that you should not start two tasks with single cycle interval. This invalid schedule is depicted in the following process table, which is obtained by overlapping two copies of the reservation table with one being shifted to the right by 1 clock.
</p>
<center>
<b>Example of a "conflict"</b><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pipeline3"><br>
<p>
('0's and '1's in this table except those in the first row represent tasks 0 and 1, respectively, and 'C' means the conflict.)
</p>
</center>
<p>
Your job is to write a program that reports the minimum number of clock cycles in which the given pipeline can process 10 tasks.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets, each representing the reservation table of a pipeline. A data set is given in the following format.
</p>
<pre>
<i>n</i>
<i>x</i><sub>0,0</sub> <i>x</i><sub>0,1</sub> ... <i>x</i><sub>0,n-1</sub>
<i>x</i><sub>1,0</sub> <i>x</i><sub>1,1</sub> ... <i>x</i><sub>1,n-1</sub>
<i>x</i><sub>2,0</sub> <i>x</i><sub>2,1</sub> ... <i>x</i><sub>2,n-1</sub>
<i>x</i><sub>3,0</sub> <i>x</i><sub>3,1</sub> ... <i>x</i><sub>3,n-1</sub>
<i>x</i><sub>4,0</sub> <i>x</i><sub>4,1</sub> ... <i>x</i><sub>4,n-1</sub>
</pre>
<p>
The integer <i>n</i> (< 20) in the first line is the width of the reservation table, or the number of clock cycles that is necessary to perform a single task. The second line represents the usage of unit0, the third line unit1, and so on. <i>x<sub>i,j</sub></i> is either 'X' or '.'. The former means <i>reserved</i> and the latter <i>free</i>. There are no spaces in any input line. For simplicity, we only consider those pipelines that consist of 5 function units. The end of the input is indicated by a data set with 0 as the value of <i>n</i>.
</p>
<H2>Output</H2>
<p>
For each data set, your program should output a line containing an integer number that is the minimum number of clock cycles in which the given pipeline can process 10 tasks.
</p>
<H2>Sample Input</H2>
<pre>
7
X...XX.
.X.....
..X....
...X...
......X
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
34
</pre>
<p>
In this sample case, it takes 41 clock cycles process 10 tasks if each task is started as early as possible under the condition that it never conflicts with any previous tasks being processed.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pipeline4"><br>
<p>(The digits in the table except those in the clock row represent the task number.)</p>
</center>
<p>
However, it takes only 34 clock cycles if each task is started at every third clock.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pipeline5"><br>
<p>(The digits in the table except those in the clock row represent the task number.)</p>
</center>
<p>
This is the best possible schedule and therefore your program should report 34 in this case.
</p>
|
p02243 |
<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>Single Source Shortest Path II</H1>
<p>
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.
</p>
<H2>Input</H2>
<p>
In the first line, an integer $n$ denoting the number of vertices in $G$ is given. In the following $n$ lines, adjacency lists for each vertex $u$ are respectively given in the following format:
</p>
<p>
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
</p>
<p>
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge connecting $u$ and $v_i$ (from $u$ to $v_i$).
</p>
<H2>Output</H2>
<p>
For each vertex, print its ID and the distance separated by a space character in a line respectively. Print in order of vertex IDs.
</p>
<H2>Constraints</H2>
<ul>
<li>$1 \leq n \leq 10,000$</li>
<li>$0 \leq c_i \leq 100,000$</li>
<li>$|E| < 500,000$</li>
<li>All vertices are reachable from vertex $0$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
</pre>
<H2>Sample Output 1</H2>
<pre>
0 0
1 2
2 2
3 1
4 3
</pre>
<br>
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p> |
p01879 |
<h2>H: われわれの努力について - About Our Effort -</h2>
<h3>問題</h3>
<p>※この問題はおまけの問題と捉えていただけるとありがたく、<a href="http://birthday0410.contest.atcoder.jp/tasks/birthday0410_x">できれば先に他の問題のほうをお楽しみいただければと思っておりまして,ですので他の問題を通し終えて暇になり,かつその暇を</a>このコンテストで潰そうという気になってくれた方に挑戦していただければと思います。</p>
<p>
D問題のクエリが遅くてすみませんでした。
しかし我々といたしましても決してただ怠慢をしていたわけではないのです。
私たちなりに努力したのです。
その努力の片鱗を味わっていただくため、このような問題を出題した次第であります。
</p>
<p>問題: D問題のサーバー側の処理をするプログラムを作成せよ。</p>
<p>なおこの問題は本当にD問題の要求を満たすプログラムを作成することが目標ということですので、言語による向き/不向きなどは一切考慮いたしませんのであしからず。最速実行速度を達成された方はもれなくAOJに収録される際にジャッジプログラムとして採用される可能性がありますのでぜひ挑戦下さい。</p>
<h3>入力形式</h3>
<p>入力は以下の形式で与えられる。</p>
<pre>
<var>N</var>
<var>p_1</var> ... <var>p_N</var>
<var>Q</var>
<var>l_1</var> <var>r_1</var>
...
<var>l_Q</var> <var>r_Q</var>
</pre>
<p>1行目では順列<var>p</var>の長さ<var>N</var>が与えられる。2行目では順列<var>p</var>を表す<var>N</var>個の整数が空白区切りで与えられる。3行目ではクエリの数を表す整数<var>Q</var>が与えられる。続く<var>Q</var>行の<var>i</var>行目は空白区切りの2つの整数<var>l_i</var>, <var>r_i</var>からなり、クエリが区間<var>[l_i, r_i]</var>のコンプレックス度を聞くものであることを表す。</p>
<p>入力は以下の制約を満たす。</p>
<ul>
<li><var>1 \≤ N \≤ 100,000</var></li>
<li><var>1 \≤ p_i \≤ N</var>, <var>p_i \neq p_j (i \neq j)</var></li>
<li><var>1 \≤ Q \≤ 200,000</var></li>
<li><var>1 \≤ l_i \≤ r_i \≤ N</var></li>
</ul>
<h3>出力形式</h3>
<p><var>Q</var>個の各クエリ<var>i</var>に関して、<var>p</var>の区間<var>[l_i, r_i]</var>のコンプレックス度を<var>i</var>行目に出力せよ。ただし、<var>p</var>の区間<var>[l_i, r_i]</var>のコンプレックス度とは、<var>(\{ (i, j) | p_i > p_j</var> <var>{\rm for}</var> <var>l \≤ i<j \≤ r \}の要素数)</var>と定義される。</p>
<h3>入力例1</h3>
<pre>
4
4 1 3 2
2
1 3
2 4
</pre>
<h3>出力例1</h3>
<pre>
2
1
</pre>
<h3>入力例2</h3>
<pre>
1
1
1
1 1
</pre>
<h3>出力例2</h3>
<pre>0</pre> |
p03844 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino wants to evaluate the formula "<var>A</var> <var>op</var> <var>B</var>".
Here, <var>A</var> and <var>B</var> are integers, and the binary operator <var>op</var> is either <code>+</code> or <code>-</code>.
Your task is to evaluate the formula instead of her.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦A,B≦10^9</var></li>
<li><var>op</var> is either <code>+</code> or <code>-</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>op</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Evaluate the formula and print the result.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 + 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Since <var>1 + 2 = 3</var>, the output should be <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 - 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-2
</pre></section>
</div>
</span> |
p02756 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has a string <var>S</var> consisting of lowercase English letters.</p>
<p>Starting with this string, he will produce a new one in the procedure given as follows.</p>
<p>The procedure consists of <var>Q</var> operations. In Operation <var>i</var> <var>(1 \leq i \leq Q)</var>, an integer <var>T_i</var> is provided, which means the following:</p>
<ul>
<li>
<p>If <var>T_i = 1</var>: reverse the string <var>S</var>.</p>
</li>
<li>
<p>If <var>T_i = 2</var>: An integer <var>F_i</var> and a lowercase English letter <var>C_i</var> are additionally provided.</p>
<ul>
<li>If <var>F_i = 1</var> : Add <var>C_i</var> to the beginning of the string <var>S</var>.</li>
<li>If <var>F_i = 2</var> : Add <var>C_i</var> to the end of the string <var>S</var>.</li>
</ul>
</li>
</ul>
<p>Help Takahashi by finding the final string that results from the procedure.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
<li><var>1 \leq Q \leq 2 \times 10^5</var></li>
<li><var>T_i = 1</var> or <var>2</var>.</li>
<li><var>F_i = 1</var> or <var>2</var>, if provided.</li>
<li><var>C_i</var> is a lowercase English letter, if provided.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>Q</var>
<var>Query_1</var>
<var>:</var>
<var>Query_Q</var>
</pre>
<p>In the <var>3</var>-rd through the <var>(Q+2)</var>-th lines, <var>Query_i</var> is one of the following:</p>
<pre><var>1</var>
</pre>
<p>which means <var>T_i = 1</var>, and:</p>
<pre><var>2</var> <var>F_i</var> <var>C_i</var>
</pre>
<p>which means <var>T_i = 2</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the resulting string.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>a
4
2 1 p
1
2 2 c
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>cpa
</pre>
<p>There will be <var>Q = 4</var> operations. Initially, <var>S</var> is <code>a</code>.</p>
<ul>
<li>
<p>Operation <var>1</var>: Add <code>p</code> at the beginning of <var>S</var>. <var>S</var> becomes <code>pa</code>.</p>
</li>
<li>
<p>Operation <var>2</var>: Reverse <var>S</var>. <var>S</var> becomes <code>ap</code>.</p>
</li>
<li>
<p>Operation <var>3</var>: Add <code>c</code> at the end of <var>S</var>. <var>S</var> becomes <code>apc</code>.</p>
</li>
<li>
<p>Operation <var>4</var>: Reverse <var>S</var>. <var>S</var> becomes <code>cpa</code>.</p>
</li>
</ul>
<p>Thus, the resulting string is <code>cpa</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>a
6
2 2 a
2 1 b
1
2 2 c
1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>aabc
</pre>
<p>There will be <var>Q = 6</var> operations. Initially, <var>S</var> is <code>a</code>.</p>
<ul>
<li>
<p>Operation <var>1</var>: <var>S</var> becomes <code>aa</code>.</p>
</li>
<li>
<p>Operation <var>2</var>: <var>S</var> becomes <code>baa</code>.</p>
</li>
<li>
<p>Operation <var>3</var>: <var>S</var> becomes <code>aab</code>.</p>
</li>
<li>
<p>Operation <var>4</var>: <var>S</var> becomes <code>aabc</code>.</p>
</li>
<li>
<p>Operation <var>5</var>: <var>S</var> becomes <code>cbaa</code>.</p>
</li>
<li>
<p>Operation <var>6</var>: <var>S</var> becomes <code>aabc</code>.</p>
</li>
</ul>
<p>Thus, the resulting string is <code>aabc</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>y
1
2 1 x
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>xy
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.