question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p01848 |
<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>JAG夏合宿の朝は早い.
正確にはそこまで早くないが,早いと感じる参加者が多いという.
</p>
<p>例年合宿の会場となる施設では,退去時に参加者がシーツの回収や掃除をしなければならない.
1 つの部屋でも退去が遅れると,来年以降の施設の利用に関わるため,参加者は一人たりとも寝坊してはならない.
</p>
<p>そうは言っても皆人間,寝坊することもある.
しかし,起きた人が連絡先を知っている人にモーニングコールをすることで,一人も寝坊しないよう努めることができるはずだ.
</p>
<p>JAG夏合宿の運営を任されたあなたは,寝坊を絶対に防ぐ手を打つための前準備として,どのくらいの確率で全員がきちんと起きられるのかを調べることにした.
準備としてまず,各参加者の寝坊する確率と,各々が連絡先を知っている人のリストを入手した.
ここで,部屋は個室であるため,各々が寝坊するか否かは,他の参加者が寝坊するか否かとは独立である.
起きた人は必ずすべての知っている連絡先にモーニングコールをすること,また,モーニングコールを受けた人は必ず起きることを仮定するとき,全員がきちんと起きられる確率をこれらの情報から計算せよ.
</p>
<h3>Input</h3>
<p>入力は複数のデータセットからなる. 各データセットは次の形式で表される.
</p><blockquote><i>N</i><br><i>p<sub>1</sub></i> <i>m<sub>1</sub></i> <i>a<sub>(1,1)</sub></i> ... <i>a<sub>(1, m<sub>1</sub>)</sub></i><br>...<br><i>p<sub>N</sub></i> <i>m<sub>N</sub></i> <i>a<sub>(N,1)</sub></i> ... <i>a<sub>(N, m<sub>N</sub>)</sub></i></blockquote>
<p><i>N</i> は参加者の数であり,100 を越えない正の整数である.<i>p<sub>i</sub></i> は <i>i</i> 番目の参加者の寝坊する確率であり,小数点以下 2 桁以内の 0 以上 1 以下の実数である.<i>m<sub>i</sub></i> は <i>i</i> 番目の参加者が知っている連絡先の数であり,0 以上 <i>N</i> 以下の整数である.<i>a<sub>(i, j)</sub></i> は <i>i</i> 番目の参加者が知っている <i>j</i> 番目の連絡先が <i>a<sub>(i, j)</sub></i> 番目の参加者のものであることを表す.<i>a<sub>(i, j)</sub></i> は <i>N</i> を越えない正の整数である.
</p>
<p>入力の終わりは,1 つのゼロからなる行で示す.
</p>
<h3>Output</h3>
<p>各データセットについて,全員が起床できる確率を 1 行に出力せよ.出力には 0.00001 以上の誤差を含んではならない.
</p>
<h3>Sample Input</h3>
<pre>2
0.60 1 2
0.60 0
2
0.60 1 2
0.60 1 1
5
0.10 1 2
0.20 1 3
0.30 1 4
0.40 1 5
0.50 1 1
5
0.10 0
0.20 1 1
0.30 1 1
0.40 1 1
0.50 1 1
5
0.10 4 2 3 4 5
0.20 0
0.30 0
0.40 0
0.50 0
4
0.10 1 2
0.20 0
0.30 1 4
0.40 1 3
5
0.10 0
0.20 0
0.30 0
0.40 0
0.50 0
0</pre>
<h3>Output for Sample Input</h3>
<pre>0.400000000
0.640000000
0.998800000
0.168000000
0.900000000
0.792000000
0.151200000</pre> |
p03875 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>Snuke received two matrices <var>A</var> and <var>B</var> as birthday presents.
Each of the matrices is an <var>N</var> by <var>N</var> matrix that consists of only <var>0</var> and <var>1</var>.</p>
<p>Then he computed the product of the two matrices, <var>C = AB</var>.
Since he performed all computations in modulo two, <var>C</var> was also an <var>N</var> by <var>N</var> matrix that consists of only <var>0</var> and <var>1</var>.
For each <var>1 ≤ i, j ≤ N</var>, you are given <var>c_{i, j}</var>, the <var>(i, j)</var>-element of the matrix <var>C</var>.</p>
<p>However, Snuke accidentally ate the two matrices <var>A</var> and <var>B</var>, and now he only knows <var>C</var>.
Compute the number of possible (ordered) pairs of the two matrices <var>A</var> and <var>B</var>, modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ N ≤ 300</var></li>
<li><var>c_{i, j}</var> is either <var>0</var> or <var>1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>c_{1, 1}</var> <var>...</var> <var>c_{1, N}</var>
:
<var>c_{N, 1}</var> <var>...</var> <var>c_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible (ordered) pairs of two matrices <var>A</var> and <var>B</var> (modulo <var>10^9+7</var>).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
1 0 0 1 1 1 0 0 1 0
0 0 0 1 1 0 0 0 1 0
0 0 1 1 1 1 1 1 1 1
0 1 0 1 0 0 0 1 1 0
0 0 1 0 1 1 1 1 1 1
1 0 0 0 0 1 0 0 0 0
1 1 1 0 1 0 0 0 0 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 1 0 0 0 0
1 0 1 0 0 1 1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>741992411
</pre></section>
</div>
</span> |
p03526 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In the final of CODE FESTIVAL in some year, there are <var>N</var> participants.
The <em>height</em> and <em>power</em> of Participant <var>i</var> is <var>H_i</var> and <var>P_i</var>, respectively.</p>
<p>Ringo is hosting a game of stacking zabuton (cushions).</p>
<p>The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton.
Initially, the stack is empty.
When it is Participant <var>i</var>'s turn, if there are <var>H_i</var> or less zabuton already stacked, he/she will add exactly <var>P_i</var> zabuton to the stack. Otherwise, he/she will give up and do nothing.</p>
<p>Ringo wants to maximize the number of participants who can add zabuton to the stack.
How many participants can add zabuton to the stack in the optimal order of participants?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 5000</var></li>
<li><var>0 \leq H_i \leq 10^9</var></li>
<li><var>1 \leq P_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>P_1</var>
<var>H_2</var> <var>P_2</var>
<var>:</var>
<var>H_N</var> <var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of participants who can add zabuton to the stack.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 2
1 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>When the participants line up in the same order as the input, Participants <var>1</var> and <var>3</var> will be able to add zabuton.</p>
<p>On the other hand, there is no order such that all three participants can add zabuton. Thus, the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 4
3 1
4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>When the participants line up in the order <var>2</var>, <var>3</var>, <var>1</var>, all of them will be able to add zabuton.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1 3
8 4
8 3
9 1
6 4
2 3
4 2
9 2
8 3
0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p03176 | <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> flowers arranged in a row.
For each <var>i</var> (<var>1 \leq i \leq N</var>), the height and the beauty of the <var>i</var>-th flower from the left is <var>h_i</var> and <var>a_i</var>, respectively.
Here, <var>h_1, h_2, \ldots, h_N</var> are all distinct.</p>
<p>Taro is pulling out some flowers so that the following condition is met:</p>
<ul>
<li>The heights of the remaining flowers are monotonically increasing from left to right.</li>
</ul>
<p>Find the maximum possible sum of the beauties of the remaining flowers.</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 2 × 10^5</var></li>
<li><var>1 \leq h_i \leq N</var></li>
<li><var>h_1, h_2, \ldots, h_N</var> are all distinct.</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>h_1</var> <var>h_2</var> <var>\ldots</var> <var>h_N</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 maximum possible sum of the beauties of the remaining flowers.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 1 4 2
10 20 30 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>60
</pre>
<p>We should keep the second and fourth flowers from the left.
Then, the heights would be <var>1, 2</var> from left to right, which is monotonically increasing, and the sum of the beauties would be <var>20 + 40 = 60</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
1
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
<p>The condition is met already at the beginning.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1 2 3 4 5
1000000000 1000000000 1000000000 1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5000000000
</pre>
<p>The answer may not fit into a 32-bit integer type.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>9
4 2 5 8 3 6 1 7 9
6 8 8 4 6 3 5 7 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>31
</pre>
<p>We should keep the second, third, sixth, eighth and ninth flowers from the left.</p></section>
</div>
</span> |
p03199 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has an <var>N \times N</var> grid. The square at the <var>i</var>-th row and the <var>j</var>-th column of the grid is denoted by <var>(i,j)</var>.
Particularly, the top-left square of the grid is <var>(1,1)</var>, and the bottom-right square is <var>(N,N)</var>.</p>
<p>An integer, <var>0</var> or <var>1</var>, is written on <var>M</var> of the squares in the Takahashi's grid.
Three integers <var>a_i,b_i</var> and <var>c_i</var> describe the <var>i</var>-th of those squares with integers written on them: the integer <var>c_i</var> is written on the square <var>(a_i,b_i)</var>.</p>
<p>Takahashi decides to write an integer, <var>0</var> or <var>1</var>, on each of the remaining squares so that the condition below is satisfied.
Find the number of such ways to write integers, modulo <var>998244353</var>.</p>
<ul>
<li>For all <var>1\leq i < j\leq N</var>, there are even number of <var>1</var>s in the square region whose top-left square is <var>(i,i)</var> and whose bottom-right square is <var>(j,j)</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>0 \leq M \leq min(5 \times 10^4,N^2)</var></li>
<li><var>1 \leq a_i,b_i \leq N(1\leq i\leq M)</var></li>
<li><var>0 \leq c_i \leq 1(1\leq i\leq M)</var></li>
<li>If <var>i \neq j</var>, then <var>(a_i,b_i) \neq (a_j,b_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>a_1</var> <var>b_1</var> <var>c_1</var>
<var>:</var>
<var>a_M</var> <var>b_M</var> <var>c_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible ways to write integers, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 1 1
3 1 0
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>For example, the following ways to write integers satisfy the condition:</p>
<pre>101 111
011 111
000 011
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5
1 3 1
2 4 0
2 3 1
4 2 1
4 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>32
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 5
1 3 1
3 3 0
3 1 0
2 3 1
3 2 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>4 8
1 1 1
1 2 0
3 2 1
1 4 0
2 1 1
1 3 0
3 4 1
4 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>100000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>342016343
</pre></section>
</div>
</span> |
p03463 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A game is played on a strip consisting of <var>N</var> cells consecutively numbered from 1 to <var>N</var>. </p>
<p>Alice has her token on cell <var>A</var>. Borys has his token on a different cell <var>B</var>.</p>
<p>Players take turns, Alice moves first.
The moving player must shift his or her token from its current cell <var>X</var> to the neighboring cell on the left, cell <var>X-1</var>, or on the right, cell <var>X+1</var>.
Note that it's disallowed to move the token outside the strip or to the cell with the other player's token.
In one turn, the token of the moving player must be shifted exactly once.</p>
<p>The player who can't make a move loses, and the other player wins.</p>
<p>Both players want to win. Who wins if they play optimally?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100</var></li>
<li><var>1 \leq A < B \leq N</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Alice</code> if Alice wins, <code>Borys</code> if Borys wins, and <code>Draw</code> if nobody wins.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Alice
</pre>
<p>Alice can move her token to cell 3.
After that, Borys will be unable to move his token to cell 3, so he will have to move his token to cell 5.
Then, Alice moves her token to cell 4. Borys can't make a move and loses. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Borys
</pre>
<p>Alice can't make the very first move and loses.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>58 23 42
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Borys
</pre></section>
</div>
</span> |
p03033 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an infinitely long street that runs west to east, which we consider as a number line.</p>
<p>There are <var>N</var> roadworks scheduled on this street.
The <var>i</var>-th roadwork blocks the point at coordinate <var>X_i</var> from time <var>S_i - 0.5</var> to time <var>T_i - 0.5</var>.</p>
<p><var>Q</var> people are standing at coordinate <var>0</var>. The <var>i</var>-th person will start the coordinate <var>0</var> at time <var>D_i</var>, continue to walk with speed <var>1</var> in the positive direction and stop walking when reaching a blocked point.</p>
<p>Find the distance each of the <var>Q</var> people will walk.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N, Q \leq 2 \times 10^5</var></li>
<li><var>0 \leq S_i < T_i \leq 10^9</var></li>
<li><var>1 \leq X_i \leq 10^9</var></li>
<li><var>0 \leq D_1 < D_2 < ... < D_Q \leq 10^9</var></li>
<li>If <var>i \neq j</var> and <var>X_i = X_j</var>, the intervals <var>[S_i, T_i)</var> and <var>[S_j, T_j)</var> do not overlap.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Q</var>
<var>S_1</var> <var>T_1</var> <var>X_1</var>
<var>:</var>
<var>S_N</var> <var>T_N</var> <var>X_N</var>
<var>D_1</var>
<var>:</var>
<var>D_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the distance the <var>i</var>-th person will walk or <var>-1</var> if that person walks forever.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
2
10
-1
13
-1
</pre>
<p>The first person starts coordinate <var>0</var> at time <var>0</var> and stops walking at coordinate <var>2</var> when reaching a point blocked by the first roadwork at time <var>2</var>.</p>
<p>The second person starts coordinate <var>0</var> at time <var>1</var> and reaches coordinate <var>2</var> at time <var>3</var>. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate <var>2</var>.</p>
<p>The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is <var>-1</var>.</p></section>
</div>
</span> |
p02788 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Silver Fox is fighting with <var>N</var> monsters.</p>
<p>The monsters are standing in a row, and we can assume them to be standing on a number line. The <var>i</var>-th monster, standing at the coordinate <var>X_i</var>, has the <em>health</em> of <var>H_i</var>.</p>
<p>Silver Fox can use bombs to attack the monsters.
Using a bomb at the coordinate <var>x</var> decreases the healths of all monsters between the coordinates <var>x-D</var> and <var>x+D</var> (inclusive) by <var>A</var>.
There is no way other than bombs to decrease the monster's health.</p>
<p>Silver Fox wins when all the monsters' healths become <var>0</var> or below.</p>
<p>Find the minimum number of bombs needed to win.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>0 \leq D \leq 10^9</var></li>
<li><var>1 \leq A \leq 10^9</var></li>
<li><var>0 \leq X_i \leq 10^9</var></li>
<li><var>1 \leq H_i \leq 10^9</var></li>
<li><var>X_i</var> are distinct.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>D</var> <var>A</var>
<var>X_1</var> <var>H_1</var>
<var>:</var>
<var>X_N</var> <var>H_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of bombs needed to win.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 2
1 2
5 4
9 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>First, let us use a bomb at the coordinate <var>4</var> to decrease the first and second monsters' health by <var>2</var>.</p>
<p>Then, use a bomb at the coordinate <var>6</var> to decrease the second and third monsters' health by <var>2</var>.</p>
<p>Now, all the monsters' healths are <var>0</var>.
We cannot make all the monsters' health drop to <var>0</var> or below with just one bomb.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>We should use five bombs at the coordinate <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3000000000
</pre>
<p>Watch out for overflow.</p></section>
</div>
</span> |
p02272 |
<H1>Merge Sort</H1>
<p>
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function.
</p>
<pre>
Merge(A, left, mid, right)
n1 = mid - left;
n2 = right - mid;
create array L[0...n1], R[0...n2]
for i = 0 to n1-1
do L[i] = A[left + i]
for i = 0 to n2-1
do R[i] = A[mid + i]
L[n1] = SENTINEL
R[n2] = SENTINEL
i = 0;
j = 0;
for k = left to right-1
if L[i] <= R[j]
then A[k] = L[i]
i = i + 1
else A[k] = R[j]
j = j + 1
Merge-Sort(A, left, right){
if left+1 < right
then mid = (left + right)/2;
call Merge-Sort(A, left, mid)
call Merge-Sort(A, mid, right)
call Merge(A, left, mid, right)
</pre>
<H2>Input</H2>
<p>
In the first line <i>n</i> is given. In the second line, <i>n</i> integers are given.
</p>
<H2>Output</H2>
<p>
In the first line, print the sequence S. Two consequtive elements should be separated by a space character.
</p>
<p>
In the second line, print the number of comparisons.
</p>
<H2>Constraints</H2>
<ul>
<li>n ≤ 500000</li>
<li>0 ≤ an element in S ≤ 10<sup>9</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
10
8 5 9 2 6 3 7 1 10 4
</pre>
<H2>Sample Output 1</H2>
<pre>
1 2 3 4 5 6 7 8 9 10
34
</pre>
<H2>Notes</H2>
<!--
<a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a>
-->
|
p02622 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are strings <var>S</var> and <var>T</var>. Consider changing <var>S</var> to <var>T</var> by repeating the operation below. Find the minimum number of operations required to do so.</p>
<p>Operation: Choose one character of <var>S</var> and replace it with a different character.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> and <var>T</var> have lengths between <var>1</var> and <var>2\times 10^5</var> (inclusive).</li>
<li><var>S</var> and <var>T</var> consists of lowercase English letters.</li>
<li><var>S</var> and <var>T</var> have equal lengths.</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>T</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>cupofcoffee
cupofhottea
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>We can achieve the objective in four operations, such as the following:</p>
<ul>
<li>First, replace the sixth character <code>c</code> with <code>h</code>.</li>
<li>Second, replace the eighth character <code>f</code> with <code>t</code>.</li>
<li>Third, replace the ninth character <code>f</code> with <code>t</code>.</li>
<li>Fourth, replace the eleventh character <code>e</code> with <code>a</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abcde
bcdea
</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>apple
apple
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>No operations may be needed to achieve the objective.</p></section>
</div>
</span> |
p03930 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
<div class="part">
Max Score: $300$ Points <br/>
<section>
<h3>Problem Statement</h3>
We are playing a puzzle. An upright board with $H$ rows by $W$ columns of cells, is used in this puzzle. <br/>
A stone in $i$-th row and $j$-th column engraved with a digit, one of 1 through 9, is placed in each of the cells. <br/>
You can erase 1 cell in the board. <br/>
<br/>
The game process is following: <br/>
<ol class="simple">
<li>When $K$ or more stones in horizontally adjacent cells are engraved with the same digit, the stones will disappear. Disappearances of all such groups of stones take place simultaneously.</li>
<li>When stones are in the cells above the emptied cells, these stones drop down so that the emptied cells are filled.</li>
<li>After the completion of all stone drops, if one or more groups of stones satisfy the disappearance condition, repeat by returning to the step 1.</li>
<li>Score is $\sum_i 2^i \times \left(\text{Sum of numbers in the stones which disappeared in the $i$-th chain (0-indexed)}\right)$.</li>
</ol>
Please answer the points if he erased the optimal place.<br/>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
The input is given from standard input in the following format. </section></div></div></div></span> |
p01327 |
<h1><font color="#000">Problem G:</font> 天体観測</h1>
<p>
2012年のある日のこと。
北の田舎町に住むあなたは、愛娘を連れて展望台で星見をすることにした。
この町は都会と違って街明かりが少なく、空気も澄んでいるので、晴れた日は満天の星空が広がっている。
天文にそこそこ詳しいあなたは季節ごとの有名な星や星座、それにまつわる神話ぐらいは知っているのだが、
なにせここは星降る町、名前のわからない星座もたくさん見えている。
この前の星見のときにそういった星々に関する娘の質問に答えられなかったあなたは、
星見の時刻にいったいどの星座が見えるのかを調べたいと思った。
</p>
<p>
特定の日時にどの星が見えるのかを知るには、星座早見盤というアイテムが有用である。
最近では携帯端末のGPSと連携した星座早見盤アプリも提供されている。
だが、あいにくあなたの手元には星座早見盤がなく、携帯は七年前の機種で、最新のアプリが動くわけがなかった。
詰んだと思ったあなたが最後の望みをかけてハードディスクを漁ったところ、
なんと2012年1月1日の午前零時時点での各星座を構成する星々の位置を記したファイルを発見した。
これがあれば任意の日時の星の位置がわかるはず!
あなたは急いでどの星座が見えるのかを出力するプログラムを書くことにした。
</p>
<p>
星々の情報は、観測者を中心とした天球上の座標群として与えられている。
座標は方位角と高度のペアで表されている。
方位角は真北を0度、真東を90度というように時計回りに測った0度以上360度未満の角度であり、
高度は地平線上を0度、天頂を90度度、天底を-90度とした-90度以上90度以下の角度である。
各天体は北極星と観測者を結ぶ直線を回転軸として、天球上を一定速度で反時計回りに回転している。
その回転速度は24時間あたり(1+1/365.24)×360度である。
北極星は真北方向の高度43.2度の点にある。
</p>
<p>
ある星座が見えるとは、その星座を構成するすべての星が地平線より上にあることをいう。
テストデータにおいて、当該時刻に地平線から高度±0.01度以内に星があることはないとしてよい。
なお、地軸のズレ、天体との距離などは考えなくてよい。
また、2012年は閏年であることに注意せよ。
</p>
<h2>Input</h2>
<p>
入力は以下のような形式で与えられる。
</p>
<pre><i>mon</i>/<i>day</i> <i>hh</i>:<i>mm</i>
<i>n</i>
<i>name<sub>1</sub></i> <i>m<sub>1</sub></i>
<i>a<sub>11</sub></i> <i>h<sub>11</sub></i>
<i>a<sub>12</sub></i> <i>h<sub>12</sub></i>
...
<i>a<sub>1m<sub>1</sub></sub></i> <i>h<sub>1m<sub>1</sub></sub></i>
<i>name<sub>2</sub></i> <i>m<sub>2</sub></i>
<i>a<sub>21</sub></i> <i>h<sub>21</sub></i>
...
</pre>
<p>
一行目には星見をする2012年のある日時が24時制で与えられる。
二行目の <i>n</i> は見えるかどうか判定したい星座の数を表す。
残りの行はその <i>n</i> 個の星座の2012年1月1日 00:00時点での位置情報である。
各星座の情報の先頭行には、星座名 <i>name<sub>i</sub></i> と星座を構成する星の数 <i>m<sub>i</sub></i> が与えられる。
続く <i>m<sub>i</sub></i> 行に、各星の方位角 <i>a<sub>ij</sub></i> と高度 <i>h<sub>ij</sub></i> が与えられる。
これらの二つの数値は小数点以下三桁まで記述された浮動小数点数である。
</p>
<p>
入力の数値は、1 ≤ <i>n</i> ≤ 1000、1 ≤ <i>m<sub>i</sub></i> ≤ 1000、0.000 ≤ <i>a<sub>ij</sub></i> < 360.000、-90.000 ≤ <i>h<sub>ij</sub></i> ≤ 90.000を満たす。
また、星座名はアルファベットの大文字小文字からなり、長さが50文字を超えることはない。
サンプルにあるとおり、「夏の大三角」や「北斗七星」など、88星座に入っていないものが与えられることもある。
なお、時刻は日没後の時刻とはかぎらないが、気にせず星が見えるものとしてよい。
</p>
<h2>Output</h2>
<p>
入力に与えられた順に、指定された日時に見える星座の一覧を出力せよ。
一つも星座が見えないようなテストデータはないと仮定してよい。
</p>
<h2>Notes on Test Cases</h2>
<p>
上記入力形式で複数のデータセットが与えられます。
</p>
<p>
入力の1行目にデータセットの数Tが与えられます。
</p>
<p>
各データセットに対して上記出力形式で出力を行うプログラムを作成して下さい。
</p>
<h2>Sample Input</h2>
<pre>
3
7/7 18:30
3
Aquila 8
359.216 -32.936
358.624 -49.913
352.155 -43.404
346.852 -35.279
345.110 -36.796
342.448 -44.407
343.088 -38.981
336.070 -43.369
Cygnus 11
357.838 6.615
355.808 5.107
353.475 -18.553
348.868 -10.771
347.949 1.298
344.907 -4.637
342.909 1.163
338.483 -9.293
338.854 -1.786
338.515 1.304
331.752 -10.737
Lyra 4
5.063 -7.812
2.708 -13.386
1.327 -2.841
0.815 -14.109
9/3 02:40
3
SevenStars 7
40.483 50.729
48.968 50.637
50.421 42.796
44.855 40.960
43.493 35.637
42.111 31.430
44.997 25.256
SummerTriangle 3
342.909 1.163
345.110 -36.796
5.063 -7.812
WinterTriangle 3
165.368 51.176
207.400 51.262
184.960 31.381
7/7 19:00
91
Andromeda 25
300.224 10.559
313.114 22.235
304.593 17.311
305.145 18.508
299.557 18.169
295.825 15.561
296.928 16.703
290.573 13.699
304.020 24.766
300.872 24.287
296.636 24.636
304.470 32.153
303.783 32.893
298.697 32.261
306.181 35.986
296.619 37.096
301.005 41.728
319.394 10.944
323.303 16.879
313.853 10.187
313.295 13.504
317.463 18.294
315.012 16.124
315.502 17.165
316.369 19.322
Antila 5
150.199 5.822
143.663 11.282
144.808 2.868
138.069 2.334
136.680 -6.080
Apus 6
159.498 -45.403
165.358 -47.196
157.404 -51.717
166.529 -52.133
167.065 -52.812
162.765 -60.430
Aquarius 28
318.790 -48.408
321.209 -45.287
318.270 -46.509
310.269 -47.366
305.625 -45.668
308.937 -39.175
306.021 -39.676
303.902 -30.310
293.964 -39.757
296.515 -33.643
282.661 -42.871
299.661 -28.583
300.287 -26.468
290.965 -33.635
281.107 -39.811
297.231 -25.827
293.848 -28.361
279.450 -36.914
284.435 -32.529
288.734 -27.776
281.899 -32.844
273.078 -34.510
284.834 -23.654
282.207 -25.447
282.043 -24.537
271.558 -31.463
273.631 -23.685
269.813 -26.206
Aquila 19
0.874 -31.730
359.216 -32.936
358.624 -49.913
355.895 -52.798
355.474 -35.099
353.377 -34.624
352.155 -43.404
349.613 -47.552
349.977 -38.924
345.808 -53.003
346.852 -35.279
339.294 -54.454
345.110 -36.796
342.448 -44.407
343.088 -38.981
340.624 -37.632
336.070 -43.369
340.114 -29.343
329.215 -43.658
Ara 8
139.371 -64.281
128.988 -67.070
126.140 -67.495
133.937 -70.565
146.948 -68.649
115.206 -73.448
124.296 -74.895
129.807 -78.284
Aries 16
275.089 19.700
277.208 23.346
277.494 27.270
273.485 25.417
269.538 23.135
277.570 29.777
272.582 27.036
270.956 32.094
275.776 36.366
274.279 37.296
262.543 29.989
266.391 34.798
273.056 41.891
263.012 36.658
263.680 38.088
262.590 39.297
Auriga 21
258.333 63.534
282.118 68.223
274.900 67.732
274.775 68.507
266.432 68.904
287.684 71.012
269.744 70.488
245.605 69.176
303.422 75.275
259.211 76.033
324.841 73.413
322.545 74.855
284.226 78.538
218.521 73.350
316.324 81.078
231.890 84.097
278.842 87.076
336.299 83.829
155.787 85.774
127.797 86.332
120.527 85.282
Bootes 24
63.869 9.873
69.774 4.070
67.862 3.467
60.529 5.629
63.774 0.539
40.081 23.036
44.262 19.473
67.421 -4.525
38.676 22.314
61.891 -1.179
53.418 6.177
47.886 11.938
53.387 5.299
42.612 15.477
64.297 -9.243
54.097 1.616
42.092 9.644
50.239 -1.089
36.476 15.172
51.041 -3.111
44.417 2.429
40.498 4.563
37.434 6.614
36.639 5.466
Caelum 3
206.749 -2.707
206.383 0.705
207.503 3.802
Camelopardis 9
336.366 53.550
306.868 63.261
314.379 64.832
333.859 61.000
324.283 65.152
333.999 66.052
347.170 66.444
358.133 64.282
22.412 70.692
Cancer 14
152.932 60.247
141.543 68.586
149.220 52.365
129.286 67.634
139.314 59.869
141.009 55.655
133.303 60.477
128.079 59.843
131.349 56.985
116.140 64.655
132.656 49.904
105.407 64.702
130.791 47.655
118.700 56.309
CanesVenatici 9
63.515 33.891
54.117 37.264
64.014 31.442
60.753 31.416
60.907 26.172
61.859 23.114
58.947 24.067
56.181 24.166
56.197 23.490
CanisMajor 12
189.554 16.222
191.117 30.052
187.145 25.454
184.960 31.381
182.841 15.253
182.535 34.807
180.964 19.769
180.236 20.737
179.917 24.636
179.696 32.436
178.624 21.184
175.070 17.938
CanisMinor 5
169.498 54.684
167.330 58.263
165.368 51.176
160.497 56.218
161.829 47.153
Capricornus 15
327.283 -54.381
319.640 -62.109
327.152 -54.307
324.725 -55.607
313.330 -57.369
302.734 -61.915
300.239 -61.281
305.714 -52.841
295.483 -58.754
302.466 -49.134
294.302 -53.161
297.453 -46.446
300.104 -41.866
295.158 -45.704
296.821 -42.155
Carina 7
186.061 -4.875
171.511 -4.945
169.452 -13.029
167.374 -24.125
162.642 -15.652
163.244 -28.369
156.225 -25.313
Cassiopeia 18
324.796 30.076
326.794 34.518
317.285 30.327
319.592 32.153
311.156 28.226
340.196 40.324
322.818 35.995
315.615 34.775
320.474 39.098
330.339 41.508
332.996 42.444
336.611 43.459
329.769 42.982
323.558 43.299
335.542 45.252
327.048 45.835
331.423 27.745
324.605 27.533
Centaurus 16
144.780 -21.358
151.103 -29.155
136.031 -24.020
134.304 -26.850
128.655 -31.224
114.889 -26.222
130.425 -37.948
109.349 -29.106
117.349 -34.385
122.386 -37.770
137.790 -43.449
109.153 -34.197
107.859 -36.848
112.627 -42.112
135.878 -47.823
110.171 -46.148
Cepheus 16
355.930 31.338
349.846 17.598
347.662 17.057
344.189 19.225
347.193 26.771
346.570 27.967
340.498 19.415
339.367 22.048
345.204 30.053
335.982 18.661
334.049 20.245
349.184 35.742
344.517 32.277
336.609 24.983
337.594 27.709
345.323 37.813
Cetus 29
267.392 -21.962
272.139 -12.783
274.115 -7.347
261.316 -14.311
265.273 -8.669
271.035 -2.352
270.805 1.139
261.818 -5.639
260.665 -1.490
256.455 -4.506
250.542 -9.105
252.749 -2.256
255.205 2.027
254.630 2.111
245.181 -4.356
264.415 18.831
253.034 9.471
247.128 6.587
261.394 21.309
243.942 5.376
257.758 20.709
249.146 12.323
253.144 17.620
243.530 9.279
259.617 25.458
255.832 27.254
251.561 24.282
245.843 22.473
247.574 26.675
Chamaeleon 6
174.828 -30.357
173.717 -31.227
167.691 -34.936
169.124 -36.723
161.658 -35.846
165.432 -40.069
Circinus 2
141.590 -48.550
132.085 -52.609
Columba 6
202.143 9.996
197.412 10.578
195.025 10.858
193.570 10.680
191.926 4.413
189.632 11.237
ComaBerenices 7
76.648 24.387
79.683 19.987
77.453 20.178
80.843 17.387
70.827 20.336
73.668 13.661
67.542 17.115
CoronaAustralis 3
76.831 -84.408
72.159 -87.309
349.050 -82.780
CoronaBorealis 6
44.830 -2.520
42.619 -1.332
44.991 -5.346
37.053 0.095
40.620 -8.046
33.560 -1.062
Corvus 4
114.367 -5.461
109.900 -2.973
106.846 -4.729
111.347 -10.379
Crater 7
124.123 8.440
124.193 3.979
117.555 8.787
118.622 5.586
110.936 9.608
116.023 1.385
113.531 0.100
Crux 4
142.482 -29.634
147.192 -33.867
140.733 -31.246
140.848 -33.879
Cygnus 26
357.838 6.615
355.808 5.107
353.475 -18.553
353.876 -12.067
354.603 3.708
351.653 -8.897
348.868 -10.771
346.567 -8.538
350.193 10.869
347.949 1.298
344.907 -4.637
342.557 -7.945
340.846 -13.795
342.909 1.163
338.483 -9.293
338.854 -1.786
340.656 4.326
338.515 1.304
336.234 -3.364
331.752 -10.737
334.609 -1.970
332.686 -6.040
335.619 5.437
334.489 4.935
331.664 0.559
334.307 9.233
Delphinus 5
333.672 -31.713
331.571 -32.362
333.741 -26.848
332.447 -27.320
332.054 -26.066
Dorado 7
205.464 -10.486
200.871 -13.113
196.063 -12.729
191.203 -21.965
190.853 -16.249
188.787 -18.553
185.561 -20.832
Draco 28
28.940 47.754
32.728 46.686
27.652 42.406
32.423 39.207
30.070 33.592
29.528 32.232
26.812 21.591
22.960 18.431
14.533 25.591
12.136 21.124
13.986 7.554
8.952 22.630
12.900 10.242
12.891 10.228
8.276 23.088
6.773 26.220
4.729 30.713
9.530 11.119
10.253 5.765
5.511 18.022
3.426 26.157
1.169 28.661
1.500 12.613
0.731 24.504
358.998 20.874
358.972 26.573
353.557 29.067
356.093 36.356
Equuleus 2
323.384 -29.260
319.354 -32.975
Eridanus 29
219.089 -30.779
223.136 -24.855
220.757 -22.413
222.767 -18.286
226.742 -10.667
236.404 3.705
244.644 15.058
223.094 -9.567
233.490 4.341
240.785 18.142
239.287 22.218
236.398 19.741
228.885 10.392
230.696 13.844
234.428 21.532
239.136 27.577
224.969 10.176
228.619 20.174
235.564 30.495
230.014 28.159
229.050 32.214
212.080 4.745
211.967 9.906
225.626 33.576
218.908 24.204
220.788 30.349
223.184 34.664
215.927 35.337
214.381 33.359
Fornax 7
238.898 -9.116
237.171 -8.220
240.540 -1.605
231.177 -8.178
229.829 -4.623
224.613 6.412
221.710 3.538
Gemini 22
215.932 66.683
204.877 67.736
199.742 65.953
193.146 62.679
193.518 71.530
188.373 59.467
192.635 80.565
180.202 71.018
179.143 67.371
174.375 62.866
171.813 63.143
168.932 68.478
161.323 73.914
153.261 77.453
148.264 77.059
154.841 72.360
152.127 69.337
146.998 72.565
156.258 63.667
134.440 76.874
143.773 70.603
136.491 70.307
Grus 10
266.639 -56.891
261.892 -55.418
250.399 -57.109
258.350 -51.534
252.761 -52.750
247.501 -51.272
238.441 -51.698
236.933 -49.917
245.584 -46.524
235.380 -46.029
Hercules 31
33.142 5.662
43.844 -17.673
29.344 6.259
26.982 6.515
39.748 -17.544
45.996 -28.329
41.678 -22.405
36.788 -16.433
26.483 1.894
22.911 7.383
26.485 -1.995
30.710 -15.768
27.551 -9.426
26.391 -10.747
25.126 -8.401
32.749 -27.966
25.531 -17.599
21.385 -6.334
21.711 -10.815
15.742 3.862
21.581 -17.539
14.288 1.096
17.591 -16.951
15.964 -19.046
13.290 -8.148
14.702 -16.037
17.081 -28.351
12.616 -16.934
9.946 -24.416
4.443 -26.136
4.239 -28.516
Horologium 4
212.195 -27.502
215.685 -21.711
209.563 -22.898
210.127 -2.984
Hydra 24
143.985 47.058
145.069 44.803
151.923 30.938
145.140 38.337
138.169 45.241
135.092 39.726
136.675 32.126
137.556 29.724
130.493 33.636
138.050 22.682
132.130 20.111
130.180 20.428
129.080 15.379
131.778 8.535
124.835 11.440
128.852 0.658
126.517 -5.926
127.538 -9.245
104.527 -18.245
98.485 -25.440
99.975 -26.915
99.280 -28.259
98.943 -34.064
93.274 -36.105
Hydrus 11
198.297 -43.876
202.979 -41.907
208.163 -34.122
213.775 -30.545
205.448 -32.460
200.398 -35.209
193.118 -38.207
203.866 -31.341
200.214 -31.329
193.659 -34.973
194.307 -31.540
Indus 7
249.907 -72.922
239.450 -71.406
220.919 -67.358
206.717 -56.713
235.616 -59.690
231.364 -58.806
207.454 -50.856
Lacerta 4
330.868 14.794
328.679 13.927
320.762 5.716
321.696 8.482
Leo 27
108.913 56.585
123.339 44.644
122.115 42.133
99.000 55.511
117.773 44.879
106.792 51.358
102.424 51.543
118.908 37.713
109.440 42.916
113.660 39.315
100.430 45.670
106.478 36.782
110.515 33.255
99.191 37.449
106.077 31.291
109.303 24.383
105.551 26.268
109.300 22.087
92.537 33.471
97.094 30.159
110.548 17.282
103.478 22.505
104.608 19.066
104.441 16.037
87.023 27.107
91.610 23.269
89.591 22.768
LeoMinor 9
90.267 60.380
78.517 57.855
92.724 53.388
86.200 50.349
81.581 50.769
86.265 46.546
95.468 40.706
86.698 44.569
81.288 45.027
Lepus 9
208.923 19.793
209.526 25.864
209.073 29.219
204.435 23.896
204.385 27.140
199.741 22.797
201.635 31.020
198.720 25.558
198.849 30.984
Libra 16
81.767 -29.125
83.418 -30.457
77.768 -27.899
74.449 -26.474
89.322 -38.371
81.462 -35.785
72.163 -30.079
75.587 -36.700
69.669 -33.980
72.203 -36.540
86.964 -46.207
75.625 -41.168
74.720 -44.181
67.649 -40.782
68.788 -42.391
61.765 -36.662
Lupus 11
117.171 -41.790
118.068 -45.036
111.531 -46.416
116.593 -50.101
123.695 -51.230
93.851 -43.568
104.221 -48.998
99.276 -47.504
98.305 -47.468
90.274 -51.170
91.817 -55.374
Lynx 10
340.957 72.851
350.646 71.341
13.353 77.484
18.414 73.281
59.902 79.893
47.406 76.156
83.141 75.429
72.888 72.348
78.567 66.265
96.482 61.871
Lyra 7
8.778 -10.140
5.063 -7.812
2.708 -13.386
1.327 -2.841
0.815 -14.109
359.054 -10.696
357.282 -8.610
Mensa 7
188.214 -35.195
193.058 -25.199
190.066 -28.325
185.361 -35.800
186.324 -29.775
184.202 -26.795
181.257 -32.429
Microscopium 5
264.385 -70.579
286.221 -64.016
274.073 -66.473
281.802 -61.120
266.935 -63.909
Monoceros 11
193.937 39.673
195.344 50.445
191.879 42.909
192.497 53.543
187.013 55.210
185.664 49.081
177.432 43.009
176.624 47.247
168.308 42.271
167.934 37.614
160.433 42.707
Musca 5
152.442 -31.405
156.829 -38.365
153.135 -37.536
154.045 -40.135
148.162 -39.941
Norma 3
108.500 -58.666
125.170 -60.575
117.887 -61.581
Octans 13
198.046 -45.252
176.567 -38.166
173.012 -42.811
172.072 -43.886
172.730 -47.145
179.818 -46.801
191.207 -53.945
182.212 -45.697
194.137 -52.731
192.192 -49.399
186.876 -46.654
191.609 -47.909
184.474 -44.508
Ophiuchus 20
54.470 -34.618
54.219 -36.013
48.446 -37.238
54.066 -43.720
50.326 -45.370
36.864 -29.115
36.334 -30.222
43.032 -42.256
53.910 -61.019
53.402 -62.293
31.010 -37.921
59.681 -65.616
25.109 -30.741
42.187 -61.743
25.758 -38.990
25.154 -41.103
26.385 -52.352
20.997 -41.799
16.895 -35.752
14.223 -42.479
Orion 20
228.557 43.501
227.159 42.547
233.926 49.831
224.091 40.245
231.313 52.497
224.916 48.508
212.650 33.396
213.079 36.124
214.760 41.605
217.291 47.355
211.550 42.550
216.105 51.230
208.390 38.774
209.681 41.921
203.047 35.727
207.400 51.262
202.907 45.028
202.227 48.919
206.751 59.217
201.381 57.499
Pavo 10
157.654 -67.059
164.415 -71.696
176.459 -62.514
176.133 -71.320
189.680 -61.203
196.371 -65.611
220.726 -71.988
203.251 -63.374
200.903 -58.638
210.828 -60.620
Pegasus 31
289.423 1.639
292.789 5.389
325.271 -19.328
325.355 -15.082
321.576 -18.057
315.029 -25.454
309.887 -31.091
324.502 -7.231
321.746 -10.569
313.113 -20.498
318.709 -9.439
322.477 -2.549
322.345 -2.460
306.855 -24.931
308.208 -18.427
304.677 -19.779
318.503 -0.637
303.255 -16.572
314.882 -0.922
310.240 -4.458
309.992 0.187
301.577 -9.597
297.306 -13.646
295.935 -13.393
304.294 -0.680
309.331 6.413
303.256 -0.214
295.450 -7.529
295.715 0.944
290.000 -4.903
299.060 6.102
Perseus 24
307.992 37.714
307.408 38.982
311.185 41.765
294.837 44.540
301.426 46.254
310.678 48.794
305.863 48.704
281.711 43.164
306.515 50.399
285.480 45.931
287.939 47.329
300.332 50.249
299.861 52.709
296.472 53.324
295.380 55.305
286.455 54.355
269.053 51.499
280.841 55.738
273.943 54.251
299.144 59.485
293.899 59.557
295.040 60.674
268.445 57.603
282.731 62.992
Phoenix 9
240.413 -36.726
241.278 -32.781
234.988 -34.724
235.320 -32.610
223.631 -37.224
233.002 -23.838
227.369 -22.186
247.359 -41.041
233.157 -41.238
Pictor 5
199.115 -5.204
196.549 -5.314
190.277 -10.223
187.892 -6.886
181.859 -13.299
Pisces 30
276.084 -15.147
276.760 -13.373
283.165 -1.965
277.824 -5.444
287.819 5.104
277.923 2.647
284.761 9.075
292.714 18.557
275.728 5.436
280.618 10.596
284.273 15.764
291.602 21.582
273.667 7.181
270.057 5.224
288.083 21.157
280.421 17.307
276.573 15.617
273.154 14.509
267.381 10.808
269.460 14.019
263.563 11.435
294.064 -18.352
291.117 -16.513
287.818 -16.306
291.268 -12.413
288.534 -10.905
285.402 -13.291
282.129 -14.379
279.313 -13.299
285.935 -6.652
PiscesAustrinus 8
278.189 -58.674
274.140 -56.842
272.659 -51.571
277.649 -47.812
267.833 -47.693
271.890 -43.451
267.416 -41.162
260.978 -42.711
Puppis 9
184.580 3.817
182.079 -2.625
177.070 9.833
175.119 3.899
167.505 32.508
168.381 22.802
168.339 5.677
164.057 21.464
160.076 30.354
Pyxis 4
158.634 10.564
154.957 16.224
152.121 11.537
147.334 15.581
Reticulum 5
204.908 -22.855
201.994 -23.451
202.121 -20.347
199.887 -20.103
198.493 -20.590
Sagitta 3
349.566 -28.691
348.056 -27.420
345.286 -25.999
Sagittarius 25
48.012 -67.119
44.526 -72.258
28.519 -65.511
51.339 -78.206
32.619 -72.785
41.334 -77.820
23.740 -70.063
12.238 -71.480
5.559 -72.441
3.057 -67.672
356.728 -73.111
355.646 -67.730
351.935 -63.658
350.579 -60.563
262.868 -86.361
312.000 -84.491
337.993 -68.724
340.644 -61.337
339.682 -61.389
336.325 -63.392
282.888 -79.729
333.366 -58.963
302.710 -76.078
319.336 -69.154
268.021 -75.299
Scorpius 14
80.363 -49.004
74.835 -46.432
70.299 -45.175
73.601 -52.052
73.114 -54.227
74.595 -56.737
80.967 -62.586
89.217 -64.779
98.307 -69.868
77.481 -71.296
77.193 -71.890
89.403 -74.055
81.163 -74.348
83.072 -75.589
Sculptor 11
258.000 -26.547
249.899 -31.550
243.095 -27.647
248.893 -19.849
246.841 -20.340
240.080 -14.665
244.594 -9.531
260.749 -39.021
253.603 -38.949
257.110 -35.369
259.902 -31.592
Scutum 5
16.148 -59.376
11.653 -54.049
8.921 -55.461
8.156 -54.279
6.023 -49.906
Serpens 13
62.443 -19.751
53.456 -13.220
55.387 -23.131
49.361 -16.131
47.238 -14.241
60.461 -31.027
55.246 -25.667
47.088 -17.328
50.255 -33.010
39.013 -56.091
15.238 -46.901
11.969 -46.189
2.194 -42.577
SevenStars 7
40.483 50.729
48.968 50.637
50.421 42.796
44.855 40.960
43.493 35.637
42.111 31.430
44.997 25.256
Sextans 5
129.626 29.644
126.345 22.444
122.446 24.760
119.299 25.894
119.015 18.085
SummerTriangle 3
342.909 1.163
345.110 -36.796
5.063 -7.812
Taurus 27
250.893 31.722
250.982 32.632
252.943 35.539
241.685 27.325
261.126 45.412
244.002 33.045
260.593 45.877
260.194 46.146
245.956 40.306
239.935 35.811
254.646 47.658
250.907 46.787
258.577 51.508
239.262 40.001
244.242 45.761
245.368 47.668
245.642 49.782
239.805 47.440
240.886 49.021
246.413 54.695
238.949 53.205
238.548 57.087
240.905 65.777
226.104 57.692
225.532 61.707
217.863 59.965
227.613 69.046
Telescopium 6
99.632 -80.656
100.423 -83.483
175.148 -82.103
227.583 -82.622
206.443 -75.581
228.471 -76.495
Triangulum 5
285.165 28.434
288.118 34.349
285.904 35.093
280.102 34.723
286.401 38.875
TriangulumAustrale 6
148.672 -52.090
146.607 -54.162
142.070 -56.831
142.826 -59.157
156.860 -56.997
157.390 -58.985
Tucana 6
216.837 -42.185
208.705 -40.221
217.821 -35.934
223.308 -56.356
226.434 -48.712
215.737 -44.634
UrsaMajor 29
29.282 68.109
66.378 69.195
22.970 60.853
68.864 68.465
34.212 60.841
58.080 63.568
23.054 57.220
43.463 59.925
73.296 55.002
33.894 55.376
75.061 53.630
50.113 54.941
48.195 54.330
72.518 46.730
48.968 50.637
40.483 50.729
65.995 46.548
79.010 39.942
73.034 42.329
65.674 42.568
74.681 36.517
58.506 41.892
50.421 42.796
44.855 40.960
42.300 39.601
36.409 39.726
43.493 35.637
42.111 31.430
44.997 25.256
UrsaMinor 10
359.062 43.472
15.334 38.584
16.704 36.737
17.194 34.620
17.526 31.442
11.304 34.699
11.341 32.253
11.030 31.917
5.554 36.468
1.714 40.033
Vela 5
168.619 -1.071
164.855 -6.629
157.488 -0.252
160.372 -12.557
155.025 -13.588
Virgo 33
98.539 18.430
101.244 14.256
95.800 15.774
93.423 16.427
96.882 8.238
94.860 9.978
97.474 1.850
98.384 0.141
86.005 10.761
87.288 8.349
97.602 -4.270
88.734 3.618
92.116 -0.944
82.053 7.572
92.018 -4.372
83.466 1.036
100.540 -14.806
94.167 -11.471
94.253 -12.053
75.583 4.802
81.944 -3.198
84.072 -5.412
87.744 -9.129
88.703 -12.071
94.791 -18.290
95.548 -20.598
78.670 -9.609
85.118 -19.408
81.691 -17.430
86.326 -22.486
76.304 -16.663
75.459 -21.104
70.253 -17.188
Volans 6
181.087 -22.253
179.426 -22.704
178.481 -19.274
176.577 -24.804
171.114 -20.237
167.223 -21.251
Vulpecula 7
353.634 -21.875
350.153 -20.389
346.451 -17.791
342.107 -20.025
335.915 -21.936
334.725 -14.255
331.735 -19.292
WinterTriangle 3
165.368 51.176
207.400 51.262
184.960 31.381
</pre>
<h2>Output for Sample Input</h2>
<pre>
Cygnus
Lyra
SevenStars
SummerTriangle
WinterTriangle
Bootes
Camelopardis
Cancer
CanesVenatici
Cassiopeia
Cepheus
ComaBerenices
CoronaBorealis
Corvus
Crater
Cygnus
Delphinus
Draco
Hercules
Lacerta
Leo
LeoMinor
Libra
Lynx
Lyra
Ophiuchus
Sagitta
Scutum
Serpens
SevenStars
Sextans
SummerTriangle
UrsaMajor
UrsaMinor
Virgo
Vulpecula
</pre>
|
p00865 |
<H1><font color="#000">Problem B:</font> Expected Allowance</H1>
<p>
Hideyuki is allowed by his father Ujisato some 1000 yen bills every month for his pocket money.
In the first day of every month, the number of bills is decided as follows. Ujisato prepares <i>n</i>
pieces of <i>m</i>-sided dice and declares the cutback <i>k</i>. Hideyuki rolls these dice. The number of
bills given is the sum of the spots of the rolled dice decreased by the cutback. Fortunately to
Hideyuki, Ujisato promises him to give at least one bill, even if the sum of the spots does not
exceed the cutback. Each of the dice has spots of 1 through m inclusive on each side, and the
probability of each side is the same.
</p>
<p>
In this problem, you are asked to write a program that finds the expected value of the number
of given bills.
</p>
<p>
For example, when <i>n</i> = 2, <i>m</i> = 6 and <i>k</i> = 3, the probabilities of the number of bills being 1, 2, 3, 4, 5, 6, 7, 8 and 9 are 1/36 + 2/36 + 3/36, 4/36, 5/36, 6/36, 5/36, 4/36, 3/36, 2/36 and 1/36, respectively.
</p>
<p>
Therefore, the expected value is
</p>
<p>
(1/36 + 2/36 + 3/36) × 1 + 4/36 × 2 + 5/36 × 3 + 6/36 × 4 + 5/36 × 5 + 4/36 × 6 + 3/36 × 7 + 2/36 × 8 + 1/36 × 9, which is approximately 4.11111111.
</p>
<H2>Input</H2>
<p>
The input is a sequence of lines each of which contains three integers n, m and k in this order.
They satisfy the following conditions.
</p>
<p>
1 ≤ <i>n</i><br>
2 ≤ <i>m</i><br>
0 ≤ <i>k</i> < <i>nm</i><br>
<i>nm</i> × <i>m<sup>n</sup></i> < 100000000 (10<sup>8</sup>)<br>
</p>
<p>
The end of the input is indicated by a line containing three zeros.
</p>
<H2>Output</H2>
<p>
The output should be comprised of lines each of which contains a single decimal fraction. It is
the expected number of bills and may have an error less than 10<sup>-7</sup> . No other characters should
occur in the output.
</p>
<H2>Sample Input</H2>
<pre>
2 6 0
2 6 3
3 10 9
13 3 27
1 2008 3
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7.00000000
4.11111111
7.71000000
1.42902599
1001.50298805
</pre>
|
p02858 | <span class="lang-en">
<p>Score: <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In <var>2937</var>, DISCO creates a new universe called DISCOSMOS to celebrate its <var>1000</var>-th anniversary.</p>
<p>DISCOSMOS can be described as an <var>H \times W</var> grid. Let <var>(i, j)</var> <var>(1 \leq i \leq H, 1 \leq j \leq W)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p>
<p>At time <var>0</var>, one robot will be placed onto each square. Each robot is one of the following three types:</p>
<ul>
<li>Type-H: Does not move at all.</li>
<li>Type-R: If a robot of this type is in <var>(i, j)</var> at time <var>t</var>, it will be in <var>(i, j+1)</var> at time <var>t+1</var>. If it is in <var>(i, W)</var> at time <var>t</var>, however, it will be instead in <var>(i, 1)</var> at time <var>t+1</var>. (The robots do not collide with each other.)</li>
<li>Type-D: If a robot of this type is in <var>(i, j)</var> at time <var>t</var>, it will be in <var>(i+1, j)</var> at time <var>t+1</var>. If it is in <var>(H, j)</var> at time <var>t</var>, however, it will be instead in <var>(1, j)</var> at time <var>t+1</var>.</li>
</ul>
<p>There are <var>3^{H \times W}</var> possible ways to place these robots. In how many of them will every square be occupied by one robot at times <var>0, T, 2T, 3T, 4T</var>, and all subsequent multiples of <var>T</var>?</p>
<p>Since the count can be enormous, compute it modulo <var>(10^9 + 7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq H \leq 10^9</var></li>
<li><var>1 \leq W \leq 10^9</var></li>
<li><var>1 \leq T \leq 10^9</var></li>
<li><var>H, W, T</var> are all 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>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the number of ways to place the robots 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>2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>Shown below are some of the ways to place the robots that satisfy the condition, where <code>.</code>, <code>></code>, and <code>v</code> stand for Type-H, Type-R, and Type-D, respectively:</p>
<pre>>> .. vv
.. .. vv
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>869 120 1001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>672919729
</pre></section>
</div>
</span> |
p01777 |
<h2>F: Disordered Data Detection / 異常検知</h2>
<h3>物語</h3>
<p>宮守あかねは武蔵野ソフトウェアに務めるエンジニアである.今日は顧客から受けた不具合報告に頭を悩ませている.「変な話,この前作ってもらったソフトの挙動がぷるんぷるんしてるんでぇ,そちらでチェックしてもらえますか?保守するのもおたくらの仕事でしょ?」いつも無理難題ばかり押し付けてくるこの顧客だが,今回ばかりはこちらに非がある.なぜなら,いつも適当な仕事ばかりのジローがテストに通っていないコードをそのまま放置して製品に組み込んだことを告白したからである.普通の人間ならジローに殴りかかりそうなものだが,もはやいつものことだ,あかねは怒りを通り越し,すでに悟りを開きつつある.なにはともあれ,バグを取り除かなければならない.まずはデータログを解析し,異常が出ている箇所を検知することでバグの原因を探ろう.</p>
<p>今,<var>D</var> 日分のログがあり,各データは1つの整数である.<var>l</var> 日目から <var>r</var> 日目までのデータについて,<var>l</var> 日目のデータと <var>r</var> 日目のデータの間に収まらず,大きくかけ離れたデータは異常の可能性が高いと考えられる.よって,指定された期間を入力とし,上記のような外れ値を検知するコードを書くことにした.</p>
<p>顧客が提示したデバッグ期限は3時間後.万策尽きたかのような状況だが,あかねは何度もこのような状況を乗り越えてきた.お気に入りのドーナツを頬張り気合を入れて,どんどんデバッグ,どーんと行こう!</p>
<h3>問題</h3>
<p>長さ <var>D</var> の整数列 <var>x_1, . . . , x_D</var> がある.この数列に対し <var>Q</var> 回のクエリが与えられる.<var>i</var> 番目のクエリは3つの整数 <var>l_i</var>, <var>r_i</var>, <var>e_i</var> からなる.<var>i</var> 番目のクエリに対し,<var>a_i = min\{x_{l_i},x_{r_i}\}</var>, <var>b_i = max\{x_{l_i},x_{r_i}\}</var> としたとき,<var>x_j < a_i − e_i</var> もしくは <var>b_i+e_i < x_j</var> を満たすような <var>l_i ≤ j ≤ r_i</var> の個数を答えよ.</p>
<h3>入力形式</h3>
<p>入力は以下の形式からなる.</p>
<pre>
<var>D</var>
<var>x_1</var> <var>x_2</var> <var> . . . </var> <var>x_D</var>
<var>Q</var>
<var>l_1</var> <var>r_1</var> <var>e_1</var>
<var> . . . </var>
<var>l_Q</var> <var>r_Q</var> <var>e_Q</var>
</pre>
<p>入力の1行目は数列の長さを表す1つの整数 <var>D</var> (<var>1 ≤ D ≤ 100{,}000</var>) からなる.2行目では,数列 <var>X</var> を表す <var>D</var> 個の整数がそれぞれ空白1つを区切りとして与えられる.<var>i</var> 番目の整数 <var>x_i</var> は <var>−10^8 ≤ x_i ≤ 10^8</var> を満たす.</p>
<p>3行目はクエリの個数を表す1つの整数 <var>Q</var> (<var>1≤ Q ≤ 100{,}000</var>) からなる.続く <var>Q</var> 行のうち <var>j</var> 番目の行では,<var>j</var> 番目のクエリを表す3つの整数 <var>l_j</var>, <var>r_j</var>, <var>e_j</var> が空白1つを区切りとして与えられる.<var>j</var> 番目のクエリについて,<var>1 ≤ l_j ≤ r_j ≤ D</var>, <var>0 ≤ e_j ≤ 10^8</var> を満たす.</p>
<h3>出力形式</h3>
<p><var>Q</var> 個のクエリに対する答えを,クエリが与えられた順にそれぞれ1行ごとに出力せよ.</p>
<h3>入力例1</h3>
<pre>
7
4 1 10 5 7 7 3
5
2 5 0
3 6 1
3 6 2
1 7 2
1 7 5
</pre>
<h3>出力例1</h3>
<pre>
1
1
0
3
1
</pre>
<h3>入力例2</h3>
<pre>
9
8 3 0 2 5 2 5 2 1
3
1 3 5
2 5 0
3 9 0
</pre>
<h3>出力例2</h3>
<pre>
0
2
5
</pre>
<h3>入力例3</h3>
<pre>
9
10 10 10 7 2 10 10 1 5
13
3 3 6
3 4 5
3 5 4
3 6 3
3 7 2
3 8 1
3 9 0
4 9 1
5 9 2
6 9 3
7 9 4
8 9 5
9 9 6
</pre>
<h3>出力例3</h3>
<pre>
0
0
0
1
2
0
2
4
2
1
0
0
0
</pre> |
p00536 |
<h2>財宝 (Treasures)</h2>
<h2>問題</h2>
<p>
盗賊の Anna と Bruno は大富豪の邸宅に忍び込み,財宝 1 から財宝 N までの N 個の財宝を見つけた.これらの財宝を Anna と Bruno で分配することになった.財宝のうちのいくつかを Anna が取り,残りの財宝のうちのいくつかを Bruno が取る.同じ財宝を 2 人が取ることはできない.Anna や Bruno は財宝を 1 個も取らなくてもよい.また,残った財宝は邸宅に残しておくので,2 人とも取らない財宝があってもよい.
</p>
<p>
それぞれの財宝には「市場価値」と「貴重度」という 2 つの値が定まっている.Anna が取った財宝の市場価値の合計と Bruno が取った財宝の市場価値の合計の差の絶対値が D 以下なら,Anna は公平だと思って満足する.一方,Bruno は,Anna より貴重度の大きい財宝が欲しいと思っている.
</p>
<p>
Anna が満足するように財宝を分配したときの,Bruno が取った財宝の貴重度の合計から Anna が取った財宝の貴重度の合計を引いた値の最大値を求めよ.
</p>
<h2>入力</h2>
<p>
入力は 1 + N 行からなる.
</p>
<p>
1 行目には,2 つの整数 N, D (1 ≤ N ≤ 30,0 ≤ D ≤ 10<sup>15</sup>) が空白を区切りとして書かれている.これは,財宝の個数が N 個であり,Anna が取った財宝の市場価値の合計と Bruno が取った財宝の市場価値の合計の差の絶対値が D 以下なら Anna が満足することを表す.
</p>
<p>
続く N 行のうちの i 行目 (1 ≤ i ≤ N) には,2 つの整数 X<sub>i</sub>, Y<sub>i</sub> (0 ≤ X<sub>i</sub> ≤ 10<sup>15</sup>,0 ≤ Y<sub>i</sub> ≤ 10<sup>15</sup>) が空白を区切りとして書かれている.これは,財宝 i の市場価値が X<sub>i</sub> であり,貴重度が Y<sub>i</sub> であることを表す.
</p>
<p>
与えられる 5 つの入力データのうち,入力 1 では N ≦ 10 を満たす.また,入力 2 では D = 0 を満たす.
</p>
<h2>出力</h2>
<p>
Anna が満足するように財宝を分配したときの,Bruno が取った財宝の貴重度の合計から Anna が取った財宝の貴重度の合計を引いた値の最大値を 1 行で出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
6 15
50 900
30 200
40 100
80 600
60 100
70 700
</pre>
<h3>出力例 1</h3>
<pre>
1200
</pre>
<h3>入力例 2</h3>
<pre>
5 0
0 1000000000000000
0 1000000000000000
1 1
1000000000000000 0
1000000000000000 0
</pre>
<h3>出力例 2</h3>
<pre>
2000000000000000
</pre>
<p>
入出力例 1 においては,Anna が財宝 2 と財宝 3 と財宝 5 を取り,Bruno が財宝 1 と財宝 6 を取ると,取った財宝の市場価値の合計は Anna が 130,Bruno が 120 となり,差の絶対値 10 が D = 15 以下なので Anna は満足する.このとき,取った財宝の貴重度の合計は Anna が 400,Bruno が 1600 となり,Bruno が取った財宝の貴重度の合計から Anna が取った財宝の貴重度の合計を引いた値は 1200 となる.これが最大である.
</p>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00166 |
<H1>多角形の面積</H1>
<p>
1つの円に内接する2つの多角形の頂点情報を入力とし、それらの面積の大小関係を出力するプログラムを作成してください。
</p>
<p>
<var>X</var> 角形の各頂点には反時計回りに 1 から <var>X</var> まで番号が振ってあるものとします(図は、<var>X</var> = 4 の場合の例を示しています)。ただし、与えられる多角形は円の中心を内部に含むものとし、頂点 <var>i</var> の位置に関するデータは、頂点 <var>i</var> から頂点 <var>i+1</var> まで反時計回りに計った中心角の角度 <var>v</var> (1 ≤ <var>v</var> < 180 の整数) で与えられます。また、出力する大小関係については、第1の多角形の面積が大きい場合は 1 (半角数字)、第2の多角形の面積が大きい場合は 2 (半角数字)、それぞれの面積が等しい場合は 0 (半角数字) と出力してください。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_areaOfPolygon">
</center>
<!--
<p>
プログラムは以下に定義する入力が続く限り処理を繰り返し、入力が終わったら終了するように作成し
てください。
</p>
-->
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>m</var>
<var>v<sub>1</sub></var>
<var>v<sub>2</sub></var>
:
<var>v<sub>m −1</sub></var>
<var>n</var>
<var>v<sub>1</sub></var>
<var>v<sub>2</sub></var>
:
<var>v<sub>n − 1</sub></var>
</pre>
<p>
1行目に第1の多角形の頂点の数 <var>m</var> (3 ≤ <var>m</var> ≤ 50)、続く <var>m − 1</var> 行に第1の多角形の頂点 <var>i</var> の情報 <var>v<sub>i</sub></var> (1 ≤ <var>v<sub>i</sub></var> < 180) が与えられます。
</p>
<p>
続く行に第2の多角形の頂点の数 <var>n</var> (3 ≤ <var>n</var> ≤ 50)、続く <var>n − 1</var> 行に第2の多角形の頂点 <var>i</var> の情報 <var>v<sub>i</sub></var> (1 ≤ <var>v<sub>i</sub></var> < 180) が与えられます。
</p>
<p>
データセットの数は 200 を超えません。
</p>
<H2>Output</H2>
<p>
データセットごとに大小関係(半角数字)を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
4
30
125
75
4
30
125
75
5
30
125
75
65
4
30
125
75
4
30
125
75
6
30
50
50
25
75
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
1
2
</pre>
|
p00473 |
<H1>お菓子の分割
</H1>
<h2> 問題</h2>
<p>
長さ N ミリメートルの棒状のお菓子が 1 本ある(ここで N は偶数). 2 人の JOI
関係者が,このお菓子を複数本に切断して,合計 N/2 ミリメートルずつに分けること
にした.
</p>
<p>
理由は不明であるが,このお菓子は場所によって切断のしやすさが異なっている.
2 人は,お菓子を左から 1 ミリメートルごとに調べ,各場所で切断に何秒かかるか
を割り出した.2 人がお菓子を分けるための切断にかかる秒数の最小値を求めるプ
ログラムを作成せよ.
</p>
<h2>入力</h2>
<!--
<p>
入力ファイルのファイル名は input.txt である.
</p>
-->
<p>
入力の 1 行目には,棒の長さ N(2 ≤ N ≤ 10000 ,ただし N は偶数) が書かれてい
る.入力の i + 1 行目 (1 ≤ i ≤ N − 1) には,左端から i ミリメートル目の場所の切
断にかかる秒数を表す整数 ti (1 ≤ ti ≤ 10000) が書かれている.切断可能な場所が
N − 1 箇所であることに注意せよ.
</p>
<p>
採点用データのうち,配点の 5% 分については,高々 2 カ所を切断することで最
小値を実現でき,10% 分については,高々 3 カ所を切断することで最小値を実現で
きる.配点の 20% 分については,N ≤ 20 である.
</p>
<h2> 出力</h2>
<p>
<!--出力ファイルのファイル名は output.txt である.-->
出力は2 人がお菓子を分るための切断にかかる秒数の最小値を含む 1 行からなる.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
6
1
8
12
6
2
</pre>
<h3>出力例 1</h3>
<pre>
7
</pre>
<p>
この場合,左端から 1 ミリメートルと 4 ミリメートルの場所で切断するとかかる
秒数が最小となる.かかる秒数は 1 秒と 6 秒で,合計 7 秒である.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0550">
</center>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00189 |
<H1>便利な町</H1>
<p>
来春卒業するAさんは、就職を機に引越しをすることにしました。就職する会社は、オフィスがいくつかの町にあって、日によって出勤するオフィスが違います。そこでAさんは,どこのオフィスに
行くにも時間の短い町に住もうと考えました。
</p>
<p>
そこであなたは、Aさんを助けるため、住むのに一番便利な町を探すことになりました。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_location">
</center>
<br/>
<p>
町には 0 から始まる番号が振られており、町と町の間には道があります。それぞれの道に対して通勤時間が決まっています。Aさんがある町に住んでいる場合に、自分の町のオフィスまでの通勤時間は 0 とします。このときに全ての町までの通勤時間の総和を考えます。例えば、町と道の配置が上の図のようになっていて、Aさんが町1に住んだ場合には、それぞれの町までの通勤時間は
<br/>
<br/>
町 0 まで 80<br/>
町 1 まで 0<br/>
町 2 まで 20<br/>
町 3 まで 70<br/>
町 4 まで 90<br/>
<br/>
となり、総和は 260 となります。
</p>
<p>
道の数と、全ての道の情報を入力とし、それぞれの町に住んだ場合の通勤時間の総和を計算し、それが最小となる町の番号と、そのときの通勤時間の総和を出力するプログラムを作成してください。ただし、通勤時間の総和が最小となる町が複数ある場合は、一番小さい町の番号及びその時の通勤時間の総和を出力してください。町の総数は 10 以下、道の総数は 45 以下とし、全ての道は双方向に移動でき、通勤時間は方向によって変わらないものとします。また、どの町からでもその他全ての町への 経路があるものとします。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。 各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var>
:
<var>a<sub>n</sub></var> <var>b<sub>n</sub></var> <var>c<sub>n</sub></var>
</pre>
<p>
1行目に道の数 <var>n</var> (1 ≤ <var>n</var> ≤ 45) が与えられます。続く <var>n</var> 行に <var>i</var> 番目の道の情報が与えられます。
<var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> (0 ≤ <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> ≤ 9) は <var>i</var> 番目の道がつないでいる町の番号、<var>c<sub>i</sub></var> (0 ≤ <var>c<sub>i</sub></var> ≤ 100) はその道の通勤時間を表します。
</p>
<H2>Output</H2>
<p>
データセット毎に、通勤時間の総和が最小になる町の番号及びその時の通勤時間の総和を空白区切りで1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2 240
1 2
</pre>
|
p00023 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Circles Intersection</H1>
<p>
You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$.
</p>
<p>
Write a program which prints:
</p>
<ul>
<li>"2" if $B$ is in $A$,</li>
<li>"-2" if $A$ is in $B$, </li>
<li>"1" if circumference of $A$ and $B$ intersect, and</li>
<li>"0" if $A$ and $B$ do not overlap.</li>
</ul>
<p>
You may assume that $A$ and $B$ are not identical.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. The first line consists of an integer $N$ ($N \leq 50$), the number of datasets. There will be $N$ lines where each line represents each dataset. Each data set consists of real numbers:<br/>
<br/>
$x_a$ $y_a$ $r_a$ $x_b$ $y_b$ $r_b$<br/>
</p>
<H2>Output</H2>
<p>
For each dataset, print 2, -2, 1, or 0 in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 5.0 0.0 0.0 4.0
0.0 0.0 2.0 4.1 0.0 2.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
0
</pre>
|
p01262 |
<H1><font color="#000">Problem C:</font> Adaptive Time Slicing Quantization</H1>
<p>
Nathan O. Davis is a student at the department of integrated systems. Today he learned digital quanti-
zation in a class. It is a process that approximates analog data (e.g. electrical pressure) by a finite set of
discrete values or integers.
</p>
<p>
He had an assignment to write a program that quantizes the sequence of real numbers each representing
the voltage measured at a time step by the voltmeter. Since it was not fun for him to implement normal
quantizer, he invented a new quantization method named Adaptive Time Slicing Quantization. This
quantization is done by the following steps:
</p>
<ol>
<li> Divide the given sequence of real numbers into arbitrary <i>M</i> consecutive subsequences called
frames. They do not have to be of the same size, but each frame must contain at least two ele-
ments. The later steps are performed independently for each frame.</li>
<li> Find the maximum value <i>V</i><sub>max</sub> and the minimum value <i>V</i><sub>min</sub> of the frame.</li>
<li> Define the set of quantized values. The set contains 2<sup><i>L</i></sup> equally spaced values of the interval
[<i>V</i><sub>min</sub>, <i>V</i><sub>max</sub>] including the both boundaries. Here, <i>L</i> is a given parameter called a <i>quantization
level</i>. In other words, the <i>i</i>-th quantized value <i>q<sub>i</sub></i> (1 ≤ <i>i</i> ≤ 2<sup><i>L</i></sup>) is given by:
<br>
<center>
<p> .
<i>q<sub>i</sub></i> = <i>V</i><sub>min</sub> + (<i>i</i> - 1){(<i>V</i><sub>max</sub> - <i>V</i><sub>min</sub>)/(2<sup><i>L</i></sup> - 1)}
</p>
</center>
</li>
<li> Round the value of each element of the frame to the closest quantized value.</li>
</ol>
<p>
The key of this method is that we can obtain a better result as choosing more appropriate set of frames in
the step 1. The quality of a quantization is measured by the sum of the squares of the quantization errors
over all elements of the sequence: the less is the better. The quantization error of each element is the
absolute difference between the original and quantized values.
</p>
<p>
Unfortunately, Nathan caught a bad cold before he started writing the program and he is still down in his
bed. So he needs you help. Your task is to implement Adaptive Time Slicing Quantization instead. In
your program, the quantization should be performed with the best quality, that is, in such a way the sum
of square quantization errors is minimized.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset contains two lines. The first line contains three
integers <i>N</i> (2 ≤ <i>N</i> ≤ 256), <i>M</i> (1 ≤ <i>M</i> ≤ <i>N</i>/2), and <i>L</i> (1 ≤ <i>L</i> ≤ 8), which represent the number of
elements in the sequence, the number of frames, and the quantization level. The second line contains <i>N</i>
real numbers ranging in [0, 1]. The input is terminated by the dataset with <i>N</i> = <i>M</i> = <i>L</i> = 0, which must not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, output the minimum sum of square quantization errors in one line. The answer with an
absolute error of less than or equal to 10<sup>-6</sup> is considered to be correct.
</p>
<H2>Sample Input</H2>
<pre>
5 2 1
0.1 0.2 0.3 0.4 0.5
6 2 2
0.1 0.2 0.3 0.4 0.5 0.6
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.01
0.00
</pre>
|
p01798 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem I
Midpoint</h2>
<p>
One day, you found $L + M + N$ points on a 2D plane, which you named $A_1, ..., A_L, B_1, ...,B_M, C_1,...,C_N$. Note that two or more points of them can be at the same coordinate. These were named after the following properties:
</p>
<ul>
<li> the points $A_1,...,A_L$ were located on a single straight line,</li>
<li> the points $B_1,...,B_M$ were located on a single straight line, and</li>
<li> the points $C_1,...,C_N$ were located on a single straight line.</li>
</ul>
<p>
Now, you are interested in a triplet $(i, j, k)$ such that $C_k$ is the midpoint between $A_i$ and $B_j$. Your task is counting such triplets.
</p>
<h3>Input</h3>
<p>
The first line contains three space-separated positive integers $L$, $M$, and $N$ $(1 \leq L, M, N \leq 10^5)$. The next $L$ lines describe $A$. The $i$-th of them contains two space-separated integers representing the $x$-coordinate and the $y$-coordinate of $A_i$. The next $M$ lines describe $B$. The $j$-th of them contains two space-separated integers representing the $x$-coordinate and the $y$-coordinate of $B_j$. The next $N$ lines describe $C$. The $k$-th of them contains two space-separated integers representing the $x$-coordinate and the $y$-coordinate of $C_k$. It is guaranteed that the absolute values of all the coordinates do not exceed $10^5$.
</p>
<h3>Output</h3>
<p>
Print the number of the triplets which fulfill the constraint.
</p>
<h3>Sample Input 1</h3>
<pre>2 2 3
0 0
2 0
0 0
0 2
0 0
1 1
1 1</pre>
<h3>Output for the Sample Input 1</h3>
<pre>3</pre>
<h3>Sample Input 2</h3>
<pre>4 4 4
3 5
0 4
6 6
9 7
8 2
11 3
2 0
5 1
4 3
7 4
10 5
1 2</pre>
<h3>Output for the Sample Input 2</h3>
<pre>8</pre>
<h3>Sample Input 3</h3>
<pre>4 4 4
0 0
3 2
6 4
9 6
7 14
9 10
10 8
13 2
4 2
5 4
6 6
8 10</pre>
<h3>Output for the Sample Input 3</h3>
<pre>3</pre>
|
p00920 |
<H1><font color="#000">Problem G: </font>Longest Chain</H1>
<p>
Let us compare two triples <var>a = (x<sub>a</sub>, y<sub>a</sub>, z<sub>a</sub>)</var> and <var>b = (x<sub>b</sub>, y<sub>b</sub>, z<sub>b</sub>)</var> by a partial order ∠ defined as follows.
<br/>
<center>
<var>a</var> ∠ <var>b</var> ⇔ <var>x<sub>a</sub></var> < <var>x<sub>b</sub></var> and <var>y<sub>a</sub></var> < <var>y<sub>b</sub></var> and <var>z<sub>a</sub></var> < <var>z<sub>b</sub></var>
<br/>
</center>
<br/>
<p>
Your mission is to find, in the given set of triples, the longest ascending series <var>a<sub>1</sub></var> ∠ <var>a<sub>2</sub></var> ∠ ... ∠ <var>a<sub>k</sub></var>.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets, each specifying a set of triples formatted as follows.
</p>
<pre>
<var>m</var> <var>n</var> <var>A</var> <var>B</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var>
...
<var>x<sub>m</sub></var> <var>y<sub>m</sub></var> <var>z<sub>m</sub></var>
</pre>
<p>
Here, <var>m</var>, <var>n</var>, <var>A</var> and <var>B</var> in the first line, and all of <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> and <var>z<sub>i</sub></var> (<var>i</var> = 1, . . . , <var>m</var>) in the following lines are non-negative integers.
</p>
<p>
Each dataset specifies a set of <var>m + n</var> triples. The triples <var>p<sub>1</sub></var> through <var>p<sub>m</sub></var> are explicitly specified in the dataset, the <var>i</var>-th triple <var>p<sub>i</sub></var> being (<var>x<sub>i</sub>, y<sub>i</sub>, z<sub>i</sub>)</var>. The remaining <var>n</var> triples are specified by parameters <var>A</var> and <var>B</var> given to the following generator routine.
</p>
<pre>
int a = A, b = B, C = ~(1<<31), M = (1<<16)-1;
int r() {
a = 36969 * (a & M) + (a >> 16);
b = 18000 * (b & M) + (b >> 16);
return (C & ((a << 16) + b)) % 1000000;
}
</pre>
<p>
Repeated 3<var>n</var> calls of <span>r()</span> defined as above yield values of <var>x<sub>m+1</sub></var>, <var>y<sub>m+1</sub></var>, <var>z<sub>m+1</sub></var>, <var>x<sub>m+2</sub></var>, <var>y<sub>m+2</sub></var>, <var>z<sub>m+2</sub></var>, ..., <var>x<sub>m+n</sub></var>, <var>y<sub>m+n</sub></var>, and <var>z<sub>m+n</sub></var>, in this order.
</p>
<p>
You can assume that 1 ≤ <var>m + n</var> ≤ 3 × 10<sup>5</sup>, 1 ≤ <var>A,B</var> ≤ 2<sup>16</sup>, and 0 ≤ <var>x<sub>k</sub>, y<sub>k</sub>, z<sub>k</sub></var> < 10<sup>6</sup> for 1 ≤ <var>k</var> ≤ <var>m + n</var>.
</p>
<p>
The input ends with a line containing four zeros. The total of <var>m + n</var> for all the datasets does not exceed 2 × 10<sup>6</sup>.
</p>
<H2>Output</H2>
<p>
For each dataset, output the length of the longest ascending series of triples in the specified set. If <var>p<sub>i<sub>1</sub></sub></var> ∠ <var>p<sub>i<sub>2</sub></sub></var> ∠ ... ∠ <var>p<sub>i<sub>k</sub></sub></var> is the longest, the answer should be <var>k</var>.
</p>
<H2>Sample Input</H2>
<pre>
6 0 1 1
0 0 0
0 2 2
1 1 1
2 0 2
2 2 0
2 2 2
5 0 1 1
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
10 0 1 1
3 0 0
2 1 0
2 0 1
1 2 0
1 1 1
1 0 2
0 3 0
0 2 1
0 1 2
0 0 3
0 10 1 1
0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
5
1
3
</pre> |
p01632 |
<h1>Problem F: 自転車</h1>
<h2>Problem Statement</h2>
<p>
菊地君は、大の自転車好きである。今日も彼は、お気に入りの自転車に乗ってサイクリングロードへと走り出そうとしている。
</p>
<p>
彼が住む地域には、N個の町が存在する。各町を町1、町2...、町Nと呼ぶこととする。彼が住む町は、町1である。この地域には、サイクリングを趣味としている人が多く、最近では頻繁に町と町を結ぶサイクリングロードが作られている。サイクリングロードを使うと、2つの町を双方向に移動できる。入力では、どの町とどの町が新しくサイクリングロードで繋がれたかが時系列順に入力される。
</p>
<p>
菊地君は、新しいサイクリングロードが1つ完成したときに、次に示す条件を満たすときだけサイクリングに出かける。まず、サイクリング中に同じ風景を何回も見るのはつまらないため、<span style="font-weight:bold;">同じ町や同じサイクリングロードを2回以上通らない</span>ような道順である必要がある。サイクリングの終了時には家に帰るようにしたいため、<span style="font-weight:bold;">スタート地点は町1で、ゴール地点は町1</span>である必要がある。そして、<span style="font-weight:bold;">完成した最新のサイクリングロード1つを必ず走らなければならない</span>。また、全ての町やサイクリングロードを通る必要はない。
</p>
<p>
完成したサイクリングロードが時系列順に与えられるので、各サイクリングロードが完成した時点で、菊地君がサイクリングできるかどうかを答えよ。
</p>
<h2>Input</h2>
<p>
各データセットは、以下の形式で入力される。
</p>
<pre>N M
a1 b1
a2 b2
...
aM bM
</pre>
<p>
入力値は、全て整数である。Nは町の数、Mは作られるサイクリングロードの数である。<span style="font-weight:bold;">始め、どの町と町の間にもサイクリングロードは作られていない</span>。aiとbiは、町aiと町biを繋ぐサイクリングロードが、i番目に完成することを表わしている。
</p>
<h2>Constraints</h2>
<ul>
<li>3 <= N <= 100</li>
<li>1 <= M <= N * (N - 1) / 2</li>
<li>1 <= ai, bi <= N</li>
<li>ai ≠ bi</li>
<li>同じ町間を繋ぐサイクリングロードは、2回以上現れない。</li>
</ul>
<h2>Output</h2>
<p>
M行にわたって、問題文に指定された条件で菊地君がサイクリングできるかどうかを答えよ。出力のi行目は、{(a1, b1), (a2, b2), ..., (ai, bi)}のサイクリングロードを使って、サイクリングできるかどうかを出力する。サイクリングできるならば"Yes"、できないならば"No"と出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>3 3
1 2
2 3
3 1
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>No
No
Yes
</pre>
<p>
始めの2つのサイクリングロードだけでは、自分の町に戻ることができないためNoとなる。(3, 1)が追加されたときは、新しいサイクリングロード(3と1の道)を通りつつ、自分の町に戻ることができるためYesとなる。
</p>
<h2>Sample Input 2</h2>
<pre>4 4
1 2
2 3
2 4
3 4
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>No
No
No
No
</pre>
<p>
どの段階においても、自分の町に戻るのに、同じ町・サイクリングロードを必ず2回以上通らなければならないため、全てNoである。
</p> |
p03121 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an infinitely large triangular grid, as shown below.
Each point with integer coordinates contains a lamp.</p>
<p><img alt="" src="https://img.atcoder.jp/wtf19/f617c94527a62ed72fe7db12b6d1f6b0.png"/></p>
<p>Initially, only the lamp at <var>(X, 0)</var> was on, and all other lamps were off.
Then, Snuke performed the following operation zero or more times:</p>
<ul>
<li>Choose two integers <var>x</var> and <var>y</var>.
Toggle (on to off, off to on) the following three lamps: <var>(x, y), (x, y+1), (x+1, y)</var>.</li>
</ul>
<p>After the operations, <var>N</var> lamps <var>(x_1, y_1), \cdots, (x_N, y_N)</var> are on, and all other lamps are off.
Find <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>-10^{17} \leq x_i, y_i \leq 10^{17}</var></li>
<li><var>(x_i, y_i)</var> are pairwise distinct.</li>
<li>The input is consistent with the statement, and you can uniquely determine <var>X</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>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
-2 1
-2 2
0 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-1
</pre>
<p>The following picture shows one possible sequence of operations:</p>
<p><img alt="" src="https://img.atcoder.jp/wtf19/cff6dc4d81e995e9300ccbaca5bf85de.png"/></p></section>
</div>
</span> |
p03571 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We constructed a rectangular parallelepiped of dimensions <var>A \times B \times C</var> built of <var>ABC</var> cubic blocks of side <var>1</var>.
Then, we placed the parallelepiped in <var>xyz</var>-space as follows:</p>
<ul>
<li>For every triple <var>i, j, k</var> (<var>0 \leq i < A, 0 \leq j < B, 0 \leq k < C</var>), there exists a block that has a diagonal connecting the points <var>(i, j, k)</var> and <var>(i + 1, j + 1, k + 1)</var>. All sides of the block are parallel to a coordinate axis.</li>
</ul>
<p>For each triple <var>i, j, k</var>, we will call the above block as block <var>(i, j, k)</var>.</p>
<p>For two blocks <var>(i_1, j_1, k_1)</var> and <var>(i_2, j_2, k_2)</var>, we will define the distance between them as max<var>(|i_1 - i_2|, |j_1 - j_2|, |k_1 - k_2|)</var>.</p>
<p>We have passed a wire with a negligible thickness through a segment connecting the points <var>(0, 0, 0)</var> and <var>(A, B, C)</var>.
How many blocks <var>(x,y,z)</var> satisfy the following condition? Find the count modulo <var>10^9 + 7</var>.</p>
<ul>
<li>There exists a block <var>(x', y', z')</var> such that the wire passes inside the block <var>(x', y', z')</var> (not just boundary) and the distance between the blocks <var>(x, y, z)</var> and <var>(x', y', z')</var> is at most <var>D</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A < B < C \leq 10^{9}</var></li>
<li>Any two of the three integers <var>A, B</var> and <var>C</var> are coprime.</li>
<li><var>0 \leq D \leq 50,000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the blocks 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>3 4 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>54
</pre>
<p>The figure below shows the parallelepiped, sliced into five layers by planes parallel to <var>xy</var>-plane.
Here, the layer in the region <var>i - 1 \leq z \leq i</var> is called layer <var>i</var>.</p>
<p>The blocks painted black are penetrated by the wire, and satisfy the condition.
The other blocks that satisfy the condition are painted yellow.</p>
<div style="text-align: center;">
<img alt="b09f2a541e463456c01d148eabdf36c3.png" src="https://img.atcoder.jp/code-festival-2017-qualc/b09f2a541e463456c01d148eabdf36c3.png">
</img></div>
<p>There are <var>54</var> blocks that are painted black or yellow.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 3 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>There are four blocks that are penetrated by the wire, and only these blocks satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 5 7 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>105
</pre>
<p>All blocks satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3 123456781 1000000000 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>444124403
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1234 12345 1234567 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>150673016
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>999999997 999999999 1000000000 50000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>8402143
</pre></section>
</div>
</span> |
p02730 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A string <var>S</var> of an odd length is said to be a <em>strong palindrome</em> if and only if all of the following conditions are satisfied:</p>
<ul>
<li><var>S</var> is a palindrome.</li>
<li>Let <var>N</var> be the length of <var>S</var>. The string formed by the <var>1</var>-st through <var>((N-1)/2)</var>-th characters of <var>S</var> is a palindrome.</li>
<li>The string consisting of the <var>(N+3)/2</var>-st through <var>N</var>-th characters of <var>S</var> is a palindrome.</li>
</ul>
<p>Determine whether <var>S</var> is a strong palindrome.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> consists of lowercase English letters.</li>
<li>The length of <var>S</var> is an odd number between <var>3</var> and <var>99</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>S</var> is a strong palindrome, print <code>Yes</code>;
otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>akasaka
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<ul>
<li><var>S</var> is <code>akasaka</code>.</li>
<li>The string formed by the <var>1</var>-st through the <var>3</var>-rd characters is <code>aka</code>.</li>
<li>The string formed by the <var>5</var>-th through the <var>7</var>-th characters is <code>aka</code>.
All of these are palindromes, so <var>S</var> is a strong palindrome.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>level
</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>atcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p03822 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> contestants participated in a competition. The total of <var>N-1</var> matches were played in a knockout tournament.
For some reasons, the tournament may not be "fair" for all the contestants.
That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.</p>
<p>After each match, there were always one winner and one loser. The last contestant standing was declared the champion.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/agc009/783f7be9c88350e31963edba8a958879.png">
<p>Figure: an example of a tournament</p>
</img></div>
<p>For convenience, the contestants were numbered <var>1</var> through <var>N</var>. The contestant numbered <var>1</var> was the champion, and the contestant numbered <var>i(2 ≦ i ≦ N)</var> was defeated in a match against the contestant numbered <var>a_i</var>.</p>
<p>We will define the <em>depth</em> of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.</p>
<p>Find the minimum possible depth of the tournament.</p>
<p>The formal description of the structure of the tournament is as follows. In the <var>i</var>-th match, one of the following played against each other:</p>
<ul>
<li>Two predetermined contestants</li>
<li>One predetermined contestant and the winner of the <var>j</var>-th match, where <var>j(j<i)</var> was predetermined</li>
<li>The winner of the <var>j</var>-th match and the winner of the <var>k</var>-th match, where <var>j</var> and <var>k</var> <var>(j,k<i, j ≠ k)</var> were predetermined</li>
</ul>
<p>Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≦ N ≦ 10^5</var></li>
<li><var>1 ≦ a_i ≦ N(2 ≦ i ≦ N)</var></li>
<li>It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).</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_2</var>
:
<var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible depth of the tournament.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1
1
2
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The following tournament and the result of the matches are consistent with the given information:</p>
<ul>
<li>In the first match, contestants <var>4</var> and <var>5</var> played against each other, and contestant <var>4</var> won.</li>
<li>In the second match, contestants <var>2</var> and <var>4</var> played against each other, and contestant <var>2</var> won.</li>
<li>In the third match, contestants <var>1</var> and <var>3</var> played against each other, and contestant <var>1</var> won.</li>
<li>In the fourth match, contestants <var>1</var> and <var>2</var> played against each other, and contestant <var>1</var> won.</li>
</ul>
<div style="text-align: center;">
<img alt="783f7be9c88350e31963edba8a958879.png" src="https://atcoder.jp/img/agc009/783f7be9c88350e31963edba8a958879.png">
</img></div>
<p>The depth of this tournament is <var>3</var>, since contestant <var>5</var> must play three matches in order to win the championship.
There is no tournament with depth <var>2</var> or less that is consistent with the given information, thus the output should be <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
1
2
1
3
1
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
4
4
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p03988 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Aoki loves numerical sequences and trees.</p>
<p>One day, Takahashi gave him an integer sequence of length <var>N</var>, <var>a_1, a_2, ..., a_N</var>, which made him want to construct a tree.</p>
<p>Aoki wants to construct a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var>, such that for each <var>i = 1,2,...,N</var>, the distance between vertex <var>i</var> and the farthest vertex from it is <var>a_i</var>, assuming that the length of each edge is <var>1</var>.</p>
<p>Determine whether such a tree exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≦ N ≦ 100</var></li>
<li><var>1 ≦ a_i ≦ N-1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists a tree that satisfies the condition, print <code>Possible</code>. Otherwise, print <code>Impossible</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
3 2 2 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Possible
</pre>
<p><img alt="" src="https://atcoder.jp/img/agc005/cda0380bb5cd1b9502cfceaf2526d91e.png"/></p>
<p>The diagram above shows an example of a tree that satisfies the conditions. The red arrows show paths from each vertex to the farthest vertex from it.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Impossible
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1 2 2 2 2 2 2 2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Possible
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
1 1 2 2 2 2 2 2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Impossible
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>6
1 1 1 1 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Impossible
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>5
4 3 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>Possible
</pre></section>
</div>
</span> |
p02360 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>The Maximum Number of Overlaps</H1>
<p>
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<p>
$N$<br>
$x1_1$ $y1_1$ $x2_1$ $y2_1$<br>
$x1_2$ $y1_2$ $x2_2$ $y2_2$<br>
:<br>
$x1_N$ $y1_N$ $x2_N$ $y2_N$<br>
</p>
<p>
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
</p>
<h2>Constraints</h2>
<ul>
<li>$ 1 \leq N \leq 100000 $</li>
<li>$ 0 \leq x1_i < x2_i \leq 1000 $</li>
<li>$ 0 \leq y1_i < y2_i \leq 1000 $</li>
<li>$ x1_i, y1_i, x2_i, y2_i$ are given in integers</li>
</ul>
<h2>Output</h2>
<p>
Print the maximum number of overlapped seals in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
2
0 0 3 2
2 1 4 3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<br>
<h2>Sample Input 2</h2>
<pre>
2
0 0 2 2
2 0 4 2
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<br>
<h2>Sample Input 3</h2>
<pre>
3
0 0 2 2
0 0 2 2
0 0 2 2
</pre>
<h2>Sample Output 3</h2>
<pre>
3
</pre> |
p02675 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.</p>
<p>When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "<var>N</var> 本" for a positive integer <var>N</var> not exceeding <var>999</var> is as follows:</p>
<ul>
<li><code>hon</code> when the digit in the one's place of <var>N</var> is <var>2</var>, <var>4</var>, <var>5</var>, <var>7</var>, or <var>9</var>;</li>
<li><code>pon</code> when the digit in the one's place of <var>N</var> is <var>0</var>, <var>1</var>, <var>6</var> or <var>8</var>;</li>
<li><code>bon</code> when the digit in the one's place of <var>N</var> is <var>3</var>.</li>
</ul>
<p>Given <var>N</var>, print the pronunciation of "本" in the phrase "<var>N</var> 本".</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is a positive integer not exceeding <var>999</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>16
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>pon
</pre>
<p>The digit in the one's place of <var>16</var> is <var>6</var>, so the "本" in "<var>16</var> 本" is pronounced <code>pon</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>hon
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>183
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>bon
</pre></section>
</div>
</span> |
p00648 |
<h1>Problem B: Watchin' TVA</h1>
<p>
Animation is one of methods for making movies and in Japan, it is popular to broadcast as a television program or perform as a movie. Many people, especially the young, love one. And here is an anime lover called Jack. We say he is an mysterious guy with uncertain age. He likes anime which are broadcasted in midnight and early morning especially.
</p>
<p>
In his room, there is a huge piece of paper on the wall. He writes a timetable of TV anime on it. In his house, he can watch all Japanese TV anime programs that are broadcasted in Japan using a secret and countrywide live system. However he can not watch all anime and must give up to watch some programs because they are "broadcasted at the same time" in a season. Here, programs are "broadcasted at the same time" means that two or more programs have one or more common minutes in broadcasting time. Increasing the number of anime programs in recent makes him nervous. Actually, some people buy DVDs after the program series ends or visit a web site called vhefoo. Anyway, he loves to watch programs on his live system. Of course, he is not able to watch two or more programs at the same time. However, as described above, he must give up some programs broadcasted at the same time. Therefore, he has a set of programs <i>F</i> and he watches programs in a set <i>F</i> absolutely.
</p>
<p>
Your task is to write a program that reads a timetable and outputs the maximum number of watchable programs, keeping that Jack watches all programs in the set <i>F</i>. Of course, there are multiple choices of programs, so we want the number of programs he can watch. If two or more programs in a set <i>F</i> are broadcasted at the same time, you must give Jack an unfortunate announcement. In this case, your program outputs -1. In addition, each anime program is a program of 30 minutes.
</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>PROGRAM<sub>1</sub></i>
<i>PROGRAM<sub>2</sub></i>
...
<i>PROGRAM<sub>N</sub></i>
<i>P</i>
<i>FAV<sub>1</sub></i>
<i>FAV<sub>2</sub></i>
...
<i>FAV<sub>P</sub></i>
</pre>
<p>
<i>N</i> is the number of programs in a season.<br>
<i>PROGRAM<sub>i</sub></i>(1≤<i>i</i>≤<i>N</i>)is a string which has the following format.
</p>
<pre>
<i>name</i> <i>weekday</i> <i>start</i>
</pre>
<ul>
<li><i>name</i> is a program name. This is a a string having between 1 and 32 characters and these names do not overlap each other program. A name consists of alphanumeric characters and '_'(underscore).</li>
<li><i>weekday</i> is a broadcasting weekday about the corresponding program. This is an integer. 0 means Sunday and 1 is Monday and so on (2:Tuesday, 3:Wednesday, 4:Thursday, 5:Friday, 6:Saturday).</li>
<li><i>start</i> is a starting time of the program broadcasting. This is an integer between 600 and 2929. First one or two digits represent hour and the last two digits represent minute. If the hour has one digit it will be a representation "900" for example. Note: a program may have an integer more than or equal to 2400 as <i>start</i>, if the program begins the next day. For example, a program begins from 2500 on Monday should be interpreted as a program begins from 0100 on Tuesday.<font color="#880000"> There are no input the minute of <i>start</i> exceeds 59. And when the hour of <i>start</i> is equal to 29, there are no input the minute of <i>start</i> exceeds 29.</font></li>
</ul>
<p>
<i>P</i> is an integer and represents the number of elements in the set <i>F</i>. And <i>FAV<sub>i</sub></i>(1≤<i>i</i>≤<i>P</i>≤<i>N</i>) is a string for a program name which Jack watches absolutely. You can assume names which are not given in program descriptions will not appear in the set <i>F</i>.<br>
The last line contains a single 0 which represents the end of input.
</p>
<h2>Constraints</h2>
<p>
The number of datasets is less than or equal to 400.<br>
1≤<i>N</i>≤500
</p>
<h2>Output</h2>
<p>
For each dataset, output an integer <i>S</i> that represents maximum number of programs Jack can watch in the following format.
</p>
<pre>
<i>S</i>
</pre>
<h2>Sample Input</h2>
<pre>
1
galaxy_angel 0 600
1
galaxy_angel
11
A 0 600
B 0 610
C 0 610
D 0 610
E 0 640
EE 0 700
F 0 710
G 0 710
H 0 710
I 0 740
J 0 750
2
B
H
42
nchj 6 2620
anhnnnmewbktthsrn 4 2515
gntmdsh 1 1800
achnnl 4 2540
hnskirh 0 2200
aonexrcst 0 1700
dgdys 6 2330
hdnnara 4 2525
dnpaonntssotk 4 2555
ddmnwndrlnd 6 2500
C 4 2445
astrttnomch 0 2330
seknnqasr 1 2630
sftnt 4 2630
stnsgt 2 2605
drrnenmknmrmr 4 2610
hnzm 6 2713
yndmsoazzlsn 6 2658
mrahlcalv 4 2615
hshzrhkkrhs 1 900
ortchntsbshni 0 2430
kmnmzshrski 1 2530
sktdnc 4 1800
gykkybrkjhkirkhn 2 2459
trk 0 900
30zzsinhkntiik 3 2700
sngkotmmmirprdx 1 2600
yran 2 2529
tntissygntinybu 1 2614
skiichhtki 5 2505
tgrbnny 6 2558
dnbrsnki 3 1927
yugozxl 1 1930
frbllchrmn 1 1928
fjrg 1 1955
shwmngtr 0 2200
xmn 5 2200
rngnkkrskitikihn 0 2100
szysz 0 1254
prttyrythmaulrdrm 6 1000
sckiesfrntrqst 5 1820
mshdr 1 2255
1
mrahlcalv
0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1
4
31
</pre>
<h2>Hint</h2>
<p>
Second dataset: He can watch program E after watching B. Then he can choose a program either I or J after watching H. Therefore he can watch maximum 4 programs.
</p>
|
p03967 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer and his friend TopCoDeer is playing a game.
The game consists of <var>N</var> turns.
In each turn, each player plays one of the two <em>gestures</em>, <em>Rock</em> and <em>Paper</em>, as in Rock-paper-scissors, under the following condition:</p>
<p>(※) After each turn, (the number of times the player has played Paper)<var>≦</var>(the number of times the player has played Rock).</p>
<p>Each player's score is calculated by (the number of turns where the player wins) <var>-</var> (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.</p>
<p><em>(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)</em></p>
<p>With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the <var>N</var> turns, before the game starts.
Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.</p>
<p>The gesture that TopCoDeer will play in each turn is given by a string <var>s</var>. If the <var>i</var>-th <var>(1≦i≦N)</var> character in <var>s</var> is <code>g</code>, TopCoDeer will play Rock in the <var>i</var>-th turn. Similarly, if the <var>i</var>-th <var>(1≦i≦N)</var> character of <var>s</var> in <code>p</code>, TopCoDeer will play Paper in the <var>i</var>-th turn.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N≦10^5</var></li>
<li><var>N=|s|</var></li>
<li>Each character in <var>s</var> is <code>g</code> or <code>p</code>.</li>
<li>The gestures represented by <var>s</var> satisfy the condition (※).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the AtCoDeer's maximum possible score.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>gpg
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>Playing the same gesture as the opponent in each turn results in the score of <var>0</var>, which is the maximum possible score.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ggppgggpgg
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>For example, consider playing gestures in the following order: Rock, Paper, Rock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three victories and suffers one defeat, resulting in the score of <var>2</var>, which is the maximum possible score.</p></section>
</div>
</span> |
p02225 | <a href="https://onlinejudge.u-aizu.ac.jp/resources/icpcooc2019practice/A.pdf" target='_blank'>Problem description is available from here.</a> |
p00218 |
<H1>クラス分け</H1>
<p>
会津進学塾では、生徒が塾に入る際に実力テストを行ってクラス分けをします。テストは数学、英語、国語の 3 科目行い、生徒を A,B,C クラスにクラス分けします。A クラスのレベルが一番高く、順に低くなっていきます。
</p>
<p>
クラス分けの判断は以下の表に基づきます。
</p>
<center>
<table border=1>
<tr>
<th width="460"> 条件 </th><th width="80"> クラス</th>
</tr>
<tr>
<td>100 点の科目がある </td><td> A </td>
</tr>
<tr>
<td>数学と英語の平均点が 90 点以上 </td><td> A </td>
</tr>
<tr>
<td>3 科目の平均点が 80 点以上 </td><td> A</td>
</tr>
<tr>
<td>3 科目の平均点が 70 点以上 </td><td> B</td>
</tr>
<tr>
<td>3 科目の平均点が 50 点以上で数学か英語が 80 点以上 </td><td> B</td>
</tr>
<tr>
<td>上の条件を満たさない </td><td> C</td>
</tr>
</table>
</center>
<br/>
<p>
複数の条件を満たす場合は、よりレベルの高いクラスに分けられます。
</p>
<p>
生徒の人数 <var>n</var> (1 ≤ <var>n</var> ≤ 10000)、各生徒の数学の点数 <var>pm<sub>i</sub></var> (0 ≤ <var>pm<sub>i</sub></var> ≤ 100)、英語の点数 <var>pe<sub>i</sub></var> (0 ≤ <var>pe<sub>i</sub></var> ≤ 100)、国語の点数 <var>pj<sub>i</sub></var> (0 ≤ <var>pj<sub>i</sub></var> ≤ 100) を入力とし、各生徒のクラスA,B,C (半角英字) を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>pm<sub>1</sub></var> <var>pe<sub>1</sub></var> <var>pj<sub>1</sub></var>
<var>pm<sub>2</sub></var> <var>pe<sub>2</sub></var> <var>pj<sub>2</sub></var>
:
<var>pm<sub>n</sub></var> <var>pe<sub>n</sub></var> <var>pj<sub>n</sub></var>
</pre>
<p>
入力はすべて整数で与えられます。データセットの数は 1000 を超えません。
</p>
<H2>Output</H2>
<p>
入力データセットごとに、各生徒のクラスを順番に出力します。
</p>
<H2>Sample Input</H2>
<pre>
4
100 70 20
98 86 55
80 34 36
65 79 65
2
99 81 20
66 72 90
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
A
A
B
C
A
B
</pre>
|
p01059 |
<h1>Gossip</h1>
<!--
<p>
12プロこと会津プロダクションは有名芸能プロダクションである。12プロには多くのアイドルが在籍している。
</p>
-->
<h2>Problem</h2>
<p>
1から<var>n</var>までの番号が順番に割り当てられている<var>n</var>人のアイドルが横一列に並んでいる。<br>
アイドル<var>i</var>は単位時間でアイドル<var>i</var>-1とアイドル<var>i</var>+1に情報を伝達することができる。ただし、アイドル1はアイドル2にしか情報を伝達できず、アイドル<var>n</var>はアイドル<var>n</var>-1にしか情報を伝達できない。<br><br>
時刻0の時点で、番号が<var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, ..., <var>a<sub>m</sub></var>である<var>m</var>人のアイドルが秘密の情報を持っている。すべてのアイドルが秘密の情報を得ることのできる最小の時間を求めよ。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。</p>
<pre>
<var>n</var> <var>m</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>m</sub></var>
</pre>
<p>
1行目に2つの整数<var>n</var>と<var>m</var>が空白区切りで与えられる。<br>
2行目に<var>m</var>個の整数<var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, ..., <var>a<sub>m</sub></var>が空白区切りで与えられる。
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>n</var> ≤ 10<sup>5</sup></li>
<li>1 ≤ <var>m</var> ≤ <var>n</var></li>
<li>1 ≤ <var>a<sub>i</sub></var> ≤ <var>n</var></li>
<li><var>a<sub>i</sub></var>の値は全て異なる</li>
<li><var>a<sub>i</sub></var>は昇順で与えられる</li>
</ul>
<h2>Output</h2>
<p>
すべてのアイドルに情報が伝わる最小の時間を1行に出力する。
</p>
<h2>Sample Input 1</h2>
<pre>
3 2
1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
10 3
2 5 7
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<h2>Sample Input 3</h2>
<pre>
10 5
2 5 6 8 10
</pre>
<h2>Sample Output 3</h2>
<pre>
1
</pre>
<h2>Sample Input 4</h2>
<pre>
100000 1
1
</pre>
<h2>Sample Output 4</h2>
<pre>
99999
</pre> |
p03064 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>N</var> integers. The <var>i</var>-th integer is <var>a_i</var>.
Find the number, modulo <var>998244353</var>, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:</p>
<ul>
<li>Let <var>R</var>, <var>G</var> and <var>B</var> be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths <var>R</var>, <var>G</var> and <var>B</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 300</var></li>
<li><var>1 \leq a_i \leq 300(1\leq i\leq N)</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var>
<var>:</var>
<var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number, modulo <var>998244353</var>, of ways to paint each of the integers red, green or blue so that the condition is satisfied.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1
1
1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>18
</pre>
<p>We can only paint the integers so that the lengths of the sides of the triangle will be <var>1</var>, <var>2</var> and <var>2</var>, and there are <var>18</var> such ways.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
1
3
2
3
5
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>150
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
3
2
3
8
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>563038556
</pre></section>
</div>
</span> |
p01409 |
<H1>C: Common Palindromes</H1>
<p>
ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした.
</p>
<p>
今日の修行は,文字列中にある回文を探すことによって,文章から隠れたメッセージを読解する能力を高めようというものである.回文はたくさんあるかもしれないので,探すついでに個数も数えてしまいたい.
</p>
<p>
2 つの文字列 <i>S</i>, <i>T</i> が与えられるので,以下を満たす整数の組 (<i>i</i>, <i>j</i>, <i>k</i>, <i>l</i>) の個数を求めたい.
</p>
<ul>
<li>1 ≤ <i>i</i> ≤ <i>j</i> ≤ (<i>S</i> の長さ).</li>
<li>1 ≤ <i>k</i> ≤ <i>l</i> ≤ (<i>T</i> の長さ).</li>
<li><i>S</i> の <i>i</i> 文字目から <i>j</i> 文字目までを取り出した部分文字列は,<i>T</i> の <i>k</i> 文字目から <i>l</i> 文字目までを取り出した部分文字列と同一であり,さらにこれらは回文 (左から読んでも右から読んでも同じになる文字列) となっている.</li>
</ul>
<H2>Input</H2>
<pre>
<i>S</i>
<i>T</i>
</pre>
<p>
文字列 <i>S</i>, <i>T</i> はともに長さが 1 以上 50,000 以下であり,アルファベット大文字からなる.
</p>
<H2>Output</H2>
<p>
条件を満たす整数の組 (<i>i</i>, <i>j</i>, <i>k</i>, <i>l</i>) の個数を 1 行に出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
ICPC
CPCPC
</pre>
<H2>Sample Output 1</H2>
<pre>
10
</pre>
<H2>Sample Input 2</H2>
<pre>
BABBAB
ABBA
</pre>
<H2>Sample Output 2</H2>
<pre>
14
</pre>
<H2>Sample Input 3</H2>
<pre>
MYON
USAGI
</pre>
<H2>Sample Output 3</H2>
<pre>
0
</pre> |
p03434 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have <var>N</var> cards. A number <var>a_i</var> is written on the <var>i</var>-th card.<br/>
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.<br/>
The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</li>
<li><var>a_i \ (1 \leq i \leq N)</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</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_3</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>First, Alice will take the card with <var>3</var>. Then, Bob will take the card with <var>1</var>.
The difference of their scores will be <var>3</var> - <var>1</var> = <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 7 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>First, Alice will take the card with <var>7</var>. Then, Bob will take the card with <var>4</var>. Lastly, Alice will take the card with <var>2</var>. The difference of their scores will be <var>7</var> - <var>4</var> + <var>2</var> = <var>5</var>. The difference of their scores will be <var>3</var> - <var>1</var> = <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
20 18 2 18
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>18
</pre></section>
</div>
</span> |
p00131 |
<h1>博士の光電管</h1>
<p>
博士 : ピーター君。やったよ。
</p>
<p>
ピーター : またですか。今度はどんなくだらない発明ですか。
</p>
<p>
博士 : あの幻の素粒子アキシオンの検出器を発明したんじゃ。
</p>
<p>
ピーター : アキシオンといえば、欧州合同原子核研究機構 (CERN) をはじめとする研究者たちが血眼で追っかけているという、あれですよね。本当ですかぁ?
</p>
<p>
博士 : 本当だってばよ。細かい説明は省くが、非常に強力な磁場を内蔵する特殊な光電管が光ることによって、通過するアキシオンを検出する。
</p>
<p>
ピーター : 他 に先んじて検出すれば、小柴先生のニュートリノ検出に匹敵するノーベル賞級の研究ですよ。
これで役立たずの研究ばかりしている「ダメ研究室」などという汚名も返上できますね。
</p>
<p>
博士 : そうだとも。小柴先生の「スーパーカミオカンデ」にあやかって、この装置を、(悪口言ったら)「タダジャオカンデ」と命名した。
</p>
<p>
ピーター : ちょっと苦しいって言うか、卑屈って言うか・・・。
</p>
<p>
博士 : それはいいとして、この装置ちょっとした癖があるんじゃよ。
アキシオン粒子がある光電管を通過すると、感度の関係でその光電管と隣接する上下左右の光電管が反応する。
</p>
<center>
<table>
<tr><td>図1</td><td width=80></td><td>図2</td></tr>
<tr>
<td>
<table>
<tr>
<td>
<table>
<tr><td width="28" align="center">★</td><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td></tr>
<tr><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">★</td><td width="28" align="center">●</td></tr>
<tr><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td></tr>
<tr><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">●</td></tr>
<tr><td width="28" align="center">●</td><td width="28" align="center">●</td><td width="28" align="center">★</td><td width="28" align="center">●</td><td width="28" align="center">●</td></tr>
</table>
</td>
<td>
<table>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td width="40"> → </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
</td>
<td>
<table>
<tr><td width="28">○</td><td width="28">○</td><td width="28">●</td><td width="28">○</td><td width="28">●</td></tr>
<tr><td>○</td><td>●</td><td>○</td><td>○</td><td>○</td></tr>
<tr><td>●</td><td>●</td><td>●</td><td>○</td><td>●</td></tr>
<tr><td>●</td><td>●</td><td>○</td><td>●</td><td>●</td></tr>
<tr><td>●</td><td>○</td><td>○</td><td>○</td><td>●</td></tr>
</table>
</td>
</tr>
</table>
</td>
<td></td>
<td>
<table>
<tr>
<td>
<table>
<tr><td width="28">●</td><td width="28">○</td><td width="28">○</td><td width="28">●</td><td width="28">○</td></tr>
<tr><td>○</td><td>★</td><td>★</td><td>○</td><td>☆</td></tr>
<tr><td>●</td><td>●</td><td>○</td><td>●</td><td>●</td></tr>
<tr><td>○</td><td>●</td><td>●</td><td>○</td><td>●</td></tr>
<tr><td>●</td><td>○</td><td>○</td><td>○</td><td>●</td></tr>
</table>
</td>
<td>
<table>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td width="40"> → </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>
</td>
<td>
<table>
<tr><td width="28">●</td><td width="28">●</td><td width="28">●</td><td width="28">●</td><td width="28">●</td></tr>
<tr><td>●</td><td>●</td><td>●</td><td>○</td><td>●</td></tr>
<tr><td>●</td><td>○</td><td>●</td><td>●</td><td>○</td></tr>
<tr><td>○</td><td>●</td><td>●</td><td>○</td><td>●</td></tr>
<tr><td>●</td><td>○</td><td>○</td><td>○</td><td>●</td></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
<br/>
<p>
ピーター : つまり、図1の左側★印の光電管を粒子が通過した場合、
右側のように点灯すると言うことですね。
(図は 5 × 5 の例。黒は消灯・白は点灯状態。以下同じ。)
</p>
<p>
博士 : また反応とは、光電管の状態が反転する。つまり消えている光電管は光り、
光っている光電管は消える。
</p>
<p>
ピーター : つまり、図2の左側の★印や☆印を粒子が通過した場合、右側のような状態になると。
</p>
<p>
博士 : これを正方形になんと 100 個 (10 × 10) 配置して待ち受けるわけだ。
</p>
<p>
ピーター : これだけの大発明、ノーベル賞選考委員会も「ホッチャオカンデ」なんて。
</p>
<p>
博士 : おぉピーター君、君も我が研究室の作風になじんできたようだね。いい感じだ。
では、早速実験を始めよう。まずはこの装置、現在ランダムに光電管が点いているので、
実験が始められるように全部消えた状態にリセットしてくれたまえ。
なあに、どの光電管にアキシオン粒子を当てれば全部消えるか考えればいいだけじゃよ。
簡単だろう?
</p>
<p>
ピーター : 考えるのはいいんですが博士。当てるためには、
幻のアキシオン粒子を発生させて打ち込める装置がないといけないんじゃないですか。
</p>
<p>
博士 : ・・・。
</p>
<p>
博士とピータ (同時に)コリャアカンデ!だははは・・・・。
ー:
</p>
<p>
ということで、本日も和気あいあいと暮れてゆく博士の研究室ですが、例によって話は全く進みそうもありません。しょうがないので、ピーター君に代わってプログラムを作成してあげてください。
プログラムは次のようなものになります。
</p>
<p>
A. 装置の光電管の状態を 10 × 10 の配列として入力します。0は消灯中、1は点灯中を表します。
0 と 1 以外のデータは含まれません。
</p>
<p>
B. 入力した装置の状態をすべて消灯にするために、アキシオン粒子を通過させる位置を計算して出力します。これは、入力と同じ 10 × 10の配列で光電管の位置を表します。「0 は通過させない」、「1 は通過させる」ことを表します。すべてを消灯する方法は必ず 1 通りだけ存在するものとします。
</p>
<!--
なお、以下はヒントです。
a. 粒子を通過させる順番は結果に関係ありません。
b. 粒子を偶数回通過させることは通過させないことと同じです。 また、奇数回通過させるこ
とは1回通過させることと同じです。
c. 以上から、すべての光電管について0(通過させない)と 1(通過させる)のどちらかを選
択することがすなわち解答になります。
C. プログラムを終了します。
-->
<H2>Input</H2>
<p>
複数のデータセットが与えられます。1行目にデータセットの数 <var>n</var> (<var>n</var> ≤ 20) が与えられます。各データセットは以下の形式で与えられます。
</p>
<pre>
<var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,10</sub></var>
<var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,10</sub></var>
:
<var>a<sub>10,1</sub></var> <var>a<sub>10,2</sub></var> ... <var>a<sub>10,10</sub></var>
</pre>
<p>
<var>a<sub>i,j</sub></var> は装置の <var>i</var> 行目 <var>j</var> 列目の光電管の状態を示す整数 (0 または 1) を表します。
</p>
<H2>Output</H2>
<p>
各データセットについて、粒子を通過させる位置を以下の形式で出力してください。
</p>
<pre>
<var>b<sub>1,1</sub></var> <var>b<sub>1,2</sub></var> ... <var>b<sub>1,10</sub></var>
<var>b<sub>2,1</sub></var> <var>b<sub>2,2</sub></var> ... <var>b<sub>2,10</sub></var>
:
<var>b<sub>10,1</sub></var> <var>b<sub>10,2</sub></var> ... <var>b<sub>10,10</sub></var>
</pre>
<p>
<var>b<sub>i,j</sub></var> は装置の <var>i</var> 行目 <var>j</var> 列目の光電管に粒子を通過させるかいなかを示す整数 (0 または 1) を表します。
</p>
<H2>Sample Input</H2>
<pre>
1
0 1 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 1 0 0 1 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 1 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0
</pre>
|
p00561 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>Kingdom of JOIOI</h1>
<p>
The Kingdom of JOIOI is a rectangular grid of $H \times W$ cells. In the Kingdom of JOIOI, in order to improve efficiency of administrative institutions, the country will be divided into two regions called "JOI" and "IOI."
</p>
<p>
Since we do not want to divide it in a complicated way, the division must satisfy the following conditions:
</p>
<ul>
<li> Each region must contain at least one cell.</li>
<li> Each cell must belong to exactly one of two regions.</li>
<li> For every pair of cells in the JOI region, we can travel from one to the other by passing through cells belonging to the JOI region only. When move from a cell to another cell, the two cells must share an edge. The same is true for the IOI region.</li>
<li> For each row or column, if we take all the cells in that row or column, the cells belonging to each region must be connected. All the cells in a row or column may belong to the same region.</li>
</ul>
<p>
Each cell has an integer called the <b>altitude</b>. After we divide the country into two regions, it is expected that traveling in each region will be active. But, if the difference of the altitudes of cells are large, traveling between them becomes hard. Therefore, we would like to minimize the maximum of the difference of the altitudes between cells belonging to the same region. In other words, we would like to minimize the larger value of
</p>
<ul>
<li> the difference between the maximum and the minimum altitudes in the JOI region, and</li>
<li> the difference between the maximum and the minimum altitudes in the IOI region.</li>
</ul>
<h3>Task</h3>
<p>
Given the altitudes of cells in the Kingdom of JOIOI, write a program which calculates the minimum of the larger value of the difference between the maximum and the minimum altitudes in the JOI region and the difference between the maximum and the minimum altitudes in the IOI region when we divide the country into two regions.
</p>
<h3>Input</h3>
<p>
Read the following data from the standard input.
</p>
<ul>
<li> The first line of input contains two space separated integers $H$, $W$. This means the Kingdom of JOIOI is a rectangular grid of $H \times W$ cells.</li>
<li> The $i$-th line ($1 \leq i \leq H$) of the following $H$ lines contains $W$ space separated integers $A_{i,1}, A_{i,2}, ..., A_{i,W}$. This means the cell in the $i$-th row from above and $j$-th column from left ($1 \leq j \leq W$) has altitude $A_{i,j}$.</li>
</ul>
<h3>Output</h3>
<p>
Write one line to the standard output. The output contains the minimum of the larger value of the difference between the maximum and the minimum altitudes in the JOI region and the difference between the maximum and the minimum altitudes in the IOI region when we divide the country into two regions.
</p>
<h3>Constraints</h3>
<p>
All input data satisfy the following conditions.
</p>
<ul>
<li>$2 \leq H \leq 2 000.$</li>
<li>$2 \leq W \leq 2 000.$</li>
<li>$1 \leq A_{i, j} \leq 1 000 000 000 (1 \leq i \leq H, 1 \leq j \leq W).$</li>
</ul>
<h3>Sample Input and Output</h3>
<h3>Sample Input 1</h3>
<pre>
4 4
1 12 6 11
11 10 2 14
10 1 9 20
4 17 19 10
</pre>
<h3>Sample Output 1</h3>
<pre>
11
</pre>
<p>
For example, in this sample input, we divide the country into two regions as follows. Here, ‘J’ denotes the JOI region, and ‘I’ denotes the IOI region.
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_3_1">
<p>
The following division does not satisfy the condition because, in the third column from left, cells with ‘I’ are not connected.
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_3_2">
<h3>Sample Input 2</h3>
<pre>
8 6
23 23 10 11 16 21
15 26 19 28 19 20
25 26 28 16 15 11
11 8 19 11 15 24
14 19 15 14 24 11
10 8 11 7 6 14
23 5 19 23 17 17
18 11 21 14 20 16
</pre>
<h3>Sample Output 2</h3>
<pre>
18
</pre>
<br/>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commonse License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2016/2017-ho/index.html">The 16th Japanese Olympiad in Informatics (JOI 2016/2017)
Final Round</a>
</p>
</div> |
p00832 | <H1><font color="#000">Problem F:</font> Dice Puzzle</H1>
<p>
Let’s try a dice puzzle. The rules of this puzzle are as follows.
</p>
<ol>
<li>
Dice with six faces as shown in Figure 1 are used in the puzzle.
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/dicePuzzle1">
<p>Figure 1: Faces of a die</p>
</center>
</li>
<li>
With twenty seven such dice, a 3 × 3 × 3 cube is built as shown in Figure 2.
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/dicePuzzle2">
<p>Figure 2: 3 × 3 × 3 cube</p>
</center>
</li>
<li>
When building up a cube made of dice, the sum of the numbers marked on the faces of adjacent dice that are placed against each other must be seven (See Figure 3). For example, if one face of the pair is marked “2”, then the other face must be “5”.
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/dicePuzzle3">
<p>Figure 3: A pair of faces placed against each other</p>
</center>
</li>
<li>
The top and the front views of the cube are partially given, i.e. the numbers on faces of
some of the dice on the top and on the front are given.
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/dicePuzzle4">
<p>Figure 4: Top and front views of the cube</p>
</center>
</li>
<li>
The goal of the puzzle is to find all the plausible dice arrangements that are consistent
with the given top and front view information.
</li>
</ol>
<p>
Your job is to write a program that solves this puzzle.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets in the following format.
</p>
<pre>
<i>N</i>
<i>Dataset</i><sub>1</sub>
<i>Dataset</i><sub>2</sub>
...
<i>Dataset<sub>N</sub></i>
</pre>
<p>
<i>N</i> is the number of the datasets.
</p>
<p>
The format of each dataset is as follows.
</p>
<pre>
<i>T</i><sub>11</sub> <i>T</i><sub>12</sub> <i>T</i><sub>13</sub>
<i>T</i><sub>21</sub> <i>T</i><sub>22</sub> <i>T</i><sub>23</sub>
<i>T</i><sub>31</sub> <i>T</i><sub>32</sub> <i>T</i><sub>33</sub>
<i>F</i><sub>11</sub> <i>F</i><sub>12</sub> <i>F</i><sub>13</sub>
<i>F</i><sub>21</sub> <i>F</i><sub>22</sub> <i>F</i><sub>23</sub>
<i>F</i><sub>31</sub> <i>F</i><sub>32</sub> <i>F</i><sub>33</sub>
</pre>
<p>
<i>T<sub>ij</sub></i> and <i>F<sub>ij</sub></i> (1 ≤ <i>i</i> ≤ 3, 1 ≤ <i>j</i> ≤ 3) are the faces of dice appearing on the top and front views,
as shown in Figure 2, or a zero. A zero means that the face at the corresponding position is
unknown.
</p>
<H2>Output</H2>
<p>
For each plausible arrangement of dice, compute the sum of the numbers marked on the nine
faces appearing on the right side of the cube, that is, with the notation given in Figure 2,
∑<sup>3</sup><sub><i>i</i>=1</sub>∑<sup>3</sup><sub><i>j</i>=1</sub><i>R<sub>ij</sub></i>.
</p>
<p>
For each dataset, you should output the right view sums for all the plausible arrangements, in
ascending order and without duplicates. Numbers should be separated by a single space.
</p>
<p>
When there are no plausible arrangements for a dataset, output a zero.
</p>
<p>
For example, suppose that the top and the front views are given as follows.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/dicePuzzle5">
<p>Figure 5: Example</p>
</center>
<p>There are four plausible right views as shown in Figure 6. The right view sums are 33, 36, 32,
and 33, respectively. After rearranging them into ascending order and eliminating duplicates,
the answer should be “32 33 36”.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/dicePuzzle6">
<p>Figure 6: Plausible right views</p>
</center>
<p>
The output should be one line for each dataset. The output may have spaces at ends of lines.
</p>
<H2>Sample Input</H2>
<pre>
4
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
4 3 3
5 2 2
4 3 3
6 1 1
6 1 1
6 1 0
1 0 0
0 2 0
0 0 0
5 1 2
5 1 2
0 0 0
2 0 0
0 3 0
0 0 0
0 0 0
0 0 0
3 0 1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
27
24
32 33 36
0
</pre>
|
p01720 |
<p>イクタ君は、無向グラフについて異常なほどの思い入れを持っている。イクタ君は、無向グラフ <var>G</var> とその 2 点 <var>s,t</var>の組<var>(G,s,t)</var>のうち、その「うつくしさ」が大きいものが好きである。
組<var>(G,s,t)</var>の「うつくしさ」とは、辺 <var>e = \{u, v\}</var> (<var>u</var> と <var>v</var> は <var>G</var> の異なる 2 点) で、<var>G</var>における<var>s</var>から<var>t</var>への最短路の長さが、<var>G</var>に<var>e</var>をつけくわえた無向グラフにおける<var>s</var>から<var>t</var>への最短路の長さより 1 だけ大きいものの個数である。
</p>
<p>あなたの仕事は、組<var>(G,s,t)</var>が与えられたとき、その「うつくしさ」を求めるプログラムを書くことである。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。
</p><blockquote>
<var>N</var> <var>M</var> <var>s</var> <var>t</var><br><var>x<sub>1</sub></var> <var>y<sub>1</sub></var><br>...<br><var>x<sub>i</sub></var> <var>y<sub>i</sub></var><br>...<br><var>x<sub>M</sub></var> <var>y<sub>M</sub></var><br></blockquote>
<p>最初に無向グラフの頂点数、辺数、2つの頂点を表す整数<var>N,M,s,t</var>が入力される。
2行目から<var>M+1</var>行目までは辺によって結ばれている2つの頂点が入力される。
(ただし、<var>G</var> の頂点集合を<var>\{1,</var>...<var>, N\}</var>とする。)
</p>
<h3>Constraints</h3>
<p>入力中の各変数は以下の制約を満たす。</p>
<ul>
<li> <var>2≤ N ≤ 100,000</var>
</li>
<li> <var>1≤ M ≤ 300,000</var>
</li>
<li> <var>1≤ s,t,x<sub>i</sub>,y<sub>i</sub> ≤ N</var>
</li>
<li> <var>s</var> と <var>t</var> とは異なる
</li>
<li> <var>s</var> から <var>t</var> に辿り着けることは保証されている
</li></ul>
<h2>Output</h2>
<p>与えられたグラフを<var>G</var>としたとき、組<var>(G,s,t)</var>の「うつくしさ」を1行で出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>3 2 1 3
1 2
2 3
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
</pre>
<ul><li> 頂点1から頂点3に辺を張ると、2点間の最短距離が 1 短くなる。
</li></ul>
<h2>Sample Input 2</h2>
<pre>9 8 7 8
2 6
4 9
8 6
9 2
3 8
1 8
8 5
7 9
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>7
</pre>
<h2>Sample Input 3</h2>
<pre>4 3 1 4
1 2
3 4
4 1
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>0
</pre><ul><li> 頂点1と頂点4には既に辺が張られているので、これ以上距離を縮めることはできない。
</li></ul>
<h2>Sample Input 4</h2>
<pre>9 7 8 9
9 6
6 5
3 6
3 7
2 5
8 5
1 4
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>2
</pre> |
p01370 |
<!-- begin en only -->
<!--<h3><U>Brave Force Story</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><i>
「最果ての地,ナイン・アイランドには特別な力を持つものが生きていた.
ある者は火,ある者は氷,ある者は風,ある者は土を意のままに操ることができた.
人はこれらの術者をこう呼んだ.『Brave Force』と・・・.時は戦国時代.権力者たちはBrave Forceを私欲のために使わんとBrave Force狩りを始めた.
Brave Forceを巡る戦いが今始まろうとしている.」
</i></p>
<p>
以上は,あなたが今つくろうとしている戦略シミュレーションゲームのプロローグである.このプロローグは本問題には全く関係ない.
</p>
<p>
問題の説明に戻ろう.戦略シミュレーションの世界においては, 正6角形のマスがよく使われる.
これは, 正方形のマスに比べて方向による距離の違いが小さく, 敷き詰めも可能であるからである.
</p>
<p>
今回はこのようなマップ上でコマを動かすことを考える.コマは各ターンごとに隣接するマスに移動させることができる.
もちろんマップ上には多くの障害物があってそこには移動することができない.さて一定のターン数が経過するまでにたどり着くことが可能なマスの数はいくつあるだろうか.
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
入力はそれぞれがマップの情報を表す1つ以上のデータセットからなる.
</p>
<p>
データセットの最初の行には, 2つの整数が含まれていて, 1番目がターン数 <i>t</i> で, 2番目が障害物の数 <i>n</i> である.
</p>
<p>
それに続く <i>n</i> 行にはそれぞれ障害物のマスの座標を表す2つの整数が含まれていて, 1番目が x 座標で, 2番目が y 座標である. 障害物の座標は互いに異なっている.
</p>
<p>
そして最後の行にはスタート位置のマスの座標を表す2つの整数が含まれていて, 1番目が x 座標で, 2番目が y 座標である. このマスには障害物はない. またこのマスは到達できるマスに含められる.
</p>
<p>
マスに割り当てられた座標は下の図のようになっている.
</p>
<p style="text-align: center;">
<a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011B-1" width="50%">
</a><br/>
図B-1 マスに割り当てられた座標
</p>
<p>
入力の終わりは"0 0"を含む行で表される.
</p>
<p>
いずれの座標も絶対値が30以下である. ターン数は1以上30以下である. 障害物の数は0以上300以下である.
</p>
<p style="text-align: center;">
<a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011B-2" width="50%">
</a><br/>
図B-2 Sample Input の1つ目のデータセット
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
各マップについて到達できるマスの数を表す整数を各行に出力せよ. それ以外の余計な文字を出力に含めてはいけない.
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
1 1
1 0
0 0
2 2
-2 1
2 0
2 2
2 0
-1 1
4 4
-2 1
1 -2
1 2
3 -3
-2 0
4 6
0 1
1 1
1 0
-1 0
-1 -1
0 -1
0 0
0 0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
6
18
19
58
1
</pre>
</div>
|
p00998 |
<h1>Problem I : RMQ</h1>
<p>
<i>n</i> 個の数字<i>a<sub>0</sub></i> ,<i>a<sub>1</sub></i> , ... ,<i>a<sub>n-1</sub></i> と<i>q</i> が与えられる。<br>
<i>q</i> 個のクエリーに対して適切な処理を行なって欲しい。<br>
クエリーは以下の3種類の操作が存在する。<br>
</p>
<ul>
<li>値のシフトを行う</li>
<i>l</i> と<i>r</i> のペアが与えられる。(<i>l</i> < <i>r</i> )
<i>a<sub>l</sub></i> から <i>a<sub>r</sub></i> までの値を Circular Shiftさせる。
<br>
<br>
<span>
0 1 2 3 4 5 6 7 8 9<br>
</span>
<br>
に対してl=2,r=5というクエリーが与えられたとする。<br>
<br>
シフトを行った数字列は<br>
<br>
<span>
0 1 5 2 3 4 6 7 8 9<br>
</span>
<br>
となる。<br>
</ul>
<ul>
<li>最小値を求める</li>
<i>l</i> と<i>r</i> のペアが与えられる。(<i>l</i> ≤ <i>r</i> ) <br>
<i>a<sub>l</sub></i> から <i>a<sub>r</sub></i>までの値の中で最小の値を求める。<br>
</ul>
<ul>
<li>値の更新</li>
<i>pos</i> と <i>val</i> のペアが与えられる。
<i>a<sub>pos</sub></i> の値を <i>val</i> に更新する。
</ul>
<h2>Input</h2>
<p>
入力は以下のフォーマットで与えられる。
</p>
<pre>
<i>n</i> <i>q</i>
<i>a<sub>0</sub></i>
<i>a<sub>1</sub></i>
.
.
.
<i>a<sub>n-1</sub></i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>z<sub>1</sub></i>
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>z<sub>2</sub></i>
.
.
.
<i>x<sub>q</sub></i> <i>y<sub>q</sub></i> <i>z<sub>q</sub></i>
</pre>
<p>
<i>x<sub>i</sub> = 0</i> なら、シフトのクエリーを表す。このとき、<i>l = y<sub>i</sub></i> , <i>r = z<sub>i</sub></i> とする。<br>
<i>x<sub>i</sub> = 1</i> なら、最小値を求めるクエリーを表す。このとき、<i>l = y<sub>i</sub></i> , <i>r = z<sub>i</sub></i> とする。<br>
<i>x<sub>i</sub> = 2</i> なら、値を更新するクエリーを表す。このとき、<i>pos = y<sub>i</sub></i> , <i>val = z<sub>i</sub></i> とする。<br>
</p>
<p>
入力は以下の制約を満たす<br>
1 ≤ <i>n , q</i> ≤ 200,000<br>
0 ≤ <i>a<sub>i</sub></i> ≤ 10,000,000</br>
値を更新するクエリーについて、0 ≤ <i>val</i> ≤ 10,000,000</br>
</p>
<h2>Output</h2>
<p>
クエリーとして<i>x<sub>i</sub> = 1</i> が与えられたときに、答えの値を1行に出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
10 3
0
1
2
3
4
5
6
7
8
9
1 5 7
0 2 5
1 5 7
</pre>
<h2>Sample Output 1</h2>
<pre>
5
4
</pre>
<h2>Sample Input 2</h2>
<pre>
10 10
289383
930886
692777
636915
747793
238335
885386
760492
516649
641421
2 7 368690
1 3 6
0 2 6
1 1 8
0 2 9
2 2 665123
1 5 9
0 2 8
2 7 961393
1 1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
238335
238335
238335
368690
</pre>
|
p00977 | <h2>Colorful Tree</h2>
<p>
A tree structure with some colors associated with its vertices and a sequence of commands on it are given. A command is either an update operation or a query on the tree. Each of the update operations changes the color of a specified vertex, without changing the tree structure. Each of the queries asks the number of edges in the minimum connected subgraph of the tree that contains all the vertices of the specified color.
</p>
<p>
Your task is to find answers of each of the queries, assuming that the commands are performed in the given order.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$
$a_1$ $b_1$
...
$a_{n-1}$ $b_{n-1}$
$c_1 ... c_n$
$m$
$command_1$
...
$command_m$
</pre>
<p>
The first line contains an integer $n$ ($2 \leq n \leq 100 000$), the number of vertices of the tree. The vertices are numbered 1 through $n$. Each of the following $n - 1$ lines contains two integers $a_i$ ($1 \leq a_i \leq n$) and $b_i$ ($1 \leq b_i \leq n$), meaning that the $i$-th edge connects vertices $a_i$ and $b_i$. It is ensured that all the vertices are connected, that is, the given graph is a tree. The next line contains $n$ integers, $c_1$ through $c_n$, where $c_j$ ($1 \leq c_j \leq 100 000$) is the initial color of vertex $j$. The next line contains an integer $m$ ($1 \leq m \leq 100 000$), which indicates the number of commands. Each of the following $m$ lines contains a command in the following format.
</p>
<pre>
$U$ $x_k$ $y_k$
</pre>
<p>or</p>
<pre>
$Q$ $y_k$
</pre>
<p>
When the $k$-th command starts with <span>U</span>, it means an update operation changing the color of vertex $x_k$ ($1 \leq x_k \leq n$) to $y_k$ ($1 \leq y_k \leq 100 000$). When the $k$-th command starts with <span>Q</span>, it means a query asking the number of edges in the minimum connected subgraph of the tree that contains all the vertices of color $y_k$ ($1 \leq y_k \leq 100 000$).
</p>
<h3>Output</h3>
<p>
For each query, output the number of edges in the minimum connected subgraph of the tree containing all the vertices of the specified color. If the tree doesn't contain any vertex of the specified color, output <span>-1</span> instead.
</p>
<h3>Sample Input 1</h3>
<pre>
5
1 2
2 3
3 4
2 5
1 2 1 2 3
11
Q 1
Q 2
Q 3
Q 4
U 5 1
Q 1
U 3 2
Q 1
Q 2
U 5 4
Q 1
</pre>
<h3>Sample Output 1</h3>
<pre>
2
2
0
-1
3
2
2
0
</pre>
|
p03658 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> sticks.
The length of the <var>i</var>-th stick is <var>l_i</var>.</p>
<p>Snuke is making a snake toy by joining <var>K</var> of the sticks together.</p>
<p>The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq N \leq 50</var></li>
<li><var>1 \leq l_i \leq 50</var></li>
<li><var>l_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>K</var>
<var>l_1</var> <var>l_2</var> <var>l_3</var> <var>...</var> <var>l_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>You can make a toy of length <var>12</var> by joining the sticks of lengths <var>3</var>, <var>4</var> and <var>5</var>, which is the maximum possible length.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15 14
50 26 27 21 41 7 42 35 7 5 5 36 39 1 45
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>386
</pre></section>
</div>
</span> |
p01665 |
<h2>J - タイル置き</h2>
<p>
サイズ<var>H</var>×<var>W</var>の盤面にサイズ1×2のタイルをマス目にそって<var>N</var>個配置する方法が何通りあるか求めたい.</p>
<p>タイルは重なってはいけない. また縦横どちらの向きに置いても構わない.</p>
<p>タイルは全て同じ見た目であり互いに区別しないものとする.</p>
<p>タイルは180度回転しても同じ見た目であり、区別しないものとする.</p>
<p>答えは大きくなる可能性があるので1,000,000,007で割った余りを答えよ</p>
<h2>入力形式</h2>
<p>
入力は以下の形式で与えられる.
<pre>
<var>H</var> <var>W</var> <var>N</var>
</pre>
<h2>出力形式</h2>
<p>タイルの置き方の総数を 1,000,000,007 で割った余りを出力せよ.
</p>
<h2>制約</h2>
<ul>
<li><var>1 ≤ H ≤ 1,000,000,000</var></li>
<li><var>1 ≤ W ≤ 1,000,000,000</var></li>
<li><var>1 ≤ N ≤ 5</var></li>
<li>入力値はすべて整数である.</li>
</ul>
<p>
この問題の判定には,50 点分のテストケースのグループが設定されている.このグループに含まれるテストケースは上記の制約に加えて下記の制約も満たす.
</p>
<ul>
<li><var>1 ≤ H ≤ 6</var></li>
<li><var>1 ≤ W ≤ 6</var></li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
2 2 1
</pre>
<h3>出力例 1</h3>
<pre>
4
</pre>
<p>次の4通りある。</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_tile_2_2_1">
<h3>入力例 2</h3>
<pre>
2 2 2
</pre>
<h3>出力例 2</h3>
<pre>
2
</pre>
<p>次の2通りある</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_tile_2_2_2">
<h3>入力例 3</h3>
<pre>
2 2 3
</pre>
<h3>出力例 3</h3>
<pre>
0
</pre>
<h3>入力例 4</h3>
<pre>
1000000000 1000000000 5
</pre>
<h3>出力例 4</h3>
<pre>
68450176
</pre> |
p04037 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> piles of candies on the table. The piles are numbered <var>1</var> through <var>N</var>. At first, pile <var>i</var> contains <var>a_i</var> candies.</p>
<p>Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of the following two operations:</p>
<ol>
<li>Choose a pile with the largest number of candies remaining, then eat all candies of that pile.</li>
<li>From each pile with one or more candies remaining, eat one candy.</li>
</ol>
<p>The player who eats the last candy on the table, loses the game. Determine which player will win if both players play the game optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N≤10^5</var></li>
<li><var>1≤a_i≤10^9</var></li>
</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>If Snuke will win, print <code>First</code>. If Ciel will win, print <code>Second</code>.</p>
</section>
</div>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>First
</pre>
<p>At the beginning of the game, pile <var>2</var> contains the most candies. If Snuke eats all candies of this pile, Ciel has no choice but to eat the last candy.</p>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>First
</pre>
<p>If Snuke eats one candy from each pile, Ciel is again left with the last candy.</p>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Second
</pre></section>
</div>
</hr></hr></hr></hr></span> |
p03208 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some other world, today is Christmas Eve.</p>
<p>There are <var>N</var> trees planted in Mr. Takaha's garden. The height of the <var>i</var>-th tree <var>(1 \leq i \leq N)</var> is <var>h_i</var> meters.</p>
<p>He decides to choose <var>K</var> trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.</p>
<p>More specifically, let the height of the tallest decorated tree be <var>h_{max}</var> meters, and the height of the shortest decorated tree be <var>h_{min}</var> meters. The smaller the value <var>h_{max} - h_{min}</var> is, the better. What is the minimum possible value of <var>h_{max} - h_{min}</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K < N \leq 10^5</var></li>
<li><var>1 \leq h_i \leq 10^9</var></li>
<li><var>h_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>K</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>Print the minimum possible value of <var>h_{max} - h_{min}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
10
15
11
14
12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If we decorate the first, third and fifth trees, <var>h_{max} = 12, h_{min} = 10</var> so <var>h_{max} - h_{min} = 2</var>. This is optimal.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 3
5
7
5
7
7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If we decorate the second, fourth and fifth trees, <var>h_{max} = 7, h_{min} = 7</var> so <var>h_{max} - h_{min} = 0</var>. This is optimal.</p>
<p>There are not too many trees in these sample inputs, but note that there can be at most one hundred thousand trees (we just can't put a sample with a hundred thousand lines here).</p></section>
</div>
</span> |
p01235 |
<H1><font color="#000">Problem B:</font> Electrophoretic</H1>
<p>
Scientist Frank, majoring in electrochemistry, has developed line-shaped strange electrodes called <i>F-electrodes</i>.
During being activated, each F-electrode causes a special potential on and between the two lines touching the
F-electrode’s endpoints at a right angle. Then electrically-charged particles located inside the potential area get
to move in the direction parallel to the potential boundary (i.e. perpendicular to the F-electrode), either toward or
against F-electrode. The moving direction can be easily controlled between the two possibles; it is also possible
to get particles to pass through F-electrodes. In addition, unlike ordinary electrodes, F-electrodes can affect
particles even infinitely far away, as long as those particles are located inside the potential area. On the other
hand, two different F-electrodes cannot be activated at a time, since their potentials conflict strongly.
</p>
<p>
We can move particles on our will by controlling F-electrodes. However, in some cases, we cannot lead them to
the desired positions due to the potential areas being limited. To evaluate usefulness of F-electrodes from some
aspect, Frank has asked you the following task: to write a program that finds the shortest distances from the
particles’ initial positions to their destinations with the given sets of F-electrodes.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_electrophoretic">
</center>
<H2>Input</H2>
<p>
The input consists of multiple test cases. The first line of each case contains <i>N</i> (1 ≤ <i>N</i> ≤ 100) which represents
the number of F-electrodes. The second line contains four integers <i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>, <i>x<sub>t</sub></i> and <i>y<sub>t</sub></i>, where (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>) and (<i>x<sub>t</sub></i>, <i>y<sub>t</sub></i>)
indicate the particle’s initial position and destination. Then the description of <i>N</i> F-electrodes follow. Each line
contains four integers <i>Fx<sub>s</sub></i>, <i>Fy<sub>s</sub></i>, <i>Fx<sub>t</sub></i> and <i>Fy<sub>t</sub></i>, where (<i>Fx<sub>s</sub></i>, <i>Fy<sub>s</sub></i>) and (<i>Fx<sub>t</sub></i>, <i>Fy<sub>t</sub></i> ) indicate the two endpoints of an
F-electrode. All coordinate values range from 0 to 100 inclusive.
</p>
<p>
The input is terminated by a case with <i>N</i> = 0.
</p>
<H2>Output</H2>
<p>
Your program must output the case number followed by the shortest distance between the initial position to
the destination. Output “Impossible” (without quotes) as the distance if it is impossible to lead the elementary
particle to the destination. Your answers must be printed with five digits after the decimal point. No absolute
error in your answers may exceed 10<sup>-5</sup>.
</p>
<H2>Sample Input</H2>
<pre>
2
2 1 2 2
0 0 1 0
0 1 0 2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 3.00000
</pre>
|
p00074 |
<H1>ビデオテープ</H1>
<p>
標準録画で 120 分のビデオテープがあります。テープを完全に巻き戻した状態でビデオデッキのカウンタを 00:00:00 にし、標準録画モードで録画したところ、あるカウンタ値になりました。このカウンタ値(時、分、秒)を入力し、残りのテープの長さ(録画可能時間)を求め、時:分:秒の形式で出力するプログラムを作成して下さい。
</p>
<p>
ただし、2 時間(120分)以内の入力とします。なお、テープ残量は標準録画モードと 3 倍録画モードの場合の2通りを計算し、出力例のように時、分、秒とも 2 桁ずつ出力します。また "05" のように 10 の位が 0 の場合は、"0" をつけてください。
</p>
<H2>入力</H2>
<p> 複数のデータセットが与えられます。各データセットは以下のとおりです。</p>
<pre class=exp>
<var>T</var> <var>H</var> <var>S</var>
</pre>
<p>
<var>T</var>, <var>H</var>, <var>S</var> はそれぞれ時、分、秒を表す整数です。
</p>
<p>
<var>T</var>, <var>H</var>, <var>S</var> がすべて -1 のとき入力の終わりとします。データセットの数は 50 を超えません。
</p>
<H2>出力</H2>
<p>各データセットごとに<br/>
1 行目に、テープの残りを標準録画した場合の録画可能時間の時、分、秒を半角コロン区切りで、<br/>
2 行目に、テープの残りを3倍録画した場合の録画可能時間の時、分、秒を半角コロン区切りで<br/>
出力して下さい。
</p>
<H2>Sample Input</H2>
<pre>
1 30 0
-1 -1 -1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
00:30:00
01:30:00
</pre>
|
p02049 | <h3>全宇宙生命ゲノムデータベース リターンズ</h3>
<!-- begin ja only -->
<p>西暦2301年,宇宙連邦共和国の生命科学局では,宇宙生物のゲノム配列の研究を行っていた.近年の研究の結果,ゲノム配列に特定のパターンが何回現れるかが生物の性質に大きく影響することが分かってきた.</p>
<p>宇宙生物のゲノム配列は英大文字からなる文字列で表される.研究員たちはゲノム配列の中に,ある特定のパターンが何回現れるかを数え上げることにした.しかしながら,宇宙生物のゲノム配列は非常に長いため,後述する方法で繰り返しがある部分文字列を圧縮してデータベースに保存している.</p>
<p>あなたの仕事は圧縮されたゲノム配列 <i>S</i> から文字列 <i>Q</i> の出現回数を数え上げるプログラムを作成することである.ただし,<i>Q</i> の出現は,開始位置さえ異なっていれば,重なっている部分があっても別の出現として数える.例えば, MISSISSIPPI に ISSI は 2 回出現する.</p>
<p>ゲノム配列の圧縮方法は以下のBNFで定義される.</p>
<blockquote><Genome> ::= <Letter> | <Number> <Letter> | <Number> ( <Genome> ) | <Genome> <Genome>
<Letter> ::= 'A' | 'B' | … | 'Z'
<Number> ::= <Digit> | <Number> '0' | <Number> <Digit>
<Digit> ::= '1' | '2' | … | '9'</blockquote>
<p>ここで,文字列の前に付けられる整数はその文字列がその回数だけ繰り返されることを表す.例えば,5A は AAAAA を表し,2(AB) は ABAB を表す.整数の直後に括弧がない場合は,その直後の1文字のみが繰り返される.例えば,2AB は AAB を表す.繰り返しは多重にネストすることが可能で,2(2(AB)C) は 2(ABABC) と同じであり,ABABCABABC を表す.</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>入力は最大で 50 個のデータセットから構成される.各データセットは次の形式で表される.</p>
<blockquote><i>S</i>
<i>Q</i></blockquote>
<p>各データセットの1行目は,圧縮されたゲノム配列を表す文字列 <i>S</i> である.<i>S</i> は上記のBNFに従い,その長さは <i>1</i> 以上 <i>3 000</i> 文字以下である.また,<i>S</i> を展開した元のゲノム配列の長さは <i>10<sup>18</sup></i> 以下である.各データセットの2行目は数え上げる対象となる文字列 <i>Q</i> である.<i>Q</i> は英大文字からなり,長さは <i>1</i> 以上 <i>3 000</i> 文字以下である.</p>
<p>入力の終了は '#' の1文字だけを含む行で表される.</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>各データセットについて,<i>S</i> を展開した文字列に <i>Q</i> が何回現れるかを出力せよ.</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>MI2(2SI)2PI
ISSI
100(100(JAG))
JAG
1000000000000000000A
AAAAA
#
</pre><h3>Output for the Sample Input</h3><pre>2
10000
999999999999999996
</pre>
|
p00424 |
<H1></H1>
<p>
与えられた変換表にもとづき,データを変換するプログラムを作成しなさい.
</p>
<p>
データに使われている文字は英字か数字で,英字は大文字と小文字を区別する.変換表に現れる文字の順序に規則性はない.
</p>
<p>
変換表は空白をはさんで前と後ろの 2 つの文字がある(文字列ではない).変換方法は,変換表のある行の前の文字がデータに現れたら,そのたびにその文字を後ろの文字に変換し出力する.変換は 1 度だけで,変換した文字がまた変換対象の文字になっても変換しない.変換表に現れない文字は変換せず,そのまま出力する.
</p>
<p>
入力ファイルには,変換表(最初の n + 1 行)に続き変換するデータ(n + 2 行目以降)が書いてある. 1 行目に変換表の行数 n,続く n 行の各行は,空白をはさんで 2 つの文字,さらに続けて, n + 2 行目に変換するデータの行数 m,続く m 行の各行は 1 文字である. m ≤ 10<sup>5</sup> とする.出力は,出力例のように途中に空白や改行は入れず 1 行とせよ.
</p>
<table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;">
<tr>
<th width="150" align="left">入力例</th>
</tr>
<tr><td>3</td></tr>
<tr><td>A a</td></tr>
<tr><td>0 5</td></tr>
<tr><td>5 4</td></tr>
<tr><td>10</td></tr>
<tr><td>A</td></tr>
<tr><td>B</td></tr>
<tr><td>C</td></tr>
<tr><td>0</td></tr>
<tr><td>1</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>a</td></tr>
<tr><td>b</td></tr>
<tr><td>A</td></tr>
<tr>
<td> </td>
</tr>
<tr>
<th width="150" align="left">出力例</th>
</tr>
<tr><td>aBC5144aba</td></tr>
</table>
<h3>入力</h3>
<p>
入力は複数のデータセットからなる.n が 0 のとき入力が終了する.データセットの数は 5 を超えない.
</p>
<h3>出力</h3>
<p>
データセットごとに、変換後の文字列を1行に出力する.
</p>
<H2>入力例</H2>
<pre>
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
</pre>
<H2>出力例</H2>
<pre>
aBC5144aba
aBC5144aba
</pre>
<p>
各データセットの出力(変換後の文字列)の後に改行を入れること.
</p>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p02419 | <H1>Finding a Word</H1><br>
<p>
Write a program which reads a word <var>W</var> and a text <var>T</var>, and prints the number of word <var>W</var> which appears in text <var>T</var>
</p>
<p>
<var>T</var> consists of string <var>T<sub>i</sub></var> separated by space characters and newlines. Count the number of <var>T<sub>i</sub></var> which equals to <var>W</var>. The word and text are case insensitive.
</p>
<H2>Constraints</H2>
<ul>
<li>The length of <var>W</var> ≤ 10</li>
<li><var>W</var> consists of lower case letters</li>
<li>The length of <var>T</var> in a line ≤ 1000</li>
</ul>
<H2>Input</H2>
<p>
In the first line, the word <var>W</var> is given. In the following lines, the text <var>T</var> is given separated by space characters and newlines.
</p>
<p>
"<span>END_OF_TEXT</span>" indicates the end of the text.
</p>
<H2>Output</H2>
<p>
Print the number of <var>W</var> in the text.
</p>
<H2>Sample Input</H2>
<pre>
computer
Nurtures computer scientists and highly-skilled computer engineers
who will create and exploit "knowledge" for the new era.
Provides an outstanding computer environment.
END_OF_TEXT
</pre>
<H2>Sample Output</H2>
<pre>
3
</pre>
|
p02376 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Maximum Flow</H1>
<p>
A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find the maximum flow from the $source$ to the $sink$.
</p>
<H2>Input</H2>
<p>
A flow network is given in the following format.
</p>
$|V|\;|E|$<br>
$u_0\;v_0\;c_0$<br>
$u_1\;v_1\;c_1$<br>
:<br>
$u_{|E|-1}\;v_{|E|-1}\;c_{|E|-1}$<br>
<br>
<p>
$|V|$, $|E|$ is the number of vertices and edges of the flow network respectively. The vertices in $G$ are named with the numbers 0, 1,..., $|V|-1$. The source is 0 and the sink is $|V|-1$.
</p>
<p>
$u_i$, $v_i$, $c_i$ represent $i$-th edge of the flow network.
A pair of $u_i$ and $v_i$ denotes that there is an edge from $u_i$ to $v_i$ and $c_i$ is the capacity of $i$-th edge.
</p>
<H2>Output</H2>
<p>
Print the maximum flow.
</p>
<H2>Constraints</H2>
<ul>
<li> $2 \leq |V| \leq 100$</li>
<li> $1 \leq |E| \leq 1000$</li>
<li> $0 \leq c_i \leq 10000$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
|
p03834 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>As a New Year's gift, Dolphin received a string <var>s</var> of length <var>19</var>.<br/>
The string <var>s</var> has the following format: <code>[five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]</code>.<br/>
Dolphin wants to convert the comma-separated string <var>s</var> into a space-separated string.<br/>
Write a program to perform the conversion for him. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>s</var> is <var>19</var>.</li>
<li>The sixth and fourteenth characters in <var>s</var> are <code>,</code>.</li>
<li>The other characters in <var>s</var> are lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the string after the conversion.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>happy,newyear,enjoy
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>happy newyear enjoy
</pre>
<p>Replace all the commas in <code>happy,newyear,enjoy</code> with spaces to obtain <code>happy newyear enjoy</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>haiku,atcoder,tasks
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>haiku atcoder tasks
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abcde,fghihgf,edcba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>abcde fghihgf edcba
</pre></section>
</div>
</span> |
p01809 |
<h2>幾何問題を解こう</h2>
<p>
A君は今日も幾何の問題を解いている。
幾何の問題を解く時は浮動小数点誤差に気をつけることが大事である。
</p>
<p>
浮動小数点誤差とは、2進法の有限小数で数を表す際におこる丸めによって起きる誤差である。
例えば、10進法での <var>0.1</var> は2進法では <var>0.00011001100110011</var> ... という無限小数になるが、
これを有限の桁で丸める際に誤差が発生してしまう。
</p>
<p>
正の整数 <var>p</var>, <var>q</var> が10進法で与えられる。
有理数 <var>p</var> / <var>q</var> を有限桁数の小数で表現することができるような <var>b</var> 進法(<var>b</var> は2以上の整数)を求めよ。
複数ある場合は最も小さいものを出力せよ。
</p>
<h3>Constraints</h3>
<ul>
<li><var>0 < p < q < 10^9</var></li>
</ul>
<h3>Input Format</h3>
<p>
入力は以下の形式で標準入力から与えられる。
</p>
<pre>
<var>p</var> <var>q</var>
</pre>
<h3>Output Format</h3>
<p>
答えを一行に出力せよ。
</p>
<h3>Sample Input 1</h3>
<pre>
1 2
</pre>
<h3>Sample Output 1</h3>
<pre>
2
</pre>
<p>
1/2 は 2 進法で 0.1 です
</p>
<h3>Sample Input 2</h3>
<pre>
21 30
</pre>
<h3>Sample Output 2</h3>
<pre>
10
</pre>
<p>
21/30 は 10 進法で 0.7 です
</p> |
p02726 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have an undirected graph <var>G</var> with <var>N</var> vertices numbered <var>1</var> to <var>N</var> and <var>N</var> edges as follows:</p>
<ul>
<li>For each <var>i=1,2,...,N-1</var>, there is an edge between Vertex <var>i</var> and Vertex <var>i+1</var>.</li>
<li>There is an edge between Vertex <var>X</var> and Vertex <var>Y</var>.</li>
</ul>
<p>For each <var>k=1,2,...,N-1</var>, solve the problem below:</p>
<ul>
<li>Find the number of pairs of integers <var>(i,j) (1 \leq i < j \leq N)</var> such that the shortest distance between Vertex <var>i</var> and Vertex <var>j</var> in <var>G</var> is <var>k</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>3 \leq N \leq 2 \times 10^3</var></li>
<li><var>1 \leq X,Y \leq N</var></li>
<li><var>X+1 < Y</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>For each <var>k=1, 2, ..., N-1</var> in this order, print a line containing the answer to the problem.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
4
1
0
</pre>
<p>The graph in this input is as follows:
<br/>
<br/>
<img alt="Figure" src="https://img.atcoder.jp/ghi/3ae0885a4aeda99694b9fde4efe39dc1.png">
<br/>
<br/>
There are five pairs <var>(i,j) (1 \leq i < j \leq N)</var> such that the shortest distance between Vertex <var>i</var> and Vertex <var>j</var> is <var>1</var>: <var>(1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5)</var>.
<br/>
There are four pairs <var>(i,j) (1 \leq i < j \leq N)</var> such that the shortest distance between Vertex <var>i</var> and Vertex <var>j</var> is <var>2</var>: <var>(1,3)\,,(1,4)\,,(2,5)\,,(3,5)</var>.
<br/>
There is one pair <var>(i,j) (1 \leq i < j \leq N)</var> such that the shortest distance between Vertex <var>i</var> and Vertex <var>j</var> is <var>3</var>: <var>(1,5)</var>.
<br/>
There are no pairs <var>(i,j) (1 \leq i < j \leq N)</var> such that the shortest distance between Vertex <var>i</var> and Vertex <var>j</var> is <var>4</var>.</img></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
0
</pre>
<p>The graph in this input is as follows:
<br/>
<br/>
<img alt="Figure" src="https://img.atcoder.jp/ghi/be2921b3b307fc993a390a59437e624e.png">
<br/>
<br/></img></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
8
4
2
0
0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 4 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>10
12
10
8
4
1
0
0
0
</pre></section>
</div>
</span> |
p03567 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke built an online judge to hold a programming contest.</p>
<p>When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string <var>S</var> as a contiguous substring.
(The judge can return any two-character substring of <var>S</var>.)</p>
<p>Determine whether the judge can return the string <code>AC</code> as the verdict to a program.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq |S| \leq 5</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 the judge can return the string <code>AC</code> as a verdict to a program, print <code>Yes</code>; if it cannot, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>BACD
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The string <code>AC</code> appears in <code>BACD</code> as a contiguous substring (the second and third characters).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ABCD
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>Although the string <code>ABCD</code> contains both <code>A</code> and <code>C</code> (the first and third characters), the string <code>AC</code> does not appear in <code>ABCD</code> as a contiguous substring.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>CABD
</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>ACACA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>XX
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>No
</pre></section>
</div>
</span> |
p03137 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will play a one-player game using a number line and <var>N</var> pieces.</p>
<p>First, we place each of these pieces at some integer coordinate.</p>
<p>Here, multiple pieces can be placed at the same coordinate.</p>
<p>Our objective is to visit all of the <var>M</var> coordinates <var>X_1, X_2, ..., X_M</var> with these pieces, by repeating the following move:</p>
<p><strong>Move</strong>: Choose a piece and let <var>x</var> be its coordinate. Put that piece at coordinate <var>x+1</var> or <var>x-1</var>.</p>
<p>Note that the coordinates where we initially place the pieces are already regarded as visited.</p>
<p>Find the minimum number of moves required to achieve the objective.</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 M \leq 10^5</var></li>
<li><var>-10^5 \leq X_i \leq 10^5</var></li>
<li><var>X_1, X_2, ..., X_M</var> are all different.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>X_1</var> <var>X_2</var> <var>...</var> <var>X_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the minimum number of moves required to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 5
10 12 1 2 14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>The objective can be achieved in five moves as follows, and this is the minimum number of moves required.</p>
<ul>
<li>Initially, put the two pieces at coordinates <var>1</var> and <var>10</var>.</li>
<li>Move the piece at coordinate <var>1</var> to <var>2</var>.</li>
<li>Move the piece at coordinate <var>10</var> to <var>11</var>.</li>
<li>Move the piece at coordinate <var>11</var> to <var>12</var>.</li>
<li>Move the piece at coordinate <var>12</var> to <var>13</var>.</li>
<li>Move the piece at coordinate <var>13</var> to <var>14</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 7
-10 -3 0 9 -100 2 17
</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>100 1
-100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03422 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Aoki are playing a stone-taking game. Initially, there are <var>N</var> piles of stones, and the <var>i</var>-th pile contains <var>A_i</var> stones and has an associated integer <var>K_i</var>.</p>
<p>Starting from Takahashi, Takahashi and Aoki take alternate turns to perform the following operation:</p>
<ul>
<li>Choose a pile. If the <var>i</var>-th pile is selected and there are <var>X</var> stones left in the pile, remove some number of stones between <var>1</var> and <var>floor(X/K_i)</var> (inclusive) from the pile.</li>
</ul>
<p>The player who first becomes unable to perform the operation loses the game. Assuming that both players play optimally, determine the winner of the game.
Here, <var>floor(x)</var> represents the largest integer not greater than <var>x</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 200</var></li>
<li><var>1 \leq A_i,K_i \leq 10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>K_1</var>
<var>:</var>
<var>A_N</var> <var>K_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Takahashi will win, print <code>Takahashi</code>; if Aoki will win, print <code>Aoki</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
5 2
3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Aoki
</pre>
<p>Initially, from the first pile at most <var>floor(5/2)=2</var> stones can be removed at a time, and from the second pile at most <var>floor(3/3)=1</var> stone can be removed at a time.</p>
<ul>
<li>If Takahashi first takes two stones from the first pile, from the first pile at most <var>floor(3/2)=1</var> stone can now be removed at a time, and from the second pile at most <var>floor(3/3)=1</var> stone can be removed at a time.</li>
<li>Then, if Aoki takes one stone from the second pile, from the first pile at most <var>floor(3/2)=1</var> stone can be removed at a time, and from the second pile no more stones can be removed (since <var>floor(2/3)=0</var>).</li>
<li>Then, if Takahashi takes one stone from the first pile, from the first pile at most <var>floor(2/2)=1</var> stone can now be removed at a time, and from the second pile no more stones can be removed.</li>
<li>Then, if Aoki takes one stone from the first pile, from the first pile at most <var>floor(1/2)=0</var> stones can now be removed at a time, and from the second pile no more stones can be removed.</li>
</ul>
<p>No more operation can be performed, thus Aoki wins. If Takahashi plays differently, Aoki can also win by play accordingly.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
3 2
4 3
5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Takahashi
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
28 3
16 4
19 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Aoki
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4
3141 59
26535 897
93 23
8462 64
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Takahashi
</pre></section>
</div>
</span> |
p03588 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A group of people played a game. All players had distinct scores, which are positive integers.</p>
<p>Takahashi knows <var>N</var> facts on the players' scores. The <var>i</var>-th fact is as follows: the <var>A_i</var>-th highest score among the players is <var>B_i</var>.</p>
<p>Find the maximum possible number of players in the game.</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(1\leq i\leq N)</var></li>
<li><var>0 \leq B_i \leq 10^9(1\leq i\leq N)</var></li>
<li>If <var>i ≠ j</var>, <var>A_i ≠ A_j</var>.</li>
<li>There exists a possible outcome of the game that are consistent with the facts.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>B_1</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the maximum possible number of players in the game.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4 7
2 9
6 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>The maximum possible number of players is achieved when, for example, the players have the following scores: <var>12,9,8,7,5,2,1,0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 10
3 6
5 2
4 4
2 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 1000000000
1000000000 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000001
</pre></section>
</div>
</span> |
p03072 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> mountains ranging from east to west, and an ocean to the west.</p>
<p>At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns.</p>
<p>The height of the <var>i</var>-th mountain from the west is <var>H_i</var>.</p>
<p>You can certainly see the ocean from the inn at the top of the westmost mountain.</p>
<p>For the inn at the top of the <var>i</var>-th mountain from the west <var>(i = 2, 3, ..., N)</var>, you can see the ocean if and only if <var>H_1 \leq H_i</var>, <var>H_2 \leq H_i</var>, <var>...</var>, and <var>H_{i-1} \leq H_i</var>.</p>
<p>From how many of these <var>N</var> inns can you see the ocean?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 20</var></li>
<li><var>1 \leq H_i \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of inns from which you can see the ocean.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
6 5 6 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>You can see the ocean from the first, third and fourth inns from the west.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
4 5 3 5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
9 5 6 8 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p02233 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Fibonacci Number</H1>
<p>
Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula:
</p>
\begin{equation*}
fib(n)= \left \{
\begin{array}{ll}
1 & (n = 0) \\
1 & (n = 1) \\
fib(n - 1) + fib(n - 2) & \\
\end{array}
\right.
\end{equation*}
<H2>Input</H2>
<p>
An integer $n$ is given.
</p>
<H2>output</H2>
<p>
Print the $n$-th fibonacci number in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>$0 \leq n \leq 44$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre> |
p02399 |
<H1>A/B Problem</H1>
<p>
Write a program which reads two integers <var>a</var> and <var>b</var>, and calculates the following values:
</p>
<ul>
<li><var>a</var> ÷ <var>b</var>: <var>d</var> (in integer)</li>
<li>remainder of <var>a</var> ÷ <var>b</var>: <var>r</var> (in integer)</li>
<li><var>a</var> ÷ <var>b</var>: <var>f</var> (in real number)</li>
</ul>
<H2>Input</H2>
<p>
Two integers <var>a</var> and <var>b</var> are given in a line.
</p>
<H2>Output</H2>
<p>
Print <var>d</var>, <var>r</var> and <var>f</var> separated by a space in a line. For <var>f</var>, the output should not contain an absolute error greater than 10<sup>-5</sup>.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>a</var>, <var>b</var> ≤ 10<sup>9</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3 2
</pre>
<H2>Sample Output 1</H2>
<pre>
1 1 1.50000
</pre> |
p03971 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these.</p>
<p>Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests.</p>
<ul>
<li>A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than <var>A+B</var>.</li>
<li>An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than <var>A+B</var> and the student ranks <var>B</var>-th or above among all overseas students.</li>
</ul>
<p>A string <var>S</var> is assigned indicating attributes of all participants. If the <var>i</var>-th character of string <var>S</var> is <code>a</code>, this means the participant ranked <var>i</var>-th in the Qualification contests is a Japanese student; <code>b</code> means the participant ranked <var>i</var>-th is an overseas student; and <code>c</code> means the participant ranked <var>i</var>-th is neither of these.</p>
<p>Write a program that outputs for all the participants in descending rank either <code>Yes</code> if they passed the Qualification contests or <code>No</code> if they did not pass.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N,A,B≦100000</var></li>
<li><var>A+B≦N</var></li>
<li><var>S</var> is <var>N</var> characters long.</li>
<li><var>S</var> consists only of the letters <code>a</code>, <code>b</code> and <code>c</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Inputs are provided from Standard Input in the following form.</p>
<pre><var>N</var> <var>A</var> <var>B</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Output <var>N</var> lines. On the <var>i</var>-th line, output <code>Yes</code> if the <var>i</var>-th participant passed the Qualification contests or <code>No</code> if that participant did not pass.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 2 3
abccabaabb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
Yes
No
No
Yes
Yes
Yes
No
No
No
</pre>
<p>The first, second, fifth, sixth, and seventh participants pass the Qualification contests.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>12 5 2
cabbabaacaba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No
</pre>
<p>The sixth participant is third among overseas students and thus does not pass the Qualification contests.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 2 2
ccccc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
No
No
No
No
</pre></section>
</div>
</span> |
p02663 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In this problem, we use the <var>24</var>-hour clock.</p>
<p>Takahashi gets up exactly at the time <var>H_1</var> : <var>M_1</var> and goes to bed exactly at the time <var>H_2</var> : <var>M_2</var>. (See Sample Inputs below for clarity.)
He has decided to study for <var>K</var> consecutive minutes while he is up.
What is the length of the period in which he can start studying?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \le H_1, H_2 \le 23</var></li>
<li><var>0 \le M_1, M_2 \le 59</var></li>
<li>The time <var>H_1</var> : <var>M_1</var> comes before the time <var>H_2</var> : <var>M_2</var>.</li>
<li><var>K \ge 1</var></li>
<li>Takahashi is up for at least <var>K</var> minutes.</li>
<li>All values in input are integers (without leading zeros).</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_1</var> <var>M_1</var> <var>H_2</var> <var>M_2</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the length of the period in which he can start studying, as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 0 15 0 30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>270
</pre>
<p>Takahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.
It takes <var>30</var> minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is <var>270</var> minutes, so we should print <var>270</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 0 12 0 120
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Takahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes <var>120</var> minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print <var>0</var>.</p></section>
</div>
</span> |
p01366 |
<H1><font color="#000">Problem H:</font> Road Construction</H1>
<p>
King Mercer is the king of ACM kingdom. There are one capital and some cities in his kingdom.
Amazingly, there are no roads in the kingdom now. Recently, he planned to construct roads
between the capital and the cities, but it turned out that the construction cost of his plan is
much higher than expected.
</p>
<p>
In order to reduce the cost, he has decided to create a new construction plan by removing some
roads from the original plan. However, he believes that a new plan should satisfy the following
conditions:
</p>
<ul>
<li> For every pair of cities, there is a route (a set of roads) connecting them.</li>
<li> The minimum distance between the capital and each city does not change from his original
plan.</li>
</ul>
<p>
Many plans may meet the conditions above, but King Mercer wants to know the plan with
minimum cost. Your task is to write a program which reads his original plan and calculates the
cost of a new plan with the minimum cost.
</p>
<H2>Input</H2>
<p>
The input consists of several datasets. Each dataset is formatted as follows.
</p>
<p>
<i>N M</i><br>
<i>u</i><sub>1</sub> <i>v</i><sub>1</sub> <i>d</i><sub>1</sub> <i>c</i><sub>1</sub> <br>
.<br>
.<br>
.<br>
<i>u</i><sub><i>M</i></sub> <i>v</i><sub><i>M</i></sub> <i>d</i><sub><i>M</i></sub> <i>c</i><sub><i>M</i></sub> <br>
</p>
<p>
The first line of each dataset begins with two integers, <i>N</i> and <i>M</i> (1 ≤ <i>N</i> ≤ 10000, 0 ≤ <i>M</i> ≤
20000). <i>N</i> and <i>M</i> indicate the number of cities and the number of roads in the original plan,
respectively.
</p>
<p>
The following <i>M</i> lines describe the road information in the original plan. The <i>i</i>-th line contains
four integers, <i>u<sub>i</sub></i>, <i>v<sub>i</sub></i>, <i>d<sub>i</sub></i> and <i>c<sub>i</sub></i> (1 ≤ <i>u<sub>i</sub></i>, <i>v<sub>i</sub></i> ≤ <i>N</i> , <i>u<sub>i</sub></i> ≠ <i>v<sub>i</sub></i> , 1 ≤ <i>d<sub>i</sub></i> ≤ 1000, 1 ≤ <i>c<sub>i</sub></i> ≤ 1000). <i>u<sub>i</sub></i> , <i>v<sub>i</sub></i>, <i>d<sub>i</sub></i>
and <i>c<sub>i</sub></i> indicate that there is a road which connects <i>u<sub>i</sub></i>-th city and <i>v<sub>i</sub></i>-th city, whose length is <i>d<sub>i</sub></i> and whose cost needed for construction is <i>c<sub>i</sub></i>.
</p>
<p>
Each road is bidirectional. No two roads connect the same pair of cities. The 1-st city is the
capital in the kingdom.
</p>
<p>
The end of the input is indicated by a line containing two zeros separated by a space. You
should not process the line as a dataset.
</p>
<H2>Output</H2>
<p>
For each dataset, print the minimum cost of a plan which satisfies the conditions in a line.
</p>
<H2>Sample Input</H2>
<pre>
3 3
1 2 1 2
2 3 2 1
3 1 3 2
5 5
1 2 2 2
2 3 1 1
1 4 1 1
4 5 1 1
5 3 1 1
5 10
1 2 32 10
1 3 43 43
1 4 12 52
1 5 84 23
2 3 58 42
2 4 86 99
2 5 57 83
3 4 11 32
3 5 75 21
4 5 23 43
5 10
1 2 1 53
1 3 1 65
1 4 1 24
1 5 1 76
2 3 1 19
2 4 1 46
2 5 1 25
3 4 1 13
3 5 1 65
4 5 1 34
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
5
137
218
</pre>
|
p01736 |
<p>
You and your grandma are playing with graph automata, which is generalization of cell automata.
</p>
<p>
A graph automaton is expressed by a graph. The vertices of the graph have a time-dependent value, which can be either 0 or 1.
There is no more than one edge between any of two vertices, but self-loops might exist.
</p>
<p>
The values of vertices change regularly according to the following rule:
At time <var>t+1</var>, the value of vertex <var>i</var> will be 1 if and only if there are an odd number of edges from the vertex <var>i</var> to a vertex which has the value 1 at time <var>t</var>; otherwise 0.
</p>
<p>Now, your forgetful grandma forgot the past states of the automaton. Your task is to write a program which recovers the past states from the current time and states --- time machines are way too expensive.
There may be multiple candidates or no consistent states.
For such cases, you must print an appropriate error message.
</p>
<h3>Input</h3>
<p>The input is formatted as follows:
</p>
<pre>
<var>N</var>
<var>a_{11}</var> ... <var>a_{1N}</var>
:
:
<var>a_{N1}</var> ... <var>a_{NN}</var>
<var>v_1</var>
:
:
<var>v_N</var>
<var>T</var>
</pre>
<p>The first line contains one integer <var>N</var> (<var>2 \leq N \leq 300</var>).
<var>N</var> indicates the number of vertices.
The following <var>N</var> lines indicate the adjacent matrix of the graph.
When <var>(i,j)</var>-element is 1, there is an edge from vertex <var>i</var> to vertex <var>j</var>.
Otherwise, there is no edge.
The following <var>N</var> lines indicate the value vector of the vertices.
The <var>i</var>-th element indicates the value of vertex <var>i</var> at time 0.
Each element of the matrix and the vector can be 0 or 1.
The last line contains one integer <var>T</var> (<var>1 \leq T \leq 100,000,000</var>).
<var>-T</var> is the time your grandma wants to know the status at.
</p>
<h3>Output</h3>
<p>Print the value vector at time <var>-T</var> separated one white space in one line as follows:
</p><pre>
<var>v_1</var> ... <var>v_N</var></pre>
<p>Each value must be separated with one white space.
If there is no consistent value vectors, you should print <code>none</code> in one line.
Or if there are multiple candidates and the solution is not unique (i.e. the solution is not unique), you should print <code>ambiguous</code> in one line.
</p>
<h3>Sample Input 1</h3>
<pre>2
1 1
0 1
1
1
1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>0 1
</pre>
<h3>Sample Input 2</h3>
<pre>2
0 1
0 0
1
0
1
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>ambiguous
</pre>
<h3>Sample Input 3</h3>
<pre>2
0 1
0 0
1
0
2
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>none
</pre> |
p02819 | <span class="lang-en">
<p>Score: <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Find the minimum prime number greater than or equal to <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3>
<p>A prime number is an integer greater than <var>1</var> that cannot be evenly divided by any positive integer except <var>1</var> and itself.</p>
<p>For example, <var>2</var>, <var>3</var>, and <var>5</var> are prime numbers, while <var>4</var> and <var>6</var> are not.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var> 2 \le X \le 10^5 </var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the minimum prime number greater than or equal to <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>23
</pre>
<p>The minimum prime number greater than or equal to <var>20</var> is <var>23</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p><var>X</var> itself can be a prime number.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>99992
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100003
</pre></section>
</div>
</span> |
p00824 |
<H1><font color="#000">Problem F:</font> Gap</H1>
<p>
Let’s play a card game called Gap.
</p>
<p>
You have 28 cards labeled with two-digit numbers. The first digit (from 1 to 4) represents the
suit of the card, and the second digit (from 1 to 7) represents the value of the card.
</p>
<p>
First, you shuffle the cards and lay them face up on the table in four rows of seven cards, leaving
a space of one card at the extreme left of each row. The following shows an example of initial
layout.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gap1">
</center>
<p>
Next, you remove all cards of value 1, and put them in the open space at the left end of the
rows: “11” to the top row, “21” to the next, and so on.
</p>
<p>
Now you have 28 cards and four spaces, called gaps, in four rows and eight columns. You start
moving cards from this layout.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gap2">
</center>
<p>
At each move, you choose one of the four gaps and fill it with the successor of the left neighbor
of the gap. The successor of a card is the next card in the same suit, when it exists. For instance
the successor of “42” is “43”, and “27” has no successor.
</p>
<p>
In the above layout, you can move “43” to the gap at the right of “42”, or “36” to the gap at
the right of “35”. If you move “43”, a new gap is generated to the right of “16”. You cannot
move any card to the right of a card of value 7, nor to the right of a gap.
</p>
<p>
The goal of the game is, by choosing clever moves, to make four ascending sequences of the same
suit, as follows.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_gap3">
</center>
<p>
Your task is to find the minimum number of moves to reach the goal layout.
</p>
<H2>Input</H2>
<p>
The input starts with a line containing the number of initial layouts that follow.
</p>
<p>
Each layout consists of five lines - a blank line and four lines which represent initial layouts of
four rows. Each row has seven two-digit numbers which correspond to the cards.
</p>
<H2>Output</H2>
<p>
For each initial layout, produce a line with the minimum number of moves to reach the goal
layout. Note that this number should not include the initial four moves of the cards of value 1.
If there is no move sequence from the initial layout to the goal layout, produce “-1”.
</p>
<H2>Sample Input</H2>
<pre>
4
12 13 14 15 16 17 21
22 23 24 25 26 27 31
32 33 34 35 36 37 41
42 43 44 45 46 47 11
26 31 13 44 21 24 42
17 45 23 25 41 36 11
46 34 14 12 37 32 47
16 43 27 35 22 33 15
17 12 16 13 15 14 11
27 22 26 23 25 24 21
37 32 36 33 35 34 31
47 42 46 43 45 44 41
27 14 22 35 32 46 33
13 17 36 24 44 21 15
43 16 45 47 23 11 26
25 37 41 34 42 12 31
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
33
60
-1
</pre>
|
p00577 | <h1>マルバツスタンプ (Circle Cross Stamps)</h1>
<!-- 時間制限 : 2sec / メモリ制限 : 256MB-->
<h2>問題文</h2>
<p>
JOI 君はマルスタンプ,バツスタンプ,マルバツスタンプの3種類のスタンプをそれぞれ <var>0</var> 個以上持っている.これらはマルやバツのマークを紙に印字することができるスタンプである.
</p>
<p>
マルスタンプを使うとマルが <var>1</var> つ印字され,バツスタンプを使うとバツが <var>1</var> つ印字される.マルバツスタンプを使うとマルとバツが横一列に <var>1</var> つずつ印字され,スタンプの向きを変えることで,マルの右にバツが来るようにも,バツの右にマルが来るようにも印字できる.
</p>
<p>
JOI 君は,持っているスタンプをそれぞれちょうど <var>1</var> 回ずつ適当な順番で使い,紙に横一列にマルとバツを印字した.印字されたマルとバツの列は文字列 <var>S</var> で表される.<var>S</var> は <code>O</code> と <code>X</code> から構成された長さ <var>N</var> の文字列であり,<var>S_i = </var> <code>O</code> ならば JOI 君が印字したマークのうち左から <var>i</var> 番目のものがマルであることを表し,<var>S_i =</var> <code>X</code> ならばそれがバツであることを表す (<var>1 ≦ i ≦ N</var>).
</p>
<p>
あなたは,JOI 君が持っているスタンプの個数は分からないが,JOI 君が印字したマルとバツの列は知っている.印字されたマルとバツの列から,JOI 君が持っているマルバツスタンプの個数としてあり得るもののうち最大値を求めよ.
</p>
<h2> 制約</h2>
<ul>
<li><var>1 ≦ N ≦ 100000 (= 10^5)</var></li>
<li><var>S</var> は長さ <var>N</var> の文字列である.</li>
<li><var>S</var> の各文字は <code>O</code> か <code>X</code> である.</li>
</ul>
<h2> 入力・出力</h2>
<p>
<b>入力</b><br>
入力は以下の形式で標準入力から与えられる.<br>
<var>N</var><br>
<var>S</var>
</p>
<p>
<b>出力</b><br>
JOI 君が持っているマルバツスタンプの個数としてあり得るもののうち最大値を出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
5
OXXOX
</pre>
<h3>出力例 1</h3>
<pre>
2
</pre>
<p>
JOI 君が印字したマークは,左から順に,マル,バツ,バツ,マル,バツである.JOI 君がマルスタンプ,バツスタンプ,マルバツスタンプをそれぞれ <var>0, 1, 2</var> 個持っているとすると,以下の順番でスタンプを使えば,そのようにマークを印字することができる.
</p>
<ul>
<li><var>1</var> つ目のマルバツスタンプを使ってマルとバツをこの順に印字する.</li>
<li>この右に,<var>2</var> つ目のマルバツスタンプを使ってバツとマルをこの順に印字する.</li>
<li>最後に,この右に,バツスタンプを使ってバツを印字する.</li>
</ul>
<p>
マルバツスタンプを <var>3</var> 個以上持っているケースは考えられないので,<var>2</var> を出力する.
</p>
<h3>入力例 2</h3>
<pre>
14
OXOXOXOXXOXOXO
</pre>
<h3>出力例 2</h3>
<pre>
7
</pre>
<h3>入力例 3</h3>
<pre>
10
OOOOOOOOOO
</pre>
<h3>出力例 3</h3>
<pre>
0
</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>
|
p00127 |
<h1>ポケベル打ち</h1>
<p>
ある日、たろう君は、本文に「519345213244」という数字だけが書いてあるおかしなメールを受け取り
ました。そのメールは、10 歳年上の従姉からだったので電話して聞いてみると、「あ、急いでたから
ポケベル打ちで送っちゃった。便利よね。よろしくねっ!」といって切られてしまいました。いつも
せわしなく、少し強引なところのあるこの従姉をよく知るたろう君は、仕方なく自分で「ポケベル打
ち」について調べてみると、10 年ぐらい前に一世を風靡したかな入力の方法だということが分かりまし
た。
</p>
<p>
「ポケベル打ち」では、図 1 のような変換表に従い‘あ’は 11、‘お’は 15 という具合に、2 つの数字
で一つの文字を入力していきます。例えば「なると」という文字列を入力するには「519345」と打ちま
す。従って、どの文字も 2 つの数字で入力することができるのです。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pocketPager1">
<p>図1</i>
</center>
<p>
携帯電話がまだ広く普及していないころ、高校生はこの方法で公衆電話から友達のポケベルにメッセー
ジを送信していたのだそうです。猛烈なスピードでポケベル打ちができる女子高生もいたとか。最近、
仕事も忙しくなってきた従姉は、メールを無意識のうちにポケベル打ちでタイプするようになってしま
いました。
</p>
<p>
そこで、毎回解読に苦労しているたろう君を助けるために、ポケベル打ちによるメッセージを文字列
に変換し出力するプログラムを作成してください。ただし、変換には図2の変換表を使い、英
小文字及び、「.」、「?」、「!」、空白のみを対象とします。変換出来ない文字を含むメッセージに対しては NA と出力してください。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pocketPager2">
<p>図2</i>
</center>
<H2>Input</H2>
<p>
複数のメッセージが与えられます。各行に1つのメッセージ (200 文字以内) が与えられます。メッセージの総数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
各メッセージに対して、変換後のメッセージまたは NA を1行に出力してください。
</p>
<H2>Sample Input</H2>
<pre>
341143514535
314
143565553551655311343411652235654535651124615163
551544654451431564
4
3411
6363636363
153414
</pre>
<H2>Output for the Sample Input</H2>
<pre>
naruto
NA
do you wanna go to aizu?
yes sure!
NA
na
?????
end
</pre>
|
p00432 |
<H1></H1>
<p>
平面に長方形のシートが何枚か置かれている. これらのシートで覆われている部分の面積や周長を求めるプログラムを作成せよ.
</p>
<p>
ただし, 平面を座標平面とみなしたとき, シートの配置は次の条件 (1), (2) を満たすものとする.
</p>
<p>
(1) 各シートの長方形の 4 頂点の <i>x</i>, <i>y</i> 座標は全て 0 以上 10000 以下の整数であり, 長方形の各辺は <i>x</i> 軸, または <i>y</i> 軸に平行である.
</p>
<p>
(2) シートの枚数は高々 10000 枚以下である.
</p>
<!--
<p>
入力ファイルのファイル名は “input.txt” である.“input.txt” の 1 行目に長方形の個数 <i>n</i> と問題の種類を表す整数 <i>r</i> が空白で区切って書かれている. 2 行目以降の各行には, 各シートの左下頂点座標 (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) と右上頂点座標 (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) の座標値が <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>2</sub> の順で空白で区切って書いてある.
</p>
<p>
出力ファイルのファイル名は “output.txt” である.“output.txt” には <i>r</i> = 1 のとき 1 行目に面積を, <i>r</i> = 2 のとき 1 行目に面積, 2 行目に周囲の長さを出力する. いずれの場合も最後に改行を入れること.
</p>
-->
<p>
入力データ の 1 行目に長方形の個数 <i>n</i> と問題の種類を表す整数 <i>r</i> が空白で区切って書かれている. 2 行目以降の各行には, 各シートの左下頂点座標 (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) と右上頂点座標 (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) の座標値が <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>2</sub> の順で空白で区切って書いてある.
</p>
<p>
出力には <i>r</i> = 1 のとき 1 行目に面積を, <i>r</i> = 2 のとき 1 行目に面積, 2 行目に周囲の長さを出力する. いずれの場合も最後に改行を入れること.
</p>
<p>
また, テストデータの 40% では長方形の頂点の座標が 0 以上 100 以下で, そのうちの 1/2 では面積だけを求める問題である. さらに, 全体の 1/2 は面積だけを求める問題である.
</p>
<table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;">
<tr>
<th width="150" align="left">入力例1</th>
<th width="150" align="left">入力例2</th>
<th width="150" align="left">入力例3</th>
<th width="150" align="left">入力例4</th>
</tr>
<tr><td></td><td></td></tr>
<tr><td>5 1 </td><td>5 2 </td><td>2 2 </td><td>3 2 </td></tr>
<tr><td>0 0 3 2 </td><td>0 0 3 2 </td><td>0 0 8 9 </td><td>2 2 8 8 </td></tr>
<tr><td>1 1 2 5 </td><td>1 1 2 5 </td><td>0 0 9 8 </td><td>3 0 4 9 </td></tr>
<tr><td>0 4 6 5 </td><td>0 4 6 5 </td><td> </td><td>5 0 7 9 </td></tr>
<tr><td>3 3 5 6 </td><td>3 3 5 6 </td><td> </td><td> </td></tr>
<tr><td>5 0 7 6 </td><td>5 0 7 6 </td><td> </td><td> </td></tr>
<tr>
<td> </td>
</tr>
<tr>
<th width="150" align="left">出力例1</th>
<th width="150" align="left">出力例2</th>
<th width="150" align="left">出力例3</th>
<th width="150" align="left">出力例4</th>
</tr>
<tr><td>29 </td><td>29 </td><td>80 </td><td>45 </td></tr>
<tr><td> </td><td>38 </td><td>36 </td><td>36 </td></tr>
</table>
<h3>入力</h3>
<p>
入力は複数のデータセットからなる.<i>n</i>, <i>r</i> がともに 0 のとき入力が終了する.データセットの数は 10 を超えない.
</p>
<h3>出力</h3>
<p>
データセットごとに, <i>r</i> = 1 のとき 1 行目に面積を, <i>r</i> = 2 のとき 1 行目に面積, 2 行目に周囲の長さを出力する.
</p>
<H2>入力例</H2>
<pre>
5 1
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
5 2
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
2 2
0 0 8 9
0 0 9 8
3 2
2 2 8 8
3 0 4 9
5 0 7 9
0 0
</pre>
<H2>出力例</H2>
<pre>
29
29
38
80
36
45
36
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00062 |
<H1>一番下の行の数字は?</H1>
<p>
次のような数字のパターンを作ることを考えます。
</p>
<pre>
4 8 2 3 1 0 8 3 7 6
2 0 5 4 1 8 1 0 3
2 5 9 5 9 9 1 3
7 4 4 4 8 0 4
1 8 8 2 8 4
9 6 0 0 2
5 6 0 2
1 6 2
7 8
5
</pre>
<p>
このパターンは以下の規則に従っています。
</p>
<pre>
A B
C
</pre>
<p>
という数字の並びにおいて、C は A + B の 1 の位の数字である。たとえば、
</p>
<pre>
9 5
4
</pre>
<p>
では、9 + 5 = 14 の 1 の位の数字、すなわち 4 が 9 と 5 の斜め下に並べられます。また、
</p>
<pre>
2 3
5
</pre>
<p>
では、2 + 3 = 5 の 1 の位の数字、すなわち 5 が 2 と 3 の斜め下に並べられます。
</p>
<p>
一番上の行の 10 個の整数を読み込んで、一番下の行の 1 個の数を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
入力は複数のデータセットからなります。各データセットとして、一番上の行の 10 個の数字が文字列として1行に与えられます。
</p>
<p>
データセットの数は 20 を超えません。
</p>
<H2>Output</H2>
<p>データセットごとに、一番下の行の数字を1行に出力します。
<H2>Sample Input</H2>
<pre>
4823108376
1234567890
0123456789
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
6
4
</pre>
|
p00598 |
<H1><font color="#000000">Problem D:</font> Operations with Finite Sets</H1>
<p>
Let <i>A, B, C, D, E</i> be sets of integers and let <i>U</i> is a universal set that includes all sets under consideration. All elements in any set are different (no repetitions).
</p>
<p>
u - <b>union</b> of two sets, <i>AuB</i> = {<i>x ∈ U</i> : <i>x ∈ A</i> or <i>x ∈ B</i>} is the set of all elements which belong to <i>A</i> or <i>B</i>.
</p>
<p>
i - <b>intersection</b> of two sets, <i>AiB</i> = {<i>x ∈ U</i> : <i>x ∈ A</i> and <i>x ∈ B</i>} is the set of all elements which belong to both <i>A</i> and <i>B</i>.
</p>
<p>
d - <b>difference</b> of two sets, <i>AdB</i> = {<i>x ∈ U</i> : <i>x ∈ A</i>, <i>x ∉ B</i>} is the set of those elements of <i>A</i> which do not belong to <i>B</i>.
</p>
<p>
s - <b>symmetric difference</b> of two sets, <i>AsB</i> = (<i>AdB</i>)<i>u</i>(<i>BdA</i>) consists of those elements which belong to <i>A</i> or <i>B</i> but not to both.
</p>
<p>
c - <b>complement</b> of a set, <i>cA</i> = {<i>x ∈ U</i> : <i>x ∉ A</i>}, is set of elements which belong to <i>U</i> but do not belong to <i>A</i>. Unary operator <i>c</i> has higest precedence.
</p>
<p>
The universal set <i>U</i> is defined as a union of all sets specified in data.
</p>
<p>
Your task is to determine the result of an expression, which includes sets, set operations and parenthesis (any number of parenthesis and any correct enclosure of parenthesis may take place).
</p>
<H2>Input</H2>
<p>
Input consists of several pairs of lines difining sets and one pair of lines defining an expression. Each pair of lines for set definition includes the following.
</p>
<p>
<i>Line 1</i>: Set name (A, B, C, D, E), number of elements in a set.
</p>
<p>
<i>Line 2</i>: Set elements separated by blanks.
</p>
<p>
Pair of lines for expression definition:
</p>
<p>
<i>Line 1</i>: R 0
</p>
<p>
<i>Line 2</i>: Expression consisting of set names, operators and parenthesis (no blanks).
</p>
<p>
Number of sets can vary from 1 to 5. Set names can be specified in any order. Each set consists of 1-100 elements. Pair of lines for expression definition signals the end of data set. Input file includes several data sets. The number of datasets is less than 20.
</p>
<H2>Output</H2>
<p>
For each data set, the output should contain one line with resulting set elements sorted in ascending order separated by blanks. If the result contains no set elements then the line should contain the text NULL.
</p>
<H2>Sample Input</H2>
<pre>
A 3
1 3 -1
B 4
3 1 5 7
D 1
5
R 0
cAiBdD
C 3
1 2 3
A 4
2 10 8 3
B 3
2 4 8
R 0
(As(AiB))uC
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7
1 2 3 10
</pre> |
p01223 |
<h1><font color="#000">Problem A:</font>サイゾウ</h1>
<p>
ある国で「サイゾウ」というテレビ番組が流行している.
この番組は参加者がフィールドアスレチックに挑戦し,
見事攻略すれば賞金をもらえるというものである.
</p>
<p>
フィールドアスレチックは高さが異なるブロックを一列に並べて作られていて,
攻略のためにはいかにして段差を登り降りするかが重要になる
(図1).
この番組に参加することになったあなたの友人は,
フィールドアスレチックの構造が与えられたときに,
登らなければならない最大の段差と降りなければならない最大の段差を
計算するプログラムを書いてほしいと,
凄腕プログラマーであるあなたに依頼してきた.
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_athletic"
alt="アスレチックの構造の例(入力例の最初のデータセット).">
</td>
</tr>
<tr>
<td>図1: アスレチックの構造の例(入力例の最初のデータセット).</td>
</tr>
</table>
</center>
<h2>Input</h2>
<p>
入力の1行目にはデータセットの個数 <var>t</var>
(0 < <var>t</var> ≤ 100) が与えられる.
この行に引き続き <var>t</var> 個のデータセットが与えられる.
</p>
<p>
データセットの1行目はフィールドアスレチックを構成している
ブロックの個数 <var>n</var>
(2 ≤ <var>n</var> ≤ 100) である.
2行目にはスタートからゴールまでのブロックの高さを示す整数が
順に <var>n</var> 個与えられる.
1番目がスタート, <var>n</var>番目がゴールに対応している.
これらの整数は1つの空白文字で区切られている.
各ブロックの高さ <var>h</var> は 0 < <var>h</var> ≤ 1000 を満たす.
</p>
<h2>Output</h2>
<p>
各データセットに対し,
登らなければならない最大の段差の大きさと,
降りなければならない最大の段差の大きさを,
1つの空白文字で区切って1行に出力せよ.
なお,登る段差がない,または降りる段差がない場合は,
対応する最大の段差の大きさは 0 とすること.
</p>
<h2>Sample Input</h2>
<pre>
5
5
10 70 30 50 90
2
20 100
2
100 30
3
50 50 50
7
123 45 678 901 234 567 890
</pre>
<h2>Output for the Sample Input</h2>
<pre>
60 40
80 0
0 70
0 0
633 667
</pre>
|
p04021 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke got an integer sequence of length <var>N</var> from his mother, as a birthday present. The <var>i</var>-th <var>(1 ≦ i ≦ N)</var> element of the sequence is <var>a_i</var>. The elements are pairwise distinct.
He is sorting this sequence in increasing order.
With supernatural power, he can perform the following two operations on the sequence in any order:</p>
<ul>
<li>Operation <var>1</var>: choose <var>2</var> consecutive elements, then reverse the order of those elements.</li>
<li>Operation <var>2</var>: choose <var>3</var> consecutive elements, then reverse the order of those elements.</li>
</ul>
<p>Snuke likes Operation <var>2</var>, but not Operation <var>1</var>. Find the minimum number of Operation <var>1</var> that he has to perform in order to sort the sequence in increasing order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≦ N ≦ 10^5</var></li>
<li><var>0 ≦ A_i ≦ 10^9</var></li>
<li>If <var>i ≠ j</var>, then <var>A_i ≠ A_j</var>.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var>
:
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of times Operation <var>1</var> that Snuke has to perform.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2
4
3
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The given sequence can be sorted as follows:</p>
<ul>
<li>First, reverse the order of the last three elements. The sequence is now: <var>2,1,3,4</var>.</li>
<li>Then, reverse the order of the first two elements. The sequence is now: <var>1,2,3,4</var>.</li>
</ul>
<p>In this sequence of operations, Operation <var>1</var> is performed once. It is not possible to sort the sequence with less number of Operation <var>1</var>, thus the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
10
8
5
3
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre></section>
</div>
</span> |
p01673 |
<h2>G - Revenge of Minimum Cost Flow</h2>
<h3>Problem Statement</h3>
<p>
Flora is a freelance carrier pigeon.
Since she is an excellent pigeon, there are too much task requests to her.
It is impossible to do all tasks, so she decided to outsource some tasks to Industrial Carrier Pigeon Company.
</p>
<p>
There are <var>N</var> cities numbered from 0 to <var>N-1</var>.
The task she wants to outsource is carrying <var>f</var> freight units from city <var>s</var> to city <var>t</var>.
There are <var>M</var> pigeons in the company.
The <var>i</var>-th pigeon carries freight from city <var>s_i</var> to <var>t_i</var>, and carrying cost of <var>u</var> units is <var>u a_i</var> if <var>u</var> is smaller than or equals to <var>d_i</var>, otherwise <var>d_i a_i + (u-d_i)b_i</var>.
Note that <var>i</var>-th pigeon cannot carry from city <var>t_i</var> to <var>s_i</var>.
Each pigeon can carry any amount of freights.
If the pigeon carried freight multiple times, the cost is calculated from total amount of freight units he/she carried.
</p>
<p>
Flora wants to minimize the total costs.
Please calculate minimum cost for her.
</p>
<h3>Input</h3>
<p>
The test case starts with a line containing five integers <var>N</var> (<var>2 \leq N \leq 100</var>), <var>M</var> (<var>1 \leq M \leq 1{,}000</var>), <var>s</var> (<var>0 \leq s \leq N-1</var>), <var>t</var> (<var>0 \leq t \leq N-1</var>) and <var>f</var> (<var>1 \leq f \leq 200</var>).
You may assume <var>s \neq t</var>.
Each of the next <var>M</var> lines contains five integers <var>s_i</var> (<var>0 \leq s_i \leq N-1</var>), <var>t_i</var> (<var>0 \leq t_i \leq N-1</var>), <var>a_i</var> (<var>0 \leq a_i \leq 1{,}000</var>), <var>b_i</var> (<var>0 \leq b_i \leq 1{,}000</var>) and <var>d_i</var> (<var>1 \leq d_i \leq 200</var>).
Each denotes <var>i</var>-th pigeon's information.
You may assume at most one pair of <var>a_i</var> and <var>b_i</var> satisfies <var>a_i < b_i</var>, all others satisfies <var>a_i > b_i</var>.
</p>
<h3>Output</h3>
<p>
Print the minimum cost to carry <var>f</var> freight units from city <var>s</var> to city <var>t</var> in a line.
If it is impossible to carry, print "Impossible" (quotes for clarity).
</p>
<h3>Sample Input 1</h3>
<pre>
2 2 0 1 5
0 1 3 0 3
0 1 2 1 6
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
9
</pre>
<h3>Sample Input 2</h3>
<pre>
4 4 0 3 5
0 1 3 0 3
1 3 3 0 3
0 2 2 1 6
2 3 2 1 6
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
18
</pre>
<h3>Sample Input 3</h3>
<pre>
2 1 0 1 1
1 0 1 0 1
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
Impossible
</pre>
<h3>Sample Input 4</h3>
<pre>
2 2 0 1 2
0 1 5 1 2
0 1 6 3 1
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
9
</pre>
<h3>Sample Input 5</h3>
<pre>
3 3 0 2 4
0 2 3 4 2
0 1 4 1 3
1 2 3 1 1
</pre>
<h3>Output for the Sample Input 5</h3>
<pre>
14
</pre> |
p00961 |
<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>
<h2>Problem E
Black or White
</h2>
<p>
Here lies a row of a number of bricks each painted either black or white. With a single stroke of your brush, you can overpaint a part of the row of bricks at once with either black or white paint. Using white paint, all the black bricks in the painted part become white while originally white bricks remain white; with black paint, white bricks become black and black ones remain black. The number of bricks painted in one stroke, however, is limited because your brush cannot hold too much paint at a time. For each brush stroke, you can paint any part of the row with any number of bricks up to the limit.
</p>
<p>
In the first case of the sample input, the initial colors of four bricks are black, white, white, and black. You can repaint them to white, black, black, and white with two strokes: the first stroke paints all four bricks white and the second stroke paints two bricks in the middle black.
</p>
<p>
Your task is to calculate the minimum number of brush strokes needed to change the brick colors as specified. Never mind the cost of the paints.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$n$ $k$
$s$
$t$
</pre>
<p>
The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 500 000$). $n$ is the number of bricks in the row and $k$ is the maximum number of bricks painted in a single stroke. The second line contains a string $s$ of $n$ characters, which indicates the initial colors of the bricks. The third line contains another string $t$ of $n$ characters, which indicates the desired colors of the bricks. All the characters in both s and t are either <span>B</span> or <span>W</span> meaning black and white, respectively.
</p>
<h3>Output</h3>
<p>
Output the minimum number of brush strokes required to repaint the bricks into the desired colors.
</p>
<h3>Sample Input 1</h3>
<pre>
4 4
BWWB
WBBW
</pre>
<h3>Sample Output 1</h3>
<pre>
2
</pre>
<h3>Sample Input 2</h3>
<pre>
4 3
BWWB
WBBW
</pre>
<h3>Sample Output 2</h3>
<pre>
3
</pre>
<h3>Sample Input 3</h3>
<pre>
4 3
BWWW
BWWW
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
7 1
BBWBWBW
WBBWWBB
</pre>
<h3>Sample Output 4</h3>
<pre>
4
</pre> |
p01389 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">問題 B </font> 蝉</h1>
<h2>問題文</h2>
<p>
N 君は毎日学校に通っているが,その道のりはとても長い.さらに今は暑い夏である.道中,蝉が五月蝿い.出来れば避けたいものである.ところで情報化が発達した現代社会においては,家に居ながらにしてどこに何匹の蝉がいるか調べることが出来る.その情報を使い,途中で出会う蝉の数が最も少ない道で学校に行くことに決めた.
</p>
<p>
家と学校が描かれた地図は長方形状になっており,<var>H × W</var> 個のブロックに分割される.一番左上のブロックに N 君の家があり,一番右下に学校がある.彼は学校へまっすぐ登校したいので家の方に逆戻りすることはない (地図において,右か下のブロックにしか移動しない).各ブロックにおいて,そこにいる蝉の数だけ不快になる.どのような道を選べば,不快な度合いを最小化,つまり出会う蝉の数を最小に出来るだろうか.
</p>
<h2>入力形式</h2>
<p>
最初の行には二つの数字 <var>H</var>,<var>W</var> がこの順で与えられる.<var>H</var> は地図の縦方向のブロック数を示し,<var>W</var> は横方向のブロック数を示す.<br>
次の <var>H</var> 行に蝉の情報が書かれた地図が与えられる.各行は <var>W</var> 文字からなり,各文字は対応するブロック中の蝉の数を示す.ブロック中の蝉の数は <var>9</var> を超えることはない.
</p>
<h2>出力形式</h2>
<p>出会う蝉の数の最小値を <var>1</var> 行で与えよ.</p>
<h2>制約</h2>
<ul>
<li> <var>2 ≤ H ≤ 50</var> </li>
<li> <var>2 ≤ W ≤ 50</var> </li>
<li>N 君の家と学校には蝉はいない.</li>
<li>ブロック中の蝉の数は <var>0</var> 以上 <var>9</var> 以下である.</li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
3 3
023
321
120
</pre>
<h3>出力例 1</h3>
<pre>5</pre>
<h3>入力例 2</h3>
<pre>
5 6
000000
923450
000000
054329
000000
</pre>
<h3>出力例 2</h3>
<pre>4</pre>
<p>N 君は右か下のブロックにしか移動しないことに注意せよ.</p>
<h3>入力例 3</h3>
<pre>
6 9
089712364
781263576
937526351
736589623
217835653
837479570
</pre>
<h3>出力例 3</h3>
<pre>46</pre>
|
p03160 | <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> stones, numbered <var>1, 2, \ldots, N</var>.
For each <var>i</var> (<var>1 \leq i \leq N</var>), the height of Stone <var>i</var> is <var>h_i</var>.</p>
<p>There is a frog who is initially on Stone <var>1</var>.
He will repeat the following action some number of times to reach Stone <var>N</var>:</p>
<ul>
<li>If the frog is currently on Stone <var>i</var>, jump to Stone <var>i + 1</var> or Stone <var>i + 2</var>. Here, a cost of <var>|h_i - h_j|</var> is incurred, where <var>j</var> is the stone to land on.</li>
</ul>
<p>Find the minimum possible total cost incurred before the frog reaches Stone <var>N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq h_i \leq 10^4</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>h_1</var> <var>h_2</var> <var>\ldots</var> <var>h_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible total cost incurred.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
10 30 40 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>30
</pre>
<p>If we follow the path <var>1</var> → <var>2</var> → <var>4</var>, the total cost incurred would be <var>|10 - 30| + |30 - 20| = 30</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
10 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If we follow the path <var>1</var> → <var>2</var>, the total cost incurred would be <var>|10 - 10| = 0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
30 10 60 10 60 50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>40
</pre>
<p>If we follow the path <var>1</var> → <var>3</var> → <var>5</var> → <var>6</var>, the total cost incurred would be <var>|30 - 60| + |60 - 60| + |60 - 50| = 40</var>.</p></section>
</div>
</span> |
p03530 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some place in the Arctic Ocean, there are <var>H</var> rows and <var>W</var> columns of ice pieces floating on the sea.
We regard this area as a grid, and denote the square at the <var>i</var>-th row and <var>j</var>-th column as Square <var>(i,j)</var>.
The ice piece floating in each square is either thin ice or an iceberg, and a penguin lives in one of the squares that contain thin ice.
There are no ice pieces floating outside the grid.</p>
<p>The ice piece at Square <var>(i,j)</var> is represented by the character <var>S_{i,j}</var>.
<var>S_{i,j}</var> is <code>+</code>, <code>#</code> or <code>P</code>, each of which means the following:</p>
<ul>
<li><code>+</code>: Occupied by thin ice.</li>
<li><code>#</code>: Occupied by an iceberg.</li>
<li><code>P</code>: Occupied by thin ice. The penguin lives here.</li>
</ul>
<p>When summer comes, unstable thin ice that is not held between some pieces of ice collapses one after another.
Formally, thin ice at Square <var>(i,j)</var> will collapse when it does NOT satisfy either of the following conditions:</p>
<ul>
<li>Both Square <var>(i-1,j)</var> and Square <var>(i+1,j)</var> are occupied by an iceberg or uncollapsed thin ice.</li>
<li>Both Square <var>(i,j-1)</var> and Square <var>(i,j+1)</var> are occupied by an iceberg or uncollapsed thin ice.</li>
</ul>
<p>When a collapse happens, it may cause another. Note that icebergs do not collapse.</p>
<p>Now, a mischievous tourist comes here. He will do a little work so that, when summer comes, the thin ice inhabited by the penguin will collapse.
He can smash an iceberg with a hammer to turn it to thin ice.
At least how many icebergs does he need to smash?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 40</var></li>
<li><var>S_{i,j}</var> is <code>+</code>, <code>#</code> or <code>P</code>.</li>
<li><var>S</var> contains exactly one <code>P</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>H</var> <var>W</var>
<var>S_{1,1}</var><var>S_{1,2}</var><var>...</var><var>S_{1,W}</var>
<var>S_{2,1}</var><var>S_{2,2}</var><var>...</var><var>S_{2,W}</var>
<var>:</var>
<var>S_{H,1}</var><var>S_{H,2}</var><var>...</var><var>S_{H,W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of icebergs that needs to be changed to thin ice in order to cause the collapse of the thin ice inhabited by the penguin when summer comes.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
+#+
#P#
+#+
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, when the right and bottom icebergs are changed to thin ice, collapses happen as follows:</p>
<pre>+#+ .#. .#. .#.
#P+ -> #P+ -> #P. -> #..
+++ .+. ... ...
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 6
#+++++
+++#++
#+++++
+++P+#
+##+++
++++#+
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>40 40
#++#+++++#+#+#+##+++++++##+#+++#++##++##
+##++++++++++#+###+##++++#+++++++++#++##
+++#+++++#++#++####+++#+#+###+++##+++#++
+++#+######++##+#+##+#+++#+++++++++#++#+
+++##+#+#++#+++#++++##+++++++++#++#+#+#+
#++#+++#+#++++##+#+#+++##+#+##+#++++##++
++#+##+++#++####+#++##++#+++#+#+#++++#++
+#+###++++++##++++++#++##+#####++#++##++
##+##+#+++#+#+##++#+###+######++++#+###+
+++#+++##+#####+#+#++++#+#+++++#+##++##+
#+++#+##+++++++#++#++++++++++###+#++#+#+
##+++##++#+++++#++++#++#+##++#+#+#++##+#
##+++#+###+++++##++#+#+++####+#+++++#+++
+++#++#++#+++++++++#++###++++++++###+##+
++#+++#++++++#####++##++#+++#+++++#++++#
++#++#+##++++#####+###+++####+#+#+######
++++++##+++++##+++++#++###++#++##+++++++
+#++++##++++++#++++#+#++++#++++##+++##+#
+++++++#+#++##+##+#+++++++###+###++##+++
++++++#++###+#+#+++##+#++++++#++#+#++#+#
##+##++++++#+++++#++#+#++##+++#+#+++##+#
#+++#+#+##+#+##++#P#++#++++++##++#+#++##
#+++#++##+##+#++++#++#++##++++++#+#+#+++
++++####+#++#####+++#+###+#++###++++#++#
#+#++####++##++#+#+#+##+#+#+##++++##++#+
+###+###+#+##+++#++++++#+#++++###+#+++++
+++#+++++#+++#+++++##++++++++###++#+#+++
+#+#++#+#++++++###+#++##+#+##+##+#+#####
#++++++++#+#+###+######++#++#+++++++++++
##+++##+#+#++#++#++#++++++#++##+#+#++###
+#+#+#+++++++#+++++++######+##++#++##+##
++#+++#+###+#++###+++#+++#+#++++#+###+++
#+#+###++#+#####+++++#+####++#++#+###+++
+#+##+#++#++##+++++++######++#++++++++++
+####+#+#+++++##+#+#++#+#++#+++##++++#+#
#++##++#+#+++++##+#++++####+++++###+#+#+
##+#++#++#+##+#+#++##++###+###+#+++++##+
##++###+###+#+#++#++#########+++###+#+##
+++#+++#++++++++++#+#+++#++#++###+####+#
++##+###+++++++##+++++#++#++++++++++++++
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>151
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 1
P
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre></section>
</div>
</span> |
p03863 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a string <var>s</var> of length <var>3</var> or greater.
No two neighboring characters in <var>s</var> are equal.</p>
<p>Takahashi and Aoki will play a game against each other.
The two players alternately performs the following operation, Takahashi going first:</p>
<ul>
<li>Remove one of the characters in <var>s</var>, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in <var>s</var>.</li>
</ul>
<p>The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 ≤ |s| ≤ 10^5</var></li>
<li><var>s</var> consists of lowercase English letters.</li>
<li>No two neighboring characters in <var>s</var> are equal.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Takahashi will win, print <code>First</code>. If Aoki will win, print <code>Second</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Second
</pre>
<p>Takahashi, who goes first, cannot perform the operation, since removal of the <code>b</code>, which is the only character not at either ends of <var>s</var>, would result in <var>s</var> becoming <code>aa</code>, with two <code>a</code>s neighboring.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>First
</pre>
<p>When Takahashi removes <code>b</code> from <var>s</var>, it becomes <code>ac</code>.
Then, Aoki cannot perform the operation, since there is no character in <var>s</var>, excluding both ends.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abcab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>First
</pre></section>
</div>
</span> |
p02771 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>A triple of numbers is said to be <em>poor</em> when two of those numbers are equal but the other number is different from those two numbers.</p>
<p>You will be given three integers <var>A</var>, <var>B</var>, and <var>C</var>. If this triple is poor, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>A</var>, <var>B</var>, and <var>C</var> are all integers between <var>1</var> and <var>9</var> (inclusive).</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>If the given triple is poor, 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 7 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><var>A</var> and <var>C</var> are equal, but <var>B</var> is different from those two numbers, so this triple is poor.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>A</var>, <var>B</var>, and <var>C</var> are all equal, so this triple is not poor.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 9 6
</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>3 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre></section>
</div>
</span> |
p02321 |
<H1>Huge Knapsack Problem</H1>
<br/>
<p>
You have <var>N</var> items that you want to put them into a knapsack. Item <var>i</var> has value <var>v<sub>i</sub></var> and weight <var>w<sub>i</sub></var>.
</p>
<p>
You want to find a subset of items to put such that:
</p>
<ul>
<li>The total value of the items is as large as possible.</li>
<li>The items have combined weight at most <var>W</var>, that is capacity of the knapsack.</li>
</ul>
<p>
Find the maximum total value of items in the knapsack.
</p>
<H2>Input</H2>
<pre>
<var>N</var> <var>W</var>
<var>v<sub>1</sub></var> <var>w<sub>1</sub></var>
<var>v<sub>2</sub></var> <var>w<sub>2</sub></var>
:
<var>v<sub>N</sub></var> <var>w<sub>N</sub></var>
</pre>
<p>
The first line consists of the integers <var>N</var> and <var>W</var>. In the following <var>N</var> lines, the value and weight of the <var>i</var>-th item are given.
</p>
<H2>Output</H2>
<p>
Print the maximum total values of the items in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>N</var> ≤ 40</li>
<li> 1 ≤ <var>v<sub>i</sub></var> ≤ 10<sup>15</sup></li>
<li> 1 ≤ <var>w<sub>i</sub></var> ≤ 10<sup>15</sup></li>
<li> 1 ≤ <var>W</var> ≤ 10<sup>15</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 5
4 2
5 2
2 1
8 3
</pre>
<H2>Sample Output 1</H2>
<pre>
13
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
2 20
5 9
4 10
</pre>
<H2>Sample Output 2</H2>
<pre>
9
</pre> |
p03926 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares in a row, numbered <var>1</var> through <var>N</var> from left to right.
Snuke and Rng are playing a board game using these squares, described below:</p>
<ol>
<li>First, Snuke writes an integer into each square.</li>
<li>Each of the two players possesses one piece. Snuke places his piece onto square <var>1</var>, and Rng places his onto square <var>2</var>.</li>
<li>The player whose piece is to the left of the opponent's, moves his piece. The destination must be a square to the right of the square where the piece is currently placed, and must not be a square where the opponent's piece is placed.</li>
<li>Repeat step <em>3.</em> When the pieces cannot be moved any more, the game ends.</li>
<li>The score of each player is calculated as the sum of the integers written in the squares where the player has placed his piece before the end of the game.</li>
</ol>
<p>Snuke has already written an integer <var>A_i</var> into square <var>i (1≦i≦N-1)</var>, but not into square <var>N</var> yet.
He has decided to calculate for each of <var>M</var> integers <var>X_1,X_2,...,X_M</var>, if he writes it into square <var>N</var> and the game is played, what the value "(Snuke's score) - (Rng's score)" will be.
Here, it is assumed that each player moves his piece to maximize the value "(the player's score) - (the opponent's score)".</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3≦N≦200,000</var></li>
<li><var>0≦A_i≦10^6</var></li>
<li>The sum of all <var>A_i</var> is at most <var>10^6</var>.</li>
<li><var>1≦M≦200,000</var></li>
<li><var>0≦X_i≦10^9</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li><var>700</var> points will be awarded for passing the test set satisfying <var>M=1</var>.</li>
<li>Additional <var>900</var> points will be awarded for passing the test set without additional constraints.</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-1}</var>
<var>M</var>
<var>X_1</var>
<var>X_2</var>
<var>:</var>
<var>X_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each of the <var>M</var> integers <var>X_1, ..., X_M</var>, print the value "(Snuke's score) - (Rng's score)" if it is written into square <var>N</var>, one per line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
2 7 1 8
1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>The game proceeds as follows, where <code>S</code> represents Snuke's piece, and <code>R</code> represents Rng's.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/0c38db3b7902579a8bc2d0798b8dda27.png"/></p>
<p>Both player scores <var>10</var>, thus "(Snuke's score) - (Rng's score)" is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
2 0 1 6 1 1 2 6
5
2016
1
1
2
6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2001
6
6
7
7
</pre></section>
</div>
</span> |
p00609 |
<H1><font color="#000000">Problem E:</font> Amazing Graze</H1>
<p>
In 2215 A.D., a war between two planets, ACM and ICPC, is being more and more intense.
</p>
<p>
ACM introduced new combat planes. These planes have a special system that is called Graze, and fighting power of a plane increases when it is close to energy bullets that ICPC combat planes shoot.
</p>
<p>
Both combat planes and energy bullets have a shape of a sphere with a radius of <i>R</i>. Precisely, fighting power of a plane is equivalent to the number of energy bullet where distance from the plane is less than or equals to 2<i>R</i>.
</p>
<p>
You, helper of captain of intelligence units, are asked to analyze a war situation. The information given to you is coordinates of <i>AN</i> combat planes and <i>BN</i> energy bullets. Additionally, you know following things:
</p>
<ul>
<li> All combat planes and energy bullet has same <i>z</i>-coordinates. In other word, <i>z</i>-coordinate can be ignored.</li>
<li> No two combat planes, no two energy bullets, and no pair of combat plane and energy bullet collide (i.e. have positive common volume) each other.</li>
</ul>
<p>
Your task is to write a program that outputs total fighting power of all combat planes.
</p>
<H2>Input</H2>
<p>
Input file consists of a number of data sets.
One data set is given in following format:
</p>
<pre>
<i>AN BN R</i>
<i>XA</i><sub>1</sub> <i>YA</i><sub>1</sub>
<i>XA</i><sub>2</sub> <i>YA</i><sub>2</sub>
:
<i>XA<sub>AN</sub></i> <i>YA<sub>AN</sub></i>
<i>XB</i><sub>1</sub> <i>YB</i><sub>1</sub>
<i>XB</i><sub>2</sub> <i>YB</i><sub>2</sub>
:
<i>XB<sub>BN</sub></i> <i>YB<sub>BN</sub></i>
</pre>
<p>
<i>AN</i>, <i>BN</i>, <i>R</i> are integers that describe the number of combat planes, energy bullets, and their radius respectively.
</p>
<p>
Following <i>AN</i> lines indicate coordinates of the center of combat planes. Each line has two integers that describe <i>x</i>-coordinate and <i>y</i>-coordinate.
</p>
<p>
Following <i>BN</i> lines indicate coordinates of the center of energy bullets, in the same format as that of combat planes.
</p>
<p>
Input ends when <i>AN</i> = <i>BN</i> = 0. You should output nothing for this case.
</p>
<H2>Output</H2>
<p>
For each data set, output the total fighting power.
</p>
<H2>Constraints</H2>
<ul>
<li>Jude data includes at most 20 data sets.</li>
<li>1 ≤ <i>AN</i>, <i>BN</i> ≤ 100000</li>
<li>0 < <i>R</i> ≤ 10 </li>
<li>0 ≤ (coordinate values) < 10000</li>
</ul>
<H2>Sample Input</H2>
<pre>
2 2 1
0 0
0 4
2 2
2 8
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
</pre>
|
p02634 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>A</var> horizontal rows and <var>B</var> vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation:</p>
<ul>
<li>Assume that the grid currently has <var>a</var> horizontal rows and <var>b</var> vertical columns. Choose "vertical" or "horizontal".<ul>
<li>If we choose "vertical", insert one row at the top of the grid, resulting in an <var>(a+1) \times b</var> grid.</li>
<li>If we choose "horizontal", insert one column at the right end of the grid, resulting in an <var>a \times (b+1)</var> grid.</li>
</ul>
</li>
<li>Then, paint one of the added squares black, and the other squares white.</li>
</ul>
<p>Assume the grid eventually has <var>C</var> horizontal rows and <var>D</var> vertical columns. Find the number of ways in which the squares can be painted in the end, modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A \leq C \leq 3000</var></li>
<li><var>1 \leq B \leq D \leq 3000</var></li>
<li><var>A</var>, <var>B</var>, <var>C</var>, and <var>D</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways in which the squares can be painted in the end, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Any two of the three squares other than the bottom-left square can be painted black.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 1 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>65
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31 41 59 265
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>387222020
</pre></section>
</div>
</span> |
p00259 |
<H1>有限体電卓</H1>
<p>
0以外のすべての実数の逆数は実数になりますが、整数の逆数が整数になるとは限りません。C言語などで 3.0/2.0*2.0 = 3.0 なのに 3/2*2 = 2 になってしまうのはこのためです。ですが、素数で割った余りが等しい整数を同じものとみなすと、0以外のすべての整数が逆数をもつようにできます。
</p>
<p>
整数 x と y を p で割った余りが等しいとき、x ≡ y (mod p) と書きます。p が素数のとき、このような x と y を同じものとみなすなら、すべての整数 n は0から p−1 までのどれかの整数 x に対して x ≡ n (mod p) となるので、けっきょく { 0, 1, 2, ..., p−1 } という集合だけからなる世界を考えればよいことがわかります。
</p>
<p>
この世界での加減乗除は以下のようになります。
</p>
<ul>
<li> 加算 x+y の値は、x+y ≡ z (mod p) となる 0 から p−1 までの数 z になります。</li>
<li> 減算 x−yの値は、y+m ≡ 0 (mod p) となる 0 から p−1 までの数 m(これが y に相当します)について、x−y ≡ x + m (mod p) となることから得られます。たとえば、p = 5のとき、4+1 ≡ 0 (mod 5) となります。このとき、2−4 ≡ 2+1 ≡ 3 (mod 5) より、2−4の値は3になります。</li>
<li> 乗算 x*y の値は、x*y ≡ z (mod p) となる 0 から p−1 までの数 z になります。</li>
<li> 除算 x/y の値は、y*d ≡ 1 (mod p)となる 0 から p−1 までの数 d (これがyの逆数になります)について、x/y ≡ x*d (mod p) となることから得られます。たとえば、p = 5 のとき、2*3 ≡ 1 (mod 5) より 3 は 2 の逆数になります。このとき、1/2 ≡ 1*3 ≡ 3 (mod 5) より、1/2 の値は 3 になります。
</ul>
<p>
このようにして加減乗除の四則演算がすべて0からp−1の範囲に収まります。このとき、集合 { 0,1,...,p−1 } を p の有限体といいます。この有限体の中で、加減乗除、0 から p−1 までの数、カッコを使って 算術式を構成することができます。
</p>
<p>
p の有限体の 0 以外のすべての要素が逆数をもつことは、フェルマーの小定理と呼ばれる有名な定理 a<sup>p−1</sup> ≡ 1 (mod p) からわかります(ただし、p は素数、a と p は互いに素)。p の有限体のすべての要素 x は p と互いに素なので、この定理から x*x<sup>p-2</sup> ≡ 1 (mod p) となり x<sup>p-2</sup> が x の逆数になるからです。
</p>
<p>
では、素数と式が与えられたときに、その素数の有限体で式を計算する電卓プログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる。入力の終わりは0の後にコロンが1つ続くだけの行 0: で示される。各データセットは以下の形式で与えられる。
</p>
<pre>
p:exp
</pre>
<p>
データセットは1行であり、p (2 ≤ p ≤ 46000) は素数、exp は算術式を示す。exp は加減乗除(それぞれ +, -, *, /)とカッコ、0 から p−1 までの数から構成される。演算子、数、カッコなどの前後には1つ以上の空白が現れる可能性がある。exp の長さは 100,000 を超えない。
</p>
<p>
データセットの数は 1000 を超えない。
</p>
<h2>出力</h2>
<p>
データセットごとに、計算結果を出力する。出力形式は以下の通りである。
</p>
<pre>
exp = val (mod p)
</pre>
<p>
val は、p の有限体での算術式 exp の計算結果である。ただし、0 での除算が含まれるときは NG と出力する。また、exp に現れる加減乗除、カッコ、数の前後には空白を空けないこと。ただし、= の前後には空白を一つずつ空ける。また、valと開きカッコの間、modとp の間にも空白を一つずつ空ける。
</p>
<h2>入力例</h2>
<pre>
5: 2 - 3
17: 1 + 3 * (2 + 3 / 5 * 2) + 7
11: 1 / 8 - 5 - 8 * 2
19: 8 / (2 - 3 * 7)
1153: 10 * 3 / 7 + ( 50 + 81 / 22 ) + 11
0:
</pre>
<h2>出力例</h2>
<pre>
2-3 = 4 (mod 5)
1+3*(2+3/5*2)+7 = 4 (mod 17)
1/8-5-8*2 = 8 (mod 11)
NG
10*3/7+(50+81/22)+11 = 915 (mod 1153)
</pre>
|
p02264 |
<p>
There are <i>n</i> processes in a queue. Each process has name<sub><i>i</i></sub> and time<sub><i>i</i></sub>. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a <i>quantum</i> (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue.
</p>
<p>
For example, we have the following queue with the quantum of 100ms.
</p>
<pre>
A(150) - B(80) - C(200) - D(200)
</pre>
<p>
First, process A is handled for 100ms, then the process is moved to the end of the queue with the remaining time (50ms).
</p>
<pre>
B(80) - C(200) - D(200) - A(50)
</pre>
<p>
Next, process B is handled for 80ms. The process is completed with the time stamp of 180ms and removed from the queue.
</p>
<pre>
C(200) - D(200) - A(50)
</pre>
<p>
Your task is to write a program which simulates the round-robin scheduling<!-- using a queue-->.
<!--You can use a queue to implement the program.-->
</p>
<H2>Input</H2>
<p>
<i>n</i> <i>q</i><br>
<i>name<sub>1</sub> time<sub>1</sub></i><br>
<i>name<sub>2</sub> time<sub>2</sub></i><br>
...<br>
<i>name<sub>n</sub> time<sub>n</sub></i><br>
</p>
<p>
In the first line the number of processes <i>n</i> and the quantum <i>q</i> are given separated by a single space.
</p>
<p>
In the following <i>n</i> lines, names and times for the <i>n</i> processes are given. <i>name<sub>i</sub></i> and <i>time<sub>i</sub></i> are separated by a single space.
</p>
<H2>Output</H2>
<p>
For each process, prints its name and the time the process finished in order.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 100000</li>
<li>1 ≤ <i>q</i> ≤ 1000</li>
<li>1 ≤ <i>time<sub>i</sub></i> ≤ 50000</li>
<li>1 ≤ length of <i>name<sub>i</sub></i> ≤ 10</li>
<li>1 ≤ Sum of <i>time<sub>i</sub></i> ≤ 1000000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5 100
p1 150
p2 80
p3 200
p4 350
p5 20
</pre>
<H2>Sample Output 1</H2>
<pre>
p2 180
p5 400
p1 450
p3 550
p4 800
</pre>
<H2>Notes</H2>
<a href="template/ALDS1_3_B_template.c" target="_blank">Template in C</a>
|
p03025 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Aoki will play a game. They will repeatedly play it until one of them have <var>N</var> wins in total.</p>
<p>When they play the game once, Takahashi wins with probability <var>A</var> %, Aoki wins with probability <var>B</var> %, and the game ends in a draw (that is, nobody wins) with probability <var>C</var> %.
Find the expected number of games that will be played, and print it as follows.</p>
<p>We can represent the expected value as <var>P/Q</var> with coprime integers <var>P</var> and <var>Q</var>.
Print the integer <var>R</var> between <var>0</var> and <var>10^9+6</var> (inclusive) such that <var>R \times Q \equiv P\pmod {10^9+7}</var>.
(Such an integer <var>R</var> always uniquely exists under the constraints of this problem.)</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100000</var></li>
<li><var>0 \leq A,B,C \leq 100</var></li>
<li><var>1 \leq A+B</var></li>
<li><var>A+B+C=100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the expected number of games that will be played, in the manner specified in the statement.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 25 25 50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Since <var>N=1</var>, they will repeat the game until one of them wins.
The expected number of games played is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 50 50 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>312500008
</pre>
<p><var>C</var> may be <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p><var>B</var> may also be <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 31 41 28
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>104136146
</pre></section>
</div>
</span> |
p01018 | <h1>Problem C: Warping Girl</h1>
<h2>Problem</h2>
<p>
会津魔法学校は, 魔法を使える者が集まる学校である. その学校の生徒の一人であるハルカは, 魔法陣の上でワープの魔法を使う事ができる.
</p>
<p>
彼女の家から学校には, 長さ <var>L</var> の一直線状の道がある. また, この道には所々魔法陣が描かれている.<br>
彼女は毎日この道を使って学校に通っているため, できるだけ短い時間で学校に辿り着きたいと思っている.
</p>
<p>
そこでプログラマーであるあなたは, 彼女に学校まで行くときにかかる最小の時間を教えてあげることにした.
</p>
<p>
ハルカは, <var>1</var> 分で距離 <var>1</var> だけ歩いて先に進むことができる ( *戻ることはできない).また, ワープの魔法陣が書いてある位置 <var>P<sub>i</sub></var> で魔法を唱えることで, <var>P<sub>i</sub></var> からちょうど <var>D<sub>i</sub></var> だけ進んだ場所に <var>T<sub>i</sub></var> 分で移動することができる. 移動先に魔法陣がある場合も, 連続してワープ魔法を使用することができる.
</p>
<p>
彼女の家の位置は <var>0</var>、学校の位置は <var>L</var> である.
</p>
<h2>Input</h2>
<pre>
<var>L</var> <var>n</var>
<var>P<sub>1</sub></var> <var>D<sub>1</sub></var> <var>T<sub>1</sub></var>
<var>P<sub>2</sub></var> <var>D<sub>2</sub></var> <var>T<sub>2</sub></var>
.
.
<var>P<sub>n</sub></var> <var>D<sub>n</sub></var> <var>T<sub>n</sub></var>
</pre>
<p>
1行目に道の長さ <var>L</var>, 魔法陣の数 <var>n</var> が与えられる.
次に <var>n</var> 個の魔法陣の状態が与えられる.
<var>P<sub>i</sub></var> は <var>i</var> 番目の魔法陣がある位置, <var>D<sub>i</sub></var> は <var>i</var> 番目の魔法陣からワープする距離, <var>T<sub>i</sub></var> は <var>i</var> 番目の魔法陣を使ってワープしたときにかかる時間を表す.
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす. </p>
<ul>
<li>与えられる数は全て整数である</li>
<li>1 ≤ <var>L</var> ≤ <var>10<sup>9</sup></var>
<li>0 ≤ <var>n</var> ≤ <var>min(10<sup>3</sup>, L)</var> (<var>min</var> は<var>A, B</var> の小さい方を表す)
<li>0 ≤ <var>P<sub>i</sub></var> ≤ <var>L - 1</var>
<li>0 ≤ <var>D<sub>i</sub></var> ≤ <var>L - P<sub>i</sub></var>
<li>0 ≤ <var>T<sub>i</sub></var> ≤ <var>10<sup>3</sup></var>
<li><var>P<sub>i</sub></var> ≠ <var>P<sub>j</sub></var>
</ul>
<h2>Output</h2>
<p>学校に辿り着くための最小の時間を一行に出力せよ.</p>
<h2>Sample Input 1</h2>
<pre>
10 3
2 2 1
4 2 1
8 1 1
</pre>
<h2>Sample Output 1</h2>
<pre>
8
</pre>
<h2>Sample Input 2</h2>
<pre>
10 2
2 3 1
3 5 1
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre>
<h2>Sample Input 3</h2>
<pre>
1 0
</pre>
<h2>Sample Output 3</h2>
<pre>
1
</pre>
|
p03475 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A railroad running from west to east in Atcoder Kingdom is now complete.</p>
<p>There are <var>N</var> stations on the railroad, numbered <var>1</var> through <var>N</var> from west to east.</p>
<p>Tomorrow, the opening ceremony of the railroad will take place.</p>
<p>On this railroad, for each integer <var>i</var> such that <var>1≤i≤N-1</var>, there will be trains that run from Station <var>i</var> to Station <var>i+1</var> in <var>C_i</var> seconds. No other trains will be operated.</p>
<p>The first train from Station <var>i</var> to Station <var>i+1</var> will depart Station <var>i</var> <var>S_i</var> seconds after the ceremony begins. Thereafter, there will be a train that departs Station <var>i</var> every <var>F_i</var> seconds.</p>
<p>Here, it is guaranteed that <var>F_i</var> divides <var>S_i</var>.</p>
<p>That is, for each Time <var>t</var> satisfying <var>S_i≤t</var> and <var>t%F_i=0</var>, there will be a train that departs Station <var>i</var> <var>t</var> seconds after the ceremony begins and arrives at Station <var>i+1</var> <var>t+C_i</var> seconds after the ceremony begins, where <var>A%B</var> denotes <var>A</var> modulo <var>B</var>, and there will be no other trains.</p>
<p>For each <var>i</var>, find the earliest possible time we can reach Station <var>N</var> if we are at Station <var>i</var> when the ceremony begins, ignoring the time needed to change trains.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤N≤500</var></li>
<li><var>1≤C_i≤100</var></li>
<li><var>1≤S_i≤10^5</var></li>
<li><var>1≤F_i≤10</var></li>
<li><var>S_i%F_i=0</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>C_1</var> <var>S_1</var> <var>F_1</var>
<var>:</var>
<var>C_{N-1}</var> <var>S_{N-1}</var> <var>F_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines. Assuming that we are at Station <var>i</var> <var>(1≤i≤N)</var> when the ceremony begins, if the earliest possible time we can reach Station <var>N</var> is <var>x</var> seconds after the ceremony begins, the <var>i</var>-th line should contain <var>x</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
6 5 1
1 10 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
11
0
</pre>
<p>We will travel from Station <var>1</var> as follows:</p>
<ul>
<li><var>5</var> seconds after the beginning: take the train to Station <var>2</var>.</li>
<li><var>11</var> seconds: arrive at Station <var>2</var>.</li>
<li><var>11</var> seconds: take the train to Station <var>3</var>.</li>
<li><var>12</var> seconds: arrive at Station <var>3</var>.</li>
</ul>
<p>We will travel from Station <var>2</var> as follows:</p>
<ul>
<li><var>10</var> seconds: take the train to Station <var>3</var>.</li>
<li><var>11</var> seconds: arrive at Station <var>3</var>.</li>
</ul>
<p>Note that we should print <var>0</var> for Station <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
12 24 6
52 16 4
99 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>187
167
101
0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
12 13 1
44 17 17
66 4096 64
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4162
4162
4162
0
</pre></section>
</div>
</span> |
p01448 |
<H1>Problem B: 友だちの誘い方</H1>
<p>
明日から、待ちに待った夏休みが始まります。なのでわたしは、友だちを誘って、海に遊びに行くこ
とに決めました。
</p>
<p>
けれども、わたしの友だちには、恥ずかしがりやさんが多いです。その人たちは、あまり多くの人が
いっしょに来ると知ったら、きっと嫌がるでしょう。
</p>
<p>
ほかにも、わたしの友だちには、目立ちたがりやさんも多いです。その人たちは、いっしょに来る人
があまり多くないと知れば、きっと嫌がるでしょう。
</p>
<p>
それと、わたしの友だちには、いつもは目立ちたがりやなのに実は恥ずかしがりやさんな人もいま
す。その人たちは、いっしょに来る人が多すぎても少なすぎても、きっと嫌がるでしょう。
</p>
<p>
こういうのは、大勢で行った方が楽しいはずです。だからわたしは、できるだけたくさんの友だちを
誘いたいと思っています。けれども、嫌がる友だちを無理やり連れていくのはよくありません。
</p>
<p>
いったい、わたしは最大で何人の友だちを誘うことができるのでしょうか。
</p>
<p>
わたしは、こういう頭を使いそうな問題が大の苦手です。なので、あなたにお願いがあります。もし
よろしければ、わたしの代わりにこの問題を解いていただけないでしょうか。いえ、決して無理にと
は言いません。けれど、もし解いていただるのでしたら、わたしはとても嬉しいです。
</p>
<H2>Input</H2>
<p>
N<br>
<i>a</i><sub>1</sub> <i>b</i><sub>1</sub><br>
<i>a</i><sub>2</sub> <i>b</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>a<sub>N</sub> b<sub>N</sub></i><br>
</p>
<p>
入力の1行目には、整数N(1 ≤ <i>N</i> ≤ 100,000)が書かれている。これは、友だちの数をあらわす。
</p>
<p>
続く<i>N</i>行には、整数 <i>a<sub>i</sub></I> と整数 <i>b<sub>i</sub></i>(2 ≤ <i>a<sub>i</sub></i> ≤ <i>b<sub>i</sub></i> ≤ 100,001)が、空白区切りで書かれている。1+ i 行目に書かれた整数 <i>a<sub>i</sub></I> と<i>b<sub>i</sub></i> は、i 番目の友だちは海に行く人数が <i>a<sub>i</sub></i> 人以上 <i>b<sub>i</sub></i> 人以下でないと嫌がることをあらわす。海に行く人数には「わたし」も含まれることに注意せよ。
</p>
<H2>Output</H2>
<p>
嫌がる友だちが出ないように、海に誘うことのできる友だちの最大人数を出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
4
2 5
4 7
2 4
3 6
</pre>
<h2>Sample output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
5
8 100001
7 100001
12 100001
8 100001
3 100001
</pre>
<h2>Sample output 2</h2>
<pre>
0
</pre>
<h2>Sample Input 3</h2>
<pre>
6
2 9
4 8
6 7
6 6
5 7
2 100001
</pre>
<h2>Sample output 3</h2>
<pre>
5
</pre>
|
p00170 |
<H1>ランチ</H1>
<p>
お昼に食べるお弁当を作るために、お店で食べ物を買いました。お店では、食べ物を入れるのに細長い袋しかもらえなかったので、すべての食べ物を縦に積んで袋に入れる必要があります。袋が倒れにくいように、できるだけ重い物を下にして詰めたいのですが、食べ物の中にはやわらかい物もあって、上に重い物を乗せるとつぶれてしまいます。
</p>
<!--
そこで、それぞれの食べ物がつぶれないように、かつ出来るだけ重い物が下になるように食べ物を積みたいと思います。
-->
<p>
そこで、食べ物の情報を入力とし、全ての食べ物がつぶれず、かつ全体の重心が最も低くなるような積み方を出力するプログラムを作成してください。それぞれの食べ物ごとに、名前 <var>f</var>、重さ <var>w</var>、上に載せて耐えられる重さ <var>s</var> が指定されます。
「全ての食べ物がつぶれない」というのは、下から順に、(<var>f<sub>1</sub></var>、<var>f<sub>2</sub></var>、... 、<var>f<sub>n</sub></var>)と <var>n</var> 個の食べ物を積んだ時、すべての <var>f</var> について、<br/>
<br/>
<var>s<sub>f<sub>i</sub></sub> ≥ w<sub>f<sub>i+1</sub></sub> + w<sub>f<sub>i+2</sub></sub> + </var> ... <var> + w<sub>f<sub>n</sub></sub></var>
<br/>
<br/>
であることを意味します。また、全体の重心 <var>G</var> は、<br/>
<br/>
<var>G = (1 × w<sub>f<sub>1</sub></sub> + 2 × w<sub>f<sub>2</sub></sub> + </var> ... <var> + n × w<sub>f<sub>n</sub></sub>)</var> / <var>(w<sub>f<sub>1</sub></sub> + w<sub>f<sub>2</sub></sub>+</var> ... <var>+w<sub>f<sub>n</sub></sub></var>)
<br/>
<br/>
とします。ただし、解はちょうど1つだけ存在するものとします。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>f<sub>1</sub></var> <var>w<sub>1</sub></var> <var>s<sub>1</sub></var>
<var>f<sub>2</sub></var> <var>w<sub>2</sub></var> <var>s<sub>2</sub></var>
:
<var>f<sub>n</sub></var> <var>w<sub>n</sub></var> <var>s<sub>n</sub></var>
</pre>
<p>
1行目に食べ物の個数 <var>n</var> (1 ≤ <var>n</var> ≤ 10)、続く <var>n</var> 行に <var>i</var> 番目の食べ物の名前 <var>f<sub>i</sub></var> (20 文字以内の半角英文字列)、重さ <var>w<sub>i</sub></var> (1 ≤ <var>w<sub>i</sub></var> ≤ 1000)、耐えられる重さ <var>s<sub>i</sub></var> (1 ≤ <var>s<sub>i</sub></var> ≤ 1000) が空白区切りで与えられます。
</p>
<p>
データセットの数は 20 を超えません。
</p>
<H2>Output</H2>
<p>
データセットごとに、次の形式で食べ物の名前を下から積み上げる順に出力します。<br/>
<br/>
1 行目: 1 番下の食べ物の名前(半角英文字列) <br/>
2 行目: 下から2 番目の食べ物の名前<br/>
:<br/>
<var>n</var> 行目: 1 番上の食べ物の名前<br/>
</p>
<H2>Sample Input</H2>
<pre>
4
sandwich 80 120
apple 50 200
cheese 20 40
cake 100 100
9
onigiri 80 300
onigiri 80 300
anpan 70 280
mikan 50 80
kanzume 100 500
chocolate 50 350
cookie 30 80
purin 40 400
cracker 40 160
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
apple
cake
sandwich
cheese
kanzume
purin
chocolate
onigiri
onigiri
anpan
mikan
cracker
cookie
</pre>
|
p00520 |
<H1>問題 6: 小籠包 (Xiao Long Bao)
</H1>
<br/>
<h2>問題</h2>
<p>
JOI 君はお昼ごはんに,中華料理屋で小籠包を食べることにした.
小籠包とは,具と熱いスープを小麦粉の皮で包んだ料理であり,食べるときにスープが周囲に飛び散ることで知られている.
</p>
<p>
JOI 君が注文した小籠包のセットは,具やスープの異なる N 個の小籠包からなる.
N 個の小籠包は等間隔に一列に並んでおり,順番に 1 から N の番号がつけられている.
i 番目の小籠包と j 番目の小籠包の間の距離は絶対値 |i - j| である.
</p>
<p>
JOI 君は小籠包をある順番で食べていく.
最初,すべての小籠包のおいしさは 0 である.
i 番目の小籠包を食べると,周囲にその汁が飛び散り,まだ食べられていない小籠包のうち,小籠包 i からの距離が D<sub>i</sub> 以下の小籠包に汁がかかる.汁がかかった小籠包はおいしさが
A<sub>i</sub> 増える.すなわち, i 番目の小籠包を食べたときに,
j 番目の小籠包 (1 ≤ j ≤ N かつ i - D<sub>i</sub> ≤ j ≤ i + D<sub>i</sub>) がまだ食べられずに残っているならば,
j 番目の小籠包のおいしさが A<sub>i</sub> 増える.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2014-yo-t6-fig01" alt="picture" width="400" height="200">
</center>
<br>
<p>
JOI 君は,食べる順番を工夫することで,食べる小籠包のおいしさの合計を最大化したい.
もっとも良い順番で食べたときの,JOI 君が食べる小籠包のおいしさの合計を求めるプログラムを作成せよ.
</p>
<h2>入力</h2>
<p>
入力ファイルは 3 行からなる.
</p>
<p>
1 行目には 1 つの整数 N (1 ≤ N ≤ 100) が書かれている.
</p>
<p>
2 行目には, N 個の整数 D<sub>1</sub>, D<sub>2</sub>, ..., D<sub>N</sub> (0 ≤ D<sub>i</sub> ≤ 7) が空白を区切りとして書かれている.
</p>
<p>
3 行目には, N 個の整数 A<sub>1</sub>, A<sub>2</sub>, ..., A<sub>N</sub> (0 ≤ A<sub>i</sub> ≤ 1000) が空白を区切りとして書かれている.
</p>
<h2>出力</h2>
<p>
JOI 君が食べる小籠包のおいしさの合計の最大値を 1 行で出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例 1 </h3>
<pre>
5
1 0 1 1 2
0 2 6 3 4
</pre>
<h3>出力例 1 </h3>
<pre>
20
</pre>
<p>
入出力例 1 では,5 番目 → 3 番目 → 1 番目 → 2 番目 → 4 番目 の順番で食べると,
おいしさの合計が 20 になる.合計が 20 を超えるような食べ方は存在しないので,これが最善である.
</p>
<h3>入力例 2 </h3>
<pre>
10
5 2 7 2 6 5 3 5 3 6
8 7 8 4 0 6 0 10 10 0
</pre>
<h3>出力例 2 </h3>
<pre>
237
</pre>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p01761 |
<h1>B : Books / 本</h1>
<h1>Problem</h1>
<p>大学生のいづあ君はかなりの読書家である。面白そうだと思った本は迷わず買うため、蔵書が増えすぎて管理できなくなっているのが悩みである。そこでいづあ君は、持っている本の中から目的の本を検索するシステムを作ることにした。</p>
<p>全ての本は次の 3 つの属性を持つ。</p>
<ul>
<li><em>title</em> : 本のタイトルを表す文字列である。</li>
<li><em>author</em> : 本の著者を表す文字列である。</li>
<li><em>date</em> : 本の出版日を表す <code>2014/07/07</code> のような形式をした文字列である。</li>
</ul>
<p>検索のクエリは次のような形式で与えられる。</p>
<p><em>Q_title</em> <em>Q_author</em> <em>Q_date_from</em> <em>Q_date_to</em><br>
</p>
<ul>
<li><em>Q_title</em> : タイトルに文字列 <em>Q_title</em> を含む本がヒットする。</li>
<li><em>Q_author</em> : 著者名に文字列 <em>Q_author</em> を含む本がヒットする。</li>
<li><em>Q_date_from</em> : 出版日が <em>Q_date_from</em> と同じかそれより後である本がヒットする。</li>
<li><em>Q_date_to</em> : 出版日が <em>Q_date_to</em> と同じかそれより前である本がヒットする。</li>
</ul>
<p>ただし、クエリに <code>*</code> (アスタリスク)が指定された場合は任意の文字列にヒットする。ある本がヒットするかの判定は上記 4 つの論理積で行われる。つまり、 1 つ以上ヒットしていない属性がある場合はその本はヒットしていないものとする。(「ヒットする」とは本が検索クエリに合致することを意味する。)</p>
<p>いづあ君の仕事は与えられたクエリを順に処理するプログラムを書くことである。</p>
<h1>Input</h1>
<p>入力は次の形式で与えられる。</p>
<p><em>N</em><br><em>book 1</em><br>...<br><em>book N</em><br><em>Q</em><br><em>query 1</em><br>...<br><em>query Q</em></p>
<p>
<em>N</em> はいづあ君が持っている本の数であり、続く <em>N</em> 行にはそれぞれの本に関する情報が続く。本に関する情報は次のような形式である。
</p>
<p><em>title</em> <em>author</em> <em>date</em></p>
<p>
<em>Q</em> は検索クエリの数であり、続く <em>Q</em> 行にクエリが続く。検索のクエリは次のような形式で与えられる。
</p>
<p><em>Q_title</em> <em>Q_author</em> <em>Q_date_from</em> <em>Q_date_to</em></p>
<h1>Constraints</h1>
<ul>
<li><em>N</em>, <em>Q</em> は整数である。</li>
<li>1 ≦ <em>N</em> ≦ 100</li>
<li>1 ≦ <em>Q</em> ≦ 100</li>
<li>タイトルが同じ本は含まれない。</li>
<li>本のタイトル、著者、及びそれらに対するクエリの文字列の長さは 50 文字以下であり、含まれる文字はアルファベットの大文字と小文字のみである。大文字と小文字は区別される('a'と'A'は違う文字とみなす)。ただしクエリは<code>*</code>一文字のこともある。</li>
<li>本の出版日及びそれに対するクエリは <code>2014/07/31</code> のような形式で表され、西暦年 (4桁)/月(2桁)/日(2桁) という意味である。この例の場合は 2014 年 7 月 31 日を表す。</li>
<li>日付は 1970 年 1 月 1 日から 2037 年 12 月 31 日の範囲内である。</li>
<li>15 月 40 日のような無効な日付は入力されない。</li>
</ul>
<h1>Output</h1>
<p>各クエリに対して、ヒットする本のタイトルを答えよ。 2 冊以上ヒットする場合は、1 行に 1 冊ずつ、入力された順番に全てのタイトルを出力せよ。 1 冊もヒットしない場合は 1 行も出力してはならない。クエリとクエリの間には空行を挟むこと。</p>
<h1>Samples</h1>
<h2>Sample Input 1</h2>
<pre>6
antbook iwiWataKitamasa 2012/01/28
hogebook foo 2000/01/01
hugabook bar 2000/01/01
cheeterbook chokudai 2012/09/29
aojbook YutakaWatanabe 2014/06/28
piyobook buz 2000/01/01
4
a * * *
* chokudai * *
* Chokudai * *
* * 2014/01/01 2014/12/31</pre>
<h2>Sample Output 1</h2>
<pre>antbook
hugabook
aojbook
cheeterbook
aojbook</pre>
<p>3 番目のクエリは、一見 2 番目のクエリと同じように見えるが、先頭の文字が大文字となっており、そのような名前のちょくだいさんは著者名として存在しないため、 1 行も出力してはならない。</p> |
p00873 |
<H1><font color="#000">Problem J:</font> Zigzag</H1>
<p>
Given several points on a plane, let’s try to solve a puzzle connecting them with a zigzag line.
The puzzle is to find the zigzag line that passes through all the given points with the minimum
number of turns. Moreover, when there are several zigzag lines with the minimum number of
turns, the shortest one among them should be found.
</p>
<p>
For example, consider nine points given in Figure 1.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_zigzag1">
<p>Figure 1: Given nine points</p>
</center>
<p>
A zigzag line is composed of several straight line segments. Here, the rule requests that each
line segment should pass through two or more given points.
</p>
<p>
A zigzag line may turn at some of the given points or anywhere else. There may be some given
points passed more than once.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_zigzag2">
<p>Figure 2: Zigzag lines with three turning points.</p>
</center>
<p>
Two zigzag lines with three turning points are depicted in Figure 2 (a) and (b) for the same
set of given points shown in Figure 1. The length of the zigzag line in Figure 2 (a) is shorter than that in Figure 2 (b). In fact, the length of the zigzag line in Figure 2 (a) is the shortest
so that it is the solution for the nine points given in Figure 1.
</p>
<p>
Another zigzag line with four turning points is depicted in Figure 3. Its length is shorter than
those in Figure 2, however, the number of turning points is greater than those in Figure 2,
and thus, it is not the solution.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_zigzag3">
<p>Figure 3: Zigzag line with four turning points.</p>
</center>
<p>
There are two zigzag lines that passes another set of given points depicted in Figure 4 (a) and
(b).
</p>
<p>
Both have the same number of turning points, and the line in (a) is longer than that in (b).
However, the solution is (a), because one of the segments of the zigzag line in (b) passes only
one given point, violating the rule.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_zigzag4">
<p>Figure 4: Zigzag line with two turning points (a), and not a zigzag line concerned (b).</p>
</center>
<p>
Your job is to write a program that solves this puzzle.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, followed by a line containing one zero. Each dataset
has the following format.
</p>
<pre>
<i>n</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
.
.
.
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub>
</pre>
<p>
Every input item in a dataset is a non-negative integer. Items in a line are separated by a single
space.
</p>
<p>
<i>n</i> is the number of the given points. <i>x</i><sub><i>k</i></sub> and <i>y</i><sub><i>k</i></sub> (<i>k</i> = 1, . . . , <i>n</i>) indicate the position of the <i>k</i>-th
point. The order of the points is meaningless. You can assume that 2 ≤ <i>n</i> ≤ 10, 0 ≤ <i>x</i><sub><i>k</i></sub> ≤ 10,
and 0 ≤ <i>y</i><sub><i>k</i></sub> ≤ 10.
</p>
<H2>Output</H2>
<p>
For each dataset, the minimum number of turning points and the length of the shortest zigzag
line with that number of turning points should be printed, separated by a space in a line. The
length should be in a decimal fraction with an error less than 0.0001 (= 1.0 × 10<sup>-4</sup> ).
</p>
<p>
You may assume that the minimum number of turning points is at most four, that is, the number
of line segments is at most five.
</p>
<p>
The example solutions for the first four datasets in the sample input are depicted in Figure 5
and 6.
</p>
<H2>Sample Input</H2>
<pre>
2
0 0
10 9
4
0 0
3 1
0 3
3 3
10
2 2
4 2
6 2
2 4
4 4
6 4
2 6
4 6
6 6
3 3
10
0 0
2 0
4 0
0 2
2 2
4 2
0 4
2 4
4 4
6 8
9
0 0
1 0
3 0
0 1
1 1
3 1
0 2
1 2
2 2
10
0 0
1 0
0 1
1 1
9 9
9 10
10 9
10 10
0 2
10 8
10
0 0
0 10
2 0
2 1
2 7
2 10
5 1
6 7
9 2
10 9
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 13.45362405
1 18.48683298
3 24.14213562
4 24.94813673
3 12.24264069
3 60.78289622
3 502.7804353
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_zigzag5">
<p>Figure 5: Example solutions for the first and the second datasets in the sample inputs.</p>
</center>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_zigzag6">
<p>Figure 6: Example solutions for the third and the fourth datasets in the sample inputs.</p>
</center>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.