question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p00524 |
<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> ãã¯ãã¢ã¢ã³ã¬(Sugar Glider)
</H1>
<br/>
<p>
ãã¯ãã¢ã¢ã³ã¬ã®JOI åãäœãã§ããæ£®ã«ã¯ãŠãŒã«ãªã®æšã $N$ æ¬çããŠããïŒãããã®æšã«ã¯1 ãã $N$ ã®çªå·ãã€ããŠããïŒæš $i$ ã®é«ã㯠$H_i$ ã¡ãŒãã«ã§ããïŒ
</p>
<p>
JOI åãçžäºã«çŽæ¥é£ã³ç§»ãããšã®ã§ããæšã®çµã $M$ çµããïŒåçµã®æšã®éãé£ã³ç§»ãããã«ãããæéãå®ãŸã£ãŠããïŒJOI åãæšã®éãé£ã³ç§»ã£ãŠããéã¯ïŒå°é¢ããã®é«ãã1 ç§ããã1 ã¡ãŒãã«äžããïŒããªãã¡ïŒJOI åã®çŸåšã®å°é¢ããã®é«ãã $h$ ã¡ãŒãã«ïŒæšã®éãé£ã³ç§»ãããã«ãããæéã $t$ ç§ã§ãããšãïŒé£ã³ç§»ã£ãåŸã®å°é¢ããã®é«ã㯠$h - t$ ã¡ãŒãã«ãšãªãïŒãã ãïŒ$h - t$ ã0 ãããå°ãããªãå Žåãè¡ãå
ã®æšã®é«ãããã倧ãããªãå Žåã¯é£ã³ç§»ãããšãã§ããªãïŒ
</p>
<p>
ããã«ïŒJOI åã¯æšã®åŽé¢ãäžäžã«ç§»åããããšã«ãã£ãŠïŒå°é¢ããã®é«ãã0 ã¡ãŒãã«ããä»ããæšã®é«ãã®ç¯å²ã§å¢æžãããããšãã§ããïŒJOI åãå°é¢ããã®é«ãã1 ã¡ãŒãã«å¢å ãŸãã¯æžå°ãããããã«ã¯1 ç§ã®æéããããïŒ
</p>
<p>
JOI åã¯ïŒæš1 ã®é«ã$X$ ã¡ãŒãã«ã®äœçœ®ããæš$N$ ã®é äž(é«ã$H_N$ ã¡ãŒãã«ã®äœçœ®) ã«è¡ãããšããŠããïŒãã®ããã«ãããæéã®æå°å€ãç¥ãããïŒ
</p>
<h2>課é¡</h2>
<p>
åæšã®é«ããšïŒJOI åãçŽæ¥é£ã³ç§»ãããšãã§ããæšã®çµã®æ
å ±ãšïŒæåJOI åãããå Žæã®é«ããäžããããïŒæš $N$ ã®é äžã«è¡ãããã«ãããæéã®æå°å€ãæ±ããããã°ã©ã ãäœæãã.
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li>1 è¡ç®ã«ã¯ïŒæŽæ° $N, M, X$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒæšã®æ¬æ°ã $N$ æ¬ïŒç§»åã§ããæšã®çµã $M$ çµããïŒæåJOI åãæš1 ã®é«ã $X$ ã¡ãŒãã«ã®äœçœ®ã«ããããšã衚ãïŒ</li>
<li>ç¶ã $N$ è¡ã®ãã¡ã® $i$ è¡ç®$(1 \leq i \leq N)$ ã«ã¯ïŒæŽæ° $H_i$ ãæžãããŠããïŒããã¯ïŒæš $i$ ã®é«ãã $H_i$ ã¡ãŒãã«ã§ããããšã衚ãïŒ</li>
<li>ç¶ã$M$ è¡ã®ãã¡ã® $j$ è¡ç®$(1 \leq j \leq M)$ ã«ã¯ïŒæŽæ° $A_j, B_j, T_j$ $(1 \leq A_j \leq N, 1 \leq B_j \leq N, A_j \ne B_j)$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒæš $A_j$ ãšæš $B_j$ ã®éãçžäºã« $T_j$ ç§ã§é£ã³ç§»ãããšãã§ããããšã衚ããŠããïŒãŸãïŒ$1 \leq j < k \leq M$ ãªãã°ïŒ$(A_j, B_j) \ne (A_k, B_k)$ ããã³$(A_j, B_j) \ne (B_k, A_k)$ ãæºããïŒ</li>
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒæš1 ã®é«ã $X$ ã¡ãŒãã«ã®äœçœ®ããæš $N$ ã®é äžã«è¡ãããã«ãããæéã®æå°å€ãç§åäœã§è¡šãæŽæ°ã1 è¡ã§åºåããïŒãã ãïŒãã®ãããªæ¹æ³ããªãå Žåã¯ä»£ããã« -1 ãåºåããïŒ
</p>
<h2>å¶é</h2>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li> $2 \leq N \leq 100000$</li>
<li> $1 \leq M \leq 300000$</li>
<li> $1 \leq H_i \leq 1000000000 (1 \leq i \leq N)$</li>
<li> $1 \leq T_j \leq 1000000000 (1 \leq j \leq M)$</li>
<li> $0 \leq X \leq H_1$</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1 </h3>
<pre>
5 5 0
50
100
25
30
10
1 2 10
2 5 50
2 4 20
4 3 1
5 4 20
</pre>
<h3>åºåäŸ 1 </h3>
<pre>
110
</pre>
<p>
äŸãã°ïŒä»¥äžã®ããã«ç§»åããã°ããïŒ<br>
1. æš1 ã50 ã¡ãŒãã«ç»ãïŒ<br>
2. æš1 ããæš2 ã«é£ã³ç§»ãïŒ<br>
3. æš2 ããæš4 ã«é£ã³ç§»ãïŒ<br>
4. æš4 ããæš5 ã«é£ã³ç§»ãïŒ<br>
5. æš5 ã10 ã¡ãŒãã«ç»ãïŒ<br>
</p>
<br>
<h3>å
¥åäŸ 2 </h3>
<pre>
2 1 0
1
1
1 2 100
</pre>
<h3>åºåäŸ 2 </h3>
<pre>
-1
</pre>
<p>
JOI åã¯æš1 ããæš2 ã«é£ã³ç§»ãããšãã§ããªãïŒ
</p>
<br>
<h3>å
¥åäŸ 3 </h3>
<pre>
4 3 30
50
10
20
50
1 2 10
2 3 10
3 4 10
</pre>
<h3>åºåäŸ 3 </h3>
<pre>
100
</pre>
<br>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00877 |
<H1><font color="#000">Problem D:</font> Separate Points</H1>
<p>
Numbers of black and white points are placed on a plane. Let's imagine that a straight line
of infinite length is drawn on the plane. When the line does not meet any of the points, the
line divides these points into two groups. If the division by such a line results in one group
consisting only of black points and the other consisting only of white points, we say that the
line "separates black and white points".
</p>
<p>
Let's see examples in Figure 3. In the leftmost example, you can easily find that the black and
white points can be perfectly separated by the dashed line according to their colors. In the
remaining three examples, there exists no such straight line that gives such a separation.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_separatePoints"><br>
<p>Figure 3: Example planes</p>
</center>
<p>
In this problem, given a set of points with their colors and positions, you are requested to decide
whether there exists a straight line that separates black and white points.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets, each of which is formatted as follows.
</p
<p>
<i>n m</i><br>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br>
.<br>
.<br>
.<br>
<i>x<sub>n</sub> y<sub>n</sub></i><br>
<i>x</i><sub><i>n</i>+1</sub> <i>y</i><sub><i>n</i>+1</sub><br>
.<br>
.<br>
.<br>
<i>x</i><sub><i>n</i>+<i>m</i></sub> <i>y</i><sub><i>n</i>+<i>m</i></sub><br>
</p>
<p>
The first line contains two positive integers separated by a single space; <i>n</i> is the number of black
points, and <i>m</i> is the number of white points. They are less than or equal to 100. Then <i>n</i> + <i>m</i>
lines representing the coordinates of points follow. Each line contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i>
separated by a space, where (<i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> ) represents the <i>x</i>-coordinate and the <i>y</i>-coordinate of the <i>i</i>-th
point. The color of the <i>i</i>-th point is black for 1 ≤ i ≤ <i>n</i>, and is white for <i>n</i> + 1 ≤ <i>i</i> ≤ <i>n</i> + <i>m</i>.
</p>
<p>
All the points have integral <i>x</i>- and <i>y</i>-coordinate values between 0 and 10000 inclusive. You can
also assume that no two points have the same position.
</p>
<p>
The end of the input is indicated by a line containing two zeros separated by a space.
</p>
<H2>Output</H2>
<p>
For each dataset, output "<span>YES</span>" if there exists a line satisfying the condition. If not, output
"<span>NO</span>". In either case, print it in one line for each input dataset.
</p>
<H2>Sample Input</H2>
<pre>
3 3
100 700
200 200
600 600
500 100
500 300
800 500
3 3
100 300
400 600
400 100
600 400
500 900
300 300
3 4
300 300
500 300
400 600
100 100
200 900
500 900
800 100
1 2
300 300
100 100
500 500
1 1
100 100
200 100
2 2
0 0
500 700
1000 1400
1500 2100
2 2
0 0
1000 1000
1000 0
0 1000
3 3
0 100
4999 102
10000 103
5001 102
10000 102
0 101
3 3
100 100
200 100
100 200
0 0
400 0
0 400
3 3
2813 1640
2583 2892
2967 1916
541 3562
9298 3686
7443 7921
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
NO
NO
YES
YES
NO
NO
NO
YES
</pre>
|
p01765 |
<h1>F : Todaiji / æ±å€§å¯º</h1>
<h1>Problem</h1>
<p>ã¥ããåã¯æ
è¡ã倧奜ãã§ãããå¥è¯æ
è¡ã«èšªããã¥ããåã¯ã<a href="http://www.nkdaibutsu.com/nara/daibutsuden.html">æ±å€§å¯ºã«ããæ±ã®ç©Ž</a>ããããããšã«ãããããããã¥ããåã¯æè¿å€ªãã ããããã穎ã«åŒã£ããã£ãŠããŸããããããªããããã§ã¥ããåã¯ãã©ããŸã§å€ªã£ãŠã倧äžå€«ãã調ã¹ãããã°ã©ã ãæžãããšã«ããã</p>
<p>ç°¡åã®ããåé¡ã¯å¹³é¢äžã§èããã穎ã¯2æ¬ã®æãç·ã§ãã¥ããåã¯åã§è¡šãããšãšãããæãç· 1 ã¯ç¹ (0,0) ãå§ç¹ãç¹ (1000,0) ãçµç¹ã§ãããæãç· 2 ã¯ç¹ (0,1000) ãå§ç¹ãç¹ (1000,1000) ãçµç¹ã§ããã ã¥ããåã®å
šèº«ã <em>x</em> < 0 ã®é åã«ããç¶æ
ããã2 æ¬ã®æãç·ã®éãéãã <em>x</em> > 1000 ã®é åã«ã¥ããåã®å
šèº«ãåºãç¶æ
ã«å°éã§ãããããªæå€§ã®çŽåŸãæ±ããŠã»ãããééããéã®çµè·¯ã¯èªç±ã§ãããåãæãç·ã«æ¥ããŠãè¯ãã</p>
<h1>Input</h1>
<p>å
¥åã¯æ¬¡ã®ãããªåœ¢åŒã§äžããããã</p>
<p><em>N<sub>1</sub></em><br><em>x<sub>11</sub></em> <em>y<sub>11</sub></em><br><em>x<sub>12</sub></em> <em>y<sub>12</sub></em><br>...<br><em>x<sub>1N1</sub></em> <em>y<sub>1N1</sub></em><br><em>N<sub>2</sub></em><br><em>x<sub>21</sub></em> <em>y<sub>21</sub></em><br><em>x<sub>22</sub></em> <em>y<sub>22</sub></em><br>...<br><em>x<sub>2N2</sub></em> <em>y<sub>2N2</sub></em></p>
<ul>
<li><em>N<sub>1</sub></em> ã¯1ã€ç®ã®æãç·ãæ§æããç¹ã®æ°ã§ããã</li>
<li><em>x<sub>1i</sub></em>, <em>y<sub>1i</sub></em> ã¯ã1ã€ç®ã®æãç·ãæ§æãã <em>i</em> çªç®ã®ç¹ã®åº§æšã§ããã(<em>x<sub>1i</sub></em>, <em>y<sub>1i</sub></em>) ãš (<em>x<sub>1(i+1)</sub></em>, <em>y<sub>1(i+1)</sub></em>) ãçµã°ããã</li>
<li>(0,0) ãš (<em>x<sub>11</sub></em> , <em>y<sub>11</sub></em>)ã(<em>x<sub>1N1</sub></em> , <em>y<sub>1N1</sub></em>) ãš (1000,0) ãããããç·ã§çµã°ããã</li>
<li>2ã€ç®ã®æãç·ã«ã€ããŠãæãç·1ãšåæ§ã®åœ¢åŒã§å
¥åãããããã ãã(<em>x<sub>21</sub></em> , <em>y<sub>21</sub></em>) ãšçµã°ããã®ã¯ (0,1000)ã(<em>x<sub>2N2</sub></em> , <em>y<sub>2N2</sub></em>) ãšçµã°ããã®ã¯ (1000,1000) ã§ããã</li>
</ul>
<h1>Constraints</h1>
<ul>
<li>å
¥åã¯å
šãп޿°ã§ããã</li>
<li>1 ⊠<em>N<sub>1</sub></em>, <em>N<sub>2</sub></em> ⊠50</li>
<li>0 ⊠<em>x<sub>ij</sub></em> , <em>y<sub>ij</sub></em> ⊠1000</li>
<li><em>x<sub>ij</sub></em> ⊠<em>x<sub>i(j+1)</sub></em></li>
<li>æãç·ã¯èªåèªèº«ãšäº€ãããªãã</li>
<li>2 æ¬ã®æãç·ã¯äº€ãããªãã</li>
</ul>
<h1>Output</h1>
<p>2 æ¬ã®æãç·ã®éãééã§ãããã¥ããåã®äœã®æå€§ã®çŽåŸã1è¡ã§åºåããã10<sup>-6</sup> ãŸã§ã®èª€å·®ã¯èš±ãããã</p>
<h1>Samples</h1>
<h2>Sapmle Input 1</h2>
<pre>2
300 300
700 300
2
300 700
700 700</pre>
<h2>Sapmle Output 1</h2>
<pre>400.0000000000</pre>
<h2>Sapmle Input 2</h2>
<pre>31
53 334
96 201
99 129
114 365
123 39
186 257
195 247
233 335
256 79
302 217
404 302
411 222
428 422
433 388
441 443
468 309
497 408
518 218
537 361
538 193
541 447
580 16
606 185
610 178
737 421
754 210
805 418
849 416
876 262
878 220
948 207
28
7 919
89 640
145 656
152 963
204 558
252 630
269 690
325 629
357 583
454 593
523 648
538 949
541 821
559 655
581 614
593 877
607 571
631 817
682 942
776 529
810 606
813 598
834 778
838 999
910 661
920 824
982 517
987 689</pre>
<h2>Sapmle Output 2</h2>
<pre>114.7257599670</pre>
<div class="figure">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_todaiji_sample2">
</div>
<p>ãµã³ãã« 2 ãå³ç€ºãããšãã®ããã«ãªãã</p> |
p03758 | <span class="lang-en lang-child hidden-lang">
<div class="part">
Max Score: $1500$ Points <br/>
<section>
<h3>Problem Statement</h3>
Huge kingdom: $Atcoder$ contains $N$ towns and $N-1$ roads. This kingdom is connected.<br/>
<br/>
You have to detect the kingdom's road.<br/>
In order to detect, You can ask this form of questions.<br/>
<ul>
<li>You can output a string $S$. Length of $S$ must be $N$ and The character of string $S$ must be represented by '$0$' or '$1$'.</li>
<li>Computer paint the towns with white or black according to the character string you output.</li>
<li>If $i$-th character of $S$ is '0', computer paint town $i$ white.</li>
<li>If $i$-th character of $S$ is '1', computer paint town $i$ black.</li>
<li>Please consider an undirected graph $G$.</li>
<li>For each edge, computer do the following processing: If both ends painted black, computer adds this edge to $G$.</li>
<li>Computer returns value $x$: sum of "diameter of tree"$^2$ about each connected components.</li>
</ul>
For example, when $S$="11001111" and the kingdom's structure is this, computer returns 10.<br/>
<div align="left" class="img-nocaption">
<img src="https://atcoder.jp/img/s8pc-4/18f55c17e4feefd6794b69a1b91d5e6f.png" width="500"/>
</div>
Please detect the structure of $Atcoder$ as few questions as possible.<br/>
</section>
</div>
<div class="io-style">
<div class="part">
<section>
<h3>Input, Output</h3>
This is a reactive problem.<br/>
The first input is as follows:<br/>
<br/>
<blockquote>
$N$
</blockquote>
<ul class="simple">
<li>$N$ is number of towns in $Atcoder$.</li>
</ul>
<br/>
Next, you can ask questions.<br/>
The question must be in the form as follows:<br/>
<blockquote>
? $S$
</blockquote>
$S$ is a string. The mean of $S$ written in the problem statement. Length of $S$ must be $N$.<br/>
<br/>
The answer of question is as follows:<br/>
<blockquote>
$x$
</blockquote>
The mean of $x$ written in the problem statement.<br/>
<br/>
Finally, your program must output as follows:<br/>
<blockquote>
! $(a_1,b_1)$ $(a_2,b_2)$ $(a_3,b_3)$ ⊠$(a_{N-1},b_{N-1})$
</blockquote>
This output means your program detects all roads of $Atcoder$.<br/>
$(a_i,b_i)$ means there is a road between $a_i$ and $b_i$.<br/>
<br/>
You can output roads any order, but you must output the answer on a single line.<br/>
</section>
</div>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li>$N$=200</li>
<li>$Atcoder$ contains $N-1$ roads and this kingdom is connected.</li>
<li>All cases were made randomly.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Scoring</h3>
Let the number of questions be $L$.<br/>
<br/>
<ul>
<li>If $L > 20000$, $score$ = $0$ points</li>
<li>If $18000 < L ⊠20000$, $score$ = $200$ points</li>
<li>If $5000 < L ⊠18000$, $score$ = $650-L/40$ points</li>
<li>If $4000 < L ⊠5000$, $score$ = $800-L/20$ points</li>
<li>If $2000 < L ⊠4000$, $score$ = $1400-L/5$ points</li>
<li>If $1200 < L ⊠2000$, $score$ = $1500-L/4$ points</li>
<li>If $700 < L ⊠1200$, $score$ = $1850-L/2$ points</li>
<li>If $L ⊠700$, $score$ = $1500$ points</li>
</ul>
<br/>
There is $5$ cases, so points of each case is $score/5$.<br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input</h3>
This case is $N=4$. This case is not include because this is not $N=200$.<br/>
<pre>
N=4
0 1
1 2
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output</h3>
Sample interaction is as follows:<br/>
<table class="table-striped table-bordered table-condensed">
<tr align="center">
<th>Input from computer</th>
<th>Output</th>
</tr>
<tr align="center">
<td>4</td>
<td> </td>
</tr>
<tr align="center">
<td> </td>
<td>? 1111</td>
</tr>
<tr align="center">
<td>4</td>
<td> </td>
</tr>
<tr align="center">
<td> </td>
<td>? 1101</td>
</tr>
<tr align="center">
<td>4</td>
<td> </td>
</tr>
<tr align="center">
<td> </td>
<td>? 1001</td>
</tr>
<tr align="center">
<td>0</td>
<td> </td>
</tr>
<tr align="center">
<td> </td>
<td>? 1100</td>
</tr>
<tr align="center">
<td>1</td>
<td> </td>
</tr>
<tr align="center">
<td> </td>
<td>? 1011</td>
</tr>
<tr align="center">
<td>0</td>
<td> </td>
</tr>
<tr align="center">
<td> </td>
<td>! (0,1) (1,2) (1,3)</td>
</tr>
</table>
<br/>
In this sample, structure of $Atcoder$ is as follows:<br/>
<div align="left" class="img-nocaption">
<img src="https://atcoder.jp/img/s8pc-4/8d26e2d0a3fd5e4cc24efe8d21296341.png" width="500"/>
</div>
<br/>
This question is not always meaningful.<br/>
</section>
</div>
</span> |
p01335 |
<h1><font color="#000">Problem C:</font> K Poker</h1>
<h2>Description</h2>
<p>æã¯200X幎ãK倧åŠã§æŽ»åããè¬ã®ãµãŒã¯ã«Kã¯ãã®å€§åŠã®æåç¥ã®æäžã«Kæ±4Fã§åœŒããäœæããæ°ããªã²ãŒã ãKããŒã«ãŒãçºè¡šããã<br>
ãã®ã²ãŒã ã¯äžèŠãããšæ®éã®ããŒã«ãŒã§ããããã«ãŒãã«åºæ¬ç¹ãšããèŠçŽ ãã€ããŠããŒã«ãŒãããå¥¥ã®æ·±ãã²ãŒã ã«ãããã®ã§ããã<br>
ã«ãŒãã®åºæ¬ç¹ã¯ããããã®ã«ãŒãã«æžãããŠããçµµæã«ãã£ãŠæ±ºãŸããææã®ç¹æ°ã¯ææã«ãã5æã®åºæ¬ç¹ã®åèšã«ææã®åœ¹ã®åçãæãããã®ã«ãªãã<br>
ãã®åºæ¬ç¹ãå°å
¥ããäºã«ãããäŸãã°ãã«ããŠã¹ãªã©ã®åŒ·ã圹ãäœã£ããšããŠãåºæ¬ç¹ã0ã§ããã°ãã¿ãšåæ§ã«æ±ãããŠããŸããã¯ã³ãã¢ã«è² ããããšããããã<br>
ãã以å€ã®ã«ãŒã«ã¯éåžžã®ããŒã«ãŒãšåãã§ããã<br>
ãã®KããŒã«ãŒãPCã«ç§»æ€ããããšæã£ãããªãã¯ææã®ç¹æ°ãèšç®ããããã°ã©ã ãæžãäºã«ããã</p>
<p>ãªããã®ã²ãŒã ã¯18æ³æªæºã®äººã¯ãã¬ã€åºæ¥ãªãã</p>
<h2>Input</h2>
<p>å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã<br>
åãã¹ãã±ãŒã¹ã®æåã®è¡ã«ã¯ãã§ãã¯ããææã®æ°NãæžãããŠããã<br>
次ã®4è¡ã«ã¯13åã®æŽæ°ã䞊ã³ã«ãŒãã®åºæ¬ç¹ã1-13ã®é ã«äžŠãã§æžãããŠããã4è¡ã®ã¹ãŒãã¯äžããé ã«ã¹ããŒããã¯ããŒããŒãããŒãããã€ã€ã®é ã«äžŠãã§ããã<br>
次ã®è¡ã«ã¯9åã®æŽæ°ã䞊ã³ãé ã«ã¯ã³ãã¢ãããŒãã¢ãã¹ãªãŒã«ãŒããã¹ãã¬ãŒãããã©ãã·ã¥ããã«ããŠã¹ããã©ãŒã«ãŒããã¹ãã¬ãŒããã©ãã·ã¥ããã€ã€ã«ã¹ãã¬ãŒããã©ãã·ã¥ã®åçã衚ããŠããã圹ã®åçã¯å¿
ãæé ãšãªã£ãŠããããã¿(圹ç¡ããããŒãã¢)ã®åçã¯åžžã«0ã§ããã<br>
次ã®Nè¡ã«ã¯ææã衚ã5åã®é·ã2ã®ç°ãªãæååã䞊ãã§ããã1æåç®ã¯ã«ãŒãã®æ°å€ã衚ã,A,2,3,4,5,6,7,8,9,T,J,Q,Kã®ããããã§ããã2æåç®ã¯ã«ãŒãã®ã¹ãŒãã衚ããS,C,H,Dã®ããããã§ãããåã¢ã«ãã¡ãããã¯Aã¯ãšãŒã¹ãTã¯10ãJã¯ãžã£ãã¯ãQã¯ã¯ã€ãŒã³ãKã¯ãã³ã°ãSã¯ã¹ããŒããCã¯ã¯ããŒããŒãHã¯ããŒããDã¯ãã€ã€ã衚ãã<br>
å
¥åã®æ°å€ã¯å
šãŠ[0,10000]ã®ç¯å²ã«åãŸã£ãŠããã<br>
å
¥åã¯EOFã§çµããã</p>
<h2>Output</h2>
<p>åææã®ç¹æ°ã1è¡ãã€åºåããã<br>
é£ç¶ãã2ã€ã®ãã¹ãã±ãŒã¹ã®éã«ã¯ç©ºè¡ã1ã€å
¥ããããšã<br>
圹ã«ã€ããŠã¯<a href="http://ja.wikipedia.org/wiki/%E3%83%9D%E3%83%BC%E3%82%AB%E3%83%BC#.E3.83.9D.E3.83.BC.E3.82.AB.E3.83.BC.E3.83.BB.E3.83.8F.E3.83.B3.E3.83.89">wikipediaã®ããŒã«ãŒ</a>ã®ããŒãžãåç
§ã®ããšã
ãªããã¹ãã¬ãŒãã¯ãšãŒã¹ãšãã³ã°ããŸããå Žåãããããææã10,ãžã£ãã¯ãã¯ã€ãŒã³ããã³ã°ããšãŒã¹ã®å Žåã«ã®ã¿ã¹ãã¬ãŒããšã¿ãªãããã</p>
<h2>Sample Input</h2>
<pre>
3
0 1 0 1 0 0 0 0 0 1 0 0 0
1 0 0 0 0 0 1 0 0 1 0 0 2
0 1 1 0 1 1 1 0 0 0 0 5 5
3 1 1 1 0 1 0 0 1 0 3 0 2
1 1 2 4 5 10 20 50 100
7H 6H 2H 5H 3H
9S 9C 9H 8H 8D
KS KH QH JD TS
10
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 3 4 5 6 7 8 9
AS 3D 2C 5D 6H
6S 6C 7D 8H 9C
TS TD QC JD JC
KD KH KC AD 2C
3D 4H 6D 5H 7C
2S KS QS AS JS
TS TD JD JC TH
8H 8D TC 8C 8S
4S 5S 3S 7S 6S
KD QD JD TD AD
</pre>
<h2>Output for Sample Input</h2>
<pre>
25
0
14
0
5
10
15
20
25
30
35
40
45
</pre>
|
p03308 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence <var>A</var> of length <var>N</var>.
Find the maximum absolute difference of two elements (with different indices) in <var>A</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 100</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum absolute difference of two elements (with different indices) in <var>A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 4 6 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>The maximum absolute difference of two elements is <var>A_3-A_1=6-1=5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
1000000000 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>999999999
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
1 1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p02630 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have a sequence <var>A</var> composed of <var>N</var> positive integers: <var>A_{1}, A_{2}, \cdots, A_{N}</var>.</p>
<p>You will now successively do the following <var>Q</var> operations:</p>
<ul>
<li>In the <var>i</var>-th operation, you replace every element whose value is <var>B_{i}</var> with <var>C_{i}</var>.</li>
</ul>
<p>For each <var>i</var> <var>(1 \leq i \leq Q)</var>, find <var>S_{i}</var>: the sum of all elements in <var>A</var> just after the <var>i</var>-th operation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var> 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5} </var></li>
<li><var> B_{i} \neq C_{i} </var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>A_{1}</var> <var>A_{2}</var> <var>\cdots</var> <var>A_{N}</var>
<var>Q</var>
<var>B_{1}</var> <var>C_{1}</var>
<var>B_{2}</var> <var>C_{2}</var>
<var>\vdots</var>
<var>B_{Q}</var> <var>C_{Q}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print <var>Q</var> integers <var>S_{i}</var> to Standard Output in the following format:</p>
<pre><var>S_{1}</var>
<var>S_{2}</var>
<var>\vdots</var>
<var>S_{Q}</var>
</pre>
<p>Note that <var>S_{i}</var> may not fit into a <var>32</var>-bit integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 2 3 4
3
1 2
3 4
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
12
16
</pre>
<p>Initially, the sequence <var>A</var> is <var>1,2,3,4</var>.</p>
<p>After each operation, it becomes the following:</p>
<ul>
<li><var>2, 2, 3, 4</var></li>
<li><var>2, 2, 4, 4</var></li>
<li><var>4, 4, 4, 4</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 1 1 1
3
1 2
2 1
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
4
4
</pre>
<p>Note that the sequence <var>A</var> may not contain an element whose value is <var>B_{i}</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 2
3
1 100
2 100
100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>102
200
2000
</pre></section>
</div>
</span> |
p03922 | <span class="lang-en">
<p>Score : <var>700</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is playing with <var>N</var> cards.</p>
<p>The <var>i</var>-th card has an integer <var>X_i</var> on it.</p>
<p>Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:</p>
<ul>
<li>The integers on the two cards are the same.</li>
<li>The sum of the integers on the two cards is a multiple of <var>M</var>.</li>
</ul>
<p>Find the maximum number of pairs that can be created.</p>
<p>Note that a card cannot be used in more than one pair.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2âŠNâŠ10^5</var></li>
<li><var>1âŠMâŠ10^5</var></li>
<li><var>1âŠX_iâŠ10^5</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>M</var>
<var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum number of pairs that can be created.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 5
3 1 4 1 5 9 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>Three pairs <var>(3,2), (1,4)</var> and <var>(1,9)</var> can be created.</p>
<p>It is possible to create pairs <var>(3,2)</var> and <var>(1,1)</var>, but the number of pairs is not maximized with this.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>15 10
1 5 6 10 11 11 11 20 21 25 25 26 99 99 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre></section>
</div>
</span> |
p03888 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In an electric circuit, when two resistors <var>R_1</var> and <var>R_2</var> are connected in parallel, the equivalent resistance <var>R_3</var> can be derived from the following formula:</p>
<ul>
<li><var>\frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3}</var></li>
</ul>
<p>Given <var>R_1</var> and <var>R_2</var>, find <var>R_3</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq R_1, R_2 \leq 100</var></li>
<li><var>R_1</var> and <var>R_2</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>R_1</var> <var>R_2</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the value of <var>R_3</var>.</p>
<p>The output is considered correct if the absolute or relative error is at most <var>10^{-6}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1.2000000000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>49.7487437186
</pre></section>
</div>
</span> |
p02260 |
<H1>Selection Sort</H1>
<p>
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:
</p>
<pre>
SelectionSort(A)
1 for i = 0 to A.length-1
2 mini = i
3 for j = i to A.length-1
4 if A[j] < A[mini]
5 mini = j
6 swap A[i] and A[mini]
</pre>
<p>
Note that, indices for array elements are based on 0-origin.
</p>
<p>
Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
</p>
<H2>Input</H2>
<p>
The first line of the input includes an integer <i>N</i>, the number of elements in the sequence.
</p>
<p>
In the second line, <i>N</i> elements of the sequence are given separated by space characters.
</p>
<H2>Output</H2>
<p>
The output consists of 2 lines.
</p>
<p>
In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.
</p>
<p>
In the second line, please print the number of swap operations.
</p>
<H2>Constraints</H2>
<p>
1 ≤ <i>N</i> ≤ 100
</p>
<H2>Sample Input 1</H2>
<pre>
6
5 6 4 2 1 3
</pre>
<H2>Sample Output 1</H2>
<pre>
1 2 3 4 5 6
4
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
6
5 2 4 6 1 3
</pre>
<H2>Sample Output 2</H2>
<pre>
1 2 3 4 5 6
3
</pre>
|
p03021 | <span class="lang-en">
<p>Score : <var>1500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices numbered <var>1, 2, ..., N</var>. The <var>i</var>-th edge connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.
You are also given a string <var>S</var> of length <var>N</var> consisting of <code>0</code> and <code>1</code>. The <var>i</var>-th character of <var>S</var> represents the number of pieces placed on Vertex <var>i</var>.</p>
<p>Snuke will perform the following operation some number of times:</p>
<ul>
<li>Choose two pieces the distance between which is at least <var>2</var>, and bring these pieces closer to each other by <var>1</var>. More formally, choose two vertices <var>u</var> and <var>v</var>, each with one or more pieces, and consider the shortest path between them. Here the path must contain at least two edges. Then, move one piece from <var>u</var> to its adjacent vertex on the path, and move one piece from <var>v</var> to its adjacent vertex on the path.</li>
</ul>
<p>By repeating this operation, Snuke wants to have all the pieces on the same vertex. Is this possible?
If the answer is yes, also find the minimum number of operations required to achieve it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 2000</var></li>
<li><var>|S| = N</var></li>
<li><var>S</var> consists of <code>0</code> and <code>1</code>, and contains at least one <code>1</code>.</li>
<li><var>1 \leq a_i, b_i \leq N(a_i \neq b_i)</var></li>
<li>The edges <var>(a_1, b_1), (a_2, b_2), ..., (a_{N - 1}, b_{N - 1})</var> forms 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>S</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_{N - 1}</var> <var>b_{N - 1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is impossible to have all the pieces on the same vertex, print <code>-1</code>. If it is possible, print the minimum number of operations required.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
0010101
1 2
2 3
1 4
4 5
1 6
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>We can gather all the pieces in three operations as follows:</p>
<ul>
<li>Choose the pieces on Vertex <var>3</var> and <var>5</var>.</li>
<li>Choose the pieces on Vertex <var>2</var> and <var>7</var>.</li>
<li>Choose the pieces on Vertex <var>4</var> and <var>6</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7
0010110
1 2
2 3
1 4
4 5
1 6
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
01
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03471 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>The commonly used bills in Japan are <var>10000</var>-yen, <var>5000</var>-yen and <var>1000</var>-yen bills. Below, the word "bill" refers to only these.</p>
<p>According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained <var>N</var> bills for a total of <var>Y</var> yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †2000</var></li>
<li><var>1000 †Y †2 à 10^7</var></li>
<li><var>N</var> is an integer.</li>
<li><var>Y</var> is a multiple of <var>1000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the total value of <var>N</var> bills cannot be <var>Y</var> yen, print <code>-1 -1 -1</code>.</p>
<p>If the total value of <var>N</var> bills can be <var>Y</var> yen, let one such set of bills be "<var>x</var> <var>10000</var>-yen bills, <var>y</var> <var>5000</var>-yen bills and <var>z</var> <var>1000</var>-yen bills", and print <var>x</var>, <var>y</var>, <var>z</var> with spaces in between. If there are multiple possibilities, any of them may be printed.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9 45000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4 0 5
</pre>
<p>If the envelope contained <var>4</var> <var>10000</var>-yen bills and <var>5</var> <var>1000</var>-yen bills, he had <var>9</var> bills and <var>45000</var> yen in total. It is also possible that the envelope contained <var>9</var> <var>5000</var>-yen bills, so the output <code>0 9 0</code> is also correct.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20 196000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1 -1 -1
</pre>
<p>When the envelope contained <var>20</var> bills in total, the total value would be <var>200000</var> yen if all the bills were <var>10000</var>-yen bills, and would be at most <var>195000</var> yen otherwise, so it would never be <var>196000</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000 1234000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>14 27 959
</pre>
<p>There are also many other possibilities.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2000 20000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>2000 0 0
</pre></section>
</div>
</span> |
p03164 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> items, numbered <var>1, 2, \ldots, N</var>.
For each <var>i</var> (<var>1 \leq i \leq N</var>), Item <var>i</var> has a weight of <var>w_i</var> and a value of <var>v_i</var>.</p>
<p>Taro has decided to choose some of the <var>N</var> items and carry them home in a knapsack.
The capacity of the knapsack is <var>W</var>, which means that the sum of the weights of items taken must be at most <var>W</var>.</p>
<p>Find the maximum possible sum of the values of items that Taro takes home.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq W \leq 10^9</var></li>
<li><var>1 \leq w_i \leq W</var></li>
<li><var>1 \leq v_i \leq 10^3</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>W</var>
<var>w_1</var> <var>v_1</var>
<var>w_2</var> <var>v_2</var>
<var>:</var>
<var>w_N</var> <var>v_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the values of items that Taro takes home.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 8
3 30
4 50
5 60
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>90
</pre>
<p>Items <var>1</var> and <var>3</var> should be taken.
Then, the sum of the weights is <var>3 + 5 = 8</var>, and the sum of the values is <var>30 + 60 = 90</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 1000000000
1000000000 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 15
6 5
5 6
6 4
6 6
3 5
7 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>17
</pre>
<p>Items <var>2, 4</var> and <var>5</var> should be taken.
Then, the sum of the weights is <var>5 + 6 + 3 = 14</var>, and the sum of the values is <var>6 + 6 + 5 = 17</var>.</p></section>
</div>
</span> |
p01159 |
<H1><font color="#000">Problem E:</font> Autocorrelation Function</H1>
<p>
Nathan O. Davis is taking a class of signal processing as a student in engineering. Todayâs topic of the
class was autocorrelation. It is a mathematical tool for analysis of signals represented by functions or
series of values. Autocorrelation gives correlation of a signal with itself. For a continuous real function
<i>f</i>(<i>x</i>), the autocorrelation function <i>R<sub>f</sub></i> (<i>r</i>) is given by
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_autocorrelation1">
</center>
<p>
where <i>r</i> is a real number.
</p>
<p>
The professor teaching in the class presented an assignment today. This assignment requires students
to make plots of the autocorrelation functions for given functions. Each function is piecewise linear and
continuous for all real numbers. The figure below depicts one of those functions.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_autocorrelation2">
<p>
Figure 1: An Example of Given Functions
</p>
</center>
<p>
The professor suggested use of computer programs, but unfortunately Nathan hates programming. So he
calls you for help, as he knows you are a great programmer. You are requested to write a program that
computes the value of the autocorrelation function where a function <i>f</i>(<i>x</i>) and a parameter <i>r</i> are given as
the input. Since he is good at utilization of existing software, he could finish his assignment with your
program.
</p>
<H2>Input</H2>
<p>
The input consists of a series of data sets.
</p>
<p>
The first line of each data set contains an integer <i>n</i> (3 ≤ <i>n</i> ≤ 100) and a real number <i>r</i> (-100 ≤ <i>r</i> ≤ 100),
where n denotes the number of endpoints forming sub-intervals in the function <i>f</i>(<i>x</i>), and <i>r</i> gives the
parameter of the autocorrelation function <i>R<sub>f</sub></i>(<i>r</i>). The <i>i</i>-th of the following <i>n</i> lines contains two integers
<i>x<sub>i</sub></i> (-100 ≤ <i>x<sub>i</sub></i> ≤ 100) and <i>y<sub>i</sub></i> (-50 ≤ <i>y<sub>i</sub></i> ≤ 50), where (<i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> ) is the coordinates of the <i>i</i>-th endpoint.
The endpoints are given in increasing order of their <i>x</i>-coordinates, and no couple of endpoints shares the
same <i>x</i>-coordinate value. The <i>y</i>-coordinates of the first and last endpoints are always zero.
</p>
<p>
The end of input is indicated by <i>n</i> = <i>r</i> = 0. This is not part of data sets, and hence should not be
processed.
</p>
<H2>Output</H2>
<p>
For each data set, your program should print the value of the autocorrelation function in a line. Each
value may be printed with an arbitrary number of digits after the decimal point, but should not contain
an error greater than 10<sup>-4</sup> .
</p>
<H2>Sample Input</H2>
<pre>
3 1
0 0
1 1
2 0
11 1.5
0 0
2 7
5 3
7 8
10 -5
13 4
15 -1
17 3
20 -7
23 9
24 0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0.166666666666667
165.213541666667
</pre>
|
p03534 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has a string <var>S</var> consisting of three kinds of letters: <code>a</code>, <code>b</code> and <code>c</code>.</p>
<p>He has a phobia for palindromes, and wants to permute the characters in <var>S</var> so that <var>S</var> will not contain a palindrome of length <var>2</var> or more as a substring. Determine whether this is possible.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 10^5</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>If the objective is achievable, print <code>YES</code>; if it is unachievable, print <code>NO</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abac
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>As it stands now, <var>S</var> contains a palindrome <code>aba</code>, but we can permute the characters to get <code>acba</code>, for example, that does not contain a palindrome of length <var>2</var> or more.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>aba
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>babacccabab
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre></section>
</div>
</span> |
p01509 |
<H1>PLAY in BASIC</H1>
<p>
One sunny day, Dick T. Mustang found an ancient personal computer in the closet.
He brought it back to his room and turned it on with a sense of nostalgia, seeing a message coming on the screen:
</p>
<pre>
READY?
</pre>
<p>
Yes. BASIC.
</p>
<p>
BASIC is a programming language designed for beginners, and was widely used from 1980's to 1990's.
There have been quite a few BASIC dialects.
Some of them provide the PLAY statement, which plays music when called with a string of a musical score written in Music Macro Language (MML).
Dick found this statement is available on his computer and accepts the following commands in MML:
</p>
<dl>
<dt>Notes: Cn, C+n, C-n, Dn, D+n, D-n, En,...,... (n = 1,2,4,8,16,32,64,128 + dots)</dt><dd>
<p>Each note command consists of a musical note followed by a duration specifier.</p>
<p>Each musical note is one of the seven basic notes: 'C', 'D', 'E', 'F', 'G', 'A', and 'B'. It can be followed by either '+' (indicating a sharp) or '-' (a flat). The notes 'C' through 'B' form an octave as depicted in the figure below. The octave for each command is determined by the current octave, which is set by the octave commands as described later. It is not possible to play the note 'C-' of the lowest octave (1) nor the note 'B+' of the highest octave (8).</p>
<p>Each duration specifier is basically one of the following numbers: '1', '2', '4', '8', '16', '32', '64', and '128', where '1' denotes a whole note, '2' a half note, '4' a quarter note, '8' an eighth note, and so on. This specifier is <i>optional</i>; when omitted, the duration will be the default one set by the L command (which is described below). In addition, duration specifiers can contain <i>dots</i> next to the numbers. A dot adds the half duration of the basic note. For example, '4.' denotes the duration of '4' (a quarter) plus '8' (an eighth, i.e. half of a quarter), or as 1.5 times long as '4'. It is possible that a single note has more than one dot, where each extra dot extends the duration by half of the previous one. For example, '4..' denotes the duration of '4' plus '8' plus '16', '4...' denotes the duration of '4' plus '8' plus '16' plus '32', and so on. The duration extended by dots cannot be shorter than that of '128' due to limitation of Dick's computer; therefore neither '128.' nor '32...' will be accepted. The dots specified without the numbers extend the default duration. For example, 'C.' is equivalent to 'C4.' when the default duration is '4'. Note that 'C4C8' and 'C4.' are <i>unequivalent</i>; the former contains two distinct notes, while the latter just one note.</p></dd>
<dt>Rest: Rn (n = 1,2,4,8,16,32,64,128 + dots)</dt><dd>
<p>The R command rests for the specified duration. The duration should be specified in the same way as the note commands, and it can be omitted, too. Note that 'R4R8' and 'R4.' are <i>equivalent</i>, unlike 'C4C8' and 'C4.', since the both rest for the same duration of '4' plus '8'.</p></dd>
<dt>Octave: On (n = 1-8), <, ></dt><dd>
<p>The O command sets the current octave to the specified number. '>' raises one octave up, and '<' drops one down. It is not allowed to set the octave beyond the range from 1 to 8 by these commands. The octave is initially set to 4.</p></dd>
<dt>Default duration: Ln (n = 1,2,4,8,16,32,64,128)</dt><dd>
<p>The L command sets the default duration. The duration should be specified in the same way as the note commands, but <i>cannot be omitted nor followed by dots</i>. The default duration is initially set to 4.</p></dd>
<dt>Volume: Vn (n = 1-255)</dt><dd>
<p>The V command sets the current volume. Larger is louder. The volume is initially set to 100.</p></dd>
</dl>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_music2" height="192" width="570">
</center>
<p>
As an amateur composer, Dick decided to play his pieces of music by the PLAY statement.
He managed to write a program with a long MML sequence, and attempted to run the program to play his music -- but unfortunately he encountered an unexpected error: the MML sequence was too long to be handled in his computer's small memory!
</p>
<p>
Since he didn't want to give up all the efforts he had made to use the PLAY statement, he decided immediately to make the MML sequence shorter so that it fits in the small memory.
It was too hard for him, though.
So he asked you to write a program that, for each given MML sequence, prints the shortest MML sequence (i.e. MML sequence containing minimum number of characters) that expresses the same music as the given one.
Note that the final values of octave, volume, and default duration can be differrent from the original MML sequence.
</p>
<H2>Input</H2>
<p>
The input consists of multiple data sets. Each data set is given by a single line that contains an MML sequence up to 100,000 characters.
All sequences only contain the commands described above.
Note that each sequence contains at least one note, and there is no rest before the first note and after the last note.
</p>
<p>
The end of input is indicated by a line that only contains "*".
This is not part of any data sets and hence should not be processed.
</p>
<H2>Output</H2>
<p>
For each test case, print its case number and the shortest MML sequence on a line.
</p>
<p>
If there are multiple solutions, print any of them.
</p>
<H2>Sample Input</H2>
<pre>
C4C4G4G4A4A4G2F4F4E4E4D4D4C2
O4C4.C8F4.F8G8F8E8D8C2
B-8>C8<B-8V40R2R..R8.V100EV50L1CG
*
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1: CCGGAAG2FFEEDDC2
Case 2: C.C8F.L8FGFEDC2
Case 3: L8B-B+B-RL1RE4V50CG
</pre>
|
p00748 |
<h1><font color="#000000">Problem C:</font> Pollock's conjecture</h1>
<!-- begin en only -->
<p>
The <I>n</I>th triangular number is
defined as
the sum of the first <I>n</I> positive integers.
The <I>n</I>th tetrahedral number is
defined as
the sum of the first <I>n</I> triangular numbers.
It is easy to show that
the <I>n</I>th tetrahedral number is equal to
<I>n</I>(<I>n</I>+1)(<I>n</I>+2) ⁄ 6.
For example,
the 5th tetrahedral number is
1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+5)
= 5×6×7 ⁄ 6
= 35.
</p>
<!-- end en only -->
<dl>
<dt>
<!-- begin en only -->
The first 5 triangular numbers
<!-- end en only -->
1, 3, 6, 10, 15
</dt>
<dd>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-11" alt="Tr[1]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-12" alt="Tr[2]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-13" alt="Tr[3]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-14" alt="Tr[4]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-15" alt="Tr[5]" align="top">
</dd>
<dt>
<!-- begin en only -->
The first 5 tetrahedral numbers
<!-- end en only -->
1, 4, 10, 20, 35
</dt>
<dd>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-1" alt="Tet[1]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-2" alt="Tet[2]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-3" alt="Tet[3]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-4" alt="Tet[4]" align="top">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_C-5" alt="Tet[5]" align="top">
</dd>
</dl>
<!-- begin en only -->
<p>
In 1850,
Sir Frederick Pollock, 1st Baronet,
who was not a professional mathematician
but a British lawyer and Tory (currently known as Conservative) politician,
conjectured
that every positive integer can be represented
as the sum of at most five tetrahedral numbers.
Here,
a tetrahedral number may occur in the sum more than once
and,
in such a case, each occurrence is counted separately.
The conjecture has been open for more than one and a half century.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Your mission is to write a program
to verify Pollock's conjecture for individual integers.
Your program should make a calculation of
the least number of tetrahedral numbers
to represent each input integer as their sum.
In addition,
for some unknown reason,
your program should make a similar calculation
with only odd tetrahedral numbers available.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
For example,
one can represent 40 as the sum of 2 tetrahedral numbers,
4×5×6 ⁄ 6 + 4×5×6 ⁄ 6,
but 40 itself is not a tetrahedral number.
One can represent 40 as the sum of 6 odd tetrahedral numbers,
5×6×7 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6 + 1×2×3 ⁄ 6,
but cannot represent as the sum of fewer odd tetrahedral numbers.
Thus, your program should report 2 and 6 if 40 is given.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input is a sequence of lines each of which contains a single positive integer less than 10<sup>6</sup>.
The end of the input is indicated by a line containing a single zero.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each input positive integer,
output a line containing two integers separated by a space.
The first integer should be
the least number of tetrahedral numbers
to represent the input integer as their sum.
The second integer should be
the least number of odd tetrahedral numbers
to represent the input integer as their sum.
No extra characters should appear in the output.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
40
14
5
165
120
103
106
139
0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
2 6
2 14
2 5
1 1
1 18
5 35
4 4
3 37
</pre>
|
p02775 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>In the Kingdom of AtCoder, only banknotes are used as currency. There are <var>10^{100}+1</var> kinds of banknotes, with the values of <var>1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}</var>. You have come shopping at a mall and are now buying a takoyaki machine with a value of <var>N</var>. <em>(Takoyaki is the name of a Japanese snack.)</em></p>
<p>To make the payment, you will choose some amount of money which is at least <var>N</var> and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus <var>N</var>.</p>
<p>What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count?</p>
<p>Assume that you have sufficient numbers of banknotes, and so does the clerk.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>N</var> is an integer between <var>1</var> and <var>10^{1,000,000}</var> (inclusive).</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the minimum possible number of total banknotes used by you and the clerk.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>36
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>If you give four banknotes of value <var>10</var> each, and the clerk gives you back four banknotes of value <var>1</var> each, a total of eight banknotes are used.</p>
<p>The payment cannot be made with less than eight banknotes in total, so the answer is <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>91
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>If you give two banknotes of value <var>100, 1</var>, and the clerk gives you back one banknote of value <var>10</var>, a total of three banknotes are used.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>243
</pre></section>
</div>
</span> |
p03867 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Aoki are going to together construct a sequence of integers.</p>
<p>First, Takahashi will provide a sequence of integers <var>a</var>, satisfying all of the following conditions:</p>
<ul>
<li>The length of <var>a</var> is <var>N</var>.</li>
<li>Each element in <var>a</var> is an integer between <var>1</var> and <var>K</var>, inclusive.</li>
<li><var>a</var> is a <em>palindrome</em>, that is, reversing the order of elements in <var>a</var> will result in the same sequence as the original.</li>
</ul>
<p>Then, Aoki will perform the following operation an arbitrary number of times:</p>
<ul>
<li>Move the first element in <var>a</var> to the end of <var>a</var>.</li>
</ul>
<p>How many sequences <var>a</var> can be obtained after this procedure, modulo <var>10^9+7</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€Nâ€10^9</var></li>
<li><var>1â€Kâ€10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the sequences <var>a</var> that can be obtained after the procedure, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>The following six sequences can be obtained:</p>
<ul>
<li><var>(1, 1, 1, 1)</var></li>
<li><var>(1, 1, 2, 2)</var></li>
<li><var>(1, 2, 2, 1)</var></li>
<li><var>(2, 2, 1, 1)</var></li>
<li><var>(2, 1, 1, 2)</var></li>
<li><var>(2, 2, 2, 2)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>75
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1000000000 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>875699961
</pre></section>
</div>
</span> |
p00318 |
<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>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_hibara" width="700">
</center>
<br/>
<p>
äžå³ã®ãããªçŽç·ã§è¡šãããæµ·å²žç·äžã«èŠ³æž¬ç¹ãèšçœ®ããæ¢æ»ã¬ãŒãã眮ããæ¢æ»ã¬ãŒãã§ã¯ã芳枬ç¹ãäžå¿ãšããããã倧ããã®ååã®ç¯å²ã«éºè·¡ããããšããããšããããããªããããããè€æ°ã®èŠ³æž¬ããŒã¿ãçµã¿åãããããšã§ãããçãç¯å²ã«çµã蟌ãããšãã§ããã
</p>
<p>
芳枬ç¹ã®äœçœ®ã𿢿»ã¬ãŒãã瀺ãååŸãããªãããã€ãã®èŠ³æž¬ããŒã¿ãäžãããããšããæµ·å²žç·ããæå€§ã§ã©ã®ãããã®è·é¢ãŸã§èª¿æ»ããå¿
èŠãããããæ±ããããã°ã©ã ãäœæããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var>
<var>x<sub>1</sub></var> <var>r<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>r<sub>2</sub></var>
:
<var>x<sub>N</sub></var> <var>r<sub>N</sub></var>
</pre>
<p>
ïŒè¡ç®ã«æ¢æ»ã¬ãŒãã«ãã£ãŠæž¬å®ãããããŒã¿ã®æ° <var>N</var> (1 ≤ <var>N</var> ≤ 100000) ãäžãããããç¶ã <var>N</var> è¡ã«ã芳枬ããŒã¿ <var>i</var> ã®æµ·å²žç·äžã§ã®äœçœ®ãã¡ãŒãã«åäœã§è¡šãæŽæ° <var>x<sub>i</sub></var> (0 ≤ <var>x<sub>i</sub></var> ≤ 1,000,000) ãšããã®äœçœ®ããååŸäœã¡ãŒãã«ä»¥å
ã«éºè·¡ãååšããããè¡šãæŽæ° <var>r<sub>i</sub></var> (1 ≤ <var>r<sub>i</sub></var> ≤ 1,000,000) ãäžããããã芳枬ç¹ãåã芳枬ããŒã¿ãïŒã€ä»¥äžäžããããããšãããã
</p>
<p>
äžãããã芳枬ããŒã¿ãè€æ°ã®å Žåãããããã¹ãŠã®ååã«å«ãŸããç¹ãå¿
ãååšãããšèããŠããã
</p>
<h2>Output</h2>
<p>
海岞ç·ããæå€§ã§äœã¡ãŒãã«ãŸã§èª¿æ»ããå¿
èŠããããã宿°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 0.001 ã¡ãŒãã«ãè¶
ããŠã¯ãªããªãããã®æ¡ä»¶ãæºããã°å°æ°ç¹ä»¥äžã¯äœæ¡è¡šç€ºããŠãããã
</p>
<h2>Sample Input 1</h2>
<pre>
2
0 2
1 2
</pre>
<h2>Sample Output 1</h2>
<pre>
1.936
</pre>
<br/>
<h2>Sample Input 2</h2>
<pre>
3
0 3
1 2
2 1
</pre>
<h2>Sample Output 2</h2>
<pre>
1.0
</pre>
<br/>
<h2>Sample Input 3</h2>
<pre>
2
0 1
3 2
</pre>
<h2>Sample Output 3</h2>
<pre>
0.0
</pre> |
p02325 |
<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>Bitonic Traveling Salesman Problem (Bitonic TSP)</H1>
<p>
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria:
</p>
<ul>
<li>Visit the points according to the following steps:
<ol>
<li>It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point). </li>
<li>Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point.</li>
</ol>
</li>
<li>Through the processes 1. 2., the tour must visit each point at least once.</li>
</ul>
<h2>Input</h2>
<p>The input data is given in the following format:</p>
<p>
$N$<br>
$x_1$ $y_1$<br>
$x_2$ $y_2$<br>
...<br>
$x_N$ $y_N$<br>
</p>
<h2>Constraints</h2>
<ul>
<li> $2 \leq N \leq 1000$ </li>
<li> $-1000 \leq x_i, y_i \leq 1000$</li>
<li> $x_i$ differ from each other</li>
<li> The given points are already sorted by x-coordinates</li>
</ul>
<h2>Output</h2>
<p>
Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001.
</p>
<h2>Sample Input 1</h2>
<pre>
3
0 0
1 1
2 0
</pre>
<h2>Sample Output 1</h2>
<pre>
4.82842712
</pre>
<h2>Sample Input 2</h2>
<pre>
4
0 1
1 2
2 0
3 1
</pre>
<h2>Sample Output 2</h2>
<pre>
7.30056308
</pre>
<h2>Sample Input 3</h2>
<pre>
5
0 0
1 2
2 1
3 2
4 0
</pre>
<h2>Sample Output 3</h2>
<pre>
10.94427191
</pre>
|
p00436 |
<H1>ã«ãŒãã®äžŠã³æ¿ã</H1>
<h2>åé¡</h2>
<p>
1 ãã 2n ã®æ°ãæžããã 2n æã®ã«ãŒããããïŒäžãã 1, 2, 3, ... , 2n ã®é ã«ç©ã¿éãªã£ãŠããïŒ
</p>
<p>
ãã®ã«ãŒããïŒæ¬¡ã®æ¹æ³ãäœåãçšããŠäžŠã¹æ¿ããïŒ
</p>
<p>
<b>æŽæ° k ã§ã«ãã</b><br>
äžãã k æã®ã«ãŒãã®å±± A ãš æ®ãã®ã«ãŒãã®å±± B ã«åããåŸïŒ å±± A ã®äžã«å±± B ãã®ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card01">
</center>
<br/>
<p>
<b>ãªãã«ã·ã£ããã«</b><br>
äžãã n æã®å±± A ãšæ®ãã®å±± B ã«åãïŒ äžãã A ã®1æç®ïŒ B ã®1æç®ïŒ A ã®2æç®ïŒ B ã®2æç®ïŒ âŠïŒ A ã® næç®ïŒ B ã® næç®ïŒ ãšãªãããã«ããŠïŒ 1 ã€ã®å±±ã«ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card02">
</center>
<br/>
<p>
å
¥å<!--ãã¡ã€ã«-->ã®æç€ºã«åŸãïŒã«ãŒããäžŠã³æ¿ããããšã®ã«ãŒãã®çªå·ãïŒäžããé çªã«åºåããããã°ã©ã ãäœæããïŒ
</p>
<H2>å
¥å</H2>
<ul>
<li> 1 è¡ç®ã«ã¯ n ïŒ1 ⊠n ⊠100ïŒãæžãããŠããïŒ ããªãã¡ã«ãŒãã®ææ°ã¯ 2n æã§ããïŒ</li>
<li> 2 è¡ç®ã«ã¯æäœã®åæ° m ïŒ1 ⊠m ⊠1000ïŒãæžãããŠããïŒ</li>
<li> 3 è¡ç®ãã m + 2 è¡ç®ãŸã§ã® m è¡ã«ã¯ïŒ 0 ãã 2n-1 ãŸã§ã®ãããã 1 ã€ã®æŽæ° k ãæžãããŠããïŒ ã«ãŒããäžŠã¹æ¿ããæ¹æ³ãé ã«æå®ããŠããïŒ
<ul>
<li> k = 0 ã®å Žåã¯ïŒ ãªãã«ã·ã£ããã«ãè¡ãïŒ</li>
<li> 1 ⊠k ⊠2n-1 ã®å Žåã¯ïŒ k ã§ã«ãããè¡ãïŒ </li>
</ul>
</li>
</ul>
<H2>åºå</H2>
<p>
<!--2n è¡ãããªããåºåãã¡ã€ã«ãæåºããïŒ-->åºåã¯2n è¡ãããªãïŒ 1 è¡ç®ã«ã¯äžŠã¹æ¿ãçµäºåŸã®äžçªäžã®ã«ãŒãã®çªå·ïŒ 2 è¡ç®ã«ã¯äžŠã¹æ¿ãçµäºåŸã®äžãã 2 çªç®ã®ã«ãŒãã®çªå·ãšããããã«ïŒ i è¡ç®ã«ã¯äžãã i çªç®ã®ã«ãŒãã®çªå·ãåºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
2
2
1
0
</pre>
<h3>åºåäŸ 1</h3>
<pre>
2
4
3
1
</pre>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
3
4
2
4
0
0
</pre>
<h3>åºåäŸ 2</h3>
<pre>
1
5
4
3
2
6
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div> |
p00066 |
<H1>äžç®äžŠã¹</H1>
<p>
äžç®äžŠã¹ã¯ïŒïŒ × ïŒã®ãã¹ç®ã®äžã«äº€äºã« â ãš Ã ãå
¥ããŠãããçžŠã»æšªã»æãã®äœããã«äžå â ã à ã䞊ãã ãšãã«ãåã¡ãšãªãã²ãŒã ã§ãïŒå³1ãå³3 ãåç
§ïŒ
</p>
<center>
<table>
<tr>
<td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic1"></td>
<td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic2"></td>
<td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic3"></td>
</tr>
<tr>
<td>å³ïŒïŒâã®åã¡</td>
<td>å³ïŒïŒÃ ã®åã¡</td>
<td>å³ïŒïŒåŒãåã</td>
</tr>
</table>
</center>
<br/>
<p>
äžç®äžŠã¹ã¯ãâãšÃã亀äºã«ãã¹ç®ãåããŠãããã©ã¡ãããäžåæã£ããšãã«ã²ãŒã çµäºãšãªããŸãããã®ãããå³ 4 ã®ããã«ãâãšÃãäž¡æ¹ãšãäžåããã£ãŠããå Žåã¯ããããªãå±é¢ã§ããããããªãå±é¢ãå
¥åãããããšã¯ãããŸããã
</p>
<center>
<table>
<tr>
<td width="140"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic4"></td>
</tr>
<tr>
<td>å³ïŒïŒããããªãå±é¢</td>
</tr>
</table>
</center>
<br/>
<p>
äžç®äžŠã¹ã®ç€é¢ãèªã¿èŸŒãã§ãåæã®çµæãåºåããããã°ã©ã ãäœæããŠäžããã
</p>
<H2>Input</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸããåããŒã¿ã»ãããšããŠãç€é¢ã衚ãïŒã€ã®æååãïŒè¡ã«äžããããŸãã
ç€é¢ã®æååã¯ãâãÃã空çœãããããåè§è±å°æåã® oãxãs ã§ãããããäžå³ã®ãã¹ç®ã®é ã«äžŠãã§ããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tic5">
</center>
<br/>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ãâãåã¡ãªãåè§è±å°æåã® o ããÃãåã¡ãªãåè§è±å°æåã® x ããåŒãåããªãã°åè§è±å°æåã® d ãïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
ooosxssxs
xoosxsosx
ooxxxooxo
</pre>
<H2>Output for the Sample Input</H2>
<pre>
o
x
d
</pre>
|
p04025 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Evi has <var>N</var> integers <var>a_1,a_2,..,a_N</var>. His objective is to have <var>N</var> equal <strong>integers</strong> by transforming some of them.</p>
<p>He may transform each integer at most once. Transforming an integer <var>x</var> into another integer <var>y</var> costs him <var>(x-y)^2</var> dollars. Even if <var>a_i=a_j (iâ j)</var>, he has to pay the cost separately for transforming each of them (See Sample 2).</p>
<p>Find the minimum total cost to achieve his objective.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ100</var></li>
<li><var>-100âŠa_iâŠ100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> ... <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum total cost to achieve Evi's objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
4 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>Transforming the both into <var>6</var>s will cost <var>(4-6)^2+(8-6)^2=8</var> dollars, which is the minimum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3
</pre>
<p>Transforming the all into <var>2</var>s will cost <var>(1-2)^2+(1-2)^2+(3-2)^2=3</var> dollars. Note that Evi has to pay <var>(1-2)^2</var> dollar separately for transforming each of the two <var>1</var>s.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
4 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre>
<p>Leaving the <var>4</var> as it is and transforming the <var>2</var> and the <var>5</var> into <var>4</var>s will achieve the total cost of <var>(2-4)^2+(5-4)^2=5</var> dollars, which is the minimum.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>4
-100 -100 -100 -100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre>
<p>Without transforming anything, Evi's objective is already achieved. Thus, the necessary cost is <var>0</var>.</p></section>
</div>
</span> |
p01227 |
<h1><font color="#000">Problem E:</font> ã«ã³ããªãŒããŒã</h1>
<p>
ããéçå°åã§ã®è©±ã§ããïŒ
ãã®å°åã§ã¯ã«ã³ããªãŒããŒããšåŒã°ãããŸã£ãããªéã«æ²¿ã£ãŠïŒ
å®¶ããŸã°ãã«å»ºã£ãŠããïŒ
ä»ãŸã§ãã®å°åã«ã¯é»æ°ãéã£ãŠããªãã£ãã®ã ãïŒ
ä»åæ¿åºããããã€ãã®çºé»æ©ãäžããããããšã«ãªã£ãïŒ
çºé»æ©ã¯å¥œããªãšããã«èšçœ®ã§ãããïŒ
å®¶ã«é»æ°ãäŸçµŠãããã«ã¯ã©ããã®çºé»æ©ã«é»ç·ãä»ããŠã€ãªãã£ãŠããªããã°ãªããïŒ
é»ç·ã«ã¯é·ãã«æ¯äŸããã³ã¹ããçºçããïŒ
å°åã§å¯äžã®æè¡ç³»å
¬åå¡ã§ããããªãã®ä»äºã¯ïŒ
ãã¹ãŠã®å®¶ã«é»æ°ãäŸçµŠããããšããæ¡ä»¶ã®äžã§ïŒ
ã§ããã ãé»ç·ã®é·ãã®ç·èšãçããªããããªçºé»æ©
ããã³é»ç·ã®é
çœ®ãæ±ããããšã§ããïŒ
ãªãïŒçºé»æ©ã®å®¹éã¯ååã«å€§ããã®ã§ïŒ
ãããã§ãå€ãã®å®¶ã«é»æ°ãäŸçµŠããããšãã§ãããã®ãšããïŒ
</p>
<p>
ãµã³ãã«å
¥åã®1çªç®ã®ããŒã¿ã»ãããå³2ã«ç€ºãïŒ
ãã®åé¡ã«å¯Ÿããæé©ãªé
眮ãäžããã«ã¯ïŒ
å³ã®ããã« <var>x</var> = 20 ãš <var>x</var> = 80 ã®äœçœ®ã«çºé»æ©ãé
眮ãïŒ
ããããå³äžã®ã°ã¬ãŒã§ç€ºããäœçœ®ã«é»ç·ãåŒãã°ããïŒ
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_road"
alt="çºé»æ©ãšé»ç·ã®é
眮ã®äŸïŒå
¥åäŸã®æåã®ããŒã¿ã»ããïŒïŒ">
</td>
</tr>
<tr>
<td>å³2: çºé»æ©ãšé»ç·ã®é
眮ã®äŸïŒå
¥åäŸã®æåã®ããŒã¿ã»ããïŒïŒ</td>
</tr>
</table>
</center>
<h2>Input</h2>
<p>
å
¥åã®1è¡ç®ã«ã¯ããŒã¿ã»ããã®åæ° <var>t</var>
(0 < <var>t</var> ≤ 50) ãäžããããïŒ
</p>
<p>
åŒãç¶ã <var>t</var> åã®ããŒã¿ã»ãããäžããããïŒ
ããŒã¿ã»ããã¯ããããæ¬¡ã®ãããªåœ¢åŒã§2è¡ã§äžããããïŒ
</p>
<pre>
<var>n</var> <var>k</var>
<var>x</var><sub>1</sub> <var>x</var><sub>2</sub> ... <var>x</var><sub><var>n</var></sub>
</pre>
<p>
<var>n</var> ã¯å®¶ã®æžæ°ïŒ<var>k</var> ã¯çºé»æ©ã®åæ°ã§ããïŒ
<var>x</var><sub>1</sub>, <var>x</var><sub>2</sub>, ...,
<var>x</var><sub><var>n</var></sub>
ã¯ããããå®¶ã®äœçœ®ã衚ãäžæ¬¡å
座æšã§ããïŒ
ãããã®å€ã¯ãã¹ãп޿°ã§ããïŒ
0 < <var>n</var> ≤ 100000,
0 < <var>k</var> ≤ 100000,
0 ≤ <var>x</var><sub>1</sub> < <var>x</var><sub>2</sub> <
... < <var>x</var><sub><var>n</var></sub> ≤ 1000000
ãæºããïŒ
</p>
<p>
ããã«ïŒããŒã¿ã»ããã®ãã¡ 90% ã¯ïŒ
0 < <var>n</var> ≤ 100, 0 < <var>k</var> ≤ 100 ãæºãããŠããïŒ
</p>
<h2>Output</h2>
<p>
åããŒã¿ã»ããã«å¯ŸãïŒ
å¿
èŠãªé»ç·ã®é·ãã®ç·èšã®æå°å€ã1è¡ã«åºåããïŒ
</p>
<h2>Sample Input</h2>
<pre>
6
5 2
10 30 40 70 100
7 3
3 6 10 17 21 26 28
1 1
100
2 1
0 1000000
3 5
30 70 150
6 4
0 10 20 30 40 50
</pre>
<h2>Output for the Sample Input</h2>
<pre>
60
13
0
1000000
0
20
</pre>
|
p02958 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a sequence <var>p</var> = {<var>p_1,\ p_2,\ ...,\ p_N</var>} which is a permutation of {<var>1,\ 2,\ ...,\ N</var>}.</p>
<p>You can perform the following operation at most once: choose integers <var>i</var> and <var>j</var> <var>(1 \leq i < j \leq N)</var>, and swap <var>p_i</var> and <var>p_j</var>. Note that you can also choose not to perform it.</p>
<p>Print <code>YES</code> if you can sort <var>p</var> in ascending order in this way, and <code>NO</code> otherwise.</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 50</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 <code>YES</code> if you can sort <var>p</var> in ascending order in the way stated in the problem statement, and <code>NO</code> otherwise.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
5 2 3 4 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
</pre>
<p>You can sort <var>p</var> in ascending order by swapping <var>p_1</var> and <var>p_5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
2 4 3 5 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>NO
</pre>
<p>In this case, swapping any two elements does not sort <var>p</var> in ascending order.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7
1 2 3 4 5 6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>YES
</pre>
<p><var>p</var> is already sorted in ascending order, so no operation is needed.</p></section>
</div>
</span> |
p00965 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script>
<h2>Problem I
Starting a Scenic Railroad Service
</h2>
<p>
Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a scenic valley will arise a big boom, but not quite sure how big the boom will be.
</p>
<p>
A market survey was ordered and Jim has just received an estimated list of passengers' travel sections. Based on the list, he'd like to estimate the minimum number of train seats that meets the demand.
</p>
<p>
Providing as many seats as all of the passengers may cost unreasonably high. Assigning the same seat to more than one passenger without overlapping travel sections may lead to a great cost cutback.
</p>
<p>
Two different policies are considered on seat assignments. As the views from the train windows depend on the seat positions, it would be better if passengers can choose a seat. One possible policy (named `policy-1') is to allow the passengers to choose an arbitrary seat among all the remaining seats when they make their reservations. As the order of reservations is unknown, all the possible orders must be considered on counting the required number of seats.
</p>
<p>
The other policy (named `policy-2') does not allow the passengers to choose their seats; the seat assignments are decided by the railroad operator, not by the passengers, after all the reservations are completed. This policy may reduce the number of the required seats considerably.
</p>
<p>
Your task is to let Jim know how dierent these two policies are by providing him a program that computes the numbers of seats required under the two seat reservation policies. Let us consider a case where there are four stations, S1, S2, S3, and S4, and four expected passengers $p_1$, $p_2$, $p_3$, and $p_4$ with the travel list below.
</p>
<center>
<table>
<tr>
<th width="120">passenger</th>
<th width="120">from</th>
<th width="120">to</th>
</tr>
<tr>
<td>$p_1$</td>
<td>S1</td>
<td>S2</td>
</tr>
<tr>
<td>$p_2$</td>
<td>S2</td>
<td>S3</td>
</tr>
<tr>
<td>$p_3$</td>
<td>S1</td>
<td>S3</td>
</tr>
<tr>
<td>$p_4$</td>
<td>S3</td>
<td>S4</td>
</tr>
</table>
</center>
<br/>
<p>
The travel sections of $p_1$ and $p_2$ do not overlap, that of $p_3$ overlaps those of $p_1$ and $p_2$, and that of $p_4$ does not overlap those of any others.
</p>
<p>
Let's check if two seats would suffice under the policy-1. If $p_1$ books a seat first, either of the two seats can be chosen. If $p_2$ books second, as the travel section does not overlap that of $p_1$, the same seat can be booked, but the other seat may look more attractive to $p_2$. If $p_2$ reserves a seat different from that of $p_1$, there will remain no available seats for $p_3$ between S1 and S3 (Figure I.1).
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_railroadService1" width="600">
<p>Figure I.1. With two seats</p>
</center>
<p>
With three seats, $p_3$ can find a seat with any seat reservation combinations by $p_1$ and $p_2$. $p_4$ can also book a seat for there are no other passengers between S3 and S4 (Figure I.2).
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_railroadService2" width="600">
<p>Figure I.2. With three seats</p>
</center>
<p>
For this travel list, only three seats suffice considering all the possible reservation orders and seat preferences under the policy-1.
</p>
<p>
On the other hand, deciding the seat assignments after all the reservations are completed enables a tight assignment with only two seats under the policy-2 (Figure I.3).
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2017_railroadService3" width="600">
<p>Figure I.3. Tight assignment to two seats</p>
</center>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$
$a_1$ $b_1$
...
$a_n$ $b_n$
</pre>
<p>
Here, the first line has an integer $n$, the number of the passengers in the estimated list of passengers' travel sections ($1 \leq n \leq 200 000$). The stations are numbered starting from 1 in their order along the route. Each of the following $n$ lines describes the travel for each passenger by two integers, the boarding and the alighting station numbers, $a_i$ and $b_i$, respectively ($1 \leq a_i < b_i \leq 100 000$). Note that more than one passenger in the list may have the same boarding and alighting stations.
</p>
<h3>Output</h3>
<p>
Two integers $s_1$ and $s_2$ should be output in a line in this order, separated by a space. $s_1$ and $s_2$ are the numbers of seats required under the policy-1 and -2, respectively.
</p>
<h3>Sample Input 1</h3>
<pre>
4
1 3
1 3
3 6
3 6
</pre>
<h3>Sample Output 1</h3>
<pre>
2 2
</pre>
<h3>Sample Input 2</h3>
<pre>
4
1 2
2 3
1 3
3 4
</pre>
<h3>Sample Output 2</h3>
<pre>
3 2
</pre>
<h3>Sample Input 3</h3>
<pre>
10
84 302
275 327
364 538
26 364
29 386
545 955
715 965
404 415
903 942
150 402
</pre>
<h3>Sample Output 3</h3>
<pre>
6 5
</pre> |
p01677 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<h3>Problem Statement</h3>
<p>Nathan O. Davis is a student at the department of integrated systems.
</p>
<p>Today's agenda in the class is audio signal processing.
Nathan was given a lot of homework out.
One of the homework was to write a program to process an audio signal.
He copied the given audio signal to his USB memory and brought it back to his home.
</p>
<p>When he started his homework, he unfortunately dropped the USB memory to the floor.
He checked the contents of the USB memory and found that the audio signal data got broken.
</p>
<p>There are several characteristics in the audio signal that he copied.
</p><ul><li><p> The audio signal is a sequence of $N$ samples.
</p></li><li><p> Each sample in the audio signal is numbered from $1$ to $N$ and represented as an integer value.
</p></li><li><p> Each value of the odd-numbered sample(s) is strictly smaller than the value(s) of its neighboring sample(s).
</p></li><li><p> Each value of the even-numbered sample(s) is strictly larger than the value(s) of its neighboring sample(s).
</p></li></ul>
<p>He got into a panic and asked you for a help.
You tried to recover the audio signal from his USB memory but some samples of the audio signal are broken and could not be recovered.
Fortunately, you found from the metadata that all the broken samples have the same integer value.
</p>
<p>Your task is to write a program,
which takes the broken audio signal extracted from his USB memory as its input,
to detect whether the audio signal can be recovered uniquely.
</p>
<h3>Input</h3>
<p>The input consists of multiple datasets.
The form of each dataset is described below.
</p>
<blockquote>$N$<br>$a_{1}$ $a_{2}$ ... $a_{N}$</blockquote>
<p>The first line of each dataset consists of an integer, $N (2 \le N \le 1{,}000)$.
$N$ denotes the number of samples in the given audio signal.
The second line of each dataset consists of $N$ values separated by spaces.
The $i$-th value, $a_{i}$, is either a character <code>x</code> or an integer between $-10^9$ and $10^9$, inclusive.
It represents the $i$-th sample of the broken audio signal.
If $a_{i}$ is a character <code>x</code> , it denotes that $i$-th sample in the audio signal is broken.
Otherwise it denotes the value of the $i$-th sample.
</p>
<p>The end of input is indicated by a single $0$.
This is not included in the datasets.
</p>
<p>You may assume that the number of the datasets does not exceed $100$.
</p>
<h3>Output</h3>
<p>For each dataset, output the value of the broken samples in one line if the original audio signal can be recovered uniquely.
If there are multiple possible values, output <code>ambiguous</code>.
If there are no possible values, output <code>none</code>.
</p>
<h3>Sample Input</h3>
<pre>5
1 x 2 4 x
2
x x
2
1 2
2
2 1
2
1000000000 x
4
x 2 1 x
0</pre>
<h3>Output for the Sample Input</h3>
<pre>3
none
ambiguous
none
ambiguous
none</pre> |
p01362 |
<H1><font color="#000">Problem D:</font> Dice Room</H1>
<p>
You are playing a popular video game which is famous for its depthful story and interesting
puzzles. In the game you were locked in a mysterious house alone and there is no way to call for
help, so you have to escape on yours own. However, almost every room in the house has some
kind of puzzles and you cannot move to neighboring room without solving them.
</p>
<p>
One of the puzzles you encountered in the house is following. In a room, there was a device
which looked just like a dice and laid on a table in the center of the room. Direction was written
on the wall. It read:
</p>
<p>
"This cube is a remote controller and you can manipulate a remote room, Dice
Room, by it. The room has also a cubic shape whose surfaces are made up of 3x3
unit squares and some squares have a hole on them large enough for you to go though
it. You can rotate this cube so that in the middle of rotation at least one edge always
touch the table, that is, to 4 directions. Rotating this cube affects the remote room
in the same way and positions of holes on the room change. To get through the
room, you should have holes on at least one of lower three squares on the front and
back side of the room."
</p>
<p>
You can see current positions of holes by a monitor. Before going to Dice Room, you should
rotate the cube so that you can go though the room. But you know rotating a room takes some
time and you donât have much time, so you should minimize the number of rotation. How many
rotations do you need to make it possible to get though Dice Room?
</p>
<H2>Input</H2>
<p>
The input consists of several datasets. Each dataset contains 6 tables of 3x3 characters which
describe the initial position of holes on each side. Each character is either '<span>*</span>' or '<span>.</span>'. A hole is
indicated by '<span>*</span>'. The order which six sides appears in is: front, right, back, left, top, bottom.
The order and orientation of them are described by this development view:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_diceRoom1">
<p>
Figure 4: Dice Room
</p>
</center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_diceRoom2">
<p>
Figure 5: available dice rotations
</p>
</center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_diceRoom3">
<p>
</p>
</center>
<p>
There is a blank line after each dataset. The end of the input is indicated by a single '<span>#</span>'.
</p>
<H2>Output</H2>
<p>
Print the minimum number of rotations needed in a line for each dataset. You may assume all
datasets have a solution.
</p>
<H2>Sample Input</H2>
<pre>
...
...
.*.
...
...
.*.
...
...
...
...
...
.*.
...
...
.*.
...
...
...
...
.*.
...
*..
...
..*
*.*
*.*
*.*
*.*
.*.
*.*
*..
.*.
..*
*.*
...
*.*
...
.*.
.*.
...
.**
*..
...
...
.*.
.*.
...
*..
..*
...
.**
...
*..
...
#
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
1
0
</pre>
|
p01698 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- begin en only -->
<!--<h3><u>Wish upon a shooting star</u></h3>-->
<!-- end en only -->
<!-- begin ja only -->
<h3><u>æµãæã«é¡ãã</u></h3>
<!-- end ja only -->
<!-- begin en only -->
<!-- end en only -->
<!-- begin ja only -->
<p>è¬ã®çµç¹ JAG (Japanese Alumni Group) ã§ã¯å®æçã«äŒè°ãéããŠããïŒããæ¥ã®è°é¡ã¯ãè¿æ¥è¡ããã ICPC (International Collegiate Programming Contest) åœå
äºéžã§åå ããŒã ãåãçºæ®ã§ããããã«ããã«ã¯ãã§ãã£ãïŒäŒè°ã®çµè«ãšããŠæµãæã«åããŒã ã®å¥éãç¥ãããšã«ãªãïŒåœŒãã¯æ¬éšã眮ã建ç©ã®å±äžã«åºãïŒ
</p>
<p>圌ããå±äžã«åºããšïŒç©ºã«ã¯ $n$ åã®æµãæãèŠããŠããïŒæµãæã¯3次å
空éäžã®çãšããŠè¡šããïŒ$1$ ãã $n$ ã®çªå·ãå²ãæ¯ãããŠããïŒæã«è©³ããã¡ã³ããŒã«ããïŒåæµãæã¯äžå®ã®é床ã§çŽç·çã«ç§»åãããšåæã«ïŒäžå®ã®é床ã§ååŸãå°ãããªã£ãŠãããšã¿ãªããããšãåãã£ãïŒå®éã«æž¬å®ããŠã¿ããšããïŒåæµãæã®åæäœçœ® $(px_i, py_i, pz_i)$ïŒç§»åé床 $(vx_i, vy_i, vz_i)$ïŒåæååŸ $r_i$ïŒæ¶æ»
é床 $vr_i$ ãåãã£ãïŒããã¯æµãæ $i$ ãæå» $t$ ($t \geq 0$) ã§äžå¿åº§æš $(px_i + t vx_i, py_i + t vy_i, pz_i + t vz_i)$ïŒååŸ $r_i - t vr_i$ ã®çãšãªãäºã衚ããŠããïŒæµãæã¯ïŒååŸã 0 ã«ãªã£ãç¬éã«èªç¶æ¶æ»
ããŠããŸãïŒãŸãïŒ2ã€ã®æµãæãæ¥è§Šããå Žåã¯ã©ã¡ãã®æµãæãæ¶æ»
ããŠããŸãïŒ
</p>
<p>ããªãã®ä»äºã¯ïŒå¹çããåå ããŒã ã®å¥éãç¥ãããšãã§ããããã«ïŒåæµãæãæ¶æ»
ãããŸã§ã®æéãæ±ããããšã§ããïŒåœŒãã®äžã«ã¯åè¶ããèŠåã®æã¡äž»ãããããïŒæ
å ±ãäžãããã $n$ å以å€ã«æµãæãååšããå¯èœæ§ã«ã€ããŠã¯èæ
®ããªããŠãè¯ãïŒå ããŠïŒåœŒãã¯éåžžã«å¹çããæµãæã®èŠ³æž¬ãè¡ã£ãããïŒèŠ³æž¬ã«ããã£ãæéã¯ç¡èŠã§ããã»ã©å°ãããšèããŠè¯ãïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æããïŒ1ã€ã®å
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯100以äžã§ããïŒ
åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ
</p>
<blockquote>$n$<br>$px_1$ $py_1$ $pz_1$ $vx_1$ $vy_1$ $vz_1$ $r_1$ $vr_1$<br>...<br>$px_n$ $py_n$ $pz_n$ $vx_n$ $vy_n$ $vz_n$ $r_n$ $vr_n$</blockquote>
<p>$n$ ã¯æµãæã®æ°ãè¡šãæŽæ°ã§ããïŒ$1$ ä»¥äž $200$ 以äžãšä»®å®ããŠè¯ãïŒ
</p>
<p>ç¶ã $n$ è¡ã«ã¯æµãæã®æ
å ±ãäžããããïŒ
åè¡ã¯å°æ°ç¹ä»¥äž4æ¡ã§è¡šããã8ã€ã®å€ãå«ã¿ïŒ$(px_i, py_i, pz_i)$ ã¯æµãæ $i$ ã®åæäœçœ®ãïŒ$(vx_i, vy_i, vz_i)$ ã¯ç§»åé床ãïŒ$r_i$ ã¯åæååŸãïŒ$vr_i$ ã¯æ¶æ»
é床ããããã衚ãïŒ
äžããããå€ã«ã€ããŠïŒ$-1{,}000 \leq px_i \leq 1{,}000$ïŒ$-1{,}000 \leq py_i \leq 1{,}000$ïŒ$-1{,}000 \leq pz_i \leq 1{,}000$ïŒ$-100 \leq vx_i \leq 100$ïŒ $-100 \leq vy_i \leq 100$ïŒ $-100 \leq vz_i \leq 100$ïŒ$1 \leq r_i \leq 100$ïŒ$1 \leq vr_i \leq 100$ ã§ãããšä»®å®ããŠè¯ãïŒ
</p>
<p>ãŸãïŒäžããããããŒã¿ã»ããã«ã€ããŠä»¥äžãä»®å®ããŠè¯ãïŒ
</p><ul><li> ãã1ã€ã®æµãæã®åæååŸã $10^{-8}$ å€åããŠãïŒæ¥è§Šããæã®ãã¢ã®éåã¯å€ãããªã
</li><li> ãã1ã€ã®æµãæãæ¥è§Šã«ããæ¶æ»
ããªããšä»®å®ããŠãïŒ$10^{-8}$ 以å
ã®æéã§2ã€ä»¥äžã®æµãæã«æ¥è§ŠãããïŒä»ã®æµãæãšæ¥è§Šããæå»ãã$10^{-8}$以å
ã«èªç¶æ¶æ»
ããããšã¯ãªã
</li><li> åæç¶æ
ã§ã¯ã©ã®2ã€ã®æµãæãéãªã£ãŠãããïŒ$10^{-8}$以äžã®è·é¢ã空ããŠãã
</li><li> æå» $t < 10^{-8}$ ã§ã¯ã©ã®2ã€ã®æµãæãæ¥è§Šããªã
</li></ul>
<p>$n = 0$ ã¯å
¥åã®çµããã瀺ãïŒããã¯ããŒã¿ã»ããã«ã¯å«ããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«ã€ããŠïŒåæµãæãæ¶æ»
ãããŸã§ã®æéãæµãæ1ããé ã«ãããã1è¡ã«åºåããªããïŒ
</p>
<p>åºåã«ã¯$10^{-8}$ãè¶
ãã絶察誀差ããã£ãŠã¯ãªããªãïŒ
</p>
<p>ãã以å€ã®äœèšãªæåãåºåããŠã¯ãªããªãïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>1
0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 4.0000 1.0000
2
0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 4.0000 1.0000
10.0000 0.0000 0.0000 -2.0000 0.0000 0.0000 4.0000 1.0000
5
-10.0000 0.0000 0.0000 10.0000 0.0000 0.0000 2.0000 1.0000
-5.0000 0.0000 0.0000 10.0000 0.0000 0.0000 2.0000 1.0000
0.0000 0.0000 0.0000 10.0000 0.0000 0.0000 2.0000 1.0000
11.0000 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 100.0000
15.0000 0.0000 0.0000 -10.0000 0.0000 0.0000 2.0000 1.0000
27
-45.6243 -40.4815 42.0513 -0.8380 -6.3628 4.5484 12.0279 2.2721
8.7056 -9.8256 34.1560 6.0068 6.2527 -6.8506 28.9807 1.5037
30.1481 29.9591 -46.2881 6.7611 8.6669 1.5629 14.5578 1.3181
24.2927 8.3779 -21.8931 0.7074 0.1879 -8.9742 5.5877 2.6893
25.3009 -42.9168 10.7480 -7.2477 -8.5507 7.7846 13.7923 2.8726
17.6938 42.3577 -5.0334 6.4949 -2.1472 -5.3101 23.3066 1.4769
-7.9296 -29.6442 -24.2157 -1.1064 -9.5802 6.5858 12.4250 2.3816
9.5851 -20.0455 -35.1885 5.7477 -1.0622 2.5211 3.5233 1.2466
-35.5762 44.5412 -46.7816 3.6053 0.4991 4.3470 20.6922 2.8529
-44.9386 -48.0381 -43.6877 7.4101 3.9491 7.1619 10.4301 2.4920
-49.9870 -28.6276 -2.6522 5.8008 -1.0054 -4.9061 25.1188 1.4916
45.0228 31.3811 29.2546 -8.7777 -3.7836 -7.7180 17.4361 1.8706
35.5553 45.8774 -29.8025 -7.3596 -9.2114 -3.5987 6.8841 2.6143
19.9857 34.3874 42.5551 5.2133 -5.5350 -7.6617 2.9294 1.4026
23.5109 18.1633 -34.8265 7.3260 -4.1912 5.3518 3.0036 1.5027
43.5134 -27.5238 49.4679 -4.5986 1.8410 6.8741 2.2009 1.4525
-28.8994 23.2934 -6.1914 5.7985 -6.2129 -8.2882 16.1683 1.7463
3.6721 38.2528 -38.7741 4.5115 6.6442 6.4406 10.7555 1.0971
17.4488 -12.6965 -23.1293 2.8257 6.3319 -1.5368 7.3785 2.9350
33.2708 -17.9437 -0.5347 8.7428 7.3193 5.9738 6.2292 2.6210
-14.4660 -25.1449 -4.4191 -9.4843 -6.6439 -4.7330 7.7910 2.1659
32.4428 -24.2605 48.1228 -5.2396 1.5916 -5.9552 1.1760 1.3618
-21.9088 43.6286 -8.8286 6.4641 0.5554 -4.6827 1.2504 1.4718
-0.1784 -42.1729 -2.7193 5.3741 0.9098 9.7622 1.4764 1.2611
29.3245 -33.2298 -26.3824 -8.4192 -2.9427 -7.3759 9.6346 1.7490
-35.1767 35.9652 33.4779 4.0088 2.4579 2.0981 19.2565 1.7121
-17.5530 1.4161 -14.0271 6.4564 -4.8261 -8.7461 3.0566 1.5906
0</pre>
<h3>Output for Sample Input</h3>
<pre>4.0000000000
1.0000000000
1.0000000000
2.0000000000
2.0000000000
0.6111111111
0.0100000000
0.6111111111
5.2937370714
0.3931996496
11.0445337986
2.0777525750
4.8013298058
0.0925901184
5.2170809540
2.8263276111
7.2530407655
4.1854333868
0.2348376111
1.0517364512
0.0925901184
1.0517364512
1.9988021561
1.5152495697
9.2586039054
9.8035730562
2.5139693356
2.3766501335
0.2348376111
0.3931996496
0.8495719527
1.1707239711
5.5086335049
11.2472986391
1.9216647806</pre>
|
p00820 |
<H1><font color="#000">Problem B:</font> Lagrange's Four-Square Theorem</H1>
<p>
The fact that any positive integer has a representation as the sum of at most four positive
squares (i.e. squares of positive integers) is known as Lagrangeâs Four-Square Theorem. The
first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission
however is not to explain the original proof nor to discover a new proof but to show that the
theorem holds for some specific numbers by counting how many such possible representations
there are.
</p>
<p>
For a given positive integer n, you should report the number of all representations of n as the
sum of at most four positive squares. The order of addition does not matter, e.g. you should
consider 4<sup>2</sup> + 3<sup>2</sup> and 3<sup>2</sup> + 4<sup>2</sup> are the same representation.
</p>
<p>
For example, letâs check the case of 25. This integer has just three representations 1<sup>2</sup> +2<sup>2</sup> +2<sup>2</sup> +4<sup>2</sup> ,
3<sup>2</sup> + 4<sup>2</sup> , and 5<sup>2</sup> . Thus you should report 3 in this case. Be careful not to count 4<sup>2</sup> + 3<sup>2</sup> and
3<sup>2</sup> + 4<sup>2</sup> separately.
</p>
<H2>Input</H2>
<p>
The input is composed of at most 255 lines, each containing a single positive integer less than
2<sup>15</sup> , followed by a line containing a single zero. The last line is not a part of the input data.
</p>
<H2>Output</H2>
<p>
The output should be composed of lines, each containing a single integer. No other characters
should appear in the output.
</p>
<p>
The output integer corresponding to the input integer <i>n</i> is the number of all representations
of <i>n</i> as the sum of at most four positive squares.
</p>
<H2>Sample Input</H2>
<pre>
1
25
2003
211
20007
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
3
48
7
738
</pre>
|
p01732 |
<p>
Nathan O. Davis is running a company. His company owns a web service which has a lot of users. So his office is full of servers, routers and messy LAN cables.
</p>
<p>He is now very puzzling over the messy cables, because they are causing many kinds of problems. For example, staff working at the company often trip over a cable. No damage if the cable is disconnected. It's just lucky. Computers may fall down and get broken if the cable is connected. He is about to introduce a new computer and a new cable. He wants to minimize staff's steps over the new cable.
</p>
<p>
His office is laid-out in a two-dimensional grid with <var>H \times W</var> cells. The new cable should weave along edges of the cells. Each end of the cable is at a corner of a cell. The grid is expressed in zero-origin coordinates, where the upper left corner is (0, 0).
</p>
<p>
Each staff starts his/her work from inside a certain cell and walks in the office along the grid in a fixed repeated pattern every day. A walking pattern is described by a string of four characters <code>U</code>, <code>D</code>, <code>L</code> and <code>R</code>. <code>U</code> means moving up, <code>D</code> means moving down, <code>R</code> means moving to the right, and <code>L</code> means moving to the left. For example, <code>UULLDDRR</code> means moving up, up, left, left, down, down, right and right in order. The staff repeats the pattern fixed <var>T</var> times. Note that the staff stays in the cell if the staff is going out of the grid through the wall.
</p>
<p>
You have the moving patterns of all staff and the positions of both ends of the new cable. Your job is to find an optimal placement of the new cable, which minimizes the total number his staff would step over the cable.
</p>
<h3>Input</h3>
<p>The first line of the input contains three integers which represent the dimension of the office <var>W</var>, <var>H</var> (<var>1 \leq W, H \leq 500</var>), and the number of staff <var>N</var> (<var>1 \leq N \leq 1000</var>), respectively.
The next line contains two <var>x-y</var> pairs (<var>0 \leq x \leq W</var>, <var>0 \leq y \leq H</var>), which mean the position of two endpoints of a LAN cable to be connected.
These values represents the coordinates of the cells to which the cable is plugged in its top-left corner.
Exceptionally, <var>x = W</var> means the right edge of the rightmost cell, and <var>y = H</var> means the bottom edge of the bottommost cell.
</p>
<p>Following lines describe staff's initial positions and their moving patterns.
The first line includes an <var>x</var>-<var>y</var> pair (<var>0 \leq x \lt W</var>, <var>0 \leq y \lt H</var>), which represents the coordinate of a staff's initial cell.
The next line has an integer <var>T</var> (<var>1 \leq T \leq 100</var>) and a string which consists of <code>U</code>, <code>D</code>, <code>L</code> and <code>R</code>, whose meaning is described as above.
The length of a pattern string is greater than or equal to <var>1</var>, and no more than <var>1,000</var>.
These two lines are repeated <var>N</var> times.
</p>
<h3>Output</h3>
<p>Output the minimum number of times his staff step over the cable in a single line.
</p>
<h3>Sample Input 1</h3>
<pre>3 3 1
1 1 3 3
0 0
1 RRDDLLUU
</pre>
<h3>Output for the Sample Input 1</h3>
<pre>1
</pre>
<h3>Sample Input 2</h3>
<pre>3 3 1
0 0 3 3
0 0
1 RRDDLLUU
</pre>
<h3>Output for the Sample Input 2</h3>
<pre>0
</pre>
<h3>Sample Input 3</h3>
<pre>3 3 1
1 1 3 3
0 0
10 RRDDLLUU
</pre>
<h3>Output for the Sample Input 3</h3>
<pre>10
</pre>
<h3>Sample Input 4</h3>
<pre>3 3 4
1 1 3 3
0 0
10 R
2 0
10 D
2 2
10 L
0 2
10 U
</pre>
<h3>Output for the Sample Input 4</h3>
<pre>1
</pre> |
p00573 | <h1>宿åž(Commuter Pass)</h1>
<p>
JOI åãäœãéœåžã«ã¯<var>N</var> åã®é§
ãããïŒãããã<var>1, 2, ..., N</var> ã®çªå·ãä»ããããŠããïŒãŸãïŒ<var>M</var> æ¬ã®ééè·¯ç·ãããïŒãããã<var>1, 2, ..., M</var> ã®çªå·ãä»ããããŠããïŒééè·¯ç·<var>i</var> (<var>1 \leq i \leq M</var>) ã¯é§
<var>A_i</var> ãšé§
<var>B_i</var> ãåæ¹åã«çµãã§ããïŒä¹è»éè³ã¯<var>C_i</var> åã§ããïŒ
</p>
<p>
JOI åã¯é§
S ã®è¿ãã«äœãã§ããïŒé§
<var>T</var> ã®è¿ãã®IOI 髿 ¡ã«éã£ãŠããïŒãã®ããïŒäž¡è
ãçµã¶å®æåžã賌å
¥ããããšã«ããïŒå®æåžã賌å
¥ããéã«ã¯ïŒé§
<var>S</var> ãšé§
<var>T</var> ã®éãæå°ã®éè³ã§ç§»åããçµè·¯ãäžã€æå®ããªããã°ãªããªãïŒãã®å®æåžãçšãããšïŒæå®ããçµè·¯ã«å«ãŸããééè·¯ç·ã¯åæ¹åã«èªç±ã«ä¹ãéãã§ããïŒ
</p>
<p>
JOI åã¯ïŒé§
<var>U</var> ããã³é§
<var>V</var> ã®è¿ãã«ããæžåºãããå©çšããŠããïŒããã§ïŒé§
<var>U</var> ããé§
<var>V</var> ãžã®ç§»åã«ãããéè³ãã§ããã ãå°ãããªãããã«å®æåžã賌å
¥ããããšèããïŒ
</p>
<p>
é§
<var>U</var> ããé§
<var>V</var> ãžã®ç§»åã®éã¯ïŒãŸãé§
<var>U</var> ããé§
<var>V</var> ãžã®çµè·¯ã1 ã€éžã¶ïŒãã®çµè·¯ã«å«ãŸããééè·¯ç·<var>i</var> ã«ãããŠæ¯æãã¹ãéè³ã¯ïŒ
</p>
<ul>
<li> ééè·¯ç·<var>i</var> ã宿åžã賌å
¥ããéã«æå®ããçµè·¯ã«å«ãŸããå ŽåïŒ0 å</li>
<li> ééè·¯ç·<var>i</var> ã宿åžã賌å
¥ããéã«æå®ããçµè·¯ã«å«ãŸããªãå ŽåïŒ<var>C_i</var> å</li>
</ul>
<p>
ãšãªãïŒãã®éè³ã®åèšãïŒé§
<var>U</var> ããé§
<var>V</var> ãžã®ç§»åã«ãããéè³ã§ããïŒ
</p>
<p>
宿åžã賌å
¥ããéã«æå®ããçµè·¯ãããŸãéžãã ãšãã®ïŒé§
<var>U</var> ããé§
<var>V</var> ãžã®ç§»åã«ãããéè³ã®æå°å€ãæ±ãããïŒ
</p>
<h3>課é¡</h3>
<p>
宿åžã賌å
¥ããéã«æå®ããçµè·¯ãããŸãéžãã ãšãã®ïŒé§
<var>U</var> ããé§
<var>V</var> ãžã®ç§»åã«ãããéè³ã®æå°å€ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h3>å
¥å</h3>
<p>
æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯ïŒ2 åã®æŽæ°<var>N, M</var> ãæžãããŠããïŒãããã¯ïŒJOI åãäœãéœåžã«<var>N</var> åã®é§
ãš<var>M</var> æ¬ã®ééè·¯ç·ãããããšã衚ãïŒ</li>
<li> 2 è¡ç®ã«ã¯ïŒ2 åã®æŽæ°<var>S, T</var> ãæžãããŠããïŒãããã¯ïŒJOI åãé§
<var>S</var> ããé§
<var>T</var> ãžã®å®æåžã賌å
¥ããããšã衚ãïŒ</li>
<li> 3 è¡ç®ã«ã¯ïŒ2 åã®æŽæ°<var>U, V</var> ãæžãããŠããïŒãããã¯ïŒJOI åãé§
<var>U</var> ããé§
<var>V</var> ãžã®ç§»åã«ãããéè³ãæå°åãããããšã衚ãïŒ</li>
<li> ç¶ã<var>M</var> è¡ã®ãã¡ã®<var>i</var> è¡ç®(<var>1 \leq i \leq M</var>) ã«ã¯ïŒ3 åã®æŽæ°<var>A_i, B_i,C_i</var> ãæžãããŠããïŒãããã¯ïŒééè·¯ç·<var>i</var> ãé§
<var>A_i</var> ãšé§
<var>B_i</var> ãåæ¹åã«çµã³ïŒãã®éè³ã<var>C_i</var> åã§ããããšã衚ãïŒ</li>
</ul>
<h3>åºå</h3>
<p>
æšæºåºåã«ïŒå®æåžã賌å
¥ããéã«é§
<var>S</var> ããé§
<var>T</var> ãžã®çµè·¯ãããŸãæå®ãããšãã®ïŒé§
<var>U</var> ããé§
<var>V</var> ãžã®ç§»åã«ãããéè³ã®æå°å€ã1 è¡ã§åºåããïŒ
</p>
<h3>å¶é</h3>
<p>
ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p>
<ul>
<li><var> 2 \leq N \leq 100 000ïŒ </var></li>
<li><var> 1 \leq M \leq 200 000ïŒ</var></li>
<li><var> 1 \leq S \leq NïŒ</var></li>
<li><var> 1 \leq T \leq NïŒ</var></li>
<li><var> 1 \leq U \leq NïŒ</var></li>
<li><var> 1 \leq V \leq NïŒ</var></li>
<li><var> S ≠ TïŒ</var></li>
<li><var> U ≠ VïŒ</var></li>
<li><var> S ≠ U</var> ãŸãã¯<var>T ≠ VïŒ</var></li>
<li> ã©ã®é§
ããä»ã®ã©ã®é§
ãžã1 æ¬ä»¥äžã®ééè·¯ç·ãçšããŠå°éã§ããïŒ</li>
<li><var> 1 \leq A_i < B_i \leq N (1 \leq i l\leq M)ïŒ</var></li>
<li><var> 1 \leq i < j \leq M</var> ã«å¯ŸãïŒ<var>A_i ≠ A_j</var> ãŸãã¯<var>B_i ≠ B_jïŒ</var></li>
<li><var> 1 \leq C_i \leq 1 000 000 000 (1 \leq i \leq M)ïŒ</var></li>
</ul>
<!--
å°èª²é¡
å°èª²é¡1 [16 ç¹]
S = U ãæºããïŒ
å°èª²é¡2 [15 ç¹]
é§
S ããé§
T ãžæå°ã®éè³ã§ç§»åãããšãã«çšããããšãã§ããçµè·¯ã¯1 éããããªãïŒ
å°èª²é¡3 [24 ç¹]
N ⊠300 ãæºããïŒ
å°èª²é¡4 [45 ç¹]
远å ã®å¶éã¯ãªãïŒ
-->
<h3>å
¥åºåäŸ</h3>
<h3>å
¥åäŸ1</h3>
<pre>
6 6
1 6
1 4
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
</pre>
<h3>åºåäŸ1</h3>
<pre>
2
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒå®æåžãè²·ãéã«æå®ã§ããçµè·¯ã¯é§
1 → é§
2 → é§
3 → é§
5 → é§
6 ãšããçµè·¯ã«éãããïŒ
</p>
<p>
é§
1 ããé§
4 ãžã®ç§»åã«ãããéè³ãæå°åããã«ã¯ïŒé§
1 → é§
2 → é§
3 → é§
5 → é§
4 ãšããçµè·¯ãéžã¹ã°ããïŒãã®çµè·¯ãéžãã å ŽåïŒåééè·¯ç·ã«ãããŠæ¯æãã¹ãéè³ã¯ïŒ
</p>
<ul>
<li> é§
4 ãšé§
5 ãçµã¶ééè·¯ç·5 ã«ãããŠã¯ïŒ2 åïŒ</li>
<li> ãã以å€ã®ééè·¯ç·ã«ãããŠã¯ïŒ0 åïŒ</li>
</ul>
<p>
ãšãªãã®ã§ïŒãããéè³ã®åèšã¯2 åãšãªãïŒ
</p>
<h3>å
¥åäŸ2 </h3>
<pre>
6 5
1 2
3 6
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
</pre>
<h3>åºåäŸ2</h3>
<pre>
3000000000
</pre>
<p>
ãã®å
¥åäŸã§ã¯ïŒé§
3 ããé§
6 ãžã®ç§»åã«å®æåžãçšããªãïŒ
</p>
<h3>å
¥åäŸ3</h3>
<pre>
8 8
5 7
6 8
1 2 2
2 3 3
3 4 4
1 4 1
1 5 5
2 6 6
3 7 7
4 8 8
</pre>
<h3>åºåäŸ3</h3>
<pre>
15
</pre>
<h3>å
¥åäŸ4</h3>
<pre>
5 5
1 5
2 3
1 2 1
2 3 10
2 4 10
3 5 10
4 5 10
</pre>
<h3> åºåäŸ4</h3>
<pre>
0
</pre>
<h3>å
¥åäŸ5</h3>
<pre>
10 15
6 8
7 9
2 7 12
8 10 17
1 3 1
3 8 14
5 7 15
2 3 7
1 10 14
3 6 12
1 5 10
8 9 1
2 9 7
1 4 1
1 8 1
2 4 7
5 6 16
</pre>
<h3>åºåäŸ5</h3>
<pre>
19
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2017/2018-ho/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第17 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2017/2018) æ¬éžã</a>
</p>
|
p00089 |
<H1>æççµè·¯</H1>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_17_1">
</center>
<br/>
<p>
å³ïŒã«äŸç€ºããããã«æŽæ°ïŒ0 ä»¥äž 99 以äžïŒãã²ãããã«äžŠã¹ãŸãããã®ãããªãã²ãããã衚ãããŒã¿ãèªã¿èŸŒãã§ãäžçªäžããã¹ã¿ãŒãããŠäžçªäžãŸã§æ¬¡ã®ã«ãŒã«ã«åŸã£ãŠé²ããšããééããæŽæ°ã®åã®æå€§å€ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<ul>
<li>åã¹ãããã§ã察è§ç·äžã®å·Šäžã察è§ç·äžã®å³äžã«é²ãããšãã§ããŸãã</li>
</ul>
<p>
äŸãã°å³1ã®äŸã§ã¯ãå³2ã«ç€ºãããã«ã7,3,8,7,5,7,8,3,7ãéžãã§éã£ããšãããã®åã¯æå€§ã® 55 ïŒ7+3+8+7+5+7+8+3+7=55ïŒ ãšãªããŸãã
</p>
<H2>Input</H2>
<p>
å
¥åäŸã«ç€ºãããã«ãã«ã³ãã§åºåãããæŽæ°ã®äžŠã³ããã²ã圢ç¶ã«äžããããŸããåè¡ã«ç©ºçœæåã¯å«ãŸããŸãããå
¥åäŸã¯å³ïŒã«å¯Ÿå¿ããŠããŸãã
ããŒã¿ã®è¡æ°ã¯ 100 è¡æªæºã§ãã
</p>
<H2>Output</H2>
<p>
ã«ãŒã«ã«åŸã£ãŠééããæŽæ°ã®åã®æå€§å€ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
7
3,8
8,1,0
2,7,4,4
4,5,2,6,5
2,7,4,4
8,1,0
3,8
7
</pre>
<H2>Sample Output</H2>
<pre>
55
</pre>
|
p00123 |
<h1>ã¹ããŒãã¹ã±ãŒããããžãã¹ã</h1>
<p>
ã¹ããŒãã¹ã±ãŒããããžãã¹ãã§ã¯ã2 çš®é¡ã®è·é¢ã§èŠå®ãããã¿ã€ã ãäžåã£ãå Žåã«çŽãèªå®ãããŸããäŸãã° A çŽã«ãªãã«ã¯ 500 M ã§ 40.0 ç§æªæºãã〠1000 M ã§ 1 å 23 ç§æªæºã§ããããšãæ±ããããŸãã
</p>
<p>
ã¹ããŒãã¹ã±ãŒãå€§äŒ (500 M ãš 1000 M) ã§èšé²ããã¿ã€ã ãå
¥åãšããã¹ããŒãã¹ã±ãŒããããžãã¹ãã§äœçŽã«çžåœããããåºåããããã°ã©ã ãäœæããŠäžããã500 M ãš1000 M ã®ãããžãã¹ãèŠå®ã¿ã€ã ã¯äžè¡šã®ãšããã§ãã E çŽã«æºããªãã£ãå Žåã«ã¯ãNA ãšåºåããŠãã ããã
</p>
<center>
<table>
<tr><th width="100"></th><th width="120"> 500 M</th><th width="120">1000 M</th></tr>
<tr><td>AAA çŽ</td><td> 35 ç§ 50</td><td> 1 å 11 ç§ 00</td></tr>
<tr><td> AA çŽ </td><td> 37 ç§ 50</td><td> 1 å 17 ç§ 00</td></tr>
<tr><td> A çŽ </td><td> 40 ç§ 00</td><td> 1 å 23 ç§ 00</td></tr>
<tr><td> B çŽ </td><td> 43 ç§ 00</td><td> 1 å 29 ç§ 00</td></tr>
<tr><td> C çŽ </td><td> 50 ç§ 00</td><td> 1 å 45 ç§ 00</td></tr>
<tr><td> D çŽ </td><td> 55 ç§ 00</td><td> 1 å 56 ç§ 00</td></tr>
<tr><td> E çŽ </td><td>1å10 ç§ 00 </td><td>2 å 28 ç§ 00</td></tr>
</table>
</center>
<br/>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ãããšããŠã500 M ã¿ã€ã ãš 1000 M ã¿ã€ã ããããã衚ã宿° <var>t<sub>1</sub></var>, <var>t<sub>2</sub></var> (8.0 ≤ <var>t<sub>1</sub></var>, <var>t<sub>2</sub></var> ≤ 360.0) ã空çœåºåãã§äžããããŸãã<var>t<sub>1</sub></var>, <var>t<sub>2</sub></var> ã¯ç§åäœã§å°æ°ç¹ä»¥äžæå€§ 2 æ¡ãŸã§ã®æ°åãå«ã宿°ã§äžããããŸãã
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããããšã«ãå€å®çµæ AAA ~ E ãŸã㯠NA ãïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
40.0 70.0
72.5 140.51
</pre>
<H2>Output for the Sample Input</H2>
<pre>
B
NA
</pre>
|
p03426 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns. The square at the <var>i</var>-th row and the <var>j</var>-th column will be called Square <var>(i,j)</var>.</p>
<p>The integers from <var>1</var> through <var>HÃW</var> are written throughout the grid, and the integer written in Square <var>(i,j)</var> is <var>A_{i,j}</var>.</p>
<p>You, a magical girl, can teleport a piece placed on Square <var>(i,j)</var> to Square <var>(x,y)</var> by consuming <var>|x-i|+|y-j|</var> magic points.</p>
<p>You now have to take <var>Q</var> practical tests of your ability as a magical girl.</p>
<p>The <var>i</var>-th test will be conducted as follows:</p>
<ul>
<li>
<p>Initially, a piece is placed on the square where the integer <var>L_i</var> is written.</p>
</li>
<li>
<p>Let <var>x</var> be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer <var>x+D</var> is written, as long as <var>x</var> is not <var>R_i</var>. The test ends when <var>x=R_i</var>.</p>
</li>
<li>
<p>Here, it is guaranteed that <var>R_i-L_i</var> is a multiple of <var>D</var>.</p>
</li>
</ul>
<p>For each test, find the sum of magic points consumed during that test.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 300</var></li>
<li><var>1 \leq D \leq HÃW</var></li>
<li><var>1 \leq A_{i,j} \leq HÃW</var></li>
<li><var>A_{i,j} \neq A_{x,y} ((i,j) \neq (x,y))</var></li>
<li><var>1 \leq Q \leq 10^5</var></li>
<li><var>1 \leq L_i \leq R_i \leq HÃW</var></li>
<li><var>(R_i-L_i)</var> is a multiple of <var>D</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>D</var>
<var>A_{1,1}</var> <var>A_{1,2}</var> <var>...</var> <var>A_{1,W}</var>
<var>:</var>
<var>A_{H,1}</var> <var>A_{H,2}</var> <var>...</var> <var>A_{H,W}</var>
<var>Q</var>
<var>L_1</var> <var>R_1</var>
<var>:</var>
<var>L_Q</var> <var>R_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each test, print the sum of magic points consumed during that test.</p>
<p>Output should be in the order the tests are conducted.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 2
1 4 3
2 5 7
8 9 6
1
4 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<ul>
<li>
<p><var>4</var> is written in Square <var>(1,2)</var>.</p>
</li>
<li>
<p><var>6</var> is written in Square <var>(3,3)</var>.</p>
</li>
<li>
<p><var>8</var> is written in Square <var>(3,1)</var>.</p>
</li>
</ul>
<p>Thus, the sum of magic points consumed during the first test is <var>(|3-1|+|3-2|)+(|3-3|+|1-3|)=5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 2 3
3 7
1 4
5 2
6 8
2
2 2
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
0
</pre>
<p>Note that there may be a test where the piece is not moved at all, and there may be multiple identical tests.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
13 13
2 10
13 13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
5
0
</pre></section>
</div>
</span> |
p03076 | <span class="lang-en">
<p>Score: <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>The restaurant AtCoder serves the following five dishes:</p>
<ul>
<li>ABC Don (rice bowl): takes <var>A</var> minutes to serve.</li>
<li>ARC Curry: takes <var>B</var> minutes to serve.</li>
<li>AGC Pasta: takes <var>C</var> minutes to serve.</li>
<li>APC Ramen: takes <var>D</var> minutes to serve.</li>
<li>ATC Hanbagu (hamburger patty): takes <var>E</var> minutes to serve.</li>
</ul>
<p>Here, the time to serve a dish is the time between when an order is placed and when the dish is delivered.</p>
<p>This restaurant has the following rules on orders:</p>
<ul>
<li>An order can only be placed at a time that is a multiple of <var>10</var> (time <var>0</var>, <var>10</var>, <var>20</var>, <var>...</var>).</li>
<li>Only one dish can be ordered at a time.</li>
<li>No new order can be placed when an order is already placed and the dish is still not delivered, but a new order can be placed at the exact time when the dish is delivered.</li>
</ul>
<p>E869120 arrives at this restaurant at time <var>0</var>. He will order all five dishes. Find the earliest possible time for the last dish to be delivered.<br/>
Here, he can order the dishes in any order he likes, and he can place an order already at time <var>0</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>A, B, C, D</var> and <var>E</var> are integers between <var>1</var> and <var>123</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>D</var>
<var>E</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the earliest possible time for the last dish to be delivered, as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>29
20
7
35
120
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>215
</pre>
<p>If we decide to order the dishes in the order ABC Don, ARC Curry, AGC Pasta, ATC Hanbagu, APC Ramen, the earliest possible time for each order is as follows:</p>
<ul>
<li>Order ABC Don at time <var>0</var>, which will be delivered at time <var>29</var>.</li>
<li>Order ARC Curry at time <var>30</var>, which will be delivered at time <var>50</var>.</li>
<li>Order AGC Pasta at time <var>50</var>, which will be delivered at time <var>57</var>.</li>
<li>Order ATC Hanbagu at time <var>60</var>, which will be delivered at time <var>180</var>.</li>
<li>Order APC Ramen at time <var>180</var>, which will be delivered at time <var>215</var>.</li>
</ul>
<p>There is no way to order the dishes in which the last dish will be delivered earlier than this.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>101
86
119
108
57
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>481
</pre>
<p>If we decide to order the dishes in the order AGC Pasta, ARC Curry, ATC Hanbagu, APC Ramen, ABC Don, the earliest possible time for each order is as follows:</p>
<ul>
<li>Order AGC Pasta at time <var>0</var>, which will be delivered at time <var>119</var>.</li>
<li>Order ARC Curry at time <var>120</var>, which will be delivered at time <var>206</var>.</li>
<li>Order ATC Hanbagu at time <var>210</var>, which will be delivered at time <var>267</var>.</li>
<li>Order APC Ramen at time <var>270</var>, which will be delivered at time <var>378</var>.</li>
<li>Order ABC Don at time <var>380</var>, which will be delivered at time <var>481</var>.</li>
</ul>
<p>There is no way to order the dishes in which the last dish will be delivered earlier than this.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>123
123
123
123
123
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>643
</pre>
<p>This is the largest valid case.</p></section>
</div>
</span> |
p02237 |
<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>Graph</H1>
<p>
There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation.
</p>
<p>
An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, the adjacency list $Adj[u]$ contains all vertices $v$ such that there is an edge $(u, v) \in E$. That is, $Adj[u]$ consists of all vertices adjacent to $u$ in $G$.
</p>
<p>
An adjacency-matrix representation consists of $|V| \times |V|$ matrix $A = a_{ij}$ such that $a_{ij} = 1$ if $(i, j) \in E$, $a_{ij} = 0$ otherwise.
</p>
<p>
Write a program which reads a directed graph $G$ represented by the adjacency list, and prints its adjacency-matrix representation. $G$ consists of $n\; (=|V|)$ vertices identified by their IDs $1, 2,.., n$ respectively.
</p>
<H2>Input</H2>
<p>
In the first line, an integer $n$ is given. In the next $n$ lines, an adjacency list $Adj[u]$ for vertex $u$ are given in the following format:
</p>
<p>
$u$ $k$ $v_1$ $v_2$ ... $v_k$
</p>
<p>
$u$ is vertex ID and $k$ denotes its degree. $v_i$ are IDs of vertices adjacent to $u$.
</p>
<H2>Output</H2>
<p>
As shown in the following sample output, print the adjacent-matrix representation of $G$. Put a single space character between $a_{ij}$.
</p>
<H2>Constraints</H2>
<ul>
<li>$1 \leq n \leq 100$</li>
</ul>
<H2>Sample Input</H2>
<pre>
4
1 2 2 4
2 1 4
3 0
4 1 3
</pre>
<H2>Sample Output</H2>
<pre>
0 1 0 1
0 0 0 1
0 0 0 0
0 0 1 0
</pre>
|
p02667 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has an empty string <var>S</var> and a variable <var>x</var> whose initial value is <var>0</var>.</p>
<p>Also, we have a string <var>T</var> consisting of <code>0</code> and <code>1</code>.</p>
<p>Now, Takahashi will do the operation with the following two steps <var>|T|</var> times.</p>
<ul>
<li>Insert a <code>0</code> or a <code>1</code> at any position of <var>S</var> of his choice.</li>
<li>Then, increment <var>x</var> by the sum of the digits in the odd positions (first, third, fifth, ...) of <var>S</var>. For example, if <var>S</var> is <code>01101</code>, the digits in the odd positions are <code>0</code>, <code>1</code>, <code>1</code> from left to right, so <var>x</var> is incremented by <var>2</var>.</li>
</ul>
<p>Print the maximum possible final value of <var>x</var> in a sequence of operations such that <var>S</var> equals <var>T</var> in the end.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |T| \leq 2 \times 10^5</var></li>
<li><var>T</var> consists of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible final value of <var>x</var> in a sequence of operations such that <var>S</var> equals <var>T</var> in the end.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>Below is one sequence of operations that maximizes the final value of <var>x</var> to <var>5</var>.</p>
<ul>
<li>Insert a <code>1</code> at the beginning of <var>S</var>. <var>S</var> becomes <code>1</code>, and <var>x</var> is incremented by <var>1</var>.</li>
<li>Insert a <code>0</code> to the immediate right of the first character of <var>S</var>. <var>S</var> becomes <code>10</code>, and <var>x</var> is incremented by <var>1</var>.</li>
<li>Insert a <code>1</code> to the immediate right of the second character of <var>S</var>. <var>S</var> becomes <code>101</code>, and <var>x</var> is incremented by <var>2</var>.</li>
<li>Insert a <code>1</code> at the beginning of <var>S</var>. <var>S</var> becomes <code>1101</code>, and <var>x</var> is incremented by <var>1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0111101101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>26
</pre></section>
</div>
</span> |
p03975 | <span class="lang-en">
<p>Score : <var>66</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>
Summer vacation ended at last and the second semester has begun.
You, a Kyoto University student, came to university and heard a rumor that somebody will barricade the entrance of your classroom.
The barricade will be built just before the start of the <var>A</var>-th class and removed by Kyoto University students just before the start of the <var>B</var>-th class.
All the classes conducted when the barricade is blocking the entrance will be cancelled and you will not be able to attend them.
Today you take <var>N</var> classes and class <var>i</var> is conducted in the <var>t_i</var>-th period.
You take at most one class in each period.
Find the number of classes you can attend.
</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq N \leq 1000</var></li>
<li><var>1 \leq A < B \leq 10^9 </var></li>
<li><var>1 \leq t_i \leq 10^9</var></li>
<li>All <var>t_i</var> values are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p><var>N</var>, <var>A</var> and <var>B</var> are given on the first line and <var>t_i</var> is given on the <var>(i+1)</var>-th line. </p>
<pre>
<var>N</var> <var>A</var> <var>B</var>
<var>t<sub>1</sub></var>
:
<var>t<sub>N</sub></var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the number of classes you can attend. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
5 5 9
4
3
6
9
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
4
</pre>
<p>You can not only attend the third class. </p>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
5 4 9
5
6
7
8
9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
1
</pre>
<p>You can only attend the fifth class. </p>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 3</h3>
<pre>
4 3 6
9
6
8
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3>
<pre>
4
</pre>
<p>You can attend all the classes. </p>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 4</h3>
<pre>
2 1 2
1
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3>
<pre>
1
</pre>
<p>You can not attend the first class, but can attend the second. </p>
</section>
</div>
</span> |
p01948 |
<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>
Janken Master
</H1>
<p>
You are supposed to play the rock-paper-scissors game. There are $N$ players including you.
</p>
<p>
This game consists of multiple rounds. While the rounds go, the number of remaining players decreases. In each round, each remaining player will select an arbitrary shape independently. People who show rocks win if all of the other people show scissors. In this same manner, papers win rocks, scissors win papers. There is no draw situation due to the special rule of this game: if a round is tied based on the normal rock-paper-scissors game rule, the player who has the highest programming contest rating (this is nothing to do with the round!) will be the only winner of the round. Thus, some players win and the other players lose on each round. The losers drop out of the game and the winners proceed to a new round. They repeat it until only one player becomes the winner.
</p>
<p>
Each player is numbered from $1$ to $N$. Your number is $1$. You know which shape the other $N-1$ players tend to
show, that is to say, you know the probabilities each player shows rock, paper and scissors. The $i$-th player shows rock with $r_i\%$ probability, paper with $p_i\%$ probability, and scissors with $s_i\%$ probability. The rating of programming contest of the player numbered $i$ is $a_i$. There are no two players whose ratings are the same. Your task is to calculate your probability to win the game when you take an optimal strategy based on each player's tendency and rating.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$
$a_1$
$a_2$ $r_2$ $p_2$ $s_2$
...
$a_N$ $r_N$ $p_N$ $s_N$
</pre>
<p>
The first line consists of a single integer $N$ ($2 \leq N \leq 14$). The second line consists of a single integer
$a_i$ ($1 \leq a_i \leq N$). The ($i+1$)-th line consists of four integers $a_i, r_i, p_i$ and $s_i$ ($1 \leq a_i \leq N, 0 \leq r_i, p_i, s_i \leq 100,$ $r_i + p_i + s_i = 100$) for $i=2, ..., N$. It is guaranteed that $a_1, ..., a_N$ are pairwise distinct.
</p>
<H2>Output</H2>
<p>
Print the probability to win the game in one line. Your answer will be accepted if its absolute or relative error does not exceed $10^{-6}$.
</p>
<H2>Sample Input 1</H2>
<pre>
2
2
1 40 40 20
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
0.8
</pre>
<p>
Since you have the higher rating than the other player, you will win the game if you win or draw in the first round.
</p>
<H2>Sample Input 2</H2>
<pre>
2
1
2 50 50 0
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
0.5
</pre>
<p>
You must win in the first round.
</p>
<H2>Sample Input 3</H2>
<pre>
3
2
1 50 0 50
3 0 0 100
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
1
</pre>
<p>
In the first round, your best strategy is to show a rock. You will win the game with $50\%$ in this round. With the other $50\%$, you and the second player proceed to the second round and you must show a rock to win the game.
</p>
<H2>Sample Input 4</H2>
<pre>
3
2
3 40 40 20
1 30 10 60
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
0.27
</pre>
<H2>Sample Input 5</H2>
<pre>
4
4
1 34 33 33
2 33 34 33
3 33 33 34
</pre>
<H2>Output for Sample Input 5</H2>
<pre>
0.6591870816
</pre>
|
p02688 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>N</var> <em>Snukes</em> called Snuke <var>1</var>, Snuke <var>2</var>, ..., Snuke <var>N</var> live in a town.</p>
<p>There are <var>K</var> kinds of snacks sold in this town, called Snack <var>1</var>, Snack <var>2</var>, ..., Snack <var>K</var>. The following <var>d_i</var> Snukes have Snack <var>i</var>: Snuke <var>A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}</var>.</p>
<p>Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 100</var></li>
<li><var>1 \leq K \leq 100</var></li>
<li><var>1 \leq d_i \leq N</var></li>
<li><var>1 \leq A_{i, 1} < \cdots < A_{i, d_i} \leq 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>d_1</var>
<var>A_{1, 1} \cdots A_{1, d_1}</var>
<var>\vdots</var>
<var>d_K</var>
<var>A_{K, 1} \cdots A_{K, d_K}</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 2
2
1 3
1
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<ul>
<li>Snuke <var>1</var> has Snack <var>1</var>.</li>
<li>Snuke <var>2</var> has no snacks.</li>
<li>Snuke <var>3</var> has Snack <var>1</var> and <var>2</var>.</li>
</ul>
<p>Thus, there will be one victim: Snuke <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1
3
1
3
1
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre></section>
</div>
</span> |
p02372 |
<H1>Height of a Tree</H1>
<br/>
<p>
Given a tree <var>T</var> with non-negative weight, find the height of each node of the tree. For each node, the height is the distance to the most distant leaf from the node.
</p>
<H2>Input</H2>
<pre>
<var>n</var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>1</sub></var>
<var>s<sub>2</sub></var> <var>t<sub>2</sub></var> <var>w<sub>2</sub></var>
:
<var>s<sub>n-1</sub></var> <var>t<sub>n-1</sub></var> <var>w<sub>n-1</sub></var>
</pre>
<p>
The first line consists of an integer <var>n</var> which represents the number of nodes in the tree. Every node has a unique ID from 0 to <var>n</var>-1 respectively.
</p>
<p>
In the following <var>n</var>-1 lines, edges of the tree are given.
<var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent end-points of the <var>i</var>-th edge (undirected) and <var>w<sub>i</sub></var> represents the weight (distance) of the <var>i</var>-th edge.
</p>
<H2>Output</H2>
<p>
The output consists of <var>n</var> lines. Print the height of each node 0, 1, 2, ..., <var>n-1</var> in order.
</p>
<h2>Constraints</h2>
<ul>
<li> 1 ≤ <var>n</var> ≤ 10,000</li>
<li> 0 ≤ <var>w<sub>i</sub></var> ≤ 1,000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4
0 1 2
1 2 1
1 3 3
</pre>
<H2>Sample Output 1</H2>
<pre>
5
3
4
5
</pre> |
p02722 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is a positive integer <var>N</var>.</p>
<p>We will choose an integer <var>K</var> between <var>2</var> and <var>N</var> (inclusive), then we will repeat the operation below until <var>N</var> becomes less than <var>K</var>.</p>
<ul>
<li>Operation: if <var>K</var> divides <var>N</var>, replace <var>N</var> with <var>N/K</var>; otherwise, replace <var>N</var> with <var>N-K</var>.</li>
</ul>
<p>In how many choices of <var>K</var> will <var>N</var> become <var>1</var> in the end?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^{12}</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 choices of <var>K</var> in which <var>N</var> becomes <var>1</var> in the end.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p>There are three choices of <var>K</var> in which <var>N</var> becomes <var>1</var> in the end: <var>2</var>, <var>5</var>, and <var>6</var>.</p>
<p>In each of these choices, <var>N</var> will change as follows:</p>
<ul>
<li>When <var>K=2</var>: <var>6 \to 3 \to 1</var></li>
<li>When <var>K=5</var>: <var>6 \to 1</var></li>
<li>When <var>K=6</var>: <var>6 \to 1</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3141
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>13
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>314159265358
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>9
</pre></section>
</div>
</span> |
p03830 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var>.
Find the number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1â€Nâ€10^3</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>There are four divisors of <var>3!</var> <var>=6</var>: <var>1</var>, <var>2</var>, <var>3</var> and <var>6</var>. Thus, the output should be <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>30
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>972926972
</pre></section>
</div>
</span> |
p03099 | <span class="lang-en">
<p>Score : <var>1300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A museum exhibits <var>N</var> jewels, Jewel <var>1, 2, ..., N</var>.
The coordinates of Jewel <var>i</var> are <var>(x_i, y_i)</var> (the museum can be regarded as a two-dimensional plane), and the value of that jewel is <var>v_i</var>.</p>
<p>Snuke the thief will steal some of these jewels.</p>
<p>There are <var>M</var> conditions, Condition <var>1, 2, ..., M</var>, that must be met when stealing jewels, or he will be caught by the detective.
Each condition has one of the following four forms:</p>
<ul>
<li>(<var>t_i</var> =<code>L</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>x</var> coordinates are <var>a_i</var> or smaller.</li>
<li>(<var>t_i</var> =<code>R</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>x</var> coordinates are <var>a_i</var> or larger.</li>
<li>(<var>t_i</var> =<code>D</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>y</var> coordinates are <var>a_i</var> or smaller.</li>
<li>(<var>t_i</var> =<code>U</code>, <var>a_i</var>, <var>b_i</var>) : Snuke can only steal at most <var>b_i</var> jewels whose <var>y</var> coordinates are <var>a_i</var> or larger.</li>
</ul>
<p>Find the maximum sum of values of jewels that Snuke the thief can steal.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 80</var></li>
<li><var>1 \leq x_i, y_i \leq 100</var></li>
<li><var>1 \leq v_i \leq 10^{15}</var></li>
<li><var>1 \leq M \leq 320</var></li>
<li><var>t_i</var> is <code>L</code>, <code>R</code>, <code>U</code> or <code>D</code>.</li>
<li><var>1 \leq a_i \leq 100</var></li>
<li><var>0 \leq b_i \leq N - 1</var></li>
<li><var>(x_i, y_i)</var> are pairwise distinct.</li>
<li><var>(t_i, a_i)</var> are pairwise distinct.</li>
<li><var>(t_i, b_i)</var> 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>x_1</var> <var>y_1</var> <var>v_1</var>
<var>x_2</var> <var>y_2</var> <var>v_2</var>
<var>:</var>
<var>x_N</var> <var>y_N</var> <var>v_N</var>
<var>M</var>
<var>t_1</var> <var>a_1</var> <var>b_1</var>
<var>t_2</var> <var>a_2</var> <var>b_2</var>
<var>:</var>
<var>t_M</var> <var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum sum of values of jewels that Snuke the thief can steal.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
1 3 6
1 5 9
3 1 8
4 3 8
6 2 9
5 4 11
5 7 10
4
L 3 1
R 2 3
D 5 3
U 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>36
</pre>
<p><img alt="Figure" src="https://img.atcoder.jp/agc031/rghe0iwfjoievjw4epdfmengow.png"/></p>
<p>Stealing Jewel <var>1, 5, 6</var> and <var>7</var> results in the total value of <var>36</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 2 3
4 5 6
7 8 9
1
L 100 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 1 10
1 2 11
2 1 12
2 2 13
3
L 8 3
L 9 2
L 10 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>13
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10
66 47 71040136000
65 77 74799603000
80 53 91192869000
24 34 24931901000
91 78 49867703000
68 71 46108236000
46 73 74799603000
56 63 93122668000
32 51 71030136000
51 26 70912345000
21
L 51 1
L 7 0
U 47 4
R 92 0
R 91 1
D 53 2
R 65 3
D 13 0
U 63 3
L 68 3
D 47 1
L 91 5
R 32 4
L 66 2
L 80 4
D 77 4
U 73 1
D 78 5
U 26 5
R 80 2
R 24 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>305223377000
</pre></section>
</div>
</span> |
p03563 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is a user of a site that hosts programming contests.<br/>
When a user competes in a contest, the <em>rating</em> of the user (not necessarily an integer) changes according to the <em>performance</em> of the user, as follows: </p>
<ul>
<li>Let the current rating of the user be <var>a</var>.</li>
<li>Suppose that the performance of the user in the contest is <var>b</var>.</li>
<li>Then, the new rating of the user will be the avarage of <var>a</var> and <var>b</var>.</li>
</ul>
<p>For example, if a user with rating <var>1</var> competes in a contest and gives performance <var>1000</var>, his/her new rating will be <var>500.5</var>, the average of <var>1</var> and <var>1000</var>.</p>
<p>Takahashi's current rating is <var>R</var>, and he wants his rating to be exactly <var>G</var> after the next contest.<br/>
Find the performance required to achieve it. </p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq R, G \leq 4500</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>R</var>
<var>G</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the performance required to achieve the objective.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2002
2017
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2032
</pre>
<p>Takahashi's current rating is <var>2002</var>.<br/>
If his performance in the contest is <var>2032</var>, his rating will be the average of <var>2002</var> and <var>2032</var>, which is equal to the desired rating, <var>2017</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4500
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-4500
</pre>
<p>Although the current and desired ratings are between <var>0</var> and <var>4500</var>, the performance of a user can be below <var>0</var>.</p></section>
</div>
</span> |
p03133 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There is a square grid with <var>N</var> rows and <var>M</var> columns.
Each square contains an integer: <var>0</var> or <var>1</var>. The square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left contains <var>a_{ij}</var>.</p>
<p>Among the <var>2^{N+M}</var> possible pairs of a subset <var>A</var> of the rows and a subset <var>B</var> of the columns, find the number of the pairs that satisfy the following condition, modulo <var>998244353</var>:</p>
<ul>
<li>The sum of the <var>|A||B|</var> numbers contained in the intersection of the rows belonging to <var>A</var> and the columns belonging to <var>B</var>, is odd.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 300</var></li>
<li><var>0 \leq a_{i,j} \leq 1(1\leq i\leq N,1\leq j\leq M)</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_{11}</var> <var>...</var> <var>a_{1M}</var>
<var>:</var>
<var>a_{N1}</var> <var>...</var> <var>a_{NM}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the pairs of a subset of the rows and a subset of the columns that satisfy the condition, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
0 1
1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>For example, if <var>A</var> consists of the first row and <var>B</var> consists of both columns, the sum of the numbers contained in the intersection is <var>0+1=1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 3
0 0 0
0 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>8
</pre></section>
</div>
</span> |
p01661 |
<h2>F - ïŒæ³æ</h2>
<p>ïŒæ³ã®èªçæ¥ã«"圌"ã¯ç¶ããåããããïŒ</p>
<p>ããåãïŒæ³ã«ãªã£ããšããããšã¯ïŒç§ã¯ããåŒéã ïŒä»æ¥ãããåãïŒæ³æã®é·ã ïŒ<br>
ïŒæ³æã®æåŸã«ããïŒïŒæ³æã®é·ãïŒæ³ã®éã ãåžææŽ»åãè¡ãããšãèªããããŠããïŒ<br>
ãã®å®å®è¹ã䜿ã£ãŠïŒããããããã®äººã
ã«ïŒæ³æã®çŽ æŽããããåºããŠããªããïŒã
</p>
<p>
ïŒæ³æãããããããã®äººã«åºããããã«"圌"ã¯ïŒèªåã®åšãã®æã«ã€ããŠã®æ
å ±ãéããïŒ<br>
"圌"ã®æã®åšãã«ã¯ïŒ<var>n</var> åã®ææãããïŒææã¯ <var> 1, ... , n</var> ã§çªå·ä»ããããŠããããšãããã£ãïŒ<br>
ææ<var>i</var> ãã ææ<var>j</var>ã®éãç§»åããã«ã¯ïŒ<var>w_i_j</var> (幎)ã®æéããããããšãããã£ãïŒ
</p>
<p>
ãããŠïŒããããã®æã§åœŒãïŒæ³ã§ããããæéïŒã€ãŸãåžææŽ»åã§ããæéãç°ãªãããšãããã£ãïŒ<br>
ããããã®ææäžã§ã¯ïŒå®å®æŠ<var>l_i</var>幎1æ1æ¥00:00:00以é<var>r_i</var>幎1æ1æ¥00:00:00ããåãŸã§ã®æé垯ã§ããã°7æ³ã§ããããïŒ <br>
ããšãäžåºŠããæã§ïŒæ³ä»¥å€ã®å¹Žéœ¢ã«ãªã£ãŠãïŒãã®æã§åŸããïŒæ³ã«ãªã£ãå ŽåãïŒå¥ã®æã§ïŒæ³ã«ãªãã°åžææŽ»åãåéããããšãã§ããïŒ
</p>
<p>
ãããã©ã®æã§ã©ããããïŒãããŠã©ã®é åºã§åžææŽ»åãè¡ãã°ããå€ãã®äººã«ïŒæ³æãäŒããããšãã§ããã®ãïŒ<br>
"圌"ã«ã¯ããããªãã£ãïŒããã§"圌"ã¯ããã°ã©ãã³ã°ãåŸæãªããªãã«å©ããæ±ããããšã«ããïŒ
</p>
<p>
çŸåšã¯å®å®æŠ0幎1æ1æ¥00:00:00ã§ããïŒ"圌"ã¯ææ <var>s</var> ã«ããïŒ
ææéãæé©ã«ç§»åã»æ»åšããå Žåã«åžææŽ»åãè¡ããæé·ã®å¹Žæ°ïŒ<br>
ã€ãŸã"圌"ãïŒæ³ã§ãã€ææã§éããæé·ã®å¹Žæ°<var>T</var>ãæ±ããŠããããïŒ
ãã ãïŒå¹Žæ°<var>T</var>ã«ã¯ç§»åæéã¯å«ãŸããªãïŒ
</p>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
<pre>
<var>n</var> <var>s</var>
<var>l_1</var> <var>r_1</var>
<var> ... </var>
<var>l_{n}</var> <var>r_{n}</var>
<var>w_{1,1} </var> <var>w_{1,2}</var> <var>...</var> <var>w_{1,n}</var>
<var> ... </var>
<var>w_{n,1}</var> <var>w_{n,2}</var> <var>...</var> <var>w_{n,n}</var>
</pre>
<p>
<var>n</var> ã¯ææã®åæ°ã§ããïŒ<var>s</var> ã¯äž»äººå
¬ãæåã«ããææãããããïŒ<br>
<var>l_i</var> ãš <var>r_i</var> ã¯ããããïŒææ<var>i</var> ã§ã®7æ³ã§ããããæé垯ã®äžéãšäžéãããããïŒ</br>
<var>w_i_j</var> ã¯ïŒææ<var>i</var>ããææ<var>j</var>ãç§»åããã®ã«ãããæéãããããïŒ<br>
å
¥åã¯ãã¹ãп޿°ã§ããïŒ
</p>
<h2>åºå圢åŒ</h2>
<p>
çã<var>T</var>ãåºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ n ≤ 500</var></li>
<li><var>1 ≤ s ≤ n</var></li>
<li><var>0 ≤ l_i < r_i ≤ 10^8</var></li>
<li><var>0 ≤ w_{ij} ≤ 10^8</var> (<var>i</var> â <var>j</var>)</li>
<li><var>w_{ij} = 0 </var> (<var>i</var> = <var>j</var>)</li>
</ul>
<!--
<p>ãã®åé¡ã®å€å®ã«ã¯ïŒ50 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ</p>
<ul>
<li>ãã¹ãŠã® <var>i, j </var> ã«å¯Ÿã㊠<var>w_{ij} = 0 </var></li>
</ul>
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
2 1
0 100
150 250
0 100
100 0
</pre>
<h3>åºåäŸ 1</h3>
<pre>
150
</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
5 1
7 44
10 49
38 48
11 23
11 30
0 1 7 2 7
10 0 3 8 10
4 8 0 2 5
3 2 1 0 4
8 4 3 3 0
</pre>
<h3>åºåäŸ 2</h3>
<pre>
41
</pre> |
p00973 | <h2>Fair Chocolate-Cutting</h2>
<p>
You are given a flat piece of chocolate of convex polygon shape. You are to cut it into two pieces of precisely the same amount with a straight knife.
</p>
<p>
Write a program that computes, for a given convex polygon, the maximum and minimum lengths of the line segments that divide the polygon into two equal areas.
</p>
<p>
The figures below correspond to first two sample inputs. Two dashed lines in each of them correspond to the equal-area cuts of minimum and maximum lengths.
</p>
<div style="text-align:center">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2018_fairChocolateCutting"><br>
Figure F.1. Sample Chocolate Pieces and Cut Lines
</div>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$
$x_1$ $y_1$
...
$x_n$ $y_n$
</pre>
<p>
The first line has an integer $n$, which is the number of vertices of the given polygon. Here, $n$ is between 3 and 5000, inclusive. Each of the following $n$ lines has two integers $x_i$ and $y_i$, which give the coordinates ($x_i, y_i$) of the $i$-th vertex of the polygon, in counterclockwise order. Both $x_i$ and $y_i$ are between 0 and 100 000, inclusive.
</p>
<p>
The polygon is guaranteed to be simple and convex. In other words, no two edges of the polygon intersect each other and interior angles at all of its vertices are less than $180^\circ$.
</p>
<h3>Output</h3>
<p>
Two lines should be output. The first line should have the minimum length of a straight line segment that partitions the polygon into two parts of the equal area. The second line should have the maximum length of such a line segment. The answer will be considered as correct if the values output have an absolute or relative error less than $10^{-6}$.
</p>
<h3>Sample Input 1</h3>
<pre>
4
0 0
10 0
10 10
0 10
</pre>
<h3>Sample Output 1</h3>
<pre>
10
14.142135623730950488
</pre>
<h3>Sample Input 2</h3>
<pre>
3
0 0
6 0
3 10
</pre>
<h3>Sample Output 2</h3>
<pre>
4.2426406871192851464
10.0
</pre>
<h3>Sample Input 3</h3>
<pre>
5
0 0
99999 20000
100000 70000
33344 63344
1 50000
</pre>
<h3>Sample Output 3</h3>
<pre>
54475.580091580027976
120182.57592539864775
</pre>
<h3>Sample Input 4</h3>
<pre>
6
100 350
101 349
6400 3440
6400 3441
1200 7250
1199 7249
</pre>
<h3>Sample Output 4</h3>
<pre>
4559.2050019027964982
6216.7174287968524227
</pre>
|
p01231 |
<h1><font color="#000">Problem I:</font> Aaron ãš Bruce</h1>
<p>
Aaron ã¯å¶æªãªç¯çœªè
ã§ããïŒ
圌ã¯å¹ŸåºŠãç¯çœªãç¹°ãè¿ããªãã
ïŒäžåŒã2åïŒã®ãã16åïŒäžçæ³¥æ£256åïŒé£ãéã65,536åïŒ
ãïŒãã®äººäžŠã¿å€ãã身äœèœåãçšããŠ
èŠå¯ã®æããéãç¶ããŠããïŒ
Bruce ã¯èŠå¯å®ã§ããïŒ
圌ã¯çªåºããéåèœåã¯æã£ãŠããªããïŒ
åçæ®åœ±ãè¶£å³ã§ããïŒ
åœŒã®æ®ã£ãåçãéèªã«èŒãã»ã©ã®è
åãæã£ãŠããïŒ
</p>
<p>
ããæ¥ïŒBruce ã¯å±±å¥¥ã«åçæ®åœ±ããã«æ¥ãïŒ
ãããšå¶ç¶ Aaron ã®ã¢ãžããçªãæ¢ããŠããŸã£ãïŒ
Bruce ãéãã Aaron ã远ã£ãŠãããšïŒ
圌ãã¯èœãšã穎ã«èœã¡ãŠå€ä»£éºè·¡ã®äžã«è¿·ã蟌ãã§ããŸã£ãïŒ
</p>
<p>
å€ä»£éºè·¡ã®äžã¯ããã€ãã®éšå±ãšïŒéšå±ã©ãããçµã¶éè·¯ã§æ§æãããŠããïŒ
å€ä»£éºè·¡ã« <var>M</var> åã®éšå±ããããšãïŒ
éºè·¡å
ã®éšå±ã«ã¯ãããã 0 ãã <var>M</var>â1 ãŸã§ã®çªå·ãã€ããããŠããïŒ
</p>
<p>
Aaron ã¯éããŠããéã«æå¹ãè¿ãããããããªããšèããã®ã§ïŒ
Bruce ãæé©ã«ç§»åãããšãã«äžçªé·ãééãç¶ããããããã«
éºè·¡ã®äžãç§»åããïŒ
Bruce ã¯æ©ã Aaron ãåçã«åãããã®ã§ïŒ
Aaron ãæé©ã«ç§»åãããšãã«äžçªæ©ã Bruce ãåçã«åããããããã«
éºè·¡ã®äžãç§»åããïŒ
</p>
<p>
Aaron ãš Bruce ã¯é çªã«è¡åããïŒ
æå㯠Aaron ã®çªãšããïŒ
ããããã®é çªã®ãšãïŒé£æ¥ããŠããéšå±ã®ã©ãã1ã€ã«ç§»åïŒ
ãããã¯ãã®å Žã«ãšã©ãŸãããšãã§ããïŒ
Aaron ãš Bruce ãåãéšå±ã«å
¥ã£ããšãïŒ
Bruce 㯠Aaron ãæ®åœ±ãããã®ãšããïŒ
</p>
<p>
Bruce ã Aaron ãæ®åœ±ããã®ã«ã©ããããã®æéããããããæ±ããŠæ¬²ããïŒ
æéã¯ã¿ãŒã³æ°ã§è¡šãããšãšãïŒ
Aaron ãš Bruce ããšãã«1åè¡åãçµãã£ãã1ã¿ãŒã³ãšæ°ããïŒ
</p>
<p>
äŸãã°ïŒå³5ã®ãããªç¶æ³ã®ãšãïŒ
Aaron ã¯éšå±5ã«éã蟌ãã° Bruce ã¯4ã¿ãŒã³ã§ãã©ãçããïŒ
Aaron ãéšå±7ã«éã蟌ãã° Bruce ã¯ãã©ãçãã®ã«5ã¿ãŒã³ãããïŒ
Aaron ã«ãšã£ãŠã¯éšå±7ã«éã蟌ãããšã§äžçªé·ãéãç¶ããããã®ã§
çãã¯5ã¿ãŒã³ãšãªãïŒ
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chase_1"
alt="Aaron ã5ã¿ãŒã³éãç¶ããããäŸïŒ">
</td>
</tr>
<tr>
<td>å³5: Aaron ã5ã¿ãŒã³éãç¶ããããäŸïŒ</td>
</tr>
</table>
</center>
<p>
ãŸãïŒå³6ã®ãããªç¶æ³ã®ãšãïŒ
Aaron ã Bruce ããé ãããããã«éšå±ãç§»åããããšã§
ãã€ãŸã§ãéãåãããšãã§ããïŒ
</p>
<center>
<table>
<tr>
<td>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chase_2"
alt="Aaron ããã€ãŸã§ãéãç¶ããããäŸïŒ">
</td>
</tr>
<tr>
<td>å³6: Aaron ããã€ãŸã§ãéãç¶ããããäŸïŒ</td>
</tr>
</table>
</center>
<h2>Input</h2>
<p>
å
¥åã®æåã®è¡ã«ããŒã¿ã»ããæ°ãè¡šãæ° <var>N</var>
(0 < <var>N</var> ≤ 100) ãäžããããïŒ
次ã®è¡ãã <var>N</var> åã®ããŒã¿ã»ãããç¶ãïŒ
</p>
<p>
åããŒã¿ã»ããã¯å€ä»£éºè·¡ã®åœ¢ç¶ãš Aaron ãš Bruce ã®åæäœçœ®ãããªãïŒ
åãã«ïŒå€ä»£éºè·¡ã®éšå±ã®æ° <var>M</var>
(2 ≤ <var>M</var> ≤ 50) ãäžããããïŒ
次ã«èŠçŽ æ° <var>M</var> × <var>M</var> ã®è¡åãäžããããïŒ
åè¡åã®èŠçŽ ã¯ 0 ããã㯠1 ã§ããïŒ
<var>i</var> è¡ç®ã® <var>j</var> çªç®ã®æ°åã 1 ãªãã°ïŒ
éšå± <var>i</var> ãšéšå± <var>j</var>
ã¯éè·¯ã§ã€ãªãã£ãŠãããšããããšãæå³ãã
ïŒãã ãïŒè¡åã®è¡çªå·ãšåçªå·ã¯0ããæ°ããïŒïŒ
è¡åã® (<var>i</var>, <var>j</var>) æåãš
(<var>j</var>, <var>i</var>) æåã®å€ã¯å¿
ãçããïŒ
(<var>i</var>, <var>i</var>) æåã®å€ã¯ 0 ã§ããïŒ
ç¶ããŠïŒ2ã€ã®æŽæ° <var>a</var>, <var>b</var> ãäžããããïŒ
åæŽæ°ã¯ãããã Aaron ã®åæäœçœ®ã®éšå±çªå·
(0 ≤ <var>a</var> < <var>M</var>) ãš
Bruce ã®åæäœçœ®ã®éšå±çªå·
(0 ≤ <var>b</var> < <var>M</var>) ã瀺ãïŒ
<var>a</var> ãš <var>b</var> ã®å€ã¯å¿
ãç°ãªãïŒ
</p>
<h2>Output</h2>
<p>
åããŒã¿ã»ããããšã«ïŒBruce ã Aaron ãæ®åœ±ããã®ã«äœã¿ãŒã³ããããã
1è¡ã§åºåããïŒ
ã©ãã ããã£ãŠãæ®åœ±ã§ããªãå Žåã¯
“<code>infinity</code>” ãšåºåããïŒ
</p>
<h2>Sample Input</h2>
<pre>
6
8
0 1 0 0 0 0 0 0
1 0 1 0 0 0 0 0
0 1 0 1 1 0 0 0
0 0 1 0 0 0 0 0
0 0 1 0 0 1 1 0
0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 1
0 0 0 0 0 0 1 0
3 0
4
0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0
1 0
5
0 1 0 1 0
1 0 0 1 0
0 0 0 0 1
1 1 0 0 0
0 0 1 0 0
2 0
5
0 1 0 0 1
1 0 1 1 1
0 1 0 1 0
0 1 1 0 1
1 1 0 1 0
2 4
5
0 1 0 1 0
1 0 1 1 0
0 1 0 0 1
1 1 0 0 1
0 0 1 1 0
3 0
5
0 1 0 1 1
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
1 1 0 1 0
0 4
</pre>
<h2>Output for the Sample Input</h2>
<pre>
5
infinity
infinity
2
infinity
1
</pre>
|
p04033 | <span class="lang-en">
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given two integers <var>a</var> and <var>b</var> (<var>aâ€b</var>). Determine if the product of the integers <var>a</var>, <var>a+1</var>, <var>âŠ</var>, <var>b</var> is positive, negative or zero.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>a</var> and <var>b</var> are integers.</li>
<li><var>-10^9â€aâ€bâ€10^9</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In test cases worth <var>100</var> points, <var>-10â€aâ€bâ€10</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>a</var> <var>b</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the product is positive, print <code>Positive</code>. If it is negative, print <code>Negative</code>. If it is zero, print <code>Zero</code>.</p>
</section>
</div>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Positive
</pre>
<p><var>1Ã2Ã3=6</var> is positive.</p>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>-3 -1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>Negative
</pre>
<p><var>(-3)Ã(-2)Ã(-1)=-6</var> is negative.</p>
</section>
</div>
<hr>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>-1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Zero
</pre>
<p><var>(-1)Ã0Ã1=0</var>.</p></section>
</div>
</hr></hr></hr></hr></span> |
p00070 |
<H1>Combination of Number Sequences</H1>
<p>
0 ãã 9 ãŸã§ã®æŽæ°ã䜿ã£ã <var>n</var> åã®æ°ã®äžŠã³ <var>k<sub>1</sub></var>, <var>k<sub>2</sub></var>, ..., <var>k<sub>n</sub></var> ãèããŸããæ£ã®æŽæ° <var>n</var> ãš <var>s</var> ãèªã¿èŸŒãã§ã<br/>
<br/>
<var>k<sub>1</sub> + 2 × k<sub>2</sub> + 3 × k<sub>3</sub> +</var> ... <var>+ n × k<sub>n</sub> = s </var><br/>
<br/>
ãšãªã£ãŠãããã㪠<var>n</var> åã®æ°ã®äžŠã³ãäœéãããããåºåããããã°ã©ã ãäœæããŠãã ããããã ãã1 ã€ã®ã<var>n</var> åã®æ°ã®äžŠã³ãã«ã¯åãæ°ã 2 å以äžçŸãããªããã®ãšããŸãã
</p>
<H2>Input</H2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸããåããŒã¿ã»ãããšããŠã<var>n</var> (1 ≤ <var>n</var> ≤ 10) ãš <var>s</var> (0 ≤ <var>s</var> ≤ 10,000)ã空çœåºåãã§ïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã«ã<var>n</var> åã®æŽæ°ã®åã <var>s</var> ã«ãªãçµã¿åããã®åæ°ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
3 10
3 1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
8
0
</pre>
|
p00420 | <h1>ååŠç©è³ªã¢ã«ãã¡</h1>
ã<p>
ã¢ã€ã
補è¬ã§ã¯æ¥ã
ååŠç©è³ªã®ç ç©¶ããªãããŠããŸããããŸç ç©¶ãããŠããã®ã¯ã$1$çªãã$N$çªã®ååã巊端ããå³ç«¯ãžçŽç·ç¶ã«ãªããã æ§é ãããŠããååŠç©è³ªãã³ãŒãããŒã ãã¢ã«ãã¡ãã§ãã
</p>
<p>
ã¢ã€ã
補è¬ã®éçºããæè¡ã䜿ãã°ãã¢ã«ãã¡ãæ§æããååã®äœçœ®ãå
¥ãæ¿ããããšãã§ããŸããå
¥ãæ¿ãã¯æ±ºãŸã£ãæé ã§ããè¡ãããšãã§ããŸãããããã®æé ã®éäžããå§ããŠéäžã§çµããããšãã§ããŸãã巊端ãã$a$çªç®ãš$b$çªç®ã®ååãå
¥ãæ¿ããæäœã$(a,b)$ãšæžããšããŸããããšãã°ã$N=5$ã§æ±ºãŸã£ãæé ã$(1,3),(2,5),(4,3),(1,5)$ã®ãšãã$1$çªç®ã®æäœ$(1,3)$ããå§ããŠ$3$çªç®ã®æäœ$(4,3)$ã§çµããããšãã$2$çªç®ã®æäœ$(2,5)$ããå§ããŠ$4$çªç®ã®æäœ$(1,5)$ã§çµããããšãã§ããŸãã
</p>
<p>
ããªãã¯ãã¢ã«ãã¡ã®ååã®å
¥ãæ¿ãæé ã®äžã®éå§äœçœ®ãšçµäºäœçœ®ãéžãã§ã·ãã¥ã¬ãŒã·ã§ã³ãè¡ããå
¥ãæ¿ãåŸã®ååã®ç¶æ
ã調ã¹ãããšã«ããŸããã
</p>
<p>
ã¢ã«ãã¡ã®ååã®å
¥ãæ¿ãæé ãäžãããããã·ãã¥ã¬ãŒã·ã§ã³ãäœåºŠãè¡ã£ããšããåã·ãã¥ã¬ãŒã·ã§ã³ã§ã®ååã®äœçœ®ã«ã€ããŠè³ªåã«çããããã°ã©ã ãäœæããã質åã¯æ¬¡ã®1.ãŸãã¯2.ã®åœ¢ãããŠããã</p>
</p>
<ol>
<li> çµäºåŸã«å·Šç«¯ãã$i$çªç®ã«äœçœ®ããŠããååã¯ãæåã¯äœçªç®ã«äœçœ®ããŠãããã</li>
<li> æåã«$i$ çªç®ã«äœçœ®ããŠããååãçµäºåŸã«ã©ã®äœçœ®ã«æ¥ãŠãããã
</li>
</ol>
<p>
ãã ããåã·ãã¥ã¬ãŒã·ã§ã³ã¯ãã¢ã«ãã¡ã®åæç¶æ
ïŒ$1$çªãã$N$çªã®ååã巊端ããå³ç«¯ãžçŽç·ç¶ã«ãªããã ç¶æ
ïŒããå§ãããã®ãšããã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
$N$ $K$ $Q$
$a_1$ $b_1$
$a_2$ $b_2$
:
$a_K$ $b_K$
$query_1$
$query_2$
:
$query_Q$
</pre>
<p>
ïŒè¡ç®ã«ã¢ã«ãã¡ãæ§æããååã®æ°$N$ ($2 \leq N \leq 100,000$)ãå
¥ãæ¿ãæé ã®é·ã$K$ ($1 \leq K \leq 100,000$)ãå
¥ãæ¿ãåŸã®ååã®ç¶æ
ã調ã¹ãåæ°$Q$ ($1 \leq Q \leq 100,000$)ãäžãããããç¶ã$K$è¡ã«å
¥ãæ¿ãæé ã®äžã®åæäœ$a_i,b_i$ ($1 \leq a_i,b_i \leq N$, $a_i \ne b_i$)ãäžããããã$i$çªç®ã®æäœã¯ã巊端ãã$a_i$çªç®ãš$b_i$çªç®ã®ååãå
¥ãæ¿ããæäœã衚ããç¶ã$Q$è¡ã«ãå
¥ãæ¿ãçµäºåŸã®ååã®ç¶æ
ãå°ãã質åãäžãããããå$query_i$ã¯ä»¥äžã®ããããã®åœ¢åŒã§äžããããã
</p>
<pre>
1 $s$ $t$ $x$
</pre>
<p>
ãŸãã¯
</p>
<pre>
2 $s$ $t$ $x$
</pre>
<p>
æåã®æ°åã1ã®å Žåãå
¥ãæ¿ãæé ã®äžã®å
¥ãæ¿ãã$s$çªãã$t$çª($1 \leq s \leq t \leq K$)ãŸã§è¡ã£ãåŸã«ãå·ŠåŽãã$x$çªç®($1 \leq x \leq N$)ã®ååã®çªå·ãäœçªãå°ãã質åã衚ããæåã®æ°åã2ã®å Žåãå
¥ãæ¿ãæé ã®äžã®å
¥ãæ¿ãã$s$çªãã$t$çª($1 \leq s \leq t \leq K$)ãŸã§è¡ã£ãåŸã«ã$x$çª($1 \leq x \leq N$)ã®ååãå·Šããæ°ããŠäœçªç®ã«ãããå°ãã質åã衚ãã
</p>
<h2>åºå</h2>
<p>
å質åã«å¯ŸããŠãçããïŒè¡ã«åºåããã
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
6 5 8
1 3
2 5
3 4
2 4
2 5
1 1 5 1
1 1 5 2
1 1 5 3
1 1 5 4
1 1 5 5
1 1 5 6
2 3 4 2
1 1 1 1
</pre>
<h3>åºåäŸ</h3>
<pre>
3
2
4
5
1
6
4
3
</pre>
<p>
å
¥ãæ¿ãæé ã¯$(1,3),(2,5),(3,4),(2,4),(2,5)$ã§ããã<br/>
$1$çªç®ãã$6$çªç®ã®è³ªåã§ã¯ãæé ã®$1$çªç®($s=1$)ãã$5$çªç®($t=5$)ãŸã§ãã¹ãŠè¡ã£ãå Žåãªã®ã§ãå
¥ãæ¿ãåŸã®ç¶æ
ã¯ãã¹ãŠå
±éã§ä»¥äžã®ããã«ãªãã
</p>
<p>
åæç¶æ
ã<span>1 2 3 4 5 6</span><br>
$(1,3)$ã®åŸ <span>3 2 1 4 5 6</span><br>
$(2,5)$ã®åŸ <span>3 5 1 4 2 6</span><br>
$(3,4)$ã®åŸ <span>3 5 4 1 2 6</span><br>
$(2,4)$ã®åŸ <span>3 1 4 5 2 6</span><br>
$(2,5)$ã®åŸ <span>3 2 4 5 1 6</span><br>
</p>
<p>
$7$çªç®ã®è³ªåã§ã¯$s=3,t=4$ãªã®ã§ãå
¥ãæ¿ãåŸã®ç¶æ
ã¯ä»¥äžã®ããã«ãªããååçªå·$2$çªã¯å·Šããæ°ããŠ$4$çªç®ã«ããã®ã§ãçãã¯4ã«ãªãã
</p>
<p>
åæç¶æ
ã<span>1 2 3 4 5</span><br>
$(3,4)$ã®åŸ <span>1 2 4 3 5</span><br>
$(2,4)$ã®åŸ <span>1 3 4 2 5</span><br>
</p>
<p>
$8$çªç®ã®è³ªåã§ã¯$s=1,t=1$ãªã®ã§ãå
¥ãæ¿ãåŸã®ç¶æ
ã¯ä»¥äžã®ããã«ãªãã
</p>
<p>
åæç¶æ
ã<span>1 2 3 4 5</span><br>
$(1,3)$ã®åŸ <span>3 2 1 4 5</span><br>
</p>
|
p00135 |
<H1>æèšã®çãéãšé·ãé</H1>
<p>
åå§ã¹ããŒã©ã€ã䞻矩çµç¹ãã¢ã«ã«ã€ãããããããããã®äºåç¶ãå±ããŸãããã¢ã«ã«ã€ããšããã°ãèŠäººã®é¡é¢ã«ãã€ãæãã€ãããããããããã§æåã§ãããæè¿ã§ã¯ç«è¬ãçšããŠã¬ã»ãã·ã§ã³äŒå Žã«ããºãè±ç«ããŸãæ£ãããªã©ãããéæ¿åããŠããŸãããäºåç¶ã¯æ¬¡ã®æé¢ã§ãã
</p>
<pre>
---ããœã³ã³ ããã®æéã奪ããè¯ããªãã
æèšã®çãéãšé·ãé åºäŒããããã¢ã«ã«ã€ã æ£çŸ©è¡ãã
ã¹ããŒã©ã€ã å倧ãªãã
</pre>
<p>
ãã©ãã©ãããŠããè§£ããªãã®ã§ãããæèšã®çéãšé·éãšãéãªã£ãããã«ãããããæ±ºè¡ãããšããæå³ã®ããã§ãã
</p>
<p>
ãã®ãããããèŠæãããããæå»ãå
¥åãšããŠãçéãšé·éãè¿ãå Žå㯠"alert"ãé ãå Žå㯠"safe"ããã以å€ã®å Žå㯠"warning" ãšåºåããããã°ã©ã ãäœæããŠãã ããããã ãããè¿ãããšã¯çéãšé·éã®è§åºŠã 0° ä»¥äž 30° æªæºã®å Žåãããããé ãããšã¯ 90° ä»¥äž 180° 以äžã®å ŽåããããŸãããªããæå»ã¯ 00:00 ä»¥äž 11:59 以äžãšããŸãã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>hh<sub>1</sub></var>:<var>mm<sub>1</sub></var>
<var>hh<sub>2</sub></var>:<var>mm<sub>2</sub></var>
:
<var>hh<sub>n</sub></var>:<var>mm<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«å€å®ããæå»ã®åæ° <var>n</var>ïŒ1 ≤ <var>n</var> ≤ 10000ïŒã2 è¡ç®ä»¥éã« <var>i</var> çªç®ã®æå» <var>hh<sub>i</sub></var>:<var>mm<sub>i</sub></var> ãããããïŒè¡ã«äžããããŸãã
</p>
<H2>Output</H2>
<p>
<var>i</var> çªç®ã®æå»ã®å€å®çµæ safeãwarningããŸã㯠alert ãé çªã«ããããïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
4
02:15
06:01
11:55
10:40
</pre>
<H2>Output for the Sample Input</H2>
<pre>
alert
safe
alert
warning
</pre>
|
p02108 |
<h1>Problem K: Donuts Purchase</h1>
<h2>Problem</h2>
<p>
ã©ãã€ã¯äŒæã®éããããšããªãæã§ããªããšãªãããŒãããé£ã¹ãããªã£ãã®ã§ãåºãå·¡ãããŒããã賌å
¥ããŠããããšã«ããã<br>
åè¡ã«ã¯1è»ã®ããŒããåºãããããã¹ãŠã®ããŒããåºã¯å¥æ°æ¥ãå®äŒæ¥ãšãªã£ãŠããã<br>
ã©ãã€ã«ã¯ããŒããã®å¥œã¿ãããã®ã§ãåºã«ãã£ãŠåŸãããæºè¶³åºŠãéãã<br>
ããã§ã©ãã€ã¯æé©ã«è¡åããããšã§ãã§ããã ãå€ãã®æºè¶³åºŠãåŸãããšã«ããã<br>
</p>
<p>
ã©ãã€ãäœãã§ããäžçã«ã¯ããããã0ãã<var>n</var>-1ã®çªå·ãå²ãåœãŠããã<var>n</var>åã®è¡ãããããããã¯<var>m</var>æ¬ã®éã§ç¹ãããŠããã<br>
ããããã®éã¯äžæ¹éè¡ã«ãªã£ãŠãããã©ãã€ã¯è¡<var>a<sub>i</sub></var>ããè¡<var>b<sub>i</sub></var>ãžç§»åããããšãã§ããã<br>
æåã©ãã€ã¯å¶æ°æ¥ã«è¡0ã«ããã<br>
ã©ãã€ã¯è¡ã«ã¯çãŸããã«ã1æ¥ã«éã1æ¬æž¡ãå¥ã®è¡ã«ç§»åããã<br>
ã©ãã€ã¯è¡<var>i</var>ã«å°çããæ¥ã«ãåºãå¶æ¥ããŠããã°1ã€ããŒããã賌å
¥ããæºè¶³åºŠ<var>c<sub>i</sub></var>ãåŸãã<br>
åãè¡ã¯äœåºŠã§ã蚪ããããšãã§ãããã1ã€ã®åºã§ã¯1床ãã賌å
¥ããªãã<br>
ã©ãã€ãããä»¥äžæºè¶³åºŠãåŸãããªãç¶æ
ã«ãªããŸã§æé©ã«è¡åããæã®æºè¶³åºŠã®åèšã®æå€§ãæ±ããã
</p>
<h2>Input</h2>
<pre>
<var>n</var> <var>m</var>
<var>c<sub>0</sub></var> ... <var>c<sub>n−1</sub></var>
<var>a<sub>0</sub></var> <var>b<sub>0</sub></var>
...
<var>a<sub>m−1</sub></var> <var>b<sub>m−1</sub></var>
</pre>
<p>
å
¥åã¯ãã¹ãп޿°ã§äžããããã<br>
1è¡ç®ã«è¡ã®æ°<var>n</var>ãšéã®æ°<var>m</var>ã空çœåºåãã§äžããããã<br>
2è¡ç®ã«è¡<var>i</var>ã®åºã§ããŒããã賌å
¥ããéã«åŸãããæºè¶³åºŠ<var>c<sub>i</sub></var>ã空çœåºåãã§äžããããã<br>
ç¶ã<var>m</var>è¡ã«éã®æ
å ±ã衚ã<var>a<sub>i</sub></var>ãš<var>b<sub>i</sub></var>ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<p>
å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã
</p>
<ul>
<li>1 ≤ <var>n</var> ≤ 10<sup>5</sup></li>
<li>0 ≤ <var>m</var> ≤ min(<var>n</var>×(<var>n</var>−1),10<sup>5</sup>)</li>
<li>0 ≤ <var>c<sub>i</sub></var> ≤ 1000</li>
<li>0 ≤ <var>a<sub>i</sub></var>,<var>b<sub>i</sub></var> ≤ <var>n</var> − 1</li>
<li>èªå·±ã«ãŒããå€é蟺ã¯ååšããªã</li>
</ul>
<h2>Output</h2>
<p>
æºè¶³åºŠã®åèšã®æå€§å€ã1è¡ã«åºåããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
2 1
1 2
0 1
</pre>
<h2>Sample Output 1</h2>
<pre>
1
</pre>
<h2>Sample Input 2</h2>
<pre>
5 5
1 1 1 1 1
0 1
1 2
2 3
3 0
3 4
</pre>
<h2>Sample Output 2</h2>
<pre>
3
</pre>
<h2>Sample Input 3</h2>
<pre>
4 4
1 1 1 1
0 1
1 2
2 0
2 3
</pre>
<h2>Sample Output 3</h2>
<pre>
4
</pre> |
p00565 | <h1>åå
(Sugoroku)</h1>
<h2> å顿</h2>
<p>
JOI åã¯ããããã®å®¶ã§åå
ãèŠã€ããïŒåå
ã¯çŽç·ç¶ã«äžŠãã <var>N+2</var> åã®ãã¹ãããªãïŒ<var>1</var> çªç®ã®ãã¹ã¯ã¹ã¿ãŒãïŒ<var>N+2</var> çªç®ã®ãã¹ã¯ãŽãŒã«ã§ããïŒãã®ä»ã®åãã¹ã«ã¯ <var>0</var> ãŸã㯠<var>1</var> ãæžãããŠããŠïŒå <var>i</var> (<var>1âŠiâŠN</var>) ã«ã€ããŠïŒ<var>i+1</var> çªç®ã®ãã¹ã«æžãããæ°å㯠<var>A_i</var> ã§ããïŒ
</p>
<p>
åå
ã§ã¯ïŒæåã«ã¹ã¿ãŒãã®ãã¹ã«ã³ãã眮ãïŒãµã€ã³ããæ¯ã£ãŠïŒåºãç®ã®æ°ã ãã³ããé²ããããšãç¹°ãè¿ãïŒãã ãïŒ<var>1</var> ã®æžããããã¹ã«æ¢ãŸã£ãå Žåã¯ïŒã²ãŒã ãªãŒããŒã§ããïŒã²ãŒã ãªãŒããŒã«ãªããã«ãŽãŒã«ã®ãã¹ã«æ¢ãŸããïŒãŽãŒã«ã®ãã¹ãéãéãããïŒã²ãŒã ã¯ãªã¢ã§ããïŒ</p>
<p>
JOI åã¯åå
ãéã¶ããã®ãµã€ã³ããããã¡ãå±ããã«è²·ãã«è¡ãããšã«ããïŒããã¡ãå±ããã«ã¯ <var>N+1</var> åã®ãµã€ã³ãã売ã£ãŠããïŒ<var>j</var> çªç® (<var>1âŠjâŠN+1</var>) ã®ãµã€ã³ã㯠<var>j</var> åã®é¢ãæã¡ïŒ<var>1,2,...,j</var> ã <var>1</var> ã€ãã€æžãããŠããïŒ</p>
<p>
JOI åã¯ã²ãŒã ã¯ãªã¢ã§ãããããªãµã€ã³ãã®ãã¡ïŒæãé¢ã®æ°ãå°ãªããµã€ã³ãã <var>1</var> åè²·ãããšã«ããïŒJOI åã¯ã©ã®ãµã€ã³ããè²·ãã°ããã ãããïŒ</p>
<h2> å¶çŽ</h2>
<ul>
<li><var>1 \leq N \leq100</var></li>
<li><var>0 \leq A_i \leq 1</var> (<var>1 \leq i \leq N</var>)</li>
</ul>
<h2>å
¥åã»åºå</h2>
<p>
<b>å
¥å</b><br>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ<br>
<var>N</var><br>
<var>A_1</var> <var>A_2</var> ... <var>A_N</var>
</p>
<p>
<b>åºå</b><br>
JOI åã賌å
¥ãã¹ããµã€ã³ãã®é¢ã®æ°ãçããïŒ<br>
<h2>å
¥åºåäŸ</h2>
<b>å
¥åäŸ 1</b><br>
<pre>
5
0 1 0 0 0
</pre>
<b>åºåäŸ 1</b><br>
<pre>
2
</pre>
<p>
åå
㯠<var>7</var> ãã¹ãããªãïŒ<var>3</var> ãã¹ç®ã®ã¿ã« <var>1</var> ãæžãããŠããïŒé¢ã®æ°ã <var>2</var> åã®ãµã€ã³ãã䜿ã£ãå ŽåïŒäŸãã°åºãç®ã <var>1,2,1,1,1</var> ãšãªã£ããšãã«ã²ãŒã ã¯ãªã¢ããããšãã§ããïŒãããæå°ãªã®ã§ <var>2</var> ãåºåããïŒ</p>
<hr>
<b>å
¥åäŸ 2</b><br>
<pre>
5
1 1 1 1 1
</pre>
<b>åºåäŸ 2</b><br>
<pre>
6
</pre>
<p>
åå
㯠<var>7</var> ãã¹ãããªãïŒã¹ã¿ãŒããšãŽãŒã«ä»¥å€ã®ãã¹å
šãŠã« <var>1</var> ãæžãããŠããïŒãã®ãšãïŒé¢ã®æ°ã <var>6</var> åã®ãµã€ã³ããå¿
èŠã§ããïŒãããæå°ãªã®ã§ <var>6</var> ãåºåããïŒ</p>
<hr>
<b>å
¥åäŸ 3</b><br>
<pre>
7
0 0 1 0 1 1 0
</pre>
<b>åºåäŸ 3</b><br>
<pre>
3
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2017/2018-yo/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 17 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2017/2018 äºéžç«¶æèª²é¡ã</a>
</p>
|
p02558 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected graph with <var>N</var> vertices and <var>0</var> edges. Process <var>Q</var> queries of the following types.</p>
<ul>
<li><code>0 u v</code>: Add an edge <var>(u, v)</var>.</li>
<li><code>1 u v</code>: Print <var>1</var> if <var>u</var> and <var>v</var> are in the same connected component, <var>0</var> otherwise.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 200,000</var></li>
<li><var>1 \leq Q \leq 200,000</var></li>
<li><var>0 \leq u_i, v_i \lt 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>Q</var>
<var>t_1</var> <var>u_1</var> <var>v_1</var>
<var>t_2</var> <var>u_2</var> <var>v_2</var>
:
<var>t_Q</var> <var>u_Q</var> <var>v_Q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºå</h3><p>For each query of the latter type, print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 7
1 0 1
0 0 1
0 2 3
1 0 1
1 1 2
0 0 2
1 1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0
1
0
1
</pre></section>
</div>
</span> |
p03719 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given three integers <var>A</var>, <var>B</var> and <var>C</var>.
Determine whether <var>C</var> is not less than <var>A</var> and not greater than <var>B</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>-100â€A,B,Câ€100</var> </li>
<li><var>A</var>, <var>B</var> and <var>C</var> are all integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If the condition is satisfied, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<p><var>C=2</var> is not less than <var>A=1</var> and not greater than <var>B=3</var>, and thus the output should be <code>Yes</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<p><var>C=4</var> is less than <var>A=6</var>, and thus the output should be <code>No</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
</pre></section>
</div>
</span> |
p01724 |
<p>è² ããå«ãã®ã€ã¯ã¿åã¯ãæè¿å²ç¢ç€ã䜿ã£ãŠéã¶ã²ãŒã ã«ç±äžããŠããã
ããããå²ç¢ãäºç®äžŠã¹ãå人ã«å
šãåãŠãªãã®ã§ãããŸãæåã§ãªã Phutball ãšããã²ãŒã ã®ç¹èšãããããšã«ããã
</p>
<p>ãã®ã²ãŒã ã¯é£ããã²ãŒã ãªã®ã§ãæå§ãã«èªåã®ã¿ãŒã³ã«åã£ãŠçµå±ã§ããããå€å®ã§ããããã«ç¹èšããããšã«ããã
</p>
<p>ã²ãŒã ã®å婿¡ä»¶ã¯ä»¥äžã®ãããªãã®ã§ããã
</p>
<ul>
<li> çœç³ã¯é»ç³ã®çœ®ãããŠããå Žæã«ãžã£ã³ãããããšã¯åºæ¥ãªãã
</li>
<li> ç¢ç€ã®äžå€®ã®<var> 19 × 15 </var>ã®éšåãçšããã
</li>
<li> å婿¡ä»¶ãå€å®ãããç¢ç€ã¯çœç³ã1ã€ãšé»ç³ãããã€ã眮ãããç¶æ
ã§äžããããã
</li>
<li> ãŽãŒã«å°ç¹ãšããã®ã¯ç¢ç€ã®äžç«¯ãããã®äžåŽãæããïŒäžå³ãåç
§ãããïŒ
</li>
<li> ãŽãŒã«å°ç¹ã«çœç³ãéã¹ã°åå©ããã
</li>
<li> åå©ããããã«ä»¥äžã®ãããªããšãè¡ãã
<ul>
<li> çœç³ã¯1å以äžãžã£ã³ããè¡ãããšãã§ããã
</li>
<li> ãžã£ã³ãã¯çœç³ã«é£æ¥ãã8æ¹åïŒäžäžå·Šå³ãšæãäžãæãäžïŒã®é»ç³ã®ã©ãããé£ã³è¶ããããšã§è¡ããã
</li>
<li> é»ç³ã飿¥ããŠããªãæ¹åãžãžã£ã³ãããããšã¯åºæ¥ãªãã
</li>
<li> é£ã³è¶ããããé»ç³ã¯ã1åã®ãžã£ã³ãããšã«ç¢ç€ã®äžããåãé€ãããã
</li>
<li> ãžã£ã³ãããããšã®çœç³ã¯ãŽãŒã«å°ç¹ãã²ãŒã ç€ã®äžã«ååšããªããã°ãããªãã
</li>
<li> é»ç³ã2å以äžé£ç¶ããŠããŠããã¡ããã©ããããŸããããã«ãžã£ã³ãã§ããã
</li>
<li> çœç³ã¯é»ç³ã®çœ®ãããŠããå Žæã«ãžã£ã³ãããããšã¯åºæ¥ãªãã(ãžã£ã³ãããæ¹åã«é£ç¶ããŠããé»ç³ã¯å¿
ãé£ã³è¶ããªããŠã¯ãªããªãã)
</li></ul>
</li></ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Phutball_phut1" height="280" width="410">
<br><br>
<p>å³ã®äžžå°ãã€ããŠããå Žæãžã¯ãžã£ã³ãããããšãå¯èœã§ãããå
šãŠãŽãŒã«å°ç¹ã§ããããããå°ã®å Žæã¯ãŽãŒã«å°ç¹ã§ããªããç¢ç€ã®å
åŽã§ããªãã®ã§ããžã£ã³ãããããšã¯åºæ¥ãªãã
</p>
<p>ããªãã®ä»äºã¯ã€ã¯ã¿åã®ç¹èšãæå©ãããããã«ããŽãŒã«ã§ãããã©ããã®å€å®ãšããŽãŒã«ããããã®æå°ã®ãžã£ã³ãåæ°ãæ±ããããã°ã©ã ãæžããŠãããäºã§ããã
</p>
<h2>Input</h2>
<p><span>.OX</span>ã§æ§æããã<var>19 × 15</var>ã®ç€é¢ã19è¡ã§äžããããã
åè¡ã¯å¿
ã15æåãããªããåæåã¯æ¬¡ã衚ãã
</p>
<ul><li>"."ã¯ç©ºçœã衚ãã
</li><li>"O"ã¯çœç³ã衚ãã
</li><li>"X"ã¯é»ç³ã衚ãã
</li></ul>
<h3>Constraints</h3>
<ul><li> é»ç³ã®æ°ã20以äžã
</li><li> çœç³ã¯å¿
ã1ã€ã ãååšããã
</li><li> ãã§ã«ãŽãŒã«ããç¶æ
ãå
¥åãããããšã¯ãªãã
</li></ul>
<h2>Output</h2>
<p>ãŽãŒã«å¯èœãªãæçã®ææ°ã1è¡ã«åºåããããŽãŒã«ããããšãäžå¯èœãªå Žåã¯-1ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
......O........
......X........
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>1
</pre>
<ul><li>çœç³ã¯é»ç³ã1åãžã£ã³ãããŠãŽãŒã«ããããšãã§ããã
</li></ul>
<h2>Sample Input 2</h2>
<pre>...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
......O........
...............
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>-1
</pre>
<ul><li> çœç³ã¯ç§»åã§ããªãã®ã§ãŽãŒã«ã§ããªãã
</li></ul>
<h2>Sample Input 3</h2>
<pre>...............
...............
...............
...............
...............
...............
...............
...............
...........O...
............X..
.............X.
.............X.
.............X.
...............
..............X
.........X.....
.............X.
......X....X..X
.....X.X.XX.X..
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>6
</pre>
<ul><li> ã¡ããã©6åã§ãŽãŒã«ã§ããã
</li></ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Phutball_sample3" height="391" width="418">
<br><br>
<ul><li> ãžã£ã³ãæ¯ã«åè§£ããç»åã以äžã«ç€ºãã
</li></ul>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Phutball_a" height="314" width="847">
<br><br>
<h2>Sample Input 4</h2>
<pre>...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
.....XX........
.....XXXO......
......X........
</pre>
<h2>Output for the Sample Input 4</h2>
<pre>4
</pre> |
p00836 |
<H1><font color="#000">Problem A:</font> Sum of Consecutive Prime Numbers</H1>
<p>
Some positive integers can be represented by a sum of one or more consecutive prime numbers.
How many such representations does a given positive integer have? For example, the integer 53
has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations
2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is
3. The integer 20 has no such representations. Note that summands must be consecutive prime
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
</p>
<p>
Your mission is to write a program that reports the number of representations for the given
positive integer.
</p>
<H2>Input</H2>
<p>
The input is a sequence of positive integers each in a separate line. The integers are between 2
and 10 000, inclusive. The end of the input is indicated by a zero.
</p>
<H2>Output</H2>
<p>
The output should be composed of lines each corresponding to an input line except the last zero.
An output line includes the number of representations for the input integer as the sum of one
or more consecutive prime numbers. No other characters should be inserted in the output.
</p>
<H2>Sample Input</H2>
<pre>
2
3
17
41
20
666
12
53
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
1
2
3
0
0
1
2
</pre>
|
p03349 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Find the number of the possible tuples of sequences <var>(A_0,A_1,...,A_N)</var> that satisfy all of the following conditions, modulo <var>M</var>:</p>
<ul>
<li>For every <var>i</var> <var>(0\leq i\leq N)</var>, <var>A_i</var> is a sequence of length <var>i</var> consisting of integers between <var>1</var> and <var>K</var> (inclusive);</li>
<li>For every <var>i</var> <var>(1\leq i\leq N)</var>, <var>A_{i-1}</var> is a subsequence of <var>A_i</var>, that is, there exists <var>1\leq x_i\leq i</var> such that the removal of the <var>x_i</var>-th element of <var>A_i</var> would result in a sequence equal to <var>A_{i-1}</var>;</li>
<li>For every <var>i</var> <var>(1\leq i\leq N)</var>, <var>A_i</var> is lexicographically larger than <var>A_{i-1}</var>.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,K \leq 300</var></li>
<li><var>2 \leq M \leq 10^9</var></li>
<li><var>N</var>, <var>K</var> and <var>M</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible tuples of sequences <var>(A_0,A_1,...,A_N)</var>, modulo <var>M</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>Five tuples below satisfy the conditions:</p>
<ul>
<li><var>(),(1),(1,1)</var></li>
<li><var>(),(1),(1,2)</var></li>
<li><var>(),(1),(2,1)</var></li>
<li><var>(),(2),(2,1)</var></li>
<li><var>(),(2),(2,2)</var></li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3 999999999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>358
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>150 150 998244353
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>186248260
</pre></section>
</div>
</span> |
p01374 |
<!-- begin en only -->
<!--<h3><U>Sakura Poetry</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>
Nathan O. Davis ã¯éç©åè·¯ã³ãŒã¹ã®åŠçã§ããïŒ
</p>
<p>
Nathan ã¯è¶³ããªãåäœãè£å
ããããã«ïŒæ¥æ¬æåã«é¢ããææ¥ã履修ããŠããïŒä»æ¥ã®èª²é¡ã¯è©©ã®äœæã§ããïŒ
</p>
<p>
Nathan ã¯å匷äžè¶³ã§æ¥æ¬èªãäžåŸæãªããïŒããã°ã©ã ã«è©©ãèªåçæãããããšèããïŒæå§ãã«åœŒã¯ïŒæ¥æ¬èªã®åèªã®æ¥ç¶èŸæžãå
¥æããïŒ
ããšã¯åèªã®æ¥ç¶ã«ãããã£ãŠã©ã³ãã ãªæç« ãçæããã ãã§ããïŒ
</p>
<p>
ããããªããïŒã©ã³ãã ã«çæãããå
šãŠã®æååãè©©ãšããŠèªããããããã§ã¯ãªãïŒ
è©©ã«ã¯ïŒããã€ãã®å£èªã®ãã¡1ã€ãïŒäžåºŠã ãçŸããŠããªããã°ãªããªãïŒããå£èªã2å以äžåºçŸããããšãïŒ2çš®é¡ä»¥äžã®å£èªã1åãã€åºçŸããããšã¯èš±ãããªãïŒ
ãŸãïŒå£èªã¯åèªã®æ¥ç¶ã®å¢çããŸããã§åºçŸããŠãããïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒå
¥åã§äžããããåèªã®æ¥ç¶èŸæžãšå£èªã®ãªã¹ãããïŒæå®ãããé·ãã®è©©ãäœéãã«äœãããããæ±ããããã°ã©ã ãäœæããããšã§ããïŒ
éãåèªãç¹ããŠè©©ãšãªãåãæååãåŸãããå ŽåïŒãããã¯éè€ããŠæ°ãäžãããã®ãšããïŒçãã¯éåžžã«å€§ãããªãããã®ã§ïŒ 1,000,000,007 ã§å²ã£ãäœããåºåããïŒ</p>
</p>
<!-- end ja only -->
</div>
<h3>Input</h3>
<div>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãå«ãã§ããïŒ1ã€ã®ãã¹ãã±ãŒã¹ã¯ïŒä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<blockquote>
<i>N</i> <i>M</i> <i>K</i><br/>
<i>from<sub>1</sub></i> <i>to<sub>1</sub></i><br/>
<i>from<sub>2</sub></i> <i>to<sub>2</sub></i><br/>
:<br/>
</i>from<sub>N</sub></i> <i>to<sub>N</sub></i><br/>
<i>seasonword<sub>1</sub></i><br/>
<i>seasonword<sub>2</sub></i><br/>
:<br/>
<i>seasonword<sub>K</sub></i>
</blockquote>
<p>
å
¥åã®æåã®è¡ã«ã¯3ã€ã®æŽæ° <i>N</i> (1 ≤ <i>N</i> ≤ 250), <i>M</i> (1 ≤ <i>M</i> ≤ 500), <i>K</i> (1 ≤ <i>K</i> ≤ 30) ãå«ãŸãïŒããããåèªã®æ¥ç¶èŸæžã®å€§ããïŒäœæãã¹ãè©©ã®é·ãïŒå£èªã®æ°ã衚ãïŒ
</p>
ç¶ã <i>N</i> è¡ã¯åèªã®æ¥ç¶èŸæžã®æ
å ±ã衚ãïŒ
åè¡ã¯2ã€ã®æåå <i>from<sub>i</sub></i> , <i>to<sub>i</sub></i> ãå«ã¿ïŒåèª <i>from<sub>i</sub></i> ã®åŸã«ç¶ããŠåèª <i>to<sub>i</sub></i> ãåºçŸããŠããããšããããšã衚ãïŒ
<i>to<sub>i</sub></i> ã®åŸã«ç¶ã㊠<i>from<sub>i</sub></i> ãåºçŸããŠããããšããããšã衚ããã®ã§ã¯ãªãããšã«æ³šæããïŒãŸãïŒ<i>from<sub>i</sub></i> ã§çµãããããªä»ã®æååã®åŸã«ç¶ã㊠<i>to<sub>i</sub></i> ãåºçŸããŠããããšããããšã衚ããã®ã§ããªãïŒè©©ã¯ïŒæ¥ç¶èŸæžã«å«ãŸããã©ã®åèªããå§ããŠãããïŒ
ç¶ã <i>K</i> è¡ã¯1ã€ã®æåå <i>seasonword<sub>i</sub></i> ãããªãïŒããããå£èªã衚ãïŒ
å
¥åäžã«çŸããæååã¯å
šãŠå°æåã®ã¢ã«ãã¡ããããããªãïŒãã®é·ã㯠1 ä»¥äž 20 以äžã§ããïŒ
æ¥ç¶èŸæžã®åé
ç®ïŒããã³å£èªã¯äºãã«ç°ãªãïŒ
ããªãã¡ïŒ <i>i</i> ≠ <i>j</i> ã«å¯Ÿã㊠<i>from<sub>i</sub></i> ≠ <i>from<sub>j</sub></i> ãŸã㯠<i>to<sub>i</sub></i> ≠ <i>to<sub>j</sub></i> ãæãç«ã€ïŒ
åæ§ã«ïŒ<i>i</i> ≠ <i>j</i> ã«å¯Ÿã㊠<i>seasonword<sub>i</sub></i> ≠ <i>seasonword<sub>j</sub></i> ãæãç«ã€ïŒ
å
¥åã®æ«å°Ÿã«ã¯ïŒå
¥åã®çµäºã衚ã 3 ã€ã® 0 ãããïŒ
</p>
<!-- end ja only -->
</div>
<h3>Output</h3>
<div>
<!-- begin ja only -->
<p>
çæãããç°ãªãè©©ã®æ°ã 1,000,000,007 ã§å²ã£ãäœãã1è¡ã«åºåããïŒ
å
ã«èšåããããã«ïŒéãåèªãç¹ããŠè©©ãšãªãåãæååãåŸãããå ŽåïŒãããã¯éè€ããŠæ°ãäžãããã®ãšããïŒ
å³å¯ã«èšãã°ïŒ2ã€ã®è©© <i>s</i>, <i>t</i> ãããïŒããããåèªã®å [<i>a<sub>1</sub></i> , <i>a<sub>2</sub></i> , ..., <i>a<sub>n</sub></i> ], [<i>b<sub>1</sub></i> , <i>b<sub>2</sub></i> , ..., <i>b<sub>m</sub></i> ] ãé ã«é£çµããŠåŸããããã®ã§ãããšãïŒ
<i>n</i> = <i>m</i> ãã€ãã¹ãŠã® 1 ≤ <i>i</i> ≤ <i>n</i> ã«å¯Ÿã㊠<i>a<sub>i</sub></i> = <i>b<sub>i</sub></i> ã§ãããšãïŒãŸããã®ãšãã«éã£ãŠïŒ2ã€ã®è©© <i>s</i>, <i>t</i> ã¯åäžã®è©©ãšã¿ãªãããïŒ
</p>
<!-- end ja only -->
</div>
<h3>Sample Input</h3>
<div>
<pre>
4 64 2
negawakuha hananoshitanite
hananoshitanite harushinan
harushinan sonokisaragino
sonokisaragino mochizukinokoro
sakura
hana
2 15 2
naha naha
naha gachoon
sakura
hana
3 7 2
asakur a
a sakura
asa kura
sakura
hana
9 100 2
a a
a h
a n
h a
h h
h n
n a
n h
n n
sakura
hana
4 2 2
a a
a b
b a
b b
ab
b
4 7 4
i cpc
mi cp
ac mi
cp c
ac
wa
tle
re
0 0 0
</pre>
</div>
<h3>Output for the Sample Input</h3>
<div>
<pre>
1
1
3
715991824
1
1
</pre>
</div> |
p03963 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> balls placed in a row.
AtCoDeer the deer is painting each of these in one of the <var>K</var> colors of his paint cans.
For aesthetic reasons, any two adjacent balls must be painted in different colors.</p>
<p>Find the number of the possible ways to paint the balls.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1âŠNâŠ1000</var></li>
<li><var>2âŠKâŠ1000</var></li>
<li>The correct answer is at most <var>2^{31}-1</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the possible ways to paint the balls.</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>2
</pre>
<p>We will denote the colors by <var>0</var> and <var>1</var>. There are two possible ways: we can either paint the left ball in color <var>0</var> and the right ball in color <var>1</var>, or paint the left in color <var>1</var> and the right in color <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
<p>Since there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.</p></section>
</div>
</span> |
p02671 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>3^N</var> people dancing in circle.
We denote with <var>0,1,\dots, 3^{N}-1</var> the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person.</p>
<p>The people are going to dance on two kinds of songs: salsa and rumba.</p>
<ul>
<li>When a salsa is played, the person in position <var>i</var> goes to position <var>j</var>, where <var>j</var> is the number obtained replacing all digits <var>1</var> with <var>2</var> and all digits <var>2</var> with <var>1</var> when reading <var>i</var> in base <var>3</var> (e.g., the person in position <var>46</var> goes to position <var>65</var>).</li>
<li>When a rumba is played, the person in position <var>i</var> moves to position <var>i+1</var> (with the identification <var>3^N = 0</var>).</li>
</ul>
<p>You are given a string <var>T=T_1T_2\cdots T_{|T|}</var> such that <var>T_i=</var><code>S</code> if the <var>i</var>-th song is a salsa and <var>T_i=</var><code>R</code> if it is a rumba.
After all the songs have been played, the person that initially was in position <var>i</var> is in position <var>P_i</var>.
Compute the array <var>P_0,P_1,\dots, P_{3^N-1}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \le N \le 12</var></li>
<li><var>1 \le |T| \le 200,000</var></li>
<li><var>T</var> contains only the characters <code>S</code> and <code>R</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>T</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>You should print on Standard Output:</p>
<pre><var>P_0</var> <var>P_1</var> <var>\cdots</var> <var>P_{3^N-1}</var>
</pre>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1
SRS
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2 0 1
</pre>
<p>Before any song is played, the positions are: <var>0</var>, <var>1</var>, <var>2</var>.</p>
<p>When we say "person <var>i</var>", we mean "the person that was initially in position <var>i</var>".</p>
<ol>
<li>After the first salsa, the positions are: <var>0</var>, <var>2</var>, <var>1</var>.</li>
<li>After the rumba, the positions are: <var>1</var>, <var>0</var>, <var>2</var> (so, person <var>0</var> is in position <var>1</var>, person <var>1</var> is in position <var>0</var> and person <var>2</var> is in position <var>2</var>).</li>
<li>After the second salsa, the positions are <var>2</var>, <var>0</var>, <var>1</var> (so, person <var>0</var> is in position <var>2</var>, person <var>1</var> is in position <var>0</var> and person <var>2</var> is in position <var>1</var>).</li>
</ol>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
RRSRSSSSR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3 8 1 0 5 7 6 2 4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
SRSRRSRRRSRRRR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>23 9 22 8 3 7 20 24 19 5 18 4 17 12 16 2 6 1 14 0 13 26 21 25 11 15 10
</pre></section>
</div>
</span> |
p02221 | <span class="lang">
<span class="lang-ja">
<h1>K: ããŒãã¡ã³ã</h1>
<div class="part">
<section>
<h3>å顿</h3><p>京éœå€§åŠã¯ã¹ããåã«ãŠã$2$ 人çšå¯ŸæŠã²ãŒã ã®ããŒãã¡ã³ããè¡ãããããšããŠããŸãã</p>
<p>ãã®ããŒãã¡ã³ãã®åå è
㯠$2^N$ 人ããŠã $1$ ãã $2^N$ ãŸã§ã®çªå·ãã€ããŠããŸãã</p>
<p>åå è
ã®ãã¡ã® $2$ äººãæŠã£ãæã®åæã¯ã$0$ ãš $1$ ãããªãé·ã $2^N-1$ ã®æåå $S$ ã«ãã£ãŠè¡šãããŸãã</p>
<p>人 $x$ ãšäºº $y$ $(1 \le x < y \le 2^N)$ ãæŠã£ããšãã</p>
<ul>
<li>$S_{y-x} = 0$ ã®ãšãã人 $x$ ãåã¡ã </li>
<li>$S_{y-x} = 1$ ã®ãšãã人 $y$ ãåã€</li>
</ul>
<p>ããšãåãã£ãŠããŸãã</p>
<p>ããŒãã¡ã³ãã¯åå è
ãäžåã«äžŠã¶ããšã§å§ãŸãã以äžã®éãã«é²è¡ããŸãã</p>
<ol>
<li>åã®å
é ãã $2$ 人ãã€ãã¢ãäœãããã¹ãŠã®ãã¢ã«ã€ããŠããã¢å
ã® $2$ äººãæŠãã</li>
<li>1 ã®å¯ŸæŠã§åã£ã人ã¯åã«æ®ããè² ãã人ã¯åããæããã</li>
<li>æ®ã£ãŠãã人ã $2$ 人以äžãããšãã¯ãåãè©°ã㊠1 ã«æ»ãã</li>
<li>æ®ã£ãŠãã人ã $1$ 人ãšãªã£ããããã®äººãåªåè
ãšãªãã</li>
</ol>
<p>ããŸãåå è
ã¯åæç¶æ
ãšããŠãå
é ãã $i$ çªç® $(1 \le i \le 2^N)$ ã人 $P_i$ ãšãªãããã«äžŠãã§ããŸãã</p>
<p>$0 \le k \le 2^N-1$ ãæºãããã¹ãŠã®æŽæ° $k$ ã«ã€ããŠã以äžã®åé¡ãè§£ããŠãã ããã</p>
<ul>
<li>åæç¶æ
ããå
é $k$ 人ãããã®é çªãå€ããã«åã®æ«å°Ÿã«ç§»åããã<ul>
<li>ã€ãŸããç§»ååŸã®åã«ãããåå è
ã®çªå·ãå
é ããæããŠãããšã $P_{k+1}, P_{k+2}, ..., P_{2^N}, P_1, P_2, ..., P_k$ ãšãªãã</li>
</ul>
</li>
<li>ç§»ååŸã®åããããŒãã¡ã³ããå§ãããšãã®ãåªåè
ã®çªå·ãæ±ããã</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>å¶çŽ</h3><ul>
<li>$1 \leq N \leq 18$</li>
<li>$N$ ã¯æŽæ°ã§ããã</li>
<li>$S$ 㯠$0$ ãš $1$ ãããªãé·ã $2^N-1$ ã®æååã§ããã</li>
<li>$P$ 㯠$1$ ãã $2^N$ ãŸã§ã®æŽæ°ãäžŠã¹æ¿ããé åã§ããã</li>
</ul>
</section>
</div>
<hr />
<div class="io-style">
<div class="part">
<section>
<h3>å
¥å</h3><p>å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã</p>
<pre>$N$
$S_1S_2 \ldots S_{2^N-1}$
$P_1$ $P_2$ $\ldots$ $P_{2^N}$
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºå</h3><p>$2^N$ è¡åºåããã</p>
<p>$i$ è¡ç® $(1 \le i \le 2^N)$ ã«ã¯ã$k = i-1$ ãšãããšãã®äžèšã®åé¡ã®çããåºåããã</p>
</section>
</div>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ1</h3><pre>2
100
1 4 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ1</h3><pre>1
2
1
2
</pre>
<p>äŸãã° $k = 2$ ãšãããšããç§»ååŸã®åã«ãããåå è
ã®çªå·ãå
é ããæããŠãããšã $2, 3, 1, 4$ ãšãªããŸãã</p>
<p>人 $2$ 㚠人 $3$ ãæŠããšã $S_1 = 1$ ãã人 $3$ ãåã¡ãŸãã</p>
<p>人 $1$ 㚠人 $4$ ãæŠããšã $S_3 = 0$ ãã人 $1$ ãåã¡ãŸãã</p>
<p>人 $3$ 㚠人 $1$ ãæŠããšã $S_2 = 0$ ãã人 $1$ ãåã¡ãŸãã</p>
<p>ãããã£ãŠã $k = 2$ ã®å Žåã®åªåè
ã¯ã人 $1$ ãšãªããŸãã</p>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ2</h3><pre>4
101011100101000
8 15 2 9 12 5 1 7 14 10 11 3 4 6 16 13
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ2</h3><pre>16
1
16
2
16
12
10
14
16
1
16
2
16
12
10
14
</pre>
</section>
</div>
<hr />
<div class="part">
<section>
<h3>å
¥åäŸ3</h3><pre>1
0
1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>åºåäŸ3</h3><pre>1
1
</pre></section>
</div>
</span>
</span>
|
p03060 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> gems. The value of the <var>i</var>-th gem is <var>V_i</var>.</p>
<p>You will choose some of these gems, possibly all or none, and get them.</p>
<p>However, you need to pay a cost of <var>C_i</var> to get the <var>i</var>-th gem.</p>
<p>Let <var>X</var> be the sum of the values of the gems obtained, and <var>Y</var> be the sum of the costs paid.</p>
<p>Find the maximum possible value of <var>X-Y</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 20</var></li>
<li><var>1 \leq C_i, V_i \leq 50</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>V_1</var> <var>V_2</var> <var>...</var> <var>V_N</var>
<var>C_1</var> <var>C_2</var> <var>...</var> <var>C_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible value of <var>X-Y</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
10 2 5
6 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>If we choose the first and third gems, <var>X = 10 + 5 = 15</var> and <var>Y = 6 + 4 = 10</var>.
We have <var>X-Y = 5</var> here, which is the maximum possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
13 21 6 19
11 30 6 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>6
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1
1
50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre></section>
</div>
</span> |
p03430 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has decided to give a string to his mother.</p>
<p>The <em>value</em> of a string <var>T</var> is the length of the longest common subsequence of <var>T</var> and <var>T'</var>, where <var>T'</var> is the string obtained by reversing <var>T</var>.
That is, the value is the longest length of the following two strings that are equal: a subsequence of <var>T</var> (possibly non-contiguous), and a subsequence of <var>T'</var> (possibly non-contiguous).</p>
<p>Takahashi has a string <var>S</var>. He wants to give her mother a string of the highest possible value, so he would like to change at most <var>K</var> characters in <var>S</var> to any other characters in order to obtain a string of the highest possible value.
Find the highest possible value achievable.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 300</var></li>
<li><var>0 \leq K \leq |S|</var></li>
<li><var>S</var> consists of lowercase English letters.</li>
<li><var>K</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>S</var>
<var>K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the highest possible value achievable.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>abcabcabc
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>7
</pre>
<p>Changing the first character to <code>c</code> results in <code>cbcabcabc</code>.
Let this tring be <var>T</var>, then one longest common subsequence of <var>T</var> and <var>T'</var> is <code>cbabcbc</code>, whose length is <var>7</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>atcodergrandcontest
3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>15
</pre></section>
</div>
</span> |
p01118 | <!--<h2>Problem B</h2>-->
<!-- begin en only -->
<h3>On-Screen Keyboard</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
You are to input a string with an OSK (on-screen keyboard).
A remote control with five buttons, four arrows and an OK (Fig. B-1),
is used for the OSK.
Find the minimum number of button presses required
to input a given string with the given OSK.
</p>
<!-- end en only -->
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B1.png">
<figcaption style="padding-top: 10px" align="center">
<!-- begin en only -->
Fig. B-1 Remote control
<!-- end en only -->
</figcaption>
</center>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-0.png">
<figcaption style="padding-top: 10px" align="center">
<!-- begin en only -->
Fig. B-2 An on-screen keyboard
<!-- end en only -->
</figcaption>
</center>
<center>
<!-- begin en only -->
<table border=1>
<thead>
<tr><th>Character to input</th><th>Move of highlighted cells</th><th>Button presses</th></tr>
</thead>
<tbody>
<tr><td align="center"><tt>I</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-1.png"></td><td>→,→,→,→,→,→,→,→,OK (9 presses)</td></tr>
<tr><td align="center"><tt>C</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-2.png"></td><td>←,←,←,←,←,←,OK (7 presses)</td></tr>
<tr><td align="center"><tt>P</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-3.png"></td><td>↓,→,→,→,→,OK (6 presses)</td></tr>
<tr><td align="center"><tt>C</tt></td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2019_B2-4.png"></td><td>↑,←,←,←,←,OK (6 presses)</td></tr>
</tbody>
</table>
<!-- end en only -->
<figcaption style="padding-top: 10px" align="center">
<!-- begin en only -->
Fig. B-3 The minimum steps to input “<tt>ICPC</tt>” with the OSK in Fig. B-2
<!-- end en only -->
</figcaption>
</center>
<!-- begin en only -->
<p>
The OSK has cells arranged in a grid, each of which has a
character in it or is empty.
No two of the cells have the same character.
</p>
<p>
One of the cells of the OSK is highlighted, and
pressing the OK button will input the character in that cell,
if the cell is not empty.
</p>
<p>
Initially, the cell at the top-left corner is highlighted.
Pressing one of the arrow buttons will change the highlighted cell
to one of the adjacent cells in the direction of the arrow.
When the highlighted cell is on an edge of the OSK,
pushing the arrow button with the direction to go out of the edge
will have no effect.
</p>
<p>
For example, using the OSK with its arrangement shown in Fig. B-2,
a string “<tt>ICPC</tt>” can be input with 28 button presses
as shown in Fig. B-3, which is the minimum number of presses.
</p>
<p>
Characters in cells of the OSKs are any of a lowercase letter
(‘<tt>a</tt>’, ‘<tt>b</tt>’, ..., ‘<tt>z</tt>’),
an uppercase letter
(‘<tt>A</tt>’, ‘<tt>B</tt>’, ..., ‘<tt>Z</tt>’),
a digit
(‘<tt>0</tt>’, ‘<tt>1</tt>’, ..., ‘<tt>9</tt>’),
a comma (‘<tt>,</tt>’),
a hyphen (‘<tt>-</tt>’),
a dot (‘<tt>.</tt>’),
a slash (‘<tt>/</tt>’),
a colon (‘<tt>:</tt>’),
a semicolon (‘<tt>;</tt>’),
or an at sign (‘<tt>@</tt>’).
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of at most 100 datasets, each in the following format.
</p>
<!-- end en only -->
<p>
<blockquote>
<p>
<i>h w</i><br>
<i>r</i><sub>1</sub><br>
...<br>
<i>r</i><sub>h</sub><br>
<i>s</i>
</p>
</blockquote>
</p>
<!-- begin en only -->
<p>
The two integers <i>h</i> and <i>w</i> in the first line are
the height and the width of the OSK, respectively.
They are separated by a space, and satisfy 1 ≤ <i>h</i> ≤ 50 and 1 ≤ <i>w</i> ≤ 50.
</p>
<p>
Each of the next <i>h</i> lines gives a row of the OSK.
The <i>i</i>-th row, <i>r</i><sub>i</sub> is a string of length <i>w</i>.
The characters in the string corresponds to the characters
in the cells of the <i>i</i>-th row of the OSK
or an underscore (‘<tt>_</tt>’) indicating an empty cell,
from left to right.
</p>
<p>
The given OSK satisfies the conditions stated above.
</p>
<p>
The next line is a string <i>s</i> to be input. Its length is between 1 and 1000, inclusive.
All the characters in <i>s</i> appear in the given OSK.
Note that <i>s</i> does not contain underscores.
</p>
<p>
The end of the input is indicated by a line containing two zeros.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output a single line containing an integer indicating the minimum number of button presses required to input the given string with the given OSK.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
3 9
ABCDEFGHI
JKLMNOPQR
STUVWXYZ_
ICPC
5 11
___________
____A______
________M__
___________
_C_________
ACM
4 21
1_2_3_4_5_6_7_8_9_0_-
QqWwEeRrTtYyUuIiOoPp@
AaSsDdFfGgHhJjKkLl;_:
ZzXxCcVvBbNnMm,_._/__
ICPC2019,AsiaYokohamaRegional,QualificationRound
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
28
23
493
</pre>
|
p03125 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given positive integers <var>A</var> and <var>B</var>.</p>
<p>If <var>A</var> is a divisor of <var>B</var>, print <var>A + B</var>; otherwise, print <var>B - A</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq A \leq B \leq 20</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If <var>A</var> is a divisor of <var>B</var>, print <var>A + B</var>; otherwise, print <var>B - A</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>16
</pre>
<p>As <var>4</var> is a divisor of <var>12</var>, <var>4 + 12 = 16</var> should be printed.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>8 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>12
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>2
</pre>
<p><var>1</var> is a divisor of <var>1</var>.</p></section>
</div>
</span> |
p01548 |
<h1>åé¡å Audition</h1>
<p>ã¢ã€ãã«---ããã¯å¥³ã®åéã®æ°žé ã®æ§ããããããé ç¹ã«ç«ãŠãã®ã¯ã»ãã®äžæ¡ãããããªãµãã€ãã«ãªäžçã«ãããªãã¯ã¢ã€ãã«ãããã¥ãŒãµãŒãšããŠè¶³ãèžã¿å
¥ããããšã«ãªããŸããããããŠã仿¥ã¯ããªãã®æ
åœã¢ã€ãã«ãé£ããŠå€§äºãªãªãŒãã£ã·ã§ã³ã«æãããšã«ãªããŸããã
</p>
<p>ãªãŒãã£ã·ã§ã³ã®æ±ºãæã«ãªãã®ã¯ããžã¥ã¢ã«ããã³ã¹ãããŒã«ã«ã® 3 èŠçŽ ã§ãããªãŒãã£ã·ã§ã³äžã«ã¯ <var>m</var> åã®ã¢ããŒã«ã¿ã€ã ãããã 1 åã®ã¢ããŒã«ã¿ã€ã ããšã«åã¢ã€ãã«ã¯ããžã¥ã¢ã«ã¢ããŒã«ããã³ã¹ã¢ããŒã«ãããŒã«ã«ã¢ããŒã«ã®ãããããè¡ãããšãåºæ¥ãŸããããžã¥ã¢ã«ã¢ããŒã«ãè¡ããšãã®ã¢ã€ãã«ã®ããžã¥ã¢ã«ãã€ã³ãã¯åœŒå¥³ã®æã£ãŠãããžã¥ã¢ã«å€ã ãããã³ã¹ã¢ããŒã«ãè¡ããšãã³ã¹ãã€ã³ãã¯åœŒå¥³ã®æã£ãŠããã³ã¹å€ã ããããŒã«ã«ã¢ããŒã«ãè¡ããšããŒã«ã«ãã€ã³ãã¯åœŒå¥³ã®æã£ãŠãããŒã«ã«å€ã ãäžæããŸãã
</p>
<p><var>m</var> åã®ã¢ããŒã«ãçµäºããåŸã<var>N</var> 人ã®ã¢ã€ãã«ã®ãã¡ããžã¥ã¢ã«ãã€ã³ãã®é«ãã»ããã 3 人㯠5 ãªãŒãã£ã·ã§ã³ãã€ã³ãããã³ã¹ãã€ã³ãã®é«ãã»ããã 3 人㯠3 ãªãŒãã£ã·ã§ã³ãã€ã³ããããŒã«ã«ãã€ã³ãã®é«ãã»ããã 3 人㯠2 ãªãŒãã£ã·ã§ã³ãã€ã³ããç²åŸããŸããäžæ¹ãããžã¥ã¢ã«ãã€ã³ããæäžäœã ãšãªãŒãã£ã·ã§ã³ãã€ã³ã㯠1 ç¹æžç¹ããã³ã¹ãã€ã³ããæäžäœã ãšãªãŒãã£ã·ã§ã³ãã€ã³ã㯠1 ç¹æžç¹ãããŒã«ã«ãã€ã³ããæäžäœã ãšãªãŒãã£ã·ã§ã³ãã€ã³ã㯠1 ç¹æžç¹ãšãªããŸããïŒãªãŒãã£ã·ã§ã³ãã€ã³ãã1以äžã§ããããã 1 ç¹æžç¹ïŒã
</p>
<p>ãªãŒãã£ã·ã§ã³ã®å§ãã«ãåã¢ã€ãã«ã®ããžã¥ã¢ã«ãã€ã³ãããã³ã¹ãã€ã³ããããŒã«ã«ãã€ã³ãã¯ãããã 0 ã§ããããªãã¯ã¢ã€ãã« 1 ã®ãããã¥ãŒãµãŒã§ãã¢ããŒã«ã¿ã€ã ããšã«ã©ã®ã¢ããŒã«ãè¡ããæç€ºããããšãåºæ¥ãŸããã¢ã€ãã« 1 以å€ã®ã¢ã€ãã«ã¯ã¢ããŒã«ã¿ã€ã ããšã«ã©ã³ãã ã«ç確çã«ã©ããã®ã¢ããŒã«ãè¡ããŸãïŒã€ãŸããããã 3 åã® 1 ã®ç¢ºçã§è¡ãããïŒãã¢ã€ãã« 1 ã®ããžã¥ã¢ã«ããã³ã¹ãããŒã«ã«ã®ãã€ã³ããä»ã®ã¢ã€ãã«ãšçããå Žåãã¢ã€ãã« 1 ã¯åžžã«äžäœãšããŸããã¢ã€ãã« 1 ã®ç²åŸãããªãŒãã£ã·ã§ã³ãã€ã³ãã®æåŸ
å€ãæå€§ã«ãªãããã«æç€ºãããšãã®æåŸ
å€ãæ±ããŠäžãããã¢ã€ãã«ã®éåœã¯ãããªãã®æç€ºã«ããã£ãŠããŸãïŒ
</p>
<p>ã¡ãªã¿ã«ãæç€ºã¯ãªãŒãã£ã·ã§ã³ãå§ãŸãåã«å
šãŠè¡ã£ãŠããã®åŸãªãŒãã£ã·ã§ã³äžã®æç€ºã®å€æŽã¯åºæ¥ãªããã®ãšããŸããã€ãŸããä»ã®ã¢ã€ãã«ãããªãŒãã£ã·ã§ã³ãå§ãŸã£ãŠããã®ã¢ããŒã«ã§ã©ã®ã¢ããŒã«ãããããèŠãŠããããã®å Žåã«ãããŠã®æåŸ
å€ãæå€§ãšãªããããªæç€ºãåºãããšããããšã¯åºæ¥ãªããã®ãšããŸãã
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢ã§äžããããŸãã
</p><blockquote>
<var>n</var> <var>m</var><br><var>vi<sub>1</sub></var> <var>da<sub>1</sub></var> <var>vo<sub>1</sub></var><br><var>vi<sub>2</sub></var> <var>da<sub>2</sub></var> <var>vo<sub>2</sub></var><br>...<br><var>vi<sub>n</sub></var> <var>da<sub>n</sub></var> <var>vo<sub>n</sub></var><br></blockquote>
<p>1è¡ç®ã«ã¯ãªãŒãã£ã·ã§ã³ã«åºå Žããã¢ã€ãã«ã®æ° <var>n</var> (<var>4 ≤ n ≤ 2000</var>) ãšããã®ãªãŒãã£ã·ã§ã³ã«ãããã¢ããŒã«ã¿ã€ã ã®æ° <var>m</var> (<var>1 ≤ m ≤ 2000</var>) ãæžããŠãããŸããæ¬¡ã® <var>n</var> è¡ã«ã¯ããããã¢ã€ãã«iã®ããžã¥ã¢ã«å€ <var>vi<sub>i</sub></var>ããã³ã¹å€ <var>da<sub>i</sub></var>ãããŒã«ã«å€ <var>vo<sub>i</sub></var> (<var>1 ≤ vi<sub>i</sub>, da<sub>i</sub>, vo<sub>i</sub> ≤ 10,000</var>)ãæžããŠãããŸãã
</p>
<h2>Output</h2>
<p>ã¢ã€ãã« 1 ã®ç²åŸãããªãŒãã£ã·ã§ã³ãã€ã³ãã®æåŸ
å€ã®æå€§å€ã 1 è¡ã§åºåããªããã
</p>
<h2>Sample Input 1</h2>
<pre>4 1
1 1 1
1 1 1
1 1 1
1 1 1
</pre>
<h2>Output for the Sample Input 1</h2>
<pre>2.777777777778
</pre>
<p>ã©ã®ã¢ããŒã«ãè¡ã£ãŠãããã®ãžã£ã³ã«ã§ 3 äœä»¥å
ã«å
¥ãã確çã¯çããã§ããã 3 äœä»¥å
ã«å
¥ã£ãæã«è²°ãããªãŒãã£ã·ã§ã³ãã€ã³ããæãå€ãããžã¥ã¢ã«ã®ã¢ããŒã«ãè¡ãã®ããã£ãšãæåŸ
å€ãè¯ããªããŸãã
</p>
<h2>Sample Input 2</h2>
<pre>4 10
1 1 1
10 10 10
10 10 10
10 10 10
</pre>
<h2>Output for the Sample Input 2</h2>
<pre>-2.335340954780
</pre>
<p>éåžžã«å³ãããªãŒãã£ã·ã§ã³ãšãªãã§ãããã
</p>
<h2>Sample Input 3</h2>
<pre>9 9
13 5 19
19 21 37
15 1 7
7 11 15
21 23 25
33 29 19
13 19 11
21 5 15
7 13 1
</pre>
<h2>Output for the Sample Input 3</h2>
<pre>4.678837855075
</pre> |
p03575 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an undirected connected graph with <var>N</var> vertices and <var>M</var> edges that does not contain self-loops and double edges.<br/>
The <var>i</var>-th edge <var>(1 \leq i \leq M)</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>. </p>
<p>An edge whose removal disconnects the graph is called a <em>bridge</em>.<br/>
Find the number of the edges that are bridges among the <var>M</var> edges. </p>
</section>
</div>
<div class="part">
<section>
<h3>Notes</h3><ul>
<li>A <em>self-loop</em> is an edge <var>i</var> such that <var>a_i=b_i</var> <var>(1 \leq i \leq M)</var>.</li>
<li><em>Double edges</em> are a pair of edges <var>i,j</var> such that <var>a_i=a_j</var> and <var>b_i=b_j</var> <var>(1 \leq i<j \leq M)</var>.</li>
<li>An undirected graph is said to be <em>connected</em> when there exists a path between every pair of vertices.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 50</var></li>
<li><var>N-1 \leq M \leq min(N(Nâ1)â2,50)</var></li>
<li><var>1 \leq a_i<b_i \leq N</var></li>
<li>The given graph does not contain self-loops and double edges.</li>
<li>The given graph is connected.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format: </p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the edges that are bridges among the <var>M</var> edges.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>The figure below shows the given graph:</p>
<div style="text-align: center;">
<img alt="570677a9809fd7a5b63bff11e5d9bf79.png" src="https://img.atcoder.jp/abc075/570677a9809fd7a5b63bff11e5d9bf79.png">
</img></div>
<p>The edges shown in red are bridges. There are four of them.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3
1 2
1 3
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>It is possible that there is no bridge.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 5
1 2
2 3
3 4
4 5
5 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre>
<p>It is possible that every edge is a bridge.</p></section>
</div>
</span> |
p03826 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are two rectangles.
The lengths of the vertical sides of the first rectangle are <var>A</var>, and the lengths of the horizontal sides of the first rectangle are <var>B</var>.
The lengths of the vertical sides of the second rectangle are <var>C</var>, and the lengths of the horizontal sides of the second rectangle are <var>D</var>.</p>
<p>Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1â€Aâ€10^4</var></li>
<li><var>1â€Bâ€10^4</var></li>
<li><var>1â€Câ€10^4</var></li>
<li><var>1â€Dâ€10^4</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>A</var> <var>B</var> <var>C</var> <var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 5 2 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>15
</pre>
<p>The first rectangle has an area of <var>3Ã5=15</var>, and the second rectangle has an area of <var>2Ã7=14</var>.
Thus, the output should be <var>15</var>, the larger area.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>100 600 200 300
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>60000
</pre></section>
</div>
</span> |
p02734 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are a sequence of <var>N</var> integers <var>A_1</var>, <var>A_2</var>, <var>\ldots</var>, <var>A_N</var> and a positive integer <var>S</var>.<br/>
For a pair of integers <var>(L, R)</var> such that <var>1\leq L \leq R \leq N</var>, let us define <var>f(L, R)</var> as follows:<br/></p>
<ul>
<li><var>f(L, R)</var> is the number of sequences of integers <var>(x_1, x_2, \ldots , x_k)</var> such that <var>L \leq x_1 < x_2 < \cdots < x_k \leq R</var> and <var>A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S</var>.</li>
</ul>
<p>Find the sum of <var>f(L, R)</var> over all pairs of integers <var>(L, R)</var> such that <var>1\leq L \leq R\leq N</var>. Since this sum can be enormous, print it modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 3000</var></li>
<li><var>1 \leq S \leq 3000</var></li>
<li><var>1 \leq A_i \leq 3000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>S</var>
<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 sum of <var>f(L, R)</var>, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
2 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p>The value of <var>f(L, R)</var> for each pair is as follows, for a total of <var>5</var>.</p>
<ul>
<li><var>f(1,1) = 0</var></li>
<li><var>f(1,2) = 1</var> (for the sequence <var>(1, 2)</var>)</li>
<li><var>f(1,3) = 2</var> (for <var>(1, 2)</var> and <var>(3)</var>)</li>
<li><var>f(2,2) = 0</var></li>
<li><var>f(2,3) = 1</var> (for <var>(3)</var>)</li>
<li><var>f(3,3) = 1</var> (for <var>(3)</var>)</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 8
9 9 9 9 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>10 10
3 1 4 1 5 9 2 6 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>152
</pre></section>
</div>
</span> |
p00709 |
<H1>Square Carpets</H1>
<P>
Mr. Frugal bought a new house.
He feels deeply in love with his new house
because it has a comfortable living room
in which he can put himself completely at ease.
He thinks his new house is a really good buy.
</P>
<P>
But, to his disappointment,
the floor of its living room has some scratches on it.
</P>
<P>
The floor has a rectangle shape, covered with square panels.
He wants to replace all the scratched panels with flawless panels,
but he cannot afford to do so.
Then, he decides to cover all the scratched panels
with carpets.
</P>
<P>
The features of the carpets he can use are as follows.
</P>
<OL>
<LI> Carpets are square-shaped.
<LI> Carpets may overlap each other.
<LI> Carpets cannot be folded.
<LI> Different sizes of carpets are available.
Lengths of sides of carpets are multiples of that of the panels.
</OL>
<P>
The carpets must cover all the scratched panels,
but must not cover any of the flawless ones.
</P>
<P>
For example,
if the scratched panels are as shown in Figure 1,
at least 6 carpets are needed.
</P>
<CENTER>
<TABLE>
<TR>
<TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_carpets"></TD>
</TR>
<TR>
<TD ALIGN="center">Figure 1: Example Covering</TD>
</TR>
</TABLE>
</CENTER>
<P>
As carpets cost the same irrespective of their sizes,
Mr. Frugal would like to use as few number of carpets as possible.
</P>
<P>
Your job is to write a program which tells the minimum number
of the carpets to cover all the scratched panels.
</P>
<H2>Input</H2>
<P>
The input consists of multiple data sets.
As in the following, the end of the input is indicated by a line
containing two zeros.
</P>
<BLOCKQUOTE>
<I>DataSet</I><SUB>1</SUB><BR>
<I>DataSet</I><SUB>2</SUB><BR>
...<BR>
<I>DataSet</I><SUB><I>n</I></SUB><BR>
<TT>0</TT> <TT>0</TT>
</BLOCKQUOTE>
<P>
Each data set (<I>DataSet</I><SUB><I>i</I></SUB>) represents the
state of a floor. The format of a data set is as follows.
</P>
<BLOCKQUOTE>
<I>W</I> <I>H</I><BR>
<I>P</I><SUB>11</SUB> <I>P</I><SUB>12</SUB> <I>P</I><SUB>13</SUB> ... <I>P</I><SUB>1<I>W</I></SUB><BR>
<I>P</I><SUB>21</SUB> <I>P</I><SUB>22</SUB> <I>P</I><SUB>23</SUB> ... <I>P</I><SUB>2<I>W</I></SUB><BR>
...<BR>
<I>P</I><SUB><I>H</I>1</SUB> <I>P</I><SUB><I>H</I>2</SUB>
<I>P</I><SUB><I>H</I>3</SUB> ... <I>P</I><SUB><I>HW</I></SUB><BR>
</BLOCKQUOTE>
<P>
The positive integers <I>W</I> and <I>H</I> are the numbers of panels
on the living room
in the x- and y- direction, respectively.
The values of <I>W</I> and <I>H</I> are no more than 10.
The integer <I>P</I><SUB><I>yx</I></SUB> represents the state of the panel.
The value of <I>P</I><SUB><I>yx</I></SUB> means,
</P>
<BLOCKQUOTE>
<TT>0</TT>: flawless panel (must not be covered),<BR>
<TT>1</TT>: scratched panel (must be covered).
</BLOCKQUOTE>
<H2>Output</H2>
<P>
For each data set,
your program should output a line containing one integer which
represents the minimum number of the carpets to cover
all of the scratched panels.
</P>
<H2>Sample Input</H2>
<PRE>
4 3
0 1 1 1
1 1 1 1
1 1 1 1
8 5
0 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 1 1 1 1
0 1 1 1 0 1 1 1
8 8
0 1 1 0 0 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 0 0 1 1 0
10 10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 0 1 1 0 1 1 0 1
1 1 1 1 1 1 1 1 1 1
0 0
</PRE>
<H2>Output for the Sample Input</H2>
<PRE>
2
6
14
29
</PRE>
|
p02364 |
<H1>Minimum Spanning Tree</H1>
<br/>
<p>
Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph <var>G</var> = (<var>V</var>, <var>E</var>).
</p>
<H2>Input</H2>
<pre>
<var>|V|</var> <var>|E|</var>
<var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>w<sub>0</sub></var>
<var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>1</sub></var>
:
<var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>w<sub>|E|-1</sub></var>
</pre>
<p>
, where <var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., <var>|V|</var>-1 respectively.
</p>
<p>
<var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target verticess of <var>i</var>-th edge (undirected) and <var>w<sub>i</sub></var> represents the weight of the <var>i</var>-th edge.
</p>
<H2>Output</H2>
<p>
Print the sum of the weights of the Minimum Spanning Tree.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <var>|V|</var> ≤ 10,000</li>
<li>0 ≤ <var>|E|</var> ≤ 100,000</li>
<li>0 ≤ <var>w<sub>i</sub></var> ≤ 10,000</li>
<li>The graph is connected</li>
<li>There are no parallel edges</li>
<li>There are no self-loops</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4 6
0 1 2
1 2 1
2 3 1
3 0 1
0 2 3
1 3 5
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
<br/>
<H2>Sample Input 2</H2>
<pre>
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6
</pre>
<H2>Sample Output 2</H2>
<pre>
5
</pre> |
p00359 | <H1>Dungeon</H1>
<p>
Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of <var>W × H</var> squares. Each square is identified with its column and row number, thus the square located in the <var>x</var>-th column and the <var>y</var>-th row is represented as (<var>x</var>, <var>y</var>). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is (<var>W</var>-1, <var>H</var>-1).
</p>
<p>
Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times.
</p>
<ul>
<li> One-square movement in the up, down, left, or right direction within the board</li>
<li> Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom</li>
</ul>
<p>
BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBomâs behavior and it can move even to a square where an enemy character is located.
</p>
<p>
Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>W</var> <var>H</var> <var>N</var>
<var>x_1</var> <var>y_1</var>
<var>x_2</var> <var>y_2</var>
:
<var>x_N</var> <var>y_N</var>
</pre>
<p>
The first line provides the number of squares in the horizontal direction <var>W</var> (1 ≤ <var>W</var> ≤ 10<sup>5</sup>), in the vertical direction <var>H</var> (1 ≤ <var>H</var> ≤ 10<sup>5</sup>), and the number of enemy characters <var>N</var> (1 ≤ <var>N</var> ≤ 10<sup>5</sup>). Each of the subsequent <var>N</var> lines provides location information of the <var>i</var>-th enemy, column <var>x_i</var> (0 ≤ <var>x_i</var> ≤ <var>W</var>-1) and row <var>y_i</var> (0 ≤ <var>y_i</var> ≤ <var>H</var>-1). The number of enemy characters in a specific square can be either one or zero.
</p>
<h2>Output</h2>
<p>
Output the minimum Cost in a line.
</p>
<h2>Sample Input 1</h2>
<pre>
5 4 4
0 3
1 1
2 2
2 3
</pre>
<h2>Sample Output 1</h2>
<pre>
2
</pre>
<h2>Sample Input 2</h2>
<pre>
6 6 5
2 1
5 2
3 3
1 4
1 5
</pre>
<h2>Sample Output 2</h2>
<pre>
4
</pre>
<h2>Sample Input 3</h2>
<pre>
8 8 4
6 0
7 0
0 6
0 7
</pre>
<h2>Sample Output 3</h2>
<pre>
0
</pre>
|
p00477 |
<H1>åèšæé (Total Time)</H1>
<h2>åé¡</h2>
<p>
倪éå㯠3 ã«æã®åºã蚪ããããšãæ¥èª²ã«ããŠããïŒå®¶ãåºçºãïŒæ±ºãŸã£ãé çªã§ 3 ã«æã®åºãåã£ãåŸïŒå®¶ã«åž°ãïŒãšãã©ãïŒã¹ããããŠã©ããã䜿ã£ãŠïŒååºéãç§»åããã®ã«äœç§ããã£ãããèšãïŒãã®ç§æ°ãèšé²ããïŒ
</p>
<p>
ããæ¥ã®èšæž¬çµæãäžãããããšãïŒãã®æ¥ã®ç§»åæéã®åèšãäœåäœç§ããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠4 è¡ãããªãïŒ 1 è¡ã« 1 ã€ãã€æ£ã®æŽæ°ãæžãããŠããïŒ<br>
1 è¡ç®ã®æŽæ°ã¯å®¶ãã 1 ã€ç®ã®åºãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒ<br>
2 è¡ç®ã®æŽæ°ã¯ 1 ã€ç®ã®åºãã 2 ã€ç®ã®åºãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒ<br>
3 è¡ç®ã®æŽæ°ã¯ 2 ã€ç®ã®åºãã 3 ã€ç®ã®åºãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒ<br>
4 è¡ç®ã®æŽæ°ã¯ 3 ã€ç®ã®åºããå®¶ãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒãã ãïŒäžããããå
¥åããŒã¿ã«ãããŠã¯åèšç§»åæé㯠1 å 0 ç§ä»¥äžã§ 59 å 59 ç§ä»¥äžã§ããããšãä¿èšŒãããŠããïŒ<br>
</p>
<h2>åºå</h2>
<p>
åºå㯠2 è¡ãããªãïŒx å y ç§ (1 ≤ x ≤ 59 , 0 ≤ y ≤ 59 )ã®ãšãïŒ 1è¡ç®ã« x ãïŒ2è¡ç®ã« y ãåºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
31
34
7
151
</pre>
<h3>åºåäŸ 1</h3>
<pre>
3
43
</pre>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
316
430
643
1253
</pre>
<h3>åºåäŸ 2</h3>
<pre>
44
2
</pre>
<br>
<h3>å
¥åäŸ 3</h3>
<pre>
5
10
15
30
</pre>
<h3>åºåäŸ 3</h3>
<pre>
1
0
</pre>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
<br>
|
p00027 |
<H1>What day is today?</H1>
<p>
Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29.
</p>
<H2>Input</H2>
<p>
The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset consists of two integers <var>m</var> and <var>d</var> separated by a single space in a line. These integers respectively represent the month and the day.
</p>
<p>
The number of datasets is less than or equal to 50.
</p>
<H2>Output</H2>
<p>
For each dataset, print the day (please see the following words) in a line.
</p>
<pre>
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
</pre>
<H2>Sample Input</H2>
<pre>
1 1
2 29
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Thursday
Sunday
</pre>
|
p01266 |
<H1><font color="#000">Problem H:</font> Robot Communication</H1>
<p>
In the year 21xx, human beings are proliferating across the galaxy. Since the end of the last century,
thousands of pioneer spaceships have been launched in order to discover new habitation planets.
</p>
<p>
The Presitener is one of those spaceships, heading toward the Andromeda galaxy. After a long, long
cruise in the hyperspace, the crew have finally found a very hopeful candidate planet. The next thing to
do is to investigate the planet whether it is really suitable for a new resident or not.
</p>
<p>
For that purpose, the ship is taking some unattended landers. The captain Juclean Dripac decided to
drop them to the planet and collect data about it. But unfortunately, these robots are a bit old and not so
clever that the operator has to program what to do on the planet beforehand of the landing. Many staffs
including you are called for making this important plan.
</p>
<p>
The most complicated phase in the mission is to gather and integrate all the data collected independently
by many robots. The robots need to establish all-to-all communication channels to exchange the data,
once during the mission. That is, all the robots activate their communication channels all together at the
predetermined time, and they exchange the data with each other at that time.
</p>
<p>
They use wireless channels to communicate with each other, so the distance between robots does not limit
the connectivity. But the farther two robots goes, the more power they have to use for communication.
Due to the limitation of the battery capacity, you want to save the transmission power as much as possible.
</p>
<p>
For a good thing, communication units of the robots also have the routing functionality, each robot only
has to talk with the nearest robot. Suppose a graph whose vertices represent robots and edges represent
communication channels established between them. If the graph is connected, all-to-all communication
can be established.
</p>
<p>
Your task is to write the program to calculate the minimum total transmission power required for all-
to-all communication among the robots. Each robot moves linearly on the planet surface. Each pair of
robots which communicate each other must occupy one channel, but you can assume enough number of
channels are available. The transmission power required for two robots is proportional to the distance
between them, so the cost here is exactly the sum of the distances between each pair of robots which
establish a communication channel.
</p>
<p>
You may also regard the planet surface as a two-dimensional surface, as it is huge enough. The time
required for communicating data among robots are also negligible.
</p>
<H2>Input</H2>
<p>
The input contains multiple datasets. Each dataset has the format below.
</p>
<pre>
<i>N T</i>
<i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>vx</i><sub>1</sub> <i>vy</i><sub>1</sub>
...
<i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub> <i>vx</i><sub><i>N</i></sub> <i>vy</i><sub><i>N</i></sub>
</pre>
<p>
The first line of each dataset contains two integers; <i>N</i> is the number of robots used for gathering data
(2 ≤ <i>N</i> ≤ 16), and <i>T</i> is the time limit of the mission (1 ≤ <i>T</i> < 1000).
</p>
<p>
Each of the following <i>N</i> lines describes the motion of a robot. (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>) and (<i>vx<sub>i</sub></i>, <i>vy<sub>i</sub></i> ) are the initial landing
position and the velocity of the <i>i</i>-th robot, respectively (|<i>x<sub>i</sub></i>|, |<i>y<sub>i</sub></i>| < 100000, |<i>vx<sub>i</sub></i>|, |<i>vy<sub>i</sub></i>| < 1000).
</p>
<p>
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and
should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, output in a line the minimum communication cost required for all-to-all communication.
Your program may output an arbitrary number of digits after the decimal point. The absolute error should
be less than or equal to 0.001.
</p>
<H2>Sample Input</H2>
<pre>
4 2
2 0 0 1
0 4 1 0
4 6 0 -1
6 2 -1 0
4 6
2 0 0 1
0 4 1 0
4 6 0 -1
6 2 -1 0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6.00000000
4.24264069
</pre>
|
p01636 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: { inlineMath: [['\\(','\\)']] }
});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<h1 class="ndoc-heading1">Problem C: Mysterious Operator</h1>
<p class="ndoc-top">ã±ãŒæ°ããã€ãã®ããã«æSNSãé²èЧããŠãããšã
ãè§£ãã人ã¯IQ150以äžããããšããåé¡ãã¿ã€ã ã©ã€ã³ã«æµããŠããã
ã±ãŒæ°ã¯IQã150以äžããã®ã§ãèŠããŸã§ããªããã®åé¡ãäžç¬ã§è§£ããŠããŸã£ãã
圌ã«ããŠã¿ãã°ããã®ãããªåé¡ãªãã«é ãåãããå¿
èŠã¯ç¡ãã ã³ã³ãã¥ãŒã¿ã«ä»»ããã°å
åãªã®ã§ããã</p>
<h2 class="ndoc-heading2">åé¡</h2>
<p class="ndoc-top">åé¡ã«ã¯ä»¥äžã®ãããªè¬ã®æ°åŒãæžãããŠããã</p>
<ul class="ndoc-indent">
<li>\( 5 + 3 = 28 \)</li>
<li>\( 9 + 1 = 810 \)</li>
<li>\(8 + 6 = 214 \)</li>
<li>\( 5 + 4 = 19 \)</li>
<li>\( 2 + 2 = 4 \)</li>
<li>\( 15 + 8 = 723 \)</li>
<li>\( 7 + 9 = -216 \)</li>
<li>\( 3 + 0 = 33 \)</li>
</ul>
<p>äžèšã®æŒç®å\( + \)ã«ã€ããŠèããæãããæ£æŽæ°\( a \)ã«ã€ããŠ\( x \geq 0, y \geq 0 \)ãã€\( x + y = a \)ã«ãªããããªæŽæ°ã®ãã¢\( x,y \)ã®åæ°ãæ±ããã</p>
<h2 class="ndoc-heading2">å
¥å</h2>
<p class="ndoc-indent">
æ£æŽæ°\(a\)ãäžè¡ã§äžããããã
</p>
<h2 class="ndoc-heading2">åºå</h2>
<p>
\( a = x + y, x \geq 0, y \geq 0\)ãæºãããã¢\((x,y)\)ã®åæ°ãäžè¡ã«åºåããã
</p>
<h2 class="ndoc-heading2">å¶çŽ</h2>
<ul class="ndoc-indent">
<li>\( 1 \leq a \leq 10^9(= 1000000000) \)</li>
</ul>
<h2 class="ndoc-heading2">å
¥åºåäŸ</h2>
<h3 class="ndoc-heading3">å
¥å1</h3>
<pre>
19
</pre>
<h3 class="ndoc-heading3">åºå1</h3>
<pre>
1
</pre>
<p>\( 5 + 4 \)ã®1éãã§ããã</p>
<h3 class="ndoc-heading3">å
¥å2</h3>
<pre>
22
</pre>
<h3 class="ndoc-heading3">åºå2</h3>
<pre>
2
</pre>
<p>\( 11 + 11 \)ãšã\( 2 + 0 \)ã®2éããååšããã</p>
<h3 class="ndoc-heading3">å
¥å3</h3>
<pre>
1
</pre>
<h3 class="ndoc-heading3">åºå3</h3>
<pre>
0
</pre>
<p>\( 1 + 0 = 11 , 0 + 1 = -11 \)ã§ããã\( 1 \)ã¯çæããããšãã§ããªãã</p>
<h3 class="ndoc-heading3">å
¥å4</h3>
<pre>
101
</pre>
<h3 class="ndoc-heading3">åºå4</h3>
<pre>
0
</pre>
<p>\( 1 - 0 \)ã¯\( 101 \)ã§ã¯ãªãããšã«æ³šæããããšã</p>
<h3 class="ndoc-heading3">å
¥å5</h3>
<pre>
660233276
</pre>
<h3 class="ndoc-heading3">åºå5</h3>
<pre>
4
</pre> |
p00924 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
</script>
<h2>Problem A:
Bit String Reordering
</h2>
<p>
You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required.
</p>
<p>
The initial bit string is simply represented by a sequence of bits, while the target is specified by a <i>run-length code</i>. The run-length code of a bit string is a sequence of the lengths of maximal consecutive sequences of zeros or ones in the bit string. For example, the run-length code of "011100" is "1 3 2". Note that there are two different bit strings with the same run-length code, one starting with zero and the other starting with one. The target is either of these two.
</p>
<p>
In Sample Input 1, bit string "100101" should be reordered so that its run-length code is "1 3 2", which means either "100011" or "011100". At least four swaps are required to obtain "011100". On the other hand, only one swap is required to make "100011". Thus, in this example, 1 is the answer.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The test case is formatted as follows. <br>
<br>
$N$ $M$<br>
$b_1$ $b_2$ . . . $b_N$<br>
$p_1$ $p_2$ . . . $p_M$<br>
<br>
The first line contains two integers $N$ ($1 \leq N \leq 15$) and $M$ ($1 \leq M \leq N$). The second line
specifies the initial bit string by $N$ integers. Each integer $b_i$ is either 0 or 1. The third line contains the run-length code, consisting of $M$ integers. Integers $p_1$ through $p_M$ represent the lengths of consecutive sequences of zeros or ones in the bit string, from left to right. Here, $1 \leq p_j$ for $1 \leq j \leq M$ and $\sum^{M}_{j=1} p_j = N$ hold. It is guaranteed that the initial bit string can be reordered into a bit string with its run-length code $p_1, . . . , p_M$.
</p>
<h3>Output</h3>
<p>
Output the minimum number of swaps required
</p>
<h3>Sample Input 1</h3>
<pre>6 3
1 0 0 1 0 1
1 3 2</pre>
<h3>Sample Output 1</h3>
<pre>1</pre>
<h3>Sample Input 2</h3>
<pre>7 2
1 1 1 0 0 0 0
4 3</pre>
<h3>Sample Output 2</h3>
<pre>12</pre>
<h3>Sample Input 3</h3>
<pre>15 14
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 2</pre>
<h3>Sample Output 3</h3>
<pre>7</pre>
<h3>Sample Input 4</h3>
<pre>1 1
0
1</pre>
<h3>Sample Output 4</h3>
<pre>0</pre>
|
p02919 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>Given is a permutation <var>P</var> of <var>\{1, 2, \ldots, N\}</var>.</p>
<p>For a pair <var>(L, R) (1 \le L \lt R \le N)</var>, let <var>X_{L, R}</var> be the second largest value among <var>P_L, P_{L+1}, \ldots, P_R</var>.</p>
<p>Find <var>\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var> 2 \le N \le 10^5 </var></li>
<li><var> 1 \le P_i \le N </var></li>
<li><var> P_i \neq P_j </var> <var>(i \neq j)</var></li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>P_1</var> <var>P_2</var> <var>\ldots</var> <var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print <var>\displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
2 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>5
</pre>
<p><var>X_{1, 2} = 2, X_{1, 3} = 2</var>, and <var>X_{2, 3} = 1</var>, so the sum is <var>2 + 2 + 1 = 5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
1 2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>30
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
8 2 7 3 4 5 6 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>136
</pre></section>
</div>
</span> |
p01323 |
<h1><font color="#000">Problem C:</font> ã³ã³ãã€ã«</h1>
<p>æ±äº¬å€§åŠã«å
¥åŠãããããŸãåã¯TSG(æ±å€§ã¹ãŒããŒã²ãŒããŒãº)ãšãããµãŒã¯ã«ã«å
¥ã£ãã</p>
<p>ãã®ãµãŒã¯ã«ã¯æ¯å¹Žãé§å Žç¥ã§ã²ãŒã ãå±ç€ºããŠããããããŸãåãã²ãŒã ãäœæããŠå±ç€ºããããšã«ããã</p>
<p>ãããŸãåã®äœæããã²ãŒã ã¯æ¬¡ã®ãããªãããããèœã¡ç©ããºã«ã²ãŒã ã§ããã</p>
<p>
<ul>
<li>暪6ãã¹Ã瞊12ãã¹ã®æ Œåç¶ã®ãã£ãŒã«ãããããåãã¹ã«ã€ã1åã®ãããã¯ã眮ãããšãã§ããã</li>
<li>äžãããããã¯ã2ã€1çµã§èœäžããŠããããããã¯ã«ã¯èµ€ã»ç·ã»éã»é»ã»çŽ«ã®5è²ã®åºæ¬ãããã¯ãšãéªéãããã¯ã®èš6çš®é¡ãããããã¬ã€ã€ãŒã¯ãããã¯ãåè»¢ãæšªç§»åã«ããæäœããèœäžäœçœ®ã倿Žããããšãã§ããã</li>
<li>èœäžããŠãããããã¯ããã£ãŒã«ãã®åºãã»ãã®ãããã¯ã«è¡çªãããšããã®äœçœ®ã«ãããã¯ãåºå®ãããã</li>
<li>åºå®ããããããã¯ãšåè²ã®ãããã¯ãåšå²4æ¹åã«ããå Žåããããã¯äºãã«ãã£ã€ãããã ãããéªéãããã¯ã¯äºãã«ãã£ã€ããªãã</li>
<li>ãããã¯ã4å以äžãã£ã€ããšæ¶æ»
ãåŸç¹ãšãªãããéªéãããã¯ã®åšå²4æ¹åã«ååšããåºæ¬ãããã¯ãæ¶æ»
ãããšããã®ãéªéãããã¯ãäžç·ã«æ¶æ»
ããããããã¯ã®æ¶æ»
ã¯ãå
šãŠã®ãããã¯ã®èœäžãçµäºããã¿ã€ãã³ã°ã§åæã«èµ·ããã</li>
<li>ãããã¯ã®æ¶æ»
ã«ããããã®äžã«ãã£ããããã¯ãèœäžããããã®ãããã¯ã®èœäžã¯ãã¬ã€ã€ãŒãæäœã§ããªãããã®ãšãåã³ãããã¯ã4å以äžãã£ã€ããšæ¶æ»
ããé£éãèµ·ããããã ããè€æ°è²ãåæã«æ¶ããå Žåã§ãã1é£éæ±ããšãªãã</li>
</ul>
</p>
<p>ãããŸãåã¯ãã®ã²ãŒã ã®å€§éšåã®ããã°ã©ã ãæžãçµããããã©ãããŠããããã¯ããã£ã€ããŠæ¶æ»
ãããšãã®åŠçãæžãããšãåºæ¥ãªãã£ããããã§ãµãŒã¯ã«ã®å人ã§ããããªãã«ãã®éšåã®ããã°ã©ã ãæžããŠãããããšã«ããã
</p>
<h2>Input</h2>
<p>å
¥åã¯12è¡ãããªãã</p>
<p>å
¥åã® <i>i</i> è¡ç®ã¯é·ã6ã®æååãããªãããã® <i>j</i> æåç®ã¯ãã£ãŒã«ãã®äžãã <i>i</i> è¡ç®ãå·Šãã <i>j</i> åç®ã®ãã¹ã®ç¶æ
ã衚ããŠããã</p>
<p>ãã¹ã®ç¶æ
ã衚ãæåã¯ä»¥äžã®7ã€ã®ãã¡ã®ããããã§ããã</p>
<center>
<table>
<tr><th>æå</th><th>çš®é¡</th></tr>
<tr><td><span style="font-family: monospace">R</span></td><td>èµ€</td></tr>
<tr><td><span style="font-family: monospace">G</span></td><td>ç·</td></tr>
<tr><td><span style="font-family: monospace">B</span></td><td>é</td></tr>
<tr><td><span style="font-family: monospace">Y</span></td><td>é»</td></tr>
<tr><td><span style="font-family: monospace">P</span></td><td>玫</td></tr>
<tr><td><span style="font-family: monospace">O</span></td><td>ãéªé</td></tr>
<tr><td><span style="font-family: monospace">.</span></td><td>空ããã¹</td></tr>
</table>
</center>
<p>ãŸããå
¥åã«å«ãŸããå
šãŠã®ãããã¯ã¯åºã®äžãä»ã®ãããã¯ã®äžã«ä¹ã£ãŠããã
</p>
<h2>Output</h2>
<p>å
¥åã®ç¶æ
ãããã«ãŒã«ã«åŸã£ãŠãããã¯ãæ¶ããŠãã£ãæã®é£éæ°ãèšç®ããäžè¡ã§åºåããã</p>
<p>ãããã¯ãäžã€ãæ¶ããªãå Žåã¯0ãšåºåããã
</p>
<h2>Notes on Test Cases</h2>
<p>
äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸãã
</p>
<p>
å
¥åã®1è¡ç®ã«ããŒã¿ã»ããã®æ°TãäžããããŸãã
</p>
<p>
åããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã
</p>
<!--
<h2>Sample Input 1</h2>
<pre>......
......
......
......
......
......
......
......
.RGB..
RGOP..
RGBPB.
RGBPP.
</pre>
<h2>Output for Sample Input 1</h2>
<pre>3
</pre>
<h2>Sample Input 2</h2>
<pre>GBRGYP
GBRRYP
BGGRBB
BPRGYY
GGPRRY
BYPPRB
YGGGPB
GYYYPR
YRBRBR
YBRBRB
BRBRBR
BRBRBR
</pre>
<h2>Output for Sample Input 2</h2>
<pre>18
</pre>
<h2>Sample Input 3</h2>
<pre>......
......
......
......
......
......
......
......
......
......
..OO..
..OO..
</pre>
<h2>Output for Sample Input 3</h2>
<pre>0
</pre>
-->
<h2>Sample Input </h2>
<pre>
3
......
......
......
......
......
......
......
......
.RGB..
RGOP..
RGBPB.
RGBPP.
GBRGYP
GBRRYP
BGGRBB
BPRGYY
GGPRRY
BYPPRB
YGGGPB
GYYYPR
YRBRBR
YBRBRB
BRBRBR
BRBRBR
......
......
......
......
......
......
......
......
......
......
..OO..
..OO..
</pre>
<h2>Output for Sample Input</h2>
<pre>
3
18
0
</pre> |
p01773 |
<h2>B: Cram School Schedule / å¡Ÿã®æéå²</h2>
<h3>ç©èª</h3>
<p>ããªãã¯å¡Ÿã®çµå¶è
ã§ããïŒããªãã®å¡Ÿã¯åäººææ¥å¶ã§1人ã®çåŸãš1人ã®å
çã§ææ¥ãè¡ãïŒãã®å¡Ÿã®å
çã¯éåžžã«åªç§ã§ç§ç®ã«ããããããã¹ãŠã®ææ¥ãè¡ãããšãã§ããïŒãŸãïŒå
çãšçåŸã¯éåžžã«ã¿ããªã®ã§ïŒåºåžã§ããææ¥ã«ã¯ä»ã®ææ¥ã®åºåžç¶æ³ã«ãããããïŒãã¹ãŠåºåžããããšãå¯èœã§ããïŒäŸãã°ïŒåãæéåž¯ã®ææ¥ã«åºåžã§ãã2人ã®çåŸãš4人ã®å
çãããå Žåã¯ïŒãã®æé垯ã«2ã€ã®ææ¥ãè¡ããïŒ</p>
<p>ããªãã¯æ¥æã®ææ¥äºå®ãç«ãŠãªããŠã¯ãããªããïŒå
çãšçåŸã®äººæ°ãå€ãããäºå®ãç«ãŠãã®ãéåžžã«å€§å€ã§ããïŒãŸãïŒããªãã¯ã§ããã ãå€ãã®ææ¥ãè¡ããããšèããŠããïŒãã®ããïŒããªãã¯è¡ããæå€§ã®ææ¥æ°ãæ±ããããã°ã©ã ãäœãããšã«ããïŒ</p>
<h3>åé¡</h3>
<p>å
çã®äººæ°ãšïŒçåŸã®äººæ°ïŒããããã®å
çãšçåŸã®äºå®ããªãæéåž¯ïŒææ¥ãè¡ããæé垯ãäžããããïŒããããã®å
çïŒãŸãã¯çåŸã«ã€ããŠïŒäºå®ããªãæéåž¯ãææ¥ãè¡ããæé垯ãå®å
šã«è¢«èŠããŠãããšãïŒãã®å
çïŒãŸãã¯çåŸã¯ãã®ææ¥ã«åºåžã§ããïŒããããã®ææ¥ãè¡ããæé垯ã§ã¯ïŒåºåžã§ããå
çãšçåŸãããªããã¢ãè€æ°äœãïŒäœã£ããã¢ã®æ°ã ãã®ææ¥ãåæã«è¡ãããšãã§ããïŒãã®ãšãã«è¡ããæå€§ã®ææ¥æ°ãæ±ããïŒ</p>
<h3>å
¥å圢åŒ</h3>
<p>å
¥åããŒã¿ã®åœ¢åŒã¯ä»¥äžã®ããã«äžããããïŒ</p>
<pre>
ææ¥ãè¡ããæéåž¯ã®æ
å ±
<var>n</var>
å
ç<var>1</var>ã®æéåž¯ã®æ
å ±
...
å
ç<var>n</var>ã®æéåž¯ã®æ
å ±
<var>m</var>
çåŸ<var>1</var>ã®æéåž¯ã®æ
å ±
...
çåŸ<var>m</var>ã®æéåž¯ã®æ
å ±
</pre>
<p>æåã®1è¡ã«ã¯ææ¥ãè¡ããæéåž¯ã®æ
å ±ãäžããããïŒ</p>
<p>ç¶ã1è¡ã«ã¯å
çã®äººæ° <var>n</var> (<var>1 ≤ n ≤ 100</var>) ãäžããããïŒç¶ã <var>n</var> è¡ã® <var>i</var> è¡ç®ã«ã¯ <var>i</var> çªç®ã®å
çã®äºå®ããªãæéåž¯ã®æ
å ±ãäžããããïŒ</p>
<p>ç¶ã1è¡ã«ã¯çåŸã®äººæ° <var>m</var> (<var>1 ≤ m ≤ 100</var>) ãäžããããïŒç¶ã <var>m</var> è¡ã® <var>i</var> è¡ç®ã«ã¯ <var>i</var> çªç®ã®çåŸã®äºå®ããªãæéåž¯ã®æ
å ±ãäžããããïŒ</p>
<p>åã
ã®æéåž¯ã®æ
å ±ã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ</p>
<pre><var>k</var> <var>ah_1</var>:<var>am_1</var>-<var>bh_1</var>:<var>bm_1</var> <var> . . . </var> <var>ah_k</var>:<var>am_k</var>-<var>bh_k</var>:<var>bm_k</var></pre>
<p>ã¯ããã«æéåž¯ã®æ° <var>k</var> (<var>1 ≤ k ≤ 100</var>) ãäžãããïŒç©ºçœåºåãã§ <var>k</var> åã®æé垯ãäžããããïŒ<var>i</var> çªç®ã®æé垯㯠<var>ah_i</var>:<var>am_i</var>-<var>bh_i</var>:<var>bm_i</var> ã®åœ¢åŒã§äžãããïŒ<var>ah_i</var>:<var>am_i</var> ãéå§æå»ã衚ãïŒ<var>bh_i</var>:<var>bm_i</var> ãçµäºæå»ã衚ãïŒ<var>ah_i</var>, <var>am_i</var>, <var>bh_i</var>, <var>bm_i</var> ã¯ãããã0è©°ã2æ¡ã§ <var>0 ≤ ah_i, bh_i ≤ 23</var>, <var>0 ≤ am_i, bm_i ≤ 59</var> ãæºããæŽæ°ã§ããïŒ</p>
<p>äžãããããã¹ãŠã®æé垯ã«ã€ããŠïŒéå§æå»ã¯çµäºæå»ããçã«æ©ãïŒãŸãïŒããããã®æéåž¯ã®æ
å ±ã«ãããŠïŒæéåž¯ã¯æ©ãæå»é ã«äžŠãã§ããïŒã©ã®çµäºæå»ã1ã€åŸã®æé垯ã®éå§æå»ããçã«æ©ãïŒ</p>
<h3>åºå圢åŒ</h3>
<p>è¡ããææ¥ã®æå€§æ°ã1è¡ã§åºåããïŒ</p>
<h3>å
¥åäŸ1</h3>
<pre>
2 10:00-11:30 12:00-13:00
2
1 10:00-15:00
2 09:00-12:00 18:10-18:55
2
2 10:00-13:00 15:30-16:40
3 06:00-08:00 12:00-13:10 15:00-17:00
</pre>
<h3>åºåäŸ1</h3>
<pre>2</pre>
<p>1ã€ç®ã®æé垯ãš2ã€ç®ã®æé垯ã§1ã€ãã€ææ¥ãè¡ãããšã§ïŒ2åã®ææ¥ãè¡ãããšãã§ããïŒ</p>
<h3>å
¥åäŸ2</h3>
<pre>
2 07:00-08:30 10:00-12:00
3
3 08:30-09:00 11:05-15:05 23:10-23:55
2 09:00-12:00 17:45-18:55
1 08:00-10:00
2
2 07:20-11:00 12:30-17:05
3 07:48-08:51 11:22-16:15 17:02-17:59
</pre>
<h3>åºåäŸ2</h3>
<pre>0</pre>
<p>äºå®ããªãæé垯ã§07:00ããã®ææ¥ã«éã«åãå
çãšçåŸã®ãã¢ãååšããªãã®ã§1ã€ç®ã®æéåž¯ã¯ææ¥ãè¡ãããšãã§ããªãïŒãŸãïŒ2ã€ç®ã®æé垯ã¯2人ç®ã®å
çãåºåžã§ãããïŒçåŸã¯èª°ãåºåžã§ããªãïŒãã£ãŠïŒ2ã€ç®ã®æéåž¯ãææ¥ãè¡ãããšãã§ããªãïŒãããã£ãŠïŒè¡ããæå€§ã®ææ¥æ°ã¯0ã§ããïŒ</p> |
p00861 |
<H1><font color="#000">Problem H:</font> Bug Hunt</H1>
<p>
In this problem, we consider a simple programming language that has only declarations of one-
dimensional integer arrays and assignment statements. The problem is to find a bug in the given
program.
</p>
<p>
The syntax of this language is given in BNF as follows:
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_bugHunt">
</center>
<p>
where <span><</span><i>new line</i><span>></span> denotes a new line character (LF).
</p>
<p>
Characters used in a program are alphabetical letters, decimal digits, <span>=</span>, <span>[</span>, <span>]</span> and new line characters. No other characters appear in a program.
</p>
<p>
A declaration declares an array and specifies its length. Valid indices of an array of length <i>n</i> are integers between 0 and <i>n</i> - 1, inclusive. Note that the array names are case sensitive, i.e.
array <span>a</span> and array <span>A</span> are different arrays. The initial value of each element in the declared array is undefined.
</p>
<p>
For example, array <span>a</span> of length 10 and array <span>b</span> of length 5 are declared respectively as follows.
</p>
<pre>
a[10]
b[5]
</pre>
<p>
An expression evaluates to a non-negative integer. A <span><</span><i>number</i><span>></span> is interpreted as a decimal
integer. An <span><</span><i>array_name</i><span>></span> <span>[<</span><i>expression</i><span>>]</span> evaluates to the value of the <span><</span><i>expression</i><span>></span> -th element of
the array. An assignment assigns the value denoted by the right hand side to the array element
specified by the left hand side.
</p>
<p>
Examples of assignments are as follows.
</p>
<pre>
a[0]=3
a[1]=0
a[2]=a[a[1]]
a[a[0]]=a[1]
</pre>
<p>
A program is executed from the first line, line by line. You can assume that an array is declared once and only once before any of its element is assigned or referred to.
</p>
<p>
Given a program, you are requested to find the following bugs.
</p>
<ul>
<li> An index of an array is invalid.</li>
<li> An array element that has not been assigned before is referred to in an assignment as an index of array or as the value to be assigned.</li>
</ul>
<p>
You can assume that other bugs, such as syntax errors, do not appear. You can also assume
that integers represented by <span><</span><i>number</i><span>></span>s are between 0 and 2<sup>31</sup> - 1 (= 2147483647), inclusive.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets followed by a line which contains only a single '<span>.</span>' (period).
Each dataset consists of a program also followed by a line which contains only a single '<span>.</span>' (period).
A program does not exceed 1000 lines. Any line does not exceed 80 characters excluding a new
line character.
</p>
<H2>Output</H2>
<p>
For each program in the input, you should answer the line number of the assignment in which
the first bug appears. The line numbers start with 1 for each program. If the program does not
have a bug, you should answer zero. The output should not contain extra characters such as
spaces.
</p>
<H2>Sample Input</H2>
<pre>
a[3]
a[0]=a[1]
.
x[1]
x[0]=x[0]
.
a[0]
a[0]=1
.
b[2]
b[0]=2
b[1]=b[b[0]]
b[0]=b[1]
.
g[2]
G[10]
g[0]=0
g[1]=G[0]
.
a[2147483647]
a[0]=1
B[2]
B[a[0]]=2
a[B[a[0]]]=3
a[2147483646]=a[2]
.
.
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
2
2
3
4
0
</pre>
|
p01289 |
<H1><font color="#000">Problem G:</font> Strange Couple</H1>
<p>
Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they donât know the route at all (since they have just moved to
their new home). Yes, they will be going just by their feeling.
</p>
<p>
The town they drive can be considered as an undirected graph with a number of intersections (vertices)
and roads (edges). Each intersection may or may not have a sign. On intersections with signs, Alice and
Bob will enter the road for the shortest route. When there is more than one such roads, they will go into
one of them at random.
</p>
<p>
On intersections without signs, they will just make a random choice. Each random selection is made with
equal probabilities. They can even choose to go back to the road they have just come along, on a random
selection.
</p>
<p>
Calculate the expected distance Alice and Bob will drive before reaching the theater.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>n s t</i><br>
<i>q</i><sub>1</sub> <i>q</i><sub>2</sub> ... <i>q<sub>n</sub></i><br>
<i>a</i><sub>11</sub> <i>a</i><sub>12</sub> ... <i>a</i><sub>1<i>n</i></sub><br>
<i>a</i><sub>21</sub> <i>a</i><sub>22</sub> ... <i>a</i><sub>2<i>n</i></sub><br>
.<br>
.<br>
.<br>
<i>a</i><sub><i>n</i>1</sub> <i>a</i><sub><i>n</i>2</sub> ... <i>a</i><sub><i>nn</i></sub><br>
</p>
<p>
<i>n</i> is the number of intersections (<i>n</i> ≤ 100). <i>s</i> and <i>t</i> are the intersections the home and the theater are
located respectively (1 ≤ <i>s</i>, <i>t</i> ≤ <i>n</i>, <i>s</i> ≠ <i>t</i>); <i>q<sub>i</sub></i> (for 1 ≤ <i>i</i> ≤ <i>n</i>) is either 1 or 0, where 1 denotes there is a
sign at the <i>i</i>-th intersection and 0 denotes there is not; <i>a<sub>ij</sub></i> (for 1 ≤ <i>i</i>, <i>j</i> ≤ <i>n</i>) is a positive integer denoting
the distance of the road connecting the <i>i</i>-th and <i>j</i>-th intersections, or 0 indicating there is no road directly
connecting the intersections. The distance of each road does not exceed 10.
</p>
<p>
Since the graph is undirectional, it holds <i>a<sub>ij</sub></i> = <i>a<sub>ji</sub></i> for any 1 ≤ <i>i</i>, <i>j</i> ≤ <i>n</i>. There can be roads connecting the
same intersection, that is, it does <i>not</i> always hold <i>a<sub>ii</sub></i> = 0. Also, note that the graph is not always planar.
</p>
<p>
The last dataset is followed by a line containing three zeros. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, print the expected distance accurate to 10<sup>-8</sup> , or "<span>impossible</span>" (without quotes) if there is no route to get
to the theater. The distance may be printed with any number of digits after the decimal point.
</p>
<H2>Sample Input</H2>
<pre>
5 1 5
1 0 1 0 0
0 2 1 0 0
2 0 0 1 0
1 0 0 1 0
0 1 1 0 1
0 0 0 1 0
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
8.50000000
</pre>
|
p00532 |
<h2>ã¯ãªã¹ãã¹ããŒãã£ãŒ (Christmas Party)</h2>
<h2> åé¡</h2>
<p>
JOI åã¯åé 1 ããåé N ãŸã§ã® N 人ã®åéãæããŠã¯ãªã¹ãã¹ããŒãã£ãŒãè¡ã£ãïŒã¯ãªã¹ãã¹ããŒãã£ãŒãçãäžãã£ãŠãããšããã§ïŒåéãšäžç·ã«æ¬¡ã®ãããªã²ãŒã ãè¡ãããšã«ãªã£ãïŒ
</p>
<ol>
<li>
æåã« JOI å㯠N 人ã®åéã®äžãã 1 人ãéžã¶ïŒä»¥éã¯ãã®åéãã¿ãŒã²ãããšåŒã¶ããšã«ããïŒ
</li>
<li>
JOI åã¯ïŒã¿ãŒã²ãããšããŠéžãã åéã«ïŒãã®äººãã¿ãŒã²ããã§ããããšããã£ããäŒããïŒã¿ãŒã²ãã以å€ã®åéã¯ïŒèª°ãã¿ãŒã²ããããç¥ãããšã¯ã§ããªãïŒ
</li>
<li>
ã¿ãŒã²ãã以å€ã®åéã¯ããããïŒã¿ãŒã²ããã誰ããäºæ³ããŠïŒãã®äººã®ååãçŽã«èšå
¥ããïŒã¿ãŒã²ããã¯èªåèªèº«ã®ååãçŽã«èšå
¥ããïŒ
</li>
<li>
ãã¹ãŠã®äººã®èšå
¥ãçµãã£ãåŸïŒJOI åã¯ã¿ãŒã²ããã®ååãçºè¡šããïŒ
</li>
<li>
äºæ³ãåœãã£ã人㯠1 ç¹ãåŸãïŒãªãïŒã¿ãŒã²ããã¯èªåèªèº«ã®ååãçŽã«èšå
¥ããŠããã®ã§ïŒå¿
ã 1 ç¹ãåŸãïŒäºæ³ãå€ãã人ã«ã¯åŸç¹ã¯äžããããªãïŒ
</li>
<li>
ããã«å ããŠïŒäºæ³ãå€ãã人ã®äººæ°ã X 人ãšãããšãïŒã¿ãŒã²ããã¯è¿œå ã§ X ç¹ãåŸãïŒ
</li>
</ol>
<p>
JOI åãã¡ã¯ãã®ã²ãŒã ã M åè¡ã£ãïŒããããã®åéã«å¯ŸããŠïŒM åã®ã²ãŒã ã«ãããåèšåŸç¹ãæ±ããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠3 + M è¡ãããªãïŒ
</p>
<p>
1 è¡ç®ã«ã¯ïŒåéã®äººæ° N (3 ≤ N ≤ 100) ãæžãããŠããïŒ
</p>
<p>
2 è¡ç®ã«ã¯ïŒJOI åãã¡ãè¡ã£ãã²ãŒã ã®åæ° M (3 ≤ M ≤ 100) ãæžãããŠããïŒ
</p>
<p>
3 è¡ç®ã«ã¯ïŒM åã®æŽæ° A<sub>1</sub>, A<sub>2</sub>, ..., A<sub>M</sub> ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒi åç® (1 ⊠i ⊠M) ã®ã²ãŒã ã®ã¿ãŒã²ãããåé A<sub>i</sub> (1 ≤ A<sub>i</sub> ≤ N) ã§ããããšã衚ãïŒ
</p>
<p>
ç¶ã M è¡ã®ãã¡ã® i è¡ç® (1 ⊠i ⊠M) ã«ã¯ïŒN åã®æŽæ° B<sub>i,1</sub>, B<sub>i,2</sub>, ..., B<sub>i,N</sub> ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒi åç®ã®ã²ãŒã ã«ãããŠåé j (1 ≤ j ≤ N) ãåé B<sub>i,j</sub> (1 ≤ B<sub>i,j</sub> ≤ N) ã®ååãçŽã«èšå
¥ããããšã衚ãïŒã¿ãŒã²ããã¯èªåèªèº«ã®ååãçŽã«èšå
¥ããã®ã§ïŒj = A<sub>i</sub> ã®ãšãïŒåžžã« B<sub>i,j</sub> = j ã§ããïŒ
</p>
<h2>åºå</h2>
<p>
ããããã®åéã«å¯ŸããŠïŒM åã®ã²ãŒã ã«ãããåèšåŸç¹ãåºåããïŒåºå㯠N è¡ãããªãïŒj è¡ç® (1 ≤ j ≤ N) ã«åé j ã®åèšåŸç¹ãåºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
3
4
1 2 3 2
1 1 2
3 2 2
1 1 3
2 2 2
</pre>
<h3>åºåäŸ 1</h3>
<pre>
3
4
5
</pre>
<h3>å
¥åäŸ 2</h3>
<pre>
5
3
3 3 1
2 4 3 3 3
4 3 3 3 1
1 3 4 1 1
</pre>
<h3>åºåäŸ 1</h3>
<pre>
3
1
6
3
2
</pre>
<p>
å
¥åºåäŸ 1 ã§ã¯ 3 人ã®åéã 4 åã®ã²ãŒã ãè¡ãïŒ
</p>
<ul>
<li>1 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 1 ã§ããïŒåé 1 㯠2 ç¹ïŒåé 2 㯠1 ç¹ïŒåé 3 㯠0 ç¹ãåŸãïŒ</li>
<li>2 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 2 ã§ããïŒåé 1 㯠0 ç¹ïŒåé 2 㯠2 ç¹ïŒåé 3 㯠1 ç¹ãåŸãïŒ</li>
<li>3 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 3 ã§ããïŒåé 1 㯠0 ç¹ïŒåé 2 㯠0 ç¹ïŒåé 3 㯠3 ç¹ãåŸãïŒ</li>
<li>4 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 2 ã§ããïŒåé 1 㯠1 ç¹ïŒåé 2 㯠1 ç¹ïŒåé 3 㯠1 ç¹ãåŸãïŒ</li>
</ul>
<p>
4 åã®ã²ãŒã çµäºåŸã®åèšåŸç¹ã¯ïŒåé 1 㯠3 ç¹ïŒåé 2 㯠4 ç¹ïŒåé 3 㯠5 ç¹ã§ããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p00162 |
<H1>ããã³ã°æ°</H1>
<p>
1 ã« 2, 3, 5 ãäœåã (0 å以äž) ããç®ããŠåŸãããæ°ãããã³ã°æ° (Hamming numbers) ãšåŒã³ãŸããäŸãã°ã
</p>
<ul>
<li>1</li>
<li>1 Ã 2 Ã 2 = 4</li>
<li>1 Ã 2 Ã 2 Ã 3 Ã 5 Ã 5 = 300</li>
</ul>
<p>
ãªã©ã¯ããã³ã°æ°ã§ããã11, 13, 14 ãªã©ã¯ããã³ã°æ°ã§ã¯ãããŸããã
</p>
<p>
ããã³ã°æ°ã¯ã©ãã 60 ã®ã¹ãä¹ãå²ãåã(äŸãã°ã54 㯠60<sup>3</sup> = 21600 ãå²ãåã) ã®ã§ãæå»ãªã© 60 鲿³ã®èšç®ã«ã¯éœåã®è¯ãæ°ãšããŠæããç¥ãããŠããŸããããŸããæ¥œåšã®èª¿åŸã«çšããé³éã®äžã€ã§ããçŽæ£åŸã§ã¯ãé³ã®åšæ³¢æ°ã®æ¯ã 24, 27, 30, 32, 36, 40, 45, 48 ãšããããã³ã°æ°ãããªãæ°åã«ãªããŸãã
</p>
<p>
æŽæ° <var>m</var>ã<var>n</var> ãå
¥åãšãã<var>m</var> ä»¥äž <var>n</var> 以äžã®ããã³ã°æ°ã®åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
</p>
<p>
åããŒã¿ã»ãããšããŠãïŒã€ã®æŽæ° <var>m</var> ãš <var>n</var> (1 ≤ <var>m</var>, <var>n</var> ≤ 1000000, <var>m</var> ≤ <var>n</var>) ã空çœåºåãã§ïŒè¡ã«äžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããããšã« <var>m</var> ä»¥äž <var>n</var> 以äžã®ããã³ã°æ°ã®åæ°ãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
3 8
1 27
1 86
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
5
17
31
</pre>
|
p00498 |
<H1> JOI åœã®ãç¥ãäºæ
(Festivals in JOI Kingdom) </H1>
<p>
JOI åœã«ã¯N åã®è¡ãããïŒãããã®éã¯<i>M</i> æ¬ã®åæ¹åã«éè¡å¯èœãªéè·¯ã§çµã°ããŠããïŒåœæ°ã¯éè·¯ãéã£ãŠãããã®è¡ãç§»åããïŒ
</p>
<p>
JOI åœã®åœæ°ã«ã¯ïŒãç¥ãã奜ããªäººãå€ãïŒçŸåšïŒ<i>K</i> åã®è¡ã§ãç¥ããéå¬ãããŠããïŒéåžžã«è³ãã£ãŠããïŒäžæ¹ã§ïŒäžéšã®åœæ°ã¯ãç¥ããéšããããšããŠå«ãïŒãç¥ãã«ã§ããã ãè¿ã¥ããããªããšæã£ãŠããïŒ
</p>
<p>
ããã§åœçã¯ïŒåªç§ãªããã°ã©ããŒã§ããããªãã«ïŒãã®ãããªãç¥ããå«ãåœæ°ã®ããïŒããè¡ããããè¡ã«ç§»åããããã«ïŒãç¥ããéå¬ãããŠããè¡ã«ã©ãã ãè¿ã¥ããã«ç§»åããããšãã§ããããé«éã«èª¿ã¹ãããšã®ã§ããããã°ã©ã ã®äœæãäŸé ŒããïŒ
</p>
<h2>課é¡</h2>
<p>
éè·¯ã®æ
å ±ãšãç¥ããéå¬ãããŠããè¡ã®æ
å ±ïŒããã³<i>Q</i> åã®ã¯ãšãªïŒåºçºããè¡<i>S<sub>i</sub></i> ãšè¡ãããè¡<i>T<sub>i</sub></i>ã®çµïŒãäžããããïŒåã¯ãšãª<i>i</i> ã«å¯ŸãïŒè¡<i>S<sub>i</sub></i> ããè¡<i>T<sub>i</sub></i> ãžã®ãã¹ãŠã®çµè·¯ã®ãã¡ïŒãç¥ããŸã§ã®è·é¢ãæå€§ãšãªãçµè·¯ã®ïŒãç¥ããŸã§ã®è·é¢ãæ±ããããã°ã©ã ãäœæããïŒãã ãïŒããçµè·¯ã®ãç¥ããŸã§ã®è·é¢ãšã¯ïŒçµè·¯äžã®è¡ãããç¥ããéå¬ãããŠããè¡ãŸã§ã®ç§»åè·é¢ã®æå°å€ã®ããšã§ããïŒ
</p>
<h2>å¶é</h2>
<p>
2 ≤ <i>N</i> ≤ 100000 (= 10<sup>5</sup>) JOI åœã®è¡ã®åæ°<br>
1 ≤ <i>M</i> ≤ 200000 (= 2 × 10<sup>5</sup>) JOI åœã®éè·¯ã®æ¬æ°<br>
1 ≤ <i>K</i> ≤ <i>N</i> ãç¥ããéå¬ãããŠããè¡ã®åæ°<br>
1 ≤ <i>Q</i> ≤ 100000 (= 10<sup>5</sup>) ã¯ãšãªã®åæ°<br>
1 ≤ <i>L<sub>i</sub></i> ≤ 1000 <i>i</i> çªç®ã®éè·¯ã®é·ã<br>
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯æŽæ°<i>N</i>, <i>M</i>, <i>K</i>, <i>Q</i> ã空çœãåºåããšããŠæžãããŠããïŒ<i>N</i> ã¯JOI åœã®è¡ã®åæ°ãïŒ<i>M</i> ã¯JOIåœã®éè·¯ã®æ¬æ°ãïŒ<i>K</i> ã¯ãç¥ããéå¬ãããŠããè¡ã®åæ°ãïŒ<i>Q</i> ã¯ã¯ãšãªã®åæ°ããããã衚ãïŒè¡ã«ã¯1, 2, ... , <i>N</i> ã®çªå·ãã€ããããŠããïŒ
</li>
<li> ç¶ã<i>M</i> è¡ã¯éè·¯ã®æ
å ±ã衚ãïŒ<i>i</i> + 1 è¡ç®(1 ≤ <i>i</i> ≤ <i>M</i>) ã«ã¯æŽæ°<i>A<sub>i</sub></i>, <i>B<sub>i</sub></i>, <i>L<sub>i</sub></i> (1 ≤ <i>A<sub>i</sub></i> ≤ <i>N</i>, 1 ≤ <i>B<sub>i</sub></i> ≤ <i>N</i>) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒ<i>i</i> çªç®ã®éè·¯ãè¡<i>A<sub>i</sub></i> ãšè¡<i>B<sub>i</sub></i> ãçµãã§ããïŒé·ãã<i>L<sub>i</sub></i> ã§ããããšã衚ãïŒéè·¯ã®äž¡ç«¯ãåãè¡ã§ããããšã¯ãªãïŒãŸãïŒä»»æã®2 ã€ã®è¡<i>p</i>, <i>q</i> ã«å¯ŸãïŒ<i>p</i> ãš<i>q</i>ãçµã¶éè·¯ã¯2 æ¬ä»¥äžååšããªãïŒã©ã®è¡ããã©ã®è¡ãžãããã€ãã®éè·¯ããã©ã£ãŠè¡ãããšãã§ããïŒ</li>
<li> ç¶ã<i>K</i> è¡ã¯ãç¥ããéå¬ãããŠããè¡ã®æ
å ±ã衚ãïŒ<i>i</i> + <i>M</i> + 1 è¡ç®(1 ≤ <i>i</i> ≤ <i>K</i>) ã«ã¯1 ã€ã®æŽæ°<i>F<sub>i</sub></i>(1 ≤ <i>F<sub>i</sub></i> ≤ <i>N</i>) ãæžãããŠããïŒããã¯è¡<i>F<sub>i</sub></i> ã§ãç¥ããéå¬ãããŠããããšã衚ãïŒ<i>F</i><sub>1</sub>, ..., <i>F<sub>K</sub></i> ã®äžã«åãå€ã2 å以äžçŸããããšã¯ãªãïŒ
</li>
<li> ç¶ã<i>Q</i> è¡ã¯ã¯ãšãªã衚ãïŒ<i>i</i> + <i>M</i> + <i>K</i> + 1 è¡ç®(1 ≤ <i>i</i> ≤ <i>Q</i>) ã«ã¯2 ã€ã®æŽæ°<i>S<sub>i</sub></i>, <i>T<sub>i</sub></i> (1 ≤ <i>S<sub>i</sub></i> ≤ <i>N</i>, 1 ≤ <i>T<sub>i</sub></i> ≤ <i>N</i>, <i>S<sub>i</sub></i> ≠ <i>T<sub>i</sub></i>) ã空çœãåºåããšããŠæžãããŠããïŒããã¯<i>i</i> çªç®ã®ã¯ãšãªã®åºçºããè¡ã<i>S<sub>i</sub></i> ã§ããè¡ãããè¡ã<i>T<sub>i</sub></i> ã§ããããšã衚ãïŒ</li>
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒå
šã¯ãšãªãžã®çãã<i>Q</i> è¡ã§åºåããïŒããªãã¡ïŒ<i>i</i> è¡ç®ã«ïŒè¡<i>S<sub>i</sub></i> ããè¡<i>T<sub>i</sub></i> ãžã®ãã¹ãŠã®çµè·¯ã®ãã¡ïŒãç¥ããŸã§ã®è·é¢ãæå€§ãšãªãçµè·¯ã®ïŒãç¥ããŸã§ã®è·é¢ãè¡šãæŽæ°ãåºåããïŒ
</p>
<h2>æ¡ç¹åºæº</h2>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡ïŒ<br>
é
ç¹ã®10% åã«ã€ããŠã¯ïŒ<i>Q</i> = 1 ãæºããïŒ<br>
é
ç¹ã®20% åã«ã€ããŠã¯ïŒ<i>N</i> ≤ 5000, <i>Q</i> ≤ 5000 ãæºããïŒ<br>
é
ç¹ã®30% åã«ã€ããŠã¯ïŒããã2 ã€ã®æ¡ä»¶ã®å°ãªããšãäžæ¹ãæºããïŒãŸãïŒããã2 ã€ã®æ¡ä»¶ã®äž¡æ¹ãæºãããããªæ¡ç¹çšããŒã¿ã¯ãªãïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
6 6 2 3
1 2 5
2 3 4
2 4 6
3 5 9
4 5 3
5 6 7
1
6
3 4
5 2
1 4
</pre>
<h3>åºåäŸ 1</h3>
<pre>
7
5
0
</pre>
<p>
6 ã€ã®è¡ã6 æ¬ã®éè·¯ã§çµã°ããŠããïŒãç¥ãã¯è¡1, 6 ã®2 ã€ã®è¡ã§éå¬ãããŠããïŒã¯ãšãªã¯ä»¥äžã®3 ã€ã§ããïŒ
</p>
<ul>
<li> 1 ã€ç®ã®ã¯ãšãªã¯è¡3 ããè¡4 ãžè¡ããšãããã®ã§ããïŒè¡2 ãçµç±ããçµè·¯ã§ã¯ãç¥ããŸã§ã®è·é¢ã¯5ïŒè¡5 ãçµç±ããçµè·¯ã§ã¯ãç¥ããŸã§ã®è·é¢ã¯7 ãšãªãããïŒçãã¯7 ã§ããïŒ
</li>
<li> 2 ã€ç®ã®ã¯ãšãªã¯è¡5 ããè¡2 ãžè¡ããšãããã®ã§ããïŒè¡3 ãšè¡4 ã®ã©ã¡ããçµç±ããŠãïŒè¡2 ã§ãç¥ããŸã§ã®è·é¢ãæå°ãšãªãïŒçãã¯5 ã§ããïŒ
</li>
<li> 3 ã€ç®ã®ã¯ãšãªã¯è¡1 ããè¡4 ãžè¡ããšãããã®ã§ããïŒè¡1 ã¯ãç¥ããéå¬ãããŠããè¡ã§ããããïŒçãã¯0 ãšãªãïŒ
</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_festivalsInJOIKingdom1"><br>
<b>
å³1: å
¥åäŸ1
</b>
</center>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
12 17 2 5
1 3 6
1 6 7
2 3 8
2 4 4
2 8 11
2 12 2
3 6 3
3 7 8
3 11 2
4 12 2
5 10 3
6 10 5
8 9 6
8 12 7
9 10 6
11 9 10
12 9 5
8
7
2 6
5 2
1 10
8 9
9 4
</pre>
<h3>åºåäŸ 2</h3>
<pre>
8
8
11
0
6
</pre>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_festivalsInJOIKingdom2"><br>
<b>
å³1: å
¥åäŸ2
</b>
</center>
<br>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p03467 | <span class="lang-en">
<p>Score : <var>1400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Consider the following set of rules for encoding strings consisting of <code>0</code> and <code>1</code>:</p>
<ul>
<li>Strings <code>0</code> and <code>1</code> can be encoded as <code>0</code> and <code>1</code>, respectively. </li>
<li>If strings <var>A</var> and <var>B</var> can be encoded as <var>P</var> and <var>Q</var>, respectively, then string <var>AB</var> can be encoded as <var>PQ</var>.</li>
<li>If string <var>A</var> can be encoded as <var>P</var> and <var>K \geq 2</var> is a positive integer, then string <var>AA...A</var> (<var>A</var> repeated <var>K</var> times) can be encoded as <code>(</code><var>P</var><code>x</code><var>K</var><code>)</code>.</li>
</ul>
<p>For example, string <code>001001001</code>, among other possibilities, can be encoded as <code>001001001</code>, <code>00(1(0x2)x2)1</code> and <code>(001x3)</code>.</p>
<p>Let's call string <var>A</var> a subset of string <var>B</var> if:</p>
<ul>
<li><var>A</var> and <var>B</var> are equal in length and consist of <code>0</code> and <code>1</code>;</li>
<li>for all indices <var>i</var> such that <var>A_i</var> = <code>1</code>, it's also true that <var>B_i</var> = <code>1</code>.</li>
</ul>
<p>You are given string <var>S</var> consisting of <code>0</code> and <code>1</code>. Find the total number of distinct encodings of all subsets of <var>S</var>, modulo <var>998244353</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq |S| \leq 100</var></li>
<li><var>S</var> consists of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total number of distinct encodings of all subsets of <var>S</var> modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>011
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p>There are four subsets of <var>S</var>:</p>
<ul>
<li><code>011</code> can be encoded as <code>011</code> and <code>0(1x2)</code>;</li>
<li><code>010</code> can be encoded as <code>010</code>;</li>
<li><code>001</code> can be encoded as <code>001</code> and <code>(0x2)1</code>;</li>
<li><code>000</code> can be encoded as <code>000</code>, <code>0(0x2)</code>, <code>(0x2)0</code> and <code>(0x3)</code>.</li>
</ul>
<p>Thus, the total number of encodings of all subsets of <var>S</var> is <var>2 + 1 + 2 + 4 = 9</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>10
</pre>
<p>This time <var>S</var> has only one subset, but it can be encoded in <var>10</var> different ways.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>101110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>156
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>001110111010110001100000100111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>363383189
</pre>
<p>Don't forget to take the result modulo <var>998244353</var>.</p></section>
</div>
</span> |
p03037 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have <var>N</var> ID cards, and there are <var>M</var> gates.</p>
<p>We can pass the <var>i</var>-th gate if we have one of the following ID cards: the <var>L_i</var>-th, <var>(L_i+1)</var>-th, ..., and <var>R_i</var>-th ID cards.</p>
<p>How many of the ID cards allow us to pass all the gates alone?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq M \leq 10^5</var></li>
<li><var>1 \leq L_i \leq R_i \leq 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>M</var>
<var>L_1</var> <var>R_1</var>
<var>L_2</var> <var>R_2</var>
<var>\vdots</var>
<var>L_M</var> <var>R_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ID cards that allow us to pass all the gates alone.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2
1 3
2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Two ID cards allow us to pass all the gates alone, as follows:</p>
<ul>
<li>The first ID card does not allow us to pass the second gate.</li>
<li>The second ID card allows us to pass all the gates.</li>
<li>The third ID card allows us to pass all the gates.</li>
<li>The fourth ID card does not allow us to pass the first gate.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 3
3 6
5 7
6 9
</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>100000 1
1 100000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100000
</pre></section>
</div>
</span> |
p02276 | <H1>Partition</H1>
<!--
<p style="color:#f00">
Please note that problem description and judge data for this problem are still under construction. They may revised and your submissions can be rejudged.
</p>
-->
<p>
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q.
</p>
<p>
In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r).
</p>
<p>
Your task is to read a sequence A and perform the Partition based on the following pseudocode:
</p>
<pre>
Partition(A, p, r)
1 x = A[r]
2 i = p-1
3 for j = p to r-1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1
</pre>
</p>
Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].
</p>
<H2>Input</H2>
<p>
The first line of the input includes an integer <i>n</i>, the number of elements in the sequence A.
</p>
<p>
In the second line, <i>A<sub>i</sub></i> (<i>i</i> = 1,2,...,<i>n</i>), elements of the sequence are given separated by space characters.
</p>
<H2>Output</H2>
<p>
Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. The element which is selected as the pivot of the partition should be indicated by <span>[</span> <span>]</span>.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 100,000</li>
<li>0 ≤ <i>A<sub>i</sub></i> ≤ 100,000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
12
13 19 9 5 12 8 7 4 21 2 6 11
</pre>
<H2>Sample Output 1</H2>
<pre>
9 5 8 7 4 2 6 [11] 21 13 19 12
</pre>
|
p01909 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1>E: 忥åŒ</h1>
<h2>èæ¯</h2>
<p>
ããæ¥ Y ããã¯ããã°ã©ãã³ã°ã³ã³ãã¹ãã«åå ããããïŒäŒå Žããã倧åŠã«åãããŸããïŒ
ãšããã倧åŠã«çããšäººãããããïŒãªããšä»æ¥ã¯åæ¥åŒã ã£ãã®ã§ãïŒ
äŒå Žã«åãããã«ãäººã«æŒãæµãããŠããŸãïŒèªåã®é²ã¿ããæ¹åã«é²ãããšããã§ããŸããïŒ
人混ã¿ããæãåºãããã«ïŒY ããã¯ä»ããå Žæããå°ãã§ãé ãã«è¡ããããšèããŸããïŒ
ããã§ Y ããã¯ç¶æ³ã以äžã®ãããªåé¡ãšããŠå®åŒåãïŒç«¶æããã°ã©ãã³ã°ã圹ã«ç«ãŠãããšã«ããŸããïŒ
</p>
<p>
ãªãïŒä»¥äžã®å顿ã§ã¯ Y ããã¯ç¹ $P$ ãšããŠã¢ãã«åãããŠããŸãïŒ
</p>
<h2>åé¡</h2>
<p>
座æšå¹³é¢äžã®åç¹ã«ç¹ $P$ ã眮ãããŠããïŒ
ç¹ $P$ ãåããïŒã§ããã ãåç¹ããã®ãã³ããã¿ã³è·é¢ãé ãäœçœ®ã«ç§»åããããïŒ
</p>
<p>
ã¯ããã«ïŒæåå $S = s_1s_2 \cdots s_{|S|}$ ($|S|$ 㯠$S$ ã®æåæ°) ãäžããããïŒ
ç¹ $P$ ã®ç§»åã¯ïŒæåå $S$ ã®å
é ããæåã 1 æåãã€èªã¿èŸŒãããšã§è¡ãïŒ
æåå $S$ ã¯æå 'U', 'L', 'D', 'R' ãããªãïŒ
ããããã®æåãèªã¿èŸŒãã ãšãïŒç¹ $P$ ã®ç§»ååã®åº§æšã $(x, y)$ ãšãããšïŒ
ç§»ååŸã®ç¹ $P$ ã®åº§æšã¯ãããã $(x, y+1),\ (x-1, y),\ (x, y-1),\ (x+1, y)$ ãšãªãïŒ
</p>
<p>
åæåãèªã¿èŸŒãçŽåã«ïŒéæ³ãããããåŠããéžæããããšãã§ããïŒ
éæ³ã«ã¯éæ³ 1 ãšéæ³ 2 ã®äºçš®é¡ãããïŒæåå $S$ ã® $i$ çªç®ã®æåã $s_i$ ãšãããšïŒ
$s_i$ ãèªã¿èŸŒãçŽåã«éæ³ãããããšãã®å€åã¯ä»¥äžã®éãã§ããïŒ
</p>
<ul>
<li>éæ³ 1 ãããããšã: å
šãŠã® $s_j \ (i \le j \le |S|)$ ã«å¯ŸãïŒ'U' ã 'D' ã«ïŒ'D' ã 'U' ã«çœ®æããïŒ</li>
<li>éæ³ 2 ãããããšã: å
šãŠã® $s_j \ (i \le j \le |S|)$ ã«å¯ŸãïŒ'L' ã 'R' ã«ïŒ'R' ã 'L' ã«çœ®æããïŒ</li>
</ul>
<p>
çŽæçã«ã¯ïŒéæ³ 1 ã§ã¯ãã®åŸã®äžäžã®æ±ããå転ãããããšãã§ãïŒéæ³ 2 ã§ã¯å·Šå³ã®æ±ããå転ãããããšãã§ããïŒ
ããæåãèªã¿èŸŒãåã«ãããéæ³ã®åæ°ã¯è€æ°åã§ãæ§ããªãïŒãŸãïŒäž¡æ¹ã®éæ³ãç¶ããŠãããŠãããŸããªãïŒ
ãã ãïŒæåå $S$ ã®æåããã¹ãŠèªã¿çµãããŸã§ã«éæ³ããããããåæ°ã¯ïŒåèš $K$ åãŸã§ã§ããïŒ
詳现ã¯ãµã³ãã«ãåç
§ããããïŒ
</p>
<p>
æåå $S$ ã®æåããã¹ãŠèªã¿çµããåŸã®ç¹ $P$ ã®åº§æšã $(x',y')$ ãšãããšãïŒ$|x'| + |y'|$
ã®æå€§å€ãæ±ããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le |S| \le 2000$</li>
<li>$1 \le K \le 2000$</li>
</ul>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ
</p>
<p>
$S$<br>
$K$
</p>
<h2>åºå</h2>
<p>
$|x'| + |y'|$ ã®æå€§å€ã 1 è¡ã§åºåããïŒãŸããæ«å°Ÿã«æ¹è¡ãåºåãã.
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
RRLUDDD
2
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
7
</pre>
<p>
3 æåç®ãèªã¿èŸŒãçŽåã«éæ³ 2 ãããããšïŒæåå $S$ 㯠"RRRUDDD" ãšãªãïŒ
ç¶ã㊠5 æåç®ãèªã¿èŸŒãçŽåã«éæ³ 1 ãããããšïŒæåå $S$ 㯠"RRRUUUU" ãšãªãïŒ
ãã¹ãŠã®æåãèªã¿çµããåŸã®ç¹ $P$ ã®åº§æšã¯ $(3, 4)$ ãšãªãïŒ
åç¹ããã®ãã³ããã¿ã³è·é¢ã¯ 7 ã§ããïŒããã¯ãã®äŸã®æå€§å€ã§ããïŒ
</p>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
LULLLUULLU
1984
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
10
</pre>
<p>
1 åãéæ³ããããªãã£ãå ŽåïŒ$xâ = -6, \ yâ = 4$ ãšãªãïŒ$|xâ| + |yâ| = 10$ ã§ããïŒ
</p>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
DRDLUDD
1
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
5
</pre>
<h3>ãµã³ãã«å
¥å 4</h3>
<pre>
LURRRLUDLL
1
</pre>
<h3>ãµã³ãã«åºå 4</h3>
<pre>
6
</pre>
|
p03934 | <span class="lang-en lang-child hidden-lang">
<div id="task-statement">
<div class="part">
Max Score: $1200$ Points <br/>
<section>
<h3>Problem statement</h3>
There are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$. <br/>
A sushi chef carried out $Q$ operations for customers. <br/>
<br/>
The $i$-th operation is follows: <br/>
<ol class="simple">
<li>The sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers. </li>
<li>He puts a dish of sushi on the selected seats.</li>
<li>A customer who have selected for professional eats this sushi.</li>
<li>Repeat 1-3, $b_i$ times.</li>
</ol>
<br/>
Please calculate the number of dishes of sushi that have been eaten by each customer.<br/>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
The input is given from Standard Input in the following format: <br/>
<blockquote>$N \ Q$
$a_1 \ b_1$
$a_2 \ b_2$
$ ïŒ \ ïŒ $
$a_Q \ b_Q$
</blockquote>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<ul>
<li>You have to print $N$ lines.</li>
<li>The $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \le i \le N)$.</li>
</ul>
</section>
<section>
<h3>Constraints</h3>
<ul>
<li>$3 \le N, Q \le 100,000$</li>
<li>$1 \le a_i \le N$</li>
<li>$1 \le b_i \le 10^{12}$</li>
<li>Any final results do not exceed $2 \times 10^{13}$.</li>
</ul>
</section>
<section>
<h3>Subtasks</h3>
Subtask 1 [ $60$ points ] <br/>
<ul>
<li>$N, Q \le 100$</li>
<li>$b_i = 1$</li>
</ul>
Subtask 2 [ $400$ points ] <br/>
<ul>
<li>$N, Q \le 100$</li>
<li>$b_i \le 10^{12}$</li>
</ul>
Subtask 3 [ $240$ points ] <br/>
<ul>
<li>$N, Q \le 100,000$</li>
<li>$b_i = 1$</li>
</ul>
Subtask 4 [ $500$ points ] <br/>
<ul>
<li>There are no additional constraints.</li>
</ul>
</section>
</div>
</div>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
9 3
5 11
8 4
4 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
4
4
4
4
2
2
1
1
0
</pre>
The change of the number of dishes of sushi have eaten is following: <br/>
<br/>
<table class="table-striped table-bordered table-condensed">
<tr align="center">
<th></th>
<td width="90">Customer 1</td>
<td width="90">Customer 2</td>
<td width="90">Customer 3</td>
<td width="90">Customer 4</td>
<td width="90">Customer 5</td>
<td width="90">Customer 6</td>
<td width="90">Customer 7</td>
<td width="90">Customer 8</td>
<td width="90">Customer 9</td>
</tr>
<tr align="center">
<th>1st Operation</th>
<td>3</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td>
</tr>
<tr align="center">
<th>2nd Operation</th>
<td>3</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>2</td> <td>1</td> <td>1</td> <td>0</td>
</tr>
<tr align="center">
<th>3rd Operation</th>
<td>4</td> <td>4</td> <td>4</td> <td>4</td> <td>2</td> <td>2</td> <td>1</td> <td>1</td> <td>0</td>
</tr>
</table>
<br/>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
6 6
3 5
6 11
1 6
4 7
5 2
2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
10
10
5
5
4
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 3</h3>
<pre>
5 6
1 1
2 1
3 1
1 1
5 1
3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3>
<pre>
2
2
1
1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 4</h3>
<pre>
10 10
10 10
9 20
8 30
7 40
6 50
5 60
4 70
3 80
2 90
1 100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3>
<pre>
223
123
77
50
33
21
12
7
3
1
</pre>
</section>
</div>
Writer: E869120 <br/>
</div>
</span> |
p02626 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> piles of stones. The <var>i</var>-th pile has <var>A_i</var> stones.</p>
<p>Aoki and Takahashi are about to use them to play the following game:</p>
<ul>
<li>Starting with Aoki, the two players alternately do the following operation:<ul>
<li>Operation: Choose one pile of stones, and remove one or more stones from it.</li>
</ul>
</li>
<li>When a player is unable to do the operation, he loses, and the other player wins.</li>
</ul>
<p>When the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.</p>
<p>In such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most <var>(A_1 - 1)</var> stones from the <var>1</var>-st pile to the <var>2</var>-nd pile before the game begins.</p>
<p>If this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print <code>-1</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 300</var></li>
<li><var>1 \leq A_i \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>A_1</var> <var>\ldots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of stones to move to guarantee Takahashi's win; otherwise, print <code>-1</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>Without moving stones, if Aoki first removes <var>2</var> stones from the <var>1</var>-st pile, Takahashi cannot win in any way.</p>
<p>If Takahashi moves <var>1</var> stone from the <var>1</var>-st pile to the <var>2</var>-nd before the game begins so that both piles have <var>4</var> stones, Takahashi can always win by properly choosing his actions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2
3 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>It is not allowed to move stones from the <var>2</var>-nd pile to the <var>1</var>-st.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
1 1 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>-1
</pre>
<p>It is not allowed to move all stones from the <var>1</var>-st pile.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8
10 9 8 7 6 5 4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>3
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>3
4294967297 8589934593 12884901890
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>1
</pre>
<p>Watch out for overflows.</p></section>
</div>
</span> |
p02333 | <!--<h1>åå12çž ãã®3:ããŒã«ã«åºå¥ããã»ç®±ã«åºå¥ããã»ç®±ã®äžèº«ã¯1ã€ä»¥äž</h1>-->
<h1>Balls and Boxes 3</h1>
<table border="">
<tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr>
<tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td style="background-color:#aff">3</td></tr>
<tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr>
<tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td>9</td></tr>
<tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr>
</table>
<h2>Problem</h2>
<p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p>
<p>Find the number of ways to put the balls under the following conditions:</p>
<ul>
<li>Each ball is distinguished from the other.</li>
<li>Each box is distinguished from the other.</li>
<li>Each ball can go into only one box and no one remains outside of the boxes.</li>
<li>Each box must contain at least one ball.</li>
</ul>
<p>Note that you must print this count modulo $10^9+7$.</p>
<h2>Input</h2>
<pre>
$n$ $k$
</pre>
<p>The first line will contain two integers $n$ and $k$.</p>
<h2>Output</h2>
<p>Print the number of ways modulo $10^9+7$ in a line.</p>
<h2>Constraints</h2>
<ul>
<li>$1 \le n \le 1000$</li>
<li>$1 \le k \le 1000$</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
4 3
</pre>
<h2>Sample Output 1</h2>
<pre>
36
</pre>
<h2>Sample Input 2</h2>
<pre>
10 3
</pre>
<h2>Sample Output 2</h2>
<pre>
55980
</pre>
<h2>Sample Input 3</h2>
<pre>
100 100
</pre>
<h2>Sample Output 3</h2>
<pre>
437918130
</pre>
|
p02299 |
<H1>Polygon-Point-Containment</H1>
<br/>
<p>
For a given polygon <var>g</var> and target points <var>t</var>, print "2" if <var>g</var> contains <var>t</var>, "1" if <var>t</var> is on a segment of <var>g</var>, "0" otherwise.
</p>
<p>
<var>g</var> is represented by a sequence of points <var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>,..., <var>p<sub>n</sub></var> where line segments connecting <var>p<sub>i</sub></var> and <var>p<sub>i+1</sub></var> (1 ≤ <var>i</var> ≤ <var>n-1</var>) are sides of the polygon. The line segment connecting <var>p<sub>n</sub></var> and <var>p<sub>1</sub></var> is also a side of the polygon.
</p>
<p>
Note that the polygon is not necessarily convex.
</p>
<H2>Input</H2>
<p>
The entire input looks like:
</p>
<pre>
<var>g</var> (the sequence of the points of the polygon)
<var>q</var> (the number of queris = the number of target points)
1st query
2nd query
:
<var>q</var>th query
</pre>
<p>
<var>g</var> is given by coordinates of the points <var>p<sub>1</sub></var>,..., <var>p<sub>n</sub></var> in the following format:
</p>
<pre>
<var>n</var>
<var>x<sub>1</sub></var> <var>y<sub>1</sub></var>
<var>x<sub>2</sub></var> <var>y<sub>2</sub></var>
:
<var>x<sub>n</sub></var> <var>y<sub>n</sub></var>
</pre>
<p>
The first integer <var>n</var> is the number of points. The coordinate of a point <var>p<sub>i</sub></var> is given by two integers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. The coordinates of points are given in the order of counter-clockwise visit of them.
</p>
<p>
Each query consists of the coordinate of a target point <var>t</var>. The coordinate is given by two intgers <var>x</var> and <var>y</var>.
</p>
<H2>Output</H2>
<p>
For each query, print "2", "1" or "0".
</p>
<H2>Constraints</H2>
<ul>
<li>
3 ≤ <var>n</var> ≤ 100
</li>
<li>
1 ≤ <var>q</var> ≤ 1000
</li>
<li>
-10000 ≤ <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> ≤ 10000
</li>
<li>No point of the polygon will occur more than once.</li>
<li>Two sides of the polygon can intersect only at a common endpoint.</li>
</ul>
<H2>Sample Input</H2>
<pre>
4
0 0
3 1
2 3
0 3
3
2 1
0 2
3 2
</pre>
<H2>Sample Output</H2>
<pre>
2
1
0
</pre>
<br/> |
p03871 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><style>
#nck {
width: 30px;
height: auto;
}
</style>
<p>There are two (6-sided) dice: a red die and a blue die.
When a red die is rolled, it shows <var>i</var> with probability <var>p_i</var> percents, and when a blue die is rolled, it shows <var>j</var> with probability <var>q_j</var> percents.</p>
<p>Petr and tourist are playing the following game.
Both players know the probabilistic distributions of the two dice.
First, Petr chooses a die in his will (without showing it to tourist), rolls it, and tells tourist the number it shows.
Then, tourist guesses the color of the chosen die.
If he guesses the color correctly, tourist wins. Otherwise Petr wins.</p>
<p>If both players play optimally, what is the probability that tourist wins the game?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 †p_i, q_i †100</var></li>
<li><var>p_1 + ... + p_6 = q_1 + ... + q_6 = 100</var></li>
<li>All values in the input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>p_1</var> <var>p_2</var> <var>p_3</var> <var>p_4</var> <var>p_5</var> <var>p_6</var>
<var>q_1</var> <var>q_2</var> <var>q_3</var> <var>q_4</var> <var>q_5</var> <var>q_6</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the probability that tourist wins.
The absolute error or the relative error must be at most <var>10^{-9}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>25 25 25 25 0 0
0 0 0 0 50 50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1.000000000000
</pre>
<p>tourist can always win the game: If the number is at most <var>4</var>, the color is definitely red. Otherwise the color is definitely blue.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 20 20 10 20 20
20 20 20 10 10 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0.550000000000
</pre></section>
</div>
</span> |
p02763 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a string <var>S</var> of length <var>N</var> consisting of lowercase English letters.</p>
<p>Process <var>Q</var> queries of the following two types:</p>
<ul>
<li>Type <var>1</var>: change the <var>i_q</var>-th character of <var>S</var> to <var>c_q</var>. (Do nothing if the <var>i_q</var>-th character is already <var>c_q</var>.)</li>
<li>Type <var>2</var>: answer the number of different characters occurring in the substring of <var>S</var> between the <var>l_q</var>-th and <var>r_q</var>-th characters (inclusive).</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var>, <var>Q</var>, <var>i_q</var>, <var>l_q</var>, and <var>r_q</var> are integers.</li>
<li><var>S</var> is a string consisting of lowercase English letters.</li>
<li><var>c_q</var> is a lowercase English letter.</li>
<li><var>1 \leq N \leq 500000</var></li>
<li><var>1 \leq Q \leq 20000</var></li>
<li><var>|S| = N</var></li>
<li><var>1 \leq i_q \leq N</var></li>
<li><var>1 \leq l_q \leq r_q \leq N</var></li>
<li>There is at least one query of type <var>2</var> in each testcase.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
<var>Q</var>
<var>Query_1</var>
<var>\vdots</var>
<var>Query_Q</var>
</pre>
<p>Here, <var>Query_i</var> in the <var>4</var>-th through <var>(Q+3)</var>-th lines is one of the following:</p>
<pre><var>1</var> <var>i_q</var> <var>c_q</var>
</pre>
<pre><var>2</var> <var>l_q</var> <var>r_q</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>For each query of type <var>2</var>, print a line containing the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
1
5
</pre>
<p>In the first query, <code>cdbb</code> contains three kinds of letters: <code>b</code> , <code>c</code> , and <code>d</code>, so we print <var>3</var>.</p>
<p>In the second query, <var>S</var> is modified to <code>abcdzbd</code>.</p>
<p>In the third query, <code>a</code> contains one kind of letter: <code>a</code>, so we print <var>1</var>.</p>
<p>In the fourth query, <var>S</var> is modified to <code>abcazbd</code>.</p>
<p>In the fifth query, <var>S</var> does not change and is still <code>abcazbd</code>.</p>
<p>In the sixth query, <code>abcazbd</code> contains five kinds of letters: <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, and <code>z</code>, so we print <var>5</var>.</p></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.