question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03411 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On a two-dimensional plane, there are <var>N</var> red points and <var>N</var> blue points.
The coordinates of the <var>i</var>-th red point are <var>(a_i, b_i)</var>, and the coordinates of the <var>i</var>-th blue point are <var>(c_i, d_i)</var>.</p>
<p>A red point and a blue point can form a <em>friendly pair</em> when, the <var>x</var>-coordinate of the red point is smaller than that of the blue point, and the <var>y</var>-coordinate of the red point is also smaller than that of the blue point.</p>
<p>At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq a_i, b_i, c_i, d_i < 2N</var></li>
<li><var>a_1, a_2, ..., a_N, c_1, c_2, ..., c_N</var> are all different.</li>
<li><var>b_1, b_2, ..., b_N, d_1, d_2, ..., d_N</var> are all different.</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>d_1</var>
<var>c_2</var> <var>d_2</var>
<var>:</var>
<var>c_N</var> <var>d_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of friendly pairs.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 0
3 1
1 3
4 2
0 4
5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, you can pair <var>(2, 0)</var> and <var>(4, 2)</var>, then <var>(3, 1)</var> and <var>(5, 5)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 0
1 1
5 2
2 3
3 4
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>For example, you can pair <var>(0, 0)</var> and <var>(2, 3)</var>, then <var>(1, 1)</var> and <var>(3, 4)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
2 2
3 3
0 0
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>It is possible that no pair can be formed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>4
</pre></section>
</div>
</span> |
p03105 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi likes the sound when he buys a drink from a vending machine.</p>
<p>That sound can be heard by spending <var>A</var> yen (the currency of Japan) each time.</p>
<p>Takahashi has <var>B</var> yen. He will hear the sound as many times as he can with that money, but at most <var>C</var> times, as he would be satisfied at that time.</p>
<p>How many times will he hear the sound?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A, B, C \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>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of times Takahashi will hear his favorite sound.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 11 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Since he has not less than <var>8</var> yen, he will hear the sound four times and be satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 9 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>He may not be able to be satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01138 |
<!-- begin en only -->
<h3><U>Osaki</U></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><U>大崎</U></h3>
<!-- end ja only -->
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
山手線は東京 23 区内に敷設されている環状鉄道路線である.総路線距離は 34.5km であり,1 周にはおよそ 1 時間を要する.駅は全部で 29 駅存在する.ラインカラーはウグイス色である.ピーク時の混雑率は 200% を超え,日本の鉄道路線の中で最も混雑している路線の 1 つである.最も混雑する時間帯では 3 分に 1 本の列車が走っており,東京に初めて来た人々はその光景に驚くものである.
</p>
<p>
鉄子さんは山手線を愛してやまない生粋の鉄道好きである.ある日,彼女は愛読書である JR 時刻表を読みながら次の疑問に至った.「山手線では一日に何台の車両が使われているのだろう?」
</p>
<p>
彼女は時刻表から運行に最低限必要な車両の台数を割り出そうとした.しかし,列車の本数が非常に多かったので,彼女一人の力では到底数え切れそうにない.そこで彼女は優秀なプログラマーであるあなたに助けを求めた.
</p>
<p>
あなたの仕事は与えられた時刻表から山手線の運行に要する車両の最低台数を求めるプログラムを書くことである.山手線は環状路線であることから,その時刻表は便宜上「大崎駅」を始発駅および終着駅として表記されることが多い.そのため,彼女から渡された時刻表にも各列車の大崎駅における発時刻および着時刻のみが記されている.
</p>
<p>
なお,実際の山手線では起こりえないが,状況設定を簡単にするため,ここでは大崎駅の到着直後に列車が大崎駅を出発可能であると考えることにする.また,鉄子さんが写した時刻に誤りがあったり,鉄子さんの妄想によって勝手に加えられた列車が時刻表に紛れ込んだりしている場合もあるが,あなたはそれらを見抜くことができないので,あくまでも書かれたとおりの時刻に対して台数を求めなければならない.
</p>
<p>
きちんと動作するプログラムを書けば,彼女が列車内デートに誘ってくれるかもしれない.もっとも,誘いに乗るか断るかはあなた次第であるが.
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
入力は複数のデータセットから構成される.各データセットは次の形式になっている.
</p>
<blockquote>
<i>n</i><br>
<i>hh</i>:<i>mm</i>:<i>ss</i> <i>hh</i>:<i>mm</i>:<i>ss</i><br>
<i>hh</i>:<i>mm</i>:<i>ss</i> <i>hh</i>:<i>mm</i>:<i>ss</i><br>
...<br>
<i>hh</i>:<i>mm</i>:<i>ss</i> <i>hh</i>:<i>mm</i>:<i>ss</i>
</blockquote>
<p>
1 行目の整数 <i>n</i> は時刻表に含まれる列車の本数である.この値は 10,000 を超えないことが保証されている.2 行目から <i>n</i> + 1 行目までの <i>n</i> 行には各列車の大崎駅の発時刻および着時刻がこの順番で与えられ,発時刻と着時刻の間は 1 つの空白で区切られている.各時刻は <i>hh</i>:<i>mm</i>:<i>ss</i> の形式で表現され,<i>hh</i> が時,<i>mm</i> が分,<i>ss</i> が秒を表している.それぞれの値の範囲は 0 ≦ <i>hh</i> < 24, 0 ≦ <i>mm</i> < 60, 0 ≦ <i>ss</i> < 60である.これらの数値は全て 2 桁となるように,必要に応じて先頭に 0 が付け加えられている.
</p>
<p>
夜の 24:00 をまたいで運行されるような列車は含まれない.したがって,常に発時刻は常に着時刻よりも前の時刻である.
</p>
<p>
入力の終了は <i>n</i> = 0 によって示される.これはデータセットには含まれない.
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
各データセットに対して,最低限必要となる車両の台数を 1 行に出力しなさい.
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
3
05:47:15 09:54:40
12:12:59 12:13:00
16:30:20 21:18:53
6
00:00:00 03:00:00
01:00:00 03:00:00
02:00:00 03:00:00
03:00:00 04:00:00
03:00:00 05:00:00
03:00:00 06:00:00
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
3
</pre>
|
p03555 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a grid with <var>2</var> rows and <var>3</var> columns of squares.
The color of the square at the <var>i</var>-th row and <var>j</var>-th column is represented by the character <var>C_{ij}</var>.</p>
<p>Write a program that prints <code>YES</code> if this grid remains the same when rotated <var>180</var> degrees, and prints <code>NO</code> otherwise.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>C_{i,j}(1 \leq i \leq 2, 1 \leq j \leq 3)</var> is a lowercase English letter.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>C_{11}C_{12}C_{13}</var>
<var>C_{21}C_{22}C_{23}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if this grid remains the same when rotated <var>180</var> degrees; print <code>NO</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>pot
top
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>This grid remains the same when rotated <var>180</var> degrees.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>tab
bet
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>This grid does not remain the same when rotated <var>180</var> degrees.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>eye
eel
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre></section>
</div>
</span> |
p01568 |
<h1>Repairing</h1>
<p>In the International City of Pipe Construction, it is planned to repair the water pipe at a certain point in the water pipe network.
The network consists of water pipe segments, stop valves and source point.
A water pipe is represented by a segment on a 2D-plane and intersected pair of water pipe segments are connected at the intersection point.
A stop valve, which prevents from water flowing into the repairing point while repairing, is represented by a point on some water pipe segment.
In the network, just one source point exists and water is supplied to the network from this point.
</p>
<p>Of course, while repairing, we have to stop water supply in some areas, but,
in order to reduce the risk of riots, the length of water pipes stopping water supply must be minimized.
What you have to do is to write a program to minimize the length of water pipes needed to stop water supply when the coordinates of end points of water pipe segments, stop valves, source point and repairing point are given.
</p>
<h2>Input</h2>
<p>A data set has the following format:
</p><blockquote>
<var>N</var> <var>M</var><br>
<var>x<sub>s1</sub></var> <var>y<sub>s1<sub></var> <var>x<sub>d1</sub></var> <var>y<sub>d1</sub></var><br>
...<br>
<var>x<sub>sN</sub></var> <var>y<sub>sN</sub></var> <var>x<sub>dN</sub></var> <var>y<sub>dN</sub></var><br>
<var>x<sub>v1</sub></var> <var>y<sub>v1</sub></var><br>
...<br>
<var>x<sub>vM</sub></var> <var>y<sub>vM</sub></var><br>
<var>x<sub>b</sub></var> <var>y<sub>b</sub></var><br>
<var>x<sub>c</sub></var> <var>y<sub>c</sub></var><br>
</blockquote>
<p>The first line of the input contains two integers, <var>N</var> (<var>1 ≤ N ≤ 300</var>) and <var>M</var> (<var>0 ≤ M ≤ 1,000</var>) that indicate the number of water pipe segments and stop valves.
The following <var>N</var> lines describe the end points of water pipe segments.
The <var>i</var>-th line contains four integers, <var>x<sub>si</sub></var>, <var>y<sub>si</sub></var>, <var>x<sub>di</sub></var> and <var>y<sub>di</sub></var> that indicate the pair of coordinates of end points of <var>i</var>-th water pipe segment.
The following <var>M</var> lines describe the points of stop valves.
The <var>i</var>-th line contains two integers, <var>x<sub>vi</sub></var> and <var>y<sub>vi</sub></var> that indicate the coordinate of end points of <var>i</var>-th stop valve.
The following line contains two integers, <var>x<sub>b</sub></var> and <var>y<sub>b</sub></var> that indicate the coordinate of the source point.
The last line contains two integers, <var>x<sub>c</sub></var> and <var>y<sub>c</sub></var> that indicate the coordinate of the repairing point.
</p>
<p>You may assume that any absolute values of coordinate integers are less than 1,000 (inclusive.)
You may also assume each of the stop valves, the source point and the repairing point is always on one of water pipe segments and that that each pair among the stop valves, the source point and the repairing point are different.
And, there is not more than one intersection between each pair of water pipe segments.
Finally, the water pipe network is connected, that is, all the water pipes are received water supply initially.
</p>
<h2>Output</h2>
<p>Print the minimal length of water pipes needed to stop water supply in a line.
The absolute or relative error should be less than or <var>10<sup>-6</sup></var>.
When you cannot stop water supply to the repairing point even though you close all stop valves, print "<code>-1</code>" in a line.
</p>
<h2>Sample Input 1</h2>
<pre>1 2
0 0 10 0
1 0
9 0
0 0
5 0
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>9.0
</pre>
<h2>Sample Input 2</h2>
<pre>5 3
0 4 2 4
0 2 2 2
0 0 2 0
0 0 0 4
2 0 2 4
0 2
1 0
2 2
1 4
2 1
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>3.0
</pre>
<h2>Sample Input 3</h2>
<pre>2 1
0 0 0 4
0 2 2 2
1 2
0 1
0 3
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>-1
</pre>
|
p01092 |
<h2>Development of Small Flying Robots</h2>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2015_H" align="right" width="300">
<p>
You are developing small flying robots in your laboratory.
</p>
<p>
The laboratory is a box-shaped building with <i>K</i> levels, each numbered 1 through <i>K</i> from bottom to top.
The floors of all levels are square-shaped with their edges precisely aligned east-west and north-south.
Each floor is divided into <i>R</i> × <i>R</i> cells.
We denote the cell on the <i>z</i>-th level in the <i>x</i>-th column from the west and the <i>y</i>-th row from the south as (<i>x</i>, <i>y</i>, <i>z</i>).
(Here, <i>x</i> and <i>y</i> are one-based.)
For each <i>x</i>, <i>y</i>, and <i>z</i> (<i>z</i> > 1),
the cell (<i>x</i>, <i>y</i>, <i>z</i>) is located immediately above the cell (<i>x</i>, <i>y</i>, <i>z</i> − 1).
</p>
<p>
There are <i>N</i> robots flying in the laboratory,
each numbered from 1 through <i>N</i>.
Initially, the <i>i</i>-th robot is located at the cell (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i>).
</p>
<p>
By your effort so far,
you successfully implemented the feature to move each flying robot to any place that you planned.
As the next step, you want to implement a new feature that gathers all
the robots in some single cell with the lowest energy consumption,
based on their current locations and the surrounding environment.
</p>
<p>
Floors of the level two and above have several holes.
Holes are rectangular and their edges align with edges of the
cells on the floors.
There are <i>M</i> holes in the laboratory building, each numbered 1 through <i>M</i>.
The <i>j</i>-th hole can be described by five integers
<i>u</i><sub>1<i>j</i></sub>, <i>v</i><sub>1<i>j</i></sub>, <i>u</i><sub>2<i>j</i></sub>, <i>v</i><sub>2<i>j</i></sub>, and <i>w</i><sub><i>j</i></sub>.
The <i>j</i>-th hole extends over the cells (<i>x</i>, <i>y</i>, <i>w</i><sub><i>j</i></sub>)
where
<i>u</i><sub>1<i>j</i></sub> ≤ <i>x</i> ≤ <i>u</i><sub>2<i>j</i></sub> and
<i>v</i><sub>1<i>j</i></sub> ≤ <i>y</i> ≤ <i>v</i><sub>2<i>j</i></sub>.
</p>
<p>
Possible movements of robots and energy consumption involved are as follows.
</p>
<ul>
<li>You can move a robot from one cell to an adjacent cell, toward one of north, south, east, or west.
The robot consumes its energy by 1 for this move.</li>
<li> If there is a hole to go through immediately above,
you can move the robot upward by a single level.
The robot consumes its energy by 100 for this move.</li>
</ul>
<p>
The robots never fall down even if there is a hole below.
Note that you can move two or more robots to the same cell.
</p>
<p>
Now, you want to gather all the flying robots at a single cell in the
<i>K</i>-th level where there is no hole on the floor, with the least energy consumption.
Compute and output the minimum total energy required by the robots.
</p>
<h3>Input</h3>
<p>
The input consists of at most 32 datasets, each in the following format.
Every value in the input is an integer.
</p>
<blockquote>
<i>N</i> <br>
<i>M</i> <i>K</i> <i>R</i> <br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>z</i><sub>1</sub> <br>
... <br>
<i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub> <i>z</i><sub><i>N</i></sub> <br>
<i>u</i><sub>11</sub> <i>v</i><sub>11</sub> <i>u</i><sub>21</sub> <i>v</i><sub>21</sub> <i>w</i><sub>1</sub> <br>
... <br>
<i>u</i><sub>1<i>M</i></sub> <i>v</i><sub>1<i>M</i></sub> <i>u</i><sub>2<i>M</i></sub> <i>v</i><sub>2<i>M</i></sub> <i>w</i><sub><i>M</i></sub> <br>
</blockquote>
<p>
<i>N</i> is the number of robots in the laboratory (1 ≤ <i>N</i> ≤ 100).
<i>M</i> is the number of holes (1 ≤ <i>M</i> ≤ 50),
<i>K</i> is the number of levels (2 ≤ <i>K</i> ≤ 10),
and <i>R</i> is the number of cells in one row and also one column on a single floor (3 ≤ <i>R</i> ≤ 1,000,000).
</p>
<p>
For each <i>i</i>,
integers <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, and <i>z<sub>i</sub></i>
represent the cell that the <i>i</i>-th robot initially located at
(1 ≤ <i>x<sub>i</sub></i> ≤ <i>R</i>,
1 ≤ <i>y<sub>i</sub></i> ≤ <i>R</i>,
1 ≤ <i>z<sub>i</sub></i> ≤ <i>K</i>).
Further,
for each <i>j</i>,
integers
<i>u</i><sub>1<i>j</i></sub>, <i>v</i><sub>1<i>j</i></sub>, <i>u</i><sub>2<i>j</i></sub>, <i>v</i><sub>2<i>j</i></sub>, and <i>w</i><sub><i>j</i></sub>
describe the position and the extent of the <i>j</i>-th hole
(1 ≤ <i>u</i><sub>1<i>j</i></sub> ≤ <i>u</i><sub>2<i>j</i></sub> ≤ <i>R</i>,
1 ≤ <i>v</i><sub>1<i>j</i></sub> ≤ <i>v</i><sub>2<i>j</i></sub> ≤ <i>R</i>,
2 ≤ <i>w</i><sub><i>j</i></sub> ≤ <i>K</i>).
</p>
<p>
The following are guaranteed.
</p>
<ul>
<li>In each level higher than or equal to two, there exists at least one hole.</li>
<li>In each level, there exists at least one cell not belonging to any holes.</li>
<li>No two holes overlap. That is, each cell belongs to at most one hole.</li>
</ul>
<p>
Two or more robots can initially be located at the same cell.
Also note that two neighboring cells may belong to different holes.
</p>
<p>
The end of the input is indicated by a line with a single zero.
</p>
<h3>Output</h3>
<p>
For each dataset, print the minimum total energy consumption in a single line.
</p>
<h3>Sample Input</h3>
<pre>2
1 2 8
1 1 1
8 8 1
3 3 3 3 2
3
3 2 3
1 1 2
1 1 2
1 1 2
1 1 1 1 2
1 2 1 2 2
2 1 2 1 2
2
2 3 100
100 50 1
1 50 3
100 1 100 100 3
1 1 1 100 2
5
6 7 60
11 11 1
11 51 1
51 11 1
51 51 1
31 31 1
11 11 51 51 2
11 11 51 51 3
11 11 51 51 4
11 11 51 51 5
18 1 54 42 6
1 43 59 60 7
5
6 4 9
5 5 3
1 1 1
1 9 1
9 1 1
9 9 1
3 3 7 7 4
4 4 6 6 2
1 1 2 2 3
1 8 2 9 3
8 1 9 2 3
8 8 9 9 3
5
10 5 50
3 40 1
29 13 2
39 28 1
50 50 1
25 30 5
3 5 10 10 2
11 11 14 14 2
15 15 20 23 2
40 40 41 50 2
1 49 3 50 2
30 30 50 50 3
1 1 10 10 4
1 30 1 50 5
20 30 20 50 5
40 30 40 50 5
15
2 2 1000000
514898 704203 1
743530 769450 1
202298 424059 1
803485 898125 1
271735 512227 1
442644 980009 1
444735 799591 1
474132 623298 1
67459 184056 1
467347 302466 1
477265 160425 2
425470 102631 2
547058 210758 2
52246 779950 2
291896 907904 2
480318 350180 768473 486661 2
776214 135749 872708 799857 2
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>216
6
497
3181
1365
1930
6485356
</pre> |
p03806 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Dolphin is planning to generate a small amount of a certain chemical substance C.<br/>
In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of <var>M_a:M_b</var>.<br/>
He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy.<br/>
The pharmacy sells <var>N</var> kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock.<br/>
The package of chemical <var>i</var> contains <var>a_i</var> grams of the substance A and <var>b_i</var> grams of the substance B, and is sold for <var>c_i</var> yen (the currency of Japan).<br/>
Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C.<br/>
Find the minimum amount of money required to generate the substance C.<br/>
If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N≦40</var> </li>
<li><var>1≦a_i,b_i≦10</var> </li>
<li><var>1≦c_i≦100</var> </li>
<li><var>1≦M_a,M_b≦10</var> </li>
<li><var>gcd(M_a,M_b)=1</var></li>
<li><var>a_i</var>, <var>b_i</var>, <var>c_i</var>, <var>M_a</var> and <var>M_b</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M_a</var> <var>M_b</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
<var>a_2</var> <var>b_2</var> <var>c_2</var>
<var>:</var>
<var>a_N</var> <var>b_N</var> <var>c_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1 1
1 2 1
2 1 2
3 3 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The amount of money spent will be minimized by purchasing the packages of chemicals <var>1</var> and <var>2</var>.<br/>
In this case, the mixture of the purchased chemicals will contain <var>3</var> grams of the substance A and <var>3</var> grams of the substance B, which are in the desired ratio: <var>3:3=1:1</var>.<br/>
The total price of these packages is <var>3</var> yen. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1 10
10 10 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>The ratio <var>1:10</var> of the two substances A and B cannot be satisfied by purchasing any combination of the packages. Thus, the output should be <code>-1</code>.</p></section>
</div>
</span> |
p00729 |
<h1><font color="#000">Problem B:</font> Analyzing Login/Logout Records</h1>
<!-- end en only -->
<p>
You have a computer literacy course in your university. In the computer
system, the login/logout records of all PCs in a day are stored in a
file. Although students may use two or more PCs at a time, no one can
log in to a PC which has been logged in by someone who has not
logged out of that PC yet.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
You are asked to write a program that calculates the total time of a
student that he/she used at least one PC in a given time period
(probably in a laboratory class) based on the records in the file.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The following are example login/logout records.
<ul>
<li> The student 1 logged in to the PC 1 at 12:55
<li> The student 2 logged in to the PC 4 at 13:00
<li> The student 1 logged in to the PC 2 at 13:10
<li> The student 1 logged out of the PC 2 at 13:20
<li> The student 1 logged in to the PC 3 at 13:30
<li> The student 1 logged out of the PC 1 at 13:40
<li> The student 1 logged out of the PC 3 at 13:45
<li> The student 1 logged in to the PC 1 at 14:20
<li> The student 2 logged out of the PC 4 at 14:30
<li> The student 1 logged out of the PC 1 at 14:40
</ul>
<p>
For a query such as "Give usage of the student 1 between 13:00 and
14:30", your program should answer "55 minutes", that is, the sum of
45 minutes from 13:00 to 13:45 and 10 minutes from 14:20 to 14:30, as
depicted in the following figure.
</p>
<!-- end en only -->
<p align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_b"><br>
</p>
<h2>Input</h2>
<!-- begin en only -->
<p>
The input is a sequence of a number of datasets.
The end of the input is indicated by a line containing two zeros
separated by a space.
The number of datasets never exceeds 10.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Each dataset is formatted as follows.
<blockquote>
<i>N</i> <i>M</i> <br>
<i>r</i> <br>
record<sub>1</sub><br>
... <br>
record<sub><i>r</i> </sub><br>
<i>q</i> <br>
query<sub>1</sub><br>
... <br>
query<sub><i>q</i> </sub><br>
</blockquote>
</p>
<!-- end en only -->
<p>
<!-- begin en only -->
The numbers <i>N</i> and <i>M</i> in the first line are the numbers of
PCs and the students, respectively. <i>r</i> is the number of
records. <i>q</i> is the number of queries. These four are integers
satisfying the following.
<!-- end en only -->
<blockquote>
1 ≤ <i>N</i> ≤ 1000, 1 ≤ <i>M</i> ≤ 10000, 2 ≤ <i>r</i> ≤ 1000, 1 ≤ <i>q</i> ≤ 50
</blockquote>
</p>
<!-- begin en only -->
<p>
Each record consists of four integers, delimited by a space, as follows.
</p>
<!-- end en only -->
<blockquote>
<i>t</i> <i>n</i> <i>m</i> <i>s</i>
</blockquote>
<p>
<!-- begin en only -->
<i>s</i> is 0 or 1.
If <i>s</i> is 1, this line means that the student <i>m</i> logged in
to the PC <i>n</i> at time <i>t</i> . If <i>s</i> is 0, it means that
the student <i>m</i> logged out of the PC <i>n</i> at time <i>t</i> .
The time is expressed as elapsed minutes from 0:00 of the day.
<i>t</i> , <i>n</i> and <i>m</i> satisfy the following.
<!-- end en only -->
<blockquote>
540 ≤ <i>t</i> ≤ 1260,
1 ≤ <i>n</i> ≤ <i>N</i> , 1 ≤ <i>m</i> ≤ <i>M</i>
</blockquote>
<p>
<!-- begin en only -->
You may assume the following about the records.
<nl>
<li>Records are stored in ascending order of time <i>t.</i>
<li>No two records for the same PC has the same time <i>t.</i>
<li>No PCs are being logged in before the time of the first record
nor after that of the last record in the file.
<li>Login and logout records for one PC appear alternatingly, and each of the login-logout record pairs is for the same student.
</nl>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
Each query consists of three integers delimited by a space, as follows.
</p>
<!-- end en only -->
<blockquote>
<i>t<sub>s</sub></i> <i>t<sub>e</sub></i> <i>m</i>
</blockquote>
<p>
<!-- begin en only -->
It represents "Usage of the student <i>m</i> between
<i>t<sub>s</sub></i> and <i>t<sub>e</sub></i> ".
<i>t<sub>s</sub></i> , <i>t<sub>e</sub></i> and <i>m</i>
satisfy the following.
<!-- end en only -->
<blockquote>
540 ≤ <i>t<sub>s</sub></i> < <i>t<sub>e</sub></i> ≤ 1260,
1 ≤ <i>m</i> ≤ <i>M</i>
</blockquote>
<h2>Output</h2>
<!-- begin en only -->
<p>
For each query, print a line having a decimal integer indicating the
time of usage in minutes. Output lines should not have any character
other than this number.
</p>
<!-- end en only -->
<h2>Sample Input</h2>
<pre>
4 2
10
775 1 1 1
780 4 2 1
790 2 1 1
800 2 1 0
810 3 1 1
820 1 1 0
825 3 1 0
860 1 1 1
870 4 2 0
880 1 1 0
1
780 870 1
13 15
12
540 12 13 1
600 12 13 0
650 13 15 1
660 12 15 1
665 11 13 1
670 13 15 0
675 11 13 0
680 12 15 0
1000 11 14 1
1060 12 14 1
1060 11 14 0
1080 12 14 0
3
540 700 13
600 1000 15
1000 1200 11
1 1
2
600 1 1 1
700 1 1 0
5
540 600 1
550 650 1
610 620 1
650 750 1
700 800 1
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
55
70
30
0
0
50
10
50
0
</pre>
|
p02714 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>S</var> of length <var>N</var> consisting of <code>R</code>, <code>G</code>, and <code>B</code>.</p>
<p>Find the number of triples <var>(i,~j,~k)~(1 \leq i < j < k \leq N)</var> that satisfy both of the following conditions:</p>
<ul>
<li><var>S_i \neq S_j</var>, <var>S_i \neq S_k</var>, and <var>S_j \neq S_k</var>.</li>
<li><var>j - i \neq k - j</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 4000</var></li>
<li><var>S</var> is a string of length <var>N</var> consisting of <code>R</code>, <code>G</code>, and <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 number of triplets in question.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
RRGB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Only the triplet <var>(1,~3,~4)</var> satisfies both conditions. The triplet <var>(2,~3,~4)</var> satisfies the first condition but not the second, so it does not count.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1800
</pre></section>
</div>
</span> |
p00379 | <h1>Dudeney Number</h1>
<p>
A Dudeney number is a positive integer for which the sum of its decimal digits is equal to the cube root of the number. For example, $512$ is a Dudeney number because it is the cube of $8$, which is the sum of its decimal digits ($5 + 1 + 2$).
</p>
<p>
In this problem, we think of a type similar to Dudeney numbers and try to enumerate them.
</p>
<p>
Given a non-negative integer $a$, an integer $n$ greater than or equal to 2 and an upper limit $m$, make a program to enumerate all $x$’s such that the sum of its decimal digits $y$ satisfies the relation $x = (y + a)^n$, and $x \leq m$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$a$ $n$ $m$
</pre>
<p>
The input line provides three integers: $a$ ($0 \leq a \leq 50$), $n$ ($2 \leq n \leq 10$) and the upper limit $m$ ($1000 \leq m \leq 10^8$).
</p>
<h2>Output</h2>
<p>
Output the number of integers that meet the above criteria.
</p>
<h2>Sample Input 1</h2>
<pre>
16 2 1000
</pre>
<h2>Sample Output 1<h2>
<pre>
2
</pre>
<p>
Two: $400 = (4 + 0 + 0 + 16)^2$ and $841 = (8 + 4 + 1 + 16)^2$
</p>
<h2>Sample Input 2</h2>
<pre>
0 3 5000
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<p>
Three: $1=1^3$, $512 = (5 + 1 + 2)^3$ and $4913 = (4 + 9 + 1 + 3)^3$.
</p>
<h2>Sample Input 3</h2>
<pre>
2 3 100000
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
<p>
There is no such number $x$ in the range below $100,000$ such that its sum of decimal digits $y$ satisfies the relation $(y+2)^3 = x$.
</p>
|
p02344 | <H1>Weighted Union Find Trees</H1>
<p>
There is a sequence $A = a_0, a_1, ..., a_{n-1}$. You are given the following information and questions.
</p>
<ul>
<li>relate$(x, y, z)$: $a_y$ is greater than $a_x$ by $z$</li>
<li>diff$(x, y)$: report the difference between $a_x$ and $a_y$ $(a_y - a_x)$</li>
</ul>
<H2>Input</H2>
<pre>
$n \; q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
In the first line, $n$ and $q$ are given. Then, $q$ information/questions are given in the following format.
</p>
<pre>
0 $x \; y\; z$
</pre>
<p>
or
</p>
<pre>
1 $x \; y$
</pre>
<p>
where '<span>0</span>' of the first digit denotes the relate information and '<span>1</span>' denotes the diff question.
</p>
<H2>Output</H2>
<p>
For each diff question, print the difference between $a_x$ and $a_y$ $(a_y - a_x)$.
</p>
<H2>Constraints</H2>
<ul>
<li>
$2 \leq n \leq 100,000$
</li>
<li>
$1 \leq q \leq 200,000$
</li>
<li>
$0 \leq x, y < n$
</li>
<li>
$x \ne y$
</li>
<li>
$0 \leq z \leq 10000$
</li>
<li>There are no inconsistency in the given information</li>
</ul>
<H2>Sample Input</H2>
<pre>
5 6
0 0 2 5
0 1 2 3
1 0 1
1 1 3
0 1 4 8
1 0 4
</pre>
<H2>Sample Output</H2>
<pre>
2
?
10
</pre>
|
p01991 | <h2>C: な◯りカット (Namo.. Cut)</h2>
<h3>問題</h3>
<p>-謎の巨大クラゲ、 コードネーム「な◯り」を討伐せよ-</p>
<p>
「な◯り」は非常に生命力が強いため、素早く切断し続けなければ、あっという間に復活してしまう。
我々は、「な◯り」をどのように切断するのが効率良いのか、日々試行錯誤している。
その過程で、あなた方プログラマの手が必要になった。
</p>
<p>
「な◯り」は <var>N</var> 頂点と <var>N</var> 辺からなる連結な無向グラフで表現できる。
以降、各頂点が <var>1</var> から <var>N</var> の異なる数で名前付けられているとしよう。
</p>
<p>
我々は、「な◯り」に関して <var>Q</var> 回の質問を行う。
それらすべてに答えるプログラムを作成して欲しい。
</p>
<p>質問は <var>1</var> から <var>Q</var> の番号を持ち、各質問は次のように構成される。</p>
<ul>
<li> 質問 <var>i</var> では 2 つの頂点 <var>a_i</var> と <var>b_i</var> が指定される。 <var>a_i</var> と <var>b_i</var> を非連結にするために、削除する必要のある辺の最小本数を答えよ。</li>
</ul>
<p>ここで、頂点 <var>u</var> と <var>v</var> が非連結であるとは、 <var>u</var> と <var>v</var> を行き来できる経路が存在しないことを指す。</p>
<h3>入力形式</h3>
<pre>
<var>N</var>
<var>u_1</var> <var>v_1</var>
<var>u_2</var> <var>v_2</var>
<var>...</var>
<var>u_N</var> <var>v_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_Q</var> <var>b_Q</var>
</pre>
<p>入力はすべて整数である。</p>
<p>
1 行目には頂点数 <var>N</var> が与えられる。
続く <var>N</var> 行のうち <var>i</var> 行目には、<var>i</var> 番目の辺が繋ぐ 2 頂点の番号 <var>u_i, v_i</var> が空白区切りで与えられる。
</p>
<p>
次に、質問の回数 <var>Q</var> が与えられる。
続く <var>Q</var> 行のうち <var>i</var> 行目には、<var>i</var> 番目の質問で指定される 2 頂点の番号 <var>a_i, b_i</var> が空白区切りで与えられる。
</p>
<h3>制約</h3>
<ul>
<li> <var>3 \leq N \leq 100,000</var></li>
<li> <var>1 \leq Q \leq 100,000</var></li>
<li> グラフに自己ループ及び多重辺は存在しない</li>
<li> <var>1 \leq a_i, b_i \leq N</var> かつ <var>a_i \neq b_i</var> (<var>1 \leq i \leq Q</var>)</li>
</ul>
<h3>出力形式</h3>
<p>
出力は <var>Q</var> 行からなる。
<var>i</var> 行目には、<var>a_i</var> と <var>b_i</var> を非連結にするために、削除する必要のある辺の最小本数を表す整数を出力せよ。
</p>
<h3>入力例1</h3>
<pre>
3
1 2
1 3
2 3
1
1 3
</pre>
<h3>出力例1</h3>
<pre>2</pre>
<h3>入力例2</h3>
<pre>
7
1 2
1 6
3 5
2 5
5 4
1 4
3 7
3
2 4
3 1
6 7
</pre>
<h3>出力例2</h3>
<pre>
2
1
1
</pre>
|
p00683 |
<H1>A Simple Offline Text Editor</H1>
<P>A text editor is a useful software tool that can help people in various situations including writing and programming. Your job in this problem is to construct an offline text editor, i.e., to write a program that first reads a given text and a sequence of editing commands and finally reports the text obtained by performing successively the commands in the given sequence.</P>
<P>The editor has a text buffer and a cursor. The target text is stored in the text buffer and most editing commands are performed around the cursor. The cursor has its position that is either the beginning of the text, the end of the text, or between two consecutive characters in the text. The initial cursor position (i.e., the cursor position just after reading the initial text) is the beginning of the text.</P>
<P>A text manipulated by the editor is a single line consisting of a sequence of characters, each of which must be one of the following: 'a' through 'z', 'A' through 'Z', '0' through '9', '.' (period), ',' (comma), and ' ' (blank). You can assume that any other characters never occur in the text buffer. You can also assume that the target text consists of at most 1,000 characters at any time. The definition of words in this problem is a little strange: a word is a non-empty character sequence delimited by not only blank characters but also the cursor. For instance, in the following text with a cursor represented as '^', </P><DIR>
<DIR>
<P>He^llo, World.</P></DIR>
</DIR>
<P>the words are the following.</P><DIR>
<DIR>
<P>He</P>
<P>llo,</P>
<P>World.</P></DIR>
</DIR>
<P>Notice that punctuation characters may appear in words as shown in this example.</P>
<P>The editor accepts the following set of commands. In the command list, "<I>any-text</I>" represents any text surrounded by a pair of double quotation marks such as "abc" and "Co., Ltd.".</P>
<P ALIGN="CENTER"><CENTER><TABLE BORDER CELLSPACING=1 CELLPADDING=6 WIDTH=584>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P><B>Command</B></TD>
<TD WIDTH="77%" VALIGN="TOP">
<B><P>Descriptions</B></TD>
</TR>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P>forward char</TD>
<TD WIDTH="77%" VALIGN="TOP">
<P>Move the cursor by one character to the right, unless the cursor is already at the end of the text.</TD>
</TR>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P>forward word</TD>
<TD WIDTH="77%" VALIGN="TOP">
<P>Move the cursor to the end of the leftmost word in the right. If no words occur in the right, move it to the end of the text.</TD>
</TR>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P>backward char</TD>
<TD WIDTH="77%" VALIGN="TOP">
<P>Move the cursor by one character to the left, unless the cursor is already at the beginning of the text.</TD>
</TR>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P>backward word</TD>
<TD WIDTH="77%" VALIGN="TOP">
<P>Move the cursor to the beginning of the rightmost word in the left. If no words occur in the left, move it to the beginning of the text.</TD>
</TR>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P>insert "<I>any-text</I>"</TD>
<TD WIDTH="77%" VALIGN="TOP">
<P>Insert <I>any-text</I> (excluding double quotation marks) at the position specified by the cursor. After performing this command, the new cursor position is at the end of the inserted text. The length of <I>any-text</I> is less than or equal to 100.</TD>
</TR>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P>delete char</TD>
<TD WIDTH="77%" VALIGN="TOP">
<P>Delete the character that is right next to the cursor, if it exists.</TD>
</TR>
<TR><TD WIDTH="23%" VALIGN="TOP">
<P>delete word</TD>
<TD WIDTH="77%" VALIGN="TOP">
<P>Delete the leftmost word in the right of the cursor. If one or more blank characters occur between the cursor and the word before performing this command, delete these blanks, too. If no words occur in the right, delete no characters in the text buffer.</TD>
</TR>
</TABLE>
</CENTER></P>
<H2>Input</H2>
<P>The first input line contains a positive integer, which represents the number of texts the editor will edit. For each text, the input contains the following descriptions:</P>
<UL>
<UL>
<LI>The first line is an initial text whose length is at most 100.</LI>
<LI>The second line contains an integer <I>M</I> representing the number of editing commands.</LI>
<LI>Each of the third through the <I>M</I>+2nd lines contains an editing command.</LI></UL>
</UL>
<P>You can assume that every input line is in a proper format or has no syntax errors. You can also assume that every input line has no leading or trailing spaces and that just a single blank character occurs between a command name (e.g., forward) and its argument (e.g., char).</P>
<H2>Output</H2>
<P>For each input text, print the final text with a character '^' representing the cursor position. Each output line shall contain exactly a single text with a character '^'.</P>
<H2>Sample Input</H2>
<FONT FACE="Courier New">
<pre>
3
A sample input
9
forward word
delete char
forward word
delete char
forward word
delete char
backward word
backward word
forward word
Hallow, Word.
7
forward char
delete word
insert "ello, "
forward word
backward char
backward char
insert "l"
3
forward word
backward word
delete word
</pre>
</FONT>
<H2>Output for the Sample Input</H2>
<FONT FACE="Courier New">
<pre>
Asampleinput^
Hello, Worl^d.
^
</pre>
</FONT>
|
p00396 | <h2>Playing with Stones</h2>
<p>
Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows:
</p>
<ol>
<li>
Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in each of the areas.
</li>
<li>
Koshiro and Ukiko alternately select an area and perform one of the following operations.<br>
(a) Remove a white stone from the area<br>
(b) Remove one or more black stones from the area. Note, however, that the number of the black stones must be less than or equal to white ones in the area.<br>
(c) Pick up a white stone from the stone pod and replace it with a black stone. There are plenty of white stones in the pod so that there will be no shortage during the game.<br>
</li>
<li>If either Koshiro or Ukiko cannot perform 2 anymore, he/she loses.</li>
</ol>
<p>
They played the game several times, with Koshiro’s first move and Ukiko’s second move, and felt the winner was determined at the onset of the game. So, they tried to calculate the winner assuming both players take optimum actions.
</p>
<p>
Given the initial allocation of black and white stones in each area, make a program to determine which will win assuming both players take optimum actions.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$w_1$ $b_1$
$w_2$ $b_2$
:
$w_N$ $b_N$
</pre>
<p>
The first line provides the number of areas $N$ ($1 \leq N \leq 10000$). Each of the subsequent $N$ lines provides the number of white stones $w_i$ and black stones $b_i$ ($1 \leq w_i, b_i \leq 100$) in the $i$-th area.
</p>
<h2>Output</h2>
<p>
Output <span>0</span> if Koshiro wins and <span>1</span> if Ukiko wins.
</p>
<h2>Sample Input 1</h2>
<pre>
4
24 99
15 68
12 90
95 79
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 1</h2>
<pre>
3
2 46
94 8
46 57
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
|
p03943 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Two students of AtCoder Kindergarten are fighting over candy packs.</p>
<p>There are three candy packs, each of which contains <var>a</var>, <var>b</var>, and <var>c</var> candies, respectively.</p>
<p>Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.</p>
<p>Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ a, b, c ≦ 100</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>a</var> <var>b</var> <var>c</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to distribute the packs so that each student gets the same number of candies, print <code>Yes</code>. Otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 30 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Give the pack with <var>30</var> candies to one student, and give the two packs with <var>10</var> and <var>20</var> candies to the other. Then, each gets <var>30</var> candies.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>30 30 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>In this case, the student who gets the pack with <var>100</var> candies always has more candies than the other.</p>
<p>Note that every pack must be given to one of them.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>56 25 31
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p02651 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are two persons, numbered <var>0</var> and <var>1</var>, and a variable <var>x</var> whose initial value is <var>0</var>.
The two persons now play a game.
The game is played in <var>N</var> rounds. The following should be done in the <var>i</var>-th round (<var>1 \leq i \leq N</var>):</p>
<ul>
<li>Person <var>S_i</var> does one of the following:<ul>
<li>Replace <var>x</var> with <var>x \oplus A_i</var>, where <var>\oplus</var> represents bitwise XOR.</li>
<li>Do nothing.</li>
</ul>
</li>
</ul>
<p>Person <var>0</var> aims to have <var>x=0</var> at the end of the game, while Person <var>1</var> aims to have <var>x \neq 0</var> at the end of the game.</p>
<p>Determine whether <var>x</var> becomes <var>0</var> at the end of the game when the two persons play optimally.</p>
<p>Solve <var>T</var> test cases for each input file.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq T \leq 100</var></li>
<li><var>1 \leq N \leq 200</var></li>
<li><var>1 \leq A_i \leq 10^{18}</var></li>
<li><var>S</var> is a string of length <var>N</var> consisting of <code>0</code> and <code>1</code>.</li>
<li>All numbers 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.
The first line is as follows:</p>
<pre><var>T</var>
</pre>
<p>Then, <var>T</var> test cases follow.
Each test case is given in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each test case, print a line containing <code>0</code> if <var>x</var> becomes <var>0</var> at the end of the game, and <code>1</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
0
0
</pre>
<p>In the first test case, if Person <var>1</var> replaces <var>x</var> with <var>0 \oplus 1=1</var>, we surely have <var>x \neq 0</var> at the end of the game, regardless of the choice of Person <var>0</var>.</p>
<p>In the second test case, regardless of the choice of Person <var>1</var>, Person <var>0</var> can make <var>x=0</var> with a suitable choice.</p></section>
</div>
</span> |
p02201 | <h2>増えるE869120君 (Ninja E869120)</h2>
<p>E869120君は分身が得意です。</p>
<p>ここに、$N$ 人のパ研部員がいます。しかし、このうちの何人かが E869120 君かもしれません。</p>
<p>そこで、あなたは $N$ 人全てのパ研部員に名前を聞きました。その結果、$N$ 人の部員はそれぞれ $S_1, S_2, S_3, \dots, S_N$ と名乗りました。</p>
<p>E869120 君は何人に分身していたでしょうか?ただし、全てのパ研部員は正直に自分の名前を答えるものとします。</p>
<h3>入力</h3>
<p>入力は以下の形式で標準入力から与えられる。</p>
<pre>
$N$
$S_1$
$S_2$
$S_3$
$\ldots$
$S_N$
</pre>
<h3>出力</h3>
<p>E869120君が何人に分身していたか、その人数を出力してください。ただし、E869120君がいない場合は「0」と出力してください。</p>
<p>ただし、最後には改行を入れること。</p>
<h3>制約</h3>
<ul>
<li>$1 \leq N \leq 1000$</li>
<li>$1 \leq (S_i$ の長さ$) \leq 100$</li>
<li>$N$ は整数である。</li>
<li>$S_i$ は数字とアルファベット大文字からなる文字列である。</li>
</ul>
<h3>入力例1</h3>
<pre>
5
E869120
TMJN
E869120
TAISA
YNYMXIAOLONGBAO
</pre>
<h3>出力例1</h3>
<pre>
2
</pre>
<p>E869120君は 2 人に分身しています。</p>
<h3>入力例2</h3>
<pre>
3
SQUARE1001
MENCOTTON
B2563125
</pre>
<h3>出力例2</h3>
<pre>
0
</pre>
<p>E869120君がいないときは0を出力してください。</p>
<h3>入力例3</h3>
<pre>
6
E8691200
E869121
E869122
E869123
E869124
E869125
</pre>
<h3>出力例3</h3>
<pre>
0
</pre>
<p>偽者に注意してください。</p> |
p01587 |
<H1><font color="#000">Problem G:</font> Riffle Swap</H1>
<p>
You have a deck of 2<sup><i>N</i></sup> cards (1 ≤ <i>N</i> ≤ 1000000) and want to have them shuffled.
</p>
<p>
The most popular shuffling technique is probably the riffle shuffle, in which you split a deck into two halves, place them in your left and right hands, and then interleave the cards alternatively from those hands. The shuffle is called perfect when the deck is divided exactly in half and the cards are interleaved one-by-one from the bottom half. For example, the perfect riffle shuffle of a deck of eight cards <0, 1, 2, 3, 4, 5, 6, 7> will result in a deck <0, 4, 1, 5, 2, 6, 3, 7>.
</p>
<p>
Since you are not so good at shuffling that you can perform the perfect riffle shuffle, you have decided to simulate the shuffle by swapping two cards as many times as needed. How many times you will have to perform swapping at least? As the resultant number will obviously become quite huge, your program should report the number modulo <i>M</i> = 1000003.
</p>
<H2>Input</H2>
<p>
The input just contains a single integer <i>N</i>.
</p>
<H2>Output</H2>
<p>
Print the number of swaps in a line. No extra space or empty line should occur.
</p>
<H2>Sample Input and Output</H2>
<H2>Input #1</H2>
<pre>
1
</pre>
<H2>Output #1</H2>
<pre>
0
</pre>
<br/>
<H2>Input #2</H2>
<pre>
2
</pre>
<H2>Output #2</H2>
<pre>
1
</pre>
<br/>
<H2>Input #3</H2>
<pre>
3
</pre>
<H2>Output #3</H2>
<pre>
4
</pre>
<br/>
<H2>Input #4</H2>
<pre>
4
</pre>
<H2>Output #4</H2>
<pre>
10
</pre>
<br/>
<H2>Input #5</H2>
<pre>
10
</pre>
<H2>Output #5</H2>
<pre>
916
</pre>
|
p03040 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a function <var>f(x)</var>, which is initially a constant function <var>f(x) = 0</var>.</p>
<p>We will ask you to process <var>Q</var> queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:</p>
<ul>
<li>An update query <code>1 a b</code>: Given two integers <var>a</var> and <var>b</var>, let <var>g(x) = f(x) + |x - a| + b</var> and replace <var>f(x)</var> with <var>g(x)</var>.</li>
<li>An evaluation query <code>2</code>: Print <var>x</var> that minimizes <var>f(x)</var>, and the minimum value of <var>f(x)</var>. If there are multiple such values of <var>x</var>, choose the minimum such value.</li>
</ul>
<p>We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq Q \leq 2 \times 10^5</var></li>
<li><var>-10^9 \leq a, b \leq 10^9</var></li>
<li>The first query is an update query.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>Q</var>
<var>Query_1</var>
<var>:</var>
<var>Query_Q</var>
</pre>
<p>See Sample Input 1 for an example.</p>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each evaluation query, print a line containing the response, in the order in which the queries are given.</p>
<p>The response to each evaluation query should be the minimum value of <var>x</var> that minimizes <var>f(x)</var>, and the minimum value of <var>f(x)</var>, in this order, with space in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 4 2
2
1 1 -8
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4 2
1 -3
</pre>
<p>In the first evaluation query, <var>f(x) = |x - 4| + 2</var>, which attains the minimum value of <var>2</var> at <var>x = 4</var>.</p>
<p>In the second evaluation query, <var>f(x) = |x - 1| + |x - 4| - 6</var>, which attains the minimum value of <var>-3</var> when <var>1 \leq x \leq 4</var>. Among the multiple values of <var>x</var> that minimize <var>f(x)</var>, we ask you to print the minimum, that is, <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 -1000000000 1000000000
1 -1000000000 1000000000
1 -1000000000 1000000000
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1000000000 3000000000
</pre></section>
</div>
</span> |
p03410 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two integer sequences, each of length <var>N</var>: <var>a_1, ..., a_N</var> and <var>b_1, ..., b_N</var>.</p>
<p>There are <var>N^2</var> ways to choose two integers <var>i</var> and <var>j</var> such that <var>1 \leq i, j \leq N</var>. For each of these <var>N^2</var> pairs, we will compute <var>a_i + b_j</var> and write it on a sheet of paper.
That is, we will write <var>N^2</var> integers in total.</p>
<p>Compute the XOR of these <var>N^2</var> integers.</p>
<p><details>
<summary style="display:list-item">Definition of XOR</summary></details></p>
<p>The XOR of integers <var>c_1, c_2, ..., c_m</var> is defined as follows:</p>
<ul>
<li>Let the XOR be <var>X</var>. In the binary representation of <var>X</var>, the digit in the <var>2^k</var>'s place (<var>0 \leq k</var>; <var>k</var> is an integer) is <var>1</var> if there are an odd number of integers among <var>c_1, c_2, ...c_m</var> whose binary representation has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> if that number is even.</li>
</ul>
<p>For example, let us compute the XOR of <var>3</var> and <var>5</var>. The binary representation of <var>3</var> is <var>011</var>, and the binary representation of <var>5</var> is <var>101</var>, thus the XOR has the binary representation <var>110</var>, that is, the XOR is <var>6</var>.</p>
<p></p></section></div></span> |
p02128 | <h1>Problem E: Light</h1>
<h2>Problem</h2>
<p>
$W \times H$ の二次元のマス上に$N$個の街灯がある。<br>
がっちょ君は$(1,1)$からスタートして$(W,H)$に行きたい。<br>
がっちょ君は暗いところが怖いので、街灯により明るくなっているマスしか歩きたくない。<br>
最初、すべての街灯はその街灯のあるマスのみを明るくしている。<br>
そこで、がっちょ君は好きな街灯$i$に対してコスト$r_i$を設定することにした。なお、コストを設定しない街灯があってもよい。<br>
街灯$i$はコスト$r_i$を消費することにより、その街灯を中心にマンハッタン距離で$r_i$以内の範囲を明るくすることができる。ただしコストは正の整数とする。<br>
がっちょ君は上下左右のいずれかの方向に隣接するマスに移動する事ができる。<br>
がっちょ君は$r_i$の合計値を最小になるように設定することにした。そのときの合計値を求めよ。<br>
<p>2つの地点 $(a,b)$ と $(c,d)$ 間のマンハッタン距離は $|a−c|$+$|b−d|$ で表される。</p>
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
$W$ $H$ $N$
$x_1$ $y_1$
...
$x_N$ $y_N$
</pre>
<p>
入力はすべて整数で与えられる。<br>
1行目に$W$と$H$と$N$が空白区切りで与えられる。<br>
続く$N$行に街灯$i$の座標$($$x_i$,$y_i$$)$が空白区切りで与えられる。<br>
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$1 \leq W \leq 500$</li>
<li>$1 \leq H \leq 500$</li>
<li>$1 \leq N \leq 100$</li>
<li>$1 \leq N \leq W \times H$</li>
<li>$1 \leq $$x_i$$ \leq W$</li>
<li>$1 \leq $$y_i$$ \leq H$</li>
<li>同じ座標に複数の街灯はない</li>
</ul>
<h2>Output</h2>
<p>
$r_i$の合計値の最小値を1行に出力せよ。<br>
</p>
<h2>Sample Input 1</h2>
<pre>
10 10 1
6 6
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<h2>Sample Input 2</h2>
<pre>
5 10 3
3 9
2 8
5 1
</pre>
<h2>Sample Output 2</h2>
<pre>
8
</pre>
<h2>Sample Input 3</h2>
<pre>
1 1 1
1 1
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
|
p00115 |
<h1>宇宙船 UAZ アドバンス号</h1>
<p>
恒星歴 2005.11.5。あなたは宇宙船 UAZ アドバンス号の艦長として敵の宇宙船と交戦しようとしています。 幸い敵の宇宙船はまだこちらに気付かずに静止しています。また、すでに敵の宇宙座標は判明しており強力な直線のビームを放つ「フェザー砲」は発射準備を完了しています。あとは、発射命令を出すばかりです。
</p>
<p>
ところが、宇宙空間には、敵の設置したエネルギーバリアが存在しています。バリアは三角形をしており「フェザー砲」のビームをはね返してしまいます。また、ビームがバリアに当たれば敵に気付かれて逃げられてしまいます。事前に命中すると判定できなければ、発射命令は出せません。
</p>
<p>
そこで、UAZ アドバンス号、敵、バリアの位置の宇宙座標(3次元座標 <var>x</var>, <var>y</var>, <var>z</var>) を入力して、ビームがバリアをさけて敵に命中する場合は "HIT"、バリアに当たってしまう場合"MISS"と出力するプログラムを作成してください。
</p>
<p>
ただし、バリアはアドバンス号から 3 角形に見えるものだけが対象であり、線分につぶれて見えるものはないものとします。また、バリアは 3 角形の頂点を含む境界でも有効であり、ビームをはね返すものとします。また、敵がバリア内にいる場合は"MISS"と出力して下さい。
</p>
<!--
<p>
恒星歴 2005.11.5。あなたは宇宙船 UAZ アドバンス号の艦長として敵の宇宙船と交戦しようとしています。 幸い敵の宇宙船はまだこちらに気付かずに静止しています。また、すでに敵の宇宙座標は判明しており強力な直線のビームを放つ「フェザー砲」は発射準備を完了しています。あとは、発射命令を出すばかりです。
</p>
<p>
ところが、1つだけ困ったことが判明しました。宇宙空間には、敵の設置したエネルギーバリアが存在している
のです。バリアは三角形をしており「フェザー砲」ビームをはね返してしまいます。また、ビームがバリアに当たれ
ば敵に気付かれて逃げられてしまいます。事前に命中すると判定できなければ、発射命令は出せません。
</p>
<p>
そこで、UAZ アドバンス号、敵、バリアの位置の宇宙座標(3次元座標 <i>x</i>, <i>y</i>, <i>z</i> )を入力して、「フェ
ザー砲」がバリアをさけて敵に命中する場合は“HIT”、バリアに命中してはね返されてしまう場合“MISS”と出力し
て終了するプログラムを作成してください。
</p>
<p>
ただし、バリアはアドバンス号から 3 角形に見えるものだけが対象であり、線分につぶれて見えるものはないも
のとします。また、バリアは 3 角形の頂点を含む境界でも有効であり、ビームをはね返すものとします。
</p>
-->
<H2>Input</H2>
<p>
入力データの形式は以下のとおりです:<br/>
<br/>
1 行目は、UAZ アドバンス号の座標 (<var>x</var>, <var>y</var>, <var>z</var>) (整数、半角空白区切り)<br/>
2 行目は、敵の座標 (<var>x</var>, <var>y</var>, <var>z</var>) (整数、半角空白区切り)<br/>
3 行目は、バリアの頂点 1 の座標 (<var>x</var>, <var>y</var>, <var>z</var>) (整数、半角空白区切り)<br/>
4 行目は、バリアの頂点 2 の座標 (<var>x</var>, <var>y</var>, <var>z</var> ) (整数、半角空白区切り)<br/>
5 行目は、バリアの頂点 3 の座標 (<var>x</var>, <var>y</var>, <var>z</var> ) (整数、半角空白区切り)<br/>
</p>
<H2>Output</H2>
<p>
HIT または MISS と1行に出力してください。
</p>
<H2>Constraints</H2>
<ul>
<li>-100 ≤ <var>x</var>, <var>y</var>, <var>z</var> ≤ 100</li>
<li>UAZ アドバンス号と敵が同じ位置にいることはない。</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
-10 0 0
10 0 0
0 10 0
0 10 10
0 0 10
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
HIT
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
-10 6 6
10 6 6
0 10 0
0 10 10
0 0 10
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
MISS
</pre>
<br/>
|
p02082 |
<h1>E: Expensive Function</h1>
<h2>問題文</h2>
<p>数列$a$と非負整数上の関数$f(x)$が以下のように定義されています。</p>
<ul>
<li>$a_1 = 0$</li>
<li>$a_i = (a_{i-1} \times p + q) \bmod M (i \geq2)$</li>
<li>$f(x) = x \mbox{ XOR } a_1 \mbox{ XOR } a_2 \mbox{ XOR } ... \mbox{ XOR } a_{10^8}$ </li>
</ul>
<p>松崎くんが計算すると、$f(s) = t$ でした。
非負整数 $y$ が与えられるので、$f(y)$ を求めてください。</p>
<p>$n$ 個の非負整数 $x_1, x_2, \ldots, x_n$ の排他的論理和 $x_1 \mbox{ XOR } x_2 \mbox{ XOR } \ldots \mbox{ XOR } x_n$ は以下のように定義されます:</p>
<ul>
<li>$x_1 \mbox{ XOR } x_2 \mbox{ XOR } \ldots \mbox{ XOR } x_n$ を二進表記した際の $2^k ( k \geq 0 )$ の位の数は $x_1, x_2, \ldots, x_n$ のうち、二進表記した際の $2^k ( k \geq 0 )$ の位の数が $1$ となるものの個数が奇数ならば $1$ 、そうでなければ $0$ となる。</li>
</ul>
<h2>制約</h2>
<ul>
<li>$0 \leq p, q, s, t, y \leq 10^9$ </li>
<li>$1 \leq M \leq 10^9$ </li>
<li>入力は全て整数</li>
</ul>
<h2>入力</h2>
<p>入力は以下の形式で標準入力から与えられます。</p>
<pre>$s$ $t$
$p$ $q$ $M$
$y$</pre>
<h2>出力</h2>
<p>$f(y)$ を出力してください。</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>0 15656
3 7 13333
0
</pre>
<h3>出力例1</h3>
<pre>15656
</pre>
<h3>入力例2</h3>
<pre>0 0
0 0 3
0
</pre>
<h3>出力例2</h3>
<pre>0
</pre>
<h3>入力例3</h3>
<pre>1000000000 1000000000
1000000000 1000000000 1000000000
1000000000
</pre>
<h3>出力例3</h3>
<pre>1000000000
</pre>
|
p02578 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> persons are standing in a row. The height of the <var>i</var>-th person from the front is <var>A_i</var>.</p>
<p>We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:</p>
<p>Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.</p>
<p>Find the minimum total height of the stools needed to meet this goal.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2\times 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>\ldots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total height of the stools needed to meet the goal.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
2 1 5 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>If the persons stand on stools of heights <var>0</var>, <var>1</var>, <var>0</var>, <var>1</var>, and <var>2</var>, respectively, their heights will be <var>2</var>, <var>2</var>, <var>5</var>, <var>5</var>, and <var>5</var>, satisfying the condition.</p>
<p>We cannot meet the goal with a smaller total height of the stools.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
3 3 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Giving a stool of height <var>0</var> to everyone will work.</p></section>
</div>
</span> |
p00545 |
<h1>JOI国のお散歩事情 (Walking in JOI Kingdom)</h1>
<h2> 問題</h2>
<p>
JOI 国には東西に走る 1 本の十分に長い道路がある.JOI 国の王宮が道路沿いにあり,JOI 国における道路沿いの位置は整数 A で表される.A = 0 のときは王宮の位置を表す.A > 0 のときは,王宮から東へ A メートル進んだ位置を表す.A < 0 のときは,王宮から西へ -A メートル進んだ位置を表す.
</p>
<p>
JOI 国の道路沿いには N 軒の家があり,家には西から順に 1 から N までの番号が付けられている.JOI 国には N 人の国民がいて,国民には 1 から N までの番号が付けられている.家 i には国民 i が住んでいる.家 i の位置は 0 でない偶数 A<sub>i</sub> で表される.A<sub>1</sub>, ..., A<sub>N</sub> は全て異なる.
</p>
<p>
JOI 国では,近年国民の運動不足が問題になっている.国民の健康が気になった JOI 国の王様は,国民全員に散歩をする命令を出した.王様が命令を出すと,全ての国民は一斉に東向きまたは西向きに歩き始める.それぞれの国民がどちらの向きに歩き始めるかは,国民ごとに決まっている.全ての国民は,歩くときは 1 秒あたり 1 メートルの速度で歩く.
</p>
<p>
JOI 国の国民は皆おしゃべりが大好きである.散歩の途中にほかの国民に出会うと,その場所で立ち止まって世間話を始めてしまう.すでに立ち止まっている国民に出会った場合も同様である.一度立ち止まった国民は,再び歩き出すことはない.
</p>
<p>
JOI 国には Q 人の重要人物がいる.JOI 国の王様は,命令が出されてから T 秒後の,Q 人の重要人物の位置を把握しておきたい.命令が出されてから T 秒後の,Q 人の重要人物の位置を求めるプログラムを作成せよ.
</p>
<h2> 入力</h2>
<p>
入力は,1 + N + Q 行からなる.
</p>
<p>
1 行目には,3 つの整数 N,T,Q (1 ≦ N ≦ 100000 (= 10<sup>5</sup>), 0 ≦ T ≦ 10<sup>18</sup>, 1 ≦ Q ≦ 1000,1 ≦ Q ≦ N) が空白を区切りとして書かれている.これは,JOI 国に家が N 軒あり,王様が命令を出してから T 秒後の,Q 人の重要人物の位置を把握しておきたいことを表す.
</p>
<p>
続く N 行のうち i 行目には,2 つの整数 A<sub>i</sub>, D<sub>i</sub> (-10<sup>18</sup> ≦ A<sub>i</sub> ≦ 10<sup>18</sup>, A<sub>i</sub> は 0 でない偶数, 1 ≦ D<sub>i</sub> ≦ 2) が空白を区切りとして書かれている.A<sub>i</sub> は家 i の位置を表す偶数である.すべての i (1 ≦ i ≦ N - 1) について,A<sub>i</sub> < A<sub>i+1</sub> を満たす.D<sub>i</sub> は命令が出された後に国民 i が歩き始める方向を表す.D<sub>i</sub> = 1 のときは国民 i は東向きに歩き始める.D<sub>i</sub> = 2 のときは国民 i は西向きに歩き始める.
</p>
<p>
続く Q 行のうち i 行目には,整数 X<sub>i</sub> (1 ≦ X<sub>i</sub> ≦ N) が書かれている.これは,i 番目の重要人物が家 X<sub>i</sub> に住んでいることを表す.すべての i (1 ≦ i ≦ Q - 1) について,X<sub>i</sub> < X<sub>i+1</sub> を満たす.
</p>
<p>
与えられる 5 つの入力データのうち,入力 1 では N ≦ 100,T ≦ 10000を満たす.また,入力 2 では N ≦ 5000 を満たす.また,入力 3 では,ある整数 M (1 ≦ M ≦ N - 1) があって,すべての i (1 ≦ i ≦ M) について D<sub>i</sub> = 1,すべての j (M + 1 ≦ j ≦ N) について D<sub>j</sub> = 2 を満たす.また,入力 1,2,3 では,入力に与えられる整数の絶対値は 1000000000 (= 10<sup>9</sup>) を超えない.入力 4,5 では,与えられる整数が 32 ビット符号付き整数の範囲に収まらないことに注意せよ.
</p>
<h2> 出力</h2>
<p>
出力は Q 行からなる.
</p>
<p>
i 行目 (1 ≦ i ≦ Q) には,王様が命令を出してから T 秒後の,i 番目の重要人物の位置を表す整数を出力せよ.この値が整数であることは,問題文の条件より保証されている.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
5 5 3
-8 1
-4 2
-2 2
4 2
10 1
1
3
5
</pre>
<h3>出力例 1</h3>
<pre>
-6
-6
15
</pre>
<h3>入力例 2</h3>
<pre>
7 18 5
-100 1
-56 2
-34 1
-30 1
-22 1
-4 2
18 2
1
3
4
5
7
</pre>
<h3>出力例 2</h3>
<pre>
-82
-16
-13
-13
0
</pre>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2015/2016-yo/index.html">情報オリンピック日本委員会作 『第 15 回日本情報オリンピック JOI 2015/2016 予選競技課題』</a>
</p>
</div>
|
p01704 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
color: #333333;
display: block;
padding: 8.5px;
margin: 0 0 9px;
font-size: 12px;
line-height: 18px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}</style><div class="part"><h3>Problem Statement</h3><p>We have planted $N$ flower seeds, all of which come into different flowers.
We want to make all the flowers come out together.
</p>
<p>Each plant has a value called vitality, which is initially zero.
Watering and spreading fertilizers cause changes on it, and the $i$-th plant will come into flower if its vitality is equal to or greater than $\mathit{th}_i$.
Note that $\mathit{th}_i$ may be negative because some flowers require no additional nutrition.
</p>
<p>Watering effects on all the plants.
Watering the plants with $W$ liters of water changes the vitality of the $i$-th plant by $W \times \mathit{vw}_i$ for all $i$ ($1 \le i \le n$), and costs $W \times \mathit{pw}$ yen, where $W$ need not be an integer.
$\mathit{vw}_i$ may be negative because some flowers hate water.
</p>
<p>We have $N$ kinds of fertilizers, and the $i$-th fertilizer effects only on the $i$-th plant.
Spreading $F_i$ kilograms of the $i$-th fertilizer changes the vitality of the $i$-th plant by $F_i \times \mathit{vf}_i$, and costs $F_i \times \mathit{pf}_i$ yen, where $F_i$ need not be an integer as well.
Each fertilizer is specially made for the corresponding plant, therefore $\mathit{vf}_i$ is guaranteed to be positive.
</p>
<p>Of course, we also want to minimize the cost.
Formally, our purpose is described as "to minimize $W \times \mathit{pw} + \sum_{i=1}^{N}(F_i \times \mathit{pf}_i)$ under $W \times \mathit{vw}_i + F_i \times \mathit{vf}_i \ge \mathit{th}_i$, $W \ge 0$, and $F_i \ge 0$ for all $i$ ($1 \le i \le N$)".
Your task is to calculate the minimum cost.
</p>
</div><div class="part"><h3>Input</h3>
<p>The input consists of multiple datasets.
The number of datasets does not exceed $100$, and the data size of the input does not exceed $20\mathrm{MB}$.
Each dataset is formatted as follows.
</p>
<blockquote style="font-size:14pt">$N$<br>$\mathit{pw}$<br>$\mathit{vw}_1$ $\mathit{pf}_1$ $\mathit{vf}_1$ $\mathit{th}_1$<br>:<br>:<br>$\mathit{vw}_N$ $\mathit{pf}_N$ $\mathit{vf}_N$ $\mathit{th}_N$</blockquote>
<p>The first line of a dataset contains a single integer $N$, number of flower seeds.
The second line of a dataset contains a single integer $\mathit{pw}$, cost of watering one liter.
Each of the following $N$ lines describes a flower. The $i$-th line contains four integers, $\mathit{vw}_i$, $\mathit{pf}_i$, $\mathit{vf}_i$, and $\mathit{th}_i$, separated by a space.
</p>
<p>You can assume that $1 \le N \le 10^5$, $1 \le \mathit{pw} \le 100$, $-100 \le \mathit{vw}_i \le 100$, $1 \le \mathit{pf}_i \le 100$, $1 \le \mathit{vf}_i \le 100$, and $-100 \le \mathit{th}_i \le 100$.
</p>
<p>The end of the input is indicated by a line containing a zero.
</p>
</div><div class="part"><h3>Output</h3>
<p>For each dataset, output a line containing the minimum cost to make all the flowers come out.
The output must have an absolute or relative error at most $10^{-4}$.
</p>
</div><div class="part"><h3>Sample Input</h3>
<pre>3
10
4 3 4 10
5 4 5 20
6 5 6 30
3
7
-4 3 4 -10
5 4 5 20
6 5 6 30
3
1
-4 3 4 -10
-5 4 5 -20
6 5 6 30
3
10
-4 3 4 -10
-5 4 5 -20
-6 5 6 -30
0</pre>
</div><div class="part"><h3>Output for the Sample Input</h3>
<pre>43.5
36
13.5
0</pre>
</div> |
p03739 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>. The <var>i</var>-th term in the sequence is <var>a_i</var>.
In one operation, you can select a term and either increment or decrement it by one.</p>
<p>At least how many operations are necessary to satisfy the following conditions?</p>
<ul>
<li>For every <var>i</var> <var>(1≤i≤n)</var>, the sum of the terms from the <var>1</var>-st through <var>i</var>-th term is not zero.</li>
<li>For every <var>i</var> <var>(1≤i≤n-1)</var>, the sign of the sum of the terms from the <var>1</var>-st through <var>i</var>-th term, is different from the sign of the sum of the terms from the <var>1</var>-st through <var>(i+1)</var>-th term.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ n ≤ 10^5</var></li>
<li><var>|a_i| ≤ 10^9</var></li>
<li>Each <var>a_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum necessary count of operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 -3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, the given sequence can be transformed into <var>1, -2, 2, -2</var> by four operations. The sums of the first one, two, three and four terms are <var>1, -1, 1</var> and <var>-1</var>, respectively, which satisfy the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
3 -6 4 -5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The given sequence already satisfies the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
-1 4 3 2 -5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p00816 | <H1><font color="#000">Problem F:</font> Shredding Company</H1>
<p>
You have just been put in charge of developing a new shredder for the Shredding Company. Although a ``normal'' shredder would just shred sheets of paper into little pieces so that the contents would become unreadable, this new shredder needs to have the following unusual basic characteristics.
</p>
<ul>
<li> The shredder takes as input a <i>target number</i> and a sheet of paper with a number written on it.</li>
<li> It shreds (or cuts) the sheet into pieces each of which has one or more digits on it.</li>
<li> The sum of the numbers written on each piece is the closest possible number to the target number, without going over it.</li>
</ul>
<p>
For example, suppose that the target number is <i>50</i>, and the sheet of paper has the number <i>12346</i>. The shredder would cut the sheet into four pieces, where one piece has <i>1</i>, another has <i>2</i>, the third has <i>34</i>, and the fourth has <i>6</i>. This is because their sum 43 (= 1 + 2 + 34 + 6) is closest to the target number <i>50</i> of all possible combinations without going over 50. For example, a combination where the pieces are <i>1</i>, <i>23</i>, <i>4</i>, and <i>6</i> is not valid, because the sum of this combination 34 (= 1 + 23 + 4 + 6) is less than the above combination's 43. The combination of <i>12</i>, <i>34</i>, and <i>6</i> is not valid either, because the sum 52 (= 12+34+6) is greater than the target number of 50.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_shredding">
<p>Figure 1. Shredding a sheet of paper having the number <i>12346</i> when the target number is <i>50</i></p>
</center>
<p>
There are also three special rules:
</p>
<ul>
<li> If the target number is the same as the number on the sheet of paper, then the paper is not cut. For example, if the target number is <i>100</i> and the number on the sheet of paper is also <i>100</i>, then the paper is not cut.</li>
<li> If it is not possible to make any combination whose sum is less than or equal to the target number, then error is printed on a display. For example, if the target number is <i>1</i> and the number on the sheet of paper is <i>123</i>, it is not possible to make any valid combination, as the combination with the smallest possible sum is <i>1</i>, <i>2</i>, <i>3</i>. The sum for this combination is 6, which is greater than the target number, and thus error is printed.</li>
<li> If there is more than one possible combination where the sum is closest to the target number without going over it, then <i>rejected</i> is printed on a display. For example, if the target number is <i>15</i>, and the number on the sheet of paper is <i>111</i>, then there are two possible combinations with the highest possible sum of 12: (a) <i>1</i> and <i>11</i> and (b) <i>11</i> and <i>1</i>; thus rejected is printed.
</li>
</ul>
<p>
In order to develop such a shredder, you have decided to first make a simple program that would simulate the above characteristics and rules. Given two numbers, where the first is the target number and the second is the number on the sheet of paper to be shredded, you need to figure out how the shredder should ``cut up'' the second number.
<H2>Input</H2>
<p>
The input consists of several test cases, each on one line, as follows:
</p>
<pre>
<i>t</i><sub>1</sub> <i>num</i><sub>1</sub>
<i>t</i><sub>2</sub> <i>num</i><sub>2</sub>
...
<i>t</i><sub><i>n</i></sub> <i>num</i><sub><i>n</i></sub>
0 0
</pre>
<p>
Each test case consists of the following two positive integers, which are separated by one space: (1) the first integer (<i>t<sub>i</sub></i> above) is the target number; (2) the second integer (<i>num<sub>i</sub></i> above) is the number that is on the paper to be shredded.
</p>
<p>
Neither integers may have a 0 as the first digit, e.g., 123 is allowed but 0123 is not. You may assume that both integers are at most 6 digits in length. A line consisting of two zeros signals the end of the input.
</p>
<H2>Output</H2>
<p>
For each test case in the input, the corresponding output takes one of the following three types:
</p>
<ul>
<li> <i>sum</i> <i>part</i><sub>1</sub> <i>part</i><sub>2</sub> ...</li>
<li> rejected</li>
<li> error</li>
</ul>
<p>
In the first type, <i>part<sub>j</sub></i> and <i>sum</i> have the following meaning:
</p>
<ul>
<li> Each <i>part<sub>j</sub></i> is a number on one piece of shredded paper. The order of <i>part<sub>j</sub></i> corresponds to the order of the original digits on the sheet of paper.</li>
<li> <i>sum</i> is the sum of the numbers after being shredded, i.e., <i>sum</i> = <i>part</i><sub>1</sub> + <i>part</i><sub>2</sub> + ... .</li>
</ul>
<p>
Each number should be separated by one space.
</p>
<p>
The message "error" is printed if it is not possible to make any combination, and "rejected" if there is more than one possible combination.
</p>
<p>
No extra characters including spaces are allowed at the beginning of each line, nor at the end of each line.
</p>
<H2>Sample Input</H2>
<pre>
50 12346
376 144139
927438 927438
18 3312
9 3142
25 1299
111 33333
103 862150
6 1104
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
43 1 2 34 6
283 144 139
927438 927438
18 3 3 12
error
21 1 2 9 9
rejected
103 86 2 15 0
rejected
</pre>
|
p03693 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer has three cards, one red, one green and one blue.<br/>
An integer between <var>1</var> and <var>9</var> (inclusive) is written on each card: <var>r</var> on the red card, <var>g</var> on the green card and <var>b</var> on the blue card.<br/>
We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.<br/>
Is this integer a multiple of <var>4</var>? </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ r, g, b ≤ 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>g</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the three-digit integer is a multiple of <var>4</var>, print <code>YES</code> (case-sensitive); otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p><var>432</var> is a multiple of <var>4</var>, and thus <code>YES</code> should be printed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p><var>234</var> is not a multiple of <var>4</var>, and thus <code>NO</code> should be printed.</p></section>
</div>
</span> |
p02981 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> of us are going on a trip, by train or taxi.</p>
<p>The train will cost each of us <var>A</var> yen (the currency of Japan).</p>
<p>The taxi will cost us a total of <var>B</var> yen.</p>
<p>How much is our minimum total travel expense?</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 20</var></li>
<li><var>1 \leq A \leq 50</var></li>
<li><var>1 \leq B \leq 50</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</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the minimum total travel expense.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>The train will cost us <var>4 \times 2 = 8</var> yen, and the taxi will cost us <var>9</var> yen, so the minimum total travel expense is <var>8</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p01354 |
<H1>Problem F: The Castle</H1>
<p>
待ち伏せていた敵を見事撃破したうさぎは, 主人公を敵の城内に進めることに成功した. 主人公が城の地下牢に捕らわれていたねこたちを解放したところ, 彼らのうちの何匹かが主人公の力になってくれることになった.
</p>
<p>
ねこたちの話では, 城の奥にいる魔王に辿りつくには1 番から<i>n</i> 番の<i>n</i> 個の部屋をこの順に通り抜けることになるが, 各部屋には1 体ずつ敵が待ち受けていて逐一倒していかなければならないという. 仲間になった<i>m</i>匹のねこそれぞれについて, 各部屋の敵それぞれに対する勝率が分かっており, 主人公はこのねこたちを1 匹ずつ城の奥へ向けて派遣する. 各部屋はそこにいる敵を倒してからでなければ通過できないので, あるねこがある部屋の敵にやられたら, 次のねこはその部屋の敵から戦っていくことになる.
</p>
<p>
派遣されたねこは敵にやられるまで進むが, 派遣したねこがどの部屋の敵にやられたかは毎回知ることができ, それによって次にどのねこを派遣するかを決めることができる. どのようにすれば, ねこたちが待ち受けるすべての敵を倒せる確率が最大になるだろうか.
</p>
<H2>Input</H2>
<p>
入力の一行目には<i>m</i> と<i>n</i> がスペースで区切られて与えられる. 1 ≤ <i>m</i>, <i>n</i> ≤ 16
</p>
<p>
つづく<i>m</i> 行には, 猫が敵に勝つ確率を表す<i>n</i> 個の実数が与えられる. <i>i</i> + 1 行目の<i>j</i> 個目の実数は, <i>j</i> 番の部屋の敵に勝つ確率を表している. 確率は小数点以下3 桁まで.
</p>
<H2>Output</H2>
<p>
ねこたちが待ち受けるすべての敵を倒せる確率が最大になるようにうまく順番を決めていくとき, その確率を答えよ. 出力は誤差を含んでいてもよいが, 真の値との誤差は10<sup>−9</sup> 以内にせよ.
</p>
<H2>Sample Input 1</H2>
<pre>
2 3
0.900 0.500 0.100
0.500 0.500 0.500
</pre>
<H2>Sample Output 1</H2>
<pre>
0.372500000000
</pre>
|
p03369 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs <var>700</var> yen (the currency of Japan), plus <var>100</var> yen for each kind of topping (boiled egg, sliced pork, green onions).</p>
<p>A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string <var>S</var>. <var>S</var> is three characters long, and if the first character in <var>S</var> is <code>o</code>, it means the ramen should be topped with boiled egg; if that character is <code>x</code>, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in <var>S</var> mean the presence or absence of sliced pork and green onions on top of the ramen.</p>
<p>Write a program that, when <var>S</var> is given, prints the price of the corresponding bowl of ramen.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is a string of length <var>3</var>.</li>
<li>Each character in <var>S</var> is <code>o</code> or <code>x</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the price of the bowl of ramen corresponding to <var>S</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>oxo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>900
</pre>
<p>The price of a ramen topped with two kinds of toppings, boiled egg and green onions, is <var>700 + 100 \times 2 = 900</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ooo
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000
</pre>
<p>The price of a ramen topped with all three kinds of toppings is <var>700 + 100 \times 3 = 1000</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>xxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>700
</pre>
<p>The price of a ramen without any toppings is <var>700</var> yen.</p></section>
</div>
</span> |
p01641 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: { inlineMath: [['\\(','\\)']] }
});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<h1 class="ndoc-heading1">Problem H: Brainf*ck</h1>
<p class="ndoc-top">
BさんはBrainf*ckが大好きで、学校で出された課題も全てBrainf*ckを使って提出している。
最近そんなBさんに洗脳され、先生が課題を解く言語をBrainf*ckに限定してしまった。</p>
<p class="ndoc-top">このままでは皆が単位を落としてしまう。
あなたは、Brainf*ckプログラムを生成するプログラムを作ることで、皆の単位を救い出す手伝いをすることにした。</p>
<p class="ndoc-top">
もちろん、Brainf*ckプログラムを生成するプログラムはBrainf*ckで記述する必要はない。</p>
<h2 class="ndoc-heading2">問題</h2>
<p class="ndoc-top">指定された文字列\( s \)を出力するBrainf*ckプログラムを生成せよ。</p>
<h3 class="ndoc-heading3">Brainf*ck言語仕様</h3>
<p class="ndoc-top">ジャッジで用いるBrainf*ckの言語仕様を記す。</p>
<p class="ndoc-top">Brainf*ckプログラムは文字列で記述される。
プログラム文字列は角括弧(<span style=
"font-family: monospace;">[</span>および<span style=
"font-family: monospace;">]</span>)の対応が取れている必要があるが、それ以外の制限はない。</p>
<p class="ndoc-top">
Brainf*ckプログラムが実行される時、バイト配列とその要素を指し示すポインターを持つ。バイト配列は無限の大きさを持ち、8bit非負整数の情報を保持することができる。
これをC言語で表すと次のようになる。</p>
<pre>
unsigned char memory[100000]; // バイト配列(実際にはもっと広大な領域を確保する)
unsigned char *ptr = memory; // バイト配列の要素を指し示すポインター
</pre>
<p class="ndoc-top">Brainf*ckでは1つの命令は1文字で表され、命令には以下の7種類がある。</p>
<style>
.brainfuck {
border-collapse: collapse;
border: solid 1px #999;
font-size: 100%;
}
.brainfuck th, .brainfuck td{
border: solid 1px #999;
padding: 4px 6px;
}
.brainfuck th {
background: #E6E6E6;
text-align: center;
color: #666;
}
</style>
<table class="brainfuck">
<thead>
<tr>
<th style="width: 2em;">
文字
</th>
<th>
意味
</th>
<th>
C言語での記述法
</th>
</tr>
</thead>
<tr>
<td>
<tt class="backtick">+</tt>
</td>
<td>
ポインターが示すバイト配列の要素の値を1増やす。値が255の時は0になる。
</td>
<td>
<tt class="backtick">(*ptr)++;</tt>
</td>
</tr>
<tr>
<td>
<tt class="backtick">-</tt>
</td>
<td>
ポインターが示すバイト配列の要素の値を1減らす。値が0の時は255になる。
</td>
<td>
<tt class="backtick">(*ptr)--;</tt>
</td>
</tr>
<tr>
<td>
<tt class="backtick">></tt>
</td>
<td>
ポインターが示すバイト配列の要素の位置を正に1ずらす。
</td>
<td>
<tt class="backtick">ptr++;</tt>
</td>
</tr>
<tr>
<td>
<tt class="backtick"><</tt>
</td>
<td>
ポインターが示すバイト配列の要素の位置を負に1ずらす。
</td>
<td>
<tt class="backtick">ptr--;</tt>
</td>
</tr>
<tr>
<td>
<tt class="backtick">[</tt>
</td>
<td>
ポインターが示すバイト配列の要素の値が0ならば、対応する<tt class=
"backtick">]</tt>に飛ぶ。そうでなければ次の命令に進む。
</td>
<td>
<tt class="backtick">while(*ptr) {</tt>
</td>
</tr>
<tr>
<td>
<tt class="backtick">]</tt>
</td>
<td>
ポインターが示すバイト配列の要素の値が0ならば、対応する<tt class="backtick">[</tt>に飛ぶ。そうでなければ次の命令に進む。
</td>
<td>
<tt class="backtick">} do while(*ptr);</tt>
</td>
</tr>
<tr>
<td>
<tt class="backtick">.</tt>
</td>
<td>
ポインターが示すバイト配列の要素の値をASCIIコードと見なし、文字を出力する。
</td>
<td>
<tt class="backtick">putchar(*ptr);</tt>
</td>
</tr>
</tbody>
</table>
<p class="ndoc-top">命令は先頭から順に実行され、命令を表す文字ではない文字はコメントとして無視される。</p>
<p class="ndoc-top">
以上のBrainf*ckの仕様はおおよそ一般に使われているBrainf*ckと同様なものなので、<a href=
"http://ja.wikipedia.org/wiki/Brainfuck">http://ja.wikipedia.org/wiki/Brainfuck</a>などを参考にすることができる。ただし、<a href="http://k-operafan.info/static/uecpc2013/files/brainfuck.c">ジャッジに用いるBrainf*ck</a>は、一文字入力命令を使用することはできないので注意すること。</p>
<h2 class="ndoc-heading2">入力</h2>
<p class="ndoc-top">1行に1000文字以内の文字列\( s \)が与えられる。</p>
<h2 class="ndoc-heading2">出力</h2>
<p class="ndoc-top">Brainf*ckコードを20000文字以内で出力せよ。実行結果が\( s
\)に一致した任意のプログラムがAcceptされる。</p>
<h2 class="ndoc-heading2">制約</h2>
<ul class="ndoc-indent">
<li>\( 1 \leq |s| \leq 1000 \)</li>
<li>\( s \)はASCII文字列</li>
<li>\( s \)にはASCIIコード33〜126の文字しか含まれない(記号、英字、数字のみで空白や制御文字を含まない)</li>
<li>出力したプログラムの長さは空白、改行、コメントを含めて\( 20000 \)文字までを許容する</li>
<li>命令は\( 10^7 \)回実行されるとストップする</li>
<li>Brainf*ckプログラムは最後に改行を出力してはならない</li>
</ul>
<h2 class="ndoc-heading2">入出力例</h2>
<h3 class="ndoc-heading3">入力1</h3>
<pre>
ABC
</pre>
<h3 class="ndoc-heading3">出力1</h3>
<pre>
++++++++[>++++++++<-]>+.+.+.
</pre>
<h3 class="ndoc-heading3">入力2</h3>
<pre>
HelloWorld!!
</pre>
<h3 class="ndoc-heading3">出力2</h3>
<pre>
+++++++++[>++++++++<-]>.<+++++[>+++++<-]>++++.+++++++..+++.[>+>+<<-]++++[>------<-]>.>.+++.--
----.--------.[-]++++++[>+++++<-]>+++..
</pre>
<p>入力に空白が含まれることはない。</p>
<h3 class="ndoc-heading3">入力3</h3>
<pre>
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</pre>
<h3 class="ndoc-heading3">出力3</h3>
<pre>
+++++++++++++++++++++++++++++++++.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+
.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.
</pre>
<p>このケースは33から126のASCIIコードを順番に並べたものである。</p> |
p00953 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem H
Animal Companion in Maze
</h2>
<p>
George, your pet monkey, has escaped, slipping the leash!
</p>
<p>
George is hopping around in a maze-like building with many rooms. The doors of the rooms, if any, lead directly to an adjacent room, not through corridors. Some of the doors, however, are one-way: they can be opened only from one of their two sides.
</p>
<p>
He repeats randomly picking a door he can open and moving to the room through it. You are chasing him but he is so quick that you cannot catch him easily. He never returns immediately to the room he just has come from through the same door, believing that you are behind him. If any other doors lead to the room he has just left, however, he may pick that door and go back.
</p>
<p>
If he cannot open any doors except one through which he came from, voila, you can catch him there eventually.
</p>
<p>
You know how rooms of the building are connected with doors, but you don't know in which room George currently is.
</p>
<p>
It takes one unit of time for George to move to an adjacent room through a door.
</p>
<p>
Write a program that computes how long it may take before George will be confined in a room. You have to find the longest time, considering all the possibilities of the room George is in initially, and all the possibilities of his choices of doors to go through.
</p>
<p>
Note that, depending on the room organization, George may have possibilities to continue hopping around forever without being caught.
</p>
<p>
Doors may be on the ceilings or the floors of rooms; the connection of the rooms may not be drawn as a planar graph.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case, in the following format.<br/>
<br/>
$n$ $m$<br/>
$x_1$ $y_1$ $w_1$<br/>
.<br/>
.<br/>
.<br/>
$x_m$ $y_m$ $w_m$<br/>
</p>
<p>
The first line contains two integers $n$ ($2 \leq n \leq 100000$) and $m$ ($1 \leq m \leq 100000$), the number of rooms and doors, respectively. Next $m$ lines contain the information of doors. The $i$-th line of these contains three integers $x_i$, $y_i$ and $w_i$ ($1 \leq x_i \leq n, 1 \leq y_i \leq n, x_i \ne y_i, w_i = 1$ or $2$), meaning that the $i$-th door connects two rooms numbered $x_i$ and $y_i$, and it is one-way from $x_i$ to $y_i$ if $w_i = 1$, two-way if $w_i = 2$.
</p>
<h3>Output</h3>
<p>
Output the maximum number of time units after which George will be confined in a room. If George has possibilities to continue hopping around forever, output "<span>Infinite</span>".
</p>
<h3>Sample Input 1</h3>
<pre>2 1
1 2 2</pre>
<h3>Sample Output 1</h3>
<pre>1</pre>
<br/>
<h3>Sample Input 2</h3>
<pre>2 2
1 2 1
2 1 1</pre>
<h3>Sample Output 2</h3>
<pre>Infinite</pre>
<br/>
<h3>Sample Input 3</h3>
<pre>6 7
1 3 2
3 2 1
3 5 1
3 6 2
4 3 1
4 6 1
5 2 1</pre>
<h3>Sample Output 3</h3>
<pre>4</pre>
<br/>
<h3>Sample Input 4</h3>
<pre>3 2
1 3 1
1 3 1</pre>
<h3>Sample Output 4</h3>
<pre>1</pre>
|
p03386 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Print all the integers that satisfies the following in ascending order:</p>
<ul>
<li>Among the integers between <var>A</var> and <var>B</var> (inclusive), it is either within the <var>K</var> smallest integers or within the <var>K</var> largest integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A \leq B \leq 10^9</var></li>
<li><var>1 \leq K \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print all the integers that satisfies the condition above in ascending order.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 8 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
4
7
8
</pre>
<ul>
<li><var>3</var> is the first smallest integer among the integers between <var>3</var> and <var>8</var>.</li>
<li><var>4</var> is the second smallest integer among the integers between <var>3</var> and <var>8</var>.</li>
<li><var>7</var> is the second largest integer among the integers between <var>3</var> and <var>8</var>.</li>
<li><var>8</var> is the first largest integer among the integers between <var>3</var> and <var>8</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 8 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
5
6
7
8
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 9 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
3
4
5
6
7
8
9
</pre></section>
</div>
</span> |
p01211 |
<H1><font color="#000">Problem E:</font> Spirograph</H1>
<p>
Some of you might have seen instruments like the figure below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_spirograph1">
<p>Figure 1: Spirograph</p>
</center>
<p>
There are a fixed circle (indicated by <i>A</i> in the figure) and a smaller interior circle with some
pinholes (indicated by <i>B</i>). By putting a pen point through one of the pinholes and then rolling
the circle <i>B</i> without slipping around the inside of the circle <i>A</i>, we can draw curves as illustrated
below. Such curves are called <i>hypotrochoids</i>.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_spirograph2">
<p>Figure 2: An Example Hypotrochoid</p>
</center>
<p>
Your task is to write a program that calculates the length of hypotrochoid, given the radius of
the fixed circle <i>A</i>, the radius of the interior circle <i>B</i>, and the distance between the <i>B</i>’s centroid and the used pinhole.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case is described by a single line in which
three integers <i>P</i>, <i>Q</i> and <i>R</i> appear in this order, where <i>P</i> is the radius of the fixed circle <i>A</i>, <i>Q</i>
is the radius of the interior circle <i>B</i>, and <i>R</i> is the distance between the centroid of the circle <i>B</i>
and the pinhole. You can assume that 0 ≤ <i>R</i> < <i>Q</i> < <i>P</i> ≤ 1000. <i>P</i>, <i>Q</i>, and <i>R</i> are separated by
a single space, while no other spaces appear in the input.
</p>
<p>
The end of input is indicated by a line with <i>P</i> = <i>Q</i> = <i>R</i> = 0.
</p>
<H2>Output</H2>
<p>
For each test case, output the length of the hypotrochoid curve. The error must be within
10<sup>-2</sup> (= 0.01).
</p>
<H2>Sample Input</H2>
<pre>
3 2 1
3 2 0
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
13.36
6.28
</pre>
|
p04013 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Tak has <var>N</var> cards. On the <var>i</var>-th <var>(1 \leq i \leq N)</var> card is written an integer <var>x_i</var>.
He is selecting one or more cards from these <var>N</var> cards, so that the average of the integers written on the selected cards is exactly <var>A</var>.
In how many ways can he make his selection?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>1 \leq A \leq 50</var></li>
<li><var>1 \leq x_i \leq 50</var></li>
<li><var>N,\,A,\,x_i</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded for passing the test set satisfying <var>1 \leq N \leq 16</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to select cards such that the average of the written integers is exactly <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 8
7 9 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<ul>
<li>The following are the <var>5</var> ways to select cards such that the average is <var>8</var>:<ul>
<li>Select the <var>3</var>-rd card.</li>
<li>Select the <var>1</var>-st and <var>2</var>-nd cards.</li>
<li>Select the <var>1</var>-st and <var>4</var>-th cards.</li>
<li>Select the <var>1</var>-st, <var>2</var>-nd and <var>3</var>-rd cards.</li>
<li>Select the <var>1</var>-st, <var>3</var>-rd and <var>4</var>-th cards.</li>
</ul>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 8
6 6 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8 5
3 6 2 8 7 6 5 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>19
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>8589934591
</pre>
<ul>
<li>The answer may not fit into a <var>32</var>-bit integer.</li>
</ul></section>
</div>
</span> |
p00050 |
<H1>りんごと桃</H1>
<p>
福島県は果物の産地としても有名で、その中でも特に桃とりんごは全国でも指折りの生産量を誇っています。ところで、ある販売用の英文パンフレットの印刷原稿を作ったところ、手違いでりんごに関する記述と桃に関する記述を逆に書いてしまいました。
</p>
<p>
あなたは、apple と peach を修正する仕事を任されましたが、なにぶん面倒です。1行の英文を入力して、そのなかの apple という文字列を全て peach に、peach という文字列を全てapple に交換した英文を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
英文(半角英数字、空白、記号を含む)が1行に与えられます。入力される文字列の長さは 1000 以下です。
</p>
<H2>Output</H2>
<p>
apple とpeach という文字列を交換した英文を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
the cost of one peach is higher than that of one apple.
</pre>
<H2>Output for the Sample Input</H2>
<pre>
the cost of one apple is higher than that of one peach.
</pre>
|
p02597 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An altar enshrines <var>N</var> stones arranged in a row from left to right. The color of the <var>i</var>-th stone from the left <var>(1 \leq i \leq N)</var> is given to you as a character <var>c_i</var>; <code>R</code> stands for red and <code>W</code> stands for white.</p>
<p>You can do the following two kinds of operations any number of times in any order:</p>
<ul>
<li>Choose two stones (not necessarily adjacent) and swap them.</li>
<li>Choose one stone and change its color (from red to white and vice versa).</li>
</ul>
<p>According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200000</var></li>
<li><var>c_i</var> is <code>R</code> or <code>W</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>c_{1}c_{2}...c_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the minimum number of operations needed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
WWRR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, the two operations below will achieve the objective.</p>
<ul>
<li>Swap the <var>1</var>-st and <var>3</var>-rd stones from the left, resulting in <code>RWWR</code>.</li>
<li>Change the color of the <var>4</var>-th stone from the left, resulting in <code>RWWW</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
RR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>It can be the case that no operation is needed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
WRWWRWRR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p00400 | <h1>アスキー文字</h1>
<p>
コンピュータの内部ではすべての情報が数値として扱われています。たとえば、アスキーコードでは、アルファベットの大文字Aに数値の65が割り当てられています。同様にアルファベットの大文字Bに66、Cに67というように、AからZには連続してそれぞれ65から90が割り当てられています。また、アスキーコードでは、アルファベットの小文字aに97が割り当てられています。同様にアルファベットの小文字bに98、cに99というように、aからzには連続してそれぞれ97から122が割り当てられています。
</p>
<p>
与えられたアスキーコードの数値が、アルファベットの大文字と小文字のどちらを表すか判定するプログラムを作成せよ。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>$N$
</pre>
<p>
1行に数値$N$ ($0 \leq N \leq 127$)が与えられる。
</p>
<h2>出力</h2>
<p>
大文字なら「1」を、小文字なら「2」を、それ以外なら「0」を1行に出力する。
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
67
</pre>
<h3>出力例1</h3>
<pre>
1
</pre>
<h3>入力例2</h3>
<pre>
110
</pre>
<h3>出力例2</h3>
<pre>
2
</pre>
<h3>入力例3</h3>
<pre>
32
</pre>
<h3>出力例3</h3>
<pre>
0
</pre>
|
p02313 |
<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>Area of Intersection between Two Circles</H1>
<p>
Write a program which prints the area of intersection between given circles $c1$ and $c2$.
</p>
<H2>Input</H2>
<p>
The input is given in the following format.
</p>
<p>
$c1x\; c1y\; c1r$ <br>
$c2x\; c2y\; c2r$ <br>
</p>
<p>
$c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers.
</p>
<H2>Output</H2>
<p>
Output the area in a line.
The output values should be in a decimal fraction with an error less than 0.000001.
</p>
<H2>Constraints</H2>
<ul>
<li>$-10,000 \leq c1x, c1y, c2x, c2y \leq 10,000$</li>
<li>$1 \leq c1r, c2r \leq 10,000$</li>
</ul>
<H2>Sample Input and Output</H2>
<br>
<H2>Sample Input 1</H2>
<pre>
0 0 1
2 0 2
</pre>
<H2>Sample Output 1</H2>
<pre>
1.40306643968573875104
</pre>
<br>
<H2>Sample Input 2</H2>
<pre>
1 0 1
0 0 3
</pre>
<H2>Sample Output 2</H2>
<pre>
3.14159265358979311600
</pre>
|
p00284 |
<h1>無限急行</h1>
<p>
ムゲン鉄道のムゲン線には無限個の駅があります。駅には …, -3, -2, -1, 0, 1, 2, 3, … と番号が振られていて、各駅は数直線上の整数と同じ順番で隣り合っています。あなたはいま、ある番号の駅から電車に乗り、それより大きな番号の駅に向かおうとしています。
</p>
<p>
ムゲン線には無限種類の快速電車が走っています。それらは 0 級快速、1 級快速、2 級快速、3 級快速、… のように番号で呼ばれています。<var>n</var> 級快速の電車は、2<var><sup>n</sup></var> の倍数の番号の駅に停車します。たとえば、1級快速は駅 …, -4, -2, 0, 2, 4, … に、3 級快速は駅 …, -24, -16, -8, 0, 8, 16, 24, … に停車するといった具合です。0 級快速はすべての駅に停車するので、本当は各駅停車ですがムゲン鉄道は「快速」と呼んでいます。
</p>
<p>
どの級の快速電車も、ある停車駅から次の停車駅まで移動するのに1単位時間かかります。また、快速電車間の乗り換えにかかる時間は無視できるものとします。乗車駅 <var>s</var> と降車駅 <var>d</var> が与えられたとき、<var>s</var> から <var>d</var> へ移動するのに必要な最小の時間を求めるプログラムを作成してください。ただし、<var>s</var> から <var>d</var> へ移動する間に、大きな番号から小さな番号の駅に向かっての移動は認められないものとします。
</p>
<h2>入力</h2>
<p>
入力は1つのデータセットからなる。入力データは以下の形式で与えられる。
</p>
<pre>
<var>N</var>
<var>s<sub>1</sub></var> <var>d<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>d<sub>2</sub></var>
:
<var>s<sub>N</sub></var> <var>d<sub>N</sub></var>
</pre>
<p>
1行目に移動の回数を表す <var>N</var> (1 ≤ <var>N</var> ≤ 100) が与えられる。続く <var>N</var> 行に、乗車駅の番号 <var>s<sub>i</sub></var> と降車駅の番号 <var>d<sub>i</sub></var> (-1,000,000,000 ≤ <var>s<sub>i</sub></var> < <var>d<sub>i</sub></var> ≤ 1,000,000,000) が与えられる。
</p>
<h2>出力</h2>
<p>
与えられた乗車駅と降車駅ごとに、移動に必要な最小の時間を1行に出力する。
</p>
<h2>入出力例</h2>
<h2>入力例</h2>
<pre>
3
0 7
-1048576 0
-3 5
</pre>
<h2>出力例</h2>
<pre>
3
1
4
</pre>
|
p03851 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino is about to compete in the final round of a certain programming competition.
In this contest, there are <var>N</var> problems, numbered <var>1</var> through <var>N</var>.
Joisino knows that it takes her <var>T_i</var> seconds to solve problem <var>i(1≦i≦N)</var>.</p>
<p>In this contest, a contestant will first select some number of problems to solve.
Then, the contestant will solve the selected problems.
After that, the score of the contestant will be calculated as follows:</p>
<ul>
<li>(The score) <var>=</var> (The number of the pairs of integers <var>L</var> and <var>R</var> <var>(1≦L≦R≦N)</var> such that for every <var>i</var> satisfying <var>L≦i≦R</var>, problem <var>i</var> is solved) - (The total number of seconds it takes for the contestant to solve the selected problems)</li>
</ul>
<p>Note that a contestant is allowed to choose to solve zero problems, in which case the score will be <var>0</var>.</p>
<p>Also, there are <var>M</var> kinds of drinks offered to the contestants, numbered <var>1</var> through <var>M</var>.
If Joisino takes drink <var>i(1≦i≦M)</var>, her brain will be stimulated and the time it takes for her to solve problem <var>P_i</var> will become <var>X_i</var> seconds.
Here, <var>X_i</var> may be greater than the length of time originally required to solve problem <var>P_i</var>.
Taking drink <var>i</var> does not affect the time required to solve the other problems.</p>
<p>A contestant is allowed to take exactly one of the drinks before the start of the contest.
For each drink, Joisino wants to know the maximum score that can be obtained in the contest if she takes that drink.
Your task is to write a program to calculate it instead of her.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1≦N≦3*10^5</var></li>
<li><var>1≦T_i≦10^9</var></li>
<li>(The sum of <var>T_i</var>) <var>≦10^{12}</var></li>
<li><var>1≦M≦3*10^5</var></li>
<li><var>1≦P_i≦N</var></li>
<li><var>1≦X_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>T_1</var> <var>T_2</var> <var>...</var> <var>T_N</var>
<var>M</var>
<var>P_1</var> <var>X_1</var>
<var>P_2</var> <var>X_2</var>
<var>:</var>
<var>P_M</var> <var>X_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each drink, print the maximum score that can be obtained if Joisino takes that drink, in order, one per line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 1 4 1 1
2
3 2
3 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
2
</pre>
<p>If she takes drink <var>1</var>, the maximum score can be obtained by solving all the problems.</p>
<p>If she takes drink <var>2</var>, the maximum score can be obtained by solving the problems <var>1,2,4</var> and <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>12
1 2 1 3 4 1 2 1 12 3 12 12
10
9 3
11 1
5 35
6 15
12 1
1 9
4 3
10 2
5 1
7 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>34
35
5
11
35
17
25
26
28
21
</pre></section>
</div>
</span> |
p02743 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Does <var>\sqrt{a} + \sqrt{b} < \sqrt{c}</var> hold?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a, b, c \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>a \ b \ c</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>\sqrt{a} + \sqrt{b} < \sqrt{c}</var>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>No
</pre>
<p><var>\sqrt{2} + \sqrt{3} < \sqrt{9}</var> does not hold.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
<p><var>\sqrt{2} + \sqrt{3} < \sqrt{10}</var> holds.</p></section>
</div>
</span> |
p03502 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>An integer <var>X</var> is called a Harshad number if <var>X</var> is divisible by <var>f(X)</var>, where <var>f(X)</var> is the sum of the digits in <var>X</var> when written in base <var>10</var>.</p>
<p>Given an integer <var>N</var>, determine whether it is a Harshad number.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1?N?10^8</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 <code>Yes</code> if <var>N</var> is a Harshad number; print <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><var>f(12)=1+2=3</var>. Since <var>12</var> is divisible by <var>3</var>, <var>12</var> is a Harshad number.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>57
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>f(57)=5+7=12</var>. Since <var>57</var> is not divisible by <var>12</var>, <var>12</var> is not a Harshad number.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>148
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p01495 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem J:
SolveMe
</h2>
<p>
$N$ 個の部屋があり, それぞれの部屋の床にはうさぎの絵が描かれている. あなたが部屋 $r$ のうさぎの絵の右耳の部分に乗ると, あなたは部屋 $A[r]$ に書かれたうさぎのしっぽの上にテレポートする. 同様に, 部屋 $r$ のうさぎの絵の左耳の部分に乗ると, 部屋 $B[r]$ に書かれたうさぎのしっぽの上にテレポートする.
</p>
<p>
整数 $X$, $Y$, $Z$ が与えられる. ねこは, 以下の条件を満たすようにテレポートを設定しようとしている. テレポートの $N^{2N}$ 通りの設定方法のうち, 条件を満たすものは何通りか, mod 1,000,000,007で求めよ.
</p>
<p>
条件: 任意の部屋 $r$ に対し, $r$ から右耳にちょうど $X$ 回乗り, 左耳にちょうど 1 回乗り, 右耳にちょうど $Y$ 回乗り, 左耳にちょうど 1 回乗り, 右耳にちょうど $Z$ 回乗ると, $r$ に戻る.
</p>
<h3>Constraints</h3>
<ul>
<li>$N$ will be between 1 and 1,000, inclusive.</li>
<li>$X$, $Y$, $Z$ will be between 0 and 1,000,000,000,000,000,000, inclusive.</li>
</ul>
<h3>Input</h3>
<p>
入力は以下の形式で与えられる:<br>
<br>
$N$ $X$ $Y$ $Z$
</p>
<h3>Output</h3>
<p>
テレポートの設定方法を 1,000,000,007 で割ったあまりを表す整数を 1 行に出力せよ.
</p>
<h3>Sample Input 1</h3>
<pre>3 1 0 1</pre>
<h3>Sample Output 1</h3>
<pre>18</pre>
<h3>Sample Input 2</h3>
<pre>5 8 5 8</pre>
<h3>Sample Output 2</h3>
<pre>120</pre> |
p03152 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider writing each of the integers from <var>1</var> to <var>N \times M</var> in a grid with <var>N</var> rows and <var>M</var> columns, without duplicates.
Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions:</p>
<ul>
<li>The largest among the values in the <var>i</var>-th row <var>(1 \leq i \leq N)</var> is <var>A_i</var>.</li>
<li>The largest among the values in the <var>j</var>-th column <var>(1 \leq j \leq M)</var> is <var>B_j</var>.</li>
</ul>
<p>For him, find the number of ways to write the numbers under these conditions, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>1 \leq M \leq 1000</var></li>
<li><var>1 \leq A_i \leq N \times M</var></li>
<li><var>1 \leq B_j \leq N \times M</var></li>
<li><var>A_i</var> and <var>B_j</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_{N}</var>
<var>B_1</var> <var>B_2</var> <var>...</var> <var>B_{M}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to write the numbers under the conditions, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
4 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p><var>(A_1, A_2) = (4, 3)</var> and <var>(B_1, B_2) = (3, 4)</var>. In this case, there are two ways to write the numbers, as follows:</p>
<ul>
<li><var>1</var> in <var>(1, 1)</var>, <var>4</var> in <var>(1, 2)</var>, <var>3</var> in <var>(2, 1)</var> and <var>2</var> in <var>(2, 2)</var>.</li>
<li><var>2</var> in <var>(1, 1)</var>, <var>4</var> in <var>(1, 2)</var>, <var>3</var> in <var>(2, 1)</var> and <var>1</var> in <var>(2, 2)</var>.</li>
</ul>
<p>Here, <var>(i, j)</var> denotes the square at the <var>i</var>-th row and the <var>j</var>-th column.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
5 9 7
3 6 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Since there is no way to write the numbers under the condition, <var>0</var> should be printed. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 2
4 4
4 4
</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>14 13
158 167 181 147 178 151 179 182 176 169 180 129 175 168
181 150 178 179 167 180 176 169 182 177 175 159 173
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>343772227
</pre></section>
</div>
</span> |
p03447 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You went shopping to buy cakes and donuts with <var>X</var> yen (the currency of Japan).</p>
<p>First, you bought one cake for <var>A</var> yen at a cake shop.
Then, you bought as many donuts as possible for <var>B</var> yen each, at a donut shop.</p>
<p>How much do you have left after shopping?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A, B \leq 1</var> <var>000</var></li>
<li><var>A + B \leq X \leq 10</var> <var>000</var></li>
<li><var>X</var>, <var>A</var> and <var>B</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
<var>A</var>
<var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount you have left after shopping.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1234
150
100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>84
</pre>
<p>You have <var>1234 - 150 = 1084</var> yen left after buying a cake.
With this amount, you can buy <var>10</var> donuts, after which you have <var>84</var> yen left.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000
108
108
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>28
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>579
123
456
</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>7477
549
593
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>405
</pre></section>
</div>
</span> |
p01180 |
<H1><font color="#000"></font>The Closest Circle</H1>
<p>
You are given <i>N</i> non-overlapping circles in xy-plane. The radius of each circle varies, but the radius of
the largest circle is not double longer than that of the smallest.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_closestCircle1">
<p>Figure 1: The Sample Input</p>
</center>
<p>
The distance between two circles <i>C</i><sub>1</sub> and <i>C</i><sub>2</sub> is given by the usual formula
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_closestCircle2">
</center>
<p>
where (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ) is the coordinates of the center of the circle <i>C<sub>i</sub></i>, and <i>r<sub>i</sub></i> is the radius of <i>C<sub>i</sub></i>, for <i>i</i> = 1, 2.
</p>
<p>
Your task is to write a program that finds the closest pair of circles and print their distance.
</p>
<H2>Input</H2>
<p>
The input consists of a series of test cases, followed by a single line only containing a single zero, which
indicates the end of input.
</p>
<p>
Each test case begins with a line containing an integer <i>N</i> (2 ≤ <i>N</i> ≤ 100000), which indicates the number
of circles in the test case. <i>N</i> lines describing the circles follow. Each of the <i>N</i> lines has three decimal
numbers <i>R</i>, <i>X</i>, and <i>Y</i>. R represents the radius of the circle. <i>X</i> and <i>Y</i> represent the <i>x</i>- and <i>y</i>-coordinates of
the center of the circle, respectively.
</p>
<H2>Output</H2>
<p>
For each test case, print the distance between the closest circles. You may print any number of digits
after the decimal point, but the error must not exceed 0.00001.
</p>
<H2>Sample Input</H2>
<pre>
4
1.0 0.0 0.0
1.5 0.0 3.0
2.0 4.0 0.0
1.0 3.0 4.0
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.5
</pre>
|
p03017 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares arranged in a row, numbered <var>1, 2, ..., N</var> from left to right.
You are given a string <var>S</var> of length <var>N</var> consisting of <code>.</code> and <code>#</code>. If the <var>i</var>-th character of <var>S</var> is <code>#</code>, Square <var>i</var> contains a rock; if the <var>i</var>-th character of <var>S</var> is <code>.</code>, Square <var>i</var> is empty.</p>
<p>In the beginning, Snuke stands on Square <var>A</var>, and Fnuke stands on Square <var>B</var>.</p>
<p>You can repeat the following operation any number of times:</p>
<ul>
<li>Choose Snuke or Fnuke, and make him jump one or two squares to the right. The destination must be one of the squares, and it must not contain a rock or the other person.</li>
</ul>
<p>You want to repeat this operation so that Snuke will stand on Square <var>C</var> and Fnuke will stand on Square <var>D</var>.</p>
<p>Determine whether this is possible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 \leq N \leq 200\ 000</var></li>
<li><var>S</var> is a string of length <var>N</var> consisting of <code>.</code> and <code>#</code>.</li>
<li><var>1 \leq A, B, C, D \leq N</var></li>
<li>Square <var>A</var>, <var>B</var>, <var>C</var> and <var>D</var> do not contain a rock.</li>
<li><var>A</var>, <var>B</var>, <var>C</var> and <var>D</var> are all different.</li>
<li><var>A < B</var></li>
<li><var>A < C</var></li>
<li><var>B < D</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</var> <var>B</var> <var>C</var> <var>D</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Yes</code> if the objective is achievable, and <code>No</code> if it is not.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 1 3 6 7
.#..#..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The objective is achievable by, for example, moving the two persons as follows. (<code>A</code> and <code>B</code> represent Snuke and Fnuke, respectively.)</p>
<pre>A#B.#..
A#.B#..
.#AB#..
.#A.#B.
.#.A#B.
.#.A#.B
.#..#AB
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 1 3 7 6
.#..#..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15 1 3 15 13
...#.#...#.#...
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p02256 |
<H1>Greatest Common Divisor</H1>
<p>
Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i>
</p>
<H2>Input</H2>
<p>
<i>a</i> and <i>b</i> are given in a line sparated by a single space.
</p>
<H2>Output</H2>
<p>
Output the greatest common divisor of <i>a</i> and <i>b</i>.
</p>
<H2>Constrants</H2>
<p>
1 ≤ <i>a</i>, <i>b</i> ≤ 10<sup>9</sup>
</p>
<H2>Hint</H2>
<p>
You can use the following observation:
</p>
<p>
For integers <i>x</i> and <i>y</i>, if <i>x</i> ≥ <i>y</i>, then gcd(<i>x</i>, <i>y</i>) = gcd(<i>y</i>, <i>x</i>%<i>y</i>)
</p>
<H2>Sample Input 1</H2>
<pre>
54 20
</pre>
<H2>Sample Output 1</H2>
<pre>
2
</pre>
<H2>Sample Input 2</H2>
<pre>
147 105
</pre>
<H2>Sample Output 2</H2>
<pre>
21
</pre>
|
p01883 |
<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>Parentheses</h2>
<p>
Dave loves strings consisting only of '(' and ')'. Especially, he is interested in balanced strings. Any balanced strings can be constructed using the following rules:
</p>
<ul>
<li> A string "()" is balanced.</li>
<li> Concatenation of two balanced strings are balanced.</li>
<li> If $T$ is a balanced string, concatenation of '(', $T$, and ')' in this order is balanced. For example, "()()" and "(()())" are balanced strings. ")(" and ")()(()" are not balanced strings.</li>
</ul>
<p>
Dave has a string consisting only of '(' and ')'. It satises the followings:
</p>
<ul>
<li> You can make it balanced by swapping adjacent characters exactly $A$ times. </li>
<li> For any non-negative integer $B$ ($B < A$), you cannot make it balanced by $B$ swaps of adjacent characters.</li>
<li> It is the shortest of all strings satisfying the above conditions.</li>
</ul>
<p>
Your task is to compute Dave's string. If there are multiple candidates, output the minimum in lexicographic order. As is the case with ASCII, '(' is less than ')'.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case, which contains an integer $A$ ($1 \leq A \leq 10^9$).
</p>
<h3>Output</h3>
<p>
Output Dave's string in one line. If there are multiple candidates, output the minimum in lexicographic order.
</p>
<h3>Sample Input 1</h3>
<pre>
1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
)(
</pre>
<p>
There are infinitely many strings which can be balanced by only one swap. Dave's string is the shortest of them.
</p>
<h3>Sample Input 2</h3>
<pre>
4
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
)())((
</pre>
<p>
String "))(()(" can be balanced by 4 swaps, but the output should be ")())((" because it is the minimum in lexicographic order.
</p>
|
p00791 |
<H1><font color="#000">Problem D:</font> Trapezoids</H1>
<p>
If you are a computer user, you should have seen pictures drawn with ASCII characters. Such a picture may not look as good as GIF or Postscript pictures, but is much easier to handle. ASCII pictures can easily be drawn using text editors, and can convey graphical information using only text-based media. Program s extracting information from such pictures may be useful.
</p>
<p>
We are interested in simple pictures of trapezoids, consisting only of asterisk('*') characters and blank spaces. A trapezoid (trapezium in the Queen's English) is a four-side polygon where at least one pair of its sides is parallel. Furthermore, the picture in this problem satisfies the following conditions.
</p>
<ol>
<li>All the asterisks in the picture belong to sides of some trapezoid.</li>
<li>Two sides of a trapezoid are horizontal and the other two are vertical or incline 45 degrees.</li>
<li>Every side is more than 2 characters long.</li>
<li>Two distinct trapezoids do not share any asterisk characters.</li>
<li>Sides of two trapezoids do not touch. That is, asterisks of one trapezoid do not appear in eight neighbors of asterisks of a different trapezoid. For example, the following arrangements never appear.</li>
</ol>
<pre>
**** | **** | ******
* * | * * *** | * *
**** | ******* * | ****
**** | *** | ****
* * | | * *
**** | | ****
</pre>
<p>
Some trapezoids may appear inside others. For example, the following is a valid picture.
</p>
<pre>
*********
* *
* *** *
* * * *
* ***** *
* *
*********
</pre>
<p>
Your task is to recognize trapezoids in the picture and to calculate the area of each trapezoid. The area of a trapezoid is the number of characters on or inside its four sides, including the areas of the trapezoids inside it, if any.
</p>
<H2>Input</H2>
<p>
The input contains several descriptions of pictures. Each of then starts with a line containing an integer <i>h</i> (1 ≤ <i>h</i> ≤ 1000), where <i>h</i> is the height (number of lines) of the picture. Each line of the picture consists only of asterisk and space characters, and contains less than 80 characters. The lines of the picture do not necessarily have the same length and may contain redundant space characters at the end. After the last picture, and integer zero terminates the input.
</p>
<H2>Output</H2>
<p>
For each picture, your program should produce output lines each containing two integers <i>m</i> and <i>n</i> is this order, which means there are <i>n</i> trapezoids of area <i>m</i> in the picture. output lines for one picture should be in ascending order on <i>m</i> and count all the trapezoids in the picture.
</p>
<p>
Output lines for two pictures should be separated by a line containing ten hyphen ('-') characters. This separator line should not appear before the output for the first picture nor after the output for the last.
</p>
<H2>Sample Input</H2>
<pre>
7
********
* *
* *** *
* * * *
* *** *
* *
********
9
***
* *
***** *****
* *
*** *****
* *
* *
***
11
**** *******************
* * ********* * *
****** * * **** * ********* *
* *** * * * * * * *
*** * * * * **** ******* * * *** *** * *
* * * ***** * * * * * * * * * * *
*** * * *** * * *** *** * *
********* * * * *
* ********************* *
* *
*****************************
0
</pre>
<p>
(Spacing between lines in pictures is made narrower for better appearance. Note that a blank line exists as the first line of the second picture.)
</p>
<H2>Output for the Sample Input</H2>
<pre>
9 1
56 1
----------
12 2
15 1
----------
9 3
12 2
15 2
63 1
105 1
264 1
</pre>
|
p03914 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> towns in Takahashi Kingdom. They are conveniently numbered <var>1</var> through <var>N</var>.</p>
<p>Takahashi the king is planning to go on a tour of inspection for <var>M</var> days. He will determine a sequence of towns <var>c</var>, and visit town <var>c_i</var> on the <var>i</var>-th day. That is, on the <var>i</var>-th day, he will travel from his current location to town <var>c_i</var>. If he is already at town <var>c_i</var>, he will stay at that town. His location just before the beginning of the tour is town <var>1</var>, the capital. The tour ends at town <var>c_M</var>, without getting back to the capital. </p>
<p>The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town <var>a</var> to town <var>b</var>, there will be a newly paved one-way road from town <var>a</var> to town <var>b</var>.</p>
<p>Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns <var>c</var> satisfy this condition?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦300</var></li>
<li><var>1≦M≦300</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of sequences of towns satisfying the condition, modulo <var>1000000007 (=10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>As shown below, the condition is satisfied only when <var>c = (2,3,1)</var> or <var>c = (3,2,1)</var>. Sequences such as <var>c = (2,3,2)</var>, <var>c = (2,1,3)</var>, <var>c = (1,2,2)</var> do not satisfy the condition.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/199a3fd8d2aed75750901a206c8b7e76.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>150 300
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>734286322
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>300 150
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01929 |
<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>
<h3>へやわり!</h3>
<p><i>N+1</i> 部屋が1列に並んだ新築の建物がある.各部屋はすべて1人用の住居であり,現在どの部屋も空室だが,来月から新たに <i>N</i> 人がここに住む予定である.したがって彼らが暮らし始めると1室は空き部屋になる.
</p>
<p>あなたは大家として,彼らの嗜好に合わせた部屋割りを多く提案したいと考えている.ここで部屋割りとは,それぞれの人がどの部屋に住むのかを与える表である.例えば <i>N = 3</i> のとき,「1人目は4号室,2人目は1号室,3人目は2号室」がありうる一つの部屋割りである.
</p>
<p>もちろん,ありうるすべての部屋割りを提案すれば話は早いが,それでは提案の意味がないため,大家の手間と住人の嗜好を考慮していくつか制約を設ける.
</p>
<p>まず,提案された部屋割りの一つに彼らが住み始めてから,「別の提案された部屋割りの方に変更したい」と言われるかもしれない.この建物は新築であり,彼らはまだ誰も入居していない新しい部屋が好みであることがわかっているので,単純に誰か1人が空き部屋へ引っ越しをするだけで提案された別の部屋割りに変更できるときに限りこれが起こりうる.しかし大家として,そういう面倒ごとは避けたいため,このような変更が許されないよう,提案する部屋割りをうまく調整したい.
つまり,提案する部屋割りの集合は次を満たさなければならない.
「任意の二つの異なる提案された部屋割り <i>A, B</i> に対して,部屋割り <i>A</i> の空き部屋に誰か1人を移しても部屋割り <i>B</i> にならない」
</p>
<p>次に,これから住む <i>N</i> 人にはそれぞれちょうど1人好ましい人がいることがわかっている.したがって,提案するすべての部屋割りは,すべての人に対して好ましい人が隣に住むような部屋割りにする.
</p>
<p>これらの条件を満たす部屋割りの集合で,最大の集合の大きさはいくらだろうか?<i>1,</sub>000,</sub>000,</sub>007</i> で割った余りを求めてほしい.
</p>
<h3>Input</h3>
<p>入力は複数のデータセットからなる.
各データセットは次の形式で表される.
</p><blockquote><i>N</i><br><i>a<sub>1</sub></i> <i>a<sub>2</sub> ... a<sub>N</sub></i><br></blockquote>
<p>データセットの 1 行目には,来月建物に住む人数を表す整数 <i>N</i> が与えられる.これは <i>2 ≤ N ≤ 100,</sub>000</i> を満たす.
2行目には <i>i</i> 番目の人にとって隣の部屋に住んでくれると好ましい人の番号 <i>a<sub>i</sub></i> の情報が与えられる.これについては <i>1 ≤ a<sub>i</sub> ≤ N</i> かつ <i>a<sub>i</sub> ≠ i</i> を満たす.
また,データセットの数は 50 を超えない.
入力の終わりは,1個のゼロだけからなる行で表される.
</p><blockquote></blockquote>
<h3>Output</h3>
<p>各データセットに対して,問題文にあるような,同時に提案できる部屋割りの数の最大値を,<i>1,</sub>000,</sub>000,</sub>007</i> で割った余りを1行で出力せよ.
</p>
<h3>Sample Input</h3>
<pre>2
2 1
3
3 1 2
10
2 1 1 1 1 1 1 1 1 1
8
2 1 4 3 3 7 6 6
25
2 3 2 5 4 5 8 7 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24
10
2 1 4 3 6 5 8 7 10 9
0
</pre>
<h3>Output for Sample Input</h3>
<pre>2
0
0
144
633544712
11520</pre> |
p02606 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>How many multiples of <var>d</var> are there among the integers between <var>L</var> and <var>R</var> (inclusive)?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq L \leq R \leq 100</var></li>
<li><var>1 \leq d \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>L</var> <var>R</var> <var>d</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of multiples of <var>d</var> among the integers between <var>L</var> and <var>R</var> (inclusive).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 10 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<ul>
<li>Among the integers between <var>5</var> and <var>10</var>, there are three multiples of <var>2</var>: <var>6</var>, <var>8</var>, and <var>10</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 20 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<ul>
<li>Among the integers between <var>6</var> and <var>20</var>, there are two multiples of <var>7</var>: <var>7</var> and <var>14</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100
</pre></section>
</div>
</span> |
p01303 |
<h1><font color="#000">Problem A:</font>ねこかわいがり</h1>
<p>
ある学園のキャンパス内には、多くのねこが住んでいる。なつめは、それらのねこをかわいがることを日課としている。
しかし、ねこ達は気まぐれで、キャンパスの外に散歩に出かけているかもしれない。
</p>
<p>
キャンパスの敷地は各辺が <var>x</var> 軸または <var>y</var> 軸に平行な長方形であり、門の部分を除いてフェンスで囲まれているが、ねこは門から自由に出入りできるし、また、フェンスを乗り越えて移動することもある。
</p>
<p>
ある日、なつめはキャンパス内にいるねこたちをなるべく平等にかわいがるために、キャンパス内に何匹のねこがいるのかを知りたいと考えた。
あなたの仕事は、座標平面上のキャンパスの位置とねこ達の座標が与えられたときに、キャンパス内にいるねこの数を求めることである。
ただし、フェンスの上を歩いているねこや、ちょうど門を通過中のねこもキャンパス内にいるとみなす。
</p>
<h2>Input</h2>
<p>
入力の1行目には、4つの整数 <var>X</var>, <var>Y</var>, <var>W</var>, <var>H</var> が、スペース文字で区切られて与えられる。これらはそれぞれ、キャンパスの南西端の <var>x</var> 座標、同地点の <var>y</var> 座標、キャンパスの東西方向の幅、およびキャンパスの南北方向の長さを表す。これらの値は、-10000 <= <var>X</var>, <var>Y</var> <= 10000 および 0 < <var>W</var>, <var>H</var> <= 10000 を満たす。
</p>
<p>
入力の2行目にはねこの数 <var>N</var> (0 < <var>N</var> <= 100) が与えられる。
</p>
<p>
続く <var>N</var> 行には、それぞれのねこについて1行に1匹ずつ、ねこの位置の <var>x</var>, <var>y</var> 座標を表す整数の組 (-50000 <= <var>x</var>, <var>y</var> <= 50000) が与えられる。
</p>
<p>
<var>x</var> 軸の正の方向は東、<var>y</var> 軸の正の方向は北であり、与えられる数値はすべて整数である。
</p>
<h2>Output</h2>
<p>
キャンパス内にいるねこの数を出力せよ。
</p>
<h2>Notes on Submission</h2>
<p>
上記形式で複数のデータセットが与えられます。入力データの 1 行目にデータセットの数が与えられます。各データセットに対する出力を上記形式で順番に出力するプログラムを作成して下さい。
</p>
<h2>Sample Input</h2>
<pre>
2
1 3 20 10
4
21 13
1 15
10 10
25 10
1 3 20 10
4
21 13
1 15
10 10
25 10
</pre>
<h2>Output for the Sample Input</h2>
<pre>
2
2
</pre>
|
p01753 |
<p>
西暦20XX 年,学校対抗魔法競技大会が開かれていた.大会もいよいよ,最終競技を残すのみとなった.あなたはその競技の選手の1 人である.
</p>
<p>
あなたが出場する競技は,空間内に配置された青いオブジェをすべて破壊するまでの時間を競うというものである.選手は競技用の銃の持込が許可されている.空間内には複数の青いオブジェと同じ数の赤いオブジェ,そして複数の障害物が配置されている.青いオブジェと赤いオブジェは1 対1 に対応しており,赤いオブジェが配置されている座標から青いオブジェに弾を撃つことで青いオブジェを破壊しなければならない.空間内に配置されている障害物は球状であり,少しずつ組成が異なっているが,通常の弾であれば障害物に触れると弾はその場に止まってしまう.
</p>
<p>
競技に使われる弾はMagic Bullet という特殊な弾である.この弾は魔力をため込むことができ,弾が障害物に接触した際に自動的に魔力を消費し,弾が貫通する魔法が発動する.障害物の組成の違いから,貫通するために必要な魔法やその発動のために消費する魔力の量は異なっている.このため,ある障害物に対する魔法が発動した後であっても,別の障害物を貫通するためには新たに別の魔法を発動する必要がある.また,弾が複数の障害物に同時に接触した場合は同時に魔法が発動する.弾に込められた魔力の量は魔法の発動のたびに減少する.
</p>
<p>
障害物の位置や大きさ,貫通する魔法の発動に必要な魔力の量はすでに公開されているのに対し,赤いオブジェ,青いオブジェの位置は公開されていない.しかし,過去の同一競技の情報から,ある程度オブジェの位置を予想することができた.魔力を弾にこめることは非常に体力を消耗してしまうため,あなたは魔力をできるだけ節約したいと考えた.そこで,赤いオブジェとそれに対応する青いオブジェの位置を仮定して,そのときに弾にこめるべき必要な魔力の最小量,つまり,青いオブジェに到達している時点で弾に残っている魔力が0 になる魔力の量を求めよう.
</p>
<h2>Input</h2>
<p>
入力はすべて整数である.それぞれの数は1 つの空白により区切られる.
</p>
<pre>
<var>N</var> <var>Q</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var> <var>r<sub>1</sub></var> <var>l<sub>1</sub></var>
:
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>z<sub>N</sub></var> <var>r<sub>N</sub></var> <var>l<sub>N</sub></var>
<var>sx<sub>1</sub></var> <var>sy<sub>1</sub></var> <var>sz<sub>1</sub></var> <var>dx<sub>1</sub></var> <var>dy<sub>1</sub></var> <var>dz<sub>1</sub></var>
:
<var>sx<sub>Q</sub></var> <var>sy<sub>Q</sub></var> <var>sz<sub>Q</sub></var> <var>dx<sub>Q</sub></var> <var>dy<sub>Q</sub></var> <var>dz<sub>Q</sub></var>
</pre>
<ul>
<li> <var>N</var> は障害物の個数であり,<var>Q</var> は仮定した青いオブジェと赤いオブジェの座標の組の個数である.</li>
<li> <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>, <var>z<sub>i</sub></var> はそれぞれ <var>i</var> 個目の障害物の中心の位置を表す <var>x</var> 座標,<var>y</var> 座標,<var>z</var> 座標である.</li>
<li> <var>r<sub>i</sub></var> は <var>i</var> 個目の障害物の半径である.</li>
<li> <var>l<sub>i</sub></var> は <var>i</var> 個目の障害物を貫通するための魔法で消費する魔力の量である.</li>
<li> <var>sx<sub>j</sub></var>, <var>sy<sub>j</sub></var>, <var>sz<sub>j</sub></var> はそれぞれ <var>j</var> 番目の仮定における赤いオブジェの位置を表す <var>x</var> 座標,<var>y</var> 座標,<var>z</var> 座標である.</li>
<li> <var>dx<sub>j</sub></var>, <var>dy<sub>j</sub></var>, <var>dz<sub>j</sub></var> はそれぞれ <var>j</var> 番目の仮定における青いオブジェの位置を表す <var>x</var> 座標,<var>y</var> 座標,<var>z</var> 座標である.</li>
</ul>
<h2>Constraints</h2>
<ul>
<li> 0 ≤ <var>N</var> ≤ 50 </li>
<li> 1 ≤ <var>Q</var> ≤ 50</li>
<li> -500 ≤ <var>x<sub>i</sub>, y<sub>i</sub>, z<sub>i</sub></var> ≤ 500</li>
<li> 1 ≤ <var>r<sub>i</sub></var> ≤ 1,000</li>
<li> 1 ≤ <var>l<sub>i</sub></var> ≤ 10<sup>16</sup></li>
<li> -500 ≤ <var>sx<sub>j</sub>, sy<sub>j</sub>, sz<sub>j</sub></var> ≤ 500</li>
<li> -500 ≤ <var>dx<sub>j</sub>, dy<sub>j</sub>, dz<sub>j</sub> ≤ 500</li>
<li> 障害物が他の障害物にめり込んでいることはない</li>
<li> オブジェの座標は障害物の内部,表面にはない</li>
<li> それぞれの仮定において,赤いオブジェと青いオブジェの座標は一致しない</li>
</ul>
<h2>Output</h2>
<p>
それぞれ1 組の赤いオブジェとそれに対応する青いオブジェの位置の仮定において,空間中に障害物と赤いオブジェと青いオブジェ1 対とのみがあるものとして,弾にこめるべき魔力の量を1 行に出力せよ.弾は赤いオブジェの位置から青いオブジェの位置まで一直線に飛ぶものとし,弾の大きさは非常に小さいので点として扱う.
</p>
<h2>Sample Input 1</h2>
<pre>
5 1
0 10 0 5 2
0 20 0 5 12
0 30 0 5 22
0 40 0 5 32
0 50 0 5 42
0 0 0 0 60 0
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>
110
</pre>
<h2>Sample Input 2</h2>
<pre>
1 1
10 5 0 5 9
0 0 0 9 12 0
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>
9
</pre>
<h2>Sample Input 3</h2>
<pre>
5 5
-38 -71 -293 75 1
-158 -38 -405 66 1
-236 -303 157 266 1
316 26 411 190 1
207 -312 -27 196 1
-50 292 -375 -401 389 -389
460 278 409 -329 -303 411
215 -220 -200 309 -474 300
261 -494 -87 -300 123 -463
386 378 486 -443 -64 299
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>
0
2
1
3
0
</pre> |
p00841 |
<H1><font color="#000">Problem F:</font> Atomic Car Race</H1>
<p>
In the year 2020, a race of atomically energized cars will be held. Unlike today’s car races, fueling
is not a concern of racing teams. Cars can run throughout the course without any refueling.
Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of
their cars.
</p>
<p>
The race is a road race having n checkpoints in the course. Their distances from the start are <i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, ... , and <i>a<sub>n</sub></i> (in kilometers). The <i>n</i>-th checkpoint is the goal. At the <i>i</i>-th checkpoint (<i>i</i> < <i>n</i>),
tires of a car can be changed. Of course, a team can choose whether to change or not to change
tires at each checkpoint. It takes <i>b</i> seconds to change tires (including overhead for braking and
accelerating). There is no time loss at a checkpoint if a team chooses not to change tires.
</p>
<p>
A car cannot run fast for a while after a tire change, because the temperature of tires is lower
than the designed optimum. After running long without any tire changes, on the other hand,
a car cannot run fast because worn tires cannot grip the road surface well. The time to run
an interval of one kilometer from <i>x</i> to <i>x</i> + 1 is given by the following expression (in seconds).
Here <i>x</i> is a nonnegative integer denoting the distance (in kilometers) from the latest checkpoint
where tires are changed (or the start). <i>r</i>, <i>v</i>, <i>e</i> and <i>f</i> are given constants.
</p>
<pre>
1/(<i>v</i> - <i>e</i> × (<i>x</i> - <i>r</i>)) (if <i>x</i> ≥ <i>r</i>)
1/(<i>v</i> - <i>f</i> × (<i>r</i> - <i>x</i>)) (if <i>x</i> < <i>r</i>)
</pre>
<p>
Your mission is to write a program to determine the best strategy of tire changes which minimizes
the total time to the goal.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets each corresponding to a race situation. The format of a
dataset is as follows.
</p>
<pre>
<i>n</i>
<i>a</i><sub>1</sub> <i>a</i><sub>2</sub> . . . <i>a<sub>n</sub></i>
<i>b</i>
<i>r v e f</i>
</pre>
<p>
The meaning of each of the input items is given in the problem statement. If an input line
contains two or more input items, they are separated by a space.
</p>
<p>
<i>n</i> is a positive integer not exceeding 100. Each of <i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, ... , and <i>a<sub>n</sub></i> is a positive integer satisfying 0 < <i>a</i><sub>1</sub> < <i>a</i><sub>2</sub> < . . . < <i>a<sub>n</sub></i> ≤ 10000. <i>b</i> is a positive decimal fraction not exceeding 100.0. <i>r</i> is a
nonnegative integer satisfying 0 ≤ <i>r</i> ≤ <i>a<sub>n</sub></i> - 1. Each of <i>v</i>, <i>e</i> and <i>f</i> is a positive decimal fraction.
You can assume that <i>v</i> - <i>e</i> × (<i>a<sub>n</sub></i> - 1 - <i>r</i>) ≥ 0.01 and <i>v</i> - <i>f</i> × <i>r</i> ≥ 0.01.
</p>
<p>
The end of the input is indicated by a line with a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset in the input, one line containing a decimal fraction should be output. The
decimal fraction should give the elapsed time at the goal (in seconds) when the best strategy is
taken. An output line should not contain extra characters such as spaces.
</p>
<p>
The answer should not have an error greater than 0.001. You may output any number of digits
after the decimal point, provided that the above accuracy condition is satisfied.
</p>
<H2>Sample Input</H2>
<pre>
2
2 3
1.0
1 1.0 0.1 0.3
5
5 10 15 20 25
0.15
1 1.0 0.04 0.5
10
1783 3640 3991 4623 5465 5481 6369 6533 6865 8425
4.172
72 59.4705 0.0052834 0.0611224
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3.5397
31.9249
168.6682
</pre>
|
p03294 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>N</var> positive integers <var>a_1, a_2, ..., a_N</var>.</p>
<p>For a non-negative integer <var>m</var>, let <var>f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N)</var>.</p>
<p>Here, <var>X\ mod\ Y</var> denotes the remainder of the division of <var>X</var> by <var>Y</var>.</p>
<p>Find the maximum value of <var>f</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 3000</var></li>
<li><var>2 \leq a_i \leq 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>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum value of <var>f</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 4 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p><var>f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10</var> is the maximum value of <var>f</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
7 46 11 20 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>90
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
994 518 941 851 647 2 581
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4527
</pre></section>
</div>
</span> |
p00512 |
<H1>問題 3 </H1>
<br/>
<p>
ある工場では,各営業所から製品生産の注文を受けている.
前日の注文をまとめて,各製品の生産合計を求めたい.
</p>
<p>
入力ファイルの1行目には注文データの数 n が書いてあり,
続く n 行には製品名と注文数が空白で区切られて書いてある.
製品名は5文字以内の英大文字で書かれている.
注文データには同じ製品が含まれていることもあり,順序はバラバラである.
</p>
<p>
この注文データの中に現れる同じ製品の注文数を合計し,
出力ファイルに製品名と合計を空白を区切り文字として出力しなさい.
ただし,製品名に次の順序を付けて,その順で出力すること.
</p>
<p>
順序:文字の長さの小さい順に,同じ長さのときは,前から比べて
最初に異なる文字のアルファベット順とする.
</p>
<p>
入力データにおける製品数,注文数とその合計のどれも10<sup>6</sup>以下である.
</p>
<p>
出力ファイルにおいては,
出力の最後の行にも改行コードを入れること.
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
5
A 20
B 20
A 20
AB 10
Z 10
</pre>
<h3>出力例1</h3>
<pre>
A 40
B 20
Z 10
AB 10
</pre>
<br>
<h3>入力例2</h3>
<pre>
5
AAA 20
ABA 20
AAA 20
AAB 20
AAA 20
</pre>
<h3>出力例2</h3>
<pre>
AAA 60
AAB 20
ABA 20
</pre>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00142 |
<h1>素数の性質</h1>
<p>
4 で割ると 3 あまる素数 <var>n</var> (11、19、23 など) には、面白い性質があります。1 以上 <var>n</var> 未満の自然数 (1, 2,... , <var>n</var> - 1) を 2 乗したものを <var>n</var> で割ったあまりを計算した結果を並べると、同じ数になるものがあるため、互いに異なった数の個数は、(<var>n</var> - 1)/2 になります。
</p>
<p>
この様にして得られた数の集合には、特別な性質があります。得られた数の集合から、互いに異なる 2 つ <var>a</var> と <var>b</var> を選んでその差を計算します。差が負になったときは、その差に <var>n</var> を足します。さらに結果が (<var>n</var> - 1)/2 より大きいときは、その差を <var>n</var> から引きます。
</p>
<p>
例えば、<var>n = 11</var> のとき 1 と 9 の差は、<var>1 − 9 = −8</var> → <var>−8 + n = −8 + 11 = 3</var> になります。9 と 1 の差も <var>9 −1 = 8</var> → <var>n − 8 = 11 − 8 = 3</var> で、同じ値 3 になります。この差は、円周上に 0, 1, ・・・, <var>n</var> - 1 を書いて、二つの数字の間の短い方の円弧を考えるとわかりやすくなります。(下図参照)
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_natureOfPrimeNumber1">
</center>
<br/>
<p>
こうして得られた数の「差」は、1, 2, . . ., (<var>n</var> - 1)/2 のいずれかであり、同じ回数出現します。
</p>
<p>
【例】 <var>n = 11</var> の時は、以下のようになります。
</p>
<ol>
<li> 1 から <var>n</var>-1 までの数を 2 乗したものを <var>n</var> で割った余りを計算します。
<pre>
1<sup>2</sup> = 1 → 1
2<sup>2</sup> = 4 → 4
3<sup>2</sup> = 9 → 9
4<sup>2</sup> = 16 → 5
5<sup>2</sup> = 25 → 3
6<sup>2</sup> = 36 → 3
7<sup>2</sup> = 49 → 5
8<sup>2</sup> = 64 → 9
9<sup>2</sup> = 81 → 4
10<sup>2</sup> = 100 → 1
</pre>
</li>
<li> <var>a</var>, <var>b</var> の「差」の計算<br><br>
<ol>
<li> 1 で得られた 1, 3, 4, 5, 9 について異なる数同士の差を計算します。</li>
<li> 計算結果が負の場合、<var>n</var> = 11 を加算します。</li>
<li> さらに、計算結果が (<var>n</var>-1)/2 = 5 より大きい場合 <var>n</var> = 11 から減算します。</li>
</ol>
</li>
<li>出現回数を求める<br>
<p>
計算結果 1, 2, 3, 4, 5 の出現回数をそれぞれ数え上げます。
</p>
</li>
</ol>
<p>
これらの計算結果から 1, 2, 3, 4, 5 の出現回数が 4 回であることがわかります。この性質は 4 で割ると 3 あまる素数特有の性質であり 4 で割ると 1 あまる素数ではこのようなことはおきません。このことを確認するため、10000 以下の奇数 <var>n</var> を入力とし、例題にあるような計算 (<var>n</var> で割ったあまりの 2 乗の差の頻度を求める)を実行し、その出現回数を出力するプログラムを作成してください。
</p>
<!--
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_natureOfPrimeNumber2"></td>
-->
<H2>Input</H2>
<p>
複数のデータセットが与えられます。各データセットとして1つの整数 <var>n</var> (<var>n</var> ≤ 10000) が1行に与えられます。入力は 0 を1つ含む行でおわります。
</p>
<H2>Output</H2>
<p>
各データセットについて、出現頻度を以下の形式で出力してください。
</p>
<pre>
剰余の平方の差が 1 である(<var>a, b</var>)の出現個数(整数)
剰余の平方の差が 2 である(<var>a, b</var>)の出現個数(整数)
:
:
剰余の平方の差が (<var>n</var>-1)/2 である(<var>a, b</var>)の出現個数(整数)
</pre>
<H2>Sample Input</H2>
<pre>
11
15
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
4
4
4
4
2
2
4
2
4
4
2
</pre>
|
p02190 | <h2>Set</h2>
<p>数列<var>a_1,a_2,..,a_N</var>が与えられます。</p>
<p>この数列に値は何種類ありますか。</p>
<h3>入力</h3>
<pre>
<var>N</var>
<var>a_1 a_2...a_N</var>
</pre>
<h3>出力</h3>
<p>数列の値の種類数を出力せよ。</p>
<h3>制約</h3>
<ul>
<li><var>1 \leq N \leq 10^5 </var></li>
<li><var>1 \leq a_i \leq 10^9</var></li>
</ul>
<h3>入力例</h3>
<pre>
6
8 6 9 1 2 1
</pre>
<h3>出力例</h3>
<pre>
5
</pre>
|
p00457 |
<H1> 連鎖 </H1>
<h2>問題</h2>
<p>
次のようなゲームがある.
</p>
<p>
あるキャラクターが縦 1 列に N 個並んでいる.これらのキャラクターの色は赤,青,黄のいずれかであり,初期状態で同じ色のキャラクターが4つ以上連続して並んでいることはない.プレーヤーは,ある位置のキャラクターを選び他の色に変更することができる.この操作により同じ色のキャラクターが4つ以上連続して並ぶとそれらのキャラクターは消滅する.キャラクターが消滅することにより新たに同じ色のキャラクターが4つ以上連続して並ぶとそれらのキャラクターも消滅し,同じ色のキャラクターが4つ以上連続して並んでいる箇所がなくなるまでこの連鎖は続く.このゲームの目的は,消滅しないで残っているキャラクター数をなるべく少なくすることである.
</p>
<p>
例えば,下図の左端の状態で,上から6番目のキャラクターの色を黄色から青に変更すると,青のキャラクターが5つ連続するので消滅し,最終的に3つのキャラクターが消滅せずに残る.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_chain">
</center>
<br>
<p>
初期状態における N 個のキャラクターの色の並びが与えられたとき, 1箇所だけキャラクターの色を変更した場合の,消滅しないで残っているキャラクター数の最小値 M を求めるプログラムを作成せよ.</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる.各データセットは以下の形式で与えられる.
</p>
<p>
1行目はキャラクター数 N (1 ≤ N ≤ 10000) だけからなる.続く N 行には 1, 2, 3 のいずれか1つの整数が書かれており, i + 1 行目 (1 ≤ i ≤ N) は初期状態における上から i 番目のキャラクターの色を表す(1 は赤を,2 は青を,3は黄を表す).
</p>
<p>
N が 0 のとき入力の終了を示す.データセットの数は 5 を超えない.
</p>
<h2>出力</h2>
<p>
データセットごとに, 消滅しないで残っているキャラクター数の最小値 M を1行に出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例</h3>
<pre>
12
3
2
1
1
2
3
2
2
2
1
1
3
12
3
2
1
1
2
3
2
1
3
2
1
3
0
</pre>
<h3>出力例</h3>
<pre>
3
12
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00007 |
<H1>Debt Hell</H1>
<p>
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week.
</p>
<p>
Write a program which computes the amount of the debt in <var>n</var> weeks.
</p>
<H2>Input</H2>
<p>
An integer <var>n</var> (0 ≤ <var>n</var> ≤ 100) is given in a line.
</p>
<H2>Output</H2>
<p>
Print the amout of the debt in a line.
</p>
<H2>Sample Input</H2>
<pre>
5
</pre>
<H2>Output for the Sample Input</H2>
<pre>
130000
</pre>
|
p04044 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha has a sequence of <var>N</var> strings <var>S_1, S_2, ..., S_N</var>. The length of each string is <var>L</var>.</p>
<p>She will concatenate all of the strings in some order, to produce a long string.</p>
<p>Among all strings that she can produce in this way, find the lexicographically smallest one.</p>
<p>Here, a string <var>s=s_1s_2s_3</var>...<var>s_n</var> is <em>lexicographically smaller</em> than another string <var>t=t_1t_2t_3</var>...<var>t_m</var> if and only if one of the following holds:
<ul>
<li>There exists an index <var>i(1≦i≦min(n,m))</var>, such that <var>s_j = t_j</var> for all indices <var>j(1≦j<i)</var>, and <var>s_i<t_i</var>.</li>
<li><var>s_i = t_i</var> for all integers <var>i(1≦i≦min(n,m))</var>, and <var>n<m</var>.</li>
</ul></p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ N, L ≦ 100</var></li>
<li>For each <var>i</var>, the length of <var>S_i</var> equals <var>L</var>.</li>
<li>For each <var>i</var>, <var>S_i</var> consists of lowercase 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>L</var>
<var>S_1</var>
<var>S_2</var>
:
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest string that Iroha can produce.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
dxx
axx
cxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>axxcxxdxx
</pre>
<p>The following order should be used: <code>axx</code>, <code>cxx</code>, <code>dxx</code>.</p></section>
</div>
</span> |
p03781 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a kangaroo at coordinate <var>0</var> on an infinite number line that runs from left to right, at time <var>0</var>.
During the period between time <var>i-1</var> and time <var>i</var>, the kangaroo can either stay at his position, or perform a jump of length exactly <var>i</var> to the left or to the right.
That is, if his coordinate at time <var>i-1</var> is <var>x</var>, he can be at coordinate <var>x-i</var>, <var>x</var> or <var>x+i</var> at time <var>i</var>.
The kangaroo's nest is at coordinate <var>X</var>, and he wants to travel to coordinate <var>X</var> as fast as possible.
Find the earliest possible time to reach coordinate <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>X</var> is an integer.</li>
<li><var>1≤X≤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>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the earliest possible time for the kangaroo to reach coordinate <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The kangaroo can reach his nest at time <var>3</var> by jumping to the right three times, which is the earliest possible time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>He can reach his nest at time <var>2</var> by staying at his position during the first second, and jumping to the right at the next second.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p02893 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are integers <var>N</var> and <var>X</var>. For each integer <var>k</var> between <var>0</var> and <var>X</var> (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo <var>998244353</var>.</p>
<ul>
<li>Let us repeat the following operation on the integer <var>k</var>. Operation: if the integer is currently odd, subtract <var>1</var> from it and divide it by <var>2</var>; otherwise, divide it by <var>2</var> and add <var>2^{N-1}</var> to it. How many operations need to be performed until <var>k</var> returns to its original value? (The answer is considered to be <var>0</var> if <var>k</var> never returns to its original value.)</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><var>0 \leq X < 2^N</var></li>
<li><var>X</var> is given in binary and has exactly <var>N</var> digits. (In case <var>X</var> has less than <var>N</var> digits, it is given with leading zeroes.)</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the answers to the questions for the integers between <var>0</var> and <var>X</var> (inclusive), modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>40
</pre>
<p>For example, for <var>k=3</var>, the operation changes <var>k</var> as follows: <var>1,0,4,6,7,3</var>. Therefore the answer for <var>k=3</var> is <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
110101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>616
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>30
001110011011011101010111011100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>549320998
</pre></section>
</div>
</span> |
p01246 |
<H1><font color="#000">Problem D:</font> Land Mark</H1>
<p>
<i>“Hey, what’s up? It’s already 30 minutes past eleven!”</i>
</p>
<p>
<i>“I’m so sorry, but actually I got lost. I have no idea where I am now at all and I got tired wandering around.
Please help!”</i>
</p>
<p>
- Today you came to the metropolis to play with your friend. But she didn’t show up at the appointed time.
What happened to her? After some uncomfortable minutes, finally you managed to get her on line, and have
been just notified that she’s been lost in the city.
</p>
<p>
You immediately told her not to move, and asked her what are around her to figure out where she is. She told
the names of some famous land marks, in the order where she caught in her sight while she made a full turn
counterclockwise without moving around.
</p>
<p>
Fortunately, today you have a map of the city. You located all the land marks she answered on the map, but want
to know in which district of the city she’s wandering.
</p>
<p>
Write a program to calculate the area where she can be found, as soon as you can!
</p>
<H2>Input</H2>
<p>
Each input case is given in the format below:
</p>
<pre>
<i>N</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
...
<i>x<sub>N</sub></i> <i>y<sub>N</sub></i>
<i>l</i><sub>1</sub> . . . <i>l<sub>N</sub></i>
</pre>
<p>
An integer <i>N</i> in the first line specifies the number of land marks she named (<i>N</i> ≤ 10). The following <i>N</i> lines
specify the x- and y-coordinates of the land marks in the city. Here you modeled the city as an unbounded two-
dimensional plane. All coordinate values are integers between 0 and 100, inclusive. The last line of a test case
specifies the order in which she found these land marks in a counterclockwise turn.
</p>
<p>
A single line containing zero indicates the end of input. This is not a part of the input and should not be processed.
</p>
<H2>Output</H2>
<p>
Your program should output one line for each test case.
</p>
<p>
The line should contain the case number followed by a single number which represents the area where she can be
found. The value should be printed with the fifth digit after the decimal point, and should not contain an absolute
error greater than 10<sup>-5</sup> .
</p>
<p>
If there is no possible area found under the given condition, output “No area” in a line, instead of a number. If
you cannot bound the area, output “Infinity”.
</p>
<H2>Sample Input</H2>
<pre>
8
1 0
2 0
3 1
3 2
2 3
1 3
0 2
0 1
1 2 3 4 5 6 7 8
8
1 0
2 0
3 1
3 2
2 3
1 3
0 2
0 1
4 3 2 1 8 7 6 5
4
0 0
1 0
1 1
0 1
1 2 3 4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 10.00000
Case 2: No area
Case 3: Infinity
</pre>
|
p01616 |
<h1>D: Statement Coverage / 命令網羅</h1>
<p>「うわっ!なんてひどいコードだ!」</p>
<p>古いソースコードを開きながら先輩が叫んでいる. また面倒な仕事が押し付けられそうだ…….</p>
<p>ソースコードにはめまいがしそうなほどたくさんの if 文が並んでいる.</p>
<pre>
if 条件文 1; 命令 1
if 条件文 2; 命令 2
if 条件文 3; 命令 3
...
</pre>
<p>どうやら制御の構造はそれほど複雑ではないらしい.</p>
<p>1 つの条件文には,変数と NOT 演算子 "~" ,そして AND "&" / OR "|" の 2 項演算子が現れる. 変数は真または偽を表し,変数名は1文字以上のアルファベットで表される. 演算の順序は NOT 演算子が優先だが,括弧で先に計算するよう順序を変えてもよい. 変数は 1 つもしくは 2 つ,2 項演算は高々 1 回,それ以外は何度でも現れて良い.</p>
<p>とりあえずコンパイルは通った. コードを修正する前にテストを書く必要がある. 今回頼まれたのは,このコードのテストケースを書く作業だ. テストケースの数は,全ての命令が 1 度以上実行されれば十分である. テストケースの数を見積もって, 1 つで済むようなら引き受けることにしよう.</p>
<div>
<h1>Input</h1>
<p>与えられる入力は以下のように表される.</p>
<div>
<div>
<em>N</em> <em>M</em>
</div>
<div>
<em>cond</em><sub>1</sub>;
</div>
<div>
<em>cond</em><sub>2</sub>;
</div>
<div>
...
</div>
<div>
<em>cond</em><sub><i>N</i></sub>;
</div>
</div>
<br/>
<p><em>N</em> ( 1 ≦ <em>N</em> ≦ 500 ) 行の条件文が現れ,条件文中には <em>M</em> ( 1 ≦ <em>M</em> ≦ 500 ) 種類の変数が存在する. 条件文 <em>cond</em><sub>i</sub> は最大 1000 文字である. また,変数名は10文字を超えない.</p>
</div>
<div>
<h1>Output</h1>
<p>作業を引き受けるなら accept,拒否するなら reject を 1 行出力せよ.</p>
</div>
<div>
<h1>Sample Input 1</h1>
<pre>
3 4
~~(~A|B);
~(~C&~D);
~(~A|~~D);
</pre>
</div>
<div>
<h1>Sample Output 1</h1>
<pre>
accept
</pre>
</div>
<div>
<h1>Sample Input 2</h1>
<pre>
2 1
var;
~var;
</pre>
</div>
<div>
<h1>Sample Output 2</h1>
<pre>
reject
</pre>
</div> |
p02939 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> consisting of lowercase English letters. Find the maximum positive integer <var>K</var> that satisfies the following condition:</p>
<ul>
<li>There exists a partition of <var>S</var> into <var>K</var> non-empty strings <var>S=S_1S_2...S_K</var> such that <var>S_i \neq S_{i+1}</var> (<var>1 \leq i \leq K-1</var>).</li>
</ul>
<p>Here <var>S_1S_2...S_K</var> represents the concatenation of <var>S_1,S_2,...,S_K</var> in this order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 2 \times 10^5</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum positive integer <var>K</var> that satisfies the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aabbaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>We can, for example, divide <var>S</var> into four strings <code>aa</code>, <code>b</code>, <code>ba</code>, and <code>a</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aaaccacabaababc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12
</pre></section>
</div>
</span> |
p00904 |
<H1><font color="#000">Problem A: </font> Ginkgo Numbers</H1>
<p>
We will define Ginkgo numbers and multiplication on Ginkgo numbers.
</p>
<p>
A <i>Ginkgo number</i> is a pair <<i>m</i>, <i>n</i>> where <i>m</i> and <i>n</i> are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers.
</p>
<p>
The multiplication on Ginkgo numbers is defined by <<i>m</i>, <i>n</i>> · <<i>x</i>, <i>y</i>> = <<i>mx</i> − <i>ny</i>, <i>my</i> + <i>nx</i>>. For example, <1, 1> · <-2, 1> = <-3,-1>.
</p>
<p>
A Ginkgo number <<i>m</i>, <i>n</i>> is called a divisor of a Ginkgo number <<i>p</i>, <i>q</i>> if there exists a Ginkgo number <<i>x</i>, <i>y</i>> such that <<i>m</i>, <i>n</i>> · <<i>x</i>, <i>y</i>> = <<i>p</i>, <i>q</i>>.
</p>
<p>
For any Ginkgo number <<i>m</i>, <i>n</i>>, Ginkgo numbers <1, 0>, <0, 1>, <-1, 0>, <0,-1>, <<i>m</i>, <i>n</i>>, <-<i>n</i>,<i>m</i>>, <-<i>m</i>,-<i>n</i>> and <<i>n</i>,-<i>m</i>> are divisors of <<i>m</i>, <i>n</i>>. If <i>m</i><sup>2</sup>+<i>n</i><sup>2</sup> > 1, these Ginkgo numbers are distinct. In other words, any Ginkgo number such that <i>m</i><sup>2</sup> + <i>n</i><sup>2</sup> > 1 has at least eight divisors.
</p>
<p>
A Ginkgo number <<i>m</i>, <i>n</i>> is called a prime if <i>m</i><sup>2</sup>+<i>n</i><sup>2</sup> > 1 and it has exactly eight divisors. Your mission is to check whether a given Ginkgo number is a prime or not.
</p>
<p>
The following two facts might be useful to check whether a Ginkgo number is a divisor of another Ginkgo number.
</p>
<ul>
<li> Suppose <i>m</i><sup>2</sup> + <i>n</i><sup>2</sup> > 0. Then, <<i>m</i>, <i>n</i>> is a divisor of <<i>p</i>, <i>q</i>> if and only if the integer <i>m</i><sup>2</sup> + <i>n</i><sup>2</sup> is a common divisor of <i>mp</i> + <i>nq</i> and <i>mq</i> − <i>np</i>.</li>
<li> If <<i>m</i>, <i>n</i>> · <<i>x</i>, <i>y</i>> = <<i>p</i>, <i>q</i>>, then (<i>m</i><sup>2</sup> + <i>n</i><sup>2</sup>)(<i>x</i><sup>2</sup> + <i>y</i><sup>2</sup>) = <i>p</i><sup>2</sup> + <i>q</i><sup>2</sup>.</li>
</ul>
<H2>Input</H2>
<p>
The first line of the input contains a single integer, which is the number of datasets.
</p>
<p>
The rest of the input is a sequence of datasets. Each dataset is a line containing two integers <i>m</i> and <i>n</i>, separated by a space. They designate the Ginkgo number <<i>m</i>, <i>n</i>>. You can assume 1 < <i>m</i><sup>2</sup> + <i>n</i><sup>2</sup> < 20000.
</p>
<H2>Output</H2>
<p>
For each dataset, output a character '<span>P</span>' in a line if the Ginkgo number is a prime. Output a character '<span>C</span>' in a line otherwise.
</p>
<H2>Sample Input</H2>
<pre>
8
10 0
0 2
-3 0
4 2
0 -13
-4 1
-2 -1
3 -1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
C
C
P
C
C
P
P
C
</pre> |
p01179 |
<H1><font color="#000">Problem I:</font> Cousin's Aunt</H1>
<p>
Sarah is a girl who likes reading books.
</p>
<p>
One day, she wondered about the relationship of a family in a mystery novel. The story said,
</p>
<ul>
<li>B is A’s father’s brother’s son, and</li>
<li>C is B’s aunt.</li>
</ul>
<p>
Then she asked herself, “So how many degrees of kinship are there between A and C?”
</p>
<p>
There are two possible relationships between B and C, that is, C is either B’s father’s sister or
B’s mother’s sister in the story. If C is B’s father’s sister, C is in the third degree of kinship to
A (A’s father’s sister). On the other hand, if C is B’s mother’s sister, C is in the fifth degree of
kinship to A (A’s father’s brother’s wife’s sister).
</p>
<p>
You are a friend of Sarah’s and good at programming. You can help her by writing a general
program to calculate the maximum and minimum degrees of kinship between A and C under
given relationship.
</p>
<p>
The relationship of A and C is represented by a sequence of the following basic relations: father,
mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson,
granddaughter, uncle, aunt, nephew, and niece. Here are some descriptions about these relations:
</p>
<ul>
<li><i>X</i>’s brother is equivalent to <i>X</i>’s father’s or mother’s son not identical to <i>X</i>.</li>
<li><i>X</i>’s grandfather is equivalent to <i>X</i>’s father’s or mother’s father.</li>
<li><i>X</i>’s grandson is equivalent to <i>X</i>’s son’s or daughter’s son.</li>
<li><i>X</i>’s uncle is equivalent to <i>X</i>’s father’s or mother’s brother.</li>
<li><i>X</i>’s nephew is equivalent to <i>X</i>’s brother’s or sister’s son.</li>
<li>Similar rules apply to sister, grandmother, granddaughter, aunt and niece.</li>
</ul>
<p>
In this problem, you can assume there are none of the following relations in the family: adoptions,
marriages between relatives (i.e. the family tree has no cycles), divorces, remarriages, bigamous
marriages and same-sex marriages.
</p>
<p>
The degree of kinship is defined as follows:
</p>
<ul>
<li> The distance from <i>X</i> to <i>X</i>’s father, <i>X</i>’s mother, <i>X</i>’s son or <i>X</i>’s daughter is one.</li>
<li> The distance from <i>X</i> to <i>X</i>’s husband or <i>X</i>’s wife is zero.</li>
<li> The degree of kinship between <i>X</i> and <i>Y</i> is equal to the shortest distance from <i>X</i> to <i>Y</i>
deduced from the above rules.</li>
</ul>
<H2>Input</H2>
<p>
The input contains multiple datasets. The first line consists of a positive integer that indicates
the number of datasets.
</p>
<p>
Each dataset is given by one line in the following format:
</p>
<pre>
C is A(’s <i>relation</i>)*
</pre>
<p>
Here, <i>relation</i> is one of the following:
</p>
<pre>
father, mother, son, daughter, husband, wife, brother,
sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, niece.
</pre>
<p>
An asterisk denotes zero or more occurance of portion surrounded by the parentheses. The
number of relations in each dataset is at most ten.
</p>
<H2>Output</H2>
<p>
For each dataset, print a line containing the maximum and minimum degrees of kinship separated
by exact one space. No extra characters are allowed of the output.
</p>
<H2>Sample Input</H2>
<pre>
7
C is A’s father’s brother’s son’s aunt
C is A’s mother’s brother’s son’s aunt
C is A’s son’s mother’s mother’s son
C is A’s aunt’s niece’s aunt’s niece
C is A’s father’s son’s brother
C is A’s son’s son’s mother
C is A
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5 3
5 1
2 2
6 0
2 0
1 1
0 0
</pre>
|
p03144 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> jewels, numbered <var>1</var> to <var>N</var>.
The color of these jewels are represented by integers between <var>1</var> and <var>K</var> (inclusive), and the color of Jewel <var>i</var> is <var>C_i</var>.
Also, these jewels have specified values, and the value of Jewel <var>i</var> is <var>V_i</var>.</p>
<p>Snuke would like to choose some of these jewels to exhibit.
Here, the set of the chosen jewels must satisfy the following condition:</p>
<ul>
<li>For each chosen jewel, there is at least one more jewel of the same color that is chosen.</li>
</ul>
<p>For each integer <var>x</var> such that <var>1 \leq x \leq N</var>, determine if it is possible to choose exactly <var>x</var> jewels, and if it is possible, find the maximum possible sum of the values of chosen jewels in that case.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq K \leq \lfloor N/2 \rfloor</var></li>
<li><var>1 \leq C_i \leq K</var></li>
<li><var>1 \leq V_i \leq 10^9</var></li>
<li>For each of the colors, there are at least two jewels of that color.</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>C_1</var> <var>V_1</var>
<var>C_2</var> <var>V_2</var>
<var>:</var>
<var>C_N</var> <var>V_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.
In the <var>i</var>-th line, if it is possible to choose exactly <var>i</var> jewels, print the maximum possible sum of the values of chosen jewels in that case, and print <var>-1</var> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
1 1
1 2
1 3
2 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-1
9
6
14
15
</pre>
<p>We cannot choose exactly one jewel.</p>
<p>When choosing exactly two jewels, the total value is maximized when Jewel <var>4</var> and <var>5</var> are chosen.</p>
<p>When choosing exactly three jewels, the total value is maximized when Jewel <var>1, 2</var> and <var>3</var> are chosen.</p>
<p>When choosing exactly four jewels, the total value is maximized when Jewel <var>2, 3, 4</var> and <var>5</var> are chosen.</p>
<p>When choosing exactly five jewels, the total value is maximized when Jewel <var>1, 2, 3, 4</var> and <var>5</var> are chosen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2
1 1
1 2
2 3
2 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
9
12
12
15
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8 4
3 2
2 3
4 5
1 7
3 11
4 13
1 17
2 19
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
24
-1
46
-1
64
-1
77
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>15 5
3 87
1 25
1 27
3 58
2 85
5 19
5 39
1 58
3 12
4 13
5 54
4 100
2 33
5 13
2 55
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>-1
145
173
285
318
398
431
491
524
576
609
634
653
666
678
</pre></section>
</div>
</span> |
p01483 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<h1> Elevator</h1>
<p>
Time Limit: 8 sec / Memory Limit: 64 MB
</p>
<h2> E: エレベータ</h2>
<p>
あなたの友人は,キリンのマークの引越業者でアルバイトをしている.
彼の仕事は,建物から荷物を運び出すことである.
</p>
<p>
今回,彼はある<i>n</i>階建てのビルからいくつかの荷物を運び出すことになった.
幸い,このビルにはエレベータが1つ備え付けられているため,
エレベータで荷物を運び出すことにした.
</p>
<p>
運び出すべき荷物は,各階に複数個あり,荷物毎に重さが異なる.
エレベータには,重量制限が設定されており,重さ<i>W</i>を超える荷物を載せることはできない.
エレベータは十分に広く,重量制限を満たすならば,どれだけ多くの荷物でも載せることができる.
</p>
<p>
エレベータは停止した階で荷物の搬入と搬出を行うことができる.
ベテランアルバイターである彼は,エレベータに乗らずに,階段で移動する.
エレベータに荷物を積み込んだ後,階段で次のエレベータの停止フロアに先回りし,荷物の搬入と搬出を行うのだ.
ベテランアルバイターの彼は,荷物の搬入と搬出を非常に高速に行うことができるので,各フロアでのエレベータの停止時間は,無視することができる.
よって,全ての荷物を1階に移動させるのに必要な時間は,エレベータの移動距離から容易に算出できる.
</p>
<p>
彼は,荷物をできるだけ早く1階に移動させたい.
彼はベテランアルバイターではあるが,どのような手順で各階での荷物の出し入れを行えばよいのか分からない.
そこで,彼は,友人であるあなたに助けを求めてきた.
</p>
<p>
あなたの仕事は,彼が全ての荷物を1階に移動させるために必要なエレベータの最小の移動距離を求めることである.
</p>
<h2> Input</h2>
<p>
入力は以下の形式で与えられる.
</p>
<pre>
<i>n m W</i>
1階の荷物の情報
...
<i>i</i> 階の荷物の情報
...
<i>n</i> 階の荷物の情報
</pre>
<p>
<i>i</i>階の荷物の情報は,以下の形式で与えられる.(1 <= <i>i</i> <= <i>n</i>)
</p>
<pre>
<i>k<sub>i</sub></i> <i>w<sub>1</sub></i> <i>w<sub>2</sub></i>, ..., <i>w<sub>j</sub></i>, ..., <i>w<sub>k<sub>i</sub></sub></i>
</pre>
<p>
入力の形式の各変数の意味は次の通りである.
</p>
<ul>
<li> <i>n</i> はフロア数(1 <= <i>n</i> <= 10000)</li>
<li> <i>m</i> はエレベータの初期位置(1 <= <i>m</i> <= n)</li>
<li> <i>W</i> はエレベータの重量制限(1 <= <i>W</i> <= 10000)</li>
<li> <i>k<sub>i</sub></i> は荷物の数(0 <= <i>k<sub>i</sub></i> <= 15, 1 <= <i>k<sub>1</sub></i> + <i>k<sub>2</sub></i> + ... + <i>k<sub>n</sub></i> <= 15)</li>
<li> <i>w<sub>j</sub></i> は荷物 <i>j</i> の重さ(1 <= <i>w<sub>j</sub></i> <= <i>W</i>)</li>
</ul>
<h2> Output</h2>
<p>
最小の移動距離を1行で出力せよ.
</p>
<h2> Sample Input 1</h2>
<pre>
3 3 2
1 1
2 1 1
3 1 1 1
</pre>
<h2> Sample Output 1</h2>
<pre>
8
</pre>
<h2> Sample Input 2</h2>
<pre>
3 3 10
0
2 4 5
3 3 3 5
</pre>
<h2> Sample Output 2</h2>
<pre>
6
</pre>
<h2> Sample Input 3</h2>
<pre>
3 3 100
5 3 4 5 6 7
0
0
</pre>
<h2> Sample Output 3</h2>
<pre>
0
</pre>
</body>
</html> |
p01529 |
<h1>J - 刺身</h1>
<h2>問題文</h2>
<p>
きつねのしえるは川で釣りをしていた.黒くて細長い魚を手に入れることができたので,その場で切り刻んで刺身にして食べることにした.
</p>
<p>
魚は体長が <var>N</var> センチメートルある.奇妙なことに,この魚は身体の部分ごとに密度が異なっていた.
魚の身体を頭から 1 センチメートルごとに区切って番号を <var>1, 2, ..., N</var> と付けるとき,身体の <var>i</var> 番目の部分の重みは <var>w_i</var> であった.
魚の <var>i</var> 番目から <var>j</var> 番目までの部分を <var>[i..j]</var> と表すことにする.
最初,しえるは魚の身体 <var>[0..N-1]</var> を 1 枚だけ持っていると見なせる.しえるはこれを切っていき最終的に <var>N</var> 個に分割された魚の身体 <var>[0..0], [1..1], ..., [N-1..N-1]</var> を得たい.
</p>
<p>
しえるは今野外におり,まな板などを持っていないので,次のようなアクロバティックな方法で魚の身体を切っていくことにした : まず,魚の身体を 1 枚取る.これを <var>[i..j]</var> とする.この魚の身体は長さが少なくとも 2 センチメートル以上でなければならない.すなわち, <var>j-i ≥ 1</var> でなければならない.次に,それを空中に投げる.そして日本刀を手に持ち,宙に舞う魚を真っ二つに切る.このとき,しえるは強靭な運動神経によって任意の位置でこの魚を切ることができるが,必ず 1 センチメートル区切りの位置で切るものとする.これにより,元の魚の身体 <var>[i..j]</var> を,任意の切断位置 <var>k (i ≤ k < j)</var> によって,<var>[i..k]</var> と <var>[k+1..j]</var> の 2 つに分割するのである.
このアクロバティックな方法で魚の身体を 2 つに切るとき,元の身体の重さ (=<var>w<sub>i</sub>+w<sub>i+1</sub>+...+w<sub>j</sub></var>) だけコストがかかる.
</p>
<p>
しえるは,魚のすべての部分を 1 センチメートル区切りに切るのにかかるコストの合計値を最小にしたい.
</p>
<h2>入力形式</h2>
<p>
入力は以下の形式で与えられる.
</p>
<pre><var>N</var>
<var>w<sub>1</sub></var> <var>w<sub>2</sub></var> ... <var>w<sub>N</sub></var>
</pre>
<p>
<var>N</var> は魚の体長である.<var>w<sub>i</sub></var> は魚の <var>i</var> 番目の部分の重さである.
</p>
<h2>出力形式</h2>
<p>
魚を <var>N</var> 個に切り分けるのにかかるコストの合計の最小値を出力せよ.
</p>
<h2>制約</h2>
<ul>
<li><var>2 ≤ N ≤ 4,000</var></li>
<li><var>1 ≤ w<sub>i</sub> ≤ 10<sup>10</sup></li>
<li>入力値はすべて整数である.</li>
</ul>
<p>この問題の判定には,3 点分のテストケースのグループが設定されている. このグループに含まれるテストケースは上記の制約に加えて下記の制約も満たす.</p>
<ul>
<li><var>1 ≤ N ≤ 100</var></li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
3
1 2 3
</pre>
<h3>出力例 1</h3>
<pre>
9
</pre>
<p>
まず,魚全体を 2 番目と 3 番目の部分の間で切る.これには 1+2+3 = 6 のコストがかかる.
次に,1 番目と 2 番目の部分の間で切る.これには 1+2=3 のコストがかかる.合計で 6+3=9 のコストがかかり,これが最善手である.
</p>
<h3>入力例 2</h3>
<pre>
6
9876543210 9876543210 9876543210 9876543210 9876543210 9876543210
</pre>
<h3>出力例 2</h3>
<pre>
158024691360
</pre>
<h3>入力例 3</h3>
<pre>
10
127 131 137 139 149 151 157 163 167 173
</pre>
<h3>出力例 3</h3>
<pre>
5016
</pre>
<hr>
<address>Writer: 楠本充</address>
<address>Tester: 花田裕一朗</address> |
p03514 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>2N</var> pots. The market price of the <var>i</var>-th pot <var>(1 ≤ i ≤ 2N)</var> is <var>p_i</var> yen (the currency of Japan).</p>
<p>Now, you and Lunlun the dachshund will alternately take one pot. You will go first, and we will continue until all the pots are taken by you or Lunlun. Since Lunlun does not know the market prices of the pots, she will always choose a pot randomly from the remaining pots with equal probability. You know this behavior of Lunlun, and the market prices of the pots.</p>
<p>Let the sum of the market prices of the pots you take be <var>S</var> yen. Your objective is to maximize the expected value of <var>S</var>. Find the expected value of <var>S</var> when the optimal strategy is adopted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 10^5</var></li>
<li><var>1 ≤ p_i ≤ 2 × 10^5</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var>
<var>:</var>
<var>p_{2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the expected value of <var>S</var> when the strategy to maximize the expected value of <var>S</var> is adopted. The output is considered correct if its absolute or relative error from the judge's output is at most <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
150000
108
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>150000.0
</pre>
<p>Naturally, you should choose the <var>150000</var> yen pot.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
50000
50000
100000
100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>183333.3333333333
</pre>
<p>First, you will take one of the <var>100000</var> yen pots. The other <var>100000</var> yen pot will become yours if it is not taken in Lunlun's next turn, with probability <var>2/3</var>. If it is taken, you will have to settle for a <var>50000</var> yen pot. Thus, the expected value of <var>S</var> when the optimal strategy is adopted is <var>2/3 × (100000 + 100000) + 1/3 × (100000 + 50000) = 183333.3333…</var></p></section>
</div>
</span> |
p02755 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the price of a product before tax such that, when the consumption tax rate is <var>8</var> percent and <var>10</var> percent, the amount of consumption tax levied on it is <var>A</var> yen and <var>B</var> yen, respectively. (Yen is the currency of Japan.)</p>
<p>Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer.</p>
<p>If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print <code>-1</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A \leq B \leq 100</var></li>
<li><var>A</var> and <var>B</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print <code>-1</code>.</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>25
</pre>
<p>If the price of a product before tax is <var>25</var> yen, the amount of consumption tax levied on it is:</p>
<ul>
<li>When the consumption tax rate is <var>8</var> percent: <var>\lfloor 25 \times 0.08 \rfloor = \lfloor 2 \rfloor = 2</var> yen.</li>
<li>When the consumption tax rate is <var>10</var> percent: <var>\lfloor 25 \times 0.1 \rfloor = \lfloor 2.5 \rfloor = 2</var> yen.</li>
</ul>
<p>Thus, the price of <var>25</var> yen satisfies the condition. There are other possible prices, such as <var>26</var> yen, but print the minimum such price, <var>25</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
<p>If the price of a product before tax is <var>100</var> yen, the amount of consumption tax levied on it is:</p>
<ul>
<li>When the consumption tax rate is <var>8</var> percent: <var>\lfloor 100 \times 0.08 \rfloor = 8</var> yen.</li>
<li>When the consumption tax rate is <var>10</var> percent: <var>\lfloor 100 \times 0.1 \rfloor = 10</var> yen.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>19 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>There is no price before tax satisfying this condition, so print <code>-1</code>.</p></section>
</div>
</span> |
p00768 |
<h3>ICPC Ranking</h3>
<p>
Your mission in this problem is to write a program
which, given the submission log of an ICPC (International Collegiate Programming Contest),
determines team rankings.
</p>
<p>
The log is a sequence of records of program submission
in the order of submission.
A record has four fields: elapsed time, team number,
problem number, and judgment.
The elapsed time is the time elapsed from the beginning of the contest
to the submission.
The judgment field tells whether the submitted program was
correct or incorrect, and when incorrect,
what kind of an error was found.
</p>
<p>
The team ranking is determined according to the following rules.
Note that the rule set shown here is one used in the real ICPC World Finals and Regionals,
with some detail rules omitted for simplification.
</p>
<ol>
<li>
Teams that solved more problems are ranked higher.
</li>
<li>
Among teams that solve the same number of problems,
ones with smaller total consumed time are ranked higher.
</li>
<li>
If two or more teams solved the same number of problems, and their
total consumed times are the same, they are ranked the same.
</li>
</ol>
<p>
The total consumed time is the sum of the consumed time for each problem solved.
The consumed time for a solved problem is the elapsed time
of the accepted submission plus 20 penalty minutes for every previously rejected submission for that problem.
</p>
<p>
If a team did not solve a problem, the consumed time for the problem is zero, and thus even if there are several incorrect submissions, no penalty is given.
</p>
<p>
You can assume that a team never submits a program for a problem
after the correct submission for the same problem.
</p>
<h3>Input</h3>
<p>
The input is a sequence of datasets each in the following format.
The last dataset is followed by a line with four zeros.
</p>
<blockquote>
<i>M</i> <i>T</i> <i>P</i> <i>R</i> <br>
<i>m</i><sub>1</sub> <i>t</i><sub>1</sub> <i>p</i><sub>1</sub> <i>j</i><sub>1</sub> <br>
<i>m</i><sub>2</sub> <i>t</i><sub>2</sub> <i>p</i><sub>2</sub> <i>j</i><sub>2</sub> <br>
..... <br>
<i>m<sub>R</sub></i> <i>t<sub>R</sub></i> <i>p<sub>R</sub></i> <i>j<sub>R</sub></i> <br>
</blockquote>
<p>
The first line of a dataset contains four integers
<i>M</i>, <i>T</i>, <i>P</i>, and <i>R</i>.
<i>M</i> is the duration of the contest.
<i>T</i> is the number of teams.
<i>P</i> is the number of problems.
<i>R</i> is the number of submission records.
The relations
120 ≤ <i>M</i> ≤ 300,
1 ≤ <i>T</i> ≤ 50,
1 ≤ <i>P</i> ≤ 10,
and 0 ≤ <i>R</i> ≤ 2000
hold for these values.
Each team is assigned a team number between 1 and <i>T</i>, inclusive.
Each problem is assigned a problem number between 1 and <i>P</i>, inclusive.
</p>
<p>
Each of the following <i>R</i> lines contains a submission record
with four integers
<i>m<sub>k</sub></i>, <i>t<sub>k</sub></i>,
<i>p<sub>k</sub></i>, and <i>j<sub>k</sub></i>
(1 ≤ <i>k</i> ≤ <i>R</i>).
<i>m<sub>k</sub></i> is the elapsed time.
<i>t<sub>k</sub></i> is the team number.
<i>p<sub>k</sub></i> is the problem number.
<i>j<sub>k</sub></i> is the judgment
(0 means correct, and other values mean incorrect).
The relations
0 ≤ <i>m<sub>k</sub></i> ≤ <i>M</i>−1,
1 ≤ <i>t<sub>k</sub></i> ≤ <i>T</i>,
1 ≤ <i>p<sub>k</sub></i> ≤ <i>P</i>,
and 0 ≤ <i>j<sub>k</sub></i> ≤ 10
hold for these values.
</p>
<p>
The elapsed time fields are rounded off to the nearest minute.
</p>
<p>
Submission records are given in the order of submission.
Therefore, if <i>i</i> < <i>j</i>,
the <i>i</i>-th submission is done before the <i>j</i>-th submission
(<i>m<sub>i</sub></i> ≤ <i>m<sub>j</sub></i>).
In some cases, you can determine the ranking of two teams
with a difference less than a minute, by using this fact.
However, such a fact is never used in the team ranking.
Teams are ranked only using time information in minutes.
</p>
<h3>Output</h3>
<p>
For each dataset, your program should output team numbers (from 1 to <i>T</i>),
higher ranked teams first.
The separator between two team numbers should be a comma.
When two teams are ranked the same, the separator between them
should be an equal sign.
Teams ranked the same should be listed
in decreasing order of their team numbers.
</p>
<h3>Sample Input</h3>
<pre>
300 10 8 5
50 5 2 1
70 5 2 0
75 1 1 0
100 3 1 0
150 3 2 0
240 5 5 7
50 1 1 0
60 2 2 0
70 2 3 0
90 1 3 0
120 3 5 0
140 4 1 0
150 2 4 1
180 3 5 4
15 2 2 1
20 2 2 1
25 2 2 0
60 1 1 0
120 5 5 4
15 5 4 1
20 5 4 0
40 1 1 0
40 2 2 0
120 2 3 4
30 1 1 0
40 2 1 0
50 2 2 0
60 1 2 0
120 3 3 2
0 1 1 0
1 2 2 0
300 5 8 0
0 0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
3,1,5,10=9=8=7=6=4=2
2,1,3,4,5
1,2,3
5=2=1,4=3
2=1
1,2,3
5=4=3=2=1
</pre>
|
p03847 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a positive integer <var>N</var>.
Find the number of the pairs of integers <var>u</var> and <var>v</var> <var>(0≦u,v≦N)</var> such that there exist two non-negative integers <var>a</var> and <var>b</var> satisfying <var>a</var> <var>xor</var> <var>b=u</var> and <var>a+b=v</var>.
Here, <var>xor</var> denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N≦10^{18}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible pairs of integers <var>u</var> and <var>v</var>, modulo <var>10^9+7</var>.</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>5
</pre>
<p>The five possible pairs of <var>u</var> and <var>v</var> are:</p>
<ul>
<li>
<p><var>u=0,v=0</var> (Let <var>a=0,b=0</var>, then <var>0</var> <var>xor</var> <var>0=0</var>, <var>0+0=0</var>.)</p>
</li>
<li>
<p><var>u=0,v=2</var> (Let <var>a=1,b=1</var>, then <var>1</var> <var>xor</var> <var>1=0</var>, <var>1+1=2</var>.)</p>
</li>
<li>
<p><var>u=1,v=1</var> (Let <var>a=1,b=0</var>, then <var>1</var> <var>xor</var> <var>0=1</var>, <var>1+0=1</var>.)</p>
</li>
<li>
<p><var>u=2,v=2</var> (Let <var>a=2,b=0</var>, then <var>2</var> <var>xor</var> <var>0=2</var>, <var>2+0=2</var>.)</p>
</li>
<li>
<p><var>u=3,v=3</var> (Let <var>a=3,b=0</var>, then <var>3</var> <var>xor</var> <var>0=3</var>, <var>3+0=3</var>.)</p>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1422
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>52277
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000000000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>787014179
</pre></section>
</div>
</span> |
p00292 |
<h1>残り物には福がある</h2>
<p>
<var>K</var> 個の石から、<var>P</var> 人が順番に1つずつ石を取るゲームがあります。<var>P</var> 人目が石を取った時点で、まだ石が残っていれば、また1人目から順番に1つずつ石を取っていきます。このゲームでは、最後の石を取った人が勝ちとなります。<var>K</var> と<var>P</var> が与えられたとき、何人目が勝つか判定するプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var>
<var>K</var><sub>1</sub> <var>P</var><sub>1</sub></var>
<var>K</var><sub>2</sub> <var>P</var><sub>2</sub></var>
:
<var>K<sub>N</sub></var> <var>P<sub>N</sub></var>
</pre>
<p>
1行目にはゲームを行う回数 <var>N</var> (1 ≤ <var>N</var> ≤ 100) が与えられる。続く <var>N</var> 行に、<var>i</var> 回目のゲームにおける石の個数 <var>K<sub>i</sub></var> (2 ≤ <var>K<sub>i</sub></var> ≤ 1000) と、ゲームに参加する人数 <var>P<sub>i</sub></var> (2 ≤ <var>P<sub>i</sub></var> ≤ 1000) が与えられる。
</p>
<h2>出力</h2>
<p>
それぞれのゲームについて、何人目が勝つかを1行に出力する。
</p>
<h2>入出力例</h2>
<br>
<h2>入力例</h2>
<pre>
3
10 3
2 10
4 2
</pre>
<h2> 出力例</h2>
<pre>
1
2
2
</pre>
|
p02305 |
<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>Intersection of Circles</H1>
<p>
For given two circles $c1$ and $c2$, print
</p>
<pre>
4
</pre>
<p>
if they do not cross (there are 4 common tangent lines),
</p>
<pre>
3
</pre>
<p>
if they are circumscribed (there are 3 common tangent lines),
</p>
<pre>
2
</pre>
<p>
if they intersect (there are 2 common tangent lines),
</p>
<pre>
1
</pre>
<p>
if a circle is inscribed in another (there are 1 common tangent line),
</p>
<pre>
0
</pre>
<p>
if a circle includes another (there is no common tangent line).
</p>
<H2>Input</H2>
<p>
Coordinates and radii of $c1$ and $c2$ are given in the following format.
</p>
<p>
$c1x \; c1y \; c1r$ <br>
$c2x \; c2y \; c2r$
</p>
<p>
$c1x$, $c1y$ and $c1r$ represent the center coordinate and radius of the first circle.
$c2x$, $c2y$ and $c2r$ represent the center coordinate and radius of the second circle.
All input values are given in integers.
</p>
<H2>Output</H2>
<p>
Print "4", "3", "2", "1" or "0" in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>$-1,000 \leq c1x, c1y, c2x, c2y \leq 1,000$</li>
<li>$1 \leq c1r, c2r \leq 1,000$</li>
<li>$c1$ and $c2$ are different</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
1 1 1
6 2 2
</pre>
<H2>Sample Output 1</H2>
<pre>
4
</pre>
<H2>Sample Input 2</H2>
<pre>
1 2 1
4 2 2
</pre>
<H2>Sample Output 2</H2>
<pre>
3
</pre>
<H2>Sample Input 3</H2>
<pre>
1 2 1
3 2 2
</pre>
<H2>Sample Output 3</H2>
<pre>
2
</pre>
<H2>Sample Input 4</H2>
<pre>
0 0 1
1 0 2
</pre>
<H2>Sample Output 4</H2>
<pre>
1
</pre>
<H2>Sample Input 5</H2>
<pre>
0 0 1
0 0 2
</pre>
<H2>Sample Output 5</H2>
<pre>
0
</pre>
|
p00338 |
<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>プログラミングコンテスト II</H1>
<p>
白虎大学では毎年プログラミングコンテストを開催しています。コンテストは全てのチームの得点が 0の状態から開始し、解答状況に応じて得点が加算されていきます。このコンテストでは、得点の高い順に順位付けが行われます。チームの総数を <var>N</var> としたとき、チームには 1 から <var>N</var> の番号がそれぞれ割り当てられています。得点が同じ場合は番号がより小さい方が上位になります。
</p>
<p>
白虎大学では、コンテストを盛り上げるために観戦用のランキングシステムを開発しています。開発チームの一員であるあなたは、このシステムの一部であるプログラムの作成を任されています。
</p>
<p>
与えられた命令に従って、得点の更新と、指定された順位のチームの番号と得点を報告するプログラムを作成せよ。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var> <var>C</var>
<var>command<sub>1</sub></var>
<var>command<sub>2</sub></var>
:
<var>command<sub>C</sub></var>
</pre>
<p>
1行目にチーム数 <var>N</var> (2 ≤ <var>N</var> ≤ 100000) と命令の数 <var>C</var> (1 ≤ <var>C</var> ≤ 100000)が与えられる。続く <var>C</var> 行に、1行ずつ命令が与えられる。各命令は以下の形式で与えられる。
</p>
<pre>
0 <var>t</var> <var>p</var>
</pre>
<p>
または
</p>
<pre>
1 <var>m</var>
</pre>
<p>
最初の数字が0のとき更新命令、1のとき報告命令を表す。更新命令では指定された番号 <var>t</var> (1 ≤ <var>t</var> ≤ <var>N</var>) のチームに、整数で与えられる得点 <var>p</var> (1 ≤ <var>p</var> ≤ 10<sup>9</sup>) を加算する。報告命令では指定された順位 <var>m</var> (1 ≤ <var>m</var> ≤ <var>N</var>) のチームの番号と得点を報告する。ただし、報告命令は少なくとも1回現れるものとする。
</p>
<h2>Output</h2>
<p>
各報告命令に対して、指定された順位のチームの番号と得点を空白区切りで1行に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
3 11
0 2 5
0 1 5
0 3 4
1 1
1 2
1 3
0 3 2
1 1
0 2 1
1 2
1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1 5
2 5
3 4
3 6
3 6
1 5
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 2
1 1
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
1 0
2 0
</pre> |
p02610 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> camels numbered <var>1,2,\ldots,N</var>.
Snuke has decided to make them line up in a row.</p>
<p>The happiness of Camel <var>i</var> will be <var>L_i</var> if it is among the <var>K_i</var> frontmost camels, and <var>R_i</var> otherwise.</p>
<p>Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel.</p>
<p>Solve this problem for each of the <var>T</var> test cases given.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq T \leq 10^5</var></li>
<li><var>1 \leq N \leq 2 \times 10^{5}</var></li>
<li><var>1 \leq K_i \leq N</var></li>
<li><var>1 \leq L_i, R_i \leq 10^9</var></li>
<li>The sum of values of <var>N</var> in each input file is at most <var>2 \times 10^5</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>T</var>
<var>\mathrm{case}_1</var>
<var>\vdots</var>
<var>\mathrm{case}_T</var>
</pre>
<p>Each case is given in the following format:</p>
<pre><var>N</var>
<var>K_1</var> <var>L_1</var> <var>R_1</var>
<var>\vdots</var>
<var>K_N</var> <var>L_N</var> <var>R_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>T</var> lines. The <var>i</var>-th line should contain the answer to the <var>i</var>-th test case.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2
1 5 10
2 15 5
3
2 93 78
1 71 59
3 57 96
19
19 23 16
5 90 13
12 85 70
19 67 78
12 16 60
18 48 28
5 4 24
12 97 97
4 57 87
19 91 74
18 100 76
7 86 46
9 100 57
3 76 73
6 84 93
1 6 84
11 75 94
19 15 3
12 11 34
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>25
221
1354
</pre>
<ul>
<li>In the first test case, it is optimal to line up the camels in the order <var>2, 1</var>.<ul>
<li>Camel <var>1</var> is not the frontmost camel, so its happiness will be <var>10</var>.</li>
<li>Camel <var>2</var> is among the two frontmost camels, so its happiness will be <var>15</var>.</li>
</ul>
</li>
<li>In the second test case, it is optimal to line up the camels in the order <var>2, 1, 3</var>.<ul>
<li>Camel <var>1</var> is among the two frontmost camels, so its happiness will be <var>93</var>.</li>
<li>Camel <var>2</var> is the frontmost camel, so its happiness will be <var>71</var>.</li>
<li>Camel <var>3</var> is among the three frontmost camels, so its happiness will be <var>57</var>.</li>
</ul>
</li>
</ul></section>
</div>
</span> |
p03902 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is a magician. He can cast a spell on an integer sequence <var>(a_1,a_2,...,a_M)</var> with <var>M</var> terms, to turn it into another sequence <var>(s_1,s_2,...,s_M)</var>, where <var>s_i</var> is the sum of the first <var>i</var> terms in the original sequence.</p>
<p>One day, he received <var>N</var> integer sequences, each with <var>M</var> terms, and named those sequences <var>A_1,A_2,...,A_N</var>. He will try to cast the spell on those sequences so that <var>A_1 < A_2 < ... < A_N</var> will hold, where sequences are compared lexicographically.
Let the action of casting the spell on a selected sequence be one cast of the spell. Find the minimum number of casts of the spell he needs to perform in order to achieve his objective.</p>
<p>Here, for two sequences <var>a = (a_1,a_2,...,a_M), b = (b_1,b_2,...,b_M)</var> with <var>M</var> terms each, <var>a < b</var> holds lexicographically if and only if there exists <var>i (1 ≦ i ≦ M)</var> such that <var>a_j = b_j (1 ≦ j < i)</var> and <var>a_i < b_i</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ N ≦ 10^3</var></li>
<li><var>1 ≦ M ≦ 10^3</var></li>
<li>Let the <var>j</var>-th term in <var>A_i</var> be <var>A_{(i,j)}</var>, then <var>1 ≦ A_{(i,j)} ≦ 10^9</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>200</var> points, Takahashi can achieve his objective by at most <var>10^4</var> casts of the spell, while keeping the values of all terms at most <var>10^9</var>.</li>
<li>In the test set worth another <var>800</var> points, <var>A_{(i,j)} ≦ 80</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_{(1,1)}</var> <var>A_{(1,2)}</var> … <var>A_{(1,M)}</var>
<var>A_{(2,1)}</var> <var>A_{(2,2)}</var> … <var>A_{(2,M)}</var>
:
<var>A_{(N,1)}</var> <var>A_{(N,2)}</var> … <var>A_{(N,M)}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of casts of the spell Takahashi needs to perform. If he cannot achieve his objective, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
2 3 1
2 1 2
2 6 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Takahashi can achieve his objective by casting the spell on <var>A_2</var> once to turn it into <var>(2 , 3 , 5)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
3 2 10
10 5 4
9 1 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>In this case, Takahashi cannot achieve his objective by casting the spell any number of times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5
2 6 5 6 9
2 6 4 9 10
2 6 8 6 7
2 1 7 3 8
2 1 4 8 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>11
</pre></section>
</div>
</span> |
p00787 |
<H1><font color="#000">Problem H:</font> Digital Racing Circuit</H1>
<p>
You have an ideally small racing car on an <i>x-y</i> plane (0 ≤ <i>x, y</i> ≤ 255, where bigger <i>y</i> denotes upper coordinate). The racing circuit course is figured by two solid walls. Each wall is a closed loop of connected line segments. End point coordinates of every line segment are both integers (See Figure 1). Thus, a wall is represented by a list of end point integer coordinates (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>), (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>), ...,(<i>x</i><sub><i>n</i></sub>, <i>y</i><sub><i>n</i></sub>). The start line and the goal line are identical.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_digitalRacing"><br>
<b>Figure 1. A Simple Course</b>
</center>
<p>
For the qualification run, you start the car at any integer coordinate position on the start line, say (<i>s<sub>x</sub>, s<sub>y</sub></i>).
</p>
<p>
At any clock <i>t</i> (≥ 0), according to the acceleration parameter at <i>t</i>, (<i>a<sub>x,t</sub>, a<sub>y,t</sub></i>), the velocity changes instantly to (<i>v<sub>x,t-1</sub> + a<sub>x,t</sub>, v<sub>y,t-1</sub> + a<sub>y,t</sub></i>), if the velocity at <i>t</i> - 1 is (<i>v<sub>x,t-1</sub>, v<sub>y,t-1</sub></i>). The velocity will be kept constant until the next clock. It is assumed that the velocity at clock -1, (<i>v<sub>x,-1</sub>, v<sub>y,-1</sub></i>) is (0, 0). Each of the acceleration components must be either -1, 0, or 1, because your car does not have so fantastic engine and brake. In other words, any successive pair of velocities should not differ more than 1 for either <i>x</i>-component or <i>y</i>-component. Note that your trajectory will be piecewise linear as the walls are.
</p>
<p>
Your car should not touch nor run over the circuit wall, or your car will be crashed, even at the start line. The referee watches your car's trajectory very carefully, checking whether or not the trajectory touches the wall or attempts to cross the wall.
</p>
<p>
The objective of the qualification run is to finish your run within as few clock units as possible, without suffering from any interference by other racing cars. That is, you run alone the circuit around clockwise and reach, namely touch or go across the goal line without having been crashed. Don't be crashed even in the last trajectory segment after you reach the goal line. But we don't care whatever happens after that clock
</p>
<p>
Your final lap time is the clock <i>t</i> when you reach the goal line for the first time after you have once left the start line. But it needs a little adjustment at the goal instant. When you cross the goal line, only the necessary fraction of your car's last trajectory segment is counted. For example, if the length of your final trajectory segment is 3 and only its 1/3 fraction is needed to reach the goal line, you have to add only 0.333 instead of 1 clock unit.
</p>
<p>
Drivers are requested to control their cars as cleverly as possible to run fast but avoiding crash. ALAS! The racing committee decided that it is too DANGEROUS to allow novices to run the circuit. In the last year, it was reported that some novices wrenched their fingers by typing too enthusiastically their programs. So, this year, you are invited as a referee assistant in order to accumulate the experience on this dangerous car race.
</p>
<p>
A number of experienced drivers are now running the circuit for the qualification for semi-finals. They submit their driving records to the referee. The referee has to check the records one by one whether it is not a fake.
</p>
<p>
Now, you are requested to make a program to check the validity of driving records for any given course configuration. Is the start point right on the start line without touching the walls? Is every value in the acceleration parameter list either one of -1, 0, and 1? Does the length of acceleration parameter list match the reported lap time? That is, aren't there any excess acceleration parameters after the goal, or are these enough to reach the goal? Doesn't it involve any crash? Does it mean a clockwise running all around? (Note that it is not inhibited to run backward temporarily unless crossing the start line again.) Is the lap time calculation correct? You should allow a rounding error up to 0.01 clock unit in the lap time.
</p>
<H2>Input</H2>
<p>
The input consists of a course configuration followed by a number of driving records on that course.
</p>
<p>
A course configuration is given by two lists representing the inner wall and the outer wall, respectively. Each line shows the end point coordinates of the line segments that comprise the wall. A course configuration looks as follows:
</p>
<pre>
<i>i</i><sub><i>x</i>,1</sub> <i>i</i><sub><i>y</i>,1</sub> ..... <i>i</i><sub><i>x</i>,N</sub> <i>i</i><sub><i>y</i>,N</sub> 99999
<i>o</i><sub><i>x</i>,1</sub> <i>o</i><sub><i>y</i>,1</sub> ..... <i>o</i><sub><i>x</i>,M</sub> <i>o</i><sub><i>y</i>,M</sub> 99999
</pre>
<p>
where data are alternating <i>x</i>-coordinates and <i>y</i>-coordinates that are all non-negative integers (≤ 255) terminated by 99999. The start/goal line is a line segment connecting the coordinates (<i>i</i><sub><i>x</i>,1</sub>, <i>i</i><sub><i>y</i>,1</sub>) and (<i>o</i><sub><i>x</i>,1</sub>, <i>o</i><sub><i>y</i>,1</sub>). For simplicity, <i>i</i><sub><i>y</i>,1</sub> is assumed to be equal to <i>o</i><sub><i>y</i>,1</sub>; that is, the start/goal line is horizontal on the <i>x-y</i> plane. Note that <i>N</i> and <i>M</i> may vary among course configurations, but do not exceed 100, because too many curves involve much danger even for experienced drivers. You need not check the validity of the course configuration.
</p>
<p>
A driving record consists of three parts, which is terminated by 99999: two integers <i>s<sub>x</sub>, s<sub>y</sub></i> for the start position (<i>s<sub>x</sub>, s<sub>y</sub></i>), the lap time with three digits after the decimal point, and the sequential list of acceleration parameters at all clocks until the goal. It is assumed that the length of the acceleration parameter list does not exceed 500. A driving record looks like the following:
</p>
<pre>
<i>s<sub>x</sub> s<sub>y</sub></i>
<i>lap-time</i>
<i>a</i><sub><i>x</i>,0</sub> <i>a</i><sub><i>y</i>,0</sub> <i>a</i><sub><i>x</i>,1</sub> <i>a</i><sub><i>y</i>,1</sub> ... <i>a</i><sub><i>x</i>,<i>L</i></sub> <i>a</i><sub><i>y</i>,<i>L</i></sub> 99999
</pre>
<p>
Input is terminated by a null driving record; that is, it is terminated by a 99999 that immediately follows 99999 of the last driving record.
</p>
<H2>Output</H2>
<p>
The test result should be reported by simply printing OK or NG for each driving record, each result in each line. No other letter is allowed in the result.
</p>
<H2>Sample Input</H2>
<pre>
6 28 6 32 25 32 26 27 26 24 6 24 99999
2 28 2 35 30 35 30 20 2 20 99999
3 28
22.667
0 1 1 1 1 0 0 -1 0 -1 1 0 0 0 1 0 -1 0 0 -1 -1 -1 -1 0 -1 0 -1 -1 -1 1 -1 1
-1 1 -1 0 1 0 1 1 1 1 1 0 1 1 99999
5 28
22.667
0 1 -1 1 1 0 1 -1 1 -1 1 0 1 0 1 0 -1 -1 -1 0 -1 -1 -1 0 -1 1 -1 -1 -1 1
-1 0 -1 1 -1 0 1 0 1 0 1 1 1 1 1 1 99999
4 28
6.333
0 1 0 1 1 -1 -1 -1 0 -1 0 -1 0 -1 99999
3 28
20.000
0 -1 1 -1 1 0 1 1 1 1 1 0 -1 0 -1 0 -1 1 -1 1
-1 1 -1 0 -1 -1 -1 -1 -1 -1 -1 0 1 0 1 -1 1 -1 1 -1 99999
99999
</pre>
<H2>Output for the Sample Input</H2>
<pre>
OK
NG
NG
NG
</pre>
|
p01895 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>E: 札 / Fuda </h1>
<p>
この問題はリアクティブ問題です。
サーバー側に用意されたプログラムと対話的に応答することで正答を導くプログラムを作成する必要があります。
</p>
<h2>問題文</h2>
<p>
湖に浮かぶ $N$ 個の小島からなるビワコという村がある。
各小島には $0$ から $N-1$ まで番号が振られている。
村には島と島の間に架かる橋が $M$ 本あり、$0$ から $M-1$ まで番号が振られている。
橋は双方向に移動可能である。
ここで言う橋とは単に島と島の間の通り道ということであり、取り除くと互いに到達不可能な島の組が増える意味ではない。
</p>
<p>
最近、橋の両端に掲示板を設置し、その橋を渡った先の島から橋を $1$ 本だけ使って移動できる島 (今いる島を含まない) の番号の書かれた札を貼ることで、
スムーズな移動を実現する計画が持ち上がった。
一枚の札には一つの移動先しか書くことが出来ないため、移動できる島の数だけ札が必要になる。
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day1RUPC_image05">
<p>
この札の作成を命じられたあなたは、札は全部で何枚必要かを調べることにした。
村には、かつて全ての橋を架けた橋職人がいる。
また、各島にはその島に住んでいる村人がいる。
村は広大で全ての掲示板を見て回るのは骨が折れるため、本部から電話で彼らに質問をすることで必要な札の枚数を求めることにした。
</p>
<p>
橋職人への質問では、まず、何番の橋の情報が知りたいかを橋職人に伝える。
すると、どの島とどの島の間に該当する橋を架けたかを確実に教えてくれる (edgクエリ)。
住人への質問では、まず聞きたい島の番号$i$を伝える。
すると、島 $i$ にかかる橋の数とその橋がどこにかかっているかを教えてくれる (lst クエリ)。
しかし、貧弱な通信網を使用しているため、各橋に対して、80% の確率で情報が抜け落ちてしまう。
</p>
<p>
札の発注まで時間がないので全体で多くても $3N$ 回しか質問ができない。
以上の条件のもとで、必要な札の数を求めるプログラムを書きなさい。
</p>
<h2>入出力仕様</h2>
<p>
以降では、あなたが提出したプログラムを「解答」、ジャッジ側が用意したプログラムを「ジャッジ」と呼ぶ。
入出力の詳細な仕様を以下に示すが、先にサンプルを見ると速い。
</p>
<h3>島と橋の数</h3>
<p> ジャッジは、まず島の数 $N$ と橋の数の合計 $M$ を $1$ 行に出力する。</p>
<pre>
N M
</pre>
<p>続いて、解答は edg, lst クエリを最大 $3N$ 回、 ans をちょうど 1 回ジャッジに対して送ることができる。</p>
<h3>edg クエリ</h3>
<p>解答の edg クエリに対し、ジャッジは橋$i$の両端の島の番号を答える。解答は次の形式で出力せよ。</p>
<pre>
edg i
</pre>
<p>これに対して、ジャッジは次の形式で応答する。</p>
<pre>
a b
</pre>
<p>$a$, $b$ は橋 $i$ が結ぶ島の番号である。</p>
<h3>lst クエリ</h3>
<p>解答の lst クエリに対し、ジャッジは小島 $i$ にかかる橋の本数と、それぞれの橋の行き先の島の番号を答える。解答は次の形式で出力せよ。</p>
<pre>
lst i
</pre>
<p>これに対して、ジャッジは次の形式で応答する。</p>
<pre>
k v1 v2 v3 … vk
</pre>
<p>
$k$ は島 $i$ にかかる橋の数である。
続く $v_1 \cdots v_k$ は頂点$i$から橋を一度だけ使って移動可能な頂点の番号のリストである。
各橋の行き先 $v_j$ に対し、$v_j \ge 0$ の場合はその情報がしっかり伝わったことを表す。$v_j = -1$ の場合は情報が抜け落ちていることを表す。
$-1$ かどうかは乱数で決められ、80% の確率で $-1$ となる。したがって、同じ $i$ に対して複数回このクエリを実行すると、結果は変わりうる。また、順番も不定である。
</p>
<h3>ans クエリ</h3>
<p>
解答の ans クエリによって、答えを出力できる。このクエリは 1 度しか行うことが出来ず、結果が正しくない場合は直ちに誤答となる。
このクエリの実行後に、解答は直ちに正常終了せよ。 $X$ を答えとして出力したい場合の形式は以下の通りである。
</p>
<pre>
ans X
</pre>
<h3>制約と注意</h3>
<ul>
<li>$1 \le N \le 100$</li>
<li>$0 \le M \le N(N-1)/2$</li>
<li>橋は異なる 2 つの島の間に架かっている。</li>
<li>異なる橋が、同じ 2 つの島を結ぶことはない。</li>
<li>ans 以外のクエリは高々 $3N$ 回しか投げられない。</li>
<li>ジャッジプログラムの出力は全て $1$ 行かつスペース区切りの整数からなる。</li>
<li>仕様に従わない出力の結果は不定である。</li>
<li>解答はジャッジの応答をすぐに標準入力で受け取らなければならない。</li>
<li>解答はクエリを出力した直後にバッファを空にせよ。最小の解答プログラム例を下に示す。C、C++以外の言語は各自で調べてほしい。</li>
</ul>
<p>C</p>
<pre>
#include <stdio.h>
int main(){
int n,m;
scanf("%d %d", & n, &m);
printf("ans 100\n"); // 答えをジャッジに提出
fflush(stdout); // フラッシュ
return 0;
}
</pre>
<p>C++</p>
<pre>
#include <iostream>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
cout << "ans 100" << endl; // 改行直後にフラッシュ
// cout << "ans 100\n" << flush; // 上と同じ
}
</pre>
<h2>サンプル</h2>
<p>
解答プログラムとジャッジプログラムの入出力例を以下に示す。
問題文の図中の村に対する答えを求めている。
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day1RUPC_image06"> |
p02240 |
<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>Connected Components</H1>
<p>
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
</p>
<H2>Input</H2>
<p>
In the first line, two integer $n$ and $m$ are given. $n$ is the number of users in the SNS and $m$ is the number of relations in the SNS. The users in the SNS are identified by IDs $0, 1, ..., n-1$.
</p>
<p>
In the following $m$ lines, the relations are given. Each relation is given by two integers $s$ and $t$ that represents $s$ and $t$ are friends (and reachable each other).
</p>
<p>
In the next line, the number of queries $q$ is given. In the following $q$ lines, $q$ queries are given respectively. Each query consists of two integers $s$ and $t$ separated by a space character.
</p>
<H2>Output</H2>
<p>
For each query, print "yes" if $t$ is reachable from $s$ through the social network, "no" otherwise.
</p>
<H2>Constraints</H2>
<ul>
<li>$2 \leq n \leq 100,000$</li>
<li>$0 \leq m \leq 100,000$</li>
<li>$1 \leq q \leq 10,000$</li>
</ul>
<H2>Sample Input</H2>
<pre>
10 9
0 1
0 2
3 4
5 7
5 6
6 7
6 8
7 8
8 9
3
0 1
5 9
1 3
</pre>
<H2>Sample Output</H2>
<pre>
yes
yes
no
</pre> |
p03001 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a rectangle in a coordinate plane. The coordinates of the four vertices are <var>(0,0)</var>, <var>(W,0)</var>, <var>(W,H)</var>, and <var>(0,H)</var>.
You are given a point <var>(x,y)</var> which is within the rectangle or on its border. We will draw a straight line passing through <var>(x,y)</var> to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq W,H \leq 10^9</var></li>
<li><var>0\leq x\leq W</var></li>
<li><var>0\leq y\leq H</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>W</var> <var>H</var> <var>x</var> <var>y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible area of the part whose area is not larger than that of the other, followed by <code>1</code> if there are multiple ways to cut the rectangle and achieve that maximum, and <code>0</code> otherwise.</p>
<p>The area printed will be judged correct when its absolute or relative error is at most <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3.000000 0
</pre>
<p>The line <var>x=1</var> gives the optimal cut, and no other line does.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2.000000 1
</pre></section>
</div>
</span> |
p01196 |
<H1><font color="#000"></font>The Phantom</H1>
<!-- Problem D -->
<p>
Mr. Hoge is in trouble. He just bought a new mansion, but it’s haunted by a phantom. He asked a famous conjurer
Dr. Huga to get rid of the phantom. Dr. Huga went to see the mansion, and found that the phantom is scared by
its own mirror images. Dr. Huga set two flat mirrors in order to get rid of the phantom.
</p>
<p>
As you may know, you can make many mirror images even with only two mirrors. You are to count up the
number of the images as his assistant. Given the coordinates of the mirrors and the phantom, show the number
of images of the phantom which can be seen through the mirrors.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test cases starts with a line which contains two positive integers,
<i>p</i><sub><i>x</i></sub> and <i>p</i><sub><i>y</i></sub> (1 ≤ <i>p</i><sub><i>x</i></sub>, <i>p</i><sub><i>y</i></sub> ≤ 50), which are the <i>x</i>- and <i>y</i>-coordinate of the phantom. In the next two lines, each line
contains four positive integers <i>u</i><sub><i>x</i></sub>, <i>u</i><sub><i>y</i></sub>, <i>v</i><sub><i>x</i></sub> and <i>v</i><sub>y</sub></i> (1 ≤ <i>u</i><sub><i>x</i></sub>, <i>u</i><sub><i>y</i></sub>, <i>v</i><sub><i>x</i></sub>, <i>v</i><sub><i>y</i></sub> ≤ 50), which are the coordinates of the mirror.
</p>
<p>
Each mirror can be seen as a line segment, and its thickness is negligible. No mirror touches or crosses with
another mirror. Also, you can assume that no images will appear within the distance of 10<sup>-5</sup> from the endpoints
of the mirrors.
</p>
<p>
The input ends with a line which contains two zeros.
</p>
<H2>Output</H2>
<p>
For each case, your program should output one line to the standard output, which contains the number of images
recognized by the phantom. If the number is equal to or greater than 100, print “TOO MANY” instead.
</p>
<H2>Sample Input</H2>
<pre>
4 4
3 3 5 3
3 5 5 6
4 4
3 3 5 3
3 5 5 5
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
TOO MANY
</pre>
|
p03451 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a <var>2 \times N</var> grid. We will denote the square at the <var>i</var>-th row and <var>j</var>-th column (<var>1 \leq i \leq 2</var>, <var>1 \leq j \leq N</var>) as <var>(i, j)</var>.</p>
<p>You are initially in the top-left square, <var>(1, 1)</var>.
You will travel to the bottom-right square, <var>(2, N)</var>, by repeatedly moving right or down.</p>
<p>The square <var>(i, j)</var> contains <var>A_{i, j}</var> candies.
You will collect all the candies you visit during the travel.
The top-left and bottom-right squares also contain candies, and you will also collect them.</p>
<p>At most how many candies can you collect when you choose the best way to travel?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq A_{i, j} \leq 100</var> (<var>1 \leq i \leq 2</var>, <var>1 \leq j \leq N</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of candies that can be collected.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
3 2 2 4 1
1 2 2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>14
</pre>
<p>The number of collected candies will be maximized when you:</p>
<ul>
<li>move right three times, then move down once, then move right once.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 1 1 1
1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>You will always collect the same number of candies, regardless of how you travel.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
3 3 4 5 4 5 3
5 3 4 4 2 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>29
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre></section>
</div>
</span> |
p00154 |
<H1>カードの組み合わせ</H1>
<p>
整数が書いてあるカードが何枚か入っている袋を使ってゲームをしましょう。各回のゲームで参加者はまず、好きな数 <var>n</var> を一つ宣言します。そして、袋の中から適当な枚数だけカードを一度に取り出して、それらのカードに書かれた数の総和が <var>n</var> に等しければ豪華賞品がもらえます。なお、それぞれのゲーム終了後カードは袋に戻されます。
</p>
<p>
袋の中の <var>m</var> 種類のカードの情報および、<var>g</var> 回のゲームで参加者が宣言した数を入力とし、それぞれのゲームで豪華商品をもらえるカードの組み合わせが何通りあるかを出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>m</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>a<sub>m</sub></var> <var>b<sub>m</sub></var>
<var>g</var>
<var>n<sub>1</sub></var>
<var>n<sub>2</sub></var>
:
<var>n<sub>g</sub></var>
</pre>
<p>
1行目にカードの種類数 <var>m</var> (1 ≤ <var>m</var> ≤ 7)、続く <var>m</var> 行に <var>i</var> 種類目のカードに書かれた整数 <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 100) とその枚数 <var>b<sub>i</sub></var> (1 ≤ <var>b<sub>i</sub></var> ≤ 10) が空白区切りで与えられます。
</p>
<p>
続く行にゲームの回数 <var>g</var> (1 ≤ <var>g</var> ≤ 10)、続く <var>g</var> 行にゲーム <var>i</var> で宣言された整数 <var>n<sub>i</sub></var> (1 ≤ <var>n<sub>i</sub></var> ≤ 1,000) が与えられます。
</p>
<p>
データセットの数は 100 を超えない。
</p>
<H2>Output</H2>
<p>
入力データセットごとに、<var>i</var> 行目にゲーム <var>i</var> で豪華賞品がもらえるカードの組み合わせ数を出力します。
</p>
<H2>Sample Input</H2>
<pre>
5
1 10
5 3
10 3
25 2
50 2
4
120
500
100
168
7
1 10
3 10
5 10
10 10
25 10
50 10
100 10
3
452
574
787
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
16
0
12
7
9789
13658
17466
</pre>
|
p02169 | <h1>Problem H: Count Words</h1>
<h2>Problem</h2>
<p>
$M$ 種類の文字がある。それらを使って長さ $N$ の文字列を作る。使われている文字の種類数が $K$ 以上であるような文字列は何通りあるか。$998244353$ で割ったあまりを求めよ。<br><br>
ここで長さ $N$ の2つの文字列が異なるとは以下のように定義される。
<ul><li>
2つの文字列を $S = S_1S_2 \ldots S_N$, $T = T_1T_2 \ldots T_N$ とした場合に、$S_i \neq T_i$ となるような $i$ $(1 \leq i \leq N)$ が存在する。
</ul></li>
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
$M$ $N$ $K$
</pre>
<p>
1行に $M, N, K$ が空白区切りで与えられる。<br>
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$1 \leq M \leq 10^{18} $</li>
<li>$1 \leq N \leq 10^{18} $</li>
<li>$1 \leq K \leq 1000 $</li>
<li>入力はすべて整数</li>
</ul>
<h2>Output</h2>
<p>
使われている文字の種類数が $K$ 以上であるような長さ $N$ の文字列の通り数を $998244353$ で割ったあまりを出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
2 10 1
</pre>
<h2>Sample Output 1</h2>
<pre>
1024
</pre>
<h2>Sample Input 2</h2>
<pre>
1 1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
<h2>Sample Input 3</h2>
<pre>
5 10 3
</pre>
<h2>Sample Output 3</h2>
<pre>
9755400
</pre>
<h2>Sample Input 4</h2>
<pre>
7 8 3
</pre>
<h2>Sample Output 4</h2>
<pre>
5759460
</pre>
<h2>Sample Input 5</h2>
<pre>
1000000000000000000 1000000000000000000 1000
</pre>
<h2>Sample Output 5</h2>
<pre>
133611974
</pre>
|
p00504 |
<H1> お土産購入計画 (Gifts)</H1>
<br/>
<h2>問題</h2>
<p>
オーストラリアに旅行に来た JOI 君は様々な場所で観光を楽しみ,ついに帰国する日がやってきた.今,JOI 君は帰りの飛行機が出発する国際空港のある町にいる.この町は東西南北に区画整理されており,各区画には道,土産店,住宅,国際空港がある.
JOI 君は最も北西の区画から出発して最も南東の区画の国際空港を目指す.
</p>
<p>
JOI 君は今いる区画から隣り合った区画に移動することができるが,住宅のある区画には入ることはできない.また飛行機の時間に間に合わせるために,今いる区画の東か南の区画にのみ移動する.ただし,時間にはいくらか余裕があるため,K 回まで今いる区画の北か西の区画へ移動することができる.
</p>
<p>
JOI 君は土産店のある区画に入ると,日本の友人たちのためにお土産を買う.JOI 君は土産店について入念に下調べをしていたので,どの土産店に行ったら何個のお土産を買うことができるかが分かっている.JOI 君が購入できるお土産の個数の最大値を求めるプログラムを作成せよ.
</p>
<p>
ただし,お土産を買う時間は無視できるとし,同じ土産店に 2 度以上訪れたときは最初に訪れたときだけお土産を買う.
</p>
<h2> 入力</h2>
<p>
入力は 1 + H 行からなる.
</p>
<p>
1 行目には,3 つの整数 H, W, K (2 ≦ H ≦ 50, 2 ≦ W ≦ 50, 1 ≦ K ≦ 3) が空白を区切りとして書かれている.
</p>
<p>
続く H 行にはそれぞれ W 文字からなる文字列が書かれており,区画の情報を表す.北から i 番目,西から j 番目の区画を (i, j) と表す (1 ≦ i ≦ H, 1 ≦ j ≦ W).
i 行目の j 番目の文字は,区画 (i, j) が道か国際空港である場合は '.' であり,住宅である場合は '#' である.
土産店である場合は '1', '2', ..., '9' のいずれかであり,その土産店で買うことができるお土産の個数を表す.
</p>
<p>
与えられる入力データにおいては,JOI 君がはじめにいる最も北西の区画が道であることは保証されている.また,JOI 君が国際空港にたどり着けることは保証されている.
</p>
<h2> 出力</h2>
<p>
JOI 君が購入できるお土産の個数の最大値を表す整数を 1 行で出力せよ.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
5 4 2
...#
.#.#
.#73
8##.
....
</pre>
<h3>出力例 1</h3>
<pre>
11
</pre>
<p>
入出力例 1 において,JOI 君は 3 回南へ進み区画 (4, 1) の土産店で買い物をした後,さらに南へ 1 回,東へ 3 回進み,そこから北へ 2 回進むことで区画 (3, 4) の土産店で買い物をする.最後に南へ 2 回進んで国際空港へたどり着くと,合計で 11 個のお土産を買うことができる.
</p>
<h3>入力例 2</h3>
<pre>
4 4 3
.8#9
9.#.
.#9.
....
</pre>
<h3>出力例 2</h3>
<pre>
27
</pre>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02539 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>2N</var> people numbered <var>1</var> through <var>2N</var>.
The height of Person <var>i</var> is <var>h_i</var>.</p>
<p>How many ways are there to make <var>N</var> pairs of people such that the following conditions are satisfied?
Compute the answer modulo <var>998,244,353</var>.</p>
<ul>
<li>Each person is contained in exactly one pair.</li>
<li>For each pair, the heights of the two people in the pair are different.</li>
</ul>
<p>Two ways are considered different if for some <var>p</var> and <var>q</var>, Person <var>p</var> and Person <var>q</var> are paired in one way and not in the other.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50,000</var></li>
<li><var>1 \leq h_i \leq 100,000</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>h_1</var>
<var>:</var>
<var>h_{2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1
1
2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two ways:</p>
<ul>
<li>Form the pair (Person <var>1</var>, Person <var>3</var>) and the pair (Person <var>2</var>, Person <var>4</var>).</li>
<li>Form the pair (Person <var>1</var>, Person <var>4</var>) and the pair (Person <var>2</var>, Person <var>3</var>).</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
30
10
20
40
20
10
10
30
50
60
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>516
</pre></section>
</div>
</span> |
p03282 | <span class="lang-en">
<p>Score: <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Mr. Infinity has a string <var>S</var> consisting of digits from <code>1</code> to <code>9</code>. Each time the date changes, this string changes as follows:</p>
<ul>
<li>Each occurrence of <code>2</code> in <var>S</var> is replaced with <code>22</code>. Similarly, each <code>3</code> becomes <code>333</code>, <code>4</code> becomes <code>4444</code>, <code>5</code> becomes <code>55555</code>, <code>6</code> becomes <code>666666</code>, <code>7</code> becomes <code>7777777</code>, <code>8</code> becomes <code>88888888</code> and <code>9</code> becomes <code>999999999</code>. <code>1</code> remains as <code>1</code>.</li>
</ul>
<p>For example, if <var>S</var> is <code>1324</code>, it becomes <code>1333224444</code> the next day, and it becomes <code>133333333322224444444444444444</code> the day after next.
You are interested in what the string looks like after <var>5 \times 10^{15}</var> days. What is the <var>K</var>-th character from the left in the string after <var>5 \times 10^{15}</var> days?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>S</var> is a string of length between <var>1</var> and <var>100</var> (inclusive).</li>
<li><var>K</var> is an integer between <var>1</var> and <var>10^{18}</var> (inclusive).</li>
<li>The length of the string after <var>5 \times 10^{15}</var> days is at least <var>K</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the <var>K</var>-th character from the left in Mr. Infinity's string after <var>5 \times 10^{15}</var> days.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1214
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The string <var>S</var> changes as follows: </p>
<ul>
<li>Now: <code>1214</code></li>
<li>After one day: <code>12214444</code></li>
<li>After two days: <code>1222214444444444444444</code></li>
<li>After three days: <code>12222222214444444444444444444444444444444444444444444444444444444444444444</code></li>
</ul>
<p>The first five characters in the string after <var>5 \times 10^{15}</var> days is <code>12222</code>. As <var>K=4</var>, we should print the fourth character, <code>2</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
157
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>The initial string is <code>3</code>. The string after <var>5 \times 10^{15}</var> days consists only of <code>3</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>299792458
9460730472580800
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> |
p00857 |
<H1><font color="#000">Problem D:</font> Lowest Pyramid</H1>
<p>
You are constructing a triangular pyramid with a sheet of craft paper with grid lines. Its base
and sides are all of triangular shape. You draw the base triangle and the three sides connected
to the base on the paper, cut along the outer six edges, fold the edges of the base, and assemble
them up as a pyramid.
</p>
<p>
You are given the coordinates of the base's three vertices, and are to determine the coordinates
of the other three. All the vertices must have integral X- and Y-coordinate values between -100 and +100 inclusive. Your goal is to minimize the height of the pyramid satisfying these
conditions. Figure 3 shows some examples.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lowestPyramid">
<p>
Figure 3: Some craft paper drawings and side views of the assembled pyramids
</p>
</center>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<p>
<i>X</i><sub>0</sub> <i>Y</i><sub>0</sub> <i>X</i><sub>1</sub> <i>Y</i><sub>1</sub> <i>X</i><sub>2</sub> <i>Y</i><sub>2</sub>
</p>
<p>
They are all integral numbers between -100 and +100 inclusive. (<i>X</i><sub>0</sub>, <i>Y</i><sub>0</sub>), (<i>X</i><sub>1</sub>, <i>Y</i><sub>1</sub>), (<i>X</i><sub>2</sub>, <i>Y</i><sub>2</sub>) are the coordinates of three vertices of the triangular base in counterclockwise order.
</p>
<p>
The end of the input is indicated by a line containing six zeros separated by a single space.
</p>
<H2>Output</H2>
<p>
For each dataset, answer a single number in a separate line. If you can choose three vertices (<i>X</i><sub>a</sub>, <i>Y</i><sub>a</sub>), (<i>X</i><sub>b</sub>, <i>Y</i><sub>b</sub>) and (<i>X</i><sub>c</sub>, <i>Y</i><sub>c</sub>) whose coordinates are all integral values between -100 and +100 inclusive, and triangles (<i>X</i><sub>0</sub>, <i>Y</i><sub>0</sub> )-(<i>X</i><sub>1</sub>, <i>Y</i><sub>1</sub>)-(<i>X</i><sub>a</sub>, <i>Y</i><sub>a</sub>), (<i>X</i><sub>1</sub>, <i>Y</i><sub>1</sub>)-(<i>X</i><sub>2</sub>, <i>Y</i><sub>2</sub>)-(<i>X</i><sub>b</sub>, <i>Y</i><sub>b</sub>), (<i>X</i><sub>2</sub>, <i>Y</i><sub>2</sub>)-(<i>X</i><sub>0</sub>, <i>Y</i><sub>0</sub>)-(<i>X</i><sub>c</sub>, <i>Y</i><sub>c</sub>) and (<i>X</i><sub>0</sub>, <i>Y</i><sub>0</sub>)-(<i>X</i><sub>1</sub>, <i>Y</i><sub>1</sub>)-(<i>X</i><sub>2</sub>, <i>Y</i><sub>2</sub>) do not overlap each other (in the XY-plane), and can be assembled as a triangular pyramid of positive (non-zero) height, output the minimum height among such pyramids. Otherwise, output -1.
</p>
<p>
You may assume that the height is, if positive (non-zero), not less than 0.00001. The output should not contain an error greater than 0.00001.
</p>
<H2>Sample Input</H2>
<pre>
0 0 1 0 0 1
0 0 5 0 2 5
-100 -100 100 -100 0 100
-72 -72 72 -72 0 72
0 0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
1.49666
-1
8.52936
</pre>
|
p03778 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer found two rectangles lying on the table, each with height <var>1</var> and width <var>W</var>.
If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of <var>[0,1]</var> and the horizontal range of <var>[a,a+W]</var>, and the second rectangle covers the vertical range of <var>[1,2]</var> and the horizontal range of <var>[b,b+W]</var>, as shown in the following figure:</p>
<p><img alt="" src="https://atcoder.jp/img/abc056/5c3a0ed9a07aa0992011c11ffbc9441b.png"/></p>
<p>AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.
Find the minimum distance it needs to be moved.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1≤W≤10^5</var></li>
<li><var>1≤a,b≤10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>W</var> <var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum distance the second rectangle needs to be moved.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The rectangles are already connected, and thus no move is needed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 10 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p01745 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<p>
<var>w</var> を正整数,<var>p</var> を長さ2<sup>2<var>w</var>+1</sup> の文字列とする.<var>(w, p)</var>- セルオートマトンとは次のようなものである.
</p>
<ul>
<li> 0 または 1 の状態をとることのできるセルが無限個一次元に並んでいる.</var>
<li> 時刻 0 に,すぬけ君は好きな有限個のマスを選んで状態を 1 にすることができる.残りのセルは 0 である.</li>
<li> 時刻 <var>t (> 0)</var> のセル <var>x</var> の状態 <var>f(t, x)</var> は,<var>f(t − 1, x − w), . . . , f(t − 1, x + w)</var> によって以下のように定まる:<br>
\begin{eqnarray}
f(t, x) = p[ \sum^w_{i=-w}2^{w+i} f(t − 1, x + i)] \;\;\;\;\;\;\;\;\;\;(1)
\end{eqnarray}
</li>
</ul>
<p>
すぬけ君は,時刻 0 にどのように初期状態を選んでも 1 の個数が初期状態から変わらないようなセルオートマトンが好きである.整数 <var>w</var> と文字列 <var>s</var> が与えられたとき,辞書順で <var>s</var> 以上の文字列 <var>p</var> であって <var>(w, p)</var>− セルオートマトンがすぬけ君に好かれるような最小の <var>p</var> を求めよ.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>w</var> ≤ 3</li>
<li> <var>|s|</var> = 2<sup>2<var>w</var>+1</sup></li>
<li> <var>s</var> に現れる文字は '0', '1' のみである</li>
</ul>
<h2>Input</h2>
<pre>
<var>w</var>
<var>s</var>
</pre>
<h2>Output</h2>
<p>
条件を満たす最小の <var>p</var> を出力せよ.そのようなものが存在しないときは "<span>no</span>" と出力せよ.
</p>
<h2>Sample Input 1</h2>
<pre>
1
00011000
</pre>
<h2>Sample Output 1</h2>
<pre>
00011101
</pre>
<h2>Sample Input 2</h2>
<pre>
1
11111111
</pre>
<h2>Sample Output 2</h2>
<pre>
no
</pre>
|
p03328 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some village, there are <var>999</var> towers that are <var>1,(1+2),(1+2+3),...,(1+2+3+...+999)</var> meters high from west to east, at intervals of <var>1</var> meter.</p>
<p>It had been snowing for a while before it finally stopped. For some two adjacent towers located <var>1</var> meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are <var>a</var> meters for the west tower, and <var>b</var> meters for the east tower.</p>
<p>Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.</p>
<p>Assume also that the depth of the snow cover is always at least <var>1</var> meter.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq a < b < 499500(=1+2+3+...+999)</var></li>
<li>All values in input are integers.</li>
<li>There is no input that contradicts the assumption.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the depth of the snow cover is <var>x</var> meters, print <var>x</var> as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The heights of the two towers are <var>10</var> meters and <var>15</var> meters, respectively.
Thus, we can see that the depth of the snow cover is <var>2</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>54 65
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.