question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03522 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence <var>A</var> of length <var>N</var>.</p>
<p>On this sequence, we can perform the following two kinds of operations:</p>
<ul>
<li>
<p>Swap two adjacent elements.</p>
</li>
<li>
<p>Select one element, and increment it by <var>1</var>.</p>
</li>
</ul>
<p>We will repeatedly perform these operations so that <var>A</var> will be a non-decreasing sequence. Find the minimum required number of operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †200000</var></li>
<li><var>1 †A_i †10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var>
<var>A_2</var>
<var>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to turn <var>A</var> into a non-decreasing sequence.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
4
1
8
8
7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can turn <var>A</var> into a non-decreasing sequence in two operations:</p>
<ul>
<li>Initially, <var>A = \{4, 1, 8, 8, 7\}</var>.</li>
<li>Swap the first two elements. Now, <var>A = \{1, 4, 8, 8, 7\}</var>.</li>
<li>Increment the last element by <var>1</var>. Now, <var>A = \{1, 4, 8, 8, 8\}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20
8
2
9
7
4
6
7
9
7
4
7
4
4
3
6
2
3
4
4
9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>62
</pre></section>
</div>
</span> |
p03488 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive <var>x</var>-axis direction.</p>
<p>This robot will be given an instruction sequence <var>s</var>.
<var>s</var> consists of the following two kinds of letters, and will be executed in order from front to back.</p>
<ul>
<li><code>F</code> : Move in the current direction by distance <var>1</var>.</li>
<li><code>T</code> : Turn <var>90</var> degrees, either clockwise or counterclockwise.</li>
</ul>
<p>The objective of the robot is to be at coordinates <var>(x, y)</var> after all the instructions are executed.
Determine whether this objective is achievable.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>s</var> consists of <code>F</code> and <code>T</code>.</li>
<li><var>1 \leq |s| \leq 8</var> <var>000</var></li>
<li><var>x</var> and <var>y</var> are integers.</li>
<li><var>|x|, |y| \leq |s|</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
<var>x</var> <var>y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the objective is achievable, print <code>Yes</code>; if it is not, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>FTFFTFFF
4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>FTFFTFFF
-2 -2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
<p>The objective can be achieved by, for example, turning clockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>FF
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>TF
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>FFTTFF
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre>
<p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning counterclockwise in the second <code>T</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>TTTT
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>No
</pre></section>
</div>
</span> |
p03172 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> children, numbered <var>1, 2, \ldots, N</var>.</p>
<p>They have decided to share <var>K</var> candies among themselves.
Here, for each <var>i</var> (<var>1 \leq i \leq N</var>), Child <var>i</var> must receive between <var>0</var> and <var>a_i</var> candies (inclusive).
Also, no candies should be left over.</p>
<p>Find the number of ways for them to share candies, modulo <var>10^9 + 7</var>.
Here, two ways are said to be different when there exists a child who receives a different number of candies.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>0 \leq K \leq 10^5</var></li>
<li><var>0 \leq a_i \leq K</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways for the children to share candies, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five ways for the children to share candies, as follows:</p>
<ul>
<li><var>(0, 1, 3)</var></li>
<li><var>(0, 2, 2)</var></li>
<li><var>(1, 0, 3)</var></li>
<li><var>(1, 1, 2)</var></li>
<li><var>(1, 2, 1)</var></li>
</ul>
<p>Here, in each sequence, the <var>i</var>-th element represents the number of candies that Child <var>i</var> receives.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 10
9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There may be no ways for the children to share candies.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 0
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
<p>There is one way for the children to share candies, as follows:</p>
<ul>
<li><var>(0, 0)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 100000
100000 100000 100000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>665683269
</pre>
<p>Be sure to print the answer modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p02011 | <h1>Problem H. Enlarge Circles</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
You are given $N$ distinct points on the 2-D plane. For each point, you are going to make a single circle whose center is located at the point. Your task is to maximize the sum of perimeters of these $N$ circles so that circles do not overlap each other. Here, "overlap" means that two circles have a common point which is not on the circumference of at least either of them. Therefore, the circumferences can be touched. Note that you are allowed to make a circle with radius $0$.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$N$
$x_1$ $y_1$
$\vdots$
$x_N$ $y_N$
</pre>
<p>
The first line contains an integer $N$, which is the number of points ($2 \leq N \leq 200$). Each of the following $N$ lines gives the coordinates of a point. Integers $x_i$ and $y_i$ ($-100 \leq x_i, y_i \leq 100$) in the $i$-th line of them give the $x$- and $y$-coordinates, respectively, of the $i$-th point. These points are distinct, in other words, $(x_i,y_i) \ne (x_j, y_j)$ is satisfied if $i$ and $j$ are different.
</p>
<h2>Output</h2>
<p>
Output the maximized sum of perimeters. The output can contain an absolute or a relative error no more than $10^{-6}$.
</p>
<h2>Examples</h2>
<h2>Sample Input 1</h2>
<pre>
3
0 0
3 0
5 0
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
31.415926535
</pre>
<h2>Sample Input 2</h2>
<pre>
3
0 0
5 0
0 5
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
53.630341225
</pre>
<h2>Sample Input 3</h2>
<pre>
9
91 -18
13 93
73 -34
15 2
-46 0
69 -42
-23 -13
-87 41
38 68
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
1049.191683488
</pre>
|
p00186 |
<H1>äŒæŽ¥å°é¶</H1>
<p>
2008 幎 4 æã«ãäŒæŽ¥è¥æŸåžã¯é·ã20 m 85 cm ã®ãããšãäœãã«ææŠããŠæåããŸããããã®ãšã䜿ãããé¶èããäŒæŽ¥ç¹ç£ã®äŒæŽ¥å°é¶ã§ããäŒæŽ¥å°é¶ã¯ãšãŠãããããã®ã§ããã飌è²ããããããã®ã§çç£éãå°ãªãã倿®µãé«ãã®ãé£ç¹ã§ãã<!--çŸåšãçç£æ¡å€§ã®ããã®åªåãé²ããããŠããã®ã§ããã®ãã¡ã¿ãªããã®äœãçºã§ãç®ã«ããæ¥ãæ¥ããããããŸããã-->
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_chicken"><br/>
<br/>
</center>
<p>
仿¥ã¯äžéåã®å®¶ã«ãé ããã芪æãéã³ã«æ¥ãŸãããæ¯ããã¯é¶èã®æ°Žçããäœã£ãŠèŠªæãããŠãªãããšã«ããŸãããè¿ãã®ãèå±ããã§ã¯äŒæŽ¥å°é¶ãšãµã€ãã®é¶èã® 2 çš®é¡ã®é¶èã売ã£ãŠããŸãããæ¯ããã¯ã以äžã®ãããªæç€ºãäžéåã«äžããŠããèå±ããã«è¡ã£ãŠé¶èãè²·ã£ãŠããããã«
é Œã¿ãŸããã
</p>
<ul>
<li>é¶èãè¶³ããªããªããšå°ãã®ã§ã決ããããé以äžã®é¶èãè²·ãã</li>
<li>äºç®ã®èš±ãç¯å²ã§äŒæŽ¥å°é¶ãã§ããã ãå€ãè²·ã(äŒæŽ¥å°é¶ã¯å¿
ãè²·ãããš)ã</li>
<li>äŒæŽ¥å°é¶ãè²·ã£ãæ®ãã§ãµã€ãã®é¶èãã§ããã ãå€ãè²·ã(äºç®ãè¶³ããªããã°è²·ããªã)ã</li>
</ul>
<p>
äžéåããèå±ããã«è¡ããšãäŒæŽ¥å°é¶ãåèã®ããäžäººãè²·ããéãå¶éããŠããŸãããäžéåãããæ¯ããããäžãããããã¹ãŠã®æç€ºãå®ã£ãŠè²·ãç©ããããšããäžéåãè²·ãäŒæŽ¥å°é¶ãšæ®éã®é¶èã®éã¯ããããäœã°ã©ã ã«ãªãã§ããã?
</p>
<p>
è²·ãã¹ãé¶èã®éã®äžé <var>q<sub>1</sub></var>ãäºç® <var>b</var>ããã®ãèå±ããã§ã®äŒæŽ¥å°é¶ 100 ã°ã©ã ã®å€æ®µ <var>c<sub>1</sub></var>ããµã€ãã®é¶è 100 ã°ã©ã ã®å€æ®µ <var>c<sub>2</sub></var>ãäŒæŽ¥å°é¶ãäžäººãè²·ããéã®äžé <var>q<sub>2</sub></var> ãå
¥åãšããäžéåãè²·ãäŒæŽ¥å°é¶ãšãµã€ãã®é¶èã®éã 100 ã°ã©ã åäœã§åºåããããã°ã©ã ãäœæããŠãã ããããã ãããã®ãèå±ããã§ã¯ãæ¯ããã®æç€ºéãã«è²·ããªãå Žåã«ã¯ããNAããšåºåããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>q<sub>1</sub></var> <var>b</var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> <var>q<sub>2</sub></var>
</pre>
<p>
é¶èã®éã衚ãããŒã¿ <var>q<sub>1</sub></var> ãš <var>q<sub>2</sub></var> ã¯100 ã°ã©ã åäœã§æå®ãããŸãããŸãã<var>b</var>ã<var>c<sub>1</sub></var>ã<var>c<sub>2</sub></var>ã<var>q<sub>1</sub></var>ã<var>q<sub>2</sub></var> 㯠1 ä»¥äž 1,000,000 以äžã®æŽæ°ãšããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«ãäžéåã賌å
¥ããäŒæŽ¥å°é¶ã®éãšãµã€ãã®é¶èã®é(åè§ç©ºçœåºåã) ãŸãã¯ãNAããïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
48 9297 240 126 32
20 3010 157 141 7
30 117002 5680 962 15
8 1673 1712 190 22
64 8478 87 54 307
23 5477 117 92 12
50 7558 1396 187 17
279 88677 4522 514 14
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
28 20
7 13
15 33
NA
97 0
12 44
NA
NA
</pre>
|
p02441 | <h1>Count</h1>
<p>
For a given sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$, perform the following operations.
</p>
<ul>
<li>count($b, e, k$): print the number of the specific values $k$ in $a_b, a_{b+1}, ..., a_{e-1}$.
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1, ..., \; a_{n-1}$
$q$
$b_1 \; e_1 \; k_1$
$b_2 \; e_2 \; k_2$
:
$b_q \; e_q \; k_q$
</pre>
<p>
The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $b_i \; b_e \; k_i$ are given as queries.
</p>
<h2>Output</h2>
<p>
For each query, print the number of specified values.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$-1,000,000,000 \leq a_i, k_i \leq 1,000,000,000$</li>
<li>$1 \leq q \leq 1,000$</li>
<li>$0 \leq b < e \leq n$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
9
1 4 1 4 2 1 3 5 6
3
0 9 1
1 6 1
3 7 5
</pre>
<h2>Sample Output 1</h2>
<pre>
3
2
0
</pre>
|
p03600 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads.
The following are known about the road network:</p>
<ul>
<li>People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.</li>
<li>Different roads may have had different lengths, but all the lengths were positive integers.</li>
</ul>
<p>Snuke the archeologist found a table with <var>N</var> rows and <var>N</var> columns, <var>A</var>, in the ruin of Takahashi Kingdom.
He thought that it represented the shortest distances between the cities along the roads in the kingdom.</p>
<p>Determine whether there exists a road network such that for each <var>u</var> and <var>v</var>, the integer <var>A_{u, v}</var> at the <var>u</var>-th row and <var>v</var>-th column of <var>A</var> is equal to the length of the shortest path from City <var>u</var> to City <var>v</var>.
If such a network exist, find the shortest possible total length of the roads.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li>If <var>i â j</var>, <var>1 \leq A_{i, j} = A_{j, i} \leq 10^9</var>.</li>
<li><var>A_{i, i} = 0</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var>
<var>...</var>
<var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>If there exists no network that satisfies the condition, print <code>-1</code>.
If it exists, print the shortest possible total length of the roads.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 1 3
1 0 2
3 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The network below satisfies the condition:</p>
<ul>
<li>City <var>1</var> and City <var>2</var> is connected by a road of length <var>1</var>.</li>
<li>City <var>2</var> and City <var>3</var> is connected by a road of length <var>2</var>.</li>
<li>City <var>3</var> and City <var>1</var> is not connected by a road.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 1 3
1 0 1
3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>As there is a path of length <var>1</var> from City <var>1</var> to City <var>2</var> and City <var>2</var> to City <var>3</var>, there is a path of length <var>2</var> from City <var>1</var> to City <var>3</var>.
However, according to the table, the shortest distance between City <var>1</var> and City <var>3</var> must be <var>3</var>.</p>
<p>Thus, we conclude that there exists no network that satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>82
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
0 1000000000 1000000000
1000000000 0 1000000000
1000000000 1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3000000000
</pre></section>
</div>
</span> |
p02912 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is going to buy <var>N</var> items one by one.</p>
<p>The price of the <var>i</var>-th item he buys is <var>A_i</var> yen (the currency of Japan).</p>
<p>He has <var>M</var> discount tickets, and he can use any number of them when buying an item.</p>
<p>If <var>Y</var> tickets are used when buying an item priced <var>X</var> yen, he can get the item for <var>\frac{X}{2^Y}</var> (rounded down to the nearest integer) yen.</p>
<p>What is the minimum amount of money required to buy all the items?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N, M \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum amount of money required to buy all the items.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
2 13 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>We can buy all the items for <var>9</var> yen, as follows:</p>
<ul>
<li>Buy the <var>1</var>-st item for <var>2</var> yen without tickets.</li>
<li>Buy the <var>2</var>-nd item for <var>3</var> yen with <var>2</var> tickets.</li>
<li>Buy the <var>3</var>-rd item for <var>4</var> yen with <var>1</var> ticket.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 4
1 9 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100000
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>We can buy the item priced <var>1000000000</var> yen for <var>0</var> yen with <var>100000</var> tickets.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>9500000000
</pre></section>
</div>
</span> |
p01797 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem H
Kimagure Cleaner</h2>
<p>
Ichiro won the newest model cleaner as a prize of a programming contest. This cleaner automatically moves around in a house for cleaning. Because Ichiro's house is very large, it can be modeled as an infinite two-dimensional Cartesian plane, whose axes are called $X$ and $Y$. The positive direction of the $Y$-axis is to the left if you face the positive direction of the $X$-axis.
</p>
<p>
The cleaner performs a sequence of actions for cleaning. Each action consists of a turn and a run. In an action, first the cleaner turns right or left by 90 degrees, and then runs straight by an integer length to the direction that the cleaner faces. At the end of a day, the cleaner reports the log of its actions in the day to Ichiro, in order to inform him where it has cleaned and where it hasn't.
</p>
<p>
Unlike common cleaners, this cleaner has human-like artificial intelligence. Therefore, the cleaner is very forgetful (like humans) and it is possible that the cleaner forgets the direction of a turn, or the cleaner only remembers the length of a run as a very rough range. However, in order to pretend to be operating correctly, the cleaner has to recover the complete log of actions after finishing the cleaning.
</p>
<p>
The cleaner was initially at the point $(0, 0)$, facing the positive direction of $X$-axis. You are given the cleaner's location after cleaning, $(X, Y)$, and an incomplete log of the cleaner's actions that the cleaner remembered. Please recover a complete log from the given incomplete log. The actions in the recovered log must satisfy the following constraints:
</p>
<ul>
<li> The number of actions must be the same as that in the incomplete log.</li>
<li> The direction of the $i$-th turn must be the same as that in the incomplete log if it is recorded in the incomplete log.</li>
<li> The length of the $i$-th run must be within the range of the length specified in the incomplete log.</li>
<li> The cleaner must be at $(X, Y)$ after finishing all actions. The direction of the cleaner after cleaning is not important and you do not have to care about it, because the cleaner can turn freely after cleaning, though it cannot run after cleaning. You are not required to recover the actual path, because Ichiro only checks the format of the log and the location of the cleaner after cleaning.</li>
</ul>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains three integers $N$ $(1 \leq N \leq 50)$, $X$, and $Y$ $(-10^9 \leq X, Y \leq 10^9)$. $N$ represents the number of actions in the incomplete log. $X$ and $Y$ represent the cleaner's location $(X, Y)$ after cleaning. The $i$-th line of the following $N$ lines contains a character $D_i$ and two integers $LL_i$ and $LU_i$. $D_i$ represents the direction of the $i$-th turn: '<span>L</span>', '<span>R</span>', and '<span>?</span>' represents left, right, and not recorded respectively. $LL_i$ and $LU_i$ represent a lower and upper bound of the length of the $i$-th run, respectively. You can assume $1 \leq LL_i \leq LU_i \leq 55,555,555$.
</p>
<h3>Output</h3>
<p>
Display the recovered log. In the first line, display N, the number of actions in the log. In the $i$-th line of the following $N$ lines, display the direction of the $i$-th turn in a character and the length of the $i$-th run separated by a single space. Represent a right turn by a single character '<span>R</span>', and a left turn by a single character '<span>L</span>'. The recovered log must satisfy the constraints in the problem. If there are multiple
logs that satisfy the constraints, you can display any of them. Display $-1$ in a line if there is no log that satisfies the constraints.
</p>
<h3>Sample Input 1</h3>
<pre>2 -3 4
L 2 5
? 3 5</pre>
<h3>Output for the Sample Input 1</h3>
<pre>2
L 4
L 3</pre>
<h3>Sample Input 2</h3>
<pre>5 3 -4
? 1 5
? 1 5
? 1 5
? 1 5
? 1 5</pre>
<h3>Output for the Sample Input 2</h3>
<pre>5
L 1
R 2
R 4
L 1
R 1</pre> |
p00885 |
<H1><font color="#000">Problem B:</font> Balloon Collecting</H1>
<p>
"Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player can control the vehicle to move left or right, or simply stay. When one of the balloons reaches the ground, the vehicle and the balloon must reside at the same position, otherwise the balloon will burst and the game ends.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_balloonCollecting">
<p>
Figure B.1: Robot vehicle and falling balloons
</p>
</center>
<p>
The goal of the game is to store all the balloons into the house at the left end on the game field. The vehicle can carry at most three balloons at a time, but its speed changes according to the number of the carrying balloons. When the vehicle carries <i>k</i> balloons (<i>k</i> = 0, 1, 2, 3), it takes <i>k</i>+1 units of time to move one unit distance. The player will get higher score when the total moving distance of the vehicle is shorter.
</p>
<p>
Your mission is to help the game designer check game data consisting of a set of balloons. Given a landing position (as the distance from the house) and a landing time of each balloon, you must judge whether a player can capture all the balloons, and answer the minimum moving distance needed to capture and store all the balloons. The vehicle starts from the house. If the player cannot capture all the balloons, you must identify the first balloon that the player cannot capture.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows.
</p>
<p>
<i>n</i><br>
<i>p</i><sub>1</sub> <i>t</i><sub>1</sub><br>
.<br>
.<br>
.<br>
<i>p</i><sub><i>n</i></sub> <i>t</i><sub><i>n</i></sub><br>
</p>
<p>
The first line contains an integer n, which represents the number of balloons (0 < <i>n</i> ≤ 40). Each of the following <i>n</i> lines contains two integers <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) separated by a space. <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> represent the position and the time when the <i>i</i>-th balloon reaches the ground (0 < <i>p<sub>i</sub></i> ≤ 100, 0 < <i>t<sub>i</sub></I> ≤ 50000). You can assume <i>t<sub>i</sub></i> < <i>t<sub>j</sub></i> for <i>i</i> < <i>j</i>. The position of the house is 0, and the game starts from the time 0.
</p>
<p>
The sizes of the vehicle, the house, and the balloons are small enough, and should be ignored. The vehicle needs 0 time for catching the balloons or storing them into the house. The vehicle can start moving immediately after these operations.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output one word and one integer in a line separated by a space. No extra characters should occur in the output.
</p>
<ul>
<li> If the player can capture all the balloons, output "OK" and an integer that represents the minimum moving distance of the vehicle to capture and store all the balloons.
</li>
<li> If it is impossible for the player to capture all the balloons, output "NG" and an integer <i>k</i> such that the <i>k</i>-th balloon in the dataset is the first balloon that the player cannot capture.
</li>
</ul>
<H2>Sample Input</H2>
<pre>
2
10 100
100 270
2
10 100
100 280
3
100 150
10 360
40 450
3
100 150
10 360
40 440
2
100 10
50 200
2
100 100
50 110
1
15 10
4
1 10
2 20
3 100
90 200
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
OK 220
OK 200
OK 260
OK 280
NG 1
NG 2
NG 1
OK 188
</pre>
|
p03250 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have decided to give an allowance to your child depending on the outcome of the game that he will play now.</p>
<p>The game is played as follows:</p>
<ul>
<li>There are three "integer panels", each with a digit between <var>1</var> and <var>9</var> (inclusive) printed on it, and one "operator panel" with a <code>+</code> printed on it.</li>
<li>The player should construct a formula of the form <var>X + Y</var>, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)</li>
<li>Then, the amount of the allowance will be equal to the resulting value of the formula.</li>
</ul>
<p>Given the values <var>A, B</var> and <var>C</var> printed on the integer panels used in the game, find the maximum possible amount of the allowance.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A, B, C \leq 9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible amount of the allowance.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>53
</pre>
<p>The amount of the allowance will be <var>53</var> when the panels are arranged as <code>52+1</code>, and this is the maximum possible amount.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 9 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>108
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>82
</pre></section>
</div>
</span> |
p01778 |
<h2>G: Dungeon of Cards / ã«ãŒãã®è¿·å®®</h2>
<h3>ç©èª</h3>
<p>ããã¯äžæè°ã®åœãããµããïŒãããµãã蟺å¢ã®å°ã«äœçœ®ããã«ãŒãã®è¿·å®®ã«ã¯ïŒéé財å®ãç ããšäŒããããŠããïŒå¥œå¥å¿æºçãªãããã«ããã¯ïŒãã®èšãäŒããèããããªãïŒå人ã®ãŠã£ãé£ããŠã«ãŒãã®è¿·å®®ãç®æãæ
ã«åºãããšã«ããïŒ</p>
<p>ç¿æ¥ïŒæ
ã®èšç»ãç«ãŠãããã«ãããã«ããããŠã£ã®å®¶ã蚪ãããšïŒãŠã£ã¯äœããèã蟌ãã§ããããã ã£ãïŒã©ãããçšæåšå°ãªãŠã£ã¯ã«ãŒãã®è¿·å®®ã«é¢ããéèŠãªæ
å ±ãå
¥æããããã ïŒããã¯ïŒã«ãŒãã®è¿·å®®ã«ã¯ <var>N</var> æã®æãããïŒããããã®æãéããããã«ã«ãŒããå¿
èŠã«ãªããšããããšã ïŒ</p>
<p>ã«ãŒãã®è¿·å®®ãžã®éäžã«ã¯ïŒæãéãããã®ã«ãŒããæ±ãåºãããïŒãŠã£ã¯ããã§ã«ãŒãã調éããããšèããŠããããããïŒåé¡ãªã®ã¯äºç®ã§ããïŒãããã«ãããšãŠã£ã¯æ±ºããŠãéæã¡ã§ã¯ãªãã®ã§ïŒã«ãŒãã«ãéããããããŠããŸããšéäžã®é£æãååã«ç¢ºä¿ã§ããªãå¯èœæ§ãããã®ã ïŒ</p>
<p>幞ã <var>N</var> æã®æã®æ
å ±ã¯ïŒãããŸã§è¿·å®®ã«æãã 人ã
ã®èšé²ããç¥ãããšãã§ããïŒãããªãå¹çã®è¯ãã«ãŒãã®è²·ãæ¹ãèšç®ã§ãããããããªãïŒãããïŒïŒäººã§èããã«ã¯å°ãé£ããïŒããã§ãããã«ãããšãŠã£ã¯ïŒãããµããã«äœãåªç§ãªããã°ã©ãã§ããããªãã«äŸé Œãããããšã«ããïŒ</p>
<h3>åé¡</h3>
<p><var>N</var> æã®æãš <var>M</var> æã®ã«ãŒããããïŒæã»ã«ãŒããšãã«ïŒæã«ã€ãè±å€§æåã¢ã«ãã¡ããã ('A'-'Z') 1ã€ãš1æ¡ã®æ°å ('0'-'9') ãæãããŠããïŒæã«ã«ãŒããããããšïŒã«ãŒãã«æãããã¢ã«ãã¡ãããïŒãããã¯æ°åã®ã©ã¡ããäžæ¹ã§ãæã®ãã®ãšäžèŽããŠããã°ïŒãã®æãéããããšãã§ããïŒãã®ãšãã«ãŒãã¯ãªããªããªãããïŒåãã«ãŒããäœåºŠã§ã䜿ããŸããããšãã§ããïŒãŸãïŒã«ãŒãã«ã¯ãããã倿®µãä»ããŠããïŒ</p>
<p><var>N</var> æã®æãš <var>M</var> æã®ã«ãŒãã®æ
å ±ãå
ã«ïŒãã¹ãŠã®æãéããããšãã§ããã«ãŒãã®è²·ãæ¹ã®ãã¡ïŒèŠããéé¡ãæå°ãšãªãå Žåã®éé¡ãèšç®ããããã°ã©ã ãäœæããïŒ</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒãããªãïŒ</p>
<pre>
<var>N</var>
<var>a_1</var> <var>b_1</var>
...
<var>a_N</var> <var>b_N</var>
<var>M</var>
<var>c_1</var> <var>d_1</var> <var>e_1</var>
...
<var>c_M</var> <var>d_M</var> <var>e_M</var>
</pre>
<p>1è¡ç®ã§ã¯æã®ææ°ãè¡šãæŽæ° <var>N</var> ãäžããããïŒç¶ã <var>N</var> è¡ã®ãã¡ïŒ<var>i</var> è¡ç®ã§ã¯ <var>i</var> çªç®ã®æã«æžãããè±å€§æåã¢ã«ãã¡ããã <var>a_i</var> ãš1æ¡ã®æ°å <var>b_i</var> ãäžããããïŒ</p>
<p>ç¶ã1è¡ã§ã¯ïŒåºã§æ±ãããŠããã«ãŒãã®ææ° <var>M</var> ãäžããããïŒç¶ã <var>M</var> è¡ã®ãã¡ïŒ<var>j</var> è¡ç®ã§ã¯ <var>j</var> çªç®ã®ã«ãŒãã«æžãããè±å€§æåã¢ã«ãã¡ããã <var>c_j</var> ãš1æ¡ã®æ°å <var>d_j</var>ïŒäŸ¡æ Œ <var>e_j</var> ãäžããããïŒ</p>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºããïŒ
<ul>
<li> <var>1 ≤ N, M ≤ 10{,}000</var> </li>
<li> <var>a_i, c_j</var> ã¯ã¢ã«ãã¡ããã倧æå ('A'-'Z') 1æå </li>
<li> <var>b_i, d_j</var>ã¯1æ¡ã®æ°å ('0'-'9') 1æå </li>
<li> <var>1 ≤ e_j ≤ 1{,}000</var> </li>
<li> <var>N, M, e_j</var> ã¯ãã¹ãп޿° </li>
</ul>
</p>
<h3>åºå圢åŒ</h3>
<p>è¿·å®®ã®æããã¹ãŠéããããã«å¿
èŠãªã«ãŒããæããããã®æå°äºç®ã1è¡ã«åºåããïŒã©ã®ããã«ã«ãŒããè²·ã£ãŠãå
šãŠã®æãéããããªãå ŽåïŒ-1ã1è¡ã«åºåããïŒ</p>
<h3>å
¥åäŸïŒ</h3>
<pre>
4
D 1
D 2
A 3
D 4
4
A 1 7
D 4 5
D 3 6
B 3 3
</pre>
<h3>åºåäŸïŒ</h3>
<pre>6</pre>
<h3>å
¥åäŸ2</h3>
<pre>
4
D 1
D 2
A 3
D 4
4
A 1 7
D 4 5
D 3 10
B 3 3
</pre>
<h3>åºåäŸ2</h3>
<pre>8</pre>
<h3>å
¥åäŸ3</h3>
<pre>
5
D 1
D 2
A 3
Z 0
D 4
4
A 1 7
D 4 5
D 3 6
B 3 3
</pre>
<h3>åºåäŸ3</h3>
<pre>-1</pre> |
p03745 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an array <var>A</var> of length <var>N</var>.
Your task is to divide it into several contiguous subarrays.
Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order.
At least how many subarrays do you need to divide <var>A</var> into?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>Each <var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible number of subarrays after division of <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 2 3 2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One optimal solution is to divide the array into <var>[1,2,3]</var> and <var>[2,2,1]</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
1 2 1 2 1 2 1 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1 2 3 2 1 999999999 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p02857 | <span class="lang-en">
<p>Score: <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p><font color="red"><strong>This is an interactive task.</strong></font></p>
<p>We have <var>2N</var> balls arranged in a row, numbered <var>1, 2, 3, ..., 2N</var> from left to right, where <var>N</var> is an odd number. Among them, there are <var>N</var> red balls and <var>N</var> blue balls.</p>
<p>While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most <var>210</var> questions of the following form:</p>
<ul>
<li>You choose any <var>N</var> of the <var>2N</var> balls and ask whether there are more red balls than blue balls or not among those <var>N</var> balls.</li>
</ul>
<p>Now, let us begin.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 99</var></li>
<li><var>N</var> is an odd number.</li>
</ul>
<hr/>
</section>
</div>
<div class="part">
<section>
<h3>Input and Output</h3>
<p>First, receive the number of balls of each color, <var>N</var>, from Standard Input:</p>
<pre><var>N</var>
</pre>
<p>Then, ask questions until you find out the color of every ball.
A question should be printed to Standard Output in the following format:</p>
<pre>? <var>A_1</var> <var>A_2</var> <var>A_3</var> <var>...</var> <var>A_N</var>
</pre>
<p>This means that you are asking about the <var>N</var> balls <var>A_1, A_2, A_3, ..., A_N</var>, where <var>1 \leq A_i \leq 2N</var> and <var>A_i \neq A_j (i \neq j)</var> must hold.</p>
<p>The response <var>T</var> to this question will be given from Standard Input in the following format:</p>
<pre><var>T</var>
</pre>
<p>Here <var>T</var> is one of the following strings:</p>
<ul>
<li><code>Red</code>: Among the <var>N</var> balls chosen, there are more red balls than blue balls.</li>
<li><code>Blue</code>: Among the <var>N</var> balls chosen, there are more blue balls than red balls.</li>
<li><code>-1</code>: You printed an invalid question (including the case you asked more than <var>210</var> questions), or something else that was invalid.</li>
</ul>
<p>If the judge returns <code>-1</code>, your submission is already judged as incorrect. The program should immediately quit in this case.</p>
<p>When you find out the color of every ball, print your guess to Standard Output in the following format:</p>
<pre>! <var>c_1</var><var>c_2</var><var>c_3</var><var>...</var><var>c_{2N}</var>
</pre>
<p>Here <var>c_i</var> should be the character representing the color of Ball <var>i</var>; use <code>R</code> for red and <code>B</code> for blue.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notice</h3>
<ul>
<li><font color="red"><strong>Flush Standard Output each time you print something.</strong></font> Failure to do so may result in <code>TLE</code>.</li>
<li>Immediately terminate your program after printing your guess (or receiving the <code>-1</code> response). Otherwise, the verdict will be indeterminate.</li>
<li>If your program prints something invalid, the verdict will be indeterminate.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input and Output</h3>
<table class="table-striped table-bordered table-condensed">
<tr align="center">
<th align="center">Input</th>
<th align="center">Output</th>
</tr>
<tr align="center">
<td><code>3</code></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td><code>? 1 2 3</code></td>
</tr>
<tr align="center">
<td><code>Red</code></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td><code>? 2 4 6</code></td>
</tr>
<tr align="center">
<td><code>Blue</code></td>
<td></td>
</tr>
<tr align="center">
<td></td>
<td><code>! RRBBRB</code></td>
</tr>
</table>
<p>In this sample, <var>N = 3</var>, and the colors of Ball <var>1, 2, 3, 4, 5, 6</var> are red, red, blue, blue, red, blue, respectively.</p>
<ul>
<li>In the first question, there are two red balls and one blue ball among the balls <var>1, 2, 3</var>, so the judge returns <code>Red</code>.</li>
<li>In the second question, there are one red ball and two blue balls among the balls <var>2, 4, 6</var>, so the judge returns <code>Blue</code>.</li>
</ul></section>
</div>
</span> |
p01282 |
<H1><font color="#000">Problem J:</font> Revenge of the Round Table</H1>
<p>
Two contries A and B have decided to make a meeting to get acquainted with each other. <i>n</i> ambassadors
from A and B will attend the meeting in total.
</p>
<p>
A round table is prepared for in the meeting. The ambassadors are getting seated at the round table, but
they have agreed that more than k ambassadors from the same country does not sit down at the round
table in a row for deeper exchange.
</p>
<p>
Your task is to write a program that reports the number of possible arrangements when rotations are not
counted. Your program should report the number modulo <i>M</i> = 1000003.
</p>
<p>
Let us provide an example. Suppose <i>n</i> = 4 and <i>k</i> = 2. When rotations are counted as different arrangements, the following six arrangements are possible.
</p>
<pre>
AABB
ABBA
BBAA
BAAB
ABAB
BABA
</pre>
<p>
However, when rotations are regarded as same, the following two arrangements are possible.
</p>
<pre>
AABB
ABAB
</pre>
<p>
Therefore the program should report 2.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of two integers <i>n</i> (1 ≤ <i>n</i> ≤ 1000) and <i>k</i> (1 ≤ k ≤ 1000) in one line.
</p>
<p>
It does not always hold <i>k</i> < <i>n</i>. This means the program should consider cases in which the ambassadors
from only one country attend the meeting.
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the number of possible arrangements modulo <i>M</i> = 1000003 in one line.
</p>
<H2>Sample Input</H2>
<pre>
3 1
3 2
3 3
4 2
10 5
1000 500
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
2
4
2
90
570682
</pre>
|
p01328 |
<h1><font color="#000">Problem H:</font> è¿·ãç«ãèµ°ã£ã</h1>
<p>æŽèåå°éåºã¹ãã¬ã€ãã£ããã§ã¯ããããã®ç«ã飌ãããŠãããç«ã®æ°ãããŸãã«ãå€ãããããã®åºã®ã¹ã¿ããã§ããåžã¯é€ããã«å°ã£ãŠããã
ããã€ãã®å Žæã«é€ã眮ããŠããç«ã¯è²ªæ¬²ãªã®ã§æãè¿ãé€ã«åãã£ãŠããŸããäžã€ã®é€å
¥ãã«ããããã®ç«ãéäžããŠããŸãã
ããªãã¯åžã®ããã«ãã§ããã ãç«ãéäžããªãé€ã®é
çœ®ãæ±ããåé¡ãè§£ãããšã«ããã</p>
<p>åé¡ãç°¡åã«ãããããç«ã¯å¹³é¢äžã® y>0 ã®éšåã«ããŠé€ã眮ããŸã§åããªããšããã
ç«ã¯ N åã®éå£ã«åãããŠããŠãäžç®æã«äœå¹ããããããããªãã
é€å
¥ã㯠y=0 äžã® M ç¹ã«åºå®ããŠããããã®äžããããã€ãéžãã§é€ãå
¥ããããšã«ãªãã
é€ãå
¥ãããšãç«ã¯(ãŠãŒã¯ãªããè·é¢ã§)äžçªè¿ãé€ã®å
¥ã£ãé€å
¥ãã«åããããåãè·é¢ã«äºã€ãããšãã¯x座æšãå°ããã»ãã«åãããã®ãšããã</p>
<p>ãã®æ¡ä»¶ã®äžã§ãæãç«ãéãŸã£ãŠããé€å
¥ãã®ç«ã®æ°ãæå°åããªããã
</p>
<h2>Input</h2>
å
¥åã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããã
<pre>
N M
x<sub>1</sub> y<sub>1</sub> C<sub>1</sub>
...
x<sub>N</sub> y<sub>N</sub> C<sub>N</sub>
x<sub>1</sub>
...
x<sub>M</sub>
</pre>
<p>å
¥åã®1è¡ç®ã«ã¯ã2ã€ã®æŽæ° N, M ãã¹ããŒã¹æåã§åºåãããŠäžããããããããã¯ãåé¡æã§æå®ãããšããã§ããã0 ≤ N ≤ 1000 ããã³ 1 ≤ M ≤ 1000 ãæºããã</p>
<p>ç¶ã N è¡ã«ã¯ãããããã®ç«ã®éå£ã«ã€ããŠ1è¡ã«1ã€ãã€ãéå£ã®äœçœ®ã® x, y 座æšãè¡šãæŽæ°ã®çµ
(-10000 ≤ x ≤ 10000, 0 < y ≤ 10000)ãšäœå¹éãŸã£ãŠããããè¡šãæŽæ°C(1 ≤ C ≤ 100000)ãäžããããã</p>
<p>ãã®åŸã®Mè¡ã«ã¯ãããããã®é€å
¥ãã«ã€ããŠ1è¡ã«1ã€ãã€ãé€å
¥ãã®äœçœ®ã®x座æšãè¡šãæŽæ°(-10000 ≤ x ≤ 10000)ãäžããããã
åãç¹ã«ãäºã€ä»¥äžã®é€å
¥ããååšããããšã¯ãªãã
</p>
<h2>Output</h2>
<p>æãç«ãéãŸã£ãŠããé€å
¥ãã®ç«ã®æ°ã®æå°å€ãåºåããã
</p>
<h2>Notes on Test Cases</h2>
<p>
äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã
</p>
<p>
N, M ããšãã« 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã
</p>
<h2>Sample Input</h2>
<pre>
3 3
-1 1 1
0 1 1
1 1 1
-3
0
3
5 5
7 3 5
-9 2 7
4 9 6
10 5 9
-9 7 9
0
-1
-2
-9
-8
0 0
</pre>
<h2>Output for Sample Input</h2>
<pre>
2
20
</pre> |
p03315 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is always an integer in Takahashi's mind.</p>
<p>Initially, the integer in Takahashi's mind is <var>0</var>. Takahashi is now going to eat four symbols, each of which is <code>+</code> or <code>-</code>. When he eats <code>+</code>, the integer in his mind increases by <var>1</var>; when he eats <code>-</code>, the integer in his mind decreases by <var>1</var>.</p>
<p>The symbols Takahashi is going to eat are given to you as a string <var>S</var>. The <var>i</var>-th character in <var>S</var> is the <var>i</var>-th symbol for him to eat.</p>
<p>Find the integer in Takahashi's mind after he eats all the symbols.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>S</var> is <var>4</var>.</li>
<li>Each character in <var>S</var> is <code>+</code> or <code>-</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the integer in Takahashi's mind after he eats all the symbols.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>+-++
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<ul>
<li>Initially, the integer in Takahashi's mind is <var>0</var>.</li>
<li>The first integer for him to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>1</var>.</li>
<li>The second integer to eat is <code>-</code>. After eating it, the integer in his mind becomes <var>0</var>.</li>
<li>The third integer to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>1</var>.</li>
<li>The fourth integer to eat is <code>+</code>. After eating it, the integer in his mind becomes <var>2</var>.</li>
</ul>
<p>Thus, the integer in Takahashi's mind after he eats all the symbols is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>-+--
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>----
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-4
</pre></section>
</div>
</span> |
p02154 | <h1>Problem F: Equilateral Triangle</h1>
<h2>Problem</h2>
<p>$N$åã®é ç¹ãããªãåžå€è§åœ¢ãäžããããã</p>
<p>ãã®åžå€è§åœ¢ã®å
šãŠã®é ç¹ãå«ãæ£äžè§åœ¢ãèãããšãããã®æ£äžè§åœ¢ã®äžèŸºã®é·ãã®æå°å€ãæ±ããã</p>
<p></p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§ãã¹ãп޿°ã§äžããããã</p>
<pre>
$N$
$px_1$ $py_1$
$px_2$ $py_2$
$\vdots$
$px_N$ $py_N$
</pre>
<p>
$1$è¡ç®ã«ã¯åžå€è§åœ¢ã®é ç¹æ°ãè¡šãæŽæ°$N$ãäžããããã<br>
ç¶ã$N$è¡ã«ã¯åžå€è§åœ¢ã®åé ç¹ã®æ
å ±ãåæèšåšãã®é ã§äžããããã<br>
$1+i$è¡ç®ã«ã¯$i$çªç®ã®é ç¹ã®åº§æšã衚ã$px_i$,$py_i$ã空çœåºåãã§äžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$3 \le N \le 10000$</li>
<li>$-10^9 \le px_i, py_i \le 10^9$</li>
<li>åžå€è§åœ¢ã®é ç¹ã®ãã¡ã©ã®3ç¹ãéžãã§ããåäžçŽç·äžã«ã¯ååšããªã</li>
</ul>
<h2>Output</h2>
<p>
æ¡ä»¶ãæºããæ£äžè§åœ¢ã®äžèŸºã®é·ãã®æå°å€ãåºåããã<br>
ãã ãã$10^{-5}$ ãŸã§ã®çµ¶å¯Ÿèª€å·®ãŸãã¯çžå¯Ÿèª€å·®ã¯èš±å®¹ãããã
</p>
<h2>Sample Input 1</h2>
<pre>
4
2 3
1 2
2 1
3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
3.04720672
</pre>
<h2>Sample Input 2</h2>
<pre>
7
-96469 25422
-55204 -45592
-29140 -72981
98837 -86795
92303 63297
19059 96012
-67980 70342
</pre>
<h2>Sample Output 2</h2>
<pre>
310622.35426197
</pre>
|
p00169 |
<H1>ãã©ãã¯ãžã£ãã¯</H1>
<p>
ãã©ãã¯ãžã£ãã¯ã¯ã«ãžãã§è¡ãããã«ãŒãã²ãŒã ã®äžçš®ã§ã1 ã 13 ãŸã§ã®æ°ãæžãããã«ãŒãã䜿ã£ãŠã²ãŒã ãè¡ãããŸããåã«ãŒãã®ç¹æ°ã¯æ¬¡ã®ããã«æ±ºãŸã£ãŠããŸãã
</p>
<ul>
<li>1 㯠1 ç¹ããã㯠11 ç¹</li>
<li>2 ãã 9 ãŸã§ã¯ãæžãããŠããæ°ã®éãã®ç¹æ°</li>
<li>10 ãã 13 ãŸã§ã¯ã10 ç¹</li>
</ul>
<p>
ãã®ã²ãŒã ã«ã¯èŠªãå«ããäœäººãã®åå è
ãããããããããäœæãã®ã«ãŒãã®çµãæã£ãŠããŸãããã®ã«ãŒãã®çµã®ããšãæãšåŒã³ãŸããæã®ç¹æ°ã¯ã«ãŒãã®ç¹æ°ã®åèšã§ãããã®èšç®ã¯æ¬¡ã®ããã«è¡ããã®ãšããŸãã
</p>
<ul>
<li>ã«ãŒãã®ç¹æ°ã®åèšã 21 ãã倧ãããªããšãã¯ãæã®ç¹æ°ã 0 ç¹ãšãã</li>
<li>ã«ãŒãã®ç¹æ°ãšããŠã1 㯠1 ç¹ãšèšç®ããŠã 11 ç¹ãšèšç®ããŠãããããæã®ç¹æ°ãæå€§ãšãªãæ¹ãéžã¶ããšãšãã</li>
</ul>
<p>
é
ãããã«ãŒãã®æ
å ±ãå
¥åãšããæã®ç¹æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<!--
ãã ãã1ã€ã®æã«å«ãŸããã«ãŒãã®ææ° n ã¯1以äž21以äžãšããåãæ°ãæžãããã«ãŒããäœæã§ã
å«ãããšãã§ãããã®ãšããŸãã-->
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>n</sub></var>
</pre>
<p>
ïŒè¡ã« <var>i</var> çªç®ã®ã«ãŒãã«æžãããŠããæŽæ° <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 13) ã空çœåºåãã§ïŒè¡ã«äžããããŸããã«ãŒãã®æ° <var>n</var> 㯠100 ãè¶
ããŸããã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 200 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«æã®ç¹æ°ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
1
7 7 7
7 7 8
12 1
10 1 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
11
21
0
21
12
</pre>
|
p00493 |
<H1>ãžã°ã¶ã°æ° (Zig-Zag Numbers) </H1>
<h2> åé¡</h2>
<p>
æ£ã®æŽæ°ã (å
é ã« 0 ãã€ããã«) 10 鲿³ã§æžããŠæ¡ã®æ°åãé çªã«èŠãŠãããšå¢å ãšæžå°ã亀äºã«ç¹°ãè¿ããŠãããšãïŒãã®æ°ã¯ããžã°ã¶ã°æ°ãã§ãããšåŒã¶ããšã«ãããïŒããšãã°ïŒ2947 ã¯æ¡ã®æ°åã 2 â 9 â 4 â 7 ãšïŒå¢å â æžå° â å¢å ã®é ã«ãªã£ãŠããã®ã§ãžã°ã¶ã°æ°ã§ããïŒãŸãïŒ71946 㯠æžå° â å¢å â æžå° â å¢å ã®é ãªã®ã§ãžã°ã¶ã°æ°ã§ããïŒäžæ¹ïŒ123 ã 71446 ã 71442 ã 88 ã¯ãžã°ã¶ã°æ°ã§ã¯ãªãïŒãªãïŒ1 æ¡ã®æ£ã®æŽæ°ã¯ãžã°ã¶ã°æ°ã§ãããšèããããšãšããïŒ
</p>
<p>
A ä»¥äž B 以äžã® M ã®åæ°ã®ãã¡ïŒãžã°ã¶ã°æ°ã®åæ°ã 10000 ã§å²ã£ãäœããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥å㯠3 è¡ãããªãïŒ1 è¡ã« 1 ã€ãã€æ£ã®æŽæ°ãæžãããŠããïŒ
</p>
<p>
1 è¡ç®ã®æŽæ°ã¯ A ãïŒ2 è¡ç®ã®æŽæ°ã¯ B ãïŒ3 è¡ç®ã®æŽæ°ã¯ M ã衚ãïŒããã㯠1 ⊠A ⊠B ⊠10<sup>500</sup>ïŒ1 ⊠M ⊠500 ãæºããïŒ
</p>
<p>
â» A ã B ã®å€ã¯ïŒéåžžã®æŽæ°ã衚ãããŒã¿åã«ã¯åãŸããªãå¯èœæ§ãããããšã«æ³šæããïŒ
</p>
<h2> åºå</h2>
<p>
A ä»¥äž B 以äžã® M ã®åæ°ã®ãã¡ïŒãžã°ã¶ã°æ°ã®åæ°ã 10000 ã§å²ã£ãäœãã 1 è¡ã§åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
100
200
5
</pre>
<h3>åºåäŸ 1</h3>
<pre>
13
</pre>
<p>
å
¥åºåäŸ 1 ã«ãããŠïŒ100 ä»¥äž 200 以äžã® 5 ã®åæ°ã§ãããžã°ã¶ã°æ°ã¯ïŒ105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195 ã® 13 åã§ããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
6
1234567
3
</pre>
<h3>åºåäŸ 2</h3>
<pre>
246
</pre>
<p>
å
¥åºåäŸ 2 ã«ãããŠïŒ6 ä»¥äž 1234567 以äžã® 3 ã®åæ°ã§ãããžã°ã¶ã°æ°ã¯ 50246 åããã®ã§ïŒããã 10000 ã§å²ã£ãäœãã§ãã 246 ãåºåããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00539 |
<h2>JOI å
Œ (JOI Park)</h2>
<p>
20XX 幎㫠IOI åœã§è¡ããããªãªã³ããã¯ã«åãïŒIOI åœã«ãã JOI å
¬åãæŽåããããšã«ãªã£ãïŒJOIå
¬åã«ã¯ <var>N</var> åã®åºå ŽãããïŒåºå Žã«ã¯ 1 ãã <var>N</var> ã®çªå·ãã€ããŠããïŒåºå Žãç¹ã <var>M</var> æ¬ã®éãããïŒéã«ã¯ 1 ãã <var>M</var> ã®çªå·ãã€ããŠããïŒé <var>i</var> (1 ≤ <var>i</var> ≤ <var>M</var>) ã¯åºå Ž <var>A<sub>i</sub></var> ãšåºå Ž <var>B<sub>i</sub></var> ãåæ¹åã«ç¹ãã§ããïŒé·ã㯠<var>D<sub>i</sub></var> ã§ããïŒã©ã®åºå Žããã©ã®åºå Žãžãããã€ãã®éã蟿ã£ãŠè¡ãããšãã§ããïŒ
</p>
<p>
æŽåèšç»ã§ã¯ïŒãŸãïŒ0 以äžã®æŽæ° <var>X</var> ãéžã³ïŒåºå Ž 1 ããã®è·é¢ã <var>X</var> 以äžã§ãããããªåºå Ž (åºå Ž 1 ãå«ã) ã©ããããã¹ãŠçžäºã«å°äžéã§çµã¶ïŒãã ãïŒåºå Ž <var>i</var> ãšåºå Ž <var>j</var> ã®è·é¢ãšã¯ïŒåºå Ž <var>i</var> ããåºå Ž <var>j</var> ã«è¡ããšãã«éãéã®é·ãã®åã®æå°å€ã§ããïŒæŽåèšç»ã§ã¯å°äžéã®æŽåã³ã¹ãã«é¢ããæŽæ° <var>C</var> ãå®ãŸã£ãŠããïŒå°äžéã®æŽåã«ãããã³ã¹ã㯠<var>C × X</var> ã§ããïŒ
</p>
<p>
次ã«ïŒå°äžéã§çµã°ããåºå Žã©ãããçµã¶éããã¹ãŠæ€å»ããïŒéã®æ€å»ã«ã³ã¹ãã¯ããããªãïŒæåŸã«ïŒæ€å»ãããã«æ®ã£ãéããã¹ãŠè£ä¿®ããïŒé·ã <var>d</var> ã®éãè£ä¿®ããããã«ãããã³ã¹ã㯠<var>d</var> ã§ããïŒæŽåèšç»å®æœåã® JOI å
¬åã«ã¯å°äžéã¯ãªãïŒJOI å
¬åã®æŽåã«ãããã³ã¹ãã®åã®æå°å€ãæ±ããïŒ
</p>
<h3>課é¡</h3>
<p>
JOI å
¬åã®åºå Žã®æ
å ±ãšïŒå°äžéã®æŽåã³ã¹ãã«é¢ããæŽæ°ãäžãããããšãïŒJOI å
¬åã®æŽåã«ããã
ã³ã¹ãã®åã®æå°å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h3>å
¥å</h3>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒæŽæ° <var>N</var>, <var>M</var>,<var>C</var> ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒåºå Žã <var>N</var> åïŒéã <var>M</var> æ¬ããïŒå°äžéã®æŽåã³ã¹ãã«é¢ããæŽæ°ã <var>C</var> ã§ããããšã衚ãïŒ</li>
<li> ç¶ã <var>M</var> è¡ã®ãã¡ã® <var>i</var> è¡ç® (1 ≤ <var>i</var> ≤ <var>M</var>) ã«ã¯ïŒæŽæ° <var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>, <var>D<sub>i</sub></var> ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒé <var>i</var> ãåºå Ž <var>A<sub>i</sub></var> ãšåºå Ž <var>B<sub>i</sub></var> ãç¹ãïŒé·ãã <var>D<sub>i</sub></var> ã§ããããšã衚ãïŒ
</li>
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«ïŒJOI å
¬åã®æŽåã«ãããã³ã¹ãã®åã®æå°å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ
</p>
<h3>å¶é</h3>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ</p>
<ul>
<li> 2 ≤ <var>N</var> ≤ 100 000ïŒ</li>
<li> 1 ≤ <var>M</var> ≤ 200 000ïŒ</li>
<li> 1 ≤ <var>C</var> ≤ 100 000ïŒ</li>
<li> 1 ≤ <var>A<sub>i</sub></var> ≤ <var>N</var> (1 ≤ <var>i</var> ≤ <var>M</var>)ïŒ</li>
<li> 1 ≤ <var>B<sub>i</sub></var> ≤ <var>N</var> (1 ≤ <var>i</var> ≤ <var>M</var>)ïŒ</li>
<li> <var>A<sub>i</sub></var> ≠ <var>B<sub>i</sub></var> (1 ≤ <var>i</var> ≤ <var>M</var>)ïŒ</li>
<li> (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) ≠ (<var>A<sub>j</sub></var>, <var>B<sub>j</sub></var>) ããã³ (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) ≠ (<var>B<sub>j</sub></var>, <var>A<sub>j</sub></var>) (1 ≤ <var>i</var> < <var>j</var> ≤ <var>M</var>)ïŒ</li>
<li> 1 ≤ <var>D<sub>i</sub></var> ≤ 100 000 (1 ≤ <var>i</var> ≤ <var>M</var>)ïŒ</li>
<li> äžããããå
¥åããŒã¿ã«ãããŠã¯ïŒã©ã®åºå Žããã©ã®åºå Žãžãããã€ãã®éã蟿ãããšã«ããè¡ããããšãä¿èšŒãããŠããïŒ</li>
</ul>
<h3>å
¥åºåäŸ</h3>
<h3>å
¥åäŸ 1 </h3>
<pre>
5 5 2
2 3 1
3 1 2
2 4 3
1 2 4
2 5 5
</pre>
<h3>åºåäŸ 1</h3>
<pre>
14
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒ<var>X</var> = 3 ãšããŠïŒåºå Ž 1 ããã®è·é¢ã 3 以äžã§ãããããªåºå Ž (åºå Ž 1, åºå Ž 2, åºå Ž 3) ã©ããããã¹ãŠçžäºã«å°äžéã§çµãã ãšãïŒæŽåã«ãããã³ã¹ãã®å㯠2 × 3 + 3 + 5 = 14 ãšãªãïŒãããæå°å€ã§ããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
5 4 10
1 2 3
2 3 4
3 4 3
4 5 5
</pre>
<h3>åºåäŸ 2</h3>
<pre>
15
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒX = 0 ã®ãšãæŽåã«ãããã³ã¹ãã®åãæå°ã«ãªãïŒ
</p>
<h3>å
¥åäŸ 3 </h3>
<pre>
6 5 2
1 2 2
1 3 4
1 4 3
1 5 1
1 6 5
</pre>
<h3>åºåäŸ 3</h3>
<pre>
10
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒ<var>X</var> = 5 ãšããŠãã¹ãŠã®åºå Žãçžäºã«å°äžéã§çµãã ãšãïŒæŽåã«ãããã³ã¹ãã®åãæå°ã«ãªãïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p01001 |
<h1>Problem C: General of Taiko</h1>
<h2>Problem</h2>
<p>
ãšããã²ãŒã ã»ã³ã¿ãŒã«ã¯ãæ²ã«åãããŠæµããŠããèé¢éãã«å倪éŒãå©ãã²ãŒã ããããŸãã
èé¢ã¯é·ã<var> L </var>ã®ã»ã«ãããªããåã»ã«ã«ã¯äœããªãããŸãã¯ããŒããšåŒã°ãããã¬ã€ã€ãŒããšãã¹ãè¡åã衚ããèšå·ããããŸãã
ããŒãã¯2çš®é¡ãããããããå倪éŒã®é¢ãå©ãããã³ããå倪éŒã®çžãå©ããã³ããããããŸãã
ãããã®ããŒãã«åãããŠå倪éŒãå©ããšåŸç¹ãåŸãããšãã§ããŸãã
ãã®åŸç¹ã®åèšã10000ç¹ä»¥äžã§ããã°ã¯ãªã¢ãšãªããŸãã
</p>
<p>
ãã®ãšãããã¬ã€ã€ãŒãæ²ãã¯ãªã¢ã§ãã確çãæ±ããªããããã ãããã¬ã€ã€ãŒã¯åžžã«æé©ãªè¡åããšãããšã«ããŸãã
</p>
<p>
ãã¬ã€ã€ãŒãèé¢éãã«å倪éŒãå©ã粟床ã¯11段éãããããããã
0%, 10%, 20%, ..., 90%, 100%ã®ç¢ºçã§èé¢éãã«å倪éŒãå©ãããšãã§ããŸãã
</p>
<p>
äžèšã®äºçš®é¡ã®åäœã¯å³è
ãšå·Šè
ã©ã¡ãã§ã§ãè¡ãããšãã§ããŸãã
ãã¬ã€ã€ãŒã®æ
å ±ãšããŠãããããã®è
ã§è¡ã£ãå Žåã®ç²ŸåºŠã®å®å®çã衚ãå€ã16çš®é¡ãäžèšã®ããã«äžããããŸãã
</p>
<pre>
<var>lt</var>_<var>lt</var> <var>lt</var>_<var>rt</var> <var>lt</var>_<var>lk</var> <var>lt</var>_<var>rk</var>
<var>rt</var>_<var>lt</var> <var>rt</var>_<var>rt</var> <var>rt</var>_<var>lk</var> <var>rt</var>_<var>rk</var>
<var>lk</var>_<var>lt</var> <var>lk</var>_<var>rt</var> <var>lk</var>_<var>lk</var> <var>lk</var>_<var>rk</var>
<var>rk</var>_<var>lt</var> <var>rk</var>_<var>rt</var> <var>rk</var>_<var>lk</var> <var>rk</var>_<var>rk</var>
</pre>
<p>
ãã ãã<var> lt </var> ã¯å·Šè
ã§ãã³, <var> rt </var> ã¯å³è
ã§ãã³, <var> lk </var> ã¯å·Šè
ã§ã³ã, <var> rk </var> ã¯å³è
ã§ã³ãã®åäœã衚ããŸãã
äŸãã°ã<var> lt</var>_<var>rk </var>ã¯å·Šè
ã§ãã³ã®ããšã«å³è
ã§ã³ããè¡ã£ãæã®ç²ŸåºŠã®å®å®ã®åºŠåãã衚ãããã®å€ã«ãã£ãŠå·Šè
ã§ãã³ã®ããšã«å³è
ã§ã³ããè¡ããšãã®ç²ŸåºŠããäžèšã®ããã«å€åããŸãã
</p>
<pre>
ãã¬ã€ã€ãŒã®ç²ŸåºŠ = max(0, (粟床ã®å®å®ç - 10) * 10 + äžã€åã®ç²ŸåºŠ) (%)
</pre>
<p>
æ²ã®æ
å ±ã¯ä»¥äžã®ãšããã§ãã
æ²ã®é·ãã衚ã<var> L </var>ãèé¢ã衚ã<var> L </var>åã®æ°å<var> s<sub>i</sub> </var>(0 ≤<var> i </var>< <var> L </var>)ã§ç€ºããããèé¢ã®å
é ã¯<var> s<sub>0</sub> </var>ã§ããã
<var> s<sub>i</sub> </var>ã®å€ã¯ä»¥äžã®3ã€ã§ãã
</p>
<pre>
0 ... ããŒããªã
1 ... ãã³
2 ... ã³ã
</pre>
<p>
ãã¬ã€ã€ãŒãæåã«å倪éŒãå©ããšãã®ç²ŸåºŠã¯100%ã§ãã
ãŸãããã¬ã€ã€ãŒã¯èé¢ãç¡èŠããããšãã§ããŸãã
ããŒãããªãã£ãããããŒããç¡èŠããå Žåããã¬ã€ã€ãŒã®ç²ŸåºŠã¯100%ã«ãªããŸãã
</p>
<p>
åããŒãã«åãããŠå倪éŒãå©ãããšãã®åŸç¹ã¯äžèšã®ããã«ãªããŸãã
</p>
<pre>
åŸç¹ =<var> A </var>+<var> B </var>* min(ã³ã³ãæ°, 10)
</pre>
<p>
ãã®åé¡ã«ãããã³ã³ãæ°ãšã¯ãé£ç¶ããŠããŒãã«åãããŠå倪éŒãå©ããæ°ã§ãã
ãã¬ã€ã€ãŒãããŒãã«åãããŠå©ããå Žåãäžèšã®åŒãå
ã«åŸç¹ãå
¥ãããã®åŸã«ã³ã³ãæ°ã1å¢ããŸãã
ããŒãã«åãããŠå倪éŒãå©ããªãã£ãå Žåãã³ã³ããéåããã³ã³ãæ°ã0ã«ãªããŸãã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®ãšããã§ãã
</p>
<pre>
<var>lt</var>_<var>lt</var> <var>lt</var>_<var>rt</var> <var>lt</var>_<var>lk</var> <var>lt</var>_<var>rk</var>
<var>rt</var>_<var>lt</var> <var>rt</var>_<var>rt</var> <var>rt</var>_<var>lk</var> <var>rt</var>_<var>rk</var>
<var>lk</var>_<var>lt</var> <var>lk</var>_<var>rt</var> <var>lk</var>_<var>lk</var> <var>lk</var>_<var>rk</var>
<var>rk</var>_<var>lt</var> <var>rk</var>_<var>rt</var> <var>rk</var>_<var>lk</var> <var>rk</var>_<var>rk</var>
<var>L</var>
<var>s<sub>0</sub></var> <var>s<sub>1</sub></var> <var>s<sub>2</sub></var> ⊠<var>s<sub>L - 1</sub></var>
<var>A</var> <var>B</var>
</pre>
<p>
å
¥åã®çµããã¯è² ã®æŽæ°4ã€ãããªããŸãã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããŸãã
</p>
<ul>
<li>0 <<var> L </var>≤ 100</li>
<li>0 ≤ 粟床ã®å®å®ç ≤ 10</li>
<li>粟床ã®å®å®çã¯æŽæ°</li>
<li>0 <<var> A </var>, <var> B </var>≤ 10000</li>
<li><var> A </var>ãš<var> B </var>ã¯ãšãã«100ã®åæ°</li>
<li>ããŒã¿ã»ããã®æ°ã¯100å以äž</li>
</ul>
<h2>Output</h2>
<p>
åå
¥åã«å¯ŸããŠãã¯ãªã¢ã§ãã確çã1è¡ã§åºåããªããã
ãã ããåºåã¯0.001以äžã®èª€å·®ãå«ãã§ãè¯ãã§ãã
</p>
<h2>Sample Input</h2>
<pre>
9 0 0 0
0 9 0 0
0 0 0 0
0 0 0 0
5
1 1 1 1 1
1000 500
10 10 10 10
10 10 10 10
10 10 10 10
10 10 10 10
5
1 0 2 0 1
1000 2000
3 8 6 10
0 1 6 8
10 2 4 7
8 6 6 8
19
2 2 0 2 2 0 2 1 0 1 2 0 1 2 0 1 0 2 2
200 100
-1 -1 -1 -1
</pre>
<h2>Sample Output</h2>
<pre>
0.3024000000
0.0000000000
0.5120000000
</pre>
|
p01451 |
<H1>Problem E: è¡ãé§ããé</H1>
<p>
ããŒãŽã¡çåœã«ã¯ããã¿ã¿æãšãããæãïŒçš®é¡ã®æ°æãæ®ãããŠããããã¿ã¿æã®æå€§ã®ç¹åŸŽã¯ã
é
¢è±ã«ãã€ãããã«ãå
¥ããŠé£ã¹ãããšã§ãããã ããããæã¯ããã€ãããã«ã«é
¢è±ãå
¥ããŠé£ã¹
ãããããªïŒã€ã®æ°æããäºãã«ä»²è¯ããã£ãŠãããã¯ãããªãããã¿ã¿æãšãããæã¯ãäœçŸå¹Žã
ã®æãããã£ãšããã¿åããç¶ããŠããã
</p>
<p>
ãããªããæ¥ãããŒãŽã¡çã®ããšã«ãïŒã€ã®æ°æããå顿žãå±ãããããã«ãããšãã¿ã¿æã¯ãèª
åãã¡ãæ®ããè¡ïŒ¡ãšè¡ïŒ¢ã®ããã ãçµã¶éã建èšããŠã»ããããããäžæ¹ã§ãããæããèªåãã¡
ãæ®ããè¡ïŒ£ãšè¡ïŒ€ã®ããã ãçµã¶éã建èšããŠã»ãããããã
</p>
<p>
ïŒã€ã®æ°æãè¡çªããã®ãé²ãããããã¿ã¿æãéãéãšãããæãéãéã亀差ãããããšã¯ã§ã
ãªãããŸããæè¡çãªå¶çŽã«ãããïŒã€ã®è¡ã®ããã ãäžçŽç·ã«çµã¶ãããªéãã建èšããããšã¯ã§
ããªããã€ãŸããå¿
èŠãªãã°è¡ïŒ¡ãšè¡ïŒ¢ãçŽæ¥éã§çµã°ãã«ãããã€ãã®ãã¿ã¿æã®è¡ãçµç±ããŠè¡
ãšè¡ïŒ¢ã鿥çã«çµã¶ããšã«ãªãã ããïŒãã¡ããããããæã®è¡ãçµç±ããŠã¯ãªããªãïŒããã®
éããã¿ã¿æã®è¡ãçµã¶éã©ããã¯äº€å·®ããŠããŠããããè¡ïŒ£ãšè¡ïŒ€ã«ã€ããŠãåæ§ã§ããã
</p>
<p>
éã建èšããã«ã¯ããã®é·ãã«æ¯äŸããã³ã¹ãããããããªã®ã§ãæ¡ä»¶ãã¿ããã€ã€ãã§ããã ã建
èšããéã®é·ãã®åèšãçããªãããã«ããããããŠãé·ãã®æå°å€ã¯ããã€ã«ãªãã ãããã
</p>
<H2>Input</H2>
<p>
<i>N<sub>A</sub> N<sub>B</sub></i><br>
<i>x</i><sub><i>A</i>,1</sub> <i>y</i><sub><i>A</i>,1</sub><br>
<i>x</i><sub><i>A</i>,2</sub> <i>y</i><sub><i>A</i>,2</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub> <i>y</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub><br>
<i>x</i><sub><i>B</i>,1</sub> <i>y</i><sub><i>B</i>,1</sub><br>
<i>x</i><sub><i>B</i>,2</sub> <i>y</i><sub><i>B</i>,2</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub> <i>y</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub><br>
</p>
<p>
å
¥åã®ïŒè¡ç®ã«ã¯ãæŽæ°<i>N<sub>A</sub></i>ïŒ2 ≤ <i>N<sub>A</sub></i> ≤ 1,000ïŒãšæŽæ°<i>N<sub>B</sub></i>ïŒ2 ≤ <i>N<sub>B</sub></i> ≤ 1,000ïŒãã空çœåºåãã§æžãããŠãããããã¯ãããŒãŽã¡çåœã«ã¯ãã¿ã¿æãæ®ããè¡ãNA åããããæãæ®ããè¡ãNB åããããšããããããåæç¶æ
ã§ã¯ãã©ãã«ãéã¯å»ºèšãããŠããªãã
</p>
<p>
ç¶ã<i>N<sub>A</sub></i> è¡ã«ã¯ãæŽæ°<i>x<sub>A,i</sub></i>ïŒ-10,000 ≤ <i>x<sub>A,i</sub></i> ≤ 10,000ïŒãšæŽæ°<i>y<sub>A,i</sub></i>ïŒ-10,000 ≤ <i>y<sub>A,i</sub></i> ≤ 10,000ïŒãã空çœåºåãã§æžãããŠãããããŒãŽã¡çåœã®å°çã¯ïŒæ¬¡å
çŽäº€åº§æšå¹³é¢ã§ããããããïŒïŒ i è¡ç®ã«æžãããæŽæ°<i>x<sub>A,i</sub></i> ãš<i>y<sub>A,i</sub></i> ã¯ããã¿ã¿æãæ®ããi çªç®ã®è¡ã®äœçœ®åº§æšã(<i>x<sub>A,i</sub></i>, <i>y<sub>A,i</sub></i>) ã§ããããšãããããã(<i>x<sub>A,1</sub></i>, <i>y<sub>A,1</sub></i>) ãš(<i>x<sub>A,2</sub></i>, <i>y<sub>A,2</sub></i>) ããçµã¶ã¹ãïŒã€ã®è¡ã®åº§æšã§ããã
</p>
<p>
ç¶ã<i>N<sub>B</sub></i> è¡ã«ã¯ãæŽæ°<i>x<sub>B,i</sub></i>ïŒ-10,000 ≤ <i>x<sub>B,i</sub></i> ≤ 10,000ïŒãšæŽæ°<i>y<sub>B,i</sub></i>ïŒ-10,000 ≤ <i>y<sub>B,i</sub></i> ≤ 10,000ïŒãã空çœåºåãã§æžãããŠãããïŒïŒ <i>N<sub>A</sub></i> ïŒ i è¡ç®ã«æžãããæŽæ°<i>x<sub>B,i</sub></i> ãš<i>y<sub>B,i</sub></i> ã¯ããããæãæ®ããi çªç®ã®è¡ã®äœçœ®åº§æšã(<i>x<sub>B,i</sub></i>, <i>y<sub>B,i</sub></i>) ã§ããããšãããããã(<i>x<sub>B,1</sub></i>, <i>y<sub>B,1</sub></i>) ãš(<i>x<sub>B,2</sub></i>, <i>y<sub>B,2</sub></i>) ããçµã¶ã¹ãïŒã€ã®è¡ã®åº§æšã§ããã
</p>
<p>
ã©ã®ïŒã€ã®è¡ã®åº§æšãç°ãªã£ãŠãããã©ã®ïŒã€ã®è¡ãåäžçŽç·äžã«ãªããšä»®å®ããŠããã
</p>
<H2>Output</H2>
<p>
åé¡æã®æ¡ä»¶ãã¿ããããã«éã建èšãããšããéã®é·ãã®åèšã®æå°å€ãåºåãããããã§èšã
ãé·ãããšã¯ããŠãŒã¯ãªããè·é¢ã®ããšã§ããããã ããã©ããã£ãŠãæ¡ä»¶ãã¿ããéã建èšã§ããª
ããšãã¯ã代ããã«-1 ãåºåãããåºåã¯èª€å·®ãå«ãã§ããŠãããããçã®å€ãšã®çžå¯Ÿèª€å·®ã10<sup>-9</sup>æªæºã§ãªããã°ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
2 2
0 0
1 1
2 0
2 -1
</pre>
<h2>Sample Output 1</h2>
<pre>
2.414213562373
</pre>
<h2>Sample Input 2</h2>
<pre>
2 3
4 0
0 0
2 3
2 -2
3 1
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre>
<h2>Sample Input 3</h2>
<pre>
5 2
-2 1
1 2
-1 3
-1 5
1 4
0 4
0 0
</pre>
<h2>Sample Output 3</h2>
<pre>
12.359173603117
</pre> |
p03196 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> integers <var>a_1, a_2, ..., a_N</var> not less than <var>1</var>.
The values of <var>a_1, a_2, ..., a_N</var> are not known, but it is known that <var>a_1 \times a_2 \times ... \times a_N = P</var>.</p>
<p>Find the maximum possible greatest common divisor of <var>a_1, a_2, ..., a_N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{12}</var></li>
<li><var>1 \leq P \leq 10^{12}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>P</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 24
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The greatest common divisor would be <var>2</var> when, for example, <var>a_1=2, a_2=6</var> and <var>a_3=2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>As <var>a_i</var> are positive integers, the only possible case is <var>a_1 = a_2 = a_3 = a_4 = a_5 = 1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>111
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 972439611840
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>206
</pre></section>
</div>
</span> |
p01902 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>
<h2>E: 鬌çããæã - Unbalanced Old Maid -</h2>
<h3>ç©èª</h3>
<p>é«åãããšåç°ãããšåããã¯åäŸã®é ããã®ä»²è¯ã3人çµã ã3äººã¯æ²çžã«ä¿®åŠæ
è¡ã«è¡ãããå°é¢šãæ¥ãŠããŸããæµ·ã§éã¶ããšãã§ããªãã®ã§ããæããããããšã«ããã</p>
<p>
åç°ããã¯åè² äºã«ã¯åŒ·ãããããŒã«ãŒãã§ã€ã¹ãèŠæãªãããèªåã®ã«ãŒããåŒããããšãã«ç¡æèã«ããããããé¡èžãæ«é²ããŠããŸããåç°ãããæããŠæ¢ãŸãªãé«åãããšåããã¯ãåç°ããã®é¡èžãèŠãã ãã§åç°ããã®ææãåãã£ãŠããŸããããåç°ããã®ã«ãŒããåŒããšãã¯ãèªåãæå©ã«ãªãããã«åŒãããšãã§ããã
äžæ¹ãé«åãããšåããã¯ç¹ã«é¡èžããããã¯ããªãã®ã§ãææãã°ããããšã¯ãªãã ãã£ãŠãé«åãããšåããã®ã«ãŒããåŒã人ã¯ãããããé«åãããšåãããæã£ãŠããã«ãŒãã®äžããç確çã§1æåŒãã
</p>
<p>ã©ãèããŠãäžå©ãªåç°ããã¯ãããæãã§ãªããªãåãŠãªãããšã«éåæãèŠããŠããã 䜿çšããã«ãŒãã®çš®é¡æ°<var>n</var>ãšåæã®ææãäžãããããšããåç°ãããè² ããšãªããªã確çãæ±ããŠããããã</p>
<h3>å顿</h3>
<p>é«åãããåç°ãããåããã®3人ã¯ã以äžã®ç¶æ³ã§ããæããè¡ãã</p>
<ul>
<li>䜿çšããã«ãŒãã¯ã1ãã<var>n</var>ãŸã§ã®æŽæ°ãæžããã<var>n</var>çš®é¡ã®ã«ãŒããããã4æãã€ãšãžã§ãŒã«ãŒ1æã®åèš<var>4n+1</var>æã§ããã</li>
<li>æåã®ææãäžãããããšãã3人ã¯ããããèªåã®ææã«åäžã®æŽæ°ãæžãããã«ãŒãã®ãã¢ïŒ2æçµïŒããããªãã°ããã®ãããªãã¢ãå
šãŠæšãŠãã</li>
<li>3人ã¯ãé«åãããåããã®ææããã«ãŒããåŒããããåç°ãããé«åããã®ææããã«ãŒããåŒãããåãããåç°ããã®ææããã«ãŒããåŒãããšããé çªïŒã¿ãŒã³ïŒã§ä»¥äžã®æäœãç¹°ãè¿ããïŒãã®ããæãã§ã¯ãã«ãŒããåŒãã人ããæ¬¡ã«åŒããããšããã«ãŒã«ã§ããããšã«æ³šæãããïŒ</li>
<ol>
<li>äžäººããžã§ãŒã«ãŒã®ã¿ãæã¡ããã®äººä»¥å€ã®2äººã®ææã空ã®ãšããããæãã¯çµäºãããžã§ãŒã«ãŒãæã£ãŠãã人ãè² ããšãªãã</li>
<li>ã«ãŒããåŒãé çªã®äººã®ææã空ã®ãšããã¿ãŒã³ã次ã®äººãšãã1.ã«æ»ãã</li>
<li>ããã§ãªããã°ãã«ãŒããåŒãé çªã®äººã¯æ±ºããããçžæããã«ãŒãã1æåŒãããã ããçžæã®ææã空ã®ãšãããŸã æ®ã£ãŠãããã1人ããã«ãŒããåŒãã</li>
<li>åŒããã«ãŒããšåãæŽæ°ãæžãããã«ãŒããã«ãŒããåŒããäººã®ææã«ããã°ããã®2æãæšãŠãã</li>
<li>ã¿ãŒã³ã次ã®äººãšãã1.ãžæ»ãã</li>
</ol>
<li>ãã ããåç°ããã®ã«ãŒããåŒã人ïŒåãããé«åããïŒã¯ã以äžã®æŠç¥ã§ã«ãŒãåŒãã</li>
<ol>
<li>ããèªåã®ã«ãŒããšåç°ããã®ã«ãŒãã§åãæŽæ°ãæžãããã«ãŒããããã°ããããã®ãã¡æå°ã®æŽæ°ãæžãããã«ãŒããåŒã</li>
<li>ããã§ãªããšããåç°ããããžã§ãŒã«ãŒã§ãªãã«ãŒããæã£ãŠããã°ããããã®ãã¡æå°ã®æŽæ°ãæžãããã«ãŒããåŒã</li>
<li>ããã§ãªããªããåç°ããã¯ãžã§ãŒã«ãŒããæã£ãŠããªãã®ã§ããžã§ãŒã«ãŒãåŒã</li>
</ol>
<li>é«åãããšåããã®ã«ãŒããåŒã人ã¯ãããããé«åãããšåãããæã£ãŠããã«ãŒãã®äžããç確çã§1æåŒãã</li>
</ul>
<p>䜿çšããã«ãŒãã®çš®é¡æ°<var>n</var>ãš3人ã®åæã®ææãäžãããããšããåç°ãããè² ããšãªããªã確çãæ±ããŠããããã</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯4è¡ãããªãã以äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>n</var>
<var>m_1</var> <var>c_{1,1}</var> ... <var>c_{1,m_1}</var>
<var>m_2</var> <var>c_{2,1}</var> ... <var>c_{2,m_2}</var>
<var>m_3</var> <var>c_{3,1}</var> ... <var>c_{3,m_3}</var>
</pre>
<p>
1è¡ç®ã«ãžã§ãŒã«ãŒä»¥å€ã®ã«ãŒãã®çš®é¡æ°<var>n</var>ãäžããããã
ç¶ãå
¥åã¯3è¡ãããªãã2è¡ç®ã«é«åããã®ææã3è¡ç®ã«åç°ããã®ææã4è¡ç®ã«åããã®ææã®æ
å ±ãäžããããã
<var>i+1 (1 ≤ i ≤ 3)</var>è¡ç®ã§ã¯è¡é ã«ææã¡ã®ææ°<var>m_i</var>ãç¶ããŠææã¡ã®ã«ãŒãã衚ã<var>m_i</var>åã®æŽæ°<var>c_{i,j} (1 ≤ j ≤ m_i)</var>ã空çœåºåãã§äžããããã <var>0</var>ã¯ãžã§ãŒã«ãŒã<var>1</var>ãã<var>n</var>ã¯ã«ãŒãã«æžãããæŽæ°ã衚ãã
</p>
<h3>å¶çŽ</h3>
<ul>
<li><var>1 ≤ n ≤ 100</var></li>
<li><var>m_1+m_2+m_3 = 4n+1</var></li>
<li>3äººã®ææã§0ã¯ã¡ããã©1ã€ã<var>1</var>ãã<var>n</var>ã¯ã¡ããã©4åãã€çŸãã</li>
<li><var>0 ≤ c_{i,j} ≤ n</var> (<var>1 ≤ i ≤ 3</var>, <var>1 ≤ j ≤ m_i</var>)</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>åç°ãããè² ããšãªããªã確çã1è¡ã«åºåãããçãã«ã¯<var>10^{−6}</var>ãè¶
ãã絶察誀差ããã£ãŠã¯ãªããªãã</p>
<h3>å
¥åäŸ1</h3>
<pre>
1
1 1
3 0 1 1
1 1
</pre>
<h3>åºåäŸ1</h3>
<pre>0.0</pre>
<p>
é«åãããåããã®ã«ãŒã1ãåŒããé«åãããšåããã¯ææã空ã«ãªãã
åç°ããã¯ã©ãããŠãåã€ããšã¯ã§ããªãã
</p>
<h3>å
¥åäŸ2</h3>
<pre>
1
2 1 1
1 1
2 0 1
</pre>
<h3>åºåäŸ2</h3>
<pre>0.5</pre>
<p>ã¯ããã®é«åããã®ã¿ãŒã³ã¯ãé«åããã®ææãæ¢ã«ç©ºãªã®ã§äœãããªããæ¬¡ã®åç°ããã®ã¿ãŒã³ã§ã¯ãåç°ããã¯åããã®ææã®ãã¡ãããã0.5ã®ç¢ºçã§ã«ãŒã1ããžã§ãŒã«ãŒãåŒããã«ãŒã1ãåŒãããšããåç°ããã®ææã¯ç©ºãšãªãåå©ãããäžæ¹ãžã§ãŒã«ãŒãåŒãããšãã¯ã次ã®åããã®ã¿ãŒã³ã§ãåããã¯ç¢ºå®ã«ã«ãŒã1ãåŒãã®ã§åç°ãããè² ããšãªãã</p>
<h3>å
¥åäŸ3</h3>
<pre>
2
3 0 1 2
3 1 2 2
3 1 1 2
</pre>
<h3>åºåäŸ3</h3>
<pre>0.5</pre>
<h3>å
¥åäŸ4</h3>
<pre>
2
2 0 1
6 2 2 2 1 1 1
1 2
</pre>
<h3>åºåäŸ4</h3>
<pre>0.6666666667</pre> |
p00610 |
<H1><font color="#000000">Problem F:</font> Cleaning Robot 2.0</H1>
<p>
Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful.
</p>
<p>
First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has <i>N</i> × <i>N</i> rooms arranged in a square likewise. Then he laid either black or white carpet on each room.
</p>
<p>
Since still enough money remained, he decided to spend them for development of a new robot. And finally he completed.
</p>
<p>
The new robot operates as follows:
</p>
<ul>
<li>The robot is set on any of <i>N</i> × <i>N</i> rooms, with directing any of north, east, west and south.</li>
<li>The robot detects color of carpets of lefthand, righthand, and forehand adjacent rooms if exists. If there is exactly one room that its carpet has the same color as carpet of room where it is, the robot changes direction to and moves to and then cleans the room. Otherwise, it halts. Note that halted robot doesn't clean any longer. Following is some examples of robot's movement.
<br>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cleaningRobot2">
<p>Figure 1. An example of the room</p>
</center>
<br>
In Figure 1,
<ul>
<li>robot that is on room (1,1) and directing north directs east and goes to (1,2).</li>
<li>robot that is on room (0,2) and directing north directs west and goes to (0,1).</li>
<li>robot that is on room (0,0) and directing west halts.</li>
</ul>
</li>
<li>Since the robot powered by contactless battery chargers that are installed in every rooms, unlike the previous robot, it never stops because of running down of its battery. It keeps working until it halts.</li>
</ul>
<p>
Doctor's house has become larger by the renovation. Therefore, it is not efficient to let only one robot clean. Fortunately, he still has enough budget. So he decided to make a number of same robots and let them clean simultaneously.
</p>
<p>
The robots interacts as follows:
</p>
<ul>
<li> No two robots can be set on same room.</li>
<li> It is still possible for a robot to detect a color of carpet of a room even if the room is occupied by another robot.</li>
<li> All robots go ahead simultaneously.</li>
<li> When robots collide (namely, two or more robots are in a single room, or two robots exchange their position after movement), they all halt. Working robots can take such halted robot away.</li>
</ul>
<p>
On every room dust stacks slowly but constantly. To keep his house pure, he wants his robots to work so that dust that stacked on any room at any time will eventually be cleaned.
</p>
<p>
After thinking deeply, he realized that there exists a carpet layout such that no matter how initial placements of robots are, this condition never can be satisfied. Your task is to output carpet layout that there exists at least one initial placements of robots that meets above condition. Since there may be two or more such layouts, please output the <i>K</i>-th one lexicographically.
</p>
<H2>Input</H2>
<p>
Input file contains several data sets.
One data set is given in following format:
</p>
<pre>
<i>N K</i>
</pre>
<p>
Here, <i>N</i> and <i>K</i> are integers that are explained in the problem description.
</p>
<p>
The end of input is described by a case where <i>N</i> = <i>K</i> = 0. You should output nothing for this case.
</p>
<H2>Output</H2>
<p>
Print the <i>K</i>-th carpet layout if exists, "<span>No</span>" (without quotes) otherwise.
</p>
<p>
The carpet layout is denoted by <i>N</i> lines of string that each has exactly <i>N</i> letters. A room with black carpet and a room with white carpet is denoted by a letter '<span>E</span>' and '<span>.</span>' respectively. Lexicographically order of carpet layout is defined as that of a string that is obtained by concatenating the first row, the second row, ..., and the <i>N</i>-th row in this order.
</p>
<p>
Output a blank line after each data set.
</p>
<p>
</p>
<H2>Constraints</H2>
<ul>
<li>Judge data consists of at most 100 data sets.</li>
<li>1 ≤ <i>N</i> < 64</li>
<li>1 ≤ <i>K</i> < 2<sup>63</sup></li>
</ul>
<H2>Sample Input</H2>
<pre>
2 1
2 3
6 4
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
..
..
No
..EEEE
..E..E
EEE..E
E..EEE
E..E..
EEEE..
</pre>
|
p00240 |
<H1>éå©èšç®</H1>
<p>
éå©ã¯éè¡ã«é ããŠãããéã«ä»ãããã®èšç®æ¹æ³ãå©çã¯éè¡ã«ãã£ãŠæ§ã
ã§ãã婿¯ãšå
éãåããããã®ãå
å©ãšåŒã³ãŸãããå
å©ã®èšç®æ¹æ³ãšããŠã婿¯ãå
éã«çµã¿å
¥ããã«èšç®ãããåå©ããšå©æ¯ãå
éã«çµã¿å
¥ããŠèšç®ãããè€å©ããšãããã®ããããããå€ãã®å
å©ãåŸãããã«ã¯ãã®å·®ç°ãçè§£ããŠããªããã°ãªããŸãããå
å©ã®èšç®æ¹æ³ã¯ä»¥äžã®ããã«ãªããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0240_1"><br>
<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0240_2">
</center>
<br>
<!--
<p>
ã§ããã°ãããããªéå©ã§ãããå€ããéãå¢ãããããšæããã®ã§ããçžæ²¢ããã®å®¶åºã§ã¯ãä»ãŸã§é ããŠããéè¡ã¯éå©ãäœãäºã«æ°ã¥ããæ°ããéè¡ã«ä¹ãæããããšããŠããŸããããããçžæ²¢ããäžå®¶ã¯éå©ã®ããšã«ã€ããŠããŸã詳ããç¥ããªãã£ãã®ã§ãéå©ã«è©³ããããªãã«å©ããæ±ããŠããŸãããæ¯èŒãã¹ãéè¡ã®æ°ã¯å€ããããçžæ²¢ããäžå®¶ä»¥å€ã«ãå©ããæ±ãããããã§ããäœæ¥ãå¹çåããããã«ããè¯ãéè¡ãèšç®ããããã°ã©ã ãäœæããŠãããŸãããã
</p>
-->
<p>
éè¡ã®æ°ããéãé ãã幎æ°ãåéè¡ã®æ
å ±ïŒéè¡çªå·ãéå©ã®çš®é¡ã幎å©çïŒããŒã»ã³ãïŒïŒãå
¥åãšããæãå
å©ãé«ããªãéè¡çªå·ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããæãå
å©ãé«ããªãéè¡ã¯äžã€ã ãã§ãã
</p>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>y</var>
<var>b<sub>1</sub></var> <var>r<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>b<sub>2</sub></var> <var>r<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>b<sub>n</sub></var> <var>r<sub>n</sub></var> <var>t<sub>n</sub></var>
</pre>
<p>
1è¡ç®ã«éè¡ã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 50)ã2è¡ç®ã«ãéãé ããå¹Žæ° <var>y</var> (1 ≤ <var>y</var> ≤ 30)ãäžããããŸããç¶ã<var>n</var> è¡ã« <var>i</var> çªç®ã®éè¡ã®éè¡çªå· <var>b<sub>i</sub></var>ã幎å©çãè¡šãæŽæ° <var>r<sub>i</sub></var> (1 ≤ <var>r<sub>i</sub></var> ≤ 100)ã éå©ã®çš®é¡ <var>t<sub>i</sub></var> (1 ãŸã㯠2) ãäžããããŸããéå©ã®çš®é¡ <var>t<sub>i</sub></var> ã¯ãåå©ã®å Žåã¯1ãè€å©ã®å Žåã¯2ã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãæãå
å©ãé«ããªãéè¡çªå·ãïŒè¡ã«åºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
2
8
1 5 2
2 6 1
2
9
1 5 2
2 6 1
0
</pre>
<h2>åºåäŸ</h2>
<pre>
2
1
</pre> |
p03895 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi recorded his daily life for the last few days as a integer sequence of length <var>2N</var>, as follows:</p>
<ul>
<li><var>a_1, b_1, a_2, b_2, ... , a_N, b_N</var></li>
</ul>
<p>This means that, starting from a certain time <var>T</var>, he was:</p>
<ul>
<li>sleeping for exactly <var>a_1</var> seconds</li>
<li>then awake for exactly <var>b_1</var> seconds</li>
<li>then sleeping for exactly <var>a_2</var> seconds</li>
<li>:</li>
<li>then sleeping for exactly <var>a_N</var> seconds</li>
<li>then awake for exactly <var>b_N</var> seconds</li>
</ul>
<p>In this record, he waked up <var>N</var> times.</p>
<p>Takahashi is wondering how many times he waked up early during the recorded period.</p>
<p>Here, he is said to <em>wake up early</em> if he wakes up between <var>4:00</var> AM and <var>7:00</var> AM, inclusive.</p>
<p>If he wakes up more than once during this period, each of these awakenings is counted as waking up early.</p>
<p>Unfortunately, he forgot the time <var>T</var>.</p>
<p>Find the maximum possible number of times he waked up early during the recorded period.</p>
<p>For your information, a day consists of <var>86400</var> seconds, and the length of the period between <var>4:00</var> AM and <var>7:00</var> AM is <var>10800</var> seconds.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq a_i, b_i \leq 10^5</var></li>
<li><var>a_i</var> and <var>b_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
:
<var>a_N</var> <var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of times he waked up early during the recorded period.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
28800 57600
28800 57600
57600 28800
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
28800 57600
4800 9600
6000 1200
600 600
300 600
5400 600
6000 5760
6760 2880
6000 12000
9000 600
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre></section>
</div>
</span> |
p02787 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ibis is fighting with a monster.</p>
<p>The <em>health</em> of the monster is <var>H</var>.</p>
<p>Ibis can cast <var>N</var> kinds of spells. Casting the <var>i</var>-th spell decreases the monster's health by <var>A_i</var>, at the cost of <var>B_i</var> Magic Points.</p>
<p>The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.</p>
<p>Ibis wins when the health of the monster becomes <var>0</var> or below.</p>
<p>Find the minimum total Magic Points that have to be consumed before winning.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H \leq 10^4</var></li>
<li><var>1 \leq N \leq 10^3</var></li>
<li><var>1 \leq A_i \leq 10^4</var></li>
<li><var>1 \leq B_i \leq 10^4</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>N</var>
<var>A_1</var> <var>B_1</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total Magic Points that have to be consumed before winning.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9 3
8 3
4 2
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>First, let us cast the first spell to decrease the monster's health by <var>8</var>, at the cost of <var>3</var> Magic Points. The monster's health is now <var>1</var>.</p>
<p>Then, cast the third spell to decrease the monster's health by <var>2</var>, at the cost of <var>1</var> Magic Point. The monster's health is now <var>-1</var>.</p>
<p>In this way, we can win at the total cost of <var>4</var> Magic Points.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 6
1 1
2 3
3 9
4 27
5 81
6 243
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
<p>It is optimal to cast the first spell <var>100</var> times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>139815
</pre></section>
</div>
</span> |
p02292 |
<H1>Counter-Clockwise</H1>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_CGL_CGL_1_C">
</center>
<p>
For given three points <var>p0, p1, p2</var>, print
</p>
<pre>
COUNTER_CLOCKWISE
</pre>
<p>
if <var>p0, p1, p2</var> make a counterclockwise turn (1),
</p>
<pre>
CLOCKWISE
</pre>
<p>
if <var>p0, p1, p2</var> make a clockwise turn (2),
</p>
<pre>
ONLINE_BACK
</pre>
<p>
if <var>p2</var> is on a line <var>p2, p0, p1</var> in this order (3),
</p>
<pre>
ONLINE_FRONT
</pre>
<p>
if <var>p2</var> is on a line <var>p0, p1, p2</var> in this order (4),
</p>
<pre>
ON_SEGMENT
</pre>
<p>
if <var>p2</var> is on a segment <var>p0p1</var> (5).
</p>
<H2>Input</H2>
<pre>
<var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var>
<var>q</var>
<var>x<sub>p2<sub>0</sub></sub></var> <var>y<sub>p2<sub>0</sub></sub></var>
<var>x<sub>p2<sub>1</sub></sub></var> <var>y<sub>p2<sub>1</sub></sub></var>
...
<var>x<sub>p2<sub>q-1</sub></sub></var> <var>y<sub>p2<sub>q-1</sub></sub></var>
</pre>
<p>
In the first line, integer coordinates of <var>p0</var> and <var>p1</var> are given. Then, <var>q</var> queries are given for integer coordinates of <var>p2</var>.
</p>
<H2>Output</H2>
<p>
For each query, print the above mentioned status.
</p>
<H2>Constraints</H2>
<ul>
<li>
<var>1 ≤ q ≤ 1000</var>
</li>
<li>
<var>-10000 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 10000</var>
</li>
<li>
<var>p0</var> and <var>p1</var> are not identical.
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
0 0 2 0
2
-1 1
-1 -1
</pre>
<H2>Sample Output 1</H2>
<pre>
COUNTER_CLOCKWISE
CLOCKWISE
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
0 0 2 0
3
-1 0
0 0
3 0
</pre>
<H2>Sample Output 2</H2>
<pre>
ONLINE_BACK
ON_SEGMENT
ONLINE_FRONT
</pre>
<br/>
|
p01847 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h3>ã«ãŒãã³</h3>
<p>ããããå€ããã£ãŠããïŒããªãã¯å€ã«åããŠéšå±ã®æš¡æ§æ¿ããããããšã«ããïŒä»å¹Žã®å€ã¯ãšãŠãæ¥å·®ãã匷ãããšãäºæ³ãããŠããïŒãŸã¶ããã®ãèŠæãªããªãã«ã¯èŸãå£ç¯ã«ãªãããã ïŒããã§ïŒããªãã¯éšå±ã®æããã調ç¯ããããã«ïŒéšå±ã®çªã«ã«ãŒãã³ãåãä»ããããšèããïŒ
</p>
<p>åãä»ããã«ãŒãã³ã¯é·æ¹åœ¢ã§ããïŒèŸºãå°é¢ã«å¯ŸããŠåçŽïŒãããã¯å¹³è¡ã§ããããã«åãä»ããïŒãŸãïŒããªãã®éšå±ã®çªã¯éåžžã«ç¹æ®ãªåœ¢ãããŠããïŒå蟺ãå°é¢ã«å¹³è¡ãŸãã¯åçŽã§ãããã㪠<i>N</i> è§åœ¢ã§è¡šãããïŒãã®ããïŒã«ãŒãã³ãåãä»ãããšãã«ã«ãŒãã³ã«èŠãããŠããªãçªã®é¢ç©ãã©ã®ãããã«ãªãã®ããæ±ããã®ã¯é£ããïŒéšå±ã®æããã調ç¯ããããã«ãïŒã«ãŒãã³ãåãä»ããäœçœ®ã決ããæã«ã©ã®ãããçªãèŠããããç¥ãããšã¯éèŠã§ããïŒããã§ïŒããªãã¯çªãšã«ãŒãã³ã®èšçœ®äœçœ®ãšåœ¢ç¶ãäžãããããšãã«ïŒã«ãŒãã³ã«èŠãããŠããªãçªã®é¢ç©ãæ±ããããã°ã©ã ãäœãããšã«ããïŒ
</p>
<p>äŸãšããŠæ¬¡ã®ãããªçªãšã«ãŒãã³ã®èšçœ®ã®ä»æ¹ãèããïŒãã®å Žåã¯ã«ãŒãã³ã«é ããŠããªãçªã®é¢ç©ã¯ 8 ãšãªãïŒãã®äŸã¯ãµã³ãã«å
¥åã® 3 ã±ãŒã¹ç®ã«å¯Ÿå¿ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_window" witdh="400" height="400"><br/>
</center>
<h3>Input</h3>
<p>å
¥åã¯è€æ°ããŒã¿ã»ãããããªãïŒ
åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ
</p>
<blockquote><i>N</i><br><i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br>:<br>:<br><i>x<sub>N</sub></i> <i>y<sub>N</sub></i><br><i>a<sub>1</sub></i> <i>b<sub>1</sub></i><br><i>a<sub>2</sub></i> <i>b<sub>2</sub></i><br><i>a<sub>3</sub></i> <i>b<sub>3</sub></i><br><i>a<sub>4</sub></i> <i>b<sub>4</sub></i></blockquote>
<p>æåã®è¡ã«ã¯çªã®æã€é ç¹æ°ãè¡šãæŽæ° <i>N</i> ãäžãããã (<i>4 ≤ N ≤ 100</i>)ïŒç¶ã <i>N</i> è¡ã«ã¯çªã®çžç°ãªãé ç¹ã®x座æšãè¡šãæŽæ° <i>x<sub>i</sub></i> ãšy座æšãè¡šãæŽæ° <i>y<sub>i</sub></i> ãäžãããã (<i>-20,000 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 20,000, 1 ≤ i ≤ N</i>)ïŒããã§ïŒyè»žã®æ£ã®åãã¯xè»žã®æ£ã®åããã90床ååæèšåãã«å転ãããæ¹åãšããïŒããã«ïŒç¶ã 4 è¡ã«ã¯ã«ãŒãã³ã®çžç°ãªãé ç¹ã®x座æšãè¡šãæŽæ° <i>a<sub>j</sub></i> ãš y座æšãè¡šãæŽæ° <i>b<sub>j</sub></i> ãäžãããã (<i>-20,000 ≤ a<sub>j</sub>, b<sub>j</sub> ≤ 20,000, 1 ≤ j ≤ 4</i>)ïŒçªïŒã«ãŒãã³ãšãã«ïŒããããã®é ç¹ã¯åæèšåãé ã«äžããããïŒãŸãïŒçªïŒã«ãŒãã³ã衚ãå³åœ¢ã¯ããããèªå·±äº€å·®ããªãå³åœ¢ã§ããïŒ
</p>
<p>å
¥åã®çµããã¯1ã€ã® 0 ãããªãè¡ã§ç€ºãïŒ
</p>
<h3>Output</h3>
<p>åããŒã¿ã»ããã«ã€ããŠïŒã«ãŒãã³ã«èŠãããŠããªãçªã®é¢ç©ã 1 è¡ã«åºåããïŒãã ãïŒé¢ç©ã¯å¿
ãæŽæ°å€ã«ãªãããšã«æ³šæããïŒ
</p>
<h3>Sample Input</h3>
<pre>4
0 0
10 0
10 10
0 10
0 0
5 0
5 10
0 10
6
0 0
10 0
10 5
5 5
5 10
0 10
2 0
8 0
8 10
2 10
12
1 1
1 3
-1 3
-1 1
-3 1
-3 -1
-1 -1
-1 -3
1 -3
1 -1
3 -1
3 1
2 2
-2 2
-2 -2
2 -2
4
20000 20000
-20000 20000
-20000 -20000
20000 -20000
1000 1000
-1000 1000
-1000 -1000
1000 -1000
4
1000 1000
-1000 1000
-1000 -1000
1000 -1000
20000 20000
-20000 20000
-20000 -20000
20000 -20000
4
0 0
10 0
10 10
0 10
20 0
30 0
30 10
20 10
0</pre>
<h3>Output for Sample Input</h3>
<pre>50
30
8
1596000000
0
100</pre>
|
p00755 |
<h3><U>Identically Colored Panels Connection</U></h3>
<!-- end en only -->
<div>
<!-- please enclose each h3 level section with div -->
<!-- begin en only -->
<p>
Dr. Fukuoka has invented fancy panels.
Each panel has a square shape of a unit size and
has one of the six colors, namely, yellow, pink, red, purple, green and blue.
The panel has two remarkable properties.
One property is that, when two or more panels with the same color
are placed adjacently, their touching edges melt a little
and they are fused each other.
The fused panels are united into a polygonally shaped panel.
The other property is that the color of a panel can be changed
to one of six colors by giving an electrical shock.
The resulting color can be controlled by its waveform.
The electrical shock to an already united panel changes
the color of the whole to a specified single color.
</p>
<p>
Since he wants to investigate the strength with respect to the
color and the size of a united panel compared to unit panels,
he tries to unite panels into a polygonal panel with a specified color.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_1" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-1: panels and their initial colors<br><br>
</center>
<!-- end en only -->
<!-- begin en only -->
<p>
Since many panels are simultaneously synthesized and generated on a base plate
through some complex chemical processes,
the fabricated panels are randomly colored and
they are arranged in a rectangular shape on the base plate (Figure C-1).
Note that the two purple (color 4) panels in Figure C-1 are
already united at the initial state since they are
adjacent to each other.
</p>
<p>
Installing electrodes to a panel, and
changing its color several times by giving electrical shocks
according to an appropriate sequence for a specified target color,
he can make a united panel merge the adjacent panels
to unite them step by step
and can obtain a larger panel with the target color.
Unfortunately, panels will be broken when
they are struck by the sixth electrical shock.
That is, he can change the color of a panel or a united panel only
five times.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Let us consider a case
where the panel at the upper left corner of the panel configuration
(Figure C-1) is attached with the electrodes.
First, changing the color of the panel from yellow to blue,
the two adjacent panels are fused into a united panel (Figure C-2).
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_2" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-2:
Change of the color of the panel at the upper left corner,
from yellow (color 1) to blue (color 6).<br><br>
</center>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
Second, changing the color of the upper left united panel from blue
to red, a united red panel that consists of three unit panels is newly formed
(Figure C-3).
Then, changing the color of the united panel from red to purple,
panels are united again to form a united panel of five unit panels
(Figure C-4).
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_3" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-3:
Change of the color of the panel at the upper left corner,
from blue (color 6) to red (color 3).
<br><br>
</center>
<!-- end en only -->
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_4" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-4:
Change of the color of the panel at the upper left corner,
from red (color 3) to purple (color 4).
<br><br>
</center>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
Furthermore, through making a pink united panel in Figure C-5 by
changing the color from purple to pink,
then, the green united panel in Figure C-6 is obtained
by changing the color from pink to green.
The green united panel consists of ten unit panels.
</p>
<!-- end en only -->
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_5" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-5:
Change of the color of the panel at the upper left corner,
from purple (color 4) to pink (color 2).<br><br>
</center>
<!-- end en only -->
</p>
<p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1174_6" align="center" width="200" height="120"><br>
</center>
<!-- begin en only -->
<center>
Figure C-6:
Change of the color of the panel at the upper left corner,
from pink (color 2) to green (color 5).<br><br>
</center>
<!-- end en only -->
</p>
<!-- begin en only -->
<p>
In order to check the strength of united panels with
various sizes and colors, he needs to unite as many panels
as possible with the target color.
Your job is to write a program that finds a sequence to change
the colors five times
in order to get the largest united panel with the target color.
Note that the electrodes are fixed to the panel at the upper left corner.
</p>
<!-- end en only -->
</div>
<h3>Input</h3>
<div>
<!-- begin en only -->
<p>
The input consists of multiple datasets, each being in the following format.
</p>
<!-- end en only -->
<blockquote>
<i>h</i> <i>w</i> <i>c</i><br>
<i>p</i><sub>1,1</sub> <i>p</i><sub>1,2</sub> ... <i>p</i><sub>1,<i>w</i></sub><br>
<i>p</i><sub>2,1</sub> <i>p</i><sub>2,2</sub> ... <i>p</i><sub>2,<i>w</i></sub><br>
...<br>
<i>p</i><sub><i>h</i>,1</sub> <i>p</i><sub><i>h</i>,2</sub> ... <i>p</i><sub><i>h</i>,<i>w</i></sub><br>
</blockquote>
<!-- begin en only -->
<i>h</i> and <i>w</i> are positive integers no more than 8 that
represent the height and the width of the given rectangle.
<i>c</i> is a positive integer no more than 6 that represents
the target color of the finally united panel.
<i>p</i><sub><i>i</i>,<i>j</i></sub> is a positive integer no more than 6
that represents the initial color of the panel at the position
(<i>i</i>, <i>j</i>).
<p>The end of the input is indicated by a line that consists of
three zeros separated by single spaces.
</p>
<!-- end en only -->
</div>
<h3>Output</h3>
<div>
<!-- begin en only -->
<p>
For each dataset, output the largest possible number of unit panels
in the united panel at the upper left corner with the target color
after five times of color changes of the panel
at the upper left corner.
No extra characters should occur in the output.
</p>
<!-- end en only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3 5 5
1 6 3 2 5
2 5 4 6 1
1 2 4 1 5
4 5 6
1 5 6 1 2
1 4 6 3 2
1 5 2 3 2
1 1 2 3 2
1 1 5
1
1 8 6
1 2 3 4 5 1 2 3
8 1 1
1
2
3
4
5
1
2
3
8 8 6
5 2 5 2 6 5 4 2
4 2 2 2 5 2 2 2
4 4 4 2 5 2 2 2
6 4 5 2 2 2 6 6
6 6 5 5 2 2 6 6
6 2 5 4 2 2 6 6
2 4 4 4 6 2 2 6
2 2 2 5 5 2 2 2
8 8 2
3 3 5 4 1 6 2 3
2 3 6 4 3 6 2 2
4 1 6 6 6 4 4 4
2 5 3 6 3 6 3 5
3 1 3 4 1 5 6 3
1 6 6 3 5 1 5 3
2 4 2 2 2 6 5 3
4 1 3 6 1 5 5 4
0 0 0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
10
18
1
5
6
64
33
</pre>
</div> |
p02768 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Akari has <var>n</var> kinds of flowers, one of each kind.</p>
<p>She is going to choose one or more of these flowers to make a bouquet.</p>
<p>However, she hates two numbers <var>a</var> and <var>b</var>, so the number of flowers in the bouquet cannot be <var>a</var> or <var>b</var>.</p>
<p>How many different bouquets are there that Akari can make?</p>
<p>Find the count modulo <var>(10^9 + 7)</var>.</p>
<p>Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 \leq n \leq 10^9</var></li>
<li><var>1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var> <var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of bouquets that Akari can make, modulo <var>(10^9 + 7)</var>. (If there are no such bouquets, print <code>0</code>.)</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>In this case, Akari can choose <var>2</var> or <var>4</var> flowers to make the bouquet.</p>
<p>There are <var>6</var> ways to choose <var>2</var> out of the <var>4</var> flowers, and <var>1</var> way to choose <var>4</var>, so there are a total of <var>7</var> different bouquets that Akari can make.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1000000000 141421 173205
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>34076506
</pre>
<p>Print the count modulo <var>(10^9 + 7)</var>.</p></section>
</div>
</span> |
p00305 |
<h1>æ </h1>
<p>
ç»åã®äžããæçãªæ
å ±ãæœåºããç»åèªèã¯ã³ã³ãã¥ãŒã¿ãµã€ãšã³ã¹ã®äžã§ãéèŠãªç ç©¶ããŒãã®ã²ãšã€ã§ããããžã¿ã«ã«ã¡ã©ãéè»¢æ¯æŽã·ã¹ãã ãé²ç¯ã·ã¹ãã ãªã©ã«å¹
åºãå¿çšãããŠããŸãã
</p>
<p>
ãã®ãããªç ç©¶ã®ãããã§ãç§ãã¡ã¯ç»åè§£æãè¡ãããã®å€ãã®ãœãããŠã§ã¢ãããã°ã©ã éãäœ¿ãæ§ã
ãªåŠçãè¡ãããšãã§ããŸããäžæ¹ãèªåã§ããã°ã©ã ãæžããŠè§£æããããšã§ããã®ä»çµã¿ãç¥ããæ¥œããæéãéããããšãã§ããŸããããã§ã¯ãäžé¢šå€ãã£ãç»åèªèãããŠã¿ãŸãããã
</p>
<p>
ç»åãšããŠæ¬¡ã®ãããªåãã¯ã»ã«ãæŽæ°ã®å€ãæã€ <var>N</var> × <var>N</var> ã®ãã¯ã»ã«ãå
¥åãšããŠäžããããŸãããã®ç»åã®äžãããç·ã®å€ªããïŒãã¯ã»ã«ã®é·æ¹åœ¢ã®æ ïŒããïŒãïŒã€æœåºããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame1" width="380">
</center>
<br>
<p>
æ ãèŠããã¯ã»ã«ã®å€ã®åãæå€§ãšãªããããªæ ãæœåºããŠããã®åãå ±åããããã°ã©ã ãäœæããŠ
äžããããã ããäžã®å³ã®ããã«ãçžŠãæšªã®ãã¯ã»ã«æ°ãïŒã€ãïŒã€ã®å Žåãæ ãšã¿ãªããã®ãšããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_frame2" width="560">
</center>
<br>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>p<sub>1,1</sub></var> <var>p<sub>1,2</sub></var> ... <var>p<sub>1,N</sub></var>
<var>p<sub>2,1</sub></var> <var>p<sub>2,2</sub></var> ... <var>p<sub>2,N</sub></var>
:
<var>p<sub>N,1</sub></var> <var>p<sub>N,2</sub></var> ... <var>p<sub>N,N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«çžŠãšæšªã®ãã¯ã»ã«æ° <var>N</var> (1 ≤ <var>N</var> ≤ 300) ãäžãããããç¶ã <var>N</var> è¡ã«ã<var>i</var> è¡ <var>j</var> åç®ã®ãã¯ã»ã«ã®å€ãè¡šãæŽæ° <var>p<sub>i,j</sub></var> (-1000 ≤ <var>p<sub>i,j</sub></var> ≤ 1000)ãäžããããã
</p>
<h2>åºå</h2>
<p>
ãã¯ã»ã«å€ã®åãæå€§ãšãªããããªæ ã®ããã¯ã»ã«å€ã®åãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
5
2 0 0 2 0
0 1 0 2 0
0 0 0 -1 0
0 4 0 3 0
-1 0 0 1 0
</pre>
<h2> åºåäŸïŒ </h2>
<pre>
12
</pre>
<h2>å
¥åäŸïŒ</h2>
<pre>
3
0 0 0
0 -1 0
0 0 0
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
0
</pre>
|
p02338 | <!--<h1>åå12çž ãã®8:ããŒã«ã«åºå¥ããã»ç®±ã«åºå¥ãªãã»ç®±ã®äžèº«ã¯1ã€ä»¥äž</h1>-->
<h1>Balls and Boxes 8</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td style="background-color:#aff">8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is distinguished from the other.</li>
<li>Each box is <b>not</b> distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box can contain at most one ball.</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
5 10
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
200 100
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
|
p03483 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters.
Determine whether we can turn <var>S</var> into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 2 Ã 10^5</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If we cannot turn <var>S</var> into a palindrome, print <code>-1</code>. Otherwise, print the minimum required number of operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>eel
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>We can turn <var>S</var> into a palindrome by the following operation:</p>
<ul>
<li>Swap the <var>2</var>-nd and <var>3</var>-rd characters. <var>S</var> is now <code>ele</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ataatmma
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>We can turn <var>S</var> into a palindrome by the following operation:</p>
<ul>
<li>Swap the <var>5</var>-th and <var>6</var>-th characters. <var>S</var> is now <code>ataamtma</code>.</li>
<li>Swap the <var>4</var>-th and <var>5</var>-th characters. <var>S</var> is now <code>atamatma</code>.</li>
<li>Swap the <var>3</var>-rd and <var>4</var>-th characters. <var>S</var> is now <code>atmaatma</code>.</li>
<li>Swap the <var>2</var>-nd and <var>3</var>-rd characters. <var>S</var> is now <code>amtaatma</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>snuke
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>We cannot turn <var>S</var> into a palindrome.</p></section>
</div>
</span> |
p03179 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>N</var> be a positive integer.
You are given a string <var>s</var> of length <var>N - 1</var>, consisting of <code><</code> and <code>></code>.</p>
<p>Find the number of permutations <var>(p_1, p_2, \ldots, p_N)</var> of <var>(1, 2, \ldots, N)</var> that satisfy the following condition, modulo <var>10^9 + 7</var>:</p>
<ul>
<li>For each <var>i</var> (<var>1 \leq i \leq N - 1</var>), <var>p_i < p_{i + 1}</var> if the <var>i</var>-th character in <var>s</var> is <code><</code>, and <var>p_i > p_{i + 1}</var> if the <var>i</var>-th character in <var>s</var> is <code>></code>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an integer.</li>
<li><var>2 \leq N \leq 3000</var></li>
<li><var>s</var> is a string of length <var>N - 1</var>.</li>
<li><var>s</var> consists of <code><</code> and <code>></code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of permutations that satisfy the condition, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
<><
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are five permutations that satisfy the condition, as follows:</p>
<ul>
<li><var>(1, 3, 2, 4)</var></li>
<li><var>(1, 4, 2, 3)</var></li>
<li><var>(2, 3, 1, 4)</var></li>
<li><var>(2, 4, 1, 3)</var></li>
<li><var>(3, 4, 1, 2)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
<<<<
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There is one permutation that satisfies the condition, as follows:</p>
<ul>
<li><var>(1, 2, 3, 4, 5)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>20
>>>><>>><>><>>><<>>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>217136290
</pre>
<p>Be sure to print the number modulo <var>10^9 + 7</var>.</p></section>
</div>
</span> |
p01144 |
<!-- begin en only -->
<h3><U> Princess' Marriage </U></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><U> ãå§«æ§ã®å«å
¥ã </U></h3>
<!-- end ja only -->
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ããè²§ä¹ãªåœã®ããŠãã°ã§åæ¢ãªãå§«æ§ã¯ïŒã®ã£ã³ãã«ã®é
åœãããªãã¥ãã¥ãšã«æ¹åŒã§æ±ºå®ãããäºãç¥ãããšã«ããïŒã®ã£ã³ãã«ã«ã€ããŠè©³ãããªã£ãæ°ãããŠã®ã£ã³ãã«ã§ã®åå©ã確信ããïŒãã®çµæïŒä»ãŸã§ãããæŽã«å€é¡ã®ãéãã€ã蟌ã¿ïŒåœæ°ãçŽããçšéããã¹ãŠå€±ãã»ã©ã®è² ããå«ããŠããŸã£ãïŒãã®äºæ
ãéãåãæ¢ããçæ§ã¯ïŒãå§«æ§ãé£ã®åœãžå«ãããããšã«ããïŒããããããšã«ããïŒãå§«æ§ãæ¥é ã®è¡ããåçããïŒåæã«é£åœãšã®äº€åãæ·±ããŠè²¡æ¿æŽå©ãããŠãããããšèããããã§ããïŒ
</p>
<p>
ãå§«æ§ãšé£åœã®çåæ§ã¯ãäºãã®äºãæ°ã«å
¥ãïŒãŸãäž¡åœã®çæ§éã§ãæ¿ç¥çµå©ã«é¢ããåæããªãããïŒãå§«æ§ã¯ãªããªãã®ãéãæã«ææ°æã
ãšé£ã®åœãžåºãããïŒäžæ¹ã§ïŒãå§«æ§ãå«ãåæ©ã¯çæ§ã®äžæ¹çãªå©ç远åã®ããã§ããïŒå¿«ããªããšèããé£åœã®çåæ§ã®åŽè¿ã¯ïŒãå§«æ§ã亡ãè
ã«ããããã«éã®éäžã«ç¡æ°ã®åºå®¢éãæŸã£ãïŒ
</p>
<p>
ãå§«æ§ãéãéã¯ãã§ã«æ±ºããããŠããïŒãå§«æ§ã®éãéã«ã¯åèš <i>L</i> åã®å®¿å ŽãããïŒäŸ¿å®äžïŒåºçºå°ç¹ããã³å°çå°ç¹ãå®¿å ŽãšãïŒåå®¿å Žã <i>S<sub>1</sub></i>, <i>S<sub>2</sub></i>, ... <i>S<sub>L</sub></i> ãšåŒã¶ããšã«ããïŒãå§«æ§ã¯æåã« <i>S<sub>1</sub></i> ã«ããïŒæé ã« (<i>S<sub>2</sub></i>, <i>S<sub>3</sub></i> ... ãšããé çªã§) å®¿å Žã蚪ããŠïŒæçµçã« <i>S<sub>L</sub></i> ãžè¡ããã®ãšããïŒå®¿å Žã§ã¯ééãæã£ãŠè·è¡ãéãããšãã§ãïŒãéãããéã奜ããªè·é¢ã ãå¥çŽããŠãå§«æ§ãå®ãããããšãã§ããïŒè·è¡ãéãè²»çšã¯ïŒè·é¢1ã«ã€ãé1ã§ããïŒãå§«æ§ã¯éãåºéå
ãéšåçã«å®ã£ãŠãããããšãåºæ¥ãããšã«æ³šæããïŒ<i>S<sub>i</sub></i>ãš<i>S<sub>i+1</sub></i>éã®è·é¢ã¯<i>D<sub>i</sub></i>ïŒ<i>S<sub>i</sub></i>ãš<i>S<sub>i+1</sub></i>éã§è·é¢1ã«ã€ãåºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ã¯<i>P<sub>i</sub></i>ã§äžããããŠããïŒ
</p>
<p>
ãå§«æ§ãäºç®<i>M</i>ãæã£ãŠããŠïŒåºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ãæå°ã«ãªãããã«è·è¡ãéã£ããšãã®ïŒç®çå°ãŸã§ã«åºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ãæ±ããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒããšãïŒ
</p>
<blockquote>
<i>N</i> <i>M</i><br>
<i>D<sub>1</sub></i> <i>P<sub>1</sub></i><br>
<i>D<sub>2</sub></i> <i>P<sub>2</sub></i><br>
...<br>
<i>D<sub>N</sub></i> <i>P<sub>N</sub></i>
</blockquote>
åããŒã¿ã»ããã®æåã®è¡ã«ã¯äºã€ã®æŽæ°ãäžãããïŒããããåºéã®æ° <i>N</i>(1âŠ<i>N</i>âŠ10,000) ãšïŒãå§«å·®ãæã€äºç® <i>M</i>(0âŠ<i>M</i>âŠ1,000,000,000) ã衚ãïŒæ¬¡ã® <i>N</i> è¡ã¯ãå§«æ§ãéãéã®æ
å ±ã衚ãïŒåè¡ã¯äºã€ã®æŽæ°ãå«ãŸããŠããïŒ<i>i</i>è¡ç®ã¯åºéã®è·é¢ <i>D<sub>i</sub></i>(1âŠ<i>D<sub>i</sub></i>âŠ10,000) ãšãã®éãïŒåäœè·é¢ç§»åãããšãã«è¥²ãããåæ°ã®æåŸ
å€ <i>P<sub>i</sub></i>(0âŠ<i>P<sub>i</sub></i><=10) ãããªãïŒ
å
¥åã®çµç«¯ã¯ <i>N</i>=0, <i>M</i>=0 ãšãªãããŒã¿ã»ããã§ããããããïŒãã®ããŒã¿ã»ããã«å¯ŸããŠã¯èšç®çµæãåºåããŠã¯ãªããªãïŒ
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããæ¯ã«ïŒãå§«æ§ãç®çå°ãŸã§ã«åºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ãåºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
2 8
5 6
4 5
3 1
5 10
5 10
5 10
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
5
140
</pre>
|
p03529 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider the following game:</p>
<ul>
<li>The game is played using a row of <var>N</var> squares and many stones.</li>
<li>First, <var>a_i</var> stones are put in Square <var>i\ (1 \leq i \leq N)</var>.</li>
<li>A player can perform the following operation as many time as desired: "Select an integer <var>i</var> such that Square <var>i</var> contains exactly <var>i</var> stones. Remove all the stones from Square <var>i</var>, and add one stone to each of the <var>i-1</var> squares from Square <var>1</var> to Square <var>i-1</var>."</li>
<li>The final score of the player is the total number of the stones remaining in the squares.</li>
</ul>
<p>For a sequence <var>a</var> of length <var>N</var>, let <var>f(a)</var> be the minimum score that can be obtained when the game is played on <var>a</var>.</p>
<p>Find the sum of <var>f(a)</var> over all sequences <var>a</var> of length <var>N</var> where each element is between <var>0</var> and <var>K</var> (inclusive).
Since it can be extremely large, find the answer modulo <var>1000000007 (= 10^9+7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq K \leq N</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of <var>f(a)</var> modulo <var>1000000007 (= 10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>There are nine sequences of length <var>2</var> where each element is between <var>0</var> and <var>2</var>. For each of them, the value of <var>f(a)</var> and how to achieve it is as follows:</p>
<ul>
<li><var>f(\{0,0\})</var>: <var>0</var> (Nothing can be done)</li>
<li><var>f(\{0,1\})</var>: <var>1</var> (Nothing can be done)</li>
<li><var>f(\{0,2\})</var>: <var>0</var> (Select Square <var>2</var>, then Square <var>1</var>)</li>
<li><var>f(\{1,0\})</var>: <var>0</var> (Select Square <var>1</var>)</li>
<li><var>f(\{1,1\})</var>: <var>1</var> (Select Square <var>1</var>)</li>
<li><var>f(\{1,2\})</var>: <var>0</var> (Select Square <var>1</var>, Square <var>2</var>, then Square <var>1</var>)</li>
<li><var>f(\{2,0\})</var>: <var>2</var> (Nothing can be done)</li>
<li><var>f(\{2,1\})</var>: <var>3</var> (Nothing can be done)</li>
<li><var>f(\{2,2\})</var>: <var>3</var> (Select Square <var>2</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20 17
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>983853488
</pre></section>
</div>
</span> |
p01514 |
<!-- begin en only -->
<h3><u>You Are the Judge
</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>審å€ã¯åã ïŒ
</u></h3>
<!-- end ja only -->
<div>
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ããªãã¯ããã°ã©ãã³ã°ã³ã³ãã¹ã iCPC ã®å¯©å€ã ã仿¥ãäœäºããªã詊åãçµãããåŸã¯çµæãåºåããã ãã ãšæããããçªç¶ã·ã¹ãã ã忢ããŠããŸã£ãïŒã
</p>
<p>
ããã§ã¯çµæãåºåã§ããªãïŒãã§ãã倧äžå€«ãæã
ã«ã¯ãã°ãããã
</p>
<p>
ããªãã¯åªããããã°ã©ããŒã§ããããã€ãŠ iCPC ã§èŒãããæçžŸãæ®ããããšãããã
</p>
<p>
ããã§ããªãã¯ã·ã¹ãã ãã°ããåããŒã ã®æçžŸãå²ãåºããããŒã ã®é äœè¡šãåºåããããã°ã©ã ãäœæããããšã«ããã
</p>
<p>
å
¥åãšããŠããŒã ã®æ°ãåé¡ã®æ°ãã·ã¹ãã ãã°ãäžããããã
</p>
<p>
ã·ã ãã ãã°ã¯ä»¥äžã® 2 çš®é¡ã®ã¬ã³ãŒããããªãã
</p>
<table>
<thead><tr><th style="padding: .5em; background: #069; color: #fff">ã¬ã³ãŒã</th><th style="padding: .5em; background: #069; color: #fff">å
容</th><th style="padding: .5em; background: #069; color: #fff">广</th></tr></thead>
<tbody><tr><td style="padding: .5em; background: #0cf">tID pID time CORRECT</td><td style="padding: .5em; background: #0cf"> æå» time ã«ãããŒã tID ã åé¡ pID ã«æ£è§£ããããã°ã©ã ãéä¿¡ã </td><td style="padding: .5em; background: #0cf"> ããŒã tID ã®æ£è§£æ°ã«1ãå ç®ãããã<br>ããŒã tID ã®ããã«ãã£ã«ã(ããŒã tID ã®åé¡ pID ã«å¯Ÿããèª€çæ°*1200+time)ãå ç®ãããã<br> 以åŸ, ããŒã tID ã®åé¡ pID ã«å¯Ÿããè§£çã¯æ£åŽãããã·ã¹ãã ãã°ã«ãéä¿¡å±¥æŽãæ®ããªãã </td></tr></tbody>
<tbody><tr><td style="padding: .5em; background: #0cf">tID pID time WRONG</td><td style="padding: .5em; background: #0cf"> æå» time ã«ãããŒã tID ã åé¡ pID ã«èª€çããããã°ã©ã ãéä¿¡ã </td><td style="padding: .5em; background: #0cf"> ããŒã tID ã® åé¡ pID ã«å¯Ÿããèª€çæ°ã«1ãå ç®ãããã </td></tr></tbody>
</table>
<p>
â»äžèšã®ã·ã¹ãã ãã°ã¯ãã®åé¡ã®ããã«ç°¡ç¥åããããã®ã§ãããæ¬çªã®ICPCã§èŠãããã·ã¹ãã ãã°ãšç°ãªãããšã«çæãã
</p>
<p>
iCPCã«ãããé äœä»ãã®ã«ãŒã«ã¯ä»¥äžã®éãã§ããã
</p>
<ul>
<li>ããå€ãã®åé¡ãè§£ããããŒã ã¯é äœãäžã«ãªã</li>
<li>è§£ããåé¡ãåãå Žåãããã«ãã£ã®å°ãªãããŒã ã®ã»ããé äœãäžã«ãªã</li>
<li>è§£ããåé¡ãããã«ãã£ãåãå ŽåãããŒã çªå·ãå°ããã»ãã®ããŒã ãé äœãäžã«ãªã</li>
</ul>
<p>
å
¥åããäžããããã³ã³ãã¹ãã®æ
å ±ã»ã·ã¹ãã ãã°ããåããŒã ã®æçžŸãå²ãåºããããŒã ã®é äœè¡šãåºåããã
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<blockquote>
<var>T</var> <var>P</var> <var>R</var><br/>
<var>tID<sub>1</sub></var> <var>pID<sub>1</sub></var> <var>time<sub>1</sub></var> <var>message<sub>1</sub></var><br/>
<var>tID<sub>2</sub></var> <var>pID<sub>2</sub></var> <var>time<sub>2</sub></var> <var>message<sub>2</sub></var><br/>
<var>...</var><br/>
<var>tID<sub>R</sub></var> <var>pID<sub>R</sub></var> <var>time<sub>R</sub></var> <var>message<sub>R</sub></var><br/>
</blockquote>
<p>
ããŒã¿ã»ããã®1è¡ç®ã«ã¯ åå ããŒã æ° T ãå顿° Pãã·ã¹ãã ãã°ã®ã¬ã³ãŒãæ° R ãå«ãŸããã
</p>
<p>
ç¶ãRè¡ã«ã¯ã·ã¹ãã ãã°ã®åã¬ã³ãŒããå«ãŸããã
</p>
<p>
ã·ã¹ãã ãã°ã®ã¬ã³ãŒããšããŠãããŒã çªå· tID<sub>i</sub>ãåé¡çªå· pID<sub>i</sub>ã詊åéå§ããã®çµéæé time<sub>i</sub>ãã¡ãã»ãŒãžã®çš®é¡ message<sub>i</sub> ãå«ãŸããã
</p>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºããã
</p>
<ul>
<li>1 ≤ T ≤ 50</li>
<li>1 ≤ P ≤ 10</li>
<li>1 ≤ R ≤ 500</li>
<li>1 ≤ tID<sub>i</sub> ≤ T</li>
<li>1 ≤ pID<sub>i</sub> ≤ P</li>
<li>1 ≤ time<sub>i</sub> ≤ 10800</li>
<li>message<sub>i</sub> 㯠CORRECT, WRONGã®ãããã</li>
<li>ã·ã¹ãã ãã°ã®ã¬ã³ãŒãã¯ãæå»ã®å°ãããã®ããé ã«äžããããè€æ°ã®ã¬ã³ãŒãã®æå»ãåãã«ãªãããšã¯ãªã</li>
</ul>
<p>
å
¥åã®çµããã¯ã¹ããŒã¹ã§åºåããã3åã®0ã§äžããããã
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
äžããããã·ã¹ãã ãã°ããåããŒã ã®æçžŸã»é äœãå²ãåºããé äœãäžã®ããŒã ããé ã«ãããŒã çªå·ãæ£è§£æ°ãããã«ã㣠ãåºåããã
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3 3 5
3 1 800 WRONG
1 1 1200 CORRECT
3 1 1400 CORRECT
1 2 2400 CORRECT
1 3 3600 CORRECT
5 2 5
3 1 1000 WRONG
5 2 2000 CORRECT
3 1 2800 CORRECT
4 1 4000 CORRECT
5 1 5000 CORRECT
6 3 15
2 1 10 WRONG
3 3 15 WRONG
3 3 20 CORRECT
1 1 50 CORRECT
4 2 60 WRONG
1 2 70 WRONG
4 1 80 CORRECT
1 2 90 WRONG
1 2 150 CORRECT
3 1 160 WRONG
3 1 180 CORRECT
3 2 210 WRONG
5 3 500 CORRECT
4 2 720 CORRECT
5 1 1500 CORRECT
0 0 0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div>
<h3>Output for Sample Input</h3>
<div>
<pre>
1 3 7200
3 1 2600
2 0 0
5 2 7000
3 1 4000
4 1 4000
1 0 0
2 0 0
4 2 2000
5 2 2000
1 2 2600
3 2 2600
2 0 0
6 0 0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div> |
p03207 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In some other world, today is the day before Christmas Eve.</p>
<p>Mr. Takaha is buying <var>N</var> items at a department store. The regular price of the <var>i</var>-th item <var>(1 \leq i \leq N)</var> is <var>p_i</var> yen (the currency of Japan).</p>
<p>He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining <var>N-1</var> items cost their regular prices. What is the total amount he will pay?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10</var></li>
<li><var>100 \leq p_i \leq 10000</var></li>
<li><var>p_i</var> is an even number.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var>
<var>p_2</var>
<var>:</var>
<var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total amount Mr. Takaha will pay.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4980
7980
6980
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>15950
</pre>
<p>The <var>7980</var>-yen item gets the discount and the total is <var>4980 + 7980 / 2 + 6980 = 15950</var> yen.</p>
<p>Note that outputs such as <code>15950.0</code> will be judged as Wrong Answer.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
4320
4320
4320
4320
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>15120
</pre>
<p>Only one of the four items gets the discount and the total is <var>4320 / 2 + 4320 + 4320 + 4320 = 15120</var> yen.</p></section>
</div>
</span> |
p04038 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves colorful balls. He has a total of <var>NÃK</var> balls, <var>K</var> in each of his favorite <var>N</var> colors. The colors are numbered <var>1</var> through <var>N</var>.</p>
<p>He will arrange all of the balls in a row from left to right, in arbitrary order. Then, for each of the <var>N</var> colors, he will paint the leftmost ball of that color into color <var>0</var>, a color different from any of the <var>N</var> original colors.</p>
<p>After painting, how many sequences of the colors of the balls are possible? Find this number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€N,Kâ€2,000</var></li>
</ul>
</section>
</div>
<hr>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible sequences of the colors of the balls after painting, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The following <var>4</var> sequences are possible:</p>
<ul>
<li><var>(0,1,0,2)</var></li>
<li><var>(0,0,1,2)</var></li>
<li><var>(0,2,0,1)</var></li>
<li><var>(0,0,2,1)</var></li>
</ul>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>The following <var>1</var> sequence is possible:</p>
<ul>
<li><var>(0,0,0)</var></li>
</ul>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>14
</pre>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2000 2000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>546381702
</pre></section>
</div>
</hr></hr></hr></hr></hr></span> |
p03657 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is giving cookies to his three goats.</p>
<p>He has two cookie tins. One contains <var>A</var> cookies, and the other contains <var>B</var> cookies. He can thus give <var>A</var> cookies, <var>B</var> cookies or <var>A+B</var> cookies to his goats (he cannot open the tins).</p>
<p>Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A,B \leq 100</var></li>
<li>Both <var>A</var> and <var>B</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to give cookies so that each of the three goats can have the same number of cookies, print <code>Possible</code>; otherwise, print <code>Impossible</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Possible
</pre>
<p>If Snuke gives nine cookies, each of the three goats can have three cookies.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Impossible
</pre>
<p>Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.</p></section>
</div>
</span> |
p02945 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two integers: <var>A</var> and <var>B</var>.</p>
<p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>-100 \leq A,\ B \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the largest number among <var>A + B</var>, <var>A - B</var>, and <var>A \times B</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>-13 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-10
</pre>
<p>The largest number among <var>A + B = -10</var>, <var>A - B = -16</var>, and <var>A \times B = -39</var> is <var>-10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 -33
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>34
</pre>
<p>The largest number among <var>A + B = -32</var>, <var>A - B = 34</var>, and <var>A \times B = -33</var> is <var>34</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>13 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>39
</pre>
<p>The largest number among <var>A + B = 16</var>, <var>A - B = 10</var>, and <var>A \times B = 39</var> is <var>39</var>.</p></section>
</div>
</span> |
p00978 | <h2>Sixth Sense</h2>
<p>
Ms. Future is gifted with precognition. Naturally, she is excellent at some card games since she can correctly foresee every player's actions, except her own. Today, she accepted a challenge from a reckless gambler Mr. Past. They agreed to play a simple two-player trick-taking card game.
</p>
<p>
Cards for the game have a number printed on one side, leaving the other side blank making indistinguishable from other cards.
</p>
<p>
A game starts with the same number, say $n$, of cards being handed out to both players, without revealing the printed number to the opponent.
</p>
<p>
A game consists of $n$ tricks. In each trick, both players pull one card out of her/his hand. The player pulling out the card with the larger number takes this trick. Because Ms. Future is extremely good at this game, they have agreed to give tricks to Mr. Past when both pull out cards with the same number. Once a card is used, it can never be used later in the same game. The game continues until all the cards in the hands are used up. The objective of the game is to take as many tricks as possible.
</p>
<p>
Your mission of this problem is to help Ms. Future by providing a computer program to determine the best playing order of the cards in her hand. Since she has the sixth sense, your program can utilize information that is not available to ordinary people before the game.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$
$p_1$ ... $p_n$
$f_1$ ... $f_n$
</pre>
<p>
$n$ in the first line is the number of tricks, which is an integer between 2 and 5000, inclusive. The second line represents the Mr. Past's playing order of the cards in his hand. In the $i$-th trick, he will pull out a card with the number $p_i$ ($1 \leq i \leq n$). The third line represents the Ms. Future's hand. $f_i$ ($1 \leq i \leq n$) is the number that she will see on the $i$-th received card from the dealer. Every number in the second or third line is an integer between 1 and 10 000, inclusive. These lines may have duplicate numbers.
</p>
<h3>Output</h3>
<p>
The output should be a single line containing $n$ integers $a_1 ... a_n$ separated by a space, where $a_i$ ($1 \leq i \leq n$) is the number on the card she should play at the $i$-th trick for maximizing the number of taken tricks. If there are two or more such sequences of numbers, output the lexicographically greatest one among them.
</p>
<h3>Sample Input 1</h3>
<pre>
5
1 2 3 4 5
1 2 3 4 5
</pre>
<h3> Sample Output 1</h3>
<pre>
2 3 4 5 1
</pre>
<h3>Sample Input 2</h3>
<pre>
5
3 4 5 6 7
1 3 5 7 9
</pre>
<h3>Sample Output 2</h3>
<pre>
9 5 7 3 1
</pre>
<h3>Sample Input 3</h3>
<pre>
5
3 2 2 1 1
1 1 2 2 3
</pre>
<h3>Sample Output 3</h3>
<pre>
1 3 1 2 2
</pre>
<h3>Sample Input 4</h3>
<pre>
5
3 4 10 4 9
2 7 3 6 9
</pre>
<h3> Sample Output 4</h3>
<pre>
9 7 3 6 2
</pre>
|
p01390 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">åé¡ C </font> ãããšã</h1>
<h2>å顿</h2>
<p>ãªããšãªãæã ã£ãã®ã§ãããšãã® AI ãäœã£ãŠ AI ãšãããšããããããšã«ããïŒãããšããšã¯ <var>2</var> 人ã§éã¶ã²ãŒã ã§ïŒäž¡è
ã®éã§ãŸã äžåºŠãçºèšãããŠãããïŒ(æåã®æçªãé€ããŠ) å
é ã®æåãçŽåã®åèªã®æåŸã®æåãšãªã£ãŠããåèªã亀äºã«èšãåãã²ãŒã ã§ããïŒ</p>
<p>ä»å AI ã«åèªã®å€å®ãå®è£
ããã®ãé¢åã ã£ãã®ã§ïŒåèªã®å®çŸ©ã¯ã¢ã«ãã¡ãããã®å°æåãããªãæååå
šãŠãšããïŒ</p>
<p>ããã AI ã宿ãããããã§ãããšããããã®ã¯é¢åããããªã£ãŠããã®ã§ïŒããã°ã©ã ãæžããŠèªåã®ä»£ããã« AI ãšå¯ŸæŠãããããšã«ããïŒããã°ã©ã ãæžãã®ã¯è¯ãã®ã ãç®æšãç¡ãã®ã¯ã€ãŸããªãã®ã§ïŒãªãã¹ãæ©ã AI ã«åã€ããã°ã©ã ãæžãããšã«ããïŒããªãã¡ïŒãªãã¹ãå°ãªããããšãã§ AI ã«äžæ£ãªå¿çããããããã°ã©ã ãæžãã®ã§ããïŒ</p>
<p>ãªãããã°ã©ã ãå
æã§ AI ãåŸæã§ããïŒ</p>
<h2>å
¥åºå</h2>
<p>ããã°ã©ã ã¯ãããšãã®åèªãçºèšãããšïŒAI ã®è¿çãèãããšãã§ããïŒ
äŸãã° C/C++ ã§ <tt>abc</tt> ãšåèªãçºèšããã«ã¯</p>
<pre>printf("?abc\n"); fflush(stdout);</pre>
<p>ãšããïŒæ¬¡ã«ïŒ</p>
<pre>scanf("%s", str);</pre>
<p>ãšãããš <var>str</var> ã« AI ã®è¿çãå
¥ãïŒ</p>
<p>æçµçã« AI ã®èª€ããææããã«ã¯ <tt>!OUT</tt> ãšåºåããããšïŒèª€ããææããã®ã¯ïŒééã£ãçºèšã®çŽåŸã§ãªããã°ãªããªãïŒèª€ããææããæç¹ã§ããã°ã©ã ãçµäºããïŒäžèŠãªåºåã¯äžåè¡ã£ãŠã¯ãããªãïŒèª€ãã®ææãæ£ãããã°ããã°ã©ã ã¯æ£è§£ (<i>Accepted</i>) ãšå€å®ãããïŒåèªã®å¿çãäžé©åã§ãã£ããïŒAI ãžã®èª€ãã®ææãæ£ãããªãå ŽåïŒAI ã®èª€ããææããªãã£ãå Žåã¯èª€ç (<i>Wrong Answer</i>) ãšå€å®ãããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li>ããã°ã©ã ã®äœ¿ã£ãŠè¯ãåèªã®é·ã㯠<var>1</var> æåä»¥äž <var>10</var> æå以äžã§ããïŒ</li>
<li>AI ã®äœ¿ãåèªã®é·ã㯠<var>1</var> æåä»¥äž <var>2</var> æå以äžã§ããïŒ</li>
<li>ããã°ã©ã ã¯æå€§ã§ <var>50</var> åãŸã§çºèšããããšãåºæ¥ãïŒãããè¶
ãããšèª€ç (<i>Query Limit Exceeded</i>) ãšãªãïŒ</li>
<li>AIïŒããã°ã©ã äž¡è
ãšãåèªã«äœ¿ã£ãŠè¯ãæåã¯ã¢ã«ãã¡ãããã®å°æåã®ã¿ã§ããïŒ </li>
<li>AI ã®è¿çã¯ã¢ã«ãã¡ãããã®å°æåã®ã¿ãããªãïŒ</li>
<li>æåã®æçªã§ã¯ïŒããã°ã©ã ã¯ã©ã®ã¢ã«ãã¡ããããããããšããéå§ããŠãè¯ãïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<p>
以äžã®äŸã¯ããã°ã©ã ã®å
¥åºåã®äŸã§ããïŒå·Šã®åãããã°ã©ã ã®åºåïŒå³ã®åãããã°ã©ã ãžã®å
¥å (AI ã®çºèš) ã衚ãïŒæåã«ããã°ã©ã 㯠<tt>abcdefghij</tt> ãšããåèªãèšã£ãŠããïŒãã®å¿çãšã㊠AI 㯠<tt>jk</tt> ãšè¿ããŠãïŒ<var>3</var> åç®ã®å¿çã®éã« AI ã¯ãã§ã«äœ¿ãããŠãã <tt>jk</tt> ãšããåèªãçºããŠããã®ã§ããã«å¯ŸããŠããã°ã©ã 㯠<tt>!OUT</tt> ãšèšã£ãŠ AI ã®èª€ããææããŠããïŒ
</p>
<div class="reactive-example">
<table class="withborder">
<tr><th>ããã°ã©ã ã®åºå</th><th>ããã°ã©ã ãžã®å
¥å</th></tr>
<tr><td>?abcdefghij</td><td></td></tr>
<tr><td></td><td>jk</td></tr>
<tr><td>?kkkk</td><td></td></tr>
<tr><td></td><td>kl</td></tr>
<tr><td>?lj</td><td></td></tr>
<tr><td></td><td>jk</td></tr>
<tr><td>!OUT</td><td></td></tr>
</table>
</div>
<br>
<h3>å
¥åäŸ 2</h3>
<p>
以äžã®äŸã§ã¯ïŒAI ã <tt>aaa</tt> ãšããåèªã«å¯Ÿã㊠<tt>bb</tt> ãšãããšãã«ãªããªãè¿çãããŠãããã <tt>!OUT</tt> ãšè¿ããŠããïŒ
</p>
<div class="reactive-example">
<table class="withborder">
<tr><th>ããã°ã©ã ã®åºå</th><th>ããã°ã©ã ãžã®å
¥å</th></tr>
<tr><td>?aaa</td><td></td></tr>
<tr><td></td><td>bb</td></tr>
<tr><td>!OUT</td><td></td></tr>
</table>
</div>
<br>
|
p02416 |
<H1>Sum of Numbers</H1><br>
<p>
Write a program which reads an integer and prints sum of its digits.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. For each dataset, an integer <var>x</var> is given in a line. The number of digits in <var>x</var> does not exceed 1000.
</p>
<p>
The input ends with a line including single zero. Your program should not process for this terminal symbol.
</p>
<H2>Output</H2>
<p>
For each dataset, print the sum of digits in <var>x</var>.
</p>
<H2>Sample Input</H2>
<pre>
123
55
1000
0
</pre>
<H2>Sample Output</H2>
<pre>
6
10
1
</pre>
|
p02046 | <h3>é¿ããã¹ã</h3>
<!-- begin ja only -->
<p>ããªãã¯ããŸïŒäžäžå·Šå³ã«åºå€§ã«åºãããã¹ç®ã®åç¹ã«åœããäœçœ® <i>(0, 0)</i> ã«ããïŒãã¹ã®äœçœ®ã¯<i>x</i>座æšãš<i>y</i>座æšã§è¡šããïŒå³ã«1ãã¹åãããšã<i>x</i>座æšã1ã€å¢ããããšã«å¯Ÿå¿ãïŒäžã«1ãã¹åãããšã<i>y</i>座æšã1ã€å¢ããããšã«å¯Ÿå¿ããïŒããªãã¯ããããç®çå°ã§ãããã¹ <i>(x, y)</i> ãç®æããŠåºçºãããšããã ïŒããªã㯠1 æ©ã§äžäžå·Šå³æãã® 8 æ¹åã«é£æ¥ãããã¹ã«ç§»åããããšãã§ããïŒ</p>
<p>ããïŒç®çå°ã«åãã£ãŠç§»åéå§ã ïŒãšããªãã¯ææ°èŸŒãã§ãããšãããããããªããïŒã¡ãã£ãšåŸ
ã£ãŠã»ããïŒäžã€ã ãå
ã«å¿ åããŠããããšãããïŒããã¯ãã®ãã¹ç®ã«æœãè¬ã®äººç©ïŒåã蟌ã¿ã®ããã»å»»å°å®®ã®ååšã ïŒå»»å°å®®ã¯ããªãã 1 æ©ç§»åããã®ã確èªãããšïŒããªããé²ãã æ¹åã®ããã« 1 æ©å
ã®ãã¹ã«ç¬æã«ç§»åãïŒéªéãããŠããïŒããæ£ç¢ºã«èšãã°ïŒããªãããã¹ <i>(x<sub>s</sub>, y<sub>s</sub>) </i>ãã <i>(x<sub>t</sub>, y<sub>t</sub>)</i> ã«ç§»åãããšãïŒå»»å°å®®ã¯ <i>(x<sub>t</sub> + (x<sub>t</sub> - x<sub>s</sub>), y<sub>t</sub> + (y<sub>t</sub> - y<sub>s</sub>))</i> ã«ç§»åããïŒæããã«ç°æ§ãªé°å²æ°ãéžãåºãå»»å°å®®ïŒã€ãã®éåãã«å
¥ã蟌ãã®ã¯å±éºã ïŒåã蟌ãŸããçŽåŸã¯ä»æ¹ãªããšããŠïŒæ¬¡ã«ç§»åããå
ã®ãã¹ïŒãããã¯ãã® 8 æ¹åã«é£æ¥ãããã¹ã®ã©ããã«å»»å°å®®ããã§ã«ãããšïŒã€ãã®éåãã«å
¥ã蟌ãã§ããŸãããšã«ãªãã®ã§ïŒããã¯ã©ãããŠãé¿ãããïŒ</p>
<p>äžèšã®ããã«å»»å°å®®ã®éåããé¿ãã€ã€ïŒç®çå°ã«èŸ¿ãçãããã«ã¯æå°ã§äœæ©å¿
èŠã ãããïŒããªãã®ä»äºã¯ãã®æå°æ©æ°ãæ±ããããã°ã©ã ãæžãããšã ïŒãã ãïŒå»»å°å®®ã¯åæç¶æ
ã§ã¯ã©ã®ãã¹ã«ãååšããïŒæåã® 1 æ©ç®ä»¥éããäžèšã®ã«ãŒã«ã«åŸã£ããã¹ã«çŸãããã®ãšããïŒ</p>
<p>æåã®ãµã³ãã«ã§ã¯ïŒããªã㯠<i>(2, 0)</i> ãç®æãïŒäŸãã°æåã«å³æšªã®ãã¹<i>(1, 0)</i> ã«ç§»åããŠããŸããšïŒå»»å°å®®ã <i>(2, 0)</i> ã«åã蟌ãã§ããããïŒæ¬¡ã«ãã®ãã¹ãžãšç§»åããããšãã§ããªãïŒäžæ¹ïŒæåã«å³æãäžã® <i>(1, 1)</i> ã«ç§»åãããšïŒå»»å°å®®ã®äœçœ®ã¯ <i>(2, 2)</i> ãšãªã <i>(2, 0)</i> ãå»»å°å®®ã®éåãã§ã¯ãªãããïŒæ¬¡ã® 1 æ©ã§ <i>(2, 0)</i> ã«ç§»åããããšãã§ããïŒ</p>
<p><center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2019_C" width="600pt"></center></p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ãã㯠2 ã€ã®æŽæ° <i>x</i>, <i>y</i> ãããªã 1 è¡ã§è¡šãããïŒããã¯ç®çå°ã®ãã¹ãäœçœ® <i>(x, y)</i> ã§ããããšã衚ãïŒ<i>|x|, |y| ≤ 10<sup>9</sup></i> ãæºããïŒ</p>
<p>å
¥åã®çµãã㯠EOF (ãã¡ã€ã«ã®çµç«¯) ã§è¡šãããïŒ å
šããŒã¿ã»ããã®ç·æ°ã¯ 50 ãè¶
ããªãïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>æ¡ä»¶ãæºããããã«ç§»åãç¹°ãè¿ããšãïŒãã¹ <i>(0, 0)</i> ãããã¹ <i>(x, y)</i> ã«ç§»åããããã«å¿
èŠãªæå°æ©æ°ã 1 è¡ã«åºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>2 0
2 2
1 -1
0 0
0 -5
173 207
</pre><h3>Output for the Sample Input</h3><pre>2
4
1
0
6
379
</pre>
|
p00581 | <h1>åè
ã倪é(Bitaro the Brave)</h1>
<p>
åè
ã®ã倪éã¯ïŒéçãšå¯Ÿå³ããããšãšãªã£ãïŒ
</p>
<p>
ã倪éã¯ïŒçžŠ$H$ è¡ïŒæšª$W$ åã®ãã¹ç®äžã«å®ç³(Jewel)ïŒãªãŒã(Orb)ïŒéå¡(Ingot) ãé
眮ãïŒéæ³ãçºåããããšã«ãã£ãŠéçã«æ»æãããããšããŠããïŒä»¥äžïŒãã¹ç®ã®ãã¡äžãã$i$ è¡ç®($1 \leq i \leq H$)ïŒå·Šãã$j$ åç®($1 \leq j \leq W$) ã®ãã¹ãïŒãã¹($i, j$) ãšè¡šãïŒ
</p>
<p>
ã倪éã¯ä»ïŒããããã®ãã¹ã«ããã3 çš®é¡ã®ãã¡1 åãé
眮ããïŒä»ããéæ³ãçºåããããšããŠãããïŒãã®éæ³ã®åšåã¯ãã¹ç®äžã®å®ç³ïŒãªãŒãïŒéå¡ã®é
眮ã«ãã£ãŠæ±ºãŸãïŒå
·äœçã«ã¯ïŒæ¬¡ã®æ¡ä»¶ãæºããæŽæ°($i, j, k, l$) ($1 \leq i < k \leq H, 1 \leq j < l \leq W$) ã®çµã®åæ°ãïŒéæ³ã®åšåã§ããïŒ<br/>
<br/>
æ¡ä»¶ïŒãã¹($i, j$) ã«ã¯å®ç³ãïŒãã¹($i, l$) ã«ã¯ãªãŒããïŒãã¹($k, j$) ã«ã¯éå¡ã眮ãããŠããïŒ<br/>
</p>
<p>
ã倪éã¯ïŒãã®éæ³ã®åšåãæ°ã«ãªã£ãŠããïŒ
</p>
<p>
ãã¹ç®äžã®å®ç³ïŒãªãŒãïŒéå¡ã®é
眮ãäžãããããšãïŒã倪éãçºåããéæ³ã®åšåãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ
</p>
<pre>
$H$ $W$
$S_1$
:
$S_H$
</pre>
<p>
$S_i$ ($1 \leq i \leq H$) ã¯é·ã$W$ ã®æååã§ïŒãã®$j$ æåç®($1 \leq j \leq W$) ãJ ã®ãšãã¯ãã¹($i, j$) ã«å®ç³ãïŒO ã® ãšãã¯ãã¹($i, j$) ã«ãªãŒããïŒI ã®ãšãã¯ãã¹($i, j$) ã«éå¡ã眮ãããŠããããšã衚ãïŒ
</p>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒéæ³ã®åšåãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$2 \leq H \leq 3 000$ïŒ</li>
<li>$2 \leq W \leq 3 000$ïŒ</li>
<li>$S_i$ ã¯é·ã$W$ ã®æååã§ãã($1 \leq i \leq H$)ïŒ</li>
<li>$S_i$ ã®åæåã¯JïŒOïŒI ã®ããããã§ãã($1 \leq i \leq H$)ïŒ</li>
</ul>
<!--
å°èª²é¡
1. (20 ç¹) H ⊠100ïŒW ⊠100ïŒ
2. (30 ç¹) H ⊠500ïŒW ⊠500ïŒ
3. (50 ç¹) 远å ã®å¶çŽã¯ãªãïŒ
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
3 4
JOIJ
JIOO
IIII
</pre>
<h3>åºåäŸ1</h3>
<pre>
3
</pre>
<p>ãã®å
¥åäŸã§ã¯ïŒ($i, j, k, l$) = (1, 1, 3, 2), (2, 1, 3, 3), (2, 1, 3, 4) ã®3 åã®çµãæ¡ä»¶ãæºããã®ã§ïŒçãã¯3 ã§ããïŒ
</p>
<h3>å
¥åäŸ2 </h3>
<pre>
4 4
JJOO
JJOO
IIJO
IIIJ
</pre>
<h3>åºåäŸ2</h3>
<pre>
17
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2018/2019-ho/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第18 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2018/2019) æ¬éžã</a>
</p>
|
p00094 |
<H1>åªé¢ç©ã®èšç®</H1>
<p>
åå°ã®é¢ç©ã衚çŸãããââåªããšããåäœãèããããšã¯ãªãã§ããããïŒ å€æ¥ãïŒäººã®æŠå£«ãïŒæ¥ã«é£ã¹ããç±³ãäœãé¢ç©ãèšããŸããã
</p>
<p>
<var>a</var>mïŒœ× <var>b</var>mã®åå°ããããŸãã<var>a</var> ãš <var>b</var> ãå
¥åãããã®åå°ã®åªé¢ç© <var>S</var>åªïŒœãåºåããããã°ã©ã ãäœæããŠãã ããã 1 åª = 3.305785 [m<sup>2</sup>] ãšãã<var>a</var> ãš <var>b</var> 㯠100 以äžã®æŽæ°ãšããŸãã
</p>
<H2>å
¥å</H2>
<pre>
<var>a</var> <var>b</var>
</pre>
<p>
ïŒã€ã®ç©ºçœã§åºåããã <var>a</var> ãš <var>b</var> ãïŒè¡ã«äžããããã
</p>
<H2>åºå</H2>
<p>
åªé¢ç© <var>S</var> ãïŒè¡ã«åºåããã0.0001 以äžã®èª€å·®ãèš±ãããã
</p>
<H2>å
¥åäŸ1</H2>
<pre>
15 25
</pre>
<H2>åºåäŸ1</H2>
<pre>
113.437508
</pre>
|
p02553 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are integers <var>a,b,c</var> and <var>d</var>.
If <var>x</var> and <var>y</var> are integers and <var>a \leq x \leq b</var> and <var>c\leq y \leq d</var> hold, what is the maximum possible value of <var>x \times y</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>-10^9 \leq a \leq b \leq 10^9</var></li>
<li><var>-10^9 \leq c \leq d \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var> <var>c</var> <var>d</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If <var>x = 1</var> and <var>y = 1</var> then <var>x \times y = 1</var>.
If <var>x = 2</var> and <var>y = 1</var> then <var>x \times y = 2</var>.
Therefore, the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5 -4 -2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-6
</pre>
<p>The answer can be negative.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>-1000000000 0 -1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000000000000000
</pre></section>
</div>
</span> |
p02103 |
<h1>Problem F: Great Devil Sakanikia</h1>
<h2>Problem</h2>
<p>
倧æªéãµã«ãŒãã£ã¯ä»æ¥ã倩æµã®ç«ã«è¥²ãããŠããã<br>
ãã€ãããããŠããèš³ã«ã¯ãããªãã®ã§ãç§å¯å
µåšã賌å
¥ããã<br>
ãã®ç§å¯å
µåšã¯ã巚倧ãªå²©ãçæããããšã§ç«ã®ç§»åçµè·¯ãå¡ããç«ããã¡ãã«è¿ã¥ããªãããã«ããããšãã§ããã<br>
</p>
<p>
ä»ããµã«ãŒãã£ãšäžå¹ã®ç«ããã¹(0,0),(<var>n</var>−1,0),(<var>n</var>−1,<var>m</var>−1),(0,<var>m</var>−1)ã§å²ãŸããé·æ¹åœ¢ã®éåºéå
ã«ããã<br>
ãã¹(0,0)ã«ç«ããã¹(<var>n</var>−1,<var>m</var>−1)ã«ãµã«ãŒãã£ãããã<br>
ç«ã¯äžäžå·Šå³ã®é£æ¥ãããã¹ã«ç§»åããããšãã§ããããåºéå€ã«åºãããšã¯ã§ããªãã<br>
ããã€ãã®ãã¹ã¯ã穎ãé害ç©ã®åœ±é¿ã§äŸµå
¥ããããšãã§ããªãã<br>
ãµã«ãŒãã£ã¯ããããã¹ã«1ã€å²©ãçæããããšã§ãã®ãã¹ã«ç«ã䟵å
¥ã§ããªãããããšãã§ããã<br>
ãã ãããã¹(0,0)ãšãã¹(<var>n</var>−1,<var>m</var>−1)ã«å²©ãçæããããšã¯ã§ããªãã
</p>
<p>
ãã¹(0,0)ãããã¹(<var>n</var>−1,<var>m</var>−1)ãŸã§ã®ç§»åçµè·¯ãå¡ãããã«å¿
èŠãªãçæããå²©ã®æ°ã®æå°å€ãæ±ããã
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var> <var>k</var>
<var>x</var><sub>1</sub> <var>y</var><sub>1</sub>
...
<var>x<sub>k</sub></var> <var>y<sub>k</sub></var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«ãã¹ã®å€§ããã衚ãïŒã€ã®æŽæ°<var>n</var>ãš<var>m</var>ã䟵å
¥ã§ããªããã¹ã®æ°<var>k</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ãã<var>k</var>è¡ã«äŸµå
¥ã§ããªããã¹ã®åº§æšãäžããããã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li>2 ≤ <var>n</var>,<var>m</var> ≤ 10<sup>5</sup></li>
<li>0 ≤ <var>k</var> ≤ min(<var>n</var>×<var>m</var>−2,10<sup>5</sup>)</li>
<li>0 ≤ <var>x<sub>i</sub></var> ≤ <var>n</var> − 1</li>
<li>0 ≤ <var>y<sub>i</sub></var> ≤ <var>m</var> − 1</li>
<li>(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>) ≠ (<var>x<sub>j</sub></var>,<var>y<sub>j</sub></var>) (<var>i</var> ≠ <var>j</var>)</li>
<li>(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>) ≠ (0,0) ≠ (<var>n</var>−1,<var>m</var>−1)</li>
</ul>
<h2>Output</h2>
<p>
ãã¹(0,0)ãããã¹(<var>n</var>−1,<var>m</var>−1)ãŸã§ã®ç§»åçµè·¯ãå¡ãããã«å¿
èŠãªãçæããå²©ã®æ°ã®æå°å€ã1è¡ã«åºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
3 5 2
0 2
2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5 3
0 2
2 2
4 1
</pre>
<h2>Sample Output 2</h2>
<pre>
2
</pre> |
p01685 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h3>Problem Statement</h3>
<p>You have a rectangular board with square cells arranged in $H$ rows and $W$ columns.
The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right.
The cell at the row $i$ and the column $j$ is denoted by $(i, j)$.
Each cell on the board is colored in either Black or White.
</p>
<p>You will paint the board as follows:
</p><ol><li><p> Choose a cell $(i, j)$ and a color $c$, each uniformly at random, where $1 \le i \le H$, $1 \le j \le W$, and $c \in \{{\rm Black}, {\rm White}\}$.
</p></li><li><p> Paint the cells $(i', j')$ with the color $c$ for any $1 \le i' \le i$ and $1 \le j' \le j$.
</p></li></ol>
<p>Here's an example of the painting operation.
You have a $3 \times 4$ board with the coloring depicted in the left side of the figure below.
If your random choice is the cell $(2, 3)$ and the color Black, the board will become as shown in the right side of the figure.
$6$ cells will be painted with Black as the result of this operation.
Note that we count the cells "painted" even if the color is not actually changed by the operation, like the cell $(1, 2)$ in this example.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2013_fig_overwrite" height="175" width="640" /><br/>
Fig: An example of the painting operation
</center>
<br/>
<p>Given the initial coloring of the board and the desired coloring, you are supposed to perform the painting operations repeatedly until the board turns into the desired coloring.
Write a program to calculate the expected total number of painted cells in the sequence of operations.
</p>
<h3>Input</h3>
<p>The input consists of several datasets. The number of datasets is at most $100$.
</p>
<p>The first line of each dataset contains two integers $H$ and $W$ ($1 \le H, W \le 5$), the numbers of rows and columns of the board respectively.
Then given are two coloring configurations of the board, where the former is the initial coloring and the latter is the desired coloring.
A coloring configuration is described in $H$ lines, each of which consists of $W$ characters. Each character is either B or W, denoting a Black cell or a White cell, respectively.
There is one blank line between two configurations, and also after each dataset.
You can assume that the resulting expected value for each dataset will not exceed $10^9$.
</p>
<p>The input is terminated by a line with two zeros, and your program should not process this as a dataset.
</p>
<h3>Output</h3>
<p>For each dataset, your program should output the expected value in a line. The absolute error or the relative error in your answer must be less than $10^{-6}$.
</p>
<h3>Sample Input</h3>
<pre>1 2
BB
WW
2 1
B
W
B
W
2 2
BW
BW
WW
WW
3 4
BBBB
BBBB
BBBB
WWWW
WWWW
WWWW
5 5
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB
BBBBB
BBBWB
BBBBB
BWBBB
BBBBB
0 0</pre>
<h3>Output for the Sample Input</h3>
<pre>6.0000000000
0.0000000000
12.8571428571
120.0000000000
23795493.8449918639</pre> |
p00997 |
<h1>Problem H : Dungeon (II)</h1>
<p>
ããªãã¯ãšããã²ãŒã ã®éçºã«æºãã£ãŠããã
ãã®ã²ãŒã ã¯ã©ã³ãã ã«çæããããã³ãžã§ã³ããã¬ã€ã€ãŒãæ¢çŽ¢ãããšãããã®ã§ããã
ã²ãŒã ã®ä»æ§ãšããŠããã¬ã€ã€ãŒã«äºããã³ãžã§ã³ã®å±éºåºŠãæç€ºããçæããããã³ãžã§ã³ãæ¢çŽ¢ããã®ãããããšãæ°ãããã³ãžã§ã³ãçæããªãããããéžæã§ããããã«ãããã
</p>
<p>
ãã®ã²ãŒã ã§çæããããã³ãžã§ã³ã«ã¯<i>n</i> åã®éšå±ãååšããŠããã0ãã <i>n-1</i> ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã
éšå±ãšéšå±ã¯éè·¯ã§çµã°ããŠãããéšå±ãšéšå±ãçµã¶éè·¯ã¯ãåèšã§ <i>n-1</i> æ¬ååšããŠããã
éè·¯ã¯ã©ã¡ãã®æ¹åãžãé²ãããšãã§ããã
ãŸããéšå±ãšéšå±ã®éã«ã¯è·é¢ãèšå®ãããŠããã
çæããããã³ãžã§ã³ã§ã¯ããã€ãã®éè·¯ãçµç±ããŠãããéšå±ããä»ã®ãã¹ãŠã®éšå±ãžè¡ãããšãå¯èœã§ããã
ãããŠããã¬ã€ã€ãŒãã²ãŒã ãè¡ãéã«ãïŒã€ã®ç°ãªãéšå±ãã¹ã¿ãŒãå°ç¹ãšãŽãŒã«å°ç¹ãšããŠéžã°ããã
</p>
<p>
ããªãã¯ãã³ãžã§ã³ã®è©äŸ¡ãè¡ãããã«ãå±éºåºŠã®è©äŸ¡æ¹æ³ã決ããããšã«ããã
ãŸããããéšå±ããå¥ã®éšå±ãŸã§ã«ç§»åããéã®å±éºåºŠããéšå±éãæçã§ç§»åããããã«äœ¿ãéè·¯ã®äžã§ãæãã³ã¹ãé«ãéè·¯ã®å€ãšããã
ãããŠããã³ãžã§ã³ã®å±éºåºŠãã<i>i</i> < <i>j</i> ãšãªãéšå±ã®ãã¢ã®éãç§»åããéã®å±éºåºŠã®ç·åãšããããšã«ããã
</p>
<p>
ã©ã³ãã ã«çæããããã³ãžã§ã³ã®ãå
¥åãšããŠäžããããã
ãŸãã<i>i</i> < <i>j</i> ãšãªããã¹ãŠã®éšå±ã®ãã¢ã«ã€ããŠãç§»åããéã®å±éºåºŠãèšç®ããŠæ¬²ããã
ãããŠããã®ç·åãåé¡ã®çããšããŠåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>n</i>
<i>a<sub>1</sub></i> <i>b<sub>1</sub></i> <i>c<sub>1</sub></i>
.
.
.
<i>a<sub>n-1</sub></i> <i>b<sub>n-1</sub></i> <i>c<sub>n-1</sub></i>
</pre>
<p>
<i>a<sub>i</sub></i> <i>b<sub>i</sub></i> <i>c<sub>i</sub></i> 㯠éšå± <i>a<sub>i</sub></i> ãš <i>b<sub>i</sub></i>ããçµã¶éè·¯ã®è·é¢ã<i>c<sub>i</sub></i>ã§ããããšã衚ãã
</p>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºãã<br>
2 ≤ <i>n</i> ≤ 200,000 <br>
0 ≤ <i>a<sub>i</sub></i>,<i>b<sub>i</sub></i> < <i>n</i><br>
0 ≤ <i>c<sub>i</sub></i> ≤ 100,000<br>
</p>
<h2>Output</h2>
<p>
çãã®å€ã1è¡ã«åºåãã
</p>
<h2>Sample Input 1</h2>
<pre>
4
0 1 3
1 2 5
1 3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
23
</pre>
<h2>Sample Input 2</h2>
<pre>
6
0 2 5
2 1 1
2 3 10
3 5 4
3 4 2
</pre>
<h2>Sample Output 2</h2>
<pre>
111
</pre>
|
p03342 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an integer sequence <var>A</var> of length <var>N</var>.</p>
<p>Find the number of the pairs of integers <var>l</var> and <var>r</var> (<var>1 \leq l \leq r \leq N</var>) that satisfy the following condition:</p>
<ul>
<li><var>A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r</var></li>
</ul>
<p>Here, <var>xor</var> denotes the bitwise exclusive OR.</p>
<p><details>
<summary style="display:list-item">Definition of XOR</summary></details></p>
<p>The XOR of integers <var>c_1, c_2, ..., c_m</var> is defined as follows:</p>
<ul>
<li>Let the XOR be <var>X</var>. In the binary representation of <var>X</var>, the digit in the <var>2^k</var>'s place (<var>0 \leq k</var>; <var>k</var> is an integer) is <var>1</var> if there are an odd number of integers among <var>c_1, c_2, ...c_m</var> whose binary representation has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> if that number is even.</li>
</ul>
<p>For example, let us compute the XOR of <var>3</var> and <var>5</var>. The binary representation of <var>3</var> is <var>011</var>, and the binary representation of <var>5</var> is <var>101</var>, thus the XOR has the binary representation <var>110</var>, that is, the XOR is <var>6</var>.</p>
<p></p></section></div></span> |
p03712 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a image with a height of <var>H</var> pixels and a width of <var>W</var> pixels.
Each pixel is represented by a lowercase English letter.
The pixel at the <var>i</var>-th row from the top and <var>j</var>-th column from the left is <var>a_{ij}</var>.</p>
<p>Put a box around this image and output the result. The box should consist of <code>#</code> and have a thickness of <var>1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †H, W †100</var></li>
<li><var>a_{ij}</var> is a lowercase English letter.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{11}</var> <var>...</var> <var>a_{1W}</var>
<var>:</var>
<var>a_{H1}</var> <var>...</var> <var>a_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the image surrounded by a box that consists of <code>#</code> and has a thickness of <var>1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
abc
arc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>#####
#abc#
#arc#
#####
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>###
#z#
###
</pre></section>
</div>
</span> |
p02800 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>H \times W</var> grid, where each square is painted white or black in the initial state.
Given are strings <var>A_1, A_2, ..., A_H</var> representing the colors of the squares in the initial state.
For each pair <var>(i, j)</var> (<var>1 \leq i \leq H</var>, <var>1 \leq j \leq W</var>), if the <var>j</var>-th character of <var>A_i</var> is <code>.</code>, the square at the <var>i</var>-th row and <var>j</var>-th column is painted white; if that character is <code>#</code>, that square is painted black.</p>
<p>Among the <var>2^{HW}</var> ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo <var>998,244,353</var>.</p>
<ul>
<li>Choose one row, then paint all the squares in that row white.</li>
<li>Choose one row, then paint all the squares in that row black.</li>
<li>Choose one column, then paint all the squares in that column white.</li>
<li>Choose one column, then paint all the squares in that column black.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H, W \leq 10</var></li>
<li><var>|A_i| = W</var> (<var>1 \leq i \leq H</var>)</li>
<li>All strings <var>A_i</var> consist of <code>.</code> and <code>#</code>.</li>
<li><var>H</var> and <var>W</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>A_1</var>
<var>A_2</var>
<var>\vdots</var>
<var>A_H</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
#.
.#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>15
</pre>
<p>For example, if we paint the second row black, the grid becomes:</p>
<pre>#.
##
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
...
...
...
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>230
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 4
#...
...#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>150
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6 7
.......
.......
.#.....
..#....
.#.#...
.......
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>203949910
</pre></section>
</div>
</span> |
p00217 |
<H1>ãŠã©ãŒãã³ã°</H1>
<p>
äŒæŽ¥ãªããŒãµã€ããã¹ãã¿ã«ã§ã¯ããªãããªãšå¥åº·å¢é²ã®ãããå
¥é¢æ£è
ãäžæ¥äºåã®ãŠã©ãŒãã³ã°ãè¡ã£ãŠããŸããå
æ°ã«éé¢ããããã«ããŠã©ãŒãã³ã°ã§äœåãå埩ããããšé 匵ãäººãæ¥ã«æ¥ã«å¢ãããããšãããé¢é·ããäžæ¥ã§äžçªé·ãè·é¢ãæ©ãã人ã«ãã¬ãŒã³ãããããã!ããšããäŒç»ãç«ã¡äžããŸããã
</p>
<!--
<p>
äŒæŽ¥ãªããŒãµã€ããã¹ãã¿ã«ã§ã¯ããªãããªãšå¥åº·å¢é²ã®ãããå
¥é¢æ£è
ãäžæ¥äºåã®ãŠã©ãŒãã³ã°ãè¡ã£ãŠããŸããå
æ°ã«éé¢ããããã«ããŠã©ãŒãã³ã°ã§äœåãå埩ããããšé 匵ãäººãæ¥ã«æ¥ã«å¢ããŠãããŸãããå¥åº·ã«ãªãã«ã€ããæ°æã¡ãæããç¬é¡ãèŠãããããã«ãªã£ãããšãããé¢é·å
çãã ãäžæ¥ã§äžçªé·ãè·é¢ãæ©ãã人ã«ãã¬ãŒã³ãããããã!ããšããäŒç»ãç«ã¡äžããŸããã
</p>
-->
<p>
æ£è
ã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 10000)ãããããã®æ£è
ã®çªå· <var>p<sub>i</sub></var> (1 ≤ <var>p<sub>i</sub></var> ≤ 10000)ãäžåç®ã«æ©ããè·é¢ <var>d1<sub>i</sub></var>ãäºåç®ã«æ©ããè·é¢ <var>d2<sub>i</sub></var> (0 ≤ <var>d1<sub>i</sub></var>, <var>d2<sub>i</sub></var> ≤ 5000) ãå
¥åãšããæ©ããè·é¢ã®åèšãæãé·ãæ£è
ã®çªå·ãšãã®è·é¢ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããäžæ¥ã«æ©ããè·é¢ãåãæ£è
ã¯ããªããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>p<sub>1</sub></var> <var>d1<sub>1</sub></var> <var>d2<sub>1</sub></var>
<var>p<sub>2</sub></var> <var>d1<sub>2</sub></var> <var>d2<sub>2</sub></var>
:
<var>p<sub>n</sub></var> <var>d1<sub>n</sub></var> <var>d2<sub>n</sub></var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããŸããããŒã¿ã»ããã®æ°ã¯50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãæãé·ãåèšè·é¢ãæ©ããæ£è
ã®çªå·ãšãã®æ©ããè·é¢ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
5
263 2345 2504
1 3210 1985
5000 1501 4132
10000 503 3107
51 1758 2690
3
345 5000 2396
7 3910 1590
6789 2525 3616
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5000 5633
345 7396
</pre>
|
p02380 |
<H1>Triangle</H1><br>
<p>
For given two sides of a triangle <i>a</i> and <i>b</i> and the angle <i>C</i> between them, calculate the following properties:
</p>
<ul>
<li><var>S</var>: Area of the triangle</li>
<li><var>L</var>: The length of the circumference of the triangle</li>
<li><var>h</var>: The height of the triangle with side <var>a</var> as a bottom edge</li>
</ul>
<H2>Input</H2>
<p>
The length of <i>a</i>, the length of <i>b</i> and the angle <i>C</i> are given in integers.
</p>
<H2>Output</H2>
<p>
Print <var>S</var>, <var>L</var> and <var>h</var> in a line respectively. The output should not contain an absolute error greater than 10<sup>-4</sup>.
</p>
<H2>Sample Input</H2>
<pre>
4 3 90
</pre>
<H2>Sample Output</H2>
<pre>
6.00000000
12.00000000
3.00000000
</pre>
|
p03968 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer has <var>N</var> square tiles. The tiles are numbered <var>1</var> through <var>N</var>, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the <var>1000</var> colors, which are represented by the integers <var>0</var> between <var>999</var>. The top-left, top-right, bottom-right and bottom-left corner of the tile with the number <var>i</var> are painted in color <var>C_{i,0}, C_{i,1}, C_{i,2}</var> and <var>C_{i,3}</var>, respectively, when seen in the direction of the number written on the tile (See Figure <var>1</var>).</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/arc062/b8ec940254d280135500dab6d00d4370.png">
<p>Figure <var>1</var>: The correspondence between the colors of a tile and the input</p>
</img></div>
<p>AtCoDeer is constructing a cube using six of these tiles, under the following conditions:</p>
<ul>
<li>For each tile, the side with the number must face outward.</li>
<li>For each vertex of the cube, the three corners of the tiles that forms it must all be painted in the same color.</li>
</ul>
<p>Help him by finding the number of the different cubes that can be constructed under the conditions.
Since each tile has a number written on it, two cubes are considered different if the set of the used tiles are different, or the tiles are used in different directions, even if the formation of the colors are the same. (Each tile can be used in one of the four directions, obtained by <var>90°</var> rotations.) Two cubes are considered the same only if rotating one in the three dimensional space can obtain an exact copy of the other, including the directions of the tiles.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/arc062/8c7552f20698dab0aad52bba476fe6d7.png">
<p>Figure <var>2</var>: The four directions of a tile</p>
</img></div>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>6âŠNâŠ400</var></li>
<li><var>0âŠC_{i,j}âŠ999 (1âŠiâŠN , 0âŠjâŠ3)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>C_{1,0}</var> <var>C_{1,1}</var> <var>C_{1,2}</var> <var>C_{1,3}</var>
<var>C_{2,0}</var> <var>C_{2,1}</var> <var>C_{2,2}</var> <var>C_{2,3}</var>
<var>:</var>
<var>C_{N,0}</var> <var>C_{N,1}</var> <var>C_{N,2}</var> <var>C_{N,3}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different cubes that can be constructed under the conditions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
0 1 2 3
0 4 6 1
1 6 7 2
2 7 5 3
6 4 5 7
4 0 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The cube below can be constructed.</p>
<p><img alt="" src="https://atcoder.jp/img/arc062/094fbca5395bfaaea28c98c51230693b.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>144
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>122880
</pre></section>
</div>
</span> |
p01955 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>
Permutation Period
</H1>
<p>
You have a permutation $p$ of $N$ integers. Initially $p_i = i$ holds for $1 \leq i \leq N$. For each $j$ ($1 \leq j \leq N$), let's denote $p_{j}^0 = j$ and $p_{j}^k = p_{p_j}^{k-1}$ for any $k\geq 1$. The <i>period</i> of $p$ is defined as the minimum positive integer $k$ which satisfies $p_{j}^k = j$ for every $j$ ($1 \leq j \leq N$).
</p>
<p>
You are given $Q$ queries. The $i$-th query is characterized by two distinct indices $x_i$ and $y_i$. For each query, swap $p_{x_i}$ and $p_{y_i}$ and then calculate the period of updated $p$ modulo $10^9 + 7$ in the given order.
</p>
<p>
It can be proved that the period of $p$ always exists.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$N$ $Q$
$x_1$ $y_1$
...
$x_Q$ $y_Q$
</pre>
<p>
The first line consists of two integers $N$ and $Q$ ($2 \leq N \leq 10^5, 1 \leq Q \leq 10^5$). The ($i+1$)-th line consists of two integers $x_i$ and $y_i$ ($1 \leq x_i, y_i \leq N, x_i \ne y_i$).
</p>
<H2>Output</H2>
<p>
Print the answer in one line for each query.
</p>
<H2>Sample Input 1</H2>
<pre>
5 4
2 5
2 4
1 3
1 2
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
2
3
6
5
</pre>
<p>
$p$ changes as follows: $[1,2,3,4,5] \rightarrow [1,5,3,4,2] \rightarrow [1,4,3,5,2] \rightarrow [3,4,1,5,2] \rightarrow [4,3,1,5,2]$.
</p>
<H2>Sample Input 2</H2>
<pre>
2 2
1 2
1 2
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
2
1
</pre>
<p>
$p$ changes as follows: $[1,2] \rightarrow [2,1] \rightarrow [1,2]$.
</p>
<H2>Sample Input 3</H2>
<pre>
10 10
5 6
5 9
8 2
1 6
8 1
7 1
2 6
8 1
7 4
8 10
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
2
3
6
4
6
7
12
7
8
9
</pre>
|
p00647 |
<h1>Problem A: It's our delight!!</h1>
<p>
You are a student of University of Aizu.
And you work part-time at a restaurant.
</p>
<p>
Staffs of the restaurant are well trained to be delighted to provide more delicious products faster.
</p>
<p>
The speed providing products particularly depends on skill of the staff.
So, the manager of the restaurant want to know how long it takes to provide products.
</p>
<p>
Though some restaurants employ a system which calculates how long it takes to provide products automatically,
the restaurant where you work employs a system which calculates it manually.
</p>
<p>
You, a student of University of Aizu, want to write a program to calculate it, and you hope that your program makes the task easier.
You are given the checks in a day.
If the length of time it takes to provide the products of a check is shorter than or equal to 8 minutes, it is "ok" check.
Write a program to output the ratio of "ok" checks to the total in percentage.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets.
The last dataset is followed by a line containing a single zero.
You don't have to process this data.
The first line of each dataset contains a single integer <i>n</i>.
<p>
<i>n</i> (0 < <i> n </i> ≤ 100) is the number of checks.
Each of following <i> n </i> lines gives the details of a check in the following format.
<pre>
<i>hh:mm MM</i>
</pre>
<p>
<i>hh:mm</i> is the clock time to print the check.
<i>MM</i> is minute of the clock time to provide products.
The clock time is expressed according to the 24 hour clock.<br>
For example, "eleven one PM" is expressed by "23:01".<br>
You can assume that the all of products are provided within fifteen minutes.
The restaurant is open from AM 11:00 to AM 02:00.
After AM 02:00, no check is printed.
Also at AM 02:00, no check is printed.
</p>
<h2>Output</h2>
<p>
Your program has to print in the following format for each dataset.
</p>
<pre>
lunch <i>L</i>
dinner <i>D</i>
midnight <i>M</i>
</pre>
<p>
<i> L </i> is ratio of "ok" check printed to the total in lunch time.
<i> D </i> is ratio of "ok" check printed to the total in dinner time.
<i> M </i> is ratio of "ok" check printed to the total in midnight time.
You can truncate digits number after the decimal point of the ratio on the percentage. Lunch, dinner, and midnight times are defined as follows:
</p>
<pre>
Lunch time is 11:00 ~ 14:59.
Dinner time is 18:00 ~ 20:59.
Midnight time is 21:00 ~ 01:59.
</pre>
<p>
If a check is not printed in the three range of time, you don't have to process it.
If no check is in the range of time, you should print "no guest".
</p>
<h2>Sample input</h2>
<pre>
5
12:57 59
20:12 15
12:19 21
18:52 03
16:09 14
0
</pre>
<h2>Sample output</h2>
<pre>
lunch 100
dinner 50
midnight no guest
</pre>
<h2>Hint</h2>
<p>
If you want to read three integers in the following format,<br>
integer:integer(space)integer<br>
you can read them by scanf("%d%*c%d%d",&a, &b, &c); in C.
</p>
<!--
<hr>
<div class="dat" style="font-size:10pt">
The University of Aizu Programming Contest 2011<br>
Problemsetter: Tetsuya Shiota<br>
</div>
--> |
p01406 |
<h2>
Problem I: ã«ã¹ã¿ã ãã€ã³ãè·äºº
</h2>
<p>
slipã¯ãšããã¬ãŒã·ã³ã°ã²ãŒã ã®åç»ã奜ãã§ããã
ãšãã£ãŠããè»ãèµ°ã£ãŠããåç»ã奜ãã§ããããã§ã¯ãªãããã®ã²ãŒã ã«æèŒãããã«ã¹ã¿ã ãã€ã³ãã«ãŒäœæãšããæ©èœã«ãã£ãŠãè»äœãã«ã¹ã¿ãã€ãºããåç»ã奜ããªã®ã§ããã
ããã¯ãåãå€è§åœ¢ãªã©ãšãã£ãåºæ¬çãªå¹ŸäœåŠå³åœ¢ãéãããããããšã§ãè»äœã«ã«ã¹ã¿ã ãã€ã³ããã§ããæ©èœã§ããã
</p>
<p>
ãã®ã«ã¹ã¿ã ãã€ã³ãã«ãã£ãŠæ§ã
ãªã¢ãŒããåµãã ããããããè·äººãšåŒã°ãã人ã
ãããã
è·äººéã®æã«ãããã°ãè»äœã«ã¬ãªã¬ãªããã¢ã€ã¹ãã£ã³ãã£ãŒã®ãã£ã©ã¯ã¿ãŒããã¢ã€ãã«ããããã¥ãŒã¹ããŠæ¥œããã²ãŒã ã®ãã£ã©ã¯ã¿ãŒãåµãã ãããšãªã©é äœããªãäºã§ããã
è·äººã®è»ã¯ããªãŒã¯ã·ã§ã³ã§é«å€ã§ååŒããããã»ã©ã§ããã
</p>
<p>
ãã®äžã§ããslipããæ°ã«å
¥ãã®è·äººãããã
ãã®è·äººã¯ãæåœ¢ã®å³åœ¢ã®ã¿ã§æ§ã
ãªã¢ãŒããåµãåºããŠããã
ãã®è·äººã¯æåœ¢ãäœæãéãããããããšã§ãèªç±èªåšã«åœ¢ãåµãåºããŠããã
</p>
<p>
ããæ¥slipã¯ãè·äººãäœãã¢ãŒãã«ãããŠãæåœ¢ãäžçªå€ãéãªã£ãŠããéšåã§äœæããã®ãæ°ã«ãªãã ããã
ããã§ãæäœæ¥ã§æ°ããããšæã£ãã®ã ããææ°ãå€ãã£ãããã«è«ŠããŠããŸã£ãã
</p>
<p>
ããã§ãåæã«åäººãšæã£ãŠããããªãã«ãããã°ã©ã ãäœã£ãŠãããããšã«ããã
ããªãã®ä»äºã¯ãäžããããæåœ¢ã®äœçœ®æ
å ±ãããæå€§äœæã®éãªããããã®ã調ã¹ãããšã§ããã
ããã§ã¯ãæåœ¢åå£«ãæ¥ããŠããå Žåãéãªã£ãŠãããã®ãšããã
</p>
<h2>
Input
</h2>
<p>
ããŒã¿ã»ããã®å
¥åã¯ä»¥äžã®åœ¢åŒã§ããã
</p>
<pre>
<i>n</i>
<i>m<sub>1</sub></i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>r<sub>1</sub></i> <i>s<sub>1</sub></i> <i>t<sub>1</sub></i>
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>r<sub>2</sub></i> <i>s<sub>2</sub></i> <i>t<sub>2</sub></i>
...
<i>x<sub>i</sub></i> <i>y<sub>i</sub></i> <i>r<sub>i</sub></i> <i>s<sub>i</sub></i> <i>t<sub>i</sub></i>
...
<i>x<sub>m<sub>1</sub></sub></i> <i>y<sub>m<sub>1</sub></sub></i> <i>r<sub>m<sub>1</sub></sub></i> <i>s<sub>m<sub>1</sub></sub></i> <i>t<sub>m<sub>1</sub></sub></i>
...
<i>m<sub>i</sub></i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>r<sub>1</sub></i> <i>s<sub>1</sub></i> <i>t<sub>1</sub></i>
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>r<sub>2</sub></i> <i>s<sub>2</sub></i> <i>t<sub>2</sub></i>
...
<i>x<sub>m<sub>i</sub></sub></i> <i>y<sub>m<sub>i</sub></sub></i> <i>r<sub>m<sub>i</sub></sub></i> <i>s<sub>m<sub>i</sub></sub></i> <i>t<sub>m<sub>i</sub></sub></i>
<i>m<sub>t</sub></i>
...
<i>x<sub>m<sub>t</sub></sub></i> <i>y<sub>m<sub>t</sub></sub></i> <i>r<sub>m<sub>t</sub></sub></i> <i>s<sub>m<sub>t</sub></sub></i> <i>t<sub>m<sub>t</sub></sub></i>
</pre>
<p>
<i>n</i>(<i>0 < n ≤ 50</i>)ã¯ãã¹ãã±ãŒã¹ã®åæ°ã
<i>m<sub>i</sub></i>(<i>0 < m<sub>i</sub> ≤ 16</i>)ã¯è²ŒãããŠããæåœ¢ã®ææ°ã
<i>x<sub>i</sub></i>(<i>0 ≤ x<sub>i</sub> ≤ 500</i>)ã¯æåœ¢ã®é ç¹ã®x座æšã
<i>y<sub>i</sub></i>(<i>0 ≤ y<sub>i</sub> ≤ 500</i>)ã¯æåœ¢ã®é ç¹ã®y座æšã
<i>r<sub>i</sub></i>(<i>0 < r<sub>i</sub> ≤ 100</i>)ã¯æåœ¢ã®ååŸã
<i>s<sub>i</sub></i>(<i>0 ≤ s<sub>i</sub> < 360</i>)ã¯æåœ¢ã®äžå¿è§ã®éå§è§åºŠ(degree)ã
<i>t<sub>i</sub></i>(<i>0 ≤ t<sub>i</sub> < 360</i>)ã¯æåœ¢ã®äžå¿è§ã®çµäºè§åºŠ(degree)
ã衚ãã
</p>
<p>
ãŸããã¹ãп޿°ã§ããã
ããã§äžããããæåœ¢ã¯å¿
ããã<i>s < t</i>ãšã¯éããªãã
<i>s < t</i>ãš<i>s > t</i>ã®å Žåã®å³ãããããå³1,2ã«è¡šãã
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I1">
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I2">
</td>
</tr>
<tr>
<td>
<center>å³1</center>
</td>
<td>
<center>å³2</center>
</td>
</tr>
</table>
</center>
<p>
ãã ãå
¥åã«ã¯å³3ã®ããã«ãç·ãšç·ããŽã£ããã«éãªãå
¥åã¯ç¡ããã®ãšããã
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I3">
</td>
</tr>
<tr>
<td>
<center>å³3</center>
</td>
</tr>
</table>
</center>
<h2>
Output
</h2>
<p>
åããŒã¿ã»ããã«å¯Ÿããæåœ¢ãéãªã£ãŠããéšåã®æå€§ææ°ã衚瀺ããã
</p>
<h2>
Sample Input
</h2>
<pre>
3
3
17 12 7 340 180
26 22 10 150 270
27 13 5 100 230
3
0 0 8 0 90
10 10 8 180 0
50 50 5 180 270
2
10 10 5 0 270
0 0 30 0 90
</pre>
<h2>
Output for Sample Input
</h2>
<pre>
3
2
2
</pre>
<h2>
Hint
</h2>
<p>
ããã§ãµã³ãã«ã®1ã€ç®ã¯å³4ã®ããã«é
眮ãããŠãã
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_I4">
</td>
</tr>
<tr>
<td>
<center>å³4</center>
</td>
</tr>
</table>
</center> |
p03591 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo is giving a present to Snuke.</p>
<p>Ringo has found out that Snuke loves <em>yakiniku</em> (a Japanese term meaning grilled meat. <em>yaki</em>: grilled, <em>niku</em>: meat). He supposes that Snuke likes grilled things starting with <code>YAKI</code> in Japanese, and does not like other things.</p>
<p>You are given a string <var>S</var> representing the Japanese name of Ringo's present to Snuke. Determine whether <var>S</var> starts with <code>YAKI</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10</var></li>
<li><var>S</var> consists of uppercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>S</var> starts with <code>YAKI</code>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>YAKINIKU
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><code>YAKINIKU</code> starts with <code>YAKI</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>TAKOYAKI
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><code>TAKOYAKI</code> (a Japanese snack. <em>tako</em>: octopus) does not start with <code>YAKI</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>YAK
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p01056 |
<h1>Lights of Apartment</h1>
<h2>Problem</h2>
<p>
ãšãŒã¡ãããšãªã«ã¡ãããšãã«ãããã¯ãã³ã·ã§ã³ã«éã³ã«æ¥ãã<br>
3人ã¯å
šãŠã®éšå±ã®é»æ°ã管çã§ããéšå±ã«å¿ã³èŸŒã¿ãããããããããšã«ããã<br><br>
ãã®ãã³ã·ã§ã³ã¯<var>n</var>åã®ç«æ¹äœã1åã«äžŠãã§ãã圢ãããŠããã<br>
åç«æ¹äœã¯è¥¿ããé ã«1蟺ã®é·ãã1ãã€å¢ããŠããŠ(1,2,3,...,<var>n</var>)ã<var>i</var>çªç®ã®ç«æ¹äœã¯<var>i</var>éãããåéã«çžŠ<var>i</var>Ãæšª<var>i</var>åã®éšå±ãããã<br>
2çªç®ä»¥éã®ç«æ¹äœã®è¥¿åŽã¯1ã€è¥¿ã®ç«æ¹äœã®æ±åŽãšæ¥ããŠããŠãå
šãŠã®ç«æ¹äœã®ååŽã¯çã£çŽããªéè·¯ã«é¢ããŠããã<br>
</p>
<br>
<left>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2015UOA_I" width="360" ><br>
</left>
<br>
<p>
åãå
šãŠã®éšå±ã«é»æ°ãã€ããŠããã<br>
3人ã¯ããããæ¬¡ã®è¡åãããã<br>
</p>
<ul>
<li>ãšãŒã¡ããã¯è¥¿ãã<var>k</var>çªç®ã®å
šãŠã®éšå±ã®é»æ°ãæ¶ããã</li>
<li>ãªã«ã¡ããã¯åãã<var>k</var>çªç®ã®å
šãŠã®éšå±ã®é»æ°ãæ¶ããã</li>
<li>ãã«ãããã¯<var>k</var>éã®å
šãŠã®éšå±ã®é»æ°ãæ¶ããã</li>
</ul>
<p>
ãã®ãããªããããã <var>m</var> åè¡ãããåŸã«é»æ°ãã€ããŠããéšå±ã®æ°ãæ±ããã
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var>
<var>q<sub>1</sub></var> <var>k<sub>1</sub></var>
...
<var>q<sub>m</sub></var> <var>k<sub>m</sub></var>
</pre>
<p>
å
¥åã¯å
šãп޿°ã§äžããããã<br>
1è¡ç®ã«ç«æ¹äœã®æ°<var>n</var>ãè¡åã®æ°<var>m</var>ãäžããããã<br>
2è¡ç®ä»¥é<var>m</var>è¡ã«è¡åãã人ã®çªå·<var>q</var>ãš<var>k</var>ãäžããããã<br><br>
<var>q<sub>i</sub></var>ã0ã®å ŽåãšãŒã¡ããã 1ã®å Žåãªã«ã¡ããã2ã®å Žåãã«ããããè¡åããããšã衚ãã
</p>
<p>
3人ã¯éšå±ããªãå Žæã®é»æ°ãæ¶ãããšããããšãããã
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>n</var>,<var>m</var> ≤ 50000</li>
<li>0 ≤ <var>q<sub>i</sub></var> ≤ 2</li>
<li>1 ≤ <var>k<sub>i</sub></var> ≤ 2Ã10<sup>9</sup></li>
<li>åãè¡åã¯äžåºŠããäžããããªã</li>
</ul>
<h2>Output</h2>
<p>
黿°ãã€ããŠããéšå±ã®æ°ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 1
0 4
</pre>
<h2>Sample Output 1</h2>
<pre>
27
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2
2 2
2 3
</pre>
<h2>Sample Output 2</h2>
<pre>
14
</pre>
|
p01543 |
<h1>ãŸããããŠ</h1>
<p>
倪éåã¯å°åŠçã§ããã©ã·ã®è£ã«èœæžããããŠããŸãã
ããæã倪éåã¯æ¬¡ã®ã²ãŒã ãæãã€ããŸããã
</p>
<ul>
<li><var>n×n</var>ã®æ Œåç¶ã®ãã¹ç®ãæžããŠãããŸãã
</li><li>ããããã®ãã¹ç®ã®åæç¶æ
ã¯ãäžžå°ãæžãããŠããããæžãããŠããªããã®ã©ã¡ããäžæ¹ã§ãã
</li><li>ãããã®äžžå°ãæ¶ãããæžãããããŠæçµçã«ã©ã®äžåãèŠãŠãå¿
ãã¡ããã©1ã€ã®ã¿ã®äžžå°ããã©ã®äžè¡ãèŠãŠãå¿
ã1ã€ã®ã¿ã®äžžå°ãååšããããã«ããããšãç®æšã§ããããã®ç¶æ
ã«ããã°ã²ãŒã ãã¯ãªã¢ããããšã«ãªããŸãã
</li></ul>
<p>
倪éåã¯ãã®ã²ãŒã ãæãã€ããŸãããã倪éåã¯ãã®ã²ãŒã ãã¯ãªã¢ããã®ã«å€§å€æéãããã£ãŠããŸããŸããããã§ã倧åŠçã§ããããªãã«å©ããæ±ããŸããã
倪éåã®å
ã§ãã倧åŠçã§ããããªãã®ä»äºã¯ä»¥äžã®éãã§ãã<br>
å³å¯ãªç¶æ³ãèããããã«ããããã¹ç®ã«äžžå°ãæžã蟌ãã³ã¹ãããããã¹ç®ã«ããäžžå°ãæ¶ãã³ã¹ããããªãã¯å°ãåºããŸããããã®ã³ã¹ããçšããŠãã®ã²ãŒã ãã¯ãªã¢ããããã«ãããæäœã®ã³ã¹ããæå°åãããããªæé ãèããã
ãã®ãšããæå°ã®ã³ã¹ãããã³ãã®ã³ã¹ããéæãããããªæé ãåºåããããã°ã©ã ãæžããŠãã ããã
åºåã«ã€ããŠã¯ãæå°ã³ã¹ããéæããæé ãªããã©ã®ãããªæäœãé çªã§ãåºåããŠããããã®ãšããã
</p>
<h2>Input</h2>
<blockquote>
<var>n</var><br><var>W<sub>11</sub></var> <var>W<sub>12</sub></var> .. <var>W<sub>1n</sub></var><br><var>W<sub>21</sub></var> <var>W<sub>22</sub></var> .. <var>W<sub>2n</sub></var><br>..<br><var>W<sub>n1</sub></var> <var>W<sub>n2</sub></var> .. <var>W<sub>nn</sub></var><br><var>E<sub>11</sub></var> <var>E<sub>12</sub></var> .. <var>E<sub>1n</sub></var><br><var>E<sub>21</sub></var> <var>E<sub>22</sub></var> .. <var>E<sub>2n</sub></var><br>..<br><var>E<sub>n1</sub></var> <var>E<sub>n2</sub></var> .. <var>E<sub>nn</sub></var><br><var>F<sub>1</sub></var>(<var>n</var>æå)<br><var>F<sub>2</sub></var>(<var>n</var>æå)<br>..<br><var>F<sub>n</sub></var>(<var>n</var>æå)<br></blockquote>
<ul>
<li><var>n</var>ã¯å€ªéåã®äœã£ããã¹ç®ãäžèŸºã«ããã€ãããã衚ã
</li><li><var>W<sub>ij</sub></var>ã¯äžãã<var>i</var>çªç®ãå·Šãã<var>j</var>çªç®ã®ãã¹ç®ã«äžžå°ãæžã蟌ãã³ã¹ãã衚ã
</li><li><var>E<sub>ij</sub></var>ã¯äžãã<var>i</var>çªç®ãå·Šãã<var>j</var>çªç®ã®ãã¹ç®ã«æžãããŠããäžžå°ãæ¶ãã³ã¹ãã衚ã
</li><li><var>F<sub>i</sub></var>ã¯äžãã<var>i</var>çªç®ã®è¡ã®ãã¹ç®ã®åæç¶æ
ã衚ã
</li><li><var>F<sub>i</sub></var>ã®å·Šãã<var>j</var>æåç®ã«ã€ããŠ
<ul>
<li>'o'ã®ãšããäžãã<var>i</var>çªç®ãå·Šãã<var>j</var>çªç®ã®ãã¹ç®ã«äžžå°ãæžãããŠããããšã衚ãã
</li><li>'.'ã®ãšããäžãã<var>i</var>çªç®ãå·Šãã<var>j</var>çªç®ã®ãã¹ç®ã空çœã§ããããšã衚ãã
</li></ul>
</li></ul>
<h2>Constraints</h2>
<blockquote>
<var>1≤ n ≤ 100</var><br><var>1≤ W<sub>ij</sub> ≤ 1000</var><br><var>1≤ E<sub>ij</sub> ≤ 1000 </var><br></blockquote>
<ul>
<li><var>F<sub>i</sub></var>ã¯æååã§ããããã®é·ãã¯<var>n</var>ã§ãã
</li><li><var>F<sub>i</sub></var>ã¯'o'ãš'.'ã®ã¿ã§æ§æãããŠãã
</li></ul>
<h2>Output</h2>
<blockquote>
<var>mincost</var><br><var>cnt</var><br><var>R<sub>1</sub></var> <var>C<sub>1</sub></var> <var>operate<sub>1</sub></var><br><var>R<sub>2</sub></var> <var>C<sub>2</sub></var> <var>operate<sub>2</sub></var><br>..<br><var>R<sub>cnt</sub></var> <var>C<sub>cnt</sub></var> <var>operate<sub>cnt</sub></var><br></blockquote>
<ul>
<li><var>mincost</var>ã¯ã倪éåã®ã²ãŒã ãã¯ãªã¢ããããã«å¿
èŠãªæå°ã³ã¹ãã衚ãã
</li><li><var>mincost</var>ã¯æžãèŸŒã¿æäœãæ¶å»æäœã§çºçããã³ã¹ãã®ç·åã§èšç®ãããã
</li><li><var>cnt</var> : <var>mincost</var>ã®ã³ã¹ããéæããæäœãè¡ã£ãåæ°ã衚ã
</li><li><var>k</var>åç®<var>(1≤k≤cnt)</var>ã«å®è¡ããæäœã¯<var>k+2</var>è¡ç®ã«èšè¿°ãã
</li><li><var>k</var>åç®<var>(1≤k≤cnt)</var>ã®æäœã«å¯ŸããŠ
<ul>
<li>äžãã<var>i</var>çªç®ã®ãã¹ç®ãå·Šãã<var>j</var>çªç®ã®ãã¹ç®ã«å¯ŸããŠè¡ã£ããã®ãšãããš
</li><li><var>R<sub>k</sub≥i , C<sub>k</sub≥j</var>ã§ããã
</li><li>ãã®æäœãäžžå°ãæ¶ãæäœã§ãããªãã°<var>operate<sub>k</sub></var> = "erase"ãšãã
</li><li>ãã®æäœãäžžå°ãæžã蟌ãæäœã§ãããªãã°<var>operate<sub>k</sub></var> = "write"ãšãã
</li><li><var>R<sub>k</sub>,C<sub>k</sub>,operate<sub>k</sub></var>ã¯äžè¡ã«ç©ºçœåºåãã§åºåããªããã°ãªããªã
</li></ul>
</li><li>äžžå°ã®æžãããŠãããã¹ç®ã«å¯ŸããŠäžžå°ãèšè¿°ããæäœãããã³äžžå°ãæžãããŠããªããã¹ç®ã«å¯ŸããŠäžžå°ãæ¶å»ããæäœãããå Žåã¯WrongAnswerã§ãã
</li><li><var>cnt</var>åã®æäœã«ãããã³ã¹ãã®ç·åã<var>mincost</var>ã«äžèŽããªããšãã¯WrongAnswerã§ãã
</li></ul>
<H2>Sample Input 1</H2>
<pre>3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
o.o
...
.o.
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>2
2
1 3 erase
2 3 write
</pre>
<p>
äžãã1çªç®ãå·Šãã3çªç®ã®ãã¹ç®ã®äžžå°ãæ¶å»ãã
äžãã2çªç®ãå·Šãã3çªç®ã®ãã¹ç®ã«äžžå°ãæžãå ããã°ç®æšã¯éæã§ããã
ãã®ãšãã³ã¹ãã¯2ã®ã¿ããããããããããæå°ã®ã³ã¹ãã§ããã
</p>
<H2>Sample Input 2</H2>
<pre>4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
oooo
oooo
oooo
oooo
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>30
12
1 1 erase
1 2 erase
1 3 erase
2 1 erase
2 2 erase
2 4 erase
3 1 erase
3 3 erase
3 4 erase
4 2 erase
4 3 erase
4 4 erase
</pre>
<p>
ã³ã¹ã(1+2+3+4)*3ã ãæ¶å»åŠçãããã°ã¯ãªã¢ãšãªããŸãã
</p>
<H2>Sample Input 3</H2>
<pre>3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
o..
.o.
..o
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>0
0
</pre>
<p>
ãã§ã«ç®æšã¯éæãããŠãããããã³ã¹ãåã³æäœåæ°ã¯ãšãã«0ãšãªãã
</p> |
p03084 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takaha-shi, the capital of Republic of AtCoder, there are <var>N</var> roads extending east and west, and <var>M</var> roads extending north and south. There are no other roads.
The <var>i</var>-th east-west road from the north and the <var>j</var>-th north-south road from the west cross at the intersection <var>(i, j)</var>.
Two east-west roads do not cross, nor do two north-south roads.
The distance between two adjacent roads in the same direction is <var>1</var>.</p>
<p>Each road is one-way; one can only walk in one direction. The permitted direction for each road is described by a string <var>S</var> of length <var>N</var> and a string <var>T</var> of length <var>M</var>, as follows:</p>
<ul>
<li>If the <var>i</var>-th character in <var>S</var> is <code>W</code>, one can only walk westward along the <var>i</var>-th east-west road from the north;</li>
<li>If the <var>i</var>-th character in <var>S</var> is <code>E</code>, one can only walk eastward along the <var>i</var>-th east-west road from the north;</li>
<li>If the <var>i</var>-th character in <var>T</var> is <code>N</code>, one can only walk northward along the <var>i</var>-th north-south road from the west;</li>
<li>If the <var>i</var>-th character in <var>T</var> is <code>S</code>, one can only walk southward along the <var>i</var>-th south-west road from the west.</li>
</ul>
<p>Process the following <var>Q</var> queries:</p>
<ul>
<li>In the <var>i</var>-th query, <var>a_i, b_i, c_i</var> and <var>d_i</var> are given. What is the minimum distance to travel to reach the intersection <var>(c_i, d_i)</var> from the intersection <var>(a_i, b_i)</var> by walking along the roads?</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100000</var></li>
<li><var>2 \leq M \leq 100000</var></li>
<li><var>2 \leq Q \leq 200000</var></li>
<li><var>|S| = N</var></li>
<li><var>S</var> consists of <code>W</code> and <code>E</code>.</li>
<li><var>|T| = M</var></li>
<li><var>T</var> consists of <code>N</code> and <code>S</code>.</li>
<li><var>1 \leq a_i \leq N</var></li>
<li><var>1 \leq b_i \leq M</var></li>
<li><var>1 \leq c_i \leq N</var></li>
<li><var>1 \leq d_i \leq M</var></li>
<li><var>(a_i, b_i) \neq (c_i, d_i)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>Q</var>
<var>S</var>
<var>T</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var>
<var>a_2</var> <var>b_2</var> <var>c_2</var> <var>d_2</var>
<var>:</var>
<var>a_Q</var> <var>b_Q</var> <var>c_Q</var> <var>d_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>In the <var>i</var>-th line, print the response to the <var>i</var>-th query. If the intersection <var>(c_i, d_i)</var> cannot be reached from the intersection <var>(a_i, b_i)</var> by walking along the roads, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5 4
EEWW
NSNNS
4 1 1 4
1 3 1 2
4 2 3 2
3 3 3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
11
5
4
</pre>
<p>The permitted direction for each road is shown in the following figure (north upward):</p>
<p><img alt="" src="https://img.atcoder.jp/exawizards2019/bfb8c54cc4098353946320d8c263807e.png"/></p>
<p>For each of the four queries, a route that achieves the minimum travel distance is as follows:</p>
<p><img alt="" src="https://img.atcoder.jp/exawizards2019/d1918596004a23a20aa138e591e0ee99.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 2
EEE
SSS
1 1 3 3
3 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
-1
</pre>
<p>The travel may be impossible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9 7 10
EEEEEWEWW
NSSSNSN
4 6 9 2
3 7 6 7
7 5 3 5
1 1 8 1
4 3 5 4
7 4 6 4
2 5 8 6
6 6 2 7
2 4 7 5
7 2 9 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
-1
4
9
2
3
7
7
6
-1
</pre></section>
</div>
</span> |
p01113 | <h3>Floating-Point Numbers</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
In this problem, we consider floating-point number formats, data representation formats to approximate real numbers on computers.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Scientific notation is a method to express a number, frequently used for
numbers too large or too small to be written tersely in usual decimal form.
In scientific notation, all numbers are written in the form
<i>m</i> × 10<sup><i>e</i></sup>.
Here, <i>m</i> (called <i>significand</i>) is a number
greater than or equal to 1 and less than 10,
and <i>e</i> (called <i>exponent</i>) is an integer.
For example, a number 13.5 is equal to 1.35 × 10<sup>1</sup>,
so we can express it in scientific notation with significand 1.35 and exponent 1.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
As binary number representation is convenient on computers,
let's consider <i>binary scientific notation</i> with base two, instead of ten.
In binary scientific notation, all numbers are written in the form
<i>m</i> × 2<sup><i>e</i></sup>.
Since the base is two, <i>m</i> is limited to be less than 2.
For example, 13.5 is equal to 1.6875 × 2<sup>3</sup>,
so we can express it in binary scientific notation
with significand 1.6875 and exponent 3.
The significand 1.6875 is equal to 1 + 1/2 + 1/8 + 1/16,
which is 1.1011<sub>2</sub> in binary notation.
Similarly, the exponent 3 can be expressed as 11<sub>2</sub> in binary notation.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A floating-point number expresses a number in binary scientific notation in finite number of bits.
Although the accuracy of the significand and the range of the exponent are limited by the number of bits, we can express numbers in a wide range with reasonably high accuracy.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
In this problem, we consider a 64-bit floating-point number format,
simplified from one actually used widely,
in which only those numbers greater than or equal to 1 can be expressed.
Here, the first 12 bits are used for the exponent and the remaining 52 bits for the significand.
Let's denote the 64 bits of a floating-point number by
<i>b</i><sub>64</sub>...<i>b</i><sub>1</sub>.
With <i>e</i> an unsigned binary integer
(<i>b</i><sub>64</sub>...<i>b</i><sub>53</sub>)<sub>2</sub>,
and with <i>m</i> a binary fraction represented by the remaining 52 bits
plus one (1.<i>b</i><sub>52</sub>...<i>b</i><sub>1</sub>)<sub>2</sub>,
the floating-point number represents the number
<i>m</i> × 2<sup><i>e</i></sup>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
We show below the bit string of the representation of 13.5 in the format described above.
</p>
<p style="text-align:center;">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_E1-en">
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
In floating-point addition operations, the results have to be approximated by numbers representable in floating-point format.
Here, we assume that the approximation is by truncation.
When the sum of two floating-point numbers <i>a</i> and <i>b</i> is expressed in binary scientific notation as
<i>a</i> + <i>b</i> = <i>m</i> × 2<sup>e</sup> (1 ≤ <i>m</i> < 2, 0 ≤ <i>e</i> < 2<sup>12</sup>),
the result of addition operation on them will be a floating-point number with its first 12 bits representing <i>e</i> as an unsigned integer
and the remaining 52 bits representing the first 52 bits of the binary fraction of <i>m</i>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A disadvantage of this approximation method is that the approximation error accumulates easily.
To verify this, let's make an experiment of adding a floating-point number many times, as in the pseudocode shown below.
Here, <i>s</i> and <i>a</i> are floating-point numbers, and the results of individual addition are approximated as described above.
</p>
<!-- end en only -->
<pre><i>s</i> := <i>a</i>
for <i>n</i> times {
<i>s</i> := <i>s</i> + <i>a</i>
}
</pre>
<!-- begin en only -->
<p>
For a given floating-point number <i>a</i> and a number of repetitions <i>n</i>,
compute the bits of the floating-point number <i>s</i> when the above pseudocode finishes.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of at most 1000 datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<p>
<i>n</i> <br>
<i>b</i><sub>52</sub>...<i>b</i><sub>1</sub> <br>
</p>
</blockquote>
<!-- begin en only -->
<p>
<i>n</i> is the number of repetitions. (1 ≤ <i>n</i> ≤ 10<sup>18</sup>)
For each <i>i</i>, <i>b</i><sub><i>i</i></sub> is either 0 or 1.
As for the floating-point number <i>a</i> in the pseudocode, the exponent is 0 and the significand is <i>b</i><sub>52</sub>...<i>b</i><sub>1</sub>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing a zero.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, the 64 bits of the floating-point number <i>s</i> after finishing the pseudocode should be output as a sequence of 64 digits, each being <tt>0</tt> or <tt>1</tt> in one line.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>1
0000000000000000000000000000000000000000000000000000
2
0000000000000000000000000000000000000000000000000000
3
0000000000000000000000000000000000000000000000000000
4
0000000000000000000000000000000000000000000000000000
7
1101000000000000000000000000000000000000000000000000
100
1100011010100001100111100101000111001001111100101011
123456789
1010101010101010101010101010101010101010101010101010
1000000000000000000
1111111111111111111111111111111111111111111111111111
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>0000000000010000000000000000000000000000000000000000000000000000
0000000000011000000000000000000000000000000000000000000000000000
0000000000100000000000000000000000000000000000000000000000000000
0000000000100100000000000000000000000000000000000000000000000000
0000000000111101000000000000000000000000000000000000000000000000
0000000001110110011010111011100001101110110010001001010101111111
0000000110111000100001110101011001000111100001010011110101011000
0000001101010000000000000000000000000000000000000000000000000000
</pre>
|
p00352 |
<H1>Handsel</H1>
<!-- New Yearâs gift money -->
<p>
Alice and Brown are brothers in a family and each receives pocket money in celebration of the coming year. They are very close and share the total amount of the money fifty-fifty. The pocket money each receives is a multiple of 1,000 yen.
</p>
<p>
Write a program to calculate each oneâs share given the amount of money Alice and Brown received.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>a</var> <var>b</var>
</pre>
<p>
A line of data is given that contains two values of money: <var>a</var> (1000 ≤ <var>a</var> ≤ 50000) for Alice and <bar>b</var> (1000 ≤ <var>b</var> ≤ 50000) for Brown.
</p>
<h2>Output</h2>
<p>
Output the amount of money each of Alice and Brown receive in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
1000 3000
</pre>
<h2>Sample Output 1</h2>
<pre>
2000
</pre>
<h2>Sample Input 2</h2>
<pre>
5000 5000
</pre>
<h2>Sample Output 2</h2>
<pre>
5000
</pre>
<h2>Sample Input 3</h2>
<pre>
1000 2000
</pre>
<h2>Sample Output 3</h2>
<pre>
1500
</pre>
|
p03987 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>One day, Snuke was given a permutation of length <var>N</var>, <var>a_1, a_2, ..., a_N</var>, from his friend.</p>
<p>Find the following:</p>
<p><img src="https://atcoder.jp/img/agc005/520049e1a049bb9810b398b35d7dcb7f.png" style="height: 50px;"/></p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠N ⊠200,000</var></li>
<li><var>(a_1, a_2, ..., a_N)</var> is a permutation of <var>(1, 2, ..., N)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
<p>Note that the answer may not fit into a 32-bit integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 3 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>19
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
5 4 8 1 2 6 7 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>85
</pre></section>
</div>
</span> |
p02695 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are positive integers <var>N</var>, <var>M</var>, <var>Q</var>, and <var>Q</var> quadruples of integers ( <var>a_i</var> , <var>b_i</var> , <var>c_i</var> , <var>d_i</var> ).</p>
<p>Consider a sequence <var>A</var> satisfying the following conditions:</p>
<ul>
<li><var>A</var> is a sequence of <var>N</var> positive integers.</li>
<li><var>1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M</var>.</li>
</ul>
<p>Let us define a score of this sequence as follows:</p>
<ul>
<li>The score is the sum of <var>d_i</var> over all indices <var>i</var> such that <var>A_{b_i} - A_{a_i} = c_i</var>. (If there is no such <var>i</var>, the score is <var>0</var>.)</li>
</ul>
<p>Find the maximum possible score of <var>A</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>2 †N †10</var></li>
<li><var>1 \leq M \leq 10</var></li>
<li><var>1 \leq Q \leq 50</var></li>
<li><var>1 \leq a_i < b_i \leq N</var> ( <var>i = 1, 2, ..., Q</var> )</li>
<li><var>0 \leq c_i \leq M - 1</var> ( <var>i = 1, 2, ..., Q</var> )</li>
<li><var>(a_i, b_i, c_i) \neq (a_j, b_j, c_j)</var> (where <var>i \neq j</var>)</li>
<li><var>1 \leq d_i \leq 10^5</var> ( <var>i = 1, 2, ..., Q</var> )</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>Q</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var>
<var>:</var>
<var>a_Q</var> <var>b_Q</var> <var>c_Q</var> <var>d_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible score of <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>110
</pre>
<p>When <var>A = \{1, 3, 4\}</var>, its score is <var>110</var>. Under these conditions, no sequence has a score greater than <var>110</var>, so the answer is <var>110</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>357500
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10 1
1 10 9 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p01810 |
<h2>ç£ç</h2>
<p>ç¡é人ã®å人ãã¡ããããã¯ãããå人ãã¡ã¯ <var>0, 1, 2,</var> ... ãšçªå·ãæ¯ãããŠããã</p>
<p>æ¬¡ã®æäœã <var>N</var> åè¡ãã</p>
<ul>
<li><var>0</var> çªç®ã®å人ãéæŸãã<var>k, 2k, 3k,</var> ... çªç®ã®å人ãã¡ãåŠåããã</li>
<li>ãã®åŸãæ®ã£ãå人ãã¡ã«çªå·ãæ¯ãçŽãããã®ãšããå
ã®çªå·ãå°ããå人ããé ã« <var>0, 1, 2, </var> ... ãšçªå·ãæ¯ãã</li>
</ul>
<p><var>N</var> åç®ã®æäœã§éæŸãããå人ãã¯ããã«æ¯ãããŠããçªå·ãæ±ããã</p>
<h3>Constraints</h3>
<ul>
<li><var>1</var> ≤ <var>N</var> ≤ <var>10^5</var></li>
<li><var>2</var> ≤ <var>k</var> ≤ <var>10^5</var></li>
<li>çã㯠<var>10^{18}</var> 以äžã§ããã</li>
</ul>
<h3>Input Format</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
<var>N</var> <var>k</var>
</pre>
<h3>Output Format</h3>
<p>çããäžè¡ã«åºåããã</p>
<h3>Sample Input 1</h3>
<pre>
4 2
</pre>
</section>
<h3>Sample Output 1</h3>
<pre>
7
</pre>
<h3>Sample Input 2</h3>
<pre>
1 3
</pre>
<h3>Sample Output 2</h3>
<pre>
0
</pre>
<h3>Sample Input 3</h3>
<pre>
100000 100000
</pre>
<h3>Sample Output 3</h3>
<pre>
99999
</pre> |
p00702 |
<h1>
Kanglish : Analysis on Artificial Language
</h1>
<p>The late Prof. Kanazawa made an artificial language named Kanglish, which is
similar to English, for studying mythology. Words and sentences of Kanglish are
written with its own special characters called "Kan-characters". The size of the
set of the Kan-characters is 38, i.e., there are 38 different Kan-characters in
the set. Since Kan-characters cannot be directly stored in a computer because of
the lack of a coded character set, Prof. Kanazawa devised a way to represent
each Kan-character as an alphabetical letter or an ordered combination of two
alphabetical letters. Thus, each Kan-character is represented as one of the
following 26 letters
</p><blockquote>"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", and "z",
</blockquote>or one of the following 12 combinations of letters
<blockquote>"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw",
and "ts". </blockquote>
<p>
In addition, the Kan-characters are ordered according to
the above alphabetical representation. The order is named Kan-order in which the
Kan-character represented by "a" is the first one, that by "b" is the second,
that by "z" is the 26th, that by "ld" is the 27th, and that by "ts" is the 38th
(the last).
</p>
<p></p>
<p>The representations of words in Kanglish are separated by spaces. Each
sentence is written in one line, so there are no periods or full stops in
Kanglish. All alphabetical letters are in lower case, i.e., there are no
capitalizations. </p>
<p>We currently have many documents written in Kanglish with the alphabetical
representation. However, we have lost most of Prof. Kanazawa's work on how they
can be translated. To recognize his work, we have decided to first analyze them
statistically. The first analysis is to check sequences of consecutive
Kan-characters in words. </p>
<p>For example, a substring "ic" in a word "quice" indicates an ordered pair of
two adjacent Kan-characters that are represented by "i" and "c". For simplicity,
we make a rule that, in the alphabetical representation of a word, a
Kan-character is recognized as the longest possible alphabetical representation
from left to right. Thus, a substring "ncw" should be considered as a pair of
"nc" and "w". It does not consist of "n" and "cw", nor "n", "c", and "w". </p>
<p>For each Kan-character, there are 38 possible pairs of that Kan-character and
another Kan-character, e.g. "aa", "ab", ..., "az", "ald", ..., "ats". Thus,
mathematically, there is a total of 1444 (i.e., 38x38) possible pairs, including
pairs such as "n" and "cw", which is actually not allowed according to the above
rule. </p>
<p>Your job is to write a program that counts how many times each pair occurs in
input data. For example, in the sentence </p><pre> qua ist qda quang quice</pre>
<p>
the Kan-character represented by "qu" appears
three times. There are two occurrences of the pair of "qu" and "a", and one
occurrence of the pair of "qu" and "i". Note that the alphabetical letter "q"
appears four times in the example sentence, but the Kan-character represented by
"q" occurs only once, because "qu" represents another Kan-character that is
different from the Kan-character represented by "q".
<p></p>
<p>For simplicity, a newline at the end of a line is considered as a space. Thus
in the above example, "e" is followed by a space. </p>
<h2>Input</h2><pre><i>n</i>
<i>line</i><sub>1</sub>
<i>line</i><sub>2</sub>
...
<i>line</i><sub><i>n</i></sub>
</pre>
<p>The first line of the input is an integer <i>n</i>, which indicates the
number of lines that follow. Each line except for the first line represents one
Kanglish sentence. You may assume that <i>n</i> <= 1000 and that each line
has at most 59 alphabetical letters including spaces. </p>
<h2>Output</h2><pre>a <i>kc</i><sub>1</sub> <i>m</i><sub>1</sub>
b <i>kc</i><sub>2</sub> <i>m</i><sub>2</sub>
c <i>kc</i><sub>3</sub> <i>m</i><sub>3</sub>
...
ts <i>kc</i><sub>38</sub> <i>m</i><sub>38</sub>
</pre>
<p>The output consists of 38 lines for the whole input lines. Each line of the
output has two strings and an integer. In the <i>i</i>-th line in the output,
the first string is the alphabetical representation of the <i>i</i>-th
Kan-character in the Kan-order. For example, the first string of the first line
is "a", that of the third line is "c", and that of the 37th line is "cw". The
first string is followed by a space. </p>
<p>The second string in the <i>i</i>-th line (denoted by <i>kc<sub>i</sub></i>
above) shows the alphabetical representation of a Kan-character that most often
occurred directly after the first Kan-character. If there are two or more such
Kan-characters, the first one in the Kan-order should be printed. The second
string is followed by a space. </p>
<p>The integer (denoted by <i>m<sub>i</sub></i> above) in the <i>i</i>-th line
shows the number of times that the second Kan-character occurred directly after
the first Kan-character. In other words, the integer shows the number of times
that ``the ordered pair of the first Kan-character and the second
Kan-character'' appeared in the input. The integer is followed by a newline.
</p>
<p>Suppose the 28th output line is as follows:
</p><blockquote><pre>mb e 4</pre></blockquote>
<p>
"mb" is output because it is the 28th character in
the Kanglish alphabet. "e 4" means that the pair "mbe" appeared 4 times in the
input, and that there were no pairs beginning with "mb" that appeared more than
4 times.
<p></p>
<p>Note that if the <i>i</i>-th Kan-character does not appear in the input, or
if the <i>i</i>-th Kan-character is not followed by any other Kan-characters but
spaces, the second string in the <i>i</i>-th output line should be "a" and the
third item should be zero. </p>
<p>Although the output does not include spaces, Kan-characters that appear with
a space in-between is not considered as a pair. Thus, in the following example
</p><blockquote><pre>abc def</pre></blockquote>
<p>
"d" is not counted as occurring after "c".
<p></p>
<h2>Sample Input</h2>
<pre>
3
nai tiruvantel ar varyuvantel i valar tielyama nu vilya
qua ist qda quang ncw psts
svampti tsuldya jay quadal ciszeriol
</pre>
<h2>Output for the Sample Input</h2>
<pre>
a r 3
b a 0
c i 1
d a 2
e l 3
f a 0
g a 0
h a 0
i s 2
j a 1
k a 0
l y 2
m a 1
n a 1
o l 1
p a 0
q d 1
r i 1
s t 1
t i 3
u v 2
v a 5
w a 0
x a 0
y a 3
z e 1
ld y 1
mb a 0
mp t 1
nc w 1
nd a 0
ng a 0
nt e 2
nw a 0
ps ts 1
qu a 3
cw a 0
ts u 1
</pre>
|
p00597 |
<H1><font color="#000000">Problem C:</font> Finding the Largest Carbon Compound Given Its Longest Chain</H1>
<p>
An bydrocarbon is an organic compound which contains only carbons and hydrogens. An isomer is a compound that has the same number of carbons but different structures. Heptane, for example, is a hydrocarbon with 7 carbons. It has nine isomers. The structural formula of three are shown in Figure 1. Carbons are represented by the letter C, and bonds between carbons are represented by a straight line. In all figures, hydrogens are not represented for simplicity. Each carbon can be connected to a maximum of 4 carbons.
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_longestchain1"></td></tr>
</table>
<table>
<tr><td>Figure 1: These three examples of isomers of heptane have the same number of carbons but different structures.</td></tr>
</table>
</center>
<br/>
<p>
Let define a chain in an isomer as a sequence of connected carbons without branches. An isomer can have many chains of the same length. Figure 2 shows the longest chain of carbons for each of the represented isomer. Note that there can be many instances of longest chain in an isomer.
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_longestchain2"></td></tr>
</table>
<table>
<tr><td>Figure 2: The figures shows one instance of longest chain of carbons in each isomer. The first and the second isomers show longest chains of 5 carbons. The longest chain in the third isomer has 4 carbons.</td></tr>
</table>
</center>
<br/>
<p>
Your task is to identify the number of carbons of the largest possible carbon compound whose longest carbon chain has <i>n</i> (1 ≤ <i>n</i> ≤ 30) carbons.
</p>
<H2>Input</H2>
<p>
Each input contains a list of number of carbons, i.e. the length of a carbon chain.
</p>
<p>
The number of input lines is less than or equal to 30.
</p>
<H2>Output</H2>
<p>
For each number n in input, identify the number of carbons of the largest possible carbon compound whose longest carbon chain has n carbons.
</p>
<H2>Sample Input</H2>
<pre>
1
4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
8
</pre> |
p02050 | <h3>Kã¯å€è§åœ¢ã®ã±ã€</h3>
<!-- begin ja only -->
<p>ã<i>1</i> çªãããªãããã¡ã§ããïŒ<i>K</i> çªãããã¡ãªãã§ããããïŒã</p>
<p>ãããã±ã€æ°ã®åº§å³ã®éã§ããïŒæè¿ã±ã€æ°ã¯ãã£ã±ãå€è§åœ¢ã«èå³ãããããã§ïŒç®ã®åã«åºããåºå€§ãªäºæ¬¡å
å¹³é¢äžã«çœ®ããã <i>N</i> åã®ç¹ãèŠãŠïŒããããå€è§åœ¢ã圢æããæ¹æ³ã«ã€ããŠæãã銳ããŠããïŒã±ã€æ°ã¯ã©ãããïŒãã® <i>N</i> åã®ç¹ã®ãã¡ããã€ãã®ç¹ãéžãã§èªç±ãªé çªã§ç¹ããããšã§ïŒéžãã ç¹ãé ç¹ãšããå€è§åœ¢ãæ§æããããšã«ããããã ïŒãã ãïŒå€è§åœ¢ã¯ä»¥äžã®æ¡ä»¶ãæºããå¿
èŠãããïŒ</p>
<ul>
<li>åçŽå€è§åœ¢ã§ããïŒããªãã¡ïŒ3 ã€ä»¥äžã®é ç¹ãæã¡ïŒé£ç¶ããªãä»»æã® 2 蟺ã亀ç¹ãæããªãïŒ</li>
<li>éžã°ããç¹ä»¥å€ãå«ã <i>N</i> åãã¹ãŠã®ç¹ããã®å
éšïŒãŸãã¯åšäžã«å«ãïŒ</li>
</ul>
<p>ã±ã€æ°ã¯å·±ã®ä¿¡å¿µã«åŸã£ãŠïŒãã®ãããªå€è§åœ¢ã®ãã¡ïŒåšé·ïŒããªãã¡å
šãŠã®èŸºã®é·ãã®åã <i>K</i> çªç®ã«çãå€è§åœ¢ãæžæããŠããïŒ</p>
<p>ããªãã®ä»äºã¯ïŒã±ã€æ°ãæäŒãããïŒæ¡ä»¶ãæºããå€è§åœ¢ã®ãã¡ïŒåšé·ã®æé ã«äžŠã¹ããšãã« <i>K</i> çªç®ãšãªãå€è§åœ¢ãæ±ãïŒãã®åšé·ãåºåããããã°ã©ã ãæžãããšã ïŒãã ãïŒãã®ãããªå€è§åœ¢ã <i>K</i> å以äžååšããªãããšãããïŒãã®ãããªãšãã«ã¯ã±ã€æ°ã®ç¡å¿µã®æ°æã¡ãæ
®ãã€ã€ïŒç³ãèš³ãªãæ°æã¡ã蟌ããªãã <i>-1</i> ãšåºåããå¿
èŠãããïŒ</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>N</i> <i>K</i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i>
...
<i>x<sub>N</sub></i> <i>y<sub>N</sub></i></blockquote>
<p>ããŒã¿ã»ããã®1è¡ç®ã«ã¯äºæ¬¡å
å¹³é¢äžã®ç¹ã®æ° <i>N</i> ãšæ±ããåšé·ã®é äœ <i>K</i> ãäžããããïŒ <i>N</i>, <i>K</i> ã¯ãšãã«æŽæ°ã§ããïŒ<i>3 ≤ N ≤ 25</i>, <i>1 ≤ K ≤ 10</i> ãæãç«ã€ïŒç¶ã <i>N</i> è¡ã§ã¯åç¹ã®äºæ¬¡å
å¹³é¢äžã®åº§æšãäžããããïŒ<i>N</i> è¡ã®ãã¡ <i>i</i> è¡ç®ã«ã¯ <i>i</i> çªç®ã®ç¹ã® <i>x</i> åº§æš <i>x<sub>i</sub></i> ãš <i>y</i> åº§æš <i>y<sub>i</sub></i> ããšãã«æŽæ°ã§äžãããïŒãã¹ãŠã® <i>1 ≤ i ≤ N</i> ã«ã€ã㊠<i>-100 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 100</i> ãæãç«ã€ïŒã©ã®çžç°ãªã 3 ç¹ãéžãã§ãïŒãã® 3 ç¹ãã¹ãŠãéããããªçŽç·ã¯ååšããªããšä»®å®ããŠããïŒãŸãïŒå
¥åã«ãããŠïŒåšé·ã®æé ã«äžŠã¹ããšãã« <i>K</i> çªç®ãšãªãïŒå顿äžã«è¿°ã¹ãæ¡ä»¶ãæºããå€è§åœ¢ã¯ïŒååšãããªãã°äžæã«å®ãŸããšä»®å®ããŠããïŒ</p>
<p>å
¥åã®çµããã¯ïŒ2 åã®ãŒãã ããããªãè¡ã§è¡šãããïŒ å
šããŒã¿ã»ããã®ç·æ°ã¯ 50 ãè¶
ããªãïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>äžããããç¹éåããããã€ãã®ç¹ãéžã³åçŽå€è§åœ¢ãäœããšãïŒæ§æå¯èœãªåçŽå€è§åœ¢ã®ãã¡ <i>K</i> çªç®ã«åšé·ãçãå€è§åœ¢ã®åšé·ã 1 è¡ã«åºåããïŒãã®ãããªå€è§åœ¢ãååšããªãå Žå㯠-1 ãåºåããïŒçµæã¯ <i>10<sup>-4</sup></i> 以äžã®èª€å·®ãå«ãã§ã¯ãããªãïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>5 2
1 1
1 4
2 2
3 1
3 5
3 1
0 2
1 0
-1 0
3 2
0 2
1 0
-1 0
9 10
8 1
9 19
2 10
1 1
4 17
7 13
3 4
6 13
9 21
0 0
</pre><h3>Output for the Sample Input</h3><pre>11.812559200041266
6.472135954999580
-1
52.202878812480016
</pre>
|
p02400 | <H1>Circle</H1>
<p>
Write a program which calculates the area and circumference of a circle for given radius <var>r</var>.
</p>
<H2>Input</H2>
<p>
A real number <var>r</var> is given.
</p>
<H2>Output</H2>
<p>
Print the area and circumference of the circle in a line. Put a single space between them. The output should not contain an absolute error greater than 10<sup>-5</sup>.
</p>
<h2>Constraints</h2>
<ul>
<li> 0 < <var>r</var> < 10000</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
2
</pre>
<H2>Sample Output 1</H2>
<pre>
12.566371 12.566371
</pre>
<H2>Sample Input 2</H2>
<pre>
3
</pre>
<H2>Sample Output 2</H2>
<pre>
28.274334 18.849556
</pre>
|
p01386 |
<div>
<h1 class="title">åé¡ K : å·¡åã»ãŒã«ã¹ãã³åé¡</h1>
<p>2011 幎ã®ãã®é ïŒãŸã ããã°ã©ãã³ã°ã³ã³ãã¹ãã¯ãšãŠãå¹³åã§ããïŒ
æã
ã¯ã«ãŒã«ã粟èªããã«æ°è»œã«ã³ã³ãã¹ãã«åå ããŠããïŒ
ãããïŒããã« Gââgle ã®é°è¬ã¯è¿«ã£ãŠããïŒ
ããæ¥ïŒGââgle ã«ãã£ãŠç§å¯è£ã«è²·åãããŠãã TâpCâder ã®ã³ã³ãã¹ãã¯ïŒ
人ç¥ãããã¡ã«ã«ãŒã«ãæ¹å€ãããŠããïŒåœããã®ããã°ã©ãã³ã°ã³ã³ãã¹ããšãªã£ãŠããïŒ
ãããŠåã¯ïŒããã§ïŒäœãç¥ããïŒ
ãŸã£å
ã« kita_masa ã®ããã°ã©ã ã®ãªãŒããŒãããŒãçªããã®ã âŠïŒ</p>
<dl class="docutils">
<dt>(iwi)</dt>
<dd>ãããâŠããâŠã</dd>
<dt>wata</dt>
<dd>ãä»ããã¹ãããšã¯èªåãæ»ããããšã§ã¯ãªãïŒãã£ã³ã¹ãç¡é§ã«ããæ°ãïŒã</dd>
</dl>
<p>âŠããããã°ïŒä»ããã€ã¯ïŒéšå±ã«å±
ãå
šãŠã®äººéãäžç¬ã«ããŠåããŠããïŒ
ã©ããªã£ãŠãããã ïŒ</p>
<dl class="docutils">
<dt>wata</dt>
<dd>ããŸãïŒç¥ã£ãŠãããããããªããïŒ Gââgle 㯠NP å®å
šåé¡ãå«ãå€ãã®èšç®å°é£ãšèšãããŠããåé¡ã«å¯Ÿããå€é
åŒæéã®å¹ççãªã¢ã«ãŽãªãºã ãæã£ãŠããïŒP vs NP åé¡ã解決ãããïŒæ¢ããŠãããç§å¿ããããšã«ãã£ãŠãããŸã§æé·ããã®ã ïŒã</dd>
<dt>(iwi)</dt>
<dd>ãããããšã¯æã£ãŠãããïŒãã¯ããâŠïŒ ãããïŒãåã¯ä»ïŒGââgle ã®äººéãäžç¬ã«ããŠåããïŒããããåãâŠïŒã</dd>
<dt>wata</dt>
<dd>ãæ®å¿µãªããéãïŒãããâŠãåãªãïŒåããã¯ãã ããïŒã</dd>
</dl>
<p>âŠãªãã»ã©!! ããããããšãïŒ
圌ã¯å€§åŠæä»£ïŒææ°æéã®ã¢ã«ãŽãªãºã ãé«éã«ããããšã«èå³ãæã£ãŠããïŒ
äŸãææ°æéã§ãã£ãŠãïŒææ°ã®åºã極ããŠå°ãããã°ïŒ
çŸå®çãªã€ã³ã¹ã¿ã³ã¹ã«å¯ŸããŠååã«é«éãªå¯èœæ§ãããïŒ</p>
<dl class="docutils">
<dt>wata</dt>
<dd>ãããããããšã ïŒäŸãã°ïŒä»åã¯ïŒå·¡åã»ãŒã«ã¹ãã³åé¡ã® <span style="font-size:110%;font-family:times new roman;"><i>O</i><sup>*</sup>(1.0001<sup><i>n</i></sup>)</span> æéã®ã¢ã«ãŽãªãºã ã宿ãããããšããŠããïŒã</dd>
</dl>
<p>åãŸããïŒæ³å以äžã âŠïŒ</p>
<dl class="docutils">
<dt>wata</dt>
<dd>ã宿ãããã«ããã£ãŠïŒã°ã©ãã¢ã«ãŽãªãºã ã«è©³ãããåã®åãå¿
èŠã ïŒ æã貞ããŠããããªïŒã</dd>
<dt>(iwi)</dt>
<dd>ãããïŒå¿è«ã ïŒãŸããã!!ã</dd>
</dl>
<div>
<h1>åé¡</h1>
<p>ã°ã©ããäžããããïŒ
ã°ã©ãã¯<span style="font-size:110%;font-family:times new roman;"><i>N</i></span> åã®é ç¹ãæã¡ïŒé ç¹ã«ã¯ <span style="font-size:110%;font-family:times new roman;">1</span> ãã <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> ã®çªå·ãä»ããŠããïŒ
ãŸãïŒã°ã©ã㯠<span style="font-size:110%;font-family:times new roman;"><i>M</i></span> åã®èŸºãæã¡ïŒèŸºã¯æå (äžæ¹éè¡) ã§ïŒ
ããããè·é¢ã決ãŸã£ãŠããïŒ</p>
<p>é ç¹ <span style="font-size:110%;font-family:times new roman;">1</span> ããåºçºãïŒé ç¹ <span style="font-size:110%;font-family:times new roman;">2, 3, âŠ, <i>N</i></span> ããã®é çªã«èšªãïŒé ç¹ <span style="font-size:110%;font-family:times new roman;">1</span> ãžæ»ãçµè·¯ãèããïŒ
ããã§ïŒããã®é çªã«èšªããããšããã®ã¯ïŒçµè·¯ã«å«ãŸããé ç¹ã®éšååã«
<span style="font-size:110%;font-family:times new roman;">2, 3, âŠ, <i>N</i></span> ãå«ãŸãããšããããšã§ããïŒ
ã€ãŸãïŒã¹ã¿ãŒãå°ç¹ã®é ç¹ <span style="font-size:110%;font-family:times new roman;">1</span> ããé ç¹ <span style="font-size:110%;font-family:times new roman;">2</span> ãžã®ç§»åã¯ïŒ
çŽæ¥ã®ç§»åã§ãã£ãŠãïŒä»ã®é ç¹ãçµç±ããç§»åã§ãã£ãŠãããïŒ
次ã®é ç¹ <span style="font-size:110%;font-family:times new roman;">2</span> ããé ç¹ <span style="font-size:110%;font-family:times new roman;">3</span>ãžã®ç§»åïŒ
ããã«ãã®æ¬¡ã®é ç¹ <span style="font-size:110%;font-family:times new roman;">3</span> ããé ç¹ <span style="font-size:110%;font-family:times new roman;">4</span>ãžã®ç§»åçã«é¢ããŠãåæ§ã§ããïŒ
åãé ç¹ãåã蟺ã 2 床éã£ãŠãæ§ããªãïŒ</p>
<p>ã°ã©ããäžããããæïŒ
é ç¹ <span style="font-size:110%;font-family:times new roman;">1</span> ããåºçºãé ç¹ <span style="font-size:110%;font-family:times new roman;">2, 3, âŠ, <i>N</i></span> ããã®é çªã«èšªãé ç¹ <span style="font-size:110%;font-family:times new roman;">1</span> ãžæ»ãçµè·¯ã®ãã¡ïŒ
æçã®ãã®ã®é·ããåºåããããã°ã©ã ãäœæããïŒ
çµè·¯ã®é·ããšã¯ïŒçµè·¯ã«å«ãŸãã蟺ã®è·é¢ã®åã§ããïŒ
è€æ°åå«ãŸãã蟺ã«é¢ããŠã¯ïŒå«ãŸããåæ°ã®åã ãè·é¢ãå ããïŒ</p>
</div>
<div>
<h1>å
¥å</h1>
<p>å
¥åã®æåã®è¡ã¯ 2 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>N</i>, <i>M</i></span> ãå«ãïŒ
ããã¯ïŒã°ã©ãã®é ç¹æ°ãšèŸºæ°ã衚ãïŒ</p>
<p>ç¶ã <span style="font-size:110%;font-family:times new roman;"><i>M</i></span> è¡ã¯ïŒèŸºã®æ
å ±ã衚ãïŒ
ãããã®è¡ã®ãã¡ã® <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> è¡ç®ã¯ 3 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub>, <i>b</i><sub><i>i</i></sub>, <i>c</i><sub><i>i</i></sub></span> ãæžãããŠããïŒ
蟺 <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> ã¯é ç¹ <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub></span> ããé ç¹ <span style="font-size:110%;font-family:times new roman;"><i>b</i><sub><i>i</i></sub></span> ãçµã³ïŒãã®è·é¢ã¯ <span style="font-size:110%;font-family:times new roman;"><i>c</i><sub><i>i</i></sub></span> ã§ããããšã衚ãïŒ</p>
</div>
<div>
<h1>åºå</h1>
<p>æ¡ä»¶ãæºããçµè·¯ã®ãã¡æçã®ãã®ã®é·ããåºåããïŒ
ãã ãïŒæ¡ä»¶ãæºããçµè·¯ãååšããªãå Žåã¯ïŒ-1 ãåºåããïŒ</p>
</div>
<div>
<h1>å¶çŽ</h1>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">2 ≤ <i>N</i> ≤ 10<sup>5</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">0 ≤ <i>M</i> ≤ <i>N</i> + 500</span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>a</i><sub><i>i</i></sub>, <i>b</i><sub><i>i</i></sub> ≤ <i>N</i></span>ïŒ<span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub> ≠ <i>b</i><sub><i>i</i></sub></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>c</i><sub><i>i</i></sub> ≤ 10<sup>3</sup></span></li>
</ul>
</div>
<div>
<h1>å
¥åºåäŸ</h1>
<div>
<h2>å
¥åºåäŸ 1</h2>
<p>å
¥åäŸ 1:</p>
<pre class="literal-block">
5 5
1 2 10
2 3 20
3 4 30
4 5 40
5 1 50
</pre>
<p>å
¥åäŸ 1 ã«å¯Ÿããåºåã®äŸ:</p>
<pre class="literal-block">
150
</pre>
</div>
<div>
<h2>å
¥åºåäŸ 2</h2>
<p>å
¥åäŸ 2:</p>
<pre class="literal-block">
5 5
1 5 10
5 4 20
4 3 30
3 2 40
2 1 50
</pre>
<p>å
¥åäŸ 2 ã«å¯Ÿããåºåã®äŸ:</p>
<pre class="literal-block">
600
</pre>
</div>
</div>
</div>
|
p02953 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares arranged in a row from left to right. The height of the <var>i</var>-th square from the left is <var>H_i</var>.</p>
<p>For each square, you will perform either of the following operations once:</p>
<ul>
<li>Decrease the height of the square by <var>1</var>.</li>
<li>Do nothing.</li>
</ul>
<p>Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq H_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2 1 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>You can achieve the objective by decreasing the height of only the second square from the left by <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre></section>
</div>
</span> |
p03641 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>N</var> be a positive even number.</p>
<p>We have a permutation of <var>(1, 2, ..., N)</var>, <var>p = (p_1, p_2, ..., p_N)</var>.
Snuke is constructing another permutation of <var>(1, 2, ..., N)</var>, <var>q</var>, following the procedure below.</p>
<p>First, let <var>q</var> be an empty sequence.
Then, perform the following operation until <var>p</var> becomes empty:</p>
<ul>
<li>Select two adjacent elements in <var>p</var>, and call them <var>x</var> and <var>y</var> in order. Remove <var>x</var> and <var>y</var> from <var>p</var> (reducing the length of <var>p</var> by <var>2</var>), and insert <var>x</var> and <var>y</var>, preserving the original order, at the beginning of <var>q</var>.</li>
</ul>
<p>When <var>p</var> becomes empty, <var>q</var> will be a permutation of <var>(1, 2, ..., N)</var>.</p>
<p>Find the lexicographically smallest permutation that can be obtained as <var>q</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an even number.</li>
<li><var>2 †N †2 à 10^5</var></li>
<li><var>p</var> is a permutation of <var>(1, 2, ..., N)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest permutation, with spaces in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 2 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 1 2 4
</pre>
<p>The solution above is obtained as follows:</p>
<table>
<thead>
<tr>
<th align="center"><var>p</var></th>
<th align="center"><var>q</var></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><var>(3, 2, 4, 1)</var></td>
<td align="center"><var>()</var></td>
</tr>
<tr>
<td align="center">â</td>
<td align="center">â</td>
</tr>
<tr>
<td align="center"><var>(3, 1)</var></td>
<td align="center"><var>(2, 4)</var></td>
</tr>
<tr>
<td align="center">â</td>
<td align="center">â</td>
</tr>
<tr>
<td align="center"><var>()</var></td>
<td align="center"><var>(3, 1, 2, 4)</var></td>
</tr>
</tbody>
</table>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
4 6 3 2 8 5 7 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3 1 2 7 4 6 8 5
</pre>
<p>The solution above is obtained as follows:</p>
<table>
<thead>
<tr>
<th align="center"><var>p</var></th>
<th align="center"><var>q</var></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><var>(4, 6, 3, 2, 8, 5, 7, 1)</var></td>
<td align="center"><var>()</var></td>
</tr>
<tr>
<td align="center">â</td>
<td align="center">â</td>
</tr>
<tr>
<td align="center"><var>(4, 6, 3, 2, 7, 1)</var></td>
<td align="center"><var>(8, 5)</var></td>
</tr>
<tr>
<td align="center">â</td>
<td align="center">â</td>
</tr>
<tr>
<td align="center"><var>(3, 2, 7, 1)</var></td>
<td align="center"><var>(4, 6, 8, 5)</var></td>
</tr>
<tr>
<td align="center">â</td>
<td align="center">â</td>
</tr>
<tr>
<td align="center"><var>(3, 1)</var></td>
<td align="center"><var>(2, 7, 4, 6, 8, 5)</var></td>
</tr>
<tr>
<td align="center">â</td>
<td align="center">â</td>
</tr>
<tr>
<td align="center"><var>()</var></td>
<td align="center"><var>(3, 1, 2, 7, 4, 6, 8, 5)</var></td>
</tr>
</tbody>
</table></section>
</div>
</span> |
p03211 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a string <var>S</var> consisting of digits <code>1</code>, <code>2</code>, <var>...</var>, <code>9</code>.
Lunlun, the Dachshund, will take out three consecutive digits from <var>S</var>, treat them as a single integer <var>X</var> and bring it to her master. (She cannot rearrange the digits.)</p>
<p>The master's favorite number is <var>753</var>. The closer to this number, the better.
What is the minimum possible (absolute) difference between <var>X</var> and <var>753</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is a string of length between <var>4</var> and <var>10</var> (inclusive).</li>
<li>Each character in <var>S</var> is <code>1</code>, <code>2</code>, <var>...</var>, or <code>9</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible difference between <var>X</var> and <var>753</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1234567876
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>34
</pre>
<p>Taking out the seventh to ninth characters results in <var>X = 787</var>, and the difference between this and <var>753</var> is <var>787 - 753 = 34</var>. The difference cannot be made smaller, no matter where <var>X</var> is taken from.</p>
<p>Note that the digits cannot be rearranged. For example, taking out <code>567</code> and rearranging it to <code>765</code> is not allowed.</p>
<p>We cannot take out three digits that are not consecutive from <var>S</var>, either. For example, taking out the seventh digit <code>7</code>, the ninth digit <code>7</code> and the tenth digit <code>6</code> to obtain <code>776</code> is not allowed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>35753
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If <code>753</code> itself can be taken out, the answer is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1111111111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>642
</pre>
<p>No matter where <var>X</var> is taken from, <var>X = 111</var>, with the difference <var>753 - 111 = 642</var>.</p></section>
</div>
</span> |
p02816 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are two sequences <var>a=\{a_0,\ldots,a_{N-1}\}</var> and <var>b=\{b_0,\ldots,b_{N-1}\}</var> of <var>N</var> non-negative integers each.</p>
<p>Snuke will choose an integer <var>k</var> such that <var>0 \leq k < N</var> and an integer <var>x</var> not less than <var>0</var>, to make a new sequence of length <var>N</var>, <var>a'=\{a_0',\ldots,a_{N-1}'\}</var>, as follows:</p>
<ul>
<li><var>a_i'= a_{i+k \mod N}\ XOR \ x</var></li>
</ul>
<p>Find all pairs <var>(k,x)</var> such that <var>a'</var> will be equal to <var>b</var>.</p>
<details>
<summary>What is <var>\mbox{ XOR }</var>?</summary>
<p>
The XOR of integers <var>A</var> and <var>B</var>, <var>A \mbox{ XOR } B</var>, is defined as follows:
<ul>
<li>When <var>A \mbox{ XOR } B</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if either <var>A</var> or <var>B</var>, but not both, has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> otherwise.</li>
</ul>
For example, <var>3 \mbox{ XOR } 5 = 6</var>. (In base two: <var>011 \mbox{ XOR } 101 = 110</var>.)
</p>
</details>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>0 \leq a_i,b_i < 2^{30}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_0</var> <var>a_1</var> <var>...</var> <var>a_{N-1}</var>
<var>b_0</var> <var>b_1</var> <var>...</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print all pairs <var>(k, x)</var> such that <var>a'</var> and <var>b</var> will be equal, using one line for each pair, in ascending order of <var>k</var> (ascending order of <var>x</var> for pairs with the same <var>k</var>).</p>
<p>If there are no such pairs, the output should be empty.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 2 1
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 3
</pre>
<p>If <var>(k,x)=(1,3)</var>,</p>
<ul>
<li>
<p><var>a_0'=(a_1\ XOR \ 3)=1</var></p>
</li>
<li>
<p><var>a_1'=(a_2\ XOR \ 3)=2</var></p>
</li>
<li>
<p><var>a_2'=(a_0\ XOR \ 3)=3</var></p>
</li>
</ul>
<p>and we have <var>a' = b</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 0 0 0 0
2 2 2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 2
1 2
2 2
3 2
4 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
0 1 3 7 6 4
1 5 4 6 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2 2
5 5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2
1 2
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre></pre>
<p>No pairs may satisfy the condition.</p></section>
</div>
</span> |
p03704 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a positive integer <var>n</var>, we denote the integer obtained by reversing the decimal notation of <var>n</var> (without leading zeroes) by <var>rev(n)</var>. For example, <var>rev(123) = 321</var> and <var>rev(4000) = 4</var>.</p>
<p>You are given a positive integer <var>D</var>. How many positive integers <var>N</var> satisfy <var>rev(N) = N + D</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>D</var> is an integer.</li>
<li><var>1 †D < 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the positive integers <var>N</var> such that <var>rev(N) = N + D</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>63
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two positive integers <var>N</var> such that <var>rev(N) = N + 63</var>: <var>N = 18</var> and <var>29</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>75
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There are no positive integers <var>N</var> such that <var>rev(N) = N + 75</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>864197532
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1920
</pre></section>
</div>
</span> |
p01739 | <p>
You are a programmer who loves pretty girl games (a sub-genre of dating simulation games). A game, which is titled "Floatable Heart" and was released last Friday, has arrived at your home just now. This game has multiple stories. When you complete all of those stories, you can get a special figure of the main heroine, Megumi. So, you want to hurry to play the game! But, let's calm down a bit and think how to complete all of the stories in the shortest time first.
</p>
<p>
In fact, you have the special skill that allows you to know the structure of branching points of games. By using the skill, you have found out that there are <var>n</var> branching points in this game and <var>i</var>-th branching point has <var>k_{i}</var> choices. This game is so complicated that multiple routes get to <var>i</var>-th branching point probably. You also noticed that it takes <var>c_{ij}</var> minutes to proceed from <var>i</var>-th branching point to another branching point (or an ending), if you select <var>j</var>-th choice of <var>i</var>-th branching point. Of course you need to select all the choices on all the branching points and read stories between a branching point and another branching point (or an ending) to complete all of those stories. In addition, you can assume it only takes negligible time to return to the beginning of the game ("reset") and to play from the beginning to the first branching point.
</p>
<p>
The game's manual says that this game has an additional feature called "Quick Save", and the feature allows you to record the point where you are currently playing and return there at any time later. However, this feature is not working for some bug. Thus you have to restart from the first branching point every time, if you reach an ending or quit the game on the way. Any patch to fix this bug has not been yet published. This is an imposed tribulation for the fastest players.
</p>
<p>Well, let's estimate how long it will take for completing all of the stories in the shortest time.
</p>
<h3>Input</h3>
<p>A data set is given in the following format.
</p><pre>
<var>n</var>
<var>k_{1}</var> <var>t_{11}</var> <var>c_{12}</var> ... <var>t_{1k_{1}}</var> <var>c_{1k_{1}}</var>
:
:
<var>k_{n}</var> <var>t_{n1}</var> <var>c_{n2}</var> ... <var>t_{nk_{n}}</var> <var>c_{nk_{n}}</var>
</pre>
<p>The first line of the data set contains one integer <var>n</var> (<var>2 \leq n \leq 1{,}000</var>), which denotes the number of the branching points in this game. The following <var>n</var> lines describe the branching points. The <var>i</var>-th line describes the branching point of ID number <var>i</var>. The first integer <var>k_{i}</var> (<var>0 \leq k_{i} \leq 50</var>) is the number of choices at the <var>i</var>-th branching point. <var>k_{i} ≥ 0</var> means that the <var>i</var>-th branching point is an ending. Next <var>2k_{i}</var> integers <var>t_{ij}</var> (<var>1 \leq t_{ij} \leq n</var>) and <var>c_{ij}</var> (<var>0 \leq c_{ij} \leq 300</var>) are the information of choices. <var>t_{ij}</var> denotes the ID numbers of the next branching points when you select the <var>j</var>-th choice. <var>c_{ij}</var> denotes the time to read the story between the <var>i</var>-th branching point and the <var>t_{ij}</var>-th branching point. The branching point with ID 1 is the first branching point. You may assume all the branching point and endings are reachable from the first branching point. You may also assume that there is no loop in the game, that is, no branching point can be reached more than once without a reset.
</p>
<h3>Output</h3>
<p>Print the shortest time in a line.
</p>
<h3>Sample Input 1</h3>
<pre>2
1 2 2
0
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>2
</pre>
<h3>Sample Input 2</h3>
<pre>6
2 2 1 3 2
2 4 3 5 4
2 5 5 6 6
0
0
0
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>24
</pre>
<h3>Sample Input 3</h3>
<pre>6
3 2 100 3 10 3 10
1 4 100
1 4 10
3 5 1 5 1 6 1
0
0
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>243
</pre>
|
p03354 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a permutation of the integers from <var>1</var> through <var>N</var>, <var>p_1</var>, <var>p_2</var>, .., <var>p_N</var>.
We also have <var>M</var> pairs of two integers between <var>1</var> and <var>N</var> (inclusive), represented as <var>(x_1,y_1)</var>, <var>(x_2,y_2)</var>, .., <var>(x_M,y_M)</var>.
AtCoDeer the deer is going to perform the following operation on <var>p</var> as many times as desired so that the number of <var>i</var> (<var>1</var> <var>â€</var> <var>i</var> <var>â€</var> <var>N</var>) such that <var>p_i = i</var> is maximized:</p>
<ul>
<li>Choose <var>j</var> such that <var>1</var> <var>â€</var> <var>j</var> <var>â€</var> <var>M</var>, and swap <var>p_{x_j}</var> and <var>p_{y_j}</var>.</li>
</ul>
<p>Find the maximum possible number of <var>i</var> such that <var>p_i = i</var> after operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2</var> <var>â€</var> <var>N</var> <var>â€</var> <var>10^5</var></li>
<li><var>1</var> <var>â€</var> <var>M</var> <var>â€</var> <var>10^5</var></li>
<li><var>p</var> is a permutation of integers from <var>1</var> through <var>N</var>.</li>
<li><var>1</var> <var>â€</var> <var>x_j,y_j</var> <var>â€</var> <var>N</var></li>
<li><var>x_j</var> <var>â </var> <var>y_j</var></li>
<li>If <var>i</var> <var>â </var> <var>j</var>, <var>\{x_i,y_i\}</var> <var>â </var> <var>\{x_j,y_j\}</var>.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>p_1</var> <var>p_2</var> <var>..</var> <var>p_N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_M</var> <var>y_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of <var>i</var> such that <var>p_i = i</var> after operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
5 3 1 4 2
1 3
5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If we perform the operation by choosing <var>j=1</var>, <var>p</var> becomes <code>1 3 5 4 2</code>, which is optimal, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
3 2 1
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>If we perform the operation by, for example, choosing <var>j=1</var>, <var>j=2</var>, <var>j=1</var> in this order, <var>p</var> becomes <code>1 2 3</code>, which is obviously optimal.
Note that we may choose the same <var>j</var> any number of times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 8
5 3 6 8 7 10 9 1 2 4
3 1
4 1
5 9
2 5
6 5
3 5
8 9
7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 1
1 2 3 4 5
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
</pre>
<p>We do not have to perform the operation. </p></section>
</div>
</span> |
p01369 |
<!-- begin en only -->
<h3><U>koukyoukoukokukikou</U></h3>
<!-- end en only -->
<!-- begin ja only -->
<!-- end ja only -->
<div>
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ACM-ICPC ãæãã誰ããæããåãåºãã»ã©æ¬²ããããã®ïŒ ããã AcceptedïŒ
ç¥ã㊠ACïŒ ãããïŒ å®ã®ãšããïŒ ãããéããã®ã¯ããéããã人ãã¡ã ãã§ïŒ äžéäžè¬ã«ã¯ "koukyoukoukokukikou" ã®ç¥ç§°ã«éããªãïŒ
</p>
<P>
ãšããã§ïŒ äžè¬çãªããŒããŒãã®ããŒé
眮(å³A-1)ãQWERTYé
åãšåŒã¶ã®ã«å¯ŸãïŒ ãããšã¯å¥ã®Dvoraké
åãšåŒã°ããããŒé
眮ãèæ¡ãããŠããïŒ
Dvoraké
åã§ã¯ãã䜿ãããããŒãããŒã ããžã·ã§ã³ã«ããã®ã§ïŒ ããéãã¿ã€ãã§ãããš Tæ°(ä»®) ã¯åŒ·ç¡¬ã«äž»åŒµããŠããïŒ
</p>
<p style="text-align: center;">
<a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011A-1" width="50%">
</a><br/>
å³A-1 QWERTYé
å
</p>
<p>
ãã® T æ°(ä»®)ã¯ãã®æååãèŠãŠããŠããããšã«æ°ä»ããïŒ "koukyoukoukokukikou" 㯠Dvorak é
åã䜿ããšçæã ãã§ã¿ã€ãã§ããããšã«ïŒ
ãããïŒ åæã«æ®å¿µãªäºå®ã«ãæ°ä»ããïŒ QWERTY é
åã§ãçæã ãã§ã¿ã€ãã§ããã®ã ïŒ
</p>
<p>
T æ°(ä»®)ã¯ä»ã« Dvorak é
åã䜿ããšçæã ãã§ã¿ã€ãã§ããæååããªããèå³ãæã£ãïŒ
ãããïŒ ã§ããã° QWERTY é
åã䜿ã£ããšãã«çæã ãã§ã¿ã€ãã§ããŠæ¬²ãããªãïŒ
ãã®ããã«ïŒ åæååã«å¯ŸããŠïŒ QWERTY é
åã§æåãã¿ã€ããããšãã«äœ¿ãæãå
¥ãæ¿ããåæ°ãæ±ããããã°ã©ã ãäœãããšã«ããïŒ
ããããã°ïŒ T æ°(ä»®)㯠QWERTY é
åãã»ãšãã©å¿ããŠããŸã£ãŠããã®ã§ãã£ãïŒ ä»£ããã«ããã°ã©ã ãæžããŠããããšãããïŒ
</p>
<p>
ãªãïŒ QWERTY é
åã§ããããã®ããŒãå·Šå³ã©ã¡ãã®æã§ã¿ã€ãããããã®ãªã®ãããããªããªã£ããšãã¯ïŒ äžã®å³A-2ãåç
§ããã°ããã ããïŒ
</p>
<p style="text-align: center;">
<a name="section_A"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011A-2" width="50%">
</a><br/>
å³A-2 ããããã®æã§ã¿ã€ããããç¯å²
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åã¯åè¡ã«ã¿ã€ãããæãå
¥ãæ¿ããåæ°ãã«ãŠã³ããã¹ãæååã1åãã€å«ãŸããïŒ
æååã¯ã¢ã«ãã¡ãããå°æåã®ã¿ãããªã£ãŠããŠ32æå以äžã§ããïŒ
å
¥åã®çµããã¯"#"ã®ã¿ãããªãè¡ã§ç€ºãããïŒ ãã®"#"ã¯ã«ãŠã³ãããå¯Ÿè±¡ã®æååã§ã¯ãªãïŒ
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åãããåæååã«ã€ããŠæŽæ°ã1ã€ãã€åè¡ã«åºåããïŒ
åºåãã¹ãæŽæ°ã¯ïŒ QWERTY é
åã䜿ã£ããšãã«ïŒ æåãã¿ã€ãããæãå
¥ãæ¿ããåæ°ã§ããïŒ
åºåã«äœèšãªæåãå«ããŠã¯ãããªãïŒ
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
koukyoukoukokukikou
abrakadabra
acmicpc
japaque
helloworld
#
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
0
2
4
5
7
</pre>
</div> |
p00981 | <h2>Wall Painting</h2>
<p>
Here stands a wall made of a number of vertical panels. The panels are not painted yet.
</p>
<p>
You have a number of robots each of which can paint panels in a single color, either red, green, or blue. Each of the robots, when activated, paints panels between a certain position and another certain position in a certain color. The panels painted and the color to paint them are fixed for each of the robots, but which of them are to be activated and the order of their activation can be arbitrarily decided.
</p>
<p>
Youâd like to have the wall painted to have a high <i>aesthetic value</i>. Here, the aesthetic value of the wall is defined simply as the sum of aesthetic values of the panels of the wall, and the aesthetic value of a panel is defined to be:
</p>
<ul>
<li> 0, if the panel is left unpainted.</li>
<li> The bonus value specified, if it is painted only in a single color, no matter how many times it is painted.</li>
<li> The penalty value specified, if it is once painted in a color and then overpainted in one or more different colors.</li>
</ul>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$ $m$ $x$ $y$
$c_1$ $l_1$ $r_1$
.
.
.
$c_m$ $l_m$ $r_m$
</pre>
<p>
Here, $n$ is the number of the panels ($1 \leq n \leq 10^9$) and $m$ is the number of robots ($1 \leq m \leq 2 \times 10^5$). $x$ and $y$ are integers between $1$ and $10^5$, inclusive. $x$ is the bonus value and $-y$ is the penalty value. The panels of the wall are consecutively numbered $1$ through $n$. The $i$-th robot, when activated, paints all the panels of numbers $l_i$ through $r_i$ ($1 \leq l_i \leq r_i \leq n$) in color with color number $c_i$ ($c_i \in \{1, 2, 3\}$). Color numbers 1, 2, and 3 correspond to red, green, and blue, respectively.
</p>
<h3>Output</h3>
<p>
Output a single integer in a line which is the maximum achievable aesthetic value of the wall.</p>
<h3>Sample Input 1 </h3>
<pre>
8 5 10 5
1 1 7
3 1 2
1 5 6
3 1 4
3 6 8
</pre>
<h3>Sample Output 1</h3>
<pre>
70
</pre>
<h3>Sample Input 2 </h3>
<pre>
26 3 9 7
1 11 13
3 1 11
3 18 26
</pre>
<h3>Sample Output 2</h3>
<pre>
182
</pre>
<h3>Sample Input 3 </h3>
<pre>
21 10 10 5
1 10 21
3 4 16
1 1 7
3 11 21
3 1 16
3 3 3
2 1 17
3 5 18
1 7 11
2 3 14
</pre>
<h3>Sample Output 3</h3>
<pre>
210
</pre>
<h3>Sample Input 4 </h3>
<pre>
21 15 8 7
2 12 21
2 1 2
3 6 13
2 13 17
1 11 19
3 3 5
1 12 13
3 2 2
1 12 15
1 5 17
1 2 3
1 1 9
1 8 12
3 8 9
3 2 9
</pre>
<h3>Sample Output 4</h3>
<pre>
153
</pre>
|
p01693 |
<h2>G - Derangement / å®å
šé å</h2>
<h3>Story</h3>
<p>Dã®ã²ãšã¯é åã«é¢ããç ç©¶ãããŠããããããšãDã®ã²ãšã¯ã"å®å
šé å (Derangement)"ãšããé åã®ã¯ã©ã¹ãèŠã€ããããå®å
šãªé åãšããªãããã£ãããïŒïŒïŒãããDããã¯ããŸãïŒïŒïŒããšå»äºç
ããããããDã®ã²ãšã¯ãäžããããé åããã¹ãŠå®å
šé åã«æžãæããŠããŸãããšèããã</p>
<h3>Problem</h3>
<p>é·ã<var>n</var>ã®é å<var>p</var> <var>=</var> <var>(p_1</var> <var>p_2</var> <var>...</var> <var>p_n)</var>ãäžããããã<var>i</var>çªç®ã®èŠçŽ ãš<var>j</var>çªç®ã®èŠçŽ ãå
¥ãæ¿ããæäœã«ã¯<var>(p_i+p_j) \times |i-j|</var>ã®ã³ã¹ããèŠããããã®ãšããäžèšã®å
¥ãæ¿ãæäœã®ã¿ãçšããŠ<var>p</var>ãå®å
šé åã«ããããã«å¿
èŠãªæå°ã®ã³ã¹ããæ±ããã</p>
<p>ãã ããé å<var>q</var>ãå®å
šé åã§ãããšã¯ã<var>1 \leq i \leq n</var>ã«ã€ããŠã<var>q_i \neq i</var>ãæãç«ã€ããšãèšããããšãã°ã<var>(5</var> <var>3</var> <var>1</var> <var>2</var> <var>4)</var>ã¯å®å
šé åã§ãããã<var>(3</var> <var>2</var> <var>5</var> <var>4</var> <var>1)</var>ã¯<var>4</var>çªç®ã®æ°ã<var>4</var>ãªã®ã§å®å
šé åã§ã¯ãªãã</p>
<h3>Input</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒãããªãã</p>
<pre><var>n</var>
<var>p_1</var> <var>p_2</var> ... <var>p_n</var></pre>
<p><var>1</var>è¡ç®ã¯é åã®é·ã<var>n</var>ãè¡šãæŽæ°<var>1</var>ã€ãããªãã <var>2</var>è¡ç®ã¯<var>n</var>åã®æŽæ°ãããªãã<var>i</var>çªç®ã®æŽæ°ã¯é å<var>p</var>ã®<var>i</var>çªç®ã®èŠçŽ ã衚ããããããã¯ç©ºçœ<var>1</var>æåã§åºåãããŠããã</p>
<p>å¶çŽ:</p>
<ul>
<li><var>2 \leq n \leq 100</var></li>
<li><var>1 \leq p_i \leq n, i \neq j â p_i \neq p_j</var></li>
</ul>
<h3>Output</h3>
<p><var>p</var>ãå®å
šé åã«äžŠã³æ¿ããããã®æå°ã³ã¹ãã<var>1</var>è¡ã«åºåãããè¡ã®æåŸã§ã¯å¿
ãæ¹è¡ãè¡ãããšã</p>
<h3>Sample Input 1</h3>
<pre>5
1 2 3 5 4</pre>
<h3>Sample Output 1</h3>
<pre>7</pre>
<p>1ãš2ãå
¥ãæ¿ããåŸã1ãš3ãå
¥ãæ¿ãããšã(2 3 1 5 4)ãšãªãå®å
šé åã§ããã</p>
<h3>Sample Input 2</h3>
<pre>5
5 3 1 2 4</pre>
<h3>Sample Output 2</h3>
<pre>0</pre>
<p>å§ãããå®å
šé åã§ããã</p>
<h3>Sample Input 3</h3>
<pre>10
1 3 4 5 6 2 7 8 9 10</pre>
<h3>Sample Output 3</h3>
<pre>38</pre> |
p00128 |
<h1>ããã°ã</h1>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_abacus1">
</center>
<br/>
<p>
ããã°ããç¿ãå§ããå人ããã®ãé¡ãã§ãããªãã¯ããã°ãã®ç ã®äžŠã³
ã衚瀺ããããã°ã©ã ãäœæããããšã«ãªããŸãããããæ°åãå
¥åãšããŠãããã°ãã®ç ã®äžŠã³ãåºåããããã°ã©ã ãäœæããŠãã ããããã ãã衚瀺ããããã°ãã®æ¡æ°ã¯ 5 æ¡ãšãã0 ãã 9 ãŸã§ã®ç ã®é
眮ã¯ãããã '<span>*</span>' (åè§ã¢ã¹ã¿ãªã¹ã¯)ã'<span> </span>' (åè§ç©ºçœ)ã'<span>=</span>' (åè§ã€ã³ãŒã«) ãçšããŠä»¥äžã®ããã«è¡šããã®ãšããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_abacus2">
</center>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ãã¹ãã±ãŒã¹ãäžããããŸããåãã¹ãã±ãŒã¹ãšã㊠5 æ¡ãŸã§ã®æ°åïŒæŽæ°ïŒã ïŒ è¡ã«äžããããŸãã
</p>
<p>
ãã¹ãã±ãŒã¹ã®æ°ã¯ 1024 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åãã¹ãã±ãŒã¹ã€ããŠããã°ãã®ç ã®é
眮ãåºåããŠãã ããããã¹ãã±ãŒã¹ã®éã«ïŒè¡ã®ç©ºè¡ãå
¥ããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
2006
1111
</pre>
<H2>Output for the Sample Input</H2>
<pre>
****
*
=====
* *
****
* ***
*****
*****
*****
=====
****
*
*****
*****
*****
</pre>
|
p02115 |
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem E: Piano</h1>
<h2>Problem</h2>
<p>
ãã£ã¡ãåã¯ãã¢ãã匟ãããšããŠããããã¢ãã¯å³åŽã«ããéµç€ã»ã©é«ãé³ãåºãããã£ã¡ãåã¯ããæ¥œèãæã£ãŠããããã®æ¥œèã«åŸã£ãŠåŒŸãã
</p>
<p>
楜èã«ã¯ãããæå»ã«ã©ã®éµç€ã匟ãã¹ããã瀺ãé³ç¬Šãæç³»åé ã«èšèŒãããŠããããã®æ¥œèã«ã¯åé³(è€æ°ã®éµç€ãæŒãããšãã«åºãé³)ã¯çŸãããé³ã®é·ããèããªãããšã«ããã
</p>
<p>
ãã£ã¡ãåã¯ãã¢ãã匟ããšãã以äžã®ã«ãŒã«ã«åŸãã
</p>
<ul>
<li>çæã®ã¿ã§åŒŸã</li>
<li>æäžæ¬ã§éµç€ã²ãšã€ã匟ã</li>
<li>æåã®é³ã¯ã©ã®æã§ã匟ãã</li>
<li>çŽåã®é³ããé«ãé³ã匟ããšããçŽåã®é³ã匟ããæãããã²ãšã€ä»¥äžå³ã«ããæã䜿ã</li>
<li>çŽåã®é³ããäœãé³ã匟ããšããçŽåã®é³ã匟ããæãããã²ãšã€ä»¥äžå·Šã«ããæã䜿ã</li>
<li>çŽåã®é³ãšåãé«ãã®é³ã匟ããšããçŽåã®é³ã匟ããæãšåãæã䜿ã</li>
</ul>
<p>
ãã£ã¡ãåãäœ¿ãæ¥œèãäžããããã®ã§ãã«ãŒã«ã«åŸã£ãŠãã®æ¥œèãæŒå¥ãããã«ã¯ãæŒå¥ããæ¹ã®è
ã«æå°äœæ¬ã®æãå¿
èŠããæ±ããããã ããå¿
èŠãªæã¯6æ¬ä»¥äžã«ãªãããšãããããšã«æ³šæããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var>
<var>a<sub>2</sub></var>
...
<var>a<sub>N</sub></var>
</pre>
<p>
1è¡ç®ã«ã楜èã«æžãããŠããé³ç¬Šã®ç·æ°ãè¡šãæŽæ°<var>N</var>ãäžããããã <br>ç¶ã2è¡ç®ãã<var>N</var>+1è¡ç®ãŸã§ã«ãæå»<var>i</var>(1 ≤ <var>i</var> ≤ <var>N</var>)ã«åŒŸãã¹ãéµç€ãæãå·Šã®éµç€ããäœçªç®ããè¡šãæŽæ°<var>a<sub>i</sub></var>ãäžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 10<sup>5</sup></li>
<li>0 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>9</sup></li>
</ul>
<h2>Output</h2>
<p>
ãã£ã¡ãåãäžèšã«ãŒã«ã«åŸã£ãŠåŒŸãããã«å¿
èŠãªæå°ã®æã®æ¬æ°ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3
2
5
1
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<p>
ãã®å Žåãå³1ã®①ã② ã③ ã®é ã§éµç€ã匟ããæã2æ¬ãããšãå·ŠåŽã®æã§éµç€2ããå³åŽã®æã§éµç€5ãããŸãå·ŠåŽã®æã§éµç€1ã匟ãããšãã§ããã
</p>
<center>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2017Day2_aizu2017_keyboard" alt="Sample1ã®å³è§£">
<legend>å³1: Sample1 ã®å³è§£</legend>
</figure>
</center>
<h2>Sample Input 2</h2>
<pre>
5
4
5
2
1
3
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<h2>Sample Input 3</h2>
<pre>
3
4
4
4
</pre>
<h2>Sample Output 3</h2>
<pre>
1
</pre> |
p00578 | <h1>æ¥æ¬æ²æ²¡ (Japan Sinks)</h1>
<!--ããæéå¶é : 2sec / ã¡ã¢ãªå¶é : 256MB-->
<h2>å顿</h2>
<p>
æ¥æ¬åå³¶ã¯çްé·ãåå³¶ã§ããïŒæ¥æ¬åå³¶ã¯å¹³è¡ãªå¢çç·ã«ãã <var>N</var> åã®åºç»ã«åããããŠããïŒåºç»ã«ã¯ç«¯ããé ã« <var>1</var> ãã <var>N</var> ã®çªå·ãä»ããããŠããïŒåºç» <var>i</var> (<var>1 ⊠i ⊠N</var>) ã®é«ã㯠<var>A_i</var> ã§ããïŒ
</p>
<p>
æ¥æ¬åå³¶ã¯æµ·ã«å²ãŸããŠããïŒæµ·é¢ã®é«ãã¯å Žæã«ãããäžå®ã§ããïŒé«ããæµ·é¢ã®é«ãããé«ãåºç»ã<strong>éžå°</strong>ãšåŒã¶ïŒ
</p>
<p>
éžå°ãé£ç¶ããŠããéšåã®ããšã<strong>å³¶</strong>ãšåŒã¶ïŒããæ£ç¢ºã«æžããšä»¥äžã®éãã§ããïŒæŽæ° <var>l</var>, <var>r</var> (<var>1 ⊠l ⊠r ⊠N</var>) ã«ã€ããŠïŒæ¥æ¬åå³¶ã®ãã¡åºç» <var>l</var>ïŒåºç» <var>l+1</var>ïŒ<var>...</var>ïŒåºç» <var>r</var> ãããªãéšåã<strong>é å</strong> [<var>l, r</var>] ãšããïŒä»¥äžã®æ¡ä»¶ãæºããé å [<var>l, r</var>] ãå³¶ãšããïŒ
</p>
<ul>
<li>åºç» <var>l</var>ïŒåºç» <var>l+1</var>ïŒ<var>...</var>ïŒåºç» <var>r</var> ã¯ãã¹ãŠéžå°ã§ããïŒ</li>
<li><var>l>1</var> ãªãã°åºç» <var>l-1</var> ã¯éžå°ã§ã¯ãªãïŒ</li>
<li><var>r<N</var> ãªãã°åºç» <var>r+1</var> ã¯éžå°ã§ã¯ãªãïŒ</li>
</ul>
<p>
æµ·é¢ã®äžæã«ããïŒæ¥æ¬åå³¶ã¯å°ããã€æ²æ²¡ããŠããïŒçŸåšã®æµ·é¢ã®é«ã㯠<var>0</var> ã§ãããïŒããã¯æéãçµã€ã«ã€ããŠåŸã
ã«äžããïŒã€ãã«ã¯æ¥æ¬å
šäœãæµ·ã«ãªã£ãŠããŸãïŒ
</p>
<p>
JOI åã¯ïŒæµ·é¢ã®é«ããäžæãããšïŒæ¥æ¬ã®å³¶ã®æ°ã墿žããããšã«æ°ä»ããïŒçŸåšããïŒæ¥æ¬ã«éžå°ããªããªããŸã§ã®é (çŸåšãå«ã) ã«ãããïŒå³¶ã®æ°ã®æå€§å€ãæ±ãããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ⊠N ⊠100000 (= 10^5)</var></li>
<li><var>0 ⊠A_i ⊠1000000000 (= 10^9)</var> (<var>1 ⊠i ⊠N</var>)</li>
</ul>
<h2>å
¥åã»åºå</h2>
<p>
<b>å
¥å</b><br>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ<br>
<var>N</var><br>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</p>
<p>
<b>åºå</b><br>
çŸåšããïŒæ¥æ¬ã«éžå°ããªããªããŸã§ã®é (çŸåšãå«ã) ã«ãããïŒå³¶ã®æ°ã®æå€§å€ã 1 è¡ã§åºåããïŒ
</p>
<!--
<h2>å°èª²é¡</h2>
<p>
</p>
<p style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;">
<li>(<var>7</var> ç¹) <var>N ⊠2000</var>, <var>A_i ⊠2000</var> (<var>1 ⊠i ⊠N</var>)</li>
<li>(<var>8</var> ç¹) <var>N ⊠2000</var></li>
<li>(<var>85</var> ç¹) 远å ã®å¶çŽã¯ãªãïŒ</li>
</ol>
</p>
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
6
0 1 2 1 3 2
</pre>
<h3>åºåäŸ 1</h3>
<pre>
2
</pre>
<ul>
<li>æµ·é¢ã®é«ãã <var>0</var> ä»¥äž <var>1</var> æªæºã®ãšãïŒåºç» <var>2, 3, 4, 5, 6</var> ãéžå°ã§ããïŒé å [<var>2, 6</var>] ãå¯äžã®å³¶ãªã®ã§ïŒå³¶ã®æ°ã¯ <var>1</var> ã§ããïŒ</li>
<li>æµ·é¢ã®é«ãã <var>1</var> ä»¥äž <var>2</var> æªæºã®ãšãïŒåºç» <var>3, 5, 6</var> ãéžå°ã§ããïŒé å [<var>3, 3</var>] ãšé å [<var>5, 6</var>] ãå³¶ãªã®ã§ïŒå³¶ã®æ°ã¯ <var>2</var> ã§ããïŒ</li>
<li>æµ·é¢ã®é«ãã <var>2</var> ä»¥äž <var>3</var> æªæºã®ãšãïŒåºç» <var>5</var> ã®ã¿ãéžå°ã§ããïŒé å [<var>5, 5</var>] ãå¯äžã®å³¶ãªã®ã§ïŒå³¶ã®æ°ã¯ <var>1</var> ã§ããïŒ</li>
<li>æµ·é¢ã®é«ãã <var>3</var> ã«ãªããšïŒéžå°ã¯ãªããªãïŒå³¶ã®æ°ã¯ <var>0</var> ã«ãªãïŒ</li>
</ul>
<p>
ãã£ãŠå³¶ã®æ°ã®æå€§å€ã¯ <var>2</var> ãªã®ã§ïŒ<var>2</var> ãåºåããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
6
3 2 3 0 2 0
</pre>
<h3>åºåäŸ 2</h3>
<pre>
2
</pre>
<ul>
<li>æµ·é¢ã®é«ãã <var>0</var> ä»¥äž <var>2</var> æªæºã®ãšãïŒåºç» <var>1, 2, 3, 5</var> ãéžå°ã§ããïŒé å [<var>1, 3</var>] ãšé å [<var>5, 5</var>] ãå³¶ãªã®ã§ïŒå³¶ã®æ°ã¯ <var>2</var> ã§ããïŒ</li>
<li>æµ·é¢ã®é«ãã <var>2</var> ä»¥äž <var>3</var> æªæºã®ãšãïŒåºç» <var>1, 3</var> ãéžå°ã§ããïŒé å [<var>1, 1</var>] ãšé å [<var>3, 3</var>] ãå³¶ãªã®ã§ïŒå³¶ã®æ°ã¯ <var>2</var> ã§ããïŒ</li>
<li>æµ·é¢ã®é«ãã <var>3</var> ã«ãªããšïŒéžå°ã¯ãªããªãïŒå³¶ã®æ°ã¯ <var>0</var> ã«ãªãïŒ</li>
</ul>
<p>
ãã£ãŠå³¶ã®æ°ã®æå€§å€ã¯ <var>2</var> ãªã®ã§ïŒ<var>2</var> ãåºåããïŒ
</p>
<h3>å
¥åäŸ 3</h3>
<pre>
10
4 1 2 1 2 3 5 4 3 2
</pre>
<h3>åºåäŸ 3</h3>
<pre>
3
</pre>
<br/>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2018/2019-yo/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 18 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2018/2019 äºéžç«¶æèª²é¡ã</a>
</p>
</div>
|
p02545 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are integer sequences <var>A</var> and <var>B</var> of length <var>3N</var>. Each of these two sequences contains three copies of each of <var>1, 2, \dots, N</var>.
In other words, <var>A</var> and <var>B</var> are both arrangements of <var>(1, 1, 1, 2, 2, 2, \dots, N, N, N)</var>.</p>
<p>Tak can perform the following operation to the sequence <var>A</var> arbitrarily many times:</p>
<ul>
<li>Pick a value from <var>1, 2, \dots, N</var> and call it <var>x</var>. <var>A</var> contains exactly three copies of <var>x</var>. Remove the middle element of these three. After that, append <var>x</var> to the beginning or the end of <var>A</var>.</li>
</ul>
<p>Check if he can turn <var>A</var> into <var>B</var>. If he can, print the minimum required number of operations to achieve that.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 33</var></li>
<li><var>A</var> and <var>B</var> are both arrangements of <var>(1, 1, 1, 2, 2, 2, \dots, N, N, N)</var>.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ... <var>A_{3N}</var>
<var>B_1</var> <var>B_2</var> ... <var>B_{3N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Tak can turn <var>A</var> into <var>B</var>, print the minimum required number of operations to achieve that. Otherwise, print <var>-1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 3 1 1 3 2 2 1 3
1 2 2 3 1 2 3 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, Tak can perform operations as follows:</p>
<ul>
<li><code>2 3 1 1 3 2 2 1 3</code> (The initial state)</li>
<li><code>2 2 3 1 1 3 2 1 3</code> (Pick <var>x = 2</var> and append it to the beginning)</li>
<li><code>2 2 3 1 3 2 1 3 1</code> (Pick <var>x = 1</var> and append it to the end)</li>
<li><code>1 2 2 3 1 3 2 3 1</code> (Pick <var>x = 1</var> and append it to the beginning)</li>
<li><code>1 2 2 3 1 2 3 1 3</code> (Pick <var>x = 3</var> and append it to the end)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 1 2 2 2 3 3 3
1 1 1 2 2 2 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
2 3 3 1 1 1 2 2 3
3 2 2 1 1 1 3 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8
3 6 7 5 4 8 4 1 1 3 8 7 3 8 2 4 7 5 2 2 6 5 6 1
7 5 8 1 3 6 7 5 4 8 1 3 3 8 2 4 2 6 5 6 1 4 7 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>7
</pre></section>
</div>
</span> |
p00082 |
<H1>ã¡ãªãŒãŽãŒã©ã³ã</H1>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_10_1">
</center><br/>
<p>
éåå°ã«ããã¡ãªãŒãŽãŒã©ã³ãã¯ãåãã§ãããã倧ããªåç€ã®äžã«éЬã銬è»ãªã©ã®ä¹ãç©ãåºå®ãããŠããŠãåç€ãå転ãããšåæã«ä¹ãç©ãäžäžã«æºãããå®çªã®éå
·ã§ããããéåå°ã®ã¡ãªãŒãŽãŒã©ã³ãã¯ãïŒäººä¹ãã®éЬè»ãïŒå°ãïŒäººä¹ãã®è»ïŒå°ãïŒäººä¹ãã®éЬãïŒå°ãèšïŒå°ã®ä¹ãç©ãå³ïŒã®ãããªé åºã§åããããŠããŸãããããŠãéåå°ã«ããã§ã®ã客æ§ã¯ãå³ïŒã«ç€ºãä¹ãå ŽïŒãïŒã®ã©ããã§åŸ
ã€ããã«ãªã£ãŠããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_10_2">
</center><br/>
<p>
ãã®éåå°ã®ã¡ãªãŒãŽãŒã©ã³ãã¯ãããªããä¹ãç©ãä¹ãå Žã«ãŽã£ãããšåãäœçœ®ã«åæ¢ããŸãããããŠãïŒãïŒã®ããããã§åŸ
ã£ãŠããã客ããŸã¯ãç®ã®åã«ãšãŸã£ãä¹ãç©ã«ä¹ãããšã«ãªã£ãŠããŸããæ¥ãã§ä»ã®ä¹ãå Žãžç§»åããŠããããä¹ããšããããšã¯ã§ããŸãããå¹çãããã客ããŸã«ãã®ããã§ããã ãããã«ã¯ãã¡ãªãŒãŽãŒã©ã³ãã®åæ¢ããäœçœ®ãããŸã調æŽããŠãä¹ããªãã客ããŸãã§ããã ãå°ãªãããããã«ããªããã°ãªããŸããã
</p>
<p>
ä¹ãå ŽïŒãïŒã§åŸ
ã£ãŠããã客ããŸã®äººæ°ãèªã¿èŸŒãã§ãã©ã®äœçœ®ã«ã©ã®ä¹ãç©ãæ¥ãããã«æ¢ããã°ä¹ããªãã客ããŸãæãå°ãªããªãããåºåããããã°ã©ã ãäœæããŠãã ããã
<!--ãªããä¹ããªããªãã客ããŸãæå°ãšãªããšãæ¹ãäœéããããå Žåã¯ããã®ãã¡ã®äžã€ã ãåºåããããã«ããŠãã ããã-->
</p>
<H2>å
¥å</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>p<sub>0</sub></var> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> <var>p<sub>3</sub></var> <var>p<sub>4</sub></var> <var>p<sub>5</sub></var> <var>p<sub>6</sub></var> <var>p<sub>7</sub></var>
</pre>
<p>
ä¹ãå Ž 0, 1, ..., 7 ã§åŸ
ã£ãŠããã客æ§ã®äººæ°ãè¡šãæŽæ° <var>p<sub>0</sub></var>, <var>p<sub>1</sub></var>,... , <var>p<sub>7</sub></var> ( 0 ≤ <var>p<sub>i</sub></var> ≤ 10,000) ã空çœåºåãã§ïŒè¡ã«äžããããŸãã
</p>
<H2>åºå</H2>
<p>
ã¡ãªãŒãŽãŒã©ã³ãã®ä¹ãç©ã®éЬè»ã 4ãè»ã 2ã銬ã 1 ã§è¡šãããšãšããŸããä¹ãå Ž 0, 1, ... , 7 ã«ãšããä¹ãç©ãããããã <var>c<sub>0</sub></var>, <var>c<sub>1</sub></var>,..., <var>c<sub>7</sub></var> ãšããŸããããŒã¿ã»ããããšã«ã<var>c<sub>0</sub></var>, <var>c<sub>1</sub></var>,..., <var>c<sub>7</sub></var> ã空çœåºåãã§ 1 è¡ã«åºåããŸãã
</p>
<p>
ãªããä¹ããªããªãã客ããŸãæå°ãšãªããšãæ¹ãè€æ°ããå Žåã¯ã<var>c<sub>0</sub>c<sub>1</sub>c<sub>2</sub>c<sub>3</sub>c<sub>4</sub>c<sub>5</sub>c<sub>6</sub>c<sub>7</sub></var> ã 8 æ¡ã®æŽæ° <var>V</var> ãšã¿ãªãã<var>V</var> ãæå°ãšãªããšãæ¹ãéžã¶ãã®ãšããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Sample Input</H2>
<pre>
2 3 1 4 0 1 0 1
4 2 3 2 2 2 1 1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 4 1 4 1 2 1 2
4 1 4 1 2 1 2 1
</pre>
|
p01040 | <h1>Problem D: Friday the 13th</h1>
<h2>Problem</h2>
<p>
ä»å¹Žããç«åœé€šå€§åŠç«¶æããã°ã©ãã³ã°å宿ããéå¬ãããããšãšãªã£ããåã¯æ¯å¹Žéå¬ããããã®å宿ããšãŠã楜ãã¿ã«ããŠãããããããæ¬²æã«èãåããå宿åã«æ£è²¡ããŠããŸãããéã«äœè£ãç¡ããªã£ãŠããŸã£ããããã§åã¯ãç«åœé€šå€§åŠã®æå¯ãé§
ã§ããåèæŽ¥ãŸã§ç§»åããã®ã«æãå®ãæžã鿥18ãã£ã·ã䜿ãããšã«ããããã®å笊ã¯å®ãæžã代ããã«ä¹ãæããå€ãçºçããç§»åã«äžž1æ¥äœ¿ããªããã°ãªããªãã®ã§ãšãŠãç²ããããããªç§»åãããæ¥ã13æ¥ã®éææ¥ã§ããããšã«æ°ã¥ããã®ã¯äŒæŽ¥è¥æŸé§
ãåºçºããåŸã ã£ããåã¯12æéãäžå®ãæããªããé»è»ã«æºãããã¯ãã«ãªã£ãã
</p>
<p>
仿¥ã¯å宿2æ¥ç®ã2015幎3æ15æ¥ãæ¥ææ¥ã§ããã13æ¥ã¯ç¹ã«äœäºããªãåèæŽ¥ã«å°çããããåã¯ãããã®ãããªäžå®ãå³ãããããªããšæã£ããããã§2æ¥ç®ã®ãžã£ããžã§ããåã¯ãæå®ãããæéå
ã«ååšãã13æ¥ã®éææ¥ã®æ°ãæ±ããåé¡ãåºé¡ããããã°ã©ã ãäœæããŠãããããšã«ããã
</p>
<p>
é(ããã)幎ã®å®çŸ©ã¯ä»¥äžã®éãã§ããã
</p>
<ul>
<li>西æŠå¹Žã4ã§å²ãåãã幎ã¯é幎ã§ããã</li>
<li>ãã ãã100ã§å²ãåãã幎ã¯é幎ã§ãªãã</li>
<li>ãã ãã400ã§å²ãåãã幎ã¯é幎ã§ããã</li>
</ul>
<h2>Input</h2>
<p>
空çœã§åºåããã6ã€ã®æŽæ°<var>Y<sub>1</sub></var>, <var>M<sub>1</sub></var>, <var>D<sub>1</sub></var>, <var>Y<sub>2</sub></var>, <var>M<sub>2</sub></var>, <var>D<sub>2</sub></var>ã1è¡ã§äžããããã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºããã
</p>
<ul>
<li>1 ≤ <var>Y<sub>1</sub></var> ≤ <var>Y<sub>2</sub></var> ≤ 10<sup>18</sup></li>
<li>1 ≤ <var>M<sub>i</sub></var> ≤ 12</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 31 (<var>M<sub>i</sub></var> = 1, 3, 5, 7, 8, 10, 12)</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 30 (<var>M<sub>i</sub></var> = 4, 6, 9, 11)</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 28 (<var>M<sub>i</sub></var> = 2 ã〠<var>Y<sub>i</sub></var>幎ã¯é幎ã§ãªã)</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 29 (<var>M<sub>i</sub></var> = 2 ã〠<var>Y<sub>i</sub></var>幎ã¯é幎ã§ãã)</li>
<li><var>Y<sub>1</sub></var>幎<var>M<sub>1</sub></var>æ<var>D<sub>1</sub></var>æ¥ã¯<var>Y<sub>2</sub></var>幎<var>M<sub>2</sub></var>æ<var>D<sub>2</sub></var>æ¥ãã0æ¥ä»¥äžåã®æ¥ä»ã§ãã</li>
</ul>
<h2>Output</h2>
<p>
<var>Y<sub>1</sub></var>幎<var>M<sub>1</sub></var>æ<var>D<sub>1</sub></var>æ¥ãã<var>Y<sub>2</sub></var>幎<var>M<sub>2</sub></var>æ<var>D<sub>2</sub></var>æ¥ãŸã§ã®éã«ååšãã13æ¥ã®éææ¥ã®æ°ã1è¡ã«åºåããã
</p>
<h2>Sample Input1</h2>
<pre>
2015 3 13 2015 3 13
</pre>
<h2>Sample Output1</h2>
<pre>
1
</pre>
<h2>Sample Input2</h2>
<pre>
2015 2 14 2015 3 15
</pre>
<h2>Sample Output2</h2>
<pre>
1
</pre>
<h2>Sample Input3</h2>
<pre>
1234 5 6 789012345678901234 5 6
</pre>
<h2>Sample Output3</h2>
<pre>
1357101234567708000
</pre>
|
p03587 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke prepared <var>6</var> problems for a upcoming programming contest.
For each of those problems, Rng judged whether it can be used in the contest or not.</p>
<p>You are given a string <var>S</var> of length <var>6</var>.
If the <var>i</var>-th character of <var>s</var> is <code>1</code>, it means that the <var>i</var>-th problem prepared by Snuke is accepted to be used; <code>0</code> means that the problem is not accepted.</p>
<p>How many problems prepared by Snuke are accepted to be used in the contest?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>S</var> is <var>6</var>.</li>
<li><var>S</var> consists of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the number of problems prepared by Snuke that are accepted to be used in the contest.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>111100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The first, second, third and fourth problems are accepted, for a total of four.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>001001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01410 |
<H1>D: Dangerous Tower</H1>
<p>
ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ
</p>
<p>
仿¥ã®ä¿®è¡ã¯ïŒç©ã¿æšãäžå¯§ã«ç©ã¿äžããããšã«ãã£ãŠïŒæ±ºããŠãã¹ã¿ã€ãã³ã°ãããªãã»ã©ã®æå
ã®åšçšããæã«å
¥ããããšãããã®ã§ããïŒãã£ããç©ã¿æšãããããããã®ã§ïŒé«ãå¡ãäœããïŒ
</p>
<p>
ç©ã¿æšã¯ <i>N</i> åããïŒ<i>i</i> çªç® (1 ≤ <i>i</i> ≤ <i>N</i>) ã®ç©ã¿æšã¯ 1 × <i>A</i><sub><i>i</i></sub> × <i>B</i><sub><i>i</i></sub> ã®çŽæ¹äœã®åœ¢ãããŠããïŒé·ã 1 ã®èŸºã¯å¥¥è¡ãæ¹åã«çšããŠïŒé·ã <i>A</i><sub><i>i</i></sub>, <i>B</i><sub><i>i</i></sub> ã®èŸºã暪æ¹åãšé«ãæ¹åã« 1 ã€ãã€å²ãåœãŠãããšã«ããïŒç©ã¿æšãç©ã¿äžãããšãïŒäžã®æ®µã®ç©ã¿æšã¯äžã®æ®µã®ç©ã¿æšããæšªã®é·ããå³å¯ã«çããªããã°ãªããªãïŒç©ã¿æšã¯å¥œããªé çªã«äœ¿ãããšãã§ãïŒãŸãïŒäœ¿ããªãç©ã¿æšããã£ãŠãããïŒãã®ãããªå¶çŽäžã§ïŒäœãããšãå¯èœãªæãé«ãå¡ãäœãããïŒ
</p>
<H2>Input</H2>
<pre>
<i>N</i>
<i>A</i><sub>1</sub> <i>B</i><sub>1</sub>
...
<i>A</i><sub><i>N</i></sub> <i>B</i><sub><i>N</i></sub>
</pre>
<p>
1 ≤ <i>N</i> ≤ 1,000ïŒ1 ≤ <i>A</i><sub><i>i</i></sub>ïŒ<i>B</i><sub><i>i</i></sub> ≤ 1,000,000 ãæºããïŒå
¥åã®å€ã¯ãã¹ãп޿°ã§ããïŒ
</p>
<H2>Output</H2>
<p>
å¡ã®é«ãã®æå€§å€ã 1 è¡ã«åºåããïŒ
</p>
<H2>Sample Input 1</H2>
<pre>
3
10 40
10 40
20 30
</pre>
<H2>Sample Output 1</H2>
<pre>
80
</pre>
<H2>Sample Input 2</H2>
<pre>
4
1 2
2 3
3 4
4 1
</pre>
<H2>Sample Output 2</H2>
<pre>
11
</pre> |
p00651 |
<h1>Problem E: Legend of Storia</h1>
<p>
In Storia Kingdom, there is an artifact called "Perfect Sphere" made by a great meister Es. This is handed down for generations in the royal palace as a treasure. Es left a memo and filled mysterious values in it. Within achievements of researches, it has been revealed that the values denote coordinate values. However it is still unknown the definition of the coordinate system.
</p>
<p>
By the way, you are a person who lived in age of Es lived. The values which meister Es left are defined by following. Es set an moving object in the artifact sphere. Surprisingly, that is rigid body and perpetual organization. The object rotates inside the sphere and it is always touching the inside surface of the sphere. This value is a coordinate of the tangent point by the object and the sphere, but it is not a three dimensional value. The object is a plate and this is a simple polygon. Here, "simple" means "non self-intersected". This rotates while touching a great circle of the sphere. Here, assume that the great circle is a circle <i>O</i> centered in the origin in the xy plane. (It is two-dimensional Cartesian coordinate system, the direction of positive x-value is right and the direction of positive y-value is up). This plate touches the circle <i>O</i> with a single point at the beginning of the movement. And it rotates in counterclockwise as the current touching point is the rotation fulcrum. When another point <i>X</i> of the plate touches the circle <i>O</i> newly, the plate continue to rotate as described above, but in the next rotation, the rotation fulcrum point is changed. This will be the point <i>X</i>. If two or more points can be interpreted as the point <i>X</i>, the point <i>X</i> is a most distant point from the currently touching point <i>X'</i>. Here, that distance is the length of the arc of the circle <i>O</i> from the point <i>X'</i> to the point <i>X</i> in clockwise.
</p>
<p>
Es asked you, an excellent assistant, to write a program that enumerates <i>Q</i> tangent points (fulcrum points while the movement) by the plate and the circle <i>O</i> while the movement of the plate described above in the chronological order. Of course, one and the previous one must be distinct points. Following figures show you examples of the movement of the plate inside the circle <i>O</i>.
<br>
1<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E1"><br>
2<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E2"><br>
3<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E3"><br>
4<br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uapc2011_E4"><br>
</p>
<h2>Input</h2>
<p>
Input consists of multiple datasets.<br>
A dataset is given in a following format.
</p>
<pre>
<i>N</i> <i>R</i> <i>Q</i>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i>
<i>x<sub>2</sub></i> <i>y<sub>2</sub></i>
...
<i>x<sub>N</sub></i> <i>y<sub>N</sub></i>
</pre>
<p>
<i>N</i>, <i>R</i>, <i>Q</i> are integers that represent the number of points of the plate, the radius of the circle, and the number of points Es needs respectively.<br>
Following <i>N</i> lines contain 2<i>N</i> integers that represent coordinates of the plate's points ( <i>x<sub>k</sub></i> , <i>y<sub>k</sub></i> ) in the circle.(1≤<i>k</i>≤<i>N</i>)<br>
</p>
<ul>
You can assume following conditions.
<li>Points of the plate are given in counterclockwise.</li>
<li>No three points are co-linear.</li>
<li><i>N</i>-1 points of the plate are given inside of the circle (distances between the center of the circle and these points are less than <i>R</i>). And 1 point is on the circle edge.</li>
<i>N</i>=<i>R</i>=<i>Q</i>=0 shows the end of input.
</ul>
</p>
<h2>Constraints</h2>
<p>
The number of datasets is less than or equal to 400.<br>
3≤<i>N</i>≤25<br>
1≤<i>R</i>≤1000<br>
0≤<i>Q</i>≤100
</p>
<h2>Output</h2>
<p>
For each dataset, output (<i>Px</i> <i>Py</i>:real number) in <i>Q</i> in the following format.
</p>
<pre>
<i>Px<sub>1</sub></i> <i>Px<sub>1</sub></i>
<i>Px<sub>2</sub></i> <i>Py<sub>2</sub></i>
...
<i>Px<sub>N+1</sub></i> <i>Py<sub>N+1</sub></i>
</pre>
<p>
These answers must satisfy |<i>Tx<sub>i</sub></i>-<i>Px<sub>i</sub></i>|≤0.0001 and |<i>Ty<sub>i</sub></i>-<i>Py<sub>i</sub></i>|≤0.0001.<br>
Here, <i>Px<sub>i</sub></i>, <i>Py<sub>i</sub></i>(1≤<i>i</i>≤<i>Q</i>) are your output and <i>Tx<sub>i</sub></i>,<i>Ty<sub>i</sub></i>(1≤<i>i</i>≤<i>Q</i>) are judge's output.
</p>
<h2>Sample Input</h2>
<pre>
4 10 8
0 -10
3 -7
0 -4
-3 -7
0 0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
-4.146082488326 -9.100000000000
-7.545870128753 -6.562000000000
-9.587401146004 -2.842840000000
-9.903199956975 1.388031200000
-8.436422775690 5.369056784000
-5.451089494781 8.383652146880
-1.484560104812 9.889190123322
2.749190104024 9.614673877565
</pre> |
p01943 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']], skipTags: ["script","noscript","style","textarea","code"]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h2>FïŒ æãç®ã¯æ¥œãã - Multiplication Is Interesting -</h2>
<h3>ç©èª</h3>
<p>ç·åé«çã®é£æ³¢åããã¯ã圌女ã®èªçæ¥ã«æ°åããã¬ãŒã³ãããããšèããŠãããåœŒå¥³ã¯æãç®ã倧奜ããªå¥³ã®åãªã®ã§ã飿³¢ããã¯åœŒå¥³ã«ã§ããã ãå€ãã®æãç®ã楜ãããŠãããããããªæ°åããã¬ãŒã³ãããããšæã£ãŠãããããããèšç®çµæã <var>2^{20}</var> ãè¶
ããå€ã«ãªããšåœŒå¥³ã®æ©å«ãéç«¯ã«æªããªã£ãŠããŸãïŒéåžžã®äººé¡ã¯ <var>2^{20}</var>ãšããèšå€§ãªæ°ãèšç®ã§ããªããããããã§ã圌女ã¯éåãšå¯å€§ãªäººã§ãããšèšããïŒãåœŒå¥³ã®æ©å«ãæãªããªãããã«ãã§ããã ãå€ãã®æãç®ã楜ããã§ããããæ°åã飿³¢ãããäœã£ãã®ã§ãããªãã®ä»äºã¯ãã®æ°åã圌女ãååã«æ¥œããŸãããããæ€èšŒããããã°ã©ã ãäœãããšã§ãããã€ãŸããããªãã®ä»äºã¯æ°åã®é£ç¶ããéšååã®äžã§ãéšååã®ç·ç©ã <var>K</var> ãè¶
ããªãæé·ã®éšååã®é·ããçããããã°ã©ã ãäœãããšã§ããã</p>
<h3>åé¡</h3>
<p>é·ã <var>N</var> ã®éè² å®æ°å <var>S = s_1, s_2, ..., s_N</var> ãš éè² å®æ° <var>K</var> ãããã ããªãã®ä»äºã¯ã以äžã®æ¡ä»¶ãæºãã <var>S</var> ã®é£ç¶ããéšååã®ãã¡ãæ¬¡ã®æ¡ä»¶ãæºããæé·ã®éšååã®é·ããæ±ããããšã§ããããã®ãšããéšååã®é·ã㯠<var>1</var> 以äžã§ãªããã°ãªããªãã</p>
<ul>
<li> <var>S</var> ã®é£ç¶ããéšåå $T = s_\ell, \ldots, s_r$ ã«ã€ã㊠$\prod_{i = \ell, \ldots, r} s_i \leq$ <var>K</var>ãæºããã</li>
</ul>
<p>ããæ¡ä»¶ãæºããéšååãäžã€ãååšããªããšãã¯ã <var>0</var> ãåºåããã</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ</p>
<pre>
<var>N</var> <var>K</var>
<var>s_1</var>
<var>s_2</var>
$\dots$
<var>s_N</var>
</pre>
<p><var>1</var> è¡ç®ã«ã¯æ°åã®é·ã <var>N</var> ãš éšååã®ç·ç©ã®äžé <var>K</var> ãäžãããããç¶ã <var>N</var> è¡ã®ãã¡ã <var>i</var> è¡ç®ã§ã¯éè² å®æ°å <var>S</var> ã® <var>i</var> çªç®ã®å®æ° <var>s_i</var> ãäžããããã</p>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq N \leq 100,000</var> </li>
<li> <var>0 \leq s_i \leq 2.00</var> </li>
<li> <var>0 \leq K \leq 1,048,576</var></li>
<li> <var>N</var> ã¯æŽæ°ã<var>K</var> ãš <var>s_i</var> ã¯å°æ°ç¹ç¬¬ <var>3</var> äœä»¥äžãå«ãŸãªã宿°ã§ãã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p><var>S</var> ã®éšååã®ç·ç©ã <var>K</var> ãè¶
ããªãæé·ã®éšååã®é·ãã <var>1</var> è¡ã«åºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>
6 2.01
1.10
1.44
0.91
2.00
1.12
1.55
</pre>
<h3>åºåäŸ1</h3>
<pre>3</pre>
<h3>å
¥åäŸ2</h3>
<pre>
8 12.22
2.00
2.00
2.00
1.91
2.00
2.00
2.00
0.01
</pre>
<h3>åºåäŸ2</h3>
<pre>8</pre> |
p02396 |
<H1>Print Test Cases</H1>
<p>
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.
</p>
<p>
Write a program which reads an integer <var>x</var> and print it as is. Note that multiple datasets are given for this problem.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of an integer <var>x</var> in a line.
</p>
<p>
The input ends with an integer 0. You program should not process (print) for this terminal symbol.
</p>
<H2>Output</H2>
<p>
For each dataset, print <var>x</var> in the following format:
</p>
<pre>
Case i: x
</pre>
<p>
where <var>i</var> is the case number which starts with 1. Put a single space between "Case" and <var>i</var>. Also, put a single space between ':' and <var>x</var>.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <var>x</var> ≤ 10000</li>
<li>The number of datasets ≤ 10000</li>
</ul>
<H2>Sample Input</H2>
<pre>
3
5
11
7
8
19
0
</pre>
<H2>Sample Output</H2>
<pre>
Case 1: 3
Case 2: 5
Case 3: 11
Case 4: 7
Case 5: 8
Case 6: 19
</pre> |
p00201 |
<h1>é¬éãã¹ã¿ãŒ</h1>
<p>
ããªãã¯ã€ãã«éæ³ã®éãé¬ééãæã«å
¥ããŸãããé¬ééã«è€æ°ã®ã¢ã€ãã ãå
¥ãããšãæ°ãã㢠ã€ãã ãäœãããšãã§ããŸããæ°ããäœã£ãã¢ã€ãã ã¯ãä»ã®ã¢ã€ãã ãäœãããã«é¬ééãžå
¥ããããšãã§ããŸããã¢ã€ãã ãäœãããã«å¿
èŠãªã¢ã€ãã ã®ãªã¹ããèšãããã®ãé¬éã¬ã·ããšåŒã¶ããšã«ããŸãã以äžã® 3 ã€ã¯é¬éã¬ã·ãã®äŸã§ãã
</p>
<ol>
<li> æšçãšç³žã§ã©ã±ãããã§ããã</li>
<li> ãç±³ãšæ°Žã§ãã«ãããã§ããã</li>
<li> ã©ã±ãããšãã€ã¯ãšãã«ããã§ã®ã¿ãŒãã§ããã</li>
</ol>
<p>
ã¢ã€ãã ã¯ãéã䜿ã£ãŠæã«ãããããšãã§ããŸãããé¬ééã§äœã£ãæ¹ãå®ãããå ŽåããããŸããäŸãã°ãåã¢ã€ãã ã®è³Œå
¥äŸ¡æ Œã以äžã®ããã«äžããããŠãããšããŸãã
</p>
<center>
<table border=1 cellpadding=8 cellspacing=2>
<tr><td width=140>ã¢ã€ãã å</td><td width=140> 賌å
¥äŸ¡æ Œ(å)</td></tr>
<tr><td> æšç </td><td> 3,000</td></tr>
<tr><td> 糞 </td><td> 800</td></tr>
<tr><td> ãç±³ </td><td> 36</td></tr>
<tr><td> æ°Ž </td><td> 0</td></tr>
<tr><td> ã©ã±ãã </td><td> 5,000</td></tr>
<tr><td> ãã€ã¯ </td><td> 9,800</td></tr>
<tr><td> ãã«ãã </td><td> 140</td></tr>
<tr><td> ã®ã¿ãŒ </td><td> 98,000</td></tr>
</tr>
</table>
<br/>
</center>
<p>
ã©ã±ãã㯠5,000 åã§è³Œå
¥ã§ããŸãããæšçãšç³žã賌å
¥ããŠé¬éããã° 3,800 åã§æã«å
¥ããããŸããæŽã«ãé¬éãéããããšã«ãããšãŠããåŸã«ã¢ã€ãã ãæã«å
¥ããããŸããå³ 1 ã¯äžèš 3 ã€ã®é¬éã¬ã·ãäŸãçµã¿åããããã®ã§ããã®ã¿ãŒã¯ 98,000 åã§è³Œå
¥ã§ããŸãããæšçã糞ããç±³ãæ°Žããã€ã¯ã賌å
¥ããŠé¬éããã°ããã£ãã® 13,636 åã§æã«å
¥ããããŸãã
</p>
<br><br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_recipe">
<p>å³ 1</p>
</center>
<br><br>
<p>
ããªãã¯åéºã楜ã«é²ããããããªãã¹ãå®ãç®çã®ã¢ã€ãã ãæã«å
¥ããããšèããŸããã ã¢ã€ãã ã®ãªã¹ããé¬éã¬ã·ãã®ãªã¹ããæå®ãããã¢ã€ãã ãå
¥åãšããæå®ãããã¢ã€ãã ãäœãããã«å¿
èŠãªéé¡ã®æå°å€ãåºåããããã°ã©ã ãäœæããŠäžããã
</p>
<!--
<p>
ã¢ã€ãã ãªã¹ãã«å«ãŸããã¢ã€ãã ã®çš®é¡ <var>n</var> 㯠1 ä»¥äž 100 以äžã®æŽæ°ãšããåã¢ã€ãã ã賌å
¥ããå Žåã®å€æ®µ <var>p</var> 㯠0 ä»¥äž 1000000 以äžãšããŸããã¢ã€ãã ã®åå <var>i</var> 㯠1 æåä»¥äž 100 æå以äžã®ã¢ã«ãã¡ããããããªãåè§æååã§ããé¬éã¬ã·ãã®çš®é¡ <var>m</var> 㯠0 ä»¥äž 100 以äžã®æŽæ°ã§ãã 1ã€ã®é¬éã¬ã·ãã¯ã¢ã€ãã ã®åå <var>o</var>ããããäœãããã«å¿
èŠãªã¢ã€ãã ã®åæ° <var>k</var> ã <var>k</var> åã®ã¢ã€ãã å <var>q</var> ã®ãªã¹ãã«ãã£ãŠäžããããŸãã<var>k</var> 㯠100 以äžãšããŸãã
</p>
-->
<p>
åã¢ã€ãã ã®æ°éã«éãã¯ãªããã®ãšããŸããã¢ã€ãã ã¯è€æ°ã®ã¬ã·ãã«äœ¿ãããããšããããŸããã1 ã€ã®ã¢ã€ãã ãäœãããã®ã¬ã·ãã¯ããã ã 1 ã€ã§ãããŸããããã¢ã€ãã ãèµ·ç¹ãšããŠã¬ã·ãããã©ã£ãŠãã£ããšãããã®ã¢ã€ãã ãåã³ã¬ã·ãã«çŸããããšã¯ãããŸããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>s<sub>1</sub></var> <var>p<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>p<sub>2</sub></var>
:
<var>s<sub>n</sub></var> <var>p<sub>n</sub></var>
<var>m</var>
<var>o<sub>1</sub></var> <var>k<sub>1</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>1</sub></sub></var>
<var>o<sub>2</sub></var> <var>k<sub>2</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>2</sub></sub></var>
:
<var>o<sub>m</sub></var> <var>k<sub>m</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>m</sub></sub></var>
<var>t</var>
</pre>
<p>
1 è¡ç®ã«ãªã¹ãã«å«ãŸããã¢ã€ãã ã®çš®é¡æ° <var>n</var> (1 ≤ <var>n</var> ≤ 100) ãäžããããŸããç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®ã¢ã€ãã ã®åå <var>s<sub>i</sub></var> (1 æåä»¥äž 100 æå以äžã®ã¢ã«ãã¡ããããããªãåè§æåå) ãšããã賌å
¥ããå Žåã®å€æ®µ <var>p<sub>i</sub></var> (0 ≤ <var>p<sub>i</sub></var> ≤ 1000000)ãäžããããŸãã
</p>
<p>
ç¶ãè¡ã«é¬éã¬ã·ãã®æ° <var>m</var> (0 ≤ <var>m</var> ≤ 100) ãäžããããŸããç¶ã <var>m</var> è¡ã« <var>i</var> çªç®ã®ã¬ã·ãã®æ
å ±ãäžããããŸããåã¬ã·ããšããŠãã¢ã€ãã ã®åå <var>o<sub>i</sub></var>ããããäœãããã«å¿
èŠãªã¢ã€ãã ã®åæ° <var>k<sub>i</sub></var> (1 ≤ <var>k<sub>i</sub></var> ≤ 100) ã <var>k<sub>i</sub></var> åã®ã¢ã€ãã å <var>q<sub>1</sub></var>, <var>q<sub>2</sub></var> ... <var>q<sub>k<sub>i</sub></var> ãäžããããŸãã
</p>
<p>
æåŸã®è¡ã«æå®ãããã¢ã€ãã å <var>t</var> ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 30 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãæå°ã®å€æ®µãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
8
wood 3000
string 800
rice 36
water 0
racket 5000
microphone 9800
onigiri 140
guitar 98000
3
racket 2 wood string
onigiri 2 rice water
guitar 3 racket microphone onigiri
guitar
1
computer 300000
0
computer
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
13636
300000
</pre>
|
p02729 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have <var>N+M</var> balls, each of which has an integer written on it.<br/>
It is known that: </p>
<ul>
<li>The numbers written on <var>N</var> of the balls are even.</li>
<li>The numbers written on <var>M</var> of the balls are odd.</li>
</ul>
<p>Find the number of ways to choose two of the <var>N+M</var> balls (disregarding order) so that the sum of the numbers written on them is even.<br/>
It can be shown that this count does not depend on the actual values written on the balls.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>0 \leq N,M \leq 100</var></li>
<li><var>2 \leq N+M</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>For example, let us assume that the numbers written on the three balls are <var>1,2,4</var>.</p>
<ul>
<li>If we choose the two balls with <var>1</var> and <var>2</var>, the sum is odd;</li>
<li>If we choose the two balls with <var>1</var> and <var>4</var>, the sum is odd;</li>
<li>If we choose the two balls with <var>2</var> and <var>4</var>, the sum is even.</li>
</ul>
<p>Thus, the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>13 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>81
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>0 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>3
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.