question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00923 |
<H1><font color="#000">Problem J: </font><span>C(O|W|A*RD*|S)* CROSSWORD</span> Puzzle</H1>
<p>
The first crossword puzzle was published on December 21, 1913 by Arthur Wynne. To celebrate the centennial of his great-great-grandfather's invention, John "Coward" Wynne<sup>1</sup> was struggling to make crossword puzzles. He was such a coward that whenever he thought of a tricky clue for a word, he couldnât stop worrying if people would blame him for choosing a bad clue that could never mean that word. At the end of the day, he cowardly chose boring clues, which made his puzzles less interesting.
</p>
<p>
One day, he came up with a brilliant idea: puzzles in which word meanings do not matter, and yet interesting. He told his idea to his colleagues, who admitted that the idea was intriguing. They even named his puzzles "Coward's Crossword Puzzles" after his nickname.
</p>
<p>
However, making a Coward's crossword puzzle was not easy. Even though he did not have to think about word meanings, it was not easy to check if a puzzle has one and only one set of answers. As the day of the centennial anniversary was approaching, John started worrying if he would not be able to make interesting ones in time. Let's help John by writing a program that solves Coward's crossword puzzles.
</p>
<p>
Each puzzle consists of <var>h</var> × <var>w</var> cells along with <var>h</var> across clues and <var>w</var> down clues. The clues are regular expressions written in a pattern language whose BNF syntax is given as in the table below.
</p>
<pre>
clue ::= "^" pattern "$"
pattern ::= simple | pattern "|" simple
simple ::= basic | simple basic
basic ::= elementary | elementary "*"
elementary ::= "." | "A" | "B" | ... | "Z" | "(" pattern ")"
</pre>
<center>
<span>
Table J.1. BNF syntax of the pattern language.
</span>
</center>
</br>
<p>
The clues (as denoted by p and q below) match words (as denoted by s below) according to the
following rules.
</p>
<ul>
<li><span>^</span><var>p</var><span>$</span> matches <var>s</var> if <var>p</var> matches <var>s</var>.</li>
<li><var>p</var><span>|</span><var>q</var> matches a string <var>s</var> if <var>p</var> and/or <var>q</var> matches <var>s</var>.</li>
<li><var>pq</var> matches a string <var>s</var> if there exist <var>s<sub>1</sub></var> and <var>s<sub>2</sub></var> such that <var>s<sub>1</sub>s<sub>2</sub></var> = <var>s</var>, <var>p</var> matches <var>s<sub>1</sub></var>, and <var>q</var> matches <var>s<sub>2</sub></var>.</li>
<li><var>p</var><span>*</span> matches a string <var>s</var> if <var>s</var> is empty, or there exist <var>s<sub>1</sub></var> and <var>s<sub>2</sub></var> such that <var>s<sub>1</sub>s<sub>2</sub></var> = <var>s</var>, <var>p</var> matches</li>
<li><var>s<sub>1</sub></var>, and <var>p</var><span>*</span> matches <var>s<sub>2</sub></var>.</li>
<li>Each of <span>A</span>, <span>B</span>, . . . , <span>Z</span> matches the respective letter itself.</li>
<li><span>(</span><var>p</var><span>)</span> matches <var>s</var> if <var>p</var> matches <var>s</var>.</li>
<li><span>.</span> is the shorthand of <span>(A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z)</span>.</li>
</ul>
<p>
Below is an example of a Cowardâs crossword puzzle with the answers filled in the cells.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_crosswordPuzzle" style="aling:center;width:240px"><br/>
</center>
<br/>
<p>
<b>Java Specific:</b> Submitted Java programs may not use classes in the java.util.regex package.<br/>
<b>C++ Specific:</b> Submitted C++ programs may not use the std::regex class.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each of which represents a puzzle given in the following format.
</p>
<pre>
<var>h</var> <var>w</var>
<var>p<sub>1</sub></var>
<var>p<sub>2</sub></var>
...
<var>p<sub>h</sub></var>
<var>q<sub>1</sub></var>
<var>q<sub>2</sub></var>
...
<var>q<sub>2</sub></var>
</pre>
<p>
Here, <var>h</var> and <var>w</var> represent the vertical and horizontal numbers of cells, respectively, where 2 ≤ <var>h,w</var> ≤ 4. The <var>p<sub>i</sub></var> and <var>q<sub>j</sub></var> are the across and down clues for the <var>i</var>-th row and <var>j</var>-th column, respectively. Any clue has no more than 512 characters.
</p>
<p>
The last dataset is followed by a line of two zeros. You may assume that there are no more than 30 datasets in the input.
</p>
<H2>Output</H2>
<p>
For each dataset, when the puzzle has a unique set of answers, output it as <var>h</var> lines of <var>w</var> characters. When the puzzle has no set of answers, or more than one set of answers, output "<span>none</span>" or "<span>ambiguous</span>" without double quotations, respectively.
</p>
<H2>Sample Input</H2>
<pre>
2 2
^(C|I|T|Y)*<span>$</span>
^(C|O|P|S)*<span>$</span>
^(F|L|I|P)*<span>$</span>
^(B|A|C|K)*<span>$</span>
2 2
^HE|LL|O*<span>$</span>
^(P|L|E|A|S|E)*<span>$</span>
^(H|L)*<span>$</span>
^EP|IP|EF<span>$</span>
4 4
^LONG|TALL|S*ALLY<span>$</span>
^(R*EV*|OL*U(TIO)*N)*<span>$</span>
^(STRAWBERRY|F*I*E*L*D*S*|FOREVER)*<span>$</span>
^P.S.|I|LOVE|YOU<span>$</span>
^(RE|A|L)((L|OV*E)*)<span>$</span>
^(LUC*Y*|IN.THE.SKY)(WITH|DI*A*M*ON*D*S*)<span>$</span>
^(IVE*|GOT|A|F*E*E*L*I*N*G*)*<span>$</span>
^YEST*E*R*D*A*Y*<span>$</span>
2 3
^(C|P)(OL|AS)<span>$</span>
^(LU|TO)(X|R)<span>$</span>
^CT|PL<span>$</span>
^OU|AO<span>$</span>
^SR|LX<span>$</span>
2 2
^T*|(HI)|S*<span>$</span>
^SE|NT|EN|CE<span>$</span>
^IS<span>$</span>
^(F|A|L|S|E)*<span>$</span>
2 4
^ARKA|BARB|COLU<span>$</span>
^NSAS|ADOS|MBIA<span>$</span>
^..<span>$</span>
^..<span>$</span>
^KA|RO|LI<span>$</span>
^AS|BA|US<span>$</span>
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
IC
PC
HE
LP
ALLY
OUNE
EDIS
LOVE
ambiguous
none
ARKA
NSAS
</pre>
<h2>Notes</h2>
<p>
<sup>1</sup> All characters appearing in this problem, except for Arthur Wynne, are fictitious. Any resemblance to real persons, living or dead, is purely coincidental.
</p> |
p00470 |
<H1>éå€çµè·¯ </H1>
<h2>åé¡</h2>
<p>
JOIãããäœãã«ããã®ããéœåžã¯ïŒååæ¹åã«ãŸã£ããã«äŒžã³ã w æ¬ã®éè·¯ãšïŒæ±è¥¿æ¹åã«ãŸã£ããã«äŒžã³ã h æ¬ã®éè·¯ã«ããïŒç¢ç€ã®ç®ã®åœ¢ã«åºåããããŠããïŒ
</p>
<p>
ååæ¹åã® w æ¬ã®éè·¯ã«ã¯ïŒè¥¿ããé ã« 1, 2, ... , w ã®çªå·ãä»ããããŠããïŒãŸãïŒæ±è¥¿æ¹åã® h æ¬ã®éè·¯ã«ã¯ïŒåããé ã« 1, 2, ... , h ã®çªå·ãä»ããããŠããïŒè¥¿ãã i çªç®ã®ååæ¹åã®éè·¯ãšïŒåãã j çªç®ã®æ±è¥¿æ¹åã®éè·¯ã亀ãã亀差ç¹ã (i, j) ã§è¡šãïŒ
</p>
<p>
JOIããã¯ïŒäº€å·®ç¹ (1, 1) ã®è¿ãã«äœãã§ããïŒäº€å·®ç¹ (w, h) ã®è¿ãã®äŒç€Ÿã«è»ã§éã£ãŠããïŒè»ã¯éè·¯ã«æ²¿ã£ãŠã®ã¿ç§»åããããšãã§ããïŒJOIããã¯ïŒé倿éãçãããããïŒæ±ãŸãã¯åã«ã®ã¿åãã£ãŠç§»åããŠéå€ããŠããïŒãŸãïŒãã®éœåžã§ã¯ïŒäº€éäºæ
ãæžããããã«ïŒæ¬¡ã®ãããªäº€éèŠåãèšããããŠããïŒ
</p>
<ul>
<li>
亀差ç¹ãæ²ãã£ãè»ã¯ïŒãã®çŽåŸã®äº€å·®ç¹ã§æ²ããããšã¯åºæ¥ãªãïŒ
</li>
</ul>
<p>
ããªãã¡ïŒäº€å·®ç¹ã§æ²ãã£ãããšã«1ãããã¯ã ãé²ãã§åã³æ²ããããšã¯èš±ãããªãïŒãã®ãšãïŒJOIããã®éå€çµè·¯ã¯äœéãèããããã ãããïŒ
</p>
<p>
w ãš h ãäžãããããšãïŒJOIããã®éå€çµè·¯ã®åæ°ã 100000 ã§å²ã£ãäœããåºåããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯1è¡ãããªãïŒç©ºçœãåºåããšããŠ2åã®æŽæ° w, h (2 ≤ w ≤ 100ïŒ 2 ≤ h ≤ 100) ãæžãããŠããïŒw ã¯ååæ¹åã®éè·¯ã®æ¬æ°ïŒ h ã¯æ±è¥¿æ¹åã®éè·¯ã®æ¬æ°ã衚ãïŒ
</p>
<p>
w, h ããšãã« 0 ã®ãšãå
¥åã®çµäºã瀺ã.ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ïŒJOIããã®éå€çµè·¯ã®åæ°ã 100000 ã§å²ã£ãäœãã1è¡ã«åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
3 4
15 15
0 0
</pre>
<h3>åºåäŸ</h3>
<pre>
5
43688
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2010-yo-t5-fig01"><br>1ã€ç®ã®å
¥åäŸã«ãããJOIããã®éå€çµè·¯ ( 5 éã)
</p>
<p>
1ã€ç®ã®å
¥åäŸã«ãããŠïŒJOIããã®éå€çµè·¯ã¯å³ã®ããã« 5 éãèããããïŒãããã£ãŠïŒ5ãåºåããïŒ
</p>
<p>
2ã€ç®ã®å
¥åäŸã«ãããŠïŒJOIããã®éå€çµè·¯ã¯ 143688 éãèããããïŒãããã£ãŠïŒ143688 ã 100000 ã§å²ã£ãäœãã§ãã 43688 ãåºåããïŒ
</p>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00020 |
<H1>Capitalize</H1>
<p>
Write a program which replace all the lower-case letters of a given text with the corresponding captital letters.
</p>
<H2>Input</H2>
<p>
A text including lower-case letters, periods, and space is given in a line. The number of characters in the text is less than or equal to 200.
</p>
<H2>Output</H2>
<p>
Print the converted text.
</p>
<H2>Sample Input</H2>
<pre>
this is a pen.
</pre>
<H2>Output for the Sample Input</H2>
<pre>
THIS IS A PEN.
</pre>
|
p00535 |
<h2>ç ã®å (Sandcastle)</h2>
<h2> åé¡</h2>
<p>
JOI åã¯å®¶æãšãšãã«æµ·æ°ŽæµŽã«æ¥ãïŒããããæ³³ãã§æ³³ãç²ãã JOI åã¯ïŒæ¬¡ã¯ç æµã§ç ã®åãäœã£ãŠéãã ïŒãã°ããããŠç éã³ã«ã飜ãããšïŒJOI åã¯åãæŸçœ®ããŠãŸãæµ·ã«æ³³ãã«åãã£ãïŒ
</p>
<p>
JOI åãäœã£ãåã¯ïŒç æµã®ãã¡ã®ããé·æ¹åœ¢ã®é åã«å«ãŸããŠããïŒãã®é·æ¹åœ¢ã®é åã¯ïŒæ±è¥¿ååã«ãã¹ç®ç¶ã«åºåãããŠããïŒåãã¹ã¯ïŒJOI åãäœã£ãåã®äžéšã§ãããã¹ (以äžïŒãåãã¹ããšåŒã¶) ãããã§ãªããã¹ (以äžïŒãæŽå°ãã¹ããšåŒã¶) ã®ããããã§ããïŒããããã®åãã¹ã«ã¯ã匷床ããšåŒã°ãã 1 ä»¥äž 9 以äžã®æŽæ°ãå®ãŸã£ãŠããïŒé·æ¹åœ¢ã®é åã®å€çžéšïŒããªãã¡å€åŽãšæ¥ããŠãããã¹ã«ã¯åãã¹ã¯ååšããªãïŒ
</p>
<p>
ãããŠæœ®ãæºã¡ãŠããŠïŒé·æ¹åœ¢ã®é åã«ãæ³¢ãæŒãå¯ããŠããããã«ãªã£ãïŒæ³¢ã 1 ã€æŒãå¯ããŠãããã³ã«ïŒåãã¹ã®ãã¡æ¬¡ã®æ¡ä»¶ãæºãããã®ã¯ãã¹ãŠäžæã«åŽ©å£ããŠïŒæŽå°ãã¹ã«å€åããïŒ
</p>
<ul>
<li>æ¡ä»¶ïŒ åšå²ã® 8 ãã¹ (æ±è¥¿ååããã³åæ±ïŒå西ïŒåæ±ïŒå西æ¹åã«é£æ¥ãããã¹) ã«ããæŽå°ãã¹ã®æ°ãïŒãã®ãã¹ã®åŒ·åºŠã®å€ä»¥äžã§ããïŒ
</li>
</ul>
<p>
æ³¢ãåŒããšïŒãŸããªãæ¬¡ã®æ³¢ãæŒãå¯ããŠæ¥ãïŒ
</p>
<p>
ååå€ãã®æ³¢ãæŒãå¯ãããšïŒåããã¹ãŠåŽ©ããŠããŸããïŒäžå€«ãªéšåã ããæ®ããããŠïŒæ³¢ãæŒãå¯ããŠããŠã 1 ã€ãåãã¹ã厩å£ããªããããªç¶æ
ã«èœã¡çãïŒ1 ã€ä»¥äžã®åãã¹ã厩å£ããããããªæ³¢ãæŒãå¯ããŠããåæ°ãæ±ããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠1 + H è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯ïŒ2 ã€ã®æŽæ° H, W (2 ≤ H ≤ 1000, 2 ≤ W ≤ 1000) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒé·æ¹åœ¢ã®é åã瞊 H è¡ïŒæšª W åã® H × W åã®ãã¹ã«åºåãããŠããããšã衚ãïŒé·æ¹åœ¢ã®çžŠæ¹åã¯ååæ¹åã§ããïŒæšªæ¹åã¯æ±è¥¿æ¹åã§ããïŒ
</p>
<p>
ç¶ã H è¡ã«ã¯ãããã W æåãããªãæååãæžãããŠããïŒæåã®æ³¢ãæŒãå¯ããŠããåã®é·æ¹åœ¢ã®é åã®ç¶æ
ã衚ãïŒH è¡ã®ãã¡ã® i è¡ç®ã®å·Šãã j çªç®ã®æå (1 ≤ i ≤ H, 1 ≤ j ≤ W) ã¯ïŒé·æ¹åœ¢ã®é åã®åãã i è¡ç®ïŒè¥¿ãã j åç®ã®ãã¹ãæŽå°ãã¹ã§ããå Žå㯠'.' (ããªãªã) ã§ããïŒåãã¹ã§ããå Žå㯠'1', '2', ..., '9' ã®ããããã§ããïŒãã®ãã¹ã®åŒ·åºŠã衚ãïŒ
</p>
<p>
é·æ¹åœ¢ã®é åã®å€çžéšã¯ãã¹ãŠæŽå°ãã¹ã§ããïŒããªãã¡ïŒãã¹ãŠã®å
¥åã«ãããŠïŒ1 è¡ç®ãŸã㯠H è¡ç®ã®æåãšïŒåè¡ã®å·Šãã 1 çªç®ãŸã㯠W çªç®ã®æåã¯ãã¹ãŠ '.' ã§ããïŒ
</p>
<p>
äžããããå
¥åããŒã¿ã®ãã¡ïŒå
¥å 1 ã§ã¯ H ≤ 50, W ≤ 50 ãæºããïŒ
</p>
<h2>åºå</h2>
<p>
1 ã€ä»¥äžã®åãã¹ã厩å£ããããããªæ³¢ãæŒãå¯ããŠããåæ°ã 1 è¡ã§åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5 6
......
.939..
.3428.
.9393.
......
</pre>
<h3>åºåäŸ 1</h3>
<pre>
3
</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
10 10
..........
.99999999.
.9.323239.
.91444449.
.91444449.
.91444449.
.91444449.
.91232329.
.99999999.
..........
</pre>
<h3>åºåäŸ 2</h3>
<pre>
35
</pre>
<p>
å
¥åºåäŸ 1 ã«ãããŠã¯ïŒåãã«æŒãå¯ããæ³¢ã§åŒ·åºŠ 3 ã®åãã¹ããã¹ãŠåŽ©å£ãïŒ<br>
</p>
<pre>
......
.9.9..
..428.
.9.9..
......
</pre>
<p>
ãšããç¶æ
ã«ãªãïŒ
</p>
<p>
æ¬¡ã«æŒãå¯ããŠããæ³¢ã§ã¯åŒ·åºŠ 2 ã®åãã¹ã厩å£ãïŒ
</p>
<pre>
......
.9.9..
..4.8.
.9.9..
......
</pre>
<p>
ãšããç¶æ
ã«ãªãïŒ
</p>
<p>
æ¬¡ã«æŒãå¯ããŠããæ³¢ã§ã¯åŒ·åºŠ 4 ã®åãã¹ã厩å£ãïŒ
</p>
<pre>
......
.9.9..
....8.
.9.9..
......
</pre>
<p>
ãšããç¶æ
ã«ãªãïŒ
</p>
<p>
ãã以éã®æ³¢ãåãã¹ã厩ãããšã¯ãªãïŒãã£ãŠçã㯠3 ã§ããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00165 |
<H1>å®ãã</H1>
<p>
ããåœã®çæ§ã¯çŽ æ°ãšã®ã£ã³ãã«ã倧奜ãã§ãããã®åœã®é貚ã®åäœã¯ãã©ã€ã ãšãããŸãã2007 幎 11 æ 1 æ¥çŸåšã®ãã©ã€ã ã®ã¯ãã¹åã¬ãŒã㯠9973 ãšã¡ããã©çŽ æ°ã«ãªã£ãŠããã®ã§ãçæ§ã¯å€§åã³ã§ãããã®åœã§ã¯ 1/101 ãã©ã€ã ã1ãµããã©ã€ã ãšããè£å©è²šå¹£ã䜿ãããŠããŸãã
</p>
<p>
ãã®åœã®æ¿åºã¯ãåœå®¶è²¡æ¿ã®å®å®ãåœæ°ã®å𝿥œãçæ§ã®è¶£å³ãåæã«æºè¶³ãããããšãç®çã«å®ããæ¯èå
¬ç€Ÿãèšç«ããå®ããäºæ¥ãå§ããããšã«ããŸãããçŽ æ°ã倧奜ããªçæ§ã¯ãçŽ æ°ã話é¡ã«ãªãã°ããã ãã§æºè¶³ããŠãè³éããããããªããŸããããã§æ¯èå
¬ç€Ÿã¯æ¬¡ã®ãããªå®ãããèããŸããã
</p>
<ul>
<li>ããã«ã¯ 0 ãã <var>MP</var> ãŸã§ã®äžé£ã®çªå·ãã€ããããŠããã<var>MP</var> ã¯ãã®åœã§ç¥ãããŠããæå€§ã®çŽ æ°ã§ãæ¯æäžæ¥ã«å®å ±ã§å瀺ããããåæã«ã<var>MP</var> 以äžã®ãã¹ãŠã®çŽ æ°ãçºè¡šãããããã以äžå€§ããªçŽ æ°ãçºèŠãããŠãããã®æã®éã¯ãå®ããæ¯èå
¬ç€Ÿãå«ãå
šãŠã®å
¬çãªæ©é¢ã§ã¯ãäžæ¥ã«çºè¡šããã<var>MP</var> ãæå€§ã®çŽ æ°ãšããŠæ±ãã2007 幎 11 æ 1 æ¥ ã«ã¯<var>MP</var> = 999983 (1000000 以äžã®æå€§ã®çŽ æ°) ãçºè¡šãããã</li>
<li>å®ããã®è²©å£²äŸ¡æ Œã¯ 1 ãµããã©ã€ã ã</li>
<li>å®ããã®æœéžã§ã¯ãåœããããã®çªå· <var>p</var> ãšè³éç®åºã®ããã®æ° <var>m</var> ã®çµ(<var>p</var>, <var>m</var>) ãäœçµãéžã°ããã<var>p</var>, <var>m</var> ã¯ãããã0 ä»¥äž <var>MP</var> 以äžã®æŽæ°ã</li>
<li>ãã®åœã§ç¥ãããŠããçŽ æ°ã®äžã§ <var>p</var> - <var>m</var> ä»¥äž <var>p</var> + <var>m</var> 以äžã®ãã®ã <var>X</var> åãããšãããšãæœéžçµæ(<var>p</var>, <var>m</var>) ã®è³éã¯ã<var>X</var> ãã©ã€ã ãšãªãã</li>
<li>æœéžçµæ (<var>p</var>, <var>m</var>) ã®è³é <var>X</var> ãã©ã€ã ã¯çªå· <var>p</var> ã®å®ãããæã£ãŠããåœéžè
ã«æ¯æããããã<var>X</var> = 0 ã®å Žåãããããã®å Žåã«ã¯åœéžè
ã«ã¯è³éã¯æ¯æãããªãã</li>
<li>è³éã®ãã¡ 1 ãã©ã€ã ã¯å®ããã®å£²ãäžãããæ¯åºããã<var>X</var> - 1 ãã©ã€ã ã¯çæ§ã®å
å»·è²»ããæ¯åºãããïŒçæ§ãæã£ãŠãããïŒã<var>X</var> = 0 ãªãã°å®ããã®å£²ãäžããã 1 ãã©ã€ã ãå
å»·è²»ã«ç¹°ãå
¥ãããããïŒçæ§ã«å¯Ÿãæ¯æãããïŒ</li>
<li>ã²ãšã€ã®çªå· <var>p</var> ãè€æ°ã®åœããããã«ãªãããšãããããã®å Žåã«ã¯ããããã®æœéžçµæ(<var>p</var>, <var>m</var>) ããç®åºãããè³éã®åèšãåœéžè
ã«æ¯æãããã</li>
</ul>
<p>
ãã®ããã§ã¯åœãããããè²·ã£ãäººã¯æœéžçµæããé¢ä¿ããçŽ æ°ãæ¢ãããã®åæ°ãæ°ããã®ã§ãåœæ°ã®è©±é¡ã«çŽ æ°ãããåºãŠããŠçæ§ã¯ãšãŠããæºæŠã§ããå®ããæ¯èå
¬ç€ŸãšããŠã¯åœãããã1æ¬åœããå
¬ç€Ÿè² æ
ã 1 ãã©ã€ã ãè²©å£²äŸ¡æ Œã 1 ãµããã©ã€ã ã ãããåœããããã®æ¬æ° <var>n</var> ãã販売ããå®ãã 101 æ¬ããã 1 æ¬ä»¥äžãšãªãããã«ããã° (ããªãã¡ã<var>n</var> ≤ (販売ããæ¬æ°)/101 ãšããã°) èµ€åã«ã¯ãªããŸããã
</p>
<!--
<p>
åé¡ã¯å
å»·è²»ããã®æ¯åºé¡ã§ããå®ããæ¯èå
¬ç€Ÿã®æŽä»£ã®ç·è£ã¯çæ§ã®ãåŠåã§ãã¿ããªçæ§ãšåæ§ã«çŽ æ°ã倧奜ãã§ãããåœããããã«å¯Ÿããå
å»·è²»ããã®æ¯åºé¡ã決ããäŒè°ã楜ããã§ããŸããããšããã2007幎ã®äººäºç°åã§ãåŠåã§ã¯ãªãã圹人ãç·è£ã«å°±ä»»ããŸãããäžå¹žãªããšã«ãã®ç·è£ã¯çæ§ã®ããšã¯ååã«å°æ¬ããŠããŸãããæ°åŠãèŠæã§ãçŽ æ°ã®è©±ãèããšããã«é³¥èãç«ã¡ãŸããããã§ããªãã¯ãã®äžå¹žãªæ°ç·è£ã®ã¢ã·ã¹ã¿ã³ããšãªã£ãŠãæœéžçµæãå
¥åãšããŠã2007幎11æã«ãããå®ããæ¯èå
¬ç€Ÿãçæ§ã«è«æ±ããè³éã®é¡ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããæœéžçµæã®æ° n ã¯1以äž1000000以äžã§ãããè«
æ±ããè³éã®é¡ãè² ã«ãªãããšã¯ãªããã®ãšããŸãã
</p>
-->
<p>
åé¡ã¯å
å»·è²»ããã®æ¯åºé¡ã§ããããªãã®ä»äºã¯ãæœéžçµæãå
¥åãšããŠã2007 幎 11 æã«ãããå®ããæ¯èå
¬ç€Ÿãçæ§ã«è«æ±ããè³éã®é¡ãåºåããããã°ã©ã ãäœæããããšã§ãããã ããè«æ±ããè³éã®é¡ãè² ã«ãªãããšã¯ãªããã®ãšããŸãã
</p>
<p>泚æ</p>
<ul>
<li>ãã®åœã«ãããçŽ æ°ã®å®çŸ©ãæ¥æ¬ã®åŠæ ¡æè²ã§åŠç¿ããå
容ãšåãã§ããå³ã¡ãçŽ æ°ãšã¯ 1 ãšèªåèªèº«ä»¥å€ã®çŽæ°ãæããªãèªç¶æ°ããããŸãïŒãªãã1 ã¯çŽ æ°ã§ã¯ãããŸããïŒã</li>
<li>æã
㯠1000003 ãçŽ æ°ã§ããããšãç¥ã£ãŠããŸããããã®åœã§ã¯ 2007 幎 11 ææ®µéã§ã¯ç¥ãããŠããŸããããã®ããã999963 ä»¥äž 1000003 以äžã®ç¯å²ã«ãããã®åœã§ç¥ãããŠããçŽ æ°ã¯ 999983 ãš 999979 ã® 2 åãããããŸããã</li>
</ul>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>p<sub>1</sub></var> <var>m<sub>1</sub></var>
<var>p<sub>2</sub></var> <var>m<sub>2</sub></var>
:
<var>p<sub>n</sub></var> <var>m<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«æœéžçµæã®æ° <var>n</var> (1 ≤ <var>n</var> ≤ 1000000)ãç¶ã <var>n</var> è¡ã« <var>i</var> çªç®ã®æœéžçµæã®æ
å ± <var>p<sub>i</sub></var>, <var>m<sub>i</sub></var> ã空çœåºåãã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«çæ§ãžã®è«æ±é¡ããã©ã€ã åäœïŒæŽæ°ïŒã§ïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
4
5 0
9 1
3 10
11 3
1
999983 20
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
1
</pre>
|
p02158 | <h1>Problem J: Rings</h1>
<h2>Problem</h2>
<p>ãšããæ°Žæé€šã«äœãã€ã«ã«åã¯ããžã£ã³ããããŠ$N$åã®ãªã³ã°ããããæãããšãè€çŸãããããŸãã</p>
<ul>
<li>ã€ã«ã«åã¯åº§æš$(0,0)$ããé£ã³ã$(T,0)$ã§çæ°Žããã</li>
<li>ãžã£ã³ãã®è»éã¯æŸç©ç·ã§ããã</li>
<li>$i$çªç®ã®ãªã³ã°ã¯ããžã£ã³ãã®è»éã$(X_i,L_i)$ãš$(X_i,H_i)$ãçµã¶ç·åãšäº€ãããšããããæãããšå€å®ãããã</li>
<li>$1$åã®ãžã£ã³ãã«ã¯åéãšåãã ãã®äœåãå¿
èŠã§ããã</li>
</ul>
<p>ã€ã«ã«åã¯ãå¿
èŠã§ããã°äœåºŠã§ããžã£ã³ããããããšãã§ããŸããéåå é床ãã¯ãã«ã$(0,-1)$ãšããŠãã€ã«ã«åãå
šãŠã®ãªã³ã°ãéãæããããã«å¿
èŠãªäœåã®åèšã®æå°å€ãæ±ããŠãã ããããã ããæ©æŠãç©ºæ°æµæã¯ç¡èŠã§ããã»ã©å°ãããšããŸãã</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$T$ $N$
$X_1$ $L_1$ $H_1$
$\vdots$
$X_N$ $L_N$ $H_N$
</pre>
<p>ãŸã$1$è¡ã«$T$ãš$N$ãäžããããããã®åŸ$N$è¡ã«$i$çªç®ã®ãªã³ã°ã®äœçœ®ã$X_i$ã$L_i$ã$H_i$ãäžããããã</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>å
¥åã¯ãã¹ãп޿°ã§ããã</li>
<li>$1 \le X_i < T \le 10^6$</li>
<li>$1 \le N \le 10^5$</li>
<li>$1 \le L_i < H_i \le 10^6$</li>
</ul>
<h2>Output</h2>
<p>çããäžè¡ã«åºåããã絶察誀差ãŸãã¯çžå¯Ÿèª€å·®ã$10^{-9}$以äžã®å Žåæ£çãšå€å®ãããã</p>
<h2>Sample Input 1</h2>
<pre>
100 5
50 1 5
50 5 10
50 20 30
50 40 60
50 61 1000000
</pre>
<h2>Sample Output 1</h2>
<pre>
48.6090201099
</pre>
<p>ç¹$(50,5)$ãéãããã«é£ã¶ãšã$1$çªç®ãš$2$çªç®ã®ãªã³ã°ãåæã«ãããããšãã§ããŸãã</p>
<h2>Sample Input 2</h2>
<pre>
64 15
38 133177 927361
48 177920 668766
12 680425 790550
43 6853 384115
17 214954 723798
62 63843 153825
28 399349 482937
2 336136 367001
33 138008 733496
6 203462 911631
58 321974 527734
17 696940 781678
55 265874 507640
41 56037 880001
34 279422 528651
</pre>
<h2>Sample Output 2</h2>
<pre>
6087.909851326286
</pre>
|
p03319 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a sequence of length <var>N</var>: <var>A_1, A_2, ..., A_N</var>. Initially, this sequence is a permutation of <var>1, 2, ..., N</var>.</p>
<p>On this sequence, Snuke can perform the following operation:</p>
<ul>
<li>Choose <var>K</var> consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.</li>
</ul>
<p>Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K \leq N \leq 100000</var></li>
<li><var>A_1, A_2, ..., A_N</var> is a permutation of <var>1, 2, ..., N</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>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 minimum number of operations required.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 3
2 3 1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One optimal strategy is as follows:</p>
<ul>
<li>
<p>In the first operation, choose the first, second and third elements. The sequence <var>A</var> becomes <var>1, 1, 1, 4</var>.</p>
</li>
<li>
<p>In the second operation, choose the second, third and fourth elements. The sequence <var>A</var> becomes <var>1, 1, 1, 1</var>.</p>
</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2 3
</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>8 3
7 3 1 8 4 6 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p01324 |
<h1><font color="#000">Problem D:</font> ç¡ççŸãªåäœç³»</h1>
<pre>
京ãåã{犟äº}ãç©£ãæºãæŸãæ£ãèŒãæ¥µãææ²³æ²ãé¿å§ç¥ãé£ç±ä»ãäžå¯æè°ãç¡é倧æ°
åãåãæ¯ã糞ã応ã埮ãç¹ãæ²ã塵ãåãæžºãæŒ ãæš¡ç³ãé¡å·¡ãé èŸãç¬æ¯ã匟æãå¹é£ãå
埳ãèç©ºãæž
æµãé¿é Œè¶ãé¿æ©çŸ
ãæ¶
æ§å¯é
</pre>
<p>ããããäœãåããã ãããããããã¯å
šãŠ10ã®çޝä¹ã«ã€ããããæ°è©ã§ããã</p>
<pre>
京 = 10<sup>16</sup>, å = 10<sup>20</sup>, {犟äº} = 10<sup>24</sup>, ç©£ = 10<sup>28</sup>, æº = 10<sup>32</sup>, ...
å = 10<sup>-1</sup>ãå = 10<sup>-2</sup>ãæ¯ = 10<sup>-3</sup>ã糞 = 10<sup>-4</sup>ã応 = 10<sup>-5</sup>, ...</pre>
<p>ã§ã¯ããããå®çšçã«äœ¿ãããŠããã®ãèŠãããšã¯ããã ãããïŒç¡ãã®ã§ã¯ãªããããïŒ éå»ã®å
人éãçèã®æ«ã«ãããã®åœåãè¡ã£ãã«ããããããããããã®æ°è©ãæ¥ã®ç®ãèŠãããªããšã¯ãªããšå¿äœç¡ãããšã ããã</p>
<p>ãã®åé¡ã¯ãã³ã³ãã¹ãåå è
ã®çæ§ã«ãããã®æ°è©ãç¥ã£ãŠãããããã«äœããããã®ã§ããã以äžã«åé¡ã®æŠèŠã瀺ãã</p>
<pre>1 km = 10<sup>3</sup> m</pre>
<p>äžèšã®ãããªåäœéã®é¢ä¿ãå
¥åãšããŠäžããããããã®åé¡ã§ã¯ã巊蟺ã«ãããåäœãå³èŸºã«ãããåäœã®10ã®çޝä¹åãšãªã£ãŠãããããªåäœéã®é¢ä¿ã ããäžããããã
åäœéã®é¢ä¿ãççŸããŠãããšã¯ãäžããããé¢ä¿ãã以äžã®é¢ä¿ãåæã«æãç«ã€ããšãããã</p>
<pre>
1 A = 10<sup>x</sup> B
1 A = 10<sup>y</sup> B
</pre>
<p>
ãã ãã x≠yã§ããã AãšBã¯ä»»æã®åäœã
</p>
<p>å
¥åãšããŠäžããããåäœéã®é¢ä¿ãççŸããŠãããã©ããå€å®ããã ãªããå
¥åã¯ç°¡æã®ããææ°è¡šèšã§äžããããã
</p>
<h2>Input</h2>
<p>å
¥åã®äžè¡ç®ã«ãåäœéã®é¢ä¿ã®åæ°ãç€ºãæŽæ° N (1≤ N ≤ 100) ãäžããããã</p>
<p>ç¶ãNè¡ã«ãåäœéã®é¢ä¿ãå«ãŸããã
åäœéã®é¢ä¿ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã</p>
<p>"1 A = 10^x B"</p>
<p>A, B ã¯åäœã瀺ããAãšBã¯çžç°ãªã£ãŠããããããã空çœãå«ãŸãªãã¢ã«ãã¡ãããå°æå1ã16æåãããªããx 㯠-100ãã100ãŸã§ã®æŽæ°ã§ããã
"1 A = 10^x B" ãå®çŸ©ããããšãã "1 B = 10^-x A" ãæé»ã®ãã¡ã«å®çŸ©ãããŠãããã®ãšããã</p>
<p>
ä»»æã®åäœç³»ã®ãã¢ã2å以äžå®çŸ©ãããããšã¯ãªãã
ããªãã¡ã"1 kilobyte = 10^3 byte", "1 kilobyte = 10^1 byte" ã®ãããªé¢ä¿ããåæã«å
¥åã«å«ãŸããããšã¯ãªãã
åæ§ã«ã"1 kilobyte = 10^3 byte", "1 byte = 10^-3 kilobyte" ã®ãããªé¢ä¿ããåæã«å
¥åã«å«ãŸããããšã¯ãªãã
</p>
<h2>Output</h2>
<p>äžããããåäœç³»ãççŸããŠããªããã° Yes ãã ççŸããŠããã° No ãåºåããã
</p>
<h2>Notes on Test Cases</h2>
<p>
äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã
</p>
<p>
N ã 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã
</p>
<!--
<h2>Sample Input 1</h2>
<pre>3
1 km = 10^3 m
1 m = 10^2 cm
1 km = 10^5 cm
</pre>
<h2>Output for Sample Input 1</h2>
<pre>Yes
</pre>
<h2>Sample Input 2</h2>
<pre>7
1 kilometre = 10^3 metre
1 megametre = 10^3 kilometre
1 metre = 10^-6 megametre
1 terametre = 10^3 gigametre
1 petametre = 10^3 terametre
1 gigametre = 10^-6 petametre
1 metre = 10^-15 petametre
</pre>
<h2>Output for Sample Input 2</h2>
<pre>Yes
</pre>
<h2>Sample Input 3</h2>
<pre>4
1 a = 10^2 b
1 a = 10^3 c
1 b = 10^2 c
1 c = 10^1 d
</pre>
<h2>Output for Sample Input 3</h2>
<pre>No
</pre>
<h2>Sample Input 4</h2>
<pre>4
1 acm = 10^2 icpc
1 icpc = 10^3 utpc
1 utpc = 10^4 topcoder
1 topcoder = 10^-1 acm
</pre>
<h2>Output for Sample Input 4</h2>
<pre>No
</pre>
-->
<h2>Sample Input</h2>
<pre>
3
1 km = 10^3 m
1 m = 10^2 cm
1 km = 10^5 cm
7
1 kilometre = 10^3 metre
1 megametre = 10^3 kilometre
1 metre = 10^-6 megametre
1 terametre = 10^3 gigametre
1 petametre = 10^3 terametre
1 gigametre = 10^-6 petametre
1 metre = 10^-15 petametre
4
1 a = 10^2 b
1 a = 10^3 c
1 b = 10^2 c
1 c = 10^1 d
4
1 acm = 10^2 icpc
1 icpc = 10^3 utpc
1 utpc = 10^4 topcoder
1 topcoder = 10^-1 acm
0
</pre>
<h2>Output for Sample Input</h2>
<pre>
Yes
Yes
No
No
</pre>
|
p03749 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino has a bar of length <var>N</var>, which has <var>M</var> marks on it.
The distance from the left end of the bar to the <var>i</var>-th mark is <var>X_i</var>.</p>
<p>She will place several squares on this bar.
Here, the following conditions must be met:</p>
<ul>
<li>Only squares with integral length sides can be placed.</li>
<li>Each square must be placed so that its bottom side touches the bar.</li>
<li>The bar must be completely covered by squares.
That is, no square may stick out of the bar, and no part of the bar may be left uncovered.</li>
<li>The boundary line of two squares may not be directly above a mark.</li>
</ul>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/agc013/placing_example.jpg">
<p>Examples of arrangements that satisfy/violate the conditions</p>
</img></div>
<p>The <em>beauty</em> of an arrangement of squares is defined as the <strong>product</strong> of the areas of all the squares placed.
Joisino is interested in the sum of the beauty over all possible arrangements that satisfy the conditions.
Write a program to find it.
Since it can be extremely large, print the sum modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 \leq N \leq 10^9</var></li>
<li><var>0 \leq M \leq 10^5</var></li>
<li><var>1 \leq X_1 < X_2 < ... < X_{M-1} < X_M \leq N-1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>X_1</var> <var>X_2</var> <var>...</var> <var>X_{M-1}</var> <var>X_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the beauty over all possible arrangements that satisfy the conditions, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>13
</pre>
<p>There are two possible arrangements:</p>
<ul>
<li>Place a square of side length <var>1</var> to the left, and place another square of side length <var>2</var> to the right</li>
<li>Place a square of side length <var>3</var></li>
</ul>
<p>The sum of the beauty of these arrangements is <var>(1 \times 1 \times 2 \times 2) + (3 \times 3) = 13</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>66
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 9
1 2 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>693316425
</pre></section>
</div>
</span> |
p01774 |
<h2>C: Digital Clock / ããžã¿ã«æèš</h2>
<h3>ç©èª</h3>
<p>ãããã«ããã¯æè¿ïŒé¢šéªãåŒããŠããŸã£ãïŒããŸãã®ã ããã«ãããããåºãããªãïŒèŸããã«ããŠããå§¿ããŸãããããïŒ</p>
<p>ãããæã§æã§ä»æ¹ããªããããã«ããã¯ïŒæäžã«ããããžã¿ã«æèšã§éã¶æ¹æ³ãèãã€ããïŒäžã®å³ã®ãããªããžã¿ã«æèšã®å
ã£ãŠããæ£ã®æ¬æ°ãæ¯ç§æ¯ç§ïŒãã ã²ãããã«æ°ããã®ã§ããïŒ</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital"></img>
<p>äœæéããã®éã³ãç¶ããé ïŒãããã«ããã¯æéãéã£ãŠããŠãå
ã£ãŠããæ£ã®æ¬æ°ãçããå Žåãããããšã«æ°ã¥ããïŒå
ã£ãŠããæ£ã®æ¬æ°ãçããæéãäœéãããã®ãæ°ã«ãªã£ããããã«ããã¯ïŒçç
äžã®ããªãã«æ°ããŠããããããé¡ãããŠããïŒ</p>
<p>ãããããåºãããªããããã«ããã®ããã«ïŒããªãã¯ããã°ã©ã ãæžããŠæ±ããããšã«ããïŒ</p>
<h3>åé¡</h3>
<p>å¹Žææ¥ïŒããã³æåç§ã衚瀺ããäžå³ã®ãããªããžã¿ã«æèšãããïŒå
ã£ãŠããæ£ã®æ¬æ°ãã¡ããã© <var>N</var> æ¬ã«ãªãå¹Žææ¥æåç§ãäœéããããçããïŒãã ãïŒããžã¿ã«æèšã¯äžéšå£ããŠããããïŒçµ¶å¯Ÿå
ããªãæ£ãäœç®æãããïŒå
ããªãæ£ã«ãã£ãŠåã衚瀺ã«èŠããå Žåã§ãïŒè¡šç€ºããããšããå¹Žææ¥æåç§ãç°ãªãå Žåã¯å¥ã«æ°ããããšã«æ³šæããïŒ</p>
<p>åæ°åã®å
ãç®æã¯æ¬¡ã®å³ã«ç€ºãéãã§ããïŒ</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital_number"></img>
<p>
ããžã¿ã«æèšã¯è¥¿æŠã0è©°ã4æ¡ïŒ0000幎ã9999幎ïŒïŒæïŒæ¥ïŒæïŒåïŒç§ããããã0è©°ã2æ¡ã§è¡šç€ºããïŒ
</p>
<p>
æã¯1æ¥ããå§ãŸãïŒ4, 6, 9, 11æã¯30æ¥ãŸã§ïŒ1, 3, 5, 7, 8, 10, 12æã¯31æ¥ãŸã§ã§ããïŒ2æã¯éåžž28æ¥ãŸã§ã ãïŒé幎ã«ã¯29æ¥ãŸã§ãšãªãïŒããã§é幎ãšã¯ïŒæ¬¡ã®ãããªå¹Žã§ããïŒ
</p>
<ol type="1">
<li> 西æŠã400ã§å²ãåãã幎ã¯é幎ã§ããïŒ</li>
<li> 西æŠã400ã§å²ãåããªããïŒ100ã§å²ãåãã幎ã¯é幎ã§ã¯ãªãïŒ</li>
<li> 西æŠã100ã§å²ãåããªããïŒ4ã§å²ãåãã幎ã¯é幎ã§ããïŒ</li>
<li> 西æŠã4ã§å²ãåããªã幎ã¯é幎ã§ã¯ãªãïŒ</li>
</ol>
<p>æéã¯0æãã23æãŸã§ïŒåã¯0åãã59åãŸã§ïŒç§ã¯0ç§ãã59ç§ãŸã§ã§ããïŒéç§ã«é¢ããŠã¯èããªããŠããïŒ</p>
<h3>å
¥å圢åŒ</h3>
<p>1è¡ç®ã«å
ã£ãŠããæ£ã®æ¬æ° <var>N</var> (<var>0 ≤ N ≤ 98</var>) ãäžããããïŒ</p>
<p>2è¡ç®ã«å£ããŠå
ããªãç®æã®åæ° <var>K</var> (<var>0 ≤ K ≤ 98</var>) ãäžãããïŒç¶ã㊠<var>K</var> è¡ã«å£ããŠããç®æã®æ
å ±ãäžããããïŒ<var>K</var> è¡ã®ãã¡ <var>i</var> è¡ç®ã«ã¯ïŒ<var>i</var> çªç®ã®å£ããŠããæ£ã®æ¡ <var>p_i</var> (<var>0 ≤ p_i ≤ 13</var>) ãšäœçœ® <var>q_i</var> (<var>0 ≤ q_i ≤ 6</var>) ã空çœåºåãã§äžããããïŒ</p>
<p>æ¡ãšã¯ïŒæ¬¡ã®å³ã®ãããªããžã¿ã«æèšã®åæ°åã«å²ãåœãŠãããIDã§ããïŒäžäœã®æ°åããé ã«0ãã13ãŸã§ãå²ãåœãŠãçªå·ã®ããšã§ããïŒ</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital_num_id"></img>
<p>ãŸãïŒæ£ã®äœçœ®ãšã¯æ¬¡ã®å³ã®ãããªåæ°åäžã«ãããæ£ã®IDã§ããïŒäžã®æ£ããé ã«0ãã6ãŸã§ã®æ°åãå²ãåœãŠãçªå·ã®ããšã§ããïŒ</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital_bar_id"></img>
<h3>åºå圢åŒ</h3>
<p>å
ã£ãŠããæ£ã®æ¬æ°ãã¡ããã© <var>N</var> æ¬ã«ãªãå¹Žææ¥æåç§ã®ç·æ°ã1è¡ã«åºåããïŒ</p>
<h3>å
¥åäŸ1</h3>
<pre>
28
0
</pre>
<h3>åºåäŸ1</h3>
<pre>1</pre>
<p>1111幎11æ11æ¥11æ11å11ç§ã®1éãã§ããïŒ</p>
<h3>å
¥åäŸ2</h3>
<pre>
28
1
2 0
</pre>
<h3>åºåäŸ2</h3>
<pre>2</pre>
<p>1171幎11æ11æ¥11æ11å11ç§ ãš 1111幎11æ11æ¥11æ11å11ç§ ã®2éãã§ããïŒ</p>
<h3>å
¥åäŸ3</h3>
<pre>
98
1
3 0
</pre>
<h3>åºåäŸ3</h3>
<pre>0</pre>
<h3>å
¥åäŸ4</h3>
<pre>
60
1
3 0
</pre>
<h3>åºåäŸ4</h3>
<pre>13362470370</pre> |
p00866 |
<H1><font color="#000">Problem C:</font> Stopped Watches</H1>
<p>
In the middle of Tyrrhenian Sea, there is a small volcanic island called Chronus. The island
is now uninhabited but it used to be a civilized island. Some historical records imply that the
island was annihilated by an eruption of a volcano about 800 years ago and that most of the
people in the island were killed by pyroclastic flows caused by the volcanic activity. In 2003, a
European team of archaeologists launched an excavation project in Chronus Island. Since then,
the project has provided many significant historic insights. In particular the discovery made
in the summer of 2008 astonished the world: the project team excavated several mechanical
watches worn by the victims of the disaster. This indicates that people in Chronus Island had
such a highly advanced manufacturing technology.
</p>
<p>
Shortly after the excavation of the watches, archaeologists in the team tried to identify what
time of the day the disaster happened, but it was not successful due to several difficulties. First,
the extraordinary heat of pyroclastic flows severely damaged the watches and took away the
letters and numbers printed on them. Second, every watch has a perfect round form and one
cannot tell where the top of the watch is. Lastly, though every watch has three hands, they
have a completely identical look and therefore one cannot tell which is the hour, the minute,
or the second (It is a mystery how the people in Chronus Island were distinguishing the three hands. Some archaeologists
guess that the hands might be painted with different colors, but this is only a hypothesis, as the paint was lost
by the heat.
). This means that we cannot decide the time indicated by a watch uniquely;
there can be a number of candidates. We have to consider different rotations of the watch.
Furthermore, since there are several possible interpretations of hands, we have also to consider
all the permutations of hands.
</p>
<p>
You are an information archaeologist invited to the project team and are asked to induce the
most plausible time interval within which the disaster happened, from the set of excavated
watches.
</p>
<p>
In what follows, we express a time modulo 12 hours. We write a time by the notation <i>hh</i>:<i>mm</i>:<i>ss</i>,
where <i>hh</i>, <i>mm</i>, and <i>ss</i> stand for the hour (<i>hh</i> = 00, 01, 02, . . . , 11), the minute (<i>mm</i> = 00,
01, 02, . . . , 59), and the second (<i>ss</i> = 00, 01, 02, . . . , 59), respectively. The time starts from
00:00:00 and counts up every second 00:00:00, 00:00:01, 00:00:02, . . ., but it reverts to 00:00:00
every 12 hours.
</p>
<p>
The watches in Chronus Island obey the following conventions of modern analog watches.
</p>
<ul>
<li>A watch has three hands, i.e. the hour hand, the minute hand, and the second hand,
though they look identical as mentioned above.</li>
<li>Every hand ticks 6 degrees clockwise in a discrete manner. That is, no hand stays between
ticks, and each hand returns to the same position every 60 ticks.</li>
<li>The second hand ticks every second.</li>
<li>The minute hand ticks every 60 seconds.</li>
<li>The hour hand ticks every 12 minutes.</li>
</ul>
<p>
At the time 00:00:00, all the three hands are located at the same position.
</p>
<p>
Because people in Chronus Island were reasonably keen to keep their watches correct and pyroclastic flows spread over the island quite rapidly, it can be assumed that all the watches were
stopped in a short interval of time. Therefore it is highly expected that the time the disaster
happened is in the shortest time interval within which all the excavated watches have at least
one candidate time.
</p>
<p>
You must calculate the shortest time interval and report it to the project team.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each of which is formatted as follows.
</p>
<p>
<i>n</i><br>
<i>s<sub>1</sub> t<sub>1</sub> u<sub>1</sub></i><br>
<i>s<sub>2</sub> t<sub>2</sub> u<sub>2</sub></i><br>
.<br>
.<br>
.<br>
<i>s<sub>n</sub> t<sub>n</sub> u<sub>n</sub></i><br>
</p>
<p>
The first line contains a single integer <i>n</i> (2 ≤ <i>n</i> ≤ 10), representing the number of the watches.
The three numbers <i>s<sub>i</sub></i> , <i>t<sub>i</sub></i> , <i>u<sub>i</sub></i> in each line are integers such that 0 ≤ <i>s<sub>i</sub></i> ,<i>t<sub>i</sub></i> , <i>u<sub>i</sub></i> ≤ 59 and they specify
the positions of the three hands by the number of ticks relative to an arbitrarily chosen position.
</p>
<p>
Note that the positions of the hands of a watch can be expressed in many different ways. For
example, if a watch was stopped at the time 11:55:03, the positions of hands can be expressed
differently by rotating the watch arbitrarily (e.g. 59 55 3, 0 56 4, 1 57 5, etc.) and as well by
permuting the hour, minute, and second hands arbitrarily (e.g. 55 59 3, 55 3 59, 3 55 59, etc.).
</p>
<p>
The end of the input is indicated by a line containing a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset, output the shortest time interval within which all the watches given in the
dataset have at least one candidate time. The output must be written in a single line in the
following format for each dataset.
</p>
<p>
<i>hh</i>:<i>mm</i>:<i>ss</i> <i>h'h'</i>:<i>m'm'</i>:<i>s's'</i>
</p>
<p>
Each line contains a pair of times <i>hh</i>:<i>mm</i>:<i>ss</i> and, <i>h'h'</i>:<i>m'm'</i>:<i>s's'</i> indicating that the shortest
interval begins at hh:mm:ss and ends at <i>h'h'</i>:<i>m'm'</i>:<i>s's'</i> inclusive. The beginning time and the
ending time are separated by a single space and each of them should consist of hour, minute,
and second in two digits separated by colons. No extra characters should appear in the output.
</p>
<p>
In calculating the shortest interval, you can exploit the facts that every watch has at least one
candidate time and that the shortest time interval contains 00:00:00 only if the interval starts
from 00:00:00 (i.e. the shortest interval terminates before the time reverts to 00:00:00).
</p>
<p>
If there is more than one time interval that gives the shortest, output the one that first comes
after 00:00:00 inclusive.
</p>
<H2>Sample Input</H2>
<pre>
3
8 8 18
32 32 32
57 2 57
5
49 3 49
7 30 44
27 21 21
33 56 56
21 46 4
3
45 52 28
36 26 36
20 55 50
10
33 8 39
50 57 43
35 21 12
21 17 11
16 21 58
45 40 53
45 30 53
39 1 8
55 48 30
7 48 15
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
00:00:00 00:00:10
06:14:56 06:32:09
07:27:37 07:32:02
05:17:40 05:21:03
</pre>
|
p03067 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are three houses on a number line: House <var>1</var>, <var>2</var> and <var>3</var>, with coordinates <var>A</var>, <var>B</var> and <var>C</var>, respectively.
Print <code>Yes</code> if we pass the coordinate of House <var>3</var> on the straight way from House <var>1</var> to House <var>2</var> without making a detour, and print <code>No</code> otherwise.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0\leq A,B,C\leq 100</var></li>
<li><var>A</var>, <var>B</var> and <var>C</var> are distinct integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>Yes</code> if we pass the coordinate of House <var>3</var> on the straight way from House <var>1</var> to House <var>2</var> without making a detour, and print <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 8 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>We pass the coordinate <var>5</var> on the straight way from the house at coordinate <var>3</var> to the house at coordinate <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>31 41 59
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre></section>
</div>
</span> |
p03437 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given positive integers <var>X</var> and <var>Y</var>.
If there exists a positive integer not greater than <var>10^{18}</var> that is a multiple of <var>X</var> but not a multiple of <var>Y</var>, choose one such integer and print it.
If it does not exist, print <var>-1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †X,Y †10^9</var></li>
<li><var>X</var> and <var>Y</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>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print a positive integer not greater than <var>10^{18}</var> that is a multiple of <var>X</var> but not a multiple of <var>Y</var>, or print <var>-1</var> if it does not exist.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>16
</pre>
<p>For example, <var>16</var> is a multiple of <var>8</var> but not a multiple of <var>6</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>A multiple of <var>3</var> is a multiple of <var>3</var>.</p></section>
</div>
</span> |
p01959 |
<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>
Revenge of the Broken Door
</H1>
<p>
The JAG Kingdom consists of $N$ cities and $M$ bidirectional roads. The $i$-th road ($u_i, v_i, c_i$) connects the city $u_i$ and the city $v_i$ with the length $c_i$. One day, you, a citizen of the JAG Kingdom, decided to go to the city $T$ from the city $S$. However, you know that one of the roads in the JAG Kingdom is currently under construction and you cannot pass the road. You don't know which road it is. You can know whether a road is under construction only when you are in either city connected by the road.
</p>
<p>
Your task is to minimize the total length of the route in the worst case. You don't need to decide a route in advance of departure and you can choose where to go next at any time. If you cannot reach the city $T$ in the worst case, output '-1'.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$ $M$ $S$ $T$
$u_1$ $v_1$ $c_1$
:
$u_M$ $v_M$ $c_M$
</pre>
<p>
The first line contains four integers $N, M, S,$ and $T$, where $N$ is the number of the cities ($2 \leq N \leq 100,000$), $M$ is the number of the bidirectional roads ($1 \leq M \leq 200,000$), $S$ is the city you start from ($1 \leq S \leq N$), and $T$ is the city you want to reach to ($1 \leq T \leq N, S \ne T$). The following $M$ lines represent road information: the $i$-th line of the $M$ lines consists of three integers $u_i, v_i, c_i,$ which means the $i$-th road connects the cities $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq N, u_i \ne v_i$) with the length $c_i$ ($1 \leq c_i \leq 10^9$). You can assume that all the pairs of the cities are connected if no road is under construction. That is, there is at least one route from city $x$ to city $y$ with given roads, for all cities $x$ and $y$. It is also guaranteed that there are no multiple-edges, i.e., $\{u_i,v_i\} \ne \{u_j,v_j\}$ for all $1 \leq i < j \leq M$.
</p>
<H2>Output</H2>
<p>
Output the minimum total length of the route in the worst case. If you cannot reach the city $T$ in the worst case, output '-1'.
</p>
<H2>Sample Input 1</H2>
<pre>
3 3 1 3
1 2 1
2 3 5
1 3 3
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
6
</pre>
<H2>Sample Input 2</H2>
<pre>
4 4 1 4
1 2 1
2 4 1
1 3 1
3 4 1
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
4
</pre>
<H2>Sample Input 3</H2>
<pre>
5 4 4 1
1 2 3
2 3 4
3 4 5
4 5 6
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
-1
</pre> |
p03964 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report <var>N</var> times, and when he checked it for the <var>i</var>-th <var>(1âŠiâŠN)</var> time, the ratio was <var>T_i:A_i</var>.
It is known that each candidate had at least one vote when he checked the report for the first time.</p>
<p>Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the <var>N</var>-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ1000</var></li>
<li><var>1âŠT_i,A_iâŠ1000 (1âŠiâŠN)</var></li>
<li><var>T_i</var> and <var>A_i</var> <var>(1âŠiâŠN)</var> are coprime.</li>
<li>It is guaranteed that the correct answer is at most <var>10^{18}</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>T_1</var> <var>A_1</var>
<var>T_2</var> <var>A_2</var>
<var>:</var>
<var>T_N</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the <var>N</var>-th time.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 3
1 1
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>When the numbers of votes obtained by the two candidates change as <var>2,3 â 3,3 â 6,4</var>, the total number of votes at the end is <var>10</var>, which is the minimum possible number.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 1
1 1
1 5
1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>101
</pre>
<p>It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
3 10
48 17
31 199
231 23
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6930
</pre></section>
</div>
</span> |
p02676 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We have a string <var>S</var> consisting of lowercase English letters.</p>
<p>If the length of <var>S</var> is at most <var>K</var>, print <var>S</var> without change.</p>
<p>If the length of <var>S</var> exceeds <var>K</var>, extract the first <var>K</var> characters in <var>S</var>, append <code>...</code> to the end of them, and print the result.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>K</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</li>
<li><var>S</var> is a string consisting of lowercase English letters.</li>
<li>The length of <var>S</var> is between <var>1</var> and <var>100</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print a string as stated in Problem Statement.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
nikoandsolstice
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>nikoand...
</pre>
<p><code>nikoandsolstice</code> has a length of <var>15</var>, which exceeds <var>K=7</var>.</p>
<p>We should extract the first <var>7</var> characters in this string, append <code>...</code> to the end of them, and print the result <code>nikoand...</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>40
ferelibenterhominesidquodvoluntcredunt
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>ferelibenterhominesidquodvoluntcredunt
</pre>
<p>The famous quote from Gaius Julius Caesar.</p></section>
</div>
</span> |
p02226 | <h2> test </h2>
UnionFindïŒãã€ããªå
¥åïŒ |
p03821 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are an integer sequence <var>A_1,...,A_N</var> consisting of <var>N</var> terms, and <var>N</var> buttons.
When the <var>i</var>-th <var>(1 ⊠i ⊠N)</var> button is pressed, the values of the <var>i</var> terms from the first through the <var>i</var>-th are all incremented by <var>1</var>.</p>
<p>There is also another integer sequence <var>B_1,...,B_N</var>. Takahashi will push the buttons some number of times so that for every <var>i</var>, <var>A_i</var> will be a multiple of <var>B_i</var>.</p>
<p>Find the minimum number of times Takahashi will press the buttons.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 ⊠N ⊠10^5</var></li>
<li><var>0 ⊠A_i ⊠10^9(1 ⊠i ⊠N)</var></li>
<li><var>1 ⊠B_i ⊠10^9(1 ⊠i ⊠N)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>B_1</var>
:
<var>A_N</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print an integer representing the minimum number of times Takahashi will press the buttons.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 5
2 7
9 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>Press the first button twice, the second button twice and the third button three times.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
3 1
4 1
5 9
2 6
5 3
5 8
9 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>22
</pre></section>
</div>
</span> |
p02733 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a chocolate bar partitioned into <var>H</var> horizontal rows and <var>W</var> vertical columns of squares.</p>
<p>The square <var>(i, j)</var> at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is dark if <var>S_{i,j}</var> is <code>0</code>, and white if <var>S_{i,j}</var> is <code>1</code>.</p>
<p>We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.</p>
<p>How many times do we need to cut the bar so that every block after the cuts has <var>K</var> or less white squares?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H \leq 10</var></li>
<li><var>1 \leq W \leq 1000</var></li>
<li><var>1 \leq K \leq H \times W</var></li>
<li><var>S_{i,j}</var> is <code>0</code> or <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>K</var>
<var>S_{1,1}S_{1,2}...S_{1,W}</var>
<var>:</var>
<var>S_{H,1}S_{H,2}...S_{H,W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of minimum times the bar needs to be cut so that every block after the cuts has <var>K</var> or less white squares.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5 4
11100
10001
00111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, cutting between the <var>1</var>-st and <var>2</var>-nd rows and between the <var>3</var>-rd and <var>4</var>-th columns - as shown in the figure to the left - works.</p>
<p>Note that we cannot cut the bar in the ways shown in the two figures to the right.</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/ac90dd542639c04402125403b1c319d7.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 5 8
11100
10001
00111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>No cut is needed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 10 4
1110010010
1000101110
0011101001
1101000111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</span> |
p02699 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>S</var> sheep and <var>W</var> wolves.</p>
<p>If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.</p>
<p>If the wolves will attack the sheep, print <code>unsafe</code>; otherwise, print <code>safe</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq S \leq 100</var></li>
<li><var>1 \leq W \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var> <var>W</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the wolves will attack the sheep, print <code>unsafe</code>; otherwise, print <code>safe</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>unsafe
</pre>
<p>There are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>safe
</pre>
<p>Many a sheep drive away two wolves.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>unsafe
</pre></section>
</div>
</span> |
p02363 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>All Pairs Shortest Path</H1>
<br/>
<H2>Input</H2>
<p>
An edge-weighted graph <var>G</var> (<var>V</var>, <var>E</var>).
</p>
<pre>
|<var>V</var>| |<var>E</var>|
<var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>d<sub>0</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var>
:
<var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>d<sub>|E|-1</sub></var>
</pre>
<p>
<var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in <var>G</var>. The graph vertices are named with the numbers 0, 1,..., <var>|V|-1</var> respectively.
</p>
<p>
<var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target vertices of <var>i</var>-th edge (directed) and <var>d<sub>i</sub></var> represents the cost of the <var>i</var>-th edge.
</p>
<H2>Output</H2>
<p>
If the graph contains a negative cycle (a cycle whose sum of edge costs is a negative value), print
<pre>
NEGATIVE CYCLE
</pre>
<p>
in a line.
</p>
<p>
Otherwise, print
</p>
<pre>
<var>D<sub>0,0</sub></var> <var>D<sub>0,1</sub></var> ... <var>D<sub>0,|V|-1</sub></var>
<var>D<sub>1,0</sub></var> <var>D<sub>1,1</sub></var> ... <var>D<sub>1,|V|-1</sub></var>
:
<var>D<sub>|V|-1,0</sub></var> <var>D<sub>1,1</sub></var> ... <var>D<sub>|V|-1,|V|-1</sub></var>
</pre>
<p>
The output consists of <var>|V|</var> lines. For each <var>i</var>th line, print the cost of the shortest path from vertex <var>i</var> to each vertex <var>j</var> (<var>j = 0, 1, ... |V|-1</var>) respectively. If there is no path from vertex <var>i</var> to vertex <var>j</var>, print "<span>INF</span>". Print a space between the costs.
</p>
<H2>Constraints</H2>
<ul>
<li> 1 ≤ <var>|V|</var> ≤ 100</li>
<li> 0 ≤ <var>|E|</var> ≤ 9900</li>
<li> -2 × 10<sup>7</sup> ≤ <var>d<sub>i</sub></var> ≤ 2 × 10<sup>7</sup></li>
<li> There are no parallel edges</li>
<li> There are no self-loops</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 6
0 1 1
0 2 5
1 2 2
1 3 4
2 3 1
3 2 7
</pre>
<H2>Sample Output 1</H2>
<pre>
0 1 3 4
INF 0 2 3
INF INF 0 1
INF INF 7 0
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4 6
0 1 1
0 2 -5
1 2 2
1 3 4
2 3 1
3 2 7
</pre>
<H2>Sample Output 2</H2>
<pre>
0 1 -5 -4
INF 0 2 3
INF INF 0 1
INF INF 7 0
</pre>
<br/>
<H2>Sample Input 3</H2>
<pre>
4 6
0 1 1
0 2 5
1 2 2
1 3 4
2 3 1
3 2 -7
</pre>
<H2>Sample Output 3</H2>
<pre>
NEGATIVE CYCLE
</pre>
<br/>
|
p03122 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><font color="red"><strong>Red bold fonts show the difference from C1.</strong></font></p>
<p>There is an infinitely large triangular grid, as shown below.
Each point with integer coordinates contains a lamp.</p>
<p><img alt="" src="https://img.atcoder.jp/wtf19/f617c94527a62ed72fe7db12b6d1f6b0.png"/></p>
<p>Initially, only the lamp at <font color="red"><strong><var>(X, Y)</var></strong></font> was on, and all other lamps were off.
Then, Snuke performed the following operation zero or more times:</p>
<ul>
<li>Choose two integers <var>x</var> and <var>y</var>.
Toggle (on to off, off to on) the following three lamps: <var>(x, y), (x, y+1), (x+1, y)</var>.</li>
</ul>
<p>After the operations, <var>N</var> lamps <var>(x_1, y_1), \cdots, (x_N, y_N)</var> are on, and all other lamps are off.
Find <font color="red"><strong><var>X</var> and <var>Y</var></strong></font>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><font color="red"><strong><var>1 \leq N \leq 10^4</var></strong></font></li>
<li><var>-10^{17} \leq x_i, y_i \leq 10^{17}</var></li>
<li><var>(x_i, y_i)</var> are pairwise distinct.</li>
<li>The input is consistent with the statement, and you can uniquely determine <font color="red"><strong><var>X</var> and <var>Y</var></strong></font>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <font color="red"><strong><var>X</var> and <var>Y</var>, separated by a space</strong></font>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
-2 1
-2 2
0 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>-1 0
</pre>
<p>The following picture shows one possible sequence of operations:</p>
<p><img alt="" src="https://img.atcoder.jp/wtf19/cff6dc4d81e995e9300ccbaca5bf85de.png"/></p></section>
</div>
</span> |
p03088 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Find the number of strings of length <var>N</var> that satisfy the following conditions, modulo <var>10^9+7</var>:</p>
<ul>
<li>The string does not contain characters other than <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>.</li>
<li>The string does not contain <code>AGC</code> as a substring.</li>
<li>The condition above cannot be violated by swapping two adjacent characters once.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>A substring of a string <var>T</var> is a string obtained by removing zero or more characters from the beginning and the end of <var>T</var>.</p>
<p>For example, the substrings of <code>ATCODER</code> include <code>TCO</code>, <code>AT</code>, <code>CODER</code>, <code>ATCODER</code> and <code></code> (the empty string), but not <code>AC</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of strings of length <var>N</var> that satisfy the following conditions, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>61
</pre>
<p>There are <var>4^3 = 64</var> strings of length <var>3</var> that do not contain characters other than <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>. Among them, only <code>AGC</code>, <code>ACG</code> and <code>GAC</code> violate the condition, so the answer is <var>64 - 3 = 61</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>230
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>388130742
</pre>
<p>Be sure to print the number of strings modulo <var>10^9+7</var>.</p></section>
</div>
</span> |
p03572 | <span class="lang-en">
<p>Score : <var>1800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Three men, A, B and C, are eating sushi together.
Initially, there are <var>N</var> pieces of sushi, numbered <var>1</var> through <var>N</var>.
Here, <var>N</var> is a multiple of <var>3</var>.</p>
<p>Each of the three has likes and dislikes in sushi.
A's preference is represented by <var>(a_1,\ ...,\ a_N)</var>, a permutation of integers from <var>1</var> to <var>N</var>.
For each <var>i</var> (<var>1 \leq i \leq N</var>), A's <var>i</var>-th favorite sushi is Sushi <var>a_i</var>.
Similarly, B's and C's preferences are represented by <var>(b_1,\ ...,\ b_N)</var> and <var>(c_1,\ ...,\ c_N)</var>, permutations of integers from <var>1</var> to <var>N</var>.</p>
<p>The three repeats the following action until all pieces of sushi are consumed or a fight brakes out (described later):</p>
<ul>
<li>Each of the three A, B and C finds his most favorite piece of sushi among the remaining pieces. Let these pieces be Sushi <var>x</var>, <var>y</var> and <var>z</var>, respectively. If <var>x</var>, <var>y</var> and <var>z</var> are all different, A, B and C eats Sushi <var>x</var>, <var>y</var> and <var>z</var>, respectively. Otherwise, a fight brakes out.</li>
</ul>
<p>You are given A's and B's preferences, <var>(a_1,\ ...,\ a_N)</var> and <var>(b_1,\ ...,\ b_N)</var>.
How many preferences of C, <var>(c_1,\ ...,\ c_N)</var>, leads to all the pieces of sushi being consumed without a fight?
Find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 399</var></li>
<li><var>N</var> is a multiple of <var>3</var>.</li>
<li><var>(a_1,\ ...,\ a_N)</var> and <var>(b_1,\ ...,\ b_N)</var> are permutations of integers from <var>1</var> to <var>N</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>...</var> <var>a_N</var>
<var>b_1</var> <var>...</var> <var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the preferences of C that leads to all the pieces of sushi being consumed without a fight, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2 3
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The answer is two, <var>(c_1,\ c_2,\ c_3) = (3,\ 1,\ 2),\ (3,\ 2,\ 1)</var>.
In both cases, A, B and C will eat Sushi <var>1</var>, <var>2</var> and <var>3</var>, respectively, and there will be no more sushi.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2 3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Regardless of what permutation <var>(c_1,\ c_2,\ c_3)</var> is, A and B will try to eat Sushi <var>1</var>, resulting in a fight.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2 3 4 5 6
2 1 4 3 6 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>80
</pre>
<p>For example, if <var>(c_1,\ c_2,\ c_3,\ c_4,\ c_5,\ c_6) = (5,\ 1,\ 2,\ 6,\ 3,\ 4)</var>, A, B and C will first eat Sushi <var>1</var>, <var>2</var> and <var>5</var>, respectively, then they will eat Sushi <var>3</var>, <var>4</var> and <var>6</var>, respectively, and there will be no more sushi.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6
1 2 3 4 5 6
6 5 4 3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>160
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>33600
</pre></section>
</div>
</span> |
p00077 |
<H1>ã©ã³ã¬ã³ã°ã¹</H1>
<p>
æååãé£ç¶ããå ŽåãããèŠåã§æåã眮ãæãæååãçãããããšãã§ããŸããããšãã°ãAAAA ãšããæååã®å Žåã@4A ãšè¡šçŸããã° 1 æååå§çž®ãããŸãããã®èŠåã§å§çž®ãããæååãå
¥åããŠããšã®æååã«åŸ©å
ããããã°ã©ã ãäœæããŠãã ããããã ãã埩å
ããæååã«ïŒ æåã¯åºçŸããªããã®ãšããŸãã
</p>
<p>
ãŸããåæã®æååã¯è±å€§æåãè±å°æåãæ°åãèšå·ã§ãã 100 æå以å
ãé£ç¶ããæå㯠9 æå以å
ã§ãã
</p>
<H2>å
¥å</H2>
<p>è€æ°ã®æååãäžããããŸããïŒè¡ã«ïŒã€ã®æååãäžããããŸããæååã®æ°ã¯ 50 ãè¶
ããŸããã</p>
<H2>åºå</H2>
<p>æååããšã«ãåæåã«å¯ŸããŠåŸ©å
ããæååãïŒè¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
ab@5C1@8050
@99+1=1@90
</pre>
<H2>Output for the Sample Input</H2>
<pre>
abCCCCC10000000050
999999999+1=1000000000
</pre>
|
p00427 |
<H1></H1>
<p>
次ã®ãããªã²ãŒã ãèããïŒ 1 ãã n ãŸã§ã®æ°ã 1 ã€ãã€æžããã n æã®ã«ãŒãã k çµããïŒããã kn æã®ã«ãŒããããã·ã£ããã«ïŒããåãããšïŒããŠïŒ k æãã€ã®å±±ãäœã暪äžåã«äžŠã¹ãïŒãã®ããã«ããŠã§ãã n åã®å±±ã®å·Šãã i çªç®ã®ïŒk æã®ã«ãŒãã®ïŒå±±ããå±± i ããšåŒã¶ããšã«ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t5-fig_base">
</center>
<br>
<p>
ã²ãŒã ã¯å±± 1 ããå§ããïŒå±±ã®äžçªäžã®ã«ãŒã 1 æãåŒãïŒåŒããã«ãŒãã¯å
ã®å±±ã«æ»ããªãïŒïŒãã®ã«ãŒãã«æžãããŠããæ°ã i ã ã£ãå Žåã«ã¯å±± i ã®äžçªäžã®ã«ãŒã 1 æãåŒãïŒãã®ããã«ããŠïŒåŒããã«ãŒãã«æžãããŠããæ°ãçªå·ãšããå±±ã®äžçªäžã®ã«ãŒã 1 æãåŒãããšãç¹°ãè¿ãïŒãã¹ãŠã®å±±ã«ã«ãŒããç¡ããªãã°æåã§ããïŒãŸã ã«ãŒããæ®ã£ãŠããå±±ãããã®ã«ïŒæ¬¡ã«ã«ãŒããåŒãã¹ãå±±ãç¡ããªã£ãŠããå Žåã¯å€±æã§ããïŒ
</p>
<p>
ãéäžã§å€±æããå Žåã«ã¯ïŒãã®ãŸãŸå€±æã§çµäºãããïŒãŸãã¯æ®ã£ãã«ãŒãã®å±±ããã®ãŸãŸïŒå±±ã®çªå·ããã®ãŸãŸïŒã«ããŠã²ãŒã ãåéããïŒã²ãŒã ãåéããå Žåã¯ïŒæåã«åŒãã«ãŒãã¯ã«ãŒããæ®ã£ãŠããå±±ã®ãã¡ã®äžçªå·Šã®å±±ãããšããïŒãã®å±±ã®äžçªäžã®ã«ãŒããæåã«åŒãããã«ãŒããšãªãïŒïŒåéåŸãåéåãšåæ§ã®æ¹æ³ã§ã²ãŒã ãé²ãïŒãã¹ãŠã®å±±ã«ã«ãŒããç¡ããªãã°æåã§ããïŒãŸã ã«ãŒããæ®ã£ãŠããå±±ãããã®ã«ïŒæ¬¡ã«ã«ãŒããåŒãã¹ãå±±ãç¡ããªã£ãå Žåã¯å€±æã§ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t5-fig_sample">
</center>
<br>
<p>
ãã®ãããªã²ãŒã ã®åéãæå€§ m åãŸã§è¡ããã®ãšããïŒãã ãïŒm 㯠0 ã 1 ã§ããïŒã€ãŸãïŒ 1 åãåéããªããïŒ 1 åã ãåéãããã®ããããã§ããïŒã²ãŒã éå§åã®ã·ã£ããã«ã®ä»æ¹ã«ããã«ãŒãã®åæé
眮ã¯ç°ãªãïŒåœç¶ïŒã«ãŒãã®åæé
眮ã«ããïŒåéããã«æåããããšãããã°ïŒåéããŠæåããããšãïŒåéããŠå€±æããããšãããïŒååã·ã£ããã«ããŠããã®ã§ïŒã©ã®åæé
眮ãå
šãŠåã確çã§çŸãããã®ãšèããããšã«ããŠïŒåéã m å以å
ã§æåãã確ç p ãæ±ãããïŒãã®ç¢ºç p ãå°æ°ã§è¡šãïŒå°æ°ç¬¬ r äœãŸã§æ±ããŠåºåããããã°ã©ã ãäœããªããïŒãã ãïŒæ¬¡ã®æ¡ä»¶ãæºããããã«åºåããããš.
</p>
<ul>
<li> åå倧ããæ£æŽæ° K ãåããš pÃ10K ã æŽæ°ãšãªãå ŽåïŒ å°æ°éšã¯éäžãã 0 ãç¶ããïŒãã® 0 ãåºåããããšïŒ äŸãã°ïŒ p = 3/8 = 0.375 ã®å ŽåïŒ r = 5 ãªã 0.37500 ãšåºåãïŒ r = 2 ãªã 0.37 ãšåºåããïŒ p = 1.0 ã®å Žåãåæ§ã«ïŒ äŸãã° r = 3 ãªã 1.000 ãšåºåããããšïŒ</li>
<li> äŸãã° 0.150000⊠ã¯åŸªç°å°æ° 0.1499999⊠ãšããŠè¡šãããšãã§ãããïŒ ãã®ãããªå ŽåïŒ åè
ã®è¡šãæ¹ãçšããïŒ </li>
</ul>
<p>
å
¥åãã¡ã€ã«ã® 1 è¡ç®ã«ã¯æŽæ° nïŒkïŒmïŒr ããã®é ã«ç©ºçœãåºåãæåãšããŠæžããŠããïŒ 1 ⊠n ⊠10000ïŒ 1 ⊠k ⊠100ïŒ m = 0 ãŸã㯠m = 1ïŒ 1 ⊠r ⊠10000 ã§ããïŒ
</p>
<!--
<p>
ãã¢ããããŒãããåºåãã¡ã€ã«ã«ãããŠã¯ïŒæå®éãã«åºåãã p ã®åŸã«æ¹è¡ãå
¥ããããšïŒ
</p>
-->
<table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;">
<tr>
<th width="150" align="left">å
¥åäŸïŒ</th>
<th width="150" align="left">å
¥åäŸïŒ</th>
<th width="150" align="left">å
¥åäŸïŒ</th>
</tr>
<tr><td></td><td></td></tr>
<tr><td>2 1 0 5</td><td>3 1 1 3</td><td>2 2 1 3</td><td></td></tr>
<tr>
<td>ã</td>
</tr>
<tr>
<th width="150" align="left">åºåäŸïŒ</th>
<th width="150" align="left">åºåäŸïŒ</th>
<th width="150" align="left">åºåäŸïŒ</th>
</tr>
<tr><td>0.50000</td><td>0.833</td><td>1.000</td><td></td></tr>
</table>
<h3>å
¥å</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒn, k, m, r ããã¹ãŠ 0 ã®ãšãå
¥åãçµäºããïŒããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h3>åºå</h3>
<p>
ããŒã¿ã»ããããšã«ãæå®éãã« p ãïŒè¡ã«åºåããïŒ
</p>
<H2>å
¥åäŸ</H2>
<pre>
2 1 0 5
3 1 1 3
2 2 1 3
0 0 0 0
</pre>
<H2>åºåäŸ</H2>
<pre>
0.50000
0.833
1.000
</pre>
<p>
åããŒã¿ã»ããã«ã€ããŠïŒæå®éãã«åºåãã p ã®åŸã«æ¹è¡ãå
¥ããããšïŒ
</p>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p01666 |
<h2>K - encode/decode</h2>
<p>
以äžã®ïŒæ¡ä»¶ãå
šãŠæºããæååTã®äºããè¯ããæååãšåŒã¶ããšã«ãã
<ul>
<li>Tã¯ABCDEFGHIã®9çš®é¡ã®æååãããªã</li>
<li>Täžã®é£ç¶ããïŒæåã¯æ¬¡ã®ã°ã©ãäžã§ã飿¥ããŠãã
</ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_graph">
<p>ãè¯ããæååã®äŸ</p>
<ul>
<li>BEB</li>
<li>ABCDCBEFGHI</li>
</ul>
<p>ãè¯ããæååã§ã¯ãªãäŸ</p>
<ul>
<li>AC(AãšCã¯é£æ¥ããŠããªã)</li>
<li>AABCD(åãæåã¯ã°ã©ãäžã§ã¯é£æ¥ããŠããªããšã¿ãªã)</li>
</ul>
<p>
以äžã®æ¡ä»¶ãæºãããããªïŒã€ã®é¢æ°,encodeãšdecodeãå®è£
ãã.
</p>
<ul>
<li>ä»»æã®01åSã«å¯Ÿã,encode(S)ã¯ãè¯ããæååã§ãã</li>
<li>ä»»æã®01åSã«å¯Ÿã,decode(encode(S))=Sãæºãã</li>
</ul>
<h2>å
¥åºå圢åŒ</h2>
<p>ãã®åé¡ã«ã¯encodeãã§ãŒãºãšdecodeãã§ãŒãºããã, ããããç¬ç«ã«ããã°ã©ã ãå®è¡ããã.</p>
<p>encodeãã§ãŒãºã®ãšã, å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã.</p>
<pre>
encode
<var>N</var>
<var>S</var>
</pre>
<p>
<var>N</var>ã¯äžãããã01å<var>S</var>ã®é·ãã§ãã.
<var>S</var>ã¯ããªããencodeããã¹ã01åã§ãã.
ãã®æã®,ããªããæåºããããã°ã©ã ã®åºåã<var>T</var>ãšãã. <var>T</var>ãè¯ãæååã§ãªãå Žåã¯äžæ£è§£ãšãªã,decodeãã§ãŒãºã¯å®è¡ãããªã.
decodeãã§ãŒãºã®ãšã,å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã.
</p>
<pre>
decode
<var>M</var>
<var>T</var>
</pre>
<p>
<var>T</var>ã¯encodeãã§ãŒãºã«ãããããªãã®åºåã§ãã.
<var>M</var>ã¯æåå<var>T</var>ã®é·ãã§ãã.
ãã®æã®,ããªããæåºããããã°ã©ã ã®åºåãencodeãã§ãŒãºã«ãããSãšäžèŽããå Žå,æ£è§£ãšãªã
</p>
<h2>æ¡ç¹æ¹åŒ</h2>
<p>ãã®åé¡ã§ã¯å
¥å<var>S</var>ã«å¯Ÿããåºåencode(S)ã®é·ãã«å¿ããŠåŸç¹ã決ãŸã.</p>
<p>å
šãŠã®ãã¹ãã±ãŒã¹ã«ã€ããŠ, |encode(S)| ⊠|S| + 10 ãæºãããšããã®åé¡ã«å¯ŸããåŸç¹ãæºç¹ãšãªã.</p>
<p>ãŸã, |encode(S)| ⊠2Ã|S| + 10 ãæºããå Žå, ãã®åé¡ã«å¯ŸããåŸç¹ã¯50ç¹ãšãªã.</p>
<!--
<p>ãã®åé¡ã§ã¯å
¥å<var>S</var>ã«å¯Ÿããåºåencode(S)ã®é·ãã«å¿ããŠåŸç¹ã決ãŸã.</p>
<p>å
šãŠã®ãã¹ãã±ãŒã¹ã«ã€ããŠ, |encode(S)| ⊠|S| + 10 ãæºãããšããã®åé¡ã«å¯ŸããåŸç¹ã¯æºç¹ã®1000ç¹ãšãªã.</p>
<p>ãŸã, |encode(S)| ⊠2Ã|S| + 10 ãæºããå Žå, ãã®åé¡ã«å¯ŸããåŸç¹ã¯50ç¹ãšãªã.</p>
-->
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ N ≤ 300000</var> </li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>encodeãã§ãŒãº</h3>
<p>å
¥å</p>
<pre>
encode
6
001100
</pre>
<p>åºå</p>
<pre>
ABCBE
</pre>
<p>encodeãã§ãŒãºã®çµäºåŸããªãã®ããã°ã©ã ã¯äžæŠçµäºã,次ã«decodeãã§ãŒãºãéå§ãã</p>
<h3>decodeãã§ãŒãº</h3>
<p>å
¥å</p>
<pre>
decode
5
ABCBE
</pre>
<p>åºå</p>
<pre>
001100
</pre> |
p00974 | <h3>What Goes Up Must Come Down</h3>
<p>
Several cards with numbers printed on them are lined up on the table.
</p>
<p>
We'd like to change their order so that first some are in non-decreasing order of the numbers on them, and the rest are in non-increasing order. For example, (1, 2, 3, 2, 1), (1, 1, 3, 4, 5, 9, 2), and (5, 3, 1) are acceptable orders, but (8, 7, 9) and (5, 3, 5, 3) are not.
</p>
<p>
To put it formally, with $n$ the number of cards and $b_i$ the number printed on the card at the $i$-th position ($1 \leq i \leq n$) after reordering, there should exist $k \in \{1, ... n\}$ such that ($b_i \leq b_{i+1} \forall _i \in \{1, ... k - 1\}$) and ($b_i \geq b_{i+1} \forall _i \in \{k, ..., n - 1\}$) hold.
</p>
<p>
For reordering, the only operation allowed at a time is to swap the positions of an adjacent card pair. We want to know the minimum number of swaps required to complete the reorder.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$
$a_1$ ... $a_n$
</pre>
<p>
An integer $n$ in the first line is the number of cards ($1 \leq n \leq 100 000$). Integers $a_1$ through $a_n$ in the second line are the numbers printed on the cards, in the order of their original positions ($1 \leq a_i \leq 100 000$).
</p>
<h3>Output</h3>
<p>
Output in a line the minimum number of swaps required to reorder the cards as specified.
</p>
<h3>Sample Input 1</h3>
<pre>
7
3 1 4 1 5 9 2
</pre>
<h3> Sample Output 1</h3>
<pre>
3
</pre>
<h3>Sample Input 2</h3>
<pre>
9
10 4 6 3 15 9 1 1 12
</pre>
<h3>Sample Output 2</h3>
<pre>
8
</pre>
<h3>Sample Input 3</h3>
<pre>
8
9 9 8 8 7 7 6 6
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
6
8 7 2 5 4 6
</pre>
<h3>Sample Output 4</h3>
<pre>
4
</pre>
|
p02949 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a directed graph with <var>N</var> vertices numbered <var>1</var> to <var>N</var> and <var>M</var> edges.
The <var>i</var>-th edge is directed from Vertex <var>A_i</var> to Vertex <var>B_i</var>, and there are <var>C_i</var> coins placed along that edge.
Additionally, there is a button on Vertex <var>N</var>.</p>
<p>We will play a game on this graph.
You start the game on Vertex <var>1</var> with zero coins, and head for Vertex <var>N</var> by traversing the edges while collecting coins.
It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it.
As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.</p>
<p>When you reach Vertex <var>N</var>, you can end the game by pressing the button. (You can also choose to leave Vertex <var>N</var> without pressing the button and continue traveling.)
However, when you end the game, you will be asked to pay <var>T \times P</var> coins, where <var>T</var> is the number of minutes elapsed since the start of the game. If you have less than <var>T \times P</var> coins, you will have to pay all of your coins instead.</p>
<p>Your score will be the number of coins you have after this payment.
Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2500</var></li>
<li><var>1 \leq M \leq 5000</var></li>
<li><var>1 \leq A_i, B_i \leq N</var></li>
<li><var>1 \leq C_i \leq 10^5</var></li>
<li><var>0 \leq P \leq 10^5</var></li>
<li>All values in input are integers.</li>
<li>Vertex <var>N</var> can be reached from Vertex <var>1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>P</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>:</var>
<var>A_M</var> <var>B_M</var> <var>C_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print <code>-1</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 10
1 2 20
2 3 30
1 3 45
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>35
</pre>
<p><img alt="Figure of the graph given in Sample Input 1" src="https://img.atcoder.jp/ghi/5cb074e2d7c3282da137ac4ab2fbc700.png"/></p>
<p>There are two ways to travel from Vertex <var>1</var> to Vertex <var>3</var>:</p>
<ul>
<li>Vertex <var>1 \rightarrow 2 \rightarrow 3</var>: You collect <var>20 + 30 = 50</var> coins on the way. After two minutes from the start of the game, you press the button, pay <var>2 \times 10 = 20</var> coins, and you have <var>50 - 20 = 30</var> coins left.</li>
<li>Vertex <var>1 \rightarrow 2</var>: You collect <var>45</var> coins on the way. After one minute from the start of the game, you press the button, pay <var>1 \times 10 = 10</var> coins, and you have <var>45 - 10 = 35</var> coins left.</li>
</ul>
<p>Thus, the maximum score that can be obtained is <var>35</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 10
1 2 100
2 2 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p><img alt="Figure of the graph given in Sample Input 2" src="https://img.atcoder.jp/ghi/eb2188ad1e8189f963d233415fb293b6.png"/></p>
<p>The edge extending from Vertex <var>1</var> takes you to Vertex <var>2</var>. If you then traverse the edge extending from Vertex <var>2</var> to itself <var>t</var> times and press the button, your score will be <var>90 + 90t</var>. Thus, you can infinitely increase your score, which means there is no maximum value of the score that can be obtained.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p><img alt="Figure of the graph given in Sample Input 3" src="https://img.atcoder.jp/ghi/217f7a224b80a05d8e25140c57e65ae7.png"/></p>
<p>There is no way to travel from Vertex <var>1</var> to Vertex <var>4</var> other than traversing the edge leading from Vertex <var>1</var> to Vertex <var>4</var> directly. You will pick up one coin along this edge, but after being asked to paying <var>10</var> coins, your score will be <var>0</var>.</p>
<p>Note that you can collect an infinite number of coins if you traverse the edge leading from Vertex <var>1</var> to Vertex <var>2</var>, but this is pointless since you can no longer reach Vertex <var>4</var> and end the game.</p></section>
</div>
</span> |
p04034 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> boxes, numbered <var>1</var> through <var>N</var>. At first, box <var>1</var> contains one red ball, and each of the other boxes contains one white ball.</p>
<p>Snuke will perform the following <var>M</var> operations, one by one. In the <var>i</var>-th operation, he randomly picks one ball from box <var>x_i</var>, then he puts it into box <var>y_i</var>.</p>
<p>Find the number of boxes that may contain the red ball after all operations are performed.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€Nâ€10^5</var></li>
<li><var>1â€Mâ€10^5</var></li>
<li><var>1â€x_i,y_iâ€N</var></li>
<li><var>x_iâ y_i</var></li>
<li>Just before the <var>i</var>-th operation is performed, box <var>x_i</var> contains at least <var>1</var> ball.</li>
</ul>
</section>
</div>
<hr>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_M</var> <var>y_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of boxes that may contain the red ball after all operations are performed.</p>
</section>
</div>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Just after the first operation, box <var>1</var> is empty, box <var>2</var> contains one red ball and one white ball, and box <var>3</var> contains one white ball.</p>
<p>Now, consider the second operation. If Snuke picks the red ball from box <var>2</var>, the red ball will go into box <var>3</var>. If he picks the white ball instead, the red ball will stay in box <var>2</var>.
Thus, the number of boxes that may contain the red ball after all operations, is <var>2</var>.</p>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2
2 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>All balls will go into box <var>3</var>.</p>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 4
1 2
2 3
4 1
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre></section>
</div>
</hr></hr></hr></hr></span> |
p01236 |
<H1><font color="#000">Problem C:</font> Median Filter</H1>
<p>
The median filter is a nonlinear digital filter used to reduce noise in images, sounds, and other kinds of signals.
It examines each sample of the input through a <i>window</i> and then emits the <i>median</i> of the samples in the win-
dow. Roughly speaking, a window is an interval that contains a target sample and its preceding and succeeding
samples; the median of a series of values is given by the middle value of the series arranged in ascending (or
descending) order.
</p>
<p>
Let us focus on a typical median filter for black-and-white raster images. The typical filter uses a 3 × 3 window,
which contains a target pixel and the eight adjacent pixels. The filter examines each pixel in turn through this
3 × 3 window, and outputs the median of the nine pixel values, i.e. the fifth lowest (or highest) pixel value, to the
corresponding pixel. We should note that the output is just given by the pixel value in majority for black-and-
white images, since there are only two possible pixel values (i.e. black and white). The figure below illustrates
how the filter works.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_medianFilter1">
<p><i><b>Note:</b> The colors of lightly-shaded pixels depend on outside of the region.</i></p>
</center>
<p>
The edges of images need to be specially processed due to lack of the adjacent pixels. In this problem, we extends
the original images by repeating pixels on the edges as shown in the figure below. In other words, the lacked
pixels take the same values as the nearest available pixels in the original images.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_medianFilter2">
<p><i><b>Note:</b> The letters âaâ through âfâ indicate pixel values.</i></p>
</center>
<p>
You are requested to write a program that reads images to which the filter is applied, then finds the original
images containing the greatest and smallest number of black pixels among all possible ones, and reports the
difference in the numbers of black pixels.
</p>
<H2>Input</H2>
<p>
The input contains a series of test cases.
</p>
<p>
The first line of each test case contains two integers <i>W</i> and <i>H</i> (1 ≤ <i>W</i>, <i>H</i> ≤ 8), which indicates the width and
height of the image respectively. Then <i>H</i> lines follow to describe the filtered image. The <i>i</i>-th line represents
the <i>i</i>-th scan line and contains exactly <i>W</i> characters, each of which is either â#â (representing black) or â.â
(representing white).
</p>
<p>
The input is terminated by a line with two zeros.
</p>
<H2>Output</H2>
<p>
For each test case, print a line that contains the case number followed by the difference of black pixels. If there
are no original images possible for the given filtered image, print âImpossibleâ instead.
</p>
<p>
Obey the format as shown in the sample output.
</p>
<H2>Sample Input</H2>
<pre>
5 5
#####
#####
#####
#####
#####
4 4
####
####
####
####
4 4
#...
....
....
...#
4 4
.#.#
#.#.
.#.#
#.#.
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 10
Case 2: 6
Case 3: 2
Case 4: Impossible
</pre>
|
p01723 |
<p>ã€ã¯ã¿åã®äœãçºã«ã¯<var>N</var>åã®å¡ãããã
ããããã®å¡ã«ã¯0ãã<var>N−1</var>ãŸã§ã®ç°ãªãçªå·ãäžããããŠãããçªå·<var>i</var>ã®å¡ãå¡<var>i</var>ãšåŒã¶ã
奜å¥å¿æºçãªã€ã¯ã¿åã¯<var>N</var>åã®å¡ã®é«ãã«èå³ãæã¡ããããã®å€§å°é¢ä¿ã衚ã衚<var>T</var>ãäœãããšã«ããã
<var>T</var>ã¯<var>N × N</var>åã®èŠçŽ ãæã¡ãåèŠçŽ <var>T<sub>i, j</sub> (0 ≤ i, j ≤ N − 1)</var>ã¯æ¬¡ã®ããã«å®çŸ©ãããã
</p>
<ul>
<li> <var>T<sub>i, j</sub> = −1</var> <var>⇔</var> å¡<var>i</var>ã®é«ããå¡<var>j</var>ã®é«ãããå°ãã
</li>
<li> <var>T<sub>i, j</sub> = 0</var> <var>⇔</var> å¡<var>i</var>ã®é«ããšå¡<var>j</var>ã®é«ããçãã
</li>
<li> <var>T<sub>i, j</sub> = 1</var> <var>⇔</var> å¡<var>i</var>ã®é«ããå¡<var>j</var>ã®é«ããã倧ãã
</li>
</ul>
<p>ã€ã¯ã¿åã¯è¡š<var>T</var>ãäœæããããã®èª¿æ»ãšããŠã2ã€ã®å¡ãéžã³ãããã®é«ããæ¯èŒãããšããããšã<var>N−1</var>åç¹°ãè¿ããã
</p>
<p>ã€ã¯ã¿åã®èª¿æ»ã«é¢ããŠä»¥äžã®ããšãããã£ãŠããã
</p>
<ul>
<li> <var>i</var>åç®ã®æ¯èŒ<var>(1 ≤ i ≤ \ N − 1)</var>ã§å¡<var>a<sub>i</sub></var>, å¡<var>b<sub>i</sub></var>ãéžã°ãããšãããšå¡<var>a<sub>i</sub></var>ã®é«ããå¡<var>b<sub>i</sub></var>ã®é«ããã倧ããã£ããã€ãŸã<var>T<sub>a<sub>i</sub>, b<sub>i</sub></sub> = 1</var>, <var>T<sub>b<sub>i</sub>, a<sub>i</sub></sub> = −1</var>ã§ãã£ãã
</li>
<li> ããããã®å¡ã¯èªåèªèº«ããã倧ããªå¡ãšã¯é«ã
äžåããæ¯èŒãããŠããªãã
</li></ul>
<p>æ®å¿µãªããã€ã¯ã¿åã®èª¿æ»ã«ããæ
å ±ã ãã§è¡š<var>T</var>ã®å
容ãäžæã«æ±ºããããšãã§ãããšã¯éããªãã
衚<var>T</var>ãã€ã¯ã¿åã®èª¿æ»ãšççŸããã<var>T</var>ãå®çŸ©ããããããªå¡ã®é«ãã®çµã¿åãããååšãããšã<var>T</var>ãæ£ãã衚ãšåŒã¶ããšã«ããã
æ£ãã衚ãšããŠäœéãã®ãã®ãèããããããèšç®ããŠã€ã¯ã¿åã«æããŠæ¬²ããã
</p>
<p>ãã ããæ¯èŒãããïŒã€ã®å¡ã®é«ãã¯äºãã«ç°ãªãããã¹ãŠã®å¡ã®é«ããäºãã«ç°ãªããšã¯éããªãã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var><br><var>a<sub>1</sub></var> <var>b<sub>1</sub></var><br>...<br><var>a<sub>N−1</sub></var> <var>b<sub>N−1</sub></var>
</pre>
<p><var>N</var>ã¯å¡ã®æ°ã衚ãã
<var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> (<var>1 ≤ i ≤ N − 1</var>)ã¯å¡<var>a<sub>i</sub></var>ãå¡<var>b<sub>i</sub></var>ããé«ãããšã衚ãã
</p>
<h3>Constraints</h3>
<p>å
¥åäžã®å倿°ã¯ä»¥äžã®å¶çŽãæºããã
</p>
<ul>
<li> <var>1 ≤ N ≤ 200</var>
</li>
<li> <var>0 ≤ a<sub>i</sub>, b<sub>i</sub> < N</var>
</li>
<li> <var>a<sub>i</sub> ≠ b<sub>i</sub></var>
</li>
<li> ç°ãªãå¡ãåãé«ãã§ããããšãããã
</li>
<li> ã€ã¯ã¿åã®èª¿æ»çµæèªäœãççŸããŠããããšã¯ãªããå°ãªããšã1ã€ã€ã¯ã¿åã®èª¿æ»çµæãšççŸããªã衚<var>T</var>ãååšããã
</li></ul>
<h2>Output</h2>
<p>èããããæ£ãã衚Tã®åæ°ã®æ°ã1,000,000,007ã§å²ã£ãããŸããåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>3
0 1
1 2
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Ordering_sample1" height="74" width="77">
<br>
<ul><li> æ£ãã衚<var>T</var>ã¯äžå³ã®1éãã§ããã
</li></ul>
<h2>Sample Input 2</h2>
<pre>3
0 1
0 2
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>3
</pre><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Ordering_sample5" height="76" width="233">
<br>
<ul><li> æ£ãã衚<var>T</var>ã¯äžå³ã®3éãã§ããã
</li></ul>
<h2>Sample Input 3</h2>
<pre>1
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>1
</pre><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Ordering_sample4" height="30" width="30">
<br>
<ul><li> æ£ãã衚<var>T</var>ã¯äžå³ã®1éãã§ããã
</li></ul>
<h2>Sample Input 4</h2>
<pre>7
0 1
1 2
2 3
3 4
0 5
0 6
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>91
</pre> |
p00831 |
<H1><font color="#000">Problem E:</font> Confusing Login Names</H1>
<p>
Meikyokan University is very famous for its research and education in the area of computer
science. This university has a computer center that has advanced and secure computing facilities
including supercomputers and many personal computers connected to the Internet.
</p>
<p>
One of the policies of the computer center is to let the students select their own login names.
Unfortunately, students are apt to select similar login names, and troubles caused by mistakes
in entering or specifying login names are relatively common. These troubles are a burden on
the staff of the computer center.
</p>
<p>
To avoid such troubles, Dr. Choei Takano, the chief manager of the computer center, decided
to stamp out similar and confusing login names. To this end, Takano has to develop a program
that detects confusing login names.
</p>
<p>
Based on the following four operations on strings, the distance between two login names is
determined as the minimum number of operations that transforms one login name to the other.
</p>
<ol>
<li> Deleting a character at an arbitrary position.</li>
<li> Inserting a character into an arbitrary position.</li>
<li> Replacing a character at an arbitrary position with another character.</li>
<li> Swapping two adjacent characters at an arbitrary position.</li>
</ol>
<p>
For example, the distance between â<span>omura</span>â and â<span>murai</span>â is two, because the following sequence
of operations transforms â<span>omura</span>â to â<span>murai</span>â.
</p>
<pre>
delete âoâ insert âiâ
omura --> mura --> murai
</pre>
<p>
Another example is that the distance between â<span>akasan</span>â and â<span>kaason</span>â is also two.
</p>
<pre>
swap âaâ and âkâ replace âaâ with âoâ
akasan --> kaasan --> kaason
</pre>
<p>
Takano decided that two login names with a small distance are confusing and thus must be
avoided.
</p>
<p>
Your job is to write a program that enumerates all the confusing pairs of login names.
</p>
<p>
Beware that the rules may combine in subtle ways. For instance, the distance between â<span>ant</span>â
and â<span>neat</span>â is two.
</p>
<pre>
swap âaâ and ânâ insert âeâ
ant --> nat --> neat
</pre>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset is given in the following format.
</p>
<pre>
<i>n</i>
<i>d</i>
<i>name</i><sub>1</sub>
<i>name</i><sub>2</sub>
...
<i>name<sub>n</sub></i>
</pre>
<p>
The first integer <i>n</i> is the number of login names. Then comes a positive integer <i>d</i>. Two login
names whose distance is less than or equal to <i>d</i> are deemed to be confusing. You may assume
that 0 < <i>n</i> ≤ 200 and 0 < <i>d</i> ≤ 2. The <i>i</i>-th studentâs login name is given by <i>name<sub>i</sub></i>, which is
composed of only lowercase letters. Its length is less than 16. You can assume that there are no
duplicates in <i>name<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>).
</p>
<p>
The end of the input is indicated by a line that solely contains a zero.
</p>
<H2>Output</H2>
<p>
For each dataset, your program should output all pairs of confusing login names, one pair per
line, followed by the total number of confusing pairs in the dataset.
</p>
<p>
In each pair, the two login names are to be separated only by a comma character (,), and the
login name that is alphabetically preceding the other should appear first. The entire output of
confusing pairs for each dataset must be sorted as follows. For two pairs â<i>w</i><sub>1</sub>,<i>w</i><sub>2</sub>â and â<i>w</i><sub>3</sub>,<i>w</i><sub>4</sub>â,
if <i>w</i><sub>1</sub> alphabetically precedes <i>w</i><sub>3</sub>, or they are the same and <i>w</i><sub>2</sub> precedes <i>w</i><sub>4</sub>, then â<i>w</i><sub>1</sub>,<i>w</i><sub>2</sub>â must
appear before â<i>w</i><sub>3</sub>,<i>w</i><sub>4</sub>â.
</p>
<H2>Sample Input</H2>
<pre>
8
2
omura
toshio
raku
tanaka
imura
yoshoi
hayashi
miura
3
1
tasaka
nakata
tanaka
1
1
foo
5
2
psqt
abcdef
abzdefa
pqrst
abdxcef
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
imura,miura
imura,omura
miura,omura
toshio,yoshoi
4
tanaka,tasaka
1
0
abcdef,abdxcef
abcdef,abzdefa
pqrst,psqt
3
</pre>
|
p01373 |
<!-- begin en only -->
<!--<h3><U>Divide the Cake</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>
ã€ã³ãšãã³ã¯ACMå士ã«ãã£ãŠéçºããã人工ç¥èœãæèŒããååã®ããããã§ããïŒä»æ¥ã¯äºäººã®èªçæ¥ãªã®ã§ïŒå士ã¯äºäººã®ããã«ããããã®ã€ããŽãã®ã£ãã±ãŒããçšæããïŒ
</p>
<p>
ã±ãŒãã¯æšªå¹
<i>W</i> Ã奥è¡ã <i>H</i> ã®é·æ¹åœ¢ã®åœ¢ãããŠããïŒ
䟿å®äžïŒã±ãŒãã¯äžããèŠããšã(0,0)ïŒ(<i>W</i> ,0)ïŒ(<i>W</i> ,<i>H</i> )ïŒ(0,<i>H</i> )ãé ç¹ãšããé·æ¹åœ¢ã«ãªãããã«çœ®ãããŠãããšããïŒ
ãŸãïŒäºäººã«åçã«ãªãããã«ã¡ããã©2<i>N</i> åã®ã€ããŽãä¹ã£ãŠããïŒ
</p>
<p>
ãã£ãããªã®ã§ïŒå士ã¯äºäººã«ã±ãŒããåãããããšã«ããïŒ
ã€ã³ãšãã³ã¯ååããŠã±ãŒããåãããïŒã€ã³ãå
äžã®äžç«¯ã蟺(0,0)-(0,<i>H</i> )ã®éã«ããïŒãã³ã¯ããäžç«¯ã蟺(<i>W</i> ,0)-(<i>W</i> ,<i>H</i> )ã®éã«ãããŠåæã«äžã«äžãããšããæ¹æ³ããšãããšã«ããïŒ
ãã¡ããå
äžã¯çŽç·ç¶ãªã®ã§ïŒéžãã 2ç¹ãéãçŽç·ã§ã±ãŒãã¯2ã€ã«åãããïŒ(å³E-1)
</p>
<p style="text-align: center;">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011E-1" width="50%"><br/>
å³E-1
</p>
<p>
å士ã¯äººå·¥ç¥èœã宿ãããããšã«æºè¶³ãä»ã®éšåãé©åœã«äœã£ãããã«ïŒäºäººã®è
ã®ããŒãã¯äžå®å®ã«ãªã£ãŠããŸã£ãïŒ
ãã®ããïŒèŸº(0,0)-(0,<i>H</i> )(ãŸãã¯èŸº(<i>W</i> ,0)-(<i>W</i> ,<i>H</i> ))äžã®çã£ãå Žæã«çœ®ãããšããŠãã©ãããŠããããŠããŸãã®ã§ããïŒ
</p>
<p>
äºäººã¯ã€ããŽã奜ããªã®ã§ïŒã§ããã° <i>N</i> åãã€ã«åããããšèããŠããïŒ
ããã§ïŒ<i>N</i> åãã€ã«ãªãããã«åããªãå Žåã¯2ç¹ãéžã³ãªããããšã«ããïŒ
2<i>N</i> åã®ã€ããŽã®é
眮ã«ãã£ãŠã¯ååãã€ã«åããããªãã£ããïŒåãããããšããŠãïŒãšãŠã確çãäœãå ŽåãèããããïŒ
ãã®ãããªå Žåã«äœåºŠã2ç¹ãéžã³ãªããã®ã¯äžæ¯ãªã®ã§ïŒãŸãåãã« <i>N</i> åãã€ã«åãããããã«åãã確çãèšç®ããããšã«ããïŒ
</p>
<p>
äºäººã®è
ã®ããŒãã¯äžå®å®ãªã®ã§ïŒåããäºæ³ããã®ã¯é£ããïŒ
ãšããããïŒäºäººã¯ãå
äžã眮ãç¹ã¯èŸº(0,0)-(0,<i>H</i> )(ãŸãã¯èŸº(<i>W</i> ,0)-(<i>W</i> ,<i>H</i> ))äžã«å¿
ãä¹ãïŒçœ®ããã確çã¯ã©ã®äºç¹ãçããããšããä»®å®ã眮ãããšã«ããïŒ
ãŸãïŒã€ããŽã®å€§ãããèæ
®ããã®ãé¢åãªã®ã§ïŒç¹ãšã¿ãªãããšã«ããïŒ
</p>
<p>
ããã¯äººå·¥ç¥èœã®æ§èœã詊ãããæ©äŒã§ããïŒ
å士ãšåãç ç©¶æã«å€ããŠããããªãã«ïŒ2<i>N</i> åã®ã€ããŽã®äœçœ®ãäžãããããšãã«ïŒ 2人ãšåãä»®å®ãçšããŠã€ããŽã <i>N</i> åãã€ã«åããã確çãèšç®ããããã°ã©ã ãäœæããä»äºãå²ãåœãŠãããïŒ
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒå
¥åã®çµããã¯ç©ºçœã§åºåããã3ã€ã®ãŒããããªãè¡ã«ãã£ãŠäžããããïŒåããŒã¿ã»ããã¯1ã€ã®ã±ãŒãã«é¢ããæ
å ±ã衚ãïŒãã®åœ¢åŒã¯ä»¥äžã®éãã§ããïŒ
</p>
<blockquote>
<i>W</i> <i>H</i> <i>N</i><br/>
<i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br/>
...<br/>
<i>x<sub>2N</sub></i> <i>y<sub>2N</sub></i><br/>
</blockquote>
<p>
ããŒã¿ã»ããã®æåã®è¡ã¯3ã€ã®æŽæ° <i>W</i> ,<i>H</i> ,<i>N</i> ãããªãïŒããããã±ãŒãã®æšªå¹
ïŒå¥¥è¡ãïŒã€ããŽã®åæ°/2ã衚ãïŒ
ç¶ã2<i>N</i> è¡ã¯2åã®æŽæ°ãããªãïŒããããã€ããŽã®x座æšãšy座æšã衚ãïŒ
</p>
<p>
ããããã®å€ã¯æ¬¡ã®å¶çŽãæºãããŠããïŒ
<ul>
<li>1 ≤ <i>W</i> ,<i>H</i> ≤ 1,000</li>
<li>1 ≤ <i>N</i> ≤ 100</li>
<li>0 ≤ <i>x<sub>i</sub></i> ≤ <i>W</i></li>
<li>0 ≤ <i>y<sub>i</sub></i> ≤ <i>H</i></li>
</ul>
</p>
<p>
ãŸãïŒ2ã€ã®ç°ãªãã€ããŽãåã座æšã«ããããšã¯ãªãïŒ
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
ããããã®ããŒã¿ã»ããã«å¯ŸããŠïŒ 2人ã®ä»®å®ãçšããå Žåã«ã€ããŽã2çåããã確çã衚ã宿°ã1è¡ã«åºåããïŒ
çãã«ã¯ 10<sup>-8</sup> ãè¶ãã誀差ããã£ãŠã¯ãããªãïŒãã以å€ã®äœèšãªæåãåºåããŠã¯ãªããªãïŒ
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
2 2 1
0 1
2 1
3 3 1
1 1
2 1
0 0 0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
0.5000000000
0.1666666667
</pre>
</div>
|
p01689 |
<h2>C - Dowsing Machine / ããŠãžã³ã°ãã·ãŒã³</h2>
<h3>Story</h3>
<p>äžéã§ã¯Xã ãšãYã ãšãã§éšãããããã©ãããããã®æä»£ã¯"D"ã§ããã"ãã¯ãªã³ã¢ã³ã¹ã¿ãŒD"ã¯ãç§å¯çµç€Ÿ"Rå£"ã«ãã£ãŠéçºããã"Dãã·ã³"ã䜿ã£ãŠ"Dã®ã²ãš"ãè²¡å®æ¢çŽ¢ãè¡ã倧人æ°ã²ãŒã ã§ããã</p>
<p>ãã®ã²ãŒã ã§ã¯ãæ Œåç¶ãããã®ãããã¹ã«ããDã®ã²ãšãã飿¥ããäžäžå·Šå³ã®ãã¹ãžã®ç§»åãç¹°ãè¿ãã財å®ãååšãããã¹ãžã®å°éãç®æãã ãããäžã«ã¯è²¡å®ãååšãããã¹ã1ã€ã ãããã 財å®ãååšãããã¹ã¯æããã«ãããŠããªããããDãã·ã³ã䜿ã£ãŠååšãã財å®ã®ãã¹ãçµã蟌ãã§ããã財å®ãååšãããã¹ãžç§»åãããã</p>
<p>Dãã·ã³ã䜿ããšã財å®ãååšãããã¹ãå«ãè€æ°ãã¹ãžã®åå¿ã瀺ããåå¿ã¯ãDãã·ã³ã䜿ã£ããšãã«Dã®ã²ãšãå±
ããã¹ãåºæºã«è¡šçŸãããããã ããDãã·ã³ã¯å£ããŠããããšããããDãã·ã³ã䜿ã£ããšãã«ã財å®ãååšãåŸãªããã¹ãžã®åå¿ã瀺ãããšãããããŸããDã®ã²ãšãç§»åã§ããªãå£ãã¹ããããäžã«ååšããããã財å®ã®ååšãããã¹ã«ç§»åã§ããªãããšããããDã®ã²ãšã¯ãããããªãã¹ã§Dãã·ã³ã䜿ãããã®åå¿ã芳枬ãããDã®ã²ãšã¯ã財å®ã®ååšãããã¹ã«å°éã§ããã ãããã</p>
<h3>Problem</h3>
<!--
<dl>
<dt>é«ã <var>h</var> å¹
<var>w</var> ã®äºæ¬¡å
æ Œåãèããããããã¹ <var>t_{i,j}</var> ã¯ã次ã®ããããã®æåã§è¡šãããã</dt>
<dd>
-->
<p>é«ã <var>h</var> å¹
<var>w</var> ã®äºæ¬¡å
æ Œåãèããããããã¹ <var>t_{i,j}</var> ã¯ã次ã®ããããã®æåã§è¡šãããã</p>
<ul>
<li>"." : éè¡å¯èœã§ããããšã衚ãããã®ãã¹ã«ã¯è²¡å®ãååšãããããããªãã</li>
<li>"#" : å£ããããéè¡äžå¯èœã§ããããšã衚ãããã®ãã¹ã«ã¯è²¡å®ã¯ååšããªãã</li>
<li>"D" : éè¡å¯èœã§ãããDã®ã²ãšãããããšã衚ãããã®ãã¹ã«ã¯è²¡å®ãååšãããããããªãã</li>
</ul>
<!--
</dd>
</dl>
-->
<p>Dã®ã²ãšã¯ãäžäžå·Šå³ã«é£æ¥ããéè¡å¯èœãªãã¹ãžç§»åããããšãã§ããã</p>
<p>Dãã·ã³ã¯äœ¿çšããäœçœ®ã«å¿ããŠãå³ã®ãããªäºæ¬¡å
æ Œåå
ã®ããããã®ãã¹éåãžã®åå¿ã瀺ããäžå³ã®åç©åœ¢ã¯ïŒãããããååŸ <var>r_1, r_2, ..., r_d</var> ã®æ£æ¹åœ¢ã§ãããæ£æ¹åœ¢ã®ååŸã <var>r_k</var> ã§ãããšã¯ãæ£æ¹åœ¢ã®äžèŸºã®é·ãã <var>2 r_k + 1</var> ã§ããããšãæå³ããã</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_fig1" alt="fig1.png" />
</center>
<br/>
<p><var>(x, y)</var>ã§Dãã·ã³ã䜿çšãããšãã«ç€ºãããåå¿ã <var>s</var> ãšããã<var>1 \leq s \leq d-1</var>ã®ãšãã¯ã<var>(x, y)</var>ãäžå¿ãšããååŸ <var>r_{s+1}</var> ã®æ£æ¹åœ¢ããã ååŸ <var>r_s</var> ã®æ£æ¹åœ¢ãé€ããå³åœ¢ã«å«ãŸãããã¹ã«è²¡å®ãååšããããšã衚ãã<var>s=0</var> ã®ãšãã¯ã<var>(x, y)</var>ãäžå¿ãšããååŸ <var>r_1</var> ã®æ£æ¹åœ¢ã«å«ãŸãããã¹ã«è²¡å®ãååšããããšã衚ãã<var>s=d</var> ã®ãšãã¯ã<var>(x, y)</var>ãäžå¿ãšããååŸ <var>r_d</var> ã®æ£æ¹åœ¢ã®å€åŽã®ãã¹ã«è²¡å®ãååšããããšã衚ãã財å®ãååšãããã¹ã¯å¿
ã<var>1</var>ã€ã ãååšãããããããDãã·ã³ãå£ããŠããå ŽåãDãã·ã³ã¯ããã«ççŸããåå¿ã瀺ãã</p>
<p>Dãã·ã³ã®äœ¿çšã«ãã£ãŠç€ºãããåå¿ãè€æ°äžããããã Dãã·ã³ã確å®ã«å£ããŠããå Žåã¯"Broken"ãDã®ã²ãšãããäœçœ®ãã財å®ã®ååšãããã¹ã«å¿
ããã©ãçããå Žåã¯"Yes"ã絶察ã«ãã©ãçããªãå Žåã¯"No"ããã©ãçãããã©ããåãããªãå Žåã¯"Unknown"ãåºåããã</p>
<h3>Input</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre><var>h</var> <var>w</var> <var>d</var> <var>n</var>
<var>t_{0,0}t_{0,1}...t_{0,w-1}</var>
<var>...</var>
<var>t_{h-1,0}t_{h-1,1}...t_{h-1,w-1}</var>
<var>r_1</var> <var>r_2</var> <var>...</var> <var>r_d</var>
<var>x_1</var> <var>y_1</var> <var>s_1</var>
<var>...</var>
<var>x_n</var> <var>y_n</var> <var>s_n</var></pre>
<p>1è¡ç®ã¯4ã€ã®æŽæ°ãããªãïŒããããïŒäºæ¬¡å
æ Œåã®çžŠå¹
<var>h</var>ãæšªå¹
<var>w</var>ã æ£æ¹åœ¢ã®åæ°<var>d</var>ãDãã·ã³ã䜿çšããåæ°<var>n</var>ã空çœ1æååºåãã§äžŠãã§ããã ç¶ã<var>h</var>è¡ã§ã¯åãã¹ã®æåãäžããããã <var>i+2</var>è¡ç®(<var>0 \leq i < h</var>)ã®<var>j+1</var>çªç®(<var>0 \leq j < w</var>)ã®æå<var>t_{i,j}</var>ã¯ãã¹<var>(j,i)</var>ã®æåã衚ãã <var>h+2</var>è¡ç®ã§ã¯ã忣æ¹åœ¢ã®ååŸ<var>r_k</var>(<var>1 \leq k \leq d</var>)ã空çœ1æååºåãã§äžããããã ç¶ã<var>n</var>è¡ã§ã¯ãDãã·ã³ã®åå¿ãäžããããã <var>l+h+3</var>è¡ç®(<var>1 \leq l \leq n</var>)ã§ã¯ã<var>x_l</var>ã<var>y_l</var>ã<var>s_l</var>ã空çœ1æååºåãã§äžãããããã¹<var>(x_l, y_l)</var>ã§Dãã·ã³ã䜿çšãããšãã«åå¿<var>s_l</var>ã瀺ãããããšã衚ãã</p>
<p>å¶çŽ</p>
<ul>
<li><var>1 \leq h \leq 50, 1 \leq w \leq 50, 1 \leq d \leq 10, 1 \leq n \leq 50</var></li>
<li><var>t_{i,j}</var>ã¯"#", ".", "D"ã®ããããã§ãããæå"D"ã¯å¿
ã1ã€ã ãååšãã</li>
<li><var>0 \leq r_k \leq 50</var>ã§ããïŒ<var>k > 1</var>ã«ã€ããŠ<var>r_{k-1} < r_k</var></li>
<li><var>0 \leq x_l < w, 0 \leq y_l < h, 0 \leq s_l \leq d</var></li>
<li>æå"D"ã§è¡šããããã¹ããã®ç§»åãç¹°ãè¿ãããšã§ïŒãã¹<var>(x_l, y_l)</var>ãžå°éããããšãã§ãã</li>
</ul>
<h3>Output</h3>
<p>"Broken", "Yes", "No", "Unknown"ã®ããããã®ãã¡ãé©åãªãã®ã<var>1</var>è¡ã«åºåãããè¡ã®æåŸã§ã¯å¿
ãæ¹è¡ãè¡ãããšã</p>
<h3>Sample Input 1</h3>
<pre>6 10 3 4
##########
#........#
#...D....#
#........#
#........#
##########
2 4 6
3 2 0
7 4 2
8 4 3
1 4 1</pre>
<h3>Sample Output 1</h3>
<pre>Yes</pre>
<h3>Sample Input 2</h3>
<pre>6 10 2 3
##########
#.#......#
###......#
#......D.#
#........#
##########
1 2
3 2 1
3 1 1
1 3 1</pre>
<h3>Sample Output 2</h3>
<pre>No</pre>
<h3>Sample Input 3</h3>
<pre>6 10 3 1
##########
#........#
#...D....#
#........#
#........#
##########
2 4 6
3 4 3</pre>
<h3>Sample Output 3</h3>
<pre>Broken</pre>
<h3>Sample Input 4</h3>
<pre>6 10 3 3
##########
#.#......#
###.D....#
#.#......#
#........#
##########
2 4 6
3 2 0
7 4 2
8 4 3</pre>
<h3>Sample Output 4</h3>
<pre>Unknown</pre> |
p00132 |
<h1>ãžã°ãœãŒããºã«</h1>
<p>
åäŸãã倧人ãŸã§è³ãã¬ç³»ããºã«ã²ãŒã ãæµè¡ããŠããŸããæã
ãé
ããåãã¬ãããããºã«ã²ãŒã ãäœã£ãŠã¿ããªã§éã¶ããšã«ããŸããã
</p>
<p>
æã
ãèããã®ã¯ãžã°ãœãŒããºã«ã®ã²ãŒã ã§ãæªå®æã®éšåãåããã®ã«å¿
èŠãªããŒã¹ãéžã¶ãšãããã®ã§ããå³ 1 (a) ã¯ããºã«ã®æ ã®äŸã§ããé»ãåãŸã£ãŠããéšåãçœãæªå®æã®éšåã§ãããã®ããºã«ã宿ããã®ã«äœ¿ããããŒã¹ãå³ 1 (b) ã®ããã«äžããããŸãããã®äžãããæ ã®çœãéšåãåããããšãã§ããé»ãããŒã¹ã 1 ã€ä»¥äžéžæããŸããäŸãã°ãå³ 2 ã®éžæäŸ 1 ã®ãããªçµã¿åãããªãæ£è§£ãšãªããŸããäžæ¹ãéžæäŸ 2 ã®ãããªçµã¿åããã§ã¯ããºã«ã¯å®æããªãã®ã§äžæ£è§£ãšãªããŸãããŸããéžæããããŒã¹ãäœã£ãŠããŸãå Žåãäžæ£è§£ã§ãããã®ããã«ããã¬ã€ã€ãŒã¯é©åãªããŒã¹ãéžæããããšã§ã²ãŒã ãã¯ãªã¢ããŸãã
</p>
<p>
ããã§ãã®ããºã«ã²ãŒã ã§çšããå€å®ããã°ã©ã ãéçºããããšã«ãªããŸãããæªå®æã®ããºã«ãããŒã¹ã®åè£ããããŠãã¬ã€ã€ãŒãéžãã ããŒã¹ã®çµã¿åãããå
¥åãšãããã¬ã€ã€ãŒãé©åãªããŒã¹ãéžã¶ããšãã§ããŠããã° YES ããããã§ãªããã° NO ãšåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>
ãã®åé¡ã§ã¯ãããºã«ã®æ 㯠<var>H × W</var> ã®é
åã§è¡šããæªå®æã®éšåã . (åè§ããªãªã)ã宿ããŠããéšåã # (åè§ã·ã£ãŒã)ã«ãã£ãŠäžããŸããããºã«ã®æ ã®å€§ããã¯æå€§ <var>20 × 20</var> ãšããŸãããŸããåããŒã¹ã¯ <var>h × w</var> ã®é
åã§è¡šããããŒã¹ãæ§æããéšåã # ãããã§ãªãéšåã . ã«ãã£ãŠäžããŸããäžããããåããŒã¹ã¯ãå
ã®ç¶æ
ãã 90 床ã180 床ã270 床ã ãå転ããããšãã§ããŸãããŸããåããŒã¹ã®å€§ããã¯æå€§ <var>20 × 20</var> ãšããäžããããããŒã¹ã®æ° <var>n</var> ã¯æå€§ 10 ãšããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_jigsawPuzzle">
</center>
<br>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>H</var> <var>W</var>
<var>g<sub>1,1</sub></var><var>g<sub>1,2</sub></var>...<var>g<sub>1,W</sub></var>
<var>g<sub>2,1</sub></var><var>g<sub>2,2</sub></var>...<var>g<sub>2,W</sub></var>
:
<var>g<sub>H,1</sub></var><var>g<sub>H,2</sub></var>...<var>g<sub>H,W</sub></var>
<var>n</var>
<var>h<sub>1</sub></var> <var>w<sub>1</sub></var>
<var>c1<sub>1,1</sub></var><var>c1<sub>1,2</sub></var>...<var>c1<sub>1,w<sub>1</sub></sub></var>
<var>c1<sub>2,1</sub></var><var>c1<sub>2,2</sub></var>...<var>c1<sub>2,w<sub>1</sub></sub></var>
:
<var>c1<sub>h<sub>1</sub>,1</sub></var><var>c1<sub>h<sub>1</sub>,2</sub></var>...<var>c1<sub>h<sub>1</sub>,w<sub>1</sub></sub></var>
:
:
<var>h<sub>n</sub></var> <var>w<sub>n</sub></var>
<var>cn<sub>1,1</sub></var><var>cn<sub>1,2</sub></var>...<var>cn<sub>1,w<sub>n</sub></sub></var>
<var>cn<sub>2,1</sub></var><var>cn<sub>2,2</sub></var>...<var>cn<sub>2,w<sub>n</sub></sub></var>
:
<var>cn<sub>h<sub>n</sub>,1</sub></var><var>cn<sub>h<sub>n</sub>,2</sub></var>...<var>cn<sub>h<sub>n</sub>,w<sub>n</sub></sub></var>
<var>p</var>
<var>k<sub>1</sub></var> <var>t<sub>1</sub></var> <var>t<sub>2</sub></var> ... <var>t<sub>k<sub>1</sub></sub></var>
<var>k<sub>2</sub></var> <var>t<sub>1</sub></var> <var>t<sub>2</sub></var> ... <var>t<sub>k<sub>2</sub></sub></var>
:
<var>k<sub>p</sub></var> <var>t<sub>1</sub></var> <var>t<sub>2</sub></var> ... <var>t<sub>k<sub>p</sub></sub></var>
</pre>
<p>
1 è¡ç®ã«ãããºã«ã®æ ã®å€§ãã <var>H</var>(瞊) ãš <var>W</var>(暪) ãäžããããŸãã
2 è¡ç®ã«ãæå <var>g<sub>i,j</sub></var> (<span>.</span> ãŸã㯠<span>#</span>) ãããªãããºã«ã®ç€é¢ã衚ã 1 è¡ <var>W</var> æåã®æååã <var>H</var> è¡äžããããŸãã
</p>
<p>
ç¶ããŠããŒã¹ã®æ° <var>n</var>ã<var>n</var> åã®ããŒã¹ã®æ
å ±ãäžããããŸããåããŒã¹ã®æ
å ±ãšããŠã<var>l</var> çªç®ã®ããŒã¹ã®é
åã®ãµã€ãº <var>h<sub>l</sub></var> (瞊) ãš <var>w<sub>l</sub></var> (暪)ã<var>l</var> çªç®ã®ããŒã¹ã®é
åãäžããããŸãã<var>l</var> çªç®ã®ããŒã¹ã®é
åãšããŠæå <var>cl<sub>i,j</sub></var> (<span>.</span> ãŸã㯠<span>#</span>) ãããªã 1 è¡ <var>w<sub>l</sub></var> æåã®æååã <var>h<sub>l</sub></var> è¡äžããããŸãã
</p>
<p>
ç¶ããŠãã¬ã€ã€ãŒã®äººæ° <var>p</var>ã<var>i</var> çªç®ã®ãã¬ã€ã€ãŒã®éžæããããŒã¹ã®æ° <var>k<sub>i</sub></var> ãšéžæããããŒã¹ã®çªå· <var>t<sub>j</sub></var> ãäžããããŸãã
</p>
<p>
å
¥åã¯ïŒã€ã® 0 ãå«ãè¡ã§çµäºããŸããããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ã<var>i</var> çªç®ã®ãã¬ã€ã€ãŒãéžæããããŒã¹ã®æ£åŠ YES ãŸã㯠NO ã <var>i</var> è¡ç®ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
14 20
####################
###.............####
####..........######
#######.....########
########.....#######
###..###......######
###..####......#####
#########......#####
###########.....####
############.....###
###.########......##
###.#######...###.##
##...###....#####.##
####################
10
12 15
#############..
.##########....
....#####......
.....#####.....
.....######....
......######...
......######...
........#####..
.........#####.
.........######
........###...#
.....####.....#
3 3
#..
###
#..
2 2
##
##
4 10
....#####.
....######
...###...#
####.....#
6 5
....#
..###
#####
##.##
#..##
#..#.
6 4
...#
.###
####
##.#
##.#
#...
2 6
######
.#####
2 7
..#####
#######
2 13
#############
.##########..
6 9
#####....
.######..
.######..
..######.
...#####.
....#####
8
3 1 2 3
4 1 2 3 4
7 2 3 4 5 6 7 8
5 2 3 10 7 8
6 2 3 9 5 6 4
8 2 3 4 6 9 5 4 10
4 4 5 6 9
5 10 2 3 4 9
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
YES
NO
YES
NO
NO
YES
</pre>
|
p00562 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>Soccer</h1>
<p>
You are a manager of a prestigious soccer team in the JOI league.
</p>
<p>
The team has $N$ players numbered from 1 to $N$. The players are practicing hard in order to win the tournament game. The field is a rectangle whose height is $H$ meters and width is $W$ meters. The vertical line of the field is in the north-south direction, and the horizontal line of the field is in the east-west direction. A point in the field is denoted by ($i, j$) if it is $i$-meters to the south and $j$ meters to the east from the northwest corner of the field.
</p>
<p>
After the practice finishes, players must clear the ball. In the beginning of the clearance, the player $i$ ($1 \leq i \leq N$) stands at ($S_i, T_i$). There is only one ball in the field, and the player 1 has it. You stand at ($S_N, T_N$) with the player $N$. The clearance is finished if the ball is passed to ($S_N, T_N$), and you catch it. You cannot move during the clearance process.
</p>
<p>
You can ask players to act. But, if a player acts, his <b>fatigue degree</b> will be increased according to the action. Here is a list of possible actions of the players. If a player has the ball, he can act (i),(ii), or (iii). Otherwise, he can act (ii) or (iv).
</p>
<ul>
<li> (i) Choose one of the 4 directions (east/west/south/north), and choose a positive integer $p$. Kick the ball to that direction. Then, the ball moves exactly p meters. The kicker does not move by this action, and he loses the ball. His fatigue degree is increased by $A \times p + B$.</li>
<li>(ii) Choose one of the 4 directions (east/west/south/north), and move 1 meter to that direction. If he has the ball, he moves with it. His fatigue degree is increased by $C$ regardless of whether he has the ball or not.</li>
<li>(iii) Place the ball where he stands. He loses the ball. His fatigue degree does not change.</li>
<li>(iv) Take the ball. His fatigue degree does not change. A player can take this action only if he stands at the same place as the ball, and nobody has the ball.</li>
</ul>
<p>
Note that it is possible for a player or a ball to leave the field. More than one players can stand at the same place.
</p>
<p>
Since the players just finished the practice, their fatigue degrees must not be increased too much. You want to calculate the minimum possible value of the sum of fatigue degrees of the players for the clearance process.
</p>
<h2>Task</h2>
<p>
Given the size of the field and the positions of the players, write a program which calculates the minimum possible value of the sum of fatigue degrees of the players for the clearance process.
</p>
<h3>Input</h3>
<p>
Read the following data from the standard input.
</p>
<ul>
<li> The first line of input contains two space separated integers $H$, $W$. This means the field is a rectangle whose height is $H$ meters and width is $W$ meters.</li>
<li> The second line contains three space separated integers $A$, $B$, $C$ describing the increment of the fatigue degree by actions.</li>
<li> The third line contains an integer N, the number of players.</li>
<li> The $i$-th line ($1 \leq i \leq N$) of the following $N$ lines contains two space separated integers $S_i$, $T_i$. This means, in the beginning of the clearance, the player $i$ ($1 \leq i \leq N$) stands at ($S_i, T_i$).</li>
</ul>
<h3>Output</h3>
<p>
Write one line to the standard output. The output contains the minimum possible value of the sum of fatigue degrees of the players for the clearance process.
</p>
<h3>Constraints</h3>
<p>
All input data satisfy the following conditions.
</p>
<ul>
<li>$1 \leq H \leq 500ïŒ$</li>
<li>$1 \leq W \leq 500ïŒ$</li>
<li>$0 \leq A \leq 1 000 000 000ïŒ$</li>
<li>$0 \leq B \leq 1 000 000 000ïŒ$</li>
<li>$0 \leq C \leq 1 000 000 000ïŒ$</li>
<li>$2 \leq N \leq 100 000ïŒ$</li>
<li>$0 \leq S_i \leq H (1 \leq i \leq N)ïŒ$</li>
<li>$0 \leq T_i \leq W (1 \leq i \leq N)ïŒ$</li>
<li>$(S_1, T_1) \ne (S_N, T_N)ïŒ$</li>
</ul>
<h3>Sample Input and Output</h3>
<h3>Sample Input 1</h3>
<pre>
6 5
1 3 6
3
1 1
0 4
6 5
</pre>
<h3>Sample Output 1</h3>
<pre>
26
</pre>
<p>
In this sample input, the initial status of the field is as in the following figure. The white circles are the players. The black circle is the ball. You stand at (6, 5).
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_4_1" width="280"><br>
The initial status of the field</br>
</center>
<p>
The players act as follows:
</p>
<ol>
<li>. The player 1 kicks the ball to the east for $3$ meters. His fatigue degree is increased by $1 \times 3 + 3 = 6$. The ball moves to ($1, 4$).</li>
<li> The player 2 moves $1$ meter to the south, and he has the ball. His fatigue degree is increased by $6$.</li>
<li> The player 2 moves $1$ meter to the east. His fatigue degree is increased by $6$.</li>
<li> The player 2 kicks the ball to the south for $5$ meters. His fatigue degree is increased by $1 \times 5 + 3 = 8$. The ball moves to ($6, 5$).</li>
</ol>
<p>
In these actions, the sum of fatigue degrees is $6 + 6 + 6 + 8 = 26$, which is the minimum possible value.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_4_2" width="600"><br>
The actions in an optimal solution
</center>
<h3>Sample Input 2</h3>
<pre>
3 3
0 50 10
2
0 0
3 3
</pre>
<h3>Sample Output 2</h3>
<pre>
60
</pre>
<p>In Sample Input 2, it not not necessary to</p>
<h3>Sample Input 3</h3>
<pre>
4 3
0 15 10
2
0 0
4 3
</pre>
<h3>Sample Output 3</h3>
<pre>
45
</pre>
<h3>Sample Input 4</h3>
<pre>
4 6
0 5 1000
6
3 1
4 6
3 0
3 0
4 0
0 4
</pre>
<h3>Sample Output 4</h3>
<pre>
2020
</pre>
<p>
that more than one players can stand at the same place.
</p>
<br/>
<div class="source">
<p class="source">
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commonse License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
</p>
<p class="source">
<a href="https://www.ioi-jp.org/joi/2016/2017-ho/index.html">The 16th Japanese Olympiad in Informatics (JOI 2016/2017)
Final Round</p>
</p>
</div> |
p00098 |
<H1>Maximum Sum Sequence II</H1>
<p>
äžããããæŽæ°ã®è¡å
</p>
<pre>
<var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,n</sub></var>
<var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,n</sub></var>
:
<var>a<sub>n,1</sub></var> <var>a<sub>n,2</sub></var> ... <var>a<sub>n, n</sub></var>
</pre>
<p>
ã§ãçžŠã»æšªæ¹åã«ïŒã€ä»¥äžé£ç¶ããé
ïŒéšåè¡åïŒã®åã®æå€§å€ãåºåããŠçµäºããããã°ã©ã ãäœæããŠäžããã
</p>
<H2>Input</H2>
<p>
å
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,n</sub></var>
<var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,n</sub></var>
:
<var>a<sub>n,1</sub></var> <var>a<sub>n,2</sub></var> ... <var>a<sub>n, n</sub></var>
</pre>
<p>
<var>n</var> 㯠1 ä»¥äž 100 以äžã<var>a<sub>i,j</sub></var> 㯠-10000 ä»¥äž 10000 以äžã§ãã
<H2>Output</H2>
<p>
æå€§å€ã 1 è¡ã«åºåããŠäžããã
</p>
<H2>Sample Input 1</H2>
<pre>
3
1 -2 3
-4 5 6
7 8 -9
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
16
</pre>
<p>
ãã®å
¥åã®å Žåã以äžã®éšåè¡åã®é
ã®åãæå€§ãšãªããŸãã
</p>
<pre>
-4 5
7 8
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4
1 3 -9 2
2 7 -1 5
-8 3 2 -1
5 0 -3 1
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
15
</pre>
<p>
ãã®å
¥åã®å Žåã以äžã®éšåè¡åã®é
ã®åãæå€§ãšãªããŸãã
</p>
<pre>
7 -1 5
3 2 -1
</pre>
|
p02230 | UF with binary input (K = 100) |
p02660 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Given is a positive integer <var>N</var>. Consider repeatedly applying the operation below on <var>N</var>:</p>
<ul>
<li>First, choose a positive integer <var>z</var> satisfying all of the conditions below:<ul>
<li><var>z</var> can be represented as <var>z=p^e</var>, where <var>p</var> is a prime number and <var>e</var> is a positive integer;</li>
<li><var>z</var> divides <var>N</var>;</li>
<li><var>z</var> is different from all integers chosen in previous operations.</li>
</ul>
</li>
<li>Then, replace <var>N</var> with <var>N/z</var>.</li>
</ul>
<p>Find the maximum number of times the operation can be applied.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^{12}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the maximum number of times the operation can be applied.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>24
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We can apply the operation three times by, for example, making the following choices:</p>
<ul>
<li>Choose <var>z=2 (=2^1)</var>. (Now we have <var>N=12</var>.)</li>
<li>Choose <var>z=3 (=3^1)</var>. (Now we have <var>N=4</var>.)</li>
<li>Choose <var>z=4 (=2^2)</var>. (Now we have <var>N=1</var>.)</li>
</ul>
</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>
<p>We cannot apply the operation at all.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>64
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3
</pre>
<p>We can apply the operation three times by, for example, making the following choices:</p>
<ul>
<li>Choose <var>z=2 (=2^1)</var>. (Now we have <var>N=32</var>.)</li>
<li>Choose <var>z=4 (=2^2)</var>. (Now we have <var>N=8</var>.)</li>
<li>Choose <var>z=8 (=2^3)</var>. (Now we have <var>N=1</var>.)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1000000007
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1
</pre>
<p>We can apply the operation once by, for example, making the following choice:</p>
<ul>
<li><var>z=1000000007 (=1000000007^1)</var>. (Now we have <var>N=1</var>.)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>997764507000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>7
</pre></section>
</div>
</span> |
p03972 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>On an <var>xy</var> plane, in an area satisfying <var>0 †x †W, 0 †y †H</var>, there is one house at each and every point where both <var>x</var> and <var>y</var> are integers.</p>
<p>There are unpaved roads between every pair of points for which either the <var>x</var> coordinates are equal and the difference between the <var>y</var> coordinates is <var>1</var>, or the <var>y</var> coordinates are equal and the difference between the <var>x</var> coordinates is <var>1</var>.</p>
<p>The cost of paving a road between houses on coordinates <var>(i,j)</var> and <var>(i+1,j)</var> is <var>p_i</var> for any value of <var>j</var>, while the cost of paving a road between houses on coordinates <var>(i,j)</var> and <var>(i,j+1)</var> is <var>q_j</var> for any value of <var>i</var>.</p>
<p>Mr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠W,H ⊠10^5</var></li>
<li><var>1 ⊠p_i ⊠10^8(0 ⊠i ⊠W-1)</var></li>
<li><var>1 ⊠q_j ⊠10^8(0 ⊠j ⊠H-1)</var></li>
<li><var>p_i (0 ⊠i ⊠Wâ1)</var> is an integer.</li>
<li><var>q_j (0 ⊠j ⊠Hâ1)</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Inputs are provided from Standard Input in the following form.</p>
<pre><var>W</var> <var>H</var>
<var>p_0</var>
:
<var>p_{W-1}</var>
<var>q_0</var>
:
<var>q_{H-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Output an integer representing the minimum total cost.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
3
5
2
7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>29
</pre>
<p>It is enough to pave the following eight roads.</p>
<ul>
<li>Road connecting houses at <var>(0,0)</var> and <var>(0,1)</var></li>
<li>Road connecting houses at <var>(0,1)</var> and <var>(1,1)</var></li>
<li>Road connecting houses at <var>(0,2)</var> and <var>(1,2)</var></li>
<li>Road connecting houses at <var>(1,0)</var> and <var>(1,1)</var></li>
<li>Road connecting houses at <var>(1,0)</var> and <var>(2,0)</var></li>
<li>Road connecting houses at <var>(1,1)</var> and <var>(1,2)</var></li>
<li>Road connecting houses at <var>(1,2)</var> and <var>(2,2)</var></li>
<li>Road connecting houses at <var>(2,0)</var> and <var>(2,1)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
2
4
8
1
2
9
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>60
</pre></section>
</div>
</span> |
p03421 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Determine if there exists a sequence obtained by permuting <var>1,2,...,N</var> that satisfies the following conditions:</p>
<ul>
<li>The length of its longest increasing subsequence is <var>A</var>.</li>
<li>The length of its longest decreasing subsequence is <var>B</var>.</li>
</ul>
<p>If it exists, construct one such sequence.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>A subsequence of a sequence <var>P</var> is a sequence that can be obtained by extracting some of the elements in <var>P</var> without changing the order.</p>
<p>A longest increasing subsequence of a sequence <var>P</var> is a sequence with the maximum length among the subsequences of <var>P</var> that are monotonically increasing.</p>
<p>Similarly, a longest decreasing subsequence of a sequence <var>P</var> is a sequence with the maximum length among the subsequences of <var>P</var> that are monotonically decreasing.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,A,B \leq 3\times 10^5</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</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there are no sequences that satisfy the conditions, print <code>-1</code>.</p>
<p>Otherwise, print <var>N</var> integers. The <var>i</var>-th integer should be the <var>i</var>-th element of the sequence that you constructed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 4 1 5 3
</pre>
<p>One longest increasing subsequence of this sequence is <var>{2,4,5}</var>, and one longest decreasing subsequence of it is <var>{4,3}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 7 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2 3 4 5 6 7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>300000 300000 300000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre></section>
</div>
</span> |
p03071 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are two buttons, one of size <var>A</var> and one of size <var>B</var>.</p>
<p>When you press a button of size <var>X</var>, you get <var>X</var> coins and the size of that button decreases by <var>1</var>.</p>
<p>You will press a button twice. Here, you can press the same button twice, or press both buttons once.</p>
<p>At most how many coins can you get?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>3 \leq A, B \leq 20</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of coins you can get.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>You can get <var>5 + 4 = 9</var> coins by pressing the button of size <var>5</var> twice, and this is the maximum result.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>12
</pre></section>
</div>
</span> |
p03564 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Square1001 has seen an electric bulletin board displaying the integer <var>1</var>.
He can perform the following operations A and B to change this value:</p>
<ul>
<li>Operation A: The displayed value is doubled.</li>
<li>Operation B: The displayed value increases by <var>K</var>.</li>
</ul>
<p>Square1001 needs to perform these operations <var>N</var> times in total.
Find the minimum possible value displayed in the board after <var>N</var> operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N, K \leq 10</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>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum possible value displayed in the board after <var>N</var> operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The value will be minimized when the operations are performed in the following order: A, A, B, B.<br/>
In this case, the value will change as follows: <var>1</var> â <var>2</var> â <var>4</var> â <var>7</var> â <var>10</var>. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>76
</pre>
<p>The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.<br/>
In this case, the value will change as follows: <var>1</var> â <var>2</var> â <var>4</var> â <var>8</var> â <var>16</var> â <var>26</var> â <var>36</var> â <var>46</var> â <var>56</var> â <var>66</var> â <var>76</var>. </p>
<p>By the way, this contest is AtCoder Beginner Contest 076.</p></section>
</div>
</span> |
p01559 |
<h1>MinimumCostPath</h1>
<p>NxNã®æ¹çŒãããã
</p>
<p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_grid" height="140px"><br>
(N=3ã®å Žåã®å³)
</p>
<p>飿¥ãããã¹ç®ã«ç§»åããã«ã¯ã³ã¹ãã1ãããããã ããæãã«ç§»åããããšã¯åºæ¥ãªãã
ãŸãé害ç©ããããã¹ç®ãMåããããã®ãã¹ã«å
¥ãããšã¯èš±ãããªãã
ãã¹(1, 1)ãããã¹(N, N)ã«æå°ã®ã³ã¹ãã§ç§»åããæ¹æ³ã¯äœéããããã
çãã¯å€§ãããªãããšãããããã®ã§ã1000000009(=10<sup>9</sup>+9)ã§MODãåã£ãŠåºåããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã
</p><blockquote>
N M<br>X<sub>1</sub> Y<sub>1</sub><br>X<sub>2</sub> Y<sub>2</sub><br>âŠâŠ<br>X<sub>M</sub> Y<sub>M</sub><br></blockquote>
<p>X<sub>i</sub>, Y<sub>i</sub>ã¯(X<sub>i</sub>, Y<sub>i</sub>)ã«é害ç©ãããããšã衚ã
</p>
<h2>Constraints</h2>
<ul><li><p>2 ≤ N ≤ 10<sup>6</sup>
</p></li><li><p> 0 ≤ M ≤ 50
</p></li><li><p> 1 ≤ X<sub>i</sub> , Y<sub>i</sub> ≤ N
</p></li><li><p> i ≠ jãªãã° (X<sub>i</sub>, Y<sub>i</sub>) ≠ (X<sub>j</sub>, Y<sub>j</sub>)
</p></li><li><p> (X<sub>i</sub>, Y<sub>i</sub>) ≠ (1, 1)
</p></li><li><p> (X<sub>i</sub>, Y<sub>i</sub>) ≠ (N, N)
</p></li></ul>
<h2>Output</h2>
<p>1è¡ã«çµè·¯ã®ç·æ°ãåºåããããã ãããã¹(1, 1)ãããã¹(N, N)ã«ç§»åããçµè·¯ãååšããªãå Žåã¯0ãšåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>3 0
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>6
</pre>
以äžã®å³ã«å¯Ÿå¿ããã<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_1" height="140px">
<h2>Sample Input 2</h2>
<pre>3 1
2 2
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>2
</pre>
以äžã®å³ã«å¯Ÿå¿ããã<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_2" height="140px">
<h2>Sample Input 3</h2>
<pre>5 8
4 3
2 1
4 2
4 4
3 4
2 2
2 4
1 4
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>1
</pre>
以äžã®å³ã«å¯Ÿå¿ããã<br>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_3" height="270px">
<h2>Sample Input 4</h2>
<pre>1000 10
104 87
637 366
393 681
215 604
707 876
943 414
95 327
93 415
663 596
661 842
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>340340391
</pre>
<h2>Sample Input 5</h2>
<pre>2 2
1 2
2 1
</pre>
<h2>Output for the Sample Input 5</h2>
<pre>0
</pre> |
p03134 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> Snukes lining up in a row.
You are given a string <var>S</var> of length <var>N</var>. The <var>i</var>-th Snuke from the front has two red balls if the <var>i</var>-th character in <var>S</var> is <code>0</code>; one red ball and one blue ball if the <var>i</var>-th character in <var>S</var> is <code>1</code>; two blue balls if the <var>i</var>-th character in <var>S</var> is <code>2</code>.</p>
<p>Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure <var>2N</var> times, modulo <var>998244353</var>:</p>
<ul>
<li>Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.</li>
<li>Takahashi receives the ball and put it to the end of his sequence.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 2000</var></li>
<li><var>S</var> consists of <code>0</code>,<code>1</code> and <code>2</code>.</li>
</ul>
<p>Note that the integer <var>N</var> is not directly given in input; it is given indirectly as the length of the string <var>S</var>.</p>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible sequences Takahashi may have after repeating the procedure <var>2N</var> times, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>02
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There are three sequences that Takahashi may have: <code>rrbb</code>, <code>rbrb</code> and <code>rbbr</code>, where <code>r</code> and <code>b</code> stand for red and blue balls, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1210
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>55
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>12001021211100201020
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>543589959
</pre></section>
</div>
</span> |
p01109 | <h3>Income Inequality</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
We often compute the average as the first step
in processing statistical data.
Yes, the average is a good tendency measure of data,
but it is not always the best.
In some cases, the average may hinder the understanding
of the data.
</p>
<p>
For example, consider the national income of a country.
As the term <i>income inequality</i> suggests,
a small number of people earn a good portion of the gross national income
in many countries.
In such cases, the average income computes much higher than the
income of the vast majority.
It is not appropriate to regard the average as the income of typical people.
</p>
<p>
Let us observe the above-mentioned phenomenon in some concrete data.
Incomes of <i>n</i> people, <i>a</i><sub>1</sub>, ... ,
<i>a<sub>n</sub></i>, are given.
You are asked to write a program that reports the number of people
whose incomes are less than or equal to the average
(<i>a</i><sub>1</sub> + ... + <i>a<sub>n</sub></i>) / <i>n</i>.
</p>
<!-- end en only -->
<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>a</i><sub>1</sub> <i>a</i><sub>2</sub> ... <i>a<sub>n</sub></i>
</p>
</blockquote>
<!-- begin en only -->
<p>
A dataset consists of two lines.
In the first line, the number of people <i>n</i> is given.
<i>n</i> is an integer satisfying 2 ≤ <i>n</i> ≤ 10 000.
In the second line, incomes of <i>n</i> people are given.
<i>a<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>) is the income
of the <i>i</i>-th person.
This value is an integer greater than or equal to 1 and
less than or equal to 100 000.
</p>
<p>
The end of the input is indicated by a line containing a zero.
The sum of <i>n</i>'s of all the datasets does not exceed 50 000.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output the number of people whose incomes are
less than or equal to the average.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>7
15 15 15 15 15 15 15
4
10 20 30 60
10
1 1 1 1 1 1 1 1 1 100
7
90 90 90 90 90 90 10
7
2 7 1 8 2 8 4
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>7
3
9
1
4
</pre>
|
p00348 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>ãœãŒã</H1>
<p>
髿 ¡å
¥åŠåŸãããã°ã©ãã³ã°éšã«å
¥éšããã¿ã±åããã¯ã次第ã«ã¢ã«ãŽãªãºã ã®é¢çœãã«ã®ããããã§ãããŸãããããŸã§ã¯ãïŒå¹Žçã«ãªã£ããããã°ã©ãã³ã°ç²ååã«åºå ŽããŠã¿ãããšèããŠããŸãã
</p>
<p>
ãããšãããœãŒãã»ã¢ã«ãŽãªãºã ã«ã€ããŠåŠãã ã¿ã±åããã¯ããœãŒãã»ã¢ã«ãŽãªãºã ãèªåã§èšèšããŠã¿ãŸãããã¿ã±åãããäœã£ããœãŒãã»ã¢ã«ãŽãªãºã ã§ã¯ãå
¥åãšããŠèŠçŽ ã®éã«éè€ã®ãªããïŒå以äžã®èªç¶æ°ãããªãåãäžãããããšãã以äžã®åŠçãå®è¡ããŸãã
</p>
<ol>
<li> ã¯ããã«ãåã®å
é ã®èŠçŽ ãéžã¶ã</li>
<li> éžãã èŠçŽ ã®çŽåã«èŠçŽ ããããšããéžãã èŠçŽ ãšãã®çŽåã®èŠçŽ ãæ¯ã¹ããçŽåã®èŠçŽ ã®ã»ãã倧ãããªãããããåã®æ«å°Ÿã®çŽåŸã«ç§»åããã(å³ïŒããã®æäœããéžãã èŠçŽ ãåã®å
é ã«ãªãããéžãã èŠçŽ ãããã®çŽåã®èŠçŽ ã®æ¹ãå°ãããªããŸã§ç¶ããã</li>
<li> éžãã èŠçŽ ãåã®æ«å°Ÿãªãçµäºãããã§ãªããã°ãéžãã èŠçŽ ã®çŽåŸã®èŠçŽ ãæ°ãã«éžã³ã2 ãžæ»ãã</li>
</ol>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sort" width="360"><br/>
</center>
<br/>
<p>
ã¿ã±åããã¯ãã®ã¢ã«ãŽãªãºã ãã©ã®ãããã®èšç®æéãå¿
èŠãšãããèŠç©ããããã«ãèŠçŽ ãåã®æ«å°Ÿã®çŽåŸã«ç§»åãããæäœã®åæ°ãæ°ããããšã«ããŸããã
</p>
<br/>
<p>
åã®æ
å ±ãå
¥åãšããèŠçŽ ãåã®æ«å°Ÿã®çŽåŸã«ç§»åãããæäœã®åæ°ãå ±åããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«åã«å«ãŸããèŠçŽ ã®åæ° <var>N</var> (1 ≤ <var>N</var> ≤ 200000) ãäžãããããïŒè¡ç®ã«åã®èŠçŽ <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 10<sup>9</sup>) ãå
é ããé çªã«äžãããããèŠçŽ <var>a<sub>i</sub></var> ã«éè€ã¯ãªãã
</p>
<h2>Output</h2>
<p>
èŠçŽ ãåã®æ«å°Ÿã®çŽåŸã«ç§»åãããæäœã®åæ°ãïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
6
1 3 6 5 8 2
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<p>
å
¥åäŸïŒã§ã¯ãèŠçŽ ã®ç§»åãè¡ããããã³ã«ã以äžã®ããã«åãå€åããŠããã
</p>
<pre>
0åç®ïŒ 1 3 6 5 8 2
1åç®ïŒ 1 3 5 8 2 6
2åç®ïŒ 1 3 5 2 6 8
3åç®ïŒ 1 3 2 6 8 5
4åç®ïŒ 1 2 6 8 5 3
5åç®ïŒ 1 2 6 5 3 8
6åç®ïŒ 1 2 5 3 8 6
7åç®ïŒ 1 2 3 8 6 5
8åç®ïŒ 1 2 3 6 5 8
9åç®ïŒ 1 2 3 5 8 6
10åç®ïŒ 1 2 3 5 6 8
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
4
4 3 2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
6
</pre> |
p02375 | <H1>Range Query on a Tree II</H1>
<p>
Write a program which manipulates a weighted rooted tree $T$ with the following operations:
</p>
<ul>
<li>$add(v,w)$: add $w$ to all edges from the root to node $u$<br>
<li>$getSum(u)$: report the sum of weights of all edges from the root to node $u$<br>
</ul>
<p>
The given tree $T$ consists of $n$ nodes and every node has a unique ID from $0$ to $n-1$ respectively where ID of the root is $0$.
Note that all weights are initialized to zero.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<p>
$n$<br>
$node_0$<br>
$node_1$<br>
$node_2$<br>
$:$<br>
$node_{n-1}$<br>
$q$<br>
$query_1$<br>
$query_2$<br>
$:$<br>
$query_{q}$<br>
</p>
<p>
The first line of the input includes an integer $n$, the number of nodes in the tree.
</p>
<p>
In the next $n$ lines,the information of node $i$ is given in the following format:
</p>
<pre>
<var>k<sub>i</sub></var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>k</sub></var>
</pre>
<p>
$k_i$ is the number of children of node $i$, and $c_1$ $c_2$ ... $c_{k_i}$ are node IDs of 1st, ... $k$th child of node $i$.
</p>
<p>
In the next line, the number of queries $q$ is given. In the next $q$ lines, $i$th query is given in the following format:
</p>
<pre>
0 <var>v</var> <var>w</var>
</pre>
<p>
or
</p>
<pre>
1 <var>u</var>
</pre>
<p>
The first integer represents the type of queries.'0' denotes $add(v, w)$ and '1' denotes $getSum(u)$.
</p>
<h2>Constraints</h2>
<ul>
<li>All the inputs are given in integers</li>
<li>$ 2 \leq n \leq 100000 $</li>
<li>$ c_j < c_{j+1} $ $( 1 \leq j \leq k-1 )$</li>
<li>$ 2 \leq q \leq 200000 $</li>
<li>$ 1 \leq u,v \leq n-1 $</li>
<li>$ 1 \leq w \leq 10000 $</li>
</ul>
<h2>Output</h2>
<p>
For each $getSum$ query, print the sum in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
6
2 1 2
2 3 5
0
0
0
1 4
7
1 1
0 3 10
1 2
0 4 20
1 3
0 5 40
1 4
</pre>
<h2>Sample Output 1</h2>
<pre>
0
0
40
150
</pre>
<h2>Sample Input 2</h2>
<pre>
4
1 1
1 2
1 3
0
6
0 3 1000
0 2 1000
0 1 1000
1 1
1 2
1 3
</pre>
<h2>Sample Output 2</h2>
<pre>
3000
5000
6000
</pre>
|
p00718 |
<h1><font color="#000">Problem C:</font> Numeral System</h1>
<p>
Prof. Hachioji has devised a new numeral system of
integral numbers with four lowercase letters "m", "c", "x", "i"
and with eight digits "2", "3", "4", "5", "6", "7", "8", "9".
He doesn't use digit "0" nor digit "1" in this system.
</p>
<p>
The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1,
respectively,
and the digits "2", ...,"9" correspond to 2, ..., 9, respectively.
This system has nothing to do with the Roman numeral system.
</p>
<p>
For example,
character strings
</p>
<blockquote>
"5m2c3x4i", "m2c4i" and "5m2c3x"
</blockquote>
<p>
correspond to the integral numbers
5234 (=5*1000+2*100+3*10+4*1),
1204 (=1000+2*100+4*1),
and 5230 (=5*1000+2*100+3*10),
respectively.
The parts of strings in the above example, "5m", "2c", "3x" and "4i"
represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1),
respectively.
</p>
<p>
Each of the letters "m", "c", "x" and "i" may
be prefixed by one of the digits
"2", "3", ..., "9".
In that case, the prefix digit and the letter are regarded
as a pair.
A pair that consists of a prefix digit and a letter
corresponds to an integer that is equal to
the original value of the letter multiplied by
the value of the prefix digit.
</p>
<p>
For each letter "m", "c", "x" and "i",
the number of its occurrence in a string is at most one.
When it has a prefix digit, it should appear together with the prefix digit.
The letters "m", "c", "x" and "i" must appear in this order, from left to right.
Moreover, when a digit exists in a string,
it should appear as the prefix digit of the following letter.
Each letter may be omitted in a string, but
the whole string must not be empty.
A string made in this manner is called an <I>MCXI-string</I>.
</p>
<p>
An MCXI-string corresponds to a positive integer
that is the sum of the values of the letters
and those of the pairs contained in it as mentioned above.
The positive integer corresponding to an MCXI-string is called its
MCXI-value.
Moreover, given an integer from 1 to 9999,
there is a unique MCXI-string whose MCXI-value is equal
to the given integer.
For example,
the MCXI-value of an MCXI-string "m2c4i" is
1204 that is equal to <tt>1000 + 2*100 + 4*1</tt>.
There are no MCXI-strings but "m2c4i" that correspond to 1204.
Note
that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are
not valid MCXI-strings.
The reasons are use of "1",
multiple occurrences of "c", use of "0", and the wrong order of "c" and "m",
respectively.
</p>
<p>
Your job is to write a program for Prof. Hachioji
that reads two MCXI-strings,
computes the sum of their MCXI-values, and
prints the MCXI-string corresponding to the result.
</p>
<h2>Input</h2>
<p>
The input is as follows.
The first line contains a positive integer <I>n</I> (<= 500) that
indicates the number of the following lines.
The <I>k</I>+1 th line is the specification of
the <I>k</I> th computation (<I>k</I>=1, ..., <I>n</I>).
</p>
<blockquote>
<I>n</I> <br>
<I>specification</I><sub>1</sub> <br>
<I>specification</I><sub>2</sub> <br>
...<br>
<I>specification</I><sub><I>n</I></sub> <br>
</blockquote>
<p>
Each specification is described in a line:
<blockquote>
<I>MCXI-string</I><sub>1</sub> <I>MCXI-string</I><sub>2</sub>
</blockquote>
<p>
The two MCXI-strings are separated by a space.
</p>
<p>
You may assume that the sum of the two MCXI-values
of the two MCXI-strings in each specification
is less than or equal to 9999.
</p>
<h2>Output</h2>
<p>
For each specification,
your program should print an MCXI-string in a line.
Its MCXI-value should be the sum of the two MCXI-values
of the MCXI-strings in the specification.
No other characters should appear in the output.
</p>
<h2>Sample Input</h2>
<pre>
10
xi x9i
i 9i
c2x2i 4c8x8i
m2ci 4m7c9x8i
9c9x9i i
i 9m9c9x8i
m i
i m
m9i i
9m8c7xi c2x8i
</pre>
<h2>Output for the Sample Input</h2>
<pre>
3x
x
6cx
5m9c9x9i
m
9m9c9x9i
mi
mi
mx
9m9c9x9i
</pre>
|
p02725 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a circular pond with a perimeter of <var>K</var> meters, and <var>N</var> houses around them.</p>
<p>The <var>i</var>-th house is built at a distance of <var>A_i</var> meters from the northmost point of the pond, measured clockwise around the pond.</p>
<p>When traveling between these houses, you can only go around the pond.</p>
<p>Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the <var>N</var> houses.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq K \leq 10^6</var></li>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>0 \leq A_1 < ... < A_N < K</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>K</var> <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 distance that needs to be traveled when you start at one of the houses and visit all the <var>N</var> houses.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>20 3
5 10 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>If you start at the <var>1</var>-st house and go to the <var>2</var>-nd and <var>3</var>-rd houses in this order, the total distance traveled will be <var>10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20 3
0 5 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
<p>If you start at the <var>2</var>-nd house and go to the <var>1</var>-st and <var>3</var>-rd houses in this order, the total distance traveled will be <var>10</var>.</p></section>
</div>
</span> |
p03837 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected connected weighted graph with <var>N</var> vertices and <var>M</var> edges that contains neither self-loops nor double edges.<br/>
The <var>i</var>-th <var>(1â€iâ€M)</var> edge connects vertex <var>a_i</var> and vertex <var>b_i</var> with a distance of <var>c_i</var>.<br/>
Here, a <em>self-loop</em> is an edge where <var>a_i = b_i (1â€iâ€M)</var>, and <em>double edges</em> are two edges where <var>(a_i,b_i)=(a_j,b_j)</var> or <var>(a_i,b_i)=(b_j,a_j) (1â€i<jâ€M)</var>.<br/>
A <em>connected graph</em> is a graph where there is a path between every pair of different vertices.<br/>
Find the number of the edges that are not contained in any shortest path between any pair of different vertices. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2â€Nâ€100</var> </li>
<li><var>N-1â€Mâ€min(N(N-1)/2,1000)</var> </li>
<li><var>1â€a_i,b_iâ€N</var> </li>
<li><var>1â€c_iâ€1000</var></li>
<li><var>c_i</var> is an integer.</li>
<li>The given graph contains neither self-loops nor double edges.</li>
<li>The given graph is connected.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var> <var>c_1</var>
<var>a_2</var> <var>b_2</var> <var>c_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var> <var>c_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3
1 2 1
1 3 1
2 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>In the given graph, the shortest paths between all pairs of different vertices are as follows:</p>
<ul>
<li>The shortest path from vertex <var>1</var> to vertex <var>2</var> is: vertex <var>1</var> â vertex <var>2</var>, with the length of <var>1</var>.</li>
<li>The shortest path from vertex <var>1</var> to vertex <var>3</var> is: vertex <var>1</var> â vertex <var>3</var>, with the length of <var>1</var>.</li>
<li>The shortest path from vertex <var>2</var> to vertex <var>1</var> is: vertex <var>2</var> â vertex <var>1</var>, with the length of <var>1</var>.</li>
<li>The shortest path from vertex <var>2</var> to vertex <var>3</var> is: vertex <var>2</var> â vertex <var>1</var> â vertex <var>3</var>, with the length of <var>2</var>.</li>
<li>The shortest path from vertex <var>3</var> to vertex <var>1</var> is: vertex <var>3</var> â vertex <var>1</var>, with the length of <var>1</var>.</li>
<li>The shortest path from vertex <var>3</var> to vertex <var>2</var> is: vertex <var>3</var> â vertex <var>1</var> â vertex <var>2</var>, with the length of <var>2</var>.</li>
</ul>
<p>Thus, the only edge that is not contained in any shortest path, is the edge of length <var>3</var> connecting vertex <var>2</var> and vertex <var>3</var>, hence the output should be <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 2
1 2 1
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Every edge is contained in some shortest path between some pair of different vertices.</p></section>
</div>
</span> |
p01220 |
<H1><font color="#000">Problem E:</font> Triangles</H1>
<p>
There is a group that paints an emblem on the ground to invite aliens every year. You are a member of
this group and you have to paint the emblem this year.
</p>
<p>
The shape of the emblem is described as follows. It is made of <i>n</i> regular triangles whose sides are
equally one unit length long. These triangles are placed so that their centroids coincide, and each of them
is rotated counterclockwise by 360/<i>n</i> degrees with respect to the one over it around its centroid. The
direction of the top triangle is not taken into account.
</p>
<p>
It is believed that emblems have more impact as their <i>n</i> are taken larger. So you want to paint the emblem
of <i>n</i> as large as possible, but you donât have so much chemicals to paint. Your task is to write a program
which outputs the area of the emblem for given <i>n</i> so that you can estimate the amount of the needed
chemicals.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_triangles">
<p>Figure 1: The Emblem for <i>n</i> = 2</p>
</center>
<H2>Input</H2>
<p>
The input data is made of a number of data sets. Each data set is made of one line which contains an
integer <i>n</i> between 1 and 1000 inclusive.
</p>
<p>
The input is terminated by a line with <i>n</i> = 0. This line should not be processed.
</p>
<H2>Output</H2>
<p>
For each data set, output the area of the emblem on one line. Your program may output an arbitrary
number of digits after the decimal point. However, the error should be 10<sup>-6</sup> ( = 0.000001) or less.
</p>
<H2>Sample Input</H2>
<pre>
1
2
3
4
5
6
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.433013
0.577350
0.433013
0.732051
0.776798
0.577350
</pre>
|
p04022 | <span class="lang-en">
<p>Score : <var>1100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke got positive integers <var>s_1,...,s_N</var> from his mother, as a birthday present. There may be duplicate elements.</p>
<p>He will circle some of these <var>N</var> integers. Since he dislikes cubic numbers, he wants to ensure that if both <var>s_i</var> and <var>s_j (i â j)</var> are circled, the product <var>s_is_j</var> is <em>not</em> cubic. For example, when <var>s_1=1,s_2=1,s_3=2,s_4=4</var>, it is not possible to circle both <var>s_1</var> and <var>s_2</var> at the same time. It is not possible to circle both <var>s_3</var> and <var>s_4</var> at the same time, either.</p>
<p>Find the maximum number of integers that Snuke can circle.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 ⊠N ⊠10^5</var></li>
<li><var>1 ⊠s_i ⊠10^{10}</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s_1</var>
:
<var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of integers that Snuke can circle.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8
1
2
3
4
5
6
7
8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>Snuke can circle <var>1,2,3,5,6,7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
2
4
8
16
32
64
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
1
10
100
1000000007
10000000000
1000000009
999999999
999
999
999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
</pre></section>
</div>
</span> |
p00962 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>Problem F
Pizza Delivery
</h2>
<p>
Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street sections. Reversals will be on one single street section between two adjacent intersections for each day; the directions of all the other sections will not change, and the reversal will be canceled on the next day.
</p>
<p>
Alyssa orders a piece of pizza everyday from the same pizzeria. The pizza is delivered along the shortest route from the intersection with the pizzeria to the intersection with Alyssa's house.
</p>
<p>
Altering the traffic regulation may change the shortest route. Please tell Alyssa how the social experiment will affect the pizza delivery route.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case in the following format.
</p>
<pre>
$n$ $m$
$a_1$ $b_1$ $c_1$
...
$a_m$ $b_m$ $c_m$
</pre>
<p>
The first line contains two integers, $n$, the number of intersections, and $m$, the number of street sections in New Tsukuba City ($2 \leq n \leq 100 000, 1 \leq m \leq 100 000$). The intersections are numbered $1$ through $n$ and the street sections are numbered $1$ through $m$.
</p>
<p>
The following $m$ lines contain the information about the street sections, each with three integers $a_i$, $b_i$, and $c_i$ ($1 \leq a_i n, 1 \leq b_i \leq n, a_i \ne b_i, 1 \leq c_i \leq 100 000$). They mean that the street section numbered $i$ connects two intersections with the one-way direction from $a_i$ to $b_i$, which will be reversed on the $i$-th day. The street section has the length of $c_i$. Note that there may be more than one street section connecting the same pair of intersections.
</p>
<p>
The pizzeria is on the intersection 1 and Alyssa's house is on the intersection 2. It is guaranteed that at least one route exists from the pizzeria to Alyssa's before the social experiment starts.
</p>
<h3>Output</h3>
<p>
The output should contain $m$ lines. The $i$-th line should be
</p>
<ul>
<li> <span>HAPPY</span> if the shortest route on the $i$-th day will become shorter,</li>
<li> <span>SOSO</span> if the length of the shortest route on the $i$-th day will not change, and</li>
<li> <span>SAD</span> if the shortest route on the $i$-th day will be longer or if there will be no route from the pizzeria to Alyssa's house.</li>
</ul>
<p>
Alyssa doesn't mind whether the delivery bike can go back to the pizzeria or not.
</p>
<h3>Sample Input 1</h3>
<pre>
4 5
1 3 5
3 4 6
4 2 7
2 1 18
2 3 12
</pre>
<h3>Sample Output 1</h3>
<pre>
SAD
SAD
SAD
SOSO
HAPPY
</pre>
<h3>Sample Input 2</h3>
<pre>
7 5
1 3 2
1 6 3
4 2 4
6 2 5
7 5 6
</pre>
<h3>Sample Output 2</h3>
<pre>
SOSO
SAD
SOSO
SAD
SOSO
</pre>
<h3>Sample Input 3</h3>
<pre>
10 14
1 7 9
1 8 3
2 8 4
2 6 11
3 7 8
3 4 4
3 2 1
3 2 7
4 8 4
5 6 11
5 8 12
6 10 6
7 10 8
8 3 6
</pre>
<h3>Sample Output 3</h3>
<pre>
SOSO
SAD
HAPPY
SOSO
SOSO
SOSO
SAD
SOSO
SOSO
SOSO
SOSO
SOSO
SOSO
SAD
</pre> |
p01670 |
<h2>D - Medical Inspection</h2>
<h3>Problem Statement</h3>
<p>
The government has declared a state of emergency due to the MOFU syndrome epidemic in your country. Persons in the country suffer from MOFU syndrome and cannot get out of bed in the morning. You are a programmer working for the Department of Health. You have to take prompt measures.
</p>
<p>
The country consists of <var>n</var> islands numbered from 1 to <var>n</var> and there are ocean liners between some pair of islands.
The Department of Health decided to establish the quarantine stations in some islands and restrict an infected person's moves to prevent the expansion of the epidemic.
To carry out this plan, there must not be any liner such that there is no quarantine station in both the source and the destination of the liner.
The problem is the department can build at most <var>K</var> quarantine stations due to the lack of budget.
</p>
<p>
Your task is to calculate whether this objective is possible or not.
And if it is possible, you must calculate the minimum required number of quarantine stations.
</p>
<h3>Input</h3>
<p>
The test case starts with a line containing three integers <var>N (2 \leq N \leq 3{,}000)</var>, <var>M (1 \leq M \leq 30{,}000)</var> and <var>K (1 \leq K \leq 32)</var>.
Each line in the next <var>M</var> lines contains two integers <var>a_i (1 \leq a_i \leq N)</var> and <var>b_i (1 \leq b_i \leq N)</var>. This represents <var>i</var>-th ocean liner connects island <var>a_i</var> and <var>b_i</var>.
You may assume <var>a_i \neq b_i</var> for all <var>i</var>, and there are at most one ocean liner between all the pairs of islands.
</p>
<h3>Output</h3>
<p>
If there is no way to build quarantine stations that satisfies the objective, print "Impossible" (without quotes). Otherwise, print the minimum required number of quarantine stations.
</p>
<h3>Sample Input 1</h3>
<pre>
3 3 2
1 2
2 3
3 1
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>
2
</pre>
<h3>Sample Input 2</h3>
<pre>
3 3 1
1 2
2 3
3 1
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>
Impossible
</pre>
<h3>Sample Input 3</h3>
<pre>
7 6 5
1 3
2 4
3 5
4 6
5 7
6 2
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>
4
</pre>
<h3>Sample Input 4</h3>
<pre>
10 10 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>
4
</pre>
|
p00431 |
<H1></H1>
<p>
䞡端ã«ãªã³ã°ã®ã€ããçŽãèãã.ãªã³ã°ã¯æ£æŽæ°ãä»ããŠããŠ,çŽãåºå¥ãã.çŽã®äž¡ç«¯ã®ãªã³ã°ã«ã¯ç°ãªãæ° <i>a</i>, <i>b</i> ãä»ãããã.ããã,[<i>a</i>, <i>b</i>] ãšèšè¿°ãã.è€æ°ã®çŽããã,äžæ¹ã®çŽãšä»æ¹ã®çŽã®ãªã³ã°ã«ä»ããŠããæ°ãåãå Žå,ãã®ãªã³ã°ã®ãšããã§,ãããã®çŽãã€ãªããããšãã§ããŠ,ã€ãªããŠã§ãããã®ãéãšåŒã¶ããšã«ãã.äŸãã°,[1, 3] ãš [3, 4] ãšããçŽãã㯠[1, 3, 4] ãšããéãã§ãã.çŽãšéãéåå¿ãåãæŽæ°ãä»ããŠãããªã³ã°ã®ãšããã§ã€ãªããããšãã§ãããã®ãšãã.
</p>
<p>
äŸãã°,é [1, 3, 4] ãšçŽ [5, 1] ãã㯠[5, 1, 3, 4] ãã§ã,é [1, 3, 4] ãšé [2, 3, 5] ããã¯, äžå€®ã§ã¯ãã¹ãããããªåœ¢ã«ãªã.é [1, 3, 4] ãšé [4, 6, 1] ããã¯, 茪ã®åœ¢ãã§ãã.
</p>
<p>
ãã®ããã«æ§ã
ãªåœ¢ãã§ããã, ãã®ãã¡ã®äžéšã§,åãæ°ã®ä»ãããªã³ã°ã¯äžåºŠã ããã©ãã€ãªãã£ãè€æ°ã®çŽãéãšåŒã¶ããšã«ãã.äŸãã°,é [1, 3, 4] ãšé[2, 3, 5] ããã§ãã,äžå€®ã§ã¯ãã¹ãããããªåœ¢ã«ã¯, [1, 3, 5],[2, 3, 4] ãšããéãå«ãŸã,é [1, 3, 4] ãšé [4, 6, 1] ããã§ãã茪ã«ã¯, [1, 3, 4, 6],[3, 4, 6, 1],[4, 6, 1, 3]ãªã©ã®éãå«ãŸãã.
</p>
<p>
ãããã®éã«å¯ŸããŠ,å«ãŸããæ°ã®åæ°ãé·ããšå®çŸ©ãã. äžããããè€æ°ã®çŽã«å¯ŸããŠ,ã€ãªãããããã®ã¯ãã¹ãŠã€ãªãããš1ã€ä»¥äžã®
éãå«ã圢ãã§ãã.ãã®ãã¡ã®æå€§ã®éã®é·ããæ±ããããã°ã©ã ãäœæãã.
</p>
<!--
<p>
å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠âinput.txtâ ã§ãã.âinput.txtâ ã®æåã®è¡ã«ã¯çŽã®åæ°ã§ããæ£æŽæ° 1 ≤ <i>n</i> ≤ 100 ãæžããŠãã,ã€ã¥ã <i>n</i> è¡ã®ããããã«ã¯, 空çœã§åºåããã 2 ã€ã®æŽæ° <i>a</i>, <i>b</i> ãæžããŠãã 1 ≤ <i>a</i> < <i>b</i> ≤ 100 ãšãªã£ãŠãã.åè¡ã® 2 ã€ã®æŽæ°ã¯ 1 ã€ã®çŽã®äž¡ç«¯ã®æŽæ°ã衚ãã.
</p>
<p>
åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠âoutput.txtâ ã§ãã.âoutput.txtâ ã«ãããŠã¯,åºå(æå€§ã®éã®é·ã)ã®åŸã«æ¹è¡ãå
¥ããããš.
</p>
-->
<p>
å
¥åããŒã¿ ã®æåã®è¡ã«ã¯çŽã®åæ°ã§ããæ£æŽæ° 1 ≤ <i>n</i> ≤ 100 ãæžããŠãã,ã€ã¥ã <i>n</i> è¡ã®ããããã«ã¯, 空çœã§åºåããã 2 ã€ã®æŽæ° <i>a</i>, <i>b</i> ãæžããŠãã 1 ≤ <i>a</i> < <i>b</i> ≤ 100 ãšãªã£ãŠãã.åè¡ã® 2 ã€ã®æŽæ°ã¯ 1 ã€ã®çŽã®äž¡ç«¯ã®æŽæ°ã衚ãã.
</p>
<table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;">
<tr>
<th width="150" align="left">å
¥åäŸïŒ</th>
<th width="150" align="left">å
¥åäŸïŒ</th>
<th width="150" align="left">å
¥åäŸïŒ</th>
</tr>
<tr><td></td><td></td></tr>
<tr><td>7 </td><td>6 </td><td>7 </td></tr>
<tr><td>1 3 </td><td>1 2 </td><td>1 3 </td></tr>
<tr><td>3 4 </td><td>2 3 </td><td>2 4 </td></tr>
<tr><td>1 4 </td><td>3 4 </td><td>3 5 </td></tr>
<tr><td>2 7 </td><td>4 5 </td><td>4 6 </td></tr>
<tr><td>5 7 </td><td>1 5 </td><td>6 7 </td></tr>
<tr><td>6 7 </td><td>2 6 </td><td>2 6 </td></tr>
<tr><td>1 7 </td><td> </td><td>4 7 </td></tr>
<tr>
<td>ã</td>
</tr>
<tr>
<th width="150" align="left">åºåäŸïŒ</th>
<th width="150" align="left">åºåäŸïŒ</th>
<th width="150" align="left">åºåäŸïŒ</th>
</tr>
<tr><td>5</td><td>6</td><td>4</td></tr>
</table>
<h3>å
¥å</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒn ã 0 ã®ãšãå
¥åãçµäºããïŒããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ
</p>
<h3>åºå</h3>
<p>
ããŒã¿ã»ããããšã«ãæå€§ã®éã®é·ããïŒè¡ã«åºåããïŒ
</p>
<H2>å
¥åäŸ</H2>
<pre>
7
1 3
3 4
1 4
2 7
5 7
6 7
1 7
6
1 2
2 3
3 4
4 5
1 5
2 6
7
1 3
2 4
3 5
4 6
6 7
2 6
4 7
0
</pre>
<H2>åºåäŸ</H2>
<pre>
5
6
4
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00061 |
<H1>Rank Checker</H1>
<!--
<p>
æã¯2020 幎ãããœã³ã³ç²åå 2020 ã®äºéžçµæãä¿åããããŒã¿ããããŸãããã®ããŒã¿ã«ã¯ãåããŒã ã«æ¯ãããæŽççªå·ãšæ£è§£æ°ãä¿åãããŠããŸããåå è
ããŒã æ°ã¯äžæã§ãããããªãå€ãæš¡æ§ã§ãïŒäž»å¬è
ã®ãããããªèŠæã§ããããŸãïŒãæ£è§£æ°ã®å€ãã»ãããé ã« 1 äœã2 äœ ... ãšé äœãã€ããŠããããšãšããŸãã
</p>
-->
<p>
æã¯2020 幎ãããœã³ã³ç²åå 2020 ã®äºéžçµæãä¿åããããŒã¿ããããŸãããã®ããŒã¿ã«ã¯ãåããŒã ã«æ¯ãããæŽççªå·ãšæ£è§£æ°ãä¿åãããŠããŸããããã§ã¯ãæ£è§£æ°ã§é äœã決å®ãããã®ãšããæ£è§£æ°ã®å€ãã»ãããé ã« 1 äœã2 äœ ... ãšé äœãã€ããŠããããšãšããŸãã
</p>
<p>
äºéžçµæã®ããŒã¿ãšæŽççªå·ãããŒããŒãããå
¥åããŠããã®çªå·ã®ããŒã ã®é äœãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
å
¥åããŒã¿ã¯ïŒã€ã®éšåãããªããŸããååã®éšåã¯ãäºéžçµæã®ããŒã¿ãåŸåã®éšåã¯é äœãç¥ãããããŒã çªå·ã®åãåããã§ããäºéžçµæã®ããŒã¿ã®åœ¢åŒã¯ä»¥äžã®éãã§ãã
</p>
<pre>
<var>p<sub>1</sub></var>,<var>s<sub>1</sub></var>
<var>p<sub>2</sub></var>,<var>s<sub>2</sub></var>
...
...
<var>0</var>,<var>0</var>
</pre>
<p>
<var>p<sub>i</sub></var> (1 ≤ <var>p<sub>i</sub></var> ≤ 100 )ã <var>s<sub>i</sub></var> (0 ≤ <var>s<sub>i</sub></var> ≤ 30) ã¯ãããã <var>i</var> ããŒã ç®ã®æŽççªå·ãšæ£è§£æ°ãè¡šãæŽæ°ã§ããæŽççªå·ãšæ£è§£æ°ããšãã« 0 ã®ãšããã®ããŒã¿ã®å
¥åãçµãããã®ãšããŸãã
</p>
<p>
ç¶ããŠåŸåã®åãåãããè€æ°äžããããŸããåãåããã®åœ¢åŒã¯ä»¥äžã®éãã§ãã
</p>
<pre>
<var>q<sub>1</sub></var>
<var>q<sub>2</sub></var>
:
</pre>
<p>
ååãåããã¯ïŒè¡ã«æŽççªå· <var>q<sub>i</sub></var> (1 ≤ <var>q<sub>i</sub></var> ≤ 30) ãäžããããŸãããããå
¥åã®æåŸãŸã§åŠçããŠäžãããåãåããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ååãåããã«ã€ããŠãããŒã ã®é äœãïŒè¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
1,20
2,20
3,30
4,10
5,10
6,20
0,0
1
2
4
5
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
2
3
3
</pre>
<H2>Note</H2>
<p>
å
¥åäŸã®ããŒã¿ã«ãããŠãããŒã ãæ£è§£æ°é ã«æŽåãããšïŒ
</p>
<pre>
3,30
1,20
2,20
6,20
4,10
5,10
</pre>
<p>
ãšãªããŸããããã§ã¯ãæ£è§£æ°ãåºã«é äœã決å®ããããã30åæ£è§£ããŒã ã1äœã20åæ£è§£ããŒã ã2äœã10åæ£è§£ããŒã ã3äœãšããŸãïŒäžäœã®ããŒã æ°ãèæ
®ãã10åæ£è§£ããŒã ã5äœãšããéåžžã®é äœä»ããšã¯ç°ãªãããšã«æ³šæããŠäžããïŒã
</p> |
p02549 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> cells arranged in a row, numbered <var>1, 2, \ldots, N</var> from left to right.</p>
<p>Tak lives in these cells and is currently on Cell <var>1</var>. He is trying to reach Cell <var>N</var> by using the procedure described below.</p>
<p>You are given an integer <var>K</var> that is less than or equal to <var>10</var>, and <var>K</var> non-intersecting segments <var>[L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]</var>.
Let <var>S</var> be the union of these <var>K</var> segments.
Here, the segment <var>[l, r]</var> denotes the set consisting of all integers <var>i</var> that satisfy <var>l \leq i \leq r</var>.</p>
<ul>
<li>When you are on Cell <var>i</var>, pick an integer <var>d</var> from <var>S</var> and move to Cell <var>i + d</var>. You cannot move out of the cells.</li>
</ul>
<p>To help Tak, find the number of ways to go to Cell <var>N</var>, modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>1Â \leq K \leq \min(N, 10)</var></li>
<li><var>1 \leq L_i \leq R_i \leq N</var></li>
<li><var>[L_i, R_i]</var> and <var>[L_j, R_j]</var> do not intersect (<var>i \neq j</var>) </li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>L_1</var> <var>R_1</var>
<var>L_2</var> <var>R_2</var>
<var>:</var>
<var>L_K</var> <var>R_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways for Tak to go from Cell <var>1</var> to Cell <var>N</var>, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
1 1
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The set <var>S</var> is the union of the segment <var>[1, 1]</var> and the segment <var>[3, 4]</var>, therefore <var>S = \{ 1, 3, 4 \}</var> holds.</p>
<p>There are <var>4</var> possible ways to get to Cell <var>5</var>:</p>
<ul>
<li><var>1 \to 2 \to 3 \to 4 \to 5</var>,</li>
<li><var>1 \to 2 \to 5</var>,</li>
<li><var>1 \to 4 \to 5</var> and</li>
<li><var>1 \to 5</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 2
3 3
5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>Because <var>S = \{ 3, 5 \}</var> holds, you cannot reach to Cell <var>5</var>.
Print <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 1
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>60 3
5 8
1 3
10 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>221823067
</pre>
<p>Note that you have to print the answer modulo <var>998244353</var>.</p></section>
</div>
</span> |
p00574 | <h1>æ¯èã®è±èµ°(Snake Escaping)</h1>
<p>
JOI ç ç©¶æã§ã¯<var>2^L</var> å¹ã®æ¯èã飌ã£ãŠããïŒãããã<var>0, 1, ..., 2^L - 1</var> ã®çªå·ãä»ããããŠããïŒãã¹ãŠã®æ¯èã¯é ããé ã«<var>L</var> åã®éšåã«åãããŠããïŒããããã®éšåã¯éãŸãã¯èµ€ã§ããïŒæ¯è<var>i</var> ã«å¯ŸãïŒ<var>i</var> ã2é²è¡šèšããŠ<var>i =</var> $\sum_{k=1}^{L}$<var> c_k2^{L-k} (0 \leq c_k \leq 1)</var> ãšããããšãïŒ
</p>
<ul>
<li> <var>c_k = 0</var> ã§ããã°ïŒæ¯è<var>i</var> ã®é ããæ°ããŠ<var>k</var> çªç®ã®éšåã¯éã§ããïŒ</li>
<li> <var>c_k = 1</var> ã§ããã°ïŒæ¯è<var>i</var> ã®é ããæ°ããŠ<var>k</var> çªç®ã®éšåã¯èµ€ã§ããïŒ</li>
</ul>
<p>
忝èã«ã¯æ¯æ§ãšåŒã°ãã0 以äž9 以äžã®æŽæ°å€ãå®ãŸã£ãŠããïŒ<span>0</span>, <span>1</span>, <span>2</span>, <span>3</span>, <span>4</span>, <span>5</span>, <span>6</span>, <span>7</span>, <span>8</span>, <span>9</span> ãããªãé·ã<var>2^L</var> ã®æåå<var>S</var> ãäžãããïŒãã®<var>i</var> æåç®(<var>1 \leq i \leq 2^L</var>) ã¯æ¯è<var>i - 1</var> ã®æ¯æ§ã衚ãïŒ
</p>
<p>
æ¯èãã¡ã®åãã¯çŽ æ©ãã®ã§ïŒJOI ç ç©¶æããã¯ïŒããæ¯èãã¡ãè±èµ°ããŠããŸãïŒJOI ç ç©¶æã«ã¯è±èµ°ããæ¯èãç®æããåšèŸºäœæ°ããèŠæ
ãå¯ããããïŒ
</p>
<p>
ããªãã«ã¯ïŒ<var>Q</var> æ¥éã«ãããèŠæ
ã®æ
å ±ãäžããããïŒ<var>d</var> æ¥ç®(<var>1 \leq d \leq Q</var>) ã«å¯ããããèŠæ
ã¯ïŒ <span>0</span>, <span>1</span>, <span>?</span>ãããªãé·ã<var>L</var> ã®æåå<var>T_d</var> ãšããŠè¡šããïŒ
</p>
<ul>
<li> <var>T_d</var> ã®<var>j</var> æåç®(<var>1 \leq j \leq L</var>) ã<span>0</span> ã®å Žåã¯ïŒ<var>d</var> æ¥ç®ã«è±èµ°ãããã¹ãŠã®æ¯èã®é ããæ°ããŠ<var>j</var> çªç®ã®éšåãéã§ããããšã衚ãïŒ</li>
<li> <var>T_d</var> ã®<var>j</var> æåç®(<var>1 \leq j \leq L</var>) ã<span>1</span> ã®å Žåã¯ïŒ<var>d</var> æ¥ç®ã«è±èµ°ãããã¹ãŠã®æ¯èã®é ããæ°ããŠ<var>j</var> çªç®ã®éšåãèµ€ã§ããããšã衚ãïŒ</li>
<li> <var>T_d</var> ã®<var>j</var> æåç®(<var>1 \leq j \leq L</var>) ã<span>?</span> ã®å Žåã¯ïŒ<var>d</var> æ¥ç®ã«è±èµ°ããæ¯èã®é ããæ°ããŠ<var>j</var> çªç®ã®éšåã«ã€ããŠã¯ïŒåšèŸºäœæ°ããã¯æ
å ±ãäžããããªãã£ãããšã衚ãïŒ</li>
</ul>
<p>
èŠæ
ã¯ãã¹ãŠæ£ç¢ºãªæ
å ±ã§ããïŒè±èµ°ããæ¯èã¯JOI ç ç©¶æã®è·å¡ããã®æ¥ã®ãã¡ã«æç²ããïŒæç²ãããæ¯èãïŒç¿æ¥ä»¥éã«åã³è±èµ°ããããšã¯ããåŸãïŒ
</p>
<p>
æ¯èã®è±èµ°ã«ãããªã¹ã¯ãèŠç©ããããã«ïŒJOI ç ç©¶æã®K çäºé·ã¯è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãç¥ãããïŒããªãã®ä»äºã¯ïŒ<var>Q</var> æ¥éã«ãããèŠæ
ã®æ
å ±ããïŒããããã®æ¥ããšã«ïŒãã®æ¥ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãæ±ããããã°ã©ã ãäœæããããšã§ããïŒ
</p>
<h3>課é¡</h3>
<p>
æ¯èã®æ¯æ§ã衚ãæåå<var>S</var> ãšïŒ<var>Q</var> æ¥éã®èŠæ
ã®æ
å ±ãäžããããã®ã§ïŒããããã®æ¥ããšã«ïŒãã®æ¥ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<p>
ã¡ã¢ãªå¶éãå°ããããšã«æ³šæããããšïŒ
</p>
<h3>å
¥å</h3>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒæŽæ°<var>L, Q</var> ã空çœãåºåããšããŠæžãããŠããïŒãããã¯é ã«ïŒæ¯èã®éšåã®åæ°ãšïŒèŠæ
ã®å¯ããããæ¥æ°ã衚ãïŒ
</li>
<li> 2 è¡ç®ã«ã¯ïŒé·ã<var>2^L</var> ã®æåå<var>S</var> ãæžãããŠããïŒãã®æååã¯æ¯èã®æ¯æ§ã衚ãïŒ</li>
<li> ç¶ã<var>Q</var> è¡ã®ãã¡ã®<var>d</var> è¡ç®(<var>1 \leq d \leq Q</var>) ã«ã¯ïŒé·ã<var>L</var> ã®æåå<var>T_d</var> ãæžãããŠããïŒãã®æååã¯<var>d</var> æ¥ç®ã®èŠæ
ã衚ãïŒ</li>
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«<var>Q</var> è¡ã§åºåããïŒ<var>d</var> è¡ç®ã«ã¯ïŒ<var>d</var> æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãè¡šãæŽæ°ãåºåããïŒ
</p>
<h3>å¶é</h3>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li><var> 1 \leq L \leq 20</var>ïŒ</li>
<li><var> 1 \leq Q \leq 1 000 000</var>ïŒ</li>
<li><var>S</var> ã¯é·ã<var>2^L</var> ã®æååã§ããïŒ</li>
<li> æåå<var>S</var> ã¯<span>0</span>, <span>1</span>, <span>2</span>, <span>3</span>, <span>4</span>, <span>5</span>, <span>6</span>, <span>7</span>, <span>8</span>, <span>9</span> ãããªãïŒ</li>
<li> <var>T_d</var> ã¯é·ã<var>L</var> ã®æååã§ãã(<var>1 \leq d \leq Q</var>)ïŒ</li>
<li> æåå<var>T_d</var> ã¯<span>0</span>, <span>1</span>, <span>?</span> ãããªã(<var>1 \leq d \leq Q</var>)ïŒ</li>
</ul>
<!--
å°èª²é¡
å°èª²é¡1 [5 ç¹]
以äžã®æ¡ä»¶ãæºããïŒ
L ⊠10ïŒ
Q ⊠1 000ïŒ
å°èª²é¡2 [7 ç¹]
L ⊠10 ãæºããïŒ
å°èª²é¡3 [10 ç¹]
L ⊠13 ãæºããïŒ
å°èª²é¡4 [53 ç¹]
Q ⊠50 000 ãæºããïŒ
å°èª²é¡5 [25 ç¹]
远å ã®å¶éã¯ãªãïŒ
-->
<h3>å
¥åºåäŸ</h3>
<h3>å
¥åäŸ1 </h3>
<pre>
3 5
12345678
000
0??
1?0
?11
???
</pre>
<h3>åºåäŸ1</h3>
<pre>
1
10
12
12
36
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒ<var>L = 3</var> ã§ããïŒ3 ã€ã®éšåã«åãããæ¯èãïŒå
šéšã§<var>2^3 = 8</var> å¹ããïŒèŠæ
ã¯5 æ¥éã«ããã£ãŠå¯ããããïŒ
</p>
<ul>
<li> 1 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è0 ã®ã¿ã§ããïŒæ¯æ§ã®åèšã¯1 ã§ããïŒ</li>
<li> 2 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è0, 1, 2, 3 ã§ããïŒæ¯æ§ã®åèšã¯10 ã§ããïŒ</li>
<li> 3 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è4, 6 ã§ããïŒæ¯æ§ã®åèšã¯12 ã§ããïŒ</li>
<li> 4 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è3, 7 ã§ããïŒæ¯æ§ã®åèšã¯12 ã§ããïŒ</li>
<li> 5 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è0, 1, 2, 3, 4, 5, 6, 7 ã§ããïŒæ¯æ§ã®åèšã¯36 ã§ããïŒ</li>
</ul>
<h3>å
¥åäŸ2</h3>
<pre>
4 8
3141592653589793
0101
?01?
??1?
?0??
1?00
01?1
??10
????
</pre>
<h3>åºåäŸ2</h3>
<pre>
9
18
38
30
14
15
20
80
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2017/2018-ho/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第17 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2017/2018) æ¬éžã</a>
</p>
|
p02119 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem I: Making Pairs</h1>
<h2>Problem</h2>
<p>æ¬æ¥ãã€ãã«å®å
šæåŸ
å¶ã®é«çŽã¬ã¹ãã©ã³ããã€ã
ã¬ã¹ãã©ã³ãããªãŒãã³ãããæ°ããªäŒå¡ãæåŸ
ããæš©å©ãæã€ã®ã¯ãã®ã¬ã¹ãã©ã³ã®äŒå¡ã®ã¿ã§ãæåãäŒå¡ã¯äŒå¡çªå·0ã§ããã¬ã¹ãã©ã³ã®ãªãŒããŒã®ã¿ã§ããã</p>
<p>ãã€ã
ã¬ã¹ãã©ã³ã¯ãã®é«çŽãæ
ããªãŒãã³åæ¥ãã$N$æ¥éããéãããªãããã®æéäžãæ¯æ¥äŒå¡ã®ãã¡èª°ãäžäººããèªåã®å人ãäžäººã ãæ°ãã«äŒå¡ãšããŠæåŸ
ããã$i$æ¥ç®ã«æåŸ
ãããäŒå¡ã«ã¯äŒå¡çªå·$i$ãå²ãåœãŠããããã®äŒå¡ã¯æåŸ
ãããæ¥ãå«ãããä»¥éæ¯æ¥æ¥åºããã</p>
<p>ãã®ã¬ã¹ãã©ã³ã«ã¯äºäººçšããŒãã«ããååšããªãã®ã§ãäŒå¡ã®äººã
ã¯ã§ããã ããã¢ã§ããŒãã«ã䜿çšããŠé£äºããããé£äºã«ã¯ãªãŒããŒãåå ããã®ã§ãä»ã®äŒå¡ã¯ãªãŒããŒãšãã¢ãçµãããšãã§ãããããããäŒå¡ã®äººã
ã¯ç人èŠç¥ãã§ãããèªåãæåŸ
ããå人ããèªåãæåŸ
ããå人ãšãããã¢ãçµã¿ããããªããåäŒå¡ã¯ããå人ãšãã¢ãçµããªãã£ãå Žåãäžäººå¯ããé£äºãããã</p>
<p>$N$æ¥éã®åæ¥ã«ã€ããŠãå人ã©ããã®ãã¢ã®æ°ãæå€§ãšãªãããã«ãã¢ãçµãã ãšããããã€ã®ãã¢ãã§ãããæ±ããã</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<p>
$N$<br>
$p_1$<br>
$p_2$<br>
...<br>
$p_N$<br>
</p>
<p>
1è¡ç®ã«ã¬ã¹ãã©ã³ãéãããæ¥æ°$N$ãäžããããã<br>
ç¶ã$N$è¡ã«ãäŒå¡çªå·ã$i$ã®äŒå¡ãæåŸ
ããäŒå¡ã®äŒå¡çªå·$p_i$ãäžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq N \leq 5000$</li>
<li>$0 \leq p_i \leq i-1$ ($1 \leq i \leq N$)</li>
<li>$N$, $p_i$ã¯æŽæ°</li>
</ul>
<h2>Output</h2>
<p>
åºåã¯$N$è¡ãããªãã<br>
$i$è¡ç®ã«ã¯ã$i$æ¥ç®ã«äœãããšã®ã§ããå人ã©ããã®ãã¢ã®æå€§æ°ãåºåããã
($1 \leq i \leq N$)</p>
<h2>Sample Input 1</h2>
<pre>
3
0
0
2
</pre>
<h2>Sample Output 1</h2>
<pre>
1
1
2
</pre>
<h2>Sample Input 2</h2>
<pre>
5
0
1
2
3
4
</pre>
<h2>Sample Output 2</h2>
<pre>
1
1
2
2
3
</pre> |
p00124 |
<h1>ãªãŒã°æŠã®ã¹ã³ã¢ã·ãŒã</h1>
<p>
ã¹ããŒãã®å€§äŒã«ã¯ãªãŒã°æŠãšããŒãã¡ã³ãæŠããããŸãããµãã«ãŒã®ãªãŒã°æŠã§ã¯åã»è² ã»åŒåã«ããããç¹æ°ãä»ãããã®åã¡ç¹ã§é äœãç«¶ããŸããåã¡ç¹ã¯ããããå(3ç¹)ãè² (0ç¹)ãåŒå(1ç¹)ã§ãã
</p>
<p>
ããŒã æ°ãšãªãŒã°æŠã®æçžŸãå
¥åãšããæçžŸã®è¯ãé (åã¡ç¹ã®å€ãé )ã«äžŠã¹æ¿ããããŒã åãšåã¡ç¹ãåºåããããã°ã©ã ãäœæããŠãã ãããåã¡ç¹ãåç¹ã®å Žåã¯å
¥åé ã«åºåããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>name<sub>1</sub></var> <var>w<sub>1</sub></var> <var>l<sub>1</sub></var> <var>d<sub>1</sub></var>
<var>name<sub>2</sub></var> <var>w<sub>2</sub></var> <var>l<sub>2</sub></var> <var>d<sub>2</sub></var>
:
<var>name<sub>n</sub></var> <var>w<sub>n</sub></var> <var>l<sub>n</sub></var> <var>d<sub>n</sub></var>
</pre>
<p>
ïŒè¡ç®ã«ããŒã æ° <var>n</var> (<var>n</var> ≤ 10) ãäžããããŸããç¶ã <var>n</var> è¡ã«ããŒã <var>i</var> ã®åå <var>name<sub>i</sub></var> (20æå以å
ã®ã¢ã«ãã¡ããã)ãåã®æ° <var>w<sub>i</sub></var>ãè² ã®æ° <var>l<sub>i</sub></var>ãåŒåã®æ° <var>d<sub>i</sub></var> (0 ≤ <var>w<sub>i</sub></var>, <var>l<sub>i</sub></var>, <var>d<sub>i</sub></var> ≤ 9) ã空çœåºåãã§äžããããŸãã
</p>
<p>
ããŒã æ°ã 0 ã®ãšããå
¥åã®çµäºãšããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ãäžŠã¹æ¿ããããŒã ã®ãªã¹ããåºåããŠãã ããã<var>i</var> è¡ç®ã« <var>i</var> çªç®ã®ããŒã ã®ååãšåã¡ç¹ãã«ã³ãã§åºåã£ãŠåºåããŠãã ããã
</p>
<p>
ããŒã¿ã»ããã®éã«ïŒã€ã®ç©ºè¡ãå
¥ããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
4
Japan 1 0 2
Egypt 1 2 0
Canada 0 2 1
Spain 2 0 1
3
India 0 2 0
Poland 1 0 1
Italy 1 0 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Spain,7
Japan,5
Egypt,3
Canada,1
Poland,4
Italy,4
India,0
</pre>
|
p01365 |
<H1><font color="#000">Problem G:</font> Camera Control</H1>
<p>
"ACM48" is one of the most popular dance vocal units in Japan. In this winter, ACM48 is
planning a world concert tour. You joined the tour as a camera engineer.
</p>
<p>
Your role is to develop software which controls the camera on a stage. For simplicity you can
regard the stage as 2-dimensional space. You can rotate the camera to an arbitrary direction
by the software but cannot change its coordinate.
</p>
<p>
During a stage performance, each member of ACM48 moves along her route and sings the part(s)
assigned to her. Here, a route is given as a polygonal line.
</p>
<p>
You have to keep focusing the camera on a member during a stage performance. You can change
the member focused by the camera if and only if the current and next members are in the same
direction from the camera.
</p>
<p>
Your task is to write a program which reads the stage performance plan and calculates the
maximum time that you can focus the camera on members that are singing.
</p>
<p>
You may assume the following are satisfied:
</p>
<ul>
<li> You can focus the camera on an arbitrary member at the beginning time.</li>
<li> Each route of the member does not touch the camera.</li>
<li> Each member stays at the last coordinates after she reaches there.</li>
</ul>
<H2>Input</H2>
<p>
The input contains multiple test cases. Each test case has the following format:
</p>
<p>
<i>N</i><br>
<i>c<sub>x</sub> c<sub>y</sub></i><br>
The information of the 1-st member<br>
.<br>
.<br>
.<br>
The information of the <i>N</i>-th member<br>
</p>
<p>
<i>N</i> (1 ≤ <i>N</i> ≤ 50) is the number of the members. (<i>c<sub>x</sub></i>, <i>c<sub>y</sub></i>) is the coordinates of the camera. Then
the information of the <i>N</i> members follow.
</p>
<p>
The information of the <i>i</i>-th member has the following format:
</p>
<p>
<i>M<sub>i</sub></i><br>
<i>x</i><sub><i>i</i>,1</sub> <i>y</i><sub><i>i</i>,1</sub> <i>t</i><sub><i>i</i>,1</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>i</i>,<i>M<sub>i</sub></i></sub> <i>y</i><sub><i>i</i>,<i>M<sub>i</sub></i></sub> <i>t</i><sub><i>i</i>,<i>M<sub>i</sub></i></sub> <br>
<i>L<sub>i</sub></i><br>
<i>b</i><sub><i>i</i>,1</sub> <i>e</i><sub><i>i</i>,1</sub><br>
.<br>
.<br>
.<br>
<i>b</i><sub><i>i</i>,<i>L<sub>i</sub></i></sub> <i>e</i><sub><i>i</i>,<i>L<sub>i</sub></i></sub> <br>
</p>
<p>
<i>M<sub>i</sub></i> (1 ≤ <i>M<sub>i</sub></i> ≤ 100) is the number of the points in the route. (<i>x<sub>i,j</sub></i>, <i>y<sub>i,j</sub></i> ) is the coordinates of the
<i>j</i>-th in the route. <i>t<sub>i,j</sub></i> (0 = <i>t</i><sub><i>i</i>,0</sub> < <i>t</i><sub><i>i</i>,<i>j</i></sub> < <i>t</i><sub><i>i</i>,<i>j</i>+1</sub> ≤ 10<sup>3</sup> for 0 < <i>j</i>) is the time that the <i>i</i>-th member
reaches the <i>j</i>-th coordinates. <i>L<sub>i</sub></i> (0 ≤ <i>L<sub>i</sub></i> ≤ 100) is the number of the vocal part. <i>b<sub>i,k</sub></i> and <i>e<sub>i,k</sub></i> (0 ≤ <i>b<sub>i,k</sub></i> < <i>e<sub>i,k</sub></i> < <i>b</i><sub><i>i</i>,<i>k</i>+1</sub> < <i>e</i><sub><i>i</i>,<i>k</i>+1</sub> ≤ 10<sup>3</sup> ) are the beginning and the ending time of the <i>k</i>-th vocal
part, respectively.
</p>
<p>
All the input values are integers. You may assume that the absolute of all the coordinates are
not more than 10<sup>3</sup> .
</p>
<p>
<i>N</i> = 0 denotes the end of the input. You may not process this as a test case.
</p>
<H2>Output</H2>
<p>
For each dataset, print the maximum time that you can focus the camera on singing members
with an absolute error of at most 10<sup>-6</sup>. You may output any number of digits after the decimal
point.
</p>
<H2>Sample Input</H2>
<pre>
2
0 0
2
-5 5 0
5 5 10
1
0 6
2
5 5 0
-5 5 10
1
6 10
1
7 -65
2
-65 10 0
65 1 3
2
0 1
23 24
2
0 0
2
100 10 0
-10 10 10
5
0 1
2 3
4 5
6 7
8 9
2
10 0 0
0 10 10
5
1 2
3 4
5 6
7 8
9 10
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
9.00000000
2.00000000
5.98862017
</pre>
|
p03358 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var>.
The <var>i</var>-th edge connects Vertex <var>x_i</var> and <var>y_i</var>.
Each vertex is painted white or black.
The initial color of Vertex <var>i</var> is represented by a letter <var>c_i</var>.
<var>c_i</var> <var>=</var> <code>W</code> represents the vertex is white; <var>c_i</var> <var>=</var> <code>B</code> represents the vertex is black.</p>
<p>A cat will walk along this tree.
More specifically, she performs one of the following in one second repeatedly:</p>
<ul>
<li>Choose a vertex that is adjacent to the vertex where she is currently, and move to that vertex. Then, invert the color of the destination vertex.</li>
<li>Invert the color of the vertex where she is currently.</li>
</ul>
<p>The cat's objective is to paint all the vertices black. She may start and end performing actions at any vertex.
At least how many seconds does it takes for the cat to achieve her objective?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1</var> <var>â€</var> <var>N</var> <var>â€</var> <var>10^5</var></li>
<li><var>1</var> <var>â€</var> <var>x_i,y_i</var> <var>â€</var> <var>N</var> (<var>1</var> <var>â€</var> <var>i</var> <var>â€</var> <var>N-1</var>)</li>
<li>The given graph is a tree.</li>
<li><var>c_i</var> <var>=</var> <code>W</code> or <var>c_i</var> <var>=</var> <code>B</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>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
<var>:</var>
<var>x_{N-1}</var> <var>y_{N-1}</var>
<var>c_1c_2..c_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of seconds required to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2
2 3
2 4
4 5
WBBWW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>The objective can be achieved in five seconds, for example, as follows:</p>
<ul>
<li>Start at Vertex <var>1</var>. Change the color of Vertex <var>1</var> to black.</li>
<li>Move to Vertex <var>2</var>, then change the color of Vertex <var>2</var> to white.</li>
<li>Change the color of Vertex <var>2</var> to black.</li>
<li>Move to Vertex <var>4</var>, then change the color of Vertex <var>4</var> to black.</li>
<li>Move to Vertex <var>5</var>, then change the color of Vertex <var>5</var> to black.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
3 1
4 5
2 6
6 1
3 4
WWBWBB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
B
</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>20
2 19
5 13
6 4
15 6
12 19
13 19
3 11
8 3
3 20
16 13
7 14
3 17
7 8
10 20
11 9
8 18
8 2
10 1
6 13
WBWBWBBWWWBBWWBBBBBW
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>21
</pre></section>
</div>
</span> |
p00827 |
<H1><font color="#000">Problem A:</font> The Balance</H1>
<p>
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
</p>
<p>
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put
one 700mg weight on the side of the medicine and three 300mg weights on the opposite side
(Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg
weights on the other (Figure 2), she would not choose this solution because it is less convenient
to use more weights.
</p>
<p>
You are asked to help her by calculating how many weights are required.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_theBalance1">
<p>Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight</p>
</center>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_theBalance2">
<p>Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights</p>
</center>
<H2>Input</H2>
<p>
The input is a sequence of datasets. A dataset is a line containing three positive integers <i>a</i>, <i>b</i>,
and <i>d</i> separated by a space. The following relations hold: <i>a</i> ≠ <i>b</i>, <i>a</i> ≤ 10000, <i>b</i> ≤ 10000, and
<i>d</i> ≤ 50000. You may assume that it is possible to measure <i>d</i> mg using a combination of <i>a</i> mg
and <i>b</i> mg weights. In other words, you need not consider âno solutionâ cases.
</p>
<p>
The end of the input is indicated by a line containing three zeros separated by a space. It is not
a dataset.
</p>
<H2>Output</H2>
<p>
The output should be composed of lines, each corresponding to an input dataset (<i>a</i>, <i>b</i>, <i>d</i>). An
output line should contain two nonnegative integers <i>x</i> and <i>y</i> separated by a space. They should
satisfy the following three conditions.
</p>
<ul>
<li> You can measure <i>d</i> mg using <i>x</i> many <i>a</i> mg weights and <i>y</i> many <i>b</i> mg weights.</li>
<li> The total number of weights (<i>x</i> + <i>y</i>) is the smallest among those pairs of nonnegative
integers satisfying the previous condition.</li>
<li> The total mass of weights (<i>ax</i> + <i>by</i>) is the smallest among those pairs of nonnegative
integers satisfying the previous two conditions.</li>
</ul>
<p>
No extra characters (e.g. extra spaces) should appear in the output.
</p>
<H2>Sample Input</H2>
<pre>
700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 3
1 1
1 0
0 3
1 1
49 74
3333 1
</pre>
|
p01735 |
<p>
Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices.
Each node in the game has an evaluation value which shows how good a situation is.
This value is the same as maximum value of child nodesâ values multiplied by -1. Values on leaf nodes are evaluated with Cielâs special function -- which is a bit heavy.
So, she will use alpha-beta pruning for getting root nodeâs evaluation value to decrease the number of leaf nodes to be calculated.
</p>
<p>
By the way, changing evaluation order of child nodes affects the number of calculation on the leaf nodes.
Therefore, Ciel wants to know the minimum and maximum number of times to calculate in leaf nodes when she could evaluate child node in arbitrary order.
She asked you to calculate minimum evaluation number of times and maximum evaluation number of times in leaf nodes.
</p>
<p>
Ciel uses following algotithm:
</p>
<pre>
function negamax(node, α, β)
if node is a terminal node
return value of leaf node
else
foreach child of node
val := -negamax(child, -β, -α)
if val >= β
return val
if val > α
α := val
return α
</pre>
<p>
[NOTE]
<a href="http://en.wikipedia.org/wiki/Negamax">negamax algorithm</a>
</p>
<h3>Input</h3>
<p>Input follows following format:</p>
<pre>
<var>n</var>
<var>p_1</var> <var>p_2</var> ... <var>p_n</var>
<var>k_1</var> <var>t_{11}</var> <var>t_{12}</var> ... <var>t_{1k}</var>
:
:
<var>k_n</var> <var>t_{n1}</var> <var>t_{n2}</var> ... <var>t_{nk}</var>
</pre>
<p>The first line contains an integer <var>n</var>, which means the number of vertices in game tree T.<br>
The second line contains <var>n</var> integers <var>p_i</var>, which means the evaluation value of vertex <var>i</var>.<br>
Then, next <var>n</var> lines which contain the information of game tree T.<br>
<var>k_i</var> is the number of child nodes of vertex <var>i</var>, and <var>t_{ij}</var> is the indices of the child node of vertex <var>i</var>.<br>
Input follows following constraints:
</p>
<ul><li> <var>2 \leq n \leq 100</var>
</li><li> <var>-10,000 \leq p_i \leq 10,000</var>
</li><li> <var>0 \leq k_i \leq 5</var>
</li><li> <var>2 \leq t_{ij} \leq n</var>
</li><li> Index of root node is <var>1</var>.
</li><li> Evaluation value except leaf node is always <var>0</var>. This does not mean the evaluation values of non-leaf nodes are <var>0</var>. You have to calculate them if necessary.
</li><li> Leaf node sometimes have evaluation value of <var>0</var>.
</li><li> Game tree T is tree structure.
</li></ul>
<h3>Output</h3>
<p>Print the minimum evaluation number of times and the maximum evaluation number of times in leaf node.<br>
Please separated by whitespace between minimum and maximum.
</p><pre>
minimum maximum</pre>
<h3>Sample Input 1</h3>
<pre>3
0 1 1
2 2 3
0
0
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>2 2
</pre>
<h3>Sample Input 2</h3>
<pre>8
0 0 100 100 0 -100 -100 -100
2 2 5
2 3 4
0
0
3 6 7 8
0
0
0
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>3 5
</pre>
<h3>Sample Input 3</h3>
<pre>8
0 0 100 100 0 100 100 100
2 2 5
2 3 4
0
0
3 6 7 8
0
0
0
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>3 4
</pre>
<h3>Sample Input 4</h3>
<pre>19
0 100 0 100 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10
2 2 3
0
2 4 5
0
3 6 7 8
3 9 10 11
3 12 13 14
3 15 16 17
2 18 19
0
0
0
0
0
0
0
0
0
0
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>7 12
</pre>
</div>
</div> |
p03708 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Nukes has an integer that can be represented as the bitwise OR of one or more integers between <var>A</var> and <var>B</var> (inclusive).
How many possible candidates of the value of Nukes's integer there are?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †A †B < 2^{60}</var></li>
<li><var>A</var> and <var>B</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>A</var>
<var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of possible candidates of the value of Nukes's integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>In this case, <var>A=7</var> and <var>B=9</var>. There are four integers that can be represented as the bitwise OR of a non-empty subset of {<var>7</var>, <var>8</var>, <var>9</var>}: <var>7</var>, <var>8</var>, <var>9</var> and <var>15</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>65
98
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>63
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>271828182845904523
314159265358979323
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>68833183630578410
</pre></section>
</div>
</span> |
p03026 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices <var>1,2,\ldots,N</var>, and positive integers <var>c_1,c_2,\ldots,c_N</var>.
The <var>i</var>-th edge in the tree <var>(1 \leq i \leq N-1)</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p>
<p>We will write a positive integer on each vertex in <var>T</var> and calculate our <em>score</em> as follows:</p>
<ul>
<li>On each edge, write the smaller of the integers written on the two endpoints.</li>
<li>Let our score be the sum of the integers written on all the edges.</li>
</ul>
<p>Find the maximum possible score when we write each of <var>c_1,c_2,\ldots,c_N</var> on one vertex in <var>T</var>, and show one way to achieve it. If an integer occurs multiple times in <var>c_1,c_2,\ldots,c_N</var>, we must use it that number of times.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10000</var></li>
<li><var>1 \leq a_i,b_i \leq N</var></li>
<li><var>1 \leq c_i \leq 10^5</var></li>
<li>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>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>
<var>c_1</var> <var>\ldots</var> <var>c_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Use the following format:</p>
<pre><var>M</var>
<var>d_1</var> <var>\ldots</var> <var>d_N</var>
</pre>
<p>where <var>M</var> is the maximum possible score, and <var>d_i</var> is the integer to write on Vertex <var>i</var>.
<var>d_1,d_2,\ldots,d_N</var> must be a permutation of <var>c_1,c_2,\ldots,c_N</var>.
If there are multiple ways to achieve the maximum score, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 2
2 3
3 4
4 5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
1 2 3 4 5
</pre>
<p>If we write <var>1,2,3,4,5</var> on Vertex <var>1,2,3,4,5</var>, respectively, the integers written on the four edges will be <var>1,2,3,4</var>, for the score of <var>10</var>. This is the maximum possible score.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2
1 3
1 4
1 5
3141 59 26 53 59
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>197
59 26 3141 59 53
</pre>
<p><var>c_1,c_2,\ldots,c_N</var> may not be pairwise distinct.</p></section>
</div>
</span> |
p03476 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We say that a odd number <var>N</var> is <em>similar to 2017</em> when both <var>N</var> and <var>(N+1)/2</var> are prime.</p>
<p>You are given <var>Q</var> queries.</p>
<p>In the <var>i</var>-th query, given two odd numbers <var>l_i</var> and <var>r_i</var>, find the number of odd numbers <var>x</var> similar to 2017 such that <var>l_i †x †r_i</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€Qâ€10^5</var></li>
<li><var>1â€l_iâ€r_iâ€10^5</var></li>
<li><var>l_i</var> and <var>r_i</var> are odd.</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>Q</var>
<var>l_1</var> <var>r_1</var>
<var>:</var>
<var>l_Q</var> <var>r_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line <var>(1â€iâ€Q)</var> should contain the response to the <var>i</var>-th query.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<ul>
<li><var>3</var> is similar to 2017, since both <var>3</var> and <var>(3+1)/2=2</var> are prime.</li>
<li><var>5</var> is similar to 2017, since both <var>5</var> and <var>(5+1)/2=3</var> are prime.</li>
<li><var>7</var> is not similar to 2017, since <var>(7+1)/2=4</var> is not prime, although <var>7</var> is prime.</li>
</ul>
<p>Thus, the response to the first query should be <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
13 13
7 11
7 11
2017 2017
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
0
0
1
</pre>
<p>Note that <var>2017</var> is also similar to 2017.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 53
13 91
37 55
19 51
73 91
13 49
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
4
1
1
1
2
</pre></section>
</div>
</span> |
p02637 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are an integer <var>K</var> and integers <var>a_1,\dots, a_K</var>. Determine whether a sequence <var>P</var> satisfying below exists. If it exists, find the lexicographically smallest such sequence.</p>
<ul>
<li>Every term in <var>P</var> is an integer between <var>1</var> and <var>K</var> (inclusive).</li>
<li>For each <var>i=1,\dots, K</var>, <var>P</var> contains <var>a_i</var> occurrences of <var>i</var>.</li>
<li>For each term in <var>P</var>, there is a contiguous subsequence of length <var>K</var> that contains that term and is a permutation of <var>1,\dots, K</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq K \leq 100</var></li>
<li><var>1 \leq a_i \leq 1000 \quad (1\leq i\leq K)</var></li>
<li><var>a_1 + \dots + a_K\leq 1000</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>K</var>
<var>a_1</var> <var>a_2</var> <var>\dots</var> <var>a_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there is no sequence satisfying the conditions, print <code>-1</code>.
Otherwise, print the lexicographically smallest sequence satisfying the conditions.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 1 3 2 2 3 1 2 3
</pre>
<p>For example, the fifth term, which is <var>2</var>, is in the subsequence <var>(2, 3, 1)</var> composed of the fifth, sixth, and seventh terms.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
3 2 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 2 3 4 1 3 1 2 4 3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
3 1 4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre></section>
</div>
</span> |
p03925 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a graph with <var>N</var> vertices, numbered <var>0</var> through <var>N-1</var>. Edges are yet to be added.</p>
<p>We will process <var>Q</var> queries to add edges.
In the <var>i</var>-th <var>(1âŠiâŠQ)</var> query, three integers <var>A_i, B_i</var> and <var>C_i</var> will be given, and we will add infinitely many edges to the graph as follows:</p>
<ul>
<li>The two vertices numbered <var>A_i</var> and <var>B_i</var> will be connected by an edge with a weight of <var>C_i</var>.</li>
<li>The two vertices numbered <var>B_i</var> and <var>A_i+1</var> will be connected by an edge with a weight of <var>C_i+1</var>.</li>
<li>The two vertices numbered <var>A_i+1</var> and <var>B_i+1</var> will be connected by an edge with a weight of <var>C_i+2</var>.</li>
<li>The two vertices numbered <var>B_i+1</var> and <var>A_i+2</var> will be connected by an edge with a weight of <var>C_i+3</var>.</li>
<li>The two vertices numbered <var>A_i+2</var> and <var>B_i+2</var> will be connected by an edge with a weight of <var>C_i+4</var>.</li>
<li>The two vertices numbered <var>B_i+2</var> and <var>A_i+3</var> will be connected by an edge with a weight of <var>C_i+5</var>.</li>
<li>The two vertices numbered <var>A_i+3</var> and <var>B_i+3</var> will be connected by an edge with a weight of <var>C_i+6</var>.</li>
<li>...</li>
</ul>
<p>Here, consider the indices of the vertices modulo <var>N</var>.
For example, the vertice numbered <var>N</var> is the one numbered <var>0</var>, and the vertice numbered <var>2N-1</var> is the one numbered <var>N-1</var>.</p>
<p>The figure below shows the first seven edges added when <var>N=16, A_i=7, B_i=14, C_i=1</var>:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/5b0258fb4255f846a4e10ce875362baf.png"/></p>
<p>After processing all the queries, find the total weight of the edges contained in a minimum spanning tree of the graph.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2âŠNâŠ200,000</var></li>
<li><var>1âŠQâŠ200,000</var></li>
<li><var>0âŠA_i,B_iâŠN-1</var></li>
<li><var>1âŠC_iâŠ10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Q</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_Q</var> <var>B_Q</var> <var>C_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total weight of the edges contained in a minimum spanning tree of the graph.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 1
5 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>21
</pre>
<p>The figure below shows the minimum spanning tree of the graph:</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/f1a6c3cfd52c386e6da5c8c761a78521.png"/></p>
<p>Note that there can be multiple edges connecting the same pair of vertices.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 1
0 0 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1000000001
</pre>
<p>Also note that there can be self-loops.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 3
0 1 10
0 2 10
0 4 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>42
</pre></section>
</div>
</span> |
p01918 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath2017.js" charset="UTF-8"></script>
<h2>C: ä»å·çŒããã³ - Imagawayaki Man -</h2>
<h3>ç©èª</h3>
<p>ä»å·çŒããã³ã¯ãæ£çŸ©ã®ããŒããŒã§ãããé¡ã¯çŽåŸ <var>1</var> ã¡ãŒãã«ã®ä»å·çŒãïŒäž»ã«å°éºŠç²ã§ã§ããçå°ã®äžã«ãã£ã·ããšé€¡ãè©°ããŠçŒããé£ã¹ç©ã§ãããèŠãç®ã¯å圢ã§ãããçŸå³ãããåæµ·éã§ã¯ãåã«ããçŒãããšåŒã°ããããšãå€ãã逡ãšããŠå°è±é€¡ã®ã»ãã«ãã«ã¹ã¿ãŒãã¯ãªãŒã ãªã©ãçšããããšããããããŸããŸãªå³ã®ããªãšãŒã·ã§ã³ãããããã®ãããããã€é£ã¹ãŠã飜ããªããå°è±é€¡ãã«ã¹ã¿ãŒãã¯ãªãŒã ã®ã»ãã«ãæ¹è¶é€¡ãããããžã£ã ãªã©ãçŸå³ãããäžã«ã¿ã³ãå
¥ããããçŒãã®ãããªãã®ãããããã ãã©ã®å³ãçŸå³ãããäžã®åçã¯æšæºçãªä»å·çŒãã§ãããå·Šã¯ã¯ãªãŒã 逡ãå³ã¯å°è±é€¡ãå
¥ã£ãŠãããçŸå³ãããã§ãããå®éã«é£ã¹ãŠèŠããšããããã¯ãçŸå³ããã£ãããšããã§ãä»å·çŒãã®çŽåŸã¯éåžž <var>10</var> ã»ã³ãã¡ãŒãã«çšåºŠã§ããã®ã§ãçŽåŸ <var>1</var> ã¡ãŒãã«ã®ä»å·çŒãã¯ããªã倧ããªãã®ã§ããããšã«æ³šæããããïŒã§ã§ããŠããããè
¹ã®ç©ºããè
ã«èªåã®é¡ãåããŠå·®ãåºãããšãããããã®ãããå¿
èŠã«å¿ããŠé¡ãåãæ¿ããå¿
èŠãããããã€ã§ãåãæ¿ããããããã«ãä»å·çŒãå·¥å Žã§ãããããäžäººã§ãã£ããšäžã€ãã€ä»å·çŒããçŒããŠæ¥ã
åããŠããã</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day3_HUPC2017_imagawayaki" type="image/jpeg" width="300"></img>
<p>ãšããã§ãä»å·çŒãã¯é£åã§ãããããåœç¶ãªããè³å³æéãååšãããç¡é§ã«ããªãããã«ã¯ãçŒããŠããæéãçµã£ããã®ããé ã«äœ¿ãããšãæãŸãããããããã¯äžå³ã®ããã«ã宿ããçŽåŸ <var>1</var> ã¡ãŒãã«ã®ä»å·çŒã (å³äžã®çè²éš) ãå¹
<var>1</var> ã¡ãŒãã«ã®ã¬ãŒã³ (å³äžã®ç°è²éš) ã®äžã«ééãªã䞊ã¹ãŠä¿åããŠããã</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day3_HUPC2017_lane" type="image/png" width="300"></img>
<p>ããæ¥ã倧æªå
ã®èçãã³ãå·¥å Žã«çŸããä»å·çŒããã³ãå°ãããããšãèªæ
¢ã®èçåã䜿ã£ãŠå·šå€§ãªä»å·çŒãããã£ããšéã³ã奜ãåæã«äžŠã³æ¿ããŠããŸã£ããèçãã³ã¯èçåã ãã§ãªãèšæ¶åãè¯ãã®ã§ãã©ã®ä»å·çŒããå
ã
äœçªç®ã«ãã£ãã®ãèŠããŠããããã ãè² ããèªããããªãä»å·çŒããã³ã¯ãäœãšãããŠãããããã®ä»å·çŒããäœçªç®ã«åºæ¥ããŠãªã®ãç¥ãããããèŠãç®ã§ã¯åããããã«ãªããããã§ãèçãã³ã«ããã¡ãããåã¯ã¡ãããšèŠããŠããããã§ããèçãã³ã¯æ¬åœã«ã¡ãããšèŠããŠããã®ããªïŒïŒããšæçºããããã«ãæ¬åœã«èŠããŠãããåããã¹ããããïŒããšèšã£ãŠè³ªåãç¹°ãè¿ãããšã§ãäœçªç®ã«åºæ¥ããŠãªã®ãç¥ãããšã«ããããã ããããŸã質åãããããšãæ¢ã£ãŠããããšãåä»ãããŠããŸãã®ã§ãã»ã©ã»ã©ã«ããªããã°ãªããªããããªãã«ã¯ãä»å·çŒããã³ãå©ããããã質åãç¹°ãè¿ãçæããããããã®ä»å·çŒããäœçªç®ã«åºæ¥ããŠãªã®ããåœãŠãããã°ã©ã ãäœæããŠã»ããã</p>
<h3>åé¡</h3>
<p>ãŸããå·¥å Žã«äžŠãã§ããä»å·çŒãã®åæ° <var>N</var> (<var>1 \leq N \leq 10,000</var>) ãæšæºå
¥åã«ãã1è¡ã§äžããããããããã®ä»å·çŒãã®è£œé æ¥æã¯äºãã«ç°ãªããã€ãŸãã <var>1 \leq i \leq N</var> ãæºããä»»æã®æŽæ° <var>i</var> ã«ã€ããŠã <var>i</var> çªç®ã«åºæ¥ããŠã®ä»å·çŒãã¯ãã ã²ãšã€ååšããã</p>
<p>ãã以éãä»»æã®2æŽæ° <var>a</var>, <var>b</var> (<var>1 \leq a, b \leq N</var>) ã«ãããŠãæšæºåºåã«</p>
<pre>? <var>a</var> <var>b</var></pre>
<p>ãšåºåãããšãã<var>a</var> çªç®ã«åºæ¥ããŠã®ä»å·çŒãã®äžå¿ãã <var>b</var> çªç®ã«åºæ¥ããŠã®ä»å·çŒãã®äžå¿ãŸã§ã®è·é¢ã¯äœã¡ãŒãã«ãïŒããšãã質åãè¡ãããšãã§ããããã®çãã¯æšæºå
¥åã«äžè¡ã§æŽæ°ãšããŠããã«äžãããããç©èªã§ãè¿°ã¹ãéããã¬ãŒã³äžã«ééãªãçŽåŸ <var>1</var> ã¡ãŒãã«ã®ä»å·çŒãã䞊ã¹ãããŠããã®ã§ãå·Šããæ°ã㊠<var>i</var> çªç®ã®ä»å·çŒãã®äžå¿ãã <var>j</var> çªç®ã®ä»å·çŒãã®äžå¿ãŸã§ã®è·é¢ã¯æ£ç¢ºã« <var>|i - j|</var> ã¡ãŒãã«ã§ããããã®è³ªå㯠<var>20,000</var> åãŸã§ç¹°ãè¿ãè¡ãããšãã§ããã</p>
<p>ããããã®ä»å·çŒããäœçªç®ã«åºæ¥ããŠãªã®ãåãã£ãããæšæºåºåã«æçµçãªçããåºåããªããã°ãªããªããåºå圢åŒã¯ãå <var>i</var> (<var> 1 \leq i \leq N</var>) ã«ãããŠãå·Šãã <var>i</var> çªç® ã®ä»å·çŒãã <var>x_i</var> çªç®ã«åºæ¥ããŠã®ãšãã</p>
<pre>! <var>x_1</var> <var>x_2</var> <var>x_3</var> ... <var>x_N</var></pre>
<p>ãŸãã¯ã</p>
<pre>! <var>x_N</var> <var>x_{N-1}</var> <var>x_{N-2}</var> ... <var>x_1</var></pre>
<p>ãšããã°ãããã€ãŸããå·Šããé ã«çããŠããå³ããé ã«çããŠãæ§ããªãããã®æçµçãªè§£çã¯ã1床ããè¡ãããšãã§ããªãããã®è§£çãæ£ããåºåã ã£ããšããæ£çãšã¿ãªãã</p>
<p>æšæºåºåãè¡ãæ¯ã«ãã¹ããªãŒã ããã©ãã·ã¥ (flush) ããå¿
èŠãããããšã«æ³šæããããäž»èŠãªèšèªã§ã®ãã©ãã·ã¥äŸã以äžã«ç€ºãããã¡ããããã以å€ã®æ¹æ³ã§ãã©ãã·ã¥ãè¡ã£ãŠãæ§ããªãã</p>
<p>C èšèª:</p>
<pre>
#include <stdio.h>
fflush(stdout);
</pre>
<p>C++:</p>
<pre>
#include <iostream>
std::cout.flush();
</pre>
<p>Java:</p>
<pre>System.out.flush();</pre>
<h3>å
¥åºåäŸ</h3>
<pre>
<table width="600" class="withborder"><tbody>
<tr><th>æšæºå
¥å</th><th>æšæºåºå</th></tr>
<tr><td>3</td><td> </td></tr>
<tr><td> </td><td>? 1 2</td></tr>
<tr><td>2</td><td> </td></tr>
<tr><td> </td><td>? 2 3</td></tr>
<tr><td>1</td><td> </td></tr>
<tr><td> </td><td>? 1 3</td></tr>
<tr><td>1</td><td></td></tr>
<tr><td> </td><td>! 2 3 1</td></tr>
</tbody></table>
</pre> |
p02267 |
<H1>Search I</H1>
<p>
You are given a sequence of <i>n</i> integers S and a sequence of different <i>q</i> integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
</p>
<H2>Input</H2>
<p>
In the first line <i>n</i> is given. In the second line, <i>n</i> integers are given. In the third line <i>q</i> is given. Then, in the fourth line, <i>q</i> integers are given.
</p>
<H2>Output</H2>
<p>
Print C in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>n ≤ 10000</li>
<li> q ≤ 500 </li>
<li>0 ≤ an element in S ≤ 10<sup>9</sup></li>
<li>0 ≤ an element in T ≤ 10<sup>9</sup></li>
</ul>
<H2>Sample Input 1</H2>
<pre>
5
1 2 3 4 5
3
3 4 1
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
<H2>Sample Input 2</H2>
<pre>
3
3 1 2
1
5
</pre>
<H2>Sample Output 2</H2>
<pre>
0
</pre>
<H2>Sample Input 3</H2>
<pre>
5
1 1 2 2 3
2
1 2
</pre>
<H2>Sample Output 3</H2>
<pre>
2
</pre>
<H2>Notes</H2>
<!--
<a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a>
-->
|
p02288 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1>Maximum Heap</h1>
<p>
A binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The largest element in a max-heap is stored at the root, and the subtree rooted at a node contains values no larger than that contained at the node itself.
</p>
<p>
Here is an example of a max-heap.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_9_B_1">
</center>
<br>
<p>
Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code.
</p>
<p>
$maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap.
</p>
<pre>
1 maxHeapify(A, i)
2 l = left(i)
3 r = right(i)
4 // select the node which has the maximum value
5 if l ≤ H and A[l] > A[i]
6 largest = l
7 else
8 largest = i
9 if r ≤ H and A[r] > A[largest]
10 largest = r
11
12 if largest ≠ iã// value of children is larger than that of i
13 swap A[i] and A[largest]
14 maxHeapify(A, largest) // call recursively
</pre>
<p>
The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner.
</p>
<pre>
1 buildMaxHeap(A)
2 for i = H/2 downto 1
3 maxHeapify(A, i)
</pre>
<H2>Input</H2>
<p>
In the first line, an integer $H$ is given. In the second line, $H$ integers which represent elements in the binary heap are given in order of node id (from $1$ to $H$).
</p>
<H2>Output</H2>
<p>
Print values of nodes in the max-heap in order of their id (from $1$ to $H$). <u>Print a single space character before each value.</u>
</p>
<H2>Constraint</H2>
<ul>
<li>$1 \leq H \leq 500,000$</li>
<li>$-2,000,000,000 \leq$ value of a node $\leq 2,000,000,000$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
10
4 1 3 2 16 9 10 14 8 7
</pre>
<H2>Sample Output 1</H2>
<pre>
16 14 10 8 7 9 3 2 4 1
</pre>
<br>
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p>
|
p02772 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.</p>
<p>According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:</p>
<ul>
<li>All even numbers written on the document are divisible by <var>3</var> or <var>5</var>.</li>
</ul>
<p>If the immigrant should be allowed entry according to the regulation, output <code>APPROVED</code>; otherwise, print <code>DENIED</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3>
<ul>
<li>The condition in the statement can be rephrased as "If <var>x</var> is an even number written on the document, <var>x</var> is divisible by <var>3</var> or <var>5</var>".
Here "<a href="https://en.wikipedia.org/wiki/Material_conditional">if</a>" and "<a href="https://en.wikipedia.org/wiki/Logical_disjunction">or</a>" are logical terms.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq A_i \leq 1000</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>\dots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If the immigrant should be allowed entry according to the regulation, print <code>APPROVED</code>; otherwise, print <code>DENIED</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
6 7 9 10 31
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>APPROVED
</pre>
<p>The even numbers written on the document are <var>6</var> and <var>10</var>.</p>
<p>All of them are divisible by <var>3</var> or <var>5</var>, so the immigrant should be allowed entry.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
28 27 24
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>DENIED
</pre>
<p><var>28</var> violates the condition, so the immigrant should not be allowed entry.</p></section>
</div>
</span> |
p03860 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is going to open a contest named "AtCoder <var>s</var> Contest".
Here, <var>s</var> is a string of length <var>1</var> or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.</p>
<p>Snuke has decided to abbreviate the name of the contest as "A<var>x</var>C".
Here, <var>x</var> is the uppercase English letter at the beginning of <var>s</var>.</p>
<p>Given the name of the contest, print the abbreviation of the name.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The length of <var>s</var> is between <var>1</var> and <var>100</var>, inclusive.</li>
<li>The first character in <var>s</var> is an uppercase English letter.</li>
<li>The second and subsequent characters in <var>s</var> are lowercase English letters.</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>AtCoder <var>s</var> Contest
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the abbreviation of the name of the contest.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>AtCoder Beginner Contest
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>ABC
</pre>
<p>The contest in which you are participating now.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>AtCoder Snuke Contest
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>ASC
</pre>
<p>This contest does not actually exist.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>AtCoder X Contest
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>AXC
</pre></section>
</div>
</span> |
p02322 | <h1>Knapsack Problem with Limitations II</h1>
<p>You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$.</p>
<p>You want to find a subset of items to put such that:</p>
<ul>
<li>The total value of the items is as large as possible.</li>
<li>The items have combined weight at most $W$, that is capacity of the knapsack.</li>
<li>You can select at most $m_i$ items for $i$-th item.</li>
</ul>
<p>Find the maximum total value of items in the knapsack.</p>
<h2>Input</h2>
<pre>
$N$ $W$
$v_1$ $w_1$ $m_1$
$v_2$ $w_2$ $m_2$
:
$v_N$ $w_N$ $m_N$
</pre>
<p>The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given.</p>
<h2>Output</h2>
<p>Print the maximum total values of the items in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le N \le 50$</li>
<li>$1 \le v_i \le 50$</li>
<li>$1 \le w_i \le 10^9$</li>
<li>$1 \le m_i \le 10^9$</li>
<li>$1 \le W \le 10^9$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4 8
4 3 2
2 1 1
1 2 4
3 2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
12
</pre>
<h2>Sample Input 2</h2>
<pre>
2 100
1 1 100
2 1 50
</pre>
<h2>Sample Output 2</h2>
<pre>
150
</pre>
<h2>Sample Input 3</h2>
<pre>
5 1000000000
3 5 1000000000
7 6 1000000000
4 4 1000000000
6 8 1000000000
2 5 1000000000
</pre>
<h2>Sample Output 3</h2>
<pre>
1166666666
</pre>
|
p03499 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a rooted tree with <var>N+1</var> vertices.
The vertices are numbered <var>0</var> through <var>N</var>, and Vertex <var>0</var> is the root of the tree.
The parent of Vertex <var>i</var> <var>(1 \leq i \leq N)</var> is Vertex <var>p_i</var>.</p>
<p>Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them.
The play begins with placing one marble on some of the vertices, then proceeds as follows:</p>
<ol>
<li>If there is a marble on Vertex <var>0</var>, move the marble into the box.</li>
<li>Move each marble from the vertex to its parent (all at once).</li>
<li>For each vertex occupied by two or more marbles, remove all the marbles from the vertex.</li>
<li>If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play.</li>
</ol>
<p>There are <var>2^{N+1}</var> ways to place marbles on some of the vertices.
For each of them, find <strong>the number of marbles that will be in the box at the end of the play</strong>, and compute the sum of all those numbers modulo <var>1,000,000,007</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N < 2 \times 10^{5}</var></li>
<li><var>0 \leq p_i < i</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3><ul>
<li>In the test set worth <var>400</var> points, <var>N < 2{,}000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_{N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>When we place a marble on both Vertex <var>1</var> and <var>2</var>, there will be multiple marbles on Vertex <var>0</var> by step 2. In such a case, these marbles will be removed instead of being moved to the box.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
0 1 1 0 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>96
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>31
0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>730395550
</pre>
<p>Be sure to compute the sum modulo <var>1,000,000,007</var>.</p></section>
</div>
</span> |
p03163 | <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> items, numbered <var>1, 2, \ldots, N</var>.
For each <var>i</var> (<var>1 \leq i \leq N</var>), Item <var>i</var> has a weight of <var>w_i</var> and a value of <var>v_i</var>.</p>
<p>Taro has decided to choose some of the <var>N</var> items and carry them home in a knapsack.
The capacity of the knapsack is <var>W</var>, which means that the sum of the weights of items taken must be at most <var>W</var>.</p>
<p>Find the maximum possible sum of the values of items that Taro takes home.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq W \leq 10^5</var></li>
<li><var>1 \leq w_i \leq W</var></li>
<li><var>1 \leq v_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>W</var>
<var>w_1</var> <var>v_1</var>
<var>w_2</var> <var>v_2</var>
<var>:</var>
<var>w_N</var> <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the values of items that Taro takes home.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 8
3 30
4 50
5 60
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>90
</pre>
<p>Items <var>1</var> and <var>3</var> should be taken.
Then, the sum of the weights is <var>3 + 5 = 8</var>, and the sum of the values is <var>30 + 60 = 90</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5000000000
</pre>
<p>The answer may not fit into a 32-bit integer type.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 15
6 5
5 6
6 4
6 6
3 5
7 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>17
</pre>
<p>Items <var>2, 4</var> and <var>5</var> should be taken.
Then, the sum of the weights is <var>5 + 6 + 3 = 14</var>, and the sum of the values is <var>6 + 6 + 5 = 17</var>.</p></section>
</div>
</span> |
p03533 | <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>.</p>
<p>Takahashi can insert the character <code>A</code> at any position in this string any number of times.</p>
<p>Can he change <var>S</var> into <code>AKIHABARA</code>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 50</var></li>
<li><var>S</var> consists of uppercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to change <var>S</var> into <code>AKIHABARA</code>, print <code>YES</code>; otherwise, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>KIHBR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>Insert one <code>A</code> at each of the four positions: the beginning, immediately after <code>H</code>, immediately after <code>B</code> and the end.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>AKIBAHARA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>The correct spell is <code>AKIHABARA</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>AAKIAHBAARA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre></section>
</div>
</span> |
p00036 |
<H1>å¹³é¢äžã®å³åœ¢</H1>
<p>
瞊 8ãæšª 8 ã®ãã¹ãããªãå³ 1 ã®ãããªå¹³é¢ããããŸãã
<br>
<center>
<table cellspacing=0 cellpadding=0>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
</table>
<br>
<table>
<tr><td>å³ïŒ</td></tr>
</table>
</center>
<br>
<p>
ãã®å¹³é¢äžã«ã以äžã® A ãã G ã®å³åœ¢ã®ã©ãããäžã€ã ã眮ãããŠããŸãã
</p>
<center>
<table>
<tr>
<td width=100>
<table><tr><td>A</td></tr></table>
<table cellspacing=0 cellpadding=0>
<tr><td>â </td><td>â </td><td></td><td></td></tr>
<tr><td>â </td><td>â </td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
</td>
<td width=100>
<table><tr><td>B</td></tr></table>
<table cellspacing=0 cellpadding=0>
<tr><td></td><td>â </td><td></td><td></td></tr>
<tr><td></td><td>â </td><td></td><td></td></tr>
<tr><td></td><td>â </td><td></td><td></td></tr>
<tr><td></td><td>â </td><td></td><td></td></tr>
</table>
</td>
<td width=100>
<table><tr><td>C</td></tr></table>
<table cellspacing=0 cellpadding=0>
<tr><td>â </td><td>â </td><td>â </td><td>â </td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
</td>
</tr>
</table>
<br/>
<table>
<tr>
<td width=100>
<table><tr><td>D</td></tr></table>
<table cellspacing=0 cellpadding=0>
<tr><td></td><td>â </td><td></td><td></td></tr>
<tr><td>â </td><td>â </td><td></td><td></td></tr>
<tr><td>â </td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
</td>
<td width=100>
<table><tr><td>E</td></tr></table>
<table cellspacing=0 cellpadding=0>
<tr><td>â </td><td>â </td><td></td><td></td></tr>
<tr><td></td><td>â </td><td>â </td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
</td>
<td width=100>
<table><tr><td>F</td></tr></table>
<table cellspacing=0 cellpadding=0>
<tr><td>â </td><td></td><td></td><td></td></tr>
<tr><td>â </td><td>â </td><td></td><td></td></tr>
<tr><td></td><td>â </td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
</td>
<td width=100>
<table><tr><td>G</td></tr></table>
<table cellspacing=0 cellpadding=0>
<tr><td></td><td>â </td><td>â </td><td></td></tr>
<tr><td>â </td><td>â </td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
</td>
</tr>
</table>
</center>
<br/>
<p>ããšãã°ã次ã®å³ 2 ã®äŸã§ã¯ E ã®å³åœ¢ã眮ãããŠããŸãã
<br/>
<center>
<table>
<tr>
<td>
<table cellspacing=0 cellpadding=0>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â </td><td>â </td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â </td><td>â </td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
<tr><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td><td>â¡</td></tr>
</table>
</td>
</tr>
</table>
<br>
<table>
<tr>
<td>å³ïŒ</td>
</tr>
</table>
</center>
<br>
<p>
å¹³é¢ã®äžã§å³åœ¢ãå ããŠãããã¹ã 1ãå ããŠããªããã¹ã 0 ã§è¡šçŸããæ°åã®åãèªã¿èŸŒãã§ã眮ãããŠããå³åœ¢ã®çš®é¡ïŒAãGïŒãåºåããããã°ã©ã ãäœæããŠãã ããã
<p>
ãã ããã²ãšã€ã®å¹³é¢ã«çœ®ãããŠããå³åœ¢ã¯å¿
ãïŒã€ã§ãè€æ°ã®å³åœ¢ã眮ãããŠããããšã¯ãããŸããããŸããAãG ã§è¡šãããå³åœ¢ä»¥å€ã®ãã®ã眮ãããŠããããšã¯ãããŸããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸãã
</p>
<p>
ïŒã€ã®ããŒã¿ã»ãããšããŠãå¹³é¢ã®äžã§å³åœ¢ãå ããŠãããã¹ã 1ãå ããŠããªããã¹ã 0 ã§è¡šçŸãã 8 æåãããªã 8 ã€ã®æååãäžããããŸããäŸãã°ãå³ 2 ã«å¯Ÿå¿ããæååã®äžŠã³ã¯æ¬¡ã®ããã«ãªããŸãã
</p>
<center>
<table>
<tr>
<td>
<table cellspacing=0 cellpadding=0>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
</table>
</tr>
</table>
</center>
<br>
<p>
ããŒã¿ã»ããã®éã¯ïŒã€ã®ç©ºè¡ã§åºåãããŠããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ãå¹³é¢ã«äžããããå³åœ¢ã®çš®é¡ïŒAãG ã®ããããïŒãïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
00000000
00000000
01100000
00110000
00000000
00000000
00000000
00000000
00011110
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00000000
00110000
00110000
00000000
00000000
00000000
00000000
</pre>
<H2>Output for the Sample Input</H2>
<pre>
E
C
A
</pre>
|
p00466 |
<H1>ã¬ã·ãŒã </H1>
<h2>åé¡</h2>
<p>
倪éåã¯10åã®æ¬ã賌å
¥ããïŒ
åŸæ¥ïŒ
ã¬ã·ãŒããããšã«äŸ¡æ Œã調ã¹ãããšãããïŒ
ã¬ã·ãŒãã«ã¯æ±ããããïŒ
ããæ¬ã®äŸ¡æ Œãèªã¿åããªãã£ãïŒ
ãã®æ¬ã®äŸ¡æ ŒãïŒ
10åã®ç·é¡ãšä»ã®9åã®äŸ¡æ Œããèšç®ããããšã«ããïŒ
</p>
<p>
äŸ¡æ Œãèªã¿åããªãã£ãæ¬ã®äŸ¡æ Œãåºåããããã°ã©ã ãæžãïŒ
ãªãïŒæ¬ã®äŸ¡æ Œã¯ãã¹ãŠæ£ã®æŽæ°ã§ããïŒ
ãŸãïŒæ¶è²»çšãèæ
®ããå¿
èŠã¯ãªãïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
åããŒã¿ã»ããã¯10è¡ãããªãïŒ1è¡ã«1ã€ãã€æ£ã®æŽæ°ãæžãããŠããïŒ
1è¡ç®ã®æŽæ°ã¯10åã®ç·é¡ãïŒ
2è¡ç®ãã10è¡ç®ã®æŽæ°ã¯èªã¿åããäŸ¡æ Œã衚ããŠããïŒ
ãªãïŒ10åã®ç·é¡ã¯10000以äžã§ããïŒ
</p>
<p>
ç·é¡ ã 0 ã®ãšãå
¥åã®çµäºã瀺ã.ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h2> åºå</h2>
<p>
ããŒã¿ã»ããããšã«ïŒäŸ¡æ Œãèªã¿åããªãã£ãæ¬ã®äŸ¡æ Œã1 è¡ã«åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
9850
1050
800
420
380
600
820
2400
1800
980
0
</pre>
<h3>åºåäŸ</h3>
<pre>
600
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02908 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has permutations <var>(P_0,P_1,\cdots,P_{N-1})</var> and <var>(Q_0,Q_1,\cdots,Q_{N-1})</var> of <var>(0,1,\cdots,N-1)</var>.</p>
<p>Now, he will make new permutations <var>A</var> and <var>B</var> of <var>(0,1,\cdots,N-1)</var>, under the following conditions:</p>
<ul>
<li>For each <var>i</var> (<var>0 \leq i \leq N-1</var>), <var>A_i</var> should be <var>i</var> or <var>P_i</var>.</li>
<li>For each <var>i</var> (<var>0 \leq i \leq N-1</var>), <var>B_i</var> should be <var>i</var> or <var>Q_i</var>.</li>
</ul>
<p>Let us define the distance of permutations <var>A</var> and <var>B</var> as the number of indices <var>i</var> such that <var>A_i \neq B_i</var>.
Find the maximum possible distance of <var>A</var> and <var>B</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100000</var></li>
<li><var>0 \leq P_i \leq N-1</var></li>
<li><var>P_0,P_1,\cdots,P_{N-1}</var> are all different.</li>
<li><var>0 \leq Q_i \leq N-1</var></li>
<li><var>Q_0,Q_1,\cdots,Q_{N-1}</var> are all different.</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>P_0</var> <var>P_1</var> <var>\cdots</var> <var>P_{N-1}</var>
<var>Q_0</var> <var>Q_1</var> <var>\cdots</var> <var>Q_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible distance of <var>A</var> and <var>B</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
2 1 3 0
0 2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>For example, if we make <var>A=(0,1,2,3)</var> and <var>B=(0,2,3,1)</var>, the distance will be <var>3</var>, which is the maximum result possible.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
0 4 5 3 7 8 2 1 9 6
3 8 5 6 4 0 2 1 7 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>32
22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13
22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>28
</pre></section>
</div>
</span> |
p00935 |
<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
Decimal Sequences</h2>
<p>
Hanako learned the conjecture that all the non-negative integers appear in the infinite digit sequence of the decimal representation of $\pi$ = 3.14159265..., the ratio of a circle's circumference to its diameter. After that, whenever she watches a sequence of digits, she tries to count up non-negative integers whose decimal representations appear as its subsequences.
</p>
<p>
For example, given a sequence "<span>3 0 1</span>", she finds representations of five non-negative integers 3, 0, 1, 30 and 301 that appear as its subsequences.
</p>
<p>
Your job is to write a program that, given a finite sequence of digits, outputs the smallest non-negative integer not appearing in the sequence. In the above example, 0 and 1 appear, but 2 does not. So, 2 should be the answer.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case.<br>
<br>
$n$<br>
$d_1$ $d_2$ ... $d_n$<br>
<br>
$n$ is a positive integer that indicates the number of digits. Each of $d_k$'s $(k = 1, ... , n)$ is a digit. There is a space or a newline between $d_k$ and $d_{k+1}$ $(k = 1, ..., n - 1)$.
</p>
<p>
You can assume that $1 \leq n \leq 1000$.
</p>
<h3>Output</h3>
<p>
Print the smallest non-negative integer not appearing in the sequence.
</p>
<h3>Sample Input 1</h3>
<pre>3
3 0 1</pre>
<h3>Sample Output 1</h3>
<pre>2</pre>
<h3>Sample Input 2</h3>
<pre>11
9 8 7 6 5 4 3 2 1 1 0</pre>
<h3>Sample Output 2</h3>
<pre>12</pre>
<h3>Sample Input 3</h3>
<pre>10
9 0 8 7 6 5 4 3 2 1</pre>
<h3>Sample Output 3</h3>
<pre>10</pre>
<h3>Sample Input 4</h3>
<pre>100
3 6 7 5 3 5 6 2 9 1 2 7 0 9 3 6 0 6 2
6 1 8 7 9 2 0 2 3 7 5 9 2 2 8 9 7 3 6
1 2 9 3 1 9 4 7 8 4 5 0 3 6 1 0 6 3 2
0 6 1 5 5 4 7 6 5 6 9 3 7 4 5 2 5 4 7
4 4 3 0 7 8 6 8 8 4 3 1 4 9 2 0 6 8 9
2 6 6 4 9</pre>
<h3>Sample Output 4</h3>
<pre>11</pre>
<h3>Sample Input 5</h3>
<pre>100
7 2 7 5 4 7 4 4 5 8 1 5 7 7 0 5 6 2 0
4 3 4 1 1 0 6 1 6 6 2 1 7 9 2 4 6 9 3
6 2 8 0 5 9 7 6 3 1 4 9 1 9 1 2 6 4 2
9 7 8 3 9 5 5 2 3 3 8 4 0 6 8 2 5 5 0
6 7 1 8 5 1 4 8 1 3 7 3 3 5 3 0 6 0 6
5 3 2 2 2</pre>
<h3>Sample Output 5</h3>
<pre>86</pre>
<h3>Sample Input 6</h3>
<pre>1
3</pre>
<h3>Sample Output 6</h3>
<pre>0</pre>
|
p01627 |
<h1>Problem A: 鿥18ãã£ã· 2013</h1>
<h2>Problem Statement</h2>
<p>
äŒæŽ¥å宿ã«åå äºå®ã®é«æ§»ããã¯ãå®¶ãè²§ä¹ã§ããŸããéãæã£ãŠããªãããã®ããã鿥18ãã£ã·ã䜿çšããŠããéãç¯çŽããããšããŠããã18ãã£ã·ã¯ããã1æã ãã§ãéè¡åè»ãªãã°1æ¥äžä¹ãæŸé¡ãæ¹æã®åºå
¥ããèªç±ãšããåªããã®ã§ããïŒè©³ããå©çšã«ãŒã«ã«ã€ããŠã¯çç¥ïŒã
</p>
<p>
18ãã£ã·ã®é
åã¯ãä¹ãæããè¡ãé§
ã§ã空ããŠããæéã䜿ã£ãŠããåœå°ã®ãåç£çãèŠãŠãŸãããç¹ã§ããã圌女ã¯ããã£ããã®æ©äŒãªã®ã§ãæ
ã®éäžã§ãããããªé§
ãèŠãŠåããããšèããŠããããã ããæ¬¡ã®é»è»ã«ä¹ãé
ããŠã¯å°ããããä¹ãæãé§
ã«å°çããæå»ãããä¹ãæãé§
ãåºçºããæå»ãŸã§ã®éãTå以äžã®ãšãã ãããã®é§
ãèŠãŠåãããšã«ããã
</p>
<p>
髿§»ããã®18ãã£ã·ã䜿ã£ãä¹ãæãèšç»ãäžããããã®ã§ãèŠãŠåããé§
ã®ååãšæéãåºåãããäžçªæåã«åºçºããé§
ãšãäžçªæåŸã«å°çããé§
ã¯ãèŠãŠåãåè£ã«ã¯å
¥ããªãããšã«æ³šæããŠã»ããã
</p>
<h2>Input</h2>
åããŒã¿ã»ããã¯ã以äžã®åœ¢åŒã§å
¥åãããã
<pre>N T
st_time1 st_name1 ar_time1 ar_name1
st_time2 st_name2 ar_time2 ar_name2
...
st_timeN st_nameN ar_timeN ar_nameN
</pre>
<p>
Nã¯åè»ã«ä¹è»ããåæ°ã衚ããæŽæ°ãTã¯ä¹ãæãé§
ãèŠãŠåãã蚱容æé(å)ã衚ããæŽæ°ã§ãããç¶ããŠãNè¡ã«ããã£ãŠãåè»ã®åºçºãšå°çã®ãã¢ãäžãããããåè¡ã®å
¥åã¯ãst_timeiã®æå»ã¡ããã©ã«st_nameiã®é§
ã髿§»ããã®ä¹ãåè»ãåºçºããããšããar_timeiã®æå»ã¡ããã©ã«ar_nameiã®é§
ã«é«æ§»ããã®ä¹ãåè»ãå°çããããšãæå³ããã
</p>
<h2>Constraints</h2>
<ul>
<li>1 <= N <= 10</li>
<li>1 <= T <= 180</li>
<li>st_timeiãar_timei</li>
<ul>
<li>"HH:MM"ã«ãã衚ããããHHã«ã¯00以äž23以äžãMMã«ã¯00以äž59以äžã®2æ¡ã®æ°å€ãå
¥ããHHãæéã§ãMMãåã§ããã</li>
<li>00:00 <= st_time1 < ar_time1 < st_time2 < ar_time2 < ... < st_timeN < ar_timeN <= 23:59</li>
</ul>
<li>st_nameiãar_namei</li>
<ul>
<li>ã¢ã«ãã¡ããã倧æåã»å°æåã«ãã衚ããããæååã§ããã</li>
<li>1 <= æååã®é·ã <= 50</li>
<li>içªç®ã®å°çé§
ar_nameiãšãi+1çªç®ã®åºçºé§
st_namei+1ã®ååã¯äžèŽããã</li>
<li>st_name1ãar_nameNãä¹ãæãã®é§
ã®ååã¯ãããããç°ãªãæååã§ããã</li>
</ul>
</ul>
<h2>Output</h2>
<p>
åããŒã¿ã»ããã«ã€ããŠã以äžã®åœ¢åŒã§åºåãè¡ãã
</p>
<pre>M
stay_name1 stay_time1
stay_name2 stay_time2
...
stay_nameM stay_timeM
</pre>
<p>
MïŒ0 <= M <= N - 1ïŒã¯ãèŠãŠåããé§
ã®æ°ã衚ããæŽæ°ã§ãããç¶ããŠãMè¡ã«ããã£ãŠãèŠãŠåããé§
ã®ãªã¹ããæå»ã®æé ã«åºåãããåè¡ã¯ãstay_nameiã®é§
ãstay_timeiåéèŠãŠåããããšãæå³ããã
</p>
<h2>Sample Input 1</h2>
<pre>8 24
05:30 Kyoto 06:37 Maibara
06:50 Maibara 07:36 Tsuruga
07:42 Tsuruga 10:03 Kanazawa
10:58 Kanazawa 12:07 Toyama
12:15 Toyama 14:12 Naoetsu
14:29 Naoetsu 15:57 Nagaoka
16:11 Nagaoka 17:14 Niitsu
17:38 Niitsu 20:06 AizuWakamatsu
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>2
Kanazawa 55
Niitsu 24
</pre>
<p>Kanazawaé§
ã¯ã10:03ã«å°çã10:58ã«åºçºãããããä¹ãæãã«55åã®ç©ºãæéããããNiitsué§
ã¯ã17:14ã«å°çã17:38ã«åºçºãããããä¹ãæãã«24åã®ç©ºãæéããããã©ã¡ãããå
¥åã§æå®ããã24å以äžã®ç©ºãæéããããããåºåããã
</p>
<h2>Sample Input 2</h2>
<pre>1 180
10:44 Koriyama 11:52 AizuWakamatsu
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>0
</pre>
<p>
ä¹ãæãé§
ã¯1ã€ããªãããã0ãšåºåããã
</p> |
p01277 |
<H1><font color="#000">Problem E:</font> Symmetry</H1>
<p>
Open Binary and Object Group organizes a programming contest every year. Mr. Hex belongs to this
group and joins the judge team of the contest. This year, he created a geometric problem with its solution
for the contest. The problem required a set of points forming a line-symmetric polygon for the input.
Preparing the input for this problem was also his task. The input was expected to cover all edge cases, so
he spent much time and attention to make them satisfactory.
</p>
<p>
However, since he worked with lots of care and for a long time, he got tired before he finished. So He
might have made mistakes - there might be polygons not meeting the condition. It was not reasonable to
prepare the input again from scratch. The judge team thus decided to find all line-asymmetric polygons
in his input and fix them as soon as possible. They asked a programmer, just you, to write a program to
find incorrect polygons.
</p>
<p>
You can assume the following:
</p>
<ul>
<li> Edges of the polygon must not cross or touch each other except for the end points of adjacent
edges.</li>
<li> It is acceptable for the polygon to have adjacent three vertexes on a line, but in such a case, there
must be the vertex symmetric to each of them.</li>
</ul>
<H2>Input</H2>
<!--
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
-->
<p>
The input consists of a set of points in the following format.
</p>
<p>
<i>N</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br>
<i>x</i><sub>2</sub> <i>y</i><sub>2</sub><br>
...<br>
<i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub><br>
</p>
<p>
The first line of the input contains an integer <i>N</i> (3 ≤ <i>N</i> ≤ 1000), which denotes the number of points.
The following <i>N</i> lines describe each point. The <i>i</i>-th line contains two integers <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub> (-10000 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> ≤ 10000), which denote the coordinates of the <i>i</i>-th point.
</p>
<p>
Note that, although the points are the vertexes of a polygon, they are given in an artibrary order, not
necessarily clockwise or counterclockwise.
</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>
Output "<span>Yes</span>" in a line if the points can form a line-symmetric polygon, otherwise output "<span>No</span>".
</p>
<H2>Sample Input 1</H2>
<pre>
4
0 1
1 0
0 0
1 1
</pre>
<H2>Sample Output 1</H2>
<pre>
Yes
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
4
0 1
1 -1
0 0
1 1
</pre>
<H2>Sample Output 2</H2>
<pre>
No
</pre>
<br/>
<H2>Sample Input 3</H2>
<pre>
9
-1 1
0 1
1 1
-1 0
0 0
1 0
-1 -1
0 -1
1 -1
</pre>
<H2>Sample Output 3</H2>
<pre>
No
</pre>
<br/>
<H2>Sample Input 4</H2>
<pre>
3
-1 -1
0 0
1 1
</pre>
<H2>Sample Output 4</H2>
<pre>
No
</pre>
<br/>
<H2>Sample Input 5</H2>
<pre>
4
0 2
0 0
-1 0
1 0
</pre>
<H2>Sample Output 5</H2>
<pre>
Yes
</pre> |
p00870 |
<H1><font color="#000">Problem G:</font> Search of Concatenated Strings</H1>
<p>
The amount of information on the World Wide Web is growing quite rapidly. In this information
explosion age, we must survive by accessing only the Web pages containing information relevant
to our own needs. One of the key technologies for this purpose is keyword search. By using
well-known search engines, we can easily access those pages containing useful information about
the topic we want to know.
</p>
<p>
There are many variations in keyword search problems. If a single string is searched in a given
text, the problem is quite easy. If the pattern to be searched consists of multiple strings, or
is given by some powerful notation such as regular expressions, the task requires elaborate
algorithms to accomplish efficiently.
</p>
<p>
In our problem, a number of strings (element strings) are given, but they are not directly
searched for. Concatenations of all the element strings in any order are the targets of the search
here.
</p>
<p>
For example, consider three element strings aa, b and ccc are given. In this case, the following
six concatenated strings are the targets of the search, i.e. they should be searched in the text.
</p>
<pre align="center">
aabccc
aacccb
baaccc
bcccaa
cccaab
cccbaa
</pre>
<p>
The text may contain several occurrences of these strings. You are requested to count the
number of occurrences of these strings, or speaking more precisely, the number of positions of
occurrences in the text.
</p>
<p>
Two or more concatenated strings may be identical. In such cases, it is necessary to consider
subtle aspects of the above problem statement. For example, if two element strings are x and
xx, the string xxx is an occurrence of both the concatenation of x and xx and that of xx and x.
Since the number of positions of occurrences should be counted, this case is counted as one, not
two.
</p>
<p>
Two occurrences may overlap. For example, the string xxxx has occurrences of the concatenation
xxx in two different positions. This case is counted as two.
</p>
<H2>Input</H2>
<p>
The input consists of a number of datasets, each giving a set of element strings and a text. The
format of a dataset is as follows.
</p>
<pre>
<i>n m</i>
<i>e</i><sub>1</sub>
<i>e</i><sub>2</sub>
.
.
.
<i>e</i><sub>n</sub>
<i>t</i><sub>1</sub>
<i>t</i><sub>2</sub>
.
.
.
<i>t</i><sub>m</sub>
</pre>
<p>
The first line contains two integers separated by a space. <i>n</i> is the number of element strings. <i>m</i>
is the number of lines used to represent the text. <i>n</i> is between 1 and 12, inclusive.
</p>
<p>
Each of the following n lines gives an element string. The length (number of characters) of an
element string is between 1 and 20, inclusive.
The last <i>m</i> lines as a whole give the text. Since it is not desirable to have a very long line, the
text is separated into m lines by newlines, but these newlines should be ignored. They are not
parts of the text. The length of each of these lines (not including the newline) is between 1 and
100, inclusive. The length of the text is between 1 and 5000, inclusive.
</p>
<p>
The element strings and the text do not contain characters other than lowercase letters.
</p>
<p>
The end of the input is indicated by a line containing two zeros separated by a space.
</p>
<p>
<b>CAUTION!</b> Although the sample input contains only small datasets, note that 12! × 5000 is far larger than 2<sup>31</sup> .
</p>
<H2>Output</H2>
<p>
For each dataset in the input, one line containing the number of matched positions should be
output. An output line should not contain extra characters.
</p>
<H2>Sample Input</H2>
<pre>
3 1
aa
b
ccc
aabccczbaacccbaazaabbcccaa
3 1
a
b
c
cbbcbcbabaacabccaccbaacbccbcaaaccccbcbcbbcacbaacccaccbbcaacbbabbabaccc
3 4
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
12
197
</pre>
|
p01762 |
<h1>C : Pruning / æåã</h1>
<h1>Problem</h1>
<p>ãšã«ãããã€ãããã¥ãåã®äœãã§ããå°åã¯ä»å¹Žçæã§ãã£ãã ããã«ãå®¶ã®åºã«ã¯ 1 æ¬ã®æšãçããŠãããæ¯æ¥ãããŸãã鳎ãèãæããå¢å¹
ãããŠãããããªæ°ãããã</p>
<p>åºã®æšã¯ããŸãã«ã°ã©ãçè«ã§ãããšããã®æšã®ãããªåœ¢ãããŠããããã®æšã«ã¯ããããã®èãæ¢ãŸã£ãŠããã
èã¯ãå¿
ãæã®å
端(è)ãŸãã¯æã®åããç®(é ç¹)ã«æ¢ãŸãç¿æ§ãããã ãã ããæšã®æ ¹ã«ã¯ 1 å¹ãæ¢ãŸãããšã¯ãªãã
ãã®æšã®ããæ(蟺)ãåããšããããã空åŽ(æ ¹ãšå察åŽ)ã«ããèãå
šãŠé§é€ããããšãã§ããã
ãã ããæãåãããã«ã¯ããã®æã«å¿ããåŽåãå¿
èŠãšãªãã</p>
<p>(泚 : æ¬åŒ§å
ã®èšèã¯ã°ã©ãçè«ã®èšèã§çœ®ãæãããã®ã§ããã以éã¯å
šãŠã°ã©ãçè«ã®èšèã§è¡šçŸããããšã«ããã)</p>
<p>é«åºŠæ
å ±å瀟äŒãšãªã£ãçŸä»£ã«ãããŠã¯ã éšå±ã«å±
ãªããã«ããŠé ç¹ã«äœå¹ã®èããããã ãããŠå蟺ãåãã®ã«èŠããåŽåã調ã¹ãããšãåºæ¥ãã</p>
<p>ãã¥ãåã¯ãã®æ
å ±ãçšããŠã æšã«æ¢ãŸã£ãŠããå
šãŠã®èãé§é€ããã®ã«å¿
èŠãªæå°ã®åŽåã調ã¹ãããã°ã©ã ãæžãããšã«ããã</p>
<h1>Input</h1>
<p>å
¥åã¯æ¬¡ã®ãããªåœ¢åŒã§äžããããïŒ</p>
<p><em>N</em><br><em>C<sub>1</sub></em> ... <em>C<sub>N-1</sub></em><br><em>u<sub>0</sub></em> <em>v<sub>0</sub></em> <em>p<sub>0</sub></em><br>...<br><em>u<sub>N-2</sub></em> <em>v<sub>N-2</sub></em> <em>p<sub>N-2</sub></em></p>
<p><em>N</em> ã¯æšã«å«ãŸããé ç¹ã®æ°ã§ããã åé ç¹ã«ã¯ 0 ... <em>N</em> - 1 ã®çªå·ãæ¯ããã0çªç®ã®é ç¹ãæ ¹ãšããã <em>C<sub>1</sub></em> ... <em>C<sub>N-1</sub></em> ã¯ãåé ç¹ã«æ¢ãŸã£ãŠããèã®æ°ã§ããã <em>C<sub>i</sub></em> ã <em>i</em> çªç®ã®é ç¹ã«æ¢ãŸã£ãŠããèã®æ°ã§ããã æ ¹ã«ã¯ãèã¯1å¹ãæ¢ãŸã£ãŠããªãã 2 + <em>i</em> è¡ç®ã® <em>u<sub>i</sub></em>, <em>v<sub>i</sub></em>, <em>p<sub>i</sub></em> ã¯ãæšã«å«ãŸããèŸºã®æ
å ±ã§ããã<em>u<sub>i</sub></em>, <em>v<sub>i</sub></em> ã¯èŸºãçµã¶ 2 é ç¹ã®çªå·ã§ããã<em>p<sub>i</sub></em> ã¯ãã®èŸºãåãã®ã«å¿
èŠãªåŽåã§ããã</p>
<h1>Constraints</h1>
<ul>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
<li>äžããããã°ã©ãã¯æšã§ããã</li>
<li>2 ⊠<em>N</em> ⊠1,000</li>
<li>0 ⊠<em>C<sub>i</sub></em> ⊠1,000</li>
<li>0 ⊠<em>u<sub>i</sub></em> , <em>v<sub>i</sub></em> < <em>N</em></li>
<li>1 ⊠<em>p<sub>i</sub></em> ⊠1,000</li>
</ul>
<h1>Output</h1>
<p>èãå
šãŠé§é€ããããã«å¿
èŠãªæå°ã®åŽåã 1 è¡ã§åºåããã</p>
<h1>Samples</h1>
<h2>Sample Input 1</h2>
<pre>5
2 2 2 2
0 1 4
1 2 1
1 3 1
1 4 1</pre>
<h2>Sample Output 1</h2>
<pre>4</pre>
<p>é ç¹ 0 ãš 1 ãã€ãªã蟺ãåãã°ãå
šãŠã®èãé§é€ããããšãã§ããã</p>
<h2>Sample Input 2</h2>
<pre>5
0 2 2 2
0 1 4
1 2 1
1 3 1
1 4 1</pre>
<h2>Sample Output 2</h2>
<pre>3</pre>
<p>é ç¹ 1 ãš 2 ã 1 ãš 3 ã 1 ãš 4 ãã€ãªã蟺ã®3æ¬ãåãã°æå°ã®åŽåã§èãé§é€ããããšãã§ããã ãªããé ç¹ 0 ãš 1 ãã€ãªã蟺ãåãããšã§å
šãŠã®èãé§é€ããããšãã§ããããããã«ã¯ã³ã¹ãã 4 ããã£ãŠããŸãã</p> |
p01298 |
<H1><font color="#000">Problem F:</font> Water Tank</H1>
<p>
You built an apartment. The apartment has a water tank with a capacity of <i>L</i> in order to
store water for the residents. The tank works as a buffer between the water company and the
residents.
</p>
<p>
It is required to keep the tank "not empty" at least during use of water. A pump is used to
provide water into the tank. From the viewpoint of avoiding water shortage, a more powerful
pump is better, of course. But such powerful pumps are expensive. Thatâs the life.
</p>
<p>
You have a daily schedule table of water usage. It does not differ over days. The table is
composed of some schedules. Each schedule is indicated by the starting time of usage, the
ending time and the used volume per unit of time during the given time span.
</p>
<p>
All right, you can find the minimum required speed of providing water for days from the schedule
table. You are to write a program to compute it.
</p>
<p>
You can assume the following conditions.
</p>
<ul>
<li> A day consists of 86,400 units of time.</li>
<li> No schedule starts before the time 0 (the beginning of the day).</li>
<li> No schedule ends after the time 86,400 (the end of the day).</li>
<li> No two schedules overlap.</li>
<li> Water is not consumed without schedules.</li>
<li> The tank is full of water when the tank starts its work.</li>
</ul>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset corresponds to a schedule table in the following
format:
</p>
<p>
<i>N L</i><br>
<i>s</i><sub>1</sub> <i>t</i><sub>1</sub> <i>u</i><sub>1</sub><br>
...<br>
<i>s<sub>N</sub> t<sub>N</sub> u<sub>N</sub></i><br>
</p>
<p>
The first line of a dataset contains two integers <i>N</i> and <i>L</i> (1 ≤ <i>N</i> ≤ 86400, 1 ≤ <i>L</i> ≤ 10<sup>6</sup>), which
represents the number of schedule in the table and the capacity of the tank, respectively.
</p>
<p>
The following <i>N</i> lines describe the <i>N</i> schedules. The (<i>i</i> + 1)-th line of the dataset corresponds to the <i>i</i>-th schedule, which consists of three integers <i>s<sub>i</sub></i>, <i>t<sub>i</sub></i> and <i>u<sub>i</sub></i> . The first two integers <i>s<sub>i</sub></i> and <i>t<sub>i</sub></i> indicate the starting time and the ending time of the schedule. The last integer <i>u<sub>i</sub></i>
(1 ≤ <i>u<sub>i</sub></i> ≤ 10<sup>6</sup> ) indicates the consumed volume per unit of time during the schedule. It is
guaranteed that 0 ≤ <i>s</i><sub>1</sub> < <i>t</i><sub>1</sub> ≤ <i>s</i><sub>2</sub> < <i>t</i><sub>2</sub> ≤ ... ≤ <i>s<sub>n</sub></i> < <i>t<sub>n</sub></i> ≤ 86400.
</p>
<p>
The input is terminated by a line with two zeros. This line should not be processed.
</p>
<H2>Output</H2>
<p>
For each case, print the minimum required amount of water per unit of time provided by the
pump in a line. The amount may be printed with an arbitrary number of digits after the decimal
point, but should not contain an absolute error greater than 10<sup>-6</sup>.
</p>
<H2>Sample Input</H2>
<pre>
1 100
0 86400 1
1 100
43200 86400 1
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1.000000
0.997685
</pre>
|
p01332 |
<h1><font color="#000">Problem L:</font> Problem L: 3ã€ã®ã·ã«ãšãã</h1>
<p>JAVA(Japan Aerospace Voyage Agency: æ¥æ¬å®å®é£è¡ç ç©¶æ©æ§)ã¯ãå®å®éçºäºæ¥ã®äžç°ãšããŠ2003å¹Žã«æ¢æ»æ©ãæã¡äžããã ãã®æ¢æ»æ©æã¡äžãã®ç®çã®äžã€ã«ãå°ææã€ã·ã«ã¯ã«æ¥è¿ãããã®è¡šé¢ç©è³ªã®ãµã³ãã«ãæ¡éããããšãããã æ§ã
ãªã¢ã¯ã·ãã³ãã«èŠèãããªããããæ¢æ»æ©ã¯ã€ã·ã«ã¯ã«å°éãããããŠã€ãã«2010幎ãå°çãžåž°éããã€ã·ã«ã¯ã®ãµã³ãã«è©Šæã®å
¥ã£ãã«ãã»ã«ãååããããšã«æåããã</p>
<p>æ±äº¬å€§åŠã忥ããJAVAã«å°±è·ãããããŸãåã¯ããã®è©Šæã®ç ç©¶ãæ
åœããŠããã äžå»ãæ©ã詊æã®åæãããããšããã§ãããããšãŠãæ
éãªãããŸãåã¯ãããã«ãã»ã«ã®äžã«å¶æŽãªãšã€ãªã¢ã³ãå
¥ã£ãŠããã倧å€ã§ãããšèããã ããã§ãã«ãã»ã«ãéããåã«Xç·ãçšããŠå
éšã®ç©è³ªã®åœ¢ç¶ã調ã¹ããšã€ãªã¢ã³ãå
¥ã£ãŠããªãããšã確èªããããšã«ããã ã«ãã»ã«ã«Xç·ãåœãŠããšãç©è³ªãååšããŠãããšããã¯çœè²ã«ãååšããŠããªããšããã¯é»è²ã«ãªã£ãåçãåŸãããã æ§ã
ãªè§åºŠããXç·ãåœãŠãŠåçãåŸãããšã«ãããå
éšã®ç©è³ªã®åœ¢ç¶ãç¹å®ããããšãã§ããã</p>
<p>ããããããã§ãŸãåé¡ãçããã æ£é¢ãããå³åŽé¢ãããäžé¢ããã®ïŒæã®åçãåŸããšããã§Xç·è£
眮ãæ
éããŠããŸã£ãã®ã§ããã ããã«ãïŒæã®åçã®çŸåã«ã倱æããæ¬æ¥é»è²ã«ãªãã¹ãéšåãäžéšçœè²ãšãªã£ãŠããŸã£ãå¯èœæ§ãããã ãã®ãŸãŸã§ã¯ç©è³ªã®åœ¢ç¶ãæ£ç¢ºã«ç¹å®ããããšã¯åºæ¥ãªããããäžã«ãšã€ãªã¢ã³ãå
¥ã£ãŠããªãããšã確èªã§ãããã«ãã»ã«ãéããããšãã§ããªãã</p>
<p>ç ç©¶ãç¶ããããã«ã¯ãXç·è£
眮ãè²·ãæãããããªãã®ã ããJAVAã«ã¯äºæ¥ä»åãã«ããäºç®åæžã®åœ±é¿ã§ãXç·è£
眮ãããã«è²·ãæããã ãã®ãéããªãã ããã§ãããŸãåã¯æ¥å¹ŽåºŠã®äºç®ãå¢ãããŠãããããã®ãéã§æ°ããXç·è£
眮ãè²·ãããšãèããã ãã¡ãããäºç®ã¯ç°¡åã«ã¯å¢ããªããããæ¢æ»æ©ã®ææãæå€§éã«ã¢ããŒã«ããå¿
èŠãããã ã«ãã»ã«äžã«å€§ããªç©è³ªãå«ãŸããŠããã»ã©ææã匷ãã¢ããŒã«ããããšãã§ãããããç©è³ªãåãããæå€§äœç©ãèšç®ããããšã«ããã</p>
<p>ïŒæã®Xç·åçãšççŸããªããããªå
éšã®ç©è³ªã®åœ¢ç¶ã®ãã¡ã§ãäœç©ãæå€§ã§ãããã®ãæ±ãããã®äœç©ãåºåããã
</p>
<h2>Input</h2>
<p>åXç·åçã®çœè²ãšé»è²ã®å¢çã¯äžã€ã®å€è§åœ¢ãããªãã å€è§åœ¢ã¯åžãšã¯éããããŸãèªå·±äº€å·®ã¯ããªãã å€è§åœ¢ã®å
åŽãçœè²ãå€åŽãé»è²ã§ããã</p>
<p>å
¥åã®åœ¢åŒã¯ä»¥äžã®ããã§ããã</p>
<pre>n<sub>x</sub>
y<sub>1</sub> z<sub>1</sub>
y<sub>2</sub> z<sub>2</sub>
...
y<sub>n<sub>x</sub></sub> z<sub>n<sub>x</sub></sub>
n<sub>y</sub>
z<sub>1</sub> x<sub>1</sub>
z<sub>2</sub> x<sub>2</sub>
...
z<sub>n<sub>y</sub></sub> x<sub>n<sub>y</sub></sub>
n<sub>z</sub>
x<sub>1</sub> y<sub>1</sub>
x<sub>2</sub> y<sub>2</sub>
...
x<sub>n<sub>z</sub></sub> y<sub>n<sub>z</sub></sub></pre>
<p>n<sub>x</sub>, n<sub>y</sub>, n<sub>z</sub> ã¯ãããããæ£é¢ã»å³åŽé¢ã»äžé¢ããã®Xç·åçã«å¯Ÿå¿ããå€è§åœ¢ã®é ç¹æ°ã§ããã åé ç¹æ°ã¯3以äž20以äžã§ããã ç¶ã n è¡ã«ã¯å€è§åœ¢ã®é ç¹ã®åº§æšãåæèšåãã«äžããããã é ç¹ã®åº§æšã¯0以äž300以äžã®æŽæ°ã§ããã</p>
<p>ãŸãã座æšè»žã¯ã«ãã»ã«ã®äžå¿ããæ£é¢æ¹åã«x軞ããå³åŽé¢æ¹åã«y軞ããäžé¢æ¹åã«z軞ãåã£ãŠããã
</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_3silhouettes"></center>
<h2>Output</h2>
<p>ïŒæã®Xç·åçãšççŸããªããããªç©è³ªã®æå€§äœç©ãäžè¡ã«åºåããã åºåããå€ã¯10<sup>-3</sup>以äžã®èª€å·®ãå«ãã§ããŠãæ§ããªããå€ã¯å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãæ§ããªãã
</p>
<h2>Notes on Test Cases</h2>
<p>
äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã
</p>
<p>
n<sub>x</sub>, n<sub>y</sub>, n<sub>z</sub> ããã¹ãŠ 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã
</p>
<!--
<h2>Sample Input 1</h2>
<pre>4
0 0
100 0
100 100
0 100
4
0 0
100 0
100 100
0 100
4
0 0
100 0
100 100
0 100
</pre>
<h2>Output for Sample Input 1</h2>
<pre>1000000.0000
</pre>
<h2>Sample Input 2</h2>
<pre>3
0 0
100 0
0 100
3
0 0
100 0
0 100
3
0 0
100 0
0 100
</pre>
<h2>Output for Sample Input 2</h2>
<pre>250000.0000
</pre>
<h2>Sample Input 3</h2>
<pre>5
0 0
200 0
200 200
100 100
0 200
5
0 0
200 0
100 100
200 200
0 200
4
0 0
200 0
200 200
0 200
</pre>
<h2>Output for Sample Input 3</h2>
<pre>5333333.3333
</pre>
-->
<h2>Sample Input</h2>
<pre>
4
0 0
100 0
100 100
0 100
4
0 0
100 0
100 100
0 100
4
0 0
100 0
100 100
0 100
3
0 0
100 0
0 100
3
0 0
100 0
0 100
3
0 0
100 0
0 100
5
0 0
200 0
200 200
100 100
0 200
5
0 0
200 0
100 100
200 200
0 200
4
0 0
200 0
200 200
0 200
0
0
0
</pre>
<h2>Output for Sample Input</h2>
<pre>
1000000.0000
250000.0000
5333333.3333
</pre>
|
p00173 |
<H1>ãåã屿·</H1>
<p>
äŒæŽ¥åŠåé«çåŠæ ¡ã§ã¯ãæ¯å¹ŽåŠåç¥ããããªã£ãŠããŸãããã®äžã§ãäžçªäººæ°ã¯ãåã屿·ã§ããäžçªäººæ°ã®çç±ã¯ããåã屿·ããããªãã¯ã©ã¹ã 1ã¯ã©ã¹ã 2ã¯ã©ã¹ã§ã¯ãªãã9ã¯ã©ã¹ããåã屿·ããããªãããšã§ããããããã工倫ããããšããããããããåæ§çãªãåã屿·ã«ãªã£ãŠããŸãããã®ãããæè¿ã§ã¯è¿é£ããå€ãã®æ¥å Žè
ã蚪ããŸãã
</p>
<p>
ããã§ãåŠåç¥å®è¡å§å¡äŒã§ã¯ããåã屿·ã®å
¥å Žæéãäžè¡šã®ããã«æ ¡å
ã§çµ±äžããããã«ããšã¥ãåã¯ã©ã¹ããšã«å
¥å Žè
ç·æ°ãšåå
¥ã®éèšããããªãããšã«ããŸããã
</p>
<p>
å
¥å Žæé衚(å
¥å Žè
1人ãããã®å
¥å Žæ)
</p>
<pre>
åå ååŸ
200å 300å
</pre>
<p>
åã¯ã©ã¹æ¯ã®ååãšååŸã®å
¥å Žè
æ°ãå
¥åãšããåã¯ã©ã¹æ¯ã®å
¥å Žè
ç·æ°åã³åå
¥ã®äžèŠ§è¡šãäœæããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>name<sub>1</sub></var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>name<sub>2</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>name<sub>9</sub></var> <var>a<sub>9</sub></var> <var>b<sub>9</sub></var>
</pre>
<p>
å
¥åã¯ïŒè¡ãããªãã<var>i</var> è¡ç®ã«ç¬¬ <var>i</var> ã®ã¯ã©ã¹ã®ã¯ã©ã¹å <var>name<sub>i</sub></var> (æ°åãšã¢ã«ãã¡ããããå«ã 1 æåä»¥äž 15 æå以äžã®åè§æåå)ãååã®å
¥å Žè
æ° <var>a<sub>i</sub></var> (0 ≤ <var>a<sub>i</sub></var> ≤ 400)ã ååŸã®å
¥å Žè
æ° <var>b<sub>i</sub></var> (0 ≤ <var>b<sub>i</sub></var> ≤ 400) ãäžããããŸãã
</p>
<H2>Output</H2>
<p>
<var>i</var> è¡ç®ã«ç¬¬ <var>i</var> ã®ã¯ã©ã¹ã®ã¯ã©ã¹åã å
¥å Žè
ç·æ°ã æéåå
¥ã空çœåºåãã§ïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
1a 132 243
1c 324 183
1f 93 199
2b 372 163
2c 229 293
2e 391 206
3a 118 168
3b 263 293
3d 281 102
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1a 375 99300
1c 507 119700
1f 292 78300
2b 535 123300
2c 522 133700
2e 597 140000
3a 286 74000
3b 556 140500
3d 383 86800
</pre>
|
p00489 |
<H1>ãµãã«ãŒ (Soccer) </H1>
<h2> åé¡</h2>
<p>
JOI åœã§ã¯ãµãã«ãŒã人æ°ã§ããïŒJOI ãªãŒã°ãšãããªãŒã°æŠãæ¯é±è¡ãããŠããïŒ
</p>
<p>
JOI ãªãŒã°ã«ã¯ N åã®ããŒã ãæå±ããŠããŠïŒ1 ãã N ãŸã§ã®çªå·ãã€ããããŠããïŒãã¹ãŠã®çµã¿åããã®è©Šåãã¡ããã©äžåºŠãã€è¡ãããïŒã€ãŸãïŒ <nobr>N à (N - 1) / 2</nobr> 詊åãè¡ãããïŒå詊åã®åæã¯ããããã®ããŒã ã®åŸç¹ã§æ±ºãŸãïŒåã£ãããŒã ã®åã¡ç¹ã¯ 3 ç¹ã§ããïŒè² ããããŒã ã®åã¡ç¹ã¯ 0 ç¹ã§ããïŒåŒãåãã®å ŽåïŒäž¡ããŒã ã®åã¡ç¹ã¯ 1 ç¹ã§ããïŒé äœã¯åããŒã ã®ç²åŸããåã¡ç¹ã®åèšã§æ±ºå®ãïŒåŸå€±ç¹å·®ã¯èããªãïŒåã¡ç¹ã®åèšãçããããŒã ã®é äœã¯äžäœã«æããïŒ
</p>
<p>
äŸãšããŠïŒ 4 ããŒã ã§ã®ãªãŒã°æŠãèããïŒ<nobr>4 à (4 - 1) / 2 = 6</nobr> 詊åãè¡ãããïŒãããã®çµæã以äžã®è¡šã®ããã«ãªã£ããšããïŒãã€ãã³ã®å·ŠåŽã¯ãã®æšªã®ããŒã ã®åŸç¹ã§ããïŒå³åŽã¯ãã®çžŠã®ããŒã ã®åŸç¹ã§ããïŒ
</p>
<table style="margin-left: 50px; margin-right: 50px; border-style:solid; border-color:#000000;" border="1" cellspacing="1">
<tr>
<th></th>
<th align="center"> ããŒã 1 </th>
<th align="center"> ããŒã 2 </th>
<th align="center"> ããŒã 3 </th>
<th align="center"> ããŒã 4 </th>
<th align="center"> åã¡æ° </th>
<th align="center"> è² ãæ° </th>
<th align="center"> åŒãåãæ° </th>
<th align="center"> åã¡ç¹ </th>
</tr>
<tr>
<th align="center"> ããŒã 1 </th>
<td align="center">---</td>
<td align="center">0 - 1</td>
<td align="center">2 - 1</td>
<td align="center">2 - 2</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">4</td>
</tr>
<tr>
<th align="center"> ããŒã 2 </th>
<td align="center">1 - 0</td>
<td align="center">---</td>
<td align="center">1 - 1</td>
<td align="center">3 - 0</td>
<td align="center">2</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">7</td>
</tr>
<tr>
<th align="center"> ããŒã 3 </th>
<td align="center">1 - 2</td>
<td align="center">1 - 1</td>
<td align="center">---</td>
<td align="center">1 - 3</td>
<td align="center">0</td>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">1</td>
</tr>
<tr>
<th align="center"> ããŒã 4 </th>
<td align="center">2 - 2</td>
<td align="center">0 - 3</td>
<td align="center">3 - 1</td>
<td align="center">---</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">4</td>
</tr>
</table>
<br>
<p>
ãã®ãšãïŒåã¡ç¹ã®æãå€ãããŒã 2 ã 1 äœã§ããïŒ</br>
ãã®æ¬¡ã«åã¡ç¹ãå€ãããŒã ã¯ããŒã 1 ãšããŒã 4 ã§ããïŒãããã®ããŒã ã®é äœã¯å
±ã« 2 äœã§ããïŒ</br>
ãããŠåã¡ç¹ãæãå°ãªãããŒã 3 ã 4 äœã§ããïŒ
</p>
<p>
å
šãŠã®è©Šåã®çµæãäžãããããšãïŒåããŒã ã®é äœãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥åãã¡ã€ã«ã® 1 è¡ç®ã«ã¯ããŒã ã®åæ° N (2 ⊠N ⊠100) ãæžãããŠããïŒç¶ã <nobr>N à (N - 1) / 2</nobr> è¡ã«ã¯å詊åã®çµæãæžãããŠããïŒi + 1 è¡ç® (1 ⊠i ⊠<nobr>N à (N - 1) / 2</nobr>) ã«ã¯æŽæ° A<sub>i</sub>ïŒB<sub>i</sub>ïŒC<sub>i</sub>ïŒD<sub>i</sub> (1 ⊠A<sub>i</sub> ⊠NïŒ1 ⊠B<sub>i</sub> ⊠NïŒ0 ⊠C<sub>i</sub> ⊠100ïŒ0 ⊠D<sub>i</sub> ⊠100) ã空çœãåºåããšããŠæžãããŠããïŒããŒã A<sub>i</sub> ãšããŒã B<sub>i</sub> ã察æŠãïŒããŒã A<sub>i</sub> ã®åŸç¹ã C<sub>i</sub> ç¹ïŒããŒã B<sub>i</sub> ã®åŸç¹ã D<sub>i</sub> ç¹ã§ãã£ãããšã衚ãïŒå
šãŠã® i ã«ã€ã㊠A<sub>i</sub> â B<sub>i</sub> ã§ããïŒåãçµã¿åããã®å¯ŸæŠãæžãããŠããããšã¯ãªãïŒ
</p>
<h2> åºå</h2>
<p>
åºå㯠N è¡ãããªãïŒåè¡ã¯ 1 ã€ã®æŽæ°ãããªãïŒ i è¡ç® (1 ⊠i ⊠N) ã®æŽæ°ã¯ããŒã i ã®é äœã衚ãïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
4
1 2 0 1
1 3 2 1
1 4 2 2
2 3 1 1
2 4 3 0
3 4 1 3
</pre>
<h3>åºåäŸ 1</h3>
<pre>
2
1
4
2
</pre>
<p>
å
¥åºåäŸ 1 ã¯å顿äžã®äŸã«å¯Ÿå¿ããŠããïŒ
</p>
<h3>å
¥åäŸ 2</h3>
<pre>
5
1 2 1 1
3 4 3 1
5 1 1 2
2 3 0 0
4 5 2 3
1 3 0 2
5 2 2 2
4 1 4 5
3 5 4 0
2 4 0 1
</pre>
<h3>åºåäŸ 2</h3>
<pre>
2
4
1
4
3
</pre>
<p>
å
¥åºåäŸ 2 ã«ãããçµæã¯ä»¥äžã®éãã§ããïŒ
</p>
<table style="margin-left: 50px; margin-right: 50px;" border="1" cellspacing="1">
<tr>
<th></th>
<th align="center"> åã¡æ° </th>
<th align="center"> è² ãæ° </th>
<th align="center"> åŒãåãæ° </th>
<th align="center"> åã¡ç¹ </th>
</tr>
<tr>
<th align="center"> ããŒã 1 </th>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">7</td>
</tr>
<tr>
<th align="center"> ããŒã 2 </th>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">3</td>
<td align="center">3</td>
</tr>
<tr>
<th align="center"> ããŒã 3 </th>
<td align="center">3</td>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">10</td>
</tr>
<tr>
<th align="center"> ããŒã 4 </th>
<td align="center">1</td>
<td align="center">3</td>
<td align="center">0</td>
<td align="center">3</td>
</tr>
<tr>
<th align="center"> ããŒã 5 </th>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">4</td>
</tr>
</table>
<br>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00523 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<H1> ããŒã ã¯ãŒãã³(Baumkuchen)
</H1>
<br/>
<p>
JOI åã¯åйã®JOI åã¡ãããšJOI çŸã¡ãããšäžç·ã«ããã€ãé£ã¹ãããšããŠããïŒä»æ¥ã®ããã€ã¯3 人ã®å€§å¥œç©ã®ããŒã ã¯ãŒãã³ã ïŒ
</p>
<p>
ããŒã ã¯ãŒãã³ã¯äžå³ã®ãããªåç圢ã®ãèåã§ããïŒ3 人ã«åããããã«ïŒJOI åã¯ååŸæ¹åã«åã3åå
¥ããŠïŒããã3 ã€ã®ããŒã¹ã«åãåããªããã°ãªããªãïŒãã ããã®ããŒã ã¯ãŒãã³ã¯æ¬ç©ã®æšæã®ããã«åºãã®ã§ïŒåãå
¥ããã®ã¯ç°¡åã§ã¯ãªãïŒãã®ãããã®ããŒã ã¯ãŒãã³ã«ã¯ããããã $N$ åã®åã蟌ã¿ãå
¥ã£ãŠããïŒJOI åã¯åã蟌ã¿ã®ããäœçœ®ã§ã®ã¿åãããšãã§ããïŒåã蟌ã¿ã«1 ãã $N$ ãŸã§æèšåãã«çªå·ããµã£ããšãïŒ$1 \leq i \leq N - 1$ ã«å¯ŸãïŒ $i$ çªç®ã®åã蟌ã¿ãš$i + 1$ çªç®ã®åã蟌ã¿ã®éã®éšåã®å€§ãã㯠$A_i$ ã§ããïŒãŸã $N$ çªç®ã®åã蟌ã¿ãš1 çªç®ã®åã蟌ã¿ã®éã®éšåã®å€§ãã㯠$A_N$ ã§ããïŒ
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_baumkuchen_1"><br>
å³1: ããŒã ã¯ãŒãã³ã®äŸ $N = 6, A_1 = 1, A_2 = 5, A_3 = 4, A_4 = 5, A_5 = 2, A_6 = 4$
</center><br><br>
<h2>課é¡</h2>
<p>
åã蟌ã¿ã®åæ° $N$ ãšïŒåéšåã®å€§ãããè¡šãæŽæ° $A_1,...,A_N$ ãäžããããïŒããŒã ã¯ãŒãã³ã3 ã€ã«åãåãããšãã®ïŒæãå°ããããŒã¹ã®å€§ããã®æå€§å€ãåºåããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒæŽæ° $N$ ãæžãããŠããïŒããã¯ããŒã ã¯ãŒãã³ã« $N$ åã®åã蟌ã¿ãããããšã衚ãïŒ</li>
<li> ç¶ã$N$ è¡ã®ãã¡ã® $i$ è¡ç®$(1 \leq i \leq N)$ ã«ã¯ïŒæŽæ° $A_i$ ãæžãããŠããïŒãã㯠$i$ çªç®ã®åã蟌ã¿ãš $i + 1$ çªç®ã®åã蟌ã¿ã®éã®éšå ($i = N$ ã®ãšã㯠$N$ çªç®ã®åã蟌ã¿ãš1 çªç®ã®åã蟌ã¿ã®éã®éšå) ã®å€§ããã $A_i$ ã§ããããšã衚ãïŒ</li>
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒããŒã ã¯ãŒãã³ã3 ã€ã«åãåãããšãã®ïŒæãå°ããããŒã¹ã®å€§ããã®æå€§å€ãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ
</p>
<h2>å¶é</h2>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li>$3 \leq N \leq 100000$</li>
<li>$1 \leq A_i \leq 1000000000 (1 \leq i \leq N)$</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1 </h3>
<pre>
6
1
5
4
5
2
4
</pre>
<h3>åºåäŸ 1 </h3>
<pre>
6
</pre>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_baumkuchen_2"><br>
å³2: 1 çªç®ã®åã蟌ã¿ãš3 çªç®ã®åã蟌ã¿ãš5 çªç®ã®åã蟌ã¿ã§åãã®ãæåã§ããïŒ
</center><br><br>
<h3>å
¥åäŸ 2 </h3>
<pre>
30
1
34
44
13
30
1
9
3
7
7
20
12
2
44
6
9
44
31
17
20
33
18
48
23
19
31
24
50
43
15
</pre>
<h3>åºåäŸ 2 </h3>
<pre>
213
</pre>
<br>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00734 |
<h1><font color="#000000">Problem A:</font> Equal Total Scores</h1>
<!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> -->
<!-- begin en only -->
<p>
Taro and Hanako have numbers of cards in their hands.
Each of the cards has a score on it.
Taro and Hanako wish to make the total scores of their cards equal
by exchanging one card in one's hand with one card in the other's hand.
Which of the cards should be exchanged with which?
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Note that they have to exchange their
cards even if they already have cards of the same total score.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of a number of datasets.
Each dataset is formatted as follows.
<!-- end en only -->
<blockquote>
<i>n</i> <i>m</i><br>
<i>s</i><sub>1</sub> <br>
<i>s</i><sub>2</sub> <br>
...<br>
<i>s</i><sub><i>n</i></sub> <br>
<i>s</i><sub><i>n</i>+1</sub> <br>
<i>s</i><sub><i>n</i>+2</sub> <br>
...<br>
<i>s</i><sub><i>n</i>+<i>m</i></sub> <br>
</blockquote>
<!-- begin en only -->
</p>
<p>The first line of a dataset contains two numbers
<i>n</i> and <i>m</i> delimited by a space, where <i>n</i>
is the number of cards that Taro has
and <i>m</i> is the number of cards that Hanako has.
The subsequent <i>n</i>+<i>m</i> lines
list the score for each of the cards,
one score per line. The first <i>n</i> scores
(from <i>s</i><sub>1</sub> up to <i>s</i><sub><i>n</i></sub>)
are the scores of Taro's cards
and the remaining <i>m</i> scores
(from <i>s</i><sub><i>n</i>+1</sub> up to <i>s</i><sub><i>n</i>+<i>m</i></sub>)
are Hanako's.
</p>
<p>
The numbers <i>n</i> and <i>m</i>
are positive integers no greater than 100. Each score
is a non-negative integer no greater than 100.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing two zeros delimited
by a single space.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single line containing two numbers delimited
by a single space, where the first number is the score of the card Taro
gives to Hanako and the second number is the score of the card Hanako gives
to Taro.
If there is more than one way to exchange a pair of cards
that makes the total scores equal,
output a pair of scores whose sum is the smallest.
</p>
<p>
In case no exchange can make the total scores equal, output a
single line containing solely -1.
The output must not contain any superfluous characters
that do not conform to the format.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
2 2
1
5
3
7
6 5
3
9
5
2
3
3
12
2
7
3
5
4 5
10
0
3
8
1
9
6
0
6
7 4
1
1
2
1
2
1
4
2
3
4
3
2 3
1
1
2
2
2
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1 3
3 5
-1
2 2
-1
</pre>
|
p02709 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> children standing in a line from left to right. The activeness of the <var>i</var>-th child from the left is <var>A_i</var>.</p>
<p>You can rearrange these children just one time in any order you like.</p>
<p>When a child who originally occupies the <var>x</var>-th position from the left in the line moves to the <var>y</var>-th position from the left, that child earns <var>A_x \times |x-y|</var> happiness points.</p>
<p>Find the maximum total happiness points the children can earn.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2000</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>Print the maximum total happiness points the children can earn.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 3 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>20
</pre>
<p>If we move the <var>1</var>-st child from the left to the <var>3</var>-rd position from the left, the <var>2</var>-nd child to the <var>4</var>-th position, the <var>3</var>-rd child to the <var>1</var>-st position, and the <var>4</var>-th child to the <var>2</var>-nd position, the children earns <var>1 \times |1-3|+3 \times |2-4|+4 \times |3-1|+2 \times |4-2|=20</var> happiness points in total.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
5 5 6 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>58
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
8 6 9 1 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>85
</pre></section>
</div>
</span> |
p01826 |
<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 I:
Live Programming
</h2>
<p>
A famous Japanese idol group, JAG48, is planning the program for its next live performance.
They have $N$ different songs, $song_1$, $song_2$, ..., and $song_N$. Each song has three integer param-
eters, $t_i$, $p_i$, and $f_i$: $t_i$ denotes the length of $song_i$, $p_i$ denotes the basic satisfaction points the
audience will get when $song_i$ is performed, and $f_i$ denotes the feature value of songi that affects
the audience's satisfaction. During the live performance, JAG48 can perform any number (but
at least one) of the $N$ songs, unless the total length of the chosen songs exceeds the length of
the live performance $T$. They can decide the order of the songs to perform, but they cannot
perform the same song twice or more.
</p>
<p>
The goal of this live performance is to maximize the total satisfaction points that the audience
will get. In addition to the basic satisfaction points of each song, the difference between the
feature values of the two songs that are performed consecutively affects the total satisfaction
points. If there is no difference, the audience will feel comfortable. However, the larger the
difference will be, the more frustrated the audience will be.
</p>
<p>
Thus, the total satisfaction points will be calculated as follows:
</p>
<ul>
<li> If $song_x$ is the first song of the live performance, the total satisfaction points just after
$song_x$ is equal to $p_x$.</li>
<li> If $song_x$ is the second or subsequent song of the live performance and is performed just
after $song_y$, $p_x -(f_x -f_y)^2$ is added to the total satisfaction points, because the audience
will get frustrated if $f_x$ and $f_y$ are different.
</ul>
<p>
Help JAG48 find a program with the maximum total satisfaction points.
</p>
<h3>Input</h3>
<p>
The input is formatted as follows.<br>
<br>
$N$ $T$<br>
$t_1$ $p_1$ $f_1$<br>
: : :<br>
$t_N$ $p_N$ $f_N$<br>
<br>
</p>
<p>
The first line contains two integers $N$ and $T$: the number of the available $song_s$ $N$ ($1 \leq N \leq
4,000$), and the length of the live performance $T$ ($1 \leq T \leq 4,000$).
</p>
<p>
The following $N$ lines represent the parameters of the songs. The $i$-th line of them contains three
integers, which are the parameters of $song_i$: the length $t_i$ ($1 \leq t_i \leq 4,000$), the basic satisfaction
points $p_i$ ($1 \leq p_i \leq 10^8$), and the feature value $f_i$ ($1 \leq f_i \leq 10^4$).
</p>
<p>
You can assume that there is at least one song whose length is less than or equal to $T$.
</p>
<h3>Output</h3>
<p>
Output the maximum total satisfaction points that the audience can get during the live performance.
</p>
<h3>Sample Input</h3>
<pre>
2 10
10 200 1
10 100 100
</pre>
<h3>Output for the Sample Input</h3>
<pre>
200
</pre>
<h3>Sample Input</h3>
<pre>
3 15
5 100 1
5 100 2
5 100 4
</pre>
<h3>Output for the Sample Input</h3>
<pre>
295
</pre>
<h3>Sample Input</h3>
<pre>
3 10
5 200 200
5 200 201
5 300 1
</pre>
<h3>Output for the Sample Input</h3>
<pre>
399
</pre>
<h3>Sample Input</h3>
<pre>
3 20
5 100 200
5 100 201
5 300 1
</pre>
<h3>Output for the Sample Input</h3>
<pre>
300
</pre>
<h3>Sample Input</h3>
<pre>
5 61
14 49 7
31 46 4
30 55 5
52 99 1
34 70 3
</pre>
<h3>Output for the Sample Input</h3>
<pre>
103
</pre>
|
p00364 | <H1>Bange Hills Tower</H1>
<p>
A project is underway to build a new viewing tower in Bange town called âBange Hills Towerâ whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wakamatsuCastle" width="600"></center><br/>
<p>
Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. âview of the entire keepâ means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings).
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>N</var> <var>t</var>
<var>x_1</var> <var>h_1</var>
<var>x_2</var> <var>h_2</var>
:
<var>x_N</var> <var>h_N</var>
</pre>
<p>
The first line provides the number of existing buildings <var>N</var> (1≤<var>N</var>≤1000) and the planned location of the tower <var>t</var> (2≤<var>t</var>≤10<sup>5</sup>) in integers. Each of the subsequent <var>N</var> lines provides the information of the <var>i</var>-th building: location <var>x_i</var> (1 ≤ <var>x_i</var> < <var>t</var>) and height from the ground <var>h_i</var> (1 ≤ <var>h_i</var> ≤ 100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if <var>i ≠ j</var>, then <var>x_i ≠ x_j</var>).
</p>
<h2>Output</h2>
<p>
Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed ± 10<sup>-3</sup>.
</p>
<h2>Sample Input 1</h2>
<pre>
3 10
6 4
4 2
3 2
</pre>
<h2>Sample Output 1</h2>
<pre>
6.666667
</pre>
|
p02359 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>The Maximum Number of Customers</H1>
<p>
$N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours.
</p>
<h2>Constraints</h2>
<ul>
<li>$ 1 \leq N \leq 10^5 $</li>
<li>$ 1 \leq T \leq 10^5 $</li>
<li>$ 0 \leq l_i < r_i \leq T $</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<p>
$N$ $T$<br>
$l_1$ $r_1$<br>
$l_2$ $r_2$<br>
:<br>
$l_N$ $r_N$<br>
</p>
<h2>Output</h2>
<p>
Print the maximum number of persons in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
6 10
0 2
1 3
2 6
3 8
4 10
5 10
</pre>
<h2>Sample Output 1</h2>
<pre>
4
</pre>
<h2>Sample Input 2</h2>
<pre>
2 2
0 1
1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre> |
p03118 | <span class="lang-en">
<p>Score : <var>2718</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a very long bench.
The bench is divided into <var>M</var> sections, where <var>M</var> is a very large integer.</p>
<p>Initially, the bench is vacant.
Then, <var>M</var> people come to the bench one by one, and perform the following action:</p>
<ul>
<li>We call a section <em>comfortable</em> if the section is currently unoccupied and is not adjacent to any occupied sections.
If there is no comfortable section, the person leaves the bench.
Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there.
(The choices are independent from each other).</li>
</ul>
<p>After all <var>M</var> people perform actions, Snuke chooses an interval of <var>N</var> consecutive sections uniformly at random (from <var>M-N+1</var> possible intervals), and takes a photo.
His photo can be described by a string of length <var>N</var> consisting of <code>X</code> and <code>-</code>: the <var>i</var>-th character of the string is <code>X</code> if the <var>i</var>-th section from the left in the interval is occupied, and <code>-</code> otherwise.
Note that the photo is directed.
For example, <code>-X--X</code> and <code>X--X-</code> are different photos.</p>
<p>What is the probability that the photo matches a given string <var>s</var>?
This probability depends on <var>M</var>.
You need to compute the limit of this probability when <var>M</var> goes infinity.</p>
<p>Here, we can prove that the limit can be uniquely written in the following format using three <strong>rational</strong> numbers <var>p, q, r</var> and <var>e = 2.718 \ldots</var> (the base of natural logarithm):</p>
<p><var>p + \frac{q}{e} + \frac{r}{e^2}</var></p>
<p>Your task is to compute these three rational numbers, and print them modulo <var>10^9 + 7</var>, as described in Notes section.</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><var>1 \leq N \leq 1000</var></li>
<li><var>|s| = N</var></li>
<li><var>s</var> consists of <code>X</code> and <code>-</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print three rational numbers <var>p, q, r</var>, separated by spaces.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
X
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>500000004 0 500000003
</pre>
<p>The probability that a randomly chosen section is occupied converge to <var>\frac{1}{2} - \frac{1}{2e^2}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
---
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0 0 0
</pre>
<p>After the actions, no three consecutive unoccupied sections can be left.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
X--X-
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0 0 1
</pre>
<p>The limit is <var>\frac{1}{e^2}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5
X-X-X
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>500000004 0 833333337
</pre>
<p>The limit is <var>\frac{1}{2} - \frac{13}{6e^2}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>20
-X--X--X-X--X--X-X-X
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>0 0 183703705
</pre>
<p>The limit is <var>\frac{7}{675e^2}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>100
X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X-
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>0 0 435664291
</pre></section>
</div>
</span> |
p01125 |
<h1>Mysterious Gems</h1>
<p>
å®å®æŠ 1603ã1867 幎ïŒäººã
ã¯ãã®æä»£ã®ããšã EDO æä»£ãšåŒã¶ïŒEDO ãšã¯åœææå
端ã®å®å®èªè¡æè¡ïŒEnhanced Driving Operation ã®ããšã§ããã1603 幎㫠Dr.Izy ã«ãã£ãŠéçºãããïŒ
</p>
<p>
ããªãã¯å®å®åéºå®¶ã§ããïŒå®å®ãé£ã³åã£ãŠæ§ã
ãªææãåéºããŠããïŒãã®åéºã®éäžã§ïŒããªãã¯ãšãŠãäžæè°ãªææãçºèŠããïŒãã®ææã«ã¯ïŒè³ããšããã«äžè²ã«èŒãäžæè°ãªå®ç³ãèœã¡ãŠããïŒããªãã¯ãã®ææãžã®éäžã詊ã¿ãããšèãããïŒé倧ãªåé¡ã®ããã«ããã¯äžå¯èœã§ããããšãããã£ãïŒãã®ææã®ç©ºæ°ã«ã¯ïŒäººéãè§Šããã ãã§å³æ»ããŠããŸããããªçæ¯ã®æåãå«ãŸããŠããã®ã ïŒ
</p>
<p>
ããã§ïŒããªãã¯ããããã䜿ã£ãŠå®ç³ãååããããšãèãã€ããïŒããªãã¯ãã®ææã®åšåè»éã«ãŠåŸ
æ©ããïŒãããŠïŒéäžããããããããé éæäœããããšã«ãã£ãŠå®ç³ãååããã®ã ïŒããªãã¯ïŒããããã«ãç§»åããæ¹åããšãç§»åããè·é¢ãã®çµãããªãåœä»€ã®åã«ãã£ãŠãããããé éæäœããïŒããããã¯ç§»åçµè·¯äžïŒå°éç¹ãå«ãïŒã«å®ç³ãèŠã€ãããšïŒããããå
šãŠååããïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒãããããäžããããå
šãŠã®åœä»€ã®å®è¡ãçµãããšãã«ïŒå
šãŠã®å®ç³ãååããããšãã§ãããã©ãããå€å®ããããã°ã©ã ãæžãããšã§ããïŒ
</p>
<p>
ãªãïŒãããããäžæè°ãªå®ç³ãååããç¯å²ã¯ããã»ã©åºããªãïŒãã®ããïŒãããããç§»åããç¯å²ã¯å
šãŠ 2 次å
ã®å¹³é¢ã§è¡šãããšãã§ããïŒãããŠïŒãããããç§»åããç¯å²ã¯ (0,0) ããã³ (20,20) ãããããå·Šäžé
ããã³å³äžé
ãšããæ£æ¹åœ¢ã®å
éšïŒå¢çç·ãå«ãïŒã§ããïŒããããã¯åžžã«ç¯å²ã®äžå€®ïŒããªãã¡ (10,10) ã®åº§æšã«éäžããïŒãŸãïŒå
šãŠã®å®ç³ã¯äžå€®ä»¥å€ã®æ Œåç¹äžã«ããããšãä¿èšŒãããŠããïŒ
</p>
<h3>Input</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããã«ããæ§æãããïŒ
</p>
<p>
ããããã®ããŒã¿ã»ããã®å
é è¡ã«ã¯ïŒåäžã®æ£ã®æŽæ° <i>N</i> (1 <= <i>N</i> <= 20) ãå«ãŸãããããã¯ãããããç§»åå¯èœãªç¯å²å
ã«ããäžæè°ãªå®ç³ã®åæ°ã衚ãïŒæ¬¡ã® <i>N</i> è¡ã«ã¯ïŒãããã <i>x<sub>i</sub></i> ããã³ <i>y<sub>i</sub></i> (0 <= <i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> <= 20) ãå«ãŸãïŒãã㯠<i>i</i> çªç®ã®äžæè°ãªå®ç³ã®èœã¡ãŠãã座æšã衚ãïŒãªãïŒ1 ã€ã®å Žæã«è€æ°ã®å®ç³ãèœã¡ãŠããããšã¯ãªãïŒ
</p>
<p>
次ã®è¡ã«ã¯åäžã®æŽæ° <i>M</i> (1 <= <i>M</i> <= 30) ãå«ãŸãïŒããã¯ããããã«äžããåœä»€ã®åæ°ã衚ãïŒãã®åŸã® <i>M</i> è¡ã«ã¯ãããã <i>d<sub>j</sub></i> ãšã²ãšã€ã®æ£ã®æŽæ° <i>l<sub>j</sub></i> ãå«ãŸããïŒãã㯠<i>j</i> çªç®ã®åœä»€ã«ãããæ¹åããã³ç§»åéã衚ãïŒãã ãïŒæ¹å㯠NïŒEïŒSïŒW ã®ããããã®æåã§ããïŒé ã«åïŒæ±ïŒåïŒè¥¿ã衚ãïŒå㯠y è»žã®æ£æ¹åïŒæ±ã¯ x è»žã®æ£æ¹åïŒïŒãªãïŒãããããç§»åå¯èœãªç¯å²ãè¶
ãããããªåœä»€ã¯äžããããªãããšãä¿èšŒãããŠããïŒ
</p>
<p>
å
¥å㯠N = 0 ã®ãšãã«çµäºãïŒããã¯ããŒã¿ã»ããã«å«ãŸããªãïŒ
</p>
<h3>Output</h3>
<p>
ããããã®ããŒã¿ã»ããã«ã€ããŠïŒãããããå
šãŠã®å®ç³ãåéã§ãããšãã¯ãYesããšïŒããã§ãªããšãã¯ãNoããš 1 è¡ã«åºåããªããïŒ
</p>
<h3>Sample Input</h3>
<pre>
2
10 11
11 12
2
N 2
E 1
2
10 11
11 12
2
N 2
W 1
3
0 15
5 10
5 15
5
W 10
S 10
N 20
E 10
S 10
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
Yes
No
No
</pre>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.