question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03740 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Alice and Brown loves games. Today, they will play the following game.</p>
<p>In this game, there are two piles initially consisting of <var>X</var> and <var>Y</var> stones, respectively.
Alice and Bob alternately perform the following operation, starting from Alice:</p>
<ul>
<li>Take <var>2i</var> stones from one of the piles. Then, throw away <var>i</var> of them, and put the remaining <var>i</var> in the other pile. Here, the integer <var>i</var> <var>(1â€i)</var> can be freely chosen as long as there is a sufficient number of stones in the pile.</li>
</ul>
<p>The player who becomes unable to perform the operation, loses the game.</p>
<p>Given <var>X</var> and <var>Y</var>, determine the winner of the game, assuming that both players play optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 †X, Y †10^{18}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the winner: either <code>Alice</code> or <code>Brown</code>.</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>Brown
</pre>
<p>Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Alice
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Brown
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Alice
</pre></section>
</div>
</span> |
p03310 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has an integer sequence <var>A</var> of length <var>N</var>.</p>
<p>He will make three cuts in <var>A</var> and divide it into four (non-empty) contiguous subsequences <var>B, C, D</var> and <var>E</var>.
The positions of the cuts can be freely chosen.</p>
<p>Let <var>P,Q,R,S</var> be the sums of the elements in <var>B,C,D,E</var>, respectively.
Snuke is happier when the absolute difference of the maximum and the minimum among <var>P,Q,R,S</var> is smaller.
Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
3 2 4 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If we divide <var>A</var> as <var>B,C,D,E=(3),(2),(4),(1,2)</var>, then <var>P=3,Q=2,R=4,S=1+2=3</var>.
Here, the maximum and the minimum among <var>P,Q,R,S</var> are <var>4</var> and <var>2</var>, with the absolute difference of <var>2</var>.
We cannot make the absolute difference of the maximum and the minimum less than <var>2</var>, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
10 71 84 33 6 47 23 25 52 64
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>36
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1 2 3 1000000000 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>999999994
</pre></section>
</div>
</span> |
p00496 |
<H1>å€åº(Night Market) </H1>
<p>
倪éããã¯ïŒJOI ç¥ç€Ÿã§éãããå€ç¥ãã«è¡ãããšã«ããïŒ
</p>
<p>
JOI ç¥ç€Ÿã«åããéã«æ²¿ã£ãŠïŒ<i>N</i> åã®å€åºãéãããŠããïŒããããã®å€åºã«ã¯ïŒ1 ãã<i>N</i> ãŸã§ã®çªå·ãé çªã«ã€ããŠããïŒéãã æã®æ¥œãããšéã¶ã®ã«ãããæéãããããæŽæ°ã§æ±ºãŸã£ãŠããïŒå€åº<i>i</i> ã§éãã æã®æ¥œããã¯<i>A<sub>i</sub></i> ã§ïŒå€åº<i>i</i> ã§éã¶ã®ã«ãããæéã¯<i>B<sub>i</sub></i> ã§ããïŒ
</p>
<p>
ãŸãïŒå€ç¥ãã®ã€ãã³ããšããŠè±ç«å€§äŒãããïŒæå»<i>S</i> ã«æã倧ããªè±ç«ãæã¡äžããããïŒå€ªéããã¯ãã®æã倧ããªè±ç«ãèŠãããšæã£ãŠããïŒ
</p>
<p>
倪éããã¯å€åºãšè±ç«ã®äž¡æ¹ã楜ããããã«ïŒå€ç¥ãã«å°çããæå»0 ããå€ç¥ããçµããæå»<i>T</i> ãŸã§ã®äºå®ãç«ãŠãããšã«ããïŒ
</p>
<p>
倪éããã¯å€åºã®äžãã<i>k</i> å(1 ≤ <i>k</i> ≤ <i>N</i>) ã®å€åºãéžã³ïŒããããã«å¯ŸããŠèšªããæå»ãæŽæ°ã§æ±ºããïŒåãå€åºã2 床éžã¶ããšã¯ã§ããªãïŒéžã°ããå€åºã®çªå·ãå°ããé ã«<i>y</i><sub>1</sub>, <i>y</i><sub>2</sub>, ... <i>y<sub>k</sub></i> ãšãïŒå€åº<i>y<sub>i</sub></i> ã蚪ããæå»ã<i>x<sub>y<sub>i</sub></sub></i> ãšãããšïŒå€ªéããã¯å€åº<i>y<sub>i</sub></i> ã§æå»<i>x<sub>y<sub>i</sub></sub></i> ããæå»<i>x<sub>y<sub>i</sub></sub></i> + <i>B<sub>y<sub>i</sub></sub></i> ãŸã§éã¶ïŒ
</p>
<p>
倪éããã¯å€åºã®çªå·ã®å°ããé ã«éã³ïŒåæã«2 ã€ã®å€åºã§ã¯éã¹ãªãïŒãŸãïŒå€åºãšå€åºã®éã®ç§»
åã«ãããæéã¯ç¡èŠã§ããïŒ
</p>
<p>
æå»<i>T</i> ãè¶
ãããšå€ç¥ããçµããã®ã§ïŒå€åºã§éã¶ããšã¯ã§ããªãïŒãŸãïŒå€åºã§éãã§ããéã¯è±ç«ãèŠãããšã¯ã§ããªãïŒãã ãïŒæå»<i>S</i> ãããå€åºã§éã³å§ããæå»ãéã³çµããæå»ã§ãã£ãå Žåã¯ïŒå€ªéããã¯è±ç«ãèŠãããšãã§ãããã®ãšããïŒ
</p>
<p>
ããªãã¡ïŒäºå®ã¯ä»¥äžã®æ¡ä»¶ãæºãããŠããªããã°ãªããªãïŒ
</p>
<ul>
<li> <i>y</i><sub>1</sub> < <i>y</i><sub>2</sub> < ... < <i>y<sub>k</sub></i></li>
<li> <i>x</i><sub><i>y</i><sub>1</sub></sub>, <i>x</i><sub><i>y</i><sub>2</sub></sub>, ... <i>x<sub>y<sub>k</sub></sub></i> ã¯æŽæ°ïŒ</li>
<li> 0 ≤ <i>x</i><sub><i>y</i><sub>1</sub></sub> < <i>x</i><sub><i>y</i><sub>1</sub></sub> + <i>B</i><sub><i>y</i><sub>1</sub></sub> ≤ <i>x</i><sub><i>y</i><sub>2</sub></sub> < <i>x</i><sub><i>y</i><sub>2</sub></sub> + <i>B</i><sub><i>y</i><sub>2</sub></sub> ≤ ... ≤ <i>x<sub>y<sub>k</sub></sub></i> < <i>x<sub>y<sub>k</sub></sub></i> + <i>B<sub>y<sub>k</sub></sub></i> ≤ <i>T</i></li>
<li> <i>x<sub>y<sub>i</sub></sub></i> < <i>S</i> < <i>x<sub>y<sub>i</sub></sub></i> + <i>B<sub>y<sub>i</sub></sub></i> ãšãªããããª<i>i</i> ã¯ååšããªãïŒ</li>
</ul>
<p>
éžã°ããå€åºã®æ¥œãã<i>A</i><sub><i>y</i><sub>1</sub></sub>, <i>A</i><sub><i>y</i><sub>2</sub></sub>, ... <i>A<sub>y<sub>k</sub></sub></i> ã®åèšã<i>M</i> ãšããïŒå€ªéããã¯<i>M</i> ãã§ããã ã倧ãããªãããã«äºå®ãç«ãŠãããšæã£ãŠããïŒ
</p>
<h2>課é¡</h2>
<p>
<i>N</i> åã®å€åºã®æ
å ±ãšæå»<i>S</i>, <i>T</i> ãäžããããæïŒ<i>M</i> ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å¶é</h2>
<p>
1 ≤ <i>N</i> ≤ 3000 å€åºã®æ°<br>
1 ≤ <i>T</i> ≤ 3000 å€ç¥ããçµããæå»<br>
0 ≤ <i>S</i> ≤ <i>T</i> æã倧ããªè±ç«ãæã¡äžããããæå»<br>
0 ≤ <i>A<sub>i</sub></i> ≤ 100000 (= 10<sup>5</sup>) å€åºi ã§éãã æã®æ¥œãã<br>
1 ≤ <i>B<sub>i</sub></i> ≤ 3000 å€åº<i>i</i> ã§éã¶ã®ã«ãããæé<br>
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<p>
å
¥åã®1 è¡ç®ã«ã¯æŽæ°<i>N</i>, <i>T</i>, <i>S</i> ã空çœãåºåããšããŠæžãããŠããïŒå€åºã®æ°ã<i>N</i> åïŒå€ç¥ããçµããæå»ã<i>T</i>ïŒæã倧ããªè±ç«ãæã¡äžããããæå»ã<i>S</i> ã§ããããšã衚ãïŒ
</p>
<p>
ç¶ã<i>N</i> è¡ã«ã¯å€åºã®æ
å ±ãæžãããŠããïŒå
¥åã®<i>i</i> + 1 (1 ≤ <i>i</i> ≤ <i>N</i>) è¡ç®ã«ã¯æŽæ°<i>A<sub>i</sub></i>, <i>B<sub>i</sub></i> ã空çœãåºåããšããŠæžãããŠããïŒå€åº<i>i</i> ã§éãã æã®æ¥œããã<i>A<sub>i</sub></i> ã§ïŒå€åº<i>i</i> ã§éã¶ã®ã«ãããæéã<i>B<sub>i</sub></i> ã§ããããšã衚ãïŒ
</p>
<p>
ãŸãïŒãã¹ãŠã®å
¥åã«ãããŠïŒïŒã€ä»¥äžã®äºå®ãç«ãŠãããããšãä¿èšŒãããŠããïŒ
</p>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒ<i>M</i> ã®æå€§å€ãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ
</p>
<h2>æ¡ç¹åºæº</h2>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡ïŒ<br>
é
ç¹ã®10%åã«ã€ããŠã¯ïŒ<i>N</i> ≤ 20 ãæºããïŒ<br>
é
ç¹ã®20%åã«ã€ããŠã¯ïŒ<i>S</i> = 0 ãæºããïŒ<br>
é
ç¹ã®30%åã«ã€ããŠã¯ïŒããã2 ã€ã®æ¡ä»¶ã®å°ãªããšãäžæ¹ãæºããïŒãŸãïŒããã2 ã€ã®æ¡ä»¶ã®äž¡æ¹ãæºãããããªæ¡ç¹çšããŒã¿ã¯ãªãïŒ<br>
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5 20 14
8 9
2 4
7 13
6 3
5 8
</pre>
<h3>åºåäŸ 1</h3>
<pre>
16
</pre>
<p>
ãã®äŸã«ãããŠïŒ<br>
å€åº1 ãæå»0 ã«èšªãïŒ<br>
å€åº2 ãæå»9 ã«èšªãïŒ<br>
å€åº4 ãæå»14 ã«èšªãããããªäºå®ãç«ãŠããšïŒ<i>M</i> ãæã倧ããããããšãã§ããïŒ<br>
ãã®ãšãïŒ<i>M</i> = 8 + 2 + 6 = 16 ã§ããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div> |
p02151 | <h1>Problem C: Phone Number</h1>
<h2>Problem</h2>
<p>
æ ªåŒäŒç€ŸãŠã¯ããã¢ã®é»è©±çªããã³ããã¯æ¯æ¥ãšãŠãé·ãé»è©±çªå·ãé»è©±ã«å
¥åããŠããŸãã<br>
ããæ¥äœãã«ãç²ãããã³ããã¯ãç²ããããé©ãã¹ãèãã«è³ããŸããã<br>
ãé»è©±ã®ãã¿ã³ã®é
眮ãäžŠã¹æ¿ãããå°ãã§ã楜ã§ããã®ã§ã¯ïŒïŒã<br>
<br>
é»è©±ã«ã¯$3 \times 3$ã§çééã«åºåãããæ£æ¹åœ¢ãããã9åã®ãã¹ã«ã¯äžŠã¹æ¿ããããšã®ã§ãã1ãã9ãŸã§ã®ãã¿ã³ããããã1ã€ãã€ã€ããŠããŸãã<br>
é»è©±çªå·ãæã€éããã³ããã¯çæã ãã䜿ã£ãŠã次ã®äºã€ã®æäœãè¡ãããšãã§ããŸãã<br>
</p>
<ul>
<li>人差ãæãä»è§ŠããŠãããã¿ã³ã«èŸºã§é£æ¥ããããããã®ãã¿ã³ã«è§Šããããã«ç§»åãããã</li>
<li>人差ãæãè§ŠããŠãããã¿ã³ãæŒãã</li>
</ul>
<p>
æåã人差ãæã¯1ãã9ãŸã§ã®ããããã®ãã¿ã³ã«è§Šããããã«çœ®ãããšãã§ããŸãã<br>
ãã³ããã¯ãæåã®ãã¿ã³ãæŒããŠããæåŸã®ãã¿ã³ãæŒãçµãããŸã§ã®ã人差ãæã®ç§»ååæ°ãæãå°ããã§ããé
眮ãå¹ççãšèããŠããŸãã<br>
<br>
ããŠãããã«é·ã$N$ã®ãåŸæå
ã®é»è©±çªå·ããããŸãã<br>
ãåŸæå
ã®é»è©±çªå·ã ãèããæã«ãã©ã®ãããªé
眮ãäžçªå¹ççã§ããããïŒ<br>
ãã¿ã³ãäžŠã³æ¿ããããšã§ããã®é
眮ãäœã£ãŠãã ããã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$
$S$
</pre>
<p>
1è¡ç®ã«ãåŸæå
ã®é»è©±çªå·ã®é·ã$N$ãäžããããã<br>
2è¡ç®ã«ãåŸæå
ã®é»è©±çªå·ã1è¡ã«äžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq N \leq 10^5 $</li>
<li>$S$ã¯1ãã9ãŸã§ã®ããããã®æ°åãããªãæåå</li>
</ul>
<h2>Output</h2>
<p>
æãå¹ççãªé
眮ãã3è¡ã«ç©ºçœãå
¥ããã«åºåããã<br>
äœããè§£çãšãªãåŸãé
眮ãè€æ°ããå Žåã¯ãå·Šäžã®æ ãã<br>
123<br>
456<br>
789<br>
ã®é åºã§æ°åã䞊ã¹ãéã«èŸæžé ã§æå°ãšãªããããªãã®ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
10
1236547896
</pre>
<h2>Sample Output 1</h2>
<pre>
123
456
789
</pre>
<h2>Sample Input 2</h2>
<pre>
11
31415926535
</pre>
<h2>Sample Output 2</h2>
<pre>
137
456
892
</pre>
|
p00029 |
<H1>English Sentence</H1>
<p>
Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters.
</p>
<p>
The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces.
</p>
<H2>Input</H2>
<p>
A text is given in a line. You can assume the following conditions:
</p>
<ul>
<li>The number of letters in the text is less than or equal to 1000.</li>
<li> The number of letters in a word is less than or equal to 32.</li>
<li> There is only one word which is arise most frequently in given text.</li>
<li> There is only one word which has the maximum number of letters in given text.</li>
</ul>
<H2>Output</H2>
<p>
The two words separated by a space.
</p>
<H2>Sample Input</H2>
<pre>
Thank you for your mail and your lectures
</pre>
<H2>Output for the Sample Input</H2>
<pre>
your lectures
</pre>
|
p02014 | <h1>Problem K. Rough Sorting</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
For skilled programmers, it is very easy to implement a sorting function. Moreover, they often avoid full sorting to reduce computation time if it is not necessary. Here, we consider "rough sorting" which sorts an array except for some pairs of elements. More formally, we define an array is "$K$-roughly sorted" if an array is sorted except that <b>at most</b> $K$ pairs are in reversed order. For example, '<span>1 3 2 4</span>' is 1-roughly sorted because (3, 2) is only the reversed pair. In the same way, '<span>1 4 2 3</span>' is 2-roughly sorted because (4, 2) and (4, 3) are reversed.
</p>
<p>
Considering rough sorting by exchanging adjacent elements repeatedly, you need less number of swaps than full sorting. For example, '<span>4 1 2 3</span>' needs three exchanges for full sorting, but you only need to exchange once for 2-rough sorting.
</p>
<p>
Given an array and an integer $K$, your task is to find the result of the $K$-rough sorting with a minimum number of exchanges. If there are several possible results, you should output the lexicographically minimum result. Here, the lexicographical order is defined by the order of the first different elements.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$N$ $K$
$x_1$
$\vdots$
$x_N$
</pre>
<p>
The first line contains two integers $N$ and $K$. The integer $N$ is the number of the elements of the array ($1 \leq N \leq 10^5$). The integer $K$ gives how many reversed pairs are allowed ($1 \leq K \leq 10^9$). Each of the following $N$ lines gives the element of the array. The array consists of the permutation of $1$ to $N$, therefore $1 \leq x_i \leq N$ and $x_i \ne x_j$ ($i \ne j$) are satisfied.
</p>
<h2>Output</h2>
<p>
The output should contain $N$ lines. The $i$-th line should be the $i$-th element of the result of the $K$-rough sorting. If there are several possible results, you should output the minimum result with the lexicographical order.
</p>
<h2>Examples</h2>
<h2>Sample Input 1</h2>
<pre>
3 1
3
2
1
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
1
3
2
</pre>
<h2>Sample Input 2</h2>
<pre>
3 100
3
2
1
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
3
2
1
</pre>
<h2>Sample Input 3</h2>
<pre>
5 3
5
3
2
1
4
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
1
3
5
2
4
</pre>
<h2>Sample Input 4</h2>
<pre>
5 3
1
2
3
4
5
</pre>
<h2>Output for Sample Input 4</h2>
<pre>
1
2
3
4
5
</pre>
<p>
In the last example, the input array is already sorted, which means the input is already a 3-roughly sorted array and no swapping is needed.
</p>
|
p00479 |
<H1>ã¿ã€ã« (Tile)</H1>
<h2>åé¡</h2>
<p>
JOI 髿 ¡ã§ã¯ïŒ 1 × 1 ã®æ£æ¹åœ¢ã®ã¿ã€ã«ã䜿ã£ãŠ N × N ã®æ£æ¹åœ¢ã®å£ç»ãäœãïŒæåç¥ã§å±ç€ºããããšã«ãªã£ãïŒã¿ã€ã«ã®è²ã¯ïŒèµ€ïŒéïŒé»ã® 3 çš®é¡ã§ããïŒå£ç»ã®ãã¶ã€ã³ã¯æ¬¡ã®éãã§ããïŒãŸãïŒæãå€åŽã®åšã«èµ€ã®ã¿ã€ã«ã貌ãïŒãã®å
åŽã®åšã«éã®ã¿ã€ã«ã貌ãïŒããã«ãã®å
åŽã®åšã«é»è²ã®ã¿ã€ã«ã貌ãïŒããã N × N ã®æ£æ¹åœ¢ãåãå°œãããããŸã§ç¹°ãè¿ãïŒçšããã¿ã€ã«ã®è²ã¯ïŒäžçªå€åŽã®åšããé çªã«èµ€ïŒéïŒé»ïŒèµ€ïŒéïŒé»ïŒâŠã§ããïŒ
</p>
<p>
æåç¥ãè¿ã¥ããŠããããæ¥ïŒå£ç»ã®ãã¡ K æã®ã¿ã€ã«ãã¯ãããŠããããšã倿ããïŒããã§ïŒæ°ããã¿ã€ã«ã賌å
¥ããŠïŒã¯ãããç®æã«æ°ããã¿ã€ã«ã貌ãããšã«ããïŒ
</p>
<p>
å
¥åãšããŠå£ç»ã®äžèŸºã®é·ã N ãšïŒã¯ãããã¿ã€ã«ã®ææ° KïŒ K æã®ã¯ãããã¿ã€ã«ã®äœçœ®ãäžãããããšãïŒã¯ãããã¿ã€ã«ã®è²ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<p>
äŸãã°ïŒN = 11 ã®å ŽåïŒ11 × 11 ã®å£ç»ã®ãã¶ã€ã³ã¯äžå³ã®éãã§ããïŒ
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0556_1">
<p>
ãŸãïŒN = 16 ã®å ŽåïŒ16 × 16 ã®å£ç»ã®ãã¶ã€ã³ã¯äžå³ã®éãã§ããïŒ
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0556_2">
<br>
<h2>å
¥å</h2>
<p>
å
¥åã¯å
šéšã§ 2+K è¡ãããªãïŒ 1 è¡ç®ã«ã¯ïŒå£ç»ã®äžèŸºã®é·ã N ïŒ1 ≤ N ≤ 1000000000 = 10<sup>9</sup>ïŒãïŒ 2 è¡ç®ã«ã¯ïŒã¯ãããã¿ã€ã«ã®ææ° K ïŒ1 ≤ K ≤ 1000ïŒãæžãããŠããïŒ 2+i è¡ç®ïŒ1 ≤ i ≤ KïŒã«ã¯ïŒ2 ã€ã®æŽæ° ai ãš bi ïŒ1 ≤ ai ≤ N, 1 ≤ bi ≤ NïŒã空çœåºåãã§æžãããŠããïŒ i æç®ã®ã¯ãããã¿ã€ã«ãïŒå·Šãã ai åç®ïŒäžãã bi è¡ç®ã®ã¿ã€ã«ã§ããããšã衚ãïŒ
</p>
<p>
å
¥åã® 3 è¡ç®ãã 2+K è¡ç®ã«ã¯åãã¿ã€ã«ã衚ãè¡ãéè€ããŠçŸããããšã¯ãªãïŒãŸãïŒäžããããå
¥åããŒã¿ 40% ã§ã¯ïŒ N ≤ 1000 ãã¿ãããŠããïŒ
</p>
<h2>åºå</h2>
<p>
åºå㯠K è¡ãããªãïŒåè¡ã¯ 1 ã€ã®æŽæ°ãããªãïŒ i è¡ç®ïŒ1 ≤ i ≤KïŒã®æŽæ°ã¯ïŒi æç®ã®ã¯ãããã¿ã€ã«ãèµ€ã®ãšã㯠1 ãïŒéã®ãšã㯠2 ãïŒé»è²ã®ãšã㯠3 ã衚ãïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
11
4
5 2
9 7
4 4
3 9
</pre>
<h3>åºåäŸ 1</h3>
<pre>
2
3
1
3
</pre>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
16
7
3 7
5 2
11 6
15 2
9 7
8 12
15 16
</pre>
<h3>åºåäŸ 2</h3>
<pre>
3
2
3
2
1
2
1
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
<br>
|
p02444 | <h1>Rotate</h1>
<p>
Write a program which reads a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ and rotate specified elements by a list of the following operation:
</p>
<ul>
<li>rotate($b, m, e$): For each integer $k$ ($0 \leq k < (e - b)$), move element $b + k$ to the place of element $b + ((k + (e - m)) \mod (e - b))$.</li>
</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 \; m_1 \; e_1$
$b_2 \; m_2 \; e_2$
:
$b_{q} \; m_{q} \; e_{q}$
</pre>
<p>
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; m_i \; e_i$ in the following $q$ lines.
</p>
<h2>Output</h2>
<p>
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$-1,000,000,000 \leq a_i \leq 1,000,000,000$</li>
<li>$1 \leq q \leq 1,000$</li>
<li>$0 \leq b_i \leq m_i < e_i \leq n$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
11
1 2 3 4 5 6 7 8 9 10 11
1
2 6 9
</pre>
<h2>Sample Output 1</h2>
<pre>
1 2 7 8 9 3 4 5 6 10 11
</pre>
|
p00183 |
<H1>äžç®äžŠã¹</H1>
<p>
3 × 3 ã®ç€é¢ã®äžç®äžŠã¹ãèããŸããããäžç®äžŠã¹ã¯ 2 人ã§è¡ã察æŠã²ãŒã ã§ããå
æ»åŸæ»ã決ããäžäººã¯é»ç³ãäžäººã¯çœç³ãæã¡ãŸããç€é¢ã«ç³ã亀äºã«äžã€ãã€çœ®ããŠããã瞊暪æãã®ããããã®æ¹åã«å
ã« 3 ã€èªåã®ç³ã䞊ã¹ã人ãåã¡ãšãªããŸãã
</p>
<p>
ç€é¢ã®æ
å ±ãå
¥åãšããåæã®å€å®ãè¡ããé»ãåã¡ã®å Žåã¯ãbããçœãåã¡ã®å Žåã¯ãwããã©ã¡ããããã£ãŠããªãå Žåã¯ãNAããšåºåããããã°ã©ã ãäœæããŠãã ããã ç€é¢ã®æ
å ±ã¯ã3è¡3åã®æååã§æ§æãããŸãããbãã¯é»ç³ããwãã¯çœç³ãã+ã(åè§ãã©
ã¹)ã¯äœã眮ãããŠããªãç¶æ³ã衚ããŸãããã ããåæã«é»ã3ã€ãçœã3ã€äžŠã¶ããšã¯ãããŸã
ãã
</p>
<!--<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ticktacktoe">-->
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>board<sub>1</sub></var>
<var>board<sub>2</sub></var>
<var>board<sub>3</sub></var>
</pre>
<p>
<var>i</var> è¡ç®ã«ç€é¢ã® <var>i</var> è¡ç®ã®æ
å ±ã衚ãæåå <var>board<sub>i</sub></var> ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«ããbãããwãããNAãã®ãããããïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
bbw
wbw
+b+
bwb
wbw
wbw
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
b
NA
</pre>
|
p02917 | <span class="lang-en">
<p>Score : <var>300</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> whose values are unknown.</p>
<p>Given is an integer sequence <var>B</var> of length <var>N-1</var> which is known to satisfy the following:</p>
<p><var> B_i \geq \max(A_i, A_{i+1}) </var></p>
<p>Find the maximum possible sum of the elements 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 \leq N \leq 100</var></li>
<li><var>0 \leq B_i \leq 10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>B_1</var> <var>B_2</var> <var>...</var> <var>B_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the elements of <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p><var>A</var> can be, for example, ( <var>2</var> , <var>1</var> , <var>5</var> ), ( <var>-1</var> , <var>-2</var> , <var>-3</var> ), or ( <var>2</var> , <var>2</var> , <var>5</var> ). Among those candidates, <var>A</var> = ( <var>2</var> , <var>2</var> , <var>5</var> ) has the maximum possible sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
0 153 10 10 23
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>53
</pre></section>
</div>
</span> |
p03605 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>It is September <var>9</var> in Japan now.</p>
<p>You are given a two-digit integer <var>N</var>. Answer the question: Is <var>9</var> contained in the decimal notation of <var>N</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>10â€Nâ€99</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>9</var> is contained in the decimal notation of <var>N</var>, print <code>Yes</code>; if not, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>29
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>The one's digit of <var>29</var> is <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>72
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>72</var> does not contain <var>9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>91
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p01638 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: { inlineMath: [['\\(','\\)']] }
});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<h1 class="ndoc-heading1">Problem E: Pie Chart is as easy as
pie.</h1>
<p>ICPC World Finals 3æ¥ç®</p>
<p class="ndoc-top">ãã®æ¥ããã£ãŒæ°ã¯ããŒã å
ã®èšèªäœ¿çšå²åã調ã¹ãŠããã
çããããšã«ãæã
ã®ããŒã ã¯äœ¿çšèšèªãçµ±äžããŠããªãã 調æ»ã®çµæã2人ãC++ã1人ãJavaã䜿ã£ãŠããããšãåãã£ãã
ããŠãããããã€ãã£ãŒãïŒåã°ã©ãïŒã«ããŠã¿ããã</p>
<p class="ndoc-top"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie1" alt="pie1.png" width="400"></p>
<p class="ndoc-top">ãããJavaã®äœ¿çšå²åãå°ãªãããã«èŠãããªã
ã©ãèããŠããããªã¯ãã¯ãªãã®ã§å°ã
æãå ãããã ããã¯æè¿æµè¡ãã®ãã¯ããã¯ã§ããã
ããã€ãã£ãŒãã®äžå¿åº§æšããããããšãããã®ã ã ïŒçããã¯ããããŠã¯ãããŸãããïŒ</p>
<p class="ndoc-top"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie2" alt="pie2.png" width="400"></p>
<p class="ndoc-top">ãããããã§ãã©ã³ã¹ããšããã ãšããã§é¢ç©ã¯ã©ã®ããã«å€ãã£ãã®ã ããïŒ</p>
<h2 class="ndoc-heading2">åé¡</h2>
<p class="ndoc-top">ååŸ\(r\)ãé
ç®æ°\(n\)ã®ãã€ãã£ãŒãïŒåã°ã©ãïŒãäžããããã
é
ç®\(i\)ã®æ§ææ¯çã¯\( p_{i} \)[%]ã§ããã座æš\( (0, r)
\)ããæèšåãã«é
ç®ãå²ãåœãŠãããïŒäžå³ãåç
§ïŒã ãã€ãã£ãŒãã®äžå¿åº§æšã\( (0, 0) \)ãã\( (x, y)
\)ã«å€åããæã åé
ç®ã®å ããé¢ç©ã¯äœ%å€åããããæ±ããã</p>
<p class="ndoc-top"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie" alt="pie.png" width="400"></p>
<h2 class="ndoc-heading2">å
¥å</h2>
<pre>
r x y n
p<sub>1</sub> p<sub>2</sub> ⊠p<sub>n</sub>
</pre>
1è¡ç®ã« ãã€ãã£ãŒãã®ååŸ\(r\)ãäžå¿ã®x座æš\(x\)ãy座æš\(y\)ãé
ç®æ°\(n\)ã空çœåºåãã§äžããããã
2è¡ç®ã«ã¯ã é
ç®\(i\)ã®æ§ææ¯ç\( p_{i} \)[%]ã空çœåºåãã§äžããããã
<h2 class="ndoc-heading2">åºå</h2>
<p class="ndoc-top">
1è¡ç®ã«åé
ç®ã®å ããé¢ç©ã®å€åç[%]ããæŽæ°ã«åãæšãŠãå€ãã空çœåºåãã§åºåããã</p>
<h2 class="ndoc-heading2">å¶çŽ</h2>
<ul class="ndoc-indent">
<li>å
¥åã¯å
šãп޿°ã§äžãããã</li>
<li>\( r = 100 \)</li>
<li>\( x^{2} + y^{2} < r^{2} \)</li>
<li>\( 2 \leq n \leq 10 \)</li>
<li>\( p_{i} > 0 (1 \leq i \leq n) \)</li>
<li>\( \sum_{1 \leq i \leq n}p_{i} = 100 \)</li>
<li>\( (x, y) \)ãé«ã
è·é¢\( 10^{-3} \)ç§»åããŠãçããå€åããªãããšãä¿èšŒããã</li>
</ul>
<h2 class="ndoc-heading2">å
¥åºåäŸ</h2>
<h3 class="ndoc-heading3">å
¥å1</h3>
<pre>
100 50 -50 2
67 33
</pre>
<h3 class="ndoc-heading3">åºå1</h3>
<pre>
71 156
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie_sample_1" alt="pie_sample_1.png" width="400">
<p class="ndoc-top">é
ç®1ã®é¢ç©ã¯çŽ21048ããçŽ15153ã«å€åããã å€åçã¯15153/21048 â
71.99%ã</p>
<p class="ndoc-top">é
ç®2ã®é¢ç©ã¯çŽ10367ããçŽ16262ã«å€åããã å€åçã¯16262/10367 â
156.86%ã</p>
<h3 class="ndoc-heading3">å
¥å2</h3>
<pre>
100 -50 0 4
10 20 30 40
</pre>
<h3 class="ndoc-heading3">åºå2</h3>
<pre>
115 144 113 64
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie_sample_2" alt="pie_sample_2.png" width="400">
<p class="ndoc-top">é
ç®ããšã®ãããã®é¢ç©ã®å€åã¯ä»¥äžã®éãã</p>
<ul class="ndoc-indent">
<li>é
ç®1: 3142 â 3619</li>
<li>é
ç®2: 6283 â 9078</li>
<li>é
ç®3: 9425 â 10675</li>
<li>é
ç®4: 12566 â 8044</li>
</ul>
<h3 class="ndoc-heading3">å
¥å3</h3>
<pre>
100 70 -70 8
1 24 1 24 1 24 1 24
</pre>
<h3 class="ndoc-heading3">åºå3</h3>
<pre>
167 97 27 10 32 102 172 189
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie_sample_3" alt="pie_sample_3.png" width="400"> |
p03255 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has decided to use a robot to clean his room.</p>
<p>There are <var>N</var> pieces of trash on a number line.
The <var>i</var>-th piece from the left is at position <var>x_i</var>.
We would like to put all of them in a trash bin at position <var>0</var>.</p>
<p>For the positions of the pieces of trash, <var>0 < x_1 < x_2 < ... < x_{N} \leq 10^{9}</var> holds.</p>
<p>The robot is initially at position <var>0</var>.
It can freely move left and right along the number line, pick up a piece of trash when it comes to the position of that piece, carry any number of pieces of trash and put them in the trash bin when it comes to position <var>0</var>. It is not allowed to put pieces of trash anywhere except in the trash bin.</p>
<p>The robot consumes <var>X</var> points of energy when the robot picks up a piece of trash, or put pieces of trash in the trash bin. (Putting any number of pieces of trash in the trash bin consumes <var>X</var> points of energy.)
Also, the robot consumes <var>(k+1)^{2}</var> points of energy to travel by a distance of <var>1</var> when the robot is carrying <var>k</var> pieces of trash.</p>
<p>Find the minimum amount of energy required to put all the <var>N</var> pieces of trash in the trash bin.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^{5}</var></li>
<li><var>0 < x_1 < ... < x_N \leq 10^9</var></li>
<li><var>1 \leq X \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li><var>400</var> points will be awarded for passing the test set satisfying <var>N \leq 2000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 100
1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>355
</pre>
<ul>
<li>Travel to position <var>10</var> by consuming <var>10</var> points of energy.</li>
<li>Pick up the piece of trash by consuming <var>100</var> points of energy.</li>
<li>Travel to position <var>1</var> by consuming <var>36</var> points of energy.</li>
<li>Pick up the piece of trash by consuming <var>100</var> points of energy.</li>
<li>Travel to position <var>0</var> by consuming <var>9</var> points of energy.</li>
<li>Put the two pieces of trash in the trash bin by consuming <var>100</var> points of energy.</li>
</ul>
<p>This strategy consumes a total of <var>10+100+36+100+9+100=355</var> points of energy.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 1
1 999999997 999999998 999999999 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>19999999983
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 8851025
38 87 668 3175 22601 65499 90236 790604 4290609 4894746
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>150710136
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>16 10
1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3256017715
</pre></section>
</div>
</span> |
p01268 |
<h1><font color="#000">Problem B:</font> Matsuzaki Number</h1>
<p>
Matsuzaki ææã¯ïŒå®å®ã®ççãç ç©¶ããŠããç§åŠè
ã§ããïŒäººçïŒå®å®ïŒãã¹ãŠã®çã㯠42 ã§ãããšèšãããŠãããïŒMatsuzaki ææã¯ããã ãã§ã¯å®å®ã®ççãè§£æããã«ã¯äžååã§ãããšèããŠããïŒMatsuzaki ææã¯ïŒå®å®ã®çç㯠2 ã€ã®ãã©ã¡ãŒã¿ãããªã颿°ã§è¡šããããšèããŠããïŒ42 ã¯ãã® 1 ã€ã«éããªããšããã®ã§ããïŒ
</p>
<p>
Matsuzaki ææã®å®çŸ©ãã颿° M(<i>N</i>, <i>P</i>) ã¯ïŒ<i>N</i> ãã倧ããçŽ æ°ã 2 ã€éžãã§ïŒåãæ°ã 2 ã€ã§ãæ§ããªãïŒåããšãããšã§åŸãããæ°ã®å
šäœãïŒå°ããã»ãããé çªã«äžŠã¹ããšãã«ïŒ<i>P</i> çªç®ã«çŸããæ°ã衚ãïŒããã§ïŒ2 éã以äžã®åã§è¡šããããããªæ°ãååšãããïŒãããã£ãæ°ã¯åã®çµã¿åããã®æ°ãšåãåæ°ã ã䞊ã¹ãããïŒ
</p>
<p>
äŸãšã㊠<i>N</i> = 0 ã®å ŽåãèãããïŒãã®ãšãã¯çŽ æ°å
šäœãã 2 ã€ãéžãã§åããšãããšã«ãªãïŒãããã£ãåã®ãã¡ã§æå°ã®æ°ãèãããšïŒåãæ°ã 2 åéžã¶ããšãèš±ãããŠããããšããïŒ2 + 2 = 4 ã§ããããšããããïŒããªãã¡ M(0, 1) = 4 ã§ããïŒæ¬¡ã«å°ããæ°ã¯ 2 + 3 = 5 ã§ãããã M(0, 2) = 5 ãšãªãïŒåæ§ã«ããŠèãããšïŒåã䞊ã¹ããã®ã¯ 4, 5, 6, 7, 8, 9, 10, 10, 12, 13, 14, 14, 16, ... ã®ããã«ãªãããšããããïŒããªãã¡ïŒããšãã° M(0, 9) = 12 ã§ããïŒ
</p>
<p>
åãããã«ã㊠<i>N</i> = 10 ã®å ŽåãèãããšïŒãã®ãšã㯠10 ãã倧ããçŽ æ° {11, 13, 17, 19, ...} ãã 2 ã€ãéžã¶ããšã«ãªãïŒåŸãããåãå°ããã»ããã䞊ã¹ããš 22, 24, 26, 28, 30, 30, 32, ... ã®ããã«ãªãïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒ<i>N</i> ãš <i>P</i> ãäžããããæã« M(<i>N</i>, <i>P</i>) ãèšç®ããããã°ã©ã ãæžãããšã§ããïŒ
</p>
<h3>Input</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒããŒã¿ã»ãã㯠1 è¡ã§ããïŒ2 ã€ã®æŽæ° <i>N</i> (0 ≤ <i>N</i> ≤ 100,000) ãš <i>P</i> (1 ≤ <i>P</i> ≤ 100) ã 1 ã€ã®ç©ºçœã§åºåãããŠäžããããïŒ
</p>
<p>
å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã 2 ã€ã® -1 ãå«ã 1 è¡ã§ç€ºãããïŒ
</p>
<h3>Output</h3>
<p>
åããŒã¿ã»ããã«å¯ŸããŠïŒM(<i>N</i>, <i>P</i>) ã®å€ã 1 è¡ã«åºåããïŒåºåã«äœèšãªç©ºçœãæ¹è¡ãå«ããŠã¯ãªããªãïŒ
</p>
<h3>Sample Input</h3>
<pre>
0 55
0 1
0 2
0 3
10 1
10 2
10 3
10 4
10 5
10 6
11 1
11 2
11 3
100000 100
-1 -1
</pre>
<h3>Output for the Sample Input</h3>
<pre>
42
4
5
6
22
24
26
28
30
30
26
30
32
200274
</pre>
|
p00880 |
<H1><font color="#000">Problem G:</font> Malfatti Circles</H1>
<p>
The configuration of three circles packed inside a triangle such that each circle is tangent to the
other two circles and to two of the edges of the triangle has been studied by many mathematicians
for more than two centuries. Existence and uniqueness of such circles for an arbitrary triangle
are easy to prove. Many methods of numerical calculation or geometric construction of such
circles from an arbitrarily given triangle have been discovered. Today, such circles are called the
<i>Malfatti circles</i>.
</p>
<p>
Figure 7 illustrates an example. The Malfatti circles of the triangle with the vertices (20, 80),
(-40, -20) and (120, -20) are approximately
</p>
<ul>
<li> the circle with the center (24.281677, 45.219486) and the radius 21.565935,</li>
<li> the circle with the center (3.110950, 4.409005) and the radius 24.409005, and</li>
<li> the circle with the center (54.556724, 7.107493) and the radius 27.107493.</li>
</ul>
<p>
Figure 8 illustrates another example. The Malfatti circles of the triangle with the vertices
(20, -20), (120, -20) and (-40, 80) are approximately
</p>
<ul>
<li> the circle with the center (25.629089, â10.057956) and the radius 9.942044,</li>
<li> the circle with the center (53.225883, â0.849435) and the radius 19.150565, and</li>
<li> the circle with the center (19.701191, 19.203466) and the radius 19.913790.</li>
</ul>
<p>
Your mission is to write a program to calculate the radii of the Malfatti circles of the given
triangles.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_malfattiCircles">
</center>
<H2>Input</H2>
<p>
The input is a sequence of datasets. A dataset is a line containing six integers <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub> , <i>x</i><sub>2</sub> , <i>y</i><sub>2</sub>, <i>x</i><sub>3</sub>
and <i>y</i><sub>3</sub> in this order, separated by a space. The coordinates of the vertices of the given triangle
are (<i>x</i><sub>1</sub> , <i>y</i><sub>1</sub> ), (<i>x</i><sub>2</sub> , <i>y</i><sub>2</sub> ) and (<i>x</i><sub>3</sub> , <i>y</i><sub>3</sub> ), respectively. You can assume that the vertices form a triangle
counterclockwise. You can also assume that the following two conditions hold.
</p>
<ul>
<li> All of the coordinate values are greater than â1000 and less than 1000.</li>
<li> None of the Malfatti circles of the triangle has a radius less than 0.1.</li>
</ul>
<p>
The end of the input is indicated by a line containing six zeros separated by a space.
</p>
<H2>Output</H2>
<p>
For each input dataset, three decimal fractions <i>r</i><sub>1</sub> , <i>r</i><sub>2</sub> and <i>r</i><sub>3</sub> should be printed in a line in this
order separated by a space. The radii of the Malfatti circles nearest to the vertices with the
coordinates (<i>x</i><sub>1</sub> , <i>y</i><sub>1</sub> ), (<i>x</i><sub>2</sub> , <i>y</i><sub>2</sub> ) and (<i>x</i><sub>3</sub> , <i>y</i><sub>3</sub> ) should be <i>r</i><sub>1</sub> , <i>r</i><sub>2</sub> and <i>r</i><sub>3</sub> , respectively.
</p>
<p>
None of the output values may have an error greater than 0.0001. No extra character should
appear in the output.
</p>
<H2>Sample Input</H2>
<pre>
20 80 -40 -20 120 -20
20 -20 120 -20 -40 80
0 0 1 0 0 1
0 0 999 1 -999 1
897 -916 847 -972 890 -925
999 999 -999 -998 -998 -999
-999 -999 999 -999 0 731
-999 -999 999 -464 -464 999
979 -436 -955 -337 157 -439
0 0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
21.565935 24.409005 27.107493
9.942044 19.150565 19.913790
0.148847 0.207107 0.207107
0.125125 0.499750 0.499750
0.373458 0.383897 0.100456
0.706768 0.353509 0.353509
365.638023 365.638023 365.601038
378.524085 378.605339 378.605339
21.895803 22.052921 5.895714
</pre>
|
p01792 |
<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 C
Casino</h2>
<p>
Taro, who owes a debt of $n$ dollars, decides to make money in a casino, where he can double his wager with probability $p$ percent in a single play of a game. Taro is going to play the game repetitively. He can choose the amount of the bet in each play, as long as it is a positive integer in dollars and at most the money in his hand.
</p>
<p>
Taro possesses $m$ dollars now. Find out the maximum probability and the optimum first bet that he can repay all his debt, that is, to make his possession greater than or equal to his debt.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case, which consists of three integers $p$, $m$, and $n$ separated by single
spaces $(0 \leq p \leq 100, 0 < m < n \leq 10^9)$.
</p>
<h3>Output</h3>
<p>
Display three lines: The first line should contain the maximum probability that Taro can repay all his debt. This value must have an absolute error at most $10^{-6}$. The second line should contain an integer representing how many optimum first bets are there. Here, a first bet is optimum if the bet is necessary to achieve the maximum probability. If the number of the optimum first bets does not exceed 200, the third line should contain all of them in ascending order and separated by single spaces. Otherwise the third line should contain the 100 smallest bets and the 100 largest bets in ascending order and separated by single spaces.
</p>
<h3>Sample Input 1</h3>
<pre>60 2 3</pre>
<h3>Output for the Sample Input 1</h3>
<pre>0.789473
1
1</pre>
<h3>Sample Input 2</h3>
<pre>25 3 8</pre>
<h3>Output for the Sample Input 2</h3>
<pre>0.109375
2
1 3</pre> |
p00750 |
<h1><font color="#000000">Problem E:</font> The Most Powerful Spell</h1>
<!-- end en only -->
<!-- begin en only -->
<p>
Long long ago, there lived a wizard who invented a lot of "magical patterns."
In a room where one of his magical patterns is drawn on the floor,
anyone can use magic by casting magic spells!
The set of spells usable in the room depends on the drawn magical pattern.
Your task is to compute, for each given magical pattern,
the most powerful spell enabled by the pattern.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A spell is a string of lowercase letters.
Among the spells, lexicographically earlier one is more powerful.
Note that a string <em>w</em> is defined to be lexicographically earlier than a string <em>u</em>
when <em>w</em> has smaller letter
in the order a<b<...<z on the first position at which they differ,
or <em>w</em> is a prefix of <em>u</em>.
For instance, "abcd" is earlier than "abe" because 'c' < 'e',
and "abe" is earlier than "abef" because the former is a prefix of the latter.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
A magical pattern is a diagram consisting of uniquely numbered <em>nodes</em>
and <em>arrows</em> connecting them.
Each arrow is associated with its <em>label</em>, a lowercase string.
There are two special nodes in a pattern, called the <em>star node</em>
and the <em>gold node</em>.
A spell becomes usable by a magical pattern if and only if the spell emerges
as a sequential concatenation of the labels of a path from the star to the gold along the arrows.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The next figure shows an example of a pattern with four nodes and
seven arrows.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_E-3" width="312" height="283" alt="picture: sample dataset 1">
</center>
<!-- end en only -->
<!--
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/E-1" width="272" height="283" alt="picture: sample dataset 1">
-->
<!-- begin en only -->
<p>
The node 0 is the star node and 2 is the gold node.
One example of the spells that become usable by this magical pattern is "abracadabra",
because it appears in the path
</p><p>
0 --"abra"--> 1 --"cada"--> 3 --"bra"--> 2.
</p><p>
Another example is "oilcadabraketdadabra", obtained from the path
</p><p>
0 --"oil"--> 1 --"cada"--> 3 --"bra"--> 2 --"ket"--> 3 --"da"--> 3 --"da"--> 3 --"bra"--> 2.
</p><p>
The spell "abracadabra" is more powerful than "oilcadabraketdadabra"
because it is lexicographically earlier.
In fact, no other spell enabled by the magical pattern is more powerful than "abracadabra".
Thus "abracadabra" is the answer you have to compute.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
When you cannot determine the most powerful spell, please answer "NO".
There are two such cases.
One is the case when no path exists from the star node to the gold node.
The other case is when for every usable spell there always exist more powerful spells.
The situation is exemplified in the following figure:
"ab" is more powerful than "b", and "aab" is more powerful than "ab", and so on.
For any spell, by prepending "a", we obtain a lexicographically earlier
(hence more powerful) spell.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_E-2" width="242" height="123" alt="picture: sample dataset 2"/>
</center>
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of at most 150 datasets.
Each dataset is formatted as follows.
</p>
<!-- end en only -->
<blockquote>
<i>n a s g</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>lab</i><sub>1</sub><br>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>lab</i><sub>2</sub><br>
...<br>
<i>x<sub>a</sub> <i>y</i><sub>a</sub> <i>lab</i><sub>a</sub></i><br>
</pre>
</blockquote>
<!-- begin en only -->
<p>
The first line of a dataset contains four integers.
<i>n</i> is the number of the nodes, and <i>a</i> is the number of the arrows.
The numbers <i>s</i> and <i>g</i> indicate the star node and the gold node, respectively.
Then <i>a</i> lines describing the arrows follow.
Each line consists of two integers and one string.
The line "<i>x<sub>i</sub></i> <i>y<sub>i</sub></i> <i>lab<sub>i</sub></i>" represents
an arrow from the node <i>x<sub>i</sub></i> to the node <i>y<sub>i</sub></i>
with the associated label <i>lab<sub>i</sub></i> .
Values in the dataset satisfy:
2 ≤ <i>n</i> ≤ 40,
0 ≤ <i>a</i> ≤ 400,
0 ≤ <i>s</i>, <i>g</i>, <i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> < <i>n</i> ,
<i>s</i> ≠<i>g</i>,
and
<i>lab<sub>i</sub></i> is a string of 1 to 6 lowercase letters.
Be careful that there may be self-connecting arrows (i.e., <i>x<sub>i</sub></i> = <i>y<sub>i</sub></i> ),
and multiple arrows connecting the same pair of nodes
(i.e., <i>x<sub>i</sub></i> = <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> = <i>y<sub>j</sub></i>
for some <i>i</i> ≠ <i>j</i> ).
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing four zeros.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a line containing the most powerful spell for the magical pattern.
If there does not exist such a spell, output "NO" (without quotes).
Each line should not have any other characters.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
4 7 0 2
0 1 abra
0 1 oil
2 0 ket
1 3 cada
3 3 da
3 2 bra
2 3 ket
2 2 0 1
0 0 a
0 1 b
5 6 3 0
3 1 op
3 2 op
3 4 opq
1 0 st
2 0 qr
4 0 r
2 1 0 1
1 1 loooop
0 0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
abracadabra
NO
opqr
NO
</pre>
|
p01842 |
<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>
<h2>D - ã€ã³ããžãã«</h2>
<h3>Problem Statement</h3>
<p>
ããªãã¯åéãš"<samp>ã€ã³ããžãã«</samp>"ãšããã«ãŒãã²ãŒã ãéãŒããšããŠããïŒ
ãã®ã«ãŒãã²ãŒã ã§ã¯ïŒ"<samp>åŸç¹ã«ãŒã</samp>"ãš"<samp>劚害ã«ãŒã</samp>"ãšãã2çš®é¡ã®ã«ãŒãã䜿ãïŒ
ããããã®åŸç¹ã«ãŒãã«ã¯ïŒæ£ã®å€ãæžãããŠããïŒãã®ã«ãŒãã²ãŒã ã®ã«ãŒã«ã¯æ¬¡ã®éãã§ããïŒ
</p>
<ul>
<li> ã²ãŒã ã¯ãã¬ã€ã€ãŒ1ãšãã¬ã€ã€ãŒ2ã®2人ã®ãã¬ã€ã€ãŒã§è¡ãããïŒã²ãŒã ã¯ãã¬ã€ã€ãŒ1ã®ã¿ãŒã³ããå§ãŸãïŒ
</li>
<li> å Žã«ã¯ïŒ1ã€ã®ã¹ã¿ãã¯ãš2ã€ã®ããããããïŒã¹ã¿ãã¯ã¯ïŒ2人ã®ãã¬ã€ã€ãŒã眮ããã«ãŒããããªãïŒãŸãïŒããããã®ãã¬ã€ã€ãŒãæã€ãããã¯ãã®ãã¬ã€ã€ãŒãæã€åŸç¹ã«ãŒããšåŠšå®³ã«ãŒããããªãïŒãã¬ã€ã€ãŒã¯èªåïŒãããã¯çžæãããã®ã«ãŒãã®é çªããã€ã§ã確èªã§ããïŒã²ãŒã ã®éå§æç¹ã§ã¯ã¹ã¿ãã¯ã«ã¯1æãã«ãŒãã¯ãªãïŒ
</li>
<li> 2人ã®ãã¬ã€ã€ãŒã¯äº€äºã«æ¬¡ã®2ã€ã®è¡åã®ã©ã¡ãããã¡ããã©1åè¡ãïŒ
<ul><li> èªåã®ãããã®äžçªäžã®ã«ãŒããã¹ã¿ãã¯ã®äžçªäžã«çœ®ãïŒãã ãïŒãã®è¡åã¯èªåã®ãããã«ã«ãŒãã1æãååšããªãæã«ã¯è¡ãããšãã§ããªãïŒ
</li><li> èªåã®ã¿ãŒã³ããã¹ããïŒ
</li></ul>
</li>
<li> ãã¬ã€ã€ãŒãã¿ãŒã³ããã¹ããæïŒæ¬¡ã®åŠçãè¡ãïŒ
<ul><li> åãã¬ã€ã€ãŒã¯æ¬¡ã®2ã€ã®æ¡ä»¶ãæºããã¹ã¿ãã¯äžã®ãã¹ãŠã®åŸç¹ã«ãŒããåŸãïŒåŸãåŸç¹ã«ãŒãã¯å Žããåãé€ãããïŒ
<ol><li> èªåãã¹ã¿ãã¯ã«ãããåŸç¹ã«ãŒãã§ããïŒ
</li><li> çžæã眮ããã©ã®åŠšå®³ã«ãŒããããäžã«ãã (ã¹ã¿ãã¯äžã«çžæã®åŠšå®³ã«ãŒããååšããªããšãïŒãã¬ã€ã€ãŒã¯èªåãã¹ã¿ãã¯ã«çœ®ãããã¹ãŠã®ã«ãŒããåŸã)ïŒ
</li></ol>
</li>
<li> ã¹ã¿ãã¯ã®ã«ãŒãããã¹ãŠåãé€ãïŒ
</li></ul>
</li></ul>
<p>
ããã¹ã¿ãã¯ã«ã«ãŒãããªãç¶æ
ã§äž¡ãã¬ã€ã€ãŒãé£ç¶ããŠãã¹ããå ŽåïŒã²ãŒã ãçµäºããïŒ
åãã¬ã€ã€ãŒã®æçµçãªã¹ã³ã¢ã¯ïŒåãã¬ã€ã€ãŒãåŸãåŸç¹ã«ãŒãã«æžãããæ°ã®ç·åã§ããïŒ
</p>
<p>
åãã¬ã€ã€ãŒã¯ïŒèªåã®ã¹ã³ã¢ããçžæã®ã¹ã³ã¢ãåŒããå€ãæå€§åããããã«æé©ãªè¡åããšãïŒ
ããªãã®ä»äºã¯ïŒäžããããåãã¬ã€ã€ãŒã®ãããã«å¯ŸãïŒåãã¬ã€ã€ãŒãæé©ã«è¡åãããšãã®ãã¬ã€ã€ãŒ1ã®ã¹ã³ã¢ãšãã¬ã€ã€ãŒ2ã®ã¹ã³ã¢ã®å·®ãèšç®ããããšã§ããïŒ
</p>
<h3>Input</h3>
<p>
å
¥åã¯æ¬¡ã®ãããªåœ¢åŒã®åäžãã¹ãã±ãŒã¹ãããªãïŒ
</p>
<p>
$n$ $m$<br>
$a_1$ $a_2$ $\dots$ $a_n$<br>
$b_1$ $b_2$ $\dots$ $b_m$
</p>
<p>1è¡ç®ã¯å±±æã®ææ°ãè¡šãæ£ã®æŽæ° $n$, $m$ ($1 \le n, m \le 50$) ãããªãïŒ
2è¡ç®ã¯ $n$ åã®æŽæ°ãããªãïŒ$a_i$ ã¯ãã¬ã€ã€ãŒ1ã®ãããã®äžãã $i$ çªç®ã®ã«ãŒãã衚ã ($1 \le i \le n$)ïŒ$a_i$ 㯠$1$ 以äžïŒ$1{,}000{,}000$ 以äžïŒãŸã㯠$-1$ ã§ããïŒ
3è¡ç®ã¯ $m$ åã®æŽæ°ãããªãïŒ$b_j$ ã¯ãã¬ã€ã€ãŒ2ã®ãããã®äžãã $j$ çªç®ã®ã«ãŒãã衚ã ($1 \le j \le m$)ïŒ$b_j$ 㯠$1$ 以äžïŒ$1{,}000{,}000$ 以äžïŒãŸã㯠$-1$ ã§ããïŒ
$a_i$, $b_j$ ãæ£ã®æŽæ°ã®æã¯åŸç¹ã«ãŒãã衚ãïŒ$-1$ ã®æã¯åŠšå®³ã«ãŒãã衚ãïŒ
</p>
<h3>Output</h3>
<p>
ãäºãã®ãã¬ã€ã€ãŒãæé©ã«è¡åããæã® (ãã¬ã€ã€ãŒ1ã®ã¹ã³ã¢) - (ãã¬ã€ã€ãŒ2ã®ã¹ã³ã¢) ãåºåããïŒ
</p>
<h3>Sample Input 1</h3>
<pre>2 2
100 -1
200 300</pre>
<h3>Output for the Sample Input 1</h3>
<pre>-100</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_d-1" height="300" width="400" /><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_d-2" height="300" width="400" /><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_d-3" height="300" width="400" /><br>
</center>
<h3>Sample Input 2</h3>
<pre>3 5
10 30 -1
-1 90 20 10 -1</pre>
<h3>Output for the Sample Input 2</h3>
<pre>0</pre>
<h3>Sample Input 3</h3>
<pre>4 5
15 20 10 30
50 30 10 20 25</pre>
<h3>Output for the Sample Input 3</h3>
<pre>-60</pre> |
p02297 |
<H1>Area</H1>
<br/>
<p>
For a given polygon <var>g</var>, computes the area of the polygon.
</p>
<p>
<var>g</var> is represented by a sequence of points <var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>,..., <var>p<sub>n</sub></var> where line segments connecting <var>p<sub>i</sub></var> and <var>p<sub>i+1</sub></var> (1 ≤ <var>i</var> ≤ <var>n-1</var>) are sides of <var>g</var>. The line segment connecting <var>p<sub>n</sub></var> and <var>p<sub>1</sub></var> is also a side of the polygon.
</p>
<p>
Note that the polygon is not necessarily convex.
</p>
<H2>Input</H2>
<p>
The input consists of coordinates of the points <var>p<sub>1</sub></var>,..., <var>p<sub>n</sub></var> in the following format:
</p>
<pre>
<var>n</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
:
<var>x<sub>n</sub></var> <var>y<sub>n</sub></var>
</pre>
<p>
The first integer <var>n</var> is the number of points. The coordinate of a point <var>p<sub>i</sub></var> is given by two integers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. The coordinates of points are given in the order of counter-clockwise visit of them.
</p>
<H2>Output</H2>
<p>
Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point.
</p>
<H2>Constraints</H2>
<ul>
<li>
3 ≤ <var>n</var> ≤ 100
</li>
<li>
-10000 ≤ <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ≤ 10000
</li>
<li>No point will occur more than once.</li>
<li>Two sides can intersect only at a common endpoint.</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3
0 0
2 2
-1 1
</pre>
<H2>Sample Output 1</H2>
<pre>
2.0
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4
0 0
1 1
1 2
0 2
</pre>
<H2>Sample Output 2</H2>
<pre>
1.5
</pre>
|
p00300 |
<h1>æçæ°ã®ãªãŒãã£ãªã«ãŒã </h1>
<p>
æ°åŠè
ã§ããæçæ°ã®è¶£å³ã¯é³æ¥œéè³ã§ãå®¶ã«å¿µé¡ã®ãªãŒãã£ãªã«ãŒã ãäœããŸããã宿ãããªãŒãã£ãªã«ãŒã ã§ãå人ãæããŠãæ«é²ç®äŒãéããããšèããŠããŸããå
šå¡ã«ã§ããã ãè¯ãé³ã§èŽããŠãããããã®ã§ãéšå±ã®äžã®äœãæãã§é³ãèšæž¬ããå人ãã¡ã®äœçœ®ã§ã®é³ã®è³ªãèšç®ããã€ããã§ãã
</p>
<p>
èšæž¬ç¹ã¯ãäžã®å³ã®å匧ãšç·åã®äº€ç¹ã§ãã 1 çªãã 35 çªãŸã§ã®ç¹ããéžæããŸããïŒã€ã®ç·åäžã«ããç¹ã¯ããªãŒãã£ãªã·ã¹ãã ããã®è·é¢ã 100ïœïœãã 500ïœïœãŸã§ 100ïœïœãã€é¢ããŠäžŠãã§ããŸããïŒã€ã®å匧ç¶ã«ããç¹ã¯ããã£ãšãå³ã®ãã®ïŒ1 çªãã 5 çªãŸã§ã®ç¹ïŒããåæèšåãã«ã0°ãã 180°
ã®ç¯å²ã§ 30°床å»ã¿ã«äžŠãã§ããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio1">
</center>
<br>
<p>
ãã®ãããªå匧ãšç·åã«å²ãŸããé åå
ã®ã©ããã«å人ãå±
ãããšã«ãªãã®ã§ãå人ã®å±
ãäœçœ®ã«ãã£
ãŠå¿
èŠãªèšæž¬ç¹ãéžæããŸããå人ã®äœçœ®ã¯ãååŒ§ã«æ²¿ã£ãŠåæèšåãã«æž¬ã£ãè§åºŠãšãªãŒãã£ãªã·ã¹
ãã ããã®è·é¢ã§äžããããŸããå¿
èŠãªèšæž¬ç¹ã¯ä»¥äžã®ããã«ïŒç¹ããïŒç¹ããïŒç¹ãéžã°ããŸãã
</p>
<table>
<tr valign="top">
<td valign="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio2"></td>
<td valign="top">
å人ãã¡ããã©èšæž¬ç¹ã®äœçœ®ã«ããã°ããã®ïŒç¹ãéžã³ãŸãããã®å³ã®äŸã®å Žåãéžã°ããã®ã¯ 23 çªã®ç¹ã§ãã
</td>
</tr>
<tr valign="top">
<td valign="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio3"></td>
<td valign="top">
å人ãå匧ïŒãŸãã¯ç·åïŒã®äžã«ã¡ããã©ä¹ã£ãŠããã°ããã®å匧ïŒãŸãã¯ç·åïŒäžã«ãããåäººã«æãè¿ãïŒç¹ãéžã³ãŸãããã®å³ã®äŸã®å Žåãéžã°ããã®ã¯ 18 çªãš 23 çªã®ç¹ã§ãã
</td>
</tr>
<tr valign="top">
<td valign="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio4"></td>
<td valign="top">
å人ãå匧ãšç·åã«ãã£ãŠå²ãŸããåºç»ã®å
åŽïŒå匧ãç·åã®äžã§ã¯ãªãïŒã«ããã°ãåºç»ãäœã£ãŠããïŒç¹ãéžã³ãŸãããã®å³ã®äŸã®å Žåãéžã°ããã®ã¯ 17ã18ã22ã23 çªã®ç¹ã§ãã
</td>
</tr>
</table>
<br>
<p>
æçæ°ãå©ããããã«ãå¿
èŠãªèšæž¬ç¹ã®çªå·ãæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>r<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>r<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>r<sub>N</sub></var> <var>t<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«åäººã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 50)ãäžãããããç¶ã <var>N</var> è¡ã«ãå人ã®äœçœ®ãäžãããããå人ã®äœçœ® <var>r<sub>i</sub></var> (100 ≤ <var>r<sub>i</sub></var> ≤ 500) ã¯ãªãŒãã£ãªã·ã¹ãã ããã®è·é¢ãè¡šãæŽæ°ã<var>t<sub>i</sub></var> (0 ≤ <var>t<sub>i</sub></var> ≤ 180) ã¯ååŒ§ã«æ²¿ã£ãŠåæèšåãã«æž¬ã£ãè§åºŠãè¡šãæŽæ°ã§ããã
</p>
<h2>åºå</h2>
<p>
åå人ã®äœçœ®ã«ã€ããŠãèšæž¬ç¹ã®çªå·ãæé ã§ïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸ </h2>
<pre>
4
300 120
300 105
250 105
250 90
</pre>
<h2>åºåäŸ</h2>
<pre>
23
18 23
17 18 22 23
17 18
</pre>
|
p01141 |
<!-- begin en only -->
<h3><U>Lifeguard in the Pool</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>
Horton Moore ã¯ããŒã«ã®ç£èŠå¡ãšããŠåããŠããïŒåœŒãèŠåãã®ããã«ããŒã«ã®çžãæ©ããŠãããšããïŒããŒã«ã®äžã§äžäººã®å°å¥³ãããŒããŠããããšã«æ°ã¥ããïŒãã¡ããïŒåœŒã¯çŽã¡ã«æå©ã«åãããªããã°ãªããªãïŒãããïŒå°å¥³ã®èº«ã«äœããã£ãŠã¯å€§å€ã§ããããïŒå°ãã§ãæ©ãå°å¥³ã®ããšã«ãã©ãçãããïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒããŒã«ã®åœ¢ç¶ïŒé ç¹æ°ã 3ã10 ã®åžå€è§åœ¢ïŒïŒå°äžããã³æ°Žäžã«ãããç£èŠå¡ã®åäœè·é¢ãããã®ç§»åæéïŒãããŠç£èŠå¡ãšå°å¥³ã®åæäœçœ®ãäžãããããšãã«ïŒç£èŠå¡ãå°å¥³ã®ãšããã«å°çãããŸã§ã«ãããæçã®æéãæ±ããããã°ã©ã ãæžãããšã§ããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãããªãïŒå
¥åã®çµãã㯠1 ã€ã® 0 ã ããå«ãè¡ã«ãã£ãŠç€ºãããïŒ
</p>
<p>
åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã«ãªã£ãŠããïŒ
</p>
<blockquote>
<i>n</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> ... <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub><br>
<i>tg</i><br>
<i>tw</i><br>
<i>xs</i> <i>ys</i><br>
<i>xt</i> <i>yt</i>
</blockquote>
<p>
ããããã®èšå·ã®æå³ã¯æ¬¡ã®ãšããã§ããïŒ
</p>
<ul>
<li><p><i>n</i> ã¯åžå€è§åœ¢ãããããŒã«ã®é ç¹æ°ã瀺ãïŒãã㯠3 ä»¥äž 10 以äžã®æŽæ°ã§ããïŒ</p></li>
<li><p>(<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>) ã¯ããŒã«ã® <i>i</i> çªç®ã®é ç¹ã®åº§æšã瀺ãïŒããããã®åº§æšå€ã¯çµ¶å¯Ÿå€ã 100 以äžã®æŽæ°ã§ããïŒé ç¹ã¯åæèšåãã®é çªã§äžããããïŒ</p></li>
<li><p><i>tg</i> ã¯ç£èŠå¡ãå°äžã«ãããŠç§»åãããšãã«ãããåäœè·é¢ãããã®æéã衚ãïŒ<i>tw</i> ã¯ç£èŠå¡ãæ°Žäžã«ãããŠç§»åãããšãã«ãããåäœè·é¢ãããã®æéã衚ãïŒãããã¯ããããæŽæ°ã§ããïŒããã« 1 ⊠<i>tg</i> < <i>tw</i> ⊠100 ãæºããïŒ</p></li>
<li><p>(<i>xs</i>, <i>ys</i>) ã¯ç£èŠå¡ã®åæäœçœ®ã®åº§æšã衚ãïŒãã®åº§æšã¯ããŒã«ã®ã¡ããã©èŸºäžã«ããïŒ</p></li>
<li><p>(<i>xt</i>, <i>yt</i>) ã¯å°å¥³ã®åæäœçœ®ã®åº§æšã衚ãïŒãã®åº§æšã¯ããŒã«ã®å
åŽã«ããïŒ</p></li>
</ul>
<p>
åäžã®è¡ã«ããæ°å€ãšæ°å€ã®é㯠1 åã®ç©ºçœã§åºåãããŠããïŒ
</p>
<p>
ãã®åé¡ã«ãããŠïŒç£èŠå¡ããã³å°å¥³ã¯ç¹ã§ãããšã¿ãªãïŒãŸãïŒç£èŠå¡ãããŒã«ã®èŸºã«æ²¿ã£ãŠç§»åãããšãã¯å°äžãç§»åããŠãããšã¿ãªãïŒç£èŠå¡ã¯ïŒå°äžããæ°Žäžã«äžç¬ã§å
¥ãããšãïŒãŸãæ°Žäžããå°äžã«äžç¬ã§åºãããšãã§ãããšä»®å®ããŠæ§ããªãïŒç£èŠå¡ãå°äžããæ°Žäžã«ïŒãããã¯æ°Žäžããå°äžã«ç§»ããšãïŒç£èŠå¡ã¯åã座æšã«ãšã©ãŸããšèããããšïŒãããã£ãŠïŒããšãã°ããŒã«ã®çžããé¢ãããšããã«é£ã³èŸŒãããšã«ãã£ãŠæ°Žäžã§ã®ç§»åè·é¢ãæžããããšã¯ã§ããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«å¯ŸããŠïŒç£èŠå¡ãå°å¥³ã®å
ã«å°çãããŸã§ã«ãããæçã®æéã 1 è¡ã«åºåããªããïŒè§£çã®èª€å·®ã¯ 0.00000001 (10<sup>−8</sup>) ãè¶
ããŠã¯ãªããªãïŒç²ŸåºŠã«é¢ããæ¡ä»¶ãæºãããŠããã°ïŒå°æ°ç¹ä»¥äžã¯äœæ¡æ°åãåºåããŠãæ§ããªãïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
4
0 0 10 0 10 10 0 10
10
12
0 5
9 5
4
0 0 10 0 10 10 0 10
10
12
0 0
9 1
4
0 0 10 0 10 10 0 10
10
12
0 1
9 1
8
2 0 4 0 6 2 6 4 4 6 2 6 0 4 0 2
10
12
3 0
3 5
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
108.0
96.63324958071081
103.2664991614216
60.0
</pre>
|
p03486 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given strings <var>s</var> and <var>t</var>, consisting of lowercase English letters.
You will create a string <var>s'</var> by freely rearranging the characters in <var>s</var>.
You will also create a string <var>t'</var> by freely rearranging the characters in <var>t</var>.
Determine whether it is possible to satisfy <var>s' < t'</var> for the lexicographic order.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>For a string <var>a = a_1 a_2 ... a_N</var> of length <var>N</var> and a string <var>b = b_1 b_2 ... b_M</var> of length <var>M</var>, we say <var>a < b</var> for the lexicographic order if either one of the following two conditions holds true:</p>
<ul>
<li><var>N < M</var> and <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_N = b_N</var>.</li>
<li>There exists <var>i</var> (<var>1 \leq i \leq N, M</var>) such that <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_{i - 1} = b_{i - 1}</var> and <var>a_i < b_i</var>. Here, letters are compared using alphabetical order.</li>
</ul>
<p>For example, <code>xy</code> <var><</var> <code>xya</code> and <code>atcoder</code> <var><</var> <code>atlas</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The lengths of <var>s</var> and <var>t</var> are between <var>1</var> and <var>100</var> (inclusive).</li>
<li><var>s</var> and <var>t</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>
<var>t</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to satisfy <var>s' < t'</var>, 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>yx
axy
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>We can, for example, rearrange <code>yx</code> into <code>xy</code> and <code>axy</code> into <code>yxa</code>. Then, <code>xy</code> <var><</var> <code>yxa</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ratcode
atlas
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
<p>We can, for example, rearrange <code>ratcode</code> into <code>acdeort</code> and <code>atlas</code> into <code>tslaa</code>. Then, <code>acdeort</code> <var><</var> <code>tslaa</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>cd
abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
<p>No matter how we rearrange <code>cd</code> and <code>abc</code>, we cannot achieve our objective.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>w
ww
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>zzz
zzz
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>No
</pre></section>
</div>
</span> |
p01511 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Three-way Branch</H1>
<p>
There is a grid that consists of <var>W \times H</var> cells. The upper-left-most cell is <var>(1, 1)</var>.
You are standing on the cell of <var>(1,1)</var> and you are going to move to cell of <var>(W, H)</var>.
You can only move to adjacent lower-left, lower or lower-right cells.
</p>
<p>
There are obstructions on several cells. You can not move to it. You cannot move out the grid, either.
Write a program that outputs the number of ways to reach <var>(W,H)</var> modulo 1,000,000,009.
You can assume that there is no obstruction at <var>(1,1)</var>.
</p>
<H2>Input</H2>
<p>
The first line contains three integers, the width <var>W</var>, the height <var>H</var>, and the number of obstructions <var>N</var>.
(<var>1 \leq W \leq 75</var>, <var>2 \leq H \leq 10^{18}</var>, <var>0 \leq N \leq 30</var>)
Each of following <var>N</var> lines contains 2 integers, denoting the position of an obstruction <var>(x_i, y_i)</var>.
</p>
<p>
The last test case is followed by a line containing three zeros.
</p>
<H2>Output</H2>
<p>
For each test case, print its case number and the number of ways to reach <var>(W,H)</var> modulo 1,000,000,009.
</p>
<H2>Sample Input</H2>
<pre>
2 4 1
2 1
2 2 1
2 2
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 4
Case 2: 0
</pre>
|
p01004 |
<h1>Problem F: Ballon Contest</h1>
<h2>Problem</h2>
<p>ç©ºã®æ§åããã€ããšéããè²ãšãã©ãã®å€åœ©ãªç±æ°çã空ãèŠã£ãŠããã仿¥ã¯ç±æ°çã®å€§äŒã ã<!--倧äŒã®äŒå Žã«è¡ã£ãŠã¿ããšãç±æ°çã䜿ã£ãã¬ã¯ãªãšãŒã·ã§ã³ãéå¬ãããŠããã-->ç±æ°çããèœãšãããåŸç¹ä»ãããŒã«ãåå è
å
šå¡ã§åãåããããã<!--æ®å¿µãªããç³ãèŸŒã¿æéãåããŠããŸã£ãŠãããã-->ãã£ãããªã®ã§åªåè
ãäºæ³ããŠã¿ãããšã«ããã</p>
<ul>
<li>ã¬ã¯ãªãšãŒã·ã§ã³ã«ã¯N人åå ããã</li>
<li><var> N </var>人ã®åå è
ã¯ããããèªåã®äœçœ®ãäžãããããè€æ°ã®åå è
ã«åãäœçœ®ãäžããããäºã¯ãªãã</li>
<li>äžç©ºã®ç±æ°çããMåã®ããŒã«ãïŒåãã€èœäžããã</li>
<li>åå è
ã¯å
šå¡åãã¿ã€ãã³ã°ã§èµ°ãå§ããããŒã«ã«åãã£ãŠåãé床ã§äžçŽç·ã«èµ°ãã</li>
<li>ããŒã«ã®èœäžäœçœ®ã«äžçªæ©ã蟿ãçãã人ãããŒã«ãååŸã§ãããåæã«è€æ°äººèŸ¿ãçããå Žåã¯ãäžæ§ãªç¢ºçã§ååŸã§ããäººãæ±ºãŸãã</li>
<li>åå è
ãããŒã«ãååŸãããšåå è
å
šå¡ãå
ã®äœçœ®ã«æ»ãã</li>
<li>åå è
ãèµ°ãå§ããŠããåå è
ã®å
šå¡ãå
ã®äœçœ®ã«æ»ããŸã§ã«å¥ã®ããŒã«ãèœäžããäºã¯ãªãã</li>
<li>åããŒã«ã«ã¯åŸç¹ãšèœäžããäœçœ®ãäžããããããŒã«ãååŸãããšåŸç¹ãåŸãããã</li>
<li>ããŒã«ã¯èœäžäžã«ç©ºæ°æµæãåãããããå®éã«èœäžããå°ç¹ã«ã¯ãºã¬ãçºçãããèœäžäºå®ã®äœçœ®ããæå€§ã§X軞æ¹å㫱<var>dx </var>ãY軞æ¹å㫱<var>dy </var>ã ãäžæ§ãªç¢ºçã§ãºã¬ãã</li>
</ul>
<p>åŸãããåŸç¹ã®æåŸ
å€ãæ±ããæåŸ
å€ã®æã倧ããåå è
ã®æåŸ
å€ãåºåããã</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãã<br>
åããŒã¿ã»ããã¯ä»¥äžã§è¡šãããã<br>
</p>
<pre>
<var>N</var> <var>M</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
.
.
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var>
<var>bx<sub>1</sub></var> <var>by<sub>1</sub></var> <var>dx<sub>1</sub></var> <var>dy<sub>1</sub></var> <var>score<sub>1</sub></var>
.
.
<var>bx<sub>M</sub></var> <var>by<sub>M</sub></var> <var>dx<sub>M</sub></var> <var>dy<sub>M</sub></var> <var>score<sub>M</sub></var>
</pre>
<p>
1è¡ç®ã«ã¯ãåå è
ã®äººæ°<var> N </var>ãããŒã«ã®æ°<var> M </var>ãäžããããã<br>
2è¡ç®ãã<var> N </var>+1è¡ç®ãŸã§ã«ã¯ãåå è
ã®æ
å ±ãäžããããã<var> x<sub>i</sub> </var>,<var> y<sub>i</sub> </var>ã¯ãããããåå è
ã®äœçœ®ã®X座æšã»Y座æšã§ããã<br>
<var> N </var>+2è¡ç®ãã<var> N </var>+<var> M </var>+1è¡ç®ãŸã§ã«ã¯ãããŒã«ã®æ
å ±ãäžãããããåããŒã«ãå®éã«èœäžããå°ç¹ã®X座æšã»Y座æšã¯ãããã<var> bx<sub>j</sub> </var>-<var> dx<sub>j</sub> </var>ãã<var> bx<sub>j</sub> </var>+<var> dx<sub>j</sub> </var>ãŸã§ã<var> by<sub>j</sub> </var>-<var> dy<sub>j</sub> </var>ãã<var> by<sub>j</sub> </var>+<var> dy<sub>j</sub> </var>ãŸã§ã®ç¯å²ã®ã©ããã§ããã<var> score<sub>j</sub> </var>ã¯ããŒã«ã®åŸç¹ã§ããã<br>
å
¥åã®çµããã¯2ã€ã®ãŒããããªãã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 100</li>
<li>1 ≤ <var>M</var> ≤ 10</li>
<li>0 ≤ <var>x<sub>i</sub> </var>,<var> y<sub>i</sub> </var>,<var> bx<sub>j</sub> </var>,<var> by<sub>j</sub></var> ≤ 10000</li>
<li>1 ≤ <var>dx<sub>j</sub> </var>,<var> dy<sub>j</sub></var>≤ 10000</li>
<li>1 ≤ <var>score<sub>j</sub></var> ≤ 100</li>
<li>ãã¹ãã±ãŒã¹ã®æ°ã¯ 10 ãè¶
ããªãã</li>
<li>å
¥åã«å«ãŸããå€ã¯å
šãп޿°ã§ããã</li>
</ul>
<h2>Output</h2>
<p>
åããŒã¿ã»ããæ¯ã«ãçããäžè¡ã«åºåããªããã<br>
åºåã¯0.0001以äžã®èª€å·®ãå«ãã§ãããã<br>
</p>
<h2>Sample Input</h2>
<pre>
3 4
10 75
50 5
90 75
50 50 10 10 2
40 90 1 1 3
10 20 10 15 1
50 70 50 50 4
4 2
25 25
25 75
75 75
75 25
50 50 10 10 1
50 50 15 15 2
1 1
5 5
1 1 1 1 1
0 0
</pre>
<h2>Sample Output</h2>
<pre>
5.442857
0.750000
1.000000
</pre> |
p03039 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid of squares with <var>N</var> rows and <var>M</var> columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left. We will choose <var>K</var> of the squares and put a piece on each of them.</p>
<p>If we place the <var>K</var> pieces on squares <var>(x_1, y_1)</var>, <var>(x_2, y_2)</var>, ..., and <var>(x_K, y_K)</var>, the <em>cost</em> of this arrangement is computed as:</p>
<p><var>\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)</var></p>
<p>Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo <var>10^9+7</var>.</p>
<p>We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \times M \leq 2 \times 10^5</var></li>
<li><var>2 \leq K \leq N \times 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> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the costs of all possible arrangements of the pieces, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>There are six possible arrangements of the pieces, as follows:</p>
<ul>
<li><var>((1,1),(1,2))</var>, with the cost <var>|1-1|+|1-2| = 1</var></li>
<li><var>((1,1),(2,1))</var>, with the cost <var>|1-2|+|1-1| = 1</var></li>
<li><var>((1,1),(2,2))</var>, with the cost <var>|1-2|+|1-2| = 2</var></li>
<li><var>((1,2),(2,1))</var>, with the cost <var>|1-2|+|2-1| = 2</var></li>
<li><var>((1,2),(2,2))</var>, with the cost <var>|1-2|+|2-2| = 1</var></li>
<li><var>((2,1),(2,2))</var>, with the cost <var>|2-2|+|1-2| = 1</var></li>
</ul>
<p>The sum of these costs is <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>87210
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 100 5000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>817260251
</pre>
<p>Be sure to print the sum modulo <var>10^9+7</var>.</p></section>
</div>
</span> |
p03193 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> rectangular plate materials made of special metal called AtCoder Alloy.
The dimensions of the <var>i</var>-th material are <var>A_i \times B_i</var> (<var>A_i</var> vertically and <var>B_i</var> horizontally).</p>
<p>Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly <var>H \times W</var>.
He is trying to obtain such a plate by choosing one of the <var>N</var> materials and cutting it if necessary.
When cutting a material, the cuts must be parallel to one of the sides of the material.
Also, the materials have fixed directions and cannot be rotated.
For example, a <var>5 \times 3</var> material cannot be used as a <var>3 \times 5</var> plate.</p>
<p>Out of the <var>N</var> materials, how many can produce an <var>H \times W</var> plate if properly cut?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>1 \leq H \leq 10^9</var></li>
<li><var>1 \leq W \leq 10^9</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>1 \leq B_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</var> <var>W</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5 2
10 3
5 2
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Takahashi wants a <var>5 \times 2</var> plate.</p>
<ul>
<li>The dimensions of the first material are <var>10 \times 3</var>. We can obtain a <var>5 \times 2</var> plate by properly cutting it.</li>
<li>The dimensions of the second material are <var>5 \times 2</var>. We can obtain a <var>5 \times 2</var> plate without cutting it.</li>
<li>The dimensions of the third material are <var>2 \times 5</var>. We cannot obtain a <var>5 \times 2</var> plate, whatever cuts are made. Note that the material cannot be rotated and used as a <var>5 \times 2</var> plate.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 587586158 185430194
894597290 708587790
680395892 306946994
590262034 785368612
922328576 106880540
847058850 326169610
936315062 193149191
702035777 223363392
11672949 146832978
779291680 334178158
615808191 701464268
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre></section>
</div>
</span> |
p01454 |
<H1>Problem H: ããéæ¹é èšç»ïŒä»®ïŒ</H1>
<p>
ããªãã¯ãèªå®
ã«ããããã®ããã飌ã£ãŠããããããªããªãã®æ¥èª²ã¯ã飌ã£ãŠãããããåéã®äž
ã«å
¥ã£ãŠæŒå¯ããŠããæ§åïŒéç§°ïŒããéïŒãæ®åœ±ããããšã ãäœå¹ãã®ããããéã®äžã§ãã£ãã
ã«äžžããªã£ãŠç ãå§¿ã¯ãå®ã«æããããã
</p>
<p>
ããããã®ããã«ã¯ããéãã<i>m<sub>i</sub></i> ãšãCuteã<i>c<sub>i</sub></i> ãå®çŸ©ãããŠãããCute ãšã¯ããã®ãã1 å¹ã ããèŠããšãã®ãæãããã»ãã©ããªãã»ããªãããã»ãããããã»ããããããããªã©ãç·åçã«è©äŸ¡ããæ°å€ã§ããã倧ãããã°å€§ããã»ã©ãã®ããã¯é
åçã§ããã
</p>
<p>
ãŸããããéã«å¯ŸããŠã¯ãUnCuteããšããæ°å€ãå®çŸ©ããããããã¯ãããéå
šäœãšããŠã®ã¢ã³ãã©
ã³ã¹ããããããå€ã§ãããCute ãšã¯éã«ãå°ãããã°å°ããã»ã©ããã®ããéã¯ããããéã§ã
ããããéã®UnCute ã¯ãäžã«ããããã®Cute ã®æå€§å€<i>C<sub>max</sub></i> ãšæå°å€<i>C<sub>min</sub></i> ãçšããŠã<i>C<sub>max</sub></i> - <i>C<sub>min</sub></i>ãšãããããããã€ãŸããäžã«ãããããã¿ãªåããããã®Cute ãæã£ãŠããããéããããããéã§ããã
</p>
<p>
ããéãæã¡éã¶ãšãã®ããšãèãããšãããéã®éãïŒïŒäžã«ããããã®éãã®ç·åïŒã¯ãéçå€
<i>W</i> 以äžã§ãªããã°ãªããªãããã®æ¡ä»¶ãã¿ããããã«ããéã«å
¥ã£ãŠããããããéžãã§ãããéã®UnCute ãå°ãããããã®ã ãããã£ããã©ããŸã§å°ããã§ããã®ã ãããã
</p>
<p>
âŠâŠãšããåé¡ãè§£ããŠãã£ããæºè¶³ããæ°ã«ãªã£ãŠããã®ã¯ãéå»ã®è©±ã ã
</p>
<p>
ãã®åãããªããå®¶ã®ååº«ãæŽçããŠããããå庫ã®äžããå€ãŒããåéãèŠã€ãã£ããããã§ããª
ãã®å®¶ã«ããåéã¯ïŒã€ããããããããã¯ããã¥ã¢ã«ããéã®æä»£ãªã®ã ïŒããã ã®ããéãªã©ã
ãå€ãïŒ
</p>
<p>
ãã¥ã¢ã«ããéã§ã¯ãåé<i>A</i> ã¯ãªã¹ã®ããå°çšãããçæ¹ã®åéB ã¯ã¡ã¹ã®ããå°çšã§ããããŸãã
ãã¥ã¢ã«ããéã®UnCute ãå®çŸ©ããã«ããã£ãŠã¯ãCute ã®ã¢ã³ãã©ã³ã¹ãã ãã§ã¯ãªããïŒã€ã®
ããéã®éãã®ã¢ã³ãã©ã³ã¹ããèæ
®ã«å
¥ããå¿
èŠããããå
·äœçã«ã¯ãéãã»ãã®ããéã®éãã
<i>M<sub>max</sub></i>ã軜ãã»ãã®ããéã®éãã<i>M<sub>min</sub></i> ãšãããšïŒïŒã€ã®ããéã®éããåããšãã¯<i>M<sub>max</sub></i> = <i>M<sub>min</sub></i>ïŒããã¥ã¢ã«ããéã®UnCute ã¯ã
</p>
<center>
<p>
max{<i>M<sub>max</sub></i> - <i>M<sub>min</sub></i>, <i>C<sub>max</sub></i> - <i>C<sub>min</sub></i>}
</p>
</center>
<p>
ãšããããããããªããããã§ã®<i>C<sub>max</sub></i> ãš<i>C<sub>min</sub></i> ã¯ãããé<i>A</i> ã®äžãŸãã¯ããé<i>B</i> ã®äžã«ããããã®Cute ã®æå€§å€,æå°å€ã§ããã
</p>
<p>
ããéãæã¡éã¶ãšãã®ããšãèãããšã<i>M<sub>max</sub></i>ã¯ãéçå€<i>W</i> 以äžã§ãªããã°ãªããªãããã®æ¡ä»¶ãã¿ããããã«ãã¥ã¢ã«ããéã«å
¥ã£ãŠããããããéžãã§ããã¥ã¢ã«ããéã®UnCute ãå°ãããããã®ã ãããã£ããã©ããŸã§å°ããã§ããã®ã ãããã
</p>
<H2>Input</H2>
<p>
<i>N<sub>A</sub> N<sub>B</sub> W</i><br>
<i>m</i><sub><i>A</i>,1</sub> <i>c</i><sub><i>A</i>,1</sub><br>
<i>m</i><sub><i>A</i>,2</sub> <i>c</i><sub><i>A</i>,2</sub><br>
.<br>
.<br>
.<br>
<i>m</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub> <i>c</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub><br>
<i>m</i><sub><i>B</i>,1</sub> <i>c</i><sub><i>B</i>,1</sub><br>
<i>m</i><sub><i>B</i>,2</sub> <i>c</i><sub><i>B</i>,2</sub><br>
.<br>
.<br>
.<br>
<i>m</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub> <i>c</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub><br>
</p>
<p>
å
¥åã®ïŒè¡ç®ã«ã¯ãæŽæ°<i>N<sub>A</sub></i>ïŒ1 ≤ <i>N<sub>A</sub></i> ≤ 500ïŒãšæŽæ°<i>N<sub>B</sub></i>ïŒ1 ≤ <i>N<sub>B</sub></i> ≤ 500ïŒãšæŽæ°<i>W</i>ïŒ1 ≤ <i>W</i> ≤ 10,000ïŒãã空çœåºåãã§æžãããŠãããããã¯ãããªãã飌ã£ãŠãããªã¹ã®ãããå
šéšã§<i>N<sub>A</sub></i> å¹ãã¡ã¹ã®ãããå
šéšã§<i>N<sub>B</sub></i> å¹ããããšãããããã<i>W</i> ã¯ããéã®éãã®éçå€ã§ããã
</p>
<p>
ç¶ã<i>N<sub>A</sub></i> è¡ã«ã¯ãæŽæ°<i>m</i><sub><i>A</i>,<i>i</i></sub>ïŒ1 ≤ <i>m</i><sub><i>A</i>,<i>i</i></sub> ≤ 10,000ïŒãšæŽæ°<i>c</i><sub><i>A</i>,<i>i</i></sub>ïŒ1 ≤ <i>c</i><sub><i>A</i>,<i>i</i></sub> ≤ 1,000,000,000ïŒãã空çœåºåãã§æžãããŠãããïŒïŒ i è¡ç®ã«æžãããæŽæ°<i>m</i><sub><i>A</i>,<i>i</i></sub> ãš<i>c</i><sub><i>A</i>,<i>i</i></sub> ã¯ãi çªç®ã®ãªã¹ã®ããã®éãã<i>m</i><sub><i>A</i>,<i>i</i></sub>ãCute ã<i>c</i><sub><i>A</i>,<i>i</i></sub> ã§ããããšãããããã
</p>
<p>
ç¶ã<i>N<sub>B</sub></i> è¡ã«ã¯ãæŽæ°<i>m</i><sub><i>B</i>,<i>i</i></sub>ïŒ1 ≤ <i>m</i><sub><i>B</i>,<i>i</i></sub> ≤ 10,000ïŒãšæŽæ°<i>c</i><sub><i>B</i>,<i>i</i></sub>ïŒ1 ≤ <i>c</i><sub><i>B</i>,<i>i</i></sub> ≤ 1,000,000,000ïŒãã空çœåºåãã§æžãããŠãããïŒïŒ <i>N<sub>A</sub></i> ïŒ i è¡ç®ã«æžãããæŽæ°<i>m</i><sub><i>B</i>,<i>i</i></sub> ãš<i>c</i><sub><i>B</i>,<i>i</i></sub> ã¯ãi çªç®ã®ã¡ã¹ã®ããã®éãã<i>m</i><sub><i>B</i>,<i>i</i></sub>ãCute ã<i>c</i><sub><i>B</i>,<i>i</i></sub> ã§ããããšãããããã
</p>
<p>
ãªã¹ã®ããã«ãã¡ã¹ã®ããã«ããéãã<i>W</i> 以äžã§ãããããªããããããããïŒå¹ä»¥äžã¯ååšãããšä»®å®ããŠããã
</p>
<H2>Output</H2>
<p>
<i>M<sub>max</sub></i> ã<i>W</i> ãè¶
ããªããšããæ¡ä»¶ã®ããšã§ããã¥ã¢ã«ããéã®UnCute ã®æå°å€ãåºåããããã ããã©ã¡ãã®ããéã«ãïŒå¹ä»¥äžã®ãããå
¥ã£ãŠããªããã°ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
4 3 12
3 6
2 4
7 9
10 1
6 5
8 4
15 19
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
1 3 10
1 15
6 8
5 9
8 7
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre>
<h2>Sample Input 3</h2>
<pre>
8 6 65
30 98
27 51
4 74
65 87
49 19
27 48
43 7
35 28
43 69
8 47
64 75
18 23
54 29
40 43
</pre>
<h2>Sample Output 3</h2>
<pre>
8
</pre> |
p03469 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On some day in January <var>2018</var>, Takaki is writing a document. The document has a column where the current date is written in <code>yyyy/mm/dd</code> format. For example, January <var>23</var>, <var>2018</var> should be written as <code>2018/01/23</code>.</p>
<p>After finishing the document, she noticed that she had mistakenly wrote <code>2017</code> at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, <var>S</var>, is given as input, modifies the first four characters in <var>S</var> to <code>2018</code> and prints it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>S</var> is a string of length <var>10</var>.</li>
<li>The first eight characters in <var>S</var> are <code>2017/01/</code>.</li>
<li>The last two characters in <var>S</var> are digits and represent an integer between <var>1</var> and <var>31</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Replace the first four characters in <var>S</var> with <code>2018</code> and print it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2017/01/07
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2018/01/07
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2017/01/31
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2018/01/31
</pre></section>
</div>
</span> |
p02628 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A shop sells <var>N</var> kinds of fruits, Fruit <var>1, \ldots, N</var>, at prices of <var>p_1, \ldots, p_N</var> yen per item, respectively. (Yen is the currency of Japan.)</p>
<p>Here, we will choose <var>K</var> kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq N \leq 1000</var></li>
<li><var>1 \leq p_i \leq 1000</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>p_1</var> <var>p_2</var> <var>\ldots</var> <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the minimum possible total price of fruits.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
50 100 80 120 80
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>210
</pre>
<p>This shop sells Fruit <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, and <var>5</var> for <var>50</var> yen, <var>100</var> yen, <var>80</var> yen, <var>120</var> yen, and <var>80</var> yen, respectively.</p>
<p>The minimum total price for three kinds of fruits is <var>50 + 80 + 80 = 210</var> yen when choosing Fruit <var>1</var>, <var>3</var>, and <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1
1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000
</pre></section>
</div>
</span> |
p00615 |
<h1><font color="#000000">Problem A:</font> Traffic Analysis</h1>
<p>
There are two cameras which observe the up line and the down line respectively on the double lane (please see the following figure). These cameras are located on a line perpendicular to the lane, and we call the line 'monitoring line.' (the red line in the figure)
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_trafficAnalysis_en">
</center>
<br>
<p>
Monitoring systems are connected to the cameras respectively.
When a car passes through the monitoring line, the corresponding monitoring system records elapsed time (sec) from the start of monitoring.
</p>
<p>
Your task is to write a program which reads records of the two monitoring systems and prints the maximum time interval where cars did not pass through the monitoring line.
</p>
<p>
The two monitoring system start monitoring simultaneously. The end of monitoring is indicated by the latest time in the records.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets. Each dataset consists of:
</p>
<pre>
<i>n m</i>
<i>tl</i><sub>1</sub> <i>tl</i><sub>2</sub> ... <i>tl</i><sub>n</sub>
<i>tr</i><sub>1</sub> <i>tr</i><sub>2</sub> ... <i>tr</i><sub>m</sub>
</pre>
<p>
<i>n</i>, <i>m</i> are integers which represent the number of cars passed through monitoring line on the up line and the down line respectively. <i>tl<sub>i</sub></i>, <i>tr<sub>i</sub></i> are integers which denote the elapsed time when <i>i</i>-th car passed through the monitoring line for the up line and the down line respectively. You can assume that <i>tl</i><sub>1</sub> < <i>tl</i><sub>2</sub> < ... < <i>tl</i><sub>n</sub>ã <i>tr</i><sub>1</sub> < <i>tr</i><sub>2</sub> < ... < <i>tr</i><sub>m</sub>.
</p>
<p>
You can also assume that <i>n</i>, <i>m</i> ≤ 10000, and 1 ≤ <i>tl<sub>i</sub></i>, <i>tr<sub>i</sub></i> ≤ 1,000,000.
</p>
<p>
The end of input is indicated by a line including two zero.
</p>
<h2>Output</h2>
<p>
For each dataset, print the maximum value in a line.
</p>
<H2>Sample Input</H2>
<pre>
4 5
20 35 60 70
15 30 40 80 90
3 2
10 20 30
42 60
0 1
100
1 1
10
50
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
20
18
100
40
</pre>
|
p01907 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>C: Fractal Tree</h1>
<h2>åé¡</h2>
<p>
AORã€ã«ã¡ããã¯ããã©ã¯ã¿ã«ãª(èªå·±çžäŒŒçãª)æ§é ãæã€æ ¹ä»ãæšã奜ãã§ããã
$N$ é ç¹ããæãéã¿ä»ãæ ¹ä»ãæš $T$ ãçšããŠã以äžã®ãããªãã©ã¯ã¿ã«æ§é ãæã€æ ¹ä»ãæš $T'$ ã衚çŸããããšãèããã
</p>
<ul>
<li>$T'$ ã¯ã$T$ ã®åé ç¹ $x$ ã«å¯ŸããŠã$x$ ãæ ¹ãšã㊠$T$ ãšåæ§ã®æšæ§é (ã³ã¹ããåã) ãæã€æšãä»ãå ãããã®ã§ããã</li>
<li>$T'$ã®æ ¹ã¯ $T$ ã®ãã®ãšåããã®ã§ããã</li>
</ul>
<p>
ããããŠè¡šçŸãããæšã¯äŸãã°äžå³ã®ããã«ãªãã
</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day1_RUPC2017_FractalTree" width="75%">
</p>
<p>
AOR ã€ã«ã¡ããã¯ã$T'$ ã«å¯ŸããŠæ·±ãåªå
æ¢çŽ¢ãããããšããŠããããå
šãŠã®é ç¹ã蟿ããšæéããšãŠããããããšã«æ°ã¥ããã
ããã§ãæ·±ãåªå
æ¢çŽ¢æã®é·ç§»ã®éã«ç¢ºç $p$ ã§é·ç§»ãã確ç $1-p$ ã§é·ç§»ããªãæ¹éã§æ·±ãåªå
æ¢çŽ¢ãè¡ããããã€ãã®ããŒã蚪åããµããããšã«ããã
$T$ ãšç¢ºç $p$ ãäžããããã®ã§ã$Tâ$ ã«å¯ŸããŠæ·±ãåªå
æ¢çŽ¢ãè¡ãéã«èŸ¿ãå
šãŠã®èŸºã®ã³ã¹ãã®åã®æåŸ
å€ãæ±ããã
$T$ ã®æ
å ±ã¯é ç¹æ° $N$ ãš $N-1$ æ¬ã®èŸºã®æ
å ±ã§äžããããé ç¹ $1$ ãæ ¹ã§ããã
åé ç¹ã¯ $1,2,\dots,N$ ãšã©ããªã³ã°ãããŠããã $i \ (1 \le i \le N-1)$ çªç®ã®èŸºã¯é ç¹ $x_i$ ãš $y_i$ ãã³ã¹ã $c_i$ ã§çµãã§ããã
ä»åã®åé¡ã§æ±ãã確ç $p$ ã§åã«é·ç§»ããæ·±ãåªå
æ¢çŽ¢ã®é決å®çã¢ã«ãŽãªãºã ã¯ä»¥äžã®ããã«è¡šçŸãããã
åºåããã $\mathrm{answer}$ ã蟿ã蟺ã®ã³ã¹ãã®ç·åã§ããã
</p>
<ol>
<li>空ã®ã¹ã¿ã㯠$S$ ãçšæããã</li>
<li>$\mathrm{answer}=0$ ãšãã</li>
<li>$S$ ã« $T'$ ã®æ ¹é ç¹ãããã·ã¥ããã</li>
<li>$S$ ã®å
é ã®èŠçŽ ãåãåºããããã $x$ ãšããã</li>
<li>$x$ ã®åå $c$ ã«å¯Ÿãããããã確ç $p$ ã§æ¬¡ã®æäœãè¡ãã確ç $1-p$ ã§äœãããªãã
<ul>
<li>$S$ ã«é ç¹ $c$ ã远å ããããã㊠$\mathrm{answer}$ ã« $x$ ãã $c$ ã«ç¹ãã£ãŠãã蟺ã®éã¿ãå ããã</li>
</ul>
</li>
<li>Sã空ã§ãªããã°ã3. ã«é·ç§»ããã</li>
<li>$\mathrm{answer}$ ãåºåããã</li>
</ol>
<h2>å¶çŽ</h2>
<ul>
<li>$2 \le N \le 10^5$</li>
<li>$0 \le p \le 1.0$ (å°æ°ç¹ç¬¬ 2 äœãŸã§äžããããã)</li>
<li>$1 \le x_i,y_i \le N$</li>
<li>$1 \le c_i \le 1000$</li>
<li>$c_i$ ã¯æŽæ°ã§ãã</li>
<li>äžããããã°ã©ã㯠$N$ é ç¹ã®æ ¹ä»ãæšã§ãããããªãã¡ãé ç¹ $N$ãèŸºæ° $N-1$ãé£çµãšããæ§è³ªãæã€ã°ã©ãã§ãããé ç¹ $1$ ãæ ¹ã§ããã</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<p>
$p$<br>
$N$<br>
$x_1 \ y_1 \ c_1$<br>
$\vdots$<br>
$x_{N-1} \ y_{N-1} \ c_{N-1}$<br>
</p>
<h2>åºå</h2>
<p>
çãã 1 è¡ã§åºåãããçžå¯Ÿèª€å·®ãŸãã¯çµ¶å¯Ÿèª€å·®ã $10^{-6}$ 以äžãªã AC ãšãªãããŸããæ«å°Ÿã«æ¹è¡ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å1</h3>
<pre>
0.75
4
1 2 1
2 3 3
3 4 10
</pre>
<h3>ãµã³ãã«åºå1</h3>
<pre>
24.8569335938
</pre>
<h3>ãµã³ãã«å
¥å2</h3>
<pre>
0.75
4
1 2 1
1 3 3
3 4 10
</pre>
<h3>ãµã³ãã«åºå2</h3>
<pre>
35.0390625
</pre>
<p>
å顿ã®å³ã®æšãäžããäŸã§ããã
</p> |
p02782 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is standing on a two-dimensional plane. In one operation, he can move by <var>1</var> in the positive <var>x</var>-direction, or move by <var>1</var> in the positive <var>y</var>-direction.</p>
<p>Let us define a function <var>f(r, c)</var> as follows:</p>
<ul>
<li><var>f(r,c) := </var> (The number of paths from the point <var>(0, 0)</var> to the point <var>(r, c)</var> that Snuke can trace by repeating the operation above)</li>
</ul>
<p>Given are integers <var>r_1</var>, <var>r_2</var>, <var>c_1</var>, and <var>c_2</var>.
Find the sum of <var>f(i, j)</var> over all pair of integers <var>(i, j)</var> such that <var>r_1 †i †r_2</var> and <var>c_1 †j †c_2</var>, and compute this value modulo <var>(10^9+7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †r_1 †r_2 †10^6</var></li>
<li><var>1 †c_1 †c_2 †10^6</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>r_1</var> <var>c_1</var> <var>r_2</var> <var>c_2</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of <var>f(i, j)</var> modulo <var>(10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>14
</pre>
<p>For example, there are two paths from the point <var>(0, 0)</var> to the point <var>(1, 1)</var>: <var>(0,0)</var> â <var>(0,1)</var> â <var>(1,1)</var> and <var>(0,0)</var> â <var>(1,0)</var> â <var>(1,1)</var>, so <var>f(1,1)=2</var>.</p>
<p>Similarly, <var>f(1,2)=3</var>, <var>f(2,1)=3</var>, and <var>f(2,2)=6</var>. Thus, the sum is <var>14</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>314 159 2653 589
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>602215194
</pre></section>
</div>
</span> |
p03890 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><em>Kode Festival</em> is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for "hardness".)</p>
<p>This year, <var>2^N</var> stones participated. The hardness of the <var>i</var>-th stone is <var>A_i</var>.</p>
<p>In the contest, stones are thrown at each other in a knockout tournament.</p>
<p>When two stones with hardness <var>X</var> and <var>Y</var> are thrown at each other, the following will happen:</p>
<ul>
<li>
<p>When <var>X</var> > <var>Y</var>:
The stone with hardness <var>Y</var> will be destroyed and eliminated.
The hardness of the stone with hardness <var>X</var> will become <var>X-Y</var>.</p>
</li>
<li>
<p>When <var>X</var> = <var>Y</var>:
One of the stones will be destroyed and eliminated.
The hardness of the other stone will remain the same.</p>
</li>
<li>
<p>When <var>X</var> < <var>Y</var>:
The stone with hardness <var>X</var> will be destroyed and eliminated.
The hardness of the stone with hardness <var>Y</var> will become <var>Y-X</var>.</p>
</li>
</ul>
<p>The <var>2^N</var> stones will fight in a knockout tournament as follows:</p>
<ol>
<li>
<p>The following pairs will fight: (the <var>1</var>-st stone versus the <var>2</var>-nd stone), (the <var>3</var>-rd stone versus the <var>4</var>-th stone), ...</p>
</li>
<li>
<p>The following pairs will fight: (the winner of (<var>1</var>-st versus <var>2</var>-nd) versus the winner of (<var>3</var>-rd versus <var>4</var>-th)), (the winner of (<var>5</var>-th versus <var>6</var>-th) versus the winner of (<var>7</var>-th versus <var>8</var>-th)), ...</p>
</li>
<li>
<p>And so forth, until there is only one stone remaining.</p>
</li>
</ol>
<p>Determine the eventual hardness of the last stone remaining.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 18</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var>
<var>A_2</var>
:
<var>A_{2^N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the eventual hardness of the last stone remaining.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1
3
10
19
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1
3
2
4
6
8
100
104
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre></section>
</div>
</span> |
p02278 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Minimum Cost Sort</H1>
<p>
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times.
</p>
<p>
Write a program which reports the minimal total cost to sort the given integers.
</p>
<h2>Input</h2>
<p>
In the first line, an integer $n$ is given. In the second line, $n$ integers $w_i (i = 0, 1, 2, ... n-1)$ separated by space characters are given.
</p>
<h2>Output</h2>
<p>
Print the minimal cost in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$0 \leq w_i\leq 10^4$</li>
<li>$w_i$ are all different</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
5
1 5 3 4 2
</pre>
<h2>Sample Output 1</h2>
<pre>
7
</pre>
<br>
<h2>Sample Input 2</h2>
<pre>
4
4 3 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
10
</pre>
|
p00245 |
<H1>ã¿ã€ã ã»ãŒã«</H1>
<p>
ããè¯ãç©ããããå®ãã仿¥ãã©ããã®ã¹ãŒããŒããŒã±ããã§è¡ãããã¿ã€ã ã»ãŒã«ã§ã¯ãæ¿ããéããç¹°ãåºããããŠããŸããããäŒæŽ¥ã«ãããLLå ãããããªã¹ãŒããŒããŒã±ããã®ã²ãšã€ã§ãä»ã®ãã§ãŒã³åºãšå¯Ÿæãã¹ããå°ãå€ãã£ãã¿ã€ã ã»ãŒã«ã宿œããŠããŸããäžè¬çãªã¿ã€ã ã»ãŒã«ã§ã¯è€æ°ã®ååãåãæéã«å®ããªããã®ã§ãããLLå ã§ã¯å¯Ÿè±¡ãšãªãååã«ãã£ãŠãã¿ã€ã ã»ãŒã«ãéå§ããæéãå¥ã
ã«èšå®ãããŠããŸãã
</p>
<p>
åäºå®¶ã¯LLå ãããå©çšããå®¶åºã®äžã€ã§ãããããªåäºå®¶ã§ã¯ã奥æ§äž»å°ã®ããšãæ¬¡ã®æ¥æã«è¡ãããã¿ã€ã ã»ãŒã«ã«åããŠäœæŠäŒè°ãéããã©ã®ãããªé çªã§è²·ãç©ãããã°å€åŒããæå€§ãšãªãããåæããããšã«ãªããŸãããåºå
ãçç¥ããŠããåäºå®¶ã¯å£²ãå Žã®èŠåãå³ãæžãããŸã欲ããåç©ãã©ãã«ããããå€åŒãã¯å¹Ÿãã§ãããã売ãåãããŸã§ã®æéãææ¡ããããšã«æåããŸããã
ãããŸã§ã¯å®ç§ã ã£ãåäºå®¶ã§ãããåæãè¡ãã人ãããŸããã§ãããããã§åäºå®¶ãšèŠªäº€ããã£ãããªãã¯ããã°ã©ã ãæžãããšã«ããŸãããäžäººã®äººãåãããšãæ³å®ããŠã·ãã¥ã¬ãŒã·ã§ã³ãè¡ããŸãã
</p>
<p>
ååã¯10çš®é¡ãããæ°å1æ¡ã®ååçªå· <var>g</var> ã«ãã£ãŠ åºå¥ãããŸããã¿ã€ã ã»ãŒã«æ
å ±ã«ã¯ååçªå· <var>g</var>ã å€åŒãé¡ <var>d</var>ãã¿ã€ã ã»ãŒã«ã®éå§æå» <var>s</var> ãšå£²ãåãæå» <var>e</var> ããããŸãã
</p>
<p>
åºå
ã¯æšª <var>X</var>ã瞊 <var>Y</var> ã®ãã¹ã§æ§æããã2次å
ã°ãªããã§è¡šããããã¹ããšã«éè·¯ãååæ£ã® ã©ã¡ãããå²ãåœãŠãããŠããŸããäžã€ã®å忣ã«ã¯ 1çš®é¡ã®ååããããããã¯ååçªå· <var>g</var> ã§åºå¥ãããŸãã
ã©ã®ååãè²·ã£ãŠãããã§ãããåãååçªå·ã®ååãè€æ°è²·ã£ãŠã¯ãããŸãããå忣ããã¯ãäžäžå·Šå³ã«é£æ¥ããéè·¯ã®ãã¹ãªãã©ããªåãã§ãååãåããŸãã
</p>
<p>
ã¿ã€ã ã»ãŒã«ãå§ãŸãæå»ããååãåãããšãã§ããŸããã売ãåããæå»ããã¯ååãåãããšãã§ããŸããããŸããæéã¯å
¥åºããæç¹ã§0ããå§ãŸããŸãã
</p>
<p>
ç§»åã¯çŸåšãããã¹ããäžäžå·Šå³ã®é£æ¥ããéè·¯ãã¹ã«ç§»åããããšãã§ããŸãããå忣ã®ãã¹ã«ç§»åããããšã¯ã§ããŸãããã°ãªããã§è¡šãããåºã®å€ã«åºãããšãã§ããŸãããïŒåç§»åããæ¯ã«ïŒåäœæéçµéããŸãããŸããååãåãæéã¯èããªããã®ãšããŸãã
</p>
<p>
åºå
ã®èŠåãå³ãšè²·ãç©ããã人ã®åæäœçœ®ãšååã®ã¿ã€ã ã»ãŒã«æ
å ±ãå
¥åãšããåãããšã®ã§ããååã®å€åŒãé¡ã®åèšã®æå€§å€ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>X</var> <var>Y</var>
<var>m<sub>1,1</sub></var> <var>m<sub>2,1</sub></var> ... <var>m<sub>X,1</sub></var>
<var>m<sub>1,2</sub></var> <var>m<sub>2,2</sub></var> ... <var>m<sub>X,2</sub></var>
:
<var>m<sub>1,Y</sub></var> <var>m<sub>2,Y</sub></var> ... <var>m<sub>X,Y</sub></var>
<var>n</var>
<var>g<sub>1</sub></var> <var>d<sub>1</sub></var> <var>s<sub>1</sub></var> <var>e<sub>1</sub></var>
<var>g<sub>2</sub></var> <var>d<sub>2</sub></var> <var>s<sub>2</sub></var> <var>e<sub>2</sub></var>
:
<var>g<sub>n</sub></var> <var>d<sub>n</sub></var> <var>s<sub>n</sub></var> <var>e<sub>n</sub></var>
</pre>
<p>
1è¡ç®ã«åºèã®å€§ãã<var>X</var>, <var>Y</var> (3 ≤ <var>X</var>, <var>Y</var> ≤ 20) ãäžããããŸããç¶ã <var>Y</var> è¡ã« <var>i</var> åç® <var>j</var> è¡ç®ã®åºå
æ
å ± <var>m<sub>i,j</sub></var> ã以äžã®å
容ã§äžããããŸãã<br>
. (ããªãªã) ïŒéè·¯ã®ãã¹<br>
æ°å ïŒååã®çªå·<br>
P ïŒè²·ãç©ããã人ã®åæäœçœ®ã®ãã¹<br>
</p>
<p>
ç¶ãè¡ã«ã¿ã€ã ã»ãŒã«æ
å ±ã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 8) ãäžããããŸããç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®ã¿ã€ã ã»ãŒã«æ
å ± <var>g<sub>i</sub></var> <var>d<sub>i</sub></var> <var>s<sub>i</sub></var> <var>e<sub>i</sub></var> ãäžããããŸã(0 ≤ <var>g<sub>i</sub></var> ≤ 9, 1 ≤ <var>d<sub>i</sub></var> ≤ 10000, 0 ≤ <var>s<sub>i</sub></var>, <var>e<sub>i</sub></var> ≤ 100)ã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãåãããšã®ã§ããååã®å€åŒãé¡åèšã®æå€§å€ãïŒè¡ã«åºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
6 5
1 1 . 0 0 4
1 . . . . .
. . 2 2 . .
. . 2 2 3 3
P . . . . .
5
0 50 5 10
1 20 0 10
2 10 5 15
3 150 3 5
4 100 8 9
0 0
</pre>
<h2>åºåäŸ</h2>
<pre>
180
</pre> |
p02556 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> points on the 2D plane, <var>i</var>-th of which is located on <var>(x_i, y_i)</var>.
There can be multiple points that share the same coordinate.
What is the maximum possible Manhattan distance between two distinct points?</p>
<p>Here, the <em>Manhattan distance</em> between two points <var>(x_i, y_i)</var> and <var>(x_j, y_j)</var> is defined by <var>|x_i-x_j| + |y_i-y_j|</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq x_i,y_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 1
2 4
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The Manhattan distance between the first point and the second point is <var>|1-2|+|1-4|=4</var>, which is maximum possible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1 1
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre></section>
</div>
</span> |
p00091 |
<H1>Blur</H1>
<p>
å³ 1 ã®ãã㪠10Ã10 ã®ãã¹ç®ã®ãåžãããããïŒ1ïŒ2ïŒã®ããã«X座æšã»Y座æšã®å€ã®å¯Ÿã§ãã¹ç®ã瀺ãããšã«ããŸãã座æšå€ã¯ 0 ããå§ãŸãæŽæ°ãšããŸããäŸãã°ãå³ 1 ã®âã®åº§æšã¯ (1, 2) ã§ãã
ãã®ãåžãã«ææãå°ããã€ããããŠæç©ãäœããŸãããããææã®æ»Žã«ã¯ã倧ããäžããå°ãã® 3 ãµã€ãºããããææã®æ»Žã®èœã¡ããã¹ç®ãäžå¿ã«å³ 1 ã®ããã«åšå²ãè²ãã€ããŸããå³ 1 ã§âãäžå¿ãâãè²ã®ã«ããç¯å²ã§ãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_19_1">
</center>
<br/>
<p>
ãåžãã¯ãæåã¯ããŸã£ãããã€ãŸããã©ã®ãã¹ç®ãè²ã®æ¿ãã瀺ãå€ã 0 ãšããŸããææã®æ»Žãèœã¡ãããšã«å€ã 1 ãã€å¢ããŠãããŸãããå°ããïŒ1, 2ïŒããäžããïŒ3, 2ïŒã«èœã¡ãå Žåãåãã¹ç®ã®å€ã¯å³ 2 ã®å·Šã®ããã«ãªããŸããææããã£ãããªãã®ã§ãå³ 2 ã®å³ã«ç€ºããããªã«ããç¯å²ãåžã®å€ã«ã¯ã¿åºããããªææã®èœãšãæ¹ã¯ããªãããšã«ãªã£ãŠããŸãããŸããåãå Žæã«è€æ°ã®ææããããããšããããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_19_2">
</center>
<br/>
<p>
ãã®ãããªäœæ¥ãäœåãç¹°ãè¿ããçµæãåžã«ãã°ãããæš¡æ§ãæµ®ãã³äžãããŸããããæ®å¿µãªããšã«ããã£ããäœæ¥çµéãèšé²ãå¿ããŠããŸããŸãããã©ãã«ããã£ã±ãæãåºããŸãããããããããŠãèœãšããææã®æ»Žæ°ã¯èŠããŠããŸãããããªãã¯ããã°ãããæç©ãåçŸããªããã°ãªããŸããããã°ãããæç©ã®ããŒã¿ãèªã¿ããã§ãã©ãã«ãã©ã®ãããªææãããããããåºåããããã°ã©ã ãäœæããŠãã ããããªããèœãšããææã®æ»Žæ°ã¯ 12 以äžãšããŸãã
</p>
<H2>å
¥å</H2>
<p>
å
¥åã®åœ¢åŒã¯ä»¥äžã®ãšããã§ãïŒ
</p>
<p>
æåã® 1 è¡ã«èœãšããææã®æ»Žæ° <var>n</var> ãäžããããŸããæ¬¡ã®è¡ãã 10 è¡ã«å座æšã®è²ã®æ¿ãã空çœåºåãã§äžããããŸãã
</p>
<H2>åºå</H2>
<p>
åºå㯠<var>n</var> è¡ãããªããŸããææã®æ»Žã®ã倧ãã 3ããäžãã 2ããå°ãã 1 ã§è¡šããèœãšããææããšã«ããã®X座æšãY座æšã滎ã®å€§ããã空çœã§åºåã£ãŠ1è¡ã«åºåããŠãã ããã
</p>
<p>
ææã®ãããæ¹ã¯ã©ã®ãããªé çªã§åºåããŠãè¯ããã®ãšããŸãã
</p>
<H2>å
¥åäŸ1</H2>
<pre>
2
0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 1 1 1 0 0 0 0 0
0 0 0 1 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
</pre>
<H2>åºåäŸ1</H2>
<pre>
3 2 1
8 4 2
</pre>
<br/>
<H2>å
¥åäŸ2</H2>
<pre>
6
0 0 1 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0 0
0 0 1 1 1 3 1 1 0 0
0 0 1 1 3 1 1 1 0 0
0 0 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 0 0
</pre>
<H2>åºåäŸ2</H2>
<pre>
2 2 3
7 7 3
6 3 2
3 6 2
4 4 1
5 5 1
</pre>
|
p02106 |
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem I: Tree-Light</h1>
<h2>Problem</h2>
<p>ããªãã¯ããªãŒã©ã€ããšããããªãŒç¶ã®ç
§æåšå
·ãè²·ã£ãŠããã</p>
<p>ãã®ç
§æåšå
·ã«ã¯<var>n</var>åã®æ¥ç¹ãããããããã<var>0</var>ãã<var>n−1</var>ãŸã§ã®çªå·ãã€ããŠããã忥ç¹ã¯10段éã®æããã衚çŸã§ããé»çãšãé»çã®ç¶æ
ãåãæ¿ããããã®è£
çœ®ã§æ§æãããŠãããæåããã¹ãŠã®æ¥ç¹ã®é»çã®æããã¯<var>0</var>ã§ããã</p>
<p>ãŸããæ¥ç¹ãšæ¥ç¹ã®éã«ã¯ã±ãŒãã«ç·ãããããã¹ãŠã®æ¥ç¹ã¯<var>n−1</var>æ¬ã®ã±ãŒãã«ç·ã«ãã£ãŠç¹ãããŠãããæ¥ç¹<var>0</var>ãäžã«ããŠåãäžãããããããã§ãæ¥ç¹<var>i</var>ããäžæ¹åã«0æ¬ä»¥äžã®ã±ãŒãã«ç·ãä»ããŠãæ¥ç¹<var>i</var>ãšç¹ããæ¥ç¹ã®éåããæ¥ç¹<var>i</var>ãæ ¹ãšããéšåæšãšåŒã¶ã</p>
<p>ããªãã¯ãã®ç
§æåšå
·ã«å¯Ÿãã以äžã®ããããã®è¡åããšãã</p>
<ul>
<li><var>count(r, x, y)</var>: æ¥ç¹<var>r</var>ãæ ¹ãšããéšåæšã«å«ãŸããæ¥ç¹ã®é»çã®äžã§ãæããã<var>x</var>以äž<var>y</var>以äžã«ãªã£ãŠããé»çã®æ°ãæ°ããã</li>
<li><var>change(r, x, y)</var>: æ¥ç¹<var>r</var>ãæ ¹ãšããéšåæšã«å«ãŸããæ¥ç¹ã®é»çã®äžã§ãæãããã¡ããã©<var>x</var>ã«ãªã£ãŠãããã¹ãŠã®é»çã®æããã<var>y</var>ã«å€æŽããã</li>
</ul>
<p><var>q</var>åã®è¡åãäžããããã®ã§ã<var>count(r, x, y)</var>ãäžãããããã³ã«ãã®æç¹ã§ã®é»çã®æ°ãåºåããã</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>n</var> <var>q</var>
<var>u<sub>1</sub></var> <var>v<sub>1</sub></var>
<var>u<sub>2</sub></var> <var>v<sub>2</sub></var>
...
<var>u<sub>n−1</sub></var> <var>v<sub>n−1</sub></var>
<var>t<sub>1</sub></var> <var>r<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>t<sub>2</sub></var> <var>r<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
...
<var>t<sub>q</sub></var> <var>r<sub>q</sub></var> <var>x<sub>q</sub></var> <var>y<sub>q</sub></var>
</pre>
<p>
1è¡ç®ã«ããªãŒã©ã€ããæ§æããæ¥ç¹ã®æ°<var>n</var>ãããªãã®ãšãè¡åã®æ°<var>q</var>ã空çœåºåãã§äžããããã<br>
ç¶ã<var>n−1</var>è¡ã«ã¯ã±ãŒãã«ç·ã®æ
å ±ã空çœåºåãã§äžããããã<var>i</var>çªç®ã®ã±ãŒãã«ç·ã®æ
å ±ã¯ãã±ãŒãã«ç·<var>i</var>ãæ¥ç¹<var>u<sub>i</sub></var>ãäžã«ããŠãæ¥ç¹<var>u<sub>i</sub></var>ãšæ¥ç¹<var>v<sub>i</sub></var>ãç¹ãããšã衚ãã<br>
<var>n+1</var>è¡ç®ä»¥éã®<var>q</var>è¡ã«ã¯ããªãã®ãšãè¡åã空çœåºåãã§äžããããã<var>t<sub>i</sub> = 1</var>ãªã<var>count(r<sub>i</sub>, x<sub>i</sub>, y<sub>i</sub>)</var>ãã<var>t<sub>i</sub> = 2</var>ãªã<var>change(r<sub>i</sub>, x<sub>i</sub>, y<sub>i</sub>)</var>ã衚ãã
</p>
<h2>Constraints</h2>
<ul>
<li><var>1 ≤ n ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ q ≤ 10<sup>5</sup></var></li>
<li><var>0 ≤ u<sub>i</sub>, v<sub>i</sub>, r<sub>i</sub> ≤ n−1 (u<sub>i</sub> â v<sub>i</sub>)</var></li>
<li><var>0 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 9 (t<sub>i</sub> = 1</var>ã®æ<var>x<sub>i</sub> ≤ y<sub>i</sub>)</var></li>
</ul>
<h2>Output</h2>
<p>å<var>count(r<sub>i</sub>, x<sub>i</sub>, y<sub>i</sub>)</var>ã«ã€ããŠããã®çãã1è¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
7 5
0 1
1 2
1 3
0 4
4 5
4 6
1 0 0 9
2 0 0 5
2 1 5 8
1 0 5 8
1 0 8 8
</pre>
<h2>Sample Output 1</h2>
<pre>
7
7
3
</pre>
<h2>Sample Input 2</h2>
<pre>
7 5
0 1
1 2
2 3
0 4
4 5
5 6
2 1 0 5
2 4 0 6
2 3 5 6
2 5 6 5
1 0 0 5
</pre>
<h2>Sample Output 2</h2>
<pre>
5
</pre> |
p03347 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a sequence <var>X</var> of length <var>N</var>, where every element is initially <var>0</var>. Let <var>X_i</var> denote the <var>i</var>-th element of <var>X</var>.</p>
<p>You are given a sequence <var>A</var> of length <var>N</var>. The <var>i</var>-th element of <var>A</var> is <var>A_i</var>. Determine if we can make <var>X</var> equal to <var>A</var> by repeating the operation below. If we can, find the minimum number of operations required.</p>
<ul>
<li>Choose an integer <var>i</var> such that <var>1\leq i\leq N-1</var>. Replace the value of <var>X_{i+1}</var> with the value of <var>X_i</var> plus <var>1</var>.</li>
</ul>
</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 \leq 10^9(1\leq i\leq N)</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var>
<var>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If we can make <var>X</var> equal to <var>A</var> by repeating the operation, print the minimum number of operations required. If we cannot, print <var>-1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
0
1
1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We can make <var>X</var> equal to <var>A</var> as follows:</p>
<ul>
<li>Choose <var>i=2</var>. <var>X</var> becomes <var>(0,0,1,0)</var>.</li>
<li>Choose <var>i=1</var>. <var>X</var> becomes <var>(0,1,1,0)</var>.</li>
<li>Choose <var>i=3</var>. <var>X</var> becomes <var>(0,1,1,2)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1
2
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9
0
1
1
0
1
2
2
1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p00992 |
<h1>Problem C : War</h1>
<p>
AåœãšBåœãšããïŒã€ã®åœãæŠäºãããŠãããAåœã®è»äººã§ããããªãã¯<i>n</i>人ã®å
µå£«ãçããŠãBåœã®é åãå é ããäºã«ãªã£ãã
</p>
<p>
Båœã®é åã¯ïŒæ¬¡å
ã°ãªããã§è¡šãããŠãããããªããæåã«å é ããå Žæã¯äºæ¬¡å
ã°ãªããäžã®ããïŒãã¹ã§ããã
ããªããçããŠããå
µå£«ãã¡ã¯ãããããh_iã®äœåãæã£ãŠããã
ããããã®å
µå£«ã¯äœåã1ãæ¶è²»ããŠç§»åããããšãã§ããã
çŸåšãããã¹ã(a,b)ãšãããšã(a+1,b),(a-1,b),(a,b+1),(a,b-1)ã®4æ¹åãç§»åå
ãšããŠéžã¶ããšãå¯èœã§ããã
å
µå£«ã¯äœåã0ã«ãªã£ããããããåãããšãã§ããªããªãã
äžäººä»¥äžã®å
µå£«ãééãããã¹ã¯ãã¹ãŠå é ããããšãã§ããã
</p>
<p>
ããªãã®ä»äºã¯ãæå€§ã§ããã€ã®ãã¹ãå é ããããšãã§ããããæ±ããããšã§ããã<br>
ãã ãããã®ïŒæ¬¡å
ã°ãªããã®ãµã€ãºã¯ç¡éã«åºããšããããšã<br>
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>n</i>
<i>h<sub>1</sub></i>
.
.
.
<i>h<sub>n</sub></i>
</pre>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºãã<br>
1 ≤ <i>n</i> ≤ 500<br>
1 ≤ <i>h<sub>i</sub></i> ≤ 10,000,000<br>
</p>
<h2>Output</h2>
<p>
çãã®å€ãïŒè¡ã«åºåãã
</p>
<h2>Sample Input 1</h2>
<pre>
2
5
5
</pre>
<h2>Sample Output 1</h2>
<pre>
11
</pre>
<h2>Sample Input 2</h2>
<pre>
10
10
10
10
10
10
10
10
10
10
10
</pre>
<h2>Sample Output 2</h2>
<pre>
93
</pre>
<h2>Sample Input 3</h2>
<pre>
5
1
2
3
4
5
</pre>
<h2>Sample Output 3</h2>
<pre>
15
</pre>
|
p01680 |
<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>"Everlasting -One-" is an award-winning online game launched this year. This game has rapidly become famous for its large number of characters you can play.
</p>
<p>In this game, a character is characterized by <i>attributes</i>. There are $N$ attributes in this game, numbered $1$ through $N$. Each attribute takes one of the two states, <i>light</i> or <i>darkness</i>. It means there are $2^N$ kinds of characters in this game.
</p>
<p>You can change your character by job change. Although this is the only way to change your character's attributes, it is allowed to change jobs as many times as you want.
</p>
<p>The rule of job change is a bit complex. It is possible to change a character from $A$ to $B$ if and only if there exist two attributes $a$ and $b$ such that they satisfy the following four conditions:
</p>
<ul><li><p> The state of attribute $a$ of character $A$ is <i>light</i>.
</p></li><li><p> The state of attribute $b$ of character $B$ is <i>light</i>.
</p></li><li><p> There exists no attribute $c$ such that both characters $A$ and $B$ have the <i>light</i> state of attribute $c$.
</p></li><li><p> A pair of attribute $(a, b)$ is <i>compatible</i>.
</p></li></ul>
<p>Here, we say a pair of attribute $(a, b)$ is <i>compatible</i> if there exists a sequence of attributes $c_1, c_2, \ldots, c_n$ satisfying the following three conditions:
</p>
<ul><li><p> $c_1 = a$.
</p></li><li><p> $c_n = b$.
</p></li><li><p> Either $(c_i, c_{i+1})$ or $(c_{i+1}, c_i)$ is a special pair for all $i = 1, 2, \ldots, n-1$. You will be given the list of special pairs.
</p></li></ul>
<p>Since you love this game with enthusiasm, you are trying to play the game with all characters (it's really crazy). However, you have immediately noticed that one character can be changed to a limited set of characters with this game's job change rule. We say character $A$ and $B$ are <i>essentially different</i> if you cannot change character $A$ into character $B$ by repeating job changes.
</p>
<p>Then, the following natural question arises; how many essentially different characters are there?
Since the output may be very large, you should calculate the answer modulo $1{,}000{,}000{,}007$.
</p>
<h3>Input</h3>
<p>The input is a sequence of datasets.
The number of datasets is not more than $50$ and the total size of input is less than $5$ MB.
</p>
<p>Each dataset is formatted as follows.
</p><blockquote>$N$ $M$<br>$a_1$ $b_1$<br>:<br>:<br>$a_M$ $b_M$</blockquote>
<p>The first line of each dataset contains two integers $N$ and $M$ ($1 \le N \le 10^5$ and $0 \le M \le 10^5$).
Then $M$ lines follow.
The $i$-th line contains two integers $a_i$ and $b_i$ ($1 \le a_i \lt b_i \le N$) which denote the $i$-th special pair.
The input is terminated by two zeroes.
</p>
<p>It is guaranteed that $(a_i, b_i) \ne (a_j, b_j)$ if $i \ne j$.
</p>
<h3>Output</h3>
<p>For each dataset, output the number of essentially different characters modulo $1{,}000{,}000{,}007$.
</p>
<h3>Sample Input</h3>
<pre>3 2
1 2
2 3
5 0
100000 0
0 0</pre>
<h3>Output for the Sample Input</h3>
<pre>3
32
607723520</pre> |
p00838 |
<H1><font color="#000">Problem C:</font> Colored Cubes</H1>
<p>
There are several colored cubes. All of them are of the same size but they may be colored
differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or
may not be the same.
</p>
<p>
Two cubes are said to be <i>identically</i> colored if some suitable rotations of one of the cubes give
identical looks to both of the cubes. For example, two cubes shown in Figure 2 are identically
colored. A set of cubes is said to be identically colored if every pair of them are identically
colored.
</p>
<p>
A cube and its mirror image are not necessarily identically colored. For example, two cubes
shown in Figure 3 are not identically colored.
</p>
<p>
You can make a given set of cubes identically colored by repainting some of the faces, whatever
colors the faces may have. In Figure 4, repainting four faces makes the three cubes identically
colored and repainting fewer faces will never do.
</p>
<p>
Your task is to write a program to calculate the minimum number of faces that needs to be
repainted for a given set of cubes to become identically colored.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. A dataset consists of a header and a body appearing in this
order. A header is a line containing one positive integer n and the body following it consists
of <i>n</i> lines. You can assume that 1 ≤ <i>n</i> ≤ 4. Each line in a body contains six color names
separated by a space. A color name consists of a word or words connected with a hyphen (-).
A word consists of one or more lowercase letters. You can assume that a color name is at most
24-characters long including hyphens.
</p>
<p>
A dataset corresponds to a set of colored cubes. The integer n corresponds to the number of
cubes. Each line of the body corresponds to a cube and describes the colors of its faces. Color
names in a line is ordered in accordance with the numbering of faces shown in Figure 5. A line
</p>
<pre>
<i>color</i><sub>1</sub> <i>color</i><sub>2</sub> <i>color</i><sub>3</sub> <i>color</i><sub>4</sub> <i>color</i><sub>5</sub> <i>color</i><sub>6</sub>
</pre
<p>
corresponds to a cube colored as shown in Figure 6.
</p>
<p>
The end of the input is indicated by a line containing a single zero. It is not a dataset nor a
part of a dataset.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_coloredCube23"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_coloredCube4"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_coloredCube56"><br>
</center>
<H2>Output</H2>
<p>
For each dataset, output a line containing the minimum number of faces that need to be repainted
to make the set of cubes identically colored.
</p>
<H2>Sample Input</H2>
<pre>
3
scarlet green blue yellow magenta cyan
blue pink green magenta cyan lemon
purple red blue yellow cyan green
2
red green blue yellow magenta cyan
cyan green blue yellow magenta red
2
red green gray gray magenta cyan
cyan green gray gray magenta red
2
red green blue yellow magenta cyan
magenta red blue yellow cyan green
3
red green blue yellow magenta cyan
cyan green blue yellow magenta red
magenta red blue yellow cyan green
3
blue green green green green blue
green blue blue green green green
green green green green green sea-green
3
red yellow red yellow red yellow
red red yellow yellow red yellow
red red red red red red
4
violet violet salmon salmon salmon salmon
violet salmon salmon salmon salmon violet
violet violet salmon salmon violet violet
violet violet violet violet salmon salmon
1
red green blue yellow magenta cyan
4
magenta pink red scarlet vermilion wine-red
aquamarine blue cyan indigo sky-blue turquoise-blue
blond cream chrome-yellow lemon olive yellow
chrome-green emerald-green green olive vilidian sky-blue
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
0
0
2
3
4
4
0
16
</pre>
|
p02805 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are <var>N</var> points <var>(x_i, y_i)</var> in a two-dimensional plane.</p>
<p>Find the minimum radius of a circle such that all the points are inside or on it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 50</var></li>
<li><var>0 \leq x_i \leq 1000</var></li>
<li><var>0 \leq y_i \leq 1000</var></li>
<li>The given <var>N</var> points are all different.</li>
<li>The values in input are all integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum radius of a circle such that all the <var>N</var> points are inside or on it.</p>
<p>Your output will be considered correct if the absolute or relative error from our answer is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0 0
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0.500000000000000000
</pre>
<p>Both points are contained in the circle centered at <var>(0.5,0)</var> with a radius of <var>0.5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 0
0 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0.707106781186497524
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6.726812023536805158
</pre>
<p>If the absolute or relative error from our answer is at most <var>10^{-6}</var>, the output will be considered correct.</p></section>
</div>
</span> |
p03717 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares arranged in a row.
The squares are numbered <var>1</var>, <var>2</var>, <var>...</var>, <var>N</var>, from left to right.</p>
<p>Snuke is painting each square in red, green or blue.
According to his aesthetic sense, the following <var>M</var> conditions must all be satisfied.
The <var>i</var>-th condition is:</p>
<ul>
<li>There are exactly <var>x_i</var> different colors among squares <var>l_i</var>, <var>l_i + 1</var>, <var>...</var>, <var>r_i</var>.</li>
</ul>
<p>In how many ways can the squares be painted to satisfy all the conditions?
Find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †300</var></li>
<li><var>1 †M †300</var></li>
<li><var>1 †l_i †r_i †N</var></li>
<li><var>1 †x_i †3</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>l_1</var> <var>r_1</var> <var>x_1</var>
<var>l_2</var> <var>r_2</var> <var>x_2</var>
<var>:</var>
<var>l_M</var> <var>r_M</var> <var>x_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to paint the squares to satisfy all the conditions, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
1 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The six ways are:</p>
<ul>
<li>RGB</li>
<li>RBG</li>
<li>GRB</li>
<li>GBR</li>
<li>BRG</li>
<li>BGR</li>
</ul>
<p>where R, G and B correspond to red, green and blue squares, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2
1 3 1
2 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
<p>The six ways are:</p>
<ul>
<li>RRRG</li>
<li>RRRB</li>
<li>GGGR</li>
<li>GGGB</li>
<li>BBBR</li>
<li>BBBG</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 3
1 1 1
1 1 2
1 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>There are zero ways.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8 10
2 6 2
5 5 1
3 5 2
4 7 3
4 4 1
2 3 1
7 7 1
1 5 2
1 7 3
3 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>108
</pre></section>
</div>
</span> |
p03202 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> strings arranged in a row.
It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right.
That is, <var>S_1<S_2<...<S_N</var> holds lexicographically, where <var>S_i</var> is the <var>i</var>-th string from the left.</p>
<p>At least how many different characters are contained in <var>S_1,S_2,...,S_N</var>, if the length of <var>S_i</var> is known to be <var>A_i</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2\times 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>A_i</var> is an integer.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Note</h3><p>The strings do not necessarily consist of English alphabet; there can be arbitrarily many different characters (and the lexicographic order is defined for those characters).</p>
</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 different characters contained in the strings.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The number of different characters contained in <var>S_1,S_2,...,S_N</var> would be <var>3</var> when, for example, <var>S_1=</var><code>abc</code>, <var>S_2=</var><code>bb</code> and <var>S_3=</var><code>c</code>.</p>
<p>However, if we choose the strings properly, the number of different characters can be <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
2 3 2 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre></section>
</div>
</span> |
p01395 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">åé¡ H </font>ãã°ãããªã</h1>
<h2>å顿</h2>
<p>ãã€ãã®ãããã¯ããªããé£ã¹ãã®ã奜ãã§ããïŒ</p>
<p><var>2T+1</var> æã®éæ¿ãé£ç¶ããŠäžŠãã§ããïŒé çªã« <var>-T, -T+1, ..., T</var> ã®çªå·ãä»ããŠããïŒãããã¯ãããã®éæ¿ã«ç±ãå ãïŒçããããªããçŒãããšããŠããïŒããªããçŒãæé ã¯ä»¥äžã®ãããªãã®ã§ããïŒ</p>
<ul>
<li>ãŸãïŒæå» <var>t=-1</var> ã®ãšãã«åéæ¿ã«ã©ãã ãã®ãšãã«ã®ãŒãå ããããæ±ºãïŒå®éã«ãšãã«ã®ãŒãå ããïŒåéæ¿ã«å ãããšãã«ã®ãŒã®ç·å㯠<var>E</var> 以äžã§ãªããã°ãªããªãïŒããªãã¡ïŒ<var>i</var> çªã®éæ¿ã«å ãããšãã«ã®ãŒã <var>E(i)</var> ãšããŠïŒ<var>E(i) ≥ 0, E(-T)+...+E(T) ≤ E</var> ã§ãªããã°ãªããªãïŒãªãïŒãšãã«ã®ãŒã¯æŽæ°ã§ãªããŠãããïŒ</li>
<li>ãšãã«ã®ãŒãå ããããšïŒéæ¿ã®ç±ã㯠<var>E(i) / C(i)</var> ã«ãªãïŒããã§ïŒ<var>C(i)</var> 㯠<var>i</var> çªã®éæ¿ã®æ¯ç±ã§ããïŒ</li>
<li><var>t = -0.5</var> ã®ãšãã«ããªãã <var>0</var> çªã®éæ¿ã«èŒããïŒ</li>
<li><var>t = 0, 1, 2,..., T</var> ã®ãšãã«ïŒããªãã¯ä»èªåãããéæ¿ã®ç±ãã ãå ç±ãããïŒ</li>
<li><var>t = 0.5, 1.5, 2.5,...,T-0.5</var> ã®ãšãïŒããªãã¯èªåã®ä»ããéæ¿ã«ãšã©ãŸããïŒäž¡é£ã®éæ¿ã«ç§»åããããšãã§ããïŒ</li>
<li><var>t = T+0.5</var> ã®ãšãã«ããªããéæ¿ã®äžããååããïŒ</li>
</ul>
<p>ãšããã§çããããªããšããã®ã¯ãšãŠã掻ããããããã«é ãè¯ãã®ã§ïŒããããããšèªåã«ãããç±ãã®ç·åãæå°ã«ãªãããã«åããããããã§ã¯ãªãããšãããã¯äžå®ã«ãªã£ãïŒãããªããšéæ¿ã«é©åœã«ç±ãå ããã ãã§ã¯ããªããååã«å ç±ã§ããªãæãããããïŒ</p>
<p>ããã§ããªãã«ã¯ïŒããªããåžžã«æé©ã«åããšããŠïŒããªãã«äžããããšã®ã§ããç±ãã®åã®æå€§å€ãæ±ããŠæ¬²ããïŒ</p>
<h2>å
¥å圢åŒ</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ</p>
<pre><var>T</var> <var>E</var>
<var>C(-T)</var> <var>C(-T+1)</var> ... <var>C(T)</var>
</pre>
<var>T</var> ã¯ããªããç±ããæéïŒ<var>E</var> ã¯éæ¿ã«äžããããšã®åºæ¥ããšãã«ã®ãŒã®ç·åïŒ<var>C(i)</var> 㯠<var>i</var> çªã®éæ¿ã®æ¯ç±ã§ããïŒ
<h2>åºå圢åŒ</h2>
<p><var>1</var> è¡ç®ã«ããªãã«äžããããç±ãã®åã®æå€§å€ãåºåããïŒå°æ°ç¹ä»¥äžäœæ¡ã§ãåºåããŠæ§ããªããïŒçžå¯Ÿèª€å·®ãããã¯çµ¶å¯Ÿèª€å·®ã <var>10<sup>-6</sup></var> æªæºã«ãªã£ãŠããªããã°ãªããªãïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ T ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ E ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ C(i) ≤ 10<sup>5</sup></var></li>
<li>å
¥åã«å«ãŸããå€ã¯ãã¹ãп޿°ã§ããïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
1 100
1 1 1
</pre>
<h3>åºåäŸ 1</h3>
<pre>
100.0
</pre>
<p>ãã®å Žå㯠<var>0</var> çªã®éæ¿ã«ãšãã«ã®ãŒãå
šãŠå ããã®ãæé©ã§ããïŒ</p>
<h3>å
¥åäŸ 2</h3>
<pre>
2 100
1 2 100 2 1
</pre>
<h3>åºåäŸ 2</h3>
<pre>
2.8301886792453
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
5 100000
99999 99999 99999 1 1000 1000 1000 1 99999 99999 99999
</pre>
<h3>åºåäŸ 3</h3>
<pre>
199.4680851063830
</pre>
<h2>è¬èŸ</h2>
ãã®åé¡ã¯ Writer ã®äºäººãã€ã³ãæç RAJU çŸäžéåºãšãã¯ããã«ãçŸäžéåºã«ãããŠå€ã®æãã«èŸæããäžã§äœãããïŒ
|
p02940 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>3N</var> colored balls with IDs from <var>1</var> to <var>3N</var>.
A string <var>S</var> of length <var>3N</var> represents the colors of the balls. The color of Ball <var>i</var> is red if <var>S_i</var> is <code>R</code>, green if <var>S_i</var> is <code>G</code>, and blue if <var>S_i</var> is <code>B</code>. There are <var>N</var> red balls, <var>N</var> green balls, and <var>N</var> blue balls.</p>
<p>Takahashi will distribute these <var>3N</var> balls to <var>N</var> people so that each person gets one red ball, one blue ball, and one green ball.
The people want balls with IDs close to each other, so he will additionally satisfy the following condition:</p>
<ul>
<li>Let <var>a_j < b_j < c_j</var> be the IDs of the balls received by the <var>j</var>-th person in ascending order.</li>
<li>Then, <var>\sum_j (c_j-a_j)</var> should be as small as possible.</li>
</ul>
<p>Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo <var>998244353</var>.
We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>|S|=3N</var></li>
<li><var>S</var> consists of <code>R</code>, <code>G</code>, and <code>B</code>, and each of these characters occurs <var>N</var> times in <var>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>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways in which Takahashi can distribute the balls, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
RRRGGGBBB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>216
</pre>
<p>The minimum value of <var>\sum_j (c_j-a_j)</var> is <var>18</var> when the balls are, for example, distributed as follows:</p>
<ul>
<li>The first person gets Ball <var>1</var>, <var>5</var>, and <var>9</var>.</li>
<li>The second person gets Ball <var>2</var>, <var>4</var>, and <var>8</var>.</li>
<li>The third person gets Ball <var>3</var>, <var>6</var>, and <var>7</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
BBRGRRGRGGRBBGB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>960
</pre></section>
</div>
</span> |
p03652 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is hosting an sports meet.
There are <var>N</var> people who will participate. These people are conveniently numbered <var>1</var> through <var>N</var>.
Also, there are <var>M</var> options of sports for this event. These sports are numbered <var>1</var> through <var>M</var>.
Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.</p>
<p>Takahashi knows that Person <var>i</var>'s <var>j</var>-th favorite sport is Sport <var>A_{ij}</var>.
Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.</p>
<p>Takahashi is worried that one of the sports will attract too many people.
Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized.
Find the minimum possible number of the participants in the sport with the largest number of participants.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li><var>1 \leq M \leq 300</var></li>
<li><var>A_{i1}</var> , <var>A_{i2}</var> , <var>...</var> , <var>A_{iM}</var> is a permutation of the integers from <var>1</var> to <var>M</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_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1M}</var>
<var>A_{21}</var> <var>A_{22}</var> <var>...</var> <var>A_{2M}</var>
<var>:</var>
<var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NM}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible number of the participants in the sport with the largest number of participants.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Assume that Sports <var>1</var>, <var>3</var> and <var>4</var> are selected to be played. In this case, Person <var>1</var> will participate in Sport <var>1</var>, Person <var>2</var> in Sport <var>3</var>, Person <var>3</var> in Sport <var>3</var> and Person <var>4</var> in Sport <var>4</var>.
Here, the sport with the largest number of participants is Sport <var>3</var>, with two participants.
There is no way to reduce the number of participants in the sport with the largest number of participants to <var>1</var>. Therefore, the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
2 1 3
2 1 3
2 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected.
Therefore, the answer is <var>3</var>.</p></section>
</div>
</span> |
p02413 |
<H1>Spreadsheet</H1><br>
<p>
Your task is to perform a simple table calculation.
</p>
<p>
Write a program which reads the number of rows <var>r</var>, columns <var>c</var> and a table of <var>r</var> × <var>c</var> elements, and prints a new table, which includes the total sum for each row and column.
</p>
<H2>Input</H2>
<p>
In the first line, two integers <var>r</var> and <var>c</var> are given. Next, the table is given by <var>r</var> lines, each of which consists of <var>c</var> integers separated by space characters.
</p>
<H2>Output</H2>
<p>
Print the new table of (<var>r</var>+1) × (<var>c</var>+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table.
</p>
<H2>Constraints</H2>
<ul>
<li> 1 ≤ <var>r</var>, <var>c</var> ≤ 100</li>
<li> 0 ≤ an element of the table ≤ 100</li>
</ul>
<H2>Sample Input</H2>
<pre>
4 5
1 1 3 4 5
2 2 2 4 5
3 3 0 1 1
2 3 4 4 6
</pre>
<H2>Sample Output</H2>
<pre>
1 1 3 4 5 14
2 2 2 4 5 15
3 3 0 1 1 8
2 3 4 4 6 19
8 9 9 13 17 56
</pre>
|
p00584 | <h1>ã³ã€ã³éã(Coin Collecting)</h1>
<p>
JOI æ°ã®ã³ã¬ã¯ã·ã§ã³ã«ãŒã ã«ã¯éåžžã«å€§ããªæºãããïŒãã®äžã«ã¯äœæãã®è²Žéãªã³ã€ã³ãããïŒæºã®æé€ãããããã«ïŒJOI æ°ã¯ã³ã€ã³ãæŽçããŠäžŠã¹ãããšã«ããïŒ
</p>
<p>
æºã¯2 000 000 001 $\times$ 2 000 000 001 ã®ãã¹ç®ã«ãªã£ãŠããïŒåã«ã¯å·Šããé ã«-1 000 000 000 ãã1 000 000 000ãŸã§ã®çªå·ãã€ããããŠããïŒè¡ã«ã¯äžããé ã«-1 000 000 000 ãã1 000 000 000 ãŸã§ã®çªå·ãã€ããããŠããïŒåã®çªå·ã$x$ïŒè¡ã®çªå·ã$y$ ã§ãããã¹ã($x, y$) ã§è¡šãããšã«ããïŒ
</p>
<p>
ã³ã€ã³ã¯$2N$ æããïŒçŸåšïŒ$i$ çªç®($1 \leq i \leq 2N$) ã®ã³ã€ã³ã¯ãã¹($X_i, Y_i$) ã«çœ®ãããŠããïŒJOI æ°ã®ç®æšã¯ïŒ$1 \leq x \leq N$ ãã€$1 \leq y \leq 2$ ãæºãã($x, y$) ã§è¡šããã$2N$ åã®ãã¹ã«ïŒããããã³ã€ã³ã1 æãã€çœ®ãããŠããç¶æ
ã«ããããšã§ããïŒã³ã€ã³ãå·ã€ããªãããã«ããããïŒãã³ã€ã³ã1 æéžã³ïŒããã眮ãããŠãããã¹ãšèŸºã§é£ãåã£ããã¹ã®ããããã«ïŒãã®ã³ã€ã³ãç§»åãããããšããæäœã®ã¿ãã§ããïŒéäžïŒè€æ°ã®ã³ã€ã³ãåããã¹ã«çœ®ãããŠããŠãããïŒJOI æ°ã¯ïŒã§ããã ãå°ãªãåæ°ã®æäœã§ç®æšãéæãããïŒ
</p>
<p>
ã³ã€ã³ã®ææ°ãšïŒçŸåšã³ã€ã³ã眮ãããŠãããã¹ãäžãããããšãïŒç®æšãéæããããã«å¿
èŠãªæäœåæ°ã®æå°å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ
</p>
<pre>
$N$
$X_1$ $Y_1$
:
$X_{2N}$ $Y_{2N}$
</pre>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒç®æšãéæããããã«å¿
èŠãªæäœåæ°ã®æå°å€ã1 è¡ã§åºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$ 1 \leq N \leq 100 000$ïŒ</li>
<li>$ -1 000 000 000 \leq X_i \leq 1 000 000 000 (1 \leq i \leq 2N)$ïŒ</li>
<li>$ -1 000 000 000 \leq Y_i \leq 1 000 000 000 (1 \leq i \leq 2N)$ïŒ</li>
</ul>
<!--
å°èª²é¡
1. (8 ç¹) N ⊠10ïŒ
2. (29 ç¹) N ⊠1 000ïŒ
3. (63 ç¹) 远å ã®å¶çŽã¯ãªãïŒ
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
3
0 0
0 4
4 0
2 1
2 5
-1 1
</pre>
<h3> åºåäŸ1</h3>
<pre>
15
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒ6 åã®ã³ã€ã³ãäžå³ã®ããã«çœ®ãããŠããïŒå€ªæ ã§ç€ºããäœçœ®ã«ã³ã€ã³ãéããã®ãç®æšã§ããïŒ
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/joi2018_ho_t4_00">
<p>
äŸãã°ïŒã³ã€ã³ã以äžã®ããã«ç§»åããããšïŒ15 åã®æäœã§ç®æšãéæã§ããïŒ
</p>
<ul>
<li> 1 çªç®ã®ã³ã€ã³ïŒ(0, 0) â (1, 0) â (1, 1) â (1, 2)</li>
<li> 2 çªç®ã®ã³ã€ã³ïŒ(0, 4) â (1, 4) â (1, 3) â (2, 3) â (3, 3) â (3, 2)</li>
<li> 3 çªç®ã®ã³ã€ã³ïŒ(4, 0) â (4, 1) â (3, 1)</li>
<li> 5 çªç®ã®ã³ã€ã³ïŒ(2, 5) â (2, 4) â (2, 3) â (2, 2)</li>
<li> 6 çªç®ã®ã³ã€ã³ïŒ(-1, 1) â (0, 1) â (1, 1)</li>
</ul>
<p>
14 å以äžã®æäœã§ç®æšãéæããããšã¯ã§ããªãã®ã§ïŒ15 ãåºåããïŒ
</p>
<h3>å
¥åäŸ2</h3>
<pre>
4
2 1
2 1
2 1
3 1
3 1
3 1
3 1
3 1
</pre>
<h3>åºåäŸ2</h3>
<pre>
9
</pre>
<p>
åããã¹ã«è€æ°ã®ã³ã€ã³ã眮ãããŠãããããããªãïŒ
</p>
<h3>å
¥åäŸ3</h3>
<pre>
5
1000000000 1000000000
-1000000000 1000000000
-1000000000 -1000000000
1000000000 -1000000000
-1 -5
-2 2
2 8
4 7
-2 5
7 3
</pre>
<h3>åºåäŸ3</h3>
<pre>
8000000029
</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>
|
p02043 | <h1>G: ã€ã«ãããŒã·ã§ã³</h1>
<h2>åé¡</h2>
<p>
$1 \leq x \leq h , 1 \leq y \leq w$ ãã¿ããæ Œåç¹ $(x,y)$ ã«é»çããã.
</p>
<p>
黿ºè£
眮ã¯åº§æš $(i+0.5,j+0.5) (1 \leq i < h,1 \leq j < w, i+j$ ã¯å¶æ°ïŒã«èšçœ®ãããŠãã(14:21ä¿®æ£).
åº§æš $(i+0.5,j+0.5)$ ã«èšçœ®ãããŠãã黿ºè£
眮ããªã³ã«ãããš, åº§æš $(i,j),(i+1,j),(i,j+1),(i+1,j+1)$ ã«ååšãã $4$ ã€ã®é»çãå
ã.
</p>
<p>
$(i,j)$ ã«ããé»çããªã³ã«ãªã£ãŠãã黿ºè£
眮㫠$1$ ã€ä»¥äžã€ãªãã£ãŠãããš, ãããã $B_{i,j}$ ãåŸããã. ããªãã¯, ããããã®åèšåã®åå
¥ããããã.
ãŸã, ããããã®é»æºè£
眮ããªã³ã«ãããš, $1$ ã€ããã黿°ä»£ã $W$ ããã.
</p>
<p>
ããã€ãã®é»æºããªã³ã«ããŠãåå
¥ã®åèš - 黿°ä»£ã®åèšããæå€§åããªãã.
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$2 \leq h, w \leq 50$ </li>
<li>$0 \leq B_{i,j},W \leq 10^9$ </li>
<li>$h,w$ ã¯å¶æ°</li>
<li>å
¥åã¯ãã¹ãп޿°</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. </p>
<p>
$h\ w \ W$<br>
$B_{1,1} \dots B_{1,w}$<br>
$\vdots$<br>
$B_{h,1} \dots B_{h,w}$<br>
</p>
<h2>åºå</h2>
<p>ãåå
¥ã®åèš - 黿°ä»£ã®åèšãã®æå€§å€ãåºåãã. ãŸã, æ«å°Ÿã«æ¹è¡ãåºåãã. </p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
4 4 10
100 100 100 100
100 100 100 100
1 100 100 1
1 1 1 1
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
970
</pre>
<br>
<p>
以äžã®ããã« $@$ ã®äœçœ®ã®é»æºããªã³ã«ã, $X$ ã®äœçœ®ã®é»æºããªãã«ããã®ãæåã§ãã.
</p>
<pre>
100 100 100 100
@ @
100 100 100 100
@
1 100 100 1
X X
1 1 1 1
</pre>
|
p03081 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>There are <var>N</var> squares numbered <var>1</var> to <var>N</var> from left to right.
Each square has a character written on it, and Square <var>i</var> has a letter <var>s_i</var>. Besides, there is initially one golem on each square.</p>
<p>Snuke cast <var>Q</var> spells to move the golems.</p>
<p>The <var>i</var>-th spell consisted of two characters <var>t_i</var> and <var>d_i</var>, where <var>d_i</var> is <code>L</code> or <code>R</code>.
When Snuke cast this spell, for each square with the character <var>t_i</var>, all golems on that square moved to the square adjacent to the left if <var>d_i</var> is <code>L</code>, and moved to the square adjacent to the right if <var>d_i</var> is <code>R</code>.</p>
<p>However, when a golem tried to move left from Square <var>1</var> or move right from Square <var>N</var>, it disappeared.</p>
<p>Find the number of golems remaining after Snuke cast the <var>Q</var> spells.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,Q \leq 2 \times 10^{5}</var></li>
<li><var>|s| = N</var></li>
<li><var>s_i</var> and <var>t_i</var> are uppercase English letters.</li>
<li><var>d_i</var> is <code>L</code> or <code>R</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>Q</var>
<var>s</var>
<var>t_1</var> <var>d_1</var>
<var>\vdots</var>
<var>t_{Q}</var> <var>d_Q</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 4
ABC
A L
B L
B R
A R
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<ul>
<li>Initially, there is one golem on each square.</li>
<li>In the first spell, the golem on Square <var>1</var> tries to move left and disappears.</li>
<li>In the second spell, the golem on Square <var>2</var> moves left.</li>
<li>In the third spell, no golem moves.</li>
<li>In the fourth spell, the golem on Square <var>1</var> moves right.</li>
<li>After the four spells are cast, there is one golem on Square <var>2</var> and one golem on Square <var>3</var>, for a total of two golems remaining.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 3
AABCBDBA
A L
B R
A R
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<ul>
<li>After the three spells are cast, there is one golem on Square <var>2</var>, two golems on Square <var>4</var> and two golems on Square <var>6</var>, for a total of five golems remaining.</li>
<li>Note that a single spell may move multiple golems.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 15
SNCZWRCEWB
B R
R R
E R
W R
Z L
S R
Q L
W L
B R
C L
A L
N L
E R
Z L
S L
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p01546 |
<h1>Sports Days 2.0</h1>
<p>
äŒæŽ¥å€§åŠéå±å°åŠæ ¡ïŒäŒæŽ¥å€§å°ïŒã¯æ¥æ¬ææ°ã®ç«¶æããã°ã©ããŒé€ææ ¡ãšããŠæåã§ããã
ãã¡ãããéåäŒã«åå ããŠãããšãã§ããã¢ã«ãŽãªãºã ã®ä¿®è¡ãæ¬ ãããªãã
ç«¶æããã°ã©ãã³ã°éšéšé·ã®ããªãã¯ãã¡ãããã®å€§äŒã§ãåå©ãããã
ä»åã¯ããç«¶æã«æ³šç®ããã
</p>
<p>
ããç«¶æãšã¯äŒæŽ¥å€§å°ã§è¡ãããŠããäŒçµ±çãªç«¶æã ã
æ ¡åºã«ã³ãŒã³ã<var>V</var>å眮ããŠããã
ã³ãŒã³ã®ããã€ãã®ãã¢ã¯çœç·ã§æãããç¢å°ã§çµã°ããŠããã
ç¢å°ã®å
ã¯çåŽã ãã«ã€ããŠãããæŽæ°ã䜵èšãããŠããã
åãã³ãŒã³ã®ãã¢ãã®è€æ°ã®ç¢å°ã«çµã°ããŠããå Žåãããã
</p>
<p>
ç«¶æè
ã¯ä»»æã«ã³ãŒã³ãéžã³ãç§»åéå§ããã
ç§»åã¯ç«¶æè
ãããã³ãŒã³ããç¢å°ã®äžããã®åãã«ç§»åããæ¬¡ã®ã³ãŒã³ãžç§»ãã
åãã³ãŒã³ãåãç¢å°ãäœåºŠã蟿ã£ãŠãè¯ãã
ç«¶æè
ã¯ã³ãŒã³ããã³ãŒã³ãžã®ç§»ååŸãããã«ç§»åãããç§»åãçµäºãããããéžæããããšãã§ããã
</p>
<p>
ãã®ç«¶æã®ç®çã¯ç¢å°ã蟿ãããšã«ãããã¹ã³ã¢ãK以äžã«ããããšã§ããã
ã¹ã³ã¢ã¯ç¢å°ã蟿ã床ã«äœµèšãããæŽæ°å€ãå ç®ãããŠããã
ããå°ãªãçµç±ããç¢å°ã®æ¬æ°ã§ã¹ã³ã¢ã<var>K</var>以äžã«ããç«¶æè
ãåå©ãšãªãã
ç¢å°ãåãæ¬æ°ã®å Žåã¯ããé«ãã¹ã³ã¢ã®ç«¶æè
ãåå©ãšãªãã
</p>
<p>
ãã®ã«ãŒã«ã§æé©ãªåããç«¶æè
ãè¡ã£ãå Žåãäœæ¬ã®ç¢å°ãçµç±ãã¹ããåºåããã
ãŸããçµç±ããç¢å°ã®æ°ã100æ¬ä»¥äžã®å Žåãçµç±ãã¹ãã³ãŒã³ãé ã«ãã¹ãŠåºåããã
æé©ãªåããè€æ°ååšããå Žåãããããã©ã®åãã®çµæãåºåããŠãè¯ãã
ã¹ã³ã¢ã<var>K</var>以äžã«ããåããååšããªãå Žåã¯-1ãåºåããã
</p>
<p>
ãŸããã³ãŒã³ã«ã¯ãã¹ãŠ0ãã<var>V-1</var>ãŸã§ã®çªå·ãæ¯ãããŠããã
è²ã¯ãã¹ãŠç·è²ïŒæå³æ·±ïŒã§ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã<br>
</p>
<blockquote>
<var>V</var> <var>E</var> <var>K</var><br>
<var>v<sub>11</sub></var> <var>v<sub>12</sub></var> <var>c<sub>1</sub></var><br>...<br><var>v<sub>i1</sub></var> <var>v<sub>i2</sub></var> <var>c<sub>i</sub></var><br>...<br><var>v<sub>E1</sub></var> <var>v<sub>E2</sub></var> <var>c<sub>E</sub></var><br></blockquote>
<p>
ããã§ã<br>
</p>
<ul>
<li><var>V</var>ã¯ã³ãŒã³ã®æ°</li>
<li><var>E</var>ã¯ç¢å°ã®æ°
</li><li><var>v<sub>i,1</sub></var>ã¯ç¢å°<var>i</var>ã®å§ç¹ã®ã³ãŒã³çªå·
</li><li><var>v<sub>i2</sub></var>ã¯ç¢å°<var>i</var>ã®çµç¹ã®ã³ãŒã³çªå·
</li><li><var>c<sub>i</sub></var>ã¯ç¢å°ã«äœµèšãããŠããæŽæ°
</li></ul>
<p>
ã§ããã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li>å
¥åã¯ãã¹ãп޿°
</li>
<li><var>2≤V≤150</var>
</li>
<li><var>0≤E≤V×V</var>
</li>
<li><var>0<K≤10<sup>6</sup></var>
</li>
<li><var>0≤ v<sub>i1</sub>, v<sub>i2</sub> < V (0<i≤E)</var>
</li>
<li><var>v<sub>i1</sub> ≠ v<sub>i2</sub> (0<i≤E)</var>
</li>
<li><var>0<c<sub>i</sub> ≤ 100 (0<i≤E)</var>
</li><li><var>v<sub>i1</sub> = v<sub>j1</sub> </var>ã〠<var>v<sub>i2</sub> = v<sub>j2</sub> (i ≠ j, 0<i,j≤E)</var>ãšãªããããª<var>i, j</var>ãå«ãŸããå
¥åãååšããã
</li></ul>
<h2>Output</h2>
<p>
åºåã¯2è¡ãããªãã
</p>
<ul>
<li>1è¡ç®ãæé©ãªåããè¡ã£ãå Žåã®çµç±ããç¢å°ã®æ¬æ°ã§åºå
</li><li>2è¡ç®ãçµç±ãã¹ãã³ãŒã³ã®çªå·ãçµç±ããé çªã«ç©ºçœåºåãã§åºå
</li></ul>
<p>
æé©ãªåããè€æ°ååšããå Žåãããããã©ã®åãã®çµæãåºåããŠãè¯ãã
çµç±ãã¹ãç¢å°ã®æ¬æ°ã100æ¬ãè¶ããå Žåã2è¡ç®ã¯åºåããŠã¯ãããªãã
ã¹ã³ã¢ã<var>K</var>以äžã«ããæé©ãªåããååšããªãå Žåã¯-1ã1è¡ç®ã«åºåãã
2è¡ç®ã«äœãåºåããŠã¯ãããªãã
</p>
<H2>Sample Input 1</H2>
<pre>3 9 89
2 0 2
1 0 3
2 0 1
2 0 3
0 1 1
0 1 2
1 2 3
0 1 1
1 0 2
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>34
1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 0
</pre>
<H2>Sample Input 2</H2>
<pre>2 0 1
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>-1
</pre>
<H2>Sample Input 3</H2>
<pre>7 8 4000
0 1 1
1 0 1
1 2 2
2 3 2
3 4 2
5 4 3
3 5 4
5 6 5
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>3991
</pre> |
p01116 | <h3>For Programming Excellence</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
A countless number of skills are required to be an excellent programmer.
Different skills have different importance degrees,
and the total programming competence is measured by
the sum of products of levels and importance degrees of his/her skills.
</p>
<p>
In this summer season,
you are planning to attend a summer programming school.
The school offers courses for many of such skills.
Attending a course for a skill,
your level of the skill will be improved in proportion to the tuition paid,
one level per one yen of tuition, however,
each skill has its upper limit of the level
and spending more money will never improve the skill level further.
Skills are not independent: For taking a course for a skill,
except for the most basic course,
you have to have at least a certain level of its prerequisite skill.
</p>
<p>
You want to realize the highest possible programming competence measure
within your limited budget for tuition fees.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of no more than 100 datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<p>
<i>n</i> <i>k</i><br>
<i>h</i><sub>1</sub> ... <i>h<sub>n</sub></i> <br>
<i>s</i><sub>1</sub> ... <i>s<sub>n</sub></i> <br>
<i>p</i><sub>2</sub> ... <i>p<sub>n</sub></i> <br>
<i>l</i><sub>2</sub> ... <i>l<sub>n</sub></i> <br>
</p>
</blockquote>
<!-- begin en only -->
<ul>
<li>
The first line has two integers,
<i>n</i>, the number of different skills between 2 and 100, inclusive, and
<i>k</i>, the budget amount available between 1 and 10<sup>5</sup>, inclusive.
In what follows, skills are numbered 1 through <i>n</i>.
</li>
<li>
The second line has <i>n</i> integers
<i>h</i><sub>1</sub>...<i>h<sub>n</sub></i>,
in which <i>h<sub>i</sub></i> is the maximum level of the skill <i>i</i>,
between 1 and 10<sup>5</sup>, inclusive.
</li>
<li>
The third line has <i>n</i> integers
<i>s</i><sub>1</sub>...<i>s<sub>n</sub></i>,
in which <i>s<sub>i</sub></i> is the importance degree of the skill <i>i</i>,
between 1 and 10<sup>9</sup>, inclusive.
</li>
<li>
The fourth line has <i>n</i>−1 integers
<i>p</i><sub>2</sub>...<i>p<sub>n</sub></i>,
in which <i>p<sub>i</sub></i> is the prerequisite skill of the skill <i>i</i>,
between 1 and <i>i</i>−1, inclusive.
The skill 1 has no prerequisites.
</li>
<li>
The fifth line has <i>n</i>−1 integers
<i>l</i><sub>2</sub>...<i>l<sub>n</sub></i>,
in which <i>l<sub>i</sub></i> is the least level of prerequisite skill
<i>p<sub>i</sub></i> required to learn the skill <i>i</i>,
between 1 and <i>h<sub>p<sub>i</sub></sub></i> , inclusive.
</li>
</ul>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single line containing one integer,
which is the highest programming competence measure achievable,
that is,
the maximum sum of the products of
levels and importance degrees of the skills,
within the given tuition budget,
starting with level zero for all the skills.
You do not have to use up all the budget.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>3 10
5 4 3
1 2 3
1 2
5 2
5 40
10 10 10 10 8
1 2 3 4 5
1 1 2 3
10 10 10 10
5 10
2 2 2 5 2
2 2 2 5 2
1 1 2 2
2 1 2 1
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>18
108
35
</pre>
|
p02690 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Give a pair of integers <var>(A, B)</var> such that <var>A^5-B^5 = X</var>.
It is guaranteed that there exists such a pair for the given integer <var>X</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X \leq 10^9</var></li>
<li><var>X</var> is an integer.</li>
<li>There exists a pair of integers <var>(A, B)</var> satisfying the condition in Problem Statement.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>A</var> and <var>B</var>, with space in between.
If there are multiple pairs of integers <var>(A, B)</var> satisfying the condition, you may print any of them.</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>33
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 -1
</pre>
<p>For <var>A=2</var> and <var>B=-1</var>, <var>A^5-B^5 = 33</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 -1
</pre></section>
</div>
</span> |
p03982 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part"><section>
<h3>Problem Statement</h3>
<p>
Kyoto University decided to build a straight wall on the west side of the university to protect against gorillas that attack the university from the west every night.
Since it is difficult to protect the university at some points along the wall where gorillas attack violently, reinforcement materials are also built at those points.
Although the number of the materials is limited, the state-of-the-art technology can make a prediction about the points where gorillas will attack next and the number of gorillas that will attack at each point.
The materials are moved along the wall everyday according to the prediction.
You, a smart student majoring in computer science, are called to find the way to move the materials more efficiently.
</p>
<p>
Theare are <var>N</var> points where reinforcement materials can be build along the straight wall. They are numbered <var>1</var> through <var>N</var>.
Because of the protection against the last attack of gorillas, <var>A_i</var> materials are build at point <var>i</var> (<var>1 \leq i \leq N</var>).
For the next attack, the materials need to be rearranged such that at least <var>B_i</var> materials are built at point <var>i</var> (<var>1 \leq i \leq N</var>).
It costs <var>|i - j|</var> to move <var>1</var> material from point <var>i</var> to point <var>j</var>.
Find the minimum total cost required to satisfy the condition by moving materials.
You do not need to consider the attack after the next.
</p>
</section></div>
<div class="part"><section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>A_i \geq 1</var></li>
<li><var>B_i \geq 1</var></li>
<li><var>A_1 + A_2 + ... + A_N \leq 10^{12}</var></li>
<li><var>B_1 + B_2 + ... + B_N \leq A_1 + A_2 + ... + A_N</var></li>
<li>There is at least one way to satisfy the condition. </li>
</ul>
</section></div>
<hr/>
<div class="io-style">
<div class="part"><section>
<h3>Input</h3>
<p>The input is given from Standard Input in the following format: </p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
<var>B_1</var> <var>B_2</var> ... <var>B_N</var></pre>
</section></div>
<div class="part"><section>
<h3>Output</h3>
<p>Print the minimum total cost required to satisfy the condition. </p>
<h3>Partial Scores</h3>
<p>
<var>30</var> points will be awarded for passing the test set satisfying the following:
<ul>
<li><var>N \leq 100</var></li>
<li><var>A_1 + A_2 + ... + A_N \leq 400</var></li>
</ul>
</p>
<p>
Another <var>30</var> points will be awarded for passing the test set satisfying the following:
<ul>
<li><var>N \leq 10^3</var></li>
</ul>
</p>
<p>
Another <var>140</var> points will be awarded for passing the test set without addtional constraints and you can get <var>200</var> points in total.
</p>
</section></div>
</div>
<hr/>
<div class="part"><section>
<h3>Sample Input 1</h3>
<pre>2
1 5
3 1</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>2</pre>
<p>It costs least to move <var>2</var> materials from point <var>2</var> to point <var>1</var>. </p>
</section></div>
<div class="part"><section>
<h3>Sample Input 2</h3>
<pre>5
1 2 3 4 5
3 3 1 1 1</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>6</pre>
</section></div>
<div class="part"><section>
<h3>Sample Input 3</h3>
<pre>27
46 3 4 2 10 2 5 2 6 7 20 13 9 49 3 8 4 3 19 9 3 5 4 13 9 5 7
10 2 5 6 2 6 3 2 2 5 3 11 13 2 2 7 7 3 9 5 13 4 17 2 2 2 4</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3>
<pre>48</pre>
<p>The input of this test case satisfies both the first and second additional constraints. </p>
</section></div>
<div class="part"><section>
<h3>Sample Input 4</h3>
<pre>18
3878348 423911 8031742 1035156 24256 10344593 19379 3867285 4481365 1475384 1959412 1383457 164869 4633165 6674637 9732852 10459147 2810788
1236501 770807 4003004 131688 1965412 266841 3980782 565060 816313 192940 541896 250801 217586 3806049 1220252 1161079 31168 2008961</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3>
<pre>6302172</pre>
<p>The input of this test case satisfies the second additional constraint. </p>
</section></div>
<div class="part"><section>
<h3>Sample Input 5</h3>
<pre>2
1 99999999999
1234567891 1</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3>
<pre>1234567890</pre>
<p>The input and output values may exceed the range of 32-bit integer. </p>
</section></div>
</span> |
p00357 | <H1>Trampoline</H1>
<p>
A plurality of trampolines are arranged in a line at 10 m intervals. Each trampoline has its own maximum horizontal distance within which the jumper can jump safely. Starting from the left-most trampoline, the jumper jumps to another trampoline within the allowed jumping range. The jumper wants to repeat jumping until he/she reaches the right-most trampoline, and then tries to return to the left-most trampoline only through jumping. Can the jumper complete the roundtrip without a single stepping-down from a trampoline?
</p>
<p>
Write a program to report if the jumper can complete the journey using the list of maximum horizontal reaches of these trampolines. Assume that the trampolines are points without spatial extent.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var>
<var>d_1</var>
<var>d_2</var>
:
<var>d_N</var>
</pre>
<p>
The first line provides the number of trampolines <var>N</var> (2 ≤ <var>N</var> ≤ 3 × 10<sup>5</sup>). Each of the subsequent <var>N</var> lines gives the maximum allowable jumping distance in integer meters for the <var>i</var>-th trampoline <var>d_i</var> (1 ≤ <var>d_i</var> ≤ 10<sup>6</sup>).
</p>
<h2>Output</h2>
<p>
Output "<span>yes</span>" if the jumper can complete the roundtrip, or "<span>no</span>" if he/she cannot.
</p>
<h2>Sample Input 1</h2>
<pre>
4
20
5
10
1
</pre>
<h2>Sample Output 1</h2>
<pre>
no
</pre>
<h2>Sample Input 2</h2>
<pre>
3
10
5
10
</pre>
<h2>Sample Output 2</h2>
<pre>
no
</pre>
<h2>Sample Input 3</h2>
<pre>
4
20
30
1
20
</pre>
<h2>Sample Output 3</h2>
<pre>
yes
</pre>
|
p00707 |
<H1>The Secret Number</H1>
<P>
Your job is to find out the secret number hidden in a matrix,
each of whose element is a digit ('0'-'9') or a letter
('A'-'Z'). You can see an example matrix in Figure 1.
</P>
<CENTER>
<DIV style="margin-bottom: 5mm"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_secret1"></DIV>
Figure 1: A Matrix
</CENTER>
<P>
The secret number and other non-secret ones are coded in a
matrix as sequences of digits in a decimal format. You should
only consider sequences of digits <I>D</I><SUB>1</SUB>
<I>D</I><SUB>2</SUB> ... <I>D</I><SUB><I>n</I></SUB> such that
<I>D</I><SUB><I>k</I>+1</SUB> (1 <= <I>k</I> < <I>n</I>)
is either right next to or immediately below
<I>D</I><SUB><I>k</I></SUB> in the matrix. The secret you are
seeking is the largest number coded in this manner.
</P>
<P>
Four coded numbers in the matrix in Figure 1, i.e., 908820,
23140037, 23900037, and 9930, are depicted in Figure 2. As you
may see, in general, two or more coded numbers may share a
common subsequence. In this case, the secret number is
23900037, which is the largest among the set of all coded numbers
in the matrix.
</P>
<CENTER>
<DIV style="margin-bottom: 5mm"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_secret2"></DIV>
Figure 2: Coded Numbers
</CENTER>
<P>
In contrast, the sequences illustrated in Figure 3 should be
excluded: 908A2 includes a letter; the fifth digit of 23149930
is above the fourth; the third digit of 90037 is below right of
the second.
</P>
<CENTER>
<DIV style="margin-bottom: 5mm"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_secret3" ></DIV>
Figure 3: Inappropriate Sequences
</CENTER>
<P>
Write a program to figure out the secret number from a given
matrix.
</P>
<H2>Input</H2>
<P>
The input consists of multiple data sets, each data set
representing a matrix. The format of each data set is as
follows.
</P>
<BLOCKQUOTE>
<I>W</I> <I>H</I><BR>
<I>C</I><SUB>11</SUB><I>C</I><SUB>12</SUB> ... <I>C</I><SUB>1<I>W</I></SUB><BR>
<I>C</I><SUB>21</SUB><I>C</I><SUB>22</SUB> ... <I>C</I><SUB>2<I>W</I></SUB><BR>
...<BR>
<I>C</I><SUB><I>H</I>1</SUB><I>C</I><SUB><I>H</I>2</SUB> ... <I>C</I><SUB><I>HW</I></SUB><BR>
</BLOCKQUOTE>
<P>
In the first line of a data set, two positive integers <I>W</I>
and <I>H</I> are given. <I>W</I> indicates the width (the
number of columns) of the matrix, and <I>H</I> indicates the
height (the number of rows) of the matrix. <I>W+H</I> is less
than or equal to 70.
</P>
<P>
<I>H</I> lines follow the first line, each of which corresponds
to a row of the matrix in top to bottom order. The <I>i</I>-th
row consists of <I>W</I> characters
<I>C</I><SUB><I>i</I>1</SUB><I>C</I><SUB><I>i</I>2</SUB>
... <I>C</I><SUB><I>iW</I></SUB> in left to right order. You may
assume that the matrix includes at least one non-zero digit.
</P>
<P>
Following the last data set, two zeros in a line indicate the
end of the input.
</P>
<H2>Output</H2>
<P>
For each data set, print the secret number on a line. Leading zeros
should be suppressed.
</P>
<H2>Sample Input</H2>
<PRE>
7 4
9R2A993
0E314A0
8A900DE
820R037
6 7
JH03HE
ID7722
0DA1AH
30C9G5
99971A
CA7EAI
AHLBEM
20 2
A1234567891234CBDEGH
BDEDF908034265091499
0 0
</PRE>
<H2>Output for the Sample Input</H2>
<PRE>
23900037
771971
12345908034265091499
</PRE>
|
p01815 |
<h2>Escape</h2>
<p>
é ç¹ã«æ£ã®å€ãæã€ç¡åã°ã©ããäžããããã
é ç¹ã«ã¯ 1 ãã <var>N</var> ã®çªå·ãã€ããŠããã<var>i</var> çªç®ã®é ç¹ã¯ <var>w_i</var> ã®å€ãæã£ãŠããã
1 çªç®ã®é ç¹ããã¹ã¿ãŒãããçŽåã«éã£ã蟺ãéãããšãã§ããªããšããå¶çŽã®ããšã§ã°ã©ãäžãç§»åããããšãã§ããã
åé ç¹ã§ã¯ïŒåããŠèšªããæã«éããã®é ç¹ãæã€å€ã®ç¹æ°ãåŸãããã
</p>
<p>
ååŸã§ããç¹æ°ã®ç·åã®æå€§å€ãæ±ããã
</p>
<h3>Constraints</h3>
<ul>
<li><var>1 ≤ N ≤ 100000</var></li>
<li><var>N − 1 ≤ M ≤ 100000</var></li>
<li><var>1 ≤ w_i ≤ 1000</var></li>
<li><var>1 ≤ u_i, v_i ≤ N</var></li>
<li>å€é蟺ã»èªå·±èŸºã¯ååšããªã</li>
<li>ã°ã©ãã¯é£çµã§ãã</li>
</ul>
<h3>Input Format</h3>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>w_1</var> <var>w_2</var> ... <var>w_N</var>
<var>u_1</var> <var>v_1</var>
<var>u_2</var> <var>v_2</var>
...
<var>u_M</var> <var>v_M</var>
</pre>
<p>
<var>1</var> è¡ç®ã«ã¯<b>ã°ã©ã</b>ã®é ç¹æ° <var>N</var> ãšèŸºã®æ°ãè¡šãæŽæ° <var>M</var> ãå
¥åãããã <br />
<var>2</var> è¡ç®ã«ã¯åé ç¹ãæã€å€ <var>w_i</var> ãå
¥åãããã <br />
ããã«ç¶ã㊠<var>M</var> è¡ã«ãå蟺ã«ããç¹ããã <var>2</var> é ç¹ã®çªå·ãå
¥åãããã<br />
</p>
<h3>Output Format</h3>
<p>
çãã1è¡ã«åºåããã
</p>
<h3>Sample Input 1</h3>
<pre>
6 6
1 2 3 4 5 6
1 2
2 3
3 4
1 4
4 5
5 6
</pre>
<h3>Sample Output 1</h3>
<pre>
21
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_g_sample1-1" width=150 height=190/> <br/>
é ç¹ 1â2â3â4â5â6 ãšé²ãããšã§å
šãŠã®é ç¹ã®ç¹æ°ãéããããšãã§ããŸãã
</p>
<h3>Sample Input 2</h3>
<pre>
7 8
1 3 3 5 2 2 3
1 2
2 3
3 1
1 4
1 7
1 5
1 6
5 6
</pre>
<h3>Sample Output 2</h3>
<pre>
16
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_g_sample2" width=240 height=185/> <br/>
é ç¹ 1â2â3â1â5â6â1â4 ãšé²ãããšã§16ç¹ãéããããšãã§ããŸãã
</p>
|
p03828 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>.
Find the number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€Nâ€10^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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four divisors of <var>3!</var> <var>=6</var>: <var>1</var>, <var>2</var>, <var>3</var> and <var>6</var>. Thus, the output should be <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>30
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>972926972
</pre></section>
</div>
</span> |
p00212 |
<H1> é«éãã¹</H1>
<p>
A åã¯é«æ ¡ã®äŒã¿ãå©çšããŠãé«éãã¹(以äžãããã¹ã )ã§äžäººæ
ãããèšç»ãç«ãŠãŠããŸãããŸããA åã¯äžçªè¡ã£ãŠã¿ããçºãéžãã§ãããç®çå°ã«ããŸãããæ¬¡ã«åºçºå°ããç®çå°ãŸã§ãã¹ãä¹ãç¶ãã§ããã«ãŒããæ±ºããªããã°ãªããŸãããä¹ãç¶ãããããšãã¯ããã¹ãéããŠããå¥ã®ãã¹ã«ä¹ãæããã®ã§ãããããã®ãã¹ã®ä¹è»åžãå¿
èŠã«ãªããŸãã
</p>
<p>
A åã¯èŠªæã®ãããããããã¹ã®å²åŒåžãäœæãããããŸããã ãã®åžã 1 æäœ¿ããšä¹è»åž 1 æãåé¡ã§è³Œå
¥ã§ããŸããäŸãã°ãå³ 1 ã®åºçºå°5ããç®çå°1ãžè¡ãå Žåã«ã¯ã5â4â6â2â1ãš5â3â1ã®äºã€ã®çµè·¯ãèããããŸããå²åŒåžã 2 æãããšãããšã亀éè²»ãæãå®ãããã«ã¯5â4â6â2â1ã®çµè·¯ããã©ã£ãå Žåã4â6ãš6â2ã®è·¯ç·ã«å²åŒãå©çšããåèšæé㯠4600åãšãªããŸããäžæ¹ã5â3â1ã®çµè·¯ããã©ã£ãå Žåã5â3ãš3â1ã®è·¯ç·ã«å²åŒãå©çšããåèšæé㯠3750 åãšãªããŸãã
</p>
<p>
A åã¯èгå
ã«ãéãåãããã®ã§ã亀éè²»ã¯ã§ããã ãå°ãªãããããšèããŠããŸããããã§ A åã¯ãåºçºå°ããç®çå°ãŸã§ã®æãå®ã亀éè²»ãæ±ããããã°ã©ã ãäœæããããšã«ããŸããã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_highwayBus">
<p>
å³1
</p>
</center>
<p>
å²åŒåžã®ææ°ããã¹ãã€ãªãçºã®æ°ããã¹ã®è·¯ç·æ°ãåãã¹ã®è·¯ç·æ
å ±ãå
¥åãšããåºçºå°ããç®çå°ãŸã§ã®æãå®ã亀éè²»ãåºåããããã°ã©ã ãäœæããŠãã ãããåãã¹ã¯åæ¹åã«åäžæéã§éè¡ããŠããŸãããŸããçºã®æ°ã <var>n</var> ãšãããšãçºã«ã¯ããããç°ãªã 1 ãã <var>n</var> ãŸã§ã®çªå·ãæ¯ãããŠããŸããåºçºå°ããç®çå°ãŸã§ã®çµè·¯ã¯å¿
ãååšãããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒããïŒã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>c</var> <var>n</var> <var>m</var> <var>s</var> <var>d</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>f<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>f<sub>2</sub></var>
:
<var>a<sub>m</sub></var> <var>b<sub>m</sub></var> <var>f<sub>m</sub></var>
</pre>
<p>
1 è¡ç®ã«å²åŒåžã®ææ° <var>c</var> (1 ≤ <var>c</var> ≤ 10)ããã¹ãã€ãªãçºã®æ° <var>n</var> (2 ≤ <var>n</var> ≤ 100)ããã¹ã®è·¯ç·æ° <var>m</var> (1 ≤ <var>m</var> ≤ 500)ãåºçºå°ã®çºçªå· <var>s</var> ãšç®çå°ã®çºçªå· <var>d</var> (<var>s ≠ d</var>) ãäžããããŸãã
</p>
<p>
ç¶ã <var>m</var> è¡ã«ç¬¬ <var>i</var> ã®ãã¹ã®è·¯ç·æ
å ± <var>a<sub>i</sub>, b<sub>i</sub>, f<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub>, b<sub>i</sub></var> ≤ <var>n</var>, 1000 ≤ <var>f<sub>i</sub></var> ≤ 10000) ãäžããããŸãã<var>a<sub>i</sub>, b<sub>i</sub></var> ã¯ãã¹ã®è·¯ç·ã®å§ç¹ãšçµç¹ã®çºçªå·ã<var>f<sub>i</sub></var> ã¯ãã®è·¯ç·ã®æéã衚ã100 å»ã¿ã®æŽæ°ã§ãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãæãå®ã亀éè²»ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
1 3 3 1 3
1 3 2000
1 2 1000
2 3 1000
2 3 3 1 3
1 3 2300
1 2 1000
2 3 1200
2 6 6 5 1
1 2 1500
1 3 4500
2 6 2000
5 4 1000
6 4 2200
3 5 3000
0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1000
1100
3750
</pre>
|
p00642 |
<H1><font color="#000000">Problem F:</font> Ben Toh</H1>
<p>
As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes.
</p>
<p>
A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job.
</p>
<p>
Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%.
</p>
<p>
He continue to go to supermaket and try to get the discounted box lunch for <i>n</i> days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets.
</p>
<p>
Input for a single dataset is given as a single integer <i>n</i>.
</p>
<p>
Input terminates with a dataset where <i>n</i> = 0.
</p>
<H2>Output</H2>
<p>
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 100,000</li>
</ul>
<H2>Sample Input</H2>
<pre>
1
2
3
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1.00000000
1.50000000
2.12500000
</pre>
|
p01950 |
<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>
Endless BFS
</H1>
<p>
Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows:
</p>
<pre>
1: $current \leftarrow \{start\_vertex\}$
2: $visited \leftarrow current$
3: while $visited \ne $ the set of all the vertices
4: $found \leftarrow \{\}$
5: for $v$ in $current$
6: for each $u$ adjacent to $v$
7: $found \leftarrow found \cup\{u\}$
8: $current \leftarrow found \setminus visited$
9: $visited \leftarrow visited \cup found$
</pre>
<p>
However, Mr. Endo apparently forgot to manage visited vertices in his code. More precisely, he wrote the following
code:
</p>
<pre>
1: $current \leftarrow \{start\_vertex\}$
2: while $current \ne $ the set of all the vertices
3: $found \leftarrow \{\}$
4: for $v$ in $current$
5: for each $u$ adjacent to $v$
6: $found \leftarrow found \cup \{u\}$
7: $current \leftarrow found$
</pre>
<p>
You may notice that for some graphs, Mr. Endo's program will not stop because it keeps running infinitely. Notice that it does not necessarily mean the program cannot explore all the vertices within finite steps. See example 2 below for more details.Your task here is to make a program that determines whether Mr. Endo's program will stop within finite steps for a given graph in order to point out the bug to him. Also, calculate the minimum number of loop iterations required for the program to stop if it is finite.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$ $M$
$U_1$ $V_1$
...
$U_M$ $V_M$
</pre>
<p>
The first line consists of two integers $N$ ($2 \leq N \leq 100,000$) and $M$ ($1 \leq M \leq 100,000$), where $N$ is the number of vertices and $M$ is the number of edges in a given undirected graph, respectively. The $i$-th line of the following $M$ lines consists of two integers $U_i$ and $V_i$ ($1 \leq U_i, V_i \leq N$), which means the vertices $U_i$ and $V_i$ are adjacent in the given graph. The vertex 1 is the start vertex, i.e. $start\_vertex$ in the pseudo codes. You can assume that the given graph also meets the following conditions.
</p>
<ul>
<li>The graph has no self-loop, i.e., $U_i \ne V_i$ for all $1 \leq i \leq M$.</li>
<li>The graph has no multi-edge, i.e., $\{Ui,Vi\} \ne \{U_j,V_j\}$ for all $1 \leq i < j \leq M$.</li>
<li>The graph is connected, i.e., there is at least one path from $U$ to $V$ (and vice versa) for all vertices $1 \leq U, V \leq N$</li>
</ul>
<H2>Output</H2>
<p>
If Mr. Endo's wrong BFS code cannot stop within finite steps for the given input graph, print -1 in a line. Otherwise, print the minimum number of loop iterations required to stop.
</p>
<H2>Sample Input 1</H2>
<pre>
3 3
1 2
1 3
2 3
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
2
</pre>
<H2>Sample Input 2</H2>
<pre>
4 3
1 2
2 3
3 4
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
-1
</pre>
<p>
Transition of $current$ is $\{1\} \rightarrow \{2\} \rightarrow \{1,3\} \rightarrow \{2,4\} \rightarrow \{1,3\} \rightarrow \{2,4\} \rightarrow ... $. Although Mr. Endo's program will achieve to visit all the vertices (in 3 steps), will never become the same set as all the vertices.
</p>
<H2>Sample Input 3</H2>
<pre>
4 4
1 2
2 3
3 4
4 1
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
-1
</pre>
<H2>Sample Input 4</H2>
<pre>
8 9
2 1
3 5
1 6
2 5
3 1
8 4
2 7
7 1
7 4
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
3
</pre>
|
p02385 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Dice III</h1><br>
<p>
Write a program which reads the two dices constructed in the same way as <a href="description.jsp?id=ITP1_11_A">Dice I</a>, and determines whether these two dices are identical. You can roll a dice in the same way as <a href="description.jsp?id=ITP1_11_A">Dice I</a>, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical.
</p>
<h2>Input</h2>
<p>
In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels.<br>
In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels.
</p>
<h2>Output</h2>
<p>
Print "<sapn>Yes</span>" if two dices are identical, otherwise "<span>No</span>" in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$0 \leq $ the integer assigned to a face $ \leq 100$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
1 2 3 4 5 6
6 2 4 3 5 1
</pre>
<h2>Sample Output 1</h2>
<pre>
Yes
</pre>
<br>
<h2>Sample Input 2</h2>
<pre>
1 2 3 4 5 6
6 5 4 3 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
No
</pre> |
p01403 |
<h2>
Problem F: Farey Sequence
</h2>
<p>
slipã¯æ°åãçºããã®ã奜ãã§ããã
ãã¡ã€ã«ãããŠã³ããŒãããŠãããšãã®ãæ®ãæéãçºããŠããã ãã§ãæéãæœ°ããã»ã©ã§ããã
ãããªslipãå人ããé¢çœãæ°åãæããããã
ãã®æ°åã®å®çŸ©ã¯ä»¥äžã®ãšããã§ããã
</p>
<p>
äžè¬é
ã<i>F<sub>n</sub></i>ãšè¡šããã
<i>F<sub>n</sub></i>ãšã¯ã<i>n</i>以äžã®åæ¯ãæã€0以äž1以äžã®ãã¹ãŠã®çŽåãããåæ°(æ¢çŽåæ°)ãå°ããªé ãã䞊ã¹ããã®ã§ããã
ãã ããæŽæ°0ã1ã¯ããããåæ°0/1ã1/1ãšããŠæ±ãããã
</p>
<p>
ã€ãŸã<i>F<sub>3</sub></i>ã¯ã
</p>
<pre>
<i>F<sub>3</sub></i> = (0/1, 1/3, 1/2, 2/3, 1/1)
</pre>
<p>
ã®ããã«è¡šãããã
</p>
<p>
<i>F<sub>5</sub></i>ã§ããã°
</p>
<pre>
<i>F<sub>5</sub></i> = (0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1)
</pre>
<p>
ãšè¡šãããã
</p>
<p>
slipã¯ãã®æ°åã«ããã«ã®ãã蟌ãã ã
ããããã®æ°åãçºããŠããŠãããªããªãç¹åŸŽãã€ãããªãã£ãã
ç¹åŸŽãã€ããããã«ãŸãã¯åé
ã®é
æ°ãããã€ããã®ã調ã¹ãããšæã£ããã
å¢ãæ¹ã®èŠåããããããèªåã§çè§£ããããšãæå¿µããã
</p>
<p>
ããã§ã
åæã«åäººãšæã£ãŠããããªãã«ãæå®ããé
ã«ã©ãã ãã®é
æ°ãããã®ããèãããšã«ããã
ããªãã®ä»äºã¯ãäžããããé
ã«ãããé
æ°ãæ±ããããšã§ããã
</p>
<h2>
Input
</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<i>t</i>
<i>n<sub>1</sub></i>
...
<i>n<sub>i</sub></i>
...
<i>n<sub>t</sub></i>
</pre>
<p>
<i>t</i>(<i>1 ≤ t ≤ 10000</i>)ã¯ãã¹ãã±ãŒã¹ã®æ°ã§ããã
<i>n<sub>i</sub></i>(<i>1 ≤ n<sub>i</sub> ≤ 1000000</i>)ã¯äžããããé
ã®çªå·ã§ããã
</p>
<h2>
Output
</h2>
<p>
åãã¹ãã±ãŒã¹ããšã«ãé
æ°ã1è¡ã«è¡šç€ºããã
</p>
<h2>
Sample Input
</h2>
<pre>
2
3
5
</pre>
<h2>
Output for Sample Input
</h2>
<pre>
5
11
</pre>
|
p01053 |
<h1>Lucky Number</h1>
<h2>Problem</h2>
<p>
0 ãã <var>N</var>-1 ãŸã§ã®æ°åããããŸãã <var>M</var>+1æ¥éã®ã©ãããŒãã³ããŒã以äžã®æ¹æ³ã§éžã³ãããšæããŸãã æåã®æ¥ã«ã©ãããŒãã³ããŒãã©ã³ãã ã«æ±ºããŸãã <var>i</var>æ¥åŸã®ã©ãããŒãã³ããŒã <var>A</var> ãïŒ<var>i</var>+1ïŒæ¥åŸã®ã©ãããŒãã³ããŒã <var>B</var> ãšãããšã
</p>
<pre>
<var>B</var> = ( <var>A</var> + <var>j</var> ) % <var>N</var>
ïŒãã ã <var>j</var> 㯠0 ≤ <var>j</var> < <var>N</var> ã〠ïŒ<var>j</var> / <var>K</var>ïŒ ãå¶æ°ãšãªãå
šãŠã®æŽæ°ã§ãã )
</pre>
<p>
ã§æ±ãããã<var>B</var>ã®ãã¡ã®ããããããã©ã³ãã ã«æ±ºããŸãããã ãã<var>a</var> / <var>b</var> ã®çµæã¯å°æ°ç¹ä»¥äžãåãæšãŠãæŽæ°ãšãã<var>a</var>%<var>b</var>ã¯<var>a</var>ã<var>b</var>ã§å²ã£ãäœããšããŸãã
ãŸã <var>K</var> 㯠<var>N</var> / <var>K</var> ãå²ãåããŠã<var>N</var> / <var>K</var> ãå¶æ°ãšãªãæ°åã§ããããšãä¿èšŒãããŸãã
<p>
äŸãã° 0,1,2,3 ãšæ°åãããã <var>K</var> = 1 ã®ãšã
</p>
<ul>
<li>0 ã®æ¬¡ã®ã©ãããŒãã³ããŒã¯ 0 or 2</li>
<li>1 ã®æ¬¡ã®ã©ãããŒãã³ããŒã¯ 1 or 3</li>
<li>2 ã®æ¬¡ã®ã©ãããŒãã³ããŒã¯ 0 or 2</li>
<li>3 ã®æ¬¡ã®ã©ãããŒãã³ããŒã¯ 1 or 3</li>
</ul>
<p>
ãšãªããŸãã
</p>
<p>
次ã«<var>Q</var>åã®è³ªåãäžããããŸãã å質åã®å
容ã¯ä»¥äžã®ãšããã§ãã
</p>
<p>
æåã®æ¥ã®ã©ãããŒãã³ããŒã <var>a</var> ã®ãšã <var>b</var> æ¥åŸã®ã©ãããŒãã³ããŒã <var>c</var> ã«ãªããã㪠<var>b</var> æ¥åŸãŸã§ã®ã©ãããŒãã³ããŒã®éžã³æ¹ã¯äœéãã§ããããïŒ
éžã³æ¹ã¯èšå€§ãªæ°ã«ãªããšæãããã®ã§ 1,000,000,007 ã§å²ã£ãäœããæ±ããŠãã ããã
</p>
<p>
äŸãã°ã<var>N</var>=4 <var>K</var>=1 ã§ãæåã®ã©ãããŒãã³ããŒã 0 ã§ã3 æ¥åŸã®ã©ãããŒãã³ããŒã 2 ã«ãªããããªçµã¿åããã¯
</p>
<ul>
<li>0 → 0 → 0 → 2</li>
<li>0 → 0 → 2 → 2</li>
<li>0 → 2 → 0 → 2</li>
<li>0 → 2 → 2 → 2</li>
</ul>
<p>
ã®ïŒéãã§ãã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var> <var>K</var> <var>Q</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var>
.
.
.
<var>a<sub>Q</sub></var> <var>b<sub>Q</sub></var> <var>c<sub>Q</sub></var>
</pre>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>N</var> ≤ 5000</li>
<li>1 ≤ <var>M</var> ≤ 5000</li>
<li>1 ≤ <var>K</var> ≤ 5000</li>
<li><var>N</var> / <var>K</var> ãå²ãåãã</li>
<li><var>N</var> / <var>K</var> ã¯å¶æ°</li>
<li>1 ≤ <var>Q</var> ≤ 100000</li>
<li>0 ≤ <var>a<sub>i</sub></var> < <var>N</var> ( 1 ≤ <var>i</var> ≤ <var>Q</var> )</li>
<li>0 ≤ <var>b<sub>i</sub></var> ≤ <var>M</var> ( 1 ≤ <var>i</var> ≤ <var>Q</var> )</li>
<li>0 ≤ <var>c<sub>i</sub></var> < <var>N</var> ( 1 ≤ <var>i</var> ≤ <var>Q</var> )</li>
</ul>
<h2>Output</h2>
<p>
å質åã«å¯Ÿããçããæ±ã 1,000,000,007 ã§å²ã£ãäœããäžè¡ãã€é çªã«åºåããŠãã ããã
</p>
<h2>Sample Input1</h2>
<pre>
6 3 1 10
0 1 0
0 2 0
0 3 0
1 3 3
0 2 1
2 2 2
2 3 2
2 2 0
1 1 1
2 2 1
</pre>
<h2>Sample Output1</h2>
<pre>
1
3
9
9
0
3
9
3
1
0
</pre>
|
p03594 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns of squares.
We will represent the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left as <var>(i,\ j)</var>.
Also, we will define the distance between the squares <var>(i_1,\ j_1)</var> and <var>(i_2,\ j_2)</var> as <var>|i_1 - i_2| + |j_1 - j_2|</var>.</p>
<p>Snuke is painting each square in red, yellow, green or blue.
Here, for a given positive integer <var>d</var>, he wants to satisfy the following condition:</p>
<ul>
<li>No two squares with distance exactly <var>d</var> have the same color.</li>
</ul>
<p>Find a way to paint the squares satisfying the condition.
It can be shown that a solution always exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †H, W †500</var></li>
<li><var>1 †d †H + W - 2</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>d</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a way to paint the squares satisfying the condition, in the following format. If the square <var>(i,\ j)</var> is painted in red, yellow, green or blue, <var>c_{ij}</var> should be <code>R</code>, <code>Y</code>, <code>G</code> or <code>B</code>, respectively.</p>
<pre><var>c_{11}</var><var>c_{12}</var><var>...</var><var>c_{1W}</var>
<var>:</var>
<var>c_{H1}</var><var>c_{H2}</var><var>...</var><var>c_{HW}</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>RY
GR
</pre>
<p>There are four pairs of squares with distance exactly <var>1</var>.
As shown below, no two such squares have the same color.</p>
<ul>
<li><var>(1,\ 1)</var>, <var>(1,\ 2)</var> : <code>R</code>, <code>Y</code></li>
<li><var>(1,\ 2)</var>, <var>(2,\ 2)</var> : <code>Y</code>, <code>R</code></li>
<li><var>(2,\ 2)</var>, <var>(2,\ 1)</var> : <code>R</code>, <code>G</code></li>
<li><var>(2,\ 1)</var>, <var>(1,\ 1)</var> : <code>G</code>, <code>R</code></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>RYB
RGB
</pre>
<p>There are six pairs of squares with distance exactly <var>2</var>.
As shown below, no two such squares have the same color.</p>
<ul>
<li><var>(1,\ 1)</var> , <var>(1,\ 3)</var> : <code>R</code> , <code>B</code></li>
<li><var>(1,\ 3)</var> , <var>(2,\ 2)</var> : <code>B</code> , <code>G</code></li>
<li><var>(2,\ 2)</var> , <var>(1,\ 1)</var> : <code>G</code> , <code>R</code></li>
<li><var>(2,\ 1)</var> , <var>(2,\ 3)</var> : <code>R</code> , <code>B</code></li>
<li><var>(2,\ 3)</var> , <var>(1,\ 2)</var> : <code>B</code> , <code>Y</code></li>
<li><var>(1,\ 2)</var> , <var>(2,\ 1)</var> : <code>Y</code> , <code>R</code></li>
</ul></section>
</div>
</span> |
p03701 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are taking a computer-based examination. The examination consists of <var>N</var> questions, and the score allocated to the <var>i</var>-th question is <var>s_i</var>. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.</p>
<p>However, the examination system is actually flawed, and if your grade is a multiple of <var>10</var>, the system displays <var>0</var> as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 †N †100</var></li>
<li><var>1 †s_i †100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s_1</var>
<var>s_2</var>
<var>:</var>
<var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum value that can be displayed as your grade.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
5
10
15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>25
</pre>
<p>Your grade will be <var>25</var> if the <var>10</var>-point and <var>15</var>-point questions are answered correctly and the <var>5</var>-point question is not, and this grade will be displayed correctly. Your grade will become <var>30</var> if the <var>5</var>-point question is also answered correctly, but this grade will be incorrectly displayed as <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
10
10
15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>35
</pre>
<p>Your grade will be <var>35</var> if all the questions are answered correctly, and this grade will be displayed correctly.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
10
20
30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>Regardless of whether each question is answered correctly or not, your grade will be a multiple of <var>10</var> and displayed as <var>0</var>.</p></section>
</div>
</span> |
p02813 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two permutations <var>P</var> and <var>Q</var> of size <var>N</var> (that is, <var>P</var> and <var>Q</var> are both rearrangements of <var>(1,~2,~...,~N)</var>).</p>
<p>There are <var>N!</var> possible permutations of size <var>N</var>. Among them, let <var>P</var> and <var>Q</var> be the <var>a</var>-th and <var>b</var>-th lexicographically smallest permutations, respectively. Find <var>|a - b|</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>For two sequences <var>X</var> and <var>Y</var>, <var>X</var> is said to be lexicographically smaller than <var>Y</var> if and only if there exists an integer <var>k</var> such that <var>X_i = Y_i~(1 \leq i < k)</var> and <var>X_k < Y_k</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 8</var></li>
<li><var>P</var> and <var>Q</var> are permutations of size <var>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>
<var>Q_1</var> <var>Q_2</var> <var>...</var> <var>Q_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>|a - b|</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 3 2
3 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There are <var>6</var> permutations of size <var>3</var>: <var>(1,~2,~3)</var>, <var>(1,~3,~2)</var>, <var>(2,~1,~3)</var>, <var>(2,~3,~1)</var>, <var>(3,~1,~2)</var>, and <var>(3,~2,~1)</var>. Among them, <var>(1,~3,~2)</var> and <var>(3,~1,~2)</var> come <var>2</var>-nd and <var>5</var>-th in lexicographical order, so the answer is <var>|2 - 5| = 3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>17517
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 2 3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01696 |
<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>
<!-- begin en only -->
<!--<h3><u>Broken Cipher Generator</u></h3>-->
<!-- end en only -->
<!-- begin ja only -->
<h3><u>å£ããæå·çæåš</u></h3>
<!-- end ja only -->
<!-- begin en only -->
<!-- end en only -->
<!-- begin ja only -->
<p>JAG (Japanese Alumni Group) ã¯å€ãã®ããã°ã©ãã§æ§æãããè¬ã®çµç¹ã§ããïŒãã®çµç¹ã®æ¬éšããã建ç©ã«å
¥ãããã«ã¯æ¯åããæ©æ¢°ã«ãã£ãŠçæãããæå·æãè§£ããªããŠã¯ãªããªãïŒ
ãã®æå·æã¯ïŒ'<samp>+</samp>'ïŒ'<samp>-</samp>'ïŒ'<samp>[</samp>'ïŒ'<samp>]</samp>' ã®èšå·ãšå€§æåã®ã¢ã«ãã¡ããããããªã£ãŠããïŒä»¥äžã® BNF ã§å®çŸ©ããã <Cipher> ã«ãã£ãŠè¡šãããïŒ
</p>
<pre><Cipher> ::= <String> | <Cipher><String>
<String> ::= <Letter> | '['<Cipher>']'
<Letter> ::= '+'<Letter> | '-'<Letter> |
'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' |
'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'</pre>
<p>ããã§ããããã®èšå·ã¯ä»¥äžã®ãããªæå³ã衚ãïŒ
</p><ul><li> +(æå) : ãã®æåã®æ¬¡ã®ã¢ã«ãã¡ãããã衚ã (ãã ã '<samp>Z</samp>' ã®æ¬¡ã®ã¢ã«ãã¡ããã㯠'<samp>A</samp>' ã§ãããšãã)
</li><li> -(æå) : ãã®æåã®åã®ã¢ã«ãã¡ãããã衚ã (ãã ã '<samp>A</samp>' ã®åã®ã¢ã«ãã¡ããã㯠'<samp>Z</samp>' ã§ãããšãã)
</li><li> [(æåå)] : ãã®æååãå·Šå³å転ããæååã衚ã
</li></ul>
<p>ããããã®æå·æãçæããæ©æ¢°ã«ã¯çŸåšæ
éãçºçããŠããïŒæå·æã®ãã¡ã¢ã«ãã¡ãããã®ç®æãæ°æåå£ããŠèªããªããªã£ãŠããå ŽåãããïŒèªããªãæåã¯ä»®ã« '<samp>?</samp>' ãšè¡šãããŠããïŒ
調æ»ã®çµæïŒå£ããæåã®åãæ¹ã¯ïŒåŸ©å·åŸã®æååãïŒåŸ©å·åŸã®æååãšããŠããããæååã®äžã§èŸæžé æå°ã«ãªããããªãã®ã§ããããšãããã£ãïŒ
ããªãã®ä»äºã¯ãã®æå·æãæ£ãã埩å·ããããšã§ããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒ
åããŒã¿ã»ããã¯ïŒäžèšã® BNF ã§å®çŸ©ãããæå·æã«ãããŠïŒäžéšã®å€§æåã®ã¢ã«ãã¡ãããã â?â ã«çœ®ãæããããæååãå«ã 1 è¡ãããªãïŒ
åæååã®é·ã㯠$80$ 以äžã§ãããšä»®å®ããŠããïŒ
ãŸãåããŒã¿ã»ããã«å«ãŸãã '<samp>?</samp>' ã®æ°ã¯ $0$ ä»¥äž $3$ 以äžã§ãããšä»®å®ããŠããïŒ
</p>
<p>å
¥åã®çµäºã¯ '<samp>.</samp>' ã®1æåã ããå«ãè¡ã§è¡šãããïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸããŠïŒåŸ©å·åŸã®æååãèŸæžé æå°ã«ãªãããã«æå·æã埩å·ãããšãã®ïŒåŸ©å·åŸã®æååãåºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>A+A++A
Z-Z--Z+-Z
[ESREVER]
J---?---J
++++++++A+++Z-----------A+++Z
[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L
.</pre>
<h3>Output for Sample Input</h3>
<pre>ABC
ZYXZ
REVERSE
JAG
ICPC
JAPAN</pre>
|
p00984 | <h2>Halting Problem</h2>
<p>
A unique law is enforced in the Republic of Finite Loop. Under the law, programs that never halt are regarded as viruses. Releasing such a program is a cybercrime. So, you want to make sure that your software products always halt under their normal use.
</p>
<p>
It is widely known that there exists no algorithm that can determine whether an arbitrary given program halts or not for a given arbitrary input. Fortunately, your products are based on a simple computation model given below. So, you can write a program that can tell whether a given program based on the model will eventually halt for a given input.
</p>
<p>
The computation model for the products has only one variable $x$ and $N + 1$ states, numbered $1$ through $N + 1$. The variable $x$ can store any integer value. The state $N + 1$ means that the program has terminated. For each integer $i$ ($1 \leq i \leq N$), the behavior of the program in the state $i$ is described by five integers $a_i$, $b_i$, $c_i$, $d_i$ and $e_i$ ($c_i$ and $e_i$ are indices of states).
</p>
<p>
On start of a program, its state is initialized to $1$, and the value of $x$ is initialized by $x_0$, the input to the program. When the program is in the state $i$ ($1 \leq i \leq N$), either of the following takes place in one execution step:
</p>
<ul>
<li> if $x$ is equal to $a_i$, the value of $x$ changes to $x + b_i$ and the program state becomes $c_i$;</li>
<li> otherwise, the value of $x$ changes to $x + d_i$ and the program state becomes $e_i$.</li>
</ul>
<p>
The program terminates when the program state becomes $N + 1$.
</p>
<p>
Your task is to write a program to determine whether a given program eventually halts or not for a given input, and, if it halts, to compute how many steps are executed. The initialization is not counted as a step.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$N$ $x_0$
$a_1$ $b_1$ $c_1$ $d_1$ $e_1$
.
.
.
$a_N$ $b_N$ $c_N$ $d_N$ $e_N$
</pre>
<p>
The first line contains two integers $N$ ($1 \leq N \leq 10^5$) and $x_0$ ($â10^{13} \leq x_0 \leq 10^{13}$). The number of the states of the program is $N + 1$. $x_0$ is the initial value of the variable $x$. Each of the next $N$ lines contains five integers $a_i$, $b_i$, $c_i$, $d_i$ and $e_i$ that determine the behavior of the program when it is in the state $i$. $a_i$, $b_i$ and $d_i$ are integers between $â10^{13}$ and $10^{13}$, inclusive. $c_i$ and $e_i$ are integers between $1$ and $N + 1$, inclusive.
</p>
<h3>Output</h3>
<p>
If the given program eventually halts with the given input, output a single integer in a line which is the number of steps executed until the program terminates. Since the number may be very large, output the number modulo $10^9 + 7$.
</p>
<p>
Output $-1$ if the program will never halt.
</p>
<h3>Sample Input 1</h3>
<pre>
2 0
5 1 2 1 1
10 1 3 2 2
</pre>
<h3>Sample Output 1</h3>
<pre>
9
</pre>
<h3>Sample Input 2 </h3>
<pre>
3 1
0 1 4 2 3
1 0 1 1 3
3 -2 2 1 4
</pre>
<h3>Sample Output 2</h3>
<pre>
-1
</pre>
<h3>Sample Input 3</h3>
<pre>
3 3
1 -1 2 2 2
1 1 1 -1 3
1 1 4 -2 1
</pre>
<h3>Sample Output 3</h3>
<pre>
-1
</pre>
|
p03351 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are <var>a</var>, <var>b</var> and <var>c</var> (in meters), respectively.
Two people can directly communicate when the distance between them is at most <var>d</var> meters.
Determine if A and C can communicate, either directly or indirectly.
Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>a,b,c</var> <var>â€</var> <var>100</var></li>
<li><var>1</var> <var>â€</var> <var>d</var> <var>â€</var> <var>100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var> <var>c</var> <var>d</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If A and C can communicate, print <code>Yes</code>; if they cannot, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 7 9 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>A and B can directly communicate, and also B and C can directly communicate, so we should print <code>Yes</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 10 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>They cannot communicate in this case.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10 10 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>There can be multiple people at the same position.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 100 2 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
</pre></section>
</div>
</span> |
p02110 |
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem M: Settler</h1>
<h2>Problem</h2>
<p>
äºæ¬¡å
å¹³é¢äžã«<var>N</var>åã®ç©ºãå°ãããã空ãå°ã«ã¯ãããã1ãã<var>N</var>ãŸã§ã®çªå·ãå²ãæ¯ãããŠãããã©ã®ç©ºãå°ããšãŠãå°ããã®ã§ãç¹ãšã¿ãªãããšãã§ããã<var>i</var>çªç®ã®ç©ºãå°ã¯(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>)ã«ååšããŠããã
</p>
<p>
倪éåã¯ãã®<var>N</var>åã®ç©ºãå°ã®äžããã¡ããã©<var>K</var>åãéžã³ããããã®ç©ºãå°ã«å»ºç©ã建ãŠãããšã«ããã
ããããããŸãã«ãè¿ãå Žæã«è€æ°ã®å»ºç©ã建ãŠãŠãé¢çœããªããšæã£ãã®ã§ã倪éåã¯ããããã®ç©ºãå°ã©ããã®ãŠãŒã¯ãªããè·é¢ãå¿
ã2以äžãšãªãããã«ç©ºãå°ãéžã¶ããšã«ããã
</p>
<p>
倪éåãéžã¶ç©ºãå°ã®çµã¿åãããšããŠèãããããã®ãåºåããããã°ã©ã ãäœæããã
çµã¿åãããè€æ°ååšããå Žåã¯ãèŸæžé ã§æå°ã®ãã®ãåºåããã
ãã ããã©ã®ããã«<var>K</var>åã®ç©ºãå°ãéžãã ãšããŠãããããã2ã€ã®ç©ºãå°ã®ãŠãŒã¯ãªããè·é¢ã2ããå°ãããªã£ãŠããŸãå Žåã¯ããããã«-1ãåºåããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var> <var>K</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
...
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var>
</pre>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
<li>2 ≤ <var>K</var> ≤ <var>N</var> ≤ 6,000</li>
<li>1 ≤ <var>x<sub>i</sub></var> , <var>y<sub>i</sub></var> ≤ 1,000,000 ( 1 ≤ <var>i</var> ≤ <var>N</var> )</li>
<li> <var>x<sub>i</sub></var> <var>mod</var> 2 = <var>floor</var> ( <var>y<sub>i</sub></var> ÷ 2 ) <var>mod</var> 2 ( 1 ≤ <var>i</var> ≤ <var>N</var> )
<br>(ããã§<var>floor</var> ( <var>y<sub>i</sub></var> ÷ 2 ) ãšã¯<var>y<sub>i</sub></var>ã2ã§å²ãå°æ°ç¹ä»¥äžãåãæšãŠãå€ã§ãã)</li>
<li>åã座æšã«è€æ°ã®ç©ºãå°ãååšããããšã¯ãªãã</li>
</ul>
<h2>Output</h2>
<p>
倪éåãéžã¶ç©ºãå°ã®çªå·ãæé ã«1è¡ãã€åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 2
2 1
1 2
1 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1
3
</pre>
<h2>Sample Input 2</h2>
<pre>
4 3
2 1
1 2
1 3
2 4
</pre>
<h2>Sample Output 2</h2>
<pre>
-1
</pre>
<h2>Sample Input 3</h2>
<pre>
5 3
5 7
5 6
6 8
20 20
4 8
</pre>
<h2>Sample Output 3</h2>
<pre>
2
3
4
</pre> |
p00087 |
<H1>æªçè
ã®æ°åŒ</H1>
<p>å士 : ããŒã¿ãŒåãã€ãã«ãã£ããã</p>
<p>ããŒã¿ãŒ : ãŸãã§ãããä»åºŠã¯ã©ããªãã ããªãçºæã§ããã</p>
<p>å士 : ã€ãã«æ°åŒãèšç®æ©ã§åŠçããç»æçãªæ¹æ³ãæãã€ãããã ããã®è¡šãã¿ãŠãããã
</p>
<center>
<table border=1>
<tr><td width=200 align=center>éåžžã®èšæ³</td><td width=200 align=center>å士ã®ãç»æçãªãèšæ³</td></tr>
<tr><td>1 + 2</td><td>1 2 +</td></tr>
<tr><td>3 * 4 + 7</td><td>3 4 * 7 +</td></tr>
<tr><td>10 / ( 2 - 12 ) </td><td>10 2 12 - /</td></tr>
<tr><td>( 3 - 4 ) * ( 7 + 2 * 3 )</td><td>3 4 - 7 2 3 * + *</td></tr>
</table>
</center>
<br/>
<p>ããŒã¿ãŒ : ã¯ãã</p>
<p>å士 : ãµã£ãµã£ãµãããã ãã§ã¯ãæªçè
ã®åã«ã¯äœã®ããšã ãããããªãã ããããããããããèå¿ãªãããã</p>
<p>ããŒã¿ãŒ : ã£ãŠãããã»ã»ã»ã</p>
<p>å士 : èšç®æ©ã«ã¯ã¹ã¿ãã¯ãšããããŒã¿æ§é ãããããšã¯åãç¥ã£ãŠããããã»ãããå
å
¥ãåŸåºããã®ãããããã</p>
<p>ããŒã¿ãŒ : ã¯ããç¥ã£ãŠãŸããããã®ã»ã»ã»ã</p>
<p>å士 : ãã®ç»æçãªèšæ³ã¯ãã®ã¹ã¿ãã¯ã䜿ãããããäŸãã°ãã® 10 2 12 - / ã ããæ¬¡ã®ããã«åŠçããã
</p>
<center>
<table>
<tr><td width="100">åŠç察象</td><td width=80 align=center>10</td><td width=80 align=center>2</td><td width=80 align=center>12</td><td width=80 align=center>-</td><td width=80 align=center>/</td></tr>
<tr><td> </td><td align=center>â</td><td align=center>â</td><td align=center>â</td><td align=center>â2-12</td><td align=center>â10/-10</td></tr>
<tr><td>ã¹ã¿ãã¯</td><td align=center>
<table border=1>
<tr><td>.</td></tr>
<tr><td>.</td></tr>
<tr><td width=40>10</td></tr>
</table>
</td><td align=center>
<table border=1>
<tr><td>.</td></tr>
<tr><td width=40>2</td></tr>
<tr><td>10</td></tr>
</table>
</td><td align=center>
<table border=1>
<tr><td width=40>12</td></tr>
<tr><td>2</td></tr>
<tr><td>10</td></tr>
</table>
</td><td align=center>
<table border=1>
<tr><td>.</td></tr>
<tr><td width=40>-10</td></tr>
<tr><td>10</td></tr>
</table>
</td><td align=center>
<table border=1>
<tr><td>.</td></tr>
<tr><td>.</td></tr>
<tr><td width=40>-1</td></tr>
</table>
</td></tr>
<tr>
</tr>
</table>
</center>
<br>
<p>å士 : ã©ããããªãæ¬åŒ§ãæŒç®åã®åªå
é äœãæ°ã«ããå¿
èŠããªãããããïŒèªé ãã10 ã 2 ãã 12 ãåŒãããã®ã§å²ããããšãªããäœãšãªãåœŒã®æ¥µæ±ã®å³¶åœã®èšèãæ¥æ¬èªãšäŒŒãŠãããããããŠã
ãã®ç»æçãªçºæããããã°ãæãç 究宀ã¯å®æ³°ãããŠããã¡ãã¡ãã¡ã</p>
<p>ããŒã¿ãŒ : ã£ãŠãããå士ãããã£ãŠæ¥æ¬ã«ãããšãäŒæŽ¥å€§åŠã®åºç€ã³ãŒã¹ã§ç¿ããŸãããããéããŒã©ã³ãèšæ³ããšããã£ãŠãã¿ããªç°¡åã«ããã°ã©ã ããŠãŸããã</p>
<p>å士 : ã»ã»ã»ã</p>
<p>
ãšããããšã§ãããŒã¿ãŒåã«å€ãã£ãŠå士ã«ããã®ããã°ã©ã ãæããäºã«ãªããŸããããéããŒã©ã³ãèšæ³ãã§æžãããæ°åŒãå
¥åãšããèšç®çµæãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>å
¥å</H2>
<p>è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã§ã¯ãéããŒã©ã³ãèšæ³ã«ããæ°åŒïŒæŽæ°ãšæŒç®èšå·ãç©ºçœæåïŒæåïŒåè§ïŒã§åºåããã80æå以å
ã®æååïŒã ïŒ è¡ã«äžããããŸãã
ããå€ã 0 ã 0 ã«éããªãè¿ãå€ã§å²ããããªæ°åŒã¯äžããããŸããã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>åºå</H2>
<p>åããŒã¿ã»ããããšã«ãèšç®çµæïŒå®æ°ïŒãïŒè¡ã«åºåããŠãã ããããªããèšç®çµæã¯ 0.00001 以äžã®èª€å·®ãå«ãã§ãããã
</p>
<H2>Sample Input</H2>
<pre>
10 2 12 - /
3 4 - 7 2 3 * + *
-1 -2 3 + +
</pre>
<H2>Output for the Sample Input</H2>
<pre>
-1.000000
-13.000000
0.000000
</pre>
|
p02540 | <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> cities on a 2D plane. The coordinate of the <var>i</var>-th city is <var>(x_i, y_i)</var>. Here <var>(x_1, x_2, \dots, x_N)</var> and <var>(y_1, y_2, \dots, y_N)</var> are both permuations of <var>(1, 2, \dots, N)</var>.</p><p>For each <var>k = 1,2,\dots,N</var>, find the answer to the following question:</p><p>Rng is in City <var>k</var>.
Rng can perform the following move arbitrarily many times:</p><ul><li>move to another city that has a smaller <var>x</var>-coordinate and a smaller <var>y</var>-coordinate, or a larger <var>x</var>-coordinate and a larger <var>y</var>-coordinate, than the city he is currently in.</li></ul><p>How many cities (including City <var>k</var>) are reachable from City <var>k</var>?</p></section></div><div class="part"><section><h3>Constraints</h3><ul><li><var>1 \leq N \leq 200,000</var></li><li><var>(x_1, x_2, \dots, x_N)</var> is a permutation of <var>(1, 2, \dots, N)</var>.</li><li><var>(y_1, y_2, \dots, y_N)</var> is a permutation of <var>(1, 2, \dots, 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>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre></section></div><div class="part"><section><h3>Output</h3><p>Print <var>N</var> lines. In <var>i</var>-th line print the answer to the question when <var>k = i</var>.</p></section></div></div><hr/><div class="part"><section><h3>Sample Input 1</h3><pre>4
1 4
2 3
3 1
4 2
</pre></section></div><div class="part"><section><h3>Sample Output 1</h3><pre>1
1
2
2
</pre><p>Rng can reach City <var>4</var> from City <var>3</var>, or conversely City <var>3</var> from City <var>4</var>.</p></section></div><hr/><div class="part"><section><h3>Sample Input 2</h3><pre>7
6 4
4 3
3 5
7 1
2 7
5 2
1 6
</pre></section></div><div class="part"><section><h3>Sample Output 2</h3><pre>3
3
1
1
2
3
2
</pre></section></div></span> |
p02055 | <h2>D: Two Colors Sort</h2>
<h3>åé¡</h3>
<p>umg åã¯æ£æ©äžã« <var> 1,2, ... ,N </var> ã䞊ã³å€ããŠã§ããé·ã <var>N</var> ã®æ°å <var> P_1, P_2, ..., P_N </var> ãèŠã€ããŸããã</p>
<p>umg åã¯äžæè°ãªåã䜿ãããšã§ãåãè²ã«å¡ãããç°ãªãæ°ãäºã€éžãã§å Žæã亀æããããšãã§ããŸãã</p>
<p>umg åã¯ãæ°åã«å«ãŸããæ°ã®ãã¡ <var>R</var> åãèµ€ã«ãæ®ãã® <var>N-R</var> åãéã«å¡ãããšã§æ°åãæé ã«äžŠã³æ¿ããããããã«ããããšèããŸããã</p>
<p>umg åãç®æšãéæã§ãããã©ããå€å®ããŠãã ããã</p>
<p>ãã ããæ°åã¯ãšãŠãéãã®ã§äžæè°ãªåã䜿ããã«åããããšã¯ã§ããŸããããŸããumg åã¯å€©æãªã®ã§äžæè°ãªåãä»»æã®åæ°äœ¿ãããšãã§ããŸãã</p>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>N</var> <var>R</var>
<var>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var>
</pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq N \leq 3 \times 10^5</var></li>
<li> <var>1 \leq R \leq N</var></li>
<li> <var>1\leq P_i \leq N</var></li>
<li> <var>P_i \neq P_j</var> (<var>1 \leq i < j \leq N</var>)</li>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>umg åãç®çãéæã§ãããªã <code>Yes</code>ãããã§ãªããã° <code>No</code> ãäžè¡ã«åºåããã</p>
<h3>å
¥åäŸ 1</h3>
<pre>
3 2
1 3 2
</pre>
<h3>åºåäŸ 1</h3>
<pre>Yes</pre>
<ul>
<li> <var>1</var> ãéã«ã<var>2,3</var> ãèµ€ã«å¡ãããšã§ç®æšãéæã§ããŸãã</li>
</ul>
<h3>å
¥åäŸ 2</h3>
<pre>
5 2
1 2 3 4 5
</pre>
<h3>åºåäŸ 2</h3>
<pre>Yes</pre>
<ul>
<li> åãããæé ã«äžŠãã§ããŸãã</li>
</ul>
<h3>å
¥åäŸ 3</h3>
<pre>
10 7
3 4 8 5 7 6 2 10 1 9
</pre>
<h3>åºåäŸ 3</h3>
<pre>No</pre>
|
p00068 |
<H1>茪ãŽã </H1>
<p>
<var>n</var> æ¬ã®éãå¹³æ¿äžã®åº§æš <var>P<sub>1</sub></var> (<var>x<sub>1</sub></var>, <var>y</sub>1</sub></var>), <var>P<sub>2</sub></var> (<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>), <var>P<sub>3</sub></var> (<var>x<sub>3</sub></var>, <var>y<sub>3</sub></var>),..., <var>P<sub>n</sub></var> (<var>x<sub>n</sub></var>, <var>y<sub>n</sub></var>) ã«ïŒæ¬ãã€æã¡ã茪ãŽã ã®èŒªã®äžã«å
šãŠã®éãå
¥ãããã« 1 æ¬ã®èŒªãŽã ã§å²ã¿ãŸãããã®ãšãã茪ãŽã ã亀差ããŠã¯ãããŸããã
</p>
<p>
éã®åº§æšãèªã¿èŸŒãã§ãäžèšã®ããã«éã茪ãŽã ã§å²ãã ãšãã«èŒªãŽã ã«æ¥ããŠããªãéã®æ¬æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã茪ãŽã ã¯å
åã«äŒžã³çž®ã¿ãããã®ãšããŸããåã座æšã« 2 æ¬ä»¥äžã®éãæã€ããšã¯ãªããã®ãšããŸãããŸãã茪ãŽã ãããã£ãéãšéã®éã¯çŽç·ã§çµã°ãããã®ãšãããã®çŽç·äžã« 3 æ¬ä»¥äžã®éã䞊ã¶ããšã¯ãªããã®ãšããŸããäŸãã°ãå³ 1 ã«ç€ºããããªå
¥åã¯ããããŸãããå³ 2 ã«ç€ºãããã«èŒªãŽã ãããã£ãŠããªãéã 1 çŽç·äžã«äžŠã¶ããšã¯ããããŸãã
</p>
<center>
<table>
<tr>
<td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex1"></td>
<td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex2"></td>
</tr>
<tr>
<td>å³ïŒ</td>
<td>å³ïŒ</td>
</tr>
</table>
</center>
<br/>
<p>
ãã ããããããã®åº§æšå€ã¯ -1000.0 以äž1000.0 以äžã®å®æ°ã§ãããŸãã<var>n</var> 㯠3 ä»¥äž 100 以äžã®æŽæ°ã§ãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒã§ãäžããããŸãã
</p>
<pre>
<var>n</var>
<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>
... ãããã
...
<var>x<sub>n</sub></var>, <var>y<sub>n</sub></var>
</pre>
<p>
<var>n</var> ã 0 ã®æãå
¥åã®æåŸã瀺ããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ããŽã ãšæ¥ããŠããªãéã®æ¬æ°ãåºåããŠãã ããã
äŸãã°ãå³ 3 ã«ç€ºãïŒã€ã®éã衚ãå
¥åããã£ãå Žåãå³ 4 ã®ããã«å²ãŸããã®ã§ã茪ãŽã ã«æ¥ããŠããªãéã®æ¬æ°ã¯ 1 æ¬ã§ãã
</p>
<center>
<table>
<tr>
<td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex3"></td>
<td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex4"></td>
</tr>
<tr>
<td>å³ïŒ</td>
<td>å³ïŒ</td>
</tr>
</table>
</center>
<br/>
<H2>Sample Input</H2>
<pre>
4
1.0,0.0
0.0,1.0
2.0,1.0
1.0,2.0
9
-509.94,892.63
567.62,639.99
-859.32,-64.84
-445.99,383.69
667.54,430.49
551.12,828.21
-940.2,-877.2
-361.62,-970
-125.42,-178.48
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
3
</pre>
<H2>Hint</H2>
<p>
以äžã¯ïŒã€ãã®ãµã³ãã«å
¥åã«å¯Ÿããå³ã§ãã
</p>
<center>
<table>
<tr>
<td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex5"></td>
</tr>
<tr>
</tr>
</table>
</center>
|
p00592 |
<H1>Boring Commercial</H1>
<p>
Now it is spring holidays. A lazy student has finally passed all final examination, and he decided to just kick back and just watch TV all day. Oh, his
only source of entertainment is watching TV. And TV commercial, as usual, are
a big nuisance for him. He can watch any thing on television, but cannot bear
even a single second of commercial. So to prevent himself from the boredom of
seeing the boring commercial, he keeps shuffling through the TV channels, so
that he can watch programs on different channels without seeing even a single
commercial.
</p>
<p>
Given the number of channels, and the duration at which the TV commercials
are showed on each of the channels, you have to write a program which will
print the longest interval for which the lazy student can watch the television by
shuffling between the different channels without ever seeing an TV commercial.
</p>
<p>
For example, consider the simplified situation where there are only three
television channels, and suppose that he is watching TV from 2100 hrs to 2400
hrs. Suppose that the commercials are displayed at following time on each of
the channels.
</p>
<ul>
<li> Channel 1: 2100 to 2130, 2200 to 2230 and 2300 to 2330</li>
<li> Channel 2: 2130 to 2200, 2330 to 2400</li>
<li> Channel 3: 2100 to 2130, 2330 to 2400</li>
</ul>
<p>
Then in this case, he can watch TV without getting interrupted by commercials for full 3 hours by watching Channel 2 from 2100 to 2130, then Channel 3
from 2130 to 2330, and then Channel 1 from 2330 to 2400.
</p>
<H2>Input</H2>
<p>
The input will consist of several cases. In each case, the first line of the input
will be n, the number of channels, which will then be followed by p and q, the
time interval between which he will be watching the TV. It will be followed by
2n lines, giving the time slots for each of the channels. For each channel, the
first line will be k, the number of commercial slots, and it will then be followed
by 2k numbers giving the commercial slots in order.
</p>
<p>
The input will be terminated by values 0 for each of n, p, q. This case should
not be processed.
</p>
<H2>Output</H2>
<p>
For each case, you have to output the maximum duration (in minutes) for which
he can watch television without seeing any commercial.
</p>
<H2>Sample Input</H2>
<pre>
1 2100 2400
1
2130 2200
3 2100 2400
3
2100 2130 2200 2230 2300 2330
2
2130 2200 2330 2400
2
2100 2130 2330 2400
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
120
180
</pre>
|
p02405 | <H1>Print a Chessboard</H1>
<p>
Draw a chessboard which has a height of <var>H</var> cm and a width of <var>W</var> cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.
</p>
<pre>
#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#
</pre>
<p>
Note that the top left corner should be drawn by '#'.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of two integers <var>H</var> and <var>W</var> separated by a single space.
</p>
<p>
The input ends with two 0 (when both <var>H</var> and <var>W</var> are zero).
</p>
<H2>Output</H2>
<p>
For each dataset, print the chessboard made of '#' and '.'.
</p>
<p>
Print a blank line after each dataset.
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <i>H</i> ≤ 300</li>
<li>1 ≤ <i>W</i> ≤ 300</li>
</ul>
<H2>Sample Input</H2>
<pre>
3 4
5 6
3 3
2 2
1 1
0 0
</pre>
<H2>Sample Output</H2>
<pre>
#.#.
.#.#
#.#.
#.#.#.
.#.#.#
#.#.#.
.#.#.#
#.#.#.
#.#
.#.
#.#
#.
.#
#
</pre>
|
p00438 |
<H1>éåŠçµè·¯</H1>
<h2>åé¡</h2>
<p>
倪éåã®äœãã§ããJOIåžã¯ïŒååæ¹åã«ãŸã£ããã«äŒžã³ã a æ¬ã®éè·¯ãšïŒæ±è¥¿æ¹åã«ãŸã£ããã«äŒžã³ã b æ¬ã®éè·¯ã«ããïŒç¢ç€ã®ç®ã®åœ¢ã«åºåããããŠããïŒ
</p>
<p>
ååæ¹åã® a æ¬ã®éè·¯ã«ã¯ïŒè¥¿ããé ã« 1, 2, ... , a ã®çªå·ãä»ããããŠããïŒãŸãïŒæ±è¥¿æ¹åã® b æ¬ã®éè·¯ã«ã¯ïŒåããé ã« 1, 2, ... , b ã®çªå·ãä»ããããŠããïŒè¥¿ãã i çªç®ã®ååæ¹åã®éè·¯ãšïŒåãã j çªç®ã®æ±è¥¿æ¹åã®éè·¯ã亀ãã亀差ç¹ã (i, j) ã§è¡šãïŒ
</p>
<p>
倪éåã¯ïŒäº€å·®ç¹ (1, 1) ã®è¿ãã«äœãã§ããïŒäº€å·®ç¹ (a, b) ã®è¿ãã®JOI髿 ¡ã«èªè»¢è»ã§éã£ãŠããïŒèªè»¢è»ã¯éè·¯ã«æ²¿ã£ãŠã®ã¿ç§»åããããšãã§ããïŒå€ªéåã¯ïŒéåŠæéãçãããããïŒæ±ãŸãã¯åã«ã®ã¿åãã£ãŠç§»åããŠéåŠããŠããïŒ
</p>
<p>
çŸåšïŒ JOIåžã§ã¯ïŒ n åã®äº€å·®ç¹ (x<sub>1</sub>, y<sub>1</sub>), (x<sub>2</sub>, y<sub>2</sub>), ... , (x<sub>n</sub>, y<sub>n</sub>) ã§å·¥äºãè¡ã£ãŠããïŒå€ªéåã¯å·¥äºäžã®äº€å·®ç¹ãéãããšãã§ããªãïŒ
</p>
<p>
倪éåãäº€å·®ç¹ (1, 1) ããäº€å·®ç¹ (a, b) ãŸã§ïŒå·¥äºäžã®äº€å·®ç¹ãé¿ããªããïŒæ±ãŸãã¯åã«ã®ã¿åãã£ãŠç§»åããŠéåŠããæ¹æ³ã¯äœéãããã ãããïŒå€ªéåã®éåŠçµè·¯ã®åæ° m ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<H2>å
¥å</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒå
¥åã¯ãŒããïŒã€å«ãè¡ã§çµäºããïŒ
</p>
<p>
1è¡ç®ã«ã¯ïŒç©ºçœãåºåããšããŠ2åã®æŽæ° a, b ãæžãããŠããïŒããã¯ïŒååæ¹åã®éè·¯ã®æ¬æ°ãšïŒæ±è¥¿æ¹åã®éè·¯ã®æ¬æ°ã衚ãïŒ a, b 㯠1 ≤ a, b ≤ 16 ãã¿ããïŒ
</p>
<p>
2è¡ç®ã«ã¯, å·¥äºäžã®äº€å·®ç¹ã®åæ°ãè¡šãæŽæ° n ãæžãããŠããïŒ n 㯠1 ≤ n ≤ 40 ãã¿ããïŒ
</p>
<p>
ç¶ã n è¡ (3è¡ç®ãã n+2 è¡ç®) ã«ã¯ïŒå·¥äºäžã®äº€å·®ç¹ã®äœçœ®ãæžãããŠããïŒ i+2 è¡ç®ã«ã¯ç©ºçœã§åºåãããæŽæ° x<sub>i</sub>, y<sub>i</sub> ãæžãããŠããïŒäº€å·®ç¹ (x<sub>i</sub>, y<sub>i</sub>) ãå·¥äºäžã§ããããšã衚ãïŒ x<sub>i</sub>, y<sub>i</sub> 㯠1 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 16 ãã¿ããïŒ
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<H2>åºå</H2>
<p>
<!--æåºãããã¡ã€ã«ã¯, 倪éåã®éåŠçµè·¯ã®åæ° m ã ããå«ã1è¡ãããªã.-->
ããŒã¿ã»ããããšã«, 倪éåã®éåŠçµè·¯ã®åæ° m ã1è¡ã«åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<!--
<pre>
<table style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px;">
<tr>
<th width="150" align="left">å
¥åäŸ</th>
</tr>
<tr><td></td><td></td></tr>
<tr><td>5 4 </td></tr>
<tr><td>3 </td></tr>
<tr><td>2 2 </td></tr>
<tr><td>2 3 </td></tr>
<tr><td>4 2 </td></tr>
<tr>
<td>ã</td>
</tr>
<tr>
<th width="150" align="left">åºåäŸ</th>
</tr>
<tr><td>5</td></tr>
</table>
-->
<H2>å
¥åäŸ</H2>
<pre>
5 4
3
2 2
2 3
4 2
5 4
3
2 2
2 3
4 2
0 0
</pre>
<H2>åºåäŸ</H2>
<pre>
5
5
</pre>
<p>äžå³ã¯ a=5, b=4, n=3 ã§ïŒå·¥äºäžã®äº€å·®ç¹ã (2,2), (2,3), (4,2) ã®å Žåã衚ããŠããïŒ</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_route-fig1">
</center>
<p>
ãã®å ŽåïŒéåŠçµè·¯ã¯ m=5 éãããïŒ 5éãã®éåŠçµè·¯ãå
šãŠå³ç€ºãããšïŒä»¥äžã®éãïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_route-fig2">
</center>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p01679 |
<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 are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO.
Since every SIRO restaurant has its own tasteful ramen, he wants to try them at as many different restaurants as possible in the night.
He doesn't have plenty of time tonight, however, because he has to get up early in the morning tomorrow to join a training session.
So he asked you to find the maximum number of different restaurants to which he would be able to go to eat ramen in the limited time.
</p>
<p>There are $n$ railway stations in the city, which are numbered $1$ through $n$. The station $s$ is the nearest to the camp venue.
$m$ pairs of stations are directly connected by the railway: you can move between the stations $a_i$ and $b_i$ in $c_i$ minutes in the both directions.
Among the stations, there are $l$ stations where a SIRO restaurant is located nearby. There is at most one SIRO restaurant around each of the stations, and there are no restaurants near the station $s$.
It takes $e_i$ minutes for Jiro to eat ramen at the restaurant near the station $j_i$.
</p>
<p>It takes only a negligibly short time to go back and forth between a station and its nearby SIRO restaurant.
You can also assume that Jiro doesn't have to wait for the ramen to be served in the restaurants.
</p>
<p>Jiro is now at the station $s$ and have to come back to the station in $t$ minutes. How many different SIRO's can he taste?
</p>
<h3>Input</h3>
<p>The input is a sequence of datasets. The number of the datasets does not exceed $100$. Each dataset is formatted as follows:
</p>
<blockquote>$n$ $m$ $l$ $s$ $t$<br>$a_1$ $b_1$ $c_1$<br>:<br>:<br>$a_m$ $b_m$ $c_m$<br>$j_1$ $e_1$<br>:<br>:<br>$j_l$ $e_l$</blockquote>
<p>The first line of each dataset contains five integers:
</p><ul><li><p> $n$ for the number of stations,
</p></li><li><p> $m$ for the number of directly connected pairs of stations,
</p></li><li><p> $l$ for the number of SIRO restaurants,
</p></li><li><p> $s$ for the starting-point station, and
</p></li><li><p> $t$ for the time limit for Jiro.
</p></li></ul>
<p>Each of the following $m$ lines contains three integers:
</p><ul><li><p> $a_i$ and $b_i$ for the connected stations, and
</p></li><li><p> $c_i$ for the time it takes to move between the two stations.
</p></li></ul>
<p>Each of the following $l$ lines contains two integers:
</p><ul><li><p> $j_i$ for the station where a SIRO restaurant is located, and
</p></li><li><p> $e_i$ for the time it takes for Jiro to eat at the restaurant.
</p></li></ul>
<p>The end of the input is indicated by a line with five zeros, which is not included in the datasets.
</p>
<p>The datasets satisfy the following constraints:
</p>
<ul><li><p> $2 \le n \le 300$
</p></li><li><p> $1 \le m \le 5{,}000$
</p></li><li><p> $1 \le l \le 16$
</p></li><li><p> $1 \le s \le n$
</p></li><li><p> $1 \le t \le 100{,}000$
</p></li><li><p> $1 \le a_i, b_i \le n$
</p></li><li><p> $1 \le c_i \le 1{,}000$
</p></li><li><p> $1 \le j_i \le n$
</p></li><li><p> $1 \le e_i \le 15$
</p></li><li><p> $s \ne j_i$
</p></li><li><p> $j_i$'s are distinct.
</p></li><li><p> $a_i \ne b_i$
</p></li><li><p> $(a_i, b_i) \ne (a_j, b_j)$ and $(a_i, b_i) \ne (b_j, a_j)$ for any $i \ne j$
</p></li></ul>
<p>Note that there may be some stations not reachable from the starting point $s$.
</p>
<h3>Output</h3>
<p>For each data set, output the maximum number of different restaurants where Jiro can go within the time limit.
</p>
<h3>Sample Input</h3>
<pre>2 1 1 1 10
1 2 3
2 4
2 1 1 1 9
1 2 3
2 4
4 2 2 4 50
1 2 5
3 4 5
2 15
3 15
4 6 3 1 29
1 2 20
3 2 10
4 1 5
3 1 5
2 4 3
3 4 4
2 1
4 5
3 3
0 0 0 0 0</pre>
<h3>Output for the Sample Input</h3>
<pre>1
0
1
3</pre> |
p03644 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi loves numbers divisible by <var>2</var>.</p>
<p>You are given a positive integer <var>N</var>. Among the integers between <var>1</var> and <var>N</var> (inclusive), find the one that can be divisible by <var>2</var> for the most number of times. The solution is always unique.</p>
<p>Here, the number of times an integer can be divisible by <var>2</var>, is how many times the integer can be divided by <var>2</var> without remainder.</p>
<p>For example,</p>
<ul>
<li><var>6</var> can be divided by <var>2</var> once: <var>6</var> -> <var>3</var>.</li>
<li><var>8</var> can be divided by <var>2</var> three times: <var>8</var> -> <var>4</var> -> <var>2</var> -> <var>1</var>.</li>
<li><var>3</var> can be divided by <var>2</var> zero times.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</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>7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p><var>4</var> can be divided by <var>2</var> twice, which is the most number of times among <var>1</var>, <var>2</var>, ..., <var>7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>32
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>32
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
</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>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>64
</pre></section>
</div>
</span> |
p02956 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a set <var>S</var> of <var>N</var> points in a two-dimensional plane. The coordinates of the <var>i</var>-th point are <var>(x_i, y_i)</var>. The <var>N</var> points have distinct <var>x</var>-coordinates and distinct <var>y</var>-coordinates.</p>
<p>For a non-empty subset <var>T</var> of <var>S</var>, let <var>f(T)</var> be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in <var>T</var>. More formally, we define <var>f(T)</var> as follows:</p>
<ul>
<li><var>f(T) := </var> (the number of integers <var>i</var> <var>(1 \leq i \leq N)</var> such that <var>a \leq x_i \leq b</var> and <var>c \leq y_i \leq d</var>, where <var>a</var>, <var>b</var>, <var>c</var>, and <var>d</var> are the minimum <var>x</var>-coordinate, the maximum <var>x</var>-coordinate, the minimum <var>y</var>-coordinate, and the maximum <var>y</var>-coordinate of the points in <var>T</var>)</li>
</ul>
<p>Find the sum of <var>f(T)</var> over all non-empty subset <var>T</var> of <var>S</var>. Since it can be enormous, print the sum modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>-10^9 \leq x_i, y_i \leq 10^9</var></li>
<li><var>x_i \neq x_j (i \neq j)</var></li>
<li><var>y_i \neq y_j (i \neq 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>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of <var>f(T)</var> over all non-empty subset <var>T</var> of <var>S</var>, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
-1 3
2 1
3 -2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>13
</pre>
<p>Let the first, second, and third points be <var>P_1</var>, <var>P_2</var>, and <var>P_3</var>, respectively. <var>S = \{P_1, P_2, P_3\}</var> has seven non-empty subsets, and <var>f</var> has the following values for each of them:</p>
<ul>
<li><var>f(\{P_1\}) = 1</var></li>
<li><var>f(\{P_2\}) = 1</var></li>
<li><var>f(\{P_3\}) = 1</var></li>
<li><var>f(\{P_1, P_2\}) = 2</var></li>
<li><var>f(\{P_2, P_3\}) = 2</var></li>
<li><var>f(\{P_3, P_1\}) = 3</var></li>
<li><var>f(\{P_1, P_2, P_3\}) = 3</var></li>
</ul>
<p>The sum of these is <var>13</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 4
2 1
3 3
4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>34
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
19 -11
-3 -12
5 3
3 -15
8 -14
-9 -20
10 -9
0 2
-7 17
6 -6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>7222
</pre>
<p>Be sure to print the sum modulo <var>998244353</var>.</p></section>
</div>
</span> |
p01383 |
<div>
<h1 class="title">åé¡ H : ãã£ãã·ã¥æŠç¥</h1>
<p>ä»ïŒGââgle Code Jam ã®å°åºå€§äŒãå§ãŸãããšããŠããïŒ
æãå³åã®åžã«åº§ã£ãŠããç·ã® ID 㯠lyrically ãšèšããããïŒ
æ±äº¬å€§åп代ã®èšæ¶ã«ïŒäŒŒããã㪠ID ã®ä»²éãå±
ãèŠãããããïŒåã®ä»²éã¯äžäººæ®ããçŸå°å¥³ã ã£ãã¯ãã ïŒ</p>
<p>åã®èšæ¶ã®äžã® lyrically ã¯ïŒã¢ã«ãŽãªãºã ã®åãå®è£
ã®åãããªããïŒ
æ°åã§åé¡ã«æ£è§£ããããšã«ãå®è©ããã£ãïŒ
äŸãã°ïŒèšç®éãå€å°æªãããã°ã©ã ã§ãïŒäžæãªå®è£
ãããããšã§é«éã«ãïŒ
æ£è§£ãšãããããªããšãåŸæãšããŠããïŒ</p>
<p>ããã°ã©ã ãé«éã«ããäžã§ïŒéåžžã«å€§åã«ãªã£ãŠããã®ãïŒ
ãã£ãã·ã¥ã¡ã¢ãªãšã®èŠªåæ§ã§ããïŒ</p>
<div>
<h1>åé¡</h1>
<p>ãããã¯æ¯ã«èªã¿èŸŒã¿ã®ã³ã¹ããç°ãªãã¡ã¢ãªãèããïŒ
èµ·ããå
šãŠã®ã¡ã¢ãªã¢ã¯ã»ã¹ããããããåãã£ãç¶æ
ã§ã®ïŒ
ãã«ã¢ãœã·ã¢ãã£ãã®ãã£ãã·ã¥ã¡ã¢ãªã§ã®æåãªãã£ãã·ã¥æŠç¥ãæ±ãããïŒ
以äžïŒå¹³æãªèšèã§èª¬æããïŒ</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>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>i</i></span> ã«ã¯éã <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>i</i></sub></span> ãæ±ºãŸã£ãŠããïŒ
ãŸãïŒé·ã <span style="font-size:110%;font-family:times new roman;"><i>K</i></span> ã®æ°å <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, âŠ, <i>a</i><sub><i>K</i></sub></span> ãäžããããïŒ
å <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> 㯠<span style="font-size:110%;font-family:times new roman;">1 ≤ <i>a</i><sub><i>j</i></sub> ≤ <i>N</i></span> ãæºããæŽæ°ã§ããïŒ</p>
<p>ã¯ããã¯å
šãŠã®ç®±ã¯ç©ºã§ããïŒ
<span style="font-size:110%;font-family:times new roman;"><i>j</i> = 1, 2, âŠ, <i>K</i></span> ã®é ã«ïŒä»¥äžãè¡ãããïŒ</p>
<ul class="simple">
<li>ããŒã« <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> ãå
¥ã£ãŠããç®±ãããã°ïŒäœãããªãïŒ<ul>
<li>ãã®æäœã«ãããã³ã¹ã㯠0 ã§ããïŒ</li>
</ul>
</li>
<li>ããŒã« <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> ãå
¥ã£ãŠããç®±ããªããã°ïŒããããã®ç®±ã«ããŒã« <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> ãå
¥ããïŒ<ul>
<li>ããŒã«ãç®±ã«å
¥ããéïŒããæ¢ã«ãã®ç®±ã«å
¥ã£ãŠããããŒã«ãããã°ïŒãã®ããŒã«ã¯å€ã«åºãïŒ</li>
<li>ãã®æäœã«ãããã³ã¹ã㯠<span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>a</i><sub><i>j</i></sub></sub></span> ã§ããïŒïŒã³ã¹ãã¯ïŒå
¥ããç®±ãåãåºãããŒã«çã«ã¯ãããªãïŒïŒ</li>
</ul>
</li>
</ul>
<p>ã³ã¹ãã®åã®æå°å€ãèšç®ããããã°ã©ã ãäœæããïŒ</p>
</div>
<div>
<h1>å
¥å</h1>
<p>å
¥åã®æåã®è¡ã¯ 3 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>M</i>, <i>N</i>, <i>K</i></span> ãå«ãïŒ</p>
<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;"><i>i</i></span> è¡ç®ã«ã¯æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>i</i></sub></span> ãæžãããŠããïŒ</p>
<p>ç¶ã <span style="font-size:110%;font-family:times new roman;"><i>K</i></span> è¡ã® <span style="font-size:110%;font-family:times new roman;"><i>j</i></span> è¡ç®ã«ã¯æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> ãæžãããŠããïŒ</p>
</div>
<div>
<h1>åºå</h1>
<p>ã³ã¹ãã®åã®æå°å€ãåºåããïŒ</p>
</div>
<div>
<h1>å¶çŽ</h1>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>M</i> ≤ 10</span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>N</i> ≤ 10<sup>4</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>K</i> ≤ 10<sup>4</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>w</i><sub><i>i</i></sub> ≤ 10<sup>4</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>a</i><sub><i>j</i></sub> ≤ <i>N</i></span></li>
</ul>
</div>
<div>
<h1>éšåç¹</h1>
<p>ãã®åé¡ã®å€å®ã«ã¯ïŒ20 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ
ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã®å
¥åã¯ä»¥äžãæºããïŒ</p>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>M</i> ≤ 3</span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>N</i> ≤ 10</span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>K</i> ≤ 10<sup>3</sup></span></li>
</ul>
</div>
<div>
<h1>å
¥åºåäŸ</h1>
<div>
<h2>å
¥åäŸ 1</h2>
<p>å
¥åäŸ 1:</p>
<pre class="literal-block">
3 3 6
10
20
30
1
2
3
1
2
3
</pre>
<p>å
¥åäŸ 1 ã«å¯ŸããåºåäŸ:</p>
<pre class="literal-block">
60
</pre>
</div>
<div>
<h2>å
¥åäŸ 2</h2>
<p>å
¥åäŸ 2:</p>
<pre class="literal-block">
2 3 6
10
20
30
1
2
3
1
2
3
</pre>
<p>å
¥åäŸ 2 ã«å¯ŸããåºåäŸ:</p>
<pre class="literal-block">
80
</pre>
</div>
</div>
</div> |
p01229 |
<h1><font color="#000">Problem G:</font>ãšããžãŒã»ãã©ã³ã¹ããŒã¿ãŒ</h1>
<p>
ãšããç ç©¶æã§ïŒ
ãšãã«ã®ãŒäŒéçšã®åªäœã®éçºãããŠããïŒ
ãã®åªäœã¯å³3ã«ç€ºããããªç¹æ®ãªç©è³ªãããªã
ããªããŒæ§é ããªããŠããïŒ
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_energy"
alt="ãšãã«ã®ãŒäŒéçšåªäœã®æ§é ïŒ">
</td>
</tr>
<tr>
<td>
(-α-Ea-β-)<sub><var>n</var></sub>
</td>
</tr>
<tr>
<td>å³3: ãšãã«ã®ãŒäŒéçšåªäœã®æ§é ïŒ</td>
</tr>
</table>
</center>
<p>
å³ã® Ea ã§ç€ºããéšåããã®åªäœã®ãã£ãšãç¹åŸŽçãªéšäœã®
ãšããžãŒã¢ãã¥ã ã¬ãŒã¿ (Energy Accumulator) ã§ããïŒ
ãã®Eaåºã¯ 1 kJ å¹
ã§é¢æ£åããã倿§ãªãšãã«ã®ãŒç¶æ
ãåãããšãã§ããïŒ
ããEaåºãå±èµ·ããããšïŒ
ãã®Eaåºã®αåŽã«çµåããŠãã飿¥ããEaåºã«èç©ãããŠããå
šãšãã«ã®ãŒã
βåŽã«çµåããŠãã飿¥ããEaåºã«ç§»åããããããªå¹æãæã€
çºç±åå¿ãåŒãèµ·ããããïŒå³4ïŒïŒ
ãã®åå¿ã®éïŒå±èµ·ãããEaåºã®ãšãã«ã®ãŒã 1 kJ æ¶è²»ãããïŒ
ãªãïŒããªããŒã®äž¡ç«¯ã«äœçœ®ããEaåºããšãã«ã®ãŒç¶æ
ã 0 kJ ã«ãªã£ãŠãã
Eaåºã«å¯ŸããŠã¯å±èµ·åå¿ã¯çºçããªãããšïŒ
ããã³Eaåºã¯ååã«å€§ããªãšãã«ã®ãŒãèããããšãå¯èœã§ããããšãç¥ãããŠããïŒ
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_energy"
alt="äžå€®ã®Eaåºãå±èµ·ããããšãã®åå¿ïŒ">
</td>
</tr>
<tr>
<td>å³4: äžå€®ã®Eaåºãå±èµ·ããããšãã®åå¿ïŒ</td>
</tr>
</table>
</center>
<p>
ãã®æ§è³ªãå©çšããããšã§ãšãã«ã®ãŒã®äŒéãå¯èœã«ããããšèããŠããã®ã ãïŒ
ãšãã«ã®ãŒãå¹çããäŒéããã«ã¯åEaåºãå±èµ·ãããé çªãéèŠã§ããããšã«
ç ç©¶è
ãã¡ã¯æ°ãã€ããã®ã§ããïŒ
</p>
<p>
幞ãïŒå±èµ·ãããé çªãåæ°ã¯ä»»æã«å¶åŸ¡ã§ããã®ã ãïŒ
圌ãã«ã¯æé©ãªå±èµ·æé ãããããªãïŒ
ããã§åœŒãã®çºæ³ã®è¶³ããããšããŠïŒ
åæç¶æ
ã®ãšãã«ã®ãŒååžã«å¯ŸããŠ
æå³EaåºïŒβæ«ç«¯ãããã£ãšãè¿ãEaåºïŒ
ã«èãããããæå€§ã®ãšãã«ã®ãŒéãèšç®ããŠãããããïŒ
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æããïŒ
以äžã®ãããªåœ¢åŒã§äžããããïŒ
</p>
<pre>
<var>N</var>
<var>C</var><sub>1</sub>
<var>C</var><sub>2</sub>
...
<var>C</var><sub><var>N</var></sub>
</pre>
<p>
å
¥åã®å
é ã®æŽæ° <var>N</var>
(0 < <var>N</var> ≤ 60) ãåãæ±ãåé¡ã®ããŒã¿ã»ããæ°ã§ããïŒ
ãã®åŸã 2<var>N</var> è¡ã«æž¡ã£ãŠïŒ
ããããã®ããŒã¿ã»ããããšã®æ
å ± <var>C</var><sub><var>k</var></sub>
ãäžããããïŒ
</p>
<p>
ããããã®ããŒã¿ã»ãã <var>C</var><sub><var>k</var></sub>
ã¯ä»¥äžã®ãããªåœ¢åŒã§
2è¡ã«æž¡ãäžããããïŒ
</p>
<pre>
<var>L</var>
<var>E</var><sub>1</sub> <var>E</var><sub>2</sub> ... <var>E</var><sub><var>L</var></sub>
</pre>
<p>
<var>L</var> ã¯ããããã®ããŒã¿ã»ããã§åãæ±ãåªäœã®Eaéã®é·ãã§ããïŒ
ããã§äžããããæ°ã ãEaåºãçŽåã«çµåããŠããããšãæå³ããŠããïŒ
ãã®æ¬¡ã®è¡ã® <var>L</var> åã®æŽæ° <var>E</var><sub><var>k</var></sub> ã¯ïŒ
é·ã<var>L</var>ã®Eaéã®ãã¡αæ«ç«¯ãå·Šç«¯ã«æ®ãããšãã«
å·Šããæ°ããŠ<var>k</var>çªç®ã®Eaéã«ã¯ããã«èç©ãããŠãããšãã«ã®ãŒéã
kJåäœã§ç€ºãããã®ã§ããïŒ
</p>
<p>
ããã§ïŒ 0 ≤ <var>E</var><sub><var>k</var></sub> ≤ 4,
1 ≤ <var>L</var> ≤ 80 ã§ããããšãä¿èšŒãããŠããïŒ
</p>
<h2>Output</h2>
<p>
åºåã¯åããŒã¿ã»ããããšã«ïŒäžããããç¶æ³äžã§ã®å³ç«¯Eaéã«å°éå¯èœãª
æå€§ãšãã«ã®ãŒãkJåäœã§ïŒæŽæ°å€ã®ã¿ã1è¡ã§èšè¿°ããããšïŒ
</p>
<h2>Sample Input</h2>
<pre>
7
1
2
2
1 2
3
4 1 4
3
4 0 4
5
4 1 4 0 4
5
4 1 4 1 4
5
4 2 4 0 4
</pre>
<h2>Output for the Sample Input</h2>
<pre>
2
2
8
4
7
12
11
</pre>
|
p03214 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Niwango-kun is an employee of Dwango Co., Ltd.<br/>
One day, he is asked to generate a thumbnail from a video a user submitted.<br/>
To generate a thumbnail, he needs to select a frame of the video according to the following procedure:</p>
<ul>
<li>Get an integer <var>N</var> and <var>N</var> integers <var>a_0, a_1, ..., a_{N-1}</var> as inputs. <var>N</var> denotes the number of the frames of the video, and each <var>a_i</var> denotes the representation of the <var>i</var>-th frame of the video.</li>
<li>Select <var>t</var>-th frame whose representation <var>a_t</var> is nearest to the average of all frame representations.</li>
<li>If there are multiple such frames, select the frame with the smallest index.</li>
</ul>
<p>Find the index <var>t</var> of the frame he should select to generate a thumbnail.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq a_i \leq 100</var></li>
<li>All numbers given 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>
</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
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>1
</pre>
<p>Since the average of frame representations is <var>2</var>, Niwango-kun needs to select the index <var>1</var>, whose representation is <var>2</var>, that is, the nearest value to the average.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>4
2 5 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>0
</pre>
<p>The average of frame representations is <var>3.5</var>.<br/>
In this case, every frame has the same distance from its representation to the average.<br/>
Therefore, Niwango-kun should select index <var>0</var>, the smallest index among them.</p></section>
</div>
</span> |
p01803 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<!-- begin en only -->
<h3><u>Airport Codes</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>空枯ã³ãŒã</u></h3>
<!-- end ja only -->
<!-- end en only -->
<!-- begin ja only -->
<p>JAGçåœã§ã¯åœå
ã®ç©ºæž¯ã«ãããã空枯ã³ãŒããå²ãåœãŠãŠèå¥ãããŠããïŒ
</p>
<p>空枯ã³ãŒãã¯ïŒå°æåã®è±èªã¢ã«ãã¡ãããã§è¡šèšãã空枯ã®ååãããšã«ä»¥äžã®èŠåã§å²ãåœãŠããã:
</p><ol><li> ååã®æåã®æåãšïŒæ¯é³ (a,i,u,e,o) ã®çŽåŸã®æåãé ã«åãåºãïŒ
</li><li> åãåºããæååã <var>k</var> æåæªæºãªãããã空枯ã³ãŒããšãïŒ <var>k</var> æå以äžãªãïŒãã®åãåºããæååã®å
é <var>k</var> æåã空枯ã³ãŒããšããŠäœ¿ãïŒ
</li></ol>
<p>äŸãã° <var>k</var> = 3 ã®ãšãïŒhaneda ã«ã¯ hnd ïŒ oookayama ã«ã¯ ooo ïŒ tsu ã«ã¯ t ãšããã³ãŒããå²ãåœãŠãããïŒ
</p>
<p>ããããã®ã³ãŒãã®å²ãåœãŠæ¹ã§ã¯ïŒéãååã®ç©ºæž¯ã§ãåãã³ãŒããå²ãåœãŠãããããšãããïŒæ··ä¹±ãæããŠããŸãïŒ
空枯ã®ååã®äžèЧãäžããããã®ã§ïŒãã¹ãŠã®ç©ºæž¯ã®ã³ãŒããç°ãªãããã«ã§ãããå€å®ããŠïŒå¯èœãªå Žåã¯ãã¹ãŠã®ç©ºæž¯ã³ãŒããç°ãªãããã«ã§ããæå°ã® <var>k</var> ãæ±ãïŒäžå¯èœãªå Žåã¯ãã®æšãäŒããããã°ã©ã ãäœæããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯100å以äžã®ããŒã¿ã»ãããããªãïŒ
ããããã®ããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ
</p>
<blockquote><var>n</var><br><var>s</var><sub>1</sub><br>...<br><var>s<sub>n</sub></var></blockquote>
<p>1è¡ç®ã«ç©ºæž¯ã®æ° <var>n</var> (2 ≤ <var>n</var> ≤ 50) ãæŽæ°ã§äžãããïŒç¶ã <var>n</var> è¡ã«ã¯ãããã空枯ã®åå <var>s<sub>i</sub></var> ãæååã§äžããããïŒ
空枯ã®ååã¯'<samp>a</samp>'ãã'<samp>z</samp>'ã®å°æåã®è±èªã¢ã«ãã¡ãããã®ã¿ã§æ§æããïŒããããæåæ°ã¯1以äž50以äžã§ããïŒ
ãŸãïŒäžãããã空枯ã®ååã¯ãã¹ãŠç°ãªãïŒããªãã¡ïŒ1 ≤ <var>i</var> < <var>j</var> ≤ <var>n</var> ã®ãšã <var>s<sub>i</sub></var> ≠ <var>s<sub>j</sub></var> ãæºããïŒ
</p>
<p>å
¥åã®çµããã¯1ã€ã®ãŒãã ããããªãè¡ã§ç€ºãããïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>ããããã®ããŒã¿ã»ããã«ã€ããŠïŒãã¹ãŠã®ç©ºæž¯ã«çžç°ãªã空枯ã³ãŒããå²ãåœãŠããããšãã¯ïŒãã®ãããªæå°ã® <var>k</var> ã1è¡ã«åºåããïŒ
äžå¯èœãªå Žåã¯ïŒ-1ã1è¡ã«åºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0</pre>
<h3>Output for Sample Input</h3>
<pre>1
4
-1
3</pre>
|
p00711 |
<H1><font color="#000">Problem B:</font> Red and Black</H1>
<P>
There is a rectangular room, covered with square tiles. Each tile is
colored either red or black. A man is standing on a black tile.
From a tile, he can move to one of four adjacent tiles. But he can't
move on red tiles, he can move only on black tiles.
</P>
<P>
Write a program to count the number of black tiles which he can reach
by repeating the moves described above.
</P>
<H2>Input</H2>
<P>
The input consists of multiple data sets.
A data set starts with a line containing two positive integers <I>W</I> and <I>H</I>;
<I>W</I> and <I>H</I> are the numbers of tiles in the <I>x</I>-
and <I>y</I>- directions, respectively. <I>W</I> and <I>H</I> are
not more than 20.
</P>
<P>
There are <I>H</I> more lines in the data set, each of which
includes <I>W</I> characters. Each character represents the color of a
tile as follows.
</P>
<ul>
<li>'.' - a black tile
<li>'#' - a red tile
<li>'@' - a man on a black tile(appears exactly once in a data set)
</ul>
<p>
The end of the input is indicated by a line consisting of two zeros.
</p>
<H2>Output</H2>
<P>
For each data set, your program
should output a line which contains the number of
tiles he can reach from the initial tile (including itself).
</P>
<H2>Sample Input</H2>
<PRE>
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
</PRE>
<H2>Output for the Sample Input</H2>
<PRE>
45
59
6
13
</PRE>
|
p00341 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>æ£ã§äœãçŽæ¹äœ</H1>
<p>
ã¢ã€ã
æŸéåäŒã®æè²çªçµ(æè²)ã§ã¯ãåã©ãåãã®å·¥äœçªçµããããã§ã€ããããæŸéããŠããŸããä»åã¯æ£ã§ç®±ãäœãåã§ãããçšæããïŒïŒæ¬ã®æ£ã䜿ã£ãŠçŽæ¹äœãã§ãããã確ãããããšæããŸãããã ããæ£ã¯åã£ããæã£ããããŠã¯ãããŸããã
</p>
<br/>
<p>
ïŒïŒæ¬ã®æ£ã®é·ããäžããããã®ã§ãããããã¹ãŠã蟺ãšããçŽæ¹äœãäœãããã©ããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>e<sub>1</sub></var> <var>e<sub>2</sub></var> ... <var>e<sub>12</sub></var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªãã忣ã®é·ããè¡šãæŽæ° <var>e<sub>i</sub></var> (1 ≤ <var>e<sub>i</sub></var> ≤ 100) ãäžããããã
</p>
<h2>Output</h2>
<p>
çŽæ¹äœãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããç«æ¹äœã¯çŽæ¹äœã®äžçš®ãªã®ã§ãç«æ¹äœã®å Žåã§ããyesããšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1 1 3 4 8 9 7 3 4 5 5 5
</pre>
<h2>Sample Output 1</h2>
<pre>
no
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
1 1 2 2 3 1 2 3 3 3 1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
yes
</pre> |
p03994 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Mr. Takahashi has a string <var>s</var> consisting of lowercase English letters.
He repeats the following operation on <var>s</var> exactly <var>K</var> times.</p>
<ul>
<li>Choose an arbitrary letter on <var>s</var> and change that letter to the next alphabet. Note that the next letter of <code>z</code> is <code>a</code>.</li>
</ul>
<p>For example, if you perform an operation for the second letter on <code>aaz</code>, <code>aaz</code> becomes <code>abz</code>.
If you then perform an operation for the third letter on <code>abz</code>, <code>abz</code> becomes <code>aba</code>.</p>
<p>Mr. Takahashi wants to have the lexicographically smallest string after performing exactly <var>K</var> operations on <var>s</var>.
Find the such string.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€|s|â€10^5</var></li>
<li>All letters in <var>s</var> are lowercase English letters.</li>
<li><var>1â€Kâ€10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>s</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest string after performing exactly <var>K</var> operations on <var>s</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>xyz
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>aya
</pre>
<p>For example, you can perform the following operations: <code>xyz</code>, <code>yyz</code>, <code>zyz</code>, <code>ayz</code>, <code>aya</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>a
25
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>z
</pre>
<p>You have to perform exactly <var>K</var> operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>codefestival
100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>aaaafeaaivap
</pre></section>
</div>
</span> |
p02686 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A <strong>bracket sequence</strong> is a string that is one of the following:</p>
<ol>
<li>An empty string;</li>
<li>The concatenation of <code>(</code>, <var>A</var>, and <code>)</code> in this order, for some bracket sequence <var>A</var> ;</li>
<li>The concatenation of <var>A</var> and <var>B</var> in this order, for some non-empty bracket sequences <var>A</var> and <var>B</var> /</li>
</ol>
<p>Given are <var>N</var> strings <var>S_i</var>. Can a bracket sequence be formed by concatenating all the <var>N</var> strings in some order?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^6</var></li>
<li>The total length of the strings <var>S_i</var> is at most <var>10^6</var>.</li>
<li><var>S_i</var> is a non-empty string consisting 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_1</var>
<var>:</var>
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If a bracket sequence can be formed by concatenating all the <var>N</var> strings in some order, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
)
(()
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Concatenating <code>(()</code> and <code>)</code> in this order forms a bracket sequence.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
)(
()
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
((()))
((((((
))))))
()()()
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
(((
)
)
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> |
p01100 |
<h3>Gift Exchange Party</h3>
<p>
A gift exchange party will be held at a school in TKB City.
</p>
<p>
For every pair of students who are close friends, one gift must be given from one to the other at this party, but not the other way around.
It is decided in advance the gift directions, that is, which student of each pair receives a gift.
No other gift exchanges are made.
</p>
<p>
If each pair randomly decided the gift direction,
some might receive countless gifts, while some might receive only few or even none.
</p>
<p>
You'd like to decide the gift directions for all the friend pairs
that minimize the difference between the smallest and the largest numbers of gifts received by a student.
Find the smallest and the largest numbers of gifts received
when the difference between them is minimized.
When there is more than one way to realize that,
find the way that maximizes the smallest number of received gifts.
</p>
<h3>Input</h3>
<p>
The input consists of at most 10 datasets, each in the following format.
</p>
<p>
<i>n</i> <i>m</i><br>
<i>u</i><sub>1</sub> <i>v</i><sub>1</sub><br>
... <br>
<i>u<sub>m</sub></i> <i>v<sub>m</sub></i>
</p>
<p>
<i>n</i> is the number of students, and <i>m</i> is the number of friendship relations (2 ≤ <i>n</i> ≤ 100, 1 ≤ <i>m</i> ≤ <i>n</i> (<i>n</i>-1)/2).
Students are denoted by integers between 1 and <i>n</i>, inclusive.
The following <i>m</i> lines describe the friendship relations: for each <i>i</i>, student <i>u<sub>i</sub></i> and <i>v<sub>i</sub></i> are close friends (<i>u<sub>i</sub></i> < <i>v<sub>i</sub></i>).
The same friendship relations do not appear more than once.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<h3>Output</h3>
<p>
For each dataset, output a single line containing two integers <i>l</i> and <i>h</i> separated by a single space.
Here, <i>l</i> and <i>h</i> are the smallest and the largest numbers, respectively, of gifts received by a student.
</p>
<h3>Sample Input</h3>
<pre>
3 3
1 2
2 3
1 3
4 3
1 2
1 3
1 4
4 6
1 2
1 3
1 4
2 3
3 4
2 4
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1 1
0 1
1 2
</pre> |
p01550 |
<h1>åé¡å</h1>
<p>ä» <var>n</var> æã®æ°åãæžãããã«ãŒãããããŸãããããã®äžéšãŸãã¯å
šéšãé©åœã«äžŠã¹ãŠæ°åãäœãããšãèããŸãããã®æäœãããæ°åãå
šãŠè¶³ããæ°ãæ±ããŠäžããã
</p>
<p>äŸãã°ã 1 ãš 2 ããã£ãããäœãããæ°å㯠1, 2, 12, 21 ã® 4 ã€ãªã®ã§ãå
šãŠè¶³ããæ°ã¯ 36 ã«ãªããŸãã䞊ã¹ãçµæåãæ°åãåºæ¥ãŠãéãäžŠã¹æ¹ã ãšãããå¥ã
ã«è¶³ããŸããããšãã°ã 1 ãšããã«ãŒããš 11 ãšããã«ãŒãããã£ãã䞊ã¹ãŠ 111 ã«ãªãäžŠã¹æ¹ã2éããããŸããããããå¥ã®ãã®ãšããŠè¶³ãåãããŸããã«ãŒãã®äžã«ãªãŒãã£ã³ã°ãŒãã®ã«ãŒãã¯ãããŸãããããªãŒãã£ã³ã°ãŒãã«ãªãæ°åã¯èªããŸãããçãã1,000,000,007 ã§å²ã£ããã®ãåºåããŠãã ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ã以äžã®åœ¢ã§äžããããŸãã
</p><blockquote>
<var>n</var><br><var>a<sub>1</sub></var><br><var>a<sub>2</sub></var><br>...<br><var>a<sub>n</sub></var><br></blockquote>
<p>æåã® 1 è¡ã«ã¯ã«ãŒãã®ææ°ã衚ã <var>n</var>ïŒ<var>1 ≤ n ≤ 200</var>ïŒã次㮠<var>n</var> è¡ã«ã¯ããããã®ã«ãŒãã«æžãããŠããæ°å <var>a<sub>i</sub></var> (<var>0 ≤ a<sub>i</sub> < 10000</var>) ãæžãããŠããŸãããŸãè€æ°ã®ã«ãŒãã«åãæ°åãæžãããŠããããšã¯ãããŸããã
</p>
<h2>Output</h2>
<p>äœãããšã®åºæ¥ãå
šãŠã®æ°åã®åèšã 1,000,000,007 ã§å²ã£ããã®ã 1 è¡ã«åºåããªããã
</p>
<h2>Sample Input 1</h2>
<pre>2
1
2
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>36
</pre>
<p>ãµã³ãã«ã«ãã£ãäŸã§ãã
</p>
<h2>Sample Input 2</h2>
<pre>2
1
11
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>234
</pre>
<p>äœãããæ°å㯠1 ãš 11 ãšã 111 ã 2 éãäœãããã®ã§å
šãŠè¶³ã㊠234 ãšãªããŸãã
</p>
<h2>Sample Input 3</h2>
<pre>4
0
4
7
8
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>135299
</pre>
<p>04 ã 078 ãšãã£ãäžŠã¹æ¹ã¯èªããããªãããšã«æ³šæããŠãã ããã
</p> |
p03097 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given integers <var>N,\ A</var> and <var>B</var>.
Determine if there exists a permutation <var>(P_0,\ P_1,\ ...\ P_{2^N-1})</var> of <var>(0,\ 1,\ ...\ 2^N-1)</var> that satisfies all of the following conditions, and create one such permutation if it exists.</p>
<ul>
<li><var>P_0=A</var></li>
<li><var>P_{2^N-1}=B</var></li>
<li>For all <var>0 \leq i < 2^N-1</var>, the binary representations of <var>P_i</var> and <var>P_{i+1}</var> differ by exactly one bit.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 17</var></li>
<li><var>0 \leq A \leq 2^N-1</var></li>
<li><var>0 \leq B \leq 2^N-1</var></li>
<li><var>A \neq B</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there is no permutation that satisfies the conditions, print <code>NO</code>.</p>
<p>If there is such a permutation, print <code>YES</code> in the first line.
Then, print <var>(P_0,\ P_1,\ ...\ P_{2^N-1})</var> in the second line, with spaces in between.
If there are multiple solutions, any of them is accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
1 0 2 3
</pre>
<p>The binary representation of <var>P=(1,0,2,3)</var> is <var>(01,00,10,11)</var>, where any two adjacent elements differ by exactly one bit.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre></section>
</div>
</span> |
p03582 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a string <var>S</var>, let <var>f(S)</var> be the lexicographically smallest cyclic shift of <var>S</var>.
For example, if <var>S = </var><code>babca</code>, <var>f(S) = </var><code>ababc</code> because this is the smallest among all cyclic shifts (<code>babca</code>, <code>abcab</code>, <code>bcaba</code>, <code>cabab</code>, <code>ababc</code>).</p>
<p>You are given three integers <var>X, Y</var>, and <var>Z</var>.
You want to construct a string <var>T</var> that consists of exactly <var>X</var> <code>a</code>s, exactly <var>Y</var> <code>b</code>s, and exactly <var>Z</var> <code>c</code>s.
If there are multiple such strings, you want to choose one that maximizes <var>f(T)</var> lexicographically.</p>
<p>Compute the lexicographically largest possible value of <var>f(T)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X + Y + Z \leq 50</var></li>
<li><var>X, Y, Z</var> are non-negative integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var> <var>Z</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 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>abab
</pre>
<p><var>T</var> must consist of two <code>a</code>s and two <code>b</code>s.</p>
<ul>
<li>If <var>T = </var><code>aabb</code>, <var>f(T) = </var><code>aabb</code>.</li>
<li>If <var>T = </var><code>abab</code>, <var>f(T) = </var><code>abab</code>.</li>
<li>If <var>T = </var><code>abba</code>, <var>f(T) = </var><code>aabb</code>.</li>
<li>If <var>T = </var><code>baab</code>, <var>f(T) = </var><code>aabb</code>.</li>
<li>If <var>T = </var><code>baba</code>, <var>f(T) = </var><code>abab</code>.</li>
<li>If <var>T = </var><code>bbaa</code>, <var>f(T) = </var><code>aabb</code>.</li>
</ul>
<p>Thus, the largest possible <var>f(T)</var> is <code>abab</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>acb
</pre></section>
</div>
</span> |
p03078 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>The Patisserie AtCoder sells cakes with number-shaped candles.
There are <var>X</var>, <var>Y</var> and <var>Z</var> kinds of cakes with <var>1</var>-shaped, <var>2</var>-shaped and <var>3</var>-shaped candles, respectively.
Each cake has an integer value called <em>deliciousness</em>, as follows:</p>
<ul>
<li>The deliciousness of the cakes with <var>1</var>-shaped candles are <var>A_1, A_2, ..., A_X</var>.</li>
<li>The deliciousness of the cakes with <var>2</var>-shaped candles are <var>B_1, B_2, ..., B_Y</var>.</li>
<li>The deliciousness of the cakes with <var>3</var>-shaped candles are <var>C_1, C_2, ..., C_Z</var>.</li>
</ul>
<p>Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.<br/>
There are <var>X \times Y \times Z</var> such ways to choose three cakes.<br/>
We will arrange these <var>X \times Y \times Z</var> ways in descending order of the sum of the deliciousness of the cakes.<br/>
Print the sums of the deliciousness of the cakes for the first, second, <var>...</var>, <var>K</var>-th ways in this list.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq X \leq 1 \ 000</var></li>
<li><var>1 \leq Y \leq 1 \ 000</var></li>
<li><var>1 \leq Z \leq 1 \ 000</var></li>
<li><var>1 \leq K \leq \min(3 \ 000, X \times Y \times Z)</var></li>
<li><var>1 \leq A_i \leq 10 \ 000 \ 000 \ 000</var></li>
<li><var>1 \leq B_i \leq 10 \ 000 \ 000 \ 000</var></li>
<li><var>1 \leq C_i \leq 10 \ 000 \ 000 \ 000</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var> <var>Z</var> <var>K</var>
<var>A_1 \ A_2 \ A_3 \ ... \ A_X</var>
<var>B_1 \ B_2 \ B_3 \ ... \ B_Y</var>
<var>C_1 \ C_2 \ C_3 \ ... \ C_Z</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <var>K</var> lines. The <var>i</var>-th line should contain the <var>i</var>-th value stated in the problem statement.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 2 8
4 6
1 5
3 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>19
17
15
14
13
12
10
8
</pre>
<p>There are <var>2 \times 2 \times 2 = 8</var> ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:</p>
<ul>
<li><var>(A_2, B_2, C_2)</var>: <var>6 + 5 + 8 = 19</var></li>
<li><var>(A_1, B_2, C_2)</var>: <var>4 + 5 + 8 = 17</var></li>
<li><var>(A_2, B_1, C_2)</var>: <var>6 + 1 + 8 = 15</var></li>
<li><var>(A_2, B_2, C_1)</var>: <var>6 + 5 + 3 = 14</var></li>
<li><var>(A_1, B_1, C_2)</var>: <var>4 + 1 + 8 = 13</var></li>
<li><var>(A_1, B_2, C_1)</var>: <var>4 + 5 + 3 = 12</var></li>
<li><var>(A_2, B_1, C_1)</var>: <var>6 + 1 + 3 = 10</var></li>
<li><var>(A_1, B_1, C_1)</var>: <var>4 + 1 + 3 = 8</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 3 5
1 10 100
2 20 200
1 10 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>400
310
310
301
301
</pre>
<p>There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of <var>A_1, B_3, C_3</var> and the sum of <var>A_3, B_3, C_1</var> are both <var>301</var>.
However, they are different ways of choosing cakes, so <var>301</var> occurs twice in the output.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10 10 20
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>23379871545
22444657051
22302177772
22095691512
21667941469
21366963278
21287912315
21279176669
21160477018
21085311041
21059876163
21017997739
20703329561
20702387965
20590247696
20383761436
20343962175
20254073196
20210218542
20150096547
</pre>
<p>Note that the input or output may not fit into a <var>32</var>-bit integer type.</p></section>
</div>
</span> |
p01045 |
<h1>Problem I: Hopping Mind</h1>
<h2>Problem</h2>
<p>
ããšããšã«ã«ãªã¯åãå«è¶åºã§åãå§åйã§ããã2人ã¯ãšãŠã仲ãè¯ããããæ¥ããšããããŒãã«ã²ãŒã ã§éã¶ããšã«ãªã£ãã
</p>
<p>
ã²ãŒã ã¯<var>R</var>ãã¹×<var>C</var>ãã¹ã®ç€é¢ãšãé§ãšããŠãããã®TPãçšãããç€é¢ã®åãã¹ã¯çœãé»ã®è²ãå¡ãããŠãããæåã«TPãç€é¢ã®å³äž(<var>R</var>,<var>C</var>)ã«ããã2äººã§æ¬¡ã®è¡åã亀äºã«è¡ããTPã®çŸåšã®äœçœ®ã(<var>a</var>,<var>b</var>)ãšãããšããããããžã£ã³ãå¯èœãªäœçœ®(<var>i</var>,<var>j</var>)ã1ã€éžã³ãTPãããã«ãžã£ã³ãããããTPããžã£ã³ãå¯èœãªäœçœ®(<var>i</var>,<var>j</var>)ã¯ä»¥äžããã¹ãŠæºããã
</p>
<ol>
<li>
1 ≤ <var>i</var> ≤ <var>R</var> ã〠1 ≤ <var>j</var> ≤ <var>C</var> ã〠<var>i</var> ≤ <var>a</var> ã〠<var>j</var> ≤ <var>b</var> ã〠1 ≤ (<var>a</var>-<var>i</var>) + (<var>b</var>-<var>j</var>) ≤ <var>K</var>
</li>
<li>
(<var>i</var>,<var>j</var>)ã¯çœããã¹ã§ãã
</li>
</ol>
<p>
èªåã®ã¿ãŒã³ã«TPããžã£ã³ããããããšãã§ããªããªã£ãå Žåãè² ããšãªãã
</p>
<p>
ããšããå
æãã«ã«ãªãåŸæã§ãã®ã²ãŒã ãè¡ããã«ã«ãªã¯é ã®äžã§ã²ãŒã ãæåŸãŸã§å
èªã¿ããããšãã§ããåžžã«æé©ãªè¡åããšãããã®æãããšããåã€æ¹æ³ãååšãããã©ãããå€å®ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>R</var> <var>C</var> <var>K</var>
<var>G<sub>1,1</sub></var> <var>G<sub>1,2</sub></var> ... <var>G<sub>1,C</sub></var>
<var>G<sub>2,1</sub></var> <var>G<sub>2,2</sub></var> ... <var>G<sub>2,C</sub></var>
:
<var>G<sub>R,1</sub></var> <var>G<sub>R,2</sub></var> ... <var>G<sub>R,C</sub></var>
</pre>
<p>
1è¡ç®ã«3ã€ã®æŽæ°<var>R</var>,<var>C</var>,<var>K</var>ã空çœåºåãã§äžãããããæ¬¡ã®<var>R</var>è¡ã«ç€é¢ã®æ
å ±ãšããŠ<var>C</var>åã®".âãŸãã¯"#âãäžããããã<var>G<sub>i,j</sub></var>ã¯ç€é¢ã®äœçœ®(<var>i</var>,<var>j</var>)ã®è²ã衚ããâ.âãçœã"#âãé»ã衚ãã
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>R</var>,<var>C</var> ≤ 1000</li>
<li>1 ≤ <var>K</var> ≤ 2000</li>
<li><var>G<sub>R,C</sub></var>ã¯â.âã§ãã</li>
</ul>
<h2>Output</h2>
<p>
ããšããåã€æ¹æ³ãååšããå Žåã¯âChienoâããååšããªãå Žåã¯âCacaoâã1è¡ã«åºåããã
</p>
<h2>Sample Input1</h2>
<pre>
3 3 2
...
...
...
</pre>
<h2>Sample Output1</h2>
<pre>
Chieno
</pre>
<h2>Sample Input2</h2>
<pre>
3 3 2
#.#
.#.
#..
</pre>
<h2>Sample Output2</h2>
<pre>
Cacao
</pre>
|
p03428 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> holes in a two-dimensional plane. The coordinates of the <var>i</var>-th hole are <var>(x_i,y_i)</var>.</p>
<p>Let <var>R=10^{10^{10^{10}}}</var>. Ringo performs the following operation:</p>
<ul>
<li>Randomly choose a point from the interior of a circle of radius <var>R</var> centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.</li>
</ul>
<p>For every <var>i</var> <var>(1 \leq i \leq N)</var>, find the probability that Snuke falls into the <var>i</var>-th hole.</p>
<p>Here, the operation of randomly choosing a point from the interior of a circle of radius <var>R</var> is defined as follows:</p>
<ul>
<li>Pick two real numbers <var>x</var> and <var>y</var> independently according to uniform distribution on <var>[-R,R]</var>.</li>
<li>If <var>x^2+y^2\leq R^2</var>, the point <var>(x,y)</var> is chosen. Otherwise, repeat picking the real numbers <var>x,y</var> until the condition is met.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100</var></li>
<li><var>|x_i|,|y_i| \leq 10^6(1\leq i\leq N)</var></li>
<li>All given points are pairwise distinct.</li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> real numbers. The <var>i</var>-th real number must represent the probability that Snuke falls into the <var>i</var>-th hole.</p>
<p>The output will be judged correct when, for all output values, the absolute or relative error is at most <var>10^{-5}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0 0
1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0.5
0.5
</pre>
<p>If Ringo put Snuke in the region <var>x+y\leq 1</var>, Snuke will fall into the first hole. The probability of this happening is very close to <var>0.5</var>.
Otherwise, Snuke will fall into the second hole, the probability of which happening is also very close to <var>0.5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 0
2 8
4 5
2 6
3 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0.43160120892732328768
0.03480224363653196956
0.13880483535586193855
0.00000000000000000000
0.39479171208028279727
</pre></section>
</div>
</span> |
p01415 |
<H1>I: Starting Line</H1>
<p>
ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ
</p>
<p>
仿¥ã®ä¿®è¡ã¯ïŒäžçŽç·äžã®éãèµ°ã£ãŠïŒäœåãšå€æåãé€ãããšãããã®ã§ããïŒãããã¯ä»ïŒã¹ã¿ãŒãã©ã€ã³ã«ç«ã£ãŠé·ãé·ãéãèŠæž¡ããŠããïŒ
</p>
<p>
éã®éäžã«ã¯ããã€ããã³ãžã³ã眮ãããŠããïŒãããã¯ãã³ãžã³ãé£ã¹ããšå éããããšãã§ããïŒå éããŠããªããšãã®ãããã®èµ°ãéãã¯æ¯ç§ <i>U</i> ã¡ãŒãã«ã§ãããïŒãã³ãžã³ãé£ã¹ãããšã§ïŒæåŸã®ãã³ãžã³ãé£ã¹ãŠãã <i>T</i> ç§åŸãŸã§ã¯éããæ¯ç§ <i>V</i> ã¡ãŒãã«ãšãªãïŒãŸãïŒãããã¯ãã³ãžã³ã <i>K</i> åãŸã§é£ã¹ãã«æã£ãŠããããšãã§ããïŒãã³ãžã³ãæã£ãŠããŠãèµ°ãéãã¯å€ãããªãïŒ
</p>
<p>
ãã³ãžã³ãæã£ããé£ã¹ããããã®ã«æéã¯ããããªããšããŠïŒãŽãŒã«ãŸã§ã®æçæèŠæéãæ±ãããïŒ
</p>
<H2>Input</H2>
<pre>
<i>N</i> <i>K</i> <i>T</i> <i>U</i> <i>V</i> <i>L</i>
<i>D</i><sub>1</sub>
...
<i>D</i><sub><i>N</i></sub>
</pre>
<p>
<i>N</i> ã¯ãã³ãžã³ã®åæ°ïŒ<i>L</i> ã¯ã¹ã¿ãŒããããŽãŒã«ãŸã§ã®è·é¢ (ã¡ãŒãã«)ïŒ<i>D</i><sub><i>i</i></sub> (1 ≤ <i>i</i> ≤ <i>N</i>) 㯠<i>i</i> çªç®ã®ãã³ãžã³ã眮ãããŠããå Žæã®ã¹ã¿ãŒãããã®è·é¢ (ã¡ãŒãã«) ã§ããïŒ
</p>
<p>
1 ≤ <i>N</i> ≤ 200ïŒ1 ≤ <i>K</i> ≤ <i>N</i>ïŒ1 ≤ <i>T</i> ≤ 10,000ïŒ1 ≤ <i>U</i> < <i>V</i> ≤ 10,000ïŒ2 ≤ <i>L</i> ≤ 10,000ïŒ0 < <i>D</i><sub>1</sub> < <i>D</i><sub>2</sub> < ... < <i>D</i><sub><i>N</i></sub> < <i>L</i> ãæºããïŒå
¥åã®å€ã¯ãã¹ãп޿°ã§ããïŒ
</p>
<H2>Output</H2>
<p>
æçæèŠæé (ç§) ã 1 è¡ã«åºåããïŒ10<sup>-6</sup> 以äžã®çµ¶å¯Ÿèª€å·®ã蚱容ãããïŒ
</p>
<H2>Sample Input 1</H2>
<pre>
1 1 1 2 3 100
50
</pre>
<H2>Sample Output 1</H2>
<pre>
49.500000000
</pre>
<H2>Sample Input 2</H2>
<pre>
3 1 1 2 3 100
49
50
51
</pre>
<H2>Sample Output 2</H2>
<pre>
48.666666667
</pre> |
p02393 |
<H1>Sorting Three Numbers</H1>
<p>
Write a program which reads three integers, and prints them in ascending order.
</p>
<H2>Input</H2>
<p>
Three integers separated by a single space are given in a line.
</p>
<H2>Output</H2>
<p>
Print the given integers in ascending order in a line. Put a single space between two integers.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ the three integers ≤ 10000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3 8 1
</pre>
<H2>Sample Output 1</H2>
<pre>
1 3 8
</pre> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.