question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00164 |
<H1>おはじき取り</H1>
<p>
一郎君と次郎君の兄弟は家でよくおはじき取りをして遊びます。おはじき取りは、一カ所に積まれた複数のおはじきを二人が交互にとっていくゲームです。一度に1〜4個のおはじきを好きな数だけ順に取り、相手に最後の1個を取らせた方が勝ちになります。二人はいつも 32 個のおはじきを使い、兄である一郎君の番からゲームを始めます。
</p>
<p>
これまでに何度も戦っている二人ですが、次郎君は兄の一郎君にどうしても勝つことができません。それもそのはず、一郎君はこのゲームの必勝法を知っているからです。一郎君は、残りのおはじきの数を <var>n</var> とすると、必ず (<var>n</var> - 1) % 5 個のおはじきを取ります。ここで <var>x</var> % <var>y</var> は、<var>x</var> を <var>y</var> で割った余りを示します。
</p>
<p>
一方、次郎君は、残りのおはじきの数にかかわらず、ゲームのはじめに各回で取るおはじきの数を数列として決めてしまうのです。例えば、次郎君が決めた数列が{ 3, 1, 4, 2 } であるならば、彼の取るおはじきの数は順に 3 -> 1 -> 4 -> 2 -> 3 -> 1 -> 4 -> … となります(取ると決めた数が、おはじきの残りの数以上になった場合は、残りのおはじき全てを取ります)。
</p>
<p>
なんど負けてもやり方を変えようとしない頑固な次郎君の将来が心配になったお母さんは、次郎君がいかなる数列を選んだとしても一郎君には勝てないということを示すために、ゲームをシュミレートするプログラムを書くことにしました。
</p>
<p>
次郎君の考えた数列 <var>a</var> を入力とし、一郎君と次郎君が順次おはじきを取った後の残りのおはじきの個数を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>n</sub></var>
</pre>
<p>
1行目に次郎君の決めた数列の長さ <var>n</var> (1 ≤ <var>n</var> ≤ 25)、2行目に数列の <var>i</var> 番目の要素 <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 4) が空白区切りで与えられます。入力はすべて整数で与えられます。
</p>
<p>
データセットの数は 100 を超えません。
</p>
<H2>Output</H2>
<p>
データセットごとに、ゲームの各回でのおはじきが取られた直後のおはじきの数(整数)を出力します。
</p>
<H2>Sample Input</H2>
<pre>
4
3 1 4 2
3
4 3 2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
31
28
26
25
21
17
16
14
11
8
6
5
1
0
31
27
26
23
21
19
16
12
11
8
6
4
1
0
</pre>
|
p01325 |
<h1><font color="#000">Problem E:</font> トーマス・ライトの憂鬱</h1>
<p>昨日の夕方の話。 普段通り大学での講義が終わり、日課であるキャンパスでの猫への餌付けを済ませた後、家に帰り着くと、作業着を着た人たちが僕の家の扉を取り替える工事をしていた。 それだけなら特に僕の頭痛の種を増やすような出来事ではないのだが、取り外されて去っていく慣れ親しんだ鍵とレバーがついている茶色の扉が非常に平凡であるのに対して、今からまさに取り付けられようとしている黒色の扉が非常に奇妙なもので、ああこれはまたうちの親父が何かを思いついてしまったのだなと容易に想像がついてしまうのであった。 その偏屈親父が言うには、鍵は無くす可能性があるので信用することが出来ない。手元に鍵があったとしても、目を離している隙に鍵の複製が作られてしまったかもしれない。物にセキュリティーを頼る時代はもう終わりだ。これからはパスワードを家族の各人が覚え、そうすることによって世界征服を目論む悪の科学者から我輩の発明品を守るのだ、ということらしい。 新しく設置された扉には縦にN個ずつ、横にN個ずつの正方形をかたちどるように、縦にN+1本、横にN+1本の線が薄青色で引かれていた。 一行目の正方形の左にはA、二行目の正方形の左にはB、というように、ご丁寧に行番号が書かれている。 一列目の正方形の上には1、二列目の正方形の上には2、と、列番号はどうやら数字のようだ。 N<sup>2</sup>個の正方形には各々スイッチが一つずつ配置されており、OFFの状態だと真っ黒だが、ONの状態だと赤い丸が浮かび上がる、というセキュリティーを考えるならもう少しやりようがあるだろうというギミックが付いている。 そして全てのスイッチのON/OFFを正しく合わせたときのみ、扉が開く、という派手好きの親父が大満足な仕様となっているようだ。</p>
<p>さて、ここでの僕の問題は、このパスワードをきちんと覚えられる自信が無い、ということだ。 自分で言うのも何なのだが、僕は頭がそんなに悪くないつもりなので、パスワードの大体は覚えていられるだろうと思うのだが、機械という物は融通が効かないものだからほんのちょっと間違っただけで、寒空の下で夜を過ごすことになりかねない。 しかし、パスワードを書き写して持ち運べば、親父に見つかったときに小遣い抜きなどの理不尽な制裁が加えられることが予想される。 そこで僕はある作戦を思いついたんだ。 各行、各列の正方形に含まれる赤丸の個数をメモしてそれを持ち運ぼう。 一行目のN個の正方形に含まれる赤丸の個数、二行目のN個の....、 一列目のN個の正方形に含まれる赤丸の個数、二行目のN個の....、 という風に2N個の数字をメモしておけば、もし他の人に見られてもただの数字の羅列だ。何が何だかきっと分からないだろう。</p>
<p>やあわざわざここまで読んでくれた君。 ああそうだ、この作戦にはもしかしたら致命的な欠陥があるかもしれない。 複数のパスワードが、同じメモになってしまうかもしれないのだ。 そうなると、寒空(略)ということになりかねない。我が身の健康を揺るがす一大問題だ。 そこで君には、このメモの数字を入力すると、復元可能なパスワードが一つに定まるかどうかを判定するプログラムを書いてほしい。 一つに定まるなら、Yes、そうでないなら、Noと出力するだけのプログラムさ。簡単だろう? もしかしたらメモをとった時に赤丸を数え間違ったかもしれない。その場合は復元できるパスワードが1つも存在しないかもしれないが、その時は迷わずNoと返してくれ。 ああそうそう、間違っても僕の家に勝手に入ろうとはしないでくれよ。親父の趣味の危ない機械や罠が並んでいるから、命の保証が出来ないからね。
</p>
<h2>Input</h2>
<p>
入力は次のような形式で与えられる。
</p>
<pre>
N
1行目の和 2行目の和 ...
1列目の和 2列目の和 ...
</pre>
<p>
ただし、N は 1 ≤ N ≤ 10000 を満たす整数である。
</p>
<h2>Output</h2>
<p>
問題文に従って、YesもしくはNoを出力せよ。
</p>
<h2>Notes on Test Cases</h2>
<p>
上記入力形式で複数のデータセットが与えられます。各データセットに対して上記出力形式で出力を行うプログラムを作成して下さい。
</p>
<p>
N が 0 のとき入力の終わりを示します。
</p>
<!--
<h2>Sample Input 1</h2>
<pre>2
1 2
2 1
</pre>
<h2>Output for Sample Input 1</h2>
<pre>Yes
</pre>
<h2>Sample Input 2</h2>
<pre>3
2 1 2
2 1 2
</pre>
<h2>Output for Sample Input 2</h2>
<pre>No
</pre>
<h2>Sample Input 3</h2>
<pre>10
0 1 1 2 5 5 5 8 8 9
0 1 3 3 3 6 6 6 7 9
</pre>
<h2>Output for Sample Input 3</h2>
<pre>Yes
</pre>
-->
<h2>Sample Input</h2>
<pre>
2
1 2
2 1
3
2 1 2
2 1 2
10
0 1 1 2 5 5 5 8 8 9
0 1 3 3 3 6 6 6 7 9
0
</pre>
<h2>Output for Sample Input</h2>
<pre>
Yes
No
Yes
</pre>
|
p03318 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>S(n)</var> denote the sum of the digits in the decimal notation of <var>n</var>.
For example, <var>S(123) = 1 + 2 + 3 = 6</var>.</p>
<p>We will call an integer <var>n</var> a <strong>Snuke number</strong> when, for all positive integers <var>m</var> such that <var>m > n</var>, <var>\frac{n}{S(n)} \leq \frac{m}{S(m)}</var> holds.</p>
<p>Given an integer <var>K</var>, list the <var>K</var> smallest Snuke numbers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K</var></li>
<li>The <var>K</var>-th smallest Snuke number is not greater than <var>10^{15}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>K</var> lines. The <var>i</var>-th line should contain the <var>i</var>-th smallest Snuke number.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
2
3
4
5
6
7
8
9
19
</pre></section>
</div>
</span> |
p01775 |
<h2>D: Rescue a Postal Worker / 郵便局員を救え</h2>
<h3>物語</h3>
<p>あなたは,この春に長年の夢だった郵便局に就職できました.担当する配達地域も決定し,ウキウキ気分で迎えた初仕事ですが,あまりに浮かれていたため郵便物を入れた袋に穴が空いているのに気づかず,入っていた郵便物を全部落としてしまいました.しかし,用意周到なあなたはすべての郵便物にGPSをつけていたため,どこに郵便物が落ちているかを知ることができます.</p>
<p>郵便物を拾いなおしていると予定していた配達時間を超えてしまうかもしれないので,あなたはできる限り短い時間で配達を終えたいと思っています.落としてしまったすべての郵便物を拾いなおして,それぞれの配達先に届ける最短の時間を求めなさい.</p>
<h3>問題</h3>
<p>あなたの担当する配達地域として無向グラフを考える.<var>n</var>頂点からなる無向グラフを考えたとき,それぞれの頂点には<var>1</var>から<var>n</var>の番号が付けられている.落とした郵便物の数と落ちている頂点,それぞれの郵便物の配達先の頂点が与えられたとき,すべての郵便物を回収して配達先に届ける最短時間を求めよ.このとき,ある郵便物をその郵便物の配達先に届ける場合に拾っていない他の郵便物が存在しても良い.また,配達終了時にはどの頂点にいても良いこととする.</p>
<p>ここで,1つの頂点には高々1つの郵便物か高々1つの配達先しかなく,出発する頂点には郵便物も配達先も存在しない.与えられる無向グラフは単純なグラフ,すなわち自己閉路や多重辺のないグラフである.</p>
<h3>入力形式</h3>
<p>入力データの形式は以下の通りである.</p>
<pre>
<var>n</var> <var>m</var> <var>k</var> <var>p</var>
<var>x_1</var> <var>y_1</var> <var>w_1</var>
...
<var>x_m</var> <var>y_m</var> <var>w_m</var>
<var>s_1</var> <var>t_1</var>
...
<var>s_k</var> <var>t_k</var>
</pre>
<p>最初の1行には無向グラフの頂点数 <var>n</var> (<var>3 ≤ n ≤ 1,000</var>),辺数 <var>m</var> (<var>1 ≤ m ≤ 2,000</var>),落とした郵便物の数 <var>k</var> (<var>1 ≤ k ≤ 6</var>),始点 <var>p</var> (<var>1 ≤ p ≤ n</var>) が与えられる.行中の入力項目は空白1個区切りで与えられる.</p>
<p>続く <var>m</var> 行ではグラフ中の辺の情報が与えられる.<var>i</var> 行目には <var>i</var>番目の辺の両端の頂点 <var>x_i</var> (<var>1 ≤ x_i ≤ n</var>),<var>y_i</var> (<var>1 ≤ y_i ≤ n</var>) とその辺の重み <var>w_i</var> (<var>1 ≤ w_i ≤ 1,000</var>) が与えられる.</p>
<p>続く <var>k</var> 行の <var>j</var> 行目には落とした郵便物のある頂点 <var>s_j</var> (<var>1 ≤ s_j ≤ n</var>) とその郵便物の配達先の頂点 <var>t_j</var> (<var>1 ≤ t_j ≤ n</var>) が与えられる.</p>
<p>ここで,与えられるグラフは自己閉路や多重辺がなく,始点,各々の郵便物が落ちている頂点,各々の配達先はすべてが互いに異なる.</p>
<h3>出力形式</h3>
<p>頂点 <var>p</var> から出発して,すべての郵便物をそれぞれの配達先に届ける最短の時間を1行に表示せよ.ただし,届けられない場合は "Cannot deliver" を出力せよ.</p>
<h3>入力例1</h3>
<pre>
5 6 1 1
1 3 5
1 2 2
2 3 1
3 5 4
3 4 2
4 5 3
3 5
</pre>
<h3>出力例1</h3>
<pre>7</pre>
<h3>入力例2</h3>
<pre>
5 6 1 1
1 3 5
1 2 2
2 3 1
3 5 4
3 4 2
4 5 3
5 3
</pre>
<h3>出力例2</h3>
<pre>11</pre>
<h3>入力例3</h3>
<pre>
3 1 1 1
1 2 1
2 3
</pre>
<h3>出力例3</h3>
<pre>Cannot deliver</pre>
<h3>入力例4</h3>
<pre>
5 8 2 3
1 2 1
2 3 4
3 4 5
4 5 3
5 1 4
1 3 3
2 5 1
5 3 4
1 2
5 4
</pre>
<h3>出力例3</h3>
<pre>8</pre> |
p03748 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino has a lot of red and blue bricks and a large box.
She will build a tower of these bricks in the following manner.</p>
<p>First, she will pick a total of <var>N</var> bricks and put them into the box.
Here, there may be any number of bricks of each color in the box, as long as there are <var>N</var> bricks in total.
Particularly, there may be zero red bricks or zero blue bricks.
Then, she will repeat an operation <var>M</var> times, which consists of the following three steps:</p>
<ul>
<li>Take out an arbitrary brick from the box.</li>
<li>Put one red brick and one blue brick into the box.</li>
<li>Take out another arbitrary brick from the box.</li>
</ul>
<p>After the <var>M</var> operations, Joisino will build a tower by stacking the <var>2 \times M</var> bricks removed from the box, in the order they are taken out.
She is interested in the following question: how many different sequences of colors of these <var>2 \times M</var> bricks are possible?
Write a program to find the answer.
Since it can be extremely large, print the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 3000</var></li>
<li><var>1 \leq M \leq 3000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the count of the different possible sequences of colors of <var>2 \times M</var> bricks that will be stacked, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>56
</pre>
<p>A total of six bricks will be removed from the box. The only impossible sequences of colors of these bricks are the ones where the colors of the second, third, fourth and fifth bricks are all the same. Therefore, there are <var>2^6 - 2 \times 2 \times 2 = 56</var> possible sequences of colors.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1048576
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000 3000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>693347555
</pre></section>
</div>
</span> |
p00867 |
<H1><font color="#000">Problem D:</font> Digits on the Floor</H1>
<p>
Taro attempts to tell digits to Hanako by putting straight bars on the floor. Taro wants to
express each digit by making one of the forms shown in Figure 1.
</p>
<p>
Since Taro may not have bars of desired lengths, Taro cannot always make forms exactly as
shown in Figure 1. Fortunately, Hanako can recognize a form as a digit if the connection
relation between bars in the form is kept. Neither the lengths of bars nor the directions of forms
affect Hanako’s perception as long as the connection relation remains the same. For example,
Hanako can recognize all the awkward forms in Figure 2 as digits. On the other hand, Hanako
cannot recognize the forms in Figure 3 as digits. For clarity, touching bars are slightly separated
in Figures 1, 2 and 3. Actually, touching bars overlap exactly at one single point.
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_digits1"></td></tr>
<tr><th>Figure 1: Representation of digits</th></tr>
</table>
<br>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_digits2"></td></tr>
<tr><th>Figure 2: Examples of forms recognized as digits</th></tr>
</table>
<br>
</center>
<p>
In the forms, when a bar touches another, the touching point is an end of at least one of them.
That is, bars never cross. In addition, the angle of such two bars is always a right angle.
</p>
<p>
To enable Taro to represent forms with his limited set of bars, positions and lengths of bars can
be changed as far as the connection relations are kept. Also, forms can be rotated.
</p>
<p>
Keeping the connection relations means the following.
</p>
<center>
<table>
<tr><td align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_digits3"></td></tr>
<tr><th>Figure 3: Forms not recognized as digits (these kinds of forms are not contained in the dataset)</td></tr>
</table>
<br>
</center>
<ul>
<li>Separated bars are not made to touch.</li>
<li>Touching bars are not made separate.</li>
<li>When one end of a bar touches another bar, that end still touches the same bar. When it
touches a midpoint of the other bar, it remains to touch a midpoint of the same bar on
the same side.
</li>
<li>The angle of touching two bars is kept to be the same right angle (90 degrees and -90
degrees are considered different, and forms for 2 and 5 are kept distinguished).
</li>
</ul>
<p>
Your task is to find how many times each digit appears on the floor.
</p>
<p>
The forms of some digits always contain the forms of other digits. For example, a form for
9 always contains four forms for 1, one form for 4, and two overlapping forms for 7. In this
problem, ignore the forms contained in another form and count only the digit of the “largest”
form composed of all mutually connecting bars. If there is one form for 9, it should be interpreted
as one appearance of 9 and no appearance of 1, 4, or 7.
</p>
<H2>Input</H2>
<p>
The input consists of a number of datasets. Each dataset is formatted as follows.
</p>
<p>
<i>n</i><br>
<i>x<sub>1a</sub> y<sub>1a</sub> x<sub>1b</sub> y<sub>1b</sub></i><br>
<i>x<sub>2a</sub> y<sub>2a</sub> x<sub>2b</sub> y<sub>2b</sub></i><br>
.<br>
.<br>
.<br>
<i>x<sub>na</sub> y<sub>na</sub> x<sub>nb</sub> y<sub>nb</sub></i><br>
</p>
<p>
In the first line, <i>n</i> represents the number of bars in the dataset. For the rest of the lines, one
line represents one bar. Four integers <i>x<sub>a</sub></i>, <i>y<sub>a</sub></i> , <i>x<sub>b</sub></i> , <i>y<sub>b</sub></i> , delimited by single spaces, are given in
each line. <i>x<sub>a</sub></i> and <i>y<sub>a</sub></i> are the <i>x-</i> and <i>y-</i>coordinates of one end of the bar, respectively. <i>x<sub>b</sub></i> and
<i>y<sub>b</sub></i> are those of the other end. The coordinate system is as shown in Figure 4. You can assume
1 ≤ <i>n</i> ≤ 1000 and 0 ≤ <i>x<sub>a</sub></i> , <i>y<sub>a</sub></i> , <i>x<sub>b</sub></i> , <i>y<sub>b</sub></i> ≤ 1000.
</p>
<p>
The end of the input is indicated by a line containing one zero.
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_digits4"></td></tr>
<tr><th>Figure 4: The coordinate system</th></tr>
</table>
</center>
<p>
You can also assume the following conditions.
</p>
<ul>
<li>More than two bars do not overlap at one point.</li>
<li>Every bar is used as a part of a digit. Non-digit forms do not exist on the floor.</li>
<li>A bar that makes up one digit does not touch nor cross any bar that makes up another
digit.
</li>
<li>There is no bar whose length is zero.</li>
</ul>
<H2>Output</H2>
<p>
For each dataset, output a single line containing ten integers delimited by single spaces. These
integers represent how many times 0, 1, 2, . . . , and 9 appear on the floor in this order. Output
lines must not contain other characters.
</p>
<H2>Sample Input</H2>
<pre>
9
60 140 200 300
300 105 330 135
330 135 250 215
240 205 250 215
298 167 285 154
30 40 30 90
30 90 150 90
150 90 150 20
30 40 150 40
8
320 20 300 60
320 20 380 50
380 50 240 330
10 50 40 20
10 50 110 150
110 150 180 80
40 20 37 17
37 17 27 27
20
72 222 132 182
204 154 204 54
510 410 520 370
404 54 204 54
530 450 410 450
204 68 404 68
80 110 120 30
130 160 180 60
520 370 320 320
310 360 320 320
120 30 180 60
60 100 80 110
404 154 204 154
80 60 60 100
430 550 590 550
510 410 310 360
430 450 430 550
404 54 404 154
232 202 142 262
142 262 102 202
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 1 0 1 0 0 0 0 0 1
0 0 0 0 0 1 0 1 0 0
1 0 1 0 2 0 0 0 1 0
</pre>
|
p03898 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>.</p>
<p>The <var>i</var>-th of the <var>N-1</var> edges connects the vertices <var>p_i</var> and <var>q_i</var>.</p>
<p>Among the sequences of distinct vertices <var>v_1, v_2, ..., v_M</var> that satisfy the following condition, find the maximum value of <var>M</var>.</p>
<ul>
<li>For every <var>1 \leq i < M</var>, the path connecting the vertices <var>v_i</var> and <var>v_{i+1}</var> do not contain any vertex in <var>v</var>, except for <var>v_i</var> and <var>v_{i+1}</var>.</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 p_i, q_i \leq N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>q_1</var>
<var>p_2</var> <var>q_2</var>
:
<var>p_{N-1}</var> <var>q_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum value of <var>M</var>, the number of elements, among the sequences of vertices that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2
2 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
7 9
1 2
6 4
8 1
3 7
6 5
2 10
9 6
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre></section>
</div>
</span> |
p02270 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<p>
You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the packages in the sequence does not exceed the maximum load $P$.
</p>
<p>
Write a program which reads $n$, $k$ and $w_i$, and reports the minimum value of the maximum load $P$ to load all packages from the belt conveyor.
</p>
<H2>Input</H2>
<p>
In the first line, two integers $n$ and $k$ are given separated by a space character. In the following $n$ lines, $w_i$ are given respectively.
</p>
<H2>Output</H2>
<p>
Print the minimum value of $P$ in a line.
</p>
<H2>Constraints</H2>
<ul>
<li> $1 \leq n \leq 100,000$</li>
<li> $1 \leq k \leq 100,000$</li>
<li> $1 \leq w_i \leq 10,000$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5 3
8
1
7
3
9
</pre>
<H2>Sample Output 1</H2>
<pre>
10
</pre>
<p>
If the first truck loads two packages of $\{8, 1\}$, the second truck loads two packages of $\{7, 3\}$ and the third truck loads a package of $\{9\}$, then the minimum value of the maximum load $P$ shall be 10.
</p>
<br/>
<H2>Sample Input 2</H2>
<pre>
4 2
1
2
2
6
</pre>
<H2>Sample Output 2</H2>
<pre>
6
</pre>
<p>
If the first truck loads three packages of $\{1, 2, 2\}$ and the second truck loads a package of $\{6\}$, then the minimum value of the maximum load $P$ shall be 6.
</p> |
p03932 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
Max Score: $600$ Points <br/>
<section>
<h3>Problem Statement</h3>
Sigma and his brother Sugim are in the $H \times W$ grid. They wants to buy some souvenirs. <br/>
Their start position is upper-left cell, and the goal position is lower-right cell. <br/>
Some cells has a souvenir shop. At $i$-th row and $j$-th column, there is $a_{i, j}$ souvenirs. <br/>
In one move, they can go left, right, down, and up cell. <br/>
But they have little time, so they can move only $H+W-2$ times. <br/>
They wanted to buy souvenirs as many as possible, but they had no computer, so they couldn't get the maximal numbers of souvenirs. <br/>
Write a program and calculate the maximum souvenirs they can get, and help them. <br/>
</section>
</div>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
The input is given from standard input in the following format. <br/>
<blockquote>$H \ W$
$a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$
$a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$
$\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$
$a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$
</blockquote>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<ul>
<li>Print the maximum number of souvenirs they can get.</li>
</ul>
</section>
<section>
<h3>Constraints</h3>
<ul>
<li>$1 \le H, W \le 200$</li>
<li>$0 \le a_{i, j} \le 10^5$</li>
</ul>
</section>
<section>
<h3>Subtasks</h3>
Subtask 1 [ 50 points ] <br/>
<ul>
<li>The testcase in the subtask satisfies $1 \le H \le 2$.</li>
</ul>
Subtask 2 [ 80 points ] <br/>
<ul>
<li>The testcase in the subtask satisfies $1 \le H \le 3$.</li>
</ul>
Subtask 3 [ 120 points ] <br/>
<ul>
<li>The testcase in the subtask satisfies $1 \le H, W \le 7$.</li>
</ul>
Subtask 4 [ 150 points ] <br/>
<ul>
<li>The testcase in the subtask satisfies $1 \le H, W \le 30$.</li>
</ul>
Subtask 5 [ 200 points ] <br/>
<ul>
<li>There are no additional constraints.</li>
</ul>
</section>
</div>
</div>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
3 3
1 0 5
2 2 3
4 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
21
</pre>
The cell at $i$-th row and $j$-th column is denoted $(i, j)$. <br/>
In this case, one of the optimal solution is this:<br/>
<ul>
<li>Sigma moves $(1, 1) -> (1, 2) -> (1, 3) -> (2, 3) -> (3, 3)$.</li>
<li>Sugim moves $(1, 1) -> (2, 1) -> (3, 1) -> (3, 2) -> (3, 3)$.</li>
</ul>
Then, they can get $21$ souvernirs. <br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
6 6
1 2 3 4 5 6
8 6 9 1 2 0
3 1 4 1 5 9
2 6 5 3 5 8
1 4 1 4 2 1
2 7 1 8 2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
97
</pre>
</section>
</div>
Writer : square1001<br/>
</span> |
p02620 | <span class="lang-en">
<p>(Please read problem A first. The maximum score you can get by solving this problem C is 1, which will have almost no effect on your ranking.)</p>
<div class="part">
<section>
<h3>Beginner's Guide</h3><p>"Local search" is a powerful method for finding a high-quality solution.
In this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution.
If the solution gets better, update it, and if it gets worse, restore it.
By repeating this process, the quality of the solution is gradually improved over time.
The pseudo-code is as follows.</p>
<pre>solution = compute an initial solution (by random generation, or by applying other methods such as greedy)
while the remaining time > 0:
slightly modify the solution (randomly)
if the solution gets worse:
restore the solution
</pre>
<p>For example, in this problem, we can use the following modification: pick the date <var>d</var> and contest type <var>q</var> at random and change the type of contest to be held on day <var>d</var> to <var>q</var>.
The pseudo-code is as follows.</p>
<pre>t[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy)
while the remaining time > 0:
pick d and q at random
old = t[d] # Remember the original value so that we can restore it later
t[d] = q
if the solution gets worse:
t[d] = old
</pre>
<p>The most important thing when using the local search method is the design of how to modify solutions.</p>
<ol>
<li>If the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small.</li>
<li>In order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification.</li>
</ol>
<p>In this problem C, we focus on the second point.
The score after the modification can, of course, be obtained by calculating the score from scratch.
However, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification.
From another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation.
In such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search.
Let's implement fast incremental score computation.
It's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC!</p>
<p>In this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug.
For early detection of bugs, it is a good idea to unit test functions you implemented complicated routines.
For example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.</p>
</section>
</div>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You will be given a contest schedule for <var>D</var> days and <var>M</var> queries of schedule modification.
In the <var>i</var>-th query, given integers <var>d_i</var> and <var>q_i</var>, change the type of contest to be held on day <var>d_i</var> to <var>q_i</var>, and then output the final satisfaction at the end of day <var>D</var> on the updated schedule.
Note that we do not revert each query. That is, the <var>i</var>-th query is applied to the new schedule obtained by the <var>(i-1)</var>-th query.</p>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A and the queries.</p>
<pre><var>D</var>
<var>c_1</var> <var>c_2</var> <var>\cdots</var> <var>c_{26}</var>
<var>s_{1,1}</var> <var>s_{1,2}</var> <var>\cdots</var> <var>s_{1,26}</var>
<var>\vdots</var>
<var>s_{D,1}</var> <var>s_{D,2}</var> <var>\cdots</var> <var>s_{D,26}</var>
<var>t_1</var>
<var>t_2</var>
<var>\vdots</var>
<var>t_D</var>
<var>M</var>
<var>d_1</var> <var>q_1</var>
<var>d_2</var> <var>q_2</var>
<var>\vdots</var>
<var>d_M</var> <var>q_M</var>
</pre>
<ul>
<li>The constraints and generation methods for the input part are the same as those for Problem A.</li>
<li>For each <var>d=1,\ldots,D</var>, <var>t_d</var> is an integer generated independently and uniformly at random from <var>{1,2,\ldots,26}</var>.</li>
<li>The number of queries <var>M</var> is an integer satisfying <var>1\leq M\leq 10^5</var>.</li>
<li>For each <var>i=1,\ldots,M</var>, <var>d_i</var> is an integer generated independently and uniformly at random from <var>{1,2,\ldots,D}</var>.</li>
<li>For each <var>i=1,\ldots,26</var>, <var>q_i</var> is an integer satisfying <var>1\leq q_i\leq 26</var> generated uniformly at random from the <var>25</var> values that differ from the type of contest on day <var>d_i</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Let <var>v_i</var> be the final satisfaction at the end of day <var>D</var> on the schedule after applying the <var>i</var>-th query.
Print <var>M</var> integers <var>v_i</var> to Standard Output in the following format:</p>
<pre><var>v_1</var>
<var>v_2</var>
<var>\vdots</var>
<var>v_M</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
1
17
13
14
13
5
1 7
4 11
3 4
5 24
4 19
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>72882
56634
38425
27930
42884
</pre>
<p>Note that this example is a small one for checking the problem specification. It does not satisfy the constraint <var>D=365</var> and is never actually given as a test case.</p>
</section>
</div>
<div class="part">
<section>
<h3>Next Step</h3><p>Let's go back to Problem A and implement the local search algorithm by utilizing the incremental score calculator you just implemented!
For this problem, the current modification "pick the date <var>d</var> and contest type <var>q</var> at random and change the type of contest to be held on day <var>d</var> to <var>q</var>" is actually not so good. By considering why it is not good, let's improve the modification operation.
One of the most powerful and widely used variant of the local search method is "Simulated Annealing (SA)", which makes it easier to reach a better solution by stochastically accepting worsening moves.
For more information about SA and other local search techniques, please refer to the editorial that will be published after the contest.</p></section>
</div>
</span> |
p03461 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer wants a directed graph that satisfies the following conditions:</p>
<ul>
<li>The number of vertices, <var>N</var>, is at most <var>300</var>.</li>
<li>There must not be self-loops or multiple edges.</li>
<li>The vertices are numbered from <var>1</var> through <var>N</var>.</li>
<li>Each edge has either an integer weight between <var>0</var> and <var>100</var> (inclusive), or a label <code>X</code> or <code>Y</code>.</li>
<li>For every pair of two integers <var>(x,y)</var> such that <var>1 ≤ x ≤ A</var>, <var>1 ≤ y ≤ B</var>,
the shortest distance from Vertex <var>S</var> to Vertex <var>T</var> in the graph where the edges labeled <code>X</code> have the weight <var>x</var> and the edges labeled <code>Y</code> have the weight <var>y</var>, is <var>d_{x,y}</var>.</li>
</ul>
<p>Construct such a graph (and a pair of <var>S</var> and <var>T</var>) for him, or report that it does not exist.
Refer to Output section for output format.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>≤</var> <var>A,B</var> <var>≤</var> <var>10</var></li>
<li><var>1</var> <var>≤</var> <var>d_{x,y}</var> <var>≤</var> <var>100</var> (<var>1</var> <var>≤</var> <var>x</var> <var>≤</var> <var>A</var>, <var>1</var> <var>≤</var> <var>y</var> <var>≤</var> <var>B</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>A</var> <var>B</var>
<var>d_{1,1}</var> <var>d_{1,2}</var> <var>..</var> <var>d_{1,B}</var>
<var>d_{2,1}</var> <var>d_{2,2}</var> <var>..</var> <var>d_{2,B}</var>
<var>:</var>
<var>d_{A,1}</var> <var>d_{A,2}</var> <var>..</var> <var>d_{A,B}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If no graph satisfies the condition, print <code>Impossible</code>.</p>
<p>If there exists a graph that satisfies the condition, print <code>Possible</code> in the first line.
Then, in the subsequent lines, print the constructed graph in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>u_1</var> <var>v_1</var> <var>c_1</var>
<var>u_2</var> <var>v_2</var> <var>c_2</var>
:
<var>u_M</var> <var>v_M</var> <var>c_M</var>
<var>S</var> <var>T</var>
</pre>
<p>Here, <var>M</var> is the number of the edges, and <var>u_i</var>, <var>v_i</var>, <var>c_i</var> represent edges as follows: there is an edge from Vertex <var>u_i</var> to Vertex <var>v_i</var> whose weight or label is <var>c_i</var>.</p>
<p>Also refer to Sample Outputs.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
1 2 2
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Possible
3 4
1 2 X
2 3 1
3 2 Y
1 3 Y
1 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 3
100 50 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Impossible
</pre></section>
</div>
</span> |
p03031 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> switches with "on" and "off" state, and <var>M</var> bulbs. The switches are numbered <var>1</var> to <var>N</var>, and the bulbs are numbered <var>1</var> to <var>M</var>.</p>
<p>Bulb <var>i</var> is connected to <var>k_i</var> switches: Switch <var>s_{i1}</var>, <var>s_{i2}</var>, <var>...</var>, and <var>s_{ik_i}</var>. It is lighted when the number of switches that are "on" among these switches is congruent to <var>p_i</var> modulo <var>2</var>.</p>
<p>How many combinations of "on" and "off" states of the switches light all the bulbs?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N, M \leq 10</var></li>
<li><var>1 \leq k_i \leq N</var></li>
<li><var>1 \leq s_{ij} \leq N</var></li>
<li><var>s_{ia} \neq s_{ib} (a \neq b)</var></li>
<li><var>p_i</var> is <var>0</var> or <var>1</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>
<var>k_1</var> <var>s_{11}</var> <var>s_{12}</var> <var>...</var> <var>s_{1k_1}</var>
<var>:</var>
<var>k_M</var> <var>s_{M1}</var> <var>s_{M2}</var> <var>...</var> <var>s_{Mk_M}</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
2 1 2
1 2
0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<ul>
<li>Bulb <var>1</var> is lighted when there is an even number of switches that are "on" among the following: Switch <var>1</var> and <var>2</var>.</li>
<li>Bulb <var>2</var> is lighted when there is an odd number of switches that are "on" among the following: Switch <var>2</var>.</li>
</ul>
<p>There are four possible combinations of states of (Switch <var>1</var>, Switch <var>2</var>): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3
2 1 2
1 1
1 2
0 0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<ul>
<li>Bulb <var>1</var> is lighted when there is an even number of switches that are "on" among the following: Switch <var>1</var> and <var>2</var>.</li>
<li>Bulb <var>2</var> is lighted when there is an even number of switches that are "on" among the following: Switch <var>1</var>.</li>
<li>Bulb <var>3</var> is lighted when there is an odd number of switches that are "on" among the following: Switch <var>2</var>.</li>
</ul>
<p>Switch <var>1</var> has to be "off" to light Bulb <var>2</var> and Switch <var>2</var> has to be "on" to light Bulb <var>3</var>, but then Bulb <var>1</var> will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 2
3 1 2 5
2 2 3
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p03524 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a string <var>S</var> consisting of three kinds of letters: <code>a</code>, <code>b</code> and <code>c</code>.</p>
<p>He has a phobia for palindromes, and wants to permute the characters in <var>S</var> so that <var>S</var> will not contain a palindrome of length <var>2</var> or more as a substring. Determine whether this is possible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</var></li>
<li><var>S</var> consists of <code>a</code>, <code>b</code> and <code>c</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the objective is achievable, print <code>YES</code>; if it is unachievable, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abac
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>As it stands now, <var>S</var> contains a palindrome <code>aba</code>, but we can permute the characters to get <code>acba</code>, for example, that does not contain a palindrome of length <var>2</var> or more.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aba
</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>babacccabab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre></section>
</div>
</span> |
p01519 |
<!-- begin en only -->
<h3><u>Sister Ports
</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>姉妹港
</u></h3>
<!-- end ja only -->
<div>
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ACM 国は正 n 角形の島国である.
n 個の角に港があり,ある角の港から時計回りに 1 から n までの番号が順番に付いている.
港は点とみなす.
</p>
<p>
ACM 国には,二種類の道路がある.
</p>
<ol>
<li><b>隣り合う港を繋ぐ道路</b> 全ての隣接する港は道路で接続されている.すなわち,番号の差が 1 である港同士および港 1 と港 n の間に道路がある.この種類の道路は n 本ある.</li>
<li><b>島の内部を通る道路</b> 一部の隣接しない港の間も,道路で接続されている.この種類の道路は m 本あり,道路 i は港 a<sub>i</sub> と港 b<sub>i</sub> を接続する.</li>
</ol>
<p>
道路は線分とみなす.ACM 国では,任意の 2 つの道路は端点以外で共有点を持たない.
</p>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_fig1">
</center>
</center>
<center>
<p>
<i>図 G-1: 港と道路の例</i>
</p>
</center>
<p>
ACM 国は,港に事故が起きた時などに備えるため,全ての港について姉妹港を決め,いつでも互いを補助できるよう準備させることにした.
全ての港について姉妹港は 1 つで,港 a が港 b の姉妹港であるとき,港 b も港 a の姉妹港である.
すなわち,n 個の港から,港が重複しない n/2 個のペアを作る.
このとき,ACM 国は,姉妹港の間には必ず道がなければならないとすることにした.
</p>
<p>
ACM 国に住む優秀なプログラマーであるあなたの仕事は,
全港に対する姉妹港の選び方の総数を計算するプログラムを作成することである.
</p>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_fig2">
</center>
</center>
<center>
<p>
<i>図 G-2: 姉妹港の選び方の例(姉妹港同士の間の道路を赤色太線で表示している)</i>
</p>
</center>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
入力は1つ以上のデータセットからなる.1つのデータセットは次の形式をしている.
</p>
<blockquote>
<var>n</var> <var>m</var><br/>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var><br/>
<var>...</var><br/>
<var>a<sub>m</sub></var> <var>b<sub>m</sub></var><br/>
</blockquote>
<p>
先頭行は 2 つの正の整数 n, m からなり,
それぞれ ACM 国の港の数および種類 2 の道路の数を表す.
続く m 行の i 行目は 2 個の整数 a<sub>i</sub>, b<sub>i</sub> からなり,
道路 i が港 a<sub>i</sub>, b<sub>i</sub> を結ぶことを表す.
</p>
<p>
任意の 2 つの道路は端点以外で共有点を持たない.また,これらの数は以下の範囲の値をとる.
</p>
<ul>
<li>3 ≤ n ≤ 50,000</li>
<li>0 ≤ m ≤ 50,000</li>
<li>1 ≤ a<sub>i</sub>, b<sub>i</sub> ≤ n</li>
</ul>
<p>
入力の終わりはふたつのゼロを含む行で表される.
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
各データセットについて,
姉妹港の選び方の総数を 1000003 で割った余りを出力せよ.
適切な姉妹港の選び方が存在しない場合は 0 を出力せよ.
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
6 1
1 4
8 3
1 6
1 5
2 5
12 3
3 10
4 9
6 9
3 0
0 0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div>
<h3>Output for Sample Input</h3>
<div>
<pre>
3
5
7
0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div> |
p03174 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> men and <var>N</var> women, both numbered <var>1, 2, \ldots, N</var>.</p>
<p>For each <var>i, j</var> (<var>1 \leq i, j \leq N</var>), the compatibility of Man <var>i</var> and Woman <var>j</var> is given as an integer <var>a_{i, j}</var>.
If <var>a_{i, j} = 1</var>, Man <var>i</var> and Woman <var>j</var> are compatible; if <var>a_{i, j} = 0</var>, they are not.</p>
<p>Taro is trying to make <var>N</var> pairs, each consisting of a man and a woman who are compatible.
Here, each man and each woman must belong to exactly one pair.</p>
<p>Find the number of ways in which Taro can make <var>N</var> pairs, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 21</var></li>
<li><var>a_{i, j}</var> is <var>0</var> or <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>N</var>
<var>a_{1, 1}</var> <var>\ldots</var> <var>a_{1, N}</var>
<var>:</var>
<var>a_{N, 1}</var> <var>\ldots</var> <var>a_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways in which Taro can make <var>N</var> pairs, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 1 1
1 0 1
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There are three ways to make pairs, as follows (<var>(i, j)</var> denotes a pair of Man <var>i</var> and Woman <var>j</var>):</p>
<ul>
<li><var>(1, 2), (2, 1), (3, 3)</var></li>
<li><var>(1, 2), (2, 3), (3, 1)</var></li>
<li><var>(1, 3), (2, 1), (3, 2)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
0 1 0 0
0 0 0 1
1 0 0 0
0 0 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There is one way to make pairs, as follows:</p>
<ul>
<li><var>(1, 2), (2, 4), (3, 1), (4, 3)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>21
0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1
1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0
0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1
0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0
1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0
0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1
0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0
0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1
0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1
0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1
0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0
0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 1
0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1
1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1
0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1
1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0
0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1
0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1
0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0
1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0
1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>102515160
</pre>
<p>Be sure to print the number modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p01149 |
<H1><font color="#000">Problem A:</font> Blackjack</H1>
<p>
Brian Jones is an undergraduate student at Advanced College of Metropolitan. Recently he was
given an assignment in his class of Computer Science to write a program that plays a dealer of
blackjack.
</p>
<p>
Blackjack is a game played with one or more decks of playing cards. The objective of each player
is to have the score of the hand close to 21 without going over 21. The score is the total points
of the cards in the hand. Cards from 2 to 10 are worth their face value. Face cards (jack, queen
and king) are worth 10 points. An ace counts as 11 or 1 such a way the score gets closer to
but does not exceed 21. A hand of more than 21 points is called <i>bust</i>, which makes a player
automatically lose. A hand of 21 points with exactly two cards, that is, a pair of an ace and a
ten-point card (a face card or a ten) is called a <i>blackjack</i> and treated as a special hand.
</p>
<p>
The game is played as follows. The dealer first deals two cards each to all players and the dealer
himself. In case the dealer gets a blackjack, the dealer wins and the game ends immediately. In
other cases, players that have blackjacks win automatically. The remaining players make their
turns one by one. Each player decides to take another card (<i>hit</i>) or to stop taking (<i>stand</i>) in
his turn. He may repeatedly hit until he chooses to stand or he busts, in which case his turn
is over and the next player begins his play. After all players finish their plays, the dealer plays
according to the following rules:
</p>
<ul>
<li>Hits if the score of the hand is 16 or less.</li>
<li>Also hits if the score of the hand is 17 and one of aces is counted as 11.</li>
<li>Stands otherwise.</li>
</ul>
<p>
Players that have unbusted hands of higher points than that of the dealer win. All players that
do not bust win in case the dealer busts. It does not matter, however, whether players win or
lose, since the subject of the assignment is just to simulate a dealer.
</p>
<p>
By the way, Brian is not good at programming, thus the assignment is a very hard task for him.
</p>
<p>
So he calls you for help, as you are a good programmer.
Your task is to write a program that counts the score of the dealer’s hand after his play for each
given sequence of cards.
</p>
<H2>Input</H2>
<p>
The first line of the input contains a single positive integer N , which represents the number of
test cases. Then N test cases follow.
</p>
<p>
Each case consists of two lines. The first line contains two characters, which indicate the cards
in the dealer’s initial hand. The second line contains eight characters, which indicate the top
eight cards in the pile after all players finish their plays.
</p>
<p>
A character that represents a card is one of A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q and K, where A is
an ace, T a ten, J a jack, Q a queen and K a king.
</p>
<p>
Characters in a line are delimited by a single space.
</p>
<p>
The same cards may appear up to four times in one test case. Note that, under this condition,
the dealer never needs to hit more than eight times as long as he or she plays according to the
rule described above.
</p>
<H2>Output</H2>
<p>
For each case, print on a line “blackjack” if the dealer has a blackjack; “bust” if the dealer
busts; the score of the dealer’s hand otherwise.
</p>
<H2>Sample Input</H2>
<pre>
4
5 4
9 2 8 3 7 4 6 5
A J
K Q J T 9 8 7 6
T 4
7 J A 6 Q T K 7
2 2
2 3 4 K 2 3 4 K
</pre>
<H2>Output for the Sample Input</H2>
<pre>
18
blackjack
21
bust
</pre>
|
p00308 |
<h2>未知の病原菌</h2>
<p>
英世博士は未知の病原菌を発見しました。この病原菌は、アクダマキンとゼンダマキンと呼ばれる二種類の菌が、一直線に連なった鎖状の構造をしています。人類のために、この病原菌を無害化したいと考えています。
</p>
<p>この病原菌は、長さが2以下になると力が弱まり、免疫力によって無害化されることが分かっています。英世博士は、この病原菌を任意の場所で切断して、前半と後半の2つの鎖にすることができます。また、2つの鎖を連結して1つの鎖にすることもできます。
</p>
<p>
しかし注意しなければいけないのは、アクダマキンの数が多い鎖はきわめて有害だということです。ある鎖においてアクダマキンの数がゼンダマキンの数よりも多くなると、その瞬間アクダマキンは無制限に増殖を始めます。これは長さ2以下の鎖についても例外ではないので、慎重に鎖を切断していかなければなりません。
</p>
<p>
どの瞬間においてもアクダマキンの数の方が多いような鎖を作ることなく、一本の鎖を長さ2以下にして無害化することは可能でしょうか。英世博士は、助手であるあなたに無害化が可能かどうか判定するプログラムを作成するよう指示しました。無害化が可能ならばその操作を出力し、不可能ならば不可能であると出力するプログラムを作成してください。ただし、その操作のステップ数が最小である必要はありません。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>Q</var>
<var>str<sub>1</sub></var>
<var>str<sub>2</sub></var>
:
<var>str<sub>Q</sub></var>
</pre>
<p>
1 行目に病原菌の数 <var>Q</var> (1 ≤ <var>Q</var> ≤ 300) が与えられる。続く <var>Q</var> 行に各病原菌の初期状態を表す '<span>o</span>' (ゼンダマキン) および '<span>x</span>' (アクダマキン) からなる1つの文字列 <var>str<sub>i</sub></var> が与えられる。文字列 <var>str<sub>i</sub></var> の長さは 1 以上 100 以下である。
</p>
<h2>出力</h2>
<p>
<var>str<sub>i</sub></var> について、要求を満たす切断・結合操作の列が存在する場合、出力の最初の行にはその操作列の長さを表す整数 <var>n</var> を出力し、続く <var>n</var> 行に操作の内容を1行に1操作ずつ、最初の操作から順に出力する。
</p>
<p>
切断操作は以下の形式で表すこと。
</p>
<pre>
split <var>a</var> <var>p</var>
</pre>
<p>
<var>a</var> は切断する鎖の識別番号を表す整数であり、<var>p</var> はその鎖を切断する位置である。この操作の結果、鎖 <var>a</var> は先頭から <var>p</var> 番目(先頭を 0 から始める通し番号)の菌の直後で切断される。新しくできる2つの鎖のうち、前半のものに識別番号 <var>m</var>+1 が、後半のものに識別番号 <var>m</var>+2 が付与される(ここで、<var>m</var> はこれまでに付与された最も大きな識別番号を表す)。また、鎖 <var>a</var> は消滅する。
</p>
<p>
結合操作は以下の形式で表すこと。
</p>
<pre>
join <var>a</var> <var>b</var>
</pre>
<p>
<var>a</var>, <var>b</var> は結合する鎖の識別番号を表す整数である。この操作の結果、鎖 <var>a</var> の末尾に鎖 <var>b</var> の先頭を結合した新しい鎖が作られる。新しく作られた鎖には、識別番号 <var>m</var>+1 が付与される(ここで、<var>m</var> はこれまでに付与された最も大きな識別番号を表す)。また、鎖 <var>a</var>, <var>b</var> は消滅する。
</p>
<p>
入力として与えられる最初の鎖には、識別番号 0 が付与されている。
</p>
<p>
操作の結果、問題の要求を満たすように鎖が分解されていた場合、どのような操作でも正答と判定される。操作列の長さも必ずしも最短である必要はない。ただし、操作列の長さは 20000 以下でなければならない。データセットにおいて、鎖が分解可能な場合、必ずこの条件を満たす操作列が存在することが保証される。
</p>
<p>
不正な操作列が出力された場合、誤答と判定される。不正な操作列には、以下の場合が含まれる。
</p>
<ul>
<li> 切断操作 <span>split</span> <var>a</var> <var>p</var> において、0 ≤ <var>p</var> < (鎖 <var>a</var> の長さ)-1 が満たされていない場合。</li>
<li> 切断・結合操作の対象となる鎖の識別番号がまだ生成されていないものである場合や、既に別の操作の対象となったため消滅している場合。</li>
<li> 結合操作 <span>join</span> <var>a</var> <var>b</var> において、<var>a</var> と <var>b</var> が等しい場合。</li>
</ul>
<p>
要求を満たす切断・結合操作の列が存在しない場合、"<span>-1</span>"と出力する。
</p>
<h2>入出力例 </h2>
<h2>入力例</h2>
<pre>
6
oooxxxx
ooooxxx
oxxooxxo
ooxx
oo
ooo
</pre>
<h2> 出力例</h2>
<pre>
-1
7
split 0 0
join 2 1
split 3 4
split 4 0
join 7 6
split 8 2
split 9 0
3
split 0 1
split 2 1
split 4 1
-1
0
1
split 0 0
</pre>
<p>
例えば、入力例の2番目の病原菌 <span>ooooxxx</span> は、<br>
<span>split</span> 0 0 により <span>o</span>(1) と <span>oooxxx</span>(2) ができる。ここで、()内の数字は識別番号を表す。<br>
<span>join</span> 2 1 により <span>oooxxxo</span>(3) ができ 1 と 2 は消滅する。<br>
<span>split</span> 3 4 により <span>oooxx</span>(4) と <span>xo</span>(5) ができる。このとき{ <span>oooxx</span>(4), <span>xo</span>(5) }の鎖が存在する。<br>
<span>split</span> 4 0 により <span>o</span>(6) と <span>ooxx</span>(7) ができる。{ <span>xo</span>(5), <span>o</span>(6), <span>ooxx</span>(7)}<br>
<span>join</span> 7 6 により <span>ooxxo</span>(8) ができる。{ <span>xo</span>(5), <span>ooxxo</span>(8)}<br>
<span>split</span> 8 2 により <span>oox</span>(9) と <span>xo</span>(10) ができる。{<span>xo</span>(5), <span>oox</span>(9), <span>xo</span>(10) }<br>
<span>split</span> 9 0 により { <span>xo</span>(5), <span>xo</span>(10), <span>o</span>(11), <span>ox</span>(12) } となって終了する。
</p> |
p02335 | <!--<h1>写像12相 その5:ボールに区別なし・箱に区別あり・箱の中身は1つ以下</h1>-->
<h1>Balls and Boxes 5</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td style="background-color:#aff">5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is <b>not</b> distinguished from the other.</li>
<li>Each box is distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box can contain at most one ball.</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
3 5
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<h2>Sample Input 2</h2>
<pre>
5 10
</pre>
<h2>Sample Output 2</h2>
<pre>
252
</pre>
<h2>Sample Input 3</h2>
<pre>
100 200
</pre>
<h2>Sample Output 3</h2>
<pre>
407336795
</pre>
|
p03877 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>Consider all integers between <var>1</var> and <var>2N</var>, inclusive.
Snuke wants to divide these integers into <var>N</var> pairs such that:</p>
<ul>
<li>Each integer between <var>1</var> and <var>2N</var> is contained in exactly one of the pairs.</li>
<li>In exactly <var>A</var> pairs, the difference between the two integers is <var>1</var>.</li>
<li>In exactly <var>B</var> pairs, the difference between the two integers is <var>2</var>.</li>
<li>In exactly <var>C</var> pairs, the difference between the two integers is <var>3</var>.</li>
</ul>
<p>Note that the constraints guarantee that <var>N = A + B + C</var>, thus no pair can have the difference of <var>4</var> or more.</p>
<p>Compute the number of ways to do this, modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 5000</var></li>
<li><var>0 ≤ A, B, C</var></li>
<li><var>A + B + C = N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two possibilities: <var>1-2, 3-5, 4-6</var> or <var>1-3, 2-4, 5-6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>600 100 200 300
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>522158867
</pre></section>
</div>
</span> |
p00758 |
<h3><U>Watchdog Corporation</U></h3>
<!-- end en only -->
<div> <!-- please enclose each h3 level section with div -->
<!-- begin en only -->
<p>
In Northern Kyushu, you are running a company
which rents watchdogs in response to the customers' order.
The distinguishing point of your service is that you also
install fences to enhance the performance of watchdogs.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The dog is put on a leash, which is tied up to a peg.
You are installing fences at the
border of the dog's reach, so that strangers approaching the
fence are taken care of by your dog.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
There may be a rectangular building near the dog; the dog cannot
enter the building, but can go around it as long as the length of
the leash permits, as in Figure F-1. You do not need fences along the
building's wall.
</p>
<!-- end en only -->
<!-- begin en only -->
<div align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1177" width="720" height="480">
<p>Figure F-1: Example fence layouts (some parts of the fences are omitted.)</p>
</div>
<!-- end en only -->
<!-- begin en only -->
<p>
Given the length of the leash and the position and the size of the
building, your program should calculate the length of the fence.
</p>
<!-- end en only -->
</div>
<h3>Input</h3>
<div>
<!-- begin en only -->
<p>
The input consists of multiple datasets each consisting of
five integers in a line of the following format.
</p>
<!-- end en only -->
<blockquote>
<i>len</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub>
</blockquote>
<!-- begin en only -->
<p>
<i>len</i> indicates the length of the leash.
<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>x</i><sub>2</sub>
and <i>y</i><sub>2</sub> indicate the size and position of the
building in that a point with coordinate (<i>x</i>,<i>y</i>)
such that <i>x</i><sub>1</sub> < <i>x</i> <<i>x</i><sub>2</sub> and
<i>y</i><sub>1</sub> < <i>y</i> < <i>y</i><sub>2</sub> is
contained in the building. This means that
the building's walls are parallel to either the X-axis or Y-axis.
The peg is located on the origin.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
You may assume that 0 < <i>len</i> ≤ 100, −100
≤ <i>x</i><sub>1</sub> < <i>x</i><sub>2</sub> ≤ 100 and
−100 ≤ <i>y</i><sub>1</sub> < <i>y</i><sub>2</sub> ≤ 100.
You may also assume that the peg is located apart from the
building (that is, neither inside nor on the border of the building).
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing five zeros.
</p>
<!-- end en only -->
</div>
<h3>Output</h3>
<div>
<!-- begin en only -->
<p>
For each dataset, output the total length of the fences as a
single fractional number in
a line. There may not be any other characters in the output.
The output should not contain an error greater than 0.00001.
</p>
<!-- end en only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3 3 0 6 5
5 3 0 6 5
6 3 0 6 5
7 3 0 6 5
9 3 0 6 5
10 3 0 6 5
12 3 0 6 5
100 3 0 6 5
4 -3 4 5 8
5 -3 4 5 8
6 -3 4 5 8
64 -30 40 50 50
7 -3 4 5 8
10 -3 4 5 8
11 -3 4 5 8
14 -3 4 5 8
35 -3 4 5 8
100 -3 4 5 8
10 5 9 12 12
13 5 9 12 12
15 5 9 12 12
18 5 9 12 12
19 5 9 12 12
20 5 9 12 12
21 5 9 12 12
100 5 9 12 12
100 -5 1 -3 5
100 0 1 100 2
100 -1 99 100 100
10 -1 1 1 2
84 1 -77 5 -42
27 -12 -7 3 -4
0 0 0 0 0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
18.84955592
26.77945045
31.69103413
39.54501577
55.51851918
63.83954229
75.38181750
628.05343108
25.13274123
24.98091545
29.43519428
318.90944272
35.02723766
55.44758990
64.23914179
89.33649537
219.11188064
627.48648370
62.83185307
76.33420961
88.61222855
112.17417345
121.59895141
126.16196589
132.25443447
628.23333565
628.18890261
626.17695473
613.16456638
62.61625003
527.84509612
168.07337509
</pre>
</div> |
p02765 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is a member of a programming competition site, <em>ButCoder</em>.</p>
<p>Each member of ButCoder is assigned two values: <strong>Inner Rating</strong> and <strong>Displayed Rating</strong>.</p>
<p>The Displayed Rating of a member is equal to their Inner Rating if the member has participated in <var>10</var> or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus <var>100 \times (10 - K)</var> when the member has participated in <var>K</var> contests.</p>
<p>Takahashi has participated in <var>N</var> contests, and his Displayed Rating is <var>R</var>. Find his Inner Rating.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq R \leq 4111</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>R</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print his Inner Rating.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2919
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3719
</pre>
<p>Takahashi has participated in <var>2</var> contests, which is less than <var>10</var>, so his Displayed Rating is his Inner Rating minus <var>100 \times (10 - 2) = 800</var>.</p>
<p>Thus, Takahashi's Inner Rating is <var>2919 + 800 = 3719</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>22 3051
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3051
</pre></section>
</div>
</span> |
p03800 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke, who loves animals, built a zoo.</p>
<p>There are <var>N</var> animals in this zoo. They are conveniently numbered <var>1</var> through <var>N</var>, and arranged in a circle.
The animal numbered <var>i (2≤i≤N-1)</var> is adjacent to the animals numbered <var>i-1</var> and <var>i+1</var>. Also, the animal numbered <var>1</var> is adjacent to the animals numbered <var>2</var> and <var>N</var>, and the animal numbered <var>N</var> is adjacent to the animals numbered <var>N-1</var> and <var>1</var>.</p>
<p>There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.</p>
<p>Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered <var>i</var> answered <var>s_i</var>. Here, if <var>s_i</var> is <code>o</code>, the animal said that the two neighboring animals are of the same species, and if <var>s_i</var> is <code>x</code>, the animal said that the two neighboring animals are of different species.</p>
<p>More formally, a sheep answered <code>o</code> if the two neighboring animals are both sheep or both wolves, and answered <code>x</code> otherwise.
Similarly, a wolf answered <code>x</code> if the two neighboring animals are both sheep or both wolves, and answered <code>o</code> otherwise.</p>
<p>Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print <code>-1</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 ≤ N ≤ 10^{5}</var></li>
<li><var>s</var> is a string of length <var>N</var> consisting of <code>o</code> and <code>x</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>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there does not exist an valid assignment that is consistent with <var>s</var>, print <code>-1</code>.
Otherwise, print an string <var>t</var> in the following format. The output is considered correct if the assignment described by <var>t</var> is consistent with <var>s</var>.</p>
<ul>
<li><var>t</var> is a string of length <var>N</var> consisting of <code>S</code> and <code>W</code>.</li>
<li>If <var>t_i</var> is <code>S</code>, it indicates that the animal numbered <var>i</var> is a sheep. If <var>t_i</var> is <code>W</code>, it indicates that the animal numbered <var>i</var> is a wolf.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
ooxoox
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>SSSWWS
</pre>
<p>For example, if the animals numbered <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var> and <var>6</var> are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.</p>
<p>Let us remind you: if the neiboring animals are of the same species, a sheep answers <code>o</code> and a wolf answers <code>x</code>. If the neiboring animals are of different species, a sheep answers <code>x</code> and a wolf answers <code>o</code>.</p>
<div style="text-align: center;">
<img alt="b34c052fc21c42d2def9b98d6dccd05c.png" src="https://atcoder.jp/img/arc069/b34c052fc21c42d2def9b98d6dccd05c.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
oox
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Print <code>-1</code> if there is no valid assignment of species.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
oxooxoxoox
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>SSWWSSSWWS
</pre></section>
</div>
</span> |
p02712 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let us define the <strong>FizzBuzz sequence</strong> <var>a_1,a_2,...</var> as follows:</p>
<ul>
<li>If both <var>3</var> and <var>5</var> divides <var>i</var>, <var>a_i=\mbox{FizzBuzz}</var>.</li>
<li>If the above does not hold but <var>3</var> divides <var>i</var>, <var>a_i=\mbox{Fizz}</var>.</li>
<li>If none of the above holds but <var>5</var> divides <var>i</var>, <var>a_i=\mbox{Buzz}</var>.</li>
<li>If none of the above holds, <var>a_i=i</var>.</li>
</ul>
<p>Find the sum of all numbers among the first <var>N</var> terms of the FizzBuzz sequence.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^6</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 sum of all numbers among the first <var>N</var> terms of the FizzBuzz sequence.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>60
</pre>
<p>The first <var>15</var> terms of the FizzBuzz sequence are:</p>
<p><var>1,2,\mbox{Fizz},4,\mbox{Buzz},\mbox{Fizz},7,8,\mbox{Fizz},\mbox{Buzz},11,\mbox{Fizz},13,14,\mbox{FizzBuzz}</var></p>
<p>Among them, numbers are <var>1,2,4,7,8,11,13,14</var>, and the sum of them is <var>60</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>266666333332
</pre>
<p>Watch out for overflow.</p></section>
</div>
</span> |
p01997 | <h1>B: 直角三角形</h1>
<h2>問題</h2>
<p>
直角三角形の斜辺でない $2$ 辺の長さ $A$ , $B$ が与えられる。
長さ $A$ の辺は $x$ 軸と重なっており、長さ $B$ の辺は $y$ 軸と重なっている。
</p>
<p>
次の操作を行う。
</p>
<p>
<ol>
<li>三角形を $x$ 軸周りに回転させる。</li>
<li>操作 $1$ を行ってできた図形を $y$ 軸周りに回転させる。</li>
</ol>
</p>
<p>
操作 $2$ を行ってできた図形の体積を求めよ。
</p>
<h2>制約</h2>
<ul>
<li>入力値は全て整数である。</li>
<li>$1 < A < B < 1000$</li>
</ul>
<h2>入力形式</h2>
<p> 入力は以下の形式で与えられる。 </p>
<p>
$A\ B$
</p>
<h2>出力</h2>
<p>図形の体積を出力せよ。また、末尾に改行も出力せよ。なお、 $0.000001$ 未満の絶対誤差または相対誤差が許容される。</p>
<h2>サンプル</h2>
<h3>サンプル入力 1</h3>
<pre>
1 2
</pre>
<h3>サンプル出力 1</h3>
<pre>
33.510322
</pre>
<h3>サンプル入力 2</h3>
<pre>
7 9
</pre>
<h3>サンプル出力 2</h3>
<pre>
3053.628059
</pre>
|
p00685 |
<H1>Board Arrangements for Concentration Games</H1>
<P>You have to organize a wedding party. The program of the
party will include a concentration game played by the
bride and groom. The arrangement of the concentration game
should be easy since this game will be played to make the
party fun.</P>
<P>We have a 4x4 board and 8 pairs of cards (denoted by `A' to `H')
for the concentration game:</P>
<PRE>
+---+---+---+---+
| | | | | A A B B
+---+---+---+---+ C C D D
| | | | | E E F F
+---+---+---+---+ G G H H
| | | | |
+---+---+---+---+
| | | | |
+---+---+---+---+
</PRE>
<P>To start the game, it is necessary to arrange all 16 cards
face down on the board. For example:</P>
<PRE>
+---+---+---+---+
| A | B | A | B |
+---+---+---+---+
| C | D | C | D |
+---+---+---+---+
| E | F | G | H |
+---+---+---+---+
| G | H | E | F |
+---+---+---+---+
</PRE>
<P>The purpose of the concentration game is to expose as many
cards as possible by repeatedly performing the following
procedure: (1) expose two cards, (2) keep them open if they
match or replace them face down if they do not.</P>
<P>Since the arrangements should be simple, every pair of cards
on the board must obey the following condition: the
relative position of one card to the other card of the pair must be
one of 4 given relative positions.
The 4 relative positions are different from one another and
they are selected from the following 24 candidates:</P><PRE>
(1, 0), (2, 0), (3, 0),
(-3, 1), (-2, 1), (-1, 1), (0, 1), (1, 1), (2, 1), (3, 1),
(-3, 2), (-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (3, 2),
(-3, 3), (-2, 3), (-1, 3), (0, 3), (1, 3), (2, 3), (3, 3).
</PRE>
<P>Your job in this problem is to write a program that
reports the total number of board arrangements which satisfy
the given constraint. For example, if relative positions
(-2, 1), (-1, 1), (1, 1), (1, 2) are given, the total number
of board arrangements is two, where the following two
arrangements satisfy the given constraint:</P><PRE>
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | A | B | C | D | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | B | A | D | C | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | E | F | G | H | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | F | E | H | G | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
the relative positions: the relative positions:
A:(1, 1), B:(-1, 1) A:(1, 2), B:(-1, 1)
C:(1, 1), D:(-1, 1) C:(1, 1), D:(-2, 1)
E:(1, 1), F:(-1, 1) E:(1, 2), F:( 1, 1)
G:(1, 1), H:(-1, 1) G:(-2, 1), H:(-1, 1)
</PRE>
<P>Arrangements of the same pattern should be counted only once. Two
board arrangements are said to have the same pattern if they are
obtained from each other by repeatedly making any two pairs exchange
their positions. For example, the following two arrangements have the
same pattern:
</P><PRE>
X0 X1 X2 X3 X0 X1 X2 X3
+---+---+---+---+ +---+---+---+---+
Y0 | H | G | F | E | Y0 | A | B | C | D |
+---+---+---+---+ +---+---+---+---+
Y1 | G | E | D | F | Y1 | B | D | E | C |
+---+---+---+---+ +---+---+---+---+
Y2 | C | H | B | A | Y2 | F | A | G | H |
+---+---+---+---+ +---+---+---+---+
Y3 | B | C | A | D | Y3 | G | F | H | E |
+---+---+---+---+ +---+---+---+---+
</PRE>
where (1) `A' and `H',
(2) `B' and `G',
(3) `C' and `F', and
(4) `D' and `E'
exchange their positions respectively.
<H2>Input</H2>
<P>The input contains multiple data sets, each representing 4 relative
positions. A data set is given as a line in the following format.</P>
<DIR><TABLE><TR>
<TD>x<SUB>1</SUB></TD><TD>y<SUB>1</SUB></TD>
<TD>x<SUB>2</SUB></TD><TD>y<SUB>2</SUB></TD>
<TD>x<SUB>3</SUB></TD><TD>y<SUB>3</SUB></TD>
<TD>x<SUB>4</SUB></TD><TD>y<SUB>4</SUB></TD>
</TR></TABLE></DIR>
<P>The i-th relative position is given by (x<SUB>i</SUB>, y<SUB>i</SUB>).
You may assume that the given relative positions are different from one
another and each of them is one of the 24 candidates.</P>
<P>The end of input is indicated by the line which contains
a single number greater than 4.</P>
<H2>Output</H2>
<P>For each data set, your program should output the total number
of board arrangements (or more precisely, the total number of
patterns).</P>
<P>Each number should be printed in one line. Since your result is
checked by an automatic grading program,
you should not insert any extra characters nor lines on the output.
</p>
<H2>Sample Input</H2>
<FONT FACE="Courier New">
<pre>
-2 1 -1 1 1 1 1 2
1 0 2 1 2 2 3 3
5
</pre>
</FONT>
<H2>Output for the Sample Input</H2>
<FONT FACE="Courier New">
<pre>
2
15
</pre>
</FONT>
|
p02342 | <!--<h1>写像12相 その12:ボールに区別なし・箱に区別なし・箱の中身は1つ以上</h1>-->
<h1>Balls and Boxes 12</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td style="background-color:#aff">12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is <b>not</b> distinguished from the other.</li>
<li>Each box is <b>not</b> distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box must contain at least one ball.</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
10 5
</pre>
<h2>Sample Output 1</h2>
<pre>
7
</pre>
<h2>Sample Input 2</h2>
<pre>
30 15
</pre>
<h2>Sample Output 2</h2>
<pre>
176
</pre>
<h2>Sample Input 3</h2>
<pre>
100 30
</pre>
<h2>Sample Output 3</h2>
<pre>
3910071
</pre>
|
p03103 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up <var>M</var> cans of energy drinks.</p>
<p>There are <var>N</var> stores that sell energy drinks. In the <var>i</var>-th store, he can buy at most <var>B_i</var> cans of energy drinks for <var>A_i</var> yen (the currency of Japan) each.</p>
<p>What is the minimum amount of money with which he can buy <var>M</var> cans of energy drinks?</p>
<p>It is guaranteed that, in the given inputs, a sufficient amount of money can always buy <var>M</var> cans of energy drinks.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N, M \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>1 \leq B_i \leq 10^5</var></li>
<li><var>B_1 + ... + B_N \geq M</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>\vdots</var>
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum amount of money with which Takahashi can buy <var>M</var> cans of energy drinks.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 5
4 9
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>With <var>12</var> yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy <var>5</var> drinks with <var>11</var> yen or less.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 30
6 18
2 5
3 10
7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>130
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100000
1000000000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100000000000000
</pre>
<p>The output may not fit into a <var>32</var>-bit integer type.</p></section>
</div>
</span> |
p01094 |
<h3>Look for the Winner!</h3>
<p>
The citizens of TKB City are famous for their deep love in elections and vote counting.
Today they hold an election for the next chairperson of the electoral commission.
Now the voting has just been closed and the counting is going to start.
The TKB citizens have strong desire to know the winner as early as possible during vote counting.
</p>
<p>
The election candidate receiving the most votes shall be the next chairperson.
Suppose for instance that we have three candidates <i>A</i>, <i>B</i>, and <i>C</i> and ten votes.
Suppose also that we have already counted six of the ten votes and the vote counts of <i>A</i>, <i>B</i>, and <i>C</i> are four, one, and one, respectively.
At this moment, every candidate has a chance to receive four more votes and so everyone can still be the winner.
However, if the next vote counted is cast for <i>A</i>, <i>A</i> is ensured to be the winner since <i>A</i> already has five votes and <i>B</i> or <i>C</i> can have at most four votes at the end.
In this example, therefore, the TKB citizens can know the winner just when the seventh vote is counted.
</p>
<p>
Your mission is to write a program that receives every vote counted, one by one, identifies the winner, and determines when the winner gets ensured.
</p>
<h3>Input</h3>
<p>
The input consists of at most 1500 datasets, each consisting of two lines in the following format.
</p>
<p>
<i>n</i><br>
<i>c</i><sub>1</sub> <i>c</i><sub>2</sub> … <i>c<sub>n</sub></i><br>
</p>
<p>
<i>n</i> in the first line represents the number of votes, and is a positive integer no greater than 100.
The second line represents the <i>n</i> votes, separated by a space.
Each <i>c<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) is a single uppercase letter, <i>i.e.</i> one of 'A' through 'Z'.
This represents the election candidate for which the <i>i</i>-th vote was cast.
Counting shall be done in the given order from <i>c</i><sub>1</sub> to <i>c<sub>n</sub></i>.
</p>
<p>
You should assume that at least two stand as candidates even when all the votes are cast for one candidate.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<h3>Output</h3>
<p>
For each dataset, unless the election ends in a tie, output a single line containing an uppercase letter <i>c</i> and an integer <i>d</i> separated by a space:
<i>c</i> should represent the election winner and <i>d</i> should represent after counting how many votes the winner is identified.
Otherwise, that is, if the election ends in a tie, output a single line containing `TIE'.
</p>
<h3>Sample Input</h3>
<pre>
1
A
4
A A B B
5
L M N L N
6
K K K K K K
6
X X X Y Z X
10
A A A B A C A C C B
10
U U U U U V V W W W
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
A 1
TIE
TIE
K 4
X 5
A 7
U 8
</pre> |
p03553 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> gemstones labeled <var>1</var> through <var>N</var>.</p>
<p>You can perform the following operation any number of times (possibly zero).</p>
<ul>
<li>Select a positive integer <var>x</var>, and smash all the gems labeled with multiples of <var>x</var>.</li>
</ul>
<p>Then, for each <var>i</var>, if the gem labeled <var>i</var> remains without getting smashed, you will receive <var>a_i</var> yen (the currency of Japan).
However, <var>a_i</var> may be negative, in which case you will be charged money.</p>
<p>By optimally performing the operation, how much yen can you earn?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>|a_i| \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum amount of money that can be earned.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 2 -6 4 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>It is optimal to smash Gem <var>3</var> and <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
100 -100 -100 -100 100 -100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>200
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
-1 -2 -3 -4 -5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>It is optimal to smash all the gems.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2
-1000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>99000
</pre></section>
</div>
</span> |
p03046 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Construct a sequence <var>a</var> = {<var>a_1,\ a_2,\ ...,\ a_{2^{M + 1}}</var>} of length <var>2^{M + 1}</var> that satisfies the following conditions, if such a sequence exists.</p>
<ul>
<li>Each integer between <var>0</var> and <var>2^M - 1</var> (inclusive) occurs twice in <var>a</var>.</li>
<li>For any <var>i</var> and <var>j</var> <var>(i < j)</var> such that <var>a_i = a_j</var>, the formula <var>a_i \ xor \ a_{i + 1} \ xor \ ... \ xor \ a_j = K</var> holds.</li>
</ul>
<p><details>
<summary style="display: list-item; outline: none;">What is xor (bitwise exclusive or)?</summary></details></p>
<p>The xor of integers <var>c_1, c_2, ..., c_n</var> is defined as follows:</p>
<ul>
<li>When <var>c_1 \ xor \ c_2 \ xor \ ... \ xor \ c_n</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if the number of integers among <var>c_1, c_2, ...c_m</var> whose binary representations have <var>1</var> in the <var>2^k</var>'s place is odd, and <var>0</var> if that count is even.</li>
</ul>
<p>For example, <var>3 \ xor \ 5 = 6</var>. (If we write it in base two: <code>011</code> <var>xor</var> <code>101</code> <var>=</var> <code>110</code>.)</p>
<p></p></section></div></span> |
p01581 |
<H1><font color="#000">Problem A:</font> Cache Control</H1>
<p>
Mr. Haskins is working on tuning a database system. The database is a simple associative storage that contains key-value pairs. In this database, a key is a distinct identification (ID) number and a value is an object of any type.
</p>
<p>
In order to boost the performance, the database system has a cache mechanism. The cache can be accessed much faster than the normal storage, but the number of items it can hold at a time is limited. To implement caching, he selected least recently used (LRU) algorithm: when the cache is full and a new item (not in the cache) is being accessed, the cache discards the least recently accessed entry and adds the new item.
</p>
<p>
You are an assistant of Mr. Haskins. He regards you as a trusted programmer, so he gave you a task. He wants you to investigate the cache entries after a specific sequence of accesses.
</p>
<H2>Input</H2>
<p>
The first line of the input contains two integers <i>N</i> and <i>M</i>. <i>N</i> is the number of accessed IDs, and <i>M</i> is the size of the cache. These values satisfy the following condition: 1 ≤ <i>N</i>, <i>M</i> ≤ 100000.
</p>
<p>
The following <i>N</i> lines, each containing one ID, represent the sequence of the queries. An ID is a positive integer less than or equal to 10<sup>9</sup>.
</p>
<H2>Output</H2>
<p>
Print IDs remaining in the cache after executing all queries. Each line should contain exactly one ID. These IDs should appear in the order of their last access time, from the latest to the earliest.
</p>
<H2>Sample Input and Output</H2>
<H2>Input #1</H2>
<pre>
3 2
1
2
3
</pre>
<H2>Output #1</H2>
<pre>
3
2
</pre>
<br/>
<H2>Input #2</H2>
<pre>
5 3
1
2
3
4
1
</pre>
<H2>Output #2</H2>
<pre>
1
4
3
</pre> |
p03416 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the number of <em>palindromic numbers</em> among the integers between <var>A</var> and <var>B</var> (inclusive).
Here, a palindromic number is a positive integer whose string representation in base <var>10</var> (without leading zeros) reads the same forward and backward.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>10000 \leq A \leq B \leq 99999</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>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of <em>palindromic numbers</em> among the integers between <var>A</var> and <var>B</var> (inclusive).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>11009 11332
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four integers that satisfy the conditions: <var>11011</var>, <var>11111</var>, <var>11211</var> and <var>11311</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>31415 92653
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>612
</pre></section>
</div>
</span> |
p01978 | <h1>E: いたずらされたグラフ</h1>
<h2>問題</h2>
<p>
あなたはグラフのアルゴリズムとして典型であるフローの問題を解いていた。<br>
その問題で与えられるグラフは、頂点 $N$ 個、辺 $M$ 本であり、頂点 $x_i$ から 頂点 $y_i$ に容量 $z_i$ 、コスト $d_i$ の辺が張られている。
ところが、AORイカちゃんが入力ケースにいたずらした。
その結果、 $x_i, y_i, z_i$ の順序がシャッフルされ、頂点の情報と容量の情報が区別できなくなってしまった。
</p>
<p>
そこで、あなたは $s-t$ 間のフローを求めることを諦め、 $s-t$ 間の最短距離を求めることにした。
あなたは、 $x_i, y_i, z_i$ の順序がシャッフルされた入力ケース $a_i, b_i, c_i$ のうちから二つを頂点情報にし、コスト $d_i$ の辺を張ることにした。つまり、$a_i$ から $b_i$, $a_i$ から $c_i$, $b_i$ から $c_i$ の三つの候補のうち一つにコスト $d_i$ の辺を張る。
</p>
<p>
考えられるグラフのうち、 「s から t への最短距離」の最小値を求めよ。
</p>
<h2>制約</h2>
<ul>
<li>$2 \le N \le 10^5$</li>
<li>$1 \le M \le 10^5$</li>
<li>$1 \le s,t \le N$</li>
<li>$1 \le a_i,b_i,c_i \le N$</li>
<li>$1 \le d_i \le 10^9$</li>
<li>$s \neq t$</li>
<li>元のグラフにおいて $s$ から $t$ への経路が存在する</li>
<li>入力は全て整数</li>
</ul>
<h2>入力</h2>
<p>
$N \ M \ s \ t$<br>
$a_1 \ b_1 \ c_1 \ d_1$<br>
$\vdots$<br>
$a_M \ b_M \ c_M \ d_M$<br>
</p>
<h2>出力</h2>
<p>
考えられるグラフのうち、 「$s$ から $t$ への最短距離」の最小値を一行で出力せよ。また末尾に改行を出力せよ。
</p>
<h2>サンプル</h2>
<h3>サンプル入力 1</h3>
<pre>
5 3 1 4
3 1 2 5
3 4 2 3
5 4 2 2
</pre>
<h3>サンプル出力 1</h3>
<pre>
7
</pre>
<h3>サンプル入力 2</h3>
<pre>
8 5 8 3
4 5 1 2
5 6 2 3
7 8 5 12
3 1 2 11
1 2 3 10
</pre>
<h3>サンプル出力 2</h3>
<pre>
24
</pre>
<!-- - - - - - end nicebody - - - - - -->
|
p03945 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Two foxes Jiro and Saburo are playing a game called <em>1D Reversi</em>. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.</p>
<p>In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string <var>S</var>. There are |S| (the length of <var>S</var>) stones on the board, and each character in <var>S</var> represents the color of the <var>i</var>-th (<var>1 ≦ i ≦ |S|</var>) stone from the left. If the <var>i</var>-th character in <var>S</var> is <code>B</code>, it means that the color of the corresponding stone on the board is black. Similarly, if the <var>i</var>-th character in <var>S</var> is <code>W</code>, it means that the color of the corresponding stone is white.</p>
<p>Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ |S| ≦ 10^5</var></li>
<li>Each character in <var>S</var> is <code>B</code> or <code>W</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of new stones that Jiro needs to place for his purpose.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>BBBWW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.</p>
<p>In either way, Jiro's purpose can be achieved by placing one stone.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>WWWWWW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If all stones are already of the same color, no new stone is necessary.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>WBWBWBWBWB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
</pre></section>
</div>
</span> |
p02657 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Compute <var>A \times B</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A \leq 100</var></li>
<li><var>1 \leq B \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value <var>A \times B</var> as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>We have <var>2 \times 5 = 10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10000
</pre></section>
</div>
</span> |
p00390 | <h1>Round Table of Sages</h1>
<p>
$N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation.
</p>
<ul>
<li>If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-handed sage on his right does not cause such frustration at all.</li>
<li>If sage $i$ is left-handed and a right-handed sage sits on his left, a level of frustration $w_i$ occurs to him. A left-handed sage on his left does not cause such frustration at all.</li>
</ul>
<p>
You wish you could minimize the total amount of frustration by clever sitting order arrangement.
</p>
<p>
Given the number of sages with his dominant hand information, make a program to evaluate the minimum frustration achievable.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$a_1$ $a_2$ $...$ $a_N$
$w_1$ $w_2$ $...$ $w_N$
</pre>
<p>
The first line provides the number of sages $N$ ($3 \leq N \leq 10$). The second line provides an array of integers $a_i$ (0 or 1) which indicate if the $i$-th sage is right-handed (0) or left-handed (1). The third line provides an array of integers $w_i$ ($1 \leq w_i \leq 1000$) which indicate the level of frustration the $i$-th sage bears.
</p>
<h2>Output</h2>
<p>
Output the minimum total frustration the sages bear.
</p>
<h2>Sample Input 1</h2>
<pre>
5
1 0 0 1 0
2 3 5 1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
3
0 0 0
1 2 3
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
|
p02207 | <h2>地震 (Earthquakes)</h2>
<p>E869120 君は地震が苦手です。</p>
<p>具体的には、ある作業をしている時に震度 $p$ の地震が発生した際、その作業のパフォーマンスが $10 \times p$ パーセント低下します。</p>
<p>昨日、$N$ 回地震が発生しました。より具体的に言うと、昨日の i 回目の地震は時刻 $T_i$ に発生し、その震度は $A_i$ でした。</p>
<p>ここで $Q$ 個の質問が与えられます。$i$ 個目の質問の内容は以下の通りです。</p>
<ul>
<li>E869120 君が時刻 $L_i$ から時刻 $R_i$ まで作業をした時、最終的な作業のパフォーマンスの値はいくつになるでしょうか?</li>
</ul>
<p>ただし、作業開始時のパフォーマンスは $1000000000 \ (= 10^9)$ であり、地震以外に作業のパフォ―マンスに影響を及ぼすものはないものとします。</p>
<p>また、作業開始時、終了時と同時に地震が発生していることはありません。</p>
<h3>入力</h3>
<p>入力は以下の形式で標準入力から与えられる。</p>
<pre>
$N$
$T_1$ $A_1$
$T_2$ $A_2$
$T_3$ $A_3$
$\ldots$
$T_N$ $A_N$
$Q$
$L_1$ $R_1$
$L_2$ $R_2$
$L_3$ $R_3$
$\ldots$
$L_Q$ $R_Q$
</pre>
<h3>出力</h3>
<p>質問 $1, 2, 3, \dots, Q$ の答えをこの順に改行区切りで出力しなさい。</p>
<p>ただし、最後には改行を入れること。</p>
<p>なお、想定解答との絶対誤差又は相対誤差が $10^{-7}$ 以内ならば正解と判定される。</p>
<h3>制約</h3>
<ul>
<li>$1 \leq N \leq 100000 \ (= 10^5)$</li>
<li>$1 \leq Q \leq 100000 \ (= 10^5)$</li>
<li>$0 \leq A_i \leq 7$</li>
<li>$1 \leq T_1 < T_2 < \cdots < T_N \leq 1000000000 \ (= 10^9)$</li>
<li>$1 \leq L_i < R_i \leq 1000000000 \ (= 10^9)$</li>
<li>作業開始時刻ちょうどや作業終了時刻ちょうどに、地震が発生するような入力は与えられない。</li>
<li>入力は全て整数である。</li>
</ul>
<h3>入力例1</h3>
<pre>
3
3 3
5 4
8 1
2
1 4
4 9
</pre>
<h3>出力例1</h3>
<pre>
700000000.000000000000
539999999.999999880791
</pre>
<p>どの質問に対しても、出力された値が実際の答えの値との絶対誤差または相対誤差が $10^{-7}$ 以内であれば、正解と判定されます。</p>
<h3>入力例2</h3>
<pre>
3
3 1
41 5
92 6
2
5 35
8 97
</pre>
<h3>出力例2</h3>
<pre>
1000000000.000000000000
200000000.000000059605
</pre>
<h3>入力例3</h3>
<pre>
10
176149409 6
272323398 6
280173589 0
374879716 5
402263621 5
498152735 0
639318228 6
641750638 3
764022785 2
939252868 5
10
40529600 224871240
537110257 584835100
409292125 704323206
674752453 740931787
511335734 793975505
320036645 530705208
527941292 660218875
326908007 473745741
428255750 654430923
590875206 623136989
</pre>
<h3>出力例3</h3>
<pre>
400000000.000000000000
1000000000.000000000000
280000000.000000059605
1000000000.000000000000
224000000.000000089407
250000000.000000000000
280000000.000000059605
250000000.000000000000
280000000.000000059605
1000000000.000000000000
</pre>
|
p01702 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
color: #333333;
display: block;
padding: 8.5px;
margin: 0 0 9px;
font-size: 12px;
line-height: 18px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}</style><div class="part"><h3>Problem Statement</h3>
<p>In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches.
Each light bulb can be turned on or off by exactly one switch.
Each switch may control multiple light bulbs.
When you operate a switch, all the light bulbs controlled by the switch change their states.
You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.
</p>
<p>You decided to restore the correspondence by the following procedure.
</p><ul><li>At first, every switch is off and every light bulb is off.
</li><li>You operate some switches represented by $S_1$.
</li><li>You check the states of the light bulbs represented by $B_1$.
</li><li>You operate some switches represented by $S_2$.
</li><li>You check the states of the light bulbs represented by $B_2$.
</li><li>...
</li><li>You operate some switches represented by $S_Q$.
</li><li>You check the states of the light bulbs represented by $B_Q$.
</li></ul>
<p>After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.
</p>
<p>Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?
</p>
</div><div class="part"><h3>Input</h3>
<p>The input consists of multiple datasets.
The number of dataset is no more than $50$ and the file size is no more than $10\mathrm{MB}$.
Each dataset is formatted as follows.
</p>
<blockquote style="font-size:14pt">$N$ $M$ $Q$<br>$S_1$ $B_1$<br>:<br>:<br>$S_Q$ $B_Q$</blockquote>
<p>The first line of each dataset contains three integers $N$ ($1 \le N \le 36$), $M$ ($1 \le M \le 1{,}000$), $Q$ ($0 \le Q \le 1{,}000$), which denote the number of switches, the number of light bulbs and the number of operations respectively.
The following $Q$ lines describe the information about the switches you have operated and the states of the light bulbs you have checked.
The $i$-th of them contains two strings $S_i$ and $B_i$ of lengths $N$ and $M$ respectively.
Each $S_i$ denotes the set of the switches you have operated: $S_{ij}$ is either $0$ or $1$, which denotes the $j$-th switch is not operated or operated respectively.
Each $B_i$ denotes the states of the light bulbs: $B_{ij}$ is either $0$ or $1$, which denotes the $j$-th light bulb is off or on respectively.
</p>
<p>You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.
</p>
<p>The end of input is indicated by a line containing three zeros.
</p>
</div><div class="part"><h3>Output</h3>
<p>For each dataset, output the correspondence between the switches and the light bulbs consisting of $M$ numbers written in base-$36$.
In the base-$36$ system for this problem, the values $0$-$9$ and $10$-$35$ are represented by the characters '<samp>0</samp>'-'<samp>9</samp>' and '<samp>A</samp>'-'<samp>Z</samp>' respectively.
The $i$-th character of the correspondence means the number of the switch controlling the $i$-th light bulb.
If you cannot determine which switch controls the $i$-th light bulb, output '<samp>?</samp>' as the $i$-th character instead of the number of a switch.
</p>
</div><div class="part"><h3>Sample Input</h3>
<pre>3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0</pre>
</div><div class="part"><h3>Output for the Sample Input</h3>
<pre>2222221100
??
0
1
0123456789A</pre>
</div> |
p00810 |
<H1><font color="#000">Problem H:</font> Super Star</H1>
<p>
During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors or singers. It is a revolutionary theory in astronomy.
</p>
<p>
According to this theory, stars we are observing are not independent objects, but only small portions of larger objects called super stars. A super star is filled with invisible (or transparent) material, and only a number of points inside or on its surface shine. These points are observed as stars by us.
</p>
<p>
In order to verify this theory, Dr. Extreme wants to build motion equations of super stars and to compare the solutions of these equations with observed movements of stars. As the first step, he assumes that a super star is sphere-shaped, and has the smallest possible radius such that the sphere contains all given stars in or on it. This assumption makes it possible to estimate the volume of a super star, and thus its mass (the density of the invisible material is known).
</p>
<p>
You are asked to help Dr. Extreme by writing a program which, given the locations of a number of stars, finds the smallest sphere containing all of them in or on it. In this computation, you should ignore the sizes of stars. In other words, a star should be regarded as a point. You may assume the universe is a Euclidean space.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets. Each data set is given in the following format.
</p>
<pre>
<i>n</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>z</i><sub>1</sub>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>z</i><sub>2</sub>
...
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>z</i><sub><i>n</i></sub>
</pre>
<p>
The first line of a data set contains an integer <i>n</i>, which is the number of points. It satisfies the condition 4 ≤ <i>n</i> ≤ 30.
</p>
<p>
The locations of <i>n</i> points are given by three-dimensional orthogonal coordinates: (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i>) (<i>i</i> = 1,..., <i>n</i>). Three coordinates of a point appear in a line, separated by a space character.
</p>
<p>
Each value is given by a decimal fraction, and is between 0.0 and 100.0 (both ends inclusive). Points are at least 0.01 distant from each other.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<H2>Output</H2>
<p>
For each data set, the radius ofthe smallest sphere containing all given points should be printed, each in a separate line. The printed values should have 5 digits after the decimal point. They may not have an error greater than 0.00001.
</p>
<H2>Sample Input</H2>
<pre>
4
10.00000 10.00000 10.00000
20.00000 10.00000 10.00000
20.00000 20.00000 10.00000
10.00000 20.00000 10.00000
4
10.00000 10.00000 10.00000
10.00000 50.00000 50.00000
50.00000 10.00000 50.00000
50.00000 50.00000 10.00000
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7.07107
34.64102
</pre>
|
p01352 |
<H1>Problem D: Graph Construction</H1>
<p>
<i>n</i> 匹のうさぎがいて, 0 番から<i>n</i> − 1 番の番号がついた小屋に1 匹ずつ住んでいる.
</p>
<p>
あるとき, 秘密の組織によって地下通路の建設工事が行われる, という情報がうさぎたちのもとへ入った. 地下通路を使えば, うさぎたちは他のうさぎたちの小屋へ遊びに行けるようになって嬉しい.
</p>
<p>
通路は両方向に進むことができ, また通路同士は交わらない. 諸事情により, 一度建設された通路が破壊されてしまうこともある. 通路の建設や破壊の工事は1 本ずつ行われ, 各工事中はうさぎは自分の小屋に留まっているものとする.
</p>
<p>
うさぎたちは, 工事のいくつかの段階において, あるうさぎとあるうさぎが遊べるかどうかを事前に知りたい. うさぎたちは仲良しなので, 遊びに行くときに他のうさぎの小屋を自由に通ることができる. プログラミングが好きなうさぎたちは, 昔似たような問題を解いたので簡単だろうと思って挑戦し出したが, なかなか効率の良いプログラムが書けない. うさぎの代わりにこの問題を解け.
</p>
<H2>Input</H2>
<p>
入力の一行目には<i>n</i> と<i>k</i> がスペース区切りで与えられる。2 ≤ <i>n</i> ≤ 40 000, 1 ≤ <i>k</i> ≤ 40 000
</p>
<p>
つづく<i>k</i> 行には工事情報と質問が合わせて, 時間順に与えられる.
</p>
<ul>
<li> “1 <i>u v</i>” — 小屋<i>u</i> と<i>v</i> を結ぶ通路が建設される. 小屋<i>u</i> と<i>v</i> を結ぶ通路がないときにのみ現れる.</li>
<li> “2 <i>u v</i>” — 小屋<i>u</i> と<i>v</i> を結ぶ通路が破壊される. 小屋<i>u</i> と<i>v</i> を結ぶ通路があるときにのみ現れる.</li>
<li> “3 <i>u v</i>” — 小屋<i>u</i> と<i>v</i> のうさぎが遊べるかどうか判定せよ.</li>
</ul>
<p>
0 ≤ <i>u</i> < <i>v</i> < <i>n</i>
</p>
<H2>Output</H2>
<p>
入力に現れる各質問について, 遊べるなら”YES”を, そうでないなら”NO”を1 行ずつ出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
4 10
1 0 1
1 0 2
3 1 2
2 0 1
1 2 3
3 0 1
1 0 1
2 0 2
1 1 3
3 0 2
</pre>
<H2>Sample Output 1</H2>
<pre>
YES
NO
YES
</pre>
|
p03695 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In AtCoder, a person who has participated in a contest receives a <em>color</em>, which corresponds to the person's rating as follows: </p>
<ul>
<li>Rating <var>1</var>-<var>399</var> : gray</li>
<li>Rating <var>400</var>-<var>799</var> : brown</li>
<li>Rating <var>800</var>-<var>1199</var> : green</li>
<li>Rating <var>1200</var>-<var>1599</var> : cyan</li>
<li>Rating <var>1600</var>-<var>1999</var> : blue</li>
<li>Rating <var>2000</var>-<var>2399</var> : yellow</li>
<li>Rating <var>2400</var>-<var>2799</var> : orange</li>
<li>Rating <var>2800</var>-<var>3199</var> : red</li>
</ul>
<p>Other than the above, a person whose rating is <var>3200</var> or higher can freely pick his/her color, which can be one of the eight colors above or not.<br/>
Currently, there are <var>N</var> users who have participated in a contest in AtCoder, and the <var>i</var>-th user has a rating of <var>a_i</var>.<br/>
Find the minimum and maximum possible numbers of different colors of the users. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 100</var></li>
<li><var>1 ≤ a_i ≤ 4800</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 minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2100 2500 2700 2700
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 2
</pre>
<p>The user with rating <var>2100</var> is "yellow", and the others are "orange". There are two different colors. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1100 1900 2800 3200 3200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3 5
</pre>
<p>The user with rating <var>1100</var> is "green", the user with rating <var>1900</var> is blue and the user with rating <var>2800</var> is "red".<br/>
If the fourth user picks "red", and the fifth user picks "blue", there are three different colors. This is one possible scenario for the minimum number of colors.<br/>
If the fourth user picks "purple", and the fifth user picks "black", there are five different colors. This is one possible scenario for the maximum number of colors. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1 1
</pre>
<p>All the users are "green", and thus there is one color.</p></section>
</div>
</span> |
p02987 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a <var>4</var>-character string <var>S</var> consisting of uppercase English letters.
Determine if <var>S</var> consists of exactly two kinds of characters which both appear twice in <var>S</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>S</var> is <var>4</var>.</li>
<li><var>S</var> consists of uppercase 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 <var>S</var> consists of exactly two kinds of characters which both appear twice in <var>S</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>ASSA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><var>S</var> consists of <code>A</code> and <code>S</code> which both appear twice in <var>S</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>STOP
</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>FFEE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>FREE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> |
p00113 |
<h1>循環小数</h1>
<p>
2 つの正の整数 <var>p</var>, <var>q</var> を入力し、 <var>p</var> / <var>q</var> を小数として正確に表現することを考えます。(ただし、0 < <var>p</var> < <var>q</var> < 10<sup>6</sup>とします。)
</p>
<p>
このとき、結果は
</p>
<ul>
<li> 有限の桁で正確に表現できる。</li>
<li>ある桁の範囲を繰り返す循環小数となる。</li>
</ul>
<p>
のいずれかとなります。筆算と同じ手順で1桁ずつ小数部を求めていくと、
</p>
<ul>
<li> 割り切れた(余りが 0 になった)なら、そこまでの桁で正確に表現できた。</li>
<li> 1度出てきた余りが、再び現れたなら、循環した。</li>
</ul>
<p>
と区別できます。
</p>
<p>
2 つの整数 <var>p</var>, <var>q</var> を入力すると、 <var>p</var> / <var>q</var> を小数で表した時の、小数部を出力するプログラムを作成してください。 ただし、
</p>
<ul>
<li> 結果が有限の桁で正確に表現できる時は、数値だけを 1 行に出力してください。</li>
<li> 結果が循環小数になる時は次のように 2 行に出力してください。
<ul>
<li>最初の行に、循環する部分までの数字を出力してください。</li>
<li>次の行には、循環しない部分の下には空白を出力し、循環する部分の下には「^」を出力してください。</li>
</ul>
</li>
<li> いずれの場合も数字列は 80 文字を超えることはないものとします。</li>
</ul>
<H2>Input</H2>
<p>
入力は複数のデータセットからなります。各データセットとして、<var>p</var>, <var>q</var> が空白区切りで1行に与えられます。データセットの数は 250 を超えません。
</p>
<H2>Output</H2>
<p>
データセットごとに、循環しない小数の場合は数値の小数部分を(この場合 1 行)、循環小数の場合は循環するまでの数字と循環する部分を示す記号「^」(この場合 2 行) を出力してください。
</p>
<H2>Sample Input</H2>
<pre>
1 12
10000 32768
1 11100
1 459550
</pre>
<H2>Output for the Sample Input</H2>
<pre>
083
^
30517578125
00009
^^^
00000217604178
^^^^^^^^^^^^
</pre>
|
p00543 |
<h1>ゼッケンの交換 (Swapping Bibs)</h1>
<h2> 問題</h2>
<p>
JOI 高校の N 人の生徒が東西に一列に並んでいる.列の西の端から i 番目の生徒が生徒 i である.それぞれの生徒は整数が 1 つ書かれたゼッケンを付けている.最初,生徒 i のゼッケンには整数 A<sub>i</sub> が書かれている.
</p>
<p>
バトンが M 個あり,バトンには 1 から M までの番号が付けられている.k = 1, 2, ..., M に対し,以下の操作を行う.バトン k (2 ≦ k ≦ M) に関する操作は,バトン k - 1 に関する操作が終わってから行う.
</p>
<ol style="list-style-type: none">
<li>
先生がバトン k を生徒 1 に渡す.
</li>
<li>
バトンを受け取った生徒は,以下のルールに従ってバトンを渡す.
<ul style="list-style-type: disc">
<li>
ルール:生徒 i がバトン k を受け取ったとする.
<ul>
<li> 1 ≦ i ≦ N - 1 のとき: 生徒 i のゼッケンの整数を k で割った余りが,生徒 i + 1 のゼッケンの整数を k で割った余りよりも大きいとき,生徒 i と生徒 i + 1 がゼッケンを交換し,生徒 i は生徒 i + 1 にバトンを渡す.そうでないときは,ゼッケンを交換せずに,生徒 i は生徒 i + 1 にバトンを渡す.</li>
<li> i = N のとき: 生徒 N はバトンを先生に渡す.</li>
</ul>
</ul>
</li>
<li>先生が生徒 N からバトン k を受け取ったら,バトン k に関する操作は終わりである.
</li>
</li>
</ol>
<p>
生徒のゼッケンに最初に書かれていた整数とバトンの個数 M が与えられたとき,先生が生徒 N からバトン M を受け取った後の,それぞれの生徒のゼッケンの整数を求めるプログラムを作成せよ.
</p>
<h2> 入力</h2>
<p>
入力は 1 + N 行からなる.
</p>
<p>
1 行目には整数 N, M (1 ≦ N ≦ 100, 1 ≦ M ≦ 100) が空白を区切りとして書かれており,それぞれ生徒の人数とバトンの個数を表す.
</p>
<p>
続く N 行のうちの i 行目 (1 ≦ i ≦ N) には整数 A<sub>i</sub> (1 ≦ A<sub>i</sub> ≦ 1000) が書かれており,生徒 i のゼッケンに最初に書かれている整数 A<sub>i</sub> を表す.
</p>
<h2> 出力</h2>
<p>
出力は N 行からなる.i 行目 (1 ≦ i ≦ N) には,先生が生徒 N からバトン M を受け取った後の,生徒 i のゼッケンの整数を出力せよ.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
6 4
3
2
8
3
1
5
</pre>
<h3>出力例 1</h3>
<pre>
2
3
1
8
5
3
</pre>
<h3>入力例 2</h3>
<pre>
10 6
1
2
3
4
5
6
7
8
9
10
</pre>
<h3>出力例 2</h3>
<pre>
6
1
2
3
10
4
8
7
9
5
</pre>
<p>
入出力例 1 では 6 人の生徒がいる.最初,生徒のゼッケンは順に 3, 2, 8, 3, 1, 5 である.バトンは 4 個ある.
</p>
<ul>
<li>
バトン 1 に関する操作が終了した時点での生徒のゼッケンは順に 3, 2, 8, 3, 1, 5 である.
</li>
<li>
バトン 2 に関する操作が終了した時点での生徒のゼッケンは順に 2, 8, 3, 3, 1, 5 である.
</li>
<li>
バトン 3 に関する操作が終了した時点での生徒のゼッケンは順に 2, 3, 3, 1, 8, 5 である.
</li>
<li>
バトン 4 に関する操作が終了した時点での生徒のゼッケンは順に 2, 3, 1, 8, 5, 3 である.
</li>
</ul>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2015/2016-yo/index.html">情報オリンピック日本委員会作 『第 15 回日本情報オリンピック JOI 2015/2016 予選競技課題』</a>
</p>
</div> |
p02084 |
<h1>G: Human Seperation</h1>
<h2>問題文</h2>
<p>単位円の上に人が $10^6$ 人、等間隔に立っています。
$t = \frac{2\pi}{10^6}$ として、$i$ 番目の人は 座標 $(\cos{(it)}, \sin{(it)})$ に立っています。</p>
<p>これら $10^6$ 人の中で、非常に仲が悪いペアが $N$ 組あります。
具体的には、$i = 1, \ldots, N$ について、人 $a_i$ と人 $b_i$ は仲が悪いです。</p>
<p>単位円の管理人である松崎くんは、壁を建設することによって仲の悪いペアを全て分断することにしました。
建設する壁は厚さがなく、とてつもなく長いため、直線と同一視することができます。また、壁同士は交わっても構いません。
ただし、人が立っている場所に壁を建設することは出来ません。
壁を建設するにはコストがかかるので、なるべく少ない数の壁で全てのペアを分断したいです。
目的を達成するためには、いくつの壁を建設する必要があるか求めてください。</p>
<p>定式的に問題を言い換えると以下のようになります:</p>
<ul>
<li>2次元平面上に単位円があり、円周上の2点からなるペアが $N$ 組与えられます。</li>
<li>あなたは平面上に任意に直線を置くことができます。</li>
<li>ただし、どの与えられた点も直線上に存在してはいけません。</li>
<li>全てのペアが、いずれかの直線によって分離されるには、直線を最小で何本置く必要があるか求めてください。</li>
</ul>
<p>「2点が直線によって分離されている」とは、2点をどのような曲線で結んでも、曲線が直線と交わる状態を指します。</p>
<h2>制約</h2>
<ul>
<li>入力は全て整数</li>
<li>$1 \leq N \leq 2 \times 10^5$</li>
<li>$0 \leq a_i < b_i < 10^6$</li>
</ul>
<h2>入力</h2>
<p>入力は以下の形式で標準入力から与えられます。</p>
<pre>$N$
$a_1$ $b_1$
$:$
$a_N$ $b_N$</pre>
<h2>出力</h2>
<p>答えを1行に出力してください。</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>1
0 500000
</pre>
<h3>出力例1</h3>
<pre>1
</pre>
<p>円周上の点 $(1, 0)$ と点 $(-1, 0)$ がペアとして与えられます。
ペアは1組しかないので、明らかに1本の直線によって条件を満たすことができます。</p>
<h3>入力例2</h3>
<pre>2
0 333333
333333 666666
</pre>
<h3>出力例2</h3>
<pre>1
</pre>
<h3>入力例3</h3>
<pre>5
0 6
1 2
1 8
3 5
4 10
</pre>
<h3>出力例3</h3>
<pre>2
</pre>
|
p02591 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Inspired by the tv series <em>Stranger Things</em>, bear Limak is going for a walk between two mirror worlds.</p>
<p>There are two perfect binary trees of height <var>H</var>,
each with the standard numeration of vertices from <var>1</var> to <var>2^H-1</var>.
The root is <var>1</var> and the children of <var>x</var> are <var>2 \cdot x</var> and <var>2 \cdot x + 1</var>.</p>
<p>Let <var>L</var> denote the number of leaves in a single tree, <var>L = 2^{H-1}</var>.</p>
<p>You are given a permutation <var>P_1, P_2, \ldots, P_L</var> of numbers <var>1</var> through <var>L</var>.
It describes <var>L</var> <em>special</em> edges that connect leaves of the two trees.
There is a special edge between vertex <var>L+i-1</var> in the first tree and vertex <var>L+P_i-1</var> in the second tree.</p>
<p align="center"><img alt="graph for sample1" src="https://img.atcoder.jp/agc047/nice_wide_example.png"/></p>
<p align="center"><em>drawing for the first sample test, permutation <var>P = (2, 3, 1, 4)</var>, special edges in green</em></p>
<p>Let's define <em>product</em> of a cycle as the product of numbers in its vertices.
Compute the sum of products of all simple cycles that have <strong>exactly two special edges</strong>, modulo <var>(10^9+7)</var>.</p>
<p>A simple cycle is a cycle of length at least 3, without repeated vertices or edges.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq H \leq 18</var></li>
<li><var>1 \leq P_i \leq L</var> where <var>L = 2^{H-1}</var></li>
<li><var>P_i \neq P_j</var> (so this is a permutation)</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 (where <var>L = 2^{H-1}</var>).</p>
<pre><var>H</var>
<var>P_1</var> <var>P_2</var> <var>\cdots</var> <var>P_L</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Compute the sum of products of simple cycles that have exactly two special edges.
Print the answer modulo <var>(10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 3 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>121788
</pre>
<p>The following drawings show two valid cycles (but there are more!) with products
<var>2 \cdot 5 \cdot 6 \cdot 3 \cdot 1 \cdot 2 \cdot 5 \cdot 4 = 7200</var>
and <var>1 \cdot 3 \cdot 7 \cdot 7 \cdot 3 \cdot 1 \cdot 2 \cdot 5 \cdot 4 \cdot 2 = 35280</var>.
The third cycle is invalid because it doesn't have exactly two special edges.</p>
<p align="center"><img alt="three cycles" src="https://img.atcoder.jp/agc047/3_trees_font.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>36
</pre>
<p>The only simple cycle in the graph indeed has two special edges, and the product of vertices is
<var>1 \cdot 3 \cdot 3 \cdot 1 \cdot 2 \cdot 2 = 36</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
6 14 15 7 12 16 5 4 11 9 3 10 8 2 13 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10199246
</pre></section>
</div>
</span> |
p00056 |
<H1>ゴールドバッハの予想</H1>
<p>
4 以上の偶数は 2 つの素数の和で表すことができるということが知られています。これはゴールドバッハ予想といい、コンピュータの計算によりかなり大きな数まで正しいことが確かめられています。例えば、10 は、7 + 3、5 + 5 の 2 通りの素数の和で表すことができます。
</p>
<p>
整数 <var>n</var> を入力し、<var>n</var> を 2 つの素数の和で表す組み合わせ数が何通りあるかを出力するプログラムを作成してください。ただし、<var>n</var> は 4 以上、50,000 以下とします。また、入力される <var>n</var> は偶数であるとはかぎりません。
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。各データセットに <var>n</var> が1行に与えられます。<var>n</var> が 0 のとき入力の最後とします。データセットの数は 10,000 を超えません。
</p>
<H2>Output</H2>
<p>
各データセットに対して、<var>n</var> を 2 つの素数の和で表す組み合わせ数を1行に出力して下さい。
</p>
<H2>Sample Input</H2>
<pre>
10
11
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
0
</pre>
|
p00406 | <h1>矢印</h1>
<p>
$L$個のマスが左右に一列に並んでいます。いくつかのマスの上に駒が置いてあります。駒には左向きか右向きの矢印が書いてあります。なお、一つのマスに二つ以上の駒を置くことはできません。
</p>
<p>
どのマスにいる駒も、駒が置かれていないマスに動かすことができます。ただし、一度に動けるのは隣のマスまでで、一度に動かせるのは一つの駒だけです。駒は、矢印の向きにかかわらず、左にも右にも動かすことができます。ただし、駒を矢印の方向に一回動かすと点数が1点もらえますが、矢印とは逆方向に一回動かすと1点減点されてしまいます。なお、どのような状況から始めたとしても、得られる点数には必ず最大値があることがわかっています。
</p>
<p>
マスの個数と駒の状況が与えられたとき、得られる最大の点数を計算するプログラムを作成せよ。ただし、マスには列の左端から順番に1から$L$までの番号が割り当てられているものとする。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
$N$ $L$
$p_1$ $d_1$
$p_2$ $d_2$
:
$p_N$ $d_N$
</pre>
<p>
1行目に駒の数$N$ ($1 \leq N \leq 10^5$)とマスの数$L$ ($N \leq L \leq 10^9$)が与えられる。続く$N$行に駒が置かれたマスの番号$p_i$ ($1 \leq p_i \leq L$)と駒に書かれた矢印の向き$d_i$ (0または1)が与えられる。ただし、$d_i$が0のときは矢印が左向き、1のときは右向きを表す。同じマスの番号は与えられない($i \ne j$について、$p_i \ne p_j$)。
</p>
<h2>出力</h2>
<p>
得られる最大の点数を1行に出力する。
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
2 10
3 0
6 1
</pre>
<h3>出力例1</h3>
<pre>
6
</pre>
<h3>入力例2</h3>
<pre>
2 8
2 1
8 0
</pre>
<h3>出力例2</h3>
<pre>
5
</pre>
<h3>入力例3</h3>
<pre>
2 8
1 0
8 1
</pre>
<h3>出力例3</h3>
<pre>
0
</pre>
|
p03380 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>{\rm comb}(n,r)</var> be the number of ways to choose <var>r</var> objects from among <var>n</var> objects, disregarding order.
From <var>n</var> non-negative integers <var>a_1, a_2, ..., a_n</var>, select two numbers <var>a_i > a_j</var> so that <var>{\rm comb}(a_i,a_j)</var> is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq n \leq 10^5</var></li>
<li><var>0 \leq a_i \leq 10^9</var></li>
<li><var>a_1,a_2,...,a_n</var> are pairwise distinct.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>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 <var>a_i</var> and <var>a_j</var> that you selected, with a space in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
6 9 4 2 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11 6
</pre>
<p><var>\rm{comb}(a_i,a_j)</var> for each possible selection is as follows:</p>
<ul>
<li><var>\rm{comb}(4,2)=6</var> </li>
<li><var>\rm{comb}(6,2)=15</var> </li>
<li><var>\rm{comb}(6,4)=15</var> </li>
<li><var>\rm{comb}(9,2)=36</var> </li>
<li><var>\rm{comb}(9,4)=126</var> </li>
<li><var>\rm{comb}(9,6)=84</var> </li>
<li><var>\rm{comb}(11,2)=55</var> </li>
<li><var>\rm{comb}(11,4)=330</var> </li>
<li><var>\rm{comb}(11,6)=462</var> </li>
<li><var>\rm{comb}(11,9)=55</var></li>
</ul>
<p>Thus, we should print <var>11</var> and <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
100 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100 0
</pre></section>
</div>
</span> |
p01647 |
<h2>Problem Statement</h2>
<p>
<i>Texas hold 'em</i> is one of the standard poker games, originated in Texas, United States.
It is played with a standard deck of 52 cards, which has 4 <i>suits</i> (spades, hearts, diamonds and clubs) and 13 <i>ranks</i> (A, K, Q, J and 10-2), without jokers.
</p>
<p>
With betting aside, a game goes as described below.
</p>
<p>
At the beginning each player is dealt with two cards face down.
These cards are called <i>hole cards</i> or <i>pocket cards</i>, and do not have to be revealed until the showdown.
Then the dealer deals three cards face up as <i>community cards</i>, i.e. cards shared by all players.
These three cards are called the <i>flop</i>.
The flop is followed by another community card called the <i>turn</i> then one more community card called the <i>river</i>.
</p>
<p>
After the river, the game goes on to the <i>showdown</i>.
All players reveal their hole cards at this point.
Then each player chooses five out of the seven cards, i.e. their two hole cards and the five community cards, to form a <i>hand</i>.
The player forming the strongest hand wins the game.
There are ten possible kinds of hands, listed from the strongest to the weakest:
</p>
<ul>
<li> <i>Royal straight flush</i>: A, K, Q, J and 10 of the same suit. This is a special case of straight flush.</li>
<li> <i>Straight flush</i>: Five cards in sequence (e.g. 7, 6, 5, 4 and 3) and of the same suit.</li>
<li> <i>Four of a kind</i>: Four cards of the same rank.</li>
<li> <i>Full house</i>: Three cards of the same rank, plus a pair of another rank.</li>
<li> <i>Flush</i>: Five cards of the same suit, but not in sequence.</li>
<li> <i>Straight</i>: Five cards in sequence, but not of the same suit.</li>
<li> <i>Three of a kind</i>: Just three cards of the same rank.</li>
<li> <i>Two pairs</i>: Two cards of the same rank, and two other cards of another same rank.</li>
<li> <i>One pair</i>: Just a pair of cards (two cards) of the same rank.</li>
<li> <i>High card</i>: Any other hand.</li>
</ul>
<p>
For the purpose of a sequence, J, Q and K are treated as 11, 12 and 13 respectively.
A can be seen as a rank either next above K or next below 2, thus both A-K-Q-J-10 and 5-4-3-2-A are possible (but not 3-2-A-K-Q or the likes).
</p>
<p>
If more than one player has the same kind of hand, ties are broken by comparing the ranks of the cards.
The basic idea is to compare first those forming sets (pairs, triples or quads) then the rest cards one by one from the highest-ranked to the lowest-ranked, until ties are broken.
More specifically:
</p>
<ul>
<li> <i>Royal straight flush</i>: (ties are not broken)</li>
<li> <i>Straight flush</i>: Compare the highest-ranked card.</li>
<li> <i>Four of a kind</i>: Compare the four cards, then the remaining one.</li>
<li> <i>Full house</i>: Compare the three cards, then the pair.</li>
<li> <i>Flush</i>: Compare all cards one by one.</li>
<li> <i>Straight</i>: Compare the highest-ranked card.</li>
<li> <i>Three of a kind</i>: Compare the three cards, then the remaining two.</li>
<li> <i>Two pairs</i>: Compare the higher-ranked pair, then the lower-ranked, then the last one.</li>
<li> <i>One pair</i>: Compare the pair, then the remaining three.</li>
<li> <i>High card</i>: Compare all cards one by one.</li>
</ul>
<p>
The order of the ranks is A, K, Q, J, 10, 9, ..., 2, from the highest to the lowest,
except for A next to 2 in a straight regarded as lower than 2.
Note that there are exceptional cases where ties remain.
Also note that the suits are not considered at all in tie-breaking.
</p>
<p>
Here are a few examples of comparison (note these are only intended for explanatory purpose; some combinations cannot happen in Texas Hold 'em):
</p>
<ul>
<li><p>J-J-J-6-3 and K-K-Q-Q-8.</p></li>
</ul>
<p>
The former beats the latter since three of a kind is stronger than two pairs.
</p>
<ul>
<li><p>J-J-J-6-3 and K-Q-8-8-8.</p></li>
</ul>
<p>
Since both are three of a kind, the triples are considered first, J and 8 in this case.
J is higher, hence the former is a stronger hand.
The remaining cards, 6-3 and K-Q, are not considered as the tie is already broken.
</p>
<ul>
<li><p>Q-J-8-6-3 and Q-J-8-5-3.</p></li>
</ul>
<p>
Both are high cards, assuming hands not of a single suit (i.e. flush).
The three highest-ranked cards Q-J-8 are the same, so the fourth highest are compared.
The former is stronger since 6 is higher than 5.
</p>
<ul>
<li><p>9-9-Q-7-2 and 9-9-J-8-5.</p></li>
</ul>
<p>
Both are one pair, with the pair of the same rank (9).
So the remaining cards, Q-7-2 and J-8-5, are compared from the highest to the lowest,
and the former wins as Q is higher than J.
</p>
<p>
Now suppose you are playing a game of Texas Hold 'em with one opponent, and the hole cards and the flop have already been dealt.
You are surprisingly telepathic and able to know the cards the opponent has.
Your ability is not, however, as strong as you can predict which the turn and the river will be.
</p>
<p>
Your task is to write a program that calculates the probability of your winning the game,
assuming the turn and the river are chosen uniformly randomly from the remaining cards.
You and the opponent always have to choose the hand strongest possible.
Ties should be included in the calculation, i.e. should be counted as losses.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets, each of which has the following format:
</p>
<pre>
<var>YourCard_1</var> <var>YourCard_2</var>
<var>OpponentCard_1</var> <var>OpponentCard_2</var>
<var>CommunityCard_1</var> <var>CommunityCard_2</var> <var>CommunityCard_3</var>
</pre>
<p>
Each dataset consists of three lines.
The first and second lines contain the hole cards of yours and the opponent's respectively.
The third line contains the flop, i.e. the first three community cards.
These cards are separated by spaces.
</p>
<p>
Each card is represented by two characters.
The first one indicates the suit: <code>S</code> (spades), <code>H</code> (hearts), <code>D</code> (diamonds) or <code>C</code> (clubs).
The second one indicates the rank: <code>A</code>, <code>K</code>, <code>Q</code>, <code>J</code>, <code>T</code> (10) or <code>9</code>-<code>2</code>.
</p>
<p>
The end of the input is indicated by a line with <code>#</code>.
This should not be processed.
</p>
<h2>Output</h2>
<p>
Print the probability in a line.
The number may contain an arbitrary number of digits after the decimal point,
but should not contain an absolute error greater than <var>10^{-6}</var>.
</p>
<h2>Sample Input</h2>
<pre>
SA SK
DA CA
SQ SJ ST
SA HA
D2 C3
H4 S5 DA
HA D9
H6 C9
H3 H4 H5
#
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1.00000000000000000000
0.34444444444444444198
0.63030303030303025391
</pre>
|
p00955 |
<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 J
Cover the Polygon with Your Disk
</h2>
<p>
A convex polygon is drawn on a flat paper sheet. You are trying to place a disk in your hands to cover as large area of the polygon as possible. In other words, the intersection area of the polygon and the disk should be maximized.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case, formatted as follows. All input items are integers.<br/>
<br/>
$n$ $r$<br/>
$x_1$ $y_1$<br/>
.<br/>
.<br/>
.<br/>
$x_n$ $y_n$<br/>
</p>
<p>
$n$ is the number of vertices of the polygon ($3 \leq n \leq 10$). $r$ is the radius of the disk ($1 \leq r \leq 100$).
$x_i$ and $y_i$ give the coordinate values of the $i$-th vertex of the polygon ($1 \leq i \leq n$). Coordinate values satisfy $0 \leq x_i \leq 100$ and $0 \leq y_i \leq 100$.
</p>
<p>
The vertices are given in counterclockwise order. As stated above, the given polygon is convex. In other words, interior angles at all of its vertices are less than 180$^{\circ}$. Note that the border of a convex polygon never crosses or touches itself.
</p>
<h3>Output</h3>
<p>
Output the largest possible intersection area of the polygon and the disk. The answer should not have an error greater than 0.0001 ($10^{-4}$).
</p>
<h3>Sample Input 1</h3>
<pre>4 4
0 0
6 0
6 6
0 6</pre>
<h3>Sample Output 1</h3>
<pre>35.759506</pre>
<br/>
<h3>Sample Input 2</h3>
<pre>3 1
0 0
2 1
1 3</pre>
<h3>Sample Output 2</h3>
<pre>2.113100</pre>
<br/>
<h3>Sample Input 3</h3>
<pre>3 1
0 0
100 1
99 1</pre>
<h3>Sample Output 3</h3>
<pre>0.019798</pre>
<br/>
<h3>Sample Input 4</h3>
<pre>4 1
0 0
100 10
100 12
0 1</pre>
<h3>Sample Output 4</h3>
<pre>3.137569</pre>
<br/>
<h3>Sample Input 5</h3>
<pre>10 10
0 0
10 0
20 1
30 3
40 6
50 10
60 15
70 21
80 28
90 36</pre>
<h3>Sample Output 5</h3>
<pre>177.728187</pre>
<br/>
<h3>Sample Input 6</h3>
<pre>10 49
50 0
79 10
96 32
96 68
79 90
50 100
21 90
4 68
4 32
21 10</pre>
<h3>Sample Output 6</h3>
<pre>7181.603297</pre>
|
p02968 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>N</var>.
How many permutations <var>(P_0,P_1,\cdots,P_{2N-1})</var> of <var>(0,1,\cdots,2N-1)</var> satisfy the following condition?</p>
<ul>
<li>For each <var>i</var> <var>(0 \leq i \leq 2N-1)</var>, <var>N^2 \leq i^2+P_i^2 \leq (2N)^2</var> holds.</li>
</ul>
<p>Since the number can be enormous, compute it modulo <var>M</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 250</var></li>
<li><var>2 \leq M \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>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of permutations that satisfy the condition, modulo <var>M</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Four permutations satisfy the condition:</p>
<ul>
<li><var>(2,3,0,1)</var></li>
<li><var>(2,3,1,0)</var></li>
<li><var>(3,2,0,1)</var></li>
<li><var>(3,2,1,0)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>53999264
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>200 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>112633322
</pre></section>
</div>
</span> |
p04015 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Tak has <var>N</var> cards. On the <var>i</var>-th <var>(1 \leq i \leq N)</var> card is written an integer <var>x_i</var>.
He is selecting one or more cards from these <var>N</var> cards, so that the average of the integers written on the selected cards is exactly <var>A</var>.
In how many ways can he make his selection?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>1 \leq A \leq 50</var></li>
<li><var>1 \leq x_i \leq 50</var></li>
<li><var>N,\,A,\,x_i</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded for passing the test set satisfying <var>1 \leq N \leq 16</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to select cards such that the average of the written integers is exactly <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 8
7 9 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<ul>
<li>The following are the <var>5</var> ways to select cards such that the average is <var>8</var>:<ul>
<li>Select the <var>3</var>-rd card.</li>
<li>Select the <var>1</var>-st and <var>2</var>-nd cards.</li>
<li>Select the <var>1</var>-st and <var>4</var>-th cards.</li>
<li>Select the <var>1</var>-st, <var>2</var>-nd and <var>3</var>-rd cards.</li>
<li>Select the <var>1</var>-st, <var>3</var>-rd and <var>4</var>-th cards.</li>
</ul>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 8
6 6 9
</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>8 5
3 6 2 8 7 6 5 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>19
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>8589934591
</pre>
<ul>
<li>The answer may not fit into a <var>32</var>-bit integer.</li>
</ul></section>
</div>
</span> |
p01217 |
<H1><font color="#000">Problem B:</font> Jaggie Spheres</H1>
<p>
Let <i>J</i>(<i>n</i>) be a three-dimensional body that
</p>
<ul>
<li> is a union of unit cubes whose all vertices lie on integer coordinates,</li>
<li> contains all points that are closer than the distance of √<i>n</i> to the origin, and</li>
<li> is the smallest of all such bodies.</li>
</ul>
<p>
The figure below shows how <i>J</i>(1), <i>J</i>(2), and <i>J</i>(3) look.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_jaggieSpheres">
<p>Figure 1: Jaggie Spheres for <i>n</i> = 1, 2, 3</p>
</center>
<p>
Your task is to calculate how many faces <i>J</i>(<i>n</i>) have. Here, we define two square belong to the same face
if they are parallel and share an edge, but don’t if they share just a vertex.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets, each of which comes with a single line containing an integer <i>n</i>
(1 ≤ <i>n</i> ≤ 1000000). The end of input is indicated by <i>n</i> = 0.
</p>
<H2>Output</H2>
<p>
For each data set, print the number of faces <i>J</i>(<i>n</i>) have.
</p>
<H2>Sample Input</H2>
<pre>
1
2
3
4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6
30
30
6
</pre>
|
p01539 |
<h1>全探索お姉さんの休日</h1>
<p>
全探索お姉さんはとても優秀な女性である。
お姉さんは格子状の道の経路の数え上げを数千程度なら簡単に数え上げてしまう。
あなたと全探索お姉さんは今、六角形のタイルが敷き詰められた部屋にいる。
お姉さんは初めて見る六角形にとても興奮している様子である。
六角形の並びを座標に表すことに不慣れなお姉さんは図1のような座標系で部屋を表した。
</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_rokkaku" height="305" width="247"></center>
<center>図1</center>
<p>
あなたはこの座標系上である地点からある地点まで移動したい。
しかし、お姉さんは 1 分ごとに動きたい方向をあなたに指示する。
いつものお姉さんなら同じ座標の場所を通らないようにあなたに移動の指示を出すだろう。
しかし、この座標系に不慣れなお姉さんは<var>|x×y×t|</var>(<var>x</var>:<var>x</var> 座標、<var>y</var>:<var>y</var>座標、<var>t</var>:最初の指示からの経過時間[分])を 6 で割った余り
に対応する方向(図で示す番号と対応)を指示するだけで、まったくのでたらめな方向にあなたを誘導する。
</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_dir" height="285" width="238"></center>
<center>図2</center>
<p>
お姉さんを傷つけたくないあなたは、お姉さんの指示をできるだけ守りつつ目的地までたどり着きたい。
あなたは許された行動は下の 7 つの行動である。
</p>
<ul>
<li>方向 0 へ 1 タイル移動
</li><li>方向 1 へ 1 タイル移動
</li><li>方向 2 へ 1 タイル移動
</li><li>方向 3 へ 1 タイル移動
</li><li>方向 4 へ 1 タイル移動
</li><li>方向 5 へ 1 タイル移動
</li><li>その場に留まる
</li></ul>
<p>
お姉さんが指示を出した直後にあなたはこれら行動のうちの必ず1つを行う。
部屋には家具があり家具が配置されているタイルの中に移動することはできない。
また、<var>y</var> 座標の絶対値が <var>ly</var> を超えたり <var>x</var> 座標の絶対値が <var>lx</var> を超えるような移動は許されていない。
しかし、お姉さんはそのような移動を指示することがある。
指示を無視するとはお姉さんが示した方向と異なる方向へ移動するか、
もしくは、その場に留まることである。
目的地にたどり着くために最小で何度指示を無視すれば良いかを出力せよ。
目的地にたどり着くことが不可能な場合は -1 を出力せよ。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<blockquote>
<var>sx</var> <var>sy</var> <var>gx</var> <var>gy</var><br><var>n</var><br><var>x<sub>1</sub></var> <var>y<sub>1</sub></var><br>...<br><var>x<sub>i</sub></var> <var>y<sub>i</sub></var><br>...<br><var>x<sub>n</sub></var> <var>y<sub>n</sub></var><br><var>lx</var> <var>ly</var><br></blockquote>
<p>
ここで、
</p>
<ul>
<li><var>sx</var>, <var>sy</var> は出発地点の座標
</li><li><var>gx</var>, <var>gy</var> は目的地の座標
</li><li><var>n</var> は部屋に配置されている家具の数
</li><li><var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> は家具があるタイルの座標
</li><li><var>lx</var>, <var>ly</var> は移動できる <var>X</var>, <var>Y</var> それぞれの座標の絶対値の上限
である。
</li></ul>
<h2>Constraints</h2>
<ul>
<li>入力はすべて整数
</li><li> <var>-lx ≤ sx</var>, <var>gx ≤ lx</var>
</li><li> <var>-ly ≤ sy</var>, <var>gy ≤ ly</var>
</li><li> <var>(sx, sy) ≠ (gx, gy)</var>
</li><li> <var>(xi, yi) ≠ (sx, sy)(1≤i≤n)</var>
</li><li> <var>(xi, yi) ≠ (gx, gy)(1≤i≤n)</var>
</li><li> <var>(xi, yi) ≠ (xj, yj)(i ≠ j)</var>
</li><li> <var>0≤ n ≤ 1000</var>
</li><li> <var>-lx ≤ xi ≤ lx (1≤i≤n)</var>
</li><li> <var>-ly ≤ yi ≤ ly (1≤i≤n)</var>
</li><li> <var>0 < lx, ly ≤ 100</var>
</li></ul>
<h2>Output</h2>
<p>
出力は1つの整数を含む1行で出力せよ。
目的地にたどり着ける場合は、最小の指示を無視する回数を出力せよ。
目的地にたどり着くことが不可能な場合は-1を出力せよ。
</p>
<H2>Sample Input 1</H2>
<pre>0 0 0 2
0
2 2
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>0
</pre>
<H2>Sample Input 2</H2>
<pre>0 0 0 2
6
0 1
1 0
1 -1
0 -1
-1 -1
-1 0
2 2
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>-1
</pre>
<H2>Sample Input 3</H2>
<pre>0 0 0 2
1
0 1
2 2
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>1
</pre>
|
p03504 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino is planning to record <var>N</var> TV programs with recorders.</p>
<p>The TV can receive <var>C</var> channels numbered <var>1</var> through <var>C</var>.</p>
<p>The <var>i</var>-th program that she wants to record will be broadcast from time <var>s_i</var> to time <var>t_i</var> (including time <var>s_i</var> but not <var>t_i</var>) on Channel <var>c_i</var>.</p>
<p>Here, there will never be more than one program that are broadcast on the same channel at the same time.</p>
<p>When the recorder is recording a channel from time <var>S</var> to time <var>T</var> (including time <var>S</var> but not <var>T</var>), it cannot record other channels from time <var>S-0.5</var> to time <var>T</var> (including time <var>S-0.5</var> but not <var>T</var>).</p>
<p>Find the minimum number of recorders required to record the channels so that all the <var>N</var> programs are completely recorded.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N≤10^5</var></li>
<li><var>1≤C≤30</var></li>
<li><var>1≤s_i<t_i≤10^5</var></li>
<li><var>1≤c_i≤C</var></li>
<li>If <var>c_i=c_j</var> and <var>i≠j</var>, either <var>t_i≤s_j</var> or <var>s_i≥t_j</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>C</var>
<var>s_1</var> <var>t_1</var> <var>c_1</var>
<var>:</var>
<var>s_N</var> <var>t_N</var> <var>c_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>When the minimum required number of recorders is <var>x</var>, print the value of <var>x</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 7 2
7 8 1
8 12 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Two recorders can record all the programs, for example, as follows:</p>
<ul>
<li>With the first recorder, record Channel <var>2</var> from time <var>1</var> to time <var>7</var>. The first program will be recorded. Note that this recorder will be unable to record other channels from time <var>0.5</var> to time <var>7</var>.</li>
<li>With the second recorder, record Channel <var>1</var> from time <var>7</var> to time <var>12</var>. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time <var>6.5</var> to time <var>12</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4
1 3 2
3 4 4
1 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>There may be a channel where there is no program to record.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9 4
56 60 4
33 37 2
89 90 3
32 43 1
67 68 3
49 51 3
31 32 3
70 71 1
11 12 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> |
p01169 |
<H1><font color="#000">Problem G:</font> Turn Polygons</H1>
<p>
HCII, the health committee for interstellar intelligence, aims to take care of the health of every
interstellar intelligence.
</p>
<p>
Staff of HCII uses a special equipment for health checks of patients. This equipment looks like a
polygon-shaped room with plenty of instruments. The staff puts a patient into the equipment,
then the equipment rotates clockwise to diagnose the patient from various angles. It fits many
species without considering the variety of shapes, but not suitable for big patients. Furthermore,
even if it fits the patient, it can hit the patient during rotation.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_turnPolygons">
<p>Figure 1: The Equipment used by HCII</p>
</center>
<p>
The interior shape of the equipment is a polygon with <i>M</i> vertices, and the shape of patients
is a <i>convex</i> polygon with <i>N</i> vertices. Your job is to calculate how much you can rotate the
equipment clockwise without touching the patient, and output the angle in degrees.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets, followed by a line containing “0 0”. Each data set is
given as follows:
</p>
<pre>
<i>M N</i>
<i>px</i><sub>1</sub> <i>py</i><sub>1</sub> <i>px</i><sub>2</sub> <i>py</i><sub>2</sub> ... <i>px<sub>M</sub> py<sub>M</sub></i>
<i>qx</i><sub>1</sub> <i>qy</i><sub>1</sub> <i>qx</i><sub>2</sub> <i>qy</i><sub>2</sub> ... <i>qx<sub>N</sub> qy<sub>N</sub></i>
<i>cx cy</i>
</pre>
<p>
The first line contains two integers <i>M</i> and <i>N</i> (3 ≤ <i>M, N</i> ≤ 10). The second line contains 2<i>M</i>
integers, where (<i>px<sub>j</sub></i> , <i>py<sub>j</sub></i> ) are the coordinates of the <i>j</i>-th vertex of the equipment. The third
line contains 2<i>N</i> integers, where (<i>qx<sub>j</sub></i> , <i>qy<sub>j</sub></i> ) are the coordinates of the <i>j</i>-th vertex of the patient.
The fourth line contains two integers <i>cx</i> and <i>cy</i>, which indicate the coordinates of the center of
rotation.
</p>
<p>
All the coordinates are between -1000 and 1000, inclusive. The vertices of each polygon are
given in counterclockwise order.
</p>
<p>
At the initial state, the patient is inside the equipment, and they don’t intersect each other.
You may assume that the equipment doesn’t approach patients closer than 10<sup>-6</sup> without hitting
patients, and that the equipment gets the patient to stick out by the length greater than 10<sup>-6</sup>
whenever the equipment keeps its rotation after hitting the patient.
</p>
<H2>Output</H2>
<p>
For each data set, print the angle in degrees in a line. Each angle should be given as a decimal
with an arbitrary number of fractional digits, and with an absolute error of at most 10<sup>-7</sup> .
</p>
<p>
If the equipment never hit the patient during the rotation, print 360 as the angle.
</p>
<H2>Sample Input</H2>
<pre>
5 4
0 0 20 0 20 10 0 10 1 5
10 3 12 5 10 7 8 5
10 5
4 3
0 0 10 0 10 5 0 5
3 1 6 1 5 4
0 0
5 3
0 0 10 0 10 10 0 10 3 5
1 1 4 1 4 6
0 0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
360.0000000
12.6803835
3.3722867
</pre>
|
p03154 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a rectangular sheet of paper with height <var>H+1</var> and width <var>W+1</var>. We introduce an <var>xy</var>-coordinate system so that the four corners of the sheet are <var>(0, 0)</var>, <var>(W + 1, 0)</var>, <var>(0, H + 1)</var> and <var>(W + 1, H + 1)</var>.</p>
<p>This sheet can be cut along the lines <var>x = 1,2,...,W</var> and the lines <var>y = 1,2,...,H</var>. Consider a sequence of operations of length <var>K</var> where we choose <var>K</var> of these <var>H + W</var> lines and cut the sheet along those lines one by one in some order.</p>
<p>Let the score of a cut be the number of pieces of paper that exist just after the cut. The score of a sequence of operations is the sum of the scores of all of the <var>K</var> cuts.</p>
<p>Find the sum of the scores of all possible sequences of operations of length <var>K</var>. Since this value can be extremely large, print the number modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 10^7</var></li>
<li><var>1 \leq K \leq H + W</var></li>
<li><var>H, W</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>H</var> <var>W</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the scores, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>34
</pre>
<p>Let <var>x_1</var>, <var>y_1</var> and <var>y_2</var> denote the cuts along the lines <var>x = 1</var>, <var>y = 1</var> and <var>y = 2</var>, respectively. The six possible sequences of operations and the score of each of them are as follows:</p>
<ul>
<li><var>y_1, y_2</var>: <var>2 + 3 = 5</var></li>
<li><var>y_2, y_1</var>: <var>2 + 3 = 5</var></li>
<li><var>y_1, x_1</var>: <var>2 + 4 = 6</var></li>
<li><var>y_2, x_1</var>: <var>2 + 4 = 6</var></li>
<li><var>x_1, y_1</var>: <var>2 + 4 = 6</var></li>
<li><var>x_1, y_2</var>: <var>2 + 4 = 6</var></li>
</ul>
<p>The sum of these is <var>34</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>30 40 50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>616365902
</pre>
<p>Be sure to print the sum modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p01493 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem H:
DisconnectedGame
</h2>
<p>
Taro と Hanako がゲームをしている.
</p>
<p>
最初に, 非連結な無向グラフ(二重辺や self loop を含まない) が与えられる. Taro と Hanako は交互に操作を行う. 操作では, 辺で直接つながれていない異なる2 頂点を選び, その間に辺を加える. グラフを連結にしたほうが負けである.
</p>
<p>
グラフには $V$ 個の頂点がある. $V \times V$ の行列が与えられる. 行列の $(i, j)$-成分が'Y' であるとき $i$ と $j$ の間には辺があり, 'N' であるときは辺が無い.
</p>
<p>
両者が最善に操作をしたとき, どちらが勝つかを出力せよ.
</p>
<h3>Constraints</h3>
<ul>
<li>$V$ will be between 2 and 1,000, inclusive.</li>
<li>$a_{i,i}$ will be 'N'.</li>
<li>$a_{i,j}$ will be 'Y' or 'N'.</li>
<li>$a_{i,j}$ will be equal to $a_{j,i}$.</li>
<li>The graph will not be connected.</li>
</ul>
<h3>Input</h3>
<p>
入力は以下の形式で与えられる:<br>
<br>
$V$<br>
$a_{1,1}$ ... $a_{1,V}$<br>
...<br>
$a_{V,1}$ ... $a_{V,V}$<br>
</p>
<h3>Output</h3>
<p>
Taro が勝つ場合には "Taro" (quotes for clarity), Hanako が勝つ場合には "Hanako" (quotes for clarity) と 1 行に出力せよ.
</p>
<h3>Sample Input 1</h3>
<pre>3
NNN
NNN
NNN</pre>
<h3>Sample Output 1</h3>
<pre>Taro</pre>
<h3>Sample Input 2</h3>
<pre>5
NNYNN
NNNNN
YNNNN
NNNNY
NNNYN</pre>
<h3>Sample Output 2</h3>
<pre>Hanako</pre>
<h3>Sample Input 3</h3>
<pre>8
NYNNNNNN
YNNYNNYN
NNNNNNNY
NYNNNNYN
NNNNNNNN
NNNNNNNN
NYNYNNNN
NNYNNNNN</pre>
<h3>Sample Output 3</h3>
<pre>Taro</pre> |
p02315 |
<H1>0-1 Knapsack Problem</H1>
<br/>
<p>
You have <var>N</var> items that you want to put them into a knapsack. Item <var>i</var> has value <var>v<sub>i</sub></var> and weight <var>w<sub>i</sub></var>.
</p>
<p>
You want to find a subset of items to put such that:
</p>
<ul>
<li>The total value of the items is as large as possible.</li>
<li>The items have combined weight at most <var>W</var>, that is capacity of the knapsack.</li>
</ul>
<p>
Find the maximum total value of items in the knapsack.
</p>
<H2>Input</H2>
<pre>
<var>N</var> <var>W</var>
<var>v<sub>1</sub></var> <var>w<sub>1</sub></var>
<var>v<sub>2</sub></var> <var>w<sub>2</sub></var>
:
<var>v<sub>N</sub></var> <var>w<sub>N</sub></var>
</pre>
<p>
The first line consists of the integers <var>N</var> and <var>W</var>. In the following lines, the value and weight of the <var>i</var>-th item are given.
</p>
<H2>Output</H2>
<p>
Print the maximum total values of the items in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>N</var> ≤ 100</li>
<li> 1 ≤ <var>v<sub>i</sub></var> ≤ 1000</li>
<li> 1 ≤ <var>w<sub>i</sub></var> ≤ 1000</li>
<li> 1 ≤ <var>W</var> ≤ 10000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 5
4 2
5 2
2 1
8 3
</pre>
<H2>Sample Output 1</H2>
<pre>
13
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
2 20
5 9
4 10
</pre>
<H2>Sample Output 2</H2>
<pre>
9
</pre> |
p00328 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>線分配置</H1>
<p>
A大学は今年もプログラミングコンテストを開催する。作題チームの一員であるあなたは、計算幾何学の問題の入力データの作成を担当することになった。あなたが作りたい入力データは、<var>x</var> 軸または <var>y</var> 軸に平行で、互いに触れ合うことのない線分の集合である。あなたは、次のアルゴリズムに基づいたデータ生成プログラムを開発して、入力データを生成する。
</p>
<ol>
<li> <var>xy</var> 平面上の線分の集合 <var>T</var> を空にする。</li>
<li> 次の処理を <var>N</var> 回繰り返す。
<ul>
<li><var>x</var> 軸または <var>y</var> 軸に平行な適当な線分 <var>s</var> を作る。</li>
<li><var>s</var> が <var>T</var> 内のどの線分にも触れない場合は <var>s</var> を <var>T</var> に追加し、触れる場合は <var>s</var> を追加しない。</li>
</ul>
</li>
</ol>
<p>
<var>x</var> 軸または <var>y</var> 軸に平行な <var>N</var> 本の線分を順番に入力し、各線分が平面上に追加されるかどうかを判定するプログラムを作成せよ。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var>
<var>px<sub>1</sub></var> <var>py<sub>1</sub></var> <var>qx<sub>1</sub></var> <var>qy<sub>1</sub></var>
<var>px<sub>2</sub></var> <var>py<sub>2</sub></var> <var>qx<sub>2</sub></var> <var>qy<sub>2</sub></var>
:
<var>px<sub>N</sub></var> <var>py<sub>N</sub></var> <var>qx<sub>N</sub></var> <var>qy<sub>N</sub></var>
</pre>
<p>
1行目に線分の数 <var>N</var> (1 ≤ <var>N</var> ≤ 100000) が与えられる。続く <var>N</var> 行に、<var>i</var> 番目に追加したい線分の情報が与えられる。各行に与えられる4つの整数 <var>px<sub>i</sub></var>, <var>py<sub>i</sub></var>, <var>qx<sub>i</sub></var>, <var>qy<sub>i</sub></var> (0 ≤ <var>px<sub>i</sub></var>, <var>py<sub>i</sub></var>, <var>qx<sub>i</sub></var>, <var>qy<sub>i</sub></var> ≤ 10<sup>9</sup>) は、それぞれ <var>i</var> 番目の線分の端点の <var>x</var> 座標、<var>y</var> 座標、もう一つの端点の <var>x</var> 座標、<var>y</var> 座標を表す。ただし、線分の長さは1以上である。
</p>
<h2>Output</h2>
<p>
各線分について、追加される場合「1」を、追加されない場合「0」を1行に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
9
0 2 5 2
1 3 1 7
0 6 3 6
2 4 8 4
4 0 4 5
6 3 6 0
5 6 7 6
8 3 8 7
6 5 11 5
</pre>
<h2>Sample Output 1</h2>
<pre>
1
1
0
1
0
1
1
0
1
</pre> |
p03857 | <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> cities. There are also <var>K</var> roads and <var>L</var> railways, extending between the cities.
The <var>i</var>-th road bidirectionally connects the <var>p_i</var>-th and <var>q_i</var>-th cities, and the <var>i</var>-th railway bidirectionally connects the <var>r_i</var>-th and <var>s_i</var>-th cities.
No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.</p>
<p>We will say city <var>A</var> and <var>B</var> are <em>connected by roads</em> if city <var>B</var> is reachable from city <var>A</var> by traversing some number of roads. Here, any city is considered to be connected to itself by roads.
We will also define <em>connectivity by railways</em> similarly.</p>
<p>For each city, find the number of the cities connected to that city by both roads and railways.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≦ N ≦ 2*10^5</var></li>
<li><var>1 ≦ K, L≦ 10^5</var></li>
<li><var>1 ≦ p_i, q_i, r_i, s_i ≦ N</var></li>
<li><var>p_i < q_i</var></li>
<li><var>r_i < s_i</var></li>
<li>When <var>i ≠ j</var>, <var>(p_i, q_i) ≠ (p_j, q_j)</var></li>
<li>When <var>i ≠ j</var>, <var>(r_i, s_i) ≠ (r_j, s_j)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var> <var>L</var>
<var>p_1</var> <var>q_1</var>
:
<var>p_K</var> <var>q_K</var>
<var>r_1</var> <var>s_1</var>
:
<var>r_L</var> <var>s_L</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> integers. The <var>i</var>-th of them should represent the number of the cities connected to the <var>i</var>-th city by both roads and railways.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3 1
1 2
2 3
3 4
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 2 1
</pre>
<p>All the four cities are connected to each other by roads.</p>
<p>By railways, only the second and third cities are connected. Thus, the answers for the cities are <var>1, 2, 2</var> and <var>1</var>, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2 2
1 2
2 3
1 4
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2 2 1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1 1 2 1 2 2 2
</pre></section>
</div>
</span> |
p02745 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a string <var>s</var>.
From this string, Anuke, Bnuke, and Cnuke obtained strings <var>a</var>, <var>b</var>, and <var>c</var>, respectively, as follows:</p>
<ul>
<li>Choose a non-empty (contiguous) substring of <var>s</var> (possibly <var>s</var> itself). Then, replace some characters (possibly all or none) in it with <code>?</code>s.</li>
</ul>
<p>For example, if <var>s</var> is <code>mississippi</code>, we can choose the substring <code>ssissip</code> and replace its <var>1</var>-st and <var>3</var>-rd characters with <code>?</code> to obtain <code>?s?ssip</code>.</p>
<p>You are given the strings <var>a</var>, <var>b</var>, and <var>c</var>.
Find the minimum possible length of <var>s</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |a|, |b|, |c| \leq 2000</var></li>
<li><var>a</var>, <var>b</var>, and <var>c</var> consists of lowercase English letters and <code>?</code>s.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var>
<var>b</var>
<var>c</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible length of <var>s</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>a?c
der
cod
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>For example, <var>s</var> could be <code>atcoder</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>atcoder
atcoder
???????
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
<p><var>a</var>, <var>b</var>, and <var>c</var> may not be distinct.</p></section>
</div>
</span> |
p00778 |
<h3>A Die Maker</h3>
<p>
The work of die makers starts early in the morning.
</p>
<p>
You are a die maker.
You receive orders from customers, and make various kinds of dice every day.
Today, you received an order of a cubic die with six numbers
<i>t</i><sub>1</sub>, <i>t</i><sub>2</sub>, ..., <i>t</i><sub>6</sub> on whichever faces.
</p>
<p>
For making the ordered die, you use a tool of flat-board shape.
You initially have a die with a zero on each face.
If you rotate the die by 90 degrees on the tool towards one of northward, southward, eastward, and southward,
the number on the face that newly touches the tool is increased by one.
By rotating the die towards appropriate directions repeatedly,
you may obtain the ordered die.
</p>
<p>
The final numbers on the faces of the die
is determined by the sequence of directions towards which you rotate the die.
We call the string that represents the sequence of directions an <i>operation sequence.</i>
Formally, we define operation sequences as follows.
An operation sequence consists of <i>n</i> characters, where <i>n</i> is the number of rotations made.
If you rotate the die eastward in the <i>i</i>-th rotation,
the <i>i</i>-th character of the operation sequence is <code>E</code>.
Similarly, if you rotate it westward, it is <code>W</code>,
if southward, it is <code>S</code>, otherwise,
if northward, it is <code>N</code>.
For example, the operation sequence <code>NWS</code> represents
the sequence of three rotations, northward first, westward next,
and finally southward.
</p>
<p>
Given six integers of the customer's order,
compute an operation sequence that makes a die to order.
If there are two or more possibilities, you should compute the earliest operation sequence in dictionary order.
</p>
<h3>Input</h3>
<p>
The input consists of multiple datasets.
The number of datasets does not exceed 40.
Each dataset has the following form.
</p>
<blockquote>
<i>t</i><sub>1</sub> <i>t</i><sub>2</sub> <i>t</i><sub>3</sub> <i>t</i><sub>4</sub> <i>t</i><sub>5</sub> <i>t</i><sub>6</sub><br>
<i>p</i> <i>q</i>
</blockquote>
<p>
<i>t</i><sub>1</sub>, <i>t</i><sub>2</sub>, ..., <i>t</i><sub>6</sub> are integers that represent the order from the customer.
Further, <i>p</i> and <i>q</i> are positive integers that specify the output range of the operation sequence (see the details below).
</p>
<p>
Each dataset satisfies
0 ≤ <i>t</i><sub>1</sub> ≤ <i>t</i><sub>2</sub> ≤ ... ≤ <i>t</i><sub>6</sub> ≤ 5,000
and
1 ≤ <i>p</i> ≤ <i>q</i> ≤ <i>t</i><sub>1</sub>+<i>t</i><sub>2</sub>+...+<i>t</i><sub>6</sub>.
A line containing six zeros denotes the end of the input.
</p>
<h3>Output</h3>
<p>
For each dataset,
print the subsequence,
from the <i>p</i>-th position to the <i>q</i>-th position, inclusively,
of the operation sequence that is the earliest in dictionary order.
If it is impossible to make the ordered die, print <code>impossible</code>.
</p>
<p>
Here, dictionary order is recursively defined as follows.
The empty string comes the first in dictionary order.
For two nonempty strings <i>x</i> = <i>x</i><sub>1</sub> ... <i>x</i><sub><i>k</i></sub> and <i>y</i> = <i>y</i><sub>1</sub> ... <i>y</i><sub><i>l</i></sub>, the string <i>x</i> precedes the string <i>y</i> in dictionary order if
</p>
<ul>
<li> <i>x</i><sub>1</sub> precedes <i>y</i><sub>1</sub> in alphabetical order ('A' to 'Z'), or </li>
<li> <i>x</i><sub>1</sub> and <i>y</i><sub>1</sub> are the same character and <i>x</i><sub>2</sub> ... <i>x</i><sub><i>k</i></sub> precedes <i>y</i><sub>2</sub> ... <i>y</i><sub><i>l</i></sub> in dictionary order.</li>
</ul>
<h3>Sample Input</h3>
<pre>1 1 1 1 1 1
1 6
1 1 1 1 1 1
4 5
0 0 0 0 0 2
1 2
0 0 2 2 2 4
5 9
1 2 3 4 5 6
15 16
0 1 2 3 5 9
13 16
2 13 22 27 31 91
100 170
0 0 0 0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>EEENEE
NE
impossible
NSSNW
EN
EWNS
SNSNSNSNSNSNSNSNSNSNSNSSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNWEWE
</pre> |
p00282 |
<h1>塵劫記</h1>
<p>
大きな数を表そうとすると、文字数も多くなるし、位取りがわからなくなってしまうので、なかなか面倒です。大きな数をわかりやすく表すために、人々は数の単位を使ってきました。江戸時代に書かれた「塵劫記」という本の中では、数の単位が次のように書かれています。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_jinkouki1" width="740">
</center>
<br>
<p>
たとえば、2の100乗のようなとても大きな数は、126穣7650(じょ)6002垓2822京9401兆4967億320万5376と表せます。それでは、正の整数 <var>m</var> と <var>n</var> が与えられたとき、<var>m</var> の <var>n</var> 乗を塵劫記の単位を使って上のように表すプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる。入力の終わりはゼロ2つの行で示される。各データセットは以下の形式で与えられる。
</p>
<pre>
<var>m</var> <var>n</var>
</pre>
<p>
<var>m</var> (2 ≤ <var>m</var> ≤ 20) が基数、<var>n</var> (1 ≤ <var>n</var> < 240) が指数を表す。ただし、<var>m<sup>n</sup></var>は 10<sup>72</sup> 未満である。
</p>
<p>
データセットの数は 100 を超えない。
</p>
<h2>出力</h2>
<p>
データセットごとに、<var>m<sup>n</sup></var> を塵劫記の単位で表した文字列を1行に出力する。ただし、各単位は以下の表記で出力する。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_jinkouki2" width="740">
</center>
<br>
<p>
<var>m<sup>n</sup></var>を表す文字列は、1 から 9999 までの数と上の表に現れる単位を表す文字列からなる。文字列には、余分な 0 や単位を含めない。
</p>
<h2>入出力例</h2>
<br>
<h2>入力例</h2>
<pre>
2 10
5 20
10 8
20 17
0 0
</pre>
<h2>出力例</h2>
<pre>
1024
95Cho3674Oku3164Man625
1Oku
131Gai720Kei
</pre> |
p01885 |
<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>Escape from the Hell</h2>
<p>
One day, Buddha looked into the hell and found an office worker. He did evil, such as enforcing hard work on his subordinates. However, he made only one good in his life. He refused an unreasonable request from his customer to save the lives of his subordinates. Buddha thought that, as the reward of the good, the office worker should have had a chance to escape from the hell. Buddha took a spider silk and put down to the hell.
</p>
<p>
The office worker climbed up with the spider silk, however the length of the way $L$ meters was too long to escape one day. He had $N$ energy drinks and drunk one of them each day. The day he drunk the i-th energy drink he could climb $A_i$ meters in the daytime and after that slided down $B_i$ meters in the night. If he could reach at the height greater than or equal to the $L$ meters in the daytime, he could escape without sliding down. After the $N$ days the silk would be cut.
</p>
<p>
He realized that other sinners climbed the silk in the night. They climbed $C_i$ meters in the $i$-th night without sliding down in the daytime. If they catched up with the office worker, they should have conflicted and the silk would be cut. Therefore he needed to escape before other sinners catched him. Your task is to write a program computing the best order of energy drink and output the earliest day which he could escape. If he could not escape, your program should output -1.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case.<br/>
<br/>
$N$ $L$<br/>
$A_1$ $B_1$<br/>
$A_2$ $B_2$<br/>
...<br/>
$A_N$ $B_N$<br/>
$C_1$<br/>
$C_2$<br/>
...<br/>
$C_N$
</p>
<p>
The first line contains two integers $N$ ($1 \leq N \leq 10^5$) and $L$ ($1 \leq L \leq 10^9$), which mean the number of energy drinks and the length of the spider silk respectively. The following $N$ lines show the information of the drinks: the $i$-th of them indicates the $i$-th energy drink, he climbed up $A_i$ ($1 \leq A_i \leq 10^9$) meters and slided down $B_i$ ($1 \leq B_i \leq 10^9$) meters. Next $N$ lines show how far other sinners climbed: the $i$-th of them contains an integer $C_i$ ($1 \leq C_i \leq 10^9$), which means they climbed up $C_i$ meters in the $i$-th day.
</p>
<h3>Output</h3>
<p>
Print the earliest day which he could escape. If he could not escape, print -1 instead.
</p>
<h3>Sample Input 1</h3>
<pre>
3 9
6 3
5 2
3 1
2
2
2
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
2
</pre>
<h3>Sample Input 2</h3>
<pre>
5 20
3 2
4 2
6 3
8 4
10 5
4
2
3
4
5
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
-1
</pre>
<h3>Sample Input 3</h3>
<pre>
5 20
6 5
7 3
10 3
10 14
4 7
2
5
3
9
2
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
3
</pre>
<h3>Sample Input 4</h3>
<pre>
4 12
8 4
6 4
2 1
2 1
1
1
4
4
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
-1
</pre>
|
p00797 |
<H1><font color="#000">Problem B:</font> Family Tree</H1>
<p>
A professor of anthropology was interested in people living in isolated islands and their history.
He collected their family trees to conduct some anthropological experiment. For the experiment,
he needed to process the family trees with a computer. For that purpose he translated them
into text files. The following is an example of a text file representing a family tree.
</p>
<pre>
John
Robert
Frank
Andrew
Nancy
David
</pre>
<p>
Each line contains the given name of a person. The name in the first line is the oldest ancestor
in this family tree. The family tree contains only the descendants of the oldest ancestor. Their
husbands and wives are not shown in the family tree. The children of a person are indented
with one more space than the parent. For example, Robert and Nancy are the children of John,
and Frank and Andrew are the children of Robert. David is indented with one more space than
Robert, but he is not a child of Robert, but of Nancy. To represent a family tree in this way,
the professor excluded some people from the family trees so that no one had both parents in a
family tree.
</p>
<p>
For the experiment, the professor also collected documents of the families and extracted the
set of statements about relations of two persons in each family tree. The following are some
examples of statements about the family above.
</p>
<pre>
John is the parent of Robert.
Robert is a sibling of Nancy.
David is a descendant of Robert.
</pre>
<p>
For the experiment, he needs to check whether each statement is true or not. For example, the
first two statements above are true and the last statement is false. Since this task is tedious, he
would like to check it by a computer program.
</p>
<H2>Input</H2>
<p>
The input contains several data sets. Each data set consists of a family tree and a set of
statements. The first line of each data set contains two integers <i>n</i> (0 < <i>n</i> < 1000) and <i>m</i> (0 < <i>m</i> < 1000) which represent the number of names in the family tree and the number of
statements, respectively. Each line of the input has less than 70 characters.
</p>
<p>
As a name, we consider any character string consisting of only alphabetic characters. The names
in a family tree have less than 20 characters. The name in the first line of the family tree has
no leading spaces. The other names in the family tree are indented with at least one space, i.e.,
they are descendants of the person in the first line. You can assume that if a name in the family
tree is indented with <i>k</i> spaces, the name in the next line is indented with at most <i>k</i> + 1 spaces.
This guarantees that each person except the oldest ancestor has his or her parent in the family
tree. No name appears twice in the same family tree. Each line of the family tree contains no
redundant spaces at the end.
</p>
<p>
Each statement occupies one line and is written in one of the following formats, where <i>X</i> and
<i>Y</i> are different names in the family tree.
</p>
<pre>
<i>X</i> is a child of <i>Y</i>.
<i>X</i> is the parent of <i>Y</i>.
<i>X</i> is a sibling of <i>Y</i>.
<i>X</i> is a descendant of <i>Y</i>.
<i>X</i> is an ancestor of <i>Y</i>.
</pre>
<p>
Names not appearing in the family tree are never used in the statements. Consecutive words in
a statement are separated by a single space. Each statement contains no redundant spaces at
the beginning and at the end of the line.
</p>
<p>
The end of the input is indicated by two zeros.
</p>
<H2>Output</H2>
<p>
For each statement in a data set, your program should output one line containing True or False.
The first letter of True or False in the output must be a capital. The output for each data set
should be followed by an empty line.
</p>
<H2>Sample Input</H2>
<pre>
6 5
John
Robert
Frank
Andrew
Nancy
David
Robert is a child of John.
Robert is an ancestor of Andrew.
Robert is a sibling of Nancy.
Nancy is the parent of Frank.
John is a descendant of Andrew.
2 1
abc
xyz
xyz is a child of abc.
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
True
True
True
False
False
True
</pre>
|
p02250 |
<H1>String Search</H1>
<p>
Determine whether a text <var>T</var> includes a pattern <var>P</var>. Your program should answer for given queries consisting of <var>P_i</var>.
</p>
<H2>Input</H2>
<p>
In the first line, a text <var>T</var> is given. In the second line, an integer <var>Q</var> denoting the number of queries is given. In the following <var>Q</var> lines, the patterns <var>P_i</var> are given respectively.
</p>
<H2>Output</H2>
<p>
For each question, print 1 if the text includes <var>P_i</var>, or print 0 otherwise.
</p>
<H2>Constraints</H2>
<ul>
<li> 1 ≤ length of <var>T</var> ≤ 1000000 </li>
<li> 1 ≤ length of <var>P_i</var> ≤ 1000 </li>
<li> 1 ≤ <var>Q</var> ≤ 10000 </li>
<li>The input consists of alphabetical characters and digits</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
aabaaa
4
aa
ba
bb
xyz
</pre>
<H2>Sample Output 1</H2>
<pre>
1
1
0
0
</pre> |
p03912 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is playing with <var>N</var> cards.</p>
<p>The <var>i</var>-th card has an integer <var>X_i</var> on it.</p>
<p>Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:</p>
<ul>
<li>The integers on the two cards are the same.</li>
<li>The sum of the integers on the two cards is a multiple of <var>M</var>.</li>
</ul>
<p>Find the maximum number of pairs that can be created.</p>
<p>Note that a card cannot be used in more than one pair.</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≦X_i≦10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of pairs that can be created.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 5
3 1 4 1 5 9 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Three pairs <var>(3,2), (1,4)</var> and <var>(1,9)</var> can be created.</p>
<p>It is possible to create pairs <var>(3,2)</var> and <var>(1,1)</var>, but the number of pairs is not maximized with this.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15 10
1 5 6 10 11 11 11 20 21 25 25 26 99 99 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre></section>
</div>
</span> |
p02600 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>M-kun is a competitor in AtCoder, whose highest rating is <var>X</var>.<br/>
In this site, a competitor is given a <em>kyu</em> (class) according to his/her highest rating. For ratings from <var>400</var> through <var>1999</var>, the following kyus are given:</p>
<ul>
<li>From <var>400</var> through <var>599</var>: <var>8</var>-kyu</li>
<li>From <var>600</var> through <var>799</var>: <var>7</var>-kyu</li>
<li>From <var>800</var> through <var>999</var>: <var>6</var>-kyu</li>
<li>From <var>1000</var> through <var>1199</var>: <var>5</var>-kyu</li>
<li>From <var>1200</var> through <var>1399</var>: <var>4</var>-kyu</li>
<li>From <var>1400</var> through <var>1599</var>: <var>3</var>-kyu</li>
<li>From <var>1600</var> through <var>1799</var>: <var>2</var>-kyu</li>
<li>From <var>1800</var> through <var>1999</var>: <var>1</var>-kyu</li>
</ul>
<p>What kyu does M-kun have?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>400 \leq X \leq 1999</var></li>
<li><var>X</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the kyu M-kun has, as an integer.
For example, if he has <var>8</var>-kyu, print <code>8</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>725
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>M-kun's highest rating is <var>725</var>, which corresponds to <var>7</var>-kyu.<br/>
Thus, <code>7</code> is the correct output.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1600
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>M-kun's highest rating is <var>1600</var>, which corresponds to <var>2</var>-kyu.<br/>
Thus, <code>2</code> is the correct output.</p></section>
</div>
</span> |
p01186 |
<H1><font color="#000">Problem F:</font> TV Watching</H1>
<p>
You are addicted to watching TV, and you watch so many TV programs every day. You have been in
trouble recently: the airtimes of your favorite TV programs overlap.
</p>
<p>
Fortunately, you have both a TV and a video recorder at your home. You can therefore watch a program
on air while another program (on a different channel) is recorded to a video at the same time. However,
it is not easy to decide which programs should be watched on air or recorded to a video. As you are a
talented computer programmer, you have decided to write a program to find the way of watching TV
programs which gives you the greatest possible satisfaction.
</p>
<p>
Your program (for a computer) will be given TV listing of a day along with your <i>score</i> for each TV
program. Each score represents how much you will be satisfied if you watch the corresponding TV
program on air or with a video. Your program should compute the maximum possible sum of the scores
of the TV programs that you can watch.
</p>
<H2>Input</H2>
<p>
The input consists of several scenarios.
</p>
<p>
The first line of each scenario contains an integer <i>N</i> (1 ≤ <i>N</i> ≤ 1000) that represents the number of
programs. Each of the following <i>N</i> lines contains program information in the format below:
</p
<pre>
<i>T</i> <i>T</i><sub><i>b</i></sub> <i>T</i><sub><i>e</i></sub> <i>R</i><sub>1</sub> <i>R</i><sub>2</sub>
</pre>
<p>
<i>T</i> is the title of the program and is composed by up to 32 alphabetical letters. <i>T</i><sub><i>b</i></sub> and <i>T</i><sub><i>e</i></sub> specify the
start time and the end time of broadcasting, respectively. <i>R</i><sub>1</sub> and <i>R</i><sub>2</sub> indicate the score when you watch
the program on air and when you have the program recorded, respectively.
</p>
<p>
All times given in the input have the form of “hh:mm” and range from 00:00 to 23:59. You may assume
that no program is broadcast across the twelve midnight.
</p>
<p>
The end of the input is indicated by a line containing only a single zero. This is not part of scenarios.
</p>
<H2>Output</H2>
<p>
For each scenario, output the maximum possible score in a line.
</p>
<H2>Sample Input</H2>
<pre>
4
OmoikkiriTV 12:00 13:00 5 1
WaratteIitomo 12:00 13:00 10 2
WatarusekennhaOnibakari 20:00 21:00 10 3
SuzumiyaharuhiNoYuuutsu 23:00 23:30 100 40
5
a 0:00 1:00 100 100
b 0:00 1:00 101 101
c 0:00 1:00 102 102
d 0:00 1:00 103 103
e 0:00 1:00 104 104
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
121
207
</pre>
|
p03441 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices.
The vertices are numbered <var>0</var> through <var>N - 1</var>, and the <var>i</var>-th edge (<var>0 ≤ i < N - 1</var>) comnnects Vertex <var>a_i</var> and <var>b_i</var>.
For each pair of vertices <var>u</var> and <var>v</var> (<var>0 ≤ u, v < N</var>), we define the distance <var>d(u, v)</var> as the number of edges in the path <var>u</var>-<var>v</var>.</p>
<p>It is expected that one of the vertices will be invaded by aliens from outer space.
Snuke wants to immediately identify that vertex when the invasion happens.
To do so, he has decided to install an antenna on some vertices.</p>
<p>First, he decides the number of antennas, <var>K</var> (<var>1 ≤ K ≤ N</var>).
Then, he chooses <var>K</var> different vertices, <var>x_0</var>, <var>x_1</var>, ..., <var>x_{K - 1}</var>, on which he installs Antenna <var>0</var>, <var>1</var>, ..., <var>K - 1</var>, respectively.
If Vertex <var>v</var> is invaded by aliens, Antenna <var>k</var> (<var>0 ≤ k < K</var>) will output the distance <var>d(x_k, v)</var>.
Based on these <var>K</var> outputs, Snuke will identify the vertex that is invaded.
Thus, in order to identify the invaded vertex no matter which one is invaded, the following condition must hold:</p>
<ul>
<li>For each vertex <var>u</var> (<var>0 ≤ u < N</var>), consider the vector <var>(d(x_0, u), ..., d(x_{K - 1}, u))</var>. These <var>N</var> vectors are distinct.</li>
</ul>
<p>Find the minumum value of <var>K</var>, the number of antennas, when the condition is satisfied.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ N ≤ 10^5</var></li>
<li><var>0 ≤ a_i, b_i < N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_0</var> <var>b_0</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_{N - 2}</var> <var>b_{N - 2}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minumum value of <var>K</var>, the number of antennas, when the condition is satisfied.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
0 1
0 2
0 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, install an antenna on Vertex <var>1</var> and <var>3</var>.
Then, the following five vectors are distinct:</p>
<ul>
<li><var>(d(1, 0), d(3, 0)) = (1, 1)</var></li>
<li><var>(d(1, 1), d(3, 1)) = (0, 2)</var></li>
<li><var>(d(1, 2), d(3, 2)) = (2, 2)</var></li>
<li><var>(d(1, 3), d(3, 3)) = (2, 0)</var></li>
<li><var>(d(1, 4), d(3, 4)) = (3, 1)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>For example, install an antenna on Vertex <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
2 8
6 0
4 1
7 6
2 3
8 6
6 9
2 4
5 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre>
<p>For example, install an antenna on Vertex <var>0</var>, <var>4</var>, <var>9</var>.</p></section>
</div>
</span> |
p03011 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are three airports A, B and C, and flights between each pair of airports in both directions.</p>
<p>A one-way flight between airports A and B takes <var>P</var> hours, a one-way flight between airports B and C takes <var>Q</var> hours, and a one-way flight between airports C and A takes <var>R</var> hours.</p>
<p>Consider a route where we start at one of the airports, fly to another airport and then fly to the other airport.</p>
<p>What is the minimum possible sum of the flight times?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq P,Q,R \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>P</var> <var>Q</var> <var>R</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible sum of the flight times.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<ul>
<li>The sum of the flight times in the route A <var>\rightarrow</var> B <var>\rightarrow</var> C: <var>1 + 3 = 4</var> hours</li>
<li>The sum of the flight times in the route A <var>\rightarrow</var> C <var>\rightarrow</var> C: <var>4 + 3 = 7</var> hours</li>
<li>The sum of the flight times in the route B <var>\rightarrow</var> A <var>\rightarrow</var> C: <var>1 + 4 = 5</var> hours</li>
<li>The sum of the flight times in the route B <var>\rightarrow</var> C <var>\rightarrow</var> A: <var>3 + 4 = 7</var> hours</li>
<li>The sum of the flight times in the route C <var>\rightarrow</var> A <var>\rightarrow</var> B: <var>4 + 1 = 5</var> hours</li>
<li>The sum of the flight times in the route C <var>\rightarrow</var> B <var>\rightarrow</var> A: <var>3 + 1 = 4</var> hours</li>
</ul>
<p>The minimum of these is <var>4</var> hours.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre></section>
</div>
</span> |
p00514 |
<H1>問題 5 </H1>
<br/>
<p>
IOI 宝飾店ではビーズのネックレスを売り出すことになった.
ビーズは n 色あり,
これらをそれぞれ m 個以上ずつ選んで r 個のビーズからなるネックレスとし,
1つずつ化粧箱に入れて販売したい.
色の組合せが違うものをすべて1つずつ用意したいが,
化粧箱を何個用意したらよいか店員の誰もわからない.
n, m, r によっては現実的でない個数の化粧箱が必要となるのではないかと店長は心配している.
IOI 宝飾店の店長に代わって,
必要な化粧箱の個数を出力するプログラムを作成しなさい.
n, m, r は整数で,0≦m<n≦r≦10000 である.
</p>
<p>
入力ファイルは1行で,
空白を区切りとして n, m, r がこの順に書いてある.
入力ファイル5つのうちの3つでは n≦10 である.
</p>
<p>
出力ファイルにおいては,
出力の最後の行にも改行コードを入れること.
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>2 0 3</pre>
<h3>出力例1</h3>
<pre>4</pre>
<br>
<h3>入力例2</h3>
<pre>3 1 4</pre>
<h3>出力例2</h3>
<pre>3</pre>
<br>
<h3>入力例3</h3>
<pre>4 2 5</pre>
<h3>出力例3</h3>
<pre>0</pre>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00144 |
<H1>パケット転送</H1>
<p>
インターネットでは、データはパケットに分割され、パケットごとにルータと呼ばれる中継機器を介して宛先に転送されます。各ルータはパケットに記載された宛先から次に転送すべきルータを判断します。さらに、無限にルータ間を転送され続けることを防ぐため、パケットには TTL(Time To Live) という値が付加されています。ルータは受け取ったパケットの TTL を 1 減算し、その結果が 0 ならそのパケットを破棄し、それ以外なら次のルータに転送します。
</p>
<p>
そこで、ネットワークの設計を手助けするプログラムを作ることになりました。ネットワークの接続情報と送信パケットの情報を入力として、各パケットが宛先ルータに到着するまでに経由するルータの数のうち最小の値を表示するプログラムを作成してください。
</p>
<p>
ネットワークは図のように複数のルータとそれらを結ぶケーブルで構成されています。ただし、各接続(ケーブル)は単方向であることに注意してください。各ルータが直接つながっているルータの番号の配列がネットワークの接続の情報として与えられます。ルータの数を <var>n</var> とすれば、各ルータは 1 から <var>n</var> までの整数で識別されます。送信元から宛先ルータまでの経路が複数ある場合は、経由するルータの数が少ない方の値を出力してください。また、パケットが宛先に到達しない場合は NA と出力してください。
</p>
<p>
例えば、以下の図のようなネットワークで、送信元ルータが 6、宛先ルータが 5 の場合を考えます。最短経路は 6→1→5 であり経由するルータは 3 個です。この場合、TTL はルータ 6、1 でそれぞれ減算されるので、送信時の TTL が 3 以上であればパケットは到達できます。宛先ルータでは TTL を減算する必要はありません。また、送信元と宛先が同じルータになるようなパケットは無いものとします。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_network">
</center>
<br/>
<H2>Input</H2>
<p>
入力は以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>r<sub>1</sub></var> <var>k<sub>1</sub></var> <var>t<sub>11</sub></var> <var>t<sub>12</sub></var> ... <var>t<sub>1k<sub>1</sub></sub></var>
<var>r<sub>2</sub></var> <var>k<sub>2</sub></var> <var>t<sub>21</sub></var> <var>t<sub>22</sub></var> ... <var>t<sub>2k<sub>2</sub></sub></var>
:
<var>r<sub>n</sub></var> <var>k<sub>n</sub></var> <var>t<sub>n1</sub></var> <var>t<sub>n2</sub></var> ... <var>t<sub>nk<sub>n</sub></sub></var>
<var>p</var>
<var>s<sub>1</sub></var> <var>d<sub>1</sub></var> <var>v<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>d<sub>2</sub></var> <var>v<sub>2</sub></var>
:
<var>s<sub>p</sub></var> <var>d<sub>p</sub></var> <var>v<sub>p</sub></var>
</pre>
<p>
1 行目にルータの総数 <var>n</var>(<var>n</var> ≤ 100)、続く <var>n</var> 行に <var>i</var> 番目のルータの接続情報が与えられます。接続情報として、<var>i</var> 番目のルータの番号 <var>r<sub>i</sub></var>、<var>i</var> 番目のルータと直接接続しているルータの個数 <var>k<sub>i</sub></var>、<var>i</var> 番目のルータから送信できるルータの番号 <var>t<sub>i1</sub></var>, <var>t<sub>i2</sub></var>, ... <var>t<sub>ik<sub>i</sub></sub></var>が与えられます。
</p>
<p>
続く行にパケットの個数 <var>p</var>(<var>p</var> ≤ 1000)、続く <var>p</var> 行に <var>i</var> 番目のパケットの情報が与えられます。パケットの情報として、 送信元ルータの番号 <var>s<sub>i</sub></var>, 宛先ルータの番号 <var>d<sub>i</sub></var>, TTL の値 <var>v<sub>i</sub></var> (0 ≤ <var>v<sub>i</sub></var> ≤ 10000) が与えられます。
</p>
<H2>Output</H2>
<p>
各パケットごとに、経由するルータの個数または NA を1行に出力してください。
</p>
<H2>Sample Input</H2>
<pre>
7
1 4 2 5 4 3
2 1 5
3 1 6
4 1 7
5 2 7 6
6 1 1
7 0
6
1 2 2
1 5 3
1 2 1
5 1 3
6 3 3
1 7 4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
2
NA
3
3
3
</pre>
|
p02179 | <h1>E: モンスターバスター</h1>
<h2>問題</h2>
<p>
AORイカちゃんはモンスターバスターである.<br>
ある日, 道を歩いていると寝ているモンスターに出会った.
</p>
<p>
闘争心が強いAORイカちゃんは,モンスターに寝起きの一撃をお見舞いすることに決めた.
しかし, 現在のAORイカちゃんの攻撃力は $0$ であり, このままではまともな攻撃ができない.
</p>
<p>
モンスターバスターの精進をしているAORイカちゃんは, 実は師匠から特殊な笛を託されていた.
この笛で特定の曲を吹くと一定時間攻撃力が上がるのである.
</p>
<p>
修行を積んだAORイカちゃんは $N$ 個の曲を吹くことができる.
$i$ 番目の曲は演奏に $R_i$ 秒かかり, 演奏終了後に攻撃力が $A_i$ だけ上昇する.
演奏終了から $T_i$ 秒後にこの演奏の効果は切れ, 演奏前の攻撃力に戻ってしまう.
</p>
<p>
また, AORイカちゃんは重ね演奏をすることができる.
演奏の効果時間中に同じ曲を演奏し終えると攻撃力が $A_i$ ではなく $W_i$ 上昇する.
重ね演奏は何回でもできるが効果時間は延長しない. そのため現在効果中の $i$ 番目の曲の最初にかけた効果が切れると重ね演奏の効果もすべて切れる.
</p>
<p>
AORイカちゃんの攻撃力の最大値を出力せよ.
なお, いくら演奏してもモンスターは起きないし, AORイカちゃんは $0.5$ 秒で攻撃できる.
</p>
<h2>制約</h2>
<ul>
<li>入力値は全て整数である.</li>
<li>$1 \leq N \leq 2000$</li>
<li>$-2000 \leq A_i, W_i \leq 2000$</li>
<li>$1 \leq R_i , T_i \leq 2000$</li>
</ul>
<h2>入力形式</h2>
<p> 入力は以下の形式で与えられる. </p>
<p>
$N$<br>
$R_1\ A_1\ W_1\ T_1$<br>
$\vdots$<br>
$R_N\ A_N\ W_N\ T_N$<br>
</p>
<h2>出力</h2>
<p>
AORイカちゃんの攻撃力の最大値を出力せよ. また, 末尾に改行も出力せよ.
</p>
<h2>サンプル</h2>
<h3>サンプル入力 1</h3>
<pre>
2
5 10 5 5
4 4 2 2
</pre>
<h3>サンプル出力 1</h3>
<pre>
14
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ACPC2019Day1_E_monster_buster_sample1.png" alt="サンプル1" />
<h3>サンプル入力 2</h3>
<pre>
2
5 10 5 11
8 8 2 1
</pre>
<h3>サンプル出力 2</h3>
<pre>
20
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ACPC2019Day1_E_monster_buster_sample2.png" alt="サンプル2" />
|
p03338 | <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> of length <var>N</var> consisting of lowercase English letters.
We will cut this string at one position into two strings <var>X</var> and <var>Y</var>.
Here, we would like to maximize the number of different letters contained in both <var>X</var> and <var>Y</var>.
Find the largest possible number of different letters contained in both <var>X</var> and <var>Y</var> when we cut the string at the optimal position.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100</var></li>
<li><var>|S| = N</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the largest possible number of different letters contained in both <var>X</var> and <var>Y</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
aabbca
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If we cut the string between the third and fourth letters into <var>X =</var> <code>aab</code> and <var>Y =</var> <code>bca</code>, the letters contained in both <var>X</var> and <var>Y</var> are <code>a</code> and <code>b</code>.
There will never be three or more different letters contained in both <var>X</var> and <var>Y</var>, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
aaaaaaaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>However we divide <var>S</var>, only <code>a</code> will be contained in both <var>X</var> and <var>Y</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
</pre></section>
</div>
</span> |
p01305 |
<h1><font color="#000">Problem C:</font> カードゲーム</h1>
<p>
ねこのゲイツとジャッキーは、2人で遊ぶカードゲームのルールを考えた。そのルールとは次のようなものである。
</p>
<p>
まず、1から18の数字が書かれたカードをシャッフルし、それぞれのプレーヤーに9枚ずつ配る。両者は同時に1枚のカードを同時に出し、その値によってスコアを得る。値の大きいカードを出したプレーヤーは、大きい方の値と小さい方の値の和を自分のスコアに加える。その際、値の小さいカードを出したプレーヤーはスコアを得られない。また、一度場に出されたカードは二度と使うことはできない。カードをすべて使い終わった後にスコアが大きかったプレーヤーの勝ちとする。
</p>
<p>
ゲイツとジャッキーは互いに無作為にカードを選んで出してみることにした。最初に配られたカードが与えられたとき、ゲイツとジャッキーが勝つ確率をそれぞれ求めよ。
</p>
<h2>Input</h2>
<p>
ゲイツ、ジャッキーそれぞれの手札は、9個の整数からなる。両プレーヤーの手札は1から18までの互いに異なる整数である。入力の1行目にはゲイツの手札を表す9個の整数が与えられ、2行目にはジャッキーの手札を表す9個の整数が与えられる。整数と整数の間は空白1個で区切られる。
</p>
<h2>Output</h2>
<p>
ゲイツ、ジャッキーが勝つ確率をそれぞれ、スペースで区切って小数点以下5桁まで出力せよ。 10<sup>-5</sup> 以内の誤差は許容されるが、0未満あるいは1を越える値を出力してはならない。
</p>
<h2>Notes on Submission</h2>
<p>
上記形式で複数のデータセットが与えられます。入力データの 1 行目にデータセットの数が与えられます。各データセットに対する出力を上記形式で順番に出力するプログラムを作成して下さい。
</p>
<h2>Sample Input</h2>
<pre>
2
1 3 5 7 9 11 13 15 17
2 4 6 8 10 12 14 16 18
1 5 7 9 11 13 15 17 18
2 3 4 6 8 10 12 14 16
</pre>
<h2>Output for the Sample Input</h2>
<pre>
0.30891 0.69109
0.92747 0.07253
</pre>
|
p03292 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have three tasks, all of which need to be completed.</p>
<p>First, you can complete any one task at cost <var>0</var>.</p>
<p>Then, just after completing the <var>i</var>-th task, you can complete the <var>j</var>-th task at cost <var>|A_j - A_i|</var>.</p>
<p>Here, <var>|x|</var> denotes the absolute value of <var>x</var>.</p>
<p>Find the minimum total cost required to complete all the task.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A_1, A_2, A_3 \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A_1</var> <var>A_2</var> <var>A_3</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total cost required to complete all the task.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 6 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>When the tasks are completed in the following order, the total cost will be <var>5</var>, which is the minimum:</p>
<ul>
<li>Complete the first task at cost <var>0</var>.</li>
<li>Complete the third task at cost <var>2</var>.</li>
<li>Complete the second task at cost <var>3</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>11 5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03768 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Squid loves painting vertices in graphs.</p>
<p>There is a simple undirected graph consisting of <var>N</var> vertices numbered <var>1</var> through <var>N</var>, and <var>M</var> edges.
Initially, all the vertices are painted in color <var>0</var>. The <var>i</var>-th edge bidirectionally connects two vertices <var>a_i</var> and <var>b_i</var>. The length of every edge is <var>1</var>.</p>
<p>Squid performed <var>Q</var> operations on this graph. In the <var>i</var>-th operation, he repaints all the vertices within a distance of <var>d_i</var> from vertex <var>v_i</var>, in color <var>c_i</var>.</p>
<p>Find the color of each vertex after the <var>Q</var> operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N,M,Q ≤ 10^5</var></li>
<li><var>1 ≤ a_i,b_i,v_i ≤ N</var></li>
<li><var>a_i ≠ b_i</var></li>
<li><var>0 ≤ d_i ≤ 10</var></li>
<li><var>1 ≤ c_i ≤10^5</var></li>
<li><var>d_i</var> and <var>c_i</var> are all integers.</li>
<li>There are no self-loops or multiple edges in the given graph.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded for passing the testset satisfying <var>1 ≤ N,M,Q ≤ 2{,}000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_{M}</var> <var>b_{M}</var>
<var>Q</var>
<var>v_1</var> <var>d_1</var> <var>c_1</var>
<var>:</var>
<var>v_{Q}</var> <var>d_{Q}</var> <var>c_{Q}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer in <var>N</var> lines.
In the <var>i</var>-th line, print the color of vertex <var>i</var> after the <var>Q</var> operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 7
1 2
1 3
1 4
4 5
5 6
5 7
2 3
2
6 1 1
1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
2
2
2
2
1
0
</pre>
<p>Initially, each vertex is painted in color <var>0</var>.
In the first operation, vertices <var>5</var> and <var>6</var> are repainted in color <var>1</var>.
In the second operation, vertices <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var> and <var>5</var> are repainted in color <var>2</var>.
<div style="text-align: center;">
<img alt="2ab7e180230b159d42d35ea7e555b3b0.png" src="https://atcoder.jp/img/agc012/2ab7e180230b159d42d35ea7e555b3b0.png">
</img></div></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>14 10
1 4
5 7
7 11
4 10
14 7
14 3
6 14
8 11
5 13
8 3
8
8 6 2
9 7 85
6 9 3
6 7 5
10 3 1
12 9 4
9 6 6
8 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
0
3
1
5
5
3
3
6
1
3
4
5
3
</pre>
<p>The given graph may not be connected.</p></section>
</div>
</span> |
p01755 |
<p>
盤面上にロボットと壁,ゴールが設置されており, ロボットの行動パターンを記述したプログラムが与えられる.
</p>
<p>
与えられるプログラムは以下のEBNF で表される.
</p>
<pre>
プログラム:= {文};
文:= if 文|while 文|動作文;
if 文:= "[", 条件, プログラム, "]";
while 文:= "{", 条件, プログラム, "}";
動作文:= "^"|"v"|"<"|">";
条件:= ["~"], "N"|"E"|"S"|"W"|"C"|"T";
</pre>
<p>
「プログラム」は0個以上の「文」からなり,1つ以上の文が存在する場合は 1 つ目の文から順番に1 つずつ文が実行される.「文」は「動作文」,「if 文」,「while 文」のいずれかである.「動作文」は"<span>^</span>", "<span>v</span>","<span><</span>","<span>></span>" のいずれかであり,それぞれ以下の動作が実行される.
</p>
<ul>
<li> "<span>^</span>": 前進 </li>
<li> "<span>v</span>": 後退 </li>
<li> "<span><</span>": 左に90 度回転 </li>
<li> "<span>></span>": 右に90 度回転 </li>
</ul>
<p>
「if 文」は "<span>[</span>",「条件」,「プログラム」,"<span>]</span>" を順番に並べたもので,以下の手順で実行される.
</p>
<ol>
<li> 「条件」の内容が真かどうか判定する </li>
<li> 判定が真なら「プログラム」の内容を実行し,このif 文の処理を終了する</li>
<li> 判定が偽ならこのif 文の処理を終了する</li>
</ol>
<p>
「while 文」は "<span>{</span>",「条件」,「プログラム」,"<span>}</span>" を順番に並べたもので,以下の手順で実行される.
</p>
<ol>
<li> 「条件」の内容が真かどうか判定する </li>
<li> 判定が真なら「プログラム」の内容を実行し,1 に戻る</li>
<li> 判定が偽なら,この while 文の処理を終了する</li>
</ol>
<p>
「条件」は "<span>N</span>", "<span>E</span>", "<span>S</span>", "<span>W</span>", "<span>C</span>", "<span>T</span>" のいずれかであり,先頭には"<span>~</span>" をつけることができる.それぞれの記述は以下の真偽値を表す.
</p>
<ul>
<li> 先頭に "<span>~</span>" が付いている場合は真偽値が逆転 </li>
<li> <span>N</span>: 北を向いているならば真,そうでなければ偽</li>
<li> <span>E</span>: 東を向いているならば真,そうでなければ偽</li>
<li> <span>S</span>: 南を向いているならば真,そうでなければ偽</li>
<li> <span>W</span>: 西を向いているならば真,そうでなければ偽</li>
<li> <span>C</span>: 目の前に壁があるならば真,そうでなければ偽</li>
<li> <span>T</span>: 常に真</li>
</ul>
<p>
ロボットは最初,北を向いているものとする.ロボットは壁を通ることができず,何もないマスのみを移動できる.もし,プログラムが壁の上を通るような動作を実行しようとした場合,ロボットは移動せずその場にとどまる.最後に,ロボットはゴールに到達した時,実行途中のプログラムが残っていたとしてもすべて中断して動作を停止する.
</p>
<p>
このとき,ロボットがゴールにたどり着くまでにどのぐらい時間がかかるのか知りたい.ロボットは条件判定やプログラムの読み込みに関しては非常に高速に実行できるので実際の動作時間を決定するのは「動作文」のみである.そこで,このロボットがゴールに辿り着くまでに「動作文」を何回実行するかを教えてほしい.
</p>
<p>
なお,壁の上を通るような動作を実行しようとして,実際には「動作文」の動作が行われなかった場合にも「動作文」は実行されたものとみなす.
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる.
</p>
<pre>
<var>H</var> <var>W</var>
<var>a<sub>1,1</sub>a<sub>1,2</sub> . . . a<sub>1,W</sub></var>
<var>a<sub>2,1</sub>a<sub>2,2</sub> . . . a<sub>2,W</sub></var>
: : :
<var>a<sub>H,1</sub>a<sub>H,2</sub> . . . a<sub>H,W</sub></var>
<var>s</var>
</pre>
<p>
<var>H</var> は盤面の高さ,<var>W</var> は盤面の幅を表す.
</p>
<p>
次に盤面を真上から見た状態が与えられる.この盤面は上,下,左,右がそれぞれ北,南,西,東に対応する.各マスの状態を表す <var>a<sub>i,j</sub></var> は以下のいずれかの文字である.
</p>
<ul>
<li> "<span>s</span>" : ロボット(ロボットの初期位置.このマスには壁がないことが保証されている)</li>
<li> "<span>g</span>" : ゴール</li>
<li> "<span>#</span>" : 壁(ロボットは壁の上を移動することはできない)</li>
<li> "<span>.</span>" : 何もないマス</li>
</ul>
<p>
<var>s</var> にはロボットに与えられるプログラムが文字列として入力される.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>H,W</var> ≤ 50</li>
<li> 1 ≤ <var>s</var> の文字数 ≤ 1,000</li>
<li> <var>a<sub>i,j</sub></var> は"<span>.</span>", "<span>#</span>", "<span>s</span>", "<span>g</span>" のいずれか</li>
<li> "<span>s</span>", "<span>g</span>" はそれぞれ 1 回しか登場しない</li>
<li> <var>i = 1</var> または <var>i = H</var> または <var>j = 1</var> または <var>j = W</var> ならば <var>a<sub>i,j</sub></var> = "<span>#</span>"(盤面の外周は壁で囲まれていることが保証されている)</li>
<li> <var>s</var> として与えられるプログラムは構文的に正しい</li>
</ul>
<h2>Output</h2>
<p>
たどり着ける場合は"到達するまでに実行した「動作文」の数" を,たどりつけない場合は "-1" を出力せよ.なお,壁の上を通るような動作を実行しようとして,実際には「動作文」の動作が行われなかった場合にも「動作文」が実行されたものとみなす点に注意せよ(入力例1).
</p>
<h2>Sample Input 1</h2>
<pre>
5 3
###
#g#
#.#
#s#
###
^<^<vv
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>
5
</pre>
<h2>Sample Input 2</h2>
<pre>
5 7
#######
#.#g..#
#.###.#
#s....#
#######
{T{~C^}<}
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>
17
</pre>
<h2>Sample Input 3</h2>
<pre>
5 7
#######
#.#g..#
#.###.#
#s....#
#######
{T{~C^}>}
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>
-1
</pre>
|
p00847 |
<H1><font color="#000">Problem C:</font> Cubic Eight-Puzzle</H1>
<p>
Let's play a puzzle using eight cubes placed on a 3 × 3 board leaving one empty square.
</p>
<p>
Faces of cubes are painted with three colors. As a puzzle step, you can roll one of the cubes to
the adjacent empty square. Your goal is to make the specified color pattern visible from above
by a number of such steps.
</p>
<p>
The rules of this puzzle are as follows.
</p>
<ol>
<li>
<b>Coloring of Cubes:</b> All the cubes are colored in the same way as shown in Figure 3.
The opposite faces have the same color.
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubic8Puzzle1">
<p>Figure 3: Coloring of a cube</p>
</center>
<br>
</li>
<li>
<b>Initial Board State:</b> Eight cubes are placed on the 3 × 3 board leaving one empty square.
All the cubes have the same orientation as shown in Figure 4. As shown in the figure,
squares on the board are given <i>x</i> and <i>y</i> coordinates, (1, 1), (1, 2), .. ., and (3, 3). The
position of the initially empty square may vary.
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubic8Puzzle2">
<p>Figure 4: Initial board state</p>
</center>
<br>
</li>
<li>
<b>Rolling Cubes:</b> At each step, we can choose one of the cubes adjacent to the empty square and roll it into the empty square, leaving the original position empty. Figure 5
shows an example.
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cubic8Puzzle3">
<p>Figure 5: Rolling a cube</p>
</center>
<br>
</li>
<li>
<b>Goal:</b> The goal of this puzzle is to arrange the cubes so that their top faces form the
specified color pattern by a number of cube rolling steps described above.
</li>
</ol>
<p>
Your task is to write a program that finds the minimum number of steps required to make the
specified color pattern from the given initial state.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The end of the input is indicated by a line containing two
zeros separated by a space. The number of datasets is less than 16. Each dataset is formatted
as follows.
</p>
<pre>
<i>x y</i>
<i>F</i><sub>11</sub> <i>F</i><sub>21</sub> <i>F</i><sub>31</sub>
<i>F</i><sub>12</sub> <i>F</i><sub>22</sub> <i>F</i><sub>32</sub>
<i>F</i><sub>13</sub> <i>F</i><sub>23</sub> <i>F</i><sub>33</sub>
</pre>
<p>
The first line contains two integers <i>x</i> and <i>y</i> separated by a space, indicating the position (<i>x</i>, <i>y</i>)
of the initially empty square. The values of <i>x</i> and <i>y</i> are 1, 2, or 3.
</p>
<p>
The following three lines specify the color pattern to make. Each line contains three characters
<i>F</i><sub>1<i>j</i></sub>, <i>F</i><sub>2<i>j</i></sub>, and <i>F</i><sub>3<i>j</i></sub>, separated by a space. Character <i>F<sub>ij</sub></i> indicates the top color of the cube, if any, at position (<i>i</i>, <i>j</i>) as follows:
</p>
<pre>
B: Blue
W: White
R: Red
E: the square is Empty.
</pre>
<p>
There is exactly one '<span>E</span>' character in each dataset.
</p>
<H2>Output</H2>
<p>
For each dataset, output the minimum number of steps to achieve the goal, when the goal can
be reached within 30 steps. Otherwise, output "<span>-1</span>" for the dataset.
</p>
<H2>Sample Input</H2>
<pre>
1 2
W W W
E W W
W W W
2 1
R B W
R W W
E W W
3 3
W B W
B R E
R B R
3 3
B W R
B W R
B E R
2 1
B B B
B R B
B R E
1 1
R R R
W W W
R R E
2 1
R R R
B W B
R R E
3 2
R R R
W E W
R R R
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
3
13
23
29
30
-1
-1
</pre>
|
p01240 |
<H1><font color="#000">Problem G:</font> Oil Company</H1>
<p>
Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey
has been done and they created a detailed grid map of the area which indicates the reserve of oil.
</p>
<p>
They are now planning to construct mining plants on several grid blocks according this map, but they decided
not to place any two plants on adjacent positions to avoid spreading of fire in case of blaze. Two blocks are
considered to be adjacent when they have a common edge. You are one of the programmers working for the
company and your task is to write a program which calculates the maximum amount of oil they can mine, given
the map of the reserve.
</p>
<H2>Input</H2>
<p>
The first line of the input specifies N, the number of test cases. Then <i>N</i> test cases follow, each of which looks
like the following:
</p>
<pre>
<i>W H</i>
<i>r</i><sub>1,1</sub> <i>r</i><sub>2,1</sub> . . . <i>r</i><sub><i>W</i>,1</sub>
...
<i>r</i><sub>1,<i>H</i></sub> <i>r</i><sub>2,<i>H</i></sub> . . . <i>r</i><sub><i>W</i>,<i>H</i></sub>
</pre>
<p>
The first line of a test case contains two integers <i>W</i> and <i>H</i> (1 ≤ <i>W</i>, <i>H</i> ≤ 20). They specifies the dimension of
the area. The next <i>H</i> lines, each of which contains <i>W</i> integers, represent the map of the area. Each integer <i>r</i><sub><i>x</i>,<i>y</i></sub>
(0 ≤ <i>r</i><sub><i>x</i>,<i>y</i></sub> < 10000) indicates the oil reserve at the grid block (<i>x</i>, <i>y</i>).
</p>
<H2>Output</H2>
<p>
For each test case, output the case number (starting from 1) and the maximum possible amount of mining in a
line. Refer to the sample output section about the format.
</p>
<H2>Sample Input</H2>
<pre>
2
2 2
2 3
3 5
3 2
4 1 1
2 1 4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 7
Case 2: 8
</pre>
|
p04042 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha has a sequence of <var>N</var> strings <var>s_1, s_2, ..., s_N</var>.</p>
<p>She will choose some (possibly all) strings from the sequence, then concatenate those strings retaining the relative order, to produce a long string.</p>
<p>Among all strings of length <var>K</var> that she can produce in this way, find the lexicographically smallest one.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ N ≦ 2000</var></li>
<li><var>1 ≦ K ≦ 10^4</var></li>
<li>For each <var>i</var>, <var>1 ≦ |s_i| ≦ K</var>.</li>
<li><var>|s_1| + |s_2| + ... + |s_N| ≦ 10^6</var></li>
<li>For each <var>i</var>, <var>s_i</var> consists of lowercase letters.</li>
<li>There exists at least one string of length <var>K</var> that Iroha can produce.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>s_1</var>
<var>s_2</var>
:
<var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest string of length <var>K</var> that Iroha can produce.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 7
at
coder
codar
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>atcodar
</pre>
<p><code>at</code> and <code>codar</code> should be chosen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 7
coder
codar
at
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>codarat
</pre>
<p><code>codar</code> and <code>at</code> should be chosen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 13
kyuri
namida
zzzzzzz
aaaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>namidazzzzzzz
</pre>
<p><code>namida</code> and <code>zzzzzzz</code> should be chosen.</p></section>
</div>
</span> |
p03787 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has received an undirected graph with <var>N</var> vertices, numbered <var>1</var>, <var>2</var>, ..., <var>N</var>.
The edges in this graph are represented by <var>(u_i, v_i)</var>.
There are no self-loops and multiple edges in this graph.</p>
<p>Based on this graph, Takahashi is now constructing a new graph with <var>N^2</var> vertices, where each vertex is labeled with a pair of integers <var>(a, b)</var> (<var>1 \leq a \leq N</var>, <var>1 \leq b \leq N</var>).
The edges in this new graph are generated by the following rule:</p>
<ul>
<li>Span an edge between vertices <var>(a, b)</var> and <var>(a', b')</var> if and only if both of the following two edges exist in the original graph: an edge between vertices <var>a</var> and <var>a'</var>, and an edge between vertices <var>b</var> and <var>b'</var>.</li>
</ul>
<p>How many connected components are there in this new graph?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100,000</var></li>
<li><var>0 \leq M \leq 200,000</var></li>
<li><var>1 \leq u_i < v_i \leq N</var></li>
<li>There exists no pair of distinct integers <var>i</var> and <var>j</var> such that <var>u_i = u_j</var> and <var>v_i = v_j</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>u_1</var> <var>v_1</var>
<var>u_2</var> <var>v_2</var>
:
<var>u_M</var> <var>v_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the connected components in the graph constructed by Takahashi.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>The graph constructed by Takahashi is as follows.</p>
<p><img alt="" src="https://atcoder.jp/img/agc011/6d34a4ddeba67b2286c00acda56abbcc.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 5
1 2
3 4
3 5
4 5
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>18
</pre></section>
</div>
</span> |
p02895 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>2N</var> points <em>generally positioned</em> on the circumference of a circle, numbered <var>1,\dots,2N</var> in counterclockwise order.
Here, a set of points is said to be generally positioned if, for any six distinct points <var>U, V, W, X, Y,</var> and <var>Z</var> among them, the segments <var>UV, WX,</var> and <var>YZ</var> do not intersect at the same point.
Additionally, you will be given a <var>2N\times 2N</var> matrix <var>A</var>.</p>
<p>Find the number of ways to divide the <var>2N</var> points into <var>N</var> pairs such that all of the following are satisfied:</p>
<ul>
<li>Let us draw a red segment connecting the two points for each pair. Then, those red segments <em>form a tree</em>.</li>
<li>For each pair <var>(P, Q)</var>, <var>A_{P,Q} = A_{Q,P} = 1</var> holds.</li>
</ul>
<p>Here, a set of segments is said to form a tree if they are all connected and form no cycles.</p>
<p>For example, see the figure below:</p>
<ul>
<li>Upper left: the conditions are satisfied.</li>
<li>Upper right: the red segments form a cycle, so the conditions are not satisfied.</li>
<li>Lower left: the red segments are not connected, so the conditions are not satisfied.</li>
<li>Lower right: some vertices belong to no pair or multiple pairs, so the conditions are not satisfied.</li>
</ul>
<div style="text-align: center;">
<img src="https://img.atcoder.jp/agc039/af51d64712504b85b7a755ec48c3acac.png">
<p>Figure: A division satisfying the conditions (upper left) and divisions violating them (the others)</p>
</img></div>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>It can be proved that, as long as the <var>2N</var> points are generally positioned, the answer does not depend on their specific positions.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 20</var></li>
<li><var>A_{i,j}</var> is <code>0</code> or <code>1</code>.</li>
<li><var>A_{i,i}</var> is <code>0</code>.</li>
<li><var>A_{i,j}=A_{j,i}</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1,1}...A_{1,2N}</var>
<var>:</var>
<var>A_{2N,1}...A_{2N,2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to divide the <var>2N</var> points into <var>N</var> pairs such that all of the conditions are satisfied.
It can be proved that the answer fits into a <var>64</var>-bit signed integer under the given constraints.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
011111
101111
110111
111011
111101
111110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There are three possible divisions that satisfy the conditions: <var>((1,4),(2,6),(3,5))</var>, <var>((1,3),(2,5),(4,6))</var>, and <var>((1,5),(2,4),(3,6))</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
01111100
10011111
10011100
11101111
11110111
11111011
01011101
01011110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
0111101111111111
1011101111111111
1101101111011101
1110111111111111
1111011111110111
0001101111111111
1111110111011111
1111111011111111
1111111101111111
1111111110111111
1101110111011111
1111111111101111
1111011111110111
1111111111111011
1101111111111101
1111111111111110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4762
</pre></section>
</div>
</span> |
p01610 |
<h2>Cube of Two</h2>
<h2>Problem Statement</h2>
<p>日本で販売されているルービックキューブの各面の配色が,
世界で標準的に採用されているものに合わせられたのはつい最近のことだ.<br />
これに慣れるため,まずは簡単な2x2x2のキューブをスクランブルして遊ぼう.</p>
<p>初期状態のルービックキューブは,各色が1つの面に集まるように揃えられており,
上面に赤色,正面に黄色,右側面に青色が見える.<br />
また,下面は橙色,背面は白色,左側面は緑色である.
展開図を用いると次のように表せる.</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_J_rubik-color">
<p>各面に対し,向かって時計回りに90°回転させる操作を,それぞれの頭文字をとってU,F,R,D,B,Lと表す.<br />
ルービックキューブのスクランブルは,各文字が1つの回転操作に対応する文字列<var>S</var>として表される.<br />
初期状態から入力に従ってスクランブルしたときの,ルービックキューブの各面の色を展開図として出力せよ.</p>
<h2>Input</h2>
<p>入力は以下の形式に従う.</p>
<pre><var>S</var></pre>
<h2>Constraints</h2>
<p><var>1≦|S|≦100</var>(<var>|S|</var>は文字列の長さ)<br />
<var>S</var>はU,F,R,D,B,Lのみを含む.</p>
<h2>Output</h2>
<p>初期状態のルービックキューブに対し,各回転操作を順に適用した後の各面の状態を展開図として出力せよ.<br />
各面の色はr(赤),o(橙),y(黄),g(緑),b(青),w(白)の6種類の英小文字で表す.
また,空白部はピリオド(.)で表す.</p>
<h2>Sample Input 1</h2>
<pre>R</pre>
<h2>Output for the Sample Input 1</h2>
<pre>..ry....
..ry....
ggyobbrw
ggyobbrw
..ow....
..ow....</pre>
<p>右側面を時計回りに90°回転させると次のようになる.</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_J_sample1">
<h2>Sample Input 2</h2>
<pre>UFRDBL</pre>
<h2>Output for the Sample Input 2</h2>
<pre>..go....
..yb....
rbrwrwby
wogoygwo
..yb....
..gr....</pre>
<p>各回転操作に対する状態の遷移は次のようになる.</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_J_sample2">
|
p00902 |
<H1><font color="#000">Problem I: </font>Encircling Circles</H1>
<p>
You are given a set of circles <i>C</i> of a variety of radii (radiuses) placed at a variety of positions, possibly overlapping one another. Given a circle with radius <i>r</i>, that circle may be placed so that it encircles all of the circles in the set <i>C</i> if r is large enough.
</p>
<p>
There may be more than one possible position of the circle of radius <i>r</i> to encircle all the member circles of <i>C</i>. We define the region <i>U</i> as the union of the areas of encircling circles at all such positions. In other words, for each point in <i>U</i>, there exists a circle of radius <i>r</i> that encircles that point and all the members of <i>C</i>. Your task is to calculate the length of the periphery of that region <i>U</i>.
</p>
<p>
Figure I.1 shows an example of the set of circles <i>C</i> and the region <i>U</i>. In the figure, three circles contained in <i>C</i> are expressed by circles of solid circumference, some possible positions of the encircling circles are expressed by circles of dashed circumference, and the area <i>U</i> is expressed by a thick dashed closed curve.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1323_1">
</center>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The number of datasets is less than 100.
</p>
<p>
Each dataset is formatted as follows.
</p>
<p>
<i>n r<br>
x<sub>1</sub> y<sub>1</sub> r<sub>1</sub><br>
x<sub>2</sub> y<sub>2</sub> r<sub>2</sub><br>
.<br>
.<br>
.<br>
x<sub>n</sub> y<sub>n</sub> r<sub>n</sub></i>
</p>
<p>
The first line of a dataset contains two positive integers, <i>n</i> and <i>r</i>, separated by a single space. <i>n</i> means the number of the circles in the set <i>C</i> and does not exceed 100. <i>r</i> means the radius of the encircling circle and does not exceed 1000.
</p>
<p>
Each of the <i>n</i> lines following the first line contains three integers separated by a single space. (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) means the center position of the <i>i</i>-th circle of the set <i>C</i> and <i>r<sub>i</sub></i> means its radius.
</p>
<p>
You may assume −500≤<i>x<sub>i</sub></i> ≤500, −500≤<i>y<sub>i</sub></i> ≤500, and 1≤<i>r<sub>i</sub></i> ≤500.
</p>
<p>
The end of the input is indicated by a line containing two zeros separated by a single space.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing a decimal fraction which means the length of the periphery (circumferential length) of the region <i>U</i>.
</p>
<p>
The output should not contain an error greater than 0.01. You can assume that, when <i>r</i> changes by ε (|ε| < 0.0000001), the length of the periphery of the region <i>U</i> will not change more than 0.001.
</p>
<p>
If <i>r</i> is too small to cover all of the circles in <i>C</i>, output a line containing only 0.0.
</p>
<p>
No other characters should be contained in the output.
</p>
<H2>Sample Input</H2>
<pre>
1 10
5 5 7
2 12
5 5 7
8 6 3
3 10
3 11 2
2 1 1
2 16 3
3 15
-5 2 5
9 2 9
5 8 6
3 38
-25 -10 8
30 5 7
-3 35 11
3 39
-25 -10 8
30 5 7
-3 35 11
3 800
-400 400 2
300 300 1
300 302 1
3 800
400 -400 2
300 300 1
307 300 3
8 147
130 80 12
130 -40 12
-110 80 12
-110 -40 12
70 140 12
70 -100 12
-50 140 12
-50 -100 12
3 493
345 154 10
291 111 75
-275 -301 46
4 55
54 0 1
40 30 5
27 36 10
0 48 7
3 30
0 3 3
-3 0 4
400 0 3
3 7
2 3 2
-5 -4 2
-4 3 2
3 10
-5 -4 5
2 3 5
-4 3 5
4 6
4 6 1
5 5 1
1 7 1
0 1 1
3 493
345 154 10
291 111 75
-275 -301 46
5 20
-9 12 5
0 15 5
3 -3 3
12 9 5
-12 9 5
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
81.68140899333463
106.81415022205297
74.11215318612639
108.92086846105579
0.0
254.85616536128433
8576.936716409238
8569.462129048667
929.1977057481128
4181.124698202453
505.09134735536804
0.0
46.82023824234038
65.66979416387915
50.990642291793506
4181.124698202453
158.87951420768937
</pre>
<center>
<table>
<td valign="top">
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1323_2">
</td>
</table>
</center> |
p00451 |
<H1> 共通部分文字列 </H1>
<h2>問題</h2>
<p>
2 個の文字列が与えられたとき, 両方の文字列に含まれる文字列のうち最も長いものを探し, その長さを答えるプログラムを作成せよ.
</p>
<p>
ここで, 文字列 s が文字列 t に含まれるとは, t の中に s が連続して現れることをいう. 空文字列, すなわち長さ 0 の文字列は, どんな文字列にも含まれる. 例えば, 文字列 ABRACADABRA には次の文字列が含まれる: ABRA, RAC, D, ACADABRA, ABRACADABRA,空文字列など. 一方, 文字列 ABRACADABRA には次の文字列は含まれない: ABRC, RAA,BA, K など.
</p>
<h2>例</h2>
<p>
例 1: 文字列として ABRACADABRA と ECADADABRBCRDARA が与えられた場合, 両方に含まれる文字列には CA や CADA や ADABR や空文字列などがある. そのうち最も長いのは ADABR であり, その長さは 5 である. 2 個の文字列の中に含まれる ADABR
の位置を以下に示す.
<br><br>
<span>ABRAC<u>ADABR</u>A</span><br>
<span>ECAD<u>ADABR</u>BCRDARA</span><br>
<!-- <p> 図 2-1 例 1 の文字列の中に現れる ADABR の位置</p>-->
</p>
<p>
例 2: 文字列として <span>UPWJCIRUCAXIIRGL</span> と <span>SBQNYBSBZDFNEV</span> が与えられた場合, 両方に含まれる文字列は空文字列のみであり, その長さは 0 である.
</p>
<h2>入力</h2>
<p>
<!-- 入力ファイルのファイル名は input.txt である.-->
入力は複数のデータセットからなる.各データセットは以下の形式で与えられる.
</p>
<p>
入力は 2 行からなり, 1 行目に 1 個目の文字列が, 2 行目に 2 個目の文字列が与えられる. 文字列は英大文字からなり, 各々の文字列の長さは 1 以上 4000 以下である.
</p>
<p>
採点用データのうち, 配点の 30% 分については, 各々の文字列の長さは 1 以上 50以下である.
</p>
<p>
入力の終わりは EOF で示される. データセットの数は 10 を超えない.
</p>
<h2>出力</h2>
<!--
<p>
出力ファイルのファイル名は output.txt である.
</p>
<p>
output.txt は,与えられた 2 個の文字列の両方に含まれる文字列のうち最も長いものの長さだけを含む 1 行からなる.
</p>
-->
<p>
データセットごとに与えられた 2 個の文字列の両方に含まれる文字列のうち最も長いものの長さを 1 行に出力する.
</p>
<h2>入出力例</h2>
<h3>入力例</h3>
<pre>
ABRACADABRA
ECADADABRBCRDARA
UPWJCIRUCAXIIRGL
SBQNYBSBZDFNEV
</pre>
<h3>出力例</h3>
<pre>
5
0
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02196 | <h2>Queries with Six Inequeties</h2>
<p>四つの整数の組<var>(a,b,c,d)</var>の集合が与えられます。</p>
<p><var>j</var>番目のクエリでは、<var>x_j < a_i < y_j < b_i</var>かつ<var>z_j < c_i < w_j < d_i</var>なる<var>i</var>が存在するか判定します。</p>
<h3>入力</h3>
<pre>
<var>N Q</var>
<var>a_1 b_1 c_1 d_1</var>
<var>a_2 b_2 c_2 d_2</var>
:
<var>a_n b_n c_n d_n</var>
<var>x_1 y_1 z_1 w_1</var>
<var>x_2 y_2 z_2 w_2</var>
:
<var>x_q y_q z_q w_q</var>
</pre>
<h3>出力</h3>
<pre>
<var>ans_1</var>
<var>ans_2</var>
:
<var>ans_q</var>
</pre>
<p><var>j</var>行目には、<var>j</var>番目のクエリに対する答えを出力せよ。</p>
<p>条件を満たす添字<var>i</var>が存在するなら<code>Yes</code>、存在しないなら<code>No</code>を出力する。</p>
<h3>制約</h3>
<ul>
<li><var>1 \leq N,Q \leq 10^5 </var></li>
<li><var>1 \leq a_i < b_i \leq 10^5</var></li>
<li><var>1 \leq c_i < d_i \leq 10^5</var></li>
<li><var>1 \leq x_j < y_j \leq 10^5</var></li>
<li><var>1 \leq z_j < w_j \leq 10^5</var></li>
</ul>
<h3>入力例</h3>
<pre>
2 2
14 86 9 121
3 34 3 34
1 14 5 14
1 9 1 9
</pre>
<h3>出力例</h3>
<pre>
No
Yes
</pre>
|
p00001 |
<H1>List of Top 3 Hills</H1>
<p>
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains.
</p>
<p>
Write a program which prints heights of the top three mountains in descending order.
</p>
<H2>Input</H2>
<pre>
Height of mountain 1
Height of mountain 2
Height of mountain 3
.
.
Height of mountain 10
</pre>
<h2>Constraints</h2>
<p>
0 ≤ height of mountain (integer) ≤ 10,000
</p>
<H2>Output</H2>
<pre>
Height of the 1st mountain
Height of the 2nd mountain
Height of the 3rd mountain
</pre>
<H2>Sample Input 1</H2>
<pre>
1819
2003
876
2840
1723
1673
3776
2848
1592
922
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
3776
2848
2840
</pre>
<H2>Sample Input 2</H2>
<pre>
100
200
300
400
500
600
700
800
900
900
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
900
900
800
</pre>
|
p00294 |
<h1>鉄道路線II</h1>
<p>
わたしの住む街には、図のような <var>N</var> 個の駅からなる円環状の鉄道路線があります。この路線の各駅には 0 から <var>N</var>-1 までの番号が順番に割り当てられていて、隣の駅まで100 円で移動することができます。移動はどちらの方向にでも可能です。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_railroad" width="240">
</center>
<br>
<p>
わたしはこの路線上のいくつかの駅で買い物をしたいと思っています。そこで、プログラムを作成して移動費を計算することにしました。ある駅を始点として、買い物をするすべての駅を訪問する最小の費用(円)を求めるプログラムを作成してください。ただし、同じ駅を何度訪問しても良く、どのような順番で駅を訪問しても構いません。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var> <var>M</var> <var>p</var>
<var>d</var><sub>1</sub>
<var>d</var><sub>2</sub>
:
<var>d<sub>M</sub></var>
</pre>
<p>
1行目に駅の数 <var>N</var> (2 ≤ <var>N</var> ≤ 100000)、買い物をする駅の数 <var>M</var> (1 ≤ <var>M</var> ≤ 10000 かつ <var>M</var> < <var>N</var>)、出発する駅の番号 <var>p</var> (0 ≤ <var>p</var> ≤ <var>N</var>-1) が与えられる。続く <var>M</var> 行に買い物をする駅の番号 <var>d<sub>i</sub></var> (0 ≤ <var>d<sub>i</sub></var> ≤ <var>N</var>-1) が与えられる。ただし、<var>d<sub>i</sub></var>は全て異なり、<var>p</var> もまたどの <var>d<sub>i</sub></var> とも異なるものとする。
</p>
<h2>出力</h2>
<p>
最小の費用を1行に出力する。
</p>
<h2>入出力例</h2>
<br>
<h2>入力例1 </h2>
<pre>
5 4 0
1
2
3
4
</pre>
<h2>出力例1</h2>
<pre>
400
</pre>
<h2>入力例2</h2>
<pre>
7 2 1
6
2
</pre>
<h2>出力例2</h2>
<pre>
400
</pre>
|
p02753 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In AtCoder City, there are three stations numbered <var>1</var>, <var>2</var>, and <var>3</var>.</p>
<p>Each of these stations is operated by one of the two railway companies, A and B. A string <var>S</var> of length <var>3</var> represents which company operates each station. If <var>S_i</var> is <code>A</code>, Company A operates Station <var>i</var>; if <var>S_i</var> is <code>B</code>, Company B operates Station <var>i</var>.</p>
<p>To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.</p>
<p>Determine if there is a pair of stations that will be connected by a bus service.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>Each character of <var>S</var> is <code>A</code> or <code>B</code>.</li>
<li><var>|S| = 3</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there is a pair of stations that will be connected by a bus service, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>ABA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Company A operates Station <var>1</var> and <var>3</var>, while Company B operates Station <var>2</var>.</p>
<p>There will be a bus service between Station <var>1</var> and <var>2</var>, and between Station <var>2</var> and <var>3</var>, so print <code>Yes</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>BBA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
<p>Company B operates Station <var>1</var> and <var>2</var>, while Company A operates Station <var>3</var>.</p>
<p>There will be a bus service between Station <var>1</var> and <var>3</var>, and between Station <var>2</var> and <var>3</var>, so print <code>Yes</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>BBB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
<p>Company B operates all the stations. Thus, there will be no bus service, so print <code>No</code>.</p></section>
</div>
</span> |
p03841 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence <var>x</var> of length <var>N</var>.
Determine if there exists an integer sequence <var>a</var> that satisfies all of the following conditions, and if it exists, construct an instance of <var>a</var>.</p>
<ul>
<li><var>a</var> is <var>N^2</var> in length, containing <var>N</var> copies of each of the integers <var>1</var>, <var>2</var>, <var>...</var>, <var>N</var>.</li>
<li>For each <var>1 ≤ i ≤ N</var>, the <var>i</var>-th occurrence of the integer <var>i</var> from the left in <var>a</var> is the <var>x_i</var>-th element of <var>a</var> from the left.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 500</var></li>
<li><var>1 ≤ x_i ≤ N^2</var></li>
<li>All <var>x_i</var> are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there does not exist an integer sequence <var>a</var> that satisfies all the conditions, print <code>No</code>.
If there does exist such an sequence <var>a</var>, print <code>Yes</code> in the first line, then print an instance of <var>a</var> in the second line, with spaces inbetween.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 5 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
1 1 1 2 2 2 3 3 3
</pre>
<p>For example, the second occurrence of the integer <var>2</var> from the left in <var>a</var> in the output is the fifth element of <var>a</var> from the left.
Similarly, the condition is satisfied for the integers <var>1</var> and <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre></section>
</div>
</span> |
p02303 |
<H1>Closest Pair</H1>
<p>
For given <var>n</var> points in metric space, find the distance of the closest points.
</p>
<H2>Input</H2>
<pre>
<var>n</var>
<var>x<sub>0</sub></var> <var>y<sub>0</sub></var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
:
<var>x<sub>n-1</sub></var> <var>y<sub>n-1</sub></var>
</pre>
<p>
The first integer <var>n</var> is the number of points.
</p>
<p>
In the following <var>n</var> lines, the coordinate of the <var>i</var>-th point is given by two real numbers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. Each value is a real number with at most 6 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
Print the distance in a line. The output values should be in a decimal fraction with an error less than 0.000001.
</p>
<H2>Constraints</H2>
<ul>
<li>2 ≤ <var>n</var> ≤ 100,000</li>
<li>-100 ≤ <var>x</var>, <var>y</var> ≤ 100</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
2
0.0 0.0
1.0 0.0
</pre>
<H2>Sample Output 1</H2>
<pre>
1.000000
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
3
0.0 0.0
2.0 0.0
1.0 1.0
</pre>
<H2>Sample Output 2</H2>
<pre>
1.41421356237
</pre> |
p01485 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<h1> Satan Attacks</h1>
<p>
Time Limit: 8 sec / Memory Limit: 64 MB
</p>
<h2> G: 魔王の襲撃</h2>
<p>
伝説の剣を破壊した魔王は,ついに勇者をある遺跡に追い詰めた.
既に勇者は袋の鼠であるが,相手は神々の加護を得た勇者である.
たとえ伝説の剣がなくとも,いかなる奇跡が奴に味方するかわかったものではない.
魔王も伝説の剣の破壊やこれまでの戦闘で,魔力を大量に消費し,疲弊している.
そこで,万全を期すために,強力な使い魔を大量に召喚し,一斉攻撃を仕掛けることにした.
しかし,強力な使い魔を使役するには,魔力を大量に消費してしまう.
万が一,勇者が使い魔による総攻撃を突破した場合に備え,できるだけ魔力を温存したい.
そこで,入り口から使い魔を一度に突入させ,何体の使い魔が一斉に勇者を攻撃できるのか調べることになった.
</p>
<p>
魔王の右腕であるあなたは,低級な使い魔を召喚し,遺跡の構造を調べさせた.
しかし,低級な使い魔を利用したためか,報告された内容は非常にわかりづらいものとなってしまった.
このままでは役に立たないので,仕方なく使い魔の報告を分析することにした.
</p>
<p>
まず,遺跡の入口についてだが,複数の入口がある.
これらの入口は,必ず通路の端またはいくつかの通路が交差した場所にあることがわかった.
また,勇者は入口ではない通路の端か交差した場所にいるようだ.
</p>
<p>
そして,問題は遺跡内の通路である.
この遺跡には魔術的な結界やガーディアンなどは存在しないが,通路が複雑に入り組んでいる.
幸いといっていいのか,通路には特に一方通行系のトラップや,
一度通った通路が二度と通れなくなるようなトラップは存在しないようだ.
もちろん,入る度に遺跡内部全体の構造が変わってしまうようなトラップもない.
使い魔たちは,各通路の情報を,遺跡の中にある通路の2つの端点の座標と,
この通路を同時に通ることができる使い魔の数という形で報告してきた.
</p>
<p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_2368-a" width="500">
</td>
</tr>
<tr>
<td>
<center>
図1
</center>
</td>
</tr>
</table>
</center>
</p>
<p>
使い魔の報告した遺跡内の通路同士は,交差することがある.
二つの通路が一点で交わる場合に,これを一つの交点として数える.
このとき,通れる使い魔の数は,通路の長さに対して比例配分がされる.
例えば図1のように,使い魔が20匹通れる(0,0)と(10,0)を繋ぐ通路に対して,
交点が(4.5,0)にできた場合は,使い魔が9匹通れる(0,0)と(4.5,0)を繋ぐ通路と,
使い魔が11匹通れる(4.5,0)と(10,0)を繋ぐ通路の2つに分割される.
</p>
<p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_2368-b" width="500">
</td>
</tr>
<tr>
<td>
<center>
図2
</center>
</td>
</tr>
</table>
</center>
</p>
<p>
さらに,報告された通路同士は重なることがある.
このときは重なった通路部分同士の和が使い魔の通れる数になる.
例えば図2のように,使い魔が10匹通れる(0,0)と(10,0)を繋ぐ通路と,
使い魔が20匹通れる(2,0)と(12,0)を繋ぐ通路が与えられたときは,
使い魔が2匹通れる(0,0)と(2,0)を繋ぐ通路と,
使い魔が8+16で24匹通れる(2,0)と(10,0)を繋ぐ通路と,
使い魔が4匹通れる(10,0)と(12,0)を繋ぐ通路に分割される.
</p>
<p>
報告された通路の情報を基に,分割や併合を行っていくと,計算上通れる使い魔の数に小数が出ることがある.
使い魔は小さくなったり,半分の大きさに分裂したりはできないため,小数部分は切り捨てて考えればよいだろう.
</p>
<p>
使い魔からの情報をここまで分析したことで,遺跡内の構造が見えてきた.
後は,どれだけの使い魔が一斉に勇者を攻撃できるのか割り出すだけである.
</p>
<h2> Input</h2>
<p>
入力は以下の形式で与えられる.
</p>
<pre>
<i>n</i>
<i>ax<sub>1</sub></i> <i>ay<sub>1</sub></i> <i>bx<sub>1</sub></i> <i>by<sub>1</sub></i> <i>w<sub>1</sub></i>
・・・
<i>ax<sub>n</sub></i> <i>ay<sub>n</sub></i> <i>bx<sub>n</sub></i> <i>by<sub>n</sub></i> <i>w<sub>n</sub></i>
<i>m</i>
<i>cx<sub>1</sub></i> <i>cy<sub>1</sub></i>
・・・
<i>cx<sub>n</sub></i> <i>cy<sub>n</sub></i>
<i>dx</i> <i>dy</i>
</pre>
<p>
入力の形式に含まれる各変数の意味と制約は以下の通りである.
<i>n</i>(0 < <i>n</i> <=50)は建物内の通路の数を表す.
</p>
<p>
(<i>ax<sub>i</sub></i>, <i>ay<sub>i</sub></i>)と(<i>bx<sub>i</sub></i>, <i>by<sub>i</sub></i>) (0 <= <i>ax<sub>i</sub></i>, <i>ay<sub>i</sub></i>, <i>bx<sub>i</sub></i>, <i>by<sub>i</sub></i> <= 100)はある通路の端点を表す .ここで(<i>ax<sub>i</sub></i>, <i>ay<sub>i</sub></i>)≠(<i>bx<sub>i</sub></i>, <i>by<sub>i</sub></i>)であることが保証される.またそれぞれの通路に対して,使い魔が <i>w<sub>i</sub></i> (0 < <i>w<sub>i</sub></i> <= 100)匹通ることができる.
</p>
<p>
<i>m</i>(0 < <i>m</i> <= 10) は入り口の数を表す.(<i>cx<sub>i</sub></i>, <i>cy<sub>i</sub></i>)が入り口の位置を,
(<i>dx</i>, <i>dy</i>) は勇者が隠れている位置を表す.また<i>cx<sub>i</sub></i>, <i>cy<sub>i</sub></i> , <i>dx</i>, <i>dy</i>はすべて少数第6位の数値まで与えられる.入口の場所,勇者が隠れている位置は,通路の端点か交点上である.また分割された通路の長さは,0.000001より大きいことが保証されている.
</p>
<h2> Output</h2>
<p>
勇者が隠れている位置に,同時に襲うことが出来る使い魔の最大の数を出力せよ.
</p>
<h2> Sample Input 1</h2>
<pre>
2
0 0 5 0 10
1 0 6 0 10
1
0.000000 0.000000
6.000000 0.000000
</pre>
<h2> Sample Output 1</h2>
<pre>
2
</pre>
<h2> Sample Input 2</h2>
<pre>
2
3 0 7 0 10
0 0 10 0 100
1
0.000000 0.000000
10.000000 0.000000
</pre>
<h2> Sample Output 2</h2>
<pre>
30
</pre>
<h2> Sample Input 3</h2>
<pre>
2
0 0 5 5 7
0 5 5 0 4
1
0.000000 0.000000
2.500000 2.500000
</pre>
<h2> Sample Output 3</h2>
<pre>
3
</pre>
<h2> Sample Input 4</h2>
<pre>
2
0 0 5 0 9
3 0 8 0 9
1
3.000000 0.000000
5.000000 0.000000
</pre>
<h2> Sample Output 4</h2>
<pre>
7
</pre>
<h2> Sample Input 5</h2>
<pre>
10
30 58 43 79 60
16 68 71 61 66
45 59 66 63 63
19 84 28 42 46
45 82 12 76 68
25 57 31 17 59
75 62 18 41 78
32 77 67 18 46
27 89 29 7 32
26 52 14 38 30
4
25.000000 57.000000
61.708447 62.182561
27.000000 89.000000
27.249448 78.772627
36.776964 68.947403
</pre>
<h2> Sample Output 5</h2>
<pre>
12
</pre>
</body>
</html> |
p03142 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a rooted tree (see Notes) with <var>N</var> vertices numbered <var>1</var> to <var>N</var>.
Each of the vertices, except the root, has a directed edge coming from its parent.
Note that the root may not be Vertex <var>1</var>.</p>
<p>Takahashi has added <var>M</var> new directed edges to this graph.
Each of these <var>M</var> edges, <var>u \rightarrow v</var>, extends from some vertex <var>u</var> to its descendant <var>v</var>.</p>
<p>You are given the directed graph with <var>N</var> vertices and <var>N-1+M</var> edges after Takahashi added edges.
More specifically, you are given <var>N-1+M</var> pairs of integers, <var>(A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M})</var>, which represent that the <var>i</var>-th edge extends from Vertex <var>A_i</var> to Vertex <var>B_i</var>.</p>
<p>Restore the original rooted tree.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>For "tree" and other related terms in graph theory, see <a href="https://ja.wikipedia.org/wiki/%E6%9C%A8_(%E6%95%B0%E5%AD%A6)" target="_blank">the article in Wikipedia</a>, for example.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N</var></li>
<li><var>1 \leq M</var></li>
<li><var>N + M \leq 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>
<li>If <var>i \neq j</var>, <var>(A_i, B_i) \neq (A_j, B_j)</var>.</li>
<li>The graph in input can be obtained by adding <var>M</var> edges satisfying the condition in the problem statement to a rooted tree with <var>N</var> vertices.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var>
<var>:</var>
<var>A_{N-1+M}</var> <var>B_{N-1+M}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.
In the <var>i</var>-th line, print <code>0</code> if Vertex <var>i</var> is the root of the original tree, and otherwise print the integer representing the parent of Vertex <var>i</var> in the original tree.</p>
<p>Note that it can be shown that the original tree is uniquely determined.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
1 2
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
1
2
</pre>
<p>The graph in this input is shown below:</p>
<p><img alt="" src="https://img.atcoder.jp/nikkei2019-qual/ee05880ceecf703f656dd50bf22c573f.png"/></p>
<p>It can be seen that this graph is obtained by adding the edge <var>1 \rightarrow 3</var> to the rooted tree <var>1 \rightarrow 2 \rightarrow 3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 3
2 1
2 3
4 1
4 2
6 1
2 6
4 6
6 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
4
2
0
6
2
</pre></section>
</div>
</span> |
p03512 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider an infinite sequence <var>a_1,</var> <var>a_2,</var> <var>…</var> Initially, the values of all the terms are <var>0</var>, and from this state we will sequentially perform <var>Q</var> operations. The <var>i</var>-th operation <var>(1 ≤ i ≤ Q)</var> is as follows:</p>
<ul>
<li>For every positive integer <var>j</var>, add <var>x_i</var> to the value of <var>a_{j × m_i}</var>.</li>
</ul>
<p>Find the value of the largest term after these <var>Q</var> operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ Q ≤ 299</var></li>
<li><var>2 ≤ m_i ≤ 300</var></li>
<li><var>-10^6 ≤ x_i ≤ 10^6</var></li>
<li>All <var>m_i</var> are distinct.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>Q</var>
<var>m_1</var> <var>x_1</var>
<var>:</var>
<var>m_Q</var> <var>x_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value of the largest term after the <var>Q</var> operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 10
3 -20
6 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The values of each terms in the sequence <var>a_1,</var> <var>a_2,</var> <var>…</var> change as follows:</p>
<ul>
<li>Before the operations: <var>0,</var> <var>0,</var> <var>0,</var> <var>0,</var> <var>0,</var> <var>0,</var> <var>…</var></li>
<li>After the <var>1</var>-st operation: <var>0,</var> <var>10,</var> <var>0,</var> <var>10,</var> <var>0,</var> <var>10,</var> <var>…</var></li>
<li>After the <var>2</var>-nd operation: <var>0,</var> <var>10,</var> <var>-20,</var> <var>10,</var> <var>0,</var> <var>-10,</var> <var>…</var></li>
<li>After the <var>3</var>-rd operation: <var>0,</var> <var>10,</var> <var>-20,</var> <var>10,</var> <var>0,</var> <var>5,</var> <var>…</var></li>
</ul>
<p>The value of the largest term after all the operations is <var>10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
10 -3
50 4
100 -5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
56 114834
72 -149861
100 190757
192 -132693
240 133108
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>438699
</pre></section>
</div>
</span> |
p03007 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> integers, <var>A_1, A_2, ..., A_N</var>, written on a blackboard.</p>
<p>We will repeat the following operation <var>N-1</var> times so that we have only one integer on the blackboard.</p>
<ul>
<li>Choose two integers <var>x</var> and <var>y</var> on the blackboard and erase these two integers. Then, write a new integer <var>x-y</var>.</li>
</ul>
<p>Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>-10^4 \leq A_i \leq 10^4</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>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible value <var>M</var> of the final integer on the blackboard, and a sequence of operations <var>x_i, y_i</var> that maximizes the final integer, in the format below.</p>
<p>Here <var>x_i</var> and <var>y_i</var> represent the integers <var>x</var> and <var>y</var> chosen in the <var>i</var>-th operation, respectively.</p>
<p>If there are multiple sequences of operations that maximize the final integer, any of them will be accepted.</p>
<pre><var>M</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_{N-1}</var> <var>y_{N-1}</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 -1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
-1 1
2 -2
</pre>
<p>If we choose <var>x = -1</var> and <var>y = 1</var> in the first operation, the set of integers written on the blackboard becomes <var>(-2, 2)</var>.</p>
<p>Then, if we choose <var>x = 2</var> and <var>y = -2</var> in the second operation, the set of integers written on the blackboard becomes <var>(4)</var>.</p>
<p>In this case, we have <var>4</var> as the final integer. We cannot end with a greater integer, so the answer is <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
1 1
1 0
</pre></section>
</div>
</span> |
p03457 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point <var>(0, 0)</var> at time <var>0</var>, then for each <var>i</var> between <var>1</var> and <var>N</var> (inclusive), he will visit point <var>(x_i,y_i)</var> at time <var>t_i</var>.</p>
<p>If AtCoDeer is at point <var>(x, y)</var> at time <var>t</var>, he can be at one of the following points at time <var>t+1</var>: <var>(x+1,y)</var>, <var>(x-1,y)</var>, <var>(x,y+1)</var> and <var>(x,y-1)</var>.
Note that <strong>he cannot stay at his place</strong>.
Determine whether he can carry out his plan.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>≤</var> <var>N</var> <var>≤</var> <var>10^5</var></li>
<li><var>0</var> <var>≤</var> <var>x_i</var> <var>≤</var> <var>10^5</var></li>
<li><var>0</var> <var>≤</var> <var>y_i</var> <var>≤</var> <var>10^5</var></li>
<li><var>1</var> <var>≤</var> <var>t_i</var> <var>≤</var> <var>10^5</var></li>
<li><var>t_i</var> <var><</var> <var>t_{i+1}</var> (<var>1</var> <var>≤</var> <var>i</var> <var>≤</var> <var>N-1</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>t_1</var> <var>x_1</var> <var>y_1</var>
<var>t_2</var> <var>x_2</var> <var>y_2</var>
<var>:</var>
<var>t_N</var> <var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If AtCoDeer can carry out his plan, print <code>Yes</code>; if he cannot, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
3 1 2
6 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>For example, he can travel as follows: <var>(0,0)</var>, <var>(0,1)</var>, <var>(1,1)</var>, <var>(1,2)</var>, <var>(1,1)</var>, <var>(1,0)</var>, then <var>(1,1)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
2 100 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>It is impossible to be at <var>(100,100)</var> two seconds after being at <var>(0,0)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
5 1 1
100 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.