question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03161 | <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 one of the following: Stone <var>i + 1, i + 2, \ldots, i + K</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 K \leq 100</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>K</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>5 3
10 30 40 50 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>5</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>3 1
10 20 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>20
</pre>
<p>If we follow the path <var>1</var> → <var>2</var> → <var>3</var>, the total cost incurred would be <var>|10 - 20| + |20 - 10| = 20</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 100
10 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</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 4</h3><pre>10 4
40 10 20 70 80 10 20 70 80 60
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>40
</pre>
<p>If we follow the path <var>1</var> → <var>4</var> → <var>8</var> → <var>10</var>, the total cost incurred would be <var>|40 - 70| + |70 - 70| + |70 - 60| = 40</var>.</p></section>
</div>
</span> |
p03531 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>2^N</var> players competed in a tournament.
Each player has a unique ID number from <var>1</var> through <var>2^N</var>. When two players play a match, the player with the smaller ID always wins.</p>
<p>This tournament was a little special, in which losers are not eliminated to fully rank all the players.</p>
<p>We will call such a tournament that involves <var>2^n</var> players a <em>full tournament of level <var>n</var></em>.
In a full tournament of level <var>n</var>, the players are ranked as follows:</p>
<ul>
<li>In a full tournament of level <var>0</var>, the only player is ranked first.</li>
<li>In a full tournament of level <var>n\ (1 \leq n)</var>, initially all <var>2^n</var> players are lined up in a row. Then:</li>
<li>First, starting from the two leftmost players, the players are successively divided into <var>2^{n-1}</var> pairs of two players.</li>
<li>Each of the pairs plays a match. The winner enters the "Won" group, and the loser enters the "Lost" group.</li>
<li>The players in the "Won" group are lined up in a row, maintaining the relative order in the previous row. Then, a full tournament of level <var>n-1</var> is held to fully rank these players.</li>
<li>The players in the "Lost" group are also ranked in the same manner, then the rank of each of these players increases by <var>2^{n-1}</var>.</li>
</ul>
<p>For example, the figure below shows how a full tournament of level <var>3</var> progresses when eight players are lined up in the order <var>3,4,8,6,2,1,7,5</var>. The list of the players sorted by the final ranking will be <var>1,3,5,6,2,4,7,8</var>.</p>
<p><img alt="" src="https://img.atcoder.jp/cf17-final/e93269f0dfb68bcdff175a3b634ab0d8.png"/></p>
<p>Takahashi has a sheet of paper with the list of the players sorted by the final ranking in the tournament, but some of it blurred and became unreadable.
You are given the information on the sheet as a sequence <var>A</var> of length <var>N</var>. When <var>A_i</var> is <var>1</var> or greater, it means that the <var>i</var>-th ranked player had the ID <var>A_i</var>. If <var>A_i</var> is <var>0</var>, it means that the ID of the <var>i</var>-th ranked player is lost.</p>
<p>Determine whether there exists a valid order in the first phase of the tournament which is consistent with the sheet. If it exists, provide one such order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 18</var></li>
<li><var>0 \leq A_i \leq 2^N</var></li>
<li>No integer, except <var>0</var>, occurs more than once in <var>A_i</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_{2^N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists a valid order in the first phase of the tournament, print <code>YES</code> first, then in the subsequent line, print the IDs of the players sorted by the final ranking, with spaces in between.
If there is no such order, print <code>NO</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 3 0 6 0 0 0 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
3 4 8 6 2 1 7 5
</pre>
<p>This is the same order as the one in the statement.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p03862 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> boxes arranged in a row.
Initially, the <var>i</var>-th box from the left contains <var>a_i</var> candies.</p>
<p>Snuke can perform the following operation any number of times:</p>
<ul>
<li>Choose a box containing at least one candy, and eat one of the candies in the chosen box.</li>
</ul>
<p>His objective is as follows:</p>
<ul>
<li>Any two neighboring boxes contain at most <var>x</var> candies in total.</li>
</ul>
<p>Find the minimum number of operations required to achieve the objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≤ N ≤ 10^5</var></li>
<li><var>0 ≤ a_i ≤ 10^9</var></li>
<li><var>0 ≤ x ≤ 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>x</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Eat one candy in the second box.
Then, the number of candies in each box becomes <var>(2, 1, 2)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 1
1 6 1 2 0 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre>
<p>For example, eat six candies in the second box, two in the fourth box, and three in the sixth box.
Then, the number of candies in each box becomes <var>(1, 0, 1, 0, 0, 1)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 9
3 1 4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>The objective is already achieved without performing operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 0
5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>10
</pre>
<p>All the candies need to be eaten.</p></section>
</div>
</span> |
p02770 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence of <var>k</var> numbers: <var>d_0,d_1,...,d_{k - 1}</var>.</p>
<p>Process the following <var>q</var> queries in order:</p>
<ul>
<li>The <var>i</var>-th query contains three integers <var>n_i</var>, <var>x_i</var>, and <var>m_i</var>.
Let <var>a_0,a_1,...,a_{n_i - 1}</var> be the following sequence of <var>n_i</var> numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\ a_{j - 1} + d_{(j - 1)~\textrm{mod}~k} & ( 0 < j \leq n_i - 1 ) \end{cases}\end{eqnarray}
Print the number of <var>j~(0 \leq j < n_i - 1)</var> such that <var>(a_j~\textrm{mod}~m_i) < (a_{j + 1}~\textrm{mod}~m_i)</var>.</li>
</ul>
<p>Here <var>(y~\textrm{mod}~z)</var> denotes the remainder of <var>y</var> divided by <var>z</var>, for two integers <var>y</var> and <var>z~(z > 0)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq k, q \leq 5000</var></li>
<li><var>0 \leq d_i \leq 10^9</var></li>
<li><var>2 \leq n_i \leq 10^9</var></li>
<li><var>0 \leq x_i \leq 10^9</var></li>
<li><var>2 \leq m_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>k</var> <var>q</var>
<var>d_0</var> <var>d_1</var> <var>...</var> <var>d_{k - 1}</var>
<var>n_1</var> <var>x_1</var> <var>m_1</var>
<var>n_2</var> <var>x_2</var> <var>m_2</var>
<var>:</var>
<var>n_q</var> <var>x_q</var> <var>m_q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>q</var> lines.</p>
<p>The <var>i</var>-th line should contain the response to the <var>i</var>-th query.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
3 1 4
5 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>For the first query, the sequence {<var>a_j</var>} will be <var>3,6,7,11,14</var>.</p>
<ul>
<li><var>(a_0~\textrm{mod}~2) > (a_1~\textrm{mod}~2)</var></li>
<li><var>(a_1~\textrm{mod}~2) < (a_2~\textrm{mod}~2)</var></li>
<li><var>(a_2~\textrm{mod}~2) = (a_3~\textrm{mod}~2)</var></li>
<li><var>(a_3~\textrm{mod}~2) > (a_4~\textrm{mod}~2)</var></li>
</ul>
<p>Thus, the response to this query should be <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 3
27 18 28 18 28 46 1000000000
1000000000 1 7
1000000000 2 10
1000000000 3 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>224489796
214285714
559523809
</pre></section>
</div>
</span> |
p02320 |
<H1>Knapsack Problem with Limitations</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>, weight <var>w<sub>i</sub></var> and limitation <var>m<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>
<li>You can select at most <var>m<sub>i</sub></var> items for <i>i</i>th item.</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>m<sub>1</sub></var>
<var>v<sub>2</sub></var> <var>w<sub>2</sub></var> <var>m<sub>2</sub></var>
:
<var>v<sub>N</sub></var> <var>w<sub>N</sub></var> <var>m<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, weight and limitation 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> ≤ 100</li>
<li> 1 ≤ <var>v<sub>i</sub></var> ≤ 1,000</li>
<li> 1 ≤ <var>w<sub>i</sub></var> ≤ 1,000</li>
<li> 1 ≤ <var>m<sub>i</sub></var> ≤ 10,000</li>
<li> 1 ≤ <var>W</var> ≤ 10,000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 8
4 3 2
2 1 1
1 2 4
3 2 2
</pre>
<H2>Sample Output 1</H2>
<pre>
12
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
2 100
1 1 100
2 1 50
</pre>
<H2>Sample Output 2</H2>
<pre>
150
</pre> |
p03927 | <span class="lang-en">
<p>Score : <var>1900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a grid with <var>H</var> rows and <var>W</var> columns. The square at the <var>i</var>-th row and <var>j</var>-th column contains a character <var>S_{i,j}</var>.</p>
<p>He can perform the following two kinds of operation on the grid:</p>
<ul>
<li>Row-reverse: Reverse the order of the squares in a selected row.</li>
<li>Column-reverse: Reverse the order of the squares in a selected column.</li>
</ul>
<p>For example, reversing the <var>2</var>-nd row followed by reversing the <var>4</var>-th column will result as follows:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/31458935865e5db21bfbcd2eab9511da.png"/></p>
<p>By performing these operations any number of times in any order, how many placements of characters on the grid can be obtained?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦H,W≦200</var></li>
<li><var>S_{i,j}</var> is a lowercase English letter (<code>a</code>-<code>z</code>).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>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 number of placements of characters on the grid that can be obtained, modulo <var>1000000007 (=10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
cf
cf
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The following <var>6</var> placements of characters can be obtained:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/ddf2925467af2c9734194a886f819a2b.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 12
codefestival
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre></section>
</div>
</span> |
p02635 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> consisting of <code>0</code> and <code>1</code>. Find the number of strings, modulo <var>998244353</var>, that can result from applying the following operation on <var>S</var> between <var>0</var> and <var>K</var> times (inclusive):</p>
<ul>
<li>Choose a pair of integers <var>i, j</var> <var>(1\leq i < j\leq |S|)</var> such that the <var>i</var>-th and <var>j</var>-th characters of <var>S</var> are <code>0</code> and <code>1</code>, respectively. Remove the <var>j</var>-th character from <var>S</var> and insert it to the immediate left of the <var>i</var>-th character.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 300</var></li>
<li><var>0 \leq K \leq 10^9</var></li>
<li><var>S</var> consists of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the number of strings, modulo <var>998244353</var>, that can result from applying the operation on <var>S</var> between <var>0</var> and <var>K</var> times (inclusive).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>0101 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Four strings, <code>0101</code>, <code>0110</code>, <code>1001</code>, and <code>1010</code>, can result.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>01100110 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>14
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1101010010101101110111100011011111011000111101110101010010101010101 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>113434815
</pre></section>
</div>
</span> |
p00608 |
<H1><font color="#000000">Problem D:</font> Indian Puzzle</H1>
<p>
In the Indian Puzzle, one is intended to fill out blanks with numbers and operators in a <i>n</i> by <i>n</i> grid in order to make equalities in the grid true (See Figure 1).
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_indianPuzzle">
<p>Figure 1</p>
</center>
<br>
<p>
A blank cell should be filled out with a number (from 0 to 9 inclusive) or an operator (<span>+</span>, <span>-</span>, <span>×</span>, <span>÷</span>, <span>=</span>), and black cells split equalities. Initially, some cells are already filled with numbers or operators.
</p>
<p>
The objective of this puzzle is to fill out all the blank cells with numbers (from 0 to 9 inclusive) and operators (<span>+</span>, <span>-</span>, <span>×</span>, <span>÷</span>) in a given list. All the numbers and operators in the list must be used to fill out the blank cells.
</p>
<p>
A equality is organized by more than 2 consecutive left-to-right or top-to-bottom white cells. You can assume that a equality contains exactly one cell with '<span>=</span>' which connects two expressions.
</p>
<p>
The expressions conform to the order of operations and semantics of conventional four arithmetic operations. First, do all multiplication and division, starting from the left (top). Then, do all addition and subtraction, starting from the left (top). In addition, this puzzle has the following rules:
</p>
<ul>
<li>Division by zero and division leaving a remainder, are not allowed.</li>
<li>Leading zeros are not allowed.</li>
<li>Unary operators like <span>3×-8=-24</span> are not allowed.</li>
</ul>
<p>
In a formal description, the equality must conform the syntax in the following BNF:
</p>
<!--
<pre>
<Eq> ::= <Ex> = <Ex>
<Ex> ::= <T> | <Ex> + <T> | <Ex> - <T>
<T> ::= <N0> | <T> × <N0> | <T> ÷ <N>
<N0> ::= <N> | 0
<N> ::= <D> | <N + D0>
<D0> ::= <D> | 0
<D> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
</pre>
<pre>
<Eq> ::= <Ex> = <Ex>
<Ex> ::= <T> | <Ex> + <T> | <Ex> - <T>
<T> ::= <N> | <T> × <N> | <T> ÷ <N>
<N> ::= <D> | <N> <D>
<D> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
</pre>
-->
<pre>
<Eq> ::= <Ex> = <Ex>
<Ex> ::= <N0> | <Ex> <Op> <N0>
<N0> ::= <N> | 0
<N> ::= <D> | <N> <D> | <N> 0
<Op> ::= + | - | × | ÷
<D> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
</pre>
<p>
Of course, puzzle creators must make solvable puzzle.
Your task is to write a program which verifies whether given puzzle is solvable or not.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. Each dataset consists of:
</p>
<pre>
<i>H W</i>
<i>H</i> × <i>W</i> characters
<i>n</i>
<i>n</i> characters
</pre>
<p>
The integers <i>H</i> and <i>W</i> are the numbers of rows and columns of the grid, respectively. <i>H</i> × <i>W</i> characters denote the grid which contains '<span>.</span>' representing a blank cell, '<span>#</span>' representing a black cell, numbers (from <span>0</span> to <span>9</span> inclusive), operators('<span>+</span>','<span>-</span>', '<span>*</span>', '<span>/</span>', '<span>=</span>')(<span>×</span> is represented by '<span>*</span>' and <span>÷</span> is represented by '<span>/</span>').
</p>
<p>
The integer <i>n</i> is the number of characters in the list. The last line of a dataset contains <i>n</i> characters indicating numbers and operators for the blank cells.
</p>
<p>
The end of input is indicated by a line containing two zeros separated by a space.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>Yes</span>" if the given puzzle is solvable, "<span>No</span>" if not.
</p>
<H2>Constraints</H2>
<ul>
<li>Judge data includes at most 100 data sets.</li>
<li><i>H</i>, <i>W</i> ≤ 10</li>
<li><i>n</i> ≤ 10</li>
</ul>
<H2>Sample Input</H2>
<pre>
5 5
4=..2
+#=#+
.-2=.
=#*#=
.-.=3
6
7 3 1 4 / 8
1 6
8..3=2
2
2 +
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Yes
No
</pre>
|
p02265 |
<H1>Doubly Linked List</H1>
<p>
Your task is to implement a double linked list.
</p>
<p>
Write a program which performs the following operations:
</p>
<ul>
<li>insert x: insert an element with key x into the front of the list.</li>
<li>delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.</li>
<li>deleteFirst: delete the first element from the list. </li>
<li>deleteLast: delete the last element from the list. </li>
</ul>
<H2>Input</H2>
<p>
The input is given in the following format:
</p>
<p>
<i>n</i><br>
<i>command</i><sub>1</sub> <br>
<i>command</i><sub>2</sub> <br>
...<br>
<i>command<sub>n</sub></i> <br>
</p>
<p>
In the first line, the number of operations <i>n</i> is given. In the following <i>n</i> lines, the above mentioned operations are given in the following format:
</p>
<ul>
<li><span>insert x</span></li>
<li><span>delete x</span></li>
<li><span>deleteFirst </span></li>
<li><span>deleteLast </span></li>
</ul>
<H2>Output</H2>
<p>
Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.
</p>
<H2>Constraints</H2>
<ul>
<li>The number of operations ≤ 2,000,000</li>
<li>The number of delete operations ≤ 20</li>
<li>0 ≤ value of a key ≤ 10<sup>9</sup></li>
<li>The number of elements in the list does not exceed 10<sup>6</sup></li>
<li>For a delete, deleteFirst or deleteLast operation, there is at least one element in the list.</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
</pre>
<H2>Sample Output 1</H2>
<pre>
6 1 2
</pre>
<H2>Sample Input 2</H2>
<pre>
9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast
</pre>
<H2>Sample Output 2</H2>
<pre>
1
</pre>
<!--
<H2>Notes</H2>
<a href="template/ALDS1_3_C_template.c" target="_blank">Template in C</a>
-->
|
p00258 |
<H1>ビートパネル</H1>
<p>
遊太君は、近所のゲームセンターで人気のゲーム「ビートパネル」にはまっています。このゲームは図のようなグリッド状に並べられた 4×4 の計16個のパネル型のボタンからなります。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_beatPanel">
</center>
<br/>
<p>
図のように、左上から右下にボタン1, ボタン2, …, ボタン16の順にボタンが並んでいます。ゲームでは一定間隔でビート音が鳴り最後に終了音が鳴ります。ビート音が鳴ると同時に複数のボタンが光ります。1個も光らない場合もあります。プレイヤーは、ビート音が鳴った直後から次の音が鳴るまでの間に両手の指を使って複数のボタンを1度だけ同時に押すことができます。何も押さないということも可能です。終了音が鳴ったと同時にゲームは終了します。
</p>
<p>
遊太君は c 通りの押し方を習得しており、ビート音が鳴る度に、それらの押し方の中から1つ決めてボタンを押します。押したボタンが光っていれば、それらのボタンの光は消え、消えたボタンの数がプレイヤーのスコアに加算されます。また、一度光ったボタンはそのボタンが押されるまで光は消えることはありません。
</p>
<p>
ビート音が n 回鳴るときのボタンの光り方と遊太君が習得している c 通りのボタンの押し方を入力とし、遊太君が獲得することのできる得点の最大値を出力するプログラムを作成してください。
</p>
<h2>入力</h2>
<p>
入力は複数のデータセットからなる。入力の終わりはゼロ2つの行で示される。各データセットは以下の形式で与えられる。
</p>
<pre>
n c
a<sub>1,1</sub> a<sub>1,2</sub> ... a<sub>1,16</sub>
a<sub>2,1</sub> a<sub>2,2</sub> ... a<sub>2,16</sub>
...
a<sub>n,1</sub> a<sub>n,2</sub> ... a<sub>n,16</sub>
b<sub>1,1</sub> b<sub>1,2</sub> ... b<sub>1,16</sub>
b<sub>2,1</sub> b<sub>2,2</sub> ... b<sub>2,16</sub>
...
b<sub>c,1</sub> b<sub>c,2</sub> ... b<sub>c,16</sub>
</pre>
<p>
1行目は1つの空白で区切られた2つの整数からなる。n (1 ≤ n ≤ 30) はビート音の数、c (1 ≤ c ≤ 30) は習得しているボタンの押し方の数を示す。続く n+c 行にボタンの光り方とボタンの押し方が与えられる。行中の入力項目の区切りは1つの空白である。a<sub>k,i</sub> は k 回目のビート音が鳴ったときのボタン i の光り方を、b<sub>j,i</sub> は c 通り中 j 番目の押し方でボタン i が押されるかどうかを表す。a<sub>k,i</sub>の値は 0 が「光らない」、1 が「光る」を表す。b<sub>j,i</sub> の値は 0 が「押さない」、1 が「押す」を表す。
</p>
<p>
データセットの数は 20 を超えない。
</p>
<h2>出力</h2>
<p>
各データセットごとに、得点の最大値を1行に出力する。
</p>
<h2>入力例</h2>
<pre>
2 2
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0
2 2
0 0 1 0 1 1 1 1 0 0 1 0 0 0 1 0
0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0
0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0
5 3
0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0
1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1
0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0
0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
0 0
</pre>
<h2>出力例</h2>
<pre>
8
7
16
</pre>
|
p01019 |
<h1>Problem D: Cheat Case</h1>
<h2>Problem</h2>
<p>
算数のテストを受けることになった俺達は、今から勉強しても赤点を取ってしまうことを確信し、カンニングで乗り切ることを決意した。
</p>
<p>
算数のテスト問題を作成するA先生はテスト用紙を手書きで作ることで知られている。彼がテスト問題を作成している時の筆跡情報を、近所の博士に作ってもらった筆跡盗聴鉛筆で盗み取る作戦だ。だが肝心の筆跡情報から問題を復元するプログラムは博士の技術では作ることができなかった。しかも、たとえ問題が復元できたとしても、俺達の頭脳では問題を解くことができない。どうすることもできなくなった俺達は、プログラマーであるあなたに、筆跡情報から問題を復元し、それを解くプログラムの作成を依頼することにした。
</p>
<p>
今回のテストでは、数式を解く問題が出題される。数式中の演算記号は+(加算),-(減算),・(乗算)の3つのみで、乗算は加算、減算よりも優先して計算される。数式は必ず構文が正しいものが与えられる。また、0以外の数で、先頭が0であるものは与えられない。
</p>
<p>
問題が書かれる紙はグリッドで表される。筆跡情報は線分の集合で与えられ、各線分はX軸に水平または垂直、もしくは始点、終点が同じ(点)である。この線分は、始点から終点までにあるマスを黒く塗りつぶすことを表す。座標(0, 0)が紙の左上である。数式の各文字(0,1,2,3,4,5,6,7,8,9,+,-,・)は以下で表される。
</p>
<table width="780">
<tr height="28">
<td align="center">0</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">3</td>
<td align="center">4</td>
<td align="center">5</td>
<td align="center">6</td>
</tr>
<tr>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_0.png" alt="0"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_1.png" alt="1"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_2.png" alt="2"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_3.png" alt="3"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_4.png" alt="4"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_5.png" alt="5"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_6.png" alt="6"> </td>
</tr>
<tr height="28">
<td align="center">7</td>
<td align="center">8</td>
<td align="center">9</td>
<td align="center">+</td>
<td align="center">-</td>
<td align="center">・</td>
<td align="center"></td>
</tr>
<tr>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_7.png" alt="7"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_8.png" alt="8"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_9.png" alt="9"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_add.png" alt="+"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_subtract.png" alt="-"> </td>
<td align="center"><img width="64" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_multiply.png" alt="・"> </td>
<td align="center"> </td>
</tr>
</table>
<p>
A先生は印刷したかのような字を書くことで知られており、各文字は上記以外の書かれ方はしない。また、上記以外の文字が書かれることはない。2つ以上の文字がマスの辺を共有することはない。各文字の位置は、文字を構成するマス(黒いマス)の中で、最も左側にあるもののX座標で表される。数式の文字は、位置が小さい順に(左から右へ)解釈される。2つ以上の文字の位置が等しくなることはない。
</p>
<h2>Input</h2>
<pre>
<var>N</var>
<var>X<sub>11</var> <var>Y<sub>11</var> <var>X<sub>12</var> <var>Y<sub>12</var>
<var>X<sub>21</var> <var>Y<sub>21</var> <var>X<sub>22</var> <var>Y<sub>22</var>
:
<var>X<sub>N1</var> <var>Y<sub>N1</var> <var>X<sub>N2</var> <var>Y<sub>N2</var>
</pre>
<p>
1行目に線分の数を表す1つの整数<var>N</var>が与えられる。次に線分の情報が<var>N</var>行で与えられる。線分の情報の<var>i</var>行目には4つの整数<var>X<sub>i1</var>, <var>Y<sub>i1</var>, <var>X<sub>i2</var>, <var>Y<sub>i2</var>が空白区切りで与えられる。それぞれ、線分の1つ目の端点のX座標、Y座標、2つ目の端点のX座標、Y座標を表す。
</p>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 150</li>
<li>0 ≤ <var>X<sub>i1</var>, <var>Y<sub>i1</var>, <var>X<sub>i2</var>, <var>Y<sub>i2</var> ≤ 200 (1 ≤ <var>i</var> ≤ <var>N</var>)</li>
<li><var>X<sub>i1</var> = <var>X<sub>i2</var> または <var>Y<sub>i1</var> = <var>Y<sub>i2</var> (1 ≤ <var>i</var> ≤ <var>N</var>)</li>
<li>計算の途中と結果に現れる数は符号付き32ビット整数に収まる</li>
</ul>
<h2>Output</h2>
<p>各ケースの計算結果を一行に出力せよ。</p>
<h2>Sample Input 1</h2>
<pre>
4
1 1 1 5
3 3 5 3
4 2 4 4
7 1 7 5
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
23
1 1 3 1
3 1 3 3
3 3 1 3
1 3 1 5
1 5 3 5
5 2 7 2
7 2 7 4
7 4 5 4
5 4 5 6
5 6 7 6
11 4 13 4
13 0 15 0
15 0 15 4
18 2 18 2
21 5 23 5
21 5 21 7
21 7 23 7
23 7 23 9
23 9 21 9
24 0 26 0
24 0 24 4
24 4 26 4
26 0 26 4
</pre>
<h2>Sample Output 2</h2>
<pre>
-328
</pre>
<h2>Hint</h2>
<ul>
<li>1つのグリッドを2度以上塗りつぶすことがある</li>
<li>'1'など、1つの線分で表すことが可能でも、2つ以上の線分で表す場合がある</li>
</ul>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_sample1.png" alt="Sample Input 1"><br>
Sample Input 1の数式。<br>
<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_CheatCase_sample2.png" alt="Sample Input 2"><br>
Sample Input 2の数式。"-7"の部分のように、ある文字を覆う最小の長方形の内部に別の文字が入り込む場合がある。<br>
</p>
|
p03024 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is competing in a sumo tournament.
The tournament lasts for <var>15</var> days, during which he performs in one match per day.
If he wins <var>8</var> or more matches, he can also participate in the next tournament.</p>
<p>The matches for the first <var>k</var> days have finished.
You are given the results of Takahashi's matches as a string <var>S</var> consisting of <code>o</code> and <code>x</code>.
If the <var>i</var>-th character in <var>S</var> is <code>o</code>, it means that Takahashi won the match on the <var>i</var>-th day; if that character is <code>x</code>, it means that Takahashi lost the match on the <var>i</var>-th day.</p>
<p>Print <code>YES</code> if there is a possibility that Takahashi can participate in the next tournament, and print <code>NO</code> if there is no such possibility.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq k \leq 15</var></li>
<li><var>S</var> is a string of length <var>k</var> consisting of <code>o</code> and <code>x</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if there is a possibility that Takahashi can participate in the next tournament, and print <code>NO</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>oxoxoxoxoxoxox
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>Takahashi has <var>7</var> wins and <var>7</var> losses before the last match. If he wins that match, he will have <var>8</var> wins.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>xxxxxxxx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p01449 |
<H1>Problem 3: 時空のスゴロク・ロード</H1>
<p>
全時空統一ディメンション・スゴロク・トーナメント。500 兆人を超える参加者の中から、ただ1人
のスゴロク絶対王者を決定するその大会に、あなたは21世紀の地球代表として参加している。
</p>
<p>
今あなたが挑戦している課題は、自分自身をコマとした1次元スゴロク。端のスタートマスから出発
して、1から6までの目が一つずつ書かれた巨大な6面ダイスを振って出た目の数だけ進むことを繰
り返す、あなたもよく知っている形式のスゴロクだ。スタートマスとは反対の端にあるゴールマスに
止まるとゴールとなる。もちろん、ゴールするまでにサイコロを振った回数が少なければ少ないほど
良い成績となる。
</p>
<p>
マスの中には特殊な効果を持ったマス「○マス進む」と「○マス戻る」が存在し、そこに止まってし
まうと、指定されたマス数だけ進む、もしくは戻らなければならない。マスの効果で動いた結果、ふ
たたび効果のあるマスに止まった場合は、続けて指示どおりに移動する。
</p>
<p>
しかし、これは一筋縄では攻略できない時空スゴロクだ。恐るべきことに、たとえば「3マス進む」
の3マス先に「3マス戻る」が置かれていることもありうる。このようなマスに止まり、マスの効果
で無限ループに陥ってしまった場合は、永遠にマスを往復し続けなければならない。
</p>
<p>
だが幸いなことに、あなたの身体には、望んだ事象を全事象に変えることのできる異能『確率湾曲』
が宿っている。この能力を使えば、サイコロの出目を自由に操ることも可能。このアドバンテージを
活かして、無限ループに陥らないようにしながら進んでいくとき、ゴールするまでにサイコロを振る
回数の最小値はいくつになるだろうか。
</p>
<H2>Input</H2>
<p>
<i>N</i><br>
<i>p</i><sub>1</sub><br>
<i>p</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>p</i><sub><i>N</i></sub><br>
</p>
<p>
入力の1行目には、整数 <i>N</i>(3 ≤ <i>N</i> ≤ 100,000)が書かれている。これは、スゴロクのマス数をあらわす。マスには1 番から<i>N</i> 番までの番号がふられている。スタートのマスが1 番で、それからスタートに近い順に2 番、3 番、……、<i>N</i> - 1 番と続き、ゴールのマスが<i>N</i> 番である。<i>i</i> 番のマスでサイコロを振ってj の目が出たら、<i>i</i> + <i>j</i> 番のマスへと移動する。ただし、もしも<i>i</i> + <i>j</i> が<i>N</i> を超えていたら、余った数だけ戻ったりはせず、ゴールしたとみなされる。
</p>
<p>
続く<i>N</i> 行には、整数 <i>p<sub>i</sub></i>(-100,000 ≤ <i>p<sub>i</sub></i> ≤ 100,000)が書かれている。1 + <i>i</i> 行目に書かれた整数 <i>p<sub>i</sub></i>
は、i 番のマスに書かれている指示をあらわす。<i>p<sub>i</sub></i> > 0 ならば「<i>p<sub>i</sub></i> マス進む」、<i>p<sub>i</sub></i> < 0 ならば「-<i>p<sub>i</sub></i> マス戻る」であり、<i>p<sub>i</sub></i> = 0 ならばそのマスには何の効果もない。<i>p</i><sub>1</sub> と<i>p<sub>N</sub></i> は必ず0 である。マスの効果で、スタートより前やゴールより後に移動しろと指示されることはない。
</p>
<p>
なお、与えられるスゴロクは、ゴールすることが可能であると仮定してよい。
</p>
<H2>Output</H2>
<p>
ゴールするまでにサイコロを振る回数の最小値を出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
11
0
0
-2
0
-4
1
-1
2
0
0
0
</pre>
<h2>Sample Output 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
12
0
0
7
0
2
0
0
3
-6
-2
1
0
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
<h2>Sample Input 3</h2>
<pre>
8
0
4
-1
1
-2
-2
0
0
</pre>
<h2>Sample Output 3</h2>
<pre>
2
</pre> |
p03474 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The postal code in Atcoder Kingdom is <var>A+B+1</var> characters long, its <var>(A+1)</var>-th character is a hyphen <code>-</code>, and the other characters are digits from <code>0</code> through <code>9</code>.</p>
<p>You are given a string <var>S</var>. Determine whether it follows the postal code format in Atcoder Kingdom.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≤A,B≤5</var></li>
<li><var>|S|=A+B+1</var></li>
<li><var>S</var> consists of <code>-</code> and digits from <code>0</code> through <code>9</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Yes</code> if <var>S</var> follows the postal code format in AtCoder Kingdom; print <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
269-6650
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The <var>(A+1)</var>-th character of <var>S</var> is <code>-</code>, and the other characters are digits from <code>0</code> through <code>9</code>, so it follows the format.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
---
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>S</var> contains unnecessary <code>-</code>s other than the <var>(A+1)</var>-th character, so it does not follow the format.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 2
7444
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p01367 |
<H1><font color="#000">Problem I:</font> Operator</H1>
<p>
The customer telephone support center of the computer sales company called JAG is now in-
credibly confused. There are too many customers who request the support, and they call the
support center all the time. So, the company wants to figure out how many operators needed
to handle this situation.
</p>
<p>
For simplicity, let us focus on the following simple simulation.
</p>
<p>
Let <i>N</i> be a number of customers. The <i>i</i>-th customer has id <i>i</i>, and is described by three numbers,
<i>M<sub>i</sub></i>, <i>L<sub>i</sub></i> and <i>K<sub>i</sub></i>. <i>M<sub>i</sub></i> is the time required for phone support, <i>L<sub>i</sub></i> is the maximum stand by time
until an operator answers the call, and <i>K<sub>i</sub></i> is the interval time from hanging up to calling back.
Let us put these in other words: It takes <i>M<sub>i</sub></i> unit times for an operator to support <i>i</i>-th customer.
If the <i>i</i>-th customer is not answered by operators for <i>L<sub>i</sub></i> unit times, he hangs up the call. <i>K<sub>i</sub></i>
unit times after hanging up, he calls back.
</p>
<p>
One operator can support only one customer simultaneously. When an operator finish a call, he
can immediately answer another call. If there are more than one customer waiting, an operator
will choose the customer with the smallest id.
</p>
<p>
At the beginning of the simulation, all customers call the support center at the same time. The
simulation succeeds if operators can finish answering all customers within <i>T</i> unit times.
</p>
<p>
Your mission is to calculate the minimum number of operators needed to end this simulation
successfully.
</p>
<H2>Input</H2>
<p>
The input contains multiple datasets. Each dataset has the following format:
</p>
<p>
<i>N T</i><br>
<i>M</i><sub>1</sub> <i>L</i><sub>1</sub> <i>K</i><sub>1</sub><br>
.<br>
.<br>
.<br>
<i>M</i><sub><i>N</i></sub> <i>L</i><sub><i>N</i></sub> <i>K</i><sub><i>N</i></sub><br>
</p>
<p>
The first line of a dataset contains two positive integers, <i>N</i> and <i>T</i> (1 ≤ <i>N</i> ≤ 1000, 1 ≤ <i>T</i> ≤ 1000).
<i>N</i> indicates the number of customers in the dataset, and <i>T</i> indicates the time limit of the
simulation.
</p>
<p>
The following <i>N</i> lines describe the information of customers. The <i>i</i>-th line contains three integers,
<i>M<sub>i</sub></i>, <i>L<sub>i</sub></i> and <i>K<sub>i</sub></i> (1 ≤ <i>M<sub>i</sub></i> ≤ <i>T</i> , 1 ≤ <i>L<sub>i</sub></i> ≤ 1000, 1 ≤ <i>K<sub>i</sub></i> ≤ 1000), describing <i>i</i>-th customer's
information. <i>M<sub>i</sub></i> indicates the time required for phone support, Li indicates the maximum stand
by time until an operator answers the call, and Ki indicates the is the interval time from hanging
up to calling back.
</p>
<p>
The end of input is indicated by a line containing two zeros. This line is not part of any dataset
and hence should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the minimum number of operators needed to end the simulation successfully in a line.
</p>
<H2>Sample Input</H2>
<pre>
3 300
100 50 150
100 50 150
100 50 150
3 300
100 50 150
100 50 150
200 50 150
9 18
3 1 1
3 1 1
3 1 1
4 100 1
5 100 1
5 100 1
10 5 3
10 5 3
1 7 1000
10 18
1 2 3
2 3 4
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11
10 11 12
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
3
3
4
</pre>
|
p01737 |
<p>
Ciel, an idol whose appearance and behavior are similar to a fox, is participating in a rehearsal for the live concert which takes place in a few days.
To become a top idol, a large amount of effort is required!
</p>
<p>
The live stage can be expressed as a two-dimensional surface.
The live stage has <var>N</var> spotlights to illuminate the stage.
The <var>i</var>-th spotlight casts a light in the range of a circle with radius <var>r_{i}</var>.
The center of the light cast by the <var>i</var>-th spotlight moves along an orbital path <var>R_{i}</var>.
<var>R_{i}</var> is described as a closed polygon, though <var>R_{i}</var> might contain self-intersections.
The spotlight begins to move from the first vertex of <var>R_{i}</var>.
All of the orbital period of each spotlight are the same.
Each spotlight moves at a constant speed, and all of them return to the starting point at the same time.
</p>
<p>
In the rehearsal, Ciel has to move from the starting point to the ending point indicated on the live stage.
To achieve her goal, it is not allowed to fall out from the area illuminated with the spotlight.
But, she doesn't have to be illuminated with the spotlight as long as she is standing on the starting point.
You may assume that she can move fast enough.
Answer if it is possible for her to move to the ending point.
</p>
<h3>Input</h3>
<p>Each input dataset is given in the following format:
</p><pre>
<var>N</var> <var>sx</var> <var>sy</var> <var>ex</var> <var>ey</var>
<var>r_{1}</var> <var>K_{1}</var> <var>x_{11}</var> <var>y_{11}</var> <var>x_{12}</var> <var>y_{12}</var> ... <var>x_{1K_{1}}</var> <var>y_{1K_{1}}</var>
<var>r_{2}</var> <var>K_{2}</var> <var>x_{21}</var> <var>y_{21}</var> <var>x_{22}</var> <var>y_{22}</var> ... <var>x_{2K_{2}}</var> <var>y_{2K_{2}}</var>
:
:
<var>r_{N}</var> <var>K_{N}</var> <var>x_{N1}</var> <var>y_{N1}</var> <var>x_{N2}</var> <var>y_{N2}</var> ... <var>x_{NK_{N}}</var> <var>y_{NK_{N}}</var>
</pre>
<p>All inputs are integer. All coordinate information satisfies <var>-10,000 \leq x</var>, <var>y \leq 10,000</var>.
<var>N</var> (<var>1 \leq N \leq 100</var>) indicates the number of spotlights. <var>(sx, sy)</var> and <var>(ex, ey)</var> indicate the starting point and the ending point of Ciel's path, respectively.
The following <var>N</var> lines denote the information of each spotlight.
<var>r_{i}</var> (<var>1 \leq r_{i} \leq 100</var>) indicates the radius of the spotlight.
<var>K_{i}</var> (<var>2 \leq K_{i} \leq 10</var>) indicates the number of vertices in the orbital path.
Then, <var>K_{i}</var> vertices are given. Two consecutive vertices on the same orbital path are located at different places.
The spotlight moves from the first point <var>(x_{i1}, y_{i1})</var> to the second point <var>(x_{i2}, y_{i2})</var>, then moves to the third point <var>(x_{i3}, y_{i3})</var>, and so on.
After moving to the <var>K_{i}</var>-th point <var>(x_{iK_{i}}, y_{iK_{i}})</var>, the spotlight returns to the first point <var>(x_{i1}, y_{i1})</var> and repeats again its movement.
</p>
<p>Let <var>d_{ij}</var> be the closest distance between two central points of spotlight <var>i</var> and spotlight <var>j</var>. <var>d_{ij}</var> satisfies either of the following:
</p>
<ul><li> <var>d_{ij} > r_{i} + r_{j} + 0.000001</var>
</li><li> <var>d_{ij} < r_{i} + r_{j} - 0.000001</var>
</li></ul>
<p>Furthermore, let <var>d_{i}</var> be the closest distance between a central point of spotlight <var>i</var> and either the starting point or the ending point. <var>d_{i}</var> satisfies either of the following:
</p>
<ul><li> <var>d_{i} > r_{i} + 0.000001</var>
</li><li> <var>d_{i} < r_{i} - 0.000001</var>
</li></ul>
<h3>Output</h3>
<p>If it is possible for Ciel to move the ending point without falling out from the illuminated area,
output <code>Yes</code> in one line.
Otherwise, output <code>No</code>.
</p>
<h3>Sample Input 1</h3>
<pre>2 1 1 9 -1
2 2 1 1 -9 1
1 2 -1 -1 9 -1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>Yes
</pre>
<h3>Sample Input 2</h3>
<pre>2 1 1 9 -1
2 2 1 1 -9 1
1 2 9 -1 -1 -1
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>No
</pre>
<h3>Sample Input 3</h3>
<pre>2 11 6 -9 1
6 4 10 5 10 0 5 0 5 5
5 4 -10 0 -10 5 -5 5 -5 0
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>Yes
</pre>
<h3>Sample Input 4</h3>
<pre>1 1 9999 -1 0
100 2 0 0 0 10000
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>Yes
</pre> |
p00825 |
<H1><font color="#000">Problem G:</font> Concert Hall Scheduling</H1>
<p>
You are appointed director of a famous concert hall, to save it from bankruptcy. The hall is very
popular, and receives many requests to use its two fine rooms, but unfortunately the previous
director was not very efficient, and it has been losing money for many years. The two rooms are
of the same size and arrangement. Therefore, each applicant wishing to hold a concert asks for
a room without specifying which. Each room can be used for only one concert per day.
</p>
<p>
In order to make more money, you have decided to abandon the previous fixed price policy, and
rather let applicants specify the price they are ready to pay. Each application shall specify a
period [<i>i</i>, <i>j</i>] and an asking price <i>w</i>, where <i>i</i> and <i>j</i> are respectively the first and last days of the
period (1 ≤ <i>i</i> ≤ <i>j</i> ≤ 365), and <i>w</i> is a positive integer in yen, indicating the amount the applicant
is willing to pay to use a room for the whole period.
</p>
<p>
You have received applications for the next year, and you should now choose the applications
you will accept. Each application should be either accepted for its whole period or completely
rejected. Each concert should use the same room during the whole applied period.
</p>
<p>
Considering the dire economic situation of the concert hall, artistic quality is to be ignored,
and you should just try to maximize the total income for the whole year by accepting the most
profitable applications.
</p>
<H2>Input</H2>
<p>
The input has multiple data sets, each starting with a line consisting of a single integer n, the
number of applications in the data set. Then, it is followed by <i>n</i> lines, each of which represents
one application with a period [<i>i</i>, <i>j</i>] and an asking price <i>w</i> yen in the following format.
</p>
<pre><i>
i j w
</i></pre>
<p>
A line containing a single zero indicates the end of the input.
</p>
<p>
The maximum number of applications in a data set is one thousand, and the maximum asking
price is one million yen.
</p>
<H2>Output</H2>
<p>
For each data set, print a single line containing an integer, the maximum total income in yen
for the data set.
</p>
<H2>Sample Input</H2>
<pre>
4
1 2 10
2 3 10
3 3 10
1 3 10
6
1 20 1000
3 25 10000
5 15 5000
22 300 5500
10 295 9000
7 7 6000
8
32 251 2261
123 281 1339
211 235 5641
162 217 7273
22 139 7851
194 198 9190
119 274 878
122 173 8640
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
30
25500
38595
</pre>
|
p02818 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has <var>A</var> cookies, and Aoki has <var>B</var> cookies.
Takahashi will do the following action <var>K</var> times:</p>
<ul>
<li>If Takahashi has one or more cookies, eat one of his cookies.</li>
<li>Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.</li>
<li>If they both have no cookies, do nothing.</li>
</ul>
<p>In the end, how many cookies will Takahashi and Aoki have, respectively?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A \leq 10^{12}</var></li>
<li><var>0 \leq B \leq 10^{12}</var></li>
<li><var>0 \leq K \leq 10^{12}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the numbers of Takahashi's and Aoki's cookies after <var>K</var> actions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0 2
</pre>
<p>Takahashi will do the following:</p>
<ul>
<li>He has two cookies, so he eats one of them.</li>
<li>Now he has one cookie left, and he eats it.</li>
<li>Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.</li>
</ul>
<p>Thus, in the end, Takahashi will have <var>0</var> cookies, and Aoki will have <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>500000000000 500000000000 1000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 0
</pre>
<p>Watch out for overflows.</p></section>
</div>
</span> |
p00576 | <h1>すごろくと駒 (Sugoroku and Pieces)</h1>
<!-- 時間制限 : 2sec / メモリ制限 : 256MB -->
<h2> 問題文</h2>
<p>
JOI 君はすごろくを持っている.このすごろくは <var>2019</var> 個のマスが横一列に並んだ形をしている.これらのマスには,左端のスタートマスから右端のゴールマスへと順に <var>1</var> から <var>2019</var> までの番号がついている.
</p>
<p>
現在このすごろくの上には,<var>N</var> 個の駒が置かれている.これらの駒には,スタートに近い順に <var>1</var> から <var>N</var> までの番号がついている.駒 <var>i</var> (<var>1 ≦ i ≦ N</var>) は,マス <var>X_i</var> に置かれている.すべての駒は異なるマスに置かれている.
</p>
<p>
JOI 君はこれから <var>M</var> 回の操作を行う.<var>j</var> 回目 (<var>1 ≦ j ≦ M</var>) の操作では,駒 <var>A_j</var> を <var>1</var> マス先へ進める.ただし,移動元のマスがゴールマスであった場合,もしくは移動先のマスに別の駒が置かれている場合,駒 <var>A_j</var> は進まず,位置は変わらない.
</p>
<p>
すべての操作が終了した時点で,各駒が置かれているマスを求めよ.
</p>
<h2>制約</h2>
<ul>
<li><var>1 ≦ N ≦ 100</var></li>
<li><var>1 ≦ X_1 < X_2 < ... < X_N ≦ 2019</var></li>
<li><var>1 ≦ M ≦ 100</var></li>
<li><var>1 ≦ A_j ≦ N</var> (<var>1 ≦ j ≦ M</var>)</li>
</ul>
<h2>入力・出力</h2>
<p>
<b>入力</b><br>
入力は以下の形式で標準入力から与えられる.<br>
<var>N</var><br>
<var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var><br>
<var>M</var><br>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var>
</p>
<p>
<b>出力</b><br>
<var>N</var> 行出力せよ.<var>i</var> 行目 (<var>1 ≦ i ≦ N</var>) には,すべての操作が終了した時点で駒 <var>i</var> が置かれているマスの番号を出力せよ.
</p>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>
3
2 3 6
2
1 3
</pre>
<h3>出力例 1</h3>
<pre>
2
3
7
</pre>
<p>
<var>1</var> 回目の操作では,駒 <var>1</var> をマス <var>2</var> からマス <var>3</var> へと進めようする.しかし,駒 <var>2</var> がすでにマス <var>3</var> に置かれているため,駒 <var>1</var> は進まない.
</p>
<p>
<var>2</var> 回目の操作では,駒 <var>3</var> をマス <var>6</var> からマス <var>7</var> へと進める.
</p>
<p>
すべての操作が終了した時点で,駒 <var>1</var> はマス <var>2</var> に,駒 <var>2</var> はマス <var>3</var> に,駒 <var>3</var> はマス <var>7</var> に置かれている.
</p>
<h3>入力例 2</h3>
<pre>
2
1 2016
4
2 2 2 2
</pre>
<h3>出力例 2</h3>
<pre>
1
2019
</pre>
<p>
<var>3</var> 回目の操作が完了した時点で,駒 <var>2</var> はマス <var>2019</var> に置かれている.そのため,<var>4</var> 回目の操作では駒 <var>2</var> は進まない.
</p>
<h3>入力例 3</h3>
<pre>
4
1001 1002 1003 1004
7
1 2 3 4 3 2 1
</pre>
<h3>出力例 3</h3>
<pre>
1002
1003
1004
1005
</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>
|
p00126 |
<h1>パズル</h1>
<p>
たろう君は 9 × 9 のマス目に 1〜9 の数字を配置するパズルで遊んでいます。このパズルでは以下の規則で数字を配置しなければいけません。
</p>
<ul>
<li>同じ列に 1 つの数字はちょうど 1 回だけ現われる</li>
<li>同じ行に 1 つの数字はちょうど 1 回だけ現われる</li>
<li>二重線で区切られた 3 × 3 の各範囲には、1 つの数字はちょうど 1 回だけ現われる</li>
</ul>
<p>
例えば、下の図 1 はそのような規則を満たした配置の一つです。しかしたろう君は、図 2 のようによく規則に反した配置を作ってしまいます。左端の列に「2」が 2 回現われて、「1」が 1 回も現われず、左から2 番目の列に「1」が 2 回現われて、「2」が 1 回も現われていません。
</p>
<center>
<table>
<tr>
<td width="280"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_puzzle1"></td>
<td width="280"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_puzzle2"></td>
</tr>
<tr>
<th>図 1 </th>
<th>図 2 </th>
</tr>
</table>
</center>
<br/>
<p>
たろう君を助けるために、数字の配置を読み込んで、その配置が規則を満たしているかどうかを調べ、規則に反していたらその場所を出力するプログラムを作成してください。3 つの規則に照らして誤っている (2 回以上現れている) 数字の前には * (半角アスタリスク)を、誤っていない数字の前には空白を表示してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットが与えられます。最初の行にデータセットの数 <var>n</var> (<var>n</var> ≤ 20) が与えられます。各データセットとして、パズルの状態を示す 1 行 9 文字、9 行からなる数字列が与えられます。
</p>
<H2>Output</H2>
<p>
各データセットについて以下を出力してください。
</p>
<p>
与えられた数字と * (半角アスタリスク)と空白。誤っている数字の前には *、誤っていない数字の前には半角空白を付加する。
</p>
<p>
データセットの間に 1 行の空行を入れてください。
</p>
<H2>Sample Input</H2>
<pre>
2
2 1 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8
2 1 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8
</pre>
<H2>Output for the Sample Input</H2>
<pre>
*2*1 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
*2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9*1 2 3 4 5 6 7 8
*2*1 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
*2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9*1 2 3 4 5 6 7 8
</pre>
|
p00433 |
<H1>得点</H1>
<h2>問題</h2>
<p>
JOI高校の2人の生徒 A さんと B さんは,情報,数学,理科,英語の4教科の試験を受けた. A さんと B さんのこれら4教科の得点が与えられると, Aさんの合計点 S と Bさんの合計点 T のうち大きな方を出力するプログラムを作成せよ.ただし,同点の場合は S (= T) を出力せよ.
</p>
<H2>入力</H2>
<p>
<!--入力ファイルは2行からなる.-->
入力は2行からなる.
</p>
<p>
1行目は4つの整数が1つの空白を区切りとして書かれており,それぞれ順に, A さんの情報の得点,数学の得点,理科の得点,英語の得点を表している.
</p>
<p>
2行目は4つの整数が1つの空白を区切りとして書かれており,それぞれ順に, B さんの情報の得点,数学の得点,理科の得点,英語の得点を表している.
</p>
<p>
どの教科の得点も100点満点で,負の得点が与えられることはない.
</p>
<H2>出力</H2>
<p>
<!--提出するファイルは, 求める1つの整数からなる.-->
出力は, 求める1つの整数からなる.
</p>
<h2>入出力例</h2>
<h3>入力例1</h3>
<pre>
100 80 70 60
80 70 80 90
</pre>
<h3>出力例1</h3>
<pre>
320
</pre>
<br>
<h3>入力例2</h3>
<pre>
100 80 70 60
80 70 60 100
</pre>
<h3>出力例2</h3>
<pre>
310
</pre>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div> |
p00063 |
<H1>回文</H1>
<p>
半角アルファベット文字列からなる、1 行あたり 100 文字以内のデータがあります。いくつかの行は対称(左端から読んでも右端から読んでも同じ)です。このデータを読み込んで、その中の対称な文字列の数を出力するプログラムを作成してください。なお、1文字だけからなる行は対称であるとします。
</p>
<H2>Input</H2>
<p>
複数の文字列が複数行にわたって与えられます。各行に1つの文字列が与えられます。文字列の数は 50 を超えません。
</p>
<H2>Output</H2>
<p>
対称な文字列の数を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
abcba
sx
abcddcba
rttrd
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
</pre>
|
p00599 |
<H1><font color="#000000">Problem E:</font> Combinatorial Topology </H1>
<p>
It was long believed that a 2-dimensional place can not be filled with a finite set of polygons in aperiodic way. British mathematician, Sir Roger Penrose, developed an aperiodic tiling over the years and established a theory of what is known today as quasicrystals.
</p>
<p>
The classic Penrose tiles consist of two rhombi with angles 36 and 72 degrees, see Figure 1. The edges of the rhombi are all of equal unit length, 1. These can fill the entire place without holes and overlaps (see Figure 2). Example: the bold line boundary in Figure 1 is filled with 20 thin tiles and 20 thick tiles.
</p>
<p>
Given a boundary (set of adjacent vertices counter-clock-wise oriented), how many thin tiles (36 degrees) and how many thick tiles (72 degrees) do you need to fill it (without any holes and intersections)?
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_combinatorialtopology">
</center>
<H2>Input</H2>
<p>
Each data set is defined as follows:
</p>
<p>
<i>Line 1</i>: Number of vertices <i>N</i> (<i>N</i> < 100).
</p>
<p>
<i>N lines</i>: <i>x</i> and <i>y</i> coordinates of each vertex per line separated by blanks (|<i>x</i>| < 100, |<i>y</i>| < 100).
</p>
<p>
All floats in the input have 6 digits after the decimal point.
</p>
<p>
The required precision is 4 digits.
</p>
<p>
Input file includes several data sets. The number of data sets is less than 20.
</p>
<H2>Output</H2>
<p>
Each line contains the solution for one set. First, there is the number of thin tiles, then the number of thick tiles, separated by a space. If the boundary is illegal for the above problem, the output should be "-1 -1".
</p>
<H2>Sample Input</H2>
<pre>
4
-5.000000 0.000000
5.000000 0.000000
9.635255 14.265848
-0.364745 14.265848
3
-1.000000 0.000000
0.000000 0.000000
0.000000 1.000000
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0 150
-1 -1
</pre> |
p01222 |
<H1><font color="#000">Problem G:</font> Walk under a Scorching Sun</H1>
<p>
Edward R. Nelson is visiting a strange town for some task today. This city is built on a two-dimensional
flat ground with several vertical buildings each of which forms a convex polygon when seen from above
on it (that is to say, the buidlings are convex polygon columns). Edward needs to move from the point <i>S</i>
to the point <i>T</i> by walking along the roads on the ground. Since today the sun is scorching and it is very
hot, he wants to walk in the sunshine as less as possible.
</p>
<p>
Your task is to write program that outputs the route whose length in the sunshine is the shortest, given
the information of buildings, roads and the direction of the sun.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets. Each data set is given in the following format:
</p>
<pre>
<i>N M</i>
<i>NV</i><sub>1</sub> <i>H</i><sub>1</sub> <i>X</i><sub>1,1</sub> <i>Y</i><sub>1,1</sub> <i>X</i><sub>1,2</sub> <i>Y</i><sub>1,2</sub> . . . <i>X</i><sub>1,<i>NV</i><sub>1</sub></sub> <i>Y</i><sub>1,<i>NV</i><sub>1</sub></sub>
...
<i>NV</i><sub><i>N</i></sub> <i>H<sub>N</sub></i> <i>X</i><sub><i>N</i>,1</sub> <i>Y</i><sub><i>N</i>,1</sub> <i>X</i><sub><i>N</i>,2</sub> <i>Y</i><sub><i>N</i>,2</sub> . . . <i>X</i><sub><i>N</i>,<i>NV</i><sub><i>N</i></sub></sub> <i>Y</i><sub><i>N</i>,<i>NV</i><sub><i>N</i></sub></sub>
<i>RX</i><sub>1,1</sub> <i>RY</i><sub>1,1</sub> <i>RX</i><sub>1,2</sub> <i>RY</i><sub>1,2</sub>
...
<i>RX</i><sub><i>M</i>,1</sub> <i>RY</i><sub><i>M</i>,1</sub> <i>RX</i><sub><i>M</i>,2</sub> <i>RY</i><sub><i>M</i>,2</sub>
<i>θ φ</i>
<i>SX SY TX TY</i>
</pre>
<p>
All numbers are integers. <i>N</i> is the number of the buildings (1 ≤ <i>N</i> ≤ 15). <i>M</i> is the number of the roads
(1 ≤ <i>M</i> ≤ 15). <i>NV<sub>i</sub></i> is the number of the vertices of the base of the <i>i</i>-th building (3 ≤ <i>NV<sub>i</sub></i> ≤ 10). <i>H<sub>i</sub></i> is the
height of the <i>i</i>-th building. <i>X</i><sub><i>i</i>, <i>j</i></sub> and <i>Y</i><sub><i>i</i>, <i>j</i></sub> are the (<i>x</i>, <i>y</i>)-coordinates of the <i>j</i>-th vertex of the base of the <i>i</i>-th
building. <i>RX</i><sub><i>k</i>,.</sub> and <i>RY</i><sub><i>k</i>,.</sub> are the coordinates of the endpoints of the k-th roads. θ is the direction of the
sun, which is given by a counterclockwise degree which starts in the positive direction of <i>x</i> (0 ≤ θ < 360).
φ is the elevation angle of the sun (0 < φ < 90). (<i>SX</i>, <i>SY</i>) and (<i>TX</i>, <i>TY</i>) are the coordinates of the points
<i>S</i> and <i>T</i>, respectively. All coordinates range from 0 to 1000.
</p>
<p>
The end of the input is represented by a line with <i>N</i> = <i>M</i> = 0. This line should not be processed.
</p>
<p>
It is guaranteed that both the points <i>S</i> and <i>T</i> are on the roads. No pair of an edge of a shade and a road
is parallel. You should assume that the sun is located infinitely far away and that it doesn’t move while
Edward is walking.
</p>
<H2>Output</H2>
<p>
For each data set, output in one line the length for which he has to walk in the sunshine at least. Your
program may output an arbitrary number of digits after the decimal point. However, the error should be
0.001 or less.
</p>
<H2>Sample Input</H2>
<pre>
1 1
4 10 0 0 10 0 10 10 0 10
-5 -20 30 15
135 45
0 -15 15 0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
11.213
</pre>
|
p04020 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a large collection of cards. Each card has an integer between <var>1</var> and <var>N</var>, inclusive, written on it.
He has <var>A_i</var> cards with an integer <var>i</var>.</p>
<p>Two cards can form a pair if the absolute value of the difference of the integers written on them is at most <var>1</var>.</p>
<p>Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.</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 (1 ≦ i ≦ 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>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 maximum number of pairs that Snuke can create.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
4
0
3
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, Snuke can create the following four pairs: <var>(1,1),(1,1),(3,4),(3,4)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
2
0
1
6
0
8
2
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre></section>
</div>
</span> |
p01672 |
<h2>F - Point Distance</h2>
<h3>Problem Statement</h3>
<p>
You work for invention center as a part time programmer. This center researches movement of protein molecules. It needs how molecules make clusters, so it will calculate distance of all pair molecules and will make a histogram.
Molecules’ positions are given by a <var>N</var> x <var>N</var> grid map.
Value <var>C_{xy}</var> of cell <var>(x, y)</var> in a grid map means that <var>C_{xy}</var> molecules are in the position <var>(x, y)</var>.
</p>
<p>
You are given a grid map, please calculate histogram of all pair molecules.
</p>
<h3>Input</h3>
<p>
Input is formatted as follows.
</p>
<pre>
<var>N</var>
<var>C_{11}</var> <var>C_{12}</var> ... <var>C_{1N}</var>
<var>C_{21}</var> <var>C_{22}</var> ... <var>C_{2N}</var>
...
<var>C_{N1}</var> <var>C_{N2}</var> ... <var>C_{NN}</var>
</pre>
<p>
First line contains the grid map size <var>N</var> (<var>1 \leq N \leq 1024</var>).
Each next <var>N</var> line contains <var>N</var> numbers.
Each numbers <var>C_{xy}</var> (<var>0 \leq C_{xy} \leq 9</var>) means the number of molecule in position (x,y).
There are at least 2 molecules.
</p>
<h3>Output</h3>
<p>
Output is formatted as follows.
</p>
<pre>
<var>D_{ave}</var>
<var>d_{1}</var> <var>c_{1}</var>
<var>d_{2}</var> <var>c_{2}</var>
...
<var>d_{m}</var> <var>c_{m}</var>
</pre>
<p>
Print <var>D_{ave}</var> which an average distance of all pair molecules on first line.
Next, print histogram of all pair distance.
Each line contains a distance <var>d_i</var> and the number of pair molecules <var>c_i(0 \lt c_i)</var>.
The distance <var>d_i</var> should be calculated by squared Euclidean distance and sorted as increasing order.
If the number of different distance is more than 10,000, please show the first 10,000 lines.
The answer may be printed with an arbitrary number of decimal digits, but may not contain an absolute or relative error greater than or equal to <var>10^{-8}</var>.
</p>
<h3>Sample Input 1</h3>
<pre>
2
1 0
0 1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
1.4142135624
2 1
</pre>
<h3>Sample Input 2</h3>
<pre>
3
1 1 1
1 1 1
1 1 1
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
1.6349751825
1 12
2 8
4 6
5 8
8 2
</pre>
<h3>Sample Input 3</h3>
<pre>
5
0 1 2 3 4
5 6 7 8 9
1 2 3 2 1
0 0 0 0 0
0 0 0 0 1
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
1.8589994382
0 125
1 379
2 232
4 186
5 200
8 27
9 111
10 98
13 21
16 50
17 37
18 6
20 7
25 6
</pre> |
p00960 |
<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 D
Making Perimeter of the Convex Hull Shortest
</h2>
<p>
The convex hull of a set of three or more planar points is, when not all of them are on one line, the convex polygon with the smallest area that has all the points of the set on its boundary or in its inside. Your task is, given positions of the points of a set, to find how much shorter the perimeter of the convex hull can be made by excluding <i>two</i> points from the set.
</p>
<p>
The figures below correspond to the three cases given as Sample Input 1 to 3. Encircled points are excluded to make the shortest convex hull depicted as thick dashed lines.
</p>
<table>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_convexHullShortest1" width="240"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_convexHullShortest2" width="240"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_convexHullShortest3" width="240"></td>
</tr>
<tr>
<td style="text-align:center">Sample Input 1</td>
<td style="text-align:center">Sample Input 2</td>
<td style="text-align:center">Sample Input 3</td>
</tr>
</table>
<h3>Input</h3>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$n$
$x_1$ $y_1$
...
$x_n$ $y_n$
</pre>
<p>
Here, $n$ is the number of points in the set satisfying $5 \leq n \leq 10^5$. For each $i$, ($x_i, y_i$) gives the coordinates of the position of the $i$-th point in the set. $x_i$ and $y_i$ are integers between $-10^6$ and $10^6$, inclusive. All the points in the set are distinct, that is, $x_j \ne x_k$ or $y_j \ne y_k$ holds when $j \ne k$. It is guaranteed that no single line goes through $n - 2$ or more points in the set.
</p>
<h3>Output</h3>
<p>
Output the difference of the perimeter of the convex hull of the original set and the shortest of the perimeters of the convex hulls of the subsets with two points excluded from the original set. The output should not have an error greater than $10^{-4}$.
</p>
<h3>Sample Input 1</h3>
<pre>
10
-53 62
-19 58
-11 11
-9 -22
45 -7
37 -39
47 -58
-2 41
-37 10
13 42
</pre>
<h3>Sample Output 1</h3>
<pre>
72.96316928
</pre>
<h3>Sample Input 2</h3>
<pre>
10
-53 62
-19 58
-11 11
-9 -22
45 -7
43 -47
47 -58
-2 41
-37 10
13 42
</pre>
<h3>Sample Output 2</h3>
<pre>
62.62947992
</pre>
<h3>Sample Input 3</h3>
<pre>
10
-53 62
-35 47
-11 11
-9 -22
45 -7
43 -47
47 -58
-2 41
-37 10
13 42
</pre>
<h3>Sample Output 3</h3>
<pre>
61.58166534
</pre> |
p01388 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">問題 A </font> KUPC</h1>
<h2>問題文</h2>
<p>とある学生が,Kyoto University Programming Contest (KUPC) を開こうと考えた.そこで彼は,看板を作って皆に宣伝することにした.今,手元にはアルファベット <var>1</var> 文字の書かれた板がいくつもある.これらの板から <tt>'K'</tt>,<tt>'U'</tt>,<tt>'P'</tt>,<tt>'C'</tt> という文字の書かれた <var>4</var> 枚の板を選ぶことで看板を 1 つ作成できる.この作業を繰り返すことで,沢山の看板を作成できるはずである.さて,与えられた板を使って,最終的に何枚の KUPC と書かれた看板が得られるだろうか?
</p>
<h2>入力形式</h2>
<p>文字列が <var>1</var> 行で与えられる.文字列の各文字は,各板に書かれている文字を表す.</br></p>
<h2>出力形式</h2>
<p>KUPC という看板が何枚作成できるかを計算し,その数を <var>1</var> 行に出力せよ.</p>
<h2>制約</h2>
<ul>
<li>文字列はアルファベットのみからなる.</li>
<li>文字列の長さは <var>300</var> 以内である.</li>
</ul>
<h2>入出力例</h2>
<h3>入力例 1</h3>
<pre>KUPCkupcKUPC</pre>
<h3>出力例1</h3>
<pre>2</pre>
<h3>入力例 2</h3>
<pre>UNPACK</pre>
<h3>出力例 2</h3>
<pre>1</pre>
<h3>入力例 3</h3>
<pre>KkKUUuPPPCCC</pre>
<h3>出力例 3</h3>
<pre>2</pre> |
p02377 |
<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>
<H1>Minimum Cost Flow</H1>
<p>
Find the minimum cost to send a certain amount of flow through a flow network.
</p>
<p>
The flow network is a directed graph where each edge $e$ has capacity $c(e)$ and cost $d(e)$. Each edge $e$ can send an amount of flow $f(e)$ where $f(e) \leq c(e)$. Find the minimum value of $\sum_{e} (f(e) \times d(e))$ to send an amount of flow $F$ from source $s$ to sink $t$.
</p>
<H2>Input</H2>
<p>
A flow network $G(V,E)$ is given in the following format.
</p>
<p>
$|V|\;|E|\;F$<br>
$u_0\;v_0\;c_0\;d_0$<br>
$u_1\;v_1\;c_1\;d_1$<br>
:<br>
$u_{|E|1}\;v_{|E|-1}\;c_{|E|-1}\;d_{|E|-1}$<br>
</p>
<p>
$|V|$, $|E|$, $F$ are the number of vertices, the number of edges, and the amount of flow 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$, $d_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$ and $d_i$ are the capacity and the cost of $i$-th edge respectively.
</p>
<H2>Output</H2>
<p>
Print the minimum value in a line. If it is impossible to send the flow from the source $s$ to the sink $t$, print <span>-1</span>.
</p>
<h2>Constraints</h2>
<ul>
<li> 2 ≤ $|V|$ ≤ 100</li>
<li> 1 ≤ $|E|$ ≤ 1000</li>
<li> 0 ≤ $F$ ≤ 1000</li>
<li> 0 ≤ $c_i$, $d_i$ ≤ 1000</li>
<li> $u_i$ $\ne$ $v_i$</li>
<li> If there is an edge from vertex $x$ to vertex $y$, there is no edge from vertex $y$ to vertex $x$.</li>
</ul>
<H2>Sample Input</H2>
<pre>
4 5 2
0 1 2 1
0 2 1 2
1 2 1 1
1 3 1 3
2 3 2 1
</pre>
<H2>Sample Output</H2>
<pre>
6
</pre>
|
p01808 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<!-- begin en only -->
<h3><u>Kuru Kuru Door</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>くるくるドア</u></h3>
<!-- end ja only -->
<!-- end en only -->
<!-- begin ja only -->
<p>ACM (Automatic Cleaning Machine) 社が2011年に開発した全自動円形掃除機 ICPC (Intelligent Circular Perfect Cleaner) は,
日中に自動で動き出し,自分が通り過ぎた場所のゴミを掃除する機能を備えている.
加えて,この ICPC は,バッテリー残量が低下した場合に自動的に電源の位置まで戻る機能も備えている.
</p>
<p>この度,JAG (Japan Alumni Group) と名乗る謎の組織から, ACM 社に対し大量の ICPC の発注があった.
しかし,その発注には条件が付いていた.
それは,彼らが本拠地としているビルの内部にある「くるくるドア」に ICPC を対応させることである.
くるくるドアは,以下に述べるように平面上の物体としてモデル化されている.
</p>
<p>くるくるドアは,原点で接続された長さ <var>R</var> の 2<var>n</var> (≥ 4) 枚のドアの組として表される.
これらのドアは,角度 π/<var>n</var> おきに並んでいる.
くるくるドアは手動であり,ドアのどこに触れても触れた方向( ICPC との重なりが解消される方向)へ原点中心に一斉に回転させることができるが,
平行移動させることはできない.
初期状態では,ドアのちょうど2枚が <var>y</var> 軸に平行である.
</p>
<p>また,原点を中心とする半径 <var>R</var> の円のうち,<var>y</var> 座標の絶対値が <var>R</var>sin(π/(2<var>n</var>)) 以上である部分および,
<var>y</var> 軸上で <var>y</var> 座標の絶対値が <var>R</var> 以上の部分は壁になっている.
これらの壁は押すことができない.
</p>
<p>平面上で ICPC は半径 <var>r</var> の円として表される.
ICPC の電源は点 <var>T</var> = (<var>x<sub>t</sub></var>, <var>y<sub>t</sub></var>) にあり, ICPC はその中心座標が電源の位置に重なっている時バッテリーを充電することができる.
はじめに ICPC の中心座標が点 <var>S</var> = (<var>x<sub>s</sub></var>, <var>y<sub>s</sub></var>) となる位置にあるとき,
電源の位置まで ICPC が最短経路を通って戻れるようにすることが, JAG から出された ICPC 発注の条件である.
なお, ICPC がくるくるドアに対して正確な挙動を行うことを確かめるために, ICPC の初期位置と電源の位置は,くるくるドアを挟んで反対側となるように与えられる.
ACM 社は,凄腕プログラマーのあなたに,くるくるドアの寸法, ICPC の中心座標 <var>S</var> と半径,電源の位置 <var>T</var> が与えられたとき,ICPCが電源の位置へ到達できるかを判定し,到達可能な場合は ICPC の中心座標が移動する最短経路の長さを求めるプログラムの作成を依頼した.
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>入力は,複数のデータセットから構成され,1つの入力に含まれるデータセットの数は60個以下である.
各データセットの形式は次の通りである.
</p>
<blockquote><var>n</var><br><var>r</var> <var>R</var><br><var>x<sub>s</sub></var> <var>y<sub>s</sub></var><br><var>x<sub>t</sub></var> <var>y<sub>t</sub></var></blockquote>
<p><var>n</var> はくるくるドアを構成するドアの枚数の半分を表す整数であり,2 ≤ <var>n</var> ≤ 10 と仮定して良い.
<var>r</var>, <var>R</var> はそれぞれ ICPC の半径,くるくるドアの一枚あたりの長さを表す整数であり,1以上10以下と仮定して良い.
</p>
<p>(<var>x<sub>s</sub></var>, <var>y<sub>s</sub></var>) は ICPC の初期位置の中心座標,(<var>x<sub>t</sub></var>, <var>y<sub>t</sub></var>) は電源の位置を表す.
<var>x<sub>s</sub></var> , <var>y<sub>s</sub></var> , <var>x<sub>t</sub></var> , <var>y<sub>t</sub></var> はそれぞれ整数であり,-1,000 ≤ <var>x<sub>s</sub></var> ≤ - <var>r</var> - 1, -1,000 ≤ <var>y<sub>s</sub></var> ≤ 1,000, <var>r</var> + 1 ≤ <var>x<sub>t</sub></var> ≤ 1,000, -1,000 ≤ <var>y<sub>t</sub></var> ≤ 1,000 を満たすと仮定して良い.
加えて,点 (<var>x<sub>s</sub></var>, <var>y<sub>s</sub></var>), (<var>x<sub>t</sub></var>, <var>y<sub>t</sub></var>) はそれぞれ原点から距離 <var>R</var> + <var>r</var> + 10<sup>-6</sup> 以上離れていると仮定して良い.
すなわち, ICPC と電源は初期状態でいずれもくるくるドアの外側にあり,互いにくるくるドアを挟んで反対側に位置している.
</p>
<p>また,<var>r</var> および <var>R</var> が 10<sup>-6</sup> だけ変化しても, ICPC の電源位置への到達可能性は変わらないと仮定して良い.
</p>
<p>入力の終わりは1つのゼロだけからなる行で示される.
</p>
<p>下図は後に示す Sample Input 中の最初のデータセットにおける, ICPC の初期位置 <var>S</var> ,電源位置 <var>T</var> ,くるくるドアおよび壁の配置を表している.
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2015_sample" height="330" width="359" />
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>各データセットについて, ICPC が電源の位置に到達できる場合は,電源の位置までの移動距離の最小値を1行に出力せよ.
この場合,出力の絶対誤差は 10<sup>-6</sup> 以内でなくてはならない.
到達できない場合は,-1 を1行に出力せよ.
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>3
1 4
-5 5
5 -5
10
1 10
-10 5
5 -10
5
3 5
-20 0
20 0
8
1 9
-14 58
6 24
2
2 8
-57 -113
42 -31
4
1 4
-4 -5
4 5
0</pre>
<h3>Output for Sample Input</h3>
<pre>17.5032106371
41.3850388846
-1
102.0656847372
178.1399151364
19.5548716821</pre>
|
p03835 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two integers <var>K</var> and <var>S</var>.<br/>
Three variable <var>X, Y</var> and <var>Z</var> takes integer values satisfying <var>0≤X,Y,Z≤K</var>.<br/>
How many different assignments of values to <var>X, Y</var> and <var>Z</var> are there such that <var>X + Y + Z = S</var>? </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≤K≤2500</var> </li>
<li><var>0≤S≤3K</var> </li>
<li><var>K</var> and <var>S</var> are integers. </li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>K</var> <var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the triples of <var>X, Y</var> and <var>Z</var> that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six triples of <var>X, Y</var> and <var>Z</var> that satisfy the condition:</p>
<ul>
<li><var>X = 0, Y = 0, Z = 2</var> </li>
<li><var>X = 0, Y = 2, Z = 0</var> </li>
<li><var>X = 2, Y = 0, Z = 0</var> </li>
<li><var>X = 0, Y = 1, Z = 1</var> </li>
<li><var>X = 1, Y = 0, Z = 1</var> </li>
<li><var>X = 1, Y = 1, Z = 0</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>The maximum value of <var>X + Y + Z</var> is <var>15</var>, achieved by one triple of <var>X, Y</var> and <var>Z</var>.</p></section>
</div>
</span> |
p02727 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are going to eat <var>X</var> red apples and <var>Y</var> green apples.<br/>
You have <var>A</var> red apples of deliciousness <var>p_1,p_2, \dots, p_A</var>, <var>B</var> green apples of deliciousness <var>q_1,q_2, \dots, q_B</var>, and <var>C</var> colorless apples of deliciousness <var>r_1,r_2, \dots, r_C</var>.<br/>
Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.<br/>
From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.<br/>
Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X \leq A \leq 10^5</var></li>
<li><var>1 \leq Y \leq B \leq 10^5</var></li>
<li><var>1 \leq C \leq 10^5</var></li>
<li><var>1 \leq p_i \leq 10^9</var></li>
<li><var>1 \leq q_i \leq 10^9</var></li>
<li><var>1 \leq r_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var> <var>A</var> <var>B</var> <var>C</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_A</var>
<var>q_1</var> <var>q_2</var> <var>...</var> <var>q_B</var>
<var>r_1</var> <var>r_2</var> <var>...</var> <var>r_C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the deliciousness of the eaten apples.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 2 2 1
2 4
5 1
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:</p>
<ul>
<li>Eat the <var>2</var>-nd red apple.</li>
<li>Eat the <var>1</var>-st green apple.</li>
<li>Paint the <var>1</var>-st colorless apple green and eat it.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 2 2 2
8 6
9 1
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>25
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>74
</pre></section>
</div>
</span> |
p03566 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called <em>AtCoder Express</em>.</p>
<p>In the plan developed by the president Takahashi, the trains will run as follows:</p>
<ul>
<li>A train will run for <var>(t_1 + t_2 + t_3 + ... + t_N)</var> seconds.</li>
<li>In the first <var>t_1</var> seconds, a train must run at a speed of at most <var>v_1</var> m/s (meters per second). Similarly, in the subsequent <var>t_2</var> seconds, a train must run at a speed of at most <var>v_2</var> m/s, and so on.</li>
</ul>
<p>According to the specifications of the trains, the acceleration of a train must be always within <var>±1m/s^2</var>. Additionally, a train must stop at the beginning and the end of the run.</p>
<p>Find the maximum possible distance that a train can cover in the run.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq t_i \leq 200</var></li>
<li><var>1 \leq v_i \leq 100</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>t_1</var> <var>t_2</var> <var>t_3</var> … <var>t_N</var>
<var>v_1</var> <var>v_2</var> <var>v_3</var> … <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible that a train can cover in the run.<br/>
Output is considered correct if its absolute difference from the judge's output is at most <var>10^{-3}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
100
30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2100.000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/69c1f4241b608bc36f1f08dd4184d3f0.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>30</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>450</var> meters.</li>
<li>In the subsequent <var>40</var> seconds, it maintains the velocity of <var>30m/s</var>, covering <var>1200</var> meters.</li>
<li>In the last <var>30</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>450</var> meters.</li>
</ul>
<p>The total distance covered is <var>450</var> + <var>1200</var> + <var>450</var> = <var>2100</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
60 50
34 38
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2632.000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/a3e07ea723f50df04461165bc2cc8890.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>34</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>578</var> meters.</li>
<li>In the subsequent <var>26</var> seconds, it maintains the velocity of <var>34m/s</var>, covering <var>884</var> meters.</li>
<li>In the subsequent <var>4</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>144</var> meters.</li>
<li>In the subsequent <var>8</var> seconds, it maintains the velocity of <var>38m/s</var>, covering <var>304</var> meters.</li>
<li>In the last <var>38</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>722</var> meters.</li>
</ul>
<p>The total distance covered is <var>578</var> + <var>884</var> + <var>144</var> + <var>304</var> + <var>722</var> = <var>2632</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
12 14 2
6 2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>76.000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/77f821f590cb19d8e449303a102422dc.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>6</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>18</var> meters.</li>
<li>In the subsequent <var>2</var> seconds, it maintains the velocity of <var>6m/s</var>, covering <var>12</var> meters.</li>
<li>In the subsequent <var>4</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>16</var> meters.</li>
<li>In the subsequent <var>14</var> seconds, it maintains the velocity of <var>2m/s</var>, covering <var>28</var> meters.</li>
<li>In the last <var>2</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>2</var> meters.</li>
</ul>
<p>The total distance covered is <var>18</var> + <var>12</var> + <var>16</var> + <var>28</var> + <var>2</var> = <var>76</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
9
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>20.250000000000000000
</pre>
<p><img alt=" " src="https://img.atcoder.jp/abc076/ebde8cbeb649ae7fd338180c0562ae0b.png"/></p>
<p>The maximum distance is achieved when a train runs as follows:</p>
<ul>
<li>In the first <var>4.5</var> seconds, it accelerates at a rate of <var>1m/s^2</var>, covering <var>10.125</var> meters.</li>
<li>In the last <var>4.5</var> seconds, it decelerates at the acceleration of <var>-1m/s^2</var>, covering <var>10.125</var> meters.</li>
</ul>
<p>The total distance covered is <var>10.125</var> + <var>10.125</var> = <var>20.25</var> meters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>10
64 55 27 35 76 119 7 18 49 100
29 19 31 39 27 48 41 87 55 70
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>20291.000000000000
</pre></section>
</div>
</span> |
p03136 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Determine if an <var>N</var>-sided polygon (not necessarily convex) with sides of length <var>L_1, L_2, ..., L_N</var> can be drawn in a two-dimensional plane.</p>
<p>You can use the following theorem:</p>
<p><strong>Theorem</strong>: an <var>N</var>-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other <var>N-1</var> sides.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>3 \leq N \leq 10</var></li>
<li><var>1 \leq L_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>L_1</var> <var>L_2</var> <var>...</var> <var>L_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If an <var>N</var>-sided polygon satisfying the condition can be drawn, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 8 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Since <var>8 < 9 = 3 + 5 + 1</var>, it follows from the theorem that such a polygon can be drawn on a plane.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
3 8 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>Since <var>8 \geq 8 = 3 + 4 + 1</var>, it follows from the theorem that such a polygon cannot be drawn on a plane.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1 8 10 5 8 12 34 100 11 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p03423 | <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> students in a school.</p>
<p>We will divide these students into some groups, and in each group they will discuss some themes.</p>
<p>You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.</p>
<p>Divide the students so that the number of groups consisting of three or more students is maximized.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1000</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If you can form at most <var>x</var> groups consisting of three or more students, print <var>x</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, you can form a group of three students and another of five students.</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>0
</pre>
<p>Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p03589 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>.</p>
<p>Find a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> such that <var>4/N = 1/h + 1/n + 1/w</var>.</p>
<p>If there are multiple solutions, any of them will be accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>It is guaranteed that, for the given integer <var>N</var>, there exists a solution such that <var>h,n,w \leq 3500</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> that satisfies the condition, in the following format:</p>
<pre><var>h</var> <var>n</var> <var>w</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 2
</pre>
<p><var>4/2 = 1/1 + 1/2 + 1/2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3485
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>872 1012974 1539173474040
</pre>
<p>It is allowed to use an integer exceeding <var>3500</var> in a solution.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4664
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3498 3498 3498
</pre></section>
</div>
</span> |
p03073 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> tiles are arranged in a row from left to right. The initial color of each tile is represented by a string <var>S</var> of length <var>N</var>.</p>
<p>The <var>i</var>-th tile from the left is painted black if the <var>i</var>-th character of <var>S</var> is <code>0</code>, and painted white if that character is <code>1</code>.</p>
<p>You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.</p>
<p>At least how many tiles need to be repainted to satisfy the condition?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</var></li>
<li><var>S_i</var> is <code>0</code> or <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of tiles that need to be repainted to satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The condition can be satisfied by repainting the middle tile white.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10010010
</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>0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p02232 | <a href="https://onlinejudge.u-aizu.ac.jp/resources/icpcooc2018/A.pdf" target='_blank'>Problem is available from here.</a> |
p02398 |
<H1>How Many Divisors?</H2>
<p>
Write a program which reads three integers <var>a</var>, <var>b</var> and <var>c</var>, and prints the number of divisors of <var>c</var> between <var>a</var> and <var>b</var>.
</p>
<H2>Input</H2>
<p>
Three integers <var>a</var>, <var>b</var> and <var>c</var> are given in a line separated by a single space.
</p>
<H2>Output</H2>
<p>
Print the number of divisors in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>a</var>, <var>b</var>, <var>c</var> ≤ 10000</li>
<li> <var>a</var> ≤ <var>b</var></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5 14 80
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre> |
p03970 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.</p>
<p>He intended to write <code>CODEFESTIVAL2016</code> on it, but he mistakenly wrote a different string <var>S</var>. Fortunately, the string he wrote was the correct length.</p>
<p>So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to <code>CODEFESTIVAL2016</code>.</p>
<p>Find the minimum number of iterations for the rewrite operation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is <var>16</var> characters long.</li>
<li><var>S</var> consists of uppercase and lowercase alphabet letters and numerals.</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>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Output an integer representing the minimum number of iterations needed for the rewrite operation.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>C0DEFESTIVAL2O16
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The second character <code>0</code> must be changed to <code>O</code> and the <var>14</var>th character <code>O</code> changed to <code>0</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>FESTIVAL2016CODE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>16
</pre></section>
</div>
</span> |
p02662 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are a sequence of <var>N</var> positive integers <var>A_1</var>, <var>A_2</var>, <var>\ldots</var>, <var>A_N</var> and another positive integer <var>S</var>.<br/>
For a non-empty subset <var>T</var> of the set <var>\{1, 2, \ldots , N \}</var>, let us define <var>f(T)</var> as follows:<br/></p>
<ul>
<li><var>f(T)</var> is the number of different non-empty subsets <var>\{x_1, x_2, \ldots , x_k \}</var> of <var>T</var> such that <var>A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S</var>.</li>
</ul>
<p>Find the sum of <var>f(T)</var> over all <var>2^N-1</var> subsets <var>T</var> of <var>\{1, 2, \ldots , N \}</var>. Since the sum can be enormous, print it modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 3000</var></li>
<li><var>1 \leq S \leq 3000</var></li>
<li><var>1 \leq A_i \leq 3000</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>S</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of <var>f(T)</var> modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
2 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>For each <var>T</var>, the value of <var>f(T)</var> is shown below. The sum of these values is <var>6</var>.</p>
<ul>
<li><var>f(\{1\}) = 0</var></li>
<li><var>f(\{2\}) = 0</var></li>
<li><var>f(\{3\}) = 1</var> (One subset <var>\{3\}</var> satisfies the condition.)</li>
<li><var>f(\{1, 2\}) = 1</var> (<var>\{1, 2\}</var>)</li>
<li><var>f(\{2, 3\}) = 1</var> (<var>\{3\}</var>)</li>
<li><var>f(\{1, 3\}) = 1</var> (<var>\{3\}</var>)</li>
<li><var>f(\{1, 2, 3\}) = 2</var> (<var>\{1, 2\}, \{3\}</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 8
9 9 9 9 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10
3 1 4 1 5 9 2 6 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3296
</pre></section>
</div>
</span> |
p00130 |
<h1>列車</h1>
<p>
26 両以下の編成の列車があります。それぞれの車両には、英小文字の a から z までの識別記号が付いています。同じ記号が付いている車両はありません。ただし、車両を連結する順番は自由とします。列車の中を車掌が巡回します。車掌は、列車の中を行ったり来たりして巡回するので、同じ車両を何度も通ることがあります。ただし、すべての車両を最低一回は巡回するものとします。また、巡回をはじめる車両や巡回を終える車両が列車の一番端の車両とは限りません。
</p>
<p>
ある車掌が乗ったすべての列車の巡回記録があります。そこから分かる各列車の編成を先頭車両から出力するプログラムを作成してください。巡回記録は 1 行が 1 つの列車に対応します。各行は、英小文字を 1 文字ずつ <span><-</span> または <span>-></span> で区切った文字列でできています。<span><-</span> は前方の車両への移動、<span>-></span> は後方の車両への移動を表します。
</p>
<p>
例えば、<span>a->b<-a<-c</span> は車両 a から後方の車両である b に移り、b から前方の a に移り、a から前方の c へ移ったことを表します。この場合の列車の編成は先頭車両から <span>cab</span> となります。
</p>
<H2>Input</H2>
<p>
1行目に巡回記録の個数 <var>n</var> (<var>n</var> ≤ 50)、続く <var>n</var> 行に巡回記録 <var>i</var> を表す文字列 <var>s<sub>i</sub></var> (1024文字までの半角文字列) が与えられます。
</p>
<H2>Output</H2>
<p>
巡回記録 <var>i</var> について、先頭車両からの列車の編成を現す文字列を <var>i</var> 行目に出力してください。
</p>
<H2>Sample Input</H2>
<pre>
4
a->e->c->b->d
b<-c<-a<-d<-e
b->a->c<-a->c->d<-c<-a<-b->a->c->d->e<-d
a->e<-a<-d->a->e<-a<-d<-c->d->a<-d<-c<-b->c->d<-c
</pre>
<H2>Output for the Sample Input</H2>
<pre>
aecbd
edacb
bacde
bcdae
</pre>
|
p00560 |
<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>Semiexpress</h1>
<p>
The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one is express and the other one is local.
</p>
<p>
A local train stops at every station. For each $i$ ($1 \leq i < N$), by a local train, it takes $A$ minutes from the station $i$ to the station ($i + 1$).
</p>
<p>
An express train stops only at the stations $S_1, S_2, ..., S_M$ ($1 = S_1 < S_2 < ... < S_M = N$). For each $i$ ($1 \leq i < N$), by an express train, it takes $B$ minutes from the station $i$ to the station ($i + 1$).
</p>
<p>
The JOI Railways plans to operate another kind of trains called "semiexpress." For each $i$ ($1 \leq i < N$), by a semiexpress train, it takes $C$ minutes from the station $i$ to the station ($i + 1$). The stops of semiexpress trains are not yet determined. But they must satisfy the following conditions:
</p>
<ul>
<li> Semiexpress trains must stop at every station where express trains stop.</li>
<li> Semiexpress trains must stop at $K$ stations exactly.</li>
</ul>
<p>
The JOI Railways wants to maximize the number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes. The JOI Railways plans to determine the stops of semiexpress trains so that this number is maximized. We do not count the standing time of trains.
</p>
<p>
When we travel from the station 1 to another station, we can take trains only to the direction where the numbers of stations increase. If several kinds of trains stop at the station $i$ ($2 \leq i \leq N - 1$), you can transfer between any trains which stop at that station.
</p>
<p>
When the stops of semiexpress trains are determined appropriately, what is the maximum number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes?
</p>
<h3>Task</h3>
<p>
Given the number of stations of the JOI Railways, the stops of express trains, the speeds of the trains, and maximum travel time, write a program which calculates the maximum number of stations which satisfy the condition on the travel time.
</p>
<h3>Input</h3>
<p>
Read the following data from the standard input.
</p>
<ul>
<li> The first line of input contains three space separated integers $N$, $M$, $K$. This means there are $N$ stations of the JOI Railways, an express train stops at $M$ stations, and a semiexpress train stops at $K$ stations,</li>
<li>The second line of input contains three space separated integers $A$, $B$, $C$. This means it takes $A$, $B$, $C$ minutes by a local, express, semiexpress train to travel from a station to the next station, respectively.</li>
>li> The third line of input contains an integer $T$. This means the JOI Railways wants to maximize the number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes.</li>
<li> The $i$-th line ($1 \leq i \leq M$) of the following $M$ lines contains an integer $S_i$. This means an express train stops at the station $S_i$.</li>
</ul>
<h3>Output</h3>
<p>
Write one line to the standard output. The output contains the maximum number of stations satisfying the condition on the travel time.
</p>
<h3>Constraints</h3>
<p>
All input data satisfy the following conditions.
</p>
<ul>
<li>$2 \leq N \leq 1 000 000 000.$</li>
<li>$2 \leq M \leq K \leq 3 000.$</li>
<li>$K \leq N.$</li>
<li>$1 \leq B < C < A \leq 1 000 000 000.$</li>
<li>$1 \leq T \leq 10^{18}$</li>
<li>$1 = S_1 < S_2 < ... < S_M = N$</li>
</ul>
<h3>Sample Input and Output</h3>
<h3>Sample Input 1</h3>
<pre>
10 3 5
10 3 5
30
1
6
10
</pre>
<h3>Sample Output 1</h3>
<pre>
8
</pre>
<p>
In this sample input, there are 10 stations of the JOI Railways. An express train stops at three stations 1, 6, 10. Assume that the stops of an semiexpress train are 1, 5, 6, 8, 10. Then, among the stations 2, 3, ...10, we can travel from the station 1 to every station except for the station 9 within 30 minutes.
</p>
<p>
For some $i$, the travel time and the route from the station 1 to the station $i$ are as follows:
</p>
<ul>
<li>From the station 1 to the station 3, we can travel using a local train only. The travel time is 20 minutes.</li>
<li> From the station 1 to the station 7, we travel from the station 1 to the station 6 by an express train, and transfer to a local train. The travel time is 25 minutes.</li>
<li> From the station 1 to the station 8, we travel from the station 1 to the station 6 by an express train, and transfer to a semiexpress train. The travel time is 25 minutes.</li>
<li> From the station 1 to the station 9, we travel from the station 1 to the station 6 by an express train, from the station 6 to the station 8 by a semiexpress train, and from the station 8 to the station 9 by a local train. In total, the travel time is 35 minutes.</li>
</ul>
<h3>Sample Input 2</h3>
<pre>
10 3 5
10 3 5
25
1
6
10
</pre>
<h3>Sample Output 2</h3>
<pre>
7
</pre>
<h3>Sample Input 3</h3>
<pre>
90 10 12
100000 1000 10000
10000
1
10
20
30
40
50
60
70
80
90
</pre>
<h3>Sample Output 2</h3>
<pre>
2
</pre>
<h3>Sample Input 4</h3>
<pre>
12 3 4
10 1 2
30
1
11
12
</pre>
<h3>Sample Output 4</h3>
<pre>
8
</pre>
<h3>Sample Input 5</h3>
<pre>
300 8 16
345678901 123456789 234567890
12345678901
1
10
77
82
137
210
297
300
</pre>
<h3>Sample Output 5</h3>
<pre>
72
</pre>
<h3>Sample Input 6</h3>
<pre>
1000000000 2 3000
1000000000 1 2
1000000000
1
1000000000
</pre>
<h3>Sample Output 6</h3>
<pre>
3000
</pre>
<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> |
p00833 |
<H1><font color="#000">Problem G:</font> Color the Map</H1>
<p>
You were lucky enough to get a map just before entering the legendary magical mystery world.
The map shows the whole area of your planned exploration, including several countries with
complicated borders. The map is clearly drawn, but in sepia ink only; it is hard to recognize at
a glance which region belongs to which country, and this might bring you into severe danger. You
have decided to color the map before entering the area. “A good deal depends on preparation,”
you talked to yourself.
</p>
<p>
Each country has one or more territories, each of which has a polygonal shape. Territories
belonging to one country may or may not “touch” each other, i.e. there may be disconnected
territories. All the territories belonging to the same country must be assigned the same color.
You can assign the same color to more than one country, but, to avoid confusion, two countries
“adjacent” to each other should be assigned different colors. Two countries are considered to be
“adjacent” if any of their territories share a border of non-zero length.
</p>
<p>
Write a program that finds the least number of colors required to color the map.
</p>
<H2>Input</H2>
<p>
The input consists of multiple map data. Each map data starts with a line containing the total
number of territories <i>n</i>, followed by the data for those territories. <i>n</i> is a positive integer not
more than 100. The data for a territory with <i>m</i> vertices has the following format:
</p>
<pre>
<i>String</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub>
...
<i>x</i><sub><i>m</i></sub> <i>y</i><sub><i>m</i></sub>
-1
</pre>
<p>
“<span><i>String</i></span>” (a sequence of alphanumerical characters) gives the name of the country it belongs to.
A country name has at least one character and never has more than twenty. When a country
has multiple territories, its name appears in each of them.
</p>
<p>
Remaining lines represent the vertices of the territory. A vertex data line has a pair of nonneg-
ative integers which represent the <i>x</i>- and <i>y</i>-coordinates of a vertex. <i>x</i>- and <i>y</i>-coordinates are
separated by a single space, and y-coordinate is immediately followed by a newline. Edges of
the territory are obtained by connecting vertices given in two adjacent vertex data lines, and byconnecting vertices given in the last and the first vertex data lines. None of <i>x</i>- and <i>y</i>-coordinates
exceeds 1000. Finally, -1 in a line marks the end of vertex data lines. The number of vertices
<i>m</i> does not exceed 100.
</p>
<p>
You may assume that the contours of polygons are simple, i.e. they do not cross nor touch
themselves. No two polygons share a region of non-zero area. The number of countries in a map
does not exceed 10.
</p>
<p>
The last map data is followed by a line containing only a zero, marking the end of the input
data.
</p>
<H2>Output</H2>
<p>
For each map data, output one line containing the least possible number of colors required to
color the map satisfying the specified conditions.
</p>
<H2>Sample Input</H2>
<pre>
6
Blizid
0 0
60 0
60 60
0 60
0 50
50 50
50 10
0 10
-1
Blizid
0 10
10 10
10 50
0 50
-1
Windom
10 10
50 10
40 20
20 20
20 40
10 50
-1
Accent
50 10
50 50
35 50
35 25
-1
Pilot
35 25
35 50
10 50
-1
Blizid
20 20
40 20
20 40
-1
4
A1234567890123456789
0 0
0 100
100 100
100 0
-1
B1234567890123456789
100 100
100 200
200 200
200 100
-1
C1234567890123456789
0 100
100 100
100 200
0 200
-1
D123456789012345678
100 0
100 100
200 100
200 0
-1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
</pre>
|
p01721 |
<p>勇猛果敢なイクタ君はついに悪名高きビッグブリッジ伯爵を追い詰めた! 今やビッグブリッジ伯爵は幅 <var>w</var> メートル、奥行き <var>h</var> メートルの長方形の部屋に閉じ込められており、最期を待つばかりとなっている。
</p>
<p>部屋のある角を選び、幅方向を <var>x</var> 軸、奥行き方向を <var>y</var> 軸に、それぞれ部屋の内部が正の方向になるように座標系をとると、ビッグブリッジ伯爵は点 <var>(p, q)</var> にいる。点 <var>(x, y)</var> にイクタ君の最終兵器である衝撃波発射装置があり、ここから秒速 <var>v</var> メートルの衝撃波を全方向に出す。この衝撃波は <var>t</var> 秒間有効であり、部屋の壁面で反射する。
</p>
<p>部屋の外にいるイクタ君はビッグブリッジ伯爵がどれだけ苦しむか知りたがっているので、ビッグブリッジ伯爵に衝撃波が何回当たるかを求めるプログラムを書いてあげよう。このとき、衝撃波が同時に <var>n</var> 方向から敵に当たる場合は <var>n</var> 回当たったとみなし、また衝撃波がちょうど <var>t</var> 秒後に敵に当たる場合も有効であるとする。衝撃波は発射装置自身やビッグブリッジ伯爵などの障害物により消滅せず、衝撃波同士は干渉しない。
</p>
<h2>Input</h2>
<p>入力は以下の形式で与えられる。
</p>
<blockquote>
<var>w</var> <var>h</var> <var>v</var> <var>t</var> <var>x</var> <var>y</var> <var>p</var> <var>q</var><br></blockquote>
<ul><li> それぞれは問題文の説明の通りの正の整数である。
</li></ul>
<h3>Constraints</h3>
<ul>
<li> <var> v × t ≤ 10<sup>6</sup> </var>
</li>
<li> <var> 2 ≤ w, h ≤ 10<sup>8</sup> </var>
</li>
<li> <var> 0 < x, p < w </var>
</li>
<li> <var> 0 < y, q < h </var>
</li>
<li> <var> (x, y) ≠ (p, q) </var>
</li></ul>
<h2>Output</h2>
<p>衝撃波がビッグブリッジ伯爵に当たる回数を1行に出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>10 10 1 10 3 3 7 7
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_WaveAttack_04sec" height="540" width="720"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_WaveAttack_06sec" height="540" width="720"><br>
</center>
<br>
<h2>Sample Input 2</h2>
<pre>10 10 1 11 3 3 7 7
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>5
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_WaveAttack_10sec" height="540" width="720"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_WaveAttack_11sec" height="540" width="720"><br>
</center>
<br>
<ul><li> 入力例 1, 2 において部屋の大きさと発射装置とビッグブリッジ伯爵の位置が同じであることに注意しながら、それぞれに付随する図(黒い点が発射装置、白い点がビッグブリッジ伯爵を表す)を見よ。
</li></ul>
<h2>Sample Input 3</h2>
<pre>2 3 1000 1000 1 1 1 2
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>523598775681
</pre> |
p01371 |
<!-- begin en only -->
<!--<h3><U>Fastest Route</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>
あなたの所属する知的プログラミングサークル (通称 Intelligent Clever Programming Circle, ICPC)では,今大掃除の最中である.
部室には,歴代の先輩たちの残していったさまざまなアイテムが所狭しと放置されている.
あなたが棚を整理していると,奥に大量のレトロゲームが封印されているのを発見した.
その中のいくつかに見覚えがあったあなたは,久々にそのゲームを遊んでみることにした.
</p>
<p>
見つけたゲームの詳細は次の通りである.
</p>
<p>
このゲームには1番から <i>N</i> 番までの <i>N</i> 個のステージがあり,任意の順に攻略することができる.
また,1から <i>N</i> まで番号付けられた装備があり,それらの装備を使用することでステージの攻略時間を短縮することができる.
ゲームを始めた段階では装備は一つも持っていないが, <i>i</i> 番のステージを攻略すると <i>i</i> 番の装備を入手することができ,一度入手した後は何度でも使用できる.
装備は一ステージで一種類だけしか使用することができないが,異なるステージで同じ装備を使用することはできる.
</p>
<p>
あなたは昔このゲームをクリアしたことがあるので,各装備に対して,その装備を使用したときに各ステージを攻略するのにかかる時間をすべて把握している.
ただ普通にクリアするだけではつまらないので,あなたは全てのステージを攻略し終わるまでにかかる時間を最小にしようと考えた.
そのため,あなたはICPCでの経験を生かして,各情報を与えたときに全てのステージを攻略し終わるまでにかかる時間の最小値を計算するプログラムを書くことにした.
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
入力は複数のデータセットからなる.
入力の終わりは1つのゼロからなる行によって与えられる.
各データセットは一つのゲームに関する情報を表し,その形式は以下の通りである.
</p>
<blockquote>
<i>N</i><br/>
<i>t<sub>10</sub></i> <i>t<sub>11</sub></i> ... <i>t<sub>1N</sub></i><br/>
<i>t<sub>20</sub></i> <i>t<sub>21</sub></i> ... <i>t<sub>2N</sub></i><br/>
...<br/>
<i>t<sub>N0</sub></i> <i>t<sub>N1</sub></i> ... <i>t<sub>NN</sub></i><br/>
</blockquote>
<p>
データセットの最初の行は1つの整数 <i>N</i> からなり,ステージの数を表す.
続く <i>N</i> 行は <i>N+1</i> 個の整数からなり,ステージの攻略時間を表す. <i>t<sub>i0</sub></i> は <i>i</i> 番のステージを装備なしで攻略するのにかかる時間である.
<i>t<sub>i j</sub></i> ( <i>j</i> > 0)は <i>i</i> 番のステージを <i>j</i> 番の装備で攻略するのにかかる時間である.
</p>
<p>
それぞれの値は次の制約を満たしている.
<ul>
<li>1 ≤ <i>N</i> ≤ 16</li>
<li>1 ≤ <i>t<sub>i j</sub></i> ≤ 100,000</li>
</ul>
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
それぞれのデータセットに対して,全てのステージを攻略し終わるまでにかかる時間の最小値を表す整数を1行に出力せよ.出力行にはこの数値以外の文字を含んではならない.
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3
100 100 100 100
100 1 100 100
100 1 1 100
3
100 100 1 100
200 102 100 102
100 100 1 100
7
100 100 60 60 70 70 70 90
100 50 100 55 45 45 55 44
100 50 60 100 51 50 55 30
100 70 10 20 1 10 10 40
200 90 10 30 10 10 10 30
150 200 12 1 11 11 1 30
10000 1200 1100 1100 1200 1200 1090 1
0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
102
202
1301
</pre>
</div>
|
p00999 |
<h1>Problem A: Rental DVD Shop NEO</h1>
<h2>Problem</h2>
<p>
僕はレンタルDVDショップ、「NEO」でアルバイトを始めた。まずはこの店の料金システムを勉強することになった。
</p>
<p>
レンタルDVDは旧作、準新作、新作の3種類存在し、1本のレンタル料金がそれぞれ<var> a </var>円、<var> b </var>円、<var> c </var>円である。
会計の際に以下に示すセットレンタルを複数回適用することができる。
</p>
<ul>
<li>まだセットレンタルを適用していないDVDを数本選ぶ。</li>
<li>選んだDVDの本数が<var> d </var>本以上の場合、選んだDVDの合計金額が、<var> (選んだDVDの本数) </var>*<var> e </var>円を超える場合は、それらを<var> (選んだDVDの本数) </var>*<var> e </var>円でレンタル出来る。</li>
<li>選んだDVDの本数が<var> d </var>本未満の場合、選んだDVDの合計金額が<var> d </var>*<var> e </var>円を超える場合は、それらを<var> d </var>*<var> e </var>円でレンタル出来る。</li>
<li>上記に当てはまらない場合、選んだDVDは通常料金でレンタルとなる。</li>
</ul>
<p>
ここで僕はある問題に気づいた。セットレンタルはレジに通した時に自動的に適用されるのではなく、手動で適用しているのだ。これでは最適ではない(もっと安くなる余地がある)セットレンタルの適用をしてしまう可能性がある。これではクレームが発生しかねない。僕はクレーム対応が嫌いなので、セットレンタルを最適に適用した時の料金を計算するプログラムを作成することにした。
</p>
<h2>Input</h2>
<p>
入力は複数のデータセットからなる。
各データセットは以下で表される。
1行目は5つの整数<var> a </var>,<var> b </var>,<var> c </var>,<var> d </var>,<var> e </var>がスペース区切りで与えられる。
2行目にはレンタル本数が与えられる。3つの整数<var> na </var>,<var> nb </var>,<var> nc </var>がスペース区切りで与えられる。それぞれ旧作、準新作、新作のDVDの本数を表す。
入力の終わりは5つのゼロからなる。
</p>
<pre>
<var>a</var> <var>b</var> <var>c</var> <var>d</var> <var>e</var>
<var>na</var> <var>nb</var> <var>nc</var>
</pre>
<h2>Constraints</h2>
<p>入力は以下の条件を満たす。</p>
<ul>
<li>入力に含まれる値はすべて整数</li>
<li>0 <<var> a </var><<var> b </var><<var> e </var><<var> c </var>≤ 1000</li>
<li>0 <<var> d </var>≤ 100000</li>
<li>0 ≤<var> na </var>,<var> nb </var>,<var> nc </var>≤ 100000</li>
<li>0 <<var> na </var>+<var> nb </var>+<var> nc </var></li>
<li>データセットの数は100個以下</li>
</ul>
<h2>Output</h2>
<p>各データセットにつき、セットレンタルを最適に適用した時の料金を1行に出力せよ。</p>
<h2>Sample Input</h2>
<pre>
70 100 340 4 200
1 1 4
70 100 340 4 200
0 1 3
70 100 340 4 200
1 1 2
0 0 0 0 0
</pre>
<h2>Sample Output</h2>
<pre>
970
800
800
</pre> |
p00976 | <h2>Ranks</h2>
<p>
A <i>finite field</i> <b>F<sub>2</sub></b> consists of two elements: 0 and 1. Addition and multiplication on <b>F<sub>2</sub></b> are those on integers modulo two, as defined below.
</p>
<table align="center">
<tr>
<td>
<table>
<tr >
<td style="border-bottom:1px solid #000; border-right:1px solid #000">+</td>
<td style="border-bottom:1px solid #000">0</td>
<td style="border-bottom:1px solid #000">1</td>
</tr>
<tr><td style="border-right:1px solid #000">0</td><td>0</td><td>1</td></tr>
<tr><td style="border-right:1px solid #000">1</td><td>1</td><td>0</td></tr>
</table>
</td>
<td>
</td>
<td>
<table>
<tr >
<td style="border-bottom:1px solid #000; border-right:1px solid #000">$\times$</td>
<td style="border-bottom:1px solid #000">0</td>
<td style="border-bottom:1px solid #000">1</td>
</tr>
<tr><td style="border-right:1px solid #000">0</td><td>0</td><td>0</td></tr>
<tr><td style="border-right:1px solid #000">1</td><td>0</td><td>1</td></tr>
</table>
</td>
</tr>
</table>
<br>
<p>
A set of vectors $v_1, ... , v_k$ over <b>F<sub>2</sub></b> with the same dimension is said to be <i>linearly independent</i> when, for $c_1, ... , c_k \in $ <b>F<sub>2</sub></b>, $c_1v_1 + ... + c_kv_k = 0$ is equivalent to $c_1 = ... = c_k = 0$, where $0$ is the zero vector, the vector with all its elements being zero.
</p>
<p>
The <i>rank</i> of a matrix is the maximum cardinality of its linearly independent sets of column vectors. For example, the rank of the matrix
$
\left[
\begin{array}{rrr}
0 & 0 & 1 \\
1 & 0 & 1
\end{array}
\right]
$
is two; the column vectors
$
\left[
\begin{array}{rrr}
0 \\
1
\end{array}
\right]
$
and
$
\left[
\begin{array}{rrr}
1 \\
1
\end{array}
\right]
$
(the first and the third columns) are linearly independent while the set of all three column vectors is <i>not</i> linearly independent. Note that the rank is zero for the zero matrix.
</p>
<p>
Given the above definition of the rank of matrices, the following may be an intriguing question. <i>How does a modification of an entry in a matrix change the rank of the matrix?</i> To investigate this question, let us suppose that we are given a matrix $A$ over <b>F<sub>2</sub></b>. For any indices $i$ and $j$, let $A^{(ij)}$ be a matrix equivalent to $A$ except that the $(i, j)$ entry is flipped.
</p>
\begin{equation*}
A^{(ij)}_{kl}= \left \{
\begin{array}{ll}
A_{kl} + 1 & (k = i \; {\rm and} \; l = j) \\
A_{kl} & ({\rm otherwise}) \\
\end{array}
\right.
\end{equation*}
<p>
In this problem, we are interested in the rank of the matrix $A^{(ij)}$. Let us denote the rank of $A$ by $r$, and that of $A^{(ij)}$ by $r^{(ij)}$. Your task is to determine, for all $(i, j)$ entries, the relation of ranks before and after flipping the entry out of the following possibilities: $(i) r^{(ij)} < r, (ii) r^{(ij)} = r$, or $(iii) r^{(ij)} > r$.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$ $m$
$A_{11}$ ... $A_{1m}$
.
.
.
$A_{n1}$ ... $A_{nm}$
</pre>
<p>
$n$ and $m$ are the numbers of rows and columns in the matrix $A$, respectively ($1 \leq n \leq 1000, 1 \leq m \leq 1000$). In the next $n$ lines, the entries of $A$ are listed without spaces in between. $A_{ij}$ is the entry in the $i$-th row and $j$-th column, which is either 0 or 1.
</p>
<h3>Output</h3>
<p>
Output $n$ lines, each consisting of $m$ characters. The character in the $i$-th line at the $j$-th position must be either <span>-</span> (minus), <span>0</span> (zero), or <span>+</span> (plus). They correspond to the possibilities (i), (ii), and (iii) in the problem statement respectively.
</p>
<h3>Sample Input 1</h3>
<pre>
2 3
001
101
</pre>
<h3>Sample Output 1</h3>
<pre>
-0-
-00
</pre>
<h3>Sample Input 2</h3>
<pre>
5 4
1111
1000
1000
1000
1000
</pre>
<h3>Sample Output 2</h3>
<pre>
0000
0+++
0+++
0+++
0+++
</pre>
<h3>Sample Input 3</h3>
<pre>
10 10
1000001001
0000010100
0000100010
0001000001
0010000010
0100000100
1000001000
0000010000
0000100000
0001000001
</pre>
<h3>Sample Output 3</h3>
<pre>
000-00000-
0-00000-00
00-00000-0
+00000+000
00-0000000
0-00000000
000-00000-
0-000-0-00
00-0-000-0
+00000+000
</pre>
<h3>Sample Input 4</h3>
<pre>
1 1
0
</pre>
<h3>Sample Output 4</h3>
<pre>
+
</pre>
|
p01664 |
<h2>I - σ</h2>
<p>
大きさ <var>N</var> の順列とは,数列 <var>(1, 2, 3, …, N)</var> の各要素を並べ替えたものである.
例えば <var>(5, 2, 1, 4, 3)</var> は大きさ <var>5</var> の順列だが,一方で <var>(1, 5, 1, 2, 3)</var> はそうではない.
</p>
<p>
この問題はリアクティブ方式のタスクである.あなたは応答プログラムと「順列当てゲーム」を行う.
まず最初に,応答プログラムは順列 <var>σ</var>を1つ内部で決める.
次に,あなたにはこの順列の大きさ <var>N</var> が伝えられる.
この後,あなたは応答プログラムに何回か<em>質問</em>をする.
そして,応答プログラムの持っている順列を特定することがあなたの目的である.
</p>
<p>
質問は次のようなものである:
大きさ <var>N</var> の順列 <var>τ</var> を1つ決め,それを応答プログラムに聞くと,
応答プログラムは数列 <var>a<sub>i</sub> = (σ</var>上での数字 <var>i</var> の位置と <var>τ</var> 上での数字 <var>i</var> の位置の距離<var>)</var>を計算する.
その後,数列 <var>(a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>, …, a<sub>N</sub>)</var> を昇順に並べて列 <var>(b<sub>1</sub>, b<sub>2</sub>, b<sub>3</sub>, …, b<sub>N</sub>)</var> を作り,あなたのプログラムに出力する.
</p>
<p>
例えば,<var>σ = (5, 2, 1, 4, 3)</var> のとき,<var>τ = (2, 3, 1, 4, 5)</var> を聞くと,
応答プログラムは内部で <var>(a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>, a<sub>4</sub>, a<sub>5</sub>) = (0, 1, 3, 0, 4)</var> を計算し,
これをソートした列 <var>(b<sub>1</sub>, b<sub>2</sub>, b<sub>3</sub>, b<sub>4</sub>, b<sub>5</sub>) = (0, 0, 1, 3, 4)</var> を出力する.
</p>
<p>
できるだけ少ない質問回数で順列を特定するプログラムを記せ.
採点方法については「採点方式」の項で記す.
</p>
<h2>入出力形式</h2>
<p>
まず,順列の大きさ <var>N</var> が入力として与えられる.
</p>
<pre>
<var>N</var>
</pre>
<p>
続いて,あなたのプログラムは何回か応答プログラムに質問をする.質問のフォーマットは以下であるとする.
</p>
<pre>
? <var>τ<sub>1</sub></var> <var>τ<sub>2</sub></var> <var>τ<sub>3</sub></var> … <var>τ<sub>N</sub></var>
</pre>
<p>
<var>τ<sub>i</sub></var> は,質問する順列の <var>i</var> 番目の要素の値である.
このとき <var>(τ<sub>1</sub>, …, τ<sub>N</sub>)</var> は大きさ <var>N</var> の順列になっていなければならない.
すなわち,<var>τ<sub>i</sub></var> の値は <var>1</var> 以上 <var>N</var> 以下ですべて相異なっていなければならない.
この後,応答プログラムは質問に対する答えを出力する.
</p>
<pre>
<var>b<sub>1</sub></var> <var>b<sub>2</sub></var> <var>b<sub>3</sub></var> … <var>b<sub>N</sub></var>
</pre>
<p>
このやりとりをコード上で実装する場合,C++では例えば次のようになる.
例えば順列 <var>(5, 2, 1, 4, 3)</var> を質問したい場合には,例えば
</p>
<pre class="prettyprint">
int tau[5] = {5, 2, 1, 4, 3};
printf("?");
for (int i=0; i<5; ++i) printf(" %d", tau[i]);
printf("\n");
fflush(stdout);</pre>
<p>
のようにする.次に
</p>
<pre class="prettyprint">for (int i=0; i<5; ++i) scanf("%d", &b[i]);</pre>
<p>
とすると,配列 b に質問の答えが返ってくる.
</p>
<p>
何回か質問を行った後,あなたは応答プログラムの持つ順列 <var>σ</var> を特定する.フォーマットは以下の通りとする.
(質問のときのフォーマットとほぼ同じで,先頭の <code>?</code> が <code>!</code> になっていることに注意せよ.)
</p>
<pre>
! <var>τ<sub>1</sub></var> <var>τ<sub>2</sub></var> <var>τ<sub>3</sub></var> … <var>τ<sub>N</sub></var>
</pre>
<p>
順列の特定を行った後,あなたのプログラムは直ちに終了しなければならない.終了しなかった場合のジャッジ結果は不定とする.
</p>
<p>
この問題ではテストデータごとに質問回数の上限値が設定されており,プログラムの行った質問の回数がその上限値を上回ると誤答と判定される.
</p>
<h2>制約</h2>
<ul>
<li><var>1 ≤ N ≤ 400</var></li>
</ul>
<!--
<h2>採点方式</h2>
<ul>
<li>50点分のテストケースグループでは,質問回数の上限値は 1000 回である.</li>
<li>750点分のテストケースグループでは,質問回数の上限値は 240 回である.</li>
</ul>
-->
<h2>入出力例1</h2>
<pre style="padding-left:20px">
<!--<table class = "table table-striped table-bordered table-condensed">-->
<table class="withborder">
<tr><th>プログラムの出力</th><th>プログラムへの入力</th></tr>
<tr><td></td><td>5</td></tr>
<tr><td>? 2 3 1 4 5</td><td></td></tr>
<tr><td></td><td>0 0 1 3 4</td></tr>
<tr><td>? 1 2 3 4 5</td><td></td></tr>
<tr><td></td><td>0 0 2 2 4</td></tr>
<tr><td>? 5 4 3 2 1</td><td></td></tr>
<tr><td></td><td>0 2 2 2 2</td></tr>
<tr><td>? 5 2 1 4 3</td><td></td></tr>
<tr><td></td><td>0 0 0 0 0</td></tr>
<tr><td>! 5 2 1 4 3</td><td></td></tr>
</table>
</pre>
<p>
<var>σ = (5, 2, 1, 4, 3)</var> である.何度か質問を行った後に列を特定している.
</p>
<h2>入出力例2</h2>
<pre>
<table class = "withborder">
<tr><th>プログラムの出力</th><th>プログラムへの入力</th></tr>
<tr><td></td><td>1</td></tr>
<tr><td>! 1</td><td></td></tr>
</table>
</pre>
<p>
大きさ 1 の順列は 1 つしかないので質問をしなくても直ちに特定することができる.
</p>
|
p03659 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke and Raccoon have a heap of <var>N</var> cards. The <var>i</var>-th card from the top has the integer <var>a_i</var> written on it.</p>
<p>They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.</p>
<p>Let the sum of the integers on Snuke's cards and Raccoon's cards be <var>x</var> and <var>y</var>, respectively.
They would like to minimize <var>|x-y|</var>.
Find the minimum possible value of <var>|x-y|</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>-10^{9} \leq a_i \leq 10^{9}</var></li>
<li><var>a_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 2 3 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, <var>x=10</var>, <var>y=11</var>, and thus <var>|x-y|=1</var>. This is the minimum possible value.</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>20
</pre>
<p>Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, <var>x=10</var>, <var>y=-10</var>, and thus <var>|x-y|=20</var>.</p></section>
</div>
</span> |
p04036 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an undirected graph with <var>N</var> vertices and <var>M</var> edges. The vertices are numbered <var>1</var> through <var>N</var>, and the edges are numbered <var>1</var> through <var>M</var>. Edge <var>i</var> connects vertices <var>a_i</var> and <var>b_i</var>. The graph is connected.</p>
<p>On this graph, <var>Q</var> pairs of brothers are participating in an activity called <em>Stamp Rally</em>. The Stamp Rally for the <var>i</var>-th pair will be as follows:</p>
<ul>
<li>One brother starts from vertex <var>x_i</var>, and the other starts from vertex <var>y_i</var>.</li>
<li>The two explore the graph along the edges to visit <var>z_i</var> vertices in total, including the starting vertices. Here, a vertex is counted only once, even if it is visited multiple times, or visited by both brothers.</li>
<li>The score is defined as the largest index of the edges traversed by either of them. Their objective is to minimize this value.</li>
</ul>
<p>Find the minimum possible score for each pair.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3≤N≤10^5</var></li>
<li><var>N−1≤M≤10^5</var></li>
<li><var>1≤a_i<b_i≤N</var></li>
<li>The given graph is connected.</li>
<li><var>1≤Q≤10^5</var></li>
<li><var>1≤x_j<y_j≤N</var></li>
<li><var>3≤z_j≤N</var></li>
</ul>
</section>
</div>
<hr>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
<var>Q</var>
<var>x_1</var> <var>y_1</var> <var>z_1</var>
<var>x_2</var> <var>y_2</var> <var>z_2</var>
<var>:</var>
<var>x_Q</var> <var>y_Q</var> <var>z_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the minimum possible score for the <var>i</var>-th pair of brothers.</p>
</section>
</div>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 6
2 3
4 5
1 2
1 3
1 4
1 5
6
2 4 3
2 4 4
2 4 5
1 3 3
1 3 4
1 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
2
3
1
5
5
</pre></section>
</div>
</hr></hr></span> |
p01234 |
<H1><font color="#000">Problem A:</font> Defend the Nation</H1>
<p>
Two nations Drone and Moonlamb have been engaged in a war. You have been called up for service as a talented
programmer in Drone.
</p>
<p>
Recently, the army of Moonlamb has set up a new cannon on the field. The army of Drone knows exactly where
it has been placed, but not how it can be destroyed; direct attacks would not be successful because the army
of Moonlamb has also set up a special barrier around the cannon. Fortunately, it seems that no projectiles have
reached the troops yet. Nevertheless, the army of Drone immediately requires an effective means to intercept pro-
jectiles fired from the cannon. Otherwise they would definitely take severe damage once the army of Moonlamb
started attacks with the cannon.
</p>
<p>
The generals of Drone have decided to build a new interception system that consists of a radar system, a control
program, and an auto-operated cannon. As neither of the cannons of Moonlamb and Drone can change the firing
directions except the elevation angles, the auto-operated cannon will be placed so the two barrels face each other.
This way the army of Drone will have a better possibility of successful interception. The figure below depicts
this situation.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_defendTheNation">
</center>
<p>
The interception system works as follows. When the radar system detects projectiles fired from the barriered
cannon, it immediately sends their initial velocities and elevation angles to the control program. Then the control
program determines the elevation angles at which the interceptors should be fired in order to destroy the targeted
projectiles on the fly, and sends firing commands to the auto-operated cannon. Finally, the auto-operated cannon
fires interceptors according to the received commands.
</p>
<p>
For the maximum safety of the auto-operated cannon and other installations behind, the army of Drone wants
to destroy the projectiles at the earliest possible time. On the other hand, the interceptors can be fired only with
their fixed initial velocities. The control program thus can only control the elevation angles and the firing times.
In addition, the interceptors cannot be fired in less than &gamma seconds from when the targeted projectiles are fired,
because of delay in detecting those projectiles.
</p>
<p>
The trajectories of the projectiles and the interceptors shape parabolas, both affected only by the gravity with the
acceleration of 9.8 [m/s<sup>2</sup>]. The sizes of the projectiles, the interceptors, and the cannons are all negligible.
</p>
<p>
Your task is to write the control program and defend the nation Drone!
</p>
<H2>Input</H2>
<p>
The first line of the input contains a single integer that indicates the number of test cases.
</p>
<p>
Each test case consists of a line with five integers <i>d</i>, γ, <i>v</i><sub>1</sub> , <i>θ</i><sub>1</sub>, and <i>v</i><sub>2</sub>, in this order. <i>d</i> denotes the distance
between the two cannons in meters (1 ≤ <i>d</i> ≤ 1000); γ denotes the minimum time needed in seconds between the
projectile and the interceptor (0 ≤ γ ≤ 100); <i>v</i><sub>1</sub> denotes the initial velocity of the projectile in meters per second
(1 ≤ <i>v</i><sub>1</sub> ≤ 1000); <i>θ</i><sub>1</sub> denotes the elevation angle of the targeted projectile in degrees (1 ≤ <i>θ</i><sub>1</sub> ≤ 89); and <i>v</i><sub>2</sub> denotes
the initial velocity of the interceptor in meters per second (1 ≤ <i>v</i><sub>2</sub> ≤ 1000).
</p>
<H2>Output</H2>
<p>
For each test case, your program should print the elevation angle of the interceptor, and the time elapsing between
the projectile being fired from Moonlamb and it being destroyed. The angle and the time should be given
in degrees and seconds respectively, and both should be printed with exactly six fractional digits. In case of
multiple angles giving the same minimum elapsing time, your program may print any of them. If it is impossible
to destroy the projectile before reaching the land, your program should report as such.
</p>
<p>
The output should be formatted as shown in the sample below. Print an empty line between test cases.
</p>
<H2>Sample Input</H2>
<pre>
2
150 1 50 30 50
100 1 20 30 40
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1:
Fire at 37.995392 degree(s).
Projectile destroyed in 2.290123 second(s).
Case 2:
Projectile reaches the land.
</pre>
|
p03209 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some other world, today is Christmas.</p>
<p>Mr. Takaha decides to make a multi-dimensional burger in his party. A <em>level-<var>L</var> burger</em> (<var>L</var> is an integer greater than or equal to <var>0</var>) is the following thing:</p>
<ul>
<li>A level-<var>0</var> burger is a patty.</li>
<li>A level-<var>L</var> burger <var>(L \geq 1)</var> is a bun, a level-<var>(L-1)</var> burger, a patty, another level-<var>(L-1)</var> burger and another bun, stacked vertically in this order from the bottom.</li>
</ul>
<p>For example, a level-<var>1</var> burger and a level-<var>2</var> burger look like <code>BPPPB</code> and <code>BBPPPBPBPPPBB</code> (rotated <var>90</var> degrees), where <code>B</code> and <code>P</code> stands for a bun and a patty.</p>
<p>The burger Mr. Takaha will make is a level-<var>N</var> burger. Lunlun the Dachshund will eat <var>X</var> layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>1 \leq X \leq (</var> the total number of layers in a level-<var>N</var> burger <var>)</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of patties in the bottom-most <var>X</var> layers from the bottom of a level-<var>N</var> burger.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are <var>4</var> patties in the bottom-most <var>7</var> layers of a level-<var>2</var> burger (<code>BBPPPBPBPPPBB</code>).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The bottom-most layer of a level-<var>1</var> burger is a bun.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>50 4321098765432109
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2160549382716056
</pre>
<p>A level-<var>50</var> burger is rather thick, to the extent that the number of its layers does not fit into a <var>32</var>-bit integer.</p></section>
</div>
</span> |
p02048 | <h3>成績上昇大作戦</h3>
<!-- begin ja only -->
<p>受験生の太郎君は <i>N</i> 日間の勉強合宿に参加した.
この合宿では毎日 <i>M</i> 科目のテストを行い,
合宿の終了後にはすべてのテストの点数が書かれた成績表が配られる.
成績表は <i>N</i> 枚の紙からなっており,<i>i</i> 枚目の紙には <i>i</i> 日目の全 <i>M</i> 科目のテストの科目名と点数のみが印刷されている.</p>
<p>成績表に日付が書かれていないことに気付いた太郎君は,お母さんに成績表を渡す前に細工を加えることにした.
成績表の紙の順番を並べ替え,さらに1枚目から順番にページ番号を書き込んで冊子にすることによって「偽りの成績表」を作ったのだ.
太郎君の目的は,「偽りの成績表」でテストの点数がページ番号に対して広義単調増加している科目の個数を最大化することである.</p>
<p>太郎君が「偽りの成績表」を作るとき,テストの点数がページ番号に対して広義単調増加である科目の個数の最大値を求めよ.</p>
<p>ただし,<i>N</i> 日間のテストの点数がページ番号に対して広義単調増加であるとは <i>1 ≤ i < N</i> に対して <i>i+1</i> 枚目に記載されている点数が <i>i</i> 枚目に記載されている点数以上であることを意味する.</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>入力は 50 個以下のデータセットからなる. 各データセットは次の形式で表される.</p>
<blockquote><i>N</i> <i>M</i>
<i>a<sub>11</sub></i> <i>...</i> <i>a<sub>1M</sub></i>
<i>...</i>
<i>a<sub>N1</sub></i> <i>...</i> <i>a<sub>NM</sub></i></blockquote>
<p>1行目には,勉強合宿の日数 <i>N</i> と科目数 <i>M</i> が与えられる.<i>N</i> は <i>1</i> 以上 <i>10<sup>3</sup></i> 以下の整数で,<i>M</i> は <i>1</i> 以上 <i>40</i> 以下の整数である.</p>
<p>続く <i>N</i> 行には太郎君の点数が与えられる.各行は <i>M</i> 個の整数からなっており <i>a<sub>ij</sub></i> は太郎君の <i>i</i> 日目の科目 <i>j</i> の点数であり,<i>a<sub>ij</sub></i> は <i>0</i> 以上 <i>10<sup>3</sup></i> 以下の整数である.</p>
<p>入力の終わりは,2 つのゼロからなる行で表される.</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>各データセットについて,テストの点数がページ番号に対して広義単調増加である科目の個数の最大値を 1 行に出力せよ.</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>3 3
1 2 3
2 1 3
3 3 3
8 5
3 3 4 3 4
2 1 2 3 2
7 9 7 8 7
3 4 3 3 4
1 2 2 3 2
4 5 6 5 6
7 9 7 7 8
4 5 5 6 6
5 5
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
5 9
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
0 0
</pre><h3>Output for the Sample Input</h3><pre>2
3
1
9
</pre>
|
p00075 |
<H1>BMI</H1>
<p>
肥満は多くの成人病の原因として挙げられています。過去においては、一部の例外を除けば、高校生には無縁なものでした。しかし、過度の受験勉強等のために運動不足となり、あるいはストレスによる過食症となることが、非現実的なこととはいえなくなっています。高校生にとっても十分関心を持たねばならない問題になるかもしれません。
</p>
<p>
そこで、あなたは、保健室の先生の助手となって、生徒のデータから肥満の疑いのある生徒を探し出すプログラムを作成することになりました。
</p>
<p>
方法は BMI (Body Mass Index) という数値を算出する方法です。BMIは次の式で与えられます。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_03">
</center>
<br/>
<p>
BMI = 22 が標準的で、25 以上だと肥満の疑いがあります。
</p>
<p>
各々の生徒の体重、身長の情報から BMI を算出し、25 以上の生徒の学籍番号を出力するプログラムを作成してください。
</p>
<H2>入力</H2>
<p>
入力は以下の形式で与えられます。
</p>
<pre>
<var>s<sub>1</sub></var>,<var>w<sub>1</sub></var>,<var>h<sub>1</sub></var>
<var>s<sub>2</sub></var>,<var>w<sub>2</sub></var>,<var>h<sub>2</sub></var>
...
...
</pre>
<p>
<var>s<sub>i</sub></var> (1 ≤ <var>s<sub>i</sub></var> ≤ 2,000)、<var>w<sub>i</sub></var> (1 ≤ <var>w<sub>i</sub></var> ≤ 200)、<var>h<sub>i</sub></var> (1.0 ≤ <var>h<sub>i</sub></var> ≤ 2.0) はそれぞれ、<var>i</var> 番目の生徒の学籍番号(整数)、体重(実数)、身長(実数)を表します。
</p>
<p>
生徒の数は 50 を超えません。
</p>
<H2>出力</H2>
<p>
BMI が 25 以上の生徒の学籍番号を、入力された順番にそれぞれ1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
1001,50.0,1.60
1002,60.0,1.70
1003,70.0,1.80
1004,80.0,1.70
1005,90.0,1.60
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1004
1005
</pre>
|
p02418 |
<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>Ring</h1><br>
<p>
Write a program which finds a pattern $p$ in a ring shaped text $s$.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_8_D">
</center>
<br>
<h2>Input</h2>
<p>
In the first line, the text $s$ is given.<br>
In the second line, the pattern $p$ is given.
</p>
<h2>Output</h2>
<p>
If $p$ is in $s$, print <span>Yes</span> in a line, otherwise <span>No</span>.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq $ length of $p \leq $ length of $s \leq 100$</li>
<li>$s$ and $p$ consists of lower-case letters</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
vanceknowledgetoad
advance
</pre>
<h2>Sample Output 1</h2>
<pre>
Yes
</pre>
<br>
<h2>Sample Input 2</h2>
<pre>
vanceknowledgetoad
advanced
</pre>
<h2>Sample Output 2</h2>
<pre>
No
</pre>
|
p00425 |
<H1></H1>
<p>
サイコロが以下の図のような向きで置かれている.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t3-fig_base">
</center>
<br>
<p>
ここで使用するサイコロは,この図のように,上側に 1,南側に 2 があるときは,東側に 3 があるものとする.サイコロの向かいあう面の和は必ず 7 なので,見えない面はそれぞれ北側 5,西側 4,下側 6 になっている.
</p>
<p>
この初期配置の状態から指示に従ってサイコロを動かしていく.ただし,指示は以下の 6 通りの操作を何回か行うものである.
</p>
<center>
<table>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t3-fig_north"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t3-fig_east"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t3-fig_west"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t3-fig_south"></td>
</tr>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t3-fig_right"></td>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t3-fig_left"></td>
<td></td>
<td></td>
</tr>
</table>
</center>
<br/>
<p>
North,East,South,West の各操作は指示された方向へサイコロを 90 度回転させる.
Right,Left の 2 つの操作は上下の面はそのままで水平方向に 90 度回転させる.(回転させる向きに要注意.)
</p>
<p>
初期配置で上の面に出ている目 1 を初期値とし, 1 回の操作が終わるたびに,上の面に出ている目の数を加算していき,指示にしたがってすべての操作を終えたときの合計値を出力するプログラムを作成しなさい.
</p>
<p>
入力ファイルの 1 行目には総指示回数 n が書かれていて,続く n 行の各行には「North,East,South,West,Right,Left」のいずれか 1 つの指示が書かれているものとする.ただし, n ≦ 10000 とする.
</p>
<!--
<p>
アップロードする出力ファイルにおいては、出力(合計値)の後に改行を入れること。
</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>
</tr>
<tr><td>5</td><td>8</td></tr>
<tr><td>North</td><td>West</td></tr>
<tr><td>North</td><td>North</td></tr>
<tr><td>East</td><td>Left</td></tr>
<tr><td>South</td><td>South</td></tr>
<tr><td>West</td><td>Right</td></tr>
<tr><td></td><td>North</td></tr>
<tr><td></td><td>Left</td></tr>
<tr><td></td><td>East</td></tr>
<tr>
<td> </td>
</tr>
<tr>
<th width="150" align="left">出力例1</th> <th width="150" align="left">出力例2</th>
</tr>
<tr><td>21</td><td>34</td></tr>
</table>
<h3>入力</h3>
<p>
入力は複数のデータセットからなる.n が 0 のとき入力が終了する.データセットの数は 5 を超えない.
</p>
<h3>出力</h3>
<p>
データセットごとに、合計値を1行に出力する.
</p>
<H2>入力例</H2>
<pre>
5
North
North
East
South
West
8
West
North
Left
South
Right
North
Left
East
0
</pre>
<H2>出力例</H2>
<pre>
21
34
</pre>
<p>
各データセットの出力(合計値)の後に改行を入れること。
</p>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p03120 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Count the number of strings <var>S</var> that satisfy the following constraints, modulo <var>10^9 + 7</var>.</p>
<ul>
<li>The length of <var>S</var> is exactly <var>N</var>.</li>
<li><var>S</var> consists of digits (<code>0</code>...<code>9</code>).</li>
<li>You are given <var>Q</var> intervals.
For each <var>i (1 \leq i \leq Q)</var>, the integer represented by <var>S[l_i \ldots r_i]</var> (the substring of <var>S</var> between the <var>l_i</var>-th (<var>1</var>-based) character and the <var>r_i</var>-th character, inclusive) must be a multiple of <var>9</var>.</li>
</ul>
<p>Here, the string <var>S</var> and its substrings may have leading zeroes.
For example, <code>002019</code> represents the integer <var>2019</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^9</var></li>
<li><var>1 \leq Q \leq 15</var></li>
<li><var>1 \leq l_i \leq r_i \leq N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>Q</var>
<var>l_1</var> <var>r_1</var>
<var>:</var>
<var>l_Q</var> <var>r_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of strings that satisfy the conditions, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2
1 2
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>136
</pre>
<p>For example, <var>S = </var><code>9072</code> satisfies the conditions because both <var>S[1 \ldots 2] = </var><code>90</code> and <var>S[2 \ldots 4] = </var><code>072</code> represent multiples of <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
3
2 5
3 5
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2720
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20
10
2 15
5 6
1 12
7 9
2 17
5 15
2 4
16 17
2 12
8 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>862268030
</pre></section>
</div>
</span> |
p03570 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>s</var> consisting of lowercase English letters.
Snuke is partitioning <var>s</var> into some number of non-empty substrings.
Let the subtrings obtained be <var>s_1</var>, <var>s_2</var>, <var>...</var>, <var>s_N</var> from left to right. (Here, <var>s = s_1 + s_2 + ... + s_N</var> holds.)
Snuke wants to satisfy the following condition:</p>
<ul>
<li>For each <var>i</var> (<var>1 \leq i \leq N</var>), it is possible to permute the characters in <var>s_i</var> and obtain a palindrome.</li>
</ul>
<p>Find the minimum possible value of <var>N</var> when the partition satisfies the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |s| \leq 2 \times 10^5</var></li>
<li><var>s</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value of <var>N</var> when the partition satisfies the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aabxyyzz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The solution is to partition <var>s</var> as <code>aabxyyzz</code> = <code>aab</code> + <code>xyyzz</code>.
Here, <code>aab</code> can be permuted to form a palindrome <code>aba</code>, and <code>xyyzz</code> can be permuted to form a palindrome <code>zyxyz</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>byebye
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p><code>byebye</code> can be permuted to form a palindrome <code>byeeyb</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abcdefghijklmnopqrstuvwxyz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>26
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>abcabcxabcx
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
<p>The solution is to partition <var>s</var> as <code>abcabcxabcx</code> = <code>a</code> + <code>b</code> + <code>cabcxabcx</code>.</p></section>
</div>
</span> |
p02731 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a positive integer <var>L</var>.
Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is <var>L</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ L ≤ 1000</var></li>
<li><var>L</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>L</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is <var>L</var>.
Your output is considered correct if its absolute or relative error from our answer is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1.000000000000
</pre>
<p>For example, a rectangular cuboid whose dimensions are <var>0.8</var>, <var>1</var>, and <var>1.2</var> has a volume of <var>0.96</var>.</p>
<p>On the other hand, if the dimensions are <var>1</var>, <var>1</var>, and <var>1</var>, the volume of the rectangular cuboid is <var>1</var>, which is greater.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>36926037.000000000000
</pre></section>
</div>
</span> |
p03823 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a set consisting of <var>N</var> distinct integers. The <var>i</var>-th smallest element in this set is <var>S_i</var>. We want to divide this set into two sets, <var>X</var> and <var>Y</var>, such that:</p>
<ul>
<li>The absolute difference of any two distinct elements in <var>X</var> is <var>A</var> or greater.</li>
<li>The absolute difference of any two distinct elements in <var>Y</var> is <var>B</var> or greater.</li>
</ul>
<p>How many ways are there to perform such division, modulo <var>10^9 + 7</var>? Note that one of <var>X</var> and <var>Y</var> may be empty.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 ≦ N ≦ 10^5</var></li>
<li><var>1 ≦ A , B ≦ 10^{18}</var></li>
<li><var>0 ≦ S_i ≦ 10^{18}(1 ≦ i ≦ N)</var></li>
<li><var>S_i < S_{i+1}(1 ≦ 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</var> <var>B</var>
<var>S_1</var>
:
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different divisions under the conditions, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3 7
1
3
6
9
12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five ways to perform division:</p>
<ul>
<li><var>X=</var>{<var>1,6,9,12</var>}, <var>Y=</var>{<var>3</var>}</li>
<li><var>X=</var>{<var>1,6,9</var>}, <var>Y=</var>{<var>3,12</var>}</li>
<li><var>X=</var>{<var>3,6,9,12</var>}, <var>Y=</var>{<var>1</var>}</li>
<li><var>X=</var>{<var>3,6,9</var>}, <var>Y=</var>{<var>1,12</var>}</li>
<li><var>X=</var>{<var>3,6,12</var>}, <var>Y=</var>{<var>1,9</var>}</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 5 3
0
2
4
7
8
11
15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8 2 9
3
4
5
13
15
22
26
32
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>13
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3 3 4
5
6
7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre></section>
</div>
</span> |
p03989 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves permutations. He is making a permutation of length <var>N</var>.</p>
<p>Since he hates the integer <var>K</var>, his permutation will satisfy the following:</p>
<ul>
<li>Let the permutation be <var>a_1, a_2, ..., a_N</var>. For each <var>i = 1,2,...,N</var>, <var>|a_i - i| \neq K</var>.</li>
</ul>
<p>Among the <var>N!</var> permutations of length <var>N</var>, how many satisfies this condition?</p>
<p>Since the answer may be extremely large, find the answer modulo <var>924844033</var>(prime).</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ≦ N ≦ 2000</var></li>
<li><var>1 ≦ K ≦ 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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer modulo <var>924844033</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p><var>2</var> permutations <var>(1, 2, 3)</var>, <var>(3, 2, 1)</var> satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p><var>5</var> permutations <var>(1, 2, 3, 4)</var>, <var>(1, 4, 3, 2)</var>, <var>(3, 2, 1, 4)</var>, <var>(3, 4, 1, 2)</var>, <var>(4, 2, 3, 1)</var> satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>14
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>425 48
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>756765083
</pre></section>
</div>
</span> |
p02361 | <script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Single Source Shortest Path</H1>
<p>
For a given weighted graph <var>G(V, E)</var> and a source <var>r</var>, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path).
</p>
<H2>Input</H2>
<p>
An edge-weighted graph <var>G</var> (<var>V</var>, <var>E</var>) and the source <var>r</var>.
</p>
<pre>
|<var>V</var>| |<var>E</var>| <var>r</var>
<var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>d<sub>0</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var>
:
<var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>d<sub>|E|-1</sub></var>
</pre>
<p>
<var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in <var>G</var>. The graph vertices are named with the numbers 0, 1,..., <var>|V|-1</var> respectively. <var>r</var> is the source of the graph.
</p>
<p>
<var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target vertices of <var>i</var>-th edge (directed) and <var>d<sub>i</sub></var> represents the cost of the <var>i</var>-th edge.
</p>
<H2>Output</H2>
<p>
Print the costs of SSSP in the following format.
</p>
<pre>
<var>c<sub>0</sub></var>
<var>c<sub>1</sub></var>
:
<var>c<sub>|V|-1</sub></var>
</pre>
<p>
The output consists of <var>|V|</var> lines. Print the cost of the shortest path from the source <var>r</var> to each vertex 0, 1, ... <var>|V|-1</var> in order. If there is no path from the source to a vertex, print <span>INF</span>.
</p>
<H2>Constraints</H2>
<ul>
<li> 1 ≤ <var>|V|</var> ≤ 100000</li>
<li>0 ≤ <var>d<sub>i</sub></var> ≤ 10000</li>
<li> 0 ≤ <var>|E|</var> ≤ 500000</li>
<li> There are no parallel edges</li>
<li> There are no self-loops</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 5 0
0 1 1
0 2 4
1 2 2
2 3 1
1 3 5
</pre>
<H2>Sample Output 1</H2>
<pre>
0
1
3
4
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4 6 1
0 1 1
0 2 4
2 0 1
1 2 2
3 1 1
3 2 5
</pre>
<H2>Sample Output 2</H2>
<pre>
3
0
2
INF
</pre>
|
p00649 |
<h1>Problem C: Yanagi's Comic</h1>
<p>
Yanagi is a high school student, and she is called "Hime" by her boyfriend who is a ninja fanboy. She likes picture books very much, so she often writes picture books by herself.
She always asks you to make her picture book as an assistant.
Today, you got asked to help her with making a comic.
</p>
<p>
She sometimes reads her picture books for children in kindergartens.
Since Yanagi wants to let the children read,
she wants to insert numbers to frames in order.
Of course, such a task should be done by the assistant, you.
</p>
<p>
You want to do the task easily and fast, so you decide to write a program to output the order of reading frames based on the positions of the frames.
</p>
<p>
Write a program to print the number of order for each frame.
</p>
<p>
The comics in this problem satisfy the following rules.
</p>
<p>
The each comic is drawn on a sheet of rectangle paper.
You can assume that the top side of the paper is on the x-axis.
And you can assume that the right-hand side of the paper is on the y-axis.
The positive direction of the x-axis is leftward.
The positive direction of the y-axis is down direction.
The paper is large enough to include all frames of the comic.
In other words, no area in a frame is out of the paper.
</p>
<p>
The area of each frame is at least one.
All sides of each frame are parallel to the x-axis or the y-axis.
The frames can't overlap one another.
However the frames may share the line of side.
</p>
<p>
You must decide the order to read <i> K </i>, where <i> K </i> is a set of frames, with the following steps.
</p>
<pre>
<b>Step 1</b>:You must choose an unread frame at the right-most position in <i>K</i>.
If you find such frames multiple, you must choose the frame at the top position among them.
If you can't find any unread frames, you stop reading <i>K</i>.
The frame you chose is "Starting Frame".
In step 1, you assume that the position of a frame is the top-right point of the frame.
</pre>
<pre>
<b>Step 2</b>:You should draw a line from the right-bottom point of "Starting Frame" to leftward horizontally.
If the line touch the right-hand side of other frame, you should stop drawing.
If the line is on the side of other frame, you should not stop drawing.
If the line touch the edge of paper, you should stop drawing.
</pre>
<pre>
<b>Step 3</b>:The set of the unread frames which are above the line ( they may be the bottom-side on the line ) drawn at Step 2 is <i>L</i>.
And you should read <i>L</i>.
</pre>
<pre>
<b>Step 4</b>: Go back to Step 1.
</pre>
<h2>Input</h2>
<p>
The input consists of multiple datasets.
The last dataset is followed by a line containing one zero.
You don't have to process this data.
</p>
<p>
Each datasets is in the following format.
</p>
<pre>
<i>n
x<sub>01</sub> y<sub>01</sub> x<sub>11</sub> y<sub>11</sub>
x<sub>02</sub> y<sub>02</sub> x<sub>12</sub> y<sub>12</sub>
....
x<sub>0n</sub> y<sub>0n</sub> x<sub>1n</sub> y<sub>1n</sub>
</i>
</pre>
<p>
All numbers of the datasets are integer.
They are separated by a space.
The first line of a dataset contains one integer.
<i>n</i> is the number of frames of the comic.
<i> x<sub>0i</sub> </i> , <i> y<sub>0i</sub> </i>, <i> x<sub>1i</sub> </i>, <i> y<sub>1i</sub> </i> are two non-neighboring points of <i> i </i> th frame in the line.
</p>
<h2>Constraints</h2>
<p>
0 < <i>n</i> < 10<br>
(<i>x<sub>0i</sub></i> != <i>x<sub>1i</sub></i>) and (<i>y<sub>0i</sub></i> != <i>y<sub>1i</sub></i>)<br>
0 ≤ <i> x<sub>0i</sub> </i>, <i> y<sub>0i</sub> </i>, <i>x<sub>1i</sub> </i>, <i> y<sub>1i</sub> </i> ≤ 500<br>
</p>
<h2>Output</h2>
<p>
Print n lines for each dataset.
Print the number of order for <i>i</i>th frame in the <i>i</i>th line.
And you should print blank line between the datasets.<br>
Output format:
</p2>
<pre>
<i>num<sub>1</sub></i>
<i>num<sub>2</sub></i>
...
<i>num<sub>i</sub></i>
...
<i>num<sub>n</sub></i>
</pre>
<h2>Sample input</h2>
<pre>
4
0 0 100 60
0 60 50 90
50 60 100 90
0 90 100 120
6
0 0 100 40
0 40 50 70
50 40 100 60
50 60 100 80
0 70 50 120
50 80 100 120
0
</pre>
<h2>Sample output</h2>
<pre>
1
2
3
4
1
2
4
5
3
6
</pre>
<p>
These pictures are related to first sample and second sample.
Gray frames have been read already.
A red line denotes the line drawn at Step 2. Numbers in the figures denote the order of frames given by input.
</p>
<br>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_C1"><br>
This is related to the first sample.<br>
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_C2">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_C3"><br>
These are related to the second sample.
</p>
|
p02674 | <span class="lang-en">
<p>Score : <var>2400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people (with different names) and <var>K</var> clubs. For each club you know the list of members (so you have <var>K</var> unordered lists). Each person can be a member of many clubs (and also <var>0</var> clubs) and two different clubs might have exactly the same members.
The value of the number <var>K</var> is the minimum possible such that the following property can be true for at least one configuration of clubs.
If every person changes her name (maintaining the property that all names are different) and you know the new <var>K</var> lists of members of the clubs (but you don't know which list corresponds to which club), you are sure that you would be able to match the old names with the new ones.</p>
<p>Count the number of such configurations of clubs (or say that there are more than <var>1000</var>).
Two configurations of clubs that can be obtained one from the other if the <var>N</var> people change their names are considered equal.</p>
<p><strong>Formal statement</strong>:
A club is a (possibly empty) subset of <var>\{1,\dots, N\}</var> (the subset identifies the members, assuming that the people are indexed by the numbers <var>1, 2,\dots, N</var>).
A configuration of clubs is an unordered collection of <var>K</var> clubs (not necessarily distinct).
Given a permutation <var>\sigma(1), \dots, \sigma(N)</var> of <var>\{1,\dots, N\}</var> and a configuration of clubs <var>L=\{C_1, C_2, \dots, C_K\}</var>, we denote with <var>\sigma(L)</var> the configuration of clubs <var>\{\sigma(C_1), \sigma(C_2), \dots, \sigma(C_K)\}</var> (if <var>C</var> is a club, <var>\sigma(C)=\{\sigma(x):\, x\in C\}</var>).
A configuration of clubs <var>L</var> is name-preserving if for any pair of distinct permutations <var>\sigma\not=\tau</var>, it holds <var>\sigma(L)\not=\tau(L)</var>.</p>
<p>You have to count the number of name-preserving configurations of clubs with the minimum possible number of clubs (so <var>K</var> is minimum). Two configurations <var>L_1, L_2</var> such that <var>L_2=\sigma(L_1)</var> (for some permutation <var>\sigma</var>) are considered equal.
If there are more than <var>1000</var> such configurations, print <var>-1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \le N \le 2\cdot10^{18}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the format</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>ans</var> is the number of configurations with the properties described in the statement, you should print on Standard Output</p>
<pre><var>ans</var>
</pre>
<p>If there are more than <var>1000</var> such configurations, print <var>-1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The value of <var>K</var> is <var>1</var> and the unique name-preserving configuration of clubs is <var>\{\{1\}\}</var> (the configuration <var>\{\{2\}\}</var> is considered the same).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>The value of <var>K</var> is <var>2</var> and the unique (up to permutation) name-preserving configuration of clubs is <var>\{\{1\}, \{1, 2\}\}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
</pre>
<p>The value of <var>K</var> is <var>3</var> and the name-preserving configurations of clubs with <var>3</var> clubs are:</p>
<ul>
<li><var>\{\{1\}, \{2\}, \{1, 3\}\}</var></li>
<li><var>\{\{1\}, \{1, 2\}, \{2, 3\}\}</var></li>
<li><var>\{\{1, 2\}, \{1, 2\}, \{1, 3\}\}</var></li>
<li><var>\{\{1\}, \{1, 2\}, \{1, 2, 3\}\}</var></li>
<li><var>\{\{1\}, \{2, 3\}, \{1, 2, 4\}\}</var></li>
<li><var>\{\{1, 2\}, \{1, 3\}, \{1, 2, 4\}</var></li>
<li><var>\{\{1, 2\}, \{1, 2, 3\}, \{2, 3, 4\}\}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>26
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>123456789123456789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>-1
</pre></section>
</div>
</span> |
p03966 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report <var>N</var> times, and when he checked it for the <var>i</var>-th <var>(1≦i≦N)</var> time, the ratio was <var>T_i:A_i</var>.
It is known that each candidate had at least one vote when he checked the report for the first time.</p>
<p>Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the <var>N</var>-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1≦N≦1000</var></li>
<li><var>1≦T_i,A_i≦1000 (1≦i≦N)</var></li>
<li><var>T_i</var> and <var>A_i</var> <var>(1≦i≦N)</var> are coprime.</li>
<li>It is guaranteed that the correct answer is at most <var>10^{18}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>T_1</var> <var>A_1</var>
<var>T_2</var> <var>A_2</var>
<var>:</var>
<var>T_N</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the <var>N</var>-th time.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 3
1 1
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>When the numbers of votes obtained by the two candidates change as <var>2,3 → 3,3 → 6,4</var>, the total number of votes at the end is <var>10</var>, which is the minimum possible number.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 1
1 1
1 5
1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>101
</pre>
<p>It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
3 10
48 17
31 199
231 23
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6930
</pre></section>
</div>
</span> |
p00219 |
<H1>ヒストグラム</H1>
<p>
テンアイスクリームという名前のアイスクリーム屋さんがあります。このお店では常に 10 種類のアイスクリームが店頭に並ぶようにしています。お店の店長は商品開発の参考にするために、アイスクリームの売れ具合を表すグラフを毎日作成しています。
</p>
<p>
そんな店長のために、あなたは各アイスクリームの販売数をグラフで表示するプログラムを作成することになりました。
</p>
<p>
一日に販売されるアイスクリームの総数と売れたアイスクリームの番号を入力とし、アイスクリームの種類ごとに販売した数だけ * (半角アスタリスク) を出力するプログラムを作成してください。ただし、アイスクリームの種類を 0 から 9 までの整数で表わします。また、販売個数がゼロのアイスクリームは、- (半角ハイフン) をひとつ出力します。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>c<sub>1</sub></var>
<var>c<sub>2</sub></var>
:
<var>c<sub>n</sub></var>
</pre>
<p>
1 行目に一日に販売されるアイスクリームの総数 <var>n</var> (1 ≤ <var>n</var> ≤ 10000) が与えられます。続く <var>n</var> 行に第 <var>i</var> のアイスクリームの種類 <var>c<sub>i</sub></var> (0 ≤ <var>c<sub>i</sub></var>≤ 9) が与えられます。
</p>
<p>
データセットの数は 20 を超えません。
</p>
<H2>Output</H2>
<p>
入力データセットごとに、各アイスクリームの種類の番号順に販売数を出力します。
</p>
<H2>Sample Input</H2>
<pre>
15
2
6
7
0
1
9
8
7
3
8
9
4
8
2
2
3
9
1
5
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
*
*
***
*
*
-
*
**
***
**
-
*
-
-
-
*
-
-
-
*
</pre>
|
p02224 | <span class="lang">
<span class="lang-ja">
<h1>N: 3人協力ゲーム</h1>
<p><span style='color: red;'>リアクティブ問題です。</span></p>
<div class="part">
<section>
<h3>問題文</h3><p>$1000$ ビットの非負整数が $200$ 個あり、$a_1, \ldots, a_{100}, b_1, \ldots, b_{100}$ とします。</p>
<p>アリスは $a_1, \ldots, a_{100}$ を確認し、$3000$ ビットのメモ $X$ をチャーリーのために残します。</p>
<p>ボブは $b_1, \ldots, b_{100}$ を確認し、$3000$ ビットのメモ $Y$ をチャーリーのために残します。</p>
<p>チャーリーはメモ $X, Y$ の情報をもとに、$100$ 個の質問に答えます。</p>
<p>$i$ 番目の質問は $1000$ ビットの非負整数 $c_i$ で表され、チャーリーは $a_{x_i}$ と $b_{y_i}$ のビットごとの排他的論理和が $c_i$ に等しくなるような $x_i, y_i$ を答えます。</p>
<p>$100$ 個の質問のうち、$95$ 個以上の質問に正答できる戦略を考えてください。</p>
</section>
</div>
<div class="part">
<section>
<h3>制約</h3><ul>
<li>$a_1, \ldots, a_{100}, b_1, \ldots, b_{100}, c_1, \ldots, c_{100}$ は $2$ 進数表記で与えられ、<code>0</code>,<code>1</code> からなる長さ $1000$ の文字列である。</li>
<li>$a_1, \ldots, a_{100}$ は互いに異なる。</li>
<li>$b_1, \ldots, b_{100}$ は互いに異なる。</li>
<li>$c_1, \ldots, c_{100}$ は互いに異なる。</li>
<li>$i = 1, 2, \ldots, 100$ について、$a_j$ と $b_k$ のビットごとの排他的論理和が $c_i$ になるような $j, k$ が存在する。</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>入出力とジャッジ</h3><p>あなたのプログラムは $1$ つのテストケースに対して $3$ 回実行される。</p>
<p>$1$ 回目の実行では次の入力形式でアリスへの情報が与えられる。</p>
<pre>Alice
$a_1$
$a_2$
$\vdots$
$a_{100}$
</pre>
<p>$1$ 行目に必ず <code>Alice</code> の文字列が与えられる。
この場合、入力を全て受け取った後 <code>0</code>,<code>1</code> からなる長さ $3000$ の文字列 $X$ を出力し、プログラムを即座に終了させなければならない。</p>
<p>$2$ 回目の実行では次の入力形式でボブへの情報が与えられる。</p>
<pre>Bob
$b_1$
$b_2$
$\vdots$
$b_{100}$
</pre>
<p>$1$ 行目に必ず <code>Bob</code> の文字列が与えられる。
この場合、入力を全て受け取った後 <code>0</code>,<code>1</code> からなる長さ $3000$ の文字列 $Y$ を出力し、プログラムを即座に終了させなければならない。</p>
<p>$3$ 回目の実行では次の入力形式でチャーリーへの質問およびメモの情報が与えられる。</p>
<pre>Charlie
$X$
$Y$
$c_1$
$c_2$
$\vdots$
$c_{100}$
</pre>
<p>$1$ 行目に必ず <code>Charlie</code> の文字列が与えられる。
入力を全て受け取った後 $1$ 以上 $100$ 以下の整数 $x_1, x_2, \ldots, x_{100}$ と $1$ 以上 $100$ 以下の整数 $y_1, y_2, \ldots, y_{100}$ を以下の形式で出力し、プログラムを即座に終了させなければならない。</p>
<pre>$x_1$ $y_1$
$x_2$ $y_2$
$\vdots$
$x_{100}$ $y_{100}$
</pre>
<p>ジャッジは、$i = 1, 2, \ldots, 100$ について $a_{x_i}$ と $b_{y_i}$ のビットごとの排他的論理和が $c_i$ に一致するか調べ、一致数が $95$ 個以上であれば正答、そうでなければ誤答と判定する。</p>
<p>不正な値や不正な形式での出力があった場合にも誤答とする。</p>
</section>
</div>
<div class="part">
<section>
<h3>注意</h3><ul>
<li>出力の度に標準出力を flush せよ。そうしない場合、TLE となる可能性がある。</li>
<li>どの種類の入力の末尾にも EOF が与えられる。</li>
<li><span style='color: red;'>プロセスは、上記によって規定された以外のいかなる通信も行ってはならない。</span></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>入出力例1</h3><p>以下はビット数や非負整数の数、質問の数が異なるが、$a = (000, 011), b = (110, 111), c = (101, 100)$ としたときの対話例である。</p>
<table class="table table-bordered">
<thead>
<tr>
<th align="left">解答プログラムの出力</th>
<th align="left">解答プログラムへの入力</th>
<th align="left">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"></td>
<td align="left"></td>
<td align="left">解答プログラム(アリス)が実行される</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">Alice<br>$000$<br>$011$</td>
<td align="left">アリスは $a = (000, 011)$ の情報を得る</td>
</tr>
<tr>
<td align="left">$0000110\ldots 0$</td>
<td align="left"></td>
<td align="left">アリスはメモ $X = 0000110\ldots 0$ を残す</td>
</tr>
<tr>
<td align="left"></td>
<td align="left"></td>
<td align="left">解答プログラム(アリス)の実行が終了し、新たな解答プログラム(ボブ)が実行される</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">Bob<br>$110$<br>$111$</td>
<td align="left">ボブは $b = (110, 111)$ の情報を得る</td>
</tr>
<tr>
<td align="left">$1101110\ldots 0$</td>
<td align="left"></td>
<td align="left">ボブはメモ $Y = 1101110\ldots 0$ を残す</td>
</tr>
<tr>
<td align="left"></td>
<td align="left"></td>
<td align="left">解答プログラム(ボブ)の実行が終了し、新たな解答プログラム(チャーリー)が実行される</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">Charlie<br>$0000110\ldots 0$<br>$1101110\ldots 0$<br>$101$<br>$100$</td>
<td align="left">チャーリーは $X, Y$ の情報を得たあと、質問の情報 $c = (101, 100)$ を得る</td>
</tr>
<tr>
<td align="left">$2$ $1$<br>$2$ $2$</td>
<td align="left"></td>
<td align="left">チャーリーは $1$ つ目の質問に対して $(x_1, y_1) = (2, 1)$、$2$ つ目の質問に対して $(x_2, y_2) = (2, 2)$ と回答する</td>
</tr>
</tbody>
</table></section>
</div>
</span>
</span>
|
p03065 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a polynomial of degree <var>N</var> with integer coefficients: <var>f(x)=a_Nx^N+a_{N-1}x^{N-1}+...+a_0</var>. Find all prime numbers <var>p</var> that divide <var>f(x)</var> for every integer <var>x</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq N \leq 10^4</var></li>
<li><var>|a_i| \leq 10^9(0\leq i\leq N)</var></li>
<li><var>a_N \neq 0</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_N</var>
<var>:</var>
<var>a_0</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print all prime numbers <var>p</var> that divide <var>f(x)</var> for every integer <var>x</var>, in ascending order.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
7
-7
14
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
7
</pre>
<p><var>2</var> and <var>7</var> divide, for example, <var>f(1)=14</var> and <var>f(2)=28</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1
4
1
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre></pre>
<p>There may be no integers that satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>0
998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>998244353
</pre></section>
</div>
</span> |
p01058 |
<h1>Point in The Triangle</h1>
<h2>Problem</h2>
<p>
点(0,0),(<var>n</var>-1,0),(0,<var>m</var>-1),(<var>n</var>-1,<var>m</var>-1)に囲まれた長方形の閉区間内から格子点を3点選び、三角形を作る。<br>
このとき、点(<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>)を含むが点(<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>)を含まない三角形の数と点(<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>)を含むが点(<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>)を含まない三角形の数の差の絶対値を求めよ。<br>
点が境界線上にあるものは三角形に含まれているとみなす。<br>
ただし、3点が一直線上に並んでいるものは三角形とはみなさない。
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
</pre>
<p>
入力は全て整数で与えられる。<br>
1行に<var>n</var>,<var>m</var>,<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>,<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>が空白区切りで与えられる。
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>n</var>,<var>m</var> ≤ 500</li>
<li>0 ≤ <var>x<sub>1</sub></var>,<var>x<sub>2</sub></var> ≤ <var>n</var>-1</li>
<li>0 ≤ <var>y<sub>1</sub></var>,<var>y<sub>2</sub></var> ≤ <var>m</var>-1</li>
<li>(<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>) ≠ (<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>)</li>
</ul>
<h2>Output</h2>
<p>
差の絶対値を1行に出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>
2 2 0 0 0 1
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2 1 0 0 0
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
|
p03435 | <span class="lang-en">
<p>Score: <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have a <var>3 \times 3</var> grid. A number <var>c_{i, j}</var> is written in the square <var>(i, j)</var>, where <var>(i, j)</var> denotes the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.<br/>
According to Takahashi, there are six integers <var>a_1, a_2, a_3, b_1, b_2, b_3</var> whose values are fixed, and the number written in the square <var>(i, j)</var> is equal to <var>a_i + b_j</var>.<br/>
Determine if he is correct. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3)</var> is an integer between <var>0</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>c_{1,1}</var> <var>c_{1,2}</var> <var>c_{1,3}</var>
<var>c_{2,1}</var> <var>c_{2,2}</var> <var>c_{2,3}</var>
<var>c_{3,1}</var> <var>c_{3,2}</var> <var>c_{3,3}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If Takahashi's statement is correct, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 0 1
2 1 2
1 0 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Takahashi is correct, since there are possible sets of integers such as: <var>a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 2
2 1 2
2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>Takahashi is incorrect in this case.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>0 8 8
0 8 8
0 8 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 8 6
2 9 7
0 7 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> |
p01408 |
<H1>B: Brilliant Stars</H1>
<p>
ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした.
</p>
<p>
今日の修行は,夜空に輝くたくさんの星たちを観測して,視力と集中力を鍛えようというものである.うさぎは独自のセンスで星の特徴を記録していくことができる.
</p>
<p>
うさぎは「星の観測日記」として記録した星の特徴をノートにつけていくことにした.ここで,「似ている」 2 つの星をともに記録することは避けたい.2 つの星が「似ている」かどうかは,すべてうさぎの判断で決まっている.「似ている」かどうかの関係はあまり複雑ではなく,以下の条件を満たす.
</p>
<blockquote style="padding-left:3em">
<p>
条件: 異なる 4 つの星 A, B, C, D があり,A と B,B と C,C と D がそれぞれ「似ている」とする.このとき,A と C が「似ている」か,B と D が「似ている」か,あるいはその両方が成り立つ.
</p>
</blockquote>
<p>
うさぎは「似ている」 2 つの星を記録しないようになるべくたくさんの星を記録したい.また,そのようにする方法が何通りあるかも知りたい.
</p>
<H2>Input</H2>
<pre>
<i>N</i> <i>M</i>
<i>X</i><sub>1</sub> <i>Y</i><sub>1</sub>
...
<i>X</i><sub><i>M</i></sub> <i>Y</i><sub><i>M</i></sub>
</pre>
<p>
<i>N</i> は星の個数,<i>M</i> は「似ている」 2 つの星の組の個数である.星は 1 以上 <i>N</i> 以下の整数の番号により表され,<i>X</i><sub><i>i</i></sub>, <i>Y</i><sub><i>i</i></sub> (1 ≤ <i>i</i> ≤ <i>M</i>) は星 <i>X</i><sub><i>i</i></sub> と星 <i>Y</i><sub><i>i</i></sub> が「似ている」ことを表す.
</p>
<p>
1 ≤ <i>N</i> ≤ 100,000,0 ≤ <i>M</i> ≤ 200,000,1 ≤ <i>X</i><sub><i>i</i></sub> < <i>Y</i><sub><i>i</i></sub> ≤ <i>N</i> を満たす.(<i>X</i><sub><i>i</i></sub>, <i>Y</i><sub><i>i</i></sub>) として同一の組は複数回現れない.「似ている」かどうかの関係は,問題文で指定された条件を満たす.
</p>
<H2>Output</H2>
<p>
1 行目に,「似ている」 2 つの星を記録しないように記録できる星の個数の最大値を,2 行目に,その最大値を実現できる星の組み合わせの個数 (記録する順番のみを変えたものは同じと考える) を 1,000,000,009 で割った余りを出力せよ.
</p>
<H2>Sample Input 1</H2>
<pre>
4 3
1 2
1 3
1 4
</pre>
<H2>Sample Output 1</H2>
<pre>
3
1
</pre>
<H2>Sample Input 2</H2>
<pre>
11 5
1 2
3 4
5 6
7 8
9 10
</pre>
<H2>Sample Output 2</H2>
<pre>
6
32
</pre>
<H2>Sample Input 3</H2>
<pre>
9 14
1 2
1 3
2 3
3 4
3 5
3 6
3 7
3 8
3 9
4 5
4 6
5 6
7 8
8 9
</pre>
<H2>Sample Output 3</H2>
<pre>
4
6
</pre> |
p01326 |
<h1><font color="#000">Problem F:</font> UTF-8</h1>
<p>UTF-8はマルチバイト文字を符号化する手法の一つである。</p>
<p>文字は計算機上ではバイト列として扱われる。英語だけであればラテンアルファベットおよび数字、記号を合わせても 1byteで表現できるが、残念ながら世界中で利用されている文字を1byteで表現することはできないため、複数のバイトを用いて文字を表す必要がある。</p>
<p>ここで例えば"あ"という文字に12354(0x3042)という2バイト列を割り当てたとき、そのままバイト列を並べると0x30,0x42と2文字なのか0x3042で1文字なのかが区別がつかない。</p>
<p>このため、マルチバイト文字符号化方式のUTF-8では始めの1バイト目で続くバイト列の長さが分かるようにすることにより、この問題を克服している。具体的なビットパターンは以下のようになる。</p>
<table>
<tr><th>バイト長</th><th>ビットパターン</th></tr>
<tr><td>1</td><td style='text-align: left'>0xxxxxxx</td></tr>
<tr><td>2</td><td style='text-align: left'>110yyyyx 10xxxxxx</td></tr>
<tr><td>3</td><td style='text-align: left'>1110yyyy 10yxxxxx 10xxxxxx</td></tr>
<tr><td>4</td><td style='text-align: left'>11110yyy 10yyxxxx 10xxxxxx 10xxxxxx</td></tr>
</table>
<p>ここでxは0/1の任意のビットとする。またyも0/1の任意のビットとなるがどれか一つは1である必要がある。また全ての文字は1,2,3,4バイト文字のいずれかであるとする。</p>
<p>ここでyのビットが少なくとも一つは1であるという制約は以下のような理由による。 例えば'/'(0x2f)をバイト列にエンコードする際に0x2fと1バイトで符号化するないしは0xc0 0xafと2バイトで符号化する方法の二つがあるが、このような曖昧性を許すとセキュリティ上の脅威のもととなる可能性があるためである。</p>
<p>以上の話を聞いたあなたはUTF-8がどの程度の自由度があるのかが気になった。具体的には与えられたバイト列の一部のビットが不明な時にUTF-8として可能なバイト列の組み合わせがどの程度あるかということである。</p>
<p>このとき可能なバイト列の組み合わせの個数を求め、1,000,000で割った余りを出力せよ。
</p>
<h2>Input</h2>
<pre>N
b<sub>1</sub>
b<sub>2</sub>
...
b<sub>N</sub></pre>
<p>Nはバイト列の個数, b<sub>i</sub>はバイト列である。
1 ≤ N ≤ 1000 を満たしている。 b<sub>i</sub>は記号{0/1/x}が8個並んでいる。xはビットが不明であることを示している。
</p>
<h2>Output</h2>
<p>可能なバイト列の組み合わせの個数を1,000,000で割った余りを出力せよ。
</p>
<h2>Notes on Test Cases</h2>
<p>
上記入力形式で複数のデータセットが与えられます。各データセットに対して上記出力形式で出力を行うプログラムを作成して下さい。
</p>
<p>
N が 0 のとき入力の終わりを示します。
</p>
<!--
<h2>Sample Input 1</h2>
<pre>1
xxxxxxxx
</pre>
<h2>Output for Sample Input 1</h2>
<pre>128
</pre>
<h2>Sample Input 2</h2>
<pre>3
11100000
10x00000
10111111
</pre>
<h2>Output for Sample Input 2</h2>
<pre>1
</pre>
<h2>Sample Input 3</h2>
<pre>3
11100000
10000000
10111111
</pre>
<h2>Output for Sample Input 3</h2>
<pre>0
</pre>
<h2>Sample Input 4</h2>
<pre>4
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
</pre>
<h2>Output for Sample Input 4</h2>
<pre>778240
</pre>
-->
<h2>Sample Input</h2>
<pre>
1
xxxxxxxx
3
11100000
10x00000
10111111
3
11100000
10000000
10111111
4
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
0
</pre>
<h2>Output for Sample Input</h2>
<pre>
128
1
0
778240
</pre>
|
p02859 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>r</var>.</p>
<p>How many times is the area of a circle of radius <var>r</var> larger than the area of a circle of radius <var>1</var>?</p>
<p>It can be proved that the answer is always an integer under the constraints given.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq r \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>r</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the area of a circle of radius <var>r</var>, divided by the area of a circle of radius <var>1</var>, as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The area of a circle of radius <var>2</var> is <var>4</var> times larger than the area of a circle of radius <var>1</var>.</p>
<p>Note that output must be an integer - for example, <code>4.0</code> will not be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10000
</pre></section>
</div>
</span> |
p00864 |
<H1><font color="#000">Problem A:</font> Grey Area</H1>
<p>
Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the
world everyday. He is extremely good at sophisticated visualization tools, but yet his favorite is
a simple self-made histogram generator.
</p>
<p>
Figure 1 is an example of histogram automatically produced by his histogram.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_greyarea1">
</center>
<p>
A histogram is a visual display of frequencies of value occurrences as bars. In this example, values
in the interval 0-9 occur five times, those in the interval 10-19 occur three times, and 20-29
and 30-39 once each.
</p>
<p>
Dr. Grey’s histogram generator is a simple tool. First, the height of the histogram is fixed, that
is, the height of the highest bar is always the same and those of the others are automatically
adjusted proportionately. Second, the widths of bars are also fixed. It can only produce a
histogram of uniform intervals, that is, each interval of a histogram should have the same width
(10 in the above example). Finally, the bar for each interval is painted in a grey color, where
the colors of the leftmost and the rightmost intervals are black and white, respectively, and the
darkness of bars monotonically decreases at the same rate from left to right. For instance, in
Figure 1, the darkness levels of the four bars are 1, 2/3, 1/3, and 0, respectively.
</p>
<p>
In this problem, you are requested to estimate ink consumption when printing a histogram on paper. The amount of ink necessary to draw a bar is proportional to both its area and darkness.
<H2>Input</H2>
<p>
The input consists of multiple datasets, each of which contains integers and specifies a value
table and intervals for the histogram generator, in the following format.
</p>
<p>
<i>n</i> <i>w</i><br>
<i>v<sub>1</sub></i><br>
<i>v<sub>2</sub></i><br>
.<br>
.<br>
<i>v<sub>n</sub></i><br>
</p>
<p>
<i>n</i> is the total number of value occurrences for the histogram, and each of the <i>n</i> lines following
the first line contains a single value. Note that the same value may possibly occur multiple
times.
</p>
<p>
<i>w</i> is the interval width. A value <i>v</i> is in the first (i.e. leftmost) interval if 0 ≤ <i>v</i> < <i>w</i>, the second
one if <i>w</i> ≤ <i>v</i> < 2<i>w</i>, and so on. Note that the interval from 0 (inclusive) to <i>w</i> (exclusive) should
be regarded as the leftmost even if no values occur in this interval. The last (i.e. rightmost)
interval is the one that includes the largest value in the dataset.
</p>
<p>
You may assume the following.
</p>
<p>
1 ≤ <i>n</i> ≤ 100<br>
10 ≤ <i>w</i> ≤ 50<br>
0 ≤ <i>v<sub>i</sub></i> ≤ 100 for 1 ≤ i ≤ <i>n</i><br>
</p>
<p>
You can also assume that the maximum value is no less than <i>w</i>. This means that the histogram
has more than one interval.
The end of the input is indicated by a line containing two zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line containing the amount of ink consumed in printing the histogram.
</p>
<p>
One unit of ink is necessary to paint one highest bar black. Assume that 0.01 units of ink per
histogram is consumed for various purposes except for painting bars such as drawing lines and
characters (see Figure 1). For instance, the amount of ink consumed in printing the histogram
in Figure 1 is:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_greyarea2">
</center>
<p>
Each output value should be in a decimal fraction and may have an error less than 10<sup>-5</sup> .
</p>
<H2>Sample Input</H2>
<pre>
3 50
100
0
100
3 50
100
100
50
10 10
1
2
3
4
5
16
17
18
29
30
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.51
0.26
1.4766666666666667
</pre>
|
p01776 |
<h2>E: Do You Divide It? / 切り刻む気か?</h2>
<h3>物語</h3>
<p>T君は過去に出場したプログラミングコンテストで平面図形の問題にひどく手こずらされ,それ以来,平面図形に強い恨みを抱いている.</p>
<p>中でも,特に二次元平面上に描かれる多角形に対して複雑な感情を抱いているため,多角形を見かけると切り刻まずにはいられない.</p>
<p>T君が多角形を切り刻むときには,y軸に平行に幅<var>0.5</var>の間隔でスリットの入った板で多角形を覆い,スリットで見えない部分を切り刻んで捨ててしまう.</p>
<p>しかしながら,T君は一方的な殺戮を好まないため,多角形に再起の芽を残すべく,切り刻んだ後に残る図形の合計面積ができるだけ大きくなるように配慮する.</p>
<p>T君が切り刻んだ後に残る図形の面積を求めよう.</p>
<h3>問題</h3>
<p>二次元平面にy軸方向無限長のスリットが入っており,x軸方向に<var>0.5</var>ごとに見える部分と見えない部分が切り替わるようになっている.</p>
<p>下図のように,この平面上で,<var>N</var>個の頂点からなる多角形がx軸正方向に向けて平行移動し続ける.</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_E-sample01" />
<p>多角形が見える部分が最も大きくなる瞬間の,見えている部分の面積を出力せよ.</p>
<h3>入力形式</h3>
<p><var>1</var>行目で<var>N</var>を与える.続く<var>N</var>行の<var>i</var>行目で,多角形の反時計回りでの<var>i</var>番目の頂点座標(<var>x_i</var>,<var>y_i</var>)を与える.</p>
<p>以下を仮定してよい.</p>
<ul>
<li>入力はすべて整数</li>
<li><var>3 ≤ N ≤ 100</var>, <var>−10^3 ≤ x_i, y_i ≤ 10^3</var></li>
<li>与えられる多角形は,隣接する線分以外と辺や頂点を共有することはない</li>
<li>与えられる多角形の連続する3つの頂点は同一直線上にない</li>
</ul>
<h3>出力形式</h3>
<p>
与えられた多角形の見える部分が最も大きくなる瞬間の,見える面積を<var>1</var>行で出力せよ.
絶対誤差,相対誤差は <var>10^{−5}</var> まで許容する.
</p>
<h3>入力例1</h3>
<pre>
6
0 0
-1 -2
3 -2
2 0
3 2
-1 2
</pre>
<h3>出力例1</h3>
<pre>6.000000000</pre>
<h3>入力例2</h3>
<pre>
5
0 0
2 -2
4 -2
4 2
2 2
</pre>
<h3>出力例2</h3>
<pre>6.50000000</pre> |
p00537 |
<h2>鉄道旅行 (Railroad Trip)</h2>
<p>
JOI 国には <var>N</var> 個の都市があり,それぞれ 1, 2, . . . , <var>N</var> の番号が付けられている.また,鉄道が <var>N</var> − 1 本あり,それぞれ 1, 2, . . . , <var>N</var> − 1 の番号が付けられている.鉄道 i (1 ≤ <var>i</var> ≤ <var>N</var> − 1) は,都市 <var>i</var> と都市 <var>i</var> + 1 を双方向に結んでいる.
<p>
JOI 国の鉄道に乗車する方法として,紙の切符で乗車する方法と,IC カードで乗車する方法がある.
</p>
<ul>
<li> 鉄道 <var>i</var> に紙の切符で乗車する場合の運賃は <var>A<sub>i</sub></var> 円である.</li>
<li> 鉄道 <var>i</var> に IC カードで乗車する場合の運賃は <var>B<sub>i</sub></var> 円である.ただし,IC カードで鉄道 <var>i</var> に乗車するには,鉄道 <var>i</var> で使える IC カードを事前に購入しておく必要がある.鉄道 <var>i</var> で使える IC カードを購入するには <var>C<sub>i</sub></var> 円かかる.一度購入した IC カードは,何度でも使用することができる.</li>
</ul>
<p>
IC カードの方が金額の処理が簡単になるため,IC カードで乗車する場合の運賃の方が紙の切符で乗車する場合の運賃よりも安い.すなわち, <var>i</var> = 1, 2, . . . , <var>N</var> − 1 に対して, <var>A<sub>i</sub></var> > <var>B<sub>i</sub></var> が成り立つ.IC カードの仕様は鉄道ごとにすべて異なるため,どの <var>i</var> に対しても,鉄道 <var>i</var> で使える IC カードを他の鉄道で使用することはできない.
</p>
<p>
あなたは,JOI 国じゅうを旅行することにした.都市 <var>P<sub>1</sub></var> から出発し,<var>P<sub>2</sub></var>, <var>P<sub>3</sub></var>, . . . , <var>P<sub>M</sub></var> の順に都市を訪れる予定である.旅行は <var>M</var> − 1 日間の行程からなる.<var>j</var> 日目 (1 ≤ <var>j</var> ≤ <var>M</var> − 1) に都市 <var>P<sub>j</sub></var> から都市 <var>P<sub>j+1</sub></var> に鉄道で移動する.この際,いくつかの鉄道を乗り継いで移動することもある.また,同じ都市を二度以上訪れることがあるかもしれない.JOI 国の鉄道は速いので,どの都市からどの都市へも 1 日で移動することができる.
</p>
<p>
あなたは現在,どの鉄道の IC カードも持っていない.あなたは,あらかじめ,いくつかの鉄道の IC カー
ドを購入し,この旅行にかかる金額,すなわち,IC カード購入費用と乗車した鉄道の運賃の和をできるだけ少なくしたい.
</p>
<h3>課題</h3>
<p>
JOI 国の都市の数,旅行の行程,および JOI 国のそれぞれの鉄道の運賃と IC カードの価格が与えられる.このとき,旅行にかかる金額の最小値を求めるプログラムを作成せよ.
</p>
<h3>入力</h3>
<p>
標準入力から以下のデータを読み込め.
</p>
<ul>
<li> 1 行目には,整数 <var>N</var>, <var>M</var> が空白を区切りとして書かれている.これらはそれぞれ,JOI 国に都市が <var>N</var> 個あり,旅行が <var>M</var> − 1 日間の行程からなることを表す. </li>
<li> 2 行目には,<var>M</var> 個の整数 <var>P<sub>1</sub></var>, <var>P<sub>2</sub></var>, . . . , <var>P<sub>M</sub></var> が空白を区切りとして書かれている.これらは,<var>j</var> 日目 (1 ≤ <var>j</var> ≤ <var>M</var> − 1) に都市 <var>P<sub>j</sub></var> から都市 <var>P<sub>j+1</sub></var> に鉄道で移動することを表す.</li>
<li> 続く <var>N</var> − 1 行のうちの <var>i</var> 行目 (1 ≤ <var>i</var> ≤ <var>N</var> − 1) には,3 つの整数 <var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>, <var>C<sub>i</sub></var> が空白を区切りとして書かれている.これらはそれぞれ,鉄道 <var>i</var> に紙の切符で乗車したときの運賃が <var>A<sub>i</sub></var> 円,IC カードで乗車したときの運賃が <var>B<sub>i</sub></var> 円,鉄道 <var>i</var> で使える IC カードの金額が <var>C<sub>i</sub></var> 円であることを表す.
</ul>
<h3>出力</h3>
<p>
標準出力に,旅行にかかる金額の最小値を円単位で表す整数を 1 行で出力せよ.
</p>
<h3>制限</h3>
<p>
すべての入力データは以下の条件を満たす.
</p>
<ul>
<li> 2 ≤ <var>N</var> ≤ 100 000. </li>
<li> 2 ≤ <var>M</var> ≤ 100 000.</li>
<li> 1 ≤ <var>B<sub>i</sub></var> < <var>A<sub>i</sub></var> ≤ 100 000 (1 ≤ <var>i</var> ≤ <var>N</var> − 1).</li>
<li> 1 ≤ <var>C<sub>i</sub></var> ≤ 100 000 (1 ≤ <var>i</var> ≤ <var>N</var> − 1).</li>
<li> 1 ≤ <var>P<sub>j</sub></var> ≤ <var>N</var> (1 ≤ <var>j</var> ≤ <var>M</var>).</li>
<li> <var>P<sub>j</sub></var> ≠ <var>P<sub>j+1</sub></var> (1 ≤ <var>j</var> ≤ <var>M</var> − 1). </li>
</ul>
<h3>入出力例</h3>
<h3>
入力例 1
</h3>
<pre>
4 4
1 3 2 4
120 90 100
110 50 80
250 70 130
</pre>
<h3>出力例 1</h3>
<pre>
550
</pre>
<p>
この場合,旅行にかかる金額を最小にする方法は以下のとおりである.
</p>
<ul>
<li> 鉄道 2 と鉄道 3 の IC カードを購入する.これには 80 + 130 = 210 円かかる.</li>
<li> 1 日目に,都市 1 から都市 2 まで紙の切符を使って移動し,次に都市 2 から都市 3 まで IC カードを使って移動する.これには 120 + 50 = 170 円かかる.</li>
<li> 2 日目に,都市 3 から都市 2 まで IC カードを使って移動する.これには 50 円かかる.</li>
<li> 3 日目に,都市 2 から都市 3 まで IC カードを使って移動し,次に都市 3 から都市 4 まで IC カードを使って移動する.これには 50 + 70 = 120 円かかる.</li>
</ul>
<p>
このように移動すると,旅行にかかる金額の合計は 210 + 170 + 50 + 120 = 550 円となる.これが最小であるので,550 と出力する.
</p>
<h3>入力例 2</h3>
<pre>
8 5
7 5 3 5 4
12 5 8
16 2 1
3 1 5
17 12 17
19 7 5
12 2 19
4 1 3
</pre>
<h3>出力例 2</h3>
<pre>
81
</pre>
<div class="source">
<p class="source">
問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00167 |
<H1>バブルソート</H1>
<p>
データを並べ替えるための整列(ソート)アルゴリズムはコンピュータ科学には欠かせない基本的なアルゴリズムです。例えば、下図のように「整数値の配列の要素を昇順に並べ替える」という操作が整列です。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bubbleSort1"><br>
</center>
<p>
多くの整列アルゴリズムが考案されてきましたが、その中でも基本的なアルゴリズムの1つがバブルソートです。例として、与えられた整数値の配列をバブルソートで昇順に並べてみます。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bubbleSort2"><br/>
</center>
<br/>
<p>
バブルソートでは、各計算ステップにおいて、配列を「ソートされた部分」と「ソートされていない部分」に分けて考えます。最初は配列全体がソートされていない部分になります。
</p>
<p>
ソートされていない部分の先頭から、隣同士の要素を比較して(図では緑色の要素)、大きい値が右にくるようにそれらを交換します。二つの値が等しい場合は交換しません。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bubbleSort3"><br/>
<br/>
</center>
<p>
この処理をソートされていない部分(図では白色の要素)の末尾まで繰り返します。最後に、末尾をソートされている部分(図では青色の要素)に追加して1ステップが完了します。
</p>
<p>
このステップをソートされていない部分の長さが1になるまで繰り返します。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bubbleSort4"><br/>
<br/>
<br/>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bubbleSort5"><br/>
<br/>
<br/>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bubbleSort6"><br/>
<br/>
</center>
<p>
このようにソートされていない部分の長さが 1 になったら、ソートの処理を終了します。
</p>
<p>
それでは、<var>n</var> 個の数値の配列を入力とし、数値が配列の先頭から昇順に並ぶように上記のバブルソートの手順で並べ替えを行い、要した配列要素の交換回数を出力するプログラムを作成してください。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var>
<var>a<sub>2</sub></var>
:
<var>a<sub>n</sub></var>
</pre>
<p>
1行目に数値の数 <var>n</var> (1 ≤ <var>n</var> ≤ 100)、続く <var>n</var> 行に<var>i</var> 番目の数値 <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 1000000) が与えられます。
</p>
<p>
データセットの数は 20 を超えません。
</p>
<H2>Output</H2>
<p>
データセットごとにデータ要素の交換回数(整数)を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
5
5
3
2
1
4
6
1
2
3
4
5
6
3
3
2
1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
7
0
3
</pre>
|
p00472 |
<H1>旅人</H1>
<h2> 問題</h2>
<p>
あなたは JOI 街道を旅する旅人である.JOI 街道は東西にまっすぐに延びた道路で,JOI 街道上には n 個の宿場町がある.宿場町には西から東の順に 1 から n までの番号が付けられている.JOI 街道上の最も西の宿場町が宿場町 1 であり,最も東の宿場町が宿場町 n である.
</p>
<p>
あなたは,宿場町 1 から出発して m 日間の旅に出ることになった.あなたの旅程は数列 a1 , a2 , . . . , am に従い,次のように決められている.ai は i 日目の移動方法を表す 0 ではない整数である.i 日目にあなたが出発する宿場町を宿場町 k とおくと,i 日目にあなたは宿場町 k から宿場町 k + ai までまっすぐに移動することを意味する.
</p>
<p>
宿場町の個数 n,旅の日数 m,宿場町間の距離の情報と,移動方法を表す数列a1 , a2 , . . . , am が与えられたとき,m 日間の旅におけるあなたの移動距離の合計を100000 = 10<sup>5</sup> で割った余りを求めるプログラムを作成せよ.
</p>
<h2>入出力の例に対応する図</h2>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0549">
</center>
<h2>入力</h2>
<!--
<p>
入力ファイルのファイル名は input.txt である.
</p>
-->
<p>
1 行目には整数 n, m が空白区切りで書かれている.n (2 ≤ n ≤ 100000 = 10<sup>5</sup> ) はJOI 街道上の宿場町の個数を,m (1 ≤ m ≤ 100000 = 10<sup>5</sup> ) は旅の日数を表す.
</p>
<p>
続く n − 1 行は JOI 街道上の宿場町間の距離を表す.i + 1 行目 (1 ≤ i ≤ n − 1) に
は宿場町 i と宿場町 i + 1 の距離を表す正整数 si (1 ≤ si ≤ 100) が書かれている.
</p>
<p>
続く m 行には m 日間の移動方法を表す数列が書かれている.i + n 行目 (1 ≤ i ≤ m)
には i 日目のあなたの移動方法を表す 0 ではない整数 ai が書かれている.
</p>
<p>
採点用データにおいて,宿場町 1 より西に移動することや,宿場町 n より東に移
動することはない.
</p>
<p>
採点用データのうち,配点の 50% 分については,n ≤ 100 かつ m ≤ 100 を満たす.
</p>
<h2> 出力</h2>
<p>
<!--出力ファイルのファイル名は output.txt である.-->
<!--output.txt-->出力 は, m 日間の旅におけるあなたの移動距離の合計を 100000 = 10<sup>5</sup> で割った余りを含む 1 行からなる.
</p>
<h2> 入出力例</h2>
<h3>入力例 1</h3>
<pre>
7 5
2
1
1
3
2
1
2
-1
3
2
-3
</pre>
<h3>出力例 1</h3>
<pre>
18
</pre>
<p>
1 日目に,あなたは宿場町 1 から宿場町 3 まで移動する.2 日目に,あなたは宿場
町 3 から宿場町 2 まで移動する.そして,3 日目に宿場町 2 から宿場町 5 まで移動
し,4 日目に宿場町 5 から宿場町 7 まで移動し,5 日目に宿場町 7 から宿場町 4 ま
で移動する.5 日間の旅におけるあなたの移動距離の合計は 18 である.
</p>
<div class="source">
<p class="source">
上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。
</p>
</div>
|
p00188 |
<H1>探索</H1>
<p>
「探索」とは、たくさんの情報の中から望みの情報を得る操作のことです。身近な例では、合格発表の時の「たくさんの受験番号から自分の受験番号を見つける」ことや、電話帳から「会津太郎さんの電話番号を見つける」ときなどがあります。この探索という操作はコンピュータの分野でも広く用いられています。
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_search">
</center>
<br/>
<p>
探索の方法は沢山あります。探索の対象となるデータが、小さい順(または大きい順)に並べられている場合に使うことができる探索の方法を考えます。
</p>
<p>
小さい順(または大きい順)に並べられているデータ列の中央に位置する値と目的の値との大小関係を用いて、中央に位置する値から前半部分を探索範囲にするか後半部分を探索範囲にするかを決めることで、探索の範囲を絞っていく方法があります。手順は以下のようになります。
</p>
<ol>
<li>データの列の全体を探索の範囲とします。</li>
<li>探索の範囲の中央に位置する値を調べます。</li>
<li>目的の値と中央に位置する値が一致すれば探索を終了します。</li>
<li>目的の値と中央に位置する値よりも小さければ前半部分を探索の範囲とし、大きければ後半部分を探索の範囲として2.へ戻ります。</li>
</ol>
<p>
以下は上述した探索の方法の例です。この例での目的の値は51です。それぞれのデータには番号
(index)が振られており、この番号は0から始まっています。
</p>
<center>
<table>
<tr>
<td valign="top" style="vertical-align:top">
<br/><br/><br/>
<p>
ステップ1: 最初は番号0~6全体を探索の範囲とします。
</p>
<p>
ステップ2: 探索の範囲の中央に位置する値を調べます。ただし、「中央に位置する値」とは、(左側の番号+右側の番号)を2で割った番号の位置にある値とします。つまり、この場合、(0 + 6) ÷ 2 を計算し、番号3にある値(36)が中央に位置する値となります。
</p>
<p>
ステップ3:目的の値(51)と中央に位置する値(36)を比較します。
</p>
<p>
ステップ4:ステップ3の結果から、目的の値は中央に位置する値より大きいので、後半部分にあたる番号4 (中央に位置する値の隣)以降を探索の範囲とします。同様の手順で探索の範囲の中央に位置する値を調べ、目的の値が中央に位置する値より小さければ前半部分を探索の範囲とし、大きければ後半部分を探索の範囲として、探索の範囲を小さくしていきます。(ステップ2~ステップ4の繰り返し)目的の値が中央に位置する値と一致するか、探索の範囲がつきてしまった時に探索を終了します。
</p>
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_searchFlow">
</td>
</tr>
</table>
</center>
<br/>
<p>
<var>n</var> 個の数値の配列を入力とし、目的の値と中央に位置する値を比較した回数を出力するプログラムを作成してください。ただし、中央に位置する値の番号を計算したとき、割り切れない場合は、小数点以下を切り捨てた値をその番号とすることとします。
与えられるデータ列は小さい順に整列されているものとします。
</p>
<H2>Input</H2>
<p>
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。 各データセットは以下の形式で与えられます。
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var>
<var>a<sub>2</sub></var>
:
<var>a<sub>n</sub></var>
<var>k</var>
</pre>
<p>
1 行目に数値の数 <var>n</var> (1 ≤ <var>n</var> ≤ 100) 、続く <var>n</var> 行に <var>i</var> 個目の数値 <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 100000, 整数) が与えられます。
</p>
<p>
続く行に探索する値 <var>k</var> (1 ≤ <var>k</var> ≤ 100000) が与えられます。
</pre>
<H2>Output</H2>
<p>
データセット毎に探索が終わるまでの比較回数を1行に出力します。
</p>
<H2>Sample Input</H2>
<pre>
7
11
15
23
36
51
61
86
51
4
1
2
3
5
4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
3
</pre>
|
p00022 |
<H1>Maximum Sum Sequence</H1>
<p>
Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each data set consists of:
<pre>
<var>n</var>
<var>a<sub>1</sub></var>
<var>a<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>
</pre>
<p>
You can assume that 1 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 100000.
</p>
<p>
The input end with a line consisting of a single 0.
</p>
<H2>Output</H2>
<p>
For each dataset, print the maximum sum in a line.
</p>
<H2>Sample Input</H2>
<pre>
7
-5
-1
6
4
9
-6
-7
13
1
2
3
2
-2
-1
1
2
3
2
1
-2
1
3
1000
-200
201
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
19
14
1001
</pre>
|
p01263 |
<H1><font color="#000">Problem D:</font> Reaction</H1>
<p>
You are a hero of a role playing game, asked by the king to defeat monsters threating people’s life.
</p>
<p>
You have been making a long journey with your colleagues, and you are now in the town closest to the
final dungeon where the head of monsters dwells. You have heard from people that the head monster hits
with his strong arms, casts powerful spells, and has many special abilities, and your party would be easily
killed off without powerful equipments due to severe damages. Thus you need to prepare the equipments.
</p>
<p>
On the other hand, you have a number of magical spheres collected during the journey. Those spheres
are not useful themselves, but they can be turned into special items by a spell of reaction. You can obtain
some amount of money by selling those special items to shops in the town, then buy the equipments by
that money.
</p>
<p>
The spell of reaction works as follows. Each sphere has a color, and either positive attribute or negative
attribute. You choose one sphere with positive attribute and another with negative attribute, and you cast
the spell to the two spheres. Then the spheres will make reaction to have a set of special items produced.
Those spheres will disappear after the reaction. The set of items you will obtain solely depends on the
colors of the two spheres. You can cast the spell as many as you want, but of course you cannot cast the
spell to spheres that have disappeared. Also, not all pairs of colors of spheres make reaction.
</p>
<p>
It is natural that you want to obtain money as much as possible. So you should choose carefully the pairs
of spheres before casting the spell. On the other hand, you should be an excellent programmer, so it
should be an easy task to write a program that finds the best way using your computer.
</p>
<p>
Your task is now clear - write a program and get ready for the battle with the head monster!
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows:
</p>
<pre>
<i>N</i><sup>-</sup> <i>N</i><sup>+</sup>
<i>Number of available spheres</i>
<i>Definition of items</i>
<i>Definition of reactions</i>
</pre>
<p>
The first line contains two integers <i>N</i><sup>-</sup> and <i>N</i><sup>+</sup>, which are the numbers of different colors of spheres with
negative and positive attributes, respectively. The rest of the dataset is divided into three parts.
</p>
<p>
The first part describes the number of available spheres. This part has the following format:
</p>
<pre>
<i>K</i><sub>1</sub><sup>-</sup> <i>K</i><sub>2</sub><sup>-</sup> ... <i>K</i><sub><i>N</i><sup>-</sup></sub><sup>-</sup>
<i>K</i><sub>1</sub><sup>+</sup> <i>K</i><sub>2</sub><sup>+</sup> ... <i>K</i><sub><i>N</i><sup>+</sup></sub><sup>+</sup>
</pre>
<p>
<i>K</i><sub><i>i</i></sub><sup>-</sup> is the number of spheres of the <i>i</i>-th color with negative attribute, and <i>K</i><sub><i>i</i></sub><sup>+</sup> is the number of spheres of
the <i>i</i>-th color with positive attribute.
</p>
<p>
The second part contains the definition of items. This part is formatted as follows:
</p>
<pre>
<i>M</i>
<i>A</i><sub>1</sub> <i>P</i><sub>1</sub>
...
<i>A<sub>M</sub></i> <i>P<sub>M</sub></i>
</pre>
<p>
Here, <i>M</i> is the number of items that can be produced. Each of the following <i>M</i> lines contains a string <i>A<sub>i</sub></i>
and an integer <i>P<sub>i</sub></i>, which are the name and the selling price of the <i>i</i>-th item respectively.
</p>
<p>
The last part gives the details of reactions. This part has the following format:
</p>
<pre>
<i>L</i>
<i>I</i><sub>1</sub><sup>-</sup> <i>I</i><sub>1</sub><sup>+</sup> <i>NJ</i><sub>1</sub> <i>J</i><sub>1,1</sub> ... <i>J</i><sub>1,<i>NJ</i><sub>1</sub></sub>
...
<i>I</i><sub><i>L</i></sub><sup>-</sup> <i>I</i><sub><i>L</i></sub><sup>+</sup> <i>NJ</i><sub><i>L</i></sub> <i>J</i><sub><i>L</i>,1</sub> ... <i>J</i><sub><i>L</i>,<i>NJ</i><sub><i>L</i></sub></sub>
</pre>
<p>
The first line contains an integer <i>L</i>, which is the number of pairs of colors of spheres that can make
reaction. Each of the next <i>L</i> lines starts with two integers <i>I</i><sub><i>i</i></sub><sup>-</sup> and <i>I</i><sub.<i>i</i></sub><sup>+</sup>, which denote the colors of negative
and positive spheres respectively. The next integer <i>NJ<sub>i</sub></i> is the number of items produced by reaction
between spheres <i>I</i><sub><i>i</i></sub><sup>-</sup> and <i>I</i><sub><i>i</i></sub><sup>+</sup>. The line is then followed by <i>NJ<sub>i</sub></i> strings, each of which is an item name.
</p>
<p>
You may assume all the following: 1 ≤ <i>N</i><sup>-</sup>, <i>N</i><sup>+</sup> ≤ 100; 1 ≤ <i>K</i><sub><i>i</i></sub><sup>-</sup>, <i>K</i><sub><i>i</i></sub><sup>+</sup> ≤ 100; 1 ≤ <i>M</i> ≤ 100; 1 ≤ <i>P<sub>i</sub></i> ≤ 100;
1 ≤ <i>L</i> ≤ 100; 1 ≤ <i>NJ<sub>i</sub></i> ≤ 10. You may also assume that an item name consists only of alphanumeric
characters and the length of the name does not exceed ten.
</p>
<p>
The end of input is represented by a line with two zeros. This line is not part of any dataset.
</p>
<H2>Output</H2>
<p>
For each dataset, print a line that contains the maximum possible total selling price.
</p>
<H2>Sample Input</H2>
<pre>
2 2
1 1
1 1
4
A 10
B 20
C 30
D 40
4
1 1 3 A A A
1 2 2 B C
2 1 1 D
2 2 3 A A B
2 2
1 2
2 1
3
Scroll 50
Bastard 100
Heal100 10
3
1 1 1 Scroll
2 1 1 Bastard
2 2 1 Heal100
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
90
200
</pre>
|
p01799 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem J
New Game AI</h2>
<p>
Aoba is a beginner programmer who works for a game company. She was appointed to develop a battle strategy for the enemy AI (Artificial Intelligence) in a new game. In this game, each character has two parameters, hit point ($hp$) and defence point ($dp$). No two characters have the same $hp$ and $dp$ at the same time. The player forms a party by selecting one or more characters to battle with the enemy. Aoba decided to develop a strategy in which the AI attacks the weakest character in the party: that is, the AI attacks the character with the minimum hit point in the party (or, if there are several such characters, the character with the minimum defense point among them). She wrote a function <i>selectTarget</i>($v$) that takes an array of characters representing a party and returns a character that her AI will attack.
</p>
<p>
However, the project manager Ms. Yagami was not satisfied with the behavior of her AI. Ms. Yagami said this AI was not interesting.
</p>
<p>
Aoba struggled a lot, and eventually she found that it is interesting if she substitutes one of the constant zeros in her program with a constant $C$. The rewritten program is as follows. Note that <i>Character</i> is a type representing a character and has fields $hp$ and $dp$ which represent the hit point and the defense point of the character respectively.
</p>
<pre>
int C = <constant integer>;
Character selectTarget(Character v[]) {
int n = length(v);
int r = 0;
for (int i = 1; i < n; i++) {
if (abs(v[r].hp - v[i].hp) > C) {
if (v[r].hp > v[i].hp) r = i;
} else {
if (v[r].dp > v[i].dp) r = i;
}
}
return v[r];
}
</pre>
<p>
By the way, this function may return different characters according to the order of the characters in $v$, even if $v$ contains the same set of characters. Ms. Yagami wants to know how many characters in a party may become the target of the new AI. Aoba's next task is to write a program that takes a given party $v$ and a constant $C$, and then counts the number of characters that may become the return value of <i>selectTarget</i>($v$) if $v$ is re-ordered.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains two integers $N$ $(1 \leq N \leq 50,000)$ and $C$ $(0 \leq C \leq 10^9)$. The first integer $N$ represents the size of $v$. The second integer $C$ represents the constant $C$ in Aoba's program. The <i>i</i>-th line of the following $N$ lines contains two integers $hp_i$ and $dp_i$ $(0 \leq hp_i, dp_i \leq 10^9)$. $hp_i$ represents the hit point of the $i$-th character in $v$, and $dp_i$ represents the defense point of the $i$-th character in $v$. You can assume that $hp_i \ne hp_j$ or $dpi \ne dp_j$ if $i \ne j$ for any $1 \leq i, j \leq N$.
</p>
<h3>Output</h3>
<p>
Display the number of characters that may become the return value of <i>selectTarget</i>($v$), if $v$ is shuffled in an arbitrary order.
</p>
<h3>Sample Input 1</h3>
<pre>5 3
1 5
3 4
5 3
7 2
9 1</pre>
<h3>Output for the Sample Input 1</h3>
<pre>5</pre>
<h3>Sample Input 2</h3>
<pre>3 2
1 2
3 1
5 1</pre>
<h3>Output for the Sample Input 2</h3>
<pre>2</pre>
<h3>Sample Input 3</h3>
<pre>4 1
2 0
0 4
1 1
5 9</pre>
<h3>Output for the Sample Input 3</h3>
<pre>3</pre>
<h3>Sample Input 4</h3>
<pre>5 9
4 10
12 4
2 14
9 19
7 15</pre>
<h3>Output for the Sample Input 4</h3>
<pre>3</pre>
|
p00921 |
<H1><font color="#000">Problem H: </font>Don't Burst the Balloon</H1>
<p>
An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom.
</p>
<p>
You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls nor the needles.
</p>
<p>
<b>Java Specific:</b> Submitted Java programs may not use "java.awt.geom.Area". You may use it for your debugging purposes.
</p>
<p>
Figure H.1 shows an example of a box with needles and the corresponding largest spheric balloon. It corresponds to the first dataset of the sample input below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_dontBurstTheBalloon" style="aling:center"><br/>
<span>
Figure H.1. The upper shows an example layout and the lower shows the largest spheric balloon that can be placed.
</span>
</center>
<br/>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows.
</p>
<pre>
<var>n</var> <var>w</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>h<sub>1</sub></var>
:
<var>x<sub>n</sub></var> <var>y<sub>n</sub></var> <var>h<sub>n</sub></var>
</pre>
<p>
The first line of a dataset contains two positive integers, <var>n</var> and <var>w</var>, separated by a space. <var>n</var> represents the number of needles, and <var>w</var> represents the height of the side walls.
</p>
<p>
The bottom of the box is a 100 × 100 square. The corners of the bottom face are placed at positions (0, 0, 0), (0, 100, 0), (100, 100, 0), and (100, 0, 0).
</p>
<p>
Each of the <var>n</var> lines following the first line contains three integers, <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>, and <var>h<sub>i</sub></var>. (<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>, 0) and <var>h<sub>i</sub></var> represent the base position and the height of the <var>i</var>-th needle. No two needles stand at the same position.
</p>
<p>
You can assume that 1 ≤ <var>n</var> ≤ 10, 10 ≤ <var>w</var> ≤ 200, 0 < <var>x<sub>i</sub></var> < 100, 0 < <var>y<sub>i</sub></var> < 100 and 1 ≤ <var>h<sub>i</sub></var> ≤ 200. You can ignore the thicknesses of the needles and the walls.
</p>
<p>
The end of the input is indicated by a line of two zeros. The number of datasets does not exceed 1000.
</p>
<H2>Output</H2>
<p>
For each dataset, output a single line containing the maximum radius of a balloon that can touch the bottom of the box without interfering with the side walls or the needles. The output should not contain an error greater than 0.0001.
</p>
<H2>Sample Input</H2>
<pre>
5 16
70 66 40
38 52 20
40 35 10
70 30 10
20 60 10
1 100
54 75 200
1 10
90 10 1
1 11
54 75 200
3 10
53 60 1
61 38 1
45 48 1
4 10
20 20 10
20 80 10
80 20 10
80 80 10
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
26.00000
39.00000
130.00000
49.49777
85.00000
95.00000
</pre> |
p01633 |
<h1>Problem G: 穴掘って埋まってます</h1>
<h2>Problem Statement</h2>
<p>
魔法使いの萩原さんは、非常にネガティブな性格である。彼女は、何か落ち込むようなことがあると、穴掘りの魔法を使って穴を作り、泣きながら埋まってしまう。穴掘りの魔法とは、次のようなものである。
</p>
<p>
彼女は、まずN本の線分を地面に描く。そして、彼女が呪文を唱えると、線で囲まれた範囲に穴が出来上がる。交差・内包の関係にある2つの穴は、1つの穴として数える。ただし、頂点のみで接している2つの穴は、別々の穴として数える。
</p>
<p>
図1と図2に、Sample Input 1と2の図を示す。まず、図1において、Aの三角形とBの三角形は、頂点のみで接しているため、別々の穴と数える。Bの三角形とCの三角形は、辺同士重なっているため、1つの穴として数える。よって、図1は、穴2つである。図2では、Dの四角形がEの四角形に包含されているため、これらは1つの穴と数える。Eは、右上の穴とも交差しているため、図2は、穴1つである。
</p>
<div align="center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2013Day1_G1">
</div>
<p>
あなたは、萩原さんの世話係であり、彼女が作った無数の穴を埋めなければならない。どれくらい穴を埋めないといけないのかを知るために、彼女が作った穴の数を求めるプログラムを作成せよ。
</p>
<h2>Input</h2>
<p>
各データセットは、以下の形式で入力される。
</p>
<pre>N
xa1 ya1 xb1 yb1
xa2 ya2 xb2 yb2
...
xaN yaN xbN ybN
</pre>
<p>
入力は全て整数で表わされる。1行目は、線分の数である。続いてN行にわたって、線分の情報が与えられる。1つの線分は、線分の端点(xai, yai)と(xbi, ybi)によって表わされる。
</p>
<h2>Constraints</h2>
<ul>
<li>1 <= N <= 50</li>
<li>-1000 <= 座標 <= 1000</li>
<li>(xai, yai)と(xbi, ybi)の位置は異なる</li>
<li>2つの線分が交差しているとき、2つの線分の端点4つが一直線上に並ぶことはない</li>
</ul>
<h2>Output</h2>
<p>
穴の個数を1行で出力せよ。
</p>
<h2>Sample Input 1</h2>
<pre>8
5 0 5 10
5 10 0 5
0 5 5 0
10 0 10 10
10 10 5 5
5 5 10 0
10 2 15 5
15 5 10 8
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>2
</pre>
<h2>Sample Input 2</h2>
<pre>11
0 0 10 0
10 0 10 10
10 10 0 10
0 10 0 0
1 2 9 2
8 1 8 9
9 8 1 8
2 9 2 1
8 11 11 8
8 11 14 10
11 8 10 14
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>1
</pre>
|
p02336 | <!--<h1>写像12相 その3:ボールに区別なし・箱に区別あり・箱の中身は1つ以上</h1>-->
<h1>Balls and Boxes 6</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td style="background-color:#aff">6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is <b>not</b> distinguished from the other.</li>
<li>Each box is distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box must contain at least one ball.</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
5 3
</pre>
<h2>Sample Output 1</h2>
<pre>
6
</pre>
<h2>Sample Input 2</h2>
<pre>
10 5
</pre>
<h2>Sample Output 2</h2>
<pre>
126
</pre>
<h2>Sample Input 3</h2>
<pre>
100 30
</pre>
<h2>Sample Output 3</h2>
<pre>
253579538
</pre>
|
p02766 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>N</var>. Find the number of digits that <var>N</var> has in base <var>K</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>For information on base-<var>K</var> representation, see <a href="https://en.wikipedia.org/wiki/Positional_notation">Positional notation - Wikipedia</a>.</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^9</var></li>
<li><var>2 \leq K \leq 10</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of digits that <var>N</var> has in base <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>11 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>In binary, <var>11</var> is represented as <code>1011</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1010101 10
</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>314159265 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>18
</pre></section>
</div>
</span> |
p03874 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>Welcome to CODE FESTIVAL 2016!
In order to celebrate this contest, find a string <var>s</var> that satisfies the following conditions:</p>
<ul>
<li>The length of <var>s</var> is between <var>1</var> and <var>5000</var>, inclusive.</li>
<li><var>s</var> consists of uppercase letters.</li>
<li><var>s</var> contains exactly <var>K</var> occurrences of the string "FESTIVAL" as a subsequence.
In other words, there are exactly <var>K</var> tuples of integers <var>(i_0, i_1, ..., i_7)</var> such that <var>0 ≤ i_0 < i_1 < ... < i_7 ≤ |s|-1</var> and <var>s[i_0]='F', s[i_1]='E', ..., s[i_7]='L'</var>.</li>
</ul>
<p>It can be proved that under the given constraints, the solution always exists.
In case there are multiple possible solutions, you can output any.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ≤ K ≤ 10^{18}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a string that satisfies the conditions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>FESSSSSSSTIVAL
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>256
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>FFEESSTTIIVVAALL
</pre></section>
</div>
</span> |
p01849 |
<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>あなたは新生活に備え,おふとんを <i>N</i> 枚買った.
<i>i</i> 番目のおふとんは <i>s<sub>i</sub></i> のぬくもり供給力をもつ.
これから <i>M</i> 日間の気温の予測から,<i>j</i> 日目には <i>d<sub>j</sub></i> のぬくもり需要が予想される.
ぬくもりが足りなくても多すぎても快適さが損なわれるので,<i>j</i> 日目に掛けているおふとんのぬくもり供給力の総和と <i>d<sub>j</sub></i> の差の絶対値を <i>j</i> 日目の不快度と呼ぶことにする.
この<i>M</i> 日分の不快度の合計ができるだけ少なくなるようにしたい.
</p>
<p>ところで,あなたの部屋は残念ながらとても狭く,ベッドと押入れしかない.
そのため,ベッドにおふとんを 1 枚増やすには,そのとき押入れの一番上にあるおふとんをベッドの一番上に乗せるしかない.
逆に,ベッドのおふとんを 1 枚減らすには,そのときベッドの一番上にあるおふとんを押入れの一番上に置くしかない.
また,1 日に動かせるおふとんの枚数に制限は無いが,一度に 1 枚ずつしか動かすことができない.
</p>
<p>さて,あなたはこれから買ってきたおふとんを押入れにしまう予定である.
このときに限り,おふとんを好きな順序で押入れにしまうことができる.
どのようにおふとんを押入れに収納し,その後,日々どのようにおふとんを出し入れすれば,快適に毎日を過ごせるだろうか.
<i>M</i> 日間の不快度の和を最小化するとき,その和の値を求めよ.
なお,一度も使われないおふとんがあってもよく,おふとんを一枚も使わない日があってもよい.
</p>
<h3>Input</h3>
<p>入力は複数のデータセットからなる.
各データセットは以下の形式である.
</p>
<blockquote><i>N</i> <i>M</i><br><i>s<sub>1</sub></i> <i>s<sub>2</sub></i> <i>...</i> <i>s<sub>N</sub></i><br><i>d<sub>1</sub></i> <i>d<sub>2</sub></i> <i>...</i> <i>d<sub>M</sub></i></blockquote>
<p>データセットの 1 行目には,おふとんの枚数 <i>N</i> と,気温が予測されている日数 <i>M</i> を表す整数がスペース区切りで与えられる.
2 行目には <i>N</i> 個の整数 <i>s<sub>1</sub>, s<sub>2</sub>, ..., s<sub>N</sub></i> がスペース区切りで与えられ,<i>s<sub>i</sub></i> は <i>i</i> 番のおふとんのぬくもり供給力を表す.
3 行目には <i>M</i> 個の整数 <i>d<sub>1</sub>, d<sub>2</sub>, ..., d<sub>M</sub></i> がスペース区切りで与えられ,<i>d<sub>j</sub></i> は <i>j</i> 日目のぬくもり需要を表す.
これらの整数は,<i>1 ≤ N ≤ 15</i>, <i>1≤ M ≤ 100</i>, <i>1 ≤ s<sub>i</sub>, d<sub>j</sub> ≤ 1,000,000</i> を満たす.
</p>
<p>入力の終わりは <i>N = M = 0</i> のデータセットで表される.
このデータセットについて出力を行ってはならない.
</p>
<h3>Output</h3>
<p>各データセットについて,<i>M</i> 日間の不快度の和の最小値を 1 行に出力せよ.
</p>
<h3>Sample Input</h3>
<pre>1 1
5
6
1 1
5
2
1 1
20
5
4 1
2 4 5 9
8
4 3
3 5 2 1
10 4 7
5 5
2 2 2 2 2
1 3 5 7 9
2 5
2 5
2 5 2 5 2
0 0</pre>
<h3>Output for Sample Input</h3>
<pre>1
2
5
1
1
5
4
</pre>
<p>
5 つ目のケースについては,上から 5, 2, 3, 1 と押入れに置き,1 日目は 3 枚取り出し |10 - (5 + 2 + 3)| = 0,2 日目は 2 枚しまい |4 - 5| = 1,3 日目は 1 枚取り出し |7 - (5+2)| = 0 で,合計 0 + 1 + 0 = 1 となる.
</p>
|
p03527 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo has a string <var>S</var>.</p>
<p>He can perform the following <var>N</var> kinds of operations any number of times in any order.</p>
<ul>
<li>Operation <var>i</var>: For each of the characters from the <var>L_i</var>-th through the <var>R_i</var>-th characters in <var>S</var>, replace it with its succeeding letter in the English alphabet. (That is, replace <code>a</code> with <code>b</code>, replace <code>b</code> with <code>c</code> and so on.) For <code>z</code>, we assume that its succeeding letter is <code>a</code>.</li>
</ul>
<p>Ringo loves palindromes and wants to turn <var>S</var> into a palindrome.
Determine whether this is possible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq L_i \leq R_i \leq |S|</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>N</var>
<var>L_1</var> <var>R_1</var>
<var>L_2</var> <var>R_2</var>
<var>:</var>
<var>L_N</var> <var>R_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> if it is possible to turn <var>S</var> into a palindrome; print <code>NO</code> if it is impossible.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>bixzja
2
2 3
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>For example, if we perform Operation <var>1</var>, <var>2</var> and <var>1</var> in this order, <var>S</var> changes as <code>bixzja</code> → <code>bjyzja</code> → <code>bjzakb</code> → <code>bkaakb</code> and becomes a palindrome.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>abc
1
2 2
</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>cassert
4
1 2
3 4
1 1
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre></section>
</div>
</span> |
p03177 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a simple directed graph <var>G</var> with <var>N</var> vertices, numbered <var>1, 2, \ldots, N</var>.</p>
<p>For each <var>i</var> and <var>j</var> (<var>1 \leq i, j \leq N</var>), you are given an integer <var>a_{i, j}</var> that represents whether there is a directed edge from Vertex <var>i</var> to <var>j</var>.
If <var>a_{i, j} = 1</var>, there is a directed edge from Vertex <var>i</var> to <var>j</var>; if <var>a_{i, j} = 0</var>, there is not.</p>
<p>Find the number of different directed paths of length <var>K</var> in <var>G</var>, modulo <var>10^9 + 7</var>.
We will also count a path that traverses the same edge multiple times.</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 50</var></li>
<li><var>1 \leq K \leq 10^{18}</var></li>
<li><var>a_{i, j}</var> is <var>0</var> or <var>1</var>.</li>
<li><var>a_{i, i} = 0</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>a_{1, 1}</var> <var>\ldots</var> <var>a_{1, N}</var>
<var>:</var>
<var>a_{N, 1}</var> <var>\ldots</var> <var>a_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different directed paths of length <var>K</var> in <var>G</var>, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2
0 1 0 0
0 0 1 1
0 0 0 1
1 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p><var>G</var> is drawn in the figure below:</p>
<p><img alt="" src="https://img.atcoder.jp/dp/paths_0_muffet.png"/></p>
<p>There are six directed paths of length <var>2</var>:</p>
<ul>
<li><var>1</var> → <var>2</var> → <var>3</var></li>
<li><var>1</var> → <var>2</var> → <var>4</var></li>
<li><var>2</var> → <var>3</var> → <var>4</var></li>
<li><var>2</var> → <var>4</var> → <var>1</var></li>
<li><var>3</var> → <var>4</var> → <var>1</var></li>
<li><var>4</var> → <var>1</var> → <var>2</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
0 1 0
1 0 1
0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p><var>G</var> is drawn in the figure below:</p>
<p><img alt="" src="https://img.atcoder.jp/dp/paths_1_muffet.png"/></p>
<p>There are three directed paths of length <var>3</var>:</p>
<ul>
<li><var>1</var> → <var>2</var> → <var>1</var> → <var>2</var></li>
<li><var>2</var> → <var>1</var> → <var>2</var> → <var>1</var></li>
<li><var>2</var> → <var>1</var> → <var>2</var> → <var>3</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 2
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 0 0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p><var>G</var> is drawn in the figure below:</p>
<p><img alt="" src="https://img.atcoder.jp/dp/paths_2_muffet.png"/></p>
<p>There is one directed path of length <var>2</var>:</p>
<ul>
<li><var>4</var> → <var>5</var> → <var>6</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>957538352
</pre>
<p>Be sure to print the count modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p03198 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> positive integers <var>A_1, A_2, ..., A_N</var>.
Takahashi can perform the following operation on these integers any number of times:</p>
<ul>
<li>Choose <var>1 \leq i \leq N</var> and multiply the value of <var>A_i</var> by <var>-2</var>.</li>
</ul>
<p>Notice that he multiplies it by <strong>minus</strong> two.</p>
<p>He would like to make <var>A_1 \leq A_2 \leq ... \leq A_N</var> holds.
Find the minimum number of operations required. If it is impossible, print <code>-1</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 200000</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 1 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>One possible solution is:</p>
<ul>
<li>Choose <var>i=4</var> and multiply the value of <var>A_4</var> by <var>-2</var>. <var>A_1, A_2, A_3, A_4</var> are now <var>3, 1, 4, -2</var>.</li>
<li>Choose <var>i=1</var> and multiply the value of <var>A_1</var> by <var>-2</var>. <var>A_1, A_2, A_3, A_4</var> are now <var>-6, 1, 4, -2</var>.</li>
<li>Choose <var>i=4</var> and multiply the value of <var>A_4</var> by <var>-2</var>. <var>A_1, A_2, A_3, A_4</var> are now <var>-6, 1, 4, 4</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p><var>A_1 \leq A_2 \leq ... \leq A_N</var> holds before any operation is performed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
657312726 129662684 181537270 324043958 468214806 916875077 825989291 319670097
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7
</pre></section>
</div>
</span> |
p03462 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> white balls arranged in a row, numbered <var>1,2,..,N</var> from left to right.
AtCoDeer the deer is thinking of painting some of these balls red and blue, while leaving some of them white.</p>
<p>You are given a string <var>s</var> of length <var>K</var>.
AtCoDeer performs the following operation for each <var>i</var> from <var>1</var> through <var>K</var> in order:</p>
<ul>
<li>The <var>i</var>-th operation: Choose a contiguous segment of balls (<strong>possibly empty</strong>), and paint these balls red if the <var>i</var>-th character in <var>s</var> is <code>r</code>; paint them blue if the character is <code>b</code>.</li>
</ul>
<p>Here, if a ball which is already painted is again painted, the color of the ball will be overwritten.
However, due to the properties of dyes, <strong>it is not possible to paint a white, unpainted ball directly in blue.</strong>
That is, when the <var>i</var>-th character in <var>s</var> is <code>b</code>, the chosen segment must not contain a white ball.</p>
<p>After all the operations, how many different sequences of colors of the balls are possible?
Since the count can be large, find it modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>≤</var> <var>N</var> <var>≤</var> <var>70</var></li>
<li><var>1</var> <var>≤</var> <var>K</var> <var>≤</var> <var>70</var></li>
<li><var>|s|</var> <var>=</var> <var>K</var></li>
<li><var>s</var> consists of <code>r</code> and <code>b</code>.</li>
<li><var>N</var> and <var>K</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different possible sequences of colors of the balls after all the operations, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
rb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>There are nine possible sequences of colors of the balls, as follows:</p>
<p><code>ww</code>, <code>wr</code>, <code>rw</code>, <code>rr</code>, <code>wb</code>, <code>bw</code>, <code>bb</code>, <code>rb</code>, <code>br</code>.</p>
<p>Here, <code>r</code> represents red, <code>b</code> represents blue and <code>w</code>represents white.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2
br
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>16
</pre>
<p>Since we cannot directly paint white balls in blue, we can only choose an empty segment in the first operation.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 4
rbrb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1569
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>70 70
bbrbrrbbrrbbbbrbbrbrrbbrrbbrbrrbrbrbbbbrbbrbrrbbrrbbbbrbbrbrrbbrrbbbbr
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>841634130
</pre></section>
</div>
</span> |
p03032 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Your friend gave you a dequeue <var>D</var> as a birthday present.</p>
<p><var>D</var> is a horizontal cylinder that contains a row of <var>N</var> jewels.</p>
<p>The <em>values</em> of the jewels are <var>V_1, V_2, ..., V_N</var> from left to right. There may be jewels with negative values.</p>
<p>In the beginning, you have no jewel in your hands.</p>
<p>You can perform at most <var>K</var> operations on <var>D</var>, chosen from the following, at most <var>K</var> times (possibly zero):</p>
<ul>
<li>
<p>Operation A: Take out the leftmost jewel contained in <var>D</var> and have it in your hand. You cannot do this operation when <var>D</var> is empty.</p>
</li>
<li>
<p>Operation B: Take out the rightmost jewel contained in <var>D</var> and have it in your hand. You cannot do this operation when <var>D</var> is empty.</p>
</li>
<li>
<p>Operation C: Choose a jewel in your hands and insert it to the left end of <var>D</var>. You cannot do this operation when you have no jewel in your hand.</p>
</li>
<li>
<p>Operation D: Choose a jewel in your hands and insert it to the right end of <var>D</var>. You cannot do this operation when you have no jewel in your hand.</p>
</li>
</ul>
<p>Find the maximum possible sum of the values of jewels in your hands after the operations.</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 50</var></li>
<li><var>1 \leq K \leq 100</var></li>
<li><var>-10^7 \leq V_i \leq 10^7</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>V_1</var> <var>V_2</var> <var>...</var> <var>V_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the values of jewels in your hands after the operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 4
-10 8 2 1 2 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>14
</pre>
<p>After the following sequence of operations, you have two jewels of values <var>8</var> and <var>6</var> in your hands for a total of <var>14</var>, which is the maximum result.</p>
<ul>
<li>Do operation A. You take out the jewel of value <var>-10</var> from the left end of <var>D</var>.</li>
<li>Do operation B. You take out the jewel of value <var>6</var> from the right end of <var>D</var>.</li>
<li>Do operation A. You take out the jewel of value <var>8</var> from the left end of <var>D</var>.</li>
<li>Do operation D. You insert the jewel of value <var>-10</var> to the right end of <var>D</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 4
-6 -100 50 -2 -5 -3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>44
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 3
-6 -100 50 -2 -5 -3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>It is optimal to do no operation.</p></section>
</div>
</span> |
p02789 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.<br/>
The problem has <var>N</var> test cases, all of which must be passed to get an AC verdict.<br/>
Takahashi's submission has passed <var>M</var> cases out of the <var>N</var> test cases.<br/>
Determine whether Takahashi's submission gets an AC.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq M \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>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If Takahashi's submission gets an AC, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>All three test cases have been passed, so his submission gets an AC.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>Only two out of the three test cases have been passed, so his submission does not get an AC.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p02273 |
<H1>Koch Curve</H1>
<p>
Write a program which reads an integer <i>n</i> and draws a Koch curve based on recursive calles of depth <i>n</i>.
</p>
<p>
The Koch curve is well known as a kind of <a href="http://en.wikipedia.org/wiki/Fractal">fractals</a>.
</p>
<p>
You can draw a Koch curve in the following algorithm:
</p>
<ul>
<li>Divide a given segment (p1, p2) into three equal segments.</li>
<li>Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.</li>
<li>Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_koch">
</center>
<p>
You should start (0, 0), (100, 0) as the first segment.
</p>
<H2>Input</H2>
<p>
An integer <i>n</i> is given.
</p>
<H2>Output</H2>
<p>
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
</p>
<H2>Constraints</H2>
<ul>
<li> 0 ≤ n ≤ 6</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
1
</pre>
<H2>Sample Output 1</H2>
<pre>
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
</pre>
<H2>Sample Input 2</H2>
<pre>
2
</pre>
<H2>Sample Output 2</H2>
<pre>
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
</pre>
<H2>Notes</H2>
|
p02623 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two desks: A and B. Desk A has a vertical stack of <var>N</var> books on it, and Desk B similarly has <var>M</var> books on it.</p>
<p>It takes us <var>A_i</var> minutes to read the <var>i</var>-th book from the top on Desk A <var>(1 \leq i \leq N)</var>, and <var>B_i</var> minutes to read the <var>i</var>-th book from the top on Desk B <var>(1 \leq i \leq M)</var>.</p>
<p>Consider the following action:</p>
<ul>
<li>Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.</li>
</ul>
<p>How many books can we read at most by repeating this action so that it takes us at most <var>K</var> minutes in total? We ignore the time it takes to do anything other than reading.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N, M \leq 200000</var></li>
<li><var>1 \leq K \leq 10^9</var></li>
<li><var>1 \leq A_i, B_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>K</var>
<var>A_1</var> <var>A_2</var> <var>\ldots</var> <var>A_N</var>
<var>B_1</var> <var>B_2</var> <var>\ldots</var> <var>B_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the maximum number of books that can be read.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 240
60 90 120
80 150 80 150
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>In this case, it takes us <var>60</var>, <var>90</var>, <var>120</var> minutes to read the <var>1</var>-st, <var>2</var>-nd, <var>3</var>-rd books from the top on Desk A, and <var>80</var>, <var>150</var>, <var>80</var>, <var>150</var> minutes to read the <var>1</var>-st, <var>2</var>-nd, <var>3</var>-rd, <var>4</var>-th books from the top on Desk B, respectively.</p>
<p>We can read three books in <var>230</var> minutes, as shown below, and this is the maximum number of books we can read within <var>240</var> minutes.</p>
<ul>
<li>Read the topmost book on Desk A in <var>60</var> minutes, and remove that book from the desk.</li>
<li>Read the topmost book on Desk B in <var>80</var> minutes, and remove that book from the desk.</li>
<li>Read the topmost book on Desk A in <var>90</var> minutes, and remove that book from the desk.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4 730
60 90 120
80 150 80 150
</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>5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>Watch out for integer overflows.</p></section>
</div>
</span> |
p03931 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
<div class="part">
Max Score: $400$ Points
<section>
<h3>Problem Statement</h3>
<h3>Sample testcase 3 has a mistake, so we erased this case and rejudged all solutions of this problem. (21:01)</h3>
Snuke got a sequence $a$ of length $n$ from AtCoder company. All elements in $a$ are distinct.<br/>
He made a sequence $b$, but actually, he is not remembered it. <br/>
However, he is remembered a few things about sequence $b$. <br/>
<ul class="simple">
<li>All elements in $b$ are distinct. </li>
<li>All elements in $b$ is in $a$.</li>
<li>$b_1 \oplus b_2 \oplus \cdots \oplus b_r = k$. ($r$ is length of sequence $b$) [$\oplus$ means XOR]</li>
</ul>
<br/>
For example, if $a = { 1, 2, 3 }$ and $k = 1$, he can make $b = { 1 }, { 2, 3 }, { 3, 2 }$. <br/>
He wants to restore sequence $b$, but he says that there are too many ways and he can't restore it.
Please calculate the ways to make $b$ and help him. <br/>
Since the answer can be large, print the answer modulo $1,000,000,007$. <br/>
</section>
</div>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
The input is given from Standard Input in the following format:<br/>
<blockquote>$n \ k$
$a_1 \ a_2 \ \cdots \ a_n$
</blockquote>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<ul>
<li>Print the number of ways to make sequence $b$. </li>
<li>Print the answer modulo $1,000,000,007$. </li>
</ul>
</section>
<section>
<h3>Constraints</h3>
<ul>
<li>$1 \le n \le 100$</li>
<li>$1 \le a_i, k \le 255$</li>
<li>$i \neq j \Rightarrow a_i \neq a_j$</li>
</ul>
</section>
<section>
<h3>Subtasks</h3>
Subtask 1 [ $50$ points ] <br/>
<ul>
<li>$1 \le n \le 4$</li>
</ul>
Subtask 2 [ $170$ points ] <br/>
<ul>
<li>$1 \le n \le 20$</li>
</ul>
Subtask 3 [ $180$ points ] <br/>
<ul>
<li>There are no additional constraints.</li>
</ul>
</section>
</div>
</div>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
3 1
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
3
</pre>
You can make 3 patterns: $b = \{ 1 \}, \{ 2, 3 \}, \{ 3, 2 \}$<br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
3 10
8 7 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
6
</pre>
You can make 6 patterns: $b = \{ 5, 7, 8 \}, \{ 5, 8, 7 \}, \{ 7, 5, 8 \}, \{ 7, 8, 5 \}, \{ 8, 5, 7 \}, \{ 8, 7, 5 \}$.<br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 4</h3>
<pre>
25 127
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3>
<pre>
235924722
</pre>
<p>Please output answer mod $1,000,000,007$.</p>
</section>
writer: E869120 <br/>
</div>
</span> |
p02337 | <!--<h1>写像12相 その7:ボールに区別あり・箱に区別なし・入れ方に制限なし</h1>-->
<h1>Balls and Boxes 7</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td style="background-color:#aff">7</td><td>8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is distinguished from the other.</li>
<li>Each box is <b>not</b> distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box can contain an arbitrary number of balls (including zero).</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
3 5
</pre>
<h2>Sample Output 1</h2>
<pre>
5
</pre>
<h2>Sample Input 2</h2>
<pre>
5 3
</pre>
<h2>Sample Output 2</h2>
<pre>
41
</pre>
<h2>Sample Input 3</h2>
<pre>
100 100
</pre>
<h2>Sample Output 3</h2>
<pre>
193120002
</pre>
|
p02767 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> people living on a number line.</p>
<p>The <var>i</var>-th person lives at coordinate <var>X_i</var>.</p>
<p>You are going to hold a meeting that all <var>N</var> people have to attend.</p>
<p>The meeting can be held at any <strong>integer coordinate</strong>. If you choose to hold the meeting at coordinate <var>P</var>, the <var>i</var>-th person will spend <var>(X_i - P)^2</var> points of stamina to attend the meeting.</p>
<p>Find the minimum total points of stamina the <var>N</var> people have to spend.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq X_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>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total stamina the <var>N</var> people have to spend.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>Assume the meeting is held at coordinate <var>2</var>. In this case, the first person will spend <var>(1 - 2)^2</var> points of stamina, and the second person will spend <var>(4 - 2)^2 = 4</var> points of stamina, for a total of <var>5</var> points of stamina. This is the minimum total stamina that the <var>2</var> people have to spend.</p>
<p>Note that you can hold the meeting only at an integer coordinate.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
14 14 2 13 56 2 37
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2354
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.