question_id stringlengths 6 6 | content stringlengths 1 27.2k |
|---|---|
p01044 |
<h1>Problem HïŒ Puzzle and Hexagons</h1>
<h2>Backgorund</h2>
<p>
è¶
倧人æ°ã²ãŒã ãããºã«&ãããµãŽã³ãºããã€ãã«ãªãªãŒã¹ãããããã®ã²ãŒã ã¯è¶
é¢çœãããŠãããããã人ãç¶åºãããŸãã®ç±äžåºŠã«å»åž«ããäžæ¯èªå®ãåããè
ãç¶åºãããäžçååœã®æå¿éã¯ãã®ã²ãŒã ã®äžæ¯è
éãå©ããããã«ãããºã«&ãããµãŽã³ãºãã®ã·ãã¥ã¬ãŒã¿ãäœããå±éºãªå®æ©ã§ã®ãã¬ã€ãé¿ããããä¿ãããšãããããªãã«ã¯ã·ãã¥ã¬ãŒã¿äœãã«ååããŠæ¬²ããã
</p>
<h2>Problem</h2>
<p>
æ£å
è§åœ¢ã®ãã¹ã瞊ã«<var>H</var>åãæšªã«<var>W</var>åæ·ãè©°ããç€é¢ãäžããããã
Fig.1ã¯<var>H</var>=4,<var>W</var>=7ã®æã®ç€é¢ãšããã«å¯Ÿå¿ãããã¹ã®åº§æš(<var>x</var>,<var>y</var>)ã瀺ãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_H_img2.png" width="480"><br>
Fig.1
</center>
<p>
åæç¶æ
ã§åãã¹ã«ã¯è²ã®ã€ãããããã¯ãååšããã
ãããã¯ã®è²ã¯ä»¥äžã®ããã«ã¢ã«ãã¡ãããäžæåã§è¡šçŸãããã
</p>
<ul>
<li>'R' ã»ã»ã»èµ€</li>
<li>'G' ã»ã»ã»ç·</li>
<li>'B' ã»ã»ã»é</li>
<li>'P' ã»ã»ã»çŽ«</li>
<li>'Y' ã»ã»ã»é»</li>
<li>'E' ã»ã»ã»æ°Ž</li>
</ul>
<p>
æ¬¡ã«æäœã®æ°<var>Q</var>ãäžããããã
</p>
<p>
åæäœã§ã¯å転ã®äžå¿åº§æš(<var>x</var>,<var>y</var>)ãäžãããããã®ãã¹ã®åšå²ã«ãã6ã€ã®ãããã¯ãæèšåãã«äžã€å転ãããããšã瀺ãã(Fig.2 åç
§)ã
ãã®ãšãããããã¯ãååšããªããã¹ã空ã®ãããã¯ãååšãããšèããŠæèšåãã«äžã€å転ãããã
ãã ããæå®ããã座æšãšãã®åšèŸºã®ïŒã€ã®ãã¹ã®å
ããããäžã€ã§ã<var>H</var>Ã<var>W</var>ã®ç€é¢ã®äžã«ååšããŠããªãå Žåã¯å転ãè¡ããªãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_H_img1.png" width="400"><br>
Fig.2</center>
<p>
次ã«ä»¥äžã®åŠçãã§ããªããªããŸã§ç¹°ãè¿ãã
</p>
<ol>
<li>Fig.3ã«ãããŠããããã¯Aã®äœçœ®ããB, C, Dã®äœçœ®ã®ãããã®ãã¹ã«ããããã¯ãååšããªããšãããããã¯Aã¯Cã®äœçœ®ã«èœäžããããã¹B, Dãååšããªãå Žåã¯ãããã¯ãååšããªããšèãããã¹Cãååšããªãå Žåã¯èœäžã®åŠçãè¡ããªãã</li>
<li>1ã®åŠçãå¯èœãªãããã¯ãååšããå Žåã¯1ã«æ»ãã</li>
<li>åãè²ã®ãããã¯ã3ã€ä»¥äžç¹ãã£ãŠããå Žåããã®ãããã¯ã¯å
šãŠæ¶æ»
ããã
2ã€ã®ãããã¯ãç¹ãããšã¯ãã¹ã®äžèŸºãå
±æããããšã§ããã</li>
</ol>
<p>
泚æïŒãã®äžé£ã®åŠçã¯ãæäœãäžã€ãäžããããŠããªãç¶æ
ïŒåæç¶æ
ïŒã§ãè¡ãããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_H_img4.png" width="600"><br>
Fig.3</center>
<p>
å
šãŠã®æäœãå®è¡ããåŸã®æçµçãªç€é¢ãåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>H</var> <var>W</var>
<var>F</var><sub>0,</sub><var><sub>H−1</sub></var> <var>F</var><sub>1,</sub><var><sub>H−1</sub></var> ⊠<var>F</var><var><sub>W−1,</sub></var><var><sub>H−1</sub></var>
<var>F</var><sub>0,</sub><var><sub>H−2</sub></var> <var>F</var><sub>1,</sub><var><sub>H−2</sub></var> ⊠<var>F</var><var><sub>W−1,</sub></var><var><sub>H−2</sub></var>
.
.
.
<var>F</var><sub>0,</sub><sub>0</sub> <var>F</var><sub>1,</sub><sub>0</sub> ⊠<var>F</var><var><sub>W−1,</sub></var><sub>0</sub>
<var>Q</var>
<var>x</var><sub>0</sub> <var>y</var><sub>0</sub>
<var>x</var><sub>1</sub> <var>y</var><sub>1</sub>
.
.
.
<var>x</var><var><sub>Q−1</sub></var> <var>y</var><var><sub>Q−1</sub></var>
</pre>
<p>
1è¡ç®ã«ãç€é¢ã®çžŠãšæšªã®ãµã€ãºã衚ã2ã€ã®æŽæ°<var>H</var>ãš<var>W</var>ãäžããããã
2è¡ç®ãã<var>H</var>+1è¡ç®ã«ãåæ·»åã«å¯Ÿå¿ããç€é¢ã®è²ã衚ãæååãäžããããã
<var>H</var>+2è¡ç®ã«ãæäœã®æ°<var>Q</var>ãäžããããã
ç¶ã<var>Q</var>è¡ã«å転ã®äžå¿ã®ãã¹ã®åº§æšã衚ã<var>x</var>ãš<var>y</var>ãäžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>3 ≤ <var>H</var> ≤ 50</li>
<li>3 ≤ <var>W</var> ≤ 50</li>
<li>0 ≤ <var>x</var> < <var>W</var></li>
<li>0 ≤ <var>y</var> < <var>H</var></li>
<li>1 ≤ <var>Q</var> ≤ 100</li>
<li><var>F<sub>i,</sub><sub>j</sub></var> ( 0 ≤ <var>i</var> < W , 0 ≤ <var>j</var> < H ) ã¯'R','G','B','P','Y','E'ã®ããããã§ããã</li>
</ul>
<h2>Output</h2>
<p>
å
šãŠã®æäœãè¡ã£ãåŸã®ç€é¢ã<var>H</var>è¡ã§åºåããã
ãã ãããããã¯ãç¡ããã¹ã¯'.'ã§è¡šãããšã
</p>
<h2>Sample Input1</h2>
<pre>
3 3
RGR
RBP
YEB
1
1 1
</pre>
<h2>Sample Output1</h2>
<pre>
âŠ
YBG
EBP
</pre>
<p>
Fig.4ã¯Sample Input1ã«ãããç¶æ
ã®é·ç§»ã衚ãããã®ã§ããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp15_UA_H_img5.png"><br>
Fig.4</center>
<h2>Sample Input2</h2>
<pre>
4 5
BYYGG
RRRRR
RRBRR
YYGGB
2
3 1
3 1
</pre>
<h2>Sample Output2</h2>
<pre>
.....
.....
.....
B.BGB
</pre>
<h2>Sample Input3</h2>
<pre>
4 4
BEEP
ERYY
BBRP
RBYP
1
1 2
</pre>
<h2>Sample Output3</h2>
<pre>
....
....
....
.B..
</pre>
<p>
ç€é¢ã®åæç¶æ
ã§ãã§ã«æ¶ãããããã¯ãããããšæ³šæã
䞡端ã«ãããããã¯ã®èœäžåŠçã«æ³šæã
</p>
|
p03079 | <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, B</var> and <var>C</var>.</p>
<p>Determine if there exists an equilateral triangle whose sides have lengths <var>A, B</var> and <var>C</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,B,C \leq 100</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var> <var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exists an equilateral triangle whose sides have lengths <var>A, B</var> and <var>C</var>, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<ul>
<li>There exists an equilateral triangle whose sides have lengths <var>2, 2</var> and <var>2</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<ul>
<li>There is no equilateral triangle whose sides have lengths <var>3, 4</var> and <var>5</var>.</li>
</ul></section>
</div>
</span> |
p01414 |
<H1>H: Rectangular Stamps</H1>
<p>
ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ
</p>
<p>
仿¥ã®ä¿®è¡ã¯ïŒçµµãæãããšã«ãã£ãŠïŒåµé åãé«ããããšãããã®ã§ããïŒåè§ãã¹ã¿ã³ããçšããŠïŒäžæãæš¡æ§ãæããïŒ
</p>
<p>
倧å°ããŸããŸãªã¹ã¿ã³ãã䜿ãïŒ4 × 4 ã®ãã¹ç®ã®çŽã«æå®ãããèµ€ã»ç·ã»éã®éãã®çµµã宿ããããïŒã¹ã¿ã³ãã¯é·æ¹åœ¢ã§ããïŒãã¹ç®ã«ãŽã£ããåãããŠäœ¿ãïŒã¹ã¿ã³ãã®çžŠãšæšªãå
¥ãæ¿ããããšã¯ã§ããªãïŒ
</p>
<p>
çŽã¯æåè²ãå¡ãããŠããªãç¶æ
ã«ããïŒçŽã«ã¹ã¿ã³ããæŒããšïŒæŒãããéšåãã¹ã¿ã³ãã®è²ã«å€ããïŒäžã«é ããè²ã¯å
šãèŠããªããªãïŒã¹ã¿ã³ãã®è²ã¯ä»ããã€ã³ã¯ã«ããæ±ºå®ãããã®ã§ïŒã©ã®ã¹ã¿ã³ãã§ãïŒå¥œããªè²ãéžã¶ããšãå¯èœã§ããïŒã¹ã¿ã³ãã¯çŽããäžéšãã¯ã¿åºãç¶æ
ã§æŒãããšãå¯èœã§ããïŒã¯ã¿åºãéšåã¯ç¡èŠãããïŒ
</p>
<p>
1 ã€ã®ã¹ã¿ã³ããè€æ°å䜿ãããšã¯å¯èœã§ããïŒåãã¹ã¿ã³ããå¥ã®è²ã«å¯ŸããŠäœ¿ã£ãŠãããïŒã¹ã¿ã³ããæŒãã®ã¯ããç¥çµã䜿ãäœæ¥ãªã®ã§ïŒåºæ¥ãã ãã¹ã¿ã³ããæŒãåæ°ãå°ãªããããïŒ
</p>
<H2>Input</H2>
<pre>
<i>N</i>
<i>H</i><sub>1</sub> <i>W</i><sub>1</sub>
...
<i>H</i><sub><i>N</i></sub> <i>W</i><sub><i>N</i></sub>
<i>C</i><sub>1,1</sub><i>C</i><sub>1,2</sub><i>C</i><sub>1,3</sub><i>C</i><sub>1,4</sub>
<i>C</i><sub>2,1</sub><i>C</i><sub>2,2</sub><i>C</i><sub>2,3</sub><i>C</i><sub>2,4</sub>
<i>C</i><sub>3,1</sub><i>C</i><sub>3,2</sub><i>C</i><sub>3,3</sub><i>C</i><sub>3,4</sub>
<i>C</i><sub>4,1</sub><i>C</i><sub>4,2</sub><i>C</i><sub>4,3</sub><i>C</i><sub>4,4</sub>
</pre>
<p>
<i>N</i> ã¯ã¹ã¿ã³ãã®åæ°ïŒ<i>H</i><sub><i>i</i></sub>, <i>W</i><sub><i>i</i></sub> (1 ≤ <i>i</i> ≤ <i>N</i>) ã¯ããããïŒ<i>i</i> çªç®ã®ã¹ã¿ã³ãã®çžŠã®é·ãïŒæšªã®é·ããè¡šãæŽæ°ã§ããïŒ<i>C</i><sub><i>i</i>, <i>j</i></sub> (1 ≤ <i>i</i> ≤ 4ïŒ1 ≤ <i>j</i> ≤ 4) ã¯ïŒäžãã <i>i</i> è¡ç®ïŒå·Šãã <i>j</i> åç®ã®ãã¹ã«ã€ããŠæå®ãããçµµã®è²ã衚ãæåã§ããïŒèµ€ã¯ <tt>R</tt> ïŒç·ã¯ <tt>G</tt> ïŒé㯠<tt>B</tt> ã§è¡šãããïŒ
</p>
<p>
1 ≤ <i>N</i> ≤ 16ïŒ1 ≤ <i>H</i><sub><i>i</i></sub> ≤ 4ïŒ1 ≤ <i>W</i><sub><i>i</i></sub> ≤ 4 ãæºããïŒ(<i>H</i><sub><i>i</i></sub>, <i>W</i><sub><i>i</i></sub>) ãšããŠåäžã®çµã¯è€æ°åçŸããªãïŒ
</p>
<H2>Output</H2>
<p>
çµµã宿ãããããã«ã¹ã¿ã³ããæŒããªããã°ãªããªãæå°ã®åæ°ã 1 è¡ã«åºåããïŒ
</p>
<H2>Sample Input 1</H2>
<pre>
2
4 4
1 1
RRRR
RRGR
RBRR
RRRR
</pre>
<H2>Sample Output 1</H2>
<pre>
3
</pre>
<H2>Sample Input 2</H2>
<pre>
1
2 3
RRGG
BRGG
BRRR
BRRR
</pre>
<H2>Sample Output 2</H2>
<pre>
5
</pre> |
p03429 | <span class="lang-en">
<p>Score : <var>900</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi has an <var>N \times M</var> grid, with <var>N</var> horizontal rows and <var>M</var> vertical columns.
Determine if we can place <var>A</var> <var>1 \times 2</var> tiles (<var>1</var> vertical, <var>2</var> horizontal) and <var>B</var> <var>2 \times 1</var> tiles (<var>2</var> vertical, <var>1</var> horizontal) satisfying the following conditions, and construct one arrangement of the tiles if it is possible:</p>
<ul>
<li>All the tiles must be placed on the grid.</li>
<li>Tiles must not stick out of the grid, and no two different tiles may intersect.</li>
<li>Neither the grid nor the tiles may be rotated.</li>
<li>Every tile completely covers exactly two squares.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 1000</var></li>
<li><var>0 \leq A,B \leq 500000</var></li>
<li><var>N</var>, <var>M</var>, <var>A</var> and <var>B</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is impossible to place all the tiles, print <code>NO</code>.
Otherwise, print the following:</p>
<pre>YES
<var>c_{11}...c_{1M}</var>
<var>:</var>
<var>c_{N1}...c_{NM}</var>
</pre>
<p>Here, <var>c_{ij}</var> must be one of the following characters: <code>.</code>, <code><</code>, <code>></code>, <code>^</code> and <code>v</code>. Represent an arrangement by using each of these characters as follows:</p>
<ul>
<li>When <var>c_{ij}</var> is <code>.</code>, it indicates that the square at the <var>i</var>-th row and <var>j</var>-th column is empty;</li>
<li>When <var>c_{ij}</var> is <code><</code>, it indicates that the square at the <var>i</var>-th row and <var>j</var>-th column is covered by the left half of a <var>1 \times 2</var> tile;</li>
<li>When <var>c_{ij}</var> is <code>></code>, it indicates that the square at the <var>i</var>-th row and <var>j</var>-th column is covered by the right half of a <var>1 \times 2</var> tile;</li>
<li>When <var>c_{ij}</var> is <code>^</code>, it indicates that the square at the <var>i</var>-th row and <var>j</var>-th column is covered by the top half of a <var>2 \times 1</var> tile;</li>
<li>When <var>c_{ij}</var> is <code>v</code>, it indicates that the square at the <var>i</var>-th row and <var>j</var>-th column is covered by the bottom half of a <var>2 \times 1</var> tile.</li>
</ul>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>YES
<><>
^<>^
v<>v
</pre>
<p>This is one example of a way to place four <var>1 \times 2</var> tiles and three <var>2 \times 1</var> tiles on a <var>3 \times 4</var> grid.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 5 5 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>YES
<>..^
^.<>v
v<>.^
<><>v
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 9 20 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>NO
</pre></section>
</div>
</span> |
p02392 |
<H1>Range</H1>
<p>
Write a program which reads three integers <var>a</var>, <var>b</var> and <var>c</var>, and prints "Yes" if <var>a < b < c</var>, otherwise "No".
</p>
<H2>Input</H2>
<p>
Three integers <var>a</var>, <var>b</var> and <var>c</var> separated by a single space are given in a line.
</p>
<H2>Output</H2>
<p>
Print "Yes" or "No" in a line.
</p>
<h2>Constraints</h2>
<ul>
<li> 0 ≤ <var>a</var>, <var>b</var>, <var>c</var> ≤ 100</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
1 3 8
</pre>
<H2>Sample Output 1</H2>
<pre>
Yes
</pre>
<H2>Sample Input 2</H2>
<pre>
3 8 1
</pre>
<H2>Sample Output 2</H2>
<pre>
No
</pre> |
p01947 |
<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>
Ninja Map
</H1>
<p>
Intersections of Crossing Path City are aligned to a grid. There are $N$ east-west streets which are numbered from 1 to $N$, from north to south. There are also $N$ north-south streets which are numbered from 1 to $N$, from west to east. Every pair of east-west and north-south streets has an intersection; therefore there are $N^2$ intersections which are numbered from 1 to $N^2$.
</p>
<p>
Surprisingly, all of the residents in the city are Ninja. To prevent outsiders from knowing their locations, the numbering of intersections is shuffled.
</p>
<p>
You know the connections between the intersections and try to deduce their positions from the information. If there are more than one possible set of positions, you can output any of them.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case formatted as follows.
</p>
<pre>
$N$
$a_1$ $b_1$
...
$a_{2N^2â2N}$ $\;$ $b_{2N^2â2N}$
</pre>
<p>
The first line consists of an integer $N$ ($2 \leq N \leq 100$). The following $2N^2 - 2N$ lines represent connections between intersections. The ($i+1$)-th line consists of two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq N^2, a_i \ne b_i$), which represent that the $a_i$-th and $b_i$-th intersections are adjacent. More precisely, let's denote by ($r, c$) the intersection of the $r$-th east-west street and the $c$-th north-south street. If the intersection number of ($r,c$) is $a_i$ for some $r$ and $c$, then the intersection
number of either ($r-1, c$), ($r+1, c$), ($r, c-1$) or ($r, c+1$) must be $b_i$. All inputs of adjacencies are different, i.e., ($a_i, b_i$) $\ne$ ($a_j, b_j$) and ($a_i, b_i$) $\ne$ ($b_j, a_j$) for all $1 \leq i < j \leq 2N^2-2N$. This means that you are given information of all adjacencies on the grid.
</p>
<p>
The input is guaranteed to describe a valid map.
</p>
<H2>Output</H2>
<p>
Print a possible set of positions of the intersections. More precisely, the output consists of $N$ lines each of which has space-separated $N$ integers. The $c$-th integer of the $r$-th line should be the intersection number of ($r, c$).
</p>
<p>
If there are more than one possible set of positions, you can output any of them.
</p>
<H2>Sample Input 1</H2>
<pre>
3
1 2
4 7
8 6
2 3
8 9
5 3
4 6
5 6
7 8
1 4
2 6
5 9
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
7 4 1
8 6 2
9 5 3
</pre>
<p>
The following output will also be accepted.
</p>
<pre>
1 2 3
4 6 5
7 8 9
</pre>
<H2>Sample Input 2</H2>
<pre>
4
12 1
3 8
10 7
13 14
8 2
9 12
6 14
11 3
3 13
1 10
11 15
4 15
4 9
14 10
5 7
2 5
6 1
14 5
16 11
15 6
15 13
9 6
16 4
13 2
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
8 2 5 7
3 13 14 10
11 15 6 1
16 4 9 12
</pre> |
p02668 | <span class="lang-en">
<p>Score : <var>1000</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Snuke came up with a game that uses a number sequence, as follows:</p>
<ul>
<li>
<p>Prepare a sequence of length <var>M</var> consisting of integers between <var>0</var> and <var>2^N-1</var> (inclusive): <var>a = a_1, a_2, \ldots, a_M</var>.</p>
</li>
<li>
<p>Snuke first does the operation below as many times as he likes:</p>
<ul>
<li>Choose a positive integer <var>d</var>, and for each <var>i</var> <var>(1 \leq i \leq M)</var>, in binary, set the <var>d</var>-th least significant bit of <var>a_i</var> to <var>0</var>. (Here the least significant bit is considered the <var>1</var>-st least significant bit.)</li>
</ul>
</li>
<li>
<p>After Snuke finishes doing operations, Takahashi tries to sort <var>a</var> in ascending order by doing the operation below some number of times. Here <var>a</var> is said to be in ascending order when <var>a_i \leq a_{i + 1}</var> for all <var>i</var> <var>(1 \leq i \leq M - 1)</var>.</p>
<ul>
<li>Choose two adjacent elements of <var>a</var>: <var>a_i</var> and <var>a_{i + 1}</var>. If, in binary, these numbers differ in exactly one bit, swap <var>a_i</var> and <var>a_{i + 1}</var>.</li>
</ul>
</li>
</ul>
<p>There are <var>2^{NM}</var> different sequences of length <var>M</var> consisting of integers between <var>0</var> and <var>2^N-1</var> that can be used in the game.</p>
<p>How many among them have the following property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations? Find the count modulo <var>(10^9 + 7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>1 \leq N \leq 5000</var></li>
<li><var>2 \leq M \leq 5000</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number, modulo <var>(10^9 + 7)</var>, of sequences with the property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>352
</pre>
<p>Consider the case <var>a = 1, 3, 1, 3, 1</var> for example.</p>
<ul>
<li>When the least significant bit of each element of <var>a</var> is set to <var>0</var>, <var>a = 0, 2, 0, 2, 0</var>;</li>
<li>When the second least significant bit of each element of <var>a</var> is set to <var>0</var>, <var>a = 1, 1, 1, 1, 1</var>;</li>
<li>When the least two significant bits of each element of <var>a</var> are set to <var>0</var>, <var>a = 0, 0, 0, 0, 0</var>.</li>
</ul>
<p>In all of the cases above and the case when Snuke does no operation to change <var>a</var>, we can sort the sequence by repeatedly swapping adjacent elements that differ in exactly one bit.
Thus, this sequence has the property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2020 530
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>823277409
</pre></section>
</div>
</span> |
p00655 |
<H1>Problem I: FIMO sequence</H1>
<p>
Your task is to simulate the sequence defined in the remaining part of the problem description.
</p>
<p>
This sequence is empty at first.
<i> i </i>-th element of this sequence is expressed as <i> a<sub>i</sub> </i>.
The first element of this sequence is <i> a<sub>1</sub> </i> if the sequence is not empty.
The operation is given by integer from 0 to 9.
The operation is described below.
</p>
<p>
0:
This query is given with some integer <i>x</i>.
If this query is given, the integer x is inserted into the sequence.
If the sequence is empty, <i>a<sub>1</sub></i> = <i>x</i>.
If the sequence has <i>n</i> elements, <i>a<sub>n+1</sub></i> = <i>x</i>.
Same integer will not appear more than once as <i>x</i>.
</p>
<p>
1:
If this query is given, one element in the sequence is deleted.
The value in the middle of the sequence is deleted.
If the sequence has <i>n</i> elements and <i> n </i> is even, <i> a<sub>n/2</sub> </i> will be deleted.
If <i> n </i> is odd, <i> a<sub>⌈n/2⌉</sub> </i> will be deleted.
This query is not given when the sequence is empty.
Assume that the sequence has <i> a<sub>1</sub> </i>=1,<i> a<sub>2</sub> </i>=2,<i> a<sub>3</sub> </i>=3,<i> a<sub>4</sub> </i>=4 and <i> a<sub>5</sub> </i>=5.
In this case, <i> a<sub>3</sub> </i> will be deleted.
After deletion, the sequence will be <i> a<sub>1</sub> </i>=1, <i> a<sub>2</sub> </i>=2,<i> a<sub>3</sub> </i>=4,<i> a<sub>4</sub> </i>=5.
Assume that the sequence has <i> a<sub>1</sub> </i>=1,<i> a<sub>2</sub> </i>=2,<i> a<sub>3</sub> </i>=3 and <i> a<sub>4</sub> </i>=4,
In this case, <i> a<sub>2</sub> </i> will be deleted.
After deletion, the sequence will be <i> a<sub>1</sub> </i>=1,<i> a<sub>2</sub> </i>=3, <i> a<sub>3</sub> </i>=4.
</p>
<p>
2:
The first half of the sequence is defined by the index from 1 to ⌈<i>n</i>/2⌉ .
If this query is given, you should compute the minimum element of the first half of the sequence.
This query is not given when the sequence is empty.
</p>
<p>
Let me show an example.<br>
Assume that the sequence is {6,2,3,4,5,1,8}.
In this case, the minimum element of the first half of the sequence, {6,2,3,4} is 2.
</p>
<p>
3:
The latter half of the sequence is elements that do not belong to the first half of the sequence.
If this query is given, you should compute the minimum element of the latter half of the sequence.
This query is not given when the sequence is empty.
</p>
<p>
Let me show an example.<br>
Assume that the sequence is {6,2,3,4,5,1,8}.
In this case the answer for this query is 1 from {5,1,8}.
</p>
<p>
4:
This query is given with an integer <i>i</i>.
Assume that deletion is repeated until the sequence is empty.
Some elements in the first half of the sequence will become the answer for query 2.
You should compute the <i> i </i>-th minimum element from the answers.
This query is not given when the sequence is empty.
You can assume that <i> i </i>-th minimum element exists when this query is given.
</p>
<p>
Let me show an example.
</p>
<pre>
Assume that deletion will be repeated to the sequence {6,2,3,4,5,1,8}.
{6,2,3,4,5,1,8} The minimum element in the first half of the sequence is 2.
{6,2,3,5,1,8} The minimum element in the first half of the sequence is 2.
{6,2,5,1,8} The minimum element in the first half of the sequence is 2.
{6,2,1,8} The minimum element in the first half of the sequence is 2.
{6,1,8} The minimum element in the first half of the sequence is 1.
{6,8} The minimum element in the first half of the sequence is 6.
{8} The minimum element in the first half of the sequence is 8.
{} The first half of the sequence is empty.
</pre>
<p>
For the initial state, {6,2,3,4} is the first half of the sequence.
2 and 6 become the minimum element of the first half of the sequence.
In this example, the 1-st minimum element is 2 and the 2-nd is 6.
</p>
<p>
5:
This query is given with an integer <i> i </i>.
Assume that deletion is repeated until the sequence is empty.
Some elements in the latter half of the sequence will become the answer for query 3.
You should compute the <i> i </i>-th minimum element from the answers.
This query is not given when the sequence is empty.
You can assume that <i> i </i>-th minimum element exists when this query is given.
</p>
<p>
Let me show an example.
</p>
<pre>
Assume that deletion will be repeated to the sequence {6,2,3,4,5,1,8}.
{6,2,3,4,5,1,8} The minimum elemets in the latter half of the sequence is 1.
{6,2,3,5,1,8} The minimum elemets in the latter half of the sequence is 1.
{6,2,5,1,8} The minimum elemets in the latter half of the sequence is 1.
{6,2,1,8} The minimum elemets in the latter half of the sequence is 1.
{6,1,8} The minimum elemets in the latter half of the sequence is 8.
{6,8} The minimum elemets in the latter half of the sequence is 8.
{8} The latter half of the sequence is empty.
{} The latter half of the sequence is empty.
</pre>
<p>
For the initial state, {5,1,8} is the latter half of the sequence.
1 and 8 becomes the minimum element of the latter half ot the sequence.
In this example, the 1-st minimum element is 1 and the 2-nd is 8.
</p>
<p>
6:
If this query is given, you should compute the maximum element of the first half of the sequence.
This query is not given when the sequence is empty.
</p>
<p>
Let me show an example.<br>
Assume that the sequence is {1,3,2,5,9,6,7}.
In this case, the maximum element of the first half of the sequence,{1,3,2,5}, is 5.
</p>
<p>
7:
If this query is given, you should compute the maximum element of the latter half of the sequence.
This query is not given when the sequence is empty.
</p>
<p>
Let me show an example.<br>
Assume that the sequence is {1,3,2,5,9,6,7}.
In this case, the maximum element of the latter half of the sequence,{9,6,7}, is 9.
</p>
<p>
8:
This query is given with an integer <i> i </i>.
Assume that deletion is repeated until the sequence is empty.
Some elements in the first half of the sequence will become the answer for query 6.
You should compute the <i> i </i>-th maximum element from the answers.
This query is not given when the sequence is empty.
You can assume that <i> i </i>-th maximum elements exists when this query is given.
</p>
<p>Let me show an example.</p>
<pre>
Assume that deletion will be repeated to the sequence {1,3,2,5,9,6,7}.
{1,3,2,5,9,6,7} The maximum element in the first half of the sequence is 5.
{1,3,2,9,6,7} The maximum element in the first half of the sequence is 3.
{1,3,9,6,7} The maximum element in the first half of the sequence is 9.
{1,3,6,7} The maximum element in the first half of the sequence is 3.
{1,6,7} The maximum element in the first half of the sequence is 6.
{1,7} The maximum element in the first half of the sequence is 1.
{7} The maximum element in the first half of the sequence is 7.
{} The first half of the sequence is empty.
</pre>
<p>
For the initial state, {1,3,2,5} is the first half of the sequence.
1,3 and 5 becomes the maximum element of the first half of the sequence.
In this example, the 1-st maximum element is 5, the 2-nd is 3 and the 3-rd is 1.
</p>
<p>
9:
This query is given with an integer <i> i </i>.
Assume that deletion is repeated until the sequence is empty.
Some elements in the latter half of the sequence will become the answer for query 7.
You should compute the <i> i </i>-th maximum element from the answers.
This query is not given when the sequence is empty.
You can assume that <i> i </i>-th maximum elements exists when this query is given.
</p>
<p>Let me show an example.</p>
<pre>
Assume that deletion will be repeated to the sequence {1,3,2,5,9,6,7}.
{1,3,2,5,9,6,7} The maximum element in the latter half of the sequence is 9.
{1,3,2,9,6,7} The maximum element in the latter half of the sequence is 9.
{1,3,9,6,7} The maximum element in the latter half of the sequence is 7.
{1,3,6,7} The maximum element in the latter half of the sequence is 7.
{1,6,7} The maximum element in the latter half of the sequence is 7.
{1,7} The maximum element in the latter half of the sequence is 7.
{7} The latter half of the sequence is empty.
{} The latter half of the sequence is empty.
</pre>
<p>
For the initial state, {9,6,7} is the latter half of the sequence.
7 and 9 becomes the maximum element of the latter half of the sequence.
In this example, the 1-st maximum element is 9 and the 2-nd is 7.
</p>
<h2>Input</h2>
<p>
Input consists of multiple test cases.
The first line is the number of queries.
Following q lines are queries.
</p>
<pre>
<i>q</i>
<i>query<sub>0</sub></i>
...
<i>query<sub>i</sub></i>
...
<i>qurey_<sub>q-1</sub></i>
</pre>
<p>
The sum of the number of queries in the input data is less than 200001.
If <i>query<sub>i</sub></i> = 0, 4, 5, 8, and 9 are consists of pair of integers.
Other queries are given with a single integer.
You can assume that the length of the sequence doesn't exceed 20000.
</p>
<h2>Output</h2>
<p>
If the query is 0, you don't output any numbers.
If the query is 1, you should output the deleted number.
For other queries, you should output the computed value.
For each case, you should output "end" (without quates) after you process all queries.
</p>
<h2>Sample input</h2>
<pre>
5
0 1
0 2
0 3
0 4
1
6
0 1
0 2
0 3
0 4
0 5
1
31
0 6
0 2
0 3
0 4
0 5
0 1
0 8
4 1
4 2
5 1
5 2
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
1
32
0 1
0 3
0 2
0 5
0 9
0 6
0 7
8 1
8 2
8 3
9 1
9 2
6
7
1
6
7
1
6
7
1
6
7
1
6
7
1
6
7
1
6
1
0
</pre>
<h2>Sample output</h2>
<pre>
2
end
3
end
2
6
1
8
2
1
4
2
1
3
2
1
5
2
1
2
1
8
1
6
8
6
8
8
end
5
3
1
9
7
5
9
5
3
9
2
9
7
9
3
7
3
6
7
6
1
7
1
7
7
end
</pre>
|
p02238 |
<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>Depth First Search</H1>
<p>
Depth-first search (DFS) follows the strategy to search âdeeperâ in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search âbacktracksâ to explore edges leaving the vertex from which $v$ was discovered.
</p>
<p>
This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source.
</p>
<p>
DFS timestamps each vertex as follows:
</p>
<ul>
<li>$d[v]$ records when $v$ is first discovered.</li>
<li>$f[v]$ records when the search finishes examining $v$âs adjacency list.</li>
</ul>
<p>
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules:
</p>
<ul>
<li>$G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.</li>
<li>IDs in the adjacency list are arranged in ascending order.</li>
<li>The program should report the discover time and the finish time for each vertex.</li>
<li>When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.</li>
<li>The timestamp starts with 1.</li>
</ul>
<H2>Input</H2>
<p>
In the first line, an integer $n$ denoting the number of vertices of $G$ is given. In the next $n$ lines, adjacency lists of $u$ are given in the following format:
</p>
<p>
$u$ $k$ $v_1$ $v_2$ ... $v_k$
</p>
<p>
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices adjacent to $u$.
</p>
<H2>Output</H2>
<p>
For each vertex, print $id$, $d$ and $f$ separated by a space character in a line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the finish time respectively. Print in order of vertex IDs.
</p>
<H2>Constraints</H2>
<ul>
<li>$1 \leq n \leq 100$</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
4
1 1 2
2 1 4
3 0
4 1 3
</pre>
<H2>Sample Output 1</H2>
<pre>
1 1 8
2 2 7
3 4 5
4 3 6
</pre>
<H2>Sample Input 2</H2>
<pre>
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0
</pre>
<H2>Sample Output 2</H2>
<pre>
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6
</pre>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_11_B_2">
<p>
This is example for Sample Input 2 (discover/finish)
</p>
</center>
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p>
|
p00205 |
<H1>ããããã</H1>
<p>
仲è¯ã 5 人çµã§ããããããããããšã«ãªããŸãããããããããšã¯ãã°ãŒããã§ããããŒãšãã 3ã€ã®æããããã°ãŒãšãã§ãã®åè² ãªãã°ãŒããåã¡ãã»ãã§ãããè² ããããã§ããšããŒãªãããã§ãããåã¡ãã»ããŒããè² ãããããŒãšã°ãŒãªãããŒããåã¡ãã»ã°ãŒããè² ãããšããã«ãŒã«ã§ããå
šå¡ãåãæããŸãã¯ã°ãŒããã§ããããŒå
šãŠãåºãå Žåã¯ããããããšãªããŸãã
</p>
<p>
5 人ã®ãããããã®æãå
¥åãšããããããã®äººã®åæãåºåããããã°ã©ã ãäœæããŠãã ããããããããã®æã¯ãã°ãŒã¯ 1ããã§ã㯠2ãããŒã¯ 3 ã®æ°åã§è¡šããŸããåæã¯ãåã¡ãã 1ããè² ããã 2ããããããã 3 ã®æ°åã§è¡šããå
¥åé ã«åŸã£ãŠåºåããŸãã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã
åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>h<sub>1</sub></var>
<var>h<sub>2</sub></var>
<var>h<sub>3</sub></var>
<var>h<sub>4</sub></var>
<var>h<sub>5</sub></var>
</pre>
<p>
<var>i</var> è¡ç®ã« <var>i</var> 人ç®ã®æ <var>h<sub>i</sub></var> (1, 2 ãŸã㯠3) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 200 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ã5 人ã®åæãåºåããŸãã<var>i</var> è¡ç®ã« <var>i</var> 人ç®ã®åæ(1, 2 ãŸã㯠3) ãåºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
1
2
3
2
1
1
2
2
2
1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
3
3
3
3
1
2
2
2
1
</pre>
|
p03700 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are going out for a walk, when you suddenly encounter <var>N</var> monsters. Each monster has a parameter called <em>health</em>, and the health of the <var>i</var>-th monster is <var>h_i</var> at the moment of encounter. A monster will vanish immediately when its health drops to <var>0</var> or below.</p>
<p>Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:</p>
<ul>
<li>Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by <var>A</var>, and the health of each of the other monsters will decrease by <var>B</var>. Here, <var>A</var> and <var>B</var> are predetermined parameters, and <var>A > B</var> holds.</li>
</ul>
<p>At least how many explosions do you need to cause in order to vanish all the monsters?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>1 †N †10^5</var></li>
<li><var>1 †B < A †10^9</var></li>
<li><var>1 †h_i †10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>A</var> <var>B</var>
<var>h_1</var>
<var>h_2</var>
<var>:</var>
<var>h_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 5 3
8
7
4
2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>You can vanish all the monsters in two explosion, as follows:</p>
<ul>
<li>First, cause an explosion centered at the monster with <var>8</var> health. The healths of the four monsters become <var>3</var>, <var>4</var>, <var>1</var> and <var>-1</var>, respectively, and the last monster vanishes.</li>
<li>Second, cause an explosion centered at the monster with <var>4</var> health remaining. The healths of the three remaining monsters become <var>0</var>, <var>-1</var> and <var>-2</var>, respectively, and all the monsters are now vanished.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 10 4
20
20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
<p>You need to cause two explosions centered at each monster, for a total of four.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5 2 1
900000000
900000000
1000000000
1000000000
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>800000000
</pre></section>
</div>
</span> |
p02812 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a string <var>S</var> of length <var>N</var> consisting of uppercase English letters.</p>
<p>How many times does <code>ABC</code> occur in <var>S</var> as contiguous subsequences (see Sample Inputs and Outputs)?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 50</var></li>
<li><var>S</var> consists of uppercase English letters.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print number of occurrences of <code>ABC</code> in <var>S</var> as contiguous subsequences.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10
ZABCDBABCQ
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>Two contiguous subsequences of <var>S</var> are equal to <code>ABC</code>: the <var>2</var>-nd through <var>4</var>-th characters, and the <var>7</var>-th through <var>9</var>-th characters.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>19
THREEONEFOURONEFIVE
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>No contiguous subsequences of <var>S</var> are equal to <code>ABC</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>33
ABCCABCBABCCABACBCBBABCBCBCBCABCB
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p01697 |
<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>1 Day Passport</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>æåœã«äœã倧åŠçDæ°ã¯ïŒåœæ°çã®ã¿ãªã¹ãAæ°ã®å€§ãã¡ã³ã§ïŒãã®å€éœå¿ã§è¡ãããã©ã€ãã«è¡ãããšèããŠããïŒ
ãããïŒDæ°ã¯èŸºå¢ã®å°ã«äœãã§ããããïŒäº€éè²»ããããããšããšãŠãäžå®ã ã£ãïŒ
ãããªãšã圌ã¯ïŒJAGãšããçµç¹ããå®äŸ¡ã§è²©å£²ãããŠããã1Dayãã¹ããŒããã®ååšãç¥ã£ãïŒ
</p>
<p>JAG (Journey Administrative Group) ã¯ïŒDæ°ãäœãåœã«ååšããããã€ãã®ééäŒç€Ÿãçµ±æ¬ããçµç¹ã§ããïŒ
JAGã¯ïŒå
šåœã«è€æ°ã®é§
ãæã¡ïŒãããã®éãçµã¶è·¯ç·ãæŽåããŠããïŒ
åè·¯ç·ã¯ïŒJAGã«æå±ããäŒç€Ÿã®å
ãããã1瀟ã«ãã管çãããŠããïŒ2é§
éãéäžé§
ç¡ãã§åæ¹åã«çµãã§ããïŒ
ãŸãåè·¯ç·ã«ã¯ïŒå©çšããéã®éè³ãšæèŠæéãå®ãŸã£ãŠãã (ãããã¯ã©ã¡ãåãã«ç§»åããå Žåã§ãçãã)ïŒ
JAGã®ãã€ã€ã¯ã·ã³ãã«ã«äœãããŠããïŒåè»ã¯æ¯æ0åã«é§
ã«çºçããïŒ
ãŸãJAGã®åé§
ã¯ïŒæ¥µããŠè³¢ããã¶ã€ã³ãããŠããïŒè·¯ç·ã®ä¹ãæãã«ãããæéã¯ç¡èŠããããšãã§ããïŒ
ç§»åã«å¿
èŠãªäº€éè²»ã¯éè³ã®åçŽãªåèšãšãªã.
</p>
<p>1Dayãã¹ããŒãã¯ïŒJAGãæšä»ã®çµå¶é£ãè±ããããã«è²©å£²ãå§ããïŒä¹ãæŸé¡ãã¹ããŒãã§ããïŒ
JAGã¯ïŒäœçš®é¡ãã®1Dayãã¹ããŒãã販売ããŠããïŒ
åãã¹ããŒãã¯ïŒJAGãæå®ããè²©å£²äŸ¡æ Œã§è³Œå
¥ããããšãã§ããïŒ
ãŸããã¹ããŒãã«ã¯ïŒJAGã«æå±ããäŒç€Ÿåãããã€ãæžãããŠããïŒãããã®äŒç€Ÿã管çããå
šãŠã®è·¯ç·ã1æ¥é (è¿œå æéç¡ãã§) ä¹ãæŸé¡ã«ãªãïŒ
ãã¹ããŒãã¯ïŒããã€ã§ã賌å
¥ããããšãã§ãïŒè€æ°ã®ãã¹ããŒãã䜵çšããããšãã§ããïŒ
ãã ãïŒãã¹ããŒãã«æžãããŠããªãäŒç€Ÿã®ç®¡çè·¯ç·ãéãå ŽåïŒãã®è·¯ç·ã®éè³ã¯éåžžéãå¿
èŠãšãªãïŒ
</p>
<p>Dæ°ã¯ïŒ1Dayãã¹ããŒããããŸã䜿ãïŒãªãã¹ããéããããã©ã€ãäŒå ŽãŸã§è¡ããããšèããŠããïŒ
ãŸãïŒåœŒã¯å®¿æ³ã§äœèšã«ãéããããã®ãå«ãªã®ã§ïŒãã®åœã®1æ¥ã§ãã$H$æé以äžã§ã©ã€ãäŒå ŽãŸã§èŸ¿ãçããããšèããŠããïŒ
ãããïŒåœŒã¯èšç®ãåŸæã§ã¯ãªãããïŒåã倧åŠã®å人ã§ããã°ã©ãã³ã°ãåŸæãªããªãã«å©ããæ±ããŠæ¥ãïŒ
å°ã£ãŠããDæ°ã®ããã«ïŒæ¬¡ã®ãããªããã°ã©ã ãæžããŠããããïŒ
</p>
<p>JAGã®è·¯ç·æ
å ±ãš1Dayãã¹ããŒãã®æ
å ±ãäžãããããšãïŒDæ°ã®æå¯ãé§
ããã©ã€ãäŒå Žã®æå¯ãé§
ãžïŒ$H$æé以äžã§ç§»åããããã®æå°è²»çš (ãã¹ããŒã代ãšéè³ã®åèšã®æå°) ãæ±ããããã°ã©ã ãäœæããïŒ
$H$æé以äžã§å°éã§ããªãå ŽåãïŒã©ã€ãäŒå Žãžå°éããçµè·¯ããªãå Žåã¯ïŒ-1ãåºåããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ããããæ§æããïŒ1ã€ã®å
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯150以äžã§ããïŒ
åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ
</p>
<blockquote>$N$ $M$ $H$ $K$<br>$a_1$ $b_1$ $c_1$ $h_1$ $r_1$<br>...<br>$a_M$ $b_M$ $c_M$ $h_M$ $r_M$<br>$S$ $T$<br>$P$<br>$l_1$ $d_1$ $k_{1,1}$ ... $k_{1,l_1}$<br>...<br>$l_P$ $d_P$ $k_{P,1}$ ... $k_{P,l_P}$</blockquote>
<p>å
¥åã¯å
šãп޿°å€ã§äžããããïŒ
</p>
<p>ãŸãïŒJAGã®è·¯ç·æ
å ±ãäžããããïŒ
$N$ ($2 \le N \le 100$) ã¯é§
ã®æ°ïŒ$M$ ($1 \le M \le 500$) ã¯è·¯ç·ã®æ°ïŒ$H$ ($1 \le H \le 24$) ã¯1æ¥ã®æéïŒ$K$ ($1 \le K \le 8$) ã¯JAGã«æå±ããäŒç€Ÿæ°ã衚ãïŒ
åé§
ã«ã¯ïŒ$1, 2, \ldots, N$ ãšçªå·ãã€ããŠããïŒ
ãŸãïŒåäŒç€Ÿã«ã¯ïŒ$1, 2, \ldots, K$ ãšçªå·ãã€ããŠããïŒ
ç¶ã㊠$M$ è¡ã«ããã£ãŠè·¯ç·æ
å ±ãå
¥åãããïŒ
$a_i$ ãš $b_i$ ($1 \le a_i \lt b_i \le N$) ã $i$ çªç®ã®è·¯ç·ãã€ãªãã§ãã2ã€ã®é§
ã衚ãïŒ
$c_i$ ($1 \le c_i \le 10{,}000$) 㯠$i$ çªç®ã®è·¯ç·ã®éè³ïŒ$h_i$ ($1 \le h_i \le H$) ã¯è·¯ç·ã®æèŠæéïŒ$r_i$ ($1 \le r_i \le K$) ã¯è·¯ç·ã管çããŠããäŒç€Ÿã衚ãïŒ
ãã2ã€ã®é§
ãçµã¶è·¯ç·ã2æ¬ä»¥äžååšããããšã¯ãªãïŒ
</p>
<p>次ã®è¡ã§ïŒDæ°ã®æå¯ãé§
$S$ ãšïŒAæ°ã®ã©ã€ãäŒå Žã®æå¯ãé§
$T$ ãäžãããã ($1 \le S, T \le N$)ïŒ
$S$ ãš $T$ ã¯ç°ãªãå€ã§ããïŒ
</p>
<p>次ã«ïŒ1Dayãã¹ããŒãã®æ
å ±ãäžããããïŒ
$P$ ($0 \le P \le 2^K - 1$) ã¯ïŒ1Dayãã¹ããŒãã®çš®é¡æ°ã衚ããŠããïŒ
ç¶ã㊠$P$ è¡ã«ããã£ãŠïŒ1Dayãã¹ããŒãã®æ
å ±ãå
¥åãããïŒ
$l_j$ ($1 \le l_j \le K$) ãš $d_j$ ($1 \le d_j \le 10{,}000$) ã¯ïŒãããã $j$ çªç®ã®1Dayãã¹ããŒãã«æžãããŠããäŒç€Ÿæ°ãšãã¹ããŒãã®æéã衚ãïŒ
åãè¡ã«ïŒ$j$ çªç®ã®ãã¹ããŒãã«æžããã $l_j$ åã®äŒç€Ÿçªå· $k_{j, 1}, k_{j, 2}, \ldots, k_{j, l_j}$ ($1 \le k_{j, 1} \lt k_{j, 2} \lt \cdots \lt k_{j, l_j} \le K$) ãäžããããïŒ
åãäŒç€Ÿã®çµã¿åãããããªã1Dayãã¹ããŒããè€æ°å
¥åãããããšã¯ãªãïŒ
</p>
<p>å
¥åã®çµããã¯ïŒ$N=M=H=K=0$ ã®è¡ã«ãã£ãŠè¡šãããïŒ
ãã®ããŒã¿ã¯åŠçãè¡ã£ãŠã¯ãªããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>åããŒã¿ã»ããã«å¯ŸããŠïŒèšç®çµæã1è¡ã§åºåããïŒ
ããªãã¡ïŒDæ°ã®æå¯ãé§
ããã©ã€ãäŒå Žã®æå¯ãé§
ãžã®çµè·¯ãååšã $H$ æé以å
ã«å°éã§ããã®ã§ããã°ïŒãã®ããã®æå°ã®æéãïŒèŸ¿ãçããªãã®ã§ããã°-1ãåºåããïŒ
</p>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>3 3 3 2
1 2 3 1 1
1 3 8 1 1
2 3 3 2 2
1 3
0
3 3 2 2
1 2 3 1 1
1 3 8 1 1
2 3 3 2 2
1 3
0
6 4 3 2
1 2 3 1 1
1 3 8 1 1
4 6 3 2 2
5 6 7 2 2
1 6
0
3 3 3 2
1 2 3 1 1
1 3 8 1 1
2 3 3 2 2
1 3
2
2 6 1 2
1 2 2
3 3 2 2
1 2 3 1 1
1 3 8 1 1
2 3 3 2 2
1 3
2
2 6 1 2
1 2 2
3 2 2 2
1 2 3 1 1
2 3 3 2 2
1 3
2
2 6 1 2
1 2 2
5 4 20 4
2 4 100 5 1
1 4 100 5 3
1 5 100 5 4
3 5 100 5 2
3 2
3
2 80 1 2
2 60 1 3
2 40 2 3
0 0 0 0</pre>
<h3>Output for Sample Input</h3>
<pre>6
8
-1
5
6
-1
200</pre>
|
p00985 | <h2>Ambiguous Encoding</h2>
<p>
A friend of yours is designing an encoding scheme of a set of characters into a set of variable length bit sequences. You are asked to check whether the encoding is ambiguous or not. In an encoding scheme, characters are given distinct bit sequences of possibly different lengths as their codes. A character sequence is encoded into a bit sequence which is the concatenation of the codes of the characters in the string in the order of their appearances. An encoding scheme is said to be ambiguous if there exist two different character sequences encoded into exactly the same bit sequence. Such a bit sequence is called an âambiguous binary sequenceâ.
</p>
<p>
For example, encoding characters â<span>A</span>â, â<span>B</span>â, and â<span>C</span>â to <span>0</span>, <span>01</span> and <span>10</span>, respectively, is ambiguous. This scheme encodes two different character strings â<span>AC</span>â and â<span>BA</span>â into the same bit sequence <span>010</span>.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case of the following format.
</p>
<pre>
$n$
$w_1$
.
.
.
$w_n$
</pre>
<p>
Here, $n$ is the size of the set of characters to encode ($1 \leq n \leq 1000$). The $i$-th line of the following $n$ lines, $w_i$, gives the bit sequence for the $i$-th character as a non-empty sequence of at most 16 binary digits, 0 or 1. Note that different characters are given different codes, that is, $w_i \ne w_j$ for $i \ne j$.
</p>
<h3>Output</h3>
<p>
If the given encoding is ambiguous, print in a line the number of bits in the shortest ambiguous binary sequence. Output zero, otherwise.
</p>
<h3>Sample Input 1 </h3>
<pre>
3
0
01
10
</pre>
<h3>Sample Output 1</h3>
<pre>
3
</pre>
<h3>Sample Input 2 </h3>
<pre>
3
00
01
1
</pre>
<h3>Sample Output 2</h3>
<pre>
0
</pre>
<h3>Sample Input 3 </h3>
<pre>
3
00
10
1
</pre>
<h3>Sample Output 3</h3>
<pre>
0
</pre>
<h3>Sample Input 4</h3>
<pre>
10
1001
1011
01000
00011
01011
1010
00100
10011
11110
0110
</pre>
<h3>Sample Output 4</h3>
<pre>
13
</pre>
<h3>Sample Input 5 </h3>
<pre>
3
1101
1
10
</pre>
<h3>Sample Output 5</h3>
<pre>
4
</pre>
|
p03350 | <span class="lang-en">
<p>Score : <var>2300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a set <var>S</var> of strings consisting of <code>0</code> and <code>1</code>, and an integer <var>K</var>.</p>
<p>Find the longest string that is a subsequence of <var>K</var> or more different strings in <var>S</var>.
If there are multiple strings that satisfy this condition, find the lexicographically smallest such string.</p>
<p>Here, <var>S</var> is given in the format below:</p>
<ul>
<li>The data directly given to you is an integer <var>N</var>, and <var>N+1</var> strings <var>X_0,X_1,...,X_N</var>. For every <var>i</var> <var>(0\leq i\leq N)</var>, the length of <var>X_i</var> is <var>2^i</var>.</li>
<li>For every pair of two integers <var>(i,j)</var> <var>(0\leq i\leq N,0\leq j\leq 2^i-1)</var>, the <var>j</var>-th character of <var>X_i</var> is <code>1</code> if and only if the binary representation of <var>j</var> with <var>i</var> digits (possibly with leading zeros) belongs to <var>S</var>. Here, the first and last characters in <var>X_i</var> are called the <var>0</var>-th and <var>(2^i-1)</var>-th characters, respectively.</li>
<li><var>S</var> does not contain a string with length <var>N+1</var> or more.</li>
</ul>
<p>Here, a string <var>A</var> is a subsequence of another string <var>B</var> when there exists a sequence of integers <var>t_1 < ... < t_{|A|}</var> such that, for every <var>i</var> <var>(1\leq i\leq |A|)</var>, the <var>i</var>-th character of <var>A</var> and the <var>t_i</var>-th character of <var>B</var> is equal.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq N \leq 20</var></li>
<li><var>X_i(0\leq i\leq N)</var> is a string of length <var>2^i</var> consisting of <code>0</code> and <code>1</code>.</li>
<li><var>1 \leq K \leq |S|</var></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>N</var> <var>K</var>
<var>X_0</var>
<var>:</var>
<var>X_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the lexicographically smallest string among the longest strings that are subsequences of <var>K</var> or more different strings in <var>S</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 4
1
01
1011
01001110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p>The following strings belong to <var>S</var>: the empty string, <code>1</code>, <code>00</code>, <code>10</code>, <code>11</code>, <code>001</code>, <code>100</code>, <code>101</code> and <code>110</code>.
The lexicographically smallest string among the longest strings that are subsequences of four or more of them is <code>10</code>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 6
1
01
1011
10111010
1101110011111101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2 5
0
11
1111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>
</pre>
<p>The answer is the empty string.</p></section>
</div>
</span> |
p02111 |
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem A: Clock</h1>
<h2>Problem</h2>
<p>
ãã£ã¡ãåã¯ãæ°ã«å
¥ãã®æèšãæã£ãŠãããããæ¥æèšã®é·éãåããŠããŸããã©ãããžãªãããŠããŸã£ãããããããã£ã¡ãåã¯ãã®æèšã䜿ãç¶ãããããçéã ãã§æå»ãèªã¿åããããšèããŠããã
</p>
<p>
çéã®æ
å ±<var>θ</var>ã«å¯Ÿããæå»(æ<var>h</var>ãå<var>m</var>)ãåºåãããæèšã¯ããããã¢ããã°æèšã§ã1ãã12ã®æ°ãçééã«æèšåãã«æé ã«äžŠãã§ãããã®ã§ããã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
<var>θ</var>
</pre>
<p>
1è¡ã«çéã®è§åºŠ <var>θ</var>ãè¡šãæŽæ°ãåºŠæ°æ³(degree)ã§äžããããã
çéãæãæ¹åã¯ã12æãæãæ¹åã0床ãšãããšããæèšåãã«<var>θ</var>床å転ããæ¹åã§ããã
</p>
<h2>Constraints</h2>
<ul>
<li>0 ≤ <var>θ</var> ≤ 359</li>
</ul>
<h2>Output</h2>
<p>
çéãäžããããè§åºŠããšãæã®æå»ã<br>
<var>h</var> <var>m</var><br>
ã®åœ¢ã§1è¡ã«åºåããã<br>
<br>
æå»ã«ååååŸã®åºå¥ã¯ãªããã0 ≤ <var>h</var> ≤ 11ãšããã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
0
</pre>
<h2>Sample Output 1</h2>
<pre>
0 0
</pre>
<h2>Sample Input 2</h2>
<pre>
45
</pre>
<h2>Sample Output 2</h2>
<pre>
1 30
</pre>
<h2>Sample Input 3</h2>
<pre>
100
</pre>
<h2>Sample Output 3</h2>
<pre>
3 20
</pre> |
p00086 |
<H1>ããããŒã«</H1>
<p>
æä¹
ïŒïŒ1862ïŒå¹ŽãäŒæŽ¥ã®æ®¿æ§ã京éœå®è·è·ãåœããããŸããã京éœå®è·è·ãšã¯æ²»å®ã®æªåãã广«ã®äº¬éœãå®ã倧åãªåœ¹ç®ã§ããå¹åºãä»ã®è©ãšåæ
ããŠåžäžãããããŒã«ããªããã°ãªããŸããããšãããããåæ
ã«ãŒããæ±ºããæ®µã«ãªã£ãŠãå®¶è£ã®äžã§ãæåãªé åºè
ã®å€èãã以äžã®ãããªæ³šæãã€ããŸããã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_14_1">
</center>
<br/>
<p>
倧å€ãªããšã«ãªããŸãããæ®¿æ§ãšããã©ããã®å®¶è£ã®èšãåãç¡èŠããããã«ã¯ãããŸãããåæ
ã«ãŒãã®éžæã«ãã£ãŠã¯ããæŠå£«ã®é¢ç®ãç«ããªãããšããããšã«ãªã£ãŠããŸããŸãã
</p>
<p>
ãšããããšã§ãã¹ã¿ãŒãå°ç¹ããŽãŒã«å°ç¹ã亀差ç¹ã®æ
å ±ãå
¥åãšããŠãäžã®äžã€ã®æ¡ä»¶ãæºãããã©ãããå€å®ããããã°ã©ã ãäœã£ãŠã殿æ§ã«ç®äžããŠãã ããã
</p>
<p>
ã¹ã¿ãŒãå°ç¹ã 1ããŽãŒã«å°ç¹ã2ããã®ä»ã®äº€å·®ç¹ã 3 以äžã®æŽæ°ã§è¡šããŸãã1ã€ã®éè·¯ã¯ããã®éãçµã¶1çµã®äº€å·®ç¹çªå·ã§è¡šããŸãããªãã亀差ç¹ã®æ°ã¯ 100 以äžãšããå
šãŠã®äº€å·®ç¹ããã¹ã¿ãŒãå°ç¹ããã³ãŽãŒã«å°ç¹ãžã®çµè·¯ãããããäžã€ä»¥äžãããã®ãšããŸãã
</p>
<H2>å
¥å</H2>
<p>è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã</p>
<pre>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
ïŒ
ïŒ
<var>0</var> <var>0</var>
</pre>
<p>
åè¡ã®ïŒã€ã®æŽæ°ã¯ãäº€å·®ç¹ <var>a<sub>i</sub></var> ãšäº€å·®ç¹ <var>b<sub>i</sub></var> ãšãã€ãªãéè·¯ãååšããããšã瀺ããŸãã
<var>a<sub>i</sub></var> ãš <var>b<sub>i</sub></var> ããšãã« 0 ã®ãšãäº€å·®ç¹æ
å ±ã®å
¥åã®çµããã瀺ããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯50ãè¶
ããŸããã
</p>
<H2>åºå</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããŠãæŠå£«ã®é¢ç®ãç«ã€å ŽåïŒäžã€ã®æ¡ä»¶ãæºããå ŽåïŒOKããã以å€ã®å ŽåïŒäžã€ã®æ¡ä»¶ãæºãããªãå ŽåïŒNG ãšïŒè¡ã«åºåããŠãã ããã
</p>
<H2>Sample Input</H2>
<pre>
1 3
3 4
3 5
3 6
4 6
4 7
4 7
5 6
6 7
5 8
5 8
6 8
6 9
7 9
8 9
9 2
0 0
1 3
3 4
3 4
4 2
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
OK
NG
</pre>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_14_2">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_14_3">
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_14_4">
|
p02541 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given is an integer <var>N</var>.
Find the minimum possible positive integer <var>k</var> such that <var>(1+2+\cdots+k)</var> is a multiple of <var>N</var>.
It can be proved that such a positive integer <var>k</var> always exists.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^{15}</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>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer in a line.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>10
</pre>
<p><var>1+2+\cdots+10=55</var> holds and <var>55</var> is indeed a multple of <var>N=11</var>.
There are no positive integers <var>k \leq 9</var> that satisfy the condition, so the answer is <var>k = 10</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>20200920
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1100144
</pre></section>
</div>
</span> |
p00069 |
<H1>ãã¿ã ãã II</H1>
<p>
瞊ç·ã <var>n</var> æ¬ã®ãã¿ã ããããããŸãããã®ãã¿ã ããã¯ä»¥äžã®æ¡ä»¶ãæºãããŠããŸãã
</p>
<ul>
<li>暪ç·ã¯ç暪ã«åŒããŸããæãã«åŒãããšã¯ãããŸããã</li>
<li>暪ç·ã¯å¿
ãé£ãåã£ã瞊ç·å士ãã€ãªããŸããã€ãŸããæšªç·ã瞊ç·ããŸããããšã¯ãããŸããã</li>
<li>ã©ã®çžŠç·ã«ã€ããŠãåãç¹ããå·Šå³åæã«æšªç·ãåºãããšã¯ãããŸãããã€ãŸããæšªç·ã瞊ç·ã暪åãããšã¯ãããŸããã</li>
<li>åœãã¯ã²ãšã€ã ãã§ãã</li>
</ul>
<p>
äžå³ ã« <var>n</var> = 5 ã®ãšãã®ããã¿ã ããã®äŸã瀺ããŸããäžåŽã®æ°åã¯çžŠç·ã®çªå·(å·Šãã1, 2, 3, 4, 5 ) ã衚ããŸããâãåœããã§ãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lotsII">
</center>
<br/>
<p>
瞊ç·ã®æ¬æ° <var>n</var>ãéžãã 瞊ç·ã®çªå· <var>m</var>ããã¿ã ããã®åœãã®å Žæãåæ®µã«ãããæšªç·ã®æç¡ãèªã¿èŸŒãã§ãåœãã«ãã©ãçãããã©ããã®å€å®ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããäžãããããã¿ã ããã®ä»»æã®äœçœ®ã«1 æ¬ã ãæšªç·ãä»ãå ããããšãã§ãããã®ãšããŸãïŒä»ãå ããªããŠãããŸããŸããïŒã暪ç·ã1 æ¬ä»ãå ããåŸã®ãã¿ã ãããåè¿°ã®æ¡ä»¶ãæºãããŠããªããã°ãªããŸããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãšããã§ãïŒ
</p>
<p>
ïŒè¡ç®ã«ã瞊ç·ã®æ¬æ° <var>n</var> (1 < <var>n</var> ≤ 10) ãæžãããŠããŸãã<br/>
ïŒè¡ç®ã«ã¯ãéžãã 瞊ç·ã®çªå· <var>m</var> (1 ≤ <var>m</var> ≤ <var>n</var>) ãæžãããŠããŸãã<br/>
ïŒè¡ç®ã«ã¯ãåœãã®å ŽæïŒå³ã§ããâïŒãå·Šããæ°ããŠäœçªç®ããæžãããŠããŸãã<br/>
ïŒè¡ç®ã«ã¯ããã¿ã ããã®æ®µæ° <var>d</var> (1 ≤ <var>d</var> ≤ 30) ãæžãããŠããŸãã<br/>
ïŒè¡ç®ä»¥éã¯ãå³ã«å¯Ÿå¿ããæ°åã®äžŠã³ã®ããã«ããã¿ã ããã®äžããé ã«ãå瞊ç·ã®éã«æšªç·ããããšãã 1ããªããšãã 0 ãšããŠã<var>n</var> - 1 ã€ã®æ°åã䞊ãã§ããŸãã<br/>
<!--ãã¿ã ããã®æ®µæ°ã¯ d ã§ãã<br/>-->
</p>
<p>
å
¥åã¯ïŒã€ã® 0 ãæžãããè¡ã§çµãããŸãã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«ã€ããŠãéžãã 瞊ç·ã®çªå· <var>m</var> ããåœãã«ãã©ãçãããã©ããã«å¿ããŠä»¥äžã®å€ãåºåããŠãã ããã
</p>
<ul>
<li>暪ç·ãåŒããªããŠãåœãã«ãã©ãçãããšã㯠0 ãåºåããŠãã ããã</li>
<li>暪ç·ã1 æ¬åŒãã°åœãã«ãã©ãçãããšãã¯ããã®äžã§æãåºçºåŽïŒå³ã§ã¿ãŠäžïŒã«è¿ã暪ç·ã®äœçœ®ãåºåããŠãã ãããåºçºåŽããæ°ããŠäœæ®µç®ïŒå³ ãåèã«ããŠãã ããïŒã«ãå·Šããæ°ããŠäœçªç®ã®çžŠç·ããå³ã«åãã£ãŠæšªç·ãåŒãããåè§ã®ç©ºçœã§åºåã£ãŠåºåããŠãã ããã</li>
<li>暪ç·ã1 æ¬åŒããŠãåœãã«ãã©ãçããªããšãã«ã¯ 1 ãåºåããŠãã ããã</li>
</ul>
<H2>Sample Input</H2>
<pre>
5
2
3
9
1010
1001
0100
1001
0010
1000
0100
0101
1010
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6 4
</pre>
|
p02054 | <h2>C: äž²åºã (Skewering)</h2>
<h3>åé¡</h3>
<p>
ããæ¥ãã»ããã¡ãããç©ã¿æšã§éãã§ãããšãŠãã·ãåããã£ãŠããŸããã
ã»ããã¡ããã¯ããŠãã·ãåãšäžç·ã«ç©ã¿æšã§éã¶ããšã«ããŸããã
</p>
<p>äžèŸºã®é·ãã <var>1</var> ã®ç«æ¹äœã®ç©ã¿æšã®ãããã¯ã <var>A \times B \times C</var> åééãªãç©ã¿éããŠã§ããã<var>A \times B \times C</var> ã®çŽæ¹äœããããŸããå
šãŠã®ç«æ¹äœãšçŽæ¹äœã®å蟺㯠<var>x</var> 軞ã<var>y</var> 軞ã<var>z</var> 軞ã®ãããããšå¹³è¡ã§ãã</p>
<p>ã»ããã¡ãããšãŠãã·ãåã¯äº€äºã«ä»¥äžã®æäœãç¹°ãè¿ããŸãã</p>
<ul>
<li>çŽæ¹äœãã瞊æ¹åãæšªæ¹åã奥è¡ãæ¹åã®ããããã®æ¹åã«äžåã«äžŠãã ç©ã¿æšã®ãããã¯ã®åãéžãã§ãåã«å«ãŸãããããã¯å
šãŠãèµ€ãå¡ãããã ãããã§ã«èµ€ãå¡ãããŠãããããã¯ãå«ãåã¯éžã¶ããšãã§ããªãã</li>
</ul>
<p>ããæ£ç¢ºã«ã¯ã</p>
<ul>
<li>çŽæ¹äœã«å«ãŸãããããã¯ã®ãã¡äžã€ãšã<var>x,y,z</var> ã®äžã€ã®æ¹åããäžã€ãéžã¶ã</li>
<li>éžãã ãããã¯ãéžãã æ¹åã«æŽæ°ã®è·é¢ã ãåããããšããå®å
šã«éãªããããªãããã¯å
šãŠãèµ€ãå¡ãïŒ <var>0 </var> ãè² ã®æŽæ°ã®è·é¢ãåããããšãèããïŒããã ããæ¡ä»¶ãæºãããããã¯ã§ãã£ãŠãã§ã«å¡ããããã®ãã²ãšã€ã§ãååšããå Žåããã®æäœã¯è¡ãããšãã§ããªãã</li>
</ul>
<p>ã»ããã¡ãããå
æã§ãå
ã«æäœãè¡ããªããªã£ãæ¹ã®è² ãã§ãã</p>
<p>ãŸããæåå
šãŠã®ç«æ¹äœã«è²ã¯å¡ãããŠããŸããã</p>
<p>äºäººãæé©ã«è¡åãããšããã©ã¡ããåã€ãå€å®ããŠãã ããã</p>
<h3>å
¥å圢åŒ</h3>
<pre><var>A</var> <var>B</var> <var>C</var></pre>
<h3>å¶çŽ</h3>
<ul>
<li> <var>1 \leq A, B, C \leq 100</var></li>
<li> å
¥åã¯ãã¹ãп޿°ã§ããã</li>
</ul>
<h3>åºå圢åŒ</h3>
<p>äºäººãæé©ã«è¡åãããšããã»ããã¡ãããåã€ãªãã° <code>Hom</code> ãããŠãã·ãåãåã€ãªãã° <code>Tem</code> ãäžè¡ã«åºåããã</p>
<h3>å
¥åäŸ 1</h3>
<pre>1 1 10</pre>
<h3>åºåäŸ 1</h3>
<pre>Hom</pre>
<ul>
<li> äžåç®ã§ã»ããã¡ããã¯å
šãŠã®ãããã¯ãèµ€ãå¡ãããšãã§ããŸãã</li>
</ul>
<h3>å
¥åäŸ 2</h3>
<pre>4 3 5</pre>
<h3>åºåäŸ 2</h3>
<pre>Hom</pre>
<h3>å
¥åäŸ 3</h3>
<pre>6 4 10</pre>
<h3>åºåäŸ 3</h3>
<pre>Tem</pre>
|
p00593 |
<H1>JPEG Compression</H1>
<p>
The fundamental idea in the JPEG compression algorithm is to sort coeffi-
cient of given image by zigzag path and encode it. In this problem, we donât
discuss about details of the algorithm, but you are asked to make simple pro-
gram. You are given single integer N , and you must output zigzag path on
a matrix where size is N by N . The zigzag scanning is start at the upper-left
corner (0, 0) and end up at the bottom-right corner. See the following Figure
and sample output to make sure rule of the zigzag scanning. For example, if you
are given N = 8, corresponding output should be a matrix shown in right-side
of the Figure. This matrix consists of visited time for each element.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_1007">
</center>
<H2>Input</H2>
<p>
Several test cases are given. Each test case consists of one integer N (0 < N <
10) in a line. The input will end at a line contains single zero.
</p>
<H2>Output</H2>
<p>
For each input, you must output a matrix where each element is the visited
time. All numbers in the matrix must be right justified in a field of width 3.
Each matrix should be prefixed by a header âCase x:â where x equals test case
number.
</p>
<H2>Sample Input</H2>
<pre>
3
4
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1:
1 2 6
3 5 7
4 8 9
Case 2:
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
</pre>
|
p00439 |
<H1>æå€§ã®å </H1>
<h2>åé¡</h2>
<p>
<i>n</i> åã®æŽæ°ãããªãæ°å <i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, ..., <i>a<sub>n</sub></i> ãšæ£æŽæ° <i>k</i> (1 ≤ <i>k</i> ≤ <i>n</i>) ãäžãããã.ãã®ãšã, é£ç¶ããŠäžŠã¶ <i>k</i> åã®æŽæ°ã®å <i>S<sub>i</sub></i> = <i>a<sub>i</sub></i> + <i>a</i><sub>i+1</sub> + ... + <i>a</i><sub><i>i</i>+<i>k</i>-1</sub> (1 ≤ <i>i</i> ≤ <i>n</i> - <i>k</i> + 1) ã®æå€§å€ãåºåããããã°ã©ã ãäœããªãã.
</p>
<h2>å
¥å</h2>
<p>
<!-- å
¥åãã¡ã€ã«ã®ãã¡ã€ã«å㯠<span>input.txt</span> ã§ãã.-->
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒå
¥åã¯ïŒã€ã®ãŒããå«ãè¡ã§çµäºããïŒ
</p>
<p>
1 è¡ç®ã«ã¯æ£æŽæ° <i>n</i> (1 ≤ <i>n</i> ≤ 100000) ãšæ£æŽæ° <i>k</i> (1 ≤ <i>k</i> ≤ <i>n</i>) ããã®é ã«ç©ºçœã§
åºåãããŠæžãããŠãã.2 è¡ç®ä»¥éã®ç¬¬ 1 + <i>i</i> è¡ç® (1 ≤ <i>i</i> ≤ <i>n</i>) ã«ã¯, æ°åã® <i>i</i> çªç®ã®é
<i>a<sub>i</sub></i> (-10000 ≤ <i>a<sub>i</sub></i> ≤ 10000) ãæžãããŠãã.
æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 60% å㯠<i>n</i> ≤ 5000, <i>k</i> ≤ 1000 ãæºãã.
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ
</p>
<h2>åºå</h2>
<p>
<!--
åºåãã¡ã€ã«ã®ãã¡ã€ã«å㯠<span>output.txt</span> ã§ãã.
<span>output.txt</span> 㯠1 è¡ã ããããªã,ãã® 1 è¡ã¯ <i>S<sub>i</sub></i> ã®æå€§å€ã ããå«ã.
-->
ããŒã¿ã»ããããšã«<i>S<sub>i</sub></i> ã®æå€§å€ãïŒè¡ã«åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ</h3>
<pre>
5 3
2
5
-4
10
3
0 0
</pre>
<h3>åºåäŸ</h3>
<pre>
11
</pre>
<div class="source">
<p class="source">
äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02404 | <H1>Print a Frame</H1>
<p>
Draw a frame which has a height of <var>H</var> cm and a width of <var>W</var> cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm.
</p>
<pre>
##########
#........#
#........#
#........#
#........#
##########
</pre>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset consists of two integers <var>H</var> and <var>W</var> separated by a single space.
</p>
<p>
The input ends with two 0 (when both <var>H</var> and <var>W</var> are zero).
</p>
<H2>Output</H2>
<p>
For each dataset, print the frame made of '#' and '.'.
</p>
<p>
Print a blank line after each dataset.
</p>
<h2>Constraints</h2>
<ul>
<li>3 ≤ <i>H</i> ≤ 300</li>
<li>3 ≤ <i>W</i> ≤ 300</li>
</ul>
<H2>Sample Input</H2>
<pre>
3 4
5 6
3 3
0 0
</pre>
<H2>Sample Output</H2>
<pre>
####
#..#
####
######
#....#
#....#
#....#
######
###
#.#
###
</pre>
|
p03645 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>In Takahashi Kingdom, there is an archipelago of <var>N</var> islands, called Takahashi Islands.
For convenience, we will call them Island <var>1</var>, Island <var>2</var>, ..., Island <var>N</var>.</p>
<p>There are <var>M</var> kinds of regular boat services between these islands.
Each service connects two islands. The <var>i</var>-th service connects Island <var>a_i</var> and Island <var>b_i</var>.</p>
<p>Cat Snuke is on Island <var>1</var> now, and wants to go to Island <var>N</var>.
However, it turned out that there is no boat service from Island <var>1</var> to Island <var>N</var>, so he wants to know whether it is possible to go to Island <var>N</var> by using two boat services.</p>
<p>Help him.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 †N †200</var> <var>000</var></li>
<li><var>1 †M †200</var> <var>000</var></li>
<li><var>1 †a_i < b_i †N</var></li>
<li><var>(a_i, b_i) \neq (1, N)</var></li>
<li>If <var>i \neq j</var>, <var>(a_i, b_i) \neq (a_j, b_j)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
:
<var>a_M</var> <var>b_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If it is possible to go to Island <var>N</var> by using two boat services, print <code>POSSIBLE</code>; otherwise, print <code>IMPOSSIBLE</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
1 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>POSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 3
1 2
2 3
3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
<p>You have to use three boat services to get to Island <var>4</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 1
1 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>IMPOSSIBLE
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>5 5
1 3
4 5
2 3
2 4
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>POSSIBLE
</pre>
<p>You can get to Island <var>5</var> by using two boat services: Island <var>1</var> -> Island <var>4</var> -> Island <var>5</var>.</p></section>
</div>
</span> |
p01678 |
<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>The Animal School is a primary school for animal children.
You are a fox attending this school.
</p>
<p>One day, you are given a problem called "Arithmetical Restorations" from the rabbit teacher, Hanako.
Arithmetical Restorations are the problems like the following:
</p>
<ul><li><p> You are given three positive integers, $A$, $B$ and $C$.
</p></li><li><p> Several digits in these numbers have been erased.
</p></li><li><p> You should assign a digit in each blank position so that the numbers satisfy the formula $A+B=C$.
</p></li><li><p> The first digit of each number must not be zero. It is also the same for single-digit numbers.
</p></li></ul>
<p>You are clever in mathematics, so you immediately solved this problem.
Furthermore, you decided to think of a more difficult problem, to calculate the number of possible assignments to the given Arithmetical Restorations problem.
If you can solve this difficult problem, you will get a good grade.
</p>
<p>Shortly after beginning the new task, you noticed that there may be too many possible assignments to enumerate by hand. So, being the best programmer in the school as well, you are now trying to write a program to count the number of possible assignments to Arithmetical Restoration problems.
</p>
<h3>Input</h3>
<p>The input is a sequence of datasets.
The number of datasets is less than 100.
Each dataset is formatted as follows.
</p>
<blockquote>
$A$<br>$B$<br>$C$</blockquote>
<p>Each dataset consists of three strings, $A$, $B$ and $C$.
They indicate that the sum of $A$ and $B$ should be $C$.
Each string consists of digits (<code>0</code>-<code>9</code>) and/or question mark (<code>?</code>).
A question mark (<code>?</code>) indicates an erased digit.
You may assume that the first character of each string is not <code>0</code> and each dataset has at least one <code>?</code>.
</p>
<p>It is guaranteed that each string contains between 1 and 50 characters, inclusive.
You can also assume that the lengths of three strings are equal.
</p>
<p>The end of input is indicated by a line with a single zero.
</p>
<h3>Output</h3>
<p>For each dataset, output the number of possible assignments to the given problem modulo 1,000,000,007.
Note that there may be no way to solve the given problems because Ms. Hanako is a careless rabbit.
</p>
<h3>Sample Input</h3>
<pre>3?4
12?
5?6
?2?4
5?7?
?9?2
?????
?????
?????
0</pre>
<h3>Output for the Sample Input</h3>
<pre>2
40
200039979</pre>
<h3>Note</h3>
<p>The answer of the first dataset is 2. They are shown below.
</p><ul><li><p> 384 + 122 = 506
</p></li><li><p> 394 + 122 = 516
</p></li></ul>
|
p02957 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have two distinct integers <var>A</var> and <var>B</var>.</p>
<p>Print the integer <var>K</var> such that <var>|A - K| = |B - K|</var>.</p>
<p>If such an integer does not exist, print <code>IMPOSSIBLE</code> instead.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All values in input are integers.</li>
<li><var>0 \leq A,\ B \leq 10^9</var></li>
<li><var>A</var> and <var>B</var> are distinct.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the integer <var>K</var> satisfying the condition.</p>
<p>If such an integer does not exist, print <code>IMPOSSIBLE</code> instead.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 16
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>9
</pre>
<p><var>|2 - 9| = 7</var> and <var>|16 - 9| = 7</var>, so <var>9</var> satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>0 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>IMPOSSIBLE
</pre>
<p>No integer satisfies the condition.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>998244353 99824435
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>549034394
</pre></section>
</div>
</span> |
p01382 |
<div>
<h1 class="title">åé¡ G : ããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ãžããã¯</h1>
<p>ä»ïŒGââgle Code Jam ã®å°åºå€§äŒãå§ãŸãããšããŠããïŒ
åã®åžã«åº§ã£ãŠããç·ã® ID 㯠omeometo ãšèšããããïŒ
åŸãã®åžã«åº§ã£ãŠããç·ã® ID 㯠jellies ãšèšããããïŒ
æ±äº¬å€§åп代ã®èšæ¶ã«ïŒäŒŒããã㪠ID ã®ä»²éãå±
ãèŠãããããïŒåã®ä»²éã¯äžäººæ®ããçŸå°å¥³ã ã£ãã¯ãã ïŒ</p>
<p>圌ãã¯ïŒæºã®äžã«è»ã®ã€ã©ã¹ããæãããæ¬ãæã£ãŠããïŒ
ããã¯ãããâŠããã°ã©ãã³ã°ã³ã³ãã¹ãã®ã¢ã«ãŽãªãºã ãæåã«ç¶²çŸ
ãïŒä»ã§ã¯çºå£²çŠæ¢ãšãªã£ãäŒèª¬ã®æ¬ïŒ
ãããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ãžããã¯ãã§ã¯ãªããïŒ
åã¯ïŒomeometo ããã€ã¬ã«è¡ã£ãã®ãèŠèšããïŒå°ãæåããŠïŒèªãã§ã¿ãããšã«ããïŒ</p>
<div>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2265" alt="ããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ãžããã¯" />
<p class="caption">ããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ãžããã¯</p>
</div>
<p>âŠãããïŒåã¯äžç¬ã§æ¬ãèªã¿çµããŠããŸã£ãïŒ
æåæãã ïŒç°¡åãããïŒ
å°ãå€ãæ¬ã ãããšãã£ãŠïŒãããªå
容ã§ããå£²ãæ°ã«ãªã£ããã®ã ïŒ</p>
<p>äŸãã°ïŒæåã®äžè§åœ¢ã®åé¡ïŒããã¯ïŒç°¡åãããŠã話ã«ãªããªãïŒèªåã ã£ããïŒããããïŒ</p>
<div>
<h1>åé¡</h1>
<p><span style="font-size:110%;font-family:times new roman;"><i>N</i></span> æ¬ã®çŽç·ç¶ã®æ£ãããïŒæ£ <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> ã®é·ã㯠<span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub></span> ã§ããïŒ
ããªãã¯ïŒãããã®æ£ãã 6 æ¬ãéžã³ïŒ
ãããã® 3 æ¬ãã€ã§ïŒ2 åã®äžè§åœ¢ãäœãããšèããŠããïŒ
3 æ¬ã®æ£ã¯ããããäžè§åœ¢ã®èŸºãšããŠçšãïŒ2 ã€ã®æ£ãè§Šããäœçœ®ã¯æ£ã®ç«¯ç¹ã®ã¿ãšããïŒ
ã€ãŸãïŒæ£ã®äžéšãäžè§åœ¢ã®èŸºãšããŠäœ¿ãããšã¯èš±ãããïŒå¿
ãæ£å
šäœã蟺ãšããªããã°ãªããªãïŒ
ãŸãïŒæ£ã®å€ªãã¯èããïŒäžè§åœ¢ã¯æ£ã®é¢ç©ãæããªããã°ãªããªããã®ãšããïŒ</p>
<p>2 åã®äžè§åœ¢ã®åšé·ã®åã®æå€§å€ãæ±ããïŒ
ãã ãïŒ2 åã®äžè§åœ¢ãäœãããšãã§ããªãéã«ã¯ 0 ãçããšããïŒ</p>
</div>
<div>
<h1>å
¥å</h1>
<p>å
¥åã®æåã®è¡ã«ã¯æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> ãæžãããŠããïŒ
ç¶ã <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> è¡ã® <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> è¡ç®ã«ã¯ 1 ã€ã®æŽæ° <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>i</i></sub></span> ãæžãããŠããïŒ</p>
</div>
<div>
<h1>åºå</h1>
<p>çãã®æŽæ°ãåºåããïŒ</p>
</div>
<div>
<h1>å¶çŽ</h1>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>N</i> ≤ 10<sup>5</sup></span></li>
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>a</i><sub><i>i</i></sub> ≤ 10<sup>15</sup></span></li>
</ul>
</div>
<div>
<h1>éšåç¹</h1>
<p>ãã®åé¡ã®å€å®ã«ã¯ïŒ20 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ
ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã®å
¥åã¯ä»¥äžãæºããïŒ</p>
<ul class="simple">
<li><span style="font-size:110%;font-family:times new roman;">1 ≤ <i>N</i> ≤ 100</span></li>
</ul>
</div>
<div>
<h1>å
¥åºåäŸ</h1>
<p>å
¥åäŸ:</p>
<pre class="literal-block">
6
1
1
1
1
1
1
</pre>
<p>å
¥åäŸã«å¯Ÿããåºå:</p>
<pre class="literal-block">
6
</pre>
</div>
</div>
|
p03215 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence <var>(a_1, ..., a_N)</var> of length <var>N</var>.
He is interested in properties of the sequence <var>a</var>.</p>
<p>For a nonempty contiguous subsequence <var>a_l, ..., a_r</var> <var>(1 \leq l \leq r \leq N)</var> of the sequence <var>a</var>, its <em>beauty</em> is defined as <var>a_l + ... + a_r</var>. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of <var>K</var> nonempty contiguous subsequences among all <var>N(N+1)/2</var> nonempty contiguous subsequences. (Subsequences may share elements.)</p>
<p>Find the maximum possible value for him.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>2 \leq N \leq 1000</var></li>
<li><var>1 \leq a_i \leq 10^9</var></li>
<li><var>1 \leq K \leq N(N+1)/2</var></li>
<li>All numbers given in input are integers</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>4 2
2 5 2 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>12
</pre>
<p>There are <var>10</var> nonempty contiguous subsequences of <var>a</var>. Let us enumerate them:</p>
<ul>
<li>contiguous subsequences starting from the first element: <var>\{2\}, \{2, 5\}, \{2, 5, 2\}, \{2, 5, 2, 5\}</var></li>
<li>contiguous subsequences starting from the second element: <var>\{5\}, \{5, 2\}, \{5, 2, 5\}</var></li>
<li>contiguous subsequences starting from the third element: <var>\{2\}, \{2, 5\}</var></li>
<li>contiguous subsequences starting from the fourth element: <var>\{5\}</var></li>
</ul>
<p>(Note that even if the elements of subsequences are equal, subsequences that have different starting indices are considered to be different.)</p>
<p>The maximum possible bitwise AND of the beauties of two different contiguous subsequences is <var>12</var>.
This can be achieved by choosing <var>\{5, 2, 5\}</var> (with beauty <var>12</var>) and <var>\{2, 5, 2, 5\}</var> (with beauty <var>14</var>).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>8 4
9 1 8 2 7 5 6 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>32
</pre></section>
</div>
</span> |
p01228 |
<h1><font color="#000">Problem F:</font> Problem F: ãªãºã ãã·ãŒã³</h1>
<p>
Advanced Computer Music瀟ïŒACM瀟ïŒã¯ïŒ
ãããããããã°ã©ã ããããªãºã éãã«é³æ¥œãæŒå¥ãã
ãªãºã ãã·ãŒã³ã販売ããŠããïŒ
ããæïŒACMç€Ÿã¯æ°ãããªãºã ãã·ãŒã³ãéçºããŠå£²ãåºãããšããŠããïŒ
ACMç€Ÿã®æ§è£œåã¯åæã«1ã€ã®é³ãã鳎ããããšãã§ããªãã£ãã®ã«å¯ŸãïŒ
æ°è£œåã§ã¯æå€§ã§8ã€ã®é³ãåæã«é³Žãããããã«ãªããšããã®ã
äžçªã®ç®çæ©èœã§ãã£ãïŒ
ä»ãŸã§è€æ°ã®æ§è£œåãå©çšããŠæŒå¥ããå¿
èŠã®ãã£ãæ²ã
æ°è£œå1å°ã§æžãããã«ãªãã®ã§ïŒ
ACMç€Ÿã¯æ°è£œåãžã®ç§»è¡ãæšé²ãããããã«ïŒ
è€æ°ã®æ§è£œååãã®ãªãºã ãã¿ãŒã³ã1ã€ã®æ°è£œååãã®ãªãºã ãã¿ãŒã³ã«
倿ããããã°ã©ã ãäœãããšã«ããïŒ
</p>
<p>
ACM瀟ã®ãªãºã ãã·ãŒã³ã§ã¯ïŒåæã«ã©ã®é³ã鳎ãããã2æ¡ã®16鲿°ã§è¡šçŸããïŒ
ACM瀟ã®ãªãºã ãã·ãŒã³ã¯8ã€ã®ç°ãªãé³ã鳎ããããšãå¯èœã§ïŒ
ããããã®é³ã«ã¯0ãã7ã®çªå·ãå²ãåœãŠãããŠããïŒ
ããã¿ã€ãã³ã°ã«ãããŠïŒé³ <var>i</var> (0 ≤ <var>i</var> < 8)
ã鳎ããå Žåã <var>s</var><sub><var>i</var></sub> = 1ïŒ
鳎ãããªãå Žåã <var>s</var><sub><var>i</var></sub> = 0 ãšããïŒ
ãã®ãšãïŒããããã®é³ãåæã«é³Žããããããªåé³ã
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_rhythm" alt="Σ(s_i à 2^i)">
ãšããå€ã§è¡šãïŒ
ãã®å€ã2æ¡ã®16鲿°è¡šèšã§è¡šãããåé³è¡šçŸã
ããªãºã ãã¿ãŒã³ã®äžã§çšããããïŒ16鲿°ã®è±åã¯å€§æåãçšããïŒïŒ
äŸãã°ïŒé³0, 6, 7 ãåæã«é³Žãããããªåé³ã¯
<var>S</var> = 2<sup>0</sup> + 2<sup>6</sup> + 2<sup>7</sup>
= C1<sub>(16)</sub>
ãšãªããã “<code>C1</code>” ãšè¡šçŸããïŒ
ãŸãäœã鳎ãããªããããªãåé³ãã¯
“<code>00</code>” ãšè¡šçŸãããïŒ
</p>
<p>
ãªãºã ãã¿ãŒã³ã¯ïŒäžèšã®ãããªåé³è¡šçŸã1ã€ä»¥äžäžŠã¹ããã®ãšããŠäžããããïŒ
ãããªãºã ãã¿ãŒã³æååã¯ïŒ1å°ç¯å
ã®æŒå¥ãã¿ãŒã³ã瀺ããŠããïŒ
ããããã®åé³ã鳎ããã¿ã€ãã³ã°ãå°ç¯å
ã®çžå¯Ÿäœçœ®
<var>t</var> (0 ≤ <var>t</var> < 1)
ã§è¡šçŸããããšã«ããïŒ
<var>k</var> åã®åé³è¡šçŸãããªããªãºã ãã¿ãŒã³æååã¯ïŒ
å°ç¯ã <var>k</var> çåãããããã®åé³ãé ã«
<var>t</var> = 0/<var>k</var>, 1/<var>k</var>, ...,
(<var>k</var>â1)/<var>k</var> ã®ã¿ã€ãã³ã°ã§æŒå¥ãããããª
ãªãºã ãã¿ãŒã³ã衚ããŠããïŒ
äŸãã°ïŒãªãºã ãã¿ãŒã³ “<code>01000003</code>” ã¯ïŒ
<var>t</var> = 0/4 ã®ã¿ã€ãã³ã°ã§é³0ãæŒå¥ãïŒ
<var>t</var> = 3/4 ã®ã¿ã€ãã³ã°ã§é³0, 1ãæŒå¥ããããšã衚ãïŒ
ãŸãïŒãªãºã ãã¿ãŒã³ “<code>00</code>”
ã¯å°ç¯å
ã§äœãé³ã鳎ãããªãããšã衚ã
ïŒãªãºã ãã¿ãŒã³ã«ã¯åé³è¡šçŸã1ã€ä»¥äžå¿
èŠã§ããããšã«æ³šæããïŒïŒ
</p>
<p>
æ§è£œåã¯åæã«1ã€ã®é³ãã鳎ãããªãããïŒ
æ§è£œååãã®ãªãºã ãã¿ãŒã³æååå
ã«ã¯
“<code>00</code>”,
“<code>01</code>”,
“<code>02</code>”,
“<code>04</code>”,
“<code>08</code>”,
“<code>10</code>”,
“<code>20</code>”,
“<code>40</code>”,
“<code>80</code>”
ã®ããããã®åé³è¡šçŸããçŸããªãïŒ
æ§è£œååãã®ãªãºã ãã¿ãŒã³ã <var>N</var> å
(1 ≤ <var>N</var> ≤ 8) åãåãïŒ
ãããã®ãªãºã ãã¿ãŒã³ãåæã«æŒå¥ãããããª
æ°è£œååãã®ãªãºã ãã¿ãŒã³ãåºåããããã°ã©ã ãæžããŠæ¬²ããïŒ
</p>
<p>
äžãããã <var>N</var> åã®ãªãºã ãã¿ãŒã³ã«ãããŠïŒ
ãŸã£ããåãã¿ã€ãã³ã°ã§åãé³ãæŒå¥ãããããšã¯ãªããšä»®å®ããŠããïŒ
</p>
<h2>Input</h2>
<p>
æåã®è¡ã«ããŒã¿ã»ããã®æ°ãäžããããïŒ
次ã®è¡ä»¥éã«ã¯ïŒããããã®ããŒã¿ã»ãããé ã«èšè¿°ãããŠããïŒ
ããŒã¿ã»ããã®æ°ã¯ 120 ãè¶ããªããšä»®å®ããŠããïŒ
</p>
<p>
ããããã®ããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããïŒ
</p>
<pre>
<var>N</var>
<var>R</var><sub>1</sub>
<var>R</var><sub>2</sub>
...
<var>R</var><sub><var>N</var></sub>
</pre>
<p>
<var>R</var><sub><var>i</var></sub>
(1 ≤ <var>i</var> ≤ <var>N</var>)
ã¯ããããæ§è£œååãã®ãªãºã ãã¿ãŒã³ã§ããïŒ
</p>
<p>
åãªãºã ãã¿ãŒã³ã¯æå€§ã§2048æåïŒ1024åé³è¡šçŸïŒã§ããïŒ
äžãããããªãºã ãã¿ãŒã³ã¯å¿
ãããæçã®è¡šçŸã«ãªã£ãŠããªãããšã«æ³šæããïŒ
</p>
<h2>Output</h2>
<p>
åããŒã¿ã»ããã«ã€ããŠïŒäžãããã <var>N</var> åã®ãªãºã ãã¿ãŒã³ã
ãã¹ãŠåæã«æŒå¥ãããããªæçã®ãªãºã ãã¿ãŒã³ãçæãïŒ
1è¡ã§åºåããïŒ
ãã®ãããªãªãºã ãã¿ãŒã³ã2048æåãè¶ããå ŽåïŒ
ãªãºã ãã¿ãŒã³ã®ä»£ããã« “<code>Too complex.</code>”
ãšããæååãåºåããïŒ
</p>
<h2>Sample Input</h2>
<pre>
5
2
01000100
00020202
2
0102
00000810
1
0200020008000200
5
0001
000001
0000000001
00000000000001
0000000000000000000001
1
000000
</pre>
<h2>Output for the Sample Input</h2>
<pre>
01020302
01000A10
02020802
Too complex.
00
</pre>
|
p03080 | <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> people numbered <var>1</var> to <var>N</var>. Each person wears a red hat or a blue hat.</p>
<p>You are given a string <var>s</var> representing the colors of the people. Person <var>i</var> wears a red hat if <var>s_i</var> is <code>R</code>, and a blue hat if <var>s_i</var> is <code>B</code>.</p>
<p>Determine if there are more people wearing a red hat than people wearing a blue hat.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 100</var></li>
<li><var>|s| = N</var></li>
<li><var>s_i</var> is <code>R</code> or <code>B</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>s</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there are more people wearing a red hat than there are people wearing a blue hat, print <code>Yes</code>; otherwise, print <code>No</code>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
RRBR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
</pre>
<ul>
<li>There are three people wearing a red hat, and one person wearing a blue hat.</li>
<li>Since there are more people wearing a red hat than people wearing a blue hat, the answer is <code>Yes</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
BRBR
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>No
</pre>
<ul>
<li>There are two people wearing a red hat, and two people wearing a blue hat.</li>
<li>Since there are as many people wearing a red hat as people wearing a blue hat, the answer is <code>No</code>.</li>
</ul></section>
</div>
</span> |
p01547 |
<h1>æçµé²è¡ç·</h1>
<p>
ãã³ãã³æªç¢ºèªçç©ã«äŸµç¥ãããããã«ãªã£ãæåœã§ã¯éèŠæœèšãæ°åé²è¡å
µåšã§ä¿è·ããããšã«ããã<br>
ãã®å
µåšã¯å€è§åœ¢ã®é åã«ç¹æ®ãªã¬ã¹ãå
æºãããããšã§æªç¢ºèªçç©ã«ãã¡ãŒãžãäžããããšãã§ãããæªç¢ºèªçç©ã䟵æ»ããéäžã§ã¬ã¹ã®æ¿åºŠãå€ãããšãæ¿åºŠã®å·®ã®çµ¶å¯Ÿå€ã®ãã¡ãŒãžãäžãããã¬ã¹ã®æ¿åºŠãåãé åãåããŠãããšãã¯ãã¡ãŒãžã¯äžåçºçããªãã<br>
çŸåšã®æè¡ã§ã¯ã¬ã¹ã®æ¿åºŠã¯äžå®ã«ããã§ããªãã®ã§ãæåœã¯æ°åé²è¡å
µåšãè€æ°æå
¥ããããšã«ãããå
šãŠã®å
µåšã§ã¬ã¹ã®æ¿åºŠã¯åãã§ãããè€æ°ã®å
µåšã®é åã«å«ãŸããéšåã¯æ¿åºŠãè¶³ãåããããã
æªç¢ºèªçç©ã®åºçŸå°ç¹ãšéèŠæœèšã®äœçœ®ãå
ã«ãæªç¢ºèªçç©ãéèŠæœèšãŸã§äŸµæ»ããæã«åãããã¡ãŒãžã®æå°å€ãæ±ããŠæ¬²ããã<br>
ãã ããæªç¢ºèªçç©ã®äŸµæ»ã«ãŒãã«å€è§åœ¢ã®é ç¹ãä»ã®å€è§åœ¢ãšã®äº€ç¹ã¯å«ãŸããªããã®ãšããããŸããå€è§åœ¢ã®èŸºäžã蟺ã«ãã£ãŠäŸµæ»ããããšã¯ãªãã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<blockquote>
å€è§åœ¢ã®æ°<br>å€è§åœ¢ã®é ç¹æ°<br>xåº§æš y座æš<br>xåº§æš y座æš<br>...<br>å€è§åœ¢ã®é ç¹æ°<br>xåº§æš y座æš<br>xåº§æš y座æš<br>...<br>åºçŸå°ç¹ãšéèŠæœèšã®ããŒã¿ã®æ°<br>åºçŸäœçœ®ã®xåº§æš åºçŸäœçœ®ã®yåº§æš éèŠæœèšã®xåº§æš éèŠæœèšã®y座æš<br>åºçŸäœçœ®ã®xåº§æš åºçŸäœçœ®ã®yåº§æš éèŠæœèšã®xåº§æš éèŠæœèšã®y座æš<br>...<br></blockquote>
<h2>Constraints</h2>
<ul>
<li>å
¥åã«å«ãŸãã座æšã¯çµ¶å¯Ÿå€ã1,000以äžã®æŽæ°
</li><li>å€è§åœ¢ã®æ°ã¯1以äž5以äž
</li><li>å€è§åœ¢ã®é ç¹æ°ã¯3以äž5以äž
</li><li>åºçŸå°ç¹ãšéèŠæœèšã®ããŒã¿ã®æ°ã¯1以äž100以äž
</li><li>å€è§åœ¢ã¯äžããããé ç¹ãé ã«ã€ãªãã§ã§ããå€è§åœ¢ãæããèªå·±äº€å·®ã¯ãªã
</li><li>åºçŸå°ç¹ãšéèŠæœèšã¯å€è§åœ¢ã®é ç¹åã³èŸºäžã«ããããšã¯ãªã
</li></ul>
<h2>Output</h2>
<p>
åºçŸå°ç¹ãšéèŠæœèšã®çµããšã«æªç¢ºèªçç©ãéèŠæœèšãŸã§äŸµæ»ããéã«åãããã¡ãŒãžã®æå°å€ã1è¡ãã€åºåããã
</p>
<H2>Sample Input 1</H2>
<pre>2
4
0 4
1 1
3 1
4 4
3
6 0
10 0
8 7
1
2 3 9 1
</pre>
<H2>Output for the Sample Input 1</H2>
<pre>2
</pre>
<p>
1ã€ç®ã®å€è§åœ¢ãåºãæã«1ãã¡ãŒãžãäžãã2ã€ç®ã®å€è§åœ¢ã«å
¥ãæã«1ãã¡ãŒãžãäžããã
</p>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_probJ" height="172" width="361">
<H2>Sample Input 2</H2>
<pre>1
4
0 0
10 0
10 10
0 10
2
15 5 5 5
5 5 15 5
</pre>
<H2>Output for the Sample Input 2</H2>
<pre>1
1
</pre>
<p>
1ã€ç®ã®ããŒã¿ã§ã¯æªç¢ºèªçç©ãå€è§åœ¢ã«å
¥ãæã«ãã¡ãŒãžãçºçããã
2ã€ç®ã®ããŒã¿ã§ã¯æªç¢ºèªçç©ãå€è§åœ¢ããåºãæã«ãã¡ãŒãžãçºçããã
</p>
<H2>Sample Input 3</H2>
<pre>2
4
0 0
10 0
10 10
0 10
4
10 0
20 0
20 10
10 10
1
5 5 15 5
</pre>
<H2>Output for the Sample Input 3</H2>
<pre>0
</pre>
<p>
æªç¢ºèªçç©ã1ã€ç®ã®å€è§åœ¢ãã2ã€ç®ã®å€è§åœ¢ã«åãã«ãŒããåããšæ¿åºŠãå€ããããšããªãã®ã§ãã¡ãŒãžãäžããããšãã§ããªãã
</p>
<H2>Sample Input 4</H2>
<pre>2
3
0 0
10 0
5 10
3
5 0
15 0
10 10
1
5 5 10 5
</pre>
<H2>Output for the Sample Input 4</H2>
<pre>2
</pre>
<p>
åºçŸå°ç¹ã®é åãšéèŠæœèšã®é åã¯ç¹ã§æ¥ããŠããããã®ç¹ãéã£ãŠäŸµæ»ããããšã¯ãªãã
</p>
<H2>Sample Input 5</H2>
<pre>2
4
0 0
10 0
10 10
0 10
4
0 0
10 0
10 10
0 10
2
15 5 5 5
5 5 15 5
</pre>
<H2>Output for the Sample Input 5</H2>
<pre>2
2
</pre> |
p01117 | <!-- begin en only -->
<h3>Scores of Final Examination</h3>
<!-- end en only -->
<!-- begin en only -->
<p>
I am a junior high school teacher.
The final examination has just finished, and I have
all the students' scores of all the subjects.
I want to know the highest total score among the students,
but it is not an easy task as the student scores are
listed separately for each subject.
I would like to ask you, an excellent programmer, to help me
by writing a program that finds the total score of a student
with the highest total score.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of multiple datasets, each in the following format.
</p>
<!-- end en only -->
<blockquote>
<p>
<i>n m</i><br>
<i>p</i><sub>1,1</sub> <i>p</i><sub>1,2</sub> … <i>p</i><sub>1,<i>n</i></sub><br>
<i>p</i><sub>2,1</sub> <i>p</i><sub>2,2</sub> … <i>p</i><sub>2,<i>n</i></sub><br>
…<br>
<i>p</i><sub><i>m</i>,1</sub> <i>p</i><sub><i>m</i>,2</sub> … <i>p</i><sub><i>m,n</i></sub><br>
</p>
</blockquote>
<!-- begin en only -->
<p>
The first line of a dataset has two integers <i>n</i> and <i>m</i>.
<i>n</i> is the number of students (1 ≤ <i>n</i> ≤ 1000).
<i>m</i> is the number of subjects (1 ≤ <i>m</i> ≤ 50).
Each of the following <i>m</i> lines gives <i>n</i> students' scores
of a subject.
<i>p</i><sub><i>j,k</i></sub> is an integer representing
the <i>k</i>-th student's
score of the subject <i>j</i> (1 ≤ <i>j</i> ≤ <i>m</i>
and 1 ≤ <i>k</i> ≤ <i>n</i>).
It satisfies 0 ≤ <i>p</i><sub><i>j,k</i></sub> ≤ 1000.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
The end of the input is indicated by a line containing two zeros.
The number of datasets does not exceed 100.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
For each dataset, output the total score of a student with the highest
total score.
The total score <i>s</i><sub><i>k</i></sub>
of the student <i>k</i> is defined by
<i>s</i><sub><i>k</i></sub> =
<i>p</i><sub>1,<i>k</i></sub> + … + <i>p</i><sub><i>m,k</i></sub>.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
5 2
10 20 30 40 50
15 25 35 45 55
6 3
10 20 30 15 25 35
21 34 11 52 20 18
31 15 42 10 21 19
4 2
0 0 0 0
0 0 0 0
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
105
83
0
</pre>
|
p02691 | <span class="lang-en">
<p>Score: <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.</p>
<p>There are <var>N</var> attendees in the party, and they are given attendee numbers from <var>1</var> through <var>N</var>. The height of Attendee <var>i</var> is <var>A_i</var>.</p>
<p>According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.</p>
<ul>
<li>The absolute difference of their attendee numbers is equal to the sum of their heights.</li>
</ul>
<p>There are <var>\frac{N(N-1)}{2}</var> ways to choose two from the <var>N</var> attendees and make a pair. Among them, how many satisfy the condition above?</p>
<p>P.S.: We cannot let you know the secret.</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 2 \times 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9\ (1 \leq 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>A_1</var> <var>A_2</var> <var>\dots</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the number of pairs satisfying the condition.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
2 3 3 1 3 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<ul>
<li><var>A_1 + A_4 = 3</var>, so the pair of Attendee <var>1</var> and <var>4</var> satisfy the condition.</li>
<li><var>A_2 + A_6 = 4</var>, so the pair of Attendee <var>2</var> and <var>6</var> satisfy the condition.</li>
<li><var>A_4 + A_6 = 2</var>, so the pair of Attendee <var>4</var> and <var>6</var> satisfy the condition.</li>
</ul>
<p>No other pair satisfies the condition, so you should print <var>3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
5 2 4 2 8 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>No pair satisfies the condition, so you should print <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>22
</pre></section>
</div>
</span> |
p03983 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>
Eli- <var>1</var> started a part-time job handing out leaflets for <var>N</var> seconds.
Eli- <var>1</var> wants to hand out as many leaflets as possible with her special ability, Cloning.
Eli- <var>gen</var> can perform two kinds of actions below.
</p>
<ul>
<li> Clone herself and generate Eli- <var>(gen + 1)</var> . (one Eli- <var>gen</var> (cloning) and one Eli- <var>(gen + 1)</var> (cloned) exist as a result of Eli-<var>gen</var> 's cloning.)
This action takes <var>gen \times C</var> ( <var>C</var> is a coefficient related to cloning. ) seconds. </li>
<li> Hand out one leaflet. This action takes one second regardress of the generation ( <var>=gen</var> ). </li>
</ul>
<p>
They can not hand out leaflets while cloning.
Given <var>N</var> and <var>C</var> , find the maximum number of leaflets Eli- <var>1</var> and her clones can hand out in total modulo <var>1000000007</var> (<var>= 10^9 + 7</var>).
</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li> <var>1 \leq Q \leq 100000 = 10^5</var> </li>
<li> <var>1 \leq N_q \leq 100000 = 10^5</var> </li>
<li> <var>1 \leq C_q \leq 20000 = 2 \times 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>Q</var>
<var>N_1</var> <var>C_1</var>
:
<var>N_Q</var> <var>C_Q</var>
</pre>
<p>The input consists of multiple test cases. On line <var>1</var> , <var>Q</var> that represents the number of test cases is given.
Each test case is given on the next <var>Q</var> lines.
For the test case <var>q</var> ( <var>1 \leq q \leq Q</var> ) , <var>N_q</var> and
<var>C_q</var> are given separated by a single space.
<var>N_q</var> and <var>C_q</var> represent the working time and the coefficient related to cloning for test case <var>q</var> respectively.
</p>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>
For each test case, Print the maximum number of leaflets Eli- <var>1</var> and her clones can hand out modulo <var>1000000007</var> ( <var>= 10^9 + 7</var> ).
</p></section>
</div>
<div class="part">
<section>
<h3>Partial Scores</h3>
<p> <var>30</var> points will be awarded for passing the test set satisfying the condition: <var>Q = 1</var> . </p>
<p>Another <var>270</var> points will be awarded for passing the test set without addtional constraints and you can get <var>300</var> points in total. </p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3>
<pre>
2
20 8
20 12
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3>
<pre>
24
20
</pre>
<p> For the first test case, while only <var>20</var> leaflets can be handed out without cloning,
<var>24</var> leaflets can be handed out by cloning first and two people handing out<var>12</var> leaflets each. </p>
<p> For the second test case, since two people can only hand out <var>8</var> leaflets each if Eli- <var>1</var> clones, she should hand out <var>20</var> leaflets without cloning. </p>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 2</h3>
<pre>
1
20 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3>
<pre>
67
</pre>
<p>One way of handing out 67 leaflets is like the following image. Each black line means cloning, and each red line means handing out. </p>
<div style="text-align: center;">
<img src="/img/other/kupc2016/sushi/sample2.png"/>
</div>
<p> This case satisfies the constraint of the partial score. </p>
</section>
</div>
<div class="part">
<section>
<h3>Sample Input 3</h3>
<pre>
1
200 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3>
<pre>
148322100
</pre>
<p> Note that the value modulo <var>1000000007</var> ( <var>10^9 + 7</var> ) must be printed. </p>
<p> This case satisfies the constraint of the partial score. </p>
</section>
</div>
</span> |
p00356 |
<H1>Wire</H1>
<p>
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an <var>x</var> (horizontal) by <var>y</var> (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wire" width="300"><br/>
<span>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)<br/>
</span>
</center>
<br/>
<p>
Write a program to provide the number of points where the wire intersects with the panel boundaries.
Assume that the wire and boundary lines have no thickness.
</p>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
<var>x</var> <var>y</var>
</pre>
<p>
A line of data is given that contains the integer number of panels in the horizontal direction <var>x</var> (1 ≤ <var>x</var> ≤ 1000) and those in the vertical direction <var>y</var> (1 ≤ <var>y</var> ≤ 1000).
</p>
<h2>Output</h2>
<p>
Output the number of points where the wire intersects with the panel boundaries.
</p>
<h2>Sample Input 1</h2>
<pre>
4 4
</pre>
<h2>Sample Output 1</h2>
<pre>
5
</pre>
<h2>Sample Input 2</h2>
<pre>
4 6
</pre>
<h2>Sample Output 2</h2>
<pre>
9
</pre>
|
p00706 |
<H1>
Get Many Persimmon Trees
</H1>
<P>
Seiji Hayashi had been a professor of the Nisshinkan Samurai School
in the domain of Aizu for a long time in the 18th century.
In order to reward him for his meritorious career in education,
Katanobu Matsudaira, the lord of the domain of Aizu, had decided to
grant him a rectangular estate within a large field in the Aizu Basin.
Although the size (width and height) of the estate was strictly specified
by the lord, he was allowed to choose any location for the estate
in the field.
Inside the field which had also a rectangular shape,
many Japanese persimmon trees,
whose fruit was one of the famous products of the Aizu region
known as 'Mishirazu Persimmon', were planted.
Since persimmon was Hayashi's favorite fruit, he wanted to have
as many persimmon trees as possible in the estate given by the lord.
</P>
<P>
For example, in Figure 1, the entire field is a rectangular grid whose
width and height are 10 and 8 respectively. Each asterisk (*)
represents a place of a persimmon tree. If the specified width and
height of the estate are 4 and 3 respectively, the area surrounded by
the solid line contains the most persimmon trees. Similarly, if the
estate's width is 6 and its height is 4, the area surrounded by the
dashed line has the most, and if the estate's width and height are 3
and 4 respectively, the area surrounded by the dotted line contains
the most persimmon trees. Note that the width and height cannot be
swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure
1.
</P>
<CENTER>
<TABLE>
<TR>
<TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_trees"></TD>
</TR>
<TR>
<TD ALIGN="center">Figure 1: Examples of Rectangular Estates</TD>
</TR>
</TABLE>
</CENTER>
<P>
Your task is to find the estate of a given size (width and height)
that contains the largest number of persimmon trees.
</P>
<H2>Input</H2>
<P>
The input consists of multiple data sets.
Each data set is given in the following format.
</P>
<BLOCKQUOTE>
<I>N</I><BR>
<I>W</I><TT> </TT><I>H</I><BR>
<I>x</I><SUB>1</SUB><TT> </TT><I>y</I><SUB>1</SUB><BR>
<I>x</I><SUB>2</SUB><TT> </TT><I>y</I><SUB>2</SUB><BR>
...<BR>
<I>x</I><SUB><I>N</I></SUB><TT> </TT><I>y</I><SUB><I>N</I></SUB><BR>
<I>S</I><TT> </TT><I>T</I><BR>
</BLOCKQUOTE>
<P>
<I>N</I> is the number of persimmon trees,
which is a positive integer less than 500.
<I>W</I> and <I>H</I> are the width and the height of the entire field
respectively.
You can assume that both <I>W</I> and <I>H</I> are positive integers
whose values are less than 100.
For each <I>i</I> (1 <= <I>i</I> <= <I>N</I>),
<I>x</I><SUB><I>i</I></SUB> and <I>y</I><SUB><I>i</I></SUB> are
coordinates of the <I>i</I>-th persimmon tree in the grid.
Note that the origin of each coordinate is 1.
You can assume that 1 <= <I>x</I><SUB><I>i</I></SUB> <= <I>W</I>
and 1 <= <I>y</I><SUB><I>i</I></SUB> <= <I>H</I>,
and no two trees have the same positions.
But you should not assume that the persimmon trees are sorted in some order
according to their positions.
Lastly, <I>S</I> and <I>T</I> are positive integers of
the width and height respectively of the estate given by the lord.
You can also assume that 1 <= <I>S</I> <= <I>W</I>
and 1 <= <I>T</I> <= <I>H</I>.
</P>
<P>
The end of the input is indicated by a line that solely contains a zero.
</P>
<H2>Output</H2>
<P>
For each data set, you are requested to print one line containing the
maximum possible number of persimmon trees that can be included in an
estate of the given size.
</P>
<H2>Sample Input</H2>
<PRE>
16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0
</PRE>
<H2>Output for the Sample Input</H2>
<PRE>
4
3
</PRE>
|
p03829 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> towns on a line running east-west.
The towns are numbered <var>1</var> through <var>N</var>, in order from west to east.
Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value.
The coordinate of town <var>i</var> is <var>X_i</var>.</p>
<p>You are now at town <var>1</var>, and you want to visit all the other towns.
You have two ways to travel:</p>
<ul>
<li>
<p>Walk on the line.
Your <em>fatigue level</em> increases by <var>A</var> each time you travel a distance of <var>1</var>, regardless of direction.</p>
</li>
<li>
<p>Teleport to any location of your choice.
Your fatigue level increases by <var>B</var>, regardless of the distance covered.</p>
</li>
</ul>
<p>Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li>All input values are integers.</li>
<li><var>2â€Nâ€10^5</var></li>
<li><var>1â€X_iâ€10^9</var></li>
<li>For all <var>i(1â€iâ€N-1)</var>, <var>X_i<X_{i+1}</var>.</li>
<li><var>1â€Aâ€10^9</var></li>
<li><var>1â€Bâ€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>A</var> <var>B</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 minimum possible total increase of your fatigue level when you visit all the towns.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2 5
1 2 5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
</pre>
<p>From town <var>1</var>, walk a distance of <var>1</var> to town <var>2</var>, then teleport to town <var>3</var>, then walk a distance of <var>2</var> to town <var>4</var>.
The total increase of your fatigue level in this case is <var>2Ã1+5+2Ã2=11</var>, which is the minimum possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>7 1 100
40 43 45 105 108 115 124
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>84
</pre>
<p>From town <var>1</var>, walk all the way to town <var>7</var>.
The total increase of your fatigue level in this case is <var>84</var>, which is the minimum possible value.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>7 1 2
24 35 40 68 72 99 103
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>12
</pre>
<p>Visit all the towns in any order by teleporting six times.
The total increase of your fatigue level in this case is <var>12</var>, which is the minimum possible value.</p></section>
</div>
</span> |
p01814 |
<h2>ã»ãŒåšææåå</h2>
<p>
æåå <var>S</var> ãäžããããããã®æåå <var>S</var> ã«å¯Ÿãã<var>Q</var> åã®ã¯ãšãªã«çããã
<var>i</var> çªç®ã®ã¯ãšãªã§ã¯ã<var>S[l_i,\ r_i]</var> ãã1æåãŸã§å€ããŠãããšãã<var>S[l_i,\ r_i]</var> ãåšæ <var>t_i</var> ã®æååã«ã§ãããã©ãããå€å®ããã<var>S[l,\ r]</var> ã¯æåå <var>S</var> ã® <var>l</var> æåç®ãã <var>r</var> æåç®ãŸã§ã®éšåæååã衚ãã
</p>
<p>
æåå <var>W</var> ãåšæ <var>t</var> ã®æååã§ãããšã¯ã<var>i\ =\ 1,\2,\... ,\ |W| − t</var> ã«å¯Ÿãã
<var> W_{i} = W_{i+t}</var>
ãšãªãããšãšããã
</p>
<h3>Constraints</h3>
<ul>
<li><var>1 ≤ |S| ≤ 10^5</var></li>
<li><var>1 ≤ Q ≤ 10^5</var></li>
<li><var>1 ≤ l_i ≤ r_i ≤ |S|</var></li>
<li><var>1 ≤ t_i ≤ r_i − l_i+1 </var></li>
<li><var>S</var>ã¯ã¢ã«ãã¡ãããã®å°æåã®ã¿ãããªã</li>
</ul>
<h3>Input Format</h3>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã
</p>
<pre>
<var>S</var>
<var>Q</var>
<var>l_1</var> <var>r_1</var> <var>t_1</var>
...
<var>l_Q</var> <var>r_Q</var> <var>t_Q</var>
</pre>
<h3>Output Format</h3>
<p>
<var>Q</var> è¡ã«ããã£ãŠåºåããã
<var>i</var> è¡ç®ã«ã¯ã<var>i</var> çªç®ã®ã¯ãšãªã®çãã
<code>Yes</code> ãŸã㯠<code>No</code> ã§åºåããã
</p>
<h3>Sample Input 1</h3>
<pre>
abcabcaxcabc
4
1 9 3
8 12 3
1 4 2
2 3 2
</pre>
<h3>Sample Output 1</h3>
<pre>
Yes
Yes
No
Yes
</pre>
<h3>Sample Input 2</h3>
<pre>
isuruu
4
3 6 1
3 6 2
3 6 3
2 4 1
</pre>
<h3>Sample Output 2</h3>
<pre>
Yes
Yes
Yes
No
</pre> |
p00213 |
<H1>>åå°åå²</H1>
<p>
ããŠãžã³ã°ã¡ãŒã«ãŒã®å±±ç°ããŠã¹ã¯ãæ°ããªç®çååãšããŠãåŠæ ¡ãç
é¢ãªã©ç°å¢ãå
å®ããŠããç·ããŒã ã¿ãŠã³ã®åè²å°ã売ãåºããŸããããã®åè²å°ã¯è€æ°ã®åºç»ã«åå²ãããŠããã奜ããªã ã賌å
¥ã§ããŸããã賌å
¥ããåºç»ãåãããåå°ã®åœ¢ç¶ã¯é·æ¹åœ¢(æ£æ¹åœ¢ãå«ã)ã§ãªããã°ãªããŸããã
</p>
<p>
å±±ç°ããŠã¹ã¯ãå
šåºç»ãå®å£²ããåè²å°ã管çãããã賌å
¥è
ããšã«å¢çç·ãåŒãããã®åºç»ã® 1ã€ã«è³Œå
¥è
çªå·ãæžããçæ¿ãèšçœ®ããŠãããŸãããå¢çç·ã¯å°é¢ã«æšã®æã§ç·ãåŒããã ãã®ãã®ã§ãã£ããããæ°æ¥åŸã®è±ªéšã«ããæ¶ããŠããŸãçæ¿ã ããæ®ããŸãããå³ 1 ã¯çæ¿ã®ãã£ãåºç»ã«ããã®åºç»ãè²·ã£ã賌å
¥è
çªå·ãèšãããã®ã§ããããã§ã¯åè²å°ãã©ã®ããã«è²·ããããåãããŸãããæãã¯äºåæã®åŒãåºãã«ãã£ã賌å
¥è
çªå· <var>b</var> ãšè³Œå
¥åºç»æ° <var>k</var> ã®ã¡ã¢(å³ 2)ãèŠã€ãã£ãããšã§ãã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_partitionTable"><br/>
<p>å³ïŒïŒå·ŠïŒïŒçæ¿ã®é
眮ãå³2ïŒå³ïŒïŒã¡ã¢</p>
</center>
<p>
ããã°ã©ããŒã§ããããªãã¯ãããã°ã©ã ãæžããŠå±±ç°ããŠã¹ãå©ããããšã«ãªããŸãããåè²å°ã®å€§ãã <var>X × Y</var> ã賌å
¥è
æ° <var>n</var> ãã¡ã¢ã®æ
å ± <var>b</var>ã <var>k</var> ãåã³çæ¿ã®äœçœ®æ
å ± <var>s</var> ãå
¥åãšããå³ 3 ã«ç€ºãããã«ååºç»ã®è³Œå
¥è
ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_partition2R"><br/>
<p>
å³3ïŒååºç»ã®è³Œå
¥è
</p>
</center>
<p>
äžããããæ
å ±ã«ã€ããŠã以äžã®å Žå㯠NA ãšåºåããŸãã
</p>
<ul>
<li> åºç»ãåºå¥ããæ¹æ³ãååšããªãå Žå</li>
<li> åºç»ãåºå¥ããæ¹æ³ãè€æ°ååšããå Žå</li>
</ul>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããïŒã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>X</var> <var>Y</var> <var>n</var>
<var>b<sub>1</sub></var> <var>k<sub>1</sub></var>
<var>b<sub>2</sub></var> <var>k<sub>2</sub></var>
:
<var>b<sub>n</sub></var> <var>k<sub>n</sub></var>
<var>s<sub>11</sub></var> <var>s<sub>21</sub></var> ... <var>s<sub>X1</sub></var>
<var>s<sub>12</sub></var> <var>s<sub>22</sub></var> ... <var>s<sub>X2</sub></var>
:
<var>s<sub>1Y</sub></var> <var>s<sub>2Y</sub></var> ... <var>s<sub>XY</sub></var>
</pre>
<p>
1 è¡ç®ã«<var>X, Y, n</var> (1 ≤ <var>X, Y</var> ≤ 10, 1 ≤ <var>n</var> ≤ 15) ãäžããããŸããç¶ã <var>n</var> è¡ã«ã¡ã¢ã® <var>i</var> è¡ç®ã«æžãããæ
å ± <var>b<sub>i</sub></var> (1 ≤ <var>b<sub>i</sub></var> ≤ <var>n</var>), <var>k<sub>i</sub></var> (1 ≤ <var>k<sub>i</sub></var> ≤ 100) ãäžããããŸãã
</p>
<p>
ç¶ã <var>Y</var> è¡ã«åºç»æ
å ±ã® <var>i</var> è¡ç®ã®æ
å ± <var>s<sub>ij</sub></var> ãäžããããŸãã<var>s<sub>ij</sub></var> ã¯<var>i</var> è¡ç®ã®å·Šãã <var>j</var> çªç®ã®åºç»ã®çæ¿æ
å ±ã衚ããŸããçæ¿ã®æ
å ± <var>s<sub>ij</sub></var> ãšããŠããã®åºç»ã«çæ¿ãç¡ãå Žå㯠0 ãçæ¿ãããå Žåã¯ãã®åºç»ã®è³Œå
¥è
çªå·ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
å
¥åããŒã¿ã»ããããšã«ã賌å
¥è
æ
å ±ãŸãã¯NA ãåºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
5 4 6
1 6
2 4
3 3
4 4
5 1
6 2
0 0 1 0 0
0 0 0 2 0
0 0 0 3 0
0 4 5 0 6
3 3 1
1 9
0 0 1
0 0 0
0 0 0
4 4 4
1 6
2 2
3 4
4 4
0 1 0 0
0 0 0 2
0 0 3 0
0 4 0 0
0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1 1 1 2 2
1 1 1 2 2
4 4 3 3 3
4 4 5 6 6
1 1 1
1 1 1
1 1 1
NA
</pre>
|
p00643 |
<H1><font color="#000000">Problem G:</font> Rolling Dice</H1>
<p>
The north country is conquered by the great shogun-sama (which means
king). Recently many beautiful dice which were made by order of the
great shogun-sama were given to all citizens of the country. All
citizens received the beautiful dice with a tear of delight. Now they
are enthusiastically playing a game with the dice.
</p>
<p>
The game is played on grid of <i>h</i> * <i>w</i> cells that each of which has a
number, which is designed by the great shogun-sama's noble philosophy.
A player put his die on a starting cell and move it to a destination
cell with rolling the die. After rolling the die once, he takes a
penalty which is multiple of the number written on current cell and
the number printed on a bottom face of the die, because of malicious
conspiracy of an enemy country. Since the great shogun-sama strongly
wishes, it is decided that the beautiful dice are initially put so
that 1 faces top, 2 faces south, and 3 faces east. You will find that
the number initially faces north is 5, as sum of numbers on opposite
faces of a die is always 7. Needless to say, idiots those who move his
die outside the grid are punished immediately.
</p>
<p>
The great shogun-sama is pleased if some citizens can move the
beautiful dice with the least penalty when a grid and a starting cell
and a destination cell is given. Other citizens should be sent to coal
mine (which may imply labor as slaves). Write a program so that
citizens can deal with the great shogun-sama's expectations.
</p>
<H2>Input</H2>
<p>
The first line of each data set has two numbers <i>h</i> and <i>w</i>, which stands
for the number of rows and columns of the grid.
</p>
<p>
Next <i>h</i> line has <i>w</i> integers, which stands for the number printed on the
grid. Top-left corner corresponds to northwest corner.
</p>
<p>
Row number and column number of the starting cell are given in the
following line, and those of the destination cell are given in the next
line. Rows and columns are numbered 0 to <i>h</i>-1, 0 to <i>w</i>-1, respectively.
</p>
<p>
Input terminates when <i>h</i> = <i>w</i> = 0.
</p>
<H2>Output</H2>
<p>
For each dataset, output the least penalty.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>h</i>, <i>w</i> ≤ 10</li>
<li>0 ≤ number assinged to a cell ≤ 9</li>
<li>the start point and the goal point are different.</li>
</ul>
<H2>Sample Input</H2>
<pre>
1 2
8 8
0 0
0 1
3 3
1 2 5
2 8 3
0 1 2
0 0
2 2
3 3
1 2 5
2 8 3
0 1 2
0 0
1 2
2 2
1 2
3 4
0 0
0 1
2 3
1 2 3
4 5 6
0 0
1 2
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
24
19
17
6
21
</pre>
|
p01951 |
<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>
Low Range-Sum Matrix
</H1>
<p>
You received a card at a banquet. On the card, a matrix of $N$ rows and $M$ columns and two integers $K$ and $S$ are written. All the elements in the matrix are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is denoted by $A_{i,j}$.
</p>
<p>
You can select up to $K$ elements from the matrix and invert the sign of the elements. If you can make a matrix such that there is no vertical or horizontal contiguous subsequence whose sum is greater than $S$, you can exchange your card for a prize.
</p>
<p>
Your task is to determine if you can exchange a given card for a prize.
</p>
<H2>Input</H2>
<p>
The input consists of a single test case of the following form.
</p>
<pre>
$N$ $M$ $K$ $S$
$A_{1,1}$ $A_{1,2}$ ... $A_{1,M}$
:
$A_{N,1}$ $A_{N,2}$ ... $A_{N,M}$
</pre>
<p>
The first line consists of four integers $N, M, K$ and $S$ ($1 \leq N, M \leq 10, 1 \leq K \leq 5, 1 \leq S \leq 10^6$). The following $N$ lines represent the matrix in your card. The ($i+1$)-th line consists of $M$ integers $A_{i,1}, A_{i,2}, ..., A_{i, M}$ ($-10^5 \leq A_{i,j} \leq 10^5$).
</p>
<H2>Output</H2>
<p>
If you can exchange your card for a prize, print '<span>Yes</span>'. Otherwise, print '<span>No</span>'.
</p>
<H2>Sample Input 1</H2>
<pre>
3 3 2 10
5 3 7
2 6 1
3 4 1
</pre>
<H2>Output for Sample Input 1</H2>
<pre>
Yes
</pre>
<p>
The sum of a horizontal contiguous subsequence from $A_{1,1}$ to $A_{1,3}$ is $15$. The sum of a vertical contiguous subsequence from $A_{1,2}$ to $A_{3,2}$ is $13$. If you flip the sign of $A_{1,2}$, there is no vertical or horizontal contiguous subsequence whose sum is greater than $S$.
</p>
<H2>Sample Input 2</H2>
<pre>
2 3 1 5
4 8 -2
-2 -5 -3
</pre>
<H2>Output for Sample Input 2</H2>
<pre>
Yes
</pre>
<H2>Sample Input 3</H2>
<pre>
2 3 1 5
9 8 -2
-2 -5 -3
</pre>
<H2>Output for Sample Input 3</H2>
<pre>
No
</pre>
<H2>Sample Input 4</H2>
<pre>
2 2 3 100
0 0
0 0
</pre>
<H2>Output for Sample Input 4</H2>
<pre>
Yes
</pre>
|
p02384 |
<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>Dice II</h1><br>
<p>
Construct a dice from a given sequence of integers in the same way as <a href="description.jsp?id=ITP1_11_A">Dice I</a>.
</p>
<p>
You are given integers on the top face and the front face after the dice was rolled in the same way as <a href="description.jsp?id=ITP1_11_A">Dice I</a>. Write a program to print an integer on the right side face.
</p>
<br>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_B">
</center>
<br><br>
<h2>Input</h2>
<p>
In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.
In the second line, the number of questions $q$ is given.
</p>
<p>
In the following $q$ lines, $q$ questions are given. Each question consists of two integers on the top face and the front face respectively.
</p>
<h2>Output</h2>
<p>
For each question, print the integer on the right side face.
</p>
<h2>Constraints</h2>
<ul>
<li>$0 \leq $ the integer assigned to a face $ \leq 100$</li>
<li>The integers are all different</li>
<li>$1 \leq q \leq 24$</li>
</ul>
<h2>Sample Input</h2>
<pre>
1 2 3 4 5 6
3
6 5
1 3
3 2
</pre>
<h2>Sample Output</h2>
<pre>
3
5
6
</pre>
|
p01402 |
<h2>
Problem E: ã¢ããã
</h2>
<p>
çæãç¶ãããé·ãã£ãããã§çãã£ããããªå€ãããããçµããããšããŠããã
ãããª8æäžæ¬ã®ããæ¥ããšãã2D奜ããªäººç©ãšãã®å
茩ã®slipã¯ãã¢ããããµããŒã©ã€ããéç§°ã¢ããããšåŒã°ããã€ãã³ãã«åå ããŠããã
ã¢ããããšã¯ãããŸããŸãªã¢ãã¡ãœã³ã°ã¢ãŒãã£ã¹ããã¡ãéçµãããæ¥æ¬åœå
æå€§ã®ã¢ãã¡ãœã³ã°ã©ã€ãã€ãã³ãã§ããã
ä»å¹Žã®ã¢ãããã¯ãå
¬åŒã§å
¬è¡šãããŠããã¢ãŒãã£ã¹ãã®ä»ã«ãã·ãŒã¯ã¬ããã§è¶
è±ªè¯ææãåºæŒããå€§çæ³ã®å
ã«å¹ãéããã
ã¢ãããã«ã¯ååæŠã ã£ã2D奜ããªåœŒã¯ãã©ã€ãåŸã®äœé»ã«ã²ããã€ã€ããã²ãšã€ã®çåãæ±ããŠããã
ãã¢ãããã«åºæŒããã¢ãŒãã£ã¹ãã¯ã©ã®ããã«æ±ºããŠããã®ã ãããïŒã
圌ã¯ãæ°ããã¢ãŒãã£ã¹ãã®äžãããåºæŒã¢ãŒãã£ã¹ãã®éžåºãããã®ã«ã次ã®ãããªæ¹æ³ãããã®ã§ã¯ãªãããšãéžåºæ³ãèããŠã¿ãã
</p>
<p>
ãŸããã¢ãããã®ã¢ãŒãã£ã¹ãã«ã¯ãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ããšã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãã®2çš®é¡ã®åé¡ããããã®ãšããã
ã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ããšã¯ãã©ã€ãã«åºæŒããããšãäºåå
¬è¡šãããã©ã€ãæ¬çªã«ãªã£ãŠçªç¶çŸããã¢ãŒãã£ã¹ãã®ããšãæãã
ã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ããšã¯ãã©ã€ãã«åºæŒããããšãäºåã«å
¬è¡šããŠããã¢ãŒãã£ã¹ãã®ããšãæãã
</p>
<p>
å
šãŠã®ã¢ãŒãã£ã¹ãã¯ã次ã®ã¹ããŒã¿ã¹ãæã€ã
<ul>
<li>
ã¢ãŒãã£ã¹ãåïŒæåå</li>
<li>
ã¢ãŒãã£ã¹ããéãããã®éé¡ïŒä»¥äžãéçšéãšåŒã¶ïŒïŒèªç¶æ°</li>
<li>
ãã®ã¢ãŒãã£ã¹ããåºæŒããããšã§ãã客ãã©ãã»ã©æºè¶³ããããããïŒä»¥äžãæºè¶³åºŠãšåŒã¶ïŒïŒèªç¶æ°</li>
</ul>
ä»åãã©ã€ãã«åºæŒããã¢ãŒãã£ã¹ããéžã¶ããã«ãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£<i>N</i>人ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£<i>M</i>人ãããã§ã«çšæãããŠãããã®ãšãããããã«ãã©ã€ãã®äž»å¬è
ã¯ãã¢ãŒãã£ã¹ããéçšããããã«äœ¿çšã§ããè³é<i>LIMIT</i>ãæã£ãŠãããã®ãšããã
</p>
<p>
äž»å¬è
ã¯ãæ¬¡ã®æ¡ä»¶ãæºããããã«ãã¢ãŒãã£ã¹ããéžåºããªããã°ãªããªãã
<ul>
<li>
<i>N</i>人ã®ã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãæ ããã1人以äžã2人以äžãéžåºãã(1人or2人ãªã®ã¯ãã·ãŒã¯ã¬ãããããªãã£ããå€ãã£ããããããšãé¿ããããã§ãã)</li>
<li>
<i>M</i>人ã®ã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãæ ããã<i>X</i>人以äžã®ã¢ãŒãã£ã¹ããéžåºãã</li>
<li>
ã¢ãŒãã£ã¹ããå
šãŠéžåºãçµãããšããéçšéã®åèšãã<i>LIMIT</i>以äžã«ãã</li>
<li>
éžåºããã¢ãŒãã£ã¹ãå
šå¡ã§åŸãããæºè¶³åºŠã®åèšãæå€§åãã</li>
</ul>
ããŠããããŸã§éžåºæ³ãèãã2D奜ããªåœŒã¯ããã®æ¹æ³ã§ããã°ã©ã ãæžããŠã¿ãããšæã£ãããããã圌ã¯éžåºæ³ãèããã®ã«æ°åã䜿ã£ãŠããŸããããã°ã©ã ãæžãæ°åããªããªã£ãŠããŸã£ããããªã®ã§ã圌ã®ä»£ããã«ããã°ã©ã ãæžããŠãããŠã»ããã
</p>
<p>
ããªãã®ä»äºã¯ãäžèšã®éžåºæ³ã«åŸããã¢ãŒãã£ã¹ããéžåºãããšãã®ãå®¢ã®æå€§æºè¶³åºŠãåºåããããã°ã©ã ãäœæããããšã§ããã
</p>
<h2>
Input
</h2>
<p>
å
¥åã¯ãè€æ°ã®ããŒã¿ã»ãããããªããããŒã¿ã»ããã®ç·æ°ã¯20以äžã§ããã
åããŒã¿ã»ããã¯ã次ã®åœ¢ãããŠããã
</p>
<pre>
<i>LIMIT</i> <i>N</i> <i>M</i> <i>X</i>
<i>SEC_NAME<i><sub>1</i></i></sub> <i>SEC_E<i><sub>1</i></i></sub> <i>SEC_S<i><sub>1</i></i></sub>
...
<i>SEC_NAME<i><sub>i</i></i></sub> <i>SEC_E<i><sub>i</i></i></sub> <i>SEC_S<i><sub>i</i></i></sub>
...
<i>SEC_NAME<i><sub>N</i></i></sub> <i>SEC_E<i><sub>N</i></i></sub> <i>SEC_S<i><sub>N</i></i></sub>
<i>NAME<i><sub>1</i></i></sub> <i>E<sub>1</sub></i> <i>S<sub>1</sub></i>
...
<i>NAME<i><sub>i</i></i></sub> <i>E<sub>i</sub></i> <i>S<sub>i</sub></i>
...
<i>NAME<i><sub>M</i></i></sub> <i>E<sub>M</sub></i> <i>S<sub>M</sub></i>
</pre>
<p>
æŽæ°<i>LIMIT</i>(<i>4 ≤</i> <i>LIMIT</i> <i>≤ 1000</i>)ã<i>N</i>(<i>2 ≤ N ≤ 100</i>)ã<i>M</i>(<i>2 ≤ M ≤ 100</i>)ã<i>X</i>(<i>2 ≤ X ≤ M</i>)ã¯ã
ããããã¢ãŒãã£ã¹ããéçšããã®ã«äœ¿çšã§ããè³éãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ã®æ°ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ã®æ°ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãããéžåºããªããã°ãªããªãæäœäººæ°ã衚ãã
<i>SEC_NAME<i><sub>i</i></i></sub>ã<i>NAME<i><sub>i</i></i></sub>ãã¯ããããã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ã®ååãæã30æå以äžã®æååã§ããã
æååã«ã¯ãã¢ã«ãã¡ããã('A'-'Z', 'a'-'z')ã®ã¿ã䜿çšãããã
åãã¢ãŒãã£ã¹ãåã2å以äžåºçŸããããšã¯ãªãã
æŽæ°<i>SEC_E<i><sub>i</i></i></sub>ã<i>E<sub>i</sub></i> (<i>1 ≤</i> <i>SEC_E<i><sub>i</i></i></sub>, <i>E<sub>i</sub> ≤ 10</i>)ã<i>SEC_S<i><sub>i</i></i></sub>ã<i>S<sub>i</sub></i> (<i>1 ≤</i> <i>SEC_S<i><sub>i</i></i></sub>, <i>S<sub>i</sub> ≤ 10</i>) ã¯ãããããã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ã®éçšéãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ã®éçšéãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ãåºæŒãããšãã«åŸãããæºè¶³åºŠãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ãåºæŒãããšãã«åŸãããæºè¶³åºŠã衚ãã
</p>
<p>
å
¥åã®çµäºã¯ã0ã4ã€ã®è¡ã§ç€ºãããããã®ããŒã¿ã«ã€ããŠã¯åŠçããå¿
èŠã¯ãªãã
</p>
<h2>
Output
</h2>
<p>
éžåºæ³ãé©çšããŠã¢ãŒãã£ã¹ããéžåºãããšãããå®¢ã®æºè¶³åºŠã®æå€§å€ãåºåããã
ã¢ãŒãã£ã¹ãã®éžåºã®ä»æ¹ã¯ãå¿
ããããšä»®å®ããŠããã
</p>
<h2>
Sample Input
</h2>
<pre>
100 2 2 2
A 5 6
B 7 8
C 1 2
D 3 4
27 2 3 3
A 8 10
B 8 10
C 6 7
D 5 4
E 8 9
27 2 3 2
A 8 10
B 8 10
C 6 7
D 5 4
E 8 9
44 3 6 5
YamatoNoHito 9 10
ZettoNoHito 9 10
TMR 10 10
SkillNoGroup 8 10
NanaSama 6 9
FRPSD 6 8
Magi3rdDeshi 5 7
Magi13thDeshi 2 2
MagicalItoh 4 6
0 0 0 0
</pre>
<h2>
Output for Sample Input
</h2>
<pre>
20
30
31
55
</pre>
|
p01052 |
<h1>Movie</h1>
<h2>Problem</h2>
<p>
倪éåã¯å€äŒã¿ã®éãæ¯æ¥ïŒã€ã®æ ç»ãè¿æã®æ ç»é€šã§èŠãããšã«ããŸããã
ïŒå€ªéåã®å€äŒã¿ã¯8æ1æ¥ãã8æ31æ¥ãŸã§ã®31æ¥éãããŸããïŒ
</p>
<p>
ãã®æ ç»é€šã§ã¯ãå€äŒã¿ã®éã«<var>n</var> ã€ã®æ ç»ãäžæ ãããããšã«ãªã£ãŠããŸãã
ããããã®æ ç»ã«ã¯ 1 ãã <var>n</var> ãŸã§ã®çªå·ãå²ãåœãŠãããŠããã<var>i</var> çªç®ã®æ ç»ã¯8æ <var>a<sub>i</sub></var> æ¥ãã8æ <var>b<sub>i</sub></var> æ¥ã®éã ãäžæ ãããŸãã
</p>
<p>
倪éåã¯æ ç»ãèŠãæããããåããŠèŠãæ ç»ã ã£ãå Žå㯠100 ã®å¹žçŠåºŠãåŸãããšãã§ããŸãã
ããããéå»ã« 1 床ã§ãèŠãããšã®ããæ ç»ã ã£ãå Žå㯠50 ã®å¹žçŠåºŠãåŸãŸãã
</p>
<p>
倪éåã¯äžæ ãããæ ç»ã®äºå®è¡šãããšã«ãå€äŒã¿ã®èšç»ãç«ãŠãããšã«ããŸããã
倪éåãåŸããã幞çŠåºŠã®åèšå€ãæå€§ã«ãªãããã«æ ç»ãèŠããšãã®åèšå€ãæ±ããŠãã ããã
</p>
<p>
ã©ã®æ¥ãå¿
ã1ã€ä»¥äžã®æ ç»ãäžæ ãããŠããããšãä¿èšŒãããŸãã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>n</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var>
...
<var>a<sub>n</sub></var> <var>b<sub>n</sub></var>
</pre>
<p>
1è¡ç®ã«ã1ã€ã®æŽæ° <var>n</var> ãäžããããã
2è¡ç®ããã® <var>n</var> è¡ã®ãã¡ <var>i</var> è¡ç®ã«ã¯ 2 ã€ã®æŽæ° <var>a<sub>i</sub>, b<sub>i</sub> </var> ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<ul>
<li>1 ≤ <var>n</var> ≤ 100</li>
<li>1 ≤ <var>a<sub>i</sub></var> ≤ <var>b<sub>i</sub></var> ≤ 31 (1 ≤ <var>i</var> ≤ <var>n</var>)</li>
</ul>
<h2>Output</h2>
<p>
倪éåã®åŸããã幞çŠåºŠã®åèšå€ã®æå€§å€ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4
1 31
2 2
2 3
3 3
</pre>
<h2>Sample Output 1</h2>
<pre>
1700
</pre>
<h2>Sample Input 2</h2>
<pre>
5
1 10
10 20
20 21
22 31
4 20
</pre>
<h2>Sample Output 2</h2>
<pre>
1800
</pre> |
p03595 | <span class="lang-en">
<p>Score : <var>1600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Ringo got interested in modern art. He decided to draw a big picture on the board with <var>N+2</var> rows and <var>M+2</var> columns of squares constructed in the venue of CODE FESTIVAL 2017, using some people.</p>
<p>The square at the <var>(i+1)</var>-th row and <var>(j+1)</var>-th column in the board is represented by the pair of integers <var>(i,j)</var>. That is, the top-left square is <var>(0,0)</var>, and the bottom-right square is <var>(N+1,M+1)</var>.
Initially, the squares <var>(x,y)</var> satisfying <var>1 \leq x \leq N</var> and <var>1 \leq y \leq M</var> are painted white, and the other (outermost) squares are painted black.</p>
<p>Ringo arranged people at some of the outermost squares, facing inward.
More specifically, the arrangement of people is represented by four strings <var>A</var>, <var>B</var>, <var>C</var> and <var>D</var>, as follows:</p>
<ul>
<li>For each row except the top and bottom, if the <var>i</var>-th character <var>(1 \leq i \leq N)</var> in <var>A</var> is <code>1</code>, place a person facing right at the square <var>(i,0)</var>; otherwise, do nothing.</li>
<li>For each row except the top and bottom, if the <var>i</var>-th character <var>(1 \leq i \leq N)</var> in <var>B</var> is <code>1</code>, place a person facing left at the square <var>(i,M+1)</var>; otherwise, do nothing.</li>
<li>For each column except the leftmost and rightmost, if the <var>i</var>-th character <var>(1 \leq i \leq M)</var> in <var>C</var> is <code>1</code>, place a person facing down at the square <var>(0,i)</var>; otherwise, do nothing.</li>
<li>For each column except the leftmost and rightmost, if the <var>i</var>-th character <var>(1 \leq i \leq M)</var> in <var>D</var> is <code>1</code>, place a person facing up at the square <var>(N+1,i)</var>; otherwise, do nothing.</li>
</ul>
<p>Each person has a sufficient amount of non-white paint. No two people have paint of the same color.</p>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/code-festival-2017-quala/46a627606452b904221672922d269290.png">
<p>An example of an arrangement of people (For convenience, black squares are displayed in gray)</p>
</img></div>
<p>Ringo repeats the following sequence of operations until all people are dismissed from the venue.</p>
<ul>
<li>Select a person who is still in the venue.</li>
<li>The selected person repeats the following action while the square in front of him/her is white: move one square forward, and paint the square he/she enters with his/her paint. When the square in front of him/her is not white, he/she stops doing the action.</li>
<li>The person is now dismissed from the venue.</li>
</ul>
<div style="text-align: center;">
<img src="https://atcoder.jp/img/code-festival-2017-quala/406bcaf4d52da2ae3b09eedf63ff302e.png">
<p>An example of a way the board is painted</p>
</img></div>
<p>How many different states of the board can Ringo obtain at the end of the process? Find the count modulo <var>998244353</var>.</p>
<p>Two states of the board are considered different when there is a square painted in different colors.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N,M \leq 10^5</var></li>
<li><var>|A|=|B|=N</var></li>
<li><var>|C|=|D|=M</var></li>
<li><var>A</var>, <var>B</var>, <var>C</var> and <var>D</var> consist of <code>0</code> and <code>1</code>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>A</var>
<var>B</var>
<var>C</var>
<var>D</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of the different states of the board Ringo can obtain at the end of the process, modulo <var>998244353</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 2
10
01
10
01
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>6
</pre>
<p>There are six possible states as shown below.</p>
<p><img alt="" src="https://atcoder.jp/img/code-festival-2017-quala/1dd467cdff8a517c9555abfca0915e2e.png"/></p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>2 2
11
11
11
11
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>32
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 4
111
111
1111
1111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1276
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>17 21
11001010101011101
11001010011010111
111010101110101111100
011010110110101000111
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>548356548
</pre>
<p>Be sure to find the count modulo <var>998244353</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>3 4
000
101
1111
0010
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>21
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>9 13
111100001
010101011
0000000000000
1010111111101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>177856
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 7</h3><pre>23 30
01010010101010010001110
11010100100100101010101
000101001001010010101010101101
101001000100101001010010101000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 7</h3><pre>734524988
</pre></section>
</div>
</span> |
p02557 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given are two sequences <var>A</var> and <var>B</var>, both of length <var>N</var>.
<var>A</var> and <var>B</var> are each sorted in the ascending order.
Check if it is possible to reorder the terms of <var>B</var> so that for each <var>i</var> (<var>1 \leq i \leq N</var>) <var>A_i \neq B_i</var> holds, and if it is possible, output any of the reorderings that achieve it.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1\leq N \leq 2 \times 10^5</var></li>
<li><var>1\leq A_i,B_i \leq N</var></li>
<li><var>A</var> and <var>B</var> are each sorted in the ascending order.</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>\cdots</var> <var>A_N</var>
<var>B_1</var> <var>B_2</var> <var>\cdots</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If there exist no reorderings that satisfy the condition, print <code>No</code>.</p>
<p>If there exists a reordering that satisfies the condition, print <code>Yes</code> on the first line.
After that, print a reordering of <var>B</var> on the second line, separating terms with a whitespace.</p>
<p>If there are multiple reorderings that satisfy the condition, you can print any of them.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>6
1 1 1 2 2 3
1 1 1 2 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>Yes
2 2 3 1 1 1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3
1 1 2
1 1 3
</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>4
1 1 2 3
1 2 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>Yes
3 3 1 2
</pre></section>
</div>
</span> |
p00090 |
<H1>ã·ãŒã«ã®éãªã</H1>
<p>
1 蟺ã®é·ãã 10 ã®æ£æ¹åœ¢ã®æãçŽã«ååŸ 1 ã®å圢ã®ã·ãŒã«ã <var>n</var> æè²ŒããŸããã·ãŒã«ã¯éããŠè²Œãããšãã§ããŸããã·ãŒã«ã貌ãäœçœ®ã®åº§æšãèªã¿èŸŒãã§ãæãçŽäžã§ãã£ãšãå€ãã·ãŒã«ãéãªã£ãŠããå Žæ(ã·ãŒã«ãïŒæã ãã§ã"éãªã£ãŠãã"ãšãã)ã§ã®ã·ãŒã«ã®ææ°ãåºåããããã°ã©ã ãäœæããŠãã ããã
</p>
<p>æãçŽã®å·Šäžãåç¹ãšãã <var>x, y</var> 座æšãäžããŸãããã® <var>x, y</var> ãåã®äžå¿ãšããŠã·ãŒã«ã貌ãããšãšããŸããåã®äžå¿ãæãçŽã®å€ã«åºãããšã¯ãããŸããããŸããåäžåº§æšã«è€æ°ã®ã·ãŒã«ã貌ãããããšã¯ãããŸããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããŸãã
</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>
ïŒè¡ç®ã«ã·ãŒã«ã®ææ° <var>n</var> (0 ≤ 100) ãäžããããŸããç¶ã <var>n</var> è¡ã«ãåã·ãŒã«ã®äžå¿åº§æšãäžããããŸãã
<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> 㯠<var>i</var> æç®ã®ã·ãŒã«ã®äžå¿ã® <var>x</var> 座æšãš <var>y</var> 座æšã衚ããŸããåå€ã¯å°æ°ç¹ä»¥äžæå€§ 6 æ¡ãŸã§ã®æ°åãå«ã宿°ã§äžããããŸãã
</p>
<p>
<var>n</var> ã 0 ã®ãšããå
¥åã®æåŸãšããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
åããŒã¿ã»ããã«å¯ŸããæãçŽäžã§æãå€ãã·ãŒã«ãéãªã£ãŠããå Žæã§ã®ã·ãŒã«ã®ææ°ïŒæŽæ°ïŒãåºåããŠäžããã
</p>
<H2>Sample Input</H2>
<pre>
15
3.14979,8.51743
2.39506,3.84915
2.68432,5.39095
5.61904,9.16332
7.85653,4.75593
2.84021,5.41511
1.79500,8.59211
7.55389,8.17604
4.70665,4.66125
1.63470,4.42538
7.34959,4.61981
5.09003,8.11122
5.24373,1.30066
0.13517,1.83659
7.57313,1.58150
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
</pre>
<H2>Hint</H2>
<p>
å
¥åäŸã®ããã«ã·ãŒã«ã貌ã£ãå³ã§ããåã¯ã·ãŒã«ãæ°åã¯å
¥åäŸã®è¡æ°ã衚ããŠããŸãã
ç¹(2.3,4.6)ã§ã¯ãå
¥åäŸã® 2 è¡ç®ã3 è¡ç®ã6 è¡ç®ã10 è¡ç®ã® 4 æã®ã·ãŒã«ãéãªã£ãŠããŸãã
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_18_1">
</center>
<p>
6 ãš 9 ã®ãã®ãã®ã®äžå¿ã®è·é¢ã¯ 2.01293 ãªã®ã§ãã·ãŒã«ã¯éãªã£ãŠããŸããã1 ãš 12 ã®ãã®ãã®ã®äžå¿ã®è·é¢ã¯ 1.98231 ãªã®ã§ãã·ãŒã«ã¯éãªã£ãŠããŸãã
</p>
<p>
ïŒã€ã®åãæ¥ããŠãããšãïŒãã®ãã®ã®äžå¿ã®è·é¢ã 2 ã®ãšãïŒã¯ãéãªã£ãŠãããã®ãšããŸããã
</p>
|
p02107 |
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h1>Problem J: Demon's Plan</h1>
<h2>BackGround</h2>
<p>
ããŒã¢ã³ãºãã©ã³ã§ã¯æ
Ÿãåžã108äœã®æªéãæ¥å€ããã°ã©ãã³ã°ã³ã³ãã¹ãã§ãã®ããåã£ãŠãããäž»å¬ã§ããããããŒã³ã¯ãå
šãŠã®æ
Ÿãéãå Žæâãªã¯ã¹ïŒãã°ãâã«æªéãã¡ãæåŸ
ããããšããŠããã
ããããŒã³ã¯ãŸã æåŸ
ãéã£ãŠããªãæªéã«æåŸ
ãéãããããæªéã¯äžçåå°ã«ãããèªåã§è¡ãã®ã¯é¢åãããã®ã§èªèº«ã®äœ¿ãééã«ããããããšã«ããã
ããããŒã³ã¯æ°ãå©ãã®ã§äœ¿ãéå士ãããå¹³çã«åãããã«ã©ã®äœ¿ãéãã©ã®æªéãæ
åœããããå²ãæ¯ãããšããŠããã
</p>
<h2>Problem</h2>
<p>
<var>N</var>äœã®äœ¿ãéãš<var>M</var>äœã®æªéãããã
䜿ãé<sub><var>i</var></sub> ãš æªé<sub><var>j</var></sub> ã®è·é¢ã¯ <var>H<sub>i j</sub></var>ã§ããã
</p>
<p>
åæªéã«å¿
ã1人ã®äœ¿ãéãåããããããã©ã®äœ¿ãéãã©ã®æªéã蚪åãããã¯ä»¥äžã®æ¡ä»¶ã«åŸã£ãŠå²ãæ¯ãããšã«ããã
</p>
<ol>
<li>䜿ãé1äœãããã®èšªåããæªéã®æ°ã®å·®ã®æå€§ãæå°åããã</li>
<li>1ãæºãããäžã§èšªåããæªéãšæ
åœãã䜿ãéã®è·é¢ã®æå€§ãæå°åããã</li>
</ol>
<p>
1è¡ç®ã«äœ¿ãé1äœãããã®èšªåããæªéã®æ°ã®å·®ã®æå€§ãã2è¡ç®ã«æªéãšæ
åœãã䜿ãéã®è·é¢ã®æå€§ãåºåããã
</p>
<h2>Input</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>N</var> <var>M</var>
<var>H<sub>0 0</sub></var> <var>H<sub>0 1</sub></var> ⊠<var>H<sub>0 M−1</sub></var>
<var>H<sub>1 0</sub></var> <var>H<sub>1 1</sub></var> ⊠<var>H<sub>1 M−1</sub></var>
.
.
<var>H<sub>N−1 0</sub></var> <var>H<sub>N−1 1</sub></var> ⊠<var>H<sub>N−1 M−1</sub></var>
</pre>
<p>
1è¡ç®ã«äœ¿ãéã®æ°<var>N</var>ãšæªéã®æ°<var>M</var>ãæŽæ°ã§ç©ºçœåºåãã§äžããããã
ç¶ã<var>N</var>è¡ã«äœ¿ãéãšæªéã®è·é¢ãæŽæ°ã§äžããããã<var>H<sub>ij</sub></var>ã¯äœ¿ãé<sub>i</sub>ãšæªé<sub>j</sub>ã®è·é¢ã衚ãã
</p>
<h2>Constraints</h2>
<ul>
<li>
1 ≤ <var>N</var> ≤ 108
</li>
<li>
1 ≤ <var>M</var> ≤ 108
</li>
<li>
1 ≤ <var>H<sub>i j</sub></var> ≤ 10<sup>9</sup> ( 0 ≤ <var>i</var> < <var>N</var>, 0 ≤ <var>j</var> < <var>M</var> ) ( 䜿ãé<var>i</var>ããæªé<var>j</var>ãŸã§ã®è·é¢ )
</li>
</ul>
<h2>Output</h2>
<p>
åé¡æã®æ¡ä»¶ã«åŸãã1è¡ç®ã«äœ¿ãé1äœãããã®èšªåããæªéã®æ°ã®å·®ã®æå€§ãã2è¡ç®ã«æªéãšæ
åœãã䜿ãéã®è·é¢ã®æå€§ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 3
1 2 3
2 1 2
3 2 1
</pre>
<h2>Sample Output 1</h2>
<pre>
0
1
</pre>
<p>
䜿ãé<sub>0</sub> - æªé<sub>0</sub> <br />
䜿ãé<sub>1</sub> - æªé<sub>1</sub> <br />
䜿ãé<sub>2</sub> - æªé<sub>2</sub> <br />
ãšå²ãæ¯ãããšã§èšªåããæªéã®æ°ã®å·®ã0ã«ãªããæ
åœäœ¿ãéãšæªéã®è·é¢ã®æå€§ã1ã«ãªãæé©ãªçµã¿åããã«ãªãã
</p>
<h2>Sample Input 2</h2>
<pre>
3 5
1 2 3 4 5
5 4 3 2 1
4 3 2 1 5
</pre>
<h2>Sample Output 2</h2>
<pre>
1
2
</pre>
<p>
䜿ãé<sub>0</sub> - æªé<sub>0</sub> <br />
䜿ãé<sub>0</sub> - æªé<sub>1</sub> <br />
䜿ãé<sub>1</sub> - æªé<sub>4</sub> <br />
䜿ãé<sub>2</sub> - æªé<sub>3</sub> <br />
䜿ãé<sub>2</sub> - æªé<sub>2</sub> <br />
ãšå²ãæ¯ãããšã§èšªåããæªéã®å·®ã1ã«ãªããæ
åœäœ¿ãéãšæªéã®è·é¢ã®æå€§ã2ã«ãªãæé©ãªçµã¿åããã«ãªãã
</p> |
p03346 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence <var>(P_1,P_2,...,P_N)</var> which is a permutation of the integers from <var>1</var> through <var>N</var>.
You would like to sort this sequence in ascending order by repeating the following operation:</p>
<ul>
<li>Choose an element in the sequence and move it to the beginning or the end of the sequence.</li>
</ul>
<p>Find the minimum number of operations required.
It can be proved that it is actually possible to sort the sequence using this operation.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2\times 10^5</var></li>
<li><var>(P_1,P_2,...,P_N)</var> is a permutation of <var>(1,2,...,N)</var>.</li>
<li>All values in input are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>P_1</var>
<var>:</var>
<var>P_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1
3
2
4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, the sequence can be sorted in ascending order as follows:</p>
<ul>
<li>Move <var>2</var> to the beginning. The sequence is now <var>(2,1,3,4)</var>.</li>
<li>Move <var>1</var> to the beginning. The sequence is now <var>(1,2,3,4)</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6
3
2
5
1
4
6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>4
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>8
6
3
1
2
7
4
8
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre></section>
</div>
</span> |
p00993 |
<H1>Problem D : Numbers </H1>
<p>
<i>n</i> ãäžããããã®ã§ã<i>n</i> åã®é£ç¶ããæ£ã®æŽæ°ãæ±ããã
ãã ããã¹ãŠã®æ°ããïŒãšãã®æ°èªèº«ä»¥å€ã®çŽæ°ããããªããŠã¯ãªããªãã
</p>
<H2>Input</H2>
<p>
å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã
</p>
<pre>
<i>n</i>
</pre>
<p>
å
¥åã¯ä»¥äžã®å¶çŽãæºããã<br>
1 ≤ <i>n</i> ≤ 1,500
</p>
<h2>Output</h2>
<p>
æåã®è¡ã«ãããªããéžãã é£ç¶ãã<i>n</i> åã®æ£ã®æŽæ°ã®äžã§äžçªå°ãããã®ãåºåããã<br>
2è¡ç®ãã<i>n+1</i> è¡ç®ã«ãããããã®å€ã«å¯ŸããçŽæ°ãåºåããã<br>
çŽæ°ã¯1ããã®æ°èªèº«ã§ãªããã°ã©ã®å€ãåºåããŠãè¯ãã<br>
1è¡ç®ã«åºåããæ°ã<i>x</i>ãšããŠãiè¡ç®ã«ã¯ <i>x+i-2</i> ã®çŽæ°ãåºåããã<br>
<br>
åºåããå€ã¯5,000æ¡ãè¶
ããŠã¯ãããªãã<br>
</p>
<h2>Sample Input 1</h2>
<pre>
2
</pre>
<h2>Sample Output 1</h2>
<pre>
8
2
3
</pre>
<h2>Sample Input 2</h2>
<pre>
3
</pre>
<h2>Sample Output 2</h2>
<pre>
8
2
3
5
</pre>
<h2>Hint</h2>
<p>
Sample Output 2ã§ã¯ã8,9,10ã3åã®é£ç¶ããæŽæ°ãšããŠéžãã§ããã<br>
2è¡ç®ã«ã8ã®çŽæ°ãšããŠ2,3è¡ç®ã¯9ã®çŽæ°ãšããŠ3,ïŒè¡ç®ã«ã¯10ã®çŽæ°ãšããŠ5,ãåºåããŠããã<br>
<p>
|
p01681 |
<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>Fox Ciel is practicing miniature golf, a golf game played with a putter club only. For improving golf skills, she believes it is important how well she bounces the ball against walls.
</p>
<p>The field of miniature golf is in a two-dimensional plane and surrounded by $N$ walls forming a convex polygon. At first, the ball is placed at $(s_x, s_y)$ inside the field. The ball is small enough to be regarded as a point.
</p>
<p>Ciel can shoot the ball to any direction and stop the ball whenever she wants. The ball will move in a straight line. When the ball hits the wall, it rebounds like mirror reflection (i.e. incidence angle equals reflection angle).
</p>
<p>For practice, Ciel decided to make a single shot under the following conditions:
</p><ul><li><p> The ball hits each wall of the field exactly once.
</p></li><li><p> The ball does NOT hit the corner of the field.
</p></li></ul>
<p>Count the number of possible orders in which the ball hits the walls.
</p>
<h3>Input</h3>
<p>The input contains several datasets. The number of datasets does not exceed $100$. Each dataset is in the following format.
</p>
<blockquote>$N$<br>$s_x$ $s_y$<br>$x_1$ $y_1$<br>:<br>:<br>$x_N$ $y_N$</blockquote>
<p>The first line contains an integer $N$ ($3 \leq N \leq 8$). The next line contains two integers $s_x$ and $s_y$ ($-50 \leq s_x, s_y \leq 50$), which describe the coordinates of the initial position of the ball. Each of the following $N$ lines contains two integers $x_i$ and $y_i$ ($-50 \leq x_i, y_i \leq 50$), which describe the coordinates of each corner of the field. The corners are given in counterclockwise order. You may assume given initial position $(s_x, s_y)$ is inside the field and the field is convex.
</p>
<p>It is guaranteed that there exists a shoot direction for each valid order of the walls that satisfies the following condition: distance between the ball and the corners of the field $(x_i, y_i)$ is always greater than $10^{-6}$ until the ball hits the last wall.
</p>
<p>The last dataset is followed by a line containing a single zero.
</p>
<h3>Output</h3>
<p>For each dataset in the input, print the number of valid orders of the walls in a line.
</p>
<h3>Sample Input</h3>
<pre>4
0 0
-10 -10
10 -10
10 10
-10 10
0</pre>
<h3>Output for the Sample Input</h3>
<pre>8</pre> |
p02804 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>For a finite set of integers <var>X</var>, let <var>f(X)=\max X - \min X</var>.</p>
<p>Given are <var>N</var> integers <var>A_1,...,A_N</var>.</p>
<p>We will choose <var>K</var> of them and let <var>S</var> be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are <var>{}_N C_K</var> ways to make this choice. Find the sum of <var>f(S)</var> over all those ways.</p>
<p>Since the answer can be enormous, print it <var>\bmod (10^9+7)</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq K \leq N</var></li>
<li><var>|A_i| \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>K</var>
<var>A_1</var> <var>...</var> <var>A_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer <var>\bmod (10^9+7)</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4 2
1 1 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>11
</pre>
<p>There are six ways to choose <var>S</var>: <var>\{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\}</var> (we distinguish the two <var>1</var>s). The value of <var>f(S)</var> for these choices are <var>0,2,3,2,3,1</var>, respectively, for the total of <var>11</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>6 3
10 10 10 -10 -10 -10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>360
</pre>
<p>There are <var>20</var> ways to choose <var>S</var>. In <var>18</var> of them, <var>f(S)=20</var>, and in <var>2</var> of them, <var>f(S)=0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 1
1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>999998537
</pre>
<p>Print the sum <var>\bmod (10^9+7)</var>.</p></section>
</div>
</span> |
p00839 |
<H1><font color="#000">Problem D:</font> Organize Your Train</H1>
<p>
In the good old Hachioji railroad station located in the west of Tokyo, there are several parking
lines, and lots of freight trains come and go every day.
</p>
<p>
All freight trains travel at night, so these trains containing various types of cars are settled in
your parking lines early in the morning. Then, during the daytime, you must reorganize cars
in these trains according to the request of the railroad clients, so that every line contains the
ârightâ train, i.e. the right number of cars of the right types, in the right order.
</p>
<p>
As shown in Figure 7, all parking lines run in the East-West direction. There are exchange
lines connecting them through which you can move cars. An exchange line connects two ends
of different parking lines. Note that an end of a parking line can be connected to many ends of
other lines. Also note that an exchange line may connect the East-end of a parking line and the
West-end of another.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_organizeYourTrain1">
</center>
<p>
Cars of the same type are not discriminated between each other. The cars are symmetric, so
directions of cars donât matter either.
</p>
<p>
You can divide a train at an arbitrary position to make two sub-trains and move one of them
through an exchange line connected to the end of its side. Alternatively, you may move a whole
train as is without dividing it. Anyway, when a (sub-) train arrives at the destination parking
line and the line already has another train in it, they are coupled to form a longer train.
</p>
<p>
Your superautomatic train organization system can do these without any help of locomotive
engines. Due to the limitation of the system, trains cannot stay on exchange lines; when you
start moving a (sub-) train, it must arrive at the destination parking line before moving another
train.
</p>
<p>
In what follows, a letter represents a car type and a train is expressed as a sequence of letters.
For example in Figure 8, from an initial state having a train "<span>aabbccdee</span>"
on line 0 and no trains
on other lines, you can make "<span>bbaadeecc</span>" on line 2 with the four moves shown in the figure.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_organizeYourTrain2">
</center>
<p>
To cut the cost out, your boss wants to minimize the number of (sub-) train movements. For
example, in the case of Figure 8, the number of movements is 4 and this is the minimum.
</p>
<p>
Given the configurations of the train cars in the morning (arrival state) and evening (departure
state), your job is to write a program to find the optimal train reconfiguration plan.
</p>
<H2>Input</H2>
<p>
The input consists of one or more datasets. A dataset has the following format:
</p>
<pre>
<i>x y</i>
<i>p</i><sub>1</sub> <i>P</i><sub>1</sub> <i>q</i><sub>1</sub> <i>Q</i><sub>1</sub>
<i>p</i><sub>2</sub> <i>P</i><sub>2</sub> <i>q</i><sub>2</sub> <i>Q</i><sub>2</sub>
.
.
.
<i>p</i><sub><i>y</i></sub> <i>P</i><sub><i>y</i></sub> <i>q</i><sub><i>y</i></sub> <i>Q</i><sub><i>y</i></sub>
<i>s</i><sub>0</sub>
<i>s</i><sub>1</sub>
.
.
.
<i>s</i><sub><i>x</i>-1</sub>
<i>t</i><sub>0</sub>
<i>t</i><sub>1</sub>
.
.
.
<i>t</i><sub><i>x</i>-1</sub>
</pre>
<p>
<i>x</i> is the number of parking lines, which are numbered from 0 to <i>x</i>-1. <i>y</i> is the number of exchange
lines. Then <i>y</i> lines of the exchange line data follow, each describing two ends connected by the
exchange line; <i>p</i><sub><i>i</i></sub> and <i>q</i><sub><i>i</i></sub> are integers between 0 and <i>x</i> - 1 which indicate parking line numbers,
and <i>P<sub>i</sub></i> and <i>Q<sub>i</sub></i> are either "<span>E</span>" (East) or "<span>W</span>" (West) which indicate the ends of the parking lines.
</p>
<p>
Then <i>x</i> lines of the arrival (initial) configuration data, <i>s</i><sub>0</sub>, ... , <i>s</i><sub><i>x</i>-1</sub>, and <i>x</i> lines of the departure
(target) configuration data, <i>t</i><sub>0</sub>, ... <i>t</i><sub><i>x</i>-1</sub>, follow. Each of these lines contains one or more lowercase letters "<span>a</span>", "<span>b</span>", ..., "<span>z</span>", which indicate types of cars of the train in the corresponding parking
line, in west to east order, or alternatively, a single "<span>-</span>" when the parking line is empty.
</p>
<p>
You may assume that x does not exceed 4, the total number of cars contained in all the trains
does not exceed 10, and every parking line has sufficient length to park all the cars.
</p>
<p>
You may also assume that each dataset has at least one solution and that the minimum number
of moves is between one and six, inclusive.
</p>
<p>
Two zeros in a line indicate the end of the input.
</p>
<H2>Output</H2>
<p>
For each dataset, output the number of moves for an optimal reconfiguration plan, in a separate
line.
</p>
<H2>Sample Input</H2>
<pre>
3 5
0W 1W
0W 2W
0W 2E
0E 1E
1E 2E
aabbccdee
-
-
-
-
bbaadeecc
3 3
0E 1W
1E 2W
2E 0W
aabb
bbcc
aa
bbbb
cc
aaaa
3 4
0E 1W
0E 2E
1E 2W
2E 0W
ababab
-
-
aaabbb
-
-
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
2
5
</pre>
|
p03716 | <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Let <var>N</var> be a positive integer.</p>
<p>There is a numerical sequence of length <var>3N</var>, <var>a = (a_1, a_2, ..., a_{3N})</var>.
Snuke is constructing a new sequence of length <var>2N</var>, <var>a'</var>, by removing exactly <var>N</var> elements from <var>a</var> without changing the order of the remaining elements.
Here, the score of <var>a'</var> is defined as follows: <var>(</var>the sum of the elements in the first half of <var>a') - (</var>the sum of the elements in the second half of <var>a')</var>.</p>
<p>Find the maximum possible score of <var>a'</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 †N †10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 †a_i †10^9</var></li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Score</h3><ul>
<li>In the test set worth <var>300</var> points, <var>N †1000</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_{3N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible score of <var>a'</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
3 1 4 1 5 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>When <var>a_2</var> and <var>a_6</var> are removed, <var>a'</var> will be <var>(3, 4, 1, 5)</var>, which has a score of <var>(3 + 4) - (1 + 5) = 1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
1 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>For example, when <var>a_1</var> are removed, <var>a'</var> will be <var>(2, 3)</var>, which has a score of <var>2 - 3 = -1</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3
8 2 2 7 4 6 5 3 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>5
</pre>
<p>For example, when <var>a_2</var>, <var>a_3</var> and <var>a_9</var> are removed, <var>a'</var> will be <var>(8, 7, 4, 6, 5, 3)</var>, which has a score of <var>(8 + 7 + 4) - (6 + 5 + 3) = 5</var>.</p></section>
</div>
</span> |
p03203 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi and Aoki will play a game using a grid with <var>H</var> rows and <var>W</var> columns of square cells.
There are <var>N</var> obstacles on this grid; the <var>i</var>-th obstacle is at <var>(X_i,Y_i)</var>.
Here, we represent the cell at the <var>i</var>-th row and <var>j</var>-th column <var>(1 \leq i \leq H, 1 \leq j \leq W)</var> by <var>(i,j)</var>.
There is no obstacle at <var>(1,1)</var>, and there is a piece placed there at <var>(1,1)</var>.</p>
<p>Starting from Takahashi, he and Aoki alternately perform one of the following actions:</p>
<ul>
<li>Move the piece to an adjacent cell.
Here, let the position of the piece be <var>(x,y)</var>. Then Takahashi can only move the piece to <var>(x+1,y)</var>, and Aoki can only move the piece to <var>(x,y+1)</var>.
If the destination cell does not exist or it is occupied by an obstacle, this action cannot be taken.</li>
<li>Do not move the piece, and end his turn without affecting the grid.</li>
</ul>
<p>The game ends when the piece does not move twice in a row.</p>
<p>Takahashi would like to perform as many actions (including not moving the piece) as possible before the game ends, while Aoki would like to perform as few actions as possible before the game ends.
How many actions will Takahashi end up performing?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H,W \leq 2\times 10^5</var></li>
<li><var>0 \leq N \leq 2\times 10^5</var></li>
<li><var>1 \leq X_i \leq H</var></li>
<li><var>1 \leq Y_i \leq W</var></li>
<li>If <var>i \neq j</var>, <var>(X_i,Y_i) \neq (X_j,Y_j)</var></li>
<li><var>(X_i,Y_i) \neq (1,1)</var></li>
<li><var>X_i</var> and <var>Y_i</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>N</var>
<var>X_1</var> <var>Y_1</var>
<var>:</var>
<var>X_N</var> <var>Y_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of actions Takahashi will end up performing.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 3 1
3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>For example, the game proceeds as follows:</p>
<ul>
<li>Takahashi moves the piece to (2,1).</li>
<li>Aoki does not move the piece.</li>
<li>Takahashi moves the piece to (3,1).</li>
<li>Aoki does not move the piece.</li>
<li>Takahashi does not move the piece.</li>
</ul>
<p>Takahashi performs three actions in this case, but if both players play optimally, Takahashi will perform only two actions before the game ends.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 10 14
4 3
2 2
7 3
9 10
7 7
8 1
10 10
5 4
3 4
2 8
6 4
4 4
5 8
9 2
</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>100000 100000 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>100000
</pre></section>
</div>
</span> |
p01394 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<h1><font color="#000">åé¡ G </font> XOR åè·¯</h1>
<h2>å顿</h2>
<p>
<a href="http://www.t.kyoto-u.ac.jp/syllabus-s/?mode=subject&lang=ja&year=2011&b=5&c=90840">èšç®æ©ç§åŠå®éšåæŒç¿ 3</a> 㯠CAD ãçšã㊠CPU ãèšèšããææ¥ã§ããïŒCPU ã¯å€ãã®åè·¯ãçµã¿åãããªããã°åããïŒãã®äžã® 1 ã€ã« <var>n</var> ãããå
¥åã® XOR åè·¯ãããïŒããã§ XOR åè·¯ãšã¯ïŒå
¥åãããå <var>x<sub>1</sub>x<sub>2</sub>...x<sub>n</sub></var> ã«å¯ŸããŠïŒ<var>x<sub>1</sub> + x<sub>2</sub> + ... + x<sub>n</sub>\ (mod 2)</var> ãåºåããåè·¯ã®ããšãèšãïŒãããå®ç§ã«åäœãã XOR åè·¯ãèšèšããã®ã¯æéããããã®ã§ïŒãšãããã <var>n</var> ãããã®ãã¡ <var>k</var> ãããã ã䜿ã XOR åè·¯ A ãäœãããšã«ããïŒã€ãŸãïŒãã <var>i<sub>1</sub>, ... , i<sub>k</sub></var> ãååšãïŒåè·¯ A 㯠<var>x<sub>i<sub>1</sub></sub> + x<sub>i<sub>2</sub></sub> + ... + x<sub>i<sub>k</sub></sub>\ (mod 2)</var>ãåºåããïŒ
</p>
<p>
æ«ãåŸã«ä»åºŠã¯ <var>k</var> ãããå
¥åã® XOR åè·¯ãæ¬²ãããªã£ãïŒäœã ç°¡åã§ã¯ãªããïŒå
ã»ã©ã®åè·¯ A ã䜿ãã°ããïŒãã æ®å¿µãªããšã«ïŒåè·¯ A ãã©ã® <var>k</var> ãããã䜿ã£ãŠããã®ãå¿ããŠããŸã£ãäžã«ïŒåè·¯ A ã®èšèšå³ãééã£ãŠåé€ããŠããŸã£ãïŒãããã³ã³ãã€ã«æžã¿ã®åè·¯ A ã¯æ®ã£ãŠããïŒãªã®ã§ïŒå
¥å <var>x<sub>1</sub>x<sub>2</sub>...x<sub>n</sub></var> ãå
¥ããŠåè·¯ A ãå®è¡ããããšã§ïŒãã®åºå <var>x<sub>i<sub>1</sub></sub> + x<sub>i<sub>2</sub></sub> + ... + x<sub>i<sub>k</sub></sub>\ (mod 2)</var> ãèŠãããšã¯åºæ¥ãïŒ
åºæ¥ãã ãäœæ¥ã®æéãçããããã®ã§ïŒåè·¯ A ã®å®è¡åæ°ã«ã¯äžéãèšå®ããããšã«ãããïŒã©ãããã°åè·¯AãäŸåããŠããããã <var>i<sub>1</sub>, ... , i<sub>k</sub></var> ãèŠã€ããããã ãããïŒ
</p>
<h2>å
¥åºå</h2>
<p>
æåã« <var>n</var> ãš <var>k</var> ãã¹ããŒã¹åºåãã§äžããããïŒä»¥éïŒããã°ã©ã ã¯åè·¯ A ã«å
¥åãäžãïŒãã®åºåãèªãããšãåºæ¥ãïŒäŸãã° C/C++ ã§åè·¯ A ã«ãããå <var>x<sub>1</sub>x<sub>2</sub>...x<sub>n</sub></var> ãäžããã«ã¯
<pre>printf("?<var>x<sub>1</sub>x<sub>2</sub>...x<sub>n</sub></var>\n"); fflush(stdout);</pre>
ãšããïŒããã§å <var>x<sub>i</sub></var> ã®éã«ã¹ããŒã¹ããããŠã¯ãªããªãïŒ
次ã«ïŒ
<pre>scanf("%d", &v);</pre>
ãšãããš <var>v</var> ã«å¯Ÿå¿ããåºå <var>x<sub>i<sub>1</sub></sub> + x<sub>i<sub>2</sub></sub> + ... + x<sub>i<sub>k</sub></sub>\ (mod 2)</var> ãå
¥ãïŒ
æçµçã«åè·¯ A ãäŸåããããã <var>i<sub>1</sub>,...,i<sub>k</sub></var> ãåºåããã«ã¯
<pre>printf("!<var>i<sub>1</sub> i<sub>2</sub> ...i<sub>k</sub></var>\n"); fflush(stdout);</pre>
ãšããïŒããã§å <var>i<sub>j</sub></var> ã®éã¯ã¹ããŒã¹ãäžåºŠ 1 ã€ãã€ãããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li><var>1 ≤ n ≤ 10,000</var></li>
<li><var>1 ≤ k ≤ min(10, n)</var></li>
<li>åããŒã¿ã»ããããšã«ïŒåè·¯ A ã®å®è¡åæ°ã®äžé㯠200 åã§ããïŒãããè¶
ãããšèª€ç (<i>Query Limit Exceeded</i>) ãšå€å®ãããïŒ</li>
</ul>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<p>
以äžã®äŸã¯ããã°ã©ã ã®å
¥åºåã®äŸã§ããïŒå·Šã®åã¯ããã°ã©ã ã®åºåïŒå³ã®åã¯ããã°ã©ã ãžã®å
¥åãæç³»åé ã«ç€ºããŠããïŒæåã« <var>n k</var> ãå
¥åãšããŠäžããããïŒããã§ã¯ <var>n = 2, k = 1</var> ã§ããïŒæ¬¡ã«åè·¯ A ã« <tt>00</tt> ãšããå
¥åãããããšïŒåè·¯ A 㯠<var>0</var> ãè¿ããïŒæ¬¡ã«åè·¯ A ã« <tt>01</tt> ãšããå
¥åãããããšïŒåè·¯ A ã¯åã³ <var>0</var> ãè¿ããïŒãã®ããšããåè·¯ A 㯠<var>1</var> ãããç®ã®ã¿å©çšããŠããããšãåããïŒããã°ã©ã 㯠<var>1</var> ãè§£çãšããŠåºåããïŒ
</p>
<div class="reactive-example">
<table class="withborder">
<tr><th>ããã°ã©ã ã®åºå</th><th>ããã°ã©ã ãžã®å
¥å</th></tr>
<tr><td></td><td>2 1</td></tr>
<tr><td>?00</td><td></td></tr>
<tr><td></td><td>0</td></tr>
<tr><td>?01</td><td></td></tr>
<tr><td></td><td>0</td></tr>
<tr><td>!1</td><td></td></tr>
</table>
</div>
<br>
<h3>å
¥åäŸ 2</h3>
<p>
以äžã®äŸã§ã¯ïŒ<var>n = 2, k = 2</var> ã§ããïŒçŽã¡ã«åè·¯ A ã <var>1</var> ãããç®ãš <var>2</var> ãããç®ã®äž¡æ¹ãå©çšããŠããããšãåããïŒãã£ãŠããã°ã©ã 㯠<var>1</var> ãš <var>2</var> ãè§£çãšããŠåºåããïŒ
</p>
<div class="reactive-example">
<table class="withborder">
<tr><th>ããã°ã©ã ã®åºå</th><th>ããã°ã©ã ãžã®å
¥å</th></tr>
<tr><td></td><td>2 2</td></tr>
<tr><td>!1 2</td><td></td></tr>
</table>
</div>
<br>
|
p02941 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>N</var> positive integers arranged in a circle.</p>
<p>Now, the <var>i</var>-th number is <var>A_i</var>. Takahashi wants the <var>i</var>-th number to be <var>B_i</var>. For this objective, he will repeatedly perform the following operation:</p>
<ul>
<li>Choose an integer <var>i</var> such that <var>1 \leq i \leq N</var>.</li>
<li>Let <var>a, b, c</var> be the <var>(i-1)</var>-th, <var>i</var>-th, and <var>(i+1)</var>-th numbers, respectively. Replace the <var>i</var>-th number with <var>a+b+c</var>.</li>
</ul>
<p>Here the <var>0</var>-th number is the <var>N</var>-th number, and the <var>(N+1)</var>-th number is the <var>1</var>-st number.</p>
<p>Determine if Takahashi can achieve his objective.
If the answer is yes, find the minimum number of operations required.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>3 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq A_i, B_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>
<var>B_1</var> <var>B_2</var> <var>...</var> <var>B_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of operations required, or <code>-1</code> if the objective cannot be achieved.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
1 1 1
13 5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>Takahashi can achieve his objective by, for example, performing the following operations:</p>
<ul>
<li>Replace the second number with <var>3</var>.</li>
<li>Replace the second number with <var>5</var>.</li>
<li>Replace the third number with <var>7</var>.</li>
<li>Replace the first number with <var>13</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
1 2 3 4
2 3 4 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>5
5 6 5 2 1
9817 1108 6890 4343 8704
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>25
</pre></section>
</div>
</span> |
p03653 | <span class="lang-en">
<p>Score : <var>800</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>X+Y+Z</var> people, conveniently numbered <var>1</var> through <var>X+Y+Z</var>.
Person <var>i</var> has <var>A_i</var> gold coins, <var>B_i</var> silver coins and <var>C_i</var> bronze coins.</p>
<p>Snuke is thinking of getting gold coins from <var>X</var> of those people, silver coins from <var>Y</var> of the people and bronze coins from <var>Z</var> of the people.
It is not possible to get two or more different colors of coins from a single person.
On the other hand, a person will give all of his/her coins of the color specified by Snuke.</p>
<p>Snuke would like to maximize the total number of coins of all colors he gets.
Find the maximum possible number of coins.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq X</var></li>
<li><var>1 \leq Y</var></li>
<li><var>1 \leq Z</var></li>
<li><var>X+Y+Z \leq 10^5</var></li>
<li><var>1 \leq A_i \leq 10^9</var></li>
<li><var>1 \leq B_i \leq 10^9</var></li>
<li><var>1 \leq C_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var> <var>Z</var>
<var>A_1</var> <var>B_1</var> <var>C_1</var>
<var>A_2</var> <var>B_2</var> <var>C_2</var>
<var>:</var>
<var>A_{X+Y+Z}</var> <var>B_{X+Y+Z}</var> <var>C_{X+Y+Z}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible total number of coins of all colors he gets.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 2 1
2 4 4
3 2 1
7 6 7
5 2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>18
</pre>
<p>Get silver coins from Person <var>1</var>, silver coins from Person <var>2</var>, bronze coins from Person <var>3</var> and gold coins from Person <var>4</var>.
In this case, the total number of coins will be <var>4+2+7+5=18</var>.
It is not possible to get <var>19</var> or more coins, and the answer is therefore <var>18</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 3 2
16 17 1
2 7 5
2 16 12
17 7 7
13 2 10
12 18 3
16 15 19
5 6 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>110
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 2 4
33189 87907 277349742
71616 46764 575306520
8801 53151 327161251
58589 4337 796697686
66854 17565 289910583
50598 35195 478112689
13919 88414 103962455
7953 69657 699253752
44255 98144 468443709
2332 42580 752437097
39752 19060 845062869
60126 74101 382963164
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>3093929975
</pre></section>
</div>
</span> |
p02412 |
<H1>How many ways?</H1><br>
<p>
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
</p>
<ul>
<li>You should select three distinct integers from 1 to <var>n</var>.</li>
<li>A total sum of the three integers is <var>x</var>.</li>
</ul>
<p>
For example, there are two combinations for <var>n</var> = 5 and <var>x</var> = 9.
</p>
<ul>
<li>1 + 3 + 5 = 9</li>
<li>2 + 3 + 4 = 9</li>
</ul>
<H2>Input</H2>
<p>
The input consists of multiple datasets. For each dataset, two integers <var>n</var> and <var>x</var> are given in a line.
</p>
<p>
The input ends with two zeros for <var>n</var> and <var>x</var> respectively. Your program should not process for these terminal symbols.
</p>
<H2>Constraints</H2>
<ul>
<li>3 ≤ <var>n</var> ≤ 100</li>
<li>0 ≤ <var>x</var> ≤ 300</li>
</ul>
<H2>Output</H2>
<p>
For each dataset, print the number of combinations in a line.
</p>
<H2>Sample Input</H2>
<pre>
5 9
0 0
</pre>
<H2>Sample Output</H2>
<pre>
2
</pre>
<h2>Note</h2>
<center>
<a href="commentary.jsp?id=ITP1_7_B">
<div class="button"> 解説 </div>
</a>
</center> |
p00585 | <h1>çããéœåž(Unique Cities)</h1>
<p>
JOI åœã«ã¯$N$ åã®éœåžãããïŒ1 ãã$N$ ãŸã§ã®çªå·ãã€ããŠããïŒãããã®éœåžã¯$N - 1$ æ¬ã®éè·¯ã§çµã°ããŠããïŒ$i$ çªç®($1 \leq i \leq N - 1$) ã®éè·¯ã¯éœåž$A_i$ ãšéœåž$B_i$ ãçµãã§ããïŒåæ¹åã«éè¡å¯èœã§ããïŒã©ã®éœåžããã©ã®éœåžãžãäœæ¬ãã®éè·¯ãéè¡ããããšã§ç§»åã§ããïŒ
</p>
<p>
JOI åœã«ã¯ããã€ãã®ç¹ç£åãååšããïŒç¹ç£åã«ã¯ïŒçš®é¡ã衚ã1 以äž$M$ 以äžã®çªå·ãä»ããããŠãã(JOI åœã§çç£ãããŠããç¹ç£åã«å¯Ÿå¿ããŠããªãçªå·ããããããããªã)ïŒåéœåžã¯1 ã€ã®ç¹ç£åãçç£ããŠããïŒéœåž$j$ ($1 \leq j \leq N$) ã§ã¯ç¹ç£å$C_j$ ãçç£ããŠããïŒè€æ°ã®éœåžãåãçš®é¡ã®ç¹ç£åãçç£ããããšããããããããªãïŒ
</p>
<p>
2 ã€ã®éœåžã®éã®è·é¢ã¯ïŒãã®éãç§»åããããã«éãéè·¯ã®æ¬æ°ã®æå°å€ã§ããïŒéœåž$x$ ($1 \leq x \leq N$)ããèŠãŠéœåž$y$ ($1 \leq y \leq N, y \ne x$) ãçããéœåžã§ãããšã¯ïŒãã¹ãŠã®éœåž$z$ ($1 \leq z \leq N, z \ne x, z \ne y) ã«ã€ããŠïŒéœåž$x, y$ éã®è·é¢ãšéœåž$x, z$ éã®è·é¢ãç°ãªãããšãæå³ããïŒ
</p>
<p>
JOI åœã®å€§è£ã§ããK çäºé·ã¯ïŒãã¹ãŠã®$j$ ($1 \leq j \leq N$) ã«ã€ããŠïŒéœåž$j$ ããèŠãŠçããéœåžã§çç£ãããŠããç¹ç£åãäœçš®é¡ããããç¥ãããïŒ
</p>
<p>
JOI åœã®éè·¯ã®æ
å ±ãšïŒåéœåžã§çç£ãããŠããç¹ç£åã®çªå·ãäžãããããšãïŒåéœåžããšã«ïŒãã®éœåžããèŠãŠçããéœåžã§çç£ãããŠããç¹ç£åãäœçš®é¡ããããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ
</p>
<pre>
$N$ $M$
$A_1$ $B_1$
:
$A_{N-1}$ $B_{N-1}$
$C_1$ ... $C_N$
</pre>
<h2>åºå</h2>
<p>
æšæºåºåã«$N$ è¡ã§åºåããïŒ $j$ è¡ç®($1 \leq j \leq N$) ã«ã¯ïŒéœåž$j$ ããèŠãŠçããéœåžã§çç£ãããŠããç¹ç£åãäœçš®é¡ããããåºåããïŒ
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$ 2 \leq N \leq 200 000$ïŒ</li>
<li>$ 1 \leq M \leq N$ïŒ</li>
<li>$ 1 \leq A_i \leq N (1 \leq i \leq N - 1)ïŒ1 \leq B_i \leq N (1 \leq i \leq N - 1)$ïŒ</li>
<li>$ A_i \ne B_i (1 \leq i \leq N - 1)$ïŒ</li>
<li> ã©ã®éœåžããã©ã®éœåžãžãäœæ¬ãã®éè·¯ãéè¡ããããšã§ç§»åã§ããïŒ</li>
<li>$ 1 \leq C_j \leq M (1 \leq j \leq N)$ïŒ</li>
</ul>
<!--
å°èª²é¡
1. (4 ç¹) N ⊠2 000ïŒ
2. (32 ç¹) M = 1ïŒ
3. (32 ç¹) M = NïŒCj = j (1 ⊠j ⊠N)ïŒ
4. (32 ç¹) 远å ã®å¶çŽã¯ãªãïŒ
-->
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ1 </h3>
<pre>
5 4
1 2
2 3
3 4
3 5
1 2 1 2 4
</pre>
<h3>åºåäŸ1</h3>
<pre>
2
0
1
1
1
</pre>
<p>
éœåž1 ããèŠãŠçããéœåžã¯éœåž2; 3 ã§ããïŒããã§çç£ãããç¹ç£åã¯ç¹ç£å2; 1 ãªã®ã§ïŒçãã¯2çš®é¡ã§ããïŒ
</p>
<p>
éœåž2 ããèŠãŠçããéœåžã¯ååšããªãã®ã§ïŒçãã¯0 çš®é¡ã§ããïŒ
</p>
<p>
éœåž3 ããèŠãŠçããéœåžã¯éœåž1 ã§ããïŒããã§çç£ãããç¹ç£åã¯ç¹ç£å1 ãªã®ã§ïŒçãã¯1 çš®é¡ã§ããïŒ
</p>
<p>
éœåž4 ããèŠãŠçããéœåžã¯éœåž1; 3 ã§ããïŒã©ã¡ãã®éœåžã«ãããŠãçç£ãããç¹ç£åã¯ç¹ç£å1 ãªã®ã§ïŒçãã¯1 çš®é¡ã§ããïŒ
</p>
<p>
éœåž5 ããèŠãŠçããéœåžã¯éœåž1; 3 ã§ããïŒã©ã¡ãã®éœåžã«ãããŠãçç£ãããç¹ç£åã¯ç¹ç£å1 ãªã®ã§ïŒçãã¯1 çš®é¡ã§ããïŒ
</p>
<p>
çªå·3 ã®ç¹ç£åã¯ååšããªãããšã«æ³šæããïŒ
</p>
<h3>å
¥åäŸ2</h3>
<pre>
7 1
1 2
2 3
3 4
4 5
5 6
6 7
1 1 1 1 1 1 1
</pre>
<h3>åºåäŸ2</h3>
<pre>
1
1
1
0
1
1
1
</pre>
<!--
<p>
ãã®å
¥åäŸã¯å°èª²é¡2 ã®å¶çŽãæºããã
</p>
-->
<h3>å
¥åäŸ3</h3>
<pre>
10 10
2 6
5 8
10 8
1 4
10 6
4 5
10 7
6 9
3 7
1 2 3 4 5 6 7 8 9 10
</pre>
<h3>åºåäŸ3</h3>
<pre>
4
3
4
2
0
2
2
0
3
2
</pre>
<!--ãã®å
¥åäŸã¯å°èª²é¡3 ã®å¶çŽãæºããã
-->
<h3>å
¥åäŸ4</h3>
<pre>
22 12
9 6
12 13
4 20
21 22
3 19
2 9
6 18
18 11
18 3
16 2
6 4
3 17
16 10
8 16
22 1
16 14
15 8
9 21
2 12
21 5
12 7
1 1 4 8 4 11 7 6 7 11 6 11 10 4 7 5 3 12 9 6 12 2
</pre>
<h3>åºåäŸ4</h3>
<pre>
2
0
1
1
1
1
1
0
0
1
2
0
1
1
2
0
2
1
2
3
0
0
</pre>
<br/>
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="ã¯ãªãšã€ãã£ãã»ã³ã¢ã³ãºã»ã©ã€ã»ã³ã¹" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a>
<br/>
<a href="https://www.ioi-jp.org/joi/2018/2019-ho/index.html">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第18 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2018/2019) æ¬éžã</a>
</p>
|
p02042 | <h1>F: Absum</h1>
<h2>åé¡</h2>
<p>é·ã $N$ ã®æ°å $A$ ãäžããããïŒããªãã¯é«ã
$M$ åãŸã§ïŒæ°åã® $i$ çªç®ãš $j$ çªç®ïŒ$0 \leq i, j \leq N-1$ïŒã®èŠçŽ ãå
¥ãæ¿ããæäœãè¡ãããšãã§ããïŒ</p>
<p>æäœãè¡ãªã£ãŠã§ããæ°åã® $\sum_{i = 0}^{N - 1} abs(A_i - i)$ ã®æå€§å€ãæ±ããïŒ</p>
<h2>å¶çŽ</h2>
<ul>
<li>$2 \leq N \leq 10^5$</li>
<li>$0 \leq M \leq N$</li>
<li>$0 \leq A_i \leq 10^5$</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p> å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. </p>
<p>
$N\ M$ïŒ15:15ä¿®æ£ïŒ<br>
$A_0\ A_1\ A_2\ \dots\ A_{N - 1}$<br>
</p>
<h2>åºå</h2>
<p>æäœãè¡ãªã£ãŠã§ããæ°åã® $\sum_{i = 0}^{N - 1} abs(A_i - i)$ ã®æå€§å€ãæ±ãã.ãŸã, æ«å°Ÿã«æ¹è¡ãåºåãã.</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
5 2
0 3 2 1 4
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
12
</pre>
<p>
$0$ çªç®ã®èŠçŽ ãš $4$ çªç®ã®èŠçŽ ã«æäœãè¡ããšïŒæäœåŸã®æ°å㯠$(4, 3, 2, 1, 0)$ ãšãªãïŒ $|4 - 0| + |3 - 1| + |2 - 2| + |1 - 3| + |0 - 4| = 12$ ã§æå€§ãšãªãïŒå¿
ãããæäœã <b>$M$ åè¡ãå¿
èŠããªã</b>ããšã«æ³šæããïŒ
</p>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
3 2
0 0 0
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
3
</pre>
<p>
æäœãè¡ãããšãªãæå€§å€ãšãªãïŒ
</p>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
6 2
1 0 3 6 5 4
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
20
</pre>
|
p00751 |
<h1><font color="#000000">Problem F:</font> Old Memories</h1>
<!-- end en only -->
<!-- begin en only -->
<p>
In 4272 A.D., Master of Programming Literature, Dr. Isaac Cornell Panther-Carol,
who has miraculously survived through the three World Computer Virus Wars and reached 90 years old this year,
won a Nobel Prize for Literature.
Media reported every detail of his life.
However, there was one thing they could not report — that is, an essay written by him when he was an elementary school boy.
Although he had a copy and was happy to let them see it,
the biggest problem was that his copy of the essay was infected by a computer virus several times during the World Computer Virus War III
and therefore the computer virus could have altered the text.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
Further investigation showed that his copy was altered indeed. Why could we know that?
More than 80 years ago his classmates transferred the original essay to their brain before infection.
With the advent of Solid State Brain, one can now retain a text perfectly over centuries once it is transferred to his or her brain.
No one could remember the entire text due to the limited capacity,
but we managed to retrieve a part of the text from the brain of one of his classmates; sadly, it did not match perfectly to the copy at hand.
It would not have happened without virus infection.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
At the moment, what we know about the computer virus is that each time the virus infects an essay it does one of the following:
</p>
<ol>
<li>the virus inserts one random character to a random position in the text. (e.g., "ABCD" → "ABCZD")</li>
<li>the virus picks up one character in the text randomly, and then changes it into another character. (e.g., "ABCD" → "ABXD")</li>
<li>the virus picks up one character in the text randomly, and then removes it from the text. (e.g., "ABCD" → "ACD")</li>
</ol>
<p>
You also know the maximum number of times the computer virus infected the copy, because you could deduce it from the amount of the intrusion log.
Fortunately, most of his classmates seemed to remember at least one part of the essay (we call it a <i>piece</i> hereafter).
Considering all evidences together, the original essay might be reconstructed.
You, as a journalist and computer scientist, would like to reconstruct the original essay by writing a computer program to calculate the possible original text(s) that fits to the given pieces and the altered copy at hand.
</p>
<!-- end en only -->
<h3>Input</h3>
<!-- begin en only -->
<p>
The input consists of multiple datasets. The number of datasets is no more than 100.
Each dataset is formatted as follows:
</p>
<blockquote>
<i>d n</i><br>
<i>the altered text</i><br>
<i>piece<sub>1</sub></i><br>
<i>piece<sub>2</sub></i><br>
<i>...</i><br>
<i>piece<sub>n</sub></i><br>
</blockquote>
<p>
The first line of a dataset contains two positive integers <i>d</i> (<i>d</i> ≤ 2) and <i>n</i> (<i>n</i> ≤ 30),
where <i>d</i> is the maximum number of times the virus infected the copy and <i>n</i> is the number of <i>pieces</i>.
</p><p>
The second line is the text of the altered copy at hand. We call it <i>the altered text</i> hereafter.
The length of the altered text is less than or equal to 40 characters.
</p><p>
The following <i>n</i> lines are <i>pieces</i>, each of which is a part of the original essay remembered by one of his classmates.
Each <i>piece</i> has at least 13 characters but no more than 20 characters. All pieces are of the same length.
Characters in the altered text and <i>pieces</i> are uppercase letters (`A' to `Z') and a period (`.').
Since the language he used does not leave a space between words, no spaces appear in the text.
</p><p>
A line containing two zeros terminates the input.
</p>
<!-- end en only -->
<!-- begin en only -->
<p>
His classmates were so many that you can assume that any character that appears in the original essay is covered by at least one <i>piece</i>.
A <i>piece</i> might cover the original essay more than once; the original essay may contain repetitions.
Please note that some pieces may not appear in the original essay because some of his classmates might have mistaken to provide irrelevant pieces.
</p>
<!-- end en only -->
<h3>Output</h3>
<!-- begin en only -->
<p>
Below we explain what you should output for each dataset.
Suppose if there are <i>c</i> possibilities for the original essay that fit to the given pieces and the given altered text.
First, print a line containing <i>c</i>.
If <i>c</i> is less than or equal to 5, then print in lexicographical order <i>c</i> lines, each of which contains an individual possibility.
Note that, in lexicographical order, '.' comes before any other characters.
You can assume that <i>c</i> is always non-zero.
The output should not include any characters other than those mentioned above.
</p>
<!-- end en only -->
<h3>Sample Input</h3>
<pre>
1 4
AABBCCDDEEFFGGHHIJJKKLLMMNNOOPP
AABBCCDDEEFFGG
CCDDEEFFGGHHII
FFGGHHIIJJKKLL
JJKKLLMMNNOOPP
2 3
ABRACADABRA.ABBRACADABRA.
ABRACADABRA.A
.ABRACADABRA.
BRA.ABRACADAB
2 2
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAA
AAAAAAAAAAAAA
2 3
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXAXXXXXX
XXXXXXBXXXXXX
XXXXXXXXXXXXX
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
1
AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP
5
.ABRACADABRA.ABRACADABRA.
ABRACADABRA.A.ABRACADABRA.
ABRACADABRA.AABRACADABRA.A
ABRACADABRA.ABRACADABRA.
ABRACADABRA.ABRACADABRA.A
5
AAAAAAAAAAAAAA
AAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAA
257
</pre>
|
p01843 |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<h2>E - éžææŽ»å</h2>
<h3>Problem Statement</h3>
<p>
ããªãã¯æ¬¡åã®éžæã®åè£è
ã§ããXæ°ã®æ¯æŽè
ã§ããïŒ
Xæ°ã¯é§
åã§ã®è¡é æŒèª¬ãäºå®ããŠããïŒã§ããã ãå€ãã®ææš©è
ã«èŠãŠããããå Žæã§æŒèª¬ããããšèããŠããïŒ
</p>
<p>
é§
å㯠$N$ åã®é害ç©ãš $M$ äººã®ææš©è
ãååšããŠããäºæ¬¡å
å¹³é¢ãšããŠäžããããïŒ
åé害ç©ã¯å€è§åœ¢ã§ãããããïŒãã®å€è§åœ¢ã®å
åŽã®é åãé害ç©ãšãªãïŒå€è§åœ¢ã®èŸºäžã¯é害ç©ã«å«ãŸããªãïŒ
ãŸãïŒææš©è
ã¯å¹³é¢äžã®ç¹ãšããŠããããããïŒ
ããææš©è
ã®äœçœ®ãšXæ°ã®äœçœ®ãçµã¶ç·åäžã«é害ç©ãååšããªããšãïŒãã®ææš©è
ã¯Xæ°ãèŠãããšãã§ããïŒ
</p>
<p>
ããªãã®ä»äºã¯ïŒé§
åã®é害ç©ãšææš©è
ã®æ
å ±ãããšã«ïŒãã£ãšãå€ãã®ææš©è
ã«èŠãŠããããå°ç¹ãæ¢ãããšã ïŒ
æå€§ã§äœäººã®ææš©è
ããèŠããããã«æŒèª¬ããããšãã§ããããæ±ããïŒ
</p>
<h3>Input</h3>
<p>
å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããïŒ
</p>
<p>$N$ $M$<br>
$polygon_1$<br>
$polygon_2$<br>
$...$<br>
$polygon_N$<br>
$x_1$ $y_1$<br>
$x_2$ $y_2$<br>
$...$<br>
$x_M$ $y_M$
</p>
<p>
ããŒã¿ã»ããã®æåã®è¡ã¯ç©ºçœæå1ã€ã§åºåããã2åã®æŽæ° $N$, $M$ ãããªãïŒ
$N$ $(1 \le N \le 5)$ ã¯é§
åã«ããé害ç©ã®åæ°ã§ããïŒ$M$ $(1 \le M \le 10)$ ã¯é§
åã«ããææš©è
ã®æ°ã§ããïŒ
ç¶ãè¡ãã $N$ åã®é害ç©ã®æ
å ±ãäžããããïŒ1ã€ã®é害ç©ã衚ãå
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ
</p>
<p>
$L$<br>
$x_1$ $y_1$<br>
$x_2$ $y_2$<br>
$...$<br>
$x_L$ $y_L$
</p>
<p>
åéå®³ç©æ
å ±ã®æåã®è¡ã¯ãã®é害ç©ãããããå€è§åœ¢ã«å«ãŸããé ç¹ã®æ° $L$ ã§ããïŒ
ãã®åŸã® $L$ è¡ã«ã¯å€è§åœ¢ã®é ç¹ã®åº§æšãè¡šãæŽæ°ã®çµãåæèšåãã«èšãããŠããïŒãªãïŒé害ç©ãæ§æããé ç¹æ°ã®åèšã¯ $15$ å以äžãšãªãïŒ
</p>
<p>
$N$ åã®é害ç©ã®æ
å ±ã®åŸã«ç¶ã $M$ è¡ã«ã¯ææš©è
ã®ãã座æšãè¡šãæŽæ°ã®çµãäžããããïŒ
</p>
<p>
ãŸãïŒåãã¹ãã±ãŒã¹ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ
</p><ol><li> $ 0 \le |x_i|, |y_i| \le 20 $
</li><li> å€è§åœ¢ã®é ç¹ãŸãã¯ææš©è
ã®ããå Žæã®åº§æšã¯ãã¹ãŠäºãã«ç°ãªãïŒ
</li><li> å€è§åœ¢ã®é ç¹ãŸãã¯ææš©è
ã®ããå Žæã®åº§æšã®ãã¡3ç¹ãåäžçŽç·ç¶ã«ååšããããšã¯ãªãïŒ
</li><li> 2ã€ã®ç°ãªãå€è§åœ¢å士ã¯äº€å·®ãæããªãïŒ
</li><li> åå€è§åœ¢ã¯èªå·±äº€å·®ãæããªãïŒ
</li><li> å€è§åœ¢ã®å
éšã«ææš©è
ãååšããããšã¯ãªãïŒ
</li></ol>
<h3>Output</h3>
<p>
æå€§ã§äœäººã®ææš©è
ãæŒèª¬ãèŠãããããã«ãªããã1è¡ã«åºåããïŒ
</p>
<h3>Sample Input 1</h3>
<pre>1 2
4
5 5
15 5
15 15
5 15
0 10
20 10</pre>
<h3>Output for the Sample Input 1</h3>
<pre>2</pre>
<h3>Sample Input 2</h3>
<pre>1 2
6
0 0
20 0
12 9
20 20
0 20
8 11
1 10
19 10</pre>
<h3>Output for the Sample Input 2</h3>
<pre>1</pre>
<h3>Sample Input 3</h3>
<pre>4 2
3
0 0
20 0
20 1
3
0 18
19 19
19 20
3
3 2
4 2
4 17
3
16 3
17 3
17 18
2 9
18 10</pre>
<h3>Output for the Sample Input 3</h3>
<pre>1</pre>
<h3>Sample Input 4</h3>
<pre>3 3
3
0 -2
-1 -3
-1 -6
3
2 2
3 2
4 3
3
-4 4
-4 5
-5 6
0 -3
3 3
-5 5</pre>
<h3>Output for the Sample Input 4</h3>
<pre>3</pre>
<h3>Sample Input 5</h3>
<pre>2 2
4
2 0
1 2
-1 2
-2 0
4
3 3
3 4
-3 4
-3 3
2 1
-2 1</pre>
<h3>Output for the Sample Input 5</h3>
<pre>2</pre>
<h3>Sample Input 6</h3>
<pre>1 1
4
1 1
-1 1
-1 -1
1 -1
0 2</pre>
<h3>Output for the Sample Input 6</h3>
<pre>1</pre>
<p>
åå
¥åäŸã®é害ç©ããã³ææš©è
ã®é
眮ã¯ïŒãããã以äžã®å³ã®ããã«ãªã£ãŠããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_e-sample00" height="247" width="246" />
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_e-sample01" height="247" width="246" />
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_e-sample02" height="247" width="246" />
<br/>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_e-sample03" height="232" width="186" />
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_e-sample04" height="189" width="244" />
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_e-sample05" height="161" width="138" />
</center> |
p02296 |
<H1>Distance</H1>
<br/>
<p>
For given two segments <var>s1</var> and <var>s2</var>, print the distance between them.
</p>
<p>
<var>s1</var> is formed by end points <var>p0</var> and <var>p1</var>, and
<var>s2</var> is formed by end points <var>p2</var> and <var>p3</var>.
</p>
<H2>Input</H2>
<p>
The entire input looks like:
</p>
<pre>
<var>q</var> (the number of queries)
1st query
2nd query
...
<var>q</var>th query
</pre>
<p>
Each query consists of integer coordinates of end points of <var>s1</var> and <var>s2</var> in the following format:
</p>
<pre>
<var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>x<sub>p2</sub></var> <var>y<sub>p2</sub></var> <var>x<sub>p3</sub></var> <var>y<sub>p3</sub></var>
</pre>
<H2>Output</H2>
<p>
For each query, print the distance. The output values should be in a decimal fraction with an error less than 0.00000001.
</p>
<H2>Constraints</H2>
<ul>
<li>
1 ≤ <i>q</i> ≤ 1000
</li>
<li>
-10000 ≤ x<sub>p<sub>i</sub></sub>, y<sub>p<sub>i</sub></sub> ≤ 10000
</li>
<li>
<var>p0 ≠ p1</var> and
<var>p2 ≠ p3</var>.
</li>
</ul>
<H2>Sample Input</H2>
<pre>
3
0 0 1 0 0 1 1 1
0 0 1 0 2 1 1 2
-1 0 1 0 0 1 0 -1
</pre>
<H2>Sample Output</H2>
<pre>
1.0000000000
1.4142135624
0.0000000000
</pre>
<br/>
|
p00301 |
<h1>察称ïŒé²æ°</h1>
<p>
1 ã°ã©ã ã3 ã°ã©ã ã9 ã°ã©ã ã27 ã°ã©ã ã®ããããïŒã€ãã€ããã°ã倩ã³ãã䜿ã£ãŠ 1 ã°ã©ã ãã 40ã°ã©ã ãŸã§ 1 ã°ã©ã å»ã¿ã§éããããšãç¥ãããŠããŸããããšãã°ã倩ã³ãã®äžæ¹ã®ç¿ã«éããéããããã®ãš 3 ã°ã©ã ã®ããããèŒããããäžæ¹ã®ç¿ã« 27 ã°ã©ã ãš 1 ã°ã©ã ã®ããããèŒããŠé£ãåãã°ãéããããã®ã®éã㯠27-3+1=25 ã°ã©ã ã ãšããããŸãã ããã«ã1(=3<sup>0</sup>)ã°ã©ã ã3<sup>1</sup> ã°ã©ã ã... ã3<sup>n-1</sup> ã°ã©ã ã3<sup>n</sup> ã°ã©ã ãŸã§ã®ããããïŒã€ãã€ããã°ã倩ã³ãã䜿ã£ãŠ(3<sup>n+1</sup>-1)/2ã°ã©ã ãŸã§éããããšãç¥ãããŠããŸãããŸãã倩ã³ããé£ãåããããªãããã®çœ®ãæ¹ã¯äžéããããªãããšãç¥ãããŠããŸãã
</p>
<p>
éããããã®ãšãããã倩ã³ãã«çœ®ããŠãé£ãåããããªãããã®çœ®ãæ¹ãæååã§è¡šãããšãã§ããŸãã3<sup><var>i</var></sup> ã°ã©ã ã®ããããéããããã®ãšåãç¿ã«èŒãããšãã¯ã<span>-</span>ããããäžæ¹ã®ç¿ã«èŒãããšãã¯ã<span>+</span>ããã©ã¡ãã«ãèŒããªãã£ããšãã¯ã0ããæååã®å³ç«¯ããiçªç®ã«æžããŸãïŒå³ç«¯ãïŒçªç®ãšæ°ããŸãïŒãããšãã°ãå
ã»ã©ã® 25 ã°ã©ã ã®äŸã¯ <span>+0-+</span> ãšè¡šãããŸãã
</p>
<p>
ããã§ã¯ãéããããã®ã®éããäžãããããšãã倩ã³ããé£ãåããããªãããã®çœ®ãæ¹ã衚ãæååãåºåããããã°ã©ã ãäœæããŠãã ããããã ããïŒã®ã¹ãä¹ã°ã©ã ã®ãããã¯ãã©ã®ãããªéãã®ãã®ã§ãå¿
ãïŒã€ãããã®ãšããŸãã
</p>
<p>
ïŒè£è¶³ïŒ 察称ïŒé²æ°ã«ã€ããŠïŒ<br>
éããããã®ã®éããwã®ãšãããããã®çœ®ãæ¹ã衚ãæååã¯wã®å¯Ÿç§°ïŒé²æ°ã«ãªã£ãŠããŸãã察称ïŒé²æ°ãšã¯ãïŒã®ã¹ãä¹ã®æ°ã§äœåããè¡ããåäœã«æ° 1ã0ã-1 ã衚ãæåãæžãããšã§è¡šããæ°ã®ããšã§ããäžã®æååã§ã¯ãæåã<span>+</span>ããã<span>0</span>ããã<span>-</span>ããããããæ° 1ã0ã-1 ã«å¯Ÿå¿ããŸããããšãã°ã25 ã°ã©ã ã®ãã®ãéããšãã®ãããã®çœ®ãæ¹ã <span>+0-+</span> ã§ãã察称ïŒé²æ°ãè¡šãæ°ã¯ã1 × 3<sup>3</sup> + 0 × 3<sup>2</sup> - 1× 3<sup>1</sup> + 1 × 3<sup>0</sup> = 25 ãšãªããŸãã
</p>
<h2>å
¥å</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã
</p>
<pre>
<var>w</var>
</pre>
<p>
<var>w</var> (1 ≤ <var>w</var> ≤ 100000) ã¯éããããã®ã®éããè¡šãæŽæ°ã§ããã
</p>
<h2>åºå</h2>
<p>
ãããã®çœ®ãæ¹ã衚ãæååãåºåããããã ãæååã®å·Šç«¯ã 0 ã«ããŠã¯ãªããªãã
</p>
<h2>å
¥åºåäŸ </h2>
<h2>å
¥åäŸïŒ</h2>
<pre>
25
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
+0-+
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
2
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
+-
</pre>
<br>
<h2>å
¥åäŸïŒ </h2>
<pre>
5
</pre>
<h2>åºåäŸïŒ</h2>
<pre>
+--
</pre>
|
p01140 |
<!-- begin en only -->
<h3><U>Square Route</U></h3>
<!-- end en only -->
<!-- begin ja only -->
<h3><U>ã¹ã¯ãŠã§ã¢ã»ã«ãŒã</U></h3>
<!-- end ja only -->
<!-- begin en only -->
<p>
English text is not available in this practice contest.
</p>
<!-- end en only -->
<!-- begin ja only -->
<p>
ãã®ãã³æ°ãã豪éžã建ãŠãããšã決ãã倧å¯è±ªã®åç°æ°ã¯ïŒã©ã®è¡ã«æ°éžã建ãŠããããšæ©ãã§ããïŒå®ã¯ïŒåç°æ°ã¯æ£æ¹åœ¢ããšãŠã奜ããšããå€ãã£ã人ç©ã§ããïŒãã®ããå°ãã§ãæ£æ¹åœ¢ã®å€ãè¡ã«äœã¿ãããšæã£ãŠããïŒ
</p>
<p>
åç°æ°ã¯ïŒç¢ç€ç®ç¶ã«éè·¯ã®æŽåãããè¡ã®äžèЧãæã«å
¥ããŠïŒããããã®è¡ã«ã€ããŠïŒéè·¯ã«ãã圢äœãããæ£æ¹åœ¢ã®åæ°ãæ°ããããšã«ããïŒãšãããïŒéãšéã®ééã¯äžå®ãšã¯éããªãããïŒæäœæ¥ã§æ£æ¹åœ¢ãæ°ããã®ã¯å€§å€ã§ããïŒããã§ããªãã«ã¯ïŒç¢ç€ç®ç¶ã®éè·¯ã®æ
å ±ãäžãããããšãã«ïŒæ£æ¹åœ¢ã®åæ°ãæ°ããããã°ã©ã ãæžããŠæ¬²ããïŒ
</p>
<!-- end ja only -->
<h3>Input</h3>
<!-- begin ja only -->
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããŠããïŒåããŒã¿ã»ããã¯ä»¥äžã®ãããªæ§æã«ãªã£ãŠããïŒ
</p>
<blockquote>
<i>N</i> <i>M</i><br>
<i>h</i><sub>1</sub><br>
<i>h</i><sub>2</sub><br>
...<br>
<i>h</i><sub><i>N</i></sub><br>
<i>w</i><sub>1</sub><br>
<i>w</i><sub>2</sub><br>
...<br>
<i>w</i><sub><i>M</i></sub>
</blockquote>
<p>
1 è¡ç®ã«ã¯ 2 ã€ã®æ£ã®æŽæ° <i>N</i>, <i>M</i> (1 ⊠<i>N</i>, <i>M</i> ⊠1500) ãäžããããïŒç¶ã <i>N</i> è¡ <i>h</i><sub>1</sub>, <i>h</i><sub>2</sub>, ..., <i>h</i><sub><i>N</i></sub> (1 ⊠<i>h</i><sub><i>i</i></sub> ⊠1000ïŒã¯ïŒéè·¯ãšéè·¯ã®ååæ¹åã®ééã衚ãïŒããã§ <i>h</i><sub><i>i</i></sub> ã¯åãã <i>i</i> çªç®ã®éè·¯ãšåãã <i>i</i> + 1 çªç®ã®éè·¯ã®ééã§ããïŒåæ§ã«ïŒç¶ã <i>M</i> è¡ <i>w</i><sub>1</sub>, ..., <i>w</i><sub><i>M</i></sub> (1 ⊠<i>w</i><sub><i>i</i></sub> ⊠1000ïŒã¯ïŒéè·¯ãšéè·¯ã®æ±è¥¿æ¹åã®ééã衚ãïŒããã§ <i>w</i><sub><i>i</i></sub> ã¯è¥¿ãã <i>i</i> çªç®ã®éè·¯ãšè¥¿ãã <i>i</i> + 1 çªç®ã®éè·¯ã®ééã§ããïŒéè·¯èªäœã®å¹
ã¯åå现ãããèæ
®ããå¿
èŠã¯ãªãïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_squareRoute2" alt="æåã®ããŒã¿ã»ãã"><br>
å³ D-1: æåã®ããŒã¿ã»ãã
</center>
<p>
<i>N</i> = <i>M</i> = 0 ã¯å
¥åã®çµç«¯ã瀺ããŠããïŒããŒã¿ã»ããã«ã¯å«ããªãïŒ
</p>
<!-- end ja only -->
<h3>Output</h3>
<!-- begin ja only -->
<p>
åããŒã¿ã»ããã«å¯ŸããŠïŒæ£æ¹åœ¢ã®åæ°ã 1 è¡ã«åºåããªããïŒããšãã°ïŒSample Input ã®æåã®ããŒã¿ã»ããã«ãããŠã¯ïŒä»¥äžã®ãšãã 6 åã®æ£æ¹åœ¢ãå«ãã®ã§ïŒãã®ããŒã¿ã»ããã«å¯Ÿããåºå㯠6 ãšãªãïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_squareRoute1" alt="æåã®ããŒã¿ã»ããã«å«ãŸããæ£æ¹åœ¢"><br>
å³ D-2: æåã®ããŒã¿ã»ããã«å«ãŸããæ£æ¹åœ¢
</center>
<!-- end ja only -->
<h3>Sample Input</h3>
<pre>
3 3
1
1
4
2
3
1
1 2
10
10
10
0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
6
2
</pre>
|
p03487 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given a sequence of positive integers of length <var>N</var>, <var>a = (a_1, a_2, ..., a_N)</var>.
Your objective is to remove some of the elements in <var>a</var> so that <var>a</var> will be a <strong>good sequence</strong>.</p>
<p>Here, an sequence <var>b</var> is a <strong>good sequence</strong> when the following condition holds true:</p>
<ul>
<li>For each element <var>x</var> in <var>b</var>, the value <var>x</var> occurs exactly <var>x</var> times in <var>b</var>.</li>
</ul>
<p>For example, <var>(3, 3, 3)</var>, <var>(4, 2, 4, 1, 4, 2, 4)</var> and <var>()</var> (an empty sequence) are good sequences, while <var>(3, 3, 3, 3)</var> and <var>(2, 4, 1, 4, 2)</var> are not.</p>
<p>Find the minimum number of elements that needs to be removed so that <var>a</var> will be a good sequence.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>a_i</var> is an integer.</li>
<li><var>1 \leq a_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum number of elements that needs to be removed so that <var>a</var> will be a good sequence.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
3 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1
</pre>
<p>We can, for example, remove one occurrence of <var>3</var>. Then, <var>(3, 3, 3)</var> is a good sequence.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
2 4 1 4 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>2
</pre>
<p>We can, for example, remove two occurrences of <var>4</var>. Then, <var>(2, 1, 2)</var> is a good sequence.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
1 2 2 3 3 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>1
1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>1
</pre>
<p>Remove one occurrence of <var>10^9</var>. Then, <var>()</var> is a good sequence.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>8
2 7 1 8 2 8 1 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>5
</pre></section>
</div>
</span> |
p01510 |
<script src="./IMAGE/varmath.js" charset="UTF-8"></script>
<H1>Skyland</H1>
<p>
Somewhere in the sky, KM kingdom built <var>n</var> floating islands by their highly developed technology.
The islands are numbered from 1 to <var>n</var>.
</p>
<p>
The king of the country, Kita_masa, can choose any non-negative real number as the altitude for each island, as long as the sum of the altitudes is greater than or equals to <var>H</var>.
For floating the island <var>i</var> to the altitude <var>h_i</var>, it costs <var>b_i h_i</var>.
Besides, it costs <var>|h_i - h_j|c_{i,j}</var> for each pair of islands <var>i</var> and <var>j</var> since there are communications between these islands.
</p>
<p>
Recently, energy prices are rising, so the king, Kita_masa, wants to minimize the sum of the costs.
The king ordered you, a court programmer, to write a program that finds the altitudes of the floating islands that minimize the cost.
</p>
<H2>Input</H2>
<p>
The input contains several test cases.
Each test case starts with a line containing two integers <var>n</var> (<var>1 \leq n \leq 100</var>) and <var>H</var> (<var>0\leq H \leq 1,000</var>), separated by a single space.
The next line contains <var>n</var> integers <var>b_1</var>, <var>b_2</var>,..., <var>b_n</var> (<var>0\leq b_i \leq 1,000</var>).
Each of the next <var>n</var> lines contains <var>n</var> integers <var>c_{i,j}</var> (<var>0 \leq c_{i,j} \leq 1,000</var>).
You may assume <var>c_{i, i} = 0</var> and <var>c_{i, j} = c_{j, i}</var>.
</p>
<p>
The last test case is followed by a line containing two zeros.
</p>
<H2>Output</H2>
<p>
For each test case, print its case number.
Then print a line containing a space-separated list of the altitudes of the islands that minimizes the sum of the costs.
If there are several possible solutions, print any of them.
Your answer will be accepted if the altitude of each island is non-negative, sum of the altitudes is greater than <var>(1-10^{-9})H</var>, and the cost calculated from your answer has an absolute or relative error less than <var>10^{-9}</var> from the optimal solution.
</p>
<p>
Follow the format of the sample output.
</p>
<H2>Sample Input</H2>
<pre>
2 1
1 3
0 1
1 0
3 3
1 2 4
0 2 0
2 0 1
0 1 0
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
Case 1:
0.75 0.25
Case 2:
1.5 1.5 0.0
</pre>
|
p03038 | <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have <var>N</var> cards. On the <var>i</var>-th card, an integer <var>A_i</var> is written.</p>
<p>For each <var>j = 1, 2, ..., M</var> in this order, you will perform the following operation once:</p>
<p>Operation: Choose at most <var>B_j</var> cards (possibly zero). Replace the integer written on each chosen card with <var>C_j</var>.</p>
<p>Find the maximum possible sum of the integers written on the <var>N</var> cards after the <var>M</var> operations.</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 A_i, C_i \leq 10^9</var></li>
<li><var>1 \leq B_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>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
<var>B_1</var> <var>C_1</var>
<var>B_2</var> <var>C_2</var>
<var>\vdots</var>
<var>B_M</var> <var>C_M</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the maximum possible sum of the integers written on the <var>N</var> cards after the <var>M</var> operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 2
5 1 4
2 3
1 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>14
</pre>
<p>By replacing the integer on the second card with <var>5</var>, the sum of the integers written on the three cards becomes <var>5 + 5 + 4 = 14</var>, which is the maximum result.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>338
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>3 2
100 100 100
3 99
3 99
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>300
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>10000000001
</pre>
<p>The output may not fit into a <var>32</var>-bit integer type.</p></section>
</div>
</span> |
p01005 |
<h1>Problem G: The Humans Braving the Invaders</h1>
<h2>Problem</h2>
<p>
çŸåšãå°çã¯å®å®ããã®äŸµç¥è
ã§ããã€ã³ããŒããŒã®æ»æãåãã人é¡ã§çãæ®ã£ãè
ã¯åºå°ã«ããæã
ã ããšãªã£ãã
奎ãã«å¯Ÿæã§ããæŠåãã»ãšãã©æ®ãããŠããªãã<!--人é¡ã«åã¡ç®ã¯ã»ãŒç¡ããšèšã£ãŠããã ããã-->
ã ããããã§æã
ã¯è«Šãããšããããšã¯ããªãã
ã€ã³ããŒããå
šæ»
ãããããšããæã
人é¡ãçãæ®ãæåŸã®ææ®µã§ããã
<!--ãããŠãæ®ããã人é¡ã®ä»£è¡šãšããŠãæã
ã¯æåŸãŸã§æŠããªããã°ãªããªãã-->
ä»ããæåŸã«ãªãã§ãããäœæŠã®å
容ã説æããã
</p>
<p>
ãŸããã€ã³ããŒããŒã®æŠåã«æ¯ã¹æã
ã®æŠåã¯ããŸãã«ãå°ãªãã®ã§ããã®åºå°ã«ç«ãŠããããç± åæŠãè¡ãã
ãã®åºå°ã¯é«ãå±±ã«å²ãŸããŠããŠãã€ã³ããŒããŒã䟵æ»ããã«ã¯åºå°æ£é¢ã«ããçã£çŽããªéãéãä»ç¡ãã
ãã®éããã£ãŒã«ããšåŒã¶ããšã«ããããã®ç¹åŸŽã«ãããåæ¹ã«éäžããŠã€ã³ããŒããŒãæ»æããããšãå¯èœã§ããã
åºå°ã«ããæã
ã¯ã€ã³ããŒããŒã«å¯Ÿã2çš®é¡ã®æŠåšã§æ»æãè¡ãã
1ã€ã¯ã€ã³ããŒããŒ1äœãçæããã¹ãã€ããŒã©ã€ãã«ã§ããããã1ã€ã¯åºç¯å²ã«æ»æãã§ããã°ã¬ããŒãã©ã³ãã£ãŒã§ããã
</p>
<p>
人é¡ã§ãã£ã1人ã®ããã°ã©ããŒã§ããåã®ä»äºã¯ãã€ã³ããŒããŒãšæã
ã®è¡åèšé²ãå
ã«æŠéãã·ãã¥ã¬ãŒã·ã§ã³ããããšã ã
è¡åèšé²ã¯ã¯ãšãªãŒåœ¢åŒã§äžãããããåã¯ãšãªãŒã¯1ã€ãŸãã¯è€æ°ã®æŽæ°ãããªããæ¬¡ã®ããã«äžããããã
</p>
<table class="withborder" border=1>
<tr>
<td nowrap>0</td>
<td>ã€ã³ããŒããŒããã£ãŒã«ãäžã®ãåºå°ããã®è·é¢<var> L </var>ã®äœçœ®ã«åºçŸããã</td>
</tr>
<tr>
<td nowrap>1 <var>d</var></td>
<td>çŸåšãã£ãŒã«ãäžã«ãããã¹ãŠã®ã€ã³ããŒããŒã<var> d </var>ã ãåºå°ã«è¿ã¥ãã
ãã®åäœã®åŸãåºå°ã«å°éããã€ã³ããŒããŒãããã¡ãŒãžãåãããŸãããããã®æµã¯ãã£ãŒã«ãäžããæ¶æ»
ããã
ãã¡ãŒãžãåããå Žåã¯"damage (ãã®æåºå°ã«å°éããã€ã³ããŒããŒã®æ°)"ã1è¡ã«åºåããã
</td>
</tr>
<tr>
<td nowrap>2 <var>k</var></td>
<td>çŸåšãã£ãŒã«ãäžã«ããã€ã³ããŒããŒã®æ°ã<var> k </var>äœä»¥äžã®å Žåãåºå°ã«è¿ãæ¹ãã<var> k </var>çªç®ã®ã€ã³ããŒããŒãã¹ãã€ããŒã©ã€ãã«ã§æ»æããã
ãã®ã€ã³ããŒããŒã¯ãã£ãŒã«ãäžããæ¶æ»
ããããããŠ"hit"ã1è¡ã«åºåããã
ãã£ãŒã«ãäžã®ã€ã³ããŒããŒã®æ°ã<var> k </var>äœæªæºã®å Žåã"miss"ã1è¡ã«åºåããã
</td>
</tr>
<tr>
<td nowrap>3 <var>x</var> <var>r</var></td>
<td>åºå°ããã®è·é¢ã<var> x </var>ã®äœçœ®ã«ç¯å²<var> r </var>ã®ã°ã¬ããŒãã©ã³ãã£ãŒã§æ»æãããåºå°ããã®è·é¢ã<var> x </var>ã®äœçœ®ã«ç匟ããããããã®è·é¢ã<var> r </var>以äžã®äœçœ®ã«ãããã¹ãŠã®ã€ã³ããŒããŒã¯ãã£ãŒã«ãäžããæ¶æ»
ããã
ãããŠ"bomb (åããã€ã³ããŒããŒã®æ°)"ã1è¡ã«åºåãããè£è¶³ãšããŠãåºå°ã¯ã°ã¬ããŒãã©ã³ãã£ãŒã®ãã¡ãŒãžãåããããšã¯ãªãã
</td>
</tr>
<tr>
<td nowrap>4 <var>k</var></td>
<td>ãã£ãŒã«ãäžã®ã€ã³ããŒããŒã®æ°ã<var> k </var>äœä»¥äžã®å Žåã"distance (åºå°ã«è¿ãæ¹ããkçªç®ã®ã€ã³ããŒããŒãšåºå°ãšã®è·é¢)"ã1è¡ã«åºåããã
ãã£ãŒã«ãäžã®ã€ã³ããŒããŒã®æ°ã<var> k </var>äœæªæºã®å Žåã"distance -1"ã1è¡ã«åºåããã
</td>
</tr>
</table>
<br/>
<br/>
<p>
äœæŠã®èª¬æã¯ä»¥äžã ãç·å¡ãäœæŠéå§ïŒã»ã»ã»å¹žéãç¥ãã
</p>
<h2>Input</h2>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãã
åããŒã¿ã»ããã¯ä»¥äžã§è¡šãããã
1è¡ç®ã¯2ã€ã®æŽæ°<var> Q </var>,<var> L </var>ãã¹ããŒã¹åºåãã§äžããããã
ç¶ã<var> Q </var>è¡ã«ã¯ãäžèšã§èª¬æããã¯ãšãªãŒã<var> Q </var>åäžããããã
å
¥åã®çµããã¯2ã€ã®ãŒããããªãã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>å
¥åã«å«ãŸããå€ã¯ãã¹ãп޿°</li>
<li>1 ≤<var> Q </var>≤ 100000</li>
<li>1 ≤<var> L </var>≤ 10<sup>9</sup></li>
<li>1 ≤<var> d </var>,<var> k </var>≤ 10<sup>9</sup></li>
<li>0 ≤<var> x </var>≤<var> L </var></li>
<li>0 ≤<var> r </var>≤ 10<sup>9</sup></li>
<li>åãäœçœ®ã«ã€ã³ããŒããŒã2äœä»¥äžååšããããšã¯ãªã</li>
<li>ããŒã¿ã»ããã®æ°ã¯3å以äž</li>
</ul>
<h2>Output</h2>
<p>åããŒã¿ã»ããã«ã€ããåºåã®æç€ºãããã¯ãšãªãŒã«å¯ŸããŠåºåãããåããŒã¿ã»ããã®æåŸã«ã¯"end"ãåºåããã</p>
<h2>Sample Input</h2>
<pre>
18 10
0
4 1
1 1
4 1
0
1 1
0
2 2
1 10
0
1 1
0
1 1
0
1 5
3 4 0
3 4 1
0
9 10
4 1
2 2
3 5 5
0
4 1
2 2
3 5 5
0
2 1
0 0
</pre>
<h2>Sample Output</h2>
<pre>
distance 10
distance 9
hit
damage 2
bomb 1
bomb 2
end
distance -1
miss
bomb 0
distance 10
miss
bomb 1
hit
end
</pre> |
p03192 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer <var>N</var> that has exactly four digits in base ten.
How many times does <code>2</code> occur in the base-ten representation of <var>N</var>?</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1000 \leq N \leq 9999</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1222
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<p><code>2</code> occurs three times in <code>1222</code>. By the way, this contest is held on December <var>22</var> (JST).</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3456
</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>9592
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre></section>
</div>
</span> |
p03468 | <span class="lang-en">
<p>Score : <var>2100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You have a circle of length <var>C</var>, and you are placing <var>N</var> arcs on it. Arc <var>i</var> has length <var>L_i</var>.</p>
<p>Every arc <var>i</var> is placed on the circle uniformly at random:
a random real point on the circle is chosen, then an arc of length <var>L_i</var> centered at this point appears.</p>
<p>Note that the arcs are placed independently. For example, they may intersect or contain each other.</p>
<p>What is the probability that every real point of the circle will be covered by at least one arc?
Assume that an arc covers its ends.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 6</var></li>
<li><var>2 \leq C \leq 50</var></li>
<li><var>1 \leq L_i < C</var></li>
<li>All input values are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>C</var>
<var>L_1</var> <var>L_2</var> <var>...</var> <var>L_N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the probability that every real point of the circle will be covered by at least one arc.
Your answer will be considered correct if its absolute error doesn't exceed <var>10^{-11}</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>0.3333333333333333
</pre>
<p>The centers of the two arcs must be at distance at least <var>1</var>. The probability of this on a circle of length <var>3</var> is <var>1 / 3</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4 10
1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0.0000000000000000
</pre>
<p>Even though the total length of the arcs is exactly <var>C</var> and it's possible that every real point of the circle is covered by at least one arc,
the probability of this event is <var>0</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 2
1 1 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0.5000000000000000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>3 5
2 2 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0.4000000000000000
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>4 6
4 1 3 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>0.3148148148148148
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 6</h3><pre>6 49
22 13 27 8 2 19
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 6</h3><pre>0.2832340720702695
</pre></section>
</div>
</span> |
p01455 |
<H1>Problem I: ãããããäºééæ³</H1>
<p>
çŽæ
§æŠ2119 幎15 ã®æã宮廷éè¡å£«Sengemon Lugene ã®æã«ãã£ãŠãäžåã®éè¡æžãæžãèšãããããã®éè¡æžãIn Magirayãã¯ããã®äžçã®éè¡æ³åã®æ ¹å¹¹ã«æ·±ãé¢ãããäºééæ³ããã誰ã«ã§ãç¿åŸå¯èœãªæè¡ãšããŠäœç³»åããããšããç¹ã§é©æ°çãªæžç©ã§ãã£ãããŸãã¯ããã®æžç©ã®å
容ãèŠçŽãããã®ãèŠãŠãããã
</p>
<p>
ããšã¬ã¡ã³ãã<br>
äžçäžã®ããããç©äœã¯ããæ³ãã颚ãã矜ããè±ããç ããç¯ãâŠâŠãšãã£ããæ¥µå°èŠçŽ ããšã¬ã¡ã³ããããæ§æãããŠããããšã¬ã¡ã³ãã«ã¯å€ãã®çš®é¡ãããã人éã¯ãšã¬ã¡ã³ããšå¥çŽã亀ããããšã§ãå¥çŽã亀ãããçš®é¡ã®ãšã¬ã¡ã³ããçšããäºééæ³ãçºåãããããšãã§ããã
</p>
<p>
ãäºééæ³ã<br>
äºééæ³ãšã¯ããã®åã®éããïŒã€ã®ãšã¬ã¡ã³ããéãåãããŠè§£ãæŸã€éæ³ã§ãããäž»ãšãªããšã¬
ã¡ã³ãããäž»å±æ§ããããäžæ¹ããå¯å±æ§ããšåŒã¶ãããšãã°ãäž»å±æ§ããç¯ãã§å¯å±æ§ããè±ããª
ãããã®äºééæ³ã¯ïŒç¯ïŒè±ïŒãšè¡šèšããããïŒç¯ïŒè±ïŒãšïŒè±ïŒç¯ïŒã¯å¥ã®äºééæ³ã§ããããŸããäž»å±æ§ãšå¯å±æ§ã¯åãã§ãã£ãŠãããã
</p>
<p>
ãããŒã¯ãŒãã<br>
ãæ³â hudaãã颚â loarãã矜â shezaããè±â leideããšãã£ãããã«ãåã
ã®ãšã¬ã¡ã³ãã«ãããããçããããŒã¯ãŒãããïŒå¯ŸïŒå¯Ÿå¿ãããããšãã§ãããããŒã¯ãŒãã¯ããšã¬ã¡ã³ãã®æã€æ§è³ªãçãèšèã«è±¡åŸŽãããããšã§ãããã€ãã®é£ç¶ããããŒã¯ãŒãåãå±ããã ãã§ç°¡åã«äºééæ³ãçºåãããããšãå¯èœã«ãããç»æçãªæŠå¿µã§ããã
</p>
<p>
ãåªæã<br>
ãhudaã»leideã»loarã»shezaãã®ããã«ãïŒã€ä»¥äžã®ããŒã¯ãŒããé£ç¶ããŠäžŠã¹ããã®ããåªæããšãããè¡è
ãæå³ããåªæãå±ããããšã§ã察å¿ããäºééæ³ãçºåãããããšãã§ãããå
·äœçã«ã¯ãåªæã®äžçªæåã®ããŒã¯ãŒãã«å¯Ÿå¿ãããšã¬ã¡ã³ããäž»å±æ§ãäžçªæåŸã®ããŒã¯ãŒãã«å¯Ÿå¿ãããšã¬ã¡ã³ããå¯å±æ§ãšããäºééæ³ãçºåãããå
ã»ã©ã®åªæã®äŸã ãšãçºåããäºééæ³ã¯ïŒæ³ïŒçŸœïŒã§ããããªããåªæãïŒã€ã®ããŒã¯ãŒãã ãããæãå Žåã«ã¯ãäž»å±æ§ãå¯å±æ§ãããã®ããŒã¯ãŒãã«å¯Ÿå¿ãããšã¬ã¡ã³ãã«ãªãã
</p>
<p>
ããšã¬ã¡ã³ãå士ã®çžæ§ã<br>
ãhudaã»leideã»loarã»shezaãã®åªæã§ïŒæ³ïŒçŸœïŒã®äºééæ³ãçºåããããšã¯ãã§ã«è¿°ã¹ããããããäžèŠãããšãïŒæ³ïŒçŸœïŒã䜿ãããã®ãªãã°ãããããé·ãåªæãå±ãããšããhudaã»shezaãã ãã§è¯ãããã«ãæãããã ãå®éã«ã¯ãããã¯äžå¯èœã§ããããªããªãããæ³ïŒhudaïŒããšã矜ïŒshezaïŒãã¯çžæ§ãè¯ããªãããããããïŒã€ãé£ãåã£ãåªæãå±ãããšãåçºäœçšãèµ·ãã£ãŠãšã¬ã¡ã³ãå士ãçžæ®ºããŠããŸãããã§ãããäžæ¹ã§ããæ³ïŒhudaïŒããšãè±ïŒleideïŒãããè±ïŒleideïŒããšã颚ïŒloarïŒããã颚ïŒloarïŒããšã矜ïŒshezaïŒãã¯ãã©ã®ãã¢ãå¥œçžæ§ãªã®ã§ããhudaã»leideã»loarã»shezaãããloarã»leideã»hudaããšãã£ãåªæã§ã¯ããšã¬ã¡ã³ãã®çžæ®ºã¯èµ·ãããªãã
</p>
<p>
ãåªæè«çã<br>
äºééæ³ã䜿ãããšããè
ã¯ããããããããã¹ãŠã®å¥œçžæ§ãªãšã¬ã¡ã³ãã®ãã¢ããããã«å¯ŸããŠã
ã©ã¡ãã®ããŒã¯ãŒãããäžäœã¯ãŒããã§ãã©ã¡ãã®ããŒã¯ãŒãããäžäœã¯ãŒãããªã®ããå®çŸ©ããŠãããªããã°ãªããªããå¥œçžæ§ãªïŒã€ã®ãšã¬ã¡ã³ãã®ããŒã¯ãŒãã<i>A</i>ããšã<i>B</i>ãã«å¯ŸããŠã<i>A</i> ãäžäœã¯ãŒãã<i>B</i> ãäžäœã¯ãŒããšå®çŸ©ãããšãã<i>A</i> > <i>B</i> ãšè¡šèšããã<i>A</i> > <i>B</i> ã§ãããšããäžã€ã®åªæå
ã§ã<i>B</i> ã®çŽåŸã«<i>A</i> ã䞊ã¹ãããšã¯ã§ããªããã€ãŸããã<i>A</i><sub>1</sub>ã»<i>A</i><sub>2</sub>ã»<i>A</i><sub>3</sub>ã»âŠâŠã»<i>A<sub>k</sub></i>ããæ£ããåªæã§ãããªãã°ã<i>A</i><sub>1</sub> > <i>A</i><sub>2</sub>ïŒ<i>A</i><sub>2</sub> > <i>A</i><sub>3</sub>ïŒâŠâŠïŒ<i>A</i><sub><i>k</i>-1</sub> > <i>A<sub>k</sub></i> ã§ãªããŠã¯ãªããªããã¡ãªã¿ã«ã<i>A</i> > <i>B</i> ãã€<i>B</i> > <i>C</i> ã§ãã£ãŠãã<i>A</i> > <i>C</i> ã§ããå¿
èŠã¯ãªãã
</p>
<p>
ãã®ããã«ãåã
ã®è¡è
ããäžäœã»äžäœã¯ãŒããèªå奜ã¿ã«å®çŸ©ããããšããåªæè«çã®æ§ç¯ããšåŒ
ã¶ãããã¯ããããŠåªæã®æ§æã«å¶çŽãããããããšã§ããšã¬ã¡ã³ãã®æµããæç¢ºåããç®çã®äºé
éæ³ã®æå確çãäžããããã®å·¥å€«ã§ãããã ãããã®ä»£åãšããŠãåªæè«çãæ§ç¯ãããšãã©ã®ã
ãã«åªæãå±ããŠãçºåãããããšã®ã§ããªãäºééæ³ãçããŠããŸãå¯èœæ§ãããïŒãã ãããã
ãªãåªæè«çãæ§ç¯ããŠã䜿ãããšã®ã§ããªãäºééæ³ã¯ååšããªãããšã蚌æãããŠããïŒããã®
ãããªäºæ
ããããããã©ã®ãããªåªæè«çãæ§ç¯ãããã¯ãä»ãæãå€ãã®éè¡å£«ãæ©ãŸããŠãã
åä»ãªåé¡ãªã®ã§ããã
</p>
<p>
ãšããå°ããªçºã§æ®ããèŠç¿ãéè¡å£«ã®å°å¹ŽãŠãŒãã¯ããã¹ãŠã®ãšã¬ã¡ã³ããšã®å¥çŽãçµããããã
ãææ¥ãèªåã®åªæè«çãæ§ç¯ããããã®ååŒãè¡ãããšããŠããããŠãŒãã¯åçŽã«ãã§ããã ãã
ãããã®çš®é¡ã®äºééæ³ãçºåãããããšãã§ãããããªåªæè«çãè¯ãåªæè«çã§ããããšèããŠ
ããã
</p>
<p>
è¶
äžçŽé»è¡æåž«ïŒçŸä»£æ¥æ¬ã§èšããšããã®ã¹ãŒããŒããã°ã©ããŒïŒã§ããããªãã¯ãåéã®ãŠãŒãã
ããããŸãåªæè«çãæ§ç¯ããããšãã§ããã°ãæå€§ã§äœçš®é¡ã®äºééæ³ã䜿ããããã«ãªãã®ãç¥
ããããšçžè«ãåãããããã¯ãä»ãŸã§äžçäžã®äººéãææŠããŠãããã誰ãè§£ãããšãã§ããªãã£
ãã»ã©ã®é£åã§ããããããè§£ãããšãã§ããã°ãããªãã®ååã¯æªæ¥æ°žå«ãäžçäžã§èªãç¶ããã
ããšã«ãªãã§ãããã
</p>
<H2>Input</H2>
<p>
<i>N M</i><br>
<i>s</i><sub>1</sub><br>
<i>s</i><sub>2</sub><br>
.<br>
.<br>
.<br>
<i>s<sub>N</sub></i><br>
<i>p</i><sub>1</sub> <i>q</i><sub>1</sub>
<i>p</i><sub>2</sub> <i>q</i><sub>2</sub>
.<br>
.<br>
.<br>
<i>p<sub>M</sub> <q<sub>M</sub></i><br>
</p>
<p>
å
¥åã®ïŒè¡ç®ã«ã¯ãæŽæ°<i>N</i> ãšæŽæ°<i>M</i> ãã空çœåºåãã§æžãããŠãããããã¯ããšã¬ã¡ã³ããå
šéšã§<i>N</i> çš®é¡ãå¥œçžæ§ãªãšã¬ã¡ã³ãã®ãã¢ãå
šéšã§<i>M</i> çµååšããããšãããããã
</p>
<p>
ç¶ã<i>N</i> è¡ã«ã¯ãïŒã€ã®æååãæžãããŠãããïŒïŒ i è¡ç®ã«æžãããæåå<i>s<sub>i</sub></i> ã¯ãi çªç®ã®ãšã¬ã¡ã³ãã«å¯Ÿå¿ããããŒã¯ãŒãã<i>s<sub>i</sub></i> ã§ããããšãããããã
</p>
<p>
ç¶ãM è¡ã«ã¯ãïŒã€ã®æååã空çœåºåãã§æžãããŠãããïŒïŒ <i>N</i> ïŒ i è¡ç®ã«æžãããæåå<i>p<sub>i</sub></i> ãš<i>q<sub>i</sub></i> ã¯ãããŒã¯ãŒã<i>p<sub>i</sub></i> ã«å¯Ÿå¿ãããšã¬ã¡ã³ããšãããŒã¯ãŒã<i>q<sub>i</sub></i> ã«å¯Ÿå¿ãããšã¬ã¡ã³ãã®ãã¢ããå¥œçžæ§ã§ããããšããããããéã«ãããã«ãããããªãã£ããšã¬ã¡ã³ãã®ãã¢ã¯ãå¥œçžæ§ã§ã¯ãªãã
</p>
<p>
ãããã®ããŒã¿ã¯ã以äžã®æ¡ä»¶ãã¿ããã
</p>
<ul>
<li>2 ≤ <i>N</i> ≤ 100</li>
<li>1 ≤ <i>M</i> ≤ 4,950</li>
<li><i>s<sub>i</sub></i> ã¯ãã¢ã«ãã¡ãããã®å€§æåãŸãã¯å°æåã®ã¿ãããªãã1 æå以äž15 æå以äžã®æåå</li>
<li><i>i</i> ≠ <i>j</i> ãâã<i>s<sub>i</sub></i> ≠ <i>s<sub>j</sub></i></li>
<li><i>p<sub>i</sub></i> ≤ <i>q<sub>i</sub></i></li>
<li><i>i</i> ≤ <i>j</i> ãâã(<i>p<sub>i</sub></i>, <i>q<sub>i</sub></i>) ≠ (<i>p<sub>j</sub></i>, <i>q<sub>j</sub></i>) ãã€(<i>p<sub>i</sub></i>, <i>q<sub>i</sub></i>) ≠ (<i>q<sub>j</sub></i>, <i>p<sub>j</sub></i>)</li>
<li>ãããªãåªæè«çãæ§ç¯ããŠãçºåããããšã®ã§ããªãäºééæ³ã¯ååšããªã</li>
</ul>
<H2>Output</H2>
<p>
åªæè«çãæ§ç¯ãããšãã䜿çšå¯èœã«ãªãäºééæ³ã®çš®é¡ã®æå€§æ°ãåºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
4 3
huda
leide
loar
sheza
huda leide
leide loar
loar sheza
</pre>
<h2>Sample Output 1</h2>
<pre>
10
</pre>
<h2>Sample Input 2</h2>
<pre>
3 3
torn
siole
dimi
torn siole
torn dimi
siole dimi
</pre>
<h2>Sample Output 2</h2>
<pre>
9
</pre>
<h2>Sample Input 3</h2>
<pre>
9 10
riris
soa
elah
clar
arma
memori
neoles
qhaon
clue
clar riris
riris memori
riris neoles
soa clar
soa memori
neoles elah
elah qhaon
neoles qhaon
clue riris
arma elah
</pre>
<h2>Sample Output 3</h2>
<pre>
54
</pre>
|
p00614 |
<H1><font color="#000000">Problem J:</font> ICPC: Ideal Coin Payment and Change</H1>
<p>
Taro, a boy who hates any inefficiencies, pays coins so that the number of coins to be returned as change is minimized in order to do smoothly when he buys something.
</p>
<p>
One day, however, he doubt if this way is really efficient. When he pays more number of coins, a clerk consumes longer time to find the total value. Maybe he should pay with least possible number of coins.
</p>
<p>
Thinking for a while, he has decided to take the middle course. So he tries to minimize total number of paid coins and returned coins as change.
</p>
<p>
Now he is going to buy a product of P yen having several coins. Since he is not good at calculation, please write a program that computes the minimal number of coins.
</p>
<p>
You may assume following things:
</p>
<ul>
<li>There are 6 kinds of coins, 1 yen, 5 yen, 10 yen, 50 yen, 100 yen and 500 yen.</li>
<li>The total value of coins he has is at least <i>P</i> yen.</li>
<li>A clerk will return the change with least number of coins.</li>
</ul>
<H2>Input</H2>
<p>
Input file contains several data sets.
One data set has following format:
</p>
<pre>
<i>P</i> <i>N</i><sub>1</sub> <i>N</i><sub>5</sub> <i>N</i><sub>10</sub> <i>N</i><sub>50</sub> <i>N</i><sub>100</sub> <i>N</i><sub>500</sub>
</pre>
<p>
<i>N<sub>i</sub></i> is an integer and is the number of coins of <i>i</i> yen that he have.
</p>
<p>
The end of input is denoted by a case where <i>P</i> = 0. You should output nothing for this data set.
</p>
<H2>Output</H2>
<p>
Output total number of coins that are paid and are returned.
</p>
<H2>Constraints</H2>
<ul>
<li>Judge data contains at most 100 data sets.</li>
<li>0 ≤ <i>N<sub>i</sub></i> ≤ 1000 </li>
</ul>
<H2>Sample Input</H2>
<pre>
123 3 0 2 0 1 1
999 9 9 9 9 9 9
0 0 0 0 0 0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
6
3
</pre>
|
p02629 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p><var>1000000000000001</var> dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered <var>1</var> through <var>1000000000000001</var>, but he gave them new names, as follows:</p>
<ul>
<li>the dogs numbered <var>1,2,\cdots,26</var> were respectively given the names <code>a</code>, <code>b</code>, ..., <code>z</code>;</li>
<li>the dogs numbered <var>27,28,29,\cdots,701,702 </var> were respectively given the names <code>aa</code>, <code>ab</code>, <code>ac</code>, ..., <code>zy</code>, <code>zz</code>;</li>
<li>the dogs numbered <var>703,704,705,\cdots,18277,18278 </var> were respectively given the names <code>aaa</code>, <code>aab</code>, <code>aac</code>, ..., <code>zzy</code>, <code>zzz</code>;</li>
<li>the dogs numbered <var>18279,18280,18281,\cdots,475253,475254 </var> were respectively given the names <code>aaaa</code>, <code>aaab</code>, <code>aaac</code>, ..., <code>zzzy</code>, <code>zzzz</code>;</li>
<li>the dogs numbered <var>475255,475256,\cdots </var> were respectively given the names <code>aaaaa</code>, <code>aaaab</code>, ...;</li>
<li>and so on.</li>
</ul>
<p>To sum it up, the dogs numbered <var>1, 2, \cdots</var> were respectively given the following names:</p>
<p><code>a</code>, <code>b</code>, ..., <code>z</code>, <code>aa</code>, <code>ab</code>, ..., <code>az</code>, <code>ba</code>, <code>bb</code>, ..., <code>bz</code>, ..., <code>za</code>, <code>zb</code>, ..., <code>zz</code>, <code>aaa</code>, <code>aab</code>, ..., <code>aaz</code>, <code>aba</code>, <code>abb</code>, ..., <code>abz</code>, ..., <code>zzz</code>, <code>aaaa</code>, ...</p>
<p>Now, Roger asks you:</p>
<p>"What is the name for the dog numbered <var>N</var>?"</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>N</var> is an integer.</li>
<li><var> 1 \leq N \leq 1000000000000001</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the answer to Roger's question as a string consisting of lowercase English letters.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>b
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>27
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>aa
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>123456789
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>jjddja
</pre></section>
</div>
</span> |
p01906 |
<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>B: éãã®ç¯å²</h1>
<h2>åé¡</h2>
<p>
éãã®ç°ãªã $N$ è²ã®ããŒã«ããã¥ãŒã«ããããå
¥ã£ãŠããŸãããã¥ãŒã«ã¯ãå
é ãã
$1,2,3, \dots ,N-1,N,1,2,3, \dots ,N-1,N,1,2,3, \dots$ ãšãããµãã«æé ã«ããŒã«ã䞊ãã§ããŠã
è² $N$ ã®ããŒã«ã®åŸãã«ã¯ãŸãè² $1$ ã®ããŒã«ããé ã«å
¥ã£ãŠããŸãã
åãè²ã®ããŒã«ã¯ããããåãéãã§ãããè² $i$ ã®ããŒã«ã®éã㯠$A_i$ ã§ãã
</p>
<p>
ãã®ç¶æ
ããããã¥ãŒã®å
é ããããŒã«ã $M$ ååãåºããããã 1 ã€ã®ã°ã«ãŒããšããäœæ¥ãç¹°ãè¿ããŸãã
ãããŠããã¥ãŒããåãåºããåè²ã®ããŒã«ã®ç·æ°ããã¹ãŠçãããªã£ããšãã«ã°ã«ãŒããäœãäœæ¥ããããŸãã
ãªãããã¥ãŒã«ã¯ååãªæ°ã®ããŒã«ãå
¥ã£ãŠãããã°ã«ãŒããäœãäœæ¥ãããããŸã§ã«ãã¥ãŒã®äžèº«ã空ã«ãªãããšã¯ãããŸããã
</p>
<p>
ããšãã°ã
$N=8, M=2$ ã®ãšãã{è²1,è²2}, {è²3,è²4}, {è²5,è²6}, {è²7,è²8} ã® 4 ã°ã«ãŒããã§ããŸã
(ãã®ãšãåè²ã®ããŒã«ã¯ 1 ã€ãã€ååšãã)ã
$N=4, M=3$ ã®ãšãã{è²1,è²2,è²3}, {è²4,è²1,è²2}, {è²3,è²4,è²1}, {è²2,è²3,è²4} ã® $4$
ã°ã«ãŒããã§ããŸã (ãã®ãšãåè²ã®ããŒã«ã¯ãããã3ã€ãã€ååšãã)ã
</p>
<p>
ãã®ãšããåã°ã«ãŒãã«ãããŠã
å«ãŸããããŒã«ã®éãã®æå€§å€ãšæå°å€ã®å·®ããã®ã°ã«ãŒãã®<strong>éãã®ç¯å²</strong>ãšåŒã¶ããšã«ããŸãã
åã°ã«ãŒãã®éãã®ç¯å²ã®ç·åãåºåããŠãã ããã
</p>
<h2>å¶çŽ</h2>
<ul>
<li>$1 \le N \le 1000$</li>
<li>$1 \le M \le N$</li>
<li>$0 \le A_i \le 100$</li>
<li>å
¥åã¯å
šãп޿°ã§ãã</li>
</ul>
<h2>å
¥å圢åŒ</h2>
<p>
å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<p>
$N \ M$<br>
$A_1 \cdots A_N$
</p>
<h2>åºå</h2>
<p>
çãã 1 è¡ã§åºåããŠãã ããããŸããæ«å°Ÿã«æ¹è¡ãåºåããŠãã ããã
</p>
<h2>ãµã³ãã«</h2>
<h3>ãµã³ãã«å
¥å 1</h3>
<pre>
8 2
23 61 57 13 91 41 79 41
</pre>
<h3>ãµã³ãã«åºå 1</h3>
<pre>
170
</pre>
<p>
éãã®ç¯å²ã®ç·å㯠$38+44+50+38=170$ ãšãªããŸãã
</p>
<h3>ãµã³ãã«å
¥å 2</h3>
<pre>
4 3
72 46 67 5
</pre>
<h3>ãµã³ãã«åºå 2</h3>
<pre>
222
</pre>
<p>
éãã®ç¯å²ã®ç·å㯠$26+67+67+62=222$ ãšãªããŸãã
</p>
<h3>ãµã³ãã«å
¥å 3</h3>
<pre>
4 2
1 2 3 5
</pre>
<h3>ãµã³ãã«åºå 3</h3>
<pre>
3
</pre>
<p>
éãã®ç¯å²ã®ç·å㯠$1+2=3$ ãšãªããŸãã
</p> |
p02783 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Serval is fighting with a monster.</p>
<p>The <em>health</em> of the monster is <var>H</var>.</p>
<p>In one attack, Serval can decrease the monster's health by <var>A</var>.
There is no other way to decrease the monster's health.</p>
<p>Serval wins when the monster's health becomes <var>0</var> or below.</p>
<p>Find the number of attacks Serval needs to make before winning.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq H \leq 10^4</var></li>
<li><var>1 \leq A \leq 10^4</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>H</var> <var>A</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of attacks Serval needs to make before winning.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>10 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>3
</pre>
<ul>
<li>After one attack, the monster's health will be <var>6</var>.</li>
<li>After two attacks, the monster's health will be <var>2</var>.</li>
<li>After three attacks, the monster's health will be <var>-2</var>.</li>
</ul>
<p>Thus, Serval needs to make three attacks to win.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1 10000
</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>10000 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>10000
</pre></section>
</div>
</span> |
p03891 | <span class="lang-en">
<p>Score : <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>A <var>3Ã3</var> grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the top left corner to the bottom right corner, and from the top right corner to the bottom left corner), all add up to the same sum.</p>
<p>You are given the integers written in the following three squares in a magic square:</p>
<ul>
<li>The integer <var>A</var> at the upper row and left column</li>
<li>The integer <var>B</var> at the upper row and middle column</li>
<li>The integer <var>C</var> at the middle row and middle column</li>
</ul>
<p>Determine the integers written in the remaining squares in the magic square.</p>
<p>It can be shown that there exists a unique magic square consistent with the given information.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>0 \leq A, B, C \leq 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>A</var>
<var>B</var>
<var>C</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Output the integers written in the magic square, in the following format:</p>
<pre><var>X_{1,1}</var> <var>X_{1,2}</var> <var>X_{1,3}</var>
<var>X_{2,1}</var> <var>X_{2,2}</var> <var>X_{2,3}</var>
<var>X_{3,1}</var> <var>X_{3,2}</var> <var>X_{3,3}</var>
</pre>
<p>where <var>X_{i,j}</var> is the integer written in the square at the <var>i</var>-th row and <var>j</var>-th column.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>8
3
5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8 3 4
1 5 9
6 7 2
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>1
1
1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1 1 1
1 1 1
1 1 1
</pre></section>
</div>
</span> |
p00244 |
<H1>æž©æ³æ
è¡</H1>
<p>
æž©æ³å¥œãã®ãããããã¯ã次ã®é·æäŒæãå©çšããŠãšããæž©æ³å°ãžã®æ
è¡ãèšç»ããŠããŸããç§»åã¯é·è·é¢ãã¹ãä¹ãç¶ãããªãã¹ããéããããã«ç®çå°ãžãã©ãçããããšæã£ãŠããŸãã貯éããããšã¯ãããè³éã«å¿èš±ãªããããããã¯ããããããã«çžè«ããããšã«ããŸãããèšç»ãèããŠæå¿ãããããããã¯ããããããã«ç¹å¥ãªåç¬Šãæž¡ããŸããã
</p>
<p>
ãã®å笊ã¯ãé·è·é¢ãã¹ã®é£ç¶ãã2åºéã1åã ãç¡æã§ä¹ãããšãããã®ã§ããã䜿ãããã«ãã£ãŠã¯ããªãã®ç§»åè²»åæžãèŠèŸŒããŸããããã倧ããªå¹æãçºæ®ãããããã«ã¯ãã£ããããèšç»ãç·Žãå¿
èŠããããŸãã
</p>
<p>
åºçºå°ãšç®çå°ãåã³äžç¶å°ç¹ãåãã㊠<var>n</var> åã2ã€ã®å°ç¹ãçµã¶è·¯ç·ã <var>m</var> åäžããããŸããåå°ç¹ã«ã¯ãããã 1 ãã <var>n</var> ãŸã§ã®æ°åãå²ãæ¯ãããŠããŸããåºçºå°ã¯ 1ãç®çå°ã¯ <var>n</var> ã§ããè·¯ç·ã®æ
å ±ã¯ããã®è·¯ç·ãçµã¶2ã€ã®å°ç¹ <var>a</var> ãš <var>b</var>ãåã³ãã®æé <var>c</var> ã§è¡šãããŸããç¹å¥ãªå笊ã®å¹åã«ãããä»»æã®å°ç¹ãããäžåºŠã ãé£ç¶ãã2ã€ã®è·¯ç·ãæé0ã§ééããããšãã§ããŸãããã ããéäžã§ç®çå°ãééããŠããç®çå°ã«ãã©ãçããããšã«ã¯ãªããŸããã
</p>
<p>
åºçºå°ãç®çå°ãåã³äžç¶å°ç¹ã®ç·æ° <var>n</var> ãšè·¯ç·ã®æ° <var>m</var>ãåè·¯ç·ã®æ
å ±ãå
¥åãšããæéã®æå°å€ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããå¿
ãåºçºå°ããç®çå°ãžãšå°éããçµè·¯ãååšãããã®ãšããŸãã</p>
<h2>å
¥å</h2>
<p>
è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var> <var>m</var>
<var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var>
<var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var>
:
<var>a<sub>m</sub></var> <var>b<sub>m</sub></var> <var>c<sub>m</sub></var>
</pre>
<p>
1è¡ç®ã«åºçºå°ãç®çå°ãåã³äžç¶å°ç¹ã®ç·æ° <var>n</var> (2 ≤ <var>n</var> ≤ 100)ãšè·¯ç·ã®æ° <var>m</var> (1 ≤ <var>m</var> ≤ 300)ãäžããããŸããç¶ã <var>m</var> è¡ã«åè·¯ç·ã®æ
å ± <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 1000) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 40 ãè¶
ããŸããã
</p>
<h2>åºå</h2>
<p>
å
¥åããŒã¿ã»ããããšã«ãæéã®æå°å€ã1è¡ã«åºåããŸãã
</p>
<h2>å
¥åäŸ</h2>
<pre>
2 1
1 2 5
3 2
1 2 5
2 3 5
6 9
1 2 7
1 3 9
1 5 14
2 3 10
2 4 15
3 4 11
3 5 2
4 5 9
4 6 8
0 0
</pre>
<h2>åºåäŸ</h2>
<pre>
5
0
7
</pre> |
p02279 | <H1>Rooted Trees</H1>
<p>
A graph <i>G</i> = (<i>V</i>, <i>E</i>) is a data structure where <i>V</i> is a finite set of vertices and <i>E</i> is a binary relation on <i>V</i> represented by a set of edges. Fig. 1 illustrates an example of a graph (or graphs).
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_7_A_1"><br>
<b>Fig. 1</b>
</center>
<p>
A free tree is a connnected, acyclic, undirected graph. A rooted tree is a free tree in which one of the vertices is distinguished from the others. A vertex of a rooted tree is called "node."
</p>
<p>
Your task is to write a program which reports the following information for each node <i>u</i> of a given rooted tree <i>T</i>:
</p>
<ul>
<li>node ID of <i>u</i></li>
<li>parent of <i>u</i></li>
<li>depth of <i>u</i></li>
<li>node type (root, internal node or leaf)</li>
<li>a list of chidlren of <i>u</i></li>
</ul>
<p>
If the last edge on the path from the root <i>r</i> of a tree <i>T</i> to a node <i>x</i> is (<i>p</i>, <i>x</i>), then <i>p</i> is the <b>parent</b> of <i>x</i>, and <i>x</i> is a <b>child</b> of <i>p</i>. The root is the only node in <i>T</i> with no parent.
</p>
<!--
<p>
If two nodes have the same parent, they are <b>siblings</b>.
</p>
-->
<p>
A node with no children is an <b>external node</b> or <b>leaf</b>. A nonleaf node is an <b>internal node</b>
</p>
<p>
The number of children of a node <i>x</i> in a rooted tree <i>T</i> is called the <b>degree</b> of <i>x</i>.
</p>
<p>
The length of the path from the root <i>r</i> to a node <i>x</i> is the <b>depth</b> of <i>x</i> in <i>T</i>.
</p>
<p>
Here, the given tree consists of <i>n</i> nodes and evey node has a unique ID from 0 to <i>n</i>-1.
</p>
<p>
Fig. 2 shows an example of rooted trees where ID of each node is indicated by a number in a circle (node). The example corresponds to the first sample input.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_7_A_2"><br>
<b>Fig. 2</b>
</center>
<H2>Input</H2>
<p>
The first line of the input includes an integer <i>n</i>, the number of nodes of the tree.
</p>
<p>
In the next <i>n</i> lines, the information of each node <i>u</i> is given in the following format:
</p>
<p>
<i>id</i> <i>k</i> <i>c</i><sub>1</sub> <i>c</i><sub>2</sub> ... <i>c<sub>k</sub></i>
</p>
<p>
where <i>id</i> is the node ID of <i>u</i>, <i>k</i> is the degree of <i>u</i>, <i>c</i><sub>1</sub> ... <i>c<sub>k</sub></i> are node IDs of 1st, ... <i>k</i>th child of <i>u</i>. If the node does not have a child, the <i>k</i> is 0.
</p>
<H2>Output</H2>
<p>
Print the information of each node in the following format ordered by IDs:
</p>
<p>
<span>node</span> <i>id</i><span>: </span><span>parent = </span><i>p</i><span>, depth = </span><i>d</i><span>, <i>type</i><span>, [</span><i>c</i><sub>1</sub>...<i>c<sub>k</sub></i><span>]</span>
</p>
<p>
<i>p</i> is ID of its parent. If the node does not have a parent, print <spna>-1</span>.
</p>
<p>
<i>d</i> is depth of the node.
</p>
<p>
<i>type</i> is a type of nodes represented by a string (<span>root</span>, <span>internal node</span> or <span>leaf</span>). If the root can be considered as a leaf or an internal node, print <span>root</span>.
</p>
<p>
<i>c</i><sub>1</sub>...<i>c<sub>k</sub></i> is the list of children as a ordered tree.
</p>
<p>
Please follow the format presented in a sample output below.
</p>
<H2>Constraints</H2>
<ul>
<li>1 ≤ <i>n</i> ≤ 100000</li>
</ul>
<H2>Sample Input 1</H2>
<pre>
13
0 3 1 4 10
1 2 2 3
2 0
3 0
4 3 5 6 7
5 0
6 0
7 2 8 9
8 0
9 0
10 2 11 12
11 0
12 0
</pre>
<H2>Sample Output 1</H2>
<pre>
node 0: parent = -1, depth = 0, root, [1, 4, 10]
node 1: parent = 0, depth = 1, internal node, [2, 3]
node 2: parent = 1, depth = 2, leaf, []
node 3: parent = 1, depth = 2, leaf, []
node 4: parent = 0, depth = 1, internal node, [5, 6, 7]
node 5: parent = 4, depth = 2, leaf, []
node 6: parent = 4, depth = 2, leaf, []
node 7: parent = 4, depth = 2, internal node, [8, 9]
node 8: parent = 7, depth = 3, leaf, []
node 9: parent = 7, depth = 3, leaf, []
node 10: parent = 0, depth = 1, internal node, [11, 12]
node 11: parent = 10, depth = 2, leaf, []
node 12: parent = 10, depth = 2, leaf, []
</pre>
<H2>Sample Input 2</H2>
<pre>
4
1 3 3 2 0
0 0
3 0
2 0
</pre>
<H2>Sample Output 2</H2>
<pre>
node 0: parent = 1, depth = 1, leaf, []
node 1: parent = -1, depth = 0, root, [3, 2, 0]
node 2: parent = 1, depth = 1, leaf, []
node 3: parent = 1, depth = 1, leaf, []
</pre>
<h2>Note</h2>
<p>
You can use a <b>left-child, right-sibling representation</b> to implement a tree which has the following data:
</p>
<ul>
<li>the parent of <i>u</i></li>
<li>the leftmost child of <i>u</i></li>
<li>the immediate right sibling of <i>u</i></li>
</ul>
<!--
<p>
<a href="template/ALDS1_7_A_template.c">Template in C</a>
</p>
-->
<H2>Reference</H2>
<p>
Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
</p>
|
p01286 |
<H1><font color="#000">Problem D:</font> Luigi's Tavern</H1>
<p>
Luigi's Tavern is a thriving tavern in the Kingdom of Nahaila. The owner of the tavern Luigi supports to
organize a party, because the main customers of the tavern are adventurers. Each adventurer has a job:
hero, warrior, cleric or mage.
</p>
<p>
Any party should meet the following conditions:
</p>
<ul>
<li> A party should have a hero.</li>
<li> The warrior and the hero in a party should get along with each other.</li>
<li> The cleric and the warrior in a party should get along with each other.</li>
<li> The mage and the cleric in a party should get along with each other.</li>
<li> It is recommended that a party has a warrior, a cleric, and a mage, but it is allowed that at most
<i>N<sub>W</sub></i>, <i>N<sub>C</sub></i> and <i>N<sub>m</sub></i> parties does not have a warrior, a cleric, and a mage respectively.</li>
<li> A party without a cleric should have a warrior and a mage.</li>
</ul>
<p>
Now, the tavern has <i>H</i> heroes, <i>W</i> warriors, <i>C</i> clerics and <i>M</i> mages. Your job is to write a program to find the maximum number of parties they can form.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
The first line of the input contains 7 non-negative integers <i>H</i>, <i>W</i>, <i>C</i>, <i>M</i>, <i>N<sub>W</sub></i>, <i>N<sub>C</sub></i>, and <i>N<sub>M</sub></i>, each of which is less than or equals to 50. The <i>i</i>-th of the following <i>W</i> lines contains the list of heroes who will be getting along with the warrior <i>i</i>. The list begins with a non-negative integer <i>n<sub>i</sub></i> , less than or equals to <i>H</i>. Then the rest of the line should contain ni positive integers, each of which indicates the ID of a hero getting along with the warrior <i>i</i>.
</p>
<p>
After these lists, the following <i>C</i> lines contain the lists of warriors getting along with the clerics in the same manner. The <i>j</i>-th line contains a list of warriors who will be getting along with the cleric <i>j</i>. Then the last <i>M</i> lines of the input contain the lists of clerics getting along with the mages, of course in the same
manner. The <i>k</i>-th line contains a list of clerics who will be getting along with the mage <i>k</i>.
</p>
<p>
The last dataset is followed by a line containing seven negative integers. This line is not a part of any dataset and should not be processed.
</p>
<H2>Output</H2>
<p>
For each dataset, you should output the maximum number of parties possible.
</p>
<H2>Sample Input</H2>
<pre>
2 1 1 1 1 1 1
1 1
1 1
1 1
1 1 1 1 0 0 0
1 1
1 1
1 1
1 0 1 0 1 0 1
0
1 1 0 1 0 1 0
0
0
1 1 0 1 0 1 0
1 1
0
-1 -1 -1 -1 -1 -1 -1
</pre>
<H2>Output for the Sample Input</H2>
<pre>
2
1
1
0
1
</pre>
|
p02853 | <span class="lang-en">
<p>Score: <var>100</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3>
<p>We held two competitions: Coding Contest and Robot Maneuver.</p>
<p>In each competition, the contestants taking the <var>3</var>-rd, <var>2</var>-nd, and <var>1</var>-st places receive <var>100000</var>, <var>200000</var>, and <var>300000</var> yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional <var>400000</var> yen.</p>
<p>DISCO-Kun took the <var>X</var>-th place in Coding Contest and the <var>Y</var>-th place in Robot Maneuver.
Find the total amount of money he earned.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3>
<ul>
<li><var>1 \leq X \leq 205</var></li>
<li><var>1 \leq Y \leq 205</var></li>
<li><var>X</var> and <var>Y</var> are integers.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3>
<p>Input is given from Standard Input in the following format:</p>
<pre><var>X</var> <var>Y</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3>
<p>Print the amount of money DISCO-Kun earned, as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1000000
</pre>
<p>In this case, he earned <var>300000</var> yen in Coding Contest and another <var>300000</var> yen in Robot Maneuver. Furthermore, as he won both competitions, he got an additional <var>400000</var> yen.
In total, he made <var>300000 + 300000 + 400000 = 1000000</var> yen.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 101
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>100000
</pre>
<p>In this case, he earned <var>100000</var> yen in Coding Contest.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>0
</pre>
<p>In this case, unfortunately, he was the highest-ranked contestant without prize money in both competitions.</p></section>
</div>
</span> |
p03741 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>. The <var>i</var>-th term in the sequence is <var>a_i</var>.
In one operation, you can select a term and either increment or decrement it by one.</p>
<p>At least how many operations are necessary to satisfy the following conditions?</p>
<ul>
<li>For every <var>i</var> <var>(1â€iâ€n)</var>, the sum of the terms from the <var>1</var>-st through <var>i</var>-th term is not zero.</li>
<li>For every <var>i</var> <var>(1â€iâ€n-1)</var>, the sign of the sum of the terms from the <var>1</var>-st through <var>i</var>-th term, is different from the sign of the sum of the terms from the <var>1</var>-st through <var>(i+1)</var>-th term.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 †n †10^5</var></li>
<li><var>|a_i| †10^9</var></li>
<li>Each <var>a_i</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>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_n</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the minimum necessary count of operations.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>4
1 -3 1 0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>4
</pre>
<p>For example, the given sequence can be transformed into <var>1, -2, 2, -2</var> by four operations. The sums of the first one, two, three and four terms are <var>1, -1, 1</var> and <var>-1</var>, respectively, which satisfy the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5
3 -6 4 -5 7
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>0
</pre>
<p>The given sequence already satisfies the conditions.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6
-1 4 3 2 -5 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>8
</pre></section>
</div>
</span> |
p03311 | <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke has an integer sequence <var>A</var> of length <var>N</var>.</p>
<p>He will freely choose an integer <var>b</var>.
Here, he will get sad if <var>A_i</var> and <var>b+i</var> are far from each other.
More specifically, the <em>sadness</em> of Snuke is calculated as follows:</p>
<ul>
<li><var>abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))</var></li>
</ul>
<p>Here, <var>abs(x)</var> is a function that returns the absolute value of <var>x</var>.</p>
<p>Find the minimum possible sadness of Snuke.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 2 \times 10^5</var></li>
<li><var>1 \leq 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 minimum possible sadness of Snuke.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5
2 2 3 5 5
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>If we choose <var>b=0</var>, the sadness of Snuke would be <var>abs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2</var>.
Any choice of <var>b</var> does not make the sadness of Snuke less than <var>2</var>, so the answer is <var>2</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9
1 2 3 4 5 6 7 8 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>6
6 5 4 3 2 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>18
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>7
1 1 1 1 2 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>6
</pre></section>
</div>
</span> |
p00497 |
<H1>é(Nails)</H1>
<p>
JOI ããã¯æ¿ã«éãåºããŠéãã§ããïŒäžå³ã®ããã«ïŒJOI ããã¯äžèŸº<i>N</i> æ¬ã®æ£äžè§åœ¢ã®åœ¢ã«éã䞊ã¹ãŠåºããïŒäžãã<i>a</i> è¡ç®(1 ≤ <i>a</i> ≤ <i>N</i>) ã«ã¯<i>a</i> æ¬ã®éã䞊ãã§ããïŒãã®ãã¡å·Šãã<i>b</i> æ¬ç®(1 ≤ <i>b</i> ≤ <i>a</i>) ã®éã(<i>a</i>, <i>b</i>) ã§è¡šãïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_nails1"><br>
<b>
å³1: éã®äžŠã³æ¹ïŒ<i>N</i> = 5 ã®å ŽåïŒ
</b>
</center>
<br>
<p>
éãé ç¹ãšããæ£äžè§åœ¢ãïŒãå蟺ãå
šäœã®æ£äžè§åœ¢ã®èŸºã®ãããããšå¹³è¡ã§ïŒå
šäœã®æ£äžè§åœ¢ãšåãåããã§ãããšãïŒãã®æ£äžè§åœ¢ãã<b>ããæ£äžè§åœ¢</b>ããšåŒã¶ïŒããªãã¡ïŒãããæ£äžè§åœ¢ããšã¯ïŒ3 æ¬ã®é(<i>a</i>, <i>b</i>), (<i>a</i> + <i>x</i>, <i>b</i>), (<i>a</i> + <i>x</i>, <i>b</i> + <i>x</i>) ãé ç¹ãšããæ£äžè§åœ¢ã®ããšã§ããïŒãã ã<i>a</i>, <i>b</i>, <i>x</i> ã¯1 ≤ <i>a</i> < <i>N</i>, 1 ≤ <i>b</i> ≤ <i>a</i>, 1 ≤ <i>x</i> ≤ <i>N</i> - <i>a</i>) ãã¿ããïŒïŒ
</p>
<p>
JOI ããã¯ïŒèŒªãŽã ã䜿ã£ãŠïŒãããæ£äžè§åœ¢ãã®åšããå²ãããšã«ããïŒ
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_nails2"><br>
<b>
å³2: 茪ãŽã ã«ãããããæ£äžè§åœ¢ãã®å²ãæ¹ã®äŸ
</b>
</center>
<br>
<h2>課é¡</h2>
<p>
æ£äžè§åœ¢ã®äžèŸºã«äžŠãã§ããéã®æ¬æ°<i>N</i> ãšïŒJOI ãããæã£ãŠãã茪ãŽã ã®æ°<i>M</i> ãšïŒ<i>M</i> æ¬ã®èŒªãŽã ã«ãããããæ£äžè§åœ¢ãã®å²ãæ¹ãäžãããããšãïŒ1 æ¬ä»¥äžã®èŒªãŽã ã§å²ãããéã®æ¬æ°ãæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å¶é</h2>
<p>
2 ≤ <i>N</i> ≤ 5000 äžèŸºã«äžŠãã§ããéã®æ¬æ°<br>
1 ≤ <i>M</i> ≤ 500000 (= 5 × 10<sup>5</sup>) 茪ãŽã ã®æ°
</p>
<h2>å
¥å</h2>
<p>
æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ
</p>
<ul>
<li> 1 è¡ç®ã«ã¯æŽæ°<i>N</i>, <i>M</i> ã空çœãåºåããšããŠæžãããŠããïŒ<i>N</i> ã¯æ£äžè§åœ¢ã®äžèŸºã«äžŠãã§ããéã®æ¬æ°ãïŒ<i>M</i> ã¯JOI ããã®æã£ãŠãã茪ãŽã ã®æ°ããããã衚ãïŒ</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>X<sub>i</sub></i> (1 ≤ <i>A<sub>i</sub></i> < <i>N</i>, 1 ≤ <i>B<sub>i</sub></i> ≤ <i>A<sub>i</sub></i>, 1 ≤ <i>X<sub>i</sub></i> ≤ <i>N</i> - <i>A<sub>i</sub></i>) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒ<i>i</i>æ¬ç®ã®èŒªãŽã ã¯3 æ¬ã®é(<i>A<sub>i</sub></i>, <i>B<sub>i</sub></i>), (<i>A<sub>i</sub></i> + <i>X<sub>i</sub></i>, <i>B<sub>i</sub></i>), (<i>A<sub>i</sub></i> + <i>X<sub>i</sub></i>, <i>B<sub>i</sub></i> + <i>X<sub>i</sub></i>) ãé ç¹ãšãããããæ£äžè§åœ¢ããå²ã£ãŠããããšã衚ãïŒ
</ul>
<h2>åºå</h2>
<p>
æšæºåºåã«ïŒ1 æ¬ä»¥äžã®èŒªãŽã ã«å²ãããŠããéã®æ¬æ°ã1 è¡ã§åºåããïŒ
</p>
<h2>æ¡ç¹åºæº</h2>
<p>
æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®30% åã«ã€ããŠã¯ïŒ<i>M</i> ≤ 10000 ãæºããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
5 2
2 2 1
2 1 3
</pre>
<h3>åºåäŸ 1</h3>
<pre>
12
</pre>
<p>
ãã®äŸã¯å³2 ã®ãããªãããæ£äžè§åœ¢ãã®å²ãæ¹ã«å¯Ÿå¿ããŠããïŒãã®äŸã«ãããŠïŒ(1, 1), (4, 4), (5, 5) 以å€ã®12 æ¬ã®éã1 æ¬ä»¥äžã®èŒªãŽã ã§å²ãããŠããïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
|
p02150 | <h1>Problem B: Milk</h1>
<h2>Problem</h2>
<p>
ã¡ããã©$a$æ¬ã®çä¹³ã®ç©ºãç¶ãæã£ãŠãããšæ°ãã«$b$æ¬ã®çä¹³ã®å
¥ã£ãç¶ãšäº€æã§ããã<br>
æåã«$x$æ¬ã®çä¹³ã®å
¥ã£ãç¶ãæã£ãŠããå·æããã¯ãæå€§äœæ¬åã®çä¹³ã飲ããã ãããã$1000000007$ã§å²ã£ãäœããåºåããã<br>
</p>
<h2>Input</h2>
<p>å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã</p>
<pre>
$a$ $b$ $x$
</pre>
<p>
3ã€ã®æŽæ°$a$, $b$, $x$ã空çœåºåãã§äžããããã
</p>
<h2>Constraints</h2>
<p>å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã</p>
<ul>
<li>$1 \leq a \leq 10^{15} $</li>
<li>$0 \leq b \lt a $</li>
<li>$0 \leq x \leq 10^{15} $</li>
</ul>
<h2>Output</h2>
<p>
çãã1è¡ã«åºåããã
</p>
<h2>Sample Input 1</h2>
<pre>
3 1 5
</pre>
<h2>Sample Output 1</h2>
<pre>
7
</pre>
<h2>Sample Input 2</h2>
<pre>
3 2 5
</pre>
<h2>Sample Output 2</h2>
<pre>
11
</pre>
<h2>Sample Input 3</h2>
<pre>
82 69 64
</pre>
<h2>Sample Output 3</h2>
<pre>
64
</pre>
<h2>Sample Input 4</h2>
<pre>
316250877917604 316250877917599 681260158257385
</pre>
<h2>Sample Output 4</h2>
<pre>
62687552
</pre>
|
p02015 | <h2>A: ãç (Paken)</h2>
<p>ããªãã¯ãç éšå¡ã§ããããã"Paken" ãšåºåããªããã</p>
<h3>å
¥å</h3>
<p>ãã®åé¡ã«ã¯å
¥åã¯äžããããªãã</p>
<h3>åºå</h3>
<p>"Paken" ãš 1 è¡ã«åºåããŠãã ããã</p>
<p><span style="color:red">æåŸã®æ¹è¡ãå¿ããªãããã«ããŸãããã</span> å¿
èŠãªç©ºçœãæ¹è¡ããªãã£ãããäœèšãªç©ºçœãæ¹è¡ãåºåãããš'Presentation Error'ãšãªãäžæ£è§£ã«ãªã£ãŠããŸããŸãã®ã§ã泚æããŠãã ããã</p>
<h3>å
¥åäŸ</h3>
<pre>
(No input)
</pre>
<h3>åºåäŸ</h3>
<pre>
Paken
</pre>
<h3>泚æ</h3>
<p>Pã¯å€§æåããã®ããšã¯å°æåã§ããããšã«æ³šæããŠãã ããã</p>
|
p00028 |
<h1>Mode Value</h1>
<p>
Your task is to write a program which reads a sequence of integers and prints mode values of the sequence.
The mode value is the element which occurs most frequently.
</p>
<H2>Input</H2>
<p>
A sequence of integers <var>a<sub>i</sub></var> (1 ≤ <var>a<sub>i</sub></var> ≤ 100). The number of integers is less than or equals to 100.
</p>
<H2>Output</H2>
<p>
Print the mode values. If there are several mode values, print them in ascending order.
</p>
<H2>Sample Input</H2>
<pre>
5
6
3
5
8
7
5
3
9
7
3
4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
3
5
</pre>
<p>
For example, 3 and 5 respectively occur three times, 7 occurs two times, and others occur only one. So, the mode values are 3 and 5.
</p>
|
p02445 | <h1>Swap</h1>
<p>
Write a program which reads a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ and swap specified elements by a list of the following operation:
</p>
<ul>
<li>swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.</li>
</ul>
<h2>Input</h2>
<p>
The input is given in the following format.
</p>
<pre>
$n$
$a_0 \; a_1 \; ...,\; a_{n-1}$
$q$
$b_1 \; e_1 \; t_1$
$b_2 \; e_2 \; t_2$
:
$b_{q} \; e_{q} \; t_{q}$
</pre>
<p>
In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; e_i \; t_i$ in the following $q$ lines.
</p>
<h2>Output</h2>
<p>
Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element.
</p>
<h2>Constraints</h2>
<ul>
<li>$1 \leq n \leq 1,000$</li>
<li>$-1,000,000,000 \leq a_i \leq 1,000,000,000$</li>
<li>$1 \leq q \leq 1,000$</li>
<li>$0 \leq b_i < e_i \leq n$</li>
<li>$0 \leq t_i < t_i + (e_i - b_i) \leq n$</li>
<li>Given swap ranges do not overlap each other</li>
</ul>
<h2>Sample Input 1</h2>
<pre>
11
1 2 3 4 5 6 7 8 9 10 11
1
1 4 7
</pre>
<h2>Sample Output 1</h2>
<pre>
1 8 9 10 5 6 7 2 3 4 11
</pre>
|
p00478 |
<H1>æèŒª (Ring)</H1>
<h2>åé¡</h2>
<p>
ããªã㯠N åã®æèŒªãæã£ãŠããïŒã©ã®æèŒªã«ãïŒã¢ã«ãã¡ãããã®å€§æå 10 æåãããªãæååãå»å°ãããŠããïŒæèŒªã«ã¯æååã®æåãšæåŸãã€ãªãã£ãåœ¢ã§æåãå»å°ãããŠããïŒæèŒªã«å»å°ãããæååãéé ã«èªãå¿é
ã¯ãªãïŒ
</p>
<p>
æ¢ãããæååãäžãããããšãïŒãã®æååãå«ãæèŒªãäœåããããæ±ããããã°ã©ã ãäœæããïŒ
</p>
<h2>å
¥å</h2>
<p>
å
¥å㯠2+N è¡ãããªãïŒ<br>
1 è¡ç®ã«ã¯ïŒ1 æåä»¥äž 10 æå以äžã®ã¢ã«ãã¡ãããã®å€§æåãããªãæ¢ãããæååãæžãããŠããïŒ<br>
2 è¡ç®ã«ã¯ïŒæèŒªã®åæ° N ( 1 ⊠N ⊠100 )ãæžãããŠããïŒ<br>
2+i è¡ç®(1 ≤ i ≤ N )ã«ã¯ïŒ i åç®ã®æèŒªã«å»å°ãããŠãã 10 æåãããªãæååãæžãããŠããïŒ
</p>
<h2>åºå</h2>
<p>
æ¢ãããæååãå«ãæèŒªã®åæ°ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ
</p>
<h2>å
¥åºåäŸ</h2>
<h3>å
¥åäŸ 1</h3>
<pre>
ABCD
3
ABCDXXXXXX
YYYYABCDXX
DCBAZZZZZZ
</pre>
<h3>åºåäŸ 1</h3>
<pre>
2
</pre>
<br>
<h3>å
¥åäŸ 2</h3>
<pre>
XYZ
1
ZAAAAAAAXY
</pre>
<h3>åºåäŸ 2</h3>
<pre>
1
</pre>
<p>
å
¥åäŸ 2 ã®æèŒªã«ã¯ãXYZããšããæååã 1 ã€å«ãŸããŠããïŒããã¯ãæèŒªã®æååã®æåãšæåŸãã€ãªãã£ãŠããããã§ããïŒ
</p>
<br>
<h3>å
¥åäŸ 3</h3>
<pre>
PQR
3
PQRAAAAPQR
BBPQRBBBBB
CCCCCCCCCC
</pre>
<h3>åºåäŸ 3</h3>
<pre>
2
</pre>
<p>
å
¥åäŸ 3 ã® 1 åç®ã®æèŒªã«ã¯ãPQRããšããæååã 2 ã€å«ãŸããŠããïŒ 2 åç®ã®æèŒªã«ã¯ãPQRããšããæååã 1 åå«ãŸããŠããïŒ 3 åç®ã®æèŒªã«ã¯ãPQRããšããæååãå«ãŸããŠããªãïŒãã®ãããPQRããšããæååãå«ãŸããŠããæèŒªã®æ°ã¯ 2 åãšãªãïŒ
</p>
<div class="source">
<p class="source">
å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã<a href="http://www.ioi-jp.org">æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ</a>ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
</p>
</div>
<br> |
p00182 |
<H1>ããŒã«ãŒ</H1>
<p>
ãããããªå®¹éã®ããŒã«ãŒãäžããããŠããŸããã¯ããã«ããã®äžã®äžçªå®¹éã®å€§ããªããŒã«ãŒãäžåéžã³ãèå£ããæ°Žããã£ã±ãã«ãªããŸã§æ³šããŸããã€ãã«ã次ã®ã«ãŒã«ã«ãããããªãããããŒã«ãŒã®æ°Žãä»ã®ããŒã«ãŒã«ç§»ãæ¿ããŠãããŸãã
</p>
<ul>
<li>ããŒã«ãŒã«å
¥ã£ãŠããæ°Žã¯,æ®ããã«ãã¹ãŠä»ã®ããŒã«ãŒã«ç§»ããªããã°ãªããªãããã ããäžåã®ããŒã«ãŒã«æ°Žãå
šéšç§»ããªããšãã¯ãè€æ°ã®ããŒã«ãŒã«åããŠç§»ããŠãããã</li>
<li>ããŒã«ãŒã«æ°Žãå
¥ãããšãããã£ã±ãã«ãªããŸã§æ°Žã泚ããªããã°ãªããªãããŸããæ°ŽãããŒããŠã¯ãªããªãã</li>
<li>è€æ°ã®ããŒã«ãŒããåãããŒã«ãŒã«äžåºŠã«æ°Žã泚ãã§ã¯ãªããªãã</li>
<li>åãããŒã«ãŒã«ã¯äžåºŠããæ°Žã泚ãã§ã¯ãªããªãã</li>
</ul>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck200810">
<br/><br/>
</center>
<p>
ãã®ã«ãŒã«ã«ãããã£ããšããããŒã«ãŒã®åæ° <var>n</var> ãšåããŒã«ãŒã®å®¹éãå
¥åãšãããã¹ãŠã®ããŒã«ãŒã«æ°Žã泚ãããšãã§ãããã©ãããå€å®ããŠåºåããããã°ã©ã ãäœæããŠãã ããããã¹ãŠã®ããŒã«ãŒã«æ°Žã泚ãããšãã§ãããšã㯠YES (åè§è±å€§æå)ãã§ããªããšã㯠NO (åè§è±å€§æå) ãåºåããŠãã ããã
</p>
<H2>Input</H2>
<p>
è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã
</p>
<pre>
<var>n</var>
<var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>n</sub></var>
</pre>
<p>
1 è¡ç®ã«ããŒã«ãŒã®åæ° <var>n</var> (1 ≤ <var>n</var> ≤ 50) ãäžããããŸããïŒè¡ç®ã« <var>i</var> çªç®ã®ããŒã«ãŒã®å®¹éãè¡šãæŽæ° <var>c<sub>i</sub></var> (1 ≤ <var>c<sub>i</sub></var> ≤ 100) ãäžããããŸãã
</p>
<p>
ããŒã¿ã»ããã®æ°ã¯ 105 ãè¶
ããŸããã
</p>
<H2>Output</H2>
<p>
ããŒã¿ã»ããæ¯ã«å€å®çµæãïŒè¡ã«åºåããŸãã
</p>
<H2>Sample Input</H2>
<pre>
10
11 2 23 4 2 12 8 5 2 10
8
2 1 3 11 2 3 1 4
9
5 9 1 2 4 8 17 1 8
8
3 38 9 4 18 14 19 5
1
1
0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
YES
YES
NO
YES
</pre>
|
p02916 | <span class="lang-en">
<p>Score : <var>200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi went to an all-you-can-eat buffet with <var>N</var> kinds of dishes and ate all of them (Dish <var>1</var>, Dish <var>2</var>, <var>\ldots</var>, Dish <var>N</var>) once.</p>
<p>The <var>i</var>-th dish <var>(1 \leq i \leq N)</var> he ate was Dish <var>A_i</var>.</p>
<p>When he eats Dish <var>i</var> <var>(1 \leq i \leq N)</var>, he gains <var>B_i</var> satisfaction points.</p>
<p>Additionally, when he eats Dish <var>i+1</var> just after eating Dish <var>i</var> <var>(1 \leq i \leq N - 1)</var>, he gains <var>C_i</var> more satisfaction points.</p>
<p>Find the sum of the satisfaction points he gained.</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 20</var></li>
<li><var>1 \leq A_i \leq N</var></li>
<li><var>A_1, A_2, ..., A_N</var> are all different.</li>
<li><var>1 \leq B_i \leq 50</var></li>
<li><var>1 \leq C_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>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
<var>B_1</var> <var>B_2</var> <var>...</var> <var>B_N</var>
<var>C_1</var> <var>C_2</var> <var>...</var> <var>C_{N-1}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the sum of the satisfaction points Takahashi gained, as an integer.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3
3 1 2
2 5 4
3 6
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>14
</pre>
<p>Takahashi gained <var>14</var> satisfaction points in total, as follows:</p>
<ul>
<li>First, he ate Dish <var>3</var> and gained <var>4</var> satisfaction points.</li>
<li>Next, he ate Dish <var>1</var> and gained <var>2</var> satisfaction points.</li>
<li>Lastly, he ate Dish <var>2</var> and gained <var>5 + 3 = 8</var> satisfaction points.</li>
</ul>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
2 3 4 1
13 5 8 24
45 9 15
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>74
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>2
1 2
50 50
50
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>150
</pre></section>
</div>
</span> |
p01639 |
<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 F: MLE</h1>
<p class="ndoc-top">ICPC World Finals 4æ¥ç®</p>
<p class="ndoc-top">æãåµã®å€ã ã£ãã 倢ã®äžã§ãã£ãŒæ°ã¯ã¿ã€ã ã¹ãªããããŠããã
ICPCã®äŒå Žã®ããã ãäœãããããâŠã ãããâŠããã¯ãN幎åïŒNã¯èªç¶æ°ïŒã®ICPCãªã®ãâŠ? æ··ä¹±ã®å
ã«ç«¶æã¯éå§ããŠããŸã£ãã
ã ãæ
ãŠãå¿
èŠã¯ãªãã ãã£ãšåé¡ãç°¡åã«éããªãã äŸãã°ãããªã©ã¯ãœãŒãããã ãã§è§£ããŠããŸãã¯ãã§ã¯ãªããã
å·éã«ã³ãŒããæžãäžããéããã«Submitã</p>
<p class="ndoc-top">ããããã®çµæã¯âŠMemory Limit ExceededâŠ?!</p>
<h2 class="ndoc-heading2">åé¡</h2>
<p class="ndoc-top">C++èšèªã«ã€ããŠã¯ä»¥äžã®ã³ãŒã</p>
<pre>
long long int a[n];
unsigned long long int x = x0;
for (int i = 0; i < n; i++) {
a[i]=(long long int)x;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
}
</pre>
<p>Javaèšèªã«ã€ããŠã¯ä»¥äžã®ã³ãŒã</p>
<pre>
long[] a = new long[n];
long x = x0;
for(int i = 0; i < n; i++){
a[i] = x;
x ^= x << 13;
x ^= x >>> 7;
x ^= x << 17;
}
</pre>
<p>ã§äžããããæ¬äŒŒä¹±æ°å\( a[0], a[1], \cdots, a[n-1] \)ãæé ã«ãœãŒãããã \(k\)çªç®ã®æ°ïŒ\(
a[k-1] \)ïŒãçããã</p>
<h2 class="ndoc-heading2">å
¥å</h2>
<pre>
n k x0
</pre>
<p>1è¡ç®ã« æ¬äŒŒä¹±æ°åã®é·ã\(n\)ã æ±ããã€ã³ããã¯ã¹\(k\)ã ã³ãŒãäžã®åæå€\(x0\) ã空çœåºåãã§äžããããã</p>
<h2 class="ndoc-heading2">åºå</h2>
<p class="ndoc-top">å顿ã«ãŠå®çŸ©ãããæ¬äŒŒä¹±æ°åã«ãããŠ\(k\)çªç®ã«å°ããæ°ã1è¡ã«åºåããã</p>
<h2 class="ndoc-heading2">å¶çŽ</h2>
<ul class="ndoc-indent">
<li>\( 0 \leq x0 \leq 9 \)</li>
<li>\( 1 \leq n \leq 10^{8}(= 100000000) \)</li>
<li>\( 1 \leq k \leq n \)</li>
</ul>
<h2 class="ndoc-heading2">å
¥åºåäŸ</h2>
<h3 class="ndoc-heading3">å
¥å1</h3>
<pre>
20 10 1
</pre>
<h3 class="ndoc-heading3">åºå1</h3>
<pre>
-768720241707614171
</pre>
<p>
ãã®å
¥åã«ãããŠçæãããæ°åã¯ä»¥äžã®éãã§ããã
</p>
<pre>
1
1082269761
1152992998833853505
-7269227409276787159
-768720241707614171
-8787613929710185883
-670945072575735807
-6753709453369041295
-4166779903597258483
9024654201992055039
8332670729032836398
2074683623940568804
-1176172910426220663
5632491372296299238
-8006175397324373085
-8536891001451786268
-3486562341448986757
1956468987595729445
-6260278484400246991
1076885984028793263
</pre>
<h3 class="ndoc-heading3">å
¥å2</h3>
<pre>
1000000 100 2
</pre>
<h3 class="ndoc-heading3">åºå2</h3>
<pre>
-9221458681145860019
</pre>
<h3 class="ndoc-heading3">å
¥å3</h3>
<pre>
100000000 10000000 3
</pre>
<h3 class="ndoc-heading3">åºå3</h3>
<pre>
-7379326796154077070
</pre> |
p03604 | <span class="lang-en">
<p>Score : <var>1200</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>There are <var>2N</var> balls in the <var>xy</var>-plane. The coordinates of the <var>i</var>-th of them is <var>(x_i, y_i)</var>.
Here, <var>x_i</var> and <var>y_i</var> are integers between <var>1</var> and <var>N</var> (inclusive) for all <var>i</var>, and no two balls occupy the same coordinates.</p>
<p>In order to collect these balls, Snuke prepared <var>2N</var> robots, <var>N</var> of type A and <var>N</var> of type B.
Then, he placed the type-A robots at coordinates <var>(1, 0), (2, 0), ..., (N, 0)</var>, and the type-B robots at coordinates <var>(0, 1), (0, 2), ..., (0, N)</var>, one at each position.</p>
<p>When activated, each type of robot will operate as follows.</p>
<ul>
<li>
<p>When a type-A robot is activated at coordinates <var>(a, 0)</var>, it will move to the position of the ball with the lowest <var>y</var>-coordinate among the balls on the line <var>x = a</var>, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p>
</li>
<li>
<p>When a type-B robot is activated at coordinates <var>(0, b)</var>, it will move to the position of the ball with the lowest <var>x</var>-coordinate among the balls on the line <var>y = b</var>, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.</p>
</li>
</ul>
<p>Once deactivated, a robot cannot be activated again. Also, while a robot is operating, no new robot can be activated until the operating robot is deactivated.</p>
<p>When Snuke was about to activate a robot, he noticed that he may fail to collect all the balls, depending on the order of activating the robots.</p>
<p>Among the <var>(2N)!</var> possible orders of activating the robots, find the number of the ones such that all the balls can be collected, modulo <var>1</var> <var>000</var> <var>000</var> <var>007</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2 \leq N \leq 10^5</var></li>
<li><var>1 \leq x_i \leq N</var></li>
<li><var>1 \leq y_i \leq N</var></li>
<li>If <var>i â j</var>, either <var>x_i â x_j</var> or <var>y_i â y_j</var>.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var>
<var>x_1</var> <var>y_1</var>
<var>...</var>
<var>x_{2N}</var> <var>y_{2N}</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Outputs</h3><p>Print the number of the orders of activating the robots such that all the balls can be collected, modulo <var>1</var> <var>000</var> <var>000</var> <var>007</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2
1 1
1 2
2 1
2 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>8
</pre>
<p>We will refer to the robots placed at <var>(1, 0)</var> and <var>(2, 0)</var> as A1 and A2, respectively, and the robots placed at <var>(0, 1)</var> and <var>(0, 2)</var> as B1 and B2, respectively.
There are eight orders of activation that satisfy the condition, as follows:</p>
<ul>
<li>A1, B1, A2, B2</li>
<li>A1, B1, B2, A2</li>
<li>A1, B2, B1, A2</li>
<li>A2, B1, A1, B2</li>
<li>B1, A1, B2, A2</li>
<li>B1, A1, A2, B2</li>
<li>B1, A2, A1, B2</li>
<li>B2, A1, B1, A2</li>
</ul>
<p>Thus, the output should be <var>8</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>4
3 2
1 2
4 1
4 2
2 2
4 4
2 1
1 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>7392
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4
1 1
2 2
3 3
4 4
1 2
2 1
3 4
4 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4480
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>8
6 2
5 1
6 8
7 8
6 5
5 7
4 3
1 4
7 6
8 3
2 8
3 6
3 2
8 5
1 5
5 8
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>82060779
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 5</h3><pre>3
1 1
1 2
1 3
2 1
2 2
2 3
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 5</h3><pre>0
</pre>
<p>When there is no order of activation that satisfies the condition, the output should be <var>0</var>.</p></section>
</div>
</span> |
p01269 |
<h1><font color="#000">Problem C:</font> Brave Princess Revisited</h1>
<p>
ããè²§ä¹ãªåœã®ããŠãã°ã§åæ¢ãªãå§«æ§ãïŒæ¿ç¥çµå©ã®ããå¥ã®åœã«å«ãããšã«ãªã£ãïŒãšããããå§«æ§ã亡ãè
ãšããããšããŠããæªæŒ¢ãå«ãå
ãžã®éã®éäžã§åºå®¢ãæŸã£ãŠããïŒ
</p>
<p>
ãå§«æ§ãç¡äºã«çžæåœã«éãå±ããããïŒããªãã¯å®å
šãªçµè·¯ãæ¢ã«æ±ºå®ããŠããã®ã ãïŒãå§«æ§ã®ä»ãŸã§ã«éã£ãããšã®ãªãéãéã£ãŠã¿ãããšãã<s>ãããŸãŸãª</s>ãã£ãŠã®é¡ãã§å¥ã®éãéãããšãšãªã£ãïŒããã§ããªãã¯å°å³ãèŠãªãããå§«æ§ãéãéãæ±ºããªããããšã«ããïŒ
</p>
<p>
å
šãŠã®éã¯ïŒå®¿å Žå士ãã€ãªãè¡éã§ããïŒäŸ¿å®äžïŒåºçºå°ç¹åã³ç®çå°ç¹ãå®¿å ŽãšããïŒãšãããïŒæ°ããéã¯æ²»å®ã®åé¡ãæ±ããŠããïŒçè³ããå§«æ§ã亡ãè
ã«ããããšããåºå®¢ã襲ãããã£ãŠããå¯èœæ§ãé«ãã®ã§ããïŒ
</p>
<p>
ãã®ãããªå±éºãªéãéãã«ã¯è·è¡ãéãããšãæãŸããïŒè·è¡ã¯å®¿å Žã§éãããšãã§ãïŒéåäœã§å§«ãå®ãããããšãã§ããïŒè·è¡ãå®ã£ãŠããéã¯çè³ãåºå®¢ã«è¥²ãããããšã¯ãªããïŒè·é¢ 1 ã«ã€ãé 1 ããããïŒãã®ããïŒè·è¡ãéãããã«ã¯ææéãããæ¬¡ã®å®¿å ŽãŸã§ã®è·é¢ãé·ããªãããšãæ¡ä»¶ãšãªãïŒ
</p>
<p>
ããŸïŒäžããããäºç® <i>L</i> ã®ããšã§ïŒå§«ãç¡äºã«ç®çå°ã«çããŸã§ã«è¥²ãããã£ãŠããçè³ãåºå®¢ã®äººæ°ãæå°åããããšãèããïŒããªãã®ä»äºã¯ïŒãã®æå°åããã人æ°ãæ±ããããšã§ããïŒãªãïŒå®¿å Žã«ããéã«è¥²ãããããšã¯ãªããã®ãšããïŒ
</p>
<h3>Input</h3>
<p>
å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒãããŠããïŒ
</p>
<blockquote>
<i>N</i> <i>M</i> <i>L</i><br>
<i>A</i><sub>1</sub> <i>B</i><sub>1</sub> <i>D</i><sub>1</sub> <i>E</i><sub>1</sub><br>
<i>A</i><sub>2</sub> <i>B</i><sub>2</sub> <i>D</i><sub>2</sub> <i>E</i><sub>2</sub><br>
...<br>
<i>A</i><sub><i>M</i></sub> <i>B</i><sub><i>M</i></sub> <i>D</i><sub><i>M</i></sub> <i>E</i><sub><i>M</i></sub>
</blockquote>
<p>
æåã®è¡ã«ã¯ 3 ã€ã®éè² ã®æŽæ° <i>N</i> (2 ≤ <i>N</i> ≤ 100)ïŒ<i>M</i>ïŒ <i>L</i> (0 ≤ <i>L</i> ≤ 100) ãäžããããïŒãããã®æŽæ°ã¯ïŒå®¿å Žã®æ°ïŒéã®æ°ïŒè·è¡ãéãããã®äºç®ã衚ãïŒå®¿å Žã«ã¯ 1 ãã <i>N</i> ãŸã§ã®çªå·ãå²ãæ¯ãããŠããïŒåºçºå°ã«ã¯ 1 ïŒç®çå°ã«ã¯ <i>N</i> ã®çªå·ãããããå²ãæ¯ãããŠããïŒ
</p>
<p>
ç¶ã <i>M</i> è¡ã§ã¯éã®æ
å ±ãåè¡ã« 1 ã€ãã€äžããããïŒéã®æ
å ±ã¯ 4 ã€ã®æŽæ° <i>A</i><sub><i>i</i></sub>ïŒ<i>B</i><sub><i>i</i></sub> (1 ≤ <i>A</i><sub><i>i</i></sub> < <i>B</i><sub><i>i</i></sub> ≤ N)ïŒ <i>D</i><sub><i>i</i></sub> (1 ≤ <i>D</i><sub><i>i</i></sub> ≤ 100) <i>E</i><sub><i>i</i></sub> (0 ≤ <i>E</i><sub><i>i</i></sub> ≤ 10000) ã§äžããããïŒãããã¯ããããïŒéã®å§ç¹ãšçµç¹ã®å®¿å Žã®çªå·ïŒéã®è·é¢ïŒçè³ãåºå®¢ã«è¥²ããã人æ°ã衚ãïŒ
</p>
<p>
éã¯åæ¹åã«éè¡å¯èœã§ããïŒãã€ããå®¿å Žã®çµã«å¯ŸããŠã¯é«ã
1 ã€ã®éããååšããªãïŒãŸãïŒåºçºå°ããç®çå°ã«ã¯å¿
ãç§»åå¯èœã§ããããšãä¿èšŒãããŠããïŒ
</p>
<p>
å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã 3 ã€ã® 0 ãå«ã 1 è¡ã§ç€ºãããïŒ
</p>
<h3>Output</h3>
<p>
åããŒã¿ã»ããã«ã€ããŠïŒçè³ãåºå®¢ã«è¥²ããã人æ°ã®æå°å€ãåè¡ã«åºåããïŒåºåã«äœèšãªç©ºçœãæ¹è¡ãå«ããŠã¯ãªããªãïŒ
</p>
<h3>Sample Input</h3>
<pre>
3 2 10
1 2 8 6
2 3 10 3
3 2 10
1 2 3 8
2 3 7 7
3 3 10
1 3 17 6
1 2 2 4
2 3 9 13
4 4 5
1 3 9 3
1 4 7 25
2 3 8 2
2 4 9 3
0 0 0
</pre>
<h3>Output for the Sample Input</h3>
<pre>
3
0
4
8
</pre>
|
p03254 | <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> children, numbered <var>1, 2, ..., N</var>.</p>
<p>Snuke has decided to distribute <var>x</var> sweets among them.
He needs to give out all the <var>x</var> sweets, but some of the children may get zero sweets.</p>
<p>For each <var>i</var> (<var>1 \leq i \leq N</var>), Child <var>i</var> will be <em>happy</em> if he/she gets exactly <var>a_i</var> sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.</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 100</var></li>
<li><var>1 \leq x \leq 10^9</var></li>
<li><var>1 \leq a_i \leq 10^9</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>x</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 possible number of happy children.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>3 70
20 30 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>One optimal way to distribute sweets is <var>(20, 30, 20)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>3 10
20 30 10
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>1
</pre>
<p>The optimal way to distribute sweets is <var>(0, 0, 10)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>4 1111
1 10 100 1000
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>4
</pre>
<p>The optimal way to distribute sweets is <var>(1, 10, 100, 1000)</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>2 10
20 20
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>0
</pre>
<p>No children will be happy, no matter how the sweets are distributed.</p></section>
</div>
</span> |
p00881 |
<H1><font color="#000">Problem H:</font> Twenty Questions</H1>
<p>
Consider a closed world and a set of features that are defined for all the objects in the world.
Each feature can be answered with "yes" or "no". Using those features, we can identify any
object from the rest of the objects in the world. In other words, each object can be represented
as a fixed-length sequence of booleans. Any object is different from other objects by at least
one feature.
</p>
<p>
You would like to identify an object from others. For this purpose, you can ask a series of
questions to someone who knows what the object is. Every question you can ask is about one
of the features. He/she immediately answers each question with "yes" or "no" correctly. You
can choose the next question after you get the answer to the previous question.
</p>
<p>
You kindly pay the answerer 100 yen as a tip for each question. Because you don' t have surplus
money, it is necessary to minimize the number of questions in the worst case. You donât know
what is the correct answer, but fortunately know all the objects in the world. Therefore, you
can plan an optimal strategy before you start questioning.
</p>
<p>
The problem you have to solve is: given a set of boolean-encoded objects, minimize the maximum
number of questions by which every object in the set is identifiable.
</p>
<H2>Input</H2>
<p>
The input is a sequence of multiple datasets. Each dataset begins with a line which consists of
two integers, <i>m</i> and <i>n</i>: the number of features, and the number of objects, respectively. You
can assume 0 < <i>m</i> ≤ 11 and 0 < <i>n</i> ≤ 128. It is followed by <i>n</i> lines, each of which corresponds
to an object. Each line includes a binary string of length <i>m</i> which represent the value ("yes" or
"no") of features. There are no two identical objects.
</p>
<p>
The end of the input is indicated by a line containing two zeros. There are at most 100 datasets.
</p>
<H2>Output</H2>
<p>
For each dataset, minimize the maximum number of questions by which every object is identifiable and output the result.
</p>
<H2>Sample Input</H2>
<pre>
8 1
11010101
11 4
00111001100
01001101011
01010000011
01100110001
11 16
01000101111
01011000000
01011111001
01101101001
01110010111
01110100111
10000001010
10010001000
10010110100
10100010100
10101010110
10110100010
11001010011
11011001001
11111000111
11111011101
11 12
10000000000
01000000000
00100000000
00010000000
00001000000
00000100000
00000010000
00000001000
00000000100
00000000010
00000000001
00000000000
9 32
001000000
000100000
000010000
000001000
000000100
000000010
000000001
000000000
011000000
010100000
010010000
010001000
010000100
010000010
010000001
010000000
101000000
100100000
100010000
100001000
100000100
100000010
100000001
100000000
111000000
110100000
110010000
110001000
110000100
110000010
110000001
110000000
0 0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
0
2
4
11
9
</pre>
|
p01793 |
<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 D
Content Delivery</h2>
<p>
You are given a computer network with n nodes. This network forms an undirected tree graph. The $i$-th edge connects the $a_i$-th node with the $b_i$-th node and its distance is $c_i$. Every node has different data and the size of the data on the $i$-th node is $s_i$. The network users can deliver any data from any node to any node. Delivery cost is defined as the product of the data size the user deliver and the distance from the source to the destination. Data goes through the shortest path in the delivery. Every node makes cache to reduce the load of this network. In every delivery, delivered data is cached to all nodes which relay the data including the destination node. From the next time of delivery, the data can be delivered from any node with a cache of the data. Thus, delivery cost reduces to the product of the original data size and the distance between the nearest node with a cache and the destination.
</p>
<p>
Calculate the maximum cost of the $m$ subsequent deliveries on the given network. All the nodes have no cached data at the beginning. Users can choose the source and destination of each delivery arbitrarily.
</p>
<h3>Input</h3>
<p>
The input consists of a single test case. The first line contains two integers $n$ $(2 \leq n \leq 2,000)$ and $m$ $(1 \leq m \leq 10^9)$. $n$ and $m$ denote the number of the nodes in the network and the number of the deliveries, respectively. The following $n - 1$ lines describe the network structure. The $i$-th line of them contains three integers $a_i$, $b_i$ $(1 \leq a_i, b_i \leq n)$ and $c_i$ $(1 \leq c_i \leq 10,000)$ in this order, which means the $a_i$-th node and the $b_i$-th node are connected by an edge with the distance $c_i$. The next line contains $n$ integers. The $j$-th integer denotes $s_j$ $(1 \leq s_j \leq 10,000)$, which means the data size of the $j$-th node. The given network is guaranteed to be a tree graph.
</p>
<h3>Output</h3>
<p>
Display a line containing the maximum cost of the $m$ subsequent deliveries in the given network.
</p>
<h3>Sample Input 1</h3>
<pre>3 2
1 2 1
2 3 2
1 10 100</pre>
<h3>Output for the Sample Input 1</h3>
<pre>320</pre>
<h3>Sample Input 2</h3>
<pre>2 100
1 2 1
1 1</pre>
<h3>Output for the Sample Input 2</h3>
<pre>2</pre>
|
p01287 |
<H1><font color="#000">Problem E:</font> Colored Octahedra</H1>
<p>
A young boy John is playing with eight triangular panels. These panels are all regular triangles of the
same size, each painted in a single color; John is forming various octahedra with them.
</p>
<p>
While he enjoys his playing, his father is wondering how many octahedra can be made of these panels
since he is a pseudo-mathematician. Your task is to help his father: write a program that reports the
number of possible octahedra for given panels. Here, a pair of octahedra should be considered identical
when they have the same combination of the colors allowing rotation.
</p>
<H2>Input</H2>
<p>
The input consists of multiple datasets. Each dataset has the following format:
</p>
<p>
<i>Color</i><sub>1</sub> <i>Color</i><sub>2</sub> ... <i>Color</i><sub>8</sub>
</p>
<p>
Each <i>Color<sub>i</sub></i> (1 ≤ <i>i</i> ≤ 8) is a string of up to 20 lowercase alphabets and represents the color of the <i>i</i>-th
triangular panel.
</p>
<p>
The input ends with EOF.
</p>
<H2>Output</H2>
<p>
For each dataset, output the number of different octahedra that can be made of given panels.
</p>
<H2>Sample Input</H2>
<pre>
blue blue blue blue blue blue blue blue
red blue blue blue blue blue blue blue
red red blue blue blue blue blue blue
</pre>
<H2>Output for the Sample Input</H2>
<pre>
1
1
3
</pre>
|
p02852 | <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Takahashi is playing a board game called Sugoroku.</p>
<p>On the board, there are <var>N + 1</var> squares numbered <var>0</var> to <var>N</var>. Takahashi starts at Square <var>0</var>, and he has to stop exactly at Square <var>N</var> to win the game.</p>
<p>The game uses a roulette with the <var>M</var> numbers from <var>1</var> to <var>M</var>. In each turn, Takahashi spins the roulette. If the number <var>x</var> comes up when he is at Square <var>s</var>, he moves to Square <var>s+x</var>. If this makes him go beyond Square <var>N</var>, he loses the game.</p>
<p>Additionally, some of the squares are Game Over Squares. He also loses the game if he stops at one of those squares. You are given a string <var>S</var> of length <var>N + 1</var>, representing which squares are Game Over Squares. For each <var>i</var> <var>(0 \leq i \leq N)</var>, Square <var>i</var> is a Game Over Square if <var>S[i] = 1</var> and not if <var>S[i] = 0</var>.</p>
<p>Find the sequence of numbers coming up in the roulette in which Takahashi can win the game in the fewest number of turns possible. If there are multiple such sequences, find the lexicographically smallest such sequence. If Takahashi cannot win the game, print <var>-1</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>1 \leq N \leq 10^5</var></li>
<li><var>1 \leq M \leq 10^5</var></li>
<li><var>|S| = N + 1</var></li>
<li><var>S</var> consists of <code>0</code> and <code>1</code>.</li>
<li><var>S[0] =</var> <code>0</code></li>
<li><var>S[N] =</var> <code>0</code></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>Input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>M</var>
<var>S</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>If Takahashi can win the game, print the lexicographically smallest sequence among the shortest sequences of numbers coming up in the roulette in which Takahashi can win the game, with spaces in between.</p>
<p>If Takahashi cannot win the game, print <var>-1</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>9 3
0001000100
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>1 3 2 3
</pre>
<p>If the numbers <var>1</var>, <var>3</var>, <var>2</var>, <var>3</var> come up in this order, Takahashi can reach Square <var>9</var> via Square <var>1</var>, <var>4</var>, and <var>6</var>. He cannot reach Square <var>9</var> in three or fewer turns, and this is the lexicographically smallest sequence in which he reaches Square <var>9</var> in four turns.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>5 4
011110
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>-1
</pre>
<p>Takahashi cannot reach Square <var>5</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>6 6
0101010
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>6
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.