question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03779 | <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> |
p01314 |
<h1><font color="#000">Problem A:</font> Sum of Consecutive Integers</h1>
<!--
<h3><U>連続する整数の和</U></h3>
-->
<p>あなたは数か月に渡る受験戦争を勝ち抜き,晴れてICPC大学に入学することができた.入学手続きの日,大学のキャンパス内では熱狂的なサークルの勧誘活動が行われており,あなたは大量のパンフレットを受け取って帰ってきた.部屋に戻ってきたあなたは受け取ったパンフレットの中から気になる一枚を見つけた.そのパンフレットは大学の広報部から渡されたものだった.</p>
<p>パンフレットには以下のような問題が記されていた.</p>
<blockquote>和が <i>N</i> となるような,連続する2つ以上の正の整数の組み合わせは,何組存在するでしょうか?例えば, 9 は 2+3+4 と 4+5 の 2通りの組み合わせがあります.</blockquote>
<p>この問題の答えが気になったあなたは,プログラムを書いてその答えを調べることにした.したがって,あなたの仕事は,入力として与えられる正の整数 <i>N</i> に対して,問題の答えを出力するプログラムを書くことである.</p>
<h2>Input</h2>
<p>入力はデータセットの並びである.各データセットはひとつの整数 <i>N</i> からなる一行である.ここで 1 ≤ <i>N</i> ≤ 1000 である.</p>
<p>入力の終りは,ひとつのゼロからなる一行で示される.</p>
<h2>Output</h2>
<p>出力は,入力の各データセットの表す正の整数に対する問題の答えを,入力データセットの順序通りに並べたものである.それ以外の文字が出力にあってはならない.</p>
<!-- end ja only -->
<h2>Sample Input</h2>
<pre>
9
500
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
2
3
</pre>
|
p03329 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:</p>
<ul>
<li>
<p><var>1</var> yen (the currency of Japan)</p>
</li>
<li>
<p><var>6</var> yen, <var>6^2(=36)</var> yen, <var>6^3(=216)</var> yen, ...</p>
</li>
<li>
<p><var>9</var> yen, <var>9^2(=81)</var> yen, <var>9^3(=729)</var> yen, ...</p>
</li>
</ul>
<p>At least how many operations are required to withdraw exactly <var>N</var> yen in total?</p>
<p>It is not allowed to re-deposit the money you withdrew.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100000</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If at least <var>x</var> operations are required to withdraw exactly <var>N</var> yen in total, print <var>x</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>127
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>By withdrawing <var>1</var> yen, <var>9</var> yen, <var>36(=6^2)</var> yen and <var>81(=9^2)</var> yen, we can withdraw <var>127</var> yen in four operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>By withdrawing <var>1</var> yen three times, we can withdraw <var>3</var> yen in three operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>44852
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>16
</pre></section>
</div>
</span> |
p00913 |
<H1><font color="#000">Problem J: </font>Cubic Colonies</H1>
<p>
In AD 3456, the earth is too small for hundreds of billions of people to live in peace. Interstellar Colonization Project with Cubes (ICPC) is a project that tries to move people on the earth to space colonies to ameliorate the problem. ICPC obtained funding from governments and manufactured space colonies very quickly and at low cost using prefabricated cubic blocks.
</p>
<p>
The largest colony looks like a Rubik's cube. It consists of 3 × 3 × 3 cubic blocks (Figure J.1A). Smaller colonies miss some of the blocks in the largest colony.
</p>
<p>
When we manufacture a colony with multiple cubic blocks, we begin with a single block. Then we iteratively glue a next block to existing blocks in a way that faces of them match exactly. Every pair of touched faces is glued.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_cubicColonies1" style="aling:center"><br/>
<p>
Figure J.1: Example of the largest colony and a smaller colony
</p>
</center>
<p>
However, just before the first launch, we found a design flaw with the colonies. We need to add a cable to connect two points on the surface of each colony, but we cannot change the inside of the prefabricated blocks in a short time. Therefore we decided to attach a cable on the surface of each colony. If a part of the cable is not on the surface, it would be sheared off during the launch, so we have to put the whole cable on the surface. We would like to minimize the lengths of the cables due to budget constraints. The dashed line in Figure J.1B is such an example.
</p>
<p>
Write a program that, given the shape of a colony and a pair of points on its surface, calculates the length of the shortest possible cable for that colony.
</p>
<H2>Input</H2>
<p>
The input contains a series of datasets. Each dataset describes a single colony and the pair of the points for the colony in the following format.
</p>
<p>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>z</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>z</i><sub>2</sub><br/>
<i>b</i><sub>0,0,0</sub><i>b</i><sub>1,0,0</sub><i>b</i><sub>2,0,0</sub><br/>
<i>b</i><sub>0,1,0</sub><i>b</i><sub>1,1,0</sub><i>b</i><sub>2,1,0</sub><br/>
<i>b</i><sub>0,2,0</sub><i>b</i><sub>1,2,0</sub><i>b</i><sub>2,2,0</sub><br/>
<i>b</i><sub>0,0,1</sub><i>b</i><sub>1,0,1</sub><i>b</i><sub>2,0,1</sub><br/>
<i>b</i><sub>0,1,1</sub><i>b</i><sub>1,1,1</sub><i>b</i><sub>2,1,1</sub><br/>
<i>b</i><sub>0,2,1</sub><i>b</i><sub>1,2,1</sub><i>b</i><sub>2,2,1</sub><br/>
<i>b</i><sub>0,0,2</sub><i>b</i><sub>1,0,2</sub><i>b</i><sub>2,0,2</sub><br/>
<i>b</i><sub>0,1,2</sub><i>b</i><sub>1,1,2</sub><i>b</i><sub>2,1,2</sub><br/>
<i>b</i><sub>0,2,2</sub><i>b</i><sub>1,2,2</sub><i>b</i><sub>2,2,2</sub><br/>
</p>
<p>
(<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>z</i><sub>1</sub>) and (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>, <i>z</i><sub>2</sub>) are the two distinct points on the surface of the colony, where <i>x</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>1</sub>, <i>y</i><sub>2</sub>, <i>z</i><sub>1</sub>, <i>z</i><sub>2</sub> are integers that satisfy 0 ≤ <i>x</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>1</sub>, <i>y</i><sub>2</sub>, <i>z</i><sub>1</sub>, <i>z</i><sub>2</sub> ≤ 3. <i>b<sub>i,j,k</sub></i> is '<span>#</span>' when there is a cubic block whose two diagonal vertices are (<i>i</i>, <i>j</i>, <i>k</i>) and (<i>i</i> + 1, <i>j</i> + 1, <i>k</i> + 1), and <i>b<sub>i,j,k</sub></i> is '<span>.</span>' if there is no block. Figure J.1A corresponds to the first dataset in the sample input, whereas Figure J.1B corresponds to the second. A cable can pass through a zero-width gap between two blocks if they are touching only on their vertices or edges. In Figure J.2A, which is the third dataset in the sample input, the shortest cable goes from the point A (0, 0, 2) to the point B (2, 2, 2), passing through (1, 1, 2), which is shared by six blocks. Similarly, in Figure J.2B (the fourth dataset in the sample input), the shortest cable goes through the gap between two blocks not glued directly. When two blocks share only a single vertex, you can put a cable through the vertex (Figure J.2C; the fifth dataset in the sample input).
</p>
<p>
You can assume that there is no colony consisting of all 3 × 3 × 3 cubes but the center cube.
</p>
<p>
Six zeros terminate the input.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_cubicColonies2" style="aling:center"><br/>
<p>
Figure J.2: Dashed lines are the shortest cables. Some blocks are shown partially transparent
for illustration.
</p>
</center>
<H2>Output</H2>
<p>
For each dataset, output a line containing the length of the shortest cable that connects the two given points. We accept errors less than 0.0001. You can assume that given two points can be connected by a cable.
</p>
<H2>Sample Input</H2>
<pre>
0 0 0 3 3 3
###
###
###
###
###
###
###
###
###
3 3 0 0 0 3
#..
###
###
###
###
###
#.#
###
###
0 0 2 2 2 2
...
...
...
.#.
#..
...
##.
##.
...
0 1 2 2 1 1
...
...
...
.#.
#..
...
##.
##.
...
3 2 0 2 3 2
###
..#
...
..#
...
.#.
..#
..#
.##
0 0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6.70820393249936941515
6.47870866461907457534
2.82842712474619029095
2.23606797749978980505
2.82842712474619029095
</pre> |
p01601 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h2>回文数</h2>
<h2>Problem Statement</h2>
<p>整数<var>n</var>に最も近い回文数を求めよ.</p>
<p>なお,非負整数<var>x</var>が回文数であるとは,<var>x</var>を十進法で表現した文字列とそれを反転させた文字列が等しいことをいう.<br />
例えば0,7,33,10301などは回文数であり,32,90,1010などは回文数でない.</p>
<h2>Input</h2>
<p>入力は以下の形式に従う.与えられる数は全て整数である.</p>
<pre><var>n</var></pre>
<h2>Constraints</h2>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1≦n≦10^4</var></li></ul>
<h2>Output</h2>
<p><var>n</var>に最も近い回文数を出力せよ.<br />
そのような数が複数ある場合は最も小さいものを出力せよ.</p>
<h2>Sample Input 1</h2>
<pre>13</pre>
<h2>Output for the Sample Input 1</h2>
<pre>11</pre>
<p>13に最も近い回文数は11である.</p>
<h2>Sample Input 2</h2>
<pre>7447</pre>
<h2>Output for the Sample Input 2</h2>
<pre>7447</pre>
<p>7447は回文数なのでそのまま出力すればよい.</p>
<h2>Sample Input 3</h2>
<pre>106</pre>
<h2>Output for the Sample Input 3</h2>
<pre>101</pre>
<p>106に最も近い回文数は111と101のふたつあるが,そのうち小さい方の101を出力する.</p>
|
p01251 |
<H1><font color="#000">Problem B:</font> Left Hand Rule</H1>
<p>
The left-hand rule, which is also known as the wall follower, is a well-known strategy that solves a two-
dimensional maze. The strategy can be stated as follows: once you have entered the maze, walk around
with keeping your left hand in contact with the wall until you reach the goal. In fact, it is proven that this
strategy solves some kind of mazes.
</p>
<p>
Your task is to write a program that determines whether the given maze is solvable by using the left-hand
rule and (if the maze is solvable) the number of steps to reach the exit. Moving to a cell from the entrance
or the adjacent (north, south, east or west) cell is counted as a step.
</p>
<p>
In this problem, the maze is represented by a collection of walls placed on the two-dimensional grid.
We use an ordinary Cartesian coordinate system; the positive <i>x</i>-axis points right and the positive <i>y</i>-axis
points up. Each wall is represented by a line segment which is parallel to the <i>x</i>-axis or the <i>y</i>-axis, such
that both ends of each wall are located on integer coordinates. The size of the maze is given by <i>W</i> and <i>H</i>
that indicate the width and the height of the maze, respectively. A rectangle whose vertices are on (0, 0),
(<i>W</i>, 0), (<i>W</i>, <i>H</i>) and (0, <i>H</i>) forms the outside boundary of the maze. The outside of the maze is always
surrounded by walls except for the entrance of the maze. The entrance is represented by a line segment
whose ends are (<i>x<sub>E</sub></i>, <i>y<sub>E</sub></i>) and (<i>x<sub>E</sub></i>', <i>y<sub>E</sub></i>'). The entrance has a unit length and is located somewhere on one
edge of the boundary. The exit is a unit square whose bottom left corner is located on (<i>x<sub>X</sub></i>, <i>y<sub>X</sub></i>).
</p>
<p>
A few examples of mazes are illustrated in the figure below. They correspond to the datasets in the sample
input.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_leftHandRule">
<p>Figure 1: Example Mazes (shaded squares indicate the exits)</p>
</center>
<H2>Input</H2>
<p>
The input consists of multiple datasets.
</p>
<p>
Each dataset is formatted as follows:
</p>
<pre>
<i>W H N</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</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>2</sub>' <i>y</i><sub>2</sub>'
...
<i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub> <i>x</i><sub><i>N</i></sub>' <i>y</i><sub><i>N</i></sub>'
<i>x</i><sub><i>E</i></sub> <i>y</i><sub><i>E</i></sub> <i>x</i><sub><i>E</i></sub>' <i>y</i><sub><i>E</i></sub>' <i>x<sub>X</sub></i> <i>y<sub>X</sub></i>
</pre>
<p>
<i>W</i> and <i>H</i> (0 < <i>W</i>, <i>H</i> ≤ 100) indicate the size of the maze. <i>N</i> is the number of walls inside the maze.
The next <i>N</i> lines give the positions of the walls, where (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) and (<i>x<sub>i</sub></i>', <i>y<sub>i</sub></i>') denote two ends of each wall
(1 ≤ <i>i</i> ≤ <i>N</i>). The last line gives the positions of the entrance and the exit. You can assume that all the
coordinates given in the input are integer coordinates and located inside the boundary of the maze. You
can also assume that the wall description is not redundant, i.e. an endpoint of a wall is not shared by any
other wall that is parallel to it.
</p>
<p>
The input is terminated by a line with three zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, print a line that contains the number of steps required to reach the exit. If the given
maze is unsolvable, print “<span>Impossible</span>” instead of the number of steps.
</p>
<H2>Sample Input</H2>
<pre>
3 3 3
1 0 1 2
1 2 2 2
2 2 2 1
0 0 1 0 1 1
3 3 4
1 0 1 2
1 2 2 2
2 2 2 1
2 1 1 1
0 0 1 0 1 1
3 3 0
0 0 1 0 1 1
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
9
Impossible
Impossible
</pre>
|
p02884 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a cave consisting of <var>N</var> rooms and <var>M</var> one-directional passages. The rooms are numbered <var>1</var> through <var>N</var>.</p>
<p>Takahashi is now in Room <var>1</var>, and Room <var>N</var> has the exit. The <var>i</var>-th passage connects Room <var>s_i</var> and Room <var>t_i</var> (<var>s_i</var> < <var>t_i</var>) and can only be traversed in the direction from Room <var>s_i</var> to Room <var>t_i</var>. It is known that, for each room except Room <var>N</var>, there is at least one passage going from that room.</p>
<p>Takahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room <var>1</var> at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage.</p>
<p>Aoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room <var>1</var>. However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room <var>N</var>.</p>
<p>Let <var>E</var> be the expected number of passages Takahashi takes before he reaches Room <var>N</var>. Find the value of <var>E</var> when Aoki makes a choice that minimizes <var>E</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 600</var></li>
<li><var>N-1 \leq M \leq \frac{N(N-1)}{2}</var></li>
<li><var>s_i < t_i</var></li>
<li>If <var>i != j</var>, <var>(s_i, t_i) \neq (s_j, t_j)</var>. <strong>(Added 21:23 JST)</strong></li>
<li>For every <var>v = 1, 2, ..., N-1</var>, there exists <var>i</var> such that <var>v = s_i</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>s_1</var> <var>t_1</var>
<var>:</var>
<var>s_M</var> <var>t_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value of <var>E</var> when Aoki makes a choice that minimizes <var>E</var>.
Your output will be judged as correct when the absolute or relative error from the judge's output is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 6
1 4
2 3
1 3
1 2
3 4
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1.5000000000
</pre>
<p>If Aoki blocks the passage from Room <var>1</var> to Room <var>2</var>, Takahashi will go along the path <code>1</code> → <code>3</code> → <code>4</code> with probability <var>\frac{1}{2}</var> and <code>1</code> → <code>4</code> with probability <var>\frac{1}{2}</var>. <var>E = 1.5</var> here, and this is the minimum possible value of <var>E</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2.0000000000
</pre>
<p>Blocking any one passage makes Takahashi unable to reach Room <var>N</var>, so Aoki cannot block a passage.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 33
3 7
5 10
8 9
1 10
4 6
2 5
1 7
6 10
1 4
1 3
8 10
1 5
2 6
6 9
5 6
5 8
3 6
4 8
2 7
2 9
6 7
1 2
5 9
6 8
9 10
3 9
7 8
4 5
2 10
5 7
3 5
4 7
4 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3.0133333333
</pre></section>
</div>
</span> |
p03796 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves working out. He is now exercising <var>N</var> times.</p>
<p>Before he starts exercising, his <em>power</em> is <var>1</var>. After he exercises for the <var>i</var>-th time, his power gets multiplied by <var>i</var>.</p>
<p>Find Snuke's power after he exercises <var>N</var> times. Since the answer can be extremely large, print the answer modulo <var>10^{9}+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 10^{5}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer modulo <var>10^{9}+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<ul>
<li>After Snuke exercises for the first time, his power gets multiplied by <var>1</var> and becomes <var>1</var>.</li>
<li>After Snuke exercises for the second time, his power gets multiplied by <var>2</var> and becomes <var>2</var>.</li>
<li>After Snuke exercises for the third time, his power gets multiplied by <var>3</var> and becomes <var>6</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3628800
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>457992974
</pre>
<p>Print the answer modulo <var>10^{9}+7</var>.</p></section>
</div>
</span> |
p00010 |
<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>Circumscribed Circle of A Triangle.</H1>
<p>
Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, the number of datasets $n$ is given. Each dataset consists of:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$<br/>
<br/>
in a line. All the input are real numbers.
</p>
<H2>Output</H2>
<p>
For each dataset, print $p_x$, $p_y$ and $r$ separated by a space in a line. Print the solution to three places of decimals. Round off the solution to three decimal places.
</p>
<h2>Constraints</h2>
<ul>
<li>$-100 \leq x_1, y_1, x_2, y_2, x_3, y_3 \leq 100$</li>
<li>$ n \leq 20$</li>
</ul>
<H2>Sample Input</H2>
<pre>
1
0.0 0.0 2.0 0.0 2.0 2.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1.000 1.000 1.414
</pre>
|
p00440 |
<H1>最長の階段 </H1>
<h2>問題</h2>
<p>
1 から <i>n</i> までの整数がそれぞれ 1 つずつ書かれた <i>n</i> 枚のカードと,1 枚の白紙の
カードがある.これら <i>n</i> + 1 枚のカードの内,<i>k</i> 枚のカードが与えられる.ただし,
1 ≤ <i>k</i> ≤ n である.白紙のカードには 1 から <i>n</i> までの整数を 1 つ書くことができ
る.与えられたカードだけで,できるだけ長い連続した整数列を作りたい.
</p>
<p>
与えられるカードが入力されたときに, 与えられたカードから作ることができる連
続した整数列の最大長を出力するプログラムを作成せよ.
</p>
<h2>例1</h2>
<p>
<i>n</i> = 7, <i>k</i> = 5 とする.6, 2, 4, 7, 1 のカードが与えられたとき,このカードを使っ
て作れる連続した整数列のうち最長のものは 1, 2 であり,その長さは 2 である.
</p>
<h2>例2</h2>
<p>
<i>n</i> = 7, <i>k</i> = 5 とする.6, 2, 4, 7 と白紙のカードが与えられたとき,このカードを
使って作れる連続した整数列のうち最長のものは,白紙のカードに 5 を書くことに
よってできる 4, 5, 6, 7 であり,その長さは 4 である.
</p>
<h2>入力</h2>
<p>
<!-- 入力ファイルのファイル名は <span>input.txt</span> である.-->
入力は複数のデータセットからなる.各データセットは以下の形式で与えられる.入力はゼロ2つを含む行で終了する.
</p>
<p>
1 行目には,2 つの整数 <i>n</i> (1 ≤ <i>n</i> ≤ 100000) と <i>k</i> (1 ≤ <i>k</i> ≤ <i>n</i>) がこの順で 1 つの
空白を区切りとして書かれている.続く <i>k</i> 行には整数が 1 つずつ書かれており,与
えられる <i>k</i> 枚のカードに書かれている整数を表している.白紙のカードは 0 で表さ
れる.
</p>
<p>
採点用データのうち, 配点の 40% 分は 1 ≤ <i>n</i> ≤ 1000, 1 ≤ <i>k</i> ≤ 500 を, 配点の 20% 分は 1 ≤ <i>n</i> ≤ 60000, 1 ≤ <i>k</i> ≤ 50000 を. 配点の 40% 分は 1 ≤ <i>n</i> ≤ 100000, 1 ≤ <i>k</i> ≤ 100000 を満たす.
</p>
<p>
データセットの数は 5 を超えない.
</p>
<h2>出力</h2>
<p>
<!--
出力ファイルのファイル名は <span>output.txt</span> である.
<span>output.txt</span> は 1 行だけからなり,その 1 行は出力する整数 1 つだけを含む.
-->
データセットごとに整数を1行に出力する.
</p>
<h2>入出力例</h2>
<h3>入力例</h3>
<pre>
7 5
6
2
4
7
1
7 5
6
2
0
4
7
0 0
</pre>
<h3>出力例</h3>
<pre>
2
4
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02187 | <h2>F: 部分文字列分解</h2>
<h3>問題</h3>
<p>
2 つの文字列 <var>S</var> と <var>T</var> および整数 <var>k</var> が与えられる。
<var>T</var> の長さ <var>k</var> 以上の連続する部分文字列を考えたとき、それらの連結で <var>S</var> を構成できるか判定せよ。
</p>
<p>ここで文字列 <var>s = s_1 s_2 ... s_n</var> の連続する部分文字列 <var>s[l, r] = s_l s_{l+1} ... s_r</var> <var>(1 \leq l \leq r \leq n)</var> とは、<var>s</var> の <var>l</var> 文字目から <var>r</var> 文字目までを切り出してできる文字列を指し、その長さは <var>r - l + 1</var> である。</p>
<h3>入力形式</h3>
<pre>
<var>S</var>
<var>T</var>
<var>k</var>
</pre>
<h3>制約</h3>
<ul>
<li> <var>S</var> と <var>T</var> は小文字アルファベットからなる</li>
<li> <var>1 \leq |S|, |T| \leq 2\times 10^5</var></li>
<li> <var>1 \leq k \leq |T|</var></li>
</ul>
<h3>出力形式</h3>
<p><var>S</var> を構成できるとき <code>Yes</code> を、そうでないとき <code>No</code> を一行に出力せよ。</p>
<h3>入力例1</h3>
<pre>
abracadabra
cadabra
4
</pre>
<h3>出力例1</h3>
<pre>Yes</pre>
<p><var>T</var> の長さ <var>4</var> 以上の部分文字列である <code>abra</code> と <code>cadabra</code> を連結させることで <code>abracadabra</code> が構成でき、これは <var>S</var> と等しい文字列である。</p>
<h3>入力例2</h3>
<pre>
abcd
zcba
1
</pre>
<h3>出力例2</h3>
<pre>No</pre>
<h3>入力例3</h3>
<pre>
abc
zcba
1
</pre>
<h3>出力例3</h3>
<pre>Yes</pre>
<h3>入力例4</h3>
<pre>
abcdefg
abcddefg
4
</pre>
<h3>出力例4</h3>
<pre>No</pre>
|
p03145 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a right triangle <var>ABC</var> with <var>∠ABC=90°</var>.</p>
<p>Given the lengths of the three sides, <var>|AB|,|BC|</var> and <var>|CA|</var>, find the area of the right triangle <var>ABC</var>.</p>
<p>It is guaranteed that the area of the triangle <var>ABC</var> is an integer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |AB|,|BC|,|CA| \leq 100</var></li>
<li>All values in input are integers.</li>
<li>The area of the triangle <var>ABC</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>|AB|</var> <var>|BC|</var> <var>|CA|</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the area of the triangle <var>ABC</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p><img alt="tri" src="https://img.atcoder.jp/ghi/44c1d4cbdf4677ce3b08ca70b5ce98ea.png"/></p>
<p>This triangle has an area of <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 12 13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>30
</pre>
<p>This triangle has an area of <var>30</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>45 28 53
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>630
</pre>
<p>This triangle has an area of <var>630</var>.</p></section>
</div>
</span> |
p01178 |
<H1><font color="#000">Problem H:</font> Ramen Shop</H1>
<p>
Ron is a master of a ramen shop.
</p>
<p>
Recently, he has noticed some customers wait for a long time. This has been caused by lack of
seats during lunch time. Customers loses their satisfaction if they waits for a long time, and
even some of them will give up waiting and go away. For this reason, he has decided to increase
seats in his shop. To determine how many seats are appropriate, he has asked you, an excellent
programmer, to write a simulator of customer behavior.
</p>
<p>
Customers come to his shop in groups, each of which is associated with the following four
parameters:
</p>
<ul>
<li> <i>T<sub>i</sub></i> : when the group comes to the shop</li>
<li> <i>P<sub>i</sub></i> : number of customers</li>
<li> <i>W<sub>i</sub></i> : how long the group can wait for their seats</li>
<li> <i>E<sub>i</sub></i> : how long the group takes for eating</li>
</ul>
<p>
The <i>i</i>-th group comes to the shop with <i>P<sub>i</sub></i> customers together at the time <i>T<sub>i</sub></i> . If <i>P<sub>i</sub></i> successive
seats are available at that time, the group takes their seats immediately. Otherwise, they waits
for such seats being available. When the group fails to take their seats within the time <i>W<sub>i</sub></i>
(inclusive) from their coming and strictly before the closing time, they give up waiting and go
away. In addition, if there are other groups waiting, the new group cannot take their seats until
the earlier groups are taking seats or going away.
</p>
<p>
The shop has <i>N</i> counters numbered uniquely from 1 to <i>N</i>. The <i>i</i>-th counter has <i>C<sub>i</sub></i> seats. The
group prefers “seats with a greater distance to the nearest group.” Precisely, the group takes
their seats according to the criteria listed below. Here, <i>S<sub>L</sub></i> denotes the number of successive
empty seats on the left side of the group after their seating, and <i>S<sub>R</sub></i> the number on the right
side. <i>S<sub>L</sub></i> and <i>S<sub>R</sub></i> are considered to be infinity if there are no other customers on the left side
and on the right side respectively.
</p>
<ol>
<li> Prefers seats maximizing min{<i>S<sub>L</sub></i>, <i>S<sub>R</sub></i>}.</li>
<li> If there are multiple alternatives meeting the first criterion, prefers seats maximizing
max{<i>S<sub>L</sub></i>, <i>S<sub>R</sub></i>}.</li>
<li> If there are still multiple alternatives, prefers the counter of the smallest number.</li>
<li> If there are still multiple alternatives, prefers the leftmost seats.</li>
</ol>
<p>
When multiple groups are leaving the shop at the same time and some other group is waiting
for available seats, seat assignment for the waiting group should be made after all the finished
groups leave the shop.
</p>
<p>
Your task is to calculate the average satisfaction over customers. The satisfaction of a customer
in the <i>i</i>-th group is given as follows:
</p>
<ul>
<li> If the group goes away without eating, -1.</li>
<li> Otherwise, (<i>W<sub>i</sub></i> - <i>t<sub>i</sub></i> )/<i>W<sub>i</sub></i> where <i>t<sub>i</sub></i> is the actual waiting time for the <i>i</i>-th group (the value ranges between 0 to 1 inclusive).</li>
</ul>
<H2>Input</H2>
<p>
The input consists of multiple datasets.
</p>
<p>
Each dataset has the following format:
</p>
<pre>
<i>N M T</i>
<i>C</i><sub>1</sub> <i>C</i><sub>2</sub> ... <i>C</i><sub><i>N</i></sub>
<i>T</i><sub>1</sub> <i>P</i><sub>1</sub> <i>W</i><sub>1</sub> <i>E</i><sub>1</sub>
<i>T</i><sub>2</sub> <i>P</i><sub>2</sub> <i>W</i><sub>2</sub> <i>E</i><sub>2</sub>
...
<i>T</i><sub><i>M</i></sub> <i>P</i><sub><i>M</i></sub> <i>W</i><sub><i>M</i></sub> <i>E</i><sub><i>M</i></sub>
</pre>
<p>
<i>N</i> indicates the number of counters, <i>M</i> indicates the number of groups and <i>T</i> indicates the
closing time. The shop always opens at the time 0. All input values are integers.
</p>
<p>
You can assume that 1 ≤ <i>N</i> ≤ 100, 1 ≤ <i>M</i> ≤ 10000, 1 ≤ <i>T</i> ≤ 10<sup>9</sup>, 1 ≤ <i>C</i><sub><i>i</i></sub> ≤ 100, 0 ≤ <i>T</i><sub>1</sub> < <i>T</i><sub>2</sub> < ... < <i>T</i><sub><i>M</i></sub> < <i>T</i>, 1 ≤ <i>P</i><sub><i>i</i></sub> ≤ max <i>C</i><sub><i>i</i></sub>, 1 ≤ <i>W</i><sub><i>i</i></sub> ≤ 10<sup>9</sup> and 1 ≤ <i>E</i><sub><i>i</i></sub> ≤ 10<sup>9</sup>.
</p>
<p>
The input is terminated by a line with three zeros. This is not part of any datasets.
</p>
<H2>Output</H2>
<p>
For each dataset, output the average satisfaction over all customers in a line. Each output value
may be printed with an arbitrary number of fractional digits, but may not contain an absolute
error greater than 10<sup>-9</sup>.
</p>
<H2>Sample Input</H2>
<pre>
1 4 100
7
10 1 50 50
15 2 50 50
25 1 50 50
35 3 50 50
1 2 100
5
30 3 20 50
40 4 40 50
1 2 100
5
49 3 20 50
60 4 50 30
1 2 100
5
50 3 20 50
60 4 50 30
2 3 100
4 2
10 4 20 20
30 2 20 20
40 4 20 20
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.7428571428571429
0.4285714285714285
0.5542857142857143
-0.1428571428571428
0.8000000000000000
</pre>
|
p01482 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<h1> Memory Leak</h1>
<p>
Time Limit: 8 sec / Memory Limit: 64 MB
</p>
<h2> D: メモリーリーク</h2>
<p>
あなたの研究室の同期が, 実装中のソフトウェアのバグに悩まされていた.
彼のソフトウェアは, かなり下位のレイヤで動作するソフトウェアであるため,
高機能のデバッガやテストツールなどは使用することができない.
OS による補助がない環境であるため,
言語上使えるはずの例外処理など使えないし, 標準ライブラリですら大半のものが使用できない.
ガベージコレクタなんて夢のまた夢である.
そのため彼は, これまでトライアルアンドエラーによって自力で検証を行い, 修正を行ってきた.
しかし, 今回のバグは相当根が深いらしく, 彼はもう一ヶ月近くに渡り検証を繰り返していた.
締切までにこのバグが修正できなかったため, 彼は論文提出を見送っている.
夜中の研究室には, 断続的に彼の奇声が聞こえている始末である.
見兼ねたあなたは, 彼のソフトウェアの検証を手伝うことにした.
</p>
<p>
これまでの彼のがんばりによって, プログラムではいわゆるメモリリークが発生している可能性が高いらしい.
どうやらプログラムのどこかで, 確保したメモリを解放し忘れていることが原因で,
使用できるメモリを使い果たしてしまっているようである.
彼のプログラムはそのままでは複雑すぎるので,
彼はメモリの確保や解放を行う処理を簡単に表現し, パターン化したものを用意してくれた.
このパターンごとにどの程度メモリリークが発生するかを調べて欲しいとのことである.
</p>
<p>
まず前提として, 彼のプログラムでは, メモリマネージャというモジュールによって, メモリ領域の確保や解放といった機能が提供されているらしい.
メモリ領域を確保するとは, 正確にはメモリマネージャが管理するヒープと呼ばれるメモリ領域から,
必要な分を借り受け, その領域への「参照」を得ることである.
なお, ヒープには上限があり, プログラムからそれ以上のメモリは利用できない.
メモリ領域の大きさには「バイト」が用いられる.
</p>
<p>
「参照」とは, その領域が存在する場所を示す値である.
参照は, 変数に代入するか, 直接別のメモリ領域の確保や解放の機能へ渡す引数として利用することができる.
メモリ領域を解放するとは, 使わなくなったメモリ領域をメモリマネージャに返却することである.
</p>
<p>
そして, 彼の用意したパターンは以下の BNF で表現できるものであった.
</p>
<pre>
<line> ::= <expr> | <free>
<expr> ::= "(" <expr> ")" | <assign> | "NULL" | <variable> | <malloc> | <clone>
<assign> ::= <variable> "=" <expr>
<malloc> ::= "malloc(" <number> ")"
<free> ::= "free(" <expr> ")"
<clone> ::= "clone(" <expr> ")"
<variable> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I"
| "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R"
| "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
<number> ::= <non_zero_digit> | <number> <digit>
<non_zero_digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<digit> ::= "0" | <non_zero_digit>
</pre>
<p>
変数(variables)は, 参照の入れ物とて機能し, 名前としてアルファベットの大文字一文字を使用できる.
変数は, 今回問題となるヒープとは別の領域に確保されるため, 変数そのものが使用するメモリ量を気にする必要はない.
なお, 変数は明示的に値を代入されない限り, 更新されない.
また, 初期値は特に決まっておらず, どのような値を持っているかわからないことに注意しなければならない.
なお, 変数は評価結果として, その変数の持つ参照を返す.
</p>
<p>
代入(assign)は, 参照の値をコピーする.
右辺の式を評価して得られる参照を左辺の変数にコピーする.
初期化されていない変数や free された変数も代入することができる.
これは, 参照とは領域の場所を示す「値」でしかないため,
別の変数に代入しても, 実際に意図しない領域を操作してしまうことはない.
なお, 代入そのものは, 変数に代入された参照を返す.
</p>
<p>
malloc, free, clone は, メモリマネージャの機能を呼び出ていることを示している.
</p>
<ul>
<li> malloc は, 引数で渡された1以上の整数サイズ分のメモリ領域を確保し, その領域への参照を返す.</li>
<li> free は, 引数に確保済みのメモリ領域への参照を与えることで, その領域を解放する. なお, 評価しても何も返さない.</li>
<li> clone は, 引数に確保済みのメモリ領域への参照を与えることで, その領域をコピーする. 今回の検証では同じサイズ分の領域をもう一つ確保すると考えればよい. </li>
</ul>
<p>
なお, malloc や clone のメモリ確保のアルゴリズム自体は精錬されているため, 割り当て用のメモリ領域が断片化することはない.
また, free した領域は即座に解放され, 再利用可能になる.
ただし, 初期化されていない領域や既に free された領域に対して clone や free した場合,
意図しないメモリ領域に対してコピーや解放が行なわれてしまい, 何が起こるかわからない.
このような動作は, 別のバグの原因となっている可能性があるため, 彼に知らせる必要がある.
与えられたメモリの上限超えて malloc しようとした場合には, NULL という特殊な参照が返される.
同様に clone でコピーされる領域分のメモリが残っていない場合にも, NULL が返される.
</p>
<p>
この NULL は特定のメモリ領域を参照していないことを示す.
通常の参照と同様に NULL は変数に代入でき, 参照を引数にとる clone や free に渡すことができる.
ただし, free に NULL を引数で渡していた場合, 何も起こらないことが保証されている.
また, clone に NULL を引数で渡した場合でも, 何も起こらず, NULL が返される.
</p>
<p>
評価すると参照を返す式(expr)は, "(" ")" を使うことで入れ子にすることができる.
この場合, "(" ")"の内部の評価結果がその外側へ返されることになる.
なお, free は参照を返さないので, 入れ子にすることができない.
</p>
<p>
あなたの仕事は, パターンとして与えられた全ての行を実行した後に,
参照されていない確保済みのメモリ領域のバイト数の合計を計算することである.
なお, 与えられた全ての行を実行した後に, 一つ以上の変数が参照を持っている領域については気にしなくてよい.
また, 別のバグの原因を発見した場合には, 彼に知らせなければならない.
</p>
<p>
あなたは, パターンの分析をするためのプログラムを組むことした.
そのために, 彼の示すいくつかのパターンについて考察した.
</p>
<p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_2365-a" width="500">
</td>
</tr>
<tr>
<td>
<center>
図1
</center>
</td>
</tr>
</table>
</center>
</p>
<p>
図1は, ヒープが 100 バイト存在する状態で, 以下のようなパターンを実行したときの状態の遷移を示している
</p>
<pre>
A=malloc(10)
B=clone(A)
free(A)
</pre>
<p>
まず, 1行目では, malloc によって 10 バイトの領域を確保し, その領域への参照を変数 A に代入している.
残りの使用可能なヒープは, 90 バイトとなる
次に, 2行目では, 先ほど確保した領域への参照を持つ変数 A を clone に渡している.
これにより, 新たに10バイトの領域が確保され, 残りの使用可能なヒープは, 80 バイトとなる.
新たに確保された 10 バイトの領域への参照は, 変数 B に代入される.
そして, 3行目では, 1行目で確保された領域への参照を持つ変数 A を free に渡している.
これにより, 10バイトの領域が解放され, 残りの使用可能なヒープは, 90 バイトとなる.
以上で, このパターンの実行は終了である.
この場合では, 参照されていない確保済みの領域は存在しないため, 検証の結果は 0 バイトとなる.
2行目で確保された 10 バイトの領域は, 変数 B が参照を持っているため, メモリリークとして扱わない.
また, 変数 A は3行目で free に渡された後, 代入によって更新されていない.
そのため, この時点でも先ほど解放された領域への参照を持ったままである.
もしこの後に, この領域を free あるいは clone するような命令があった場合は, 検証結果として Error を出力する必要がある.
</p>
<p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_2365-b" width="500">
</td>
</tr>
<tr>
<td>
<center>
図2
</center>
</td>
</tr>
</table>
</center>
</p>
<p>
図2は, ヒープが100存在する状態で, 以下のようなパターンを実行したときの状態の遷移を示している
</p>
<pre>
A=clone(clone(malloc(10)))
</pre>
<p>
この場合は, まず malloc(10) が実行され, 10バイトの領域が確保される.
この領域への参照はそのまま clone に渡され, さらに 10バイトの領域が確保される.
この clone によって確保された領域も外側の clone に渡され, さらに10バイトの領域が確保される.
最後に確保された領域への参照が変数 A に代入される.
最初の malloc で確保された領域や内側の clone で確保された領域は, どの変数も参照を持っておらず, 解放することができなくなってしまう.
よって, このパターンの検証結果は 20 バイトとなる.
</p>
<h2> Input</h2>
<p>
入力は以下の形式で与えられる.
</p>
<pre>
<i>M</i>
<i>line<sub>1</sub></i>
<i>line<sub>2</sub></i>
<i>line<sub>3</sub></i>
...
<i>line<sub>i</sub></i>
...
</pre>
<p>
入力の形式で用いられる変数の意味は次の通りである.
</p>
<ul>
<li> 1行目の <i>M</i> はヒープの上限であり, 0 <= <i>M</i> <= 5000 である.</li>
<li> <i>line<sub>i</sub></i> は前述 BNF で示される式であり, EOF まで続き,100行を超えない.</li>
<li> <i>line<sub>i</sub></i> は 300 文字を超えないとする</li>
<li> malloc に引数として与えられるメモリ領域の大きさ size は 1 <= size <= 5000 である.</li>
</ul>
<h2> Output</h2>
<p>
入力で与えられた全ての行を実行した後に, 参照されていない確保済みのメモリ領域のバイト数の合計を出力せよ.
メモリリーク以外のエラーが発生していた場合には, "Error" と出力せよ.
</p>
<h2> Sample Input 1</h2>
<pre>
100
A=malloc(10)
B=clone(A)
free(A)
</pre>
<h2> Sample Output 1</h2>
<pre>
0
</pre>
<h2> Sample Input 2</h2>
<pre>
100
A=clone(clone(malloc(10)))
</pre>
<h2> Sample Output 2</h2>
<pre>
20
</pre>
<h2> Sample Input 3</h2>
<pre>
30
clone(clone(clone(clone(malloc(10)))))
</pre>
<h2> Sample Output 3</h2>
<pre>
30
</pre>
<h2> Sample Input 4</h2>
<pre>
100
free(A)
A=malloc(12)
NULL
N=clone(NULL)
</pre>
<h2> Sample Output 4</h2>
<pre>
Error
</pre>
</body>
</html> |
p03515 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke Festival 2017 will be held in a tree with <var>N</var> vertices numbered <var>1,2, ...,N</var>.
The <var>i</var>-th edge connects Vertex <var>a_i</var> and <var>b_i</var>, and has <em>joyfulness</em> <var>c_i</var>.</p>
<p>The staff is Snuke and <var>N-1</var> black cats.
Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other <var>N-1</var> vertices.</p>
<p>For each vertex, calculate the <em>niceness</em> when the headquarters are set up in that vertex.
The niceness when the headquarters are set up in Vertex <var>i</var> is calculated as follows:</p>
<ul>
<li>Let <var>X=0</var>.</li>
<li>For each integer <var>j</var> between <var>1</var> and <var>N</var> (inclusive) except <var>i</var>, do the following:<ul>
<li>Add <var>c</var> to <var>X</var>, where <var>c</var> is the smallest joyfulness of an edge on the path from Vertex <var>i</var> to Vertex <var>j</var>.</li>
</ul>
</li>
<li>The niceness is the final value of <var>X</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{5}</var></li>
<li><var>1 \leq a_i,b_i \leq N</var></li>
<li><var>1 \leq c_i \leq 10^{9}</var></li>
<li>The given graph is a tree.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>200</var> points, <var>N \leq 1000</var>.</li>
<li>In the test set worth <var>200</var> points, <var>c_i \leq 2</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line must contain the niceness when the headquarters are set up in Vertex <var>i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 10
2 3 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>20
30
30
</pre>
<ul>
<li>The figure below shows the case when headquarters are set up in each of the vertices <var>1</var>, <var>2</var> and <var>3</var>.</li>
<li>The number on top of an edge denotes the joyfulness of the edge, and the number below an vertex denotes the smallest joyfulness of an edge on the path from the headquarters to that vertex.</li>
</ul>
<div style="text-align: center;">
<img alt="1ee10aa2a1bf5e43e05161f37d88bdc1.png" src="https://atcoder.jp/img/asaporo2/1ee10aa2a1bf5e43e05161f37d88bdc1.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
6 3 2
13 3 1
1 13 2
7 1 2
8 1 1
2 8 2
2 12 2
5 2 2
2 11 2
10 2 2
10 9 1
9 14 2
4 14 1
11 15 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>16
20
15
14
20
15
16
20
15
20
20
20
16
15
20
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>19
19 14 48
11 19 23
17 14 30
7 11 15
2 19 15
2 18 21
19 10 43
12 11 25
3 11 4
5 19 50
4 11 19
9 12 29
14 13 3
14 6 12
14 15 14
5 1 6
8 18 13
7 16 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>103
237
71
263
370
193
231
207
299
358
295
299
54
368
220
220
319
237
370
</pre></section>
</div>
</span> |
p01528 |
<h1>I - 宝探し</h1>
<h2>問題文</h2>
<p>
わたしはある宝探しの依頼を受けた.<br>
どうやら,この近くの地中 <var>2W × 2H</var> の範囲内にお宝が埋まっているらしい.<br>
わたしの得意なダウジングを使えば,現在の位置からお宝がどの方向にねむっているのか知ることができる.
</p>
<p>
ただ,わたしの能力はその日の体調による影響が大きく,今日はダウジングをした時に最大で <var>E</var> 度まで誤差が出てしまいそうだ.<br>
また,わたしの体力にも限界はある.1日に200回までしかダウジングを行うことはできない.
</p>
<p>
わたしは考えることは苦手だ.<br>
あなたには,宝を見つけるためにどこでダウジングをするべきかの指示を出していただきたい.
</p>
<h2>入出力形式</h2>
<p>
最初の入力は以下の形式で与えられる.入力は全て小数12桁までの実数で与えられる.
</p>
<pre>
<var>W</var> <var>H</var> <var>E</var>
</pre>
<p>
この入力は,宝の埋まっている座標 <var>(x,y)</var> が,
</p>
<ul>
<li><var>-W</var> ≤ <var>x</var> ≤ <var>W</var></li>
<li><var>-H</var> ≤ <var>y</var> ≤ <var>H</var></li>
</ul>
<p>
を満たし,またダウジングの結果の誤差が <var>E</var> 度以下であることを表す.
</p>
<p>
以降,あなたはダウジングを行う場所を指定し結果を得るか,もしくは,宝の場所を確定したと伝えることができる.
</p>
<p>地点 <var>(x,y)</var> でダウジングを行い,結果を得るには
</p>
<pre class="prettyprint">printf("? %.12f %.12f\n", x, y); fflush(stdout);</pre>
<p>
とする.次に,
</p>
<pre class="prettyprint">scanf("%lf", &degree);</pre>
<p>
とするとダウジングの結果が得られる.<br>
結果の角度 <var>degree</var> は,<var>(x,y)</var> から宝のある方向を<var>θ</var> とした時,<var>[θ-E,θ+E]</var> の一様分布によって生成される.<br>
宝のある地点でダウジングを行った場合,<var>θ=0</var> となる.<br>
角度はx軸正方向が0度,y軸正方向が+90度とする.<br>
もし <var>-180 ≤ degree ≤ 180 </var> を満たしてない場合,この範囲に収まる様に <var> degree</var> は修正される.
</p>
<p>地点 <var>(x,y)</var> に宝が存在すると伝える場合には
</p>
<pre class="prettyprint">printf("! %.12f %.12f\n", x, y); fflush(stdout);</pre>
<p>
とする.<br>
このとき,実際の宝の位置との絶対誤差が <a href="http://mathworld.wolfram.com/L-Infinity-Norm.html"><var>L<sup>∞</sup></var>ノルム</a> で 0.5 以下になっていなければならない.
なお,ダウジングや宝の位置の指定以外の出力を行った場合は誤答(<i>Wrong Answer</i>)と判定される.
</p>
<!--
<p>
なお参考のため,実際にやりとりを行うプログラムを <a href="/img/other/kupc2012/reactive.zip">reactive.zip</a> に置いている.
</p>
-->
<h2>制約</h2>
<ul>
<li><var>0</var> ≤ <var>W</var> ≤ <var>10<sup>4</sup></var></li>
<li><var>0</var> ≤ <var>H</var> ≤ <var>10<sup>4</sup></var></li>
<li><var>0</var> ≤ <var>E</var> ≤ <var>120</var></li>
<li>入力値は全て小数12桁までの実数である.</li>
<li>ダウジングは最大で 200 回まで行える.それを越えると誤答<!--(<i>Query Limit Exceeded</i>)-->となる.</li>
</ul>
<p>
この問題の判定には,3 点分のテストケースのグループが設定されている.このグループに含まれるテストケースは上記の制約に加えて下記の制約も満たす.
</p>
<ul>
<li><var>E = 0</var></li>
</ul>
<h2>入出力例</h2>
<pre>
<!--<table class = "table table-striped table-bordered table-condensed">-->
<table class="withborder">
<tr><th>プログラムの出力</th><th>プログラムへの入力</th></tr>
<tr><td></td><td>
100 100 0
</td></tr>
<tr><td>? -97.30147375 -55.03559390</td><td></td></tr>
<tr><td></td><td>45.8958081317</td></tr>
<tr><td>? 44.46472896 -54.50272726</td><td></td></tr>
<tr><td></td><td>110.928234444</td></tr>
<tr><td> ... </td><td> ... </td></tr>
<tr><td>! 4.50000018 50.00000005</td><td></td></tr>
</table>
</pre>
<p>
最初にプログラムは宝のある範囲 <var>W,H</var> とダウジングの精度 <var>E</var> を受け取る.<br>
その後,プログラムは (-97.3, -55.0) で1回目のダウジングを行い,宝のある方向は 45.8 度の方向だという情報を得ている.<br>
次に,プログラムは (44.5, -54.5) で2回目のダウジングを行い,宝のある方向は 110.9 度の方向だという情報を得ている.<br>
その後何度かダウジングを行い,最終的に宝のある位置は (4.5, 50.0) であると出力している.
</p>
<hr>
<address>Writer : 森槙悟,楠本充,花田裕一朗</address>
<!-- <address>Tester:</address> -->
|
p00769 |
<h3>Hierarchical Democracy</h3>
<p>
The presidential election in Republic of Democratia is carried out through multiple stages as follows.
</p>
<ol>
<li>There are exactly two presidential candidates.</li>
<li>At the first stage, eligible voters go to the polls of his/her electoral district.
The winner of the district is the candidate who takes a majority of the votes.
Voters cast their ballots only at this first stage.</li>
<li>A district of the <i>k</i>-th stage (<i>k</i> > 1) consists of multiple districts of the (<i>k</i> − 1)-th stage. In contrast, a district of the (<i>k</i> − 1)-th stage is a sub-district of one and only one district of the <i>k</i>-th stage. The winner of a district of the <i>k</i>-th stage is the candidate who wins in a majority of its sub-districts of the (<i>k</i> − 1)-th stage.</li>
<li>The final stage has just one nation-wide district. The winner of the final stage is chosen as the president.</li>
</ol>
<p>
You can assume the following about the presidential election of this country.
</p>
<ul>
<li>Every eligible voter casts a vote.</li>
<li>The number of the eligible voters of each electoral district of the first stage is odd.</li>
<li>The number of the sub-districts of the (<i>k</i> − 1)-th stage that constitute a district of the <i>k</i>-th stage (<i>k</i> > 1) is also odd.</li>
</ul>
<p>
This means that each district of every stage has its winner (there is no tie).
</p>
<p>
Your mission is to write a program that finds a way to win the presidential election with the minimum number of votes.
Suppose, for instance, that the district of the final stage has three sub-districts of the first stage and that the numbers of the eligible voters of the sub-districts are 123, 4567, and 89, respectively.
The minimum number of votes required to be the winner is 107, that is, 62 from the first district and 45 from the third.
In this case, even if the other candidate were given all the 4567 votes in the second district, s/he would inevitably be the loser.
Although you might consider this election system unfair, you should accept it as a reality.
</p>
<h3>Input</h3>
<p>The entire input looks like:</p>
<blockquote>
<i>the number of datasets (=n)</i> <br>
<i>1st dataset</i> <br>
<i>2nd dataset</i> <br>
… <br>
<i>n-th dataset</i> <br>
</blockquote>
<p>
The number of datasets, <i>n</i>, is no more than 100.
</p>
<p>
The number of the eligible voters of each district and the part-whole relations among districts are denoted as follows.
</p>
<ul>
<li>An electoral district of the first stage is denoted as [<i>c</i>], where <i>c</i> is the number of the eligible voters of the district.</li>
<li>A district of the <i>k</i>-th stage (<i>k</i> > 1) is denoted as [<i>d</i><sub>1</sub><i>d</i><sub>2</sub>…<i>d<sub>m</sub></i>], where <i>d</i><sub>1</sub>, <i>d</i><sub>2</sub>, …, <i>d<sub>m</sub></i> denote its sub-districts of the (<i>k</i> − 1)-th stage in this notation.</li>
</ul>
<p>
For instance, an electoral district of the first stage that has 123 eligible voters is denoted as [123].
A district of the second stage consisting of three sub-districts of the first stage that have 123, 4567, and 89 eligible voters, respectively, is denoted as [[123][4567][89]].
</p>
<p>
Each dataset is a line that contains the character string denoting the district of the final stage in the aforementioned notation.
You can assume the following.
</p>
<ul>
<li>The character string in each dataset does not include any characters except digits ('0', '1', …, '9') and square brackets ('[', ']'), and its length is between 11 and 10000, inclusive.</li>
<li>The number of the eligible voters of each electoral district of the first stage is between 3 and 9999, inclusive.</li>
</ul>
<p>
The number of stages is a nation-wide constant.
So, for instance, [[[9][9][9]][9][9]] never appears in the input.
[[[[9]]]] may not appear either since each district of the second or later stage must have multiple sub-districts of the previous stage.
</p>
<h3>Output</h3>
<p>
For each dataset, print the minimum number of votes required to be the winner of the presidential election in a line.
No output line may include any characters except the digits with which the number is written.
</p>
<h3>Sample Input</h3>
<pre>
6
[[123][4567][89]]
[[5][3][7][3][9]]
[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8843]]
</pre>
<h3>Output for the Sample Input</h3>
<pre>
107
7
175
95
21
3599
</pre>
|
p02754 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has many red balls and blue balls. Now, he will place them in a row.</p>
<p>Initially, there is no ball placed.</p>
<p>Takahashi, who is very patient, will do the following operation <var>10^{100}</var> times:</p>
<ul>
<li>Place <var>A</var> blue balls at the end of the row of balls already placed. Then, place <var>B</var> red balls at the end of the row.</li>
</ul>
<p>How many blue balls will be there among the first <var>N</var> balls in the row of balls made this way?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{18}</var></li>
<li><var>A, B \geq 0</var></li>
<li><var>0 < A + B \leq 10^{18}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of blue balls that will be there among the first <var>N</var> balls in the row of balls.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Let <code>b</code> denote a blue ball, and <code>r</code> denote a red ball. The first eight balls in the row will be <code>bbbrrrrb</code>, among which there are four blue balls.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 0 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>He placed only red balls from the beginning.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
<p>Among <code>bbrrrr</code>, there are two blue balls.</p></section>
</div>
</span> |
p03846 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people, conveniently numbered <var>1</var> through <var>N</var>.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person <var>i</var> is <var>A_i</var>.</p>
<p>Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo <var>10^9+7</var>.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print <var>0</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N≦10^5</var></li>
<li><var>0≦A_i≦N-1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible orders in which they were standing, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
2 4 4 0 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four possible orders, as follows:</p>
<ul>
<li><var>2,1,4,5,3</var></li>
<li><var>2,5,4,1,3</var></li>
<li><var>3,1,4,5,2</var></li>
<li><var>3,5,4,1,2</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
6 4 0 2 4 0 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Any order would be inconsistent with the reports, thus the answer is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
7 5 1 1 7 3 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>16
</pre></section>
</div>
</span> |
p00293 |
<h1>路線バスの時刻表</h1>
<p>
バスマニアの健次郎君は、A市内のバスをよく利用しています。ある日ふと、健次郎君の家の前のバス停から出発するすべてのバスを写真に収めることを思い立ちました。このバス停には飯盛山行きと鶴ケ城行きの2つのバス路線が通ります。各路線の時刻表は手に入れましたが、1つの時刻表としてまとめた方がバス停で写真が撮りやすくなります。
</p>
<p>
健次郎君を助けるために、2つの路線の時刻表を、0時0分を基準として出発時刻が早い順に1つの時刻表としてまとめるプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var> <var>h</var><sub>1</sub> <var>m</var><sub>1</sub> <var>h</var><sub>2</sub> <var>m</var><sub>2</sub> ... <var>h<sub>N</sub></var> <var>m<sub>N</sub></var>
<var>M</var> <var>k</var><sub>1</sub> <var>g</var><sub>1</sub> <var>k</var><sub>2</sub> <var>g</var><sub>2</sub> ... <var>k<sub>M</sub></var> <var>g<sub>M</sub></var>
</pre>
<p>
1行目に、飯盛山行きのバスの数を表す整数 <var>N</var> (1 ≤ <var>N</var> ≤ 100) と、それに続いて飯盛山行きのバス出発時刻が早い順に与えられる。出発時刻は整数 <var>h<sub>i</sub></var> (0 ≤ <var>h<sub>i</sub></var> ≤ 23) と <var>m<sub>i</sub></var> (0 ≤ <var>m<sub>i</sub></var> ≤ 59) からなり、<var>h<sub>i</sub></var> 時 <var>m<sub>i</sub></var> 分に <var>i</var> 番目のバスが出発することを表す。2行目に、鶴ケ城行きのバスの数を表す整数 <var>M</var> (1 ≤ <var>M</var> ≤ 100) と、それに続いて鶴ケ城行きのバス出発時刻が早い順に与えられる。出発時刻は整数 <var>k<sub>i</sub></var> (0 ≤ <var>k<sub>i</sub></var> ≤ 23) と <var>g<sub>i</sub></var> (0 ≤ <var>g<sub>i</sub></var> ≤ 59) からなり、<var>k<sub>i</sub></var> 時 <var>g<sub>i</sub></var> 分に <var>i</var> 番目のバスが出発することを表す。同じ路線には、同じ時刻に出発するバスはないものとする。
</p>
<h2>出力</h2>
<p>
2つの路線の時刻表を、0時0分を基準として出発時刻が早い順に1つにまとめた時刻表を1行に出力する。ただし、同じ時刻に複数のバスが出発するときは1つだけを出力する。出発時刻の時と分を <span>:</span> で区切る。分が1桁のときは左に0をひとつ加えて2桁で出力する。時刻と時刻の間は空白1 つで区切る。
</p>
<h2>入出力例</h2>
<br>
<h2>入力例1 </H2>
<pre>
2 9 8 15 59
1 8 27
</pre>
<h2>出力例1</h2>
<pre>
8:27 9:08 15:59
</pre>
<h2>入力例2 </h2>
<pre>
2 0 0 21 0
3 7 30 21 0 23 7
</pre>
<h2>出力例2</h2>
<pre>
0:00 7:30 21:00 23:07
</pre> |
p00339 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ゲームの攻略</H1>
<p>
あなたは所属するプログラミング部の部室から古びたボードゲームを発見しました。面白そうなので遊んでみることにしました。
</p>
<p>
このゲームは <var>M</var> 個のイベントから成り、時刻 <var>t<sub>i</sub></var> にイベント <var>i</var> を攻略しなければいけません。ただし、そのときにあなたの強さは <var>s<sub>i</sub></var> 以上である必要があり、<var>s<sub>i</sub></var> 以上にできない場合はゲームオーバーになります。ゲーム開始時(時刻0)のあなたの強さは0ですが、アイテムを買うことで強さを増加させることができます。ゲーム開始時のあなたの所持金は0ですが、1単位時間あたり1増加します。
</p>
<p>
ボードにはそれぞれ1から <var>N</var> の番号が付けられた <var>N</var> 個のアイテムが順番に並べられており、アイテム <var>i</var> の値段は <var>v<sub>i</sub></var> で、それを購入するとあなたの強さが <var>h<sub>i</sub></var> 増加します。アイテムは所持金が十分であれば好きな時刻に好きな数だけ購入することができますが、残っているアイテムの中で番号が小さいものから順に選ばなければなりません。各アイテムは1度購入すると消滅します。
</p>
<p>
また、同じ時刻に複数のアイテムを連続で買うことができ、このとき隣り合うアイテムの <var>h<sub>i</sub></var> の差分の和をボーナスとして得ることができます。例えば、ある時刻にアイテム1,2,3を同時に買った場合、<var>h<sub>1</sub></var> + <var>h<sub>2</sub></var> + <var>h<sub>3</sub></var> に加えて|<var>h<sub>1</sub></var> - <var>h<sub>2</sub></var>| + |<var>h<sub>2</sub></var> - <var>h<sub>3</sub></var>| だけあなたの強さが増加します。
</p>
<p>
あなたは、全てのイベントを攻略した後の所持金を最大化したいと考えています。
</p>
<p>
アイテムの情報とイベントの情報を入力とし、すべてのイベントを攻略した後の所持金の最大値を出力するプログラムを作成せよ。
</p>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var> <var>M</var>
<var>v<sub>1</sub></var> <var>h<sub>1</sub></var>
<var>v<sub>2</sub></var> <var>h<sub>2</sub></var>
:
<var>v<sub>N</sub></var> <var>h<sub>N</sub></var>
<var>t<sub>1</sub></var> <var>s<sub>1</sub></var>
<var>t<sub>2</sub></var> <var>s<sub>2</sub></var>
:
<var>t<sub>M</sub></var> <var>s<sub>M</sub></var>
</pre>
<p>
1行目にアイテムの数 <var>N</var> (1 ≤ <var>N</var> ≤ 3000) とイベントの数 <var>M</var> (1 ≤ <var>M</var> ≤ 1000) が与えられる。続く <var>N</var> 行にアイテム <var>i</var> の値段 <va>v<sub>i</sub></var> と強さの増加量 <var>h<sub>i</sub></var> (1 ≤ <var>v<sub>i</sub></var>, <var>h<sub>i</sub></var> ≤ 100000) が与えられる。続く <var>M</var> 行にイベント <var>i</var> の時刻 <var>t<sub>i</sub></var> と条件 <var>s<sub>i</sub></var> (1 ≤ <var>t<sub>i</sub></var>, <var>s<sub>i</sub></var> ≤ 100000) が与えられる。ただし、<var>i</var> < <var>j</var> のとき、<var>t<sub>i</sub></var> < <var>t<sub>j</sub></var> とする。入力はすべて整数で与えられる。
</p>
<h2>Output</h2>
<p>
所持金の最大値を1行に出力する。ただし、攻略することができない場合には「-1」を出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
5 4
3 3
2 1
1 5
4 2
2 6
4 1
8 2
10 4
12 17
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
5 4
3 3
2 1
1 5
4 2
2 6
4 1
8 2
10 4
12 30
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre> |
p02304 |
<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>Segment Intersections: Manhattan Geometry</H1>
<p>
For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them.
</p>
<H2>Input</H2>
<p>
In the first line, the number of segments $n$ is given. In the following $n$ lines, the $i$-th segment is given by coordinates of its end points in the following format:
<br>
<br>
$x_1 \; y_1 \; x_2 \; y_2$
<br>
<br>
The coordinates are given in integers.
</p>
<H2>Output</H2>
<p>
Print the number of intersections in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>$1 \leq n \leq 100,000$</li>
<li>$ -1,000,000,000 \leq x_1, y_1, x_2, y_2 \leq 1,000,000,000$</li>
<li>Two parallel segments never overlap or touch.
<li>The number of intersections $\leq 1,000,000$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
6
2 2 2 5
1 3 5 3
4 1 4 4
5 2 7 2
6 1 6 3
6 5 6 7
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre> |
p02611 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>N</var>. Snuke will choose integers <var>s_1</var>, <var>s_2</var>, <var>n_1</var>, <var>n_2</var>, <var>u_1</var>, <var>u_2</var>, <var>k_1</var>, <var>k_2</var>, <var>e_1</var>, and <var>e_2</var> so that all of the following six conditions will be satisfied:</p>
<ul>
<li><var>0 \leq s_1 < s_2</var></li>
<li><var>0 \leq n_1 < n_2</var></li>
<li><var>0 \leq u_1 < u_2</var></li>
<li><var>0 \leq k_1 < k_2</var></li>
<li><var>0 \leq e_1 < e_2</var></li>
<li><var>s_1 + s_2 + n_1 + n_2 + u_1 + u_2 + k_1 + k_2 + e_1 + e_2 \leq N</var></li>
</ul>
<p>For every possible choice <var>(s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2)</var>, compute <var>(s_2 − s_1)(n_2 − n_1)(u_2 − u_1)(k_2 - k_1)(e_2 - e_1)</var>, and find the sum of all computed values, modulo <var>(10^{9} +7)</var>.</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 100</var></li>
<li><var>1 \leq N \leq 10^{9}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>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>
</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>4
4
6
10
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
11
4598
257255556
</pre>
<ul>
<li>When <var>N=4</var>, there is no possible choice <var>(s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2)</var>. Thus, the answer is <var>0</var>.</li>
<li>When <var>N=6</var>, there are six possible choices <var>(s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2)</var> as follows:<ul>
<li><var>(0,1,0,1,0,1,0,1,0,1)</var></li>
<li><var>(0,2,0,1,0,1,0,1,0,1)</var></li>
<li><var>(0,1,0,2,0,1,0,1,0,1)</var></li>
<li><var>(0,1,0,1,0,2,0,1,0,1)</var></li>
<li><var>(0,1,0,1,0,1,0,2,0,1)</var></li>
<li><var>(0,1,0,1,0,1,0,1,0,2)</var></li>
</ul>
</li>
<li>We have one choice where <var>(s_2 − s_1)(n_2 − n_1)(u_2 − u_1)(k_2 - k_1)(e_2 - e_1)</var> is <var>1</var> and five choices where <var>(s_2 − s_1)(n_2 − n_1)(u_2 − u_1)(k_2 - k_1)(e_2 - e_1)</var> is <var>2</var>, so the answer is <var>11</var>.</li>
<li>Be sure to find the sum modulo <var>(10^{9} +7)</var>.</li>
</ul></section>
</div>
</span> |
p03903 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi found an undirected connected graph with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>1</var> through <var>N</var>. The <var>i</var>-th edge connects vertices <var>a_i</var> and <var>b_i</var>, and has a weight of <var>c_i</var>.</p>
<p>He will play <var>Q</var> rounds of a game using this graph. In the <var>i</var>-th round, two vertices <var>S_i</var> and <var>T_i</var> are specified, and he will choose a subset of the edges such that any vertex can be reached from at least one of the vertices <var>S_i</var> or <var>T_i</var> by traversing chosen edges.</p>
<p>For each round, find the minimum possible total weight of the edges chosen by Takahashi.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ N ≦ 4,000</var></li>
<li><var>1 ≦ M ≦ 400,000</var></li>
<li><var>1 ≦ Q ≦ 100,000</var></li>
<li><var>1 ≦ a_i,b_i,S_i,T_i ≦ N</var></li>
<li><var>1 ≦ c_i ≦ 10^{9}</var></li>
<li><var>a_i \neq b_i</var></li>
<li><var>S_i \neq T_i</var></li>
<li>The given graph is connected.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>200</var> points, <var>Q = 1</var>.</li>
<li>In the test set worth another <var>300</var> points, <var>Q ≦ 3000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
<var>a_2</var> <var>b_2</var> <var>c_2</var>
:
<var>a_M</var> <var>b_M</var> <var>c_M</var>
<var>Q</var>
<var>S_1</var> <var>T_1</var>
<var>S_2</var> <var>T_2</var>
:
<var>S_Q</var> <var>T_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the minimum possible total weight of the edges chosen by Takahashi.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
1 2 3
2 3 4
3 4 5
2
2 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
7
</pre>
<p>We will examine each round:</p>
<ul>
<li>In the <var>1</var>-st round, choosing edges <var>1</var> and <var>3</var> achieves the minimum total weight of <var>8</var>.</li>
<li>In the <var>2</var>-nd round, choosing edges <var>1</var> and <var>2</var> achieves the minimum total weight of <var>7</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 6
1 3 5
4 1 10
2 4 6
3 2 2
3 4 5
2 1 3
1
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre>
<p>This input satisfies the additional constraints for both partial scores.</p></section>
</div>
</span> |
p00786 |
<H1><font color="#000">Problem G:</font>BUT We Need a Diagram</H1>
<p>
Consider a data structure called BUT (Binary and/or Unary Tree). A BUT is defined inductively as follows:
</p>
<ul>
<li>Let <i>l</i> be a letter of the English alphabet, either lowercase or uppercase (n the sequel, we say simply "a letter"). Then, the object that consists only of <i>l</i>, designating <i>l</i> as its label, is a BUT. In this case, it is called a 0-ary BUT.</li>
<li>Let <i>l</i> be a letter and <i>C</i> a BUT. Then, the object that consists of <i>l</i> and <i>C</i>, designating <i>l</i> as its label and <i>C</i> as its component, is a BUT. In this case, it is called a unary BUT.</li>
<li>Let <i>l</i> be a letter, <i>L</i> and <i>R</i> BUTs. Then, the object that consists of <i>l</i>, <i>L</i> and <i>R</i>, designating <i>l</i> as its label, <i>L</i> as its left component, and <i>R</i> as its right component, is a BUT. In this case, it is called a binary BUT.</li>
</ul>
<p>
A BUT can be represented by a expression in the following way.
</p>
<ul>
<li>When a BUT <i>B</i> is 0-ary, its representation is the letter of its label.</li>
<li>When a BUT <i>B</i> is unary, its representation is the letter of its label followed by the parenthesized representation of its component.</li>
<li>When a BUT <i>B</i> is binary, its representation is the letter of its label, a left parenthesis, the representation of its left component, a comma, the representation of its right component, and a right parenthesis, arranged in this order.</li>
</ul>
<p>
Here are examples:
</p>
<pre>
a
A(b)
a(a,B)
a(B(c(D),E),f(g(H,i)))
</pre>
<p>
Such an expression is concise, <i>but</i> a diagram is much more appealing to our eyes. We prefer a diagram:
</p>
<pre>
D H i
- ---
c E g
--- -
B f
----
a
</pre>
<p>
to the expression <pre>a(B(c(D),E),f(g(H,i)))</pre>
</p>
<pre>
Your mission is to write a program that converts the expression representing a BUT into its diagram. We want to keep a diagram as compact as possible assuming that we display it on a conventional character terminal with a fixed pitch font such as Courier. Let's define the diagram <i>D</i> for BUT <i>B</i> inductively along the structure of <i>B</i> as follows:
</pre>
<ul>
<li>When <i>B</i> is 0-ary, <i>D</i> consists only of a letter of its label. The letter is called the root of <i>D</i>, and also called the leaf of <i>D</i></li>
<li>When <i>B</i> is unary, <i>D</i> consists of a letter <i>l</i> of its label, a minus symbol <i>S</i>, and the diagram <i>C</i> for its component, satisfying the following constraints:
<ul>
<li><i>l</i> is just below <i>S</i></li>
<li>The root of <i>C</i> is just above <i>S</i></li>
</ul>
<i>l</i> is called the root of <i>D</i>, and the leaves of <i>C</i> are called the leaves of <i>D</i>.
</li>
<li>When <i>B</i> is binary, <i>D</i> consists of a letter <i>l</i> of its label, a sequence of minus symbols <i>S</i>, the diagram <i>L</i> for its left component, and the diagram <i>R</i> for its right component, satisfying the following constraints:
<ul>
<li><i>S</i> is contiguous, and is in a line.</li>
<li><i>l</i> is just below the central minus symbol of <i>S</i>, where, if the center of <i>S</i> locates on a minus symbol <i>s</i>, <i>s</i> is the central, and if the center of <i>S</i> locates between adjacent minus symbols, the left one of them is the central.</li>
<li>The root of <i>L</i> is just above the left most minus symbols of <i>S</i>, and the rot of <i>R</i> is just above the rightmost minus symbol of <i>S</i></li>
<li>In any line of <i>D</i>, <i>L</i> and <i>R</i> do not touch or overlap each other.</li>
<li>No minus symbols are just above the leaves of <i>L</i> and <i>R</i>.</li>
</ul>
<i>l</i> is called the root of <i>D</i>, and the leaves of <i>L</i> and <i>R</i> are called the leaves of <i>D</i>
</li>
</ul>
<H2>Input</H2>
<p>
The input to the program is a sequence of expressions representing BUTs. Each expression except the last one is terminated by a semicolon. The last expression is terminated by a period. White spaces (tabs and blanks) should be ignored. An expression may extend over multiple lines. The number of letter, i.e., the number of characters except parentheses, commas, and white spaces, in an expression is at most 80.
</p>
<p>
You may assume that the input is syntactically correct and need not take care of error cases.
</p>
<H2>Output</H2>
<p>
Each expression is to be identified with a number starting with 1 in the order of occurrence in the input. Output should be produced in the order of the input.
</p>
<p>
For each expression, a line consisting of the identification number of the expression followed by a colon should be produced first, and then, the diagram for the BUT represented by the expression should be produced.
</p>
<p>
For diagram, output should consist of the minimum number of lines, which contain only letters or minus symbols together with minimum number of blanks required to obey the rules shown above.
</p>
<H2>Sample Input</H2>
<pre>
a(A,b(B,C));
x( y( y( z(z), v( s, t ) ) ), u ) ;
a( b( c,
d(
e(f),
g
)
),
h( i(
j(
k(k,k),
l(l)
),
m(m)
)
)
);
a(B(C),d(e(f(g(h(i(j,k),l),m),n),o),p))
.
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1:
B C
---
A b
---
a
2:
z s t
- ---
z v
----
y
-
y u
---
x
3:
k k l
--- -
f k l m
- ---- -
e g j m
--- -----
c d i
--- -
b h
-------
a
4:
j k
---
i l
---
h m
---
g n
---
f o
---
C e p
- ---
B d
----
a
</pre>
<!-- from UVA-->
|
p01894 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>D: DAG トリオ / DAG Trio</h1>
<p>
この問題は G: DAG Trio (Hard) と制約のみが異なる同じ設定の問題です。
</p>
<h2>プロローグ</h2>
<p>
弟は最近「だぐとりお」が欲しいとしきりに呟いています。
心配になった兄が調べたところ、弟のクラスでは $k$-DAG (有向グラフであって、ある $k$ 個の辺を削除すると、辺の向きを無視したときの連結成分数を $k$ にでき、かつそれら全てが DAG である) が流行っており、
3-DAG を特に DAG トリオと呼ぶことを突き止めました。
弟に尊敬されたい兄は、与えられたグラフが DAG トリオかどうかを判別するプログラムを作成することにしました。
</p>
<h2>問題文</h2>
<p>
$N$ 頂点 $M$ 辺の有向グラフが与えられます。
各頂点には $1$ から $N$ まで番号が振られています。
各有向辺には $1$ から $M$ まで番号が振られています。
有向辺 $i$ は頂点 $a_i$ から $b_i$ に向かいます。
グラフは連結かつ単純です (辺の向きを無視すると、任意の 2 点間に道があり自己ループと多重辺がありません)。
与えられたグラフが DAG トリオならば ”YES”、そうでないなら ”NO” を出力してください。
</p>
<h2>入力</h2>
<p>
$N \ M$<br>
$a_1 \ b_1$<br>
$a_2 \ b_2$<br>
$\vdots$<br>
$a_M \ b_M$<br>
</p>
<h2>制約</h2>
<p>
$3 \le N \le 500$<br>
$\max(3, N−1) \le M \le 1000$<br>
$1 \le a_i, b_i \le N$<br>
グラフは辺の向きを無視したときに連結である。<br>
各 $i$ に対して$a_i \neq b_i$<br>
異なる $i, j$ に対して $\{a_i, b_i\} \neq \{a_j, b_j\}$<br>
</p>
<h2>出力</h2>
<p>
”YES” または ”NO” を $1$ 行で出力してください。
</p>
<h2>サンプル</h2>
<h3>サンプル入力1</h3>
<pre>
3 3
1 2
2 3
3 1
</pre>
<h3>サンプル出力1</h3>
<pre>
YES
</pre>
<h3>サンプル入力2</h3>
<pre>
6 7
1 2
2 3
4 3
4 5
5 6
6 4
3 6
</pre>
<h3>サンプル出力2</h3>
<pre>
YES
</pre>
<h3>サンプル入力3</h3>
<pre>
7 10
4 2
4 7
4 6
2 7
2 5
2 1
5 6
1 3
6 3
4 3
</pre>
<h3>サンプル出力3</h3>
<pre>
NO
</pre>
<h3>サンプル入力4</h3>
<pre>
4 4
1 2
3 2
4 3
2 4
</pre>
<h3>サンプル出力4</h3>
<pre>
YES
</pre>
<h3>サンプル入力5</h3>
<pre>
8 9
5 1
3 8
1 2
4 8
4 7
7 5
6 5
3 2
4 2
</pre>
<h3>サンプル出力5</h3>
<pre>
YES
</pre> |
p02241 |
<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>Minimum Spanning Tree</H1>
<p>
For a given weighted graph $G = (V, E)$, find the minimum spanning tree (MST) of $G$ and print total weight of edges belong to the MST.
</p>
<H2>Input</H2>
<p>
In the first line, an integer $n$ denoting the number of vertices in $G$ is given. In the following $n$ lines, a $n \times n$ adjacency matrix $A$ which represents $G$ is given.
$a_{ij}$ denotes the weight of edge connecting vertex $i$ and vertex $j$. If there is no edge between $i$ and $j$, $a_{ij}$ is given by -1.
</p>
<H2>Output</H2>
<p>
Print the total weight of the minimum spanning tree of $G$.
</p>
<H2>Constraints</H2>
<ul>
<li>$1 \leq n \leq 100$</li>
<li>$0 \leq a_{ij} \leq 2,000$ (if $a_{ij} \neq -1$)</li>
<li>$a_{ij} = a_{ji}$</li>
<li>$G$ is a connected graph</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
-1 2 3 1 -1
2 -1 -1 4 -1
3 -1 -1 1 1
1 4 1 -1 3
-1 -1 1 3 -1
</pre>
<H2>Sample Output 1</H2>
<pre>
5
</pre>
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p> |
p03000 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A ball will bounce along a number line, making <var>N + 1</var> bounces. It will make the first bounce at coordinate <var>D_1 = 0</var>, and the <var>i</var>-th bounce <var>(2 \leq i \leq N+1)</var> at coordinate <var>D_i = D_{i-1} + L_{i-1}</var>.</p>
<p>How many times will the ball make a bounce where the coordinate is at most <var>X</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq L_i \leq 100</var></li>
<li><var>1 \leq X \leq 10000</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>X</var>
<var>L_1</var> <var>L_2</var> <var>...</var> <var>L_{N-1}</var> <var>L_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of times the ball will make a bounce where the coordinate is at most <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 6
3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The ball will make a bounce at the coordinates <var>0</var>, <var>3</var>, <var>7</var> and <var>12</var>, among which two are less than or equal to <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 9
3 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>The ball will make a bounce at the coordinates <var>0</var>, <var>3</var>, <var>6</var>, <var>9</var> and <var>12</var>, among which four are less than or equal to <var>9</var>.</p></section>
</div>
</span> |
p01197 |
<H1><font color="#000"></font>Rakunarok</H1>
<!-- Problem F -->
<p>
You are deeply disappointed with the real world, so you have decided to live the rest of your life in the world of
MMORPG (Massively Multi-Player Online Role Playing Game). You are no more concerned about the time you
spend in the game: all you need is <i>efficiency</i>.
</p>
<p>
One day, you have to move from one town to another. In this game, some pairs of towns are connected by roads
where players can travel. Various monsters will raid players on roads. However, since you are a high-level player,
they are nothing but the source of experience points. Every road is bi-directional. A path is represented by a
sequence of towns, where consecutive towns are connected by roads.
</p>
<p>
You are now planning to move to the destination town through the <i>most efficient</i> path. Here, the efficiency of a
path is measured by the total experience points you will earn in the path divided by the time needed to travel the
path.
</p>
<p>
Since your object is moving, not training, you choose only a <i>straightforward</i> path. A path is said straightforward
if, for any two consecutive towns in the path, the latter is closer to the destination than the former. The <i>distance</i>
of two towns is measured by the shortest time needed to move from one town to another.
</p>
<p>
Write a program to find a path that gives the highest efficiency.
</p>
<H2>Input</H2>
<p>
The first line contains a single integer <i>c</i> that indicates the number of cases.
</p>
<p>
The first line of each test case contains two integers <i>n</i> and <i>m</i> that represent the numbers of towns and roads
respectively. The next line contains two integers <i>s</i> and <i>t</i> that denote the starting and destination towns respectively.
Then <i>m</i> lines follow. The <i>i</i>-th line contains four integers <i>u<sub>i</sub></i>, <i>v<sub>i</sub></i>, <i>e<sub>i</sub></i>, and <i>t<sub>i</sub></i>, where <i>u<sub>i</sub></i> and <i>v<sub>i</sub></i> are two towns connected
by the <i>i</i>-th road, <i>e<sub>i</sub></i> is the experience points to be earned, and <i>t<sub>i</sub></i> is the time needed to pass the road.
</p>
<p>
Each town is indicated by the town index number from 0 to (<i>n</i> - 1). The starting and destination towns never
coincide. <i>n</i>, <i>m</i>, <i>e<sub>i</sub></i>'s and <i>t<sub>i</sub></i>'s are positive and not greater than 1000.
</p>
<H2>Output</H2>
<p>
For each case output in a single line, the highest possible efficiency. Print the answer with four decimal digits.
The answer may not contain an error greater than 10<sup>-4</sup>.
</p>
<H2>Sample Input</H2>
<pre>
2
3 3
0 2
0 2 240 80
0 1 130 60
1 2 260 60
3 3
0 2
0 2 180 60
0 1 130 60
1 2 260 60
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3.2500
3.0000
</pre>
|
p03450 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people standing on the <var>x</var>-axis.
Let the coordinate of Person <var>i</var> be <var>x_i</var>.
For every <var>i</var>, <var>x_i</var> is an integer between <var>0</var> and <var>10^9</var> (inclusive).
It is possible that more than one person is standing at the same coordinate.</p>
<p>You will given <var>M</var> pieces of information regarding the positions of these people.
The <var>i</var>-th piece of information has the form <var>(L_i, R_i, D_i)</var>.
This means that Person <var>R_i</var> is to the right of Person <var>L_i</var> by <var>D_i</var> units of distance, that is, <var>x_{R_i} - x_{L_i} = D_i</var> holds.</p>
<p>It turns out that some of these <var>M</var> pieces of information may be incorrect.
Determine if there exists a set of values <var>(x_1, x_2, ..., x_N)</var> that is consistent with the given pieces of information.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var> <var>000</var></li>
<li><var>0 \leq M \leq 200</var> <var>000</var></li>
<li><var>1 \leq L_i, R_i \leq N</var> (<var>1 \leq i \leq M</var>)</li>
<li><var>0 \leq D_i \leq 10</var> <var>000</var> (<var>1 \leq i \leq M</var>)</li>
<li><var>L_i \neq R_i</var> (<var>1 \leq i \leq M</var>)</li>
<li>If <var>i \neq j</var>, then <var>(L_i, R_i) \neq (L_j, R_j)</var> and <var>(L_i, R_i) \neq (R_j, L_j)</var>.</li>
<li><var>D_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>L_1</var> <var>R_1</var> <var>D_1</var>
<var>L_2</var> <var>R_2</var> <var>D_2</var>
<var>:</var>
<var>L_M</var> <var>R_M</var> <var>D_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists a set of values <var>(x_1, x_2, ..., x_N)</var> that is consistent with all given pieces of information, print <code>Yes</code>; if it does not exist, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2 1
2 3 1
1 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Some possible sets of values <var>(x_1, x_2, x_3)</var> are <var>(0, 1, 2)</var> and <var>(101, 102, 103)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2 1
2 3 1
1 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>If the first two pieces of information are correct, <var>x_3 - x_1 = 2</var> holds, which is contradictory to the last piece of information.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 3
2 1 1
2 3 5
3 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 3
8 7 100
7 9 100
9 8 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>100 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> |
p01302 |
<H1><font color="#000">Problem J:</font> Cave Explorer</H1>
<p>
Mike Smith is a man exploring caves all over the world.
</p>
<p>
One day, he faced a scaring creature blocking his way. He got scared, but in short time he took
his knife and then slashed it to attempt to kill it. Then they were split into parts, which soon
died out but the largest one. He slashed the creature a couple of times more to make it small
enough, and finally became able to go forward.
</p>
<p>
Now let us think of his situation in a mathematical way. The creature is considered to be a
polygon, convex or concave. Mike slashes this creature straight with his knife in some direction.
We suppose here the direction is given for simpler settings, while the position is arbitrary. Then
all split parts but the largest one disappears.
</p>
<p>
Your task is to write a program that calculates the area of the remaining part when the creature
is slashed in such a way that the area is minimized.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is given in the following format:
</p>
<p>
<i>n</i><br>
<i>v<sub>x</sub> v<sub>y</sub></i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br>
...<br>
<i>x<sub>n</sub> y<sub>n</sub></i>
</p>
<p>
The first line contains an integer <i>n</i>, the number of vertices of the polygon that represents the
shape of the creature (3 ≤ <i>n</i> ≤ 100). The next line contains two integers <i>v<sub>x</sub></i> and <i>v<sub>y</sub></i>, where
(<i>v<sub>x</sub></i>, <i>v<sub>y</sub></i>) denote a vector that represents the direction of the knife (-10000 ≤ <i>v<sub>x</sub></i>, <i>v<sub>y</sub></i> ≤ 10000,
<i>v</i><sub><i>x</i></sub><sup>2</sup> + <i>v</i><sub><i>y</i></sub><sup>2</sup> > 0). Then <i>n</i> lines follow. The <i>i</i>-th line contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i>, where (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>)
denote the coordinates of the <i>i</i>-th vertex of the polygon (0 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 10000).
</p>
<p>
The vertices are given in the counterclockwise order. You may assume the polygon is always
simple, that is, the edges do not touch or cross each other except for end points.
</p>
<p>
The input is terminated by a line with a zero. This should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the minimum possible area in a line. The area may be printed with
an arbitrary number of digits after the decimal point, but should not contain an absolute error
greater than 10<sup>-2</sup>.
</p>
<H2>Sample Input</H2>
<pre>
5
0 1
0 0
5 0
1 1
5 2
0 2
7
9999 9998
0 0
2 0
3 1
1 1
10000 9999
2 2
0 2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2.00
2.2500000
</pre>
|
p01752 |
<p>
A さんと B 君は,<var>N</var> × <var>M</var> の長方形のマス目状の地域に住んでいる.各マス目は道か壁か家のどれかである.この地域は,道が複雑で入り組んでいるので痴漢被害がよく起こることで有名であるため,この地域と外部との境界は全て壁で囲まれており,隔離されている.
</p>
<p>
B 君はなんとなく気が向いたので,A さんの家を眺めに行くことにした.しかし,不幸なことにB 君は明らかに怪しい顔をしているので,A さんの家に行く途中に少しでも痴漢の疑いがあるような行動を取ったらすぐに捕まってしまうだろう.特に,右手を壁から離して歩くことは絶対にやってはならない.B 君は,一瞬たりとも右手を離すことなく,A さんの家に辿り着くことが出来るだろうか?
</p>
<p>
B 君はつねに上下左右いずれかの方向を向いていて,B 君の右手が届く範囲はB 君の向いている方向に対して正面,斜め右前,右,斜め右後ろの4 マスのみである.B 君は,次のいずれかの行動を繰り返す.ただし,これらを同時に行うことは出来ない.
</p>
<ul>
<li> 前方に壁がない場合,1 マス進む.</li>
<li> 向いている方向を90 度右に変える.</li>
<li> 向いている方向を90 度左に変える.</li>
<li> 右手が接するマスを変える.ただし,この時にB 君は右手を離すことが出来ないので,変更前のマスと変更後のマスの間には共通した点を持っていなくてはならない.</li>
</ul>
<h2>Input</h2>
<p>
入力は以下の形式で与えられる.
</p>
<pre>
<var>N</var> <var>M</var>
<var>S<sub>1</sub></var>
<var>S<sub>2</sub></var>
:
<var>S<sub>N</sub></var>
</pre>
<p>
<var>S<sub>i</sub></var> (1 ≤ <var>i</var> ≤ <var>N</var>) は, <var>M</var> 文字の文字列で各文字は次を表す.
</p>
<ul>
<li> "^","v","<",">" は B 君の最初の位置と最初に向いている方向(上下左右の向き)を表す.</li>
<li> "." は,何もないマスである.B 君は,このマスの上を移動することができる.</li>
<li> "#" は,壁を表す.壁の上を移動することは出来ない.</li>
<li> "G" は A さんの家の位置を表す.B 君は,A さんの家にたどり着くまで移動を繰り返す.</li>
</ul>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>N</var> ≤ 50 </li>
<li> 1 ≤ <var>M</var> ≤ 50</li>
<li> 入力には,文字 "^","v","<",">" のうちいずれかが必ず一つのみ現れる.</li>
<li> 同様に,入力には,文字 "G" が必ず一つのみ現れる.</li>
<li> 初期状態では,B 君が向いている方向から右の壁にB 君の右手が接している.</li>
</ul>
<h2>Output</h2>
<p>
一度も右手を離さずにA さんの家に辿り着くことが出来る場合には,A さんの家にたどり着くまでに通った異なるマスの数の最小値を出力せよ.A さんの家に辿り着くことが出来ない場合には,-1 を出力せよ.
</p>
<h2>Sample Input 1</h2>
<pre>
3 3
G##
.#.
.<.
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>
4
</pre>
<h2>Sample Input 2</h2>
<pre>
3 3
G##
.#.
.>.
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>
6
</pre>
<h2>Sample Input 3</h2>
<pre>
3 3
...
.G.
.>.
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>
-1
</pre>
<h2>Sample Input 4</h2>
<pre>
4 4
....
.#.G
...#
^#..
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>
8
</pre> |
p00840 |
<H1><font color="#000">Problem E:</font> Mobile Computing</H1>
<p>
There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful
stones on the planet, and the Yaen people love to collect them. They bring the stones back home
and make nice mobile arts of them to decorate their 2-dimensional living rooms.
</p>
<p>
In their 2-dimensional world, a mobile is defined recursively as follows:
</p>
<ul>
<li> a stone hung by a string, or</li>
<li> a rod of length 1 with two sub-mobiles at both ends; the rod
is hung by a string at the center of gravity of sub-mobiles.
When the weights of the sub-mobiles are <i>n</i> and <i>m</i>, and their
distances from the center of gravity are a and b respectively,
the equation <i>n</i> × <i>a</i> = <i>m</i> × <i>b</i> holds.</li>
</ul>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_mobileComputing1"><br/>
</center>
<p>
For example, if you got three stones with weights 1, 1, and 2, here are some possible mobiles
and their widths:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_mobileComputing2">
</center>
<p>
Given the weights of stones and the width of the room, your task is to design the widest possible
mobile satisfying both of the following conditions.
</p>
<ul>
<li> It uses all the stones.</li>
<li> Its width is less than the width of the room.</li>
</ul>
<p>
You should ignore the widths of stones.
</p>
<p>
In some cases two sub-mobiles hung from both ends of a rod might
overlap (see the figure on the below). Such mobiles are acceptable.
The width of the example is (1/3) + 1 + (1/4).
</p>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_mobileComputing3"><br/>
</center>
<H2>Input</H2>
<p>
The first line of the input gives the number of datasets. Then the specified number of datasets
follow. A dataset has the following format.
</p>
<pre>
<i>r</i>
<i>s</i>
<i>w</i><sub>1</sub>
.
.
.
<i>w<sub>s</sub></i>
</pre>
<p>
<i>r</i> is a decimal fraction representing the width of the room, which satisfies 0 < <i>r</i> < 10. <i>s</i> is the
number of the stones. You may assume 1 ≤ <i>s</i> ≤ 6. <i>w<sub>i</sub></i> is the weight of the <i>i</i>-th stone, which is
an integer. You may assume 1 ≤ <i>w<sub>i</sub></i> ≤ 1000.
</p>
<p>
You can assume that no mobiles whose widths are between <i>r</i> - 0.00001 and <i>r</i> + 0.00001 can be made of given stones.
</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 width of the widest possible mobile as defined above. An
output line should not contain extra characters such as spaces.
</p>
<p>
In case there is no mobile which satisfies the requirement, answer -1 instead.
</p>
<p>
The answer should not have an error greater than 0.00000001. 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>
5
1.3
3
1
2
1
1.4
3
1
2
1
2.0
3
1
2
1
1.59
4
2
1
1
3
1.7143
4
1
2
3
5
</pre>
<H2>Output for the Sample Input</H2>
<pre>
-1
1.3333333333333335
1.6666666666666667
1.5833333333333335
1.7142857142857142
</pre>
|
p03295 | <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> islands lining up from west to east, connected by <var>N-1</var> bridges.</p>
<p>The <var>i</var>-th bridge connects the <var>i</var>-th island from the west and the <var>(i+1)</var>-th island from the west.</p>
<p>One day, disputes took place between some islands, and there were <var>M</var> requests from the inhabitants of the islands:</p>
<p>Request <var>i</var>: A dispute took place between the <var>a_i</var>-th island from the west and the <var>b_i</var>-th island from the west. Please make traveling between these islands with bridges impossible.</p>
<p>You decided to remove some bridges to meet all these <var>M</var> requests.</p>
<p>Find the minimum number of bridges that must be removed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq M \leq 10^5</var></li>
<li><var>1 \leq a_i < b_i \leq N</var></li>
<li>All pairs <var>(a_i, b_i)</var> are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of bridges that must be removed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
1 4
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The requests can be met by removing the bridge connecting the second and third islands from the west.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 5
1 8
2 7
3 5
4 6
7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p00513 |
<H1>問題 4 </H1>
<br/>
<p>
IOI 不動産ではマンションの賃貸を行なっている.
この会社が取り扱うマンションの部屋は 1LDK で,
下図のように面積が 2xy+x+y になっている.
ただし, x, y は正整数である.
</p>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_Madori" alt="Figure_Madori">
</center>
<br/>
<p>
IOI 不動産のカタログにはマンションの面積が昇順に(狭いものから順番に)書かれているが,この中にいくつか間違い(ありえない面積のもの)が混じっていることがわかった.
</p>
<p>
カタログ(入力ファイル)は N+1 行で,最初の行に部屋数が書かれていて,
続く N 行に,1行に1部屋ずつ面積が昇順に書かれている.
ただし,
部屋数は 100,000 以下,
面積は (2の31乗)-1 = 2,147,483,647 以下である.
5つの入力データのうち3つまでは,
部屋数 1000 以下,面積 30000 以下である.
</p>
<p>
間違っている行数(ありえない部屋の数)を出力しなさい.
</p>
<p>
出力ファイルにおいては,
出力の最後の行にも改行コードを入れること.
</p>
<h2>入出力例</h2>
<h3>入力例</h3>
<pre>
10
4
7
9
10
12
13
16
17
19
20
</pre>
<h3>出力例</h3>
<pre>2</pre>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00143 |
<h1>牽牛と織女</h1>
<p>
織女は天帝の子供でしたが、父の言いつけであけてもくれても機を織っていました。
</p>
<p>
織女の織る雲錦という見事な布で仕立てた服を着るのが天帝の楽しみでした。雲錦は寿命が短くすぐに劣化してしまいますが、働き者の織女が毎日織ってくれるので、問題はありませんでした。織女は、父の言いつけを守り、毎日毎日雲錦を織り続けていたので、ボーイフレンドはいませんでした。かわいそうに思った父は、天の川の向こう岸に住む牽牛という働き者を紹介し、嫁入りさせました。
</p>
<p>
すると、織女は、結婚の楽しさに夢中になって、機織りなどそっちのけで、牽牛と遊び呆けています。天帝のお気に入りの雲錦の服も新しく仕立てられないためボロボロになってしまいました。
</p>
<p>
これには父も怒って、織女を宮殿に連れ戻したいと思いました。しかし人間である牽牛の前にボロボロの服で姿を現すわけにはいきません。遊び呆けている二人を 3 角形の壁で遮断し自分以外の全てのものが行き来できなくすることを考えました。そして、牽牛に見つからずに、織女に会って、まじめに機を織るか、さもなければ強制的に連れ帰ると宣言するというのです。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_altairAndVega">
</center>
<br/>
<p>
天帝はこの作戦を遂行するために 3 角形の壁生成装置を開発することにしました。3 角形の 3 頂点の位置 <var>(xp<sub>1</sub>, yp<sub>1</sub>)</var>, <var>(xp<sub>2</sub>, yp<sub>2</sub>)</var>, <var>(xp<sub>3</sub>, yp<sub>3</sub>)</var>、牽牛の位置 <var>(xk, yk)</var>、および織女の位置 <var>(xs, ys)</var>、を入力とし、三角形が牽牛と織女を遮断しているか否かを判定し、遮断できている場合は OK、遮断できていない場合には NG を出力するプログラムを作成してください。ただし、遮断しているとは、牽牛と織女のいずれかが三角形の内側にあり、他方が外側にある場合を言います。牽牛と織女は三角形の頂点もしくは辺の上にはいないものとします。
</p>
<p>
織女と牽牛は時々刻々場所を変えるため、プログラムは様々な位置情報を入力し質問に答えなければなりません。
</p>
<!--
<p>
天帝はこの作戦遂行のために 3 角形の壁生成装置の開発を開発部署に命じました。3 点を与えてそこに壁を作るという仕様で発注したつもりでしたが、開発部署では何を間違えたのか、ランダムに(無作為に)に 3 角形の壁を生成し、その 3 点を報告するシステムを作ってしまいました。発注者として、天帝は作り直しを命じたいのですが、服がますますボロボロになったので、最小限の手直しで手を打つことにしました。ランダムに壁ができたのではたまったもんじゃないので、作ろうとする 3 角形が決まった段階で、3 点を報告し、それで満足するものならば(すなわち遮断ができていれば)天帝が OK ボタンを押して壁の作成を指示するという仕様にしました。遮断できていなければ(遮断不全ならば) NG ボタンを押し、やり直しとなります。織女と牽牛は時々刻々場所を変えます。壁生成装置からは無作為の 3 点がどんどん出力されてきます。
</p>
<p>
天帝は与えられた状況下で、壁の作成を指示すべきか否かを判定する必要に迫られました。そこで、天帝にかわり、3角形の 3 頂点の位置 <var>(xp<sub>1</sub>, yp<sub>1</sub>)</var>, <var>(xp<sub>2</sub>, yp<sub>2</sub>)</var>, <var>(xp<sub>3</sub>, yp<sub>3</sub>)</var>、牽牛の位置 <var>(xk, yk)</var>、および織女の位置 <var>(xs, ys)</var>、を入力とし、三角形が牽牛と織女を遮断しているか否かを判定し、遮断できている場合は OK、遮断できていない場合には NG を出力するプログラムを作成してください。ただし、遮断しているとは、牽牛と織女のいずれかが三角形の内側にあり、他方が外側にある場合を言います。牽牛と織女は三角形の頂点もしくは辺の上にはいないものとします。
</p>
-->
<H2>Input</H2>
<p>
入力は以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>query<sub>1</sub></var>
<var>query<sub>2</sub></var>
:
<var>query<sub>n</sub></var>
</pre>
<p>
1行目に判別したい情報の個数 <var>n</var> (<var>n</var> ≤ 10000)、続く <var>n</var> 行に <var>i</var> 番目の質問 <var>query<sub>i</sub></var> が与えられます。各質問は以下の形式で与えられます。
</p>
<pre>
<var>xp<sub>1</sub></var> <var>yp<sub>1</sub></var> <var>xp<sub>2</sub></var> <var>yp<sub>2</sub></var> <var>xp<sub>3</sub></var> <var>yp<sub>3</sub></var> <var>xk</var> <var>yk</var> <var>xs</var> <var>ys</var>
</pre>
<p>
各質問として、3 角形の 3 頂点の位置、牽牛の位置、および織女の位置 (-1000 ≤ <var>xp<sub>1</sub></var>, <var>yp<sub>1</sub></var>, <var>xp<sub>2</sub></var>, <var>yp<sub>2</sub></var>, <var>xp<sub>3</sub></var>, <var>yp<sub>3</sub></var>, <var>xk</var>, <var>yk</var>, <var>xs</var>, <var>ys</var> ≤ 1000) が1行に与えられます。入力はすべて整数です。
</p>
<H2>Output</H2>
<p>
質問ごとに、判定結果 OK または NG を1行に出力してください。
</p>
<H2>Sample Input</H2>
<pre>
5
2 5 9 2 8 9 2 11 6 5
2 5 9 2 8 9 2 11 12 6
2 5 9 2 8 9 2 11 11 9
14 1 25 7 17 12 17 9 20 5
14 1 25 7 17 12 22 13 20 5
</pre>
<H2>Output for the Sample Input</H2>
<pre>
OK
NG
NG
NG
OK
</pre>
|
p02191 | <h2>Range Count Query</h2>
<p>数列<var>a_1,a_2,..,a_N</var>が与えられます。</p>
<p>クエリでは、値が<var>l</var>以上<var>r</var>以下の項の個数を答えてください。</p>
<h3>入力</h3>
<pre>
<var>N Q</var>
<var>a_1 a_2...a_N</var>
<var>l_1 r_1</var>
<var>l_2 r_2</var>
:
<var>l_q r_q</var>
</pre>
<h3>出力</h3>
<pre>
<var>ans_1</var>
<var>ans_2</var>
:
<var>ans_q</var>
</pre>
<p><var>i</var>行目には、<var>i</var>番目のクエリに対する答え、すなわち<var>l_i \leq a_j \leq r_i</var>なる<var>j</var>の個数を出力せよ。</p>
<h3>制約</h3>
<ul>
<li><var>1 \leq N,Q \leq 10^5 </var></li>
<li><var>1 \leq a_i \leq 10^9</var></li>
<li><var>1 \leq l_i \leq r_i \leq 10^9</var></li>
</ul>
<h3>入力例</h3>
<pre>
6 3
8 6 9 1 2 1
2 8
1 7
3 5
</pre>
<h3>出力例</h3>
<pre>
3
4
0
</pre>
|
p00456 |
<H1> コンテスト </H1>
<h2>問題</h2>
<p>
先日,オンラインでのプログラミングコンテストが行われた. W大学とK大学のコンピュータクラブは以前からライバル関係にあり,このコンテストを利用して両者の優劣を決めようということになった.
</p>
<p>
今回,この2つの大学からはともに10人ずつがこのコンテストに参加した.長い議論の末,参加した10人のうち,得点の高い方から3人の得点を合計し,大学の得点とすることにした.
</p>
<p>
W大学およびK大学の参加者の得点のデータが与えられる.このとき,おのおのの大学の得点を計算するプログラムを作成せよ.
</p>
<h2>入力</h2>
<p>
入力は20行からなる. 1行目から10行目にはW大学の各参加者の得点を表す整数が, 11行目から20行目にはK大学の各参加者の得点を表す整数が書かれている.これらの整数はどれも0以上100以下である.
</p>
<h2>出力</h2>
<p>
W大学の得点とK大学の得点を,この順に空白区切りで出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
23
23
20
15
15
14
13
9
7
6
25
19
17
17
16
13
12
11
9
5</pre>
<h3>出力例1</h3>
<pre>
66 61</pre>
<br>
<h3>入力例2</h3>
<pre>
17
25
23
25
79
29
1
61
59
100
44
74
94
57
13
54
82
0
42
45</pre>
<h3>出力例2</h3>
<pre>
240 250</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00006 |
<H1>Reverse Sequence</H1>
<p>
Write a program which reverses a given string <var>str</var>.
</p>
<H2>Input</H2>
<p>
<var>str</var> (the size of <var>str</var> ≤ 20) is given in a line.
</p>
<H2>Output</H2>
<p>
Print the reversed <var>str</var> in a line.
</p>
<H2>Sample Input</H2>
<pre>
w32nimda
</pre>
<H2>Output for the Sample Input</H2>
<pre>
admin23w
</pre>
|
p03780 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer has <var>N</var> cards with positive integers written on them. The number on the <var>i</var>-th card <var>(1≤i≤N)</var> is <var>a_i</var>.
Because he loves big numbers, he calls a subset of the cards <em>good</em> when the sum of the numbers written on the cards in the subset, is <var>K</var> or greater.</p>
<p>Then, for each card <var>i</var>, he judges whether it is <em>unnecessary</em> or not, as follows:</p>
<ul>
<li>If, for any good subset of the cards containing card <var>i</var>, the set that can be obtained by eliminating card <var>i</var> from the subset is also good, card <var>i</var> is unnecessary.</li>
<li>Otherwise, card <var>i</var> is NOT unnecessary.</li>
</ul>
<p>Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1≤N≤5000</var></li>
<li><var>1≤K≤5000</var></li>
<li><var>1≤a_i≤10^9 (1≤i≤N)</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N,K≤400</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>a_1</var> <var>a_2</var> ... <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the unnecessary cards.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 6
1 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>There are two good sets: {<var>2,3</var>} and {<var>1,2,3</var>}.</p>
<p>Card <var>1</var> is only contained in {<var>1,2,3</var>}, and this set without card <var>1</var>, {<var>2,3</var>}, is also good. Thus, card <var>1</var> is unnecessary.</p>
<p>For card <var>2</var>, a good set {<var>2,3</var>} without card <var>2</var>, {<var>3</var>}, is not good. Thus, card <var>2</var> is NOT unnecessary.</p>
<p>Neither is card <var>3</var> for a similar reason, hence the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 400
3 1 4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>In this case, there is no good set. Therefore, all the cards are unnecessary.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 20
10 4 3 10 25 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p04045 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,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>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
p02892 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a connected undirected graph with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>1</var> to <var>N</var>, and the edges are described by a grid of characters <var>S</var>.
If <var>S_{i,j}</var> is <code>1</code>, there is an edge connecting Vertex <var>i</var> and <var>j</var>; otherwise, there is no such edge.</p>
<p>Determine whether it is possible to divide the vertices into non-empty sets <var>V_1, \dots, V_k</var> such that the following condition is satisfied. If the answer is yes, find the maximum possible number of sets, <var>k</var>, in such a division.</p>
<ul>
<li>Every edge connects two vertices belonging to two "adjacent" sets. More formally, for every edge <var>(i,j)</var>, there exists <var>1\leq t\leq k-1</var> such that <var>i\in V_t,j\in V_{t+1}</var> or <var>i\in V_{t+1},j\in V_t</var> holds.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200</var></li>
<li><var>S_{i,j}</var> is <code>0</code> or <code>1</code>.</li>
<li><var>S_{i,i}</var> is <code>0</code>.</li>
<li><var>S_{i,j}=S_{j,i}</var></li>
<li>The given graph is connected.</li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S_{1,1}...S_{1,N}</var>
<var>:</var>
<var>S_{N,1}...S_{N,N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is impossible to divide the vertices into sets so that the condition is satisfied, print <var>-1</var>.
Otherwise, print the maximum possible number of sets, <var>k</var>, in a division that satisfies the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
01
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can put Vertex <var>1</var> in <var>V_1</var> and Vertex <var>2</var> in <var>V_2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
011
101
110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
010110
101001
010100
101000
100000
010000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p01247 |
<H1><font color="#000">Problem G:</font> Japanese Style Pub</H1>
<p>
You’ve just entered a Japanese-style pub, or an <i>izakaya</i> in Japanese, for a drinking party (called <i>nomi-kai</i>) with
your dear friends.
</p>
<p>
Now you are to make orders for glasses of hard and soft drink as requested by the participants. But unfortunately,
most staffs in typical <i>izakayas</i> are part-time workers; they are not used to their work so they make mistakes at a
certain probability for each order.
</p>
<p>
You are worrying about such mistakes. Today is a happy day for the participants, the dearest friends of yours.
</p>
<p>
Your task is to write a program calculating the probability at which the <i>izakaya</i> staff brings correct drinks for
the entire orders. Cases in which the staff’s mistakes result in a correct delivery should be counted into the
probability, since those cases are acceptable for you.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case begins with a line containing an interger <i>N</i> (1 ≤ <i>N</i> ≤ 8).
The integer <i>N</i> indicates the number of kinds of drinks available in the <i>izakaya</i>.
</p>
<p>
The following <i>N</i> lines specify the probabilities for the drinks in the format shown below.
</p>
<pre>
<i>p</i><sub>11</sub> <i>p</i><sub>12</sub> . . . <i>p</i><sub>1<i>N</i></sub>
<i>p</i><sub>21</sub> <i>p</i><sub>22</sub> . . . <i>p</i><sub>2<i>N</i></sub>
...
<i>p</i><sub><i>N</i>1</sub> <i>p</i><sub><i>N</i>2</sub> . . . <i>p</i><sub><i>NN</i></sub>
</pre>
<p>
Each real number <i>p<sub>ij</sub></i> indicates the probability where the staff delivers a glass of the drink <i>j</i> for an order of the
drink <i>i</i>. It holds that <i>p<sub>ij</sub></i> ≥ 0 and <i>p</i><sub><i>i</i>1</sub> + <i>p</i><sub><i>i</i>2</sub> + . . . + <i>p</i><sub><i>iN</i></sub> = 1 for 1 ≤ <i>i</i>, <i>j</i> ≤ <i>N</i>. At the end of each test case, a line
which contains <i>N</i> comes. The <i>i</i>-th integer <i>n<sub>i</sub></i> represents the number of orders for the drink <i>i</i> by the participants
(0 ≤ <i>n<sub>i</sub></i> ≤ 4).
</p>
<p>
The last test case is followed by a line containing a zero.
</p>
<H2>Output</H2>
<p>
For Each test case, print a line containing the test case number (beginning with 1) followed by the natural
logarithm of the probability where the staff brings correct drinks for the entire orders. Print the results with eight
digits to the right of the decimal point. If the staff cannot bring correct drinks in any case, print “-INFINITY”
instead. Use the format of the sample output.
</p>
<H2>Sample Input</H2>
<pre>
3
0.7 0.1 0.2
0.1 0.8 0.1
0.0 0.0 1.0
4 3 2
8
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
2 2 2 2 2 2 2 2
2
1 0
1 0
2 2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: -1.89723999
Case 2: -8.14438201
Case 3: -INFINITY
</pre>
|
p01617 |
<h1>E: Twins Idol / ツインズアイドル</h1>
<p>アイドル事務所841プロダクションには,多くの個性的なアイドル達が所属している. 双子のアイドルであるアキ&マキは,841プロに所属するアイドルであり,2人ともとてもゲーム好きである. ある日2人は,次のようなゲームを自分達で自作して楽しむことにした. このゲームは,2人で協力するタイプのゲームであるため,双子の息の合ったプレイが期待される.</p>
<p>まず,ゲームを始める前に,2人が別々に自分の好きなようにフィールドを床に描く. フィールドは,アルファベットの1文字が書かれたいくつかのボードと,ボード間をつなぐルートで構成される. 彼女らは,このルート上を辿ることで,ボード間を移動できる. ただし,ルートには矢印がついており,その矢印の方向に向かってしか移動できない. アキのフィールドとマキのフィールドの間にルートは存在しないため,互いのフィールドを行き来することはできない.</p>
<p>まず,アキとマキが,自分のフィールド内の好きなボードに立つところからゲームが始まる. そして,以下の決まりに従って,2人が同時に行動していく.</p>
<ul>
<li>2人の立っているボードの文字が等しい場合</li>
<ul>
<li>スコアとして,1点を得る.</li>
<li>2人は現在立っているボードを離れて,別のボードに移動しなければならない.</li>
<li>ただし,別のボードに移動しようとした際,2人の内どちらかが移動できなかった場合,ゲームを終了する.</li>
</ul>
<li>2人の立っているボードの文字が異なる場合</li>
<ul>
<li>スコアを得ることはできない.</li>
<li>2人はそれぞれ,「現在のボードにとどまる」か「別のボードに移動する」かを選択して行動する.2人が同じ行動を取る必要はない.</li>
<li>ただし,別のボードに移動しようとした際,移動できなかった場合,ゲームを終了する.</li>
</ul>
<li>現在以降のターンを使用して,現在のボードから,どう移動しても点数を増やせないとき</li>
<ul>
<li>ゲームを終了する.</li>
</ul>
</ul>
<p>アキ&マキは,このゲームでなるべく高いスコアを出したいと考えている. 2人が最大でどれだけの得点を取得できるか,841プロの新人敏腕プロデューサである君が,お得意のプログラミングによって華麗にヒントを与えてあげよう.</p>
<div>
<h1>Input</h1>
<p>入力は次の形式で表される.</p>
<div>
<em>AKI_FIELD</em><br />
<em>MAKI_FIELD</em><br />
</div>
<br/>
<p><em>AKI_FIELD</em>と<em>MAKI_FIELD</em>は,それぞれアキとマキのフィールドを表す. 各フィールドの入力は,次の形式で表される.</p>
<div>
<em>N</em> <em>M</em><br />
<em>c</em>1 <em>c</em>2, ..., <em>cN</em><br />
<em>a</em>1 <em>b</em>1<br />
...<br />
<em>ai</em> <em>bi</em><br />
...<br />
<em>aM</em> <em>bM</em><br />
</div>
<br/>
<p>全ての数値は整数値である. <em>N</em> (1 <= <em>N</em> <= 100) はボードの数であり,各ボードには,1, 2, ..., <em>N</em>の番号が付いている. <em>M</em> (0 <= <em>M</em> <= 5000) はボード間のルートの数を表す. 次の1行には,各ボードに書かれている文字が,ボード1から順番に空白で区切られて入力される. 各文字は,アルファベットの小文字か大文字のいずれかである. 大文字と小文字は,別の文字として扱わなければならない. 続いて,<em>M</em>行にわたって,ルート情報が入力される. 各ルートは,ボード<em>ai</em>からボード<em>bi</em>に向かって伸びている(1 <= <em>ai</em>, <em>bi</em> <= <em>N</em>). <em>ai</em>と<em>bi</em>は異なる値であり,一度入力されたルートが,再び入力されることはない. ただし,一度入力されたルートの逆方向のルートが入力されることはある.</p>
</div>
<div>
<h1>Output</h1>
<p>アキ&マキが取得できる最大の得点を答えよ. ただし,無限に点数を増やせる場合は,-1を出力せよ.</p>
</div>
<div>
<h1>Sample Input 1</h1>
<pre>
5 5
a c b c a
1 2
1 3
2 3
3 4
3 5
4 3
b a c c
1 3
2 3
3 4
</pre>
</div>
<div>
<h1>Sample Output 1</h1>
<pre>
3
</pre>
</div>
<div>
<h1>Sample Input 2</h1>
<pre>
2 2
a b
1 2
2 1
4 3
a b a b
1 2
2 3
3 4
</pre>
</div>
<div>
<h1>Sample Output 2</h1>
<pre>
4
</pre>
</div>
<div>
<h1>Sample Input 3</h1>
<pre>
3 3
Y Y I
1 2
2 3
3 1
3 3
I O R
1 3
3 2
2 1
</pre>
</div>
<div>
<h1>Sample Output 3</h1>
<pre>
-1
</pre>
</div> |
p00905 |
<H1><font color="#000">Problem B: </font>Stylish</H1>
<p>
<i>Stylish</i> is a programming language whose syntax comprises <i>names</i>, that are sequences of Latin alphabet letters, three types of <i>grouping symbols</i>, periods ('.'), and newlines. Grouping symbols, namely round brackets ('(' and ')'), curly brackets ('{' and '}'), and square brackets ('[' and ']'), must match and be nested properly. Unlike most other programming languages, Stylish uses periods instead of whitespaces for the purpose of term separation. The following is an example of a Stylish program.
</p>
<pre>
1 ( Welcome .to
2 ......... Stylish )
3 { Stylish .is
4 .....[.( a. programming . language .fun .to. learn )
5 .......]
6 ..... Maybe .[
7 ....... It. will .be.an. official . ICPC . language
8 .......]
9 .....}
</pre>
<p>
As you see in the example, a Stylish program is indented by periods. The <i>amount of indentation</i> of a line is the number of leading periods of it.
</p>
<p>
Your mission is to visit Stylish masters, learn their indentation styles, and become the youngest Stylish master. An indentation style for <i>well-indented</i> Stylish programs is defined by a triple of integers, (<i>R</i>, <i>C</i>, <i>S</i>), satisfying 1 ≤ <i>R</i>, <i>C</i>, <i>S</i> ≤ 20. <i>R</i>, <i>C</i> and <i>S</i> are amounts of indentation introduced by an open round bracket, an open curly bracket, and an open square bracket, respectively.
</p>
<p>
In a well-indented program, the amount of indentation of a line is given by <i>R</i>(<i>r<sub>o</sub></i> − <i>r<sub>c</sub></i>) + <i>C</i>(<i>c<sub>o</sub></i> − <i>c<sub>c</sub></i>) + <i>S</i>(<i>s<sub>o</sub></i> − <i>s<sub>c</sub></i>), where <i>r<sub>o</sub></i>, <i>c<sub>o</sub></i>, and <i>s<sub>o</sub></i> are the numbers of occurrences of open round, curly, and square brackets in all preceding lines, respectively, and <i>r<sub>c</sub></i>, <i>c<sub>c</sub></i>, and <i>s<sub>c</sub></i> are those of close brackets. The first line has no indentation in any well-indented program.
</p>
<p>
The above example is formatted in the indentation style (<i>R</i>, <i>C</i>, <i>S</i>) = (9, 5, 2). The only grouping symbol occurring in the first line of the above program is an open round bracket. Therefore the amount of indentation for the second line is 9 · (1 − 0) + 5 · (0 − 0) + 2 ·(0 − 0) = 9. The first four lines contain two open round brackets, one open curly bracket, one open square bracket, two close round brackets, but no close curly nor square bracket. Therefore the amount of indentation for the fifth line is 9 · (2 − 2) + 5 · (1 − 0) + 2 · (1 − 0) = 7.
</p>
<p>
Stylish masters write only well-indented Stylish programs. Every master has his/her own indentation style.
</p>
<p>
Write a program that imitates indentation styles of Stylish masters.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. The first line of a dataset contains two integers <i>p</i> (1 ≤ <i>p</i> ≤ 10) and <i>q</i> (1 ≤ <i>q</i> ≤ 10). The next <i>p</i> lines form a well-indented program <i>P</i> written by a
Stylish master and the following <i>q</i> lines form another program <i>Q</i>. You may assume that every line of both programs has at least one character and at most 80 characters. Also, you may assume that no line of <i>Q</i> starts with a period.
</p>
<p>
The last dataset is followed by a line containing two zeros.
</p>
<H2>Output</H2>
<p>
Apply the indentation style of <i>P</i> to <i>Q</i> and output the appropriate amount of indentation for each line of <i>Q</i>. The amounts must be output in a line in the order of corresponding lines of <i>Q</i> and they must be separated by a single space. The last one should not be followed by trailing spaces. If the appropriate amount of indentation of a line of <i>Q</i> cannot be determined uniquely through analysis of <i>P</i>, then output <span>-1</span> for that line.
</p>
<H2>Sample Input</H2>
<pre>
5 4
(Follow.my.style
.........starting.from.round.brackets)
{then.curly.brackets
.....[.and.finally
.......square.brackets.]}
(Thank.you
{for.showing.me
[all
the.secrets]})
4 2
(This.time.I.will.show.you
.........(how.to.use.round.brackets)
.........[but.not.about.square.brackets]
.........{nor.curly.brackets})
(I.learned
how.to.use.round.brackets)
4 2
(This.time.I.will.show.you
.........(how.to.use.round.brackets)
.........[but.not.about.square.brackets]
.........{nor.curly.brackets})
[I.have.not.learned
how.to.use.square.brackets]
2 2
(Be.smart.and.let.fear.of
..(closed.brackets).go)
(A.pair.of.round.brackets.enclosing
[A.line.enclosed.in.square.brackets])
1 2
Telling.you.nothing.but.you.can.make.it
[One.liner.(is).(never.indented)]
[One.liner.(is).(never.indented)]
2 4
([{Learn.from.my.KungFu
...}])
((
{{
[[
]]}}))
1 2
Do.not.waste.your.time.trying.to.read.from.emptiness
(
)
2 3
({Quite.interesting.art.of.ambiguity
....})
{
(
)}
2 4
({[
............................................................]})
(
{
[
]})
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 9 14 16
0 9
0 -1
0 2
0 0
0 2 4 6
0 -1
0 -1 4
0 20 40 60
</pre> |
p02938 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are integers <var>L</var> and <var>R</var>. Find the number, modulo <var>10^9 + 7</var>, of pairs of integers <var>(x, y)</var> <var>(L \leq x \leq y \leq R)</var> such that the remainder when <var>y</var> is divided by <var>x</var> is equal to <var>y \mbox{ XOR } x</var>.</p>
<details>
<summary>What is <var>\mbox{ XOR }</var>?</summary>
<p>
The XOR of integers <var>A</var> and <var>B</var>, <var>A \mbox{ XOR } B</var>, is defined as follows:
<ul>
<li>When <var>A \mbox{ XOR } B</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if either <var>A</var> or <var>B</var>, but not both, has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> otherwise.</li>
</ul>
For example, <var>3 \mbox{ XOR } 5 = 6</var>. (In base two: <var>011 \mbox{ XOR } 101 = 110</var>.)
</p>
</details>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq L \leq R \leq 10^{18}</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of pairs of integers <var>(x, y)</var> <var>(L \leq x \leq y \leq R)</var> satisfying the condition, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Three pairs satisfy the condition: <var>(2, 2)</var>, <var>(2, 3)</var>, and <var>(3, 3)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>604
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1000000000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>68038601
</pre>
<p>Be sure to compute the number modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p02312 |
<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 a Circle and a Polygon</H1>
<p>
Find the area of intersection between a circle $c$ and a polygon $g$. The center coordinate of the circle is ($0, 0$).
</p>
<p>
The polygon $g$ is represented by a sequence of points $p_1$, $p_2$,..., $p_n$ where line segments connecting $p_i$ and $p_{i+1}$ ($1 \leq i \leq n−1$) are sides of the polygon. The line segment connecting $p_n$ and $p_1$ is also a side of the polygon.
</p>
<p>
Note that the polygon is not necessarily convex.
</p>
<h2>Input</h2>
<p>The input is given in the following format.<br/>
<br/>
$n$ $r$<br/>
$x_1$ $y_1$<br/>
$x_2$ $y_2$<br/>
:<br/>
$x_n$ $y_n$<br/>
</p>
<p>
In the first line, an integer <var>n</var> representing the number of points in the polygon is given. The coordinate of a point $p_i$ is given by two integers $x_i$ and $y_i$. The coordinates of the points are given in the order of counter-clockwise visit of them. All input values are given in integers.
</p>
<h2>Constraints</h2>
<ul>
<li>$3 \leq n \leq 100$</li>
<li>$1 \leq r \leq 100$</li>
<li>$-100 \leq x_i, y_i \leq 100$</li>
</ul>
<h2>Output</h2>
<p>
Print the area of intersection in a line.
The output values should be in a decimal fraction with an error less than 0.00001.
</p>
<h2>Sample Input 1</h2>
<pre>
3 5
1 1
4 1
5 5
</pre>
<h2>Sample Output 1</h2>
<pre>
4.639858417607
</pre>
<h2>Sample Input 2</h2>
<pre>
4 5
0 0
-3 -6
1 -3
5 -4
</pre>
<h2>Sample Output 2</h2>
<pre>
11.787686807576
</pre> |
p00285 |
<h1>微生物発電</h1>
<p>
飯沼博士は磐梯山の噴気孔でふしぎな微生物を見つけました。この微生物の雄と雌1体ずつが合体すると、電気エネルギーを放出します。この微生物を研究すれば、将来のエネルギー危機から我々を救えるかもしれません。
</p>
<p>
観察を続けると、微生物は合体したときだけ電気エネルギーを発生させることと、合体した微生物のさらなる合体はないことがわかりました。さらに観察を続けると、合体で放出される電気エネルギーは、微生物が体内に持つ未知の粒子(博士はこれを磐梯山にちなんでB粒子と名づけました)の量で決まることがわかりました。合体する雄と雌が体内に持つB粒子の量をそれぞれ <var>bm</var> と <var>bw</var> とすると、合体により放出される電気エネルギーは |<var>bm</var> - <var>bw</var>| × (|<var>bm</var> - <var>bw</var>| - 30)<sup>2</sup> という式で計算できます。
</p>
<p>
この発見により、微生物の集団から得られる最大の電気エネルギーが計算できるようになりました。それでは、微生物の集団に含まれる雄と雌の数と、各個体が持つB粒子の量が与えられたとき、この微生物の集団から得られる最大の電気エネルギーを計算するプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる。入力の終わりはゼロ2つの行で示される。入力データは以下の形式で与えられる。
</p>
<pre>
<var>M</var> <var>W</var>
<var>bm<sub>1</sub></var> <var>bm<sub>2</sub></var> ... <var>bm<sub>M</sub></var>
<var>bw<sub>1</sub></var> <var>bw<sub>2</sub></var> ... <var>bw<sub>W</sub></var>
</pre>
<p>
1行目の <var>M</var> と <var>W</var> (1 ≤ <var>M,W</var> ≤ 12) はそれぞれ雄と雌の微生物の数である。2行目に、<var>i</var> 番目の雄が体内に持つB粒子の量 <var>bm<sub>i</sub></var> (0 ≤ <var>bm<sub>i</sub></var> ≤ 50) が与えられる。3行目に、<var>i</var> 番目の雌が体内に持つB粒子の量 <var>bw<sub>i</sub></var> (0 ≤ <var>bw<sub>i</sub></var> ≤ 50) が与えられる。<br>
<br>
データセットの数は 20 を超えない。
</p>
<h2>出力</h2>
<p>
データセットごとに、微生物の集団から得られる電気エネルギーの最大値を1行に出力する。
</p>
<h2>入出力例</h2>
<br>
<h2>入力例</h2>
<pre>
3 3
0 20 30
10 20 30
10 10
32 10 15 8 20 10 6 45 50 41
18 0 37 25 45 11 25 21 32 27
7 3
23 14 39 6 47 16 23
19 37 8
0 0
</pre>
<h2>出力例</h2>
<pre>
12000
53906
11629
</pre>
|
p03850 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino has a formula consisting of <var>N</var> terms: <var>A_1</var> <var>op_1</var> <var>A_2</var> <var>...</var> <var>op_{N-1}</var> <var>A_N</var>.
Here, <var>A_i</var> is an integer, and <var>op_i</var> is an binary operator either <code>+</code> or <code>-</code>.
Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) into the formula.
Opening parentheses can only be inserted immediately before an integer, and closing parentheses can only be inserted immediately after an integer.
It is allowed to insert any number of parentheses at a position.
Your task is to write a program to find the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N≦10^5</var></li>
<li><var>1≦A_i≦10^9</var></li>
<li><var>op_i</var> is either <code>+</code> or <code>-</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>op_1</var> <var>A_2</var> <var>...</var> <var>op_{N-1}</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
5 - 1 - 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>The maximum possible value is: <var>5 - (1 - 3) = 7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 - 2 + 3 - 4 + 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>The maximum possible value is: <var>1 - (2 + 3 - 4) + 5 = 5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1 - 20 - 13 + 14 - 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>13
</pre>
<p>The maximum possible value is: <var>1 - (20 - (13 + 14) - 5) = 13</var>.</p></section>
</div>
</span> |
p02742 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a board with <var>H</var> horizontal rows and <var>W</var> vertical columns of squares.
There is a bishop at the top-left square on this board.
How many squares can this bishop reach by zero or more movements?</p>
<p>Here the bishop can only move diagonally.
More formally, the bishop can move from the square at the <var>r_1</var>-th row (from the top) and the <var>c_1</var>-th column (from the left) to the square at the <var>r_2</var>-th row and the <var>c_2</var>-th column if and only if exactly one of the following holds:</p>
<ul>
<li><var>r_1 + c_1 = r_2 + c_2</var></li>
<li><var>r_1 - c_1 = r_2 - c_2</var></li>
</ul>
<p>For example, in the following figure, the bishop can move to any of the red squares in one move:</p>
<p><img alt="" src="https://img.atcoder.jp/panasonic2020/943f3f8428e6f8328924ff99681c932b.png"/></p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H, W \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>H \ W</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of squares the bishop can reach.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The bishop can reach the cyan squares in the following figure:</p>
<p><img alt="" src="https://img.atcoder.jp/panasonic2020/b218e01560fe6e40e7d082ca57a64e6e.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre>
<p>The bishop can reach the cyan squares in the following figure:</p>
<p><img alt="" src="https://img.atcoder.jp/panasonic2020/088830f8a244d99a9f95d20bf9a8d336.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>500000000000000000
</pre></section>
</div>
</span> |
p03503 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino is planning to open a shop in a shopping street.</p>
<p>Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.</p>
<p>There are already <var>N</var> stores in the street, numbered <var>1</var> through <var>N</var>.</p>
<p>You are given information of the business hours of those shops, <var>F_{i,j,k}</var>. If <var>F_{i,j,k}=1</var>, Shop <var>i</var> is open during Period <var>k</var> on Day <var>j</var> (this notation is explained below); if <var>F_{i,j,k}=0</var>, Shop <var>i</var> is closed during that period. Here, the days of the week are denoted as follows. Monday: Day <var>1</var>, Tuesday: Day <var>2</var>, Wednesday: Day <var>3</var>, Thursday: Day <var>4</var>, Friday: Day <var>5</var>. Also, the morning is denoted as Period <var>1</var>, and the afternoon is denoted as Period <var>2</var>.</p>
<p>Let <var>c_i</var> be the number of periods during which both Shop <var>i</var> and Joisino's shop are open. Then, the profit of Joisino's shop will be <var>P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}</var>.</p>
<p>Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N≤100</var></li>
<li><var>0≤F_{i,j,k}≤1</var></li>
<li>For every integer <var>i</var> such that <var>1≤i≤N</var>, there exists at least one pair <var>(j,k)</var> such that <var>F_{i,j,k}=1</var>.</li>
<li><var>-10^7≤P_{i,j}≤10^7</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>F_{1,1,1}</var> <var>F_{1,1,2}</var> <var>...</var> <var>F_{1,5,1}</var> <var>F_{1,5,2}</var>
<var>:</var>
<var>F_{N,1,1}</var> <var>F_{N,1,2}</var> <var>...</var> <var>F_{N,5,1}</var> <var>F_{N,5,2}</var>
<var>P_{1,0}</var> <var>...</var> <var>P_{1,10}</var>
<var>:</var>
<var>P_{N,0}</var> <var>...</var> <var>P_{N,10}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible profit of Joisino's shop.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>If her shop is open only during the periods when Shop <var>1</var> is opened, the profit will be <var>8</var>, which is the maximum possible profit.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-2
</pre>
<p>Note that a shop must be open during at least one period, and the profit may be negative.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>23
</pre></section>
</div>
</span> |
p01494 |
<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 I:
ThreeRooks
</h2>
<p>
ねこがチェスの練習をしている.
</p>
<p>
ねこは, $X \times Y$ のチェス盤の上にルークを 3 つ置こうとしている. このチェス盤の $K$ 個のマス目にはうさぎが座っている. $i$ 匹目のうさぎの座標は $(x[i], y[i])$ である. ただし, チェス盤の左上端のマス目の座標を $(0, 0)$, 右下端のマス目の座標を $(X-1, Y-1)$ とする。うさぎが座っている場所にはルークを置くことができない. また, 1 つのマス目に複数個のルークを置くことはできない.
</p>
<p>
どの 2 つのルークも互いに攻撃し合わないようにルークを3 つ置く方法は何通りあるか, mod 1,000,000,007 で求めよ. 2 つのルークは同じ行または同じ列にあり, 間にうさぎが座っていない場合に互いに攻撃しあうものとする.
</p>
<h3>Constraints</h3>
<ul>
<li>$X$, $Y$ will be between 1 and 1,000,000,000, inclusive.</li>
<li>$K$ will be between 1 and 100,000, inclusive.</li>
<li>$x_i$ will be between 0 and $X-1$, inclusive.</li>
<li>$y_i$ will be between 0 and $Y-1$, inclusive.</li>
<li>No two rabbits sit on the same cell.</li>
</ul>
<h3>Input</h3>
<p>
入力は以下の形式で与えられる:<br>
<br>
$X$ $Y$ $K$<br>
$x_1$ $y_1$<br>
...<br>
$x_K$ $y_K$<br>
<br>
</p>
<h3>Output</h3>
<p>
ルークの配置の個数を 1,000,000,007 で割ったあまりを表す整数を 1 行に出力せよ.
</p>
<h3>Sample Input 1</h3>
<pre>3 3 1
0 0</pre>
<h3>Sample Output 1</h3>
<pre>4</pre>
<h3>Sample Input 2</h3>
<pre>5 8 2
2 2
4 5</pre>
<h3>Sample Output 2</h3>
<pre>3424</pre> |
p03153 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cities in Republic of AtCoder. The size of the <var>i</var>-th city is <var>A_{i}</var>.
Takahashi would like to build <var>N-1</var> bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.</p>
<p>Assume that the cost of building a road connecting the <var>i</var>-th city and the <var>j</var>-th city is <var>|i-j| \times D + A_{i} + A_{j}</var>.
For Takahashi, find the minimum possible total cost to achieve the objective.</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 D \leq 10^9</var></li>
<li><var>1 \leq A_{i} \leq 10^9</var></li>
<li><var>A_{i}</var> and <var>D</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>D</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible total cost.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
1 100 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>106
</pre>
<p>This cost can be achieved by, for example, building roads connecting City <var>1</var>, <var>2</var> and City <var>1</var>, <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 1000
1 100 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2202
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 14
25 171 7 1 17 162
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>497
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>12 5
43 94 27 3 69 99 56 25 8 15 46 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>658
</pre></section>
</div>
</span> |
p03446 | <span class="lang-en">
<p>Score : <var>2100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a rectangular parallelepiped of dimensions <var>A×B×C</var>, divided into <var>1×1×1</var> small cubes.
The small cubes have coordinates from <var>(0, 0, 0)</var> through <var>(A-1, B-1, C-1)</var>.</p>
<p>Let <var>p</var>, <var>q</var> and <var>r</var> be integers. Consider the following set of <var>abc</var> small cubes:</p>
<p><var>\{(\ (p + i)</var> mod <var>A</var>, <var>(q + j)</var> mod <var>B</var>, <var>(r + k)</var> mod <var>C\ )</var> <var>|</var> <var>i</var>, <var>j</var> and <var>k</var> are integers satisfying <var>0</var> <var>≤</var> <var>i</var> <var><</var> <var>a</var>, <var>0</var> <var>≤</var> <var>j</var> <var><</var> <var>b</var>, <var>0</var> <var>≤</var> <var>k</var> <var><</var> <var>c</var> <var>\}</var></p>
<p>A set of small cubes that can be expressed in the above format using some integers <var>p</var>, <var>q</var> and <var>r</var>, is called a <em>torus cuboid</em> of size <var>a×b×c</var>.</p>
<p>Find the number of the sets of torus cuboids of size <var>a×b×c</var> that satisfy the following condition, modulo <var>10^9+7</var>:</p>
<ul>
<li>No two torus cuboids in the set have intersection.</li>
<li>The union of all torus cuboids in the set is the whole rectangular parallelepiped of dimensions <var>A×B×C</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>≤</var> <var>a</var> <var><</var> <var>A</var> <var>≤</var> <var>100</var></li>
<li><var>1</var> <var>≤</var> <var>b</var> <var><</var> <var>B</var> <var>≤</var> <var>100</var></li>
<li><var>1</var> <var>≤</var> <var>c</var> <var><</var> <var>C</var> <var>≤</var> <var>100</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var> <var>c</var> <var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the sets of torus cuboids of size <var>a×b×c</var> that satisfy the condition, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 1 2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 2 4 4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>744
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 3 4 6 7 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 3 4 98 99 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>471975164
</pre></section>
</div>
</span> |
p01181 |
<H1><font color="#000">Problem A:</font> Moduic Squares</H1>
<p>
Have you ever heard of Moduic Squares? They are like 3 × 3 Magic Squares, but each of them has one
extra cell called a moduic cell. Hence a Moduic Square has the following form.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_moduicSquares1">
<p>Figure 1: A Moduic Square</p>
</center>
<p>
Each of cells labeled from A to J contains one number from 1 to 10, where no two cells contain the same
number. The sums of three numbers in the same rows, in the same columns, and in the diagonals in the
3 × 3 cells must be congruent modulo the number in the moduic cell. Here is an example Moduic Square:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_moduicSquares2">
<p>Figure 2: An example Moduic Square</p>
</center>
<p>
You can easily see that all the sums are congruent to 0 modulo 5.
</p>
<p>
Now, we can consider interesting puzzles in which we complete Moduic Squares with partially filled cells.
For example, we can complete the following square by filling 4 into the empty cell on the left and 9 on
the right. Alternatively, we can also complete the square by filling 9 on the left and 4 on the right. So
this puzzle has two possible solutions.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_moduicSquares3">
<p>Figure 3: A Moduic Square as a puzzle</p>
</center>
<p>
Your task is to write a program that determines the number of solutions for each given puzzle.
</p>
<H2>Input</H2>
<p>
The input contains multiple test cases. Each test case is specified on a single line made of 10 integers
that represent cells A, B, C, D, E, F, G, H, I, and J as shown in the first figure of the problem statement.
Positive integer means that the corresponding cell is already filled with the integer. Zero means that the
corresponding cell is left empty.
</p>
<p>
The end of input is identified with a line containing ten of -1’s. This is not part of test cases.
</p>
<H2>Output</H2>
<p>
For each test case, output a single integer indicating the number of solutions on a line. There may be
cases with no solutions, in which you should output 0 as the number.
</p>
<H2>Sample Input</H2>
<pre>
3 1 6 8 10 7 0 0 2 5
0 0 0 0 0 0 0 0 0 1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
362880
</pre>
|
p03016 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><!-- You are given <var>Q</var> tuples of integers <var>(L_i, A_i, B_i, M_i)</var>. For each tuple, answer the following question. -->
<p>There is an arithmetic progression with <var>L</var> terms: <var>s_0, s_1, s_2, ... , s_{L-1}</var>.</p>
<p>The initial term is <var>A</var>, and the common difference is <var>B</var>. That is, <var>s_i = A + B \times i</var> holds.</p>
<p>Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence <var>3, 7, 11, 15, 19</var> would be concatenated into <var>37111519</var>. What is the remainder when that integer is divided by <var>M</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers.</li>
<li><var>1 \leq L, A, B < 10^{18}</var></li>
<li><var>2 \leq M \leq 10^9</var></li>
<li>All terms in the arithmetic progression are less than <var>10^{18}</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>A</var> <var>B</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the remainder when the integer obtained by concatenating the terms is divided by <var>M</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3 4 10007
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5563
</pre>
<p>Our arithmetic progression is <var>3, 7, 11, 15, 19</var>, so the answer is <var>37111519</var> mod <var>10007</var>, that is, <var>5563</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 8 1 1000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>891011
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>107 10000000000007 1000000000000007 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>39122908
</pre></section>
</div>
</span> |
p02257 |
<H1>Prime Numbers</H1>
<p>
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
</p>
<p>
Write a program which reads a list of <i>N</i> integers and prints the number of prime numbers in the list.
</p>
<H2>Input</H2>
<p>
The first line contains an integer <i>N</i>, the number of elements in the list.
</p>
<p>
<i>N</i> numbers are given in the following lines.
</p>
<H2>Output</H2>
<p>
Print the number of prime numbers in the given list.
</p>
<H2>Constraints</H2>
<p>
1 ≤ <i>N</i> ≤ 10000
</p>
<p>
2 ≤ <i>an element of the list</i> ≤ 10<sup>8</sup>
</p>
<H2>Sample Input 1</H2>
<pre class="format">
5
2
3
4
5
6
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
<H2>Sample Input 2</H2>
<pre>
11
7
8
9
10
11
12
13
14
15
16
17
</pre>
<H2>Sample Output 2</H2>
<pre>
4
</pre>
|
p01882 |
<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>We don't wanna work!</h2>
<p>
ACM is an organization of programming contests. The purpose of ACM does not matter to you. The only important thing is that workstyles of ACM members are polarized: each member is either a workhorse or an idle fellow.
</p>
<p>
Each member of ACM has a motivation level. The members are ranked by their motivation levels: a member who has a higher motivation level is ranked higher. When several members have the same value of motivation levels, the member who joined ACM later have a higher rank. The top 20% highest ranked members work hard, and the other (80%) members never (!) work. Note that if 20% of the number of ACM members is not an integer, its fraction part is rounded down.
</p>
<p>
You, a manager of ACM, tried to know whether each member is a workhorse or an idle fellow to manage ACM. Finally, you completed to evaluate motivation levels of all the current members. However, your task is not accomplished yet because the members of ACM are dynamically changed from day to day due to incoming and outgoing of members. So, you want to record transitions of members from workhorses to idle fellows, and vice versa.
</p>
<p>
You are given a list of the current members of ACM and their motivation levels in chronological order of their incoming date to ACM. You are also given a list of incoming/outgoing of members in chronological order.
</p>
<p>
Your task is to write a program that computes changes of workstyles of ACM members.
</p>
<h3>Input</h3>
<p>
The first line of the input contains a single integer $N$ ($1 \leq N \leq 50,000$) that means the number of initial members of ACM. The ($i$ + 1)-th line of the input contains a string $s_i$ and an integer $a_i$ ($0 \leq a_i \leq 10^5$), separated by a single space. $s_i$ means the name of the $i$-th initial member and $a_i$ means the motivation level of the $i$-th initial member. Each character of $s_i$ is an English letter, and $1 \leq |s_i| \leq 20$. Note that those $N$ lines are ordered in chronological order of incoming dates to ACM of each member.
</p>
<p>
The ($N$ + 2)-th line of the input contains a single integer $M$ ($1 \leq M \leq 20,000$) that means the number of changes of ACM members. The ($N$ + 2 + $j$)-th line of the input contains information of the $j$-th incoming/outgoing member. When the $j$-th information represents an incoming of a member, the information is formatted as "$+ t_j b_j$", where $t_j$ is the name of the incoming member and $b_j$ ($0 \leq b_j \leq 10^5$) is his motivation level. On the other hand, when the $j$-th information represents an outgoing of a member, the information is formatted as "$- t_j$", where $t_j$ means the name of the outgoing member. Each character of $t_j$ is an English letter, and $1 \leq |t_j| \leq 20$. Note that uppercase letters and lowercase letters are distinguished. Note that those $M$ lines are ordered in chronological order of dates when each event happens.
</p>
<p>
No two incoming/outgoing events never happen at the same time. No two members have the same name, but members who left ACM once may join ACM again.
</p>
<h3>Output</h3>
<p>
Print the log, a sequence of changes in chronological order. When each of the following four changes happens, you should print a message corresponding to the type of the change as follows:
</p>
<ul>
<li> Member $name$ begins to work hard : "$name$ is working hard now."</li>
<li> Member $name$ begins to not work : "$name$ is not working now."</li>
</ul>
<p>
For each incoming/outgoing, changes happen in the following order:
</p>
<ol>
<li> Some member joins/leaves.</li>
<li> When a member joins, the member is added to either workhorses or idle fellows.</li>
<li> Some member may change from a workhorse to an idle fellow and vice versa. Note that there are no cases such that two or more members change their workstyles at the same time.</li>
</ol>
<h3>Sample Input 1</h3>
<pre>
4
Durett 7
Gayles 3
Facenda 6
Daughtery 0
1
+ Mccourtney 2
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
Mccourtney is not working now.
Durett is working hard now.
</pre>
<p>
Initially, no member works because $4 \times 20$% $< 1$. When one member joins ACM, Durrett begins to work hard.
</p>
<h3>Sample Input 2</h3>
<pre>
3
Burdon 2
Orlin 8
Trumper 5
1
+ Lukaszewicz 7
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
Lukaszewicz is not working now.
</pre>
<p>No member works.</p>
<h3>Sample Input 3</h3>
<pre>
5
Andy 3
Bob 4
Cindy 10
David 1
Emile 1
3
+ Fred 10
- David
+ Gustav 3
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
Fred is working hard now.
Cindy is not working now.
Gustav is not working now.
</pre>
<h3>Sample Input 4</h3>
<pre>
7
Laplant 5
Varnes 2
Warchal 7
Degregorio 3
Chalender 9
Rascon 5
Burdon 0
7
+ Mccarroll 1
- Chalender
+ Orlin 2
+ Chalender 1
+ Marnett 10
- Chalender
+ Chalender 0
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
Mccarroll is not working now.
Warchal is working hard now.
Orlin is not working now.
Chalender is not working now.
Marnett is working hard now.
Warchal is not working now.
Chalender is not working now.
Warchal is working hard now.
</pre>
<p>
Some member may repeat incoming and outgoing.
</p>
<h3>Sample Input 5</h3>
<pre>
4
Aoba 100
Yun 70
Hifumi 120
Hajime 50
2
- Yun
- Aoba
</pre>
<h3>Output for the Sample Input 5</h3>
<pre>
(blank)
</pre>
|
p00790 |
<H1><font color="#000">Problem C:</font> Die Game</H1>
<p>
Life is not easy. Sometimes it is beyond your control. Now, as contestants of ACM ICPC, you might be just tasting the bitter of life. But don't worry! Do not look only on the dark side of life, but look also on the bright side. Life may be an enjoyable game of chance, like throwing dice. Do or die! Then, at last, you might be able to find the route to victory.
</p>
<p>
This problem comes from a game using a die. By the way, do you know a die? It has nothing to do with "death." A die is a cubic object with six faces, each of which represents a different number from one to six and is marked with the corresponding number of spots. Since it is usually used in pair, "a die" is rarely used word. You might have heard a famous phrase "the die is cast," though.
</p>
<p>
When a game starts, a die stands still on a flat table. During the game, the die is tumbled in all directions by the dealer. You will win the game if you can predict the number seen on the top face at the time when the die stops tumbling.
</p>
<p>
Now you are requested to write a program that simulates the rolling of a die. For simplicity, we assume that the die neither slip nor jumps but just rolls on the table in four directions, that is, north, east, south, and west. At the beginning of every game, the dealer puts the die at the center of the table and adjusts its direction so that the numbers one, two, and three are seen on the top, north, and west faces, respectively. For the other three faces, we do not explicitly specify anything but tell you the golden rule: the sum of the numbers on any pair of opposite faces is always seven.
</p>
<p>
Your program should accept a sequence of commands, each of which is either "north", "east", "south", or "west". A "north" command tumbles the die down to north, that is, the top face becomes the new north, the north becomes the new bottom, and so on. More precisely, the die is rotated around its north bottom edge to the north direction and the rotation angle is 9 degrees. Other commands also tumble the die accordingly to their own directions. Your program should calculate the number finally shown on the top after performing the commands in the sequence. Note that the table is sufficiently large and the die never falls off during the game.
</p>
<H2>Input</H2>
<p>
The input consists of one or more command sequences, each of which corresponds to a single game. The first line of a command sequence contains a positive integer, representing the number of the following command lines in the sequence. You may assume that this number is less than or equal to 1024. A line containing a zero indicates the end of the input. Each command line includes a command that is one of north, east, south, and west. You may assume that no white space occurs in any line.
</p>
<H2>Output</H2>
<p>
For each command sequence, output one line containing solely the number of the top face at the time when the game is finished.
</p>
<H2>Sample Input</H2>
<pre>
1
north
3
north
east
south
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
1
</pre>
|
p01928 |
<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>マトリョーシカはロシアの民芸品として有名な人形である.
マトリョーシカは上下に分割でき,開くと中により小さい別の人形が入っている.
現れた小さい人形を開くとさらに小さい人形が入っている,というような入れ子構造になっている.
</p>
<div style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2017_matryoshkas" witdh="300" height="300">
<br/>
</div>
<p>あなたは旅行先で珍しい形のマトリョーシカを見つけ,<i>N</i> 体の人形を購入した.
<i>i</i> 番目の人形の形状は,<i>x<sub>i</sub> × y<sub>i</sub> × z<sub>i</sub></i> の直方体である.
</p>
<p>ひとしきりマトリョーシカを鑑賞したあなたは,マトリョーシカを仕舞おうとしている.
その前に,いくつかの人形を別の人形に格納することによって必要なスペースを減らしたい.
人形を格納する際には,まだ中にひとつも人形を格納していない人形にだけ,他の人形をひとつ格納できる.
ただし,直接的に格納される人形についてだけ数えるものとし,中に人形が入っている人形を別の人形に格納することはできる.
</p>
<p>収納された人形は,外部から見えない状態になる.
ただし,以下の条件を満たさなければならない.
</p><ul><li> 人形は回転してよいが,直方体のそれぞれの辺は,他方の直方体のいずれかの辺に平行
</li><li> 回転後,対応する辺同士の長さそれぞれについて,収納される側の人形の長さの方が短い
</li><li> 1 個の人形の中に直接収納できる人形の数は高々 1 個
</li></ul>
<p>押入れの容積は限られているので,外部から見えている人形の体積の和を最小化したい.
あなたの仕事は,人形を収納する操作を任意の回数繰り返して達成できる,外部から見えている人形の体積の和の最小値を求めるプログラムを作成することである.
</p>
<h3>Input</h3>
<p>入力は複数のデータセットからなる.
データセットの個数は最大でも 50 個を超えない.
各データセットは次の形式で表される.
</p><blockquote><i>N</i><br><i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>z<sub>1</sub></i><br>:<br>:<br><i>x<sub>N</sub></i> <i>y<sub>N</sub></i> <i>z<sub>N</sub></i><br></blockquote>
<p>各データセットは <i>N + 1</i> 行からなり,データセットの 1 行目には,人形の数を表す整数 <i>N</i> が与えられる.
続く <i>N</i> 行の内 <i>i</i> 行目には,<i>i</i> 番目の人形の大きさを表す 3 つの整数 <i>x<sub>i</sub>, y<sub>i</sub>, z<sub>i</sub></i> が半角スペース区切りで与えられる.
これらの整数は,<i>1 ≤ N, x<sub>i</sub>, y<sub>i</sub>, z<sub>i</sub> ≤ 100</i> を満たす.
</p><blockquote></blockquote>
<p>入力の終わりは 1 つのゼロからなる行で表される.
</p><blockquote></blockquote>
<h3>Output</h3>
<p>各データセットについて,外部から見えている人形の体積の和の最小値を 1 行で出力せよ.
</p><blockquote></blockquote>
<h3>Sample Input</h3>
<pre>2
1 2 3
4 2 3
3
2 5 2
3 3 4
5 5 5
5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
5
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
10
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6 4
3 3 8
3 2 7
0
</pre>
<h3>Output for Sample Input</h3>
<pre>24
145
125
15
864</pre>
|
p03915 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a graph with <var>N</var> vertices, numbered <var>0</var> through <var>N-1</var>. Edges are yet to be added.</p>
<p>We will process <var>Q</var> queries to add edges.
In the <var>i</var>-th <var>(1≦i≦Q)</var> query, three integers <var>A_i, B_i</var> and <var>C_i</var> will be given, and we will add infinitely many edges to the graph as follows:</p>
<ul>
<li>The two vertices numbered <var>A_i</var> and <var>B_i</var> will be connected by an edge with a weight of <var>C_i</var>.</li>
<li>The two vertices numbered <var>B_i</var> and <var>A_i+1</var> will be connected by an edge with a weight of <var>C_i+1</var>.</li>
<li>The two vertices numbered <var>A_i+1</var> and <var>B_i+1</var> will be connected by an edge with a weight of <var>C_i+2</var>.</li>
<li>The two vertices numbered <var>B_i+1</var> and <var>A_i+2</var> will be connected by an edge with a weight of <var>C_i+3</var>.</li>
<li>The two vertices numbered <var>A_i+2</var> and <var>B_i+2</var> will be connected by an edge with a weight of <var>C_i+4</var>.</li>
<li>The two vertices numbered <var>B_i+2</var> and <var>A_i+3</var> will be connected by an edge with a weight of <var>C_i+5</var>.</li>
<li>The two vertices numbered <var>A_i+3</var> and <var>B_i+3</var> will be connected by an edge with a weight of <var>C_i+6</var>.</li>
<li>...</li>
</ul>
<p>Here, consider the indices of the vertices modulo <var>N</var>.
For example, the vertice numbered <var>N</var> is the one numbered <var>0</var>, and the vertice numbered <var>2N-1</var> is the one numbered <var>N-1</var>.</p>
<p>The figure below shows the first seven edges added when <var>N=16, A_i=7, B_i=14, C_i=1</var>:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/5b0258fb4255f846a4e10ce875362baf.png"/></p>
<p>After processing all the queries, find the total weight of the edges contained in a minimum spanning tree of the graph.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦200,000</var></li>
<li><var>1≦Q≦200,000</var></li>
<li><var>0≦A_i,B_i≦N-1</var></li>
<li><var>1≦C_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>Q</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>A_Q</var> <var>B_Q</var> <var>C_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total weight of the edges contained in a minimum spanning tree of the graph.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 1
5 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>21
</pre>
<p>The figure below shows the minimum spanning tree of the graph:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/f1a6c3cfd52c386e6da5c8c761a78521.png"/></p>
<p>Note that there can be multiple edges connecting the same pair of vertices.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 1
0 0 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000000001
</pre>
<p>Also note that there can be self-loops.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 3
0 1 10
0 2 10
0 4 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>42
</pre></section>
</div>
</span> |
p02607 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> squares assigned the numbers <var>1,2,3,\ldots,N</var>. Each square has an integer written on it, and the integer written on Square <var>i</var> is <var>a_i</var>.</p>
<p>How many squares <var>i</var> satisfy both of the following conditions?</p>
<ul>
<li>The assigned number, <var>i</var>, is odd.</li>
<li>The written integer is odd.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N, a_i \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>N</var>
<var>a_1</var> <var>a_2</var> <var>\cdots</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of squares that satisfy both of the conditions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 3 4 5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<ul>
<li>Two squares, Square <var>1</var> and <var>5</var>, satisfy both of the conditions.</li>
<li>For Square <var>2</var> and <var>4</var>, the assigned numbers are not odd.</li>
<li>For Square <var>3</var>, the written integer is not odd.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15
13 76 46 15 50 98 93 77 31 43 84 90 6 24 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre></section>
</div>
</span> |
p00114 |
<h1>電子蝿</h1>
<p>
ある計算機学者が電子空間に棲息する電子蝿という奇妙な生命体を見つけました。電子蝿の行動を観察しているうちに、この空間の (<var>x</var>, <var>y</var>, <var>z</var>) 地点にいる電子蝿は、次に以下の規則で示される (<var>x'</var>, <var>y'</var>, <var>z'</var>)に移動することが分かりました。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_electroFly">
</center>
<br/>
<p>
ただし、<var>a</var><sub>1</sub>, <var>m</var><sub>1</sub>, <var>a</var><sub>2</sub>, <var>m</var><sub>2</sub>, <var>a</var><sub>3</sub>, <var>m</var><sub>3</sub> は電子蝿の個体ごとに定まる正の整数です。<var>A</var> mod <var>B</var> は正の整数 <var>A</var> を正の整数 <var>B</var> で割ったときの余りです。
</p>
<p>
さらに観察をすると、ある種の電子蝿は (1,1,1) に置いてからしばらくすると、必ず (1,1,1) に戻ってくることがわかりました。このような蝿を戻り蝿と名付けました<sup>(1)</sup> 。
</p>
<p>
戻り蝿のデータを入力とし、(1,1,1) に戻ってくる最小の移動回数 (>0) を出力するプログラムを作成してください。なお 1< <var>a</var><sub>1</sub>, <var>m</var><sub>1</sub>, <var>a</var><sub>2</sub>, <var>m</var><sub>2</sub>, <var>a</var><sub>3</sub>, <var>m</var><sub>3</sub> < 2<sup>15</sup> とします。
</p>
<p>
<sup>(1)</sup> <var>a</var><sub>1</sub> と <var>m</var><sub>1</sub>, <var>a</var><sub>2</sub> と <var>m</var><sub>2</sub>, <var>a</var><sub>3</sub> と <var>m</var><sub>3</sub> がそれぞれ互いに素 (公約数が 1) である時に戻ります。
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。各データセットは以下の形式で与えられます。
</p>
<pre>
<var>a</var><sub>1</sub> <var>m</var><sub>1</sub> <var>a</var><sub>2</sub> <var>m</var><sub>2</sub> <var>a</var><sub>3</sub> <var>m</var><sub>3</sub>
</pre>
<p>
入力は6つの 0 を含む行で終わります。データセットの数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
各データセットごとに、(1,1,1) に戻ってくる最小の移動回数(整数)を1行に出力してください。
</p>
<H2>Sample Input</H2>
<pre>
2 5 3 7 6 13
517 1024 746 6561 4303 3125
0 0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
12
116640000
</pre>
|
p02129 | <h1>Problem F: Ghost Legs</h1>
<h2>Problem</h2>
<p>
縦線が3本のあみだくじが$N$個ある。<br>
どの線からスタートしてもスタートした線で終わるあみだくじを良いあみだくじとする。<br>
あみだくじを1つ以上選んで縦に自由な順序でつなぐことができる。<br>
良いあみだくじを作ることができるのであれば"yes"、そうでなければ"no"を出力せよ。<br>
<br>
$i$番目のあみだくじには横線が$w_i$本ある。<br>
$a_{i,j}$はあみだくじ$i$の上から$j$番目の横棒が中央の縦線から左右どちらに伸びているかを表し、<br>
$a_{i,j}$が0ならば左に、1ならば右に伸びていることを表す。<br>
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
$N$
$w_1$ $a_{1,1}$ $a_{1,2}$ ... $a_{1,w_1}$
$w_2$ $a_{2,1}$ $a_{2,2}$ ... $a_{2,w_2}$
...
$w_N$ $a_{N,1}$ $a_{N,2}$ ... $a_{N,w_N}$
</pre>
<p>
入力はすべて整数で与えられる。<br>
1行目に$N$が与えられる。<br>
続く$N$行に$w_i$と$w_i$個の$a_{i,j}$が空白区切りで与えられる。<br>
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$1 \le N \le 50$</li>
<li>$0 \le w_i \le 100$</li>
<li>$a_{i,j}$は0または1</li>
</ul>
<h2>Output</h2>
<p>
良いあみだくじを作ることができるのであれば"yes"、そうでなければ"no"を出力する。<br>
</p>
<h2>Sample Input 1</h2>
<pre>
3
2 0 0
1 1
5 1 0 0 1 0
</pre>
<h2>Sample Output 1</h2>
<pre>
yes
</pre>
<h2>Sample Input 2</h2>
<pre>
2
1 1
1 0
</pre>
<h2>Sample Output 2</h2>
<pre>
no
</pre>
|
p02083 | <h1>F: Clique Drawing</h1>
<h2>問題文</h2>
<p>$M$ 回操作を行って $N$ 頂点のグラフを作ります。
初め、$N$ 頂点のどの頂点間にも辺は存在しません。
$i$ 番目の操作では、頂点集合 $\{ v_{i, 1}, v_{i, 2}, ... , v_{i, K_i} \}$ の全ての $2$ 頂点間に辺を張ります。ただし、以前の操作によって既に辺が貼られている頂点間には張りません。
また、どの頂点も $M$ 回の操作の内高々 $2$ 回の操作にしか現れません。
これらの操作によって出来たグラフ上の、最大独立集合の大きさを求めてください。</p>
<p>無向グラフ $G = (V, E)$ の独立集合 $U$ とは、$U \subseteq V$ なる頂点の部分集合であって、全ての $u, v \in U$ について、$(u, v) \notin E$ を満たすものを指します。
最大独立集合とは、このような独立集合の内、最も大きいものを指します。</p>
<h2>制約</h2>
<ul>
<li>入力は全て整数</li>
<li>$1 \leq N \leq 10^5$</li>
<li>$1 \leq M \leq 300$</li>
<li>$2 \leq K_i \leq N$ ($1 \leq i \leq M$) </li>
<li>$1 \leq v_{i, j} \leq N$ ($1 \leq i \leq M, 1 \leq j \leq K_i$)</li>
<li>$\{ v_{i, 1}, v_{i, 2}, ... , v_{i, K_i} \}$ の中に重複した値は存在しない ($1 \leq i \leq M$) </li>
<li>全ての頂点は最大でも2回の操作にしか含まれない</li>
</ul>
<h2>入力</h2>
<p>入力は以下の形式で標準入力から与えられます。</p>
<pre>$N$ $M$
$K_1$ $v_{1, 1}$ $\ldots$ $v_{1, K_1}$
$\vdots$
$K_M$ $v_{M, 1}$ $\ldots$ $v_{M, K_M}$</pre>
<h2>出力</h2>
<p>答えを一行で出力してください。</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>2 1
2 1 2
</pre>
<h3>出力例1</h3>
<pre>1
</pre>
<p>1回の操作の後、2頂点からなる道が出来ます。
したがって、最大独立集合の大きさは1です。</p>
<h3>入力例2</h3>
<pre>4 1
3 1 2 3
</pre>
<h3>出力例2</h3>
<pre>2
</pre>
<h3>入力例3</h3>
<pre>6 3
3 2 3 5
3 3 4 6
3 1 2 4
</pre>
<h3>出力例3</h3>
<pre>3
</pre>
|
p00544 |
<h1>ロシアの旗 (Russian Flag)</h1>
<h2> 問題</h2>
<p>
K 理事長はロシアで開催される IOI 2016 に合わせて旗を作ることにした.K 理事長はまず倉庫から古い旗を取り出してきた.この旗は N 行 M 列のマス目に分けられていて,それぞれのマスには白・青・赤のいずれかの色が塗られている.
</p>
<p>
K 理事長はこの旗のいくつかのマスを塗り替えて<b>ロシアの旗</b>にしようとしている.ただし,この問題でいうロシアの旗とは以下のようなものである.
</p>
<ul>
<li>上から何行か (1 行以上) のマスが全て白で塗られている.</li>
<li>続く何行か (1 行以上) のマスが全て青で塗られている.</li>
<li>それ以外の行 (1 行以上) のマスが全て赤で塗られている.</li>
</ul>
<p>
K 理事長が古い旗をロシアの旗にするために塗り替える必要のあるマスの個数の最小値を求めよ.
</p>
<h2> 入力</h2>
<p>
入力は 1 + N 行からなる.
</p>
<p>
1 行目には,2 つの整数 N, M (3 ≦ N ≦ 50, 3 ≦ M ≦ 50) が空白を区切りとして書かれている.これは,旗が N 行 M 列のマス目に区切られていることを表す.
</p>
<p>
続く N 行にはそれぞれ M 文字からなる文字列が書かれており,古い旗のマス目に塗られている色の情報を表す.N 行のうちの i 行目の j 文字目 (1 ≦ i ≦ N, 1 ≦ j ≦ M) は,古い旗のマス目の i 行目 j 列目のマスの色を表す 'W', 'B', 'R' のいずれかの文字である.
'W' は白,'B' は青,'R' は赤を表す.
</p>
<h2> 出力</h2>
<p>
K 理事長が古い旗をロシアの旗にするために塗り替える必要のあるマスの個数の最小値を 1 行で出力せよ.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
4 5
WRWRW
BWRWB
WRWRW
RWBWR
</pre>
<h3>出力例 1</h3>
<pre>
11
</pre>
<h3>入力例 2</h3>
<pre>
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
</pre>
<h3>出力例 2</h3>
<pre>
44
</pre>
<p>
入出力例 1 において,古い旗には下図のように色が塗られている.
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_2016-yo-t3-fig01" alt="fig01" />
</p>
<p>
下図において,'X' の書かれた 11 個のマスを塗り替える.
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_2016-yo-t3-fig02" alt="fig02" />
</p>
<p>
これにより下図のようなロシアの旗にすることができる.
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_2016-yo-t3-fig03" alt="fig03" />
</p>
<p>
11 個未満のマスを塗り替えることではロシアの旗にすることはできないため,11 を出力する.
</p>
<p>
入出力例 2 においては,古い旗には下図のように色が塗られている.
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_2016-yo-t3-fig04" alt="fig04" />
</p>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2015/2016-yo/index.html">情報オリンピック日本委員会作 『第 15 回日本情報オリンピック JOI 2015/2016 予選競技課題』</a>
</p>
</div>
|
p02579 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A maze is composed of a grid of <var>H \times W</var> squares - <var>H</var> vertical, <var>W</var> horizontal.</p>
<p>The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left - <var>(i,j)</var> - is a wall if <var>S_{ij}</var> is <code>#</code> and a road if <var>S_{ij}</var> is <code>.</code>.</p>
<p>There is a magician in <var>(C_h,C_w)</var>. He can do the following two kinds of moves:</p>
<ul>
<li>Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.</li>
<li>Move B: Use magic to warp himself to a road square in the <var>5\times 5</var> area centered at the square he is currently in.</li>
</ul>
<p>In either case, he cannot go out of the maze.</p>
<p>At least how many times does he need to use the magic to reach <var>(D_h, D_w)</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 10^3</var></li>
<li><var>1 \leq C_h,D_h \leq H</var></li>
<li><var>1 \leq C_w,D_w \leq W</var></li>
<li><var>S_{ij}</var> is <code>#</code> or <code>.</code>.</li>
<li><var>S_{C_h C_w}</var> and <var>S_{D_h D_w}</var> are <code>.</code>.</li>
<li><var>(C_h,C_w) \neq (D_h,D_w)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>C_h</var> <var>C_w</var>
<var>D_h</var> <var>D_w</var>
<var>S_{11}\ldots S_{1W}</var>
<var>\vdots</var>
<var>S_{H1}\ldots S_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of times the magician needs to use the magic. If he cannot reach <var>(D_h,D_w)</var>, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
1 1
4 4
..#.
..#.
.#..
.#..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>For example, by walking to <var>(2,2)</var> and then using the magic to travel to <var>(4,4)</var>, just one use of magic is enough.</p>
<p>Note that he cannot walk diagonally.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
1 4
4 1
.##.
####
####
.##.
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>He cannot move from there.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 4
2 2
3 3
....
....
....
....
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>No use of magic is needed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 5
1 2
2 5
#.###
####.
#..##
#..##
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>2
</pre></section>
</div>
</span> |
p03738 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two positive integers <var>A</var> and <var>B</var>. Compare the magnitudes of these numbers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ A, B ≤ 10^{100}</var></li>
<li>Neither <var>A</var> nor <var>B</var> begins with a <code>0</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>A</var>
<var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>GREATER</code> if <var>A>B</var>, <code>LESS</code> if <var>A<B</var> and <code>EQUAL</code> if <var>A=B</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>36
24
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>GREATER
</pre>
<p>Since <var>36>24</var>, print <code>GREATER</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>850
3777
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>LESS
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9720246
22516266
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>LESS
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>123456789012345678901234567890
234567890123456789012345678901
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>LESS
</pre></section>
</div>
</span> |
p01705 |
<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>Circles Island is known for its mysterious shape:
it is a completely flat island with its shape being a union of circles whose centers are on the $x$-axis and their inside regions.
</p>
<p>The King of Circles Island plans to build a large square on Circles Island in order to celebrate the fiftieth anniversary of his accession.
The King wants to make the square as large as possible.
The whole area of the square must be on the surface of Circles Island, but any area of Circles Island can be used for the square.
He also requires that the shape of the square is square (of course!) and at least one side of the square is parallel to the $x$-axis.
</p>
<p>You, a minister of Circles Island, are now ordered to build the square.
First, the King wants to know how large the square can be.
You are given the positions and radii of the circles that constitute Circles Island.
Answer the side length of the largest possible square.
</p>
<p>$N$ circles are given in an ascending order of their centers' $x$-coordinates.
You can assume that for all $i$ ($1 \le i \le N-1$), the $i$-th and $(i+1)$-st circles overlap each other.
You can also assume that no circles are completely overlapped by other circles.
</p>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_square-small" height="250" width="500" />
</p>
<p>[fig.1 : Shape of Circles Island and one of the largest possible squares for test case #1 of sample input]
</p>
</div><div class="part"><h3>Input</h3>
<p>The input consists of multiple datasets. The number of datasets does not exceed $30$.
Each dataset is formatted as follows.
</p>
<blockquote style="font-size:14pt">$N$<br>$X_1$ $R_1$<br>:<br>:<br>$X_N$ $R_N$</blockquote>
<p>The first line of a dataset contains a single integer $N$ ($1 \le N \le 50{,}000$), the number of circles that constitute Circles Island.
Each of the following $N$ lines describes a circle.
The $(i+1)$-st line contains two integers $X_i$ ($-100{,}000 \le X_i \le 100{,}000$) and $R_i$ ($1 \le R_i \le 100{,}000$).
$X_i$ denotes the $x$-coordinate of the center of the $i$-th circle and $R_i$ denotes the radius of the $i$-th circle.
The $y$-coordinate of every circle is $0$, that is, the center of the $i$-th circle is at ($X_i$, $0$).
</p>
<p>You can assume the followings.
</p><ul><li> For all $i$ ($1 \le i \le N-1$), $X_i$ is strictly less than $X_{i+1}$.
</li><li> For all $i$ ($1 \le i \le N-1$), the $i$-th circle and the $(i+1)$-st circle have at least one common point ($X_{i+1} - X_i \le R_i + R_{i+1}$).
</li><li> Every circle has at least one point that is not inside or on the boundary of any other circles.
</li></ul>
<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 side length of the square with the largest area.
The output must have an absolute or relative error at most $10^{-4}$.
</p>
</div><div class="part"><h3>Sample Input</h3>
<pre>2
0 8
10 8
2
0 7
10 7
0</pre>
</div><div class="part"><h3>Output for the Sample Input</h3>
<pre>12.489995996796796
9.899494936611665</pre>
</div> |
p00817 | <H1><font color="#000">Problem G:</font> True Liars</H1>
<p>
After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had heard from patriarchs in his childhood. This must be the island in the legend.
</p>
<p>
In the legend, two tribes have inhabited the island, one is divine and the other is devilish; once members of the divine tribe bless you, your future is bright and promising, and your soul will eventually go to Heaven; in contrast, once members of the devilish tribe curse you, your future is bleak and hopeless, and your soul will eventually fall down to Hell.
</p>
<p>
In order to prevent the worst-case scenario, Akira should distinguish the devilish from the divine. But how? They looked exactly alike and he could not distinguish one from the other solely by their appearances. He still had his last hope, however. The members of the divine tribe are truth-tellers, that is, they always tell the truth and those of the devilish tribe are liars, that is, they always tell a lie.
</p>
<p>
He asked some of the whether or not some are divine. They knew one another very much and always responded to him "faithfully" according to their individual natures (i.e., they always tell the truth or always a lie). He did not dare to ask any other forms of questions, since the legend says that a devilish member would curse a person forever when he did not like the question. He had another piece of useful information: the legend tells the populations of both tribes. These numbers in the legend are trustworthy since everyone living on this island is immortal and none have ever been born at least these millennia.
</p>
<p>
You are a good computer programmer and so requested to help Akira by writing a program that classifies the inhabitants according to their answers to his inquiries.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets, each in the following format:
</p>
<pre>
<i>n</i> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>a</i><sub>1</sub>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>a</i><sub>2</sub>
...
<i>x</i><sub><i>i</i></sub> <i>y</i><sub><i>i</i></sub> <i>a</i><sub><i>i</i></sub>
...
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> <i>a</i><sub><i>n</i></sub>
</pre>
<p>
The first line has three non-negative integers <i>n</i>, <i>p</i><sub>1</sub>, and <i>p</i><sub>2</sub>. <i>n</i> is the number of questions Akira asked. <i>p</i><sub>1</sub> and <i>p</i><sub>2</sub> are the populations of the divine and devilish tribes, respectively, in the legend. Each of the following <i>n</i> lines has two integers <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> and one word <i>a<sub>i</sub></i>. <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> are the identification numbers of inhabitants, each of which is between 1 and <i>p</i><sub>1</sub> + <i>p</i><sub>2</sub>, inclusive. <i>a<sub>i</sub></i> is either "yes", if the inhabitant <i>x<sub>i</sub></i> said that the inhabitant <i>y<sub>i</sub></i> was a member of the divine tribe, or "no", otherwise. Note that <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> can be the same number since "are you a member of the divine tribe?" is a valid question. Note also that two lines may have the same <i>x</i>'s and <i>y</i>'s since Akira was very upset and might have asked the same question to the same one more than once.
</p>
<p>
You may assume that <i>n</i> is less than 1000 and that <i>p</i><sub>1</sub> and <i>p</i><sub>2</sub> are less than 300. A line with three zeros, i.e., "0 0 0", represents the end of the input. You can assume that each data set is consistent and no contradictory answers are included.
</p>
<H2>Output</H2>
<p>
For each data set, if it includes sufficient information to classify all the inhabitants, print the identification numbers of all the divine ones in ascending order, one in a line. In addition, following the output numbers, print "end" in a line. Otherwise, i.e., if a given data set does not include sufficient information to identify all the divine members, print "no" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2 1 1
1 2 no
2 1 no
3 2 1
1 1 yes
2 2 yes
3 3 yes
2 2 1
1 2 yes
2 3 no
5 4 3
1 2 yes
1 3 no
4 5 yes
5 6 yes
6 7 no
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
no
no
1
2
end
3
4
5
6
end
</pre>
|
p03692 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a directed graph <var>G</var> with <var>N</var> vertices and <var>M</var> edges.
The vertices are numbered <var>1</var> through <var>N</var>, and the edges are numbered <var>1</var> through <var>M</var>.
Edge <var>i</var> is directed from <var>x_i</var> to <var>y_i</var>.
Here, <var>x_i < y_i</var> holds.
Also, there are no multiple edges in <var>G</var>.</p>
<p>Consider selecting a subset of the set of the <var>M</var> edges in <var>G</var>, and removing these edges from <var>G</var> to obtain another graph <var>G'</var>.
There are <var>2^M</var> different possible graphs as <var>G'</var>.</p>
<p>Alice and Bob play against each other in the following game played on <var>G'</var>.
First, place two pieces on vertices <var>1</var> and <var>2</var>, one on each.
Then, starting from Alice, Alice and Bob alternately perform the following operation:</p>
<ul>
<li>Select an edge <var>i</var> such that there is a piece placed on vertex <var>x_i</var>, and move the piece to vertex <var>y_i</var> (if there are two pieces on vertex <var>x_i</var>, only move one). The two pieces are allowed to be placed on the same vertex.</li>
</ul>
<p>The player loses when he/she becomes unable to perform the operation.
We assume that both players play optimally.</p>
<p>Among the <var>2^M</var> different possible graphs as <var>G'</var>, how many lead to Alice's victory?
Find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ N ≤ 15</var></li>
<li><var>1 ≤ M ≤ N(N-1)/2</var></li>
<li><var>1 ≤ x_i < y_i ≤ N</var></li>
<li>All <var>(x_i,\ y_i)</var> are distinct.</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>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_M</var> <var>y_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of <var>G'</var> that lead to Alice's victory, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The figure below shows the two possible graphs as <var>G'</var>.
A graph marked with ○ leads to Alice's victory, and a graph marked with × leads to Bob's victory.</p>
<div style="text-align: center;">
<img alt="b250f23c38d0f5ec2204bd714e7c1516.png" src="https://atcoder.jp/img/agc016/b250f23c38d0f5ec2204bd714e7c1516.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
<p>The figure below shows the eight possible graphs as <var>G'</var>.</p>
<div style="text-align: center;">
<img alt="8192fd32f894f708c5e4a60dcdea9d35.png" src="https://atcoder.jp/img/agc016/8192fd32f894f708c5e4a60dcdea9d35.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2
1 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 10
2 4
3 4
2 5
2 3
1 2
3 5
1 3
1 5
4 5
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>816
</pre></section>
</div>
</span> |
p02980 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a square grid with <var>N</var> rows and <var>M</var> columns. Takahashi will write an integer in each of the squares, as follows:</p>
<ul>
<li>First, write <var>0</var> in every square.</li>
<li>For each <var>i=1,2,...,N</var>, choose an integer <var>k_i</var> <var>(0\leq k_i\leq M)</var>, and add <var>1</var> to each of the leftmost <var>k_i</var> squares in the <var>i</var>-th row.</li>
<li>For each <var>j=1,2,...,M</var>, choose an integer <var>l_j</var> <var>(0\leq l_j\leq N)</var>, and add <var>1</var> to each of the topmost <var>l_j</var> squares in the <var>j</var>-th column.</li>
</ul>
<p>Now we have a grid where each square contains <var>0</var>, <var>1</var>, or <var>2</var>. Find the number of different grids that can be made this way, modulo <var>998244353</var>.
We consider two grids different when there exists a square with different integers.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 5\times 10^5</var></li>
<li><var>N</var> and <var>M</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different grids that can be made, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>Let <var>(a,b)</var> denote the grid where the square to the left contains <var>a</var> and the square to the right contains <var>b</var>. Eight grids can be made: <var>(0,0),(0,1),(1,0),(1,1),(1,2),(2,0),(2,1),</var> and <var>(2,2)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>234
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>995651918
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>314159 265358
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>70273732
</pre></section>
</div>
</span> |
p03368 | <span class="lang-en">
<p>Score : <var>1700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a rooted tree with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>.
Vertex <var>1</var> is the root of the tree, and the parent of Vertex <var>i</var> ( <var>2\leq i \leq N</var> ) is Vertex <var>P_i</var> ( <var>P_i < i</var> ).
There is a number, <var>0</var> or <var>1</var>, written on each vertex. The number written on Vertex <var>i</var> is <var>V_i</var>.</p>
<p>Snuke would like to arrange the vertices of this tree in a horizontal row.
Here, for every vertex, there should be no ancestor of that vertex to the right of that vertex.</p>
<p>After arranging the vertices, let <var>X</var> be the sequence obtained by reading the numbers written on the vertices from left to right in the arrangement.
Snuke would like to minimize the inversion number of <var>X</var>.
Find the minimum possible inversion number of <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>The <em>inversion number</em> of a sequence <var>Z</var> whose length <var>N</var> is the number of pairs of integers <var>i</var> and <var>j</var> ( <var>1 \leq i < j \leq N</var> ) such that <var>Z_i > Z_j</var>.</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 P_i < i</var> ( <var>2 \leq i \leq N</var> )</li>
<li><var>0 \leq V_i \leq 1</var> ( <var>1 \leq i \leq N</var> )</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>P_2</var> <var>P_3</var> <var>...</var> <var>P_N</var>
<var>V_1</var> <var>V_2</var> <var>...</var> <var>V_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible inversion number of <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 1 2 3 3
0 1 1 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>When the vertices are arranged in the order <var>1, 3, 5, 6, 2, 4</var>, <var>X</var> will be <var>(0, 1, 0, 0, 1, 0)</var>, whose inversion number is <var>4</var>.
It is impossible to have fewer inversions, so the answer is <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p><var>X = (0)</var>, whose inversion number is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15
1 2 3 2 5 6 2 2 9 10 1 12 13 12
1 1 1 0 1 1 0 0 1 0 0 1 1 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>31
</pre></section>
</div>
</span> |
p01355 |
<H1>Problem G: Nurie</H1>
<p>
紙の上に円が<i>n</i> 個書かれている. うさぎは<i>k</i> 色の絵の具を持っていて, 次のルールに従って紙に色を塗っていく.
</p>
<ul>
<li> 各領域をある1 色の絵の具で塗るか, 何も塗らない. ここで「領域」とは, 円弧の集合で囲まれた面積有限の部分を指す.</li>
<li> 隣り合っている2 つの領域を同じ色の絵の具で塗ることはできない. ここで「隣り合っている」とは,境界の一部を共有する円弧があることを指す. 共有点が有限個である2 つの領域は, 隣り合っているとはみなされない.
</li>
<li> 隣り合っている2 つの領域の両方を塗らないままにすることは許される.</li>
</ul>
<p>
うさぎはできるだけ多くの領域を絵の具で塗りたい. 塗れる領域の個数の最大値を求めよ.
</p>
<H2>Input</H2>
<p>
1 行目: <i>n k</i> (1 ≤ <i>n</i> ≤ 20, 1 ≤ <i>k</i> ≤ 1 000 000 000)<br>
2-(<i>n</i> + 1) 行目: <i>x<sub>i</sub> y<sub>i</sub> r<sub>i</sub></i>, (−1 000 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 1 000, 1 ≤ <i>r<sub>i</sub></i> ≤ 1 000) (整数)
</p>
<p>
どの2 つの円も一致しない.
</p>
<p>
いずれか2 円の交点として得られる点集合は, 距離が10<sup>−3</sup> 以下の異なる2 点を含まない.
</p>
<H2>Output</H2>
<p>
絵の具で塗れる領域の個数の最大値を一行に出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
2 1
10 0 10
20 0 10
</pre>
<H2>Sample Output 1</H2>
<pre>
2
</pre>
|
p01640 |
<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 G: Get Lost</h1>
<p class="ndoc-top">ICPC World Finals 5日目</p>
<p class="ndoc-top">ティー氏はR国の街で迷ってしまった。
困ったことに、街並みが似ているため、自分が今どこにいるかが全く分からない。
R国は「おそろしあ」であるから、敵に襲撃される前にホテルへ戻らねばならない。 幸い、どのように曲がって来たかだけは覚えているので、
行き当たりばったりに進んでみよう。</p>
<h2 class="ndoc-heading2">問題</h2>
<p class="ndoc-top">\( w \times h \)マスの二次元格子状のマップがある。 左上のマスの座標を\(
(1, 1) \)、右下のマスの座標を\( (w, h) \)とする。 マップの周りは壁で囲まれており、
\(n\)個の障害物が座標\( (x_{i}, y_{i}) (1 \leq i \leq n) \)に置かれている。
さらに、命令列\( r_{1}r_{2} \cdots r_{m} \)と目的座標\( (g_{x}, g_{y})
\)が与えられる。 開始座標と進行方向の設定後、歩行者は以下の移動規則に従って歩行を開始する。</p>
<p class="ndoc-top">1. カウンタを\( i=1
\)に初期化し、開始座標と進行方向(上・下・左・右)を設定する。<br/>
2. 壁・障害物に出会うまで直進する。<br/>
3. 壁・障害物の手前で次のいずれかを実行する。<br/>
3. a. \( i>m \)、すなわち命令が無ければ歩行を終了する。<br/>
3. b. 命令\( r_{i} \)がLならば左、Rならば右へ方向転換する。<br/>
4. \( i \)をインクリメントする。<br/>
5. 2.に戻る。</p>
<p class="ndoc-top">歩行開始から歩行終了までに通過した座標(開始座標を含む)に目的座標\( (g_{x},
g_{y}) \)が含まれれば、歩行者が目的地に辿り着いたと解釈する。
目的地に辿り着くことのできる開始座標・進行方向の組み合わせは何通りあるかを求めよ。
ただし、開始座標には障害物やマップ外の座標を設定することはできないとする。 (目的座標を設定することはできる。)</p>
<h2 class="ndoc-heading2">入力</h2>
<pre>
w h g<sub>x</sub> g<sub>y</sub> n
x<sub>1</sub> y<sub>1</sub>
…
x<sub>n</sub> y<sub>n</sub>
r<sub>1</sub>r<sub>2</sub> … r<sub>m</sub>
</pre>
<p>1行目に マップの横幅\(w\)、縦幅\(h\)、目的地のx座標\( g_{x} \)、目的地のy座標\( g_{y}
\)、障害物の数\(n\)が空白区切りで与えられる。 2行目から\( n+1 \)行目に 各障害物の座標\( (x_{i},
y_{i}) \)が空白区切りで与えられる。 \( n+2 \)行目に長さ\(m\)の命令列\( r_{1}r_{2} \cdots
r_{m} \)が与えられる。</p>
<h2 class="ndoc-heading2">出力</h2>
<p class="ndoc-top">目的地に辿り着けるような 開始座標・進行方向の組み合わせの数を1行に出力せよ。</p>
<h2 class="ndoc-heading2">制約</h2>
<ul class="ndoc-indent">
<li>入力は全て整数である</li>
<li>\( 2 \leq w, h \leq 10^{5}(= 100000) \)</li>
<li>\( 0 \leq n \leq 10^{5}(= 100000) \)</li>
<li>\( 1 \leq g_{x}, x_{i} \leq w \)</li>
<li>\( 1 \leq g_{y}, y_{i} \leq h \)</li>
<li>\( (x_{i}, y_{i}) \not = (g_{x}, g_{y}) (1 \leq i \leq n)
\)</li>
<li>\( (x_{i}, y_{i}) \not = (x_{j}, y_{j}) (i \not = j) \)</li>
<li>\( r_{i} \in \{ L, R \} (1 \leq i \leq m) \)</li>
<li>\( 1 \leq m \leq 20 \)</li>
</ul>
<h2 class="ndoc-heading2">入出力例</h2>
<h3 class="ndoc-heading3">入力1</h3>
<pre>
3 3 3 2 2
1 1
2 2
RL
</pre>
<h3 class="ndoc-heading3">出力1</h3>
<pre>
9
</pre>
<p>以下の5通りの歩行に加え、 目的座標を開始座標とする歩行(4通り)が目的座標を通過する。</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_lost_sample_1" alt="http://k-operafan.info/static/uecpc2013/files/lost_sample_1.png" width="600">
<h3 class="ndoc-heading3">入力2</h3>
<pre>
4 4 3 1 4
1 1
3 2
1 3
4 3
RR
</pre>
<h3 class="ndoc-heading3">出力2</h3>
<pre>
13
</pre>
<p>以下の開始座標・進行方向から開始する歩行は目的座標を通過する。</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_lost_sample_2" alt="http://k-operafan.info/static/uecpc2013/files/lost_sample_2.png" width="300">
<h3 class="ndoc-heading3">入力3</h3>
<pre>
100000 100000 46597 49716 17
38713 77141
46598 78075
66177 49715
58569 77142
48303 12742
32829 65105
32830 78076
70273 27408
48302 21196
27119 54458
38714 65104
46598 54457
27118 12743
60242 21197
60241 1101
58568 27409
93581 1100
LLRRLLLLRRLL
</pre>
<h3 class="ndoc-heading3">出力3</h3>
<pre>
647505
</pre> |
p00952 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem G
Placing Medals on a Binary Tree
</h2>
<p>
You have drawn a chart of a perfect binary tree, like one shown in Figure G.1. The figure shows a finite tree, but, if needed, you can add more nodes beneath the leaves, making the tree arbitrarily deeper.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2016_Figure_G1"><br/>
Figure G.1. A Perfect Binary Tree Chart<br/>
</center><br/>
<p>
Tree nodes are associated with their depths, defined recursively. The root has the depth of zero, and the child nodes of a node of depth d have their depths $d + 1$.
</p>
<p>You also have a pile of a certain number of medals, each engraved with some number. You want to know whether the medals can be placed on the tree chart satisfying the following conditions.
</p>
<ul>
<li> A medal engraved with $d$ should be on a node of depth $d$.</li>
<li> One tree node can accommodate at most one medal.</li>
<li> The path to the root from a node with a medal should not pass through another node with a medal.</li>
</ul>
<p>
You have to place medals satisfying the above conditions, one by one, starting from the top of the pile down to its bottom. If there exists no placement of a medal satisfying the conditions, you have to throw it away and simply proceed to the next medal.
</p>
<p>
You may have choices to place medals on different nodes. You want to find the best placement. When there are two or more placements satisfying the rule, one that places a medal upper in the pile is better. For example, when there are two placements of four medal, one that places only the top and the 2nd medal, and the other that places the top, the 3rd, and the 4th medal, the former is better.
</p>
<p>
In Sample Input 1, you have a pile of six medals engraved with 2, 3, 1, 1, 4, and 2 again respectively, from top to bottom.
</p>
<ul>
<li> The first medal engraved with 2 can be placed, as shown in Figure G.2 (A).</li>
<li> Then the second medal engraved with 3 may be placed , as shown in Figure G.2 (B).</li>
<li> The third medal engraved with 1 cannot be placed if the second medal were placed as stated above, because both of the two nodes of depth 1 are along the path to the root from nodes already with a medal. Replacing the second medal satisfying the placement conditions, however, enables a placement shown in Figure G.2 (C).</li>
<li> The fourth medal, again engraved with 1, cannot be placed with any replacements of the three medals already placed satisfying the conditions. This medal is thus thrown away.</li>
<li> The fifth medal engraved with 4 can be placed as shown in of Figure G.2 (D). </li>
<li> The last medal engraved with 2 cannot be placed on any of the nodes with whatever replacements.</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2016_Figure_G2"><br/>
Figure G.2. Medal Placements<br/>
</center><br/>
<h3>Input</h3>
<p>
The input consists of a single test case in the format below.<br/>
<br/>
$n$ <br/>
$x_1$ <br/>
. <br/>
. <br/>
. <br/>
$x_n$ <br/>
</p>
<p>
The first line has $n$, an integer representing the number of medals ($1 \leq n \leq 5 \times 10^5$). The following $n$ lines represent the positive integers engraved on the medals. The $i$-th line of which has an integer $x_i$ ($1 \leq x_i \leq 10^9$) engraved on the $i$-th medal of the pile from the top.
</p>
<h3>Output</h3>
<p>
When the best placement is chosen, for each i from 1 through n, output <span>Yes</span> in a line if the i-th medal is placed; otherwise, output <span>No</span> in a line.
</p>
<h3>Sample Input 1</h3>
<pre>6
2
3
1
1
4
2
</pre>
<h3>Sample Output 1</h3>
<pre>Yes
Yes
Yes
No
Yes
No</pre>
<br/>
<h3>Sample Input 2</h3>
<pre>10
4
4
4
4
4
4
4
4
1
4
</pre>
<h3>Sample Output 2</h3>
<pre>Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No</pre>
|
p03387 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three integers <var>A</var>, <var>B</var> and <var>C</var>. Find the minimum number of operations required to make <var>A</var>, <var>B</var> and <var>C</var> all equal by repeatedly performing the following two kinds of operations in any order:</p>
<ul>
<li>Choose two among <var>A</var>, <var>B</var> and <var>C</var>, then increase both by <var>1</var>.</li>
<li>Choose one among <var>A</var>, <var>B</var> and <var>C</var>, then increase it by <var>2</var>.</li>
</ul>
<p>It can be proved that we can always make <var>A</var>, <var>B</var> and <var>C</var> all equal by repeatedly performing these operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A,B,C \leq 50</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>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to make <var>A</var>, <var>B</var> and <var>C</var> all equal.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can make <var>A</var>, <var>B</var> and <var>C</var> all equal by the following operations:</p>
<ul>
<li>Increase <var>A</var> and <var>C</var> by <var>1</var>. Now, <var>A</var>, <var>B</var>, <var>C</var> are <var>3</var>, <var>5</var>, <var>5</var>, respectively.</li>
<li>Increase <var>A</var> by <var>2</var>. Now, <var>A</var>, <var>B</var>, <var>C</var> are <var>5</var>, <var>5</var>, <var>5</var>, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 6 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31 41 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>23
</pre></section>
</div>
</span> |
p01210 |
<H1><font color="#000">Problem D:</font> Speed</H1>
<p>
Do you know <i>Speed</i>? It is one of popular card games, in which two players compete how quick
they can move their cards to tables.
</p>
<p>
To play <i>Speed</i>, two players sit face-to-face first. Each player has a deck and a tableau assigned
for him, and between them are two tables to make a pile on, one in left and one in right. A
tableau can afford up to only four cards.
</p>
<p>
There are some simple rules to carry on the game:
</p>
<ol>
<li> A player is allowed to move a card from his own tableau onto a pile, only when the rank
of the moved card is a neighbor of that of the card on top of the pile. For example A and
2, 4 and 3 are neighbors. A and K are also neighbors in this game.</li>
<li> He is also allowed to draw a card from the deck and put it on a vacant area of the tableau.</li>
<li> If both players attempt to move cards on the same table at the same time, only the faster
player can put a card on the table. The other player cannot move his card to the pile (as
it is no longer a neighbor of the top card), and has to bring it back to his tableau.</li>
</ol>
<p>
First each player draws four cards from his deck, and places them face on top on the tableau.
In case he does not have enough cards to fill out the tableau, simply draw as many as possible.
The game starts by drawing one more card from the deck and placing it on the tables on their
right simultaneously. If the deck is already empty, he can move an arbitrary card on his tableau
to the table.
</p>
<p>
Then they continue performing their actions according to the rule described above until both
of them come to a deadend, that is, have no way to move cards. Every time a deadend occurs,
they start over from each drawing a card (or taking a card from his or her tableau) and placing
on his or her right table, regardless of its face. The player who has run out of his card first is
the winner of the game.
</p>
<p>
Mr. James A. Games is so addicted in this simple game, and decided to develop robots that
plays it. He has just completed designing the robots and their program, but is not sure if they
work well, as the design is so complicated. So he asked you, a friend of his, to write a program
that simulates the robots.
</p>
<p>
The algorithm for the robots is designed as follows:
</p>
<ul>
<li>
A robot draws cards in the order they are dealt.
<ul>
<li> Each robot is always given one or more cards.</li>
<li> In the real game of <i>Speed</i>, the players first classify cards by their colors to enable
them to easily figure out which player put the card. But this step is skipped in this
simulation.</li>
<li> The game uses only one card set split into two. In other words, there appears at most
one card with the same face in the two decks given to the robots.</li>
</ul>
</li>
<li>
As a preparation, each robot draws four cards, and puts them to the tableau from right
to left.
<ul>
<li> If there are not enough cards in its deck, draw all cards in the deck.</li>
</ul>
</li>
<li>
After this step has been completed on both robots, they synchronize to each other and
start the game by putting the first cards onto the tables in the same moment.
<ul>
<li> If there remains one or more cards in the deck, a robot draws the top one and puts it
onto the right table. Otherwise, the robot takes the rightmost card from its tableau.</li>
</ul>
</li>
<li>
Then two robots continue moving according to the basic rule of the game described above,
until neither of them can move cards anymore.
<ul>
<li> When a robot took a card from its tableau, it draws a card (if possible) from the deck
to fill the vacant position after the card taken is put onto a table.</li>
<li> It takes some amount of time to move cards. When a robot completes putting a card
onto a table while another robot is moving to put a card onto the same table, the
robot in motion has to give up the action immediately and returns the card to its
original position.</li>
<li> A robot can start moving to put a card on a pile at the same time when the neighbor
is placed on the top of the pile.</li>
<li> If two robots try to put cards onto the same table at the same moment, only the
robot moving a card to the left can successfully put the card, due to the position
settings.</li>
<li> When a robot has multiple candidates in its tableau, it prefers the cards which can
be placed on the right table to those which cannot. In case there still remain multiple
choices, the robot prefers the weaker card.</li>
</ul>
</li>
<li>
When it comes to a deadend situation, the robots start over from each putting a card to
the table, then continue moving again according to the algorithm above.
</li>
<li>
When one of the robots has run out the cards, i.e., moved all dealt cards, the game ends.
<ul>
<li> The robot which has run out the cards wins the game.</li>
<li> When both robots run out the cards at the same moment, the robot which moved
the stronger card in the last move wins.</li>
</ul>
</li>
</ul>
<p>
The strength among the cards is determined by their ranks, then by the suits. The ranks are
strong in the following order: A > K > Q > J > X (10) > 9 > . . . > 3 > 2. The suits are strong
in the following order: S (Spades) > H (Hearts) > D (Diamonds) > C (Cloves). In other words,
SA is the strongest and C2 is the weakest.
</p>
<p>
The robots require the following amount of time to complete each action:
</p>
<ul>
<li> 300 milliseconds to draw a card to the tableau,</li>
<li> 500 milliseconds to move a card to the right table,</li>
<li> 700 milliseconds to move a card to the left table, and</li>
<li> 500 milliseconds to return a card to its original position.</li>
</ul>
<p>
Cancelling an action always takes the constant time of 500ms, regardless of the progress of
the action being cancelled. This time is counted from the exact moment when the action is
interrupted, not the beginning time of the action.
</p>
<p>
You may assume that these robots are well-synchronized, i.e., there is no clock skew between
them.
</p>
<p>
For example, suppose Robot A is given the deck “S3 S5 S8 S9 S2” and Robot B is given the deck
“H7 H3 H4”, then the playing will be like the description below. Note that, in the description,
“the table A” (resp. “the table B”) denotes the right table for Robot A (resp. Robot B).
</p>
<ul>
<li> Robot A draws four cards S3, S5, S8, and S9 to its tableau from right to left. Robot B
draws all the three cards H7, H3, and H4.</li>
<li> Then the two robots synchronize for the game start. Let this moment be 0ms.</li>
<li> At the same moment, Robot A starts moving S2 to the table A from the deck, and Robot
B starts moving H7 to the table B from the tableau.</li>
<li> At 500ms, the both robots complete their moving cards. Then Robot A starts moving S3
to the table A 1(which requires 500ms), and Robot B starts moving H3 also to the table
A (which requires 700ms).</li>
<li> At 1000ms, Robot A completes putting S3 on the table A. Robot B is interrupted its move
and starts returning H3 to the tableau (which requires 500ms). At the same time Robot
A starts moving S8 to the table B (which requires 700ms).</li>
<li> At 1500ms, Robot B completes returning H3 and starts moving H4 to the table A (which
requires 700ms).</li>
<li> At 1700ms, Robot A completes putting S8 and starts moving S9 to the table B.</li>
<li> At 2200ms, Robot B completes putting H4 and starts moving H3 to the table A.</li>
<li> At 2400ms, Robot A completes putting S9 and starts moving S5 to the table A.</li>
<li> At 2900ms, The both robots are to complete putting the cards on the table A. Since Robot
B is moving the card to the table left to it, Robot B completes putting H3. Robot A is
interrupted.</li>
<li> Now Robot B has finished moving all the dealt cards, so Robot B wins this game.</li>
</ul>
<H2>Input</H2>
<p>
The input consists of multiple data sets, each of which is described by four lines. The first line
of each data set contains an integer <i>N<sub>A</sub></i> , which specifies the number of cards to be dealt as a
deck to Robot A. The next line contains a card sequences of length <i>N<sub>A</sub></i> . Then the number <i>N<sub>B</sub></i>
and card sequences of length <i>N<sub>B</sub></i> for Robot <i>B</i> follows, specified in the same manner.
</p>
<p>
In a card sequence, card specifications are separated with one space character between them.
Each card specification is a string of 2 characters. The first character is one of ‘S’ (spades), ‘H’
(hearts), ‘D’ (diamonds) or ‘C’ (cloves) and specifies the suit. The second is one of ‘A’, ‘K’, ‘Q’,
‘J’, ‘X’ (for 10) or a digit between ‘9’ and ‘2’, and specifies the rank. As this game is played with
only one card set, there is no more than one card of the same face in each data set.
</p>
<p>
The end of the input is indicated by a single line containing a zero.
</p>
<H2>Output</H2>
<p>
For each data set, output the result of a game in one line. Output “A wins.” if Robot A wins,
or output “B wins.” if Robot B wins. No extra characters are allowed in the output.
</p>
<H2>Sample Input</H2>
<pre>
1
SA
1
C2
2
SA HA
2
C2 C3
5
S3 S5 S8 S9 S2
3
H7 H3 H4
10
H7 CJ C5 CA C6 S2 D8 DA S6 HK
10
C2 D6 D4 H5 DJ CX S8 S9 D3 D5
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
A wins.
B wins.
B wins.
A wins.
</pre>
|
p04012 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>w</var> be a string consisting of lowercase letters.
We will call <var>w</var> <em>beautiful</em> if the following condition is satisfied:</p>
<ul>
<li>Each lowercase letter of the English alphabet occurs even number of times in <var>w</var>.</li>
</ul>
<p>You are given the string <var>w</var>. Determine if <var>w</var> is beautiful.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |w| \leq 100</var></li>
<li><var>w</var> consists of lowercase letters (<code>a</code>-<code>z</code>).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>w</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Yes</code> if <var>w</var> is beautiful. Print <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abaccaba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><code>a</code> occurs four times, <code>b</code> occurs twice, <code>c</code> occurs twice and the other letters occur zero times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>hthth
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre></section>
</div>
</span> |
p00051 |
<H1>整数の差</H1>
<p>
8 個の 0 から 9 までの数字を入力したとき、その 8 個の数字を並べ替えてできる、最大の整数と最小の整数の差を出力するプログラムを作成してください。並び替えてできる数は 00135569 のように 0 から始まってもよいものとします。
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。1行目にデータセット数 <var>n</var> (<var>n</var> ≤ 50) が与えられます。続いて <var>n</var> 行のデータが与えられます。各データは 8 個の数字の並び(0 から 9 の数字)です。
</p>
<H2>Output</H2>
<p>
各データセットに対して、入力された数字を並べ替えてできる最大の整数と最小の整数の差を1行に出力して下さい。
</p>
<H2>Sample Input</H2>
<pre>
2
65539010
65539010
</pre>
<H2>Output for the Sample Input</H2>
<pre>
96417531
96417531
</pre>
|
p02596 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi loves the number <var>7</var> and multiples of <var>K</var>.</p>
<p>Where is the first occurrence of a multiple of <var>K</var> in the sequence <var>7,77,777,\ldots</var>? (Also see Output and Sample Input/Output below.)</p>
<p>If the sequence contains no multiples of <var>K</var>, print <code>-1</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq 10^6</var></li>
<li><var>K</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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the position of the first occurrence of a multiple of <var>K</var>. (For example, if the first occurrence is the fourth element of the sequence, print <code>4</code>.)</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>None of <var>7</var>, <var>77</var>, and <var>777</var> is a multiple of <var>101</var>, but <var>7777</var> is.</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>-1
</pre>
<p>All elements in the sequence are odd numbers; there are no multiples of <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>999983
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>999982
</pre></section>
</div>
</span> |
p00401 | <h1>2の累乗</h1>
<p>
与えられた数を、それ以下の数の中で最大の$2$の累乗に変換してください。たとえば、$2$や$3$ならば$2^1=2$に変換してください。同様に$4$,$5$,$6$,$7$ならば$2^2=4$に、$8$,$9$,$10$,$11$,...,$15$ならば$2^3=8$に変換してください。
</p>
<p>
与えられた数を、その数以下の数の中で最大の$2$の累乗に変換するプログラムを作成せよ。
</p>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
$N$
</pre>
<p>
1行に数$N$ ($2 \leq N \leq 10^6$)が与えられる。
</p>
<h2>出力</h2>
<p>
変換した数を1行に出力する。
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
54
</pre>
<h3>出力例1</h3>
<pre>
32
</pre>
<h3>入力例2</h3>
<pre>
1024
</pre>
<h3>出力例2</h3>
<pre>
1024
</pre>
|
p01139 |
<!-- begin en only -->
<h3><U>Surrounding Area</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>
ある 2 人の不動産屋が,客船に乗って南の島に向かっていた.青い空,さわやかな風….2 人は他の乗客とともに船旅を楽しんでいた.ところが,ある日突然発生した竜巻によって客船が沈んでしまった.他の乗客は救助隊によって救助されたが,どういうわけかこの 2 人だけ見落とされてしまった.数日の漂流の後,彼らはある無人島に流れ着いた.この無人島は長方形であり,以下の図のように格子に区切られていた.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_mujin" alt="無人島の形状"><br>
図 C-1: 無人島の形状
</center>
<p>
彼らはとても欲深かったので,助けを呼ぶことではなく,この無人島の土地を売ることを考えていた.そして,彼らは土地を折半するということはせず,土地の奪い合いを始めた.彼らはそれぞれ自分の土地にしたいところを,一方は黒い杭で,もう一方は白い杭で囲み始めた.全ての杭は格子の中央に打たれ,また 1 つの格子に複数の杭が打たれることはなかった.しばらくすると双方とも疲れ果てて,杭を打つことを止めた.
</p>
<p>
あなたの仕事は,黒い杭および白い杭で囲まれた土地の面積を求めるプログラムを書くことである.ただし,格子 (<i>i</i>, <i>j</i>) が黒い杭に囲まれているとは,直感的には「格子 (<i>i</i>, <i>j</i>) から上下左右に任意に移動したとき,最初に当たる杭は常に黒い杭である」ことを意味する.正確には以下のように定義される.
</p>
<blockquote>
<p>
黒い杭に「拡大隣接した」格子を次のとおりに定める.白い杭についても同様とする.
</p>
<ul>
<li><p>格子 (<i>i</i>, <i>j</i>) に杭が存在せず,さらに格子 (<i>i</i>, <i>j</i>) に隣接する格子のいずれかに黒い杭が存在するならば,格子 (<i>i</i>, <i>j</i>) は黒い杭に拡大隣接している.</p></li>
<li><p>格子 (<i>i</i>, <i>j</i>) に杭が存在せず,さらに格子 (<i>i</i>, <i>j</i>) に隣接する格子のいずれかが黒い杭に拡大隣接しているならば,格子 (<i>i</i>, <i>j</i>) は黒い杭に拡大隣接している.このルールは再帰的に適用される.</p></li>
</ul>
</li>
<p>
このとき,格子 (<i>i</i>, <i>j</i>) が黒い杭に拡大隣接していて,さらに白い杭に隣接していないとき,またそのときに限って,格子 (<i>i</i>, <i>j</i>) が黒い杭に囲まれているという.また逆に,格子 (<i>i</i>, <i>j</i>) が白い杭に拡大隣接していて,さらに黒い杭に隣接していないとき,またそのときに限って,格子 (<i>i</i>, <i>j</i>) が白い杭に囲まれているという.
</p>
</blockquote>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
入力は複数のデータセットから構成される.各データセットは以下のような構成になっている.
</p>
<blockquote>
<i>w</i> <i>h</i><br>
<i>a</i><sub>1,1</sub> <i>a</i><sub>2,1</sub> <i>a</i><sub>3,1</sub> ... <i>a</i><sub><i>w</i>,1</sub><br>
<i>a</i><sub>1,2</sub> <i>a</i><sub>2,2</sub> <i>a</i><sub>3,2</sub> ... <i>a</i><sub><i>w</i>,2</sub><br>
...<br>
<i>a</i><sub>1,<i>h</i></sub> <i>a</i><sub>2,<i>h</i></sub> <i>a</i><sub>3,<i>h</i></sub> ... <i>a</i><sub><i>w</i>,<i>h</i></sub>
</blockquote>
<p>
<i>w</i> は土地の横幅,<i>h</i> は土地の縦幅を表す.これらは 1 ≦ <i>w</i>,<i>h</i> ≦ 50 を満たす.各 <i>a</i><sub><i>i</i>,<i>j</i></sub> は格子 (<i>i</i>, <i>j</i>) の状態を表す 1 つの半角文字であり,「<code>B</code>」は黒い杭が打たれていることを,「<code>W</code>」は白い杭が打たれていることを,「<code>.</code>」(ピリオド)はいずれの杭も打たれていないことをそれぞれ示す.
</p>
<p>
<i>w</i> = <i>h</i> = 0 は入力の終端を表しており,データセットには含まれない.</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
各データセットについて,黒い杭が囲んだ土地の大きさ,および白い杭が囲んだ土地の大きさを 1 つの空白で区切って 1 行に出力しなさい.
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
10 10
.....W....
....W.W...
...W...W..
....W...W.
.....W...W
......W.W.
BBB....W..
..B..BBBBB
..B..B....
..B..B..W.
5 3
...B.
...BB
.....
1 1
.
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
6 21
12 0
0 0
</pre>
|
p03104 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>f(A, B)</var> be the exclusive OR of <var>A, A+1, ..., B</var>. Find <var>f(A, B)</var>.</p>
<p><details>
<summary style="display: list-item; outline: none;">What is exclusive OR?</summary></details></p>
<p>The bitwise exclusive OR of integers <var>c_1, c_2, ..., c_n</var> (let us call it <var>y</var>) is defined as follows:</p>
<ul>
<li>When <var>y</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if, the number of integers among <var>c_1, c_2, ...c_m</var> whose binary representations have <var>1</var> in the <var>2^k</var>'s place, is odd, and <var>0</var> if that count is even.</li>
</ul>
<p>For example, the exclusive OR of <var>3</var> and <var>5</var> is <var>6</var>. (When written in base two: the exclusive OR of <code>011</code> and <code>101</code> is <code>110</code>.)</p>
<p></p></section></div></span> |
p01569 |
<h1>Sun and Moon</h1>
<p>In the year 20XX, mankind is hit by an unprecedented crisis.
The power balance between the sun and the moon was broken by the total eclipse of the sun, and the end is looming!
To save the world, the secret society called "Sun and Moon" decided to perform the ritual to balance the power of the sun and the moon called "Ritual of Sun and Moon".
</p>
<p>The ritual consists of "Ritual of Sun" and "Ritual of Moon". "Ritual of Moon" is performed after "Ritual of Sun".
A member of the society is divided into two groups, "Messengers of Sun" and "Messengers of Moon".
Each member has some offerings and magic power.
</p>
<p>First, the society performs "Ritual of Sun".
In the ritual, each member sacrifices an offering.
If he can not sacrifice an offering here, he will be killed.
After the sacrifice, his magic power is multiplied by the original number of his offerings.
Each member must perform the sacrifice just once.
</p>
<p>Second, the society performs "Ritual of Moon".
In the ritual, each member sacrifices all remaining offerings.
After the sacrifice, his magic power is multiplied by <var>x<sup>p</sup></var>.
Here <var>x</var> is the number of days from the eclipse (the eclipse is 0th day) and <var>p</var> is the number of his sacrificed offerings.
Each member must perform the sacrifice just once.
</p>
<p>After two rituals, all "Messengers of Sun" and "Messengers of Moon" give all magic power to the "magical reactor".
If the total power of "Messengers of Sun" and the total power of "Messengers of Moon" are equal,
the society will succeed in the ritual and save the world.
</p>
<p>It is very expensive to perform "Ritual of Sun".
It may not be able to perform "Ritual of Sun" because the society is in financial trouble.
Please write a program to calculate the minimum number of days from the eclipse in which the society can succeed in "Ritual of Sun and Moon" whether "Ritual of Sun" can be performed or not.
The society cannot perform the ritual on the eclipse day (0-th day).
</p>
<h2>Input</h2>
<p>The format of the input is as follows.
</p>
<blockquote>
<var>N</var><br><var>O<sub>1</sub></var> <var>P<sub>1</sub></var><br><var>...</var><br><var>O<sub>N</sub></var> <var>P<sub>N</sub></var><br></blockquote>
<p>The first line contains an integer <var>N</var> that is the number of members of the society (<var>0 ≤ N ≤ 1,000</var>).
</p>
<p>Each of the following <var>N</var> lines contains two integers <var>O<sub>i</sub></var> (<var>0 ≤ O<sub>i</sub> ≤ 1,000,000,000</var>) and <var>P<sub>i</sub></var> (<var>1 ≤ |P<sub>i</sub>| ≤ 1,000,000,000,000,000</var>).
<var>O<sub>i</sub></var> is the number of the <var>i</var>-th member's offerings and <var>|P<sub>i</sub>|</var> is the strength of his magic power.
If <var>P<sub>i</sub></var> is a positive integer, the <var>i</var>-th member belongs to "Messengers of Sun", otherwise he belongs to "Messengers of Moon".
</p>
<h2>Output</h2>
<p>If there exists the number of days from the eclipse that satisfies the above condition , print the minimum number of days preceded by "Yes ".
Otherwise print "No".
</p>
<p>Of course, the answer must be a positive integer.
</p>
<h2>Sample Input 1</h2>
<pre>9
2 1
1 -1
1 -1
1 -1
1 -1
0 1
0 1
0 1
0 1
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>Yes 2
</pre>
<h2>Sample Input 2</h2>
<pre>2
1 1
0 -1
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>No
</pre>
|
p03554 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence <var>a = \{a_1, ..., a_N\}</var> with all zeros, and a sequence <var>b = \{b_1, ..., b_N\}</var> consisting of <var>0</var> and <var>1</var>. The length of both is <var>N</var>.</p>
<p>You can perform <var>Q</var> kinds of operations. The <var>i</var>-th operation is as follows:</p>
<ul>
<li>Replace each of <var>a_{l_i}, a_{l_i + 1}, ..., a_{r_i}</var> with <var>1</var>.</li>
</ul>
<p>Minimize the hamming distance between <var>a</var> and <var>b</var>, that is, the number of <var>i</var> such that <var>a_i \neq b_i</var>, by performing some of the <var>Q</var> operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 200,000</var></li>
<li><var>b</var> consists of <var>0</var> and <var>1</var>.</li>
<li><var>1 \leq Q \leq 200,000</var></li>
<li><var>1 \leq l_i \leq r_i \leq N</var></li>
<li>If <var>i \neq j</var>, either <var>l_i \neq l_j</var> or <var>r_i \neq r_j</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>b_1</var> <var>b_2</var> <var>...</var> <var>b_N</var>
<var>Q</var>
<var>l_1</var> <var>r_1</var>
<var>l_2</var> <var>r_2</var>
<var>:</var>
<var>l_Q</var> <var>r_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible hamming distance.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 0 1
1
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>If you choose to perform the operation, <var>a</var> will become <var>\{1, 1, 1\}</var>, for a hamming distance of <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 0 1
2
1 1
3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If both operations are performed, <var>a</var> will become <var>\{1, 0, 1\}</var>, for a hamming distance of <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 0 1
2
1 1
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5
0 1 0 1 0
1
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>2
</pre>
<p>It may be optimal to perform no operation.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>9
0 1 0 1 1 1 0 1 0
3
1 4
5 8
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>15
1 1 0 0 0 0 0 0 1 0 1 1 1 0 0
9
4 10
13 14
1 7
4 14
9 11
2 6
7 8
3 12
7 13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 7</h3><pre>10
0 0 0 1 0 0 1 1 1 0
7
1 4
2 5
1 3
6 7
9 9
1 5
7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 7</h3><pre>1
</pre></section>
</div>
</span> |
p01093 |
<h3>Selection of Participants of an Experiment</h3>
<p>
Dr. Tsukuba has devised a new method of programming training.
In order to evaluate the effectiveness of this method,
he plans to carry out a control experiment.
Having two students as the participants of the experiment,
one of them will be trained under the conventional method
and the other under his new method.
Comparing the final scores of these two,
he will be able to judge the effectiveness of his method.
</p>
<p>
It is important to select two students having the closest possible scores,
for making the comparison fair.
He has a list of the scores of all students
who can participate in the experiment.
You are asked to write a program which selects two of them
having the smallest difference in their scores.
</p>
<h3>Input</h3>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<p>
<i>n</i><br>
<i>a</i><sub>1</sub> <i>a</i><sub>2</sub> … <i>a<sub>n</sub></i>
</p>
<p>
A dataset consists of two lines.
The number of students <i>n</i> is given in the first line.
<i>n</i> is an integer satisfying 2 ≤ <i>n</i> ≤ 1000.
The second line gives scores of <i>n</i> students.
<i>a<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) is the score of the <i>i</i>-th student, which is a non-negative integer not greater than 1,000,000.
</p>
<p>
The end of the input is indicated by a line containing a zero.
The sum of <i>n</i>'s of all the datasets does not exceed 50,000.
</p>
<h3>Output</h3>
<p>
For each dataset, select two students with the smallest difference in their scores,
and output in a line (the absolute value of) the difference.
</p>
<h3>Sample Input</h3>
<pre>
5
10 10 10 10 10
5
1 5 8 9 11
7
11 34 83 47 59 29 70
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
0
1
5
</pre>
|
p03807 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> integers written on a blackboard. The <var>i</var>-th integer is <var>A_i</var>.</p>
<p>Takahashi will repeatedly perform the following operation on these numbers:</p>
<ul>
<li>Select a pair of integers, <var>A_i</var> and <var>A_j</var>, that have the same parity (that is, both are even or both are odd) and erase them.</li>
<li>Then, write a new integer on the blackboard that is equal to the sum of those integers, <var>A_i+A_j</var>.</li>
</ul>
<p>Determine whether it is possible to have only one integer on the blackboard.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≦ N ≦ 10^5</var></li>
<li><var>1 ≦ A_i ≦ 10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> … <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to have only one integer on the blackboard, print <code>YES</code>. Otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>It is possible to have only one integer on the blackboard, as follows:</p>
<ul>
<li>Erase <var>1</var> and <var>3</var> from the blackboard, then write <var>4</var>. Now, there are two integers on the blackboard: <var>2</var> and <var>4</var>.</li>
<li>Erase <var>2</var> and <var>4</var> from the blackboard, then write <var>6</var>. Now, there is only one integer on the blackboard: <var>6</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p02715 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider sequences <var>\{A_1,...,A_N\}</var> of length <var>N</var> consisting of integers between <var>1</var> and <var>K</var> (inclusive).</p>
<p>There are <var>K^N</var> such sequences. Find the sum of <var>\gcd(A_1, ..., A_N)</var> over all of them.</p>
<p>Since this sum can be enormous, print the value modulo <var>(10^9+7)</var>.</p>
<p>Here <var>\gcd(A_1, ..., A_N)</var> denotes the greatest common divisor of <var>A_1, ..., A_N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq K \leq 10^5</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of <var>\gcd(A_1, ..., A_N)</var> over all <var>K^N</var> sequences, modulo <var>(10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p><var>\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)</var>
<var>+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)</var>
<var>=1+1+1+1+1+1+1+2=9</var></p>
<p>Thus, the answer is <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 200
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10813692
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>742202979
</pre>
<p>Be sure to print the sum modulo <var>(10^9+7)</var>.</p></section>
</div>
</span> |
p00728 |
<h1><font color="#000">Problem A:</font> ICPC Score Totalizer Software</h1>
<!-- end en only -->
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_a-1" width=300 align=left>
<!-- begin en only -->
<p>
The International Clown and Pierrot Competition (ICPC), is one of the
most distinguished and also the most popular events on earth in the
show business.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
One of the unique features of this contest is the great number of
judges that sometimes counts up to one hundred. The number of judges
may differ from one contestant to another, because judges with any
relationship whatsoever with a specific contestant are temporarily
excluded for scoring his/her performance.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Basically, scores given to a contestant's performance by the judges
are averaged to decide his/her score. To avoid letting judges with
eccentric viewpoints too much influence the score, the highest and the
lowest scores are set aside in this calculation. If the same highest
score is marked by two or more judges, only one of them is ignored.
The same is with the lowest score. The average, which may contain
fractions, are truncated down to obtain final score as an integer.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
You are asked to write a program that computes the scores of
performances, given the scores of all the judges, to speed up the event
to be suited for a TV program.
</p>
<!-- end en only -->
<h2>Input</h2>
<!-- begin en only -->
<p>
The input consists of a number of datasets, each corresponding to a
contestant's performance. There are no more than 20 datasets in the input.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A dataset begins with a line with an integer <i>n</i>, the number of
judges participated in scoring the performance (3 ≤ <i>n</i> ≤
100). Each of the <i>n</i> lines following it has an integral
score <i>s</i> (0 ≤ <i>s</i> ≤ 1000) marked by a judge. No
other characters except for digits to express these numbers are in the
input. Judges' names are kept secret.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line with a single zero in it.
</p>
<!-- end en only -->
<h2>Output</h2>
<!-- begin en only -->
<p>
For each dataset, a line containing a single decimal integer
indicating the score for the corresponding performance should be
output. No other characters should be on the output line.
</p>
<!-- end en only -->
<h2>Sample Input</h2>
<pre>
3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
342
7
300
326
</pre>
|
p02345 | <H1>Range Minimum Query (RMQ)</H1>
<p>
Write a program which manipulates a sequence <var>A</var> = {<var>a<sub>0</sub>, a<sub>1</sub>, . . . , a<sub>n-1</sub></var>} with the following operations:
</p>
<ul>
<li><var>find(s, t)</var>: report the minimum element in <var>a<sub>s</sub>, a<sub>s+1</sub>, . . . ,a<sub>t</sub></var>.</li>
<li><var>update(i, x)</var>: change <var>a<sub>i</sub></var> to <var>x</var>.</li>
</ul>
<p>
Note that the initial values of <var>a<sub>i</sub></var> (<var>i = 0, 1, . . . , n−1</var>) are 2<sup>31</sup>-1.
</p>
<H2>Input</H2>
<pre>
<var>n</var> <var>q</var>
<var>com<sub>0</sub></var> <var>x<sub>0</sub></var> <var>y<sub>0</sub></var>
<var>com<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
...
<var>com<sub>q−1</sub></var> <var>x<sub>q−1</sub></var> <var>y<sub>q−1</sub></var>
</pre>
<p>
In the first line, <var>n</var> (the number of elements in <var>A</var>) and <var>q</var> (the number of queries) are given. Then, <var>q</var> queries are given where <var>com</var> represents the type of queries. '0' denotes <var>update(x<sub>i</sub>, y<sub>i</sub>)</var> and '1' denotes <var>find(x<sub>i</sub>, y<sub>i</sub>)</var>.
</p>
<H2>Output</H2>
<p>
For each <var>find</var> operation, print the minimum element.
</p>
<H2>Constraints</H2>
<ul>
<li>
<var>1 ≤ n ≤ 100000</var>
</li>
<li>
<var>1 ≤ q ≤ 100000</var>
</li>
<li>
If <var>com<sub>i</sub></var> is 0, then <var>0 ≤ x<sub>i</sub> < n</var>, <var>0 ≤ y<sub>i</sub> < 2<sup>31</sup>-1</var>.
</li>
<li>
If <var>com<sub>i</sub></var> is 1, then <var>0 ≤ x<sub>i</sub> < n</var>, <var>0 ≤ y<sub>i</sub> < n</var>.
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2
</pre>
<H2>Sample Output 1</H2>
<pre>
1
2
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
1 3
1 0 0
0 0 5
1 0 0
</pre>
<H2>Sample Output 2</H2>
<pre>
2147483647
5
</pre>
|
p00378 | <h1>Heat Stroke</h1>
<p>
We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower.
</p>
<p>
Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$A$ $B$ $X$
</pre>
<p>
The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters.
</p>
<h2>Output</h2>
<p>
Output the total price.
</p>
<h2>Sample Input 1</h2>
<pre>
180 100 2400
</pre>
<h2>Sample Output 1</h2>
<pre>
460
</pre>
<h2>Sample Input 2</h2>
<pre>
200 90 2018
</pre>
<h2>Sample Output 2</h2>
<pre>
450
</pre>
|
p01990 | <h2>B: ピボット (Pivots)</h2>
<h3>問題</h3>
<p>
<var>1</var> から <var>N</var> までの整数を並び変えた、長さ <var>N</var> の順列 <var>a_1, a_2, ..., a_N</var> が与えられる。
また、この順列に対して <var>Q</var> 個のクエリが順に与えられる。<var>i</var> 番目のクエリでは次の操作をしなければならない。
</p>
<ul>
<li> 値 <var>q_i</var> (<var>1 \leq q_i \leq N</var>) が与えられる。順列 <var>\{a_1, a_2, ..., a_N\}</var> において <var>q_i</var> の左側の順列を <var>L</var>、<var>q_i</var> の右側の順列を <var>R</var> としたとき、元の順列 <var>L \ \ q_i \ \ R</var> を <var>R \ \ q_i \ \ L</var> に変更する。つまり、<var>q_{i} = a_j</var> であるとき、順列 <var>\{a_1, ..., a_{j-1}, a_j, a_{j+1}, ..., a_N\}</var> を <var>\{a_{j+1}, ..., a_N, a_j, a_1, ..., a_{j-1}\}</var> に変更する。</li>
</ul>
<p>なお、順列 <var>L</var>, <var>R</var> は空になることもあり得る。例えば <var>L</var> が空の時は、<var>q_i \ \ R</var> を <var>R \ \ q_i</var> に変更する。<var>R</var> が空のときについても同様である。</p>
<p>与えられた順列に対してこれら <var>Q</var> 個のクエリを順に処理した後の順列を一行に出力せよ。</p>
<h3>入力形式</h3>
<pre>
<var>N</var> <var>Q</var>
<var>a_1 a_2 ... a_N</var>
<var>q_1 q_2 ... q_Q</var>
</pre>
<p>入力は全て整数である。</p>
<p>
一行目には順列の要素数 <var>N</var> とクエリの回数 <var>Q</var> が空白区切りで与えられる。
二行目には <var>1</var> から <var>N</var> までの整数を並び変えた順列 <var>a_1, a_2, ..., a_N</var> が空白区切りで与えられる。
三行目にはクエリが <var>Q</var> 個、空白区切りで与えられる。<var>q_i</var> は <var>i</var> 番目のクエリを表す。
</p>
<h3>制約</h3>
<ul>
<li> <var>1 \leq N \leq 10^5</var></li>
<li> <var>1 \leq Q \leq 10^5</var></li>
<li> <var>1 \leq a_i \leq N</var></li>
<li> <var>a_i</var> は相異なる</li>
<li> <var>1 \leq q_i \leq N</var></li>
</ul>
<h3>出力形式</h3>
<p>クエリを順にすべて処理した後の順列を一行に出力せよ。</p>
<h3>入力例1</h3>
<pre>
5 2
1 5 3 2 4
5 2
</pre>
<h3>出力例1</h3>
<pre>4 5 1 2 3</pre>
<ul>
<li> 1番目のクエリにより、順列は <var>\{3, 2, 4, 5, 1\}</var> へ変わる。</li>
<li> 2番目のクエリにより、順列は <var>\{4, 5, 1, 2, 3\}</var> へ変わる。</li>
</ul>
<h3>入力例2</h3>
<pre>
5 1
1 2 3 4 5
5
</pre>
<h3>出力例2</h3>
<pre>5 1 2 3 4</pre>
|
p00682 |
<H1>Area of Polygons</H1>
<p>
Polygons are the most fundamental objects in geometric processing.
Complex figures are often represented and handled as polygons
with many short sides.
If you are interested in the processing of geometric data,
you'd better try some programming exercises about basic
operations on polygons.
</p>
<p>
Your job in this problem is to write a program that computes the area of polygons.
</p>
<p>
A polygon is represented by a sequence of points that are its vertices.
If the vertices p<SUB>1</SUB>, p<SUB>2</SUB>, ..., p<SUB>n</SUB> are given, line segments connecting
p<SUB>i</SUB> and p<SUB>i+1</SUB> (1 <= i <= n-1) are sides of the polygon.
The line segment connecting p<SUB>n</SUB> and p<SUB>1</SUB> is also a side of the polygon.
</p>
<p>
You can assume that the polygon is not degenerate.
Namely, the following facts can be assumed without any input data checking.
</p>
<UL>
<LI>No point will occur as a vertex more than once.</LI>
<LI>Two sides can intersect only at a common endpoint (vertex).</LI>
<LI>The polygon has at least 3 vertices.</LI>
</UL>
<p>
Note that the polygon is not necessarily convex.
In other words, an inner angle may be larger than 180 degrees.
</p>
<H2>Input</H2>
<P>The input contains multiple data sets, each representing a polygon.
A data set is given in the following format.</P>
<PRE>
n
x1 y1
x2 y2
...
xn yn
</PRE>
<P>The first integer n is the number of vertices,
such that 3 <= n <= 50.
The coordinate of a vertex p<SUB>i</SUB> is given by (x<SUB>i</SUB>, y<SUB>i</SUB>).
x<SUB>i</SUB> and y<SUB>i</SUB> are integers between 0 and 1000 inclusive.
The coordinates of vertices are given in the order
of clockwise visit of them.</P>
<P>The end of input is indicated by a data set with 0 as the value of n.</P>
<H2>Output</H2>
<P>For each data set, your program should output its sequence number
(1 for the first data set, 2 for the second, etc.) and the area of the polygon separated by a single space. The area should be printed with one digit to the right of the decimal point.</P>
<P>The sequence number and the area should be printed on the same line.
Since your result is checked by an automatic grading program,
you should not insert any extra characters nor lines on the output.
</P>
<H2>Sample Input</H2>
<pre>
3
1 1
3 4
6 0
7
0 0
10 10
0 20
10 30
0 40
100 40
100 0
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 8.5
2 3800.0
</pre>
|
p00397 | <h1>K-th Exclusive OR</h1>
<p>
Exclusive OR (XOR) is an operation on two binary numbers $x$ and $y$ (0 or 1) that produces 0 if $x = y$ and $1$ if $x \ne y$. This operation is represented by the symbol $\oplus$. From the definition: $0 \oplus 0 = 0$, $0 \oplus 1 = 1$, $1 \oplus 0 = 1$, $1 \oplus 1 = 0$.
</p>
<p>
Exclusive OR on two non-negative integers comprises the following procedures: binary representation of the two integers are XORed on bit by bit bases, and the resultant bit array constitute a new integer. This operation is also represented by the same symbol $\oplus$. For example, XOR of decimal numbers $3$ and $5$ is equivalent to binary operation $011 \oplus 101$ which results in $110$, or $6$ in decimal format.
</p>
<p>
Bitwise XOR operation on a sequence $Z$ consisting of $M$ non-negative integers $z_1, z_2, . . . , z_M$ is defined as follows:
</p>
<ul>
<li> $v_0 = 0, v_i = v_{i - 1} \oplus z_i$ ($1 \leq i \leq M$)</li>
<li>Bitwise XOR on series $Z$ is defined as $v_M$.</li>
</ul>
<p>
You have a sequence $A$ consisting of $N$ non-negative integers, ample sheets of papers and an empty box. You performed each of the following operations once on every combinations of integers ($L, R$), where $1 \leq L \leq R \leq N$.
</p>
<ol>
<li>Perform the bitwise XOR operation on the sub-sequence (from $L$-th to $R$-th elements) and name the result as $B$.</li>
<li>Select a sheet of paper and write $B$ on it, then put it in the box.</li>
</ol>
<p>
Assume that ample sheets of paper are available to complete the trials. You select a positive integer $K$ and line up the sheets of paper inside the box in decreasing order of the number written on them. What you want to know is the number written on the $K$-th sheet of paper.
</p>
<p>
You are given a series and perform all the operations described above. Then, you line up the sheets of paper in decreasing order of the numbers written on them. Make a program to determine the $K$-th number in the series.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$ $K$
$a_1$ $a_2$ ... $a_N$
</pre>
<p>
The first line provides the number of elements in the series $N$ ($1 \leq N \leq 10^5$) and the selected number $K$ ($1 \leq K \leq N(N+1)/2$). The second line provides an array of elements $a_i$ ($0 \leq a_i \leq 10^6$).
</p>
<h2>Sample Input 1 </h2>
<pre>
3 3
1 2 3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
After all operations have been completed, the numbers written on the paper inside the box are as follows (sorted in decreasing order)
</p>
<ul>
<li>$3,3,2,1,1,0$</li>
</ul>
<p>
3番目の数は2であるため、2を出力する。
</p>
<h2>Sample Input 2</h2>
<pre>
7 1
1 0 1 0 1 0 1
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<h2>Sample Input 3 </h2>
<pre>
5 10
1 2 4 8 16
</pre>
<h2>Sample Output 3</h2>
<pre>
7
</pre>
|
p03942 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>Shik's job is very boring. At day <var>0</var>, his boss gives him a string <var>S_0</var> of length <var>N</var> which consists of only lowercase English letters. In the <var>i</var>-th day after day <var>0</var>, Shik's job is to copy the string <var>S_{i-1}</var> to a string <var>S_i</var>. We denote the <var>j</var>-th letter of <var>S_i</var> as <var>S_i[j]</var>.</p>
<p>Shik is inexperienced in this job. In each day, when he is copying letters one by one from the first letter to the last letter, he would make mistakes. That is, he sometimes accidentally writes down the same letter that he wrote previously instead of the correct one. More specifically, <var>S_i[j]</var> is equal to either <var>S_{i-1}[j]</var> or <var>S_{i}[j-1]</var>. (Note that <var>S_i[1]</var> always equals to <var>S_{i-1}[1]</var>.)</p>
<p>You are given the string <var>S_0</var> and another string <var>T</var>.
Please determine the smallest integer <var>i</var> such that <var>S_i</var> could be equal to <var>T</var>. If no such <var>i</var> exists, please print <code>-1</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1,000,000</var></li>
<li>The lengths of <var>S_0</var> and <var>T</var> are both <var>N</var>.</li>
<li>Both <var>S_0</var> and <var>T</var> consist of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S_0</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the smallest integer <var>i</var> such that <var>S_i</var> could be equal to <var>T</var>. If no such <var>i</var> exists, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
abcde
aaacc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p><var>S_0</var> = <code>abcde</code>, <var>S_1</var> = <code>aaccc</code> and <var>S_2</var> = <code>aaacc</code> is a possible sequence such that <var>S_2 = T</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
abcde
abcde
</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>4
acaa
aaca
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5
abcde
bbbbb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>-1
</pre></section>
</div>
</span> |
p02650 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In a two-dimensional plane, we have a rectangle <var>R</var> whose vertices are <var>(0,0)</var>, <var>(W,0)</var>, <var>(0,H)</var>, and <var>(W,H)</var>, where <var>W</var> and <var>H</var> are positive integers.
Here, find the number of triangles <var>\Delta</var> in the plane that satisfy all of the following conditions:</p>
<ul>
<li>Each vertex of <var>\Delta</var> is a grid point, that is, has integer <var>x</var>- and <var>y</var>-coordinates.</li>
<li><var>\Delta</var> and <var>R</var> shares no vertex.</li>
<li>Each vertex of <var>\Delta</var> lies on the perimeter of <var>R</var>, and all the vertices belong to different sides of <var>R</var>.</li>
<li><var>\Delta</var> contains at most <var>K</var> grid points strictly within itself (excluding its perimeter and vertices).</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq W \leq 10^5</var></li>
<li><var>1 \leq H \leq 10^5</var></li>
<li><var>0 \leq K \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>W</var> <var>H</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>For example, the triangle with the vertices <var>(1,0)</var>, <var>(0,2)</var>, and <var>(2,2)</var> contains just one grid point within itself and thus satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>132
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>461316
</pre></section>
</div>
</span> |
p02200 | <h2>今日の乱数 (Today's Random Number)</h2>
<p>E869120 君は、「今日の乱数」というキャンペーンをN日間行いました。これは、毎日 1 回乱数を生成し、その値をツイッターに投稿するという企画です。</p>
<p>$1, 2, 3, \dots, N$ 日目の「今日の乱数」は、それぞれ $A_1, A_2, A_3, \dots, A_N$ でした。</p>
<p>E869120 君は、今日の乱数の値が昨日の乱数の値よりも高ければ嬉しくなります。</p>
<p>$N$ 日間のなかで、E869120 君は何回「今日の乱数」によって嬉しくなったでしょうか?</p>
<h3>入力</h3>
<p>入力は以下の形式で標準入力から与えられる。</p>
<pre>
$N$
$A_1$ $A_2$ $A_3$ $\dots$ $A_N$
</pre>
<h3>出力</h3>
<p>$N$ 日間のなかで、E869120 君が「今日の乱数」によって嬉しくなった回数を、1 行で出力してください。</p>
<p>ただし、最後には改行を入れること。</p>
<h3>制約</h3>
<ul>
<li>$1 \leq N \leq 100000 \ (= 10^5)$</li>
<li>$1 \leq A_i \leq 1000000000 \ (= 10^9)$</li>
<li>入力は全て整数である。</li>
</ul>
<h3>入力例1</h3>
<pre>
5
8 6 9 1 20
</pre>
<h3>出力例1</h3>
<pre>
2
</pre>
<p>3 日目と 5 日目にE869120君は嬉しさを感じます。</p>
<h3>入力例2</h3>
<pre>
6
3 3 4 3 3 4
</pre>
<h3>出力例2</h3>
<pre>
2
</pre>
<p>3 日目と 6 日目にE869120君は嬉しさを感じます。</p>
<h3>入力例3</h3>
<pre>
10
10 9 8 7 6 5 4 3 2 1
</pre>
<h3>出力例3</h3>
<pre>
0
</pre>
<p>E869120君が「今日の乱数」によって嬉しくなることはありません。</p>
|
p01586 |
<H1><font color="#000">Problem F:</font> Poor Computer</H1>
<p>
Brian Fulk is struggling with a really poor computer for a couple of days. Now he is trying to write a very simple program which receives a positive integer <i>x</i> and returns some of its multiples, say, <i>a</i><sub>1</sub><i>x</i>,...,<i>a</i><sub><i>N</i></sub><i>x</i>. However, even such a simple task is not easy on this computer since it has only three arithmetic operations: addition, subtraction and left shift.
</p>
<p>
Let us describe the situation in more details. Initially the computer stores only a given positive integer <i>x</i>. The program Brian is writing will produce <i>a</i><sub>1</sub><i>x</i>,..., <i>a</i><sub><i>N</i></sub><i>x</i>, where <i>a</i><sub>1</sub>,...,<i>a</i><sub><i>N</i></sub> are given multipliers, using only the following operations:
</p>
<ul>
<li> addition of two values,</li>
<li> subtraction of two values, and</li>
<li> bitwise left shift (left shift by n bits is equivalent to multiplication by 2<sup><i>n</i></sup>).</li>
</ul>
<p>
The program should not generate any value greater than 42<i>x</i>; under this constraint he can assume that no overflow occurs. Also, since this computer cannot represent negative values, there should not be subtraction of a greater value from a smaller value.
</p>
<p>
Some of you may wonder where the number 42 comes from. There is a deep reason related to the answer to life, the universe and everything, but we don't have enough space and time to describe it.
<?p>
<p>
Your task is to write a program that finds the shortest sequence of operations to produce the multiples <i>a</i><sub>1</sub><i>x</i>,...,<i>a</i><sub><i>N</i></sub><i>x</i> and reports the length of the sequence. These numbers may be produced in any order.
</p>
<p>
Here we give an example sequence for the first sample input, in a C++/Java-like language:
</p>
<pre>
a = x << 1; // 2x
b = x + a; // 3x
c = a + b; // 5x
d = c << 2; // 20x
e = d - b; // 18x
</pre>
<H2>Input</H2>
<p>
The first line specifies <i>N</i>, the number of multipliers. The second line contains <i>N</i> integers <i>a</i><sub>1</sub>,..., <i>a</i><sub><i>N</i></sub>, each of which represents a multiplier of <i>x</i>.
</p>
<p>
You can assume that <i>N</i> ≤ 41 and 2 ≤ <i>a<sub>i</sub></i> ≤ 42 (1 ≤ <i>i</i> ≤ <i>N</i>). Furthermore, <i>a</i><sub>1</sub>,...,<i>a<sub>N</sub></i> are all distinct.
</p>
<H2>Output</H2>
<p>
Output in a line the minimum number of operations you need to produce the values <i>a</i><sub>1</sub><i>x</i>,...,<i>a</i><sub><i>N</i></sub><i>x</i>.
</p>
<H2>Sample Input and Output</H2>
<H2>Input #1</H2>
<pre>
3
3 5 18
</pre>
<H2>Output #1</H2>
<pre>
5
</pre>
<br/>
<H2>Input #2</H2>
<pre>
1
29
</pre>
<H2>Output #2</H2>
<pre>
4
</pre>
<br/>
<H2>Input #3</H2>
<pre>
4
12 19 41 42
</pre>
<H2>Output #3</H2>
<pre>
8
</pre> |
p03041 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>N</var> consisting of <code>A</code>, <code>B</code> and <code>C</code>, and an integer <var>K</var> which is between <var>1</var> and <var>N</var> (inclusive).
Print the string <var>S</var> after lowercasing the <var>K</var>-th character in it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 50</var></li>
<li><var>1 ≤ K ≤ N</var></li>
<li><var>S</var> is a string of length <var>N</var> consisting of <code>A</code>, <code>B</code> and <code>C</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string <var>S</var> after lowercasing the <var>K</var>-th character in it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
ABC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>aBC
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
CABA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>CAbA
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.