question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p02478 | <a href="https://onlinejudge.u-aizu.ac.jp/resources/icpcooc2018/practice/C.pdf" target='_blank'>Problem is available from here.</a> |
p00150 |
<H1>Twin Prime</H1>
<p>
Prime numbers are widely applied for cryptographic and communication technology.
A twin prime is a prime number that differs from another prime number by 2.
For example, (5, 7) and (11, 13) are twin prime pairs.
</p>
<p>
In this problem, we call the greater number of a twin prime "size of the twin prime."
</p>
<p>
Your task is to create a program which reads an integer <i>n</i> and prints a twin prime which has the maximum size among twin primes less than or equals to <i>n</i>
</p>
<p>
You may assume that 5 ≤ <i>n</i> ≤ 10000.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset is formatted as follows:
</p>
<pre>
<i>n</i> (integer)
</pre>
<H2>Output</H2>
<p>
For each dataset, print the twin prime <i>p</i> and <i>q</i> (<i>p</i> < <i>q</i>). <i>p</i> and <i>q</i> should be separated by a single space.
</p>
<H2>Sample Input</H2>
<pre>
12
100
200
300
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5 7
71 73
197 199
281 283
</pre> |
p00500 |
<H1>æ°åœãŠã²ãŒã (Unique number) </H1>
<br/>
<h2> åé¡</h2>
<p>
JOI åã¯åéãšã²ãŒã ãããããšã«ããïŒãã®ã²ãŒã ã«ã¯ N 人ã®ãã¬ã€ã€ãŒãåå ããïŒ1 åã®ã²ãŒã ã®ã«ãŒã«ã¯æ¬¡ã®ãããªãã®ã§ããïŒ
</p>
<p>
ããããã®ãã¬ã€ã€ãŒã¯ 1 ä»¥äž 100 以äžã®å¥œããªæŽæ°ãã«ãŒãã«æžããŠæåºããïŒåãã¬ã€ã€ãŒã¯ïŒèªåãšåãæ°ãæžãã人ãä»ã«ããªãã£ãå ŽåïŒèªåã®æžããæ°ãšåãåŸç¹ãåŸãïŒèªåãšåãæ°ãæžãã人ãä»ã«ããå Žåã¯åŸç¹ãåŸãããªãïŒ
</p>
<p>
JOI åãã¡ã¯ãã®ã²ãŒã ã 3 åè¡ã£ãïŒåãã¬ã€ã€ãŒã 3 åã®ã²ãŒã ã«ãããŠæžããæ°ãäžãããããšãïŒåãã¬ã€ã€ãŒã 3 åã®ã²ãŒã ã§åŸãåèšåŸç¹ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥å㯠1 + N è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯æŽæ° N (2 ⊠N ⊠200) ãæžãããŠããïŒãã¬ã€ã€ãŒã®äººæ°ã衚ãïŒ
</p>
<p>
ç¶ã N è¡ã®ãã¡ã® i è¡ç® (1 ⊠i ⊠N) ã«ã¯ 3 ã€ã® 1 ä»¥äž 100 以äžã®æŽæ°ã空çœãåºåããšããŠæžãããŠããïŒãããã i 人ç®ã®ãã¬ã€ã€ãŒã 1 åç®ïŒ2 åç®ïŒ3 åç®ã®ã²ãŒã ã§æžããæ°ã衚ãïŒ
</p>
<h2> åºå</h2>
<p>
åºå㯠N è¡ãããªãïŒ
</p>
<p>
i è¡ç® (1 ⊠i ⊠N) ã«ã¯ i 人ç®ã®ãã¬ã€ã€ãŒã 3 åã®ã²ãŒã ã§åŸãåèšåŸç¹ãè¡šãæŽæ°ãåºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5
100 99 98
100 97 92
63 89 63
99 99 99
89 97 98
</pre>
<h3>åºåäŸ 1</h3>
<pre>
0
92
215
198
89
</pre>
<p>
å
¥åäŸ 1 ã§ã¯ïŒåãã¬ã€ã€ãŒã 3 åã®ã²ãŒã ã§åŸãåŸç¹ã®è©³çŽ°ã¯æ¬¡ã®ããã«ãªãïŒ
</p>
<table style="margin-left: 50px; margin-right: 50px;" class="withborder">
<tr><td>ãã¬ã€ã€ãŒ 1ïŒ 0 + 0 + 0 = 0</td></tr>
<tr><td>ãã¬ã€ã€ãŒ 2ïŒ 0 + 0 + 92 = 92</td></tr>
<tr><td>ãã¬ã€ã€ãŒ 3ïŒ 63 + 89 + 63 = 215</td></tr>
<tr><td>ãã¬ã€ã€ãŒ 4ïŒ 99 + 0 + 99 = 198</td></tr>
<tr><td>ãã¬ã€ã€ãŒ 5ïŒ 89 + 0 + 0 = 89</td></tr>
</table>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
3
89 92 77
89 92 63
89 63 77
</pre>
<h3>åºåäŸ 2</h3>
<pre>
0
63
63
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p01741 |
<p>
ãã³ããã¿ã³ã§ã¯ïŒéè·¯ãx 座æšãŸãã¯y 座æšãæŽæ°ã®ãšããã«éã£ãŠããïŒãã¬ãåã®å®¶ãšãããåã®å®¶ã¯ã©ã¡ããéè·¯äžã«ããïŒçŽç·è·é¢(ãŠãŒã¯ãªããè·é¢) ã¯ã¡ããã© <var>d</var> ã§ããïŒãã¬ãåã®å®¶ãããããåã®å®¶ãŸã§éè·¯ã«æ²¿ã£ãŠç§»åãããšãã®æçè·é¢ãšããŠèããããæå€§å€ãæ±ããïŒ
</p>
<h2>Constraints</h2>
<ul>
<li> 0 < <var>d</var> ≤ 10</li>
<li><var>d</var> ã¯å°æ°ç¹ä»¥äžã¡ããã©äžæ¡ãŸã§äžãããã</li>
</ul>
<h2>Input</h2>
<pre>
<var>d</var>
</pre>
<h2>Output</h2>
<p>
çããäžè¡ã«åºåããïŒçµ¶å¯Ÿèª€å·®ãŸãã¯çžå¯Ÿèª€å·®ã <var>10<sup>−9</sup></var> 以äžã®ãšãæ£çãšå€å®ãããïŒ
</p>
<h2>Sample Input 1</h2>
<pre>
1.000
</pre>
<h2>Sample Output 1</h2>
<pre>
2.000000000000
</pre>
<h2>Sample Input 2</h2>
<pre>
2.345
</pre>
<h2>Sample Output 2</h2>
<pre>
3.316330803765
</pre>
|
p00853 |
<H1><font color="#000">Problem I:</font> Enjoyable Commutation</H1>
<p>
Isaac is tired of his daily trip to his ofice, using the same shortest route everyday. Although this saves his time, he must see the same scenery again and again. He cannot stand such a boring commutation any more.
</p>
<p>
One day, he decided to improve the situation. He would change his route everyday at least slightly. His new scheme is as follows. On the first day, he uses the shortest route. On the second day, he uses the second shortest route, namely the shortest except one used on the first day. In general, on the <i>k</i>-th day, the <i>k</i>-th shortest route is chosen. Visiting the same place twice on a route should be avoided, of course.
</p>
<p>
You are invited to help Isaac, by writing a program which finds his route on the <i>k</i>-th day. The problem is easily modeled using terms in the graph theory. Your program should find the <i>k</i>-th shortest path in the given directed graph.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<pre>
<i>n m k a b</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>d</i><sub>1</sub>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>d</i><sub>2</sub>
...
<i>x</i><sub><i>m</i></sub> <i>y</i><sub><i>m</i></sub> <i>d</i><sub><i>m</i></sub>
</pre>
<p>
Every input item in a dataset is a non-negative integer. Two or more input items in a line are separated by a space.
</p>
<p>
<i>n</i> is the number of nodes in the graph. You can assume the inequality 2 ≤ <i>n</i> ≤ 50. <i>m</i> is the number of (directed) edges. <i>a</i> is the start node, and <i>b</i> is the goal node. They are between 1 and <i>n</i>, inclusive. You are required to find the <i>k</i>-th shortest path from <i>a</i> to <i>b</i>. You can assume 1 ≤ <i>k</i> ≤ 200 and <i>a</i> ≠ <i>b</i>.
</p>
<p>
The <i>i</i>-th edge is from the node <i>x<sub>i</sub></i> to <i>y<sub>i</sub></i> with the length <i>d<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>m</i>). Both <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> are between 1 and <i>n</i>, inclusive. <i>d<sub>i</sub></i> is between 1 and 10000, inclusive. You can directly go from <i>x<sub>i</sub></i> to <i>y<sub>i</sub></i>, but not from <i>y<sub>i</sub></i> to <i>x<sub>i</sub></i> unless an edge from <i>y<sub>i</sub></i> to <i>x<sub>i</sub></i> is explicitly given. The edge connecting the same pair of nodes is unique, if any, that is, if <i>i</i> ≠ <i>j</i>, it is never the case that <i>x<sub>i</sub></i> equals <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> equals <i>y<sub>j</sub></i>. Edges are not connecting a node to itself, that is, <i>x<sub>i</sub></i> never equals <i>y<sub>i</sub></i> . Thus the inequality 0 ≤ <i>m</i> ≤ <i>n</i>(<i>n</i> - 1) holds.
</p>
<p>
Note that the given graph may be quite unrealistic as a road network. Both the cases <i>m</i> = 0 and <i>m</i> = <i>n</i>(<i>n</i> - 1) are included in the judges' data.
</p>
<p>
The last dataset is followed by a line containing five zeros (separated by a space).
</p>
<H2>Output</H2>
<p>
For each dataset in the input, one line should be output as specified below. An output line should not contain extra characters such as spaces.
</p>
<p>
If the number of distinct paths from <i>a</i> to <i>b</i> is less than <i>k</i>, the string <span>None</span> should be printed. Note that the first letter of <span>None</span> is in uppercase, while the other letters are in lowercase.
</p>
<p>
If the number of distinct paths from <i>a</i> to <i>b</i> is <i>k</i> or more, the node numbers visited in the <i>k</i>-th shortest path should be printed in the visited order, separated by a hyphen (minus sign). Note that <i>a</i> must be the first, and <i>b</i> must be the last in the printed line.
</p>
<p>
In this problem the term <i>shorter</i> (thus <i>shortest</i> also) has a special meaning. A path <i>P</i> is defined to be shorter than <i>Q</i>, if and only if one of the following conditions holds.
</p>
<ol>
<li> The length of <i>P</i> is less than the length of <i>Q</i>. The length of a path is defined to be the sum of lengths of edges on the path.</li>
<li> The length of <i>P</i> is equal to the length of <i>Q</i>, and <i>P</i>'s sequence of node numbers comes earlier than <i>Q</i>'s in the dictionary order. Let's specify the latter condition more precisely. Denote <i>P</i>'s sequence of node numbers by <i>p</i><sub>1</sub>, <i>p</i><sub>2</sub>,..., <i>p<sub>s</sub></i>, and <i>Q</i>'s by <i>q</i><sub>1</sub>, <i>q</i><sub>2</sub>,..., <i>q<sub>t</sub></i>. <i>p</i><sub>1</sub> = <i>q</i><sub>1</sub> = <i>a</i> and <i>p<sub>s</sub></i> = <i>q<sub>t</sub></i> = <i>b</i> should be observed. The sequence <i>P</i> comes earlier than <i>Q</i> in the dictionary order, if for some <i>r</i> (1 ≤ <i>r</i> ≤ <i>s</i> and <i>r</i> ≤ <i>t</i>), <i>p</i><sub>1</sub> = <i>q</i><sub>1</sub>,..., <i>p</i><sub><i>r</i>-1</sub> = <i>q</i><sub><i>r</i>-1</sub>, and <i>p<sub>r</sub></i> < <i>q<sub>r</sub></i> (<i>p<sub>r</sub></i> is numerically smaller than <i>q<sub>r</sub></i>).
</ol>
<p>
A path visiting the same node twice or more is not allowed.
</p>
<H2>Sample Input</H2>
<pre>
5 20 10 1 5
1 2 1
1 3 2
1 4 1
1 5 3
2 1 1
2 3 1
2 4 2
2 5 2
3 1 1
3 2 2
3 4 1
3 5 1
4 1 1
4 2 1
4 3 1
4 5 2
5 1 1
5 2 1
5 3 1
5 4 1
4 6 1 1 4
2 4 2
1 3 2
1 2 1
1 4 3
2 3 1
3 4 1
3 3 5 1 3
1 2 1
2 3 1
1 3 1
0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1-2-4-3-5
1-2-3-4
None
</pre>
<p>
In the case of the first dataset, there are 16 paths from the node 1 to 5. They are ordered as follows (The number in parentheses is the length of the path).
</p>
<pre>
1 (3) 1-2-3-5 9 (5) 1-2-3-4-5
2 (3) 1-2-5 10 (5) 1-2-4-3-5
3 (3) 1-3-5 11 (5) 1-2-4-5
4 (3) 1-4-3-5 12 (5) 1-3-4-5
5 (3) 1-4-5 13 (6) 1-3-2-5
6 (3) 1-5 14 (6) 1-3-4-2-5
7 (4) 1-4-2-3-5 15 (6) 1-4-3-2-5
8 (4) 1-4-2-5 16 (8) 1-3-2-4-5
</pre>
|
p03286 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an integer <var>N</var>, find the base <var>-2</var> representation of <var>N</var>.</p>
<p>Here, <var>S</var> is the base <var>-2</var> representation of <var>N</var> when the following are all satisfied:</p>
<ul>
<li><var>S</var> is a string consisting of <code>0</code> and <code>1</code>.</li>
<li>Unless <var>S =</var> <code>0</code>, the initial character of <var>S</var> is <code>1</code>.</li>
<li>Let <var>S = S_k S_{k-1} ... S_0</var>, then <var>S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N</var>.</li>
</ul>
<p>It can be proved that, for any integer <var>M</var>, the base <var>-2</var> representation of <var>M</var> is uniquely determined.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>Every value in input is integer.</li>
<li><var>-10^9 \leq N \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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the base <var>-2</var> representation of <var>N</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>-9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1011
</pre>
<p>As <var>(-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9</var>, <code>1011</code> is the base <var>-2</var> representation of <var>-9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>123456789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11000101011001101110100010101
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01311 |
<h1><font color="#000">Problem I:</font> å€ãžã®æ</h1>
<p>ãªã€ãã¯å€§ã®ãã奜ãã§ããããªã€ãã®å®¶ã§ã¯ãã£ãšããã飌ã£ãŠãããããã奜ããªãªã€ãã¯ãã€ãéè¯ãããšéãã§ãããããããä»åãªã€ãã¯æ±ºå¿ããèªåã®å®¶ã§ãããäžå¹é£Œãããšã«ããããªã€ãã¯ãããå®¶ã«è¿ããã¬ãã³ãšåä»ããŠãããããå§ããã</p>
<p>ãªã€ãã®å®¶ã¯ããããã®éšå±ãšãããããã€ãªãããããã®æãããªã£ãŠãããæã¯æ¬¡ã®2çš®é¡ãããã</p>
<dl>
<dt>人éçšã®æ®éã®æ</dt>
<dd>ãªã€ãã¯éããããšãã§ããããã¬ãã³ãèªåã§éããããšã¯ã§ããªãããªã€ããšã¬ãã³ã®äž¡æ¹ãéãããšãã§ãããäžåºŠéããã°ããã®åŸã¯éãããŸãŸã«ããŠãããã</dd>
<dt>ããçšã®å°ããªæ</dt>
<dd>ã¬ãã³ãèªåã§ãããŠèªç±ã«éãããšãã§ããããã ãå°ããããã«ããªã€ããéãããšã¯ã§ããªãã</dd>
</dl>
<p>ã¬ãã³ã¯å€ã倧奜ãã§ãããã ãããå¬ã«ãªãå®¶ã®å€ããŸã£ãããªéªã§èŠãããŠããŸãé ã«ãªããšãåœŒã®æ©å«ã¯ãšãŠãæªããªã£ãŠããŸã£ãããããã圌ã¯å®¶ã«ãããããããã¢ã®ãã¡ãããã²ãšã€ã®æããå€ããžãšã€ãªãã£ãŠãããšä¿¡ããŠããããã ã£ãããªã€ãã¯ãã®æããå€ãžã®æããšåŒãã§ããããããŠãå¯ããŠäžæ©å«ã«ãªã£ãŠãããšãã¬ãã³ã¯ããŸã£ãŠãã®æã®åãããžè¡ããããã®ã§ããã</p>
<p>å¬ã®ããæ¥ãã¬ãã³ããŸããå€ãžã®æãã®å¥¥ãžè¡ãããšæãç«ã£ããããããã¬ãã³ãã²ãšãã§æãéããŠãå€ãžã®æã®å¥¥ãžè¡ãããšã¯éããªãããã®æã¯ãã¡ããããªã€ãã¯ã¬ãã³ã®æäŒããããªããã°ãªããªããã€ãŸãããªã€ãããéããããšã®åºæ¥ãªãæãããã€ãéããŠãã¬ãã³ããå€ãžã®æãã®åããåŽãžè¡ããããã«ããŠãããã®ã ã</p>
<p>æåãå®¶ã®äžã®å
šãŠã®æã¯éãŸã£ãŠãããå®¶ã®éšå±ã®æ¥ç¶é¢ä¿ããªã€ãããã³ã¬ãã³ã®åæäœçœ®ãäžããããããªã€ããšã¬ãã³ãæé©ãªæŠç¥ããšã£ãæãã¬ãã³ããå€ãžã®æãã®å
ãžããããã«<strong>ãªã€ããéããªããã°ãªããªãæ</strong>ã®æå°æ°ãèšç®ããªããã</p>
<p>以äžã®å³ã¯ããµã³ãã«å
¥åã®äŸãå³ç€ºãããã®ã§ããã</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_summer" alt="ãµã³ãã«å
¥åã®1çªç®" >
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_summer2" alt="ãµã³ãã«å
¥åã®2çªç®" >
<br>
å³: ãµã³ãã«å
¥åã®åæç¶æ
</center>
<h2>Input</h2>
<p>
å
¥åã®1è¡ç®ã«ã¯ãéšå±ã®æ° <var>n</var> ãšæã®æ° <var>m</var> ã1ã€ã®ç©ºçœæåã§åºåã£ãŠäžãããããéšå±ã«ã¯ãããã 0 ãã <var>n</var> ã®çªå·ãå²ãæ¯ãããŠããã0ã¯ãå€ãžã®æãã®å
ãããããã2è¡ç®ã¯ãªã€ããæåã«ããéšå±ã®çªå·ãšã¬ãã³ãæåã«ããéšå±ã®çªå·ãã1ã€ã®ç©ºçœæåã§åºåã£ãŠäžãããããã©ã¡ãã®éšå±çªå·ã1以äžã§ãããæåãããå€ãžã®æãã®å
ã«ããããšã¯ãªããç¶ã <var>m</var> è¡ã«ã¯ã<var>m</var> æã®æã®æ
å ±ããããã1è¡ãã€äžãããããåè¡ã¯ãµãã€ã®éšå±IDãšæã®çš®é¡ã衚ã1æåã®ã¢ã«ãã¡ããããããªãã1ã€ã®ç©ºçœæåã§åºåãããŠãããæã¯æå®ããããµãã€ã®éšå±ãç¹ãã§ãããçš®é¡ã¯ã¢ã«ãã¡ãããã <code>N</code> ã®ãšã人éçšã®æ®éã®æã<code>L</code> ã®ãšãããçšã®å°ããªæã§ãããæãåãéšå±å士ãç¹ãããšã¯ãªããéšå±IDã0ã®ãã®ãå«ãæããå€ãžã®æãã§ãããããã¯å
¥åäžã«å¿
ããã 1ã€ååšããã1 <= n, m <= 100000ãæºããã
<h2>Output</h2>
<p>
ãªã€ããéããªããã°ãªããªãæã®æå°æ°ãã1è¡ã§åºåããã
</p>
<h2>Notes on Submission</h2>
<p>
äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã
</p>
<h2>Sample Input</h2>
<pre>
2
4 6
1 2
1 2 N
2 3 N
3 4 N
4 1 N
1 4 L
4 0 L
4 6
1 2
1 2 N
2 3 N
3 4 N
4 1 N
1 4 L
4 0 N
</pre>
<h2>Output for the Sample Input</h2>
<pre>
1
3
</pre>
|
p03906 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The currency used in Takahashi Kingdom is <em>Myon</em>.
There are <var>1</var>-, <var>10</var>-, <var>100</var>-, <var>1000</var>- and <var>10000</var>-Myon coins, and so forth. Formally, there are <var>10^n</var>-Myon coins for any non-negative integer <var>n</var>.</p>
<p>There are <var>N</var> items being sold at Ex Store.
The price of the <var>i</var>-th <var>(1âŠiâŠN)</var> item is <var>A_i</var> Myon.</p>
<p>Takahashi is going to buy some, at least one, possibly all, of these <var>N</var> items.
He hates receiving change, so he wants to bring coins to the store so that he can pay the total price without receiving change, no matter what items he chooses to buy.
Also, since coins are heavy, he wants to bring as few coins as possible.</p>
<p>Find the minimum number of coins he must bring to the store. It can be assumed that he has an infinite supply of coins.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ20,000</var></li>
<li><var>1âŠA_iâŠ10^{12}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of coins Takahashi must bring to the store, so that he can pay the total price without receiving change, no matter what items he chooses to buy.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
43 24 37
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>16
</pre>
<p>There are seven possible total prices: <var>24, 37, 43, 61, 67, 80,</var> and <var>104</var>.
With seven <var>1</var>-Myon coins, eight <var>10</var>-Myon coins and one <var>100</var>-Myon coin, Takahashi can pay any of these without receiving change.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
49735011221 970534221705 411566391637 760836201000 563515091165
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>105
</pre></section>
</div>
</span> |
p02614 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid of <var>H</var> rows and <var>W</var> columns of squares. The color of the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left <var>(1 \leq i \leq H, 1 \leq j \leq W)</var> is given to you as a character <var>c_{i,j}</var>: the square is white if <var>c_{i,j}</var> is <code>.</code>, and black if <var>c_{i,j}</var> is <code>#</code>.</p>
<p>Consider doing the following operation:</p>
<ul>
<li>Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.</li>
</ul>
<p>You are given a positive integer <var>K</var>. How many choices of rows and columns result in exactly <var>K</var> black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H, W \leq 6</var></li>
<li><var>1 \leq K \leq HW</var></li>
<li><var>c_{i,j}</var> is <code>.</code> or <code>#</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>K</var>
<var>c_{1,1}c_{1,2}...c_{1,W}</var>
<var>c_{2,1}c_{2,2}...c_{2,W}</var>
<var>:</var>
<var>c_{H,1}c_{H,2}...c_{H,W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the number of choices of rows and columns satisfying the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 2
..#
###
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>Five choices below satisfy the condition.</p>
<ul>
<li>The <var>1</var>-st row and <var>1</var>-st column</li>
<li>The <var>1</var>-st row and <var>2</var>-nd column</li>
<li>The <var>1</var>-st row and <var>3</var>-rd column</li>
<li>The <var>1</var>-st and <var>2</var>-nd column</li>
<li>The <var>3</var>-rd column</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 4
..#
###
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>One choice, which is choosing nothing, satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 2 3
##
##
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6 6 8
..##..
.#..#.
#....#
######
#....#
#....#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>208
</pre></section>
</div>
</span> |
p00629 |
<H1><font color="#000000">Problem 03:</font> Selecting Teams Advanced to Regional</H1>
<p>
æ¥æ¬ã§æ¯å¹Žéå¬ãããåœé倧åŠå¯Ÿæããã°ã©ãã³ã°ã³ã³ãã¹ãã®ã¢ãžã¢å°åºäºéžã«åºå Žããããã«ã¯ãå³ããåœå
äºéžãçªç Žããªããã°ãªããŸããã
</p>
<p>
倧åŠå¯Ÿæãšã¯èšã£ãŠããïŒã€ã®åŠæ ¡ããè€æ°ã®ããŒã ãåæŠããŸããããã§ãã§ããã ãå€ãã®åŠæ ¡ãã¢ãžã¢å°åºäºéžã«åºå Žã§ããããã«ãçªç ŽããŒã ã®éžæã«ã¯ä»¥äžã®éžæã«ãŒã«ãé©çšãããŸãïŒ
</p>
<p>
該åœããŒã ã <i>A</i> ãšããæçžŸã®åªç§ãªé çªã«æ¬¡ã®ã«ãŒã«ãé©çšããŸãïŒ
</p>
<ul>
<li>ã«ãŒã« 1ïŒ<br>
ãã®æç¹ã§ã®éžæããŒã æ°ã 10 ã«æºããªãå ŽåïŒ<br>
<i>A</i> ãšåãæå±ã§ãã®æç¹ã§éžæãããããŒã ã®æ°ã 3 ã«æºããªããã°ã<i>A</i> ã¯éžæãããŸãã
</li>
<li>ã«ãŒã« 2ïŒ<br>
ãã®æç¹ã§ã®éžæããŒã æ°ã 20 ã«æºããªãå ŽåïŒ<br>
<i>A</i> ãšåãæå±ã§ãã®æç¹ã§éžæãããããŒã ã®æ°ã 2 ã«æºããªããã°ã<i>A</i> ã¯éžæãããŸãã
</li>
<li>ã«ãŒã« 3ïŒ<br>
ãã®æç¹ã§ã®éžæããŒã æ°ã 26 ã«æºããªãå ŽåïŒ<br>
<i>A</i> ãšåãæå±ã§ãã®æç¹ã§éžæãããããŒã ããªããã°ã<i>A</i> ã¯éžæããŸãã
</li>
</ul>
<p>
ãŸããæçžŸã®é çªã¯æ¬¡ã®ã«ãŒã«ã§æ±ºå®ãããŸãïŒ
</p>
<ul>
<li>ããå€ãã®åé¡ãè§£ããããŒã ãäžäœãšãªããŸãã</li>
<li>è§£ããå顿°ãåãå Žåã¯ãããã«ãã£ãå°ããããŒã ãäžäœãšãªããŸãã</li>
</ul>
<p>
åããŒã ã®IDïŒæŽæ°ïŒãæå±ïŒæŽæ°ïŒãæ£è§£æ°ïŒæŽæ°ïŒãããã«ãã£ïŒæŽæ°ïŒãå
¥åããéžæããŒã ã®IDãéžæé ã«åºåããããã°ã©ã ãäœæããŠäžããã
ããŒã ã¯æçžŸé ã«äžãããããšã¯éããªãã®ã§ãé äœä»ãããåŸãéžæã«ãŒã«ãé©çšããªããã°ãªããªãããšã«æ³šæããŠäžããã
</p>
<p>
ãã®åé¡ã§ã¯ãæ£è§£æ°ãšããã«ãã£ãåãããŒã ããã£ãå Žåã¯IDãå°ããæ¹ãäžäœãšããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããå
¥åãšããŠäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãïŒ<br><br>
<i>n</i> (ããŒã æ°ïŒæŽæ°)<br>
I<sub>1</sub> U<sub>1</sub> A<sub>1</sub> P<sub>1</sub> (1çªç®ã®ããŒã ã®IDãæå±ãæ£è§£æ°ãããã«ãã£ïŒç©ºçœåºåãã®ïŒã€ã®æŽæ°)<br>
I<sub>2</sub> U<sub>2</sub> A<sub>2</sub> P<sub>2</sub> (2çªç®ã®ããŒã ã®IDãæå±ãæ£è§£æ°ãããã«ãã£ïŒç©ºçœåºåãã®ïŒã€ã®æŽæ°)<br>
.<br>
.<br>
I<sub><i>n</i></sub> U<sub><i>n</i></sub> A<sub><i>n</i></sub> P<sub><i>n</i></sub> (nçªç®ã®ããŒã ã®IDãæå±ãæ£è§£æ°ãããã«ãã£ïŒç©ºçœåºåãã®ïŒã€ã®æŽæ°)<br>
</p>
<p>
n 㯠300 以äžã§ãããI<sub><i>i</i></sub>, U<sub><i>i</i></sub> 㯠1 ä»¥äž 1000 以äžãšããŸããïŒã€ã®ããŒã¿ã»ããã«ãåã ID ã®ããŒã ã¯ç¡ããšä»®å®ããŠããŸããŸããã
</p>
<p>
A<sub><i>i</i></sub> 㯠10 以äžãP<sub><i>i</i></sub> 㯠100,000 以äžãšããŸãã
</p>
<p>
<i>n</i> ã 0 ã®ãšããå
¥åã®çµãããšããŸãã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«ã€ããŠãéžæããŒã ã®IDãéžæãããé ã«åºåããŠäžããã1ã€ã®IDã1è¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
6
1 1 6 200
2 1 6 300
3 1 6 400
4 2 5 1200
5 1 5 1400
6 3 4 800
3
777 1 5 300
808 2 4 20
123 3 6 500
2
2 1 3 100
1 1 3 100
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
2
3
4
6
123
777
808
1
2
</pre>
|
p02244 |
<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>8 Queens Problem</H1>
<p>
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_13_A_8queens">
</center><br>
<p>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
</p>
<H2>Input</H2>
<p>
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
</p>
<H2>Output</H2>
<p>
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by '<span>Q</span>' and an empty square is represented by '<span>.</span>'.
</p>
<H2>Constraints</H2>
<ul>
<li>There is exactly one solution</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
2
2 2
5 3
</pre>
<H2>Sample Output 1</H2>
<pre>
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q...
</pre> |
p00279 |
<H1>ããããŒãšã³ãåé¡</H1>
<p>
ãããããŒãšã³ãåé¡ããšåŒã°ããæ°åŠã®æªè§£æ±ºåé¡ã«é¢é£ããããã°ã©ã ãæžããŠã¿ãŸããããå¹³é¢äžã«äžãããã<var>N</var>åã®ç¹ãããã¡ããã©<var>k</var>åã®ç¹ãçµãã§ã§ããåžå€è§åœ¢ã®ãã¡ãæãé¢ç©ã®å°ãããã®ãèŠã€ããããã°ã©ã ãäœæããŠãã ããããã ããNåã®ç¹ã®åº§æšãäžããããåŸã質åãšããŠåžå€è§åœ¢ã®è§ã®åæ°<var>k</var>ãããã€ãäžããããŸãã
</p>
<p>
ïŒè£è¶³ïŒããããŒãšã³ãåé¡ã«ã€ããŠïŒ<br/>
å¹³é¢äžã«ã©ã®ïŒç¹ãåãçŽç·äžã«ä¹ããªãããã«<var>N</var>åã®ç¹ã眮ããŸãããã®ãšããã©ã®ããã«ç¹ã眮ããŠããkåã®ç¹ãããŸãéžã¶ãškåã®è§ããã€åžå€è§åœ¢ãå¿
ãäœãããšäºæ³ãããŠããŸãã ä»ã®ãšãããäžè§åœ¢ãªãã°<var>N</var>=3ãåè§åœ¢ãªãã°<var>N</var>=5ãäºè§åœ¢ãªãã°<var>N</var>=9ãå
è§åœ¢ãªãã°<var>N</var>=17ã§ããã°ããããšããïŒïŒïŒïŒå¹ŽãŸã§ã«èšŒæãããŠããŸãããŸããäžè§åœ¢ä»¥äžã®ãã¹ãŠã®kè§åœ¢ã«å¯ŸããŠã<var>N</var>=1+2<sup><var>k</var>-2</sup>ãšããäºæ³ããããŸãããããŸã 蚌æãããŠããŸãããããã¯ïŒïŒïŒå¹Žã«ãããç ç©¶ãé²ããããŠããé£åã§ãã<br/>
ãã®åé¡ã«ã¯ããããããŒãšã³ãåé¡ããšããçŽ æµãªååãã€ããããŠããŸããããç·å¥³ããã®åé¡ãç ç©¶ããŠãããã¡ã«ä»²è¯ããªã£ãŠãã€ãã«çµå©ããããšã«ã¡ãªãã§ãåäººã®æ°åŠè
ãåä»ããããã§ããããã³ããã¯ã§ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯1ã€ã®ããŒã¿ã»ãããããªããå
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</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>Q</var>
<var>k<sub>1</sub></var>
:
<var>k<sub>Q</sub></var>
</pre>
<p>
ïŒè¡ç®ã«å¹³é¢äžã®ç¹ã®åæ°<var>N</var>(3 ≤ <var>N</var> ≤ 40)ãäžãããããç¶ã<var>N</var>è¡ã«åç¹ã®åº§æšãäžãããããåç¹ã«ã¯1ãã<var>N</var>ãŸã§ã®çªå·ããå
¥åãããé çªã«ä»ããããŠããã<var>x<sub>i</sub></var>ãš<var>y<sub>i</sub></var>(-10000 ≤ <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ≤ 10000)ã¯<var>i</var>çªç®ã®ç¹ã®ãããã<var>x</var>座æšãš<var>y</var>座æšãè¡šãæŽæ°ã§ããã<var>x</var>è»žã®æ£æ¹åã¯å³åã, <var>y</var>è»žã®æ£æ¹åã¯äžåãã«åããã®ãšããã
</p>
<p>
ç¶ãïŒè¡ã«è³ªåã®æ°<var>Q</var>(1 ≤ <var>Q</var> ≤ <var>N</var>)ãäžãããããç¶ã<var>Q</var>è¡ã«è³ªåãäžããããã<var>k<sub>i</sub></var>(3 ≤ <var>k<sub>i</sub></var> ≤ <var>N</var>)ã¯<var>i</var>çªç®ã®è³ªåã§ããåžå€è§åœ¢ã®è§ã®åæ°ã衚ãã
</p>
<p>
ãªããå
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããã®ãšããã
</p>
<ul>
<li> å
¥åãããç¹ã®åº§æšã¯ãã¹ãŠç°ãªãã </li>
<li> ã©ã®ïŒç¹ãåãçŽç·äžã«ã¯ä¹ããªãã</li>
<li> å質åã«å¯ŸããŠé¢ç©æå°ã®åžå€è§åœ¢ã¯ïŒã€ã§ãããïŒçªç®ã«å°ããåžå€è§åœ¢ãšã®é¢ç©ã®å·®ã¯ 0.0001以äžã</li>
</ul>
<h2>åºå</h2>
<p>
質åããšã«ãé¢ç©ãæå°ã®åžå€è§åœ¢ã®å
šé ç¹ã1è¡ã«åºåãããåžå€è§åœ¢ã®é ç¹ã§æãäžã«ãããã®ã®äžã§æãå·Šã«ããé ç¹ããé ã«ãåæèšåšãã§é ç¹ã®çªå·ãåºåãããé ç¹ã®çªå·ã®éã¯ç©ºçœ1ã€ã§åºåããè¡ã®çµããã«ã¯ç©ºçœæåãåºåããªãããã ããåžå€è§åœ¢ãäœããªãå Žåã¯NAãšåºåããã
</p>
<h2>å
¥åäŸ 1</h2>
<pre>
5
0 0
3 0
5 2
1 4
0 3
3
3
4
5
</pre>
<h2>åºåäŸ 1</h2>
<pre>
1 4 5
1 2 4 5
1 2 3 4 5
</pre>
<br/>
<h2>å
¥åäŸ 2</h2>
<pre>
6
0 0
3 0
5 2
1 4
0 3
3 2
4
3
4
5
6
</pre>
<h2>åºåäŸ 2</h2>
<pre>
6 3 5
6 3 4 5
1 2 6 4 5
NA
</pre>
|
p01891 |
<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>A: ãã£ãã / Cabbage</h1>
<h2>å顿</h2>
<p>
AOR ã€ã«ã¡ããã¯èã $N$ æãããã£ãããæã«å
¥ããã
ãã®ãã£ããã®èã«ã¯å€åŽããé ã« $1,\ldots,N$ ã®çªå·ãã€ããŠããŠã$i$ çªç®ã®èã®æ±ãå
·å㯠$D_i$ ã§ããã
ãã®å€ã倧ããã»ã©æ±ãå
·åãé
·ãããšã衚ãã
AOR ã€ã«ã¡ããã¯ãã®ãã£ããã®èãæçã«äœ¿ãããã廿£ããåè£ã®æ±ãèã以äžã®æé ã«åŸã£ãŠéžã¶ããšã«ããã
</p>
<ol>
<li>
廿£åè£ã空ã«åæåããã
</li>
<li>
ãŸã 調ã¹ãŠããªãæãå€åŽã®èã«æ³šç®ãããå
šãŠèª¿ã¹çµãã£ãŠããå Žåã¯çµäºããã
</li>
<li>
ãã®èã®æ±ãå
·åã $A$ 以äžã§ããã°å»æ£åè£ã«å ãã 2. ã«æ»ããããã§ãªããã°çµäºããã
</li>
</ol>
</ol>
<p>
ãããããã®æäœãè¡ã£ãçµæãæçã«äœ¿ããèãæ¥µç«¯ã«å°ãªããªã£ãŠããŸãå Žåãããããšã«æ°ãã€ããã
ããã§ãäžèšã®æäœåŸã«æšãŠãèãèããªããã以äžã®æäœãè¡ãããšã«ããã
</p>
<ol>
<li>
廿£åè£ã§ãªãèã $M$ ææªæºã§ããã° 2. ã«é²ããããã§ãªããã°çµäºããã
</li>
<li>
廿£åè£ã®èã®ãã¡ãŸã 調ã¹ãŠããªãæãå
åŽã®èã«æ³šç®ããã廿£åè£ã®èããªãå Žåã¯çµäºããã
</li>
<li>
ãã®èã®æ±ãå
·åã $B$ 以äžã§ããã°å»æ£åè£ããå€ãã 2. ã«æ»ãã
ããã§ãªããã°å»æ£åè£ã«æ®ã£ãŠããèãå
šãŠå»æ£ããçµäºããã
</li>
</ol>
</ol>
<p>
ãããã®æäœãè¡ã£ããšããæçµçã«æšãŠãèã®ææ°ãæ±ããã
</p>
<h2>å
¥å</h2>
<p>
$N \ M \ A \ B$<br>
$D_{1} \ D_{2} \ \cdots \ D_{N}$<br>
</p>
<h2>å
¥åã®å¶çŽ</h2>
<p>
$1 \leq N \leq 1000$<br>
$0 \leq M \leq N$<br>
$1 \leq A \leq B \leq 1000$<br>
$1 \leq D_{i} \leq 1000$<br>
</p>
<h2>åºå</h2>
<p>
æçµçã«æšãŠãèã®æ°ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å1</h3>
<pre>
5 3 6 9
9 7 5 3 1
</pre>
<h3>ãµã³ãã«åºå1</h3>
<pre>
2
</pre>
<p>
äžæç®ãšäºæç®ãæšãŠãã
</p>
<h3>ãµã³ãã«å
¥å2</h3>
<pre>
5 3 6 9
5 4 3 2 1
</pre>
<h3>ãµã³ãã«åºå2</h3>
<pre>
0
</pre>
<p>
äžæç®ããæšãŠãªãã
</p>
<h3>ãµã³ãã«å
¥å3</h3>
<pre>
5 3 6 9
10 8 6 4 2
</pre>
<h3>ãµã³ãã«åºå3</h3>
<pre>
1
</pre>
<p>
äžæç®ãŸã§æšãŠãããšãããèãçŽããäºæç®ãšäžæç®ãæšãŠãªãããšã«ããã
</p>
<h3>ãµã³ãã«å
¥å4</h3>
<pre>
5 3 6 9
5 10 8 6 4
</pre>
<h3>ãµã³ãã«åºå4</h3>
<pre>
0
</pre>
<p>
äºæç®ãæ±ããŠããããšã AOR ã€ã«ã¡ããã¯ç¥ããªãã
</p>
<h3>ãµã³ãã«å
¥å5</h3>
<pre>
5 0 6 9
9 9 8 8 7
</pre>
<h3>ãµã³ãã«åºå5</h3>
<pre>
5
</pre>
<p>
å
šéšæšãŠãŠãæ°ã«ããªãã
</p> |
p00783 |
<H1><font color="#000">Problem D:</font> Napoleon's Grumble</H1>
<p>
Legend has it that, after being defeated in Waterloo, Napoleon Bonaparte, in retrospect of his days of glory, talked to himself "Able was I ere I saw Elba." Although, it is quite doubtful that he should have said this in English, this phrase is widely known as a typical <i>palindrome</i>.
</p>
<p>
A palindrome is a symmetric character sequence that looks the same when read backwards, right to left. In the above Napoleon's grumble, white spaces appear at the same positions when read backwards. This is not a required condition for a palindrome. The following, ignoring spaces and punctuation marks, are known as the first conversation and the first palindromes by human beings.
</p>
<pre>
"Madam, I'm Adam."
"Eve."
<i>(by Mark Twain)</i>
</pre>
<p>
Write a program that finds palindromes in input lines.
</p>
<H2>Input</H2>
<p>
A multi-line text is given as the input. The input ends at the end of the file.
</p>
<p>
There are at most 100 lines in the input. Each line has less than 1,024 Roman alphabet characters.
</p>
<H2>Output</H2>
<p>
Corresponding to each input line, a line consisting of <i>all</i> the character sequences that are palindromes in the input line should be output. However, trivial palindromes consisting of only one or two characters should not be reported.
</p>
<p>
On finding palindromes, any characters in the input except Roman alphabets, such as punctuation characters, digits, space, and tabs, should be ignored. Characters that differ only in their cases should be looked upon as the same character. Whether or not the character sequences represent a proper English word or sentence does not matter.
</p>
<p>
Palindromes should be reported all in uppercase characters. When two or more palindromes are reported, they should be separated by a space character. You may report palindromes in any order.
</p>
<p>
If two or more occurrences of the same palindromes are found in the same input line, report only once. When a palindrome overlaps with another, even when one is completely included in the other, both should be reported. However, palindromes appearing in the center of another palindrome, whether or not they also appear elsewhere, should not be reported. For example, for an input line of "AAAAAA", two palindromes "AAAAAA" and "AAAAA" should be output, but not "AAAA" nor "AAA". For "AABCAAAAAA", the output remains the same.
</p>
<p>
One line should be output corresponding to one input line. If an input line does not contain any palindromes, an empty line should be output.
</p>
<H2>Sample Input</H2>
<pre>
As the first man said to the
first woman:
"Madam, I'm Adam."
She responded:
"Eve."
</pre>
<H2>Output for the Sample Input</H2>
<pre>
TOT
MADAMIMADAM MADAM
ERE DED
EVE
</pre>
<p>
Note that the second line in the output is empty, corresponding to the second input line containing no palindromes. Also note that some of the palindromes in the third input line, namely "ADA", "MIM", "AMIMA", "DAMIMAD", and "ADAMIMADA", are not reported because they appear at the center of reported ones. "MADAM" <i>is</i> reported, as it does not appear in the center, but only once, disregarding its second occurrence.
</p>
|
p01038 |
<h1>Problem B: Mountain Climbing</h1>
<h2>Problem</h2>
<p>
ãªãããåã¯å±±ç»ãã®èšç»ãç«ãŠãŠããŸããèšç»ã¯ãšãŠã倧åã§ããé«åã»çå°ãå€ãã®ããå³°ã»çªªå°ãå€ãã®ããå±±è
¹ãããã®ããç¶æ³ã«ãã£ãŠçšæããè·ç©ãå€ãã£ãŠããŸãã
</p>
<p>
ãªãããåãæã£ãŠããç»å±±ã¬ã€ãããã¯ã«ã¯ãä»åç»å±±ã«å©çšããéã®äžå®ã®è·é¢æ¯ã®æšé«ãã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§é ã«æžãããŠããŸãã
</p>
<p>
ã¬ã€ãããã¯ã«æžãããŠããæšé«ãã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§é ã«
<var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>N</sub></var>ãšããé«åãçå°ãå±±è
¹ãå³°ã窪å°ã次ã®ããã«å®çŸ©ããŸã:
</p>
<ul>
<li>é«å<br/>
<var>a<sub>i-1</sub></var> < <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> > <var>a<sub>j+1</sub></var> (<var>1</var> < <var>i</var> < <var>j</var> < <var>N</var>)
</li>
<li>çå°<br />
<var>a<sub>i-1</sub></var> > <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> < <var>a<sub>j+1</sub></var> (<var>1</var> < <var>i</var> < <var>j</var> < <var>N</var>)
</li>
<li>å±±è
¹<br />
<var>a<sub>i-1</sub></var> < <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> < <var>a<sub>j+1</sub></var> (<var>1</var> < <var>i</var> < <var>j</var> < <var>N</var>)<br />
ãããã¯
<var>a<sub>i-1</sub></var> > <var>a<sub>i</sub></var> = <var>a<sub>i+1</sub></var> = ... = <var>a<sub>j</sub></var> > <var>a<sub>j+1</sub></var> (<var>1</var> < <var>i</var> < <var>j</var> < <var>N</var>)<br />
</li>
<li>å³°<br />
<var>a<sub>i-1</sub></var> < <var>a<sub>i</sub></var> > <var>a<sub>i+1</sub></var> (<var>1</var> < <var>i</var> < <var>N</var>)<br />
</li>
<li>窪å°<br />
<var>a<sub>i-1</sub></var> > <var>a<sub>i</sub></var> < <var>a<sub>i+1</sub></var> (<var>1</var> < <var>i</var> < <var>N</var>)<br />
</li>
</ul>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_kougen.png" />
<figcaption>é«å</figcaption>
</figure>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_bonchi.png" />
<figcaption>çå°</figcaption>
</figure>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sanpuku1.png" />
<figcaption>å±±è
¹</figcaption>
</figure>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sanpuku2.png" />
<figcaption>å±±è
¹</figcaption>
</figure>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_mine.png" />
<figcaption>å³°</figcaption>
</figure>
<figure>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_kubochi.png" />
<figcaption>窪å°</figcaption>
</figure>
<br />
<p>
ããªãã¯ããªãããåã®çºã«ãé«åã»çå°ã»å±±è
¹ã»å³°ã»çªªå°ãããããã®æ°ãèšç®ããããã°ã©ã ãæžãããšã«ããŸããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯æ¬¡ã®ãããªåœ¢åŒã§äžãããã:
</p>
<pre>
<var>N</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> <var>a<sub>3</sub></var>...<var>a<sub>N</sub></var>
</pre>
<p>
<var>N</var>ã¯äžããããæšé«ã®æ°ãè¡šãæŽæ°ã§ããã
<var>a<sub>i</sub></var>ã¯æšé«ãè¡šãæŽæ°ã§ãã( 1 ≤ i ≤ <var>N</var> )ããããã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 100000</li>
<li>-100000 ≤ <var>a<sub>i</sub></var> ≤ 100000</li>
</ul>
<h2>Output</h2>
<p>é«åã®æ°ãçå°ã®æ°ãå±±è
¹ãå³°ã窪å°ã®æ°ãé çªã«ç©ºçœåºåãã§äžè¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
5 1 2 3 4 3
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sample01.png" />
<h2>Sample Output 1</h2>
<pre>
0 0 0 1 0
</pre>
<h2>Sample Input 2</h2>
<pre>
12 10 5 15 15 20 20 12 12 8 3 3 5
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_B_sample02.png" />
<h2>Sample Output 2</h2>
<pre>
1 1 2 0 1
</pre>
|
p03005 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is distributing <var>N</var> balls to <var>K</var> persons.</p>
<p>If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq N \leq 100</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible difference in the number of balls received.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.</p>
<p>Thus, the maximum possible difference in the number of balls received is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre>
<p>For example, if we give <var>1, 4, 1, 1, 1</var> balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be <var>3</var>, which is the maximum result.</p></section>
</div>
</span> |
p01468 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>å顿</h2>
<p>$N$ æ¬ã®ç·å $s_1, s_2, ..., s_N$ ãäžããããããã®ãšãã
dist$(s_i, s_j)$, ( $1 \leq i,j \leq N, i \ne j $ )
ã®ãšãããæå°å€ãæ±ããã
dist$(s_i, s_j)$ ã¯</p>
<ul><li>$\sqrt{(x_i-x_j)^2 + (y_i-y_j)^2}$, ( $(x_i,y_i)$ 㯠$s_i$ äžã®ç¹ã$(x_j,y_j)$ 㯠$s_j$ äžã®ç¹)</li></ul>
<p>ã®ãšãããæå°å€ã§å®çŸ©ãããã</p>
<p>以äžã¯Sample Inputã®ããŒã¿ã»ãããå³ç€ºãããã®ã§ããã</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample0" width="240" height="240">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample1" width="240" height="240">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample2" width="240" height="240">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_closest_segment_pair_sample3" width="240" height="240">
</p>
<h2>å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã</p>
<pre>
$N$
$x_{1,1}$ $y_{1,1}$ $x_{1,2}$ $y_{1,2}$
$x_{2,1}$ $y_{2,1}$ $x_{2,2}$ $y_{2,2}$
$...$
$x_{N,1}$ $y_{N,1}$ $x_{N,2}$ $y_{N,2}$
</pre>
<p>$s_i$ã¯$(x_{i,1}, y_{i,1})$ïŒ$(x_{i,2}, y_{i,2})$ã端ç¹ãšããç·åã§ããã</p>
<h2>å¶çŽ</h2>
<ul><li>$2 \leq N \leq 10^5$</li>
<li>$0 \leq x_{i,j}, y_{i,j} \leq 100$</li>
<li>$(x_{i,1}, y_{i,1}) \neq (x_{i,2}, y_{i,2})$</li></ul>
<h2>åºå</h2>
<p>æå°å€ã1è¡ã«åºåãããåºåãããå€ã«ã¯$10^{-5}$ãã倧ããªèª€å·®ããã£ãŠã¯ãªããªãã</p>
<h2>Sample Input 1</h2>
<pre>4
2 0 2 25
0 30 15 20
16 20 5 15
23 0 23 30</pre>
<h2>Output for the Sample Input 1</h2>
<pre>0.41380294</pre>
<h2>Sample Input 2</h2>
<pre>6
0 0 0 5
1 3 3 5
6 0 6 10
7 4 10 4
11 1 11 3
7 0 10 0</pre>
<h2>Output for the Sample Input 2</h2>
<pre>1.00000000</pre>
<h2>Sample Input 3</h2>
<pre>6
5 5 5 45
7 45 19 45
7 30 19 30
21 34 21 44
26 45 36 28
45 45 26 5</pre>
<h2>Output for the Sample Input 3</h2>
<pre>0.83553169</pre>
<h2>Sample Input 4</h2>
<pre>11
10 10 10 90
10 90 35 90
10 60 35 60
35 60 35 90
40 10 40 90
37 45 60 45
60 10 60 45
65 10 65 90
65 90 90 90
65 60 90 65
90 60 90 90
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>0.00000000</pre>
|
p03455 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer found two positive integers, <var>a</var> and <var>b</var>.
Determine whether the product of <var>a</var> and <var>b</var> is even or odd.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>a,b</var> <var>â€</var> <var>10000</var></li>
<li><var>a</var> and <var>b</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the product is odd, print <code>Odd</code>; if it is even, print <code>Even</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Even
</pre>
<p>As <var>3 Ã 4 = 12</var> is even, print <code>Even</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 21
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Odd
</pre>
<p>As <var>1 Ã 21 = 21</var> is odd, print <code>Odd</code>.</p></section>
</div>
</span> |
p01192 |
<H1><font color="#000"></font>Greedy, Greedy.</H1>
<!-- Problem D-->
<p>
Once upon a time, there lived a dumb king. He always messes things up based on his whimsical ideas.
This time, he decided to renew the kingdomâs coin system. Currently the kingdom has three types of
coins of values 1, 5, and 25. He is thinking of replacing these with another set of coins.
</p>
<p>
Yesterday, he suggested a coin set of values 7, 77, and 777. âThey look so fortunate, donât they?â said
he. But obviously you canât pay, for example, 10, using this coin set. Thus his suggestion was rejected.
</p>
<p>
Today, he suggested a coin set of values 1, 8, 27, and 64. âThey are all cubic numbers. How beautiful!â
But another problem arises: using this coin set, you have to be quite careful in order to make changes
efficiently. Suppose you are to make changes for a value of 40. If you use a greedy algorithm, i.e.
continuously take the coin with the largest value until you reach an end, you will end up with seven
coins: one coin of value 27, one coin of value 8, and five coins of value 1. However, you can make
changes for 40 using five coins of value 8, which is fewer. This kind of inefficiency is undesirable, and
thus his suggestion was rejected again.
</p>
<p>
Tomorrow, he would probably make another suggestion. Itâs quite a waste of time dealing with him, so
letâs write a program that automatically examines whether the above two conditions are satisfied.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case is given in a line with the format
</p>
<pre>
<i>n</i> <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> . . . <i>c</i><sub><i>n</i></sub>
</pre>
<p>
where <i>n</i> is the number of kinds of coins in the suggestion of the king, and each <i>c<sub>i</sub></i> is the coin value.
</p>
<p>
You may assume 1 ≤ <i>n</i> ≤ 50 and 0 < <i>c</i><sub>1</sub> < <i>c</i><sub>2</sub> < . . . < <i>c</i><sub><i>n</i></sub> < 1000.
</p>
<p>
The input is terminated by a single zero.
</p>
<H2>Output</H2>
<p>
For each test case, print the answer in a line. The answer should begin with âCase #<i>i</i>: â, where <i>i</i> is the
test case number starting from 1, followed by
</p>
<ul>
<li> âCannot pay some amountâ if some (positive integer) amount of money cannot be paid using
the given coin set,</li>
<li> âCannot use greedy algorithmâ if any amount can be paid, though not necessarily with the
least possible number of coins using the greedy algorithm,</li>
<li> âOKâ otherwise.</li>
</ul>
<H2>Sample Input</H2>
<pre>
3 1 5 25
3 7 77 777
4 1 8 27 64
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case #1: OK
Case #2: Cannot pay some amount
Case #3: Cannot use greedy algorithm
</pre>
|
p01487 |
<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 B:
RabbitWalking
</h2>
<p>
ãããã®äœãã§ããéœåžã«ã¯, $V$ åã®äº€å·®ç¹ãš $E$ æ¬ã®éããã. 亀差ç¹ã¯ 1-indexed ã§çªå·ãä»ããããŠãã. $i$ çªç®ã®éã¯äº€å·®ç¹ $a_i$ ãšäº€å·®ç¹ $b_i$ ã bidirectional ã«ã€ãªãã§ãã.
</p>
<p>
ãããã¯, æ£æ©ãšå¥æ°ã奜ãã§ããïŒãããã¯ãã亀差ç¹ããåºçºã, éã奿°æ¬èŸ¿ã, åºçºããé ç¹ã«æ»ããããªçµè·¯ã«æ²¿ã£ãŠæ£æ©ããããšæã£ãŠããïŒ
</p>
<p>
ãã®éœåžã®åžé·ã§ããããã¯, éœåžå
ã®ç§»åãå¹çåããããã«ç°ãªã2 ã€ã®äº€å·®ç¹ãçµã¶éããããã远å ããããšããŠããïŒãã ãïŒãã亀差ç¹ã®çµã«å¯ŸããŠæ·èšããããšãåºæ¥ãéã¯é«ã
1æ¬ãŸã§ã§ããïŒãŸãïŒ ããã¯ãããã奜ããªã®ã§ïŒéã奿°æ¬èŸ¿ã, åºçºããé ç¹ã«æ»ããããªçµè·¯ãå«ãŸããªãããã«ããããšæã£ãŠããïŒ
</p>
<p>
æå€§ã§äœæ¬éãä»ãå ãããããæ±ãã. ãã ãïŒæåãããããã®èŠæ±ãæºããããŠããå Žåã¯-1 ãåºåãã.
</p>
<h3>Constraints</h3>
<ul>
<li>$V$ will be between 1 and 100,000, inclusive.</li>
<li>$E$ will be between 0 and 100,000, inclusive.</li>
<li>$a_i$ and $b_i$ will be distinct.</li>
<li>No two roads connect the same pair of intersections.</li>
</ul>
<h3>Input</h3>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã:<br>
<br>
$V$ $E$<br>
$a_1$ $b_1$<br>
...<br>
$a_E$ $b_E$<br>
<br>
</p>
<h3>Output</h3>
<p>
éã远å ã§ããæ¬æ°ã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã«åºåãã. æåãããããã®èŠæ±ãæºããããŠããå Žå㯠-1 ãåºåãã.
</p>
<h3>Sample Input 1</h3>
<pre>8 5
1 2
6 5
6 4
1 3
4 7</pre>
<h3>Sample Output 1</h3>
<pre>11</pre>
<h3>Sample Input 2</h3>
<pre>5 8
2 1
2 4
1 3
5 4
4 1
2 3
3 5
2 5</pre>
<h3>Sample Output 2</h3>
<pre>-1</pre>
|
p03140 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three strings <var>A, B</var> and <var>C</var>. Each of these is a string of length <var>N</var> consisting of lowercase English letters.</p>
<p>Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:</p>
<ul>
<li>Operation: Choose one of the strings <var>A, B</var> and <var>C</var>, and specify an integer <var>i</var> between <var>1</var> and <var>N</var> (inclusive). Change the <var>i</var>-th character from the beginning of the chosen string to some other lowercase English letter.</li>
</ul>
<p>What is the minimum number of operations required to achieve the objective?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li>Each of the strings <var>A, B</var> and <var>C</var> is a string of length <var>N</var>.</li>
<li>Each character in each of the strings <var>A, B</var> and <var>C</var> is a lowercase English letter.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A</var>
<var>B</var>
<var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
west
east
wait
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>In this sample, initially <var>A =</var> <code>west</code>ã<var>B =</var> <code>east</code>ã<var>C =</var> <code>wait</code>. We can achieve the objective in the minimum number of operations by performing three operations as follows:</p>
<ul>
<li>Change the second character in <var>A</var> to <code>a</code>. <var>A</var> is now <code>wast</code>.</li>
<li>Change the first character in <var>B</var> to <code>w</code>. <var>B</var> is now <code>wast</code>.</li>
<li>Change the third character in <var>C</var> to <code>s</code>. <var>C</var> is now <code>wast</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
different
different
different
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If <var>A, B</var> and <var>C</var> are already equal in the beginning, the number of operations required is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
zenkoku
touitsu
program
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>13
</pre></section>
</div>
</span> |
p03510 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In a long narrow forest stretching east-west, there are <var>N</var> beasts. Below, we will call the point that is <var>p</var> meters from the west end Point <var>p</var>. The <var>i</var>-th beast from the west <var>(1 †i †N)</var> is at Point <var>x_i</var>, and can be sold for <var>s_i</var> yen (the currency of Japan) if captured.</p>
<p>You will choose two integers <var>L</var> and <var>R</var> <var>(L †R)</var>, and throw a net to cover the range from Point <var>L</var> to Point <var>R</var> including both ends, <var>[L, R]</var>. Then, all the beasts in the range will be captured. However, the net costs <var>R - L</var> yen and your profit will be <var>(</var>the sum of <var>s_i</var> over all captured beasts <var>i) - (R - L)</var> yen.</p>
<p>What is the maximum profit that can be earned by throwing a net only once?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †2 à 10^5</var></li>
<li><var>1 †x_1 < x_2 < ... < x_N †10^{15}</var></li>
<li><var>1 †s_i †10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>s_1</var>
<var>x_2</var> <var>s_2</var>
<var>:</var>
<var>x_N</var> <var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>When the maximum profit is <var>X</var> yen, print the value of <var>X</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
10 20
40 50
60 30
70 40
90 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>90
</pre>
<p>If you throw a net covering the range <var>[L = 40, R = 70]</var>, the second, third and fourth beasts from the west will be captured, generating the profit of <var>s_2 + s_3 + s_4 - (R - L) = 90</var> yen. It is not possible to earn <var>91</var> yen or more.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
10 2
40 5
60 3
70 4
90 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>The positions of the beasts are the same as Sample 1, but the selling prices dropped significantly, so you should not aim for two or more beasts. By throwing a net covering the range <var>[L = 40, R = 40]</var>, you can earn <var>s_2 - (R - L) = 5</var> yen, and this is the maximum possible profit.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 100
3 200
999999999999999 150
1000000000000000 150
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>299
</pre></section>
</div>
</span> |
p00296 |
<h1>ããã³ãªã¬ãŒã²ãŒã </h1>
<p>
ã¢ã«ã髿 ¡ã§ã¯ãæ¯å¹Žå
šæ ¡çåŸãåå ããã²ãŒã ãè¡ã£ãŠããŸãããŸããæ ¡åºã« <var>N</var> 人ã®å
šæ ¡çåŸãå圢ã«äžŠã³ãŸããå³ã®ããã«ãåçåŸã¯ 0 ãã <var>N</var>-1 ãŸã§ã®çªå·ãæžããããŒãã±ã³ãä»ããŠããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_button" width="280">
</center>
<br>
<p>
ã²ãŒã ã§ã¯ããã³ãïŒæ¬äœ¿ããæåã¯ãŒãã±ã³ 0 çªã®çåŸãããã³ãæã£ãŠããŸããããããã以äžã®æé ã <var>M</var> åç¹°ãè¿ããŸãããŸããçŸæç¹ã§ããã³ãæã£ãŠããçåŸãé©åœãªæ£ã®æŽæ° <var>a</var> ã宣èšããŸãã<var>a</var> ãå¶æ°ã®ãšãã¯æèšåãã奿°ã®ãšãã¯åæèšåãã«é£ã®çåŸã«ããã³ãæž¡ããŠããã<var>a</var> çªç®ã«ããã³ãåãåã£ãçåŸãè±èœããŸããè±èœããçåŸã¯ãæèšåãã§é£ã®çåŸã«ããã³ãæž¡ããåããæããŸãã
</p>
<p>
ã²ãŒã ãçµãã£ãåŸã«åã«æ®ã£ãçåŸã¯ãæŸèª²åŸã®æé€ãïŒå¹Žéå
é€ãããŸããããããããæ°å¹Žã¯çåŸæ°ãå¢ãããããå
šæ ¡çåŸãéããã®ãé£ãããªã£ãŠããŠããŸããããã§ãç«¶æããã°ã©ãã³ã°éšã®ããªãã¯ãã·ãã¥ã¬ãŒã·ã§ã³ã§æé€ãå
é€ãããçåŸãæ±ããããã°ã©ã ãäœæããããé ŒãŸããŸããã
</p>
<p>
æå®ããçåŸãæé€ãå
é€ãããŠãããã©ããã質åãããšããããã«çããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var> <var>Q</var>
<var>a</var><sub>1</sub> <var>a</var><sub>2</sub> ... <var>a<sub>M</sub></var>
<var>q</var><sub>1</sub> <var>q</var><sub>2</sub> ... <var>q<sub>Q </sub></var>
</pre>
<p>
å
¥åã¯ïŒè¡ã§ãããïŒè¡ç®ã«çåŸã®äººæ° <var>N</var> (10 ≤ <var>N</var> ≤ 200000)ãç¹°ãè¿ãåæ° <var>M</var> (5 ≤ <var>M</var> < <var>N</var>)ãçåŸãæé€ãå
é€ããããã©ãããåãåããã質åã®åæ° <var>Q</var> (1 ≤ <var>Q</var> ≤ 1000) ãäžãããããç¶ãïŒè¡ã«ã<var>i</var> åç®ã®ç¹°ãè¿ãã§æåã«ããã³ãæã£ãŠããçåŸã宣èšããæŽæ°<var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 100) ãäžãããããç¶ãïŒè¡ã«ã質åãšããŠãŒãã±ã³çªå· <var>q<sub>i</sub></var> (0 ≤ <var>q</var> < <var>N</var>) ãäžããããã
</p>
<h2>åºå</h2>
<p>
質åããšã«ããŒãã±ã³çªå· <var>q<sub>i</sub></var> ã®çåŸãæé€ãå
é€ããããã©ããã <var>i</var> è¡ç®ã«åºåãããæé€ãå
é€ããããªã 1 ãããããªããªã 0 ãåºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<br>
<h2>å
¥åäŸ </h2>
<pre>
10 5 3
2 6 5 18 3
3 0 5
</pre>
<h2>åºåäŸ</h2>
<pre>
1
0
1
</pre> |
p03843 | <span class="lang-en">
<p>Score : <var>1900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices.
The vertices are numbered <var>1</var> through <var>N</var>.
For each <var>1 †i †N - 1</var>, the <var>i</var>-th edge connects vertices <var>a_i</var> and <var>b_i</var>.
The lengths of all the edges are <var>1</var>.</p>
<p>Snuke likes some of the vertices.
The information on his favorite vertices are given to you as a string <var>s</var> of length <var>N</var>.
For each <var>1 †i †N</var>, <var>s_i</var> is <code>1</code> if Snuke likes vertex <var>i</var>, and <code>0</code> if he does not like vertex <var>i</var>.</p>
<p>Initially, all the vertices are white.
Snuke will perform the following operation exactly once:</p>
<ul>
<li>Select a vertex <var>v</var> that he likes, and a non-negative integer <var>d</var>. Then, paint all the vertices black whose distances from <var>v</var> are at most <var>d</var>.</li>
</ul>
<p>Find the number of the possible combinations of colors of the vertices after the operation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †2Ã10^5</var></li>
<li><var>1 †a_i, b_i †N</var></li>
<li>The given graph is a tree.</li>
<li><var>|s| = N</var></li>
<li><var>s</var> consists of <code>0</code> and <code>1</code>.</li>
<li><var>s</var> contains at least one occurrence of <code>1</code>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In the test set worth <var>1300</var> points, <var>s</var> consists only of <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_{N - 1}</var> <var>b_{N - 1}</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible combinations of colors of the vertices after the operation.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2
1 3
1 4
1100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The following four combinations of colors of the vertices are possible:</p>
<div style="text-align: center;">
<img alt="334d566ec1f4f38d23cd580044f1cd07.png" src="https://atcoder.jp/img/agc008/334d566ec1f4f38d23cd580044f1cd07.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2
1 3
1 4
4 5
11111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>11
</pre>
<p>This case satisfies the additional constraint for the partial score.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2
1 3
1 4
2 5
2 6
100011
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p02751 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have a grid with <var>(2^N - 1)</var> rows and <var>(2^M-1)</var> columns.
You are asked to write <var>0</var> or <var>1</var> in each of these squares.
Let <var>a_{i,j}</var> be the number written in the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p>
<p>For a quadruple of integers <var>(i_1, i_2, j_1, j_2)</var> such that <var>1\leq i_1 \leq i_2\leq 2^N-1, 1\leq j_1 \leq j_2\leq 2^M-1</var>, let
<var>S(i_1, i_2, j_1, j_2) = \displaystyle \sum_{r=i_1}^{i_2}\sum_{c=j_1}^{j_2}a_{r,c}</var>.
Then, let the <em>oddness</em> of the grid be the number of quadruples <var>(i_1, i_2, j_1, j_2)</var> such that <var>S(i_1, i_2, j_1, j_2)</var> is odd.</p>
<p>Find a way to fill in the grid that maximizes its oddness.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> and <var>M</var> are integers between <var>1</var> and <var>10</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print numbers to write in the grid so that its oddness is maximized, in the following format:</p>
<pre><var>a_{1,1}a_{1,2}\cdots a_{1,2^M-1}</var>
<var>a_{2,1}a_{2,2}\cdots a_{2,2^M-1}</var>
<var>\vdots</var>
<var>a_{2^N-1,1}a_{2^N-1,2}\cdots a_{2^N-1,2^M-1}</var>
</pre>
<p>If there are multiple solutions, you can print any of them.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>111
</pre>
<p>For this grid, <var>S(1, 1, 1, 1)</var>, <var>S(1, 1, 2, 2)</var>, <var>S(1, 1, 3, 3)</var>, and <var>S(1, 1, 1, 3)</var> are odd, so it has the oddness of <var>4</var>.</p>
<p>We cannot make the oddness <var>5</var> or higher, so this is one of the ways that maximize the oddness.</p></section>
</div>
</span> |
p02301 |
<H1>Diameter of a Convex Polygon</H1>
<br/>
<p>
Find the diameter of a convex polygon <var>g</var>. In other words, find a pair of points that have maximum distance between them.
</p>
<H2>Input</H2>
<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 in <var>g</var>.
</p>
<p>
In the following lines, the coordinate of the <var>i</var>-th point <var>p<sub>i</sub></var> is given by two real numbers <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. Each value is a real number with at most 6 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
Print the diameter of <var>g</var> in a line. The output values should be in a decimal fraction with an error less than 0.000001.
</p>
<H2>Constraints</H2>
<ul>
<li>
3 ≤ <var>n</var> ≤ 80000
</li>
<li>
-100 ≤ <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ≤ 100
</li>
<li>No point in the <var>g</var> will occur more than once.</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3
0.0 0.0
4.0 0.0
2.0 2.0
</pre>
<H2>Sample Output 1</H2>
<pre>
4.00
</pre>
<H2>Sample Input 2</H2>
<pre>
4
0.0 0.0
1.0 0.0
1.0 1.0
0.0 1.0
</pre>
<H2>Sample Output 2</H2>
<pre>
1.414213562373
</pre>
|
p00453 |
<H1> ãŽãããŽããå·æž¡ã </H1>
<h2>åé¡</h2>
<p>
ããå·ã§,äžæ¹ã®å²žããç³ã®äžã次ã
ãšé£ã³ç§»ã£ãŠå察åŽã®å²žãŸã§è¡ããšããå°ã
å±éºãªã²ãŒã ãã¯ãã£ãŠãã.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hyonhyon1">
</center>
<br>
<p>
ä»,å³ 4-1 ã®ããã«,ç³ã¯ãã¹ç®ã®äžã«ååšãããšèãã.è¡ã®æ°ã¯ n ã§ãã. å³ 4-1 ã§ã¯ n = 5 ã§ãã.
</p>
<p>
ãã®ã²ãŒã ã§ã¯,äžæ¹ã®å²žããå§ããŠ,éåžžã®ãžã£ã³ããŸã㯠m å以äžã®äžè¡é£ã°ãã®ãžã£ã³ããããŠå察åŽã®å²žãŸã§æž¡ã.éåžžã®ãžã£ã³ããšã¯,ä»ããè¡ã®äžã€å
ã®è¡ã®å²žãŸãã¯ç³ã®ã©ããã«é£ã³ç§»ãããšã§ãã,äžè¡é£ã°ãã®ãžã£ã³ããšã¯,ä»ããè¡ã®äºã€å
ã®è¡ã®å²žãŸãã¯ç³ã®ã©ããã«é£ã³ç§»ãããšã§ãã.å§ãã岞ã®äžã€å
ã®è¡ã¯ 1 è¡ç®,äºã€å
ã®è¡ã¯ 2 è¡ç®ã§ãã,n â 1 è¡ç®ã®äºã€å
ã®è¡,åã³ n è¡ç®ã®äžã€å
ã®è¡ã¯å察åŽã®å²žã§ãããšãã.
</p>
<p>
ããŠ,ãã®ã²ãŒã ãã§ããã ãå®å
šã«æãéããããã«,ãžã£ã³ãã®å±éºåºŠãšãããã®ãèããããšã«ãã.ããããã®ç³ã«ã¯,æ»ãããããå®ãŸã£ãŠãã.ç³ããç³ãžé£ã³ç§»ãéã®ãžã£ã³ãã®å±éºåºŠã¯,éåžžã®ãžã£ã³ãã§ãã£ãŠã,äžè¡é£ã°ãã®ãžã£ã³ãã§ãã£ãŠã,
</p>
<p>
(ä»ããç³ã®æ»ãããã + é£ã³ç§»ãå
ã®ç³ã®æ»ãããã)×(暪ã®ç§»åè·é¢)
</p>
<p>
ã§å®ãã.ãã ã,暪ã®ç§»åè·é¢ãšã¯,åã®çªå·ã®å·®ã§ãã.ãŸã,岞ããç³ãž,ãããã¯ç³ãã岞ãžé£ã³ç§»ããžã£ã³ãã®å±éºåºŠã¯ 0 ãšãã.
</p>
<p>
å
¥åãšã㊠n, m,ããããã®ç³ã®äœçœ®ãšæ»ãããããäžãããããšã,å察åŽã®å²žãŸã§å°éããéã®ãžã£ã³ãã®å±éºåºŠã®åèšã®æå°å€ãæ±ããããã°ã©ã ãäœæãã.äžããããå
¥åããŒã¿ã¯å¿
ãå察åŽã®å²žãŸã§å°éããããšãã§ããããã«ãªã£ãŠãã,åããã¹ç®ã«ç³ã¯ 2 å以äžååšããªã.
</p>
<h2>å
¥å</h2>
<p>
<!-- å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠input.txt ã§ãã.-->
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
å
¥åã® 1 è¡ç®ã«ã¯,空çœãåºåããšã㊠2 åã®æŽæ° n,m ãæžãããŠãã.ããã¯,è¡ã®æ°ãš,äžè¡é£ã°ãã®ãžã£ã³ãã®èš±ãããåæ°ã衚ã.n,m ã¯ãããã 2 ≤ n ≤ 150, 0 ≤ m ≤ (n+1)/2ããæºãã.
</p>
<p>
ç¶ã n è¡ã«ã¯,ããããã®è¡ã«ããç³ã®æ
å ±ãæžãããŠãã.i+1 è¡ç® (1 ≤ i ≤ n)ã«ã¯,1 ã€ã®æŽæ° k<sub>i</sub> (0 ≤ k<sub>i</sub> ≤ 10) ãš,ããã«ç¶ã 2 × ki åã®æŽæ°ã空çœã§åºåããæžãããŠãã.ãããã¯,å§ãã岞ããæ°ã㊠i çªç®ã®è¡ã«ããç³ã®æ
å ±ã衚ã.
</p>
<p>
ki ã¯ãã®è¡ã«ååšããç³ã®åæ°ã衚ã,ããã«ç¶ã 2 × ki åã®æŽæ°ã«ã€ããŠã¯,2 × j - 1 åç® (1 ≤ j ≤ k<sub>i</sub> ) ã®æŽæ° x<sub>i,j</sub> ã¯ãã®è¡ã® j åç®ã®ç³ã®åã®çªå·ã,2 × jåç®ã®æŽæ° d<sub>i,j</sub> ã¯ãã®è¡ã® j åç®ã®ç³ã®æ»ããããããããã衚ã.x<sub>i,j</sub> ,d<sub>i,j</sub> ã¯ãããã 1 ≤ x<sub>i,j</sub>, d<sub>i,j</sub> ≤1000 ãæºãã.
</p>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 20% åã«ã€ããŠã¯, n ≤ 6 ãæºãã,é
ç¹ã®å¥ã® 20%åã«ã€ããŠã¯, m = 0 ãæºãã.
</p>
<p>
n, m ããšãã« 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
<!--
åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠output.txt ã§ãã.
output.txt ã¯,å察åŽã®å²žãŸã§å°éããéã®ãžã£ã³ãã®å±éºåºŠã®åèšã®æå°å€ã衚ã 1 ã€ã®æŽæ°ãå«ã 1 è¡ãããªã.
-->
ããŒã¿ã»ããããšã«, å察åŽã®å²žãŸã§å°éããéã®ãžã£ã³ãã®å±éºåºŠã®åèšã®æå°å€ã衚ã 1 ã€ã®æŽæ°ã1 è¡ã«åºåãã.
</p>
<h2>äŸ</h2>
<p>
å³ 4-2 ã«ãããŠ,ç³ã«æžãããæ°åã¯ããããã®ç³ã®æ»ããããã衚ããšãã.
ç¢å°ã§ç€ºãããé çªã§ç³ãæž¡ããšã,ããããã®ãžã£ã³ãã®å±éºåºŠã¯,é çªã« 0,
(2 + 2) × 1 = 4,(2 + 1) × 1 = 3,(1 + 4) × 2 = 10,0 ã§ãã,åèšã¯ 17 ãšãªã.
ãã®ãšã,ãžã£ã³ãã®å±éºåºŠã®åèšã¯æå°ãšãªã.
ãã®äŸã¯ïŒã€ç®ã®å
¥åºåäŸã«å¯Ÿå¿ããŠãã.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hyonhyon2">
</center>
<br>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
5 1
2 1 3 2 2
1 3 2
1 1 7
1 2 1
1 4 4
5 0
2 1 3 2 2
1 3 2
1 1 7
1 2 1
1 4 4
0 0
</pre>
<h3>åºåäŸ</h3>
<pre>
17
40
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div> |
p02194 | <h2>Zero AND Subsets</h2>
<p>éè² æŽæ°ã®å€ééå<var>a_1,a_2,..,a_N</var>ãäžããããŸãã</p>
<p>ãã®éåã®ç©ºã§ãªãéšåéåã§ãã£ãŠãå€ã®bitwiseANDã<var>0</var>ã«ãªããã®ã¯ããã€ãããŸããã</p>
<p>çãã<var>10^9+7</var>ã§å²ã£ãäœããæ±ããŠãã ããã</p>
<h3>å
¥å</h3>
<pre>
<var>N</var>
<var>a_1 a_2...a_N</var>
</pre>
<h3>åºå</h3>
<p>çãã<var>10^9+7</var>ã§å²ã£ãäœããåºåããã</p>
<h3>å¶çŽ</h3>
<ul>
<li><var>1 \leq N \leq 10^5 </var></li>
<li><var>0 \leq a_i \leq 2^{20}-1</var></li>
</ul>
<h3>å
¥åäŸ</h3>
<pre>
6
8 6 9 1 2 1
</pre>
<h3>åºåäŸ</h3>
<pre>
51
</pre>
|
p00003 |
<H1>Is it a Right Triangle?</H1>
<p>
Write a program which judges wheather given length of three side form a right triangle. Print "<span>YES</span>" if the given sides (integers) form a right triangle, "<span>NO</span>" if not so.
</p>
<H2>Input</H2>
<p>
Input consists of several data sets. In the first line, the number of data set, <var>N</var> is given. Then, <var>N</var> lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ length of the side ≤ 1,000</li>
<li> <var>N</var> ≤ 1,000</li>
</ul>
<H2>Output</H2>
<p>
For each data set, print "<span>YES</span>" or "<span>NO</span>".
</p>
<H2>Sample Input</H2>
<pre>
3
4 3 5
4 3 6
8 8 8
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
NO
</pre>
|
p01242 |
<H1><font color="#000">Problem I:</font> Revenge of Voronoi</H1>
<p>
A discrete Voronoi diagram is a derivation of a Voronoi diagram. It is represented as a set of pixels. Each of the
generatrices lies on the center of some pixel. Each pixel belongs to the generatrix nearest from the center of the
pixel in the sense of Manhattan distance. The Manhattan distance <i>d</i> between two points (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) and (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) is given by the following formula:
</p>
<center>
<p>
<i>d</i> = |<i>x</i><sub>1</sub> - <i>x</i><sub>2</sub>| + |<i>y</i><sub>1</sub> - <i>y</i><sub>2</sub>|
</p>
</center>
<p>
Your task is to find a set of generatrices which generates a given discrete Voronoi diagram. In the given diagram,
each generatrix is given a unique lowercase letter as its identifier, and each pixel is represented by the identifier
of the generatrix the pixel belongs to. If a pixel has multiple generatrices at the same distance from its center, it
belongs to the generatrix with the most preceding identifier among them (i.e. the smallest character code).
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases.
</p>
<p>
Each test case begins with a line containing two integers <i>W</i> (1 ≤ <i>W</i> ≤ 32) and <i>H</i> (1 ≤ <i>H</i> ≤ 32), which denote the
width and height of the discrete Voronoi diagram.
</p>
<p>
The following <i>H</i> lines, each of which consists of <i>W</i> letters, give one discrete Voronoi diagram. Each letter
represents one pixel.
</p>
<p>
The end of input is indicated by a line with two zeros. This is not a part of any test cases.
</p>
<H2>Output</H2>
<p>
For each test case, print the case number and the coordinates of generatrices as shown in the sample output. Each
generatrix line should consist of its identifier, <i>x</i>-coordinate, and <i>y</i>-coordinate. Generatrices should be printed in
alphabetical order of the identifiers. Each coordinate is zero-based where (0, 0) indicates the center of the top-left
corner pixel of the diagram.
</p>
<p>
You may assume that every test case has at least one solution. If there are multiple solutions, any one is acceptable.
</p>
<p>
Print a blank line after every test case including the last one.
</p>
<H2>Sample Input</H2>
<pre>
4 3
ooxx
ooxx
ooxx
4 1
null
4 4
aabb
aabb
ccdd
ccdd
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1:
o 0 0
x 2 0
Case 2:
l 2 0
n 0 0
u 1 0
Case 3:
a 0 0
b 2 0
c 0 2
d 2 2
</pre>
|
p02897 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>N</var>.</p>
<p>Takahashi chooses an integer <var>a</var> from the positive integers not greater than <var>N</var> with equal probability.</p>
<p>Find the probability that <var>a</var> is odd.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the probability that <var>a</var> is odd.
Your output will be considered correct when its absolute or relative error from the judge's output is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0.5000000000
</pre>
<p>There are four positive integers not greater than <var>4</var>: <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>. Among them, we have two odd numbers: <var>1</var> and <var>3</var>. Thus, the answer is <var>\frac{2}{4} = 0.5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0.6000000000
</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.0000000000
</pre></section>
</div>
</span> |
p03785 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Every day, <var>N</var> passengers arrive at Takahashi Airport.
The <var>i</var>-th passenger arrives at time <var>T_i</var>.</p>
<p>Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to <var>C</var> passengers.
Naturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport.
Also, a passenger will get angry if he/she is still unable to take a bus <var>K</var> units of time after the arrival of the airplane.
For that reason, it is necessary to arrange buses so that the <var>i</var>-th passenger can take a bus departing at time between <var>T_i</var> and <var>T_i + K</var> (inclusive).</p>
<p>When setting the departure times for buses under this condition, find the minimum required number of buses.
Here, the departure time for each bus does not need to be an integer, and there may be multiple buses that depart at the same time.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100000</var></li>
<li><var>1 \leq C \leq 10^9</var></li>
<li><var>1 \leq K \leq 10^9</var></li>
<li><var>1 \leq T_i \leq 10^9</var></li>
<li><var>C</var>, <var>K</var> and <var>T_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>C</var> <var>K</var>
<var>T_1</var>
<var>T_2</var>
<var>:</var>
<var>T_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum required number of buses.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3 5
1
2
3
6
12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>For example, the following three buses are enough:</p>
<ul>
<li>A bus departing at time <var>4.5</var>, that carries the passengers arriving at time <var>2</var> and <var>3</var>.</li>
<li>A bus departing at time <var>6</var>, that carries the passengers arriving at time <var>1</var> and <var>6</var>.</li>
<li>A bus departing at time <var>12</var>, that carries the passenger arriving at time <var>12</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 3 3
7
6
2
8
10
6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre></section>
</div>
</span> |
p04040 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>AÃB</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ⊠H, W ⊠100,000</var></li>
<li><var> 1 ⊠A < H</var></li>
<li><var> 1 ⊠B < W</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>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2Ã3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</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>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
p00900 |
<H1><font color="#000">Problem G: </font>Captain Q′s Treasure</H1>
<p>
You got an old map, which turned out to be drawn by the infamous pirate “Captain Q”. It shows the locations of a lot of treasure chests buried in an island.
</p>
<p>
The map is divided into square sections, each of which has a digit on it or has no digit. The digit represents the number of chests in its 9 neighboring sections (the section itself and its 8 neighbors). You may assume that there is at most one chest in each section.
</p>
<p>
Although you have the map, you can't determine the sections where the chests are buried. Even the total number of chests buried in the island is unknown. However, it is possible to calculate the minimum number of chests buried in the island. Your mission in this problem is to write a program that calculates it.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows.
</p>
<p>
<i>h w<br>
map</i>
</p>
<p>
The first line of a dataset consists of two positive integers <i>h</i> and <i>w</i>. <i>h</i> is the height of the map and w is the width of the map. You may assume 1≤<i>h</i>≤15 and 1≤<i>w</i>≤15.
</p>
<p>
The following h lines give the map. Each line consists of w characters and corresponds to a horizontal strip of the map. Each of the characters in the line represents the state of a section as follows.
</p>
<p>
‘.’: The section is not a part of the island (water). No chest is here.
</p>
<p>
‘*’: The section is a part of the island, and the number of chests in its 9 neighbors is not known.
</p>
<p>
‘0’-‘9’: The section is a part of the island, and the digit represents the number of chests in its 9 neighbors.
</p>
<p>
You may assume that the map is not self-contradicting, i.e., there is at least one arrangement of chests. You may also assume the number of sections with digits is at least one and at most 15.
</p>
<p>
A line containing two zeros indicates the end of the input.
</p>
<H2>Output</H2>
<p>
For each dataset, output a line that contains the minimum number of chests. The output should not contain any other character.
</p>
<H2>Sample Input</H2>
<pre>
5 6<br>*2.2**<br>..*...<br>..2...<br>..*...<br>*2.2**<br>6 5<br>.*2*.<br>..*..<br>..*..<br>..2..<br>..*..<br>.*2*.<br>5 6<br>.1111.<br>**...*<br>33....<br>**...0<br>.*2**.<br>6 9<br>....1....<br>...1.1...<br>....1....<br>.1..*..1.<br>1.1***1.1<br>.1..*..1.<br>9 9<br>*********<br>*4*4*4*4*<br>*********<br>*4*4*4*4*<br>*********<br>*4*4*4*4*<br>*********<br>*4*4*4***<br>*********<br>0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>6<br>5<br>5<br>6<br>23</pre> |
p01612 |
<h2>ç€Ÿå¡æ
è¡</h2>
<h2>Problem Statement</h2>
<p>ããªãã®äŒç€Ÿã«ã¯<var>n</var>人ã®ç€Ÿå¡ãååšããïŒ<var>m</var>åã®ç€Ÿå¡<var>(a_i,b_i)</var>ã®çµã«ã€ããŠïŒ<var>a_i</var>ã¯<var>b_i</var>ã®äžåžã§ããïŒ</p>
<p>瀟å¡<var>x</var>ã瀟å¡<var>y</var>ã®å®è³ªçãªäžåžã§ãããšã¯ïŒæ¬¡ã®ãã¡å°ãªããšãäžæ¹ãæãç«ã€ããšãããïŒ<br /></p>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>x</var>ã<var>y</var>ã®äžåžã§ããïŒ</li>
<li><var>y</var>ã®å®è³ªçãªäžåžã§ãã瀟å¡<var>z</var>ãååšããŠïŒ<var>x</var>ã¯<var>z</var>ã®äžåžã§ããïŒ</li></ul>
<p>ããªãã®äŒç€Ÿã§ïŒèªåèªèº«ãèªåã®å®è³ªçãªäžåžã§ãããããªç€Ÿå¡ã¯ååšããªãïŒ</p>
<p>ããªãã®äŒç€Ÿã§ã¯ç€Ÿå¡ãå
šå¡åå ããç€Ÿå¡æ
è¡ãèšç»ãããŠããïŒå
šç€Ÿå¡ã®èŠæ±ã«ããïŒæ
通ã§ã®éšå±å²ãã¯ãããéšå±å²ããã§ãªããã°ãªããªãïŒ<br />
ããéšå±å²ãããããéšå±å²ããã§ãããšã¯ä»¥äžã®äž¡æ¹ãæºããããããšãããïŒ<br /></p>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li>å瀟å¡ã¯ã©ããã®éšå±ã«å²ãæ¯ãããïŒ</li>
<li>瀟å¡<var>x</var>ãšç€Ÿå¡<var>y</var>ãåãéšå±ã«å²ãæ¯ãããŠãããšãïŒ<var>x</var>ã¯<var>y</var>ã®å®è³ªçãªäžåžã§ãªãïŒ</li></ul>
<p>å¹¹äºã®ç€Ÿå¡ã¯éåžžã«åªç§ãªã®ã§ïŒãããéšå±å²ããã§ãã€å¿
èŠãªéšå±ã®æ°ãæå°ã«ãªãããã«éšå±å²ããè¡ã£ãïŒãããæ®å¿µãªããšã«äºç®ãäžè¶³ããŠããïŒã©ãããŠãå¿
èŠãªéšå±ã®æ°ãæžãããªããã°ãªããªããããïŒ<br />
ããã§ïŒäººäºéšã§åãããªãã¯äžåž-éšäžã®é¢ä¿ãäžã€ã ãè§£æ¶ããããšã«ãã£ãŠïŒãããéšå±å²ãããåŸãããã«å¿
èŠãªéšå±ã®æ°ãæžããããšã«ããïŒ<br />
ããŠïŒã©ã®é¢ä¿ãè§£æ¶ããã°ããã®ã ããïŒ</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ</p>
<pre><var>n</var> <var>m</var>
<var>a_1</var> <var>b_1</var>
<var>...</var>
<var>a_m</var> <var>b_m</var></pre>
<h2>Constraints</h2>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>2âŠnâŠ10^5</var></li>
<li><var>1âŠmâŠ2 \times 10^5</var></li>
<li><var>1âŠa_i<b_iâŠn</var></li>
<li><var>i \neq j</var>ãªãã°<var>(a_i, b_i) \neq (a_j, b_j)</var></li></ul>
<h2>Output</h2>
<p>æ¬¡ãæºãããããª<var>i</var>ãæé ã«1è¡ãã€åºåããïŒ</p>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li>ã<var>a_i</var>ã<var>b_i</var>ã®äžåžã§ããããšããé¢ä¿ãè§£æ¶ãããšãïŒãããéšå±å²ãããåŸãããã«å¿
èŠãªéšå±ã®æ°ãæžããããšãã§ããïŒ</li></ul>
<p>ãã®ãããª<var>i</var>ãååšããªãå Žåã¯-1ã1è¡ã«åºåããïŒ</p>
<h2>Sample Input 1</h2>
<pre>5 4
1 2
2 3
3 4
3 5</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
2</pre>
|
p01307 |
<h1><font color="#000">Problem E:</font> è¶³ãç®ã²ãŒã </h1>
<p>
ããã®ãã¡ãŒãã«ã¯è¶³ãç®ãçšããç°¡åãªã²ãŒã ãæãã€ããåããããã§åéã®ãªãŒããªãŒãšäžç·ã«ãã£ãŠã¿ãããšã«ããã
</p>
<p>
ã²ãŒã ã®ã«ãŒã«ã¯æ¬¡ã®ãããªãã®ã§ããããŸãæåã«ãé©åœãªæ£ã®æŽæ°ãéžã³ãããããã¹ã¿ãŒããããåãã¬ãŒã€ãŒã¯ããã®æ°ã®ãã¡é£ãåã2ã€ã®æ¡ãéžæããŠåãèšç®ããããšã®2ã€ã®æ°åãšçœ®ãæãããããšãã°ãã1234ãã®åã®äœãšçŸã®äœãéžã¶ãšãæ¬¡ã®æ°ã¯ã154ããšãªããã5555ãã®åã®äœãšçŸã®äœãéžãã å Žåã¯ã5105ããšãªãããã®ãããªæäœãæ°ã1æ¡ã«ãªããŸã§äº€äºã«ç¹°ãè¿ããæäœãã§ããªããªã£ããã¬ãŒã€ãŒãè² ããšãªãã
</p>
<p>
ã²ãŒã éå§æã®æŽæ°ã®å€ãäžãããããå
æ»ã§ãããã¡ãŒãã«ãšåŸæ»ã§ãããªãŒããªãŒãããããæé©ãªæŠç¥ãåããšããã©ã¡ããåã€ã®ããå€å®ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ãã²ãŒã éå§æã®æ°ã衚ã1000æ¡ä»¥äžã®æ£ã®æŽæ°ã1ã€æžããã1è¡ã®ã¿ãããªãããªããæäžäœã®æ¡ã¯0ã§ã¯ãªãã
</p>
<h2>Output</h2>
<p>
ãã¡ãŒãã«ãåã€ãªã "Fabre wins."ããªãŒããªãŒãåã€ãªã "Audrey wins." ãš1è¡ã«åºåãããæåŸã«ããªãªããã€ããå¿
èŠãããããšã«æ³šæããããšã
</p>
<h2>Notes on Submission</h2>
<p>
äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã
</p>
<h2>Sample Input</h2>
<pre>
3
1234
5555
9
</pre>
<h2>Output for the Sample Input</h2>
<pre>
Audrey wins.
Fabre wins.
Audrey wins.
</pre>
|
p03290 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A programming competition site <em>AtCode</em> provides algorithmic problems.
Each problem is allocated a score based on its difficulty.
Currently, for each integer <var>i</var> between <var>1</var> and <var>D</var> (inclusive), there are <var>p_i</var> problems with a score of <var>100i</var> points.
These <var>p_1 + ⊠+ p_D</var> problems are all of the problems available on AtCode.</p>
<p>A user of AtCode has a value called <em>total score</em>.
The total score of a user is the sum of the following two elements:</p>
<ul>
<li>Base score: the sum of the scores of all problems solved by the user.</li>
<li>Perfect bonuses: when a user solves all problems with a score of <var>100i</var> points, he/she earns the perfect bonus of <var>c_i</var> points, aside from the base score <var>(1 †i †D)</var>.</li>
</ul>
<p>Takahashi, who is the new user of AtCode, has not solved any problem.
His objective is to have a total score of <var>G</var> or more points.
At least how many problems does he need to solve for this objective?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †D †10</var></li>
<li><var>1 †p_i †100</var></li>
<li><var>100 †c_i †10^6</var></li>
<li><var>100 †G</var></li>
<li>All values in input are integers.</li>
<li><var>c_i</var> and <var>G</var> are all multiples of <var>100</var>.</li>
<li>It is possible to have a total score of <var>G</var> or more points.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>D</var> <var>G</var>
<var>p_1</var> <var>c_1</var>
<var>:</var>
<var>p_D</var> <var>c_D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of problems that needs to be solved in order to have a total score of <var>G</var> or more points. Note that this objective is always achievable (see Constraints).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 700
3 500
5 800
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>In this case, there are three problems each with <var>100</var> points and five problems each with <var>200</var> points. The perfect bonus for solving all the <var>100</var>-point problems is <var>500</var> points, and the perfect bonus for solving all the <var>200</var>-point problems is <var>800</var> points. Takahashi's objective is to have a total score of <var>700</var> points or more.</p>
<p>One way to achieve this objective is to solve four <var>200</var>-point problems and earn a base score of <var>800</var> points. However, if we solve three <var>100</var>-point problems, we can earn the perfect bonus of <var>500</var> points in addition to the base score of <var>300</var> points, for a total score of <var>800</var> points, and we can achieve the objective with fewer problems.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2000
3 500
5 800
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
<p>This case is similar to Sample Input 1, but the Takahashi's objective this time is <var>2000</var> points or more. In this case, we inevitably need to solve all five <var>200</var>-point problems, and by solving two <var>100</var>-point problems additionally we have the total score of <var>2000</var> points.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 400
3 500
5 800
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
<p>This case is again similar to Sample Input 1, but the Takahashi's objective this time is <var>400</var> points or more. In this case, we only need to solve two <var>200</var>-point problems to achieve the objective.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 25000
20 1000
40 1000
50 1000
30 1000
1 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>66
</pre>
<p>There is only one <var>500</var>-point problem, but the perfect bonus can be earned even in such a case. </p></section>
</div>
</span> |
p02878 | <span class="lang-en">
<p>Score : <var>2200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two indistinguishable pieces placed on a number line.
Both pieces are initially at coordinate <var>0</var>. (They can occupy the same position.)</p>
<p>We can do the following two kinds of operations:</p>
<ul>
<li>Choose a piece and move it to the right (the positive direction) by <var>1</var>.</li>
<li>Move the piece with the smaller coordinate to the position of the piece with the greater coordinate.
If two pieces already occupy the same position, nothing happens, but it still counts as doing one operation.</li>
</ul>
<p>We want to do a total of <var>N</var> operations of these kinds in some order so that one of the pieces will be at coordinate <var>A</var> and the other at coordinate <var>B</var>.
Find the number of ways to move the pieces to achieve it.
The answer can be enormous, so compute the count modulo <var>998244353</var>.</p>
<p>Two ways to move the pieces are considered different if and only if there exists an integer <var>i</var> (<var>1 \leq i \leq N</var>) such that the set of the coordinates occupied by the pieces after the <var>i</var>-th operation is different in those two ways.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^7</var></li>
<li><var>0 \leq A \leq B \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</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to move the pieces to achieve our objective, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Shown below are the four ways to move the pieces, where <var>(x,y)</var> represents the state where the two pieces are at coordinates <var>x</var> and <var>y</var>.</p>
<ul>
<li><var>(0,0)â(0,0)â(0,1)â(0,2)â(0,3)â(1,3)</var></li>
<li><var>(0,0)â(0,0)â(0,1)â(0,2)â(1,2)â(1,3)</var></li>
<li><var>(0,0)â(0,0)â(0,1)â(1,1)â(1,2)â(1,3)</var></li>
<li><var>(0,0)â(0,1)â(1,1)â(1,1)â(1,2)â(1,3)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 0 0
</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>10 4 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>197
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1000000 100000 200000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>758840509
</pre></section>
</div>
</span> |
p00845 | <H1><font color="#000">Problem A:</font> How I Wonder What You Are!</H1>
<p>
One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be
limited, you may find much less at a time.
</p>
<p>
Children may ask the same questions to their parents on a planet of some solar system billions
of light-years away from the Earth. Their telescopes are similar to ours with circular sight fields,
but alien kids have many eyes and can look into different directions at a time through many
telescopes.
</p>
<p>
Given a set of positions of stars, a set of telescopes and the directions they are looking to, your
task is to count up how many stars can be seen through these telescopes.
</p>
<H2>Input</H2>
<p>
The input consists of one or more datasets. The number of datasets is less than 50. Each dataset
describes stars and the parameters of the telescopes used.
</p>
<p>
The first line of a dataset contains a positive integer <i>n</i> not exceeding 500, meaning the number
of stars. Each of the <i>n</i> lines following it contains three decimal fractions, <i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, and <i>s<sub>z</sub></i>. They
give the position (<i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, <i>s<sub>z</sub></i>) of the star described in Euclidean coordinates. You may assume
-1000 ≤ <i>s<sub>x</sub></i> ≤ 1000, -1000 ≤ <i>s<sub>y</sub></i> ≤ 1000, -1000 ≤ <i>s<sub>z</sub></i> ≤ 1000 and (<i>s<sub>x</sub></i>, <i>s<sub>y</sub></i>, <i>s<sub>z</sub></i>) ≠ (0, 0, 0).
</p>
<p>
Then comes a line containing a positive integer <i>m</i> not exceeding 50, meaning the number of
telescopes. Each of the following <i>m</i> lines contains four decimal fractions, <i>t<sub>x</sub></i>, <i>t<sub>y</sub></i>, <i>t<sub>z</sub></i>, and <i>φ</i>, describing a telescope.
</p>
<p>
The first three numbers represent the direction of the telescope. All the telescopes are at the
origin of the coordinate system (0, 0, 0) (we ignore the size of the planet). The three numbers give
the point (<i>t<sub>x</sub></i>, <i>t<sub>y</sub></i>, <i>t<sub>z</sub></i>) which can be seen in the center of the sight through the telescope. You may
assume -1000 ≤ <i>t<sub>x</sub></i> ≤ 1000, -1000 ≤ <i>t<sub>y</sub></i> ≤ 1000, -1000 ≤ <i>t<sub>z</sub></i> ≤ 1000 and (<i>t<sub>x</sub></i>, <i>t<sub>y</sub></i>, <i>t<sub>z</sub></i>) ≠ (0, 0, 0).
</p>
<p>
The fourth number <i>φ</i> (0 ≤ <i>φ</i> ≤ <i>π</i>/2) gives the angular radius, in radians, of the sight field of
the telescope.
</p>
<p>
Let us defie that <i>θ<sub>i,j</sub></i> is the angle between the direction of the <i>i</i>-th star and the center direction
of the <i>j</i>-th telescope and <i>φ<sub>j</sub></i>is the angular radius of the sight field of the <i>j</i>-th telescope. The <i>i</i>-th star is observable through the <i>j</i>-th telescope if and only if <i>θ<sub>i,j</sub></i> is less than . You may assume that |<i>θ<sub>i,j</sub></i> - <i>φ<sub>j</sub></i>| > 0.00000001 for all pairs of <i>i</i> and <i>j</i>.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_howIWonder"><br/>
<p>Figure 1: Direction and angular radius of a telescope</p>
</center>
<p>
The end of the input is indicated with a line containing a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset, one line containing an integer meaning the number of stars observable through
the telescopes should be output. No other characters should be contained in the output. Note
that stars that can be seen through more than one telescope should not be counted twice or
more.
</p>
<H2>Sample Input</H2>
<pre>
3
100 0 500
-500.243 -200.1 -300.5
0 300 200
2
1 1 1 0.65
-1 0 0 1.57
3
1 0 0
0 1 0
0 0 1
4
1 -1 -1 0.9553
-1 1 -1 0.9554
-1 -1 1 0.9553
-1 1 -1 0.9554
3
1 0 0
0 1 0
0 0 1
4
1 -1 -1 0.9553
-1 1 -1 0.9553
-1 -1 1 0.9553
-1 1 -1 0.9553
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
1
0
</pre>
|
p01757 |
<p>
ä»å¹ŽãïŒå
šåœããã°ã©ãã³ã°éžææš©å€§äŒã®ææããã£ãŠããïŒå
šåœå€§äŒã®åå æš©ãè³ããå°åºå€§äŒã¯ïŒ <var>2<sup>n</sup></var> ããŒã ã1 察1 ã®åã¡æ®ãåŒããŒãã¡ã³ãæ¹åŒã§å¯Ÿæ±ºããïŒ
</p>
<p>
ããŒãã¡ã³ã衚ã«ã¯ããŒã çªå· <var>0, . . . 2<sup>n</sup> − 1</var> ãå²ãæ¯ãããŠããïŒ1 åæŠãã <var>n</var> åæŠãŸã§ã®å¯Ÿæ±ºæé ã¯æ¬¡ã®éãã§ããïŒ
</p>
<ol>
<li> 1 åæŠã§ã¯ïŒïŒããŒã çªå·ã <var>l</var> ã®ããŒã ïŒãšïŒããŒã çªå·ã <var>l</var> + 1 ã®ããŒã ïŒã察決ããïŒ(<var>l</var> ≡ 0 (mod 2))
</li>
<li> <var>i + 1</var> åæŠ(<var>1 ≤ i < n</var>) ã§ã¯ïŒãããŒã çªå·ã <var>l</var> ä»¥äž <var>l + 2<sup>i</sup></var> æªæºã®ããŒã ã®ãã¡ïŒ <var>i</var> åæŠãŸã§ã®å¯Ÿæ±ºã§ 1 åãè² ããŠããªãããŒã ããšãããŒã çªå·ã <var>l + 2<sup>i</sup></var> ä»¥äž <var>l + 2<sup>i+1</sup></var> æªæºã®ããŒã ã®ãã¡ïŒ <var>i</var> åæŠãŸã§ã®å¯Ÿæ±ºã§äžåãè² ããŠããªãããŒã ãã察決ããïŒ(<var>l</var> ≡ 0 (mod 2<sup><var>i</var>+1</sup>))
</ol>
<p>
<var>n</var> åæŠãŸã§çµãããšïŒåããŒã ã®é äœã¯ 2<sup><var>n</var> − (ãã®ããŒã ãåã£ãåæ°)</sup> äœã§ç¢ºå®ããïŒãªãïŒãã®å¯Ÿæ±ºã«ã¯åŒãåããååšããªãããïŒå¯Ÿæ±ºããããŒã ã®ããããäžæ¹ãåã¡ïŒããäžæ¹ãè² ããïŒ
</p>
<p>
æŽããŠå°åºå€§äŒã®ä»£è¡šã«éžã°ããç§éã¯ïŒä»ã®å°åºå€§äŒã®çµæããããŒãžã£ãŒã«èª¿ã¹ãŠãããããšã«ããïŒããã§èª¿ã¹ãŠããã£ãçµæãããããŒãžã£ãŒããåãåã£ãé äœè¡šãã§ãã£ãïŒããããŒãžã£ãŒããåãåã£ãé äœè¡šãããã詳现ã«èª¬æãããšïŒé·ã 2<sup><var>n</var></sup> ã®æ°åã§ <var>i ( 0 ≤ i ≤ 2<sup>n</sup> − 1 )</var> çªç®ã®èŠçŽ ã«ããŒã çªå· <var>i</var> ã®ããŒã ã®é äœãæžãããŠãããã®ã§ããïŒ
</p>
<p>
ã ãïŒããããŒãžã£ãŒããåãåã£ãé äœè¡šãã«ã¯åãé äœã倧éã«äžŠãã§ããïŒããŒãã¡ã³ãã®ã«ãŒã«äžïŒåãé äœã倧éã«äžŠã¶ãªããŠããããªãã¯ãã ïŒããã§ïŒããããŒãžã£ãŒããåãåã£ãé äœè¡šãããç¡ççŸãªé äœè¡šãã«ããããã«é äœã倿ŽããããŒã æ°ã®æå°å€ãèšç®ããŠã©ã®ãããé äœè¡šãééã£ãŠãããããããŒãžã£ãŒã«æããŠããããïŒãç¡ççŸãªé äœè¡šããšã¯ïŒé äœã確å®ããããŒãã¡ã³ãã®çµæãšããŠèµ·ããããé äœè¡šã®ããšã衚ãïŒ
</p>
<h3>Input</h3>
<p>
å
¥åã«ã¯ïŒããããŒãžã£ãŒããåãåã£ãé äœè¡šãã以äžã®åœ¢åŒã§äžããããïŒ
</p>
<pre>
<var>n</var> <var>m</var>
<var>a<sub>0</sub></var> <var>a<sub>1</sub></var> . . . <var>a<sub>m</sub></var>
<var>b<sub>0</sub></var> <var>b<sub>1</sub></var> . . . <var>b<sub>m−1</sub></var>
</pre>
<ul>
<li> 1 è¡ç®ã¯ <var>n, m</var> ã®2 åã®æŽæ°ãããªãïŒ 2<sup><var>n</var></sup> ã¯ãå°åºå€§äŒã®åå ããŒã æ°ãïŒ<var>m</var> ã¯ãããããŒãžã£ãŒããåãåã£ãé äœè¡šãã§é£ç¶ããé äœã䞊ãã§ããåºéã®åæ°ãã衚ãïŒ</li>
<li> 2 è¡ç®ã¯ <var>a<sub>i</sub>(0 ≤ i ≤ m)</var> ã® <var>m + 1</var> åã®æŽæ°ãããªãïŒå <var>a<sub>i</sub></var> ã¯ãããããŒãžã£ãŒããåãåã£ãé äœè¡šãã§é£ç¶ããé äœã䞊ãã§ããåºéã®åºåãäœçœ®ãã衚ãïŒ
</li>
<li> 3 è¡ç®ã¯ <var>b<sub>i</sub>(0 ≤ i < m)</var> ã® <var>m</var> åã®æŽæ°ãããªãïŒå2<sup><var>b<sub>i</sub></var></sup> ã¯ãããããŒãžã£ãŒããåãåã£ãé äœè¡šãã«ãããããŒã çªå·ã <var>a<sub>i</sub></var> ä»¥äž <var>a<sub>i+1</sub></var> æªæºã®ããŒã ã®é äœãã衚ãïŒ
</li>
</ul>
<h3>Constraints</h3>
<ul>
<li> 1 ≤ <var>n</var> ≤ 30</li>
<li> 1 ≤ <var>m</var> ≤ 10,000</li>
<li> <var>0 = a<sub>0</sub> < a<sub>1</sub> ≤ . . . ≤ a<sub>m−1</sub> < a<sub>m</sub> = 2<sup>n</sup></var></li>
<li> 0 ≤ <var>b<sub>i</sub></var> ≤ <var>n</var></li>
</ul>
<h3>Output</h3>
<p>
ããããŒãžã£ãŒããåãåã£ãé äœè¡šãããç¡ççŸãªé äœè¡šãã«ããããã«é äœã倿ŽããããŒã æ°ã®æå°å€ã1 è¡ã«åºåããïŒ
</p>
<h3>Sample Input 1</h3>
<pre>
1 1
0 2
1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
1
</pre>
<p>
åå ããŒã æ°ã2 ã®ãç¡ççŸãªé äœè¡šãã¯ïŒ{"ããŒã çªå· 0 ã®ããŒã ã®é äœ", "ããŒã çªå· 1 ã®ããŒã ã®é äœ"} ãšã㊠{1, 2} ãš {2, 1} ã®2 éããããïŒé äœè¡š {2, 2} ããç¡ççŸãªé äœè¡šãã«ä¿®æ£ããããã«ã¯ïŒããããã®ããŒã ã®é äœã 1 ã«å€æŽããªããã°ãªããªãïŒ
</p>
<h3>Sample Input 2</h3>
<pre>
2 3
0 1 2 4
0 1 2
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
2
</pre>
<h3>Sample Input 3</h3>
<pre>
2 3
0 1 3 4
0 2 1
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
4 5
0 1 2 4 8 16
0 1 2 3 4
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
10
</pre>
|
p00516 |
<H1>åé¡ 2: ãæç¥š (Vote)
</H1>
<br/>
<h2>åé¡</h2>
<p>
20XXå¹Žã«æ±äº¬ã§äžççãªã¹ããŒã倧äŒãéãããããšã«ãªã£ãïŒããã°ã©ãã³ã°ã³ã³ãã¹ãã¯ã¹ããŒããšããŠäžçã§æ¥œããŸããŠããïŒç«¶æãšããŠæ¡çšãããå¯èœæ§ãããïŒæ¡çšãããç«¶æã決ãã審æ»å§å¡äŒã«ã€ããŠèª¿ã¹ããšããïŒæ¬¡ã®ãããªããšãåãã£ãïŒ
</p>
<ul>
<li>
審æ»å§å¡äŒã®ããã«ïŒåè£ãšãªã N åã®ç«¶æãé¢çœãæ¹ããé çªã«äžŠã¹ããªã¹ããäœæãããïŒãªã¹ãã®äžãã i çªç®ã«ã¯ i çªç®ã«é¢çœãç«¶æãæžãããŠããïŒãããç«¶æ i ãšããïŒããã«ç«¶æ i ã®éå¬ã«å¿
èŠãªè²»çš A<sub>i</sub> ãæžãããŠããïŒ
</li>
<li>ãŸãïŒå¯©æ»å§å¡äŒã¯å§å¡ 1 ããå§å¡ M ãŸã§ã® M 人ã®å§å¡ã§æ§æãããŠããïŒå§å¡ j ã¯èªåã®å¯©æ»åºæº B<sub>j</sub> ããã£ãŠããïŒéå¬ã«å¿
èŠãªè²»çšã B<sub>j</sub> 以äžã®ç«¶æã®ãã¡æãé¢çœããã®ã« 1 祚ãæç¥šããïŒ
</li>
<li>
ã©ã®å§å¡ã®å¯©æ»åºæºã«å¯ŸããŠãïŒå°ãªããšã 1 ã€ã®ç«¶æã¯éå¬ã«å¿
èŠãªè²»çšã審æ»åºæºä»¥äžã§ãã£ãïŒãããã£ãŠïŒå§å¡ã¯å
šå¡ 1 祚ãæç¥šããïŒ
</li>
<li>
æãå€ã祚ãç²åŸããç«¶æã¯ 1 ã€ã ãã§ãã£ãïŒ
</li>
</ul>
<p>
ç«¶æã®ãªã¹ããšå§å¡ã®æ
å ±ãäžãããããšãïŒæãå€ã祚ãç²åŸããç«¶æã®çªå·ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥å㯠1 + N + M è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯æŽæ° N, M (1 ≤ N ≤ 1000ïŒ1 ≤ M ≤ 1000) ãæžãããŠããïŒããããç«¶æã®æ°ïŒå§å¡ã®æ°ã衚ãïŒ
</p>
<p>
ç¶ã N è¡ã®ãã¡ã® i è¡ç® (1 ≤ i ≤ N) ã«ã¯æŽæ° A<sub>i</sub> (1 ≤ A<sub>i</sub> ≤ 1000) ãæžãããŠããïŒ ç«¶æ i ã®éå¬ã«å¿
èŠãªè²»çš A<sub>i</sub> ã衚ãïŒ
</p>
<p>
ç¶ã M è¡ã®ãã¡ã® j è¡ç® (1 ≤ j ≤ M) ã«ã¯æŽæ° B<sub>j</sub> (1 ≤ B<sub>j</sub> ≤ 1000) ãæžãããŠããïŒå§å¡ j ã®å¯©æ»åºæº B<sub>j</sub> ã衚ãïŒ
</p>
<p>
äžããããå
¥åããŒã¿ã«ãããŠã¯ïŒã©ã®å§å¡ãå¿
ã 1 祚ãæç¥šãïŒæãå€ã祚ãç²åŸããç«¶æã¯ 1 ã€ã§ããããšãä¿èšŒãããŠããïŒ
</p>
<h2>åºå</h2>
<p>
æãå€ã祚ãç²åŸããç«¶æã®çªå·ã 1 è¡ã§åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
4 3
5
3
1
4
4
3
2
</pre>
<h3>åºåäŸ 1</h3>
<pre>
2
</pre>
<p>
å
¥åºåäŸ 1 ã§ã¯ïŒç«¶æã¯ 4 ã€ããïŒå§å¡ã¯ 3 人ããïŒãªã¹ãã® 4 ã€ã®ç«¶æã«ãããè²»çšã¯ãããã 5, 3, 1, 4 ã§ããïŒ
</p>
<ul>
<li>å§å¡ 1 ã®å¯©æ»åºæºã¯ 4 ã§ããïŒè²»çšã 4 以äžã®ç«¶æã®ãã¡æãé¢çœããã®ã¯ç«¶æ 2 ã§ããïŒ</li>
<li>å§å¡ 2 ã®å¯©æ»åºæºã¯ 3 ã§ããïŒè²»çšã 3 以äžã®ç«¶æã®ãã¡æãé¢çœããã®ã¯ç«¶æ 2 ã§ããïŒ</li>
<li>å§å¡ 3 ã®å¯©æ»åºæºã¯ 2 ã§ããïŒè²»çšã 2 以äžã®ç«¶æã®ãã¡æãé¢çœããã®ã¯ç«¶æ 3 ã§ããïŒ</li>
</ul>
<p>
ãã£ãŠïŒç«¶æ 2 ã 2 祚ïŒç«¶æ 3 ã 1 祚ãç²åŸããïŒæãå€ã祚ãç²åŸããç«¶æã¯ç«¶æ 2 ã§ããã®ã§ïŒ2 ãåºåããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
6 6
3
1
4
1
5
9
2
6
5
3
5
9
</pre>
<h3>åºåäŸ 2</h3>
<pre>
1
</pre>
<p>
å
¥åºåäŸ 2 ã§ã¯ïŒç«¶æ 1 ã 5 祚ïŒç«¶æ 2 ã 1 祚ãç²åŸããïŒæãå€ã祚ãç²åŸããç«¶æã¯ç«¶æ 1 ãªã®ã§ïŒ1 ãåºåããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00146 |
<H1>ã«ãã³åäž</H1>
<p>
æªçãã«ãã³åäžãã¯äŒæŽ¥è©å£«ãæ«è£ãšããçŸå¥³ãå¯å£«å³°åããããäŒæŽ¥è¥æŸåžã«äŒæŽ¥è©ãæ®ããè»è³éãç ã£ãŠããããšãèãããããã«ãã³ã®é·å¹Žã®ä»²éã§ãããç³å·è¶ã§éãã®å ±åã«ããã°ãè»è³éã¯å䞡箱ã«åãããããã€ãã®èµã«ä¿ç®¡ãããŠãããèµã«èŠåŒµãã¯ããªããå³éã«æœé ãããŠãããããããè¶ã§éã¯åœŒãç¶ããäŒæãããç§äŒãéŒéæ¬ããã®æãç¹°ãåºãã°ç¬æã«èµãç Žãããšããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lupin">
</center>
<br/>
<p>
æ®ã£ãåé¡ã¯å䞡箱ã®éæ¬ã ãäœåã®ãªãã«ãã³ãšè¶ã§éã¯å䞡箱ãäžã€ãæãŠãªããããã§ãé Œãã«ãªãç·ãç¡é倧ä»ãã«éæ¬ãé Œãã ã<!--倧ä»ã¯ç±³ä¿µã䜿ã£ãèšç·Žãéããè¶
人çãªéæ¬èœåã身ã«ã€ããã-->
ãã¹ãŠã®å䞡箱ãéã³åºãããã«ãã«ãã³ã¯ä»¥äžã®ãããªèšç»ãç«æ¡ããã
</p>
<p>
ãŸããã«ãã³ã®éè»¢ã§æåã®èµãžè¡ããè¶ã§éãšå€§ä»ãéããã
</p>
<ul>
<li>è¶ã§éãèµãç Žã</li>
<li>倧ä»ããã¹ãŠã®å䞡箱ãéã³åºã</li>
<li>ãã®å䞡箱ãæã£ããŸãŸã«ãã³ã決ããæ¬¡ã®èµãžåãã</li>
</ul>
<p>
ãããç¹°ãè¿ããæåŸã®èµãŸã§ç Žãå䞡箱ãéã³åºãããã®éã«ã«ãã³ã¯ããªã³ãã¿ãŒãæºåãæåŸã®èµã§äºäººãšå䞡箱ãéã³äžãè±åºããã倧ä»ã¯ã©ããªã«éããã®ã鿬ã§ããããè·ç©ã®éãã«å¿ããŠç§»åé床ã¯é
ããªããã«ãã³ã¯ããã®ããšãèæ
®ããŠèµãç Žãé çªã決ããªããã°ãªããªãã
</p>
<p>
ã«ãã³ã«ä»£ãã£ãŠãæåã®èµãç Žã£ãŠããæåŸã®èµã«èŸ¿ãã€ããŸã§ã®ç§»åæéãæå°ãšãªããããªèµãç Žãé çªãåºåããããã°ã©ã ãäœæããŠãã ããããã ãã
</p>
<ul>
<li>èµã¯ãã¹ãŠé¶Žã¶åãããŸã£ããåã«èµ°ãéãã«é¢ããŠãããèµã®æ°ã¯é«ã
15 åã§ãããåããã®è·é¢ã¯é«ã
10000 ã¡ãŒãã«ä»¥äžã§ããã</li>
<li>å䞡箱ã®éãã¯ããããã²ãšã€ 20 ããã°ã©ã ã§ãããããããã®èµã«åããããŠããå䞡箱ã®åæ°ã¯ 10000 å以äžã§ããã</li>
<li>èµããèµãžã®ç§»åã¯ãéãã«æ²¿ã£ãŠå°äžã«èšçœ®ãããŠããå°äžéã䜿ãã</li>
<li>倧ä»ã¯ <var>w</var> ããã°ã©ã ã®è·ç©ãéã¶ã®ã«ãåé 2,000ïŒ(70 + <var>w</var>) ã¡ãŒãã«ã§ç§»åããã</li>
<!--<li>å¯å£«å³°åã¯èšç»ã劚害ããæããããã®ã§äºåã«ç¡ç è¬ã飲ãŸããŠç ãããããã®ã»ãã®åŠšå®³ã«ã€ããŠããéºæŒãªã察åŠããã</li>-->
</ul>
<p>
å
¥åããŒã¿ã¯ãããããã®èµã«ã€ããŠèµã®çªå·ïŒ100 以äžã®æŽæ°ïŒãšåããã®è·é¢ïŒã¡ãŒãã«ïŒãšãã®èµã«ä¿ç®¡ãããŠããå䞡箱ã®åæ°ãäžããããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>s<sub>1</sub></var> <var>d<sub>1</sub></var> <var>v<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>d<sub>2</sub></var> <var>v<sub>2</sub></var>
:
<var>s<sub>n</sub></var> <var>d<sub>n</sub></var> <var>v<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«èµã®åæ° <var>n</var>ïŒ<var>n</var> ≤ 15ïŒãç¶ã <var>n</var> è¡ã«ç¬¬ <var>i</var> ã®èµã®æ
å ±ãäžããããŸããèµã®æ
å ±ãšããŠãèµã®çªå· <var>s<sub>i</sub></var> (1 ≤ <var>s<sub>i</sub></var> ≤ 100)ãåããã®è·é¢ <var>d<sub>i</sub></var> (1 ≤ <var>d<sub>i</sub></var> ≤ 10000)ã åäž¡ç®±ã®æ° <var>v<sub>i</sub></var> (1 ≤ <var>v<sub>i</sub></var> ≤ 10000) ãïŒè¡ã«äžããããŸãã
</p>
<H2>Output</H2>
<p>
èµãç Žãé çªãïŒè¡ã«åºåããŠãã ãããèµã®çªå·ã空çœã§åºåã£ãŠãã ããã
</p>
<H2>Sample Input 1</H2>
<pre>
2
1 100 1
2 200 2
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
1 2
</pre>
<H2>Sample Input 2</H2>
<pre>
3
11 100 1
13 200 20
12 300 3
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
11 12 13
</pre>
<H2>Sample Input 3</H2>
<pre>
5
13 199 1
51 1000 1
37 350 10
27 300 2
99 200 1000
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
51 37 27 13 99
</pre>
|
p01184 |
<H1><font color="#000">Problem D:</font> International Party</H1>
<p>
Isaac H. Ives is attending an international student party (maybe for girl-hunting). Students there enjoy
talking in groups with excellent foods and drinks. However, since students come to the party from all
over the world, groups may not have a language spoken by all students of the group. In such groups,
some student(s) need to work as interpreters, but intervals caused by interpretation make their talking
less exciting.
</p>
<p>
Needless to say, students want exciting talks. To have talking exciting as much as possible, Isaac proposed
the following rule: the number of languages used in talking should be as little as possible, and not exceed
five. Many students agreed with his proposal, but it is not easy for them to find languages each student
should speak. So he calls you for help.
</p>
<p>
Your task is to write a program that shows the minimum set of languages to make talking possible, given
lists of languages each student speaks.
</p>
<H2>Input</H2>
<p>
The input consists of a series of data sets.
</p>
<p>
The first line of each data set contains two integers <i>N</i> (1 ≤ <i>N</i> ≤ 30) and <i>M</i> (2 ≤ <i>M</i> ≤ 20) separated
by a blank, which represent the numbers of languages and students respectively. The following <i>N</i> lines
contain language names, one name per line. The following <i>M</i> lines describe students in the group. The
<i>i</i>-th line consists of an integer <i>K<sub>i</sub></i> that indicates the number of languages the <i>i</i>-th student speaks, and
<i>K<sub>i</sub></i> language names separated by a single space. Each language name consists of up to twenty alphabetic
letters.
</p>
<p>
A line that contains two zeros indicates the end of input and is not part of a data set.
</p>
<H2>Output</H2>
<p>
Print a line that contains the minimum number <i>L</i> of languages to be spoken, followed by <i>L</i> language
names in any order. Each language name should be printed in a separate line. In case two or more sets of
the same size is possible, you may print any one of them. If it is impossible for the group to enjoy talking
with not more than five languages, you should print a single line that contains âImpossibleâ (without
quotes).
</p>
<p>
Print an empty line between data sets.
</p>
<H2>Sample Input</H2>
<pre>
3 4
English
French
Japanese
1 English
2 French English
2 Japanese English
1 Japanese
2 2
English
Japanese
1 English
1 Japanese
6 7
English
Dutch
German
French
Italian
Spanish
1 English
2 English Dutch
2 Dutch German
2 German French
2 French Italian
2 Italian Spanish
1 Spanish
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
English
Japanese
Impossible
Impossible
</pre>
|
p03443 | <span class="lang-en">
<p>Score : <var>2000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a bridge that connects the left and right banks of a river.
There are <var>2 N</var> doors placed at different positions on this bridge, painted in some colors.
The colors of the doors are represented by integers from <var>1</var> through <var>N</var>.
For each <var>k</var> (<var>1 \leq k \leq N</var>), there are exactly two doors painted in Color <var>k</var>.</p>
<p>Snuke decides to cross the bridge from the left bank to the right bank.
He will keep on walking to the right, but the following event will happen while doing so:</p>
<ul>
<li>At the moment Snuke touches a door painted in Color <var>k</var> (<var>1 \leq k \leq N</var>), he teleports to the right side of the other door painted in Color <var>k</var>.</li>
</ul>
<p>It can be shown that he will eventually get to the right bank.</p>
<p>For each <var>i</var> (<var>1 \leq i \leq 2 N - 1</var>), the section between the <var>i</var>-th and <var>(i + 1)</var>-th doors from the left will be referred to as Section <var>i</var>.
After crossing the bridge, Snuke recorded whether or not he walked through Section <var>i</var>, for each <var>i</var> (<var>1 \leq i \leq 2 N - 1</var>).
This record is given to you as a string <var>s</var> of length <var>2 N - 1</var>.
For each <var>i</var> (<var>1 \leq i \leq 2 N - 1</var>), if Snuke walked through Section <var>i</var>, the <var>i</var>-th character in <var>s</var> is <code>1</code>; otherwise, the <var>i</var>-th character is <code>0</code>.</p>
<div style="text-align: center;">
<img src="https://img.atcoder.jp/cookie/970b981380ffad7745008433034c0885.png">
<p>Figure: A possible arrangement of doors for Sample Input 3</p>
</img></div>
<p>Determine if there exists an arrangement of doors that is consistent with the record. If it exists, construct one such arrangement.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>|s| = 2 N - 1</var></li>
<li><var>s</var> consists of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there is no arrangement of doors that is consistent with the record, print <code>No</code>.
If there exists such an arrangement, print <code>Yes</code> in the first line, then print one such arrangement in the second line, in the following format:</p>
<pre><var>c_1</var> <var>c_2</var> <var>...</var> <var>c_{2 N}</var>
</pre>
<p>Here, for each <var>i</var> (<var>1 \leq i \leq 2 N</var>), <var>c_i</var> is the color of the <var>i</var>-th door from the left.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
010
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
1 1 2 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
001
</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>3
10110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
1 3 2 1 2 3
</pre>
<p>The figure below is identical to the one in the statement.</p>
<p><img alt="" src="https://img.atcoder.jp/cookie/970b981380ffad7745008433034c0885.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
10101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>6
00111011100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
1 6 1 2 3 4 4 2 3 5 6 5
</pre></section>
</div>
</span> |
p03013 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a staircase with <var>N</var> steps. Takahashi is now standing at the foot of the stairs, that is, on the <var>0</var>-th step.
He can climb up one or two steps at a time.</p>
<p>However, the treads of the <var>a_1</var>-th, <var>a_2</var>-th, <var>a_3</var>-th, <var>\ldots</var>, <var>a_M</var>-th steps are broken, so it is dangerous to set foot on those steps.</p>
<p>How many are there to climb up to the top step, that is, the <var>N</var>-th step, without setting foot on the broken steps?
Find the count modulo <var>1\ 000\ 000\ 007</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq M \leq N-1</var></li>
<li><var>1 \leq a_1 < a_2 < </var> <var>...</var> <var> < a_M \leq N-1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var>
<var>a_2</var>
<var> .</var>
<var> .</var>
<var> .</var>
<var>a_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to climb up the stairs under the condition, modulo <var>1\ 000\ 000\ 007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 1
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four ways to climb up the stairs, as follows:</p>
<ul>
<li><var>0 \to 1 \to 2 \to 4 \to 5 \to 6</var></li>
<li><var>0 \to 1 \to 2 \to 4 \to 6</var></li>
<li><var>0 \to 2 \to 4 \to 5 \to 6</var></li>
<li><var>0 \to 2 \to 4 \to 6</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 2
4
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There may be no way to climb up the stairs without setting foot on the broken steps.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 5
1
23
45
67
89
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>608200469
</pre>
<p>Be sure to print the count modulo <var>1\ 000\ 000\ 007</var>.</p></section>
</div>
</span> |
p00795 |
<H1><font color="#000">Problem H:</font> Co-occurrence Search</H1>
<p>
A huge amount of information is being heaped on WWW. Albeit it is not well-organized, users can browse WWW as an unbounded source of up-to-date information, instead of consulting established but a little out-of-date encyclopedia. However, you can further exploit WWW by learning more about keyword search algorithms.
</p>
<p>
For example, if you want to get information on recent comparison between Windows and UNIX, you may expect to get relevant description out of a big bunch of Web texts, by extracting texts that contain both keywords "Windows" and "UNIX" close together.
</p>
<p>
Here we have a simplified version of this co-occurrence keyword search problem, where the text and keywords are replaced by a string and key characters, respectively. A character string S of length <i>n</i> (1 ≤ <i>n</i> ≤ 1,000,000) and a set <i>K</i> of <i>k</i> distinct key characters <i>a</i><sub>1</sub>, ..., <i>a<sub>k</sub></i> (1 ≤ <i>k</i> ≤ 50) are given. Find every shortest substring of <i>S</i> that contains all of the key characters <i>a</i><sub>1</sub>, ..., <i>a<sub>k</sub></i>.
</p>
<H2>Input</H2>
<p>
The input is a text file which contains only printable characters (ASCII codes 21 to 7E in hexadecimal) and newlines. No white space such as space or tab appears in the input.
</p>
<p>
The text is a sequence of the shortest string search problems described above. Each problem consists of character string <i>S<sub>i</sub></i> and key character set <i>K<sub>i</sub></i> (<i>i</i> = 1, 2, ..., <i>p</i>). Every <i>S<sub>i</sub></i> and <i>K<sub>i</sub></i> is followed by an empty line. However, any single newline between successive lines in a string should be ignored; that is, newlines are not part of the string. For various technical reasons, every line consists of at most 72 characters. Each key character set is given in a single line. The input is terminated by consecutive empty lines; <i>p</i> is not given explicitly.
</p>
<H2>Output</H2>
<p>
All of <i>p</i> problems should be solved and their answers should be output in order. However, it is not requested to print all of the shortest substrings if more than one substring is found in a problem, since found substrings may be too much to check them all. Only the number of the substrings together with their representative is requested instead. That is, for each problem <i>i</i>, the number of the shortest substrings should be output followed by the first (or the leftmost) shortest substring <i>s</i><sub><i>i</i>1</sub>, obeying the following format:
</p>
<pre>
<i>
the number of the shortest substrings for the i-th problem
empty line
the first line of s<sub>i1</sub>
the second line of s<sub>i1</sub>
...
the last line of s<sub>i1</sub>
empty line for the substring termination
</i>
</pre>
<p>
where each line of the shortest substring <i>s</i><sub><i>i</i>1</sub> except for the last line should consist of exactly 72 characters and the last line (or the single line if the substring is shorter than or equal to 72 characters, of course) should not exceed 72 characters.
</p>
<p>
If there is no such substring for a problem, the output will be a 0 followed by an empty line; no more successive empty line should be output because there is no substring to be terminated.
</p>
<H2>Sample Input</H2>
<pre>
Thefirstexampleistrivial.
mfv
AhugeamountofinformationisbeingheapedonWWW.Albeititisnot
well-organized,userscanbrowseWWWasanunboundedsourceof
up-to-dateinformation,insteadofconsultingestablishedbutalittle
out-of-dateencyclopedia.However,youcanfurtherexploitWWWby
learningmoreaboutkeywordsearchalgorithms.Forexample,ifyou
wanttogetinformationonrecentcomparisonbetweenWindowsandUNIX,
youmayexpecttogetrelevantdescriptionoutofabigbunchofWeb
texts,byextractingtextsthatcontainbothkeywords"Windows"and"UNIX"
closetogether.
bWn
3.1415926535897932384626433832795028841971693993751058209749445923078164
pi
Wagner,Bach,Beethoven,Chopin,Brahms,Hindemith,Ives,Suk,Mozart,Stravinsky
Weary
ASCIIcharacterssuchas+,*,[,#,<,},_arenotexcludedinagivenstringas
thisexampleillustratesbyitself.Youshouldnotforgetthem.Onemorefact
youshouldnoticeisthatuppercaselettersandlowercaselettersare
distinguishedinthisproblem.Don'tidentify"g"and"G",forexmaple.
However,weareafraidthatthisexamplegivesyoutoomuchhint!
![GsC_l
ETAONRISHDLFCMUGYPWBVKXJQZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
firstexampleistriv
7
nWWW.Alb
0
1
Wagner,Bach,Beethoven,Chopin,Brahms,Hindemith,Ives,Suk,Mozart,Stravinsky
1
CIIcharacterssuchas+,*,[,#,<,},_arenotexcludedinagivenstringasthisexampl
eillustratesbyitself.Youshouldnotforgetthem.Onemorefactyoushouldnoticeis
thatuppercaselettersandlowercaselettersaredistinguishedinthisproblem.Don
'tidentify"g"and"G",forexmaple.However,weareafraidthatthisexamplegivesyo
utoomuchhint!
1
ETAONRISHDLFCMUGYPWBVKXJQZ
</pre>
|
p01887 |
<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>Pipe Fitter and the Fierce Dogs</h2>
<p>
You, a proud pipe fitter of ICPC (International Community for Pipe Connection), undertake a new task. The area in which you will take charge of piping work is a rectangular shape with $W$ blocks from west to east and $H$ blocks from north to south. We refer to the block at the $i$-th from west and the $j$-th from north as $(i, j)$. The westernmost and northernmost block is $(1, 1)$, and the easternmost and southernmost block is $(W,H)$. To make the area good scenery, the block $(i, j)$ has exactly one house if and only if both of $i$ and $j$ are odd numbers.
</p>
<p>
Your task is to construct a water pipe network in the area such that every house in the area is supplied water through the network. A water pipe network consists of pipelines. A pipeline is made by connecting one or more pipes, and a pipeline with l pipes is constructed as follows:
</p>
<ol>
<li> choose a first house, and connect the house to an underground water source with a <i>special pipe</i>.</li>
<li> choose an $i$-th house ($2 \leq i \leq l$), and connect the $i$-th house to the ($i - 1$)-th house with a <i>common pipe</i>. In this case, there is a condition to choose a next $i$-th house because the area is slope land. Let $(x, y)$ be the block of the ($i - 1$)-th house. An $i$-th house must be located at either $(x - 2, y + 2)$, $(x, y + 2)$, or $(x + 2, y + 2)$. A common pipe connecting two houses must be located at $(x - 1, y + 1)$, $(x, y + 1)$, or $(x + 1, y + 1)$, respectively.
</ol>
<p>
In addition, you should notice the followings when you construct several pipelines:
</p>
<ul>
<li> For each house, exactly one pipeline is through the house.</li>
<li> Multiple pipes can be located at one block.</li>
</ul>
<p>
In your task, common pipes are common, so you can use any number of common pipes. On the other hand, special pipes are special, so the number of available special pipes in this task is restricted under ICPC regulation.
</p>
<p>
Besides the restriction of available special pipes, there is another factor obstructing your pipe work: fierce dogs. Some of the blocks which do not contain a house seem to be home of fierce dogs. Each dog always stays at his/her home block. Since several dogs must not live at the same block as their home, you can assume each block is home of only one dog, or not home of any dogs.
</p>
<p>
The figure below is an example of a water pipe network in a 5 $\times$ 5 area with 4 special pipes. This corresponds to the first sample.
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2016_pipeFitter"><br/>
</center>
<br/>
<p>
Locating a common pipe at a no-dog block costs 1 unit time, but locating a common pipe at a dog-living block costs 2 unit time because you have to fight against the fierce dog. Note that when you locate multiple pipes at the same block, each pipe-locating costs 1 unit time for no-dog blocks and 2 for dog-living blocks, respectively. By the way, special pipes are very special, so locating a special pipe costs 0 unit time.
</p>
<p>
You, a proud pipe fitter, want to accomplish this task as soon as possible. Fortunately, you get a list of blocks which are home of dogs. You have frequently participated in programming contests before being a pipe fitter. Hence, you decide to make a program determining whether or not you can construct a water pipe network such that every house is supplied water through the network with a restricted number of special pipes, and if so, computing the minimum total time cost to construct it.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case.<br/>
<br/>
$W$ $H$ $K$<br/>
$N$<br/>
$x_1$ $y_1$<br/>
$x_2$ $y_2$<br/>
...<br/>
$x_N$ $y_N$
</p>
<p>
All numbers in a test case are integers. The first line contains three integers $W$, $H$, and $K$. $W$ and $H$ represent the size of the rectangle area. $W$ is the number of blocks from west to east ($1 \leq W < 10,000$), and $H$ is the number of blocks from north to south ($1 \leq H < 10,000$). $W$ and $H$ must be odd numbers. $K$ is the number of special pipes that you can use in this task ($1 \leq K \leq 100,000,000$). The second line has an integer $N$ ($0 \leq N \leq 100,000$), which is the number of dogs in the area. Each of the following $N$ lines contains two integers $x_i$ and $y_i$, which indicates home of the $i$-th fierce dog is the block $(x_i, y_i)$. These numbers satisfy the following conditions:
</p>
<ul>
<li> $1 \leq x_i \leq W, 1 \leq y_i \leq H$.</li>
<li> At least one of $x_i$ and $y_i$ is even number.</li>
<li> $i \ne j$ implies $(x_i, y_i) \ne (x_j, y_j)$. That is, two or more dogs are not in the same block.</li>
</ul>
<h3>Output</h3>
<p>
If we can construct a water pipe network such that every house is supplied water through the network with a restricted number of special pipes, print the minimum total time cost to construct it. If not, print -1.
</p>
<h3>Sample Input 1</h3>
<pre>
5 5 4
6
3 2
4 2
5 2
1 4
3 4
5 4
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
6
</pre>
<h3>Sample Input 2</h3>
<pre>
5 3 1
0
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
-1
</pre>
<h3>Sample Input 3</h3>
<pre>
9 5 100
5
2 1
1 2
3 4
4 3
2 2
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
5 5 3
4
1 2
5 2
1 4
5 4
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
8
</pre>
<h3>Sample Input 5</h3>
<pre>
9 5 5
10
2 1
2 2
3 2
5 2
8 2
4 3
2 4
3 4
5 4
8 4
</pre>
<h3>Output for the Sample Input 5</h3>
<pre>
10
</pre>
|
p02252 | <h1>Fractional Knapsack Problem</h1>
<p>You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.</p>
<p>When you put some items into the knapsack, the following conditions must be satisfied:</p>
<ul>
<li>The total value of the items is as large as possible.</li>
<li>The total weight of the selected items is at most $W$.</li>
<li>You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$</li>
</ul>
<p>Find the maximum total value of items in the knapsack.</p>
<h2>Input</h2>
<pre>
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
</pre>
<p>The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.</p>
<h2>Output</h2>
<p>Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le N \le 10^5$</li>
<li>$1 \le W \le 10^9$</li>
<li>$1 \le v_i \le 10^9 (1 \le i \le N)$</li>
<li>$1 \le w_i \le 10^9 (1 \le i \le N)$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
3 50
60 10
100 20
120 30
</pre>
<h2>Sample Output 1</h2>
<pre>
240
</pre>
<p>When you put 10 of item $1$, 20 of item $2$ and 20 of item $3$, the total value is maximized.</p>
<h2>Sample Input 2</h2>
<pre>
3 50
60 13
100 23
120 33
</pre>
<h2>Sample Output 2</h2>
<pre>
210.90909091
</pre>
<p>When you put 13 of item $1$, 23 of item $2$ and 14 of item $3$, the total value is maximized. Note some outputs can be a real number.</p>
<h2>Sample Input 3</h2>
<pre>
1 100
100000 100000
</pre>
<h2>Sample Output 3</h2>
<pre>
100
</pre>
|
p02602 | <span class="lang-en">
<p>Score: <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>M-kun is a student in Aoki High School, where a year is divided into <var>N</var> terms.<br/>
There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:</p>
<ul>
<li>For the first through <var>(K-1)</var>-th terms: not given.</li>
<li>For each of the <var>K</var>-th through <var>N</var>-th terms: the multiplication of the scores in the last <var>K</var> exams, including the exam in the graded term.</li>
</ul>
<p>M-kun scored <var>A_i</var> in the exam at the end of the <var>i</var>-th term.<br/>
For each <var>i</var> such that <var>K+1 \leq i \leq N</var>, determine whether his grade for the <var>i</var>-th term is <strong>strictly</strong> greater than the grade for the <var>(i-1)</var>-th term.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>2 \leq N \leq 200000</var></li>
<li><var>1 \leq K \leq N-1</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>K</var>
<var>A_1</var> <var>A_2</var> <var>A_3</var> <var>\ldots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answer in <var>N-K</var> lines.<br/>
The <var>i</var>-th line should contain <code>Yes</code> if the grade for the <var>(K+i)</var>-th term is greater than the grade for the <var>(K+i-1)</var>-th term, and <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
96 98 95 100 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
No
</pre>
<p>His grade for each term is computed as follows:</p>
<ul>
<li><var>3</var>-rd term: <var>(96 \times 98 \times 95) = 893760</var></li>
<li><var>4</var>-th term: <var>(98 \times 95 \times 100) = 931000</var></li>
<li><var>5</var>-th term: <var>(95 \times 100 \times 20) = 190000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
1001 869120 1001
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>Note that the output should be <code>No</code> if the grade for the <var>3</var>-rd term is equal to the grade for the <var>2</var>-nd term.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
Yes
No
Yes
Yes
No
Yes
Yes
</pre></section>
</div>
</span> |
p03910 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The problem set at <em>CODE FESTIVAL 20XX Finals</em> consists of <var>N</var> problems.</p>
<p>The score allocated to the <var>i</var>-th <var>(1âŠiâŠN)</var> problem is <var>i</var> points.</p>
<p>Takahashi, a contestant, is trying to score exactly <var>N</var> points. For that, he is deciding which problems to solve.</p>
<p>As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.</p>
<p>Determine the set of problems that should be solved.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ10^7</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded for passing the test set satisfying <var>1âŠNâŠ1000</var>.</li>
<li>Additional <var>100</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Among the sets of problems with the total score of <var>N</var>, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line.</p>
<p>If there exists more than one such set, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
3
</pre>
<p>Solving only the <var>4</var>-th problem will also result in the total score of <var>4</var> points, but solving the <var>1</var>-st and <var>3</var>-rd problems will lower the highest score of a solved problem.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
2
4
</pre>
<p>The set <var>\{3,4\}</var> will also be accepted.</p>
</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>
</span> |
p02317 |
<H1>Longest Increasing Subsequence</H1>
<br/>
<p>
For a given sequence <var>A = {a<sub>0</sub>, a<sub>1</sub>, ... , a<sub>n-1</sub>}</var>, find the length of the longest increasing subsequnece (LIS) in <var>A</var>.
</p>
<p>
An increasing subsequence of <var>A</var> is defined by a subsequence <var>{a<sub>i<sub>0</sub></sub>, a<sub>i<sub>1</sub></sub>, ... , a<sub>i<sub>k</sub></sub>}</var> where <var>0 ≤ i<sub>0</sub> < i<sub>1</sub> < ... < i<sub>k</sub> < n</var> and <var>a<sub>i<sub>0</sub></sub> < a<sub>i<sub>1</sub></sub> < ... < a<sub>i<sub>k</sub></sub>.
</p>
<H2>Input</H2>
<pre>
<var>n</var>
<var>a<sub>0</sub></var>
<var>a<sub>1</sub></var>
:
<var>a<sub>n-1</sub></var>
<var>
</pre>
<p>
In the first line, an integer <var>n</var> is given. In the next <var>n</var> lines, elements of <var>A</var> are given.
</p>
<H2>Output</H2>
<p>
The length of the longest increasing subsequence of <var>A</var>.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <var>n</var> ≤ 100000</li>
<li>0 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>9</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
5
1
3
2
4
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
3
1
1
1
</pre>
<H2>Sample Output 2</H2>
<pre>
1
</pre>
<br/> |
p02747 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>A Hitachi string is a concatenation of one or more copies of the string <code>hi</code>.</p>
<p>For example, <code>hi</code> and <code>hihi</code> are Hitachi strings, while <code>ha</code> and <code>hii</code> are not.</p>
<p>Given a string <var>S</var>, determine whether <var>S</var> is a Hitachi string.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>The length of <var>S</var> is between <var>1</var> and <var>10</var> (inclusive).</li>
<li><var>S</var> is a string consisting of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If <var>S</var> is a Hitachi string, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>hihi
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><code>hihi</code> is the concatenation of two copies of <code>hi</code>, so it is a Hitachi string.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>hi
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>ha
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre></section>
</div>
</span> |
p03855 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cities. There are also <var>K</var> roads and <var>L</var> railways, extending between the cities.
The <var>i</var>-th road bidirectionally connects the <var>p_i</var>-th and <var>q_i</var>-th cities, and the <var>i</var>-th railway bidirectionally connects the <var>r_i</var>-th and <var>s_i</var>-th cities.
No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.</p>
<p>We will say city <var>A</var> and <var>B</var> are <em>connected by roads</em> if city <var>B</var> is reachable from city <var>A</var> by traversing some number of roads. Here, any city is considered to be connected to itself by roads.
We will also define <em>connectivity by railways</em> similarly.</p>
<p>For each city, find the number of the cities connected to that city by both roads and railways.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 ⊠N ⊠2*10^5</var></li>
<li><var>1 ⊠K, L⊠10^5</var></li>
<li><var>1 ⊠p_i, q_i, r_i, s_i ⊠N</var></li>
<li><var>p_i < q_i</var></li>
<li><var>r_i < s_i</var></li>
<li>When <var>i â j</var>, <var>(p_i, q_i) â (p_j, q_j)</var></li>
<li>When <var>i â j</var>, <var>(r_i, s_i) â (r_j, s_j)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var> <var>L</var>
<var>p_1</var> <var>q_1</var>
:
<var>p_K</var> <var>q_K</var>
<var>r_1</var> <var>s_1</var>
:
<var>r_L</var> <var>s_L</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> integers. The <var>i</var>-th of them should represent the number of the cities connected to the <var>i</var>-th city by both roads and railways.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3 1
1 2
2 3
3 4
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 2 1
</pre>
<p>All the four cities are connected to each other by roads.</p>
<p>By railways, only the second and third cities are connected. Thus, the answers for the cities are <var>1, 2, 2</var> and <var>1</var>, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2 2
1 2
2 3
1 4
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2 2 1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 4 4
1 2
2 3
2 5
6 7
3 5
4 5
3 4
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1 1 2 1 2 2 2
</pre></section>
</div>
</span> |
p01868 |
<!-- - - - - - begin nicebody - - - - - -->
<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>D: ã¹ãã£ã㌠/ Scanner</h1>
<h2>å顿</h2>
<p>
ããã« $N$ æã®çŽããããããªã㯠$3$ å°ã®ã¹ãã£ããŒã䞊åã«çšããããšã§ã
å
šãŠã®çŽãã¹ãã£ã³ããããšèããŠãããããããã®çŽã¯ã¹ãã£ã³ã«ãããæéãæ±ºãŸã£ãŠããã
$i$ çªç®ã®çŽãã¹ãã£ã³ããã®ã«ãããæé㯠$T_i$ ã§ããã
çŽãã¹ãã£ã³ããé çªã¯ä»»æã§ãããã$1$ å°ã®ã¹ãã£ããŒã§è€æ°ã®çŽãåæã«ã¹ãã£ã³ããããšã¯ã§ããªãã
</p>
<p>
å
šãŠã®çŽã®ã¹ãã£ã³ãçµäºããã¹ãã£ã³ãè¡ã£ãŠããã¹ãã£ããŒããªããªããŸã§ã«ãããæéãæå°åããªããã
</p>
<h2>å
¥å</h2>
<p>
$N$<br>
$T_1$<br>
$T_2$<br>
$T_3$<br>
$\vdots$<br>
$T_N$<br>
</p>
<h2>å¶çŽ</h2>
<p>
$1 \leq N \leq 50$<br>
$1 \leq T_i \leq 50$<br>
å
¥åã¯å
šãп޿°<br>
</p>
<h2>åºå</h2>
<p>
çãã $1$ è¡ã§åºåããŠãã ããïŒ
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å1</h3>
<pre>
4
1
1
1
1
</pre>
<h3>ãµã³ãã«åºå1</h3>
<pre>
2
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_D1">
<h3>ãµã³ãã«å
¥å2</h3>
<pre>
9
15
20
27
4
10
7
34
30
36
</pre>
<h3>ãµã³ãã«åºå2</h3>
<pre>
61
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_D2">
<h3>ãµã³ãã«å
¥å3</h3>
<pre>
6
20
18
46
16
9
48
</pre>
<h3>ãµã³ãã«åºå3</h3>
<pre>
55
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RUPC20160306_D3">
|
p00280 |
<h1>ããã¹</h1>
<p>
ãžã§ãŠåãšã€ãšããã¯æŒäŒã¿ã«ããã¹ãããŸãããã ããæŒäŒã¿ã¯æéãéãããŠããã®ã§ãçãæéã§çµããããã«ãåŸç¹ã«ã€ããŠä»¥äžã®ïŒã€ã®ã«ãŒã«ã§è¡ããŸãã
</p>
<ul>
<li> çžæãïŒç¹ä»¥äžã®ãšãã«å
ã«ïŒç¹ãšãã°åã¡ã</li>
<li> ïŒå¯ŸïŒã®åç¹ã«ãªã£ããšãã¯ããã®çŽåŸã«é£ç¶ããŠïŒç¹ãšã£ãæ¹ãåã¡ã</li>
<li> ïŒå¯ŸïŒã®åŸã«åæ¹ãïŒç¹ãã€ãšã£ããšãã¯åŒãåãã</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2013_tennis" width="600">
</center>
<p>
以äžã®å³ã¯ããžã§ãŠåãšã€ãšããã®è©Šåã§èµ·ããåŸããã¹ãŠã®ç¶æ³ã衚ããŠããŸããäžžã®äžã®å·Šã®æ°ããžã§ãŠåã®åŸç¹ãå³ãã€ãšããã®åŸç¹ã§ããïŒ¡ãšæžããç¢å°ã¯ãžã§ãŠåãïŒç¹ãšã£ãããšããïŒ¢ãšæžããç¢å°ã¯ã€ãšãããïŒç¹ãšã£ãããšã衚ããŸãã
</p>
<p>
ãžã§ãŠåãšã€ãšããã®åŸç¹ãäžãããããšãã詊åéå§ãããã®åŸç¹ç¶æ³ã«ãªããŸã§ã«ãäžã®å³ã§éãåŸããã¹ãŠã®çµè·¯ãåæããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ïŒã€ã®ããŒã¿ã»ãããããªããå
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>j</var> <var>y</var>
</pre>
<p>
<var>j</var> (0 ≤ <var>j</var> ≤ 6) ããžã§ãŠåã®åŸç¹ã<var>y</var> (0 ≤ <var>y</var> ≤ 6) ãã€ãšããã®åŸç¹ã§ããããã ãã<var>j</var> ãš <var>y</var> ããšãã« 0 ã§ããããšã¯ãªãããŸãã<var>j</var> ã 6 ã®ãšã㯠<var>y</var> 㯠4ã<var>y</var> ã 6 ã®ãšã㯠<var>j</var> 㯠4 ã§ããã
</p>
<h2>åºå</h2>
<p>
äžã®å³ã§ã詊åéå§ïŒ0-0ãšæžãããäžžïŒããäžããããåŸç¹ãæžãããäžžãŸã§ã®ãã¹ãŠã®çµè·¯ãåºåãããçµè·¯ã¯å³ã®ç¢å°ã«æ·»ããããè±å(A,B)ã®åã§è¡šããèŸæžåŒé åºïŒè±åèŸæžã§åèªã䞊ãã§ããé çªïŒã«ãªãããã«äžŠã¹ããïŒã€ã®çµè·¯ãïŒè¡ã«åºåãããçµè·¯ã®ååŸã«ã¯ç©ºçœãåºåããªãã
</p>
<h2>å
¥åºåäŸ</h2>
<br>
<h2>å
¥åäŸ1</h2>
<pre>
2 2
</pre>
<h2>åºåäŸ1</h2>
<pre>
AABB
ABAB
ABBA
BAAB
BABA
BBAA
</pre>
<h2>å
¥åäŸ2</h2>
<pre>
5 1
</pre>
<h2>åºåäŸ2</h2>
<pre>
AAAABA
AAABAA
AABAAA
ABAAAA
BAAAAA
</pre> |
p03506 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Consider an infinite <var>N</var>-ary tree as shown below:</p>
<div style="text-align: center;">
<img src="https://img.atcoder.jp/relay2/c76baa50b0acf28062688597724a54b9.png">
<p>Figure: an infinite <var>N</var>-ary tree for the case <var>N = 3</var></p>
</img></div>
<p>As shown in the figure, each vertex is indexed with a unique positive integer, and for every positive integer there is a vertex indexed with it. The root of the tree has the index <var>1</var>. For the remaining vertices, vertices in the upper row have smaller indices than those in the lower row. Among the vertices in the same row, a vertex that is more to the left has a smaller index.</p>
<p>Regarding this tree, process <var>Q</var> queries. The <var>i</var>-th query is as follows:</p>
<ul>
<li>Find the index of the lowest common ancestor (see Notes) of Vertex <var>v_i</var> and <var>w_i</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><ul>
<li>In a rooted tree, the <em>lowest common ancestor</em> (LCA) of Vertex <var>v</var> and <var>w</var> is the farthest vertex from the root that is an ancestor of both Vertex <var>v</var> and <var>w</var>. Here, a vertex is considered to be an ancestor of itself. For example, in the tree shown in Problem Statement, the LCA of Vertex <var>5</var> and <var>7</var> is Vertex <var>2</var>, the LCA of Vertex <var>8</var> and <var>11</var> is Vertex <var>1</var>, and the LCA of Vertex <var>3</var> and <var>9</var> is Vertex <var>3</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^9</var></li>
<li><var>1 †Q †10^5</var></li>
<li><var>1 †v_i < w_i †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>Q</var>
<var>v_1</var> <var>w_1</var>
<var>:</var>
<var>v_Q</var> <var>w_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line <var>(1 †i †Q)</var> must contain the index of the lowest common ancestor of Vertex <var>v_i</var> and <var>w_i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
5 7
8 11
3 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1
3
</pre>
<p>The queries in this case correspond to the examples shown in Notes.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100000 2
1 2
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
1
</pre></section>
</div>
</span> |
p03156 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have written <var>N</var> problems to hold programming contests.
The <var>i</var>-th problem will have a score of <var>P_i</var> points if used in a contest.</p>
<p>With these problems, you would like to hold as many contests as possible under the following condition:</p>
<ul>
<li>A contest has three problems. The first problem has a score not greater than <var>A</var> points, the second has a score between <var>A + 1</var> and <var>B</var> points (inclusive), and the third has a score not less than <var>B + 1</var> points.</li>
</ul>
<p>The same problem should not be used in multiple contests.
At most how many contests can be held?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 100</var></li>
<li><var>1 \leq P_i \leq 20</var> (<var>1 \leq i \leq N</var>)</li>
<li><var>1 \leq A < B < 20</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A</var> <var>B</var>
<var>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
5 15
1 10 16 2 7 20 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Two contests can be held by putting the first, second, third problems and the fourth, fifth, sixth problems together.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
3 8
5 5 5 10 10 10 15 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>No contest can be held, because there is no problem with a score of <var>A = 3</var> or less.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
5 6
5 6 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p01491 |
<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 F:
RabbitLunch
</h2>
<p>
ãããã¯æŒé£ã«ã«ããããšããŠã€ã1 åãã€é£ã¹ã. ãããã¯ãšãŠãåæ§çãªã®ã§, é£ã¹ãã«ãããã®çš®é¡ãããŠã€ã®çš®é¡ãåãã§ãããããª, ç°ãªã2 å¹ã®ããããååšããŠã¯ãªããªã.
</p>
<p>
ã«ããã㯠$M$ çš®é¡ãã. $i$ çš®é¡ç®ã®ã«ããã㯠$m_i$ åãã. ããŠã€ã¯ $N$ çš®é¡ãã. $i$ çš®é¡ç®ã®ããŠã€ã¯ $n_i$ åãã. æå€§äœå¹ã®ããããæŒé£ããšãããæ±ãã.
</p>
<p>
$m_i$ ãš $n_i$ ã¯æ¬¡ã®æŒžååŒãçšããŠçæãã.
</p>
<ul>
<li> $m_0 = m0$ </li>
<li> $m_{i+1} = (m_i * 58 + md )$ mod $(N + 1)$</li>
<li> $n_0 = n0$</li>
<li> $n_{i+1} = (n_i * 58 + nd )$ mod $(M + 1)$</li>
</ul>
<h3>Constraints</h3>
<ul>
<li>$M$ will be between 1 and 2,500,000, inclusive.</li>
<li>$N$ will be between 1 and 2,500,000, inclusive.</li>
<li>$m0$ and $md$ will be between 0 and $N$, inclusive.</li>
<li>$n0$ and $nd$ will be between 0 and $M$, inclusive.</li>
</ul>
<h3>Input</h3>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã:<br>
<br>
$M$ $N$ $m0$ $md$ $n0$ $nd$<br>
<br>
</p>
<h3>Output</h3>
<p>
æŒé£ããšãããããã®å¹æ°ã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã«åºåãã.
</p>
<h3>Sample Input 1</h3>
<pre>2 3 1 3 1 0</pre>
<h3>Sample Output 1</h3>
<pre>2</pre>
<h3>Sample Input 2</h3>
<pre>5 8 1 2 3 4</pre>
<h3>Sample Output 2</h3>
<pre>19</pre> |
p03382 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>{\rm comb}(n,r)</var> be the number of ways to choose <var>r</var> objects from among <var>n</var> objects, disregarding order.
From <var>n</var> non-negative integers <var>a_1, a_2, ..., a_n</var>, select two numbers <var>a_i > a_j</var> so that <var>{\rm comb}(a_i,a_j)</var> is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq n \leq 10^5</var></li>
<li><var>0 \leq a_i \leq 10^9</var></li>
<li><var>a_1,a_2,...,a_n</var> are pairwise distinct.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var>
<var>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 <var>a_i</var> and <var>a_j</var> that you selected, with a space in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
6 9 4 2 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11 6
</pre>
<p><var>\rm{comb}(a_i,a_j)</var> for each possible selection is as follows:</p>
<ul>
<li><var>\rm{comb}(4,2)=6</var> </li>
<li><var>\rm{comb}(6,2)=15</var> </li>
<li><var>\rm{comb}(6,4)=15</var> </li>
<li><var>\rm{comb}(9,2)=36</var> </li>
<li><var>\rm{comb}(9,4)=126</var> </li>
<li><var>\rm{comb}(9,6)=84</var> </li>
<li><var>\rm{comb}(11,2)=55</var> </li>
<li><var>\rm{comb}(11,4)=330</var> </li>
<li><var>\rm{comb}(11,6)=462</var> </li>
<li><var>\rm{comb}(11,9)=55</var></li>
</ul>
<p>Thus, we should print <var>11</var> and <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
100 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100 0
</pre></section>
</div>
</span> |
p00957 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>Problem A
Secret of Chocolate Poles
</h2>
<p>
Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders.
</p>
<p>
Each pole should satisfy the following conditions for her secret mission, which we cannot tell.
</p>
<ul>
<li> A pole should consist of at least one disk.</li>
<li> The total thickness of disks in a pole should be less than or equal to $l$ cm.</li>
<li> The top disk and the bottom disk of a pole should be dark.</li>
<li> A disk directly upon a white disk should be dark and vice versa.</li>
</ul>
<p>
As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_chocolatePoles">
<p>
Figure A.1. Six chocolate poles corresponding to Sample Input 1
</p>
</center>
<p>
Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$l$ $k$
</pre>
<p>
Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$.
</p>
<h3>Output</h3>
<p>
Output the number of possible distinct patterns.
</p>
<h3>Sample Input 1</h3>
<pre>
5 3
</pre>
<h3>Sample Output 1</h3>
<pre>
6
</pre>
<h3>Sample Input 2</h3>
<pre>
9 10
</pre>
<h3>Sample Output 2</h3>
<pre>
5
</pre>
<h3>Sample Input 3</h3>
<pre>
10 10
</pre>
<h3>Sample Output 3</h3>
<pre>
6
</pre>
<h3>Sample Input 4</h3>
<pre>
20 5
</pre>
<h3>Sample Output 4</h3>
<pre>
86
</pre>
<h3>Sample Input 5</h3>
<pre>
100 2
</pre>
<h3>Sample Output 5</h3>
<pre>
3626169232670
</pre>
|
p01645 |
<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 L: The Return of FizzBuzz</h1>
<p class="ndoc-top">ICPC World Finals 7æ¥ç®</p>
<p class="ndoc-top">ããããææ¥ã¯ICPC World Finalsã®æ¬çªã§ããã
ãã£ãŒæ°ã¯ãããªã³ã©ã€ã³ãžã£ããž(Aru Online Judge)ã§ç·Žç¿ãããããšã«ããã
åé¡äžèЧãçºããŠãããšFizzBuzzãšããåé¡ãç®ã«ã€ããã
ãã®åé¡ã¯ãFizzBuzzã²ãŒã ã§åŸãããçºèšã®næåç®ãã20æåãåºåãããšãããã®ã ã</p>
<p class="ndoc-top">âŠãµã
ããã£ãšããéã«è§£ããŠããŸã£ãã ããã§ã¯ç°¡åãããã
å
¥åãšåºåãéã«ããåé¡ãäœã£ãŠã¿ãããšã«ãããã</p>
<h2 class="ndoc-heading2">åé¡</h2>
<p class="ndoc-top">
FizzBuzzãšã¯ã1以äžã®æŽæ°ãé ã«ã以äžã®ã«ãŒã«ã«åŸã£ãŠçºèšããŠããã²ãŒã ã§ããã</p>
<ul class="ndoc-indent">
<li>3ã§å²ãåããæã«ã¯ãFizzã</li>
<li>5ã§å²ãåããæã«ã¯ãBuzzã</li>
<li>3ãš5ã®äž¡æ¹ã§å²ãåããæã«ã¯ãFizzBuzzã</li>
<li>ãã以å€ã®æã¯ãã®æ°å</li>
</ul>
ã²ãŒã ã®é²è¡ç¶æ³ã以äžã«ç€ºãã
<p class="ndoc-top">1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz,
11, Fizz, 13, 14, FizzBuzz, 16, âŠ</p>
<p class="ndoc-top">åŸãããçºèšãçµåããããšã§åŸãããïŒç¡éé·ã®ïŒæååãFizzBuzz StringãšåŒã¶ã
ããæåå\(s\)ãäžããããã \(s\)ãFizzBuzz Stringã®éšåæååãšããŠåºçŸããããå€å®ãã
åºçŸããå Žåã«ã¯æåã«åºçŸããã€ã³ããã¯ã¹ãæ±ããã</p>
<h2 class="ndoc-heading2">å
¥å</h2>
<pre>
n
s<sub>1</sub>
s<sub>2</sub>
âŠ
s<sub>n</sub>
</pre>
<p>å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã 1è¡ç®ã«ãã¹ãã±ãŒã¹æ°\(n\)ãäžããããã 2è¡ç®ãã\( n+1
\)è¡ç®ã¯åãã¹ãã±ãŒã¹ã«å¯Ÿå¿ãã æåå\( s_{i} \)ã1è¡ã§äžããããã</p>
<h2 class="ndoc-heading2">åºå</h2>
<p class="ndoc-top">\(i\)çªç®ã®æåå\( s_{i} \)ã«ã€ããŠã \( s_{i}
\)ãFizzBuzz Stringã®éšåæååãšããŠåºçŸããå Žåã«ã¯æåã«åºçŸããã€ã³ããã¯ã¹ã(1-indexã§)ã
åºçŸããªãå Žåã«ã¯"-1"ã\(i\)è¡ç®ã«åºåããã</p>
<h2 class="ndoc-heading2">å¶çŽ</h2>
<ul class="ndoc-indent">
<li>\( 1 \leq n \leq 20 \)</li>
<li>æååã¯æå\( \{ 0,1,\cdots,8,9
,\mbox{F},\mbox{B},\mbox{i},\mbox{u},\mbox{z} \} (1 \leq i \leq n)
\)ãããªãã</li>
<li>æååã®é·ãã¯1以äž15以äžã§ããã</li>
</ul>
<h2 class="ndoc-heading2">å
¥åºåäŸ</h2>
<h3 class="ndoc-heading3">å
¥å1</h3>
<pre>
6
78Fizz
98FizzBuzz101
FizzBu
izzFiz
111111111111111
123456789
</pre>
<h3 class="ndoc-heading3">åºå1</h3>
<pre>
16
304
18
-1
7703703700
7795884765
</pre>
<p>å
¥åäŸã¯6ã€ã®ãã¹ãã±ãŒã¹ãããªãã ãããã以äžã®çºèšã«å¯Ÿå¿ããã</p>
<ul>
<li>âŠ, Buzz, Fizz, 7, 8, Fizz, Buzz, âŠ</li>
<li>âŠ, Fizz, 97, 98, Fizz, Buzz, 101, Fizz, âŠ</li>
<li>âŠ, 7, 8, Fizz, Buzz, 11, 12, âŠ</li>
<li>ååšããªã</li>
<li>âŠ, 1111111109, FizzBuzz, 1111111111,
1111111112, Fizz, 1111111114, âŠ</li>
<li>âŠ, 1123456787, Fizz, 1123456789, Buzz, Fizz, âŠ</li>
</ul>
</body>
</html> |
p03678 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will call a string that can be obtained by concatenating two equal strings an <em>even</em> string.
For example, <code>xyzxyz</code> and <code>aaaaaa</code> are even, while <code>ababab</code> and <code>xyzxy</code> are not.</p>
<p>For a non-empty string <var>S</var>, we will define <var>f(S)</var> as the shortest even string that can be obtained by appending one or more characters to the end of <var>S</var>.
For example, <var>f(</var><code>abaaba</code><var>)=</var><code>abaababaab</code>.
It can be shown that <var>f(S)</var> is uniquely determined for a non-empty string <var>S</var>.</p>
<p>You are given an even string <var>S</var> consisting of lowercase English letters.
For each letter in the lowercase English alphabet, find the number of its occurrences from the <var>l</var>-th character through the <var>r</var>-th character of <var>f^{10^{100}} (S)</var>.</p>
<p>Here, <var>f^{10^{100}} (S)</var> is the string <var>f(f(f( ... f(S) ... )))</var> obtained by applying <var>f</var> to <var>S</var> <var>10^{100}</var> times.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq |S| \leq 2\times 10^5</var></li>
<li><var>1 \leq l \leq r \leq 10^{18}</var></li>
<li><var>S</var> is an even string consisting of lowercase English letters.</li>
<li><var>l</var> and <var>r</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>l</var> <var>r</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>26</var> integers in a line with spaces in between.
The <var>i</var>-th integer should be the number of the occurrences of the <var>i</var>-th letter in the lowercase English alphabet from the <var>l</var>-th character through the <var>r</var>-th character of <var>f^{10^{100}} (S)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abaaba
6 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 2 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>
<p>Since <var>f(</var><code>abaaba</code><var>)=</var><code>abaababaab</code>, the first ten characters in <var>f^{10^{100}}(S)</var> is also <code>abaababaab</code>. Thus, the sixth through the tenth characters are <code>abaab</code>. In this string, <code>a</code> appears three times, <code>b</code> appears twice and no other letters appear, and thus the output should be <var>3</var> and <var>2</var> followed by twenty-four <var>0</var>s.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>xx
1 1000000000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>vgxgpuamkvgxgvgxgpuamkvgxg
1 1000000000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0
</pre></section>
</div>
</span> |
p04017 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> hotels are located on a straight line. The coordinate of the <var>i</var>-th hotel <var>(1 \leq i \leq N)</var> is <var>x_i</var>.</p>
<p>Tak the traveler has the following two personal principles:</p>
<ul>
<li>He never travels a distance of more than <var>L</var> in a single day.</li>
<li>He never sleeps in the open. That is, he must stay at a hotel at the end of a day.</li>
</ul>
<p>You are given <var>Q</var> queries. The <var>j</var>-th <var>(1 \leq j \leq Q)</var> query is described by two distinct integers <var>a_j</var> and <var>b_j</var>.
For each query, find the minimum number of days that Tak needs to travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel following his principles.
It is guaranteed that he can always travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel, in any given input.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq L \leq 10^9</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq x_i < x_2 < ... < x_N \leq 10^9</var></li>
<li><var>x_{i+1} - x_i \leq L</var></li>
<li><var>1 \leq a_j,b_j \leq N</var></li>
<li><var>a_j \neq b_j</var></li>
<li><var>N,\,L,\,Q,\,x_i,\,a_j,\,b_j</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded for passing the test set satisfying <var>N \leq 10^3</var> and <var>Q \leq 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>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
<var>L</var>
<var>Q</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
:
<var>a_Q</var> <var>b_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines.
The <var>j</var>-th line <var>(1 \leq j \leq Q)</var> should contain the minimum number of days that Tak needs to travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
2
1
2
</pre>
<p>For the <var>1</var>-st query, he can travel from the <var>1</var>-st hotel to the <var>8</var>-th hotel in <var>4</var> days, as follows:</p>
<ul>
<li>Day <var>1</var>: Travel from the <var>1</var>-st hotel to the <var>2</var>-nd hotel. The distance traveled is <var>2</var>.</li>
<li>Day <var>2</var>: Travel from the <var>2</var>-nd hotel to the <var>4</var>-th hotel. The distance traveled is <var>10</var>.</li>
<li>Day <var>3</var>: Travel from the <var>4</var>-th hotel to the <var>7</var>-th hotel. The distance traveled is <var>6</var>.</li>
<li>Day <var>4</var>: Travel from the <var>7</var>-th hotel to the <var>8</var>-th hotel. The distance traveled is <var>10</var>.</li>
</ul></section>
</div>
</span> |
p01215 |
<H1><font color="#000">Problem I:</font> Pythagoraslope</H1>
<p>
Alice, your girlfriend, is a student at an art school. She is in the final year, and now working
hard to build a facture for fulfilling the requirement to graduate. Her work is a large pinball
with many straight slopes. Before starting to build, she has made several plans, but is unsure if
they work as expected. So she asked you, a professional programmer, for help.
</p>
<p>
You have modeled this situation by a two dimensional plane with some line segments on it. In
this model, there is gravitation downward, i.e., in the decreasing direction of <i>y</i>-coordinate. Your
task is to write a program that simulates the pinball, and compute the last position where the
ball crosses the <i>x</i>-axis.
</p>
<p>
You may assume coefficient of restitution between the slopes and the ball is 0, i.e., when the ball
collides a slope, it instantly loses the velocity component orthogonal to the slope. And since her
pinball is so large, you may also assume that the volume of the ball is negligible.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets. Each data set is given in the format below.
</p>
<pre>
<i>N</i>
<i>g</i>
<i>x y</i>
<i>x</i><sub>1,1</sub> <i>y</i><sub>1,1</sub> <i>x</i><sub>1,2</sub> <i>y</i><sub>1,2</sub>
...
<i>x</i><sub><i>N</i>,1</sub> <i>y</i><sub><i>N</i>,1</sub> <i>x</i><sub><i>N</i>,2</sub> <i>y</i><sub><i>N</i>,2</sub>
</pre>
<p>
where <i>N</i> (<i>N</i> ≤ 100) is the number of slopes, <i>g</i> is gravity acceleration, and (<i>x</i>, <i>y</i>) is the initial
position of the ball. Each of the following <i>N</i> lines represents a slope, which is a line segment
between (<i>x</i><sub><i>i</i>,1</sub>, <i>y</i><sub><i>i</i>,1</sub> ) and (<i>x</i><sub><i>i</i>,2</sub>, <i>y</i><sub><i>i</i>,2</sub>).
</p>
<p>
You may assume that:
</p>
<ul>
<li> all coordinates are more than or equal to 1, and less than or equal to 10,000;</li>
<li> <i>x</i><sub><i>i</i>,1</sub> ≠ <i>x</i><sub><i>i</i>,2</sub> and <i>y</i><sub><i>i</i>,1</sub> ≠ <i>y</i><sub><i>i</i>,2</sub> for all 1 ≤ <i>i</i> ≤ <i>N</i>;</li>
<li> no two line segments cross each other;</li>
<li> extending or shrinking a slope by the length of 0.0001 does not change the ballâs trail, that
is, do not change the set of slopes where the ball passes;</li>
<li> the ball never collides to a slope at the angle of 90 ± 0.0001 degrees from the slope; and</li>
<li> the initial position of the ball never lies on any slope.</li>
</ul>
</p>
<p>
The end of the input is indicated by a line containing a single zero. This is not a part of the
data sets, and you must not process it.
</p>
<H2>Output</H2>
<p>
For each data set, output the <i>x</i>-coordinate of the final crossing point of the ballâs trail and the
<i>x</i>-axis. Your program may print any number of digits after the decimal point, but the output
must not contain an error greater than 10<sup>-4</sup> (= 0.0001).
</p>
<H2>Sample Input</H2>
<pre>
3
1
120 1000
100 100 180 20
170 10 270 30
270 40 400 20
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
403.87458314
</pre>
|
p03228 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In the beginning, Takahashi has <var>A</var> cookies, and Aoki has <var>B</var> cookies.
They will perform the following operation alternately, starting from Takahashi:</p>
<ul>
<li>If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person.</li>
</ul>
<p>Find the numbers of cookies Takahashi and Aoki respectively have after performing <var>K</var> operations in total.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A,B \leq 10^9</var></li>
<li><var>1 \leq K \leq 100</var></li>
<li><var>A,B</var> and <var>K</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing <var>K</var> operations in total.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5 3
</pre>
<p>The process will go as follows:</p>
<ul>
<li>In the beginning, Takahashi and Aoki have <var>5</var> and <var>4</var> cookies, respectively.</li>
<li>Takahashi eats one cookie and gives two cookies to Aoki. They now have <var>2</var> and <var>6</var> cookies, respectively.</li>
<li>Aoki gives three cookies to Takahashi. They now have <var>5</var> and <var>3</var> cookies, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>314159265 358979323 84
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>448759046 224379523
</pre></section>
</div>
</span> |
p02593 | <span class="lang-en">
<p>Score : <var>2200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given positions <var>(X_i, Y_i)</var> of <var>N</var> enemy rooks on an infinite chessboard.
No two rooks attack each other (at most one rook per row or column).</p>
<p>You're going to replace one rook with a king and then move the king repeatedly to beat as many rooks as possible.</p>
<p>You can't enter a cell that is being attacked by a rook.
Additionally, you <strong>can't move diagonally to an empty cell</strong> (but you can beat a rook diagonally).</p>
<p>(So this king moves like a superpawn that beats diagonally in 4 directions and moves horizontally/vertically in 4 directions.)</p>
<p>For each rook, consider replacing it with a king, and find the minimum possible number of moves
needed to beat the maximum possible number of rooks.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 200\,000</var></li>
<li><var>1 \leq X_i, Y_i \leq 10^6</var></li>
<li><var>X_i \neq X_j</var></li>
<li><var>Y_i \neq Y_j</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format.</p>
<pre><var>N</var>
<var>X_1</var> <var>Y_1</var>
<var>X_2</var> <var>Y_2</var>
<var>\vdots</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.
The <var>i</var>-th line is for scenario of replacing the rook at <var>(X_i, Y_i)</var> with your king.
This line should contain one integer: the minimum number of moves to beat <var>M_i</var> rooks
where <var>M_i</var> denotes the maximum possible number of beaten rooks in this scenario (in infinite time).</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 8
6 10
2 7
4 4
9 3
5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
0
7
5
0
0
</pre>
<p>See the drawing below.
If we replace rook 3 with a king, we can beat at most two other rooks.
The red path is one of optimal sequences of moves: beat rook 1,
then keep going down and right until you can beat rook 4.
There are 7 steps and that's the third number in the output.</p>
<p align="center"><img alt="path" src="https://img.atcoder.jp/agc047/rooks_path_small3.png"/></p>
<p align="center"><em>x-coordinate increases from left to right,
while y increases bottom to top.</em></p>
<p>Starting from rook 2, 5 or 6, we can't beat any other rook.
The optimal number of moves is 0.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
5 5
100 100
70 20
81 70
800 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>985
985
1065
1034
0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
2 5
4 4
13 12
12 13
14 17
17 19
22 22
16 18
19 27
25 26
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
2
9
9
3
3
24
5
0
25
</pre></section>
</div>
</span> |
p02069 | <style type="text/css">
blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
display: block;
margin: 10px 0 10px 30px;
font-size: 16px;
line-height: 18px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}
table.ioexample {
width: 100%;
border-collapse: collapse;
}
table.ioexample td {
width: 50%;
border: 1px solid rgba(0, 0, 0, 0.15);
vertical-align: top;
padding: 5px;
}
.no-page-break {
page-break-inside: avoid;
}
.page-break {
page-break-before: always;
}
</style>
<h3>Problem Statement</h3>
<p>You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers:</p>
<ul>
<li>The minimum integer $x$ such that you can select $x$ intervals from the given $N$ intervals so that the union of the selected intervals is $[0, L)$.</li>
<li>The minimum integer $y$ such that for all possible combinations of $y$ intervals from the given $N$ interval, it <em>does</em> cover $[0, L)$.</li>
</ul>
<p>We ask you to write a program to compute these two numbers.</p>
<hr />
<h3>Input</h3>
<p>The input consists of a single test case formatted as follows. </p>
<blockquote>$N$ $L$
$l_1$ $r_1$
$l_2$ $r_2$
$\vdots$
$l_N$ $r_N$</blockquote>
<p>The first line contains two integers $N$ ($1 \leq N \leq 2 \times 10^5$) and $L$ ($1 \leq L \leq 10^{12}$), where $N$ is the number of intervals and $L$ is the length of range to be covered, respectively. The $i$-th of the following $N$ lines contains two integers $l_i$ and $r_i$ ($0 \leq l_i < r_i \leq L$), representing the range of the $i$-th interval $[l_i, r_i)$. You can assume that the union of all the $N$ intervals is $[0, L)$</p>
<h3>Output</h3>
<p>Output two integers $x$ and $y$ mentioned in the problem statement, separated by a single space, in a line.</p>
<p><div class="no-page-break"><h3>Examples</h3><table class="ioexample"><tr><th>Input</th><th>Output</th></tr><tr><td><pre>3 3
0 2
1 3
1 2
</pre></td><td><pre>2 3
</pre></td></tr><tr><td><pre>2 4
0 4
0 4
</pre></td><td><pre>1 1
</pre></td></tr><tr><td><pre>5 4
0 2
2 4
0 3
1 3
3 4
</pre></td><td><pre>2 4
</pre></td></tr></table></div></p>
|
p00054 |
<H1>å°æ°äœã®å</H1>
<p>
<var>a</var>, <var>b</var>, <var>n</var> ã¯ãããããæ£ã®æŽæ°ã§ãããšããŸããåæ° <var>a</var> / <var>b</var> ã®å°æ°ç¬¬ <var>i</var> äœã®æ°ã <var>f(i)</var> ãšããŸã (0 ≤ <var>f(i)</var> ≤ 9)ããã®ãšãã<var>i = 1</var> ãã <var>n</var> ãŸã§ã® <var>f(i)</var> ã®åã <var>s</var> ãšããŸãã<br/>
<br/>
<var>s = f(1) + f(2) +</var> ... <var>+ f(n)</var><br/>
</p>
<p>
<var>a</var>, <var>b</var>, <var>n</var> ãèªã¿èŸŒãã§ã <var>s</var> ãåºåããŠçµäºããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸããåããŒã¿ã»ãããšããŠã3 ã€ã®æŽæ° <var>a</var> (1 ≤ <var>a</var> ≤ 1000), <var>b</var> (1 ≤ <var>b</var> ≤ 10000), <var>n</var> (1 ≤ <var>n</var> ≤ 100) ã空çœåºåãã§ïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ã<var>s</var> ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
1 2 3
2 3 4
5 4 3
4 3 2
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
24
7
6
</pre>
|
p02439 | <h1>Min-Max</h1>
<p>
For given three integers $a, b, c$, print the minimum value and the maximum value.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$a \; b \; c\;$
</pre>
<p>
Three integers $a, b, c$ are given in a line.
</p>
<h2>Output</h2>
<p>
Print the minimum and maximum values separated by a space in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$-1,000,000,000 \leq a, b, c \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4 5 3
</pre>
<h2>Sample Output 1</h2>
<pre>
3 5
</pre>
|
p00404 | <h1>åº</h1>
ã
<p>
ãããšå士ã®å®¶ã®åºã«ã¯æ£æ¹åœ¢ã®ã¿ã€ã«ãæ·ãã€ããããŠããŸããèžè¡ã«é è©£ãæ·±ããããšå士ã¯ãèµ€ãé»ãéã®å¡æã䜿ã£ãŠã¿ã€ã«ã«è²ãå¡ãããšã«ããŸãããã¯ããã«éšå±ã®é©åœãªã¿ã€ã«ãã²ãšã€éžã³ã以äžã®æ¹æ³ã§è²ãå¡ã£ãŠãããŸãã
</p>
<ul>
<li>ã¿ã€ã«ãå¡ãè²ããèµ€ïŒå³ã®çªå·ïŒïŒãé»ïŒå³ã®çªå·ïŒïŒãéïŒå³ã®çªå·ïŒïŒã®é ã«å€ããŠãããéã®æ¬¡ã¯ãŸãèµ€ããå§ããã</li>
<li>ãã§ã«è²ãå¡ã£ãé åã®é£ã«æ£æ¹åœ¢ã远å ããããã«è²ãå¡ããããããåãããé åãé·æ¹åœ¢ã«ãªãããã«ãããæ£æ¹åœ¢ã远å ããæ¹åã¯ãæ±ãåã西ãåã®é ã«å€ããŠãããåã®æ¬¡ã¯ãŸãæ±ããå§ããïŒå³ã§ã¯ãäžæ¹åãåã峿¹åãæ±ã§ããïŒã</li>
</ul>
<br/>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/PCK2019_floor" width="800"/>
</center>
<br/><br/>
<p>
æåã«èµ€ãå¡ã£ãã¿ã€ã«ããæ±è¥¿æ¹åã«$x$åãååæ¹åã«$y$åç§»åãããšããã«ããã¿ã€ã«ã¯ãäœè²ã«å¡ãããŠããã§ããããããã ããæ±ã®æ¹åã$x$ã®æ£ã®æ¹åãåã®æ¹åã$y$ã®æ£ã®æ¹åãšããŸãã
</p>
<p>
$x$ãš$y$ãå
¥åããã¿ã€ã«ã®è²ãåºåããããã°ã©ã ãäœæããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$x$ $y$
</pre>
<p>
ïŒè¡ã«$x$ãš$y$ ($-10^6 \leq x,y \leq 10^6$)ãäžããããã
</p>
<h2>åºå</h2>
<p>
ã¿ã€ã«ã®è²ãèµ€ã®ãšã1ãé»ã®ãšã2ãéã®ãšã3ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸïŒ</h3>
<pre>
0 0
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
1
</pre>
<h3>å
¥åäŸïŒ</h3>
<pre>
-4 5
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
2
</pre>
<h3>å
¥åäŸïŒ</h3>
<pre>
8 -14
</pre>
<h3>åºåäŸïŒ</h3>
<pre>
3
</pre>
|
p00111 |
<H1>åå£«ã®æå·</H1>
<p>
å 士 : ?D-C'KOPUA
</p>
<p>
ããŒã¿ãŒ : ã©ããããã§ãããããããå士? ããã®ããããªãããšãå«ã¶ã®ã«ã¯ããæ
£ããŸãããã
仿¥ã¯æç« ã«ãããªã£ãŠããŸãããã
</p>
<p>
å 士 : ã»ãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes1">
</center>
<br/>
<p>
ããŒã¿ãŒ : ãªãã§ãã? ãã®è¡šã¯......ãããäºéžã®åé¡ã«ãããªã®ããããŸããã衚ã䜿ã£ãŠæåã眮ãæã
ããšæåæ°ãæžããã§ãããããŸããäºéžãšæ¬éžã§åãåé¡ãåºããŠæãæããã£ãŠæ°ãããªãã§ã
ãããã
</p>
<p>
å 士 : éãããã
</p>
<p>
ããŒã¿ãŒ : é? ãªãã»ã©ãä»åºŠã¯çãããæååãå
ã«æ»ããã£ãŠåé¡ã§ããããšããããšã¯ã?D-C'KOPUAãã®
æåãããã®è¡šã䜿ã£ãŠãæåãããã笊å·ãã«çœ®ãããããã§ãã......ã§ããŸãããã
</p>
<pre>
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
</pre>
<p>
å 士 : ãããæ¬¡ã¯ããããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes2">
</center>
<br/>
<p>
ããŒã¿ãŒ : ããããããããªè¡šããããŸãããããããéã«äœ¿ããã ããã笊å·ããããæåãã«çœ®ãæããã°ãã
ãã§ãããã§ããæåã¯ã11111ãã§ãã衚ã«ãããŸããã?
</p>
<p>
å 士 : ãããããšãã¯ããã£ãšçãããããåŸããšã€ãªãããããŠã¿ãã®ã ãã
</p>
<p>
ã ㌠㿠㌠: ãããçãããŠ......ãã ã111ããªããããŸãããããæåã¯ãPãã§ããããããããšæ®ãã¯ã11ãã§ããã
ããã¯ãŽã£ããåãã®ããªãããæ¬¡ã®ã00011ããã 1 æååããŠã110ãã«ããã°ãããã§ããã
</p>
<p>
å 士 : ãããããã€ãŸããEãã ãã
</p>
<p>
ã ㌠㿠㌠: ããã§æ®ãã®ãã0011ããªã®ã§ããããæ¬¡ããåããŠã00111ãã«ããŠãTããš......ãå
šéšã§ããŸãããæ
åŸã®ã0000ãã¯æšãŠã¡ããã°ãããã§ããã?
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_memorableCodes3">
</center>
<br/>
<p>
å 士 : ããããããããããæ¬¡ã¯ããããã
</p>
<pre>
?D-C'?-C'-LMGZN?FNJKN- WEYN?P'QMRWLPZLKKTPOVRGDI
</pre>
<p>
å 士 : ããã«ããããã
</p>
<pre>
?P'QNPY?IXX?IXXK.BI -G?R'RPP'RPOVWDMW?SWUVG'-LCMGQ
</pre>
<p>
å 士 : ä»äžãã«ããããã
</p>
<pre>
?P'QMDUEQ GADKOQ ?SWUVG'-LCMG?X?IGX,PUL.?UL.VNQQI
</pre>
<p>
ã ㌠㿠㌠: ãã£ããé¢åã ãªããå士ãä»åºŠã¯èªåã§ããã°ã©ã ãäœã£ãŠäžãããã
</p>
<p>
ãšããããšã§ãå士ã®ãããã«ãäžã®æç« ã眮ãæããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ãããšããŠãïŒã€ã®æååïŒè¡šã«å«ãŸããæåãããªã 200 æå以äžã®æååïŒãïŒè¡ã«äžããããŸããå
¥åã®çµãããŸã§åŠçããŠãã ãããããŒã¿ã»ããã®æ°ã¯ 200 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ã倿åŸã®æååãïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
?D-C'KOPUA
</pre>
<H2>Output for the Sample Input</H2>
<pre>
PETER POTTER
</pre>
<!--
<p>
Judge error has been fixed on 2009/10/12. We are very sorry for the inconvenience.
</p>
-->
|
p00541 |
<h2>åå£ (Rampart)</h2>
<p>
æŽå²åŠè
ã§ãã JOI ææã¯ïŒãã€ãŠååšãã IOI çåœã«ã€ããŠç ç©¶ããŠããïŒ
</p>
<p>
éå»ã®èª¿æ»ã«ãããšïŒIOI çåœã¯çžŠ <var>H</var> è¡ïŒæšª <var>W</var> åã®ãã¹ã«åºåãããé·æ¹åœ¢ã®åœ¢ãããŠããïŒIOI çåœã®éŠéœã¯ïŒé²è¡ã®ããã«åå£ã§å²ãããŠããïŒ
</p>
<p>
IOI çåœã®éŠéœãå²ãåå£ã¯æ¬¡ã®ãããªåœ¢ãããŠããïŒåå£ã«ã¯å€§ãããšåŒã°ããå€ãå®ãŸã£ãŠããïŒå€§ãã <var>s</var> (<var>s</var> ≥ 3) ã®åå£ãšã¯ïŒ<var>s</var> × <var>s</var> ã®æ£æ¹åœ¢ã®é åããå€åšä»¥å€ã® (<var>s</var> â 2) × (<var>s</var> â 2) ã®æ£æ¹åœ¢ã®é åãé€ãããã®ã§ããïŒ
</p>
<p>
調æ»ã«ãããšïŒéŠéœãå²ãåå£ã®å€§ãã㯠<var>L</var> 以äžã§ãã£ãïŒãŸãïŒIOI çåœã®ããã€ãã®ãã¹ã«ã¯åå£ãååšããªãã£ãããšãããã£ãŠããïŒ
</p>
<p>
JOI ææã¯ïŒãããªãç ç©¶ã®ããã«ïŒåå£ãšããŠãããããã®ãäœéãããããç¥ãããïŒ
</p>
<h3>課é¡</h3>
<p>
IOI çåœã®å€§ãããšïŒåå£ã®å€§ããã®æå°å€ïŒåå£ãååšããªãã£ãããšãåãã£ãŠãããã¹ã®æ
å ±ãäžãããããšãïŒåå£ãšããŠãããããã®ã¯äœéãããããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h3>å
¥å</h3>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒæŽæ° <var>H</var>, <var>W</var>, <var>L</var>, <var>P</var> ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒIOI çåœã¯çžŠ <var>H</var> è¡ïŒæšª <var>W</var> åã®ãã¹ã«åºåãããé·æ¹åœ¢ã®åœ¢ãããŠããïŒåå£ã®å€§ãã㯠<var>L</var> 以äžã§ããïŒåå£ãååšããªãã£ãããšãããã£ãŠãããã¹ã <var>P</var> ãã¹ååšããããšã衚ãïŒ</li>
<li> ç¶ã <var>P</var> è¡ã®ãã¡ã® <var>i</var> è¡ç® (1 ≤ <var>i</var> ≤ <var>P</var>) ã«ã¯ïŒæŽæ° <var>A<sub>i</sub></var>, <var>B<sub>i</sub></var> ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒIOI çåœã®äžãã <var>A<sub>i</sub></var> è¡ç®ïŒå·Šãã <var>B<sub>i</sub></var> åç®ã®ãã¹ã«ã¯åå£ãååšããªãã£ãããšãããã£ãŠããããšã衚ãïŒ
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«ïŒåå£ãšããŠãããããã®ã¯äœéãããããè¡šãæŽæ°ã 1 è¡ã§åºåãã.
</p>
<h3>å¶é</h3>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li> 1 ≤ <var>H</var> ≤ 4 000ïŒ </li>
<li> 1 ≤ <var>W</var> ≤ 4 000ïŒ</li>
<li> 3 ≤ <var>L</var> ≤ <var>H</var> ã〠3 ≤ <var>L</var> ≤ <var>W</var>ïŒ</li>
<li> 0 ≤ <var>P</var> ≤ 100 000ïŒ</li>
<li> 1 ≤ <var>A<sub>i</sub></var> ≤ <var>H</var> (1 ≤ <var>i</var> ≤ <var>P</var>)ïŒ</li>
<li> 1 ≤ <var>B<sub>i</sub></var> ≤ <var>W</var> (1 ≤ <var>i</var> ≤ <var>P</var>)ïŒ</li>
<li> (<var>A<sub>i</sub></var>, <var>B<sub>i</sub></var>) ≠ (<var>A<sub>j</sub></var>, <var>B<sub>j</sub></var>) (1 ≤ <var>i</var> < <var>j</var> ≤ <var>P</var>)ïŒ</li>
</ul>
<h3>å
¥åºåäŸ</h3>
<h3>å
¥åäŸ 1 </h3>
<pre>
5 5 3 2
2 2
4 3
</pre>
<h3>åºåäŸ 1</h3>
<pre>
4
</pre>
<p>
ãã®å
¥åäŸã®å ŽåïŒåå£ãšããŠãããããã®ã¯ä»¥äžã® 4 éããèããããïŒãã ãïŒ× ã§ç€ºãããã¹ã¯åå£ãååšããªãã£ãããšãããã£ãŠãããã¹ã§ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_rampart">
</center>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
7 8 4 3
2 2
3 7
6 5
</pre>
<h3> åºåäŸ 2</h3>
<pre>
13
</pre>
<h3>å
¥åäŸ 3 </h3>
<pre>
4000 4000 1234 4
1161 3028
596 1892
3731 2606
702 1530
</pre>
<h3>åºåäŸ 3</h3>
<pre>
7050792912
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02086 |
<h1>I: Palindrome Compliment</h1>
<h2>å顿</h2>
<p>å°æ± ããã¯ããŒã ã¡ã€ããããè€ããŸãã
圌ã¯ããŒã ã¡ã€ãã§ããæŸåŽãããæåå $S$ ã§è€ããŸãããã®åœ¢åŒã¯ä»¥äžã®æ¡ä»¶ãæºãããŸãã</p>
<ul>
<li>$Hoge, Zaki, O$ ã¯å°æåã¢ã«ãã¡ãããã®ã¿ãããªãæåå</li>
<li>$S = Hoge + Zaki + Hoge + O$ ($+$ ã¯æååã®çµåã衚ã)</li>
<li>$S$ ã¯åæ</li>
</ul>
<p>å°æ± ããã¯$Hoge$ã®é·ãã$N$ãšãããšãã«ãæŸåŽããã®è€ãæ¹ãäœéãããã®ãæ°ã«ãªããŸããã
3人ç®ã®ããŒã ã¡ã³ããŒã«ããŠred coderã§ããããªãã¯å°æ± ããã®ä»£ããã«çããèšç®ããããšã«ãªããŸããã</p>
<p>æåå $Zaki, O$ ãš æŽæ° $N$ ãäžããããã®ã§ãããããçµã¿åããã®æ°ãæ±ããŠãã ããïŒ
ãªããçãã¯éåžžã«å€§ãããªãå¯èœæ§ãããã®ã§ã$10^9 + 7$ ã§å²ã£ã äœããåºåããŠãã ããã</p>
<h2>å¶çŽ</h2>
<ul>
<li>$Zaki$ ãš $O$ ã¯å°æåã¢ã«ãã¡ããããããªãæåå</li>
<li>$1 \leq |Zaki| \leq 10^5$</li>
<li>$1 \leq |O| \leq 10^5$</li>
<li>$1 \leq N \leq 10^9$</li>
</ul>
<h2>å
¥å</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããŸãã</p>
<pre>$Zaki$
$O$
$N$</pre>
<h2>åºå</h2>
<p>çãã1è¡ã«åºåããŠãã ããã</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>zaki
o
4
</pre>
<h3>åºåäŸ1</h3>
<pre>0
</pre>
<h3>å
¥åäŸ2</h3>
<pre>aab
aa
3
</pre>
<h3>åºåäŸ2</h3>
<pre>26
</pre>
<h3>å
¥åäŸ3</h3>
<pre>aaa
aaaa
3
</pre>
<h3>åºåäŸ3</h3>
<pre>1
</pre>
|
p00812 | <H1><font color="#000">Problem B:</font> Equals are Equals</H1>
<p>
Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink.
</p>
<p>
His headache came from the ``creativity'' of his students. They provided him a variety of ways to answer each problem. He has his own answer to each problem, which is correct, of course, and the best from his aesthetic point of view.
</p>
<p>
Some of his students wrote algebraic expressions equivalent to the expected answer, but many of them look quite different from Mr. Simpson's answer in terms of their literal forms. Some wrote algebraic expressions not equivalent to his answer, but they look quite similar to it. Only a few of the students' answers were exactly the same as his.
</p>
<p>
It is his duty to check if each expression is mathematically equivalent to the answer he has prepared. This is to prevent expressions that are equivalent to his from being marked as ``incorrect'', even if they are not acceptable to his aesthetic moral.
</p>
<p>
He had now spent five days checking the expressions. Suddenly, he stood up and yelled, ``I've had enough! I must call for help.''
</p>
<p>
Your job is to write a program to help Mr. Simpson to judge if each answer is equivalent to the ``correct'' one. Algebraic expressions written on the papers are multi-variable polynomials over variable symbols <i>a</i>, <i>b</i>,..., <i>z</i> with integer coefficients, e.g.,
(<i>a</i> + <i>b</i><sup>2</sup>)(<i>a</i> - <i>b</i><sup>2</sup>), <i>ax</i><sup>2</sup> +2<i>bx</i> + <i>c</i> and (<i>x</i><sup>2</sup> +5<i>x</i> + 4)(<i>x</i><sup>2</sup> + 5<i>x</i> + 6) + 1.
</p>
<p>
Mr. Simpson will input every answer expression as it is written on the papers; he promises you that an algebraic expression he inputs is a sequence of terms separated by additive operators `<span>+</span>' and `<span>-</span>', representing the sum of the terms with those operators, if any; a term is a juxtaposition of multiplicands, representing their product; and a multiplicand is either (a) a non-negative integer as a digit sequence in decimal, (b) a variable symbol (one of the lowercase letters `<span>a</span>' to `<span>z</span>'), possibly followed by a symbol `<span>^</span>' and a non-zero digit, which represents the power of that variable, or (c) a parenthesized algebraic expression, recursively. Note that the operator `<span>+</span>' or `<span>-</span>' appears only as a binary operator and not as a unary operator to specify the sing of its operand.
</p>
<p>
He says that he will put one or more space characters before an integer if it immediately follows another integer or a digit following the symbol `<span>^</span>'. He also says he may put spaces here and there in an expression as an attempt to make it readable, but he will never put a space between two consecutive digits of an integer. He remarks that the expressions are not so complicated, and that any expression, having its `<span>-</span>'s replaced with `<span>+</span>'s, if any, would have no variable raised to its 10th power, nor coefficient more than a billion, even if it is fully expanded into a form of a sum of products of coefficients and powered variables.
</p>
<H2>Input</H2>
<p>
The input to your program is a sequence of blocks of lines. A block consists of lines, each containing an expression, and a terminating line. After the last block, there is another terminating line. A terminating line is a line solely consisting of a period symbol.
</p>
<p>
The first expression of a block is one prepared by Mr. Simpson; all that follow in a block are answers by the students. An expression consists of lowercase letters, digits, operators `<span>+</span>', `<span>-</span>' and `<span>^</span>', parentheses `<span>(</span>' and `<span>)</span>', and spaces. A line containing an expression has no more than 80 characters.
</p>
<H2>Output</H2>
<p>
Your program should produce a line solely consisting of ``<span>yes</span>'' or ``<span>no</span>'' for each answer by the students corresponding to whether or not it is mathematically equivalent to the expected answer. Your program should produce a line solely containing a period symbol after each block.
</p>
<H2>Sample Input</H2>
<pre>
a+b+c
(a+b)+c
a- (b-c)+2
.
4ab
(a - b) (0-b+a) - 1a ^ 2 - b ^ 2
2 b 2 a
.
108 a
2 2 3 3 3 a
4 a^1 27
.
.
</pre>
<H2>Output for the Sample Input</H2>
<pre>
yes
no
.
no
yes
.
yes
yes
.
</pre>
|
p01700 |
<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>Golf</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>ã¯ãã»ã¯è¶
äžæµã®è
ãæã£ãããã«ããã°ã©ããŒã§ããïŒããã°ã©ãã³ã°ã³ã³ãã¹ãçéã§ãã®åãç¥ãã¬è
ã¯ããªãïŒ
ã¢ã«ãŽãªãºã ïŒããŒã¿ãã€ãã³ã°ïŒãããã³ã°ïŒAIïŒâŠâŠãããšãããã倧äŒãç·ãªãã«ããŠããïŒ
ãããªã¯ãã»ã次ã®ç®æšã«æ®ããç«¶æã¯ïŒãã³ãŒããŽã«ããã§ããïŒ
</p>
<p>ã³ãŒããŽã«ããšã¯ïŒäžããããåé¡ã«å¯Ÿãæ£çãè¿ãããã°ã©ã ã®ããœãŒã¹ã³ãŒãã®çãããç«¶ãç«¶æã§ããïŒ
ã³ãŒããŽã«ãã«ãããŠã¯ïŒç°ãªãããã°ã©ãã³ã°èšèªéã§å
¬å¹³ãªæ¯èŒãé£ããããïŒäœ¿çšèšèªãéå®ãããããšãå€ãïŒ
ã¯ãã»ã次ã«çã£ãŠãã倧äŒãICPC (International Competition of Program Compactness)ãã§ã¯ïŒ
ãAJAGOLããšåŒã°ããããã°ã©ãã³ã°èšèªã®ã¿ã䜿çšã§ããã«ãŒã«ãšãªã£ãŠããïŒ
ã³ãŒãã1ãã€ãã§ãçãããããïŒã¯ãã»ãåãã«æ³šç®ããã®ã¯ïŒã宿°å®£èšãã®ççž®ã ã£ãïŒ
</p>
<p>AJAGOLã¯ãã«ããã®36bitã¢ãŒããã¯ãã£ã«æé©åããŠèšèšãããäŒçµ±ããèšèªã§ããïŒ
æŽæ°ã衚çŸããããã«36bit笊å·ç¡ãæŽæ°åãçšæãããŠããïŒ$0$ ä»¥äž $2^{36}-1$ 以äžã®æŽæ°ãæ±ãããšãã§ããïŒ
ããŠïŒAJAGOLã®å®æ°ã¯éåžžïŒæ°å[0-9]ãä»»æã®åæ°çšããå鲿°ã§å®£èšãããïŒ
ãŸãïŒæŒç®åãšããŠä»¥äžã®è¡šã®æŒç®åãçšããããšãã§ããïŒ
</p>
<table style="align:center"border="1"><thead><tr><th style="width:80px">åªå
é äœ</th><th style="width:80px">æŒç®å</th><th style="width:120px">çµåæ§</th><th style="width:240px">æå³</th></tr>
</thead>
<tbody><tr><td>1</td><td>( , )</td><td>-</td><td>æ¬åŒ§</td></tr>
<tr><td>2</td><td>^</td><td>å³çµå</td><td>åªä¹: a^b := $a^b$</td></tr>
<tr><td>3</td><td>*</td><td>å·Šçµå</td><td>ä¹ç®: a*b := $a \times b$</td></tr>
<tr><td>3</td><td>/</td><td>å·Šçµå</td><td>é€ç®: a/b := $ \lfloor a \div b \rfloor$</td></tr>
<tr><td>4</td><td>+</td><td>å·Šçµå</td><td>å ç®: a+b := $a + b$</td></tr>
<tr><td>4</td><td>-</td><td>å·Šçµå</td><td>æžç®: a-b := $a - b$</td></tr>
</tbody>
</table>
<br>
<p>ããã§ïŒåªå
é äœã®å€ãå°ããæŒç®ã»ã©åªå
çã«èšç®ããïŒåãå€ã®ãšãã«ã¯çµåæ§ã«åŸã£ãé åºã§èšç®ãããïŒ
äŸãã° "<samp>2^2^3+8/3*2</samp>" ãšããèšç®åŒã¯ïŒ2^2^3+8/3*2 = 2^8+8/3*2 = 256+8/3*2 = 256+2*2 = 256+4 = 260 ãšããé åºã§èšç®ãããïŒ
ãŸãïŒæŒç®éäžã®å€ã $[0, 2^{36}-1]$ ã«åãŸããªãèšç®ããŒãé€ç®ïŒãŒãã®ãŒãä¹ã¯ïŒAJAGOLã§ã¯å®è¡æãšã©ãŒãšãªãããé¿ããå¿
èŠãããïŒ
äŸãã° "<samp>2^36-100</samp>"ïŒ"<samp>1111/0</samp>"ïŒ"<samp>(2-2)^0</samp>" ãªã©ã¯å®è¡æãšã©ãŒãšãªãïŒ
</p>
<p>è¶
äžæµã®ããã«ããã°ã©ããŒã§ããã¯ãã»ã¯ïŒãããã®æŒç®åãçšããããšã«ããïŒéåžžãããçã宿°å®£èšãå¯èœã§ããããšãèŠæããïŒ
äŸãã°ïŒ117649ã¯èšãããšç¥ãã $7^6$ ã§ãããïŒAJAGOLã®åªä¹æŒç®åãçšããããšã§ "<samp>7^6</samp>" ãš3ãã€ãã§æžãããšãã§ããïŒ
ããã¯éåžžã® "<samp>117649</samp>" ãšãã宣èšã§å¿
èŠãšãªã6ãã€ãããã3ãã€ãçãïŒ
ãã£ãŠïŒAJAGOLã«ããã³ãŒããŽã«ãã§ã¯ïŒ117649ã宿°ãšããŠçšãããå Žåã«ã¯ "<samp>7^6</samp>" ãšå®£èšããã®ãåºæ¬ãšãªãïŒ
</p>
<p>宿°å®£èšã®ççž®ã¯ã³ãŒããŽã«ãã«ãããŠæãåºæ¬çãªãã¯ããã¯ã®1ã€ã§ãããïŒãããŸã§å°æå
ã®ãã¯ããã¯ãšãèšããïŒ
ãã®ãããªãšããã«å€å€§ãªæéãæããŠããŠã¯ïŒæ¬è³ªçãªã³ãŒãã®ççž®ã«æéãå²ããªããªã£ãŠããŸãïŒ
ããã§ã¯ãã»ã¯ïŒéè² æŽæ°ãå鲿°ã§å
¥åãããšãïŒããã衚çŸããAJAGOL宿°å®£èšãšããŠæãçããã®ã調ã¹ãããšã«ããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ
åããŒã¿ã»ããã¯æŽæ° $N$ ($0 \leq N \leq 2^{36}-1$) ãå«ã1è¡ã§äžããããïŒ
å
¥åã®çµäºã¯ $-1$ ã®ã¿ãå«ã1è¡ã§è¡šãããïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸãïŒäžããããæŽæ° $N$ ã衚çŸããæãçãAJAGOL宿°å®£èšã®é·ãã1è¡ã§åºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>117649
1
125000
1610612736
68719476636
-1</pre>
<h3>Output for Sample Input</h3>
<pre>3
1
4
6
11</pre>
|
p01350 |
<H1>Problem B: Carrot Tour </H1>
<p>
ããããããåœãæ
è¡ããŠãã. ãã®åœã«ã¯1 ãã<i>n</i> ã®çªå·ãã€ãã<i>n</i> åã®éœåžããã, ãããã¯ä»éœåž1ã«ãã. éœåž<i>i</i> ã¯åº§æšå¹³é¢äžã®1 ç¹(<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) ãšã¿ãªã.
</p>
<p>
ãããã¯ä»¥äžã®æ¡ä»¶ãã¿ããããã«æ
ããã.
</p>
<ul>
<li> ç§»åçµè·¯ã¯æãç·ã§ãã, ãã®åéšåã¯ç°ãªã2 éœåžãçµã¶ç·åã§ãªããã°ãªããªã.</li>
<li> ç§»åçµè·¯ã®å
šé·ã¯<i>r</i> 以äžã§ãªããã°ãªããªã. çµè·¯ã®ãã¡éãªã£ãéšåã, éã£ãåæ°åæ°ãã.</li>
<li> ç§»åããæ¹åãå€ãããšã, æ²ããè§åºŠã¯<i>θ</i> 以äžã§ãªããã°ãªããªã. æåã®ç§»åæ¹åã«å¶éã¯ãªã.</li>
</ul>
<p>
ããããããéœåžããå¥ã®éœåžãžç§»åããããš, ç§»åå
ã®éœåžã§ãã³ãžã³ã1 æ¬ãããã. åãéœåžãè€æ°å蚪ããããšã¯å¯èœã§ãã, 蚪ãããã³ã«ãã³ãžã³ããããã. ãããããã®æ
ã§æã«å
¥ããããšã®ã§ãããã³ãžã³ã®æ¬æ°ã®æå€§å€ãæ±ãã.
</p>
<H2>Input</H2>
<p>
å
¥åã®äžè¡ç®ã«ã¯äžã€ã®æŽæ°<i>n</i> ã, äºè¡ç®ã«ã¯äºã€ã®å®æ°<i>r</i>, <i>θ</i> ãã¹ããŒã¹ã§åºåãããŠäžãããã.
</p>
<p>
1 ≤ <i>n</i> ≤ 20<br>
0 < <i>r</i> < 10<sup>4</sup><br>
0° < <i>θ</i> < 180°<br>
</p>
<p>
ç¶ã<i>n</i> è¡ã«ã¯, æŽæ°<i>x<sub>i</sub></i>, <i>y</sub>i</sub></i> ãã¹ããŒã¹ã§åºåãããŠäžãããã
</p>
<p>
-10 000 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 10 000
</p>
<p>
<i>r</i>, <i>θ</i> ã±10<sup>â3</sup> 以å
ã§å€åãããŠãçãã¯å€ãããªã.<br>
ã©ã®2 ã€ã®éœåžã®äœçœ®ãç°ãªã.
</p>
<H2>Output</H2>
<p>
ãããããã®æ
ã§æã«å
¥ããããšã®ã§ãããã³ãžã³ã®æ¬æ°ã®æå€§å€ãäžè¡ã«åºåãã.
</p>
<H2>Sample Input 1</H2>
<pre>
5
100.1 90.1
0 0
0 10
5 5
10 0
10 10
</pre>
<H2>Sample Output 1</H2>
<pre>
10
</pre>
|
p02985 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices and <var>N-1</var> edges. The vertices are numbered <var>1</var> to <var>N</var>, and the <var>i</var>-th edge connects Vertex <var>a_i</var> and <var>b_i</var>.</p>
<p>You have coloring materials of <var>K</var> colors.
For each vertex in the tree, you will choose one of the <var>K</var> colors to paint it, so that the following condition is satisfied:</p>
<ul>
<li>If the distance between two different vertices <var>x</var> and <var>y</var> is less than or equal to two, <var>x</var> and <var>y</var> have different colors.</li>
</ul>
<p>How many ways are there to paint the tree? Find the count modulo <var>1\ 000\ 000\ 007</var>.</p>
<p><details>
<summary style="display: list-item; outline: none;">What is tree?</summary>
A tree is a kind of graph. For detail, please see: <a href="https://ja.wikipedia.org/wiki/%E6%9C%A8_(%E6%95%B0%E5%AD%A6)">Wikipedia "Tree (graph theory)"</a></details></p>
<p></p></section></div></span> |
p03697 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two integers <var>A</var> and <var>B</var> as the input. Output the value of <var>A + B</var>.</p>
<p>However, if <var>A + B</var> is <var>10</var> or greater, output <code>error</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>A</var> and <var>B</var> are integers.</li>
<li><var>1 †A, B †9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>A + B</var> is <var>10</var> or greater, print the string <code>error</code> (case-sensitive); otherwise, print the value of <var>A + B</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>error
</pre></section>
</div>
</span> |
p00668 |
<H1>Problem J: The Incubator</H1>
<p>
ãµã©ãªãŒãã³ã®æã¯æ©ãããšãªãŒãã³ãŒã¹ãé²ã¿äžæµäŒæ¥ã«å
¥ç€ŸããŠæ°äººãšããè©æžãããã忥ããé ãåã«äžã£ãèŸä»€ã¯æªéã®ææã«ãããå¶æ¥æŽ»åã ã£ãã蟺éãªåå°ã§ã®äžäŸ¿ãªç掻ã匷ããããŠããããäžå¿ã¯å·Šé·ã§ãªãæ 転ã§ããããã®èšŒæ ã«çµŠæããããšäžãã£ãŠãã - ãããªå Žæã§ã¯éãªããŠäœ¿ãããããªãã®ã ãã©ãè¿å¹Žåãã¡ãçŽé¢ããŠããå®å®èŠæš¡ã®ãšãã«ã®ãŒäžè¶³ã«å¯Ÿå¿ãããããç¹å®ã®çç©çš®ã®åäœããè«å€§ãªãšãã«ã®ãŒãçæãããã¯ãããžãŒãéçºãããããã®ç¹å®ã®çç©çš®ãšããã®ãããã®èŸºéãªææã®åºæçš®ãªã®ã ããã®çç©ãçµ¶æ»
ããªãããã«ä¿è·ãã€ã€ãé©åºŠã«ãšãã«ã®ãŒãååããŠããã®ãåã®ä»äºã ã
</p>
<p>
ãšãã«ã®ãŒã®ååã¯ãããã€ãã®ã¹ããããããªãããŸãã¯ããšãã«ã®ãŒã®ååã«äœ¿çšããåäœãéžå¥ãããåäœã«ãã£ãŠåŸããããšãã«ã®ãŒã®éã¯å€§ããç°ãªãã®ã ãæ¬¡ã«ãéžå¥ãããèŠèŸŒã¿ã®ããåäœã«ãã€ã³ãã¥ããŒã·ã§ã³ãšããç¹å¥ãªåŠçãè¡ããã€ã³ãã¥ããŒããããåäœã¯èšå€§ãªãšãã«ã®ãŒã®æºãšãªãäœãããçµ¶ããèãããåãåºãããããã®ã§ãåäœã«ã§ããã ãå€ãã®ãšãã«ã®ãŒã®æºãšãªãäœããèããããŠããç¬éãçã£ãŠãåç°ã®çã«å°ãããããšãåŸ
ã¡ããã®ãšãã«ã®ãŒãæã«å
¥ãããšããä»çµã¿ã ã
</p>
<p>
ãšãªãŒããµã©ãªãŒãã³ã«èª²ãããããã«ãã¯å³ãããããããåã«ãšã£ãŠæ°åäžã®ã€ã³ãã¥ããŒããããåäœã管çããã®ã¯æé£¯åã ã仿¥ã¯ææ«ãªã®ã§æ¬ç€Ÿã«æå ±ãæåºããªããã°ãªããªããã仿ã¯ãšãŠãè¯ãåäœã«ééããããšããã£ãŠãé廿é«ã®æçžŸã«ãªãããã ã
</p>
<p>
ãšåãã§ããã®ãæã®éãæåŸã®æåŸã§ã²ã©ããã¹ããããããŠããŸã£ããSQLæãæã¡ééããŠãä»æã®ææãèšé²ããŠããããŒã¿ããŒã¹ã®ããŒãã« 1 ã€ããŸãããšãµã£é£ã°ããŠããŸã£ãã®ã ãããããªããã°ãä»æã®ææã¯å
šãç¡ããšããããšã«ãªã£ãŠããŸããéæ Œãå·Šé·ããããã¯è§£éããããããããããªãã
</p>
<p>
æåŸã®é Œã¿ã®ç¶±ã¯ãäœæ¥ã®ãã³ã«ããŸãã«ã€ããŠãããã°ãã¡ã€ã«ã ãåã¯ãã€ããåäœãã€ã³ãã¥ããŒããããã³ã«äžæãªæŽæ°ã®çªå·ãæ¯ããã€ã³ãã¥ããŒããããåäœãã¡ã®çªå·ã 1 ã€ã®é
åã«ä¿åããŠãããåã®å¶æ¥æŽ»åã¯ã次ã®ãããªè¡åãããªãã
</p>
<ol>
<li>åäœãã€ã³ãã¥ããŒããããã®åäœã«çªå· x ãå²ãåœãŠããã®åäœã®çªå·ãé
åã®æ«å°Ÿã«è¿œå ããã</li>
<li>é
åã® n çªç®ã®çªå·ã瀺ãåäœãåç°ã®çã«å°ãã</li>
<li>çªå· x ã®åäœãåç°ã®çã«å°ãã</li>
<li>æ®å¿µãªããåã¯æå€§ <i>lim</i> äœã®åäœãã管çã§ããªããåäœãã€ã³ãã¥ããŒããããšããããã€ã³ãã¥ããŒãæžã¿ã®åäœã <i>lim</i> ãè¶
ãããªãã°ãæã«ã€ã³ãã¥ããŒãããåäœããé ã« <i>lim</i> 以äžã«ãªããŸã§åç°ã®çã«å°ãã</li>
</ol>
<p>
åã¯ããã 4 ã€ã®å¶æ¥æŽ»åãè¡ããã³ã«ãæ¬ ããããã°ãã¡ã€ã«ã«èšå
¥ããŠããããããã4 ã®æŽ»åã ãã¯ãã°ãã¡ã€ã«ã«äžåèšå
¥ããŠããªããããããŠãç¹ã«ææ§ãªãšããã¯æ®ããªãããã ã
</p>
<p>
ãã€ãåã¯ãåäœã®çªå·ã®é
åã®æäœãæçŽã«è¡ãªã£ãŠããããããä»åºŠã°ããã¯ãæçŽã«æäœããªãããã°ãã¡ã€ã«ãèµ°æ»ããŠããŠã¯éã«åãããã«ãªããæå ±ã®æåºæé㯠5 æéåŸã«è¿«ã£ãŠããã
</p>
<p>
ããã§ãåãã¡ã«ãé¡ãããããã ããã°ãã¡ã€ã«ããåã®å¶æ¥æŽ»åãåçŸããããã°ã©ã ãæžããŠã»ãããããæžããŠãããããã瀌ã«åãã¡ã®é¡ãäºãäœã§ã 1 ã€å¶ããŠãããããäœã ã£ãŠæ§ããªããã©ããªé¡ãããšã ã£ãŠå¶ããŠããããããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã
åã±ãŒã¹ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
ããã«ã¯å
¥åã®ãã©ãŒããããæžãã
<i>q</i> <i>lim</i>
<i>query<sub>0</sub></i> <i>x<sub>0</sub></i>
.
.
.
<i>query<sub>q-1</sub></i> <i>x<sub>q-1</sub></i>
</pre>
<p>
<i>query<sub>i</sub></i> ã0ã®æãã€ã³ãã¥ããŒãããåäœã« <i>x<sub>i</sub></i> ã®çªå·ãå²ãåœãŠãããšã衚ãã
<br>
<i>query<sub>i</sub></i> ã1ã®æãé
åã® <i>x<sub>i</sub></i> çªç®ã®çªå·ã瀺ãåäœãåç°ã®çã«å°ãã<br>
<i>query<sub>i</sub></i> ã2ã®æããã®æç¹ã§é
åã«å«ãŸããŠããäžã§ã<i>x<sub>i</sub></i>ãçªç®ã®åäœã®çªå·ãåºåãã<br>
<i>query<sub>i</sub></i> ã3ã®æãçªå·ã <i>x<sub>i</sub></i> ã®åäœãåç°ã®çã«å°ãã<br>
<i>q</i> = 0 ã〠<i>lim</i> = 0ã®æå
¥åã®çµããã衚ãã<br>
</p>
<p>
<i>lim</i> ã¯32bit signed integerã§è¡šãããšãã§ããæ£ã®æŽæ°ã§ããã<br>
ãã¹ãŠã®ã¯ãšãªãŒã«ã€ããŠã<i>x<sub>i</sub></i> ã¯0以äžã®æŽæ°ã§32bit signed integerã§è¡šãããšãã§ããã<br>
0ã®ã¯ãšãªãŒã«ã€ããŠã<i>x<sub>i</sub></i>ãã¯32bit signed integerã®ç¯å²ã«åãŸãéè² æŽæ°ã§è¡šãããã<br>
1,2ã®ã¯ãšãªãŒã«ã€ããŠã<i>x<sub>i</sub></i> ã®å€ã¯1以äžã®æŽæ°ã§ããããŸãååšããªãé
åã®çªå·ãæå®ãããããšã¯ãªã<br>
3ã®ã¯ãšãªãŒã«ã€ããŠãååšããªãåäœçªå·ãå
¥åã«å«ãŸããããšã¯ãªãã<br>
ãŸãäžåºŠæ¶å»ãããåäœã®çªå·ãå€ãåããã¹ãã±ãŒã¹å
ã§ãå¥ã®åäœã«å²ãåœãŠãããããšã¯ãªãã<br>
</p>
<p>
ãžã£ããžããŒã¿ã¯æ¬¡ã®2ã€ã®ãã¡å°ãªããšãçæ¹ãæºããã<br>
1 ≤ q ≤ 400,000 ãã€ãã¹ãã±ãŒã¹ã®æ°ã5å以äž<br>
1 ≤ q ≤ 10,000 ãã€ãã¹ãã±ãŒã¹ã®æ°ã¯50å以äž<br>
</p>
<h2>Output</h2>
<p>
å
¥åã®ã¯ãšãªãŒã2ã®å Žåãxçªç®ã®åäœçªå·ãåºåãã<br>
åã±ãŒã¹ã®æåŸã«ã¯"end"ãåºåãã<br>
</p>
<h2>Sample input</h2>
<pre>
22 5
0 0
0 1
0 2
0 3
0 4
2 1
2 2
2 3
2 4
2 5
0 5
2 1
0 6
2 2
3 3
2 2
2 2
1 2
2 2
2 1
2 2
2 3
30 5
0 383594529
1 1
0 868094164
0 708344471
0 4102559
0 944076771
0 320398558
1 1
0 949521499
0 1035499529
0 585547493
0 915496840
0 721553343
0 405934659
0 814301872
1 1
2 3
0 919753364
1 1
0 69231610
2 2
0 373477673
0 842917649
0 961543702
0 907959899
2 1
2 2
2 3
2 4
2 5
30 5
0 726736645
0 1
0 344304573
0 241734870
3 726736645
1 3
2 1
0 586879203
2 3
0 511883046
0 481344051
0 154183395
0 435126242
0 185906768
1 1
0 383123551
0 20253038
1 5
2 1
2 2
0 163044554
3 435126242
0 105612613
0 725050544
0 559442328
2 1
2 2
2 3
2 4
2 5
0 0
</pre>
<H2>Sample output</H2>
<pre>
0
1
2
3
4
1
3
4
4
5
2
5
6
end
405934659
405934659
69231610
373477673
842917649
961543702
907959899
end
1
586879203
154183395
435126242
383123551
163044554
105612613
725050544
559442328
end
</pre>
<hr>
<p>
The University of Aizu Programming Contest 2011 Summer<br>
åæ¡: Tomoya Sakai<br>
å顿: Takashi Tayama<br>
</p>
|
p02655 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> boxes numbered <var>1</var> to <var>N</var>, and <var>M</var> balls numbered <var>1</var> to <var>M</var>.
Currently, Ball <var>i</var> is in Box <var>A_i</var>.</p>
<p>You can do the following operation:</p>
<ul>
<li>Choose a box containing two or more balls, pick up one of the balls from that box, and put it into another box.</li>
</ul>
<p>Since the balls are very easy to break, you cannot move Ball <var>i</var> more than <var>C_i</var> times in total.
Within this limit, you can do the operation any number of times.</p>
<p>Your objective is to have Ball <var>i</var> in Box <var>B_i</var> for every <var>i</var> (<var>1 \leq i \leq M</var>).
Determine whether this objective is achievable.
If it is, also find the minimum number of operations required to achieve it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq M \leq 10^5</var></li>
<li><var>1 \leq A_i,B_i \leq N</var></li>
<li><var>1 \leq C_i \leq 10^5</var></li>
<li>In the situation where the objective is achieved, every box contains one or more balls.
That is, for every <var>i</var> (<var>1 \leq i \leq N</var>), there exists <var>j</var> such that <var>B_j=i</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>A_2</var> <var>B_2</var> <var>C_2</var>
<var>\vdots</var>
<var>A_M</var> <var>B_M</var> <var>C_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the objective is unachievable, print <var>-1</var>; if it is achievable, print the minimum number of operations required to achieve it.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2 1
2 1 1
1 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We can achieve the objective in three operations, as follows:</p>
<ul>
<li>Pick up Ball <var>1</var> from Box <var>1</var> and put it into Box <var>2</var>.</li>
<li>Pick up Ball <var>2</var> from Box <var>2</var> and put it into Box <var>1</var>.</li>
<li>Pick up Ball <var>3</var> from Box <var>1</var> and put it into Box <var>3</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
1 2 1
2 1 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>5 5
1 2 1
2 1 1
1 3 2
4 5 1
5 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1 1
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre></section>
</div>
</span> |
p03947 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Two foxes Jiro and Saburo are playing a game called <em>1D Reversi</em>. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.</p>
<p>In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string <var>S</var>. There are |S| (the length of <var>S</var>) stones on the board, and each character in <var>S</var> represents the color of the <var>i</var>-th (<var>1 ⊠i ⊠|S|</var>) stone from the left. If the <var>i</var>-th character in <var>S</var> is <code>B</code>, it means that the color of the corresponding stone on the board is black. Similarly, if the <var>i</var>-th character in <var>S</var> is <code>W</code>, it means that the color of the corresponding stone is white.</p>
<p>Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠|S| ⊠10^5</var></li>
<li>Each character in <var>S</var> is <code>B</code> or <code>W</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of new stones that Jiro needs to place for his purpose.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>BBBWW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.</p>
<p>In either way, Jiro's purpose can be achieved by placing one stone.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>WWWWWW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If all stones are already of the same color, no new stone is necessary.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>WBWBWBWBWB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
</pre></section>
</div>
</span> |
p00392 | <h1>Common-Prime Sort</h1>
<p>
You are now examining a unique method to sort a sequence of numbers in increasing order. The method only allows swapping of two numbers that have a common prime factor. For example, a sequence [6, 4, 2, 3, 7] can be sorted using the following steps.
<br/>
<span>Step 0: 6 4 2 3 7</span> (given sequence)<br/>
<span>Step 1: 2 4 6 3 7</span> (elements 6 and 2 swapped)<br/>
<span>Step 2: 2 6 4 3 7</span> (elements 4 and 6 swapped)<br/>
<span>Step 3: 2 3 4 6 7</span> (elements 6 and 3 swapped)<br/>
</p>
<p>
Depending on the nature of the sequence, however, this approach may fail to complete the sorting. You have given a name "Coprime sort" to this approach and are now examining if a given sequence is coprime-sortable.
</p>
<p>
Make a program to determine if a given sequence can be sorted in increasing order by iterating an arbitrary number of swapping operations of two elements that have a common prime number.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$N$
$a_1$ $a_2$ $...$ $a_N$
</pre>
<p>
The first line provides the number of elements included in the sequence $N$ ($2 \leq N \leq 10^5$). The second line provides an array of integers $a_i$ ($2 \leq a_i \leq 10^5$) that constitute the sequence.
</p>
<h2>Output</h2>
<p>
Output "<span>1</span>" if the sequence is coprime-sortable in increasing order, or "<span>0</span>" otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
5
6 4 2 3 7
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
7
2 9 6 5 6 7 3
</pre>
<h2>Sample Output 2</h2>
<pre>
0
</pre>
|
p00238 |
<!--
<p>
äžåºŠã®é£¯ããã²ãŒã 奜ãã®ã ããåã¯æããããã°ã²ãŒã ã°ããããŠããŸãããã§ãããã ããåã髿 ¡ïŒå¹Žçãã¯ã©ã¹ã¯ããåéšã¢ãŒãã«å
¥ã£ãŠããŸããåéšå匷ãããããã«ã¯ãåœç¶ã²ãŒã ã§éã¹ãæéãçããªã£ãŠããŸããŸãããŸãã¯1æ¥ã«å匷ãããæéãæ±ºããŠãæ®ã£ãæéãã²ãŒã ãªã©ã«äœ¿ãããšã«ããŸããããã ããåã¯ä»ãŸã§èšç»ãå®ãããããããããŸããã§ãããèŠãããããªãã¯ãã ããåã®å匷æéã管çããããã°ã©ã ãæžãããšã«ããŸããã
</p>
1æ¥ã«ãããªããã°ãªããªãå匷ã®ç®æšæéãtãå匷ãéå§ããæå»ãsãçµäºããæå»ãfãšãããŸãã
-->
<p>
å匷ãéå§ããæå»ãšçµäºããæå»ã®æ
å ±ãåºã«ã1æ¥ã§å匷ããæéã®åèšã <var>t</var> 以äžã§ãããããã§ãã¯ããéããŠããªãå Žåã¯è¶³ããªãæéãæ±ããããã°ã©ã ãäœæããŸããæéã¯1æéã1åäœãšããåãç§ã¯èããªããã®ãšããŸããæå»ã¯24æé衚èšã§1æéåäœã§è¡šããŸãã
</p>
<p>
1æ¥ã®å匷ã®ç®æšæéãšãå®éã«å匷ããæéã®æ
å ±ïŒå匷ã®åæ° <var>n</var>ãããããã®å匷ã®éå§æå» <var>s</var> ãšçµäºæå» <var>f</var>ïŒãå
¥åãšããå匷æéã®åèšãç®æšã«éããŠãããã調ã¹ãéããŠããã° "OK" ããéããŠããªãå Žåã¯è¶³ããªãæéãåºåããããã°ã©ã ãäœæããŠãã ããããã ããããããè¡ã£ãå匷æéã¯éè€ããŸããã
</p>
<center>
äŸïŒ
<table style="border: 1px #000 solid" cellpadding="3" cellspacing="3">
<tr>
<td style="border: 1px #000 solid">ç®æšæé</td>
<td style="border: 1px #000 solid">å匷ããæé</td>
<td style="border: 1px #000 solid">å€å®</td>
</tr>
<tr>
<td style="border: 1px #000 solid">10æé</td>
<td style="border: 1px #000 solid"> 6æã11æ ïŒ 5æé<br>
12æã15æ ïŒ 3æé<br>
18æã22æ ïŒ 4æé</td>
<td style="border: 1px #000 solid">OK</td>
</tr>
<tr>
<td style="border: 1px #000 solid">14æé</td>
<td style="border: 1px #000 solid">6æã11æ ïŒ 5æé<br>
13æã20æ ïŒ 7æé<br></td>
<td style="border: 1px #000 solid">2æéäžè¶³</td>
</tr>
</table>
</center>
<br>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>t</var>
<var>n</var>
<var>s<sub>1</sub></var> <var>f<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>f<sub>2</sub></var>
:
<var>s<sub>n</sub></var> <var>f<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ïŒæ¥ã®ç®æšæé <var>t</var> (0 ≤ <var>t</var> ≤ 22)ã ïŒè¡ç®ã«å匷ã®åæ° <var>n</var> (1 ≤ <var>n</var> ≤ 10)ãäžããããŸããç¶ã <var>n</var> è¡ã« <var>i</var> åç®ã®å匷ã®éå§æå» <var>s<sub>i</sub></var> ãšçµäºæå» <var>f</var> (6 ≤ <var>s<sub>i</sub></var>, <var>f<sub>i</sub></var> ≤ 22) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãOK ãŸãã¯è¶³ããªãæéãïŒè¡ã«åºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
10
3
6 11
12 15
18 22
14
2
6 11
13 20
0
</pre>
<h2>åºåäŸ</h2>
<pre>
OK
2
</pre> |
p02205 | <h2>ããããã²ããã (Calculation Training)</h2>
<p>square1001 å㯠E869120 åã«ãèªçæ¥ãã¬ãŒã³ããšããŠäºã€ã®æ°å $A$ ãš $B$ ããã¬ãŒã³ãããŸããã</p>
<p>E869120 åã¯ãã®äºã€ã®æ°åã䜿ã£ãŠãèšç®ãã¬ãŒãã³ã°ãããããšã«ããŸããã</p>
<p>å
·äœçã«ã¯ãE869120åã¯æ¬¡ã®æäœãã¡ããã© $N$ åãããã®æ°ã«è¡ããŸãã</p>
<ul>
<li>奿°åç®ã®æäœã®ãšãã$A$ ã $A-B$ ã§çœ®ãæãã</li>
<li>å¶æ°åç®ã®æäœã®ãšãã$B$ ã $A+B$ ã§çœ®ãæãã</li>
</ul>
<br>
<p>E869120åã $N$ åã®æäœãããåŸã$A$ ãš $B$ ã®å€ãããããããã€ã«ãªã£ãŠãããæ±ããŠãã ããã</p>
<h3>å
¥å</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
$N$
$A$ $B$
</pre>
<h3>åºå</h3>
<p>E869120åã $N$ åã®æäœãããåŸã® $A$ ãš $B$ ã®å€ãããã®é ã«ç©ºçœåºåãã§åºåããŠãã ããã</p>
<p>ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$1 \leq N \leq 1000000000000000000 \ (= 10^{18})$</li>
<li>$1 \leq A \leq 1000000000 \ (= 10^9)$</li>
<li>$1 \leq B \leq 1000000000 \ (= 10^9)$</li>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
3
3 4
</pre>
<h3>åºåäŸ1</h3>
<pre>
-4 3
</pre>
<p>$(A, B)$ ã®å€ã¯ $(3,4) â (-1,4) â (-1,3) â (-4,3)$ ãšå€åããŸãã</p>
<h3>å
¥åäŸ2</h3>
<pre>
8
6 9
</pre>
<h3>åºåäŸ2</h3>
<pre>
3 -6
</pre>
|
p03044 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>.
The <var>i</var>-th edge in the tree connects Vertex <var>u_i</var> and Vertex <var>v_i</var>, and its length is <var>w_i</var>.
Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:</p>
<ul>
<li>For any two vertices painted in the same color, the distance between them is an even number.</li>
</ul>
<p>Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq u_i < v_i \leq N</var></li>
<li><var>1 \leq w_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>u_1</var> <var>v_1</var> <var>w_1</var>
<var>u_2</var> <var>v_2</var> <var>w_2</var>
<var>.</var>
<var>.</var>
<var>.</var>
<var>u_{N - 1}</var> <var>v_{N - 1}</var> <var>w_{N - 1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a coloring of the vertices that satisfies the condition, in <var>N</var> lines.
The <var>i</var>-th line should contain <code>0</code> if Vertex <var>i</var> is painted white and <code>1</code> if it is painted black.</p>
<p>If there are multiple colorings that satisfy the condition, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 2
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
0
1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
2 5 2
2 3 10
1 3 8
3 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
0
1
0
1
</pre></section>
</div>
</span> |
p01079 |
<h1>Problem H: Hogemon Get</h1>
<h2>Problem</h2>
<p>
ãã£ã¡ãåã¯äººæ°ã®ã²ãŒã Hogemon Getã«ç±äžããŠããããã£ã¡ãåãäœãã§ããäŒæŽ¥åœã¯ãããã1ãã<var>N</var>ã®çªå·ãã€ããŠãã<var>N</var>åã®çºãããªãããŸããäŒæŽ¥åœã«ã¯<var>M</var>æ¬ã®éãããããã¹ãŠã®éã¯ç°ãªã2ã€ã®çºãçµãã§ããããã£ã¡ãåã¯éãåæ¹åã«ç§»åããããšãã§ããããé以å€ãéã£ãŠãããçºããå¥ã®çºã«è¡ãããšã¯ã§ããªãã</p>
<p>
Hogemon Getã§ã¯ãçº<var>i</var>ã§ããŒã«ã<var>d<sub>i</sub></var>åå
¥æããããšãã§ããããã ããããçºã§åã³ããŒã«ãå
¥æããããã«ã¯ãæåŸã«ãã®çºã§ããŒã«ãå
¥æããŠãã15å以äžçµéããŠããå¿
èŠãããããªãããã£ã¡ãåã¯çº1ãçº<var>N</var>ãå«ããã¹ãŠã®çºãäœåºŠã§ã蚪ããããšãã§ããã
</p>
<p>
ãã£ã¡ãåã¯æåãçº1ã«ããŠãçº<var>N</var>ã«<var>R</var>å以å
ã§ç§»åããªããã°ãªããªããã€ãŸãã<var>R</var>ååŸã«çº<var>N</var>ã«ããå¿
èŠãããããã£ã¡ãåã¯ç§»åã®éã«ãæå€§ã§ããã€ã®ããŒã«ãå
¥æããããšãã§ããã ãããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var> <var>M</var> <var>R</var>
<var>d<sub>1</sub></var> <var>d<sub>2</sub></var> ... <var>d<sub>N</sub></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>M</sub></var> <var>b<sub>M</sub></var> <var>c<sub>M</sub></var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§ããã<br>
1è¡ç®ã«çºã®åæ°<var>N</var>,éã®æ¬æ°<var>M</var>,å¶éæé<var>R</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ã«çº<var>i</var>(<var>i</var>=1,2,...,<var>N</var>)ã«èšªããããšã§å
¥æããããšãã§ããããŒã«ã®åæ°<var>d<sub>i</sub></var>ã空çœåºåãã§äžããããã<br>
3è¡ç®ãã<var>M</var>+2è¡ç®ã«é<var>j</var>(<var>j</var>=1,2,...,<var>M</var>)ã®æ
å ±<var>a<sub>j</sub></var>,<var>b<sub>j</sub></var>,<var>c<sub>j</sub></var>ã空çœåºåãã§äžããããã<var>j</var>çªç®ã®éã¯çº<var>a<sub>j</sub></var>ãšçº<var>b<sub>j</sub></var>ã®éã<var>c<sub>j</sub></var>åã§ç§»åã§ããããšã衚ãã
</p>
<h2>Constraints</h2>
<ul>
<li>3 ≤ <var>N</var> ≤ 30</li>
<li><var>N</var>-1 ≤ <var>M</var> ≤ min(<var>N</var>×(<var>N</var>-1)/2, 300)
<li>10 ≤ <var>R</var> ≤ 1000</li>
<li>0 ≤ <var>d<sub>i</sub></var> ≤ 10</li>
<li><var>d<sub>1</sub></var> = <var>d<sub>N</sub></var> = 0</li>
<li>1 ≤ <var>a<sub>j</sub></var> < <var>b<sub>j</sub></var> ≤ <var>N</var></li>
<li>5 ≤ <var>c<sub>j</sub></var> ≤ 100</li>
<li>çº1ããçº<var>N</var>ãžã¯<var>R</var>å以å
ã§ç§»åã§ããããšãä¿èšŒãããŠãã</li>
<li>ãã2ã€ã®çºã®çµã«å¯ŸããŠ2æ¬ä»¥äžã®éãããããšã¯ãªã</li>
</ul>
<h2>Output</h2>
<p>
çº1ããçº<var>N</var>ãž<var>R</var>å以å
ã«ç§»åãããŸã§ã«å
¥æããããšãã§ããæå€§ã®ããŒã«ã®åæ°ã1è¡ã§åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 4 40
0 1 1 1 0
1 2 5
2 3 5
3 4 5
4 5 5
</pre>
<h2>Sample Output 1</h2>
<pre>
6
</pre>
<div style="width: 500px;">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_H_figure1" alt="å³1" style="width: 500px;">
</div>
<br>
<table border="1">
<tr><td width="100">çµéæé(å)</td><td width="100">çºã®çªå·</td><td width="120">ããŒã«ã®æ°(å)</td></tr>
<tr><td>0</td><td>1</td><td>0</td></tr>
<tr> <td>5</td><td>2</td><td>1</td></tr>
<tr> <td>10</td><td>3</td><td>2</td></tr>
<tr> <td>15</td><td>4</td><td>3</td></tr>
<tr> <td>20</td><td>3</td><td>3</td></tr>
<tr> <td>25</td><td>2</td><td>4</td></tr>
<tr> <td>30</td><td>3</td><td>5</td></tr>
<tr> <td>35</td><td>4</td><td>6</td></tr>
<tr> <td>40</td><td>5</td><td>6</td></tr>
</table>
<p>
â»çµéæé20åã®çº3ã§ã¯æåŸã«çº3ã§ããŒã«ãå
¥æããŠãã15åçµéããŠããªãã®ã§ããŒã«ãå
¥æããããšãã§ããªãã
</p>
<h2>Sample Input 2</h2>
<pre>
4 3 100
0 3 1 0
1 2 5
2 3 30
3 4 5
</pre>
<h2>Sample Output 2</h2>
<pre>
16
</pre>
<div style="width: 500px;">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_H_figure2" alt="å³2" style="width: 500px;">
</div>
<br>
<table border="1">
<tr><td width="100">çµéæé(å)</td><td width="100">çºã®çªå·</td><td width="120">ããŒã«ã®æ°(å)</td></tr>
<tr style="text-align:right" ><td>0</td><td>1</td><td>0</td></tr>
<tr> <td>5</td><td>2</td><td>3</td></tr>
<tr> <td>20</td><td>2</td><td>6</td></tr>
<tr> <td>35</td><td>2</td><td>9</td></tr>
<tr> <td>50</td><td>2</td><td>12</td></tr>
<tr> <td>65</td><td>2</td><td>15</td></tr>
<tr> <td>95</td><td>3</td><td>16</td></tr>
<tr> <td>100</td><td>4</td><td>16</td></tr>
</table>
<br/>
<h2>Sample Input 3</h2>
<pre>
5 4 50
0 1 1 10 0
1 2 10
2 3 10
2 4 10
4 5 10
</pre>
<h2>Sample Output 3</h2>
<pre>
22
</pre> |
p01583 |
<H1><font color="#000">Problem C:</font> Craftsman</H1>
<p>
Takeshi, a famous craftsman, accepts many offers from all over Japan. However, the tools which he is using now has become already too old. So he is planning to buy new tools and to replace the old ones before next use of the tools. Some offers may incur him monetary cost, if the offer requires the tools to be replaced. Thus, it is not necessarily best to accept all the orders he has received. Now, you are one of his disciples. Your task is to calculate the set of orders to be accepted, that maximizes his earning for a given list of orders and prices of tools. His earning may shift up and down due to sale income and replacement cost.
</p>
<p>
He always purchases tools from his friend's shop. The shop discounts prices for some pairs of items when the pair is purchased at the same time. You have to take the discount into account. The total price to pay may be not equal to the simple sum of individual prices.
</p>
<p>
You may assume that all the tools at the shop are tough enough. Takeshi can complete all orders with replaced tools at this time. Thus you have to buy at most one tool for each kind of tool.
</p>
<H2>Input</H2>
<p>
The input conforms to the following format:
</p>
<p>
<i>N M P</i><br/>
<i>X</i><sub>1</sub> <i>K</i><sub>1</sub> <i>I</i><sub>1,1</sub> ... <i>I</i><sub>1, <i>K</i><sub>1</sub></sub><br/>
...<br/>
<i>X</i><sub><i>N</i></sub> <i>K</i><sub><i>N</i></sub> <i>I</i><sub><i>N</i>,1</sub> ... <i>I</i><sub><i>N</i>, <i>K</i><sub><i>N</i></sub></sub><br/>
<i>Y</i><sub>1</sub><br/>
...<br/>
<i>Y<sub>M</sub></i><br/>
<i>J</i><sub>1,1</sub> <i>J</i><sub>1,2</sub> <i>D</i><sub>1</sub><br/>
...<br/>
<i>J</i><sub><i>P</i>,1</sub> <i>J</i><sub><i>P</i>,2</sub> <i>D<sub>P</sub></i><br/>
</p>
<p>
where <i>N</i>, <i>M</i>, <i>P</i> are the numbers of orders, tools sold in the shop and pairs of discountable items, respectively.
</p>
<p>
The following <i>N</i> lines specify the details of orders. <i>X<sub>i</sub></i> is an integer indicating the compensation for the <i>i</i>-th order, and <i>K<sub>i</sub></i> is the number of tools required to complete the order. The remaining part of each line describes the tools required for completing the order. Tools are specified by integers from 1 through <i>M</i>.
</p>
<p>
The next <i>M</i> lines are the price list at the shop of Takeshi's friend. An integer <i>Y<sub>i</sub></i> represents the price of the <i>i</i>-th tool.
</p>
<p>
The last <i>P</i> lines of each test case represent the pairs of items to be discounted. When Takeshi buys the <i>J</i><sub><i>i</i>,1</sub>-th and the <i>J</i><sub><i>i</i>,2</sub>-th tool at the same time, he has to pay only <i>D<sub>i</sub></i> yen, instead of the sum of their individual prices. It is guaranteed that no tool appears more than once in the discount list, and that max{<i>Y<sub>i</sub></i>, <i>Y<sub>j</sub></i>} < <i>D<sub>i,j</sub></i> < <i>Y<sub>i</sub></i> + <i>Y<sub>j</sub></i> for every discount prices, where <i>D<sub>i,j</sub></i> is the discount price of <i>i</i>-th and <i>j</i>-th tools bought at the same time.
</p>
<p>
Also it is guaranteed that 1 ≤ <i>N</i> ≤ 100, 2 ≤ <i>M</i> ≤ 100, 1 ≤ <i>K<sub>i</sub></i> ≤ 100, 1 ≤ <i>P</i> ≤ <i>M</i>/2 and 1 ≤ <i>X<sub>i</sub></i>, <i>Y<sub>i</sub></i> ≤ 1000.
</p>
<H2>Output</H2>
<p>
Output the maximum possible earning of Takeshi to the standard output.
</p>
<H2>Sample Input and Output</H2>
<H2>Input #1</H2>
<pre>
3 4 2
100 2 1 2
100 1 3
100 1 4
20
20
50
150
1 2 30
3 4 180
</pre>
<H2>Output #1</H2>
<pre>
120
</pre>
<br/>
<H2>Input #2</H2>
<pre>
1 2 1
100 1 2
20
40
1 2 51
</pre>
<H2>Output #2</H2>
<pre>
60
</pre>
<br/> |
p03414 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a directed graph with <var>N</var> vertices and <var>M</var> edges.
The vertices are numbered <var>1, 2, ..., N</var>, and the edges are numbered <var>1, 2, ..., M</var>.
Edge <var>i</var> points from Vertex <var>a_i</var> to Vertex <var>b_i</var>.</p>
<p>For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph.</p>
<p>Here, the reversion of Edge <var>i</var> means deleting Edge <var>i</var> and then adding a new edge that points from Vertex <var>b_i</var> to Vertex <var>a_i</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 1000</var></li>
<li><var>1 \leq M \leq 200,000</var></li>
<li><var>1 \leq a_i, b_i \leq N</var></li>
<li><var>a_i \neq b_i</var></li>
<li>If <var>i \neq j</var>, then <var>a_i \neq a_j</var> or <var>b_i \neq b_j</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>M</var> lines. In the <var>i</var>-th line, if the reversion of Edge <var>i</var> would change the number of the strongly connected components in the graph, print <code>diff</code>; if it would not, print <code>same</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>same
diff
same
</pre>
<p>The number of the strongly connected components is <var>3</var> without reversion of edges, but it will become <var>1</var> if Edge <var>2</var> is reversed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
1 2
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>diff
diff
</pre>
<p>Reversion of an edge may result in multiple edges in the graph.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 9
3 2
3 1
4 1
4 2
3 5
5 3
3 4
1 2
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>same
same
same
same
same
diff
diff
diff
diff
</pre></section>
</div>
</span> |
p01429 |
<script type="text/javascript" src="./varmath.js" charset="UTF-8"></script>
<h2>å顿</h2>
<p>
äžã®äžã®å°å¥³ãã¡ã¯ãã¥ã¥ã¹ããšå¥çŽãé¡ããå¶ããŠãããïŒãããšã²ãããã«éæ³å°å¥³ãšãªãïŒäœ¿ãéæ³ã®åœ¢ã»å¹æã¯é¡ãã«åŒ·ã圱é¿ãåããïŒéæ³å°å¥³<i>ããã</i>ã¡ããã¯æè¿ãã¥ã¥ã¹ããšå¥çŽããæ°ç±³éæ³å°å¥³ã§ããïŒ<i>ããã</i>ã®é¡ãã¯ãäºæ
ã®ããæãåããªããªãïŒé³æ¥œãæŒå¥ããã®ã諊ããŠããç·ã®åãå©ããããšãã§ãã£ãã®ã§ïŒäœãéæ¹é£ã¯é³ç¬Šã茪ã®äžã«äžŠãã 圢ãããŠããïŒ
</p>
<p><i>ããã</i>㯠<var>N</var> åã®é³ç¬Šãæã£ãŠããïŒãããã茪ã®äžã«äžŠã¹ãããšã«ãã£ãŠéæ¹é£ãäœãïŒé³ç¬Šãã©ã®ãããªé çªã§äžŠã¹ããã¯åœŒå¥³ã®èªç±ã§ããïŒéæ¹é£ãäœãããã«ç²Ÿç¥åãæ¶è²»ããïŒãã®éã¯é³ç¬Šã®é
眮ã«ãã£ãŠä»¥äžã®ããã«æ±ºãŸãïŒ
</p>
<ul>
<li>ãŸãïŒ <var>M</var> åã®æ£ã®æŽæ°ãããªã<b>鳿¥œççŸãã</b> <var>S_1,\ ...,\ S_M</var> ãå®ããããŠããïŒ</li>
<li>åé³ç¬Šã¯é³çšãæã£ãŠããïŒé³çšã¯ <var>1</var> ãã <var>M</var> ã®æŽæ° <var>K_1,\ ...,\ K_N</var> ã§è¡šãããïŒ</li>
<li>é³çšã <var>a,\ b\ (a≤b)</var> ã§ãããã㪠2 ã€ã®é³ç¬Šã®éã®<b>åçºå</b>ãšã¯ïŒ <var>[(S_a\ +\ ...\ +\ S_b) / L]</var> ã§å®ããããéã§ããïŒããã§ïŒ<var>L</var> ã¯å
¥åã§äžãããã宿°ã§ããïŒå®æ° <var>x</var> ã«å¯Ÿã㊠<var>[x]</var> 㯠<var>x</var> ãè¶ããªãæå€§ã®æŽæ°ã衚ããã®ãšããïŒ</li>
<li><i>ããã</i>ã®æ¶è²»ãã粟ç¥åã¯ïŒå2ã€ã®é£ãåãé³ç¬Š (<var>N</var> çµååšãã) ã®éã®åçºåã®åèšå€ã§ããïŒ</li>
</ul>
<p>
äŸãã°é³æ¥œççŸããããããã <var>\{100,\ 200,\ 300,\ 400,\ 500\}</var> ã§ïŒé³çšã <var>\{1,\ 3,\ 5,\ 4\}</var> ã§ããé³ç¬Šããã®é çªã§äžŠã¹ãŠéæ¹é£ãäœã£ãæïŒæ¶è²»ããã粟ç¥å㯠<var>37\ (=[(100+200+300)/99]+[(300+400+500)/99]+[(500+400)/99]+[(400+300+200+100)/99])</var> ãšãªãïŒ
</p>
<p>
䜿ãã¹ãé³ç¬Šã®é³çšã®çµã¿åãããšåé³çšã®é³æ¥œççŸãããäžããããã®ã§ïŒæ¶è²»ããã粟ç¥åã®æå°å€ãæ±ããïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ</p>
<pre><var>
N\ M\ L\\
K_1\ K_2\ âŠ\ K_N\\
S_1\ S_2\ âŠ\ S_M
</var></pre>
<p><var>N</var> ã¯<i>ããã</i>ã®æã£ãŠããé³ç¬Šã®æ°ïŒ<var>M</var> ã¯é³æ¥œççŸããã®å€ã®åæ°ïŒ<var>L</var> ã¯åçºåãå®ããã®ã«äœ¿ããã宿°ã§ããïŒ</p>
<p><var>K_i</var> ã¯é³ç¬Šã®é³çšã衚ãïŒ<var>S_j</var> ã¯é³æ¥œççŸããã衚ãïŒ</p>
<h2>åºå圢åŒ</h2>
æ¶è²»ããã粟ç¥åã®æå°å€ã <var>1</var> è¡ã«åºåããïŒ
<h2>å¶çŽ</h2>
<ul>
<li><var>3 ≤ N ≤ 2,000</var></li>
<li><var>1 ≤ M ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ L ≤ 10<sup>5</sup></var></li>
<li><var>1 ≤ K_i ≤ M</var></li>
<li><var>1 ≤ S_j ≤ 10<sup>5</sup></var></li>
<li>å
¥åå€ã¯å
šãп޿°ã§ããïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
4 5 99
1 4 5 3
100 200 300 400 500
</pre>
<h3>åºåäŸ1</h3>
<pre>37</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
3 1 99
1 1 1
100
</pre>
<h3>åºåäŸ 2</h3>
<pre>3</pre>
<hr>
<address>Problem Setter: Flat35</address> |
p03101 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>H</var> rows and <var>W</var> columns of white square cells.</p>
<p>You will choose <var>h</var> of the rows and <var>w</var> of the columns, and paint all of the cells contained in those rows or columns.</p>
<p>How many white cells will remain?</p>
<p>It can be proved that this count does not depend on what rows and columns are chosen.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq H, W \leq 20</var></li>
<li><var>1 \leq h \leq H</var></li>
<li><var>1 \leq w \leq W</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>h</var> <var>w</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of white cells that will remain.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>There are <var>3</var> rows and <var>2</var> columns of cells. When two rows and one column are chosen and painted in black, there is always one white cell that remains.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
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>2 4
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01096 |
<h3>Daruma Otoshi</h3>
<p>
You are playing a variant of a game called "Daruma Otoshi (Dharma Block Striking)".
</p>
<p>
At the start of a game, several wooden blocks of the same size but with varying weights
are stacked on top of each other, forming a tower.
Another block symbolizing Dharma is placed atop.
You have a wooden hammer with its head thicker than the height of a block,
but not twice that.
</p>
<p>
You can choose any two adjacent blocks, except Dharma on the top,
differing at most 1 in their weight,
and push both of them out of the stack with a single blow of your hammer.
The blocks above the removed ones then fall straight down,
without collapsing the tower.
You cannot hit a block pair with weight difference of 2 or more,
for that makes too hard to push out blocks while keeping the balance of the tower.
There is no chance in hitting three blocks out at a time,
for that would require superhuman accuracy.
</p>
<p>
The goal of the game is to remove as many blocks as you can.
Your task is to decide the number of blocks that can be removed
by repeating the blows in an optimal order.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2016_D1" width="80%">
<p>
Figure D1. Striking out two blocks at a time
</p>
</center>
<p>
In the above figure, with a stack of four blocks weighing 1, 2, 3, and
1, in this order from the bottom, you can hit middle
two blocks, weighing 2 and 3, out from the stack. The blocks above will
then fall down, and two blocks weighing 1 and the Dharma block will remain.
You can then push out the remaining pair of weight-1 blocks after that.
</p>
<h3>Input</h3>
<p>
The input consists of multiple datasets.
The number of datasets is at most 50.
Each dataset is in the following format.
</p>
<p>
<i>n</i> <br>
<i>w</i><sub>1</sub> <i>w</i><sub>2</sub> … <i>w</i><sub><i>n</i></sub> <br>
</p>
<p>
<i>n</i> is the number of blocks, except Dharma on the top.
<i>n</i> is a positive integer not exceeding 300.
<i>w</i><sub><i>i</i></sub> gives the weight of the <i>i</i>-th block counted from the bottom.
<i>w</i><sub><i>i</i></sub> is an integer between 1 and 1000, inclusive.
</p>
<p>
The end of the input is indicated by a line containing a zero.
</p>
<h3>Output</h3>
<p>
For each dataset, output in a line the maximum number of blocks you can remove.
</p>
<h3>Sample Input</h3>
<pre>
4
1 2 3 4
4
1 2 3 1
5
5 1 2 3 6
14
8 7 1 4 3 5 4 1 6 8 10 4 6 5
5
1 3 5 1 3
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
4
4
2
12
0
</pre> |
p03551 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is <code>YES</code> or <code>NO</code>.</p>
<p>When he checked the detailed status of the submission, there were <var>N</var> test cases in the problem, and the code received TLE in <var>M</var> of those cases.</p>
<p>Then, he rewrote the code to correctly solve each of those <var>M</var> cases with <var>1/2</var> probability in <var>1900</var> milliseconds, and correctly solve each of the other <var>N-M</var> cases without fail in <var>100</var> milliseconds.</p>
<p>Now, he goes through the following process:</p>
<ul>
<li>Submit the code.</li>
<li>Wait until the code finishes execution on all the cases.</li>
<li>If the code fails to correctly solve some of the <var>M</var> cases, submit it again.</li>
<li>Repeat until the code correctly solve all the cases in one submission.</li>
</ul>
<p>Let the expected value of the total execution time of the code be <var>X</var> milliseconds. Print <var>X</var> (as an integer).</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq M \leq {\rm min}(N, 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>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>X</var>, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, <var>X</var> is an integer not exceeding <var>10^9</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3800
</pre>
<p>In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with <var>1/2</var> probability in <var>1900</var> milliseconds.</p>
<p>The code will succeed in one attempt with <var>1/2</var> probability, in two attempts with <var>1/4</var> probability, and in three attempts with <var>1/8</var> probability, and so on.</p>
<p>Thus, the answer is <var>1900 \times 1/2 + (2 \times 1900) \times 1/4 + (3 \times 1900) \times 1/8 + ... = 3800</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>18400
</pre>
<p>The code will take <var>1900</var> milliseconds in each of the <var>2</var> cases, and <var>100</var> milliseconds in each of the <var>10-2=8</var> cases. The probability of the code correctly solving all the cases is <var>1/2 \times 1/2 = 1/4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>608000
</pre></section>
</div>
</span> |
p02710 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge in this tree connects Vertex <var>a_i</var> and <var>b_i</var>.
Additionally, each vertex is painted in a color, and the color of Vertex <var>i</var> is <var>c_i</var>. Here, the color of each vertex is represented by an integer between <var>1</var> and <var>N</var> (inclusive). The same integer corresponds to the same color; different integers correspond to different colors.</p>
<p>For each <var>k=1, 2, ..., N</var>, solve the following problem:</p>
<ul>
<li>Find the number of simple paths that visit a vertex painted in the color <var>k</var> one or more times.</li>
</ul>
<p><strong>Note:</strong> The simple paths from Vertex <var>u</var> to <var>v</var> and from <var>v</var> to <var>u</var> are not distinguished.</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 c_i \leq N</var></li>
<li><var>1 \leq a_i,b_i \leq N</var></li>
<li>The given graph is a tree.</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>c_1</var> <var>c_2</var> <var>...</var> <var>c_N</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answers for <var>k = 1, 2, ..., N</var> in order, each in its own line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 1
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
4
0
</pre>
<p>Let <var>P_{i,j}</var> denote the simple path connecting Vertex <var>i</var> and <var>j</var>.</p>
<p>There are <var>5</var> simple paths that visit a vertex painted in the color <var>1</var> one or more times:<br/>
<var>P_{1,1}\,,\,</var>
<var>P_{1,2}\,,\,</var>
<var>P_{1,3}\,,\,</var>
<var>P_{2,3}\,,\,</var>
<var>P_{3,3}</var> </p>
<p>There are <var>4</var> simple paths that visit a vertex painted in the color <var>2</var> one or more times:<br/>
<var>P_{1,2}\,,\,</var>
<var>P_{1,3}\,,\,</var>
<var>P_{2,2}\,,\,</var>
<var>P_{2,3}</var> </p>
<p>There are no simple paths that visit a vertex painted in the color <var>3</var> one or more times. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5
1 2 3 4 5
1 2
2 3
3 4
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>5
8
10
5
5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>8
2 7 2 5 4 1 7 5
3 1
1 2
2 7
4 5
5 6
6 8
7 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>18
15
0
14
23
0
23
0
</pre></section>
</div>
</span> |
p03802 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke loves flags.</p>
<p>Snuke is placing <var>N</var> flags on a line.</p>
<p>The <var>i</var>-th flag can be placed at either coordinate <var>x_i</var> or coordinate <var>y_i</var>.</p>
<p>Snuke thinks that the flags look nicer when the smallest distance between two of them, <var>d</var>, is larger. Find the maximum possible value of <var>d</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †10^{4}</var></li>
<li><var>1 †x_i, y_i †10^{9}</var></li>
<li><var>x_i</var> and <var>y_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>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 answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 3
2 5
1 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The optimal solution is to place the first flag at coordinate <var>1</var>, the second flag at coordinate <var>5</var> and the third flag at coordinate <var>9</var>. The smallest distance between two of the flags is <var>4</var> in this case.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
2 2
2 2
2 2
2 2
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>There can be more than one flag at the same position.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>22
93 6440
78 6647
862 11
8306 9689
798 99
801 521
188 206
6079 971
4559 209
50 94
92 6270
5403 560
803 83
1855 99
42 504
75 484
629 11
92 122
3359 37
28 16
648 14
11 269
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>17
</pre></section>
</div>
</span> |
p00687 |
<H1>
Unable Count</H1>
<BLOCKQUOTE>
<P><I>I would, if I could,<BR>
If I couldn't how could I?<BR>
I couldn't, without I could, could I?<BR>
Could you, without you could, could ye?<BR>
Could ye? could ye?<BR>
Could you, without you could, could ye?</I></P></BLOCKQUOTE>
<P>It is true, as this old rhyme says, that we can only DO what
we can DO and we cannot DO what we cannot DO. Changing some of
DOs with COUNTs, we have another statement that we can only COUNT
what we can DO and we cannot COUNT what we cannot DO, which looks
rather false. We could count what we could do as well as we could
count what we couldn't do. Couldn't we, if we confine ourselves
to finite issues?</P>
<P>Surely we can count, in principle, both what we can do and
what we cannot do, if the object space is finite. Yet, sometimes
we cannot count in practice what we can do or what we cannot do.
Here, you are challenged, in a set of all positive integers up
to (and including) a given bound <I>n</I>, to count
all the integers that cannot be represented by a formula of
the form <I>a</I>*<I>i</I>+<I>b</I>*<I>j</I>, where <I>a</I> and
<I>b</I> are given positive integers and <I>i</I> and <I>j</I>
are variables ranging over non-negative integers. You are requested
to report only the result of the count, i.e. how many integers
are not representable.
For example, given <i>n</i> = 7, <i>a</i> = 2, <i>b</i> = 5,
you should answer 2, since 1 and 3 cannot be represented in a
specified form, and the other five numbers are representable as follows:</P>
<PRE>
2 = 2*1 + 5*0, 4 = 2*2 + 5*0, 5 = 2*0 + 5*1,
6 = 2*3 + 5*0, 7 = 2*1 + 5*1.
</PRE>
<H2>Input</H2>
<P>The input is a sequence of lines. Each line consists of three integers,
<I>n, a</I> and <I>b, </I>in this order,<I> </I>separated by a
space<I>.</I> The integers <I>n</I>, <I>a</I> and <I>b</I> are
all positive and at most one million, except those in the last
line. The last line consists of three zeros.</P>
<H2>Output</H2>
<P>For each input line except the last one, your program should
write out a line that contains only the result of the count.</P>
<H2>Sample Input</H2>
<pre>
10 2 3
10 2 5
100 5 25
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
2
80
</pre>
|
p01995 | <h2>G: åæéšåå (Palindromic Subsequences)</h2>
<h3>åé¡</h3>
<p>è±å°æåã®ã¿ãããªãæåå <var>S</var> ãäžããããã®ã§ããã®æåå <var>S</var> ã®<b>é£ç¶ãšã¯éããªã</b>éšååã§ãã£ãŠãåæã§ãããã®ã¯äœçš®é¡ããããæ±ããŠãã ããã</p>
<p>ããã§ã<var>S</var> ã®é£ç¶ãšã¯éããªãéšååãšã¯ãå
ã®æåå <var>S</var> ãã <b><var>1</var> æå以äž</b> <var>|S|</var> æå以äžãä»»æã«éžæã (éžæããããããã®æåã®äœçœ®ã¯éé£ç¶ã§ãè¯ã)ãããããå
ã®é çªéãã«é£çµãããŠã§ããæååã®ããšãæããŸãããã®åé¡ã«ãããŠã空æååã¯éšååãšããŠèªããããªãããšã«æ³šæããŠãã ããã</p>
<p>ãŸããæåå <var>X</var> ãåæã§ãããšã¯ãå
ã®æåå <var>X</var> ãšã<var>X</var> ãå転ããæåå <var>Xâ</var> ãçããããšãæããŸãã</p>
<p>ããã«ãç°ãªãéšååã®ãšãããã®çµæ<b>åãåæãçæããããšããŠããããã¯éè€ããŠæ°ããªã</b>ããšã«æ³šæããŠãã ãããäŸãã° <var>S = </var> <code>acpc</code> ã§ããå Žåã <var>2</var> æåç®ã®ã¿ãããªãéšååãšã<var>4</var> æåç®ã®ã¿ãããªãéšååã¯ã©ã¡ããåæ <code>c</code> ã§ãããããã¯è€æ°åæ°ãããåãããŠäžåºŠã ãæ°ããããšãšããŸãã</p>
<p>çãã¯éåžžã«å€§ãããªãããšãããã®ã§ã <var>1,000,000,007</var> ã§å²ã£ãäœããåºåããŠãã ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre><var>S</var></pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq |S| \leq 2,000</var></li>
<li> <var>S</var> ã«å«ãŸããæåã¯è±å°æåã®ã¿ã§ãã</li>
</ul>
<h3>åºå圢åŒ</h3>
<ul>
<li> çãã <var>1,000,000,007</var> ã§å²ã£ãäœãã <var>1</var> è¡ã§åºåããŠãã ããã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>acpc</pre>
<h3>åºåäŸ1</h3>
<pre>5</pre>
<p>æåå <code>acpc</code> ã®é£ç¶ãšã¯éããªãéšååã§ãã£ãŠåæã§ãããã®ã¯ã <code>a</code>, <code>c</code>, <code>cc</code>, <code>cpc</code>, <code>p</code> ã® <var>5</var> çš®é¡ã§ããéšååã®çš®é¡æ°ãæ°ããããšã«æ³šæããŠãã ããã</p>
<h3>å
¥åäŸ2</h3>
<pre>z</pre>
<h3>åºåäŸ2</h3>
<pre>1</pre>
<p>æ¡ä»¶ãæºããéšåå㯠<code>z</code> ã®ã¿ã§ãã空æååã¯éšååãšããŠèªããããªãããšã«æ³šæããŠãã ããã</p>
<h3>å
¥åäŸ3</h3>
<pre>madokamagica</pre>
<h3>åºåäŸ3</h3>
<pre>28</pre>
|
p02340 | <!--<h1>åå12çž ãã®10:ããŒã«ã«åºå¥ãªãã»ç®±ã«åºå¥ãªãã»å
¥ãæ¹ã«å¶éãªã</h1>-->
<h1>Balls and Boxes 10</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td style="background-color:#aff">10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is <b>not</b> distinguished from the other.</li>
<li>Each box is <b>not</b> distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box can contain an arbitrary number of balls (including zero).</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
5 3
</pre>
<h2>Sample Output 1</h2>
<pre>
5
</pre>
<h2>Sample Input 2</h2>
<pre>
10 5
</pre>
<h2>Sample Output 2</h2>
<pre>
30
</pre>
<h2>Sample Input 3</h2>
<pre>
100 100
</pre>
<h2>Sample Output 3</h2>
<pre>
190569292
</pre>
|
p03223 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>N</var> integers; the <var>i</var>-th of them is <var>A_i</var>.
Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 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>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the absolute differences between the adjacent elements after arranging the given integers in a row in any order you like.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
6
8
1
2
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>21
</pre>
<p>When the integers are arranged as <var>3,8,1,6,2</var>, the sum of the absolute differences between the adjacent elements is <var>|3 - 8| + |8 - 1| + |1 - 6| + |6 - 2| = 21</var>. This is the maximum possible sum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
3
1
4
1
5
9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>25
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
5
5
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p03389 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three integers <var>A</var>, <var>B</var> and <var>C</var>. Find the minimum number of operations required to make <var>A</var>, <var>B</var> and <var>C</var> all equal by repeatedly performing the following two kinds of operations in any order:</p>
<ul>
<li>Choose two among <var>A</var>, <var>B</var> and <var>C</var>, then increase both by <var>1</var>.</li>
<li>Choose one among <var>A</var>, <var>B</var> and <var>C</var>, then increase it by <var>2</var>.</li>
</ul>
<p>It can be proved that we can always make <var>A</var>, <var>B</var> and <var>C</var> all equal by repeatedly performing these operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A,B,C \leq 50</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to make <var>A</var>, <var>B</var> and <var>C</var> all equal.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We can make <var>A</var>, <var>B</var> and <var>C</var> all equal by the following operations:</p>
<ul>
<li>Increase <var>A</var> and <var>C</var> by <var>1</var>. Now, <var>A</var>, <var>B</var>, <var>C</var> are <var>3</var>, <var>5</var>, <var>5</var>, respectively.</li>
<li>Increase <var>A</var> by <var>2</var>. Now, <var>A</var>, <var>B</var>, <var>C</var> are <var>5</var>, <var>5</var>, <var>5</var>, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 6 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31 41 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>23
</pre></section>
</div>
</span> |
p02961 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Jumbo Takahashi will play golf on an infinite two-dimensional grid.</p>
<p>The ball is initially at the origin <var>(0, 0)</var>, and the goal is a grid point (a point with integer coordinates) <var>(X, Y)</var>. In one stroke, Jumbo Takahashi can perform the following operation:</p>
<ul>
<li>Choose a grid point whose Manhattan distance from the current position of the ball is <var>K</var>, and send the ball to that point.</li>
</ul>
<p>The game is finished when the ball reaches the goal, and the score will be the number of strokes so far. Jumbo Takahashi wants to finish the game with the lowest score possible.</p>
<p>Determine if the game can be finished. If the answer is yes, find one way to bring the ball to the goal with the lowest score possible.</p>
<p><details><summary>What is Manhattan distance?</summary><div></div></details></p>
<p>The Manhattan distance between two points <var>(x_1, y_1)</var> and <var>(x_2, y_2)</var> is defined as <var>|x_1-x_2|+|y_1-y_2|</var>.</p>
<p></p></section></div></span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.