question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00594 | <H1>What Color Is The Universe?</H1>
<table>
<tr>
<td valign="top">
<p>
On a clear night, a boy, Campanella looked up at the sky, there were many stars which have different colors such as red, yellow, green, blue, purple, etc. He was watching the stars and just lost track of time. Presently, he wondered,
</p>
</td>
<td valign="top">
<img src="IMAGE1/colorofuniverse.png">
</td>
</tr>
</table>
<center>
<p>
"There are many stars in the space. What color is the universe if I look up it from outside?"
</p>
</center>
<p>
Until he found the answer to this question, he couldn't sleep. After a moment's thought, he proposed a hypothesis,
</p>
<center>
<p>
"When I observe the stars in the sky, if more than half of the stars have the same color, that is the color of the universe."
</p>
</center>
<p>
He has collected data of stars in the universe after consistently observing them. However, when he try to count the number of star, he was in bed sick with a cold. You decided to help him by developing a program to identify the color of the universe.
<p>
<p>
You are given an array <i>A</i>. Let |<i>A</i>| be the number of element in <i>A</i>, and let <i>N<sub>m</sub></i> be the number of <i>m</i> in <i>A</i>. For example, if <i>A</i> = {3, 1, 2, 3, 3, 1, 5, 3}, |<i>A</i>| = 8, <i>N<sub>3</sub></i> = 4, <i>N<sub>1</sub></i> = 2, <i>N<sub>5</sub></i> = 1. Your program have to find <i>m</i> such that:
</p>
<center>
<p> <i>N<sub>m</sub></i> > (|<i>A</i>| / 2 )</p>
</center>
<p>
If there is no such <i>m</i>, you also have to report the fact. There is no
such <i>m</i> for the above example, but for a array <i>A</i> = {5, 2, 5, 3, 4, 5, 5}, 5 is the answer.
</p>
<H2>Input</H2>
<p>
There are several test cases. For each test case, in the first line |<i>A</i>| is given. In the next line, there will be |<i>A</i>| integers. The integers are less than 2<sup>31</sup> and |<i>A</i>| < 1,000,000. The input terminate with a line which contains single 0.
</p>
<H2>Output</H2>
<p>
For each test case, output <i>m</i> in a line. If there is no answer, output "NO COLOR" in a line.
</p>
<H2>Sample Input</H2>
<pre>
8
3 1 2 3 3 1 5 3
7
5 2 5 3 4 5 5
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
NO COLOR
5
</pre>
|
p02053 | <h2>B: Hokkaido University Hard</h2>
<h3>注意</h3>
<p> 問題設定は A 問題と同一のものですが、制約のみが異なりますのでご注意ください。</p>
<h3>物語</h3>
<p> 北海道大学に合格し、新たな生活の始まりに心を躍らせるほむらちゃん。しかし彼女の前には、とてつもなく広いキャンパスが待ち受けていた...。</p>
<p> 「え...次の授業に間に合わないんだけど...」</p>
<h3>問題</h3>
<p> 北海道大学札幌キャンパスは異常に広いことで有名です。札幌キャンパスは縦に <var>H</var> マス、横に <var>W</var> マス並んだ長方形のマス目で表現されます。北から <var>i</var> マス、西から <var>j</var> マス進んだマスを <var>(i,j)</var> で表すことにします。キャンパス内にはいくつか建物があり、マス <var>(i,j)</var> で表される位置に建物がある場合は 'B' 、ない場合は '.' が <var>c_{i,j}</var> に書かれています。</p>
<p> 北海道大学の新入生のほむらちゃんは、キャンパスのあまりの広さに驚愕し、建物間の移動が心配になってきました。そこで、建物のある <var>2</var> つのマスのうち、最も遠い組はどれくらい離れているのかが気になりました。ここで、<var>2</var> つのマスの組 <var>(i,j) , (i',j')</var> の間の距離を <var>|i-i'|+|j-j'|</var> と定義します。</p>
<p> ほむらちゃんは、自分にはこの問題は難しいと思い、同級生のあなたに助けを求めてきました。ほむらちゃんの代わりに答えを求めてください。</p>
<h3>入力形式</h3>
<pre>
<var>H</var> <var>W</var>
<var>c_{11}</var><var>c_{12}</var> <var>...</var> <var>c_{1W}</var>
<var>:</var>
<var>c_{H1}</var><var>c_{H2}</var> <var>...</var> <var>c_{HW}</var>
</pre>
<h3>制約</h3>
<ul>
<li> <var>2 \leq H,W \leq 10^3</var></li>
<li> <var>H,W</var> は整数</li>
<li> <var>c_{i,j}</var> は 'B' か '.' のいずれかである。</li>
<li> <var>c_{i,j}</var> のうち少なくとも <var>2</var> つは 'B' である。</li>
</ul>
<h3>出力形式</h3>
<p>答えを表す整数を <var>1</var> 行に出力せよ。</p>
<h3>入力例 1</h3>
<pre>
3 3
B.B
..B
.BB
</pre>
<h3>出力例 1</h3>
<pre>4</pre>
<ul>
<li><var>(1,1)</var> と <var>(3,3)</var> の <var>2</var> 点間が最長です。</li>
</ul>
<h3>入力例 2</h3>
<pre>
4 3
B..
B..
...
...
</pre>
<h3>出力例 2</h3>
<pre>1</pre>
<ul>
<li>隣り合う位置が最長になる場合もあります。</li>
</ul>
<h3>入力例 3</h3>
<pre>
6 6
...B..
B.B.B.
.B.B.B
...B.B
.B..B.
..B...
</pre>
<h3>出力例 3</h3>
<pre>7</pre>
|
p02403 | <H1>Print a Rectangle</H1>
<p>
Draw a rectangle which has a height of <var>H</var> cm and a width of <var>W</var> cm. Draw a 1-cm square by single '#'.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of two integers <var>H</var> and <var>W</var> separated by a single space.
</p>
<p>
The input ends with two 0 (when both <var>H</var> and <var>W</var> are zero).
</p>
<H2>Output</H2>
<p>
For each dataset, print the rectangle made of <var>H</var> × <var>W</var> '#'.
</p>
<p>
Print a blank line after each dataset.
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <i>H</i> ≤ 300</li>
<li>1 ≤ <i>W</i> ≤ 300</li>
</ul>
<H2>Sample Input</H2>
<pre>
3 4
5 6
2 2
0 0
</pre>
<H2>Sample Output</H2>
<pre>
####
####
####
######
######
######
######
######
##
##
</pre>
|
p01106 |
<h3><u>Folding a Ribbon</u></h3>
<p>
Think of repetitively folding a very long and thin ribbon. First,
the ribbon is spread out from left to right, then it is creased at
its center, and one half of the ribbon is laid over the other. You
can either fold it from the left to the right, picking up the left
end of the ribbon and laying it over the right end, or from the
right to the left, doing the same in the reverse direction. To fold
the already folded ribbon, the whole layers of the ribbon are
treated as one thicker ribbon, again from the left to the right or
the reverse.
</p>
<p>
After folding the ribbon a number of times, one of the layers of the
ribbon is marked, and then the ribbon is completely unfolded
restoring the original state. Many creases remain on the
unfolded ribbon, and one certain part of the ribbon between two
creases or a ribbon end should be found marked. Knowing which
layer is marked and the position of the marked part when the ribbon
is spread out, can you tell all the directions of the repeated
folding, from the left or from the right?
</p>
<p>
The figure below depicts the case of the first dataset of the sample input.
</p><center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_F1-en" width="700">
</center>
<p></p>
<h3>Input</h3>
<p>
The input consists of at most 100 datasets, each being a line
containing three integers.
</p>
<pre>
<i>n i j</i>
</pre>
<p>
The three integers mean the following: The ribbon is folded <i>n</i>
times in a certain order; then, the <i>i</i>-th layer of the folded
ribbon, counted from the top, is marked; when the ribbon is unfolded
completely restoring the original state, the marked part is
the <i>j</i>-th part of the ribbon separated by creases, counted
from the left. Both <i>i</i> and <i>j</i> are one-based, that is,
the topmost layer is the layer 1 and the leftmost part is numbered
1. These integers satisfy 1 ≤ <i>n</i> ≤ 60, 1 ≤ <i>i</i>
≤ 2<sup><i>n</i></sup>, and 1 ≤ <i>j</i> ≤
2<sup><i>n</i></sup>.
</p>
<p>
The end of the input is indicated by a line with three zeros.
</p>
<h3>Output</h3>
<p>
For each dataset, output one of the possible folding sequences that
bring about the result specified in the dataset.
</p>
<p>
The folding sequence should be given in one line consisting
of <i>n</i> characters, each being either <tt>L</tt>
or <tt>R</tt>. <tt>L</tt> means a folding from the left to the
right, and <tt>R</tt> means from the right to the left. The folding
operations are to be carried out in the order specified in the
sequence.
</p>
<h3>Sample Input</h3>
<pre>3 3 2
12 578 2214
59 471605241352156968 431565444592236940
0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>LRR
RLLLRRRLRRLL
LRRRLRRLLRRRRLLLLRLLRRRLRRLLRLLLLLLRLRLLRLRLLLRLRLLRLLRRRLL
</pre>
|
p03091 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a simple connected undirected graph consisting of <var>N</var> vertices and <var>M</var> edges.
The vertices are numbered <var>1</var> to <var>N</var>, and the edges are numbered <var>1</var> to <var>M</var>.</p>
<p>Edge <var>i</var> connects Vertex <var>a_i</var> and <var>b_i</var> bidirectionally.</p>
<p>Determine if three circuits (see Notes) can be formed using each of the edges exactly once.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>A circuit is a cycle allowing repetitions of vertices but not edges.</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, b_i \leq N</var></li>
<li>The given graph is simple and connected.</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If three circuits can be formed using each of the edges exactly once, print <code>Yes</code>; if they cannot, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 9
1 2
1 3
2 3
1 4
1 5
4 5
1 6
1 7
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<ul>
<li>Three circuits can be formed using each of the edges exactly once, as follows:
<div style="text-align: center;">
<img alt="b8c8e2245d45a31cf39749b0a49fc2bd.png" src="https://img.atcoder.jp/agc031/b8c8e2245d45a31cf39749b0a49fc2bd.png">
</img></div></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2
2 3
3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<ul>
<li>Three circuits are needed.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>18 27
17 7
12 15
18 17
13 18
13 6
5 7
7 1
14 5
15 11
7 6
1 9
5 4
18 16
4 6
7 2
7 11
6 3
12 14
5 2
10 5
7 8
10 15
3 15
9 8
7 15
5 16
18 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p01556 |
<h1>Convex-Cut</h1>
<p>N個の頂点からなる凸多角形が与えられる。各頂点の座標は反時計周りに(X<sub>1</sub>, Y<sub>1</sub>), (X<sub>2</sub> ,Y<sub>2</sub>), ……, (X<sub>N</sub>, Y<sub>N</sub>)で表わされる。
点Pを通るどのような直線で凸多角形を切断しても、切断後に得られる2つの凸多角形の面積が等しいような点Pの座標を求めよ。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。
</p><blockquote>
N<br>X<sub>1</sub> Y<sub>1</sub><br>X<sub>2</sub> Y<sub>2</sub><br>……<br>X<sub>N</sub> Y<sub>N</sub><br></blockquote>
<h2>Constraints</h2>
<ul><li><p>入力は全て整数である
</p></li><li><p>3 ≤ N ≤ 50
</p></li><li><p>0 ≤ |X<sub>i</sub>|, |Y<sub>i</sub>| ≤ 1000000
</p></li><li><p>入力の多角形は単純な凸多角形である。
</p></li><li><p>出力は、出力座標を(X, Y)、厳密解を(cX, cY)とした時にmax(|X-cX|, |Y-cY|) ≤ 0.0001を満たす必要がある
</p></li></ul>
<h2>Output</h2>
<p>問題文の条件を満たす点があるのならば、その点の座標を
<blockquote>X Y<br></blockquote>
の形式で出力せよ。
点が存在しない場合は"NA"と1行に出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>4
100 100
0 100
0 0
100 0
</pre>
以下の図に対応する。<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_Convex-Cut-Sample1" height="320px">
<h2>Output for the Sample Input 1</h2>
<pre>50.00000 50.00000
</pre>
<h2>Sample Input 2</h2>
<pre>3
100 100
0 100
0 0
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>NA
</pre>
以下の図に対応する。<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_Convex-Cut-Sample2" height="320px"> |
p01805 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<!-- begin en only -->
<h3><u>Alternate Escape</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>アリスハウス</u></h3>
<!-- end ja only -->
<!-- end en only -->
<!-- begin ja only -->
<p>AliceとBobはボードゲームで遊んでいる.
このボードゲームは, <var>H</var> 行 <var>W</var> 列のマス目が書かれた盤面と1つのコマを使って遊ぶ.
このゲームでは,盤面の左上のマスを1行1列目として,下方向に行を,右方向に列を数える.
</p>
<p>マス同士が隣接する辺と,マスが盤面の外側と接する辺には壁を置けるようになっていて,ゲームの開始時にはそれぞれの辺について壁の有無が指定されている.また,ゲームの開始時には,コマが盤面のマスのいずれか1箇所に置かれている.
</p>
<p>AliceとBobは交互に手番をこなすことでゲームを進める.
ゲームはAliceの手番から始まる.
Aliceの目的は,コマを盤面の外まで動かして,迷路から脱出させることである.
Aliceが1手でできる行動は,コマを今ある位置のマスから,上下左右に隣接するマスのうち,間の辺に壁がない方向のいずれかに移動させることである.
コマの今あるマスが盤面の外側に接していて,間の辺に壁がない場合,そこからコマを脱出させることができる.
</p>
<p>一方,Bobの目的は,コマの脱出を妨害することである.
Bobの手番では,壁の有無を反転させるか,何もせずに手番を終えるかを選ぶことができる.
壁の有無を反転させることを選んだ場合,盤面のすべてのマスの辺について,壁の有無が反転する.
</p>
<p>盤面の初期状態と,コマの初期位置が与えられるので,AliceとBobの両者が最適な行動をとったときに,Aliceがコマを盤面から脱出させられるか判定せよ.
ただし,Aliceの手番においてコマが4方向とも壁で囲まれてしまった場合は脱出できないとみなす.
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>入力は40個以下のデータセットからなる.
それぞれのデータセットは次の形式で与えられる.
</p>
<blockquote><var>H</var> <var>W</var> <var>R</var> <var>C</var><br> <var>Horz</var><sub>1,1</sub> <var>Horz</var><sub>1,2</sub> ... <var>Horz</var><sub>1,<var>W</var></sub><br><var>Vert</var><sub>1,1</sub> <var>Vert</var><sub>1,2</sub> ... <var>Vert</var><sub>1,<var>W</var>+1</sub><br>...<br><var>Vert</var><sub><var>H</var>,1</sub> <var>Vert</var><sub><var>H</var>,2</sub> ... <var>Vert</var><sub><var>H</var>,<var>W</var>+1</sub><br> <var>Horz</var><sub><var>H</var>+1,1</sub> <var>Horz</var><sub><var>H</var>+1,2</sub> ... <var>Horz</var><sub><var>H</var>+1,<var>W</var></sub></blockquote>
<p>1行目には4つの整数 <var>H</var>, <var>W</var> (1 ≤ <var>H</var>, <var>W</var> ≤ 500), <var>R</var>, <var>C</var> (1 ≤ <var>R</var> ≤ <var>H</var>, 1 ≤ <var>C</var> ≤ <var>W</var>) が与えられる.
これらは盤面が <var>H</var> 行 <var>W</var> 列のマス目からなり,コマの初期位置が <var>R</var> 行 <var>C</var> 列目であることを表す.
</p>
<p>続く 2<var>H</var> + 1 行には盤面の初期状態が与えられる.
</p>
<p>2<var>i</var> 行目 (1 ≤ <var>i</var> ≤ <var>H</var> + 1) は,<var>W</var>個の整数 <var>Horz</var><sub><var>i</var>,1</sub>, <var>Horz</var><sub><var>i</var>,2</sub>, ..., <var>Horz</var><sub><var>i</var>,<var>W</var></sub>を含む.
<var>Horz</var><sub><var>i</var>,<var>j</var></sub>は,<var>i</var> 行 <var>j</var> 列目のマスの上側の辺に壁が有るとき1で,無いとき0である.
ただし,<var>Horz</var><sub><var>H</var>+1,<var>j</var></sub>は, <var>H</var> 行 <var>j</var> 列目のマスの下側の辺における壁の有無を表す.
</p>
<p>2<var>i</var> + 1 行目 (1 ≤ <var>i</var> ≤ <var>H</var>) は,<var>W</var> + 1 個の整数 <var>Vert</var><sub><var>i</var>,1</sub>, <var>Vert</var><sub><var>i</var>,2</sub>, ..., <var>Vert</var><sub><var>i</var>,<var>W</var>+1</sub>を含む.
<var>Vert</var><sub><var>i</var>,<var>j</var></sub>は, <var>i</var> 行 <var>j</var> 列目のマスの左側の辺に壁が有るとき1で,無いとき0である.
ただし,<var>Vert</var><sub><var>i</var>,<var>W</var>+1</sub>は, <var>i</var> 行 <var>W</var> 列目のマスの右側の辺における壁の有無を表す.
</p>
<p>入力の終わりは,4つのゼロからなる1行で示される.
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>それぞれのデータセットについて,Aliceがコマを盤面から脱出させられる場合は"<samp>Yes</samp>",できない場合は"<samp>No</samp>"と1行に出力せよ.
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>3 3 2 2
1 1 1
0 0 0 0
1 1 1
0 0 0 0
1 1 1
0 0 0 0
1 1 1
3 3 2 2
1 0 1
1 0 1 1
1 0 0
0 0 0 0
0 0 1
1 1 0 1
1 0 1
1 3 1 1
1 1 1
1 0 0 1
1 0 1
2 2 1 1
1 0
1 0 0
0 0
0 0 0
0 0
0 0 0 0</pre>
<h3>Output for Sample Input</h3>
<pre>Yes
No
Yes
No</pre>
<h3>Hint</h3>
<!-- begin ja only -->
<p>1つ目のデータセットではAliceは次のように動くことでコマを脱出させられる。
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2015_alice-bob" height="493" width="473" /><ol><li> 初期状態
</li><li> Aliceがコマを左に動かす
</li><li> Bobは脱出を阻止するために壁を反転させる
</li><li> Aliceがコマを上に動かす
</li></ol>
<p>Bobが次の手番で壁の有無を反転させてもさせなくても、
Aliceは次の手番でコマを脱出させられる。
</p>
<!-- end ja only -->
|
p03838 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a calculator. It has a display and two buttons.</p>
<p>Initially, the display shows an integer <var>x</var>.
Snuke wants to change this value into another integer <var>y</var>, by pressing the following two buttons some number of times in arbitrary order:</p>
<ul>
<li>Button A: When pressed, the value on the display is incremented by <var>1</var>.</li>
<li>Button B: When pressed, the sign of the value on the display is reversed.</li>
</ul>
<p>Find the minimum number of times Snuke needs to press the buttons to achieve his objective.
It can be shown that the objective is always achievable regardless of the values of the integers <var>x</var> and <var>y</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>x</var> and <var>y</var> are integers.</li>
<li><var>|x|, |y| ≤ 10^9</var></li>
<li><var>x</var> and <var>y</var> are different.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>x</var> <var>y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of times Snuke needs to press the buttons to achieve his objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>Press button A ten times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 -10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>Press button B once.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>-10 -20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>12
</pre>
<p>Press the buttons as follows:</p>
<ul>
<li>Press button B once.</li>
<li>Press button A ten times.</li>
<li>Press button B once.</li>
</ul></section>
</div>
</span> |
p00717 |
<h1><font color="#000">Problem B:</font> Polygonal Line Search</h1>
<p>
Multiple polygonal lines are given on the <i>xy</i>-plane.
Given a list of polygonal lines and a template,
you must find out polygonal lines
which have the same shape as the template.
</p>
<p>
A polygonal line consists of several line segments parallel to <i>x</i>-axis or
<i>y</i>-axis. It is defined by a list of <i>xy</i>-coordinates of vertices from the start-point to the end-point in order,
and always turns 90 degrees at each vertex.
A single polygonal line does not pass the same point twice.
Two polygonal lines have the same shape when they
fully overlap each other only with rotation and translation
within <i>xy</i>-plane (i.e. without magnification or a flip).
The vertices given in reverse order from the start-point to the end-point is the
same as that given in order.
</p>
<p>
Figure 1 shows examples of polygonal lines.
In this figure, polygonal lines A and B have the same shape.
</p>
<p>
Write a program that answers polygonal lines which have the same shape as
the template.
</p>
<center>
<table>
<tr>
<td ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_polygonalLine"></td>
</tr>
<tr>
<td ALIGN="center">Figure 1: Polygonal lines </td>
</tr>
</table>
</center>
<h2>Input</h2>
<p>
The input consists of multiple datasets.
The end of the input is indicated by a line which contains a zero.
</p>
<p>
A dataset is given as follows.
<blockquote>
<I>n</I><BR>
Polygonal line<SUB>0</SUB><BR>
Polygonal line<SUB>1</SUB><BR>
Polygonal line<SUB>2</SUB><BR>
...<BR>
Polygonal line<SUB><I>n</I></SUB>
</blockquote>
<I>n</I> is the number of polygonal lines for the object of search on
<i>xy</i>-plane.
<I>n</I> is an integer, and 1 <= <I>n</I> <= 50.
Polygonal line<SUB>0</SUB> indicates the template.
</p>
<p>
A polygonal line is given as follows.
</p>
<blockquote>
<I>m</I><BR>
<I>x<SUB>1</SUB></I> <I>y<SUB>1</SUB></I><BR>
<I>x<SUB>2</SUB></I> <I>y<SUB>2</SUB></I><BR>
...<BR>
<I>x<SUB>m</SUB></I> <I>y<SUB>m</SUB></I><BR>
</blockquote>
</p>
<p>
<I>m</I> is the number of the vertices of a polygonal line (3 <= <I>m</I> <= 10).
<I>x<SUB>i</SUB></I> and <I>y<SUB>i</SUB></I>, separated by a space,
are the <i>x</i>- and <i>y</i>-coordinates
of a vertex, respectively (-10000 < <I>x<SUB>i</SUB></I> < 10000, -10000 <<I>y<SUB>i</SUB></I> < 10000).
</p>
<h2>Output</h2>
<p>
For each dataset in the input, your program should report numbers assigned to the polygonal lines that have the same shape as the template, in ascending order.
Each number must be written in a separate line without any other characters such as leading or trailing spaces.
</p>
<p>
Five continuous "+"s must be placed in a line at the end of each dataset.
</p>
<h2>Sample Input</h2>
<pre>
5
5
0 0
2 0
2 1
4 1
4 0
5
0 0
0 2
-1 2
-1 4
0 4
5
0 0
0 1
-2 1
-2 2
0 2
5
0 0
0 -1
2 -1
2 0
4 0
5
0 0
2 0
2 -1
4 -1
4 0
5
0 0
2 0
2 1
4 1
4 0
4
4
-60 -75
-60 -78
-42 -78
-42 -6
4
10 3
10 7
-4 7
-4 40
4
-74 66
-74 63
-92 63
-92 135
4
-12 22
-12 25
-30 25
-30 -47
4
12 -22
12 -25
30 -25
30 47
3
5
-8 5
-8 2
0 2
0 4
8 4
5
-3 -1
0 -1
0 7
-2 7
-2 16
5
-1 6
-1 3
7 3
7 5
16 5
5
0 1
0 -2
8 -2
8 0
17 0
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1
3
5
+++++
3
4
+++++
+++++
</pre>
|
p03992 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>This contest is <code>CODE FESTIVAL</code>.
However, Mr. Takahashi always writes it <code>CODEFESTIVAL</code>, omitting the single space between <code>CODE</code> and <code>FESTIVAL</code>.</p>
<p>So he has decided to make a program that puts the single space he omitted.</p>
<p>You are given a string <var>s</var> with <var>12</var> letters.
Output the string putting a single space between the first <var>4</var> letters and last <var>8</var> letters in the string <var>s</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>s</var> contains exactly <var>12</var> letters.</li>
<li>All letters in <var>s</var> are uppercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string putting a single space between the first <var>4</var> letters and last <var>8</var> letters in the string <var>s</var>.
Put a line break at the end.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>CODEFESTIVAL
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>CODE FESTIVAL
</pre>
<p>Putting a single space between the first <var>4</var> letters and last <var>8</var> letters in <code>CODEFESTIVAL</code> makes it <code>CODE FESTIVAL</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>POSTGRADUATE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>POST GRADUATE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>ABCDEFGHIJKL
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>ABCD EFGHIJKL
</pre></section>
</div>
</span> |
p02680 | <span class="lang-en">
<p>Score: <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>There is a grass field that stretches infinitely.</p>
<p>In this field, there is a negligibly small cow. Let <var>(x, y)</var> denote the point that is <var>x\ \mathrm{cm}</var> south and <var>y\ \mathrm{cm}</var> east of the point where the cow stands now. The cow itself is standing at <var>(0, 0)</var>.</p>
<p>There are also <var>N</var> north-south lines and <var>M</var> east-west lines drawn on the field. The <var>i</var>-th north-south line is the segment connecting the points <var>(A_i, C_i)</var> and <var>(B_i, C_i)</var>, and the <var>j</var>-th east-west line is the segment connecting the points <var>(D_j, E_j)</var> and <var>(D_j, F_j)</var>.</p>
<p>What is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print <code>INF</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers between <var>-10^9</var> and <var>10^9</var> (inclusive).</li>
<li><var>1 \leq N, M \leq 1000</var></li>
<li><var>A_i < B_i\ (1 \leq i \leq N)</var></li>
<li><var>E_j < F_j\ (1 \leq j \leq M)</var></li>
<li>The point <var>(0, 0)</var> does not lie on any of the given segments.</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>C_1</var>
<var>:</var>
<var>A_N</var> <var>B_N</var> <var>C_N</var>
<var>D_1</var> <var>E_1</var> <var>F_1</var>
<var>:</var>
<var>D_M</var> <var>E_M</var> <var>F_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If the area of the region the cow can reach is infinite, print <code>INF</code>; otherwise, print an integer representing the area in <var>\mathrm{cm^2}</var>.</p>
<p>(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 6
1 2 0
0 1 1
0 2 2
-3 4 -1
-2 6 3
1 0 1
0 1 2
2 0 2
-1 -4 5
3 -2 4
1 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>13
</pre>
<p>The area of the region the cow can reach is <var>13\ \mathrm{cm^2}</var>.</p>
<p><img alt="Sample 1" src="https://img.atcoder.jp/abc168/education.png" title="Sample 1"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 1
-3 -1 -2
-3 -1 1
-2 -1 2
1 4 -2
1 4 -1
1 4 1
3 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>INF
</pre>
<p>The area of the region the cow can reach is infinite.</p></section>
</div>
</span> |
p00347 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>勢力の予想 </H1>
<p>
信夫くんと静夫くんは長方形の島で領地を取り合うゲームをしています。下の図①のように、島全体は格子状に区切られた正方形の区画でできており、区画にはそこから生じる損得が整数で示されています。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_rectangleGame" width="680"><br/>
</center>
<br/>
<p>
このゲームでは1つの駒を動かして領地の境界線を決めていきます。ゲーム開始時、駒は島の北西端にあります(図①)。この駒を島の南東端まで動かしていったときの駒の軌跡が領地の境界線となります。二人のプレーヤーは交互に駒を動かします。駒は南隣の格子点か東隣の格子点にのみ動かすことができます(図②)。駒が島の端に到達した場合は、南か東のうち動かせる方向に動かします。駒が南東端に到達したらゲーム終了です。
</p>
<p>
ゲーム終了後の境界線から北東側の領域が先攻プレーヤーの領域、南西側の領域が後攻プレーヤーの領
域です(図③)。各プレーヤーの領域内に含まれる、区画から生じる損得の合計がそのプレーヤーのス
コアとなります。二人ともゲームにはかなり慣れており、最終的に自分のスコアから相手のスコアをひ
いた値が一番大きくなるように正確に駒を動かします。
</p>
<br/>
<p>
島の大きさとそれぞれの区画から生じる損得が与えられたとき、ゲーム終了時の結果を計算するプログラムを作成せよ。結果は、信夫くんと静夫くんのスコアの差の絶対値とする。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>W</var> <var>H</var>
<var>s<sub>1,1</sub></var> <var>s<sub>1,2</sub></var> ... <var>s<sub>1,W</sub></var>
<var>s<sub>2,1</sub></var> <var>s<sub>2,2</sub></var> ... <var>s<sub>2,W</sub></var>
:
<var>s<sub>H,1</sub></var> <var>s<sub>H,2</sub></var> ... <var>s<sub>H,W</sub></var>
</pre>
<p>
1行目に島に含まれる東西方向と南北方向の区画の数 <var>W</var>, <var>H</var> (1 ≤ <var>W</var>, <var>H</var> ≤ 1000) が与えられる。続く <var>H</var> 行に <var>i</var> 行 <var>j</var> 列目の区画から生じる損得 <var>s<sub>i,j</sub></var> (-1000 ≤ <var>s<sub>i,j</sub></var> ≤ 1000) が与えられる。ただし、<var>i</var> の値が増加する方向を南、<var>j</var> の値が増加する方向を東とする。
</p>
<h2>Output</h2>
<p>
信夫くんと静夫くんのスコアの差の絶対値を1行に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
2 1
-2 1
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
2 2
2 -3
3 -1
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
5 4
5 3 2 -5 2
2 -4 2 8 -4
2 3 -7 6 7
3 -4 10 -3 -3
</pre>
<h2>Sample Output 3</h2>
<pre>
5
</pre>
|
p01940 |
<h2>C: たったひとつの部分列 - Unique Subsequence -</h2>
<h3>問題</h3>
<p>ある日えびちゃんは、机の上に長さ <var>n</var> のテキスト文字列 <var>T</var> と長さ <var>m</var> のパターン文字列 <var>P</var> (<var>m \leq n</var>) が置かれていることに気づきました。えびちゃんは、文字列に現れる「たったひとつの部分列」が大好きであるため、 <var>P</var> が <var>T</var> のたったひとつの部分列であるかどうかをすぐに調査し始めました。</p>
<p><var>P</var> が <var>T</var> のたったひとつの部分列であるという性質は以下のように表されます。ここで、文字列 <var>X</var> の <var>i</var> 文字目を <var>X_i</var> と書きます。</p>
<ul>
<li> 長さ <var>m</var> の数列 <var>S = (s_1, ..., s_m)</var> (ただし、 <var>s_1 < s_2 < ... < s_m</var>) で、各 <var>i</var> (<var>i = 1, ..., m</var>) について <var>T_{s_i} = P_i</var> である数列 <var>S</var> が一意に定まる。</li>
</ul>
<p>調査を始めてから数時間、えびちゃんは文字列をぐっと睨んでいましたが、文字列が長すぎるために疲れてしまったようです。それを見かねたあなたは、えびちゃんを手伝ってあげることにしました。えびちゃんのために、 <var>P</var> が <var>T</var> のたったひとつの部分列であるならば “yes” を、そうでないならば “no” を出力するプログラムを作成してください。</p>
<h3>入力形式</h3>
<pre>
<var>T</var>
<var>P</var>
</pre>
<p>
<var>1</var> 行目には、テキスト文字列 <var>T</var> が与えられる。
<var>2</var> 行目には、パターン文字列 <var>P</var> が与えられる。
</p>
<h3>制約</h3>
<ul>
<li> <var>1 \leq |P| \leq |T| \leq 5 \times 10^5</var></li>
<li> <var>T</var> および <var>P</var> は英字小文字 ‘a’-’z’ で構成される。</li>
</ul>
<h3>出力形式</h3>
<p><var>P</var> が <var>T</var> のたったひとつの部分列であるならば “yes” を、そうでないならば “no” を1行に出力してください。</p>
<h3>入力例1</h3>
<pre>
aizucamp
azu
</pre>
<h3>出力例1</h3>
<pre>yes</pre>
<h3>入力例2</h3>
<pre>
abracadabra
rada
</pre>
<h3>出力例2</h3>
<pre>no</pre>
<h3>入力例3</h3>
<pre>
hokkaido
dekai
</pre>
<h3>出力例3</h3>
<pre>no</pre> |
p00652 |
<H1>Problem F: Cutting a Chocolate</H1>
<p>
Turtle Shi-ta and turtle Be-ko decided to divide a chocolate.
The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), (<i>w</i>,0), (<i>w</i>,<i>h</i>) and (0,<i>h</i>).
The chocolate has lines for cutting.
They cut the chocolate only along some of these lines.
</p>
<p>
The lines are expressed as follows.
There are <i> m </i> points on the line connected between (0,0) and (0,<i>h</i>), and between (<i>w</i>,0) and (<i>w</i>,<i>h</i>).
Each <i>i</i>-th point, ordered by <i>y</i> value (<i>i</i> = 0 then <i>y</i> =0), is connected as cutting line.
These lines do not share any point where 0 < <i>x</i> < <i>w</i> .
They can share points where <i>x</i> = 0 or <i>x</i> = <i>w </i>.
However, (0, <i>l<sub>i</sub></i> ) = (0,<i>l<sub>j</sub></i> ) and (<i>w</i>,<i>r<sub>i</sub></i> ) = (<i>w</i>,<i>r<sub>j</sub></i> ) implies <i> i </i> = <i> j </i> .
The following figure shows the example of the chocolate.
</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_F1"></center>
<p>
There are <i> n </i> special almonds, so delicious but high in calories on the chocolate.
Almonds are circle but their radius is too small. You can ignore radius of almonds.
The position of almond is expressed as (<i>x</i>,<i>y</i>) coordinate.
</p>
<p>
Two turtles are so selfish. Both of them have requirement for cutting.
</p>
<p>
Shi-ta's requirement is that the piece for her is continuous.
It is possible for her that she cannot get any chocolate.
Assume that the minimum index of the piece is <i> i </i> and the maximum is <i> k </i>.
She must have all pieces between <i> i </i> and <i> k </i>.
For example, chocolate piece 1,2,3 is continuous but 1,3 or 0,2,4 is not continuous.
</p>
<p>
Be-ko requires that the area of her chocolate is at least <i> S </i>.
She is worry about her weight. So she wants the number of almond on her chocolate is as few as possible.
</p>
<p>
They doesn't want to make remainder of the chocolate because the chocolate is expensive.
</p>
<p>
Your task is to compute the minumum number of Beko's almonds if both of their requirment are satisfied.
</p>
<H2>Input</H2>
<p>
Input consists of multiple test cases.<br>
Each dataset is given in the following format.
</p>
<pre>
<i>n</i> <i>m</i> <i>w</i> <i>h</i> <i>S</i>
<i>l<sub>0</sub></i> <i>r<sub>0</sub></i>
...
<i>l<sub>m-1</sub></i> <i>r<sub>m-1</sub></i>
<i>x<sub>0</sub></i> <i>y<sub>0</sub></i>
...
<i>x<sub>n-1</sub></i> <i>y<sub>n-1</sub></i>
</pre>
<p>
The last line contains five 0s.
<i>n</i> is the number of almonds.
<i>m</i> is the number of lines.
<i>w</i> is the width of the chocolate.
<i>h</i> is the height of the chocolate.
<i>S</i> is the area that Be-ko wants to eat.
Input is integer except <i>x<sub>i</sub></i> <i>y<sub>i</sub></i>.
</p>
<p>
Input satisfies following constraints.<br>
1 ≤ <i>n</i> ≤ 30000<br>
1 ≤ <i>m</i> ≤ 30000<br>
1 ≤ <i>w</i> ≤ 200<br>
1 ≤ <i>h</i> ≤ 1000000<br>
0 ≤ <i>S</i> ≤ <i>w*h</i><br>
</p>
<p>
If <i>i</i> < <i> j </i> then <i> l<sub>i</sub> </i> ≤ <i> l<sub>j</sub> </i> and <i> r<sub>i</sub> </i> ≤ <i>r<sub>j</sub></i> and then <i> i </i>-th lines and <i> j </i>-th lines share at most 1 point.
It is assured that <i>l<sub>m-1</sub></i> and <i>r<sub>m-1</sub></i> are <i>h</i>.
<i>x<sub>i</sub> </i> <i>y<sub>i</sub></i> is floating point number with ten digits.
It is assured that they are inside of the chocolate.
It is assured that the distance between points and any lines is at least 0.00001.
</p>
<h2>Output</h2>
<p>
You should output the minumum number of almonds for Be-ko.
</p>
<h2>Sample input</h2>
<pre>
2 3 10 10 50
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 70
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 30
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 40
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
2 3 10 10 100
3 3
6 6
10 10
4.0000000000 4.0000000000
7.0000000000 7.0000000000
0 0 0 0 0
</pre>
<h2>Sample output</h2>
<pre>
1
1
0
1
2
</pre>
|
p02395 |
<H1>Print Many Hello World</H1>
<p>
Write a program which prints 1000 "Hello World".
</p>
<H2>Input</H2>
<p>
There is no input for this problem.
</p>
<H2>Output</H2>
<p>
The output consists of 1000 lines. Print "Hello World" in each line.
</p>
<H2>Sample Input</H2>
<pre>
No input
</pre>
<H2>Sample Output</H2>
<pre>
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
.
.
.
.
.
.
Hello World
</pre> |
p00202 |
<h1>上司のおごり</h1>
<p>
会津太郎さんの会社には、割り切れない事が大嫌いな上司がいます。太郎さんがその上司と食事に行くときは、割り勘で会計をしているのですが、支払金額が参加人数で割り切れないときは、いつも上司がおごってくれています。
</p>
<p>
ある日、太郎さんは食事会の幹事になりました。お金の少ない太郎さんは、その上司を誘ってなんとかおごってもらえるように出来ないか考えました。もう料理屋に注文をしなければならないのですが、まだ何人参加するかは分からないので、どんな人数が参加してもおごってもらえるような注文をしておきたいようです。太郎さんの同期で、同じく食事会に参加する予定のあなたは、太郎さんに協力して、予算額以下で最大のどんな人数でも割り切れない金額を算出することにしました。
</p>
<p>
料理の種類、各料理の料金、予算額を入力とし、予算額以下で最大のどんな数字でも割り切れない合計金額(ただし、 1 と合計金額は除く)を出力するプログラムを作成してください。なお、各種類の料理は複数個注文できますが、全種類の料理を注文する必要はありません。ただし、このような合計金額がない場合は、 NA と出力してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。 入力の終わりはゼロふたつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var> <var>x</var>
<var>v<sub>1</sub></var>
<var>v<sub>2</sub></var>
:
<var>v<sub>n</sub></var>
</pre>
<p>
1 行目に料理の種類 <var>n</var> (1 ≤ <var>n</var> ≤ 30) と予算額 <var>x</var> (1 ≤ <var>x</var> ≤ 1000000) が空白区切りで与えられます。続く<var>n</var> 行に <var>i</var> 種類目の料理の金額を表す整数 <var>v<sub>i</sub></var> (1 ≤ <var>v<sub>i</sub></var> ≤ 1000000) が与えられます。
</p>
<p>
データセットの数は 100 を超えません。
</p>
<H2>Output</H2>
<p>
入力データセットごとに、予算額に最も近い合計金額、または NA を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
4 15000
305
260
129
500
3 400
10
20
30
3 200909
5
9
12
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
14983
NA
200909
</pre>
|
p01043 |
<h1>Problem G: Yu-kun Likes a Treasure</h1>
<h2>Background</h2>
<p>
会津大学付属幼稚園はプログラミングが大好きな子供が集まる幼稚園である。園児の一人であるゆう君は、プログラミングと同じくらい財宝が大好きだ。ゆう君は今日も財宝を探すため洞窟を探索する予定だ。そこでゆう君は洞窟の地図から、洞窟を全て見て回る際に歩く距離を求めるプログラムを書くことにした。
</p>
<h2>Problem</h2>
<p>
洞窟の情報とゆう君の初期位置が与えられる。Fig.1のように、 洞窟は2次元平面上の多角形で表される部屋が、1つ以上繋がった集合で構成される。部屋が別の部屋と接する場合は必ず点で接し、その接点が洞窟の道となり、接点に訪れるとその道を通ったことになる。
</p>
<p>
道は扉で閉ざされており、扉が閉まっている状態でその道を通ることはできない。扉を開くためには部屋の中にちょうど1つだけ存在するボタンを押す必要がある。ボタンは2次元平面上の点として表される。
</p>
<p>
ゆう君はボタンが存在する点を訪れることでボタンを押すことができる。ボタンを押すと部屋にある全ての扉が開く。Fig.1では部屋の中にある丸がボタンを表し、顔のマークがゆう君を、そして矢印が指しているボタンがゆう君のいる場所を表す。ボタンを押して扉を開いた後、道を通るとすぐに全ての扉は閉まる。そのため、そこから別の部屋へと移動するためには再度その部屋の中にあるボタンを押す必要がある。ゆう君は最初、いずれかの部屋の中にあるボタンと同じ場所にいる。
</p>
<center>
<table>
<tr>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_G_00.png" alt="Figure 1" height="250" width="350">
</tr>
<tr>
<td ALIGN="center">Fig. 1</td>
</tr>
</table>
</center>
<p>
Fig. 2 に移動の例を示す。番号の付いている矢印はゆう君の移動経路を表す。
</p>
<p>
次の順番で移動することは可能である。
</p>
<p>
1 -> 2 -> 3 -> 4
</p>
<p>
次の順番で移動することは不可能である。
</p>
<p>
1 -> 4
</p>
<p>
これは、1の経路で移動し部屋同士の接点を訪れるとその瞬間に扉が閉まるからである。
</p>
<center>
<table>
<tr>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_G_01.png" alt="Figure 2" height="250" width="350">
</tr>
<tr>
<td ALIGN="center">Fig. 2</td>
</tr>
</table>
</center>
<p>
ゆう君が洞窟内の全ての道を通り、再度初期位置に戻ってくるまでにかかる移動距離の最小値を出力せよ。ただし、同じ道を何度通っても良い。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>n</var> <var>m</var>
部屋1の情報
部屋2の情報
…
部屋<var>n</var>の情報
</pre>
<p>
<var>n</var>,<var>m</var>はそれぞれ洞窟を構成する部屋を表す多角形の数、ゆう君が最初にいる部屋の番号を表す。
</p>
<p>
部屋の情報は次の形式で与えられる。
</p>
<pre>
<var>p</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
…
<var>x<sub>p</sub></var> <var>y<sub>p</sub></var>
<var>bx</var> <var>by</var>
</pre>
<p>
<var>p</var>は多角形の頂点数を表す。(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>) と (<var>x<sub>i+1</sub></var>,<var>y<sub>i+1</sub></var>) の頂点を繋いだ線分が多角形の一辺である。ただし、<var>p</var>番目の頂点は1番目の頂点と繋がる。 (<var>bx</var>,<var>by</var>) は多角形の内部にあるボタンの位置を表す。多角形は反時計回りで与えられる。
</p>
<h2>Constraints</h2>
<p>
入力は以下の制約を満たす。
</p>
<ul>
<li>1 ≤ <var>n</var> ≤ 15</li>
<li>1 ≤ <var>m</var> ≤ <var>n</var></li>
<li>3 ≤ <var>p</var> ≤ 20</li>
<li>0 ≤ <var>x</var>,<var>y</var>,<var>bx</var>,<var>by</var> ≤ 1000</li>
<li>多角形は反時計回りで与えられる</li>
<li>多角形が別の多角形を内包するようなことはない</li>
<li>多角形はその内部 ( 多角形の辺は含まない ) にちょうど1つだけボタンを持つ</li>
<li>任意の異なる2つの多角形は共通な面積を持たない</li>
<li>任意の異なる2つの多角形<var>a</var>,<var>b</var>において、<var>a</var>と<var>b</var>の接点は高々1つしかない</li>
<li>任意の異なる2つの多角形<var>a</var>,<var>b</var>において、直接または1つ以上の多角形を経由することで<var>a</var>から<var>b</var>へ移動することができる</li>
</ul>
<h2>Output</h2>
<p>
ゆう君が初期位置から全ての道を通って再度初期位置に戻ってくるまでにかかる移動の距離の総和の最小値を出力せよ。小数点以下は何桁数字を出力しても構わない。ただし、解答の誤差は0.00001(10<sup>-5</sup>)を超えてはならない。
</p>
<h2>Sample Input1</h2>
<pre>
3 1
4
0 4
2 4
2 7
0 7
1 6
5
1 0
6 0
4 5
2 2
1 4
4 2
3
2 6
6 4
6 7
5 6
</pre>
<h2>Sample Output1</h2>
<pre>
14.6502815399
</pre>
<h2>Sample Input2</h2>
<pre>
3 2
3
0 2
3 5
0 5
1 4
3
1 0
4 0
1 3
2 1
3
2 2
4 3
2 4
3 3
</pre>
<h2>Sample Output2</h2>
<pre>
8.0644951022
</pre>
<h2>Sample Input2</h2>
<pre>
4 4
3
0 5
3 8
0 8
1 7
3
1 3
4 3
1 6
2 4
5
2 0
7 0
7 2
3 2
2 3
6 1
3
6 2
7 7
2 7
6 6
</pre>
<h2>Sample Output2</h2>
<pre>
18.9356648257
</pre>
|
p03584 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>Seisu-ya</em>, a store specializing in non-negative integers, sells <var>N</var> non-negative integers. The <var>i</var>-th integer is <var>A_i</var> and has a <em>utility</em> of <var>B_i</var>.
There may be multiple equal integers with different utilities.</p>
<p>Takahashi will buy some integers in this store. He can buy a combination of integers whose <em>bitwise OR</em> is less than or equal to <var>K</var>. He wants the sum of utilities of purchased integers to be as large as possible.</p>
<p>Find the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq K < 2^{30}</var></li>
<li><var>0 \leq A_i < 2^{30}(1\leq i\leq N)</var></li>
<li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_1</var> <var>B_1</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the maximum possible sum of utilities of purchased integers.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>Buy <var>2</var> and <var>3</var> to achieve the maximum possible total utility, <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 6
3 3
4 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
<p>Buy <var>2</var> and <var>4</var> to achieve the maximum possible total utility, <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>32
</pre></section>
</div>
</span> |
p01413 |
<H1>G: Quest of Merchant</H1>
<p>
ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした.
</p>
<p>
今日の修行は,街を駆け回り交易を行うことで,商売の力を手にしようというものである.
</p>
<p>
今後の修行のためにも,できるだけ多くの資金を稼ぎたい.
</p>
<p>
この世界は,東西南北方向の道路が等間隔に並んでいて,碁盤状になっている.唯一存在する市場の位置を (0, 0),街には <i>x</i> 座標,<i>y</i> 座標が定まっている (座標が整数値の点が交差点に対応する).うさぎは道路に沿ってのみ移動することができ,隣接する交差点間を移動するのに 1 分を要する.いくつかの交差点には街がある.交易では,街で商品を買い,市場にて販売することによって価格の差の分の利益を得る.
</p>
<p>
うさぎの初期資金は十分にあり,お金が足りないから商品が購入できない,といったことはない.だが,それぞれの商品には重さがあり,うさぎは重さの合計が <i>W</i> までの商品しか同時に持ち運ぶことができない.よって,街に商品を仕入れに行ったり市場に戻ったりを繰り返すことになる.場合によっては,複数の街で商品を購入してから市場に戻ることになるかもしれない.
</p>
<p>
街での商品の購入や,市場での商品の販売は一瞬で行えるものとする.また,街にある商品が品切れになってしまうことは有り得ず,無限に購入することが可能である.
</p>
<p>
うさぎは,今回売買を行おうとしている各商品の名前,1 個あたりの重さおよび販売価格と,各街の <i>x</i> 座標,<i>y</i> 座標および販売商品の名前と価格を,データにまとめた.うさぎは今,市場がある (0, 0) の位置にいる.プログラムを使って,制限時間 <i>T</i> 分の間にどれだけ稼ぐことが可能か調べたい.
</p>
<H2>Input</H2>
<pre>
<i>N</i> <i>M</i> <i>W</i> <i>T</i>
<i>S</i><sub>1</sub> <i>V</i><sub>1</sub> <i>P</i><sub>1</sub>
...
<i>S</i><sub><i>M</i></sub> <i>V</i><sub><i>M</i></sub> <i>P</i><sub><i>M</i></sub>
<i>L</i><sub>1</sub> <i>X</i><sub>1</sub> <i>Y</i><sub>1</sub>
<i>R</i><sub>1,1</sub> <i>Q</i><sub>1,1</sub>
...
<i>R</i><sub>1,<i>L</i><sub>1</sub></sub> <i>Q</i><sub>1,<i>L</i><sub>1</sub></sub>
...
<i>L</i><sub><i>N</i></sub> <i>X</i><sub><i>N</i></sub> <i>Y</i><sub><i>N</i></sub>
<i>R</i><sub><i>N</i>,1</sub> <i>Q</i><sub><i>N</i>,1</sub>
...
<i>R</i><sub><i>N</i>,<i>L</i><sub><i>N</i></sub></sub> <i>Q</i><sub><i>N</i>,<i>L</i><sub><i>N</i></sub></sub>
</pre>
<p>
<i>N</i> は街の数,<i>M</i> は商品の種類数である.<i>S</i><sub><i>i</i></sub>, <i>V</i><sub><i>i</i></sub>, <i>P</i><sub><i>i</i></sub> (1 ≤ <i>i</i> ≤ <i>M</i>) はそれぞれ,<i>i</i> 番目の商品の名前,1 個あたりの重さ,1 個あたりの販売価格である.
街は 1 以上 <i>N</i> 以下の整数で表される.<i>L</i><sub><i>j</i></sub>, <i>X</i><sub><i>j</i></sub>, <i>Y</i><sub><i>j</i></sub> (1 ≤ <i>j</i> ≤ <i>N</i>) はそれぞれ,街 <i>j</i> で売られている商品の種類数,街 <i>j</i> の <i>x</i> 座標,<i>y</i> 座標である.<i>R</i><sub><i>j</i>,<i>k</i></sub>, <i>Q</i><sub><i>j</i>,<i>k</i></sub> (1 ≤ <i>j</i> ≤ <i>N</i>,1 ≤ <i>k</i> ≤ <i>L</i><sub><i>j</i></sub>) はそれぞれ,街 <i>j</i> で売られている <i>k</i> 番目の商品の名前,価格である.
</p>
<p>
1 ≤ <i>N</i> ≤ 7,1 ≤ <i>M</i> ≤ 7,1 ≤ <i>W</i> ≤ 10,000,1 ≤ <i>T</i> ≤ 10,000,1 ≤ <i>V</i><sub><i>i</i></sub> ≤ <i>W</i>,1 ≤ <i>P</i><sub><i>i</i></sub> ≤ 10,000,1 ≤ <i>L</i><sub><i>j</i></sub> ≤ <i>M</i>,-10,000 ≤ <i>X</i><sub><i>j</i></sub> ≤ 10,000,-10,000 ≤ <i>Y</i><sub><i>j</i></sub> ≤ 10,000,1 ≤ <i>Q</i><sub><i>j</i>, <i>k</i></sub> ≤ 10,000 を満たす.商品の名前はアルファベット小文字からなる長さが 1 以上 7 以下の文字列である.その他の値はすべて整数である.<i>S</i><sub><i>i</i></sub> はすべて異なる.(<i>X</i><sub><i>j</i></sub>, <i>Y</i><sub><i>j</i></sub>) として同一の組は複数回現れず,(<i>X</i><sub><i>j</i></sub>, <i>Y</i><sub><i>j</i></sub>) = (0, 0) となることはない.
各 <i>j</i> に対して <i>R</i><sub><i>j</i>, <i>k</i></sub> はすべて異なり,各 <i>R</i><sub><i>j</i>,<i>k</i></sub> はいずれかの <i>S</i><sub><i>i</i></sub> に一致する.
</p>
<H2>Output</H2>
<p>
うさぎが得られる最大の利益を 1 行に出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
2 2 100 20
alfalfa 10 10
carrot 5 10
1 1 6
carrot 4
1 -3 0
alfalfa 5
</pre>
<H2>Sample Output 1</H2>
<pre>
170
</pre>
<H2>Sample Input 2</H2>
<pre>
2 3 100 20
vim 10 10
emacs 5 10
vstudio 65 100
2 1 6
emacs 4
vstudio 13
3 -3 0
vim 5
emacs 9
vstudio 62
</pre>
<H2>Sample Output 2</H2>
<pre>
183
</pre> |
p03300 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>2N</var>, containing <var>N</var> occurrences of <code>a</code> and <var>N</var> occurrences of <code>b</code>.</p>
<p>You will choose some of the characters in <var>S</var>. Here, for each <var>i = 1,2,...,N</var>, it is not allowed to choose exactly one of the following two: the <var>i</var>-th occurrence of <code>a</code> and the <var>i</var>-th occurrence of <code>b</code>. (That is, you can only choose both or neither.) Then, you will concatenate the chosen characters (without changing the order).</p>
<p>Find the lexicographically largest string that can be obtained in this way.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 3000</var></li>
<li><var>S</var> is a string of length <var>2N</var> containing <var>N</var> occurrences of <code>a</code> and <var>N</var> occurrences of <code>b</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically largest string that satisfies the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
aababb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>abab
</pre>
<p>A subsequence of <var>T</var> obtained from taking the first, third, fourth and sixth characters in <var>S</var>, satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
bbabaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>bbabaa
</pre>
<p>You can choose all the characters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
bbbaabbabaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>bbbabaaa
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>9
abbbaababaababbaba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>bbaababababa
</pre></section>
</div>
</span> |
p01297 |
<H1><font color="#000">Problem E:</font> Safe Area</H1>
<p>
Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams
from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan
moves a circular-shaped machine within the screen, in such a way it does not overlap a laser
beam. As in many shooters, the machine is destroyed when the overlap happens.
</p>
<p>
Nathan is facing an uphill stage. Many enemies attack simultaneously in this stage, so eventually
laser beams fill out almost all of the screen. Surprisingly, it is even possible he has no "safe area" on the screen. In other words, the machine cannot survive wherever it is located in some
cases.
</p>
<p>
The world is as kind as it is cruel! There is a special item that helps the machine to survive
any dangerous situation, even if it is exposed in a shower of laser beams, for some seconds. In
addition, another straight line (called "a warning line") is drawn on the screen for a few seconds
before a laser beam is emit along that line.
</p>
<p>
The only problem is that Nathan has a little slow reflexes. He often messes up the timing to
use the special item. But he knows a good person who can write a program to make up his slow
reflexes - it's you! So he asked you for help.
</p>
<p>
Your task is to write a program to make judgement whether he should use the item or not, for
given warning lines and the radius of the machine.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset corresponds to one situation with warning
lines in the following format:
</p>
<p>
<i>W H N R</i><br>
<i>x</i><sub>1,1</sub> <i>y</i><sub>1,1</sub> <i>x</i><sub>1,2</sub> <i>y</i><sub>1,2</sub> <i>t</i><sub>1</sub><br>
<i>x</i><sub>2,1</sub> <i>y</i><sub>2,1</sub> <i>x</i><sub>2,2</sub> <i>y</i><sub>2,2</sub> <i>t</i><sub>2</sub><br>
...<br>
<i>x</i><sub><i>N</i>,1</sub> <i>y</i><sub><i>N</i>,1</sub> <i>x</i><sub><i>N</i>,2</sub> <i>y</i><sub><i>N</i>,2</sub> <i>t<sub>N</sub></i><br>
</p>
<p>
The first line of a dataset contains four integers <i>W</i>, <i>H</i>, <i>N</i> and <i>R</i> (2 < <i>W</i> ≤ 640, 2 < <i>H</i> ≤ 480,
0 ≤ <i>N</i> ≤ 100 and 0 < <i>R</i> < min{<i>W</i>, <i>H</i>}/2). The first two integers <i>W</i> and <i>H</i> indicate the width
and height of the screen, respectively. The next integer <i>N</i> represents the number of laser beams.
</p>
<p>
The last integer <i>R</i> indicates the radius of the machine. It is guaranteed that the output would
remain unchanged if the radius of the machine would become larger by 10<sup>-5</sup> than <i>R</i>.
</p>
<p>
The following <i>N</i> lines describe the <i>N</i> warning lines. The (<i>i</i>+1)-th line of the dataset corresponds
to the <i>i</i>-th warning line, which is represented as a straight line which passes through two given
different coordinates (<i>x</i><sub><i>i</i>,1</sub>, <i>y</i><sub><i>i</i>,1 </sub>) and (<i>x</i><sub><i>i</i>,2</sub> , <i>y</i><sub><i>i</i>,2</sub> ). The last integer <i>t<sub>i</sub></i> indicates the thickness of the
laser beam corresponding to the <i>i</i>-th warning line.
</p>
<p>
All given coordinates (<i>x</i>, <i>y</i>) on the screen are a pair of integers (0 ≤ <i>x</i> ≤ <i>W</i>, 0 ≤ <i>y</i> ≤ <i>H</i>). Note
that, however, the machine is allowed to be located at non-integer coordinates during the play.
</p>
<p>
The input is terminated by a line with four zeros. This line should not be processed.
</p>
<H2>Output</H2>
<p>
For each case, print "<span>Yes</span>" in a line if there is a safe area, or print "<span>No</span>" otherwise.
</p>
<H2>Sample Input</H2>
<pre>
100 100 1 1
50 0 50 100 50
640 480 1 1
0 0 640 480 100
0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
No
Yes
</pre>
|
p03750 | <span class="lang-en">
<p>Score : <var>2000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cards. The two sides of each of these cards are distinguishable.
The <var>i</var>-th of these cards has an integer <var>A_i</var> printed on the front side, and another integer <var>B_i</var> printed on the back side.
We will call the deck of these cards <var>X</var>.
There are also <var>N+1</var> cards of another kind.
The <var>i</var>-th of these cards has an integer <var>C_i</var> printed on the front side, and nothing is printed on the back side.
We will call this another deck of cards <var>Y</var>.</p>
<p>You will play <var>Q</var> rounds of a game.
Each of these rounds is played independently.
In the <var>i</var>-th round, you are given a new card. The two sides of this card are distinguishable.
It has an integer <var>D_i</var> printed on the front side, and another integer <var>E_i</var> printed on the back side.
A new deck of cards <var>Z</var> is created by adding this card to <var>X</var>.
Then, you are asked to form <var>N+1</var> pairs of cards, each consisting of one card from <var>Z</var> and one card from <var>Y</var>.
Each card must belong to exactly one of the pairs.
Additionally, for each card from <var>Z</var>, you need to specify which side to <em>use</em>.
For each pair, the following condition must be met:</p>
<ul>
<li>(The integer printed on the used side of the card from <var>Z</var>) <var> \leq </var> (The integer printed on the card from <var>Y</var>)</li>
</ul>
<p>If it is not possible to satisfy this condition regardless of how the pairs are formed and which sides are used, the score for the round will be <var>-1</var>.
Otherwise, the score for the round will be the count of the cards from <var>Z</var> whose front side is used.</p>
<p>Find the maximum possible score for each round.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq A_i ,B_i ,C_i ,D_i ,E_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>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>
<var>C_1</var> <var>C_2</var> <var>..</var> <var>C_{N+1}</var>
<var>Q</var>
<var>D_1</var> <var>E_1</var>
<var>D_2</var> <var>E_2</var>
<var>:</var>
<var>D_Q</var> <var>E_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each round, print the maximum possible score in its own line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4 1
5 3
3 1
1 2 3 4
3
5 4
4 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
1
2
</pre>
<p>For example, in the third round, the cards in <var>Z</var> are <var>(4,1),(5,3),(3,1),(2,3)</var>.
The score of <var>2</var> can be obtained by using front, back, back and front sides of them, and pair them with the fourth, third, first and second cards in <var>Y</var>, respectively.
It is not possible to obtain a score of <var>3</var> or greater, and thus the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
7 1
9 7
13 13
11 8
12 9
16 7 8 6 9 11
7
6 11
7 10
9 3
12 9
18 16
8 9
10 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
3
3
1
-1
3
2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9
89 67
37 14
6 1
42 25
61 22
23 1
63 60
93 62
14 2
67 96 26 17 1 62 56 92 13 38
11
93 97
17 93
61 57
88 62
98 29
49 1
5 1
1 77
34 1
63 27
22 66
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
9
8
7
7
9
9
10
9
7
9
</pre></section>
</div>
</span> |
p02842 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid <var>N</var> yen (the currency of Japan) for it.</p>
<p>The consumption tax rate for foods in this shop is <var>8</var> percent. That is, to buy an apple pie priced at <var>X</var> yen before tax, you have to pay <var>X \times 1.08</var> yen (rounded down to the nearest integer).</p>
<p>Takahashi forgot the price of his apple pie before tax, <var>X</var>, and wants to know it again. Write a program that takes <var>N</var> as input and finds <var>X</var>. We assume <var>X</var> is an integer.</p>
<p>If there are multiple possible values for <var>X</var>, find any one of them. Also, Takahashi's memory of <var>N</var>, the amount he paid, may be incorrect. If no value could be <var>X</var>, report that fact.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 50000</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If there are values that could be <var>X</var>, the price of the apple pie before tax, print any one of them.<br/>
If there are multiple such values, printing any one of them will be accepted.<br/>
If no value could be <var>X</var>, print <code>:(</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>432
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>400
</pre>
<p>If the apple pie is priced at <var>400</var> yen before tax, you have to pay <var>400 \times 1.08 = 432</var> yen to buy one.<br/>
Otherwise, the amount you have to pay will not be <var>432</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1079
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>:(
</pre>
<p>There is no possible price before tax for which you have to pay <var>1079</var> yen with tax.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>927
</pre>
<p>If the apple pie is priced <var>927</var> yen before tax, by rounding down <var>927 \times 1.08 = 1001.16</var>, you have to pay <var>1001</var> yen.</p></section>
</div>
</span> |
p00486 |
<H1>歩くサンタクロース(Walking Santa) </H1>
<p>
昨年末,サンタクロースはJOI 村の子供たちにクリスマスプレゼントを渡すのを忘れてしまった.そこで,お詫びの気持ちとして子供たちにチョコレートケーキを届けることにした.届けるべき日は明日に迫っているので,そろそろ移動計画を考えなければならない.
</p>
<p>
JOI 村は,南北方向にまっすぐに伸びる<i>W</i> 本の道路と,東西方向にまっすぐに伸びる<i>H</i> 本の道路により,碁盤の目の形に区分けされている. 南北方向の<i>W</i> 本の道路には,西から順に1, 2, ... , <i>W</i> の番号が付けられており,東西方向の<i>H</i> 本の道路には,南から順に1, 2, ... , <i>H</i> の番号が付けられている. 西から<i>x</i> 番目の南北方向の道路と,南から<i>y</i> 番目の東西方向の道路が交わる交差点を(<i>x</i>, <i>y</i>) で表す. JOI 村には<i>N</i> 軒の家があり,それらはいずれかの交差点に位置している. サンタクロースは道路に沿ってのみ移動することができる. 隣り合う交差点の間を移動するのにかかる時間を1 とする.
</p>
<p>
JOI 村のすべての家には子供がいるので,サンタクロースはJOI 村のすべての家に1 個ずつチョコレートケーキを届けてまわらなければならない. 大切なチョコレートケーキを持ってトナカイと空を飛びまわるのはやや危険であるので,サンタクロースとトナカイはJOI 村のいずれかの交差点に降り立ち,サンタクロースがそこから歩いてチョコレートケーキを届けることにした. サンタクロースは同時に2 個以上のチョコレートケーキを運んで歩くことはしない.つまり,サンタクロースはチョコレートケーキを1 軒の家に届けるたびに降り立った交差点に戻る.
</p>
<p>
サンタクロースは,JOI 村に降り立ってからすべての家にチョコレートケーキを届けるまでの所要時間が最小になるような移動計画を選ぶことにした.ここで,最後の家にチョコレートケーキを届けてから降り立った交差点に戻るまでの時間は所要時間に含めないことに注意せよ.また,移動にかかる時間以外は考えない.
</p>
<h2>課題</h2>
<p>
家の位置の情報が与えられたとき,サンタクロースが降り立つ交差点をうまく選んだ場合の,JOI 村に降り立ってからすべての家にチョコレートケーキを届けるまでの所要時間の最小値と,所要時間を最小にするために降り立つべき交差点の位置を求めるプログラムを作成せよ.
</p>
<h2>制限</h2>
<p>
1 ≤ <i>W</i> ≤ 1000000000 = 10<sup>9</sup> 南北方向に伸びる道路の本数<br>
1 ≤ <i>H</i> ≤ 1000000000 = 10<sup>9</sup> 東西方向に伸びる道路の本数<br>
1 ≤ <i>N</i> ≤ 100000 = 10<sup>5</sup> 家の数<br>
1 ≤ <i>X<sub>i</sub></i> ≤ <i>W</i> <i>i</i> 番目の家の位置の, 南北方向に伸びる道路の番号<br>
1 ≤ <i>Y<sub>i</sub></i> ≤ <i>H</i> <i>i</i> 番目の家の位置の, 東西方向に伸びる道路の番号
</p>
<h2>入力</h2>
<p>
標準入力から以下の入力を読み込め.
</p>
<ul>
<li> 1 行目には各方向の道路の本数を表す整数 <i>W</i>, <i>H</i> が空白を区切りとして書かれている.</li>
<li> 2 行目には家の数を表す整数<i>N</i> が書かれている.</li>
<li> 続く<i>N</i> 行には,家の位置の情報が書かれている.<i>i</i> + 2 行目(1 ≤ <i>i</i> ≤ <i>N</i>) には整数<i>X<sub>i</sub></i>, <i>Y<sub>i</sub></i> が空白を区切りとして書かれており,<i>i</i> 番目の家が交差点(<i>X<sub>i</sub></i>, <i>Y<sub>i</sub></i>) に位置していることを表す.これら<i>N</i> 個の交差点はすべて異なる.
</ul>
<h2>出力</h2>
<p>
標準出力に以下のデータを出力せよ.
</p>
<ul>
<li> 1 行目には所要時間の最小値を表す1 つの整数が書かれていなければならない.</li>
<li> 2 行目には所要時間を最小にするために降り立つべき交差点が(<i>x</i>, <i>y</i>) であるとき,2 つの整数<i>x</i>, <i>y</i> がこの順に空白を区切りとして書かれていなければならない.適切な交差点が複数ある場合は,そのうち最も西にある(つまり,<i>x</i> の値が小さい) 交差点を, それでも1 つに定まらない場合は, さらにそのうちで最も南にある(つまり,<i>y</i> の値が小さい) 交差点を選べ.
</ul>
<h2>注意</h2>
<p>
この問題では,扱う整数の範囲が32 ビットに収まらない可能性があることに注意せよ.
</p>
<h2>採点基準</h2>
<p>
採点用データのうち,配点の40%分については,<i>N</i> ≤ 1000 を満たす.<br>
採点用データのうち,配点の10%分については,<i>W</i> ≤ 50, <i>H</i> ≤ 50, <i>N</i> ≤ 1000 を満たす.
</p>
<h2>入出力の例</h2>
<h3>入力例1</h3>
<pre>
5 4
3
1 1
3 4
5 3
</pre>
<h3>出力例1</h3>
<pre>
10
3 3
</pre>
<p>
たとえば,次のような移動計画により所要時間を最小にできる.
</p>
<ul>
<li> 交差点(3; 3) に降り立つ.</li>
<li> 交差点(3; 4) に位置している家にチョコレートケーキを届ける.ここまでの経過時間は1 である.</li>
<li> 交差点(3; 3) に戻る.ここまでの経過時間は2 である.</li>
<li> 交差点(5; 3) に位置している家にチョコレートケーキを届ける.ここまでの経過時間は4 である.</li>
<li> 交差点(3; 3) に戻る.ここまでの経過時間は6 である.</li>
<li> 交差点(1; 1) に位置している家にチョコレートケーキを届ける.ここまでの経過時間は10 である.</li>
</ul>
<br>
<h3>入力例2</h3>
<pre>
4 6
8
1 3
3 2
4 4
2 5
2 3
3 3
3 4
2 4
</pre>
<h3>出力例2</h3>
<pre>
21
2 3
</pre>
<p>
家がある交差点に降り立ってもよいことに注意せよ.
</p>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div> |
p02141 | <h1>Problem E: Donut Hole</h1>
<h2>Problem</h2>
<p>
あなたはACPCのために横$W$縦$H$の長方形で平べったく、穴のないドーナツを持参しました。<br>
このドーナツを$2$次元平面上の座標$(0,0)$にドーナツの中心を重ね、長さがHの辺と$y$軸が平行になるように置きます。<br>
</p>
<p>
ACPC$1$日目にあなたは座標($x$,$y$)を中心に横$w$縦$h$の範囲に存在するドーナツを食べました。<br>
$2$日目と$3$日目に食べる量を等しくしたいあなたは、座標$(0,0)$を通る直線でドーナツを分割し、直線の片側の領域にあるドーナツの面積の総和がもう片側の領域にあるドーナツの面積の総和と等しくなっているようにしたいと考えています。<br>
</p>
<p>
そのような直線の傾きを一つ求めてください。<br>
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
$W$ $H$ $w$ $h$ $x$ $y$
</pre>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$1 \lt h \lt H \lt 10^6$</li>
<li>$1 \lt w \lt W \lt 10^6$</li>
<li>$1 \le y \le (h/2+H-1)-H/2$</li>
<li>$1 \le x \le (w/2+W-1)-W/2$</li>
<li>$W$,$H$,$w$,$h$は偶数</li>
</ul>
<h2>Output</h2>
<p>直線の傾きを一行に出力せよ。なお、絶対誤差または相対誤差が$10^{-6}$以下であれば正解となる。</p>
<h2>Sample Input 1</h2>
<pre>
6000 5000 20 10 400 300
</pre>
<h2>Sample Output 1</h2>
<pre>
0.75
</pre>
<h2>Sample Input 2</h2>
<pre>
10 10 8 8 8 8
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
|
p00469 |
<H1>カード並べ</H1>
<h2>問題</h2>
<p>
花子さんは n 枚(4 ≤ n ≤ 10)のカードを並べて遊んでいる.
それぞれのカードには 1 以上 99 以下の整数が 1 つずつ書かれている.
花子さんは,これらのカードの中から k 枚(2 ≤ k ≤ 4)を選び,
横一列に並べて整数を作ることにした.
花子さんは全部で何種類の整数を作ることができるだろうか.
</p>
<p>
例えば,1, 2, 3, 13, 21 の 5 枚のカードが与えられ,そこから 3 枚を選び整数を作ることを考える.
2, 1, 13 をこの順に並べると,整数 2113 を作ることができる.
また,21, 1, 3 をこの順に並べても,同じ整数 2113 を作ることができる.
このように,異なるカードの組み合わせから同じ整数が作られることもある.
</p>
<p>
n 枚のカードに書かれた整数が与えられたとき,
その中から k 枚を選び,横一列に並べることで作ることができる整数の個数を求めるプログラムを作成せよ.
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる.各データセットは以下の形式で与えられる.
</p>
<p>
各データセットは 2+n 行からなる.
1 行目にはカードの枚数 n (4 ≤ n ≤ 10)が,
2 行目にはカードを選ぶ枚数 k (2 ≤ k ≤ 4)が書かれている.
2+i 行目(1 ≤ i ≤ n)には i 枚目のカードに書かれている 1 以上 99 以下の整数が書かれている.
</p>
<p>
n, k がともに 0 のとき入力の終了を示す.データセットの数は 5 を超えない.
</p>
<h2>出力</h2>
<p>
データセットごとに,花子さんが作ることができる整数の個数を1 行に出力する.
</p>
<h2>入出力例</h2>
<h3>入力例</h3>
<pre>
4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0
</pre>
<h3>出力例</h3>
<pre>
7
68
</pre>
<p>
1つ目の入力例 において,
1, 2, 12, 1 の 4 枚のカードの中から 2 枚を選び,横一列に並べて作ることができる整数は,
11, 12, 21, 112, 121, 122, 212 の 7 個である.
</p>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02454 | <h1>Equal Range</h1>
<p>
For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, print a pair of the lower bound and the upper bound for a specific value $k$ given as a query.
</p>
<ul>
<li>
lower bound: the place pointing to the first element greater than or equal to a specific value, or $n$ if there is no such element.
</li>
<li>
upper bound: the place pointing to the first element greater than a specific value, or $n$ if there is no such element.
</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ,..., \; a_{n-1}$
$q$
$k_1$
$k_2$
:
$k_q$
</pre>
<p>
The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries.
</p>
<h2>Output</h2>
<p>
For each query, print the pari of the lower bound $l$ ($l = 0, 1, ..., n$) and upper bound $r$ ($r = 0, 1, ..., n$) separated by a space character in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 100,000$</li>
<li>$1 \leq q \leq 200,000$</li>
<li>$0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$
<li>$0 \leq k_i \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4
1 2 2 4
3
2
3
5
</pre>
<h2>Sample Output 1</h2>
<pre>
1 3
3 3
4 4
</pre>
|
p00193 |
<H1>コンビニ</H1>
<table>
<tr>
<td style="vertical-align:top">
<p>
コンビニエンスストア・デブンイレブンは事業を広げるため若松市に一店舗目をオープンしようと考えています。若松市には既に他のたくさんのコンビニエンスストアがあるので、新店舗をオープンする場所が成功の鍵を握ることになりそうです。デブンイレブンは「お客さんは自分の住んでいる地域から最も近いコンビニを利用する」という前提の下、「多くのお客さんが利用するであろう地点」に出店することにしています。
</p>
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_devenEleven1">
</td>
</tr>
</table>
<p>
デブンイレブンは、既設の各コンビニがカバーしている範囲を把握するため、若松市の地図を合同な正六角形(以後「ブロック」)を用いて区分しました。このとき、各ブロックには既設のコンビニが多くとも一つだけ入るように区分しました。この地図上で、各ブロックからあるコンビニへ行くのに経由するブロックの数をもとにコンビニとの距離を求めます。各ブロックはこの距離が最も小さいコンビニによってカバーされていると考えます。問題は、この地図をもとに「できるだけ多くのブロックをカバーする既設のコンビニがないブロック」を探すことです。
</p>
<p>
デブンイレブンのプログラマであるあなたは、ブロック分けされた地図情報と新店舗の候補地の情報から、最も広くカバーできるブロック数を計算するプログラムを開発することになりました。
</p>
<p>
<var>m × n</var> に区分した地図は図1のように表します。六角形のブロックが横に <var>m</var> 個、縦に <var>n</var> 個並び、それぞれは一つの座標(<var>x, y</var>)で示されます。奇数行の左端はその上の行の左端の左下に、偶数行の左端はその上の行の左端の右下に、それぞれ位置します。例えば、座標(1, 1)は図1の一番左上のブロックを示します。また、座標(1, 2)は座標(1, 1)の右下に位置し、座標(1, 3)は座標(1, 2)の左下に位置します。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_devenEleven2">
</center>
<br/>
<p>
図2は既設のコンビニが6個あった場合の例で、6 × 6 に区分されています。各コンビニは1から順に番号が振られています。このとき、各コンビニがカバーするブロックを番号毎に塗り分けると図3のようになります。座標(1, 4)や(2, 5)のように塗られていないブロックは最も近いコンビニが二つ以上あり、どちらとも判断がつかないブロックになっています。例えば、座標(1, 4)のブロックの場合、番号4のコンビニと番号5のコンビニへの距離が等しく、このブロックをカバーしているコンビニはないものとして考えます。番号4のコンビニがカバーしているブロック数は5となります。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_devenEleven3">
</center>
<br/>
<p>
ここで、デブンイレブンが座標(1, 3)と座標(5, 3)を新店舗の候補地として考えているとします。座標(1, 3)に店舗を構えた場合、カバーできるブロック数は3となります(図4)。一方、座標(5, 3)に店舗を構えた場合にカバーできるブロック数は4となります(図5)。したがって、最も広くカバーできるブロック数は4となります。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_devenEleven4">
</center>
<br/>
<p>
地図情報 <var>m × n</var>、既設のコンビニの数 <var>s</var> とその座標(<var>x, y</var>)、候補地の数 <var>t</var> とその座標(<var>p, q</var>)を入力とし、全候補地の中で最も広くカバーできるブロック数を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。 各データセットは以下の形式で与えられます。
</p>
<pre>
<var>m</var> <var>n</var>
<var>s</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
:
<var>x<sub>s</sub></var> <var>y<sub>s</sub></var>
<var>t</var>
<var>p<sub>1</sub></var> <var>q<sub>1</sub></var>
<var>p<sub>2</sub></var> <var>q<sub>2</sub></var>
:
<var>p<sub>t</sub></var> <var>q<sub>t</sub></var>
</pre>
<p>
1 行目に区分した地図の大きさ(横、縦)を表す整数 <var>m</var>, <var>n</var> (2 ≤ <var>m, n</var> ≤ 100) が与えられます。
</p>
<p>
2行目に既設のコンビニの数 <var>s</var> (1 ≤ <var>s</var> ≤ 10) が与えられます。続く<var>s</var> 行に、 <var>i</var> 個目の既設のコンビニの座標 <var>x<sub>i</sub></var>, <var>y<sub>1</sub></var> が与えられます。
</p>
<p>
続く行に、新店舗の候補地の数 <var>t</var> (1 ≤ <var>t</var> ≤ 10 ) が与えられます。続く <var>t</var> 行に、<var>i</var> 個目の候補地の座標 <var>p<sub>i</sub></var>, <var>q<sub>i</sub></var> が与えられます。
</p>
<p>
データセットの数は 20 を超えません。
</p>
<H2>Output</H2>
<p>
データセット毎に、全候補地の中で最も広くカバーできるブロック数を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
6 6
6
1 1
6 1
3 2
3 5
1 6
5 6
2
1 3
5 3
6 6
6
3 2
3 5
6 1
1 1
1 6
5 6
2
2 3
5 3
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
4
</pre>
|
p00039 |
<H1>ローマ数字</H1>
<p>
古代ローマでは数を数えることは難しい仕事でした。アラビア数字の 0,1,2,3,…, 9 はまだ流布していませんでした。その代わり次のような記号が使われていました。
</p>
<center>
<table border=1>
<tr>
<td bgcolor="#EEFFFF" width="100">アラビア数字</td><td width="100">ローマ数字</td><td bgcolor="#EEFFFF" width="100">アラビア数字</td><td width="100">ローマ数字</td><td bgcolor="#EEFFFF" width="100">アラビア数字</td><td width="100">ローマ数字</td>
</tr>
<tr><td bgcolor="#EEFFFF">1</td><td>I</td><td bgcolor="#EEFFFF">11<td>XI</td><td bgcolor="#EEFFFF">30</td><td>XXX</td><td>
<tr><td bgcolor="#EEFFFF">2</td><td>II</td><td bgcolor="#EEFFFF">12<td>XII</td><td bgcolor="#EEFFFF">40</td><td>XL</td><td>
<tr><td bgcolor="#EEFFFF">3</td><td>III</td><td bgcolor="#EEFFFF">13<td>XIII</td><td bgcolor="#EEFFFF">50</td><td>L</td><td>
<tr><td bgcolor="#EEFFFF">4</td><td>IV</td><td bgcolor="#EEFFFF">14<td>XIV</td><td bgcolor="#EEFFFF">60</td><td>LX</td><td>
<tr><td bgcolor="#EEFFFF">5</td><td>V</td><td bgcolor="#EEFFFF">15<td>XV</td><td bgcolor="#EEFFFF">70</td><td>LXX</td><td>
<tr><td bgcolor="#EEFFFF">6</td><td>VI</td><td bgcolor="#EEFFFF">16<td>XVI</td><td bgcolor="#EEFFFF">80</td><td>LXXX</td><td>
<tr><td bgcolor="#EEFFFF">7</td><td>VII</td><td bgcolor="#EEFFFF">17<td>XVII</td><td bgcolor="#EEFFFF">90</td><td>XC</td><td>
<tr><td bgcolor="#EEFFFF">8</td><td>VIII</td><td bgcolor="#EEFFFF">18<td>XVIII</td><td bgcolor="#EEFFFF">100</td><td>C</td><td>
<tr><td bgcolor="#EEFFFF">9</td><td>IX</td><td bgcolor="#EEFFFF">19<td>XIX</td><td bgcolor="#EEFFFF">500</td><td>D</td><td>
<tr><td bgcolor="#EEFFFF">10</td><td>X</td><td bgcolor="#EEFFFF">20<td>XX</td><td bgcolor="#EEFFFF">1000</td><td>M</td><td>
</table>
</center>
<br/>
<p>
I は 1、 V は 5、 X は 10、 L は 50、 C は 100、 D は 500、 M は 1000、 他の例は上の表を見てください。小さい数が大きい数に続いている、つまり右側にあるときは足し算をします。小さい数が大きい数の前に、つまり左にあるときは、大きい数から小さい数を引きます。大きい数字の前にあって引き算を表す小さな数字は一回の引き算あたりひとつしかありません。
</p>
<p>
ローマ数字をアラビア数字(通常の数字)の表記(10 進表示)に変換して出力するプログラムを作成してください。ただし、与えられるローマ数字は上記のルールにのみ従っています(実際のローマ数字の表記にはもっと細かいルールがありますが、ここでは考慮する必要はありません。たとえば、実際のローマ数字ではI はV かX から、X はL かC から、C はD かM からしか引き算しませんし、同じローマ数字は4つ以上(または5つ以上)足し並べることはありません。)
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。それぞれのデータセットにローマ数字(半角大文字のI, V, X, L, C, D ,M で表される連続した文字列)が1行に与えられます。与えられるローマ数字の文字列の長さはおのおの 100 以下です。
</p>
<p>
データセットの数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
各データセットに対し、アラビア数字(整数)を1行に出力して下さい。
</p>
<H2>Sample Input</H2>
<pre>
IV
CCCCLXXXXVIIII
CDXCIX
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
499
499
</pre>
|
p02004 | <h1>Problem A. GuruGuru</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
You are playing a game called <i>Guru Guru Gururin</i>. In this game, you can move with the vehicle called Gururin. There are two commands you can give to Gururin: '<span>R</span>' and '<span>L</span>'. When '<span>R</span>' is sent, Gururin rotates clockwise by 90 degrees. Otherwise, when '<span>L</span>' is sent, Gururin rotates counterclockwise by 90 degrees.
</p>
<p>
During the game, you noticed that Gururin obtains magical power by performing special commands. In short, Gururin obtains magical power every time when it performs one round in the clockwise direction from north to north. In more detail, the conditions under which magical power can be obtained is as follows.
</p>
<ul>
<li>At the beginning of the special commands, Gururin faces north.</li>
<li>At the end of special commands, Gururin faces north.</li>
<li>Except for the beginning and the end of special commands, Gururin does not face north.</li>
<li>During the special commands, Gururin faces north, east, south, and west one or more times, respectively, after the command of '<span>R</span>'.</li>
</ul>
<p>
At the beginning of the game, Gururin faces north. For example, if the sequence of commands Gururin received in order is '<span>RRRR</span>' or '<span>RRLRRLRR</span>', Gururin can obtain magical power. Otherwise, if the sequence of commands is '<span>LLLL</span>' or '<span>RLLR</span>', Gururin cannot obtain magical power.
</p>
<p>
Your task is to calculate how many times Gururin obtained magical power throughout the game. In other words, given the sequence of the commands Gururin received, calculate how many special commands exists in it.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case in the format below.
</p>
<pre>
$S$
</pre>
<p>
The first line consists of a string $S$, which represents the sequence of commands Gururin received. $S$ consists of '<span>L</span>' and '<span>R</span>'. The length of $S$ is between $1$ and $10^3$ inclusive.
</p>
<h2>Output</h2>
<p>
Print the number of times Gururin obtained magical power throughout the game in one line.
</p>
<h2>Examples</h2>
<h2>Sample Input 1 </h2>
<pre>
RRRRLLLLRRRR
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2 </h2>
<pre>
RLLRLLLLRRRLLLRRR
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
0
</pre>
<h2>Sample Input 3 </h2>
<pre>
LR
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
0
</pre>
<h2>Sample Input 4 </h2>
<pre>
RRLRRLRRRRLRRLRRRRLRRLRRRRLRRLRR
</pre>
<h2>Output for Sample Input 4</h2>
<pre>
4
</pre>
|
p03245 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is introducing a <strong>robot arm</strong> with the following properties to his factory:</p>
<ul>
<li>The robot arm consists of <var>m</var> <strong>sections</strong> and <var>m+1</var> <strong>joints</strong>. The sections are numbered <var>1</var>, <var>2</var>, ..., <var>m</var>, and the joints are numbered <var>0</var>, <var>1</var>, ..., <var>m</var>. Section <var>i</var> connects Joint <var>i-1</var> and Joint <var>i</var>. The length of Section <var>i</var> is <var>d_i</var>.</li>
<li>For each section, its <strong>mode</strong> can be specified individually. There are four modes: <code>L</code>, <code>R</code>, <code>D</code> and <code>U</code>. The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint <var>i</var> will be determined as follows (we denote its coordinates as <var>(x_i, y_i)</var>):<ul>
<li><var>(x_0, y_0) = (0, 0)</var>.</li>
<li>If the mode of Section <var>i</var> is <code>L</code>, <var>(x_{i}, y_{i}) = (x_{i-1} - d_{i}, y_{i-1})</var>.</li>
<li>If the mode of Section <var>i</var> is <code>R</code>, <var>(x_{i}, y_{i}) = (x_{i-1} + d_{i}, y_{i-1})</var>.</li>
<li>If the mode of Section <var>i</var> is <code>D</code>, <var>(x_{i}, y_{i}) = (x_{i-1}, y_{i-1} - d_{i})</var>.</li>
<li>If the mode of Section <var>i</var> is <code>U</code>, <var>(x_{i}, y_{i}) = (x_{i-1}, y_{i-1} + d_{i})</var>.</li>
</ul>
</li>
</ul>
<p>Snuke would like to introduce a robot arm so that the position of Joint <var>m</var> can be matched with all of the <var>N</var> points <var>(X_1, Y_1), (X_2, Y_2), ..., (X_N, Y_N)</var> by properly specifying the modes of the sections.
Is this possible?
If so, find such a robot arm and how to bring Joint <var>m</var> to each point <var>(X_j, Y_j)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>-10^9 \leq X_i \leq 10^9</var></li>
<li><var>-10^9 \leq Y_i \leq 10^9</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In the test cases worth <var>300</var> points, <var>-10 \leq X_i \leq 10</var> and <var>-10 \leq Y_i \leq 10</var> hold.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>X_1</var> <var>Y_1</var>
<var>X_2</var> <var>Y_2</var>
<var>:</var>
<var>X_N</var> <var>Y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print <code>-1</code>.</p>
<pre><var>m</var>
<var>d_1</var> <var>d_2</var> <var>...</var> <var>d_m</var>
<var>w_1</var>
<var>w_2</var>
<var>:</var>
<var>w_N</var>
</pre>
<p><var>m</var> and <var>d_i</var> are the configurations of the robot arm. Refer to the problem statement for what each of them means.
Here, <var>1 \leq m \leq 40</var> and <var>1 \leq d_i \leq 10^{12}</var> must hold. Also, <var>m</var> and <var>d_i</var> must all be integers.</p>
<p><var>w_j</var> is a string of length <var>m</var> that represents the way to bring Joint <var>m</var> of the robot arm to point <var>(X_j, Y_j)</var>.
The <var>i</var>-th character of <var>w_j</var> should be one of the letters <code>L</code>, <code>R</code>, <code>D</code> and <code>U</code>, representing the mode of Section <var>i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
-1 0
0 3
2 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1 2
RL
UU
DR
</pre>
<p>In the given way to bring Joint <var>m</var> of the robot arm to each <var>(X_j, Y_j)</var>, the positions of the joints will be as follows:</p>
<ul>
<li>To <var>(X_1, Y_1) = (-1, 0)</var>: First, the position of Joint <var>0</var> is <var>(x_0, y_0) = (0, 0)</var>. As the mode of Section <var>1</var> is <code>R</code>, the position of Joint <var>1</var> is <var>(x_1, y_1) = (1, 0)</var>. Then, as the mode of Section <var>2</var> is <code>L</code>, the position of Joint <var>2</var> is <var>(x_2, y_2) = (-1, 0)</var>.</li>
<li>To <var>(X_2, Y_2) = (0, 3)</var>: <var>(x_0, y_0) = (0, 0), (x_1, y_1) = (0, 1), (x_2, y_2) = (0, 3)</var>.</li>
<li>To <var>(X_3, Y_3) = (2, -1)</var>: <var>(x_0, y_0) = (0, 0), (x_1, y_1) = (0, -1), (x_2, y_2) = (2, -1)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 0
1 0
2 0
3 0
4 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
1 1
RU
UR
</pre>
<p>There may be duplicated points among <var>(X_j, Y_j)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
-7 -3
7 3
-3 -7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
3 1 4 1 5
LRDUL
RDULR
DULRD
</pre></section>
</div>
</span> |
p01278 |
<H1><font color="#000">Problem F:</font> Voronoi Island</H1>
<p>
Some of you know an old story of Voronoi Island. There were N liege lords and they are always involved
in territorial disputes. The residents of the island were despaired of the disputes.
</p>
<p>
One day, a clever lord proposed to stop the disputes and divide the island fairly. His idea was to divide the
island such that any piece of area belongs to the load of the nearest castle. The method is called Voronoi
Division today.
</p>
<p>
Actually, there are many aspects of whether the method is fair. According to one historian, the clever
lord suggested the method because he could gain broader area than other lords.
</p>
<p>
Your task is to write a program to calculate the size of the area each lord can gain. You may assume that
Voronoi Island has a convex shape.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>N M</i><br>
<i>Ix</i><sub>1</sub> <i>Iy</i><sub>1</sub><br>
<i>Ix</i><sub>2</sub> <i>Iy</i><sub>2</sub><br>
...<br>
<i>Ix</i><sub><i>N</i></sub> <i>Iy</i><sub><i>N</i></sub><br>
<i>Cx</i><sub>1</sub> <i>Cy</i><sub>1</sub><br>
<i>Cx</i><sub>2</sub> <i>Cy</i><sub>2</sub><br>
...<br>
<i>Cx</i><sub><i>M</i></sub> <i>Cy</i><sub><i>M</i></sub><br>
</p>
<p>
<i>N</i> is the number of the vertices of Voronoi Island; <i>M</i> is the number of the liege lords; (<i>Ix<sub>i</sub></i>, <i>Iy<sub>i</sub></i>) denotes
the coordinate of the <i>i</i>-th vertex; (<i>Cx<sub>i</sub></i>, <i>Cy<sub>i</sub></i> ) denotes the coordinate of the castle of the i-the lord.
</p>
<p>
The input meets the following constraints: 3 ≤ <i>N</i> ≤ 10, 2 ≤ <i>M</i> ≤ 10, -100 ≤ <i>Ix<sub>i</sub></i>, <i>Iy<sub>i</sub></i>, <i>Cx<sub>i</sub></i>, <i>Cy<sub>i</sub></i> ≤ 100. The
vertices are given counterclockwise. All the coordinates are integers.
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the area gained by each liege lord with an absolute error of at most 10<sup>-4</sup> . You may output any
number of digits after the decimal point. The order of the output areas must match that of the lords in the
input.
</p>
<H2>Sample Input</H2>
<pre>
3 3
0 0
8 0
0 8
2 2
4 2
2 4
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
9.0
11.5
11.5
</pre>
|
p01782 |
<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>C - Decoding Ancient Messages</h2>
<h3>Problem Statement</h3>
<p>
Professor Y's work is to dig up ancient artifacts. Recently, he found a lot of strange stone plates, each of which has $N^2$ characters arranged in an $N \times N$ matrix. Further research revealed that each plate represents a message of length $N$. Also, the procedure to decode the message from a plate was turned out to be the following:
</p>
<ol>
<li>Select $N$ characters from the plate one by one so that any two characters are neither in the same row nor in the same column.</li>
<li>Create a string by concatenating the selected characters.</li>
<li>Among all possible strings obtained by the above steps, find the lexicographically smallest one. It is the message represented by this plate.</li>
</ol>
<p>
NOTE: The order of the characters is defined as the same as the order of their ASCII values (that is, $\mathtt{A} \lt \mathtt{B} \lt \cdots \lt \mathtt{Z} \lt \mathtt{a} \lt \mathtt{b} \lt \cdots \lt \mathtt{z}$).
</p>
<p>
After struggling with the plates, Professor Y gave up decoding messages by hand. You, a great programmer and Y's old friend, was asked for a help. Your task is to write a program to decode the messages hidden in the plates.
</p>
<h3>Input</h3>
<p>The input is formated as follows:
</p>
<blockquote>$N$<br>$c_{11} c_{12} \cdots c_{1N}$<br>$c_{21} c_{22} \cdots c_{2N}$<br>:<br>:<br>$c_{N1} c_{N2} \cdots c_{NN}$</blockquote>
<p>
The first line contains an integer $N$ ($1 \le N \le 50$). Each of the subsequent $N$ lines contains a string of $N$ characters. Each character in the string is an uppercase or lowercase English letter (<code>A</code>-<code>Z</code>, <code>a</code>-<code>z</code>).
</p>
<h3>Output</h3>
<p>Print the message represented by the plate in a line.</p>
<h3>Sample Input 1</h3>
<pre>3
aab
czc
baa</pre>
<h3>Output for the Sample Input 1</h3>
<pre>aac</pre>
<h3>Sample Input 2</h3>
<pre>36
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiQiiiiiiiiiiiiiiiQiiiiiiiii
iiiiiiiiiiQQQiiiiiiiiiiQQQQiiiiiiiii
iiiiiiiiiiQQQQQiiiiiiiQQQQiiiiiiiiii
iiiiiiiiiiiQQQQQQQQQQQQQQQiiiiiiiiii
iiiiiiiiiiiQQQQQQQQQQQQQQQiiiiiiiiii
iiiiiiiiiiiQQQQQQQQQQQQQQiiiiiiiiiii
iiiiiiiiiiiiQQQQQQQQQQQQQiiiiiiiiiii
iiiiiiiiiiiQQQQQQQQQQQQQQQiiiiiiiiii
iiiiiiiiiiQQQQQQQQQQQQQQQQQiiiiiiiii
iiiiiiQiiiQQQQQQQQQQQQQQQQQiiiQiiiii
iiiiiiQQiQQQQQQQQQQQQQQQQQQiiQQiiiii
iiiiiiiQQQQQQQQQQQQQQQQQQQQiQQiiiiii
iiiiiiiiiQQQQQQQQQQQQQQQQQQQQiiiiiii
iiiiiiiiQQQQQiiQQQQQQQQiiQQQQQiiiiii
iiiiiiQQQQQQiiiiQQQQQiiiiQQQQQQiiiii
iiiiiQQQQQQQQiiiQQQQQiiQQQQQQQQiQiii
iiiQQQQQQQiiQiiiQQQQQiiQiiQQQQQQQQii
iQQQQQQQQQiiiiiQQQQQQQiiiiiiQQQQQQQi
iiQQQQQQQiiiiiiQQQQQQQiiiiiiiiQQQiii
iQQQQiiiiiiiiiQQQQQQQQQiiiiiiiiQQQii
iiiiiiiiiiiiiiQQQQQQQQQiiiiiiiiiiiii
iiiiiiiiiiiiiQQQQQQQQQQiiiiiiiiiiiii
iiiiiiiiiiiiiQQQQQQQQQQiiiiiiiiiiiii
iiiiiiiiiiiiiiQQQQQQQQiiiiiiiiiiiiii
iiiiiiiiiiiiiiQQQQQQQQiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii</pre>
<h3>Output for the Sample Input 2</h3>
<pre>QQQQQQQQQQQQQQQQQQQQQQQQQiiiiiiiiiii</pre>
<h3>Sample Input 3</h3>
<pre>3
Acm
aCm
acM</pre>
<h3>Output for the Sample Input 3</h3>
<pre>ACM</pre> |
p00890 |
<H1><font color="#000">Problem G:</font> Test Case Tweaking</H1>
<p>
You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they are not interesting. You want to produce a dataset whose answer is a desired value such as the number representing this year 2010. So you will tweak (which means 'adjust') the cost of the minimum cost path to a given value by changing the costs of some edges. The number of changes should be made as few as possible.
</p>
<p>
A non-negative integer c and a directed graph <i>G</i> are given. Each edge of <i>G</i> is associated with a cost of a non-negative integer. Given a path from one node of <i>G</i> to another, we can define the cost of the path as the sum of the costs of edges constituting the path. Given a pair of nodes in <i>G</i>, we can associate it with a non-negative cost which is the minimum of the costs of paths connecting them.
</p>
<p>
Given a graph and a pair of nodes in it, you are asked to adjust the costs of edges so that the minimum cost path from one node to the other will be the given target cost <i>c</i>. You can assume that <i>c</i> is smaller than the cost of the minimum cost path between the given nodes in the original graph.
</p>
<p>
For example, in Figure G.1, the minimum cost of the path from node 1 to node 3 in the given graph is 6. In order to adjust this minimum cost to 2, we can change the cost of the edge from node 1 to node 3 to 2. This direct edge becomes the minimum cost path after the change.
</p>
<p>
For another example, in Figure G.2, the minimum cost of the path from node 1 to node 12 in the given graph is 4022. In order to adjust this minimum cost to 2010, we can change the cost of the edge from node 6 to node 12 and one of the six edges in the right half of the graph. There are many possibilities of edge modification, but the minimum number of modified edges is 2.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows.
</p>
<p>
<i>n m c</i><br>
<i>f</i><sub>1</sub> <i>t</i><sub>1</sub> <i>c</i><sub>1</sub><br>
<i>f</i><sub>2</sub> <i>t</i><sub>2</sub> <i>c</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>f</i><sub><i>m</i></sub> <i>t</i><sub><i>m</i></sub> <i>c</i><sub><i>m</i></sub><br>
</p>
<center>
<table>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_testCaseTweaking1"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_testCaseTweaking2"></td>
</tr>
<tr>
<td align="center"><p>Figure G.1: Example 1 of graph</p></td>
<td align="center"><p>Figure G.2: Example 2 of graph</p></td>
</tr>
</table>
</center>
<p>
The integers <i>n</i>, <i>m</i> and <i>c</i> are the number of the nodes, the number of the edges, and the target cost, respectively, each separated by a single space, where 2 ≤ <i>n</i> ≤ 100, 1 ≤ <i>m</i> ≤ 1000 and 0 ≤ <i>c</i> ≤ 100000.
</p>
<p>
Each node in the graph is represented by an integer 1 through <i>n</i>.
</p>
<p>
The following <i>m</i> lines represent edges: the integers <i>f<sub>i</sub></i>, <i>t<sub>i</sub></i> and <i>c<sbu>i</sub></i> (1 ≤ <i>i</i> ≤ <i>m</i>) are the originating node, the destination node and the associated cost of the <i>i</i>-th edge, each separated by a single space. They satisfy 1 ≤ <i>f<sub>i</sub></i>, <i>t<sub>i</sub></i> ≤ <i>n</i> and 0 ≤ <i>c<sub>i</sub></i> ≤ 10000. You can assume that <i>f<sub>i</sub></i> ≠ <i>t<sub>i</sub></i> and (<i>f<sub>i</sub></i>, <i>t<sub>i</sub></i>) ≠ (<i>f<sub>j</sub></i>, <i>t<sub>j</sub></i>) when <i>i</i> ≠ <i>j</i>.
</p>
<p>
You can assume that, for each dataset, there is at least one path from node 1 to node <i>n</i>, and that the cost of the minimum cost path from node 1 to node <i>n</i> of the given graph is greater than <i>c</i>.
</p>
<p>
The end of the input is indicated by a line containing three zeros separated by single spaces.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing the minimum number of edges whose cost(s) should be changed in order to make the cost of the minimum cost path from node 1 to node <i>n</i> equal to the target cost <i>c</i>. Costs of edges cannot be made negative. The output should not contain any other extra characters.
</p>
<H2>Sample Input</H2>
<pre>
3 3 3
1 2 3
2 3 3
1 3 8
12 12 2010
1 2 0
2 3 3000
3 4 0
4 5 3000
5 6 3000
6 12 2010
2 7 100
7 8 200
8 9 300
9 10 400
10 11 500
11 6 512
10 18 1
1 2 9
1 3 2
1 4 6
2 5 0
2 6 10
2 7 2
3 5 10
3 6 3
3 7 10
4 7 6
5 8 10
6 8 2
6 9 11
7 9 3
8 9 9
8 10 8
9 10 1
8 2 1
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
2
3
</pre>
|
p03615 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>N</var> points <var>(x_i,y_i)</var> located on a two-dimensional plane.
Consider a subset <var>S</var> of the <var>N</var> points that forms a convex polygon.
Here, we say a set of points <var>S</var> <em>forms a convex polygon</em> when there exists a convex polygon with a positive area that has the same set of vertices as <var>S</var>. All the interior angles of the polygon must be strictly less than <var>180°</var>.</p>
<div style="text-align: center;">
<img alt="cddb0c267926c2add885ca153c47ad8a.png" src="https://atcoder.jp/img/arc082/cddb0c267926c2add885ca153c47ad8a.png">
</img></div>
<p>For example, in the figure above, {<var>A,C,E</var>} and {<var>B,D,E</var>} form convex polygons; {<var>A,C,D,E</var>}, {<var>A,B,C,E</var>}, {<var>A,B,C</var>}, {<var>D,E</var>} and {} do not.</p>
<p>For a given set <var>S</var>, let <var>n</var> be the number of the points among the <var>N</var> points that are inside the convex hull of <var>S</var> (including the boundary and vertices). Then, we will define the <em>score</em> of <var>S</var> as <var>2^{n-|S|}</var>.</p>
<p>Compute the scores of all possible sets <var>S</var> that form convex polygons, and find the sum of all those scores.</p>
<p>However, since the sum can be extremely large, print the sum modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N≤200</var></li>
<li><var>0≤x_i,y_i<10^4 (1≤i≤N)</var></li>
<li>If <var>i≠j</var>, <var>x_i≠x_j</var> or <var>y_i≠y_j</var>.</li>
<li><var>x_i</var> and <var>y_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of all the scores modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
0 0
0 1
1 0
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>We have five possible sets as <var>S</var>, four sets that form triangles and one set that forms a square. Each of them has a score of <var>2^0=1</var>, so the answer is <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 0
0 1
0 2
0 3
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre>
<p>We have three "triangles" with a score of <var>1</var> each, two "triangles" with a score of <var>2</var> each, and one "triangle" with a score of <var>4</var>. Thus, the answer is <var>11</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
3141 2718
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>There are no possible set as <var>S</var>, so the answer is <var>0</var>.</p></section>
</div>
</span> |
p01628 |
<h1>Problem B: あみだくじ</h1>
<h2>Problem Statement</h2>
<p>
会津合宿に参加予定の高槻さんは、家が貧乏であり、いつも紙をなるべく節約して使うようにしている。彼女は、会津合宿のチーム決めのために、他の参加者の人達とあみだくじをすることになった。
</p>
<p>
この合宿のあみだくじの作り方は次のようなものである。まず、紙にN本の縦棒を平行に書く。そして、M本の横棒を上から順番に、縦棒と垂直になるように、かつ横棒の高さが全て異なるように書いていく。例えば、Sample Input 1のあみだは、図1のようになる。
</p>
<p>
ここで、高槻さん、ちょっと不満げな表情。こんなに縦長にあみだくじを書いていると紙がもったいない。もっと、高さを圧縮できるはず。ということで、彼女のために以下に示すあみだくじの高さ圧縮の問題を解いてほしい。
</p>
<p>
まず、あみだくじの高さとは、同じ高さに存在する横棒をまとめて高さ1と数えて、これを一番下の横棒まで数えた値である。ここでは、高さ圧縮を行うために、各横棒を上下に自由に動かすことができるものとする。ただし、横棒を削除することも追加することも許されない。高さ圧縮をした後のあみだくじは、必ず以下の条件を満たしている必要がある。
</p>
<ul>
<li>横棒の端点が他の横棒の端点と接していない。</li>
<li>圧縮後のあみだくじを辿った結果と、圧縮前のあみだくじを辿った結果が一致している。</li>
</ul>
<p>
図2は、図1を圧縮したものである。「縦棒1と2を結ぶ横棒」が一番上まで移動して、「縦棒4と5を結ぶ横棒」と同じ高さとなり、この2つで高さ1。あとは、「縦棒3と4を結ぶ横棒」と「縦棒2と3を結ぶ横棒」は、それぞれ別の高さとなり、全体で高さ3である。
</p>
<div align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2013Day1_B1">
</div>
<p>
与えられたあみだくじを高さ圧縮し、圧縮後の高さを出力せよ。
</p>
<h2>Input</h2>
<p>
各データセットは、以下の形式で入力される。
</p>
<pre>N M
a1
a2
...
aM
</pre>
<p>
入力は全て整数である。Nは縦棒の数、Mは横棒の数を示す。続いて、M行にわたって横棒の情報が入力される。aiは、i番目の横棒が縦棒aiと、その1つ右の縦棒を結んでいることを表わしている。i番目の横棒は、i+1番目の横棒より上側に存在する。
</p>
<h2>Constraints</h2>
<ul>
<li>2 <= N <= 8</li>
<li>1 <= M <= 8</li>
<li>1 <= ai <= N - 1</li>
</ul>
<h2>Output</h2>
<p>
圧縮後のあみだくじの高さを1行で出力する。
</p>
<h2>Sample Input 1</h2>
<pre>5 4
4
3
1
2
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>3
</pre>
<h2>Sample Input 2</h2>
<pre>4 3
1
2
3
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>3
</pre>
<p>
高さ圧縮は行えないため、横棒の数Mを出力する。
</p> |
p02907 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke found a random number generator.
It generates an integer between <var>0</var> and <var>N-1</var> (inclusive).
An integer sequence <var>A_0, A_1, \cdots, A_{N-1}</var> represents the probability that each of these integers is generated. The integer <var>i</var> (<var>0 \leq i \leq N-1</var>) is generated with probability <var>A_i / S</var>, where <var>S = \sum_{i=0}^{N-1} A_i</var>. The process of generating an integer is done independently each time the generator is executed.</p>
<p>Now, Snuke will repeatedly generate an integer with this generator until the following condition is satisfied:</p>
<ul>
<li>For every <var>i</var> (<var>0 \leq i \leq N-1</var>), the integer <var>i</var> has been generated at least <var>B_i</var> times so far.</li>
</ul>
<p>Find the expected number of times Snuke will generate an integer, and print it modulo <var>998244353</var>.
More formally, represent the expected number of generations as an irreducible fraction <var>P/Q</var>. Then, there exists a unique integer <var>R</var> such that <var>R \times Q \equiv P \pmod{998244353},\ 0 \leq R < 998244353</var>, so print this <var>R</var>.</p>
<p>From the constraints of this problem, we can prove that the expected number of generations is a finite rational number, and its integer representation modulo <var>998244353</var> can be defined.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 400</var></li>
<li><var>1 \leq A_i</var></li>
<li><var>\sum_{i=0}^{N-1} A_i \leq 400</var></li>
<li><var>1 \leq B_i</var></li>
<li><var>\sum_{i=0}^{N-1} B_i \leq 400</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_0</var> <var>B_0</var>
<var>A_1</var> <var>B_1</var>
<var>\vdots</var>
<var>A_{N-1}</var> <var>B_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the expected number of times Snuke will generate an integer, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The expected number of times Snuke will generate an integer is <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 3
2 2
3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>971485877
</pre>
<p>The expected number of times Snuke will generate an integer is <var>132929/7200</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15
29 3
78 69
19 15
82 14
9 120
14 51
3 7
6 14
28 4
13 12
1 5
32 30
49 24
35 23
2 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>371626143
</pre></section>
</div>
</span> |
p00310 |
<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>
選手のみなさん、パソコン甲子園にようこそ。パソコン甲子園では、現在、プログラミング部門、モバイル部門、そして、いちまいの絵CG部門、計3部門の競技が開催されています。
<!--
大会の運営に当たって参加者の総数を求める必要がありますが、参加者数は部門ごとに集計されているので全体の人数がわかりません。
-->
</p>
<p>
各部門の参加者数が与えられたとき、参加者の総数を計算するプログラムを作成せよ。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>p</var> <var>m</var> <var>c</var>
</pre>
<p>
入力は1行であり、プログラミング部門の参加者数 <var>p</var> (0 ≤ <var>p</var> ≤ 10000)、モバイル部門の参加者数 <var>m</var> (0 ≤ <var>m</var> ≤ 10000)、いちまいの絵CG部門の参加者数 <var>c</var> (0 ≤ <var>c</var> ≤ 10000) が与えられる。
</p>
<h2>Output</h2>
<p>
参加者の総数を1行に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
10 10 20
</pre>
<h2>Sample Output 1</h2>
<pre>
40
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
100 0 0
</pre>
<h2>Sample Output 2</h2>
<pre>
100
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
1000 1000 1000
</pre>
<h2>Sample Output 3</h2>
<pre>
3000
</pre> |
p01852 |
<h1 id="a-指折り数えて-finger-counting">A : 指折り数えて / Finger Counting</h1>
<h2 id="問題文">問題文</h2>
<p>肉西くんは指の数を増やしたり減らしたりできる.<br />肉西くんの前には <var>n</var> 個のまんじゅうがある.<br />肉西くんは指を折ってまんじゅうの個数を数えようとしている.<br />肉西くんの指が取れる形は折れているか折れていないかの <var>2</var> つしか無い.<br />肉西くんは <a href="http://www.asahi-net.or.jp/~ax2s-kmtn/ref/bdh.html">2 進数</a>を理解している.<br />肉西くんは各指に <var>2</var> 進数の桁を対応させて数を数えることが出来る.<br />肉西くんは対数を理解していない.<br />肉西くんのかわりにまんじゅうを数え上げるのに必要な指の本数の最小値を求めよ.</p>
<h2 id="入力">入力</h2>
<pre>
<var>n</var>
</pre>
<h2 id="制約">制約</h2>
<ul>
<li>整数である</li>
<li><var>0 ≤ n ≤ 10<sup>18</sup></var></li>
</ul>
<h2 id="出力">出力</h2>
<p>答えを <var>1</var> 行に出力し,最後に改行を出力せよ.</p>
<h2 id="サンプル">サンプル</h2>
<h3 id="サンプル入力1">サンプル入力1</h3>
<pre>
0
</pre>
<h3 id="サンプル出力1">サンプル出力1</h3>
<pre>
0
</pre>
<h3 id="サンプル入力2">サンプル入力2</h3>
<pre>
4
</pre>
<h3 id="サンプル出力2">サンプル出力2</h3>
<pre>
3
</pre>
<h3 id="サンプル入力3">サンプル入力3</h3>
<pre>
31
</pre>
<h3 id="サンプル出力3">サンプル出力3</h3>
<pre>
5
</pre>
<h3 id="サンプル入力4">サンプル入力4</h3>
<pre>
36028797018963968
</pre>
<h3 id="サンプル出力4">サンプル出力4</h3>
<pre>
56
</pre>
|
p00740 |
<h1><font color="#000000">Problem A:</font> Next Mayor</h1>
<p>
One of the oddest traditions of the town of Gameston may be that even
the town mayor of the next term is chosen according to the result of a game.
When the expiration of the term of the mayor approaches, at least
three candidates, including the mayor of the time, play a game of
pebbles, and the winner will be the next mayor.
</p>
<p>
The rule of the game of pebbles is as follows.
In what follows, <I>n</I> is the number of participating candidates.
</p>
<DL>
<DT>Requisites
<DD>A round table, a bowl, and plenty of pebbles.
<DT>Start of the Game
<DD>
A number of pebbles are put into the bowl;
the number is decided by the Administration Commission using
some secret stochastic process.
All the candidates, numbered from 0 to <I>n</I>-1 sit around the round table,
in a counterclockwise order. Initially, the bowl is handed to the
serving mayor at the time, who is numbered 0.
<DT>Game Steps
<DD>
When a candidate is handed the bowl and if any pebbles are in it,
one pebble is taken out of the bowl and is
kept, together with those already at hand, if any.
If no pebbles are left in the bowl, the candidate puts
all the kept pebbles, if any, into the bowl. Then, in either case, the bowl is
handed to the next candidate to the right.
This step is repeated until the winner is decided.
<DT>End of the Game
<DD>
When a candidate takes the last pebble in the bowl, and no other
candidates keep any pebbles, the game ends and that candidate with all
the pebbles is the winner.
</DL>
</p>
<p>
A math teacher of Gameston High, through his analysis, concluded that this game will always end within a finite number of steps, although the number of required steps can be very large.
</p>
<h3>Input</h3>
<p>
The input is a sequence of datasets. Each dataset is a line
containing two integers <I>n</I> and <I>p</I> separated by a single
space. The integer <I>n</I> is the number of the candidates including
the current mayor, and the integer <I>p</I> is the total number of the
pebbles initially put in the bowl. You may assume 3 ≤ <I>n</I> ≤ 50
and 2 ≤ <I>p</I> ≤ 50.
</p>
<p>
With the settings given in the input datasets, the game will end within 1000000 (one million) steps.
</p>
<p>
The end of the input is indicated by a line
containing two zeros separated by a single space.
</p>
<h3>Output</h3>
<p>
The output should be composed of lines corresponding to input datasets
in the same order, each line of which containing the candidate number
of the winner.
No other characters should appear in the output.
</p>
<h3>Sample Input</h3>
<pre>
3 2
3 3
3 50
10 29
31 32
50 2
50 50
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
0
1
5
30
1
13
</pre>
|
p02287 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Complete Binary Tree</H1>
<p>
A complete binary tree is a binary tree in which every internal node has two children and all leaves have the same depth. A binary tree in which if last level is not completely filled but all nodes (leaves) are pushed across to the left, is also (nearly) a complete binary tree.
</p>
<p>
A binary heap data structure is an array that can be viewed as a nearly complete binary tree as shown in the following figure.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_9_A_1">
</center>
<br>
<p>
Each node of a nearly complete binary tree corresponds to an element of the array that stores the value in the node. An array $A$ that represents a binary heap has the heap size $H$, the number of elements in the heap, and each element of the binary heap is stored into $A[1...H]$ respectively. The root of the tree is $A[1]$, and given the index $i$ of a node, the indices of its parent $parent(i)$, left child $left(i)$, right child $right(i)$ can be computed simply by $\lfloor i / 2 \rfloor$, $2 \times i$ and $2 \times i + 1$ respectively.
</p>
<p>
Write a program which reads a binary heap represented by a nearly complete binary tree, and prints properties of nodes of the binary heap in the following format:
</p>
<p>
node $id$: key = $k$, parent key = $pk$, left key = $lk$, right key = $rk$,
</p>
<p>
$id$, $k$, $pk$, $lk$ and $rk$ represent id (index) of the node, value of the node, value of its parent, value of its left child and value of its right child respectively. Print these properties in this order. If there are no appropriate nodes, print nothing.
</p>
<H2>Input</H2>
<p>
In the first line, an integer $H$, the size of the binary heap, is given. In the second line, $H$ integers which correspond to values assigned to nodes of the binary heap are given in order of node id (from $1$ to $H$).
</p>
<H2>Output</H2>
<p>
Print the properties of the binary heap in the above format from node $1$ to $H$ in order. <u>Note that, the last character of each line is a single space character.</u>
</p>
<H2>Constraints</H2>
<ul>
<li> $H \leq 250$</li>
<li>$-2,000,000,000 \leq$ value of a node $\leq 2,000,000,000$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
7 8 1 2 3
</pre>
<H2>Sample Output 1</H2>
<pre>
node 1: key = 7, left key = 8, right key = 1,
node 2: key = 8, parent key = 7, left key = 2, right key = 3,
node 3: key = 1, parent key = 7,
node 4: key = 2, parent key = 8,
node 5: key = 3, parent key = 8,
</pre>
<br>
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p> |
p01501 |
<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 G:
Shelter
</h2>
<p>
Taro lives in a town with N shelters. The shape of the town is a convex polygon.
</p>
<p>
He'll escape to the nearest shelter in case of emergency. Given the current location, the cost of escape is defined as the square of the distance to the nearest shelter. Because emergency occurs unpredictably, Taro can be at any point inside the town with the same probability. Calculate the expected cost of his escape.
</p>
<h3>Input</h3>
<p>
The first line contains two integers $M$ and $N$ ($3 \leq M \leq 100, 1 \leq N \leq 100$), which denote the number of vertices of the town and the number of shelters respectively.
</p>
<p>
The following $M$ lines describe the coordinates of the vertices of the town in the conunter-clockwise order. The $i$-th line contains two integers $x_i$ and $y_i$ ($-1000 \leq x_i, y_i \leq 1000$), which indicate the coordinates of the $i$-th vertex. You may assume the polygon is always simple, that is, the edges do not touch or cross each other except for the end points.
</p>
<p>
Then the following $N$ lines describe the coordinates of the shelters. The $i$-th line contains two integers $x_i$ and $y_i$, which indicate the coordinates of the $i$-th shelter. You may assume that every shelter is strictly inside the town and any two shelters do not have same coordinates.
</p>
<h3>Output</h3>
<p>
Output the expected cost in a line. The answer with an absolute error of less than or equal to $10^{-4}$ is considered to be correct.
</p>
<h3>Sample Input 1</h3>
<pre>4 1
0 0
3 0
3 3
0 3
1 1</pre>
<h3>Sample Output 1</h3>
<pre>2.0000000000</pre>
<h3>Sample Input 2</h3>
<pre>5 2
2 0
2 2
0 2
-2 0
0 -2
0 0
1 1</pre>
<h3>Sample Output 2</h3>
<pre>1.0000000000</pre>
<h3>Sample Input 3</h3>
<pre>4 3
0 0
3 0
3 3
0 3
1 1
1 2
2 2</pre>
<h3>Sample Output 3</h3>
<pre>0.7500000000</pre> |
p01151 |
<H1><font color="#000">Problem D:</font> Divisor is the Conqueror</H1>
<p>
<i>Divisor is the Conquerer</i> is a solitaire card game. Although this simple game itself is a great
way to pass one’s time, you, a programmer, always kill your time by programming. Your task
is to write a computer program that automatically solves <i>Divisor is the Conquerer</i> games. Here
is the rule of this game:
</p>
<p>
First, you randomly draw <i>N</i> cards (1 ≤ <i>N</i> ≤ 52) from your deck of playing cards. The game is
played only with those cards; the other cards will not be used.
</p>
<p>
Then you repeatedly pick one card to play among those in your hand. You are allowed to choose
any card in the initial turn. After that, you are only allowed to pick a card that conquers the
cards you have already played. A card is said to conquer a set of cards when the rank of the card
divides the sum of the ranks in the set. For example, the card 7 conquers the set {5, 11, 12},
while the card 11 does not conquer the set {5, 7, 12}.
</p>
<p>
You win the game if you successfully play all <i>N</i> cards you have drawn. You lose if you fails,
that is, you faces a situation in which no card in your hand conquers the set of cards you have
played.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases.
</p>
<p>
Each test case consists of two lines. The first line contains an integer <i>N</i> (1 ≤ N ≤ 52), which represents the number of the cards. The second line contains <i>N</i> integers <i>c<sub>1</sub> , . . . , c<sub>N</sub></i> (1 ≤ <i>c<sub>i</sub></i> ≤ 13),
each of which represents the rank of the card. You may assume that there are at most four cards
with the same rank in one list.
</p>
<p>
The input is terminated by a line with a single zero.
</p>
<H2>Output</H2>
<p>
For each test case, you should output one line. If there are any winning strategies for the cards
of the input, print any one of them as a list of <i>N</i> integers separated by a space.
</p>
<p>
If there is no winning strategy, print “No”.
</p>
<H2>Sample Input</H2>
<pre>
5
1 2 3 3 7
4
2 3 3 3
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3 3 1 7 2
No
</pre>
|
p03496 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has an integer sequence, <var>a</var>, of length <var>N</var>. The <var>i</var>-th element of <var>a</var> (<var>1</var>-indexed) is <var>a_{i}</var>.</p>
<p>He can perform the following operation any number of times:</p>
<ul>
<li>Operation: Choose integers <var>x</var> and <var>y</var> between <var>1</var> and <var>N</var> (inclusive), and add <var>a_x</var> to <var>a_y</var>.</li>
</ul>
<p>He would like to perform this operation between <var>0</var> and <var>2N</var> times (inclusive) so that <var>a</var> satisfies the condition below. Show one such sequence of operations.
It can be proved that such a sequence of operations always exists under the constraints in this problem.</p>
<ul>
<li>Condition: <var>a_1 \leq a_2 \leq ... \leq a_{N}</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 50</var></li>
<li><var>-10^{6} \leq a_i \leq 10^{6}</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Let <var>m</var> be the number of operations in your solution. In the first line, print <var>m</var>.
In the <var>i</var>-th of the subsequent <var>m</var> lines, print the numbers <var>x</var> and <var>y</var> chosen in the <var>i</var>-th operation, with a space in between.
The output will be considered correct if <var>m</var> is between <var>0</var> and <var>2N</var> (inclusive) and <var>a</var> satisfies the condition after the <var>m</var> operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
-2 5 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
2 3
3 3
</pre>
<ul>
<li>After the first operation, <var>a = (-2,5,4)</var>.</li>
<li>After the second operation, <var>a = (-2,5,8)</var>, and the condition is now satisfied.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
-1 -3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
2 1
</pre>
<ul>
<li>After the first operation, <var>a = (-4,-3)</var> and the condition is now satisfied.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
0 0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<ul>
<li>The condition is satisfied already in the beginning.</li>
</ul></section>
</div>
</span> |
p03183 | <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> blocks, numbered <var>1, 2, \ldots, N</var>.
For each <var>i</var> (<var>1 \leq i \leq N</var>), Block <var>i</var> has a weight of <var>w_i</var>, a solidness of <var>s_i</var> and a value of <var>v_i</var>.</p>
<p>Taro has decided to build a tower by choosing some of the <var>N</var> blocks and stacking them vertically in some order.
Here, the tower must satisfy the following condition:</p>
<ul>
<li>For each Block <var>i</var> contained in the tower, the sum of the weights of the blocks stacked above it is not greater than <var>s_i</var>.</li>
</ul>
<p>Find the maximum possible sum of the values of the blocks contained in the tower.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^3</var></li>
<li><var>1 \leq w_i, s_i \leq 10^4</var></li>
<li><var>1 \leq v_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>w_1</var> <var>s_1</var> <var>v_1</var>
<var>w_2</var> <var>s_2</var> <var>v_2</var>
<var>:</var>
<var>w_N</var> <var>s_N</var> <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the values of the blocks contained in the tower.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 2 20
2 1 30
3 1 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>50
</pre>
<p>If Blocks <var>2, 1</var> are stacked in this order from top to bottom, this tower will satisfy the condition, with the total value of <var>30 + 20 = 50</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 10
3 1 10
2 4 10
1 6 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>40
</pre>
<p>Blocks <var>1, 2, 3, 4</var> should be stacked in this order from top to bottom.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1 10000 1000000000
1 10000 1000000000
1 10000 1000000000
1 10000 1000000000
1 10000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5000000000
</pre>
<p>The answer may not fit into a 32-bit integer type.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8
9 5 7
6 2 7
5 7 3
7 8 8
1 9 6
3 3 3
4 1 7
4 5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>22
</pre>
<p>We should, for example, stack Blocks <var>5, 6, 8, 4</var> in this order from top to bottom.</p></section>
</div>
</span> |
p01444 |
<H1><font color="#000">Problem H:</font> Sky Jump</H1>
<p>
Dr. Kay Em, a genius scientist, developed a new missile named "Ikan-no-i." This missile has <i>N</i> jet engines. When the <i>i</i>-th engine is ignited, the missile's velocity changes to (<i>vx<sub>i</sub></i>, <i>vy<sub>i</sub></i>) immediately.
</p>
<p>
Your task is to determine whether the missile can reach the given target point (<i>X</i>, <i>Y</i> ). The missile can be considered as a mass point in a two-dimensional plane with the <i>y</i>-axis pointing up, affected by the gravity of 9.8 downward (i.e. the negative <i>y</i>-direction) and initially set at the origin (0, 0). The engines can be ignited at any time in any order. Still, note that at least one of them needs to be ignited to get the missile launched.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format.
</p>
<p>
<i>N</i><br>
<i>vx</i><sub>1</sub> <i>vy</i><sub>1</sub><br>
<i>vx</i><sub>2</sub> <i>vy</i><sub>2</sub><br>
...<br>
<i>vx</i><sub><i>N</i></sub> <i>vy</i><sub><i>N</i></sub><br>
<i>X Y</i><br>
</p>
<p>
All values are integers and meet the following constraints: 1 ≤ <i>N</i> ≤ 1,000, 0 < <i>vx<sub>i</sub></i> ≤ 1,000, -1,000 ≤ <i>vy<sub>i</sub></i> ≤ 1,000, 0 < <i>X</i> ≤ 1,000, -1,000 ≤ <i>Y</i> ≤ 1,000.
</p>
<p>
The end of input is indicated by a line with a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output whether the missile can reach the target point in a line: "<span>Yes</span>" if it can, "<span>No</span>" otherwise.
</p>
<H2>Sample Input</H2>
<pre>
1
1 1
10 -480
2
6 7
5 5
4 1
3
10 5
4 4
8 4
2 0
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Yes
Yes
No
</pre>
|
p03479 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>As a token of his gratitude, Takahashi has decided to give his mother an integer sequence.
The sequence <var>A</var> needs to satisfy the conditions below:</p>
<ul>
<li><var>A</var> consists of integers between <var>X</var> and <var>Y</var> (inclusive).</li>
<li>For each <var>1\leq i \leq |A|-1</var>, <var>A_{i+1}</var> is a multiple of <var>A_i</var> and strictly greater than <var>A_i</var>.</li>
</ul>
<p>Find the maximum possible length of the sequence.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X \leq Y \leq 10^{18}</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>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible length of the sequence.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The sequence <var>3,6,18</var> satisfies the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>25 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>314159265 358979323846264338
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>31
</pre></section>
</div>
</span> |
p01014 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1>Problem I: Rolling Block</h1>
<h2>Problem</h2>
<p>
Rolling Blockは直方体の金属体を回転させつつ移動させ、ゴールの穴に落とすゲームである。<br/>
このゲームのクリア条件は金属体をゴールに落とすことである。<br/>
<br/>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_image0" width="500" height="500" alt="image0">
</p>
<p>
<b>ブロックについて</b><br/>
下の図の(1)より、ブロックは1×1×<var>L</var>の直方体である。
ブロックは東西南北のどれかの方向に回転しながら移動することができる。
しかし、ブロックはステージからはみ出るような動きをとることは出来ない。<br/>
下の図の(2)より、ブロックが横に倒れている場合は移動方向に対してこのような回転をしつつ移動する。<br/>
下の図の(3)より、ブロックが直立している場合は移動方向に対してこのような回転をしつつ移動する。<br/>
(2) 、(3) については灰色のブロックが移動前、白色のブロックが移動後のブロックとする。<br/>
黒い矢印はその方向に対してブロックが移動したことを示す。
また、白の矢印は移動する際にブロックがその方向へ回転したことを示す。
ブロックに点線が引かれているが、これは回転を分かりやすくするために引いたものである。
(実際にゲームで扱うブロックにはこのような点線は書かれていない)<br/>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_image1" width="500" height="500" alt="image1">
<br/>
以下の図はブロックの回転を補足するための図である。
サイコロのように対面の和が7になるようなブロックがあるとする。
直立している場合と倒れているブロックについて、このブロックを東西南北の4方向へ回転しつつ移動させたときの上面の数字の変化を以下の図に示す。
(実際にゲームで扱うブロックにはこのような数字は書かれていない。)<br/>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_image2" width="500" height="500" alt="image2">
</p>
<p>
<b>ステージについて</b><br/>
ステージは<var>H</var>×<var>W</var>の二次元グリッドで与えられる(1 ≤ <var>H</var>,<var>W</var> ≤ 25) 。
二次元グリッドはそれぞれ以下の種類のセルから成る。
</p>
<ul>
<li>
<p>"." 床<br/>
床の上にブロックが乗ることができる。
</p>
</li>
<li>
<p>"#" 壁<br/>
壁には進行不可能であり、ブロックの一部が壁の上に乗るような移動はできない。
</p>
</li>
<li>
<p>"S" ブロックの初期位置<br/>
ブロックは1文字だけ与えられる。初期状態では直立している状態しか存在しない。
</p>
</li>
<li>
<p>"G" ゴール地点<br/>
ゴールはステージ中に1つしか出現しない。<br/>
また、ブロックが直立している状態でしかゴールすることは不可能である。<br/>
</p>
</li>
<li>
<p>特殊壁とスイッチ<br/>
アルファベット小文字 特殊壁<br/>
アルファベット大文字 特殊壁に対応するスイッチ<br/>
<br/>
特殊壁は出現時には進行不可能であり、ブロックの一部が特殊壁の上に乗るような移動はできない。
ブロックが回転を行い直立したときにブロックの真下にスイッチがあるとき、そのスイッチは押される。<br/>
スイッチを押したとき、同じアルファベットの特殊壁が出現しているときは消滅し、逆に消滅しているときは出現する。<br/>
ステージ開始直後ではすべての特殊壁が出現しているとする。<br/>
ひとつのステージで現れる特殊壁とスイッチは最大5種類とする。<br/>
スイッチを表すアルファベットは{'A','B','C','D','E'}である。<br/>
特殊壁を表すアルファベットは{'a','b','c','d','e'}である。<br/>
スイッチと特殊壁の数は<var>H</var>×<var>W</var>個以下である。<br/>
特殊壁と同じアルファベットのスイッチがステージの中に必ず出現するとは限らない。<br/>
また、スイッチと同じアルファベットの特殊壁がステージの中に必ず出現するとは限らない。<br/>
</p>
</li>
<li>
<p>"^" トラップ<br/>
トラップのマスの上には直方体が直立した状態で乗ってはいけない。
</p>
</li>
</ul>
<p>
ステージの情報と金属体の初期位置が与えられるので、このパズルを解く最短手数を求めよ。
解が存在しない場合は-1を出力しなさい。
</p>
<h2>Input</h2>
<pre>
<var>H</var> <var>W</var> <var>L</var>
<var>Cell<sub>1-1</sub></var> ... <var>Cell<sub>1-W</sub></var>
.
.
.
<var>Cell<sub>H-1</sub></var> ... <var>Cell<sub>H-W</sub></var>
</pre>
<p>
最初に<var>H</var>,<var>W</var>,<var>L</var>が与えられる。<br/>
それぞれ、ステージの縦の長さ、横の長さ、ブロックの長さを示す。<br/>
次に<var>H</var>×<var>W</var>の二次元グリッドが与えられる。これはステージの情報を表している。<br/>
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>1 ≤ <var>H</var>,<var>W</var> ≤ 25</li>
<li>1 < <var>L</var> < 10</li>
<li>Cell は Cell = {'A','B','C','D','E','S','G','a','b','c','d','e','^','#','.'} から成る。</li>
</ul>
<h2>Output</h2>
<p>
ステージの情報と金属体の初期位置が与えられるので、このパズルを解く最短手数を求めよ。<br/>
解が存在しない場合は-1を出力しなさい。<br/>
</p>
<h2>Sample Input 1</h2>
<pre>
5 5 2
#####
#S.G#
#...#
#...#
#####
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<h2>Sample Input 2</h2>
<pre>
3 12 2
############
#S..A..a..G#
############
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre>
<h2>Sample Input 3</h2>
<pre>
3 12 2
############
#S...A.a..G#
############
</pre>
<h2>Sample Output 3</h2>
<pre>
-1
</pre>
<h2>Sample Input 4</h2>
<pre>
7 13 3
#############
#S....#.....#
#.....#.....#
#.....#.....#
#...........#
#..........G#
#############
</pre>
<h2>Sample Output 4</h2>
<pre>
8
</pre>
<h2>Sample Input 5</h2>
<pre>
3 12 2
############
#S^^.^^.^^G#
############
</pre>
<h2>Sample Output 5</h2>
<pre>
6
</pre> |
p03029 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>A</var> apples and <var>P</var> pieces of apple.</p>
<p>We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.</p>
<p>Find the maximum number of apple pies we can make with what we have now.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>0 \leq A, P \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</var> <var>P</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of apple pies we can make with what we have.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>We cannot make an apple pie in this case, unfortunately.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>32 21
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>58
</pre></section>
</div>
</span> |
p03880 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>A cheetah and a cheater are going to play the game of Nim.
In this game they use <var>N</var> piles of stones.
Initially the <var>i</var>-th pile contains <var>a_i</var> stones.
The players take turns alternately, and the cheetah plays first.
In each turn, the player chooses one of the piles, and takes one or more stones from the pile.
The player who can't make a move loses.</p>
<p>However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah.
From each pile, the cheater takes zero or one stone and eats it before the game.
In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats.</p>
<p>Compute the number of stones the cheater will eat.
In case there is no way for the cheater to win the game even with the cheating, print <code>-1</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 10^5</var></li>
<li><var>2 ≤ a_i ≤ 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var>
:
<var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2
3
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The only way for the cheater to win the game is to take stones from all piles and eat them.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
100
100
100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre></section>
</div>
</span> |
p02792 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Given is a positive integer <var>N</var>.<br/>
Find the number of pairs <var>(A, B)</var> of positive integers not greater than <var>N</var> that satisfy the following condition:</p>
<ul>
<li>When <var>A</var> and <var>B</var> are written in base ten without leading zeros, the last digit of <var>A</var> is equal to the first digit of <var>B</var>, and the first digit of <var>A</var> is equal to the last digit of <var>B</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</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>25
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>17
</pre>
<p>The following <var>17</var> pairs satisfy the condition: <var>(1,1)</var>, <var>(1,11)</var>, <var>(2,2)</var>, <var>(2,22)</var>, <var>(3,3)</var>, <var>(4,4)</var>, <var>(5,5)</var>, <var>(6,6)</var>, <var>(7,7)</var>, <var>(8,8)</var>, <var>(9,9)</var>, <var>(11,1)</var>, <var>(11,11)</var>, <var>(12,21)</var>, <var>(21,12)</var>, <var>(22,2)</var>, and <var>(22,22)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>108
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2020
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>40812
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>200000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>400000008
</pre></section>
</div>
</span> |
p02268 |
<H1>Search II</H1>
<p>
You are given a sequence of <i>n</i> integers S and a sequence of different <i>q</i> integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
</p>
<H2>Input</H2>
<p>
In the first line <i>n</i> is given. In the second line, <i>n</i> integers are given. In the third line <i>q</i> is given. Then, in the fourth line, <i>q</i> integers are given.
</p>
<H2>Output</H2>
<p>
Print C in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>Elements in S is sorted in ascending order</li>
<li>n ≤ 100000</li>
<li> q ≤ 50000 </li>
<li>0 ≤ an element in S ≤ 10<sup>9</sup></li>
<li>0 ≤ an element in T ≤ 10<sup>9</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
1 2 3 4 5
3
3 4 1
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
<H2>Sample Input 2</H2>
<pre>
3
1 2 3
1
5
</pre>
<H2>Sample Output 2</H2>
<pre>
0
</pre>
<H2>Sample Input 3</H2>
<pre>
5
1 1 2 2 3
2
1 2
</pre>
<H2>Sample Output 3</H2>
<pre>
2
</pre>
<H2>Notes</H2>
<!--
<a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a>
-->
|
p00255 |
<H1>パイプつなぎ職人の給料</H1>
<p>
ぼくはパイプつなぎ職人です。パイプをつなぐジョイントとパイプさえもらえれば、どんなパイプだってつないでみせます。ぼくは毎日、親方からパイプとジョイントを渡されて、それをつないで親方に渡します。でも、パイプの数が多すぎるときは、1日でそれを全部つなげることはできません。そんなときでも親方はにっこり笑って、ぼくに給料を渡してくれます。
</p>
<p>
ところで、あるとき変なことに気がつきました。全部のパイプをつなげられたときより、つなげられなかったときの方が給料が多いことがしょっちゅうあるんです。あんまり変なので、ある日、親方が来たときに、給料の計算方法が書いてあるメモをこっそり見ちゃいました。そしたら、なんと
</p>
<p>
"給料は「パイプの本数×パイプの長さの総和」で支払う。ただし、ジョイントでつなげて、ひとつながりになったものは、それを1本のパイプとみなす。"
</p>
<p>
って書いてありました。これで全部つなげた方が給料が安くなることがある理由がわかりました。たとえば下図のように、長さ 1 のパイプ 3 本と長さ 2 のジョイント 2 本を全部つなげると長さ 1+2+1+2+1 = 7 のパイプが 1 本できるので、1 × (7) = 7 です。でも、ジョイントを一つだけ使って長さ 1+2+1 = 4のパイプと長さ 1 のパイプの 2 本にすると2 × (4+1) = 10なので、全部つなげるよりいっぱい給料がもらえます。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_plumber">
</center>
<br/>
<p>
親方がなんでこんな方法で給料を決めてるかわからないけど、これでぼくもどうすればもらえる給料を多くできるかわかりました!
</p>
<p>
それでは、パイプの本数が与えられたとき、もらえる給料の最大の金額を計算するプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる。入力の終わりはゼロ1つの行で示される。各データセットは以下の形式で与えられる。
</p>
<pre>
n
p<sub>1</sub> ... p<sub>n</sub>
j<sub>1</sub> ... j<sub>n-1</sub>
</pre>
<p>
1行目にパイプの本数 n (2 ≤ n ≤ 65000) が与えられる。2行目は1つの空白で区切られた n 個の整数からなる。p<sub>i</sub> (1 ≤ p<sub>i</sub> ≤ 1000) はi番目のパイプの長さを示す。3行目は1つの空白で区切られた n-1 個の整数からなる。j<sub>i</sub> (1 ≤ j<sub>i</sub> ≤ 1000) は i 番目のジョイントの長さを示す。
</p>
<p>
i番目のジョイントは、i 番目と i+1 番目のパイプだけをつなげることができる。つなげたパイプの長さは、p<sub>i</sub> + j<sub>i</sub> + p<sub>i+1</sub> になる。
</p>
<p>
データセットの数は 100 を超えない。
</p>
<h2>出力</h2>
<p>
各データセットごとに、得られる給料の最大の金額を1行に出力する。入力として与えられるデータセットでは、出力される値は必ず32ビット符号無し整数の範囲に収まるものとする。
</p>
<h2>入力例1</h2>
<pre>
3
1 1 1
3 3
4
3 3 3 3
1 1 1
5
1 2 3 4 5
4 3 2 1
0
</pre>
<h2>出力例</h2>
<pre>
12
48
76
</pre>
|
p01917 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath2017.js" charset="UTF-8"></script>
<h2>B: だんすなうwww - Dance Now! -</h2>
<h3>物語</h3>
<p>
前回のラボライフ!ダイガクイン!!
マスターアイドルたちが競う最大の大会「ラボライフ」の前哨戦ともいえるイベント「マスターアイドルワールド」で9位を取ってしまったドサンコスノー。
キレのあるダンスは「9位の舞」、渾身の決めポーズも「9位の構え」などと冷やかされてしまい、心に深い傷を負ってしまう。
来たるラボライフ予備予選では絶対に9位をとるわけにはいかない……
決意を新たにしたドサンコスノーは、自分たちの特技「セルフコントロール」に磨きをかけ、決戦の地へと向かうのだった。
</p>
<h3>問題</h3>
<p>
<var>N</var>組のユニットが競う大会「ラボライフ」が開かれる。
この大会では、スマイル・ピュア・クールの3つの部門で別々に勝負が行われ、それぞれの勝負で得た得点の合計が高い順に総合順位が決定される。
スマイル部門の順位はそれぞれのユニットが持つスマイル値の値が高い順に決定される。
ピュア・クール部門でも同様にピュア値・クール値が高い順に順位が決定される。
順位に応じた得点設定は全部門で共通しており、ある部門で<var>i</var>位のユニットは、その部門では<var>r_i</var>点を得る。
</p>
<p>
ここで、順位が<var>i</var>位のユニットと同じ値を持つユニットが複数ある場合、それらは同率<var>i</var>位とみなし、等しく得点<var>r_i</var>を得る。
より詳細には、<var>k</var>ユニットが同率<var>i</var>位の場合には、<var>k</var>ユニットが等しく得点<var>r_i</var>を得て、<var>r_{i+1}</var>から<var>r_{i+k-1}</var>までの得点を得るユニットはいない。
また、その次に値が大きいユニット (たち) は得点<var>r_{i+k}</var>を得る。
具体的な例として、例えばそれぞれスマイル値が1, 3, 2, 3, 2の5つのユニットがあり、順位が高い順に10, 8, 6, 4, 2点が得られる場合を考える。
このとき、2番目と4番目のユニットが10点、3番目と5番目のユニットが6点、1番目のユニットが2点を得ることになる。
</p>
<p>
ラボライフ予備予選に参加するユニット・ドサンコスノーは「ラボライフは遊びじゃない」と考えているため、真っ先に大会にエントリーし、1番目のユニットとなった。
しかし、大会に参加する<var>N</var>組すべてのスマイル値・ピュア値・クール値 (以降3値と呼ぶ) の情報を入手したところ、自分たちの総合順位が (同率) 9位であることがわかった。
ドサンコスノーは特技「セルフコントロール」により3値のうちいずれか1つの値を任意の値だけ上昇させることができるが、あまり上げすぎると疲れてしまい本戦に影響するので、できるだけ上昇値を小さくしたい。
ドサンコスノーはとにかく9位を脱したいので、同率8位以上になるようにセルフコントロールによって3値のいずれか1値を上げるとき、上げる必要のある最小の値を求めよ。
</p>
<h3>入力形式</h3>
<p>入力は以下の形式で与えられる。</p>
<pre>
<var>N</var>
<var>r_1</var> ... <var>r_N</var>
<var>s_1</var> <var>p_1</var> <var>c_1</var>
...
<var>s_N</var> <var>p_N</var> <var>c_N</var>
</pre>
<p>
1行目はユニットの数を表す整数<var>N</var>が1行で与えられる。
続く2行目は<var>N</var>個の整数が空白区切りで与えられる。<var>i</var> <var>(1 \leq i \leq N)</var> 番目の整数は各部門で順位が<var>i</var>位だったときに貰える得点<var>r_i</var>を表す。
続く<var>N</var>行目のうち、<var>j</var>行目には3つの整数<var>s_j, p_j, c_j</var>が与えられる。これらはそれぞれ<var>j</var>番目のユニットのスマイル値<var>s_j</var>、ピュア値<var>p_j</var>、クール値<var>c_j</var>を表す。
なおドサンコスノーは1番目のユニットであるとする。
</p>
<h3>制約</h3>
<ul>
<li><var>9 \leq N \leq 100</var></li>
<li><var>100 \geq r_1 > ... > r_N \geq 1</var></li>
<li><var>1 \leq s_j, p_j, c_j \leq 100</var> <var>(1 \leq j \leq N)</var></li>
<li>セルフコントロールする前、ドサンコスノーは9位 (同率9位の場合はあるが、同率8位以上であることはない)</li>
</ul>
<h3>出力形式</h3>
<p>セルフコントロールによって3値のどれかを<var>x</var>だけ上げることでドサンコスノーが同率8位以上になるような最小の<var>x</var>を1行に出力せよ。ただし、セルフコントロールによってどの値をどれだけ上げても順位が上げられない場合は "Saiko" と出力せよ。</p>
<h3>入力例1</h3>
<pre>
9
9 8 7 6 5 4 3 2 1
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
</pre>
<h3>出力例1</h3>
<pre>2</pre>
<p>例えばセルフコントロールでスマイル値を2だけ上げると、ドサンコスノーの各部門における順位はそれぞれ同率7位、9位、9位となり、3+1+1 = 5点を得る。一方、2番目のユニットの各部門における順位はそれぞれ9位、8位、8位となり、1+2+2 = 5点を得る。他のユニットは6点以上を獲得するため、この2つのユニットが同率8位となり、条件を満たす。</p>
<h3>入力例2</h3>
<pre>
9
9 8 7 6 5 4 3 2 1
1 1 1
2 6 9
6 9 2
9 2 6
3 5 8
5 8 3
8 3 5
4 7 4
7 4 7
</pre>
<h3>出力例2</h3>
<pre>Saiko</pre>
<p>どの値をどれだけ上げてもドサンコスノーは11点までしか得ることができないが、他のユニットは必ず14点以上を得ることができるため、ドサンコスノーは不動の9位である。</p> |
p02638 | <span class="lang-en">
<p>Score : <var>2000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are integers <var>N</var> and <var>K</var>, and a prime number <var>P</var>. Find the number, modulo <var>P</var>, of directed graphs <var>G</var> with <var>N</var> vertices that satisfy below. Here, the vertices are distinguishable from each other.</p>
<ul>
<li><var>G</var> is a tournament, that is, <var>G</var> contains no duplicated edges or self-loops, and exactly one of the edges <var>u\to v</var> and <var>v\to u</var> exists for any two vertices <var>u</var> and <var>v</var>.</li>
<li>The in-degree of every vertex in <var>G</var> is at most <var>K</var>.</li>
<li>For any four distinct vertices <var>a</var>, <var>b</var>, <var>c</var>, and <var>d</var> in <var>G</var>, it is not the case that all of the six edges <var>a\to b</var>, <var>b\to c</var>, <var>c\to a</var>, <var>a\to d</var>, <var>b\to d</var>, and <var>c\to d</var> exist simultaneously.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 \leq N \leq 200</var></li>
<li><var>\frac{N-1}{2} \leq K \leq N-1</var></li>
<li><var>10^8<P<10^9</var></li>
<li><var>N</var> and <var>K</var> are integers.</li>
<li><var>P</var> is a prime number.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var> <var>P</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of directed graphs that satisfy the conditions, modulo <var>P</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>56
</pre>
<p>Among the <var>64</var> graphs with four vertices, <var>8</var> are isomorphic to the forbidden induced subgraphs, and the other <var>56</var> satisfy the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 3 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>720
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>50 37 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>495799508
</pre></section>
</div>
</span> |
p00605 |
<H1><font color="#000000">Problem A:</font> Vampirish Night</H1>
<p>
There is a vampire family of <i>N</i> members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that <i>K</i> blood types of ones are mixed, and each vampire has his/her favorite amount for each blood type.
</p>
<p>
You, cook of the family, are looking inside a fridge to prepare dinner. Your first task is to write a program that judges if all family members' dinner can be prepared using blood in the fridge.
</p>
<H2>Input</H2>
<p>
Input file consists of a number of data sets.
One data set is given in following format:
</p>
<pre>
<i>N K</i>
<i>S</i><sub>1</sub> <i>S</i><sub>2</sub> ... <i>S<sub>K</sub></i>
<i>B</i><sub>11</sub> <i>B</i><sub>12</sub> ... <i>B</i><sub>1<i>K</i></sub>
<i>B</i><sub>21</sub> <i>B</i><sub>22</sub> ... <i>B</i><sub>2<i>K</i></sub>
:
<i>B</i><sub><i>N</i>1</sub> <i>B</i><sub><i>N</i>2</sub> ... <i>B</i><sub><i>NK</i></sub>
</pre>
<p>
<i>N</i> and <i>K</i> indicate the number of family members and the number of blood types respectively.</p>
<p>
<i>S<sub>i</sub></i> is an integer that indicates the amount of blood of the <i>i</i>-th blood type that is in a fridge.
</p>
<p>
<i>B<sub>ij</sub></i> is an integer that indicates the amount of blood of the <i>j</i>-th blood type that the <i>i</i>-th vampire uses.
</p>
<p>
The end of input is indicated by a case where <i>N</i> = <i>K</i> = 0. You should print nothing for this data set.
</p>
<H2>Output</H2>
<p>
For each set, print "<span>Yes</span>" if everyone's dinner can be prepared using blood in a fridge, "<span>No</span>" otherwise (without quotes).
</p>
<H2>Constraints</H2>
<ul>
<li>Judge data includes at most 100 data sets.</li>
<li>1 ≤ <i>N</i> ≤ 100</li>
<li>1 ≤ <i>K</i> ≤ 100</li>
<li>0 ≤ <i>S<sub>i</sub></i> ≤ 100000</li>
<li>0 ≤ <i>B<sub>ij</sub></i> ≤ 1000</li>
</ul>
<H2>Sample Input</H2>
<pre>
2 3
5 4 5
1 2 3
3 2 1
3 5
1 2 3 4 5
0 1 0 1 2
0 1 1 2 2
1 0 3 1 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Yes
No
</pre>
|
p00412 | <h1>ガソリンスタンド</h1>
<p>
白虎サービスエリアのガソリンスタンドには、$1$から$N$の番号が割り当てられた$N$個のレーンがあります。各レーンの先頭の車が給油を行うことができます。
</p>
<p>
ガソリンスタンドに入場した車は、並んでいる車が最も少ないレーンを選び列の末尾に並びます。そのようなレーンが複数ある場合は、番号が最も小さいレーンを選びます。給油が終わるとその車はレーンから出ていき、その後ろの車が給油を行います。一度レーンを選んだら、他のレーンに移ることはできません。また、レーンに並んでいる車の順番が変わることはありません。
</p>
<p>
レーンの数、入場した車と給油が終了したレーンの情報が与えられたとき、給油が終了した車のナンバーを順番に出力するプログラムを作成せよ。入場の情報はスタンドに入ってくる車のナンバー、給油終了の情報は先頭の車の給油が終了したレーン番号としてそれぞれ与えられる。ただし、最初はどのレーンにも車は並んでいないものとする。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
$N$ $M$
$info_1$
$info_2$
:
$info_M$
</pre>
<p>
1行目にレーンの数$N$ ($1\leq N \leq 10$)と情報の数$M$ ($2 \leq M \leq 10,000$)が与えられる。続く$M$行に各情報$info_i$が与えられる。各$info_i$は以下のいずれかの形式で与えられる。
</p>
<pre>
0 $lane$
</pre>
<p>
または
</p>
<pre>
1 $car$
</pre>
<p>
最初の数字が0の場合、番号が$lane$ ($1 \leq lane \leq N$)であるレーンに並んでいる先頭の車の給油が終了したことを示す。最初の数字が1の場合、ナンバーが$car$ ($1 \leq car \leq 9,999$)である車がスタンドに入場したことを示す。
</p>
<p>
入力は以下の制約を満たす。
</p>
<ul>
<li> ガソリンスタンドに入って来る車のナンバーは、全て異なる。</li>
<li> 最初の数字が0,1である情報は、それぞれ必ず1つ以上ある。</li>
<li> 車のいないレーンに対して、最初の数字が0である情報は与えられない。</li>
</ul>
<h2>出力</h2>
<p>
給油終了の情報ごとに、給油が終了した車のナンバーを1行に出力する。
</p>
<h2>入出力例</h2>
<h3>
入力例
</h3>
<pre>
2 7
1 999
1 1000
0 2
1 1001
1 1002
0 1
0 1
</pre>
<h3>出力例</h3>
<pre>
1000
999
1002
</pre>
|
p00042 |
<H1>泥棒</H1>
<p>
宝物がたくさん収蔵されている博物館に、泥棒が大きな風呂敷を一つだけ持って忍び込みました。盗み出したいものはたくさんありますが、風呂敷が耐えられる重さが限られており、これを超えると風呂敷が破れてしまいます。そこで泥棒は、用意した風呂敷を破らず且つ最も価値が高くなるようなお宝の組み合わせを考えなくてはなりません。
</p>
<p>
風呂敷が耐えられる重さ <var>W</var>、および博物館にある個々のお宝の価値と重さを読み込んで、重さの総和が <var>W</var> を超えない範囲で価値の総和が最大になるときの、お宝の価値総和と重さの総和を出力するプログラムを作成してください。ただし、価値の総和が最大になる組み合わせが複数あるときは、重さの総和が小さいものを出力することとします。
</p>
<!--
また、博物館にあるお宝の総数は 1000 以下とし、お宝の価値は10000 以下とします。
-->
<H2>Input</H2>
<p>
複数のデータセットが与えられます。各データセットは以下のような形式で与えられます。
</p>
<pre>
<var>W</var>
<var>N</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>
1行目に風呂敷の耐えられる重さを表す整数 <var>W</var> (<var>W</var> ≤ 1,000)、2行目にお宝の数 <var>N</var> (1 ≤ <var>N</var> ≤ 1,000) が与えられます。続く <var>N</var> 行に <var>i</var> 番目のお宝の価値を表す整数 <var>v<sub>i</sub></var> (0 ≤ <var>v<sub>i</sub></var> ≤ 10,000) とその重さを表す整数 <var>w<sub>i</sub></var> (0 ≤ <var>w<sub>i</sub></var> ≤ <var>W</var>) の組がそれぞれ1行に与えられます。
</p>
<p>
<var>W</var> が 0 のとき入力の最後とします。データセットの数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
各データセットに対して以下のように出力して下さい。
</p>
<pre>
Case データセットの番号:
風呂敷に入れたお宝の価値総和
そのときのお宝の重さの総和
</pre>
<H2>Sample Input</H2>
<pre>
50
5
60,10
100,20
120,30
210,45
10,4
50
5
60,10
100,20
120,30
210,45
10,4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1:
220
49
Case 2:
220
49
</pre>
|
p02585 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi will play a game using a piece on an array of squares numbered <var>1, 2, \cdots, N</var>. Square <var>i</var> has an integer <var>C_i</var> written on it. Also, he is given a permutation of <var>1, 2, \cdots, N</var>: <var>P_1, P_2, \cdots, P_N</var>.</p>
<p>Now, he will choose one square and place the piece on that square. Then, he will make the following move some number of times between <var>1</var> and <var>K</var> (inclusive):</p>
<ul>
<li>In one move, if the piece is now on Square <var>i</var> <var>(1 \leq i \leq N)</var>, move it to Square <var>P_i</var>. Here, his score increases by <var>C_{P_i}</var>.</li>
</ul>
<p>Help him by finding the maximum possible score at the end of the game. (The score is <var>0</var> at the beginning of the game.)</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 5000</var></li>
<li><var>1 \leq K \leq 10^9</var></li>
<li><var>1 \leq P_i \leq N</var></li>
<li><var>P_i \neq i</var></li>
<li><var>P_1, P_2, \cdots, P_N</var> are all different.</li>
<li><var>-10^9 \leq C_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>P_1</var> <var>P_2</var> <var>\cdots</var> <var>P_N</var>
<var>C_1</var> <var>C_2</var> <var>\cdots</var> <var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible score at the end of the game.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
2 4 5 1 3
3 4 -10 -8 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>When we start at some square of our choice and make at most two moves, we have the following options:</p>
<ul>
<li>If we start at Square <var>1</var>, making one move sends the piece to Square <var>2</var>, after which the score is <var>4</var>. Making another move sends the piece to Square <var>4</var>, after which the score is <var>4 + (-8) = -4</var>.</li>
<li>If we start at Square <var>2</var>, making one move sends the piece to Square <var>4</var>, after which the score is <var>-8</var>. Making another move sends the piece to Square <var>1</var>, after which the score is <var>-8 + 3 = -5</var>.</li>
<li>If we start at Square <var>3</var>, making one move sends the piece to Square <var>5</var>, after which the score is <var>8</var>. Making another move sends the piece to Square <var>3</var>, after which the score is <var>8 + (-10) = -2</var>.</li>
<li>If we start at Square <var>4</var>, making one move sends the piece to Square <var>1</var>, after which the score is <var>3</var>. Making another move sends the piece to Square <var>2</var>, after which the score is <var>3 + 4 = 7</var>.</li>
<li>If we start at Square <var>5</var>, making one move sends the piece to Square <var>3</var>, after which the score is <var>-10</var>. Making another move sends the piece to Square <var>5</var>, after which the score is <var>-10 + 8 = -2</var>.</li>
</ul>
<p>The maximum score achieved is <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3
2 1
10 -7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>13
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 3
3 1 2
-1000 -2000 -3000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1000
</pre>
<p>We have to make at least one move.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 58
9 1 6 7 8 4 3 2 10 5
695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>29507023469
</pre>
<p>The absolute value of the answer may be enormous.</p></section>
</div>
</span> |
p01203 |
<H1><font color="#000">Problem B:</font> Compress Files</H1>
<p>
Your computer is a little old-fashioned. Its CPU is slow, its memory is not enough, and its hard drive is
near to running out of space. It is natural for you to hunger for a new computer, but sadly you are not so
rich. You have to live with the aged computer for a while.
</p>
<p>
At present, you have a trouble that requires a temporary measure immediately. You downloaded a new
software from the Internet, but failed to install due to the lack of space. For this reason, you have decided
to compress all the existing files into archives and remove all the original uncompressed files, so more
space becomes available in your hard drive.
</p>
<p>
It is a little complicated task to do this within the limited space of your hard drive. You are planning to
make free space by repeating the following three-step procedure:
</p>
<ol>
<li> Choose a set of files that have not been compressed yet.</li>
<li> Compress the chosen files into one new archive and save it in your hard drive. Note that this step
needs space enough to store both of the original files and the archive in your hard drive.</li>
<li> Remove all the files that have been compressed.</li>
</ol>
<p>
For simplicity, you don’t take into account extraction of any archives, but you would like to reduce the
number of archives as much as possible under this condition. Your task is to write a program to find the
minimum number of archives for each given set of uncompressed files.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets.
</p>
<p>
Each data set starts with a line containing two integers <i>n</i> (1 ≤ <i>n</i> ≤ 14) and <i>m</i> (1 ≤ <i>m</i> ≤ 1000), where
<i>n</i> indicates the number of files and <i>m</i> indicates the available space of your hard drive before the task of
compression. This line is followed by <i>n</i> lines, each of which contains two integers <i>b<sub>i</sub></i> and <i>a<sub>i</sub></i>. <i>b<sub>i</sub></i> indicates
the size of the <i>i</i>-th file without compression, and <i>a<sub>i</sub></i> indicates the size when compressed. The size of each
archive is the sum of the compressed sizes of its contents. It is guaranteed that <i>b<sub>i</sub></i> ≥ <i>a<sub>i</sub></i> holds for any
1 ≤ <i>i</i> ≤ <i>n</i>.
</p>
<p>
A line containing two zeros indicates the end of input.
</p>
<H2>Output</H2>
<p>
For each test case, print the minimum number of compressed files in a line. If you cannot compress all
the files in any way, print “Impossible” instead.
</p>
<H2>Sample Input</H2>
<pre>
6 1
2 1
2 1
2 1
2 1
2 1
5 1
1 1
4 2
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
Impossible
</pre>
|
p04001 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of digits between <code>1</code> and <code>9</code>, inclusive.
You can insert the letter <code>+</code> into some of the positions (possibly none) between two letters in this string.
Here, <code>+</code> must not occur consecutively after insertion.</p>
<p>All strings that can be obtained in this way can be evaluated as formulas.</p>
<p>Evaluate all possible formulas, and print the sum of the results.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10</var></li>
<li>All letters in <var>S</var> are digits between <code>1</code> and <code>9</code>, inclusive.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the evaluated value over all possible formulas.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>125
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>176
</pre>
<p>There are <var>4</var> formulas that can be obtained: <code>125</code>, <code>1+25</code>, <code>12+5</code> and <code>1+2+5</code>. When each formula is evaluated,</p>
<ul>
<li><var>125</var></li>
<li><var>1+25=26</var></li>
<li><var>12+5=17</var></li>
<li><var>1+2+5=8</var></li>
</ul>
<p>Thus, the sum is <var>125+26+17+8=176</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12656242944
</pre></section>
</div>
</span> |
p01653 |
<h2>Problem Statement</h2>
<p>
A magician lives in a country which consists of <var>N</var> islands and <var>M</var> bridges.
Some of the bridges are magical bridges, which are created by the magician.
Her magic can change all the lengths of the magical bridges to the same non-negative integer simultaneously.
</p>
<p>
This country has a famous 2-player race game.
Player 1 starts from island <var>S_1</var> and Player 2 starts from island <var>S_2</var>.
A player who reached the island <var>T</var> first is a winner.
</p>
<p>
Since the magician loves to watch this game, she decided to make the game most exiting by changing the length of the magical bridges
so that the difference between the shortest-path distance from <var>S_1</var> to <var>T</var> and the shortest-path distance from <var>S_2</var> to <var>T</var> is as small as possible. We ignore the movement inside the islands.
</p>
<p>
Your job is to calculate how small the gap can be.
</p>
<p>
Note that she assigns a length of the magical bridges before the race starts <i>once</i>,
and does not change the length <i>during the race</i>.
</p>
<h2>Input</h2>
<p>
The input consists of several datasets. The end of the input is denoted by five zeros separated by a single-space. Each dataset obeys <i>the</i> following format. Every number in the inputs is integer.
</p>
<pre>
<var>N</var> <var>M</var> <var>S_1</var> <var>S_2</var> <var>T</var>
<var>a_1</var> <var>b_1</var> <var>w_1</var>
<var>a_2</var> <var>b_2</var> <var>w_2</var>
...
<var>a_M</var> <var>b_M</var> <var>w_M</var>
</pre>
<p>
(<var>a_i, b_i</var>) indicates the bridge <var>i</var> connects the two islands <var>a_i</var> and <var>b_i</var>.
</p>
<p>
<var>w_i</var> is either a non-negative integer or a letter <code>x</code> (quotes for clarity). If <var>w_i</var> is an integer, it indicates the bridge <var>i</var> is normal and its length is <var>w_i</var>. Otherwise, it indicates the bridge <var>i</var> is magical.
</p>
<p>
You can assume the following:
</p>
<ul>
<li> <var>1\leq N \leq 1,000</var></li>
<li> <var>1\leq M \leq 2,000</var></li>
<li> <var>1\leq S_1, S_2, T \leq N</var></li>
<li> <var>S_1, S_2, T</var> are all different.</li>
<li> <var>1\leq a_i, b_i \leq N</var></li>
<li> <var>a_i \neq b_i</var></li>
<li> For all normal bridge <var>i</var>, <var>0 \leq w_i \leq 1,000,000,000</var></li>
<li> The number of magical bridges <var>\leq 100</var></li>
</ul>
<h2>Output</h2>
<p>
For each dataset, print the answer in a line.
</p>
<h2>Sample Input</h2>
<pre>
3 2 2 3 1
1 2 1
1 3 2
4 3 1 4 2
2 1 3
2 3 x
4 3 x
0 0 0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1
1
</pre> |
p00941 |
<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 G
Do Geese See God?</h2>
<p>
A palindrome is a sequence of characters which reads the same backward or forward. Famous ones include "dogeeseseegod" ("Do geese see God?"), "amoreroma" ("Amore, Roma.") and "risetovotesir" ("Rise to vote, sir.").
</p>
<p>
An ancient sutra has been handed down through generations at a temple on Tsukuba foothills. They say the sutra was a palindrome, but some of the characters have been dropped through transcription.
</p>
<p>
A famous scholar in the field of religious studies was asked to recover the original. After long repeated deliberations, he concluded that no information to recover the original has been lost, and that the original can be reconstructed as the shortest palindrome including all the characters of the current sutra in the same order. That is to say, the original sutra is obtained by adding some characters before, between, and/or behind the characters of the current.
</p>
<p>
Given a character sequence, your program should output one of the shortest palindromes containing the characters of the current sutra preserving their order. One of the shortest? Yes, more than one shortest palindromes may exist. Which of them to output is also specified as its rank among the candidates in the lexicographical order.
</p>
<p>
For example, if the current sutra is cdba and 7th is specified, your program should output <span>cdabadc</span> among the 8 candidates, <span>abcdcba</span>, <span>abdcdba</span>, <span>acbdbca</span>, <span>acdbdca</span>, <span>cabdbac</span>, <span>cadbdac</span>, <span>cdabadc</span> and <span>cdbabdc</span>.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The test case is formatted as follows.<br>
<br>
$S$<br>
$k$<br>
</br>
The first line contains a string $S$ composed of lowercase letters from '<span>a</span>' to '<span>z</span>'. The length of $S$ is greater than 0, and less than or equal to 2000. The second line contains an integer $k$ which represents the rank in the lexicographical order among the candidates of the original sutra. $1 \leq k \leq 10^{18}$.
</p>
<h3>Output</h3>
<p>
Output the $k$-th string in the lexicographical order among the candidates of the original sutra. If the number of the candidates is less than $k$, output <span>NONE</span>.
</p>
<p>
Though the first lines of the Sample Input/Output 7 are folded at the right margin, they are actually single lines.
</p>
<h3>Sample Input 1</h3>
<pre>crc
1</pre>
<h3>Sample Output 1</h3>
<pre>crc</pre>
<h3>Sample Input 2</h3>
<pre>icpc
1</pre>
<h3>Sample Output 2</h3>
<pre>icpci</pre>
<h3>Sample Input 3</h3>
<pre>hello
1</pre>
<h3>Sample Output 3</h3>
<pre>heolloeh</pre>
<h3>Sample Input 4</h3>
<pre>hoge
8</pre>
<h3>Sample Output 4</h3>
<pre>hogegoh</pre>
<h3>Sample Input 5</h3>
<pre>hoge
9</pre>
<h3>Sample Output 5</h3>
<pre>NONE</pre>
<h3>Sample Input 6</h3>
<pre>bbaaab
2</pre>
<h3>Sample Output 6</h3>
<pre>NONE</pre>
<h3>Sample Input 7</h3>
<pre>thdstodxtksrnfacdsohnlfuivqvqsozdstwa
szmkboehgcerwxawuojpfuvlxxdfkezprodne
ttawsyqazekcftgqbrrtkzngaxzlnphynkmsd
sdleqaxnhehwzgzwtldwaacfczqkfpvxnalnn
hfzbagzhqhstcymdeijlbkbbubdnptolrmemf
xlmmzhfpshykxvzbjmcnsusllpyqghzhdvljd
xrrebeef
11469362357953500</pre>
<h3>Sample Output 7</h3>
<pre>feeberrthdstodxtksrnfacdjsohnlfuivdhq
vqsozhgdqypllstwausnzcmjkboehgcerzvwx
akyhswuojpfhzumvmlxxdfkmezmprlotpndbu
bbkblnjiedttmawsyqazekcftgshqbrhrtkzn
gaxbzfhnnlanxvphyfnkqmzcsdfscaawdleqa
xtnhehwzgzwhehntxaqeldwaacsfdsczmqknf
yhpvxnalnnhfzbxagnzktrhrbqhsgtfckezaq
yswamttdeijnlbkbbubdnptolrpmzemkfdxxl
mvmuzhfpjouwshykaxwvzrecgheobkjmcznsu
awtsllpyqdghzosqvqhdviuflnhosjdcafnrs
ktxdotsdhtrrebeef</pre>
|
p03394 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. </p>
<p>She thinks that a set <var>S = \{a_{1}, a_{2}, ..., a_{N}\}</var> of <strong>distinct</strong> positive integers is called <strong>special</strong> if for all <var>1 \leq i \leq N</var>, the gcd (greatest common divisor) of <var>a_{i}</var> and the sum of the remaining elements of <var>S</var> is <strong>not</strong> <var>1</var>.</p>
<p>Nagase wants to find a <strong>special</strong> set of size <var>N</var>. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a <strong>special</strong> set of size <var>N</var> such that the gcd of all elements are <var>1</var> and the elements of the set does not exceed <var>30000</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 20000</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>Output <var>N</var> space-separated integers, denoting the elements of the set <var>S</var>. <var>S</var> must satisfy the following conditions :</p>
<ul>
<li>The elements must be <strong>distinct</strong> positive integers not exceeding <var>30000</var>.</li>
<li>The gcd of all elements of <var>S</var> is <var>1</var>, i.e. there does not exist an integer <var>d > 1</var> that divides all elements of <var>S</var>.</li>
<li><var>S</var> is a <strong>special</strong> set.</li>
</ul>
<p>If there are multiple solutions, you may output any of them. The elements of <var>S</var> may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 5 63
</pre>
<p><var>\{2, 5, 63\}</var> is special because <var>gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7</var>. Also, <var>gcd(2, 5, 63) = 1</var>. Thus, this set satisfies all the criteria.</p>
<p>Note that <var>\{2, 4, 6\}</var> is not a valid solution because <var>gcd(2, 4, 6) = 2 > 1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2 5 20 63
</pre>
<p><var>\{2, 5, 20, 63\}</var> is special because <var>gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9</var>. Also, <var>gcd(2, 5, 20, 63) = 1</var>. Thus, this set satisfies all the criteria.</p></section>
</div>
</span> |
p03681 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> dogs and <var>M</var> monkeys. He wants them to line up in a row.</p>
<p>As a Japanese saying goes, these dogs and monkeys are on bad terms. <em>("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)</em> Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.</p>
<p>How many such arrangements there are? Find the count modulo <var>10^9+7</var> (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N,M ≤ 10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible arrangements, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>We will denote the dogs by <code>A</code> and <code>B</code>, and the monkeys by <code>C</code> and <code>D</code>. There are eight possible arrangements: <code>ACBD</code>, <code>ADBC</code>, <code>BCAD</code>, <code>BDAC</code>, <code>CADB</code>, <code>CBDA</code>, <code>DACB</code> and <code>DBCA</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>530123477
</pre></section>
</div>
</span> |
p02993 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>The door of Snuke's laboratory is locked with a security code.</p>
<p>The security code is a <var>4</var>-digit number. We say the security code is <em>hard to enter</em> when it contains two consecutive digits that are the same.</p>
<p>You are given the current security code <var>S</var>. If <var>S</var> is hard to enter, print <code>Bad</code>; otherwise, print <code>Good</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>S</var> is a <var>4</var>-character string consisting of digits.</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> is hard to enter, print <code>Bad</code>; otherwise, print <code>Good</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3776
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Bad
</pre>
<p>The second and third digits are the same, so <var>3776</var> is hard to enter.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8080
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Good
</pre>
<p>There are no two consecutive digits that are the same, so <var>8080</var> is not hard to enter.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1333
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Bad
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>0024
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Bad
</pre></section>
</div>
</span> |
p01346 |
<H1><font color="#000">Problem H: </font> Ropeway</H1>
<p>
On a small island, there are two towns Darkside and Sunnyside, with steep mountains between them. There’s a company Intertown Company of Package Conveyance; they own a ropeway car between Darkside and Sunnyside and are running a transportation business. They want maximize the revenue by loading as much package as possible on the ropeway car.
</p>
<p>
The ropeway car looks like the following. It’s <i>L</i> length long, and the center of it is hung from the rope. Let’s suppose the car to be a 1-dimensional line segment, and a package to be a point lying on the line. You can put packages at anywhere including the edge of the car, as long as the distance between the package and the center of the car is greater than or equal to R and the car doesn’t fall down.
</p>
<p>
The car will fall down when the following condition holds:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ropeway">
</center>
<p>
Here <i>N</i> is the number of packages; <i>m<sub>i</sub></i> the weight of the <i>i</i>-th package; <i>x<sub>i</sub></i> is the position of the <i>i</i>-th package relative to the center of the car.
</p>
<p>
You, a Darkside programmer, are hired as an engineer of the company. Your task is to write a program which reads a list of package and checks if all the packages can be loaded in the listed order without the car falling down at any point.
</p>
<H2>Input</H2>
<p>
The input has two lines, describing one test case. The first line contains four integers <i>N</i>, <i>L</i>, <i>M</i>, <i>R</i>. The second line contains <i>N</i> integers <i>m</i><sub>0</sub>, <i>m</i><sub>1</sub>, ... <i>m</i><sub><i>N</i>-1</sub>. The integers are separated by a space.
</p>
<H2>Output</H2>
<p>
If there is a way to load all the packages, output “Yes” in one line, without the quotes. Otherwise, output “No”.
</p>
<H2>Sample Input 1</H2>
<pre>
3 3 2 1
1 1 4
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
Yes
</pre>
<H2>Sample Input 2</H2>
<pre>
3 3 2 1
1 4 1
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
No
</pre>
|
p01716 |
<h1>問題 E : Pattern Language</h1>
<h2>問題文</h2>
<p>
<var>m</var> 個の相異なるアルファベット <var>var_0,  var_1,   … ,  var_{m-1}</var> がある.
<var>0,   1,   … ,   9,   var_0,   var_1,   … ,   var_{m-1}</var> の <var>10+m</var> 種類の文字からなる,長さ <var>N</var> の文字列 <var>s_0s_1s_2…s_{N-1}</var> が与えられる.
この文字列における各アルファベットを数字で置き換えて回文になるようにしたい.(回文とは,前から読んでも後ろから読んでも同じ文字列をあらわす.)
ここで,同じアルファベットは同じ数字で置き換えなければならない.また与えられたすべてのアルファベット<var>var_i</var>は少なくとも,一度は文字列<var>s_0s_1s_2…s_{N-1}</var>にあらわれる.
</p>
<p>
アルファベット <var>var_i</var> は <var>0</var> 以上 <var>u_i</var> 以下の,leading zero を含まない整数に置き換える事ができる.
置き換えた後の文字列が回文になるような置き換え方が何通り存在するかを,<b>mod</b> <var>10^9+7</var> で求めよ.
なお,アルファベットの置き換え方が異なれば,得られる文字列が同じでも異なるものとして数える.
</p>
<h2>入力形式</h2>
<p>
入力は以下の形式で与えられる
<pre>
<var>N</var> <var>m</var>
<var>s_0s_1s_2…s_{N-1}</var>
<var>var_0</var> <var>u_0</var>
<var>...</var>
<var>var_{m-1}</var> <var>u_{m-1}</var>
</pre>
<h2>出力形式</h2>
<p>
置き換え方の場合の数を <var>10^9 + 7</var> で割った剰余を一行で出力せよ.
</p>
<h2>制約</h2>
<ul>
<li><var>1 ≤ N ≤ 500</var></li>
<li><var>1 ≤ m ≤ 10</var></li>
<li><var>0 ≤ u_i ≤ 99</var></li>
<li><var>s_i</var> ∈ <var>\{'0',   '1',   … ,   '9',   var_0,   var_1,   … ,   var_{m-1}\}</var></li>
<li><var>var_i ∈ \{'a',   'b',   … ,   'j'\}</var>
<li>各アルファベット <var>var_i</var> は <var>s_0s_1s_2 …s_{N-1}</var> に少なくとも一度は現れる.</li>
<li><var>var_0,  var_1,  … ,  var_{m-1}</var> はすべて異なる</li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
3 1
a1a
a 99
</pre>
<h3>出力例 1</h3>
<pre>
19
</pre>
<h3>入力例 2</h3>
<pre>
5 3
jbfjb
f 50
b 25
j 5
</pre>
<h3>出力例 2</h3>
<pre>
252
</pre>
<h3>入力例 3</h3>
<pre>
7 3
jag2013
j 53
a 10
g 93
</pre>
<h3>出力例 3</h3>
<pre>
23
</pre>
|
p00804 |
<H1><font color="#000">Problem B:</font> e-Market</H1>
<p>
The city of Hakodate recently established a commodity exchange market. To participate in the market, each dealer transmits through the Internet an order consisting of his or her name, the type of the order (buy or sell), the name of the commodity, and the quoted price.
</p>
<p>
In this market a deal can be made only if the price of a sell order is lower than or equal to the price of a buy order. The price of the deal is the mean of the prices of the buy and sell orders, where the mean price is rounded downward to the nearest integer. To exclude dishonest deals, no deal is made between a pair of sell and buy orders from the same dealer. The system of the market maintains the list of orders for which a deal has not been made and processes a new order in the following manner.
</p>
<ul>
<li> For a new sell order, a deal is made with the buy order with the highest price in the list satisfying the conditions. If there is more than one buy order with the same price, the deal is made with the earliest of them.</li>
<li> For a new buy order, a deal is made with the sell order with the lowest price in the list satisfying the conditions. If there is more than one sell order with the same price, the deal is made with the earliest of them.</li>
</ul>
<p>
The market opens at 7:00 and closes at 22:00 everyday. When the market closes, all the remaining orders are cancelled. To keep complete record of the market, the system of the market saves all the orders it received everyday.
</p>
<p>
The manager of the market asked the system administrator to make a program which reports the activity of the market. The report must contain two kinds of information. For each commodity the report must contain informationon the lowest, the average and the highest prices of successful deals. For each dealer, the report must contain information on the amounts the dealer paid and received for commodities.
</p>
<H2>Input</H2>
<p>
The input contains several data sets. Each data set represents the record of the market on one day. The first line of each data set contains an integer <i>n</i> (<i>n</i> < 1000) which is the number of orders in the record. Each line of the record describes an order, consisting of the name of the dealer, the type of the order, the name of the commodity, and the quoted price. They are separated by a single space character.
</p>
<p>
The name of a dealer consists of capital alphabetical letters and is less than 10 characters in length. The type of an order is indicated by a string, "<span>BUY</span>" or "<span>SELL</span>". The name of a commodity is a single capital letter. The quoted price is a positive integer less than 1000.
</p>
<p>
The orders in a record are arranged according to time when they were received and the first line of the record corresponds to the oldest order.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<H2>Output</H2>
<p>
The output for each data set consists of two parts separated by a line containing two hyphen (`<span>-</span>') characters.
</p>
<p>
The first part is output for commodities. For each commodity, your program should output the name of the commodity and the lowest, the average and the highest prices of successful deals in one line. The name and the prices in a line should be separated by a space character. The average price is rounded downward to the nearest integer. The output should contain only the commodities for which deals are made and the order of the output must be alphabetic.
</p>
<p>
The second part is output for dealers. For each dealer, your program should output the name of the dealer, the amounts the dealer paid and received for commodities. The name and the numbers in a line should be separated by a space character. The output should contain all the dealers who transmitted orders. The order of dealers in the output must be lexicographic on their names. The lexicographic order is the order in which words in dictionaries are arranged.
</p>
<p>
The output for each data set should be followed by a linecontaining ten hyphen (`<span>-</span>') characters.
</p>
<H2>Sample Input</H2>
<pre>
3
PERLIS SELL A 300
WILKES BUY A 200
HAMMING SELL A 100
4
BACKUS SELL A 10
FLOYD BUY A 20
IVERSON SELL B 30
BACKUS BUY B 40
7
WILKINSON SELL A 500
MCCARTHY BUY C 300
WILKINSON SELL C 200
DIJKSTRA SELL B 100
BACHMAN BUY A 400
DIJKSTRA BUY A 600
WILKINSON SELL A 300
2
ABCD SELL X 10
ABC BUY X 15
2
A SELL M 100
A BUY M 100
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
A 150 150 150
--
HAMMING 0 150
PERLIS 0 0
WILKES 150 0
----------
A 15 15 15
B 35 35 35
--
BACKUS 35 15
FLOYD 15 0
IVERSON 0 35
----------
A 350 450 550
C 250 250 250
--
BACHMAN 350 0
DIJKSTRA 550 0
MCCARTHY 250 0
WILKINSON 0 1150
----------
X 12 12 12
--
ABC 12 0
ABCD 0 12
----------
--
A 0 0
----------
</pre>
|
p02839 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns. Let <var>(i,j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p>
<p>The square <var>(i, j)</var> has two numbers <var>A_{ij}</var> and <var>B_{ij}</var> written on it.</p>
<p>First, for each square, Takahashi paints one of the written numbers red and the other blue.</p>
<p>Then, he travels from the square <var>(1, 1)</var> to the square <var>(H, W)</var>. In one move, he can move from a square <var>(i, j)</var> to the square <var>(i+1, j)</var> or the square <var>(i, j+1)</var>. He must not leave the grid.</p>
<p>Let the <em>unbalancedness</em> be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares <var>(1, 1)</var> and <var>(H, W)</var>.</p>
<p>Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.</p>
<p>Find the minimum unbalancedness possible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq H \leq 80</var></li>
<li><var>2 \leq W \leq 80</var></li>
<li><var>0 \leq A_{ij} \leq 80</var></li>
<li><var>0 \leq B_{ij} \leq 80</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>H</var> <var>W</var>
<var>A_{11}</var> <var>A_{12}</var> <var>\ldots</var> <var>A_{1W}</var>
<var>:</var>
<var>A_{H1}</var> <var>A_{H2}</var> <var>\ldots</var> <var>A_{HW}</var>
<var>B_{11}</var> <var>B_{12}</var> <var>\ldots</var> <var>B_{1W}</var>
<var>:</var>
<var>B_{H1}</var> <var>B_{H2}</var> <var>\ldots</var> <var>B_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum unbalancedness possible.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
1 2
3 4
3 4
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>By painting the grid and traveling on it as shown in the figure below, the sum of red numbers and the sum of blue numbers are <var>3+3+1=7</var> and <var>1+2+4=7</var>, respectively, for the unbalancedness of <var>0</var>.</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/a7eefcd144e470dad1d3f833a6806f2c.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3
1 10 80
80 10 1
1 2 3
4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre></section>
</div>
</span> |
p02090 |
<h2>C: Shuttle Run</h2>
<h3>Story</h3>
<p>
University H has a unique physical fitness test program, aiming to grow the mindset of students.
Among the items in the program, shuttle run is well-known as especially eccentric one. Surprisingly, there are yokans (sweet beans jellies) on a route of the shuttle run. Greedy Homura-chan would like to challenge to eat all the yokans. And lazy Homura-chan wants to make the distance she would run as short as possible. For her, you decided to write a program to compute the minimum distance she would run required to eat all the yokans.
</p>
<h3>Problem Statement</h3>
<p>At the beginning of a shuttle run, Homura-chan is at <var>0 </var> in a positive direction on a number line. During the shuttle run, Homura-chan repeats the following moves:</p>
<ul>
<li> Move in a positive direction until reaching <var>M</var>.</li>
<li> When reaching <var>M</var>, change the direction to negative.</li>
<li> Move in a negative direction until reaching <var>0 </var>.</li>
<li> When reaching <var>0 </var>, change the direction to positive.</li>
</ul>
<p>During the moves, Homura-chan also eats yokans on the number line. There are <var>N</var> yokans on the number line. Initially, the <var>i</var>-th yokan, whose length is <var>R_i - L_i</var>, is at an interval <var>[L_i, R_i]</var> on the number line. When Homura-chan reaches <var>L_i</var> in a positive direction (or <var>R_i</var> in a negative direction), she can start eating the <var>i</var>-th yokan from <var>L_i</var> to <var>R_i</var> (or from <var>R_i</var> to <var>L_i</var>), and then the <var>i</var>-th yokan disappears. Unfortunately, Homura-chan has only one mouth. So she cannot eat two yokans at the same moment, including even when she starts eating and finishes eating (See the example below). Also, note that she cannot stop eating in the middle of yokan and has to continue eating until she reaches the other end of the yokan she starts eating; it's her belief.</p>
<p>Calculate the minimum distance Homura-chan runs to finish eating all the yokans. The shuttle run never ends until Homura-chan eats all the yokans.</p>
<h3>Input</h3>
<pre>
<var>N</var> <var>M</var>
<var>L_1</var> <var>R_1</var>
<var>:</var>
<var>L_N</var> <var>R_N</var>
</pre>
<p>The first line contains two integers <var>N</var> and <var>M</var>. The following <var>N</var> lines represent the information of yokan, where the <var>i</var>-th of them contains two integers <var>L_i</var> and <var>R_i</var> corresponding to the interval <var>[L_i, R_i]</var> the <var>i</var>-th yokan is.</p>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>3 \leq M \leq 10^9</var></li>
<li><var>0 < L_i < R_i < M</var></li>
<li> Inputs consist only of integers.</li>
</ul>
<h3>Output</h3>
<p>Output the minimum distance Homura-chan runs to eat all the given yokan in a line.</p>
<h3>Sample Input 1</h3>
<pre>
1 3
1 2
</pre>
<h3>Output for Sample Input 1</h3>
<pre>2</pre>
<h3>Sample Input 2</h3>
<pre>
2 5
1 2
2 4
</pre>
<h3>Output for Sample Input 2</h3>
<pre>8</pre>
<p>Note that when Homura-chan is at the coordinate <var>2</var>, she cannot eat the first and second yokan at the same time.</p>
<object data="https://judgeapi.u-aizu.ac.jp/resources/images/JAGSummerCamp19Day3_C_shuttle_run.png" type="image/png" width="400"></object>
|
p00557 |
<h1>尾根 (Ridge)</h1>
<h2>問題</h2>
<p>
JOI カルデラは景観の良さが多くの登山家に愛される美しい地形である.
特に,尾根と呼ばれる場所からの景観は絶景である.
</p>
<p>
JOI カルデラの土地は南北 H キロメートル,東西 W キロメートルの長方形である.
南北,東西に 1 キロメートルごとに JOI カルデラの土地を分け,これら H×W 個の領域を区域と呼ぶ.
すべての区域において,その中では標高は等しい.また,異なる区域の標高は異なる.
</p>
<p>
ある区域に雨が降ると,雨水はその区域に東西南北に隣り合う最大で 4 つの区域のうち,
標高がその区域より低いような区域のすべてに流れる.そのような区域がない場合,雨水はその区域に溜まる.
他の区域から流れてきた雨水についても同様である.
JOI カルデラの外側は,外輪山の急峻な崖に囲まれているため,雨水が JOI カルデラの外に流れ出すことはない.
</p>
<p>
ある区域について,その区域のみに雨が降った場合,最終的に複数の区域に雨水が溜まるとき,その区域を尾根と呼ぶ.
絶景をこよなく愛する登山家たちのために,尾根の区域がいくつあるかを求めるプログラムを作成せよ.
</p>
<h2>入力</h2>
<p>
入力は 1 + H 行からなる.
</p>
<p>
1 行目には 2 個の整数 H, W (1 ≦ H ≦ 1000, 1 ≦ W ≦ 1000) が空白を区切りとして書かれており,JOI カルデラが南北に H キロメートル,東西に W キロメートルにわたることを表す.
</p>
<p>
続く H 行にはそれぞれ W 個の整数が空白を区切りとして書かれており,標高の情報を表す.
H 行のうちの i 行目の j 番目 (1 ≦ i ≦ H, 1 ≦ j ≦ W) の整数 M<sub>i,j</sub> (1 ≦ M<sub>i,j</sub> ≦ H×W) は,JOI カルデラの北から i 行目,西から j 列目の区域の標高を表す.
(i,j) ≠ (k,l) なら,M<sub>i,j</sub> ≠ M<sub>k,l</sub> を満たす.
</p>
<h2>出力</h2>
<p>
尾根の区域の個数を 1 行で出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
3 3
2 9 4
7 5 3
6 1 8
</pre>
<h3>出力例 1</h3>
<pre>
4
</pre>
<br/>
<h3>入力例 2</h3>
<pre>
3 5
5 3 8 2 14
9 10 4 1 13
12 7 11 6 15
</pre>
<h3>出力例 2</h3>
<pre>
4
</pre>
<br/>
<p>
入力例 1 において,標高が 5, 7, 8, 9 の 4 個の区域が尾根である.例えば,標高 9 の区域に雨が降った場合,最終的に雨水は標高 1, 2, 3 の 3 個の区域に溜まる.したがって,標高 9 の区域は尾根である.また,標高 6 の区域に雨が降った場合,最終的に雨水は標高 1 の区域にしか溜まらない.したがって,標高 6 の区域は尾根ではない.
</p>
<p>
入力例 2 において,標高が 8, 10, 11, 12 の 4 個の区域が尾根である.
</p>
<br/>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2016/2017-yo/index.html">情報オリンピック日本委員会作 『第 16 回日本情報オリンピック JOI 2016/2017 予選競技課題』</a>
</p>
</div> |
p00107 |
<H1>Carry a Cheese</H1>
<p>
Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size <i>A</i> × <i>B</i> × <i>C</i>. It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Each entrance is a rounded hole having its own radius <i>R</i>. Could you help Jerry to find suitable holes to be survive?
</p>
<p>
Your task is to create a program which estimates whether Jerry can trail the cheese via each hole.
The program should print "<span>OK</span>" if Jerry can trail the cheese via the corresponding hole (without touching it). Otherwise the program should print "<span>NA</span>".
</p>
<p>
You may assume that the number of holes is less than 10000.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The end of input is indicated by a line containing three zeros. Each dataset is formatted as follows:
</p>
<pre>
<i>A B C</i>
<i>n</i>
<i>R</i><sub>1</sub>
<i>R</i><sub>2</sub>
.
.
<i>R</i><sub><i>n</i></sub>
</pre>
<p>
<i>n</i> indicates the number of holes (entrances) and <i>R<sub>i</sub></i> indicates the radius of <i>i</i>-th hole.
</p>
<H2>Output</H2>
<p>
For each datasets, the output should have <i>n</i> lines. Each line points the result of estimation of the corresponding hole.
</p>
<H2>Sample Input</H2>
<pre>
10 6 8
5
4
8
6
2
5
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
NA
OK
OK
NA
NA
</pre>
|
p03402 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two integers <var>A</var> and <var>B</var>.</p>
<p>Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:</p>
<ul>
<li>Let the size of the grid be <var>h \times w</var> (<var>h</var> vertical, <var>w</var> horizontal). Both <var>h</var> and <var>w</var> are at most <var>100</var>.</li>
<li>The set of the squares painted white is divided into exactly <var>A</var> connected components.</li>
<li>The set of the squares painted black is divided into exactly <var>B</var> connected components.</li>
</ul>
<p>It can be proved that there always exist one or more solutions under the conditions specified in Constraints section.
If there are multiple solutions, any of them may be printed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>Two squares painted white, <var>c_1</var> and <var>c_2</var>, are called connected when the square <var>c_2</var> can be reached from the square <var>c_1</var> passing only white squares by repeatedly moving up, down, left or right to an adjacent square.</p>
<p>A set of squares painted white, <var>S</var>, forms a connected component when the following conditions are met:</p>
<ul>
<li>Any two squares in <var>S</var> are connected.</li>
<li>No pair of a square painted white that is not included in <var>S</var> and a square included in <var>S</var> is connected.</li>
</ul>
<p>A connected component of squares painted black is defined similarly.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A \leq 500</var></li>
<li><var>1 \leq B \leq 500</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Output should be in the following format:</p>
<ul>
<li>In the first line, print integers <var>h</var> and <var>w</var> representing the size of the grid you constructed, with a space in between.</li>
<li>Then, print <var>h</var> more lines. The <var>i</var>-th (<var>1 \leq i \leq h</var>) of these lines should contain a string <var>s_i</var> as follows:<ul>
<li>If the square at the <var>i</var>-th row and <var>j</var>-th column (<var>1 \leq j \leq w</var>) in the grid is painted white, the <var>j</var>-th character in <var>s_i</var> should be <code>.</code>.</li>
<li>If the square at the <var>i</var>-th row and <var>j</var>-th column (<var>1 \leq j \leq w</var>) in the grid is painted black, the <var>j</var>-th character in <var>s_i</var> should be <code>#</code>.</li>
</ul>
</li>
</ul>
</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>3 3
##.
..#
#.#
</pre>
<p>This output corresponds to the grid below:</p>
<div style="text-align: center;">
<img alt="2701558bf42f7c088abad927b419472a.png" src="https://img.atcoder.jp/arc093/2701558bf42f7c088abad927b419472a.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3 5
#.#.#
.#.#.
#.#.#
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4 2
..
#.
##
##
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>8 18
..................
..................
....##.......####.
....#.#.....#.....
...#...#....#.....
..#.###.#...#.....
.#.......#..#.....
#.........#..####.
</pre></section>
</div>
</span> |
p01595 |
<h2>Problem E: Laser Puzzle</h2>
<p>An explorer John is now at a crisis! He is entrapped in a <var>W</var>
times <var>H</var> rectangular room with a embrasure of laser beam. The
embrasure is shooting a deadly dangerous laser beam so that he cannot cross or
touch the laser beam. On the wall of this room, there are statues and a locked
door. The door lock is opening if the beams are hitting every statue.</p>
<p>In this room, there are pillars, mirrors and crystals. A mirror reflects
a laser beam. The angle of a mirror should be vertical, horizontal or diagonal.
A crystal split a laser beam into two laser beams with θ±(π/4)
where θ is the angle of the incident laser beam. He can push one mirror or
crystal at a time. He can push mirrors/crystals multiple times. But he can push
up to two of mirrors/crystals because the door will be locked forever when he
pushes the third mirrors/crystals.</p>
<p>To simplify the situation, the room consists of <var>W</var> times <var>H</var>
unit square as shown in figure 1.</p>
<div align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_laserpuzzle"><br>
Figure 1</div>
<p>He can move from a square to the neighboring square vertically or
horizontally. Please note that he cannot move diagonal direction. Pillars,
mirrors and crystals exist on the center of a square. As shown in the figure 2,
you can assume that a mirror/crystal moves to the center of the next square at
the next moment when he push it. That means, you don't need to consider a state
about pushing a mirror/crystal.</p>
<div align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_laserpuzzle"><br>
Figure 2</div>
<p>You can assume the following conditions:</p>
<ul>
<li>the direction of laser beams are horizontal, vertical or diagonal,</li>
<li>the embrasure is shooting a laser beam to the center of the
neighboring square,</li>
<li>the embrasure is on the wall,</li>
<li>he cannot enter to a square with pillar,</li>
<li>a mirror reflects a laser beam at the center of the square,</li>
<li>a mirror reflects a laser beam on the both side,</li>
<li>a mirror blocks a laser beam if the mirror is parallel to
the laser beam,</li>
<li>a crystal split a laser beam at the center of the square,</li>
<li>diagonal laser does not hit a statue,</li>
<li>and he cannot leave the room if the door is hit by a vertical, horizontal or
diagonal laser.</li>
</ul>
<p>In order to leave this deadly room, he should push and move mirrors and
crystals to the right position and leave the room from the door. Your job is to
write a program to check whether it is possible to leave the room.</p>
<p>Figure 3 is an initial situation of the first sample input.</p>
<div align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_laserpuzzle"><br>
Figure 3</div>
<p>Figure 4 is one of the solution for the first sample input.</p>
<div align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_laserpuzzle"><br>
Figure 4</div>
<h2>Input</h2>
<p>The first line of the input contains two positive integers <var>W</var>
and <var>H</var> (2 < <var>W</var>, <var>H</var> <= 8). The map of the room is
given in the following <var>H</var> lines. The map consists of the following
characters:</p>
<ul>
<li>'#': wall of the room,</li>
<li>'*': a pillar,</li>
<li>'S': a statue on the wall,</li>
<li>'/': a diagonal mirror with angle π/4 from the bottom side of the
room,</li>
<li>'\': a diagonal mirror with angle 3π/4 from the bottom side of the
room,</li>
<li>'-': a horizontal mirror,</li>
<li>'|': a vertical mirror,</li>
<li>'O': a crystal,</li>
<li>'@': the initial position of John,</li>
<li>'.': an empty floor,</li>
<li>'L': the embrasure,</li>
<li>'D': the door</li>
</ul>
<p>The judges also guarantee that this problem can be solved without
extraordinary optimizations.</p>
<h2>Output</h2>
<p>Output "Yes" if it is possible for him to leave the room. Otherwise,
output "No".</p>
<h2>Sample Input 1</h2>
<pre>
7 8
##S####
#.....#
S.O...#
#.*|..#
L..*..#
#.O*..D
#.@...#
#######
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>
Yes
</pre>
<h2>Sample Input 2</h2>
<pre>
8 3
###L####
S.../@.#
######D#
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>
Yes
</pre>
<h2>Sample Input 3</h2>
<pre>
8 3
##L#####
S..\.@.#
######D#
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>
No
</pre> |
p03052 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a simple connected undirected graph <var>G</var> consisting of <var>N</var> vertices and <var>M</var> edges.
The vertices are numbered <var>1</var> to <var>N</var>, and the edges are numbered <var>1</var> to <var>M</var>.</p>
<p>Edge <var>i</var> connects Vertex <var>a_i</var> and <var>b_i</var> bidirectionally.
It is guaranteed that the subgraph consisting of Vertex <var>1,2,\ldots,N</var> and Edge <var>1,2,\ldots,N-1</var> is a spanning tree of <var>G</var>.</p>
<p>An allocation of weights to the edges is called a <em>good allocation</em> when the tree consisting of Vertex <var>1,2,\ldots,N</var> and Edge <var>1,2,\ldots,N-1</var> is a minimum spanning tree of <var>G</var>.</p>
<p>There are <var>M!</var> ways to allocate the edges distinct integer weights between <var>1</var> and <var>M</var>.
For each good allocation among those, find the total weight of the edges in the minimum spanning tree, and print the sum of those total weights 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>2 \leq N \leq 20</var></li>
<li><var>N-1 \leq M \leq N(N-1)/2</var></li>
<li><var>1 \leq a_i, b_i \leq N</var></li>
<li><var>G</var> does not have self-loops or multiple edges.</li>
<li>The subgraph consisting of Vertex <var>1,2,\ldots,N</var> and Edge <var>1,2,\ldots,N-1</var> is a spanning tree of <var>G</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>\vdots</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2
2 3
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>An allocation is good only if Edge <var>3</var> has the weight <var>3</var>. For these good allocations, the total weight of the edges in the minimum spanning tree is <var>3</var>, and there are two good allocations, so the answer is <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
1 2
3 2
3 4
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>50
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15 28
10 7
5 9
2 13
2 14
6 1
5 12
2 10
3 9
10 15
11 12
12 6
2 12
12 8
4 10
15 3
13 14
1 15
15 12
4 14
1 7
5 11
7 13
9 10
2 7
1 9
5 6
12 14
5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>657573092
</pre>
<p>Print the sum of those total weights modulo <var>10^{9}+7</var>.</p></section>
</div>
</span> |
p02213 | <span class="lang">
<span class="lang-ja">
<h1>B: サイコロを転がさないで</h1>
<div class="part">
<section>
<h3>問題文</h3><p>$H$ 行 $W$ 列からなるグリッドがあります。以降、グリッド上の $i$ 行目 $j$ 列目のマスを $(i, j)$ のマスと書きます。</p>
<p>グリッドの各マスには、$1$ 以上 $6$ 以下の数字か、あるいは <code>#</code> の文字が $1$ つずつ書かれています。<span style="font-weight: bold;">ただし、$i$ と $j$ がともに偶数であるような $(i, j)$ のマスには必ず <code>#</code> が書かれています。</span></p>
<p>あなたは以下の図で表されるようなサイコロを $1$ つ持っています。</p>
<p><img alt="dice_picture" src="https://judgeapi.u-aizu.ac.jp/resources/images/kupc_2020_spring_rotating_dice.png" /></p>
<p>最初、あなたはこのサイコロを底面が $6$, 前面が $2$, 右面が $3$ となるように $(1, 1)$ のマスに置きます。
ここで、前面は $(i, j)$ の $i$ が増える方向の面を、右面は $j$ が増える方向の面を指します。</p>
<p>その後、サイコロが置かれているマスに辺で隣接する $4$ マスのいずれかにサイコロを転がす操作を好きな回数繰り返すことができます。
サイコロを転がす際、サイコロは転がす方向に90度回転します。</p>
<p>ただし、サイコロを転がす際には以下の条件を満たしている必要があります。</p>
<ul>
<li>グリッドの外にサイコロを転がしてはならない</li>
<li><code>#</code> が書かれているマスに転がしてはならない</li>
<li>転がした後の状態を考えたときに、サイコロの底面に書かれた数字とそのマスに書かれた数字が一致する</li>
</ul>
<p>$(1, 1)$ のマスには必ず $6$ が書かれていることが保証されます。</p>
<p>サイコロを転がす操作を繰り返すことで、サイコロを $(1, 1)$ のマスから $(H, W)$ のマスに移動させることができるか判定してください。</p>
</section>
</div>
<div class="part">
<section>
<h3>制約</h3><ul>
<li>$1 \leq H, W \leq 100$</li>
<li>グリッドの各マスには $1$ 以上 $6$ 以下の数字、または <code>#</code> が書かれている</li>
<li><span style="font-weight: bold;">$i, j$ がともに偶数となるような $(i, j)$ のマスには必ず <code>#</code> が書かれている</span></li>
<li>$(1, 1)$ には $6$ が書かれていることが保証される</li>
</ul>
</section>
</div>
<hr />
<div class="io-style">
<div class="part">
<section>
<h3>入力</h3><p>入力は以下の形式で標準入力から与えられる。</p>
<pre>$H$ $W$
$s_{11}s_{12} \ldots s_{1W}$
$s_{21}s_{22} \ldots s_{2W}$
$\vdots$
$s_{H1}s_{H2} \ldots s_{HW}$
</pre>
<p>ここで、$s_{ij}$ は $(i, j)$ のマスにかかれている数字または文字を表す。
すなわち、$s_{ij}$ は $1$ 以上 $6$ 以下の数字であるか、あるいは <code>#</code> である。</p>
</section>
</div>
<div class="part">
<section>
<h3>出力</h3><p>$(1, 1)$ のマスから $(H, W)$ のマスへサイコロを転がして移動させることができるならば <code>YES</code> を、そうでないならば <code>NO</code> を 1 行で出力せよ。</p>
</section>
</div>
</div>
<hr />
<div class="part">
<section>
<h3>入力例 1</h3><pre>3 3
631
4#2
516
</pre>
</section>
</div>
<div class="part">
<section>
<h3>出力例 1</h3><pre>YES
</pre>
<p>$(1, 1), (1, 2), (1, 3), (2, 3), (3, 3)$ の順に転がすことで、到達可能です。</p>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>入力例 2</h3><pre>3 3
6#1
##2
516
</pre>
</section>
</div>
<div class="part">
<section>
<h3>出力例 2</h3><pre>NO
</pre>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>入力例 3</h3><pre>5 5
61244
2#5#3
14641
5#5#5
63126
</pre>
</section>
</div>
<div class="part">
<section>
<h3>出力例 3</h3><pre>YES
</pre></section>
</div>
</span>
</span>
|
p00384 | <h1>Dungeon 2</h1>
<p>
Bob is playing a game called "Dungeon 2" which is the sequel to the popular "Dungeon" released last year. The game is played on a map consisting of $N$ rooms and $N-1$ roads connecting them. The roads allow bidirectional traffic and the player can start his tour from any room and reach any other room by way of multiple of roads. A point is printed in each of the rooms.
</p>
<p>
Bob tries to accumulate the highest score by visiting the rooms by cleverly routing his character "Tora-Tora." He can add the point printed in a room to his score only when he reaches the room for the first time. He can also add the points on the starting and ending rooms of Tora-Tora’s journey. The score is reduced by one each time Tora-Tore passes a road. Tora-Tora can start from any room and end his journey in any room.
</p>
<p>
Given the map information, make a program to work out the maximum possible score Bob can gain.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$p_1$
$p_2$
$...$
$p_N$
$s_1$ $t_1$
$s_2$ $t_2$
$...$
$s_{N-1}$ $t_{N-1}$
</pre>
<p>
The first line provides the number of rooms $N$ ($1 \leq N \leq 100,000$). Each of the subsequent $N$ lines provides the point of the $i$-th room $p_i$ ($-100 \leq p_i \leq 100$) in integers. Each of the subsequent lines following these provides the information on the road directly connecting two rooms, where $s_i$ and $t_i$ ($1 \leq s_i < t_i \leq N$) represent the numbers of the two rooms connected by it. Not a single pair of rooms are connected by more than one road.
</p>
<h2>Output</h2>
<p>
Output the maximum possible score Bob can gain.
</p>
<h2>Sample Input 1</h2>
<pre>
7
6
1
-1
4
3
3
1
1 2
2 3
3 4
3 5
5 6
5 7
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<p>
For example, the score is maximized by routing the rooms in the following sequence: $6 \rightarrow 5 \rightarrow 3 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 1$.
</p>
<h2>Sample Input 2</h2>
<pre>
4
5
0
1
1
1 2
2 3
2 4
</pre>
<h2>Sample Output 2</h2>
<pre>
5
</pre>
<p>
The score is maximized if Tora-Tora stats his journey from room 1 and ends in the same room.
</p>
|
p03951 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is interested in strings that satisfy the following conditions:</p>
<ul>
<li>The length of the string is at least <var>N</var>.</li>
<li>The first <var>N</var> characters equal to the string <var>s</var>.</li>
<li>The last <var>N</var> characters equal to the string <var>t</var>.</li>
</ul>
<p>Find the length of the shortest string that satisfies the conditions.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N≤100</var></li>
<li>The lengths of <var>s</var> and <var>t</var> are both <var>N</var>.</li>
<li><var>s</var> and <var>t</var> consist of lowercase English letters.</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>
<var>t</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the length of the shortest string that satisfies the conditions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
abc
cde
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>The shortest string is <code>abcde</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
a
z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>The shortest string is <code>az</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
expr
expr
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>The shortest string is <code>expr</code>.</p></section>
</div>
</span> |
p02643 | <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> infants registered in AtCoder, numbered <var>1</var> to <var>N</var>, and <var>2\times 10^5</var> kindergartens, numbered <var>1</var> to <var>2\times 10^5</var>.
Infant <var>i</var> has a rating of <var>A_i</var> and initially belongs to Kindergarten <var>B_i</var>.</p>
<p>From now on, <var>Q</var> transfers will happen.
After the <var>j</var>-th transfer, Infant <var>C_j</var> will belong to Kindergarten <var>D_j</var>.</p>
<p>Here, we define the <em>evenness</em> as follows. For each kindergarten with one or more infants registered in AtCoder, let us find the highest rating of an infant in the kindergarten. The evenness is then defined as the lowest among those ratings.</p>
<p>For each of the <var>Q</var> transfers, find the evenness just after the transfer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,Q \leq 2 \times 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>1 \leq C_j \leq N</var></li>
<li><var>1 \leq B_i,D_j \leq 2 \times 10^5</var></li>
<li>All values in input are integers.</li>
<li>In the <var>j</var>-th transfer, Infant <var>C_j</var> changes the kindergarten it belongs to.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Q</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>
<var>C_1</var> <var>D_1</var>
<var>C_2</var> <var>D_2</var>
<var>:</var>
<var>C_Q</var> <var>D_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines.
The <var>j</var>-th line should contain the evenness just after the <var>j</var>-th transfer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 3
8 1
6 2
9 3
1 1
2 2
1 3
4 3
2 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
2
6
</pre>
<p>Initially, Infant <var>1, 4</var> belongs to Kindergarten <var>1</var>, Infant <var>2, 5</var> belongs to Kindergarten <var>2</var>, and Infant <var>3, 6</var> belongs to Kindergarten <var>3</var>.</p>
<p>After the <var>1</var>-st transfer that makes Infant <var>4</var> belong to Kindergarten <var>3</var>, Infant <var>1</var> belongs to Kindergarten <var>1</var>, Infant <var>2, 5</var> belong to Kindergarten <var>2</var>, and Infant <var>3, 4, 6</var> belong to Kindergarten <var>3</var>. The highest ratings of an infant in Kindergarten <var>1, 2, 3</var> are <var>8, 6, 9</var>, respectively. The lowest among them is <var>6</var>, so the <var>1</var>-st line in the output should contain <var>6</var>.</p>
<p>After the <var>2</var>-nd transfer that makes Infant <var>2</var> belong to Kindergarten <var>1</var>, Infant <var>1, 2</var> belong to Kindergarten <var>1</var>, Infant <var>5</var> belongs to Kindergarten <var>2</var>, and Infant <var>3, 4, 6</var> belong to Kindergarten <var>3</var>. The highest ratings of an infant in Kindergarten <var>1, 2, 3</var> are <var>8, 2, 9</var>, respectively. The lowest among them is <var>2</var>, so the <var>2</var>-nd line in the output should contain <var>2</var>.</p>
<p>After the <var>3</var>-rd transfer that makes Infant <var>1</var> belong to Kindergarten <var>2</var>, Infant <var>2</var> belongs to Kindergarten <var>1</var>, Infant <var>1, 5</var> belong to Kindergarten <var>2</var>, and Infant <var>3, 4, 6</var> belong to Kindergarten <var>3</var>. The highest ratings of an infant in Kindergarten <var>1, 2, 3</var> are <var>6, 8, 9</var>, respectively. The lowest among them is <var>6</var>, so the <var>3</var>-rd line in the output should contain <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
4208 1234
3056 5678
1 2020
2 2020
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3056
4208
</pre></section>
</div>
</span> |
p02356 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>The Number of Windows</H1>
<p>
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfies the condition: $1 \leq l \leq r \leq N$ and $a_l + a_{l+1} + ... + a_{r-1} + a_r \leq x_i$.
</p>
<h2>Constraints</h2>
<ul>
<li> $1 \leq N \leq 10^5$ </li>
<li> $1 \leq Q \leq 500$</li>
<li> $1 \leq a_i \leq 10^9$</li>
<li> $1 \leq x_i \leq 10^{14}$</li>
</ul>
<h2>Input</h2>
<p>The input is given in the following format.</p>
<p>
$N$ $Q$<br>
$a_1$ $a_2$ ... $a_N$<br>
$x_1$ $x_2$ ... $x_Q$<br>
</p>
<h2>Output</h2>
<p>
For each query, print the number of combinations in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
6 5
1 2 3 4 5 6
6 9 12 21 15
</pre>
<h2>Sample Output 1</h2>
<pre>
9
12
15
21
18
</pre>
|
p01983 | <h3>知識の証明</h3>
<!-- begin ja only -->
<p>あなたが住んでいる集合住宅の入口のドアには,パスワード式のロックがかけられている.このパスワードはちょうど 4 桁の 0 から 9 の範囲の数字で構成されており,あなたはいつも,集合住宅の管理人から伝えられたパスワード <i>P</i> を使って,このドアのロックを解除している.</p>
<p>ある日,あなたは集合住宅の住民全員が,自分と同じパスワード <i>P</i> を使っているのかどうか気になり,同じ集合住宅に住む友人に尋ねることにした.あなたとあなたの友人は,自分のパスワードを互いに伝えあうことで,同じパスワードを使っているのかどうか確かめ合うことができる.しかしながら,パスワードがそれぞれの住民に個別に割り当てられている可能性を考えると,この方法は好ましくない.自分のパスワードを知っているのは自分だけであるべきで,他人に伝えるべきではないからである.</p>
<p>この事態を防ぐために,あなたとあなたの友人は,自分のパスワードをハッシュ関数に入力し,得られたハッシュ値を互いに伝えあうことにした.ここで使用するハッシュ関数の計算式 <i>S</i> は小文字のアルファベット 'a', 'b', 'c', 'd' と記号 '[', ']', '+', '*', '^' からなり,以下のBNFで定義される <Hash> によって表される.</p>
<blockquote><Hash> ::= <Letter> | '['<Op><Hash><Hash>']'
<Op> ::= '+' | '*' | '^'
<Letter> ::= 'a' | 'b' | 'c' | 'd'</blockquote>
<p>ここで 'a', 'b', 'c', 'd' はそれぞれ 4 桁のパスワードの先頭から 1 桁目,2 桁目,3 桁目,4 桁目の数字を表す.'+', '*', '^' は演算子であり,以下のような意味を表す.</p>
<ul>
<li>'+' : 続く 2 つの <Hash> を二進数で表したときの論理和を取る</li>
<li>'*' : 続く 2 つの <Hash> を二進数で表したときの論理積を取る</li>
<li>'^' : 続く 2 つの <Hash> を二進数で表したときの排他的論理和を取る</li>
</ul>
<p>ここで,論理和,論理積,排他的論理和の真理値表はそれぞれ以下のようになる.</p>
<table class="c_table" style="border-collapse: collapse; margin: 8px; text-align:center" cellpadding="8">
<thead class="c_thead">
<tr>
<th class="c_th" style="border: 1px solid black">A</th>
<th class="c_th" style="border: 1px solid black">B</th>
<th class="c_th" style="border: 1px solid black">[+AB]</th>
</tr>
</thead>
<tbody>
<tr>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">0</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">1</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">1</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">1</td>
</tr>
</tbody>
</table>
<table class="c_table" style="border-collapse: collapse; margin: 8px; text-align:center" cellpadding="8">
<thead class="c_thead">
<tr>
<th class="c_th" style="border: 1px solid black">A</th>
<th class="c_th" style="border: 1px solid black">B</th>
<th class="c_th" style="border: 1px solid black">[*AB]</th>
</tr>
</thead>
<tbody>
<tr>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">0</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">0</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">0</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">1</td>
</tr>
</tbody>
</table>
<table class="c_table" style="border-collapse: collapse; margin: 8px; text-align:center" cellpadding="8">
<thead class="c_thead">
<tr>
<th class="c_th" style="border: 1px solid black">A</th>
<th class="c_th" style="border: 1px solid black">B</th>
<th class="c_th" style="border: 1px solid black">[^AB]</th>
</tr>
</thead>
<tbody>
<tr>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">0</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">1</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">0</td>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">1</td>
</tr>
<tr>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">1</td>
<td class="c_td" style="border: 1px solid black">0</td>
</tr>
</tbody>
</table>
<p>例として,ハッシュ関数 [+c[+a[^bd]]] にパスワード 0404 を入力すると,ハッシュ値として 0 が得られる.同じハッシュ値が得られるパスワードとして 0000, 0101, 0202, 0303, 0505, 0606, 0707, 0808, 0909 がある.</p>
<p>あなたのパスワード <i>P</i> をハッシュ関数 <i>S</i> に入力した結果を出力せよ.また,ハッシュ値からパスワードを一意に特定可能なハッシュ関数の使用を防ぐため,あなたのパスワードと同じハッシュ値になるパスワードの数も出力せよ.</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>入力は最大で 50 個のデータセットから構成される.各データセットは次の形式で表される.</p>
<blockquote><i>S</i>
<i>P</i></blockquote>
<p>各データセットの1行目は,ハッシュ関数の計算式 <i>S</i> である.各データセットの2行目は,4 桁の 0 から 9 の範囲の数字で構成されるパスワード <i>P</i> である.ハッシュ関数 <i>S</i> の長さは 80 以下であると仮定してよい.</p>
<p>入力の終了は '.' の1文字だけを含む行で表される.</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>各データセットについて,<i>P</i> を <i>S</i> に入力して得られるハッシュ値と,<i>P</i> と同じハッシュ値が得られるパスワードの数を空白区切りで出力せよ.</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>[+c[+a[^bd]]]
0404
[*b[*[*cd]a]]
7777
[^[^ab][^cd]]
1295
a
9876
[^dd]
9090
.
</pre><h3>Output for the Sample Input</h3><pre>0 10
7 1
15 544
9 1000
0 10000
</pre>
|
p00691 |
<H1>
Fermat's Last Theorem
</H1>
<p>
In the 17th century, Fermat wrote that he proved for any integer $n \geq 3$,
there exist no positive integers $x$, $y$, $z$ such that
$x^n + y^n = z^n$.
However he never disclosed the proof. Later, this claim was named
Fermat's Last Theorem or Fermat's Conjecture.
</p>
<p>
If Fermat's Last Theorem holds in case of $n$, then it also holds
in case of any multiple of $n$.
Thus it suffices to prove cases where $n$ is a prime number
and the special case $n$ = 4.
</p>
<p>
A proof for the case $n$ = 4 was found in Fermat's own memorandum.
The case $n$ = 3 was proved by Euler in the 18th century.
After that, many mathematicians attacked Fermat's Last Theorem.
Some of them proved some part of the theorem, which was a
partial success.
Many others obtained nothing.
It was a long history.
Finally, Wiles proved Fermat's Last Theorem in 1994.
</p>
<p>
Fermat's Last Theorem implies that for any integers $n \geq 3$
and $z > 1$, it always holds that
<br/>
$z^n > $ max { $x^n + y^n | x > 0, y > 0, x^n + y^n \leq z^n$ }.
<br/>
</p>
<p>
Your mission is to write a program that verifies this in the case
$n$ = 3 for a given $z$. Your program should read in
integer numbers greater than 1, and, corresponding to each input
$z$, it should output the following:
<br/>
$z^3 - $ max { $x^3 + y^3 | x > 0, y > 0, x^3 + y^3 \leq z^3$ }.
<br/>
</p>
<H2>Input</H2>
<p>
The input is a sequence of lines each containing one positive integer
number followed by a line containing a zero. You may assume that all of
the input integers are greater than 1 and less than 1111.
</p>
<H2>Output</H2>
<p>
The output should consist of lines each containing a single
integer number. Each output integer should be
<br/>
$z^3 - $ max { $x^3 + y^3 | x > 0, y > 0, x^3 + y^3 \leq z^3$ }.
<br/>
<p>
for the corresponding input integer <I>z</I>.
No other characters should appear in any output line.
</p>
<H2>Sample Input</H2>
<pre>
6
4
2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
27
10
6
</pre>
|
p01829 |
<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>Change a Password</h2>
<p>
Password authentication is used in a lot of facilities. The office of JAG also uses password authentication. A password is required to enter their office. A password is a string of $N$ digits '0'-'9'. This password is changed on a regular basis. Taro, a staff of the security division of JAG, decided to use the following rules to generate a new password from an old one.
</p>
<ol>
<li> The new password consists of the same number $N$ of digits to the original one and each digit appears at most once in the new password. It can have a leading zero. (Note that an old password may contain same digits twice or more.)</li>
<li> The new password maximizes the difference from the old password within constraints described above. (Definition of the difference between two passwords is described below.)</li>
<li> If there are two or more candidates, the one which has the minimum value when it is read as an integer will be selected.</li>
</ol>
<p>
The difference between two passwords is defined by <i>min</i>($|a - b|, 10^N - |a - b|$), where $a$ and $b$ are the integers represented by the two passwords. For example, the difference between "11" and "42" is 31, and the difference between "987" and "012" is 25.
</p>
<p>
Taro would like to use a computer to calculate a new password correctly, but he is not good at programming. Therefore, he asked you to write a program. Your task is to write a program that generates a new password from an old password.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line of the input contains a string $S$ which denotes the old password. You can assume that the length of $S$ is no less than 1 and no greater than 10. Note that old password $S$ may contain same digits twice or more, and may have leading zeros.
</p>
<h3>Output</h3>
<p>
Print the new password in a line.
</p>
<h3>Sample Input 1</h3>
<pre>
201
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
701
</pre>
<h3>Sample Input 2</h3>
<pre>
512
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
012
</pre>
<h3>Sample Input 3</h3>
<pre>
99999
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
49876
</pre>
<h3>Sample Input 4</h3>
<pre>
765876346
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
265874931
</pre> |
p03814 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has decided to construct a string that starts with <code>A</code> and ends with <code>Z</code>, by taking out a substring of a string <var>s</var> (that is, a consecutive part of <var>s</var>).</p>
<p>Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of <var>s</var> that starts with <code>A</code> and ends with <code>Z</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ |s| ≦ 200{,}000</var></li>
<li><var>s</var> consists of uppercase English letters.</li>
<li>There exists a substring of <var>s</var> that starts with <code>A</code> and ends with <code>Z</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</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>QWERTYASDFZXCV
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>By taking out the seventh through eleventh characters, it is possible to construct <code>ASDFZ</code>, which starts with <code>A</code> and ends with <code>Z</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ZABCZ
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>HASFJGHOGAKZZFEGA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>12
</pre></section>
</div>
</span> |
p02706 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has <var>N</var> days of summer vacation.</p>
<p>His teacher gave him <var>M</var> summer assignments. It will take <var>A_i</var> days for him to do the <var>i</var>-th assignment.</p>
<p>He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.</p>
<p>What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?</p>
<p>If Takahashi cannot finish all the assignments during the vacation, print <code>-1</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^6</var></li>
<li><var>1 \leq M \leq 10^4</var></li>
<li><var>1 \leq A_i \leq 10^4</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>...</var> <var>A_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of days Takahashi can hang out during the vacation, or <code>-1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>41 2
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>30
</pre>
<p>For example, he can do the first assignment on the first <var>5</var> days, hang out on the next <var>30</var> days, and do the second assignment on the last <var>6</var> days of the vacation. In this way, he can safely spend <var>30</var> days hanging out.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 2
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>He cannot finish his assignments.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11 2
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>He can finish his assignments, but he will have no time to hang out.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>9
</pre></section>
</div>
</span> |
p03547 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In programming, hexadecimal notation is often used.</p>
<p>In hexadecimal notation, besides the ten digits <var>0, 1, ..., 9</var>, the six letters <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code>, <code>E</code> and <code>F</code> are used to represent the values <var>10, 11, 12, 13, 14</var> and <var>15</var>, respectively.</p>
<p>In this problem, you are given two letters <var>X</var> and <var>Y</var>. Each <var>X</var> and <var>Y</var> is <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code>, <code>E</code> or <code>F</code>.</p>
<p>When <var>X</var> and <var>Y</var> are seen as hexadecimal numbers, which is larger?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>Each <var>X</var> and <var>Y</var> is <code>A</code>, <code>B</code>, <code>C</code>, <code>D</code>, <code>E</code> or <code>F</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>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>X</var> is smaller, print <code><</code>; if <var>Y</var> is smaller, print <code>></code>; if they are equal, print <code>=</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>A B
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre><
</pre>
<p><var>10 < 11</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>E C
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>>
</pre>
<p><var>14 > 12</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>F F
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>=
</pre>
<p><var>15 = 15</var>.</p></section>
</div>
</span> |
p01080 |
<h1>Problem I: Traffic Tree</h1>
<h2>Problem</h2>
<p>
それぞれ1から<var>N</var>までの番号が付いた<var>N</var>個の頂点が、<var>N</var>-1本の無向辺によって繋がれたグラフが与えられる。各頂点について、その頂点からスタートしてすべての頂点を訪れるための最短のステップ数を出力せよ。
</p>
<p>
ただし、ある頂点から1本の辺をたどって別の頂点に移動することを1ステップとする。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var>
<var>u<sub>1</sub></var> <var>v<sub>1</sub></var>
.
.
.
<var>u<sub>N−1</sub></var> <var>v<sub>N−1</sub></var>
</pre>
<p>
1行目に、1つの整数<var>N</var>が与えられる。<br>
続く<var>N</var>-1行のうち<var>i</var>行目には<var>i</var>番目の辺の両端の頂点番号を表す整数<var>u<sub>i</sub></var>, <var>v<sub>i</sub></var>が空白区切りで与えられる。
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>N</var> ≤ 10<sup>5</sup></li>
<li>1 ≤ <var>u<sub>i</sub></var>,<var>v<sub>i</sub></var> ≤ <var>N</var> (1 ≤ <var>i</var> ≤ <var>N</var>-1)</li>
<li><var>u<sub>i</sub></var> ≠ <var>v<sub>i</sub></var></li>
<li>与えられるグラフは連結である</li>
</ul>
<h2>Output</h2>
<p>
頂点1から頂点<var>N</var>について<var>i</var>行目に頂点<var>i</var>からスタートしてすべての頂点を訪れるための最短のステップ数を出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
2
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1
1
</pre>
<h2>Sample Input 2</h2>
<pre>
6
1 2
1 3
3 4
3 5
5 6
</pre>
<h2>Sample Output 2</h2>
<pre>
7
6
8
7
7
6
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_I_figure1" alt="Sample Input 2の図" style="width:500px;"><br />
Sample Input2の図
</p> |
p03117 | <span class="lang-en">
<p>Score : <var>2000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>R</var> red balls and <var>B</var> blue balls.
He distributes them into <var>K</var> boxes, so that no box is empty and no two boxes are identical.
Compute the maximum possible value of <var>K</var>.</p>
<p>Formally speaking, let's number the boxes <var>1</var> through <var>K</var>.
If Box <var>i</var> contains <var>r_i</var> red balls and <var>b_i</var> blue balls, the following conditions must be satisfied:</p>
<ul>
<li>For each <var>i</var> (<var>1 \leq i \leq K</var>), <var>r_i > 0</var> or <var>b_i > 0</var>.</li>
<li>For each <var>i, j</var> (<var>1 \leq i < j \leq K</var>), <var>r_i \neq r_j</var> or <var>b_i \neq b_j</var>.</li>
<li><var>\sum r_i = R</var> and <var>\sum b_i = B</var> (no balls can be left outside the boxes).</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq R, B \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>R</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible value of <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>The following picture shows one possible way to achieve <var>K = 5</var>:</p>
<p><img alt="" src="https://img.atcoder.jp/wtf19/9ea9530037df204a84029678052ab593.png"/></p></section>
</div>
</span> |
p03639 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of length <var>N</var>, <var>a = (a_1, a_2, ..., a_N)</var>.
Each <var>a_i</var> is a positive integer.</p>
<p>Snuke's objective is to permute the element in <var>a</var> so that the following condition is satisfied:</p>
<ul>
<li>For each <var>1 ≤ i ≤ N - 1</var>, the product of <var>a_i</var> and <var>a_{i + 1}</var> is a multiple of <var>4</var>.</li>
</ul>
<p>Determine whether Snuke can achieve his objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ N ≤ 10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 ≤ a_i ≤ 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>If Snuke can achieve his objective, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 10 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>One solution is <var>(1, 100, 10)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>It is impossible to permute <var>a</var> so that the condition is satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>The condition is already satisfied initially.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>6
2 7 1 8 2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> |
p01604 |
<h2>goto busters</h2>
<h2>Problem Statement</h2>
<p>あなたは謎のプログラムのソースコードを見つけた.<br />
さっそくコンパイルして実行してみたが,いつまで待っても処理が終わらない.<br />
どうやら,プログラムが無限ループしてしまっているようである.</p>
<p>ソースコードを詳しく見てみたところ,以下のようなことがわかった.<br /></p>
<p>ソースコードは <var>N</var> 行からなり,各行はラベル文か goto 文のいずれかである.<br />
ラベル文と goto 文はそれぞれ次のようなフォーマットに従っている.<br /></p>
<pre>LABEL:</pre>
<pre>goto LABEL;</pre>
<p>ここで,LABEL はラベルを表す文字列である.</p>
<p>プログラムは先頭の行から順番に 1 行ずつ処理される.<br />
ラベル文と goto 文を処理したときの挙動は次のとおり:<br /></p>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li>ラベル文を処理しても何も起こらない</li>
<li>goto 文を処理したとき,次の処理は同じ名前のラベルを持ったラベル文から始める</li></ul>
<p>最後の行を処理し終えて次に処理する行がなくなったとき,プログラムは終了する.</p>
<p>あなたは,いくつかの goto 文を削除することでプログラムを正しく終了させたいと思っている.<br />
一方で,手を加える箇所はできるだけ少なくしたい.<br />
プログラムを終了させるためには最小でいくつの goto 文を消せばいいだろうか.</p>
<h2>Input</h2>
<pre><var>N</var>
<var>s_1</var>
<var>. . .</var>
<var>s_N</var></pre>
<p><var>s_i</var> は次の二つのうちのいずれかである.</p>
<pre>LABEL_i:
goto LABEL_i;</pre>
<h2>Constraints</h2>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1 ≦ N ≦ 100</var></li>
<li>ラベルはアルファベットの大文字または小文字のみからなる,1 文字以上 10 文字以下の文字列</li>
<li>すべての <var>s_i =</var> "goto LABEL_i;" に対して,<var>s_j =</var> "LABEL_i:" となる <var>j</var> が存在する.</li>
<li>同じ名前のラベルを持ったラベル文は二回以上現れない.</li>
<li>"goto" という名前のラベルは存在しない.</li></ul>
<h2>Output</h2>
<p>削除すべき goto 文の最小個数を 1 行に出力せよ.</p>
<h2>Sample Input 1</h2>
<pre>2
LOOP:
goto LOOP;</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1</pre>
<h2>Sample Input 2</h2>
<pre>8
goto there;
loop:
goto loop;
here:
goto goal;
there:
goto here;
goal:</pre>
<h2>Output for the Sample Input 2</h2>
<pre>0</pre>
<h2>Sample Input 3</h2>
<pre>1
GOTO:</pre>
<h2>Output for the Sample Input 3</h2>
<pre>0</pre>
|
p00916 |
<H1><font color="#000">Problem C: </font>Count the Regions</H1>
<p>
There are a number of rectangles on the <i>x-y</i> plane. The four sides of the rectangles are parallel to either the <var>x</var>-axis or the <i>y</i>-axis, and all of the rectangles reside within a range specified later. There are no other constraints on the coordinates of the rectangles.
</p>
<p>
The plane is partitioned into regions surrounded by the sides of one or more rectangles. In an example shown in Figure C.1, three rectangles overlap one another, and the plane is partitioned into eight regions.
</p>
<p>
Rectangles may overlap in more complex ways. For example, two rectangles may have overlapped sides, they may share their corner points, and/or they may be nested. Figure C.2 illustrates such cases.
</p>
<p>
Your job is to write a program that counts the number of the regions on the plane partitioned
by the rectangles.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is formatted as follows.
</p>
<pre>
<var>n</var>
<var>l<sub>1</sub></var> <var>t<sub>1</sub></var> <var>r<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>l<sub>2</sub></var> <var>t<sub>2</sub></var> <var>r<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>l<sub>n</sub></var> <var>t<sub>n</sub></var> <var>r<sub>n</sub></var> <var>b<sub>n</sub></var>
</pre>
<p>
A dataset starts with <var>n</var> (1 ≤ <var>n</var> ≤ 50), the number of rectangles on the plane. Each of the
following <var>n</var> lines describes a rectangle. The <var>i</var>-th line contains four integers, <var>l<sub>i</sub></var>, <var>t<sub>i</sub></var>, <var>r<sub>i</sub></var>, and <var>b<sub>i</sub></var>, which are the coordinates of the <var>i</var>-th rectangle; (<var>l<sub>i</sub></var>, <var>t<sub>i</sub></var>) gives the <i>x-y</i> coordinates of the top left corner, and (<var>r<sub>i</sub></var>, <var>b<sub>i</sub></var>) gives that of the bottom right corner of the rectangle (0 ≤ <var>l<sub>i</sub></var> < <var>r<sub>i</sub></var> ≤ 10<sup>6</sup>, 0 ≤ <var>b<sub>i</sub></var> < <var>t<sub>i</sub></var> ≤ 10<sup>6</sup>, for 1 ≤ <var>i</var> ≤ <var>n</var>). The four integers are separated by a space.
</p>
<p>
The input is terminated by a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing the number of regions on the plane partitioned by the sides of the rectangles.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_countTheRegions1" style="aling:center"><br/>
<span>
Figure C.1. Three rectangles partition the plane into eight regions. This corresponds to the first dataset of the sample input. The <i>x</i>- and <i>y</i>-axes are shown for illustration purposes only, and therefore they do not partition the plane.
</span>
</center>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_countTheRegions2" style="aling:center"><br/>
<span>
Figure C.2. Rectangles overlapping in more complex ways. This corresponds to the
second dataset.
</span>
</center>
<br/>
<H2>Sample Input</H2>
<pre>
3
4 28 27 11
15 20 42 5
11 24 33 14
5
4 28 27 11
12 11 34 2
7 26 14 16
14 16 19 12
17 28 27 21
2
300000 1000000 600000 0
0 600000 1000000 300000
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
8
6
6
</pre> |
p03793 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are developing a robot that processes strings.
When the robot is given a string <var>t</var> consisting of lowercase English letters, it processes the string by following the procedure below:</p>
<ol>
<li>Let <var>i</var> be the smallest index such that <var>t_i = t_{i + 1}</var>. If such an index does not exist, terminate the procedure.</li>
<li>If <var>t_i</var> is <code>z</code>, remove <var>t_i</var> and <var>t_{i + 1}</var> from <var>t</var>. Otherwise, let <var>c</var> be the next letter of <var>t_i</var> in the English alphabet, and replace <var>t_i</var> and <var>t_{i + 1}</var> together with <var>c</var>, reducing the length of <var>t</var> by <var>1</var>.</li>
<li>Go back to step 1.</li>
</ol>
<p>For example, when the robot is given the string <code>axxxxza</code>, it will be processed as follows: <code>axxxxza</code> → <code>ayxxza</code> → <code>ayyza</code> → <code>azza</code> → <code>aa</code> → <code>b</code>.</p>
<p>You are given a string <var>s</var> consisting of lowercase English letters.
Answer <var>Q</var> queries. The <var>i</var>-th query is as follows:</p>
<ul>
<li>Assume that the robot is given a substring of <var>s</var> that runs from the <var>l_i</var>-th character and up to the <var>r_i</var>-th character (inclusive). Will the string be empty after processing?</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ |s| ≤ 5 × 10^5</var></li>
<li><var>s</var> consists of lowercase English letters.</li>
<li><var>1 ≤ Q ≤ 10^5</var></li>
<li><var>1 ≤ l_i ≤ r_i ≤ |s|</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
<var>Q</var>
<var>l_1</var> <var>r_1</var>
<var>l_2</var> <var>r_2</var>
<var>:</var>
<var>l_Q</var> <var>r_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines.
The <var>i</var>-th line should contain the answer to the <var>i</var>-th query: <code>Yes</code> or <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>axxxxza
2
1 7
2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>No
Yes
</pre>
<ul>
<li>Regarding the first query, the string will be processed as follows: <code>axxxxza</code> → <code>ayxxza</code> → <code>ayyza</code> → <code>azza</code> → <code>aa</code> → <code>b</code>.</li>
<li>Regarding the second query, the string will be processed as follows: <code>xxxxz</code> → <code>yxxz</code> → <code>yyz</code> → <code>zz</code> → <code></code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aabcdefghijklmnopqrstuvwxyz
1
1 27
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>yzyyyzyzyyyz
8
1 6
7 12
1 12
6 11
1 1
1 3
4 9
3 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
Yes
Yes
Yes
No
No
No
No
</pre></section>
</div>
</span> |
p02881 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is standing on a multiplication table with infinitely many rows and columns.</p>
<p>The square <var>(i,j)</var> contains the integer <var>i \times j</var>. Initially, Takahashi is standing at <var>(1,1)</var>.</p>
<p>In one move, he can move from <var>(i,j)</var> to either <var>(i+1,j)</var> or <var>(i,j+1)</var>.</p>
<p>Given an integer <var>N</var>, find the minimum number of moves needed to reach a square that contains <var>N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^{12}</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of moves needed to reach a square that contains the integer <var>N</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p><var>(2,5)</var> can be reached in five moves. We cannot reach a square that contains <var>10</var> in less than five moves.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>13
</pre>
<p><var>(5, 10)</var> can be reached in <var>13</var> moves.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10000000019
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10000000018
</pre>
<p>Both input and output may be enormous.</p></section>
</div>
</span> |
p03269 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>L</var>. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists.</p>
<ul>
<li>The number of vertices, <var>N</var>, is at most <var>20</var>. The vertices are given ID numbers from <var>1</var> to <var>N</var>.</li>
<li>The number of edges, <var>M</var>, is at most <var>60</var>. Each edge has an integer length between <var>0</var> and <var>10^6</var> (inclusive).</li>
<li>Every edge is directed from the vertex with the smaller ID to the vertex with the larger ID. That is, <var>1,2,...,N</var> is one possible topological order of the vertices.</li>
<li>There are exactly <var>L</var> different paths from Vertex <var>1</var> to Vertex <var>N</var>. The lengths of these paths are all different, and they are integers between <var>0</var> and <var>L-1</var>.</li>
</ul>
<p>Here, the length of a path is the sum of the lengths of the edges contained in that path, and two paths are considered different when the sets of the edges contained in those paths are different.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq L \leq 10^6</var></li>
<li><var>L</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>L</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>In the first line, print <var>N</var> and <var>M</var>, the number of the vertices and edges in your graph.
In the <var>i</var>-th of the following <var>M</var> lines, print three integers <var>u_i,v_i</var> and <var>w_i</var>, representing the starting vertex, the ending vertex and the length of the <var>i</var>-th edge.
If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8 10
1 2 0
2 3 0
3 4 0
1 5 0
2 6 0
3 7 0
4 8 0
5 6 1
6 7 1
7 8 1
</pre>
<p>In the graph represented by the sample output, there are four paths from Vertex <var>1</var> to <var>N=8</var>:</p>
<ul>
<li><var>1</var> → <var>2</var> → <var>3</var> → <var>4</var> → <var>8</var> with length <var>0</var></li>
<li><var>1</var> → <var>2</var> → <var>3</var> → <var>7</var> → <var>8</var> with length <var>1</var></li>
<li><var>1</var> → <var>2</var> → <var>6</var> → <var>7</var> → <var>8</var> with length <var>2</var></li>
<li><var>1</var> → <var>5</var> → <var>6</var> → <var>7</var> → <var>8</var> with length <var>3</var></li>
</ul>
<p>There are other possible solutions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5 7
1 2 0
2 3 1
3 4 0
4 5 0
2 4 0
1 3 3
3 5 1
</pre></section>
</div>
</span> |
p01254 |
<H1><font color="#000">Problem E:</font> Reverse a Road</H1>
<p>
Andrew R. Klein resides in the city of Yanwoe, and goes to his working place in this city every weekday.
He has been totally annoyed with the road traffic of this city. All the roads in this city are one-way, so he
has to drive a longer way than he thinks he need.
</p>
<p>
One day, the following thought has come up to Andrew’s mind: “How about making the sign of one road
indicate the opposite direction? I think my act won’t be out as long as I change just one sign. Well, of
course I want to make my route to the working place shorter as much as possible. Which road should I
alter the direction of?” What a clever guy he is.
</p>
<p>
You are asked by Andrew to write a program that finds the shortest route when the direction of up to
one road is allowed to be altered. You don’t have to worry about the penalty for complicity, because you
resides in a different country from Andrew and cannot be punished by the law of his country. So just help
him!
</p>
<H2>Input</H2>
<p>
The input consists of a series of datasets, each of which is formatted as follows:
</p>
<pre>
<i>N</i>
<i>S T</i>
<i>M</i>
<i>A</i><sub>1</sub> <i>B</i><sub>1</sub>
<i>A</i><sub>2</sub> <i>B</i><sub>2</sub>
...
<i>A<sub>M</sub></i> <i>B<sub>M</sub></i>
</pre>
<p>
<i>N</i> denotes the number of points. <i>S</i> and <i>T</i> indicate the points where Andrew’s home and working place are
located respectively. <i>M</i> denotes the number of roads. Finally, <i>A<sub>i</sub></i> and <i>B<sub>i</sub></i> indicate the starting and ending
points of the <i>i</i>-th road respectively. Each point is identified by a unique number from 1 to <i>N</i>. Some roads
may start and end at the same point. Also, there may be more than one road connecting the same pair of
starting and ending points.
</p>
<p>
You may assume all the following: 1 ≤ <i>N</i> ≤ 1000, 1 ≤ <i>M</i> ≤ 10000, and <i>S</i> ≠ <i>T</i>.
</p>
<p>
The input is terminated by a line that contains a single zero. This is not part of any dataset, and hence
should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print a line that contains the shortest distance (counted by the number of passed roads)
and the road number whose direction should be altered. If there are multiple ways to obtain the shortest
distance, choose one with the smallest road number. If no direction change results in a shorter route, print
0 as the road number.
</p>
<p>
Separate the distance and the road number by a single space. No extra characters are allowed.
</p>
<H2>Sample Input</H2>
<pre>
4
1 4
4
1 2
2 3
3 4
4 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 4
</pre>
|
p00015 |
<H1>National Budget</H1>
<p>
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
</p>
<p>
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
</p>
<p>
If given integers or the sum have more than 80 digits, print "overflow".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, the number of datasets <var>N</var> (1 ≤ <var>N</var> ≤ 50) is given. Each dataset consists of 2 lines:
</p>
<pre>
The first integer
The second integer
</pre>
<p>
The integer has at most 100 digits.
</p>
<H2>Output</H2>
<p>
For each dataset, print the sum of given integers in a line.
</p>
<H2>Sample Input</H2>
<pre>
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
</pre>
|
p02028 | <h2>N: 通販 (Mail Order)</h2>
<p>胡桃沢さんは、魔界通販で積み木のおもちゃを買った。</p>
<p>積み木は一辺の長さが1の立方体の形をしており、縦に $H$ 個、横に $W$ 個に分割されたマス目の上に積まれている。</p>
<p>真横から見ると、左から順に、$A_1, A_2, A_3, \dots, A_H$ 個のブロックが積まれて見えた。</p>
<p>正面から見ると、左から順に、$B_1, B_2, B_3, \dots, B_W$ 個のブロックが積まれて見えた。</p>
<p>胡桃沢さんは偉大なので、これらの情報だけからブロックの総数を当てようと考えた。</p>
<p>小さい数を答えて間違えると格好悪いので、考えられる最大の個数を答えたい。</p>
<h3>入力</h3>
<p>1 行目には整数 $H, W$ が空白区切りで与えられる。</p>
<p>2 行目には、真横から見たときの図を表す $H$ 個の整数 $A_1, A_2, A_3, \dots, A_H$ が空白区切りで与えられる。</p>
<p>3 行目には、正面から見たときの図を表す $W$ 個の整数 $B_1, B_2, B_3, \dots, B_W$ が空白区切りで与えられる。</p>
<h3>出力</h3>
<p>これらの情報から考えられるブロックの個数の最大値を出力しなさい。</p>
<h3>制約</h3>
<ul>
<li>$H, W$ は $1$ 以上 $100 \ 000$ 以下の整数</li>
<li>$A_1, A_2, A_3, \dots, A_H$ は $1$ 以上 $100 \ 000 \ 000$ 以下の整数</li>
<li>$B_1, B_2, B_3, \dots, B_W$ は $1$ 以上 $100 \ 000 \ 000$ 以下の整数</li>
<li>すべての入力に対して、条件を満たすブロックの積み方があることが保証される</li>
</ul>
<h3>入力例1</h3>
<pre>
2 2
1 5
1 5
</pre>
<h3>出力例1</h3>
<pre>
8
</pre>
<p>縦方向に $X$ 番目、横方向に $Y$ 番目のマスを $(X, Y)$ で表すことにします。</p>
<p>マス $(2, 2)$ に5個、マス $(1, 1)$、$(1, 2)$、$(2, 1)$ に $1$ 個ずつ積まれていると合計 $8$ 個のブロックが積まれることになります。</p>
<p>$9$ 個以上積まれている可能性は無いので、答えは $8$ です。</p>
<h3>入力例2</h3>
<pre>
3 3
2 4 5
3 1 5
</pre>
<h3>出力例2</h3>
<pre>
22
</pre>
|
p02182 | <h2>A: 間違い探し</h2>
<h3>問題</h3>
<p>縦に <var>N</var> マス、横に <var>M</var> マスある長方形の盤面 <var>A</var>, <var>B</var> が与えられます。各盤面について、それぞれのマスは白または黒で塗られています。</p>
<p>盤面 <var>X</var> の <var>i</var> 行 <var>j</var> 列目のマスの色を <var>C(i, j, X)</var> と表記することにします。</p>
<p>以下の条件を満たす整数の組 <var>(i, j)</var> がいくつあるか数えてください。</p>
<ul>
<li> <var>1 \leq i \leq N</var></li>
<li> <var>1 \leq j \leq M</var></li>
<li> <var>C(i, j, A) \neq C(i, j, B)</var></li>
</ul>
<h3>入力形式</h3>
<pre>
<var>N</var> <var>M</var>
<var>A_1</var>
...
<var>A_N</var>
<var>B_1</var>
...
<var>B_N</var>
</pre>
<p><var>A_i</var> (<var>1 \leq i \leq N</var>) の <var>j</var> 文字目が <code>#</code> のときは <var>C(i, j, A)</var> が黒、<code>.</code> のときは <var>C(i, j, A)</var> が白であることを表します。<var>B</var> についても同様です。</p>
<h3>制約</h3>
<ul>
<li> <var>1 \leq N, M \leq 2,000</var></li>
<li> <var>|A_i| = |B_i| = M</var></li>
<li> <var>A_i</var>, <var>B_i</var> は <code>#</code> と <code>.</code> のみからなる文字列</li>
</ul>
<h3>出力形式</h3>
<p>答えを一行に出力してください。</p>
<h3>入力例1</h3>
<pre>
2 3
..#
##.
.##
#..
</pre>
<h3>出力例1</h3>
<pre>2</pre>
<h3>入力例2</h3>
<pre>
7 28
............................
...#.....###...####....###..
..#.#...#...#..#...#..#...#.
.#...#..#......####...#.....
.#####..#...#..#......#...#.
.#...#...###...#.......###..
............................
............................
..###....###.....##....###..
.#...#..#...#...#.#...#...#.
...##...#...#.....#....####.
..#.....#...#.....#.......#.
.#####...###....####...###..
............................
</pre>
<h3>出力例2</h3>
<pre>40</pre>
|
p00445 |
<H1> JOIとIOI </H1>
<h2>問題</h2>
<p>
与えられた文字列内の連続する3文字が,JOIまたはIOIという並びになっている個所がそれぞれ何個所あるのかを数え上げるプログラムを作成せよ.文字列はアルファベットの大文字だけからなる.例えば下図の「JOIOIOI」という文字列にはJOIが1個所,IOIが2個所に含まれている.
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_joiioi">
<br>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる.各データセットは1行であり,10000文字以下のアルファベットの大文字からなる.入力は EOF で終了する.
</p>
<p>
データセットの数は 5 を超えない.
</p>
<h2>出力</h2>
<p>
<!--提出する出力ファイルは2行からなる. 1行目に見つかったJOIの個数,2行目に見つかったIOIの個数をそれぞれ出力せよ.-->
データセットごとに, 1行目に見つかったJOIの個数,2行目に見つかったIOIの個数をそれぞれ出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例</h3>
<pre>
JOIJOI
JOIOIOIOI
JOIOIJOINXNXJIOIOIOJ
</pre>
<h3>出力例</h3>
<pre>
2
0
1
3
2
3
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.