question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01044
<h1>Problem H Puzzle and Hexagons</h1> <h2>Backgorund</h2> <p> 超倧人気ゲヌム「パズル&amp;ヘキサゎンズ」が぀いにリリヌスされた。このゲヌムは超面癜すぎおドハマりする人が続出。あたりの熱䞭床に医垫から䞭毒認定を受ける者も続出した。䞖界各囜の有志達はこのゲヌムの䞭毒者達を助けるために「パズル&amp;ヘキサゎンズ」のシミュレヌタを䜜り、危険な実機でのプレむを避けるよう促そうずした。あなたにはシミュレヌタ䜜りに協力しお欲しい。 </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&minus;1</sub></var> <var>F</var><sub>1,</sub><var><sub>H&minus;1</sub></var> 
 <var>F</var><var><sub>W&minus;1,</sub></var><var><sub>H&minus;1</sub></var> <var>F</var><sub>0,</sub><var><sub>H&minus;2</sub></var> <var>F</var><sub>1,</sub><var><sub>H&minus;2</sub></var> 
 <var>F</var><var><sub>W&minus;1,</sub></var><var><sub>H&minus;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&minus;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&minus;1</sub></var> <var>y</var><var><sub>Q&minus;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 &le; <var>H</var> &le; 50</li> <li>3 &le; <var>W</var> &le; 50</li> <li>0 &le; <var>x</var> &lt; <var>W</var></li> <li>0 &le; <var>y</var> &lt; <var>H</var></li> <li>1 &le; <var>Q</var> &le; 100</li> <li><var>F<sub>i,</sub><sub>j</sub></var> ( 0 &le; <var>i</var> &lt; W , 0 &le; <var>j</var> &lt; 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 &times; 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 &le; <i>i</i> &le; <i>N</i>) はそれぞれ<i>i</i> 番目のスタンプの瞊の長さ暪の長さを衚す敎数である<i>C</i><sub><i>i</i>, <i>j</i></sub> (1 &le; <i>i</i> &le; 41 &le; <i>j</i> &le; 4) は䞊から <i>i</i> 行目巊から <i>j</i> 列目のマスに぀いお指定された絵の色を衚す文字である赀は <tt>R</tt> 緑は <tt>G</tt> 青は <tt>B</tt> で衚される </p> <p> 1 &le; <i>N</i> &le; 161 &le; <i>H</i><sub><i>i</i></sub> &le; 41 &le; <i>W</i><sub><i>i</i></sub> &le; 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>&lt;</code>, <code>&gt;</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>&lt;</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>&gt;</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 &lt;&gt;&lt;&gt; ^&lt;&gt;^ v&lt;&gt;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 &lt;&gt;..^ ^.&lt;&gt;v v&lt;&gt;.^ &lt;&gt;&lt;&gt;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 &lt; b &lt; 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 &le; <var>a</var>, <var>b</var>, <var>c</var> &le; 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>&lceil;n/2&rceil;</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 &lceil;<i>n</i>/2&rceil; . 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 &gt; 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 &lt; 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 &lt; ... &lt; 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>&theta;</var>に察する時刻(時<var>h</var>、分<var>m</var>)を出力せよ。時蚈はいわゆるアナログ時蚈で、1から12の数が等間隔に時蚈回りに昇順に䞊んでいるものである。<br> </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>&theta;</var> </pre> <p> 1行に短針の角床 <var>&theta;</var>を衚す敎数が床数法(degree)で䞎えられる。 短針が指す方向は、12時を指す方向を0床ずしたずき、時蚈回りに<var>&theta;</var>床回転した方向である。 </p> <h2>Constraints</h2> <ul> <li>0 &le; <var>&theta;</var> &le; 359</li> </ul> <h2>Output</h2> <p> 短針が䞎えられた角床をずる時の時刻を<br> <var>h</var> <var>m</var><br> の圢で1行に出力する。<br> <br> 時刻に午前午埌の区別はないため0 &le; <var>h</var> &le; 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 &lt; <var>n</var> &le; 10) が曞かれおいたす。<br/> 行目には、遞んだ瞊線の番号 <var>m</var> (1 &le; <var>m</var> &le; <var>n</var>) が曞かれおいたす。<br/> 行目には、圓りの堎所図でいう☆が巊から数えお䜕番目かが曞かれおいたす。<br/> 行目には、あみだくじの段数 <var>d</var> (1 &le; <var>d</var> &le; 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 &le; <i>k</i> &le; <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 &le; <i>i</i> &le; <i>n</i> - <i>k</i> + 1) の最倧倀を出力するプログラムを䜜りなさい. </p> <h2>入力</h2> <p> <!-- 入力ファむルのファむル名は <span>input.txt</span> である.--> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる入力は぀のれロを含む行で終了する </p> <p> 1 行目には正敎数 <i>n</i> (1 &le; <i>n</i> &le; 100000) ず正敎数 <i>k</i> (1 &le; <i>k</i> &le; <i>n</i>) がこの順に空癜で 区切られお曞かれおいる.2 行目以降の第 1 + <i>i</i> 行目 (1 &le; <i>i</i> &le; <i>n</i>) には, 数列の <i>i</i> 番目の項 <i>a<sub>i</sub></i> (-10000 &le; <i>a<sub>i</sub></i> &le; 10000) が曞かれおいる. 採点甚デヌタのうち, 配点の 60% 分は <i>n</i> &le; 5000, <i>k</i> &le; 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 &le; <i>H</i> &le; 300</li> <li>3 &le; <i>W</i> &le; 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 &lt; 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> -&gt; Island <var>4</var> -&gt; 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 &quot;Arithmetical Restorations&quot; 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&nbsp;&le;&nbsp;<i>N</i>&nbsp;&le;&nbsp;10<sup>5</sup></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>a</i><sub><i>i</i></sub>&nbsp;&le;&nbsp;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&nbsp;&le;&nbsp;<i>N</i>&nbsp;&le;&nbsp;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 &le; <var>i</var> &lt; 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> ずなるから &ldquo;<code>C1</code>&rdquo; ず衚珟され たた䜕も鳎らさないような「和音」は &ldquo;<code>00</code>&rdquo; ず衚珟される </p> <p> リズムパタヌンは䞊蚘のような和音衚珟を1぀以䞊䞊べたものずしお䞎えられる あるリズムパタヌン文字列は1小節内の挔奏パタヌンを瀺しおいる それぞれの和音を鳎らすタむミングを小節内の盞察䜍眮 <var>t</var> (0 &le; <var>t</var> &lt; 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> のタむミングで挔奏するような リズムパタヌンを衚しおいる 䟋えばリズムパタヌン &ldquo;<code>01000003</code>&rdquo; は <var>t</var> = 0/4 のタむミングで音0を挔奏し <var>t</var> = 3/4 のタむミングで音0, 1を挔奏するこずを衚す たたリズムパタヌン &ldquo;<code>00</code>&rdquo; は小節内で䜕も音を鳎らさないこずを衚す リズムパタヌンには和音衚珟が1぀以䞊必芁であるこずに泚意せよ </p> <p> 旧補品は同時に1぀の音しか鳎らせないため 旧補品向けのリズムパタヌン文字列内には &ldquo;<code>00</code>&rdquo;, &ldquo;<code>01</code>&rdquo;, &ldquo;<code>02</code>&rdquo;, &ldquo;<code>04</code>&rdquo;, &ldquo;<code>08</code>&rdquo;, &ldquo;<code>10</code>&rdquo;, &ldquo;<code>20</code>&rdquo;, &ldquo;<code>40</code>&rdquo;, &ldquo;<code>80</code>&rdquo; のいずれかの和音衚珟しか珟れない 旧補品向けのリズムパタヌンを <var>N</var> 個 (1 &le; <var>N</var> &le; 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 &le; <var>i</var> &le; <var>N</var>) はそれぞれ旧補品向けのリズムパタヌンである </p> <p> 各リズムパタヌンは最倧で2048文字1024和音衚珟である 䞎えられるリズムパタヌンは必ずしも最短の衚珟になっおいないこずに泚意せよ </p> <h2>Output</h2> <p> 各デヌタセットに぀いお䞎えられた <var>N</var> 個のリズムパタヌンを すべお同時に挔奏するような最短のリズムパタヌンを生成し 1行で出力せよ そのようなリズムパタヌンが2048文字を越える堎合 リズムパタヌンの代わりに &ldquo;<code>Too complex.</code>&rdquo; ずいう文字列を出力せよ </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> &hellip; <i>p</i><sub>1,<i>n</i></sub><br> <i>p</i><sub>2,1</sub> <i>p</i><sub>2,2</sub> &hellip; <i>p</i><sub>2,<i>n</i></sub><br> &hellip;<br> <i>p</i><sub><i>m</i>,1</sub> <i>p</i><sub><i>m</i>,2</sub> &hellip; <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 &le; <i>n</i> &le; 1000). <i>m</i> is the number of subjects (1 &le; <i>m</i> &le; 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 &le; <i>j</i> &le; <i>m</i> and 1 &le; <i>k</i> &le; <i>n</i>). It satisfies 0 &le; <i>p</i><sub><i>j,k</i></sub> &le; 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> + &hellip; + <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 &le; <var>x</var> &le; 1000) and those in the vertical direction <var>y</var> (1 &le; <var>y</var> &le; 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 &lt;= <I>i</I> &lt;= <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 &lt;= <I>x</I><SUB><I>i</I></SUB> &lt;= <I>W</I> and 1 &lt;= <I>y</I><SUB><I>i</I></SUB> &lt;= <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 &lt;= <I>S</I> &lt;= <I>W</I> and 1 &lt;= <I>T</I> &lt;= <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&lt;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| &minus; t</var> に察し、 <var> W_{i} = W_{i+t}</var> ずなるこずずする。 </p> <h3>Constraints</h3> <ul> <li><var>1 &le; |S| &le; 10^5</var></li> <li><var>1 &le; Q &le; 10^5</var></li> <li><var>1 &le; l_i &le; r_i &le; |S|</var></li> <li><var>1 &le; t_i &le; r_i &minus; 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 &times; 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 &le; <var>X, Y</var> &le; 10, 1 &le; <var>n</var> &le; 15) が䞎えられたす。続く <var>n</var> 行にメモの <var>i</var> 行目に曞かれた情報 <var>b<sub>i</sub></var> (1 &le; <var>b<sub>i</sub></var> &le; <var>n</var>), <var>k<sub>i</sub></var> (1 &le; <var>k<sub>i</sub></var> &le; 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 &le; <i>h</i>, <i>w</i> &le; 10</li> <li>0 &le; number assinged to a cell &le; 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 &le;</i> <i>LIMIT</i> <i>&le; 1000</i>)、<i>N</i>(<i>2 &le; N &le; 100</i>)、<i>M</i>(<i>2 &le; M &le; 100</i>)、<i>X</i>(<i>2 &le; X &le; 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 &le;</i> <i>SEC_E<i><sub>i</i></i></sub>, <i>E<sub>i</sub> &le; 10</i>)、<i>SEC_S<i><sub>i</i></i></sub>、<i>S<sub>i</sub></i> (<i>1 &le;</i> <i>SEC_S<i><sub>i</i></i></sub>, <i>S<sub>i</sub> &le; 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 &le; <var>n</var> &le; 100</li> <li>1 &le; <var>a<sub>i</sub></var> &le; <var>b<sub>i</sub></var> &le; 31 (1 &le; <var>i</var> &le; <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 &le; 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&minus;1</sub></var> <var>H<sub>1 0</sub></var> <var>H<sub>1 1</sub></var> 
 <var>H<sub>1 M&minus;1</sub></var> . . <var>H<sub>N&minus;1 0</sub></var> <var>H<sub>N&minus;1 1</sub></var> 
 <var>H<sub>N&minus;1 M&minus;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 &le; <var>N</var> &le; 108 </li> <li> 1 &le; <var>M</var> &le; 108 </li> <li> 1 &le; <var>H<sub>i j</sub></var> &le; 10<sup>9</sup> ( 0 &le; <var>i</var> &lt; <var>N</var>, 0 &le; <var>j</var> &lt; <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 &le; <i>n</i> &le; 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 &le; n &le; 10,000</var></li> <li><var>1 &le; k &le; 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 &le; <var>n</var> &le; 100</li> <li>0 &le; <var>x</var> &le; 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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解説&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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 &mdash; 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" &rarr; "ABCZD")</li> <li>the virus picks up one character in the text randomly, and then changes it into another character. (e.g., "ABCD" &rarr; "ABXD")</li> <li>the virus picks up one character in the text randomly, and then removes it from the text. (e.g., "ABCD" &rarr; "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> &le; 2) and <i>n</i> (<i>n</i> &le; 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 &le; <i>q</i> &le; 1000 </li> <li> -10000 &le; x<sub>p<sub>i</sub></sub>, y<sub>p<sub>i</sub></sub> &le; 10000 </li> <li> <var>p0 &ne; p1</var> and <var>p2 &ne; 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 &times; 3<sup>3</sup> + 0 &times; 3<sup>2</sup> - 1&times; 3<sup>1</sup> + 1 &times; 3<sup>0</sup> = 25 ずなりたす。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>w</var> </pre> <p> <var>w</var> (1 &le; <var>w</var> &le; 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 &le;<var> Q </var>&le; 100000</li> <li>1 &le;<var> L </var>&le; 10<sup>9</sup></li> <li>1 &le;<var> d </var>,<var> k </var>&le; 10<sup>9</sup></li> <li>0 &le;<var> x </var>&le;<var> L </var></li> <li>0 &le;<var> r </var>&le; 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 &lt; 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> &gt; <i>B</i> ず衚蚘する。<i>A</i> &gt; <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> &gt; <i>A</i><sub>2</sub><i>A</i><sub>2</sub> &gt; <i>A</i><sub>3</sub>  <i>A</i><sub><i>k</i>-1</sub> &gt; <i>A<sub>k</sub></i> でなくおはならない。ちなみに、<i>A</i> &gt; <i>B</i> か぀<i>B</i> &gt; <i>C</i> であっおも、<i>A</i> &gt; <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 &le; <i>N</i> &le; 100</li> <li>1 &le; <i>M</i> &le; 4,950</li> <li><i>s<sub>i</sub></i> は、アルファベットの倧文字たたは小文字のみからなる、1 文字以䞊15 文字以䞋の文字列</li> <li><i>i</i> &ne; <i>j</i>  ⇒ <i>s<sub>i</sub></i> &ne; <i>s<sub>j</sub></i></li> <li><i>p<sub>i</sub></i> &le; <i>q<sub>i</sub></i></li> <li><i>i</i> &le; <i>j</i>  ⇒ (<i>p<sub>i</sub></i>, <i>q<sub>i</sub></i>) &ne; (<i>p<sub>j</sub></i>, <i>q<sub>j</sub></i>) か぀(<i>p<sub>i</sub></i>, <i>q<sub>i</sub></i>) &ne; (<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 &le; <i>N<sub>i</sub></i> &le; 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 &le; <var>n</var> &le; 100)ず路線の数 <var>m</var> (1 &le; <var>m</var> &le; 300)が䞎えられたす。続く <var>m</var> 行に各路線の情報 <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; 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 &le; <i>n</i> &le; 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 &le; <i>a</i> &le; <i>N</i>) には<i>a</i> 本の釘が䞊んでいるそのうち巊から<i>b</i> 本目(1 &le; <i>b</i> &le; <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 &le; <i>a</i> &lt; <i>N</i>, 1 &le; <i>b</i> &le; <i>a</i>, 1 &le; <i>x</i> &le; <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 &le; <i>N</i> &le; 5000 &nbsp;&nbsp;&nbsp; 䞀蟺に䞊んでいる釘の本数<br> 1 &le; <i>M</i> &le; 500000 (= 5 &times; 10<sup>5</sup>) &nbsp;&nbsp;&nbsp; 茪ゎムの数 </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 &le; <i>i</i> &le; <i>M</i>) には敎数<i>A<sub>i</sub></i>, <i>B<sub>i</sub></i>, <i>X<sub>i</sub></i> (1 &le; <i>A<sub>i</sub></i> &lt; <i>N</i>, 1 &le; <i>B<sub>i</sub></i> &le; <i>A<sub>i</sub></i>, 1 &le; <i>X<sub>i</sub></i> &le; <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> &le; 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 &le; <var>a<sub>i</sub></var> &le; 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 &le; i &le; 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 &le; <var>n</var> &le; 50) が䞎えられたす。行目に <var>i</var> 番目のビヌカヌの容量を衚す敎数 <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; 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 &lt; n; i++) { a[i]=(long long int)x; x ^= x &lt;&lt; 13; x ^= x &gt;&gt; 7; x ^= x &lt;&lt; 17; } </pre> <p>Java蚀語に぀いおは以䞋のコヌド</p> <pre> long[] a = new long[n]; long x = x0; for(int i = 0; i &lt; n; i++){ a[i] = x; x ^= x &lt;&lt; 13; x ^= x &gt;&gt;&gt; 7; x ^= x &lt;&lt; 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 &le; <i>N</i> &le; 100)<i>M</i> <i>L</i> (0 &le; <i>L</i> &le; 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 &le; <i>A</i><sub><i>i</i></sub> &lt; <i>B</i><sub><i>i</i></sub> &le; N) <i>D</i><sub><i>i</i></sub> (1 &le; <i>D</i><sub><i>i</i></sub> &le; 100) <i>E</i><sub><i>i</i></sub> (0 &le; <i>E</i><sub><i>i</i></sub> &le; 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 &lt; <i>m</i> &le; 11 and 0 &lt; <i>n</i> &le; 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 &le; <i>i</i> &le; 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>