question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03522 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence <var>A</var> of length <var>N</var>.</p>
<p>On this sequence, we can perform the following two kinds of operations:</p>
<ul>
<li>
<p>Swap two adjacent elements.</p>
</li>
<li>
<p>Select one element, and increment it by <var>1</var>.</p>
</li>
</ul>
<p>We will repeatedly perform these operations so that <var>A</var> will be a non-decreasing sequence. Find the minimum required number of operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 200000</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>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var>
<var>A_2</var>
<var>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to turn <var>A</var> into a non-decreasing sequence.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
4
1
8
8
7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can turn <var>A</var> into a non-decreasing sequence in two operations:</p>
<ul>
<li>Initially, <var>A = \{4, 1, 8, 8, 7\}</var>.</li>
<li>Swap the first two elements. Now, <var>A = \{1, 4, 8, 8, 7\}</var>.</li>
<li>Increment the last element by <var>1</var>. Now, <var>A = \{1, 4, 8, 8, 8\}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20
8
2
9
7
4
6
7
9
7
4
7
4
4
3
6
2
3
4
4
9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>62
</pre></section>
</div>
</span> |
p03488 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive <var>x</var>-axis direction.</p>
<p>This robot will be given an instruction sequence <var>s</var>.
<var>s</var> consists of the following two kinds of letters, and will be executed in order from front to back.</p>
<ul>
<li><code>F</code> : Move in the current direction by distance <var>1</var>.</li>
<li><code>T</code> : Turn <var>90</var> degrees, either clockwise or counterclockwise.</li>
</ul>
<p>The objective of the robot is to be at coordinates <var>(x, y)</var> after all the instructions are executed.
Determine whether this objective is achievable.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>s</var> consists of <code>F</code> and <code>T</code>.</li>
<li><var>1 \leq |s| \leq 8</var> <var>000</var></li>
<li><var>x</var> and <var>y</var> are integers.</li>
<li><var>|x|, |y| \leq |s|</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
<var>x</var> <var>y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the objective is achievable, print <code>Yes</code>; if it is not, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>FTFFTFFF
4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>FTFFTFFF
-2 -2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
<p>The objective can be achieved by, for example, turning clockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>FF
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>TF
1 0
</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>FFTTFF
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre>
<p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning counterclockwise in the second <code>T</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>TTTT
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>No
</pre></section>
</div>
</span> |
p03172 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> children, numbered <var>1, 2, \ldots, N</var>.</p>
<p>They have decided to share <var>K</var> candies among themselves.
Here, for each <var>i</var> (<var>1 \leq i \leq N</var>), Child <var>i</var> must receive between <var>0</var> and <var>a_i</var> candies (inclusive).
Also, no candies should be left over.</p>
<p>Find the number of ways for them to share candies, modulo <var>10^9 + 7</var>.
Here, two ways are said to be different when there exists a child who receives a different number of candies.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq K \leq 10^5</var></li>
<li><var>0 \leq a_i \leq K</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways for the children to share candies, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five ways for the children to share candies, as follows:</p>
<ul>
<li><var>(0, 1, 3)</var></li>
<li><var>(0, 2, 2)</var></li>
<li><var>(1, 0, 3)</var></li>
<li><var>(1, 1, 2)</var></li>
<li><var>(1, 2, 1)</var></li>
</ul>
<p>Here, in each sequence, the <var>i</var>-th element represents the number of candies that Child <var>i</var> receives.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 10
9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There may be no ways for the children to share candies.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 0
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p>There is one way for the children to share candies, as follows:</p>
<ul>
<li><var>(0, 0)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 100000
100000 100000 100000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>665683269
</pre>
<p>Be sure to print the answer modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p02011 | <h1>Problem H. Enlarge Circles</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
You are given $N$ distinct points on the 2-D plane. For each point, you are going to make a single circle whose center is located at the point. Your task is to maximize the sum of perimeters of these $N$ circles so that circles do not overlap each other. Here, "overlap" means that two circles have a common point which is not on the circumference of at least either of them. Therefore, the circumferences can be touched. Note that you are allowed to make a circle with radius $0$.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$N$
$x_1$ $y_1$
$\vdots$
$x_N$ $y_N$
</pre>
<p>
The first line contains an integer $N$, which is the number of points ($2 \leq N \leq 200$). Each of the following $N$ lines gives the coordinates of a point. Integers $x_i$ and $y_i$ ($-100 \leq x_i, y_i \leq 100$) in the $i$-th line of them give the $x$- and $y$-coordinates, respectively, of the $i$-th point. These points are distinct, in other words, $(x_i,y_i) \ne (x_j, y_j)$ is satisfied if $i$ and $j$ are different.
</p>
<h2>Output</h2>
<p>
Output the maximized sum of perimeters. The output can contain an absolute or a relative error no more than $10^{-6}$.
</p>
<h2>Examples</h2>
<h2>Sample Input 1</h2>
<pre>
3
0 0
3 0
5 0
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
31.415926535
</pre>
<h2>Sample Input 2</h2>
<pre>
3
0 0
5 0
0 5
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
53.630341225
</pre>
<h2>Sample Input 3</h2>
<pre>
9
91 -18
13 93
73 -34
15 2
-46 0
69 -42
-23 -13
-87 41
38 68
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
1049.191683488
</pre>
|
p00186 |
<H1>会津地鶏</H1>
<p>
2008 年 4 月に、会津若松市は長さ20 m 85 cm のやきとり作りに挑戦して成功しました。このとき使われた鶏肉が、会津特産の会津地鶏です。会津地鶏はとてもおいしいのですが、飼育がむずかしいので生産量が少なく、値段が高いのが難点です。<!--現在、生産拡大のための努力が進められているので、そのうちみなさんの住む町でも目にする日が来るかもしれません。-->
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_chicken"><br/>
<br/>
</center>
<p>
今日は一郎君の家に、遠くから親戚が遊びに来ます。お母さんは鶏肉の水炊きを作って親戚をもてなすことにしました。近くのお肉屋さんでは会津地鶏とふつうの鶏肉の 2 種類の鶏肉を売っています。お母さんは、以下のような指示を一郎君に与えて、お肉屋さんに行って鶏肉を買ってくるように
頼みました。
</p>
<ul>
<li>鶏肉が足りなくなると困るので、決められた量以上の鶏肉を買う。</li>
<li>予算の許す範囲で会津地鶏をできるだけ多く買う(会津地鶏は必ず買うこと)。</li>
<li>会津地鶏を買った残りでふつうの鶏肉をできるだけ多く買う(予算が足りなければ買わない)。</li>
</ul>
<p>
一郎君がお肉屋さんに行くと、会津地鶏が品薄のため一人が買える量を制限していました。一郎君が、お母さんから与えられたすべての指示を守って買い物をするとき、一郎君が買う会津地鶏と普通の鶏肉の量はそれぞれ何グラムになるでしょう?
</p>
<p>
買うべき鶏肉の量の下限 <var>q<sub>1</sub></var>、予算 <var>b</var>、このお肉屋さんでの会津地鶏 100 グラムの値段 <var>c<sub>1</sub></var>、ふつうの鶏肉 100 グラムの値段 <var>c<sub>2</sub></var>、会津地鶏を一人が買える量の上限 <var>q<sub>2</sub></var> を入力とし、一郎君が買う会津地鶏とふつうの鶏肉の量を 100 グラム単位で出力するプログラムを作成してください。ただし、このお肉屋さんではお母さんの指示通りに買えない場合には、「NA」と出力してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。 各データセットは以下の形式で与えられます。
</p>
<pre>
<var>q<sub>1</sub></var> <var>b</var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> <var>q<sub>2</sub></var>
</pre>
<p>
鶏肉の量を表すデータ <var>q<sub>1</sub></var> と <var>q<sub>2</sub></var> は100 グラム単位で指定されます。また、<var>b</var>、<var>c<sub>1</sub></var>、<var>c<sub>2</sub></var>、<var>q<sub>1</sub></var>、<var>q<sub>2</sub></var> は 1 以上 1,000,000 以下の整数とします。
</p>
<p>
データセットの数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
データセット毎に、一郎君が購入する会津地鶏の量とふつうの鶏肉の量(半角空白区切り) または「NA」を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
48 9297 240 126 32
20 3010 157 141 7
30 117002 5680 962 15
8 1673 1712 190 22
64 8478 87 54 307
23 5477 117 92 12
50 7558 1396 187 17
279 88677 4522 514 14
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
28 20
7 13
15 33
NA
97 0
12 44
NA
NA
</pre>
|
p02441 | <h1>Count</h1>
<p>
For a given sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$, perform the following operations.
</p>
<ul>
<li>count($b, e, k$): print the number of the specific values $k$ in $a_b, a_{b+1}, ..., a_{e-1}$.
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$b_1 \; e_1 \; k_1$
$b_2 \; e_2 \; k_2$
:
$b_q \; e_q \; k_q$
</pre>
<p>
The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $b_i \; b_e \; k_i$ are given as queries.
</p>
<h2>Output</h2>
<p>
For each query, print the number of specified values.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$-1,000,000,000 \leq a_i, k_i \leq 1,000,000,000$</li>
<li>$1 \leq q \leq 1,000$</li>
<li>$0 \leq b < e \leq n$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
9
1 4 1 4 2 1 3 5 6
3
0 9 1
1 6 1
3 7 5
</pre>
<h2>Sample Output 1</h2>
<pre>
3
2
0
</pre>
|
p03600 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads.
The following are known about the road network:</p>
<ul>
<li>People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.</li>
<li>Different roads may have had different lengths, but all the lengths were positive integers.</li>
</ul>
<p>Snuke the archeologist found a table with <var>N</var> rows and <var>N</var> columns, <var>A</var>, in the ruin of Takahashi Kingdom.
He thought that it represented the shortest distances between the cities along the roads in the kingdom.</p>
<p>Determine whether there exists a road network such that for each <var>u</var> and <var>v</var>, the integer <var>A_{u, v}</var> at the <var>u</var>-th row and <var>v</var>-th column of <var>A</var> is equal to the length of the shortest path from City <var>u</var> to City <var>v</var>.
If such a network exist, find the shortest possible total length of the roads.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li>If <var>i ≠ j</var>, <var>1 \leq A_{i, j} = A_{j, i} \leq 10^9</var>.</li>
<li><var>A_{i, i} = 0</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var>
<var>...</var>
<var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>If there exists no network that satisfies the condition, print <code>-1</code>.
If it exists, print the shortest possible total length of the roads.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 1 3
1 0 2
3 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The network below satisfies the condition:</p>
<ul>
<li>City <var>1</var> and City <var>2</var> is connected by a road of length <var>1</var>.</li>
<li>City <var>2</var> and City <var>3</var> is connected by a road of length <var>2</var>.</li>
<li>City <var>3</var> and City <var>1</var> is not connected by a road.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 1 3
1 0 1
3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>As there is a path of length <var>1</var> from City <var>1</var> to City <var>2</var> and City <var>2</var> to City <var>3</var>, there is a path of length <var>2</var> from City <var>1</var> to City <var>3</var>.
However, according to the table, the shortest distance between City <var>1</var> and City <var>3</var> must be <var>3</var>.</p>
<p>Thus, we conclude that there exists no network that satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>82
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
0 1000000000 1000000000
1000000000 0 1000000000
1000000000 1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3000000000
</pre></section>
</div>
</span> |
p02912 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is going to buy <var>N</var> items one by one.</p>
<p>The price of the <var>i</var>-th item he buys is <var>A_i</var> yen (the currency of Japan).</p>
<p>He has <var>M</var> discount tickets, and he can use any number of them when buying an item.</p>
<p>If <var>Y</var> tickets are used when buying an item priced <var>X</var> yen, he can get the item for <var>\frac{X}{2^Y}</var> (rounded down to the nearest integer) yen.</p>
<p>What is the minimum amount of money required to buy all the items?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N, M \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum amount of money required to buy all the items.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
2 13 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>We can buy all the items for <var>9</var> yen, as follows:</p>
<ul>
<li>Buy the <var>1</var>-st item for <var>2</var> yen without tickets.</li>
<li>Buy the <var>2</var>-nd item for <var>3</var> yen with <var>2</var> tickets.</li>
<li>Buy the <var>3</var>-rd item for <var>4</var> yen with <var>1</var> ticket.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
1 9 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100000
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>We can buy the item priced <var>1000000000</var> yen for <var>0</var> yen with <var>100000</var> tickets.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>9500000000
</pre></section>
</div>
</span> |
p01797 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem H
Kimagure Cleaner</h2>
<p>
Ichiro won the newest model cleaner as a prize of a programming contest. This cleaner automatically moves around in a house for cleaning. Because Ichiro's house is very large, it can be modeled as an infinite two-dimensional Cartesian plane, whose axes are called $X$ and $Y$. The positive direction of the $Y$-axis is to the left if you face the positive direction of the $X$-axis.
</p>
<p>
The cleaner performs a sequence of actions for cleaning. Each action consists of a turn and a run. In an action, first the cleaner turns right or left by 90 degrees, and then runs straight by an integer length to the direction that the cleaner faces. At the end of a day, the cleaner reports the log of its actions in the day to Ichiro, in order to inform him where it has cleaned and where it hasn't.
</p>
<p>
Unlike common cleaners, this cleaner has human-like artificial intelligence. Therefore, the cleaner is very forgetful (like humans) and it is possible that the cleaner forgets the direction of a turn, or the cleaner only remembers the length of a run as a very rough range. However, in order to pretend to be operating correctly, the cleaner has to recover the complete log of actions after finishing the cleaning.
</p>
<p>
The cleaner was initially at the point $(0, 0)$, facing the positive direction of $X$-axis. You are given the cleaner's location after cleaning, $(X, Y)$, and an incomplete log of the cleaner's actions that the cleaner remembered. Please recover a complete log from the given incomplete log. The actions in the recovered log must satisfy the following constraints:
</p>
<ul>
<li> The number of actions must be the same as that in the incomplete log.</li>
<li> The direction of the $i$-th turn must be the same as that in the incomplete log if it is recorded in the incomplete log.</li>
<li> The length of the $i$-th run must be within the range of the length specified in the incomplete log.</li>
<li> The cleaner must be at $(X, Y)$ after finishing all actions. The direction of the cleaner after cleaning is not important and you do not have to care about it, because the cleaner can turn freely after cleaning, though it cannot run after cleaning. You are not required to recover the actual path, because Ichiro only checks the format of the log and the location of the cleaner after cleaning.</li>
</ul>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains three integers $N$ $(1 \leq N \leq 50)$, $X$, and $Y$ $(-10^9 \leq X, Y \leq 10^9)$. $N$ represents the number of actions in the incomplete log. $X$ and $Y$ represent the cleaner's location $(X, Y)$ after cleaning. The $i$-th line of the following $N$ lines contains a character $D_i$ and two integers $LL_i$ and $LU_i$. $D_i$ represents the direction of the $i$-th turn: '<span>L</span>', '<span>R</span>', and '<span>?</span>' represents left, right, and not recorded respectively. $LL_i$ and $LU_i$ represent a lower and upper bound of the length of the $i$-th run, respectively. You can assume $1 \leq LL_i \leq LU_i \leq 55,555,555$.
</p>
<h3>Output</h3>
<p>
Display the recovered log. In the first line, display N, the number of actions in the log. In the $i$-th line of the following $N$ lines, display the direction of the $i$-th turn in a character and the length of the $i$-th run separated by a single space. Represent a right turn by a single character '<span>R</span>', and a left turn by a single character '<span>L</span>'. The recovered log must satisfy the constraints in the problem. If there are multiple
logs that satisfy the constraints, you can display any of them. Display $-1$ in a line if there is no log that satisfies the constraints.
</p>
<h3>Sample Input 1</h3>
<pre>2 -3 4
L 2 5
? 3 5</pre>
<h3>Output for the Sample Input 1</h3>
<pre>2
L 4
L 3</pre>
<h3>Sample Input 2</h3>
<pre>5 3 -4
? 1 5
? 1 5
? 1 5
? 1 5
? 1 5</pre>
<h3>Output for the Sample Input 2</h3>
<pre>5
L 1
R 2
R 4
L 1
R 1</pre> |
p00885 |
<H1><font color="#000">Problem B:</font> Balloon Collecting</H1>
<p>
"Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player can control the vehicle to move left or right, or simply stay. When one of the balloons reaches the ground, the vehicle and the balloon must reside at the same position, otherwise the balloon will burst and the game ends.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_balloonCollecting">
<p>
Figure B.1: Robot vehicle and falling balloons
</p>
</center>
<p>
The goal of the game is to store all the balloons into the house at the left end on the game field. The vehicle can carry at most three balloons at a time, but its speed changes according to the number of the carrying balloons. When the vehicle carries <i>k</i> balloons (<i>k</i> = 0, 1, 2, 3), it takes <i>k</i>+1 units of time to move one unit distance. The player will get higher score when the total moving distance of the vehicle is shorter.
</p>
<p>
Your mission is to help the game designer check game data consisting of a set of balloons. Given a landing position (as the distance from the house) and a landing time of each balloon, you must judge whether a player can capture all the balloons, and answer the minimum moving distance needed to capture and store all the balloons. The vehicle starts from the house. If the player cannot capture all the balloons, you must identify the first balloon that the player cannot capture.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows.
</p>
<p>
<i>n</i><br>
<i>p</i><sub>1</sub> <i>t</i><sub>1</sub><br>
.<br>
.<br>
.<br>
<i>p</i><sub><i>n</i></sub> <i>t</i><sub><i>n</i></sub><br>
</p>
<p>
The first line contains an integer n, which represents the number of balloons (0 < <i>n</i> ≤ 40). Each of the following <i>n</i> lines contains two integers <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) separated by a space. <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> represent the position and the time when the <i>i</i>-th balloon reaches the ground (0 < <i>p<sub>i</sub></i> ≤ 100, 0 < <i>t<sub>i</sub></I> ≤ 50000). You can assume <i>t<sub>i</sub></i> < <i>t<sub>j</sub></i> for <i>i</i> < <i>j</i>. The position of the house is 0, and the game starts from the time 0.
</p>
<p>
The sizes of the vehicle, the house, and the balloons are small enough, and should be ignored. The vehicle needs 0 time for catching the balloons or storing them into the house. The vehicle can start moving immediately after these operations.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output one word and one integer in a line separated by a space. No extra characters should occur in the output.
</p>
<ul>
<li> If the player can capture all the balloons, output "OK" and an integer that represents the minimum moving distance of the vehicle to capture and store all the balloons.
</li>
<li> If it is impossible for the player to capture all the balloons, output "NG" and an integer <i>k</i> such that the <i>k</i>-th balloon in the dataset is the first balloon that the player cannot capture.
</li>
</ul>
<H2>Sample Input</H2>
<pre>
2
10 100
100 270
2
10 100
100 280
3
100 150
10 360
40 450
3
100 150
10 360
40 440
2
100 10
50 200
2
100 100
50 110
1
15 10
4
1 10
2 20
3 100
90 200
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
OK 220
OK 200
OK 260
OK 280
NG 1
NG 2
NG 1
OK 188
</pre>
|
p03250 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have decided to give an allowance to your child depending on the outcome of the game that he will play now.</p>
<p>The game is played as follows:</p>
<ul>
<li>There are three "integer panels", each with a digit between <var>1</var> and <var>9</var> (inclusive) printed on it, and one "operator panel" with a <code>+</code> printed on it.</li>
<li>The player should construct a formula of the form <var>X + Y</var>, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)</li>
<li>Then, the amount of the allowance will be equal to the resulting value of the formula.</li>
</ul>
<p>Given the values <var>A, B</var> and <var>C</var> printed on the integer panels used in the game, find the maximum possible amount of the allowance.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A, B, C \leq 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>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible amount of the allowance.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>53
</pre>
<p>The amount of the allowance will be <var>53</var> when the panels are arranged as <code>52+1</code>, and this is the maximum possible amount.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 9 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>108
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>82
</pre></section>
</div>
</span> |
p01778 |
<h2>G: Dungeon of Cards / カードの迷宮</h2>
<h3>物語</h3>
<p>ここは不思議の国あじふらい.あじふらい辺境の地に位置するカードの迷宮には,金銀財宝が眠ると伝えられている.好奇心旺盛なあいずにゃんは,この言い伝えを聞くやいなや,友人のウィを連れてカードの迷宮を目指す旅に出ることにした.</p>
<p>翌日,旅の計画を立てるためにあいずにゃんがウィの家を訪れると,ウィは何やら考え込んでいるようだった.どうやら用意周到なウィはカードの迷宮に関する重要な情報を入手したようだ.それは,カードの迷宮には <var>N</var> 枚の扉があり,それぞれの扉を開けるためにカードが必要になるということだ.</p>
<p>カードの迷宮への道中には,扉を開くためのカードを扱う店がある.ウィはここでカードを調達しようと考えているらしいが,問題なのは予算である.あいずにゃんとウィは決してお金持ちではないので,カードにお金をかけすぎてしまうと道中の食料を十分に確保できない可能性があるのだ.</p>
<p>幸い <var>N</var> 枚の扉の情報は,これまで迷宮に挑んだ人々の記録から知ることができた.これなら効率の良いカードの買い方を計算できるかもしれない.しかし,2人で考えるには少し難しい.そこであいずにゃんとウィは,あじふらいに住む優秀なプログラマであるあなたに依頼をすることにした.</p>
<h3>問題</h3>
<p><var>N</var> 枚の扉と <var>M</var> 枚のカードがある.扉・カードともに1枚につき英大文字アルファベット ('A'-'Z') 1つと1桁の数字 ('0'-'9') が描かれている.扉にカードをかざすと,カードに描かれたアルファベット,もしくは数字のどちらか一方でも扉のものと一致していれば,その扉を開けることができる.このときカードはなくならないため,同じカードを何度でも使いまわすことができる.また,カードにはそれぞれ値段が付いている.</p>
<p><var>N</var> 枚の扉と <var>M</var> 枚のカードの情報を元に,すべての扉を開けることができるカードの買い方のうち,要する金額が最小となる場合の金額を計算するプログラムを作成せよ.</p>
<h3>入力形式</h3>
<p>入力は以下の形式からなる.</p>
<pre>
<var>N</var>
<var>a_1</var> <var>b_1</var>
...
<var>a_N</var> <var>b_N</var>
<var>M</var>
<var>c_1</var> <var>d_1</var> <var>e_1</var>
...
<var>c_M</var> <var>d_M</var> <var>e_M</var>
</pre>
<p>1行目では扉の枚数を表す整数 <var>N</var> が与えられる.続く <var>N</var> 行のうち,<var>i</var> 行目では <var>i</var> 番目の扉に書かれた英大文字アルファベット <var>a_i</var> と1桁の数字 <var>b_i</var> が与えられる.</p>
<p>続く1行では,店で扱われているカードの枚数 <var>M</var> が与えられる.続く <var>M</var> 行のうち,<var>j</var> 行目では <var>j</var> 番目のカードに書かれた英大文字アルファベット <var>c_j</var> と1桁の数字 <var>d_j</var>,価格 <var>e_j</var> が与えられる.</p>
<p>
入力は以下の制約を満たす.
<ul>
<li> <var>1 ≤ N, M ≤ 10{,}000</var> </li>
<li> <var>a_i, c_j</var> はアルファベット大文字 ('A'-'Z') 1文字 </li>
<li> <var>b_i, d_j</var>は1桁の数字 ('0'-'9') 1文字 </li>
<li> <var>1 ≤ e_j ≤ 1{,}000</var> </li>
<li> <var>N, M, e_j</var> はすべて整数 </li>
</ul>
</p>
<h3>出力形式</h3>
<p>迷宮の扉をすべて開けるために必要なカードを揃えるための最小予算を1行に出力せよ.どのようにカードを買っても全ての扉を開けられない場合,-1を1行に出力せよ.</p>
<h3>入力例1</h3>
<pre>
4
D 1
D 2
A 3
D 4
4
A 1 7
D 4 5
D 3 6
B 3 3
</pre>
<h3>出力例1</h3>
<pre>6</pre>
<h3>入力例2</h3>
<pre>
4
D 1
D 2
A 3
D 4
4
A 1 7
D 4 5
D 3 10
B 3 3
</pre>
<h3>出力例2</h3>
<pre>8</pre>
<h3>入力例3</h3>
<pre>
5
D 1
D 2
A 3
Z 0
D 4
4
A 1 7
D 4 5
D 3 6
B 3 3
</pre>
<h3>出力例3</h3>
<pre>-1</pre> |
p03745 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an array <var>A</var> of length <var>N</var>.
Your task is to divide it into several contiguous subarrays.
Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order.
At least how many subarrays do you need to divide <var>A</var> into?</p>
</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 \leq 10^9</var></li>
<li>Each <var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible number of subarrays after division of <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 2 3 2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One optimal solution is to divide the array into <var>[1,2,3]</var> and <var>[2,2,1]</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
1 2 1 2 1 2 1 2 1
</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>7
1 2 3 2 1 999999999 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p02857 | <span class="lang-en">
<p>Score: <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><font color="red"><strong>This is an interactive task.</strong></font></p>
<p>We have <var>2N</var> balls arranged in a row, numbered <var>1, 2, 3, ..., 2N</var> from left to right, where <var>N</var> is an odd number. Among them, there are <var>N</var> red balls and <var>N</var> blue balls.</p>
<p>While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most <var>210</var> questions of the following form:</p>
<ul>
<li>You choose any <var>N</var> of the <var>2N</var> balls and ask whether there are more red balls than blue balls or not among those <var>N</var> balls.</li>
</ul>
<p>Now, let us begin.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 99</var></li>
<li><var>N</var> is an odd number.</li>
</ul>
<hr/>
</section>
</div>
<div class="part">
<section>
<h3>Input and Output</h3>
<p>First, receive the number of balls of each color, <var>N</var>, from Standard Input:</p>
<pre><var>N</var>
</pre>
<p>Then, ask questions until you find out the color of every ball.
A question should be printed to Standard Output in the following format:</p>
<pre>? <var>A_1</var> <var>A_2</var> <var>A_3</var> <var>...</var> <var>A_N</var>
</pre>
<p>This means that you are asking about the <var>N</var> balls <var>A_1, A_2, A_3, ..., A_N</var>, where <var>1 \leq A_i \leq 2N</var> and <var>A_i \neq A_j (i \neq j)</var> must hold.</p>
<p>The response <var>T</var> to this question will be given from Standard Input in the following format:</p>
<pre><var>T</var>
</pre>
<p>Here <var>T</var> is one of the following strings:</p>
<ul>
<li><code>Red</code>: Among the <var>N</var> balls chosen, there are more red balls than blue balls.</li>
<li><code>Blue</code>: Among the <var>N</var> balls chosen, there are more blue balls than red balls.</li>
<li><code>-1</code>: You printed an invalid question (including the case you asked more than <var>210</var> questions), or something else that was invalid.</li>
</ul>
<p>If the judge returns <code>-1</code>, your submission is already judged as incorrect. The program should immediately quit in this case.</p>
<p>When you find out the color of every ball, print your guess to Standard Output in the following format:</p>
<pre>! <var>c_1</var><var>c_2</var><var>c_3</var><var>...</var><var>c_{2N}</var>
</pre>
<p>Here <var>c_i</var> should be the character representing the color of Ball <var>i</var>; use <code>R</code> for red and <code>B</code> for blue.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notice</h3>
<ul>
<li><font color="red"><strong>Flush Standard Output each time you print something.</strong></font> Failure to do so may result in <code>TLE</code>.</li>
<li>Immediately terminate your program after printing your guess (or receiving the <code>-1</code> response). Otherwise, the verdict will be indeterminate.</li>
<li>If your program prints something invalid, the verdict will be indeterminate.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input and Output</h3>
<table class="table-striped table-bordered table-condensed">
<tr align="center">
<th align="center">Input</th>
<th align="center">Output</th>
</tr>
<tr align="center">
<td><code>3</code></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td><code>? 1 2 3</code></td>
</tr>
<tr align="center">
<td><code>Red</code></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td><code>? 2 4 6</code></td>
</tr>
<tr align="center">
<td><code>Blue</code></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td><code>! RRBBRB</code></td>
</tr>
</table>
<p>In this sample, <var>N = 3</var>, and the colors of Ball <var>1, 2, 3, 4, 5, 6</var> are red, red, blue, blue, red, blue, respectively.</p>
<ul>
<li>In the first question, there are two red balls and one blue ball among the balls <var>1, 2, 3</var>, so the judge returns <code>Red</code>.</li>
<li>In the second question, there are one red ball and two blue balls among the balls <var>2, 4, 6</var>, so the judge returns <code>Blue</code>.</li>
</ul></section>
</div>
</span> |
p01282 |
<H1><font color="#000">Problem J:</font> Revenge of the Round Table</H1>
<p>
Two contries A and B have decided to make a meeting to get acquainted with each other. <i>n</i> ambassadors
from A and B will attend the meeting in total.
</p>
<p>
A round table is prepared for in the meeting. The ambassadors are getting seated at the round table, but
they have agreed that more than k ambassadors from the same country does not sit down at the round
table in a row for deeper exchange.
</p>
<p>
Your task is to write a program that reports the number of possible arrangements when rotations are not
counted. Your program should report the number modulo <i>M</i> = 1000003.
</p>
<p>
Let us provide an example. Suppose <i>n</i> = 4 and <i>k</i> = 2. When rotations are counted as different arrangements, the following six arrangements are possible.
</p>
<pre>
AABB
ABBA
BBAA
BAAB
ABAB
BABA
</pre>
<p>
However, when rotations are regarded as same, the following two arrangements are possible.
</p>
<pre>
AABB
ABAB
</pre>
<p>
Therefore the program should report 2.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of two integers <i>n</i> (1 ≤ <i>n</i> ≤ 1000) and <i>k</i> (1 ≤ k ≤ 1000) in one line.
</p>
<p>
It does not always hold <i>k</i> < <i>n</i>. This means the program should consider cases in which the ambassadors
from only one country attend the meeting.
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the number of possible arrangements modulo <i>M</i> = 1000003 in one line.
</p>
<H2>Sample Input</H2>
<pre>
3 1
3 2
3 3
4 2
10 5
1000 500
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
2
4
2
90
570682
</pre>
|
p01328 |
<h1><font color="#000">Problem H:</font> 迷い猫、走った</h1>
<p>洋菓子専門店ストレイキャッツではたくさんの猫が飼われている。猫の数があまりにも多いため、この店のスタッフである希は餌やりに困っていた。
いくつかの場所に餌を置いても、猫は貪欲なので最も近い餌に向かってしまい、一つの餌入れにたくさんの猫が集中してしまう。
あなたは希のために、できるだけ猫が集中しない餌の配置を求める問題を解くことにした。</p>
<p>問題を簡単にするため、猫は平面上の y>0 の部分にいて餌を置くまで動かないとする。
猫は N 個の集団に分かれていて、一箇所に何匹もいるかもしれない。
餌入れは y=0 上の M 点に固定してあり、この中からいくつか選んで餌を入れることになる。
餌を入れると、猫は(ユークリッド距離で)一番近い餌の入った餌入れに向かうが、同じ距離に二つあるときはx座標が小さいほうに向かうものとする。</p>
<p>この条件の下で、最も猫が集まっている餌入れの猫の数を最小化しなさい。
</p>
<h2>Input</h2>
入力は以下のような形式で与えられる。
<pre>
N M
x<sub>1</sub> y<sub>1</sub> C<sub>1</sub>
...
x<sub>N</sub> y<sub>N</sub> C<sub>N</sub>
x<sub>1</sub>
...
x<sub>M</sub>
</pre>
<p>入力の1行目には、2つの整数 N, M がスペース文字で区切られて与えられる。これらは、問題文で指定したとおりである。0 ≤ N ≤ 1000 および 1 ≤ M ≤ 1000 を満たす。</p>
<p>続く N 行には、それぞれの猫の集団について1行に1つずつ、集団の位置の x, y 座標を表す整数の組
(-10000 ≤ x ≤ 10000, 0 < y ≤ 10000)と何匹集まっているかを表す整数C(1 ≤ C ≤ 100000)が与えられる。</p>
<p>その後のM行には、それぞれの餌入れについて1行に1つずつ、餌入れの位置のx座標を表す整数(-10000 ≤ x ≤ 10000)が与えられる。
同じ点に、二つ以上の餌入れが存在することはない。
</p>
<h2>Output</h2>
<p>最も猫が集まっている餌入れの猫の数の最小値を出力せよ。
</p>
<h2>Notes on Test Cases</h2>
<p>
上記入力形式で複数のデータセットが与えられます。各データセットに対して上記出力形式で出力を行うプログラムを作成して下さい。
</p>
<p>
N, M がともに 0 のとき入力の終わりを示します。
</p>
<h2>Sample Input</h2>
<pre>
3 3
-1 1 1
0 1 1
1 1 1
-3
0
3
5 5
7 3 5
-9 2 7
4 9 6
10 5 9
-9 7 9
0
-1
-2
-9
-8
0 0
</pre>
<h2>Output for Sample Input</h2>
<pre>
2
20
</pre> |
p03315 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is always an integer in Takahashi's mind.</p>
<p>Initially, the integer in Takahashi's mind is <var>0</var>. Takahashi is now going to eat four symbols, each of which is <code>+</code> or <code>-</code>. When he eats <code>+</code>, the integer in his mind increases by <var>1</var>; when he eats <code>-</code>, the integer in his mind decreases by <var>1</var>.</p>
<p>The symbols Takahashi is going to eat are given to you as a string <var>S</var>. The <var>i</var>-th character in <var>S</var> is the <var>i</var>-th symbol for him to eat.</p>
<p>Find the integer in Takahashi's mind after he eats all the symbols.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>S</var> is <var>4</var>.</li>
<li>Each character in <var>S</var> is <code>+</code> or <code>-</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the integer in Takahashi's mind after he eats all the symbols.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>+-++
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<ul>
<li>Initially, the integer in Takahashi's mind is <var>0</var>.</li>
<li>The first integer for him to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>1</var>.</li>
<li>The second integer to eat is <code>-</code>. After eating it, the integer in his mind becomes <var>0</var>.</li>
<li>The third integer to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>1</var>.</li>
<li>The fourth integer to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>2</var>.</li>
</ul>
<p>Thus, the integer in Takahashi's mind after he eats all the symbols is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>-+--
</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>----
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-4
</pre></section>
</div>
</span> |
p02154 | <h1>Problem F: Equilateral Triangle</h1>
<h2>Problem</h2>
<p>$N$個の頂点からなる凸多角形が与えられる。</p>
<p>その凸多角形の全ての頂点を含む正三角形を考えるとき、その正三角形の一辺の長さの最小値を求めよ。</p>
<p></p>
<h2>Input</h2>
<p>入力は以下の形式ですべて整数で与えられる。</p>
<pre>
$N$
$px_1$ $py_1$
$px_2$ $py_2$
$\vdots$
$px_N$ $py_N$
</pre>
<p>
$1$行目には凸多角形の頂点数を表す整数$N$が与えられる。<br>
続く$N$行には凸多角形の各頂点の情報が反時計周りの順で与えられる。<br>
$1+i$行目には$i$番目の頂点の座標を表す$px_i$,$py_i$が空白区切りで与えられる。<br>
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>$3 \le N \le 10000$</li>
<li>$-10^9 \le px_i, py_i \le 10^9$</li>
<li>凸多角形の頂点のうちどの3点を選んでも、同一直線上には存在しない</li>
</ul>
<h2>Output</h2>
<p>
条件を満たす正三角形の一辺の長さの最小値を出力せよ。<br>
ただし、$10^{-5}$ までの絶対誤差または相対誤差は許容される。
</p>
<h2>Sample Input 1</h2>
<pre>
4
2 3
1 2
2 1
3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3.04720672
</pre>
<h2>Sample Input 2</h2>
<pre>
7
-96469 25422
-55204 -45592
-29140 -72981
98837 -86795
92303 63297
19059 96012
-67980 70342
</pre>
<h2>Sample Output 2</h2>
<pre>
310622.35426197
</pre>
|
p00169 |
<H1>ブラックジャック</H1>
<p>
ブラックジャックはカジノで行われるカードゲームの一種で、1 〜 13 までの数が書かれたカードを使ってゲームが行われます。各カードの点数は次のように決まっています。
</p>
<ul>
<li>1 は 1 点あるいは 11 点</li>
<li>2 から 9 までは、書かれている数の通りの点数</li>
<li>10 から 13 までは、10 点</li>
</ul>
<p>
このゲームには親を含めた何人かの参加者がおり、それぞれが何枚かのカードの組を持っています。このカードの組のことを手と呼びます。手の点数はカードの点数の合計です。その計算は次のように行うものとします。
</p>
<ul>
<li>カードの点数の合計が 21 より大きくなるときは、手の点数を 0 点とする</li>
<li>カードの点数として、1 は 1 点と計算しても 11 点と計算してもよいが、手の点数が最大となる方を選ぶこととする</li>
</ul>
<p>
配られたカードの情報を入力とし、手の点数を出力するプログラムを作成してください。
</p>
<!--
ただし、1つの手に含まれるカードの枚数 n は1以上21以下とし、同じ数が書かれたカードを何枚でも
含むことができるものとします。-->
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>n</sub></var>
</pre>
<p>
1行に <var>i</var> 番目のカードに書かれている整数 <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 13) が空白区切りで1行に与えられます。カードの数 <var>n</var> は 100 を超えません。
</p>
<p>
データセットの数は 200 を超えません。
</p>
<H2>Output</H2>
<p>
データセットごとに手の点数を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
1
7 7 7
7 7 8
12 1
10 1 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
11
21
0
21
12
</pre>
|
p00493 |
<H1>ジグザグ数 (Zig-Zag Numbers) </H1>
<h2> 問題</h2>
<p>
正の整数を (先頭に 0 をつけずに) 10 進法で書いて桁の数字を順番に見ていくと増加と減少を交互に繰り返しているとき,その数は「ジグザグ数」であると呼ぶことにしよう.たとえば,2947 は桁の数字が 2 → 9 → 4 → 7 と,増加 → 減少 → 増加 の順になっているのでジグザグ数である.また,71946 は 減少 → 増加 → 減少 → 増加 の順なのでジグザグ数である.一方,123 や 71446 や 71442 や 88 はジグザグ数ではない.なお,1 桁の正の整数はジグザグ数であると考えることとする.
</p>
<p>
A 以上 B 以下の M の倍数のうち,ジグザグ数の個数を 10000 で割った余りを求めるプログラムを作成せよ.
</p>
<h2> 入力</h2>
<p>
入力は 3 行からなり,1 行に 1 つずつ正の整数が書かれている.
</p>
<p>
1 行目の整数は A を,2 行目の整数は B を,3 行目の整数は M を表す.これらは 1 ≦ A ≦ B ≦ 10<sup>500</sup>,1 ≦ M ≦ 500 を満たす.
</p>
<p>
※ A や B の値は,通常の整数を表すデータ型には収まらない可能性があることに注意せよ.
</p>
<h2> 出力</h2>
<p>
A 以上 B 以下の M の倍数のうち,ジグザグ数の個数を 10000 で割った余りを 1 行で出力せよ.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
100
200
5
</pre>
<h3>出力例 1</h3>
<pre>
13
</pre>
<p>
入出力例 1 において,100 以上 200 以下の 5 の倍数であるジグザグ数は,105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195 の 13 個である.
</p>
<h3>入力例 2</h3>
<pre>
6
1234567
3
</pre>
<h3>出力例 2</h3>
<pre>
246
</pre>
<p>
入出力例 2 において,6 以上 1234567 以下の 3 の倍数であるジグザグ数は 50246 個あるので,それを 10000 で割った余りである 246 を出力する.
</p>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00539 |
<h2>JOI 公園 (JOI Park)</h2>
<p>
20XX 年に IOI 国で行われるオリンピックに備え,IOI 国にある JOI 公園を整備することになった.JOI公園には <var>N</var> 個の広場があり,広場には 1 から <var>N</var> の番号がついている.広場を繋ぐ <var>M</var> 本の道があり,道には 1 から <var>M</var> の番号がついている.道 <var>i</var> (1 ≤ <var>i</var> ≤ <var>M</var>) は広場 <var>A<sub>i</sub></var> と広場 <var>B<sub>i</sub></var> を双方向に繋いでおり,長さは <var>D<sub>i</sub></var> である.どの広場からどの広場へもいくつかの道を辿って行くことができる.
</p>
<p>
整備計画では,まず,0 以上の整数 <var>X</var> を選び,広場 1 からの距離が <var>X</var> 以下であるような広場 (広場 1 を含む) どうしをすべて相互に地下道で結ぶ.ただし,広場 <var>i</var> と広場 <var>j</var> の距離とは,広場 <var>i</var> から広場 <var>j</var> に行くときに通る道の長さの和の最小値である.整備計画では地下道の整備コストに関する整数 <var>C</var> が定まっている.地下道の整備にかかるコストは <var>C × X</var> である.
</p>
<p>
次に,地下道で結ばれた広場どうしを結ぶ道をすべて撤去する.道の撤去にコストはかからない.最後に,撤去されずに残った道をすべて補修する.長さ <var>d</var> の道を補修するためにかかるコストは <var>d</var> である.整備計画実施前の JOI 公園には地下道はない.JOI 公園の整備にかかるコストの和の最小値を求めよ.
</p>
<h3>課題</h3>
<p>
JOI 公園の広場の情報と,地下道の整備コストに関する整数が与えられたとき,JOI 公園の整備にかかる
コストの和の最小値を求めるプログラムを作成せよ.
</p>
<h3>入力</h3>
<p>
標準入力から以下のデータを読み込め.
</p>
<ul>
<li> 1 行目には,整数 <var>N</var>, <var>M</var>,<var>C</var> が空白を区切りとして書かれている.これは,広場が <var>N</var> 個,道が <var>M</var> 本あり,地下道の整備コストに関する整数が <var>C</var> であることを表す.</li>
<li> 続く <var>M</var> 行のうちの <var>i</var> 行目 (1 ≤ <var>i</var> ≤ <var>M</var>) には,整数 <var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>, <var>D<sub>i</sub></var> が空白を区切りとして書かれている.これは,道 <var>i</var> が広場 <var>A<sub>i</sub></var> と広場 <var>B<sub>i</sub></var> を繋ぎ,長さが <var>D<sub>i</sub></var> であることを表す.
</li>
</ul>
<h3>出力</h3>
<p>
標準出力に,JOI 公園の整備にかかるコストの和の最小値を表す整数を 1 行で出力せよ.
</p>
<h3>制限</h3>
<p>
すべての入力データは以下の条件を満たす.</p>
<ul>
<li> 2 ≤ <var>N</var> ≤ 100 000.</li>
<li> 1 ≤ <var>M</var> ≤ 200 000.</li>
<li> 1 ≤ <var>C</var> ≤ 100 000.</li>
<li> 1 ≤ <var>A<sub>i</sub></var> ≤ <var>N</var> (1 ≤ <var>i</var> ≤ <var>M</var>).</li>
<li> 1 ≤ <var>B<sub>i</sub></var> ≤ <var>N</var> (1 ≤ <var>i</var> ≤ <var>M</var>).</li>
<li> <var>A<sub>i</sub></var> ≠ <var>B<sub>i</sub></var> (1 ≤ <var>i</var> ≤ <var>M</var>).</li>
<li> (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) ≠ (<var>A<sub>j</sub></var>, <var>B<sub>j</sub></var>) および (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) ≠ (<var>B<sub>j</sub></var>, <var>A<sub>j</sub></var>) (1 ≤ <var>i</var> < <var>j</var> ≤ <var>M</var>).</li>
<li> 1 ≤ <var>D<sub>i</sub></var> ≤ 100 000 (1 ≤ <var>i</var> ≤ <var>M</var>).</li>
<li> 与えられる入力データにおいては,どの広場からどの広場へもいくつかの道を辿ることにより行けることが保証されている.</li>
</ul>
<h3>入出力例</h3>
<h3>入力例 1 </h3>
<pre>
5 5 2
2 3 1
3 1 2
2 4 3
1 2 4
2 5 5
</pre>
<h3>出力例 1</h3>
<pre>
14
</pre>
<p>
この入力例では,<var>X</var> = 3 として,広場 1 からの距離が 3 以下であるような広場 (広場 1, 広場 2, 広場 3) どうしをすべて相互に地下道で結んだとき,整備にかかるコストの和は 2 × 3 + 3 + 5 = 14 となる.これが最小値である.
</p>
<h3>入力例 2</h3>
<pre>
5 4 10
1 2 3
2 3 4
3 4 3
4 5 5
</pre>
<h3>出力例 2</h3>
<pre>
15
</pre>
<p>
この入力例では,X = 0 のとき整備にかかるコストの和が最小になる.
</p>
<h3>入力例 3 </h3>
<pre>
6 5 2
1 2 2
1 3 4
1 4 3
1 5 1
1 6 5
</pre>
<h3>出力例 3</h3>
<pre>
10
</pre>
<p>
この入力例では,<var>X</var> = 5 としてすべての広場を相互に地下道で結んだとき,整備にかかるコストの和が最小になる.
</p>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p01001 |
<h1>Problem C: General of Taiko</h1>
<h2>Problem</h2>
<p>
とあるゲームセンターには、曲に合わせて流れてくる譜面通りに和太鼓を叩くゲームがあります。
譜面は長さ<var> L </var>のセルからなり、各セルには何もない、またはノートと呼ばれるプレイヤーがとるべき行動を表した記号があります。
ノートは2種類ありそれぞれ、和太鼓の面を叩く「トン」、和太鼓の縁を叩く「コツ」があります。
これらのノートに合わせて和太鼓を叩くと得点を得ることができます。
この得点の合計が10000点以上であればクリアとなります。
</p>
<p>
このとき、プレイヤーが曲をクリアできる確率を求めなさい。ただし、プレイヤーは常に最適な行動をとることにします。
</p>
<p>
プレイヤーが譜面通りに和太鼓を叩く精度は11段階あり、それぞれ、
0%, 10%, 20%, ..., 90%, 100%の確率で譜面通りに和太鼓を叩くことができます。
</p>
<p>
上記の二種類の動作は右腕と左腕どちらででも行うことができます。
プレイヤーの情報として、それぞれの腕で行った場合の精度の安定率を表す値が16種類、下記のように与えられます。
</p>
<pre>
<var>lt</var>_<var>lt</var> <var>lt</var>_<var>rt</var> <var>lt</var>_<var>lk</var> <var>lt</var>_<var>rk</var>
<var>rt</var>_<var>lt</var> <var>rt</var>_<var>rt</var> <var>rt</var>_<var>lk</var> <var>rt</var>_<var>rk</var>
<var>lk</var>_<var>lt</var> <var>lk</var>_<var>rt</var> <var>lk</var>_<var>lk</var> <var>lk</var>_<var>rk</var>
<var>rk</var>_<var>lt</var> <var>rk</var>_<var>rt</var> <var>rk</var>_<var>lk</var> <var>rk</var>_<var>rk</var>
</pre>
<p>
ただし、<var> lt </var> は左腕でトン, <var> rt </var> は右腕でトン, <var> lk </var> は左腕でコツ, <var> rk </var> は右腕でコツの動作を表します。
例えば、<var> lt</var>_<var>rk </var>は左腕でトンのあとに右腕でコツを行った時の精度の安定の度合いを表し、この値によって左腕でトンのあとに右腕でコツを行うときの精度が、下記のように変化します。
</p>
<pre>
プレイヤーの精度 = max(0, (精度の安定率 - 10) * 10 + 一つ前の精度) (%)
</pre>
<p>
曲の情報は以下のとおりです。
曲の長さを表す<var> L </var>、譜面を表す<var> L </var>個の数字<var> s<sub>i</sub> </var>(0 ≤<var> i </var>< <var> L </var>)で示される。譜面の先頭は<var> s<sub>0</sub> </var>である。
<var> s<sub>i</sub> </var>の値は以下の3つです。
</p>
<pre>
0 ... ノートなし
1 ... トン
2 ... コツ
</pre>
<p>
プレイヤーが最初に和太鼓を叩くときの精度は100%です。
また、プレイヤーは譜面を無視することができます。
ノートがなかったり、ノートを無視した場合、プレイヤーの精度は100%になります。
</p>
<p>
各ノートに合わせて和太鼓を叩いたときの得点は下記のようになります。
</p>
<pre>
得点 =<var> A </var>+<var> B </var>* min(コンボ数, 10)
</pre>
<p>
この問題におけるコンボ数とは、連続してノートに合わせて和太鼓を叩けた数です。
プレイヤーがノートに合わせて叩いた場合、上記の式を元に得点が入り、その後にコンボ数が1増えます。
ノートに合わせて和太鼓を叩けなかった場合、コンボが途切れ、コンボ数が0になります。
</p>
<h2>Input</h2>
<p>
入力は複数のデータセットからなります。
各データセットは以下のとおりです。
</p>
<pre>
<var>lt</var>_<var>lt</var> <var>lt</var>_<var>rt</var> <var>lt</var>_<var>lk</var> <var>lt</var>_<var>rk</var>
<var>rt</var>_<var>lt</var> <var>rt</var>_<var>rt</var> <var>rt</var>_<var>lk</var> <var>rt</var>_<var>rk</var>
<var>lk</var>_<var>lt</var> <var>lk</var>_<var>rt</var> <var>lk</var>_<var>lk</var> <var>lk</var>_<var>rk</var>
<var>rk</var>_<var>lt</var> <var>rk</var>_<var>rt</var> <var>rk</var>_<var>lk</var> <var>rk</var>_<var>rk</var>
<var>L</var>
<var>s<sub>0</sub></var> <var>s<sub>1</sub></var> <var>s<sub>2</sub></var> … <var>s<sub>L - 1</sub></var>
<var>A</var> <var>B</var>
</pre>
<p>
入力の終わりは負の整数4つからなります。
</p>
<h2>Constraints</h2>
<p>
入力は以下の条件を満たします。
</p>
<ul>
<li>0 <<var> L </var>≤ 100</li>
<li>0 ≤ 精度の安定率 ≤ 10</li>
<li>精度の安定率は整数</li>
<li>0 <<var> A </var>, <var> B </var>≤ 10000</li>
<li><var> A </var>と<var> B </var>はともに100の倍数</li>
<li>データセットの数は100個以下</li>
</ul>
<h2>Output</h2>
<p>
各入力に対して、クリアできる確率を1行で出力しなさい。
ただし、出力は0.001以下の誤差を含んでも良いです。
</p>
<h2>Sample Input</h2>
<pre>
9 0 0 0
0 9 0 0
0 0 0 0
0 0 0 0
5
1 1 1 1 1
1000 500
10 10 10 10
10 10 10 10
10 10 10 10
10 10 10 10
5
1 0 2 0 1
1000 2000
3 8 6 10
0 1 6 8
10 2 4 7
8 6 6 8
19
2 2 0 2 2 0 2 1 0 1 2 0 1 2 0 1 0 2 2
200 100
-1 -1 -1 -1
</pre>
<h2>Sample Output</h2>
<pre>
0.3024000000
0.0000000000
0.5120000000
</pre>
|
p01451 |
<H1>Problem E: 街を駆ける道</H1>
<p>
ネーヴァ王国には、トタタ族とツテテ族、2種類の民族が暮らしている。トタタ族の最大の特徴は、
酢豚にパイナップルを入れて食べることである。だがツテテ族は、パイナップルに酢豚を入れて食べ
る。こんな2つの民族がお互いに仲良くやっていけるはずもなく、トタタ族とツテテ族は、何百年も
の昔からずっといがみ合いを続けてきた。
</p>
<p>
そんなある日、ネーヴァ王のもとに、2つの民族から嘆願書が届いた。それによるとトタタ族は、自
分たちが暮らす街Aと街Bのあいだを結ぶ道を建設してほしいらしい。一方でツテテ族も、自分たち
が暮らす街Cと街Dのあいだを結ぶ道を建設してほしいらしい。
</p>
<p>
2つの民族が衝突するのを防ぐため、トタタ族が通る道とツテテ族が通る道を交差させることはでき
ない。また、技術的な制約により、2つの街のあいだを一直線に結ぶような道しか建設することはで
きない。つまり、必要ならば街Aと街Bを直接道で結ばずに、いくつかのトタタ族の街を経由して街
Aと街Bを間接的に結ぶことになるだろう(もちろん、ツテテ族の街を経由してはならない)。その
際、トタタ族の街を結ぶ道どうしは交差していてもよい。街Cと街Dについても同様である。
</p>
<p>
道を建設するには、その長さに比例したコストがかかる。なので、条件をみたしつつ、できるだけ建
設する道の長さの合計が短くなるようにしたい。さて、長さの最小値はいくつになるだろうか。
</p>
<H2>Input</H2>
<p>
<i>N<sub>A</sub> N<sub>B</sub></i><br>
<i>x</i><sub><i>A</i>,1</sub> <i>y</i><sub><i>A</i>,1</sub><br>
<i>x</i><sub><i>A</i>,2</sub> <i>y</i><sub><i>A</i>,2</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub> <i>y</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub><br>
<i>x</i><sub><i>B</i>,1</sub> <i>y</i><sub><i>B</i>,1</sub><br>
<i>x</i><sub><i>B</i>,2</sub> <i>y</i><sub><i>B</i>,2</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub> <i>y</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub><br>
</p>
<p>
入力の1行目には、整数<i>N<sub>A</sub></i>(2 ≤ <i>N<sub>A</sub></i> ≤ 1,000)と整数<i>N<sub>B</sub></i>(2 ≤ <i>N<sub>B</sub></i> ≤ 1,000)が、空白区切りで書かれている。これは、ネーヴァ王国にはトタタ族が暮らす街がNA 個、ツテテ族が暮らす街がNB 個あることをあらわす。初期状態では、どこにも道は建設されていない。
</p>
<p>
続く<i>N<sub>A</sub></i> 行には、整数<i>x<sub>A,i</sub></i>(-10,000 ≤ <i>x<sub>A,i</sub></i> ≤ 10,000)と整数<i>y<sub>A,i</sub></i>(-10,000 ≤ <i>y<sub>A,i</sub></i> ≤ 10,000)が、空白区切りで書かれている。ネーヴァ王国の地理は2次元直交座標平面であらわされ、1+ i 行目に書かれた整数<i>x<sub>A,i</sub></i> と<i>y<sub>A,i</sub></i> は、トタタ族が暮らすi 番目の街の位置座標が(<i>x<sub>A,i</sub></i>, <i>y<sub>A,i</sub></i>) であることをあらわす。(<i>x<sub>A,1</sub></i>, <i>y<sub>A,1</sub></i>) と(<i>x<sub>A,2</sub></i>, <i>y<sub>A,2</sub></i>) が、結ぶべき2つの街の座標である。
</p>
<p>
続く<i>N<sub>B</sub></i> 行には、整数<i>x<sub>B,i</sub></i>(-10,000 ≤ <i>x<sub>B,i</sub></i> ≤ 10,000)と整数<i>y<sub>B,i</sub></i>(-10,000 ≤ <i>y<sub>B,i</sub></i> ≤ 10,000)が、空白区切りで書かれている。1+ <i>N<sub>A</sub></i> + i 行目に書かれた整数<i>x<sub>B,i</sub></i> と<i>y<sub>B,i</sub></i> は、ツテテ族が暮らすi 番目の街の位置座標が(<i>x<sub>B,i</sub></i>, <i>y<sub>B,i</sub></i>) であることをあらわす。(<i>x<sub>B,1</sub></i>, <i>y<sub>B,1</sub></i>) と(<i>x<sub>B,2</sub></i>, <i>y<sub>B,2</sub></i>) が、結ぶべき2つの街の座標である。
</p>
<p>
どの2つの街の座標も異なっており、どの3つの街も同一直線上にないと仮定してよい。
</p>
<H2>Output</H2>
<p>
問題文の条件をみたすように道を建設したとき、道の長さの合計の最小値を出力せよ。ここで言う
「長さ」とは、ユークリッド距離のことである。ただし、どうやっても条件をみたす道を建設できな
いときは、代わりに-1 を出力せよ。出力は誤差を含んでいてもよいが、真の値との相対誤差が10<sup>-9</sup>未満でなければならない。
</p>
<h2>Sample Input 1</h2>
<pre>
2 2
0 0
1 1
2 0
2 -1
</pre>
<h2>Sample Output 1</h2>
<pre>
2.414213562373
</pre>
<h2>Sample Input 2</h2>
<pre>
2 3
4 0
0 0
2 3
2 -2
3 1
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre>
<h2>Sample Input 3</h2>
<pre>
5 2
-2 1
1 2
-1 3
-1 5
1 4
0 4
0 0
</pre>
<h2>Sample Output 3</h2>
<pre>
12.359173603117
</pre> |
p03196 | <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 <var>a_1, a_2, ..., a_N</var> not less than <var>1</var>.
The values of <var>a_1, a_2, ..., a_N</var> are not known, but it is known that <var>a_1 \times a_2 \times ... \times a_N = P</var>.</p>
<p>Find the maximum possible greatest common divisor of <var>a_1, a_2, ..., a_N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{12}</var></li>
<li><var>1 \leq P \leq 10^{12}</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>P</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 24
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The greatest common divisor would be <var>2</var> when, for example, <var>a_1=2, a_2=6</var> and <var>a_3=2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>As <var>a_i</var> are positive integers, the only possible case is <var>a_1 = a_2 = a_3 = a_4 = a_5 = 1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>111
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 972439611840
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>206
</pre></section>
</div>
</span> |
p01902 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>
<h2>E: 鬼畜ババ抜き - Unbalanced Old Maid -</h2>
<h3>物語</h3>
<p>高坂さんと園田さんと南さんは子供の頃からの仲良し3人組だ。3人は沖縄に修学旅行に行くも、台風が来てしまい、海で遊ぶことができないのでババ抜きをすることにした。</p>
<p>
園田さんは勝負事には強いが、ポーカーフェイスが苦手なため、自分のカードが引かれるときに無意識にかわいらしい顔芸を披露してしまう。園田さんを愛して止まない高坂さんと南さんは、園田さんの顔芸を見るだけで園田さんの手札が分かってしまうため、園田さんのカードを引くときは、自分が有利になるように引くことができる。
一方、高坂さんと南さんは特に顔芸をしたりはしないので、手札がばれることはない。 よって、高坂さんと南さんのカードを引く人はそれぞれ、高坂さんと南さんが持っているカードの中から等確率で1枚引く。
</p>
<p>どう考えても不利な園田さんは、ババ抜きでなかなか勝てないことに違和感を覚えている。 使用するカードの種類数<var>n</var>と初期の手札が与えられたとき、園田さんが負けとならない確率を求めてあげよう。</p>
<h3>問題文</h3>
<p>高坂さん、園田さん、南さんの3人は、以下の状況でババ抜きを行う。</p>
<ul>
<li>使用するカードは、1から<var>n</var>までの整数が書かれた<var>n</var>種類のカードそれぞれ4枚ずつとジョーカー1枚の合計<var>4n+1</var>枚である。</li>
<li>最初の手札が与えられたとき、3人はそれぞれ自分の手札に同一の整数が書かれたカードのペア(2枚組)があるならば、そのようなペアを全て捨てる。</li>
<li>3人は「高坂さんが南さんの手札からカードを引く」、「園田さんが高坂さんの手札からカードを引く」「南さんが園田さんの手札からカードを引く」という順番(ターン)で以下の操作を繰り返す。(このババ抜きでは、カードを引いた人が、次に引かれるというルールであることに注意せよ。)</li>
<ol>
<li>一人がジョーカーのみを持ち、その人以外の2人の手札が空のとき、ババ抜きは終了し、ジョーカーを持っている人が負けとなる。</li>
<li>カードを引く順番の人の手札が空のとき、ターンを次の人とし、1.に戻る。</li>
<li>そうでなければ、カードを引く順番の人は決められた相手からカードを1枚引く。ただし、相手の手札が空のとき、まだ残っているもう1人からカードを引く。</li>
<li>引いたカードと同じ整数が書かれたカードがカードを引いた人の手札にあれば、その2枚を捨てる。</li>
<li>ターンを次の人とし、1.へ戻る。</li>
</ol>
<li>ただし、園田さんのカードを引く人(南さんか高坂さん)は、以下の戦略でカード引く。</li>
<ol>
<li>もし自分のカードと園田さんのカードで同じ整数が書かれたカードがあれば、それらのうち最小の整数が書かれたカードを引く</li>
<li>そうでないとき、園田さんがジョーカーでないカードを持っていれば、それらのうち最小の整数が書かれたカードを引く</li>
<li>そうでないなら、園田さんはジョーカーしか持っていないので、ジョーカーを引く</li>
</ol>
<li>高坂さんと南さんのカードを引く人は、それぞれ高坂さんと南さんが持っているカードの中から等確率で1枚引く。</li>
</ul>
<p>使用するカードの種類数<var>n</var>と3人の初期の手札が与えられたとき、園田さんが負けとならない確率を求めてあげよう。</p>
<h3>入力形式</h3>
<p>入力は4行からなり、以下の形式で与えられる。</p>
<pre>
<var>n</var>
<var>m_1</var> <var>c_{1,1}</var> ... <var>c_{1,m_1}</var>
<var>m_2</var> <var>c_{2,1}</var> ... <var>c_{2,m_2}</var>
<var>m_3</var> <var>c_{3,1}</var> ... <var>c_{3,m_3}</var>
</pre>
<p>
1行目にジョーカー以外のカードの種類数<var>n</var>が与えられる。
続く入力は3行からなり、2行目に高坂さんの手札、3行目に園田さんの手札、4行目に南さんの手札の情報が与えられる。
<var>i+1 (1 ≤ i ≤ 3)</var>行目では行頭に手持ちの枚数<var>m_i</var>、続けて手持ちのカードを表す<var>m_i</var>個の整数<var>c_{i,j} (1 ≤ j ≤ m_i)</var>が空白区切りで与えられる。 <var>0</var>はジョーカー、<var>1</var>から<var>n</var>はカードに書かれた整数を表す。
</p>
<h3>制約</h3>
<ul>
<li><var>1 ≤ n ≤ 100</var></li>
<li><var>m_1+m_2+m_3 = 4n+1</var></li>
<li>3人の手札で0はちょうど1つ、<var>1</var>から<var>n</var>はちょうど4回ずつ現れる</li>
<li><var>0 ≤ c_{i,j} ≤ n</var> (<var>1 ≤ i ≤ 3</var>, <var>1 ≤ j ≤ m_i</var>)</li>
</ul>
<h3>出力形式</h3>
<p>園田さんが負けとならない確率を1行に出力せよ。答えには<var>10^{−6}</var>を超える絶対誤差があってはならない。</p>
<h3>入力例1</h3>
<pre>
1
1 1
3 0 1 1
1 1
</pre>
<h3>出力例1</h3>
<pre>0.0</pre>
<p>
高坂さんが南さんのカード1を引き、高坂さんと南さんは手札が空になる。
園田さんはどうしても勝つことはできない。
</p>
<h3>入力例2</h3>
<pre>
1
2 1 1
1 1
2 0 1
</pre>
<h3>出力例2</h3>
<pre>0.5</pre>
<p>はじめの高坂さんのターンは、高坂さんの手札が既に空なので何もしない。次の園田さんのターンでは、園田さんは南さんの手札のうちそれぞれ0.5の確率でカード1かジョーカーを引く。カード1を引いたとき、園田さんの手札は空となり勝利する。一方ジョーカーを引いたときは、次の南さんのターンで、南さんは確実にカード1を引くので園田さんが負けとなる。</p>
<h3>入力例3</h3>
<pre>
2
3 0 1 2
3 1 2 2
3 1 1 2
</pre>
<h3>出力例3</h3>
<pre>0.5</pre>
<h3>入力例4</h3>
<pre>
2
2 0 1
6 2 2 2 1 1 1
1 2
</pre>
<h3>出力例4</h3>
<pre>0.6666666667</pre> |
p00610 |
<H1><font color="#000000">Problem F:</font> Cleaning Robot 2.0</H1>
<p>
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful.
</p>
<p>
First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has <i>N</i> × <i>N</i> rooms arranged in a square likewise. Then he laid either black or white carpet on each room.
</p>
<p>
Since still enough money remained, he decided to spend them for development of a new robot. And finally he completed.
</p>
<p>
The new robot operates as follows:
</p>
<ul>
<li>The robot is set on any of <i>N</i> × <i>N</i> rooms, with directing any of north, east, west and south.</li>
<li>The robot detects color of carpets of lefthand, righthand, and forehand adjacent rooms if exists. If there is exactly one room that its carpet has the same color as carpet of room where it is, the robot changes direction to and moves to and then cleans the room. Otherwise, it halts. Note that halted robot doesn't clean any longer. Following is some examples of robot's movement.
<br>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cleaningRobot2">
<p>Figure 1. An example of the room</p>
</center>
<br>
In Figure 1,
<ul>
<li>robot that is on room (1,1) and directing north directs east and goes to (1,2).</li>
<li>robot that is on room (0,2) and directing north directs west and goes to (0,1).</li>
<li>robot that is on room (0,0) and directing west halts.</li>
</ul>
</li>
<li>Since the robot powered by contactless battery chargers that are installed in every rooms, unlike the previous robot, it never stops because of running down of its battery. It keeps working until it halts.</li>
</ul>
<p>
Doctor's house has become larger by the renovation. Therefore, it is not efficient to let only one robot clean. Fortunately, he still has enough budget. So he decided to make a number of same robots and let them clean simultaneously.
</p>
<p>
The robots interacts as follows:
</p>
<ul>
<li> No two robots can be set on same room.</li>
<li> It is still possible for a robot to detect a color of carpet of a room even if the room is occupied by another robot.</li>
<li> All robots go ahead simultaneously.</li>
<li> When robots collide (namely, two or more robots are in a single room, or two robots exchange their position after movement), they all halt. Working robots can take such halted robot away.</li>
</ul>
<p>
On every room dust stacks slowly but constantly. To keep his house pure, he wants his robots to work so that dust that stacked on any room at any time will eventually be cleaned.
</p>
<p>
After thinking deeply, he realized that there exists a carpet layout such that no matter how initial placements of robots are, this condition never can be satisfied. Your task is to output carpet layout that there exists at least one initial placements of robots that meets above condition. Since there may be two or more such layouts, please output the <i>K</i>-th one lexicographically.
</p>
<H2>Input</H2>
<p>
Input file contains several data sets.
One data set is given in following format:
</p>
<pre>
<i>N K</i>
</pre>
<p>
Here, <i>N</i> and <i>K</i> are integers that are explained in the problem description.
</p>
<p>
The end of input is described by a case where <i>N</i> = <i>K</i> = 0. You should output nothing for this case.
</p>
<H2>Output</H2>
<p>
Print the <i>K</i>-th carpet layout if exists, "<span>No</span>" (without quotes) otherwise.
</p>
<p>
The carpet layout is denoted by <i>N</i> lines of string that each has exactly <i>N</i> letters. A room with black carpet and a room with white carpet is denoted by a letter '<span>E</span>' and '<span>.</span>' respectively. Lexicographically order of carpet layout is defined as that of a string that is obtained by concatenating the first row, the second row, ..., and the <i>N</i>-th row in this order.
</p>
<p>
Output a blank line after each data set.
</p>
<p>
</p>
<H2>Constraints</H2>
<ul>
<li>Judge data consists of at most 100 data sets.</li>
<li>1 ≤ <i>N</i> < 64</li>
<li>1 ≤ <i>K</i> < 2<sup>63</sup></li>
</ul>
<H2>Sample Input</H2>
<pre>
2 1
2 3
6 4
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
..
..
No
..EEEE
..E..E
EEE..E
E..EEE
E..E..
EEEE..
</pre>
|
p00240 |
<H1>金利計算</H1>
<p>
金利は銀行に預けているお金に付き、その計算方法や利率は銀行によって様々です。利息と元金を合わせたものを元利と呼びますが、元利の計算方法として、利息を元金に組み入れずに計算する「単利」と利息を元金に組み入れて計算する「複利」というものがあり、より多くの元利を得るためにはこの差異を理解していなければなりません。元利の計算方法は以下のようになります。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0240_1"><br>
<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0240_2">
</center>
<br>
<!--
<p>
できれば、わずかな金利でもより多くお金を増やしたいと思うものです。相沢さんの家庭では、今まで預けていた銀行は金利が低い事に気づき、新しい銀行に乗り換えようとしています。しかし、相沢さん一家は金利のことについてあまり詳しく知らなかったので、金利に詳しいあなたに助けを求めてきました。比較すべき銀行の数は多いうえ、相沢さん一家以外にも助けを求められそうです。作業を効率化するためにより良い銀行を計算するプログラムを作成しておきましょう。
</p>
-->
<p>
銀行の数、お金を預ける年数、各銀行の情報(銀行番号、金利の種類、年利率(パーセント))を入力とし、最も元利が高くなる銀行番号を出力するプログラムを作成してください。ただし、最も元利が高くなる銀行は一つだけです。
</p>
<h2>入力</h2>
<p>
複数のデータセットが与えられます。入力の終わりはゼロひとつで示されます。各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>y</var>
<var>b<sub>1</sub></var> <var>r<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>b<sub>2</sub></var> <var>r<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>b<sub>n</sub></var> <var>r<sub>n</sub></var> <var>t<sub>n</sub></var>
</pre>
<p>
1行目に銀行の数 <var>n</var> (1 ≤ <var>n</var> ≤ 50)、2行目にお金を預ける年数 <var>y</var> (1 ≤ <var>y</var> ≤ 30)が与えられます。続く<var>n</var> 行に <var>i</var> 番目の銀行の銀行番号 <var>b<sub>i</sub></var>、年利率を表す整数 <var>r<sub>i</sub></var> (1 ≤ <var>r<sub>i</sub></var> ≤ 100)、 金利の種類 <var>t<sub>i</sub></var> (1 または 2) が与えられます。金利の種類 <var>t<sub>i</sub></var> は、単利の場合は1、複利の場合は2で与えられます。
</p>
<p>
データセットの数は 100 を超えません。
</p>
<h2>出力</h2>
<p>
データセットごとに、最も元利が高くなる銀行番号を1行に出力します。
</p>
<h2>入力例</h2>
<pre>
2
8
1 5 2
2 6 1
2
9
1 5 2
2 6 1
0
</pre>
<h2>出力例</h2>
<pre>
2
1
</pre> |
p03895 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi recorded his daily life for the last few days as a integer sequence of length <var>2N</var>, as follows:</p>
<ul>
<li><var>a_1, b_1, a_2, b_2, ... , a_N, b_N</var></li>
</ul>
<p>This means that, starting from a certain time <var>T</var>, he was:</p>
<ul>
<li>sleeping for exactly <var>a_1</var> seconds</li>
<li>then awake for exactly <var>b_1</var> seconds</li>
<li>then sleeping for exactly <var>a_2</var> seconds</li>
<li>:</li>
<li>then sleeping for exactly <var>a_N</var> seconds</li>
<li>then awake for exactly <var>b_N</var> seconds</li>
</ul>
<p>In this record, he waked up <var>N</var> times.</p>
<p>Takahashi is wondering how many times he waked up early during the recorded period.</p>
<p>Here, he is said to <em>wake up early</em> if he wakes up between <var>4:00</var> AM and <var>7:00</var> AM, inclusive.</p>
<p>If he wakes up more than once during this period, each of these awakenings is counted as waking up early.</p>
<p>Unfortunately, he forgot the time <var>T</var>.</p>
<p>Find the maximum possible number of times he waked up early during the recorded period.</p>
<p>For your information, a day consists of <var>86400</var> seconds, and the length of the period between <var>4:00</var> AM and <var>7:00</var> AM is <var>10800</var> seconds.</p>
</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 10^5</var></li>
<li><var>a_i</var> and <var>b_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
:
<var>a_N</var> <var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of times he waked up early during the recorded period.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
28800 57600
28800 57600
57600 28800
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
28800 57600
4800 9600
6000 1200
600 600
300 600
5400 600
6000 5760
6760 2880
6000 12000
9000 600
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre></section>
</div>
</span> |
p02787 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ibis is fighting with a monster.</p>
<p>The <em>health</em> of the monster is <var>H</var>.</p>
<p>Ibis can cast <var>N</var> kinds of spells. Casting the <var>i</var>-th spell decreases the monster's health by <var>A_i</var>, at the cost of <var>B_i</var> Magic Points.</p>
<p>The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.</p>
<p>Ibis wins when the health of the monster becomes <var>0</var> or below.</p>
<p>Find the minimum total Magic Points that have to be consumed before winning.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H \leq 10^4</var></li>
<li><var>1 \leq N \leq 10^3</var></li>
<li><var>1 \leq A_i \leq 10^4</var></li>
<li><var>1 \leq B_i \leq 10^4</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>N</var>
<var>A_1</var> <var>B_1</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total Magic Points that have to be consumed before winning.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9 3
8 3
4 2
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>First, let us cast the first spell to decrease the monster's health by <var>8</var>, at the cost of <var>3</var> Magic Points. The monster's health is now <var>1</var>.</p>
<p>Then, cast the third spell to decrease the monster's health by <var>2</var>, at the cost of <var>1</var> Magic Point. The monster's health is now <var>-1</var>.</p>
<p>In this way, we can win at the total cost of <var>4</var> Magic Points.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 6
1 1
2 3
3 9
4 27
5 81
6 243
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
<p>It is optimal to cast the first spell <var>100</var> times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>139815
</pre></section>
</div>
</span> |
p02292 |
<H1>Counter-Clockwise</H1>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_CGL_CGL_1_C">
</center>
<p>
For given three points <var>p0, p1, p2</var>, print
</p>
<pre>
COUNTER_CLOCKWISE
</pre>
<p>
if <var>p0, p1, p2</var> make a counterclockwise turn (1),
</p>
<pre>
CLOCKWISE
</pre>
<p>
if <var>p0, p1, p2</var> make a clockwise turn (2),
</p>
<pre>
ONLINE_BACK
</pre>
<p>
if <var>p2</var> is on a line <var>p2, p0, p1</var> in this order (3),
</p>
<pre>
ONLINE_FRONT
</pre>
<p>
if <var>p2</var> is on a line <var>p0, p1, p2</var> in this order (4),
</p>
<pre>
ON_SEGMENT
</pre>
<p>
if <var>p2</var> is on a segment <var>p0p1</var> (5).
</p>
<H2>Input</H2>
<pre>
<var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var>
<var>q</var>
<var>x<sub>p2<sub>0</sub></sub></var> <var>y<sub>p2<sub>0</sub></sub></var>
<var>x<sub>p2<sub>1</sub></sub></var> <var>y<sub>p2<sub>1</sub></sub></var>
...
<var>x<sub>p2<sub>q-1</sub></sub></var> <var>y<sub>p2<sub>q-1</sub></sub></var>
</pre>
<p>
In the first line, integer coordinates of <var>p0</var> and <var>p1</var> are given. Then, <var>q</var> queries are given for integer coordinates of <var>p2</var>.
</p>
<H2>Output</H2>
<p>
For each query, print the above mentioned status.
</p>
<H2>Constraints</H2>
<ul>
<li>
<var>1 ≤ q ≤ 1000</var>
</li>
<li>
<var>-10000 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 10000</var>
</li>
<li>
<var>p0</var> and <var>p1</var> are not identical.
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
0 0 2 0
2
-1 1
-1 -1
</pre>
<H2>Sample Output 1</H2>
<pre>
COUNTER_CLOCKWISE
CLOCKWISE
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
0 0 2 0
3
-1 0
0 0
3 0
</pre>
<H2>Sample Output 2</H2>
<pre>
ONLINE_BACK
ON_SEGMENT
ONLINE_FRONT
</pre>
<br/>
|
p01847 |
<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-AMS_HTML">
</script>
<h3>カーテン</h3>
<p>もうすぐ夏がやってくる.あなたは夏に向けて部屋の模様替えをすることにした.今年の夏はとても日差しが強いことが予想されており,まぶしいのが苦手なあなたには辛い季節になりそうだ.そこで,あなたは部屋の明るさを調節するために,部屋の窓にカーテンを取り付けようと考えた.
</p>
<p>取り付けるカーテンは長方形であり,辺が地面に対して垂直,もしくは平行であるように取り付ける.また,あなたの部屋の窓は非常に特殊な形をしており,各辺が地面に平行または垂直であるような <i>N</i> 角形で表される.そのため,カーテンを取り付けたときにカーテンに覆われていない窓の面積がどのくらいになるのかを求めるのは難しい.部屋の明るさを調節するためにも,カーテンを取り付ける位置を決めた時にどのくらい窓が覆えるかを知ることは重要である.そこで,あなたは窓とカーテンの設置位置と形状が与えられたときに,カーテンに覆われていない窓の面積を求めるプログラムを作ることにした.
</p>
<p>例として次のような窓とカーテンの設置の仕方を考える.この場合はカーテンに隠れていない窓の面積は 8 となる.この例はサンプル入力の 3 ケース目に対応する.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_window" witdh="400" height="400"><br/>
</center>
<h3>Input</h3>
<p>入力は複数データセットからなる.
各データセットは次の形式で与えられる.
</p>
<blockquote><i>N</i><br><i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br>:<br>:<br><i>x<sub>N</sub></i> <i>y<sub>N</sub></i><br><i>a<sub>1</sub></i> <i>b<sub>1</sub></i><br><i>a<sub>2</sub></i> <i>b<sub>2</sub></i><br><i>a<sub>3</sub></i> <i>b<sub>3</sub></i><br><i>a<sub>4</sub></i> <i>b<sub>4</sub></i></blockquote>
<p>最初の行には窓の持つ頂点数を表す整数 <i>N</i> が与えられる (<i>4 ≤ N ≤ 100</i>).続く <i>N</i> 行には窓の相異なる頂点のx座標を表す整数 <i>x<sub>i</sub></i> とy座標を表す整数 <i>y<sub>i</sub></i> が与えられる (<i>-20,000 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 20,000, 1 ≤ i ≤ N</i>).ここで,y軸の正の向きはx軸の正の向きから90度分反時計回りに回転させた方向とする.さらに,続く 4 行にはカーテンの相異なる頂点のx座標を表す整数 <i>a<sub>j</sub></i> と y座標を表す整数 <i>b<sub>j</sub></i> が与えられる (<i>-20,000 ≤ a<sub>j</sub>, b<sub>j</sub> ≤ 20,000, 1 ≤ j ≤ 4</i>).窓,カーテンともに,それぞれの頂点は反時計回り順に与えられる.また,窓,カーテンを表す図形はそれぞれ自己交差がない図形である.
</p>
<p>入力の終わりは1つの 0 からなる行で示す.
</p>
<h3>Output</h3>
<p>各データセットについて,カーテンに覆われていない窓の面積を 1 行に出力せよ.ただし,面積は必ず整数値になることに注意せよ.
</p>
<h3>Sample Input</h3>
<pre>4
0 0
10 0
10 10
0 10
0 0
5 0
5 10
0 10
6
0 0
10 0
10 5
5 5
5 10
0 10
2 0
8 0
8 10
2 10
12
1 1
1 3
-1 3
-1 1
-3 1
-3 -1
-1 -1
-1 -3
1 -3
1 -1
3 -1
3 1
2 2
-2 2
-2 -2
2 -2
4
20000 20000
-20000 20000
-20000 -20000
20000 -20000
1000 1000
-1000 1000
-1000 -1000
1000 -1000
4
1000 1000
-1000 1000
-1000 -1000
1000 -1000
20000 20000
-20000 20000
-20000 -20000
20000 -20000
4
0 0
10 0
10 10
0 10
20 0
30 0
30 10
20 10
0</pre>
<h3>Output for Sample Input</h3>
<pre>50
30
8
1596000000
0
100</pre>
|
p00755 |
<h3><U>Identically Colored Panels Connection</U></h3>
<!-- end en only -->
<div>
<!-- please enclose each h3 level section with div -->
<!-- begin en only -->
<p>
Dr. Fukuoka has invented fancy panels.
Each panel has a square shape of a unit size and
has one of the six colors, namely, yellow, pink, red, purple, green and blue.
The panel has two remarkable properties.
One property is that, when two or more panels with the same color
are placed adjacently, their touching edges melt a little
and they are fused each other.
The fused panels are united into a polygonally shaped panel.
The other property is that the color of a panel can be changed
to one of six colors by giving an electrical shock.
The resulting color can be controlled by its waveform.
The electrical shock to an already united panel changes
the color of the whole to a specified single color.
</p>
<p>
Since he wants to investigate the strength with respect to the
color and the size of a united panel compared to unit panels,
he tries to unite panels into a polygonal panel with a specified color.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_1" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-1: panels and their initial colors<br><br>
</center>
<!-- end en only -->
<!-- begin en only -->
<p>
Since many panels are simultaneously synthesized and generated on a base plate
through some complex chemical processes,
the fabricated panels are randomly colored and
they are arranged in a rectangular shape on the base plate (Figure C-1).
Note that the two purple (color 4) panels in Figure C-1 are
already united at the initial state since they are
adjacent to each other.
</p>
<p>
Installing electrodes to a panel, and
changing its color several times by giving electrical shocks
according to an appropriate sequence for a specified target color,
he can make a united panel merge the adjacent panels
to unite them step by step
and can obtain a larger panel with the target color.
Unfortunately, panels will be broken when
they are struck by the sixth electrical shock.
That is, he can change the color of a panel or a united panel only
five times.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Let us consider a case
where the panel at the upper left corner of the panel configuration
(Figure C-1) is attached with the electrodes.
First, changing the color of the panel from yellow to blue,
the two adjacent panels are fused into a united panel (Figure C-2).
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_2" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-2:
Change of the color of the panel at the upper left corner,
from yellow (color 1) to blue (color 6).<br><br>
</center>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
Second, changing the color of the upper left united panel from blue
to red, a united red panel that consists of three unit panels is newly formed
(Figure C-3).
Then, changing the color of the united panel from red to purple,
panels are united again to form a united panel of five unit panels
(Figure C-4).
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_3" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-3:
Change of the color of the panel at the upper left corner,
from blue (color 6) to red (color 3).
<br><br>
</center>
<!-- end en only -->
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_4" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-4:
Change of the color of the panel at the upper left corner,
from red (color 3) to purple (color 4).
<br><br>
</center>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
Furthermore, through making a pink united panel in Figure C-5 by
changing the color from purple to pink,
then, the green united panel in Figure C-6 is obtained
by changing the color from pink to green.
The green united panel consists of ten unit panels.
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_5" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-5:
Change of the color of the panel at the upper left corner,
from purple (color 4) to pink (color 2).<br><br>
</center>
<!-- end en only -->
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_6" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-6:
Change of the color of the panel at the upper left corner,
from pink (color 2) to green (color 5).<br><br>
</center>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
In order to check the strength of united panels with
various sizes and colors, he needs to unite as many panels
as possible with the target color.
Your job is to write a program that finds a sequence to change
the colors five times
in order to get the largest united panel with the target color.
Note that the electrodes are fixed to the panel at the upper left corner.
</p>
<!-- end en only -->
</div>
<h3>Input</h3>
<div>
<!-- begin en only -->
<p>
The input consists of multiple datasets, each being in the following format.
</p>
<!-- end en only -->
<blockquote>
<i>h</i> <i>w</i> <i>c</i><br>
<i>p</i><sub>1,1</sub> <i>p</i><sub>1,2</sub> ... <i>p</i><sub>1,<i>w</i></sub><br>
<i>p</i><sub>2,1</sub> <i>p</i><sub>2,2</sub> ... <i>p</i><sub>2,<i>w</i></sub><br>
...<br>
<i>p</i><sub><i>h</i>,1</sub> <i>p</i><sub><i>h</i>,2</sub> ... <i>p</i><sub><i>h</i>,<i>w</i></sub><br>
</blockquote>
<!-- begin en only -->
<i>h</i> and <i>w</i> are positive integers no more than 8 that
represent the height and the width of the given rectangle.
<i>c</i> is a positive integer no more than 6 that represents
the target color of the finally united panel.
<i>p</i><sub><i>i</i>,<i>j</i></sub> is a positive integer no more than 6
that represents the initial color of the panel at the position
(<i>i</i>, <i>j</i>).
<p>The end of the input is indicated by a line that consists of
three zeros separated by single spaces.
</p>
<!-- end en only -->
</div>
<h3>Output</h3>
<div>
<!-- begin en only -->
<p>
For each dataset, output the largest possible number of unit panels
in the united panel at the upper left corner with the target color
after five times of color changes of the panel
at the upper left corner.
No extra characters should occur in the output.
</p>
<!-- end en only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3 5 5
1 6 3 2 5
2 5 4 6 1
1 2 4 1 5
4 5 6
1 5 6 1 2
1 4 6 3 2
1 5 2 3 2
1 1 2 3 2
1 1 5
1
1 8 6
1 2 3 4 5 1 2 3
8 1 1
1
2
3
4
5
1
2
3
8 8 6
5 2 5 2 6 5 4 2
4 2 2 2 5 2 2 2
4 4 4 2 5 2 2 2
6 4 5 2 2 2 6 6
6 6 5 5 2 2 6 6
6 2 5 4 2 2 6 6
2 4 4 4 6 2 2 6
2 2 2 5 5 2 2 2
8 8 2
3 3 5 4 1 6 2 3
2 3 6 4 3 6 2 2
4 1 6 6 6 4 4 4
2 5 3 6 3 6 3 5
3 1 3 4 1 5 6 3
1 6 6 3 5 1 5 3
2 4 2 2 2 6 5 3
4 1 3 6 1 5 5 4
0 0 0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
10
18
1
5
6
64
33
</pre>
</div> |
p02768 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Akari has <var>n</var> kinds of flowers, one of each kind.</p>
<p>She is going to choose one or more of these flowers to make a bouquet.</p>
<p>However, she hates two numbers <var>a</var> and <var>b</var>, so the number of flowers in the bouquet cannot be <var>a</var> or <var>b</var>.</p>
<p>How many different bouquets are there that Akari can make?</p>
<p>Find the count modulo <var>(10^9 + 7)</var>.</p>
<p>Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.</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^9</var></li>
<li><var>1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var> <var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of bouquets that Akari can make, modulo <var>(10^9 + 7)</var>. (If there are no such bouquets, print <code>0</code>.)</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>In this case, Akari can choose <var>2</var> or <var>4</var> flowers to make the bouquet.</p>
<p>There are <var>6</var> ways to choose <var>2</var> out of the <var>4</var> flowers, and <var>1</var> way to choose <var>4</var>, so there are a total of <var>7</var> different bouquets that Akari can make.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000000000 141421 173205
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>34076506
</pre>
<p>Print the count modulo <var>(10^9 + 7)</var>.</p></section>
</div>
</span> |
p00305 |
<h1>枠</h1>
<p>
画像の中から有益な情報を抽出する画像認識はコンピュータサイエンスの中でも重要な研究テーマのひとつです。デジタルカメラ、運転支援システム、防犯システムなどに幅広く応用されています。
</p>
<p>
このような研究のおかげで、私たちは画像解析を行うための多くのソフトウェアやプログラム集を使い様々な処理を行うことができます。一方、自力でプログラムを書いて解析することで、その仕組みを知り、楽しい時間を過ごすことができます。ここでは、一風変わった画像認識をしてみましょう。
</p>
<p>
画像として次のような各ピクセルが整数の値を持つ <var>N</var> × <var>N</var> のピクセルが入力として与えられます。この画像の中から、線の太さが1ピクセルの長方形の枠(わく)を1つ抽出します。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame1" width="380">
</center>
<br>
<p>
枠が覆うピクセルの値の和が最大となるような枠を抽出して、その和を報告するプログラムを作成して
下さい。ただし、下の図のように、縦、横のピクセル数が1つや2つの場合も枠とみなすものとします。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame2" width="560">
</center>
<br>
<h2>入力</h2>
<p>
入力は以下の形式で与えられる。
</p>
<pre>
<var>N</var>
<var>p<sub>1,1</sub></var> <var>p<sub>1,2</sub></var> ... <var>p<sub>1,N</sub></var>
<var>p<sub>2,1</sub></var> <var>p<sub>2,2</sub></var> ... <var>p<sub>2,N</sub></var>
:
<var>p<sub>N,1</sub></var> <var>p<sub>N,2</sub></var> ... <var>p<sub>N,N</sub></var>
</pre>
<p>
1行目に縦と横のピクセル数 <var>N</var> (1 ≤ <var>N</var> ≤ 300) が与えられる。続く <var>N</var> 行に、<var>i</var> 行 <var>j</var> 列目のピクセルの値を表す整数 <var>p<sub>i,j</sub></var> (-1000 ≤ <var>p<sub>i,j</sub></var> ≤ 1000)が与えられる。
</p>
<h2>出力</h2>
<p>
ピクセル値の和が最大となるような枠の、ピクセル値の和を1行に出力する。
</p>
<h2>入出力例</h2>
<br>
<h2>入力例1</h2>
<pre>
5
2 0 0 2 0
0 1 0 2 0
0 0 0 -1 0
0 4 0 3 0
-1 0 0 1 0
</pre>
<h2> 出力例1 </h2>
<pre>
12
</pre>
<h2>入力例2</h2>
<pre>
3
0 0 0
0 -1 0
0 0 0
</pre>
<h2>出力例2</h2>
<pre>
0
</pre>
|
p02338 | <!--<h1>写像12相 その8:ボールに区別あり・箱に区別なし・箱の中身は1つ以下</h1>-->
<h1>Balls and Boxes 8</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td style="background-color:#aff">8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is distinguished from the other.</li>
<li>Each box is <b>not</b> distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box can contain at most one ball.</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
5 10
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
200 100
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
|
p03483 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters.
Determine whether we can turn <var>S</var> into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 2 × 10^5</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If we cannot turn <var>S</var> into a palindrome, print <code>-1</code>. Otherwise, print the minimum required number of operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>eel
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>We can turn <var>S</var> into a palindrome by the following operation:</p>
<ul>
<li>Swap the <var>2</var>-nd and <var>3</var>-rd characters. <var>S</var> is now <code>ele</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ataatmma
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>We can turn <var>S</var> into a palindrome by the following operation:</p>
<ul>
<li>Swap the <var>5</var>-th and <var>6</var>-th characters. <var>S</var> is now <code>ataamtma</code>.</li>
<li>Swap the <var>4</var>-th and <var>5</var>-th characters. <var>S</var> is now <code>atamatma</code>.</li>
<li>Swap the <var>3</var>-rd and <var>4</var>-th characters. <var>S</var> is now <code>atmaatma</code>.</li>
<li>Swap the <var>2</var>-nd and <var>3</var>-rd characters. <var>S</var> is now <code>amtaatma</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>snuke
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>We cannot turn <var>S</var> into a palindrome.</p></section>
</div>
</span> |
p03179 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>N</var> be a positive integer.
You are given a string <var>s</var> of length <var>N - 1</var>, consisting of <code><</code> and <code>></code>.</p>
<p>Find the number of permutations <var>(p_1, p_2, \ldots, p_N)</var> of <var>(1, 2, \ldots, N)</var> that satisfy the following condition, modulo <var>10^9 + 7</var>:</p>
<ul>
<li>For each <var>i</var> (<var>1 \leq i \leq N - 1</var>), <var>p_i < p_{i + 1}</var> if the <var>i</var>-th character in <var>s</var> is <code><</code>, and <var>p_i > p_{i + 1}</var> if the <var>i</var>-th character in <var>s</var> is <code>></code>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an integer.</li>
<li><var>2 \leq N \leq 3000</var></li>
<li><var>s</var> is a string of length <var>N - 1</var>.</li>
<li><var>s</var> consists of <code><</code> and <code>></code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of permutations 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>4
<><
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five permutations that satisfy the condition, as follows:</p>
<ul>
<li><var>(1, 3, 2, 4)</var></li>
<li><var>(1, 4, 2, 3)</var></li>
<li><var>(2, 3, 1, 4)</var></li>
<li><var>(2, 4, 1, 3)</var></li>
<li><var>(3, 4, 1, 2)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
<<<<
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There is one permutation that satisfies the condition, as follows:</p>
<ul>
<li><var>(1, 2, 3, 4, 5)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20
>>>><>>><>><>>><<>>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>217136290
</pre>
<p>Be sure to print the number modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p01144 |
<!-- begin en only -->
<h3><U> Princess' Marriage </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>
ある貧乏な国のおてんばで勇敢なお姫様は,ギャンブルの配当がパリミュチュエル方式で決定される事を知ることにより,ギャンブルについて詳しくなった気がしてギャンブルでの勝利を確信した.その結果,今までよりも更に多額のお金をつぎ込み,国民が納めた税金をすべて失うほどの負けを喫してしまった.この事態を重く受け止めた王様は,お姫様を隣の国へ嫁がせることにした.こうすることにより,お姫様を日頃の行いを反省させ,同時に隣国との交友を深めて財政援助をしてもらおうと考えたからである.
</p>
<p>
お姫様と隣国の王子様はお互いの事が気に入り,また両国の王様間でも政略結婚に関する同意がなされた.お姫様はなけなしのお金を手に意気揚々と隣の国へ出かけた.一方で,お姫様が嫁ぐ動機は王様の一方的な利益追及のためであり,快くないと考える隣国の王子様の側近は,お姫様を亡き者にするために道の途中に無数の刺客達を放った.
</p>
<p>
お姫様が通る道はすでに決められている.お姫様の通る道には合計 <i>L</i> 個の宿場がある.便宜上,出発地点および到着地点も宿場とし,各宿場を <i>S<sub>1</sub></i>, <i>S<sub>2</sub></i>, ... <i>S<sub>L</sub></i> と呼ぶことにする.お姫様は最初に <i>S<sub>1</sub></i> におり,昇順に (<i>S<sub>2</sub></i>, <i>S<sub>3</sub></i> ... という順番で) 宿場を訪れて,最終的に <i>S<sub>L</sub></i> へ行くものとする.宿場では金銭を払って護衛を雇うことができ,お金がある限り好きな距離だけ契約してお姫様を守らせることができる.護衛を雇う費用は,距離1につき金1である.お姫様は通る区間内を部分的に守ってもらうことも出来ることに注意せよ.<i>S<sub>i</sub></i>と<i>S<sub>i+1</sub></i>間の距離は<i>D<sub>i</sub></i>,<i>S<sub>i</sub></i>と<i>S<sub>i+1</sub></i>間で距離1につき刺客に襲われる回数の期待値は<i>P<sub>i</sub></i>で与えられている.
</p>
<p>
お姫様が予算<i>M</i>を持っていて,刺客に襲われる回数の期待値が最小になるように護衛を雇ったときの,目的地までに刺客に襲われる回数の期待値を求めよ.
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
入力は複数のデータセットからなる.各データセットは以下のような形式をとる.
</p>
<blockquote>
<i>N</i> <i>M</i><br>
<i>D<sub>1</sub></i> <i>P<sub>1</sub></i><br>
<i>D<sub>2</sub></i> <i>P<sub>2</sub></i><br>
...<br>
<i>D<sub>N</sub></i> <i>P<sub>N</sub></i>
</blockquote>
各データセットの最初の行には二つの整数が与えられ,それぞれ区間の数 <i>N</i>(1≦<i>N</i>≦10,000) と,お姫差が持つ予算 <i>M</i>(0≦<i>M</i>≦1,000,000,000) を表す.次の <i>N</i> 行はお姫様が通る道の情報を表す.各行は二つの整数が含まれており,<i>i</i>行目は区間の距離 <i>D<sub>i</sub></i>(1≦<i>D<sub>i</sub></i>≦10,000) とその間を1単位距離移動したときに襲われる回数の期待値 <i>P<sub>i</sub></i>(0≦<i>P<sub>i</sub></i><=10) からなる.
入力の終端は <i>N</i>=0, <i>M</i>=0 となるデータセットであらわされる.このデータセットに対しては計算結果を出力してはならない.
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
各データセット毎に,お姫様が目的地までに刺客に襲われる回数の期待値を出力せよ.
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
2 8
5 6
4 5
3 1
5 10
5 10
5 10
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
5
140
</pre>
|
p03529 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider the following game:</p>
<ul>
<li>The game is played using a row of <var>N</var> squares and many stones.</li>
<li>First, <var>a_i</var> stones are put in Square <var>i\ (1 \leq i \leq N)</var>.</li>
<li>A player can perform the following operation as many time as desired: "Select an integer <var>i</var> such that Square <var>i</var> contains exactly <var>i</var> stones. Remove all the stones from Square <var>i</var>, and add one stone to each of the <var>i-1</var> squares from Square <var>1</var> to Square <var>i-1</var>."</li>
<li>The final score of the player is the total number of the stones remaining in the squares.</li>
</ul>
<p>For a sequence <var>a</var> of length <var>N</var>, let <var>f(a)</var> be the minimum score that can be obtained when the game is played on <var>a</var>.</p>
<p>Find the sum of <var>f(a)</var> over all sequences <var>a</var> of length <var>N</var> where each element is between <var>0</var> and <var>K</var> (inclusive).
Since it can be extremely large, find the answer modulo <var>1000000007 (= 10^9+7)</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 K \leq N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of <var>f(a)</var> modulo <var>1000000007 (= 10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>There are nine sequences of length <var>2</var> where each element is between <var>0</var> and <var>2</var>. For each of them, the value of <var>f(a)</var> and how to achieve it is as follows:</p>
<ul>
<li><var>f(\{0,0\})</var>: <var>0</var> (Nothing can be done)</li>
<li><var>f(\{0,1\})</var>: <var>1</var> (Nothing can be done)</li>
<li><var>f(\{0,2\})</var>: <var>0</var> (Select Square <var>2</var>, then Square <var>1</var>)</li>
<li><var>f(\{1,0\})</var>: <var>0</var> (Select Square <var>1</var>)</li>
<li><var>f(\{1,1\})</var>: <var>1</var> (Select Square <var>1</var>)</li>
<li><var>f(\{1,2\})</var>: <var>0</var> (Select Square <var>1</var>, Square <var>2</var>, then Square <var>1</var>)</li>
<li><var>f(\{2,0\})</var>: <var>2</var> (Nothing can be done)</li>
<li><var>f(\{2,1\})</var>: <var>3</var> (Nothing can be done)</li>
<li><var>f(\{2,2\})</var>: <var>3</var> (Select Square <var>2</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>983853488
</pre></section>
</div>
</span> |
p01514 |
<!-- begin en only -->
<h3><u>You Are the Judge
</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>審判は君だ!
</u></h3>
<!-- end ja only -->
<div>
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
あなたはプログラミングコンテスト iCPC の審判だ。今日も何事もなく試合が終わり、後は結果を出力するだけだと思いきや、突然システムが停止してしまった!
</p>
<p>
これでは結果が出力できない! でも、大丈夫。我々にはログがある。
</p>
<p>
あなたは優れたプログラマーであり、かつて iCPC で輝かしい成績を残したこともある。
</p>
<p>
そこであなたはシステムログから各チームの成績を割り出し、チームの順位表を出力するプログラムを作成することにした。
</p>
<p>
入力としてチームの数、問題の数、システムログが与えられる。
</p>
<p>
シムテムログは以下の 2 種類のレコードからなる。
</p>
<table>
<thead><tr><th style="padding: .5em; background: #069; color: #fff">レコード</th><th style="padding: .5em; background: #069; color: #fff">内容</th><th style="padding: .5em; background: #069; color: #fff">効果</th></tr></thead>
<tbody><tr><td style="padding: .5em; background: #0cf">tID pID time CORRECT</td><td style="padding: .5em; background: #0cf"> 時刻 time に、チーム tID が 問題 pID に正解するプログラムを送信。 </td><td style="padding: .5em; background: #0cf"> チーム tID の正解数に1が加算される。<br>チーム tID のペナルティに、(チーム tID の問題 pID に対する誤答数*1200+time)が加算される。<br> 以後, チーム tID の問題 pID に対する解答は棄却され、システムログにも送信履歴が残らない。 </td></tr></tbody>
<tbody><tr><td style="padding: .5em; background: #0cf">tID pID time WRONG</td><td style="padding: .5em; background: #0cf"> 時刻 time に、チーム tID が 問題 pID に誤答するプログラムを送信。 </td><td style="padding: .5em; background: #0cf"> チーム tID の 問題 pID に対する誤答数に1が加算される。 </td></tr></tbody>
</table>
<p>
※上記のシステムログはこの問題のために簡略化されたものであり、本番のICPCで見られるシステムログと異なることに留意せよ
</p>
<p>
iCPCにおける順位付けのルールは以下の通りである。
</p>
<ul>
<li>より多くの問題を解いたチームは順位が上になる</li>
<li>解いた問題が同じ場合、ペナルティの少ないチームのほうが順位が上になる</li>
<li>解いた問題もペナルティも同じ場合、チーム番号が小さいほうのチームが順位が上になる</li>
</ul>
<p>
入力より与えられるコンテストの情報・システムログから各チームの成績を割り出し、チームの順位表を出力せよ。
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
入力は複数のデータセットからなる。各データセットは以下の形式で与えられる。
</p>
<blockquote>
<var>T</var> <var>P</var> <var>R</var><br/>
<var>tID<sub>1</sub></var> <var>pID<sub>1</sub></var> <var>time<sub>1</sub></var> <var>message<sub>1</sub></var><br/>
<var>tID<sub>2</sub></var> <var>pID<sub>2</sub></var> <var>time<sub>2</sub></var> <var>message<sub>2</sub></var><br/>
<var>...</var><br/>
<var>tID<sub>R</sub></var> <var>pID<sub>R</sub></var> <var>time<sub>R</sub></var> <var>message<sub>R</sub></var><br/>
</blockquote>
<p>
データセットの1行目には 参加チーム数 T 、問題数 P、システムログのレコード数 R が含まれる。
</p>
<p>
続くR行にはシステムログの各レコードが含まれる。
</p>
<p>
システムログのレコードとして、チーム番号 tID<sub>i</sub>、問題番号 pID<sub>i</sub>、試合開始からの経過時間 time<sub>i</sub>、メッセージの種類 message<sub>i</sub> が含まれる。
</p>
<p>
入力は以下の制約を満たす。
</p>
<ul>
<li>1 ≤ T ≤ 50</li>
<li>1 ≤ P ≤ 10</li>
<li>1 ≤ R ≤ 500</li>
<li>1 ≤ tID<sub>i</sub> ≤ T</li>
<li>1 ≤ pID<sub>i</sub> ≤ P</li>
<li>1 ≤ time<sub>i</sub> ≤ 10800</li>
<li>message<sub>i</sub> は CORRECT, WRONGのいずれか</li>
<li>システムログのレコードは、時刻の小さいものから順に与えられ、複数のレコードの時刻が同じになることはない</li>
</ul>
<p>
入力の終わりはスペースで区切られた3個の0で与えられる。
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
与えられたシステムログより各チームの成績・順位を割り出し、順位が上のチームから順に、チーム番号、正解数、ペナルティ を出力せよ。
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3 3 5
3 1 800 WRONG
1 1 1200 CORRECT
3 1 1400 CORRECT
1 2 2400 CORRECT
1 3 3600 CORRECT
5 2 5
3 1 1000 WRONG
5 2 2000 CORRECT
3 1 2800 CORRECT
4 1 4000 CORRECT
5 1 5000 CORRECT
6 3 15
2 1 10 WRONG
3 3 15 WRONG
3 3 20 CORRECT
1 1 50 CORRECT
4 2 60 WRONG
1 2 70 WRONG
4 1 80 CORRECT
1 2 90 WRONG
1 2 150 CORRECT
3 1 160 WRONG
3 1 180 CORRECT
3 2 210 WRONG
5 3 500 CORRECT
4 2 720 CORRECT
5 1 1500 CORRECT
0 0 0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div>
<h3>Output for Sample Input</h3>
<div>
<pre>
1 3 7200
3 1 2600
2 0 0
5 2 7000
3 1 4000
4 1 4000
1 0 0
2 0 0
4 2 2000
5 2 2000
1 2 2600
3 2 2600
2 0 0
6 0 0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div> |
p03207 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some other world, today is the day before Christmas Eve.</p>
<p>Mr. Takaha is buying <var>N</var> items at a department store. The regular price of the <var>i</var>-th item <var>(1 \leq i \leq N)</var> is <var>p_i</var> yen (the currency of Japan).</p>
<p>He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining <var>N-1</var> items cost their regular prices. What is the total amount he will pay?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10</var></li>
<li><var>100 \leq p_i \leq 10000</var></li>
<li><var>p_i</var> is an even number.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var>
<var>p_2</var>
<var>:</var>
<var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total amount Mr. Takaha will pay.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4980
7980
6980
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>15950
</pre>
<p>The <var>7980</var>-yen item gets the discount and the total is <var>4980 + 7980 / 2 + 6980 = 15950</var> yen.</p>
<p>Note that outputs such as <code>15950.0</code> will be judged as Wrong Answer.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
4320
4320
4320
4320
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>15120
</pre>
<p>Only one of the four items gets the discount and the total is <var>4320 / 2 + 4320 + 4320 + 4320 = 15120</var> yen.</p></section>
</div>
</span> |
p04038 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves colorful balls. He has a total of <var>N×K</var> balls, <var>K</var> in each of his favorite <var>N</var> colors. The colors are numbered <var>1</var> through <var>N</var>.</p>
<p>He will arrange all of the balls in a row from left to right, in arbitrary order. Then, for each of the <var>N</var> colors, he will paint the leftmost ball of that color into color <var>0</var>, a color different from any of the <var>N</var> original colors.</p>
<p>After painting, how many sequences of the colors of the balls are possible? Find this number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N,K≤2,000</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible sequences of the colors of the balls after painting, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The following <var>4</var> sequences are possible:</p>
<ul>
<li><var>(0,1,0,2)</var></li>
<li><var>(0,0,1,2)</var></li>
<li><var>(0,2,0,1)</var></li>
<li><var>(0,0,2,1)</var></li>
</ul>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>The following <var>1</var> sequence is possible:</p>
<ul>
<li><var>(0,0,0)</var></li>
</ul>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>14
</pre>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2000 2000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>546381702
</pre></section>
</div>
</hr></hr></hr></hr></hr></span> |
p03657 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is giving cookies to his three goats.</p>
<p>He has two cookie tins. One contains <var>A</var> cookies, and the other contains <var>B</var> cookies. He can thus give <var>A</var> cookies, <var>B</var> cookies or <var>A+B</var> cookies to his goats (he cannot open the tins).</p>
<p>Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A,B \leq 100</var></li>
<li>Both <var>A</var> and <var>B</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to give cookies so that each of the three goats can have the same number of cookies, print <code>Possible</code>; otherwise, print <code>Impossible</code>.</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>Possible
</pre>
<p>If Snuke gives nine cookies, each of the three goats can have three cookies.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Impossible
</pre>
<p>Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.</p></section>
</div>
</span> |
p02945 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two integers: <var>A</var> and <var>B</var>.</p>
<p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>-100 \leq A,\ B \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>-13 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-10
</pre>
<p>The largest number among <var>A + B = -10</var>, <var>A - B = -16</var>, and <var>A \times B = -39</var> is <var>-10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 -33
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>34
</pre>
<p>The largest number among <var>A + B = -32</var>, <var>A - B = 34</var>, and <var>A \times B = -33</var> is <var>34</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>13 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>39
</pre>
<p>The largest number among <var>A + B = 16</var>, <var>A - B = 10</var>, and <var>A \times B = 39</var> is <var>39</var>.</p></section>
</div>
</span> |
p00978 | <h2>Sixth Sense</h2>
<p>
Ms. Future is gifted with precognition. Naturally, she is excellent at some card games since she can correctly foresee every player's actions, except her own. Today, she accepted a challenge from a reckless gambler Mr. Past. They agreed to play a simple two-player trick-taking card game.
</p>
<p>
Cards for the game have a number printed on one side, leaving the other side blank making indistinguishable from other cards.
</p>
<p>
A game starts with the same number, say $n$, of cards being handed out to both players, without revealing the printed number to the opponent.
</p>
<p>
A game consists of $n$ tricks. In each trick, both players pull one card out of her/his hand. The player pulling out the card with the larger number takes this trick. Because Ms. Future is extremely good at this game, they have agreed to give tricks to Mr. Past when both pull out cards with the same number. Once a card is used, it can never be used later in the same game. The game continues until all the cards in the hands are used up. The objective of the game is to take as many tricks as possible.
</p>
<p>
Your mission of this problem is to help Ms. Future by providing a computer program to determine the best playing order of the cards in her hand. Since she has the sixth sense, your program can utilize information that is not available to ordinary people before the game.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$
$p_1$ ... $p_n$
$f_1$ ... $f_n$
</pre>
<p>
$n$ in the first line is the number of tricks, which is an integer between 2 and 5000, inclusive. The second line represents the Mr. Past's playing order of the cards in his hand. In the $i$-th trick, he will pull out a card with the number $p_i$ ($1 \leq i \leq n$). The third line represents the Ms. Future's hand. $f_i$ ($1 \leq i \leq n$) is the number that she will see on the $i$-th received card from the dealer. Every number in the second or third line is an integer between 1 and 10 000, inclusive. These lines may have duplicate numbers.
</p>
<h3>Output</h3>
<p>
The output should be a single line containing $n$ integers $a_1 ... a_n$ separated by a space, where $a_i$ ($1 \leq i \leq n$) is the number on the card she should play at the $i$-th trick for maximizing the number of taken tricks. If there are two or more such sequences of numbers, output the lexicographically greatest one among them.
</p>
<h3>Sample Input 1</h3>
<pre>
5
1 2 3 4 5
1 2 3 4 5
</pre>
<h3> Sample Output 1</h3>
<pre>
2 3 4 5 1
</pre>
<h3>Sample Input 2</h3>
<pre>
5
3 4 5 6 7
1 3 5 7 9
</pre>
<h3>Sample Output 2</h3>
<pre>
9 5 7 3 1
</pre>
<h3>Sample Input 3</h3>
<pre>
5
3 2 2 1 1
1 1 2 2 3
</pre>
<h3>Sample Output 3</h3>
<pre>
1 3 1 2 2
</pre>
<h3>Sample Input 4</h3>
<pre>
5
3 4 10 4 9
2 7 3 6 9
</pre>
<h3> Sample Output 4</h3>
<pre>
9 7 3 6 2
</pre>
|
p01390 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">問題 C </font> しりとり</h1>
<h2>問題文</h2>
<p>なんとなく暇だったのでしりとりの AI を作って AI としりとりをすることにした.しりとりとは <var>2</var> 人で遊ぶゲームで,両者の間でまだ一度も発言されておらず,(最初の手番を除いて) 先頭の文字が直前の単語の最後の文字となっている単語を交互に言い合うゲームである.</p>
<p>今回 AI に単語の判定を実装するのが面倒だったので,単語の定義はアルファベットの小文字からなる文字列全てとした.</p>
<p>しかし AI が完成したあたりでしりとりをするのは面倒くさくなってきたので,プログラムを書いて自分の代わりに AI と対戦させることにした.プログラムを書くのは良いのだが目標が無いのはつまらないので,なるべく早く AI に勝つプログラムを書くことにした.すなわち,なるべく少ないやりとりで AI に不正な応答をさせるプログラムを書くのである.</p>
<p>なおプログラムが先手で AI が後手である.</p>
<h2>入出力</h2>
<p>プログラムはしりとりの単語を発言すると,AI の返答を聞くことができる.
例えば C/C++ で <tt>abc</tt> と単語を発言するには</p>
<pre>printf("?abc\n"); fflush(stdout);</pre>
<p>とする.次に,</p>
<pre>scanf("%s", str);</pre>
<p>とすると <var>str</var> に AI の返答が入る.</p>
<p>最終的に AI の誤りを指摘するには <tt>!OUT</tt> と出力すること.誤りを指摘するのは,間違った発言の直後でなければならない.誤りを指摘した時点でプログラムを終了させ,不要な出力は一切行ってはいけない.誤りの指摘が正しければプログラムは正解 (<i>Accepted</i>) と判定される.単語の応答が不適切であったり,AI への誤りの指摘が正しくない場合,AI の誤りを指摘しなかった場合は誤答 (<i>Wrong Answer</i>) と判定される.</p>
<h2>制約</h2>
<ul>
<li>プログラムの使って良い単語の長さは <var>1</var> 文字以上 <var>10</var> 文字以下である.</li>
<li>AI の使う単語の長さは <var>1</var> 文字以上 <var>2</var> 文字以下である.</li>
<li>プログラムは最大で <var>50</var> 回まで発言することが出来る.それを超えると誤答 (<i>Query Limit Exceeded</i>) となる.</li>
<li>AI,プログラム両者とも単語に使って良い文字はアルファベットの小文字のみである. </li>
<li>AI の返答はアルファベットの小文字のみからなる.</li>
<li>最初の手番では,プログラムはどのアルファベットからしりとりを開始しても良い.</li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<p>
以下の例はプログラムの入出力の例である.左の列がプログラムの出力,右の列がプログラムへの入力 (AI の発言) を表す.最初にプログラムは <tt>abcdefghij</tt> という単語を言っている.その応答として AI は <tt>jk</tt> と返してる.<var>3</var> 回目の応答の際に AI はすでに使われている <tt>jk</tt> という単語を発しているのでそれに対してプログラムは <tt>!OUT</tt> と言って AI の誤りを指摘している.
</p>
<div class="reactive-example">
<table class="withborder">
<tr><th>プログラムの出力</th><th>プログラムへの入力</th></tr>
<tr><td>?abcdefghij</td><td></td></tr>
<tr><td></td><td>jk</td></tr>
<tr><td>?kkkk</td><td></td></tr>
<tr><td></td><td>kl</td></tr>
<tr><td>?lj</td><td></td></tr>
<tr><td></td><td>jk</td></tr>
<tr><td>!OUT</td><td></td></tr>
</table>
</div>
<br>
<h3>入力例 2</h3>
<p>
以下の例では,AI が <tt>aaa</tt> という単語に対して <tt>bb</tt> としりとりにならない返答をしているため <tt>!OUT</tt> と返している.
</p>
<div class="reactive-example">
<table class="withborder">
<tr><th>プログラムの出力</th><th>プログラムへの入力</th></tr>
<tr><td>?aaa</td><td></td></tr>
<tr><td></td><td>bb</td></tr>
<tr><td>!OUT</td><td></td></tr>
</table>
</div>
<br>
|
p02416 |
<H1>Sum of Numbers</H1><br>
<p>
Write a program which reads an integer and prints sum of its digits.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. For each dataset, an integer <var>x</var> is given in a line. The number of digits in <var>x</var> does not exceed 1000.
</p>
<p>
The input ends with a line including single zero. Your program should not process for this terminal symbol.
</p>
<H2>Output</H2>
<p>
For each dataset, print the sum of digits in <var>x</var>.
</p>
<H2>Sample Input</H2>
<pre>
123
55
1000
0
</pre>
<H2>Sample Output</H2>
<pre>
6
10
1
</pre>
|
p02046 | <h3>避けるべし</h3>
<!-- begin ja only -->
<p>あなたはいま,上下左右に広大に広がるマス目の原点に当たる位置 <i>(0, 0)</i> にいる.マスの位置は<i>x</i>座標と<i>y</i>座標で表され,右に1マス動くことが<i>x</i>座標が1つ増えることに対応し,上に1マス動くことが<i>y</i>座標が1つ増えることに対応する.あなたはこれから目的地であるマス <i>(x, y)</i> を目指して出発するところだ.あなたは 1 歩で上下左右斜めの 8 方向に隣接するマスに移動することができる.</p>
<p>さあ,目的地に向かって移動開始だ!とあなたは意気込んでいるところかもしれないが,ちょっと待ってほしい.一つだけ先に忠告しておくことがある.それはこのマス目に潜む謎の人物,回り込みのプロ・廻小宮の存在だ.廻小宮はあなたが 1 歩移動したのを確認すると,あなたが進んだ方向のさらに 1 歩先のマスに瞬時に移動し,邪魔をしてくる.より正確に言えば,あなたがマス <i>(x<sub>s</sub>, y<sub>s</sub>) </i>から <i>(x<sub>t</sub>, y<sub>t</sub>)</i> に移動するとき,廻小宮は <i>(x<sub>t</sub> + (x<sub>t</sub> - x<sub>s</sub>), y<sub>t</sub> + (y<sub>t</sub> - y<sub>s</sub>))</i> に移動する.明らかに異様な雰囲気を醸し出す廻小宮.ヤツの間合いに入り込むのは危険だ.回り込まれた直後は仕方ないとして,次に移動する先のマス,あるいはその 8 方向に隣接するマスのどれかに廻小宮がすでにいると,ヤツの間合いに入り込んでしまうことになるので,これはどうしても避けたい.</p>
<p>上記のように廻小宮の間合いを避けつつ,目的地に辿り着くためには最小で何歩必要だろうか?あなたの仕事はこの最小歩数を求めるプログラムを書くことだ.ただし,廻小宮は初期状態ではどのマスにも存在せず,最初の 1 歩目以降から上記のルールに従ったマスに現れるものとする.</p>
<p>最初のサンプルでは,あなたは <i>(2, 0)</i> を目指す.例えば最初に右横のマス<i>(1, 0)</i> に移動してしまうと,廻小宮が <i>(2, 0)</i> に回り込んでくるため,次にそのマスへと移動することができない.一方,最初に右斜め上の <i>(1, 1)</i> に移動すると,廻小宮の位置は <i>(2, 2)</i> となり <i>(2, 0)</i> が廻小宮の間合いではないため,次の 1 歩で <i>(2, 0)</i> に移動することができる.</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2019_C" width="600pt"></center></p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>入力は複数のデータセットからなる. 各データセットは 2 つの整数 <i>x</i>, <i>y</i> からなる 1 行で表される.これは目的地のマスが位置 <i>(x, y)</i> であることを表し,<i>|x|, |y| ≤ 10<sup>9</sup></i> を満たす.</p>
<p>入力の終わりは EOF (ファイルの終端) で表される. 全データセットの総数は 50 を超えない.</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>条件を満たすように移動を繰り返すとき,マス <i>(0, 0)</i> からマス <i>(x, y)</i> に移動するために必要な最小歩数を 1 行に出力せよ.</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>2 0
2 2
1 -1
0 0
0 -5
173 207
</pre><h3>Output for the Sample Input</h3><pre>2
4
1
0
6
379
</pre>
|
p00581 | <h1>勇者ビ太郎(Bitaro the Brave)</h1>
<p>
勇者のビ太郎は,魔王と対峙することとなった.
</p>
<p>
ビ太郎は,縦$H$ 行,横$W$ 列のマス目上に宝石(Jewel),オーブ(Orb),金塊(Ingot) を配置し,魔法を発動することによって魔王に攻撃をしようとしている.以下,マス目のうち上から$i$ 行目($1 \leq i \leq H$),左から$j$ 列目($1 \leq j \leq W$) のマスを,マス($i, j$) と表す.
</p>
<p>
ビ太郎は今,それぞれのマスにこれら3 種類のうち1 個を配置した.今から魔法を発動しようとしているが,この魔法の威力はマス目上の宝石,オーブ,金塊の配置によって決まる.具体的には,次の条件を満たす整数($i, j, k, l$) ($1 \leq i < k \leq H, 1 \leq j < l \leq W$) の組の個数が,魔法の威力である.<br/>
<br/>
条件:マス($i, j$) には宝石が,マス($i, l$) にはオーブが,マス($k, j$) には金塊が置かれている.<br/>
</p>
<p>
ビ太郎は,この魔法の威力が気になっている.
</p>
<p>
マス目上の宝石,オーブ,金塊の配置が与えられたとき,ビ太郎が発動する魔法の威力を求めるプログラムを作成せよ.
</p>
<h2>入力</h2>
<p>
入力は以下の形式で標準入力から与えられる.
</p>
<pre>
$H$ $W$
$S_1$
:
$S_H$
</pre>
<p>
$S_i$ ($1 \leq i \leq H$) は長さ$W$ の文字列で,その$j$ 文字目($1 \leq j \leq W$) がJ のときはマス($i, j$) に宝石が,O の ときはマス($i, j$) にオーブが,I のときはマス($i, j$) に金塊が置かれていることを表す.
</p>
<h2>出力</h2>
<p>
標準出力に,魔法の威力を表す整数を1 行で出力せよ.
</p>
<h2>制約</h2>
<ul>
<li>$2 \leq H \leq 3 000$.</li>
<li>$2 \leq W \leq 3 000$.</li>
<li>$S_i$ は長さ$W$ の文字列である($1 \leq i \leq H$).</li>
<li>$S_i$ の各文字はJ,O,I のいずれかである($1 \leq i \leq H$).</li>
</ul>
<!--
小課題
1. (20 点) H ≦ 100,W ≦ 100.
2. (30 点) H ≦ 500,W ≦ 500.
3. (50 点) 追加の制約はない.
-->
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
3 4
JOIJ
JIOO
IIII
</pre>
<h3>出力例1</h3>
<pre>
3
</pre>
<p>この入力例では,($i, j, k, l$) = (1, 1, 3, 2), (2, 1, 3, 3), (2, 1, 3, 4) の3 個の組が条件を満たすので,答えは3 である.
</p>
<h3>入力例2 </h3>
<pre>
4 4
JJOO
JJOO
IIJO
IIIJ
</pre>
<h3>出力例2</h3>
<pre>
17
</pre>
<br/>
<p>
<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>
<br/>
<a href="https://www.ioi-jp.org/joi/2018/2019-ho/index.html">情報オリンピック日本委員会作 『第18 回日本情報オリンピック(JOI 2018/2019) 本選』</a>
</p>
|
p00094 |
<H1>坪面積の計算</H1>
<p>
土地の面積を表現する「○○坪」という単位を聞いたことはないでしょうか? 古来、1人の武士が1日に食べるお米を作る面積を言いました。
</p>
<p>
<var>a</var>[m]× <var>b</var>[m]の土地があります。<var>a</var> と <var>b</var> を入力し、その土地の坪面積 <var>S</var>[坪]を出力するプログラムを作成してください。 1 坪 = 3.305785 [m<sup>2</sup>] とし、<var>a</var> と <var>b</var> は 100 以下の整数とします。
</p>
<H2>入力</H2>
<pre>
<var>a</var> <var>b</var>
</pre>
<p>
1つの空白で区切られた <var>a</var> と <var>b</var> が1行に与えられる。
</p>
<H2>出力</H2>
<p>
坪面積 <var>S</var> を1行に出力する。0.0001 以下の誤差が許される。
</p>
<H2>入力例1</H2>
<pre>
15 25
</pre>
<H2>出力例1</H2>
<pre>
113.437508
</pre>
|
p02553 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are integers <var>a,b,c</var> and <var>d</var>.
If <var>x</var> and <var>y</var> are integers and <var>a \leq x \leq b</var> and <var>c\leq y \leq d</var> hold, what is the maximum possible value of <var>x \times y</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>-10^9 \leq a \leq b \leq 10^9</var></li>
<li><var>-10^9 \leq c \leq d \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var> <var>c</var> <var>d</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>1 2 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If <var>x = 1</var> and <var>y = 1</var> then <var>x \times y = 1</var>.
If <var>x = 2</var> and <var>y = 1</var> then <var>x \times y = 2</var>.
Therefore, the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5 -4 -2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-6
</pre>
<p>The answer can be negative.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>-1000000000 0 -1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000000000000000
</pre></section>
</div>
</span> |
p02103 |
<h1>Problem F: Great Devil Sakanikia</h1>
<h2>Problem</h2>
<p>
大悪魔サカーニャは今日も天敵の猫に襲われていた。<br>
いつもやられている訳にはいかないので、秘密兵器を購入した。<br>
この秘密兵器は、巨大な岩を生成することで猫の移動経路を塞ぎ、猫がこちらに近づけないようにすることができる。<br>
</p>
<p>
今、サカーニャと一匹の猫がマス(0,0),(<var>n</var>−1,0),(<var>n</var>−1,<var>m</var>−1),(0,<var>m</var>−1)で囲まれた長方形の閉区間内にいる。<br>
マス(0,0)に猫、マス(<var>n</var>−1,<var>m</var>−1)にサカーニャがいる。<br>
猫は上下左右の隣接したマスに移動することができるが、区間外に出ることはできない。<br>
いくつかのマスは、穴や障害物の影響で侵入することができない。<br>
サカーニャは、あるマスに1つ岩を生成することでそのマスに猫が侵入できなくすることができる。<br>
ただし、マス(0,0)とマス(<var>n</var>−1,<var>m</var>−1)に岩を生成することはできない。
</p>
<p>
マス(0,0)からマス(<var>n</var>−1,<var>m</var>−1)までの移動経路を塞ぐために必要な、生成する岩の数の最小値を求めよ。
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var> <var>k</var>
<var>x</var><sub>1</sub> <var>y</var><sub>1</sub>
...
<var>x<sub>k</sub></var> <var>y<sub>k</sub></var>
</pre>
<p>
入力はすべて整数で与えられる。<br>
1行目にマスの大きさを表す2つの整数<var>n</var>と<var>m</var>、侵入できないマスの数<var>k</var>が空白区切りで与えられる。<br>
2行目から<var>k</var>行に侵入できないマスの座標が与えられる。
</p>
<h2>Constraints</h2>
<p>
入力は以下の条件を満たす。
</p>
<ul>
<li>2 ≤ <var>n</var>,<var>m</var> ≤ 10<sup>5</sup></li>
<li>0 ≤ <var>k</var> ≤ min(<var>n</var>×<var>m</var>−2,10<sup>5</sup>)</li>
<li>0 ≤ <var>x<sub>i</sub></var> ≤ <var>n</var> − 1</li>
<li>0 ≤ <var>y<sub>i</sub></var> ≤ <var>m</var> − 1</li>
<li>(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>) ≠ (<var>x<sub>j</sub></var>,<var>y<sub>j</sub></var>) (<var>i</var> ≠ <var>j</var>)</li>
<li>(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>) ≠ (0,0) ≠ (<var>n</var>−1,<var>m</var>−1)</li>
</ul>
<h2>Output</h2>
<p>
マス(0,0)からマス(<var>n</var>−1,<var>m</var>−1)までの移動経路を塞ぐために必要な、生成する岩の数の最小値を1行に出力せよ。<br>
</p>
<h2>Sample Input 1</h2>
<pre>
3 5 2
0 2
2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5 3
0 2
2 2
4 1
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre> |
p01685 |
<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>Problem Statement</h3>
<p>You have a rectangular board with square cells arranged in $H$ rows and $W$ columns.
The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right.
The cell at the row $i$ and the column $j$ is denoted by $(i, j)$.
Each cell on the board is colored in either Black or White.
</p>
<p>You will paint the board as follows:
</p><ol><li><p> Choose a cell $(i, j)$ and a color $c$, each uniformly at random, where $1 \le i \le H$, $1 \le j \le W$, and $c \in \{{\rm Black}, {\rm White}\}$.
</p></li><li><p> Paint the cells $(i', j')$ with the color $c$ for any $1 \le i' \le i$ and $1 \le j' \le j$.
</p></li></ol>
<p>Here's an example of the painting operation.
You have a $3 \times 4$ board with the coloring depicted in the left side of the figure below.
If your random choice is the cell $(2, 3)$ and the color Black, the board will become as shown in the right side of the figure.
$6$ cells will be painted with Black as the result of this operation.
Note that we count the cells "painted" even if the color is not actually changed by the operation, like the cell $(1, 2)$ in this example.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2013_fig_overwrite" height="175" width="640" /><br/>
Fig: An example of the painting operation
</center>
<br/>
<p>Given the initial coloring of the board and the desired coloring, you are supposed to perform the painting operations repeatedly until the board turns into the desired coloring.
Write a program to calculate the expected total number of painted cells in the sequence of operations.
</p>
<h3>Input</h3>
<p>The input consists of several datasets. The number of datasets is at most $100$.
</p>
<p>The first line of each dataset contains two integers $H$ and $W$ ($1 \le H, W \le 5$), the numbers of rows and columns of the board respectively.
Then given are two coloring configurations of the board, where the former is the initial coloring and the latter is the desired coloring.
A coloring configuration is described in $H$ lines, each of which consists of $W$ characters. Each character is either B or W, denoting a Black cell or a White cell, respectively.
There is one blank line between two configurations, and also after each dataset.
You can assume that the resulting expected value for each dataset will not exceed $10^9$.
</p>
<p>The input is terminated by a line with two zeros, and your program should not process this as a dataset.
</p>
<h3>Output</h3>
<p>For each dataset, your program should output the expected value in a line. The absolute error or the relative error in your answer must be less than $10^{-6}$.
</p>
<h3>Sample Input</h3>
<pre>1 2
BB
WW
2 1
B
W
B
W
2 2
BW
BW
WW
WW
3 4
BBBB
BBBB
BBBB
WWWW
WWWW
WWWW
5 5
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB
BBBWB
BBBBB
BWBBB
BBBBB
0 0</pre>
<h3>Output for the Sample Input</h3>
<pre>6.0000000000
0.0000000000
12.8571428571
120.0000000000
23795493.8449918639</pre> |
p00997 |
<h1>Problem H : Dungeon (II)</h1>
<p>
あなたはとあるゲームの開発に携わっている。
そのゲームはランダムに生成されたダンジョンをプレイヤーが探索するというものである。
ゲームの仕様として、プレイヤーに予めダンジョンの危険度を提示し、生成されたダンジョンを探索するのか、それとも新しくダンジョンを生成しなおすかを、選択できるようにしたい。
</p>
<p>
このゲームで生成されるダンジョンには<i>n</i> 個の部屋が存在しており、0から <i>n-1</i> までの番号が割り振られている。
部屋と部屋は通路で結ばれている。部屋と部屋を結ぶ通路は、合計で <i>n-1</i> 本存在している。
通路はどちらの方向へも進むことができる。
また、部屋と部屋の間には距離が設定されている。
生成されたダンジョンではいくつかの通路を経由して、ある部屋から他のすべての部屋へ行くことが可能である。
そして、プレイヤーがゲームを行う際に、2つの異なる部屋がスタート地点とゴール地点として選ばれる。
</p>
<p>
あなたはダンジョンの評価を行うために、危険度の評価方法を決めることにした。
まず、ある部屋から別の部屋までに移動する際の危険度を、部屋間を最短で移動するために使う通路の中で、最もコスト高い通路の値とする。
そして、ダンジョンの危険度を、<i>i</i> < <i>j</i> となる部屋のペアの間を移動する際の危険度の総和とすることにした。
</p>
<p>
ランダムに生成されたダンジョンのが入力として与えられる。
まず、<i>i</i> < <i>j</i> となるすべての部屋のペアについて、移動する際の危険度を計算して欲しい。
そして、その総和を問題の答えとして出力せよ。
</p>
<h2>Input</h2>
<p>
入力は以下のフォーマットで与えられる。
</p>
<pre>
<i>n</i>
<i>a<sub>1</sub></i> <i>b<sub>1</sub></i> <i>c<sub>1</sub></i>
.
.
.
<i>a<sub>n-1</sub></i> <i>b<sub>n-1</sub></i> <i>c<sub>n-1</sub></i>
</pre>
<p>
<i>a<sub>i</sub></i> <i>b<sub>i</sub></i> <i>c<sub>i</sub></i> は 部屋 <i>a<sub>i</sub></i> と <i>b<sub>i</sub></i> を結ぶ通路の距離が<i>c<sub>i</sub></i>であることを表す。
</p>
<p>
入力は以下の制約を満たす<br>
2 ≤ <i>n</i> ≤ 200,000 <br>
0 ≤ <i>a<sub>i</sub></i>,<i>b<sub>i</sub></i> < <i>n</i><br>
0 ≤ <i>c<sub>i</sub></i> ≤ 100,000<br>
</p>
<h2>Output</h2>
<p>
答えの値を1行に出力せよ
</p>
<h2>Sample Input 1</h2>
<pre>
4
0 1 3
1 2 5
1 3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
23
</pre>
<h2>Sample Input 2</h2>
<pre>
6
0 2 5
2 1 1
2 3 10
3 5 4
3 4 2
</pre>
<h2>Sample Output 2</h2>
<pre>
111
</pre>
|
p03342 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an integer sequence <var>A</var> of length <var>N</var>.</p>
<p>Find the number of the pairs of integers <var>l</var> and <var>r</var> (<var>1 \leq l \leq r \leq N</var>) that satisfy the following condition:</p>
<ul>
<li><var>A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r</var></li>
</ul>
<p>Here, <var>xor</var> denotes the bitwise exclusive OR.</p>
<p><details>
<summary style="display:list-item">Definition of XOR</summary></details></p>
<p>The XOR of integers <var>c_1, c_2, ..., c_m</var> is defined as follows:</p>
<ul>
<li>Let the XOR be <var>X</var>. In the binary representation of <var>X</var>, the digit in the <var>2^k</var>'s place (<var>0 \leq k</var>; <var>k</var> is an integer) is <var>1</var> if there are an odd number of integers among <var>c_1, c_2, ...c_m</var> whose binary representation has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> if that number is even.</li>
</ul>
<p>For example, let us compute the XOR of <var>3</var> and <var>5</var>. The binary representation of <var>3</var> is <var>011</var>, and the binary representation of <var>5</var> is <var>101</var>, thus the XOR has the binary representation <var>110</var>, that is, the XOR is <var>6</var>.</p>
<p></p></section></div></span> |
p03712 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a image with a height of <var>H</var> pixels and a width of <var>W</var> pixels.
Each pixel is represented by a lowercase English letter.
The pixel at the <var>i</var>-th row from the top and <var>j</var>-th column from the left is <var>a_{ij}</var>.</p>
<p>Put a box around this image and output the result. The box should consist of <code>#</code> and have a thickness of <var>1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ H, W ≤ 100</var></li>
<li><var>a_{ij}</var> is a lowercase English letter.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{11}</var> <var>...</var> <var>a_{1W}</var>
<var>:</var>
<var>a_{H1}</var> <var>...</var> <var>a_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the image surrounded by a box that consists of <code>#</code> and has a thickness of <var>1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
abc
arc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>#####
#abc#
#arc#
#####
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>###
#z#
###
</pre></section>
</div>
</span> |
p02800 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>H \times W</var> grid, where each square is painted white or black in the initial state.
Given are strings <var>A_1, A_2, ..., A_H</var> representing the colors of the squares in the initial state.
For each pair <var>(i, j)</var> (<var>1 \leq i \leq H</var>, <var>1 \leq j \leq W</var>), if the <var>j</var>-th character of <var>A_i</var> is <code>.</code>, the square at the <var>i</var>-th row and <var>j</var>-th column is painted white; if that character is <code>#</code>, that square is painted black.</p>
<p>Among the <var>2^{HW}</var> ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo <var>998,244,353</var>.</p>
<ul>
<li>Choose one row, then paint all the squares in that row white.</li>
<li>Choose one row, then paint all the squares in that row black.</li>
<li>Choose one column, then paint all the squares in that column white.</li>
<li>Choose one column, then paint all the squares in that column black.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H, W \leq 10</var></li>
<li><var>|A_i| = W</var> (<var>1 \leq i \leq H</var>)</li>
<li>All strings <var>A_i</var> consist of <code>.</code> and <code>#</code>.</li>
<li><var>H</var> and <var>W</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>A_1</var>
<var>A_2</var>
<var>\vdots</var>
<var>A_H</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 2
#.
.#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>15
</pre>
<p>For example, if we paint the second row black, the grid becomes:</p>
<pre>#.
##
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
...
...
...
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>230
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 4
#...
...#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>150
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6 7
.......
.......
.#.....
..#....
.#.#...
.......
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>203949910
</pre></section>
</div>
</span> |
p00217 |
<H1>ウォーキング</H1>
<p>
会津リバーサイドホスピタルでは、リハビリと健康増進のため、入院患者が一日二回のウォーキングを行っています。元気に退院するために、ウォーキングで体力を回復しようと頑張る人が日に日に増えきたことから、院長が「一日で一番長い距離を歩いた人にプレゼントをあげよう!」という企画を立ち上げました。
</p>
<!--
<p>
会津リバーサイドホスピタルでは、リハビリと健康増進のため、入院患者が一日二回のウォーキングを行っています。元気に退院するために、ウォーキングで体力を回復しようと頑張る人が日に日に増えていきました。健康になるにつれ、気持ちも明るく笑顔も見られるようになったことから、院長先生が、 「一日で一番長い距離を歩いた人にプレゼントをあげよう!」という企画を立ち上げました。
</p>
-->
<p>
患者の数 <var>n</var> (1 ≤ <var>n</var> ≤ 10000)、それぞれの患者の番号 <var>p<sub>i</sub></var> (1 ≤ <var>p<sub>i</sub></var> ≤ 10000)、一回目に歩いた距離 <var>d1<sub>i</sub></var>、二回目に歩いた距離 <var>d2<sub>i</sub></var> (0 ≤ <var>d1<sub>i</sub></var>, <var>d2<sub>i</sub></var> ≤ 5000) を入力とし、歩いた距離の合計が最も長い患者の番号とその距離を出力するプログラムを作成してください。ただし、一日に歩いた距離が同じ患者はいないものとします。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>p<sub>1</sub></var> <var>d1<sub>1</sub></var> <var>d2<sub>1</sub></var>
<var>p<sub>2</sub></var> <var>d1<sub>2</sub></var> <var>d2<sub>2</sub></var>
:
<var>p<sub>n</sub></var> <var>d1<sub>n</sub></var> <var>d2<sub>n</sub></var>
</pre>
<p>
入力はすべて整数で与えられます。データセットの数は50 を超えません。
</p>
<H2>Output</H2>
<p>
入力データセットごとに、最も長い合計距離を歩いた患者の番号とその歩いた距離を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
5
263 2345 2504
1 3210 1985
5000 1501 4132
10000 503 3107
51 1758 2690
3
345 5000 2396
7 3910 1590
6789 2525 3616
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5000 5633
345 7396
</pre>
|
p02380 |
<H1>Triangle</H1><br>
<p>
For given two sides of a triangle <i>a</i> and <i>b</i> and the angle <i>C</i> between them, calculate the following properties:
</p>
<ul>
<li><var>S</var>: Area of the triangle</li>
<li><var>L</var>: The length of the circumference of the triangle</li>
<li><var>h</var>: The height of the triangle with side <var>a</var> as a bottom edge</li>
</ul>
<H2>Input</H2>
<p>
The length of <i>a</i>, the length of <i>b</i> and the angle <i>C</i> are given in integers.
</p>
<H2>Output</H2>
<p>
Print <var>S</var>, <var>L</var> and <var>h</var> in a line respectively. The output should not contain an absolute error greater than 10<sup>-4</sup>.
</p>
<H2>Sample Input</H2>
<pre>
4 3 90
</pre>
<H2>Sample Output</H2>
<pre>
6.00000000
12.00000000
3.00000000
</pre>
|
p03968 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer has <var>N</var> square tiles. The tiles are numbered <var>1</var> through <var>N</var>, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the <var>1000</var> colors, which are represented by the integers <var>0</var> between <var>999</var>. The top-left, top-right, bottom-right and bottom-left corner of the tile with the number <var>i</var> are painted in color <var>C_{i,0}, C_{i,1}, C_{i,2}</var> and <var>C_{i,3}</var>, respectively, when seen in the direction of the number written on the tile (See Figure <var>1</var>).</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/arc062/b8ec940254d280135500dab6d00d4370.png">
<p>Figure <var>1</var>: The correspondence between the colors of a tile and the input</p>
</img></div>
<p>AtCoDeer is constructing a cube using six of these tiles, under the following conditions:</p>
<ul>
<li>For each tile, the side with the number must face outward.</li>
<li>For each vertex of the cube, the three corners of the tiles that forms it must all be painted in the same color.</li>
</ul>
<p>Help him by finding the number of the different cubes that can be constructed under the conditions.
Since each tile has a number written on it, two cubes are considered different if the set of the used tiles are different, or the tiles are used in different directions, even if the formation of the colors are the same. (Each tile can be used in one of the four directions, obtained by <var>90°</var> rotations.) Two cubes are considered the same only if rotating one in the three dimensional space can obtain an exact copy of the other, including the directions of the tiles.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/arc062/8c7552f20698dab0aad52bba476fe6d7.png">
<p>Figure <var>2</var>: The four directions of a tile</p>
</img></div>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>6≦N≦400</var></li>
<li><var>0≦C_{i,j}≦999 (1≦i≦N , 0≦j≦3)</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>C_{1,0}</var> <var>C_{1,1}</var> <var>C_{1,2}</var> <var>C_{1,3}</var>
<var>C_{2,0}</var> <var>C_{2,1}</var> <var>C_{2,2}</var> <var>C_{2,3}</var>
<var>:</var>
<var>C_{N,0}</var> <var>C_{N,1}</var> <var>C_{N,2}</var> <var>C_{N,3}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different cubes that can be constructed under the conditions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
0 1 2 3
0 4 6 1
1 6 7 2
2 7 5 3
6 4 5 7
4 0 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The cube below can be constructed.</p>
<p><img alt="" src="https://atcoder.jp/img/arc062/094fbca5395bfaaea28c98c51230693b.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>144
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>122880
</pre></section>
</div>
</span> |
p01955 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>
Permutation Period
</H1>
<p>
You have a permutation $p$ of $N$ integers. Initially $p_i = i$ holds for $1 \leq i \leq N$. For each $j$ ($1 \leq j \leq N$), let's denote $p_{j}^0 = j$ and $p_{j}^k = p_{p_j}^{k-1}$ for any $k\geq 1$. The <i>period</i> of $p$ is defined as the minimum positive integer $k$ which satisfies $p_{j}^k = j$ for every $j$ ($1 \leq j \leq N$).
</p>
<p>
You are given $Q$ queries. The $i$-th query is characterized by two distinct indices $x_i$ and $y_i$. For each query, swap $p_{x_i}$ and $p_{y_i}$ and then calculate the period of updated $p$ modulo $10^9 + 7$ in the given order.
</p>
<p>
It can be proved that the period of $p$ always exists.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$N$ $Q$
$x_1$ $y_1$
...
$x_Q$ $y_Q$
</pre>
<p>
The first line consists of two integers $N$ and $Q$ ($2 \leq N \leq 10^5, 1 \leq Q \leq 10^5$). The ($i+1$)-th line consists of two integers $x_i$ and $y_i$ ($1 \leq x_i, y_i \leq N, x_i \ne y_i$).
</p>
<H2>Output</H2>
<p>
Print the answer in one line for each query.
</p>
<H2>Sample Input 1</H2>
<pre>
5 4
2 5
2 4
1 3
1 2
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
2
3
6
5
</pre>
<p>
$p$ changes as follows: $[1,2,3,4,5] \rightarrow [1,5,3,4,2] \rightarrow [1,4,3,5,2] \rightarrow [3,4,1,5,2] \rightarrow [4,3,1,5,2]$.
</p>
<H2>Sample Input 2</H2>
<pre>
2 2
1 2
1 2
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
2
1
</pre>
<p>
$p$ changes as follows: $[1,2] \rightarrow [2,1] \rightarrow [1,2]$.
</p>
<H2>Sample Input 3</H2>
<pre>
10 10
5 6
5 9
8 2
1 6
8 1
7 1
2 6
8 1
7 4
8 10
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
2
3
6
4
6
7
12
7
8
9
</pre>
|
p00647 |
<h1>Problem A: It's our delight!!</h1>
<p>
You are a student of University of Aizu.
And you work part-time at a restaurant.
</p>
<p>
Staffs of the restaurant are well trained to be delighted to provide more delicious products faster.
</p>
<p>
The speed providing products particularly depends on skill of the staff.
So, the manager of the restaurant want to know how long it takes to provide products.
</p>
<p>
Though some restaurants employ a system which calculates how long it takes to provide products automatically,
the restaurant where you work employs a system which calculates it manually.
</p>
<p>
You, a student of University of Aizu, want to write a program to calculate it, and you hope that your program makes the task easier.
You are given the checks in a day.
If the length of time it takes to provide the products of a check is shorter than or equal to 8 minutes, it is "ok" check.
Write a program to output the ratio of "ok" checks to the total in percentage.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets.
The last dataset is followed by a line containing a single zero.
You don't have to process this data.
The first line of each dataset contains a single integer <i>n</i>.
<p>
<i>n</i> (0 < <i> n </i> ≤ 100) is the number of checks.
Each of following <i> n </i> lines gives the details of a check in the following format.
<pre>
<i>hh:mm MM</i>
</pre>
<p>
<i>hh:mm</i> is the clock time to print the check.
<i>MM</i> is minute of the clock time to provide products.
The clock time is expressed according to the 24 hour clock.<br>
For example, "eleven one PM" is expressed by "23:01".<br>
You can assume that the all of products are provided within fifteen minutes.
The restaurant is open from AM 11:00 to AM 02:00.
After AM 02:00, no check is printed.
Also at AM 02:00, no check is printed.
</p>
<h2>Output</h2>
<p>
Your program has to print in the following format for each dataset.
</p>
<pre>
lunch <i>L</i>
dinner <i>D</i>
midnight <i>M</i>
</pre>
<p>
<i> L </i> is ratio of "ok" check printed to the total in lunch time.
<i> D </i> is ratio of "ok" check printed to the total in dinner time.
<i> M </i> is ratio of "ok" check printed to the total in midnight time.
You can truncate digits number after the decimal point of the ratio on the percentage. Lunch, dinner, and midnight times are defined as follows:
</p>
<pre>
Lunch time is 11:00 ~ 14:59.
Dinner time is 18:00 ~ 20:59.
Midnight time is 21:00 ~ 01:59.
</pre>
<p>
If a check is not printed in the three range of time, you don't have to process it.
If no check is in the range of time, you should print "no guest".
</p>
<h2>Sample input</h2>
<pre>
5
12:57 59
20:12 15
12:19 21
18:52 03
16:09 14
0
</pre>
<h2>Sample output</h2>
<pre>
lunch 100
dinner 50
midnight no guest
</pre>
<h2>Hint</h2>
<p>
If you want to read three integers in the following format,<br>
integer:integer(space)integer<br>
you can read them by scanf("%d%*c%d%d",&a, &b, &c); in C.
</p>
<!--
<hr>
<div class="dat" style="font-size:10pt">
The University of Aizu Programming Contest 2011<br>
Problemsetter: Tetsuya Shiota<br>
</div>
--> |
p01406 |
<h2>
Problem I: カスタムペイント職人
</h2>
<p>
slipはとあるレーシングゲームの動画が好きである。
といっても、車が走っている動画が好きであるわけではなく、このゲームに搭載されたカスタムペイントカー作成という機能によって、車体をカスタマイズする動画が好きなのである。
これは、円や多角形などといった基本的な幾何学図形を重ねあわせることで、車体にカスタムペイントができる機能である。
</p>
<p>
このカスタムペイントによって様々なアートを創りだす、いわゆる職人と呼ばれる人々がいる。
職人達の手にかかれば、車体にガリガリしたアイスキャンディーのキャラクターや、アイドルをプロデュースして楽しむゲームのキャラクターを創りだすことなど造作もない事である。
職人の車は、オークションで高値で取引をされるほどである。
</p>
<p>
その中でも、slipがお気に入りの職人がいる。
その職人は、扇形の図形のみで様々なアートを創り出している。
その職人は扇形を何枚も重ねあわせることで、自由自在に形を創り出している。
</p>
<p>
ある日slipは、職人が作るアートにおいて、扇形が一番多く重なっている部分で何枚あるのか気になりだした。
そこで、手作業で数えようと思ったのだが、枚数が多かったために諦めてしまった。
</p>
<p>
そこで、勝手に友人と思っているあなたに、プログラムを作ってもらうことにした。
あなたの仕事は、与えられた扇形の位置情報から、最大何枚の重なりがあるのか調べることである。
ここでは、扇形同士が接している場合も重なっているものとする。
</p>
<h2>
Input
</h2>
<p>
データセットの入力は以下の形式である。
</p>
<pre>
<i>n</i>
<i>m<sub>1</sub></i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>r<sub>1</sub></i> <i>s<sub>1</sub></i> <i>t<sub>1</sub></i>
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>r<sub>2</sub></i> <i>s<sub>2</sub></i> <i>t<sub>2</sub></i>
...
<i>x<sub>i</sub></i> <i>y<sub>i</sub></i> <i>r<sub>i</sub></i> <i>s<sub>i</sub></i> <i>t<sub>i</sub></i>
...
<i>x<sub>m<sub>1</sub></sub></i> <i>y<sub>m<sub>1</sub></sub></i> <i>r<sub>m<sub>1</sub></sub></i> <i>s<sub>m<sub>1</sub></sub></i> <i>t<sub>m<sub>1</sub></sub></i>
...
<i>m<sub>i</sub></i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>r<sub>1</sub></i> <i>s<sub>1</sub></i> <i>t<sub>1</sub></i>
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>r<sub>2</sub></i> <i>s<sub>2</sub></i> <i>t<sub>2</sub></i>
...
<i>x<sub>m<sub>i</sub></sub></i> <i>y<sub>m<sub>i</sub></sub></i> <i>r<sub>m<sub>i</sub></sub></i> <i>s<sub>m<sub>i</sub></sub></i> <i>t<sub>m<sub>i</sub></sub></i>
<i>m<sub>t</sub></i>
...
<i>x<sub>m<sub>t</sub></sub></i> <i>y<sub>m<sub>t</sub></sub></i> <i>r<sub>m<sub>t</sub></sub></i> <i>s<sub>m<sub>t</sub></sub></i> <i>t<sub>m<sub>t</sub></sub></i>
</pre>
<p>
<i>n</i>(<i>0 < n ≤ 50</i>)はテストケースの個数、
<i>m<sub>i</sub></i>(<i>0 < m<sub>i</sub> ≤ 16</i>)は貼られている扇形の枚数、
<i>x<sub>i</sub></i>(<i>0 ≤ x<sub>i</sub> ≤ 500</i>)は扇形の頂点のx座標、
<i>y<sub>i</sub></i>(<i>0 ≤ y<sub>i</sub> ≤ 500</i>)は扇形の頂点のy座標、
<i>r<sub>i</sub></i>(<i>0 < r<sub>i</sub> ≤ 100</i>)は扇形の半径、
<i>s<sub>i</sub></i>(<i>0 ≤ s<sub>i</sub> < 360</i>)は扇形の中心角の開始角度(degree)、
<i>t<sub>i</sub></i>(<i>0 ≤ t<sub>i</sub> < 360</i>)は扇形の中心角の終了角度(degree)
を表す。
</p>
<p>
またすべて整数である。
ここで与えられる扇形は必ずしも<i>s < t</i>とは限らない。
<i>s < t</i>と<i>s > t</i>の場合の図をそれぞれ図1,2に表す。
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I1">
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I2">
</td>
</tr>
<tr>
<td>
<center>図1</center>
</td>
<td>
<center>図2</center>
</td>
</tr>
</table>
</center>
<p>
ただし入力には図3のように、線と線がぴったりに重なる入力は無いものとする。
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I3">
</td>
</tr>
<tr>
<td>
<center>図3</center>
</td>
</tr>
</table>
</center>
<h2>
Output
</h2>
<p>
各データセットに対し、扇形が重なっている部分の最大枚数を表示せよ。
</p>
<h2>
Sample Input
</h2>
<pre>
3
3
17 12 7 340 180
26 22 10 150 270
27 13 5 100 230
3
0 0 8 0 90
10 10 8 180 0
50 50 5 180 270
2
10 10 5 0 270
0 0 30 0 90
</pre>
<h2>
Output for Sample Input
</h2>
<pre>
3
2
2
</pre>
<h2>
Hint
</h2>
<p>
ここでサンプルの1つ目は図4のように配置されている
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I4">
</td>
</tr>
<tr>
<td>
<center>図4</center>
</td>
</tr>
</table>
</center> |
p03591 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo is giving a present to Snuke.</p>
<p>Ringo has found out that Snuke loves <em>yakiniku</em> (a Japanese term meaning grilled meat. <em>yaki</em>: grilled, <em>niku</em>: meat). He supposes that Snuke likes grilled things starting with <code>YAKI</code> in Japanese, and does not like other things.</p>
<p>You are given a string <var>S</var> representing the Japanese name of Ringo's present to Snuke. Determine whether <var>S</var> starts with <code>YAKI</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10</var></li>
<li><var>S</var> consists of uppercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>S</var> starts with <code>YAKI</code>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>YAKINIKU
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><code>YAKINIKU</code> starts with <code>YAKI</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>TAKOYAKI
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><code>TAKOYAKI</code> (a Japanese snack. <em>tako</em>: octopus) does not start with <code>YAKI</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>YAK
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p01056 |
<h1>Lights of Apartment</h1>
<h2>Problem</h2>
<p>
エーちゃんとリカちゃんとハルトくんはマンションに遊びに来た。<br>
3人は全ての部屋の電気を管理できる部屋に忍び込みいたずらをすることにした。<br><br>
このマンションは<var>n</var>個の立方体が1列に並んでいる形をしている。<br>
各立方体は西から順に1辺の長さが1ずつ増えていて(1,2,3,...,<var>n</var>)、<var>i</var>番目の立方体は<var>i</var>階あり、各階に縦<var>i</var>×横<var>i</var>個の部屋がある。<br>
2番目以降の立方体の西側は1つ西の立方体の東側と接していて、全ての立方体の南側は真っ直ぐな道路に面している。<br>
</p>
<br>
<left>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015UOA_I" width="360" ><br>
</left>
<br>
<p>
初め全ての部屋に電気がついている。<br>
3人はそれぞれ次の行動をした。<br>
</p>
<ul>
<li>エーちゃんは西から<var>k</var>番目の全ての部屋の電気を消した。</li>
<li>リカちゃんは南から<var>k</var>番目の全ての部屋の電気を消した。</li>
<li>ハルトくんは<var>k</var>階の全ての部屋の電気を消した。</li>
</ul>
<p>
このようないたずらが <var>m</var> 回行われた後に電気がついている部屋の数を求めよ。
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var>
<var>q<sub>1</sub></var> <var>k<sub>1</sub></var>
...
<var>q<sub>m</sub></var> <var>k<sub>m</sub></var>
</pre>
<p>
入力は全て整数で与えられる。<br>
1行目に立方体の数<var>n</var>、行動の数<var>m</var>が与えられる。<br>
2行目以降<var>m</var>行に行動した人の番号<var>q</var>と<var>k</var>が与えられる。<br><br>
<var>q<sub>i</sub></var>が0の場合エーちゃん、 1の場合リカちゃん、2の場合ハルトくんが行動したことを表す。
</p>
<p>
3人は部屋がない場所の電気を消そうとすることもある。
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>n</var>,<var>m</var> ≤ 50000</li>
<li>0 ≤ <var>q<sub>i</sub></var> ≤ 2</li>
<li>1 ≤ <var>k<sub>i</sub></var> ≤ 2×10<sup>9</sup></li>
<li>同じ行動は一度しか与えられない</li>
</ul>
<h2>Output</h2>
<p>
電気がついている部屋の数を1行に出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
3 1
0 4
</pre>
<h2>Sample Output 1</h2>
<pre>
27
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2
2 2
2 3
</pre>
<h2>Sample Output 2</h2>
<pre>
14
</pre>
|
p01543 |
<h1>まるかいて</h1>
<p>
太郎君は小学生で、チラシの裏に落書きをしています。
ある時、太郎君は次のゲームを思いつきました。
</p>
<ul>
<li><var>n×n</var>の格子状のマス目を書いておきます。
</li><li>それぞれのマス目の初期状態は、丸印が書かれているか、書かれていないかのどちらか一方です。
</li><li>これらの丸印を消したり書いたりして最終的にどの一列を見ても必ずちょうど1つのみの丸印が、どの一行を見ても必ず1つのみの丸印が存在するようにすることが目標であり、この状態にすればゲームをクリアしたことになります。
</li></ul>
<p>
太郎君はこのゲームを思いつきましたが、太郎君はこのゲームをクリアするのに大変時間がかかってしまいます。そこで、大学生であるあなたに助けを求めました。
太郎君の兄であり大学生であるあなたの仕事は以下の通りです。<br>
厳密な状況を考えるために、あるマス目に丸印を書き込むコスト、あるマス目にある丸印を消すコストをあなたは導き出しました。このコストを用いてこのゲームをクリアするためにかかる操作のコストを最小化するような手順を考える。
このとき、最小のコストおよびそのコストを達成するような手順を出力するプログラムを書いてください。
出力については、最小コストを達成する手順なら、どのような操作、順番でも出力してもよいものとする。
</p>
<h2>Input</h2>
<blockquote>
<var>n</var><br><var>W<sub>11</sub></var> <var>W<sub>12</sub></var> .. <var>W<sub>1n</sub></var><br><var>W<sub>21</sub></var> <var>W<sub>22</sub></var> .. <var>W<sub>2n</sub></var><br>..<br><var>W<sub>n1</sub></var> <var>W<sub>n2</sub></var> .. <var>W<sub>nn</sub></var><br><var>E<sub>11</sub></var> <var>E<sub>12</sub></var> .. <var>E<sub>1n</sub></var><br><var>E<sub>21</sub></var> <var>E<sub>22</sub></var> .. <var>E<sub>2n</sub></var><br>..<br><var>E<sub>n1</sub></var> <var>E<sub>n2</sub></var> .. <var>E<sub>nn</sub></var><br><var>F<sub>1</sub></var>(<var>n</var>文字)<br><var>F<sub>2</sub></var>(<var>n</var>文字)<br>..<br><var>F<sub>n</sub></var>(<var>n</var>文字)<br></blockquote>
<ul>
<li><var>n</var>は太郎君の作ったマス目が一辺にいくつあるかを表す
</li><li><var>W<sub>ij</sub></var>は上から<var>i</var>番目、左から<var>j</var>番目のマス目に丸印を書き込むコストを表す
</li><li><var>E<sub>ij</sub></var>は上から<var>i</var>番目、左から<var>j</var>番目のマス目に書かれてある丸印を消すコストを表す
</li><li><var>F<sub>i</sub></var>は上から<var>i</var>番目の行のマス目の初期状態を表す
</li><li><var>F<sub>i</sub></var>の左から<var>j</var>文字目について
<ul>
<li>'o'のとき、上から<var>i</var>番目、左から<var>j</var>番目のマス目に丸印が書かれてあることを表す。
</li><li>'.'のとき、上から<var>i</var>番目、左から<var>j</var>番目のマス目が空白であることを表す。
</li></ul>
</li></ul>
<h2>Constraints</h2>
<blockquote>
<var>1≤ n ≤ 100</var><br><var>1≤ W<sub>ij</sub> ≤ 1000</var><br><var>1≤ E<sub>ij</sub> ≤ 1000 </var><br></blockquote>
<ul>
<li><var>F<sub>i</sub></var>は文字列であり、その長さは<var>n</var>である
</li><li><var>F<sub>i</sub></var>は'o'と'.'のみで構成されている
</li></ul>
<h2>Output</h2>
<blockquote>
<var>mincost</var><br><var>cnt</var><br><var>R<sub>1</sub></var> <var>C<sub>1</sub></var> <var>operate<sub>1</sub></var><br><var>R<sub>2</sub></var> <var>C<sub>2</sub></var> <var>operate<sub>2</sub></var><br>..<br><var>R<sub>cnt</sub></var> <var>C<sub>cnt</sub></var> <var>operate<sub>cnt</sub></var><br></blockquote>
<ul>
<li><var>mincost</var>は、太郎君のゲームをクリアするために必要な最小コストを表す。
</li><li><var>mincost</var>は書き込み操作、消去操作で発生するコストの総和で計算される。
</li><li><var>cnt</var> : <var>mincost</var>のコストを達成する操作を行った回数を表す
</li><li><var>k</var>回目<var>(1≤k≤cnt)</var>に実行する操作は<var>k+2</var>行目に記述する
</li><li><var>k</var>回目<var>(1≤k≤cnt)</var>の操作に対して
<ul>
<li>上から<var>i</var>番目のマス目、左から<var>j</var>番目のマス目に対して行ったものとすると
</li><li><var>R<sub>k</sub≥i , C<sub>k</sub≥j</var>である。
</li><li>この操作が丸印を消す操作であるならば<var>operate<sub>k</sub></var> = "erase"とせよ
</li><li>この操作が丸印を書き込む操作であるならば<var>operate<sub>k</sub></var> = "write"とせよ
</li><li><var>R<sub>k</sub>,C<sub>k</sub>,operate<sub>k</sub></var>は一行に空白区切りで出力しなければならない
</li></ul>
</li><li>丸印の書かれてあるマス目に対して丸印を記述する操作、および丸印が書かれていないマス目に対して丸印を消去する操作をした場合はWrongAnswerである
</li><li><var>cnt</var>個の操作にかかるコストの総和が<var>mincost</var>に一致しないときはWrongAnswerである
</li></ul>
<H2>Sample Input 1</H2>
<pre>3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
o.o
...
.o.
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>2
2
1 3 erase
2 3 write
</pre>
<p>
上から1番目、左から3番目のマス目の丸印を消去し、
上から2番目、左から3番目のマス目に丸印を書き加えれば目標は達成できる。
このときコストは2のみしかかからず、これが最小のコストである。
</p>
<H2>Sample Input 2</H2>
<pre>4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
oooo
oooo
oooo
oooo
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>30
12
1 1 erase
1 2 erase
1 3 erase
2 1 erase
2 2 erase
2 4 erase
3 1 erase
3 3 erase
3 4 erase
4 2 erase
4 3 erase
4 4 erase
</pre>
<p>
コスト(1+2+3+4)*3だけ消去処理をすればクリアとなります。
</p>
<H2>Sample Input 3</H2>
<pre>3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
o..
.o.
..o
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>0
0
</pre>
<p>
すでに目標は達成されているため、コスト及び操作回数はともに0となる。
</p> |
p03084 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takaha-shi, the capital of Republic of AtCoder, there are <var>N</var> roads extending east and west, and <var>M</var> roads extending north and south. There are no other roads.
The <var>i</var>-th east-west road from the north and the <var>j</var>-th north-south road from the west cross at the intersection <var>(i, j)</var>.
Two east-west roads do not cross, nor do two north-south roads.
The distance between two adjacent roads in the same direction is <var>1</var>.</p>
<p>Each road is one-way; one can only walk in one direction. The permitted direction for each road is described by a string <var>S</var> of length <var>N</var> and a string <var>T</var> of length <var>M</var>, as follows:</p>
<ul>
<li>If the <var>i</var>-th character in <var>S</var> is <code>W</code>, one can only walk westward along the <var>i</var>-th east-west road from the north;</li>
<li>If the <var>i</var>-th character in <var>S</var> is <code>E</code>, one can only walk eastward along the <var>i</var>-th east-west road from the north;</li>
<li>If the <var>i</var>-th character in <var>T</var> is <code>N</code>, one can only walk northward along the <var>i</var>-th north-south road from the west;</li>
<li>If the <var>i</var>-th character in <var>T</var> is <code>S</code>, one can only walk southward along the <var>i</var>-th south-west road from the west.</li>
</ul>
<p>Process the following <var>Q</var> queries:</p>
<ul>
<li>In the <var>i</var>-th query, <var>a_i, b_i, c_i</var> and <var>d_i</var> are given. What is the minimum distance to travel to reach the intersection <var>(c_i, d_i)</var> from the intersection <var>(a_i, b_i)</var> by walking along the roads?</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100000</var></li>
<li><var>2 \leq M \leq 100000</var></li>
<li><var>2 \leq Q \leq 200000</var></li>
<li><var>|S| = N</var></li>
<li><var>S</var> consists of <code>W</code> and <code>E</code>.</li>
<li><var>|T| = M</var></li>
<li><var>T</var> consists of <code>N</code> and <code>S</code>.</li>
<li><var>1 \leq a_i \leq N</var></li>
<li><var>1 \leq b_i \leq M</var></li>
<li><var>1 \leq c_i \leq N</var></li>
<li><var>1 \leq d_i \leq M</var></li>
<li><var>(a_i, b_i) \neq (c_i, d_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>Q</var>
<var>S</var>
<var>T</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var>
<var>a_2</var> <var>b_2</var> <var>c_2</var> <var>d_2</var>
<var>:</var>
<var>a_Q</var> <var>b_Q</var> <var>c_Q</var> <var>d_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>In the <var>i</var>-th line, print the response to the <var>i</var>-th query. If the intersection <var>(c_i, d_i)</var> cannot be reached from the intersection <var>(a_i, b_i)</var> by walking along the roads, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5 4
EEWW
NSNNS
4 1 1 4
1 3 1 2
4 2 3 2
3 3 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
11
5
4
</pre>
<p>The permitted direction for each road is shown in the following figure (north upward):</p>
<p><img alt="" src="https://img.atcoder.jp/exawizards2019/bfb8c54cc4098353946320d8c263807e.png"/></p>
<p>For each of the four queries, a route that achieves the minimum travel distance is as follows:</p>
<p><img alt="" src="https://img.atcoder.jp/exawizards2019/d1918596004a23a20aa138e591e0ee99.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 2
EEE
SSS
1 1 3 3
3 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
-1
</pre>
<p>The travel may be impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9 7 10
EEEEEWEWW
NSSSNSN
4 6 9 2
3 7 6 7
7 5 3 5
1 1 8 1
4 3 5 4
7 4 6 4
2 5 8 6
6 6 2 7
2 4 7 5
7 2 9 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
-1
4
9
2
3
7
7
6
-1
</pre></section>
</div>
</span> |
p01113 | <h3>Floating-Point Numbers</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
In this problem, we consider floating-point number formats, data representation formats to approximate real numbers on computers.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Scientific notation is a method to express a number, frequently used for
numbers too large or too small to be written tersely in usual decimal form.
In scientific notation, all numbers are written in the form
<i>m</i> × 10<sup><i>e</i></sup>.
Here, <i>m</i> (called <i>significand</i>) is a number
greater than or equal to 1 and less than 10,
and <i>e</i> (called <i>exponent</i>) is an integer.
For example, a number 13.5 is equal to 1.35 × 10<sup>1</sup>,
so we can express it in scientific notation with significand 1.35 and exponent 1.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
As binary number representation is convenient on computers,
let's consider <i>binary scientific notation</i> with base two, instead of ten.
In binary scientific notation, all numbers are written in the form
<i>m</i> × 2<sup><i>e</i></sup>.
Since the base is two, <i>m</i> is limited to be less than 2.
For example, 13.5 is equal to 1.6875 × 2<sup>3</sup>,
so we can express it in binary scientific notation
with significand 1.6875 and exponent 3.
The significand 1.6875 is equal to 1 + 1/2 + 1/8 + 1/16,
which is 1.1011<sub>2</sub> in binary notation.
Similarly, the exponent 3 can be expressed as 11<sub>2</sub> in binary notation.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A floating-point number expresses a number in binary scientific notation in finite number of bits.
Although the accuracy of the significand and the range of the exponent are limited by the number of bits, we can express numbers in a wide range with reasonably high accuracy.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
In this problem, we consider a 64-bit floating-point number format,
simplified from one actually used widely,
in which only those numbers greater than or equal to 1 can be expressed.
Here, the first 12 bits are used for the exponent and the remaining 52 bits for the significand.
Let's denote the 64 bits of a floating-point number by
<i>b</i><sub>64</sub>...<i>b</i><sub>1</sub>.
With <i>e</i> an unsigned binary integer
(<i>b</i><sub>64</sub>...<i>b</i><sub>53</sub>)<sub>2</sub>,
and with <i>m</i> a binary fraction represented by the remaining 52 bits
plus one (1.<i>b</i><sub>52</sub>...<i>b</i><sub>1</sub>)<sub>2</sub>,
the floating-point number represents the number
<i>m</i> × 2<sup><i>e</i></sup>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
We show below the bit string of the representation of 13.5 in the format described above.
</p>
<p style="text-align:center;">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_E1-en">
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
In floating-point addition operations, the results have to be approximated by numbers representable in floating-point format.
Here, we assume that the approximation is by truncation.
When the sum of two floating-point numbers <i>a</i> and <i>b</i> is expressed in binary scientific notation as
<i>a</i> + <i>b</i> = <i>m</i> × 2<sup>e</sup> (1 ≤ <i>m</i> < 2, 0 ≤ <i>e</i> < 2<sup>12</sup>),
the result of addition operation on them will be a floating-point number with its first 12 bits representing <i>e</i> as an unsigned integer
and the remaining 52 bits representing the first 52 bits of the binary fraction of <i>m</i>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A disadvantage of this approximation method is that the approximation error accumulates easily.
To verify this, let's make an experiment of adding a floating-point number many times, as in the pseudocode shown below.
Here, <i>s</i> and <i>a</i> are floating-point numbers, and the results of individual addition are approximated as described above.
</p>
<!-- end en only -->
<pre><i>s</i> := <i>a</i>
for <i>n</i> times {
<i>s</i> := <i>s</i> + <i>a</i>
}
</pre>
<!-- begin en only -->
<p>
For a given floating-point number <i>a</i> and a number of repetitions <i>n</i>,
compute the bits of the floating-point number <i>s</i> when the above pseudocode finishes.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of at most 1000 datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<p>
<i>n</i> <br>
<i>b</i><sub>52</sub>...<i>b</i><sub>1</sub> <br>
</p>
</blockquote>
<!-- begin en only -->
<p>
<i>n</i> is the number of repetitions. (1 ≤ <i>n</i> ≤ 10<sup>18</sup>)
For each <i>i</i>, <i>b</i><sub><i>i</i></sub> is either 0 or 1.
As for the floating-point number <i>a</i> in the pseudocode, the exponent is 0 and the significand is <i>b</i><sub>52</sub>...<i>b</i><sub>1</sub>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing a zero.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, the 64 bits of the floating-point number <i>s</i> after finishing the pseudocode should be output as a sequence of 64 digits, each being <tt>0</tt> or <tt>1</tt> in one line.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>1
0000000000000000000000000000000000000000000000000000
2
0000000000000000000000000000000000000000000000000000
3
0000000000000000000000000000000000000000000000000000
4
0000000000000000000000000000000000000000000000000000
7
1101000000000000000000000000000000000000000000000000
100
1100011010100001100111100101000111001001111100101011
123456789
1010101010101010101010101010101010101010101010101010
1000000000000000000
1111111111111111111111111111111111111111111111111111
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>0000000000010000000000000000000000000000000000000000000000000000
0000000000011000000000000000000000000000000000000000000000000000
0000000000100000000000000000000000000000000000000000000000000000
0000000000100100000000000000000000000000000000000000000000000000
0000000000111101000000000000000000000000000000000000000000000000
0000000001110110011010111011100001101110110010001001010101111111
0000000110111000100001110101011001000111100001010011110101011000
0000001101010000000000000000000000000000000000000000000000000000
</pre>
|
p00352 |
<H1>Handsel</H1>
<!-- New Year’s gift money -->
<p>
Alice and Brown are brothers in a family and each receives pocket money in celebration of the coming year. They are very close and share the total amount of the money fifty-fifty. The pocket money each receives is a multiple of 1,000 yen.
</p>
<p>
Write a program to calculate each one’s share given the amount of money Alice and Brown received.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>a</var> <var>b</var>
</pre>
<p>
A line of data is given that contains two values of money: <var>a</var> (1000 ≤ <var>a</var> ≤ 50000) for Alice and <bar>b</var> (1000 ≤ <var>b</var> ≤ 50000) for Brown.
</p>
<h2>Output</h2>
<p>
Output the amount of money each of Alice and Brown receive in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
1000 3000
</pre>
<h2>Sample Output 1</h2>
<pre>
2000
</pre>
<h2>Sample Input 2</h2>
<pre>
5000 5000
</pre>
<h2>Sample Output 2</h2>
<pre>
5000
</pre>
<h2>Sample Input 3</h2>
<pre>
1000 2000
</pre>
<h2>Sample Output 3</h2>
<pre>
1500
</pre>
|
p03987 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>One day, Snuke was given a permutation of length <var>N</var>, <var>a_1, a_2, ..., a_N</var>, from his friend.</p>
<p>Find the following:</p>
<p><img src="https://atcoder.jp/img/agc005/520049e1a049bb9810b398b35d7dcb7f.png" style="height: 50px;"/></p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ N ≦ 200,000</var></li>
<li><var>(a_1, a_2, ..., a_N)</var> is a permutation of <var>(1, 2, ..., N)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
<p>Note that the answer may not fit into a 32-bit integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 3 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>19
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
5 4 8 1 2 6 7 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>85
</pre></section>
</div>
</span> |
p02695 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are positive integers <var>N</var>, <var>M</var>, <var>Q</var>, and <var>Q</var> quadruples of integers ( <var>a_i</var> , <var>b_i</var> , <var>c_i</var> , <var>d_i</var> ).</p>
<p>Consider a sequence <var>A</var> satisfying the following conditions:</p>
<ul>
<li><var>A</var> is a sequence of <var>N</var> positive integers.</li>
<li><var>1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M</var>.</li>
</ul>
<p>Let us define a score of this sequence as follows:</p>
<ul>
<li>The score is the sum of <var>d_i</var> over all indices <var>i</var> such that <var>A_{b_i} - A_{a_i} = c_i</var>. (If there is no such <var>i</var>, the score is <var>0</var>.)</li>
</ul>
<p>Find the maximum possible score of <var>A</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 ≤ N ≤ 10</var></li>
<li><var>1 \leq M \leq 10</var></li>
<li><var>1 \leq Q \leq 50</var></li>
<li><var>1 \leq a_i < b_i \leq N</var> ( <var>i = 1, 2, ..., Q</var> )</li>
<li><var>0 \leq c_i \leq M - 1</var> ( <var>i = 1, 2, ..., Q</var> )</li>
<li><var>(a_i, b_i, c_i) \neq (a_j, b_j, c_j)</var> (where <var>i \neq j</var>)</li>
<li><var>1 \leq d_i \leq 10^5</var> ( <var>i = 1, 2, ..., Q</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>Q</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var>
<var>:</var>
<var>a_Q</var> <var>b_Q</var> <var>c_Q</var> <var>d_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible score of <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>110
</pre>
<p>When <var>A = \{1, 3, 4\}</var>, its score is <var>110</var>. Under these conditions, no sequence has a score greater than <var>110</var>, so the answer is <var>110</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>357500
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10 1
1 10 9 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p01810 |
<h2>監獄</h2>
<p>無限人の囚人たちがいる。はじめ、囚人たちは <var>0, 1, 2,</var> ... と番号が振られている。</p>
<p>次の操作を <var>N</var> 回行う。</p>
<ul>
<li><var>0</var> 番目の囚人を釈放し、<var>k, 2k, 3k,</var> ... 番目の囚人たちを処刑する。</li>
<li>その後、残った囚人たちに番号を振り直す。このとき、元の番号が小さい囚人から順に <var>0, 1, 2, </var> ... と番号を振る。</li>
</ul>
<p><var>N</var> 回目の操作で釈放される囚人がはじめに振られていた番号を求めよ。</p>
<h3>Constraints</h3>
<ul>
<li><var>1</var> ≤ <var>N</var> ≤ <var>10^5</var></li>
<li><var>2</var> ≤ <var>k</var> ≤ <var>10^5</var></li>
<li>答えは <var>10^{18}</var> 以下である。</li>
</ul>
<h3>Input Format</h3>
<p>入力は以下の形式で標準入力から与えられる。</p>
<pre>
<var>N</var> <var>k</var>
</pre>
<h3>Output Format</h3>
<p>答えを一行に出力せよ。</p>
<h3>Sample Input 1</h3>
<pre>
4 2
</pre>
</section>
<h3>Sample Output 1</h3>
<pre>
7
</pre>
<h3>Sample Input 2</h3>
<pre>
1 3
</pre>
<h3>Sample Output 2</h3>
<pre>
0
</pre>
<h3>Sample Input 3</h3>
<pre>
100000 100000
</pre>
<h3>Sample Output 3</h3>
<pre>
99999
</pre> |
p00702 |
<h1>
Kanglish : Analysis on Artificial Language
</h1>
<p>The late Prof. Kanazawa made an artificial language named Kanglish, which is
similar to English, for studying mythology. Words and sentences of Kanglish are
written with its own special characters called "Kan-characters". The size of the
set of the Kan-characters is 38, i.e., there are 38 different Kan-characters in
the set. Since Kan-characters cannot be directly stored in a computer because of
the lack of a coded character set, Prof. Kanazawa devised a way to represent
each Kan-character as an alphabetical letter or an ordered combination of two
alphabetical letters. Thus, each Kan-character is represented as one of the
following 26 letters
</p><blockquote>"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", and "z",
</blockquote>or one of the following 12 combinations of letters
<blockquote>"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw",
and "ts". </blockquote>
<p>
In addition, the Kan-characters are ordered according to
the above alphabetical representation. The order is named Kan-order in which the
Kan-character represented by "a" is the first one, that by "b" is the second,
that by "z" is the 26th, that by "ld" is the 27th, and that by "ts" is the 38th
(the last).
</p>
<p></p>
<p>The representations of words in Kanglish are separated by spaces. Each
sentence is written in one line, so there are no periods or full stops in
Kanglish. All alphabetical letters are in lower case, i.e., there are no
capitalizations. </p>
<p>We currently have many documents written in Kanglish with the alphabetical
representation. However, we have lost most of Prof. Kanazawa's work on how they
can be translated. To recognize his work, we have decided to first analyze them
statistically. The first analysis is to check sequences of consecutive
Kan-characters in words. </p>
<p>For example, a substring "ic" in a word "quice" indicates an ordered pair of
two adjacent Kan-characters that are represented by "i" and "c". For simplicity,
we make a rule that, in the alphabetical representation of a word, a
Kan-character is recognized as the longest possible alphabetical representation
from left to right. Thus, a substring "ncw" should be considered as a pair of
"nc" and "w". It does not consist of "n" and "cw", nor "n", "c", and "w". </p>
<p>For each Kan-character, there are 38 possible pairs of that Kan-character and
another Kan-character, e.g. "aa", "ab", ..., "az", "ald", ..., "ats". Thus,
mathematically, there is a total of 1444 (i.e., 38x38) possible pairs, including
pairs such as "n" and "cw", which is actually not allowed according to the above
rule. </p>
<p>Your job is to write a program that counts how many times each pair occurs in
input data. For example, in the sentence </p><pre> qua ist qda quang quice</pre>
<p>
the Kan-character represented by "qu" appears
three times. There are two occurrences of the pair of "qu" and "a", and one
occurrence of the pair of "qu" and "i". Note that the alphabetical letter "q"
appears four times in the example sentence, but the Kan-character represented by
"q" occurs only once, because "qu" represents another Kan-character that is
different from the Kan-character represented by "q".
<p></p>
<p>For simplicity, a newline at the end of a line is considered as a space. Thus
in the above example, "e" is followed by a space. </p>
<h2>Input</h2><pre><i>n</i>
<i>line</i><sub>1</sub>
<i>line</i><sub>2</sub>
...
<i>line</i><sub><i>n</i></sub>
</pre>
<p>The first line of the input is an integer <i>n</i>, which indicates the
number of lines that follow. Each line except for the first line represents one
Kanglish sentence. You may assume that <i>n</i> <= 1000 and that each line
has at most 59 alphabetical letters including spaces. </p>
<h2>Output</h2><pre>a <i>kc</i><sub>1</sub> <i>m</i><sub>1</sub>
b <i>kc</i><sub>2</sub> <i>m</i><sub>2</sub>
c <i>kc</i><sub>3</sub> <i>m</i><sub>3</sub>
...
ts <i>kc</i><sub>38</sub> <i>m</i><sub>38</sub>
</pre>
<p>The output consists of 38 lines for the whole input lines. Each line of the
output has two strings and an integer. In the <i>i</i>-th line in the output,
the first string is the alphabetical representation of the <i>i</i>-th
Kan-character in the Kan-order. For example, the first string of the first line
is "a", that of the third line is "c", and that of the 37th line is "cw". The
first string is followed by a space. </p>
<p>The second string in the <i>i</i>-th line (denoted by <i>kc<sub>i</sub></i>
above) shows the alphabetical representation of a Kan-character that most often
occurred directly after the first Kan-character. If there are two or more such
Kan-characters, the first one in the Kan-order should be printed. The second
string is followed by a space. </p>
<p>The integer (denoted by <i>m<sub>i</sub></i> above) in the <i>i</i>-th line
shows the number of times that the second Kan-character occurred directly after
the first Kan-character. In other words, the integer shows the number of times
that ``the ordered pair of the first Kan-character and the second
Kan-character'' appeared in the input. The integer is followed by a newline.
</p>
<p>Suppose the 28th output line is as follows:
</p><blockquote><pre>mb e 4</pre></blockquote>
<p>
"mb" is output because it is the 28th character in
the Kanglish alphabet. "e 4" means that the pair "mbe" appeared 4 times in the
input, and that there were no pairs beginning with "mb" that appeared more than
4 times.
<p></p>
<p>Note that if the <i>i</i>-th Kan-character does not appear in the input, or
if the <i>i</i>-th Kan-character is not followed by any other Kan-characters but
spaces, the second string in the <i>i</i>-th output line should be "a" and the
third item should be zero. </p>
<p>Although the output does not include spaces, Kan-characters that appear with
a space in-between is not considered as a pair. Thus, in the following example
</p><blockquote><pre>abc def</pre></blockquote>
<p>
"d" is not counted as occurring after "c".
<p></p>
<h2>Sample Input</h2>
<pre>
3
nai tiruvantel ar varyuvantel i valar tielyama nu vilya
qua ist qda quang ncw psts
svampti tsuldya jay quadal ciszeriol
</pre>
<h2>Output for the Sample Input</h2>
<pre>
a r 3
b a 0
c i 1
d a 2
e l 3
f a 0
g a 0
h a 0
i s 2
j a 1
k a 0
l y 2
m a 1
n a 1
o l 1
p a 0
q d 1
r i 1
s t 1
t i 3
u v 2
v a 5
w a 0
x a 0
y a 3
z e 1
ld y 1
mb a 0
mp t 1
nc w 1
nd a 0
ng a 0
nt e 2
nw a 0
ps ts 1
qu a 3
cw a 0
ts u 1
</pre>
|
p00597 |
<H1><font color="#000000">Problem C:</font> Finding the Largest Carbon Compound Given Its Longest Chain</H1>
<p>
An bydrocarbon is an organic compound which contains only carbons and hydrogens. An isomer is a compound that has the same number of carbons but different structures. Heptane, for example, is a hydrocarbon with 7 carbons. It has nine isomers. The structural formula of three are shown in Figure 1. Carbons are represented by the letter C, and bonds between carbons are represented by a straight line. In all figures, hydrogens are not represented for simplicity. Each carbon can be connected to a maximum of 4 carbons.
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_longestchain1"></td></tr>
</table>
<table>
<tr><td>Figure 1: These three examples of isomers of heptane have the same number of carbons but different structures.</td></tr>
</table>
</center>
<br/>
<p>
Let define a chain in an isomer as a sequence of connected carbons without branches. An isomer can have many chains of the same length. Figure 2 shows the longest chain of carbons for each of the represented isomer. Note that there can be many instances of longest chain in an isomer.
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_longestchain2"></td></tr>
</table>
<table>
<tr><td>Figure 2: The figures shows one instance of longest chain of carbons in each isomer. The first and the second isomers show longest chains of 5 carbons. The longest chain in the third isomer has 4 carbons.</td></tr>
</table>
</center>
<br/>
<p>
Your task is to identify the number of carbons of the largest possible carbon compound whose longest carbon chain has <i>n</i> (1 ≤ <i>n</i> ≤ 30) carbons.
</p>
<H2>Input</H2>
<p>
Each input contains a list of number of carbons, i.e. the length of a carbon chain.
</p>
<p>
The number of input lines is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each number n in input, identify the number of carbons of the largest possible carbon compound whose longest carbon chain has n carbons.
</p>
<H2>Sample Input</H2>
<pre>
1
4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
8
</pre> |
p02050 | <h3>Kは多角形のケイ</h3>
<!-- begin ja only -->
<p>「<i>1</i> 番じゃなきゃダメですか?<i>K</i> 番じゃダメなんでしょうか?」</p>
<p>これがケイ氏の座右の銘である.最近ケイ氏はもっぱら多角形に興味があるようで,目の前に広がる広大な二次元平面上に置かれた <i>N</i> 個の点を見て,そこから多角形を形成する方法について思いを馳せている.ケイ氏はどうやら,この <i>N</i> 個の点のうちいくつかの点を選んで自由な順番で繋げることで,選んだ点を頂点とする多角形を構成することにしたようだ.ただし,多角形は以下の条件を満たす必要がある.</p>
<ul>
<li>単純多角形である.すなわち,3 つ以上の頂点を持ち,連続しない任意の 2 辺が交点を持たない.</li>
<li>選ばれた点以外も含む <i>N</i> 個すべての点をその内部,または周上に含む.</li>
</ul>
<p>ケイ氏は己の信念に従って,このような多角形のうち,周長,すなわち全ての辺の長さの和が <i>K</i> 番目に短い多角形を渇望している.</p>
<p>あなたの仕事は,ケイ氏を手伝うため,条件を満たす多角形のうち,周長の昇順に並べたときに <i>K</i> 番目となる多角形を求め,その周長を出力するプログラムを書くことだ.ただし,そのような多角形が <i>K</i> 個以上存在しないこともある.そのようなときにはケイ氏の無念の気持ちを慮りつつ,申し訳ない気持ちを込めながら <i>-1</i> と出力する必要がある.</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>入力は複数のデータセットからなる. 各データセットは次の形式で表される.</p>
<blockquote><i>N</i> <i>K</i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i>
...
<i>x<sub>N</sub></i> <i>y<sub>N</sub></i></blockquote>
<p>データセットの1行目には二次元平面上の点の数 <i>N</i> と求める周長の順位 <i>K</i> が与えられる. <i>N</i>, <i>K</i> はともに整数であり,<i>3 ≤ N ≤ 25</i>, <i>1 ≤ K ≤ 10</i> が成り立つ.続く <i>N</i> 行では各点の二次元平面上の座標が与えられる.<i>N</i> 行のうち <i>i</i> 行目には <i>i</i> 番目の点の <i>x</i> 座標 <i>x<sub>i</sub></i> と <i>y</i> 座標 <i>y<sub>i</sub></i> がともに整数で与えられ,すべての <i>1 ≤ i ≤ N</i> について <i>-100 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 100</i> が成り立つ.どの相異なる 3 点を選んでも,その 3 点すべてを通るような直線は存在しないと仮定してよい.また,入力において,周長の昇順に並べたときに <i>K</i> 番目となる,問題文中に述べた条件を満たす多角形は,存在するならば一意に定まると仮定してよい.</p>
<p>入力の終わりは,2 個のゼロだけからなる行で表される. 全データセットの総数は 50 を超えない.</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>与えられた点集合からいくつかの点を選び単純多角形を作るとき,構成可能な単純多角形のうち <i>K</i> 番目に周長が短い多角形の周長を 1 行に出力せよ.そのような多角形が存在しない場合は -1 を出力せよ.結果は <i>10<sup>-4</sup></i> 以上の誤差を含んではいけない.</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>5 2
1 1
1 4
2 2
3 1
3 5
3 1
0 2
1 0
-1 0
3 2
0 2
1 0
-1 0
9 10
8 1
9 19
2 10
1 1
4 17
7 13
3 4
6 13
9 21
0 0
</pre><h3>Output for the Sample Input</h3><pre>11.812559200041266
6.472135954999580
-1
52.202878812480016
</pre>
|
p02400 | <H1>Circle</H1>
<p>
Write a program which calculates the area and circumference of a circle for given radius <var>r</var>.
</p>
<H2>Input</H2>
<p>
A real number <var>r</var> is given.
</p>
<H2>Output</H2>
<p>
Print the area and circumference of the circle in a line. Put a single space between them. The output should not contain an absolute error greater than 10<sup>-5</sup>.
</p>
<h2>Constraints</h2>
<ul>
<li> 0 < <var>r</var> < 10000</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
2
</pre>
<H2>Sample Output 1</H2>
<pre>
12.566371 12.566371
</pre>
<H2>Sample Input 2</H2>
<pre>
3
</pre>
<H2>Sample Output 2</H2>
<pre>
28.274334 18.849556
</pre>
|
p01386 |
<div>
<h1 class="title">問題 K : 巡回セールスマン問題</h1>
<p>2011 年のあの頃,まだプログラミングコンテストはとても平和であり,
我々はルールを精読せずに気軽にコンテストに参加していた.
しかし,そこに G○○gle の陰謀は迫っていた.
ある日,G○○gle によって秘密裏に買収されていた T○pC○der のコンテストは,
人知れずうちにルールが改変されており,命がけのプログラミングコンテストとなっていた.
そして僕は,そこで,何も知らず,
まっ先に kita_masa のプログラムのオーバーフローを突いたのだ….</p>
<dl class="docutils">
<dt>(iwi)</dt>
<dd>「うう…ああ…」</dd>
<dt>wata</dt>
<dd>「今やるべきことは自分を攻めることではない.チャンスを無駄にする気か?」</dd>
</dl>
<p>…そういえば,今こいつは,部屋に居る全ての人間を一瞬にして倒していた.
どうなっているんだ?</p>
<dl class="docutils">
<dt>wata</dt>
<dd>「まず,知っているかもしれないが, G○○gle は NP 完全問題を含む多くの計算困難と言われてきた問題に対する多項式時間の効率的なアルゴリズムを持っている.P vs NP 問題を解決したが,敢えてそれを秘匿することによってここまで成長したのだ.」</dd>
<dt>(iwi)</dt>
<dd>「もしやとは思っていたが,やはりか…. しかし,お前は今,G○○gle の人間を一瞬にして倒した.もしやお前も…?」</dd>
<dt>wata</dt>
<dd>「残念ながら違う.しかし…お前なら,分かるはずだろう?」</dd>
</dl>
<p>…なるほど!! そういうことか.
彼は大学時代,指数時間のアルゴリズムを高速にすることに興味を持っていた.
例え指数時間であっても,指数の底が極めて小さければ,
現実的なインスタンスに対して十分に高速な可能性がある.</p>
<dl class="docutils">
<dt>wata</dt>
<dd>「そういうことだ.例えば,今僕は,巡回セールスマン問題の <span style="font-size:110%;font-family:times new roman;"><i>O</i><sup>*</sup>(1.0001<sup><i>n</i></sup>)</span> 時間のアルゴリズムを完成させようとしている.」</dd>
</dl>
<p>凄まじい,想像以上だ….</p>
<dl class="docutils">
<dt>wata</dt>
<dd>「完成させるにあたって,グラフアルゴリズムに詳しいお前の力が必要だ. 手を貸してくれるな?」</dd>
<dt>(iwi)</dt>
<dd>「ああ,勿論だ.まかせろ!!」</dd>
</dl>
<div>
<h1>問題</h1>
<p>グラフが与えられる.
グラフは<span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 個の頂点を持ち,頂点には <span style="font-size:110%;font-family:times new roman;">1</span> から <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> の番号が付いている.
また,グラフは <span style="font-size:110%;font-family:times new roman;"><i>M</i></span> 個の辺を持ち,辺は有向 (一方通行) で,
それぞれ距離が決まっている.</p>
<p>頂点 <span style="font-size:110%;font-family:times new roman;">1</span> から出発し,頂点 <span style="font-size:110%;font-family:times new roman;">2, 3, …, <i>N</i></span> をこの順番に訪れ,頂点 <span style="font-size:110%;font-family:times new roman;">1</span> へ戻る経路を考える.
ここで,「この順番に訪れる」というのは,経路に含まれる頂点の部分列に
<span style="font-size:110%;font-family:times new roman;">2, 3, …, <i>N</i></span> が含まれるということである.
つまり,スタート地点の頂点 <span style="font-size:110%;font-family:times new roman;">1</span> から頂点 <span style="font-size:110%;font-family:times new roman;">2</span> への移動は,
直接の移動であっても,他の頂点を経由した移動であってもよく,
次の頂点 <span style="font-size:110%;font-family:times new roman;">2</span> から頂点 <span style="font-size:110%;font-family:times new roman;">3</span>への移動,
さらにその次の頂点 <span style="font-size:110%;font-family:times new roman;">3</span> から頂点 <span style="font-size:110%;font-family:times new roman;">4</span>への移動等に関しても同様である.
同じ頂点や同じ辺を 2 度通っても構わない.</p>
<p>グラフが与えられた時,
頂点 <span style="font-size:110%;font-family:times new roman;">1</span> から出発し頂点 <span style="font-size:110%;font-family:times new roman;">2, 3, …, <i>N</i></span> をこの順番に訪れ頂点 <span style="font-size:110%;font-family:times new roman;">1</span> へ戻る経路のうち,
最短のものの長さを出力するプログラムを作成せよ.
経路の長さとは,経路に含まれる辺の距離の和である.
複数回含まれる辺に関しては,含まれる回数の分だけ距離を加えよ.</p>
</div>
<div>
<h1>入力</h1>
<p>入力の最初の行は 2 つの整数 <span style="font-size:110%;font-family:times new roman;"><i>N</i>, <i>M</i></span> を含む.
これは,グラフの頂点数と辺数を表す.</p>
<p>続く <span style="font-size:110%;font-family:times new roman;"><i>M</i></span> 行は,辺の情報を表す.
これらの行のうちの <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> 行目は 3 つの整数 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub>, <i>b</i><sub><i>i</i></sub>, <i>c</i><sub><i>i</i></sub></span> が書かれており,
辺 <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> は頂点 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub></span> から頂点 <span style="font-size:110%;font-family:times new roman;"><i>b</i><sub><i>i</i></sub></span> を結び,その距離は <span style="font-size:110%;font-family:times new roman;"><i>c</i><sub><i>i</i></sub></span> であることを表す.</p>
</div>
<div>
<h1>出力</h1>
<p>条件を満たす経路のうち最短のものの長さを出力せよ.
ただし,条件を満たす経路が存在しない場合は,-1 を出力せよ.</p>
</div>
<div>
<h1>制約</h1>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">2 ≤ <i>N</i> ≤ 10<sup>5</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">0 ≤ <i>M</i> ≤ <i>N</i> + 500</span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>a</i><sub><i>i</i></sub>, <i>b</i><sub><i>i</i></sub> ≤ <i>N</i></span>,<span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub> ≠ <i>b</i><sub><i>i</i></sub></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>c</i><sub><i>i</i></sub> ≤ 10<sup>3</sup></span></li>
</ul>
</div>
<div>
<h1>入出力例</h1>
<div>
<h2>入出力例 1</h2>
<p>入力例 1:</p>
<pre class="literal-block">
5 5
1 2 10
2 3 20
3 4 30
4 5 40
5 1 50
</pre>
<p>入力例 1 に対する出力の例:</p>
<pre class="literal-block">
150
</pre>
</div>
<div>
<h2>入出力例 2</h2>
<p>入力例 2:</p>
<pre class="literal-block">
5 5
1 5 10
5 4 20
4 3 30
3 2 40
2 1 50
</pre>
<p>入力例 2 に対する出力の例:</p>
<pre class="literal-block">
600
</pre>
</div>
</div>
</div>
|
p02953 | <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> squares arranged in a row from left to right. The height of the <var>i</var>-th square from the left is <var>H_i</var>.</p>
<p>For each square, you will perform either of the following operations once:</p>
<ul>
<li>Decrease the height of the square by <var>1</var>.</li>
<li>Do nothing.</li>
</ul>
<p>Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq H_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 1 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>You can achieve the objective by decreasing the height of only the second square from the left by <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1 2 3 4 5
</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>1
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre></section>
</div>
</span> |
p03641 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>N</var> be a positive even number.</p>
<p>We have a permutation of <var>(1, 2, ..., N)</var>, <var>p = (p_1, p_2, ..., p_N)</var>.
Snuke is constructing another permutation of <var>(1, 2, ..., N)</var>, <var>q</var>, following the procedure below.</p>
<p>First, let <var>q</var> be an empty sequence.
Then, perform the following operation until <var>p</var> becomes empty:</p>
<ul>
<li>Select two adjacent elements in <var>p</var>, and call them <var>x</var> and <var>y</var> in order. Remove <var>x</var> and <var>y</var> from <var>p</var> (reducing the length of <var>p</var> by <var>2</var>), and insert <var>x</var> and <var>y</var>, preserving the original order, at the beginning of <var>q</var>.</li>
</ul>
<p>When <var>p</var> becomes empty, <var>q</var> will be a permutation of <var>(1, 2, ..., N)</var>.</p>
<p>Find the lexicographically smallest permutation that can be obtained as <var>q</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an even number.</li>
<li><var>2 ≤ N ≤ 2 × 10^5</var></li>
<li><var>p</var> is a permutation of <var>(1, 2, ..., N)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest permutation, with spaces in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 2 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 1 2 4
</pre>
<p>The solution above is obtained as follows:</p>
<table>
<thead>
<tr>
<th align="center"><var>p</var></th>
<th align="center"><var>q</var></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><var>(3, 2, 4, 1)</var></td>
<td align="center"><var>()</var></td>
</tr>
<tr>
<td align="center">↓</td>
<td align="center">↓</td>
</tr>
<tr>
<td align="center"><var>(3, 1)</var></td>
<td align="center"><var>(2, 4)</var></td>
</tr>
<tr>
<td align="center">↓</td>
<td align="center">↓</td>
</tr>
<tr>
<td align="center"><var>()</var></td>
<td align="center"><var>(3, 1, 2, 4)</var></td>
</tr>
</tbody>
</table>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
4 6 3 2 8 5 7 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3 1 2 7 4 6 8 5
</pre>
<p>The solution above is obtained as follows:</p>
<table>
<thead>
<tr>
<th align="center"><var>p</var></th>
<th align="center"><var>q</var></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><var>(4, 6, 3, 2, 8, 5, 7, 1)</var></td>
<td align="center"><var>()</var></td>
</tr>
<tr>
<td align="center">↓</td>
<td align="center">↓</td>
</tr>
<tr>
<td align="center"><var>(4, 6, 3, 2, 7, 1)</var></td>
<td align="center"><var>(8, 5)</var></td>
</tr>
<tr>
<td align="center">↓</td>
<td align="center">↓</td>
</tr>
<tr>
<td align="center"><var>(3, 2, 7, 1)</var></td>
<td align="center"><var>(4, 6, 8, 5)</var></td>
</tr>
<tr>
<td align="center">↓</td>
<td align="center">↓</td>
</tr>
<tr>
<td align="center"><var>(3, 1)</var></td>
<td align="center"><var>(2, 7, 4, 6, 8, 5)</var></td>
</tr>
<tr>
<td align="center">↓</td>
<td align="center">↓</td>
</tr>
<tr>
<td align="center"><var>()</var></td>
<td align="center"><var>(3, 1, 2, 7, 4, 6, 8, 5)</var></td>
</tr>
</tbody>
</table></section>
</div>
</span> |
p03211 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a string <var>S</var> consisting of digits <code>1</code>, <code>2</code>, <var>...</var>, <code>9</code>.
Lunlun, the Dachshund, will take out three consecutive digits from <var>S</var>, treat them as a single integer <var>X</var> and bring it to her master. (She cannot rearrange the digits.)</p>
<p>The master's favorite number is <var>753</var>. The closer to this number, the better.
What is the minimum possible (absolute) difference between <var>X</var> and <var>753</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is a string of length between <var>4</var> and <var>10</var> (inclusive).</li>
<li>Each character in <var>S</var> is <code>1</code>, <code>2</code>, <var>...</var>, or <code>9</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible difference between <var>X</var> and <var>753</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1234567876
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>34
</pre>
<p>Taking out the seventh to ninth characters results in <var>X = 787</var>, and the difference between this and <var>753</var> is <var>787 - 753 = 34</var>. The difference cannot be made smaller, no matter where <var>X</var> is taken from.</p>
<p>Note that the digits cannot be rearranged. For example, taking out <code>567</code> and rearranging it to <code>765</code> is not allowed.</p>
<p>We cannot take out three digits that are not consecutive from <var>S</var>, either. For example, taking out the seventh digit <code>7</code>, the ninth digit <code>7</code> and the tenth digit <code>6</code> to obtain <code>776</code> is not allowed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>35753
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If <code>753</code> itself can be taken out, the answer is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1111111111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>642
</pre>
<p>No matter where <var>X</var> is taken from, <var>X = 111</var>, with the difference <var>753 - 111 = 642</var>.</p></section>
</div>
</span> |
p02816 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are two sequences <var>a=\{a_0,\ldots,a_{N-1}\}</var> and <var>b=\{b_0,\ldots,b_{N-1}\}</var> of <var>N</var> non-negative integers each.</p>
<p>Snuke will choose an integer <var>k</var> such that <var>0 \leq k < N</var> and an integer <var>x</var> not less than <var>0</var>, to make a new sequence of length <var>N</var>, <var>a'=\{a_0',\ldots,a_{N-1}'\}</var>, as follows:</p>
<ul>
<li><var>a_i'= a_{i+k \mod N}\ XOR \ x</var></li>
</ul>
<p>Find all pairs <var>(k,x)</var> such that <var>a'</var> will be equal to <var>b</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 N \leq 2 \times 10^5</var></li>
<li><var>0 \leq a_i,b_i < 2^{30}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_0</var> <var>a_1</var> <var>...</var> <var>a_{N-1}</var>
<var>b_0</var> <var>b_1</var> <var>...</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print all pairs <var>(k, x)</var> such that <var>a'</var> and <var>b</var> will be equal, using one line for each pair, in ascending order of <var>k</var> (ascending order of <var>x</var> for pairs with the same <var>k</var>).</p>
<p>If there are no such pairs, the output should be empty.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 2 1
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 3
</pre>
<p>If <var>(k,x)=(1,3)</var>,</p>
<ul>
<li>
<p><var>a_0'=(a_1\ XOR \ 3)=1</var></p>
</li>
<li>
<p><var>a_1'=(a_2\ XOR \ 3)=2</var></p>
</li>
<li>
<p><var>a_2'=(a_0\ XOR \ 3)=3</var></p>
</li>
</ul>
<p>and we have <var>a' = b</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 0 0 0 0
2 2 2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 2
1 2
2 2
3 2
4 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
0 1 3 7 6 4
1 5 4 6 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2 2
5 5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2
1 2
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre></pre>
<p>No pairs may satisfy the condition.</p></section>
</div>
</span> |
p03704 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a positive integer <var>n</var>, we denote the integer obtained by reversing the decimal notation of <var>n</var> (without leading zeroes) by <var>rev(n)</var>. For example, <var>rev(123) = 321</var> and <var>rev(4000) = 4</var>.</p>
<p>You are given a positive integer <var>D</var>. How many positive integers <var>N</var> satisfy <var>rev(N) = N + D</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>D</var> is an integer.</li>
<li><var>1 ≤ D < 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>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the positive integers <var>N</var> such that <var>rev(N) = N + D</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>63
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two positive integers <var>N</var> such that <var>rev(N) = N + 63</var>: <var>N = 18</var> and <var>29</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>75
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There are no positive integers <var>N</var> such that <var>rev(N) = N + 75</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>864197532
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1920
</pre></section>
</div>
</span> |
p01739 | <p>
You are a programmer who loves pretty girl games (a sub-genre of dating simulation games). A game, which is titled "Floatable Heart" and was released last Friday, has arrived at your home just now. This game has multiple stories. When you complete all of those stories, you can get a special figure of the main heroine, Megumi. So, you want to hurry to play the game! But, let's calm down a bit and think how to complete all of the stories in the shortest time first.
</p>
<p>
In fact, you have the special skill that allows you to know the structure of branching points of games. By using the skill, you have found out that there are <var>n</var> branching points in this game and <var>i</var>-th branching point has <var>k_{i}</var> choices. This game is so complicated that multiple routes get to <var>i</var>-th branching point probably. You also noticed that it takes <var>c_{ij}</var> minutes to proceed from <var>i</var>-th branching point to another branching point (or an ending), if you select <var>j</var>-th choice of <var>i</var>-th branching point. Of course you need to select all the choices on all the branching points and read stories between a branching point and another branching point (or an ending) to complete all of those stories. In addition, you can assume it only takes negligible time to return to the beginning of the game ("reset") and to play from the beginning to the first branching point.
</p>
<p>
The game's manual says that this game has an additional feature called "Quick Save", and the feature allows you to record the point where you are currently playing and return there at any time later. However, this feature is not working for some bug. Thus you have to restart from the first branching point every time, if you reach an ending or quit the game on the way. Any patch to fix this bug has not been yet published. This is an imposed tribulation for the fastest players.
</p>
<p>Well, let's estimate how long it will take for completing all of the stories in the shortest time.
</p>
<h3>Input</h3>
<p>A data set is given in the following format.
</p><pre>
<var>n</var>
<var>k_{1}</var> <var>t_{11}</var> <var>c_{12}</var> ... <var>t_{1k_{1}}</var> <var>c_{1k_{1}}</var>
:
:
<var>k_{n}</var> <var>t_{n1}</var> <var>c_{n2}</var> ... <var>t_{nk_{n}}</var> <var>c_{nk_{n}}</var>
</pre>
<p>The first line of the data set contains one integer <var>n</var> (<var>2 \leq n \leq 1{,}000</var>), which denotes the number of the branching points in this game. The following <var>n</var> lines describe the branching points. The <var>i</var>-th line describes the branching point of ID number <var>i</var>. The first integer <var>k_{i}</var> (<var>0 \leq k_{i} \leq 50</var>) is the number of choices at the <var>i</var>-th branching point. <var>k_{i} ≥ 0</var> means that the <var>i</var>-th branching point is an ending. Next <var>2k_{i}</var> integers <var>t_{ij}</var> (<var>1 \leq t_{ij} \leq n</var>) and <var>c_{ij}</var> (<var>0 \leq c_{ij} \leq 300</var>) are the information of choices. <var>t_{ij}</var> denotes the ID numbers of the next branching points when you select the <var>j</var>-th choice. <var>c_{ij}</var> denotes the time to read the story between the <var>i</var>-th branching point and the <var>t_{ij}</var>-th branching point. The branching point with ID 1 is the first branching point. You may assume all the branching point and endings are reachable from the first branching point. You may also assume that there is no loop in the game, that is, no branching point can be reached more than once without a reset.
</p>
<h3>Output</h3>
<p>Print the shortest time in a line.
</p>
<h3>Sample Input 1</h3>
<pre>2
1 2 2
0
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>2
</pre>
<h3>Sample Input 2</h3>
<pre>6
2 2 1 3 2
2 4 3 5 4
2 5 5 6 6
0
0
0
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>24
</pre>
<h3>Sample Input 3</h3>
<pre>6
3 2 100 3 10 3 10
1 4 100
1 4 10
3 5 1 5 1 6 1
0
0
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>243
</pre>
|
p03354 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a permutation of the integers from <var>1</var> through <var>N</var>, <var>p_1</var>, <var>p_2</var>, .., <var>p_N</var>.
We also have <var>M</var> pairs of two integers between <var>1</var> and <var>N</var> (inclusive), represented as <var>(x_1,y_1)</var>, <var>(x_2,y_2)</var>, .., <var>(x_M,y_M)</var>.
AtCoDeer the deer is going to perform the following operation on <var>p</var> as many times as desired so that the number of <var>i</var> (<var>1</var> <var>≤</var> <var>i</var> <var>≤</var> <var>N</var>) such that <var>p_i = i</var> is maximized:</p>
<ul>
<li>Choose <var>j</var> such that <var>1</var> <var>≤</var> <var>j</var> <var>≤</var> <var>M</var>, and swap <var>p_{x_j}</var> and <var>p_{y_j}</var>.</li>
</ul>
<p>Find the maximum possible number of <var>i</var> such that <var>p_i = i</var> after operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2</var> <var>≤</var> <var>N</var> <var>≤</var> <var>10^5</var></li>
<li><var>1</var> <var>≤</var> <var>M</var> <var>≤</var> <var>10^5</var></li>
<li><var>p</var> is a permutation of integers from <var>1</var> through <var>N</var>.</li>
<li><var>1</var> <var>≤</var> <var>x_j,y_j</var> <var>≤</var> <var>N</var></li>
<li><var>x_j</var> <var>≠</var> <var>y_j</var></li>
<li>If <var>i</var> <var>≠</var> <var>j</var>, <var>\{x_i,y_i\}</var> <var>≠</var> <var>\{x_j,y_j\}</var>.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>p_1</var> <var>p_2</var> <var>..</var> <var>p_N</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 maximum possible number of <var>i</var> such that <var>p_i = i</var> after operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
5 3 1 4 2
1 3
5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If we perform the operation by choosing <var>j=1</var>, <var>p</var> becomes <code>1 3 5 4 2</code>, which is optimal, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
3 2 1
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>If we perform the operation by, for example, choosing <var>j=1</var>, <var>j=2</var>, <var>j=1</var> in this order, <var>p</var> becomes <code>1 2 3</code>, which is obviously optimal.
Note that we may choose the same <var>j</var> any number of times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 8
5 3 6 8 7 10 9 1 2 4
3 1
4 1
5 9
2 5
6 5
3 5
8 9
7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 1
1 2 3 4 5
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre>
<p>We do not have to perform the operation. </p></section>
</div>
</span> |
p01369 |
<!-- begin en only -->
<h3><U>koukyoukoukokukikou</U></h3>
<!-- end en only -->
<!-- begin ja only -->
<!-- end ja only -->
<div>
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ACM-ICPC を愛する誰もが手から喉が出るほど欲しがるもの, それが Accepted.
略して AC. しかし, 実のところ, それが通じるのはごく限られた人たちだけで, 世間一般には "koukyoukoukokukikou" の略称に過ぎない.
</p>
<P>
ところで, 一般的なキーボードのキー配置(図A-1)をQWERTY配列と呼ぶのに対し, それとは別のDvorak配列と呼ばれるキー配置も考案されている.
Dvorak配列ではよく使われるキーがホームポジションにあるので, より速くタイプできると T氏(仮) は強硬に主張している.
</p>
<p style="text-align: center;">
<a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011A-1" width="50%">
</a><br/>
図A-1 QWERTY配列
</p>
<p>
その T 氏(仮)はこの文字列を見ていてあることに気付いた. "koukyoukoukokukikou" は Dvorak 配列を使うと片手だけでタイプできることに.
しかし, 同時に残念な事実にも気付いた. QWERTY 配列でも片手だけでタイプできるのだ.
</p>
<p>
T 氏(仮)は他に Dvorak 配列を使うと片手だけでタイプできる文字列がないか興味を持った.
しかし, できれば QWERTY 配列を使ったときに片手だけでタイプできて欲しくない.
そのために, 各文字列に対して, QWERTY 配列で文字をタイプするときに使う手が入れ替わる回数を求めるプログラムを作ることにした.
そういえば, T 氏(仮)は QWERTY 配列をほとんど忘れてしまっていたのであった. 代わりにプログラムを書いてあげるとしよう.
</p>
<p>
なお, QWERTY 配列でそれぞれのキーが左右どちらの手でタイプされるものなのかわからなくなったときは, 下の図A-2を参照すればよいだろう.
</p>
<p style="text-align: center;">
<a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011A-2" width="50%">
</a><br/>
図A-2 それぞれの手でタイプされる範囲
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
入力は各行にタイプする手が入れ替わる回数をカウントすべき文字列が1個ずつ含まれる.
文字列はアルファベット小文字のみからなっていて32文字以下である.
入力の終わりは"#"のみからなる行で示される. この"#"はカウントする対象の文字列ではない.
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
入力された各文字列について整数を1つずつ各行に出力せよ.
出力すべき整数は, QWERTY 配列を使ったときに, 文字をタイプする手が入れ替わる回数である.
出力に余計な文字を含めてはいけない.
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
koukyoukoukokukikou
abrakadabra
acmicpc
japaque
helloworld
#
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
0
2
4
5
7
</pre>
</div> |
p00981 | <h2>Wall Painting</h2>
<p>
Here stands a wall made of a number of vertical panels. The panels are not painted yet.
</p>
<p>
You have a number of robots each of which can paint panels in a single color, either red, green, or blue. Each of the robots, when activated, paints panels between a certain position and another certain position in a certain color. The panels painted and the color to paint them are fixed for each of the robots, but which of them are to be activated and the order of their activation can be arbitrarily decided.
</p>
<p>
You’d like to have the wall painted to have a high <i>aesthetic value</i>. Here, the aesthetic value of the wall is defined simply as the sum of aesthetic values of the panels of the wall, and the aesthetic value of a panel is defined to be:
</p>
<ul>
<li> 0, if the panel is left unpainted.</li>
<li> The bonus value specified, if it is painted only in a single color, no matter how many times it is painted.</li>
<li> The penalty value specified, if it is once painted in a color and then overpainted in one or more different colors.</li>
</ul>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$ $m$ $x$ $y$
$c_1$ $l_1$ $r_1$
.
.
.
$c_m$ $l_m$ $r_m$
</pre>
<p>
Here, $n$ is the number of the panels ($1 \leq n \leq 10^9$) and $m$ is the number of robots ($1 \leq m \leq 2 \times 10^5$). $x$ and $y$ are integers between $1$ and $10^5$, inclusive. $x$ is the bonus value and $-y$ is the penalty value. The panels of the wall are consecutively numbered $1$ through $n$. The $i$-th robot, when activated, paints all the panels of numbers $l_i$ through $r_i$ ($1 \leq l_i \leq r_i \leq n$) in color with color number $c_i$ ($c_i \in \{1, 2, 3\}$). Color numbers 1, 2, and 3 correspond to red, green, and blue, respectively.
</p>
<h3>Output</h3>
<p>
Output a single integer in a line which is the maximum achievable aesthetic value of the wall.</p>
<h3>Sample Input 1 </h3>
<pre>
8 5 10 5
1 1 7
3 1 2
1 5 6
3 1 4
3 6 8
</pre>
<h3>Sample Output 1</h3>
<pre>
70
</pre>
<h3>Sample Input 2 </h3>
<pre>
26 3 9 7
1 11 13
3 1 11
3 18 26
</pre>
<h3>Sample Output 2</h3>
<pre>
182
</pre>
<h3>Sample Input 3 </h3>
<pre>
21 10 10 5
1 10 21
3 4 16
1 1 7
3 11 21
3 1 16
3 3 3
2 1 17
3 5 18
1 7 11
2 3 14
</pre>
<h3>Sample Output 3</h3>
<pre>
210
</pre>
<h3>Sample Input 4 </h3>
<pre>
21 15 8 7
2 12 21
2 1 2
3 6 13
2 13 17
1 11 19
3 3 5
1 12 13
3 2 2
1 12 15
1 5 17
1 2 3
1 1 9
1 8 12
3 8 9
3 2 9
</pre>
<h3>Sample Output 4</h3>
<pre>
153
</pre>
|
p01693 |
<h2>G - Derangement / 完全順列</h2>
<h3>Story</h3>
<p>Dのひとは順列に関する研究をしている。あるときDのひとは、"完全順列 (Derangement)"という順列のクラスを見つけた。「完全な順列とかなんかかっこいい!!!しかもDからはじまる!!!」と廚二病をこじらせたDのひとは、与えられた順列をすべて完全順列に書き換えてしまおうと考えた。</p>
<h3>Problem</h3>
<p>長さ<var>n</var>の順列<var>p</var> <var>=</var> <var>(p_1</var> <var>p_2</var> <var>...</var> <var>p_n)</var>が与えられる。<var>i</var>番目の要素と<var>j</var>番目の要素を入れ替える操作には<var>(p_i+p_j) \times |i-j|</var>のコストを要する。このとき、上記の入れ替え操作のみを用いて<var>p</var>を完全順列にするために必要な最小のコストを求めよ。</p>
<p>ただし、順列<var>q</var>が完全順列であるとは、<var>1 \leq i \leq n</var>について、<var>q_i \neq i</var>が成り立つことを言う。たとえば、<var>(5</var> <var>3</var> <var>1</var> <var>2</var> <var>4)</var>は完全順列であるが、<var>(3</var> <var>2</var> <var>5</var> <var>4</var> <var>1)</var>は<var>4</var>番目の数が<var>4</var>なので完全順列ではない。</p>
<h3>Input</h3>
<p>入力は以下の形式からなる。</p>
<pre><var>n</var>
<var>p_1</var> <var>p_2</var> ... <var>p_n</var></pre>
<p><var>1</var>行目は順列の長さ<var>n</var>を表す整数<var>1</var>つからなる。 <var>2</var>行目は<var>n</var>個の整数からなり、<var>i</var>番目の整数は順列<var>p</var>の<var>i</var>番目の要素を表す。それぞれは空白<var>1</var>文字で区切られている。</p>
<p>制約:</p>
<ul>
<li><var>2 \leq n \leq 100</var></li>
<li><var>1 \leq p_i \leq n, i \neq j ⇔ p_i \neq p_j</var></li>
</ul>
<h3>Output</h3>
<p><var>p</var>を完全順列に並び替えるための最小コストを<var>1</var>行に出力せよ。行の最後では必ず改行を行うこと。</p>
<h3>Sample Input 1</h3>
<pre>5
1 2 3 5 4</pre>
<h3>Sample Output 1</h3>
<pre>7</pre>
<p>1と2を入れ替えた後、1と3を入れ替えると、(2 3 1 5 4)となり完全順列である。</p>
<h3>Sample Input 2</h3>
<pre>5
5 3 1 2 4</pre>
<h3>Sample Output 2</h3>
<pre>0</pre>
<p>始めから完全順列である。</p>
<h3>Sample Input 3</h3>
<pre>10
1 3 4 5 6 2 7 8 9 10</pre>
<h3>Sample Output 3</h3>
<pre>38</pre> |
p00128 |
<h1>そろばん</h1>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_abacus1">
</center>
<br/>
<p>
そろばんを習い始める友人からのお願いで、あなたはそろばんの珠の並び
を表示するプログラムを作成することになりました。ある数字を入力として、そろばんの珠の並びを出力するプログラムを作成してください。ただし、表示するそろばんの桁数は 5 桁とし、0 から 9 までの珠の配置はそれぞれ '<span>*</span>' (半角アスタリスク)、'<span> </span>' (半角空白)、'<span>=</span>' (半角イコール) を用いて以下のように表すものとします。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_abacus2">
</center>
<br/>
<H2>Input</H2>
<p>
複数のテストケースが与えられます。各テストケースとして 5 桁までの数字(整数)が 1 行に与えられます。
</p>
<p>
テストケースの数は 1024 を超えません。
</p>
<H2>Output</H2>
<p>
各テストケースついてそろばんの珠の配置を出力してください。テストケースの間に1行の空行を入れてください。
</p>
<H2>Sample Input</H2>
<pre>
2006
1111
</pre>
<H2>Output for the Sample Input</H2>
<pre>
****
*
=====
* *
****
* ***
*****
*****
*****
=====
****
*
*****
*****
*****
</pre>
|
p02115 |
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem E: Piano</h1>
<h2>Problem</h2>
<p>
がっちょ君はピアノを弾こうとしている。ピアノは右側にある鍵盤ほど高い音が出る。がっちょ君はある楽譜を持っており、その楽譜に従って弾く。
</p>
<p>
楽譜には、ある時刻にどの鍵盤を弾くべきかを示す音符が時系列順に記載されている。この楽譜には和音(複数の鍵盤を押したときに出る音)は現れず、音の長さも考えないことにする。
</p>
<p>
がっちょ君はピアノを弾くとき、以下のルールに従う。
</p>
<ul>
<li>片手のみで弾く</li>
<li>指一本で鍵盤ひとつを弾く</li>
<li>最初の音はどの指でも弾ける</li>
<li>直前の音より高い音を弾くとき、直前の音を弾いた指よりもひとつ以上右にある指を使う</li>
<li>直前の音より低い音を弾くとき、直前の音を弾いた指よりもひとつ以上左にある指を使う</li>
<li>直前の音と同じ高さの音を弾くとき、直前の音を弾いた指と同じ指を使う</li>
</ul>
<p>
がっちょ君が使う楽譜が与えられるので、ルールに従ってその楽譜を演奏しきるには、演奏する方の腕に最小何本の指が必要かを求めよ。ただし、必要な指は6本以上になることがあることに注意せよ。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var>
<var>a<sub>2</sub></var>
...
<var>a<sub>N</sub></var>
</pre>
<p>
1行目に、楽譜に書かれている音符の総数を表す整数<var>N</var>が与えられる。 <br>続く2行目から<var>N</var>+1行目までに、時刻<var>i</var>(1 ≤ <var>i</var> ≤ <var>N</var>)に弾くべき鍵盤が最も左の鍵盤から何番目かを表す整数<var>a<sub>i</sub></var>が与えられる。
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 10<sup>5</sup></li>
<li>0 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>9</sup></li>
</ul>
<h2>Output</h2>
<p>
がっちょ君が上記ルールに従って弾くために必要な最小の指の本数を1行に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
3
2
5
1
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
この場合、図1の①、② 、③ の順で鍵盤を弾く。指が2本あると、左側の指で鍵盤2を、右側の指で鍵盤5を、また左側の指で鍵盤1を弾くことができる。
</p>
<center>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day2_aizu2017_keyboard" alt="Sample1の図解">
<legend>図1: Sample1 の図解</legend>
</figure>
</center>
<h2>Sample Input 2</h2>
<pre>
5
4
5
2
1
3
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<h2>Sample Input 3</h2>
<pre>
3
4
4
4
</pre>
<h2>Sample Output 3</h2>
<pre>
1
</pre> |
p00578 | <h1>日本沈没 (Japan Sinks)</h1>
<!-- 時間制限 : 2sec / メモリ制限 : 256MB-->
<h2>問題文</h2>
<p>
日本列島は細長い列島である.日本列島は平行な境界線により <var>N</var> 個の区画に分けられている.区画には端から順に <var>1</var> から <var>N</var> の番号が付けられている.区画 <var>i</var> (<var>1 ≦ i ≦ N</var>) の高さは <var>A_i</var> である.
</p>
<p>
日本列島は海に囲まれており,海面の高さは場所によらず一定である.高さが海面の高さより高い区画を<strong>陸地</strong>と呼ぶ.
</p>
<p>
陸地が連続している部分のことを<strong>島</strong>と呼ぶ.より正確に書くと以下の通りである.整数 <var>l</var>, <var>r</var> (<var>1 ≦ l ≦ r ≦ N</var>) について,日本列島のうち区画 <var>l</var>,区画 <var>l+1</var>,<var>...</var>,区画 <var>r</var> からなる部分を<strong>領域</strong> [<var>l, r</var>] という.以下の条件を満たす領域 [<var>l, r</var>] を島という:
</p>
<ul>
<li>区画 <var>l</var>,区画 <var>l+1</var>,<var>...</var>,区画 <var>r</var> はすべて陸地である.</li>
<li><var>l>1</var> ならば区画 <var>l-1</var> は陸地ではない.</li>
<li><var>r<N</var> ならば区画 <var>r+1</var> は陸地ではない.</li>
</ul>
<p>
海面の上昇により,日本列島は少しずつ沈没している.現在の海面の高さは <var>0</var> であるが,これは時間が経つにつれて徐々に上がり,ついには日本全体が海になってしまう.
</p>
<p>
JOI 君は,海面の高さが上昇すると,日本の島の数が増減することに気付いた.現在から,日本に陸地がなくなるまでの間 (現在も含む) における,島の数の最大値を求めたい.
</p>
<h2>制約</h2>
<ul>
<li><var>1 ≦ N ≦ 100000 (= 10^5)</var></li>
<li><var>0 ≦ A_i ≦ 1000000000 (= 10^9)</var> (<var>1 ≦ i ≦ N</var>)</li>
</ul>
<h2>入力・出力</h2>
<p>
<b>入力</b><br>
入力は以下の形式で標準入力から与えられる.<br>
<var>N</var><br>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</p>
<p>
<b>出力</b><br>
現在から,日本に陸地がなくなるまでの間 (現在も含む) における,島の数の最大値を 1 行で出力せよ.
</p>
<!--
<h2>小課題</h2>
<p>
</p>
<p style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<li>(<var>7</var> 点) <var>N ≦ 2000</var>, <var>A_i ≦ 2000</var> (<var>1 ≦ i ≦ N</var>)</li>
<li>(<var>8</var> 点) <var>N ≦ 2000</var></li>
<li>(<var>85</var> 点) 追加の制約はない.</li>
</ol>
</p>
-->
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
6
0 1 2 1 3 2
</pre>
<h3>出力例 1</h3>
<pre>
2
</pre>
<ul>
<li>海面の高さが <var>0</var> 以上 <var>1</var> 未満のとき,区画 <var>2, 3, 4, 5, 6</var> が陸地である.領域 [<var>2, 6</var>] が唯一の島なので,島の数は <var>1</var> である.</li>
<li>海面の高さが <var>1</var> 以上 <var>2</var> 未満のとき,区画 <var>3, 5, 6</var> が陸地である.領域 [<var>3, 3</var>] と領域 [<var>5, 6</var>] が島なので,島の数は <var>2</var> である.</li>
<li>海面の高さが <var>2</var> 以上 <var>3</var> 未満のとき,区画 <var>5</var> のみが陸地である.領域 [<var>5, 5</var>] が唯一の島なので,島の数は <var>1</var> である.</li>
<li>海面の高さが <var>3</var> になると,陸地はなくなり,島の数は <var>0</var> になる.</li>
</ul>
<p>
よって島の数の最大値は <var>2</var> なので,<var>2</var> を出力する.
</p>
<h3>入力例 2</h3>
<pre>
6
3 2 3 0 2 0
</pre>
<h3>出力例 2</h3>
<pre>
2
</pre>
<ul>
<li>海面の高さが <var>0</var> 以上 <var>2</var> 未満のとき,区画 <var>1, 2, 3, 5</var> が陸地である.領域 [<var>1, 3</var>] と領域 [<var>5, 5</var>] が島なので,島の数は <var>2</var> である.</li>
<li>海面の高さが <var>2</var> 以上 <var>3</var> 未満のとき,区画 <var>1, 3</var> が陸地である.領域 [<var>1, 1</var>] と領域 [<var>3, 3</var>] が島なので,島の数は <var>2</var> である.</li>
<li>海面の高さが <var>3</var> になると,陸地はなくなり,島の数は <var>0</var> になる.</li>
</ul>
<p>
よって島の数の最大値は <var>2</var> なので,<var>2</var> を出力する.
</p>
<h3>入力例 3</h3>
<pre>
10
4 1 2 1 2 3 5 4 3 2
</pre>
<h3>出力例 3</h3>
<pre>
3
</pre>
<br/>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2018/2019-yo/index.html">情報オリンピック日本委員会作 『第 18 回日本情報オリンピック JOI 2018/2019 予選競技課題』</a>
</p>
</div>
|
p02545 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are integer sequences <var>A</var> and <var>B</var> of length <var>3N</var>. Each of these two sequences contains three copies of each of <var>1, 2, \dots, N</var>.
In other words, <var>A</var> and <var>B</var> are both arrangements of <var>(1, 1, 1, 2, 2, 2, \dots, N, N, N)</var>.</p>
<p>Tak can perform the following operation to the sequence <var>A</var> arbitrarily many times:</p>
<ul>
<li>Pick a value from <var>1, 2, \dots, N</var> and call it <var>x</var>. <var>A</var> contains exactly three copies of <var>x</var>. Remove the middle element of these three. After that, append <var>x</var> to the beginning or the end of <var>A</var>.</li>
</ul>
<p>Check if he can turn <var>A</var> into <var>B</var>. If he can, print the minimum required number of operations to achieve that.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 33</var></li>
<li><var>A</var> and <var>B</var> are both arrangements of <var>(1, 1, 1, 2, 2, 2, \dots, N, N, 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>A_1</var> <var>A_2</var> ... <var>A_{3N}</var>
<var>B_1</var> <var>B_2</var> ... <var>B_{3N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Tak can turn <var>A</var> into <var>B</var>, print the minimum required number of operations to achieve that. Otherwise, print <var>-1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 3 1 1 3 2 2 1 3
1 2 2 3 1 2 3 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, Tak can perform operations as follows:</p>
<ul>
<li><code>2 3 1 1 3 2 2 1 3</code> (The initial state)</li>
<li><code>2 2 3 1 1 3 2 1 3</code> (Pick <var>x = 2</var> and append it to the beginning)</li>
<li><code>2 2 3 1 3 2 1 3 1</code> (Pick <var>x = 1</var> and append it to the end)</li>
<li><code>1 2 2 3 1 3 2 3 1</code> (Pick <var>x = 1</var> and append it to the beginning)</li>
<li><code>1 2 2 3 1 2 3 1 3</code> (Pick <var>x = 3</var> and append it to the end)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 3
</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>3
2 3 3 1 1 1 2 2 3
3 2 2 1 1 1 3 3 2
</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>8
3 6 7 5 4 8 4 1 1 3 8 7 3 8 2 4 7 5 2 2 6 5 6 1
7 5 8 1 3 6 7 5 4 8 1 3 3 8 2 4 2 6 5 6 1 4 7 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>7
</pre></section>
</div>
</span> |
p00082 |
<H1>メリーゴーランド</H1>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_10_1">
</center><br/>
<p>
遊園地にあるメリーゴーランドはご存じでしょう。大きな円盤の上に馬や馬車などの乗り物が固定されていて、円盤が回転すると同時に乗り物が上下に揺れる、定番の遊具です。ある遊園地のメリーゴーランドは、4人乗りの馬車が2台、2人乗りの車2台、1人乗りの馬が4台、計8台の乗り物が図1のような順序で備えられています。そして、遊園地においでのお客様は、図1に示す乗り場0〜7のどこかで待つようになっています。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_10_2">
</center><br/>
<p>
この遊園地のメリーゴーランドは、かならず乗り物が乗り場にぴったりと合う位置に停止します。そして、0〜7のそれぞれで待っているお客さまは、目の前にとまった乗り物に乗ることになっています。急いで他の乗り場へ移動してそこから乗るということはできません。効率よく、お客さまにたのしんでいただくためには、メリーゴーランドの停止する位置をうまく調整して、乗れないお客さまをできるだけ少なくするようにしなければなりません。
</p>
<p>
乗り場0〜7で待っているお客さまの人数を読み込んで、どの位置にどの乗り物が来るように止めれば乗れないお客さまが最も少なくなるかを出力するプログラムを作成してください。
<!--なお、乗れなくなるお客さまが最小となるとめ方が何通りもある場合は、そのうちの一つだけ出力するようにしてください。-->
</p>
<H2>入力</H2>
<p>
入力は複数のデータセットからなります。各データセットは以下の形式で与えられます。
</p>
<pre>
<var>p<sub>0</sub></var> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> <var>p<sub>3</sub></var> <var>p<sub>4</sub></var> <var>p<sub>5</sub></var> <var>p<sub>6</sub></var> <var>p<sub>7</sub></var>
</pre>
<p>
乗り場 0, 1, ..., 7 で待っているお客様の人数を表す整数 <var>p<sub>0</sub></var>, <var>p<sub>1</sub></var>,... , <var>p<sub>7</sub></var> ( 0 ≤ <var>p<sub>i</sub></var> ≤ 10,000) が空白区切りで1行に与えられます。
</p>
<H2>出力</H2>
<p>
メリーゴーランドの乗り物の馬車を 4、車を 2、馬を 1 で表すこととします。乗り場 0, 1, ... , 7 にとめる乗り物を、それぞれ <var>c<sub>0</sub></var>, <var>c<sub>1</sub></var>,..., <var>c<sub>7</sub></var> とします。データセットごとに、<var>c<sub>0</sub></var>, <var>c<sub>1</sub></var>,..., <var>c<sub>7</sub></var> を空白区切りで 1 行に出力します。
</p>
<p>
なお、乗れなくなるお客さまが最小となるとめ方が複数ある場合は、<var>c<sub>0</sub>c<sub>1</sub>c<sub>2</sub>c<sub>3</sub>c<sub>4</sub>c<sub>5</sub>c<sub>6</sub>c<sub>7</sub></var> を 8 桁の整数 <var>V</var> とみなし、<var>V</var> が最小となるとめ方を選ぶものとします。
</p>
<p>
データセットの数は 100 を超えません。
</p>
<H2>Sample Input</H2>
<pre>
2 3 1 4 0 1 0 1
4 2 3 2 2 2 1 1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 4 1 4 1 2 1 2
4 1 4 1 2 1 2 1
</pre>
|
p01040 | <h1>Problem D: Friday the 13th</h1>
<h2>Problem</h2>
<p>
今年も「立命館大学競技プログラミング合宿」が開催されることとなった。僕は毎年開催されるこの合宿をとても楽しみにしている。しかし、欲望に耐え切れず合宿前に散財してしまい、お金に余裕が無くなってしまった。そこで僕は、立命館大学の最寄り駅である南草津まで移動するのに最も安く済む青春18きっぷを使うことにした。この切符は安く済む代わりに乗り換えが多く発生し、移動に丸1日使わなければならないのでとても疲れる。そんな移動をする日が13日の金曜日であることに気づいたのは会津若松駅を出発した後だった。僕は12時間、不安を感じながら電車に揺られるはめになった。
</p>
<p>
今日は合宿2日目、2015年3月15日、日曜日である。13日は特に何事もなく南草津に到着したが、僕はもうこのような不安を味わいたくないと思った。そこで2日目のジャッジである僕は、指定された期間内に存在する13日の金曜日の数を求める問題を出題し、プログラムを作成してもらうことにした。
</p>
<p>
閏(うるう)年の定義は以下の通りである。
</p>
<ul>
<li>西暦年が4で割り切れる年は閏年である。</li>
<li>ただし、100で割り切れる年は閏年でない。</li>
<li>ただし、400で割り切れる年は閏年である。</li>
</ul>
<h2>Input</h2>
<p>
空白で区切られた6つの整数<var>Y<sub>1</sub></var>, <var>M<sub>1</sub></var>, <var>D<sub>1</sub></var>, <var>Y<sub>2</sub></var>, <var>M<sub>2</sub></var>, <var>D<sub>2</sub></var>が1行で与えられる。
</p>
<h2>Constraints</h2>
<p>
入力は以下の制約を満たす。
</p>
<ul>
<li>1 ≤ <var>Y<sub>1</sub></var> ≤ <var>Y<sub>2</sub></var> ≤ 10<sup>18</sup></li>
<li>1 ≤ <var>M<sub>i</sub></var> ≤ 12</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 31 (<var>M<sub>i</sub></var> = 1, 3, 5, 7, 8, 10, 12)</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 30 (<var>M<sub>i</sub></var> = 4, 6, 9, 11)</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 28 (<var>M<sub>i</sub></var> = 2 かつ <var>Y<sub>i</sub></var>年は閏年でない)</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 29 (<var>M<sub>i</sub></var> = 2 かつ <var>Y<sub>i</sub></var>年は閏年である)</li>
<li><var>Y<sub>1</sub></var>年<var>M<sub>1</sub></var>月<var>D<sub>1</sub></var>日は<var>Y<sub>2</sub></var>年<var>M<sub>2</sub></var>月<var>D<sub>2</sub></var>日より0日以上前の日付である</li>
</ul>
<h2>Output</h2>
<p>
<var>Y<sub>1</sub></var>年<var>M<sub>1</sub></var>月<var>D<sub>1</sub></var>日から<var>Y<sub>2</sub></var>年<var>M<sub>2</sub></var>月<var>D<sub>2</sub></var>日までの間に存在する13日の金曜日の数を1行に出力せよ。
</p>
<h2>Sample Input1</h2>
<pre>
2015 3 13 2015 3 13
</pre>
<h2>Sample Output1</h2>
<pre>
1
</pre>
<h2>Sample Input2</h2>
<pre>
2015 2 14 2015 3 15
</pre>
<h2>Sample Output2</h2>
<pre>
1
</pre>
<h2>Sample Input3</h2>
<pre>
1234 5 6 789012345678901234 5 6
</pre>
<h2>Sample Output3</h2>
<pre>
1357101234567708000
</pre>
|
p03587 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke prepared <var>6</var> problems for a upcoming programming contest.
For each of those problems, Rng judged whether it can be used in the contest or not.</p>
<p>You are given a string <var>S</var> of length <var>6</var>.
If the <var>i</var>-th character of <var>s</var> is <code>1</code>, it means that the <var>i</var>-th problem prepared by Snuke is accepted to be used; <code>0</code> means that the problem is not accepted.</p>
<p>How many problems prepared by Snuke are accepted to be used in the contest?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>S</var> is <var>6</var>.</li>
<li><var>S</var> consists of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the number of problems prepared by Snuke that are accepted to be used in the contest.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>111100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The first, second, third and fourth problems are accepted, for a total of four.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>001001
</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>000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01410 |
<H1>D: Dangerous Tower</H1>
<p>
ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした.
</p>
<p>
今日の修行は,積み木を丁寧に積み上げることによって,決してミスタイピングをしないほどの手先の器用さを手に入れようというものである.せっかく積み木がたくさんあるので,高い塔を作ろう.
</p>
<p>
積み木は <i>N</i> 個あり,<i>i</i> 番目 (1 ≤ <i>i</i> ≤ <i>N</i>) の積み木は 1 × <i>A</i><sub><i>i</i></sub> × <i>B</i><sub><i>i</i></sub> の直方体の形をしている.長さ 1 の辺は奥行き方向に用いて,長さ <i>A</i><sub><i>i</i></sub>, <i>B</i><sub><i>i</i></sub> の辺を横方向と高さ方向に 1 つずつ割り当てることにした.積み木を積み上げるとき,上の段の積み木は下の段の積み木より横の長さが厳密に短くなければならない.積み木は好きな順番に使うことができ,また,使わない積み木があってもよい.このような制約下で,作ることが可能な最も高い塔を作りたい.
</p>
<H2>Input</H2>
<pre>
<i>N</i>
<i>A</i><sub>1</sub> <i>B</i><sub>1</sub>
...
<i>A</i><sub><i>N</i></sub> <i>B</i><sub><i>N</i></sub>
</pre>
<p>
1 ≤ <i>N</i> ≤ 1,000,1 ≤ <i>A</i><sub><i>i</i></sub>,<i>B</i><sub><i>i</i></sub> ≤ 1,000,000 を満たす.入力の値はすべて整数である.
</p>
<H2>Output</H2>
<p>
塔の高さの最大値を 1 行に出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
3
10 40
10 40
20 30
</pre>
<H2>Sample Output 1</H2>
<pre>
80
</pre>
<H2>Sample Input 2</H2>
<pre>
4
1 2
2 3
3 4
4 1
</pre>
<H2>Sample Output 2</H2>
<pre>
11
</pre> |
p00651 |
<h1>Problem E: Legend of Storia</h1>
<p>
In Storia Kingdom, there is an artifact called "Perfect Sphere" made by a great meister Es. This is handed down for generations in the royal palace as a treasure. Es left a memo and filled mysterious values in it. Within achievements of researches, it has been revealed that the values denote coordinate values. However it is still unknown the definition of the coordinate system.
</p>
<p>
By the way, you are a person who lived in age of Es lived. The values which meister Es left are defined by following. Es set an moving object in the artifact sphere. Surprisingly, that is rigid body and perpetual organization. The object rotates inside the sphere and it is always touching the inside surface of the sphere. This value is a coordinate of the tangent point by the object and the sphere, but it is not a three dimensional value. The object is a plate and this is a simple polygon. Here, "simple" means "non self-intersected". This rotates while touching a great circle of the sphere. Here, assume that the great circle is a circle <i>O</i> centered in the origin in the xy plane. (It is two-dimensional Cartesian coordinate system, the direction of positive x-value is right and the direction of positive y-value is up). This plate touches the circle <i>O</i> with a single point at the beginning of the movement. And it rotates in counterclockwise as the current touching point is the rotation fulcrum. When another point <i>X</i> of the plate touches the circle <i>O</i> newly, the plate continue to rotate as described above, but in the next rotation, the rotation fulcrum point is changed. This will be the point <i>X</i>. If two or more points can be interpreted as the point <i>X</i>, the point <i>X</i> is a most distant point from the currently touching point <i>X'</i>. Here, that distance is the length of the arc of the circle <i>O</i> from the point <i>X'</i> to the point <i>X</i> in clockwise.
</p>
<p>
Es asked you, an excellent assistant, to write a program that enumerates <i>Q</i> tangent points (fulcrum points while the movement) by the plate and the circle <i>O</i> while the movement of the plate described above in the chronological order. Of course, one and the previous one must be distinct points. Following figures show you examples of the movement of the plate inside the circle <i>O</i>.
<br>
1<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E1"><br>
2<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E2"><br>
3<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E3"><br>
4<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E4"><br>
</p>
<h2>Input</h2>
<p>
Input consists of multiple datasets.<br>
A dataset is given in a following format.
</p>
<pre>
<i>N</i> <i>R</i> <i>Q</i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i>
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i>
...
<i>x<sub>N</sub></i> <i>y<sub>N</sub></i>
</pre>
<p>
<i>N</i>, <i>R</i>, <i>Q</i> are integers that represent the number of points of the plate, the radius of the circle, and the number of points Es needs respectively.<br>
Following <i>N</i> lines contain 2<i>N</i> integers that represent coordinates of the plate's points ( <i>x<sub>k</sub></i> , <i>y<sub>k</sub></i> ) in the circle.(1≤<i>k</i>≤<i>N</i>)<br>
</p>
<ul>
You can assume following conditions.
<li>Points of the plate are given in counterclockwise.</li>
<li>No three points are co-linear.</li>
<li><i>N</i>-1 points of the plate are given inside of the circle (distances between the center of the circle and these points are less than <i>R</i>). And 1 point is on the circle edge.</li>
<i>N</i>=<i>R</i>=<i>Q</i>=0 shows the end of input.
</ul>
</p>
<h2>Constraints</h2>
<p>
The number of datasets is less than or equal to 400.<br>
3≤<i>N</i>≤25<br>
1≤<i>R</i>≤1000<br>
0≤<i>Q</i>≤100
</p>
<h2>Output</h2>
<p>
For each dataset, output (<i>Px</i> <i>Py</i>:real number) in <i>Q</i> in the following format.
</p>
<pre>
<i>Px<sub>1</sub></i> <i>Px<sub>1</sub></i>
<i>Px<sub>2</sub></i> <i>Py<sub>2</sub></i>
...
<i>Px<sub>N+1</sub></i> <i>Py<sub>N+1</sub></i>
</pre>
<p>
These answers must satisfy |<i>Tx<sub>i</sub></i>-<i>Px<sub>i</sub></i>|≤0.0001 and |<i>Ty<sub>i</sub></i>-<i>Py<sub>i</sub></i>|≤0.0001.<br>
Here, <i>Px<sub>i</sub></i>, <i>Py<sub>i</sub></i>(1≤<i>i</i>≤<i>Q</i>) are your output and <i>Tx<sub>i</sub></i>,<i>Ty<sub>i</sub></i>(1≤<i>i</i>≤<i>Q</i>) are judge's output.
</p>
<h2>Sample Input</h2>
<pre>
4 10 8
0 -10
3 -7
0 -4
-3 -7
0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
-4.146082488326 -9.100000000000
-7.545870128753 -6.562000000000
-9.587401146004 -2.842840000000
-9.903199956975 1.388031200000
-8.436422775690 5.369056784000
-5.451089494781 8.383652146880
-1.484560104812 9.889190123322
2.749190104024 9.614673877565
</pre> |
p01943 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], skipTags: ["script","noscript","style","textarea","code"]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h2>F: 掛け算は楽しい - Multiplication Is Interesting -</h2>
<h3>物語</h3>
<p>男子高生の難波列くんは、彼女の誕生日に数列をプレゼントしようと考えている。彼女は掛け算が大好きな女の子なので、難波くんは彼女にできるだけ多くの掛け算を楽しんてもらえるような数列をプレゼントしたいと思っている。しかし、計算結果が <var>2^{20}</var> を超える値になると彼女の機嫌が途端に悪くなってしまう(通常の人類は <var>2^{20}</var>という膨大な数を計算できないため、これでも彼女は随分と寛大な人であると言える)。彼女の機嫌を損なわないように、できるだけ多くの掛け算を楽しんでもらえる数列を難波くんが作ったので、あなたの仕事はその数列が彼女を十分に楽しませられるか検証するプログラムを作ることである。つまり、あなたの仕事は数列の連続する部分列の中で、部分列の総積が <var>K</var> を超えない最長の部分列の長さを答えるプログラムを作ることである。</p>
<h3>問題</h3>
<p>長さ <var>N</var> の非負実数列 <var>S = s_1, s_2, ..., s_N</var> と 非負実数 <var>K</var> がある。 あなたの仕事は、以下の条件を満たす <var>S</var> の連続する部分列のうち、次の条件を満たす最長の部分列の長さを求めることである。このとき、部分列の長さは <var>1</var> 以上でなければならない。</p>
<ul>
<li> <var>S</var> の連続する部分列 $T = s_\ell, \ldots, s_r$ について $\prod_{i = \ell, \ldots, r} s_i \leq$ <var>K</var>を満たす。</li>
</ul>
<p>もし条件を満たす部分列が一つも存在しないときは、 <var>0</var> を出力せよ。</p>
<h3>入力形式</h3>
<p>入力は次の形式で与えられる.</p>
<pre>
<var>N</var> <var>K</var>
<var>s_1</var>
<var>s_2</var>
$\dots$
<var>s_N</var>
</pre>
<p><var>1</var> 行目には数列の長さ <var>N</var> と 部分列の総積の上限 <var>K</var> が与えられる。続く <var>N</var> 行のうち、 <var>i</var> 行目では非負実数列 <var>S</var> の <var>i</var> 番目の実数 <var>s_i</var> が与えられる。</p>
<h3>制約</h3>
<ul>
<li> <var>1 \leq N \leq 100,000</var> </li>
<li> <var>0 \leq s_i \leq 2.00</var> </li>
<li> <var>0 \leq K \leq 1,048,576</var></li>
<li> <var>N</var> は整数、<var>K</var> と <var>s_i</var> は小数点第 <var>3</var> 位以下を含まない実数である</li>
</ul>
<h3>出力形式</h3>
<p><var>S</var> の部分列の総積が <var>K</var> を超えない最長の部分列の長さを <var>1</var> 行に出力せよ。</p>
<h3>入力例1</h3>
<pre>
6 2.01
1.10
1.44
0.91
2.00
1.12
1.55
</pre>
<h3>出力例1</h3>
<pre>3</pre>
<h3>入力例2</h3>
<pre>
8 12.22
2.00
2.00
2.00
1.91
2.00
2.00
2.00
0.01
</pre>
<h3>出力例2</h3>
<pre>8</pre> |
p02396 |
<H1>Print Test Cases</H1>
<p>
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.
</p>
<p>
Write a program which reads an integer <var>x</var> and print it as is. Note that multiple datasets are given for this problem.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of an integer <var>x</var> in a line.
</p>
<p>
The input ends with an integer 0. You program should not process (print) for this terminal symbol.
</p>
<H2>Output</H2>
<p>
For each dataset, print <var>x</var> in the following format:
</p>
<pre>
Case i: x
</pre>
<p>
where <var>i</var> is the case number which starts with 1. Put a single space between "Case" and <var>i</var>. Also, put a single space between ':' and <var>x</var>.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <var>x</var> ≤ 10000</li>
<li>The number of datasets ≤ 10000</li>
</ul>
<H2>Sample Input</H2>
<pre>
3
5
11
7
8
19
0
</pre>
<H2>Sample Output</H2>
<pre>
Case 1: 3
Case 2: 5
Case 3: 11
Case 4: 7
Case 5: 8
Case 6: 19
</pre> |
p00201 |
<h1>錬金マスター</h1>
<p>
あなたはついに魔法の釜、錬金釜を手に入れました。錬金釜に複数のアイテムを入れると、新しいア イテムを作ることができます。新しく作ったアイテムは、他のアイテムを作るために錬金釜へ入れることもできます。アイテムを作るために必要なアイテムのリストを記したものを錬金レシピと呼ぶことにします。以下の 3 つは錬金レシピの例です。
</p>
<ol>
<li> 木片と糸でラケットができる。</li>
<li> お米と水でおにぎりができる。</li>
<li> ラケットとマイクとおにぎりでギターができる。</li>
</ol>
<p>
アイテムはお金を使って手にいれることもできますが、錬金釜で作った方が安くすむ場合もあります。例えば、各アイテムの購入価格が以下のように与えられているとします。
</p>
<center>
<table border=1 cellpadding=8 cellspacing=2>
<tr><td width=140>アイテム名</td><td width=140> 購入価格(円)</td></tr>
<tr><td> 木片 </td><td> 3,000</td></tr>
<tr><td> 糸 </td><td> 800</td></tr>
<tr><td> お米 </td><td> 36</td></tr>
<tr><td> 水 </td><td> 0</td></tr>
<tr><td> ラケット </td><td> 5,000</td></tr>
<tr><td> マイク </td><td> 9,800</td></tr>
<tr><td> おにぎり </td><td> 140</td></tr>
<tr><td> ギター </td><td> 98,000</td></tr>
</tr>
</table>
<br/>
</center>
<p>
ラケットは 5,000 円で購入できますが、木片と糸を購入して錬金すれば 3,800 円で手に入れられます。更に、錬金を重ねることによりとてもお得にアイテムを手に入れられます。図 1 は上記 3 つの錬金レシピ例を組み合わせたものです。ギターは 98,000 円で購入できますが、木片、糸、お米、水、マイクを購入して錬金すれば、たったの 13,636 円で手に入れられます。
</p>
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_recipe">
<p>図 1</p>
</center>
<br><br>
<p>
あなたは冒険を楽に進めるため、なるべく安く目的のアイテムを手に入れようと考えました。 アイテムのリスト、錬金レシピのリスト、指定されたアイテムを入力とし、指定されたアイテムを作るために必要な金額の最小値を出力するプログラムを作成して下さい。
</p>
<!--
<p>
アイテムリストに含まれるアイテムの種類 <var>n</var> は 1 以上 100 以下の整数とし、各アイテムを購入する場合の値段 <var>p</var> は 0 以上 1000000 以下とします。アイテムの名前 <var>i</var> は 1 文字以上 100 文字以下のアルファベットからなる半角文字列です。錬金レシピの種類 <var>m</var> は 0 以上 100 以下の整数です。 1つの錬金レシピはアイテムの名前 <var>o</var>、それを作るために必要なアイテムの個数 <var>k</var> 、 <var>k</var> 個のアイテム名 <var>q</var> のリストによって与えられます。<var>k</var> は 100 以下とします。
</p>
-->
<p>
各アイテムの数量に限りはないものとします。アイテムは複数のレシピに使われることがありますが、1 つのアイテムを作るためのレシピはたかだか 1 つです。また、あるアイテムを起点としてレシピをたどっていったとき、そのアイテムが再びレシピに現れることはありません。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>s<sub>1</sub></var> <var>p<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>p<sub>2</sub></var>
:
<var>s<sub>n</sub></var> <var>p<sub>n</sub></var>
<var>m</var>
<var>o<sub>1</sub></var> <var>k<sub>1</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>1</sub></sub></var>
<var>o<sub>2</sub></var> <var>k<sub>2</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>2</sub></sub></var>
:
<var>o<sub>m</sub></var> <var>k<sub>m</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>m</sub></sub></var>
<var>t</var>
</pre>
<p>
1 行目にリストに含まれるアイテムの種類数 <var>n</var> (1 ≤ <var>n</var> ≤ 100) が与えられます。続く <var>n</var> 行に <var>i</var> 番目のアイテムの名前 <var>s<sub>i</sub></var> (1 文字以上 100 文字以下のアルファベットからなる半角文字列) とそれを購入する場合の値段 <var>p<sub>i</sub></var> (0 ≤ <var>p<sub>i</sub></var> ≤ 1000000)が与えられます。
</p>
<p>
続く行に錬金レシピの数 <var>m</var> (0 ≤ <var>m</var> ≤ 100) が与えられます。続く <var>m</var> 行に <var>i</var> 番目のレシピの情報が与えられます。各レシピとして、アイテムの名前 <var>o<sub>i</sub></var>、それを作るために必要なアイテムの個数 <var>k<sub>i</sub></var> (1 ≤ <var>k<sub>i</sub></var> ≤ 100) 、 <var>k<sub>i</sub></var> 個のアイテム名 <var>q<sub>1</sub></var>, <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>i</sub></var> が与えられます。
</p>
<p>
最後の行に指定されたアイテム名 <var>t</var> が与えられます。
</p>
<p>
データセットの数は 30 を超えません。
</p>
<H2>Output</H2>
<p>
入力データセットごとに、最小の値段を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
8
wood 3000
string 800
rice 36
water 0
racket 5000
microphone 9800
onigiri 140
guitar 98000
3
racket 2 wood string
onigiri 2 rice water
guitar 3 racket microphone onigiri
guitar
1
computer 300000
0
computer
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
13636
300000
</pre>
|
p02729 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have <var>N+M</var> balls, each of which has an integer written on it.<br/>
It is known that: </p>
<ul>
<li>The numbers written on <var>N</var> of the balls are even.</li>
<li>The numbers written on <var>M</var> of the balls are odd.</li>
</ul>
<p>Find the number of ways to choose two of the <var>N+M</var> balls (disregarding order) so that the sum of the numbers written on them is even.<br/>
It can be shown that this count does not depend on the actual values written on the balls.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>0 \leq N,M \leq 100</var></li>
<li><var>2 \leq N+M</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>For example, let us assume that the numbers written on the three balls are <var>1,2,4</var>.</p>
<ul>
<li>If we choose the two balls with <var>1</var> and <var>2</var>, the sum is odd;</li>
<li>If we choose the two balls with <var>1</var> and <var>4</var>, the sum is odd;</li>
<li>If we choose the two balls with <var>2</var> and <var>4</var>, the sum is even.</li>
</ul>
<p>Thus, the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>13 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>81
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>0 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>3
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.