question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p03216 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.<br/>
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.</p>
<p>Given a string <var>S</var> of length <var>N</var> and an integer <var>k</var> <var>(k \geq 3)</var>,
he defines the <em><var>k</var>-DMC number</em> of <var>S</var> as the number of triples <var>(a, b, c)</var> of integers that satisfy the following conditions:</p>
<ul>
<li><var>0 \leq a < b < c \leq N - 1</var></li>
<li><var>S[a]</var> = <code>D</code></li>
<li><var>S[b]</var> = <code>M</code></li>
<li><var>S[c]</var> = <code>C</code></li>
<li><var>c-a < k</var></li>
</ul>
<p>Here <var>S[a]</var> is the <var>a</var>-th character of the string <var>S</var>. Indexing is zero-based, that is, <var>0 \leq a \leq N - 1</var> holds.</p>
<p>For a string <var>S</var> and <var>Q</var> integers <var>k_0, k_1, ..., k_{Q-1}</var>, calculate the <var>k_i</var>-DMC number of <var>S</var> for each <var>i</var> <var>(0 \leq i \leq Q-1)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>3 \leq N \leq 10^6</var></li>
<li><var>S</var> consists of uppercase English letters</li>
<li><var>1 \leq Q \leq 75</var></li>
<li><var>3 \leq k_i \leq N</var></li>
<li>All numbers given in input are integers</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
<var>Q</var>
<var>k_{0}</var> <var>k_{1}</var> <var>...</var> <var>k_{Q-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <var>Q</var> lines.
The <var>i</var>-th line should contain the <var>k_i</var>-DMC number of the string <var>S</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>18
DWANGOMEDIACLUSTER
1
18
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>1
</pre>
<p><var>(a,b,c) = (0, 6, 11)</var> satisfies the conditions.<br/>
Strangely, Dwango Media Cluster does not have so much DMC-ness by his definition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>18
DDDDDDMMMMMCCCCCCC
1
18
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>210
</pre>
<p>The number of triples can be calculated as <var>6\times 5\times 7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3>
<pre>54
DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED
3
20 30 40
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3>
<pre>0
1
2
</pre>
<p><var>(a, b, c) = (0, 23, 36), (8, 23, 36)</var> satisfy the conditions except the last one, namely, <var>c-a < k_i</var>.<br/>
By the way, DWANGO is an acronym for "Dial-up Wide Area Network Gaming Operation".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Output 4</h3>
<pre>30
DMCDMCDMCDMCDMCDMCDMCDMCDMCDMC
4
5 10 15 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3>
<pre>10
52
110
140
</pre></section>
</div>
</span> |
p04029 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give <var>1</var> candy to the first child in the line, <var>2</var> candies to the second child, ..., <var>N</var> candies to the <var>N</var>-th child. How many candies will be necessary in total?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the necessary number of candies in total.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The answer is <var>1+2+3=6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>55
</pre>
<p>The sum of the integers from <var>1</var> to <var>10</var> is <var>55</var>.</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>
<p>Only one child. The answer is <var>1</var> in this case.</p></section>
</div>
</span> |
p02057 | <h2>F: MOD Rush</h2>
<h3>åé¡</h3>
<p>é·ã <var>N</var> ã®æ£ã®æŽæ°å <var>A</var> ãšãé·ã <var>M</var> ã®æ£ã®æŽæ°å <var>B</var> ãäžããããŸãã</p>
<p>ãã¹ãŠã® <var>(i, j)</var> <var>(1 \leq i \leq N, 1 \leq j \leq M)</var> ã«ã€ããŠã<var>A_i</var> ã <var>B_j</var> ã§å²ã£ãããŸããæ±ãããããã®åãåºåããŠãã ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>N</var> <var>M</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
<var>B_1</var> <var>B_2</var> <var>...</var> <var>B_M</var>
</pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq N, M \leq 2 \times 10^5</var></li>
<li> <var>1 \leq A_i, B_i \leq 2 \times 10^5</var></li>
<li> å
¥åã¯ãã¹ãп޿°ã§äžãããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>çãã <var>1</var> è¡ã«åºåããŠãã ãããæåŸã«æ¹è¡ããŠãã ããã</p>
<h3>å
¥åäŸ 1</h3>
<pre>
3 3
5 1 6
2 3 4
</pre>
<h3>åºåäŸ 1</h3>
<pre>9</pre>
<ul>
<li> æ°å <var>A</var> ã® <var>1</var> çªç®ã®èŠçŽ ããæ°å <var>B</var> ã®åèŠçŽ ã§å²ã£ãããŸããèããŸãã<var>5</var> ã <var>2</var> ã§å²ããšããŸã㯠<var>1</var>ã<var>3</var> ã§å²ããšããŸã㯠<var>2</var>ã<var>4</var> ã§å²ããšããŸã㯠<var>1</var> ã§ãã</li>
<li> åæ§ã« <var>2</var> çªç®ã®èŠçŽ ã«ã€ããŠãèãããšãããŸãã¯ãããã <var>1, 1, 1</var> ã§ãã</li>
<li> <var>3</var> çªç®ã®èŠçŽ ã«ã€ããŠãèãããšãããŸãã¯ãããã <var>0, 0, 2</var> ã§ãã</li>
<li> ããŸããåèšãããš <var>1 + 2 + 1 + 1 + 1 + 1 + 0 + 0 + 2 = 9</var> ãšãªãã®ã§ã<var>9</var> ãåºåããŸãã</li>
</ul>
<h3>å
¥åäŸ 2</h3>
<pre>
2 4
2 7
3 3 4 4
</pre>
<h3>åºåäŸ 2</h3>
<pre>16</pre>
<ul>
<li> æ°åå
ã«ã¯åãå€ãè€æ°å«ãŸããŠããããšããããŸãããããããã®èŠçŽ ã«å¯ŸããŠããŸããèšç®ããŠåãæ±ããŸãã</li>
</ul>
<h3>å
¥åäŸ 3</h3>
<pre>
3 1
12 15 21
3
</pre>
<h3>åºåäŸ 3</h3>
<pre>0</pre>
|
p00590 |
<H1>Pair of Primes</H1>
<p>
We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing
order and decreasing order like this:
</p>
<pre>
1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1
</pre>
<p>
Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both
numbers in the pairs are prime.
</p>
<H2>Input</H2>
<p>
Input contains several test cases. Each test case consists of an integer N in
one line.
</p>
<H2>Output</H2>
<p>
For each line of input, output P .
</p>
<H2>Sample Input</H2>
<pre>
1
4
7
51
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
2
2
6
</pre>
|
p02407 |
<H1>Reversing Numbers</H1><br>
<p>
Write a program which reads a sequence and prints it in the reverse order.
</p>
<H2>Input</H2>
<p>
The input is given in the following format:
</p>
<pre>
<var>n</var>
<var>a</var><sub>1</sub> <var>a</var><sub>2</sub> . . . <var>a</var><sub><var>n</var></sub>
</pre>
<p>
<var>n</var> is the size of the sequence and <var>a<sub>i</sub></var> is the <var>i</var>th element of the sequence.
</p>
<H2>Output</H2>
<p>
Print the reversed sequence in a line. Print a single space character between adjacent elements (Note that your program should not put a space character after the last element).
</p>
<h2>Constraints</h2>
<ul>
<li><var>n</var> ≤ 100</li>
<li>0 ≤ <var>a<sub>i</sub></var> < 1000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
1 2 3 4 5
</pre>
<H2>Sample Output 1</H2>
<pre>
5 4 3 2 1
</pre>
<H2>Sample Input 2</H2>
<pre>
8
3 3 4 4 5 8 7 9
</pre>
<H2>Sample Output 2</H2>
<pre>
9 7 8 5 4 4 3 3
</pre>
<h2>Note</h2>
<center>
<a href="commentary.jsp?id=ITP1_6_A">
<div class="button"> 解説 </div>
</a>
</center>
|
p02112 |
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem B: Hating Crowd</h1>
<h2>Problem</h2>
<p>
ããŒãåã¯1幎12ã¶ææ¯æ30æ¥ãŸã§èš360æ¥ã®äžçç·ã§æ®ãããŠããŸãããã®äžçã§ã¯æ¯å¹Žåãæ¥çšã®<var>N</var>åã®é£äŒãäžçäžã®äººã«é©çšãããŠããŸãããé£äŒ<var>i</var>ã¯<var>M<sub>i</sub></var>æ<var>D<sub>i</sub></var>æ¥ããå§ãŸãé£ç¶ãã<var>V<sub>i</sub></var>æ¥éã§ãã
</p>
<p>
ããŒãåã¯NEETãªã®ã§é£äŒã«é¢ä¿ãªãæ¯æ¥äŒã¿ã§ããããæ¥ããŒãåã¯çããåºãããããšæããŸãããã人混ã¿ãå«ããªã®ã§ãé£äŒã®åœ±é¿ã§æ··éããæ¥ã¯ãªãã¹ãå€ã«åºãããããŸãããããã§ãããŒãåã¯ä»¥äžã®æ¹æ³ã§åæ¥ã®æ··é床ãèšç®ããæ··é床ãäžçªå°ããæ¥ãæ¢ãããšããŠããŸãã
</p>
<ul>
<li>ããæ¥ä»<var>x</var>ããé£äŒ<var>i</var>ã«ãã£ãŠåãã圱é¿ã®åºŠåãè¡šãæ°å€ã¯ãæ¥ä»<var>x</var>ãé£äŒ<var>i</var>ã®äžã«å«ãŸããŠããã°<var>S<sub>i</sub></var>ã§ãããããã§ãªããã°ã <var>max</var>( 0, <var>S<sub>i</sub> − min</var> ( <var>x</var>ããé£äŒ<var>i</var>ã®åæ¥ãŸã§ã®æ¥æ° , é£äŒ<var>i</var>ã®æçµæ¥ãã<var>x</var>ãŸã§ã®æ¥æ° ) )ã§ãã</li>
<li>ããæ¥ä»<var>x</var>ã®æ··é床ã¯ã<var>N</var>åã®é£äŒããåãã圱é¿ã®åºŠåã®äžã§ãæã倧ããåãã圱é¿ã®åºŠåãšãªã</li>
</ul>
<p>
1幎ã®äžã§äžçªå°ããæ··é床ãåºåããŠãã ããã ãã ããé£äŒ<var>i</var>ã¯å¹Žãè·šãäºããããŸãããŸããé£äŒã®æ¥çšã¯éè€ããäºããããŸãã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var>
<var>M<sub>1</sub></var> <var>D<sub>1</sub></var> <var>V<sub>1</sub></var> <var>S<sub>1</sub></var>
<var>M<sub>2</sub></var> <var>D<sub>2</sub></var> <var>V<sub>2</sub></var> <var>S<sub>2</sub></var>
...
<var>M<sub>N</sub></var> <var>D<sub>N</sub></var> <var>V<sub>N</sub></var> <var>S<sub>N</sub></var>
</pre>
<p>
1è¡ç®ã«æŽæ°<var>N</var>ãäžããããã<br>
2è¡ç®ãã<var>N</var>+1è¡ç®ã«æŽæ°<var>M<sub>i</sub></var>, <var>D<sub>i</sub></var>, <var>V<sub>i</sub></var>, <var>S<sub>i</sub></var>ã空çœåºåãã§äžãããããïŒ1 ≤ <var>i</var> ≤ <var>N</var>ïŒ
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 100</li>
<li>1 ≤ <var>M<sub>i</sub></var> ≤ 12</li>
<li>1 ≤ <var>D<sub>i</sub></var> ≤ 30</li>
<li>1 ≤ <var>V<sub>i</sub></var>, <var>S<sub>i</sub></var> ≤ 360</li>
</ul>
<h2>Output</h2>
<p>
äžçªå°ããæ··é床ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
1
1 1 359 1
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
2
2 4 25 306
1 9 7 321
</pre>
<h2>Sample Output 2</h2>
<pre>
158
</pre>
<h2>Sample Input 3</h2>
<pre>
8
2 9 297 297
8 6 359 211
8 16 28 288
7 9 113 143
3 18 315 190
10 18 277 300
9 5 276 88
3 5 322 40
</pre>
<h2>Sample Output 3</h2>
<pre>
297
</pre> |
p00085 |
<H1>ãšã»ãã®ãã€ã¢</H1>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_13_1">
</center>
<br/>
<p>æããšã»ãã®ãã€ã¢ãšããã²ãŒã ããããŸããã<var>n</var> 人ãåå ããŠãããšããŸããããåå è
ã¯äžå¿ãåããŠåé£ãçµã¿ã1 ããé çªã«çªå·ãæ¯ãããŸããã¢ãã¢ãã®ãã€ã¢ãã²ãšã€ãåå è
<var>n</var> (å·Šã®å³å
åŽã®å€§ããæ°åã® 30 )ã«æž¡ãããŸãããã€ã¢ãæž¡ãããåå è
ã¯å³é£ã®åå è
ã«ãã®ãã€ã¢ãæž¡ããŸãã <var>m</var> åç®ã«æž¡ããã人ã¯å³é£ã®äººã«æž¡ããŠåé£ããæããŸã(å·Šã®å³ã§ã¯ <var>m</var> = 9 ã®å Žåã衚ããŠããŸã) ã åæž¡ãæ¯ã«äžäººãã€ã¬ããæåŸã«æ®ã£ã人ãåè
ãšãªãããã€ã¢ãããã ããŸãã
</p>
<p>
<var>n</var> ,<var>m</var> ãæ±ºãŸã£ãŠãããå®éã«ãã€ã¢ãæž¡ãå§ããåã«ã©ãã«ãããåãŠããããããšããã§ããããäžã®å³ã¯ 30 人ã®åå è
ã§ 9 人ããšã«æãããšããã«ãŒã«ã§ãã®ã²ãŒã ãããå Žåãæžã衚ããŠããŸããå
åŽã®å€§ããæ°åãåå è
ã«æ¯ãããçªå·ãå€åŽã®å°ããæ°åãæããé çªã§ããããã«ãããšã9,18,27,6,16,26 ãšããé çªã§åé£ããæãåºããæåŸã«ã¯ 21 ãæ®ãããšã«ãªããŸããããªãã¡ 21 ãåè
ãšãªããŸã(å°ããæ°åã 30 ã«ãªã£ãŠããŸã)ã
</p>
<p>
ã²ãŒã åå è
æ° <var>n</var> ãšåé£ããæãåºãåå è
ã®éé <var>m</var> ãå
¥åããåè
ã®çªå·ãåºåããããã°ã©ã ãäœæããŠãã ããããã ãã<var>m</var>, <var>n</var> < 1000 ãšããŸãã
</p>
<H2>å
¥å</H2>
<p>è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã</p>
<pre>
<var>n</var> <var>m</var>
</pre>
<p>
ã²ãŒã åå è
æ° <var>n</var> ïŒæŽæ°ïŒãšåé£ããæãåºãåå è
ã®éé <var>m</var> ïŒæŽæ°ïŒã空çœåºåãã§ïŒè¡ã«äžããããŸãã
</p>
<p>å
¥åã¯ïŒã€ã® 0 ã§çµãããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã</p>
<H2>åºå</H2>
<p>åããŒã¿ã»ããã«å¯ŸããŠãåè
ãšãªããã€ã¢ãããã ã人ã®çªå·ïŒæŽæ°ïŒãïŒè¡ã«åºåããŠãã ããã</P>
<H2>Sample Input</H2>
<pre>
41 3
30 9
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
31
21
</pre>
|
p02542 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a board with <var>N</var> rows and <var>M</var> columns.
The information of this board is represented by <var>N</var> strings <var>S_1,S_2,\ldots,S_N</var>.
Specifically, the state of the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is represented as follows:</p>
<ul>
<li><var>S_{i,j}=</var><code>.</code> : the square is empty.</li>
<li><var>S_{i,j}=</var><code>#</code> : an obstacle is placed on the square.</li>
<li><var>S_{i,j}=</var><code>o</code> : a piece is placed on the square.</li>
</ul>
<p>Yosupo repeats the following operation:</p>
<ul>
<li>Choose a piece and move it to its right adjecent square or its down adjacent square.
Moving a piece to squares with another piece or an obstacle is prohibited.
Moving a piece out of the board is also prohibited.</li>
</ul>
<p>Yosupo wants to perform the operation as many times as possible.
Find the maximum possible number of operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 50</var></li>
<li><var>1 \leq M \leq 50</var></li>
<li><var>S_i</var> is a string of length <var>M</var> consisting of <code>.</code>, <code>#</code> and <code>o</code>.</li>
<li><var>1 \leq (</var> the number of pieces <var>)\leq 100</var>.
In other words, the number of pairs <var>(i, j)</var> that satisfy <var>S_{i,j}=</var><code>o</code> is between <var>1</var> and <var>100</var>, both 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>
<var>S_1</var>
<var>S_2</var>
<var>\vdots</var>
<var>S_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of operations in a line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
o..
...
o.#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Yosupo can perform operations <var>4</var> times as follows:</p>
<pre>o.. .o. ..o ... ...
... -> ... -> ... -> ..o -> ..o
o.# o.# o.# o.# .o#
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9 10
.#....o#..
.#..#..##o
.....#o.##
.###.#o..o
#.#...##.#
..#..#.###
#o.....#..
....###..o
o.......o#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>24
</pre></section>
</div>
</span> |
p02811 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has <var>K</var> <var>500</var>-yen coins. (Yen is the currency of Japan.)
If these coins add up to <var>X</var> yen or more, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq 100</var></li>
<li><var>1 \leq X \leq 10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the coins add up to <var>X</var> yen or more, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 900
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Two <var>500</var>-yen coins add up to <var>1000</var> yen, which is not less than <var>X = 900</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 501
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>One <var>500</var>-yen coin is worth <var>500</var> yen, which is less than <var>X = 501</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>Four <var>500</var>-yen coins add up to <var>2000</var> yen, which is not less than <var>X = 2000</var> yen.</p></section>
</div>
</span> |
p03703 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>, <var>a =</var> {<var>a_1, a_2, âŠ, a_N</var>}, and an integer <var>K</var>.</p>
<p><var>a</var> has <var>N(N+1)/2</var> non-empty contiguous subsequences, {<var>a_l, a_{l+1}, âŠ, a_r</var>} <var>(1 †l †r †N)</var>. Among them, how many have an arithmetic mean that is greater than or equal to <var>K</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 †N †2 \times 10^5</var></li>
<li><var>1 †K †10^9</var></li>
<li><var>1 †a_i †10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>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>:</var>
<var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 6
7
5
7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>All the non-empty contiguous subsequences of <var>a</var> are listed below:</p>
<ul>
<li>{<var>a_1</var>} = {<var>7</var>}</li>
<li>{<var>a_1, a_2</var>} = {<var>7, 5</var>}</li>
<li>{<var>a_1, a_2, a_3</var>} = {<var>7, 5, 7</var>}</li>
<li>{<var>a_2</var>} = {<var>5</var>}</li>
<li>{<var>a_2, a_3</var>} = {<var>5, 7</var>}</li>
<li>{<var>a_3</var>} = {<var>7</var>}</li>
</ul>
<p>Their means are <var>7</var>, <var>6</var>, <var>19/3</var>, <var>5</var>, <var>6</var> and <var>7</var>, respectively, and five among them are <var>6</var> or greater. Note that {<var>a_1</var>} and {<var>a_3</var>} are indistinguishable by the values of their elements, but we count them individually.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 26
10
20
30
40
30
20
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>13
</pre></section>
</div>
</span> |
p00986 | <h2>Parentheses Editor</h2>
<p>
You are working with a strange text editor for texts consisting only of open and close parentheses. The editor accepts the following three keys as editing commands to modify the text kept in it.
</p>
<ul>
<li> â<span>(</span>â appends an open parenthesis (â<span>(</span>â) to the end of the text.</li>
<li> â<span>)</span>â appends a close parenthesis (â<span>)</span>â) to the end of the text.</li>
<li> â<span>-</span>â removes the last character of the text.</li>
</ul>
<p>
A balanced string is one of the following.
</p>
<ul>
<li> â<span>()</span>â</li>
<li> â<span>(</span>$X$<span>)</span>â where $X$ is a balanced string</li>
<li> â$XY$â where both $X$ and $Y$ are balanced strings</li>
</ul>
<p>
Initially, the editor keeps an empty text. You are interested in the number of balanced substrings in the text kept in the editor after each of your key command inputs. Note that, for the same balanced substring occurring twice or more, their occurrences should be counted separately. Also note that, when some balanced substrings are inside a balanced substring, both the inner and outer balanced substrings should be counted.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case given in a line containing a number of characters, each of which is a command key to the editor, that is, either â<span>(</span>â, â<span>)</span>â, or â<span>-</span>â. The number of characters does not exceed 200 000. They represent a key input sequence to the editor.
</p>
<p>
It is guaranteed that no â<span>-</span>â command comes when the text is empty.
</p>
<h3>Output</h3>
<p>
Print the numbers of balanced substrings in the text kept in the editor after each of the key command inputs are applied, each in one line. Thus, the number of output lines should be the same as the number of characters in the input line.
</p>
<h3>Sample Input 1 </h3>
<pre>
(()())---)
</pre>
<h3>Sample Output 1</h3>
<pre>
0
0
1
1
3
4
3
1
1
2
</pre>
<h3>Sample Input 2 </h3>
<pre>
()--()()----)(()()))
</pre>
<h3>Sample Output 2</h3>
<pre>
0
1
0
0
0
1
1
3
1
1
0
0
0
0
0
1
1
3
4
4
</pre>
|
p01694 |
<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>Step Aerobics</u></h3>-->
<!-- end en only -->
<!-- begin ja only -->
<h3><u>èžã¿å°æé</u></h3>
<!-- end ja only -->
<p>JAG倧åŠã«éãäžæš¹åïŒéç§°ã«ãŒåã¯ïŒãã®å€åéã§ããããªãã«èªãããŠïŒICPC (International Collegiate Potchari Contest) ã«åºå Žããããšã«ãªã£ãïŒ
ICPCã¯ïŒã¹ããŒãç³»ã®ã³ã³ãã¹ãã§ããïŒé«åºŠãªéåèœåãå¿
èŠãšãããïŒ
ãããïŒã«ãŒåã¯ãã€ãããœã³ã³ã®åã«ããŠã°ããã§ïŒå°ãåãã ãã§ãç²ããŠããŸãã»ã©ã«éåäžè¶³ã ã£ãïŒ
ããã§ã«ãŒåã¯ïŒICPCã§ããæçžŸãæ®ãããã®ç¬¬1ã¹ããããšããŠïŒæè»œã«å§ããããéåïŒãèžã¿å°æéããå§ããããšã«ããïŒ
</p>
<p>èžã¿å°æéãšã¯ïŒãã®åã®éãïŒèžã¿å°ãšåºãšã®äžãäžãããã ã²ãããç¹°ãè¿ãã ãã®åçŽãªéåã§ããïŒ
ãã ãïŒèžã¿å°æéã§ã¯ïŒæ£ããè¶³ã®æéãè¡ããªããã°ïŒãã®å¹æãåŸãããšã¯ã§ããªãïŒ
æ£ããæéãšã¯ïŒä»¥äžã®2çš®é¡ã®å
ãããããæºããè¶³ã®åãã§ããïŒ
</p>
<ul><li> 䞡足ãåºã«ã€ããç¶æ
ããïŒå·Šè¶³ãšå³è¶³ãèžã¿å°ã®äžã«äžããŠïŒèžã¿å°ã®äžã«äž¡è¶³ãšãã€ããç¶æ
ã«ãªãïŒå·Šè¶³ãšå³è¶³ã©ã¡ããå
ã«äžããŠãããïŒ
</li><li> èžã¿å°ã®äžã«äž¡è¶³ãšãã€ããç¶æ
ããïŒå·Šè¶³ãšå³è¶³ãåºã«äžããŠïŒäž¡è¶³ãåºã«ã€ããç¶æ
ã«ãªãïŒå·Šè¶³ãšå³è¶³ã©ã¡ããå
ã«äžããŠãããïŒ
</li></ul>
<p>以äžãããããããã«ïŒåºãŸãã¯èžã¿å°ã®äžã«ããç¶æ
ããé£ç¶ã§çè¶³ã ããäžãäžãããŠãïŒæ£ããæéãšã¯ãªããªãïŒ
èžã¿å°æééåã§ã¯ïŒäžèšã®æ£ããæéã®åãã®ãããããæºãããšãïŒ1åãšã«ãŠã³ããïŒãã®ã«ãŠã³ãæ°ã倧ãããã°å€§ããã»ã©ïŒå¹æãåŸãããšãã§ããïŒ
åºãšèžã¿å°ãåŸåŸ©ããªããŠãïŒçéã ãã§1åãšã«ãŠã³ãããããšã«æ³šæããŠã»ããïŒ
</p>
<p>ããªãã¯ïŒããŒã ã¡ã€ãã§ããã«ãŒåã«å°ãã§ã匷ããªã£ãŠã»ãããšèããŠããïŒ
ããã§ããªãã¯ïŒã«ãŒåãèžã¿å°æéãããŒã£ãŠããªããïŒããã°ã©ã ãæžããŠãã§ãã¯ããŠãããããšã«ããïŒ
ã«ãŒåãèžã¿å°æéã§åãããè¶³ã®æ
å ±ãäžããããã®ã§ïŒæ£ããæéãè¡ã£ãåæ°ãæ±ããïŒ
ãã ãïŒ<b>䞡足ãšãåºã«ã€ããŠããç¶æ
ããèžã¿å°æéãå§ãã</b>ãã®ãšããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ããããæ§æããïŒ1ã€ã®å
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯150以äžã§ããïŒ
åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ
</p>
<blockquote>$n$<br>$f_1$ $f_2$ ... $f_n$</blockquote>
<p>1è¡ç®ã§ïŒè¶³ãåãããåæ°ãè¡šãæŽæ° $n$ ($1 \le n \le 100$) ãäžããããïŒ
2è¡ç®ã§ïŒè¶³ã®åäœã衚ãæååã§ãã $f_i$ ãæç³»åé ã« $n$ åïŒã¹ããŒã¹åºåãã§äžããããïŒ
$f_i$ ã¯ïŒä»¥äžã®4çš®é¡ã®æååã®å
ããããã§ããïŒ
</p>
<ul><li> "<samp>lu</samp>" : å·Šè¶³ãèžã¿å°ãžäžããïŒ
</li><li> "<samp>ru</samp>" : å³è¶³ãèžã¿å°ãžäžããïŒ
</li><li> "<samp>ld</samp>" : å·Šè¶³ãåºãžäžããïŒ
</li><li> "<samp>rd</samp>" : å³è¶³ãåºãžäžããïŒ
</li></ul>
<p>åºã«ã€ããŠããè¶³ãããã«äžãããããªåäœãïŒèžã¿å°ã«ã€ããŠããè¶³ãããã«äžãããããªåäœã¯å
¥åãããªããšä»®å®ããŠããïŒ
</p>
<p>$n$ ã0ã®è¡ã¯å
¥åã®çµããã衚ãïŒãã®ããŒã¿ã«ã€ããŠã¯åŠçãè¡ã£ãŠã¯ãªããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸããŠïŒ1è¡ã§æ£ããèžã¿å°æéãè¡ã£ãåæ°ãåºåããïŒ
åè¡ã®çµããã«æ¹è¡ãåºåããªãå ŽåãïŒäžå¿
èŠãªæåãåºåããå ŽåïŒèª€çãšå€æãããŠããŸãããæ³šæããããšïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>4
lu ru ld rd
4
lu ld lu ru
1
lu
10
ru lu ld rd ru rd ru lu rd ld
0</pre>
<h3>Output for Sample Input</h3>
<pre>2
1
0
4</pre>
|
p03353 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>s</var>.
Among the <strong>different</strong> substrings of <var>s</var>, print the <var>K</var>-th lexicographically smallest one.</p>
<p>A substring of <var>s</var> is a string obtained by taking out a non-empty contiguous part in <var>s</var>.
For example, if <var>s</var> <var>=</var> <code>ababc</code>, <code>a</code>, <code>bab</code> and <code>ababc</code> are substrings of <var>s</var>, while <code>ac</code>, <code>z</code> and an empty string are not.
Also, we say that substrings are different when they are different as strings.</p>
<p>Let <var>X = x_{1}x_{2}...x_{n}</var> and <var>Y = y_{1}y_{2}...y_{m}</var> be two distinct strings. <var>X</var> is lexicographically larger than <var>Y</var> if and only if <var>Y</var> is a prefix of <var>X</var> or <var>x_{j} > y_{j}</var> where <var>j</var> is the smallest integer such that <var>x_{j} \neq y_{j}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>|s|</var> <var>â€</var> <var>5000</var></li>
<li><var>s</var> consists of lowercase English letters.</li>
<li><var>1</var> <var>â€</var> <var>K</var> <var>â€</var> <var>5</var></li>
<li><var>s</var> has at least <var>K</var> different substrings.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>200</var> points will be awarded as a partial score for passing the test set satisfying <var>|s|</var> <var>â€</var> <var>50</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the <var>K</var>-th lexicographically smallest substring of <var>K</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>aba
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>b
</pre>
<p><var>s</var> has five substrings: <code>a</code>, <code>b</code>, <code>ab</code>, <code>ba</code> and <code>aba</code>.
Among them, we should print the fourth smallest one, <code>b</code>.
Note that we do not count <code>a</code> twice.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>atcoderandatcodeer
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>andat
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>z
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>z
</pre></section>
</div>
</span> |
p01401 |
<h2>
Problem D: äŒèª¬ã®å£
</h2>
<p>
â» ãã®åé¡ã«ã¯åšäºæåãå€ãå«ãŸããŸããèžçŒãã«ã泚æãã ããã
</p>
<p>
ã€ãã«åŸ©æŽ»ãéããéçã¯ãåã³äžçãéã«å
ãããã«äººéçã«æ»ãå
¥ãããšããŠããã
</p>
<p>
éçã¯ãæ¬æ ŒçãªäŸµæ»ãå§ããåã«ããŸãäŒèª¬ã®å£ãç Žå£ããããšã«ããã
ååã®æŠäºã«ãããŠãéçã¯äŒèª¬ã®å£ãæã€åè
ã«ãã£ãŠåãããã
éçã®äœã¯éã®è¡£ã«ãã£ãŠå®ãããŠãããããçåå¯ãªæ»æã§ã¯éçãå·ã€ããããšã¯ã§ããªãã
ããããäŒèª¬ã®å£ã¯ãç¥ã
ã®å è·ã«ãããéçã®éã®è¡£ãã容æã«è²«ããŠããŸãã
ãã®ãããä»åã®æŠäºã«åå©ããããã«ã¯ããªããšããŠããã®äŒèª¬ã®å£ãæã«å
¥ããŠç Žå£ããå¿
èŠãããã
</p>
<p>
調æ»ã®æ«ãäŒèª¬ã®å£ã¯ãšããéºè·¡ã®æå¥¥ã«å®çœ®ãããæ¬¡ä»£ã®åè
ãçŸãããã®ãåŸ
ã£ãŠããããšãããã£ãã
äŒèª¬ã®å£ã¯ãéªæªãªè
ãçè³ã«ãã£ãŠå¥ªãããã®ãé²ãããã«ãåšå²ã«ç¹åšããç¡æ°ã®å®ç ã«ãã£ãŠå°å°ãããŠããã
éçã¯ã匷åãªéåãæã£ãŠãããããè§Šããã ãã§å®ç ãç Žå£ããããšãã§ããã
ãã ããå®ç ã«ããå°å°ã¯å€éæ§é ã«ãªã£ãŠããã衚局ããé ã«ç Žå£ããŠããå¿
èŠãããã
äŸãã°ã第1ã®å°å°ã®å®ç ãç Žå£ããåã«ç¬¬2以éã®å°å°ã®å®ç ã«è§ŠãããšããŠããç Žå£ããããšã¯ã§ããªãã
ãŸããè€æ°ã®å®ç ãåãå°å°ãæ§æããŠããããšãããããéçã¯ãã®ãã¡ã®äžã€ã«è§Šããã ãã§ãåæã«ãã®å°å°ãç Žå£ããããšãã§ããã
</p>
<p>
éºè·¡ã«ã¯ç¥èãªåãæºã¡ãŠããã䞊ã®éç©ã§ã¯å
¥ãããšãããŸãŸãªããªãã
ããã§ãéçèªã赎ãäŒèª¬ã®å£ãååããŠããããšã«ãªã£ãã
ããã«éçãšããã©ãé·æéãã®åãåãç¶ããã°ãã ã§ã¯ããŸãªãã
éçã®å³è
ã§ããããªãã®ä»äºã¯ã念ã®ããéçãå
šãŠã®å°å°ãç Žå£ããäŒèª¬ã®å£ã®äžã«èŸ¿ãã€ããŸã§ã®æéãæ±ããããšã§ããã
</p>
<h2>
Input
</h2>
<p>
å
¥åã¯ãè€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ã¹ããŒã¹ã§åºåããããŒãäºã€ãããªãè¡ã§ããã
ããŒã¿ã»ããã®ç·æ°ã¯50以äžã§ããã
åããŒã¿ã»ããã¯ã次ã®åœ¢åŒãããŠããã
</p>
<pre>
<i>w</i> <i>h</i>
<i>s(1,1)</i> ... <i>s(1,w)</i>
<i>s(2,1)</i> ... <i>s(2,w)</i>
...
<i>s(h,1)</i> ... <i>s(h,w)</i>
</pre>
<p>
<i>w</i>ãš<i>h</i>ã¯ãããããéºè·¡ã®ããã¢ã衚çŸããè¡åããŒã¿ã®å¹
ãšé«ããç€ºãæŽæ°ã§ããããããã<i>1 ≤ w, h ≤ 100</i>ã§ããã<i>2 ≤ w + h ≤ 100</i>ãšä»®å®ããŠè¯ãã
ç¶ã<i>h</i>è¡ã¯ãããããã¹ããŒã¹ã§åºåããã<i>w</i>åã®æåããæ§æãããŠãããæå<i>s(y,x)</i>ã¯ã座æš<i>(y,x)</i>ã®å°ç¹ã®ç¶æ
ã瀺ãã
</p>
<p>
ãã®æå³ã¯ã以äžã®éãã§ããã
<ul>
<li>
SïŒéçãæåã«ããå°ç¹ãããã¢ã«å¿
ã1ã€ã ãååšããã</li>
<li>
GïŒäŒèª¬ã®å£ã®å°ç¹ãå¿
ã1ã€ã ãååšããã</li>
<li>
.ïŒãªã«ããªãã</li>
<li>
æ°åïŒå®ç ãããå°ç¹ãæ°åã¯æ§æããå°å°ã®çªå·ã瀺ããæ°åã¯1以äžã®æŽæ°ã§ãããéã®æ°åã«æãã¯ãªããšããŠããã</li>
</ul>
ãŸããéçã¯ãéºè·¡ã®ããã¢å
ã®äžäžå·Šå³ã®é£æ¥ãã座æšã«ç§»åããããšãã§ãããã®ç§»åã«ãããæéã1ãšããã
ç Žå£ã§ããå®ç ã¯è§Šããã ãã§ç Žå£ã§ãããããå®ç ã®ç Žå£ã«ã¯æéã¯ããããªãã
</p>
<h2>
Output
</h2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠãéçãå
šãŠã®å°å°ãç Žå£ããäŒèª¬ã«å£ã«èŸ¿ãã€ãããã«å¿
èŠãªæçæéãåºåããã
</p>
<h2>
Sample Input
</h2>
<pre>
10 10
S . . . . . . . . .
. . . . . . . . . .
. . . . 1 . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . 3 . .
. . . . . . . . . .
. . . . . 4 . . . .
. . . . . . . . . .
2 . . . . . . . . G
10 10
S . . . . . 3 . . .
. . 3 . . . . . . .
. . . . 1 . . . . .
. . . . . . 4 . . .
. . 3 . . . 1 . . .
. . . . . . . 3 . .
. . . . . . . . . .
. . . . . 4 . . . .
. . . . . 5 . . . .
2 . . . . . . . . G
10 10
S . . . . . . . . 1
. . . . . 5 . . . .
. 4 . . . . . . . .
. . . . 8 . 9 . . .
. . . . 10 . . . . .
. . 7 . G . . . . .
. . . 11 . . . . . .
3 . . . . . . . . 6
. . . . . . . 2 . .
. . . . . . . . . .
0 0
</pre>
<h2>
Output for Sample Input
</h2>
<pre>
38
36
71
</pre>
|
p01051 |
<h1>Squid Ink</h1>
<h2>Problem</h2>
<p>
è¿å¹Žãã€ã«ãã¡ã®éã§ã¯çžåŒµãäºããé »ç¹ã«èµ·ããŠãããè€æ°ã®ã€ã«ãã¡ãããŒã ãçµã¿ãèªãã®ã€ã«ã¹ããæŠåšã«æŠãã®ãè¿å¹Žã®ã€ã«ã®æŠéã¹ã¿ã€ã«ã§ããã
</p>
<p>
çŸåšãçžåŒµãäºããèµ·ãã£ãŠããããã®æŠå Žã¯ <var>R</var>×<var>C</var> ã®ã°ãªããã§è¡šããããçžåŒµãäºãã«åå ããŠããã€ã«ã®ã²ãœå€ªã¯ãã®ã°ãªããäžã®ããå Žæã«ããããã®äºãã§ã¯ãéèŠãªå Žæãæµãããæ©ãå æ ããããšã§æŠæ³ãæå©ã«ããããšãã§ããããã®ãããã²ãœå€ªã¯éèŠãããªå Žæã1ã€æ±ºããããã«ãªãã¹ãæ©ãç§»åããããšèããŠããã
</p>
<p>
ã²ãœå€ªã¯é£æ¥ããäžäžå·Šå³ã®ãã¹ã«ç§»åããããšãã§ãããã°ãªããã®åãã¹ã«ã¯å³æ¹ããŸãã¯æµã®ã€ã«ã¹ããå¡ãããŠããå Žåãããããªã«ãå¡ãããŠããªããã¹ã«ç§»åããå Žåã2ç§ããããã峿¹ã®ã€ã«ã¹ããå¡ãããŠãããã¹ã«ç§»åããå Žåããã®ååã®æé(1ç§)ã§æžããæµã®ã€ã«ã¹ããå¡ãããŠãããã¹ã«ã¯ç§»åããããšãã§ããªããå£ããããã¹ãæŠå Žã®å€ãžã¯åœç¶ç§»åããããšãã§ããªãã
</p>
<p>
ãŸããã²ãœå€ªã¯äžäžå·Šå³ã®ããããã®æ¹åãåããã€ã«ã¹ããåãããšãã§ããããããšãåæ¹ã®3ãã¹ã峿¹ã®ã€ã«ã¹ãã§äžæžããããããã ãéäžã«å£ãããå Žåã¯ãã®æåãŸã§ããã€ã«ã¹ãã¯å±ããªãããã®åäœã«ã¯2ç§ãããã
</p>
<p>
æŠå Žã®æ
å ±ãšã²ãœå€ªã®äœçœ®ãšç®çã®äœçœ®ãäžããããã®ã§ãæçã§äœç§ã§ç§»åã§ãããæ±ããŠã»ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>R</var> <var>C</var>
<var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,C</sub></var>
<var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,C</sub></var>
:
<var>a<sub>R,1</sub></var> <var>a<sub>R,2</sub></var> ... <var>a<sub>R,C</sub></var>
</pre>
<p>
1è¡ç®ã«2ã€ã®æŽæ°<var>R</var>,<var>C</var>ã空çœåºåãã§äžãããããç¶ã<var>R</var>è¡ã«æŠå Žã®æ
å ±ãšããŠ<var>C</var>åã®ãã¹ã®æ
å ±ãäžããããã<var>a<sub>i,j</sub></var>ã¯æŠå Žã®äœçœ®(<var>i</var>,<var>j</var>)ã®ãã¹ã®æ
å ±ã衚ãã以äžã®ããããã®æåã§ããã
</p>
<ul>
<li>'.': ãªã«ãå¡ãããŠããªããã¹</li>
<li>'#': å£</li>
<li>'o': 峿¹ã®ã€ã«ã¹ããå¡ãããŠãããã¹</li>
<li>'x': æµã®ã€ã«ã¹ããå¡ãããŠãããã¹</li>
<li>'S': ã²ãœå€ªã®äœçœ®(å
¥åäžã«1ã€ã ãååšãããã¹ã¯ãªã«ãå¡ãããŠããªã)</li>
<li>'G': ç®çã®äœçœ®(å
¥åäžã«1ã€ã ãååšãããã¹ã¯ãªã«ãå¡ãããŠããªã)</li>
</ul>
<p>
äžããããå
¥åã¯ãç®çã®äœçœ®ãŸã§ç§»åããããšãå¯èœã§ããããšãä¿èšŒãããã
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>R</var>,<var>C</var> ≤ 30</li>
</ul>
<h2>Output</h2>
<p>
ã²ãœå€ªãç®çã®äœçœ®ãŸã§ç§»åããã®ã«ãããæçã®ç§æ°ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5 5
S....
.....
.....
.....
....G
</pre>
<h2>Sample Output 1</h2>
<pre>
14
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5
Sxxxx
xxxxx
xxxxx
xxxxx
xxxxG
</pre>
<h2>Sample Output 2</h2>
<pre>
15
</pre>
<h2>Sample Input 3</h2>
<pre>
4 5
S#...
.#.#.
.#.#.
...#G
</pre>
<h2>Sample Output 3</h2>
<pre>
23
</pre>
<h2>Sample Input 4</h2>
<pre>
4 5
S#ooo
o#o#o
o#o#o
ooo#G
</pre>
<h2>Sample Output 4</h2>
<pre>
14
</pre>
<h2>Sample Input 5</h2>
<pre>
4 5
G####
ooxoo
##x#o
Soooo
</pre>
<h2>Sample Output 5</h2>
<pre>
10
</pre>
|
p03596 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>A</var> slimes lining up in a row.
Initially, the sizes of the slimes are all <var>1</var>.</p>
<p>Snuke can repeatedly perform the following operation.</p>
<ul>
<li>Choose a positive even number <var>M</var>. Then, select <var>M</var> consecutive slimes and form <var>M / 2</var> pairs from those slimes as follows: pair the <var>1</var>-st and <var>2</var>-nd of them from the left, the <var>3</var>-rd and <var>4</var>-th of them, <var>...</var>, the <var>(M-1)</var>-th and <var>M</var>-th of them. Combine each pair of slimes into one larger slime. Here, the size of a combined slime is the sum of the individual slimes before combination. The order of the <var>M / 2</var> combined slimes remain the same as the <var>M / 2</var> pairs of slimes before combination.</li>
</ul>
<p>Snuke wants to get to the situation where there are exactly <var>N</var> slimes, and the size of the <var>i</var>-th (<var>1 †i †N</var>) slime from the left is <var>a_i</var>.
Find the minimum number of operations required to achieve his goal.</p>
<p>Note that <var>A</var> is not directly given as input. Assume <var>A = a_1 + a_2 + ... + a_N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 †a_i †10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required to achieve Snuke's goal.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One way to achieve Snuke's goal is as follows.
Here, the selected slimes are marked in bold.</p>
<ul>
<li>(1, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, 1) â (1, <strong>2</strong>, <strong>2</strong>, 1)</li>
<li>(<strong>1</strong>, <strong>2</strong>, <strong>2</strong>, <strong>1</strong>) â (<strong>3</strong>, <strong>3</strong>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
2 1 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>One way to achieve Snuke's goal is as follows.</p>
<ul>
<li>(<strong>1</strong>, <strong>1</strong>, 1, 1, 1, 1, 1) â (<strong>2</strong>, 1, 1, 1, 1, 1)</li>
<li>(2, 1, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>, <strong>1</strong>) â (2, 1, <strong>2</strong>, <strong>2</strong>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
3 1 4 1 5 9 2 6 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>10
</pre></section>
</div>
</span> |
p00210 |
<H1>ã¶ã»ã¹ã¯ãšã¢ãŒãº</H1>
<p>
ãã®åºŠãæåãªããŒãããŒã¯ã«ã巚倧迷路ã¶ã»ã¹ã¯ãšã¢ãŒãºãæ°ãã宿ããŸããã æ¶é²çœ²ã®æå°ã«ããé¿é£èšç·Žãããªããã°ãªããŸãããã巚倧迷路ãªã ãã«èšç·Žã«ãããæéãäºæž¬ããããšãã§ããŸãããããã§ãããªãã¯ä»¥äžã®ä»æ§ãããšã«é¿é£èšç·Žã·ãã¥ã¬ãŒã¿ãéçºããããšã«ãªããŸããã
</p>
<p>
巚倧迷路ã¯å³ 1 ã«ç€ºãããã«ã暪 <var>W</var> ã瞊 <var>H</var> ã® <var>W × H</var> åã®ãã¹ç®ã§è¡šããããŸããåãã¹ç®ã¯ãéè·¯(çœããã¹ç®)ãå£(è¶è²ããã¹ç®) ãéåžžå£(ç·ã®ãã¹ç®)ã®ããããã§ããå³äžã®âã¯äººã衚ãããã®äžã®è±å°æå(EãWãSãN)ã¯ãã®äººãåããŠããæ¹è§(æ±è¥¿åå)ã衚ããŠããŸããå³ã¯äžæ¹åãåã«ãªãããã«æãããŠããŸãã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_squares">
<p>å³1</p>
</center>
<br/>
<p>
巚倧迷路å
ã«ããäººã¯æåãæ±è¥¿ååã®ããããã®æ¹åãåããŠç«ã£ãŠããŸããå人㯠1 ç§åäœã§åæã«æ¬¡ã«ç€ºãæé ã§ç§»åã詊ã¿ãŸãã
</p>
<ol>
<li>çŸåšåããŠããæ¹åã®ãå³ãåãå·ŠãåŸã®ãã¹ç®ãé çªã«èª¿ã¹ãæåã«èŠã€ããã空ããŠããéè·¯ãŸãã¯éåžžå£ã®æ¹åã«åããå€ããŸãããã®ãããªãã¹ç®ãç¡ãå Žåã¯åããå€ããŸããã</li>
<li> ç®ã®åã®ãã¹ç®ã空ããŠããŠãä»ã®äººã®ç®ã®åã®ãã¹ç®ã«ãªã£ãŠããªãå Žåã¯ç§»åããŸããåããã¹ç®ãç®ã®åã®ãã¹ãšãã人ãè€æ°ããå Žåã¯ããã®ãã¹ç®ã®ãæ±ãåã西ãåã®ãã¹ç®ã«ãã人ã®é ã§éžæããã 1 人ãç§»åããŸãã
</li>
</ol>
<p>
ç§»ååŸã«éåžžå£ã«å°çãã人ã¯ãç¡äºé¿é£ãè¿·è·¯å
ããæ¶ããŸãã
</p>
<p>
äžãããã巚倧迷路ãšäººã®äœçœ®æ
å ±ãå
¥åãšããå
šãŠã®äººãé¿é£ãçµããæéãåºåããããã°ã©ã ãäœæããŠãã ããã è±åºã« 180 ç§ããé·ãæéãèŠããå Žå㯠NA ãšåºåããŠäžããã è¿·è·¯ãšäººã®äœçœ®æ
å ±ã¯ã <var>H</var> è¡ <var>W</var> åã®æåã«ãã£ãŠäžããããŸããåæåã®æå³ã¯ä»¥äžã®ãšããã§ãã
</p>
<p>
<span>#</span> : å£<br>
<span>.</span> : åº<br>
<span>X</span> : éåžžå£<br>
<span>E</span> : æ±ãåããŠãã人<br>
<span>N</span> : åãåããŠãã人<br>
<span>W</span> : 西ãåããŠãã人<br>
<span>S</span> : åãåããŠãã人<br>
</p>
<p>
ãªããè¿·è·¯ãšå€éšãšã®å¢çã¯å£ <span>#</span> ãŸãã¯éåžžå£ <span>X</span> ã®ããããã§ãããŸãã巚倧迷路ã®äžã«ã¯ã人ãå¿
ãïŒäººä»¥äžããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>W</var> <var>H</var>
<var>str<sub>1</sub></var>
<var>str<sub>2</sub></var>
:
<var>str<sub>H</sub></var>
</pre>
<p>
1 è¡ç®ã«è¿·è·¯ã®æšªæ¹åã®å€§ãã <var>W</var>ã瞊æ¹åã®å€§ãã <var>H</var> (1 ≤ <var>W, H</var> ≤ 30) ãäžããããŸããç¶ã <var>H</var> è¡ã«è¿·è·¯ã® <var>i</var> è¡ç®ã衚ãæåå <var>str<sub>i</sub></var> (é·ã <var>W</var>) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãå
šãŠã®äººãé¿é£ãçµããæéãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
8
NA
9
16
10
</pre>
|
p01952 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<H1>
Tiny Room
</H1>
<p>
You are an employee of Automatic Cleaning Machine (ACM) and a member of the development team of Intelligent Circular Perfect Cleaner (ICPC). ICPC is a robot that cleans up the dust of the place which it passed through.
</p>
<p>
Your task is an inspection of ICPC. This inspection is performed by checking whether the center of ICPC reaches all the $N$ given points.
</p>
<p>
However, since the laboratory is small, it may be impossible to place all the points in the laboratory so that the entire body of ICPC is contained in the laboratory during the inspection. The laboratory is a rectangle of $H \times W$ and ICPC is a circle of radius $R$. You decided to write a program to check whether you can place all the points in the laboratory by rotating and/or translating them while maintaining the distance between arbitrary two points.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$N$ $H$ $W$ $R$
$x_1$ $y_1$
:
$x_N$ $y_N$
</pre>
<p>
The first line consists of four integers $N, H, W$ and $R$ ($1 \leq N \leq 100$, $1 \leq H, W \leq 10^9$, $1 \leq R \leq 10^6$). The following $N$ lines represent the coordinates of the points which the center of ICPC must reach. The ($i+1$)-th line consists of two integers $x_i$ and $y_i$ ($0 \leq x_i, y_i \leq 10^9$). $x_i$ and $y_i$ represent the $x$ and $y$ coordinates of the $i$-th point, respectively. It is guaranteed that the answer will not change even if $R$ changes by $1$.
</p>
<H2>Output</H2>
<p>
If all the points can be placed in the laboratory, print '<span>Yes</span>'. Otherwise, print '<span>No</span>'.
</p>
<H2>Sample Input 1</H2>
<pre>
4 20 20 1
10 0
20 10
10 20
0 10
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
Yes
</pre>
<p>
All the points can be placed in the laboratory by rotating them through $45$ degrees.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummer2017_tinyRoom" width="480">
</center>
<H2>Sample Input 2</H2>
<pre>
2 5 55 1
0 0
30 40
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
Yes
</pre>
<H2>Sample Input 3</H2>
<pre>
2 5 49 1
0 0
30 40
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
No
</pre>
<H2>Sample Input 4</H2>
<pre>
1 3 3 1
114 514
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
Yes
</pre>
|
p00640 |
<H1><font color="#000000">Problem D:</font> Distorted Love</H1>
<p>
Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal information. The word "privacy" is not in her dictionary. A person like her is called "stoker" or "<i>yandere</i>", but it doesn't mean much to her.
</p>
<p>
To know about him, she set up spyware to his PC. This spyware can record his mouse operations while he is browsing websites. After a while, she could successfully obtain the record from the spyware in absolute secrecy.
</p>
<p>
Well, we want you to write a program which extracts web pages he visited from the records.
</p>
<p>
All pages have the same size <i>H</i> × <i>W</i> where upper-left corner is (0, 0) and lower right corner is (<i>W</i>, <i>H</i>). A page includes several (or many) rectangular buttons (parallel to the page). Each button has a link to another page, and when a button is clicked the browser leads you to the corresponding page.
</p>
<p>
His browser manages history and the current page in the following way:
</p>
<p>
The browser has a buffer of 1-dimensional array with enough capacity to store pages, and a pointer to indicate a page in the buffer. A page indicated by the pointer is shown on the browser. At first, a predetermined page is stored and the pointer indicates that page. When the link button is clicked, all pages recorded in the right side from the pointer are removed from the buffer. Then, the page indicated by the link button is stored into the right-most position of the buffer, and the pointer moves to right. As a result, the user browse the page indicated by the button.
</p>
<p>
The browser also has special buttons 'back to the previous page' (back button) and 'forward to the next page' (forward button). When the user clicks the back button, the pointer moves to left, and the user clicks the forward button, the pointer moves to right. But in both cases, if there are no such pages in the buffer, nothing happen.
</p>
<p>
The record consists of the following operations:
</p>
<pre>
click x y
</pre>
<p>
It means to click (<i>x</i>, <i>y</i>). If there is a button on the point (<i>x</i>, <i>y</i>), he moved to the corresponding page. If there is nothing in the point, nothing happen. The button is clicked if <i>x</i>1 ≤ <i>x</i> ≤ <i>x</i>2 and <i>y</i>1 ≤ <i>y</i> ≤ <i>y</i>2 where <i>x</i>1, <i>x</i>2 means the leftmost and rightmost coordinate and <i>y</i>1, <i>y</i>2 means the topmost and bottommost coordinate of the corresponding button respectively.
</p>
<pre>
back
</pre>
<p>
It means to click the Back button.
</p>
<pre>
forward
</pre>
<p>
It means to click the Forward button.
</p>
<p>
In addition, there is a special operation <span>show</span>. Your program should print the name of current page for each <span>show</span> operation.
</p>
<p>
By the way, setting spyware into computers of others may conflict with the law. Do not attempt, or you will be reprimanded by great men.
</p>
<H2>Input</H2>
<p>
Input consists of several datasets.
</p>
<p>
Each dataset starts with an integer <i>n</i> which represents the number of pages in the dataset.
</p>
<p>
Next line contains two integers <i>W</i> and <i>H</i>.
</p>
<p>
Next, information of each page are given. Each page starts with a string of characters and <i>b</i>[<i>i</i>], the number of buttons the page has. Following <i>b</i>[<i>i</i>] lines give information of buttons. Each button consists of four integers representing the coordinate (<i>x</i>1, <i>y</i>1) of upper left corner and the coordinate (<i>x</i>2, <i>y</i>2) of lower right corner of the button and a string of characters, which represents the name of page that the link of the button represents.
</p>
<p>
Next, the number of operation <i>m</i> is given. Following <i>m</i> lines represent the record of operations. Please see the above description for the operation.
</p>
<p>
The first page is stored in the buffer at first.
</p>
<p>
Input ends when <i>n</i> = 0.
</p>
<H2>Output</H2>
<p>
For each dataset, output the name of current page for each <span>show</span> operation.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 100</li>
<li><i>b</i>[<i>i</i>] ≤ 100</li>
<li>1 ≤ the number of characters in the name ≤ 20</li>
<li>Buttons are not touch, overlapped nor run over from the browser.</li>
</ul>
<H2>Sample Input</H2>
<pre>
3
800 600
index 1
500 100 700 200 profile
profile 2
100 100 400 200 index
100 400 400 500 link
link 1
100 100 300 200 index
9
click 600 150
show
click 200 450
show
back
back
show
forward
show
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
profile
link
index
profile
</pre>
|
p02387 | <H1>Hello World</H1>
<p>
Welcome to Online Judge!
</p>
<p>
Write a program which prints "Hello World" to standard output.
</p>
<H2>Input</H2>
<p>
There is no input for this problem.
</p>
<H2>Output</H2>
<p>
Print "Hello World" in a line.
</p>
<H2>Sample Input 1</H2>
<pre>
No input
</pre>
<H2>Sample Output 1</H2>
<pre>
Hello World
</pre>
|
p03980 | <span class="lang-en">
<p>Score : <var>150</var> points</p>
<div id="task-statement">
<script src="http://atcoder.jp/js/varmath.js"></script>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>
Gorillas in Kyoto University are good at math.
They are currently trying to solve problems to find the value of an expression that contains two functions, <code>_</code> , <code>^</code>.
Each of these functions takes two input values. <code>_</code> function returns the smaller of the two input values and <code>^</code> function returns the larger.
Gorillas know that integers in the expression are non-negative and less than or equal to <var>99</var>,
but can not find out the length of the expression until they read a terminal symbol <code>?</code> that represents the end of the expression. The number of characters included in each expression is less than or equal to 1000, but they do not even know this fact.
Ai, a smart gorilla, noticed that she may be able to know the value of the expression even if they don't read the whole expression.
</p>
<p>
For example,
</p>
<p>Assume you read the following sentence from the left.</p>
<pre>^(41,3)?</pre>
<p>When you read the sixth character, that is, when you read the following expression,</p>
<pre>^(41,3</pre>
<p>you can tell the second input value of the funcion is whether <var>3</var> or an integer between <var>30</var> and <var>39</var>, and the value turns out <var>41</var>. </p>
<p>
Since Ai wants to solve problems earlier than other gorillas, she decided to solve the problems such that she reads as fewer characters as possible from the left.
For each expression, Find the value of the expression and the minimum number of characters Ai needs to read to know the value.
</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq Q \leq 200</var></li>
<li>The number of characters each expression contains is less than or equal to <var>1000</var>. </li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>The input consists of multiple test cases and is given from Standard Input in the following format:</p>
<pre>
<var>Q</var>
<var>statement_1</var>
...
<var>statement_Q</var>
</pre>
</section>
</div>
</div>
<p>Each <var>statement_i</var> <var>(1 \leq i \leq Q)</var> is given in the following BNF format.</p>
<pre>
<var><statement></var> ::= <var><expression></var> <code>?</code>
<var><expression></var> ::= (<code>^</code> | <code>_</code>) <code>(</code> <var><expression></var> <code>,</code> <var><expression></var> <code>)</code> | <var><number> </var>
<var><number></var> :: = <code>0</code> | <code>1</code> | <code>2</code> | ... | <code>98</code> | <code>99</code>
</pre>
<div class="io-style">
<div class="part">
<section>
<h3>Output</h3>
<p>
Output consists of <var>Q</var> lines.
On line <var>i</var> <var>(1 \leq i \leq Q)</var>, print the value of the expression and the number of character Ai needs to read for the test case <var>i</var> separated by space.
</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
4
_(4,51)?
^(99,_(3,67))?
_(0,87)?
3?
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
4 5
99 4
0 3
3 2
</pre>
<ul>
<li>For the first test case, when you read the fifth character, that is, when you read <code>_(4,5</code>, you will know the value is <var>4</var>. </li>
<li>For the second test case, when you read the fourth character, that is, when you read <code>^(99</code>, you will know the value is <var>99</var>. </li>
<li>For the third test case, when you read the third character, that is, when you read <code>_(0</code>, you will know the value is <var>0</var>. </li>
<li>For the fourth test case, you will not know the value is <var>3</var> untill you read the terminal symbol.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
7
_(23,^(_(22,40),4))?
_(0,99)?
^(99,_(^(19,2),5))?
_(^(43,20),^(30,29))?
^(_(20,3),_(50,41))?
^(_(20,3),_(3,41))?
^(_(20,3),_(4,41))?
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
22 18
0 3
99 4
30 17
41 17
3 14
4 15
</pre>
</section>
</div>
</div>
</span> |
p02692 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a game that involves three variables, denoted <var>A</var>, <var>B</var>, and <var>C</var>.</p>
<p>As the game progresses, there will be <var>N</var> events where you are asked to make a choice.
Each of these choices is represented by a string <var>s_i</var>. If <var>s_i</var> is <code>AB</code>, you must add <var>1</var> to <var>A</var> or <var>B</var> then subtract <var>1</var> from the other; if <var>s_i</var> is <code>AC</code>, you must add <var>1</var> to <var>A</var> or <var>C</var> then subtract <var>1</var> from the other; if <var>s_i</var> is <code>BC</code>, you must add <var>1</var> to <var>B</var> or <var>C</var> then subtract <var>1</var> from the other.</p>
<p>After each choice, none of <var>A</var>, <var>B</var>, and <var>C</var> should be negative.</p>
<p>Determine whether it is possible to make <var>N</var> choices under this condition. If it is possible, also give one such way to make the choices.</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 A,B,C \leq 10^9</var></li>
<li><var>N, A, B, C</var> are integers.</li>
<li><var>s_i</var> is <code>AB</code>, <code>AC</code>, or <code>BC</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>A</var> <var>B</var> <var>C</var>
<var>s_1</var>
<var>s_2</var>
<var>:</var>
<var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to make <var>N</var> choices under the condition, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
<p>Also, in the former case, show one such way to make the choices in the subsequent <var>N</var> lines. The <var>(i+1)</var>-th line should contain the name of the variable (<code>A</code>, <code>B</code>, or <code>C</code>) to which you add <var>1</var> in the <var>i</var>-th choice.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1 3 0
AB
AC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
A
C
</pre>
<p>You can successfully make two choices, as follows:</p>
<ul>
<li>In the first choice, add <var>1</var> to <var>A</var> and subtract <var>1</var> from <var>B</var>. <var>A</var> becomes <var>2</var>, and <var>B</var> becomes <var>2</var>.</li>
<li>In the second choice, add <var>1</var> to <var>C</var> and subtract <var>1</var> from <var>A</var>. <var>C</var> becomes <var>1</var>, and <var>A</var> becomes <var>1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 1 0 0
AB
BC
AB
</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>1 0 9 0
AC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Yes
C
B
B
C
C
B
A
A
</pre></section>
</div>
</span> |
p00355 |
<H1>Reservation System</H1>
<p>
The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap each other.
</p>
<p>
Write a program to report if a new reservation overlaps with any of the existing reservations. Note that the coincidence of start and end times is not considered to constitute an overlap. All the temporal data is given as the elapsed time from the moment at which the L system starts operation.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>a</var> <var>b</var>
<var>N</var>
<var>s_1</var> <var>f_1</var>
<var>s_2</var> <var>f_2</var>
:
<var>s_N</var> <var>f_N</var>
</pre>
<p>
The first line provides new reservation information, i.e., the start time <var>a</var> and end time <var>b</var> (0 ≤ <var>a</var> < <var>b</var> ≤ 1000) in integers. The second line specifies the number of existing reservations <var>N</var> (0 ≤ <var>N</var> ≤ 100). Subsequent <var>N</var> lines provide temporal information for the <var>i</var>-th reservation: start time <var>s_i</var> and end time <var>f_i</var> (0 ≤ <var>s_i</var> < <var>f_i</var> ≤ 1000) in integers. No two existing reservations overlap.
</p>
<h2>Output</h2>
<p>
Output "1" if the new reservation temporally overlaps with any of the existing ones, or "0" otherwise.
</p>
<h2>Sample Input 1</h2>
<pre>
5 7
3
1 4
4 5
7 10
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
3 7
3
7 10
1 4
4 5
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
|
p02368 |
<H1>Strongly Connected Components</H1>
<p>
A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable.
</p>
<H2>Input</H2>
<p>
A directed graph <var>G(V, E)</var> and a sequence of queries where each query contains a pair of nodes <var>u</var> and <var>v</var>.
</p>
<pre>
<var>|V|</var> <var>|E|</var>
<var>s<sub>0</sub></var> <var>t<sub>0</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var>
:
<var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var>
<var>Q</var>
<var>u<sub>0</sub></var> <var>v<sub>0</sub></var>
<var>u<sub>1</sub></var> <var>v<sub>1</sub></var>
:
<var>u<sub>Q-1</sub></var> <var>v<sub>Q-1</sub></var>
</pre>
<p>
<var>|V|</var> is the number of nodes and <var>|E|</var> is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively.
</p>
<p>
<var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target nodes of <var>i</var>-th edge (directed).
</p>
<p>
<var>u<sub>i</sub></var> and <var>v<sub>i</sub></var> represent a pair of nodes given as the <var>i</var>-th query.
</p>
<H2>Output</H2>
<p>
For each query, pinrt "1" if the given nodes belong to the same strongly connected component, "0" otherwise.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <var>|V|</var> ≤ 10,000</li>
<li>0 ≤ <var>|E|</var> ≤ 30,000</li>
<li>1 ≤ <var>Q</var> ≤ 100,000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4
</pre>
<H2>Sample Output 1</H2>
<pre>
1
0
1
1
</pre> |
p01817 |
<h2>I - ãã€ã³ãªããŒã¹</h2>
<p>èŠçŽ æ° <var>N</var> ã®é
å <var>A</var> ãäžããããããã ãã<var>A</var> 㯠<var>(1, 2,</var> ... <var>, N)</var> ã®é åã§ããã</p>
<p>æ¬¡ã®æäœã <var>0</var> åä»¥äž <var>10,000</var> å以äžã®ä»»æã®åæ°è¡ãã<var>A</var> ã <var>(1, 2,</var> ...<var>, N)</var> ãžãœãŒããããã</p>
<ul>
<li>æŽæ° <var>i</var> (<var>1 ≤ i ≤ N</var>) ã <var>1</var> ã€éžã³ãåºé <var>A[1,\ i-1]</var> ã®èŠçŽ ãéé ã«ããåºé <var>A[i+1,\ N]</var> ã®èŠçŽ ãéé ã«ããã</li>
</ul>
<p>ãã ããåºé <var>A[l,\ r]</var> ãšã¯ <var>A</var> ã® <var>l, l+1,</var> ...<var>, r </var> çªç®ã®äœçœ®ã®ããšã§ããã</p>
<p><var>A</var> ã <var>(1, 2,</var> ...<var>, N)</var> ãžãœãŒãã§ãããå€å®ããããœãŒãã§ãããªãã°ãæäœã®äŸãäžã€åºåããã</p>
<h3>Constraints</h3>
<ul>
<li><var>1 ≤ N ≤ 3,000</var></li>
<li><var>A</var> 㯠<var>(1, 2,</var> ... <var>, N)</var> ã®é åã§ããã</li>
</ul>
<h3>Input Format</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
<var>N</var>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
</pre>
<h3>Output Format</h3>
<p><var>A</var> ã <var>(1, 2,</var> ...<var>, N)</var> ãžãœãŒãã§ããªããªãã°ã<code>-1</code> ãšã ãäžè¡ã«åºåããã</p>
<p>ãœãŒãã§ãããªãã°ãæäœã®äŸãäžã€æ¬¡ã®ããã«åºåããã</p>
<ul>
<li><var>1</var> è¡ç®ã«ã¯ãæäœã®åæ°ãè¡šãæŽæ° <var>M</var> (<var>0 ≤ M ≤ 10,000</var>) ãåºåããã</li>
<li><var>2</var> è¡ç®ããã® <var>M</var> è¡ã®ãã¡ <var>k</var> è¡ç®ã«ã¯ã<var>k</var> åç®ã®æäœã§éžã¶æŽæ° <var>i</var> (<var>1 ≤ i ≤ N</var>) ãåºåããã</li>
</ul>
<h3>Sample Input 1</h3>
<pre>
5
5 1 4 2 3
</pre>
<h3>Sample Output 1</h3>
<pre>
2
3
1
</pre>
<p>äŸãã°ã次ã®ããã« <var>2</var> åã®æäœãè¡ãã°ããã</p>
<ul>
<li><var>i=3</var> ãéžã¶ãš <var>(5,\ 1,\ 4,\ 2,\ 3)</var> â <var>(1,\ 5,\ 4,\ 3,\ 2)</var></li>
<li><var>i=1</var> ãéžã¶ãš <var>(1,\ 5,\ 4,\ 3,\ 2)</var> â <var>(1,\ 2,\ 3,\ 4,\ 5)</var></li>
</ul>
<h3>Sample Input 2</h3>
<pre>
2
2 1
</pre>
<h3>Sample Output 2</h3>
<pre>
-1
</pre>
<h3>Sample Input 3</h3>
<pre>
3
1 2 3
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre> |
p00705 |
<H1>
When Can We Meet?
</H1>
<P>
The ICPC committee would like to have its meeting as soon as
possible to address every little issue of the next contest.
However, members of the committee are so busy maniacally developing
(possibly useless) programs that it is very difficult to arrange
their schedules for the meeting.
So, in order to settle the meeting date, the chairperson requested every
member to send back a list of convenient dates by E-mail.
Your mission is to help the chairperson, who is now dedicated to other
issues of the contest, by writing a program that
chooses the best date from the submitted lists.
Your program should find the date convenient for the most members.
If there is more than one such day, the earliest is the best.
</P>
<H2>Input</H2>
<P>
The input has multiple data sets, each starting with a line
containing the number of committee members and the quorum of the meeting.
<BLOCKQUOTE><I>N Q</I></BLOCKQUOTE>
<p>
Here, <I>N</I>, meaning the size of the committee, and <I>Q</I>
meaning the quorum, are positive integers. <I>N</I> is less than 50,
and, of course, <I>Q</I> is less than or equal to <I>N.</I>
</P>
<P>
<I>N</I> lines follow, each describing convenient dates for a
committee
member in the following format.
<BLOCKQUOTE>
<I>M Date</I><SUB>1</SUB>
<I>Date</I><SUB>2</SUB> ... <I>Date<SUB>M</SUB></I>
</BLOCKQUOTE>
<p>
Here, <I>M</I> means the number of convenient dates for
the member, which is an integer greater than or equal to zero.
The remaining items in the line are his/her dates of convenience,
which are positive integers less than 100, that is, 1 means tomorrow,
2 means the day after tomorrow, and so on.
They are in ascending order without any repetition
and separated by a space character.
Lines have neither leading nor trailing spaces.
</P>
<P>
A line containing two zeros indicates the end of the input.
</P>
<H2>Output</H2>
<P>For each data set, print a single line containing the date number
convenient for the largest number of committee members.
If there is more than one
such date, print the earliest. However, if no dates are convenient
for more than or equal to the quorum number of members, print 0 instead.</P>
<H2>Sample Input</H2>
<PRE>
3 2
2 1 4
0
3 3 4 8
3 2
4 1 5 8 9
3 2 5 9
5 2 4 5 7 9
3 3
2 1 4
3 2 5 9
2 2 4
3 3
2 1 2
3 1 2 9
2 2 4
0 0
</PRE>
<H2>Output for the Sample Input</H2>
<PRE>
4
5
0
2
</PRE>
|
p02738 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a positive integer <var>N</var>.
Find the number of permutations <var>(P_1,P_2,\cdots,P_{3N})</var> of <var>(1,2,\cdots,3N)</var> that can be generated through the procedure below.
This number can be enormous, so print it modulo a prime number <var>M</var>.</p>
<ul>
<li>Make <var>N</var> sequences <var>A_1,A_2,\cdots,A_N</var> of length <var>3</var> each, using each of the integers <var>1</var> through <var>3N</var> exactly once.</li>
<li>Let <var>P</var> be an empty sequence, and do the following operation <var>3N</var> times.<ul>
<li>Among the elements that are at the beginning of one of the sequences <var>A_i</var> that is non-empty, let the smallest be <var>x</var>.</li>
<li>Remove <var>x</var> from the sequence, and add <var>x</var> at the end of <var>P</var>.</li>
</ul>
</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2000</var></li>
<li><var>10^8 \leq M \leq 10^9+7</var></li>
<li><var>M</var> is a prime number.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of permutations modulo <var>M</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>All permutations of length <var>3</var> count.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>261
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>314 1000000007
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>182908545
</pre></section>
</div>
</span> |
p03083 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Today, Snuke will eat <var>B</var> pieces of black chocolate and <var>W</var> pieces of white chocolate for an afternoon snack.</p>
<p>He will repeat the following procedure until there is no piece left:</p>
<ul>
<li>Choose black or white with equal probability, and eat a piece of that color if it exists.</li>
</ul>
<p>For each integer <var>i</var> from <var>1</var> to <var>B+W</var> (inclusive), find the probability that the color of the <var>i</var>-th piece to be eaten is black.
It can be shown that these probabilities are rational, and we ask you to print them modulo <var>10^9 + 7</var>, as described in Notes.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>When you print a rational number, first write it as a fraction <var>\frac{y}{x}</var>, where <var>x, y</var> are integers and <var>x</var> is not divisible by <var>10^9 + 7</var>
(under the constraints of the problem, such representation is always possible).
Then, you need to print the only integer <var>z</var> between <var>0</var> and <var>10^9 + 6</var>, inclusive, that satisfies <var>xz \equiv y \pmod{10^9 + 7}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq B,W \leq 10^{5}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>B</var> <var>W</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answers in <var>B+W</var> lines. In the <var>i</var>-th line, print the probability that the color of the <var>i</var>-th piece to be eaten is black, modulo <var>10^{9}+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>500000004
750000006
750000006
</pre>
<ul>
<li>There are three possible orders in which Snuke eats the pieces:<ul>
<li>white, black, black</li>
<li>black, white, black</li>
<li>black, black, white</li>
</ul>
</li>
<li>with probabilities <var>\frac{1}{2}, \frac{1}{4}, \frac{1}{4}</var>, respectively. Thus, the probabilities of eating a black piece first, second and third are <var>\frac{1}{2},\frac{3}{4}</var> and <var>\frac{3}{4}</var>, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>500000004
500000004
625000005
187500002
187500002
</pre>
<ul>
<li>They are <var>\frac{1}{2},\frac{1}{2},\frac{5}{8},\frac{11}{16}</var> and <var>\frac{11}{16}</var>, respectively.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132
</pre></section>
</div>
</span> |
p03579 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Rng has a connected undirected graph with <var>N</var> vertices.
Currently, there are <var>M</var> edges in the graph, and the <var>i</var>-th edge connects Vertices <var>A_i</var> and <var>B_i</var>.</p>
<p>Rng will add new edges to the graph by repeating the following operation:</p>
<ul>
<li>Operation: Choose <var>u</var> and <var>v</var> <var>(u \neq v)</var> such that Vertex <var>v</var> can be reached by traversing exactly three edges from Vertex <var>u</var>, and add an edge connecting Vertices <var>u</var> and <var>v</var>. It is not allowed to add an edge if there is already an edge connecting Vertices <var>u</var> and <var>v</var>.</li>
</ul>
<p>Find the maximum possible number of edges that can be added.</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 M \leq 10^5</var></li>
<li><var>1 \leq A_i,B_i \leq N</var></li>
<li>The graph has no self-loops or multiple edges.</li>
<li>The graph is connected.</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>Find the maximum possible number of edges that can be added.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 5
1 2
2 3
3 4
4 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>If we add edges as shown below, four edges can be added, and no more.</p>
<p><img alt="" src="https://img.atcoder.jp/code-festival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
1 2
2 3
3 1
5 4
5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>Five edges can be added, for example, as follows:</p>
<ul>
<li>Add an edge connecting Vertex <var>5</var> and Vertex <var>3</var>.</li>
<li>Add an edge connecting Vertex <var>5</var> and Vertex <var>2</var>.</li>
<li>Add an edge connecting Vertex <var>4</var> and Vertex <var>1</var>.</li>
<li>Add an edge connecting Vertex <var>4</var> and Vertex <var>2</var>.</li>
<li>Add an edge connecting Vertex <var>4</var> and Vertex <var>3</var>.</li>
</ul></section>
</div>
</span> |
p01544 |
<h1>æé·å¢å ååé¡</h1>
<p>
æã¯éããŠå€ªéåã¯é«æ ¡çã«ãªããŸããã
倧åŠçã ã£ããå
ããã®åœ±é¿ãåããã³ã³ãã¥ãŒã¿ãŒãµã€ãšã³ã¹ã«èå³ãæã¡å§ããŸããã
倪éåã¯ã³ã³ãã¥ãŒã¿ãŒãµã€ãšã³ã¹ã®æç§æžãèªã¿é²ãããæé·å¢å éšåååé¡ããšããæååé¡ãããããšãç¥ããŸããã倪éåã¯ãã®åé¡ã®ããšãçè§£ããŸããããèªåã§ãé¡äŒŒåé¡ãäœããªããã®ããšæ°ã«ãªããŸããã
ããã§å€ªéåã¯è©Šè¡é¯èª€ã®çµæã«æ¬¡ã®ãããªåé¡ãäœããŸããã
</p>
<ul>
<li><var>n</var>åã®æŽæ°ã§æ§æãããæ°åAããã
</li><li><var>m-1</var>åã®åºåããå
¥ããŠãæ°åAã<var>m</var>åã®æ°åã«åè§£ããããªããåè§£åŸã®ããããã®æ°åã¯1ã€ä»¥äžã®æ°ãå¿
ãå«ãŸãªããã°ãªããªãã
</li><li>ãã®<var>m</var>åããããã®æ°åå
ã®æŽæ°ããã¹ãŠè¶³ãåãããçµæåºæ¥äžãã<var>m</var>åã®æ°ããå
ã®æ°åã®é ã«é
眮ãããšå³å¯ãªå¢å åã«ãªã£ãŠãã(ã€ãŸããåºæ¥äžããæ°åã¯<var>B<sub>i</sub> < B<sub>i+1</sub></var>ãã¿ãã)ããã«ãããã
</li><li>ç®æšã¯æçµçã«ã§ããæ°å<var>B</var>ã®é·ã<var>m</var>ãæå€§åããããšã§ããã
</li></ul>
<p>
äŸãã°ãæ°å<var>A</var>ã{5,-4,10,-3,8}ã®å ŽåãèããŠã¿ãã<br>
åºåãã®äœçœ®ãè¡šãæ°å<var>C</var>ãçšæãã<var>C={2,4}</var>ãšããã<br>
ãã®ãšããæ°å<var>A</var>ã¯(5,-4),(10,-3),(8)ã®éšåã«åããããããã®å
éšãè¶³ãåããããšãããã1,7,8ãšãªããåºæ¥äžããæ°å<var>B</var>ã¯{1,7,8}ãšãªãã
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_probG" height="389" width="555">
<p>
倪éåã¯ãã®åé¡ã«ã€ããŠ"æé·å¢å ååé¡"ãšåä»ãããããè§£ãã¢ã«ãŽãªãºã ãèããŸããã<br>
ãããŠç€ŸäŒäººã«ãªã£ãããªãã«ãã§ãã¯ãããŠã»ãããšé£çµ¡ãããŸããã
ããªãã®ä»äºã¯ãæé·ãã倪éåã®äœã£ãåé¡ãè§£ãããã°ã©ã ãäœãããšã§ãã<br>
ãã§ãã¯ããã®ãä»äºãªã®ã§ã<var>m-1</var>åã®åºåãã®äœçœ®ãåºåããŸãã
ãªããæé©ãª<var>m</var>ã«å¯ŸããŠãã®ãããªåºåãæ¹ãè€æ°èããããå ŽåããããŸããããã®<var>m</var>ãæ£ããåºåãããŠããã°ãèãããããã®ã®ãã¡äžã€ãåºåããã°ããã§ãã
</p>
<h2>Input</h2>
<p>
æ¹è¡åºåãã§<var>n+1</var>åã®æŽæ°ãäžããããã
</p>
<blockquote>
<var>n</var> <br><var>A<sub>1</sub></var><br><var>A<sub>2</sub></var><br>...<br><var>A<sub>n</sub></var><br></blockquote>
<ul>
<li><var>n</var>ã¯äžããããæ°å<var>A</var>ã®é·ãã衚ã
</li><li><var>A<sub>i</sub></var>ã¯æ°å<var>A</var>ã®içªç®ã®èŠçŽ ã衚ãã
</li></ul>
<h2>Constraints</h2>
<blockquote>
<var>1≤n≤4000</var><br><var>|Ai|≤ 10<sup>8</sup></var>ã<br></blockquote>
<ul>
<li>æŽæ°<var>k</var>ã«å¯ŸããŠ<var>|k|</var>ã¯<var>k</var>ã®çµ¶å¯Ÿå€ã衚ã
</li></ul>
<h2>Output</h2>
<blockquote>
<var>m</var><br><var>C<sub>1</sub></var> <var>C<sub>2</sub></var> .. <var>C<sub>m-1</sub></var><br></blockquote>
<ul>
<li>1è¡ç®ã¯äžã€ã®æŽæ°<var>m</var>ãåºåããã
<var>m</var>ã¯æçµçã«ã§ããæ°å<var>B</var>ã®é·ãã衚ãã
2è¡ç®ã¯<var>m-1</var>åã®æŽæ°<var>C<sub>i</sub></var>ã空çœåºåãã§åºåããã
<var>C<sub>i</sub></var>ã¯ãæ°å<var>A</var>ã<var>m</var>åã®éšåã«é©åã«åºåã£ãæã®<var>i</var>çªç®ã®åºåãå Žæã衚ãã
åºåãå Žæã®å®çŸ©ã¯å³ãåç
§ããããªãã<var>1≤C<sub>i</sub><n</var> ãæºããã
2è¡ç®ã®<var>m-1</var>åã®æŽæ°åCã¯æé ã«äžŠãã§ããªããã°ãªããªããããã£ãŠã<var>i < j</var> ãªãã°
<var>C<sub>i</sub> < C<sub>j</sub> </var>ãæç«ããã
</li></ul>
<ul>
<li><var>m=1</var>ã®å Žå2è¡ç®ã¯ç©ºè¡ã«ãªãã
</li><li>æ°å<var>C</var>ã«åŸã£ãŠæ°å<var>A</var>ããæ°å<var>B</var>ãçæãããšããæ°å<var>B</var>ãå¢å åã«ãªã£ãŠããªããšã(ããªãã¡<var>B<sub>i</sub>≥B<sub>i+1</sub></var>ãšãªã<var>i(1≤i<m)</var>ãååšãããšã)ãWrongAnswerãšãªã
</li></ul>
<H2>Sample Input 1</H2>
<pre>3
1
2
4
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>3
1 2
</pre>
<p>
ããšããšå¢å åãªã®ã§ããã¹ãŠã®å Žæã«åºåããå
¥ããã°ãã
</p>
<H2>Sample Input 2</H2>
<pre>3
2
2
2
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>2
1
</pre>
<p>
2 2 2ã¯å¢å åã§ãªãã®ã§ã3ã€ã«åå²ããããšã¯ã§ããªã
</p>
<H2>Sample Input 3</H2>
<pre>3
4
2
1
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>1
(空è¡)
</pre>
<p>
ã©ãåå²ããŠãå¢å åã«ã¯ãªããªããããåå²ãããªã
</p> |
p03129 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Determine if we can choose <var>K</var> different integers between <var>1</var> and <var>N</var> (inclusive) so that no two of them differ by <var>1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1\leq N,K\leq 100</var></li>
<li><var>N</var> and <var>K</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If we can choose <var>K</var> integers as above, print <code>YES</code>; otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>We can choose <var>1</var> and <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
</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>31 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 90
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>NO
</pre></section>
</div>
</span> |
p01114 | <h3>Equilateral Triangular Fence</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
Ms. Misumi owns an orchard along a straight road.
Recently, wild boars have been witnessed strolling around the orchard aiming at pears, and she plans to construct a fence around many of the pear trees.
</p>
<p>The orchard contains <i>n</i> pear trees, whose locations are given by the two-dimensional Euclidean coordinates (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>),..., (<i>x<sub>n</sub></i>, <i>y<sub>n</sub></i>). For simplicity, we neglect the thickness of pear trees.
Ms. Misumi's aesthetic tells that the fence has to form a equilateral triangle with one of its edges parallel to the road.
Its opposite apex, of course, should be apart from the road.
The coordinate system for the positions of the pear trees is chosen so that the road is expressed as <i>y</i> = 0, and the pear trees are located at <i>y</i> ≥ 1.
</p>
<p>
Due to budget constraints, Ms. Misumi decided to allow at most <i>k</i> trees to be left outside of the fence.
You are to find the shortest possible perimeter of the fence on this condition.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The following figure shows the first dataset of the Sample Input.
There are four pear trees at (−1,2), (0,1), (1,2), and (2,1).
By excluding (−1,2) from the fence, we obtain the equilateral triangle with perimeter 6.
</p>
<!-- end en only -->
<p style="text-align:center;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_F1"> </p>
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of multiple datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<p>
<i>n</i> <br>
<i>k</i> <br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br>
... <br>
<i>x<sub>n</sub></i> <i>y<sub>n</sub></i> <br>
</p>
</blockquote>
<!-- begin en only -->
<p>
Each of the datasets consists of <i>n</i>+2 lines.
<i>n</i> in the first line is the integer representing the number of pear trees; it satisfies 3 ≤ <i>n</i> ≤ 10 000.
<i>k</i> in the second line is the integer representing the number of pear trees that may be left outside of the fence; it satisfies 1 ≤ <i>k</i> ≤ min(<i>n</i>−2, 5 000).
The following <i>n</i> lines have two integers each representing the <i>x-</i> and <i>y-</i> coordinates, in this order, of the locations of pear trees; it satisfies −10 000 ≤ <i>x<sub>i</sub></i> ≤ 10 000, 1 ≤ <i>y<sub>i</sub></i> ≤ 10 000.
No two pear trees are at the same location, i.e., (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>)=(<i>x<sub>j</sub></i>, <i>y<sub>j</sub></i>) only if <i>i</i>=<i>j</i>.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing a zero.
The number of datasets is at most 100.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single number that represents the shortest possible perimeter of the fence.
The output must not contain an error greater than 10<sup>−6</sup>.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>4
1
0 1
1 2
-1 2
2 1
4
1
1 1
2 2
1 3
1 4
4
1
1 1
2 2
3 1
4 1
4
1
1 2
2 1
3 2
4 2
5
2
0 1
0 2
0 3
0 4
0 5
6
3
0 2
2 2
1 1
0 3
2 3
1 4
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>6.000000000000
6.928203230276
6.000000000000
7.732050807569
6.928203230276
6.000000000000
</pre>
|
p02411 | <H1>Grading</H1>
<p>
Write a program which reads a list of student test scores and evaluates the performance for each student.
</p>
<p>
The test scores for a student include scores of the midterm examination <var>m</var> (out of 50), the final examination <var>f</var> (out of 50) and the makeup examination <var>r</var> (out of 100). If the student does not take the examination, the score is indicated by -1.
</p>
<p>
The final performance of a student is evaluated by the following procedure:
</p>
<ul>
<li>If the student does not take the midterm or final examination, the student's grade shall be F.</li>
<li>If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A.</li>
<li>If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B.</li>
<li>If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C.</li>
<li>If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C.</li>
<li>If the total score of the midterm and final examination is less than 30, the student's grade shall be F.</li>
</ul>
<H2>Input</H2>
<p>
The input consists of multiple datasets. For each dataset, three integers <var>m</var>, <var>f</var> and <var>r</var> are given in a line.
</p>
<p>
The input ends with three -1 for <var>m</var>, <var>f</var> and <var>r</var> respectively. Your program should not process for the terminal symbols.
</p>
<p>
The number of datasets (the number of students) does not exceed 50.
</p>
<H2>Output</H2>
<p>
For each dataset, print the grade (<span>A</span>, <span>B</span>, <span>C</span>, <span>D</span> or <span>F</span>) in a line.
</p>
<H2>Sample Input</H2>
<pre>
40 42 -1
20 30 -1
0 2 -1
-1 -1 -1
</pre>
<H2>Sample Output</H2>
<pre>
A
C
F
</pre>
|
p00586 |
<H1>A + B Problem</H1>
<p>
Compute A + B.
</p>
<H2>Input</H2>
<p>
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
</p>
<H2>Output</H2>
<p>
For each pair of input integers A and B, you must output the sum of A and B in one line.
</p>
<H2>Constraints</H2>
<ul>
<li> -1000 ≤ A, B ≤ 1000</li>
</ul>
<H2>Sample Input</H2>
<pre>
1 2
10 5
100 20
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
15
120
</pre>
<H2>Sample Program</H2>
<table>
<tr>
<td>
<pre>
#include<stdio.h>
int main(){
int a, b;
while( scanf("%d %d", &a, &b) != EOF ){
printf("%d\n", a + b);
}
return 0;
}
</pre>
</td>
<td width=100></td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ab" >
</td>
</tr>
</table>
|
p02041 | <h1>E: LISum</h1>
<h2>åé¡</h2>
<p>
é·ã $N$ ã®æ°å $A$ ãäžããããã
æ°å $A$ ã®æé·å¢å éšååã®ã²ãšã€ã $B$ ãšãããšãã$\sum B_i$ ã®æå€§å€ãæ±ããã
</p>
<p>
æ°å $A$ ã®æé·å¢å éšååãšã¯ããã¹ãŠã® $i < j$ ã§ $A_i < A_j$ ãæºããéšååã®ãã¡ãæé·ãªãã®ã瀺ãã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>å
¥åå€ã¯å
šãп޿°ã§ããã</li>
<li>$1 \leq N \leq 10^5$</li>
<li>$0 \leq A_i \leq 10^5$</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã </p>
<p>
$N$<br>
$A_1 \dots A_N$<br>
</p>
<h2>åºå</h2>
<p>æ°å $A$ ã®æé·å¢å éšååã®ã²ãšã€ã $B$ ãšãããšãã$\sum B_i$ ã®æå€§å€ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã </p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
4
6 4 7 8
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
21
</pre>
<p>æé·å¢å éšåå㯠$ (6, 7, 8)$ ãš $(4, 7, 8)$ ã§ããããã£ãп倧å€ã¯ $21$ ã§ããã</p>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
3
1000 2 3
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
5
</pre>
<p>æé·å¢å éšåå㯠$(2,3)$ ã®ã¿ã§ããã</p>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
7
17 17 13 4 20 12 15
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
31
</pre>
<h3>ãµã³ãã«å
¥å 4</h3>
<pre>
7
19 16 14 9 4 20 2
</pre>
<h3>ãµã³ãã«åºå 4</h3>
<pre>
39
</pre>
|
p03200 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> Reversi pieces arranged in a row. (A <em>Reversi piece</em> is a disc with a black side and a white side.)
The state of each piece is represented by a string <var>S</var> of length <var>N</var>.
If <var>S_i=</var><code>B</code>, the <var>i</var>-th piece from the left is showing black;
If <var>S_i=</var><code>W</code>, the <var>i</var>-th piece from the left is showing white.</p>
<p>Consider performing the following operation:</p>
<ul>
<li>Choose <var>i</var> (<var>1 \leq i < N</var>) such that the <var>i</var>-th piece from the left is showing black and the <var>(i+1)</var>-th piece from the left is showing white, then flip both of those pieces. That is, the <var>i</var>-th piece from the left is now showing white and the <var>(i+1)</var>-th piece from the left is now showing black.</li>
</ul>
<p>Find the maximum possible number of times this operation can be performed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 2\times 10^5</var></li>
<li><var>S_i=</var><code>B</code> or <code>W</code></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible number of times the operation can be performed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>BBW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The operation can be performed twice, as follows:</p>
<ul>
<li>Flip the second and third pieces from the left.</li>
<li>Flip the first and second pieces from the left.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>BWBWBW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre></section>
</div>
</span> |
p01397 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">åé¡ J </font> Mod 3 Knights Out</h1>
<h2>å顿</h2>
<p>
ããæ¥ã®å€æ¹ïŒã³ã³ãã¹ãã®åé¡ãè§£ãçµããäºäººã¯ä»æ¥ã®åé¡ã«ã€ããŠè©±ãåã£ãŠããïŒ<br>
AããããŒïŒãã®ã©ã€ãã¢ãŠãã®åé¡ïŒmod <var>2</var> ãããªã㊠mod <var>3</var> ãšã mod <var>7</var> ãšãã ã£ããè§£æ³åãã£ãã®ã«ãŒïŒã<br>
BããããïŒmod <var>3</var> ã§å¥ã®æ¹æ³ã§è§£ãåé¡ãäœãã°ãããã§ããïŒåãããŸããïŒã<br>
ããããŠæ¬¡ã®ãããªåé¡ãèªçããïŒ</p>
<p></p>
<p><var>H à W</var> ã®ãã§ã¹ç€ãããïŒãã§ã¹ç€ã®åãã¹ã«ã¯ <var>0</var> ãã <var>2</var> ã®æŽæ°ãæžãããŠããïŒãã®ãã§ã¹ç€ã«ãã€ãã眮ããŠããïŒãã ãïŒåãã¹ã«ã¯å€ããŠã <var>1</var> äœã®ãã€ããã眮ããªãïŒåãã¹ã«ã€ããŠïŒ<var>(ãã¹ã®æ°å€+ãããæ»æãããã¹ã«ãããã€ãã®æ°)=0 mod 3</var>ãæãç«ã€ãããªãã€ãã®é
眮ã<b>è¯ã</b>é
眮ãšåŒã¶ïŒæ»æãããã¹ãšã¯ãã®ãã¹ãã瞊æ¹åã« <var>±2</var> ãã¹ãã€æšªæ¹åã« <var>±1</var> ãã¹ïŒãããã¯çžŠæ¹åã« <var>±1</var> ãã¹ãã€æšªæ¹åã« <var>±2</var> ãã¹ããããã¹ã®ããšã§ããïŒ</p>
<p>è¯ããã€ãã®é
çœ®ã®æ°ãæ±ããïŒçãã¯å€§ãããªãå¯èœæ§ãããã®ã§ <var>1,000,000,007</var> ã§å²ã£ãäœããçããïŒ</p>
<h2>å
¥å圢åŒ</h2>
<p>
æåã®è¡ã« <var>H</var> ãš <var>W</var> ãã¹ããŒã¹åºåãã§äžããããïŒ
</p>
<p>
次㮠<var>H</var> è¡ã«ã¯ããã§ã¹ç€ã®ãã¹ç®ã«æžãããŠããæ°å€ãšã㊠<var>W</var> åã® <var>0</var>ïŒ<var>1</var>ïŒ<var>2</var> ã®ããããã®æŽæ°ãã¹ããŒã¹åºåãã§äžããããïŒ
</p>
<h2>åºå圢åŒ</h2>
<p>
è¯ããã€ãã®é
çœ®ã®æ°ã <var>1,000,000,007</var> ã§å²ã£ãäœããåºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ H ≤ 50</var></li>
<li><var>1 ≤ W ≤ 16</var></li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5 5
0 2 0 2 0
2 0 0 0 2
0 0 0 0 0
2 0 0 0 2
0 2 0 2 0
</pre>
<h3>åºåäŸ 1</h3>
<pre>
5
</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
3 3
2 2 2
2 0 2
2 2 2
</pre>
<h3>åºåäŸ 2</h3>
<pre>
8
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
7 7
2 2 2 2 2 2 2
2 1 1 2 1 1 2
2 0 1 0 1 0 2
2 2 0 2 0 2 2
2 0 1 0 1 0 2
2 1 1 2 1 1 2
2 2 2 2 2 2 2
</pre>
<h3>åºåäŸ 3</h3>
<pre>
96
</pre>
<h3>å
¥åäŸ 4</h3>
<pre>
7 3
2 2 2
1 0 1
0 1 0
1 1 1
0 1 0
1 0 1
2 2 2
</pre>
<h3>åºåäŸ 4</h3>
<pre>
8
</pre>
<h3>å
¥åäŸ 5</h3>
<pre>
6 6
0 2 0 1 0 2
2 0 1 2 2 2
0 2 2 0 0 0
2 0 2 0 2 0
0 2 2 1 0 2
0 0 0 2 0 2
</pre>
<h3>åºåäŸ 5</h3>
<pre>
1
</pre>
<h3>å
¥åäŸ 6</h3>
<pre>
16 16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
</pre>
<h3>åºåäŸ 6</h3>
<pre>
1
</pre>
<h2>è¬èŸ</h2>
ãã®åé¡ã¯ Tester ãš Writer ã<a href="http://icpc2010.honiden.nii.ac.jp/regional-contest/problem">ã¢ãžã¢å°åºäºéžã®åé¡</a>ã«é¢ããŠè©±ãåã£ãã®ããã£ãããšããŠäœãããã
|
p03650 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a directed graph with <var>N</var> vertices and <var>N</var> edges. The vertices are numbered <var>1, 2, ..., N</var>.</p>
<p>The graph has the following <var>N</var> edges: <var>(p_1, 1), (p_2, 2), ..., (p_N, N)</var>, and the graph is weakly connected. Here, an edge from Vertex <var>u</var> to Vertex <var>v</var> is denoted by <var>(u, v)</var>, and a weakly connected graph is a graph which would be connected if each edge was bidirectional.</p>
<p>We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, <var>a_i</var> is the value assigned to Vertex <var>i</var>.</p>
<ul>
<li>Each <var>a_i</var> is a non-negative integer.</li>
<li>For each edge <var>(i, j)</var>, <var>a_i \neq a_j</var> holds.</li>
<li>For each <var>i</var> and each integer <var>x(0 †x < a_i)</var>, there exists a vertex <var>j</var> such that the edge <var>(i, j)</var> exists and <var>x = a_j</var> holds.</li>
</ul>
<p>Determine whether there exists such an assignment.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †N †200</var> <var>000</var></li>
<li><var>1 †p_i †N</var></li>
<li><var>p_i \neq i</var></li>
<li>The graph is weakly connected.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> ... <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the assignment is possible, print <code>POSSIBLE</code>; otherwise, print <code>IMPOSSIBLE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 3 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
</pre>
<p>The assignment is possible: {<var>a_i</var>} = {<var>0, 1, 0, 1</var>} or {<var>a_i</var>} <var>=</var> {<var>1, 0, 1, 0</var>}.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>POSSIBLE
</pre>
<p>The assignment is possible: {<var>a_i</var>} <var>=</var> {<var>2, 0, 1, 0</var>}.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6
4 5 6 5 6 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>IMPOSSIBLE
</pre></section>
</div>
</span> |
p02942 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>N</var> rows and <var>M</var> columns of squares.
Each integer from <var>1</var> to <var>NM</var> is written in this grid once.
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 is <var>A_{ij}</var>.</p>
<p>You need to rearrange these numbers as follows:</p>
<ol>
<li>First, for each of the <var>N</var> rows, rearrange the numbers written in it as you like.</li>
<li>Second, for each of the <var>M</var> columns, rearrange the numbers written in it as you like.</li>
<li>Finally, for each of the <var>N</var> rows, rearrange the numbers written in it as you like.</li>
</ol>
<p>After rearranging the numbers, you want 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 to be <var>M\times (i-1)+j</var>.
Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 100</var></li>
<li><var>1 \leq A_{ij} \leq NM</var></li>
<li><var>A_{ij}</var> are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1M}</var>
<var>:</var>
<var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NM}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print one way to rearrange the numbers in the following format:</p>
<pre><var>B_{11}</var> <var>B_{12}</var> <var>...</var> <var>B_{1M}</var>
<var>:</var>
<var>B_{N1}</var> <var>B_{N2}</var> <var>...</var> <var>B_{NM}</var>
<var>C_{11}</var> <var>C_{12}</var> <var>...</var> <var>C_{1M}</var>
<var>:</var>
<var>C_{N1}</var> <var>C_{N2}</var> <var>...</var> <var>C_{NM}</var>
</pre>
<p>Here <var>B_{ij}</var> is 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 after Step <var>1</var>, and <var>C_{ij}</var> is the number written in that square after Step <var>2</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
2 6
4 3
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 6
4 3
5 1
2 1
4 3
5 6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4
1 4 7 10
2 5 8 11
3 6 9 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 4 7 10
5 8 11 2
9 12 3 6
1 4 3 2
5 8 7 6
9 12 11 10
</pre></section>
</div>
</span> |
p01378 |
<div>
<h1 class="title">åé¡ C : [[iwi]]</h1>
<p>ããã ïŒåã®ãã³ãã«ããŒã 㯠(iwi) ã ïŒ
åã¯ç¢ºãã«æã«ããã°ã©ãã³ã°ã³ã³ãã¹ãã«åå ããŠããïŒ
ãããŠïŒå€ãã®ä»²éãšæ¥œããæéãéãããïŒ</p>
<p>確ãïŒä»²éãã¡ã¯å
šå¡ïŒçŸå°å¥³ã ã£ããããªæ°ãããïŒ
ããã°ã©ãã³ã°ã³ã³ãã¹ãã®äžçã¯ïŒåã®ããŒã¬ã ã ã£ããããªæ°ãããïŒ
Gââgle ã¯ïŒåã®ããŒã¬ã ã奪ã£ãã®ã ïŒããã«éããªãïŒ
æã®ä»²éã®æããããã€ããããã«ãïŒãã¯ãããã°ã©ãã³ã°ã³ã³ãã¹ãã«åºãªããã°ãªããªãïŒ</p>
<p>Gââgle Code Jam ã«åå ç»é²ããããšã«ãããïŒ
ä»åºŠã® ID ã«ã¯ïŒäžžæ¬åŒ§ä»¥å€ã®æ¬åŒ§ãæ€èšã«å
¥ããŠã¿ããïŒ</p>
<div>
<h1>åé¡</h1>
<p>'i', 'w', '(', ')', '{', '}', '[', ']' ãããªãæååãäžããããæïŒ
ãã®éšååããšã£ãŠïŒç·å¯Ÿç§°ãªæååãäœãããïŒ
æå€§ã§äœæåã®æååãäœãããšãã§ããããèšç®ããããã°ã©ã ãäœæããïŒ</p>
<p>äžããããæååã¯ïŒ
"iwi" ãšããæååãäžåºŠå«ã¿ïŒãã以å€ã®éšåã«ã¯ 'i' ãš 'w' ãå«ãŸãªãïŒ
ãã圢åŒçã«ã¯ïŒäžããããæåå㯠<span style="font-size:110%;font-family:times new roman;"><i>s</i></span> "iwi" <span style="font-size:110%;font-family:times new roman;"><i>t</i></span>
ïŒ<span style="font-size:110%;font-family:times new roman;"><i>s</i></span> ãš "iwi" ãš <span style="font-size:110%;font-family:times new roman;"><i>t</i></span> ãé£çµãããã®ïŒãšãã圢ã§è¡šãããšãã§ãïŒ
<span style="font-size:110%;font-family:times new roman;"><i>s</i></span> ãš <span style="font-size:110%;font-family:times new roman;"><i>t</i></span> 㯠'(', ')', '{', '}', '[', ']' ãããªãæååã§ããïŒ
<span style="font-size:110%;font-family:times new roman;"><i>s</i></span> ã <span style="font-size:110%;font-family:times new roman;"><i>t</i></span> ã 0 æåã§ããå¯èœæ§ãããïŒ</p>
<p>äœãæååã¯ïŒäžããããæååã®éšååããšã£ãŠäœãïŒ
éšååãšã¯ïŒå
ã®æååããããã€ãã®æåãåãåºãïŒããããïŒ
å
ã®æååã«å«ãŸããé çªã§ç¹ãããã®ã§ããïŒ
åãåºãæåãã¡ã¯å¿
ãããå
ã®æååã§é£ç¶ããŠããªããŠãè¯ãïŒ</p>
<p>ãŸãïŒäœãæååãïŒäžããããæååãšåæ§ã«ïŒ"iwi" ãšããæååãäžåºŠå«ã¿ïŒ
ãã以å€ã®éšåã«ã¯ 'i' ãš 'w' ã¯å«ãŸãªãããã«ãããïŒ</p>
<p>ããã§çšããå·Šå³ã«ç·å¯Ÿç§°ã®å®çŸ©ã¯ïŒä»¥äžãšããïŒ</p>
<ol class="arabic simple">
<li>以äžã®æååã¯å·Šå³ã«ç·å¯Ÿç§°ïŒ</li>
</ol>
<blockquote>
<ul class="simple">
<li>空æåå</li>
<li>"i"</li>
<li>"w"</li>
</ul>
</blockquote>
<ol class="arabic simple" start="2">
<li>æåå <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> ãå·Šå³ã«ç·å¯Ÿç§°ã®ãšãïŒä»¥äžã®æååãå·Šå³ã«ç·å¯Ÿç§°ïŒ</li>
</ol>
<blockquote>
<ul class="simple">
<li>"i" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "i"</li>
<li>"w" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "w"</li>
<li>"(" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> ")"</li>
<li>")" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "("</li>
<li>"{" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "}"</li>
<li>"}" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "{"</li>
<li>"[" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "]"</li>
<li>"]" <span style="font-size:110%;font-family:times new roman;"><i>x</i></span> "["</li>
</ul>
</blockquote>
<ol class="arabic simple" start="3">
<li>以äžã®ãã®ã®ã¿ãå·Šå³ã«ç·å¯Ÿç§°ïŒ</li>
</ol>
</div>
<div>
<h1>å
¥å</h1>
<p>å
¥å㯠'i', 'w', '(', ')', '{', '}', '[', ']' ãããªãäžèšã®æ¡ä»¶ãæºããæååã§ããïŒ</p>
</div>
<div>
<h1>åºå</h1>
<p>äžèšã®æ¡ä»¶ãæºããäœãããšã®ã§ããæååã®é·ãã®æå€§å€ãåºåããïŒ</p>
</div>
<div>
<h1>å¶çŽ</h1>
<ul class="simple">
<li>å
¥åã®æååã®é·ã㯠15 以äžã§ããïŒ</li>
</ul>
</div>
<div>
<h1>å
¥åºåäŸ</h1>
<div>
<h2>å
¥åºåäŸ 1</h2>
<p>å
¥åäŸ 1:</p>
<pre class="literal-block">
[[[iwi[[[
</pre>
<p>å
¥åäŸ 1 ã«å¯ŸããåºåäŸ:</p>
<pre class="literal-block">
3
</pre>
<p>"iwi" ãšããæååããäœãããšãã§ããªãïŒ</p>
</div>
<div>
<h2>å
¥åºåäŸ 2</h2>
<p>å
¥åäŸ 2:</p>
<pre class="literal-block">
[{)iwi(]}
</pre>
<p>å
¥åäŸ 2 ã«å¯ŸããåºåäŸ:</p>
<pre class="literal-block">
7
</pre>
<p>"[)iwi(]" ã "{)iwi(}" ãªã© 7 æåã®æååãäœãããšãã§ããïŒ</p>
</div>
</div>
</div> |
p03345 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi, Nakahashi and Hikuhashi have integers <var>A</var>, <var>B</var> and <var>C</var>, respectively.
After repeating the following operation <var>K</var> times, find the integer Takahashi will get minus the integer Nakahashi will get:</p>
<ul>
<li>Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.</li>
</ul>
<p>However, if the absolute value of the answer exceeds <var>10^{18}</var>, print <code>Unfair</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A,B,C \leq 10^9</var></li>
<li><var>0 \leq K \leq 10^{18}</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation <var>K</var> times.
If the absolute value of the answer exceeds <var>10^{18}</var>, print <code>Unfair</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>After one operation, Takahashi, Nakahashi and Hikuhashi have <var>5</var>, <var>4</var> and <var>3</var>, respectively. We should print <var>5-4=1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 2 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>1000000000 1000000000 1000000000 1000000000000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p01682 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h3>Problem Statement</h3>
<p>Dr. Suposupo developed a programming language called Shipura. Shipura supports only one binary operator ${\tt >>}$ and only one unary function ${\tt S<\ >}$.
</p>
<p>$x {\tt >>} y$ is evaluated to $\lfloor x / 2^y \rfloor$ (that is, the greatest integer not exceeding $x / 2^y$), and ${\tt S<} x {\tt >}$ is evaluated to $x^2 \bmod 1{,}000{,}000{,}007$ (that is, the remainder when $x^2$ is divided by $1{,}000{,}000{,}007$).
</p>
<p>The operator ${\tt >>}$ is left-associative. For example, the expression $x {\tt >>} y {\tt >>} z$ is interpreted as $(x {\tt >>} y) {\tt >>} z$, not as $x {\tt >>} (y {\tt >>} z)$. Note that these parentheses do not appear in actual Shipura expressions.
</p>
<p>The syntax of Shipura is given (in BNF; Backus-Naur Form) as follows:
</p><pre>expr ::= term | expr sp ">>" sp term
term ::= number | "S" sp "<" sp expr sp ">"
sp ::= "" | sp " "
number ::= digit | number digit
digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"</pre>
<p>The start symbol of this syntax is $\tt expr$ that represents an expression in Shipura. In addition, $\tt number$ is an integer between $0$ and $1{,}000{,}000{,}000$ inclusive, written without extra leading zeros.
</p>
<p>Write a program to evaluate Shipura expressions.
</p>
<h3>Input</h3>
<p>The input is a sequence of datasets. Each dataset is represented by a line which contains a valid expression in Shipura.
</p>
<p>A line containing a single ${\tt \#}$ indicates the end of the input. You can assume the number of datasets is at most $100$ and the total size of the input file does not exceed $2{,}000{,}000$ bytes.
</p>
<h3>Output</h3>
<p>For each dataset, output a line containing the evaluated value of the expression.
</p>
<h3>Sample Input</h3>
<pre>S< S< 12 >> 2 > >
123 >> 1 >> 1
1000000000 >>129
S<S<S<S<S<2>>>>>
S <S< S<2013 >>> 11 >>> 10 >
#</pre>
<h3>Output for the Sample Input</h3>
<pre>81
30
0
294967268
14592400</pre> |
p00990 |
<h1>Problem A : ID</h1>
<p>
A倧åŠã§ã¯IDã®å
¥åãã¹ãå€çºããŠããã<br>
ããã§ãA倧åŠã¯å
¥åãã¹é²æ¢ã®ããæ°ããIDãçºè¡ããããšã«ããã<br>
æ°ããIDã«ã¯å
¥åãã¹é²æ¢ã®ããã«IDãæ£ãããã©ãããã§ãã¯ããæ¹æ³ãããã<br>
</p>
<p>
<br>
ã»å
šãŠã®æ¡ã®æ°åã®ç·åãæ±ããã<br>
ã»ãã ããå³ç«¯ã®æ¡ãïŒçªç®ãšããŠãå¶æ°çªç®ã®æ¡ã®æ°åãïŒåã«ããã<br>
ã»ïŒåããããšã«ãã£ãŠæ°åãïŒïŒä»¥äžã«ãªã£ãæãïŒã®äœã®æ°åãšïŒïŒã®äœã®æ°åãå ç®ããæ°åããã®æ¡ã®æ°åãšããã<br>
ã»ç·åãïŒïŒã§å²ãåããã°æ£ããIDãããã§ãªããã°ééããšããã<br>
<br>
</p>
<p>
äŸãšããŠã53579ãšããIDããã§ãã¯ããã<br>
å
šãŠã®æ¡ã®æ°åã®ç·åãæ±ããã®ã§ã<br>
5 + 3 + 5 + 7 + 9<br>
</p>
<p>
ãã ããå¶æ°çªç®ã®æ¡ã®æ°åãïŒåã«ããã®ã§ã<br>
5 + <u>6</u> + 5 + <u>14</u> + 9<br>
</p>
<p>
ïŒåããããšã«ãã£ãŠæ°åãïŒïŒä»¥äžã«ãªã£ãæãïŒã®äœã®æ°åãšïŒïŒã®äœã®æ°åãå ç®ããæ°åããã®æ¡ã®æ°åãšããã®ã§ã<br>
5 + 6 + 5 + <u>(1 + 4)</u> + 9<br>
</p>
<p>
以äžãããç·åã¯30ãšãªãã30ã¯10ã§å²ãåããã®ã§ã53579ã¯æ£ããIDã§ããã<br>
</p>
<p>
Båã¯A倧åŠã®å€§åŠçã§ãããæ°ããIDãçºè¡ããŠããã£ãããIDã®äžéšã®æ¡ãå¿ããŠããŸã£ãã<br>
ããããå¿ããŠããŸã£ãéšåã«ã©ããªæ°åãå
¥ãããããã€ãåè£ãçµãããšã«æåããã<br>
ããªãã®ä»äºã¯ãBåã®IDã®æ£ããçµã¿åãããäœéãããããæ±ããããšã§ããã<br>
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>n</i>
<i>ID</i>
<i>m</i>
<i>a<sub>0</sub> a<sub>1</sub> ... a<sub>m-1</sub></i>
</pre>
<p>
<i>n</i>ã¯<i>ID</i>ã®æ¡ã®æ°ã§ããã<br>
<i>ID</i>ã®åæ¡ã«ã¯0~9ã®æ°åãŸãã¯å¿ããæ¡ã§ãããšããããšã瀺ã'*'ãšããæåãå
¥ãã<br>
<i>m</i>ã¯'*'ã«å
¥ãæ°åã®åè£ã®æ°ã§ããã<br>
<i>a<sub>i</sub></i>ã¯'*'ã«å
¥ãæ°åã®åè£ã§ããã<br>
</p>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºãã<br>
1 ≤ <i>n</i> ≤ 100,000<br>
1 ≤ <i>m</i> ≤ 10<br>
0 ≤ <i>a<sub>i</sub></i> ≤ 9<br>
1 ≤ '*'ã®æ° ≤ 7<br>
</p>
<h2>Output</h2>
<p>
çãã®å€ãïŒè¡ã«åºåãã
</p>
<h2>Sample Input 1</h2>
<pre>
5
5*57*
2
3 9
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
15
2***9*2*6*1199*
9
0 1 2 3 4 6 7 8 9
</pre>
<h2>Sample Output 2</h2>
<pre>
478297
</pre>
|
p01728 |
<p>
ããªãªã³ã¯äºæ¬¡å
å¹³é¢äžã«ãããé·ã<var>2L</var>ã®ç·åã®åœ¢ç¶ãããŠããã<br>
ããªãªã³ã®ãŸããã«ã¯ãç·åã®åœ¢ç¶ãããããã€ãã®é害ç©ãååšããŠããã
</p>
<p>ããªãªã³ã¯é害ç©ã«æ¥ãããšäœåãåãããŠããŸãã<br>
å®ç§äž»çŸ©ã®ããªãªã³ã¯ç¡å·ã§ãŽãŒã«ããããšã«ããã
</p>
<p>ããªãªã³ã¯ä»¥äžã®è¡åãã§ããã
</p>
<ul>
<li> å¹³è¡ç§»å
</li>
<li> ããªãªã³ã衚ãç·åã®äžç¹ãäžå¿ãšããŠãåæèšåšãã«ã¡ããã© <var> 180 / r </var> 床ã ãå転ãã
</li></ul>
<p>ãã ããäºæ¬¡å
å¹³é¢ã¯äžæ¹åã«<var>y</var>軞ããšãã
</p>
<p>ããªãªã³ã®ãŸããã«ã2 ç¹ S, G ãããã<br>
å§ãã¯ããªãªã³ã®äžå¿ã¯ç¹ S ã«ãã£ãŠã<var>x</var>軞ã«å¹³è¡ãªç¶æ
ã«ãªã£ãŠããã
</p>
<p>ããªãªã³ã¯ãå¹³è¡ç§»åããã®ã¯åŸæã ããå転ããã®ã¯äžåŸæã§ããã<br>
ããªãã®ä»äºã¯ãããªãªã³ãäžå¿ãç¹ S ããç¹ G ãŸã§ç§»åããããŸã§ã«å¿
èŠãªãæå°ã®å転è¡åã®åæ°ãæ±ããããšã§ããã<br>
ç§»åãããããšãã§ããªãå Žåã¯ããã®ããšãæ€åºããã
</p>
<p>
ãã ãã以äžã®ããšã«æ³šæããã
</p>
<ul><li> ããªãªã³ã¯ç§»åããªããå転ããããšã¯ã§ããªãã
</li><li> ããªãªã³ãå転ããéäžã§é害ç©ã«ã¶ã€ããããå Žåã¯ãå転ããããšã¯ã§ããªãã
</li><li> é害ç©ãäºãã«äº€å·®ããŠããããšã¯ããåŸãã
</li><li> ç·åã¯ååå°ããæéã®å€ªããæã€ãã®ãšããŠæ±ããæåŸã®ãµã³ãã«ãèŠãã
</ul>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>L</var> <var>r</var><br><var>s<sub>x</sub></var> <var>s<sub>y</sub></var><br><var>g<sub>x</sub></var> <var>g<sub>y</sub></var><br><var>n</var><br><var>x<sub>11</sub></var> <var>y<sub>11</sub></var> <var>x<sub>12</sub></var> <var>y<sub>12</sub></var><br>...<br><var>x<sub>n1</sub></var> <var>y<sub>n1</sub></var> <var>x<sub>n2</sub></var> <var>y<sub>n2</sub></var></pre>
<p><var>L</var>ã¯ããªãªã³ã®ååã®é·ãã衚ãã
<var>r</var>ã¯å転è§åºŠãå®ãããã®ã§ããã
<var>(s<sub>x</sub>, s<sub>y</sub>)</var>ã¯ç¹ Sã<var>(g<sub>x</sub>, g<sub>y</sub>)</var>ã¯ç¹ G ã®åº§æšã§ããã
<var>n</var>ã¯é害ç©ã®æ°ã衚ãã
<var>(x<sub>i1</sub>, y<sub>i1</sub>)</var>ãš<var>(x<sub>i2</sub>, y<sub>i2</sub>)</var>ã¯<var>i</var>çªç®ã®é害ç©ã衚ãç·åã®ç«¯ç¹ã§ããã
</p>
<h3>Constraints</h3>
<p>å
¥åã¯ä»¥äžã®å¶çŽãæºããã
</p>
<ul><li> <var> 1 ≤ n ≤ 30 </var>
</li><li> <var> 2≤ r ≤ 11 </var>
</li><li> <var> 1 ≤ L ≤ 10<sup>5</sup> </var>
</li><li> å
¥åã«å«ãŸãã座æšã®åæåã¯çµ¶å¯Ÿå€ã<var>10<sup>5</sup></var>以äž
</li><li> å
¥åã«å«ãŸããæ°å€ã¯ãã¹ãп޿°
</li><li> <var>i = 1, . . . , n</var>ã«ã€ããŠ<var> (x<sub>i1</sub>, y<sub>i1</sub>) ≠ (x<sub>i2</sub>, y<sub>i2</sub>) </var>
</li><li> ããªãªã³ãã¹ã¿ãŒãå°ç¹ã«xè»žã«æ°Žå¹³ãªç¶æ
ã§é
眮ãããšããé害ç©ãšã®ïŒç·åãšç·åãšã®ïŒè·é¢ã¯<var> 10<sup>−3</sup> </var>ãã倧ãã
</li><li> é害ç©ã衚ãç·åã®ç«¯ç¹ããäž¡æ¹åã«<var> 10<sup>−3</sup> </var>ã ãå»¶ã°ããŠãçž®ããŠãè§£ã¯å€ãããªã
</li><li> <var>L</var>ã <var> 10<sup>−3</sup> </var>ã ã墿žãããŠãè§£ã¯å€ãããªã
</li><li> é害ç©ã®ç·åã<var>l<sub>i</sub></var>ãšæžãããšã«ãããšã<var>1 ≤ i ≤ j ≤ n</var>ã§ãã£ãŠã<var>l<sub>i</sub></var>ãš<var>l<sub>j</sub></var>ã®è·é¢ã<var>2L</var>以äžã§ãããããªçµ<var>(i, j)</var>ã¯é«ã
100å
</li><li> ãŽãŒã«å°ç¹ã¯é害ç©ã«ä¹ã£ãŠããããšã¯ãªã
</li></ul>
<h2>Output</h2>
<p>ã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§ç§»åããããã«å¿
èŠãªæå°ã®å転è¡åã®åæ°ã1è¡ã«åºåããã
ç§»åãããããšãã§ããªãå Žåã¯ã-1ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>1 2
3 3
2 -1
4
1 0 1 5
0 1 4 1
0 4 6 4
5 0 5 5
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
</pre>
<ul><li> ããªãªã³ã90床å転ãããããšã§ãééãæããããšãã§ããã
</li></ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample1" height="600" width="600"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_a" height="100" width="700"><br>
<br>
<h2>Sample Input 2</h2>
<pre>1 2
3 3
2 -1
4
1 0 1 5
0 1 6 1
0 4 6 4
5 0 5 5
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>-1
</pre>
<ul><li> ããªãªã³ã¯å®å
šã«å²ãŸããŠããã®ã§ããŽãŒã«ãŸã§ç§»åããããšãã§ããªãã
</li></ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample2" height="600" width="600"><br>
<h2>Sample Input 3</h2>
<pre>1 4
3 3
7 0
5
1 0 1 5
0 1 6 1
0 4 6 4
8 0 2 5
6 0 4 2
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>3
</pre>
<ul><li> æãã®çµè·¯ãéãããã«ã¯ã3ååæèšåšãã«å転ããªããã°ãªããªãã
</li></ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample3" height="600" width="600"><br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_b" height="100" width="700"><br>
<br>
<h2>Sample Input 4</h2>
<pre>2 2
4 2
4 5
5
1 5 2 0
0 4 3 4
0 1 8 1
7 0 7 5
8 4 5 4
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>-1
</pre>
<ul><li> ããªãªã³ã¯é害ç©ã«ãŽã£ããæ¥ããããšãã§ããªãã®ã§ãééã®ãšããã§å転ããŠãŽãŒã«ãŸã§ç§»åããããšã¯ã§ããªãã
</li></ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_KuruKuruKururin_sample4" height="370" width="567">
|
p03715 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a bar of chocolate with a height of <var>H</var> blocks and a width of <var>W</var> blocks.
Snuke is dividing this bar into exactly three pieces.
He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.</p>
<p>Snuke is trying to divide the bar as evenly as possible.
More specifically, he is trying to minimize <var>S_{max}</var> - <var>S_{min}</var>, where <var>S_{max}</var> is the area (the number of blocks contained) of the largest piece, and <var>S_{min}</var> is the area of the smallest piece.
Find the minimum possible value of <var>S_{max} - S_{min}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †H, W †10^5</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value of <var>S_{max} - S_{min}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>In the division below, <var>S_{max} - S_{min} = 5 - 5 = 0</var>.</p>
<div style="text-align: center;">
<img alt="2a9b2ef47b750c0b7ba3e865d4fb4203.png" src="https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>In the division below, <var>S_{max} - S_{min} = 8 - 6 = 2</var>.</p>
<div style="text-align: center;">
<img alt="a42aae7aaaadc4640ac5cdf88684d913.png" src="https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>In the division below, <var>S_{max} - S_{min} = 10 - 6 = 4</var>.</p>
<div style="text-align: center;">
<img alt="eb0ad0cb3185b7ae418e21c472ff7f26.png" src="https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>100000 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>50000
</pre></section>
</div>
</span> |
p02807 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>There are <var>N</var> slimes standing on a number line.
The <var>i</var>-th slime from the left is at position <var>x_i</var>.</p>
<p>It is guaruanteed that <var>1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}</var>.</p>
<p>Niwango will perform <var>N-1</var> operations. The <var>i</var>-th operation consists of the following procedures:</p>
<ul>
<li>Choose an integer <var>k</var> between <var>1</var> and <var>N-i</var> (inclusive) with equal probability.</li>
<li>Move the <var>k</var>-th slime from the left, to the position of the neighboring slime to the right.</li>
<li>Fuse the two slimes at the same position into one slime.</li>
</ul>
<p>Find the total distance traveled by the slimes multiplied by <var>(N-1)!</var> (we can show that this value is an integer), modulo <var>(10^{9}+7)</var>. If a slime is born by a fuse and that slime moves, we count it as just one slime.</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 x_1 < x_2 < \ldots < x_N \leq 10^{9}</var></li>
<li><var>x_i</var> is an integer.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Subtasks</h3>
<ul>
<li><var>400</var> points will be awarded for passing the test cases satisfying <var>N \leq 2000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>x_2</var> <var>\ldots</var> <var>x_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<ul>
<li>With probability <var>\frac{1}{2}</var>, the leftmost slime is chosen in the first operation, in which case the total distance traveled is <var>2</var>.</li>
<li>With probability <var>\frac{1}{2}</var>, the middle slime is chosen in the first operation, in which case the total distance traveled is <var>3</var>.</li>
<li>The answer is the expected total distance traveled, <var>2.5</var>, multiplied by <var>2!</var>, which is <var>5</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>12
161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>750927044
</pre>
<ul>
<li>Find the expected value multiplied by <var>(N-1)!</var>, modulo <var>(10^9+7)</var>.</li>
</ul></section>
</div>
</span> |
p02554 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>How many integer sequences <var>A_1,A_2,\ldots,A_N</var> of length <var>N</var> satisfy all of the following conditions?</p>
<ul>
<li><var>0 \leq A_i \leq 9</var></li>
<li>There exists some <var>i</var> such that <var>A_i=0</var> holds.</li>
<li>There exists some <var>i</var> such that <var>A_i=9</var> holds.</li>
</ul>
<p>The answer can be very large, so output it modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^6</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Two sequences <var>\{0,9\}</var> and <var>\{9,0\}</var> satisfy all conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>869121
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2511445
</pre></section>
</div>
</span> |
p00569 | <h1>Lçªç®ã®Kçªç®ã®æ° (LthKthNumber)</h1>
<h2>å顿</h2>
<p>
暪äžåã«äžŠã¹ããã <var>N</var> æã®ã«ãŒããããïŒå·Šãã <var>i</var> æç®(<var>1 ⊠i ⊠N</var>)ã®ã«ãŒãã«ã¯ïŒæŽæ° <var>a_i</var> ãæžãããŠããïŒ</p>
<p>
JOI åã¯ïŒãããã®ã«ãŒããçšããŠæ¬¡ã®ãããªã²ãŒã ãè¡ãïŒé£ç¶ãã <var>K</var> æä»¥äžã®ã«ãŒãã®åãéžã³ïŒæ¬¡ã®æäœãè¡ãïŒ</p>
<ul>
<li>éžãã ã«ãŒããïŒæžãããŠããæŽæ°ãå°ããé ã«å·Šãã䞊ã¹ãïŒ</li>
<li>䞊ã¹ãã«ãŒãã®ãã¡ïŒå·Šãã <var>K</var> çªç®ã®ã«ãŒãã«æžãããæŽæ°ãçŽã«æžãåºãïŒ</li>
<li>éžãã ã«ãŒããïŒãã¹ãŠå
ã®äœçœ®ã«æ»ãïŒ</li>
</ul>
<p>
ãã®æäœãïŒé£ç¶ãã <var>K</var> æä»¥äžã®ã«ãŒãã®åãã¹ãŠã«å¯ŸããŠè¡ãïŒããªãã¡ïŒ<var>1 ⊠l ⊠r ⊠N</var> ã〠<var>K ⊠r - l + 1</var> ãæºãããã¹ãŠã® <var>(l,r)</var> ã«ã€ããŠïŒ<var>a_l, a_{l+1}, ..., a_r</var> ã®ãã¡ <var>K</var> çªç®ã«å°ããªæŽæ°ãæžãåºãïŒ</p>
<p>
ããããŠæžãåºãããæŽæ°ãïŒå·Šããå°ããé ã«äžŠã¹ãïŒäžŠã¹ãæŽæ°ã®ãã¡ïŒå·Šãã <var>L</var> çªç®ã®ãã®ããã®ã²ãŒã ã«ããã JOI åã®åŸç¹ã§ããïŒJOI åã®åŸç¹ãæ±ããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 \leq N \leq 200000</var></li>
<li><var>1 \leq K \leq N</var></li>
<li><var>1 \leq a_i \leq N</var></li>
<li><var>1 \leq L</var></li>
<li>JOI åãæžãåºãæŽæ°ã¯ <var>L</var> å以äžã§ããïŒ</li>
</ul>
<h2>å
¥åã»åºå</h2>
<p>
<b>å
¥å</b><br>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ<br>
<var>N</var> <var>K</var> <var>L</var><br>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</p>
<p>
<b>åºå</b><br>
JOI åã®åŸç¹ã <var>1</var> è¡ã§åºåããïŒ<br>
<!--
<h2>å°èª²é¡</h2>
<p>
<b>å°èª²é¡ 1 [6ç¹]</b>
</p>
<ul>
<li><var>N ⊠100</var></li>
</ul>
<p>
<b>å°èª²é¡ 2 [33ç¹]</b>
</p>
<ul>
<li><var>N ⊠4000</var></li>
</ul>
<p>
<b>å°èª²é¡ 3 [61ç¹]</b>
</p>
<ul>
<li>远å ã®å¶éã¯ãªãïŒ</li>
</ul>
-->
<h2>å
¥åºåäŸ</h2>
<b>å
¥åäŸ 1</b><br>
<pre>
4 3 2
4 3 1 2
</pre>
<b>åºåäŸ 1</b><br>
<pre>
3
</pre>
<p>
<var>1 \leq l \leq r \leq N (= 4)</var> ã〠<var>K (= 3) \leq r - l + 1</var> ãæºãã <var>(l,r)</var> ã¯ïŒ<var>(1,3), (1,4), (2,4)</var> ã® <var>3</var> éãããïŒ</p>
<p>
ãããã® <var>(l,r)</var> ã«å¯ŸãïŒ<var>a_l, a_{l+1}, ..., a_r</var> ã§ <var>3</var> çªç®ã«å°ããªæŽæ°ã¯ïŒãããã <var>4, 3, 3</var> ã§ããïŒ</p>
<p>
ãã®ãã¡ <var>L (= 2)</var> çªç®ã«å°ããæŽæ°ã¯ <var>3</var> ãªã®ã§ïŒJOI åã®åŸç¹ã¯ <var>3</var> ã§ããïŒåãæŽæ°ãè€æ°ãããšããïŒéè€ããŠæ°ããããšã«æ³šæããïŒ</p>
<hr>
<b>å
¥åäŸ 2</b><br>
<pre>
5 3 3
1 5 2 2 4
</pre>
<b>åºåäŸ 2</b><br>
<pre>
4
</pre>
<p>
JOI åãæžãåºãæŽæ°ã¯ïŒ</p>
<ul>
<li><var>(l,r) = (1,3)</var> ã«å¯Ÿã <var>5</var></li>
<li><var>(l,r) = (1,4)</var> ã«å¯Ÿã <var>2</var></li>
<li><var>(l,r) = (1,5)</var> ã«å¯Ÿã <var>2</var></li>
<li><var>(l,r) = (2,4)</var> ã«å¯Ÿã <var>5</var></li>
<li><var>(l,r) = (2,5)</var> ã«å¯Ÿã <var>4</var></li>
<li><var>(l,r) = (3,5)</var> ã«å¯Ÿã <var>4</var></li>
</ul>
<p>
ã§ããïŒãã®ãã¡ <var>L (= 3)</var> çªç®ã«å°ããæŽæ°ã¯ <var>4</var> ã§ããïŒ
</p>
<hr>
<b>å
¥åäŸ 3</b><br>
<pre>
6 2 9
1 5 3 4 2 4
</pre>
<b>åºåäŸ 3</b><br>
<pre>
4
</pre>
<hr>
<b>å
¥åäŸ 4</b><br>
<pre>
6 2 8
1 5 3 4 2 4
</pre>
<b>åºåäŸ 4</b><br>
<pre>
3
</pre>
|
p00093 |
<H1>ããã幎</H1>
<p>
è¥¿æŠ <var>a</var> 幎ãã <var>b</var> 幎ãŸã§ã®éã«ãããã¹ãŠã®ããã幎ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
ãããå¹Žã®æ¡ä»¶ã¯ã次ã®ãšãããšããŸãããã ãã0 < <var>a</var> ≤ <var>b</var> < 3,000 ãšããŸããäžããããæéã«ããã幎ããªãå Žåã«ã¯ "NA"ãšåºåããŠãã ããã
</p>
<ul>
<li> 西æŠå¹Žã 4 ã§å²ãåãã幎ã§ããããšã</li>
<li> ãã ãã100 ã§å²ãåãã幎ã¯ããã幎ãšããªãã</li>
<li> ãããã400 ã§å²ãåãã幎ã¯ããã幎ã§ããã</li>
</ul>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã®åœ¢åŒã¯ä»¥äžã®ãšããã§ãïŒ
</p>
<pre>
<var>a</var> <var>b</var>
</pre>
<p>
<var>a</var>, <var>b</var> ããšãã« 0 ã®ãšãå
¥åã®çµäºãšããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
<!--åããŒã¿ã»ããããšã«ã4 æ¡ã®è¥¿æŠãŸã㯠NA(åè§è±å€§æå)ãåºåããŠãã ããã-->
ããŒã¿ã»ããããšã«ã西æŠãŸã㯠NA ãåºåããŠãã ããã
</p>
<p>
ããŒã¿ã»ããã®éã«ïŒã€ã®ç©ºè¡ãå
¥ããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
2001 2010
2005 2005
2001 2010
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2004
2008
NA
2004
2008
</pre>
|
p02104 |
<h1>Problem G: Chairs</h1>
<h2>Problem</h2>
<p>
1ãã<var>N</var>ã®çªå·ãå²ãåœãŠããã<var>N</var>èã®æ€
åã«ã1ãã<var>N</var>ã®IDãå²ãåœãŠããã<var>N</var>人ã®äººã座ãããšããŠãããIDã<var>i</var>ã®äººã¯æ€
å<var>p<sub>i</sub></var>ã«åº§ããããšæã£ãŠããã
</p>
<p>
<var>N</var>人ã®äººã¯IDãå°ããé ã«1åã«äžŠã³ãåã®å
é ã®äººã以äžã®è¡åããšãã
</p>
<ol>
<li>æ€
å<var>p<sub>i</sub></var>ã«èª°ã座ã£ãŠããªããã°ããã®æ€
åã«åº§ãã</li>
<li>ããã§ãªããã°ã<var>p<sub>i</sub></var>ã«1ãå ç®ããåã®æåŸå°Ÿã«äžŠã³çŽãããã ãã<var>p<sub>i</sub></var>ã<var>N</var>ãè¶
ããå Žåã¯<var>p<sub>i</sub></var>ã1ã«ããã</li>
</ol>
<p>
å
šãŠã®äººãæ€
åã«åº§ããŸã§ãã®è¡åãç¹°ãè¿ããããšããæçµçã«åæ€
åã«åº§ã£ãŠãã人ã®IDãåºåããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var>
<var>p<sub>1</sub></var> <var>p<sub>2</sub></var> ... <var>p<sub>N</sub></var>
</pre>
<p>
1è¡ç®ã«æŽæ°<var>N</var>ãäžããããã<br>
2è¡ç®ã«<var>N</var>åã®æŽæ°<var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>, ..., <var>p<sub>N</sub></var>ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 10<sup>5</sup></li>
<li>1 ≤ <var>p<sub>i</sub></var> ≤ <var>N</var></li>
</ul>
<h2>Output</h2>
<p>
<var>N</var>è¡ã«æçµçãªç¶æ
ãåºåããã<br>
<var>i</var>è¡ç®ã«æ€
å<var>i</var>ã«åº§ã£ãŠãã人ã®IDãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
5
1 2 3 4 5
</pre>
<h2>Sample Output 1</h2>
<pre>
1
2
3
4
5
</pre>
<h2>Sample Input 2</h2>
<pre>
5
3 3 4 4 5
</pre>
<h2>Sample Output 2</h2>
<pre>
4
2
1
3
5
</pre> |
p00139 |
<H1>ãã</H1>
<p>
ããäžçã«ã¯ïŒæåã ãã§ã§ããäžæè°ãªãããäœãã§ããŸãããã®ããã«ã¯çŸåšAçš®ãšBçš®ã®2çš®é¡ã確èªãããŠããŸããããã以å€ã®çš®é¡ãããå¯èœæ§ããããŸãã
</p>
<p>
Açš®ã¯ïŒ">'"ã®åŸã«"="ã1å以äžäžŠãã åŸã"#"ãæ¥ãŠãããã«åãšåãåæ°ã®"="ãæ¥ãåŸã"~"ïŒåè§ãã«ãïŒã§çµãããŸãã
</p>
<p>
Bçš®ã¯ïŒ">^"ã®åŸã« "Q="ã1å以äžäžŠãã åŸã"~~"ã§çµãããŸãã
</p>
<pre>
Açš®ã®äŸïŒ >'====#====~ >'==#==~
</pre>
<pre>
Bçš®ã®äŸïŒ >^Q=Q=Q=Q=~~ >^Q=Q=~~
</pre>
<p>
ãããæååããŒã¿ãšããŠåãåãããããã©ããªçš®é¡ã§ããããå€å¥ããŠãAçš®ã®å Žåã¯ãAããBçš®ã®å Žåã¯ãBãããã以å€ã®çš®é¡ã®å Žåã¯ãNAããåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>S<sub>1</sub></var>
<var>S<sub>2</sub></var>
:
<var>S<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«å€å¥ãããããã®æ° <var>n</var>ïŒ1 ≤ <var>n</var> ≤ 10000ïŒãç¶ã <var>n</var> è¡ã« <var>i</var> å¹ç®ã®ããã衚ãæåå <var>S<sub>i</sub></var> (200æå以äžã®ã空çœãå«ãŸãªãæåå) ãããããïŒè¡ã«äžããããŸãã
</p>
<H2>Output</H2>
<p>
<var>i</var> è¡ç®ã« <var>i</var> å¹ç®ã®ããã®çš®é¡ AãB ãŸã㯠NA ãåºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
3
>'======#======~
>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
>'===#====~
</pre>
<H2>Output for the Sample Input</H2>
<pre>
A
B
NA
</pre>
|
p03938 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>You are given a permutation <var>p</var> of the set {<var>1, 2, ..., N</var>}. Please construct two sequences of positive integers <var>a_1</var>, <var>a_2</var>, ..., <var>a_N</var> and <var>b_1</var>, <var>b_2</var>, ..., <var>b_N</var> satisfying the following conditions:</p>
<ul>
<li><var>1 \leq a_i, b_i \leq 10^9</var> for all <var>i</var></li>
<li><var>a_1 < a_2 < ... < a_N</var></li>
<li><var>b_1 > b_2 > ... > b_N</var></li>
<li><var>a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 20,000</var></li>
<li><var>p</var> is a permutation of the set {<var>1, 2, ..., N</var>}</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>The output consists of two lines. The first line contains <var>a_1</var>, <var>a_2</var>, ..., <var>a_N</var> seperated by a space. The second line contains <var>b_1</var>, <var>b_2</var>, ..., <var>b_N</var> seperated by a space. </p>
<p>It can be shown that there always exists a solution for any input satisfying the constraints.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 4
5 4
</pre>
<p><var>a_1 + b_1 = 6</var> and <var>a_2 + b_2 = 8</var>. So this output satisfies all conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2 3
5 3 1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5 10 100
100 10 1
</pre></section>
</div>
</span> |
p01905 |
<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: ããŒãã¡ã³ã</h1>
<h2>åé¡</h2>
<p>
AOR ã€ã«ã¡ãããšããªãã¯ãããŒãã¡ã³ã圢åŒã®åç倧äŒã·ã³ã°ã«ã¹ã®éšã«åµå¯ã«æ¥ãã
å
šãŠã®è©Šåãé²ç»ããã AOR ã€ã«ã¡ããã®ããã«ãããªãã¯ãã®å€§äŒã§è¡ãããè©Šåæ°ãæ±ããŠãããããšã«ããã
</p>
<p>
ãã®å€§äŒã«ã¯ $N$ 人ã®éžæãåå ããŠããããããã $0, \dots , N - 1$ ã®èçªå·ãæã£ãŠããã
ãã®ãã¡ã $M$ 人ã®éžæãæ£æš©ãã詊åã«ã¯åºå Žããªãã£ãã
</p>
<p>
ãã®å€§äŒã®è©Šåæ°ã¯ã以äžã®ã«ãŒã«ã«åºããŠæ±ºå®ãããã
</p>
<ul>
<li>ã·ãŒãéžæã¯ååšãããä»»æã®åºå Žè
ãåªåããããã«å¿
èŠãªåå©åæ°ã¯äžå®ã§ããã</li>
<li>察æŠçžæãäžåšã®å Žåã¯è©Šåãè¡ãããåºå Žããéžæãåå©ãããè©Šåæ°ã«ã¯ã«ãŠã³ããããªãã</li>
<li>åªåè
ãæ±ºãŸã£ã段éã§å€§äŒã¯çµäºããã</li>
<li>äžåºŠè©Šåã«è² ãã人ãåã³è©Šåãããããšã¯ãªããã€ãŸãæè
埩掻æŠã 3 äœæ±ºå®æŠãªã©ã¯è¡ããªãã</li>
<li>ãªããåçå°ã 1 å°ããç¡ãããç°ãªã詊åãåæã«è¡ãããããšã¯ãªãããŸãå詊åã§ã¯å¿
ãåè
ãæ±ºãŸã (åŒãåããšãªãããšã¯ãªã)ã</li>
</ul>
<p>
ãªããããŒãã¡ã³ãã®å®çŸ©ã¯æ¬¡ã®ãšããã§ããã
ããŒãã¡ã³ãã¯é«ã $L = \log_2 N$ ã®å®å
šäºåæšã§è¡šãããèã«ãããåé ç¹ã«ã¯åå è
ã®èçªå·ãæžã蟌ãŸããŠããã
æ ¹ã®æ·±ãã 0 ãšãããšã $i$ åæŠ ($1 \le i \le L$) ã§ã¯ã
æ·±ã $L - i$ ã®åé ç¹ã®åã«æžãããçªå·ã®éžæå士ã詊åãè¡ãããã®åè
ã®èçªå·ããã®é ç¹ã«æžã蟌ãã
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day1_RUPC2017_Tournament">
<h2>å¶çŽ</h2>
<ul>
<li>$2 \le N \le 2^8$</li>
<li>$0 \le M \le N - 1$</li>
<li>$0 \le a_i \le N - 1 \ (0 \le i \le M - 1)$</li>
<li> $N$ 㯠2 ã®çޝä¹ã§ããã</li>
<li> $a_i \ (0 \le i \le M - 1)$ ã¯çžç°ãªã</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<p>
$N \ M$<br>
$a_1$<br>
$\vdots$<br>
$a_M$<br>
</p>
<ul>
<li>1 è¡ç®ã«ã¯ãåå è
ãè¡šãæŽæ° $N$ ãåå è
ã®ãã¡æ£æš©ããè
ã®äººæ°ãè¡šãæŽæ° $M$ ãäžããããã</li>
<li>ç¶ã $M$ è¡ã«ã¯ãæ£æš©ããŠåºå Žããªãã£ãéžæã®çªå·ãè¡šãæŽæ° $a_i$ ãäžããããã</li>
</ul>
<h2>åºå</h2>
<p>
ãã®å€§äŒãçµäºãããŸã§ã«è¡ãããè©Šåæ°ã 1 è¡ã§åºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
2 0
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
1
</pre>
<p>
æåã®è©Šåã§åªåè
ãæ±ºãŸãã
</p>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
4 2
2
3
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
1
</pre>
|
p00617 |
<H1><font color="#000000">Problem C:</font> Simple GUI Application</H1>
<p>
Advanced Creative Mobile 瀟ïŒACM瀟ïŒã§ã¯ãæ°ããããŒã¿ãã«ã³ã³ãã¥ãŒã¿ã«æèŒããGUIã¢ããªã±ãŒã·ã§ã³ã®éçºãè¡ãããšã«ãªã£ãã
</p>
<p>
äžå³ã«ç€ºãããã«ãGUIã¯ïŒã€ã®ã¡ã€ã³ããã«ãæã¡ããã®äžã«ããã€ãã®ããã«ãé
眮ãããããã«ãããã®ããã«ã®äžã«ãããã€ãã®ããã«ãé
眮ããããããªå
¥ãåæ§é ã«ãªã£ãŠãããããã«ã¯ãã¹ãŠèŸºã座æšè»žã«å¹³è¡ã»åçŽãªé·æ¹åœ¢ãŸãã¯æ£æ¹åœ¢ã§ããã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_GUITag">
</center>
<br>
<p>
ã¢ããªã±ãŒã·ã§ã³ã¯ããã«ã®å
¥ãåæ§é ãã¿ã°æ§é ã§ä¿æãã仿§ãšãªã£ãŠãããããã«ã衚ãã¿ã°æ§é ã¯ãã¿ã°å€ãšãã®ããã«ã®äžã«é
眮ãããŠããããã«ã®ã¿ã°æ§é ã®ãªã¹ããæã€ãã¿ã°å€ã¯ãã®ããã«ã®å·Šäžã®åº§æš (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) ãš å³äžã®åº§æš (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) ã瀺ãã
</p>
<p>ã¿ã°æ§é ã®æ§æèŠåã以äžã«ç€ºããããã§ãæ§æã®èšè¿°ã«çšããèšå·ã®æå³ãã以äžã®è¡šã®ããã«å®ããã"<span><</span>"ã"<span>></span>", "<span>,</span>" åã³ "<span>/</span>" ã¯ãåå¥èŠçŽ ã§ããã
</p>
<br>
<center>
<table border=1>
<tr>
<th>èšå·</th><th>æå³</th>
</tr>
<tr>
<td><span>::=</span></td><td>å®çŸ©ãã</td>
</tr>
<tr>
<td><span>{}*<span></td><td> <span>{<span> ãš <span>}</span> ã§å²ãŸããèŠçŽ ã® 0 å以äžã®ç¹°ãè¿ã</td>
</tr>
</table>
</center>
<br>
<pre>
ã¿ã°æ§é ::= éå§ã¿ã° ã¿ã°å€ {ã¿ã°æ§é }* çµäºã¿ã°
éå§ã¿ã° ::= <ã¿ã°å>
çµäºã¿ã° ::= </ã¿ã°å>
ã¿ã°å ::= æåå
ã¿ã°å€ ::= æŽæ°,æŽæ°,æŽæ°,æŽæ°
</pre>
<p>
ã¿ã°åã¯ããã«ã®ååã瀺ãïŒæå以äžãããªãæååã§ããã
</p>
<p>
ã¿ã°å€ã¯ãã«ã³ãã§åºåãããïŒã€ã®æŽæ°ã§ãããããããããã«ã®åº§æšã瀺ã <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>, <i>x</i><sub>2</sub>, <i>y</i><sub>2</sub> ã§ããã
</p>
<p>
äŸãã°ãäžå³ã«ç€ºããGUIã¯ä»¥äžã®ã¿ã°æ§é ã§èšè¿°ããã(ã¹ããŒã¹ã®é¢ä¿äžïŒè¡ã«ãŸããã£ãŠããããå
¥åã¯ïŒè¡ã§äžãããã)ïŒ
</p>
<pre>
<main>10,10,190,150<menu>20,20,70,140</menu><primary>80,20,180,140
<text>90,30,170,80</text><button>130,110,170,130</button></primary></main>
</pre>
<p>
ãã®GUIã§ã¯ããŠãŒã¶ãããç¹ãã¿ãããããšããã®ç¹ã«ãããŠæäžéšã«ããããã«ãéžæãããïŒå¢çç·ãå«ãïŒã
</p>
<p>
ããªãã®ä»äºã¯ãã¡ã€ã³ããã«ã®ã¿ã°æ§é ãšãã¿ãããããç¹ã®ãªã¹ããèªã¿èŸŒã¿ã以äžã®æ
å ±ãåºåããããã°ã©ã ãäœæããããšã§ããã
</p>
<ul>
<li>éžæãããããã«ã®åå</li>
<li>ãã®ããã«ã®çŽæ¥äžã«é
眮ãããŠããããã«ã®æ°ïŒä»¥äž"åã®æ°"ãšåŒã¶ïŒ</li>
</ul>
<p>
ãªããå
¥åãããã¿ã°æ§é ã«ã€ããŠä»¥äžã®ããšãä»®å®ããŠããã
</p>
<ul>
<li>ã¿ã°æ§é ã«ææ³ãšã©ãŒã¯ãªãã</li>
<li>ããã«ããããå«ãããã«ïŒä»¥äž"芪ããã«"ãšåŒã¶ïŒããã¯ã¿åºãããšã¯ãªããå¢çã«ãè§Šããªãã</li>
<li>åã芪ããã«ãæã€ããã«å士ã¯éãªãããè§Šããªãã</li>
<li>åãååã®ããã«ã¯ãªãã</li>
</ul>
<H2>Input</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<pre>
<i>n</i>
ã¿ã°æ§é
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub>
.
.
.
<i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub>
</pre>
<p>
<i>n</i> ã¯ã¿ãããããç¹ã®æ°ãç€ºãæŽæ°ã§ãããã¿ã°æ§é ã¯ç©ºçœãå«ãŸãªãïŒè¡ã®æååã§ããã<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> 㯠<i>i</i> çªãã«ã¿ãããããç¹ã® <i>x</i> 座æšãš <i>y</i> 座æšã衚ãïŒåº§æšè»žã¯äžå³ã«å®ãããã®ãšããïŒã
</p>
<p>
<i>n</i> ≤ 100ãã¿ã°æ§é ã®æååã®é·ã ≤ 1000 ãšä»®å®ããŠããããŸããå
¥åã§äžãããã <i>x</i> åº§æš <i>y</i> 座æšã¯ 0 ä»¥äž 10,000 以äžãšä»®å®ããŠããã
</p>
<p>
<i>n</i> ã 0 ã®ãšãå
¥åã®çµãããšããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠãéžæãããé çªã«ããã«ã®ååãšåã®æ°ãåºåãããåååãšåã®æ°ãïŒã€ã®ç©ºçœã§åºåã£ãŠïŒè¡ã«åºåãããäœãéžæãããªãå ŽåïŒã¿ãããããç¹ã«ããã«ããªãå ŽåïŒã¯ã"OUT OF MAIN PANEL 1"ãšåºåããã
</p>
<H2>Sample Input</H2>
<pre>
5
<main>10,10,190,150<menu>20,20,70,140</menu><primary>80,20,180,140</primary></main>
10 10
15 15
40 60
2 3
130 80
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
main 2
main 2
menu 0
OUT OF MAIN PANEL 1
primary 0
</pre>
|
p03892 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is drawing a segment on grid paper.</p>
<p>From a certain square, a square that is <var>x</var> squares to the right and <var>y</var> squares above, is denoted as square <var>(x, y)</var>.</p>
<p>When Takahashi draws a segment connecting the lower left corner of square <var>(A, B)</var> and the lower left corner of square <var>(C, D)</var>, find the number of the squares crossed by the segment.</p>
<p>Here, the segment is said to <em>cross</em> a square if the segment has non-empty intersection with the region within the square, excluding the boundary.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq A, B, C, D \leq 10^9</var></li>
<li>At least one of <var>A \neq C</var> and <var>B \neq D</var> holds.</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>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the squares crossed by the segment.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3 10 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre></section>
</div>
</span> |
p02780 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> dice arranged in a line from left to right. The <var>i</var>-th die from the left shows <var>p_i</var> numbers from <var>1</var> to <var>p_i</var> with equal probability when thrown.</p>
<p>We will choose <var>K</var> adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †K †N †200000</var></li>
<li><var>1 †p_i †1000</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>p_1</var> ... <var>p_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible value of the expected value of the sum of the numbers shown.</p>
<p>Your output will be considered correct when its absolute or relative error from our answer is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
1 2 2 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7.000000000000
</pre>
<p>When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is <var>7</var>. This is the maximum value we can achieve.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 1
6 6 6 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3.500000000000
</pre>
<p>Regardless of which die we choose, the expected value of the number shown is <var>3.5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 4
17 13 13 12 15 20 10 13 17 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>32.000000000000
</pre></section>
</div>
</span> |
p00247 |
<H1>æ°·ã®è¿·è·¯</H1>
<p>
åè§ã®ãã¹ã瞊暪ã«ãªãã¹ãé·æ¹åœ¢ã®è¿·è·¯ããããŸãããã®è¿·è·¯ã§ã¯æ±è¥¿ååã®é£æ¥ãããã¹ãžç§»åããªãããã¹ã¿ãŒãã®ãã¹SãåºçºãããŽãŒã«ã®ãã¹Gãç®æããŸãããã¹ã®çš®é¡ã«ã¯ãå¹³åãå±±ãæ°·ã®ïŒçš®é¡ããããŸããSãšGã¯ãå¹³åã®ãã¹ã«çœ®ãããŠããŸããå¹³åã®ãã¹ã«ã¯ç§»åã§ããŸãããå±±ã®ãã¹ã«ã¯ç§»åã§ããŸãããæ°·ã®ãã¹ã¯ç§»åã§ããŸãããæ¡ä»¶ã«ãã£ãŠæ°·ãå²ãåããªããªããŸãã
</p>
<ul>
<li> æ°·ã®ãã¹ã¯æ±è¥¿ååã«é£æ¥ãããã®å
šäœã§ã²ãšã€ã®å¡ãšããŠæ±ãããŸãã</li>
<li> æ°·ã®å¡ã®ãªãã§ããã¹ã®åæ°ã®ååããå€ãã®ãã¹ã«ç§»åãããšãå¡å
šäœãå²ããŸãã</li>
</ul>
<p>
äŸãã°ãå³ïŒã¯äžããããè¿·è·¯ã®æççµè·¯ã®ã¹ãããæ°ã 11 ã§ããããšã瀺ããŠããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0247_1"><br>
<b>å³1</b>
</center>
<p>
ããããå³ïŒã®ããã«æ°·ã®ãã¹ãéã£ãŠè¿éãããããšãããšã倧ãããïŒã®æ°·ã®å¡ã«å¯ŸããïŒåç®ã®ç§»ååŸã«åããªããªã£ãŠããŸãGã«ã¯å°éã§ããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0247_2">
<b>å³2</b>
</center>
<p>
ãã®ãããªè¿·è·¯ã®æ
å ±ãå
¥åãšããSããGãŸã§ã®æççµè·¯ã®ã¹ãããæ°ãæ±ããããã°ã©ã ãäœæããŠãã ããããã¹ã®çš®é¡ã¯ãããã以äžã®æåã§è¡šãããŸãïŒ
</p>
<center>
<table style="border: 1px #000 solid" "border="1" cellpadding="3" cellspacing="0">
<tr>
<th width="160"style="border: 1px #000 solid" >æåïŒåè§ïŒ</th>
<th width="160"style="border: 1px #000 solid" >ãã¹ã®çš®é¡</th>
</tr>
<tr>
<td style="border: 1px #000 solid" >. ïŒããªãªãïŒ</td>
<td style="border: 1px #000 solid" >å¹³å</td>
</tr>
<tr>
<td style="border: 1px #000 solid" >#ïŒã·ã£ãŒãïŒ</td>
<td style="border: 1px #000 solid" >å±±</td>
</tr>
<tr>
<td style="border: 1px #000 solid" >X</td>
<td style="border: 1px #000 solid" >æ°·</td>
</tr>
</table>
</center>
<br>
<p>
äžããããè¿·è·¯ã¯å¿
ãè§£ãããã®ãšããŸããè¿·è·¯ã¯ãã®æ±è¥¿æ¹åã®ãã¹ã®æ° <var>X</var>ãååæ¹åã®ãã¹ã®æ° <var>Y</var> ãš <var>X</var> × <var>Y</var> åã®æåãšããŠäžããããŸãã
</p>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>X</var> <var>Y</var>
<var>line<sub>1</sub></var>
<var>line<sub>2</sub></var>
:
<var>line<sub>Y</sub></var>
</pre>
<p>
1è¡ç®ã«è¿·è·¯ã®å€§ãããè¡šãæŽæ° <var>X</var>, <var>Y</var> (2 ≤ <var>X, Y</var> ≤ 12) ãäžããããŸããç¶ã <var>Y</var> è¡ã«è¿·è·¯ã® <var>i</var> è¡ç®ã®æ
å ± <var>line<sub>i</sub></var> (é·ã <var>X</var> ã®åè§è±æåå) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 40 ãè¶
ããªãã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãæå°ã®ã¹ãããæ°ãïŒè¡ã«åºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
5 5
.X.S.
.X#..
.XX##
.#XG.
..X..
7 3
SXX.XXG
X.#.#X.
XXX.XX#
4 4
S...
X.X.
GX..
...X
10 10
..XXXXX.XX
.X.#.#X.XX
SX.#X.X..X
#X.##.X.XX
..XXXX#.XX
##.##.##XX
....X.XX#X
.##X..#X#X
....XX#..X
...#XXG..X
0 0
</pre>
<h2>åºåäŸ</h2>
<pre>
11
10
10
33
</pre> |
p01006 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1>Problem A: Nasty Boys</h1>
<h2>Problem</h2>
<p>
倪éåã¯åŠæ ¡ã®ããã«ãŒã«å€§äºãªæ¬ãé ããŠããã®ã§ä»ã®äººãããšãŠãå³éã«ç®¡çããŠããŠãåŠæ ¡ã§æ¯çµŠãããéµã«å ããŠä»¥äžã®ãããªãã¿ã³èªèšŒåŒã®éµãèšçœ®ããŠããŸãã</p>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_progpic" width="300px" height="200px" />
</p>
<p>
ãã ãã¹ã¯ãŒããå¿ãããã倪éããã¯ãã¹ã¯ãŒããäžçæžãã§æžãããã®ã«ããŠããŸãçããããŸããæŽã«è©°ãã®çã倪éåã¯èªåã®ãã¹ã¯ãŒããèãããšãã«åè£ãçŽã«æžããŠããŸããããã®çŽãããŸããŸæŸã£ãã¯æ¬¡éåã¯ãæ§æ Œãæªãã®ã§æšãŠãã«ããã«ãŒãéããããšã«ææŠããŸããã
</p>
<p>
ãããçŽã«ã¯ãªããš1000åãã®ãã¹ã¯ãŒãã®æ¡ãæžãããŠãããå
šãŠã®å
¥åã詊ããšæ¥ãæ®ããŠããŸãããã§ãã
ããã§å€ªéåã®çãç¥ã£ãŠããæ¬¡éåã¯ã調ã¹ãåæ°ãæžããããã«1000åã®ãã¹ã¯ãŒãã®äžããäžçæžãã§ãããã®ã ããåãäžããããšã«ããŠããã®äœæ¥ãããã°ã©ããŒã®è²Žæ¹ã«é Œãããšã«ããŸããã
</p>
<p>
1ã€ã®ããŒã¿ã»ããã«ã€ãå¿
ãåè£ã¯äžã€ä»¥äžååšããŸããäžçæžãã®ã«ãŒã«ã以äžã«ç€ºããŸãã
</p>
<ol>
<li>åãæåã¯é£ç¶ããªããäŸãã°AAAã¯èš±ãããªãã</li>
<li>äžäžå·Šå³4æ¹åã«äžçæžããå¯èœãæãæ¹åã«ç§»åããªãã</li>
<li>ãã¿ã³é
åã®æ å€ã«åºãŠé£ç¶ããããšã¯ãªããäŸãã°ABCAã®ãããªç§»åã¯èš±ãããªãã</li>
<li>äžåºŠéã£ãæåã®äžãäœåºŠãééå¯èœã</li>
<li>ãã¿ã³1æåã®ã¿ã®å
¥åãäžçæžããšã¿ãªãã</li>
</ol>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®ããã«1000åã®æåå矀ãããªããåè¡ã¯AããIãŸã§ã®1æå以äž10æå以äžã®å€§æåã®ã¢ã«ãã¡ãããåã§ãããããããæååã®ããŒã¿ã®éè€ã¯ãªããã®ãšããã
</p>
<pre>
<var>string<sub>1</sub></var>
<var>string<sub>2</sub></var>
<var>...</var>
<var>string<sub>1000</sub></var>
</pre>
<h2>Output</h2>
<p>
å
¥åã®ãã¡åè£ãšãªããã¹ã¯ãŒãïŒcandidatePasswordïŒã®ã¿æãåºããŠä»¥äžã®ããã«åæããããªã以äžã®å Žåã¯Nåã®åè£ãæããããŠããã
</p>
<pre>
<var>candidatePassword<sub>1</sub></var>
<var>candidatePassword<sub>2</sub></var>
<var>...</var>
<var>candidatePassword<sub>N</sub></var>
</pre>
<p>
åºåã¯å
¥åã®æååã®é ãšåãã§ããé çªãå
¥ãæ¿ããŠã¯ãªããªãã
</p>
<h2>Sample Input</h2>
<pre>
ABCFI
ABCABCABC
AEI
EFC
ïŒäžç¥ïŒ
DEHED
EEEEE
ïŒä»¥äžã§ã¡ããã©1000åïŒ
</pre>
<h2>Sample Output</h2>
<pre>
ABCFI
EFC
ïŒäžç¥ïŒ
DEHED
</pre> |
p03191 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a sequence of length <var>2N</var>: <var>A_1, A_2, ..., A_{2N}</var>.
Each <var>A_i</var> is either <var>-1</var> or an integer between <var>1</var> and <var>2N</var> (inclusive). Any integer other than <var>-1</var> appears at most once in <var>{A_i}</var>.</p>
<p>For each <var>i</var> such that <var>A_i = -1</var>, Snuke replaces <var>A_i</var> with an integer between <var>1</var> and <var>2N</var> (inclusive), so that <var>{A_i}</var> will be a permutation of <var>1, 2, ..., 2N</var>.
Then, he finds a sequence of length <var>N</var>, <var>B_1, B_2, ..., B_N</var>, as <var>B_i = min(A_{2i-1}, A_{2i})</var>.</p>
<p>Find the number of different sequences that <var>B_1, B_2, ..., B_N</var> can be, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li><var>A_i = -1</var> or <var>1 \leq A_i \leq 2N</var>.</li>
<li>If <var>A_i \neq -1, A_j \neq -1</var>, then <var>A_i \neq A_j</var>. (<var>i \neq 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>A_1</var> <var>A_2</var> <var>...</var> <var>A_{2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of different sequences that <var>B_1, B_2, ..., B_N</var> can be, modulo <var>10^9 + 7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 -1 -1 3 6 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>There are six ways to make <var>{A_i}</var> a permutation of <var>1, 2, ..., 2N</var>; for each of them, <var>{B_i}</var> would be as follows:</p>
<ul>
<li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 4, 3, 6, 5)</var>: <var>(B_1, B_2, B_3) = (1, 3, 5)</var></li>
<li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 5, 3, 6, 4)</var>: <var>(B_1, B_2, B_3) = (1, 3, 4)</var></li>
<li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 2, 3, 6, 5)</var>: <var>(B_1, B_2, B_3) = (1, 2, 5)</var></li>
<li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 5, 3, 6, 2)</var>: <var>(B_1, B_2, B_3) = (1, 3, 2)</var></li>
<li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 2, 3, 6, 4)</var>: <var>(B_1, B_2, B_3) = (1, 2, 4)</var></li>
<li><var>(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 4, 3, 6, 2)</var>: <var>(B_1, B_2, B_3) = (1, 3, 2)</var></li>
</ul>
<p>Thus, there are five different sequences that <var>B_1, B_2, B_3</var> can be.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
7 1 8 3 5 2 6 4
</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
7 -1 -1 -1 -1 -1 -1 6 14 12 13 -1 15 -1 -1 -1 -1 20 -1 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9540576
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>20
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 -1 -1 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 34 -1 -1 -1 -1 31 -1 -1 -1 -1 -1 -1 -1 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>374984201
</pre></section>
</div>
</span> |
p01456 |
<H1>Problem J: å顿æ
åœè
ã¯åããªãïŒ</H1>
<p>
<i>N</i> åã®ç¹ãããªãæåã°ã©ããããããã®ã°ã©ãã«éè·¯ã¯ãªããããããã®ç¹ã«ã¯ãããã€ãã®ç³ã眮ãããŠããããã®ã°ã©ãã䜿ã£ãŠãïŒäººã®ãã¬ã€ã€ãŒãã²ãŒã ãããããã®ãã®ã®æçªã¯ã亀äºã«èšªãããåãã¬ã€ã€ãŒã¯ãèªåã®æçªã«ãããŠãé ç¹<i>v</i> ãéžã³ãããã«çœ®ãããç³ãïŒã€ä»¥äžåãé€ãããã®åŸã<i>v</i> ãã<i>w</i> ã«èŸºã匵ãããŠãããã¹ãŠã®é ç¹<i>w</i> ã«ã€ããŠã<i>w</i> ã«çœ®ãããŠããç³ã®åæ°ãèªç±ã«å€åãããããšãã§ããïŒããã€å¢ãããŠããããã€æžãããŠããå€åãããªããŠãããïŒããããç¹°ãè¿ããŠãæåã«åãç³ããªããªã£ãæ¹ã®è² ãã§ãããäž¡è
ãæåãã€ããããšããå
æãšåŸæãã©ã¡ããåã€ãããããã¯ããã€ãŸã§ãã²ãŒã ãçµãããªããã
</p>
<p>
ãâŠâŠãããç¡çã§ããããããã<br>
ãäœãïŒã<br>
ãäœããããªããŠïŒãããã«ã©ããã£ãŠèªç¶ãªåé¡èšå®ãã€ããã£ãŠèšããã§ããã<br>
ãã¯ã¯ã¯ããããèããã®ãåã®ä»äºãããªãããæç« æ
åœã ããïŒã<br>
ãäžžæãã«ãã»ã©ããããŸããâŠâŠããŸãã²ãŒã ã®ã«ãŒã«ãäžèªç¶ãããã§ãããã<br>
ãããããªãïŒãåã¯ããããç³åãã²ãŒã ã ãšæããã©ãã<br>
ããã¬ã€ã€ãŒã®ææã§ç³ãç¡å°œèµã«å¢ãããç³åãã²ãŒã ããããã£ãŠããŸããŸããïŒã<br>
ãããåãä»ããŸãããšèšã£ããã<br>
ããããææã§ç³ãâŠâŠã£ãŠã©ãã§ããããïŒããã£ã¡ãå°ãã¯èããŠãã ãããã<br>
ãããã ãããçžæ»ããå»åž«ã®éºå¿ãç¶ãéºåã®ææã§ç³ãåãããªããŠã©ãã ãïŒã<br>
ãèããã®ã¯ãããããããïŒãç³åãã²ãŒã ã®è©±ã ãïŒã<br>
ãéãã®ããïŒãã§ããåããã¯é³¥ãããããåé³ç°çŸ©èªããªããŠé£ãããã ããã<br>
ããã£ããèšèéã³ããé¢ãããïŒãèªç¶ãªåé¡èšå®ãèããŠããã£ãŠèšã£ãŠããã§ããïŒã<br>
ãã ããããã¯åã®ä»äºã ããã«ãåã¯ãã ã®ä»²ä»åœ¹ãåæ¡æ
åœãšæç« æ
åœã®éããšããã€ã ããã<br>
ãããâŠâŠãåæ¡æ
åœããã©ãããŠãããªåä»ãªåé¡ãâŠâŠã<br>
ãåæ¡æ
åœè
ããåãžã®ã¡ãã»ãŒãžãããããïœãååã«èŠããæç« æ
åœïœïœãã ããã ãã<br>
ãççãã®ééïŒããã€ãäžçºæ®ŽãïŒã<br>
ããŸããåã®ãç³ãå¢ããç³åãã²ãŒã ãªããŠå®ã«èšå®ãã€ãã«ãããšæããªãããïŒãã£ãŠã¢ãã
ã€ã¹ã®ããããããã ãããã©ãã<br>
ãççãåããïŒããã€ããšèšãã仿®ŽãïŒã<br>
ãã¯ã£ã¯ã£ã¯ãåãç· ãåããŸã§ã«æç« æ
åœãšããŠã®åœ¹å²ãæãããªããããªããåãåæã«å顿
ãæžãã¡ãããïŒã<br>
ãæ®ŽâŠâŠã£ãŠããïŒããåãæžããŠãããã®ïŒã<br>
ãã¿ã€ãã«ã¯ãå顿æ
åœè
ã¯åããªãïŒããæ¬æã«ã¯ãåãã¡ã®ãã®äŒè©±ããã®ãŸãŸæ²èŒã<br>
ãé ŒããããããŠïŒããããªãµãããåé¡ãèªåå矩ã§äžã«åºãããããããçã«ãªããŠèšããã
ãïŒã<br>
ãã¯ã£ã¯ã£ã¯ãç· ãåããå®ããªããããªå¥Žã¯ã瀟äŒçã«æ¹æ®ºãããŠåœç¶ã ããã<br>
ãççïŒããããªã£ãããæå°ã§ãèªç¶ãªåé¡èšå®ãæãã€ããŠãããããããïŒã<br><br>
ïŒâ»ãçµå±ãã®ãŸãŸæ²èŒãããŸããïŒ<br>
</p>
<H2>Input</H2>
<p>
<i>N M</i><br>
<i>v</i><sub>1</sub><br>
<i>v</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>v<sub>N</sub></i><br>
<i>a</i><sub>1</sub> <i>b</i><sub>1</sub></br>
<i>a</i><sub>2</sub> <i>b</i><sub>2</sub></br>
.<br>
.<br>
.<br>
<i>a<sub>M</sub> b<sub>M</sub></i><br>
</p>
<p>
å
¥åã®ïŒè¡ç®ã«ã¯ãæŽæ°<i>N</i>ïŒ2 ≤ <i>N</i> ≤ 1,000ïŒãšæŽæ°<i>M</i>ïŒ1 ≤ <i>M</i> ≤ 10,000ïŒãã空çœåºåãã§æžãããŠãããããã¯ãæåã°ã©ããN åã®ç¹ãš<i>M</i> æ¬ã®èŸºãããªãããšããããããé ç¹ã«ã¯ã1 çªãã<i>N</i> çªãŸã§ã®çªå·ããµãããŠããã
</p>
<p>
ç¶ã<i>N</i> è¡ã«ã¯ãæŽæ°<i>v<sub>i</sub></i>ïŒ1 ≤ <i>v<sub>i</sub></i> ≤ 10,000ïŒãæžãããŠãããïŒïŒ i è¡ç®ã«æžãããæŽæ°<i>v<sub>i</sub></i> ã¯ãi çªã®ç¹ã«æåã¯vi åã®ç³ã眮ãããŠããããšãããããã
</p>
<p>
ç¶ã<i>M</i> è¡ã«ã¯ãæŽæ°<i>a<sub>i</sub></i>ïŒ1 ≤ <i>a<sub>i</sub></i> ≤ <i>N</i>ïŒãšæŽæ°<i>b<sub>i</sub></i>ïŒ1 ≤ <i>b<sub>i</sub></i> ≤ <i>N</i>ïŒãã空çœåºåãã§æžãããŠãããïŒïŒ<i>N</i> ïŒ i è¡ç®ã«æžãããæŽæ°<i>a<sub>i</sub></i> ãš<i>b<sub>i</sub></i> ã¯ã<i>a<sub>i</sub></i> çªã®ç¹ãã<i>b<sub>i</sub></i> çªã®ç¹ãžåŒµãããŠãã蟺ãååšããããšããããããããç¹ããèªåèªèº«ãžãšåŒµããã蟺ã¯ååšãããããç¹A ããããç¹B ãžåŒµããã蟺ã¯é«ã
ïŒæ¬ã§ããã
</p>
<p>
äžããããæåã°ã©ãã«ã¯éè·¯ããªããšä»®å®ããŠããã
</p>
<H2>Output</H2>
<p>
äž¡ãã¬ã€ã€ãŒãèªèº«ã®åå©ãç®æããŠæåãã€ããããšããå
æãåã€ãªãã°1 ããåŸæãåã€ãªã
ã°2 ãããã€ãŸã§ãã²ãŒã ãçµãããªããªãã°0 ãåºåããã
</p>
<h2>Sample Input 1 </h2>
<pre>
6 5
7
14
5
11
2
5
1 2
2 3
3 4
4 5
5 6
</pre>
<h2>Sample Output 1 </h2>
<pre>
2
</pre>
<h2>Sample Input 2 </h2>
<pre>
5 7
295
127
350
982
426
1 5
3 5
4 2
3 1
3 4
5 4
3 2
</pre>
<h2>Sample Output 2 </h2>
<pre>
1
</pre>
<h2>Sample Input 3 </h2>
<pre>
8 7
6
1
7
2
5
2
6
3
1 3
6 3
7 4
4 2
1 6
5 4
7 5
</pre>
<h2>Sample Output 3 </h2>
<pre>
2
</pre> |
p01143 |
<!-- begin en only -->
<h3><U> Princess' Gamble </U></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><U> ãå§«æ§ã®ã®ã£ã³ãã« </U></h3>
<!-- end ja only -->
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ããè²§ä¹ãªåœã®ããŠãã°ã§åæ¢ãªãå§«æ§ã¯ïŒããæ¥éšå±ã®å£ãå£ããŠãåãæãåºãïŒç«¶éЬãªã©ã®ã®ã£ã³ãã«ãè¡ãããŠããè³åå Žã«å
¥ã£ãŠãã£ãïŒãšãããïŒã®ã£ã³ãã«ãªã©ãã£ãããšã®ãªããå§«æ§ã¯ïŒéåžžã«è² ãã蟌ãã§ããŸã£ãïŒãã®ç¶æ³ãããããããªããšæã£ããå§«æ§ã¯ïŒäžäœã©ã®ãããªä»çµã¿ã§ã®ã£ã³ãã«ãè¡ãããŠãããã調ã¹ãŠã¿ãïŒãããšïŒãã®ãããªã®ã£ã³ãã«ã§ã¯ããªãã¥ãã¥ãšã«æ¹åŒãšåŒã°ããæ¹åŒã§é
åœã決å®ãããŠããããšãçªãæ¢ããïŒ
</p>
<p>
ããªãã¥ãã¥ãšã«æ¹åŒãšã¯ïŒç«¶èµ°ã察象ãšããã®ã£ã³ãã«ã«ãããŠé
åœã決å®ããããã«äœ¿çšããèšç®æ¹æ³ã§ããïŒãã®æ¹åŒã§ã¯ïŒå
šãŠã®æãéãããŒã«ãïŒäžå®ã®å²åãæ§é€ããäžã§ïŒåœéžè
ã«æãéã«æ¯äŸããéé¡ãåé
ããïŒ
</p>
<p>
çŸåšãå§«æ§ãç±äžããŠããã®ã£ã³ãã«ã¯ïŒåå è
ã¯ç«¶æåã«ã©ã®ç«¶æè
ãåªåããããäºæ³ãã 1æ100ãŽãŒã«ãã®æç¥šåžã賌å
¥ãïŒç«¶æã®çµæãäºæ³ãšäžèŽããã°åœéžéãåãåãæš©å©ãåŸããšãããã®ã§ããïŒãªãïŒãŽãŒã«ãã¯ãã®åœã®é貚åäœã§ããïŒããªãã®ä»äºã¯å
¥åãšããŠäžããããç«¶æã®æ
å ±ãããšã«ïŒæç¥šåžäžæãããã®é
åœãèšç®ããããã°ã©ã ãæžãããšã§ããïŒ
</p>
<p>
å
è¿°ã®æ¹æ³ã§èšç®ãããé
åœé¡ãæŽæ°ã«ãªããªãå Žåã¯ïŒåãæšãŠã«ãã£ãп޿°ã«ããããšïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæãïŒããŒã¿ã»ããã®åæ°ã¯100以äžã§ããïŒæåŸã®ããŒã¿ã»ããã®åŸã«ïŒå
¥åã®çµããã瀺ãã0 0 0ããããªãäžè¡ãäžããããïŒ
</p>
<p>
åããŒã¿ã»ããã¯æ¬¡ã®ãããªåœ¢åŒãããŠããïŒ
</p>
<blockquote>
<i>N</i> <i>M</i> <i>P</i><br>
<i>X<sub>1</sub></i><br>
...<br>
<i>X<sub>N</sub></i>
</blockquote>
<p>
æåã®è¡ã® <i>N</i> ã¯æç¥šã®å¯Ÿè±¡ãšãªãç«¶æè
ã®æ°ïŒ<i>M</i> ã¯åªåããç«¶æè
ã®çªå·ïŒ<i>P</i> ã¯æ§é€çïŒçŸåçïŒãè¡šãæŽæ°ã§ããïŒ <i>X<sub>i</sub></i> 㯠<i>i</i> çªç®ã®ç«¶æè
ã«æç¥šãããæç¥šåžã®ææ°ã§ããïŒ 1 ⊠<i>N</i> ⊠100ïŒ 1 ⊠<i>M</i> ⊠<i>N</i>ïŒ 0 ⊠<i>P</i> ⊠100ïŒ 0 ⊠<i>X<sub>i</sub></i> ⊠1000 ãä»®å®ããŠããïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«å¯ŸãïŒåœéžããæç¥šåžäžæãããã®é
åœéé¡ãç€ºãæŽæ°ãããªãäžè¡ãåºåããïŒè³ãã«åã£ã人ãããªãå Žåã¯0ãåºåããïŒåºåè¡ã«ã¯ä»ã®æåããã£ãŠã¯ãªããªãïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
3 2 50
1
2
3
4 4 75
1
2
3
0
3 1 10
8
1
1
0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
150
0
112
</pre>
|
p03484 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has decided to make a <em>Christmas Tree</em> for the Christmas party in AtCoder, Inc.</p>
<p>A Christmas Tree is a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var> and <var>N-1</var> edges, whose <var>i</var>-th edge <var>(1\leq i\leq N-1)</var> connects Vertex <var>a_i</var> and <var>b_i</var>.</p>
<p>He would like to make one as follows:</p>
<ul>
<li>Specify two non-negative integers <var>A</var> and <var>B</var>.</li>
<li>Prepare <var>A</var> <em>Christmas Paths</em> whose lengths are at most <var>B</var>. Here, a Christmas Path of length <var>X</var> is a graph with <var>X+1</var> vertices and <var>X</var> edges such that, if we properly number the vertices <var>1</var> through <var>X+1</var>, the <var>i</var>-th edge <var>(1\leq i\leq X)</var> will connect Vertex <var>i</var> and <var>i+1</var>.</li>
<li>Repeat the following operation until he has one connected tree:<ul>
<li>Select two vertices <var>x</var> and <var>y</var> that belong to different connected components. Combine <var>x</var> and <var>y</var> into one vertex. More precisely, for each edge <var>(p,y)</var> incident to the vertex <var>y</var>, add the edge <var>(p,x)</var>. Then, delete the vertex <var>y</var> and all the edges incident to <var>y</var>.</li>
</ul>
</li>
<li>Properly number the vertices in the tree.</li>
</ul>
<p>Takahashi would like to find the lexicographically smallest pair <var>(A,B)</var> such that he can make a Christmas Tree, that is, find the smallest <var>A</var>, and find the smallest <var>B</var> under the condition that <var>A</var> is minimized.</p>
<p>Solve this problem for him.</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,b_i \leq N</var></li>
<li>The given graph is a tree.</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>b_1</var>
:
<var>a_{N-1}</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For the lexicographically smallest <var>(A,B)</var>, print <var>A</var> and <var>B</var> with a space in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
1 2
2 3
2 4
4 5
4 6
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3 2
</pre>
<p>We can make a Christmas Tree as shown in the figure below:</p>
<p><img alt="" src="https://img.atcoder.jp/arc088/96f78221624d6a13628f6052f5db697d.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
1 2
2 3
3 4
4 5
5 6
5 7
5 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2 5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1 2
2 3
3 4
2 5
6 5
6 7
7 8
5 9
10 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3 4
</pre></section>
</div>
</span> |
p01513 |
<!-- begin en only -->
<h3><u>Save Your Privacy!
</u></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><u>åã®ãã©ã€ãã·ãŒãå®ã!
</u></h3>
<!-- end ja only -->
<div>
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ICPC (International Committee of Privacy and Confidence) ã¯äžçäžã«å€ãã®æ§æå¡ãæã€çµç¹ã§ããããã®åã®éãéåžžã«ãã©ã€ãã·ãŒãå°éãããç§å¯äž»çŸ©è
ãã¡ã®å£äœã§ãããæ§æå¡ãã¡ã¯å¿
èŠäžä»ã®æ§æå¡ã®å人æ
å ±ãç¥ã£ãŠããŸãããšãããããããããå³éã«ç§å¿ãããã矩åä»ããããŠããã
</p>
<p>
ãããããæ¥ãäœäººãã®æ§æå¡ã®å人æ
å ±ãæŒæŽ©ããŠããŸã£ãïŒICPCã® ACM (Account Control Manager: ã¢ã«ãŠã³ã管ç責任è
) ã§ããããªãã¯ãéããã«æ
å ±ãæŒæŽ©ãããæ§æå¡ãç¹å®ããå³éã«åŠåããªããã°ãªããªãã
</p>
<p>
ããªãã¯æ§æå¡ããã倧ããªæš©éãæã€ç®¡çè
ãªã®ã§ã誰ã誰ã®å人æ
å ±ãç¥ã£ãŠããŸã£ãŠããããå®å
šã«ææ¡ããŠããããã¡ãããã©ã®æ§æå¡ãèªåã®ç¥ããªãæ§æå¡ã®å人æ
å ±ãæŒæŽ©ãããããšã¯ããããªããããããç¯äººã¯èªåãç¥ã£ãŠããå
šãŠã®å人æ
å ±ãæŒæŽ©ããããšã¯éããªããå人æ
å ±ãæŒæŽ©ããŠããŸã£ãæ§æå¡ã®äžèЧãããã©ã®æ§æå¡ãå人æ
å ±ãæŒæŽ©ãããã®ãã (å¯èœãªãã°) ç¹å®ãããã
</p>
<p>
ãšããã§ãICPC ãšããçµç¹ãäœãç®çãšããŠæŽ»åããŠããã®ãã¯æéèŠæ©å¯ã§ããã管çè
ã®æš©éããã£ãŠããŠãç¥ãããšã¯ã§ããªãã
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åãã¡ã€ã«ã¯è€æ°ã®ããŒã¿ã»ãããå«ãã1 ã€ã®ããŒã¿ã»ããã¯ã以äžã®åœ¢åŒã§äžããããã
</p>
<blockquote>
<var>N</var><br/>
<var>M<sub>1</sub></var> <var>p<sub>1,1</sub></var> <var>p<sub>1,2</sub>...</var> <var>p<sub>1,M<sub>1</sub></sub></var><br/>
<var>M<sub>2</sub></var> <var>p<sub>2,1</sub></var> <var>p<sub>2,2</sub>...</var> <var>p<sub>2,M<sub>2</sub></sub></var><br/>
<var>:</var><br/>
<var>M<sub>N</sub></var> <var>p<sub>N,1</sub></var> <var>p<sub>N,2</sub>...</var> <var>p<sub>N,M<sub>N</sub></sub></var><br/>
<var>K</var> <var>l<sub>1</sub></var> <var>l<sub>2</sub>...</var> <var>l<sub>K</sub></var><br/>
</blockquote>
<p>
N (2 ≤ N ≤ 100) ã¯æ§æå¡ã®æ°ãè¡šãæŽæ°ã§ãããããããã®æ§æå¡ã«ã¯ 1 ãã N ãŸã§ã®çªå·ãæ¯ãããŠããã
ç¶ã N è¡ã«ã¯åæ§æå¡ã®çªå·é ã«ããã®æ§æå¡ãç¥ã£ãŠããå人æ
å ±ã®äžèЧãäžãããããåè¡ã®æåã®æŽæ° M<sub>i</sub> (0 ≤ M<sub>i</sub> ≤ N)ã¯ãåŸã«ç¶ãæŽæ°ã®åæ°ã衚ããæ®ãã®æŽæ°ã¯ããã®æ§æå¡ãå人æ
å ±ãç¥ã£ãŠããæ§æå¡ã®çªå·ã衚ãã
æåŸã®è¡ã«ã¯ãå人æ
å ±ãæŒæŽ©ããæ§æå¡ã®äžèЧã瀺ãããã K (1 ≤ K ≤ N) ã¯æŒæŽ©ããæ§æå¡ã®äººæ°ã衚ããæ®ãã®æŽæ°ã¯æŒæŽ©ããæ§æå¡ã®çªå·ã衚ãã
</p>
<p>
å
¥åã¯æ£ããäžãããããšä»®å®ããŠãããã€ãŸããããæ§æå¡ãç¥ã£ãŠããå人æ
å ±ã®äžèЧãšããŠãåãæ§æå¡ã®çªå·ã 2 å以äžäžããããããååšããªãæ§æå¡ã®çªå·ãäžããããããšã¯ãªããæŒæŽ©ããæ§æå¡ã®çªå·ã®äžèЧãåæ§ã§ããã
</p>
<p>
N = 0 ã®ãšããå
¥åã¯çµäºããã
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
å人æ
å ±ãæŒæŽ©ãããæ§æå¡ãç¹å®ã§ãããªãã°ããã®æ§æå¡ã®çªå·ãåºåãããç¹å®ã§ããªãå Žå -1 ãåºåããã
</p>
<p>
ç¹å®ã§ããªãå Žåã«ã¯ã次㮠2 ã€ã®ã±ãŒã¹ãããã 1 ã€ã¯ãæµåºãããå¯èœæ§ãããæ§æå¡ã 2 äººä»¥äžæããããå Žåã§ããããã 1 ã€ã¯ãã©ã®æ§æå¡ãæµåºããããšä»®å®ããŠãççŸãçããå Žåã§ãããã©ã¡ãã®å Žåã§ããããªãã®ããã°ã©ã 㯠-1 ãšåºåããªããã°ãªããªãã
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3
2 2 3
1 1
1 1
2 2 3
3
2 2 3
1 3
1 2
1 2
5
3 1 3 4
4 1 3 4 5
2 1 3
2 1 2
0
3 1 3 5
3
2 2 1
1 1
1 2
3 3 2 1
0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div>
<h3>Output for Sample Input</h3>
<div>
<pre>
1
-1
2
-1
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div> |
p01840 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h2>B - 豪éžãšå®
é
䟿</h2>
<h3>Problem Statement</h3>
<p>
倪éåã¯è±ªéžã§äžäººæ®ãããããŠããïŒ
å匷奜ãã®å€ªéåã¯ïŒä»æ¥ãéžå
ã®æžæã§å匷ãããã€ããã§ããïŒ
倪éåã¯ïŒæžæä»¥å€ã®å Žæã§ã¯éäžã§ããªãã®ã§ïŒå匷ã¯å¿
ãæžæã§è¡ãïŒ
</p>
<p>
ãšããããã®æ¥ïŒå€ªéåå®ã®å®
é
䟿ã $N$ ä»¶å±ãïŒ$i$ ($1 \leq i \leq N$) çªç®ã®å®
é
䟿ã®å±ãæå»ã¯ $a_i$ ã§ããïŒ
é
éå¡ãçé¢å
ã§åŸ
ãããã®ã¯å¿èŠããã®ã§ïŒå€ªéåã¯å®
é
䟿ã®å±ãæå»ã«ã¯çé¢ã«ããããšã«ããïŒ
豪éžã¯åºãã®ã§ïŒæžæãšçé¢éã®ç§»åã«ã¯çé $M$ ã®æéããããïŒ
</p>
<p>
äžæ¹ã§ïŒå€ªéåã¯ã§ããã ãé·ãæéå匷ããããšæã£ãŠããïŒ
æå» $0$ ããæå» $T$ ãŸã§ã§ïŒå€ªéåãæžæã§å匷ã§ããæéã®æå€§å€ãæ±ããïŒ
</p>
<p>
ãªãïŒå€ªéåã¯æå» $0$ ã«ã¯æžæã«ããŠïŒæå» $M$ ããæ©ãå®
é
䟿ãå±ãããšã¯ãªãïŒæå» $T$ ããé
ãå®
é
䟿ãå±ãããšããªãïŒ
ãŸãïŒå€ªéåãå®
é
䟿ãåãåãã®ã«ãããæéã¯ç¡èŠã§ããïŒ
</p>
<h3>Input</h3>
<p>
åããŒã¿ã»ãã㯠2 è¡ãããªãïŒ
1 è¡ç®ã¯ç©ºçœã§åºåããã 3 ã€ã®æŽæ° $N, M, T$ ãããªãïŒ
ãããã®æŽæ°ã¯ïŒ$1 \leq N \leq 100$, $1 \leq M \leq 10{,}000$, $1 \leq T \leq 10{,}000$ ãæºããïŒ
2 è¡ç®ã¯ç©ºçœã§åºåããã $N$ åã®æŽæ° $a_1, a_2, \dots, a_N$ ãããªãïŒ
å $a_i$ 㯠$M \leq a_i \leq T$ ãæºããïŒãŸã $a_i < a_{ i + 1 }$ ($1 \leq i < N$) ã§ããïŒ
</p>
<h3>Output</h3>
<p>
倪éåãå匷ã§ããæéã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã«åºåããïŒ
</p>
<h3>Sample Input 1</h3>
<pre>1 1 5
3</pre>
<h3>Output for the Sample Input 1</h3>
<pre>3</pre>
<h3>Sample Input 2</h3>
<pre>2 1 10
2 7</pre>
<h3>Output for the Sample Input 2</h3>
<pre>6</pre>
<h3>Sample Input 3</h3>
<pre>2 4 10
6 8</pre>
<h3>Output for the Sample Input 3</h3>
<pre>2</pre> |
p00752 |
<!-- begin en only -->
<h1><font color="#000000">Problem G:</font> Laser Beam Reflections</h1>
<!-- end en only -->
<!-- begin en only -->
<p>
A laser beam generator, a target object and some mirrors are
placed on a plane.
The mirrors stand upright on the plane,
and both sides of the mirrors are flat and can reflect beams.
To point the beam at the target,
you may set the beam to several directions because of different reflections.
Your job is to find the shortest beam path
from the generator to the target and answer the length of the path.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Figure G-1 shows examples of possible beam paths,
where the bold line represents the shortest one.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_G-0" align="center"><br><br>
<!-- begin en only -->
Figure G-1: Examples of possible paths
<!-- end en only -->
</center>
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of a number of datasets. The end of the input is indicated by a line containing a zero.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Each dataset is formatted as follows.
Each value in the dataset except <i>n</i> is an integer no less than 0 and no more than 100.
</p>
<!-- end en only -->
<p></p>
<blockquote>
<i>n</i><br>
<i>PX</i><sub>1</sub> <i>PY</i><sub>1</sub> <i>QX</i><sub>1</sub> <i>QY</i><sub>1</sub><br>
...<br>
<i>PX<sub><i>n</i></sub></i> <i>PY<sub><i>n</i></sub></i> <i>QX<sub><i>n</i></sub></i> <i>QY<sub><i>n</i></sub></i><br>
<i>TX</i> <i>TY</i><br>
<i>LX</i> <i>LY</i><br>
</blockquote>
<p></p>
<!-- begin en only -->
<p>
The first line of a dataset contains an integer <i>n</i> (1 ≤ <i>n</i> ≤ 5),
representing the number of mirrors.
The following <i>n</i> lines list the arrangement of mirrors on the plane.
The coordinates
(<i>PX<sub>i</sub></i>, <i>PY<sub>i</sub></i>) and
(<i>QX<sub>i</sub></i>, <i>QY<sub>i</sub></i>) represent
the positions of both ends of the mirror.
Mirrors are apart from each other.
The last two lines represent the target position (<i>TX</i>, <i>TY</i>)
and the position of the beam generator (<i>LX</i>, <i>LY</i>).
The positions of the target and the generator are apart from each other,
and these positions are also apart from mirrors.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The sizes of the target object and the beam generator are small enough to be ignored.
You can also ignore the thicknesses of mirrors.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
In addition, you can assume the following conditions on the given datasets.
<ul>
<li>There is at least one possible path from the beam generator to the target.
</li>
<li>The number of reflections along the shortest path is less than 6.
</li>
<li>
The shortest path does not cross or touch a plane containing a mirror
surface at any points within 0.001 unit distance from either end of the mirror.
</li>
<li>
Even if the beam could arbitrarily select reflection or passage
when it reaches each plane containing a mirror surface
at a point within 0.001 unit distance from one of the mirror ends,
any paths from the generator to the target would not be
shorter than the shortest path.
</li>
<li>
When the beam is shot from the generator in an arbitrary direction and
it reflects on a mirror or passes the mirror within 0.001 unit distance from the mirror,
the angle <i>θ</i> formed by the beam and the mirror
satisfies sin(<i>θ</i>) > 0.1,
until the beam reaches the 6th reflection point (exclusive).
</li>
</ul>
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Figure G-1 corresponds to the first dataset of the Sample Input below.
Figure G-2 shows the shortest paths for the subsequent datasets of the Sample Input.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_G-2" align="center"><br><br>
<!-- begin en only -->
Figure G-2: Examples of the shortest paths
<!-- end en only -->
</center>
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single line containing the length of the shortest path from
the beam generator to the target.
The value should not have an error greater than 0.001.
No extra characters should appear in the output.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809
</pre>
|
p02295 | <H1>Cross Point</H1>
<br/>
<p>
For given two segments <var>s1</var> and <var>s2</var>, print the coordinate of the cross point of them.
</p>
<p>
<var>s1</var> is formed by end points <var>p0</var> and <var>p1</var>, and
<var>s2</var> is formed by end points <var>p2</var> and <var>p3</var>.
</p>
<H2>Input</H2>
<p>
The entire input looks like:
</p>
<pre>
<var>q</var> (the number of queries)
1st query
2nd query
...
<var>q</var>th query
</pre>
<p>
Each query consists of integer coordinates of end points of <var>s1</var> and <var>s2</var> in the following format:
</p>
<pre>
<var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>x<sub>p2</sub></var> <var>y<sub>p2</sub></var> <var>x<sub>p3</sub></var> <var>y<sub>p3</sub></var>
</pre>
<H2>Output</H2>
<p>
For each query, print the coordinate of the cross point. The output values should be in a decimal fraction with an error less than 0.00000001.
</p>
<H2>Constraints</H2>
<ul>
<li>
1 ≤ <i>q</i> ≤ 1000
</li>
<li>
-10000 ≤ x<sub>p<sub>i</sub></sub>, y<sub>p<sub>i</sub></sub> ≤ 10000
</li>
<li>
<var>p0 ≠ p1</var> and
<var>p2 ≠ p3</var>.
</li>
<li>
The given segments have a cross point and are not in parallel.
</li>
</ul>
<H2>Sample Input</H2>
<pre>
3
0 0 2 0 1 1 1 -1
0 0 1 1 0 1 1 0
0 0 1 1 1 0 0 1
</pre>
<H2>Sample Output</H2>
<pre>
1.0000000000 0.0000000000
0.5000000000 0.5000000000
0.5000000000 0.5000000000
</pre>
<br/>
|
p00302 |
<h1>ããã·ã³é€šãã©ãœã³éš</h1>
<p>
ã¢ã€ã
åžç«ããã·ã³é€šã¯ãææŠäž¡éãæ²ããæŽå²ããåŠæ ¡ã§ããããã·ã³é€šãã©ãœã³éšã¯ç±è¡æå°ã§æåã§ãããæ±ºããããç·Žç¿æéã®éãåšåã³ãŒã¹ãã²ãããèµ°ããšãã鬌ã®ç¹èšãè¡ããŸãããã®ãšããè±æ°Žçç¶ã§åããéšå¡ãããªãããã«ãéšå¡ã®å®åã«åãããŠé£²ã¿ç©ãæäŸãã絊氎æãèšããŠããŸãã
</p>
<p>
åéšå¡ãïŒåäœæéãããã«èµ°ããè·é¢(ããŒã¹)ã¯éšå¡ããšã«æ±ºãŸã£ãŠãããå
šå¡ãïŒåäœæéããšã«å¿
ã絊氎ã§ããããã«çµŠæ°Žæãèšããããã§ç¹èšãè¡ããŸããéšå¡ã¯ 1 åäœæéã§çãã絊氎æã§å¿
ãäžèº«ã®å
¥ã£ã容åšãåãããã®ãŸãŸèµ°ãç¶ããŸããããã«ã次ã®ïŒåäœæéã§çãã絊氎æã§ç©ºã®å®¹åšã眮ããäžèº«ã®å
¥ã£ã容åšãåã£ãŠèµ°ãç¶ãããšããããšãç¹°ãè¿ããŸãããŸãã空ã®å®¹åšã¯ã眮ããŠãã 1 åäœæéã®æç¹ã§é£²æãè£å
ããããã®ç¬éãã誰ã«ã§ãæäŸã§ããããã«ãªããŸãã
</p>
<p>
éšå¡ã¯å
šå¡åãå°ç¹ããã容åšãæããã«åºçºããŸããæ±ºããããç·Žç¿æéãŸã§èµ°ããšç·Žç¿ãçµããŸã(ãã®ãšãã絊氎ãå¿
èŠã§ã)ãè€æ°ã®éšå¡ãåæã«åã絊氎æã«å°çããå Žåãããã®ã§ãäžãæã®çµŠæ°Žæã§åæã«è€æ°ã®å®¹åšãå¿
èŠã«ãªãããšããããŸãã
</p>
<p>
鬌ã®ç¹èšãå®å
šã«è¡ãããã«ãæäœããã€ã®çµŠæ°Žå®¹åšãå¿
èŠã«ãªããæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>R</var> <var>T</var>
<var>p<sub>1</sub></var>
<var>p<sub>2</sub></var>
:
<var>p<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«éšå¡ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100)ãåšåã³ãŒã¹ã®é·ã <var>R</var> (1 ≤ <var>R</var> ≤ 1000)ãæ±ºããããç·Žç¿æé <var>T</var> (1 ≤ <var>T</var> ≤ 1000) ãäžãããããç¶ã <var>N</var> è¡ã«ãéšå¡ <var>i</var> ã®ããŒã¹ <var>p<sub>i</sub></var> (1 ≤ <var>p<sub>i</sub></var> ≤ 1000) ãäžããããã
</p>
<h2>åºå</h2>
<p>
æäœããã€ã®çµŠæ°Žå®¹åšãå¿
èŠã«ãªãããïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸïŒ </h2>
<pre>
1 10 20
1
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
11
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
2 5 12
1
2
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
8
</pre>
|
p03607 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are playing the following game with Joisino.</p>
<ul>
<li>Initially, you have a blank sheet of paper.</li>
<li>Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated <var>N</var> times.</li>
<li>Then, you are asked a question: How many numbers are written on the sheet now?</li>
</ul>
<p>The numbers announced by Joisino are given as <var>A_1, ... ,A_N</var> in the order she announces them. How many numbers will be written on the sheet at the end of the game?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€Nâ€100000</var></li>
<li><var>1â€A_iâ€1000000000(=10^9)</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var>
<var>:</var>
<var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print how many numbers will be written on the sheet at the end of the game.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
6
2
6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>The game proceeds as follows:</p>
<ul>
<li>
<p><var>6</var> is not written on the sheet, so write <var>6</var>.</p>
</li>
<li>
<p><var>2</var> is not written on the sheet, so write <var>2</var>.</p>
</li>
<li>
<p><var>6</var> is written on the sheet, so erase <var>6</var>.</p>
</li>
</ul>
<p>Thus, the sheet contains only <var>2</var> in the end. The answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
2
5
5
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>It is possible that no number is written on the sheet in the end.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
12
22
16
22
18
12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre></section>
</div>
</span> |
p02915 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is going to set a <var>3</var>-character password.</p>
<p>How many possible passwords are there if each of its characters must be a digit between <var>1</var> and <var>N</var> (inclusive)?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 9</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible passwords.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>There are eight possible passwords: <code>111</code>, <code>112</code>, <code>121</code>, <code>122</code>, <code>211</code>, <code>212</code>, <code>221</code>, and <code>222</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There is only one possible password if you can only use one kind of character.</p></section>
</div>
</span> |
p00928 |
<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 E:
Automotive Navigation
</h2>
<p>
The International Commission for Perfect Cars (ICPC) has constructed a city scale test course for advanced driver assistance systems. Your company, namely the Automotive Control Machines (ACM), is appointed by ICPC to make test runs on the course.
</p>
<p>
The test course consists of streets, each running straight either east-west or north-south. No streets of the test course have dead ends, that is, at each end of a street, it meets another one. There are no grade separated streets either, and so if a pair of orthogonal streets run through the same geographical location, they always meet at a crossing or a junction, where a car can turn from one to the other. No U-turns are allowed on the test course and a car never moves outside of the streets.
</p>
<p>
Oops! You have just received an error report telling that the GPS (Global Positioning System) unit of a car running on the test course was broken and the driver got lost. Fortunately, however, the odometer and the electronic compass of the car are still alive.
</p>
<p>
You are requested to write a program to estimate the current location of the car from available information. You have the car's location just before its GPS unit was broken. Also, you can remotely measure the running distance and the direction of the car once every time unit. The measured direction of the car is one of north, east, south, and west. If you measure the direction of the car while it is making a turn, the measurement result can be the direction either before or after the turn. You can assume that the width of each street is zero.
</p>
<p>
The car's direction when the GPS unit was broken is not known. You should consider every possible direction consistent with the street on which the car was running at that time.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains four integers $n$, $x_0$, $y_0$, $t$, which are the number of streets ($4 \leq n \leq 50$), $x$- and $y$-coordinates of the car at time zero, when the GPS unit was broken, and the current time ($1 \leq t \leq 100$), respectively. $(x_0, y_0)$ is of course on some street. This is followed by $n$ lines, each containing four integers $x_s$, $y_s$, $x_e$, $y_e$ describing a street from $(x_s, y_s)$ to $(x_e, y_e)$ where $(x_s, y_s) \ne (x_e, y_e)$. Since each street runs either east-west or north-south, $x_s = x_e$ or $y_s = y_e$ is also satisfied. You can assume that no two parallel streets overlap or meet. In this coordinate system, the $x$- and $y$-axes point east and north, respectively. Each input coordinate is non-negative and at most 50. Each of the remaining $t$ lines contains an integer $d_i$ ($1 \leq d_i \leq 10$), specifying the measured running distance from time $i â 1$ to $i$, and a letter $c_i$, denoting the measured direction of the car at time $i$ and being either <span>N</span> for north, <span>E</span> for east, <span>W</span> for west, or <span>S</span> for south.
</p>
<h3>Output</h3>
<p>
Output all the possible current locations of the car that are consistent with the measurements. If they are $(x_1, y_1),(x_2, y_2), . . . ,(x_p, y_p)$ in the lexicographic order, that is, $x_i < x_j$ or $x_i = x_j$ and $y_i < y_j$ if $1 \leq i < j \leq p$, output the following:<br>
<br>
$x_1$ $y_1$<br>
$x_2$ $y_2$<br>
.<br>
.<br>
.<br>
$x_p$ $y_p$<br>
<br>
Each output line should consist of two integers separated by a space.
</p>
<p>
You can assume that at least one location on a street is consistent with the measurements
</p>
<h3>Sample Input 1</h3>
<pre>4 2 1 1
1 1 1 2
2 2 2 1
2 2 1 2
1 1 2 1
9 N</pre>
<h3>Sample Output 1</h3>
<pre>1 1
2 2</pre>
<h3>Sample Input 2</h3>
<pre>6 0 0 2
0 0 2 0
0 1 2 1
0 2 2 2
0 0 0 2
1 0 1 2
2 0 2 2
2 E
7 N</pre>
<h3>Sample Output 2</h3>
<pre>0 1
1 0
1 2
2 1</pre>
<h3>Sample Input 3</h3>
<pre>7 10 0 1
5 0 10 0
8 5 15 5
5 10 15 10
5 0 5 10
8 5 8 10
10 0 10 10
15 5 15 10
10 N</pre>
<h3>Sample Output 3</h3>
<pre>5 5
8 8
10 10
15 5</pre> |
p03257 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>.</p>
<p>Construct any one <var>N</var>-by-<var>N</var> matrix <var>a</var> that satisfies the conditions below. It can be proved that a solution always exists under the constraints of this problem.</p>
<ul>
<li><var>1 \leq a_{i,j} \leq 10^{15}</var></li>
<li><var>a_{i,j}</var> are pairwise distinct integers.</li>
<li>There exists a positive integer <var>m</var> such that the following holds: Let <var>x</var> and <var>y</var> be two elements of the matrix that are vertically or horizontally adjacent. Then, <var>{\rm max}(x,y)</var> <var>{\rm mod}</var> <var>{\rm min}(x,y)</var> is always <var>m</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 500</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 your solution in the following format:</p>
<pre><var>a_{1,1}</var> <var>...</var> <var>a_{1,N}</var>
<var>:</var>
<var>a_{N,1}</var> <var>...</var> <var>a_{N,N}</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4 7
23 10
</pre>
<ul>
<li>For any two elements <var>x</var> and <var>y</var> that are vertically or horizontally adjacent, <var>{\rm max}(x,y)</var> <var>{\rm mod}</var> <var>{\rm min}(x,y)</var> is always <var>3</var>.</li>
</ul></section>
</div>
</span> |
p01790 |
<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 A
Balanced Paths</h2>
<p>
You are given an undirected tree with $n$ nodes. The nodes are numbered 1 through $n$. Each node is labeled with either '(' or ')'. Let $l[u \rightarrow v]$ denote the string obtained by concatenating the labels of the nodes on the simple path from $u$ to $v$. (Note that the simple path between two nodes is uniquely determined on a tree.) A <i>balanced</i> string is defined as follows:
</p>
<ul>
<li> The empty string is balanced.</li>
<li> For any balanced string $s$, the string "(" $s$ ")" is balanced.</li>
<li> For any balanced strings $s$ and $t$, the string $st$ (the concatenation of $s$ and $t$) is balanced.</li>
<li> Any other string is NOT balanced.</li>
</ul>
<p>
Calculate the number of the ordered pairs of the nodes ($u$, $v$) such that $l[u \rightarrow v]$ is balanced.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The input starts with an integer $n (2 \leq n \leq 10^5)$, which is the number of nodes of the tree. The next line contains a string of length $n$, each character of which is either '(' or ')'. The $x$-th character of the string represents the label of the node $x$ of the tree. Each of the following $n - 1$ lines contains two integers $a_i$ and $b_i$ $(1 \leq a_i, b_i \leq n)$, which represents that the node $a_i$ and the node $b_i$ are connected by an edge. The given graph is guaranteed to be a tree.
</p>
<h3>Output</h3>
<p>
Display a line containing the number of the ordered pairs ($u$, $v$) such that $l[u \rightarrow v]$ is balanced.
</p>
<h3>Sample Input 1</h3>
<pre>2
()
1 2</pre>
<h3>Output for the Sample Input 1</h3>
<pre>1</pre>
<h3>Sample Input 2</h3>
<pre>4
(())
1 2
2 3
3 4</pre>
<h3>Output for the Sample Input 2</h3>
<pre>2</pre>
<h3>Sample Input 3</h3>
<pre>5
()())
1 2
2 3
2 4
1 5</pre>
<h3>Output for the Sample Input 3</h3>
<pre>4</pre>
|
p00882 |
<H1><font color="#000">Problem I:</font> Hobby on Rails</H1>
<p>
ICPC (International Connecting Points Company) starts to sell a new railway toy. It consists
of a toy tramcar and many rail units on square frames of the same size. There are four types
of rail units, namely, straight (S), curve (C), left-switch (L) and right-switch (R) as shown in
Figure 9. A switch has three ends, namely, branch/merge-end (B/M-end), straight-end (S-end)
and curve-end (C-end).
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby1">
</center>
<p>
A switch is either in "through" or "branching" state. When the tramcar comes from B/M-end,
and if the switch is in the through-state, the tramcar goes through to S-end and the state changes
to branching; if the switch is in the branching-state, it branches toward C-end and the state
changes to through. When the tramcar comes from S-end or C-end, it goes out from B/M-end
regardless of the state. The state does not change in this case.
</p>
<p>
Kids are given rail units of various types that fill a rectangle area of <i>w</i> × <i>h</i>, as shown in Fig-
ure 10(a). Rail units meeting at an edge of adjacent two frames are automatically connected.
Each rail unit may be independently rotated around the center of its frame by multiples of 90
degrees in order to change the connection of rail units, but its position cannot be changed.
</p>
<p>
Kids should make "valid" layouts by rotating each rail unit, such as getting Figure 10(b) from
Figure 10(a). A layout is valid when all rails at three ends of every switch are directly or
indirectly connected to an end of another switch or itself. A layout in Figure 10(c) is invalid as
well as Figure 10(a). Invalid layouts are frowned upon.
</p>
<p>
When a tramcar runs in a valid layout, it will eventually begin to repeat the same route forever.
That is, we will eventually find the tramcar periodically comes to the same running condition,
which is a triple of the tramcar position in the rectangle area, its direction, and the set of the
states of all the switches.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby2">
</center>
<p>
A periodical route is a sequence of rail units on which the tramcar starts from a rail unit with
a running condition and returns to the same rail unit with the same running condition for the first time. A periodical route through a switch or switches is called the "fun route", since kids
like the rattling sound the tramcar makes when it passes through a switch. The tramcar takes
the same unit time to go through a rail unit, not depending on the types of the unit or the
tramcar directions. After the tramcar starts on a rail unit on a âfun routeâ, it will come back to
the same unit with the same running condition, sooner or later. The fun time <i>T</i> of a fun route
is the number of time units that the tramcar takes for going around the route.
</p>
<p>
Of course, kids better enjoy layouts with longer fun time. Given a variety of rail units placed
on a rectangular area, your job is to rotate the given rail units appropriately and to find the fun
route with the longest fun time in the valid layouts.
</p>
<p>
For example, there is a fun route in Figure 10(b). Its fun time is 24. Let the toy tramcar start
from B/M-end at (1, 2) toward (1, 3) and the states of all the switches are the through-states. It
goes through (1, 3), (1, 4), (1, 5), (2, 5), (2, 4), (1, 4), (1, 3), (1, 2), (1, 1), (2, 1), (2, 2) and (1, 2).
Here, the tramcar goes through (1, 2) with the same position and the same direction, but with
the different states of the switches. Then the tramcar goes through (1, 3), (1, 4), (2, 4), (2, 5),
(1, 5), (1, 4), (1, 3), (1, 2), (2, 2), (2, 1), (1, 1) and (1, 2). Here, the tramcar goes through (1, 2)
again, but with the same switch states as the initial ones. Counting the rail units the tramcar
visited, the tramcar should have run 24 units of time after its start, and thus the fun time is 24.
</p>
<p>
There may be many valid layouts with the given rail units. For example, a valid layout containing
a fun route with the fun time 120 is shown in Figure 11(a). Another valid layout containing a
fun route with the fun time 148 derived from that in Figure 11(a) is shown in Figure 11(b). The
four rail units whose rotations are changed from Figure 11(a) are indicated by the thick lines.
</p>
<p>
A valid layout depicted in Figure 12(a) contains two fun routes, where one consists of the rail
units (1, 1), (2, 1), (3, 1), (4, 1), (4, 2), (3, 2), (2, 2), (1, 2) with <i>T</i> = 8, and the other consists of
all the remaining rail units with <i>T</i> = 18.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby3">
</center>
<p>
Another valid layout depicted in Figure 12(b) has two fun routes whose fun times are <i>T</i> = 12
and <i>T</i> = 20. The layout in Figure 12(a) is different from that in Figure 12(b) at the eight rail
units rotated by multiples of 90 degrees. There are other valid layouts with some rotations of
rail units but there is no fun route with the fun time longer than 20, so that the longest fun
time for this example (Figure 12) is 20.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby4">
</center>
<p>
Note that there may be simple cyclic routes that do not go through any switches in a valid
layout, which are not counted as the fun routes. In Figure 13, there are two fun routes and one
simple cyclic route. Their fun times are 12 and 14, respectively. The required time for going
around the simple cyclic route is 20 that is greater than fun times of the fun routes. However,
the longest fun time is still 14.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hobby5">
</center>
<H2>Input</H2>
<p>
The input consists of multiple datasets, followed by a line containing two zeros separated by a
space. Each dataset has the following format.
</p>
<p>
<i>w h</i><br>
<i>a</i><sub>11</sub> ... <i>a</i><sub>1<i>w</i></sub><br>
...<br>
<i>a</i><sub><i>h</i>1</sub> ... <i>a</i><sub><i>hw</i></sub><br>
</p>
<p>
<i>w</i> is the number of the rail units in a row, and <i>h</i> is the number of those in a column. <i>a<sub>ij</sub></i>
(1 ≤ <i>i</i> ≤ <i>h</i>, 1 ≤ <i>j</i> ≤ <i>w</i>) is one of uppercase letters '<span>S</span>', '<span>C</span>', '<span>L</span>' and '<span>R</span>', which indicate the types
of the rail unit at (<i>i</i>, <i>j</i>) position, i.e., straight, curve, left-switch and right-switch, respectively.
Items in a line are separated by a space. You can assume that 2 ≤ <i>w</i> ≤ 6, 2 ≤ <i>h</i> ≤ 6 and the
sum of the numbers of left-switches and right-switches is greater than or equal to 2 and less
than or equal to 6.
</p>
<H2>Output</H2>
<p>
For each dataset, an integer should be printed that indicates the longest fun time of all the fun
routes in all the valid layouts with the given rail units. When there is no valid layout according
to the given rail units, a zero should be printed.
</p>
<H2>Sample Input</H2>
<pre>
5 2
C L S R C
C C S C C
6 4
C C C C C C
S L R R C S
S S S L C S
C C C C C C
6 6
C L S S S C
C C C S S C
C C C S S C
C L C S S C
C C L S S C
C S L S S C
6 6
C S S S S C
S C S L C S
S C S R C S
S C L S C S
S C R S C S
C S S S S C
4 4
S C C S
S C L S
S L C S
C C C C
6 4
C R S S L C
C R L R L C
C S C C S C
C S S S S C
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
24
20
148
14
0
178
</pre>
|
p02016 | <h2>B: åå (Twins)</h2>
<p>ãšããååã¯ãèªåãã¡ã®ã©ã¡ããå
ã§ã©ã¡ããåŒããããŸãç¥ãããŠããªãããšã«è
¹ãç«ãŠãã</p>
<p>"ani" ãšå
¥åãããã "square1001"ã"otouto" ãšå
¥åãããã "e869120" ãšåºåããããã°ã©ã ãäœããªããã</p>
<h3>å
¥å</h3>
<p>å
¥åãšã㊠"ani" ãŸã㯠"otouto" ãšããæååã®ã©ã¡ãããäžããããŸãã</p>
<h3>åºå</h3>
<p>"e869120" ãŸã㯠"square1001" ããå顿ã®éãã«åºåããŠãã ãããæåŸã®æ¹è¡ãå¿ããªãããã«ããŸãããã</p>
<h3>å
¥åäŸ1</h3>
<pre>
ani
</pre>
<h3>åºåäŸ1</h3>
<pre>
square1001
</pre>
<h3>å
¥åäŸ2</h3>
<pre>
otouto
</pre>
<h3>åºåäŸ2</h3>
<pre>
e869120
</pre>
|
p02446 | <h1>Unique</h1>
<p>
For a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, eliminate all equivalent elements.
</p>
<h2>Input</h2>
<p>
A sequence is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ,..., \; a_{n-1}$
</pre>
<h2>Output</h2>
<p>
Print the sequence after eliminating equivalent elements in a line. Separate adjacency elements by a space character.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 100,000$</li>
<li>$-1000,000,000 \leq a_i \leq 1,000,000,000$</li>
<li>$a_0 \leq a_1 \leq ... \leq a_{n-1}$
</ul>
<h2>Sample Input 1</h2>
<pre>
4
1 2 2 4
</pre>
<h2>Sample Output 1</h2>
<pre>
1 2 4
</pre>
|
p00181 |
<H1>æ¬æ£</H1>
<p>
倪éåã¯ãšããå°èª¬ã«ã¯ãŸã£ãŠããŸãããã®å°èª¬ã¯å
šéšã§ <var>n</var> å·»ãããåå·»ã§æ¬ã®åããç°ãªããŸãã倪éåã¯ãã®å°èª¬ã倧倿°ã«å
¥ã£ãã®ã§ããã®å°èª¬å°çšã®æ¬æ£ãè²·ãããšæã£ãŠããŸããããããéšå±ã«å€§ããªæ¬æ£ã眮ããšããªãçããªã£ãŠããŸãã®ã§ãåºæ¥ãã ãæ¬æ£ã®å¹
ãå°ãããªãããã«å·¥å€«ããªããã°ãªããŸãããåºãã倩äºã®é«ããæž¬ã£ããšãããã©ããã <var>m</var> æ®µã®æ¬æ£ãªã眮ããããšãåãããŸãããããã§ãå°èª¬ <var>n</var> å·»ãã©ã®ããã«åããã° <var>m</var> æ®µã®æ¬æ£ã®å¹
ãæå°ã«åºæ¥ãã§ãããã?
倪éåã«ã¯ãã ããããããåæ®µã«çŽããå°èª¬ã¯å·»ã®çªå·é ã«äžŠãã§ããªããã°ãªããŸããã
</p>
<p>
æ¬æ£ã®æ®µæ°ãå°èª¬ã®å·»æ°ã忬ã®åããå
¥åãšããŠãå
šå·»ã 1å·»ããé ã«åããããšãã§ããæ¬æ£ã®äžã§å¹
ãæå°ãšãªããã®ã®å¹
ãæ±ããããã°ã©ã ãäœæããŠãã ããããã ããæ¬æ£ã®æ ã®å€§ããã¯å¹
ã«å«ããªãããšãšããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck200809">
</center>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>m</var> <var>n</var>
<var>w<sub>1</sub></var>
<var>w<sub>2</sub></var>
:
<var>w<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«éšå±ã«çœ®ãããšãã§ããæ¬æ£ã®æ®µæ° <var>m</var> (1 ≤ <var>m</var> ≤ 20)ã å°èª¬ã®å·»æ° <var>n</var> (1 ≤ <var>n</var> ≤ 100) ãäžããããŸããç¶ã <var>n</var> è¡ã«ç¬¬ <var>i</var> å·»ã®æ¬ã®åããè¡šãæŽæ° <var>w<sub>i</sub></var> (1 ≤ <var>w<sub>i</sub></var> ≤ 1000000) ãäžããããŸãã
</p>
<p>
ãã ããæ¬æ£ã®å¹
㯠1500000 ãè¶
ããªããã®ãšããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«æå°ãšãªãæ¬æ£ã®å¹
ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
3 9
500
300
800
200
100
600
900
700
400
4 3
1000
1000
1000
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1800
1000
</pre>
|
p00494 |
<H1>JJOOII (JJOOII) </H1>
<p>
JOI (æ¥æ¬æ
å ±ãªãªã³ããã¯) ã®æ¬éžã«åããŠããã°ã©ãã³ã°ã®ç·Žç¿ãããŠããããªãã¯ïŒä»å¹ŽåºŠã®JOI ã®äºéžã®åé¡ã«ã¯æ°å€ãæ±ãåé¡ã°ãããåºé¡ããïŒæååãæ±ãåé¡ããªãã£ãããšã«æ°ãã€ããïŒããã§ããªãã¯ïŒãã£ããæååã®åé¡ã«åŒ·ããªã£ãŠã©ã€ãã«ãã¡ã«å·®ãã€ããããšã«ããïŒ
</p>
<p>
JOI ã®éå»åãçºããŠãããšïŒJ, O, I ã®3 çš®é¡ã®æåãããªãæååã«æ
£ããŠããå¿
èŠããããããªããšãããã£ãïŒããã§ïŒãã®ãããªæååã«ã€ããŠèãããïŒããªãã¯ãäžããããæååãJOI ãšããéšåæååããã€ãã©ãããçããããšããåé¡ãæãã€ãããã®ã®ïŒããã¯ããã«è§£ããŠããŸã£ãïŒãã£ãšã¬ãã«ã®é«ãåé¡ãè§£ãããããªãã¯ïŒä»¥äžã®ãããªåé¡ãäœã£ãïŒ
</p>
<p>
æåå<i>t</i> ãæåå<i>s</i> ã®<b>éšåæåå</b>ã§ãããšã¯ïŒ<i>t</i> ã®å
é ããã³æ«å°Ÿã«äœæåã(0 æåã§ããã) ãä»ãè¶³ããš<i>s</i> ã«ãªãããšã§ããïŒããšãã°ïŒJJOOII ã¯OJJOOIIOJOI ã®éšåæååã§ããïŒäžæ¹ïŒJOI ã¯JOOI ã®éšåæååã§ã¯ãªãïŒ
</p>
<p>
ãŸãïŒ0 以äžã®æŽæ°<i>k</i> ã«å¯ŸãïŒ<b>ã¬ãã«<i>k</i> ã®JOI å</b>ãšã¯ïŒ<i>k</i> åã®æåJïŒ<i>k</i> åã®æåOïŒ<i>k</i> åã®æåI ããã®é ã«äžŠã¹ãæååã®ããšã§ãããšããïŒããšãã°ïŒJJOOII ã¯ã¬ãã«2 ã®JOI åã§ããïŒäžããããæååã®éšåæååã§ããJOI åã®ãã¡ïŒã¬ãã«ãæå€§ã®ãã®ãæ±ãããïŒ
</p>
<h2>課é¡</h2>
<p>
J, O, I ã®3 çš®é¡ã®æåãããªãé·ã<i>N</i> ã®æåå<i>S</i> ãäžãããããšãïŒã¬ãã«<i>k</i> ã®JOI åã<i>S</i> ã®éšåæååã§ãããããªæå€§ã®<i>k</i> ã®å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å¶é</h2>
<p>
1 ≤ <i>N</i> ≤ 1000000 (= 10<sup>6</sup>) <i>S</i> ã®é·ã
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯J, O, I ã®3 çš®é¡ã®æåãããªãæåå<i>S</i> ãæžãããŠããïŒ</li>
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒã¬ãã«<i>k</i> ã®JOI åã<i>S</i> ã®éšåæååã§ãããããªæå€§ã®<i>k</i> ã®å€ãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ
</p>
<h2>æ¡ç¹åºæº</h2>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®20%åã«ã€ããŠã¯ïŒ<i>N</i> ≤ 100 ãæºããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
OJJOOIIOJOI
</pre>
<h3>åºåäŸ 1</h3>
<pre>
2
</pre>
<p>
OJJOOIIOJOI ã¯ã¬ãã«2 ã®JOI åã§ããJJOOII ãéšåæååãšããŠå«ãã§ããïŒã¬ãã«3 以äžã®JOIåã¯éšåæååãšããŠå«ãŸãªãïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
IJJIIJJJ
</pre>
<h3>åºåäŸ 2</h3>
<pre>
0
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
JOIJOIJOIJOIJOI
</pre>
<h3>åºåäŸ 3</h3>
<pre>
1
</pre>
<h3>å
¥åäŸ 4</h3>
<pre>
OOJJJJJJJOOOOIIIII
</pre>
<h3>åºåäŸ 4</h3>
<pre>
4
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02153 | <h1>Problem E: ããã€ãããçãããªãã§</h1>
<h2>Problem</h2>
<p>
ããã€ããã¯ç²çŸ
ãããã€ã®äºã§ãã<br />
</p>
<p>
ããã€ããã¯ãœãã(èµ·åºããäº)éç«¯ãæ Œåç¶ã®åºç»ã«åºåãããŠããã¹ããŒãžã«éã蟌ããããŸããããã®ã¹ããŒãžã«ã¯ããã äžã€ã®åºå£ããããŸãã
åºç»ã¯éãå¡ãŸãã¯ç匟ã®ããããã§ãããããã€ããã¯äžäžå·Šå³ã«ç§»åããããšã§ãéãŸãã¯ç匟ã®åºç»ã«äŸµå
¥ããããšãã§ããŸãã
æãã«ã¯ç§»åã§ããŸããããŸããå¡ã®åºç»ã¯éãããšãã§ããŸãããã¹ããŒãžã®å€ã«ãéã®åºç»ãç¡éã«åºãã£ãŠããŸããäºã®å€©æµã§ããã¯ããããçºãéãäºã¯ã§ããŸããã
</p>
<p>
ããã€ããã¯ãã£ããšåž°å®
ããŠãã(ç¡ç ããäº)ãè¡ãããã®ã§ããã®ã¹ããŒãžã®åºå£ã«åããããšæããŸããã
</p>
<p>
ããã€ã®èµ€å€ç·ãèªåšã«æãäºãã§ããããã€ããã¯ãèªèº«ã®åšå²8åºç»ãåæã«éã«å€ããèœåãæã£ãŠããŸãã
ãããããã®8åºç»ãšèªèº«ãããããããã®åºç»ãç匟ã®åºç»ã®å ŽåãèªçããŠããã€ããã¯çäžããããã©ãããæåSNSãã«ã¡ã£ããŒãããåºæ¥ãªããªã£ãŠããŸãã®ã§èœåãçºåããäºãã§ããŸããã
</p>
<p>
<img width=50% src="https://judgeapi.u-aizu.ac.jp/resources/images/3055_E.png" />
</p>
<p>
äŸãå³ç€ºããŸããã€ã©ã¹ããé
眮ãããŠããªãåºç»ãšããã€ãããããåºç»ã¯éã®åºç»ã§ãã
ããã€ããã®åšå²8åºç»ãšã¯ãªã¬ã³ãžè²ã®åºç»ãæããŸããå·Šã®å³ã§ã¯ããã€ããã®åšå²8åºç»ãããã³èªèº«ãããåºç»ã«ç匟ã®åºç»ã¯å«ãŸããŠããªãçºãèœåãçºåã§ããŸãã
ããããå³ã®å³ã§ã¯åšå²8åºç»ãããã³èªèº«ãããåºç»ã®ããããã«ç匟ã®åºç»ãå«ãŸããŠããçºãèœåãçºåããäºãã§ããŸããã
</p>
<p>
ç§»åããã³ã¹ãã¯1åºç»ã®ç§»åããšã«$A$ãèœåãçºåããã³ã¹ãã¯1åããã$B$ã§ããéã«å€ããå¡ãããã®ã³ã¹ãã§ã¯ãªãäºã«æ³šæããŠãã ãããéå§å°ç¹ãšã¹ããŒãžã®åºå£ã¯éã§ãã
éå§å°ç¹ããã¹ããŒãžã®åºå£ã«çããŸã§ã®ç§»åããã³ã¹ããšèœåãçºåããã³ã¹ãã®åèšã®æå°å€ãåºåããŠãã ããããã ããã¹ããŒãžã®åºå£ã«å°éã§ããªãå Žåã¯ä»£ããã«"INF"ãšåºåããŠãã ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$H$ $W$ $A$ $B$
$c_{1,1} \cdots c_{1,W}$
$\vdots$
$c_{H,1} \cdots c_{H,W}$
</pre>
<p>
å
¥åã¯$H+1$è¡ãããªãã<br />
$1$è¡ç®ã«ã¯äžäžã®é·ããè¡šãæŽæ°$H$ãå·Šå³ã®é·ããè¡šãæŽæ°$W$ãç§»åããã³ã¹ããè¡šãæŽæ°$A$ãèœåãçºåããã³ã¹ããè¡šãæŽæ°$B$ããããã空çœåºåãã§äžããããã<br />
$2$è¡ç®ããã®$H$è¡ã«ã¯ãããã€ãããéã蟌ããããã¹ããŒãžã®ååºç»ã«ãããç¶æ
$c_{i,j}$ãäžããããã<br />
$c_{i,j}$ã¯ãããã's','g','.','#','*'ã®ãããããããªããåºç»$(i,j)$ãäžèšã®ãããªç¶æ
ã§ããããšã衚ãã<br />
's' : ãã®åºç»ãéå§å°ç¹ã§ããããšã衚ãã<br />
'g' : ãã®åºç»ãã¹ããŒãžã®åºå£ã§ããããšã衚ãã<br />
'.' : ãã®åºç»ãéã§ããããšã衚ãã<br />
'#' : ãã®åºç»ãå¡ã§ããããšã衚ãã<br />
'*' : ãã®åºç»ãç匟ã§ããããšã衚ãã<br />
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \le H,W,A,B \le 1000$</li>
<li>$3 \le H+W$</li>
<li>$c_{i,j} \in${'s','g','.','#','*'}</li>
<li>'s','g'ã¯ãããã1åãã€åºçŸãã</li>
</ul>
<h2>Output</h2>
<p>éå§å°ç¹ããã¹ããŒãžã®åºå£ã«çããŸã§ã®ç§»åããã³ã¹ããšèœåãçºåããã³ã¹ãã®åèšã®æå°å€ãåºåããŠãã ããããã ããã¹ããŒãžã®åºå£ã«å°éã§ããªãå Žåã¯ä»£ããã«"INF"ãšåºåããŠãã ããã</p>
<h2>Sample input 1</h2>
<pre>
4 4 1 1
g#..
#...
.*..
...s
</pre>
<h2>Sample output 1</h2>
<pre>
7
</pre>
<h2>Sample input 2</h2>
<pre>
4 4 1 1
g#..
#*..
....
...s
</pre>
<h2>Sample output 2</h2>
<pre>
INF
</pre>
<h2>Sample input 3</h2>
<pre>
2 4 1 1
###g
s###
</pre>
<h2>Sample output 3</h2>
<pre>
6
</pre>
<h2>Sample input 4</h2>
<pre>
3 3 1 10
g..
##.
s..
</pre>
<h2>Sample output 4</h2>
<pre>
6
</pre>
<h2>Sample input 5</h2>
<pre>
3 3 10 1
g..
##.
s..
</pre>
<h2>Sample output 5</h2>
<pre>
21
</pre>
|
p01285 |
<H1><font color="#000">Problem C:</font> Find the Point</H1>
<p>
We understand that reading English is a great pain to many of you. So weâll keep this problem statememt
simple. Write a program that reports the point equally distant from a set of lines given as the input. In
case of no solutions or multiple solutions, your program should report as such.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is given in the following format:
</p>
<p>
<i>n</i><br>
<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><br>
<i>x</i><sub>2,1</sub> <i>y</i><sub>2,1</sub> <i>x</i><sub>2,2</sub> <i>y</i><sub>2,2</sub><br>
...<br>
<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><br>
</p>
<p>
<i>n</i> is the number of lines (1 ≤ <i>n</i> ≤ 100); (<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>) denote the different points the <i>i</i>-th line passes through. The lines do not coincide each other. The coordinates are all integers between -10000
and 10000.
</p>
<p>
The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print a line as follows. If there is exactly one point equally distant from all the given lines, print the <i>x</i>- and <i>y</i>-coordinates in this order with a single space between them. If there is more than one such point,
just print "<span>Many</span>" (without quotes). If there is none, just print "<span>None</span>" (without quotes).
</p>
<p>
The coordinates may be printed with any number of digits after the decimal point, but should be accurate
to 10<sup>-4</sup>.
</p>
<H2>Sample Input</H2>
<pre>
2
-35 -35 100 100
-49 49 2000 -2000
4
0 0 0 3
0 0 3 0
0 3 3 3
3 0 3 3
4
0 3 -4 6
3 0 6 -4
2 3 6 6
-1 2 -4 6
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Many
1.5000 1.5000
1.000 1.000
</pre>
|
p03742 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Alice and Brown loves games. Today, they will play the following game.</p>
<p>In this game, there are two piles initially consisting of <var>X</var> and <var>Y</var> stones, respectively.
Alice and Bob alternately perform the following operation, starting from Alice:</p>
<ul>
<li>Take <var>2i</var> stones from one of the piles. Then, throw away <var>i</var> of them, and put the remaining <var>i</var> in the other pile. Here, the integer <var>i</var> <var>(1â€i)</var> can be freely chosen as long as there is a sufficient number of stones in the pile.</li>
</ul>
<p>The player who becomes unable to perform the operation, loses the game.</p>
<p>Given <var>X</var> and <var>Y</var>, determine the winner of the game, assuming that both players play optimally.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 †X, Y †10^{18}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the winner: either <code>Alice</code> or <code>Brown</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Brown
</pre>
<p>Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Alice
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Brown
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>Alice
</pre></section>
</div>
</span> |
p02850 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Given is a tree <var>G</var> with <var>N</var> vertices.
The vertices are numbered <var>1</var> through <var>N</var>, and the <var>i</var>-th edge connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p>
<p>Consider painting the edges in <var>G</var> with some number of colors.
We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.</p>
<p>Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var> 2 \le N \le 10^5</var></li>
<li><var> 1 \le a_i \lt b_i \le N</var></li>
<li>All values in input are integers.</li>
<li>The given graph is a tree.</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>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>\vdots</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <var>N</var> lines.</p>
<p>The first line should contain <var>K</var>, the number of colors used.</p>
<p>The <var>(i+1)</var>-th line <var>(1 \le i \le N-1)</var> should contain <var>c_i</var>, the integer representing the color of the <var>i</var>-th edge, where <var>1 \le c_i \le K</var> must hold.</p>
<p>If there are multiple colorings with the minimum number of colors that satisfy the condition, printing 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 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
1
2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8
1 2
2 3
2 4
2 5
4 7
5 6
6 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
1
2
3
4
1
1
2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2
1 3
1 4
1 5
1 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
1
2
3
4
5
</pre></section>
</div>
</span> |
p03312 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has an integer sequence <var>A</var> of length <var>N</var>.</p>
<p>He will make three cuts in <var>A</var> and divide it into four (non-empty) contiguous subsequences <var>B, C, D</var> and <var>E</var>.
The positions of the cuts can be freely chosen.</p>
<p>Let <var>P,Q,R,S</var> be the sums of the elements in <var>B,C,D,E</var>, respectively.
Snuke is happier when the absolute difference of the maximum and the minimum among <var>P,Q,R,S</var> is smaller.
Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>4 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
3 2 4 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If we divide <var>A</var> as <var>B,C,D,E=(3),(2),(4),(1,2)</var>, then <var>P=3,Q=2,R=4,S=1+2=3</var>.
Here, the maximum and the minimum among <var>P,Q,R,S</var> are <var>4</var> and <var>2</var>, with the absolute difference of <var>2</var>.
We cannot make the absolute difference of the maximum and the minimum less than <var>2</var>, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
10 71 84 33 6 47 23 25 52 64
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>36
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1 2 3 1000000000 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>999999994
</pre></section>
</div>
</span> |
p03365 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> squares lining up in a row, numbered <var>1</var> through <var>N</var> from left to right.
Initially, all squares are white.
We also have <var>N-1</var> painting machines, numbered <var>1</var> through <var>N-1</var>.
When operated, Machine <var>i</var> paints Square <var>i</var> and <var>i+1</var> black.</p>
<p>Snuke will operate these machines one by one.
The order in which he operates them is represented by a permutation of <var>(1, 2, ..., N-1)</var>, <var>P</var>, which means that the <var>i</var>-th operated machine is Machine <var>P_i</var>.</p>
<p>Here, the <em>score</em> of a permutation <var>P</var> is defined as the number of machines that are operated before all the squares are painted black for the first time, when the machines are operated in the order specified by <var>P</var>.
Snuke has not decided what permutation <var>P</var> to use, but he is interested in the scores of possible permutations.
Find the sum of the scores over all possible permutations for him.
Since this can be extremely large, compute the sum modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^6</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 sum of the scores over all possible permutations, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>16
</pre>
<p>There are six possible permutations as <var>P</var>.
Among them, <var>P = (1, 3, 2)</var> and <var>P = (3, 1, 2)</var> have a score of <var>2</var>, and the others have a score of <var>3</var>.
Thus, the answer is <var>2 \times 2 + 3 \times 4 = 16</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There is only one possible permutation: <var>P = (1)</var>, which has a score of <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>84
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>341429644
</pre></section>
</div>
</span> |
p01358 |
<H1>Problem J: Usaneko Matrix</H1>
<p>
ããããšãããåè² ãããŠãã. ã«ãŒã«ã¯ä»¥äžã®éãã§ãã.
</p>
<p>
ãŸã2 å¹ã¯ãããã<i>n</i> è¡<i>n</i> åã®æ£æ¹åœ¢ç¶ã«<i>n</i><sup>2</sup> åã®æŽæ°ãçŽã«æžã, ãã©ã³ãã1 æãã€åŒã. 次ã«, 1 ãã 1 000 000 ãŸã§ã®æ°ã1 ã€ãã€æžããã1 000 000 æã®ã«ãŒãã2 å¹ã§ã·ã£ããã«ã, ããã1 æãã€äº€äºã«åŒããŠãã. 2 å¹ã¯ã«ãŒããåŒããããã³, ã«ãŒããšåãæ°ãèªåã®çŽã«æžãããŠãããããã«å°ãã€ãã. ãå°ãã€ãã<i>n</i> åã®æ°ã®çµã§ãã£ãŠ, äžçŽç·äžã«äžŠãã§ãããã®ãã®åæ°ã, ã¯ããã«åŒãããã©ã³ãã®æ°ä»¥äžã«ãªãããšãå婿¡ä»¶ãšãã.
</p>
<p>
äžãããã<i>m</i> æç®ã®ã«ãŒããŸã§ã§, ããããšããã®ã©ã¡ããåã€ãçãã. ãã ãåæã¯, ããã«ãŒããåŒãããŠå°ãã€ãçµãã£ã段éã§2 å¹ã®ãã¡çæ¹ã®ã¿ãå婿¡ä»¶ãã¿ããããšãã«æ±ºãŸããã®ãšã, ãã以å€ã®å Žåã¯åŒãåããšãã. ãããããå婿¡ä»¶ãã¿ãããåŸã§ãã«ãŒããåŒãããããšã¯ããã, ããã¯åæã«åœ±é¿ããªã.
</p>
<H2>Input</H2>
<p>
1 è¡ç®ïŒâ<i>n u v m</i>â (æ£æ¹åœ¢ã®ãµã€ãº, ãããã®ãã©ã³ãã®æ°, ããã®ãã©ã³ãã®æ°, åŒãããã«ãŒãã®ææ°) 2-(<i>N</i> + 1) è¡ç®ïŒããããçŽã«æžã<i>n</i><sup>2</sup> åã®æ°(<i>N</i> + 2)-(2<i>N</i> + 1) è¡ç®ïŒãããçŽã«æžã<i>n</i><sup>2</sup> åã®æ°(2<i>N</i> + 2)-(2<i>N</i> +<i>M</i> + 1) è¡ç®ïŒåŒãããm æã®ã«ãŒã<br>
1 ≤ <i>n</i> ≤ 500<br>
1 ≤ <i>u</i>, <i>v</i> ≤ 13<br>
1 ≤ <i>m</i> ≤ 100 000<br>
1 ≤ (æžãããæ°) ≤ 1 000 000<br>
</p>
<p>
ããããçŽã«æžã<i>n</i><sup>2</sup> åã®æ°, ãããçŽã«æžã<i>n</i><sup>2</sup> åã®æ°, åŒããã<i>m</i> æã®ã«ãŒãã«æžãããæ°ã¯ããããã®äžã§ç°ãªã.
</p>
<H2>Output</H2>
<p>
ããããåã€å Žåã«ã¯âUSAGIâã, ãããåã€å Žåã«ã¯âNEKOâã, åŒãåããªãã°âDRAWâ, ãããã
äžè¡ã«åºåãã.
</p>
<H2>Sample Input 1</H2>
<pre>
3 2 2 10
1 2 3
4 5 6
7 8 9
1 2 3
6 5 4
7 8 9
11
4
7
5
10
9
2
1
3
8
</pre>
<H2>Sample Output 1</H2>
<pre>
USAGI
</pre>
<H2>Sample Input 2</H2>
<pre>
3 2 1 10
1 2 3
4 5 6
7 8 9
1 2 3
6 5 4
7 8 9
11
4
7
5
10
9
2
1
3
8
</pre>
<H2>Sample Output 2</H2>
<pre>
DRAW
</pre>
|
p03735 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> bags, each containing two white balls. The <var>i</var>-th box contains two balls with integers <var>x_i</var> and <var>y_i</var> written on them, respectively.</p>
<p>For each of these bags, you will paint one of the balls red, and paint the other blue.</p>
<p>Afterwards, the <var>2N</var> balls will be classified according to color.</p>
<p>Then, we will define the following:</p>
<ul>
<li><var>R_{max}</var>: the maximum integer written on a ball painted in red</li>
<li><var>R_{min}</var>: the minimum integer written on a ball painted in red</li>
<li><var>B_{max}</var>: the maximum integer written on a ball painted in blue</li>
<li><var>B_{min}</var>: the minimum integer written on a ball painted in blue</li>
</ul>
<p>Find the minimum possible value of <var>(R_{max} - R_{min}) \times (B_{max} - B_{min})</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †200,000</var></li>
<li><var>1 †x_i, y_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>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
:
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2
3 4
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>15
</pre>
<p>The optimal solution is to paint the balls with <var>x_1</var>, <var>x_2</var>, <var>y_3</var> red, and paint the balls with <var>y_1</var>, <var>y_2</var>, <var>x_3</var> blue.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1010 10
1000 1
20 1020
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>380
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 1
1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>999999998000000001
</pre></section>
</div>
</span> |
p01708 |
<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>
<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote {
font-family: Menlo, Monaco, "Courier New", monospace;
color: #333333;
display: block;
padding: 8.5px;
margin: 0 0 9px;
font-size: 12px;
line-height: 18px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: pre;
white-space: pre-wrap;
word-break: break-all;
word-wrap: break-word;
}</style><div class="part"><h3>Problem Statement</h3><p>One day, you found an old scroll with strange texts on it.
</p>
<p>You revealed that the text was actually an expression denoting the position of
treasure. The expression consists of following three operations:
</p><ul><li> From two points, yield a line on which the points lie.
</li><li> From a point and a line, yield a point that is symmetric to the given point with respect to the line.
</li><li> From two lines, yield a point that is the intersection of the lines.
</li></ul>
<p>The syntax of the expression is denoted by following BNF:
</p><pre>
<expression> ::= <point>
<point> ::= <point-factor> | <line> "@" <line-factor> | <line> "@" <point-factor> | <point> "@" <line-factor>
<point-factor> ::= "(" <number> "," <number> ")" | "(" <point> ")"
<line> ::= <line-factor> | <point> "@" <point-factor>
<line-factor> ::= "(" <line> ")"
<number> ::= <zero-digit> | <positive-number> | <negative-number>
<positive-number> ::= <nonzero-digit> | <positive-number> <digit>
<negative-number> ::= "-" <positive-number>
<digit> ::= <zero-digit> | <nonzero-digit>
<zero-digit> ::= "0"
<nonzero-digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"</pre>
<p>Each <point> or <point-factor> denotes a point, whereas each <line> or <line-factor> denotes a line. The former notion of <point-factor> $(X,Y)$ represents a point which has $X$ for $x$-coordinate and $Y$ for $y$-coordinate on the $2$-dimensional plane.
"<samp>@</samp>" indicates the operations on two operands. Since each operation is distinguishable from others by its operands' types (i.e. a point or a line),
all of these operations are denoted by the same character "<samp>@</samp>".
Note that "<samp>@</samp>" is left-associative, as can be seen from the BNF.
</p>
<p>Your task is to determine where the treasure is placed.
</p>
</div><div class="part"><h3>Input</h3>
<p>The input consists of multiple datasets. Each dataset is a single line which
contains an expression denoting the position of treasure.
</p>
<p>It is guaranteed that each dataset satisfies the following conditions:
</p><ul><li> The length of the string never exceeds $10^2$.
</li><li> If both operands of "<samp>@</samp>" are points, their distance is greater than $1$.
</li><li> If both operands of "<samp>@</samp>" are lines, they are never parallel.
</li><li> The absolute values of points' coordinates never exceed $10^2$ at any point of evaluation.
</li></ul>
<p>You can also assume that there are at most $100$ datasets.
</p>
<p>The input ends with a line that contains only a single "<samp>#</samp>".
</p>
</div><div class="part"><h3>Output</h3>
<p>For each dataset, print the $X$ and $Y$ coordinates of the point, denoted by
the expression, in this order.
</p>
<p>The output will be considered correct if its absolute or relative error is at most $10^{-2}$.
</p>
</div><div class="part"><h3>Sample Input</h3>
<pre>((0,0)@(1,1))@((4,1)@(2,5))
((0,0)@(3,1))@((1,-3)@(2,-1))
(0,0)@(1,1)@(4,1)
(0,0)@((1,1)@(4,1))
(((0,0)@((10,20)@(((30,40))))))
((0,0)@(3,1))@((1,-3)@(2,-1))@(100,-100)@(100,100)
#</pre>
</div><div class="part"><h3>Output for the Sample Input</h3>
<pre>3.00000000 3.00000000
3.00000000 1.00000000
1.00000000 4.00000000
0.00000000 2.00000000
-10.00000000 10.00000000
-99.83681795 -91.92248853</pre>
</div> |
p02827 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A <i>balancing network</i> is an abstract device built up of <var>N</var> wires, thought of as running from left to right,
and <var>M</var> <i>balancers</i> that connect pairs of wires. The wires are numbered from <var>1</var> to <var>N</var> from top to bottom,
and the balancers are numbered from <var>1</var> to <var>M</var> from left to right.
Balancer <var>i</var> connects wires <var>x_i</var> and <var>y_i</var> (<var>x_i < y_i</var>).</p>
<div style="text-align: center;">
<img alt="pic1-small-2acea94b.png" src="https://img.atcoder.jp/agc041/pic1-small-2acea94b.png">
</img></div>
<p>Each balancer must be in one of two states: <i>up</i> or <i>down</i>.</p>
<p>Consider a token that starts moving to the right along some wire at a point to the left of all balancers.
During the process, the token passes through each balancer exactly once.
Whenever the token encounters balancer <var>i</var>, the following happens:</p>
<ul>
<li>If the token is moving along wire <var>x_i</var> and balancer <var>i</var> is in the down state, the token moves down to wire <var>y_i</var> and continues moving to the right.</li>
<li>If the token is moving along wire <var>y_i</var> and balancer <var>i</var> is in the up state, the token moves up to wire <var>x_i</var> and continues moving to the right.</li>
<li>Otherwise, the token doesn't change the wire it's moving along.</li>
</ul>
<p>Let a state of the balancing network be a string of length <var>M</var>, describing the states of all balancers.
The <var>i</var>-th character is <code>^</code> if balancer <var>i</var> is in the up state, and <code>v</code> if balancer <var>i</var> is in the down state.</p>
<p>A state of the balancing network is called <i>uniforming</i> if a wire <var>w</var> exists such that, regardless of the starting wire,
the token will always end up at wire <var>w</var> and run to infinity along it. Any other state is called <i>non-uniforming</i>.</p>
<p>You are given an integer <var>T</var> (<var>1 \le T \le 2</var>). Answer the following question:</p>
<ul>
<li>If <var>T = 1</var>, find any uniforming state of the network or determine that it doesn't exist.</li>
<li>If <var>T = 2</var>, find any non-uniforming state of the network or determine that it doesn't exist.</li>
</ul>
<p>Note that if you answer just one kind of questions correctly, you can get partial score.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 50000</var></li>
<li><var>1 \leq M \leq 100000</var></li>
<li><var>1 \leq T \leq 2</var></li>
<li><var>1 \leq x_i < y_i \leq N</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li><var>800</var> points will be awarded for passing the testset satisfying <var>T = 1</var>.</li>
<li><var>800</var> points will be awarded for passing the testset satisfying <var>T = 2</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>T</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_M</var> <var>y_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print any uniforming state of the given network if <var>T = 1</var>, or any non-uniforming state if <var>T = 2</var>. If the required state doesn't exist, output <code>-1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5 1
1 3
2 4
1 2
3 4
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>^^^^^
</pre>
<p>This state is uniforming: regardless of the starting wire, the token ends up at wire <var>1</var>.</p>
<div style="text-align: center;">
<img alt="pic2-small-2acea94b.png" src="https://img.atcoder.jp/agc041/pic2-small-2acea94b.png">
</img></div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5 2
1 3
2 4
1 2
3 4
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>v^^^^
</pre>
<p>This state is non-uniforming: depending on the starting wire, the token might end up at wire <var>1</var> or wire <var>2</var>.</p>
<div style="text-align: center;">
<img alt="pic3final-small-2acea94b.png" src="https://img.atcoder.jp/agc041/pic3final-small-2acea94b.png"/>
</div>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 1 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>A uniforming state doesn't exist.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 1 2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>-1
</pre>
<p>A non-uniforming state doesn't exist.</p></section>
</div>
</span> |
p00549 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h2>ã¹ã¿ã³ãã©ãªãŒïŒ (Collecting Stamps 2)</h2>
<p>
JOI ååºè¡ã«ã¯å€§éãã«æ²¿ã£ãŠ $N$ åã®åºãããïŒJOI ååºè¡ã®å
¥å£ããåºå£ã«åãã£ãŠãããã $1, 2, ..., N$ ã®çªå·ãä»ããããŠããïŒJOI ååºè¡ã¯äžæ¹éè¡ã§ïŒå
¥å£ããåºå£æ¹åãžããç§»åããããšã¯ã§ããªãïŒ
</p>
<p>
ãŸã¡ãããã®ããïŒJOI ååºè¡ã§ã¹ã¿ã³ãã©ãªãŒãè¡ãããšã«ãªã£ãïŒãã®ã¹ã¿ã³ãã©ãªãŒã§ã¯ïŒããããã®åºã¯JïŒOïŒI ã®ããããã®ã¹ã¿ã³ããçšæãïŒåºã§è²·ãç©ããã人ã¯ã¹ã¿ã³ãã«ãŒãã«ã¹ã¿ã³ããæŒããŠãããïŒã¹ã¿ã³ãã©ãªãŒã«åå ãã人ã¯ã¡ããã© 3 ã€ã®åºã«å
¥ãïŒååºè¡ã®å
¥å£ã§ã¯ 3 ã€ã®æ¬ã®ããã¹ã¿ã³ãã«ãŒããé
ãïŒ1 åç®ã«å
¥ã£ãåºïŒ2 åç®ã«å
¥ã£ãåºïŒ3 åç®ã«å
¥ã£ãåºã®ã¹ã¿ã³ããæŒããŠãããïŒååºè¡ã®åºå£ã§ã¹ã¿ã³ãã«ãŒããååãïŒæŒãããã¹ã¿ã³ããå
ã«å
¥ã£ãåºã®ãã®ããé ã«JïŒOïŒIã«ãªã£ãŠãããšãïŒåºå£ã§åååžããããããã£ã³ããŒã³ã宿œããããšã«ãªã£ãïŒæŒãããã¹ã¿ã³ãã®çš®é¡ãé çªãç°ãªããšãã¯åååžã¯ããããªãïŒ
</p>
<p>
ãã§ã« $N$ åã®ãã¹ãŠã®åºã¯ã©ã®ã¹ã¿ã³ããçšæãããæ±ºãããïŒæ°ãã«1 ã€ã®åºãJOI ååºè¡ã«åºãããšã«ãªãïŒæ°ããåºåºããå ŽæãšïŒãã®åºãçšæããã¹ã¿ã³ããæ±ºããããšã«ãªã£ãïŒæ°ããåºãåºãå Žæã¯ïŒåº $i$ ãšåº $i + 1$ ã®é $(1 \leq i \leq N - 1)$ïŒå
¥å£ãšåº $1$ ã®éïŒåº $N$ ãšåºå£ã®éã®ããããããæ±ºããïŒãŸãïŒæ°ããåºã®ã¹ã¿ã³ã㯠JïŒOïŒI ã® 3 éãããæ±ºããïŒ
</p>
<p>
åååžããããããããªåºã®éžã³æ¹ã®æ°ã倧ããã»ã©ïŒã¹ã¿ã³ãã©ãªãŒãçãäžãããšååºè¡ã¯èããïŒããã§ïŒæ°ããåºãåºã®å Žæãšçšæããã¹ã¿ã³ããæ±ºãããšãã®ïŒäžèšã®åºã®éžã³æ¹ã®æ°ã®æå€§å€ãæ±ãããïŒ
</p>
<h2>課é¡</h2>
<p>
JOI ååºè¡ã®ãã§ã«ããåºãçšæããã¹ã¿ã³ãã®æ
å ±ãäžãããããšãïŒæ°ããåºãåºã®å Žæãšçšæããã¹ã¿ã³ããæ±ºãããšãã®ïŒåååžããããããããªåºã®éžã³æ¹ã®æ°ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒ1 ã€ã®æŽæ° $N$ ãæžãããŠããïŒããã¯ïŒJOI ååºè¡ã«ã¯çŸåš $N$ åã®åºãããããšãæå³ããïŒ</li>
<li> 2 è¡ç®ã«ã¯ïŒ$N$ æåã®åè§è±å€§æå J, O, I ã®ã¿ãããªãæåå $S$ ãæžãããŠããïŒæåå $S$ ã®å·Šãã $i$ æåç® $(1 \leq i \leq N)$ ã¯ïŒåº $i$ ãçšæããã¹ã¿ã³ãã®çš®é¡ã衚ãïŒ </li>
</ul>
<h2>åºå</h2>
<p>
åååžããããããããªåºã®éžã³æ¹ã®æ°ã®æå€§å€ãæšæºåºåã« 1 è¡ã§åºåããïŒ
</p>
<p>
åååžããããããããªåºã®éžã³æ¹ã®æ°ã32 ããã笊å·ä»ãæŽæ°ã®ç¯å²ã«åãŸããšã¯éããªãããšã«æ³šæããïŒ
</p>
<h2>å¶é</h2>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li> $3 \leq N \leq 100 000$</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
5
JOIOI
</pre>
<h3>åºåäŸ1</h3>
<pre>
6
</pre>
<p>
å
¥åäŸ 1 ã§ã¯ïŒåº 1 ãšåº 2 ã®éã«ïŒã¹ã¿ã³ã J ãçšæããæ°ããåºãåºãããšãïŒåºãçšæããã¹ã¿ã³ããå
¥å£ããé ã«äžŠã¹ããš JJOIOI ãšãªãïŒ
</p>
<p>
ãã®ãšãïŒåååžããããããããªåºã®éžã³æ¹ã¯ä»¥äžã® 6 éãã§ããïŒ
</p>
<ul>
<li> 1, 3, 4 çªç®ã®åºã«è¡ãïŒ </li>
<li> 1, 3, 6 çªç®ã®åºã«è¡ãïŒ </li>
<li> 1, 5, 6 çªç®ã®åºã«è¡ãïŒ </li>
<li> 2, 3, 4 çªç®ã®åºã«è¡ãïŒ </li>
<li> 2, 3, 6 çªç®ã®åºã«è¡ãïŒ </li>
<li> 2, 5, 6 çªç®ã®åºã«è¡ãïŒ </li>
</ul>
<p>
å
¥åäŸ 1 ã«ãããŠïŒåååžããããããããªåºã®éžã³æ¹ã 7 éã以äžã«ãªãããšã¯ãªãïŒ
</p>
<h3>å
¥åäŸ2</h3>
<pre>
7
JJJOIII
</pre>
<h3>åºåäŸ2</h3>
<pre>
18
</pre>
<h3>å
¥åäŸ3</h3>
<pre>
4
OIIJ
</pre>
<h3>åºåäŸ3</h3>
<pre>
2
</pre>
<p>
å
¥åäŸ 3 ã§ã¯ïŒå
¥å£ãšåº 1 ã®éã«ã¹ã¿ã³ã J ãçšæããæ°ããåºãåºãããšãïŒåååžããããããããªåºã®éžã³æ¹ã®æ°ãæå€§ãšãªãïŒ
</p>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf">第15å æ¥æ¬æ
å ±ãªãªã³ããã¯æ¬éž èª²é¡ 2016 幎 2 æ 14 æ¥</a>
</p>
</div>
|
p02574 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> integers. The <var>i</var>-th number is <var>A_i</var>.</p>
<p><var>\{A_i\}</var> is said to be pairwise coprime when <var>GCD(A_i,A_j)=1</var> holds for every pair <var>(i, j)</var> such that <var>1\leq i < j \leq N</var>.</p>
<p><var>\{A_i\}</var> is said to be setwise coprime when <var>\{A_i\}</var> is not pairwise coprime but <var>GCD(A_1,\ldots,A_N)=1</var>.</p>
<p>Determine if <var>\{A_i\}</var> is pairwise coprime, setwise coprime, or neither.</p>
<p>Here, <var>GCD(\ldots)</var> denotes greatest common divisor.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^6</var></li>
<li><var>1 \leq A_i\leq 10^6</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>\ldots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>\{A_i\}</var> is pairwise coprime, print <code>pairwise coprime</code>; if <var>\{A_i\}</var> is setwise coprime, print <code>setwise coprime</code>; if neither, print <code>not coprime</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>pairwise coprime
</pre>
<p><var>GCD(3,4)=GCD(3,5)=GCD(4,5)=1</var>, so they are pairwise coprime.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
6 10 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>setwise coprime
</pre>
<p>Since <var>GCD(6,10)=2</var>, they are not pairwise coprime. However, since <var>GCD(6,10,15)=1</var>, they are setwise coprime.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
6 10 16
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>not coprime
</pre>
<p><var>GCD(6,10,16)=2</var>, so they are neither pairwise coprime nor setwise coprime.</p></section>
</div>
</span> |
p00119 |
<H1>倪éåã®å·å¿µ</H1>
<p>
ãŸããã
ã奜ãã®å€ªéããã®å®¶ã§ãããžããªäºä»¶ããããŸãããå宀ã®ä»å£ã«äŸããŠãã£ã3ã€ã®ãŸããã
ãã®ãã¡1ã€ãç¡ããªã£ãŠããã®ã§ãããã€ãã¯ããã€ã«ããã ãããšçã£ãŠãã倪éãããç¯äººãèŠã€ããããææ»ãå§ãããšããã®æ¥ãå宀ã«å
¥ã£ã人ãäœäººãããããšãåãããŸãããããã§ããããã®å®¹çè
ãéšå±ã«å
¥ã£ãé åºã調ã¹ããããå
šå¡ã«æ¬¡ã®ãããªåœ¢åŒã®èšŒèšãããŠãããããšã«ãŸããã
</p>
<p>
容çè
A ã®èšŒèš ãç§ã¯å®¹çè
B ããå
ã«éšå±ã«å
¥ã£ããã
</p>
<p>
容çè
ã®äžäºº(?)ã¯äžæ¯ç«ã®ã¿ããªã®ã§èšŒèšã¯ã§ããŸãããã幞éã«ãæåŸã«éšå±ã«å
¥ã£ããšããã倪éããã¯èŠãŠããŸããã
</p>
<p>
倪éããã¯ãããã®èšŒèšãããéšå±ã«å
¥ã£ãé çªãæšæž¬ããŠææ»ã«åœ¹ç«ãŠãããšã«ããŸããã
</p>
<p>
äŸãã°ã6 人ã®å®¹çè
ãããŠã¿ãã容çè
2 ãšããå Žåã以äžã®ãããªèšŒèšãåŸããããšããŸãã
</p>
<p>
容çè
5 ã®èšŒèš ãç§ã¯ 2 ããå
ã«éšå±ã«å
¥ã£ããã<br>
容çè
1 ã®èšŒèš ãç§ã¯ 4 ããå
ã«éšå±ã«å
¥ã£ããã<br>
容çè
3 ã®èšŒèš ãç§ã¯ 5 ããå
ã«éšå±ã«å
¥ã£ããã<br>
容çè
4 ã®èšŒèš ãç§ã¯ 2 ããå
ã«éšå±ã«å
¥ã£ããã<br>
容çè
1 ã®èšŒèš ãç§ã¯ 6 ããå
ã«éšå±ã«å
¥ã£ããã<br>
容çè
6 ã®èšŒèš ãç§ã¯ 4 ããå
ã«éšå±ã«å
¥ã£ããã<br>
容çè
3 ã®èšŒèš ãç§ã¯ 4 ããå
ã«éšå±ã«å
¥ã£ããã<br>
</p>
<p>
ãã®èšŒèšãã€ãªãåããããšãéšå±ã«å
¥ã£ãé åºã¯
</p>
<ul>
<li>3â5â1â6â4â2</li>
<li>1â6â3â4â5â2</li>
<li>3â1â6â5â4â2</li>
</ul>
<p>
ãªã©ãäœéããã®å¯èœæ§ã«çµã蟌ãããšãã§ããŸãã
</p>
<p>
ã¿ã (容çè
2) 以å€ã®å®¹çè
å
šå¡ã®èšŒèšãããéšå±ã«å
¥ã£ãé çªãæšæž¬ããå¯èœæ§ã®ããé çªã® 1 ã€ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããè€æ°ã®èšŒèšããã容çè
ããããããããŸããããã©ã®èšŒèšãçå®ã§ããççŸããŠããªããã®ãšããŸãã
</p>
<!--
ãã ãã容çè
ã®äººæ°ã m ãšãããš m 㯠20 以äžã§ããã容çè
㯠1 ãã m ãŸã§ã®æŽæ°ã§èå¥ãããŸãã蚌èšã®æ°ã¯ 100 以äžãšããŸãããŸããè€æ°ã®èšŒèšããã容çè
ããããããããŸããããã©ã®èšŒèšãçå®ã§ããççŸããŠããªããã®ãšããŸãã
-->
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>m</var>
<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>
1 è¡ç®ã«å®¹çè
ã®äººæ° <var>m</var> (<var>m</var> ≤ 20)ã2 è¡ç®ã«èšŒèšã®æ° <var>n</var> (<var>n</var> ≤ 100) ãäžããããŸãã
ç¶ã <var>n</var> è¡ã« <var>i</var> åç®ã®èšŒèšã®å
容 <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ãããããïŒè¡ã«äžããããŸãã<var>x<sub>i</sub></var> <var>y<sub>i</sub></var> ã¯ã容çè
<var>x<sub>i</sub></var>(ç§)ã¯å®¹çè
<var>y<sub>i</sub></var> ããå
ã«å
¥ã£ãããšãã蚌èšã衚ããŸãã
</p>
<H2>Output</H2>
<p>
æåã«éšå±ã«å
¥ã£ã容çè
ã®çªå·ã2 çªç®ã«éšå±ã«å
¥ã£ã容çè
ã®çªå·ã...ã<var>m</var> çªç®ã«éšå±ã«å
¥ã£ã容çè
ã®çªå·ãããããïŒè¡ã«é çªã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
6
7
5 2
1 4
3 5
4 2
1 6
6 4
3 4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
5
1
6
4
2
</pre>
|
p02124 | <h1>Problem A: ai1333</h1>
<h2>Problem</h2>
<p>çæŠ1333幎ã人é¡å²äžæé«ã®ç§åŠè
Dr.ãŠã·ã·ã¯ãèªãã®è±ç¥ãåŸäžã«æ®ãã¹ããIDãai1333ã®äººå·¥ç¥èœãéçºããããããã100幎ã®éãai1333ã¯äººé¡ã«å€å€§ãªå©çããããããããèªçãã100幎ç®ãè¿ããæ¥ãèªãã®åŸç¶ãšããŠIDãai13333ã®æ°ããªäººå·¥ç¥èœãäœæãããã®æ©èœãæ°žä¹
ã«åæ¢ããã以é100幎ããšã«ã人工ç¥èœã¯âai1333âããå§ãŸãèªèº«ã®IDã®æ«å°Ÿã«â3âãé£çµããIDãæã€åŸç¶ãæ®ãããã«ãªã£ãã</p>
<p>å
¥åãšããŠçæŠ1333幎ããã®çµé幎æ°$x$ãäžããããã®ã§ããã®å¹Žã«äœæããã人工ç¥èœã®IDãåºåããããã ãã$x$ã¯100ã®éè² æŽæ°åã§ããããšãä¿èšŒãããã</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$x$
</pre>
<p>
çµé幎æ°$x$ã1è¡ã«äžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$0 \le x \le 10000$</li>
<li>$x$ã¯100ã®éè² æŽæ°å</li>
</ul>
<h2>Ouput</h2>
<p>çæŠ1333幎ãã$x$幎åŸã«äœæããã人工ç¥èœã®IDã1è¡ã«åºåããã</p>
<h2>Sample Input 1</h2>
<pre>
0
</pre>
<h2>Sample Output 1</h2>
<pre>
ai1333
</pre>
<h2>Sample Input 2</h2>
<pre>
300
</pre>
<h2>Sample Output 2</h2>
<pre>
ai1333333
</pre>
|
p02431 | <h1>Vector</h1>
<p>
For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations:
</p>
<ul>
<li>pushBack($x$): add element $x$ at the end of $A$</li>
<li>randomAccess($p$):print element $a_p$</li>
<li>popBack(): delete the last element of $A$</li>
</ul>
<p>
$A$ is a 0-origin array and it is empty in the initial state.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $x$
</pre>
<p>or</p>
<pre>
1 $p$
</pre>
<p>or</p>
<pre>
2
</pre>
<p>
where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent pushBack, randomAccess and popBack operations respectively.
</p>
<p>
randomAccess and popBack operations will not be given for an empty array.
</p>
<h2>Output</h2>
<p>
For each randomAccess, print $a_p$ in a line.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq q \leq 200,000$</li>
<li>$0 \leq p < $ the size of $A$</li>
<li>$-1,000,000,000 \leq x \leq 1,000,000,000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
8
0 1
0 2
0 3
2
0 4
1 0
1 1
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1
2
4
</pre>
|
p02061 | <h2>B: èªèº«ã® 2 å</h2>
<h3>åé¡</h3>
<p>ã¯ãšãªã <var>Q</var> åäžããããŸãã1 åã®ã¯ãšãªã«ã€ãã 1 ã€ã®æ£ã®æŽæ° <var>N</var> ãäžããããã®ã§ã次㮠2 ã€ã®æ¡ä»¶ãæºããæ£ã®æŽæ° <var>M</var> ã®åæ°ãæ±ããŠãã ããã</p>
<ul>
<li><var>2 \leq M \leq N</var> ãæºãã</li>
<li><var>M</var> ã®çŽæ°ã®ãã¡ã<var>M</var> ãé€ãããã®ã®ç·ç©ã <var>M</var> ã® <var>2</var> å以äžã«ãªã</li>
</ul>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã</p>
<pre>
<var>Q</var>
<var>N_1</var>
<var>N_2</var>
<var>:</var>
<var>N_Q</var>
</pre>
<ul>
<li><var>1</var> è¡ç®ã§ã¯ãã¯ãšãªæ° <var>Q</var> ãäžããããŸãã</li>
<li><var>2</var> è¡ç®ãã <var>N+1</var> è¡ç®ã§ã¯ãåã¯ãšãªã«ã€ããŠäžãããã 1 ã€ã®æ£ã®æŽæ° <var>N</var> ãäžããããŸãã</li>
</ul>
<h3>å¶çŽ</h3>
<ul>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>2 \leq N_i \leq 10^5</var> <var>(1 \leq i \leq Q)</var></li>
</ul>
<h3>åºå圢åŒ</h3>
<p>äžèšã® 2 ã€ã®æ¡ä»¶ãæºããæ£ã®æŽæ°ã®åæ°ããå <var>N_i</var> ã«å¯ŸããŠãæ¹è¡åºåãã§åºåããŠãã ããã</p>
<h3>å
¥åäŸ</h3>
<pre>
3
43
9
24
</pre>
<h3>åºåäŸ</h3>
<pre>
11
0
5
</pre>
<ul>
<li> <var>N=24</var> ã®æã<var>M</var> ãšããŠèããããã®ã¯ <var>12</var>, <var>16</var>, <var>18</var>, <var>20</var>, <var>24</var> ã® <var>5</var> çš®é¡ã§ããã</li>
</ul>
|
p03220 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A country decides to build a palace.</p>
<p>In this country, the average temperature of a point at an elevation of <var>x</var> meters is <var>T-x \times 0.006</var> degrees Celsius.</p>
<p>There are <var>N</var> places proposed for the place. The elevation of Place <var>i</var> is <var>H_i</var> meters.</p>
<p>Among them, Princess Joisino orders you to select the place whose average temperature is the closest to <var>A</var> degrees Celsius, and build the palace there.</p>
<p>Print the index of the place where the palace should be built.</p>
<p>It is guaranteed that the solution is unique.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>0 \leq T \leq 50</var></li>
<li><var>-60 \leq A \leq T</var></li>
<li><var>0 \leq H_i \leq 10^5</var></li>
<li>All values in input are integers.</li>
<li>The solution is unique.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>T</var> <var>A</var>
<var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the index of the place where the palace should be built.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
12 5
1000 2000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<ul>
<li>The average temperature of Place <var>1</var> is <var>12-1000 \times 0.006=6</var> degrees Celsius.</li>
<li>The average temperature of Place <var>2</var> is <var>12-2000 \times 0.006=0</var> degrees Celsius.</li>
</ul>
<p>Thus, the palace should be built at Place <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
21 -11
81234 94124 52141
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre></section>
</div>
</span> |
p03670 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N(N+1)/2</var> dots arranged to form an equilateral triangle whose sides consist of <var>N</var> dots, as shown below.
The <var>j</var>-th dot from the left in the <var>i</var>-th row from the top is denoted by <var>(i, j)</var> (<var>1 \leq i \leq N</var>, <var>1 \leq j \leq i</var>).
Also, we will call <var>(i+1, j)</var> immediately lower-left to <var>(i, j)</var>, and <var>(i+1, j+1)</var> immediately lower-right to <var>(i, j)</var>.</p>
<p><img alt="" src="https://atcoder.jp/img/agc017/8d354fb1a389a0aa5b64ba93f6ca7801.png"/></p>
<p>Takahashi is drawing <var>M</var> polygonal lines <var>L_1, L_2, ..., L_M</var> by connecting these dots.
Each <var>L_i</var> starts at <var>(1, 1)</var>, and visits the dot that is immediately lower-left or lower-right to the current dots <var>N-1</var> times.
More formally, there exist <var>X_{i,1}, ..., X_{i,N}</var> such that:</p>
<ul>
<li><var>L_i</var> connects the <var>N</var> points <var>(1, X_{i,1}), (2, X_{i,2}), ..., (N, X_{i,N})</var>, in this order.</li>
<li>For each <var>j=1, 2, ..., N-1</var>, either <var>X_{i,j+1} = X_{i,j}</var> or <var>X_{i,j+1} = X_{i,j}+1</var> holds.</li>
</ul>
<p>Takahashi would like to draw these lines so that no part of <var>L_{i+1}</var> is to the left of <var>L_{i}</var>.
That is, for each <var>j=1, 2, ..., N</var>, <var>X_{1,j} \leq X_{2,j} \leq ... \leq X_{M,j}</var> must hold.</p>
<p>Additionally, there are <var>K</var> conditions on the shape of the lines that must be followed.
The <var>i</var>-th condition is denoted by <var>(A_i, B_i, C_i)</var>, which means:</p>
<ul>
<li>If <var>C_i=0</var>, <var>L_{A_i}</var> must visit the immediately lower-left dot for the <var>B_i</var>-th move.</li>
<li>If <var>C_i=1</var>, <var>L_{A_i}</var> must visit the immediately lower-right dot for the <var>B_i</var>-th move.</li>
</ul>
<p>That is, <var>X_{A_i, {B_i}+1} = X_{A_i, B_i} + C_i</var> must hold.</p>
<p>In how many ways can Takahashi draw <var>M</var> polygonal lines? Find the count modulo <var>1000000007</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>Before submission, it is strongly recommended to measure the execution time of your code using "Custom Test".</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 20</var></li>
<li><var>1 \leq M \leq 20</var></li>
<li><var>0 \leq K \leq (N-1)M</var></li>
<li><var>1 \leq A_i \leq M</var></li>
<li><var>1 \leq B_i \leq N-1</var></li>
<li><var>C_i = 0</var> or <var>1</var></li>
<li>No pair appears more than once as <var>(A_i, B_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>K</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>A_K</var> <var>B_K</var> <var>C_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways for Takahashi to draw <var>M</var> polygonal lines, modulo <var>1000000007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2 1
1 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six ways to draw lines, as shown below. Here, red lines represent <var>L_1</var>, and green lines represent <var>L_2</var>.</p>
<p><img alt="" src="https://atcoder.jp/img/agc017/75921b6e5a59ab17b4c07ada848b9f14.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2 2
1 1 1
2 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 4 2
1 3 1
4 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>172
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>20 20 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>881396682
</pre></section>
</div>
</span> |
p02962 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are two strings <var>s</var> and <var>t</var> consisting of lowercase English letters. Determine if the number of non-negative integers <var>i</var> satisfying the following condition is finite, and find the maximum value of such <var>i</var> if the number is finite.</p>
<ul>
<li>There exists a non-negative integer <var>j</var> such that the concatenation of <var>i</var> copies of <var>t</var> is a substring of the concatenation of <var>j</var> copies of <var>s</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><ul>
<li>
<p>A string <var>a</var> is a substring of another string <var>b</var> if and only if there exists an integer <var>x</var> <var>(0 \leq x \leq |b| - |a|)</var> such that, for any <var>y</var> <var>(1 \leq y \leq |a|)</var>, <var>a_y = b_{x+y}</var> holds.</p>
</li>
<li>
<p>We assume that the concatenation of zero copies of any string is the empty string. From the definition above, the empty string is a substring of any string. Thus, for any two strings <var>s</var> and <var>t</var>, <var>i = 0</var> satisfies the condition in the problem statement.</p>
</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |s| \leq 5 \times 10^5</var></li>
<li><var>1 \leq |t| \leq 5 \times 10^5</var></li>
<li><var>s</var> and <var>t</var> consist of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>s</var>
<var>t</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the number of non-negative integers <var>i</var> satisfying the following condition is finite, print the maximum value of such <var>i</var>; if the number is infinite, print <code>-1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abcabab
ab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The concatenation of three copies of <var>t</var>, <code>ababab</code>, is a substring of the concatenation of two copies of <var>s</var>, <code>abcabababcabab</code>, so <var>i = 3</var> satisfies the condition.</p>
<p>On the other hand, the concatenation of four copies of <var>t</var>, <code>abababab</code>, is not a substring of the concatenation of any number of copies of <var>s</var>, so <var>i = 4</var> does not satisfy the condition.</p>
<p>Similarly, any integer greater than <var>4</var> does not satisfy the condition, either. Thus, the number of non-negative integers <var>i</var> satisfying the condition is finite, and the maximum value of such <var>i</var> is <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aa
aaaaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>For any non-negative integer <var>i</var>, the concatenation of <var>i</var> copies of <var>t</var> is a substring of the concatenation of <var>4i</var> copies of <var>s</var>. Thus, there are infinitely many non-negative integers <var>i</var> that satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>aba
baaab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>As stated in Notes, <var>i = 0</var> always satisfies the condition.</p></section>
</div>
</span> |
p02348 |
<H1>Range Update Query (RUQ)</H1>
<p>
Write a program which manipulates a sequence <var>A</var> = {<var>a<sub>0</sub>, a<sub>1</sub>, . . . , a<sub>n−1</sub></var>} with the following operations:
</p>
<ul>
<li><var>update(s, t, x)</var>: change <var>a<sub>s</sub></var>, <var>a<sub>s+1</sub></var>, ..., <var>a<sub>t</sub></var> to <var>x</var>.</li>
<li><var>find(i)</var>: output the value of <var>a<sub>i</sub>.</li>
</ul>
<p>
Note that the initial values of <var>a<sub>i</sub></var> (<var>i = 0, 1, . . . , n−1</var>) are 2<sup>31</sup>-1.
</p>
<H2>Input</H2>
<pre>
<var>n</var> <var>q</var>
<var>query<sub>1</sub></var>
<var>query<sub>2</sub></var>
:
<var>query<sub>q</sub></var>
</pre>
<p>
In the first line, <var>n</var> (the number of elements in <var>A</var>) and <var>q</var> (the number of queries) are given. Then, <i>i</i>th query <var>query<sub>i</sub></var> is given in the following format:
</p>
<pre>
0 <var>s</var> <var>t</var> <var>x</var>
</pre>
<p>
or
</p>
<pre>
1 <var>i</var>
</pre>
<p>
The first digit represents the type of the query. '0' denotes <var>update(s, t, x)</var> and '1' denotes <var>find(i)</var>.
</p>
<H2>Output</H2>
<p>
For each <var>find</var> operation, print the value.
</p>
<H2>Constraints</H2>
<ul>
<li>
<var>1 ≤ n ≤ 100000</var>
</li>
<li>
<var>1 ≤ q ≤ 100000</var>
</li>
<li>
<var>0 ≤ s ≤ t < n</var>
</li>
<li>
<var>0 ≤ i < n</var>
</li>
<li>
<var>0 ≤ x < 2<sup>31</sup>−1</var>
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
</pre>
<H2>Sample Output 1</H2>
<pre>
1
3
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
1 3
1 0
0 0 0 5
1 0
</pre>
<H2>Sample Output 2</H2>
<pre>
2147483647
5
</pre> |
p00375 | <h1>Celsius/Fahrenheit</h1>
ã
<p>
In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Todayâs temperature is $68$ degrees" is commonly encountered while you are in America.
</p>
<p>
A value in Fahrenheit can be converted to Celsius by first subtracting $32$ and then multiplying by $\frac{5}{9}$. A simplified method may be used to produce a rough estimate: first subtract $30$ and then divide by $2$. Using the latter method, $68$ Fahrenheit is converted to $19$ Centigrade, i.e., $\frac{(68-30)}{2}$.
</p>
<p>
Make a program to convert Fahrenheit to Celsius using the simplified method: $C = \frac{F - 30}{2}$.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$F$
</pre>
<p>
The input line provides a temperature in Fahrenheit $F$ ($30 \leq F \leq 100$), which is an integer divisible by $2$.
</p>
<h2>Output</h2>
<p>
Output the converted Celsius temperature in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
68
</pre>
<h2>Sample Output 1</h2>
<pre>
19
</pre>
<h2>Sample Input 2</h2>
<pre>
50
</pre>
<h2>Sample Output 2</h2>
<pre>
10
</pre>
|
p01837 |
<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>Longest Shortest Path</h2>
<p>
You are given a directed graph and two nodes $s$ and $t$. The given graph may contain multiple edges between the same node pair but not self loops. Each edge $e$ has its initial length $d_e$ and the cost $c_e$. You can extend an edge by paying a cost. Formally, it costs $x \cdot c_e$ to change the length of an edge $e$ from $d_e$ to $d_e + x$. (Note that $x$ can be a non-integer.) Edges cannot be shortened.
</p>
<p>
Your task is to maximize the length of the shortest path from node $s$ to node $t$ by lengthening some edges within cost $P$. You can assume that there is at least one path from $s$ to $t$.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case formatted as follows.<br/>
<br/>
$N$ $M$ $P$ $s$ $t$<br/>
$v_1$ $u_1$ $d_1$ $c_1$<br/>
...<br/>
$v_M$ $u_M$ $d_M$ $c_M$<br/>
</p>
<p>
The first line contains five integers $N$, $M$, $P$, $s$, and $t$: $N$ ($2 \leq N \leq 200$) and $M$ ($1 \leq M \leq 2,000$) are the number of the nodes and the edges of the given graph respectively, $P$ ($0 \leq P \leq 10^6$) is the cost limit that you can pay, and $s$ and $t$ ($1 \leq s, t \leq N, s \ne t$) are the start and the end node of objective path respectively. Each of the following $M$ lines contains four integers $v_i$, $u_i$, $d_i$, and $c_i$, which mean there is an edge from $v_i$ to $u_i$ ($1 \leq v_i, u_i \leq N, v_i \ne u_i$) with the initial length $d_i$ ($1 \leq d_i \leq 10$) and the cost $c_i$ ($1 \leq c_i \leq 10$).
</p>
<h3>Output</h3
<p>
Output the maximum length of the shortest path from node $s$ to node $t$ by lengthening some edges within cost $P$. The output can contain an absolute or a relative error no more than $10^{-6}$.
</p>
<h3>Sample Input 1</h3>
<pre>
3 2 3 1 3
1 2 2 1
2 3 1 2
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
6.0000000
</pre>
<h3>Sample Input 2</h3>
<pre>
3 3 2 1 3
1 2 1 1
2 3 1 1
1 3 1 1
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
2.5000000
</pre>
<h3>Sample Input 3</h3>
<pre>
3 4 5 1 3
1 2 1 2
2 3 1 1
1 3 3 2
1 3 4 1
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
4.2500000
</pre>
|
p02718 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have held a popularity poll for <var>N</var> items on sale. Item <var>i</var> received <var>A_i</var> votes.</p>
<p>From these <var>N</var> items, we will select <var>M</var> as popular items. However, we cannot select an item with less than <var>\dfrac{1}{4M}</var> of the total number of votes.</p>
<p>If <var>M</var> popular items can be selected, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq M \leq N \leq 100</var></li>
<li><var>1 \leq A_i \leq 1000</var></li>
<li><var>A_i</var> are distinct.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>M</var> popular items can be selected, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 1
5 4 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>There were <var>12</var> votes in total. The most popular item received <var>5</var> votes, and we can select it.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
380 19 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>There were <var>400</var> votes in total. The second and third most popular items received less than <var>\dfrac{1}{4\times 2}</var> of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>12 3
4 56 78 901 2 345 67 890 123 45 6 789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.