question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p01691 |
<h2>E - Disappear Drive / æ¶ãããã©ã€ãŽ</h2>
<h3>Story</h3>
<p>Dã®ã²ãšã¯ãã¹ã±ããããŒã«ã奜ãã ããã·ã¥ãŒãã奜ããªãããä»ã®ãã¯ããã¯ã¯ããã£ããã§ãããããªãã«ã¯ç¹ã«èŠæã§ãçžæã®å®åç¯å²ã«å
¥ããšå¿
ãããŒã«ã奪ãããŠããŸããããã§ã©ããªçžæãå¿
ãæãå»ãå¿
殺ã®ããªãã«ãç·šã¿åºãããšã«ãããåªåã®æ«ã圌ã¯éã«æ¶ãããã©ã€ãŽã"ãã£ã¹ã¢ãã¢ãã©ã€ãŽ"ã宿ãããã</p>
<p>ãã£ã¹ã¢ãã¢ãã©ã€ãŽã¯ãçžæãæçºããããšã§éäžåã奪ãèŠç·ãå€ã"ãã£ã¹ãã£ã¬ã¯ã·ã§ã³"ã«ããéãäœãããã®éã«æ¬¡å
(ãã£ã¡ã³ãžã§ã³)ã®å£ãè¶
ããŠçžæã®å®åç¯å²ãããæããŠããŸãå®å
šç¡æ¬ ã®ãã©ã€ãŽã§ãããããããæ¬¡å
ã®å£ãè¶
ããããšã¯äœãžã®è² æ
ã倧ãããããæ¬¡å
ãè¶
ããããåæ°ã«ã¯å¶éãããããŸããåžžã«éäžåã䜿ããããéåžžã®ç§»åãå«ããæ¹å転æã<var>1</var>床ãŸã§ããã§ããªããã³ãŒãäžã§ã©ã®ããã«åãã°ãããŒã«ã奪ãããã«æçã§ãŽãŒã«ãŸã§èŸ¿ãçããã ãããã</p>
<h3>Problem</h3>
<p>äºæ¬¡å
å¹³é¢äžã«ã<var>(0,0)</var>ãå·Šäžã<var>(50,94)</var>ãå³äžãšããé·æ¹åœ¢ãèããããŸãããã®å¹³é¢äžã«ã¯<var>N</var>åã®åãååšãã<var>i</var>çªç®ã®åã®äžå¿ã®äœçœ®ã¯<var>(x_i,y_i)</var>ãååŸã¯<var>r_i</var>ã§ãããåå士ã«éãªãã¯ãªãã</p>
<p><var>(25,0)</var>ãç¹<var>S</var>ã<var>(25,94)</var>ãç¹<var>G</var>ãšãã<var>S</var>ãã<var>G</var>ãžè³ãçµè·¯ãèããããçµè·¯ããšã¯ã(1)<var>S</var>ãš<var>G</var>ãçµãã ç·åã§ãããã(2)é·æ¹åœ¢å
éšã®ä»»æã®ç¹<var>P</var>ã«ã€ããŠç·å<var>SP</var>ãšç·å<var>GP</var>ãçµåãããã®ãããªãã<var>S</var>ãã<var>G</var>ãžãšåããçµè·¯ã®éäžãäžåºŠããåã®å
éšã«å
¥ã£ãŠãããã®åã®å
éšããåºããŸã§ã®éããåã®å
éšãééããåºéããšå®çŸ©ããããã ããé·æ¹åœ¢ã»åã®åšäžã¯ããããé·æ¹åœ¢ã»åã®å
éšã«ã¯å«ãŸããªããšããã</p>
<p>åã®å
éšãééããåºéã®æ°ã<var>D</var>å以äžã§ãããããªçµè·¯ã®ãã¡ãæçã®çµè·¯ã®é·ããæ±ãããã©ãããŠããŽãŒã«ã§ããªããšãã¯<var>-1</var>ãè¿ãããšã</p>
<h3>Input</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒãããªãã</p>
<pre><var>N</var> <var>D</var>
<var>x_1</var> <var>y_1</var> <var>r_1</var>
<var>...</var>
<var>x_N</var> <var>y_N</var> <var>r_N</var></pre>
<p><var>1</var>è¡ç®ã¯<var>2</var>ã€ã®æŽæ°ãããªããåã®åæ°<var>N</var>ãåã®å
éšãééã§ããåæ°<var>D</var>ã空çœ<var>1</var>æååºåãã§äžããããã ç¶ã<var>N</var>è¡ã¯åã®æ
å ±ãäžããããã <var>i+1</var>è¡ç®(<var>1 \leq i \leq N</var>)ã¯<var>3</var>ã€ã®æŽæ°ãããªãã<var>i</var>çªç®ã®åã®äžå¿ã®x座æš<var>x_i</var>ãy座æš<var>y_i</var>ãååŸ<var>r_i</var>ã空çœ<var>1</var>æååºåãã§äžããããã</p>
<p>å¶çŽ:</p>
<ul>
<li><var>0 \leq N \leq 5</var></li>
<li><var>0 \leq D \leq 5</var></li>
<li><var>0 \leq x_i \leq 50</var></li>
<li><var>0 \leq y_i \leq 94</var></li>
<li><var>1 \leq r_i \leq 100</var></li>
<li>ä»»æã®<var>2</var>åéã¯<var>10^{-5}</var>以äžé¢ããŠãããšä»®å®ããŠããã</li>
<li><var>S</var>,<var>G</var>ã¯ããããä»»æã®åã®å
éšã«ã¯å«ãŸããªããšä»®å®ããŠããã</li>
<li><var>S</var>,<var>G</var>ã¯ããããä»»æã®åãš<var>10^{-5}</var>以äžé¢ããŠãããšä»®å®ããŠããã</li>
<li>æççµè·¯ã«ãããç¹Pã¯ãé·æ¹åœ¢ã®åšããã³ä»»æã®ååšãã<var>10^{-5}</var>以äžé¢ããŠãããšä»®å®ããŠããã</li>
</ul>
<h3>Output</h3>
<p>æççµè·¯ã®é·ãã<var>1</var>è¡ã«åºåãããè¡ã®æåŸã§ã¯å¿
ãæ¹è¡ãè¡ãããšã ãã ããã©ãããŠããŽãŒã«ã§ããªããšãã¯<var>-1</var>ãè¿ãããšã æ£çã«å¯Ÿãã<var>10^{-7}</var>以äžã®çµ¶å¯Ÿèª€å·®ããããã¯çžå¯Ÿèª€å·®ã¯èš±å®¹ãããã</p>
<h3>Sample Input 1</h3>
<pre>1 0
25 47 10</pre>
<h3>Sample Output 1</h3>
<pre>96.2027355887</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample1" alt="DisappearDrive_sample1.png" />
<p>æ¶ããããšãã§ããªãã®ã§ãè¿åããçµè·¯ãæçã§ããã</p>
<h3>Sample Input 2</h3>
<pre>1 1
25 47 10</pre>
<h3>Sample Output 2</h3>
<pre>94.0000000000</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample2" alt="DisappearDrive_sample2.png" />
<p>æ¶ããããšãã§ããã®ã§ãäžçŽç·ã«çªãæããã°ããã</p>
<h3>Sample Input 3</h3>
<pre>1 0
20 47 5</pre>
<h3>Sample Output 3</h3>
<pre>94.0000000000</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample3" alt="DisappearDrive_sample3.png" />
<p>ååšäžã¯åã®å
éšã«å«ãŸããªãã®ã§ãæ¶ããã«ééããããšãã§ããã</p>
<h3>Sample Input 4</h3>
<pre>1 0
25 47 40</pre>
<h3>Sample Output 4</h3>
<pre>-1</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample4" alt="DisappearDrive_sample4.png" />
<p>æ¶ããããšãè¿åããããšãã§ããªãããããŽãŒã«ã«å°éã§ããªãã</p>
<h3>Sample Input 5</h3>
<pre>5 2
11 10 16
33 40 18
20 66 10
45 79 14
22 85 8</pre>
<h3>Sample Output 5</h3>
<pre>96.1320937224</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample5" alt="DisappearDrive_sample5.png" /> |
p00983 | <h2>Reordering the Documents</h2>
<p>
Susan is good at arranging her dining table for convenience, but not her office desk.
</p>
<p>
Susan has just finished the paperwork on a set of documents, which are still piled on her desk. They have serial numbers and <i>were</i> stacked in order when her boss brought them in. The ordering, however, is not perfect now, as she has been too lazy to put the documents slid out of the pile back to their proper positions. Hearing that she has finished, the boss wants her to return the documents immediately in the document box he is sending her. The documents should be stowed in the box, of course, in the order of their serial numbers.
</p>
<p>
The desk has room just enough for two more document piles where Susan plans to make two temporary piles. All the documents in the current pile are to be moved one by one from the top to either of the two temporary piles. As making these piles too tall in haste would make them tumble, not too many documents should be placed on them. After moving <i>all</i> the documents to the temporary piles and receiving the document box, documents in the two piles will be moved from their tops, one by one, into the box. Documents should be in reverse order of their serial numbers in the two piles to allow moving them to the box in order.
</p>
<p>
For example, assume that the pile has six documents #1, #3, #4, #2, #6, and #5, in this order from the top, and that the temporary piles can have no more than three documents. Then, she can form two temporary piles, one with documents #6, #4, and #3, from the top, and the other with #5, #2, and #1 (Figure E.1). Both of the temporary piles are reversely ordered. Then, comparing the serial numbers of documents on top of the two temporary piles, one with the larger number (#6, in this case) is to be removed and stowed into the document box first. Repeating this, all the documents will be perfectly ordered in the document box.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_reordering_the_documents" width="680"/><br>
Figure E.1. Making two temporary piles
</center>
<p>
Susan is wondering whether the plan is actually feasible with the documents in the current pile and, if so, how many different ways of stacking them to two temporary piles would do. You are asked to help Susan by writing a program to compute the number of different ways, which should be zero if the plan is not feasible.
</p>
<p>
As each of the documents in the pile can be moved to either of the two temporary piles, for $n$ documents, there are $2^n$ different choice combinations in total, but some of them may disturb the reverse order of the temporary piles and are thus inappropriate.
</p>
<p>
The example described above corresponds to the first case of the sample input. In this case, the last two documents, #5 and #6, can be swapped their destinations. Also, exchanging the roles of two temporary piles totally will be OK. As any other move sequences would make one of the piles higher than three and/or make them out of order, the total number of different ways of stacking documents to temporary piles in this example is $2 \times 2 = 4$.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$ $m$
$s_1$ ... $s_n$
</pre>
<p>
Here, $n$ is the number of documents in the pile ($1 \leq n \leq 5000$), and $m$ is the number of documents that can be stacked in one temporary pile without committing risks of making it tumble down ($n/2 \leq m \leq n$). Numbers $s_1$ through $s_n$ are the serial numbers of the documents in the document pile, from its top to its bottom. It is guaranteed that all the numbers $1$ through $n$ appear exactly once.
</p>
<h3>Output</h3>
<p>
Output a single integer in a line which is the number of ways to form two temporary piles suited for the objective. When no choice will do, the number of ways is $0$, of course.
</p>
<p>
If the number of possible ways is greater than or equal to $10^9 + 7$, output the number of ways modulo $10^9 + 7$.
</p>
<h3>Sample Input 1 </h3>
<pre>
6 3
1 3 4 2 6 5
</pre>
<h3>Sample Output 1</h3>
<pre>
4
</pre>
<h3>Sample Input 2 </h3>
<pre>
6 6
1 3 4 2 6 5
</pre>
<h3>Sample Output 2</h3>
<pre>
8
</pre>
<h3>Sample Input 3 </h3>
<pre>
4 4
4 3 1 2
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre>
|
p01384 |
<div>
<h1 class="title">åé¡ I : ãããæŒç®</h1>
<p>ãããã Gââgle Code Jam ã®äžç倧äŒãå§ãŸãããšããŠããïŒ
åã§ã¯ Pâtr, tâmek, SnapDragân ãã¯ãããšããïŒ
Gââgle ã®èªãæåŒ·ã®ã³ãŒããŒéãçšã¿ãå©ãããŠããïŒ
åŠãªåããèŠããã°ïŒåœã¯ãªãã ããïŒ
ç®ãã€ããïŒã³ã³ãã¹ãéå§ããã£ãšåŸ
ã€ïŒ</p>
<p>âŠåŠã ïŒã³ã³ãã¹ããå§ãŸããªãïŒ
ç®ãéããŠã¿ããšâŠãªããšããããšã ïŒéšå±ã®å
šãŠã®äººéãïŒåããŠããïŒ
ããéãïŒå
šãŠã§ã¯ãªãïŒäžäººã®ç·ïŒwata ãé€ããŠã ïŒ</p>
<dl class="docutils">
<dt>wata</dt>
<dd>ããã£ãšè©±ãããïŒ ä¹
ãã¶ãã ãªïŒ(iwi)ã</dd>
<dt>(iwi)</dt>
<dd>ãâŠãåã¯äœè
ã ïŒ ä¿ºã®ç¥ã wata ã¯å¹Œãªãã¿ç³»çŸå°å¥³ã®ã¯ããâŠã</dd>
<dt>wata</dt>
<dd>ããŸã ãããªåŠæ³ã«åãæãããŠããã®ã!! æãåºã!! åãæ¢ãã!! 圌ã¯ãããã®äžçã«ã¯å±
ãªããã !!ã</dd>
</dl>
<p>ã¯ã£âŠ!! åã¯å
šãŠãæãåºããŠããïŒ
åã¯äžçã§æåã«ããã°ã©ãã³ã°ã³ã³ãã¹ãã§äººã殺ããã®ã ïŒ
ãããŠïŒåãæ®ºããã®ã¯ä»ã§ããªãïŒæã仲ã®è¯ãã£ãå人ã®äžäººïŒkita_masa ã§ãã£ãïŒ</p>
<p>kita_masa ã¯èªãããããæŒç®ã®é人ãšèšãïŒ
ãããã颿°ã¯ãããæŒç®ã§èšè¿°ã§ãããšèšãïŒå°ãå€ãã£ã奎ã ã£ãïŒ
ããããã°ä»ïŒãããæŒç®ãçšããŠäœæããã颿°ããããïŒ
kita_masa ã«ããããé¡ãããããšã¯ã§ããªãïŒ
ããã§ïŒkita_masa ã®ä»£ããã«ãªãããã°ã©ã ãäœæããããšã«ããïŒ</p>
<div>
<h1>åé¡</h1>
<p><span style="font-size:110%;font-family:times new roman;"><i>N</i></span> åã®æŽæ°ã®çµ <span style="font-size:110%;font-family:times new roman;">(<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>)</span> ãäžããããïŒ
å
šãŠã®çµã«å¯Ÿã㊠<span style="font-size:110%;font-family:times new roman;"><i>y</i><sub><i>i</i></sub> = <i>f</i>(<i>x</i><sub><i>i</i></sub>)</span> ãªã颿° <span style="font-size:110%;font-family:times new roman;"><i>f</i></span> ãå¶çŽã®äžã§äœãããšãèããïŒ</p>
<p>颿° <span style="font-size:110%;font-family:times new roman;"><i>f</i></span> ã¯ïŒC èšèªã®ãœãŒã¹ã³ãŒããšããŠä»¥äžã®ããã«è¡šçŸã§ãããã®ãšãã:</p>
<pre class="literal-block">
uint32_t f(uint32_t x) {
return åŒ;
}
</pre>
<p>ããã§ïŒuint32_t 㯠32 ããã笊å·ç¡ãæŽæ°ã衚ãïŒ
ãŸãïŒåŒã¯ä»¥äžã® BNF ã§è¡šçŸã§ãããã®ãšãã:</p>
<pre class="literal-block">
<expr> ::= "x"
| <num>
| "(~" <expr> ")"
| "(" <expr> <op2> <expr> ")"
<op2> ::= "&" | "|" | "^" | "+" | "-" | "*"
</pre>
<p><num> 㯠32 ããã笊å·ç¡ãæŽæ°ã§è¡šçŸã§ããéè² ã®æŽæ°ã
10 鲿°ã§èªç¶ã« (leading-zero çãæãã) 衚çŸãããã®ãšããïŒ</p>
<p>ãã®ãããªé¢æ°ã®åŒãåºåããããã°ã©ã ãäœæããïŒ</p>
</div>
<div>
<h1>å
¥å</h1>
<p>å
¥åã®æåã®è¡ã¯ 1 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> ãå«ãïŒ</p>
<p>ç¶ã <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> è¡ã® <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> è¡ç®ã¯ 2 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub></span> ãå«ãïŒ</p>
</div>
<div>
<h1>åºå</h1>
<p>æ¡ä»¶ãæºããåŒãåºåããïŒ</p>
</div>
<div>
<h1>å¶çŽ</h1>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>N</i> ≤ 8</span></li>
<li><span style="font-size:110%;font-family:times new roman;">0 ≤ <i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub> < 256</span></li>
<li>åŒã¯å¿
ãïŒäžèšã® BNF ã«åŸãæžåŒã§åºåããïŒäŸã C èšèªã®è¡šçŸãšããŠåŠ¥åœã§ãã£ããšããŠãïŒç©ºçœãæ¹è¡ã®æ¿å
¥ãæ¬åŒ§ã®åé€ãªã©ã¯ããŠã¯ãªããªãïŒ</li>
<li>åºå㯠100000 æåãè¶ããŠã¯ãªããªãïŒ</li>
<li>æ¡ä»¶ãæºãã颿° <span style="font-size:110%;font-family:times new roman;"><i>f</i></span> ãåžžã«ååšãããããªå
¥åãäžããããïŒ</li>
</ul>
</div>
<div>
<h1>éšåç¹</h1>
<p>ãã®åé¡ã®å€å®ã«ã¯ïŒ20 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ
ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã®å
¥åã¯ä»¥äžãæºããïŒ</p>
<ul class="simple">
<li>'+', '-', '*' ãçšããªããããªæ£ããåºåãååšãã</li>
</ul>
</div>
<div>
<h1>å
¥åºåäŸ</h1>
<p>å
¥åäŸ1:</p>
<pre class="literal-block">
8
1 1
2 2
3 3
4 0
5 1
6 2
7 3
8 0
</pre>
<p>å
¥åäŸ 1 ã«å¯Ÿããåºåã®äŸ:</p>
<pre class="literal-block">
(x&3)
</pre>
<p>å
¥åäŸ2:</p>
<pre class="literal-block">
8
1 0
2 0
3 2
4 0
5 4
6 4
7 6
8 0
</pre>
<p>å
¥åäŸ 2 ã«å¯Ÿããåºåã®äŸ:</p>
<pre class="literal-block">
(x&(x-1))
</pre>
<p>è¯ãç¥ãããæå³ã® 1 ãããããªãã«ããæäœã§ããïŒ</p>
</div>
</div> |
p03643 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>This contest, <em>AtCoder Beginner Contest</em>, is abbreviated as <em>ABC</em>.</p>
<p>When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.</p>
<p>What is the abbreviation for the <var>N</var>-th round of ABC? Write a program to output the answer.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>100 †N †999</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 abbreviation for the <var>N</var>-th round of ABC.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>ABC100
</pre>
<p>The 100th round of ABC is ABC100.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>425
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>ABC425
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>ABC999
</pre></section>
</div>
</span> |
p02951 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two bottles for holding water.</p>
<p>Bottle <var>1</var> can hold up to <var>A</var> milliliters of water, and now it contains <var>B</var> milliliters of water.</p>
<p>Bottle <var>2</var> contains <var>C</var> milliliters of water.</p>
<p>We will transfer water from Bottle <var>2</var> to Bottle <var>1</var> as much as possible.</p>
<p>How much amount of water will remain in Bottle <var>2</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq B \leq A \leq 20</var></li>
<li><var>1 \leq C \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> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the integer representing the amount of water, in milliliters, that will remain in Bottle <var>2</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>We will transfer two milliliters of water from Bottle <var>2</var> to Bottle <var>1</var>, and one milliliter of water will remain in Bottle <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 3 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>12 3 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03213 | <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>. Among the divisors of <var>N!</var> <var>(= 1 \times 2 \times ... \times N)</var>, how many <em>Shichi-Go numbers</em> (literally "Seven-Five numbers") are there?</p>
<p>Here, a Shichi-Go number is a positive integer that has exactly <var>75</var> divisors.</p>
</section>
</div>
<div class="part">
<section>
<h3>Note</h3><p>When a positive integer <var>A</var> divides a positive integer <var>B</var>, <var>A</var> is said to a <em>divisor</em> of <var>B</var>.
For example, <var>6</var> has four divisors: <var>1, 2, 3</var> and <var>6</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>N</var> is an integer.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the Shichi-Go numbers that are divisors of <var>N!</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>There are no Shichi-Go numbers among the divisors of <var>9! = 1 \times 2 \times ... \times 9 = 362880</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>There is one Shichi-Go number among the divisors of <var>10! = 3628800</var>: <var>32400</var>.</p>
</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>543
</pre></section>
</div>
</span> |
p00595 |
<H1><font color="#000000">Problem A:</font> Greatest Common Divisor</H1>
<p>
Please find the greatest common divisor of two natural numbers. A clue is: The Euclid's algorithm is a way to resolve this task.
</p>
<H2>Input</H2>
<p>
The input file consists of several lines with pairs of two natural numbers in each line. The numbers do not exceed 100000.
</p>
<p>
The number of pairs (datasets) is less than 50.
</p>
<H2>Output</H2>
<p>
Your program has to print the greatest common divisor for each pair of input numbers. Print each result on a new line.
</p>
<H2>Sample Input</H2>
<pre>
57 38
60 84
</pre>
<H2>Output for the Sample Input</H2>
<pre>
19
12
</pre> |
p02052 | <h2>A: Hokkaido University Easy</h2>
<h3>泚æ</h3>
<p>ãåé¡èšå®ã¯ B åé¡ãšåäžã®ãã®ã§ãããå¶çŽã®ã¿ãç°ãªããŸãã®ã§ã泚æãã ããã</p>
<h3>ç©èª</h3>
<p>ãåæµ·é倧åŠã«åæ Œããæ°ããªç掻ã®å§ãŸãã«å¿ãèºãããã»ããã¡ãããããã圌女ã®åã«ã¯ããšãŠã€ããªãåºããã£ã³ãã¹ãåŸ
ã¡åããŠãã...ã</p>
<p>ããã...æ¬¡ã®ææ¥ã«éã«åããªããã ãã©...ã</p>
<h3>åé¡</h3>
<p>ãåæµ·éå€§åŠæå¹ãã£ã³ãã¹ã¯ç°åžžã«åºãããšã§æåã§ããæå¹ãã£ã³ãã¹ã¯çžŠã« <var>H</var> ãã¹ã暪㫠<var>W</var> ãã¹äžŠãã é·æ¹åœ¢ã®ãã¹ç®ã§è¡šçŸãããŸããåãã <var>i</var> ãã¹ã西ãã <var>j</var> ãã¹é²ãã ãã¹ã <var>(i,j)</var> ã§è¡šãããšã«ããŸãããã£ã³ãã¹å
ã«ã¯ããã€ã建ç©ãããããã¹ <var>(i,j)</var> ã§è¡šãããäœçœ®ã«å»ºç©ãããå Žå㯠'B' ããªãå Žå㯠'.' ã <var>c_{i,j}</var> ã«æžãããŠããŸãã</p>
<p>ãåæµ·é倧åŠã®æ°å
¥çã®ã»ããã¡ããã¯ããã£ã³ãã¹ã®ããŸãã®åºãã«é©æãã建ç©éã®ç§»åãå¿é
ã«ãªã£ãŠããŸãããããã§ã建ç©ã®ãã <var>2</var> ã€ã®ãã¹ã®ãã¡ãæãé ãçµã¯ã©ããããé¢ããŠããã®ããæ°ã«ãªããŸãããããã§ã<var>2</var> ã€ã®ãã¹ã®çµ <var>(i,j) , (i',j')</var> ã®éã®è·é¢ã <var>|i-i'|+|j-j'|</var> ãšå®çŸ©ããŸãã</p>
<p>ãã»ããã¡ããã¯ãèªåã«ã¯ãã®åé¡ã¯é£ãããšæããåçŽçã®ããªãã«å©ããæ±ããŠããŸãããã»ããã¡ããã®ä»£ããã«çããæ±ããŠãã ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre>
<var>H</var> <var>W</var>
<var>c_{11}</var><var>c_{12}</var> <var>...</var> <var>c_{1W}</var>
<var>:</var>
<var>c_{H1}</var><var>c_{H2}</var> <var>...</var> <var>c_{HW}</var>
</pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>2\leq H,W \leq 30</var></li>
<li> <var>H,W</var> ã¯æŽæ°</li>
<li> <var>c_{i,j}</var> 㯠'B' ã '.' ã®ããããã§ããã</li>
<li> <var>c_{i,j}</var> ã®ãã¡å°ãªããšã <var>2</var> ã€ã¯ 'B' ã§ããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>çããè¡šãæŽæ°ã <var>1</var> è¡ã«åºåããã</p>
<h3>å
¥åäŸ 1</h3>
<pre>
3 3
B.B
..B
.BB
</pre>
<h3>åºåäŸ 1</h3>
<pre>4</pre>
<ul>
<li><var>(1,1)</var> ãš <var>(3,3)</var> ã® <var>2</var> ç¹éãæé·ã§ãã</li>
</ul>
<h3>å
¥åäŸ 2</h3>
<pre>
4 3
B..
B..
...
...
</pre>
<h3>åºåäŸ 2</h3>
<pre>1</pre>
<ul>
<li>é£ãåãäœçœ®ãæé·ã«ãªãå ŽåããããŸãã</li>
</ul>
<h3>å
¥åäŸ 3</h3>
<pre>
6 6
...B..
B.B.B.
.B.B.B
...B.B
.B..B.
..B...
</pre>
<h3>åºåäŸ 3</h3>
<pre>7</pre>
|
p02402 |
<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>Min, Max and Sum</h1>
<p>
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
</p>
<h2>Input</h2>
<p>
In the first line, an integer $n$ is given. In the next line, $n$ integers $a_i$ are given in a line.
</p>
<h2>Output</h2>
<p>
Print the minimum value, maximum value and sum in a line. Put a single space between the values.
</p>
<h2>Constraints</h2>
<ul>
<li>$0 < n \leq 10000$</li>
<li>$-1000000 \leq a_i \leq 1000000$</li>
</ul>
<h2>Sample Input</h2>
<pre>
5
10 1 5 4 17
</pre>
<h2>Sample Output</h2>
<pre>
1 17 37
</pre>
|
p00350 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>æååã²ãŒã </H1>
<p>
ããªãã¯ãååã®ã¢ã€åãšã
ãŒåã«æååã䜿ã£ãã²ãŒã ã®ããã°ã©ã ããã¬ãŒã³ãããŸããããã®ã²ãŒã ã§ã¯ãã¢ã€åãšã
ãŒåãæååã®äžããéšåæååãããããéžã³ãããããæ¯èŒããŠå°ããæ¹ãéžãã 人ã«åŸç¹ãå ç®ãããŸããäºäººã¯ç«¶ãåããäœåºŠãã²ãŒã ãè¡ããŸããããšããããåãæååã«å¯ŸããŠäœåºŠãã²ãŒã ãããŠãããã¡ã«é£œããŠããŸããŸãããããã§ããªãã¯ãæååãå€åããããã«ããã°ã©ã ãä¿®æ£ããããšã«ããŸããã
</p>
<br/>
<p>
é·ã <var>N</var> ã®æåå <var>U</var> ãš <var>Q</var> åã®åœä»€æãäžãããããšãã以äžã®åœä»€ãåŠçããããã°ã©ã ãäœæããã
</p>
<ul>
<li> æåå <var>U</var> ã®æå®ãããç¯å²ã«ãããã¹ãŠã®æåããæå®ãããæåã«çœ®ãæããã</li>
<li> æåå <var>U</var> ã®æå®ãããïŒã€ã®éšåæåå <var>S</var>, <var>T</var> ãèŸæžé ã§æ¯èŒããŠããããã®å€§å°é¢ä¿ãåºåããã</li>
</ul>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>U</var>
<var>Q</var>
<var>query<sub>1</sub></var>
<var>query<sub>2</sub></var>
:
<var>query<sub>Q</sub></var>
</pre>
<p>
ïŒè¡ç®ã«æååã®é·ã <var>N</var> (1 ≤ <var>N</var> ≤ 200000)ãïŒè¡ç®ã«æåå <var>U</var> (è±å°æåã®ã¿ãå«ãæåå)ãäžãããããïŒè¡ç®ã«åœä»€ã®æ° <var>Q</var> (1 ≤ <var>Q</var> ≤ 100000) ãäžãããããç¶ã <var>Q</var> è¡ã« <var>i</var> çªç®ã®åœä»€ <var>query<sub>i</sub></var> ãäžãããããå <var>query<sub>i</sub></var> ã¯ã以äžã®ããããã®åœ¢åŒã§äžããããã
</p>
<pre>
set <var>x</var> <var>y</var> <var>z</var>
</pre>
<p>
ãŸãã¯
</p>
<pre>
comp <var>a</var> <var>b</var> <var>c</var> <var>d</var>
</pre>
<p>
set <var>x</var> <var>y</var> <var>z</var> ã¯æåå <var>U</var> ã® <var>x</var> æåç®ãã <var>y</var> æåç®ãŸã§ããæå®ãããæå <var>z</var> ã«çœ®ãæããããšã衚ãããã ãã1 ≤ <var>x</var> ≤ <var>y</var> ≤ <var>N</var> ã§ããã<var>z</var> ã¯è±å°æåã§ããã
</p>
<p>
comp <var>a</var> <var>b</var> <var>c</var> <var>d</var> ã¯æåå <var>U</var> ã® <var>a</var> æåç®ãã <var>b</var> æåç®ãŸã§ã®éšåæååã <var>S</var>ãæåå <var>U</var> ã® <var>c</var> æåç®ãã <var>d</var> æåç®ãŸã§ã®éšåæååã <var>T</var> ãšãããšããæåå <var>S</var> ãšæåå <var>T</var> ãèŸæžé ã§æ¯èŒããããšã衚ãããã ãã1 ≤ <var>a</var> ≤ <var>b</var> ≤ <var>N</var> ã〠1 ≤ <var>c</var> ≤ <var>d</var> ≤ <var>N</var> ã§ããã
</p>
<h2>Output</h2>
<p>
å comp åœä»€ã«ã€ããŠã<var>S</var> ã®æ¹ãå°ãããªãã°ãsãã<var>T</var> ã®æ¹ãå°ãããªãã°ãtããäž¡è
ãäžèŽããŠãããªãã°ãeããšïŒè¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
13
aizualgorithm
9
comp 1 1 4 5
comp 2 6 1 5
set 9 12 b
comp 9 9 10 10
comp 5 8 1 4
set 1 10 z
set 11 13 x
comp 8 10 1 5
comp 1 5 1 5
</pre>
<h2>Sample Output 1</h2>
<pre>
s
t
e
t
s
e
</pre> |
p02697 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are going to hold a competition of one-to-one game called AtCoder Janken. <em>(Janken is the Japanese name for Rock-paper-scissors.)</em>
<var>N</var> players will participate in this competition, and they are given distinct integers from <var>1</var> through <var>N</var>.
The arena has <var>M</var> playing fields for two players. You need to assign each playing field two distinct integers between <var>1</var> and <var>N</var> (inclusive).
You cannot assign the same integer to multiple playing fields.
The competition consists of <var>N</var> rounds, each of which proceeds as follows:</p>
<ul>
<li>For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.</li>
<li>Then, each player adds <var>1</var> to its integer. If it becomes <var>N+1</var>, change it to <var>1</var>.</li>
</ul>
<p>You want to ensure that no player fights the same opponent more than once during the <var>N</var> rounds.
Print an assignment of integers to the playing fields satisfying this condition.
It can be proved that such an assignment always exists under the constraints given.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq M</var></li>
<li><var>M \times 2 +1 \leq N \leq 200000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>M</var> lines in the format below.
The <var>i</var>-th line should contain the two integers <var>a_i</var> and <var>b_i</var> assigned to the <var>i</var>-th playing field.</p>
<pre><var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 3
</pre>
<p>Let us call the four players A, B, C, and D, and assume that they are initially given the integers <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>, respectively.</p>
<ul>
<li>
<p>The <var>1</var>-st round is fought by B and C, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>2</var>, <var>3</var>, <var>4</var>, and <var>1</var>, respectively.</p>
</li>
<li>
<p>The <var>2</var>-nd round is fought by A and B, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>3</var>, <var>4</var>, <var>1</var>, and <var>2</var>, respectively.</p>
</li>
<li>
<p>The <var>3</var>-rd round is fought by D and A, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>4</var>, <var>1</var>, <var>2</var>, and <var>3</var>, respectively.</p>
</li>
<li>
<p>The <var>4</var>-th round is fought by C and D, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>, respectively.</p>
</li>
</ul>
<p>No player fights the same opponent more than once during the four rounds, so this solution will be accepted.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 6
2 5
3 4
</pre></section>
</div>
</span> |
p03985 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Story</h3>
<p>I am a Summoner who can invoke monsters. I can embody the pictures of monsters drawn on sketchbooks.
<p>I recently have received a request from Primate Research Institute of Kyoto University to invoke "Hundred Eyes Monster".
<p>What an great honor it is to contribute to the prosperity of the primate research of Kyoto University!
I decided to paint an extremely high-quarity monster to the best of my ability. </p>
<p>I have already painted the forehead and mouth and this time I am going to paint as many eyes as possible between the forehead and mouth.
Well...I cannot wait to see the complete painting.
<h3>Problem Statement</h3>
<p>
Two circles <var>A</var>, <var>B</var> are given on a two-dimensional plane.
The coordinate of the center and radius of circle <var>A</var> is (<var>x_A</var>, <var>y_A</var>) and <var>r_A</var> respectively.
The coordinate of the center and radius of circle <var>B</var> is (<var>x_B</var>, <var>y_B</var>) and <var>r_B</var> respectively.
These two circles have no intersection inside.
Here, we consider a set of circles <var>S</var> that satisfies the following conditions.
</p>
<ul>
<li>Each circle in <var>S</var> touches both <var>A</var> and <var>B</var>, and does not have common points with them inside the circle. </li>
<li>Any two different circles in <var>S</var> have no common points inside them.
</li></ul>
<p>
Write a program that finds the maximum number of elements in <var>S</var>.
</p>
</p></p></p></section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq T \leq 50000</var></li>
<li><var>-10^5 \leq x_A \leq 10^5</var></li>
<li><var>-10^5 \leq y_A \leq 10^5</var></li>
<li><var>-10^5 \leq x_B \leq 10^5</var></li>
<li><var>-10^5 \leq y_B \leq 10^5</var></li>
<li><var>1 \leq r_A \leq 10^5</var></li>
<li><var>1 \leq r_B \leq 10^5</var></li>
<li><var>{r_A}^2 + {r_B}^2 < (x_A - x_B)^2 + (y_A - y_B)^2</var></li>
<li>All values given as input are integers.</li>
<li>It is guaranteed that, when the radiuses of <var>A</var> and <var>B</var> change by <var>0.0005</var>, the answer does not change.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>The input consists of multiple test cases and is given from Standard Input in the following format:
<pre>
<var>T</var>
<var>testcase_1</var>
:
<var>testcase_T</var>
</pre>
Each test case is given with the following format.
<pre>
<var>x_A</var> <var>y_A</var> <var>r_A</var> <var>x_B</var> <var>y_B</var> <var>r_B</var>
</pre>
</p></section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>
The output consists of <var>T</var> lines.
On line <var>i</var> (<var>1 \leq i \leq T</var>), putput the maximum number of elements in <var>S</var> in <var>i</var>-th test case.
</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
4
0 -3 2 0 3 2
0 0 9 8 8 2
0 0 9 10 10 5
0 0 707 1000 1000 707
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
3
10
21
180
</pre>
You can arrange circles ,for example, like the following images in Sample 1, 2. <br/>
<div style="text-align: center;">
<img src="/img/other/kupc2016/sushi/img00.png"/>
<img src="/img/other/kupc2016/sushi/img01.png"/>
</div>
</section>
</div>
</span> |
p00700 |
<h1>
Exploring Caves
</h1>
<p>There are many caves deep in mountains found in the countryside. In legend,
each cave has a treasure hidden within the farthest room from the cave's
entrance. The Shogun has ordered his Samurais to explore these caves with
Karakuri dolls (robots) and to find all treasures. These robots move in the
caves and log relative distances and directions between rooms. </p>
<p>Each room in a cave is mapped to a point on an integer grid (x, y >= 0).
For each cave, the robot always starts from its entrance, runs along the grid
and returns to the entrance (which also serves as the exit). The treasure in
each cave is hidden in the farthest room from the entrance, using Euclid
distance for measurement, i.e. the distance of the room at point (x, y) from the
entrance (0, 0) is defined as the square root of (x*x+y*y). If more than one
room has the same farthest distance from the entrance, the treasure is hidden in
the room having the greatest value of x. While the robot explores a cave, it
records how it has moved. Each time it takes a new direction at a room, it notes
the difference (dx, dy) from the last time it changed its direction. For
example, suppose the robot is currently in the room at point (2, 4). If it moves
to room (6, 4), the robot records (4, 0), i.e. dx=6-2 and dy=4-4. The first data
is defined as the difference from the entrance. The following figure shows rooms
in the first cave of the Sample Input. In the figure, the farthest room is the
square root of 61 distant from the entrance. <br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cave1" width="594" height="587"> </p>
<p>Based on the records that the robots bring back, your job is to determine the
rooms where treasures are hidden. </p>
<h2>Input</h2>
<p>In the first line of the input, an integer <i>N</i> showing the number of
caves in the input is given. Integers <i>dx<sub>i</sub></i> and
<i>dy<sub>i</sub></i> are <i>i</i>-th data showing the differences between
rooms. Note that since the robot moves along the grid, either
<i>dx<sub>i</sub></i> or <i>dy<sub>i</sub></i> is zero. An integer pair
<i>dx<sub>i</sub></i> = <i>dy<sub>i</sub></i> = 0 signals the end of one cave's
data which means the robot finished the exploration for the cave and returned
back to the entrance. The coordinates are limited to (0,0)-(1000,1000). </p>
<h2>Output</h2>
<p>Print the position (x, y) of the treasure room on a line for each cave. </p>
<h2>Sample Input</h2>
<pre>
3
1 0
0 1
-1 0
1 0
0 5
-1 0
0 -1
5 0
0 1
0 -1
1 0
0 -4
-3 0
0 3
2 0
0 -2
-1 0
0 1
0 -1
1 0
0 2
-2 0
0 -3
3 0
0 4
-4 0
0 -5
-2 0
0 0
1 0
-1 0
0 0
2 0
0 1
-1 0
0 1
-1 0
0 -2
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
6 5
1 0
2 1
</pre>
|
p01812 |
<h2>çã£æãªéšå±</h2>
<p>
ç®ãèŠãŸããšãAåã¯çã£æãªéšå±ã®äžã«ããã
ã©ãããAå㯠<var>N</var> åã®éšå±ããæ§æããããã³ãžã§ã³ã«è¿·ã蟌ãã§ããŸã£ãããã ã
ããªãã¯Aåãã©ã®éšå±ã«è¿·ã蟌ãã ã®ããç¥ãããšã¯ã§ããªãã£ããã幞ãã«ããã³ãžã§ã³ã®ããããæã«å
¥ããããšãã§ããã
Aåã®é²ãã¹ãéã瀺ãæããéšå±ã«å°ããã
</p>
<p>
<var>N</var> åã®éšå±ã®ãã¡ <var>M</var> åã®éšå±ãçã£æãªéšå±ã§ããããããã <var>D_1</var>, <var>D_2</var>, ..., <var>D_M</var> çªç®ã®éšå±ãçã£æãªéšå±ã§ããããšãåãã£ãŠããã
ãŸããå
šãŠã®éšå±ããã¡ããã© <var>K</var> æ¬ã®äžæ¹éè¡ã®éãé ã«äžŠãã§ããã<var>i</var> çªç®ã®éšå±ããåºãéã¯ãããã
<var>v_{i,1}</var>, <var>v_{i,2}</var>, ..., <var>v_{i,K}</var> çªç®ã®éšå±ã«ç¹ãã£ãŠããã
ããªãã¯ãAåã«å¯Ÿãä»ããéšå±ãã <var>a_1</var>, <var>a_2</var>, ..., <var>a_l</var> çªç®ã®éãé ã«é²ãŸããããšãã§ããã
ãã ããAåã¯æããéšå±ã«å°éããããã以éã®æç€ºã¯ç¡èŠããã
ããªãã¯ãæç€ºã®ååŸã«ãããŠAåãä»ããéšå±ã®æ
å ±ãç¥ãããšã¯ã§ããªããããAåãã©ã®éšå±ã«ãããšããŠãæããéšå±ã«èŸ¿ãçãããããªæç€ºåãäŒããªããã°ãªããªãã
ãã®ãããªæç€ºã®ãã¡ãæãçããã®ã®é·ããçããã
</p>
<h3>Constraints</h3>
<ul>
<li><var>2 ≤ N ≤ 100</var></li>
<li><var>1 ≤ M ≤ min(16, N − 1)</var></li>
<li><var>1 ≤ K ≤ N</var></li>
<li><var>1 ≤ D_i ≤ N</var></li>
<li><var>D_i</var> ã¯å
šãŠç°ãªã</li>
<li><var>1 ≤ v_{i, j} ≤ N</var></li>
<li> å
šãŠã®æãéšå±ã¯å°ãªããšã1ã€ã®æããéšå±ã«å°éå¯èœã§ãã </li>
</ul>
<h3>Input Format</h3>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã
</p>
<pre>
<var>N</var> <var>M</var> <var>K</var>
<var>D_1</var> <var>D_2</var> ... <var>D_M</var>
<var>v_{1,1}</var> <var>v_{1,2}</var> ... <var>v_{1,K}</var>
<var>v_{2,1}</var> <var>v_{2,2}</var> ... <var>v_{2,K}</var>
...
<var>v_{N,1}</var> <var>v_{N,2}</var> ... <var>v_{N,K}</var>
</pre>
<h3>Output Format</h3>
<p>
çããäžè¡ã«åºåããã
</p>
<h3>Sample Input 1</h3>
<pre>
4 2 2
1 2
2 4
3 1
4 2
1 3
</pre>
<h3>Sample Output 1</h3>
<pre>
2
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_sample1"/> <br/>
1, 1 ãšããæç€ºãåºããš
</p>
<ul>
<li>Aåã®åæäœçœ®ãéšå±1ã§ããå Žåã2ã€ç®ã®ç§»åã§éšå±3ã«å°éãã</li>
<li>Aåã®åæäœçœ®ãéšå±2ã§ããå Žåã1ã€ç®ã®ç§»åã§éšå±3ã«å°éãã</li>
</ul>
<h3>Sample Input 2</h3>
<pre>
3 2 2
1 2
2 3
1 2
2 1
</pre>
<h3>Sample Output 2</h3>
<pre>
3
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_sample2"/> <br/>
2, 1, 2 ãšããæç€ºãåºããš
</p>
<ul>
<li>Aåã®åæäœçœ®ãéšå±1ã§ããå Žåã1ã€ç®ã®ç§»åã§éšå±3ã«å°éãã</li>
<li>Aåã®åæäœçœ®ãéšå±2ã§ããå Žåã3ã€ç®ã®ç§»åã§éšå±3ã«å°éãã</li>
</ul>
<h3>Sample Input 3</h3>
<pre>
6 3 3
1 2 3
4 1 1
2 5 2
3 3 6
4 4 4
5 5 5
6 6 6
</pre>
<h3>Sample Output 3</h3>
<pre>
3
</pre>
<p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_sample3"/> <br/>
éé£çµã§ããã±ãŒã¹ããèªå·±èŸºãå€é蟺ãããã±ãŒã¹ã«æ°ãã€ããã
</p>
|
p01541 |
<h1>ã»ããªãããšãã</h1>
<p>
髿©åã¯è¹æ(ããã)ã¡ãããšãã¥ãŒãšãŒã¯ã芳å
ããããšã«ãªããŸããã
髿©åã¯èгå
ãããšããã«ç¹ã«åžæã¯ãªãã£ãã®ã§ãããè¹æã¡ããã®ç±çãªèªãã«ããã以äžã®å°å³ã«ãããããª"ã»ããªãããšãã"ã芳å
ããããšã«æ±ºãŸããŸããã
</p>
<center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_hosonaga" height="344" width="454"></center>
<center>Google ããã - (C)2012 Google</center>
<p>
ãã®"ã»ããªãããšãã"ã¯ãšãŠã现é·ããçŽç·ãšã¿ãªãããšãã§ããŸãããŸãã"ã»ããªãããšãã"ã«ã¯çæ¹ã®ç«¯ã«ã¹ã¿ãŒãå°ç¹ããããçæ¹ã®ç«¯ã«ãŽãŒã«å°ç¹ããããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžåããŠäœå°ãã®èгå
çšã®éЬè»ãèµ°ã£ãŠããŸãããã®éЬè»ã¯ä»¥äžã®ãããªã«ãŒã«ã«åŸã£ãŠéè¡ãããŠããŸãã
</p>
<ul>
<li>銬è»ã¯<var>n</var>å°ããããã¹ãŠã®éЬè»ã¯ã¹ã¿ãŒãå°ç¹ããåºçºããŠãŽãŒã«å°ç¹ãŸã§é²ã¿ãŸãã
</li><li>以äžã®ãã¹ãŠã®å Žåã«ãããŠéЬè»ã®å€§ããã¯ç¡èŠã§ããŸãã
</li><li>éäžã§é床ã倿Žããããšãé£ããããããã¹ãŠã®éЬè»ã¯éЬè»ã¯ãããã1kmãããã<var>S<sub>i</sub></var>(<var>S<sub>i</sub></var>ã¯1以äžã®æŽæ°)åã®çéã§é²ã¿ãŸãã
</li><li>銬è»ã«ã¯åºçºããé çªãå®ããããŠããããã®é çªãå®ããªããã°ãªããŸããããã ãããŽãŒã«å°ç¹ã«å°çããé çªã«ã€ããŠç¹ã«æ±ºãŸãã¯ãããŸããã
</li><li>è€æ°ã®éЬè»ã¯ã¹ã¿ãŒãå°ç¹ãåæã«çºè»ããããšã¯ã§ããããã銬è»ãçºè»ããã°æ¬¡ã®éЬè»ãçºè»ãããŸã§ã«1å以äžéããããªããã°ãªããŸããã
</li><li>ãŽãŒã«å°ç¹ã¯ååã«åºããããäœå°ã®éЬè»ãåæã«å°çããŠãæ§ããŸããããŸãããŽãŒã«å°ç¹ã«å°çãã銬è»ã¯ããã§æ¢ãŸãããã£ãšãŽãŒã«å°ç¹ã«ããŸãã
</li><li>"ã»ããªãããšãã"ã¯å€§å€çްé·ããã銬è»ã¯åºæ¬çã«åãå Žæã«2å°äžŠã¶ããšã¯ã§ããŸãããããããç¹å¥ã«"ãããã²ãããšãã"ã<var>m</var>ç®æãããããã§ã®ã¿2å°ãŸã§äžŠã¶ããšãã§ãããã銬è»ãå¥ã®éЬè»ã远ãæãããšãå¯èœã§ãã
</li></ul>
<p>
ãŸããå
è¿°ãã"ã»ããªãããšãã"ãš"ãããã²ãããšãã"ã«ã€ããŠã以äžã®å¶çŽãæºãããŸãã
</p>
<ul>
<li>ã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§ã¯çŽç·çã«çµã°ããŠããããã®è·é¢ã¯(<var>dist</var>)km(<var>dist</var>ã¯1以äžã®æŽæ°)
</li><li><var>m</var>ç®æã®"ãããã²ãããšãã"ã¯ã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§ã®ã©ããã«ããããããã¯ããããã¹ã¿ãŒãå°ç¹ããã³ãŽãŒã«å°ç¹ãšã¯éãªããŸããããŸããããããã®"ãããã²ãããšãã"ã¯ã¹ã¿ãŒãå°ç¹ããã¡ããã©(<var>D<sub>i</sub></var>)km(<var>D<sub>i</sub></var>ã¯1以äžã®æŽæ°)ã®å°ç¹ã«ãããŸãã
</li></ul>
<p>
ãããèãã髿©åã¯ã以äžã«è¿°ã¹ã銬è»éè¡ã®ã«ãŒã«ãå®ãã€ã€éЬè»ã®åºçºæå»ã調æŽããããšã«ããã1å°ç®ã®éЬè»ãçºè»ããŠãããã¹ãŠã®éЬè»ãå°çãããŸã§ã«ãããæéãå°ããã§ããããšãèŠæããŸããã
髿©åã®åºããçµæãç¥ãããã«ã
銬è»ã®å°æ°<var>n</var> , ããããã®éЬè»ã®é床ã«é¢ãããã©ã¡ãŒã¿<var>S<sub>i</sub></var>,"ã»ããªãããšãã"äžã«ååšãã"ãããã²ãããšãã"ã®ç·æ°<var>m</var> ,ããããã®"ãããã²ãããšãã"ã®ã¹ã¿ãŒãå°ç¹ããã®è·é¢<var>D<sub>i</sub></var> ãäžããããã®ã§ã
1å°ç®ã®éЬè»ãçºè»ããŠãããã¹ãŠã®éЬè»ãå°çãããŸã§ã«ãããæéã®æå°å€ãæ±ããããã°ã©ã ãæžãããšãããªãã®ä»äºã§ãã
ãªããè¹æã¡ããã¯"ã»ããªãããšãã"ã§ã®èгå
ãååã«æ¥œãã¿ãŸãããã髿©åã¯ãã®èгå
ã®åŸã«ã¯ãã»ããªããã£ãâŠããšããã€ã¶ãããªãã£ãããã§ãã
</p>
<h2>Input</h2>
<p>
å
¥å圢åŒã¯ä»¥äžã®ããã«ãªã£ãŠããã
</p>
<blockquote>
<var>dist</var><br><var>n</var><br><var>S<sub>1</sub></var><br><var>S<sub>2</sub></var><br>..<br><var>S<sub>n</sub></var><br><var>m</var><br><var>D<sub>1</sub></var><br><var>D<sub>2</sub></var><br>..<br><var>D<sub>m</sub></var><br></blockquote>
<ul>
<li><var>dist</var>ã¯ã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§ã®è·é¢(km)ã衚ã
</li><li><var>n</var>ã¯ã¹ã¿ãŒãå°ç¹ãçºè»ãã銬è»ã®æ°ã衚ã
</li><li><var>S<sub>i</sub></var>ã¯éЬè»ã®é床ã衚ãã<var>i</var>çªç®ã«åºçºãã銬è»ã¯1kmã<var>(S<sub>i</sub>)</var>åã§é²ãããšã衚ãã
</li><li><var>m</var>ã¯"ãããã²ãããšãã"ã®ç·æ°ã衚ã
</li><li><var>D<sub>i</sub></var>ã¯ã¹ã¿ãŒãå°ç¹ããããããã®"ãããã²ãããšãã"ãžã®è·é¢(km)ã衚ãã
</li></ul>
<h2>Constraints</h2>
<blockquote>
<var>1≤dist≤100000000(10<sup>8</sup>)</var><br><var>1≤n≤5</var><br><var>0≤m≤5</var><br><var>1≤S<sub>i</sub>≤100</var><br><var>0<D<sub>i</sub><dist</var><br><var>i≠j</var>ãªãã°<var>D<sub>i</sub>≠D<sub>j</sub></var><br>å
¥åã«åºçŸããæ°ã¯ãã¹ãп޿°ã§ããã<br></blockquote>
<ul>
<li><var>i < j</var>ãªãã°ã<var>i</var>çªç®ã«åºçºãã銬è»ã¯<var>j</var>çªç®ã®éЬè»ãã1åä»¥äžæ©ãåºçºããªããã°ãªããªã
</li></ul>
<h2>Output</h2>
<p>
1å°ç®ã®éЬè»ãçºè»ããŠãããã¹ãŠã®éЬè»ãå°çãããŸã§ã«ãããæéã®æå°å€ã1è¡ã«åºåãããåäœã¯åã§ããã
</p>
<H2>Sample Input 1</H2>
<pre>100
2
1
2
0
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>201
</pre>
<p>
2å°ç®ã¯1å°ç®ãåºçºãã1ååŸã«åºçºããã
</p>
<H2>Sample Input 2</H2>
<pre>100
2
2
1
0
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>200
</pre>
<p>
2å°ç®ã¯1å°ç®ãåºçºãã100ååŸã«åºçºãããŽãŒã«ã§1å°ç®ã«è¿œãã€ãã
</p>
<H2>Sample Input 3</H2>
<pre>100
3
2
1
1
1
50
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>200
</pre>
<p>
2å°ç®ã¯1å°ç®ãåºçºãã50ååŸã«åºçºãã50mã®ã²ãããšããã§1å°ç®ãæãã<br>
3å°ç®ã¯1å°ç®ãåºçºãã100ååŸã«åºçºãããŽãŒã«ã§1å°ç®ã«è¿œãã€ãã
</p>
<H2>Sample Input 4</H2>
<pre>100
4
3
1
1
3
2
40
60
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>421
</pre> |
p03086 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of uppercase English letters. Find the length of the longest <em>ACGT string</em> that is a substring (see Notes) of <var>S</var>.</p>
<p>Here, a ACGT string is a string that contains no characters other than <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>.</p>
</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>S</var> is a string of length between <var>1</var> and <var>10</var> (inclusive).</li>
<li>Each character in <var>S</var> is an uppercase English letter.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the length of the longest <em>ACGT string</em> that is a substring of <var>S</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>ATCODER
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Among the ACGT strings that are substrings of <code>ATCODER</code>, the longest one is <code>ATC</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>HATAGAYA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>Among the ACGT strings that are substrings of <code>HATAGAYA</code>, the longest one is <code>ATAGA</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>SHINJUKU
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>Among the ACGT strings that are substrings of <code>SHINJUKU</code>, the longest one is <code></code> (the empty string).</p></section>
</div>
</span> |
p01111 | <h3>Skyscraper "MinatoHarukas"</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
Mr. Port plans to start a new business renting one or more floors
of the new skyscraper with one giga floors, MinatoHarukas.
He wants to rent as many vertically adjacent floors as possible,
because he wants to show advertisement on as many vertically
adjacent windows as possible.
The rent for one floor is proportional to the floor number,
that is, the rent per month for the <i>n</i>-th floor is <i>n</i> times
that of the first floor.
Here, the ground floor is called the first floor in the American style,
and basement floors are out of consideration for the renting.
In order to help Mr. Port, you should write a program that computes
the vertically adjacent floors satisfying his requirement and
whose total rental cost per month is
<em><font color="#ff0000">exactly equal</font></em> to his budget.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
For example, when his budget is 15 units,
with one unit being the rent of the first floor,
there are four possible rent plans,
1+2+3+4+5, 4+5+6, 7+8, and 15.
For all of them, the sums are equal to 15.
Of course in this example the rent of maximal number of the floors
is that of 1+2+3+4+5, that is, the rent from the first floor to the fifth floor.
</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>b</i> <br>
</p>
</blockquote>
<!-- begin en only -->
<p>
A dataset consists of one line,
the budget of Mr. Port <i>b</i> as multiples of the rent of the first floor.
<i>b</i> is a positive integer satisfying 1 < <i>b</i> < 10<sup>9</sup>.
</p>
<p>
The end of the input is indicated by a line containing a zero.
The number of datasets does not exceed 1000.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single line containing two positive integers
representing the plan with the maximal number of vertically adjacent floors
with its rent price exactly equal to the budget of Mr. Port.
The first should be the lowest floor number and
the second should be the number of floors.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>15
16
2
3
9699690
223092870
847288609
900660121
987698769
999999999
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>1 5
16 1
2 1
1 2
16 4389
129 20995
4112949 206
15006 30011
46887 17718
163837 5994
</pre>
|
p01404 |
<h2>
Problem G: æ°Žæèš
</h2>
<p>
çµç¶æ¹ã®æ¹åºããå€ãã£ãåœ¢ã®æ°Žæèšã®ãããªãã®ãçºèŠãããã
</p>
<p>
æ°Žæèšã¯æ°Žå¹³ãªåºãå¹³é¢äžã«çœ®ãããïŒã€ä»¥äžã®äžèŸºã30cmã®ç«æ¹äœã®æ°Žæ§œã§æ§æãããŠããã
æ°Žæ§œã¯æ Œåç¶ã«äžŠã¹ãããæ§ã
ãªé«ãã®å°ã®äžã«çœ®ãããŠãããæ°Žæ§œã®åã¿ã¯ç¡èŠã§ããã
åãé«ãã®å°ã®äžã«çœ®ãããæ°Žæ§œãååŸå·Šå³ã«é£æ¥ããŠãããšãããããã®æ°Žæ§œã®éã«ã¯ç©Žããããããæ°Žã®é«ããçããä¿ãããä»çµã¿ã«ãªã£ãŠããã(å³1)
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_G1">
</td>
</tr>
<tr>
<td>
<center>å³1</center>
</td>
</tr>
</table>
</center>
<p>
äžç·ã«çºèŠãããæç®ã«ãããšãããæ°Žæ§œã«æ°Žãç¶ç¶çã«æ³šããä»ã®ç¹å®ã®æ°Žæ§œã®æ°Žäœã調ã¹ãŠãããããã
</p>
<p>
å³2ã®ããã«ããæ°Žæ§œã«æ°Žã泚ããæ°Žãããµãããšããããµããæ°Žã¯ãã®æ°Žæ§œã«é£æ¥ããŠããæ¹åã«çããéæµã蟌ããæ°Žæ§œããªãå Žæã«æ°Žãæµããå Žåãæ°Žæèšã®å€ã«èªåçã«ææ°Žãããã
ãŸãæ°Žãããµããæ¹åããªããšããæ°Žæ§œã®å®¹éããå€ãæ°Žãæ Œåå
ã«ãšã©ãŸãããšã¯ãªãããã®ãããªå Žåãæ°Žæ§œã®å®¹éãè¶
ããåã®æ°Žã¯äžæè°ãªåã§æ¶æ»
ããã
飿¥ããŠããæ°Žæ§œããããšã®æ°Žæ§œããå°ãã§ãé«ãå°ã«çœ®ãããŠãããšãããã®æ¹åã«æ°Žã¯æµããªãã®ã§æ³šæããããšã
äŸãã°å³3ã®å Žåãäžå€®ã®æ°Žæ§œããå·Šå³ãšå¥¥ã®æ°Žæ§œã«ããããããµããéã®1/4ãã€ã®æ°Žãæµã蟌ãã
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_G2">
</td>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_G3">
</td>
</tr>
<tr>
<td>
<center>å³2</center>
</td>
<td>
<center>å³3</center>
</td>
</tr>
</table>
</center>
<p>
ããªãã®ä»äºã¯ãã®æ°Žæèšãã·ãã¥ã¬ãŒãããããã°ã©ã ãæžãäºã§ããã
</p>
<h2>
Input
</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãã
ããŒã¿ã»ããã®åæ°ã¯ã300以äžã§ãããããã以äžã®åœ¢åŒã§ããã
</p>
<pre>
<i>w</i> <i>h</i>
<i>f<sub>x</sub></i> <i>f<sub>y</sub></i> <i>f<sub>q</sub></i>
<i>p<sub>0,0</sub></i> <i>p<sub>0,1</sub></i> ... <i>p<sub>0,w-1</sub></i>
<i>p<sub>1,0</sub></i> <i>p<sub>1,1</sub></i> ... <i>p<sub>1,w-1</sub></i>
...
<i>p<sub>h-1,0</sub></i> <i>p<sub>h-1,1</sub></i> ... <i>p<sub>h-1,w-1</sub></i>
<i>l</i>
<i>t<sub>1</sub></i> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i>
...
<i>t<sub>l</sub></i> <i>x<sub>l</sub></i> <i>y<sub>l</sub></i>
</pre>
<p>
<i>w</i>ã<i>h</i>ã¯ãããããæ Œåã®åããã³è¡ã®æ°ãè¡šãæ£ã®æŽæ°ã§ããããããã<i>1 ≤ w ≤ 10</i>ã<i>1 ≤ h ≤ 10</i>ãæºããã
<i>f<sub>x</sub></i>ã<i>f<sub>y</sub></i>ã<i>f<sub>q</sub></i>ã¯æ°Žãæµãæ°Žæ§œã眮ããŠããæ Œåã®å Žæ(<i>f<sub>x</sub></i>ã<i>f<sub>y</sub></i>)ãšæµé(<i>f<sub>q</sub></i>)ã衚ããæµéã®åäœã¯<i>cm^3</i>ã§ããã
ãããã¯<i>0 ≤ f<sub>x</sub> < w</i>ã<i>0 ≤ f<sub>y</sub> < h</i>ã<i>1 ≤ f<sub>q</sub> ≤ 30000</i>ãæºããã
ç¶ã<i>h</i>è¡ã¯ããããã¹ããŒã¹ã§åºåããã<i>w</i>åã®æ°åããæ§æãããŠããã
æ Œå{<i>i</i>,<i>j</i>}ã«çœ®ããæ°Žæ§œã®çœ®ãããå°ã®é«ãã衚ãã
åäœã¯<i>cm</i>ã§ããã<i>0 ≤ p<sub>i,j</sub> ≤ 1000</i>ãæºããæŽæ°ã§ããã
<i>p<sub>i,j</sub>=0</i>ã®ãšãããã®å Žæã«ã¯æ°Žæ§œã¯çœ®ãããŠããªãã
次ã®äžè¡ã¯æ°Žæ§œã®æ°Žã®é«ãã®æž¬å®åæ°ãè¡šãæ£ã®æŽæ°<i>l</i>ãããªãã
ããã¯<i>1 ≤ l ≤ 10</i>ãæºããã
ç¶ã<i>l</i>è¡ã¯ã¹ããŒã¹ã§åºåããã<i>t<sub>k</sub></i>ã<i>x<sub>k</sub></i>ã<i>y<sub>k</sub></i>ã®3ã€ã®æŽæ°å€ãå«ãã§ããã
<i>t<sub>k</sub></i>ã¯æž¬å®æéã衚ãã<i>x<sub>k</sub></i>ã<i>y<sub>k</sub></i>ã¯æž¬å®å Žæã®æ Œåã瀺ãã
<i>x<sub>k</sub></i>ã<i>y<sub>k</sub></i>ã¯å¿
ãæ°Žæ§œã®ããæ Œåã瀺ããšä»®å®ããŠããã
ãŸãã<i>0 ≤ t ≤ 10000</i>ãæºããã
</p>
<p>
å
¥åã®çµããã¯ãµãã€ã®ãŒããå«ãè¡ã§è¡šãããã
</p>
<h2>
Output
</h2>
<p>
åããŒã¿ã»ããã«å¯ŸããæŽæ°ã<i>l</i>ååºåããã
ãã®æŽæ°ã¯æå®ãããæé<i>t<sub>k</sub></i>ã«ããã
æ Œå<i>x<sub>k</sub></i>ã<i>y<sub>k</sub></i>äžã«ããæ°Žæ§œã®æ°Žã®é«ããåºåããããšã
ãªããæ°Žã®é«ãã®å°æ°ç¹ä»¥äžã¯åãæšãŠãšããã
</p>
<h2>
Sample Input
</h2>
<pre>
3 3
1 1 900
0 10 0
10 45 10
10 0 0
3
5 1 1
50 1 0
100 0 1
5 5
2 0 9000
0 0 4 0 0
0 3 3 3 0
2 2 2 2 2
0 0 1 0 0
0 0 1 0 0
4
5 2 0
10 2 1
100 2 2
250 2 3
0 0
</pre>
<h2>
Output for Sample Input
</h2>
<pre>
5
5
8
30
5
13
4
</pre>
|
p03439 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><font color="red"><strong>This is an interactive task.</strong></font></p>
<p>Let <var>N</var> be an odd number at least <var>3</var>.</p>
<p>There are <var>N</var> seats arranged in a circle.
The seats are numbered <var>0</var> through <var>N-1</var>.
For each <var>i</var> (<var>0 †i †N - 2</var>), Seat <var>i</var> and Seat <var>i + 1</var> are adjacent.
Also, Seat <var>N - 1</var> and Seat <var>0</var> are adjacent.</p>
<p>Each seat is either vacant, or oppupied by a man or a woman.
However, no two adjacent seats are occupied by two people of the same sex.
It can be shown that there is at least one empty seat where <var>N</var> is an odd number at least <var>3</var>.</p>
<p>You are given <var>N</var>, but the states of the seats are not given.
Your objective is to correctly guess the ID number of any one of the empty seats.
To do so, you can repeatedly send the following query:</p>
<ul>
<li>Choose an integer <var>i</var> (<var>0 †i †N - 1</var>). If Seat <var>i</var> is empty, the problem is solved. Otherwise, you are notified of the sex of the person in Seat <var>i</var>.</li>
</ul>
<p>Guess the ID number of an empty seat by sending at most <var>20</var> queries.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an odd number.</li>
<li><var>3 †N †99</var> <var>999</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Input and Output</h3><p>First, <var>N</var> is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
<p>Then, you should send queries.
A query should be printed to Standart Output in the following format.
Print a newline at the end.</p>
<pre><var>i</var>
</pre>
<p>The response to the query is given from Standard Input in the following format:</p>
<pre><var>s</var>
</pre>
<p>Here, <var>s</var> is <code>Vacant</code>, <code>Male</code> or <code>Female</code>.
Each of these means that Seat <var>i</var> is empty, occupied by a man and occupied by a woman, respectively.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notice</h3><ul>
<li>Flush Standard Output each time you print something. Failure to do so may result in <code>TLE</code>.</li>
<li>Immediately terminate the program when <var>s</var> is <code>Vacant</code>. Otherwise, the verdict is indeterminate.</li>
<li>The verdict is indeterminate if more than <var>20</var> queries or ill-formatted queries are sent.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input / Output 1</h3>
<p>In this sample, <var>N = 3</var>, and Seat <var>0</var>, <var>1</var>, <var>2</var> are occupied by a man, occupied by a woman and vacant, respectively.</p>
<table class="table-striped table-bordered table-condensed">
<thead>
<tr><th width="200">Input</th><th width="200">Output</th></tr>
</thead>
<tbody>
<tr><td>3</td><td></td></tr>
<tr><td></td><td>0</td></tr>
<tr><td>Male</td><td></td></tr>
<tr><td></td><td>1</td></tr>
<tr><td>Female</td><td></td></tr>
<tr><td></td><td>2</td></tr>
<tr><td>Vacant</td><td></td></tr>
</tbody>
</table>
</section>
</div>
</span> |
p03593 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>H</var>-by-<var>W</var> matrix.
Let <var>a_{ij}</var> be the element at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.
In this matrix, each <var>a_{ij}</var> is a lowercase English letter.</p>
<p>Snuke is creating another <var>H</var>-by-<var>W</var> matrix, <var>A'</var>, by freely rearranging the elements in <var>A</var>.
Here, he wants to satisfy the following condition:</p>
<ul>
<li>Every row and column in <var>A'</var> can be read as a palindrome.</li>
</ul>
<p>Determine whether he can create a matrix satisfying the condition.</p>
</section>
</div>
<div class="part">
<section>
<h3>Note</h3><p>A <em>palindrome</em> is a string that reads the same forward and backward.
For example, <code>a</code>, <code>aa</code>, <code>abba</code> and <code>abcba</code> are all palindromes, while <code>ab</code>, <code>abab</code> and <code>abcda</code> are not.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †H, W †100</var></li>
<li><var>a_{ij}</var> is a lowercase English letter.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>a_{11}</var><var>a_{12}</var><var>...</var><var>a_{1W}</var>
<var>:</var>
<var>a_{H1}</var><var>a_{H2}</var><var>...</var><var>a_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Snuke can create a matrix satisfying the condition, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
aabb
aabb
aacc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>For example, the following matrix satisfies the condition.</p>
<pre>abba
acca
abba
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
aa
bb
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>It is not possible to create a matrix satisfying the condition, no matter how we rearrange the elements in <var>A</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 1
t
w
e
e
t
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre>
<p>For example, the following matrix satisfies the condition.</p>
<pre>t
e
w
e
t
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 5
abxba
abyba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>1 1
z
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> |
p01054 |
<h1>String Conversion</h1>
<h2>Problem</h2>
<p>
ãžã§ããã¡ãŒãšããªã¢ã³ã¯ã«ãŒã©ã«æåå<var>S</var>ããã¬ãŒã³ãããŸããã<br>
ããããã«ãŒã©ã¯æåå<var>S</var>ãããã£ãŠãå¬ãããããŸããã<br>
æåå<var>T</var>ãæ¬²ããã£ãã®ã§ãã<br>
3人ã¯ååããŠæåå<var>S</var>ãæåå<var>T</var>ã«å€ããããšã«ããŸããã<br>
</p>
<p>
æåã«ãžã§ããã¡ãŒãæåãä»»æã®é çªã«äžŠã³æ¿ããŸãã
</p>
<p>
次ã«ããªã¢ã³ãïŒçš®é¡ã®ã¢ã«ãã¡ãããã®å°æåã亀æããããšãä»»æã®åæ°è¡ããŸãã<br>
ãã®æäœã§ã¯ãäŸãã°ä»¥äžã®ããã«ãæååäžã®åãæåãå
šãŠäº€æãããŸãã<br>
</p>
<ul>
<li><var>aab</var> → <var>a</var>ãš<var>b</var>ã亀æ → <var>bba</var></li>
<li><var>aab</var> → <var>a</var>ãš<var>c</var>ã亀æ → <var>ccb</var></li>
</ul>
<p>
æåŸã«ã«ãŒã©ããã1æåãå¥ã®1æåã«çœ®æããããšã<var>T</var>ã«ãªããŸã§ç¹°ãè¿ããŸãã<br>
ãžã§ããã¡ãŒãšããªã¢ã³ã¯ã«ãŒã©ã®çœ®æåæ°ãå°ãªããªãããã«ããŠãããããšã«ããŸããã<br>
ã«ãŒã©ãè¡ã眮æã®åæ°ã®æå°å€ãæ±ããŠãã ããã
</p>
<h2>Input</h2>
<pre>
<var>n</var>
<var>S</var>
<var>T</var>
</pre>
<p>
1è¡ç®ã«æååã®é·ã<var>n</var>ãäžããããã<br>
2è¡ç®ã«æåå<var>S</var>ã3è¡ç®ã«æåå<var>T</var>ãäžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>n</var> ≤ 10<sup>5</sup></li>
<li><var>S</var>,<var>T</var>ã¯<var>'a'~'z'</var>ã®ã¿ãå«ã</li>
<li>|<var>S</var>| = |<var>T</var>| = <var>n</var></li>
</ul>
<h2>Output</h2>
<p>
ã«ãŒã©ã®æå°ã®çœ®æåæ°ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3
abc
xyz
</pre>
<h2>Sample Output 1</h2>
<pre>
0
</pre>
<h2>Sample Input 2</h2>
<pre>
5
aaabb
xyxyz
</pre>
<h2>Sample Output 2</h2>
<pre>
1
</pre>
|
p03069 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. Every stone is painted white or black.
A string <var>S</var> represents the color of the stones. The <var>i</var>-th stone from the left is white if the <var>i</var>-th character of <var>S</var> is <code>.</code>, and the stone is black if the character is <code>#</code>.</p>
<p>Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone.
Find the minimum number of stones that needs to be recolored.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2\times 10^5</var></li>
<li><var>S</var> is a string of length <var>N</var> consisting of <code>.</code> and <code>#</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of stones that needs to be recolored.</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>1
</pre>
<p>It is enough to change the color of the first stone to white.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
#.##.
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>9
.........
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p02228 | a |
p00215 |
<H1>ããã¢ã³ã¯ãªãŒãã£ãŒ</H1>
<p>
æåœã§<!--ççºç-->倧人æ°ã®ã²ãŒã ãããã¢ã³ã¯ãªãŒãã£ãŒãæ¥æ¬ã§ãªã¡ã€ã¯ãããŠçºå£²ãããŸããã ã²ãŒã ã倧奜ããªããªãã¯ã ãã®ã²ãŒã ã<!--ä»ãŸã§è²¯ãããå°é£ãã§è³Œå
¥ããäœåºŠããã¬ã€ããŸããããããŠã-->äœåºŠããã¬ã€ãããã¡ã«ã©ããããæéã§ã¯ãªã¢ã§ããã®ãèããããã«ãªããŸããããããããããèããŠãæéã®æ»ç¥æ¹æ³ãããããªãã£ãããªãã¯ãã©ãã ãæ©ãã²ãŒã ãã¯ãªã¢ã§ããããæ±ããããã°ã©ã ãäœæããããšã«ããŸããã
</p>
<p>
ã²ãŒã ã®è©³çްã¯ä»¥äžã®éãã§ãã
</p>
<!--
<p>
ããã¢ã³ã¯ãªãŒãã£ãŒ(以äžãããã¯ãª)ãšããçç©ãå€ãååšããäžçãã²ãŒã ã®èå°ã§ããåããã¯ãªã¯ãç«å±æ§ãæ°·å±æ§ãæšå±æ§ãå屿§ãæ°Žå±æ§ã® 5 çš®é¡ã®å±æ§ã®ããããäžå±æ§ãæã¡ãŸããã²ãŒã ã®äž»äººå
¬ã§ãã E åã¯ãè¿æã«äœãã§ãã芪åãªãããããã奜ããªå±æ§ã®ããã¯ãªäžå¹ãåéºã®ããŒãããŒãšããŠåãåããŸãããã®ããã¯ãªãšå
±ã«ãŽãŒã«ãç®æãããŽãŒã«ã«ããã©ã€ãã«ãåããŠããã¯ãªãã¹ã¿ãŒã«ãªãããšã䞻人å
¬ã®å€¢ã§ãããã²ãŒã ã¯ãªã¢ã§ããããŸãã
</p>
-->
<p>
ããã¢ã³ã¯ãªãŒãã£ãŒ(以äžãããã¯ãª)ãšããçç©ãå€ãååšããäžçãã²ãŒã ã®èå°ã§ããåããã¯ãªã¯ãç«å±æ§ãæ°·å±æ§ãæšå±æ§ãå屿§ãæ°Žå±æ§ã® 5 çš®é¡ã®å±æ§ã®ããããïŒã€ã®å±æ§ãæã¡ãŸããã²ãŒã ã®äž»äººå
¬ã¯ãã²ãŒã éå§æã«å¥œããªå±æ§ã®ããã¯ãªäžå¹ãåéºã®ããŒãããŒãšããŠéžã³ãŸãããã®ããã¯ãªãšå
±ã«ãŽãŒã«ãç®æãããŽãŒã«ã«ããã©ã€ãã«ãåããŠããã¯ãªãã¹ã¿ãŒã«ãªãããšãã²ãŒã ã®ç®çã§ãã
</p>
<p>
ããããã©ã€ãã«ãåãããã«ã¯å
šå±æ§ã®ããã¯ãªãããªããšåãŠãªãã®ã§ãéäžã§å
šå±æ§ã®ããã¯ãªãæãŸããªããã°ãªããŸãããããã¯ãªãæãŸããã«ã¯å±æ§ãã«ã®ãšãªããŸããç«å±æ§ã®ããã¯ãªã¯æ°·å±æ§ã®ããã¯ãªãæãŸããããšãã§ããåæ§ã«ãæ°·å±æ§ã¯æšå±æ§ãæšå±æ§ã¯å屿§ãå屿§ã¯æ°Žå±æ§ãæ°Žå±æ§ã¯ç«å±æ§ãæãŸããããšãã§ããŸãã屿§ã®é¢é£ã¯ä»¥äžã®å³ã®ããã«ãªããŸãã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pachimon1" width="30%" >
</center>
<br>
<p>
以äžã®å³ã¯ã²ãŒã ãè¡ããããããã®äžäŸã衚ããŠããŸãã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pachimon2" width="60%" >
</center>
<br>
<p>
䞻人å
¬ã¯ããã¯ãªãäžå¹ãã£ãŠã¹ã¿ãŒãå°ç¹ã§ãããSãããåºçºããäžãã¹ãã€ç§»åããªãããŽãŒã«å°ç¹ã§ãããGããç®æããŸãããã®éäžã§ãæåã«æã£ãŠããããã¯ãªä»¥å€ã® 4 ã€ã®å±æ§ã®ããã¯ãªãæãŸãããŽãŒã«å°ç¹ã§ãããã¹ç®ã«ç§»åãããšã²ãŒã çµäºãšãªããŸãã
</p>
<p>
䞻人å
¬ã¯ãä»ãããã¹ç®ããã蟺ãå
±æããé£ã®ãã¹ç®ã«ç§»åããããšãã§ãããããäžåã®ç§»åãšæ°ããŸãã䞻人å
¬ãããã¯ãªã®ãããã¹ã«ç§»åããå Žåããã®ããã¯ãªãæãŸãããã屿§ã®ããã¯ãªãæã£ãŠããã°ãã®ããã¯ãªãæãŸããããšã«ãªããŸãããã®ãã¹ã«ããããã¯ãªãæãŸãããããã®å¯åŠã«ãããããããã¹ãŠã®ãã¹ã«äœåºŠã§ãç§»åããããšãã§ããŸãã
</p>
<p>
ãããã®å€§ãã(暪æ¹åã®åæ°ã瞊æ¹åã®è¡æ°)ãšãããã®åæç¶æ
ãå
¥åãšããåãã«éžãã ããã¯ãªã®å±æ§ãšããã以å€ã® 4 ã€ã®å±æ§ã®ããã¯ãªãæãŸããã®ã«ããããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ã«è³ãæå°ç§»åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµãã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>W</var> <var>H</var>
<var>c<sub>11</sub></var><var>c<sub>12</sub></var>...<var>c<sub>1W</sub></var>
<var>c<sub>21</sub></var><var>c<sub>22</sub></var>...<var>c<sub>2W</sub></var>
:
<var>c<sub>H1</sub></var><var>c<sub>H2</sub></var>...<var>c<sub>HW</sub></var>
</pre>
<p>
1 è¡ç®ã«ãããã®æšªæ¹åã®åæ° <var>W</var> ãšçžŠæ¹åã®è¡æ° <var>H</var> (2 ≤ <var>W, H</var> ≤ 1000) ãäžããããŸããç¶ã <var>H</var> è¡ã«ãããã® <var>i</var> è¡ç®ã®æ
å ±ãäžããããŸããå
¥åããããããã«ã¯åãã¹ã®ç¶æ
ãäžããããŸãã ãSãã¯äž»äººå
¬ã®ã¹ã¿ãŒãå°ç¹ãã ãGãã¯ãŽãŒã«å°ç¹ããã1ãã2ãã3ãã4ãã5ãã¯ããã«ããããã¯ãªã®å±æ§ã( 1:ç«å±æ§ã 2:æ°·å±æ§ã 3:æšå±æ§ã 4:å屿§ã 5:æ°Žå±æ§ ããããã衚ããŸã)ã ã.(ããªãªã) ãã¯äœããªããã¹ããããã衚ããŸãã
å屿§ã®ããã¯ãªã®æ°ã¯ãããã 0 ä»¥äž 1000 以äžãšããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯140 ãè¶
ããŸããããŸããããŒã¿ã»ããã® 80 % ã«ã€ããŠã<var>W, H</var> ã¯100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ãæåã«éžãã ããã¯ãªã®å±æ§ãšæå°ç§»åæ°ãïŒè¡ã«åºåããŸãããªããã©ã®ããã«åãã®ããã¯ãªãéžãã§ããã©ã®ãããªçµè·¯ã§ç§»åããŠãããã 4 ã€ã®å±æ§ã®ããã¯ãªãæãŸããããšãã§ããªãå Žå㯠NA ãšåºåããŠãã ããã ãŸããæå°ç§»åæ°ãåãã«ãªããããªæåã®ããã¯ãªã®éžã³æ¹ãè€æ°ããå Žåã¯ã屿§ã®æ°åãå°ãããã®ãåºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
6 6
S.1..4
3..5..
..4.1.
4....5
.2.32.
5.1..G
3 2
...
S.G
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2 10
NA
</pre>
|
p02382 |
<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>Distance II</h1><br>
<p>
Your task is to calculate the distance between two $n$ dimensional vectors $x = \{x_1, x_2, ..., x_n\}$ and $y = \{y_1, y_2, ..., y_n\}$.
</p>
<p>
The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance.
<br>
\[
D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}}
\]
<br>
It can be the Manhattan distance
<br>
\[
D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n|
\]
<br>
where $p = 1 $.
<br>
<br>
It can be the Euclidean distance
<br>
\[
D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n - y_n|)^{2}}
\]
<br>
where $p = 2 $.
<br>
<br>
Also, it can be the Chebyshev distance
<br>
<br>
\[
D_{xy} = max_{i=1}^n (|x_i - y_i|)
\]
<br>
<br>
where $p = \infty$
</p>
<p>
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively.
</p>
<h2>Input</h2>
<p>
In the first line, an integer $n$ is given. In the second and third line, $x = \{x_1, x_2, ... x_n\}$ and $y = \{y_1, y_2, ... y_n\}$ are given respectively. The elements in $x$ and $y$ are given in integers.
</p>
<h2>Output</h2>
<p>
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10<sup>-5</sup>.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 100$</li>
<li>$0 \leq x_i, y_i \leq 1000$</li>
</ul>
<h2>Sample Input</h2>
<pre>
3
1 2 3
2 0 4
</pre>
<h2>Sample Output</h2>
<pre>
4.000000
2.449490
2.154435
2.000000
</pre>
|
p02678 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>There is a cave.</p>
<p>The cave has <var>N</var> rooms and <var>M</var> passages. The rooms are numbered <var>1</var> to <var>N</var>, and the passages are numbered <var>1</var> to <var>M</var>. Passage <var>i</var> connects Room <var>A_i</var> and Room <var>B_i</var> bidirectionally. One can travel between any two rooms by traversing passages. Room <var>1</var> is a special room with an entrance from the outside.</p>
<p>It is dark in the cave, so we have decided to place a signpost in each room except Room <var>1</var>. The signpost in each room will point to one of the rooms directly connected to that room with a passage.</p>
<p>Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room <var>1</var>.</p>
<ul>
<li>If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room <var>1</var> after traversing the minimum number of passages possible.</li>
</ul>
<p>Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>All values in input are integers.</li>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq M \leq 2 \times 10^5</var></li>
<li><var>1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)</var></li>
<li><var>A_i \neq B_i\ (1 \leq i \leq M)</var></li>
<li>One can travel between any two rooms by traversing passages.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A_1</var> <var>B_1</var>
<var>:</var>
<var>A_M</var> <var>B_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>If there is no way to place signposts satisfying the objective, print <code>No</code>.</p>
<p>Otherwise, print <var>N</var> lines. The first line should contain <code>Yes</code>, and the <var>i</var>-th line <var>(2 \leq i \leq N)</var> should contain the integer representing the room indicated by the signpost in Room <var>i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 4
1 2
2 3
3 4
4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
1
2
2
</pre>
<p>If we place the signposts as described in the sample output, the following happens:</p>
<ul>
<li>Starting in Room <var>2</var>, you will reach Room <var>1</var> after traversing one passage: <var>(2) \to 1</var>. This is the minimum number of passages possible.</li>
<li>Starting in Room <var>3</var>, you will reach Room <var>1</var> after traversing two passages: <var>(3) \to 2 \to 1</var>. This is the minimum number of passages possible.</li>
<li>Starting in Room <var>4</var>, you will reach Room <var>1</var> after traversing two passages: <var>(4) \to 2 \to 1</var>. This is the minimum number of passages possible.</li>
</ul>
<p>Thus, the objective is satisfied.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 9
3 4
6 1
2 4
5 3
4 6
1 5
6 2
4 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Yes
6
5
5
1
1
</pre>
<p>If there are multiple solutions, any of them will be accepted.</p></section>
</div>
</span> |
p00645 |
<H1><font color="#000000">Problem I:</font> Mysterious Onslaught</H1>
<p>
In 2012, human beings have been exposed to fierce onslaught of unidentified mysterious extra-terrestrial creatures. We have exhaused because of the long war and can't regist against them any longer. Only you, an excellent wizard, can save us. Yes, it's time to stand up!
</p>
<p>
The enemies are dispatched to the earth with being aligned like an <i>n</i> * <i>n</i> square. Appearently some of them have already lost their fighting capabilities for some unexpected reason. You have invented a highest grade magic spell 'MYON' to defeat them all. An attack of this magic covers any rectangles (which is parallel to axis). Once you cast a spell "myon," then all the enemies which the magic covers will lose their fighting capabilities because of tremendous power of the magic. However, the magic seems to activate enemies' self-repairing circuit. Therefore if any enemy which have already lost its fighting capability is exposed to the magic, the enemy repossesses its fighting capability. You will win the war when all the enemies will lose their fighting capabilities.
</p>
<p>
Let me show an example. An array of enemies below have dispatched:
</p>
<pre>
1 1 1 1 1
1 0 0 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 1
</pre>
<p>
Here, '<span>0</span>' means an enemy that doesn't possess fighting capability, and '<span>1</span>' means an enemy that possesses.
First, you cast a spell "<span>myon</span>" with covering all the enemies, which results in;
</p>
<pre>
0 0 0 0 0
0 1 1 1 0
0 1 0 1 0
0 1 1 1 0
0 0 0 0 0
</pre>
<p>
Next, cast once again with covering central 3 * 3 enemies.
</p>
<pre>
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
</pre>
<p>
Now you can defeat them all by casting a spell covers remaining one. Therefore you can cast "<span>myonmyonmyon</span>," which is the shortest spell for this case.
</p>
<p>
You are given the information of the array. Please write a program that generates the shortest spell that can defeat them all.
</p>
<H2>Input</H2>
<p>
The first line of each test case has an integer <i>n</i>. Following <i>n</i> lines are information of an array of enemies. The format is same as described in the problem statement.
</p>
<p>
Input terminates when n = 0.
You may assume that one or more enemy have fighting capability.
</p>
<H2>Output</H2>
<p>
For each dataset, output the shortest spell.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 5</li>
</ul>
<H2>Sample Input</H2>
<pre>
5
1 1 1 1 1
1 0 0 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 1
3
1 1 1
1 1 1
1 1 1
5
1 1 1 1 0
1 1 1 1 0
1 0 0 0 1
0 1 1 1 1
0 1 1 1 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
myonmyonmyon
myon
myonmyon
</pre>
|
p01957 |
<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>
Tournament Chart
</H1>
<p>
In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events.
</p>
<p>
JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '<span>[[a-b]-[c-d]]</span>' is an easy example. In this case, there are 4 contestants named a, b, c, and d, and all matches are described as follows:
</p>
<ul>
<li>Match 1 is the match between a and b.</li>
<li>Match 2 is the match between c and d.</li>
<li>Match 3 is the match between [the winner of match 1] and [the winner of match 2].</li>
</ul>
<p>
More precisely, the tournament chart satisfies the following BNF:
</p>
<ul>
<li><winner> ::= <person> | "[" <winner> "-" <winner> "]"</li>
<li><person> ::= "a" | "b" | "c" | ... | "z"</li>
</ul>
<p>
You, the chairperson of JAG, are planning to announce the results of this year's JAG competition. However, you made a mistake and lost the results of all the matches. Fortunately, you found the tournament chart that was printed before all of the matches of the tournament. Of course, it does not contains results at all. Therefore, you asked every contestant for the number of wins in the tournament, and got $N$ pieces of information in the form of "The contestant $a_i$ won $v_i$ times".
</p>
<p>
Now, your job is to determine whether all of these replies can be true.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case in the format below.
</p>
<pre>
$S$
$a_1$ $v_1$
:
$a_N$ $v_N$
</pre>
<p>
$S$ represents the tournament chart. $S$ satisfies the above BNF. The following $N$ lines represent the information of the number of wins. The ($i+1$)-th line consists of a lowercase letter $a_i$ and a non-negative integer $v_i$ ($v_i \leq 26$) separated by a space, and this means that the contestant $a_i$ won $v_i$ times. Note that $N$ ($2 \leq N \leq 26$) means that the number of contestants and it can be identified by string $S$. You can assume that each letter $a_i$ is distinct. It is guaranteed that $S$ contains each $a_i$ exactly once and doesn't contain any other lowercase letters.
</p>
<H2>Output</H2>
<p>
Print '<span>Yes</span>' in one line if replies are all valid for the tournament chart. Otherwise, print '<span>No</span>' in one line.
</p>
<H2>Sample Input 1</H2>
<pre>
[[m-y]-[a-o]]
o 0
a 1
y 2
m 0
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
Yes
</pre>
<H2>Sample Input 2</H2>
<pre>
[[r-i]-[m-e]]
e 0
r 1
i 1
m 2
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
No
</pre> |
p00995 |
<h1>Problem F : Dungeon (I)</h1>
<p>
ããªãã¯ãšããã²ãŒã ã®éçºã«æºãã£ãŠããã
ãã®ã²ãŒã ã¯ã©ã³ãã ã«çæããããã³ãžã§ã³ããã¬ã€ã€ãŒãæ¢çŽ¢ãããšãããã®ã§ããã
</p>
<p>
ãã®ã²ãŒã ã§çæããããã³ãžã§ã³ã«ã¯<i>n</i> åã®éšå±ãååšããŠããã0ãã <i>n-1</i> ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã
éšå±ãšéšå±ã¯éè·¯ã§çµã°ããŠãããéšå±ãšéšå±ãçµã¶éè·¯ã¯ã<i>m</i> æ¬ããã
éè·¯ã¯ã©ã¡ãã®æ¹åãžãé²ãããšãã§ããã
ãŸããéšå±ãšéšå±ã®éã«ã¯è·é¢ãèšå®ãããŠããã
çæããããã³ãžã§ã³ã§ã¯ããã€ãã®éè·¯ãçµç±ããŠãããéšå±ããä»ã®ãã¹ãŠã®éšå±ãžè¡ãããšãå¯èœã§ããã
ãããŠããã¬ã€ã€ãŒãã²ãŒã ãè¡ãéã«ã0çªã®éšå±ãã¹ã¿ãŒãå°ç¹ã<i>n-1</i> çªã®éšå±ããŽãŒã«å°ç¹ãšããŠéžã°ããã
</p>
<p>
ãŠãŒã¶ãŒããã³ãžã§ã³ãæ¢çŽ¢ããéã«ãæå©ãã«ãªããããªã¢ã€ãã ãå
¥ã£ãå®ç®±ããã©ããã®éšå±ã«èšçœ®ãããã
ãã®æã«ãã¹ã¿ãŒãå°ç¹ããé ããããããŽãŒã«å°ç¹ããè¿ããããšæå³ããªãã
ããã§ãã¹ã¿ãŒãããè·é¢ <i>fs</i> 以å
ã§èŸ¿ãã€ããŠããŽãŒã«ã«èŸ¿ãçãããã«æççµè·¯ãéã£ãå Žåã«ãå°ãªããšã <i>fg</i> ãããéšå±ãå®ç®±ãèšçœ®ããåè£ãšãããã
</p>
<p>
çæããããã³ãžã§ã³ãšã<i>q</i> ãäžããããã<i>q</i> åã®ã¯ãšãªãŒã«ã€ããŠãå®ç®±ãèšçœ®ããå Žæã®åè£ã®æ°ãæ°ããŠæ¬²ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>n</i> <i>m</i>
<i>a<sub>1</sub></i> <i>b<sub>1</sub></i> <i>c<sub>1</i></i>
.
.
.
<i>a<sub>m</sub></i> <i>b<sub>m</sub></i> <i>c<sub>m</i></i>
<i>q</i>
<i>fs<sub>1</sub></i> <i>fg<sub>1</sub></i>
.
.
.
<i>fs<sub>q</sub></i> <i>fg<sub>q</sub></i>
</pre>
<p>
<i>a<sub>i</sub></i> <i>b<sub>i</sub></i> <i>c<sub>i</sub></i> 㯠éšå± <i>a<sub>i</sub></i> ãš <i>b<sub>i</sub></i>ããçµã¶éè·¯ã®è·é¢ã<i>c<sub>i</sub></i>ã§ããããšã衚ãã
</p>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºãã<br>
2 ≤ <i>n</i> ≤ 100,000 <br>
0 ≤ <i>a<sub>i</sub></i> , <i>b<sub>i</sub></i> < <i>n</i><br>
0 ≤ <i>c<sub>i</sub></i> ≤ 100,000<br>
<i>n-1</i> ≤ <i>m</i> ≤ 100,000<br>
1 ≤ <i>q</i> ≤ 100,000<br>
0 ≤ <i>fs<sub>i</sub></i> , <i>fg<sub>i</sub></i> ≤ 2<sup>60</sup>
</p>
<h2>Output</h2>
<p>
åã¯ãšãªãŒã«ã€ããŠãçãã®å€ã1è¡ã«åºåãã
</p>
<h2>Sample Input 1</h2>
<pre>
4 4
0 1 3
1 3 4
0 2 2
2 3 1
4
0 0
2 2
2 1
3 4
</pre>
<h2>Sample Output 1</h2>
<pre>
1
1
2
1
</pre>
|
p01687 |
<h2>A - D's Ambition / Dã®ããŒã</h2>
<h3>Story</h3>
<p>ãããã«ããã¯è¥ã¶æŸé«æ ¡ã®ããã°ã©ãã³ã°ã³ã³ãã¹ãéšãéç§°ã·ãããéšã«æå±ãã2幎çã§ããããããããDã®ã²ãšã¯å€©äœ¿ã®ããšããããããããã«ããã«ãã£ããã§ãããéããã°ãºããºãããããšç»çãã倿
ã§ããããã®æã¯çå¥çã§ããããããã«ãããèªåè²ã«æããããšã"AIZUNYAN"ãšããæååãèŠã床"AIDUNYAN"ã«æžãæããŠããŸããããã«ãããã«ãããèªåã ãã®ãã®ã«ãããããä»ã®äººã«æ°ã¥ãããªãããã«ãã®æååããã©ãã©ã«äžŠã¹æ¿ããŠããŸããããã³ã³ã®åéã»åŸåœé€šå€§åŠäžçéšåã®ãšãªãŒãç«¶æããã°ã©ãã§ãããã·ãããéšã®éšé·ã§ãããã£ã€ã¡ããã¯ããããã«ãããDã®ã²ãšã®éã®æããæããããDã®ã²ãšãæ¹å€ããæååããã¹ãŠåŸ©å
ããããšã«ããã</p>
<h3>Problem</h3>
<p>è±å€§æåã®ã¿ãããªãæåå<var>Z</var>ããããæåå<var>Z</var>äžã«çŸãããã¹ãŠã®éšåæåå"AIZUNYAN"ã«å¯Ÿããåå¥ã«"AIDUNYAN"ã®ä»»æã®ã¢ãã°ã©ã ãçæãã眮ãæããããšã§åŸãããæååã<var>D</var>ãšãããããã§ãæåå<var>S</var>ã®ã¢ãã°ã©ã ãšã¯ã<var>S</var>ã«çŸããæåãäžŠã³æ¿ããŠåŸãããæååã®ããšããããæåå<var>D</var>ãå
¥åãšããŠäžããããã®ã§ãæåå<var>Z</var>ã埩å
ããã ãã ããæåå<var>D</var>ã«å«ãŸãã"AIDUNYAN"ã®ã¢ãã°ã©ã ã¯ãã¹ãŠã"AIZUNYAN"ãã眮ãæãããããã®ã®ã¿ã§ãããšä»®å®ããŠããããŸãã<var>D</var>äžã®ä»»æã®æå<var>D_i</var>ã«ã€ããŠã<var>D_i</var>ãå«ã¿ããã€"AIDUNYAN"ã®ã¢ãã°ã©ã ã§ããéšåæååã¯é«ã
1ã€ãããªããšä»®å®ããŠããã</p>
<h3>Input</h3>
<pre><var>D</var></pre>
<p>å
¥åã¯<var>1</var>è¡ã§äžããããè±å€§æåã®ã¿ãããªãæåå<var>D</var>ãå«ããæåå<var>D</var>ã®é·ã|<var>D</var>|ã¯<var>1 \leq |D| \leq 10^3</var>ãæºããã</p>
<h3>Output</h3>
<p><var>D</var>ã埩å
ããæåå<var>Z</var>ã<var>1</var>è¡ã«åºåãããè¡ã®æåŸã§ã¯å¿
ãæ¹è¡ãè¡ãããšã</p>
<h3>Sample Input 1</h3>
<pre>AIDUNYAN</pre>
<h3>Sample Output 1</h3>
<pre>AIZUNYAN</pre>
<p>Dã®éã®æããæãããšãã§ããã</p>
<h3>Sample Input 2</h3>
<pre>ZDD</pre>
<h3>Sample Output 2</h3>
<pre>ZDD</pre>
<p>æååé·ã<var>8</var>æåæªæºã§ãã£ããã"AIDUNYAN"ã®ã¢ãã°ã©ã ãå«ãŸãªãããšãããã</p>
<h3>Sample Input 3</h3>
<pre>AADINNUYHAMAJIDETENSHIDAKARANYANAIDUPEROPEROSHITAI</pre>
<h3>Sample Output 3</h3>
<pre>AIZUNYANHAMAJIDETENSHIDAKARAAIZUNYANPEROPEROSHITAI</pre>
<p><var>2</var>ç®æä»¥äžå«ãŸããŠããå Žåã¯ãã¹ãŠåŸ©å
ããããºããºãã</p>
<h3>Sample Input 4</h3>
<pre>NYANAIDUAIDU</pre>
<h3>Sample Output 4</h3>
<pre>AIZUNYANAIDU</pre>
<p>埩å
åŸã®æåå<var>Z</var>ã«"AIDUNYAN"ã®ã¢ãã°ã©ã ãçŸããå Žåããããã埩å
åã®æåå<var>D</var>ã«ãããŠã¢ãã°ã©ã ã§ãªãéšåãªãã°å€æŽããªãããšã«æ³šæããã</p> |
p03340 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is an integer sequence <var>A</var> of length <var>N</var>.</p>
<p>Find the number of the pairs of integers <var>l</var> and <var>r</var> (<var>1 \leq l \leq r \leq N</var>) that satisfy the following condition:</p>
<ul>
<li><var>A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r</var></li>
</ul>
<p>Here, <var>xor</var> denotes the bitwise exclusive OR.</p>
<p><details>
<summary style="display:list-item">Definition of XOR</summary></details></p>
<p>The XOR of integers <var>c_1, c_2, ..., c_m</var> is defined as follows:</p>
<ul>
<li>Let the XOR be <var>X</var>. In the binary representation of <var>X</var>, the digit in the <var>2^k</var>'s place (<var>0 \leq k</var>; <var>k</var> is an integer) is <var>1</var> if there are an odd number of integers among <var>c_1, c_2, ...c_m</var> whose binary representation has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> if that number is even.</li>
</ul>
<p>For example, let us compute the XOR of <var>3</var> and <var>5</var>. The binary representation of <var>3</var> is <var>011</var>, and the binary representation of <var>5</var> is <var>101</var>, thus the XOR has the binary representation <var>110</var>, that is, the XOR is <var>6</var>.</p>
<p></p></section></div></span> |
p02802 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi participated in a contest on AtCoder.</p>
<p>The contest had <var>N</var> problems.</p>
<p>Takahashi made <var>M</var> submissions during the contest.</p>
<p>The <var>i</var>-th submission was made for the <var>p_i</var>-th problem and received the verdict <var>S_i</var> (<code>AC</code> or <code>WA</code>).</p>
<p>The number of Takahashi's correct answers is the number of problems on which he received an <code>AC</code> once or more.</p>
<p>The number of Takahashi's penalties is the sum of the following count for the problems on which he received an <code>AC</code> once or more: the number of <code>WA</code>s received before receiving an <code>AC</code> for the first time on that problem.</p>
<p>Find the numbers of Takahashi's correct answers and penalties.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var>, <var>M</var>, and <var>p_i</var> are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>0 \leq M \leq 10^5</var></li>
<li><var>1 \leq p_i \leq N</var></li>
<li><var>S_i</var> is <code>AC</code> or <code>WA</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>M</var>
<var>p_1</var> <var>S_1</var>
<var>:</var>
<var>p_M</var> <var>S_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of Takahashi's correct answers and the number of Takahashi's penalties.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 5
1 WA
1 AC
2 WA
2 AC
2 WA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 2
</pre>
<p>In his second submission, he received an <code>AC</code> on the first problem for the first time. Before this, he received one <code>WA</code> on this problem.</p>
<p>In his fourth submission, he received an <code>AC</code> on the second problem for the first time. Before this, he received one <code>WA</code> on this problem.</p>
<p>Thus, he has two correct answers and two penalties.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100000 3
7777 AC
7777 AC
7777 AC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 0
</pre>
<p>Note that it is pointless to get an <code>AC</code> more than once on the same problem.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0 0
</pre></section>
</div>
</span> |
p03710 | <span class="lang-en">
<p>Score : <var>1700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Kenus, the organizer of <em>International Euclidean Olympiad</em>, is seeking a pair of two integers that requires many steps to find its greatest common divisor using the Euclidean algorithm.</p>
<p>You are given <var>Q</var> queries. The <var>i</var>-th query is represented as a pair of two integers <var>X_i</var> and <var>Y_i</var>, and asks you the following: among all pairs of two integers <var>(x,y)</var> such that <var>1 †x †X_i</var> and <var>1 †y †Y_i</var>, find the maximum <em>Euclidean step count</em> (defined below), and how many pairs have the maximum step count, modulo <var>10^9+7</var>.</p>
<p>Process all the queries. Here, the Euclidean step count of a pair of two non-negative integers <var>(a,b)</var> is defined as follows:</p>
<ul>
<li><var>(a,b)</var> and <var>(b,a)</var> have the same Euclidean step count.</li>
<li><var>(0,a)</var> has a Euclidean step count of <var>0</var>.</li>
<li>If <var>a > 0</var> and <var>a †b</var>, let <var>p</var> and <var>q</var> be a unique pair of integers such that <var>b=pa+q</var> and <var>0 †q < a</var>. Then, the Euclidean step count of <var>(a,b)</var> is the Euclidean step count of <var>(q,a)</var> plus <var>1</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †Q †3 à 10^5</var></li>
<li><var>1 †X_i,Y_i †10^{18}(1 †i †Q)</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>Q</var>
<var>X_1</var> <var>Y_1</var>
<var>:</var>
<var>X_Q</var> <var>Y_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each query, print the maximum Euclidean step count, and the number of the pairs that have the maximum step count, modulo <var>10^9+7</var>, with a space in between.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
4 4
6 10
12 11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 4
4 1
4 7
</pre>
<p>In the first query, <var>(2,3)</var>, <var>(3,2)</var>, <var>(3,4)</var> and <var>(4,3)</var> have a Euclidean step count of <var>2</var>. No pairs have a step count of more than <var>2</var>.</p>
<p>In the second query, <var>(5,8)</var> has a Euclidean step count of <var>4</var>.</p>
<p>In the third query, <var>(5,8)</var>, <var>(8,5)</var>, <var>(7,11)</var>, <var>(8,11)</var>, <var>(11,7)</var>, <var>(11,8)</var>, <var>(12,7)</var> have a Euclidean step count of <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10
1 1
2 2
5 1000000000000000000
7 3
1 334334334334334334
23847657 23458792534
111111111 111111111
7 7
4 19
9 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 1
1 4
4 600000013
3 1
1 993994017
35 37447
38 2
3 6
3 9
4 2
</pre></section>
</div>
</span> |
p00096 |
<H1>ïŒã€ã®æŽæ°ã®å II</H1>
<p>
4,000 以äžã®æ£ã®æŽæ° <var>n</var> ãå
¥åãã0 ã 1000 ã®ç¯å²ã®æŽæ° <var>a, b, c, d</var> ã®çµã§</p>
<pre>
<var>a + b + c + d = n</var>
</pre>
<p>ãæºãããã®ã®çµã¿åããæ°ãåºåããããã°ã©ã ãäœæããŠäžããã</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã« <var>n</var> ãïŒè¡ã«äžããããŸããå
¥åã®æåŸãŸã§åŠçããŠäžããã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ã<var>a, b, c, d</var> ã®çµã¿åããã®åæ°ãïŒè¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
2
3
35
</pre>
<H2>Output for the Sample Input</H2>
<pre>
10
20
8436
</pre>
|
p02551 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with <var>N</var> rows and <var>N</var> columns of squares. Let <var>(i, j)</var> be the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p>
<p>Each of the central <var>(N-2) \times (N-2)</var> squares in the grid has a black stone on it.
Each of the <var>2N - 1</var> squares on the bottom side and the right side has a white stone on it.</p>
<p><var>Q</var> queries are given. We ask you to process them in order.
There are two kinds of queries. Their input format and description are as follows:</p>
<ul>
<li><code>1 x</code>: Place a white stone on <var>(1, x)</var>. After that, for each black stone between <var>(1, x)</var> and the first white stone you hit if you go down from <var>(1, x)</var>, replace it with a white stone.</li>
<li><code>2 x</code>: Place a white stone on <var>(x, 1)</var>. After that, for each black stone between <var>(x, 1)</var> and the first white stone you hit if you go right from <var>(x, 1)</var>, replace it with a white stone.</li>
</ul>
<p>How many black stones are there on the grid after processing all <var>Q</var> queries?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 2\times 10^5</var></li>
<li><var>0 \leq Q \leq \min(2N-4,2\times 10^5)</var></li>
<li><var>2 \leq x \leq N-1</var></li>
<li>Queries are pairwise distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Q</var>
<var>Query_1</var>
<var>\vdots</var>
<var>Query_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print how many black stones there are on the grid after processing all <var>Q</var> queries.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 5
1 3
2 3
1 4
2 2
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>After each query, the grid changes in the following way:</p>
<p><img alt="Figure" src="https://img.atcoder.jp/ghi/31ba2cd6b3155b137f0e007299225028.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>200000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>39999200004
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>176527 15
1 81279
2 22308
2 133061
1 80744
2 44603
1 170938
2 139754
2 15220
1 172794
1 159290
2 156968
1 56426
2 77429
1 97459
2 71282
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>31159505795
</pre></section>
</div>
</span> |
p02101 |
<h1>Problem D: Let's Go To School</h1>
<h2>Problem</h2>
<p>
ãã£ã¡ãåã¯ææ«è©Šéšãè¿ã¥ããšããæ°ããªããªã£ãŠããŸãããã°ãã°åŠæ ¡ãäŒãããã«ãªãã<br>
ææ«è©ŠéšãŸã§æ®ã<var>N</var>æ¥ã§ããã<br>
ãã£ã¡ãåã®<var>i</var>æ¥ç®ã®ããæ°ã¯<var>X<sub>i</sub></var>ã§ããã<var>i</var>æ¥ç®ã«åŠæ ¡ã«è¡ãããã«å¿
èŠãªããæ°ã¯<var>Y<sub>i</sub></var>ã§ããã<br>
ãã£ã¡ãå㯠<var>X<sub>i</sub></var> ≥ <var>Y<sub>i</sub></var> ãšãªãæ¥ã®ã¿åŠæ ¡ã«è¡ãã<br>
ãã£ã¡ãåãå¿é
ããããžåã¯ããã£ã¡ãåãå±ãŸãããšã§ãå¯èœãªéãåŠæ ¡ã«è¡ãããããšèããã<br>
ããžåã¯æåãå±ãŸãå<var>P</var>ãæã£ãŠããã<br>
ããžåã<var>i</var>æ¥ç®ã«å±ãŸãå<var>t</var>(<var>t</var>ã¯0以äžã®ä»»æã®å®æ°)ãæ¶è²»ããŠãã£ã¡ãåãå±ãŸããšã
ãã£ã¡ãåã®<var>i</var>æ¥ç®ã®ããæ°ã¯<var>t</var>ã ãå¢å ããŠãããžåã®å±ãŸãåã¯<var>t</var>ã ãæžå°ãããããã«ã<var>i</var>+1 ≤ <var>N</var>ã®ãšãã<var>i</var>+1æ¥ç®ã®ãã£ã¡ãåã®ããæ°<var>X<sub>i+1</sub></var>ã¯max(0, <var>X<sub>i+1</sub></var> − <var>t</var>) ã«å€åããã<br>
ããžåã¯èªåã®æã£ãŠããå±ãŸãåãè¶
ããŠå±ãŸãããšã¯ã§ããªãã
</p>
<p>
ããžåãæé©ãªå±ãŸãæ¹ããããšãã®ããã£ã¡ãåãåŠæ ¡ã«è¡ãæå€§æ¥æ°ãæ±ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var> <var>P</var>
<var>X<sub>1</sub></var> <var>Y<sub>1</sub></var>
<var>X<sub>2</sub></var> <var>Y<sub>2</sub></var>
...
<var>X<sub>N</sub></var> <var>Y<sub>N</sub></var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«ææ«è©ŠéšãŸã§ã®æ¥æ°<var>N</var>ãšããžåãæåã«æã£ãŠããå±ãŸãå<var>P</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ããç¶ã<var>N</var>è¡ã«ã¯ãã£ã¡ãåã®<var>i</var>(<var>i</var>=1,2,...,<var>N</var>)æ¥ç®ã®ããæ°<var>X<sub>i</sub></var>ãšåŠæ ¡ã«è¡ãããã«å¿
èŠãªããæ°<var>Y<sub>i</sub></var>ã空çœåºåãã§äžããããã<br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>1 ≤ <var>N</var> ≤ 100</li>
<li>0 ≤ <var>P</var> ≤ 10<sup>6</sup></li>
<li>0 ≤ <var>X<sub>i</sub></var> ≤ 10<sup>6</sup></li>
<li>0 ≤ <var>Y<sub>i</sub></var> ≤ 10<sup>6</sup></li>
</ul>
<h2>Output</h2>
<p>
ãã£ã¡ãåãåŠæ ¡ã«è¡ãããšãã§ããæå€§ã®æ¥æ°ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 10
1 6
5 10
0 5
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5
1 1
1 2
1 2
1 3
1 3
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
|
p00429 |
<H1></H1>
<p>
0 ãã 9 ãŸã§ã®æ°åã ãã§æ§æãããæååãäžãããããšã,ãã®æååããæ¬¡ã®èŠåã«åŸã£ãŠæ°ããæååãäœãæäœãèãã.äžããããæååã巊端ãã1æåãã€é ã«èªãã§è¡ã,åãæ°å <i>a</i> ã <i>r</i> åç¶ããŠããå Žå,åæ° <i>r</i> ãšæ°å<i>a</i> ã空çœã§åºåããã«ãã®é ã§æžãåºã.äžããããæååã®å³ç«¯ãŸã§èªã¿,æåŸã®æžãåºããçµãã£ããšãããŸã§ãéäžäœåæžãåºãããã£ããšããŠãå
šéšãŸãšããŠæäœ1åãšã«ãŠã³ããã.2åç®ä»¥éã®æäœã¯ååã®æäœã«ããæžãåºãããæååãäžããããæååãšããŠåæ§ã®æäœã宿œãã.äŸãã° â<span>122244</span>â ãšããæååãäžããããå Žåã«ã¯å·Šç«¯ããé ã«1åã®1, 3åã®2,2åã®4ãªã®ã§ãã®æäœ1åã§åŸãããæåå㯠â<span>113224</span>â ã§ãã,â<span>44444444444</span>â (11 åã®4)ã®å Žåã«ã¯åŸãããæåå㯠â<span>114</span>â ãšãªã.
</p>
<p>
100 æå以äžã®äžããããæååã«äžã®æäœã <i>n</i> å宿œããæååãåºåããããã°ã©ã ãäœæãã.ãã ã, <i>n</i> ≤ 20 ãšãã.
</p>
<!--
<p>
å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠âinput.txtâ ã§ãã. âinput.txtâ 㯠2 è¡ãããªã,1 è¡ç®ã«æäœåæ° <i>n</i>, 2 è¡ç®ã«æåã®æååãæžãããŠãã.
</p>
<p>
åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠âoutput.txtâ ã§ãã.âoutput.txtâ 㯠1 è¡ã§ãã, æå®ãããåæ°ã®æäœãæœããæååã®åŸã«æ¹è¡ãå
¥ããããš.
</p>
-->
<p>
å
¥åããŒã¿ 㯠2 è¡ãããªã,1 è¡ç®ã«æäœåæ° <i>n</i>, 2 è¡ç®ã«æåã®æååãæžãããŠãã.
</p>
<table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;">
<tr>
<th width="150" align="left">å
¥åäŸ</th>
</tr>
<tr><td></td></tr>
<tr>
<td>5<br>
11</td>
</tr>
<tr>
<td>ã</td>
</tr>
<tr>
<th width="150" align="left">åºåäŸ</th>
</tr>
<tr><td>13112221
</td>
</tr>
</table>
<h3>å
¥å</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒn ã 0 ã®ãšãå
¥åãçµäºããïŒããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h3>åºå</h3>
<p>
ããŒã¿ã»ããããšã«ãæå®ãããåæ°ã®æäœãæœããæåå ãïŒè¡ã«åºåããïŒ
</p>
<H2>å
¥åäŸ</H2>
<pre>
5
11
5
11
0
</pre>
<H2>åºåäŸ</H2>
<pre>
13112221
13112221
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div> |
p02414 |
<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>Matrix Multiplication</h1><br>
<p>
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:
</p>
\[
c_{ij} = \sum_{k=1}^m a_{ik}b_{kj}
\]
<p>
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
</p>
<h2>Input</h2>
<p>
In the first line, three integers $n$, $m$ and $l$ are given separated by space characters
</p>
<p>
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$ matrix $B$ are given.
</p>
<h2>Output</h2>
<p>
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space character between adjacent elements.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n, m, l \leq 100$</li>
<li>$0 \leq a_{ij}, b_{ij} \leq 10000$</li>
</ul>
<h2>Sample Input</h2>
<pre>
3 2 3
1 2
0 3
4 5
1 2 1
0 3 2
</pre>
<h2>Sample Output</h2>
<pre>
1 8 5
0 9 6
4 23 14
</pre>
<h2>Note</h2>
<center>
<a href="commentary.jsp?id=ITP1_7_D">
<div class="button"> 解説 </div>
</a>
</center>
|
p00079 |
<H1>åž <var>n</var> è§åœ¢ã®é¢ç©</H1>
<p>
åž <var>n</var> è§åœ¢ïŒãã¹ãŠã®é ç¹ã®å
è§ã 180 åºŠæªæºã§ããå€è§åœ¢ãèŠããã«ãžããã§ããªãå€è§åœ¢ã®ããšïŒã®é ç¹ã®åº§æšãèªãã§ããã®é¢ç©ãåºåããããã°ã©ã ãäœæããŠãã ãããé ç¹ã«ã¯èŸºã®ã€ãªããã®é åºã«åŸã£ãŠé ç¹ 1ãé ç¹ 2ãé ç¹ 3ãâ¥â¥é ç¹ <var>n</var> ãšããååãã€ããŠããŸãã
</p>
<p>
ãã ãã <var>n</var> 㯠3 ä»¥äž 20 以äžãšããŸãããŸããæ¬¡ã®ãäžè§åœ¢ã® 3 蟺ã®é·ã <var>a, b, c</var> ããé¢ç© <var>S</var> ãæ±ããå
¬åŒã䜿ã£ãŠãããŸããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_07">
</center>
<br/>
<H2>å
¥å</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>x<sub>1</sub></var>,<var>y<sub>1</sub></var>
<var>x<sub>2</sub></var>,<var>y<sub>2</sub></var>
:
<var>x<sub>n</sub></var>,<var>y<sub>n</sub></var>
</pre>
<p>
<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ã¯ããããé ç¹ <var>i</var> ã® <var>x</var> 座æš, <var>y</var> 座æšã衚ã宿°ã§ãã
</p>
<H2>åºå</H2>
<p>
é¢ç© <var>S</var> ïŒå®æ°ïŒãïŒè¡ã«åºåããŸãã
åºå㯠0.000001 以äžã®èª€å·®ãå«ãã§ãããŸããŸããã
</p>
<H2>Sample Input</H2>
<pre>
0.0,0.0
0.0,1.0
1.0,1.0
2.0,0.0
1.0,-1.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2.500000
</pre>
|
p02044 | <h3>å²ãå</h3>
<!-- begin ja only -->
<p>ããªã㯠ICPC 2019 Yokohama Regional åœå
äºéžã®å¥éãç¥ãããã®ããŒãã£ãäŒç»ããïŒãã®ããŒãã£ã®åå è
㯠<i>N</i> 人ã§ããïŒ</p>
<p>ãã®ããŒãã£ã®éå¬ã«ã¯åèšã§ <i>M</i> åã®è²»çšãå¿
èŠãšãªãããïŒ<i>N</i> 人ã®åå è
ãããããã <i>M/N</i> åãéããããšã«ããïŒ<i>M</i> 㯠<i>N</i> ã§å²ãåããéé¡ãšãªã£ãããïŒäœãã«ã€ããŠå¿é
ããå¿
èŠã¯ãªãïŒ</p>
<p><i>i</i> çªç®ã®åå è
ã®ä»æ¥ã®ææé㯠<i>A<sub>i</sub></i> åã§ããïŒ<i>M/N</i> åãæãããšãã§ããªãå Žåã«ã¯ïŒä»æ¥ã®ææéããã¹ãŠæã£ãŠãããïŒè¶³ããªãåã¯åŸæ¥æã£ãŠãããããšãšããïŒ</p>
<p>ããªãã¯ä»æ¥ã®ãã¡ã«ããŒãã£ã®éå¬è²»çšããããéããããšãã§ããã ãããïŒ</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯æå€§ã§ 50 åã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ</p>
<blockquote><i>N</i> <i>M</i>
<i>A<sub>1</sub></i> <i>A<sub>2</sub></i> <i>...</i> <i>A<sub>N</sub></i></blockquote>
<p>ããŒã¿ã»ãã㯠2 è¡ãããªãïŒ1 è¡ç®ã«ã¯ããŒãã£ã®åå è
ã®æ° <i>N</i> ãšïŒããã£ãè²»çš <i>M</i> ãäžããããïŒ<i>N</i> ãš <i>M</i> ã¯æŽæ°ã§ããïŒãããã <i>2 ≤ N ≤ 100</i>ïŒ<i>N ≤ M ≤ 10 000</i> ãæãç«ã€ïŒãŸãïŒ<i>M</i> 㯠<i>N</i> ã®åæ°ã§ããïŒ2 è¡ç®ã«ã¯ <i>N</i> 人ã®åå è
ã®ããããã®ææéãäžããããïŒ<i>A<sub>i</sub></i> 㯠<i>i</i> çªç®ã®åå è
ã®ææéãè¡šãæŽæ°ã§ããïŒ<i>1 ≤ A<sub>i</sub> ≤ 10 000</i> ã§ããïŒ</p>
<p>å
¥åã®çµããã¯ïŒ2 åã® <i>0</i> ã ããããªãè¡ã§è¡šãããïŒ</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«ã€ããŠïŒä»æ¥ã®ãã¡ã«éããããšãã§ããããŒãã£ã®éå¬è²»çšã 1 è¡ã§åºåããïŒ</p>
<!-- end ja only -->
<h3>Sample Input</h3><pre>3 300
120 100 80
3 30
10 20 5
4 1000
100 200 300 400
5 5
2523 8430 3 4199 632
0 0
</pre><h3>Output for the Sample Input</h3><pre>280
25
800
5
</pre>
<p>ã²ãšã€ãã®ããŒã¿ã»ããã§ã¯ 1 人ãããã®æ¯æã㯠100 åã§ããïŒ1 çªç®ãš 2 çªç®ã®åå è
㯠100 åãæ¯æãããšãã§ãããïŒ3 çªç®ã®åå è
㯠100 åãæ¯æãããšãã§ããªãããïŒææéã§ãã 80 åãæ¯æã£ãŠãããïŒè¶³ããªã 20 åã¯åŸæ¥æ¯æã£ãŠãããããšãšããïŒä»æ¥ã®ãã¡ã«éããããšãã§ããã®ã¯ <i>100+100+80=280</i> åã§ããïŒ</p>
|
p00583 | <h1>ãã®ãããã®ãããã®ããå®¶åºèå(Growing Vegetables is Fun 3)</h1>
<p>
JOI åã¯ïŒé·å¹Žã«ãããå®¶åºèåã®çµéšãçãããŠïŒèªå®
ã®åºã§æ°ãã«ãžã§ã€èãšããæ€ç©ãè²ãŠãŠããïŒåºã«ã¯æ±è¥¿æ¹åã«äžŠãã $N$ åã®ãã©ã³ã¿ãŒãããïŒè¥¿åŽããé ã«1 ãã$N$ ãŸã§ã®çªå·ãã€ããŠããïŒãžã§ã€èã¯å
šéšã§$N$ æ ªããïŒããããã®ãã©ã³ã¿ãŒã«1 æ ªãã€æ€ããŠããïŒ
</p>
<p>
æ¥ã«ãªã£ãŠæ§åãèŠã«è¡ã£ãJOI åã¯ïŒãžã§ã€èãäºæ³ã«åããŠè²ãšãã©ãã®èãä»ããŠããããšã«æ°ãã€ããïŒããã«ïŒãžã§ã€èãæã£ãã»ã©çè²ããŠããªãããšã«æ°ãã€ããïŒJOI åã¯ãããã®ããšãäžæè°ã«æãïŒæ¬ã§èª¿ã¹ããšããïŒæ¬¡ã®ããšãããã£ãïŒ
</p>
<ul>
<li> ãžã§ã€èã«ã¯3 çš®é¡ããïŒããããèµ€ïŒç·ïŒé»ã®èãä»ããïŒ</li>
<li> èã®è²ãåããžã§ã€èãè¿ãã«çœ®ããšïŒãã®æé·ãé»å®³ãããŠããŸãïŒ</li>
</ul>
<p>
ããã§ïŒJOI åã¯ïŒãžã§ã€èãäžŠã³æ¿ããŠïŒèã®è²ãåããžã§ã€èãé£ãåããªãããã«ããããšã«ããïŒãã®ãšãïŒJOI åã¯é£ãåã2 ã€ã®ãžã§ã€èãå
¥ãæ¿ããããšããã§ããªãïŒã€ãŸãïŒ1 åã®æäœã§JOI åã¯ãã©ã³ã¿ãŒ$i$ ($1 \leq i \leq N - 1$) ãä»»æã«1 ã€éžã³ïŒãã©ã³ã¿ãŒ$i$ ã®ãžã§ã€èãšãã©ã³ã¿ãŒ$i + 1$ ã®ãžã§ã€èãå
¥ãæ¿ããããšãã§ããïŒJOI åã¯ïŒã§ããã ãå°ãªãåæ°ã®æäœã§ïŒèã®è²ãåããžã§ã€èãé£ãåããªãããã«ãããïŒ
</p>
<p>
ãžã§ã€èã®æ°ãšïŒããããã®ãžã§ã€èã®èã®è²ãäžãããããšãïŒèã®è²ãåããžã§ã€èãé£ãåããªãããã«äžŠã³æ¿ããããã«å¿
èŠãªæäœåæ°ã®æå°å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ
</p>
<pre>
$N$
$S$
</pre>
<p>
$S$ ã¯é·ã$N$ ã®æååã§ïŒãã®$i$ æåç®($1 \leq i \leq N$) ã¯ïŒãã©ã³ã¿ãŒ$i$ ã«æ€ããŠãããžã§ã€èã®èã®è²ãèµ€ãªãã°RïŒç·ãªãã°GïŒé»ãªãã°Y ã§ããïŒ
</p>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒå¿
èŠãªæäœåæ°ã®æå°å€ã1 è¡ã§åºåããïŒãã ãïŒèã®è²ãåããžã§ã€èãé£ãåããªãããã«äžŠã³æ¿ããããšãäžå¯èœãªãã°ïŒä»£ããã«-1 ãåºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$ 1 \leq N \leq 400$ïŒ</li>
<li> $S$ ã¯é·ã$N$ ã®æååã§ããïŒ</li>
<li> $S$ ã®åæåã¯RïŒGïŒY ã®ããããã§ããïŒ</li>
</ul>
<!--
å°èª²é¡
1. (5 ç¹) N ⊠15ïŒ
2. (55 ç¹) N ⊠60ïŒ
3. (15 ç¹) S ã®åæåã¯RïŒG ã®ããããã§ããïŒ
4. (25 ç¹) 远å ã®å¶çŽã¯ãªãïŒ
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1</h3>
<pre>
5
RRGYY
</pre>
<h3> åºåäŸ1</h3>
<pre>
2
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒäŸãã°æ¬¡ã®ããã«ãããšïŒèã®è²ãåããžã§ã€èãé£ãåããªãããã«ããããšãã§ããïŒ
</p>
<ul>
<li> ãŸãïŒãã©ã³ã¿ãŒ3 ã®ãžã§ã€èãšãã©ã³ã¿ãŒ4 ã®ãžã§ã€èãå
¥ãæ¿ããïŒ</li>
<li> 次ã«ïŒãã©ã³ã¿ãŒ2 ã®ãžã§ã€èãšãã©ã³ã¿ãŒ3 ã®ãžã§ã€èãå
¥ãæ¿ããïŒ</li>
</ul>
<p>
ãã®ããã«ãããšïŒãžã§ã€èã®äžŠã³ã¯RYRGY ã®ããã«ãªãïŒ1 å以äžã®æäœã§èã®è²ãåããžã§ã€èãé£ãåããªãããã«ããããšã¯ã§ããªãã®ã§ïŒ2 ãåºåããïŒ
</p>
<h3>å
¥åäŸ2</h3>
<pre>
6
RRRRRG
</pre>
<h3> åºåäŸ2</h3>
<pre>
-1
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒã©ã®ããã«æäœãããŠãïŒèã®è²ãåããžã§ã€èãé£ãåããªãããã«ããããšã¯ã§ããªãïŒ
</p>
<h3>å
¥åäŸ3</h3>
<pre>
20
YYGYYYGGGGRGYYGRGRYG
</pre>
<h3> åºåäŸ3</h3>
<pre>
8
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2018/2019-ho/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第18 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2018/2019) æ¬éžã</a>
</p>
|
p03205 | <span class="lang-en">
<p>Score : <var>2200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given <var>N-1</var> subsets of <var>\{1,2,...,N\}</var>. Let the <var>i</var>-th set be <var>E_i</var>.</p>
<p>Let us choose two distinct elements <var>u_i</var> and <var>v_i</var> from each set <var>E_i</var>, and consider a graph <var>T</var> with <var>N</var> vertices and <var>N-1</var> edges, whose vertex set is <var>\{1,2,..,N\}</var> and whose edge set is <var>(u_1,v_1),(u_2,v_2),...,(u_{N-1},v_{N-1})</var>.
Determine if <var>T</var> can be a tree by properly deciding <var>u_i</var> and <var>v_i</var>.
If it can, additionally find one instance of <var>(u_1,v_1),(u_2,v_2),...,(u_{N-1},v_{N-1})</var> such that <var>T</var> is actually a tree.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>E_i</var> is a subset of <var>\{1,2,..,N\}</var>.</li>
<li><var>|E_i| \geq 2</var></li>
<li>The sum of <var>|E_i|</var> is at most <var>2 \times 10^5</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>c_1</var> <var>w_{1,1}</var> <var>w_{1,2}</var> <var>...</var> <var>w_{1,c_1}</var>
<var>:</var>
<var>c_{N-1}</var> <var>w_{N-1,1}</var> <var>w_{N-1,2}</var> <var>...</var> <var>w_{N-1,c_{N-1}}</var>
</pre>
<p>Here, <var>c_i</var> stands for the number of elements in <var>E_i</var>, and <var>w_{i,1},...,w_{i,c_i}</var> are the <var>c_i</var> elements in <var>c_i</var>.
Here, <var>2 \leq c_i \leq N</var>, <var>1 \leq w_{i,j} \leq N</var>, and <var>w_{i,j} \neq w_{i,k}</var> (<var>1 \leq j < k \leq c_i</var>) hold.</p>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>T</var> cannot be a tree, print <code>-1</code>; otherwise, print the choices of <var>(u_i,v_i)</var> that satisfy the condition, in the following format:</p>
<pre><var>u_1</var> <var>v_1</var>
<var>:</var>
<var>u_{N-1}</var> <var>v_{N-1}</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
2 1 2
3 1 2 3
3 3 4 5
2 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2
1 3
3 4
4 5
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
3 1 2 3
3 2 3 4
3 1 3 4
3 1 2 4
3 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10
5 1 2 3 4 5
5 2 3 4 5 6
5 3 4 5 6 7
5 4 5 6 7 8
5 5 6 7 8 9
5 6 7 8 9 10
5 7 8 9 10 1
5 8 9 10 1 2
5 9 10 1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
</pre></section>
</div>
</span> |
p01238 |
<H1><font color="#000">Problem E:</font> Subdividing a Land</H1>
<p>
Indigo Real-estate Company is now planning to develop a new housing complex. The entire complex is a square,
all of whose edges are equally <i>a</i> meters. The complex contains <i>n</i> subdivided blocks, each of which is a <i>b</i>-meter
square. Here both <i>a</i> and <i>b</i> are positive integers.
</p>
<p>
However the project is facing a big problem. In this country, a percentage limit applies to the subdivision of a
land, under the pretext of environmental protection. When developing a complex, the total area of the subdivided
blocks must not exceed 50% of the area of the complex; in other words, more than or equal to 50% of the newly
developed housing complex must be kept for green space. As a business, a green space exceeding 50% of the
total area is a <i>dead space</i>. The primary concern of the project is to minimize it.
</p>
<p>
Of course purchasing and developing a land costs in proportion to its area, so the company also wants to minimize
the land area to develop as the secondary concern. You, a member of the project, were assigned this task, but can
no longer stand struggling against the problem with your pencil and paper. So you decided to write a program to
find the pair of minimum <i>a</i> and <i>b</i> among those which produce the minimum dead space for given <i>n</i>.
</p>
<H2>Input</H2>
<p>
The input consists of multiple test cases. Each test case comes in a line, which contains an integer <i>n</i>. You may
assume 1 ≤ <i>n</i> ≤ 10000.
</p>
<p>
The end of input is indicated by a line containing a single zero. This line is not a part of the input and should not
be processed.
</p>
<H2>Output</H2>
<p>
For each test case, output the case number starting from 1 and the pair of minimum <i>a</i> and <i>b</i> as in the sample
output.
</p>
<p>
You may assume both <i>a</i> and <i>b</i> fit into 64-bit signed integers.
</p>
<H2>Sample Input</H2>
<pre>
1
2
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: 3 2
Case 2: 2 1
</pre>
|
p02947 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We will call a string obtained by arranging the characters contained in a string <var>a</var> in some order, an <em>anagram</em> of <var>a</var>.</p>
<p>For example, <code>greenbin</code> is an anagram of <code>beginner</code>. As seen here, when the same character occurs multiple times, that character must be used that number of times.</p>
<p>Given are <var>N</var> strings <var>s_1, s_2, \ldots, s_N</var>. Each of these strings has a length of <var>10</var> and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers <var>i, j</var> <var>(1 \leq i < j \leq N)</var> such that <var>s_i</var> is an anagram of <var>s_j</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>s_i</var> is a string of length <var>10</var>.</li>
<li>Each character in <var>s_i</var> is a lowercase English letter.</li>
<li><var>s_1, s_2, \ldots, s_N</var> are all distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s_1</var>
<var>s_2</var>
<var>:</var>
<var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of pairs of integers <var>i, j</var> <var>(1 \leq i < j \leq N)</var> such that <var>s_i</var> is an anagram of <var>s_j</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
acornistnt
peanutbomb
constraint
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p><var>s_1 =</var> <code>acornistnt</code> is an anagram of <var>s_3 =</var> <code>constraint</code>. There are no other pairs <var>i, j</var> such that <var>s_i</var> is an anagram of <var>s_j</var>, so the answer is <var>1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
oneplustwo
ninemodsix
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>If there is no pair <var>i, j</var> such that <var>s_i</var> is an anagram of <var>s_j</var>, print <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>Note that the answer may not fit into a <var>32</var>-bit integer type, though we cannot put such a case here.</p></section>
</div>
</span> |
p03655 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Joisino is planning on touring Takahashi Town.
The town is divided into square sections by north-south and east-west lines.
We will refer to the section that is the <var>x</var>-th from the west and the <var>y</var>-th from the north as <var>(x,y)</var>.</p>
<p>Joisino thinks that a <em>touring plan</em> is good if it satisfies the following conditions:</p>
<ul>
<li>
<p>Let <var>(p,q)</var> be the section where she starts the tour. Then, <var>X_1 \leq p \leq X_2</var> and <var>Y_1 \leq q \leq Y_2</var> hold.</p>
</li>
<li>
<p>Let <var>(s,t)</var> be the section where she has lunch. Then, <var>X_3 \leq s \leq X_4</var> and <var>Y_3 \leq t \leq Y_4</var> hold.</p>
</li>
<li>
<p>Let <var>(u,v)</var> be the section where she ends the tour. Then, <var>X_5 \leq u \leq X_6</var> and <var>Y_5 \leq v \leq Y_6</var> hold.</p>
</li>
<li>
<p>By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way.</p>
</li>
</ul>
<p>Two touring plans are considered different if at least one of the following is different: the starting section, the lunch section, the ending section, and the sections that are visited on the way.
Joisino would like to know how many different good touring plans there are.
Find the number of the different good touring plans.
Since it may be extremely large, find the count modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X_1 \leq X_2 < X_3 \leq X_4 < X_5 \leq X_6 \leq 10^6</var></li>
<li><var>1 \leq Y_1 \leq Y_2 < Y_3 \leq Y_4 < Y_5 \leq Y_6 \leq 10^6</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X_1</var> <var>X_2</var> <var>X_3</var> <var>X_4</var> <var>X_5</var> <var>X_6</var>
<var>Y_1</var> <var>Y_2</var> <var>Y_3</var> <var>Y_4</var> <var>Y_5</var> <var>Y_6</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different good touring plans, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1 2 2 3 4
1 1 2 2 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The starting section will always be <var>(1,1)</var>, and the lunch section will always be <var>(2,2)</var>.
There are four good touring plans where <var>(3,3)</var> is the ending section, and six good touring plans where <var>(4,3)</var> is the ending section.
Therefore, the answer is <var>6+4=10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 2 3 4 5 6
1 2 3 4 5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2346
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>77523 89555 420588 604360 845669 973451
2743 188053 544330 647651 709337 988194
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>137477680
</pre></section>
</div>
</span> |
p01668 |
<h2>B - Integer in Integer</h2>
<h3>Problem Statement</h3>
<p>
Given an integer interval <var>\[A, B\]</var> and an integer <var>C</var>, your job is to calculate the number of occurrences of <var>C</var> as string in the interval.
</p>
<p>
For example, <var>33</var> appears in <var>333</var> twice, and appears in <var>334</var> once. Thus the number of occurrences of <var>33</var> in <var>\[333, 334\]</var> is <var>3</var>.
</p>
<h3>Input</h3>
<p>
The test case is given by a line with the three integers, <var>A</var>, <var>B</var>, <var>C</var> (<var>0 \leq A \leq B \leq 10^{10000}</var>, <var>0 \leq C \leq 10^{500}</var>).
</p>
<h3>Output</h3>
<p>
Print the number of occurrences of <var>C</var> mod 1000000007.
</p>
<h3>Sample Input 1</h3>
<pre>
1 3 2
</pre>
<h3>Output for Sample Input 1</h3>
<pre>
1
</pre>
<h3>Sample Input 2</h3>
<pre>
333 334 33
</pre>
<h3>Output for Sample Input 2</h3>
<pre>
3
</pre>
<h3>Sample Input 3</h3>
<pre>
0 10 0
</pre>
<h3>Output for Sample Input 3</h3>
<pre>
2
</pre>
|
p01392 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">åé¡ E</font> Fox Number</h1>
<h2>å顿</h2>
<p>ãã€ãã®ãããã¯æ°åã«ã€ããŠèããã®ã奜ãã§ããïŒããæ¥ïŒãããã¯ãã®äžã«ããã®æ°åãšãããã®ãããããšãç¥ãïŒèªåããã®ãããªæ°åãæ¬²ãããªã£ãŠããŸã£ãïŒããã§ïŒæ¬¡ã®æ§è³ªãæºããæ°åããšãããã Fox Number ãšåŒã¶ããšã«ããïŒ</p>
<p>[æ§è³ª]: æŽæ° <var>N</var> 㯠<var>k (≥ 1)</var> åã®çŽ æ° <var>p<sub>1</sub>, ..., p<sub>k</sub></var> ãšæ£æŽæ° <var>e<sub>1</sub>, ..., e<sub>k</sub></var> ã§ïŒ<var>p<sub>1</sub> < ... < p<sub>k</sub></var>ïŒ<var>e<sub>1</sub> ≥ ... ≥ e<sub>k</sub></var> ãæºãããã®ã«ãã£ãŠ <var>N = p<sub>1</sub><sup>e<sub>1</sub></sup> à ... à p<sub>k</sub><sup>e<sub>k</sub></sup></var> ãšæžãããšãïŒFox Number ã§ãããšåŒã¶ããšã«ããïŒ</p>
<p>ãšããã§ãããã¯ãã®æ§è³ªããã®å Žã®æãã€ãã§æ±ºããŠããŸã£ãã®ã§ãããã©ãããæ§è³ªãæã£ãŠããã®ãå
šãããã£ãŠããªãïŒããã§ïŒãã®æ°åã®æ§è³ªã調ã¹ãããã«åºé <var>[A-B, A+B]</var> ã«å«ãŸãã Fox Number ã®åæ°ãåºåããŠæ¬²ããïŒ</p>
<h2>å
¥å圢åŒ</h2>
<p><var>1</var> è¡ç®ã«ä»¥äžã® <var>2</var> ã€ã®æŽæ°ãäžããããïŒ</p>
<pre><var>A</var> <var>B</var></pre>
<h2>åºå圢åŒ</h2>
<p><var>1</var> è¡ç®ã«ïŒ<var>A-B</var> ä»¥äž <var>A+B</var> 以äžã® Fox Number ã®åæ°ãåºåããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ A ≤ 10<sup>12</sup></var></li>
<li><var>0 ≤ B ≤ 5 Ã 10<sup>5</sup></var></li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
18 2
</pre>
<h3>åºåäŸ 1</h3>
<pre>
4
</pre>
<p><var>16 = 2<sup>4</sup>, 17 = 17<sup>1</sup>, 19 = 19<sup>1</sup>, 20 = 2<sup>2</sup> à 5<sup>1</sup></var> 㯠Fox Number ã§ããïŒäžæ¹ã§ <var>18 = 2 à 3<sup>2</sup></var> 㯠Fox Number ã§ã¯ãªãïŒåèšã㊠<var>4</var> ã€ã® Fox Number ãããïŒ</p>
<h3>å
¥åäŸ 2</h3>
<pre>
100 10
</pre>
<h3>åºåäŸ 2</h3>
<pre>
18
</pre>
<h3>å
¥åäŸ 3</h3>
<pre>
123456 789
</pre>
<h3>åºåäŸ 3</h3>
<pre>
1464
</pre>
|
p03481 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>As a token of his gratitude, Takahashi has decided to give his mother an integer sequence.
The sequence <var>A</var> needs to satisfy the conditions below:</p>
<ul>
<li><var>A</var> consists of integers between <var>X</var> and <var>Y</var> (inclusive).</li>
<li>For each <var>1\leq i \leq |A|-1</var>, <var>A_{i+1}</var> is a multiple of <var>A_i</var> and strictly greater than <var>A_i</var>.</li>
</ul>
<p>Find the maximum possible length of the sequence.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X \leq Y \leq 10^{18}</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>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible length of the sequence.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The sequence <var>3,6,18</var> satisfies the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>25 100
</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>314159265 358979323846264338
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>31
</pre></section>
</div>
</span> |
p01146 |
<!-- begin en only -->
<h3><U> Princess in Danger </U></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><U> ãå§«æ§ã®å±æ© </U></h3>
<!-- end ja only -->
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ããè²§ä¹ãªåœã®ããŠãã°ã§åæ¢ãªãå§«æ§ãïŒæ¿ç¥çµå©ã®ããå¥ã®åœã«å«ãããšã«ãªã£ãïŒãšãããïŒãå§«æ§ã亡ãè
ãšããããšããŠããæªæŒ¢ã«å«ãå
ãžã®éäžã§è¥²ãããå§«æ§ã倧ãããããŠããŸãïŒè¿ãã®ç
é¢ã«æ¬éãããïŒãšãããïŒæªæŒ¢ã¯ãå§«æ§ã¯ç¢ºå®ã«äº¡ãè
ãšããããç¹æ®ãªæ¯ã䜿ã£ãŠããïŒãã®ããïŒãå§«æ§ãå©ããã«ã¯æ¬åœããç¹å¥ãªè¬ãšå·åãããè芪ã®è¡æ¶²ã倧æ¥ãã§éã°ãªããã°ãªããªããªã£ãïŒ
</p>
<p>
ãã®è¡æ¶²ã¯å·åç¶æ
ã§èŒžéãããã®ã ãïŒé®®åºŠãä¿ã€ããïŒååã®å·åããæå€§ <i>M</i> å以å
ã«è¡æ¶²å·åæœèšã§åå·åããªããã°ãªããªãïŒãããïŒå·åæœèšãèšçœ®ãããŠããå Žæã¯æ°ã«æãããªãïŒ
</p>
<p>
è¡æ¶²ã¯ïŒååã«å·åããç¶æ
ããïŒåå·åãªãã§ <i>M</i> åã®éç¡äºã§ããïŒåå·åããªããŠããæ®ãæéã <i>S</i> åã®ãšãã«ïŒ<i>T</i> åéå·åããªãã§èŒžéããå ŽåïŒåå·åããªããŠããæ®ãæé㯠<i>S</i> - <i>T</i> åãšãªãïŒåå·åããªããŠããæ®ãæéã¯ïŒåå·åããããšã«ããïŒæå€§ <i>M</i> åãŸã§å埩ããïŒè¡æ¶²ã®åå·åã«ãããæéã¯ïŒã©ãã ãå·åãããã«äŸåããïŒè¡æ¶²ãå·åæœèšã§ïŒ1åå·åããããšã«åå·åããªããŠããæ®ãæéã¯1åå埩ããïŒ
</p>
<p>
æ¬åœã®éŠéœãåºçºããæç¹ã®ïŒè¡æ¶²ãåå·åããªããŠããæ®ãæéã¯<i>M</i>åã§ããïŒ
</p>
<p>
ãå§«æ§ã®åŸè
ã§ããããªãã¯ïŒå€§åãªäž»åã®åœãæãããïŒæ¬åœã®éŠéœãããå§«æ§ãæ¬éãããç
é¢ãŸã§è¡æ¶²ã®é®®åºŠãä¿ã£ããŸãŸèŒžéããããã®çµè·¯ãèšç®ããªããã°ãªããªãïŒããïŒããªãã®äœ¿åœã¯ïŒæ¬åœã®éŠéœãããã®ç
é¢ãžã®æççµè·¯ãå²ãåºãïŒãã®æçæéãæ±ããããšã§ããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ããããæ§æãããïŒåããŒã¿ã»ããã®æåã®è¡ã«ã¯ïŒ6 ã€ã®éè² ã®æŽæ° <i>N</i>(2 ⊠<i>N</i> ⊠100)ïŒ<i>M</i>(1 ⊠<i>M</i> ⊠100)ïŒ<i>L</i>(0 ⊠<i>L</i> ⊠<i>N</i> - 2)ïŒ<i>K</i>ïŒ<i>A</i>(0 ⊠<i>A</i> ïŒ <i>N</i>)ïŒ<i>H</i>(0 ⊠<i>H</i> ïŒ <i>N</i>) ãäžããããïŒãããã¯ããããïŒçºã®æ°ïŒåå·åãè¡ããŸã§ã®å¶éæéïŒå·åæœèšã®ããçºã®æ°ïŒçºãšçºãçŽæ¥çµã¶éè·¯ã®æ°ïŒæ¬åœã®éŠéœã衚ãçªå·ïŒãå§«æ§ãæ¬éãããç
é¢ã®ããçºã®çªå·ã衚ãïŒæ¬åœã®éŠéœãšãå§«æ§ãæ¬éãããç
é¢ã¯ïŒç°ãªãçºã§ããïŒãªãïŒçºã«ã¯ 0 ã <i>N</i>-1 ãŸã§ã®çªå·ãããããå²ãåœãŠãããŠãããã®ãšããïŒç¶ãè¡ã«ã¯ïŒ<i>L</i> åã®éè² ã®æŽæ°ã 1 ã€ã®ç©ºçœã§åºåãããŠäžããããïŒãããã¯ïŒå·åæœèšãããçºã®çªå·ã衚ãïŒãªãïŒæ¬åœã®éŠéœãšãå§«æ§ãæ¬éãããç
é¢ã¯ãã®ãªã¹ãã«ã¯å«ãŸããªããïŒå·åæœèšããããã®ãšèããŠè¯ãïŒç¶ã <i>K</i> è¡ã§ã¯ïŒçºãšçºãçµã¶éè·¯ã®æ
å ±ãäžããããïŒãã®ç¬¬ <i>i</i> è¡ç®ã§ã¯ïŒ3 ã€ã®éè² ã®æŽæ° <i>X</i> ïŒ<i>Y</i> ïŒ<i>T</i> ã 1 ã€ã®ç©ºçœã§åºåãããŠäžãããïŒããã¯çº <i>X</i> ãšçº <i>Y</i> ãçŽæ¥çµã¶éãããïŒç§»åã«ã¯æé <i>T</i> ãèŠãããšããããšã衚ãïŒãªãïŒãã®éã¯åæ¹åã«éè¡å¯èœã§ããïŒãŸãïŒçº<i>X</i>ãšçº<i>Y</i>ãçŽæ¥çµã¶éã¯é«ã
äžã€ããç¡ãïŒ
</p>
<p>
å
¥å㯠<i>N = M = L = K = A = H =</i> 0 ã®æã«çµäºãïŒããã¯ããŒã¿ã»ããã«å«ãŸããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«ã€ããŠïŒé®®åºŠãä¿ã£ããŸãŸè¡æ¶²ãå±ããããšãã§ããæçæéãåºåããïŒããå±ããããšãã§ããªãå Žåã«ã¯ "Help!" ãšåºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
2 1 0 1 0 1
0 1 2
3 1 1 2 0 1
2
0 2 1
1 2 1
3 2 1 2 0 1
2
0 2 1
1 2 1
4 4 1 4 1 3
2
0 1 2
1 2 4
0 2 1
3 0 3
5 3 2 6 0 3
1 2
2 1 2
1 0 1
3 4 1
2 4 1
4 1 2
2 0 2
5 4 2 6 0 3
1 2
4 2 4
2 1 2
4 3 1
0 1 5
1 4 2
2 0 3
0 0 0 0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
Help!
3
2
10
5
12
</pre>
|
p01516 |
<!-- begin en only -->
<h3><u>Milky Way
</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>
倩ã®å·äº€éå
¬ç€Ÿã¯æéæ
è¡ãã¢ãŒã®äŒç»ã»éå¶ãè¡ãæ
è¡äŒç€Ÿã§ããã
倩ã®å·äº€éå
¬ç€Ÿã§ã¯ã倩ã®å·æšªæç¹å§«åœŠæäœéšãã¢ãŒããšããäŒç»ãèšç»äžã§ããã
ãã®ãã¢ãŒã¯çŽåº§ã®ãã¬ãåºçºãã
æã
ãå·¡ã£ãŠé·²åº§ã®ã¢ã«ã¿ã€ã«ã«åãããšãããã®ã§ããã
ããªãã¯å€©ã®å·äº€éå
¬ç€Ÿã«ç€Ÿå¡ã§ããã
ãã¢ãŒã®çµè·¯ã®éžæãä»»ãããŠããã
</p>
<p>
ç°¡åã®ãã倩ã®å·ã¯2次å
座æšäžã«ãããã®ãšãã
æã¯äºèæã§è¡šçŸããããã®ãšããã
ãã¢ãŒã«äœ¿çšããå®å®è¹ã«ã¯ç¹æ®ãªãšã³ãžã³ãæèŒãããŠããã
äºèæã®ç·åäžã¯ãšãã«ã®ãŒç¡ãã§ç§»åããããšãã§ããã
äžæ¹ãäºèæã®éãç§»åããéã«ã¯ããã®è·é¢ã«æ¯äŸãããšãã«ã®ãŒãå¿
èŠãšãªãã
</p>
<p>
è¿å¹Žã倩ã®å·äº€éå
¬ç€Ÿã®å£²äžã¯äœè¿·ããŠããã
å®å®è¹ã®ãšãã«ã®ãŒä»£ãå§ããšããåçš®å¿
èŠçµè²»ã®ç¯çŽãè¿«ãããŠããã
ããªãã®ä»äºã¯ããã¬ããã¢ã«ã¿ã€ã«ã«ç§»åããéã
æéç§»åè·é¢ã®ç·åãæå°ã«ãªããããªçµè·¯ãæ±ãã
ãã®ç·åãåºåããããã°ã©ã ãæžãããšã§ããã
</p>
<p>
ããäºèæãããã®å
éšã«å«ãŸããå¥ã®äºèæã«ç§»åããå Žåã
äºèæåå£«ãæ¥ããŠããªãå Žåã¯æéã®ç§»åãšããŠæ±ãããããšã«æ³šæããã
</p>
<p>
å³D-1ã¯3ã€ç®ã®Sample Inputãå³ç€ºãããã®ã§ããã
å³äžãèµ€è²ã®ç·åã¯æéç§»åè·é¢ã®ç·åãæå°ã«ãªããããªçµè·¯ã®ã
æéç§»åã®éšåã衚ããŠããã
</p>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_Fig-D1">
</center>
</center>
<center>
<p>
<i>å³ D-1: æéã®ç§»å</i>
</p>
</center>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åã¯1ã€ä»¥äžã®ããŒã¿ã»ãããããªãã1ã€ã®ããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒãããŠããã
</p>
<blockquote>
<var>N</var> <var>M</var> <var>L</var><br/>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>a<sub>1</sub></var> <var>r<sub>1</sub></var><br/>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>a<sub>2</sub></var> <var>r<sub>2</sub></var><br/>
<var>...</var><br/>
<var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>a<sub>N</sub></var> <var>r<sub>N</sub></var><br/>
</blockquote>
<p>
åãã¹ãã±ãŒã¹ã®åãã®1è¡ã¯æŽæ°NãMãLãããªãã
Nã¯æã®æ°(1 ≤ N ≤ 100)ã
Mã¯ãã¬ã®çªå·(1 ≤ M ≤ N)ã
Lã¯ã¢ã«ã¿ã€ã«ã®çªå·(1 ≤ L ≤ N)ã衚ãã
ç¶ãNè¡ã«ã¯åæã®æ
å ±ãäžããããã
åè¡ã¯x<sub>i</sub>ãy<sub>i</sub>ãa<sub>i</sub>ãr<sub>i</sub>ã®4ã€ã®æŽæ°ãããªãã
x<sub>i</sub>ã¯içªç®ã®æã®äžå¿ã®x座æš(0 ≤ x<sub>i</sub> ≤ 1,000)ã
y<sub>i</sub>ã¯içªç®ã®æã®äžå¿ã®y座æš(0 ≤ y<sub>i</sub> ≤ 1,000)ã
a<sub>i</sub>ã¯içªç®ã®æã®äžå¿åº§æšãšæã®å
端ãçµãã çŽç·ãy軞ãšãªãè§åºŠ(0 ≤ a<sub>i</sub> < 72)ã
r<sub>i</sub>ã¯içªç®ã®æã®äžå¿åº§æšããæã®å
端ãŸã§ã®é·ã(1 ≤ r<sub>i</sub> ≤ 1,000)ã§ããã
å
¥åã®çµããã¯3ã€ã®ãŒããå«ãè¡ã§è¡šãããã
</p>
<p>
å³ D-2ã®å·Šã®æã¯x=5, y=10, a=0, r=5ã®æã衚ããŠãããå³ã®æã¯x=15, y=10, a=30, r=5ã®æã衚ããŠããã
</p>
<center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_Fig-D2">
</center>
</center>
<center>
<p>
<i>å³ D-2: æã®äŸ</i>
</p>
</center>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
åå
¥åããšã«ããã¬ããã¢ã«ã¿ã€ã«ã«ç§»åããéã«å¿
èŠãªæéç§»åè·é¢ã®ç·åã®æå°å€ã1è¡ã«åºåããã
åºåã«ã¯ã0.000001ãè¶
ãã誀差ããã£ãŠã¯ãªããªãã
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
1 1 1
5 5 0 5
2 1 2
5 5 0 5
15 5 0 5
3 2 3
15 15 0 5
5 5 10 5
25 25 20 5
0 0 0
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div>
<h3>Output for Sample Input</h3>
<div>
<pre>
0.00000000000000000000
0.48943483704846357796
9.79033725601359705593
</pre>
<!-- begin ja only -->
<!-- end ja only -->
</div> |
p02290 |
<H1>Projection</H1>
<br/>
<p>
For given three points <var>p1, p2, p</var>, find the projection point <var>x</var> of <var>p</var> onto <var>p1p2</var>.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_CGL_CGL_1_A">
</center>
<H2>Input</H2>
<pre>
<var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>x<sub>p2</sub></var> <var>y<sub>p2</sub></var>
<var>q</var>
<var>x<sub>p<sub>0</sub></sub></var> <var>y<sub>p<sub>0</sub></sub></var>
<var>x<sub>p<sub>1</sub></sub></var> <var>y<sub>p<sub>1</sub></sub></var>
...
<var>x<sub>p<sub>q−1</sub></sub></var> <var>y<sub>p<sub>q−1</sub></sub></var>
</pre>
<p>
In the first line, integer coordinates of <var>p1</var> and <var>p2</var> are given. Then, <var>q</var> queries are given for integer coordinates of <var>p</var>.
</p>
<H2>Output</H2>
<!--
<pre>
<var>x<sub>t<sub>0</sub></sub></var> <var>y<sub>t<sub>0</sub></sub></var>
<var>x<sub>t<sub>1</sub></sub></var> <var>y<sub>t<sub>1</sub></sub></var>
...
<var>x<sub>t<sub>q-1</sub></sub></var> <var>y<sub>t<sub>q-1</sub></sub></var>
</pre>
-->
<p>
For each query, print the coordinate of the projection point <var>x</var>. The output values should be in a decimal fraction with an error less than 0.00000001.
</p>
<H2>Constraints</H2>
<ul>
<li>
<var>1 ≤ q ≤ 1000</var>
</li>
<li>
<var>-10000 ≤ x<sub>i</sub>, y<sub>i</sub> ≤ 10000</var>
</li>
<li>
<var>p1</var> and <var>p2</var> are not identical.
</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
0 0 2 0
3
-1 1
0 1
1 1
</pre>
<H2>Sample Output 1</H2>
<pre>
-1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
0 0 3 4
1
2 5
</pre>
<H2>Sample Output 2</H2>
<pre>
3.1200000000 4.1600000000
</pre>
<br/>
|
p00757 |
<h3><U>Planning Rolling Blackouts</U></h3>
<!-- end en only -->
<div> <!-- please enclose each h3 level section with div -->
<!-- begin en only -->
<p>Faced with seriously tight power supply-demand balance, the
electric power company for which you are working implemented <q>rolling
blackouts</q> in this spring. It divided the servicing area into several
groups of towns, and divided a day into several blackout periods. At
each blackout period of a day, one of the groups, which alternates
from one group to another, is cut off the electricity. By keeping the total demand of
electricity used by the rest of the towns within the supply
capacity, the company avoided unforeseeable large-scale blackout.</p>
<!-- end en only -->
<!-- begin en only -->
<p>Working at the customer relations department, you had to listen to
so many complaints from the customers, which made you think that you
could have a better implementation. Most of the complaints are about the
frequent cut-offs. But you could have divided the area into a larger number of
groups, which resulted in less frequent cut-offs for each group. The
other complaints are about the complicated grouping (in fact, someone
said that the shapes of the groups are fractals), which makes it
impossible to understand which town belongs to which group without
closely inspecting into the grouping list publicized by the company.
With the rectangular servicing area and towns located in a grid form,
you could have made a simpler grouping.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
When you talked your analysis directly to the president of the company, you are
appointed to plan rolling blackouts for this summer. Be careful what
you propose. Anyway, you need to divide the servicing area into
as many groups as possible with keeping total demand of electricity
within the supply capacity. It should also divide the towns into
simple and easy to remember groups.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Your task is to write a program, given a demand table (a table showing
electricity demand of each town) and the supply capacity, that answers
a grouping of towns that satisfy the following conditions.
</p>
<!-- end en only -->
<!-- begin en only -->
<ol>
<li>The grouping should be made by horizontally or vertically splitting
the area in a recursive manner. In other words, the grouping must
be a set of areas after applied the following splitting
procedure to a set containing only the entire area for zero or
more times:
<blockquote>(The splitting procedure) remove one area from the set,
either vertically or horizontally split it into two sub-areas,
and put the sub-areas into the set.
<!--
replace one area in the set with two sub-areas that are
obtained by splitting it either vertically or horizontally.
pick one area and split it either vertically or horizontally.
-->
</blockquote>
<!--
In other words, the groups are formed by repeatedly
split an area either vertically or horizontally into two areas.
-->
</li>
<li>The maximum suppressed demand of the grouping, which is the greatest total demand of the
all but one group, is no more than the supply capacity.</li>
<li>The grouping has the largest number of groups among the groupings
that satisfy the above conditions 1 and 2.</li>
<li>The grouping has the greatest amount of reserve power among the
groupings that satisfy the above conditions 1, 2 and 3, where the
reserve power of a grouping is the difference between the supply
capacity and the maximum suppressed demand.</li>
</ol>
<!-- end en only -->
<!-- begin en only -->
<p>Note that the condition 1 does not allow such a grouping shown in Figure E-1.</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1176" align="center" width="200" height="200"/><br/>
<!-- begin en only -->
Figure E-1: A grouping that violates the condition 1
<!-- end en only -->
<br/><br/>
</center>
</div>
<h3>Input</h3>
<div>
<!-- begin en only -->
<p>The input consists of one or more datasets. Each dataset is given in
the following format.</p>
<!-- end en only -->
<blockquote>
<i>h w s</i> <br/>
<i>u</i><sub>11</sub> <i>u</i><sub>12</sub> ... <i>u</i><sub>1<i>w</i></sub><br/>
<i>u</i><sub>21</sub> <i>u</i><sub>22</sub> ... <i>u</i><sub>2<i>w</i></sub><br/>
... <br/>
<i>u</i><sub><i>h</i>1</sub> <i>u</i><sub><i>h</i>2</sub> ... <i>u</i><sub><i>h</i><i>w</i></sub><br/>
</blockquote>
<!-- begin en only -->
<p>
The first line contains three positive integer numbers,
namely <i>h</i>, <i>w</i> and <i>s</i>, denoting the height and width
of the demand table and the power supply capacity. The following <i>h</i>
lines, each of which contains <i>w</i> integer numbers, denote demands of towns at respective
locations. Those figures are constrained as follows.
</p>
<!-- end en only -->
<blockquote>
1 ≤ <i>h</i>, <i>w</i> ≤ 32 <br/>
1 ≤ <i>u<sub><i>ij</i></sub></i> ≤ 100<br/>
</blockquote>
<!-- begin en only -->
<p>
Regrettably, you may assume that the supply capacity is less than the total demand of the area.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The last dataset is followed by a line containing three zeros.
</p>
<!-- end en only -->
</div>
<h3>Output</h3>
<div>
<!-- begin en only -->
<p>
For each dataset, print a line having two integers indicating the
number of groups in the grouping that satisfies the conditions, and
the amount of the reserve power. Each line should not have any
character other than those numbers and a space in between.
</p>
<!-- end en only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
3 3 33
4 4 2
2 9 6
6 5 3
3 4 15
1 2 1 2
2 1 2 1
1 2 1 2
32 32 1112
1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1
2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1
1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1
1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1
1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1
1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1
1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1
2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1
2 1 1 1 1 1 1 1 2 1 1 1 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 2 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 2 2
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1
1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1
1 1 1 2 1 1 2 1 1 1 2 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 2 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
4 1
6 0
553 0
</pre>
</div> |
p01845 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h3>ã«ã¬ãŒäœã</h3>
<p>ACM-ICPCåœå
äºéžãè¿ã¥ããŠããã®ã§ïŒç·Žç¿ã«è¿œã蟌ã¿ããããããšæã£ãŠããããªãã¯ïŒå人å®
ã§è¡ãããç«¶æããã°ã©ãã³ã°å宿ã«åå ããããšã«ããïŒ
åå è
ã®ãã ããã§ïŒé£äºã¯èªçããããšã«ãªã£ãïŒ
</p>
<p>åå®¿åæ¥ã®å€ïŒåå è
éã¯ãã®æ¥ã®ç·Žç¿ãçµãïŒå€é£ã®æºåã«åãæããå§ããïŒ
ç«¶æããã°ã©ãã³ã°ã ãã§ãªãïŒèªçã§ããããããšå人ã«ããèšãããããªãã¯ïŒæ
åœåã®ã¡ãã¥ãŒããã£ãšããéã«äœãçµããŠããŸãïŒæãæãŠäœããŠããŸã£ãïŒ
ããã§ïŒä»ã®äººãæ
åœããŠããã«ã¬ãŒäœããæäŒãããšã«ããïŒ
</p>
<p>ä»ïŒ<i>W<sub>0</sub></i> [L] ã®æ°Žã« <i>R<sub>0</sub></i> [g] ã®ã«ãŠãæ··ããäœãããã®ã«ã¬ãŒãããïŒ
ä»å䜿ãã«ãŠã¯ 1 çš®é¡ã§ïŒ1 åããã <i>R</i> [g] ã§ããïŒã«ãŠã¯ååãªéã®åèãããïŒ
ããªãã¯ãã®ã«ãŠã䜿ãå ŽåïŒæ¿åºŠã <i>C</i> [g/L] ã®ã«ã¬ãŒãæãçŸå³ãããšèããŠããã®ã§ïŒãã®ã«ã¬ãŒã«ããã€ãã®ã«ãŠãšæ°Žãé©åã«å ãïŒæ¿åºŠã <i>C</i> [g/L] ã«ããããšèããŠããïŒ
ããã§ïŒã«ãŠ <i>R<sub>0</sub></i> [g] ãæ°Ž <i>W<sub>0</sub></i> [L] ã«æº¶ããŠããã«ã¬ãŒã®æ¿åºŠã¯ <i>R<sub>0</sub> / W<sub>0</sub></i> [g/L] ã§ããïŒãã®ã«ã¬ãŒã« <i>R</i> [g] ã®ã«ãŠã <i>X</i> åãšæ°Ž <i>Y</i> [L] ã远å ãããšïŒãã®æ¿åºŠã¯ (<i>R<sub>0</sub> + X R</i>) / (<i>W<sub>0</sub> + Y</i>) [g/L] ã«ãªãïŒ
ã«ãŠã¯å€§éã«ãããã®ã®ïŒäœ¿ãéããã®ã¯è¯ããªããšèããããªãã¯ïŒè¿œå ããã«ãŠã®åæ°ãåºæ¥ãéãå°ãªãããŠæ¿åºŠ <i>C</i> [g/L] ã®ã«ã¬ãŒãäœãããšã«ããïŒ
</p>
<p>æ¿åºŠ <i>R<sub>0</sub>/W<sub>0</sub></i> [g/L] ã®ã«ã¬ãŒã«ïŒã«ãŠãæ°Žã®ããããïŒãŸãã¯ãã®äž¡æ¹ãé©åã«å ããããšã«ãã£ãŠæ¿åºŠ <i>C</i> [g/L] ã®ã«ã¬ãŒãäœããšãïŒè¿œå ãã¹ãã«ãŠã®åæ° <i>X</i> ã®æå°å€ãæ±ããŠæ¬²ããïŒ
</p>
<p>ãã ãïŒä»åã®ã«ã¬ãŒäœãã«ã€ããŠã¯ïŒä»¥äžã®äºæã«æ³šæããããšïŒ
</p><ul><li>远å ããã«ãŠã®åæ° <i>X</i> ã®å€ã¯ 0 以äžã®æŽæ°ã§ãªããã°ãªããªãïŒã€ãŸãïŒã«ãŠã 1/3 ååã ã远å ããïŒãšãã£ãããšã¯åºæ¥ãªãïŒ
</li><li>远å ããæ°Žã®äœç© <i>Y</i> ã®å€ã¯ 0 以äžã®å®æ°ãšããŠè¯ãïŒæŽæ°ã§ããå¿
èŠã¯ãªãïŒ
</li><li>ã«ãŠãæ°Žã®ããããïŒãŸãã¯ãã®äž¡æ¹ã远å ããªããŠãæ¿åºŠ <i>C</i> ã®ã«ã¬ãŒãäœãããšãåºæ¥ãå ŽåãããïŒ
</li><li>ã«ãŠãæ°Žã¯ååãªéã確ä¿ããŠããã®ã§ïŒã«ãŠãæ°Žãè¶³ããæ¿åºŠ <i>C</i> ã®ã«ã¬ãŒãäœãããšãåºæ¥ãªãïŒãšããäºæ
ã¯èµ·ãããªããšããŠè¯ãïŒ
</li></ul>
<h3>Input</h3>
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ
åããŒã¿ã»ãã㯠1 è¡ãããªãïŒæ¬¡ã®åœ¢åŒã§è¡šãããïŒ
</p>
<blockquote><i>R<sub>0</sub></i> <i>W<sub>0</sub></i> <i>C</i> <i>R</i></blockquote>
<p>ããã§ïŒ<i>R<sub>0</sub></i>ïŒ<i>W<sub>0</sub></i>ïŒ<i>C</i>ïŒ<i>R</i> ã¯ããããäœãããã®ã«ã¬ãŒã«æ¢ã«æº¶ã蟌ãã ã«ãŠã®è³ªé [g]ïŒã«ã¬ãŒã«å«ãŸããæ°Žã®äœç© [L]ïŒããªããäœãããã«ã¬ãŒã®æ¿åºŠ [g/L]ïŒã«ãŠ 1 åãããã®è³ªé [g] ã衚ãïŒ
ãããã®å€ã¯ïŒå
šãŠ 1 ä»¥äž 100 以äžã®æŽæ°ã§ããïŒ
å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã 4 ã€ã®ãŒããããªãè¡ã«ãã£ãŠç€ºãããïŒ
</p>
<h3>Output</h3>
<p>åããŒã¿ã»ããã«ã€ããŠïŒ<i>W<sub>0</sub></i> [L] ã®æ°Žã« <i>R<sub>0</sub></i> [g] ã®ã«ãŠãæ··ããäœãããã®ã«ã¬ãŒããïŒæ¿åºŠ <i>C</i> ã®ã«ã¬ãŒãäœãããã«è¿œå ããå¿
èŠã®ããã«ãŠã®åæ°ã®æå°å€ã 1 è¡ã§åºåããããšïŒè¿œå ããæ°Žã®éãåºåããŠã¯ãªããªãïŒ
</p>
<p>å
¥åå¶çŽããïŒåããŒã¿ã»ããã®çããšãªãã«ãŠã®åæ°ã®æå°å€ã¯ïŒ32ããã笊å·ä»ãæŽæ°ã§è¡šçŸãããç¯å²ã«ãããŸãããšãä¿èšŒãããããšã«æ³šæããïŒ
</p>
<h3>Sample Input</h3>
<pre>10 5 3 4
2 5 2 3
91 13 7 62
10 1 3 5
20 100 2 20
2 14 7 1
0 0 0 0</pre>
<h3>Output for Sample Input</h3>
<pre>2
3
0
0
9
96
</pre> |
p03878 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>There are <var>N</var> computers and <var>N</var> sockets in a one-dimensional world.
The coordinate of the <var>i</var>-th computer is <var>a_i</var>, and the coordinate of the <var>i</var>-th socket is <var>b_i</var>.
It is guaranteed that these <var>2N</var> coordinates are pairwise distinct.</p>
<p>Snuke wants to connect each computer to a socket using a cable.
Each socket can be connected to only one computer.</p>
<p>In how many ways can he minimize the total length of the cables?
Compute the answer modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^5</var></li>
<li><var>0 †a_i, b_i †10^9</var></li>
<li>The coordinates are integers.</li>
<li>The coordinates are pairwise distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var>
:
<var>a_N</var>
<var>b_1</var>
:
<var>b_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways to minimize the total length of the cables, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
0
10
20
30
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>There are two optimal connections: <var>0-20, 10-30</var> and <var>0-30, 10-20</var>.
In both connections the total length of the cables is <var>40</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
3
10
8
7
12
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre></section>
</div>
</span> |
p00307 |
<h1>ãããã«ãã§</h1>
<p>
ããªãã¯ãããã«ãã§ãçµå¶ããŠããŸãã仿¥ããªãã¯ãé¡§å®¢ã«ææããç¶ããŠããåé¡ã解決ããããšåãçµãã§ããŸãããã®åé¡ãšã¯ãåºèã®æ¬æ£ã®åè¡æ¬ãå·»æ°é ã«äžŠãã§ããããç®çã®åè¡æ¬ãæ¢ãã ãã®ãé¢åã ãšããèŠæ
ã§ãã
</p>
<p>
ããªãã®åºèã§äžçªå·»æ°ã®å€ãåè¡æ¬ã¯ãåæ¢åµ èµ€ãã³ãïŒéç§°ãèµ€ãã³ãïŒã§ããããŸãã«é·ç·šãªã®ã§ãç¹å¥ãªæ¬æ£ããèµ€ãã³ãã®ããã«çšæããŸããã
</p>
<p>
åè¡æ¬ã®åå·»ã®éããšåãã¯æ§ã
ã§ãæ¬æ£ã®å段ã®å¹
ãšãåæ®µã«äžŠã¹ãããšãã§ããæ¬ã®éãã®äžéãæ§ã
ã§ããããªãã¯ãæ¬¡ã®æ¡ä»¶ãæºè¶³ããããã«æ¬æ£ã«æ¬ã䞊ã¹ãããšã«ããŸããã
</p>
<ul>
<li> 1 å·»ããããå·»ãŸã§ã®ãèµ€ãã³ããæ¬æ£ã«äžŠãã§ããã</li>
<li> ããããã®æ®µã«ã¯ãå·»æ°é ã«ïŒéäžã§æããŠããå·»ããªãããã«ïŒæ¬ã䞊ã¶ã</li>
<li> åæ®µã«äžŠã¹ãæ¬ã®éãã®åèšãããã®æ®µã§å®ããããéãã®äžéãè¶
ããªãã</li>
<li> åæ®µã«äžŠã¹ãæ¬ã®åãã®åèšãããã®æ®µã®å¹
ãè¶
ããªãã</li>
</ul>
<p>
ãããã®æ¡ä»¶ãæºããããšãïŒãã®æ¬æ£ã«æå€§ã§äœå·»ãŸã§ãèµ€ãã³ãã䞊ã¹ãããšãã§ããããæ±ããããã°ã©ã ãäœæããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>M</var> <var>N</var>
<var>w<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>w<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>w<sub>M</sub></var> <var>t<sub>M</sub></var>
<var>c<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>c<sub>2</sub></var> <var>b<sub>2</sub></var>
:
<var>c<sub>N</sub></var> <var>b<sub>N</sub></var>
</pre>
<p>
æåã®ïŒè¡ã«ãèµ€ãã³ãã®å·»æ° <var>M</var> (1 ≤ <var>M</var> ≤ 200000) ãšæ¬æ£ã®æ®µæ° <var>N</var> (1 ≤ <var>N</var> ≤ 15) ãäžãããããç¶ã <var>M</var> è¡ã«ããèµ€ãã³ãã®åè¡æ¬ <var>i</var> å·»ç®ã®éã <var>w<sub>i</sub></var> (1 ≤ <var>w<sub>i</sub></var> ≤ 100) ãšåã <var>t<sub>i</sub></var> (1 ≤ <var>t<sub>i</sub></var> ≤ 100) ãè¡šãæŽæ°ãäžãããããç¶ã <var>N</var> è¡ã«ãæ¬æ£ã® <var>i</var> 段ç®ã®éãã®äžé <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 10<sup>8</sup>)ãšå¹
<var>b<sub>i</sub></var> (1 ≤ <var>b<sub>i</sub></var> ≤ 10<sup>8</sup>) ãè¡šãæŽæ°ãäžããããã
</p>
<h2>åºå</h2>
<p>
æ¬æ£ã«äžŠã¹ãããšãã§ããæå€§ã®ãèµ€ãã³ãå·»æ°ãïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h2>å
¥åäŸïŒ</h2>
<pre>
3 4
2 2
3 3
4 4
3 3
4 4
1 1
2 2
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
3
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
2 2
1 2
2 1
2 1
2 1
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
0
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
3 2
1 2
2 2
2 1
3 3
2 2
</pre>
<h2> åºåäŸïŒ</h2>
<pre>
2
</pre>
<br>
<h2>å
¥åäŸïŒ</h2>
<pre>
3 2
1 2
2 1
2 2
2 2
3 3
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
3
</pre> |
p00612 |
<H1><font color="#000000">Problem H:</font> Hedro's Hexahedron</H1>
<p>
Dr. Hedro is astonished. According to his theory, we can make sludge that can dissolve almost everything on the earth. Now he's trying to produce the sludge to verify his theory.
</p>
<p>
The sludge is produced in a rectangular solid shaped tank whose size is <i>N</i> × <i>N</i> × 2. Let coordinate of two corner points of tank be (-<i>N</i>/2, -<i>N</i>/2, -1), (<i>N</i>/2, <i>N</i>/2, 1) as shown in Figure 1.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hedro2">
<p>Figure 1</p>
</center>
<br>
<p>
Doctor pours liquid that is ingredient of the sludge until height of the liquid becomes 1. Next, he get a lid on a tank and rotates slowly, without ruffling, with respect to <i>z</i> axis (Figure 2). After rotating enough long time, sludge is produced. Volume of liquid never changes through this operation.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hedro">
<p>Figure 2</p>
</center>
<br>
<p>
Needless to say, ordinary materials cannot be the tank. According to Doctor's theory, there is only one material that is not dissolved by the sludge on the earth. Doctor named it finaldefenceproblem (for short, FDP). To attach FDP tiles inside the tank allows to produce the sludge.
</p>
<p>
Since to produce FDP is very difficult, the size of FDP tiles are limited to 1 * 1. At first, doctor tried to cover entire the entire inside of the tank. However, it turned out that to make enough number FDP tiles that can cover completely is impossible because it takes too long time. Therefore, he decided to replace FDP tiles where an area the sludge touches is zero with those of ordinary materials. All tiles are very thin, so never affects height of the sludge.
</p>
<p>
How many number of FDP tiles does doctor need? He has imposed this tough problem on you, his helper.
</p>
<H2>Input</H2>
<p>
Input file contains several data sets.
Each data set has one integer that describes <i>N</i>.
</p>
<p>
Input ends when <i>N</i> = 0. You should output nothing for this case.
</p>
<H2>Output</H2>
<p>
For each data set, print the number of tiles in a line.
</p>
<H2>Constraints</H2>
<ul>
<li>Judge data consists of at most 150 datasets.</li>
<li>2 ≤ <i>N</i> ≤ 10<sup>12</sup></li>
<li><i>N</i> is even number</li>
</ul>
<H2>Sample Input</H2>
<pre>
2
4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
24
64
</pre>
|
p01900 |
<link rel="stylesheet" href="css/description.css" type="text/css" />
<script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script>
<h2>C : Mod!Mod!</h2>
<h3>ç©èª</h3>
<p>
ãããïŒæ¢ããŠãŸããç®æèšŒèšïŒ
äŒæŽ¥ã«æªçãçŸããïŒã¿ããªã®ãŠããŠãæ£ãçãŸããïŒç¯äººã¯èª°ã ïŒïŒ
è§£ããããïŒMod!Mod!
</p>
<h3>å顿</h3>
<p>"ã¢ã€ãº"...ããã¯éžã°ããè
ã®å¿ã«èšããå¥è·¡ã®ã€ãŒã¿...ãç¹æ®èœå"ã¢ã€ãº"ã䜿ãã°ã©ããªãã®ã ã£ãŠçãããšãã§ããã</p>
<p>äŒæŽ¥äžã®å€§æªçãããããŸãã¯äžçãè¬ã§æºããããã«<var>n</var>äººã®æ¢åµããããŠããŠãæ£ããçãããšã«ããããŠããŠãæ£ãšã¯ããããŸãã倧奜ããªãã ã®ãèåã§ããã<var>n</var>äººã®æ¢åµã¯ããããæ°æ¬ã®ãŠããŠãæ£ãæã£ãŠããããŸããããããŸãã¯åŒ·æ¬²ãªããããããã®æ¢åµãããŠããŠãæ£ãçããšãããã®æ¢åµãææããå
šãŠã®ãŠããŠãæ£ãçãã</p>
<p>ãŠããŠãæ£ã®3æ¬åæé£ãã«ããã£ãŠããããããŸãã¯ã3æ¬ä»¥äžã®ãŠããŠãæ£ãæå
ã«ãããšããèªæã«è² ããŠææã¡ã®ãŠããŠãæ£ã3æ¬æªæºã«ãªããŸã§ã3æ¬ãã€ãŠããŠãæ£ãé£ã¹ãŠããŸããããããããããŸãã¯æå
ã«ãŠããŠãæ£ããªããšã·ã§ãã¯ã§ã¢ã€ãºã倱ã£ãŠããŸãããã以äžãŠããŠãæ£ãçãããšãã§ããªããªã£ãŠããŸããã€ãŸãããŠããŠãæ£ãçãããã«ã¯ææã¡ã®ãŠããŠãæ£ã®æ¬æ°ã1æ¬ä»¥äžã«ããŠããå¿
èŠãããã0æ¬ã«ãªããšãã以äžãŠããŠãæ£ãçãããšãã§ããªããªãã</p>
<p>å°ãã§ãå€ãã®æ¢åµãããŠããŠãæ£ãçã¿ããããããŸãã¯ãã©ã®æ¢åµããé ã«ãŠããŠãæ£ãçããã«ãã£ãŠäœäººã®æ¢åµãããŠããŠãæ£ãçããã®ããå€ããããšã«æ°ã¥ãããããããããããŸãã«ã¯é£ããããšã¯åãããªããããããŒïŒãããããŸãã®åªç§ãªéšäžã§ããããªãã¯ãããããŸãã®ä»£ããã«æå€§ã§äœäººã®æ¢åµãããŠããŠãæ£ãçãããšãã§ããã®ããæ±ããããã°ã©ã ãæžããŠãããããšã«ããã</p>
<p>æ¢åµã®äººæ°<var>n</var>ãšã<var>n</var>äººã®æ¢åµããããããäœæ¬ã®ãŠããŠãæ£ãçãã®ããäžããããã®ã§ãæé©ãªé çªã§æ¢åµãããŠããŠãæ£ãçãã ãšããæå€§ã§äœäººã®æ¢åµãããŠããŠãæ£ãçãããšãã§ããããåºåããããã°ã©ã ãäœæããããã ããã¯ããã®ææã¡ã®ãŠããŠãæ£ã®æ¬æ°ã¯0ã§ããããæåã«éãææã¡ã0æ¬ã§ããŠããŠãæ£ãçãããšãã§ãããšããã</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åã¯2è¡ãããªãã以äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>n</var>
<var>a_1</var> <var>a_2</var> ⊠<var>a_n</var>
</pre>
<p>
1è¡ç®ã«ã¯ããŠããŠãæ£ãçãæ¢åµã®æ°ã§ããæŽæ°<var>n</var>ãäžããããã
2è¡ç®ã«ã¯ã忢åµããçããŠããŠãæ£ã®æ¬æ°<var>n</var>åã空çœåºåãã§äžããããã
</p>
<h3>å¶çŽ</h3>
<ul>
<li><var>1 ≤ n ≤ 500{,}000</var></li>
<li><var>1 ≤ a_i ≤ 9</var> (<var>1 ≤ i ≤ n</var>)</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>æé©ãªé çªã§æ¢åµãããŠããŠãæ£ãçãã ãšããæå€§ã§äœäººã®æ¢åµãããŠããŠãæ£ãçãããšãã§ãããäžè¡ã«åºåããã</p>
<h3>å
¥åäŸ1</h3>
<pre>
6
2 5 2 5 2 1
</pre>
<h3>åºåäŸ1</h3>
<pre>5</pre>
<p>2 5 1 2 5ã®é ã§çããš5人ããçãããšãã§ãããã©ã®ãããªé åºã§çãã§ã6人ããçãããšã¯ã§ããªãã</p>
<h3>å
¥åäŸ2</h3>
<pre>
3
3 6 9
</pre>
<h3>åºåäŸ2</h3>
<pre>1</pre>
<p>ã©ã®1人ããçãã§ãææã¡ã®ãŠããŠãæ£ã®æ¬æ°ã¯0ã«ãªã£ãŠããŸããã¢ã€ãºã倱ã£ãŠããŸãã</p>
<h3>å
¥åäŸ3</h3>
<pre>
6
1 2 3 4 5 6
</pre>
<h3>åºåäŸ3</h3>
<pre>6</pre> |
p00242 |
<H1>å
¥ååè£</H1>
<p>
æºåž¯é»è©±ã«ã¯ãã¡ãŒã«ãªã©ã®æç« ãå¹çè¯ãå
¥åããããã«å
¥ååè£ã衚瀺ããæ©èœãæèŒãããŠããŸããããã¯ã䜿ãããé »åºŠãé«ãåèªãèšé²ããŠãããå
¥åãããæåãé æåã«æã€åèªãå
¥ååè£ãšããŠæç€ºãããã®ã§ããäŸãã°ãæ®æ®µâcomputerâãšããåèªãå€ãå
¥åããŠãããªããâcâãšå
¥åããã ãã§åè£ãšããŠâcomputerâãæç€ºãããŸãããã®ãããªæ©èœã®åºæ¬éšåãäœæããŠã¿ãŸãããã
</p>
<p>
æç« ãæåãå
¥åãšãããã®æåãé æåã«æã€åèªãåºçŸæ°ã®é ã«åºåããããã°ã©ã ãäœæããŠãã ããããã ããåºçŸæ°ãåãåèªãè€æ°ããå Žåã¯ãèŸæžåŒé åºã§åºåããŸããåºåããåèªã¯æå€§5ã€ãŸã§ãšããŸãã該åœããåèªãååšããªãå Žåã¯âNAâãšåºåããŠãã ããã
</p>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã§è¡šãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>line<sub>1</sub></var>
<var>line<sub>2</sub></var>
:
<var>line<sub>n</sub></var>
<var>k</var>
</pre>
<p>
1è¡ç®ã«æç« ã®è¡æ° <var>n</var> (1 ≤ <var>n</var> ≤ 10) ãäžããããŸããç¶ã <var>n</var> è¡ã«æç« ãäžããããŸããæç« ã¯åè§è±å°æåãšåè§ç©ºçœãããªããïŒè¡ã®æåæ°ã¯1æå以äž1024æå以äžãšããŸãã空çœã«ãã£ãŠåºåãããåèªã¯1æå以äž20æå以äžã§ãã
</p>
<p>
ç¶ãè¡ã«é æå <var>k</var> ãåè§è±åã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<h2>åºå</h2>
<p>
ããŒã¿ã»ããããšã«ãæå®ãããæåãé æåã«ãã€åèªãŸãã¯âNAâ ãåºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
1
ben likes bananas the best among many fruits because bananas are sweet and cheap
b
1
winners get to visit aizu and the university of aizu and make many friends as well
a
3
ask alex about
the answer for the
assignment on android apps
a
2
programming is both
a sport and an intellectual puzzle
c
0
</pre>
<h2>åºåäŸ</h2>
<pre>
bananas because ben best
aizu and as
about alex android answer apps
NA
</pre> |
p02785 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Fennec is fighting with <var>N</var> monsters.</p>
<p>The <em>health</em> of the <var>i</var>-th monster is <var>H_i</var>.</p>
<p>Fennec can do the following two actions:</p>
<ul>
<li>Attack: Fennec chooses one monster. That monster's health will decrease by <var>1</var>.</li>
<li>Special Move: Fennec chooses one monster. That monster's health will become <var>0</var>.</li>
</ul>
<p>There is no way other than Attack and Special Move to decrease the monsters' health.</p>
<p>Fennec wins when all the monsters' healths become <var>0</var> or below.</p>
<p>Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most <var>K</var> times.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>0 \leq K \leq 2 \times 10^5</var></li>
<li><var>1 \leq H_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>H_1</var> <var>...</var> <var>H_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 1
4 1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 9
7 9 3 2 3 8 4 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>She can use Special Move on all the monsters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 0
1000000000 1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3000000000
</pre>
<p>Watch out for overflow.</p></section>
</div>
</span> |
p03897 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have an <var>NÃN</var> checkerboard.</p>
<p>From the square at the upper left corner, a square that is <var>i</var> squares to the right and <var>j</var> squares below is denoted as <var>(i, j)</var>. Particularly, the square at the upper left corner is denoted as <var>(0, 0)</var>.</p>
<p>Each square <var>(i, j)</var> such that <var>i+j</var> is even, is colored black, and the other squares are colored white.</p>
<p>We will satisfy the following condition by painting some of the white squares:</p>
<ul>
<li>Any black square can be reached from square <var>(0, 0)</var> by repeatedly moving to a black square that shares a side with the current square.</li>
</ul>
<p>Achieve the objective by painting at most <var>170000</var> squares black.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 1,000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the squares to paint in the following format:</p>
<pre><var>K</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
:
<var>x_K</var> <var>y_K</var>
</pre>
<p>This means that a total of <var>K</var> squares are painted black, the <var>i</var>-th of which is <var>(x_i, y_i)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Judging</h3><p>The output is considered correct only if all of the following conditions are satisfied:</p>
<ul>
<li><var>0 \leq K \leq 170000</var></li>
<li><var>0 \leq x_i, y_i \leq N-1</var></li>
<li>For each <var>i</var>, <var>x_i + y_i</var> is odd.</li>
<li>If <var>i \neq j</var>, then <var>(x_i, y_i) \neq (x_j, y_j)</var>.</li>
<li>The condition in the statement is satisfied by painting all specified squares.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
1 0
</pre>
</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>3
0 1
2 1
2 3
</pre></section>
</div>
</span> |
p01003 |
<h1>Problem E: Doragoso Ball</h1>
<h2>Problem</h2>
<p>
<var> L </var>åéãããšãã©ãŽãœãçŸãã©ããªé¡ãã§ãäžã€ã ãå¶ããŠããããšãããã©ãŽãœããŒã«ããšããè¿·å®®ã«æ£ãã°ã£ãŠãããå
¥å£ããã¹ã¿ãŒãããéäžã§ç«ã¡æ¢ãŸãããšãªããã¹ãŠã®ããŒã«ãååããããããè¿·å®®å
ã«ããç¥å£ã«å¥çŽãããã®ãŸãŸåªæãå±ãããšãã©ãŽãœãçŸãé¡ããå¶ããŠããããšããããã ããåªæãå±ãå§ããæéã¯å
¥å£ããããŒã«ãå¥çŽãããŸã§ã®ã«ãŒãã®ãã¡ãç§»åæéã<var> K </var>çªç®ã«çãã«ãŒãã§ç§»åãããšãã®æéã§ãªããã°ãªããªãã
</p>
<p>
ãã®è¿·å®®ã¯éšå±ãšãããéè·¯ãããªããéšå±ãšéšå±ã¯ãããéè·¯ãéãäºã«ãã£ãŠè¡ãæ¥ã§ããããã©ãŽãœããŒã«ã¯ãããã®æ°ããéšå±ã®ã©ããã«èœã¡ãŠããã<!--ã ããç§åŠã®é²æ©ã«ãããè¿·å®®ã®éšå±ãšéšå±ã®äœçœ®é¢ä¿ã®è§£æãé²ã¿ããã©ãŽãœã¬ãŒããŒã®éçºã«ãã£ãŠã©ã®éšå±ã«ããŒã«ãèœã¡ãŠããããææ¡ã§ããäºå®ã§ãããæç ç©¶æã«éšå±ã®äœçœ®é¢ä¿ãšããŒã«ã®äœçœ®ã®ããŒã¿ãéãããäºå®ã§ããããšããç ç©¶æã§æãåªç§ãªããã°ã©ããŒã§ããããªãã¯ãåªæãå±ãå§ããã¹ãæéãæ±ãããšããéèŠãªä»»åãäžããããã-->ãªããè¿·å®®ã¯å
¥ãå£ããç¥å£ãžãã©ãã€ãéãååšããªãå¯èœæ§ãããããã ããŸããç§»åæéã¯ãããéè·¯ã®ç§»åã ããèæ
®ããéšå±ã®äžãç§»åããæéãããŒã«ãæŸããšãã«ãããæéãç¥å£ã«å¥çŽããæéã¯èæ
®ããªããŠããã<!--ãŸããåãéšå±ã«äœåºŠã蚪ããŠããããããã©ãŽãœããŒã«ãããéšå±ã«åããŠå
¥ã£ãå Žåã¯ããã®ããŒã«ãæŸãããšã«ããã-->ãŸããåãéè·¯ãåãéšå±ã«äœåºŠã蚪ããŠããããããã©ãŽãœããŒã«ãããéšå±ã«åããŠå
¥ã£ãå Žåã¯ããã®ããŒã«ãæŸãããšã«ãããç¥å£ã«å°éãããšããå¿
ãããããŒã«ãçŽããªããã°ãªããªãããã§ã¯ãªãã
</p>
<p>
è¿·å®®ã®å
éšæ§é ã®æ
å ±ãšè¿·å®®ã®å
¥ãå£ãç¥å£ã®å ŽæãšããŒã«ã®æ°<var> L </var>ãšããŒã«ã®é
çœ®å Žæãšæ±ããããŠããæçãªçµè·¯ã®é äœ<var> K </var>ãäžããããã®ã§ãåªæãå±ãå§ããã¹ãæéãæ±ããã
</p>
<p>
ãŸããç°ãªãç§»åã«ãŒãã§ããç§»åæéãåãã§ããå Žåã¯ãããã®ã«ãŒãã¯åãé äœãšããŠæ±ãã
<br/>
äŸãã°ã
<br/>
<pre>
ã«ãŒãA æé 2
ã«ãŒãB æé 5
ã«ãŒãC æé 5
ã«ãŒãD æé 5
ã«ãŒãE æé 5
ã«ãŒãF æé 7
</pre>
<p>
ãã®ãããªãšããã«ãŒãB,C,D,Eã¯2äœãã€3äœãã€4äœãã€5äœãšããŠæ±ããã«ãŒãFã¯6äœãšããŠæ±ãã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãã</br>
åããŒã¿ã»ããã¯ä»¥äžã®ãã©ãŒãããã§è¡šãããã
</p>
<pre>
<var>N</var> <var>M</var> <var>L</var> <var>K</var>
<var>u<sub>1</sub></var> <var>v<sub>1</sub></var> <var>c<sub>1</sub></var>
âŠ
<var>u<sub>M</sub></var> <var>v<sub>M</sub></var> <var>c<sub>M</sub></var>
<var>S</var> <var>G</var>
<var>B<sub>1</sub></var>
<var>B<sub>2</sub></var>
âŠ
<var>B<sub>L</sub></var>
</pre>
<p>
æåã«<var> N </var>,<var> M </var>,<var> L </var>,<var> K </var>ãäžããããã</br>
ãããããéšå±ã®æ°ããããéè·¯ã®æ°ãããŒã«ã®æ°ãæ±ããããŠããæçãªçµè·¯ã®é äœã衚ããããããã®éšå±ã¯1ã<var> N </var>ã§çªå·ä»ããããã</br>
次ã«<var> M </var>è¡ã«ãããéè·¯ã®æ
å ±ã<var> u<sub>i</sub> </var>,<var> v<sub>i</sub> </var>,<var> c<sub>i</sub> </var>ãäžããããã</br>
éšå±<var> u<sub>i</sub> </var>,<var> v<sub>i</sub> </var>éã«ãããéè·¯ãååšããééããã®ã«æé<var> c<sub>i</sub> </var>ããããããšã衚ãã</br>
次ã«<var> S </var>,<var> G </var>ãäžããããã</br>
ãããããè¿·å®®ã®å
¥ãå£ãšç¥å£ãããéšå±çªå·ã衚ãã</br>
次ã«<var> L </var>è¡ã«ããã£ãŠãã©ãŽãœããŒã«ãèœã¡ãŠããéšå±ã®çªå·<var> B<sub>i</sub> </var>( 1 ≤<var> i </var>≤<var> L </var>)ãäžããããã</br>
</p>
<p>
å
¥åã®çµããã¯4ã€ã®ãŒããããªãã</br>
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>å
¥åã«å«ãŸããå€ã¯ãã¹ãп޿°</li>
<li>2 ≤<var> N </var>≤ 50</li>
<li>0 ≤<var> M </var>≤ 1225</li>
<li>1 ≤<var> L </var>≤ 7</li>
<li>1 ≤<var> K </var>≤ 10</li>
<li>1 ≤<var> S </var>,<var> G </var>≤ <var>N</var></li>
<li>1 ≤<var> B<sub>i</sub> </var>≤ <var>N </var>( 1 ≤<var> i </var>≤ <var> L </var>)</li>
<li><var> B<sub>i</sub> </var>≠<var> B<sub>j</sub> </var> ( 1 ≤<var> i </var><<var> j </var>≤<var> L </var>)</li>
<li>1 ≤<var> u<sub>i</sub> </var>,<var> v<sub>i</sub> </var>≤<var> N </var>( 1 ≤<var> i </var>≤ <var> M </var>)</li>
<li>1 ≤<var> c<sub>i</sub> </var>≤ 1000 ( 1 ≤<var> i </var>≤ <var> M </var>)</li>
<li>ããŒã¿ã»ããã¯æå€§10åã§ãã</li>
</ul>
<h2>Output</h2>
<p>åããŒã¿ã»ããã«å¯Ÿããåªæãå±ãå§ããã¹ãæéã1è¡ã«åºåããã<var> K </var>çªç®ã«çãçµè·¯ãååšããªãå Žåã¯"NA"ã1è¡ã«åºåããã</p>
<h2>Sample Input</h2>
<pre>
9 14 5 10
1 2 1
1 4 5
2 4 4
2 3 3
2 6 2
3 6 3
3 7 2
4 6 5
4 5 6
5 8 8
6 7 3
7 8 1
7 9 9
8 9 2
1 9
1
2
5
7
9
4 5 1 3
1 2 1
1 3 2
2 3 2
2 4 9
3 4 1
1 4
2
4 5 1 10
1 2 1
1 3 2
2 3 2
2 4 9
3 4 1
1 4
2
4 3 1 1
1 2 1
2 3 1
3 4 1
1 4
1
4 3 1 2
1 2 1
2 3 1
3 4 1
1 4
1
4 3 1 10
1 2 1
2 3 1
3 4 1
1 4
1
2 1 1 1
1 2 1
1 2
1
2 1 1 10
1 2 1
1 2
1
4 2 1 4
1 2 1
3 4 1
1 4
2
0 0 0 0
</pre>
<h2>Sample Output</h2>
<pre>
27
6
8
3
5
7
1
19
NA
</pre> |
p01453 |
<H1>Problem G: ã¹ããªã³ã°ã»ã¿ã€ã«</H1>
<p>
ããæãããªããç®èŠãããšãããã¯ããã ããã®è¿·å®®ã®äžã ã£ãã
</p>
<p>
ãªãèªåããããªèŠç¥ãã¬å Žæã«ããã®ãã¯ããããªãããã®å Žã§ãã£ãšå©ããåŸ
ã€ãšããéžæè¢ã
ããã«ã¯ãããããããã£ãè¿·å®®ã®äžã«é·å±
ããŠãããšããã€ãã¯å¿
ãçªé¢šãå¹ããŠããŠå¹ãé£ã°ã
ããŠããŸãããšããããªãã¯çµéšäžç¥ã£ãŠãããããããçªé¢šãå¹ããŠãããŸã§ã®æéã¯å€æã®ãã
ãããªããããã§ããªãã¯ãè¿·å®®ããè±åºãããŸã§ã«å¿
èŠãªç§»ååæ°ã®æåŸ
å€ãæå°ã«ãªãããã«è¡
åããã®ãæåã®æŠç¥ã ãšèããã
</p>
<p>
è¶³å
ã«èœã¡ãŠããæ£äœäžæã®å·»ç©ãæŸã£ãŠãããã«èªãã§ã¿ããšãããå¶ç¶ã«ãè¿·å®®ã®å
šäœãããã
ç¥èŠããããšãã§ãããããã«ãããŸããŸæã£ãŠããèã飲ãããšã§ããã¹ãŠã®ã¯ãã®äœçœ®ãç¥ãã
ãšãã§ãããã©ããããã®è¿·å®®ã«ã¯ãå±éºãªã¢ã³ã¹ã¿ãŒããã以å€ã®ã¯ãã¯ååšããªããããã
</p>
<p>
ãã®è¿·å®®ã¯ãããã€ãã®çš®é¡ã®ã¿ã€ã«ãé·æ¹åœ¢ã«äžŠãã 圢ãããŠãããããšãã°ä»¥äžã®ããã«ããã
ãããã
</p>
<center>
<pre>
########
#..##g.#
#*#.*#.#
#......#
#*s#*.*#
########
</pre>
</center>
<p>
ã.ãïŒåºããã®äžãªãèªç±ã«æ©ãåãããšãã§ããã
</p>
<p>
ã#ãïŒå£ãããªãã¯å£ã®äžã«å
¥ãããšã¯ã§ããªãã
</p>
<p>
ãsãïŒããªãã®æåã®äœçœ®ããã®ã¿ã€ã«ã®äžã¯åºã«ãªã£ãŠããã
</p>
<p>
ãgãïŒé段ããã®ã¿ã€ã«ã®äžã«ä¹ãã°ãè¿·å®®ãè±åºããããšã«ãªãã
</p>
<p>
ã*ãïŒããããã®ã¿ã€ã«ã®äžã«ä¹ããšãããããã®åºã®äžïŒé段ãããã®ã¿ã€ã«ã¯é€ãïŒã«ã©ã³ãã ã«é£ã°ããããããããã®åºã«é£ã°ããã確çã¯ãã¹ãŠçããã
</p>
<p>
ã¿ã€ã«ã®çš®é¡ã¯ããã®ïŒã€ã®ããããã§ããã
</p>
<p>
ããªãã¯ãçŸåšä¹ã£ãŠããã¿ã€ã«ããé£ãåã£ãã¿ã€ã«ãžãäžäžå·Šå³ããããã®æ¹åã«ïŒãã¹ãã€ç§»
åããããšãã§ããããã ããããã¡ã«ç§»åããããšã¯ã§ããªãã
</p>
<p>
è¿·å®®ã®ããããäžãããããšããæåã®æŠç¥ããšã£ãå Žåã«è¿·å®®ããè±åºãããŸã§ã«å¿
èŠãªç§»ååæ°
ã®æåŸ
å€ãæ±ãããããã§é£ã°ãããã®ã¯ç§»ååæ°ã«ã¯å«ããªãã
</p>
<H2>Input</H2>
<p>
<i>W H</i><br>
<i>c</i><sub>11</sub> <i>c</i><sub>12</sub> ... <i>c</i><sub>1<i>w</i></sub><br>
<i>c</i><sub>21</sub> <i>c</i><sub>22</sub> ... <i>c</i><sub>2<i>w</i></sub><br>
:: :<br>
<i>c</i><sub><i>h</i>1</sub> <i>c</i><sub><i>h</i>2</sub> ... <i>c</i><sub><i>c</i><i>w</i></sub><br>
</p>
<p>
å
¥åã®ïŒè¡ç®ã«ã¯ãæŽæ°<i>W</i>ïŒ3 ≤ <i>W</i> ≤ 500ïŒãšæŽæ°<i>H</i>ïŒ3 ≤ <i>H</i> ≤ 500ïŒãããã®é ã«ç©ºçœåºåãã§æžãããŠãããæŽæ°<i>W</i> ã¯è¿·å®®ã®æšªå¹
ããæŽæ°<i>H</i> ã¯è¿·å®®ã®çžŠå¹
ãããããã
</p>
<p>
ç¶ã<i>H</i> è¡ã«ã¯ãè¿·å®®ã®ãããããããã<i>W</i> åã®æåãæžãããŠããïŒç©ºçœåºåãã§ã¯ãªãïŒããã®éšåã®åœ¢åŒã¯ãå
ã«æããäŸã®ãšããã§ããããªããããŒã¿äžã«ãsããšãgãã¯ãããããã¡ããã©ïŒåãã€åºçŸããããŸããè¿·å®®ã®åšå²ïŒãã¹ã¯ãå¿
ãå£ã§å²ãŸããŠããã
</p>
<p>
ãªããäžããããè¿·å®®ã§ã¯ãã©ã®ããã«ç§»åããããã§ã©ã®ããã«é£ã°ããããšããŠãããããã§é£
ã°ãããåºãä»»æã«èšå®ã§ãããšããŠãè±åºäžå¯èœãªç¶æ
ãã«é¥ãããšã¯ãªããšä»®å®ããŠããã
</p>
<H2>Output</H2>
<p>
æåã®æŠç¥ããšã£ããšãã«ãè±åºãŸã§ã«ãããç§»ååæ°ã®æåŸ
å€ãåºåãããåºåã¯èª€å·®ãå«ãã§ã
ãŠãããããçã®å€ãšã®çžå¯Ÿèª€å·®ã10<sup>-9</sup> æªæºã§ãªããã°ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
8 6
########
#..##g.#
#*#.*#.#
#......#
#*s#*.*#
########
</pre>
<h2>Sample Output 1</h2>
<pre>
5.857142857143
</pre>
<h2>Sample Input 2</h2>
<pre>
21 11
#####################
#*#*.*.*.*.*.*.*.*#*#
#*#...............#*#
#*#.#.#.#.#.#.#.#.#*#
##.#.#.#.#.#.#.#.#.##
#...................#
##.#.#.#.#.#.#.#.#.##
#s#.#.#.#.#.#.#.#.#g#
#...................#
#...................#
#####################
</pre>
<h2>Sample Output 2</h2>
<pre>
20.000000000000
</pre>
<h2>Sample Input 3</h2>
<pre>
9 8
#########
#...#*.*#
#.*.#...#
#...#*.*#
#########
#.s....g#
#.*#.*..#
#########
</pre>
<h2>Sample Output 3</h2>
<pre>
5.000000000000
</pre> |
p03194 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> integers <var>a_1, a_2, ..., a_N</var> not less than <var>1</var>.
The values of <var>a_1, a_2, ..., a_N</var> are not known, but it is known that <var>a_1 \times a_2 \times ... \times a_N = P</var>.</p>
<p>Find the maximum possible greatest common divisor of <var>a_1, a_2, ..., a_N</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{12}</var></li>
<li><var>1 \leq P \leq 10^{12}</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>P</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 24
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>The greatest common divisor would be <var>2</var> when, for example, <var>a_1=2, a_2=6</var> and <var>a_3=2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>As <var>a_i</var> are positive integers, the only possible case is <var>a_1 = a_2 = a_3 = a_4 = a_5 = 1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>111
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4 972439611840
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>206
</pre></section>
</div>
</span> |
p02156 | <h1>Problem H: Ghost</h1>
<h2>Problem</h2>
<p>
幜éãäžçŽç·äžã«å·Šããå³ã«$N$人䞊ãã§ããã<br>
æåãå·Šãã$i$çªç®ã®å¹œéã¯$U_i$ã'L'ãªãã°å·Šãã'R'ãªãã°å³ãåããŠããã<br>
<br>
圌ãã¯ãšãŠãèç
ãªã®ã§ãªãã¹ãæã幜éãèŠãããªãã<br>
<br>
ããªãã¯ãå幜éã«å¯ŸããŠæ¯ãè¿ãããã«æç€ºãã§ããã<br>
åŸããæ¯ãè¿ãã®ã¯æãã®ã§ã$i$çªç®ã®å¹œéãäžåæ¯ãè¿ããš$A_i$ã®ææåºŠãçºçããã<br>
å·ŠãåããŠãã幜éãæ¯ãè¿ããšãå³ãåãã<br>
å³ãåããŠãã幜éãæ¯ãè¿ããšãå·Šãåãã<br>
<br>
$ i < j $ ã«å¯ŸããŠã$i$çªç®ã®å¹œéãå³ãåããŠããŠããã€$j$çªç®ã®å¹œéãå·ŠãåããŠããå Žåã$i$çªç®ã®å¹œéãš$j$çªç®ã®å¹œéã¯åãåã£ãŠãããšå®çŸ©ããã<br>
以äžã®å¶çŽã$M$åäžããããã<br>
$S_i$çªç®ã®å¹œéã¯$T_i$çªç®ã®å¹œéãæãã<br>
æçµçãªç¶æ
ã§ã$S_i$çªç®ã®å¹œéãš$T_i$çªç®ã®å¹œéãåãåã£ãŠãããš$B_i$ã®ææåºŠãçºçããã<br>
<br>
æé©ãªæç€ºãè¡ãªã£ããšãã«çºçããææåºŠã®åèšã®æå°å€ãæ±ããã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$N$ $M$
$U$
$A_1$ $A_2$ $...$ $A_N$
$S_1$ $T_1$ $B_1$
$S_2$ $T_2$ $B_2$
$\vdots$
$S_M$ $T_M$ $B_M$
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \le N \le 500$</li>
<li>$0 \le M \le \min ( N \times (N-1) , 1000 )$</li>
<li>$|U|=N$</li_>
<li>$U_i = $'L' or 'R'</li>
<li>$1 \le A_i \le 1000$</li>
<li>$1 \le B_i \le 1000$</li>
<li>$1 \le S_i,T_i \le N$</li>
<li>$(S_i,T_i) \ne (S_j,T_j), $if $ i \ne j$</li>
<li>$S_i \ne T_i$</li>
</ul>
<h2>Output</h2>
<p>
ææåºŠã®åèšã®æå°å€ãåºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
3 1
RRL
5 5 1
3 1 10
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<p>
3çªç®ã®å¹œéã«æ¯ãåãããã«æç€ºããããšãææåºŠã®åèšã¯1ãšãªããææåºŠã®åèšã0以äžã«ãªããããªæç€ºã¯ååšããªãã®ã§ã1ãåºåããã
</p>
<h2>Sample Input 2</h2>
<pre>
5 5
RLRLL
9 5 1 3 10
1 3 5
2 4 9
4 2 16
1 5 2
3 5 10
</pre>
<h2>Sample Output 2</h2>
<pre>
8
</pre>
|
p00491 |
<H1>ãã¹ã¿ (Pasta) </H1>
<h2> åé¡</h2>
<p>
ããªãã¯ãã¹ã¿ã倧奜ç©ã§ããïŒæ¯æ¥ïŒæ©åŸ¡é£¯ã«ãã¹ã¿ãäœã£ãŠé£ã¹ãŠããïŒããªãã¯ããããœãŒã¹ïŒã¯ãªãŒã ãœãŒã¹ïŒããžã«ãœãŒã¹ã® 3 çš®é¡ã®ãã¹ã¿ãäœãããšãã§ããïŒ
</p>
<p>
N æ¥éã®æ©åŸ¡é£¯ã®äºå®ãèããããšã«ããïŒããããã®æ¥ã« 3 çš®é¡ã®ãã¹ã¿ãã 1 çš®é¡ãéžã¶ïŒãã ãïŒåããã¹ã¿ãç¶ããšé£œããŠããŸãã®ã§ïŒ3 æ¥ä»¥äžé£ç¶ããŠåããã¹ã¿ãéžãã§ã¯ãããªãïŒãŸãïŒN æ¥ã®ãã¡ã® K æ¥åã®ãã¹ã¿ã¯ãã§ã«æ±ºããŠããïŒ
</p>
<p>
å
¥åãšã㊠N ã®å€ãšïŒK æ¥åã®ãã¹ã¿ã®æ
å ±ãäžãããããšãïŒæ¡ä»¶ãã¿ããäºå®ãäœéããããã 10000 ã§å²ã£ãäœããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2> å
¥å</h2>
<p>
å
¥å㯠K + 1 è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯ 2 ã€ã®æŽæ° N, K (3 ⊠N ⊠100ïŒ1 ⊠K ⊠N) ã空çœãåºåããšããŠæžãããŠããïŒ
<p>
1 + i è¡ç® (1 ⊠i ⊠K) ã«ã¯ 2 ã€ã®æŽæ° A<sub>i</sub>, B<sub>i</sub> (1 ⊠A<sub>i</sub> ⊠NïŒ1 ⊠B<sub>i</sub> ⊠3) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒA<sub>i</sub> æ¥ç®ã®ãã¹ã¿ã¯ãã§ã«æ±ºãŸã£ãŠããïŒB<sub>i</sub> = 1 ã®ãšãã¯ããããœãŒã¹ã§ããïŒB<sub>i</sub> = 2 ã®ãšãã¯ã¯ãªãŒã ãœãŒã¹ã§ããïŒB<sub>i</sub> = 3 ã®ãšãã¯ããžã«ãœãŒã¹ã§ããããšã衚ãïŒA<sub>i</sub> (1 ⊠i ⊠K) ã¯å
šãŠç°ãªãïŒäžããããå
¥åããŒã¿ã«ãããŠïŒæ¡ä»¶ãã¿ããäºå®ã¯ 1 éã以äžããããšãä¿èšŒãããŠããïŒ
</p>
<h2> åºå</h2>
<p>
æ¡ä»¶ãã¿ããäºå®ãäœéããããã 10000 ã§å²ã£ãäœãã 1 è¡ã§åºåããïŒ
</p>
<h2> å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5 3
3 1
1 1
4 2
</pre>
<h3>åºåäŸ 1</h3>
<pre>
6
</pre>
<p>
å
¥åºåäŸ 1 ã«ãããŠïŒããªã㯠5 æ¥éã®äºå®ãèããïŒ1 æ¥ç®ãš 3 æ¥ç®ã¯ããããœãŒã¹ã§ããïŒ4 æ¥ç®ã¯ã¯ãªãŒã ãœãŒã¹ã§ããïŒãŸãïŒ3 æ¥ä»¥äžé£ç¶ããŠåããã¹ã¿ãéžãã§ã¯ãããªãïŒãããã®æ¡ä»¶ãã¿ããäºå®ã¯ 6 éãããïŒ
</p>
<table style="margin-left: 50px; margin-right: 50px;">
<tr>
<th></th>
<th> 1æ¥ç® </th>
<th> 2æ¥ç® </th>
<th> 3æ¥ç® </th>
<th> 4æ¥ç® </th>
<th> 5æ¥ç® </th>
</tr>
<tr>
<th>äºå® 1 </th>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">1</td>
</tr>
<tr>
<th>äºå® 2 </th>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">2</td>
</tr>
<tr>
<th>äºå® 3 </th>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">3</td>
</tr>
<tr>
<th>äºå® 4 </th>
<td align="center">1</td>
<td align="center">3</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">1</td>
</tr>
<tr>
<th>äºå® 5 </th>
<td align="center">1</td>
<td align="center">3</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">2</td>
</tr>
<tr>
<th>äºå® 6 </th>
<td align="center">1</td>
<td align="center">3</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">3</td>
</tr>
</table>
<br>
<p>
ãã®è¡šã§ã¯ïŒ1 ã¯ããããœãŒã¹ãïŒ2 ã¯ã¯ãªãŒã ãœãŒã¹ãïŒ3 ã¯ããžã«ãœãŒã¹ã衚ãïŒ
</p>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
20 5
10 2
4 3
12 1
13 2
9 1
</pre>
<h3>åºåäŸ 2</h3>
<pre>
2640
</pre>
<p>
å
¥åºåäŸ 2 ã«ãããŠïŒæ¡ä»¶ãã¿ããäºå®ã¯å
šéšã§ 4112640 éãããïŒããã 10000 ã§å²ã£ãäœãã§ãã 2640 ãåºåããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00868 |
<H1><font color="#000">Problem E:</font> Spherical Mirrors</H1>
<p>
<i>
A long time ago in a galaxy, far, far away, there were N spheres with various radii.
Spheres were mirrors, that is, they had reflective surfaces . . . .
</i>
</p>
<p>
You are standing at the origin of the galaxy (0, 0, 0), and emit a laser ray to the direction
(<i>u</i>,<i>v</i>, <i>w</i>). The ray travels in a straight line.
</p>
<p>
When the laser ray from <i>I</i> hits the surface of a sphere at <i>Q</i>, let <i>N</i> be a point outside of the
sphere on the line connecting the sphere center and Q. The reflected ray goes to the direction
towards <i>R</i> that satisfies the following conditions: (1) <i>R</i> is on the plane formed by the three
points <i>I</i>, <i>Q</i> and <i>N</i> , (2) ∠ <i>IQN</i> = ∠ <i>NQR</i>, as shown in Figure 1.
</p>
<center>
<table>
<tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_spherical"></td></tr>
<tr><th>Figure 1: Laser ray reflection</th></tr>
</table>
</center>
<p>
After it is reflected several times, finally it goes beyond our observation. Your mission is to write
a program that identifies the last reflection point.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets, each in the following format.
</p>
<pre>
<i>N</i>
<i>u v w</i>
<i>x<sub>1</sub> y<sub>1</sub> z<sub>1</sub> r<sub>1</sub></i>
.
.
.
<i>x<sub>N</sub> y<sub>N</sub> z<sub>N</sub> r<sub>N</sub></i>
</pre>
<p>
The first line of a dataset contains a positive integer <i>N</i> which is the number of spheres. The
next line contains three integers <i>u</i>, <i>v</i> and <i>w</i> separated by single spaces, where (<i>u</i>, <i>v</i>, <i>w</i>) is the
direction of the laser ray initially emitted from the origin.
</p>
<p>
Each of the following <i>N</i> lines contains four integers separated by single spaces. The <i>i</i>-th line
corresponds to the <i>i</i>-th sphere, and the numbers represent the center position (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> ) and the
radius <i>r<sub>i</sub></i> .
</p>
<p>
<i>N</i>, <i>u</i>, <i>v</i>, <i>w</i>, <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> and <i>r<sub>i</sub></i> satisfy the following conditions.
</p>
<p align="center">
1 ≤ <i>N</i> ≤ 100 <br>
â100 ≤ <i>u</i>, <i>v</i>, <i>w</i> ≤ 100<br>
â100 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> ≤ 100<br>
5 ≤ <i>r<sub>i</sub></i> ≤ 30<br>
<i>u</i><sup>2</sup> + <i>v</i><sup>2</sup> + <i>w</i><sup>2</sup> > 0<br>
</p>
<p>
You can assume that the distance between the surfaces of any two spheres is no less than 0.1.
You can also assume that the origin (0, 0, 0) is located outside of any sphere, and is at least 0.1
distant from the surface of any sphere.
</p>
<p>
The ray is known to be reflected by the sphere surfaces at least once, and at most five times.
You can assume that the angle between the ray and the line connecting the sphere center and
the reflection point, which is known as the angle of reflection (i.e. θ in Figure 1), is less than 85
degrees for each point of reflection.
</p>
<p>
The last dataset is followed by a line containing a single zero.
</p>
<H2>Output</H2>
<p>
For each dataset in the input, you should print the x-, y- and z-coordinates of the last reflection
point separated by single spaces in a line. No output line should contain extra characters.
</p>
<p>
No coordinate values in the output should have an error greater than 0.01.
</p>
<H2>Sample Input</H2>
<pre>
3
-20 -20 -24
100 100 100 30
10 8 3 5
-70 -70 -84 5
4
0 47 84
-23 41 42 8
45 -10 14 19
-5 28 47 12
-27 68 34 14
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
79.0940 79.0940 94.9128
-21.8647 54.9770 34.1761
</pre>
|
p02855 | <span class="lang-en">
<p>Score: <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.</p>
<p>The cake has <var>H - 1</var> horizontal notches and <var>W - 1</var> vertical notches, which divide the cake into <var>H \times W</var> equal sections. <var>K</var> of these sections has a strawberry on top of each of them.</p>
<p>The positions of the strawberries are given to you as <var>H \times W</var> characters <var>s_{i, j}</var> <var>(1 \leq i \leq H, 1 \leq j \leq W)</var>. If <var>s_{i, j}</var> is <code>#</code>, the section at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left contains a strawberry; if <var>s_{i, j}</var> is <code>.</code>, the section does not contain one. There are exactly <var>K</var> occurrences of <code>#</code>s.</p>
<p>Takahashi wants to cut this cake into <var>K</var> pieces and serve them to the contestants. Each of these pieces must satisfy the following conditions:</p>
<ul>
<li>Has a rectangular shape.</li>
<li>Contains exactly one strawberry.</li>
</ul>
<p>One possible way to cut the cake is shown below:</p>
<p><img alt=" " src="https://img.atcoder.jp/ddcc2020-qual/47ee461adfe41e931b433ab3e5dae2f3.png"/></p>
<p>Find one way to cut the cake and satisfy the condition. We can show that this is always possible, regardless of the number and positions of the strawberries. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq H \leq 300</var></li>
<li><var>1 \leq W \leq 300</var></li>
<li><var>1 \leq K \leq H \times W</var></li>
<li><var>s_{i, j}</var> is <code>#</code> or <code>.</code>.</li>
<li>There are exactly <var>K</var> occurrences of <code>#</code> in <var>s</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>K</var>
<var>s_{1, 1} s_{1, 2} \cdots s_{1, W}</var>
<var>s_{2, 1} s_{2, 2} \cdots s_{2, W}</var>
<var>:</var>
<var>s_{H, 1} s_{H, 2} \cdots s_{H, W}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Assign the numbers <var>1, 2, 3, \dots, K</var> to the <var>K</var> pieces obtained after the cut, in any order. Then, let <var>a_{i, j}</var> be the number representing the piece containing the section at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left of the cake. Output should be in the following format:</p>
<pre><var>a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}</var>
<var>a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}</var>
<var>:</var>
<var>a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}</var>
</pre>
<p>If multiple solutions exist, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 5
#.#
.#.
#.#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 2 2
1 3 4
5 5 4
</pre>
<p>One way to cut this cake is shown below:</p>
<p><img alt=" " src="https://img.atcoder.jp/ddcc2020-qual/d09e88243931000a04e555892fe7e6c9.png"> </img></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 7 7
#...#.#
..#...#
.#..#..
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 1 2 2 3 4 4
6 6 2 2 3 5 5
6 6 7 7 7 7 7
</pre>
<p>One way to cut this cake is shown below: </p>
<p><img alt=" " src="https://img.atcoder.jp/ddcc2020-qual/18d0f45847f5d107ac0322aecea39835.png"/> </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>13 21 106
.....................
.####.####.####.####.
..#.#..#.#.#....#....
..#.#..#.#.#....#....
..#.#..#.#.#....#....
.####.####.####.####.
.....................
.####.####.####.####.
....#.#..#....#.#..#.
.####.#..#.####.#..#.
.#....#..#.#....#..#.
.####.####.####.####.
.....................
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50
12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50
12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50
12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72
12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83
16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21
16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21
32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85
32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74
14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63
25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52
36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41
36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41
</pre></section>
</div>
</span> |
p03747 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a circle with a circumference of <var>L</var>.
Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point.
On this circumference, there are <var>N</var> ants.
These ants are numbered <var>1</var> through <var>N</var> in order of increasing coordinate, and ant <var>i</var> is at coordinate <var>X_i</var>.</p>
<p>The <var>N</var> ants have just started walking.
For each ant <var>i</var>, you are given the initial direction <var>W_i</var>. Ant <var>i</var> is initially walking clockwise if <var>W_i</var> is <var>1</var>; counterclockwise if <var>W_i</var> is <var>2</var>.
Every ant walks at a constant speed of <var>1</var> per second.
Sometimes, two ants bump into each other.
Each of these two ants will then turn around and start walking in the opposite direction.</p>
<p>For each ant, find its position after <var>T</var> seconds.</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^5</var></li>
<li><var>1 \leq L \leq 10^9</var></li>
<li><var>1 \leq T \leq 10^9</var></li>
<li><var>0 \leq X_1 < X_2 < ... < X_N \leq L - 1</var></li>
<li><var>1 \leq W_i \leq 2</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>L</var> <var>T</var>
<var>X_1</var> <var>W_1</var>
<var>X_2</var> <var>W_2</var>
<var>:</var>
<var>X_N</var> <var>W_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>N</var> lines.
The <var>i</var>-th line should contain the coordinate of ant <var>i</var> after <var>T</var> seconds. Here, each coordinate must be between <var>0</var> and <var>L-1</var>, inclusive.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 8 3
0 1
3 2
6 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
3
0
</pre>
<p><var>1.5</var> seconds after the ants start walking, ant <var>1</var> and <var>2</var> bump into each other at coordinate <var>1.5</var>.
<var>1</var> second after that, ant <var>1</var> and <var>3</var> bump into each other at coordinate <var>0.5</var>.
<var>0.5</var> seconds after that, that is, <var>3</var> seconds after the ants start walking, ants <var>1</var>, <var>2</var> and <var>3</var> are at coordinates <var>1</var>, <var>3</var> and <var>0</var>, respectively.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 20 9
7 2
9 1
12 1
18 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7
18
18
1
</pre></section>
</div>
</span> |
p01280 |
<H1><font color="#000">Problem H:</font> Galaxy Wide Web Service</H1>
<p>
The volume of access to a web service varies from time to time in a day. Also, the hours with the highest
volume of access varies from service to service. For example, a service popular in the United States
may receive more access in the daytime in the United States, while another service popular in Japan may
receive more access in the daytime in Japan. When you develop a web service, you have to design the
system so it can handle all requests made during the busiest hours.
</p>
<p>
You are a lead engineer in charge of a web service in the 30th century. Itâs the era of Galaxy Wide Web
(GWW), thanks to the invention of faster-than-light communication. The service can be accessed from
all over the galaxy. Thus many intelligent creatures, not limited to human beings, can use the service.
Since the volume of access to your service is increasing these days, you have decided to reinforce the
server system. You want to design a new system that handles requests well even during the hours with the
highest volume of access. However, this is not a trivial task. Residents in each planet have their specific
length of <i>a day</i>, say, a cycle of life. The length of <i>a day</i> is not always 24 hours. Therefore, a cycle of the
volume of access are different by planets of users.
</p>
<p>
You have obtained hourly data of the volume of access for all planets where you provide the service.
Assuming the volume of access follows a daily cycle for each planet, you want to know the highest
volume of access in one hour. It should be a quite easy task for you, a famous talented engineer in the
galaxy.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>N</i><br>
<i>d</i><sub>1</sub> <i>t</i><sub>1</sub> <i>q</i><sub>1,0</sub> ... <i>q</i><sub>1,<i>d</i><sub>1</sub>-1</sub><br>
...<br>
<i>d</i><sub><i>N</i></sub> <i>t</i><sub><i>N</i></sub> <i>q</i><sub><i>N</i>,0</sub> ... <i>q</i><sub><i>N</i>,<i>d</i><sub><i>N</i></sub>-1</sub><br>
</p>
<p>
<i>N</i> is the number of planets. <i>d<sub>i</sub></i> (1 ≤ <i>i</i> ≤ <i>N</i>) is the length of a day in the planet <i>i</i>.
<!-- added at 2013/01/13 -->
<i>t<sub>i</sub></i> (0 ≤ <i>t<sub>i</sub></i> ≤ <i>d<sub>i</sub></i> - 1) is the current time of the planet <i>i</i>.
<i>q<sub>i, j</sub></i> is the volume of access on the planet <i>i</i> during from the <i>j</i>-th hour to the (<i>j</i>+1)-th hour.
</p>
<p>
You may assume that <i>N</i> ≤ 100, <i>d<sub>i</sub></i> ≤ 24, <i>q<sub>i, j</sub></i> ≤ 1000000 (1 ≤ <i>i</i> ≤ <i>N</i>, 0 ≤ <i>j</i> ≤ <i>d<sub>i</sub></i> - 1).
</p>
<p>
The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, output the maximum volume of access in one hour in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
4 0 1 2 3 4
2 0 2 1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
</pre>
|
p03317 | <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> |
p02910 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Takahashi will do a tap dance. The dance is described by a string <var>S</var> where each character is <code>L</code>, <code>R</code>, <code>U</code>, or <code>D</code>. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.</p>
<p><var>S</var> is said to be <em>easily playable</em> if and only if it satisfies both of the following conditions:</p>
<ul>
<li>Every character in an odd position (<var>1</var>-st, <var>3</var>-rd, <var>5</var>-th, <var>\ldots</var>) is <code>R</code>, <code>U</code>, or <code>D</code>.</li>
<li>Every character in an even position (<var>2</var>-nd, <var>4</var>-th, <var>6</var>-th, <var>\ldots</var>) is <code>L</code>, <code>U</code>, or <code>D</code>.</li>
</ul>
<p>Your task is to print <code>Yes</code> if <var>S</var> is easily playable, and <code>No</code> otherwise.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>S</var> is a string of length between <var>1</var> and <var>100</var> (inclusive).</li>
<li>Each character of <var>S</var> is <code>L</code>, <code>R</code>, <code>U</code>, or <code>D</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <code>Yes</code> if <var>S</var> is easily playable, and <code>No</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>RUDLUDR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p>Every character in an odd position (<var>1</var>-st, <var>3</var>-rd, <var>5</var>-th, <var>7</var>-th) is <code>R</code>, <code>U</code>, or <code>D</code>.</p>
<p>Every character in an even position (<var>2</var>-nd, <var>4</var>-th, <var>6</var>-th) is <code>L</code>, <code>U</code>, or <code>D</code>.</p>
<p>Thus, <var>S</var> is easily playable.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>DULL
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>The <var>3</var>-rd character is not <code>R</code>, <code>U</code>, nor <code>D</code>, so <var>S</var> is not easily playable.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>UUUUUUUUUUUUUUU
</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>ULURU
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>No
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>RDULULDURURLRDULRLR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>Yes
</pre></section>
</div>
</span> |
p03602 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads.
The following are known about the road network:</p>
<ul>
<li>People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.</li>
<li>Different roads may have had different lengths, but all the lengths were positive integers.</li>
</ul>
<p>Snuke the archeologist found a table with <var>N</var> rows and <var>N</var> columns, <var>A</var>, in the ruin of Takahashi Kingdom.
He thought that it represented the shortest distances between the cities along the roads in the kingdom.</p>
<p>Determine whether there exists a road network such that for each <var>u</var> and <var>v</var>, the integer <var>A_{u, v}</var> at the <var>u</var>-th row and <var>v</var>-th column of <var>A</var> is equal to the length of the shortest path from City <var>u</var> to City <var>v</var>.
If such a network exist, find the shortest possible total length of the roads.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 300</var></li>
<li>If <var>i â j</var>, <var>1 \leq A_{i, j} = A_{j, i} \leq 10^9</var>.</li>
<li><var>A_{i, i} = 0</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var>
<var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var>
<var>...</var>
<var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>If there exists no network that satisfies the condition, print <code>-1</code>.
If it exists, print the shortest possible total length of the roads.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
0 1 3
1 0 2
3 2 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>The network below satisfies the condition:</p>
<ul>
<li>City <var>1</var> and City <var>2</var> is connected by a road of length <var>1</var>.</li>
<li>City <var>2</var> and City <var>3</var> is connected by a road of length <var>2</var>.</li>
<li>City <var>3</var> and City <var>1</var> is not connected by a road.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
0 1 3
1 0 1
3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>As there is a path of length <var>1</var> from City <var>1</var> to City <var>2</var> and City <var>2</var> to City <var>3</var>, there is a path of length <var>2</var> from City <var>1</var> to City <var>3</var>.
However, according to the table, the shortest distance between City <var>1</var> and City <var>3</var> must be <var>3</var>.</p>
<p>Thus, we conclude that there exists no network that satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>82
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3
0 1000000000 1000000000
1000000000 0 1000000000
1000000000 1000000000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3000000000
</pre></section>
</div>
</span> |
p00887 |
<H1><font color="#000">Problem D:</font> Awkward Lights</H1>
<p>
You are working as a night watchman in an office building. Your task is to check whether all the lights in the building are turned off after all the office workers in the building have left the office. If there are lights that are turned on, you must turn off those lights. This task is not as easy as it sounds to be because of the strange behavior of the lighting system of the building as described below. Although an electrical engineer checked the lighting system carefully, he could not determine the cause of this behavior. So you have no option but to continue to rely on this system for the time being.
</p>
<p>
Each floor in the building consists of a grid of square rooms. Every room is equipped with one light and one toggle switch. A toggle switch has two positions but they do not mean fixed ON/OFF. When the position of the toggle switch of a room is changed to the other position, in addition to that room, the ON/OFF states of the lights of the rooms at a certain Manhattan distance from that room are reversed. The Manhattan distance between the room at (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) of a grid of rooms and the room at (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) is given by |<i>x</i><sub>1</sub> - <i>x</i><sub>2</sub>| + |<i>y</i><sub>1</sub> - <i>y</i><sub>2</sub>|. For example, if the position of the toggle switch of the room at (2, 2) of a 4 × 4 grid of rooms is changed and the given Manhattan distance is two, the ON/OFF states of the lights of the rooms at (1, 1), (1, 3), (2, 4), (3, 1), (3, 3), and (4, 2) as well as at (2, 2) are reversed as shown in Figure D.1, where black and white squares represent the ON/OFF states of the lights.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_awkwardLights">
<p>
Figure D.1: An example behavior of the lighting system
</p>
</center>
<p>
Your mission is to write a program that answer whether all the lights on a floor can be turned off.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. Each dataset is formatted as follows.
</p>
<p>
<i>m n d</i><br>
<i>S</i><sub>11</sub> <i>S</i><sub>12</sub> <i>S</i><sub>13</sub> ... <i>S</i><sub>1<i>m</i></sub><br>
<i>S</i><sub>21</sub> <i>S</i><sub>22</sub> <i>S</i><sub>23</sub> ... <i>S</i><sub>2<i>m</i></sub><br>
...<br>
<i>S</i><sub><i>n</i>1</sub> <i>S</i><sub><i>n</i>2</sub> <i>S</i><sub><i>n</i>3</sub> ... <i>S</i><sub><i>nm</i></sub><br>
</p>
<p>
The first line of a dataset contains three integers. <i>m</i> and <i>n</i> (1 ≤ <i>m</i> ≤ 25, 1 ≤ <i>n</i> ≤ 25) are the numbers of columns and rows of the grid, respectively. <i>d</i> (1 ≤ <i>d</i> ≤ <i>m</i> + <i>n</i>) indicates the Manhattan distance. Subsequent n lines of m integers are the initial ON/OFF states. Each <i>S<sub>ij</sub></i> (1 ≤ <i>i</i> ≤ <i>n</i>, 1 ≤ <i>j</i> ≤ <i>m</i>) indicates the initial ON/OFF state of the light of the room at (<i>i</i>, <i>j</i>): '0' for OFF and '1' for ON.
</p>
<p>
The end of the input is indicated by a line containing three zeros.
</p>
<H2>Output</H2>
<p>
For each dataset, output '1' if all the lights can be turned off. If not, output '0'. In either case,
print it in one line for each input dataset.
</p>
<H2>Sample Input</H2>
<pre>
1 1 1
1
2 2 1
1 1
1 1
3 2 1
1 0 1
0 1 0
3 3 1
1 0 1
0 1 0
1 0 1
4 4 2
1 1 0 1
0 0 0 1
1 0 1 1
1 0 0 0
5 5 1
1 1 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
5 5 2
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
11 11 3
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
11 11 3
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
13 13 7
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
1
0
1
0
0
1
1
0
1
</pre>
|
p01795 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem F
ICPC Teams</h2>
<p>
You are a coach of the International Collegiate Programming Contest (ICPC) club in your university. There are 3N students in the ICPC club and you want to make $N$ teams for the next ICPC. All teams in ICPC consist of 3 members. Every student belongs to exactly one team.
</p>
<p>
When you form the teams, you should consider several relationships among the students. Some student has an extremely good relationship with other students. If they belong to a same team, their performance will improve surprisingly. The contrary situation also occurs for a student pair with a bad relationship. In short, students with a good relationship must be in the same team, and students with a bad relationship must be in different teams. Since you are a competent coach, you know all $M$ relationships among the students.
</p>
<p>
Your task is to write a program that calculates the number of possible team assignments. Two assignments are considered different if and only if there exists a pair of students such that in one assignment they are in the same team and in the other they are not.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains two integers $N$ $(1 \leq N \leq 10^6)$ and $M$ $(1 \leq M \leq 18)$. The $i$-th line of the following $M$ lines contains three integers $A_i$, $B_i$ $(1 \leq A_i, B_i \leq 3N, A_i \ne B_i)$, and $C_i$ $(C_i \in \{0, 1\})$. $A_i$ and $B_i$ denote indices of the students and $C_i$ denotes the relation type. If $C_i$ is 0, the $A_i$-th student and the $B_i$-th student have a good relation. If $C_i$ is 1, they have a bad relation. You can assume that $\{A_i, B_i\} \ne \{A_j, B_j\}$ if $i \ne j$ for all $1 \leq i, j \leq M$.
</p>
<h3>Output</h3>
<p>
Display a line containing the number of the possible team assignments modulo $10^9 + 9$.
</p>
<h3>Sample Input 1</h3>
<pre>2 2
1 2 0
3 4 1</pre>
<h3>Output for the Sample Input 1</h3>
<pre>2</pre>
|
p03252 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given strings <var>S</var> and <var>T</var> consisting of lowercase English letters.</p>
<p>You can perform the following operation on <var>S</var> any number of times:</p>
<p>Operation: Choose two distinct lowercase English letters <var>c_1</var> and <var>c_2</var>, then replace every occurrence of <var>c_1</var> with <var>c_2</var>, and every occurrence of <var>c_2</var> with <var>c_1</var>.</p>
<p>Determine if <var>S</var> and <var>T</var> can be made equal by performing the operation zero or more times.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 2 \times 10^5</var></li>
<li><var>|S| = |T|</var></li>
<li><var>S</var> and <var>T</var> consists of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>S</var> and <var>T</var> can be made equal, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>azzel
apple
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><code>azzel</code> can be changed to <code>apple</code>, as follows:</p>
<ul>
<li>Choose <code>e</code> as <var>c_1</var> and <code>l</code> as <var>c_2</var>. <code>azzel</code> becomes <code>azzle</code>.</li>
<li>Choose <code>z</code> as <var>c_1</var> and <code>p</code> as <var>c_2</var>. <code>azzle</code> becomes <code>apple</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>chokudai
redcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p>No sequences of operation can change <code>chokudai</code> to <code>redcoder</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p02013 | <h1>Problem J. Prime Routing</h1>
<!--
Time Limit: 2 sec
Memory Limit: 512 MB
-->
<p>
Fox Jiro is one of the staffs of the ACM-ICPC 2018 Asia Yokohama Regional Contest and is responsible for designing the network for the venue of the contest. His network consists of $N$ computers, which are connected by $M$ cables. The $i$-th cable connects the $a_i$-th computer and the $b_i$-th computer, and it carries data in both directions. Your team will use the $S$-th computer in the contest, and a judge server is the $T$-th computer.
</p>
<p>
He decided to adjust the routing algorithm of the network to maximize the performance of the contestants through the magical power of prime numbers. In this algorithm, a packet (a unit of data carried by the network) is sent from your computer to the judge server passing through the cables a prime number of times if possible. If it is impossible, the contestants cannot benefit by the magical power of prime numbers. To accomplish this target, a packet is allowed to pass through the same cable multiple times.
</p>
<p>
You decided to write a program to calculate the minimum number of times a packet from $S$ to $T$ needed to pass through the cables. If the number of times a packet passes through the cables cannot be a prime number, print $-1$.
</p>
<h2>Input</h2>
<p>
The input consists of a single test case, formatted as follows.
</p>
<pre>
$N$ $M$ $S$ $T$
$a_1$ $b_1$
$\vdots$
$a_M$ $b_M$
</pre>
<p>
The first line consists of four integers $N, M, S,$ and $T$ ($2 \leq N \leq 10^5, 1 \leq M \leq 10^5, 1 \leq S, T \leq N, S \ne T$). The $i$-th line of the following $M$ lines consists of two integers $a_i$ and $b_i$ ($1 \leq a_i < b_i \leq N$), which means the $i$-th cables connects the $a_i$-th computer and the $b_i$-th computer in the network. You can assume that the network satisfies the following conditions.
</p>
<ul>
<li>The network has no multi-edge, i.e.,$(a_i, b_i) \ne (a_j, b_j)$ for all $i,j$ ($1 \leq i < j \leq M$).</li>
<li>The packets from $N$ computers are reachable to $T$ by passing through some number of cables. The number is not necessarily a prime.</li>
</ul>
<h2>Output</h2>
<p>
If there are ways such that the number of times a packet sent from $S$ to $T$ passes through the cables is a prime number, print the minimum prime number of times in one line. Otherwise, print $-1$.
</p>
<h2>Examples</h2>
<h2>Sample Input 1</h2>
<pre>
5 5 1 5
1 2
1 4
2 3
3 4
3 5
</pre>
<h2>Output for Sample Input 1</h2>
<pre>
3
</pre>
<h2>Sample Input 2</h2>
<pre>
5 4 1 5
1 2
2 3
3 4
4 5
</pre>
<h2>Output for Sample Input 2</h2>
<pre>
-1
</pre>
<h2>Sample Input 3</h2>
<pre>
2 1 1 2
1 2
</pre>
<h2>Output for Sample Input 3</h2>
<pre>
3
</pre>
<h2>Sample Input 4</h2>
<pre>
3 3 1 2
1 2
1 3
2 3
</pre>
<h2>Output for Sample Input 4</h2>
<pre>
2
</pre>
|
p00184 |
<H1>é¶Žã¶å</H1>
<p>
äŒæŽ¥è¥æŸåžã®ã·ã³ãã«ã§ããé¶Žã¶åã¯ãè²çæ°é·ãæ¬æ Œçãªå€©å®é£ãç¯åãããé¶Žã¶åããšåä»ããŸããã倩å®é£ããã¯äŒæŽ¥çå°ãäžæã§ããŸãããŸããæŽããæ¥ã«ã¯ãçœèéã§æåãªé£¯çå±±ã®å±±é ããé¶Žã¶åãèŠãããšãã§ããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tsuruga"><br/>
<br/>
</center>
<p>
äŒæŽ¥è¥æŸåžã®ä»åŸã®åºå ±æŽ»åã®åèã«ãããããé¶Žã¶åã«èšªããæ¥å Žè
ã«ã€ããŠã幎代調æ»ãããããšã«ããŸãããæ¥å Žè
ã®å¹Žéœ¢ãå
¥åãšããäžèšã®å¹Žéœ¢åºåå¥ã«äººæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<center>
<table>
<tr><th width="100"> åºå</th><th width="100"> 幎霢</th></tr>
<tr><td>10æ³æªæº</td><td> 0 ~ 9</td></tr>
<tr><td> 10代</td><td> 10 ~ 19</td></tr>
<tr><td> 20代</td><td> 20 ~ 29</td></tr>
<tr><td> 30代</td><td> 30 ~ 39</td></tr>
<tr><td> 40代 </td><td> 40 ~ 49</td></tr>
<tr><td> 50代</td><td> 50 ~ 59</td></tr>
<tr><td>60æ³ä»¥äž</td><td> 60 ~</td></tr>
</table>
</center>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var>
<var>a<sub>2</sub></var>
:
<var>a<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«æ¥å Žè
ã®äººæ° <var>n</var> (1 ≤ <var>n</var> ≤ 1000000)ãç¶ã <var>n</var> è¡ã« <var>i</var> 人ç®ã®æ¥å Žè
ã®å¹Žéœ¢ <var>a<sub>i</sub></var> ( 0 ≤ <var>a<sub>i</sub></var> ≤ 120 ) ãäžããããŸãã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«ä»¥äžã®åœ¢åŒã§äººæ°ãåºåããŸãã<br/>
<br/>
1 è¡ç®: 10 æ³æªæºã®äººæ°<br/>
2 è¡ç®: 10 代ã®äººæ°<br/>
3 è¡ç®: 20 代ã®äººæ°<br/>
4 è¡ç®: 30 代ã®äººæ°<br/>
5 è¡ç®: 40 代ã®äººæ°<br/>
6 è¡ç®: 50 代ã®äººæ°<br/>
7 è¡ç®: 60 æ³ä»¥äžã®äººæ°<br/>
</pre>
<H2>Sample Input</H2>
<pre>
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
1
0
2
1
0
2
0
0
0
0
0
0
4
</pre>
|
p02443 | <h1>Reverse</h1>
<p>
Write a program which reads a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ and reverse specified elements by a list of the following operation:
</p>
<ul>
<li>reverse($b, e$): reverse the order of $a_b, a_{b+1}, ..., a_{e-1}$</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1$
$b_2 \; e_2$
:
$b_{q} \; b_{q}$
</pre>
<p>
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by two integers $b_i \; e_i$ in the following $q$ lines.
</p>
<h2>Output</h2>
<p>
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$-1,000,000,000 \leq a_i \leq 1,000,000,000$</li>
<li>$1 \leq q \leq 1,000$</li>
<li>$0 \leq b < e \leq n$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
8
1 2 3 4 5 6 7 8
2
1 6
3 8
</pre>
<h2>Sample Output 1</h2>
<pre>
1 6 5 8 7 2 3 4
</pre>
|
p02434 | <h1>Vector II</h1>
<p>
For $n$ dynamic arrays $A_i$ ($i = 0, 1, ..., n-1$), perform a sequence of the following operations:
</p>
<ul>
<li>pushBack($t$, $x$): Add element $x$ at the end of $A_t$.</li>
<li>dump($t$): Print all elements in $A_t$.</li>
<li>clear($t$): Clear $A_t$. If $A_t$ is empty, do nothing.</li>
</ul>
<p>
$A_i$ is a 0-origin array and it is empty in the initial state.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$ $q$
$query_1$
$query_2$
:
$query_q$
</pre>
<p>
Each query $query_i$ is given by
</p>
<pre>
0 $t$ $x$
</pre>
<p>or</p>
<pre>
1 $t$
</pre>
<p>or</p>
<pre>
2 $t$
</pre>
<p>
where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent pushBack, dump and clear operations respectively.
</p>
<h2>Output</h2>
<p>
For each dump operation, print elements of $A_t$ a line. Separete adjacency elements by a space character (do not print the space after the last element). Note that, if the array is empty, an empty line should be printed.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$1 \leq q \leq 500,000$</li>
<li>$-1,000,000,000 \leq x \leq 1,000,000,000$</li>
<li>The total number of elements printed by dump operations do not exceed 500,000</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
3 13
0 0 1
0 0 2
0 0 3
0 1 -1
0 2 4
0 2 5
1 0
1 1
1 2
2 1
1 0
1 1
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1 2 3
-1
4 5
1 2 3
4 5
</pre>
|
p00409 | <h1>ã€ã¯ã·ãã®ç¥ã</h1>
ã<p>
å€ä»£åœå®¶ã€ã¯ã·ãã§ã¯ãçœå®³ãèµ·ãããšãã«ãããé®ããããã«ãç¥å®ãç¥ããããããŸãã
</p>
<p>
ç¥å®ã¯å€ææžããæååSãéžã³ã以äžãç¹°ãè¿ãããšã§ååŒãé²ããŠãããŸãã
</p>
<ul>
<li>æåå$S$ã®äžã®å Žæãäžã€éžã³ãããã«æžãããæåãä»ã®æåã«å
¥ãæ¿ããŠã$S$ãæŽæ°ããã</li>
<li>$S$ãã©ã®ãããªæååã®ç¹°ãè¿ãã§è¡šããããèŠã€ããŠãèŠã€ããæååãå±ããããã ãã$S$ãæååã®ç¹°ãè¿ãã§è¡šããªããšãã¯$S$ãå±ããã
</li>
</ul>
<p>
ç¥ãã®å¹åãæå€§ã«ãªãã®ã¯ãæãçãæååã®ç¹°ãè¿ãã§å
ã®æååã衚ããã®ãå±ãããšãã§ããããšãã°ãababababãšããæååã«å¯ŸããŠããã®æååãã®ãã®ãababã§ã¯ãªããabãšå±ãããšãã«ç¥ãã®å¹åãæå€§ã«ãªããŸãã
</p>
<p>
æ°ç±³ç¥å®ã®ããªãã¯ãäžããããæåå$S$ããç¥ãã®å¹åãæå€§ã«ããæååãçŽ æ©ãèŠã€ããæ¹æ³ãäŒåŸããªããã°ãªããŸããã
</p>
</p>
æåå$S$ãšæåã®å
¥ãæ¿ãã®æ
å ±ãããã€ãäžãããããæåãå
¥ãæ¿ãããã³ã«ãåŸãããæååã«ã€ããŠç¥ãã®å¹åãæå€§ã«ããæååã®é·ããæ±ããããã°ã©ã ãäœæããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$N$ $Q$
$S$
$p_1$ $c_1$
$p_2$ $c_2$
:
$p_Q$ $c_Q$
</pre>
<p>
ïŒè¡ç®ã«æååã®é·ã$N$ ($2 \leq N \leq 10^5$)ãšæåãå
¥ãæ¿ããåæ°$Q$ ($1 \leq Q \leq 10^5$)ãäžãããããïŒè¡ç®ã«è±å°æåãããªãé·ã$N$ã®æåå$S$ãäžãããããç¶ã$Q$è¡ã«ã$i$çªç®ã«å
¥ãæ¿ããæåã®äœçœ®$p_i$ ($1 \leq p_i \leq N$)ãšå
¥ãæ¿ããåŸã®æå$c_i$ãäžããããããã ãã$p_i$ã¯æååã®å·Šç«¯ããæ°ããŠäœçªç®ãã§è¡šãããããŸãã$c_i$ã¯è±å°æåã§ããã
</p>
<h2>åºå</h2>
<p>
æåãå
¥ãæ¿ãããã³ã«ãåŸãããæååã«ã€ããŠç¥ãã®å¹åãæå€§ã«ããæååã®é·ããïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
6 5
ababac
6 b
3 c
4 a
5 b
6 c
</pre>
<h3>åºåäŸ</h3>
<pre>
2
6
6
6
3
</pre>
|
p02064 | <h2>E: æççµè·¯ã®åŸ©å
</h2>
<h3>ç©èª</h3>
<p>ç«¶æããã°ã©ããŒã¯æ¥ã
æççµè·¯åé¡ãè§£ããŠãããBFS ãããã«ãã³ãã©ãŒãããã€ã¯ã¹ãã©ãã¯ãŒã·ã£ã«ããã€ããšå€ãã®ã¢ã«ãŽãªãºã ãç¥ãããŠããã</p>
<p>ããªãã¯ãããªäžãã©ãããŠãè§£ããªãæçè·¯åé¡ããã£ããããã¯ã°ã©ããèŠãã«æçè·¯åé¡ãè§£ããšããåé¡ã ïŒãããªãã®éåžžã®äººé¡ã«ã¯è§£ããããããªãã®ã ãã30 åã ã ivvivvi ç¥ã®å€©åãåããããšãã§ããããã«ãªã£ãã</p>
<p>ivvivvi ç¥ã¯ç«¶æããã°ã©ãã³ã°ã«ãæççµè·¯åé¡ã«ã粟éããŠãããã©ããªã°ã©ãã«å¯ŸããŠãä»»æã® 2 ç¹éã®æççµè·¯é·ã宿°æéã§æ±ããèœåãæã£ãŠãããããªã㯠ivvivvi ç¥ã®åãåããŠæççµè·¯åé¡ãè§£ãããšæã£ãããæ®å¿µãªããããªãã®è§£ãã¹ãæççµè·¯åé¡ã§ã¯å
·äœçãªçµè·¯ãåºåããªããã°ãªããªããivvivvi ç¥ãªããæççµè·¯ã®åŸ©å
ã容æã ããivvivvi ç¥ã¯éåžžã«å¿ããã®ã§ãããä»¥äžæãç
©ãããããã«ã¯è¡ããªããããã§ãã§ããã ãå°ãªã質ååæ°ã§èªåã§æççµè·¯ã埩å
ããããšã«ããã</p>
<h3>åé¡</h3>
<p><var>3</var> ã€ã®æŽæ° <var>N</var>ã <var>s</var>ããããŠã<var>t</var> ãäžããããããã®ãšããé ç¹æ° <var>N</var> ã®ã°ã©ãããããé ç¹æ°ä»¥å€ã®èŸºæ°ãé ç¹ã®é£æ¥é¢ä¿ãªã©ã®ã°ã©ãã«é¢ããæ
å ±ã¯äžããããªããã<var>2</var> é ç¹ <var>u</var>ã<var>v</var> ã®è·é¢ã質åããããšãã§ãããããã§ãã°ã©ãã®é ç¹çªå·ã¯ <var>1</var> ä»¥äž <var>N</var> 以äžã§ããã<var>5N</var> å以äžã®è³ªååæ°ã§ <var>s</var> ãã <var>t</var> ãžã®æçè·¯ãçºèŠããæçè·¯ã衚ãé ç¹åã <var>1</var> ã€åºåããã</p>
<p>
<b>ãã®åé¡ã§ã¯ <var>2</var> é ç¹ <var>u</var>ã<var>v</var> éã®è·é¢ããžã£ããžã«è³ªåããªããã°ãªããªãã</b> æšæºåºåã«æ¬¡ã®ããã«åºåããããšã§ã<var>u</var>ã<var>v</var> éã®è·é¢ã質åããããšãã§ããã
</p>
<pre>? <var>u</var> <var>v</var></pre>
<p>
ãã®ããã«æšæºåºåããããšããã®çãã¯æšæºå
¥åã« <var>1</var> è¡ã®æŽæ°ãšããŠäžããããã
ãã®åé¡ã§ã¯ããã°ã©ã ã®è¡ã£ã質åã®åæ°ã <var>5N</var> åãè¶
ãããšèª€çïŒWAïŒãšå€å®ãããããã®åé¡ã§ã¯æåŸã«é ç¹åãã€ãŸãæŽæ°åãåºåãããé ç¹å <var>(x_1, ..., x_k)</var> ãåºåããåºå圢åŒã¯æ¬¡ã®ããã§ããã
</p>
<pre>! <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_k</var></pre>
<p>
ããã§ãåºå㯠<var>x_1 = s</var> ã <var>x_k = t</var> ãæºãããä»»æã®<var>1 \leq i \leq k - 1</var> ã«å¯ŸããŠã<var>x_i</var> ãš <var>x_{i + 1}</var> ãçŽæ¥çµã¶èŸºãååšããã
ããã«ããã®æçµçãªè§£çã¯ãäžåºŠããè¡ãããšãã§ããªãããã®è§£çãæ£ããåºåã ã£ããšããæ£çãšã¿ãªããããã«ãæšæºåºåãšããŠäžèšã® <var>2</var> ã€ã®èšæ³ãšç°ãªãåºåã質ååæ°ã <var>5N</var> åãè¶
ããæã¯ãžã£ããžã¯ <var>-1</var> ãè¿ãããã®æãå³åº§ã«ããã°ã©ã ãçµäºãããªãå Žåããžã£ããžã WA ãæ£ããå€å®ããããšãä¿èšŒããªãã
</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>
<p>Python:</p>
<pre>print(end='', flush=True)</pre>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åãšããŠæŽæ° <var>3</var> ã€ãäžããããã</p>
<pre><var>N</var> <var>s</var> <var>t</var></pre>
<h3>å¶çŽ</h3>
<ul>
<li><var>2 \leq N \leq 300</var></li>
<li><var>1 \leq s, t \leq N</var></li>
<li><var>s \neq t</var></li>
<li>åé¡ã«ãããŠäœ¿çšãããã°ã©ãäžã®ä»»æã® 2 é ç¹ <var>u</var>, <var>v</var> ã«ã€ããŠãæçè·é¢ãæ±ãããã®ã®æå€§å€ã¯ <var>10^9</var> 以äžã§ãã</li>
<li>åé¡ã«ãããŠäœ¿çšãããã°ã©ãã¯é£çµã§ããããšãä¿èšŒããã</li>
</ul>
<h3>å
¥åºåäŸ</h3>
<p>
<table width="600" class="withborder"><tbody>
<tr><th>æšæºå
¥å</th><th>æšæºåºå</th></tr>
<tr><td>4 1 3</td><td> </td></tr>
<tr><td> </td><td>? 4 3</td></tr>
<tr><td>3</td><td> </td></tr>
<tr><td> </td><td>? 1 4</td></tr>
<tr><td>2</td><td> </td></tr>
<tr><td> </td><td>? 2 1</td></tr>
<tr><td>1</td><td> </td></tr>
<tr><td> </td><td>? 3 2</td></tr>
<tr><td>2</td><td> </td></tr>
<tr><td> </td><td>? 1 3</td></tr>
<tr><td>3</td><td> </td></tr>
<tr><td> </td><td>? 4 2</td></tr>
<tr><td>1</td><td> </td></tr>
<tr><td> </td><td>! 1 2 3</td></tr>
</tbody></table>
</p>
<p>ãã®å
¥åºåäŸã§ã¯ä»¥äžã®ã°ã©ãã«å¯Ÿã㊠2 ç¹éã®è·é¢ã質åããŠããã</p>
<!--<object data="images/exam.png" type="image/png" width="400"></object>-->
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_HUPC2019Day1_E_exam" width="400"/>
|
p00059 |
<H1>é·æ¹åœ¢ã®éãªã</H1>
<p>
åºèŸºã <var>x</var> 軞ã«å¯ŸããŠå¹³è¡ãª 2 ã€ã®é·æ¹åœ¢ããããŸããé·æ¹åœ¢ A ã®å·Šäžã®åº§æš (<var>xa1</var>, <var>ya1</var>) ãšå³äžã®åº§æš (<var>xa2</var>, <var>ya2</var>)ãé·æ¹åœ¢ B ã®å·Šäžã®åº§æš (<var>xb1</var>, <var>yb1</var>) ãšå³äžã®åº§æš (<var>xb2</var>, <var>yb2</var>) ãèªã¿èŸŒãã§ãé·æ¹åœ¢ A ãšé·æ¹åœ¢ B ãäžéšã§ãéãªã£ãŠããã° YES ãããŸã£ããéãªã£ãŠããªããã° NO ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããé·æ¹åœ¢ A ãšé·æ¹åœ¢ B ã¯åããã®ã§ã¯ãªããšããŸãããŸããæ¥ããŠãããã®ãéãªã£ãŠãããšã¿ãªããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_intersection">
</center>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã®åœ¢åŒã¯ä»¥äžã®ãšããã§ãã
</p>
<pre>
<var>xa1</var> <var>ya1</var> <var>xa2</var> <var>ya2</var> <var>xb1</var> <var>yb1</var> <var>xb2</var> <var>yb2</var>
</pre>
<p>
å
¥åãããå€ã¯ãããã -2,000 ä»¥äž 2,000 以äžã§ãããåå€ã¯å°æ°ç¹ä»¥äžæå€§ 5 æ¡ãŸã§ã®æ°åãå«ã宿°ã§äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠã<span>YES</span> ãŸã㯠<span>NO</span> ãïŒè¡ã«åºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0
0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0
0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
YES
NO
</pre>
|
p01218 |
<H1><font color="#000">Problem C:</font> Nagashi Soumen</H1>
<p>
Mr. Natsume, the captain of a baseball club, decided to hold a <i>nagashi-soumen</i> party. He first planned
to put a flume at the arena, and let members stand by the side of the flume to eat soumen. But they are
so weird that they adhere to each special position, and refused to move to the side of the flume. They
requested Mr. Natsume to have the flumes go through their special positions. As they never changed their
minds easily, Mr. Natsume tried to rearrange flumes in order to fulfill their requests.
</p>
<p>
As a caretaker of the baseball club, you are to help Mr. Natsume arrange the flumes. Here are the rules
on the arrangement:
</p>
<ul>
<li> each flume can begin and end at arbitrary points. Also it can be curved at any point in any direction,
but cannot have any branches nor merge with another flume;</li>
<li> each flume needs to be placed so that its height strictly decreases as it goes, otherwise soumen does
not flow;</li>
<li> Mr. Natsume cannot make more than <i>K</i> flumes since he has only K machines for water-sliders; and</li>
<li> needless to say, flumes must go through all the special positions so that every member can eat
soumen.</li>
</ul>
<p>
In addition, to save the cost, you want to arrange flumes so that the total length is as small as possible.
What is the minimum total length of all flumes?
</p>
<H2>Input</H2>
<p>
Input consists of multiple data sets. Each data set follows the format below:
</p>
<pre>
<i>N K</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>z</i><sub>1</sub>
...
<i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub> <i>z</i><sub><i>N</i></sub>
</pre>
<p>
<i>N</i> (1 ≤ <i>N</i> ≤ 100) represents the number of attendants, <i>K</i> (1 ≤ <i>K</i> ≤ 4) represents the number of available
flumes, and <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> (-100 ≤ <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> ≤ 100) represent the <i>i</i>-th attendantâs coordinates. All numbers are
integers. The attendantsâ coordinates are all different.
</p>
<p>
A line with two zeros represents the end of input.
</p>
<H2>Output</H2>
<p>
For each data set, output in one line the minimum total length of all flumes in Euclidean distance. No
absolute error in your answer may exceed 10<sup>-9</sup>. Output -1 if it is impossible to arrange flumes.
</p>
<H2>Sample Input</H2>
<pre>
1 1
0 0 0
4 4
0 0 0
1 1 1
2 2 2
3 3 3
3 4
0 0 0
1 1 1
2 2 2
4 1
1 0 1
0 0 0
1 1 0
0 1 -1
5 2
0 0 100
0 0 99
1 0 99
1 0 98
1 0 -100
7 4
71 55 -77
-43 -49 50
73 -22 -89
32 99 -33
64 -22 -25
-76 -1 6
39 4 23
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
0
0
-1
200
197.671366737338417
</pre>
|
p03225 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are some coins in the <var>xy</var>-plane.
The positions of the coins are represented by a grid of characters with <var>H</var> rows and <var>W</var> columns.
If the character at the <var>i</var>-th row and <var>j</var>-th column, <var>s_{ij}</var>, is <code>#</code>, there is one coin at point <var>(i,j)</var>; if that character is <code>.</code>, there is no coin at point <var>(i,j)</var>. There are no other coins in the <var>xy</var>-plane.</p>
<p>There is no coin at point <var>(x,y)</var> where <var>1\leq i\leq H,1\leq j\leq W</var> does not hold.
There is also no coin at point <var>(x,y)</var> where <var>x</var> or <var>y</var> (or both) is not an integer.
Additionally, two or more coins never exist at the same point.</p>
<p>Find the number of triples of different coins that satisfy the following condition:</p>
<ul>
<li>Choosing any two of the three coins would result in the same Manhattan distance between the points where they exist.</li>
</ul>
<p>Here, the Manhattan distance between points <var>(x,y)</var> and <var>(x',y')</var> is <var>|x-x'|+|y-y'|</var>.
Two triples are considered the same if the only difference between them is the order of the coins.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 300</var></li>
<li><var>s_{ij}</var> is <code>#</code> or <code>.</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var>
<var>s_{11}...s_{1W}</var>
<var>:</var>
<var>s_{H1}...s_{HW}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of triples that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 4
#.##
.##.
#...
..##
...#
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><var>((1,1),(1,3),(2,2)),((1,1),(2,2),(3,1))</var> and <var>((1,3),(3,1),(4,4))</var> satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>13 27
......#.........#.......#..
#############...#.....###..
..............#####...##...
...#######......#...#######
...#.....#.....###...#...#.
...#######....#.#.#.#.###.#
..............#.#.#...#.#..
#############.#.#.#...###..
#...........#...#...#######
#..#######..#...#...#.....#
#..#.....#..#...#...#.###.#
#..#######..#...#...#.#.#.#
#..........##...#...#.#####
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>870
</pre></section>
</div>
</span> |
p02967 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a string <var>S</var> consisting of <code>A</code>,<code>B</code>, and <code>C</code>.</p>
<p>Consider the (not necessarily contiguous) subsequences <var>x</var> of <var>S</var> that satisfy all of the following conditions:</p>
<ul>
<li><code>A</code>, <code>B</code>, and <code>C</code> all occur the same number of times in <var>x</var>.</li>
<li>No two adjacent characters in <var>x</var> are the same.</li>
</ul>
<p>Among these subsequences, find one of the longest. Here a subsequence of <var>S</var> is a string obtained by deleting zero or more characters from <var>S</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^6</var></li>
<li><var>S</var> consists of <code>A</code>,<code>B</code>, and <code>C</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print one longest subsequence that satisfies the conditions.
If multiple solutions exist, any of them will be accepted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>ABBCBCAB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>ACBCAB
</pre>
<p>Consider the subsequence <code>ACBCAB</code> of <var>S</var>. It satisfies the conditions and is one of the longest with these properties, along with <code>ABCBCA</code>.
On the other hand, the subsequences <code>ABCBCAB</code> and <code>ABBCCA</code> do not satisfy the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>ABABABABACACACAC
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>BABCAC
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>ABCABACBCBABABACBCBCBCBCBCAB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>ACABACABABACBCBCBCBCA
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>AAA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>
</pre>
<p>It is possible that only the empty string satisfies the condition.</p></section>
</div>
</span> |
p01648 |
<h2>Problem Statement</h2>
<p>
You are given a connected undirected graph which has even numbers of nodes.
A connected graph is a graph in which all nodes are connected directly or indirectly by edges.
</p>
<p>
Your task is to find a spanning tree whose median value of edges' costs is minimum.
A spanning tree of a graph means that a tree which contains all nodes of the graph.
</p>
<h2>Input</h2>
<p>
The input consists of multiple datasets.
</p>
<p>
The format of each dataset is as follows.
</p>
<pre>
<var>n</var> <var>m</var>
<var>s_1</var> <var>t_1</var> <var>c_1</var>
...
<var>s_m</var> <var>t_m</var> <var>c_m</var>
</pre>
<p>
The first line contains an even number <var>n</var> (<var>2 \leq n \leq 1,000</var>) and an integer <var>m</var> <var>(n-1 \leq m \leq 10,000)</var>.
<var>n</var> is the nubmer of nodes and <var>m</var> is the number of edges in the graph.
</p>
<p>
Then <var>m</var> lines follow, each of which contains <var>s_i</var> (<var>1 \leq s_i \leq n</var>), <var>t_i</var> (<var>1 \leq s_i \leq n, t_i \neq s_i</var>) and <var>c_i</var> (<var>1 \leq c_i \leq 1,000</var>).
This means there is an edge between the nodes <var>s_i</var> and <var>t_i</var> and its cost is <var>c_i</var>.
There is no more than one edge which connects <var>s_i</var> and <var>t_i</var>.
</p>
<p>
The input terminates when <var>n=0</var> and <var>m=0</var>.
Your program must not output anything for this case.
</p>
<h2>Output</h2>
<p>
Print the median value in a line for each dataset.
</p>
<h2>Sample Input</h2>
<pre>
2 1
1 2 5
4 6
1 2 1
1 3 2
1 4 3
2 3 4
2 4 5
3 4 6
8 17
1 4 767
3 1 609
8 3 426
6 5 972
8 1 607
6 4 51
5 1 683
3 6 451
3 4 630
8 7 912
3 7 43
4 7 421
3 5 582
8 4 538
5 7 832
1 6 345
8 2 608
0 0
</pre>
<h2>Output for the Sample Input</h2>
<pre>
5
2
421
</pre>
|
p03675 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>n</var>, <var>a_1, ..., a_n</var>.
Let us consider performing the following <var>n</var> operations on an empty sequence <var>b</var>.</p>
<p>The <var>i</var>-th operation is as follows:</p>
<ol>
<li>Append <var>a_i</var> to the end of <var>b</var>.</li>
<li>Reverse the order of the elements in <var>b</var>.</li>
</ol>
<p>Find the sequence <var>b</var> obtained after these <var>n</var> operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq n \leq 2\times 10^5</var></li>
<li><var>0 \leq a_i \leq 10^9</var></li>
<li><var>n</var> and <var>a_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>n</var> integers in a line with spaces in between.
The <var>i</var>-th integer should be <var>b_i</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4 2 1 3
</pre>
<ul>
<li>After step 1 of the first operation, <var>b</var> becomes: <var>1</var>.</li>
<li>After step 2 of the first operation, <var>b</var> becomes: <var>1</var>.</li>
<li>After step 1 of the second operation, <var>b</var> becomes: <var>1, 2</var>.</li>
<li>After step 2 of the second operation, <var>b</var> becomes: <var>2, 1</var>.</li>
<li>After step 1 of the third operation, <var>b</var> becomes: <var>2, 1, 3</var>.</li>
<li>After step 2 of the third operation, <var>b</var> becomes: <var>3, 1, 2</var>.</li>
<li>After step 1 of the fourth operation, <var>b</var> becomes: <var>3, 1, 2, 4</var>.</li>
<li>After step 2 of the fourth operation, <var>b</var> becomes: <var>4, 2, 1, 3</var>.</li>
</ul>
<p>Thus, the answer is <code>4 2 1 3</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3 1 2
</pre>
<p>As shown above in Sample Output 1, <var>b</var> becomes <var>3, 1, 2</var> after step 2 of the third operation. Thus, the answer is <code>3 1 2</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1000000000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>6
0 6 7 6 7 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0 6 6 0 7 7
</pre></section>
</div>
</span> |
p02988 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a permutation <var>p</var> = {<var>p_1,\ p_2,\ ...,\ p_n</var>} of {<var>1,\ 2,\ ...,\ n</var>}.</p>
<p>Print the number of elements <var>p_i</var> (<var>1 < i < n</var>) that satisfy the following condition:</p>
<ul>
<li><var>p_i</var> is the second smallest number among the three numbers <var>p_{i - 1}</var>, <var>p_i</var>, and <var>p_{i + 1}</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>3 \leq n \leq 20</var></li>
<li><var>p</var> is a permutation of {<var>1,\ 2,\ ...,\ n</var>}.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>n</var>
<var>p_1</var> <var>p_2</var> <var>...</var> <var>p_n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of elements <var>p_i</var> (<var>1 < i < n</var>) that satisfy the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
1 3 5 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p><var>p_2 = 3</var> is the second smallest number among <var>p_1 = 1</var>, <var>p_2 = 3</var>, and <var>p_3 = 5</var>. Also, <var>p_4 = 4</var> is the second smallest number among <var>p_3 = 5</var>, <var>p_4 = 4</var>, and <var>p_5 = 2</var>. These two elements satisfy the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
9 6 3 2 5 8 7 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre></section>
</div>
</span> |
p03360 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>There are three positive integers <var>A</var>, <var>B</var> and <var>C</var> written on a blackboard. E869120 performs the following operation <var>K</var> times:</p>
<ul>
<li>Choose one integer written on the blackboard and let the chosen integer be <var>n</var>. Replace the chosen integer with <var>2n</var>.</li>
</ul>
<p>What is the largest possible sum of the integers written on the blackboard after <var>K</var> operations?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>A, B</var> and <var>C</var> are integers between <var>1</var> and <var>50</var> (inclusive).</li>
<li><var>K</var> is an integer between <var>1</var> and <var>10</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the largest possible sum of the integers written on the blackboard after <var>K</var> operations by E869220.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 3 11
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>30
</pre>
<p>In this sample, <var>5, 3, 11</var> are initially written on the blackboard, and E869120 can perform the operation once.<br/>
There are three choices: </p>
<ol>
<li>Double <var>5</var>: The integers written on the board after the operation are <var>10, 3, 11</var>.</li>
<li>Double <var>3</var>: The integers written on the board after the operation are <var>5, 6, 11</var>.</li>
<li>Double <var>11</var>: The integers written on the board after the operation are <var>5, 3, 22</var>.</li>
</ol>
<p>If he chooses 3., the sum of the integers written on the board afterwards is <var>5 + 3 + 22 = 30</var>, which is the largest among 1. through 3. </p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 4
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>22
</pre>
<p>E869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows: </p>
<ul>
<li>First, double <var>4</var>. The integers written on the board are now <var>3, 3, 8</var>. </li>
<li>Next, double <var>8</var>. The integers written on the board are now <var>3, 3, 16</var>. </li>
</ul>
<p>Then, the sum of the integers eventually written on the blackboard is <var>3 + 3 + 16 = 22</var>.</p></section>
</div>
</span> |
p02822 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a tree <var>T</var> with <var>N</var> vertices. The <var>i</var>-th edge connects Vertex <var>A_i</var> and <var>B_i</var> (<var>1 \leq A_i,B_i \leq N</var>).</p>
<p>Now, each vertex is painted black with probability <var>1/2</var> and white with probability <var>1/2</var>, which is chosen independently from other vertices. Then, let <var>S</var> be the smallest subtree (connected subgraph) of <var>T</var> containing all the vertices painted black. (If no vertex is painted black, <var>S</var> is the empty graph.)</p>
<p>Let the <em>holeyness</em> of <var>S</var> be the number of white vertices contained in <var>S</var>. Find the expected holeyness of <var>S</var>.</p>
<p>Since the answer is a rational number, we ask you to print it <var>\bmod 10^9+7</var>, as described in Notes.</p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><p>When you print a rational number, first write it as a fraction <var>\frac{y}{x}</var>, where <var>x, y</var> are integers, and <var>x</var> is not divisible by <var>10^9 + 7</var>
(under the constraints of the problem, such representation is always possible).</p>
<p>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>2 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq A_i,B_i \leq N</var></li>
<li>The given graph is a tree.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>B_1</var>
<var>:</var>
<var>A_{N-1}</var> <var>B_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the expected holeyness of <var>S</var>, <var>\bmod 10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>125000001
</pre>
<p>If the vertices <var>1, 2, 3</var> are painted black, white, black, respectively, the holeyness of <var>S</var> is <var>1</var>.</p>
<p>Otherwise, the holeyness is <var>0</var>, so the expected holeyness is <var>1/8</var>.</p>
<p>Since <var>8 \times 125000001 \equiv 1 \pmod{10^9+7}</var>, we should print <var>125000001</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2
2 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>375000003
</pre>
<p>The expected holeyness is <var>3/8</var>.</p>
<p>Since <var>8 \times 375000003 \equiv 3 \pmod{10^9+7}</var>, we should print <var>375000003</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 2
1 3
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>250000002
</pre>
<p>The expected holeyness is <var>1/4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>7
4 7
3 1
2 6
5 2
7 1
2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>570312505
</pre></section>
</div>
</span> |
p03730 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We ask you to select some number of positive integers, and calculate the sum of them.</p>
<p>It is allowed to select as many integers as you like, and as large integers as you wish.
You have to follow these, however: each selected integer needs to be a multiple of <var>A</var>, and you need to select at least one integer.</p>
<p>Your objective is to make the sum congruent to <var>C</var> modulo <var>B</var>.
Determine whether this is possible.</p>
<p>If the objective is achievable, print <code>YES</code>. Otherwise, print <code>NO</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †A †100</var></li>
<li><var>1 †B †100</var></li>
<li><var>0 †C < B</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <code>YES</code> or <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>For example, if you select <var>7</var> and <var>14</var>, the sum <var>21</var> is congruent to <var>1</var> modulo <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>The sum of even numbers, no matter how many, is never odd.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 100 97
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre>
<p>You can select <var>97</var>, since you may select multiples of <var>1</var>, that is, all integers.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>40 98 58
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>YES
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>77 42 36
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>NO
</pre></section>
</div>
</span> |
p02571 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are two strings <var>S</var> and <var>T</var>.</p>
<p>Let us change some of the characters in <var>S</var> so that <var>T</var> will be a substring of <var>S</var>.</p>
<p>At least how many characters do we need to change?</p>
<p>Here, a substring is a consecutive subsequence. For example, <code>xxx</code> is a substring of <code>yxxxy</code>, but not a substring of <code>xxyxx</code>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>The lengths of <var>S</var> and <var>T</var> are each at least <var>1</var> and at most <var>1000</var>.</li>
<li>The length of <var>T</var> is at most that of <var>S</var>.</li>
<li><var>S</var> and <var>T</var> consist of lowercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of characters in <var>S</var> that need to be changed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>cabacc
abc
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>For example, changing the fourth character <code>a</code> in <var>S</var> to <code>c</code> will match the second through fourth characters in <var>S</var> to <var>T</var>.</p>
<p>Since <var>S</var> itself does not have <var>T</var> as its substring, this number of changes - one - is the minimum needed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>codeforces
atcoder
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre></section>
</div>
</span> |
p02121 |
<h1>Problem K: Chinol Choco</h1>
<h2>Problem</h2>
<p>
ãã§ã³ã¬ãŒãäŒç€Ÿããã«ãã§ã³ã¯æ°ããåºã<var>n</var>åºå»ºãŠãããšã«ããã<br>
ããããã®åºã¯ååºé·ã«å»ºãŠããå Žæã®åè£ã2ã€çšæããŠããããã©ã¡ããã®å Žæã«å»ºãŠãã
</p>
<p>
ããã«ãã§ã³ã§ã¯<var>m</var>çš®é¡ã®ãã§ã³ã¬ãŒãã販売ããŠãããããããå¥ã®å·¥å Žã§è£œé ããŠããã<br>
ãã¹ãŠã®åºã§å
šçš®é¡ã®ãã§ã³ã¬ãŒãã販売ããã<br>
ããã«ãã§ã³ã§ã¯ãã§ã³ã¬ãŒããæ¬éããããã®ãã©ãã¯ã1å°ããææããŠãããã1å°ã®ãã©ãã¯ã§ã¯1åºåã®ãã§ã³ã¬ãŒãããéã¹ãªãã<br>
ãã®ããããã©ãã¯ã¯åºããå¥ã®åºãžç§»åããéã«ãã¹ãŠã®å·¥å Žãåãå¿
èŠãããã
</p>
<p>
ããåºããå¥ã®åºãžç§»åããæã®æçç§»åè·é¢ã®æå€§ãæå°ã«ãªãããã«åºãé
眮ããæã®ãæå€§ã®ç§»åè·é¢ãæ±ããã
</p>
<p>
åãå Žæã«è€æ°ã®åºãå·¥å Žãååšããããšãã§ããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>n</var> <var>m</var>
<var>a</var><sub>0</sub> <var>b</var><sub>0</sub> <var>c</var><sub>0</sub> <var>d</var><sub>0</sub>
...
<var>a</var><sub><var>n</var>−1</sub> <var>b</var><sub><var>n</var>−1</sub> <var>c</var><sub><var>n</var>−1</sub> <var>d</var><sub><var>n</var>−1</sub>
<var>x</var><sub>0</sub> <var>y</var><sub>0</sub>
...
<var>x</var><sub><var>m</var>−1</sub> <var>y</var><sub><var>m</var>−1</sub>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«ããã«ãã§ã³ã®åºã®æ°<var>n</var>ããã§ã³ã¬ãŒãã補é ããŠããå·¥å Žã®æ°<var>m</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ãã<var>n</var>è¡ã«ããããã®åºã建ãŠãå Žæã®åè£ã®åº§æš(<var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>),(<var>c<sub>i</sub></var>,<var>d<sub>i</sub></var>)ã空çœåºåãã§äžããããã<br>
2+<var>n</var>è¡ç®ãã<var>m</var>è¡ã«å·¥å Žã®åº§æš(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>)ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li>2 ≤ <var>n</var> ≤ 200</li>
<li>1 ≤ <var>m</var> ≤ 15</li>
<li>0 ≤ <var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>,<var>c<sub>i</sub></var>,<var>d<sub>i</sub></var>,<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var> ≤ 1000</li>
</ul>
<h2>Output</h2>
<p>
æçç§»åè·é¢ã®æå€§ãæå°ã«ãªãããã«åºãé
眮ããæã®ãæå€§ã®ç§»åè·é¢ãåºåããã<br>
誀差ã10<sup>−6</sup>ãè¶
ããŠã¯ãªããªãã
</p>
<h2>Sample Input 1</h2>
<pre>
2 1
0 0 5 5
3 3 6 6
2 2
</pre>
<h2>Sample Output 1</h2>
<pre>
4.2426406871
</pre>
<h2>Sample Input 2</h2>
<pre>
2 2
0 0 6 0
7 0 3 0
4 0
5 0
</pre>
<h2>Sample Output 2</h2>
<pre>
3.0000000000
</pre> |
p03419 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive <var>N</var> rows and <var>M</var> columns, and a card is placed in each square in this region.
The front and back sides of these cards can be distinguished, and initially every card faces up.</p>
<p>We will perform the following operation once for each square contains a card:</p>
<ul>
<li>For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.</li>
</ul>
<p>It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed.
Find the number of cards that face down after all the operations.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 10^9</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of cards that face down after all the operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
</pre>
<p>We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>5
</pre>
<p>After all the operations, all cards except at both ends face down.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>314 1592
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>496080
</pre></section>
</div>
</span> |
p01424 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Palindrome Generator</H1>
<p>
A palidrome craftsperson starts to work in the early morning,
with the clear air allowing him to polish up his palindromes.
</p>
<p>
On this morning, he is making his pieces to submit to the International Contest for Palindrome Craftspeople.
</p>
<p>
By the way, in order to make palindromes, he uses a special dictionary which contains a set of words and a set of ordered pairs of the words.
Any words and any ordered pairs of consecutive words in his palindromes must appear in the dictionary.
</p>
<p>
We already have his dictionary, so let's estimate how long a palindrome he can make.
</p>
<H2>Input</H2>
<p>
The first line in the data set consists of two integers <var>N</var> (<var>1 \leq N \leq 100</var>) and <var>M</var> (<var>0 \leq M \leq 1\,000</var>).
<var>N</var> describes the number of words in the dictionary and <var>M</var> describes the number of ordered pairs of words.
</p>
<p>
The following <var>N</var> lines describe the words he can use.
The <var>i</var>-th line (<var>1</var>-based) contains the word <var>i</var>, which consists of only lower-case letters and whose length is between <var>1</var> and <var>10</var>, inclusive.
</p>
<p>
The following <var>M</var> lines describe the ordered pairs of consecutive words he can use.
The <var>j</var>-th line (<var>1</var>-based) contains two integers <var>X_j</var> and <var>Y_j</var> (<var>1 \leq X_j, Y_j \leq N</var>).
<var>X_j</var> describes the (<var>1</var>-based) index of the former word in the palindrome and <var>Y_j</var> describes that of the latter word.
</p>
<H2>Output</H2>
<p>
Print the maximal length of the possible palindrome in a line.
If he can make no palidromes, print "0".
If he can make arbitrary long palindromes, print "-1".
</p>
<H2>Sample Input 1</H2>
<pre>
2 2
ab
ba
1 1
1 2
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>
4
</pre>
<H2>Sample Input 2</H2>
<pre>
2 2
ab
ba
1 1
2 2
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>
0
</pre>
<H2>Sample Input 3</H2>
<pre>
2 2
ab
a
1 1
1 2
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>
-1
</pre>
|
p03049 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has <var>N</var> strings. The <var>i</var>-th string is <var>s_i</var>.</p>
<p>Let us concatenate these strings into one string after arranging them in some order.
Find the maximum possible number of occurrences of <code>AB</code> in the resulting string.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{4}</var></li>
<li><var>2 \leq |s_i| \leq 10</var></li>
<li><var>s_i</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>N</var>
<var>s_1</var>
<var>\vdots</var>
<var>s_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
ABCA
XBAZ
BAD
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, if we concatenate <code>ABCA</code>, <code>BAD</code> and <code>XBAZ</code> in this order, the resulting string <code>ABCABADXBAZ</code> has two occurrences of <code>AB</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
BEWPVCRWH
ZZNQYIJX
BAVREA
PA
HJMYITEOX
BCJHMRMNK
BP
QVFABZ
PRGKSPUNA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
RABYBBE
JOZ
BMHQUVA
BPA
ISU
MCMABAOBHZ
SZMEHMA
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre></section>
</div>
</span> |
p01074 |
<h1>Problem C: Unhappy Class</h1>
<h2>Problem</h2>
<p>
å±±ä¹åŸ¡è¹åŠåã®1幎Gçµã¯ãäžå¹žãèè² ã£ã女åçåŸãã¡ãéãŸãã¯ã©ã¹ã§ããã 圌女ãã¡ã¯ã幞çŠã«ãªãããšãç®æšã«ãæ¥ã
æ§ã
ãªè©Šç·Žã«ç«ã¡åããã
</p>
<p>
圌女ãã¡ã®ã¯ã©ã¹ã§ã¯ã幞çŠã«ãªãããã®è©Šç·Žã®äžç°ãšããŠã幞çŠå®æç§ç®ãåè¬ããããšãã§ããã<br>
ææããéæã®ãããã1éãã<var>N</var>éãŸã§ã«ææ¥ç§ç®ã®æ ãããã<var>M</var>åã®åè¬å¯èœãªç§ç®ãããã
</p>
<p>
ç§ç®<var>i</var>ã¯ãææ¥<var>d<sub>i</sub></var>(<var>d<sub>i</sub></var> = 0, 1, 2, 3, 4ããããããææãç«æãæ°Žæãæšæãéæã«å¯Ÿå¿ãã)ã®<var>a<sub>i</sub></var>éç®ããå§ãŸããé£ç¶ãã<var>k<sub>i</sub></var>ã³ãã§è¡ããããããåè¬ãããšãã«åŸããã幞çŠåºŠã¯<var>t<sub>i</sub></var>ã§ããã
</p>
<p>
åçåŸã¯ãæå€§<var>L</var>åã®ç§ç®ãäºãã«éãªããªãããã«èªç±ã«éžã¶ããšãã§ãããã©ã®ããã«ç§ç®ãéžã¹ã°ãæãé«ã幞çŠåºŠãåŸãããã ããããäžããããç§ç®ã®æ
å ±ãããåŸããã幞çŠåºŠã®æå€§å€ãæ±ããŠã»ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>N</var> <var>M</var> <var>L</var>
<var>d<sub>1</sub></var> <var>a<sub>1</sub></var> <var>k<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>d<sub>2</sub></var> <var>a<sub>2</sub></var> <var>k<sub>2</sub></var> <var>t<sub>2</sub></var>
...
<var>d<sub>M</sub></var> <var>a<sub>M</sub></var> <var>k<sub>M</sub></var> <var>t<sub>M</sub></var>
</pre>
<p>
1è¡ç®ã«3ã€ã®æŽæ°<var>N</var>, <var>M</var>, <var>L</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ãã<var>M</var>+1è¡ç®ã«4ã€ã®æŽæ°<var>d<sub>i</sub></var>, <var>a<sub>i</sub></var>, <var>k<sub>i</sub></var>, <var>t<sub>i</sub></var>ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>2 ≤ <var>N</var> ≤ 8</li>
<li>0 ≤ <var>M</var> ≤ 300</li>
<li>0 ≤ <var>L</var> ≤ min(<var>N</var>×5, <var>M</var>)</li>
<li>0 ≤ <var>d<sub>i</sub></var> ≤ 4</li>
<li>1 ≤ <var>a<sub>i</sub></var> ≤ <var>N</var></li>
<li>1 ≤ <var>k<sub>i</sub></var></li>
<li><var>a<sub>i</sub></var> + <var>k<sub>i</sub></var> - 1 ≤ <var>N</var></li>
<li>1 ≤ <var>t<sub>i</sub></var> ≤ 100</li>
</ul>
<h2>Output</h2>
<p>
幞çŠåºŠã®åã®æå€§å€ã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 7 3
0 1 1 1
0 1 1 2
1 1 3 4
1 1 1 1
1 2 1 2
2 1 1 3
2 2 2 1
</pre>
<h2>Sample Output 1</h2>
<pre>
9
</pre>
<h2>Sample Input 2</h2>
<pre>
5 10 5
0 1 1 2
0 2 1 2
0 1 2 3
1 2 1 2
1 4 2 3
2 1 1 1
2 1 1 2
3 3 2 3
4 1 1 2
4 2 1 2
</pre>
<h2>Sample Output 2</h2>
<pre>
13
</pre> |
p00235 |
<H1>ãµãŒãžã§ã³ãã»ã©ã€ã¢ã³</H1>
<p>
ãã©ã€ã¢ã³è»æ¹ãæãããšããæä»€ã®ããšãã¢ã€ã
è»ã®æåºéšéã¯ãã€ããªãŒã®æ°Žäžéœåžã§æµè»ãšæ¿ããæŠéãç¹°ãåºããŠããŸããã圌ãã¯ç¡äºã«è»æ¹ãšåæµããŸããããæµã®æŠè»ãå€ããæåºããªãåŒã¹ãã«ããŸãããããã§ã圌ãã¯æµã®æŠè»ãæ··ä¹±ããããããéœåžã«ããæ©ãå
šãŠçç ŽãããšããäœæŠãå®è¡ããããšã«ããŸããã
</p>
<p>
äœæŠã¯ããã«åžä»€éšã«äŒããããæåºããªã®æºåãé²ããããŸãããæåºããªãé£ã°ãããã«ã¯ããã€æ©ãå
šãŠçç Žãããããäºæž¬ããªããã°ãªããŸãããè»ã®ããã°ã©ãã§ããããªãã®ä»»åã¯ãæåºéšéãå
šãŠã®æ©ã®çç Žã«å¿
èŠãªæéãèšç®ããããšã§ãã
</p>
<p>
æ°Žäžéœåžã¯ <var>N</var> åã®å³¶ã§æ§æãããŠãããå³¶ãšå³¶ãšã®éã«ã¯æ©ãããã£ãŠããŸãããã¹ãŠã®å³¶ã¯ããªãŒç¶ã«ç¹ãã£ãŠããŸã(äžå³åç
§) ãããå³¶ããããå³¶ãžã®çµè·¯ã¯ãäžéãã ãååšããŸããåæ©ãæž¡ãã«ã¯ãæ©ããšã«æ±ºããããæéãããããã©ã¡ãã®æ¹åã«ããã®æéã§æ©ãæž¡ãããšãå¯èœã§ãã
</p>
<p>
æåºéšéã¯ããŒããªã©æ°Žäžãç§»åããææ®µãæã£ãŠããªãã®ã§å³¶ãšå³¶ã®éãç§»åããã«ã¯æ©ãéãä»ãããŸãããæåºéšéã¯ããã®æããå³¶ã«é£æ¥ããŠããæ©ã®ãã¡ãå¿
èŠãªãã®ãäžç¬ã§çç Žããããšãã§ããŸããæåºéšéãå
šãŠã®æ©ãçç Žããã®ã«å¿
èŠãªæå°ã®æéã¯ãããã§ããããããã ããå³¶ã®äžã§ã®ç§»åæéã¯èããŸããã
</p>
<p>
å³¶ã®æ°ãããããã®æ©æ
å ±ãå
¥åãšããæ©ãå
šãŠçç Žããã®ã«å¿
èŠãªæå°ã®æéãåºåããããã°ã©ã ãäœæããŠãã ãããå³¶ã¯ãããã 1 ãã <var>N</var> ã®çªå·ã§è¡šãããŸããæ©ã¯ <var>N</var>-1 æ¬ãããŸããæ©æ
å ±ã¯ããã®æ©ã飿¥ããŠããäºã€ã®å³¶ã®çªå·(<var>a</var>, <var>b</var>)ãšããã®æ©ãæž¡ãã®ã«å¿
èŠãªæé <var>t</var> ã§æ§æãããŸããæåºéšéã¯å³¶çªå· 1 ã®å³¶ããã¹ã¿ãŒããããã®ãšããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_sergeant">
</center>
<br>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžãããããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>t<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>t<sub>2</sub></var>
:
<var>a<sub>N-1</sub></var> <var>b<sub>N-1</sub></var> <var>t<sub>N-1</sub></var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã1 è¡ç®ã«å³¶ã®æ° <var>N</var> (2 ≤ <var>N</var> ≤ 20) ãäžããããã
</p>
<p>
ç¶ã <var>N</var>-1 è¡ã« <var>i</var> çªç®ã®æ©ã®æ
å ±ãäžããããã <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>t<sub>i</sub></var> (1 ≤ <var>t<sub>i</sub></var> ≤ 500) ã¯ã<var>i</var> çªç®ã®æ©ãéã£ãŠå³¶ <var>a<sub>i</sub></var> ãšå³¶ <var>b<sub>i</sub></var> ã®éãæé <var>t<sub>i</sub></var> ã§ç§»åã§ããããšã衚ãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããªãã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ãæ©ãå
šãŠçç Žããã®ã«å¿
èŠãªæå°ã®æéã1è¡ã«åºåããã
</p>
<H2>Sample Input</H2>
<pre>
7
1 2 5
2 3 2
3 4 3
2 5 3
5 6 3
5 7 8
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
12
</pre>
|
p02208 | <h2>ã«ããµã³ã (Cutlet Sandwich)</h2>
<p>ããäžçã«ã¯ã $X$ çš®é¡ã®ããµã³ããã $Y$ çš®é¡ã®ãã«ããã $Z$ çš®é¡ã®ãã«ã¬ãŒããšããé£ã¹ç©ããããŸãã</p>
<p>ãã®äžçã«ã¯ $N$ çš®é¡ã®ãã«ããµã³ãããšããé£ã¹ç©ãããã $i$ çš®é¡ç®ã®ã«ããµã³ã㯠$A_i$ çš®é¡ç®ã®ãµã³ããš $B_i$ çš®é¡ç®ã®ã«ããåæã§ãã</p>
<p>ãŸãã $M$ çš®é¡ã®ãã«ãã«ã¬ãŒããšããé£ã¹ç©ãããã $i$ çš®é¡ç®ã®ã«ãã«ã¬ãŒã¯ $C_i$ çš®é¡ç®ã®ã«ããš $D_i$ çš®é¡ç®ã®ã«ã¬ãŒãåæã§ãã</p>
<p>Segtree åã¯ãããã«ããµã³ããŸãã¯ã«ãã«ã¬ãŒãæã£ãŠãããšããåæã®ãã¡å°ãªããšã $1$ ã€ãå
±éããŠãããããªã«ããµã³ããŸãã¯ã«ãã«ã¬ãŒãšäº€æããããšãã§ããŸãã</p>
<p>äŸãã°ã$a$ çš®é¡ç®ã®ãµã³ããš $b$ çš®é¡ç®ã®ã«ããåæã§ããã«ããµã³ããæã£ãŠãããšãã $a$ çš®é¡ç®ã®ãµã³ããŸã㯠$b$ çš®é¡ç®ã®ã«ããåæã«æã€ä»»æã®ã«ããµã³ãããŸãã¯ã $b$ çš®é¡ç®ã®ã«ããåæã«å«ãä»»æã®ã«ãã«ã¬ãŒãšäº€æã§ããŸãã
</p>
<p>ä»ã Segtree å㯠$S$ çš®é¡ç®ã®ã«ããµã³ããæã£ãŠããŸãããé£ã¹ããã®ã¯ $T$ çš®é¡ç®ã®ã«ãã«ã¬ãŒã§ãã</p>
<p>$T$ çš®é¡ç®ã®ã«ãã«ã¬ãŒãæã«å
¥ããããšãã§ãããå€å®ããŠãã ãããããå¯èœãªãã°ãæå°äœåã®äº€æã§ç®çã®ã«ãã«ã¬ãŒãæã«ããããããæ±ããŠãã ããã</p>
<h3>å
¥å</h3>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>
$X$ $Y$ $Z$ $N$ $M$ $S$ $T$
$A_1$ $B_1$
$A_2$ $B_2$
$\ldots$
$A_N$ $B_N$
$C_1$ $D_1$
$C_2$ $D_2$
$\ldots$
$C_M$ $D_M$
</pre>
<h3>åºå</h3>
<p> $T$ çš®é¡ç®ã®ã«ãã«ã¬ãŒãæã«å
¥ããããã«å¿
èŠãªæå°ã®äº€æåæ°ãåºåããŠãã ãããæã«å
¥ããããšãäžå¯èœãªãã°ã代ããã«ã $-1$ ããåºåããŠãã ããã
</p>
<p>ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã</p>
<h3>å¶çŽ</h3>
<ul>
<li>$1 \leq X,Y,Z,N,M \leq 10^5$</li>
<li>$1 \leq S \leq N$</li>
<li>$1 \leq T \leq M$</li>
<li>$1 \leq A_i \leq X$</li>
<li>$1 \leq B_i \leq Y$</li>
<li>$1 \leq C_i \leq Y$</li>
<li>$1 \leq D_i \leq Z$</li>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
</ul>
<h3>å
¥åäŸ1</h3>
<pre>
1 1 1 1 1 1 1
1 1
1 1
</pre>
<h3>åºåäŸ1</h3>
<pre>
1
</pre>
<h3>å
¥åäŸ2</h3>
<pre>
2 3 4 3 5 1 5
1 1
1 2
2 2
2 1
3 1
3 2
3 3
3 4
</pre>
<h3>åºåäŸ2</h3>
<pre>
4
</pre>
<h3>å
¥åäŸ3</h3>
<pre>
1 2 2 1 2 1 1
1 2
1 2
2 1
</pre>
<h3>åºåäŸ3</h3>
<pre>
-1
</pre>
|
p00665 |
<H1>Problem G : Everything Starts With Your Vote</H1>
<p>
ãã¥ãŒãªã¹ãã£ã¯ã¹ãšããèšèãããã確å®ã«ããŸããããšããä¿èšŒã¯ãªãããã©ã倧æµã®å Žåã¯ããŸããããæ¯èŒçåçŽãªã¢ãããŒãã®ããšã ãåçŽã«ããŠåŒ·åã§ãããããã«ããã®äžã®äžã¯å€ãã®ãã¥ãŒãªã¹ãã£ã¯ã¹ã§æºã¡æº¢ããŠããã
</p>
<p>
ãã¥ãŒãªã¹ãã£ã¯ã¹ã®äžäŸãšããŠããããªãã®ãæãããããã¢ãã¡çªçµã«ãããŠããããã£ã©ã¯ã¿ãŒã®äººæ°åºŠã¯ããã®ã¢ãã¡æ¬ç·šäžã«ãããç»å Žæéã®ç·åã«æ¯äŸããã確ãã«ããã¯å€ãã®å Žåã«æãç«ã£ãŠããããã ãããããã©ãããåã¯å°æ°æŽŸã«å±ãããããã圱ã®èããã£ã©ãèæ¯ã«ã¡ãããšæ ãã¢ããã£ã©ãªããã«éã£ãŠå¯æãèŠãããããã®ã ã
</p>
<p>
èªåã®å¥œããªãã£ã©ã®ããšããä»äººãã©ãæã£ãŠãããããããããªããããšã¯èšã£ãŠãããªãäºæ
ããæ®å¿µãªãããããé¢é£ååããã£ã®ã¥ã¢ããã£ã©ã¯ã¿ãŒãœã³ã°CDãªã©ã¯ã人æ°ã®ãããã£ã©ã®ãã®ããåªå
çã«çºå£²ãããåŸåã«ããã®ã ã忥çã«ã¯åœç¶ã®éžæã ãšã¯ãããäžäººæ°ãã£ã©ã®ãã¡ã³ã®è©èº«ã¯çãã
</p>
<p>
ããã§éèŠãšãªã£ãŠããã®ããã¢ãã¡çªçµã®å¶äœäŒç€Ÿã«ãã£ãŠè¡ãããäººæ°æç¥šã§ãããå®éã®äººæ°ãã©ãã§ãããããã§å€ãã®ç¥šãç²åŸããã°ãé¢é£ååãžã®éãéãããã®ã ãã©ããªææ®µã䜿ã£ãŠã祚ãéããã°ãªããŸãã
</p>
<p>
峿£ãªãæç¥šã®ããã«ãããé¢é£ååã1ã€è³Œå
¥ãããã³ã«1ç¥šã®æç¥šæš©ãäžããããããã®ä»çµã峿£ãšåŒã¶ã¹ããã©ããã¯ä»å€§ããè°è«ãããŠãããããšã«ããå㯠<i>L</i> ç¥šã®æç¥šæš©ãåŸããæç¥šã®å¯Ÿè±¡ãšãªããã£ã©ã¯å
šéšã§ <i>N</i> 人ããŠãããå€ãã®ç¥šãç²åŸãã <i>K</i> 人ã®ãã£ã© (å祚ã®å Žåã¯ååã®èŸæžé ) ã®é¢é£ååãäŒç»ãããããšã«ãªããåã®å¥œããªãã£ã©ã¯å
šéšã§ <i>M</i> 人ããŠããã®äžããã§ããã ãå€ãã®ãã£ã©ãäžäœ <i>K</i> 人ã«å
¥ããããšæã£ãŠããã
</p>
<p>
åã¯ãŸããããããã®ãã£ã©ãã©ãã ãã®ç¥šãç²åŸããããäºæž¬ãã(é£ããããšã§ã¯ãªãããããã£ã©ã¯ã¿ãŒã®äººæ°åºŠã¯ããã®ç»å Žæéã®ç·åã«æ¯äŸãããšä»®å®ããã ãã )ããã®äºæž¬ãæ£ãããšããŠãããå€ãã®åã®å¥œããªãã£ã©ã®é¢é£ååãçºå£²ãããããã«ããããã«ã¯ãåã¯ãã® <i>L</i> 祚ã誰ã«ã©ãã ãæããã°ããã ãããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã
åã±ãŒã¹ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>N</i> <i>M</i> <i>K</i> <i>L</i>
<i>name<sub>0</sub></i> <i>x<sub>0</sub></i>
.
.
.
<i>name<sub>N-1</sub></i> <i>x<sub>N-1</sub></i>
<i>fav<sub>0</sub></i>
.
.
.
<i>fav<sub>M-1</sub></i>
</pre>
<p>
<i>N</i>ã<i>M</i>ã<i>K</i>ã<i>L</i>ã®æå³ã¯å顿ã«èšãããŠãããšããã§ããã<br>
<i>name<sub>i</sub></i>ãã¯ãã£ã©ã¯ã¿ãŒã®ååã<i>x<sub>i</sub></i>ãã¯<i>i</i> çªç®ã®ãã£ã©ã¯ã¿ãŒã®ç¥šã®ç·æ°ã衚ãã<br>
<i>fav<sub>i</sub></i> ã¯ããªããã²ããããŠãããã£ã©ã¯ã¿ãŒã®ååã衚ãããããã®ååã¯å¿
ãç°ãªãããŸãå¿
ããã£ã©ã¯ã¿ãŒã®ååã®å
¥åã®äžã«å«ãŸããã<br>
</p>
<p>
å
¥åã®çµããã¯<i>N</i> = 0 ã〠<i>M</i> = 0 ã〠<i>K</i> = 0 ã〠<i>L</i> = 0ãããªãè¡ã«ãã£ãŠäžãããã<br>
</p>
<p>
ãŸãåå€ã¯ä»¥äžã®æ¡ä»¶ãæºãã<br>
1 ≤ <i>N</i> ≤ 100,000<br>
1 ≤ <i>M</i> ≤ <i>N</i><br>
1 ≤ <i>K</i> ≤ <i>N</i><br>
1 ≤ <i>L</i> ≤ 100,000,000<br>
0 ≤ <i>x<sub>i</sub></i> ≤ 100,000,000<br>
<i>name<sub>i</sub></i>ã¯ã¢ã«ãã¡ãããã®ã¿ãå«ã¿ãé·ãã¯10æå以äžã§ããã
</p>
<p>
ãã¹ãã±ãŒã¹ã®æ°ã¯150ãè¶
ããªãã<br>
ãŸã20,000 ≤ <i>N</i> ãšãªãã±ãŒã¹ã®æ°ã¯20ãè¶
ããªãããšãä¿èšŒãããŠããã<br>
</p>
<p>
ãžã£ããžããŒã¿ã¯å€§ããã®ã§ãéãå
¥åã䜿ãããšãæšå¥šããã
</p>
<h2>Output</h2>
<p>
<i>M</i> 人ã®ãã£ã©ã®äžããæå€§ã§äœäººãäžäœ<i>K</i> 人ã«å
¥ããããšãåºæ¥ããã1è¡ã§åºåããã
</p>
<h2>Sample input</h2>
<pre>4 1 3 4
yskwcnt 16
akzakr 7
tsnukk 12
fnmyi 13
akzakr
4 1 3 5
akzakr 7
tsnukk 12
fnmyi 13
yskwcnt 16
akzakr
4 2 2 1
akzakr 4
tsnukk 6
yskwcnt 6
fnmyi 12
akzakr
fnmyi
5 2 3 28
knmmdk 6
skrkyk 14
tmemm 14
akmhmr 15
mksyk 25
knmmdk
skrkyk
5 2 3 11
tmemm 12
skrkyk 18
knmmdk 21
mksyk 23
akmhmr 42
skrkyk
tmemm
14 5 10 38
iormns 19
hbkgnh 23
yyitktk 31
rtkakzk 36
mmftm 43
ykhhgwr 65
hrkamm 66
ktrotns 67
mktkkc 68
mkhsi 69
azsmur 73
tknsj 73
amftm 81
chyksrg 88
mkhsi
hbkgnh
mktkkc
yyitktk
tknsj
14 5 10 38
mktkkc 24
rtkakzk 25
ykhhgwr 25
hrkamm 27
amftm 37
iormns 38
tknsj 38
yyitktk 39
hbkgnh 53
mmftm 53
chyksrg 63
ktrotns 63
azsmur 65
mkhsi 76
mkhsi
hbkgnh
mktkkc
yyitktk
tknsj
0 0 0 0
</pre>
<H2>Sample output</H2>
<pre>
0
1
1
2
1
4
5
</pre>
<hr>
<p>
The University of Aizu Programming Contest 2011 Summer<br>
åæ¡: Tomoya Sakai<br>
å顿: Takashi Tayama<br>
</p> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.