question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03548 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a long seat of width <var>X</var> centimeters.
There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length <var>Y</var> centimeters.</p>
<p>We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least <var>Z</var> centimeters between two people, and between the end of the seat and a person.</p>
<p>At most how many people can sit on the seat?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq X, Y, Z \leq 10^5</var></li>
<li><var>Y+2Z \leq X</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var> <var>Z</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>13 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There is just enough room for three, as shown below:</p>
<div style="text-align: center;">
<img src="https://img.atcoder.jp/abc078/4a35302937c3cbc2f625156e7834d27f.png">
<p>Figure</p>
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>12 3 1
</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>100000 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>49999
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>64146 123 456
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>110
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>64145 123 456
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>109
</pre></section>
</div>
</span> |
p01575 |
<H1><font color="#000">Problem E:</font> Dungeon Master</H1>
<p>
Once upon a time, in a fantasy world far, far away, monsters dug caves and dungeons for adventurers. They put some obstacles in their caves so it becomes more difficult and more exciting for the adventurers to reach the goal.
</p>
<p>
One day, Emils, one of the monsters in the caves, had a question about the caves. How many patterns of a cave can they make, by changing the locations of the obstacles in it?
</p>
<p>
Here's the detail of the question. A cave consists of <i>W</i> × <i>H</i> squares. Monsters can put obstacles at some of the squares, so that adventurers can't go into them. The total number of obstacles is fixed, and there can't be two or more obstacles in one square. Adventurers enter the cave from the top-left square, and try to reach the bottom-right square. They can move from one square to any of the four adjacent squares, as long as there are no obstacles in the destination square. There must be at least one path between any two squares that don't have obstacles. There must be no obstacles in the top-left square, nor in right-bottom square. The question is, given the width <i>W</i> and height <i>H</i> of the cave, and the number <i>S</i> of obstacles, how many patterns of the caves the monsters can make. As the obstacles have the same look, they should not
be distinguished each other.
</p>
<p>
It was a very interesting mathematical question. Emils couldn't solve this question by himself, so he told it to his colleagues instead. None of them could answer to it, though. After that, the question soon got popular among the monsters working in the caves, and finally, they became unable to sleep well as they always thought about the question.
</p>
<p>
You are requested to write a program that answers to the question.
</p>
<H2>Input</H2>
<p>
The input has a line, containing three integers <i>W</i>, <i>H</i>, and <i>S</i>, separated by a space. <i>W</i> and <i>H</i> are the horizontal and vertical sizes of the cave, and <i>S</i> is the number of obstacles to put in the cave. It is guaranteed that 2 ≤ <i>W</i>, <i>H</i> ≤ 8, and that 0 ≤ <i>S</i> ≤ <i>W</i> × <i>H</i>.
</p>
<H2>Output</H2>
<p>
Output the number of patterns of the cave, in a line.
</p>
<H2>Sample Input 1</H2>
<pre>
2 2 2
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
0
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
2 2 1
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
2
</pre>
|
p01060 |
<h1>Product Sale Lines</h1>
<h2>Problem</h2>
<p>
ウニクロ卯月さんと目黒凛さんはSEARIGHT LIVE FESの物販に来ている。下図のように、物販列は二列からなり、横に<var>W</var>人、縦に<var>H</var>人並べる大きさでコの字の形をしている。列の先頭の人は買い物をした後に列からはけ、同じ列の後ろの人々はそれぞれ一人分ずつ列を詰める。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_B1" alt="picture of line" style="width: 80%;">
</center>
<p>
二人は最初に物販列の最後尾に隣同士で、それぞれ違う列に(下図オレンジと濃い青色の位置)並んでいる。二人はとても仲がよいため、常にできるだけ近くにいたい。しかし、人のはけ方は列によって違うため、違う列に並んでいる二人の位置は離れてしまう可能性がある。
</p>
<p>
あなたの仕事は、列のはけ方が与えられたとき、二人が隣同士になる回数を求めることである。
ただし、二人ともコの字の角にいる(上図の黒色の状態の)ときは、隣同士とみなさない。また、並んだ直後は隣同士に並んでいるが、これは数えない。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
<var>W</var> <var>H</var>
<var>N</var>
<var>p<sub>1</sub></var> <var>p<sub>2</sub></var> ... <var>p<sub>N</sub></var>
</pre>
<p>
1行目に列の大きさを表す整数<var>W</var>と<var>H</var>が空白区切りで与えられる。<var>W</var>はコの字の横に並べる外側の人数を、<var>H</var>は縦に並べる外側の人数を表す。2行目に人が一人どちらかの列からはける回数<var>N</var>が与えられる。3行目には列のはけ方についての情報<var>p<sub>1</sub></var>...<var>p<sub>N</sub></var>が空白区切りで与えられる。<var>p<sub>i</sub></var>に’0’または’1’であり、’0’のとき、外側の人が一人はけることを、’1’のとき内側の人が一人はけることを表す。ただし、ウニクロ卯月さんまたは目黒凛さんが列から出ることはない。
</p>
<h2>Constraints</h2>
<ul>
<li>4 ≤ <var>W</var> ≤ 100</li>
<li>4 ≤ <var>H</var> ≤ 100</li>
<li>0 ≤ <var>N</var> ≤ 100</li>
</ul>
<h2>Output</h2>
<p>二人が隣同士になる回数を一行に出力せよ。</p>
<h2>Sample Input 1</h2>
<pre>
11 11
5
0 0 0 0 0
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
11 11
5
0 0 1 1 1
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre> |
p01430 |
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script>
<h2>問題文</h2>
<p>ハコの魔女 H.N.ELLY はとある動画サイトの熱狂的なファンである.ハコの魔女の強さはその時々のその動画サイトからの転送速度に応じて変化するのではないかと<i>美樹さやか</i>は考えた.そこで動画サイトからハコの魔女の持つコンピュータまでの過去の転送速度 (=単位時間あたりのデータの転送量) を調べたい.</p>
<p>初期のインターネットのネットワークの構造とそれ以降のネットワークの構造の変化を表すクエリが与えられるので,各変化について変化した直後の動画サイトからハコの魔女の持つコンピュータまでの転送速度を求めよ.</p>
<p>インターネットは複数の転送装置からなるものと見なし,各々をつなぐ回線は双方向に情報を送ることができ,その転送速度の最大は <var>1</var> であるとする.また,ネットワークは常に動画サイトからハコの魔女へ送られるデータの転送速度を最大化するように運ぶものとする.</p>
<h2>入力形式</h2>
<p>入力は以下の形式で与えられる.</p>
<pre><var>
N\ E\ Q\\
F_1\ T_1\\
F_2\ T_2\\
…\\
F_E\ T_E\\
M_1\ A_1\ B_1\\
M_2\ A_2\ B_2\\
...\\
M_Q\ A_Q\ B_Q\\
</var></pre>
<p><var>N</var> は動画サイトとハコの魔女の持つコンピュータを含めた転送装置の数である.番号が <var>1</var> である転送装置は動画サイトであり,番号が <var>N</var> である転送装置はハコの魔女の持つコンピュータである.<var>E</var> は初期状態で接続されている転送装置の組み合わせの数であり,<var>Q</var> はインターネットが変化した回数である.初期のインターネットは <var>F_i</var> と <var>T_i</var> が転送速度 <var>1</var> で双方向に接続されていることを表す.</p>
<p>ネットワークの変化は時系列順に与えられ,<var>j</var> 番目の変化は <var>M_j</var> が <var>1</var> であれば <var>A_j,\ B_j</var> 間がつながれたことを表し,<var>M_j</var> が <var>2</var> であれば <var>A_j,\ B_j</var> 間の接続が切れたことを表す.</p>
<h2>出力形式</h2>
<p>各変化の直後における,動画サイトからハコの魔女の持つコンピュータまでの転送速度を出力せよ.</p>
<h2>制約</h2>
<ul>
<li><var>2 \leq N \leq 500</var></li>
<li><var>0 \leq E \leq 20,000</var></li>
<li><var>1 \leq Q \leq 1,000</var></li>
<li><var>1 \leq F_i \leq N,\ 1 \leq T_i \leq N,\ F_i \neq T_i \ (1 \leq i \leq E)</var></li>
<li>すべての <var>\{F_i, T_i\}</var> のペアは異なる.</li>
<li><var>1 \leq M_j \leq 2,\ 1 \leq A_j \leq N\ ,\ 1 \leq B_j \leq N\ ,\ A_j \neq B_j (1 \leq j \leq Q)</var></li>
<li>ネットワークのどの段階においても次のことが成り立つ : どの <var>2</var> つの転送装置の間も高々 <var>1</var> つの回線でしか繋がれていない.
<li><var>2</var> つの転送装置の間が既に繋がれている状態でそれらの間を接続するようなクエリが来たり,<var>2</var> つの転送装置の間が回線で繋がれていない状態でそれらの間の接続を切るようなクエリが来ることはない.</li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>2 1 2
1 2
2 1 2
1 2 1</pre>
<h3>出力例1</h3>
<pre>
0
1
</pre>
<p>最初の変化の後,ハコの魔女のコンピュータと動画サイトは繋がらなくなっているので転送速度は <var>0</var> である.</p>
<p><var>2</var> 度目の変化の後は両者は直接繋がっており,転送速度は <var>1</var> になる.</p>
<h3>入力例 2</h3>
<pre>3 0 4
1 2 3
1 2 1
1 3 1
2 2 3</pre>
<h3>出力例 2</h3>
<pre>0
1
2
1</pre>
<h3>入力例 3</h3>
<pre>6 4 8
1 2
1 3
4 6
5 6
1 2 4
1 3 5
1 2 5
1 3 4
2 2 4
2 3 5
1 2 4
2 2 1</pre>
<h3>出力例 3</h3>
<pre>1
2
2
2
2
2
2
1</pre>
<h3>入力例 4</h3>
<pre>12 38 6
1 2
1 3
1 4
1 5
2 3
2 4
2 5
2 6
2 7
2 8
2 12
3 4
3 5
3 6
3 7
3 8
4 5
4 6
4 7
4 8
5 6
5 7
5 8
6 7
6 8
6 9
6 10
6 12
7 8
7 9
7 10
8 9
8 10
9 10
9 11
9 12
10 11
11 12
2 6 12
2 9 12
1 9 12
1 6 12
2 6 12
1 6 12</pre>
<h3>出力例 4</h3>
<pre>3
2
3
4
3
4</pre>
<hr>
<address>Problem Setter: Flat35</address> |
p00671 |
<h1>Problem C: Live Schedule</h1>
<p>
YOKARI TAMURAは全国的に有名なアーティストである。今月YOKARIは D 日間にわたってライブツアーを行う。ツアーのスケジュールの決定においてこの国を C 種類の地域でわける。YOKARIがある地域でライブを行うことにより利益を得られ、これは正の整数で表される。YOKARIは原則として 1 日に最大 1 つまでライブを行う。ただし、ある地域でライブを行った後、隣接する地域でライブを行える場合はその地域で同じ日に再びライブを行うことができる。この条件を満たす限り、地域を移動しながら何度もライブを行うことができる。また、同じ日に同じ地域でライブを 2 度以上行うことはできない。さらに、同じ日に 2 回以上のライブを行う日の数はツアー期間中合計 X 以下でなければならない。
</p>
<p>
あなたはYOKARIの関係者であり、彼女のライブツアーのスケジュールを仮決めしなくてはならない。どの日にどの地域でライブを行えばもっとも有益だろうか。ただし 1 回のライブごとにYOKARIには非負の整数で表される負担がかかり、ツアー期間中の合計負担は W 以内でなければならない。あなたの仕事は各ライブでYOKARIにかかる負担と期待される利益を読み込み、スケジュールを仮決めして、利益合計の最大値を出力することである。
</p>
<h2>Input</h2>
<p>
入力は複数のテストケースからなる。
ひとつのテストケースは以下の形式に従う。
</p>
<pre>
C D W X
E<sub>1,1</sub> E<sub>1,1</sub> … E<sub>1,D</sub>
E<sub>2,1</sub> E<sub>2,1</sub> … E<sub>2,D</sub>
…
E<sub>C,1</sub> E<sub>C,2</sub> … E<sub>C,D</sub>
F<sub>1,1</sub> F<sub>1,1</sub> … F<sub>1,D</sub>
F<sub>2,1</sub> F<sub>2,1</sub> … F<sub>2,D</sub>
…
F<sub>C,1</sub> F<sub>C,2</sub> … F<sub>C,D</sub>
</pre>
<p>
C は地域の種類数、D はツアー期間の長さ、W はこのツアーでYOKARIに許容される負担の合計の最大値、X はツアー期間中にライブを同じ日に 2 度以上行える合計日数の上限である。
E<sub>i,j</sub> ( 1 ≤ i ≤ C かつ 1 ≤ j ≤ D ) は地域 i で j 日目にライブを行うことで期待される利益である。E<sub>i,j</sub> が 0 のとき地域 i で j 日目にライブを行えないことを示す。
F<sub>i,j</sub> ( 1 ≤ i ≤ C かつ 1 ≤ j ≤ D ) は地域 i で j 日目にライブを行うことでYOKARIにかかる負担である。E<sub>i,j</sub> が 0 のとき、この値は0である。
地域 i は地域 i + 1 と i - 1 それぞれに隣接する。ただし地域 1 と地域 C ( C > 2 ) は隣接しない。
入力の終わりは、4個の0がそれぞれ一文字の空白で区切られる一行で示される。
</p>
<h2>Constraints</h2>
<ul>
<li>入力はすべて整数</li>
<li>1 ≤ C ≤ 15</li>
<li>1 ≤ D ≤ 30</li>
<li>0 ≤ W ≤ 50</li>
<li>0 ≤ X ≤ 5</li>
<li>0 ≤ E<sub>i,j</sub> ≤ 1,000</li>
<li>0 ≤ F<sub>i,j</sub> ≤ 10</li>
<li>テストケースの数は 100 を超えない。</li>
</ul>
<h2>Output</h2>
<p>
各ケースに付き、スケジュールを仮決めして期待される利益合計の最大値を 1 行に出力せよ。
</p>
<h2>Sample Input</h2>
<pre>
5 5 10 2
1 1 0 1 1
0 9 1 0 1
1 1 1 9 1
1 1 9 0 1
1 1 1 1 0
1 1 0 1 1
0 9 1 0 1
1 1 1 9 1
1 1 1 0 1
1 1 1 1 0
1 1 10 0
3
7
1 1 5 0
3
6
1 2 10 1
6 7
5 6
2 1 10 1
4
8
3
7
2 1 10 0
4
8
3
7
2 1 5 0
4
8
3
6
0 0 0 0
</pre>
<h2>Sample Output</h2>
<pre>
18
3
0
7
12
8
4
</pre> |
p01963 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>
Separate String
</H1>
<p>
You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$.
</p>
<p>
For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \{a, ab, b\}$.
</p>
<ul>
<li>$a,b,a,b$</li>
<li>$a,b,ab$</li>
<li>$ab,a,b$</li>
<li>$ab,ab$</li>
</ul>
<p>
Your task is to count the number of ways to separate $t$. Because the result can be large, you should output the remainder divided by $1,000,000,007$.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$
$s_1$
:
$s_N$
$t$
</pre>
<p>
The first line consists of an integer $N$ ($1 \leq N \leq 100,000$) which is the number of the elements of $S$. The following $N$ lines consist of $N$ distinct strings separated by line breaks. The $i$-th string $s_i$ represents the $i$-th element of $S$. $s_i$ consists of lowercase letters and the length is between $1$ and $100,000$, inclusive. The summation of length of $s_i$ ($1 \leq i \leq N$) is at most $200,000$. The next line consists of a string $t$ which consists of lowercase letters and represents the string to be separated and the length is between $1$ and $100,000$, inclusive.
</p>
<H2>Output</H2>
<p>
Calculate the number of ways to separate $t$ and print the remainder divided by $1,000,000,007$.
</p>
<H2>Sample Input 1</H2>
<pre>
3
a
b
ab
abab
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
4
</pre>
<H2>Sample Input 2</H2>
<pre>
3
a
b
c
xyz
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
0
</pre>
<H2>Sample Input 3</H2>
<pre>
7
abc
ab
bc
a
b
c
aa
aaabcbccababbc
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
160
</pre>
<H2>Sample Input 4</H2>
<pre>
10
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa
aaaaaaaaa
aaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
461695029
</pre>
|
p00221 |
<H1>FizzBuzz</H1>
<p>
「Fizz Buzz」と言われる数字を使ったゲームがあります。このゲームは複数のプレイヤーで数字を1 から順にひとつずつ数え上げていくもので、各プレイヤーは直前のプレイヤーが発言した次の数字をひとつだけ発言します。その時、3 で割り切れる場合は 「Fizz」, 5 で割り切れる場合は 「Buzz」、両者で割り切れる場合は「FizzBuzz」と数の代わりに発言しなければなりません。例えば、最初の 16 までの発言は以下のようになります。
</p>
<p>
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, ・・・
</p>
<p>
太郎君は友達と「Fizz Buzz」をして遊ぶことにしました。太郎君たちはルールを次のように決めました。 <br/>
<br/>
「間違えた人は脱落する。その次の人は間違えた数の次の数から始める。つまり、1, 2, 3 と発言した場合、3 で間違えたので次は 4 から始めることになる。」<br/>
<br/>
このルールに従ってゲームを行うのですが、ゲームに慣れていないため、間違えたことに気付かないことがあり、公平な判断ができません。そこであなたは太郎君たちがこのゲームを楽しめるように、決められた発言回数が終わった時点で残っていた人を出力するプログラムを作成することにしました。
</p>
<p>
プレイヤー数、ゲーム中に発言された回数、それぞれの発言を入力とし、入力が終わった時点で残っているプレイヤーの番号を小さい順に出力するプログラムを作成してください。ただし、プレイヤーには 1 から番号が割り振られており、発言順番も 1 番目のプレイヤーから順に行い、一通り発言が終わると、再度 1 番目のプレイヤーから発言することとします。順番の回ってきたプレイヤーが既に脱落している場合は、その次のプレイヤーが発言します。また、このプログラムは、プレイヤーが一人になった時点で、その後の発言を無視しなければなりません。
<!--また、入力が終わった時点では必ずプレイヤーの誰かが残っているものとします。-->
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>m</var> <var>n</var>
<var>s<sub>1</sub></var>
<var>s<sub>2</sub></var>
:
<var>s<sub>n</sub></var>
</pre>
<p>
1 行目にプレイヤー数 <var>m</var> (2 ≤ <var>m</var> ≤ 1000) と発言回数 <var>n</var> (1 ≤ <var>n</var> ≤ 10000) が与えられます。
</p>
<p>
続く <var>n</var> 行に <var>i</var> 番目の発言 <var>s<sub>1</sub></var> が与えられます。 <var>s<sub>i</sub></var> は整数、Fizz、Buzz、または FizzBuzz を示す文字列(8文字以下)です。
</p>
<!--
<p>
続く <var>n</var> 行に <var>i</var> 番目の発言 <var>s<sub>1</sub></var> が与えられます。 <var>s<sub>i</sub></var> は数字、Fizz、Buzz、FizzBuzz、あるいは間違った発言を示すその他の文字列 (20 文字以下) です。
</p>
-->
<p>
データセットの数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
入力データセットごとに、指定された発言回数まで入力されたときに残っているプレイヤーの番号を小さい順に出力します。
</p>
<H2>Sample Input</H2>
<pre>
5 7
1
2
Fizz
4
Buzz
6
7
3 5
1
2
3
4
5
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2 3 4 5
1
</pre>
|
p02836 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.</p>
<p>Given is a string <var>S</var>. Find the minimum number of hugs needed to make <var>S</var> palindromic.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>S</var> is a string consisting of lowercase English letters.</li>
<li>The length of <var>S</var> is between <var>1</var> and <var>100</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the minimum number of hugs needed to make <var>S</var> palindromic.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>redcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>For example, we can change the fourth character to <code>o</code> and get a palindrome <code>redooder</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>vvvvvv
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>We might need no hugs at all.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abcdabc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> |
p01719 |
<p>長年の研究の末、イクタ君は未来予知能力を手に入れた! 彼がこの研究に費やした時間や金銭は莫大なものであったが、ついに報われる時がやってきたのだ。手始めに金銭を取り戻すため、イクタ君は株式投資を始めることにした。
</p>
<p>
イクタ君は現在株式は全く保有しておらず、 <var>x</var> 円を所持している。彼が投資対象に定めた株式は <var>n</var> 種類で、それらについて今日から <var>d</var> 日分の株価を予知することに成功した。その結果、驚くべきことに今日から <var>d</var> 日間は日中の株価変動が全くないことが判明した。つまり、今日を1日目としたときの <var>i </var>(<var>1 ≤ i ≤ d</var>)日目の株式 <var>j</var> (<var>1 ≤ j ≤ n</var>)の株価 <var>p<sub>i,j</sub></var> 円がわかっている。イクタ君はそれぞれの日に自由に株式を売買できる。すなわち、任意の時点で以下の操作(購入・売却)を任意の順番で任意の回数行える。ただし、各操作の前後での所持金と株式の保有単位数は非負整数でなければならない。
</p>
<ul>
<li> 購入 : <var>i</var> 日目に、株式の種類 <var>j</var> (<var>1 ≤ j ≤ n</var>)を一つ選び、所持金 <var>p<sub>i,j</sub></var> 円を支払い1単位の株式 <var>j</var> を得る。
</li>
<li> 売却 : <var>i</var> 日目に、株式の種類 <var>j</var> (<var>1 ≤ j ≤ n</var>)を一つ選び、1単位の株式 <var>j</var> を支払い <var>p<sub>i,j</sub></var> 円を得る。
</li></ul>
<p>(彼が研究に没頭する間に証券取引システムは大きな発達を遂げ、取引手数料はかからなくなった。)
</p>
<p>イクタ君は大学で情報科学を修めていたが、未来予知研究に明け暮れるすえに大学で学んだことをすべて忘れてしまっていた。そんな彼の代わりに最終日の所持金を最大化するプログラムを書いてあげてほしい。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。
</p>
<pre>
<var>n</var> <var>d</var> <var>x</var> <br><var>p<sub>1,1</sub></var> ... <var>p<sub>1,n</sub></var><br>...<br><var>p<sub>d,1</sub></var> ... <var>p<sub>d,n</sub></var><br></pre>
<ul><li> <var>n</var> : 株式の種類数
</li><li> <var>d</var> : 日数
</li><li> <var>x</var> : 1日目の所持金
</li><li> <var>p<sub>i,j</sub></var> :<var> i </var>日目の銘柄<var>j</var>の株価(今日を1日目とする)
</li></ul>
<h3>Constraints</h3>
<p>入力中の各変数は以下の制約を満たす整数である。
</p>
<ul>
<li> <var>1 ≤ n ≤ 10</var>
</li>
<li> <var>1 ≤ d ≤ 10</var>
</li>
<li> <var>1 ≤ x, p<sub>i,j</sub> ≤ 10<sup>5</sup></var>
</li>
<li> 最終日の所持金が <var>10<sup>5</sup></var> 以下となることが保証されている。
</li>
</ul>
<h2>Output</h2>
<p>最適に投資した場合の最終日の所持金を1行に出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>2 2 5
3 2
5 4
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>9
</pre>
<ul><li>例えば、それぞれの株式を1単位ずつ購入します。
</li></ul>
<h2>Sample Input 2</h2>
<pre>1 2 5
6
10000
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>5
</pre>
<ul><li> 1単位より小さい取引はできません。小口投資家の悲哀です。
</li></ul>
<h2>Sample Input 3</h2>
<pre>2 3 5
4 5
6 3
8 5
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>11
</pre>
<ul><li> 1日目は1種類目の株式に、2日目は2種類目の株式に投資します。
</li></ul>
<h2>Sample Input 4</h2>
<pre>3 3 10
10 9 6
8 7 3
7 5 1
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>10
</pre>
<ul><li> 景気が悪い時もあります。
</li></ul> |
p03724 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.</p>
<p>First, Takahashi created a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var>, and wrote <var>0</var> at each edge.</p>
<p>Then, Aoki gave him <var>M</var> queries. The <var>i</var>-th of them is as follows:</p>
<ul>
<li>Increment the number written at each edge along the path connecting vertices <var>a_i</var> and <var>b_i</var>, by one.</li>
</ul>
<p>After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number.
However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries.</p>
<p>Determine whether there exists a tree that has the property mentioned by Takahashi.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ N ≤ 10^5</var></li>
<li><var>1 ≤ M ≤ 10^5</var></li>
<li><var>1 ≤ a_i,b_i ≤ N</var></li>
<li><var>a_i ≠ b_i</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
:
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if there exists a tree that has the property mentioned by Takahashi; print <code>NO</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
1 2
2 4
1 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>For example, Takahashi's graph has the property mentioned by him if it has the following edges: <var>1-2</var>, <var>1-3</var> and <var>1-4</var>.
In this case, the number written at every edge will become <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
1 2
3 5
5 1
3 4
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p01349 |
<H1>Problem A: Ennichi</H1>
<p>
縁日に来たうさぎが, ある出店のゲームの景品がキャロットケーキであるのを見つけた. このゲームのルールは以下の通りである.
</p>
<p>
縦h マス× 横w マスの格子状のフィールドがあり, 各マスにつき高々1 個のブロックが置かれる. 各ブロックにはアルファベット大文字(‘A’ - ‘Z’) のいずれかで表される色がついている. 同色のブロックが縦または横に一直線上にn 個以上連続して並ぶと, それらのブロックは消滅する.
</p>
<p>
参加者は横に隣り合う2 つのマスを選んで, それらの状態を互いに入れ替える操作ができる. ブロックの入れ替え, 消滅, 落下によってブロックの有るマスの1 つ下のマスにブロックが無くなると, このブロックは落下する. このときふたたび同色のブロックがn 個以上並ぶと消滅する. ただし, ブロックの消滅は, 落下するブロックが存在する間は起こらず, すべてのブロックの落下が終了したタイミングで同時に起こる.
</p>
<p>
1 回の操作でフィールド上のすべてのブロックを消滅させると, このゲームは成功となり景品のケーキを得ることができる. うさぎは1 回分の参加費で確実にケーキを手に入れたく, それができない場合は参加したくない. ゲーム開始時のフィールドの状態から, うさぎがこのゲームに参加すべきであるか答えよ.
</p>
<H2>Input</H2>
<p>
入力の一行目にはh, w, n がスペースで区切られて与えられる.
</p>
<p>
2 ≤ <i>h</i>,<i>w</i>, <i>n</i> ≤ 30
</p>
<p>
続く<i>h</i> 行にはフィールドの状態が上から順に与えられる. アルファベット大文字はブロックを, ‘.’ は空きマスを表す. 与えられるフィールドの状態には, 縦あるいは横に<i>n</i> 個以上連続する同色のブロックはなく, 落下する状態にあるブロックもない. 1 個以上のブロックが存在する.
</p>
<H2>Output</H2>
<p>
うさぎがこのゲームに参加すべきであるなら”YES”を, そうでないなら”NO”を一行に出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
4 6 3
......
...Y..
...Y..
RRYRYY
</pre>
<H2>Sample Output 2</H2>
<pre>
YES
</pre>
<H2>Sample Input 1</H2>
<pre>
4 6 3
......
...Y..
...Y..
RRYRY.
</pre>
<H2>Sample Output 2</H2>
<pre>
NO
</pre> |
p03374 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is <var>C</var> meters. Customers cannot go inside the counter.</p>
<p>Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are <var>N</var> pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the <var>i</var>-th sushi is placed, is <var>x_i</var> meters. Also, the <var>i</var>-th sushi has a nutritive value of <var>v_i</var> kilocalories.</p>
<p>Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes <var>1</var> kilocalories per meter.</p>
<p>Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 10^5</var></li>
<li><var>2 ≤ C ≤ 10^{14}</var></li>
<li><var>1 ≤ x_1 < x_2 < ... < x_N < C</var></li>
<li><var>1 ≤ v_i ≤ 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Subscores</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N ≤ 100</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>C</var>
<var>x_1</var> <var>v_1</var>
<var>x_2</var> <var>v_2</var>
<var>:</var>
<var>x_N</var> <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Nakahashi can take in at most <var>c</var> kilocalories on balance before he leaves the restaurant, print <var>c</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 20
2 80
9 120
16 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>191
</pre>
<p>There are three sushi on the counter with a circumference of <var>20</var> meters. If he walks two meters clockwise from the initial place, he can eat a sushi of <var>80</var> kilocalories. If he walks seven more meters clockwise, he can eat a sushi of <var>120</var> kilocalories. If he leaves now, the total nutrition taken in is <var>200</var> kilocalories, and the total energy consumed is <var>9</var> kilocalories, thus he can take in <var>191</var> kilocalories on balance, which is the largest possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 20
2 80
9 1
16 120
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>192
</pre>
<p>The second and third sushi have been swapped. Again, if he walks two meters clockwise from the initial place, he can eat a sushi of <var>80</var> kilocalories. If he walks six more meters counterclockwise this time, he can eat a sushi of <var>120</var> kilocalories. If he leaves now, the total nutrition taken in is <var>200</var> kilocalories, and the total energy consumed is <var>8</var> kilocalories, thus he can take in <var>192</var> kilocalories on balance, which is the largest possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100000000000000
50000000000000 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>Even though the only sushi is so far that it does not fit into a <var>32</var>-bit integer, its nutritive value is low, thus he should immediately leave without doing anything.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>15 10000000000
400000000 1000000000
800000000 1000000000
1900000000 1000000000
2400000000 1000000000
2900000000 1000000000
3300000000 1000000000
3700000000 1000000000
3800000000 1000000000
4000000000 1000000000
4100000000 1000000000
5200000000 1000000000
6600000000 1000000000
8000000000 1000000000
9300000000 1000000000
9700000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>6500000000
</pre>
<p>All these sample inputs above are included in the test set for the partial score.</p></section>
</div>
</span> |
p02135 | <h1>Problem L: Tree Fragments</h1>
<h2>Problem</h2>
<p>あいちゃんは、$N$個の頂点と$N-1$本の辺からなる木$T$を持っている。各頂点には$1$から$N$までの番号と、正の整数の重みがついている。</p>
<p>次の$Q$回のクエリに順に答えよ。</p>
<p>
<ul>
<li>$1 \le a_i,b_i \le N$($a_i \ne b_i$)が与えられるので、$T$の$a_i$-$b_i$パス上の頂点とそれに接続する辺を取り除いてできる、いくつかの連結成分の中で、重みが最大となる連結成分の重みを出力する。そのような連結成分が1つもない場合、0と出力する。</li>
</ul>
</p>
<p>ただし、連結成分の重みはその連結成分に含まれる頂点の重みの和で定義される。</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
$N$
$w_1$ $w_2$ ... $w_N$
$u_1$ $v_1$
$u_2$ $v_2$
...
$u_{N-1}$ $v_{N-1}$
$Q$
$a_1$ $b_1$
$a_2$ $b_2$
...
$a_Q$ $b_Q$
</pre>
<p>入力はすべて整数で与えられる。</p>
<p>
1行目に$T$の頂点数$N$が与えられる。<br>
2行目に頂点$i$($1 \le i \le N$)の重み$w_i$が空白区切りで与えられる。<br>
3行目以降の$N$-1行に辺$_i$($1 \le i \le N-1$)の端点$u_i,v_i$が空白区切りで与えられる。<br>
$N$+2行目にクエリの数$Q$が与えられる。<br>
$N$+3行目以降の$Q$行に、クエリ$_i$($1 \le i \le Q$)を表す$a_i,b_i$が空白区切りで与えられる。<br>
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$2 \le N \le 10^5$</li>
<li>$1 \le Q \le 10^5$</li>
<li>$1 \le w_i \le 10^8$($1 \le i \le N$)</li>
<li>$1 \le u_i,v_i \le N$($1 \le i \le N-1$)</li>
<li>$u_i \ne v_i$</li>
<li>$i \ne j$なら$(u_i,v_i) \ne (u_j,v_j)$かつ$(u_i,v_i) \ne (v_j, u_j)$</li>
<li>$1 \le a_i,b_i \le N$($1 \le i \le Q$)</li>
<li>$a_i \ne b_i$</li>
</ul>
<h2>Ouput</h2>
<p>クエリ毎に、0または重みが最大となる連結成分の重みを1行に出力する。</p>
<h2>Sample Input 1</h2>
<pre>
10
1 2 3 4 5 6 7 8 9 10
1 2
2 3
3 4
3 5
2 6
6 7
2 8
8 9
8 10
3
3 8
7 1
7 10
</pre>
<h2>Sample Output 1</h2>
<pre>
13
27
12
</pre>
<h2>Sample Input 2</h2>
<pre>
5
1 2 3 4 5
1 2
2 3
3 4
4 5
3
1 2
1 5
2 4
</pre>
<h2>Sample Output 2</h2>
<pre>
12
0
5
</pre>
<h2>Sample Input 3</h2>
<pre>
15
3 8 4 2 6 5 1 2 10 3 4 2 6 1 1
1 2
2 3
3 4
3 5
2 6
6 7
6 8
1 9
9 10
10 11
10 12
9 13
13 14
13 15
5
1 1
2 7
6 10
1 15
3 4
</pre>
<h2>Sample Output 3</h2>
<pre>
28
30
12
28
46
</pre>
|
p00108 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>出現頻度操作</H1>
<p>
有限数列の変換操作に出現頻度操作というものがあります。数列 $S = \{s_1, s_2,... s_n\}$ の変換結果は同じ長さの数列となります。その結果を $C = \{c_1,c_2, ..., c_n\}$ とすると、 $c_i$ は数列 $S$ における $s_i$ の個数を表します。
</p>
<p>
例えば $S = \{3,4,1,5,9,2,6,5,3\}$ ならば $C = {2,1,1,2,1,1,1,2,2}$ となります。さらにこの数列 $C$ に出現頻度操作を行うと $P = \{4,5,5,4,5,5,5,4,4\}$ を得ます。この数列は出現頻度操作で変わることがありません。このような数列 $P$ を数列 $S$ の不動点と呼びます。どのような数列に対しても出現頻度操作を繰り返せば、その不動点を求めることが出来るということが知られています。
</p>
<p>
下の例は出現頻度操作の手順を示したものです。1 行目を数列 $S$ 、2 行目を数列 $C$、最終行を数列 $P$ とします。数列 $S$ の最初の要素($s_1 = 2$) と同じ数は 3 個あるので数列 $C$ の最初の要素 $c_1$ は 3、次の要素 ($s_2 = 7$) と同じ数は 2 個あるので $c_2 = 2$、といった具合に個数を数え $c_i$ を求めていきます。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_frequency" width="600">
</center>
<br/>
<p>
数列の長さ $n$ と数列 $S$ を入力し、不動点の数列 $P$ および、$P$ を得るために実行した出現頻度操作の最小の回数を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。各データセットは以下の形式で与えられます。<br/>
<br/>
$n$<br/>
$s_1$ $s_2$ ... $s_n$<br/>
</p>
<p>
1 行目に数列の長さを表す整数 $n$ ($n \leq 12$) が与えられます。2行目に数列 $S$ の要素を表す整数 $s_i$ ($1 \leq s_i \leq 100$) が空白区切りで与えられます。
</p>
<p>
入力は0一つの行で終わります。データセットの数は 200 を超えません。
</p>
<H2>Output</H2>
<p>
各データセットについて、1行目に出現頻度操作の最小の実行回数(整数)、2行目に対応する不動点の数列 $P$ の要素 $p_1$, $p_2$, ..., $p_n$ を空白区切りで出力してください。
</p>
<H2>Sample Input</H2>
<pre>
10
4 5 1 1 4 5 12 3 5 4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
6 6 4 4 6 6 4 4 6 6
</pre>
|
p02565 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider placing <var>N</var> flags on a line. Flags are numbered through <var>1</var> to <var>N</var>.</p>
<p>Flag <var>i</var> can be placed on the coordinate <var>X_i</var> or <var>Y_i</var>.
For any two different flags, the distance between them should be at least <var>D</var>.</p>
<p>Decide whether it is possible to place all <var>N</var> flags. If it is possible, print such a configulation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>0 \leq D \leq 10^9</var></li>
<li><var>0 \leq X_i < Y_i \leq 10^9</var></li>
<li>All values in Input are integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>D</var>
<var>X_1</var> <var>Y_1</var>
<var>X_2</var> <var>Y_2</var>
<var>\vdots</var>
<var>X_N</var> <var>Y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>No</code> if it is impossible to place <var>N</var> flags.</p>
<p>If it is possible, print <code>Yes</code> first.
After that, print <var>N</var> lines. <var>i</var>-th line of them should contain the coodinate of flag <var>i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 4
2 5
0 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
4
2
0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 4
2 5
0 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre></section>
</div>
</span> |
p00558 |
<h1>ヘビの JOI 君 (Snake JOI)</h1>
<h2>問題</h2>
<p>
ヘビの JOI 君は,ある大きな屋敷に迷い込んでしまった.屋敷の住人に見つかる前に,屋敷を脱出しなければならない.
</p>
<p>
この屋敷には部屋が N 個あり,1, 2, ..., N の番号が付けられている.また,廊下が M 本あり,i 本目の廊下 (1 ≦ i ≦ M) は部屋 A<sub>i</sub> と部屋 B<sub>i</sub> を結んでいる.JOI 君はこれらの廊下をどちらの向きにも通ることができ,廊下 i を通るのには D<sub>i</sub> 分かかる.部屋と部屋の間を廊下を通る以外の手段で移動する方法はない.
</p>
<p>
この屋敷の部屋の温度はそれぞれ一定に調節されており,JOI 君にとって寒すぎるか,快適であるか,暑すぎるかである.JOI 君は,急な温度変化に対応できないため,最後に寒すぎる部屋を出てから X 分未満のうちに暑すぎる部屋に入ることはできない.同様に,最後に暑すぎる部屋を出てから X 分未満のうちに寒すぎる部屋に入ることもできない.
</p>
<p>
JOI 君は,移動中に部屋に入るとすぐに部屋から出なければならない.また,廊下の途中で引き返したり,廊下 i を D<sub>i</sub> 分より長い時間かけて通ることもできない.ただし,一度訪れた部屋にもう一度入ることや,一度使った廊下をもう一度使うことは許される.
</p>
<p>
JOI 君は現在部屋 1 にいる.この部屋は JOI 君にとって寒すぎる.JOI 君は屋敷の出口のある部屋 N に入ると,屋敷から脱出できる.
</p>
<p>
JOI 君が屋敷から脱出するのにかかる最短の時間を求めよ.
</p>
<h2>入力</h2>
<p>
入力は 1 + N + M 行からなる.
</p>
<p>
1 行目には,3 個の整数 N, M, X (2 ≦ N ≦ 10000, 1 ≦ M ≦ 20000, 1 ≦ X ≦ 200) が空白を区切りとして書かれている.これは,屋敷に N 個の部屋と M 本の廊下があり,JOI 君が温度変化に対応するのに X 分かかることを表す.
</p>
<p>
続く N 行のうちの i 行目 (1 ≦ i ≦ N) には,部屋 i の温度を表す整数 T<sub>i</sub> (0 ≦ T<sub>i</sub> ≦ 2) が書かれている.JOI 君にとって部屋 i は,T<sub>i</sub> = 0 のとき寒すぎ,T<sub>i</sub> = 1 のとき快適であり,T<sub>i</sub> = 2 のとき暑すぎる.T<sub>1</sub> = 0 であることが保証されている.
</p>
<p>
続く M 行のうちの j 行目 (1 ≦ j ≦ M) には,3 個の整数 A<sub>j</sub>, B<sub>j</sub>, D<sub>j</sub> (1 ≦ A<sub>j</sub> < B<sub>j</sub> ≦ N, 1 ≦ D<sub>j</sub> ≦ 200) が空白を区切りとして書かれている.これは,廊下 j が部屋 A<sub>j</sub> と部屋 B<sub>j</sub> を結んでおり,通るのに D<sub>j</sub> 分かかることを表す.同じ部屋の組を結ぶ廊下が複数ある可能性があることに注意せよ.
</p>
<p>
与えられる入力データでは,JOI 君が屋敷から脱出できることは保証されている.
</p>
<h2>出力</h2>
<p>
JOI 君が屋敷から脱出するのに最短で何分かかるかを表す整数を 1 行で出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
8 10 4
0
1
1
2
1
1
2
0
1 2 1
1 3 1
2 3 3
2 4 5
3 4 1
4 5 1
5 6 1
5 8 1
1 7 2
7 8 2
</pre>
<h3>出力例 1</h3>
<pre>
9
</pre>
<br/>
<h3>入力例 2</h3>
<pre>
15 25 4
0
1
1
0
2
1
0
1
1
2
0
0
1
0
1
8 11 1
7 10 1
12 14 1
3 8 1
1 5 1
3 9 1
3 8 1
1 5 1
6 15 1
11 12 1
2 14 1
7 10 1
11 12 1
5 13 1
2 8 1
1 4 1
2 11 1
5 6 1
1 13 1
6 12 1
5 10 1
9 13 1
4 10 1
3 12 1
7 13 1
</pre>
<h3>出力例 2</h3>
<pre>
6
</pre>
<br/>
<p>
入力例 1 では,部屋を 1 → 2 → 3 → 4 → 5 → 6 → 5 → 8 の順に移動するのが最短となる.
</p>
<p>
入力例 2 では,いくつかの部屋の組 (たとえば部屋 1 と部屋 5) を結ぶ廊下が複数ある.
</p>
<br/>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2016/2017-yo/index.html">情報オリンピック日本委員会作 『第 16 回日本情報オリンピック JOI 2016/2017 予選競技課題』</a>
</p>
</div>
|
p02070 | <style type="text/css">
blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
display: block;
margin: 10px 0 10px 30px;
font-size: 16px;
line-height: 18px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}
table.ioexample {
width: 100%;
border-collapse: collapse;
}
table.ioexample td {
width: 50%;
border: 1px solid rgba(0, 0, 0, 0.15);
vertical-align: top;
padding: 5px;
}
.no-page-break {
page-break-inside: avoid;
}
.page-break {
page-break-before: always;
}
</style>
<h3>Problem Statement</h3>
<p>One day (call it day 0), you find a permutation $P$ of $N$ integers written on the blackboard in a single row.
Fortunately you have another permutation $Q$ of $N$ integers, so you decide to play with these permutations.</p>
<p>Every morning of the day 1,2,3,... , you rewrite every number on the blackboard in such a way that erases the number $x$ and write the number $Q_x$ at the same position. Please find the minimum non-negative integer $d$ such that in the evening of the day $d$ the sequence on the blackboard is sorted in increasing order.</p>
<hr />
<h3>Input</h3>
<p>The input consists of a single test case in the format below.</p>
<blockquote>$N$
$P_1$ $\ldots$ $P_N$
$Q_1$ $\ldots$ $Q_N$</blockquote>
<p>The first line contains an integer $N$ ($1 \leq N \leq 200$). The second line contains $N$ integers $P_1,\ldots,P_N$ ($1 \leq P_i \leq N$) which represent the permutation $P$. The third line contains $N$ integers $Q_1,\ldots,Q_N$ ($1 \leq Q_i \leq N$) which represent the permutation $Q$. </p>
<h3>Output</h3>
<p>Print the minimum non-negative integer $d$ such that in the evening of the day $d$ the sequence on the blackboard is sorted in increasing order. If such $d$ does not exist, print -1 instead.</p>
<p>It is guaranteed that the answer does not exceed $10^{18}$.</p>
<p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>6
2 3 1 4 5 6
3 1 2 5 4 6
</pre></td><td><pre>4
</pre></td></tr><tr><td><pre>6
1 2 3 4 5 6
3 1 2 5 4 6
</pre></td><td><pre>0
</pre></td></tr><tr><td><pre>6
2 3 1 4 5 6
3 4 5 6 1 2
</pre></td><td><pre>-1
</pre></td></tr></table></div></p>
|
p02420 | <H1>Shuffle</H1><br>
<p>
Your task is to shuffle a deck of <var>n</var> cards, each of which is marked by a alphabetical letter.
</p>
<p>
A single shuffle action takes out <var>h</var> cards from the bottom of the deck and moves them to the top of the deck.
</p>
<p>
The deck of cards is represented by a string as follows.
</p>
<pre>
abcdeefab
</pre>
<p>
The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively.
</p>
<p>
For example, a shuffle with <var>h</var> = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck:
</p>
<pre>
eefababcd
</pre>
<p>
You can repeat such shuffle operations.
</p>
<p>
Write a program which reads a deck (a string) and a sequence of <var>h</var>, and prints the final state (a string).
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is given in the following format:
</p>
<pre>
A string which represents a deck
The number of shuffle <var>m</var>
<var>h</var><sub>1</sub>
<var>h</var><sub>2</sub>
.
.
<var>h</var><sub><var>m</var></sub>
</pre>
<p>
The input ends with a single character '-' for the string.
</p>
<H2>Constraints</H2>
<ul>
<li>The length of the string ≤ 200</li>
<li>1 ≤ <var>m</var> ≤ 100</li>
<li>1 ≤ <var>h<sub>i</sub></var> < The length of the string</li>
<li> The number of datasets ≤ 10</li>
</ul>
<H2>Output</H2>
<p>
For each dataset, print a string which represents the final state in a line.
</p>
<H2>Sample Input</H2>
<pre>
aabc
3
1
2
1
vwxyz
2
3
4
-
</pre>
<H2>Sample Output</H2>
<pre>
aabc
xyzvw
</pre>
|
p02973 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence with <var>N</var> integers: <var>A = \{ A_1, A_2, \cdots, A_N \}</var>.
For each of these <var>N</var> integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:</p>
<ul>
<li>If <var>A_i</var> and <var>A_j</var> <var>(i < j)</var> are painted with the same color, <var>A_i < A_j</var>.</li>
</ul>
<p>Find the minimum number of colors required to satisfy the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq 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>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of colors required to satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
2
1
4
5
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can satisfy the condition with two colors by, for example, painting <var>2</var> and <var>3</var> red and painting <var>1</var>, <var>4</var>, and <var>5</var> blue.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
0
0
0
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>We have to paint all the integers with distinct colors.</p></section>
</div>
</span> |
p03661 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke and Raccoon have a heap of <var>N</var> cards. The <var>i</var>-th card from the top has the integer <var>a_i</var> written on it.</p>
<p>They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.</p>
<p>Let the sum of the integers on Snuke's cards and Raccoon's cards be <var>x</var> and <var>y</var>, respectively.
They would like to minimize <var>|x-y|</var>.
Find the minimum possible value of <var>|x-y|</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>-10^{9} \leq a_i \leq 10^{9}</var></li>
<li><var>a_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 2 3 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, <var>x=10</var>, <var>y=11</var>, and thus <var>|x-y|=1</var>. This is the minimum possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
10 -10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>20
</pre>
<p>Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, <var>x=10</var>, <var>y=-10</var>, and thus <var>|x-y|=20</var>.</p></section>
</div>
</span> |
p03231 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>N</var> and another string <var>T</var> of length <var>M</var>.
These strings consist of lowercase English letters.</p>
<p>A string <var>X</var> is called a <strong>good string</strong> when the following conditions are all met:</p>
<ul>
<li>Let <var>L</var> be the length of <var>X</var>. <var>L</var> is divisible by both <var>N</var> and <var>M</var>.</li>
<li>Concatenating the <var>1</var>-st, <var>(\frac{L}{N}+1)</var>-th, <var>(2 \times \frac{L}{N}+1)</var>-th, <var>...</var>, <var>((N-1)\times\frac{L}{N}+1)</var>-th characters of <var>X</var>, without changing the order, results in <var>S</var>.</li>
<li>Concatenating the <var>1</var>-st, <var>(\frac{L}{M}+1)</var>-th, <var>(2 \times \frac{L}{M}+1)</var>-th, <var>...</var>, <var>((M-1)\times\frac{L}{M}+1)</var>-th characters of <var>X</var>, without changing the order, results in <var>T</var>.</li>
</ul>
<p>Determine if there exists a good string. If it exists, find the length of the shortest such string.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 10^5</var></li>
<li><var>S</var> and <var>T</var> consist of lowercase English letters.</li>
<li><var>|S|=N</var></li>
<li><var>|T|=M</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>S</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If a good string does not exist, print <code>-1</code>; if it exists, print the length of the shortest such string.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
acp
ae
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>For example, the string <code>accept</code> is a good string.
There is no good string shorter than this, so the answer is <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 3
abcdef
abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15 9
dnsusrayukuaiia
dujrunuma
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>45
</pre></section>
</div>
</span> |
p01522 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1>C - ソーシャル</h1>
<h2>問題文</h2>
<p>
うさぎが <var>N</var> 匹おり,ボートを使って川を渡ろうとしている.ボートは <var>K</var> 個あり,誰がどのボートに乗るかを適当に決めて乗ることにした.
</p>
<p>
ところでうさぎというのは互いの仲の良し悪しに敏感であり,狭い空間に仲の悪いうさぎと一緒に閉じ込められると気分を悪くしてしまう.
この <var>N</var> 匹のうさぎについても何組かのうさぎは仲が悪いということが分かっており,今の割り当てでは何匹かは気分を悪くしてしまう可能性がある.
もっと良い割り当てを考えるのがよいところではあるが,ひとまず今の割り当てで何匹のうさぎが気分を悪くするかを求めて欲しい.
</p>
<h2>入力形式</h2>
<p>
入力は以下の形式で与えられる.
</p>
<pre>
<var>N</var> <var>K</var>
<var>m<sub>1</sub></var> <var>bunny<sub>1,1</sub></var> ... <var>bunny<sub>1,m<sub>1</sub></sub></var>
<var>m<sub>2</sub></var> <var>bunny<sub>2,1</sub></var> ... <var>bunny<sub>2,m<sub>2</sub></sub></var>
...
<var>m<sub>K</sub></var> <var>bunny<sub>K,1</sub></var> ... <var>bunny<sub>K,m<sub>K</sub></sub></var>
<var>R</var>
<var>p<sub>1</sub></var> <var>q<sub>1</sub></var>
...
<var>p<sub>R</sub></var> <var>q<sub>R</sub></var>
</pre>
<p>
<var>N</var> はボートに乗るうさぎの数である.<var>K</var> はボートの個数である.
<var>m<sub>i</sub></var> はボート <var>i</var> に乗るうさぎの数である.<var>bunny<sub>i,1</sub>, ..., bunny<sub>i,m<sub>i</sub></sub></var> はボート <var>i</var> に乗るうさぎの番号 (1 以上 <var>N</var> 以下) を表す.
<var>R</var> は仲の悪いうさぎの組の個数を表す.
<var>p<sub>j</sub>, q<sub>j</sub></var> はうさぎ<var>p<sub>j</sub></var> とうさぎ <var>q<sub>j</sub></var> の仲が悪いことを表す.</p>
<h2>出力形式</h2>
<p>
気分を悪くするうさぎの数を出力せよ.
</p>
<h2>制約</h2>
<ul>
<li><var>1 ≤ N ≤ 50</var></li>
<li><var>1 ≤ K ≤ N</var></li>
<li><var>m<sub>1</sub> + ... + m<sub>K</sub> = N</var></li>
<li><var>{bunny<sub>1,1</sub>, ..., bunny<sub>1,m<sub>1</sub></sub>, bunny<sub>2,1</sub>, ..., bunny<sub>K,m<sub>K</sub></sub> } = {1, 2, ..., N}</var></li>
<li><var>0 ≤ R ≤ N(N-1)/2</var></li>
<li><var>1 ≤ p<sub>j</sub> < q<sub>j</sub> ≤ N</var></li>
<li>組 <var>(p<sub>j</sub>, q<sub>j</sub>)</var> は全て異なる.</li>
<li>入力値はすべて整数である.</li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
6 2
2 1 5
4 2 3 4 6
2
1 2
2 5
</pre>
<h3>出力例 1</h3>
<pre>
0
</pre>
<p>
気分を悪くしているうさぎはいない.
</p>
<h3>入力例 2</h3>
<pre>
6 2
2 1 5
4 2 3 4 6
3
2 3
3 4
1 2
</pre>
<h3>出力例 2</h3>
<pre>
3
</pre>
<p>
割り当ては例 1 と同じであるが仲の悪さを表す組が異なっている.この例ではうさぎ 2,3,4 が気分を悪くしてしまう.
</p>
<h3>入力例 3</h3>
<pre>
10 3
3 4 1 9
3 10 5 2
4 3 8 7 6
9
3 4
1 2
1 9
6 8
1 6
1 8
6 7
6 10
7 8
</pre>
<h3>出力例 3</h3>
<pre>
5
</pre>
<hr>
<address>Writer: 楠本充</address>
<address>Tester: 小浜翔太郎</address> |
p01172 |
<H1><font color="#000">Problem B:</font> Headstrong Student</H1>
<p>
You are a teacher at a cram school for elementary school pupils.
</p>
<p>
One day, you showed your students how to calculate division of fraction in a class of mathematics.
Your lesson was kind and fluent, and it seemed everything was going so well - except for one
thing. After some experiences, a student Max got so curious about how precise he could compute
the quotient. He tried many divisions asking you for a help, and finally found a case where
the answer became an infinite fraction. He was fascinated with such a case, so he continued
computing the answer. But it was clear for you the answer was an infinite fraction - no matter
how many digits he computed, he wouldn’t reach the end.
</p>
<p>
Since you have many other things to tell in today’s class, you can’t leave this as it is. So you
decided to use a computer to calculate the answer in turn of him. Actually you succeeded to
persuade him that he was going into a loop, so it was enough for him to know how long he could
compute before entering a loop.
</p>
<p>
Your task now is to write a program which computes where the recurring part starts and the
length of the recurring part, for given dividend/divisor pairs. All computation should be done
in decimal numbers. If the specified dividend/divisor pair gives a finite fraction, your program
should treat the length of the recurring part as 0.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each line of the input describes a dataset. A dataset
consists of two positive integers <i>x</i> and <i>y</i>, which specifies the dividend and the divisor, respectively.
You may assume that 1 ≤ <i>x</i> < <i>y</i> ≤ 1,000,000.
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of datasets
and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, your program should output a line containing two integers separated by exactly
one blank character.
</p>
<p>
The former describes the number of digits after the decimal point before the recurring part
starts. And the latter describes the length of the recurring part.
</p>
<H2>Sample Input</H2>
<pre>
1 3
1 6
3 5
2 200
25 99
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 1
1 1
1 0
2 0
0 2
</pre>
|
p01488 |
<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 C:
TransferTrain
</h2>
<p>
うなぎは電車に乗るのが好きである. いま,うなぎは駅 A から駅 B へ電車を使って行こうとしている. うなぎは急いでいるので, 最短時間の経路を選ぶことにした. ただし,うなぎは乗り換えが苦手なので, 最短時間の経路が複数ある場合は最も乗り換え回数の少ない経路を選ぶことにした.
</p>
<p>
$N$ 本の路線がある. $i$ 本目の路線は $a_i$ 個の駅を通っている. $i$ 本目の路線の通る駅名は通る順に $s_{i,0}, ... , s_{i,a_i -1}$ であり, 駅間の所要時間は $t_{i,0}, ..., t_{i,a_i - 2}$ である. 電車は路線上を上下方向に走っており, 入力で与えられた逆順に乗ることもできる. 複数の路線の同じ駅名は同じ駅を表しており,乗り換えをすることが出来る. 乗り換えには駅や路線によらず $T$ 分かかる.
</p>
<p>
一本の路線が同じ駅を複数回通ることもある.もし同じ路線,同じ駅の,路線内で異なる位置の駅に移動したい場合は乗り換えをする必要がある. たとえば, C - D - E - F - D - G という路線を使って C から G まで行く場合, 始点から終点まで一本の電車で行くことも,D 駅で乗り換えて C - D, D - G と乗ることもできる.
</p>
<p>
うなぎが駅 A から駅 B へ行くのにかかる時間と乗り換え回数を求めよ. 電車はとても頻繁に来るので待ち時間は無視してよい.
</p>
<h3>Constraints</h3>
<ul>
<li> $N$ will be between 1 and 50,000, inclusive. </li>
<li> $T$ will be an integer between 1 and 1,000, inclusive.</li>
<li> At least one train stops at A.</li>
<li> At least one train stops at B.</li>
<li> A and B will be distinct.</li>
<li> $a_i$ will be bigger than or equal to 2.</li>
<li> $a_1 + ... + a_N$ will be between 2 and 100,000, inclusive.</li>
<li> $s_{i,j}$ will contain between 1 and 10 characters, inclusive.</li>
<li> Each character in $s_{i,j}$ will be a letter ('A'-'Z', 'a'-'z').</li>
<li> $t_{i,j}$ will be an integer between 1 and 1,000, inclusive.</li>
</ul>
<h3>Input</h3>
<p>
入力は以下の形式で与えられる:<br>
<br>
$N$ $T$<br>
$A$ $B$<br>
$a_1$<br>
$s_{1,1}$ ... $s_{1,a_1}$<br>
$t_{1,1}$ ... $t_{1,a_1 -1}$<br>
...<br>
$a_N$<br>
$s_{N,1}$ ... $s_{N,a_N}$<br>
$t_{N,1}$ ... $t_{N,a_N-1}$<br>
<br>
</p>
<h3>Output</h3>
<p>
うなぎが駅 A から駅 B へ行くのにかかる時間と乗り換え回数を空白で区切って1 行に出力せよ.
</p>
<h3>Sample Input 1</h3>
<pre>2 10
Warsaw Petersburg
3
Kiev Moscow Petersburg
150 120
3
Moscow Minsk Warsaw
100 150</pre>
<h3>Sample Output 1</h3>
<pre>380 1</pre>
<h3>Sample Input 2</h3>
<pre>2 10
Warsaw Petersburg
3
Kiev Moscow Petersburg
150 120
2
Minsk Warsaw
150</pre>
<h3>Sample Output 2</h3>
<pre>-1</pre>
|
p00333 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ニュータウン</H1>
<p>
会津県では人口増加のためにニュータウンを作ることにしました。そのために、新たに長方形の土地を開拓し、この土地を余すところなく、すべて同じ大きさの正方形からなる区画に区切ることを決めました。この土地の整備には、区画数に比例した費用がかかりますが、県としてはこの費用を最小にしたいと考えています。
</p>
<p>
新たに開拓した土地の東西方向と南北方向の長さと、1区画当たりの整備費用が与えられたとき、すべての区画を整備したときにかかる、最小の整備費用を求めるプログラムを作成せよ。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>W</var> <var>H</var> <var>C</var>
</pre>
<p>
入力は1行であり、新たに開拓した土地の東西方向の長さ <var>W</var> (1 ≤ <var>W</var> ≤ 1000)と南北方向の長さ <var>H</var> (1 ≤ <var>H</var> ≤ 1000)、区画当たりの整備費用 <var>C</var> (1 ≤ <var>C</var> ≤ 1000)が整数で与えられる。
</p>
<h2>Output</h2>
<p>
土地を整備するために必要な最小の費用を1行に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
10 20 5
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<p>
2個の正方形で土地を余すところなく区切ることができ、1区画当たりの整備費用が5なので、10と
出力する。
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
27 6 1
</pre>
<h2>Sample Output 2</h2>
<pre>
18
</pre>
<p>
18個の正方形で土地を余すところなく区切ることができ、1区画当たりの整備費用が1なので、18と出力する。
</p>
|
p00763 |
<h1>Railway Connection</h1>
<!-- end en only -->
<!-- begin en only -->
<p>
Tokyo has a very complex railway system.
For example, there exists a partial map of lines and stations
as shown in Figure D-1.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1182_1" align="center" width="300"><br><br>
<!-- begin en only -->
Figure D-1: A sample railway network
<!-- end en only -->
<br>
</center>
<!-- begin en only -->
<p>
Suppose you are going to station D from station A.
Obviously, the path with the shortest distance is A→B→D.
However, the path with the shortest distance does not necessarily
mean the minimum cost.
Assume the lines A-B, B-C, and C-D are operated by one railway company,
and the line B-D is operated by another company.
In this case, the path A→B→C→D may cost less than A→B→D.
One of the reasons is that the fare is not proportional to the distance.
Usually, the longer the distance is, the fare per unit distance is lower.
If one uses lines of more than one railway company,
the fares charged by these companies are simply added together,
and consequently the total cost may become higher although the distance is shorter
than the path using lines of only one company.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
In this problem, a railway network including multiple railway companies is given.
The fare table (the rule to calculate the fare from the distance) of each company is also given.
Your task is, given the starting point and the goal point, to write a program
that computes the path with the least total fare.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of multiple datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<i>n</i> <i>m</i> <i>c</i> <i>s</i> <i>g</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>d</i><sub>1</sub> <i>c</i><sub>1</sub><br>
...<br>
<i>x<sub>m</sub></i> <i>y<sub>m</sub></i> <i>d<sub>m</sub></i> <i>c<sub>m</sub></i><br>
<i>p</i><sub>1</sub> ... <i>p<sub>c</sub></i><br>
<i>q</i><sub>1,1</sub> ... <i>q</i><sub>1,<i>p</i><sub>1</sub>-1</sub><br>
<i>r</i><sub>1,1</sub> ... <i>r</i><sub>1,<i>p</i><sub>1</sub></sub><br>
...<br>
<i>q</i><sub><i>c</i>,1</sub> ... <i>q</i><sub><i>c,p</i><sub><i>c</i></sub>-1</sub><br>
<i>r</i><sub><i>c</i>,1</sub> ... <i>r</i><sub><i>c,p<sub>c</sub></i></sub><br>
</blockquote>
<!-- begin en only -->
<p>
Every input item in a dataset is a non-negative integer.
Input items in the same input line are separated by a space.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The first input line gives the size of the railway network and the intended trip.
<i>n </i> is the number of stations (2 ≤ <i>n</i> ≤ 100).
<i>m </i> is the number of lines connecting two stations (0 ≤ <i>m</i> ≤ 10000).
<i>c </i> is the number of railway companies (1 ≤ <i>c</i> ≤ 20).
<i>s </i> is the station index of the starting point (1 ≤ <i>s</i> ≤ <i>n</i> ).
<i>g </i> is the station index of the goal point (1 ≤ <i>g</i> ≤ <i>n</i>, <i>g</i> ≠ <i>s</i> ).
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The following <i>m </i> input lines give the details of (railway) lines.
The <i>i </i>-th line connects two stations
<i>x<sub>i</sub> </i> and <i>y<sub>i</sub> </i>
(1 ≤ <i>x<sub>i</sub></i> ≤ <i>n</i>,
1 ≤ <i>y<sub>i</sub></i> ≤ <i>n</i>,
<i>x<sub>i</sub></i> ≠ <i>y<sub>i</sub></i> ).
Each line can be traveled in both directions.
There may be two or more lines connecting the same pair of stations.
<i>d<sub>i</sub> </i> is the distance of the <i>i </i>-th line (1 ≤ <i>d<sub>i</sub></i> ≤ 200).
<i>c<sub>i</sub> </i> is the company index of the railway company operating the line (1 ≤ <i>c<sub>i</sub></i> ≤ <i>c</i> ).
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The fare table (the relation between the distance and the fare)
of each railway company can be expressed as a line chart.
For the railway company <i>j </i>,
the number of sections of the line chart is given by <i>p<sub>j</sub> </i>
(1 ≤ <i>p<sub>j</sub></i> ≤ 50).
<i>q<sub>j,k</sub> </i> (1 ≤ <i>k</i> ≤ <i>p<sub>j</sub></i>-1) gives
the distance separating two sections of the chart
(1 ≤ <i>q<sub>j,k</sub></i> ≤ 10000).
<i>r<sub>j,k</sub> </i> (1 ≤ <i>k</i> ≤ <i>p<sub>j</sub></i> ) gives
the fare increment per unit distance for the corresponding section of the chart
(1 ≤ <i>r<sub>j,k</sub></i> ≤ 100).
More precisely, with the fare for the distance <i>z </i> denoted by
<i>f<sub>j</sub></i> (<i>z</i> ),
the fare for distance <i>z </i> satisfying
<i>q</i><sub><i>j</i>,<i>k</i>-1</sub>+1 ≤ <i>z</i> ≤ <i>q</i><sub><i>j</i>,<i>k</i></sub>
is computed by the recurrence relation
<i>f<sub>j</sub></i> (<i>z</i>) = <i>f<sub>j</sub></i> (<i>z</i>-1)+<i>r<sub>j,k</sub></i>.
Assume that <i>q</i><sub><i>j</i>,0</sub> and <i>f<sub>j</sub></i> (0) are zero,
and <i>q</i><sub><i>j</i>,<i>p<sub>j</sub></i></sub> is infinity.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
For example, assume <i>p<sub>j</sub> </i> = 3,
<i>q</i><sub><i>j</i>,1</sub> = 3,
<i>q</i><sub><i>j</i>,2</sub> = 6,
<i>r</i><sub><i>j</i>,1</sub> = 10,
<i>r</i><sub><i>j</i>,2</sub> = 5, and
<i>r</i><sub><i>j</i>,3</sub> = 3.
The fare table in this case is as follows.
</p>
<table border=1>
<tr align=right><td>distance</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td></tr>
<tr align=right><td>fare</td><td>10</td><td>20</td><td>30</td><td>35</td><td>40</td><td>45</td><td>48</td><td>51</td><td>54</td></tr>
</table>
<!-- end en only -->
<!-- begin en only -->
<p>
<i>q<sub>j,k</sub> </i> increase monotonically with respect to <i>k </i>.
<i>r<sub>j,k</sub> </i> decrease monotonically with respect to <i>k </i>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The last dataset is followed by an input line containing five zeros
(separated by a space).
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset in the input, the total fare for the best route
(the route with the minimum total fare)
should be output as a line.
If the goal cannot be reached from the start, output "-1".
An output line should not contain extra characters such as spaces.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Once a route from the start to the goal is determined,
the total fare of the route is computed as follows.
If two or more lines of the same railway company are used contiguously,
the total distance of these lines is used to compute the fare of this section.
The total fare of the route is the sum of fares of such "sections consisting
of contiguous lines of the same company".
Even if one uses two lines of the same company, if a line of another company
is used between these two lines, the fares of sections including these two
lines are computed independently.
No company offers transit discount.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
4 4 2 1 4
1 2 2 1
2 3 2 1
3 4 5 1
2 4 4 2
3 1
3 6
10 5 3
10
2 0 1 1 2
1
1
4 5 2 4 1
4 3 10 1
3 2 2 1
3 2 1 2
3 2 5 2
2 1 10 1
3 3
20 30
3 2 1
5 10
3 2 1
5 5 2 1 5
1 2 10 2
1 3 20 2
2 4 20 1
3 4 10 1
4 5 20 1
2 2
20
4 1
20
3 1
0 0 0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
54
-1
63
130
</pre> |
p01871 |
<!-- - - - - - begin nicebody - - - - - -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>G: 塗るだけ / Paint</h1>
<h2>問題文</h2>
<p>
情太くんと立子さんは,
平面の世界にある庭付きの家に住んでいる.二人は点とみなせ,
庭は $N$ 頂点の単純多角形 (隣り合わないどの $2$ 辺も交差も接触もしない多角形) の形をしている.
</p>
<p>
ある日,二人は一本の伸び縮みするローラーを手に入れた.
ローラーは線分とみなせ,ローラーが通過した領域に色を塗ることができる.
二人はローラーを使って庭全体に色を塗りたいと思っている.
</p>
<p>
作業の前に,二人は以下のような準備を上から順に行う.
<ul>
<li>庭の内部の任意の $1$ 箇所に杭を打つ.</li>
<li>庭の外部のある $1$ 点に集まる.</li>
<li>十分に長い紐を用意し,片方の端を情太くん,もう一方の端を立子さんの体に結ぶ.</li>
<li>情太くんがローラーの片方の端を,立子さんがもう一方の端を持つ.</li>
</ul>
</p>
<p>
準備ができたら,以下のルールに従って塗り始める.
ただし,ローラーは杭の上空を通過させることができるが,紐はできない.
<ul>
<li>庭のどの部分から塗り始めてもよい.</li>
<li>庭の外部または周上を移動できるが,内部に入ってはいけない.</li>
<li>塗り終わるまでローラーから手を離してはいけない.</li>
</ul>
</p>
<p>
さらに,塗り終わったときに以下の条件を満たしていなければならない.
<ul>
<li>二人が再びある $1$ 点に集まっている.</li>
<li>庭の内部の任意の点の上をローラーが通過している.</li>
<li>二人の体の紐を解き,両端を結んで輪を作る.この輪を外から引っ張ったときに,杭に引っかかって抜けない.</li>
</ul>
</p>
<p>
さて,二人はできるだけ離れたくないので,塗っている最中にとる二人の距離の最大値を最小化したい.
二人に代わってそのような値を求めてほしい.
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる.$N$ は多角形を構成する頂点の数,
$(x_i,y_i)$ はある頂点から始めて時計回りまたは反時計回りに見たときの $i$ 番目の点の座標である.
</p>
<p>
$N$<br>
$x_1 \ y_1$<br>
$\vdots$<br>
$x_N \ y_N$<br>
</p>
<h2>制約</h2>
<p>
$3 \leq N \leq 50$<br>
$|x_i|, |y_i| \leq 100$<br>
全て整数である<br>
頂点は時計回りまたは反時計回りに与えられる<br>
庭の形は単純多角形である<br>
周上の連続する $3$ 点は一直線上に存在しない<br>
</p>
<h2>出力</h2>
<p>
答えを $1$ 行で出力せよ.$10^{-5}$ 未満の絶対誤差は許容される.
</p>
<h2>サンプル</h2>
<p>
各サンプルでの庭の形と塗り終わるまでのローラーの動きを図示すると以下のようになる.整数は時刻を表す.図示する都合上ローラーの動きは飛び飛びに示したが,実際には連続的に動いている.
ローラーが太くなっている部分で距離の最大値を達成している.
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_G">
<h3>サンプル入力1</h3>
<pre>
4
0 0
0 1
1 1
1 0
</pre>
<h3>サンプル出力1</h3>
<pre>
1
</pre>
<h3>サンプル入力2</h3>
<pre>
3
0 0
0 1
1 0
</pre>
<h3>サンプル出力2</h3>
<pre>
0.7071067811865476
</pre>
<h3>サンプル入力3</h3>
<pre>
8
0 0
5 0
5 3
0 3
0 2
4 2
4 1
0 1
</pre>
<h3>サンプル出力3</h3>
<pre>
1.4142135623730951
</pre>
<!-- - - - - - end nicebody - - - - - --> |
p00299 |
<h1>学食</h1>
<p>
今日はZ大学のオープンキャンパスです。毎年この日の昼休みには、大勢の高校生たちが学食に列をつくります。そこでZ大学の事務局は、行列の長さが最大でどのくらいの距離になるかを予測することにしました。事前調査の結果で、以下のことが分かっています。
</p>
<ul>
<li> 行列にはそれぞれ 1 から <var>N</var> までの番号が振られた <var>N</var> 人が並びます。</li>
<li> <var>C</var> 個の高校生のペア (<var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>) それぞれについて、以下の2種類の制約があります:
<ul>
<li>1つ目の制約は順序に関するもので以下のいずれかです:<br>
<var>a<sub>i</sub></var> は <var>b<sub>i</sub></var> よりも先、または同じ位置に並ばなくてはならない<br>
<var>a<sub>i</sub></var> は <var>b<sub>i</sub></var> よりも後、または同じ位置に並ばなくてはならない<br>
<var>a<sub>i</sub></var> は <var>b<sub>i</sub></var> より先でも、同じ位置でも、後でもよい<br>
</li>
<li>2つ目の制約は距離に関するもので以下のいずれかです:<br>
<var>a<sub>i</sub></var> と <var>b<sub>i</sub></var> は <var>d<sub>i</sub></var> メートル以上離れなければならない<br>
<var>a<sub>i</sub></var> と <var>b<sub>i</sub></var> は <var>d<sub>i</sub></var> メートル以内に並ばなければならない<br>
</li>
</li>
</ul>
</ul>
<p>
また、先頭から同じ距離の場所に複数の人が並ぶことができ、行列の先頭には常に番号 1 の人が並ぶことが分かっています。
</p>
<p>
与えられた <var>C</var> 個の制約をすべて満たす行列について、先頭から最後尾までの距離が最大となるような並び方をした場合の距離を求めるプログラムを作成してください。ただし、どこまでも離れることができる場合は <span>inf</span> と、制約を満たす並び方が不可能な場合は <span>-1</span> と出力してください。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var> <var>C</var>
<var>constraint<sub>1</sub></var>
<var>constraint<sub>2</sub></var>
:
<var>constraint<sub>C</sub></var>
</pre>
<p>
1 行目に行列に並ぶ高校生の人数 <var>N</var> (2 ≤ <var>N</var> ≤ 100) と制約の数 <var>C</var> (0 ≤ <var>C</var> ≤ 200) が与えられる。続く <var>C</var> 行に各制約 <var>constraint<sub>i</sub></var> が次の形式で与えられる。
</p>
<pre>
<var>a<sub>i</sub>o<sub>i</sub>b<sub>i</sub>s<sub>i</sub>d<sub>i</sub></var>
</pre>
<p>
制約には空白は含まれない。<var>a<sub>i</sub></var>, <var>o<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>s<sub>i</sub></var>, <var>d<sub>i</sub></var> の意味を以下に示す。
</p>
<ul>
<li> <var>a<sub>i</sub></var> と <var>b<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> ≤ <var>N</var> かつ <var>a<sub>i</sub></var> ≠ <var>b<sub>i</sub></var> ) は高校生の番号、<var>d<sub>i</sub></var> は距離 (0 ≤ <var>d</var> ≤ 10000) を表す整数である。</li>
<li> <var>o<sub>i</sub></var> は順序の制約を指定する <span><=</span>、<span>>=</span>、<span>*</span> のいずれかの文字列であり、<span><=</span> の場合「<var>a<sub>i</sub></var> は <var>b<sub>i</sub></var> よりも先、または同じ位置に並ばなくてはならない」、<span>>=</span> の場合「<var>a<sub>i</sub></var> は <var>b<sub>i</sub></var> よりも後、または同じ位置に並ばなくてはならない」、<span>*</span> の場合「<var>a<sub>i</sub></var> は <var>b<sub>i</sub></var> より先でも、同じ位置でも、後でもよい」ことを意味する。ただし <var>o<sub>i</sub></var> が <span>*</span> となる制約は7個以上与えられることはない。</li>
<li> <var>s<sub>i</sub></var> は距離の制約を指定する <span>+</span> または <span>-</span> の文字であり、<span>+</span> の場合「<var>a<sub>i</sub></var> と <var>b<sub>i</sub></var> は <var>d<sub>i</sub></var> メートル以上離れなければならない」、<span>-</span> の場合「<var>a<sub>i</sub></var> と <var>b<sub>i</sub></var> は <var>d<sub>i</sub></var> メートル以内に並ばなければならない」ことを意味する。
</li>
</ul>
<p>
ただし、あるペアに対して複数の制約が与えられることはないものとする。
</p>
<h2>出力</h2>
<p>
先頭から最後尾までの距離を1行に出力する。
</p>
<h2>入出力例 </h2>
<br>
<h2>入力例1</h2>
<pre>
3 2
1<=2-1
2<=3-2
</pre>
<h2> 出力例1</h2>
<pre>
3
</pre>
<br>
<h2>入力例2 </h2>
<pre>
3 3
1<=2-1
2<=3-2
1<=3+4
</pre>
<h2>出力例2</h2>
<pre>
-1
</pre>
<br>
<h2>入力例3 </h2>
<pre>
3 2
1<=2-2
2*3+1
</pre>
<h2>出力例3</h2>
<pre>
inf
</pre>
|
p00276 |
<H1>陣形</H1>
<p>
プログラマー養成校であるアカベ高校では、チーム戦の競技プログラマーの役割を以下の3タイプに分けています。<br>
<table style="margin-left:24px">
<tr>
<td>C:</td>
<td>コーダー</td>
<td>言語を熟知しており、コーディングを行う。</td>
</tr>
<tr>
<td>A:</td>
<td>アルゴリズマー</td>
<td>論理的思考が得意であり、アルゴリズムを考える。</td>
</tr>
<tr>
<td>N:</td>
<td>ナビゲーター</td>
<td>読解力に長けており、問題の分析・デバッグをする。</td>
</tr>
</table>
<br>
<p>
この高校では以下のいずれかの陣形で3人一組のチームを構成しています。
</p>
<table style="margin-left:24px">
<tr>
<td>CCA:</td>
<td>バランスがとれている安定型</td>
</tr>
<tr>
<td>CCC:</td>
<td>スピードを見込めるがリスクの高い速攻型</td>
</tr>
<tr>
<td>CAN:</td>
<td>正確に問題を解く慎重型</td>
</tr>
</table>
<br/>
<p>
競技プログラミング部のコーチであるあなたは、これらの部員をうまく組み合わせ、できるだけ多くのチームを結成できるよう、毎年気を配っています。そこで、コーダーの人数、アルゴリズマーの人数、ナビゲーターの人数が入力として与えられたとき、最大何チーム作れるかを出力するプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は1つのデータセットからなる。入力データは以下の形式で与えられる。
</p>
<pre>
<var>Q</var>
<var>c<sub>1</sub></var> <var>a<sub>1</sub></var> <var>n<sub>1</sub></var>
<var>c<sub>2</sub></var> <var>a<sub>2</sub></var> <var>n<sub>2</sub></var>
:
<var>c<sub>Q</sub></var> <var>a<sub>Q</sub></var> <var>n<sub>Q</sub></var>
</pre>
<p>
1行目の<var>Q</var>(0 ≤ <var>Q</var> ≤ 100)はチーム数を求めたい年数である。続く<var>Q</var>行に各年の役割別の人数が与えられる。各行にはコーダーの人数<var>c<sub>i</sub></var>(0 ≤ <var>c<sub>i</sub></var> ≤ 1000)、アルゴリズマーの人数<var>a<sub>i</sub></var>(0 ≤ <var>a<sub>i</sub></var> ≤ 1000)、ナビゲーターの人数<var>n<sub>i</sub></var>(0 ≤ <var>n<sub>i</sub></var> ≤ 1000)が与えられる。
</p>
<h2>出力</h2>
<p>
年ごとに、作成できる最大のチーム数を1行に出力する。
</p>
<h2>入力例</h2>
<pre>
4
3 0 0
1 1 1
9 4 1
0 1 2
</pre>
<h2>出力例</h2>
<pre>
1
1
4
0
</pre> |
p00626 |
<H1><font color="#000000">Problem F:</font> Chocolate with Heart Marks</H1>
<p>
太郎君はチョコレートが大好きで, 学校から帰るとハートマークが描かれたお気に入りの板チョコを食べます, 最近の楽しみは, すべてのハートマークのブロックを最後まで残すように食べることです. 太郎君は, すべてのハートマークのブロックがつながったまま, できるだけ多くのハートマークのないブロックを食べようとします.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_heartChoco">
</center>
<p>
しかし太郎君はまだ幼く, 上記のように食べようとしても無駄なブロックが残ってしまいます. そこで太郎君は, すべてのハートマークのブロックをつながったまま残すときに食べられる最大のブロック数を求めるプログラムの作成をあなたに依頼しました.
</p>
<p>
太郎君は, すべてのハートマークのブロックがつながっている限り、どんな食べ方をしてもかまいません. ブロックのいずれか一辺が他のブロックに接していないと分かれていることになります.
</p>
<H2>Input</H2>
<p>
入力は複数のデータセットからなります. 各データセットは以下の形式で与えられます:
</p>
<pre>
<i>H W </i>
<i>H</i> × <i>W</i> 個の数字
</pre>
<p>
<i>H</i>, <i>W</i> はそれぞれ板チョコの縦のサイズ, 横のサイズを示す整数です. <i>H</i> × <i>W</i> 個の数字はブロックの情報を表し, ハートマークのないブロックを表す '<span>0</span>', ハートマークのブロックを表す '<span>1</span>' から構成されます.
</p>
<p>
入力の終了は, <i>H</i> = <i>W</i> = 0 であるデータセットによって示されます. このケースに対して出力をしてはいけません.
</p>
<p>
1 ≤ <i>H</i>, <i>W</i> ≤ 12 であり、ハートマークのブロックの数は 6 個以下と仮定してかまいません.
</p>
<H2>Output</H2>
<p>
それぞれのデータセットに対して, 太郎君が食べられる最大のブロック数を出力してください.
</p>
<H2>Sample Input</H2>
<pre>
4 4
1 0 0 0
0 0 1 0
0 1 0 0
1 0 0 1
1 1
1
2 3
1 0 0
0 0 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7
0
2
</pre>
|
p03909 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>H</var> rows and <var>W</var> columns.</p>
<p>The square at the <var>i</var>-th row and <var>j</var>-th column contains a string <var>S_{i,j}</var> of length <var>5</var>.</p>
<p>The rows are labeled with the numbers from <var>1</var> through <var>H</var>, and the columns are labeled with the uppercase English letters from <code>A</code> through the <var>W</var>-th letter of the alphabet.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/90cfa9fb5e04213219ccbc8d08286b4d.png"/></p>
<p>Exactly one of the squares in the grid contains the string <code>snuke</code>. Find this square and report its location.</p>
<p>For example, the square at the <var>6</var>-th row and <var>8</var>-th column should be reported as <code>H6</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦H, W≦26</var></li>
<li>The length of <var>S_{i,j}</var> is <var>5</var>.</li>
<li><var>S_{i,j}</var> consists of lowercase English letters (<code>a</code>-<code>z</code>).</li>
<li>Exactly one of the given strings is equal to <code>snuke</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 labels of the row and the column of the square containing the string <code>snuke</code>, with no space inbetween.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>15 10
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snuke snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>H6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
snuke
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>A1
</pre></section>
</div>
</span> |
p01934 |
<!-- - - - - - begin nicebody - - - - - -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>D: 次元旅行</h1>
<h2>問題</h2>
<p>
次元が $1$ 次元から $N$ 次元まで存在する。
AORイカちゃんは次元間を移動できる。
具体的には、AORイカちゃんが $i$ 次元にいるとき、 $j$ 次元( $i > j$ )には自由に移動する事ができるが、 $k$ 次元( $i < k$ )に移動するには魔法を使う必要がある。
</p>
<p>
AORイカちゃんは $M$ 種類の魔法が使え、 $1, 2, \dots, M$ と番号が振られている。
$i$ 番目の魔法では $a_i$ 次元から $b_i$ 次元に移動できる。
これは $a_i$ 次元にいるときしか使えない。
</p>
<p>
$i$ 次元に行くと次元特有の「次元の呪い」を受ける。
$i$ 次元の「次元の呪い」により、AORイカちゃんは $d_i$ ダメージを負う。
$i$ 次元の「次元の呪い」を受けた場合、その後ずっと、 $j$ 次元( $i > j$ )の「次元の呪い」は受けない。
</p>
<p>
AORイカちゃんが $s$ 次元から $t$ 次元に移動するとき、 負うダメージの合計の最小値を求めよ。
ただし、AORイカちゃんは既に $s$ 次元の「次元の呪い」は受けており、そのダメージは考えないものとする。
また、AORイカちゃんは $t$ 次元に行けることが保証されている。
</p>
<h2>制約</h2>
<ul>
<li>$2 \leq N \leq 10^5$</li>
<li>$1 \leq M \leq min(10^5, N \times (N - 1) / 2)$</li>
<li>$1 \leq s, t \leq N$</li>
<li>$s \neq t$</li>
<li>$1 \leq d_i \leq 10^3$</li>
<li>$1 \leq a_i < b_i \leq N$</li>
<li>$i \neq j$ のとき $( a_i \neq a_j$ または $b_i \neq b_j )$ をみたす</li>
<li>入力は全て整数で与えられる。</li>
</ul>
<h2>入力形式</h2>
<p>
入力は以下の形式で与えられる。
</p>
<p>
$N \ M \ s \ t$<br>
$d_1 \dots d_N$<br>
$a_1 \ b_1$<br>
$a_2 \ b_2$<br>
$\vdots$<br>
$a_M \ b_M$<br>
</p>
<h2>出力</h2>
<p>
AORイカちゃんが受けるダメージの合計の最小値を出力せよ。また、末尾に改行も出力せよ。
</p>
<h2>サンプル</h2>
<h3>サンプル入力 1</h3>
<pre>
3 1 2 3
1 2 3
1 3
</pre>
<h3>サンプル出力 1</h3>
<pre>
3
</pre>
<h3>サンプル入力 2</h3>
<pre>
3 2 1 2
1 3 2
1 2
1 3
</pre>
<h3>サンプル出力 2</h3>
<pre>
2
</pre>
<h3>サンプル入力 3</h3>
<pre>
7 5 2 3
277 390 2 784 401 641 917
2 5
5 6
1 5
2 4
5 7
</pre>
<h3>サンプル出力 3</h3>
<pre>
401
</pre> |
p01467 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>問題文</h2>
<p>2つの整数 $A$,$B$ がある。
十進数での筆算によって $A - B$ を求める処理を以下に示す。</p>
<p> 1. $A$,$B$ を十進数で表現する。添字は下位から順に $0,1,2,...,n-1$ とし、 $A = A_{n-1} A_{n-2} ... A_{0}$,$B = B_{n-1} B_{n-2} ... B_{0}$ とする。 $n$ は十進数で表現した時の$A$の桁数とする。 $B$ の桁数が $n$ より小さいとき、上位桁に $0$ を補う。<br />
2. $borrow_{0} = 0$ とする。<br />
3. 以下の処理を $i = 0$ から $n-1$ まで繰り返す。<br />
3.1. $A_{i} - borrow_{i} \geq B_{i}$ ならば、 $C_{i} = A_{i} - borrow_{i} - B_{i}$ , $borrow_{i+1} = 0$とする。<br />
3.2. $A_{i} - borrow_{i} \lt B_{i}$ ならば、 $C_{i} = A_{i} - borrow_{i} + 10 - B_{i}$ , $borrow_{i+1} = 1$とする。</p>
<p>$A - B$ の計算結果は $C_{n-1} C_{n-2} ... C_{0}$ となる。ただし、最上位に連続する $0$ は取り除く。</p>
<p>繰り下がりを忘れると3.2の処理での $borrow_{i+1} = 1$ が $borrow_{i+1} = 0$ となる。
最大 $K$ 回繰り下がりを忘れたときの計算結果の最大値を求めよ。</p>
<h2>入力</h2>
<p>入力は以下の形式に従う。与えられる数は全て整数である。<br>
<br>
<pre>$A$ $B$ $K$</pre>
<h2>制約</h2>
<ul><li>$1 \leq B \lt A \leq 10^9$</li>
<li>$1 \leq K \leq 9$</li></ul>
<h2>出力</h2>
<p>計算結果の最大値を1行に出力せよ。</p>
<h2>Sample Input 1</h2>
<pre>99 98 1</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1</pre>
<h2>Sample Input 2</h2>
<pre>100 2 3</pre>
<h2>Output for the Sample Input 2</h2>
<pre>198</pre>
<h2>Sample Input 3</h2>
<pre>538 84 1</pre>
<h2>Output for the Sample Input 3</h2>
<pre>554</pre>
<h2>Sample Input 4</h2>
<pre>2012 1987 1</pre>
<h2>Output for the Sample Input 4</h2>
<pre>1025</pre>
|
p01037 |
<h1>Problem A: A White Wall</h1>
<h2>Background</h2>
<p>
とある都市に住むA氏の家の敷地は、真っ白な壁に囲まれている。壁に物足りなさを感じたA氏は、近所の子供たちを呼んで、壁を自由に塗ってもらうことにした。子供達にはそれぞれ壁の好きな区間を選んで色を塗ってもらう。 さて、壁はどのように塗られただろうか。
</p>
<h2>Problem</h2>
<p>
0〜<var>N</var>-1の区画で構成される以下のような円型の白い壁がある。
</p>
<br>
<left>
<img width="480" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_A.png" alt="図1"><br>
</left>
<br>
<p>
<var>M</var>人の子供たちがこの壁の開始位置<var>a</var>と開始位置からの長さ<var>L</var>を指定し、反時計回りに<var>a</var>から<var>(a+L)</var> <var>mod</var> <var>N</var>まで色を塗る(ただし、<var>a</var> <var>mod</var> <var>N</var>とは、<var>a</var>を<var>N</var>で割ったときの余りを表す)。ここで、他の人が色を塗った区間と重ねて塗ることもでき、その場合は、色が塗られた1つの区間とみなす。色が塗られた区間を大きい順に出力せよ。また、その大きさの区間がいくつあるかも同時に出力せよ。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
<var>N</var> <var>M</var>
<var>a<sub>0</sub></var> <var>L<sub>0</sub></var>
<var>a<sub>1</sub></var> <var>L<sub>1</sub></var>
...
<var>a<sub>M−1</sub></var> <var>L<sub>M−1</sub></var>
</pre>
<p>
1行目にそれぞれ壁の長さと壁に色を塗る人の数を表す2つの整数<var>N</var>,<var>M</var>が空白区切りで与えられる。続く<var>M</var>行には、各人が色を塗る区間の開始位置<var>a<sub>i</sub></var>と長さ<var>L<sub>i</sub></var>が与えられる。
<h2>Constrains</h2>
<p>入力は以下の条件を満たす</p>
<ul>
<li>2 ≤ <var>N</var> ≤ 100</li>
<li>1 ≤ <var>M</var> ≤ 50</li>
<li>0 ≤ <var>a<sub>i</sub></var> < <var>N</var></li>
<li>1 ≤ <var>L<sub>i</sub></var> ≤ <var>N</var></li>
</ul>
<h2>Output</h2>
<p>
色が塗られた区間の長さとその長さの総数を色が塗られた区間が大きい順に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
5 3
0 1
2 1
3 1
</pre>
<h2>Sample Output 1</h2>
<pre>
2 1
1 1
</pre>
<h2>Sample Input 2</h2>
<pre>
4 2
0 2
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
3 1
</pre>
<h2>Sample Input 3</h2>
<pre>
10 3
2 1
4 1
9 2
</pre>
<h2>Sample Output 3</h2>
<pre>
2 1
1 2
</pre>
|
p02162 | <h1>Problem A: AOJ50M</h1>
<h2>Problem</h2>
<p>
AliceとBobが50m走で勝負しています。<br>
しかし、この世界においてはAOJのレートが高い方が偉いので、AOJのレートが高い方が勝ちます。<br>
どちらか一方でもAOJのレートが無い場合は比べようが無いので、仕方なく50m走のタイムで勝負します。この場合はタイムが短い方を勝ちとします。<br>
AOJのレートが同じ場合は引き分け、50m走のタイムで勝負しなければならない場合はタイムが同じなら引き分けです。<br>
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
$T_1$ $T_2$ $R_1$ $R_2$
</pre>
<p>
各要素が空白区切りで与えられる。<br>
$T_1,T_2$ はそれぞれAlice、Bobの50m走のタイムを、$R_1,R_2$ はそれぞれAlice、BobのAOJのレートを表す。<br>
ただし、$R_1=-1$ のときはAliceのレートがないことを、$R_2=-1$ のときはBobのレートがないことを示す。
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$1 \leq T_1,T_2 \lt 100 $</li>
<li>$-1 \leq R_1,R_2 \lt 2850 $</li>
<li>入力は全て整数である</li>
</ul>
<h2>Output</h2>
<p>
Aliceが勝つならなら"Alice"を、Bobが勝つならなら"Bob"を、引き分けであれば"Draw"を$1$行に出力せよ。<br>
</p>
<h2>Sample Input 1</h2>
<pre>
9 8 1000 999
</pre>
<h2>Sample Output 1</h2>
<pre>
Alice
</pre>
<p>
Aliceの方がAOJのレートが高いため、Aliceの勝ちです。
</p>
<h2>Sample Input 2</h2>
<pre>
9 8 1000 1000
</pre>
<h2>Sample Output 2</h2>
<pre>
Draw
</pre>
<p>
AliceとBobのAOJのレートが同じため、引き分けです。この場合50m走の結果は関係がないことに注意してください。
</p>
<h2>Sample Input 3</h2>
<pre>
9 8 2849 -1
</pre>
<h2>Sample Output 3</h2>
<pre>
Bob
</pre>
<p>
Aliceのレートは高いですが、Bobのレートが無いため50m走のタイムが短いBobの勝ちです。
</p>
|
p03323 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>E869120's and square1001's <var>16</var>-th birthday is coming soon.<br/>
Takahashi from AtCoder Kingdom gave them a round cake cut into <var>16</var> equal fan-shaped pieces.</p>
<p>E869120 and square1001 were just about to eat <var>A</var> and <var>B</var> of those pieces, respectively,<br/>
when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".</p>
<p>Can both of them obey the instruction in the note and take desired numbers of pieces of cake?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>A</var> and <var>B</var> are integers between <var>1</var> and <var>16</var> (inclusive).</li>
<li><var>A+B</var> is at most <var>16</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print <code>Yay!</code>; otherwise, print <code>:(</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yay!
</pre>
<p>Both of them can take desired number of pieces as follows:
<img alt=" " src="https://img.atcoder.jp/abc100/e87fa456a900ac9ae36671ae8bd5eeea.png"/></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>Yay!
</pre>
<p>Both of them can take desired number of pieces as follows:
<img alt=" " src="https://img.atcoder.jp/abc100/a7989ac033e6ba86e14078864c20d9c5.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>:(
</pre>
<p>In this case, there is no way for them to take desired number of pieces, unfortunately.</p></section>
</div>
</span> |
p03289 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var>. Each character of <var>S</var> is uppercase or lowercase English letter.
Determine if <var>S</var> satisfies all of the following conditions:</p>
<ul>
<li>The initial character of <var>S</var> is an uppercase <code>A</code>.</li>
<li>There is exactly one occurrence of <code>C</code> between the third character from the beginning and the second to last character (inclusive).</li>
<li>All letters except the <code>A</code> and <code>C</code> mentioned above are lowercase.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 ≤ |S| ≤ 10</var> (<var>|S|</var> is the length of the string <var>S</var>.)</li>
<li>Each character of <var>S</var> is uppercase or lowercase English letter.</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> satisfies all of the conditions in the problem statement, print <code>AC</code>; otherwise, print <code>WA</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>AtCoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>AC
</pre>
<p>The first letter is <code>A</code>, the third letter is <code>C</code> and the remaining letters are all lowercase, so all the conditions are satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ACoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>WA
</pre>
<p>The second letter should not be <code>C</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>AcycliC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>WA
</pre>
<p>The last letter should not be <code>C</code>, either.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>AtCoCo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>WA
</pre>
<p>There should not be two or more occurrences of <code>C</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>Atcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>WA
</pre>
<p>The number of <code>C</code> should not be zero, either.</p></section>
</div>
</span> |
p02861 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> towns in a coordinate plane. Town <var>i</var> is located at coordinates (<var>x_i</var>, <var>y_i</var>). The distance between Town <var>i</var> and Town <var>j</var> is <var>\sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}</var>.</p>
<p>There are <var>N!</var> possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, <var>\dots</var>, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these <var>N!</var> paths.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 8</var></li>
<li><var>-1000 \leq x_i \leq 1000</var></li>
<li><var>-1000 \leq y_i \leq 1000</var></li>
<li><var>\left(x_i, y_i\right) \neq \left(x_j, y_j\right)</var> (if <var>i \neq j</var>)</li>
<li>(Added 21:12 JST) All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 0
1 0
0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2.2761423749
</pre>
<p>There are six paths to visit the towns: <var>1</var> → <var>2</var> → <var>3</var>, <var>1</var> → <var>3</var> → <var>2</var>, <var>2</var> → <var>1</var> → <var>3</var>, <var>2</var> → <var>3</var> → <var>1</var>, <var>3</var> → <var>1</var> → <var>2</var>, and <var>3</var> → <var>2</var> → <var>1</var>.</p>
<p>The length of the path <var>1</var> → <var>2</var> → <var>3</var> is <var>\sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}</var>.</p>
<p>By calculating the lengths of the other paths in this way, we see that the average length of all routes is:</p>
<p><var>\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...</var></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
-879 981
-866 890
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>91.9238815543
</pre>
<p>There are two paths to visit the towns: <var>1</var> → <var>2</var> and <var>2</var> → <var>1</var>. These paths have the same length.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7641.9817824387
</pre></section>
</div>
</span> |
p03773 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.<br/>
In this country, 24-hour clock is used. For example, <var>9:00</var> p.m. is referred to as "<var>21</var> o'clock".<br/>
The current time is <var>A</var> o'clock, and a contest will begin in exactly <var>B</var> hours.
When will the contest begin? Answer in 24-hour time.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A,B \leq 23</var></li>
<li><var>A</var> and <var>B</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the hour of the starting time of the contest in 24-hour time.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>21
</pre>
<p>In this input, the current time is <var>9</var> o'clock, and <var>12</var> hours later it will be <var>21</var> o'clock in 24-hour time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>19 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>19
</pre>
<p>The contest has just started.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>23 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p>The contest will begin at <var>1</var> o'clock the next day.</p></section>
</div>
</span> |
p03266 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given integers <var>N</var> and <var>K</var>. Find the number of triples <var>(a,b,c)</var> of positive integers not greater than <var>N</var> such that <var>a+b,b+c</var> and <var>c+a</var> are all multiples of <var>K</var>.
The order of <var>a,b,c</var> does matter, and some of them can be the same.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,K \leq 2\times 10^5</var></li>
<li><var>N</var> and <var>K</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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of triples <var>(a,b,c)</var> of positive integers not greater than <var>N</var> such that <var>a+b,b+c</var> and <var>c+a</var> are all multiples of <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p><var>(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1)</var> and <var>(3,3,3)</var> satisfy the condition.</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>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31415 9265
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>27
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>35897 932
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>114191
</pre></section>
</div>
</span> |
p02924 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For an integer <var>N</var>, we will choose a permutation <var>\{P_1, P_2, ..., P_N\}</var> of <var>\{1, 2, ..., N\}</var>.</p>
<p>Then, for each <var>i=1,2,...,N</var>, let <var>M_i</var> be the remainder when <var>i</var> is divided by <var>P_i</var>.</p>
<p>Find the maximum possible value of <var>M_1 + M_2 + \cdots + M_N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an integer satisfying <var>1 \leq N \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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible value of <var>M_1 + M_2 + \cdots + M_N</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>When the permutation <var>\{P_1, P_2\} = \{2, 1\}</var> is chosen, <var>M_1 + M_2 = 1 + 0 = 1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>78
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p00919 |
<H1><font color="#000">Problem F: </font>Directional Resemblance</H1>
<p>
Vectors have their directions and two vectors make an angle between them. Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. A dataset specifies a set of three-dimensional vectors, some of which are directly given in the dataset and the others are generated by the procedure described below.
</p>
<p>
Each dataset is formatted as follows.
</p>
<pre>
<var>m</var> <var>n</var> <var>S</var> <var>W</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var>
:
<var>x<sub>m</sub></var> <var>y<sub>m</sub></var> <var>z<sub>m</sub></var>
</pre>
<p>
The first line contains four integers <var>m</var>, <var>n</var>, <var>S</var>, and <var>W</var>.
</p>
<p>
The integer <var>m</var> is the number of vectors whose three components are directly specified in the
dataset. Starting from the second line, <var>m</var> lines have the three components of <var>m</var> vectors. The <var>i</var>-th line of which indicates the vector <var>v<sub>i</sub></var> = (<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>, <var>z<sub>i</sub></var>). All the vector components are positive integers less than or equal to 100.
</p>
<p>
The integer <var>n</var> is the number of vectors generated by the following procedure.
</p>
<pre>
int g = S;
for(int i=m+1; i<=m+n; i++) {
x[i] = (g/7) %100 + 1;
y[i] = (g/700) %100 + 1;
z[i] = (g/70000)%100 + 1;
if( g%2 == 0 ) { g = (g/2); }
else { g = (g/2) ^ W; }
}
</pre>
<p>
For <var>i = m + 1, . . . , m + n</var>, the <var>i</var>-th vector <var>v<sub>i</sub></var> of the set has three components <span>x[i]</span>, <span>y[i]</span>, and <span>z[i]</span> generated by this procedure.
</p>
<p>
Here, values of <span>S</span> and <span>W</span> are the parameters <var>S</var> and <var>W</var> given in the first line of the dataset. You may assume 1 ≤ <var>S</var> ≤ 10<sup>9</sup> and 1 ≤ <var>W</var> ≤ 10<sup>9</sup>.
</p>
<p>
The total number of vectors satisfies 2 ≤ <var>m + n</var> ≤ 12 × 10<sup>4</sup>. Note that exactly the same vector may be specified twice or more in a single dataset.
</p>
<p>
A line containing four zeros indicates the end of the input. The total of <var>m+n</var> for all the datasets in the input never exceeds 16 × 10<sup>5</sup>.
</p>
<H2>Output</H2>
<p>
For each dataset, output the pair of vectors among the specified set with the smallest non-zero angle in between. It is assured that there are at least two vectors having different directions.
</p>
<p>
Vectors should be indicated by their three components. The output for a pair of vectors <var>v<sub>a</sub></var> and <var>v<sub>b</sub></var> should be formatted in a line as follows.
</p>
<pre>
<var>x<sub>a</sub></var> <var>y<sub>a</sub></var> <var>z<sub>a</sub></var> <var>x<sub>b</sub></var> <var>y<sub>b</sub></var> <var>z<sub>b</sub></var>
</pre>
<p>
Two vectors (<var>x<sub>a</sub></var>, <var>y<sub>a</sub></var>, <var>z<sub>a</sub></var>) and (<var>x<sub>b</sub></var>, <var>y<sub>b</sub></var>, <var>z<sub>b</sub></var>) are ordered in the dictionary order, that is, <var>v<sub>a</sub></var> < <var>v<sub>b</sub></var> if <var>x<sub>a</sub></var> < <var>x<sub>b</sub></var>, or if <var>x<sub>a</sub> = x<sub>b</sub></var> and <var>y<sub>a</sub></var> < <var>y<sub>b</sub></var>, or if <var>x<sub>a</sub> = x<sub>b</sub></var>, <var>y<sub>a</sub> = y<sub>b</sub></var> and <var>z<sub>a</sub></var> < <var>z<sub>b</sub></var>. When a vector pair is output, the smaller vector in this order should be output first.
</p>
<p>
If more than one pair makes the equal smallest angle, the pair that is the smallest among them in the dictionary order between vector pairs should be output. The pair (<var>v<sub>i</sub></var>, <var>v<sub>j</sub></var>) is smaller than the pair (<var>v<sub>k</sub></var>, <var>v<sub>l</sub></var>) if <var>v<sub>i</sub></var> < <var>v<sub>k</sub></var>, or if <var>v<sub>i</sub> = v<sub>k</sub></var> and <var>v<sub>j</sub></var> < <var>v<sub>l</sub></var>.
</p>
<H2>Sample Input</H2>
<pre>
4 0 2013 1124
1 1 1
2 2 2
2 1 1
1 2 1
2 100 131832453 129800231
42 40 46
42 40 46
0 100000 7004674 484521438
0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 1 1 1 2 1
42 40 46 83 79 91
92 92 79 99 99 85
</pre> |
p03636 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The word <code>internationalization</code> is sometimes abbreviated to <code>i18n</code>.
This comes from the fact that there are <var>18</var> letters between the first <code>i</code> and the last <code>n</code>.</p>
<p>You are given a string <var>s</var> of length at least <var>3</var> consisting of lowercase English letters.
Abbreviate <var>s</var> in the same way.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 ≤ |s| ≤ 100</var> (<var>|s|</var> denotes the length of <var>s</var>.)</li>
<li><var>s</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the abbreviation of <var>s</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>internationalization
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>i18n
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>smiles
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>s4s
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>xyz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>x1z
</pre></section>
</div>
</span> |
p02477 | <h2>Multiplication of Big Integers II</h2>
<p>
Given two integers $A$ and $B$, compute the product, $A \times B$.
</p>
<h3>Input</h3>
<p>
Two integers $A$ and $B$ separated by a space character are given in a line.
</p>
<h3>Output</h3>
<p>
Print the product in a line.
</p>
<h3>Constraints</h3>
<ul>
<li>$-1 \times 10^{200000} \leq A, B \leq 10^{200000}$</li>
</ul>
<h3>Sample Input 1</h3>
<pre>
5 8
</pre>
<h3>Sample Output 1</h3>
<pre>
40
</pre>
<h3>Sample Input 2</h3>
<pre>
100 25
</pre>
<h3>Sample Output 2</h3>
<pre>
2500
</pre>
<h3>Sample Input 3</h3>
<pre>
-1 0
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
12 -3
</pre>
<h3>Sample Output 4</h3>
<pre>
-36
</pre>
|
p02027 | <h2>M: プレゼント (Presents)</h2>
<p>白羽さんは、とある悪魔にサプライズプレゼントとして次のような集合を用意した。</p>
<ul>
<li>$N$ 以下の異なる $K$ 個の自然数からなる</li>
<li>どの 2 つの値の組を集合から選んでも、片方の数がもう片方の数で割り切れる</li>
</ul>
<p>実はこのような集合には悪魔の力を奪う性質があり、このままだと力を失ってしまう。</p>
<p>悪魔を助けるために、このような集合がいくつあるか計算せよ。</p>
<h3>入力</h3>
<p>2 つの整数 $N, K$ が空白区切りで与えられる。</p>
<h3>出力</h3>
<p>条件を満たす集合の個数を出力せよ。</p>
<h3>制約</h3>
<ul>
<li>$N$ は $1$ 以上 $100 \ 000$ 以下の整数</li>
<li>$K$ は $1$ 以上 $N$ 以下の整数</li>
</ul>
<h3>入力例1</h3>
<pre>
6 3
</pre>
<h3>出力例1</h3>
<pre>
3
</pre>
<p>集合 $(1,2,4), (1,2,6), (1,3,6)$ が条件を満たす。</p>
<h3>入力例2</h3>
<pre>
100000 7
</pre>
<h3>出力例2</h3>
<pre>
58848855
</pre>
<p>$N = 100 \ 000, K = 7$ のとき、条件を満たす集合は $58 \ 848 \ 855$ 通りある。</p>
|
p01867 |
<!-- - - - - - begin nicebody - - - - - -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>C: 足し算掛け算 / AddMul</h1>
<h2>問題文</h2>
<p>
情太くんは <code>a</code> から <code>z</code> までの文字と,
足し算の記号 <code>+</code> しか知りません.
情太くんには姉の立子さんがいます.
立子さんはそれに加えて,掛け算 <code>*</code> と括弧 <code>(</code>,<code>)</code>,
そして <code>1</code> 以上 <code>9</code> 以下の整数 (数字) も知っています.
しかし,括弧を多重に使用すること,括弧の中で掛け算を行うことは知りません.
</p>
<p>
例えば,次のような数式があったとします.
</p>
<ol>
<li><code>a+a+a</code></li>
<li><code>a+4*(b+c)</code></li>
<li><code>a+3*(b+2*(c+d))</code></li>
<li><code>a-b</code></li>
<li><code>a/b</code></li>
<li><code>11*a</code></li>
</ol>
<p>
このうち,情太くんは 1. のみ,立子さんは 1. と 2. を書くことができます.
3. から 6. は二人とも書くことができません.
</p>
<p>
ある日,情太くんは文字列としての長さが $n$ の多項式 $S$ を書きました.
ショートコーダーの立子さんは,掛け算と括弧と <code>1</code> 以上 <code>9</code>
以下の整数を使って,$S$ を文字列としてより短い恒等な多項式 $T$ に書きなおしてやりたいと思っています.
しかし,そう簡単ではないようです.
</p>
<p>
さて,立子さんのかわりに,文字列として最も短い $T$ を作り,
その長さを出力するプログラムを書いてください.
</p>
<h2>入力</h2>
<p>
$N$<br>
$S$<br>
</p>
<h2>制約</h2>
<p>
$1 \leq N \leq 499$<br>
$N$ は奇数である<br>
$S$ は <code>a</code> から <code>z</code> までのアルファベット小文字と
<code>+</code> のみからなる<br>
$S$ の最初の文字はアルファベットであり,その後 <code>+</code>
とアルファベット $1$ 文字が交互に並ぶ<br>
$S$ に同じアルファベットは $9$ 個以下しか含まれない<br>
</p>
<h2>出力</h2>
<p>
答えを $1$ 行で出力してください.
</p>
<h2>サンプル</h2>
<h3>サンプル入力1</h3>
<pre>
5
a+a+a
</pre>
<h3>サンプル出力1</h3>
<pre>
3
</pre>
<p>
<code>a*3</code> の $3$ 文字が最短です.
</p>
<h3>サンプル入力2</h3>
<pre>
9
a+a+b+a+b
</pre>
<h3>サンプル出力2</h3>
<pre>
7
</pre>
<p>
<code>a*3+2*b</code> または <code>a*3+b+b</code> の $7$ 文字が最短です.
</p>
<h3>サンプル入力3</h3>
<pre>
11
a+a+b+a+b+b
</pre>
<h3>サンプル出力3</h3>
<pre>
7
</pre>
<p>
<code>(a+b)*3</code> で $7$ 文字
</p>
<h3>サンプル入力4</h3>
<pre>
3
a+a
</pre>
<h3>サンプル出力4</h3>
<pre>
3
</pre>
<p>
<code>a+a</code> または <code>a*2</code> で $3$ 文字
</p>
<!-- - - - - - end nicebody - - - - - --> |
p02748 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>You are visiting a large electronics store to buy a refrigerator and a microwave.</p>
<p>The store sells <var>A</var> kinds of refrigerators and <var>B</var> kinds of microwaves. The <var>i</var>-th refrigerator ( <var>1 \le i \le A</var> ) is sold at <var>a_i</var> yen (the currency of Japan), and the <var>j</var>-th microwave ( <var>1 \le j \le B</var> ) is sold at <var>b_j</var> yen.</p>
<p>You have <var>M</var> discount tickets. With the <var>i</var>-th ticket ( <var>1 \le i \le M</var> ), you can get a discount of <var>c_i</var> yen from the total price when buying the <var>x_i</var>-th refrigerator and the <var>y_i</var>-th microwave together. Only one ticket can be used at a time.</p>
<p>You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers.</li>
<li><var> 1 \le A \le 10^5 </var></li>
<li><var> 1 \le B \le 10^5 </var></li>
<li><var> 1 \le M \le 10^5 </var></li>
<li><var> 1 \le a_i , b_i , c_i \le 10^5 </var></li>
<li><var> 1 \le x_i \le A </var></li>
<li><var> 1 \le y_i \le B </var></li>
<li><var> c_i \le a_{x_i} + b_{y_i} </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>M</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_A</var>
<var>b_1</var> <var>b_2</var> <var>...</var> <var>b_B</var>
<var>x_1</var> <var>y_1</var> <var>c_1</var>
<var>\vdots</var>
<var>x_M</var> <var>y_M</var> <var>c_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1
3 3
3 3 3
1 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>With the ticket, you can get the <var>1</var>-st refrigerator and the <var>2</var>-nd microwave for <var>3+3-1=5</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1 2
10
10
1 1 5
1 1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
<p>Note that you cannot use more than one ticket at a time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 2 1
3 5
3 5
2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6
</pre>
<p>You can get the <var>1</var>-st refrigerator and the <var>1</var>-st microwave for <var>6</var> yen, which is the minimum amount to pay in this case.
Note that using a ticket is optional.</p></section>
</div>
</span> |
p00775 |
<h3>Vampire</h3>
<p>
Mr. C is a vampire. If he is exposed to the sunlight directly, he turns
into ash.
Nevertheless, last night, he attended to the meeting of Immortal and
Corpse Programmers
Circle, and he has to go home in the near dawn.
Fortunately, there are many tall buildings around Mr. C's home, and
while the sunlight is blocked by the buildings, he can move around
safely.
The top end of the sun has just reached the horizon now.
In how many seconds does Mr. C have to go into his safe coffin?
</p>
<p>
To simplify the problem, we represent the eastern dawn sky as a 2-dimensional
<i>x</i>-<i>y</i> plane, where the <i>x</i> axis is horizontal and the <i>y</i> axis
is vertical, and approximate building silhouettes by rectangles
and the sun by a circle on this plane.
</p>
<p>
The <i>x</i> axis represents the horizon.
We denote the time by <i>t</i>, and the current time is <i>t</i>=0.
The radius of the sun is <i>r</i> and
its center is at (0, -<i>r</i>) when the time <i>t</i>=0.
The sun moves on the <i>x</i>-<i>y</i> plane in a uniform linear motion at
a constant velocity of (0, 1) per second.
</p>
<p>
The sunlight is blocked if and only if the entire region of the sun
(including its edge) is included in the union of the silhouettes
(including their edges) and the region below the horizon (y ≤ 0).
</p>
<p>
Write a program that computes the time of the last moment when the sunlight is blocked.
</p>
<p>
The following figure shows the layout of silhouettes and the position of the sun at
the last moment when the sunlight is blocked, that corresponds to the
first dataset of Sample Input below. As this figure indicates, there are possibilities
that the last moment when the sunlight is blocked can be the time <i>t</i>=0.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_domestic2014_C_fig0" width="400px">
</center>
<br>
<p>
The sunlight is blocked even when two silhouettes share parts of their edges.
The following figure shows the layout of silhouettes and the position of the sun at the
last moment when the sunlight is blocked, corresponding to the second
dataset of Sample Input.
In this dataset the radius of the sun is 2 and there are two silhouettes:
the one with height 4 is in -2 ≤ <i>x</i> ≤ 0, and
the other with height 3 is in 0 ≤ <i>x</i> ≤ 2.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_domestic2014_C_fig1" width="400px">
</center>
<br>
<h3>Input</h3>
<p>
The input consists of multiple datasets.
The first line of a dataset contains two
integers <i>r</i> and <i>n</i> separated by a space.
<i>r</i> is the radius of the sun and <i>n</i> is the number of silhouettes
of the buildings.
(1 ≤ <i>r</i> ≤ 20, 0 ≤ <i>n</i> ≤ 20)
</p><p>
Each of following <i>n</i> lines contains three integers
<i>x<sub>li</sub></i>, <i>x<sub>ri</sub></i>, <i>h<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) separated by a space.
</p>
<p>
These three integers represent a silhouette rectangle of a building.
The silhouette rectangle is parallel to the horizon, and its left and right edges
are at <i>x</i> = <i>x<sub>li</sub></i> and <i>x</i> = <i>x<sub>ri</sub></i>, its top
edge is at <i>y</i> = <i>h<sub>i</sub></i>, and its bottom edge is on
the horizon.
(-20 ≤ <i>x<sub>li</sub></i> < <i>x<sub>ri</sub></i> ≤ 20,
0 < <i>h<sub>i</sub></i> ≤ 20)
</p><p>
The end of the input is indicated by a line containing two zeros separated by a space.
</p>
<p>
Note that these silhouettes may overlap one another.
</p>
<h3>Output</h3>
<p>
For each dataset, output a line containing the number indicating the time <i>t</i> of the last moment when the sunlight is blocked.
The value should not have an error greater than 0.001.
No extra characters should appear in the output.
</p>
<h3>Sample Input</h3>
<pre>2 3
-2 -1 3
0 1 3
2 3 3
2 2
-2 0 4
0 2 3
2 6
-3 3 1
-2 3 2
-1 3 3
0 3 4
1 3 5
2 3 6
2 6
-3 3 1
-3 2 2
-3 1 3
-3 0 4
-3 -1 5
-3 -2 6
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>0.0000
3.0000
2.2679
2.2679
</pre> |
p02318 |
<H1>Edit Distance (Levenshtein Distance)</H1>
<br/>
<p>
Find the edit distance between given two words <var>s1</var> and <var>s2</var>.
</p>
<p>
The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations:
</p>
<ul>
<li><strong>insertion</strong>: Insert a character at a particular position.</li>
<li><strong>deletion</strong>: Delete a character at a particular position. </li>
<li><strong>substitution</strong>: Change the character at a particular position to a different character </li>
</ul>
<H2>Input</H2>
<pre>
<var>s1</var>
<var>s2</var>
</pre>
<p>
Two words <var>s1</var> and <var>s2</var> are given in the first line and the second line respectively. The words will consist of lower case characters.
</p>
<H2>Output</H2>
<p>
Print the edit distance in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ length of <var>s1</var> ≤ 1000</li>
<li>1 ≤ length of <var>s2</var> ≤ 1000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
acac
acm
</pre>
<H2>Sample Output 1</H2>
<pre>
2
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
icpc
icpc
</pre>
<H2>Sample Output 2</H2>
<pre>
0
</pre> |
p00325 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>プログラム停止判定</H1>
<p>
皆さんは、苦労して作ったプログラムを実行してみたら、無限ループになってしまった経験はありませんか? プログラムの実行が停止するかどうかを、実行しなくても事前に判定できると便利ですよね。
</p>
<p>
残念ながら、皆さんがふだん使っているプログラミング言語では、あらゆるプログラムに対してそのような判定をすることは不可能です。しかし、それよりもはるかに計算能力の低いプログラミング言語なら、その言語で書いたプログラムが停止するかどうかを判定するプログラムを書ける場合があります。
</p>
<p>
TinyPowerというプログラミング言語を考えます。この言語のプログラムは行の並びです。プログラムの各行には、先頭に行番号を書き、その後ろに文を一つ書きます。この言語で書ける文の種類は以下の通りです。
</p>
<center>
<table width="680">
<tr>
<th style="text-align:left" width="200">文の種類</th>
<th style="text-align:left">動作</th>
</tr>
<tr>
<td>ADD var<sub>1</sub> var<sub>2</sub> var<sub>3</sub></td>
<td>変数 var<sub>2</sub> の値と var<sub>3</sub> の値を加算した結果を変数 var<sub>1</sub>に代入する</td>
</tr>
<tr>
<td>ADD var<sub>1</sub> var<sub>2</sub> con</td>
<td>変数 var<sub>2</sub> の値と定数 con を加算した結果を変数 var<sub>1</sub> に代入する</td>
</tr>
<tr>
<td>SUB var<sub>1</sub> var<sub>2</sub> var<sub>3</sub></td>
<td>変数 var<sub>2</sub> の値から var<sub>3</sub> の値を減算した結果を変数 var<sub>1</sub> に代入する</td>
</tr>
<tr>
<td>SUB var<sub>1</sub> var<sub>2</sub> con</td>
<td>変数 var<sub>2</sub> の値から定数 con を減算した結果を変数 var<sub>1</sub> に代入する</td>
</tr>
<tr>
<td>SET var<sub>1</sub> var<sub>2</sub></td>
<td>変数 var<sub>2</sub>の値を変数 var<sub>1</sub> に代入する</td>
</tr>
<tr>
<td>SET var<sub>1</sub> con</td>
<td>定数 con を変数 var<sub>1</sub> に代入する</td>
</tr>
<tr>
<td>IF var<sub>1</sub> dest</td>
<td>変数 var<sub>1</sub> の値が0でないときだけ、行番号 dest にジャンプする</td>
</tr>
<tr>
<td>HALT</td>
<td>プログラムを停止させる</td>
</tr>
</table>
</center>
<br/>
<p>
行番号は正の整数で、プログラム中に同じ行番号が2つ以上現れることはありません。変数は英小文字一文字で表し、定数と変数の値は整数です。変数の宣言は不要で、変数の初期値は0です。
</p>
<p>
プログラムの実行は先頭の文から始まり、並んでいる順に文が実行されます。ただし、上の表に書かれたように、IF文の変数の値が0でないときは、変数の後ろに書かれた行番号で指定される行にジャンプし、その行に書かれた文から実行を続けます。プログラムは以下のときに停止します。
</p>
<ul>
<li> HALT文を実行したとき。</li>
<li> 負の整数または16以上の整数を変数に代入しようとしたとき(変数の値は更新されない)。</li>
<li> プログラムに現れない行番号にジャンプしようとしたとき。</li>
<li> プログラムの最後の文を実行した後、そこからどの行にもジャンプしないとき。</li>
</ul>
<p>
TinyPowerのプログラムが与えられたとき、それが停まるかどうかを判定するプログラムを作成せよ。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var>
<var>stmt<sub>1</sub></var>
<var>stmt<sub>2</sub></var>
:
<var>stmt<sub>N</sub></var>
</pre>
<p>
1行目にプログラムの行数 <var>N</var> (1 ≤ <var>N</var> ≤ 50) が与えられる。続く <var>N</var> 行に、TinyPowerプログラムの文 <var>stmt<sub>i</sub></var> が与えられる。<var>stmt<sub>i</sub></var> は、以下のいずれかの形式で与えられる。
</p>
<pre>
<var>line</var> ADD <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>var<sub>3</sub></var>
</pre>
<p>または</p>
<pre>
<var>line</var> ADD <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>con</var>
</pre>
<p>または</p>
<pre>
<var>line</var> SUB <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>var<sub>3</sub></var>
</pre>
<p>または</p>
<pre>
<var>line</var> SUB <var>var<sub>1</sub></var> <var>var<sub>2</sub></var> <var>con</var>
</pre>
<p>または</p>
<pre>
<var>line</var> SET <var>var<sub>1</sub></var> <var>var<sub>2</sub></var>
</pre>
<p>または</p>
<pre>
<var>line</var> SET <var>var<sub>1</sub></var> <var>con</var>
</pre>
<p>または</p>
<pre>
<var>line</var> IF <var>var<sub>1</sub></var> <var>dest</var>
</pre>
<p>または</p>
<pre>
<var>line</var> HALT
</pre>
<p>
<var>line</var>, <var>dest</var> (1 ≤ <var>line</var>, <var>dest</var> ≤ 1000) は行番号、<var>var<sub>j</sub></var> (英小文字1文字)は変数、<var>con</var> (0 ≤ <var>con</var> ≤ 15) は定数を表す。<var>stmt<sub>i</sub></var> 中の区切りは空白1文字とする。なお、プログラム中に変数は必ず1つ以上現れ、異なる変数名は5つまでしか現れないものとする。
</p>
<h2>Output</h2>
<p>
プログラムが停止するときは、プログラムに現れる変数の結果を、変数名の辞書順に改行区切りで出力し、停止しないときは「inf」を出力する。変数の結果は、変数名と変数の値を「=」で区切って出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
6
10 SET c 1
20 SET i 5
100 ADD s s i
110 SUB i i c
120 IF i 100
200 HALT
</pre>
<h2>Sample Output 1</h2>
<pre>
c=1
i=0
s=15
</pre>
<p>
入力例1は、1から5までの整数の和を計算し、その結果を変数sに格納したあと、HALT文の実行で停止する。
</p>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
10 SET c 1
120 IF c 10
20 HALT
</pre>
<h2>Sample Output 2</h2>
<pre>
inf
</pre>
<p>
入力例2は、行番号10でcに1を代入し、次の行番号120のIF文で行番号10に戻ることを繰り返すので、停止しない。
</p>
<br/>
<h2>Sample Input 3</h2>
<pre>
3
111 SET c 1
12 SUB c c 2
777 SET a 4
</pre>
<h2>Sample Output 3</h2>
<pre>
a=0
c=1
</pre>
<p>
入力例3は、行番号111でcに1を代入し、次の行番号12でcに-1を代入しようとするので、停止する。このときcの値は-1に更新されない。行番号777は実行されないので、aの値は初期値0のままである。
</p> |
p01164 |
<H1><font color="#000">Problem B:</font> Sort the Panels</H1>
<p>
There was an explorer Henry Nelson traveling all over the world. One day he reached an ancient
building. He decided to enter this building for his interest, but its entrance seemed to be locked
by a strange security system.
</p>
<p>
There were some black and white panels placed on a line at equal intervals in front of the
entrance, and a strange machine with a cryptogram attached. After a while, he managed to
read this cryptogram: this entrance would be unlocked when the panels were rearranged in a
certain order, and he needed to use this special machine to change the order of panels.
</p>
<p>
All he could do with this machine was to swap arbitrary pairs of panels. Each swap could be
performed by the following steps:
</p>
<ul>
<li>move the machine to one panel and mark it;</li>
<li>move the machine to another panel and again mark it; then</li>
<li>turn on a special switch of the machine to have the two marked panels swapped.</li>
</ul>
<p>
It was impossible to have more than two panels marked simultaneously. The marks would be
erased every time the panels are swapped.
</p>
<p>
He had to change the order of panels by a number of swaps to enter the building. Unfortunately,
however, the machine was so heavy that he didn’t want to move it more than needed. Then
which steps could be the best?
</p>
<p>
Your task is to write a program that finds the minimum cost needed to rearrange the panels,
where moving the machine between adjacent panels is defined to require the cost of one. You
can arbitrarily choose the initial position of the machine, and don’t have to count the cost for
moving the machine to that position.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets.
</p>
<p>
Each dataset consists of three lines. The first line contains an integer <i>N</i>, which indicates the
number of panels (2 ≤ <i>N</i> ≤ 16). The second and third lines contain <i>N</i> characters each,
and describe the initial and final orders of the panels respectively. Each character in these descriptions is either ‘B’ (for black) or ‘W’ (for white) and denotes the color of the panel. The
panels of the same color should <i>not</i> be distinguished.
</p>
<p>
The input is terminated by a line with a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output the minimum cost on a line. You can assume that there is at least one
way to change the order of the panels from the initial one to the final one.
</p>
<H2>Sample Input</H2>
<pre>
4
WBWB
BWBW
8
WWWWBWBB
WWBBWBWW
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
9
</pre>
|
p03159 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The server in company A has a structure where <var>N</var> devices numbered <var>1, 2, ..., N</var> are connected with <var>N - 1</var> cables.
The <var>i</var>-th cable connects Device <var>U_i</var> and Device <var>V_i</var>.
Any two different devices are connected through some number of cables.</p>
<p>Each device <var>v</var> (<var>1 \leq v \leq N</var>) has a non-zero integer <var>A_v</var>, which represents the following:</p>
<ul>
<li>If <var>A_v < 0</var>, Device <var>v</var> is a computer that consumes an electric power of <var>-A_v</var>.</li>
<li>If <var>A_v > 0</var>, Device <var>v</var> is a battery that supplies an electric power of <var>A_v</var>.</li>
</ul>
<p>You have decided to disconnect some number of cables (possibly zero) to disable the server.
When some cables are disconnected, the devices will be divided into some number of connected components.
The server will be disabled if all of these connected components satisfy one of the following conditions:</p>
<ul>
<li>There is no computer in the connected component. That is, <var>A_v</var> is positive for every device <var>v</var> that belongs to the connected component.</li>
<li>There is not enough supply of electric power in the connected component. That is, the sum of <var>A_v</var> over all devices <var>v</var> that belong to the connected component is negative.</li>
</ul>
<p>At least how many cables do you need to disconnect in order to disable the server?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 5</var> <var>000</var></li>
<li><var>1 \leq |A_i| \leq 10^9</var> (<var>1 \leq i \leq N</var>)</li>
<li><var>1 \leq U_i, V_i \leq N</var> (<var>1 \leq i \leq N - 1</var>)</li>
<li><var>U_i \neq V_i</var> (<var>1 \leq i \leq N - 1</var>)</li>
<li>Any two different devices are connected through some number of cables.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
<var>U_1</var> <var>V_1</var>
<var>U_2</var> <var>V_2</var>
<var>:</var>
<var>U_{N - 1}</var> <var>V_{N - 1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
-2 7 5 6 -8 3 4
1 2
2 3
2 4
1 5
5 6
5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>We should disconnect the cable connecting Device <var>1</var> and Device <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 3 4
1 2
1 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
10 -1 10 -1 10 -1
1 2
2 3
3 4
4 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8
-2 3 6 -2 -2 -5 3 2
3 4
7 6
6 2
8 2
5 3
1 8
3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>10
3 4 9 6 1 5 -1 10 -10 -10
7 4
5 6
8 1
9 5
7 1
10 3
2 8
4 10
9 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>3
</pre></section>
</div>
</span> |
p01534 |
<h1> Anipero 2012</h1>
<h2> D: アニペロ2012</h2>
<p>
アニペロサマーライブ,通称アニペロは,さまざまなアニメソングアーティストたちが集結する,日本国内最大のアニメソングライブイベントである.アニソンが大好きな2D君は,昨年に引き続き,今年もアニペロに行くことにした.
</p>
<p>
彼は,アニペロを楽しむために,すでにサイリウムを<i>m</i>本購入している.サイリウムとは,折ると化学反応で光るスティックである.リズムに合わせてサイリウムを振ることで,ライブを盛り上げることができ,自分の満足度も上昇する.今回,彼が購入した全てのサイリウムは,次のような性質を持つ.
</p>
<ul>
<li> サイリウムは,折ってから時間が経過するにつれ暗くなっていき,10分で光を失う.</li>
<li> 折ってから5分の間は,非常に明るい(以下,「レベル2」と呼ぶ).</li>
<li> 折ってから5分経過した後は,少し暗くなる(以下,「レベル1」と呼ぶ).</li>
<li> 振っても振らなくても,光を失うスピードは変わらない.</li>
</ul>
<p>
2D君は,限られたサイリウムを曲によってうまく使い分けることで,今年のアニペロでどれだけの満足度を得られそうか,以下の問題を考えることにした.
</p>
<p>
彼は,ライブ中に流れるであろう曲を<i>n</i>曲予想している.
各曲の長さは,全て5分である.
<i>n</i>曲は,連続で流れ続け,曲と曲の間は,0分と考えてよい.
各曲には,以下の3つのパラメータが与えられる.
</p>
<ul>
<li> ある曲に対して,レベル2を1本だけ振ったときに増える満足度</li>
<li> ある曲に対して,レベル1を1本だけ振ったときに増える満足度</li>
<li> ある曲において,1本も振らないときに増える満足度</li>
</ul>
<p>
サイリウムを振ったからといって,満足度が増えるとは限らない.
振ったら逆に会場の雰囲気を乱して,満足度が減る場合もある.
振らない場合も,同様のことが言える.
</p>
<p>
サイリウムは,以下のルールに従って使用しなければならない.
</p>
<ul>
<li> 曲が始まる時点でのみ折ることができ,一度に何本でも折ることができる.サイリウムを折るのにかかる時間は無視してよい.</li>
<li> 1曲で最大8本同時に振ることができる.</li>
<ul>
<li> 複数のサイリウムを振る際,以下の式により加算する満足度を計算する.</li>
</ul>
<ul>
<li> (レベル1の本数)×(レベル1の1本あたりの満足度)+(レベル2の本数)×(レベル2の1本あたりの満足度)</li>
</ul>
<ul>
<li> 1本もサイリウムを振らない場合は,1本も振らない場合の満足度だけを加算する.</li>
</ul>
<li> 一度振ると決めたサイリウムは,1曲が終了するまで持ち替えることはできない.</li>
<li> サイリウムは,振らずに置いておくことができる.また,サイリウムを全て使いきる必要はない.</li>
</ul>
<p>
2D君は,ライブの曲予想までは済ませたが,それだけで疲れてしまって,問題を解く気になれなかった.
あなたの仕事は,彼の代わりに,今年のライブで得られそうな最大満足度を求めるプログラムを書くことである.
</p>
<h2> Input</h2>
<p>
ライブの予想曲リストに対する満足度情報が入力される.
</p>
<p>
1行目に,ライブで歌われる曲数<i>n</i> (1 <= <i>n</i> <= 50)と,ライブ開始時に2D君が持っている新品のサイリウムの数m (0 <= <i>m</i> <= 50)がスペース区切りで入力される.
続く<i>n</i>行では,1行ずつ1曲の情報が入力される.
<i>i</i>番目(1 <= <i>i</i> <= <i>n</i>)の曲情報は,
</p>
<ul>
<li> 曲<i>i</i>に対して,レベル2のサイリウムを1本振ったときの満足度<i>a<sub>i</sub></i></li>
<li> 曲<i>i</i>に対して,レベル1のサイリウムを1本振ったときの満足度<i>b<sub>i</sub></i></li>
<li> 曲<i>i</i>において,サイリウムを1本も振らないときの満足度<i>c<sub>i</sub></i></li>
</ul>
<p>
がスペース区切りで入力される(-100 <= <i>a<sub>i</sub></i>, <i>b<sub>i</sub></i>, <i>c<sub>i</sub></i> <= 100).
</p>
<h2> Output</h2>
<p>
ライブ終了時の2D君の最大満足度の予想を1行に出力せよ.
最大満足度がマイナスになることもあるので,注意すること.
行の最後には,改行を出力すること.
</p>
<h2> Sample Input 1</h2>
<pre>
1 5
2 3 8
</pre>
<h2> Sample Output 1</h2>
<pre>
10
</pre>
<h2> Sample Input 2</h2>
<pre>
2 10
2 2 20
2 3 -10
</pre>
<h2> Sample Output 2</h2>
<pre>
44
</pre>
<h2> Sample Input 3</h2>
<pre>
3 10
5 1 9
-3 2 1
1 11 0
</pre>
<h2> Sample Output 3</h2>
<pre>
102
</pre> |
p03509 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo Kingdom Congress is voting on a bill.</p>
<p><var>N</var> members are present, and the <var>i</var>-th member <var>(1 ≤ i ≤ N)</var> has <var>w_i</var> white ballots and <var>b_i</var> blue ballots. Each member <var>i</var> will put all the <var>w_i</var> white ballots into the box if he/she is in favor of the bill, and put all the <var>b_i</var> blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box.</p>
<p>After all the members vote, if at least <var>P</var> percent of the ballots in the box is white, the bill is passed; if less than <var>P</var> percent of the ballots is white, the bill is rejected.</p>
<p>In order for the bill to pass, at least how many members must be in favor of it?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 10^5</var></li>
<li><var>1 ≤ P ≤ 100</var></li>
<li><var>1 ≤ w_i ≤ 10^9</var></li>
<li><var>1 ≤ b_i ≤ 10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>P</var>
<var>w_1</var> <var>b_1</var>
<var>w_2</var> <var>b_2</var>
<var>:</var>
<var>w_N</var> <var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of members in favor of the bill required for passage.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 75
1 1
1 1
1 1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>This is a "normal" vote, where each of the four members has one white ballot and one blue ballot. For the bill to pass, at least <var>75</var> percent of the four, that is, at least three must be in favor of it.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 75
1 1
1 1
1 1
100 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>The "yes" vote of the member with <var>100</var> white ballots alone is enough to pass the bill.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 60
6 3
5 9
3 4
7 8
4 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p01021 |
<h1>Problem F: Remainder Zero</h1>
<h2>Problem</h2>
<p>
整数の集合A,Bについて,次の条件を満たす整数 <var>x</var>がいくつ存在するか答えよ。
</p>
<p>
<var>A<sub>i</sub></var> mod <var>x</var> = 0 かつ <var>x</var> mod <var>B<sub>j</sub></var> = 0 がすべての <var>i</var> (1 ≤ <var>i</var> ≤ N), <var>j</var> (1 ≤ <var>j</var> ≤ M) について成り立つ。
</p>
<p>
(<var>a</var> mod <var>b</var> は<var>a</var>を<var>b</var>で割ったときの余りを意味する)
</p>
<h2>Input</h2>
<pre>
<var>N</var> <var>M</var>
<var>A<sub>1</sub></var> <var>A<sub>2</sub></var> ... <var>A<sub>N</sub></var>
<var>B<sub>1</sub></var> <var>B<sub>2</sub></var> ... <var>B<sub>M</sub></var>
</pre>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>1 ≤ <var>N</var>, <var>M</var> ≤ 5</li>
<li>1 ≤ <var>A<sub>i</sub></var>, <var>B<sub>j</sub></var> ≤ 10<sup>14</sup> (1 ≤ <var>i</var> ≤ <var>N</var>, 1 ≤ <var>j</var> ≤ <var>M</var>)</li>
</ul>
<h2>Output</h2>
<p>条件を満たす整数 <var>x</var> がいくつ存在するか一行で出力せよ。</p>
<h2>Sample Input 1</h2>
<pre>
1 2
18
6 9
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
1 2
256
2 4
</pre>
<h2>Sample Output 2</h2>
<pre>
7
</pre>
|
p01471 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>問題文</h2>
<p>実数変数 $x_1, x_2, ..., x_N$ は以下の条件を満たす。</p>
<ol><li>$0 \leq x_i \leq 1$ ($1 \leq i \leq N$)</li>
<li>$w_1x_1+w_2x_2+...+w_Nx_N \leq W$</li></ol>
<p>このとき $v_1x_1+v_2x_2+...+v_Nx_N$ のとりうる最大値を求めよ。そのような最大値は実際に存在することが知られている。</p>
<h2>入力</h2>
<p>入力は以下の形式に従う。与えられる数は全て整数である。</p>
<pre>$N$ $W$
$w_1$ $v_1$
$w_2$ $v_2$
$...$
$w_N$ $v_N$</pre>
<h2>制約</h2>
<ul><li>$1 \leq N \leq 10^5$</li>
<li>$1 \leq W \leq 10^5$</li>
<li>$-10^4 \leq w_i \leq 10^4$</li>
<li>$-10^4 \leq v_i \leq 10^4$</li></ul>
<h2>出力</h2>
<p>$v_1x_1+v_2x_2+...+v_Nx_N$ のとりうる最大値を1行に出力せよ。
出力には $10^{-3}$ を超える誤差があってはならない。</p>
<h2>Sample Input 1</h2>
<pre>1 1
3 1</pre>
<h2>Output for the Sample Input 1</h2>
<pre>0.333333</pre>
<p>$x_1=1/3$ のとき最大となる。</p>
<h2>Sample Input 2</h2>
<pre>2 3
3 3
1 2</pre>
<h2>Output for the Sample Input 2</h2>
<pre>4.000000</pre>
<h2>Sample Input 3</h2>
<pre>2 1
-1 -3
3 10</pre>
<h2>Output for the Sample Input 3</h2>
<pre>3.666667</pre>
|
p01922 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath2017.js" charset="UTF-8"></script>
<h2>G: 恋のジュンレツRun!Run!Run! - Love Permutation, Run run run! -</h2>
<h3>物語</h3>
<p>
おおきなジュンレツ らんらんらんでぶー♪
Hello, 星空蘭にゃ!
好きなデータ構造は Starry Sky Tree にゃ!
</p>
<p>
蘭は最近物理学科に入学したんだけど、どうやらそこでもプログラミングをやらないといけないらしいんだ。
蘭、アルゴリズムやデータ構造の理論は好きなんだけど、実装はどうも苦手なんだよね……
だいたい蘭達は人間なのに、どうして機械の言葉を勉強しなくちゃいけないの!?
</p>
<p>
とはいえ、課題をやらないことには単位が出ないしやるしかないにゃ。
今回出た課題は順列の run とかいうのが関係しているらしいんだー。
この問題、明らかに作者がタイトル一発ネタで考えてるのが見え見えにゃ、ちょっと寒くないかにゃー。
とにかく、プログラミングが得意なあなたに手伝ってもらえたら、テンション上がるにゃー!
それじゃあ問題、行っくにゃ〜!
</p>
<h3>問題</h3>
<p>長さ<var>K</var>の数列<var>a</var>が<var>1 \leq a_i \leq K</var> <var>(1 \leq i \leq K)</var> かつ<var>a_i \neq a_j</var> <var>(1 \leq i < j \leq K)</var> を満たすとき、<var>a</var>は長さ<var>K</var>の順列であるという。</p>
<p>
ここで順列のパターンマッチングを以下のように定義する。
テキスト順列<var>q</var>がパターン順列<var>p</var>にマッチするとは、<var>p</var>と相対順序が一致するような、<var>p</var>と同じ長さの<var>q</var>の (連続とは限らない) 部分列が存在することをいう。
より厳密には、<var>q</var>の長さを<var>N</var>、<var>p</var>の長さを<var>M</var>としたとき、<var>q</var>が<var>p</var>にマッチするとは、ある条件を満たす添え字列 <var>1 \leq i_1 < ... < i_M \leq N</var>が存在することである。その条件とは、<var>p_x < p_y</var> <var>(1 \leq x<y \leq M)</var> ならば、かつそのときに限り<var>q_{i_x} < q_{i_y}</var>となることである。
例えば、順列<var>(3, 4, 2, 1, 5)</var>は順列<var>(2, 1, 3)</var>にマッチする。なぜならば、添え字列<var>(1, 4, 5)</var>が上記の条件を満たすからである。
</p>
<p>
さらに、順列の run を定義する。
順列のrunとは、単調増加、あるいは単調減少な極大連続部分列である。すなわち、run は連続部分列 <var>a_l, ..., , a_r</var> <var>(l<r)</var> のうち、<var>a_i < a_{i+1}</var> <var>(l \leq i < r)</var> (<var>a_i > a_{i+1}</var> <var>(l \leq i < r)</var>) を満たし、かつこの区間を真に包含する連続区間からなる run が存在しないものを言う。
例えば、順列<var>(3, 4, 2, 1, 5)</var>は<var>(3, 4)</var>, <var>(4, 2, 1)</var>, <var>(1, 5)</var>という3つのrunを持つ。
</p>
<p>
長さ<var>N</var>のテキスト順列<var>q</var>と長さ<var>M</var>のパターン順列<var>p</var>が与えられる。
ここで、<var>q</var>は必ずちょうど3つだけの run を持つことが保証される。
<var>q</var>が<var>p</var>にマッチするかどうかを判定せよ。
</p>
<h3>入力形式</h3>
<p>入力は以下の形式で与えられる。</p>
<pre>
<var>N</var>
<var>q_1</var> ... <var>q_N</var>
<var>M</var>
<var>p_1</var> ... <var>p_M</var>
</pre>
<p>
入力は全て整数からなる。
1行目にはテキストとなる順列<var>q</var>の長さ<var>N</var>が与えられる。
続く2行目は<var>N</var>個の整数が空白区切りで与えられ、<var>i</var> <var>(1 \leq i \leq N)</var> 番目の整数は<var>q</var>の<var>i</var>番目の要素<var>q_i</var>を表す。
3行目にはパターンとなる順列<var>p</var>の長さ<var>M</var>が与えられる。
続く4行目は<var>M</var>個の整数が空白区切りで与えられ、<var>j</var> <var>(1 \leq j \leq M)</var> 番目の整数は<var>p</var>の<var>j</var>番目の要素<var>p_j</var>を表す。
</p>
<h3>制約</h3>
<ul>
<li><var>4 \leq N \leq 10^5</var></li>
<li><var>1 \leq M \leq N</var></li>
<li><var>q, p</var>はそれぞれ長さ<var>N, M</var>の順列である。</li>
<li><var>q</var>が持つ run の数はちょうど3。</li>
</ul>
<h3>出力形式</h3>
<p>順列<var>q</var>が順列<var>p</var>にマッチするとき"Yes"、そうでなければ"No"と1行に出力せよ。</p>
<h3>入力例1</h3>
<pre>
5
3 4 2 1 5
3
1 2 3
</pre>
<h3>出力例1</h3>
<pre>Yes</pre>
<h3>入力例2</h3>
<pre>
5
3 5 4 1 2
3
1 2 3
</pre>
<h3>出力例2</h3>
<pre>No</pre> |
p00630 |
<H1><font color="#000000">Problem P04:</font> CamelCase</H1>
<p>
プログラミングにおける識別子(変数や関数)の命名では、
単語を連結した複合語が使われる。
しかし、そのまま連結すると単語の区切りがわからなくなるため、
一般的に以下の命名規則の中から統一するものを選び適用する:
</p>
<ul>
<li>Upper CamelCase にする<br>
単語を直接連結し複合語とし、各単語の先頭文字のみを大文字にする。<br>
例: GetUserName
</li>
<li>Lower CamelCase にする<br>
単語を直接連結し複合語とし、各単語の先頭文字のみを大文字にする。ただし、複合語の先頭文字は小文字にする。<br>
例: getUserName
</li>
<li>アンダースコアで繋ぐ<br>
単語をアンダースコアで連結し複合語とする。単語の文字はすべて小文字にする。<br>
例: get_user_name
</li>
</ul>
<p>
与えられた識別子を、指定された命名規則を適用して出力するプログラムを作成せよ。
与えられる識別子は、上記の命名規則のいづれかが既に適用されているものとする。
</p>
<H2>Input</H2>
<p>
入力として複数のデータセットが与えられる。各データセットは以下の形式で与えられる:
</p>
<p>
<i>name</i> <i>type</i> (識別子、命名規則: 空白区切りの文字列と文字)
</p>
<p>
<i>type</i>は命名規則を示す文字であり、以下の表の通りとする:
</p>
<table border=1 cellspacing=4 cellpadding=4>
<tr><th><i>type</i></td><th>命名規則</th></tr>
<tr><td><span>U</span></td><td>Upper CamelCase にする</td></tr>
<tr><td><span>L</span></td><td>Lower CamelCase にする</td></tr>
<tr><td><span>D</span></td><td>アンダースコアで繋ぐ</td></tr>
</table>
<p>
与えられる識別子の文字数は 1 以上 100 以下である。
</p>
<p>
<i>type</i> が '<span>X</span>' のとき入力の終わりとする。この入力に対する出力を行ってはならない。
</p>
<H2>Output</H2>
<p>
各データセットについて、命名規則を適用した識別子を1行に出力せよ。
</p>
<H2>Sample Input</H2>
<pre>
get_user_name L
getUserName U
GetUserName D
EndOfInput X
</pre>
<H2>Output for the Sample Input</H2>
<pre>
getUserName
GetUserName
get_user_name
</pre>
|
p00260 |
<H1>ねこまっしぐら</H1>
<p>
あるところに、高い塀に囲まれた大きなお屋敷がありました。そのお屋敷の主人は猫がとても大好きで、時折やってくる猫たちのために、いつもおいしいごはんを用意していました。お腹を空かせた猫たちは、高い塀をひょいと飛び越え、お屋敷の至る所に置いてあるごはんにまっしぐらに駆け寄るのでした。
</p>
<p>
ある日主人は、屋敷の中で何匹かの猫が倒れているのを見つけました。猫たちはごはんを探して屋敷の中を縦横無尽に走り回ったので、ぶつかったり転んだりしてしまったのです。主人は猫たちの安全を考えて、ごはんの置き場所を工夫することにしました。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_catGoingStraight">
</center>
<p>
上空から見ると、このお屋敷の塀は多角形をなしています。主人は猫たちがごはんを見つけやすいように、敷地内の中でも、多角形の頂点にあたる場所だけにごはんを置くことにしました。また猫たちは気まぐれなので、多角形の周上のどの点からお屋敷に入ってくるかは予想できません。そこで主人は、猫がどの点から入ったとしても、その点から直進していずれかのごはんにたどり着けるように、ごはんを配置することも決めました。
</p>
<p>
すべての頂点にごはんを配置すれば、この条件を満たすことができます。しかし、ごはんを補充して回るのは大変なので、主人はできるだけ少ない数の頂点にごはんを配置したいと思いました。さて、主人は最低何箇所にごはんを配置する必要があるでしょうか。
</p>
<p>
お屋敷の塀を表す多角形を入力とし、ごはんを配置する頂点の数の最小値を求めるプログラムを作成して下さい。ただし、猫は多角形の内部のみを直進できるものとします(辺は多角形の内部に含めるものとします)。
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる。入力の終わりはゼロ1つの行で示される。各データセットは以下の形式で与えられる。
</p>
<pre>
n
x<sub>1</sub> y<sub>1</sub>
x<sub>2</sub> y<sub>2</sub>
...
x<sub>n</sub> y<sub>n</sub>
</pre>
<p>
1行目に多角形の頂点の数 n (3 ≤ n ≤ 16) が与えられる。続く n 行に多角形の頂点の座標が与えられる。n 行のそれぞれは、1つの空白で区切られた2つの整数からなる。x<sub>i</sub> (-1000 ≤ x<sub>i</sub> ≤ 1000) は i 番目の頂点の x 座標、y<sub>i</sub> (-1000 ≤ y<sub>i</sub> ≤ 1000) は i 番目の頂点の y 座標を示す。多角形の頂点は、隣り合った頂点を反時計回りに訪問するような順番で与えられる。
</p>
<p>
データセットの数は 20 を超えない。
</p>
<h2>出力</h2>
<p>
各データセットごとに、ご飯を配置する頂点の数を1行に出力する。
</p>
<h2>入力例</h2>
<pre>
8
0 0
3 2
6 2
8 6
6 5
7 7
0 4
3 4
8
0 0
5 3
5 2
4 1
6 1
8 6
6 4
2 4
0
</pre>
<h2>出力例</h2>
<pre>
1
2
</pre> |
p01888 |
<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>Multisect</h2>
<p>
We are developing the world's coolest AI robot product. After the long struggle, we finally managed to send our product at revision $R_{RC}$ to QA team as a release candidate. However, they reported that some tests failed! Because we were too lazy to set up a continuous integration system, we have no idea when our software corrupted. We only know that the software passed all the test at the past revision $R_{PASS}$. To determine the revision $R_{ENBUG}$ ($R_{PASS} < R_{ENBUG} \leq R_{RC}$) in which our software started to fail, we must test our product revision-by-revision.
</p>
<p>
Here, we can assume the following conditions:
</p>
<ul>
<li> When we test at the revision $R$, the test passes if $R < R_{ENBUG}$, or fails otherwise.</li>
<li> It is equally possible, which revision between $R_{PASS} + 1$ and $R_{RC}$ is $R_{ENBUG}$.</li>
</ul>
<p>
From the first assumption, we don't need to test all the revisions. All we have to do is to find the revision $R$ such that the test at $R - 1$ passes and the test at $R$ fails. We have $K$ testing devices. Using them, we can test at most $K$ different revisions simultaneously. We call this "parallel testing". By the restriction of the testing environment, we cannot start new tests until a current parallel testing finishes, even if we don't use all the $K$ devices.
</p>
<p>
Parallel testings take some cost. The more tests fail, the more costly the parallel testing becomes. If $i$ tests fail in a parallel testing, its cost is $T_i$ ($0 \leq i \leq K$). And if we run parallel testings multiple times, the total cost is the sum of their costs.
</p>
<p>
Of course we want to minimize the total cost to determine $R_{ENBUG}$, by choosing carefully how many and which revisions to test on each parallel testing. What is the minimum expected value of the total cost if we take an optimal strategy?
</p>
<h3>Input</h3>
<p>
The input consists of a single test case with the following format.<br/>
<br/>
$R_{PASS}$ $R_{RC}$ $K$<br/>
$T_0$ $T_1$ ... $T_K$
</p>
<p>
$R_{PASS}$ and $R_{RC}$ are integers that represent the revision numbers of our software at which the test passed and failed, respectively. $1 \leq R_{PASS} < R_{RC} \leq 1,000$ holds. $K$ ($1 \leq K \leq 30$) is the maximum number of revisions we can test in a single parallel testing. $T_i$ is an integer that represents the cost of a parallel testing in which $i$ tests fail ($0 \leq i \leq K$). You can assume $1 \leq T_0 \leq T_1 \leq ... \leq T_K \leq 100,000$.
</p>
<h3>Output</h3>
<p>
Output the minimum expected value of the total cost. The output should not contain an error greater than 0.0001.
</p>
<h3>Sample Input 1</h3>
<pre>
1 10 2
1 1 1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
2.0
</pre>
<h3>Sample Input 2</h3>
<pre>
1 100 1
100 100
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
670.7070707
</pre>
<h3>Sample Input 3</h3>
<pre>
100 200 4
1 1 2 2 3
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
4.6400000
</pre>
<h3>Sample Input 4</h3>
<pre>
2 3 4
1 2 3 4 5
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
0.0
</pre>
<h3>Sample Input 5</h3>
<pre>
998 1000 4
10 100 1000 10000 100000
</pre>
<h3>Output for the Sample Input 5</h3>
<pre>
55.0
</pre>
|
p03765 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let us consider the following operations on a string consisting of <code>A</code> and <code>B</code>:</p>
<ol>
<li>Select a character in a string. If it is <code>A</code>, replace it with <code>BB</code>. If it is <code>B</code>, replace with <code>AA</code>.</li>
<li>Select a substring that is equal to either <code>AAA</code> or <code>BBB</code>, and delete it from the string.</li>
</ol>
<p>For example, if the first operation is performed on <code>ABA</code> and the first character is selected, the string becomes <code>BBBA</code>.
If the second operation is performed on <code>BBBAAAA</code> and the fourth through sixth characters are selected, the string becomes <code>BBBA</code>.</p>
<p>These operations can be performed any number of times, in any order.</p>
<p>You are given two string <var>S</var> and <var>T</var>, and <var>q</var> queries <var>a_i, b_i, c_i, d_i</var>.
For each query, determine whether <var>S_{a_i} S_{{a_i}+1} ... S_{b_i}</var>, a substring of <var>S</var>, can be made into <var>T_{c_i} T_{{c_i}+1} ... T_{d_i}</var>, a substring of <var>T</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S|, |T| \leq 10^5</var></li>
<li><var>S</var> and <var>T</var> consist of letters <code>A</code> and <code>B</code>.</li>
<li><var>1 \leq q \leq 10^5</var></li>
<li><var>1 \leq a_i \leq b_i \leq |S|</var></li>
<li><var>1 \leq c_i \leq d_i \leq |T|</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>T</var>
<var>q</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var>
<var>...</var>
<var>a_q</var> <var>b_q</var> <var>c_q</var> <var>d_q</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 response to the <var>i</var>-th query. If <var>S_{a_i} S_{{a_i}+1} ... S_{b_i}</var> can be made into <var>T_{c_i} T_{{c_i}+1} ... T_{d_i}</var>, print <code>YES</code>. Otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>BBBAAAABA
BBBBA
4
7 9 2 5
7 9 1 4
1 7 2 5
1 7 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
NO
YES
NO
</pre>
<p>The first query asks whether the string <code>ABA</code> can be made into <code>BBBA</code>.
As explained in the problem statement, it can be done by the first operation.</p>
<p>The second query asks whether <code>ABA</code> can be made into <code>BBBB</code>, and the fourth query asks whether <code>BBBAAAA</code> can be made into <code>BBB</code>.
Neither is possible.</p>
<p>The third query asks whether the string <code>BBBAAAA</code> can be made into <code>BBBA</code>.
As explained in the problem statement, it can be done by the second operation.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>AAAAABBBBAAABBBBAAAA
BBBBAAABBBBBBAAAAABB
10
2 15 2 13
2 13 6 16
1 13 2 20
4 20 3 20
1 18 9 19
2 14 1 11
3 20 3 15
6 16 1 17
4 18 8 20
7 20 3 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
</pre></section>
</div>
</span> |
p01758 |
<p>
閉路のない連結な有向グラフが与えられる.(有向グラフが連結であるとは,これを無向グラフとした時に連結であるという事である.)
</p>
<p>
このグラフに対して一つの頂点を選んで首都 <var>s</var> を定めたい.
</p>
<p>
<var>T(v) =</var> "<var>v</var> から全ての点を到達可能にするために必要な「辺の反転」操作の回数の最小値"とする.
</p>
<p>
ただし,「辺の反転」とは,頂点 <var>v, u</var> に関して <var>(v, u)</var> に張られていた有向辺を削除して <var>(u, v)</var> に張り直すことである.
</p>
<p>
頂点 <var>s</var> が首都であるとは任意の頂点 <var>v</var> に対して, <var>T(s) ≤ T(v)</var> が成立することである.
</p>
<p>
首都であるような頂点をすべて列挙して答えよ.
</p>
<h3>Input</h3>
<p>
入力は以下のような形式で <var>M + 1</var> 行で与えられる.
</p>
<pre>
<var>N</var> <var>M</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
:
<var>a<sub>M</sub></var> <var>b<sub>M</sub></var>
</pre>
<ul>
<li> 1 行目には二つの整数 <var>N, M</var> が与えられ,与えられるグラフは <var>N</var> 頂点 <var>M</var> 辺であることを表す.</li>
<li> 2 行目から <var>M + 1</var> 行目にはそれぞれ二つの整数 <var>a<sub>i</sub>, b<sub>i</sub></var> が与えられ,<var>a<sub>i</sub></var> から <var>b<sub>i</sub></var> に有向辺が張られていることを表す.
</li>
</ul>
<h3>Constraints</h3>
<ul>
<li> 1 ≤ <var>N</var> ≤ 10,000</li>
<li> 0 ≤ <var>M</var> ≤ 100,000</li>
<li> 0 ≤ <var>a<sub>i</sub></var> ≤ <var>N − 1</var></li>
<li> 0 ≤ <var>b<sub>i</sub></var> ≤ <var>N − 1</var></li>
<li> <var>a<sub>i</sub> ≠ b<sub>i</sub></var></li>
<li> <var>i ≠ j</var> ならば <var>(a<sub>i</sub>, b<sub>i</sub>) ≠ (a<sub>j</sub>, b<sub>j</sub>)</var></li>
<li> 与えられるグラフは連結で閉路はない.</li>
<li> 与えられるグラフに対して,入次数が 0 である頂点の個数は 50 以下である.</li>
</ul>
<h3>Output</h3>
<p>
以下の形式で2 行で出力せよ.
</p>
<pre>
<var>cnum</var> <var>cost</var>
<var>c<sub>1</sub></var> <var>c<sub>2</sub></var> . . . <var>c<sub>cnum</sub></var>
</pre>
<ul>
<li> 1 行目には二つの整数 <var>cnum</var>, <var>cost</var> を空白区切りで出力せよ.</li>
<li> 2 行目には <var>cnum</var> 個の整数 <var>c<sub>i</sub></var> を空白区切りで出力せよ.</li>
<li> 変数の意味は以下の通りである.<br>
− <var>cnum</var> : 首都の性質を満たす頂点数<br>
− <var>cost</var> : 首都となる頂点 <var>v</var> に対する <var>T(v)</var> の値<br>
− <var>c<sub>i</sub></var> : 首都の性質を満たす頂点を番号に関して昇順に並べた時,<var>i</var> 番目の頂点番号<br>
</li>
</ul>
<h3>Sample Input 1</h3>
<pre>
3 2
0 1
2 1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
2 1
0 2
</pre>
<ul>
<li> 頂点 0 を首都とするときには辺 (2,1) を反転すれば,(0,1), (1,2) の辺を持つグラフができるので 1 が答え.</li>
<li> <var>T(0) = 1, T(1) = 2, T(2) = 1</var> である.</li>
</ul>
<h3>Sample Input 2</h3>
<pre>
5 4
0 1
2 1
2 3
4 3
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
3 2
0 2 4
</pre>
<h3>Sample Input 3</h3>
<pre>
5 5
0 1
1 2
3 2
3 4
4 1
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
2 1
0 3
</pre> |
p02877 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a sequence of <var>N</var> integers <var>x_1,x_2,\cdots,x_N</var>.
Initially, all the elements are <var>0</var>.</p>
<p>He can do the following two kinds of operations any number of times in any order:</p>
<ul>
<li>Operation <var>1</var>: choose an integer <var>k</var> (<var>1 \leq k \leq N</var>) and a <strong>non-decreasing</strong> sequence of <var>k</var> non-negative integers <var>c_1,c_2,\cdots,c_k</var>.
Then, for each <var>i</var> (<var>1 \leq i \leq k</var>), replace <var>x_i</var> with <var>x_i+c_i</var>.</li>
<li>Operation <var>2</var>: choose an integer <var>k</var> (<var>1 \leq k \leq N</var>) and a <strong>non-increasing</strong> sequence of <var>k</var> non-negative integers <var>c_1,c_2,\cdots,c_k</var>.
Then, for each <var>i</var> (<var>1 \leq i \leq k</var>), replace <var>x_{N-k+i}</var> with <var>x_{N-k+i}+c_i</var>.</li>
</ul>
<p>His objective is to have <var>x_i=A_i</var> for all <var>i</var>.
Find the minimum number of operations required to achieve it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to achieve Snuke's objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 1 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>One way to achieve the objective in three operations is shown below.
The objective cannot be achieved in less than three operations.</p>
<ul>
<li>Do Operation <var>1</var> and choose <var>k=2,c=(1,2)</var>. Now we have <var>x=(1,2,0,0,0)</var>.</li>
<li>Do Operation <var>1</var> and choose <var>k=3,c=(0,0,1)</var>. Now we have <var>x=(1,2,1,0,0)</var>.</li>
<li>Do Operation <var>2</var> and choose <var>k=2,c=(2,1)</var>. Now we have <var>x=(1,2,1,2,1)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
2 1 2 1 2
</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>15
541962451 761940280 182215520 378290929 211514670 802103642 28942109 641621418 380343684 526398645 81993818 14709769 139483158 444795625 40343083
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
</pre></section>
</div>
</span> |
p03335 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi loves walking on a tree.
The tree where Takahashi walks has <var>N</var> vertices numbered <var>1</var> through <var>N</var>.
The <var>i</var>-th of the <var>N-1</var> edges connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p>
<p>Takahashi has scheduled <var>M</var> walks. The <var>i</var>-th walk is done as follows:</p>
<ul>
<li>The walk involves two vertices <var>u_i</var> and <var>v_i</var> that are fixed beforehand.</li>
<li>Takahashi will walk from <var>u_i</var> to <var>v_i</var> or from <var>v_i</var> to <var>u_i</var> along the shortest path.</li>
</ul>
<p>The <em>happiness</em> gained from the <var>i</var>-th walk is defined as follows:</p>
<ul>
<li>The happiness gained is the number of the edges traversed during the <var>i</var>-th walk that satisfies one of the following conditions:<ul>
<li>In the previous walks, the edge has never been traversed.</li>
<li>In the previous walks, the edge has only been traversed in the direction opposite to the direction taken in the <var>i</var>-th walk.</li>
</ul>
</li>
</ul>
<p>Takahashi would like to decide the direction of each walk so that the total happiness gained from the <var>M</var> walks is maximized.
Find the maximum total happiness that can be gained, and one specific way to choose the directions of the walks that maximizes the total happiness.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N,M ≤ 2000</var></li>
<li><var>1 ≤ a_i , b_i ≤ N</var></li>
<li><var>1 ≤ u_i , v_i ≤ N</var></li>
<li><var>a_i \neq b_i</var></li>
<li><var>u_i \neq v_i</var></li>
<li>The graph given as input is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
:
<var>a_{N-1}</var> <var>b_{N-1}</var>
<var>u_1</var> <var>v_1</var>
:
<var>u_M</var> <var>v_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum total happiness <var>T</var> that can be gained, and one specific way to choose the directions of the walks that maximizes the total happiness, in the following format:</p>
<pre><var>T</var>
<var>u^'_1</var> <var>v^'_1</var>
:
<var>u^'_M</var> <var>v^'_M</var>
</pre>
<p>where (<var>u^'_i</var>,<var>v^'_i</var>) is either (<var>u_i</var>,<var>v_i</var>) or (<var>v_i</var>,<var>u_i</var>), which means that the <var>i</var>-th walk is from vertex <var>u^'_i</var> to <var>v^'_i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
2 1
3 1
4 1
2 3
3 4
4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
2 3
3 4
4 2
</pre>
<p>If we decide the directions of the walks as above, he gains the happiness of <var>2</var> in each walk, and the total happiness will be <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 3
1 2
1 3
3 4
3 5
2 4
3 5
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
2 4
3 5
5 1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 4
1 2
2 3
1 4
4 5
4 6
2 4
3 6
5 6
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
2 4
6 3
5 6
4 5
</pre></section>
</div>
</span> |
p01308 |
<h1><font color="#000">Problem F:</font> 天使の階段</h1>
<p>
なつめの住んでいる街の上に浮かんでいる雲には、天使が住んでいる。その天使はなつめと同じくねこ好きで、しばしばねこと遊びに地上に降りてくる。地上に降りるために、天使は雲から地上へ繋がる長い長い階段を作った。しかし、毎回毎回ただ降りていくだけではつまらないと思った天使は、階段に細工をして、段を踏むと音が出るようにした。これを使って、音楽を奏でながら降りていくのだ。
</p>
<p>
音楽は12種類の音を使って奏でるものである。今回、音のオクターブは無視することにして、 C, C#, D, D#, E, F, F#, G, G#, A, A#, B の12種類のみを考える。隣りあう音同士の差を半音と呼ぶ。たとえば、Cを半音上げるとC#、C#を半音上げるとDとなる。逆に、Gを半音下げるとF#、 F#を半音下げるとFとなる。なお、Eを半音上げるとF、Bを半音上げるとCになることに注意してほしい。
</p>
<p>
階段から音が出る仕組みは次のようになっている。まず、階段は空中に浮かぶ <var>n</var> 枚の白い板からなっている。雲から数えて 1 ~ <var>n</var> 段目の板には、それぞれに12音のどれかが割り振られている。これを <var>T</var><sub><var>i</var></sub> (<var>i</var> = 1 ... <var>n</var>) と書くことにする。また簡単のために、雲は0段目、地上は <var>n</var>+1 段目と考える (ただしこれらには音階は割り当てられていない) 。天使が <var>k</var> (<var>k</var> = 0 ... <var>n</var>) 段目にいるとき、次は<var>k</var>-1, <var>k</var>+1, <var>k</var>+2 段のうち存在するもののどれかに行くことができる。ただし、<var>n</var>+1 段目 (地上) に降りた後は動くことはできず、0段目 (雲) を離れた後はそこに戻ることはできない。それぞれの動き方をしたとき、次のようなルールで音が鳴る。
</p>
<dl>
<dt>
<var>k</var>+1 段目に降りた
</dt>
<dd><var>T</var><sub><var>k</var>+1</sub> の音が鳴る。</dd>
<dt>
<var>k</var>+2 段目に降りた
</dt>
<dd><var>T</var><sub><var>k</var>+2</sub> を半音上げた音が鳴る。</dd>
<dt>
<var>k</var>-1 段目に戻った
</dt>
<dd><var>T</var><sub><var>k</var>-1</sub> を半音下げた音が鳴る。</dd>
</dl>
<p>
階段の情報 <var>T</var><sub>1</sub> ... <var>T</var><sub><var>n</var></sub> と、天使が奏でたい曲 <var>S</var><sub>1</sub> ... <var>S</var><sub><var>m</var></sub> が与えられる。このとき、奏でたい曲の前、途中、後で別の音を鳴らしてはならない。天使がこの曲を奏でて雲から地上へ降りられるかどうか判定せよ。
</p>
<h2>Input</h2>
<p>
入力の1行目には、階段の段数 <var>n</var> と天使が奏でたい曲の長さ <var>m</var> が与えられる。2行目は階段の情報であり、<var>T</var><sub>1</sub>, <var>T</var><sub>2</sub>, ..., <var>T</var><sub><var>n</var></sub> がこの順で与えられる。3行目は天使が奏でたい曲であり、<var>S</var><sub>1</sub>, <var>S</var><sub>2</sub>, ..., <var>S</var><sub><var>m</var></sub> がこの順で与えられる。これらは全て1つの空白文字で区切られており、1 <= <var>n</var>, <var>m</var> <= 50000を満たす。
</p>
<h2>Output</h2>
<p>天使が与えられた曲を奏でながら地上に降りられるなら"Yes"、そうでなければ"No"を1行に出力せよ。</p>
<h2>Notes on Submission</h2>
<p>
上記形式で複数のデータセットが与えられます。入力データの 1 行目にデータセットの数が与えられます。各データセットに対する出力を上記形式で順番に出力するプログラムを作成して下さい。
</p>
<h2>Sample Input</h2>
<pre>
4
6 4
C E D# F G A
C E F G
6 4
C E D# F G A
C D# F G
3 6
C D D
D# B D B D# C#
8 8
C B B B B B F F
C B B B B B B B
</pre>
<h2>Output for the Sample Input</h2>
<pre>
Yes
No
Yes
No
</pre>
|
p00149 |
<H1>視力検査</H1>
<p>
視力検査の検査結果データを入力とし、下記の視力判定表に基づいて各判定に当てはまる人数を、左右の視力別に出力するプログラムを作成してください。
</p>
<center>
<table>
<tr><td width="80">判定</td><td>視力</td></tr>
<tr><td>A</td><td>1.1 以上</td></tr>
<tr><td>B</td><td>0.6 以上 1.1 未満</td></tr>
<tr><td>C</td><td>0.2 以上 0.6 未満</td></tr>
<tr><td>D</td><td>0.2 未満</td></tr>
</table>
</center>
<br/>
<H2>Input</H2>
<p>
入力は以下の形式で与えられます。
</p>
<pre>
<var>l<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>l<sub>2</sub></var> <var>r<sub>2</sub></var>
<var>l<sub>3</sub></var> <var>r<sub>3</sub></var>
:
:
</pre>
<p>
<var>i</var> 行目に <var>i</var> 人目の左の視力を表す実数 <var>l<sub>i</sub></var> と右の視力を表す実数 <var>r<sub>i</sub></var> が空白区切りで与えられます。ただし、視力は 0.1 以上 2.0 以下で、 0.1 刻みで与えられます。
</p>
<p>
入力の行数は 40 を超えません。
</p>
<H2>Output</H2>
<p>
以下の形式で、判定表を出力してください。
</p>
<p>
1行目 左の視力がAの人数 右の視力がAの人数(空白区切り)<br/>
2行目 左の視力がBの人数 右の視力がBの人数(空白区切り)<br/>
3行目 左の視力がCの人数 右の視力がCの人数(空白区切り)<br/>
4行目 左の視力がDの人数 右の視力がDの人数(空白区切り)<br/>
</p>
<H2>Sample Input</H2>
<pre>
1.0 1.2
0.8 1.5
1.2 0.7
2.0 2.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2 3
2 1
0 0
0 0
</pre>
|
p02174 |
<h1>Problem M: Power Subsequences</h1>
<h2>Problem</h2>
<p>
添字が $1$ から始まり、長さが有限の数列を引数とする関数 $f$ を以下のように定義する。<br><br>
$\displaystyle f(\{a_1, a_2, \ldots, a_n\}) = \sum_{i=1}^n {a_i}^i$<br><br>
長さ $N$ の数列 $X = \{ x_1, x_2, \ldots, x_N \}$ が与えられるので、空の列を除く全ての部分列 $X'$ に対して $f(X')$ を求め、その総和を $998244353$ で割ったあまりを出力せよ。ただし、部分列の添字は、元の数列における相対的な序列を保ったまま $1$ から順に番号を振り直すものとする。また、ある2つの部分列が列として同じでも、取り出した位置が異なるならば、それらは別々に数えるものとする。<br>
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
$N$
$x_1$ $\ldots$ $x_N$
</pre>
<p>
1行目に長さ $N$ が与えられる。
2行目に数列 $X$ の要素が空白区切りで与えられる。
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$1 \leq N \leq 10^6 $</li>
<li>$1 \leq x_i \leq 10^6 $</li>
<li>入力は全て整数である</li>
</ul>
<h2>Output</h2>
<p>
空の列を除く全ての部分列 $X'$ について $f(X')$ を求め、その総和を $998244353$ で割ったあまりを出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
3
1 2 3
</pre>
<h2>Sample Output 1</h2>
<pre>
64
</pre>
<p>
$(1^1)+(2^1)+(1^1+2^2)+(3^1)+(1^1+3^2)+(2^1+3^2)+(1^1+2^2+3^3) = 64$<br>
であるから、64を出力する。<br>
</p>
<h2>Sample Input 2</h2>
<pre>
5
100 200 300 400 500
</pre>
<h2>Sample Output 2</h2>
<pre>
935740429
</pre>
|
p00519 |
<H1>問題 5: タクシー (Taxis)
</H1>
<br/>
<h2>問題</h2>
<p>
IOI 国は町 1 から町 N までの N 個の町からなり,町と町とは道路で結ばれている.IOI 国には K 本の道路があり,すべての道路は異なる 2 つの町を結んでいる.車は道路を双方向に自由に移動できるが,道路以外を通ってある町から別の町に行くことはできない.
</p>
<p>
IOI 国の町 1 に住む JOI 君は,町 N に住む祖母の家までタクシーで行くことにした.IOI 国にはタクシー会社 1 からタクシー会社 N までの N 個のタクシー会社がある.IOI 国のタクシー会社には次のような少々特殊な規則がある.
</p>
<ul>
<li>タクシー会社 i のタクシーには,町 i でのみ乗車できる.</li>
<li>タクシー会社 i のタクシーの運賃は,利用した距離によらず C<sub>i</sub> である.</li>
<li>タクシー会社 i のタクシーは,乗車してから連続して最大 R<sub>i</sub> 本の道路しか通ることができない.</li>
</ul>
<p>
たとえば R<sub>1</sub> = 2 の場合,町 1 からタクシー会社 1 のタクシーに乗車すると,最大 2 本の道路しか通ることができないため,道路を 3 本以上通るためには途中の町でタクシーを乗り換える必要がある.
</p>
<p>
JOI 君は町以外の地点でタクシーに乗ったりタクシーから降りたりすることはできない.また,タクシー以外の移動手段を用いることもできない.JOI 君が町 N に到達するために必要な運賃の合計の最小値を求めるプログラムを作成せよ.
</p>
<h2>入力</h2>
<p>
入力は 1 + N + K 行からなる.
</p>
<p>
1 行目には,2 つの整数 N, K (2 ≤ N ≤ 5000, N - 1 ≤ K ≤ 10000) が空白を区切りとして書かれている.これは,IOI 国が N 個の町からなることと,IOI 国の道路の本数が K 本であることを表す.
</p>
<p>
続く N 行のうちの i 行目 (1 ≤ i ≤ N) には,2 つの整数 C<sub>i</sub>, R<sub>i</sub> (1 ≤ C<sub>i</sub> ≤ 10000, 1 ≤ R<sub>i</sub> ≤ N) が空白を区切りとして書かれている.これは,タクシー会社 i のタクシーの運賃が C<sub>i</sub> で,乗車してから連続して最大 R<sub>i</sub> 本の道路しか通ることができないことを表す.
</p>
<p>
続く K 行のうちの j 行目 (1 ≤ j ≤ K) には,異なる 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>
与えられる入力データにおいては,どの町から別のどの町へもタクシーを乗り継いで行くことができることが保証されている.
</p>
<h2>出力</h2>
<p>
JOI 君が町 1 から町 N まで行くのに必要な運賃の合計の最小値を表す整数を 1 行で出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例</h3>
<pre>
6 6
400 2
200 1
600 3
1000 1
300 5
700 4
1 2
2 3
3 6
4 6
1 5
2 4
</pre>
<h3>出力例</h3>
<pre>
700
</pre>
<p>
上の入出力例は,以下の図に対応している.円は町を,線は道路を表す.
</p>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2014-yo-t5-fig01" alt="5-1-2(*)-4-6-3-*" width="373" height="185">
</center>
<br/>
<p>
この入出力例でJOI 君が最小の運賃で町 6 に到達するには,以下のようにする.
</p>
<ul>
<li>町 1 からタクシーに乗って町 5 に行く. (運賃 400)</li>
<li>町 5 からタクシーに乗って町 6 に行く. (運賃 300)</li>
</ul>
<p>
JOI 君がこのようなルートを通った場合の運賃の合計は 400 + 300 = 700 であるので,700 を出力する.
</p>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02031 | <h2>B: 括弧を語る数 / Parentheses Number</h2>
<h3>問題</h3>
<p>以下のように 正しい括弧列 を定めます。</p>
<ul>
<li> 空文字列は正しい括弧列である</li>
<li> 正しい括弧列 <var>S</var> に対して <code>(</code> <var>S</var> <code>)</code> は正しい括弧列である</li>
<li> 正しい括弧列 <var>S</var>, <var>T</var> に対して <var>ST</var> は正しい括弧列である</li>
</ul>
<p>ここで、正しい括弧列に対して以下のような規則で順列を対応付けます。</p>
<ul>
<li><var>i</var> 番目の<b>閉じ括弧</b>が <var>j</var> 番目の<b>開き括弧</b>に対応しているとき、 数列の <var>i</var> 番目の値は <var>j</var> である。</li>
</ul>
<p>長さ <var>n</var> の順列 <var>P = ( p_1, p_2,</var> $\ldots$<var>, p_n )</var> が与えられるので、 それに対応する括弧列を復元してください。</p>
<p>ただし、順列に対応する括弧列が存在しない場合は <code>:(</code> を出力してください。</p>
<h3>入力形式</h3>
<pre>
<var>n</var>
<var>p_1</var> <var>p_2</var> $\ldots$ <var>p_n</var>
</pre>
<p>1 行目に順列の項数 <var>n</var> が与えられる。</p>
<p>2 行目に順列 <var>p_1, p_2,</var> $\ldots$<var>, p_i,</var> $\ldots$<var>, p_n</var> が空白区切りで与えられる。</p>
<h3>制約</h3>
<ul>
<li> <var>1 \leq n \leq 10^5</var></li>
<li> <var>1 \leq p_i \leq n</var></li>
<li> 入力は全て整数である。</li>
<li><var>P = ( p_1, p_2,</var> $\ldots$<var>, p_n )</var> は順列である。</li>
</ul>
<h3>出力形式</h3>
<p>順列に対応する括弧列を出力してください。</p>
<p>そのような括弧列が存在しない場合は <code>:(</code> を出力してください。</p>
<h3>入力例1</h3>
<pre>
2
2 1
</pre>
<h3>出力例1</h3>
<pre>(())</pre>
<h3>入力例2</h3>
<pre>
10
1 2 3 4 5 6 7 8 9 10
</pre>
<h3>出力例2</h3>
<pre>()()()()()()()()()()</pre>
<h3>入力例3</h3>
<pre>
3
3 1 2
</pre>
<h3>出力例3</h3>
<pre>:(</pre>
|
p02461 | <h1>Map: Range Search</h1>
<p>
For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that <u>each key in $M$ must be unique</u>.
</p>
<ul>
<li>insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.</li>
<li>get($key$): Print the value with the specified $key$. <u>Print 0 if there is no such element</u>. </li>
<li>delete($key$): Delete the element with the specified $key$.</li>
<li>dump($L$, $R$): Print all elements formed by a pair of the key and the value such that the key is greater than or equal to $L$ and less than or equal to $R$ in lexicographic order.</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $key$ $x$
</pre>
<p>or</p>
<pre>
1 $key$
</pre>
<p>or</p>
<pre>
2 $key$
</pre>
<p>or</p>
<pre>
3 $L$ $R$
</pre>
<p>
where the first digits <span>0</span>, <span>1</span>, <span>2</span> and <span>3</span> represent insert, get, delete and dump operations.
</p>
<h2>Output</h2>
<p>
For each get operation, print the corresponding value.<br>
For each dump operation, print the corresponding elements formed by a pair of the key and the value. For the dump operation, print the elements (a pair of key and value separated by a space character) in ascending order of the keys.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq q \leq 200,000$</li>
<li>$1 \leq x \leq 1,000,000,000$</li>
<li>$1 \leq $ length of $key$ $ \leq 20$ </li>
<li>$key$ consists of lower-case letters</li>
<li>$L \leq R$ in lexicographic order</li>
<li>The total number of elements printed by dump operations does not exceed $1,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
9
0 blue 4
0 red 1
0 white 5
1 red
1 blue
2 red
1 black
1 red
3 w z
</pre>
<h2>Sample Output 1</h2>
<pre>
1
4
0
0
white 5
</pre>
|
p03620 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have two strings <var>A = A_1 A_2 ... A_n</var> and <var>B = B_1 B_2 ... B_n</var> of the same length consisting of <var>0</var> and <var>1</var>.</p>
<p>You can transform <var>A</var> using the following operations in any order and as many times as you want:</p>
<ul>
<li>Shift <var>A</var> by one character to the left (i.e., if <var>A = A_1 A_2 ... A_n</var>, replace <var>A</var> with <var>A_2 A_3 ... A_n A_1</var>).</li>
<li>Shift <var>A</var> by one character to the right (i.e., if <var>A = A_1 A_2 ... A_n</var>, replace <var>A</var> with <var>A_n A_1 A_2 ... A_{n-1}</var>).</li>
<li>Choose any <var>i</var> such that <var>B_i = 1</var>. Flip <var>A_i</var> (i.e., set <var>A_i = 1 - A_i</var>).</li>
</ul>
<p>You goal is to make strings <var>A</var> and <var>B</var> equal.</p>
<p>Print the smallest number of operations required to achieve this, or <var>-1</var> if the goal is unreachable.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |A| = |B| \leq 2,000</var></li>
<li><var>A</var> and <var>B</var> consist of <var>0</var> and <var>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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest number of operations required to make strings <var>A</var> and <var>B</var> equal, or <var>-1</var> if the goal is unreachable.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1010
1100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Here is one fastest way to achieve the goal:</p>
<ul>
<li>Flip <var>A_1</var>: <var>A = 0010</var></li>
<li>Shift <var>A</var> to the left: <var>A = 0100</var></li>
<li>Flip <var>A_1</var> again: <var>A = 1100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>There is no way to flip the only bit in <var>A</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11010
10001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>Here is one fastest way to achieve the goal:</p>
<ul>
<li>Shift <var>A</var> to the right: <var>A = 01101</var></li>
<li>Flip <var>A_5</var>: <var>A = 01100</var></li>
<li>Shift <var>A</var> to the left: <var>A = 11000</var></li>
<li>Shift <var>A</var> to the left again: <var>A = 10001</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>0100100
1111111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre>
<p>Flip <var>A_1</var>, <var>A_3</var>, <var>A_4</var>, <var>A_6</var> and <var>A_7</var> in any order.</p></section>
</div>
</span> |
p02932 | <span class="lang-en">
<p>Score: <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Find the number of sequences of <var>N</var> non-negative integers <var>A_1, A_2, ..., A_N</var> that satisfy the following conditions:</p>
<ul>
<li><var>L \leq A_1 + A_2 + ... + A_N \leq R</var></li>
<li>When the <var>N</var> elements are sorted in non-increasing order, the <var>M</var>-th and <var>(M+1)</var>-th elements are equal.</li>
</ul>
<p>Since the answer can be enormous, print it modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers.</li>
<li><var>1 \leq M < N \leq 3 \times 10^5</var></li>
<li><var>1 \leq L \leq R \leq 3 \times 10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>L</var> <var>R</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the number of sequences of <var>N</var> non-negative integers, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2 3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>105
</pre>
<p>The sequences of non-negative integers that satisfy the conditions are:</p>
<p><var>\begin{eqnarray} &(1, 1, 1, 0), (1, 1, 1, 1), (2, 1, 1, 0), (2, 1, 1, 1), (2, 2, 2, 0), (2, 2, 2, 1), \\ &(3, 0, 0, 0), (3, 1, 1, 0), (3, 1, 1, 1), (3, 2, 2, 0), (4, 0, 0, 0), (4, 1, 1, 0), \\ &(4, 1, 1, 1), (5, 0, 0, 0), (5, 1, 1, 0), (6, 0, 0, 0), (7, 0, 0, 0)\end{eqnarray}</var></p>
<p>and their permutations, for a total of <var>105</var> sequences.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 1 4 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>The three sequences that satisfy the conditions are <var>(2, 2)</var>, <var>(3, 3)</var>, and <var>(4, 4)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>141592 6535 89793 238462
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>933832916
</pre></section>
</div>
</span> |
p02898 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><var>N</var> friends of Takahashi has come to a theme park.</p>
<p>To ride the most popular roller coaster in the park, you must be at least <var>K</var> centimeters tall.</p>
<p>The <var>i</var>-th friend is <var>h_i</var> centimeters tall.</p>
<p>How many of the Takahashi's friends can ride the roller coaster?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var> 1 \le N \le 10^5 </var></li>
<li><var> 1 \le K \le 500 </var></li>
<li><var> 1 \le h_i \le 500</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>h_1</var> <var>h_2</var> <var>\ldots</var> <var>h_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the number of people among the Takahashi's friends who can ride the roller coaster.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 150
150 140 100 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Two of them can ride the roller coaster: the first and fourth friends.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 500
499
</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>5 1
100 200 300 400 500
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p03270 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi throws <var>N</var> dice, each having <var>K</var> sides with all integers from <var>1</var> to <var>K</var>. The dice are NOT pairwise distinguishable.
For each <var>i=2,3,...,2K</var>, find the following value modulo <var>998244353</var>:</p>
<ul>
<li>The number of combinations of <var>N</var> sides shown by the dice such that the sum of no two different sides is <var>i</var>.</li>
</ul>
<p>Note that the dice are NOT distinguishable, that is, two combinations are considered different when there exists an integer <var>k</var> such that the number of dice showing <var>k</var> is different in those two.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq 2000</var></li>
<li><var>2 \leq N \leq 2000</var></li>
<li><var>K</var> and <var>N</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>K</var> <var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>2K-1</var> integers. The <var>t</var>-th of them <var>(1\leq t\leq 2K-1)</var> should be the answer for <var>i=t+1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
7
4
7
7
</pre>
<ul>
<li>For <var>i=2</var>, the combinations <var>(1,2,2),(1,2,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3)</var> satisfy the condition, so the answer is <var>7</var>.</li>
<li>For <var>i=3</var>, the combinations <var>(1,1,1),(1,1,3),(1,3,3),(2,2,2),(2,2,3),(2,3,3),(3,3,3)</var> satisfy the condition, so the answer is <var>7</var>.</li>
<li>For <var>i=4</var>, the combinations <var>(1,1,1),(1,1,2),(2,3,3),(3,3,3)</var> satisfy the condition, so the answer is <var>4</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>36
36
20
20
20
36
36
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>149393349
149393349
668669001
668669001
4000002
4000002
4000002
668669001
668669001
149393349
149393349
</pre></section>
</div>
</span> |
p01563 |
<h1>Connect</h1>
<p>You are playing a solitaire puzzle called "Connect", which uses several letter tiles.
</p>
<p>There are <var>R × C</var> empty cells.
For each <var>i</var> <var>(1 ≤ i ≤ R)</var>, you must put a string <var>s<sub>i</sub></var> <var>(1 ≤ |s<sub>i</sub>| ≤ C)</var> in the <var>i</var>-th row of the table, without changing the letter order.
In other words, you choose an integer sequence <var>{a<sub>j</sub>}</var> such that
<var>1 ≤ a<sub>1</sub> < a<sub>2</sub> < ... < a<sub>|s<sub>i</sub>|</sub> ≤ C</var>
, and put the <var>j</var>-th character of the string <var>s<sub>i</sub></var> in the <var>a<sub>j</sub></var>-th column <var>(1 ≤ j ≤ |s<sub>i</sub>|)</var>.
</p>
<p>For example, when <var>C = 8</var> and <var>s<sub>i</sub> =</var> "ICPC", you can put <var>s<sub>i</sub></var> like followings.
</p><pre>I_C_P_C_
ICPC____
_IC___PC
</pre><p>'_' represents an empty cell.
</p>
<p>For each non-empty cell <var>x</var>, you get a point equal to the number of adjacent cells which have the same character as <var>x</var>.
Two cells are adjacent if they share an edge.
</p>
<p>Calculate the maximum total point you can get.
</p>
<h2>Input</h2>
<p>The first line contains two integers <var>R</var> and <var>C</var> <var>(1 ≤ R ≤ 128, 1 ≤ C ≤ 16)</var>.
</p>
<p> Then <var>R</var> lines follow, each of which contains <var>s<sub>i</sub></var>
<var>(1 ≤ |s<sub>i</sub>| ≤ C)</var>.
All characters of <var>s<sub>i</sub></var> are uppercase letters.
</p>
<h2>Output</h2>
<p>Output the maximum total point in a line.
</p>
<h2>Sample Input 1</h2>
<pre>2 4
ACM
ICPC
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>2
</pre>
<h2>Sample Input 2</h2>
<pre>2 9
PROBLEMF
CONNECT
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>6
</pre>
<h2>Sample Input 3</h2>
<pre>4 16
INTERNATIONAL
COLLEGIATE
PROGRAMMING
CONTEST
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>18
</pre>
|
p01099 |
<h3>Warp Drive</h3>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2016_G_airplane" width="30%" align="right">
<p>
The <b>warp drive</b> technology is reforming air travel, making the travel times drastically shorter.
Aircraft reaching above the <b>warp fields</b> built on the ground surface can be transferred to any desired destination in a twinkling.
</p>
<p>
With the current immature technology, however, building warp fields is quite expensive.
Our budget allows building only two of them.
Fortunately, the cost does not depend on the locations of the warp fields,
and we can build them anywhere on the ground surface, even at an airport.
</p>
<p>
Your task is, given locations of airports and a list of one way flights among them, find the best locations to build the two warp fields that give the minimal <b>average cost</b>.
The average cost is the root mean square of travel times of all the flights, defined as follows.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2016_G1">
</center>
<p>
Here, <i>m</i> is the number of flights and <i>t</i><sub><i>j</i></sub> is the shortest possible travel time of the <i>j</i>-th flight.
Note that the value of <i>t</i><sub><i>j</i></sub> depends on the locations of the warp fields.
</p>
<p>
For simplicity, we approximate the surface of the ground by a flat two dimensional plane, and approximate airports, aircraft, and warp fields by points on the plane.
Different flights use different aircraft with possibly different cruising speeds.
Times required for climb, acceleration, deceleration and descent are negligible.
Further, when an aircraft reaches above a warp field, time required after that to its destination is zero.
As is explained below, the airports have integral coordinates. Note, however, that the warp fields can have non-integer coordinates.
</p>
<h3>Input</h3>
<p>
The input consists of at most 35 datasets, each in the following format.
</p>
<p>
<i>n</i> <i>m</i> <br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br>
... <br>
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <br>
<i>a</i><sub>1</sub> <i>b</i><sub>1</sub> <i>v</i><sub>1</sub> <br>
... <br>
<i>a</i><sub><i>m</i></sub> <i>b</i><sub><i>m</i></sub> <i>v</i><sub><i>m</i></sub> <br>
</p>
<p>
<i>n</i> is the number of airports, and <i>m</i> is the number of flights (2 ≤ <i>n</i> ≤ 20, 2 ≤ <i>m</i> ≤ 40).
For each <i>i</i>, <i>x</i><sub><i>i</i></sub> and <i>y</i><sub><i>i</i></sub> are the coordinates of the <i>i</i>-th airport.
<i>x</i><sub><i>i</i></sub> and <i>y</i><sub><i>i</i></sub> are integers with absolute values at most 1000.
For each <i>j</i>, <i>a</i><sub><i>j</i></sub> and <i>b</i><sub><i>j</i></sub> are integers between 1 and <i>n</i> inclusive, and are the indices of the departure and arrival airports for the <i>j</i>-th flight, respectively.
<i>v</i><sub><i>j</i></sub> is the cruising speed for the <i>j</i>-th flight, that is, the distance that the aircraft of the flight moves in one time unit.
<i>v</i><sub><i>j</i></sub> is a decimal fraction with two digits after the decimal point (1 ≤ <i>v</i><sub><i>j</i></sub> ≤ 10).
</p>
<p>
The following are guaranteed.
<ul>
<li>Two different airports have different coordinates.</li>
<li>The departure and arrival airports of any of the flights are different.</li>
<li>Two different flights have different departure airport and/or arrival airport.</li>
</ul>
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<h3>Output</h3>
<p>
For each dataset, output the average cost when you place the two warp fields optimally.
The output should not contain an absolute error greater than 10<sup>-6</sup>.
</p>
<h3>Sample Input</h3>
<pre>
3 4
100 4
100 0
0 0
1 2 1.00
2 1 1.00
3 1 9.99
3 2 9.99
7 6
0 0
1 0
2 0
0 10
1 10
2 10
20 5
1 7 1.00
2 7 1.00
3 7 1.00
4 7 1.00
5 7 1.00
6 7 1.00
4 4
-1 -1
1 -1
-1 1
1 1
1 4 1.10
4 2 2.10
2 3 3.10
3 1 4.10
8 12
-91 0
-62 0
-18 0
2 0
23 0
55 0
63 0
80 0
2 7 3.96
3 2 2.25
2 4 5.48
8 7 9.74
5 6 6.70
7 6 1.51
4 1 7.41
5 8 1.11
6 3 2.98
3 4 2.75
1 8 5.89
4 5 5.37
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1.414214
0.816497
0.356001
5.854704
</pre> |
p01133 |
<h1><font color="#000000">Problem C:</font> Dragon Fantasy</h1>
<p>
永遠に続くと思われていた平和は突然終わりを告げた。 はるか昔に封印されていた魔王がついに復活を遂げたのである。 だが、今まさに世界が闇に覆われようとしているとき、1 人の勇者が現れた。 そしてその勇者は、世界各地に散らばっている伝説のクリスタルを集める旅に出た。 伝説によると、全てのクリスタルを集めることができたならば、どのような願いでもかなえられるという伝説の龍神を呼び出すことができると伝えられている。 その龍神の力を借りれば魔王を倒すことも可能なはずだ。
</p>
<p>
クリスタルは世界各地に散らばっている。 勇者はそれらを 1 つずつ、自らの手で集めていく必要がある。 なぜなら、勇者以外の者がクリスタルを手に入れたならば、魔王の手先によって奪われてしまうかもしれないからである。 勇者は、1 日あたりユークリッド距離で 1 だけ移動することができる。
</p>
<p>
しかし、ここで 1 つの重大な問題がある。 魔王は、常に闇の瘴気をまき散らしており、その瘴気に汚染された場所は人が立ち入ることのできない死の大地と化してしまう。 たとえ勇者であってもその場所に立ち入ることはできない。 さらに、その瘴気は時間とともに同心円状に広まっていくため、 時間の経過とともに勇者の移動できる領域は減少していってしまう。 瘴気は 1 日あたりユークリッド距離 1 だけ広がることが確認されている。 そして、その境界線上にあるクリスタルを勇者は取ることはできない。また、復活したばかりの魔王は力を蓄えるために動かないことも分かっている。
</p>
<p>
勇者は一刻も早くクリスタルを手に入れなければならない。 しかし、もし全てのクリスタルを手に入れることが不可能であるならば、別の手段を考えなければならないだろう。 そこで、あなたには勇者の初期位置と魔王の復活した場所、そしてクリスタルの存在する位置から、全てのクリスタルを手に入れることができるかどうかを調べるプログラムを作っていただきたい。
</p>
<p>
ちなみに、勇者は疲れない。 そして眠らない。 全てのクリスタルを集めて世界を救うまでは絶えず動き続け、クリスタルを集めるのだ!!
</p>
<h2>Input</h2>
<p>
入力は複数のテストケースから構成される。 各テストケースの先頭の行では 5 つの整数 <i>n</i> (0 < <i>n</i> <= 20)、<i>h<sub>x</sub></i> 、<i>h<sub>y</sub></i> 、<i>d<sub>x</sub></i> 、<i>d<sub>y</sub></i> が与えられる。
<i>n</i> はクリスタルの個数、(<i>h<sub>x</sub></i> , <i>h<sub>y</sub></i> ) は魔王が復活した瞬間での勇者の位置、(<i>d<sub>x</sub></i> , <i>d<sub>y</sub></i> ) は魔王が復活した位置である。
後に続く <i>n</i> 行には、各クリスタルの位置を表す 2 つの整数 <i>c<sub>x</sub></i> 、<i>c<sub>y</sub></i> が与えられる。 入力は <i>n</i> = <i>h<sub>x</sub></i> = <i>h<sub>y</sub></i> = <i>d<sub>x</sub></i> = <i>d<sub>y</sub></i> = 0 のときに終了し、これはテストケースには含まない。
</p>
<p>
入力で与えられる全ての座標は絶対値が 1000 以下の整数であることが保証されている。
</p>
<h2>Output</h2>
<p>各テストケースについて、全てのクリスタルを集めることができるならば「YES」と、そうでないならば「NO」と出力せよ。
</p>
<h2>Sample Input</h2>
<pre>
2 0 0 10 10
1 1
4 4
2 0 0 10 10
1 1
6 6
2 0 0 10 10
1 1
5 5
0 0 0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
YES
NO
NO
</pre> |
p00372 | <H1>Party</H1>
<p>
The students in a class in Akabe high-school define the relation “acquaintance” as:
</p>
<ul>
<li>If A and B are friends, then A is acquainted with B.</li>
<li>If A and B are friends and B is acquainted with C, then A is acquainted with C.</li>
</ul>
<p>
They define the relation “companion” as:
</p>
<ul>
<!-- Suppose A is acquainted with B, and some classmate who has been friends with A and B distances himself from them. If A is still acquainted with B, then A and B are companions.-->
<li>
Suppose A is acquainted with B, and two classmates who have been friend distance. If A is still acquainted with B, then A and B are companions.
</li>
</ul>
<p>
A boy PCK joined the class recently and wishes to hold a party inviting his class fellows. He wishes to invite as many boys and girls as possible to the party and has written up an invitation list. In arranging the list, he placed the following conditions based on the acquaintanceship within the class before he joined.
</p>
<p>
When T is in the list:
</p>
<ul>
<li>U is listed if he/she is a companion of T.</li>
<li>If U is not a companion of T, U is not listed if he/she and T are friends, or he/she and some of T’s companions are friends.</li>
</ul>
<p>
PCK made the invitation list so that the maximum number of his classmates is included.
</p>
<p>
Given the number of classmates <var>N</var> and the friendships among them, write a program to estimate the number of boys and girls in the list. All the classmates are identified by an index that ranges from 0 to <var>N</var>-1.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>M</var>
<var>s_1</var> <var>t_1</var>
<var>s_2</var> <var>t_2</var>
:
<var>s_M</var> <var>t_M</var>
</pre>
<p>
The first line provides the number of classmates <var>N</var> (2 ≤ <var>N</var> ≤ 10<sup>5</sup>) and the number of friendships <var>M</var> (1 ≤ <var>M</var> ≤ 2×10<sup>5</sup>). Each of the <var>M</var> subsequent lines provides two of the classmates <var>s_i, t_i</var> (0 ≤ <var>s_i,t_i</var> ≤ <var>N</var>-1) indicating they are friends. No duplicate relationship appears among these lines.
</p>
<h2>Output</h2>
<p>
Output the maximum number of classmates PCK invited to the party.
</p>
<h2>Sample Input 1</h2>
<pre>
7 8
0 1
1 2
1 3
2 3
0 4
4 5
4 6
5 6
</pre>
<h2>Sample Output 1</h2>
<pre>
6
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2
0 1
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre>
|
p00688 |
<h1>
Factorization of Quadratic Formula</h1>
<p>As the first step in algebra, students learn quadratic formulas and
their factorization. Often, the factorization is a severe burden
for them. A large number of students cannot master the factorization;
such students cannot be aware of the elegance of advanced algebra.
It might be the case that the factorization increases the number of people
who hate mathematics.</p>
<p>Your job here is to write a program which helps students of
an algebra course. Given a quadratic formula, your program should report
how the formula can be factorized into two linear formulas.
All coefficients of quadratic formulas and those of resultant
linear formulas are integers in this problem.</p>
<p>The coefficients <i>a</i>, <i>b</i> and <i>c</i> of a quadratic formula
<i>ax</i><sup>2</sup> + <i>bx</i> + <i>c</i> are given.
The values of <i>a</i>, <i>b</i> and <i>c</i> are integers,
and their absolute values do not exceed 10000.
From these values, your program is requested to find four integers
<i>p</i>, <i>q</i>, <i>r</i> and <i>s</i>, such that
<i>ax</i><sup>2</sup> + <i>bx</i> + <i>c</i> =
(<i>px</i> + <i>q</i>)(<i>rx</i> + <i>s</i>).</p>
<p>Since we are considering integer coefficients only, it is not
always possible to factorize a quadratic formula into linear formulas.
If the factorization of the given formula is impossible,
your program should report that fact.</p>
<h2>Input</h2>
<p>The input is a sequence of lines, each representing
a quadratic formula.
An input line is given in the following format.</p>
<blockquote>
<i>a</i> <i>b</i> <i>c</i>
</blockquote>
<p>Each of <i>a</i>, <i>b</i> and <i>c</i> is an integer.
They satisfy the following inequalities.
<blockquote>
0 < <i>a</i> <= 10000
<br>
-10000 <= <i>b</i> <= 10000
<br>
-10000 <= <i>c</i> <= 10000
</blockquote>
<p>The greatest common divisor of <i>a</i>, <i>b</i> and <i>c</i> is 1.
That is, there is no integer <i>k</i>, greater than 1,
such that all of <i>a</i>, <i>b</i> and <i>c</i> are divisible by <i>k</i>.</p>
<p>The end of input is indicated by a line consisting of three 0's.</p>
<h2>Output</h2>
<p>For each input line, your program should output the four integers
<i>p</i>, <i>q</i>, <i>r</i> and <i>s</i> in a line, if they exist.
These integers should be output in this order, separated by
one or more white spaces.
If the factorization is impossible, your program should output a line
which contains the string "Impossible" only.</p>
<p>The following relations should hold between the values
of the four coefficients.</p>
<blockquote>
<i>p</i> > 0
<br>
<i>r</i> > 0
<br>
(<i>p</i> > <i>r</i>) or (<i>p</i> = <i>r</i> and <i>q</i> >= <i>s</i>)
</i></blockquote>
<p>These relations, together with the fact that the greatest common
divisor of <i>a</i>, <i>b</i> and <i>c</i> is 1,
assure the uniqueness of the solution.
If you find a way to factorize the formula, it is not necessary
to seek another way to factorize it.</p>
<h2>Sample Input</h2>
<pre>
2 5 2
1 1 1
10 -7 0
1 0 -3
0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
2 1 1 2
Impossible
10 -7 1 0
Impossible
</pre>
|
p01830 |
<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>Delete Files</h2>
<p>
You are using an operating system named "Jaguntu". Jaguntu provides "Filer", a file manager with a graphical user interface.
</p>
<p>
When you open a folder with Filer, the name list of files in the folder is displayed on a Filer window. Each filename is displayed within a rectangular region, and this region is called a filename region. Each filename region is aligned to the left side of the Filer window. The height of each filename region is 1, and the width of each filename region is the filename length. For example, when three files "acm.in1", "acm.c~", and "acm.c" are stored in this order in a folder, it looks like Fig. C-1 on the Filer window.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2015_C_1"><br/>
</center>
<p>
You can delete files by taking the following steps. First, you select a rectangular region with dragging a mouse. This region is called selection region. Next, you press the delete key on your keyboard. A file is deleted if and only if its filename region intersects with the selection region. After the deletion, Filer shifts each filename region to the upside on the Filer window not to leave any top margin on any remaining filename region. For example, if you select a region like Fig. C-2, then the two files "acm.in1" and "acm.c~" are deleted, and the remaining file "acm.c" is displayed on the top of the Filer window as Fig. C-3.
</p>
<p>
You are opening a folder storing $N$ files with Filer. Since you have almost run out of disk space, you want to delete unnecessary files in the folder. Your task is to write a program that calculates the minimum number of times to perform deletion operation described above.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2015_C_2"><br/>
<br/>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2015_C_3"><br/>
</center>
<h3>Input</h3>
<p>
The input consists of a single test case. The test case is formatted as follows.<br/>
<br/>
$N$<br/>
$D_1$ $L_1$<br/>
$D_2$ $L_2$<br/>
...<br/>
$D_N$ $L_N$<br/>
</p>
<p>
The first line contains one integer $N$ ($1 \leq N \leq 1,000$), which is the number of files in a folder. Each of the next $N$ lines contains a character $D_i$ and an integer $L_i$: $D_i$ indicates whether the $i$-th file should be deleted or not, and $L_i$ ($1 \leq L_i \leq 1,000$) is the filename length of the $i$-th file. If $D_i$ is 'y', the $i$-th file should be deleted. Otherwise, $D_i$ is always 'n', and you should not delete the $i$-th file.
</p>
<h3>Output</h3>
<p>
Output the minimum number of deletion operations to delete only all the unnecessary files.
</p>
<h3>Sample Input 1</h3>
<pre>
3
y 7
y 6
n 5
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
1
</pre>
<h3>Sample Input 2</h3>
<pre>
3
y 7
n 6
y 5
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
2
</pre>
<h3>Sample Input 3</h3>
<pre>
6
y 4
n 5
y 4
y 6
n 3
y 6
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
2
</pre> |
p00722 |
<h1><font color="#000">Problem A:</font> Dirichlet's Theorem on Arithmetic Progressions</h1>
<p>
Good evening, contestants.
</p>
<p>
If <i>a</i> and <i>d</i> are relatively prime positive integers,
the arithmetic sequence beginning with <i>a</i>
and increasing by <i>d</i>, i.e.,
<i>a</i>,
<i>a</i> + <i>d</i>,
<i>a</i> + 2<i>d</i>,
<i>a</i> + 3<i>d</i>,
<i>a</i> + 4<i>d</i>,
...,
contains infinitely many prime numbers.
This fact is known as Dirichlet's Theorem on Arithmetic Progressions,
which had been conjectured by Johann Carl Friedrich Gauss (1777 - 1855)
and was proved by Johann Peter Gustav Lejeune Dirichlet (1805 - 1859)
in 1837.
</p>
<p>
For example,
the arithmetic sequence beginning with 2 and increasing by 3,
i.e.,
</p>
<blockquote>
2,
5,
8,
11,
14,
17,
20,
23,
26,
29,
32,
35,
38,
41,
44,
47,
50,
53,
56,
59,
62,
65,
68,
71,
74,
77,
80,
83,
86,
89,
92,
95,
98,
...
,
</blockquote>
<p>
contains infinitely many prime numbers
</a></p>
<!-- end en only -->
<blockquote>
2,
5,
11,
17,
23,
29,
41,
47,
53,
59,
71,
83,
89,
...
<!-- begin en only -->
.
<!-- end en only -->
</blockquote>
<!-- begin en only -->
<p>
Your mission, should you decide to accept it,
is to write a program to find
the <i>n</i>th prime number in this arithmetic sequence
for given positive integers <i>a</i>, <i>d</i>, and <i>n</i>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
As always, should you or any of your team be tired or confused,
the secretary disavow any knowledge of your actions.
This judge system will self-terminate in three hours.
Good luck!
</p>
<!-- end en only -->
<h2>Input</h2>
<!-- begin en only -->
<p>
The input is a sequence of datasets.
A dataset is a line containing three positive integers
<i>a</i>, <i>d</i>, and <i>n</i> separated by a space.
<i>a</i> and <i>d</i> are relatively prime.
You may assume <i>a</i> <= 9307, <i>d</i> <= 346,
and <i>n</i> <= 210.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line
containing three zeros separated by a space.
It is not a dataset.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
</p>
<!-- end en only -->
<h2>Output</h2>
<!-- begin en only -->
<p>
The output should be composed of
as many lines as the number of the input datasets.
Each line should contain a single integer
and should never contain extra characters.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The output integer corresponding to
a dataset <i>a</i>, <i>d</i>, <i>n</i> should be
the <i>n</i>th
prime number among those contained
in the arithmetic sequence beginning with <i>a</i>
and increasing by <i>d</i>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
FYI, it is known that the result is always less than
10<sup>6</sup> (one million)
under this input condition.
</p>
<!-- end en only -->
<h2>Sample Input</h2>
<pre>
367 186 151
179 10 203
271 37 39
103 230 1
27 104 185
253 50 85
1 1 1
9075 337 210
307 24 79
331 221 177
259 170 40
269 58 102
0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
92809
6709
12037
103
93523
14503
2
899429
5107
412717
22699
25673
</pre>
|
p00237 |
<H1>最後の扉</H1>
<p>
秘境の地"ナラマンダ地方"<br>
この奥深い洞窟に眠る黄金の伝説を求め、探検家ボブとマイクは様々な困難に立ち向かいました。ようやくたどり着いた最後の扉。この先には夢に見た黄金が待っています。
</p>
<p>
その扉には多数の三角形が描かれていました。試しにマイクがその 1 つに触れてみると、その三角形は光を放ちました。光は三角形の底辺から垂直に頂点方向へ長方形を描きながら伸びていき、その先にある別の三角形に触れました。すると、光に触れた三角形も同じように光を放ち、それを繰り返していきました。
</p>
<p>
扉の三角形は全て二等辺三角形(正三角形は含まない)で、どれも同じ大きさで、どれも重ならず(かつ触れることなく)、またどれも光は一定の距離だけ伸びていました。最後の三角形が光り終えると、そこには何事もなかったかのような静けさが戻ってきました。
</p>
<p>
ボブは自分の足下に奇妙なメッセージを見つけました。<br>
「むやみに触れるべからず。汝正しくこの扉に触れたとき、この扉は放たれん。 」
</p>
<p>
ボブとマイクはこのメッセージの意味を考えながら、 何度も三角形に触れてみましたがなかなか扉は開きません。 しかし、それを繰り返していくうちに、二人はメッセージの意味がだんだん分かってきました。<br>
「"むやみに触れるべからず"とは、扉に触れる回数は最小ということ。<br>
できるだけ少ない回数で触れて、全ての三角形を光らせれば、きっと扉は開くはずだ!」<br>
</p>
<p>
例えば、扉には図 1 のように複数の二等辺三角形が描かれています。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_cave1"><br>
図 1
</center>
<br>
<p>
最初に左下の三角形に触れると、図 2 に示すように、その三角形の底辺から垂直に頂点方向へ光が放たれ、その光が触れる三角形が次々に光ります。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_cave2"><br>
図 2
</center>
<br>
<p>
次に左端の三角形に触れると、図 3 に示すように、全ての三角形が光ります。この手順が全ての三角形を光らせるための最少の手数(2 手)となります。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_cave3"><br>
<p>図 3</p>
</center>
<p>
さあ、ボブとマイクが最後の扉を開ける手助けをしよう。
</p>
<p>
扉に描かれている三角形の個数、光の伸びる長さ、それぞれの三角形の頂点の座標を入力とし、全ての三角形を光らせるために扉に触れる最少の回数を出力するプログラムを作成して下さい。光の伸びる長さは、底辺からの長さであるものとします。また、光はそれを放つ三角形の頂点を含むような十分な長さを持ちます。
</p>
<p>
なお、この問題を解くにあたっては、2 点の距離が 0.01 以下の場合には、同一の点と処理します。また、1 点とひとつの直線の距離が 0.01 以下の場合には、この点はこの直線上にあるとして処理します。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えらる。入力の終わりはゼロふたつの行で示される。各データセットは以下の形式で与えらる。
</p>
<pre>
<var>n</var> <var>d</var>
<var>T<sub>1</sub></var>
<var>T<sub>2</sub></var>
:
<var>T<sub>n</sub></var>
</pre>
<p>
1行目に扉に描かれている三角形の個数 <var>n</var> (1 ≤ <var>n</var> ≤ 100) と光の伸びる長さを表す整数 <var>d</var> (1 ≤ <var>d</var> ≤ 1000) が与えられる。
</p>
<p>
続く <var>n</var> 行に各三角形の情報 <var>T<sub>i</sub></var> が以下の形式で与えられる。
</p>
<pre>
<var>x1</var> <var>y1</var> <var>x2</var> <var>y2</var> <var>x3</var> <var>y3</var>
</pre>
<p>
三角形の3つの頂点の座標が整数で与えられる(-1000 ≤ <var>x1</var>, <var>y1</var>, <var>x2</var>, <var>y2</var>, <var>x3</var>, <var>y3</var> ≤ 1000)。
</p>
<p>
データセットの数は 20 を超えない。
</p>
<H2>Output</H2>
<p>
データセットごとに、扉に触れる最少の回数を1行に出力する。
</p>
<H2>Sample Input</H2>
<pre>
3 4
1 0 3 0 2 1
2 3 2 5 3 4
5 3 5 5 6 4
3 2
1 0 3 0 2 1
2 3 2 5 3 4
5 3 5 5 6 4
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
3
</pre>
|
p01975 | <h1>B: 写像</h1>
<h2>問題</h2>
<p>
AORイカちゃんは集合 $S = \{a_1, ..., a_N\}$ と写像 $f: S→S$を作った。$f(a_i) = b_i$ である。
集合 $S$ の任意の要素 $x$ について、$g(f(x)) = h(f(x))$ を満たす全ての写像 $g, h: S→S$ が、$g(x) = h(x)$ を満たすかどうか判定し、満たさない場合は反例を一つ構成せよ。
</p>
<h2>制約</h2>
<ul>
<li>$1 \le N \le 10^5$</li>
<li>$1 \le a_i,b_i \le N$</li>
<li>$a_i \neq a_j \ (i \neq j)$</li>
<li>入力は全て整数</li>
</ul>
<h2>入力:</h2>
<p>
$N$<br>
$a_1 \cdots a_N$<br>
$b_1 \cdots b_N$<br>
</p>
<h2>出力:</h2>
<p>
条件を満たす場合は<br>
<strong>Yes</strong>
</p>
<p>
条件を満たさない場合は、反例を $g(a_i) = c_i, h(a_i) = d_i$ として<br>
<strong>No</strong><br>
$c_1 \cdots c_N$<br>
$d_1 \cdots d_N$<br>
</p>
<p>
を出力せよ。また末尾に改行を出力せよ。
</p>
<h2>サンプル</h2>
<h3>サンプル入力 1</h3>
<pre>
5
1 2 3 4 5
3 4 2 5 1
</pre>
<h3>サンプル出力 1</h3>
<pre>
Yes
</pre>
<h3>サンプル入力 2</h3>
<pre>
5
1 2 3 4 5
3 4 3 5 1
</pre>
<h3>サンプル出力 2</h3>
<pre>
No
3 1 5 2 4
3 2 5 2 4
</pre>
<!-- - - - - - end nicebody - - - - - -->
|
p03948 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> towns located in a line, conveniently numbered <var>1</var> through <var>N</var>. Takahashi the merchant is going on a travel from town <var>1</var> to town <var>N</var>, buying and selling apples.</p>
<p>Takahashi will begin the travel at town <var>1</var>, with no apple in his possession. The actions that can be performed during the travel are as follows:</p>
<ul>
<li><em>Move</em>: When at town <var>i</var> (<var>i < N</var>), move to town <var>i + 1</var>.</li>
<li><em>Merchandise</em>: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for <var>A_i</var> yen (the currency of Japan) at town <var>i</var> (<var>1 ≦ i ≦ N</var>), where <var>A_i</var> are distinct integers. Also, you can assume that he has an infinite supply of money.</li>
</ul>
<p>For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most <var>T</var>. (Note that a single apple can be counted in both.)</p>
<p>During the travel, Takahashi will perform actions so that the <em>profit</em> of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.</p>
<p>Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change <var>A_i</var> into another arbitrary non-negative integer <var>A_i'</var> for any town <var>i</var>, any number of times. The cost of performing this operation is <var>|A_i - A_i'|</var>. After performing this operation, different towns may have equal values of <var>A_i</var>.</p>
<p>Aoki's objective is to decrease Takahashi's expected profit by at least <var>1</var> yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least <var>1</var> yen.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ N ≦ 10^5</var></li>
<li><var>1 ≦ A_i ≦ 10^9</var> (<var>1 ≦ i ≦ N</var>)</li>
<li><var>A_i</var> are distinct.</li>
<li><var>2 ≦ T ≦ 10^9</var></li>
<li>In the initial state, Takahashi's expected profit is at least <var>1</var> yen.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>T</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total cost to decrease Takahashi's expected profit by at least <var>1</var> yen.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
100 50 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>In the initial state, Takahashi can achieve the maximum profit of <var>150</var> yen as follows:</p>
<ol>
<li>Move from town <var>1</var> to town <var>2</var>.</li>
<li>Buy one apple for <var>50</var> yen at town <var>2</var>.</li>
<li>Move from town <var>2</var> to town <var>3</var>.</li>
<li>Sell one apple for <var>200</var> yen at town <var>3</var>.</li>
</ol>
<p>If, for example, Aoki changes the price of an apple at town <var>2</var> from <var>50</var> yen to <var>51</var> yen, Takahashi will not be able to achieve the profit of <var>150</var> yen. The cost of performing this operation is <var>1</var>, thus the answer is <var>1</var>.</p>
<p>There are other ways to decrease Takahashi's expected profit, such as changing the price of an apple at town <var>3</var> from <var>200</var> yen to <var>199</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 8
50 30 40 10 20
</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>10 100
7 10 4 5 9 3 6 8 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> |
p00667 |
<H1>Problem I: 11224111122411</H1>
<p>
腕が引っかかって抜けない。
</p>
<p>
机の裏に転がり込んでしまったものを拾おうとして、懐中電灯代わりに携帯の画面で照らしながら腕を挿し込んでみたが、うっかり何かに引っかかって抜けなくなってしまった。無理に動かすと痛い。
</p>
<p>
どうしよう。どうすれば脱出できるのだろう。大声で助けを呼ぶか。恥ずかしいので却下したいが、独力で脱出するのは難しそうだ。いや、声の届く範囲には誰もいなかったはずだ。焦る気持ちを押さえて辺りを見渡す。あのパソコンに手が届けばメールで助けを呼べるのだが、あいにく遠すぎる。やはり偶然誰かが通りかかるのを待つしかないのか。
</p>
<p>
いや待て、メールを送る機械ならあるじゃないか。手の届くところというよりも、既にこの手の中に。深く伸ばした手の先の画面はぼやけてよく見えないが、長年使っている携帯だ。画面が見えなくてもメールぐらいは送れるはずだ。
</p>
<p>
慎重に、頭の中に画面を描きながらボタンを押す。指の感触だけを頼りに、タイプミスだけはしないように、数字キーを何度も押してメッセージを打ち込む。漢字変換はしない、平仮名でもきっと伝わるはずだ。つくづくタッチパネルが主流のスマートフォンに乗り換えていなくてよかったと思う。
</p>
<p>
深呼吸をして、送信ボタンに指をかける。しばらくして、携帯が軽く震えた。送信完了の合図だ。溜息。しばらくすれば友人が助けに来るに違いない。
</p>
<p>
友人は賢いので適切に解釈してくれると思うのだが、今送ったメッセージは、本当に送りたかったメッセージとは違うものになっているかもしれない。この携帯の文字入力メソッドは広く使われているものと同じで、例えば「あ」行の平仮名を入力するのに "1" のボタンを使う。 "1" は「あ」を、 "11" は「い」を、以下同様に "11111" が「お」を表す。平仮名はループする、つまり "111111" もまた「あ」となる。「か」行は "2" 、「さ」行は "3" 、 ... を使い、同じボタンを続けて押したときの挙動は "1" の例と同様である。
</p>
<p>
ただし、この文字入力メソッドにはちょっと厄介な挙動がある。数字ボタンを押した後しばらく操作しないでいると、平仮名への変換が強制的に行われてしまうのだ。つまり、3回続けて "1" を押せば 「う」 になるが、時間を置いて3回 "1" を押すと「あああ」になる。別の例をあげると、 "111111" と押したとき、その押す間隔によって入力された文字列は「あ」にも「ああああああ」にもなる。"111111111111"は「い」かもしれないし、「ええいああ」かもしれないし、12個の「あ」になるかもしれない。なお、違う数字ボタンを押したときにも平仮名への変換はおこなわれるので、 "12345" は「あかさたな」という文字列にしかなりえない。
</p>
<p>
さて、慎重にタイプしたので間違ったボタンを押したつもりはないのだが、適切な間隔でボタンを押せた自信はない。本当に送りたかったメッセージとは違うものを送ってしまった可能性は大いにあるのだ。さて、送られたかもしれない文字列の数は何通りだろうか。ああ、これは友人が助けに来るまでの暇つぶしにいいかもしれない。遅くても5時間以内に助けに来てくれるだろう。それまでに解けるといいのだけど。
</p>
<h2>Input</h2>
<p>
入力は複数のケースからなる。<br>
各ケースは以下のフォーマットで与えられる。
</p>
<pre>
<i>string</i>
</pre>
<p>
入力の終わりは,入力が"#"からなる行によって与えられる
</p>
<p>
<i>string</i> は0から9の間の数字を最大100,000個含む。<br>
<i>string</i> の長さが10,000を越える入力は50個を超えない。<br>
</p>
<p>
テストケースのファイルサイズは5MB以下であることが保証される。<br>
またテストケースの数は100を超えない。<br>
</p>
<p>
各数字キーで入力可能な文字は以下の表のとおりである。
</p>
<p>
<table border="1">
<tr><td>数字</td> <td>入力可能な文字</td></tr>
<tr><td>1</td> <td>あいうえお</td></tr>
<tr><td>2</td> <td>かきくけこ</td></tr>
<tr><td>3</td> <td>さしすせそ</td></tr>
<tr><td>4</td> <td>たちつてと</td></tr>
<tr><td>5</td> <td>なにぬねの</td></tr>
<tr><td>6</td> <td>はひふへほ</td></tr>
<tr><td>7</td> <td>まみむめも</td></tr>
<tr><td>8</td> <td>やゆよ</td></tr>
<tr><td>9</td> <td>らりるれろ</td></tr>
<tr><td>0</td> <td>わをん</td></tr>
</table>
</p>
<h2>Output</h2>
<p>
文章の解釈の仕方を100000007で割った余りを1行に出力せよ。
</p>
<h2>Sample input</h2>
<pre>
1
11
111111
111111111111
12345
11111111119999999999
11111111113333333333
11111111118888888888
11111111112222222222111111111
11111111110000000000444444444
11224111122411
888888888888999999999999888888888888999999999999999999
666666666666666777333333333338888888888
1111114444441111111444499999931111111222222222222888111111115555
#
</pre>
<H2>Sample output</H2>
<pre>
1
2
32
1856
1
230400
230400
156480
56217600
38181120
128
26681431
61684293
40046720
</pre>
<hr>
<p>
The University of Aizu Programming Contest 2011 Summer<br>
原案: Tomoya Sakai<br>
問題文: Takashi Tayama<br>
</p>
|
p01426 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Vector Compression</H1>
<p>
You are recording a result of a secret experiment, which consists of a large set of <var>N</var>-dimensional vectors.
Since the result may become very large, you are thinking of
compressing it. Fortunately you already have a good compression method
for vectors with small absolute values, all you have to do is to
preprocess the vectors and make them small.
</p>
<p>
You can record the set of vectors in any order you like.
Let's assume you process them in the order <var>v_1</var>, <var>v_2</var>,..., <var>v_M</var>.
Each vector <var>v_i</var> is recorded either <i>as is</i>, or as a difference vector.
When it is recorded as a difference,
you can arbitrarily pick up an already chosen vector <var>v_j (j<i)</var> and a real value <var>r</var>.
Then the actual vector value recorded is <var>(v_i - r v_j)</var>.
The values of <var>r</var> and <var>j</var> do not affect the compression ratio so much, so you don't have to care about them.
</p>
<p>
Given a set of vectors,
your task is to write a program that calculates the minimum sum of the squared length of the recorded vectors.
</p>
<H2>Input</H2>
<p>
The input is like the following style.
</p>
<p>
<var>N</var> <var>M</var><br/>
<var>v_{1,1}</var> <var>v_{1,2}</var> <var>...</var> <var>v_{1,N}</var><br/>
<var>...</var><br/>
<var>v_{M,1}</var> <var>v_{M,2}</var> <var>...</var> <var>v_{M,N}</var><br/>
</p>
<p>
The first line contains two integers <var>N</var> and <var>M</var> (<var>1 \leq N, M \leq 100</var>),
where <var>N</var> is the dimension of each vector,
and <var>M</var> is the number of the vectors.
Each of the following <var>M</var> lines contains <var>N</var> floating point values <var>v_{i,j}</var> (<var>-1.0 \leq v_{i,j} \leq 1.0</var>)
which represents the <var>j</var>-th element value of the <var>i</var>-th vector.
</p>
<H2>Output</H2>
<p>
Output the minimum sum of the squared length of the recorded vectors.
The output should not contain an absolute error greater than <var>10^{-6}</var>.
</p>
<H2>Sample Input 1</H2>
<pre>
2 3
1.0 1.0
-1.0 0.0
0.5 0.5
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
1.0
</pre>
<H2>Sample Input 2</H2>
<pre>
1 1
1.0
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
1.0
</pre>
<H2>Sample Input 3</H2>
<pre>
4 3
1.0 1.0 0.0 0.0
-1.0 0.0 -1.0 0.0
0.5 0.5 0.5 0.5
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
3.0
</pre>
|
p01076 |
<h1>Problem E: Graph Making</h1>
<h2>Problem</h2>
<p>
どの頂点とも連結でない<var>n</var>個の頂点がある。<br>
各頂点間に無向辺を張っていく。<br>
直径が<var>d</var>になるようにしたとき、最大何本の辺を張ることができるか求めよ。<br>
<!--
直径とは各頂点と連結の頂点との最短距離のうち最大を表す。<br>
-->
直径とは、2つの頂点間の最短距離のうち最大のものを表す。<br>
ここで、最短距離は頂点間を移動するために必要な辺の数の最小値である。<br>
多重辺、自己ループは認めない。
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>d</var>
</pre>
<p>
1行に2つの整数<var>n</var>と<var>d</var>が空白区切りで与えられる。
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>n</var> ≤ 10<sup>9</sup></li>
<li>1 ≤ <var>d</var> ≤ <var>n−</var>1</li>
</ul>
<h2>Output</h2>
<p>
張ることができる最大の辺の数を1行に出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
4 3
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
5 1
</pre>
<h2>Sample Output 2</h2>
<pre>
10
</pre>
<h2>Sample Input 3</h2>
<pre>
4 2
</pre>
<h2>Sample Output 3</h2>
<pre>
5
</pre> |
p02089 |
<h2>B: AddMulSubDiv</h2>
<h3>Problem Statement</h3>
<p>You have an array <var>A</var> of <var>N</var> integers. <var>A_i</var> denotes the <var>i</var>-th element of <var>A</var>.</p>
<p>You have to process one of the following queries <var>Q</var> times:</p>
<ul>
<li> Query 1: The query consists of non-negative integer <var>x</var>, and two positive integers <var>s, t</var>. For all the elements <b>greater</b> than or equal to <var>x</var> in <var>A</var>, you have to add <var>s</var> to the elements, and then multiply them by <var>t</var>. That is, an element with <var>v (v \geq x)</var> becomes <var>t(v + s)</var> after this query.</li>
</ul>
<ul>
<li> Query 2: The query consists of non-negative integer <var>x</var>, and two positive integers <var>s, t</var>. For all the elements <b>less</b> than or equal to <var>x</var> in <var>A</var>, you have to subtract <var>s</var> from the elements, and then divide them by <var>t</var>. If the result is not an integer, you truncate it towards zero. That is, an element with <var>v (v \leq x)</var> becomes $\mathrm{trunc}$ <var>( \frac{v - s}{t} )</var> after this query, where $\mathrm{trunc}$ <var>( y )</var> is the integer obtained by truncating <var>y</var> towards zero. </li>
</ul>
<ul>
<ul>
<li> "Truncating towards zero" means converting a decimal number to an integer so that if <var>x = 0.0</var> then <var>0 </var>, otherwise an integer whose absolute value is the maximum integer no more than <var>|x|</var> and whose sign is same as <var>x</var>. For example, truncating <var>3.5</var> towards zero is <var>3</var>, and truncating <var>-2.8</var> towards zero is <var>-2</var>.</li>
</ul>
</ul>
<p>After applying <var>Q</var> queries one by one, how many elements in <var>A</var> are no less than <var>L</var> and no more than <var>R</var>?</p>
<h3>Input</h3>
<pre>
<var>N</var> <var>Q</var> <var>L</var> <var>R</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
<var>q_1</var> <var>x_1</var> <var>s_1</var> <var>t_1</var>
<var>:</var>
<var>q_Q</var> <var>x_Q</var> <var>s_Q</var> <var>t_Q</var>
</pre>
<ul>
<li> The first line contains four integers <var>N</var>, <var>Q</var>, <var>L</var>, and <var>R</var>. <var>N</var> is the number of elements in an integer array <var>A</var>, <var>Q</var> is the number of queries, and <var>L</var> and <var>R</var> specify the range of integers you want to count within after the queries.</li>
<li> The second line consists of <var>N</var> integers, the <var>i</var>-th of which is the <var>i</var>-th element of <var>A</var>.</li>
<li> The following <var>Q</var> lines represent information of queries. The <var>j</var>-th line of them corresponds to the <var>j</var>-th query and consists of four integers <var>q_j</var>, <var>x_j</var>, <var>s_j</var>, and <var>t_j</var>. Here, <var>q_j = 1</var> stands for the <var>j</var>-th query is Query 1, and <var>q_j = 2</var> stands for the <var>j</var>-th query is Query 2. <var>x_j</var>, <var>s_j</var>, and <var>t_j</var> are parameters used for the <var>j</var>-th query.</li>
</ul>
<h3>Constraints</h3>
<ul>
<li> <var>1 \leq N \leq 2 \times 10^5</var></li>
<li> <var>1 \leq Q \leq 2 \times 10^5</var></li>
<li> <var>-2^{63} < L \leq R < 2^{63}</var></li>
<li> <var>0 \leq |A_i| \leq 10^9</var></li>
<li> <var>q_j \in \{ 1, 2 \}</var></li>
<li> <var>0 \leq x_j < 2^{63}</var></li>
<li> <var>1 \leq s_j, t_j \leq 10^9</var></li>
<li> Inputs consist only of integers.</li>
<li> The absolute value of any element in the array dosen't exceed <var>2^{63}</var> at any point during query processing.</li>
</ul>
<h3>Output</h3>
<p>Output the number of elements in <var>A</var> that are no less than <var>L</var> and no more than <var>R</var> after processing all given queries in one line.</p>
<h3>Sample Input 1</h3>
<pre>
3 3 3 10
1 -2 3
1 2 2 3
2 20 1 3
2 1 20 5
</pre>
<h3>Output for Sample Input 1</h3>
<pre>1</pre>
|
p02573 | <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> persons called Person <var>1</var> through Person <var>N</var>.</p>
<p>You are given <var>M</var> facts that "Person <var>A_i</var> and Person <var>B_i</var> are friends." The same fact may be given multiple times.</p>
<p>If <var>X</var> and <var>Y</var> are friends, and <var>Y</var> and <var>Z</var> are friends, then <var>X</var> and <var>Z</var> are also friends. There is no friendship that cannot be derived from the <var>M</var> given facts.</p>
<p>Takahashi the evil wants to divide the <var>N</var> persons into some number of groups so that every person has no friend in his/her group.</p>
<p>At least how many groups does he need to make?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2\times 10^5</var></li>
<li><var>0 \leq M \leq 2\times 10^5</var></li>
<li><var>1\leq A_i,B_i\leq N</var></li>
<li><var>A_i \neq B_i</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var>
<var>\vdots</var>
<var>A_M</var> <var>B_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
1 2
3 4
5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Dividing them into three groups such as <var>\{1,3\}</var>, <var>\{2,4\}</var>, and <var>\{5\}</var> achieves the goal.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 4
3 1
4 1
5 9
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p02123 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem M: Fissure Puzzle Hard</h1>
<h2>Problem</h2>
<p>$N \times N$個のマスから成るグリッドがある。最初すべてのマスは白色である。以下の手順に従って黒色のマスを増やしていく。</p>
<p>上から偶数番目かつ、左から偶数番目であるマスの中で、白色のマスを1つ選ぶ。選んだマスは黒色に変化する。さらに、そのマスの上下左右それぞれの方向について、隣接している白色のマスも連鎖的に黒色に変化する。この連鎖はその方向に白色のマスが存在しなくなるまで続く。(以下に例を示す)</p>
<p>
□□□□□□□□□<br>
□□□□□□□□□<br>
□□□□□□□□□<br>
□□□□□□□□□<br>
□□□□□□□□□<br>
□□□□□□□□□<br>
□□□□□□□□□<br>
□□□□□□□□□<br>
□□□□□□□□□<br>
↓上から4番目、左から6番目を選ぶ<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
■■■■■■■■■<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
↓上から2番目、左から2番目を選ぶ<br>
□■□□□■□□□<br>
■■■■■■□□□<br>
□■□□□■□□□<br>
■■■■■■■■■<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
□□□□□■□□□<br>
↓上から6番目、左から8番目を選ぶ<br>
□■□□□■□□□<br>
■■■■■■□□□<br>
□■□□□■□□□<br>
■■■■■■■■■<br>
□□□□□■□■□<br>
□□□□□■■■■<br>
□□□□□■□■□<br>
□□□□□■□■□<br>
□□□□□■□■□<br>
</p>
<p>
あなたは上から$i$番目で左から$j$番目のマスの色が$A_{i,j}$であるグリッドを作りたい。
作ることが可能かどうかを判定せよ。可能な場合は、選ぶべきマスの場所と順番を求めよ。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<p>
$N$<br>
$A_{1,1}$ $A_{1,2}$ ... $A_{1,N}$<br>
$A_{2,1}$ $A_{2,2}$ ... $A_{2,N}$<br>
...<br>
$A_{N,1}$ $A_{N,2}$ ... $A_{N,N}$<br>
</p>
<p>
$A_{i,j}$が'o'であるときは上から$i$番目、左から$j$番目のマスが白色であることを表し、'x'のときは黒色のマスであることを表す。
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$3 \le N \le 2047$</li>
<li>$N$は奇数である</li>
<li>$A_{i,j}$は'o'か'x'である</li>
</ul>
<h2>Output</h2>
<p>
不可能な場合は-1と1行に出力せよ。
可能な場合は1行目に選ぶマスの個数を出力し、
$i \times 2$行目には$i$番目に選択するマスが上から何番目なのかを、
$i \times 2 + 1$行目には$i$番目に選択するマスが左から何番目なのかを出力せよ。
一意に定まらない場合は辞書順で最小になるようにせよ。
</p>
<h2>Sample Input 1</h2>
<pre>
5
oxooo
oxooo
oxooo
xxxxx
oxooo
</pre>
<h2>Sample Output 1</h2>
<pre>
1
4
2
</pre>
<h2>Sample Input 2</h2>
<pre>
9
oxoooooxo
oxxxxxxxx
oxoooooxo
xxxxxxxxx
oxoxooooo
oxxxxxxxx
oxoxoxooo
oxoxxxxxx
oxoxoxooo
</pre>
<h2>Sample Output 2</h2>
<pre>
4
4
2
2
8
6
4
8
6
</pre>
<h2>Sample Input 3</h2>
<pre>
3
oxx
oxx
ooo
</pre>
<h2>Sample Output 3</h2>
<pre>
-1
</pre> |
p03698 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters. Determine whether all the characters in <var>S</var> are different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ |S| ≤ 26</var>, where <var>|S|</var> denotes the length of <var>S</var>.</li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If all the characters in <var>S</var> are different, print <code>yes</code> (case-sensitive); otherwise, print <code>no</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>uncopyrightable
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>different
</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>no
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>yes
</pre></section>
</div>
</span> |
p03362 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Print a sequence <var>a_1, a_2, ..., a_N</var> whose length is <var>N</var> that satisfies the following conditions:</p>
<ul>
<li><var>a_i</var> <var>(1 \leq i \leq N)</var> is a prime number at most <var>55</var> <var>555</var>.</li>
<li>The values of <var>a_1, a_2, ..., a_N</var> are all different.</li>
<li>In every choice of five different integers from <var>a_1, a_2, ..., a_N</var>, the sum of those integers is a composite number.</li>
</ul>
<p>If there are multiple such sequences, printing any of them is accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3>
<p>An integer <var>N</var> not less than <var>2</var> is called a prime number if it cannot be divided evenly by any integers except <var>1</var> and <var>N</var>, and called a composite number otherwise.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is an integer between <var>5</var> and <var>55</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <var>N</var> numbers <var>a_1, a_2, a_3, ..., a_N</var> in a line, with spaces in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 5 7 11 31
</pre>
<p>Let us see if this output actually satisfies the conditions.<br/>
First, <var>3</var>, <var>5</var>, <var>7</var>, <var>11</var> and <var>31</var> are all different, and all of them are prime numbers.<br/>
The only way to choose five among them is to choose all of them, whose sum is <var>a_1+a_2+a_3+a_4+a_5=57</var>, which is a composite number.<br/>
There are also other possible outputs, such as <code>2 3 5 7 13</code>, <code>11 13 17 19 31</code> and <code>7 11 5 31 3</code>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2 3 5 7 11 13
</pre>
<ul>
<li><var>2</var>, <var>3</var>, <var>5</var>, <var>7</var>, <var>11</var>, <var>13</var> are all different prime numbers.</li>
<li><var>2+3+5+7+11=28</var> is a composite number.</li>
<li><var>2+3+5+7+13=30</var> is a composite number.</li>
<li><var>2+3+5+11+13=34</var> is a composite number.</li>
<li><var>2+3+7+11+13=36</var> is a composite number.</li>
<li><var>2+5+7+11+13=38</var> is a composite number.</li>
<li><var>3+5+7+11+13=39</var> is a composite number.</li>
</ul>
<p>Thus, the sequence <code>2 3 5 7 11 13</code> satisfies the conditions. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2 5 7 13 19 37 67 79
</pre></section>
</div>
</span> |
p03732 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have <var>N</var> items and a bag of strength <var>W</var>.
The <var>i</var>-th item has a weight of <var>w_i</var> and a value of <var>v_i</var>.</p>
<p>You will select some of the items and put them in the bag.
Here, the total weight of the selected items needs to be at most <var>W</var>.</p>
<p>Your objective is to maximize the total value of the selected items.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 100</var></li>
<li><var>1 ≤ W ≤ 10^9</var></li>
<li><var>1 ≤ w_i ≤ 10^9</var></li>
<li>For each <var>i = 2,3,...,N</var>, <var>w_1 ≤ w_i ≤ w_1 + 3</var>.</li>
<li><var>1 ≤ v_i ≤ 10^7</var></li>
<li><var>W</var>, each <var>w_i</var> and <var>v_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>W</var>
<var>w_1</var> <var>v_1</var>
<var>w_2</var> <var>v_2</var>
:
<var>w_N</var> <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible total value of the selected items.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 6
2 1
3 4
4 10
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
</pre>
<p>The first and third items should be selected.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 6
2 1
3 7
4 10
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>13
</pre>
<p>The second and fourth items should be selected.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 10
1 100
1 100
1 100
1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>400
</pre>
<p>You can take everything.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 1
10 100
10 100
10 100
10 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre>
<p>You can take nothing.</p></section>
</div>
</span> |
p02820 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>At an arcade, Takahashi is playing a game called <em>RPS Battle</em>, which is played as follows:</p>
<ul>
<li>The player plays <var>N</var> rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)</li>
<li>Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):<ul>
<li><var>R</var> points for winning with Rock;</li>
<li><var>S</var> points for winning with Scissors;</li>
<li><var>P</var> points for winning with Paper.</li>
</ul>
</li>
<li>However, in the <var>i</var>-th round, the player cannot use the hand he/she used in the <var>(i-K)</var>-th round. (In the first <var>K</var> rounds, the player can use any hand.)</li>
</ul>
<p>Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.</p>
<p>The information Takahashi obtained is given as a string <var>T</var>. If the <var>i</var>-th character of <var>T</var> <var>(1 \leq i \leq N)</var> is <code>r</code>, the machine will play Rock in the <var>i</var>-th round. Similarly, <code>p</code> and <code>s</code> stand for Paper and Scissors, respectively.</p>
<p>What is the maximum total score earned in the game by adequately choosing the hand to play in each round?</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.</p>
<ul>
<li>If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;</li>
<li>if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;</li>
<li>if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;</li>
<li>if both players play the same hand, it is a draw.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq K \leq N-1</var></li>
<li><var>1 \leq R,S,P \leq 10^4</var></li>
<li><var>N,K,R,S,</var> and <var>P</var> are all integers.</li>
<li><var>|T| = N</var></li>
<li><var>T</var> consists of <code>r</code>, <code>p</code>, and <code>s</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>K</var>
<var>R</var> <var>S</var> <var>P</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum total score earned in the game.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
8 7 6
rsrpr
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>27
</pre>
<p>The machine will play {Rock, Scissors, Rock, Paper, Rock}.</p>
<p>We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn <var>27</var> points.
We cannot earn more points, so the answer is <var>27</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 1
100 10 1
ssssppr
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>211
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4996
</pre></section>
</div>
</span> |
p03227 | <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>2</var> or <var>3</var> consisting of lowercase English letters. If the length of the string is <var>2</var>, print it as is; if the length is <var>3</var>, print the string after reversing it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>S</var> is <var>2</var> or <var>3</var>.</li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the length of <var>S</var> is <var>2</var>, print <var>S</var> as is; if the length is <var>3</var>, print <var>S</var> after reversing it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>cba
</pre>
<p>As the length of <var>S</var> is <var>3</var>, we print it after reversing it.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ac
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>ac
</pre>
<p>As the length of <var>S</var> is <var>2</var>, we print it as is.</p></section>
</div>
</span> |
p04018 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>x</var> be a string of length at least <var>1</var>.
We will call <var>x</var> a <em>good</em> string, if for any string <var>y</var> and any integer <var>k (k \geq 2)</var>, the string obtained by concatenating <var>k</var> copies of <var>y</var> is different from <var>x</var>.
For example, <code>a</code>, <code>bbc</code> and <code>cdcdc</code> are good strings, while <code>aa</code>, <code>bbbb</code> and <code>cdcdcd</code> are not.</p>
<p>Let <var>w</var> be a string of length at least <var>1</var>.
For a sequence <var>F=(\,f_1,\,f_2,\,...,\,f_m)</var> consisting of <var>m</var> elements,
we will call <var>F</var> a <em>good representation</em> of <var>w</var>, if the following conditions are both satisfied:</p>
<ul>
<li>For any <var>i \, (1 \leq i \leq m)</var>, <var>f_i</var> is a good string.</li>
<li>The string obtained by concatenating <var>f_1,\,f_2,\,...,\,f_m</var> in this order, is <var>w</var>.</li>
</ul>
<p>For example, when <var>w=</var><code>aabb</code>, there are five good representations of <var>w</var>:</p>
<ul>
<li><var>(</var><code>aabb</code><var>)</var></li>
<li><var>(</var><code>a</code><var>,</var><code>abb</code><var>)</var></li>
<li><var>(</var><code>aab</code><var>,</var><code>b</code><var>)</var></li>
<li><var>(</var><code>a</code><var>,</var><code>ab</code><var>,</var><code>b</code><var>)</var></li>
<li><var>(</var><code>a</code><var>,</var><code>a</code><var>,</var><code>b</code><var>,</var><code>b</code><var>)</var></li>
</ul>
<p>Among the good representations of <var>w</var>, the ones with the smallest number of elements are called the <em>best representations</em> of <var>w</var>.
For example, there are only one best representation of <var>w=</var><code>aabb</code>: <var>(</var><code>aabb</code><var>)</var>.</p>
<p>You are given a string <var>w</var>. Find the following:</p>
<ul>
<li>the number of elements of a best representation of <var>w</var></li>
<li>the number of the best representations of <var>w</var>, modulo <var>1000000007 \, (=10^9+7)</var></li>
</ul>
<p>(It is guaranteed that a good representation of <var>w</var> always exists.)</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |w| \leq 500000 \, (=5 \times 10^5)</var></li>
<li><var>w</var> consists of lowercase letters (<code>a</code>-<code>z</code>).</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>400</var> points will be awarded for passing the test set satisfying <var>1 \leq |w| \leq 4000</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>w</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>2</var> lines.</p>
<ul>
<li>In the first line, print the number of elements of a best representation of <var>w</var>.</li>
<li>In the second line, print the number of the best representations of <var>w</var>, modulo <var>1000000007</var>.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>bcbc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
3
</pre>
<ul>
<li>In this case, there are <var>3</var> best representations of <var>2</var> elements:<ul>
<li><var>(</var><code>b</code><var>,</var><code>cbc</code><var>)</var></li>
<li><var>(</var><code>bc</code><var>,</var><code>bc</code><var>)</var></li>
<li><var>(</var><code>bcb</code><var>,</var><code>c</code><var>)</var></li>
</ul>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>ddd
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
1
</pre></section>
</div>
</span> |
p03677 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is buying a lamp.
The light of the lamp can be adjusted to <var>m</var> levels of brightness, represented by integers from <var>1</var> through <var>m</var>, by the two buttons on the remote control.</p>
<p>The first button is a "forward" button. When this button is pressed, the brightness level is increased by <var>1</var>, except when the brightness level is <var>m</var>, in which case the brightness level becomes <var>1</var>.</p>
<p>The second button is a "favorite" button. When this button is pressed, the brightness level becomes the favorite brightness level <var>x</var>, which is set when the lamp is purchased.</p>
<p>Snuke is thinking of setting the favorite brightness level <var>x</var> so that he can efficiently adjust the brightness.
He is planning to change the brightness <var>n-1</var> times. In the <var>i</var>-th change, the brightness level is changed from <var>a_i</var> to <var>a_{i+1}</var>. The initial brightness level is <var>a_1</var>.
Find the number of times Snuke needs to press the buttons when <var>x</var> is set to minimize this number.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq n,m \leq 10^5</var></li>
<li><var>1 \leq a_i\leq m</var></li>
<li><var>a_i \neq a_{i+1}</var></li>
<li><var>n</var>, <var>m</var> and <var>a_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>a_1</var> <var>a_2</var> … <var>a_n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of times Snuke needs to press the buttons.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 6
1 5 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>When the favorite brightness level is set to <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var> and <var>6</var>, Snuke needs to press the buttons <var>8</var>, <var>9</var>, <var>7</var>, <var>5</var>, <var>6</var> and <var>9</var> times, respectively.
Thus, Snuke should set the favorite brightness level to <var>4</var>.
In this case, the brightness is adjusted as follows:</p>
<ul>
<li>In the first change, press the favorite button once, then press the forward button once.</li>
<li>In the second change, press the forward button twice.</li>
<li>In the third change, press the favorite button once.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 10
10 9 8 7 6 5 4 3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>45
</pre></section>
</div>
</span> |
p00958 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>Problem B
Parallel Lines
</h2>
<p>
Given an even number of distinct planar points, consider coupling all of the points into pairs. All the possible couplings are to be considered as long as all the given points are coupled to one and only one other point.
</p>
<p>
When lines are drawn connecting the two points of all the coupled point pairs, some of the drawn lines can be parallel to some others. Your task is to find the maximum number of parallel line pairs considering all the possible couplings of the points.
</p>
<p>
For the case given in the first sample input with four points, there are three patterns of point couplings as shown in Figure B.1. The numbers of parallel line pairs are 0, 0, and 1, from the left. So the maximum is 1.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_parallelLines1">
<p>Figure B.1. All three possible couplings for Sample Input 1</p>
</center>
<p>
For the case given in the second sample input with eight points, the points can be coupled as shown in Figure B.2. With such a point pairing, all four lines are parallel to one another. In other words, the six line pairs $(L_1, L_2)$, $(L_1, L_3)$, $(L_1, L_4)$, $(L_2, L_3)$, $(L_2, L_4)$ and $(L_3, L_4)$ are parallel. So the maximum number of parallel line pairs, in this case, is 6.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$m$
$x_1$ $y_1$
...
$x_m$ $y_m$
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_parallelLines2">
<p> Figure B.2. Maximizing the number of parallel line pairs for Sample Input 2</p>
</center>
<p>
The first line contains an even integer $m$, which is the number of points ($2 \leq m \leq 16$). Each of the following $m$ lines gives the coordinates of a point. Integers $x_i$ and $y_i$ ($-1000 \leq x_i \leq 1000, -1000 \leq y_i \leq 1000$) in the $i$-th line of them give the $x$- and $y$-coordinates, respectively, of the $i$-th point.
</p>
<p>
The positions of points are all different, that is, $x_i \ne x_j$ or $y_i \ne y_j$ holds for all $i \ne j$. Furthermore, No three points lie on a single line.
</p>
<h3>Output</h3>
<p>
Output the maximum possible number of parallel line pairs stated above, in one line.
</p>
<h3>Sample Input 1</h3>
<pre>
4
0 0
1 1
0 2
2 4
</pre>
<h3>Sample Output 1</h3>
<pre>
1
</pre>
<h3>Sample Input 2</h3>
<pre>
8
0 0
0 5
2 2
2 7
3 -2
5 0
4 -2
8 2
</pre>
<h3>Sample Output 2</h3>
<pre>
6
</pre>
<h3>Sample Input 3</h3>
<pre>
6
0 0
0 5
3 -2
3 5
5 0
5 7
</pre>
<h3>Sample Output 3</h3>
<pre>
3
</pre>
<h3>Sample Input 4</h3>
<pre>
2
-1000 1000
1000 -1000
</pre>
<h3>Sample Output 4</h3>
<pre>
0
</pre>
<h3>Sample Input 5</h3>
<pre>
16
327 449
-509 761
-553 515
360 948
147 877
-694 468
241 320
463 -753
-206 -991
473 -738
-156 -916
-215 54
-112 -476
-452 780
-18 -335
-146 77
</pre>
<h3>Sample Output 5</h3>
<pre>
12
</pre> |
p02965 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of <var>N</var> integers: <var>x=(x_0,x_1,\cdots,x_{N-1})</var>.
Initially, <var>x_i=0</var> for each <var>i</var> (<var>0 \leq i \leq N-1</var>).</p>
<p>Snuke will perform the following operation <strong>exactly</strong> <var>M</var> times:</p>
<ul>
<li>Choose two distinct indices <var>i, j</var> (<var>0 \leq i,j \leq N-1,\ i \neq j</var>).
Then, replace <var>x_i</var> with <var>x_i+2</var> and <var>x_j</var> with <var>x_j+1</var>.</li>
</ul>
<p>Find the number of different sequences that can result after <var>M</var> operations.
Since it can be enormous, compute the count modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^6</var></li>
<li><var>1 \leq M \leq 5 \times 10^5</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different sequences that can result after <var>M</var> operations, modulo <var>998244353</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>3
</pre>
<p>After two operations, there are three possible outcomes:</p>
<ul>
<li><var>x=(2,4)</var></li>
<li><var>x=(3,3)</var></li>
<li><var>x=(4,2)</var></li>
</ul>
<p>For example, <var>x=(3,3)</var> can result after the following sequence of operations:</p>
<ul>
<li>First, choose <var>i=0,j=1</var>, changing <var>x</var> from <var>(0,0)</var> to <var>(2,1)</var>.</li>
<li>Second, choose <var>i=1,j=0</var>, changing <var>x</var> from <var>(2,1)</var> to <var>(3,3)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>19
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>211428932
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 50000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3463133
</pre></section>
</div>
</span> |
p02436 | <h1>Queue</h1>
<p>
Queue is a container of elements that are inserted and deleted according to FIFO (First In First Out).
</p>
<p>
For $n$ queues $Q_i$ ($i = 0, 1, ..., n-1$), perform a sequence of the following operations.
</p>
<ul>
<li>enqueue($t$, $x$): Insert an integer $x$ to $Q_t$.</li>
<li>front($t$): Report the value which should be deleted next from $Q_t$. If $Q_t$ is empty, do nothing.</li>
<li>dequeue($t$): Delete an element from $Q_t$. If $Q_t$ is empty, do nothing.</li>
</ul>
<p>
In the initial state, all queues are empty.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n \; q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $t$ $x$
</pre>
<p>or</p>
<pre>
1 $t$
</pre>
<p>or</p>
<pre>
2 $t$
</pre>
<p>
where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent enqueue, front and dequeue operations respectively.
</p>
<h2>Output</h2>
<p>
For each front operation, print an integer in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$1 \leq q \leq 200,000$</li>
<li>$-1,000,000,000 \leq x \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
3 9
0 0 1
0 0 2
0 0 3
0 2 4
0 2 5
1 0
1 2
2 0
1 0
</pre>
<h2>Sample Output 1</h2>
<pre>
1
4
2
</pre>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.