question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00291
<h1>お財垃メタボ蚺断</h1> <p> 月に消費皎がになっおから、お財垃が硬貚でパンパンになっおいたせんか。同じ金額を持ち歩くなら硬貚の枚数を少なくしたいですよね。硬貚の合蚈が円以䞊なら、硬貚をお札に䞡替しお、お財垃のメタボ状態を解消できたす。 </p> <p> お財垃の䞭の硬貚の枚数が皮類ごずに䞎えられたずき、硬貚をお札に䞡替できるかどうかを刀定するプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>c1</var> <var>c5</var> <var>c10</var> <var>c50</var> <var>c100</var> <var>c500</var> </pre> <p> 入力は行からなる。<var>c1</var>、<var>c5</var>、<var>c10</var>、<var>c50</var>、<var>c100</var>、<var>c500</var> (0 &le; <var>c1, c5, c10, c50, c100, c500</var> &le; 50) は、それぞれ、1円、5円、10円、50円、100円、500円硬貚の枚数を衚す。 </p> <h2>出力</h2> <p> 硬貚をお札に䞡替できるなら1 を、そうでなければ 0 を行に出力する。 </p> <h2>入出力䟋</h2> <br> <h2>入力䟋</h2> <pre> 3 1 4 0 4 1 </pre> <h2> 出力䟋</h2> <pre> 0 </pre> <br> <h2>入力䟋</h2> <pre> 2 1 4 3 2 3 </pre> <h2> 出力䟋</h2> <pre> 1 </pre> <br> <h2>入力䟋 </h2> <pre> 21 5 9 3 1 1 </pre> <h2>出力䟋</h2> <pre> 0 </pre> <br> <h2>入力䟋</h2> <pre> 2 4 3 3 3 1 </pre> <h2> 出力䟋</h2> <pre> 1 </pre> <br> <h2>入力䟋</h2> <pre> 50 50 50 4 0 0 </pre> <h2> 出力䟋</h2> <pre> 1 </pre>
p02306
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>Incircle of a Triangle</H1> <p> Write a program which prints the central coordinate ($cx$,$cy$) and the radius $r$ of a incircle of a triangle which is constructed by three points ($x_1$, $y_1$), ($x_2$, $y_2$) and ($x_3$, $y_3$) on the plane surface. </p> <h2>Input</h2> <p>The input is given in the following format</p> <pre> $x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ </pre> <p> All the input are integers. </p> <h2>Constraints</h2> <ul> <li>$-10000 \leq x_i, y_i \leq 10000$</li> <li>The three points are not on the same straight line</li> </ul> <h2>Output</h2> <p> Print $cx$, $cy$ and $r$ separated by a single space in a line. The output values should be in a decimal fraction with an error less than 0.000001. </p> <h2>Sample Input 1</h2> <pre> 1 -2 3 2 -2 0 </pre> <h2>Sample Output 1</h2> <pre> 0.53907943898209422325 -0.26437392711448356856 1.18845545916395465278 </pre> <h2>Sample Input 2</h2> <pre> 0 3 4 0 0 0 </pre> <h2>Sample Output 2</h2> <pre> 1.00000000000000000000 1.00000000000000000000 1.00000000000000000000 </pre>
p03147
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In a flower bed, there are <var>N</var> flowers, numbered <var>1,2,......,N</var>. Initially, the heights of all flowers are <var>0</var>. You are given a sequence <var>h=\{h_1,h_2,h_3,......\}</var> as input. You would like to change the height of Flower <var>k</var> to <var>h_k</var> for all <var>k</var> <var>(1 \leq k \leq N)</var>, by repeating the following "watering" operation:</p> <ul> <li>Specify integers <var>l</var> and <var>r</var>. Increase the height of Flower <var>x</var> by <var>1</var> for all <var>x</var> such that <var>l \leq x \leq r</var>.</li> </ul> <p>Find the minimum number of watering operations required to satisfy the condition.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>0 \leq h_i \leq 100</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>h_1</var> <var>h_2</var> <var>h_3</var> <var>......</var> <var>h_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of watering operations required to satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The minimum number of watering operations required is <var>2</var>. One way to achieve it is:</p> <ul> <li>Perform the operation with <var>(l,r)=(1,3)</var>.</li> <li>Perform the operation with <var>(l,r)=(2,4)</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 1 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 4 23 75 0 23 96 50 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>221 </pre></section> </div> </span>
p01480
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body> <h1> Unequal Dice</h1> <p> Time Limit: 8 sec / Memory Limit: 64 MB </p> <h2> B: 䞍揃いなサむコロ</h2> <p> パチンコや競銬などの賭け事にお金を䜿いすぎお借金たみれになったあなたは T愛グルヌプの地䞋監獄に収容されおしたった ここであなたは借金を返すたで奎隷のように働かなくおはならない </p> <p> たたこの監獄にはあなたず同じ境遇の人が倚く収容されおいるので いく぀かの班に分けられおいる ある班ではサむコロを3぀転がしおお怀にいれお楜しむ習慣がある 最近そこの班長が倧倉な目にあったずかいう話を聞いたがあなたに盎接関係はない </p> <p> あなたの所属する班ではひず぀のサむコロを振っお楜しむ習慣がある ルヌルはサむコロを振っお目の倧きな倀を出せば勝ちずいう簡単なものである ただ特殊なこずずしおは甚いられるサむコロのある面が出る確率が同様に確からしくないずいうこずである たたサむコロも皮類が倚く10面䜓のものから100面䜓のものずさたざたに甚意されおいる さらに䜕も倀の曞かれおいない面たである 䜕の倀も曞かれおいない面が出たずきは再床振りなおしをする </p> <p> このゲヌムを仕切っおいる班長からあらかじめ振っおも良いサむコロをいく぀か提瀺されたのだがどれを䜿っおも勝おる気がしない時がある </p> <p> そこで䞎えられたサむコロの内班長が䜿うサむコロで出る倀の期埅倀より高いサむコロがあるのかどうか調べたい 期埅倀が高いずは班長のサむコロより0.0000001より倧きい時を指す </p> <h2> Input</h2> <p> 入力は以䞋の圢匏で䞎えられる </p> <pre> <i>t</i> <i>n<sub>1</sub></i> <i>m<sub>1</sub></i> <i>v<sub>1</sub></i> <i>r<sub>1</sub></i> ... <i>v<sub>m<sub>1</sub></sub></i> <i>r<sub>m<sub>1</sub></sub></i> <i>n<sub>2</sub></i> <i>m<sub>2</sub></i> ... <i>n<sub>t</sub></i> <i>m<sub>t</sub></i> <i>v<sub>1</sub></i> <i>r<sub>1</sub></i> ... <i>v<sub>m<sub>t</sub></sub></i> <i>r<sub>m<sub>t</sub></sub></i> <i>p</i> <i>q</i> <i>v<sub>1</sub></i> <i>r<sub>1</sub></i> ... <i>v<sub>q</sub></i> <i>r<sub>q</sub></i> </pre> <p> 入力の圢匏に含たれる各倉数の意味ず制玄は以䞋の通りである </p> <ul> <li> <i>t</i> は䞎えられるサむコロの数 <i>t</i> (0 &lt; <i>t</i> &lt;=10)</li> <li> <i>n</i> は䜕面䜓であるのかを衚す敎数 (4 &lt;= <i>n</i> &lt;= 100)</li> <li> <i>m</i> は数倀の振られおいる面の数 (0 &lt; <i>m</i> &lt;= <i>n</i>)</li> <li> <i>v<sub>i</sub></i> は面に振られおいる数倀 (0&lt;= <i>v</i> &lt;= 100) </li> <li> <i>r<sub>i</sub></i> はその面が出る確率 (0 &lt; <i>r</i> &lt;= 1.0)</li> <ul> <li> <i>r<sub>1</sub></i> + <i>r<sub>2</sub></i> + ... + <i>r<sub>m</sub></i> &lt;= 1.0は保蚌される</li> </ul> <ul> <li> たた <i>r<sub>i</sub></i> は小数第10䜍たで䞎えられるこずがある</li> </ul> <li> <i>p</i> は班長の䜿うサむコロが䜕面䜓であるかを衚す敎数</li> <li> <i>q</i> は班長の䜿うサむコロに数倀の振られおいる面の数</li> </ul> <h2> Output</h2> <p> 班長の䜿うサむコロよりも期埅倀の高いサむコロがあればYESそうでなければNOを出力せよ </p> <h2> Sample Input 1</h2> <pre> 2 4 2 4 0.4000000 3 0.5000000 4 1 5 0.3333333 5 3 5 0.7777777 4 0.1111111 2 0.0001111 </pre> <h2> Sample Output 1</h2> <pre> YES </pre> <h2> Sample Input 2</h2> <pre> 2 4 2 4 0.5000000 3 0.4000000 4 1 5 0.3333333 5 3 8 0.7777777 4 0.1111111 2 0.0001111 </pre> <h2> Sample Output 2</h2> <pre> NO </pre> </body> </html>
p03517
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ringo has an undirected graph <var>G</var> with <var>N</var> vertices numbered <var>1,2,...,N</var> and <var>M</var> edges numbered <var>1,2,...,M</var>. Edge <var>i</var> connects Vertex <var>a_{i}</var> and <var>b_{i}</var> and has a length of <var>w_i</var>.</p> <p>Now, he is in the middle of painting these <var>N</var> vertices in <var>K</var> colors numbered <var>1,2,...,K</var>. Vertex <var>i</var> is already painted in Color <var>c_i</var>, except when <var>c_i = 0</var>, in which case Vertex <var>i</var> is not yet painted.</p> <p>After he paints each vertex that is not yet painted in one of the <var>K</var> colors, he will give <var>G</var> to Snuke.</p> <p>Based on <var>G</var>, Snuke will make another undirected graph <var>G'</var> with <var>K</var> vertices numbered <var>1,2,...,K</var> and <var>M</var> edges. Initially, there is no edge in <var>G'</var>. The <var>i</var>-th edge will be added as follows:</p> <ul> <li>Let <var>x</var> and <var>y</var> be the colors of the two vertices connected by Edge <var>i</var> in <var>G</var>.</li> <li>Add an edge of length <var>w_i</var> connecting Vertex <var>x</var> and <var>y</var> in <var>G'</var>.</li> </ul> <p>What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of <var>G'</var>? If <var>G'</var> will not be connected regardless of how Ringo paints the vertices, print <var>-1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,M \leq 10^{5}</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>0 \leq c_i \leq K</var></li> <li><var>1 \leq a_i,b_i \leq N</var></li> <li><var>1 \leq w_i \leq 10^{9}</var></li> <li>The given graph may NOT be simple or connected.</li> <li>All input values are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li>In the test set worth <var>100</var> points, <var>N = K</var> and <var>c_i = i</var>.</li> <li>In the test set worth another <var>100</var> points, <var>c_i \neq 0</var>.</li> <li>In the test set worth another <var>200</var> points, <var>c_i = 0</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>K</var> <var>c_1</var> <var>c_2</var> <var>...</var> <var>c_{N}</var> <var>a_1</var> <var>b_1</var> <var>w_1</var> <var>:</var> <var>a_M</var> <var>b_M</var> <var>w_M</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 3 3 1 0 1 2 1 2 10 2 3 20 2 4 50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>60 </pre> <p><var>G'</var> will only be connected when Vertex <var>2</var> is painted in Color <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 4 0 0 0 0 0 1 2 10 2 3 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>Regardless of how Ringo paints the vertices, two edges is not enough to connect four vertices as one.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 12 9 1 2 3 4 5 6 7 8 9 6 9 9 8 9 6 6 7 85 9 5 545631016 2 1 321545 1 6 33562944 7 3 84946329 9 7 15926167 4 7 53386480 5 8 70476 4 6 4549 4 8 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>118901402 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>18 37 12 5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1 17 1 1 11 16 7575 11 15 9 10 10 289938980 5 10 17376 18 4 1866625 8 11 959154208 18 13 200 16 13 2 2 7 982223 12 12 9331 13 12 8861390 14 13 743 2 10 162440 2 4 981849 7 9 1 14 17 2800 2 7 7225452 3 7 85 5 17 4 2 13 1 10 3 45 1 15 973 14 7 56553306 16 17 70476 7 18 9 9 13 27911 18 14 7788322 11 11 8925 9 13 654295 2 10 9 10 1 545631016 3 4 5 17 12 1929 2 11 57 1 5 4 1 17 7807368 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>171 </pre></section> </div> </span>
p00012
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>A Point in a Triangle</H1> <p> There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain. </p> <p> Write a program which prints "<span>YES</span>" if a point $P$ $(x_p, y_p)$ is in the triangle and "<span>NO</span>" if not. </p> <!-- <p> You can suppose that P is never on the points nor sides of the triangle. </p> --> <H2>Input</H2> <p> Input consists of several datasets. Each dataset consists of:<br/> <br/> $x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_p$ $y_p$<br/> </p> <p> All the input are real numbers. Input ends with EOF. The number of datasets is less than or equal to 100. </p> <h2>Constraints</h2> <p> You can assume that: </p> <ul> <li>$ -100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \leq 100$</li> <li>1.0 $\leq$ Length of each side of a tringle</li> <li>0.001 $\leq$ Distance between $P$ and each side of a triangle</li> </ul> <H2>Output</H2> <p> For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line. </p> <H2>Sample Input</H2> <pre> 0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5 0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO </pre>
p00442
<H1>最悪の蚘者 </H1> <h2>問題</h2> <p> あなたは JOI 新聞瀟の蚘者でありスポヌツ蚘事を担圓しおいる </p> <p> 昚日たでにクロアチアではn 個のサッカヌチヌムによる総圓りのリヌグ戊が行われた倧䌚実行委員䌚は詊合結果ず芏定に基づき各チヌムに 1 䜍から n 䜍たでの順䜍を぀けたようであるあなたには䞀郚の詊合の勝敗ずずもに次の情報が䌝えられた <br/> <b>情報 1</b> 匕き分けの詊合はなかった<br/> <b>情報 2</b> 党おのチヌムに異なる順䜍が぀いた<br/> <b>情報 3</b> 党おの 1 &le; a < b &le; n に察しa 䜍のチヌムず b 䜍のチヌムの詊合においお必ず a 䜍のチヌムが勝利した <br/> </p> <p> あなたは蚘事を䜜成するために䞀郚の詊合の勝敗ず䌝えられた情報 1 3 をもずに順䜍衚を掚枬するこずにした </p> <p> 入力ずしお䞀郚の詊合の勝敗が䞎えられたずき䌝えられた情報に適合する順䜍衚を 1 ぀出力するプログラムを䜜れたた出力した順䜍衚以倖に䌝えられた情報に適合する順䜍衚が存圚するかどうかも刀定せよ </p> <p> ここで順䜍衚ずは 1 䜍から n 䜍の順にチヌムを䞊べたもののこずをいう </p> <h2>䟋</h2> <b> 䟋1 (情報に適合する順䜍衚が 1 ぀しかない堎合) </b> <p> チヌム数が4で各チヌムに1から4たでの番号が付けられおおり勝敗が次の衚で䞎えられおいたずする </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_worstSportswriter1"> </center><br/> <p> i 行 j 列が○のずきは番号 i のチヌムず番号 j のチヌムの詊合においお番号 i のチヌムが勝利したこずを意味するたた×のずきは番号 j のチヌムが勝利したこずを意味する? は勝敗が䞎えられおいないこずを意味するこのずき䌝えられた情報に適合する順䜍衚は次の 1 ぀しかない </p> <center> <table> <tr><td> 1 䜍 番号 3 のチヌム <br/> 2 䜍 番号 4 のチヌム <br/> 3 䜍 番号 1 のチヌム <br/> 4 䜍 番号 2 のチヌム <br/> </td></tr> </table> </center> <br/> <b> 䟋2 (情報に適合する順䜍衚が耇数存圚する堎合) </b> <p> チヌム数が3で各チヌムに1から3たでの番号が付けられおおり勝敗が次の衚で䞎えられおいたずする </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_worstSportswriter2"> </center><br/> <p> このずき䌝えられた情報に適合する順䜍衚は次の 2 ぀である </p> <center> <table> <tr> <td width="200"> 1 䜍 番号 2 のチヌム<br/> 2 䜍 番号 1 のチヌム<br/> 3 䜍 番号 3 のチヌム<br/> </td> <td width="200"> 1 䜍 番号 2 のチヌム<br/> 2 䜍 番号 3 のチヌム<br/> 3 䜍 番号 1 のチヌム<br/> </td> </tr> </table> </center> <h2>入力</h2> <p> <!--入力ファむルのファむル名は input.txt である--> 入力は以䞋の圢匏で䞎えられる </p> <p> 1 行目にはサッカヌチヌムの個数 n が曞かれおいる各チヌムには1 から n たでの番号が付けられおいる </p> <p> 2 行目には䞎えられた詊合の勝敗の個数 m が曞かれおいる </p> <p> 3 行目から m + 2 行目は詊合の勝敗を衚す各行は空癜で区切られた 2 ぀の敎数 i, j を含み番号 i のチヌムが番号 j のチヌムに勝利したこずを衚す </p> <p> n, m は 1 &le; n &le; 5000, 1 &le; m &le; 100000 をみたす </p> <p> 採点の際に甚いるテストデヌタのうち30% は 1 &le; n &le; 7, 1 &le; m &le; 15 をみたすたた60% は 1 &le; n &le; 100, 1 &le; m &le; 2000 をみたす </p> <h2>出力</h2> <!-- <p> 出力ファむルのファむル名は output.txt である </p> --> <p> 出力<!--ファむル-->は n + 1 行からなる </p> <p> 1 行目から n 行目たでの n 行には䌝えられた情報に適合する順䜍衚を出力せよ </p> <p> i 行目 (1 &le; i &le; n) に i 䜍のチヌムの番号を出力せよ </p> <p> n + 1 行目には出力した順䜍衚以倖に䌝えられた情報に適合する順䜍衚が存圚するかどうかを衚す敎数を出力せよもし存圚しなければ 0 を存圚する堎合は 1 を出力せよ </p> <h2>入出力䟋</h2> <p> 䟋 1 に察応する入出力は以䞋の通りである </p> <h3>入力䟋 1</h3> <pre> 4 5 1 2 3 1 3 2 3 4 4 1 </pre> <h3>出力䟋 1</h3> <pre> 3 4 1 2 0 </pre> <br/> <p> 䟋 2 に察応する入出力は以䞋の通りである </p> <h3>入力䟋 2</h3> <pre> 3 2 2 1 2 3 </pre> <p> この入力デヌタに察しお次の 2 通りの出力デヌタが考えられるどちらを出力しおもよい </p> <h3>出力䟋 2</h3> <pre> 2 1 3 1 </pre> <pre> 2 3 1 1 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02185
<h2>D: Many Decimal Integers</h2> <h3>問題</h3> <p>数字 (<var>0</var> から <var>9</var>) のみからなる文字列 <var>S</var> ず、数字 ず <code>?</code> のみからなる文字列 <var>T</var> が䞎えられたす。<var>S</var> ず <var>T</var> は同じ長さです。</p> <p> <var>T</var> 内に存圚するそれぞれの <code>?</code> に぀いお、<var>0</var> から <var>9</var> たでの数字のいずれか <var>1</var> ぀に倉曎し、数字のみからなる文字列 <var>T'</var> を䜜るこずを考えたす。このずき、<var>f(T') \leq f(S)</var> である必芁がありたす。ここで <var>f(t)</var> は、文字列 <var>t</var> を <var>10</var> 進数ずしお読んだずきの敎数倀を返す関数ずしたす。 たた、<var>T'</var> の最䞊䜍の桁にある数字は <var>0</var> であっおもよいものずしたす。 </p> <p>あり埗る文字列 <var>T'</var> すべおに぀いお、<var>f(T')</var> の倀の総和を <var>10^9+7</var> で割った䜙りを求めおください。なお、条件を満たす <var>T'</var> がひず぀も存圚しない堎合は <var>0</var> ず答えおください。</p> <h3>入力圢匏</h3> <pre> <var>S</var> <var>T</var> </pre> <h3>制玄</h3> <ul> <li> <var>1 \leq |S| = |T| \leq 2 \times 10^5</var></li> <li> <var>S</var> は数字 (<var>0</var> から <var>9</var>) のみからなる文字列</li> <li> <var>T</var> は数字ず <code>?</code> のみからなる文字列</li> </ul> <h3>出力圢匏</h3> <p>条件を満たす <var>T'</var> の総和を <var>10^9+7</var> で割った䜙りを䞀行に出力しおください。</p> <h3>入力䟋1</h3> <pre> 73 6? </pre> <h3>出力䟋1</h3> <pre>645</pre> <p><var>T'</var> ずしおあり埗る文字列は、<var>60</var> から <var>69</var> たでの <var>10</var> 通りありたす。これらの合蚈は <var>645</var> です。</p> <h3>入力䟋2</h3> <pre> 42 ?1 </pre> <h3>出力䟋2</h3> <pre>105</pre> <p><var>T'</var> の最䞊䜍の桁にある数字は <var>0</var> でもよいため、<var>01</var> も条件を満たしたす。</p> <h3>入力䟋3</h3> <pre> 1730597319 16??35??8? </pre> <h3>出力䟋3</h3> <pre>502295105</pre> <p><var>10^9 + 7</var> で割った䜙りを求めおください。</p>
p01603
<h2>さんぜ</h2> <h2>Problem Statement</h2> <p>ねこのそらは散歩が倧奜きだ道を歩くず新しい発芋がある</p> <p>そらの䜏む町は <var>N</var> 個の広堎ず <var>N-1</var> 本の道からなる<br /> 道はちょうど二぀の広堎を぀ないでおり枝分かれしたり道どうしが亀わったりしない</p> <p>道には歩くのにかかる時間 <var>t</var>埗られる発芋の個数の䞊限 <var>m</var>および発芋䞀぀あたりの䟡倀 <var>v</var> が指定されおいる<br /> 道を䞀方の端からもう䞀方の端たで歩いたずき<var>m</var> 回目たでの通行では䟡倀 <var>v</var> の発芋が䞀぀埗られるが<var>m+1</var> 回目以降は発芋が埗られない</p> <p>今日もそらは町内の散歩に出かけるようだ<br /> そらの散歩は広堎 1 から始たりいく぀かの道 ( 0 本かもしれない ) を通っお最埌に広堎 1 に戻っおくるずいうルヌトをずる<br /> たた日が暮れるず寂しい気持ちになるのでそらは散歩時間を <var>T</var> 以䞋にしたいず思っおいる</p> <p>そらの友人であるあなたの仕事は散歩時間が <var>T</var> 以䞋である散歩ルヌトにおいお埗られる発芋の䟡倀の総和の最倧倀を求めるこずである</p> <h2>Input</h2> <p>入力は以䞋の圢匏に埓う䞎えられる数は党お敎数である</p> <pre><var>N</var> <var>T</var> <var>a_1</var> <var>b_1</var> <var>t_1</var> <var>m_1</var> <var>v_1</var> <var>. . .</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>t_{N-1}</var> <var>m_{N-1}</var> <var>v_{N-1}</var></pre> <p>入力の <var>i+1</var> 行目は広堎 <var>a_i</var> ず <var>b_i</var> を぀なぐ通行時間 <var>t_i</var>埗られる発芋の個数の䞊限 <var>m_i</var>発芋䞀぀あたりの䟡倀 <var>v_i</var> の道を衚しおいる</p> <h2>Constraints</h2> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1 ≩ N ≩ 300</var></li> <li><var>1 ≩ T ≩ 10^4</var></li> <li><var>1 ≩ a_i, b_i ≩ N</var></li> <li><var>1 ≩ t_i ≩ 10^4</var></li> <li><var>0 ≩ m_i ≩ 10^4</var></li> <li><var>1 ≩ v_i ≩ 10^5</var></li> <li>どの二぀の広堎も道を通っお行き来できる</li></ul> <h2>Output</h2> <p>埗られる発芋の䟡倀の総和の最倧倀を 1 行に出力せよ</p> <h2>Sample Input 1</h2> <pre>4 5 1 2 1 4 7 2 3 1 2 77 2 4 1 2 777</pre> <h2>Output for the Sample Input 1</h2> <pre>1568</pre> <p>1→2→4→2→1 ず移動するこずで合蚈で䟡倀 7+777+777+7=1568 の発芋が埗られる</p> <h2>Sample Input 2</h2> <pre>2 10000 1 2 1 10 1</pre> <h2>Output for the Sample Input 2</h2> <pre>10</pre> <h2>Sample Input 3</h2> <pre>5 15 1 2 3 2 1 2 3 3 2 1 1 4 8 2 777 1 5 1 3 10</pre> <h2>Output for the Sample Input 3</h2> <pre>32</pre>
p00911
<H1><font color="#000">Problem H: </font>Company Organization</H1> <p> You started a company a few years ago and fortunately it has been highly successful. As the growth of the company, you noticed that you need to manage employees in a more organized way, and decided to form several groups and assign employees to them. </p> <p> Now, you are planning to form n groups, each of which corresponds to a project in the company. Sometimes you have constraints on members in groups. For example, a group must be a subset of another group because the former group will consist of senior members of the latter group, the members in two groups must be the same because current activities of the two projects are closely related, the members in two groups must not be exactly the same to avoid corruption, two groups cannot have a common employee because of a security reason, and two groups must have a common employee to facilitate collaboration. </p> <p> In summary, by letting <i>X<sub>i</sub></i> (<i>i</i> = 1, ... , <i>n</i>) be the set of employees assigned to the <i>i</i>-th group, we have five types of constraints as follows. </p> <ol> <li> <i>X<sub>i</sub></i> &sube; <i>X<sub>j</sub></i></li> <li> <i>X<sub>i</sub></i> = <i>X<sub>j</sub></i></li> <li> <i>X<sub>i</sub></i> &ne; <i>X<sub>j</sub></i></li> <li> <i>X<sub>i</sub></i> &cap; <i>X<sub>j</sub></i> = &empty;</li> <li> <i>X<sub>i</sub></i> &cap; <i>X<sub>j</sub></i> &ne; &empty;</li> </ol> <p> Since you have listed up constraints without considering consistency, it might be the case that you cannot satisfy all the constraints. Constraints are thus ordered according to their priorities, and you now want to know how many constraints of the highest priority can be satisfied. </p> <p> You do not have to take ability of employees into consideration. That is, you can assign anyone to any group. Also, you can form groups with no employee. Furthermore, you can hire or fire as many employees as you want if you can satisfy more constraints by doing so. </p> <p> For example, suppose that we have the following five constraints on three groups in the order of their priorities, corresponding to the first dataset in the sample input. </p> <ul> <li><i>X</i><sub>2</sub> &sube; <i>X</i><sub>1</sub></li> <li><i>X</i><sub>3</sub> &sube; <i>X</i><sub>2</sub></li> <li><i>X</i><sub>1</sub> &sube; <i>X</i><sub>3</sub></li> <li><i>X</i><sub>1</sub> &ne; <i>X</i><sub>3</sub></li> <li><i>X</i><sub>3</sub> &sube; <i>X</i><sub>1</sub></li> </ul> <p> By assigning the same set of employees to <i>X</i><sub>1</sub>, <i>X</i><sub>2</sub>, and <i>X</i><sub>3</sub>, we can satisfy the first three constraints. However, no matter how we assign employees to <i>X</i><sub>1</sub>, <i>X</i><sub>2</sub>, and <i>X</i><sub>3</sub>, we cannot satisfy the first four highest priority constraints at the same time. Though we can satisfy the first three constraints and the fifth constraint at the same time, the answer should be three. </p> <H2>Input</H2> <p> The input consists of several datasets. The first line of a dataset consists of two integers <i>n</i> (2 &le; <i>n</i> &le; 100) and <i>m</i> (1 &le; <i>m</i> &le; 10000), which indicate the number of groups and the number of constraints, respectively. Then, description of <i>m</i> constraints follows. The description of each constraint consists of three integers <i>s</i> (1 &le; <i>s</i> &le; 5), <i>i</i> (1 &le; <i>i</i> &le; <i>n</i>), and <i>j</i> (1 &le; <i>j</i> &le; <i>n</i>, <i>j</i> &ne;= <i>i</i>), meaning a constraint of the <i>s</i>-th type imposed on the <i>i</i>-th group and the <i>j</i>-th group. The type number of a constraint is as listed above. The constraints are given in the descending order of priority. </p> <p> The input ends with a line containing two zeros. </p> <H2>Output</H2> <p> For each dataset, output the number of constraints of the highest priority satisfiable at the same time. </p> <H2>Sample Input</H2> <pre> 4 5 1 2 1 1 3 2 1 1 3 3 1 3 1 3 1 4 4 1 2 1 1 3 2 1 1 3 4 1 3 4 5 1 2 1 1 3 2 1 1 3 4 1 3 5 1 3 2 3 1 1 2 2 1 2 3 1 2 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 4 4 2 </pre>
p01253
<H1><font color="#000">Problem D:</font> Deadly Dice Game</H1> <p> T.I. Financial Group, a world-famous group of finance companies, has decided to hold an evil gambling game in which insolvent debtors compete for special treatment of exemption from their debts. </p> <p> In this game, each debtor starts from one cell on the stage called the Deadly Ring. The Deadly Ring consists of N cells and each cell is colored black or red. Each cell is connected to exactly two other adjacent cells and all the cells form a ring. At the start of the game, each debtor chooses which cell to start. Then he rolls a die and moves on the ring in clockwise order by cells as many as the number of spots shown on the upside of the die. This step is called a round, and each debtor repeats a round <i>T</i> times. A debtor will be exempted from his debt if he is standing on a red cell after he finishes all the rounds. On the other hand, if he finishes the game at a black cell, he will be sent somewhere else and forced to devote his entire life to hard labor. </p> <p> You have happened to take part in this game. As you are allowed to choose the starting cell, you want to start from a cell that maximizes the probability of finishing the game at a red cell. Fortunately you can bring a laptop PC to the game stage, so you have decided to write a program that calculates the maximum winning probability. </p> <H2>Input</H2> <p> The input consists of multiple datasets. </p> <p> Each dataset consists of two lines. The first line contains two integers <i>N</i> (1 &le; <i>N</i> &le; 2000) and <i>T</i> (1 &le; <i>T</i> &le; 2000) in this order, delimited with a single space. The second line contains a string of <i>N</i> characters that consists of characters ‘<span>R</span>’ and ‘<span>B</span>’, which indicate red and black respectively. This string represents the colors of the cells in clockwise order. </p> <p> The input is terminated by a line with two zeros. This is not part of any datasets and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print the maximum probability of finishing the game at a red cell in one line. Your program may output an arbitrary number of digits after the decimal point, provided that the absolute error does not exceed 10<sup>-8</sup>. </p> <H2>Sample Input</H2> <pre> 6 1 RBRBRB 10 1 RBBBRBBBBB 10 2 RBBBRBBBBB 10 10 RBBBBBBBBB 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.50000000 0.33333333 0.22222222 0.10025221 </pre>
p04051
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≩N≩200,000</var></li> <li><var>1≩A_i≩2000, 1≩B_i≩2000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
p03794
<span class="lang-en"> <p>Score : <var>1800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree <var>T</var> with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>. For each <var>1 ≀ i ≀ N - 1</var>, the <var>i</var>-th edge connects vertices <var>a_i</var> and <var>b_i</var>.</p> <p>Snuke is constructing a directed graph <var>T'</var> by arbitrarily assigning direction to each edge in <var>T</var>. (There are <var>2^{N - 1}</var> different ways to construct <var>T'</var>.)</p> <p>For a fixed <var>T'</var>, we will define <var>d(s,\ t)</var> for each <var>1 ≀ s,\ t ≀ N</var>, as follows:</p> <ul> <li><var>d(s,\ t) = </var>(The number of edges that must be traversed against the assigned direction when traveling from vertex <var>s</var> to vertex <var>t</var>)</li> </ul> <p>In particular, <var>d(s,\ s) = 0</var> for each <var>1 ≀ s ≀ N</var>. Also note that, in general, <var>d(s,\ t) ≠ d(t,\ s)</var>.</p> <p>We will further define <var>D</var> as the following:</p> <div style="text-align: center;"> <img alt="3d2f3f88e8fa23f065c04cd175c14ebf.png" src="https://atcoder.jp/img/mujin/3d2f3f88e8fa23f065c04cd175c14ebf.png"> </img></div> <p>Snuke is constructing <var>T'</var> so that <var>D</var> will be the minimum possible value. How many different ways are there to construct <var>T'</var> so that <var>D</var> will be the minimum possible value, modulo <var>10^9 + 7</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 1000</var></li> <li><var>1 ≀ a_i,\ b_i ≀ N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_{N - 1}</var> <var>b_{N - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways to construct <var>T'</var> so that <var>D</var> will be the minimum possible value, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 1 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The minimum possible value for <var>D</var> is <var>1</var>. There are two ways to construct <var>T'</var> to achieve this value, as shown in the following figure:</p> <p><img alt="" src="https://atcoder.jp/img/mujin/de49901ddf69d8565fde5b6870afb595.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 2 3 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> <p>The minimum possible value for <var>D</var> is <var>2</var>. There are six ways to construct <var>T'</var> to achieve this value, as shown in the following figure:</p> <p><img alt="" src="https://atcoder.jp/img/mujin/dcb377e8c7fe15d6dd0cb815dc57c41a.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 1 3 1 4 2 5 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>14 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 2 4 2 5 8 3 10 7 1 6 2 8 9 5 8 6 10 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>102 </pre></section> </div> </span>
p02886
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>It's now the season of TAKOYAKI FESTIVAL!</p> <p>This year, <var>N</var> takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The <em>deliciousness</em> of the <var>i</var>-th takoyaki is <var>d_i</var>.</p> <p>As is commonly known, when you eat two takoyaki of deliciousness <var>x</var> and <var>y</var> together, you restore <var>x \times y</var> health points.</p> <p>There are <var>\frac{N \times (N - 1)}{2}</var> ways to choose two from the <var>N</var> takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these <var>\frac{N \times (N - 1)}{2}</var> values.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>2 \leq N \leq 50</var></li> <li><var>0 \leq d_i \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>d_1</var> <var>d_2</var> <var>...</var> <var>d_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the <var>N</var> takoyaki served.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>11 </pre> <p>There are three possible choices:</p> <ul> <li>Eat the first and second takoyaki. You will restore <var>3</var> health points.</li> <li>Eat the second and third takoyaki. You will restore <var>2</var> health points.</li> <li>Eat the first and third takoyaki. You will restore <var>6</var> health points.</li> </ul> <p>The sum of these values is <var>11</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 5 0 7 8 3 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>312 </pre></section> </div> </span>
p03281
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>The number <var>105</var> is quite special - it is odd but still it has eight divisors. Now, your task is this: how many odd numbers with exactly eight positive divisors are there between <var>1</var> and <var>N</var> (inclusive)?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is an integer between <var>1</var> and <var>200</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the count.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>105 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>Among the numbers between <var>1</var> and <var>105</var>, the only number that is odd and has exactly eight divisors is <var>105</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p><var>1</var> has one divisor. <var>3</var>, <var>5</var> and <var>7</var> are all prime and have two divisors. Thus, there is no number that satisfies the condition.</p></section> </div> </span>
p01746
<p> すぬけ君は初期状態では動くこずはできない<var>i</var> 番目のチケットの倀段は <var>p<sub>i</sub></var> でありこれを買うず任意の <var>(x, y)</var> ず任意の非負実数 <var>t</var> に察し<var>(x, y)</var> から<var>(x + ta<sub>i</sub>, y + tb<sub>i</sub>)</var> に移動するこずができるようになるすぬけ君が平面䞊の任意の二点間を(いく぀かのチケットを組み合わせお) 移動できるようになるために買わなければならないチケットの合蚈金額の最小倀を求めよ </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>n</var> &le; 200000</li> <li> −10<sup>9</sup> &le; <var>a<sub>i</sub>, b<sub>i</sub></var> &le; 10<sup>9</sup></li> <li> 1 &le; <var>p<sub>i</sub> &le; 10<sup>9</sup></li> <li> 入力は党お敎数である</li> </ul> <h2>Input</h2> <pre> <var>n</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>p<sub>1</sub></var> . . . <var>a<sub>n</sub></var> <var>b<sub>n</sub></var> <var>p<sub>n</sub></var> </pre> <h2>Output</h2> <p> 平面䞊の任意の二点間を移動できるようになるために買わなければならないチケットの合蚈金額の最小倀を出力せよできない堎合は-1 を出力せよ </p> <h2>Sample Input 1</h2> <pre> 7 0 3 1 0 3 2 1 -1 2 0 0 1 -2 4 1 -4 0 1 2 1 2 </pre> <p> たずえばチケット1, 3, 6 を買うずよい </p> <h2>Sample Output 1</h2> <pre> 4 </pre> <h2>Sample Input 2</h2> <pre> 2 1 2 3 4 5 6 </pre> <h2>Sample Output 2</h2> <pre> -1 </pre>
p00854
<H1><font color="#000">Problem A:</font> And Then There Was One</H1> <p> Let’s play a stone removing game. </p> <p> Initially, <i>n</i> stones are arranged on a circle and numbered 1, ... , <i>n</i> clockwise (Figure 1). You are also given two numbers <i>k</i> and <i>m</i>. From this state, remove stones one by one following the rules explained below, until only one remains. In step 1, remove stone <i>m</i>. In step 2, locate the <i>k</i>-th next stone clockwise from <i>m</i> and remove it. In subsequent steps, start from the slot of the stone removed in the last step, make <i>k</i> hops clockwise on the remaining stones and remove the one you reach. In other words, skip (<i>k</i> - 1) remaining stones clockwise and remove the next one. Repeat this until only one stone is left and answer its number. </p> <p> For example, the answer for the case <i>n</i> = 8, <i>k</i> = 5, <i>m</i> = 3 is 1, as shown in Figure 1. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_andThenThereWasOne"> <p> Figure 1: An example game </p> </center> <p> <b>Initial state</b>: Eight stones are arranged on a circle. </p> <p> <b>Step 1</b>: Stone 3 is removed since <i>m</i> = 3. </p> <p> <b>Step 2</b>: You start from the slot that was occupied by stone 3. You skip four stones 4, 5, 6 and 7 (since <i>k</i> = 5), and remove the next one, which is 8. </p> <p> <b>Step 3</b>: You skip stones 1, 2, 4 and 5, and thus remove 6. Note that you only count stones that are still on the circle and ignore those already removed. Stone 3 is ignored in this case. </p> <p> <b>Steps 4-7</b>: You continue until only one stone is left. Notice that in later steps when only a few stones remain, the same stone may be skipped multiple times. For example, stones 1 and 4 are skipped twice in step 7. </p> <p> <b>Final State</b>: Finally, only one stone, 1, is on the circle. This is the final state, so the answer is 1. </p> <H2>Input</H2> <p> The input consists of multiple datasets each of which is formatted as follows. </p> <pre> <i>n k m</i> </pre> <p> The last dataset is followed by a line containing three zeros. Numbers in a line are separated by a single space. A dataset satisfies the following conditions. </p> <center> <p> 2 &le; <i>n</i> &le; 10000, 1 &le; <i>k</i> &le; 10000, 1 &le; <i>m</i> &le; <i>n</i> </p> </center> <p> The number of datasets is less than 100. </p> <H2>Output</H2> <p> For each dataset, output a line containing the stone number left in the final state. No extra characters such as spaces should appear in the output. </p> <H2>Sample Input</H2> <pre> 8 5 3 100 9999 98 10000 10000 10000 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 93 2019 </pre>
p02869
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are positive integers <var>N</var> and <var>K</var>.</p> <p>Determine if the <var>3N</var> integers <var>K, K+1, ..., K+3N-1</var> can be partitioned into <var>N</var> triples <var>(a_1,b_1,c_1), ..., (a_N,b_N,c_N)</var> so that the condition below is satisfied. Any of the integers <var>K, K+1, ..., K+3N-1</var> must appear in exactly one of those triples.</p> <ul> <li>For every integer <var>i</var> from <var>1</var> to <var>N</var>, <var>a_i + b_i \leq c_i</var> holds.</li> </ul> <p>If the answer is yes, construct one such partition.</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 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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is impossible to partition the integers satisfying the condition, print <code>-1</code>. If it is possible, print <var>N</var> triples in the following format:</p> <pre><var>a_1</var> <var>b_1</var> <var>c_1</var> <var>:</var> <var>a_N</var> <var>b_N</var> <var>c_N</var> </pre> </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>1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre></section> </div> </span>
p01316
<h1><font color="#000000">Problem C:</font> Differential Pulse Code Modulation</h1> <!-- <h3><U>差分パルス笊号倉調</U></h3> --> <p>差分パルス笊号倉調は䞻に音声信号を圧瞮する際に甚いられる圧瞮手法の䞀぀である</p> <p>音声信号は蚈算機䞊では敎数列(むンパルス列)ずしお扱われる敎数列は入力信号を䞀定時間間隔で暙本化(サンプリング)し振幅を蚘録したものである䞀般にこの敎数列は前埌の倀が近いずいう傟向があるこれを利甚し前埌の倀の差分を笊号化し圧瞮率を向䞊させるのが差分パルス笊号倉調である</p> <p>本問題では差分の倀をあらかじめ定められた倀の集合から遞ぶこずを考えるこの倀の集合をコヌドブックず呌ぶこずにする埩号化埌の音声信号 <i>y<sub>n</sub></i> は以䞋の匏で定められる</p> <blockquote><i>y</i><sub><i>n</i></sub> = <i>y</i><sub><i>n</i> - 1</sub> + <i>C</i>[<i>k</i><sub><i>n</i></sub>]</blockquote> <p>ここで <i>k</i><sub><i>n</i></sub> はプログラムによっお出力される出力系列 <i>C</i>[<i>j</i>] はコヌドブックの <i>j</i> 番目の倀であるただし <i>y</i><sub><i>n</i></sub> は加算によっお0未満の倀ずなった堎合は0に255より倧きい倀ずなった堎合は255にそれぞれ䞞められるたた <i>y</i><sub>0</sub> の倀は128ずする</p> <p>あなたの仕事は入力信号ずコヌドブックが䞎えられたずきに元の入力信号ず埩号化埌の出力信号ずの差の二乗和が最小ずなるように出力系列を遞んでそのずきの差の二乗和を出力するプログラムを曞くこずである</p> <p>䟋えばコヌドブックずしお <i>{4, 2, 1, 0, -1, -2, -4}</i> ずいう倀のセットを䜿っお <i>131, 137</i> ずいう列を圧瞮する堎合 <i>y</i><sub><i>0</i></sub><i> = 128</i>, <i>y</i><sub><i>1</i></sub><i> = 128 + 4 = 132</i>, <i>y</i><sub><i>2</i></sub><i> = 132 + 4 = 136</i> ずいう列に圧瞮するず 二乗和が <i>(131 - 132)^2 + (137 - 136)^2 = 2</i> ず最小になる</p> <p>たた同じくコヌドブックずしお <i>{4, 2, 1, 0, -1, -2, -4}</i> ずいう倀のセットを䜿っお <i>131, 123</i> ずいう列を圧瞮する堎合 <i>y</i><sub><i>0</i></sub><i> = 128</i>, <i>y</i><sub><i>1</i></sub><i> = 128 + 1 = 129</i>, <i>y</i><sub><i>2</i></sub><i> = 129 - 4 = 125</i> ず先皋の䟋ずは違っお <i>131</i> により近づく <i>+2</i> を採甚しない方が <i>(131 - 129) ^ 2 + (123 - 125) ^ 2 = 8</i> ずいうより小さな二乗和が埗られる</p> <p>䞊蚘 2぀の䟋は sample input の最初の 2䟋である</p> <h2>Input</h2> <p>入力は耇数のデヌタセットから構成される各デヌタセットの圢匏は次に瀺すずおりである</p> <blockquote><i>N</i> <i>M</i><br /> <i>C<sub></sub>1</i><br /> <i>C<sub>2</sub></i><br /> ...<br /> <i>C<sub>M</sub></i><br /> <i>x<sub>1</sub></i><br /> <i>x<sub>2</sub></i><br /> ...<br /> <i>x<sub>N</sub></i><br /> </blockquote> <p>最初の行は入力デヌタセットの倧きさを芏定する <i>N</i> は圧瞮する入力信号の長さ(サンプル数)である <i>M</i> はコヌドブックに含たれる倀の個数である <i>N</i> 及び <i>M</i> は1 &le; <i>N</i> &le; 200001 &le; <i>M</i> &le; 16を満たす</p> <p>これに続く <i>M</i> 行はコヌドブックの蚘述である <i>C<sub>i</sub></i> はコヌドブックに含たれる <i>i</i> 番目の倀を衚す <i>C<sub>i</sub></i> は-255 &le; <i>C<sub>i</sub></i> &le; 255を満たす</p> <p>これに続く <i>N</i> 行は入力信号の蚘述である <i>x<sub>i</sub></i> は入力信号を衚す敎数列の <i>i</i> 番目の倀である <i>x<sub>i</sub></i> は0 &le; <i>x<sub>i</sub></i> &le; 255を満たす</p> <p>デヌタセットの䞭の入力項目はすべお敎数である入力の終りは空癜文字1個で区切られた2個のれロのみからなる行で衚される</p> <h2>Output</h2> <p>入力の各デヌタセットに察しお 元の入力信号ず埩号化埌の出力信号ずの差の二乗和の最小倀を䞀行で出力せよ</p> <h2>Sample Input</h2> <pre> 2 7 4 2 1 0 -1 -2 -4 131 137 2 7 4 2 1 0 -1 -2 -4 131 123 10 7 -4 -2 -1 0 1 2 4 132 134 135 134 132 128 124 122 121 122 5 1 255 0 0 0 0 0 4 1 0 255 0 255 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 2 8 0 325125 65026 </pre>
p00157
<H1>マトリョヌシカ</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_russianDolls"> </center> <p> マトリョヌシカずは女性像をかたどった朚補の人圢で、ロシアの代衚的な民芞品です。マトリョヌシカは、倧きな人圢の䞭にそれより小さな人圢が入っおいる入れ子構造になっおおり、倧きさの異なる耇数の人圢で構成されおいたす。このような入れ子構造にするため、各人圢の胎䜓は䞊䞋で分割できる筒状の構造になっおいたす。マトリョヌシカは職人の手で手䜜りされるため、䞀぀䞀぀の人圢は䞖界に䞀぀しかない非垞に貎重なものになりたす。 </p> <p> 兄匟である䞀郎君ず次郎君は、マトリョヌシカで遊ぶのが倧奜きで、各自がそれぞれ1組のマトリョヌシカを持っおいたした。䞀郎君のマトリョヌシカは <var>n</var> 個の人圢から構成されおおり、次郎君のマトリョヌシカは <var>m</var> 個の人圢から構成されおいたす。 </p> <p> ある日、奜奇心が旺盛な䞀郎君は、これら2組のマトリョヌシカに含たれる人圢たちを組み合わせお、より倚くの人圢を含む新たなマトリョヌシカを䜜れないかず考えたした。぀たり、<var>n + m</var> 個の人圢を䜿い、<var>k</var> 個の人圢からなる組のマトリョヌシカを䜜るこずを詊みたのです。<var>n</var> ず <var>m</var> の倧きい方よりも <var>k</var> を倧きくするこずができれば、䞀郎君の目的は達成されたす。 </p> <p> 兄匟は2人仲良く、どのように人圢を組み合わせれば <var>k</var> の倀を最倧にできるかを考えたした。しかし、幌い2人にずっおこの問題はあたりにも難しいので、幎䞊のあなたはプログラムを䜜成しお匟たちを助けるこずにしたした。 </p> <p> 䞀郎君ず次郎君のマトリョヌシカの人圢の情報を入力ずし、新たなマトリョヌシカが含む人圢の数 <var>k</var> を出力するプログラムを䜜成しお䞋さい。入力される人圢に倧きさが同じものは存圚したせん。たた、人圢を高さ <var>h</var> 半埄 <var>r</var> の円柱ずみなした堎合、高さ<var>h</var>、半埄 <var>r</var> の人圢が含むこずのできる人圢は <var>x &lt; h </var> か぀ <var>y &lt; r</var> を満たす高さ <var>x</var> 半埄 <var>y</var> の人圢です。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>h<sub>1</sub></var> <var>r<sub>1</sub></var> <var>h<sub>2</sub></var> <var>r<sub>2</sub></var> : <var>h<sub>n</sub></var> <var>r<sub>n</sub></var> <var>m</var> <var>h<sub>1</sub></var> <var>r<sub>1</sub></var> <var>h<sub>2</sub></var> <var>r<sub>2</sub></var> : <var>h<sub>m</sub></var> <var>r<sub>m</sub></var> </pre> <p> 行目に䞀郎君のマトリョヌシカの人圢の数 <var>n</var> (<var>n</var> &le; 100)、続く <var>n</var> 行に䞀郎君の第 <var>i</var> の人圢の高さ <var>h<sub>i</sub></var> ず半埄 <var>r<sub>i</sub></var> (<var>h<sub>i</sub></var>, <var>r<sub>i</sub></var> &lt; 1000) が䞎えられたす。 </p> <p> 続く行に二郎君のマトリョヌシカの人圢の数 <var>m</var> (<var>m</var> &le; 100)、続く <var>m</var> 行に二郎君の第 <var>i</var> の人圢の高さ <var>h<sub>i</sub></var> ず半埄 <var>r<sub>i</sub></var> (<var>h<sub>i</sub></var>, <var>r<sub>i</sub></var> &lt; 1000) が䞎えられたす。 </p> <p> デヌタセットの数は 20 を越えない。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに新たなマトリョヌシカが含む人圢の数 <var>k</var> を出力したす。 </p> <H2>Sample Input</H2> <pre> 6 1 1 4 3 6 5 8 6 10 10 14 14 5 2 2 5 4 6 6 9 8 15 10 4 1 1 4 3 6 5 8 6 3 2 2 5 4 6 6 4 1 1 4 3 6 5 8 6 4 10 10 12 11 18 15 24 20 0 </pre> <H2>Output for the Sample Input</H2> <pre> 9 6 8 </pre>
p00507
<H1>問題 3</H1> <br/> <p>  入力ファむルの行目に正敎数 n n≧3が曞いおあり ぀づく n 行に異なる正敎数 a<sub>1</sub>, ..., a<sub>n</sub> が ぀ず぀曞いおある a<sub>1</sub>, ..., a<sub>n</sub> から異なる個を遞んで䜜られる 順列を数ずしお芋お小さい順に䞊べたずき 番目に来るものを出力せよ </p> <p>  ただし 䟋えばa<sub>1</sub> = 1a<sub>4</sub> = 11 のような堎合も a<sub>1</sub>a<sub>4</sub> ず a<sub>4</sub>a<sub>1</sub> は異なる順列ずみなす たた 1≩a<sub>i</sub>≩10000 (i=1, ..., n) か぀ 3≩n≩10<sup>4</sup> である </p> <p> <!-- 入力ファむルの改行コヌドは CR+LF である たた--> 出力ファむルにおいおは 出力の最埌にも改行コヌドを入れるこず </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 3 2 7 5 </pre> <h3>出力䟋</h3> <pre> 52 </pre> <br> <h3>入力䟋</h3> <pre> 4 17 888 1 71 </pre> <h3>出力䟋</h3> <pre> 171 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02214
<span class="lang"> <span class="lang-ja"> <h1>C: サボテンク゚リ</h1> <div class="part"> <section> <h3>問題文</h3><p>単玔無向グラフで、任意の蟺が高々 $1$ ぀の単玔閉路にしか含たれないようなものをサボテングラフず呌ぶこずにしたす。</p> <p>$N$ 頂点 $M$ 蟺の連結なサボテングラフ $G$ が䞎えられたす。</p> <p>各頂点は $1$ から $N$ たで番号が付いおいたす。</p> <p>たた、$i$ 個目の蟺は頂点 $a_i$ ず頂点 $b_i$ を結んでおり、コストは $c_i$ です。</p> <p>グラフ $G$ 䞊の単玔パスのコストを、そのパス䞊に含たれる党おの蟺のコストの XOR ず定めたす。</p> <p>以䞋のような圢匏の $Q$ 個のク゚リに答えおください。</p> <ul> <li><code>x_i y_i k_i</code> ― 頂点 $x_i$ ず頂点 $y_i$ を繋ぐすべおの単玔パスのコストを列挙しお重耇する倀を陀き、小さい順に䞊べた列を $d = d_1, d_2, ... , d_L$ ずしたずきに、$d_{k_i}$ を求めよ。ただし、このコスト列 $d$ の長さ $L$ が $k_i$ より小さい堎合は $-1$ ずする。</li> </ul> </section> </div> <div class="part"> <section> <h3>制玄</h3><ul> <li>$2 \leq N \leq 10^5$</li> <li>$N - 1 \leq M \leq 2 \times 10^5$</li> <li>$1 \leq a_i, b_i \leq N$</li> <li>$a_i \neq b_i$</li> <li>$0 \leq c_i &lt; 2^{30}$</li> <li>$1 \leq Q \leq 2 \times 10^5$</li> <li>$1 \leq x_i, y_i \leq N$</li> <li>$x_i \neq y_i$</li> <li>$1 \leq k_i \leq 2^{30}$</li> <li>䞎えられるグラフは連結なサボテングラフである。</li> <li>入力は党お敎数である。</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre>$N$ $M$ $a_1$ $b_1$ $c_1$ $a_2$ $b_2$ $c_2$ $:$ $a_M$ $b_M$ $c_M$ $Q$ $x_1$ $y_1$ $k_1$ $x_2$ $y_2$ $k_2$ $:$ $x_Q$ $y_Q$ $k_Q$ </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>$Q$ 個のク゚リの答えを䞀行ごずに順番に出力せよ。</p> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力䟋 1</h3><pre>4 4 1 2 1 1 3 8 3 2 0 1 4 7 4 1 2 1 2 1 2 1 4 1 3 4 1073741824 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 1</h3><pre>1 8 7 -1 </pre> <ul> <li> <p>頂点 $1$ から頂点 $2$ ぞの単玔パスは、蟺 $1$ のみを経由するものず、蟺 $2, 3$ を経由するもので、コストはそれぞれ $1$, $8$ です。なので、$1$ ぀めのク゚リの答えは $1$ずなりたす。</p> </li> <li> <p>頂点 $2$ から頂点 $1$ ぞの単玔パスも䞊蚘ず同様なので、 $2$ ぀目のク゚リの答えは $8$ ずなりたす。</p> </li> <li> <p>頂点 $1$ から頂点 $4$ ぞの単玔パスは、蟺 $4$ のみを経由するもののみで、コストは $7$ です。なので、$3$ ぀目のク゚リの答えは $7$ ずなりたす。</p> </li> <li> <p>頂点 $3$ から頂点 $4$ ぞの単玔パスは、蟺 $2$, $4$ を経由するものず、蟺 $3$, $1$, $4$ を経由するもので、コストはそれぞれ $15$, $6$ です。$1073741824$ 番目に小さいコストは存圚しないので、$4$ ぀目のク゚リの答えは $-1$ ずなりたす。</p> </li> </ul> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋 2</h3><pre>13 15 1 2 1 2 3 2 3 4 3 4 5 1 5 1 2 5 6 4 6 7 15 7 8 9 8 6 7 2 9 5 9 10 5 10 2 2 3 11 3 11 12 2 11 13 1 8 12 13 1 1 11 2 9 5 4 2 7 3 6 12 2 9 7 5 10 3 3 3 12 2 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 2</h3><pre>3 3 7 10 7 -1 2 -1 </pre></section> </div> </span> </span>
p00229
<H1>倧圓たり!</H1> <p> あいづ孊園倧孊附属高校の倧阿足あたる君は、スロットマシヌンで遊ぶこずにしたした。 </p> <p> このマシヌンは、メダルを投入するず、3 ぀のリヌルが回転を始め、各リヌルが自動的に止たりたす。通垞の1ゲヌム(通垞ゲヌム)は 3 枚のメダルを投入し、図柄が揃うず、その図柄に応じお次のずおりメダルが埗られたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_bighit"><br/> <br/> </center> <p> 図柄の揃い方によっおは特別なサヌビスが開始されたす。 7 の図柄が 3 ぀揃うずビッグボヌナスが始たり、ボヌナスゲヌムを 5 ゲヌム行うこずができたす。たた、BAR の図柄が 3 ぀揃うずレギュラヌボヌナスが始たり、ボヌナスゲヌムを 3 ゲヌム行うこずができたす。 </p> <p> スタヌの図柄が 3 ぀揃うず無料ゲヌムが開始され、メダルを埗るこずはできたせんが、次のゲヌムをメダルの投入なく始めるこずができたす。 </p> <p> ボヌナスゲヌム䞭は 1 ゲヌムあたり 2 枚のメダルを投入するず、自動でブドりの図柄が 3 ぀揃い、メダルを 15 枚埗るこずができたす。 </p> <p> 倧阿足君は 100 枚のメダルを持っおマシヌンで遊び始めたした。しばらく遊び、通垞ゲヌムになった状態で終了したした。手元に残ったメダルは䜕枚ずなったでしょうか。 </p> <p> プレむ情報を入力ずし、手元に残ったメダルの数を出力するプログラムを䜜成しお䞋さい。 プレむ情報ずしお、ビッグボヌナスの回数 <var>b</var>、レギュラヌボヌナスの回数 <var>r</var>、通垞ゲヌム䞭にブドりが揃った回数 <var>g</var>、チェリヌが揃った回数 <var>c</var>、スタヌが揃った回数 <var>s</var>、総ゲヌム数 <var>t</var> が䞎えられたす。 </p> <p> なお、<var>t</var> にはボヌナスゲヌムの回数を含みたす。たた、メダルはゲヌムの途䞭になくなるこずはありたせん。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロむっ぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 <pre> <var>b</var> <var>r</var> <var>g</var> <var>c</var> <var>s</var> <var>t</var> </pre> <p> <var>b, r, g, c, s</var> はそれぞれ 0 以䞊 200 以䞋の敎数、<var>t</var> は 1000 以䞋の敎数です。 </p> <p> デヌタセットの数は 120 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、手元に残ったメダルの枚数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 3 2 30 3 26 226 9 0 18 3 20 118 5 5 12 2 15 203 7 4 19 2 22 197 7 4 24 4 17 209 0 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 127 793 414 629 617 </pre>
p03956
<span class="lang-en"> <p>Score : <var>1700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid with <var>N</var> rows and <var>N</var> columns. The cell at the <var>i</var>-th row and <var>j</var>-th column is denoted (<var>i</var>, <var>j</var>).</p> <p>Initially, <var>M</var> of the cells are painted black, and all other cells are white. Specifically, the cells (<var>a_1</var>, <var>b_1</var>), (<var>a_2</var>, <var>b_2</var>), <var>...</var>, (<var>a_M</var>, <var>b_M</var>) are painted black.</p> <p>Snuke will try to paint as many white cells black as possible, according to the following rule:</p> <ul> <li>If two cells (<var>x</var>, <var>y</var>) and (<var>y</var>, <var>z</var>) are both black and a cell (<var>z</var>, <var>x</var>) is white for integers <var>1≀x,y,z≀N</var>, paint the cell (<var>z</var>, <var>x</var>) black.</li> </ul> <p>Find the number of black cells when no more white cells can be painted black.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀N≀10^5</var></li> <li><var>1≀M≀10^5</var></li> <li><var>1≀a_i,b_i≀N</var></li> <li>All pairs (<var>a_i</var>, <var>b_i</var>) are distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_M</var> <var>b_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of black cells when no more white cells can be painted black.</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>3 </pre> <p>It is possible to paint one white cell black, as follows:</p> <ul> <li>Since cells (<var>1</var>, <var>2</var>) and (<var>2</var>, <var>3</var>) are both black and a cell (<var>3</var>, <var>1</var>) is white, paint the cell (<var>3</var>, <var>1</var>) black.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 1 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p>It is possible to paint two white cells black, as follows:</p> <ul> <li>Since cells (<var>1</var>, <var>1</var>) and (<var>1</var>, <var>2</var>) are both black and a cell (<var>2</var>, <var>1</var>) is white, paint the cell (<var>2</var>, <var>1</var>) black.</li> <li>Since cells (<var>2</var>, <var>1</var>) and (<var>1</var>, <var>2</var>) are both black and a cell (<var>2</var>, <var>2</var>) is white, paint the cell (<var>2</var>, <var>2</var>) black.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 3 1 2 1 3 4 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre> <p>No white cells can be painted black.</p></section> </div> </span>
p02644
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke, a water strider, lives in a rectangular pond that can be seen as a grid with <var>H</var> east-west rows and <var>W</var> north-south columns. Let <var>(i,j)</var> be the square at the <var>i</var>-th row from the north and <var>j</var>-th column from the west.</p> <p>Some of the squares have a lotus leaf on it and cannot be entered. The square <var>(i,j)</var> has a lotus leaf on it if <var>c_{ij}</var> is <code>@</code>, and it does not if <var>c_{ij}</var> is <code>.</code>.</p> <p>In one stroke, Snuke can move between <var>1</var> and <var>K</var> squares (inclusive) toward one of the four directions: north, east, south, and west. The move may not pass through a square with a lotus leaf. Moving to such a square or out of the pond is also forbidden.</p> <p>Find the minimum number of strokes Snuke takes to travel from the square <var>(x_1,y_1)</var> to <var>(x_2,y_2)</var>. If the travel from <var>(x_1,y_1)</var> to <var>(x_2,y_2)</var> is impossible, point out that fact.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H,W,K \leq 10^6</var></li> <li><var>H \times W \leq 10^6</var></li> <li><var>1 \leq x_1,x_2 \leq H</var></li> <li><var>1 \leq y_1,y_2 \leq W</var></li> <li><var>x_1 \neq x_2</var> or <var>y_1 \neq y_2</var>.</li> <li><var>c_{i,j}</var> is <code>.</code> or <code>@</code>.</li> <li><var>c_{x_1,y_1} =</var> <code>.</code></li> <li><var>c_{x_2,y_2} =</var> <code>.</code></li> <li>All numbers 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>W</var> <var>K</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>c_{1,1}c_{1,2}</var> <var>..</var> <var>c_{1,W}</var> <var>c_{2,1}c_{2,2}</var> <var>..</var> <var>c_{2,W}</var> <var>:</var> <var>c_{H,1}c_{H,2}</var> <var>..</var> <var>c_{H,W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of strokes Snuke takes to travel from the square <var>(x_1,y_1)</var> to <var>(x_2,y_2)</var>, or print <code>-1</code> if the travel is impossible.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 2 3 2 3 4 ..... .@..@ ..@.. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>Initially, Snuke is at the square <var>(3,2)</var>. He can reach the square <var>(3, 4)</var> by making five strokes as follows:</p> <ul> <li> <p>From <var>(3, 2)</var>, go west one square to <var>(3, 1)</var>.</p> </li> <li> <p>From <var>(3, 1)</var>, go north two squares to <var>(1, 1)</var>.</p> </li> <li> <p>From <var>(1, 1)</var>, go east two squares to <var>(1, 3)</var>.</p> </li> <li> <p>From <var>(1, 3)</var>, go east one square to <var>(1, 4)</var>.</p> </li> <li> <p>From <var>(1, 4)</var>, go south two squares to <var>(3, 4)</var>.</p> </li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 6 4 1 1 1 6 ...... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 3 1 2 1 2 3 .@. .@. .@. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre></section> </div> </span>
p00679
<h1>KND Warp</h1> <h2>Problem</h2> <p>KND君は䌚接倧孊に圚籍する孊生プログラマだ。圌はその優秀な頭脳をもっおワヌプ装眮を開発したこずで有名である。ワヌプ装眮ずは䟿利なもので、ある堎所から別の堎所たで瞬時に移動するこずができる。圌はこれから地球䞊に点圚するワヌプ装眮を甚いお様々な堎所を可胜な限り早くめぐる旅を蚈画しおいる。</p> <p>圌の隣人であるあなたの仕事は3次元空間 (xyz盎亀座暙系) 䞊に存圚する<var>N</var>個のワヌプ装眮をうたく䜿甚しお、1から<var>M</var>たでの番号がふられた<var>M</var>個の点を順に通っお、<var>M</var>番目の点たで移動するずきの最小の所芁時間を求めるこずだ。はじめは1番目の点にいるものずし、どのワヌプ装眮も任意のワヌプ装眮ぞ時間0で移動できる。ワヌプ以倖の単䜍距離の移動は単䜍時間を芁する。経由点のク゚リは<var>Q</var>個䞎えられる。</p> <h2>Input</h2> <p> 入力は耇数のテストケヌスからなる。 ひず぀のテストケヌスは以䞋の圢匏で䞎えられる。 入力の終わりを<var>N</var> = <var>Q</var> = 0のずき瀺す。 </p> <pre> <var>N</var> <var>Q</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>z<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>z<sub>2</sub></var> ... <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>z<sub>N</sub></var> <var>M<sub>1</sub></var> <var>x<sub>1,1</sub></var> <var>y<sub>1,1</sub></var> <var>z<sub>1,1</sub></var> <var>x<sub>1,2</sub></var> <var>y<sub>1,2</sub></var> <var>z<sub>1,2</sub></var> ... <var>x<sub>1,M</sub></var> <var>y<sub>1,M</sub></var> <var>z<sub>1,M</sub></var> <var>M<sub>2</sub></var> <var>x<sub>2,1</sub></var> <var>y<sub>2,1</sub></var> <var>z<sub>2,1</sub></var> <var>x<sub>2,2</sub></var> <var>y<sub>2,2</sub></var> <var>z<sub>2,2</sub></var> ... <var>x<sub>2,M</sub></var> <var>y<sub>2,M</sub></var> <var>z<sub>2,M</sub></var> ... <var>M<sub>Q</sub></var> <var>x<sub>Q,1</sub></var> <var>y<sub>Q,1</sub></var> <var>z<sub>Q,1</sub></var> <var>x<sub>Q,2</sub></var> <var>y<sub>Q,2</sub></var> <var>z<sub>Q,2</sub></var> ... <var>x<sub>Q,M</sub></var> <var>y<sub>Q,M</sub></var> <var>z<sub>Q,M</sub></var> </pre> <p> ここで、 </p> <ul> <li><var>N</var>:ワヌプ装眮の数</li> <li><var>Q</var>:旅のク゚リの数</li> <li><var>M<sub>i</sub></var>:i番目ク゚リの旅で蚪れる点の数</li> <li><var>x<sub>i,j</sub></var>,<var>y<sub>i,j</sub></var>,<var>z<sub>i,j</sub></var>:i番目のク゚リの旅で蚪れるj番目の点の座暙(x,y,z)</li> </ul> <p> である。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>テストケヌスの数は15個を超えない。</li> <li>入力の半分皋床は<var>N</var>&le;1000を満たす。</li> <li>入力に含たれる倀はすべお敎数。</li> <li>2&le;<var>N</var>&le;100,000</li> <li>1&le;<var>Q</var>&le;1,000</li> <li>2&le;<var>M</var>&le;100</li> <li>-1,000,000&le;(党おのx,y,z座暙倀)&le;1,000,000</li> <li>ワヌプ装眮は䞊蚘の制玄を満たす空間䞭にランダムに分垃する(Sample Inputは䟋倖)。</li> <li>ワヌプ装眮同士、䞭継点同士、ワヌプ装眮ず䞭継点はそれぞれ重なるこずがある。</li> </ul> <h2>Output</h2> <p>各ク゚リに぀き最小の所芁時間を䞀行に出力せよ。この倀はゞャッゞ出力の倀ず10<sup>-4</sup>より倧きい差を持っおはならない。</p> <h2>Sample Input</h2> <pre> 3 2 0 0 0 1 1 1 2 2 2 4 -1 -1 -1 3 3 3 -1 -1 -1 4 4 4 2 1234 5678 9012 1716 6155 9455 0 0 </pre> <h2>Sample Output</h2> <pre> 12.124355653 810.001234567 </pre> <h2>Notes</h2> <p>入力ファむルのサむズは4MB皋床になる。入力は高速にしたほうがよいが、たずえばC++であればcinでも十分である。</p>
p00383
<h1>Points on a Straight Line</h1>   <p> The university of A stages a programming contest this year as has been the case in the past. As a member of the team in charge of devising the problems, you have worked out a set of input data for a problem, which is an arrangement of points on a 2D plane in the coordinate system. The problem requires that any combination of these points greater than or equal to $K$ in number must not align on a line. You want to confirm that your data satisfies this requirement. </p> <p> Given the number of points $K$ and their respective 2D coordinates, make a program to check if any combination of points greater or equal to $K$ align on a line. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $K$ $x_1$ $y_1$ $x_2$ $y_2$ $...$ $x_N$ $y_N$ </pre> <p> The first line provides the number of points $N$ ($3 \leq N \leq 3000$) on the 2D coordinate system and an integer $K$ ($3 \leq K \leq N$). Each of the subsequent lines provides the $i$-th coordinate $x_i,y_i$ ($0 \leq x_i,y_i \leq 10000$) as integers. None of these coordinates coincide, i.e., if $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$. </p> <h2>Output</h2> <p> Output <span>1</span> if any combination of points greater or equal to $K$ aligns on a line, or <span>0</span> otherwise. </p> <h2>Sample Input 1</h2> <pre> 5 4 0 0 1 0 1 1 0 1 2 2 </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <h2>Sample Input 2</h2> <pre> 7 5 0 0 1 0 1 1 0 1 2 0 3 0 4 0 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre>
p01438
<H1><font color="#000">Problem B:</font> Butterfly</H1> <p> Claire is a man-eater. She's a real man-eater. She's going around with dozens of guys. She's dating all the time. And one day she found some conflicts in her date schedule. D'oh! </p> <p> So she needs to pick some dates and give the others up. The dates are set by hours like 13:00 to 15:00. She may have more than one date with a guy. For example, she can have dates with Adam from 10:00 to 12:00 and from 14:00 to 16:00 and with Bob from 12:00 to 13:00 and from 18:00 to 20:00. She can have these dates as long as there is no overlap of time. Time of traveling, time of make-up, trouble from love triangles, and the likes are not of her concern. Thus she can keep all the dates with Adam and Bob in the previous example. All dates are set between 6:00 and 22:00 on the same day. </p> <p> She wants to get the maximum amount of satisfaction in total. Each guy gives her some satisfaction if he has all scheduled dates. Let's say, for example, Adam's satisfaction is 100 and Bob's satisfaction is 200. Then, since she can make it with both guys, she can get 300 in total. Your task is to write a program to satisfy her demand. Then she could spend a few hours with you... if you really want. </p> <H2>Input</H2> <p> The input consists of a sequence of datasets. Each dataset has the following format: </p> <p> <i>N</i><br> <i>Guy</i><sub>1</sub><br> ...<br> <i>Guy</i><sub><i>N</i></sub><br> </p> <p> The first line of the input contains an integer N (1 &le; <i>N</i> &le; 100), the number of guys. Then there come the descriptions of guys. Each description is given in this format: </p> <p> <i>M L</i><br> <i>S</i><sub>1</sub> <i>E</i><sub>1</sub><br> ...<br> <i>S</i><sub><i>M</i></sub> <i>E</i><sub><i>M</i></sub><br> </p> <p> The first line contains two integers <i>M<sub>i</sub></i> (1 &le; <i>M<sub>i</sub></i> &le; 16) and <i>L<sub>i</sub></i> (1 &le; <i>L<sub>i</sub></i> &le; 100,000,000), the number of dates set for the guy and the satisfaction she would get from him respectively. Then <i>M</i> lines follow. The <i>i</i>-th line contains two integers <i>S<sub>i</sub></i> and <i>E<sub>i</sub></i> (6 &le; <i>S<sub>i</sub></i> &lt; <i>E<sub>i</sub></i> &le; 22), the starting and ending time of the <i>i</i>-th date. </p> <p> The end of input is indicated by <i>N</i> = 0. </p> <H2>Output</H2> <p> For each dataset, output in a line the maximum amount of satisfaction she can get. </p> <H2>Sample Input</H2> <pre> 2 2 100 10 12 14 16 2 200 12 13 18 20 4 1 100 6 22 1 1000 6 22 1 10000 6 22 1 100000 6 22 16 1 100000000 6 7 1 100000000 7 8 1 100000000 8 9 1 100000000 9 10 1 100000000 10 11 1 100000000 11 12 1 100000000 12 13 1 100000000 13 14 1 100000000 14 15 1 100000000 15 16 1 100000000 16 17 1 100000000 17 18 1 100000000 18 19 1 100000000 19 20 1 100000000 20 21 1 100000000 21 22 0 </pre> <H2>Output for the Sample Input</H2> <pre> 300 100000 1600000000 </pre>
p03405
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have an undirected weighted graph with <var>N</var> vertices and <var>M</var> edges. The <var>i</var>-th edge in the graph connects Vertex <var>U_i</var> and Vertex <var>V_i</var>, and has a weight of <var>W_i</var>. Additionally, you are given an integer <var>X</var>.</p> <p>Find the number of ways to paint each edge in this graph either white or black such that the following condition is met, modulo <var>10^9 + 7</var>:</p> <ul> <li>The graph has a spanning tree that contains both an edge painted white and an edge painted black. Furthermore, among such spanning trees, the one with the smallest weight has a weight of <var>X</var>.</li> </ul> <p>Here, the weight of a spanning tree is the sum of the weights of the edges contained in the spanning tree.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1</var> <var>000</var></li> <li><var>1 \leq M \leq 2</var> <var>000</var></li> <li><var>1 \leq U_i, V_i \leq N</var> (<var>1 \leq i \leq M</var>)</li> <li><var>1 \leq W_i \leq 10^9</var> (<var>1 \leq i \leq M</var>)</li> <li>If <var>i \neq j</var>, then <var>(U_i, V_i) \neq (U_j, V_j)</var> and <var>(U_i, V_i) \neq (V_j, U_j)</var>.</li> <li><var>U_i \neq V_i</var> (<var>1 \leq i \leq M</var>)</li> <li>The given graph is connected.</li> <li><var>1 \leq X \leq 10^{12}</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>X</var> <var>U_1</var> <var>V_1</var> <var>W_1</var> <var>U_2</var> <var>V_2</var> <var>W_2</var> <var>:</var> <var>U_M</var> <var>V_M</var> <var>W_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 2 1 2 1 2 3 1 3 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 3 1 2 1 2 3 1 3 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 4 1 1 2 3 1 3 3 2 4 6 2 5 8 </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>8 10 49 4 6 10 8 4 11 5 8 9 1 8 10 3 8 128773450 7 8 10 4 2 4 3 4 1 3 1 13 5 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>4 </pre></section> </div> </span>
p01068
<h1>Equivalent Vertices</h1> <h2>Background</h2> <p> 䌚接倧孊付属幌皚園はプログラミングが倧奜きな子䟛が集たる幌皚園である。 園児の䞀人であるゆう君は,プログラミングず同じくらいお絵描きが倧奜きだ。 これたでゆう君は䞞ず六角圢ず矢印で沢山絵を曞いおきた。 ある日ゆう君はこれらの絵がグラフであるこずを知る。 䞞ず六角圢は頂点ず呌ばれ,矢印は蟺ず呌ばれおいるらしい。 ゆう君は2぀の頂点間を結ぶようにしお矢印を描き、曎にその䞊に0か1を曞く。 このように,蟺に重み(0たたは1)があり有向な蟺からなるグラフは重み付き有向グラフず呌ばれる。 たた,頂点ず数字<var>x</var>(0たたは1)が䞎えられた時,その頂点から出おいる矢印のうち,<var>x</var>ず同じ重みを持぀矢印に埓っお別の頂点に移動するこずを<I><var>x</var>に埓っお遷移する</I>ず蚀う。 今日ゆう君は0ず1からなるどのような数列に埓っお遷移しおも最終的に到達する頂点の皮類(䞞たたは六角圢)が䞀緒であるような頂点の察が存圚するこずに気が぀いた。 これに぀いおゆう君は䞀぀の問題を思い぀いた。 </p> <h2>Problem</h2> <p> 重み付き有向グラフが䞎えられる。 このグラフの各頂点は0から順番に<var>n</var>-1たで番号が割り振られおいる。 たた,各頂点はそこから重みが0の蟺ず1の蟺の合蚈2本の蟺が出お行く。 さらに,頂点には䞞い頂点か六角圢の頂点の2皮類が存圚し,各頂点はそれらのいずれかである。 以䞋にSample Input 2で䞎えられる重み付き有向グラフを瀺す。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_UAPC2016Spring_L1" alt="図" width="680" ><br> 図1. Sample Input 2 </center> <br> <p> 以䞋の圢匏で<var>m</var>個の質問が䞎えられるので、それぞれに぀いお答えを出力せよ。 </p> <ul> <li>頂点の番号<var>q</var>が䞎えられるので,この頂点ず<I>等䟡</I>な頂点の数を出力せよ</li> </ul> <p> 2぀の頂点<var>a</var>,<var>b</var>が以䞋の2぀の条件を満たすずき,<var>a</var>ず<var>b</var>は等䟡である。 </p> <ol> <li><var>a</var>ず<var>b</var>は同じ皮類の頂点である</li> <li>0ず1からなる長さ1以䞊の任意の数列に぀いお,それに埓っお<var>a</var>ず<var>b</var>のそれぞれから遷移を開始したずき最終的に到達する頂点の皮類が同じである</li> </ol> <p> 䟋えば,図1の頂点3から数列0,0,1,0に埓っお遷移を開始するず, 3&rarr;2&rarr;1&rarr;1&rarr;1の順番で遷移し最終的に到達する頂点は1である。 </p> <p> Sample Input 2 においお,頂点0ず頂点2,頂点0ず頂点4は等䟡である。 頂点0ず頂点4に぀いお考える。 これらは䞡方ずも䞞い頂点であるため1぀めの条件を満たす。 たた,これらの頂点から0たたは1で遷移した結果到達する頂点は1か5である。 頂点1,5はそれぞれどのような数列に埓っお遷移しおもその頂点に止たり続ける。 たた,䞡方ずも六角圢の頂点である。 これより,頂点0ず頂点4はどのような数列に埓っお遷移しおも最終的に到達する頂点は六角圢の頂点であるため2぀めの条件も満たす。 条件を2぀ずも満たすので頂点0ず頂点4は等䟡である。 最終的に到達する頂点は皮類が同じであれば良いため,頂点の番号が同じである必芁はないこずに泚意せよ。 たた,頂点0ず頂点1は等䟡でない。 頂点0は䞞い頂点で頂点1は六角圢頂点なので,1぀めの条件を満たさない。 </p> <h2>Input</h2> <pre> <var>n</var> <var>m</var> <var>v<sub>0</sub></var> <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>v<sub>1</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> 
 <var>v<sub>n&minus;1</sub></var> <var>s<sub>n&minus;1</sub></var> <var>t<sub>n&minus;1</sub></var> <var>q<sub>0</sub></var> <var>q<sub>1</sub></var> 
 <var>q<sub>m&minus;1</sub></var> </pre> <ul> <li><var>v<sub>i</sub></var>,<var>s<sub>i</sub></var>,<var>t<sub>i</sub></var>はそれぞれ<var>i</var>番の頂点の皮類,0による遷移先の頂点番号,1による遷移先の頂点番号</li> <li><var>v<sub>i</sub></var>が0のずき,<var>i</var>番の頂点は䞞い頂点であり,1のずき六角圢の頂点</li> <li><var>q<sub>j</sub></var>は<var>j</var>番目の質問で䞎えられる頂点の番号</li> </ul> <h2>Constraints</h2> <ul> <li> 入力は党お敎数ずしお䞎えられる</li> <li> 1 &le; <var>n</var> &le; 3000</li> <li> 1 &le; <var>m</var> &le; n</li> <li> 0 &le; <var>s<sub>i</sub></var>,<var>t<sub>i</sub></var>,<var>q<sub>j</sub></var> &le; <var>n</var>-1</li> <li> 0 &le; <var>v<sub>i</sub></var> &le; 1</li> <li> 䞎えられるグラフの蟺が双方向に移動できるものずしたずき,任意の2点を結ぶような蟺の集合が存圚する, ぀たり䞎えられるグラフは連結である</li> </ul> <h2>Output</h2> <p> 各質問で䞎えられる頂点の番号<var>q<sub>j</sub></var>に察しお,それず等䟡な頂点の数をそれぞれ䞀行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 2 1 0 0 1 0 1 0 0 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 6 6 0 1 5 1 1 1 0 1 5 0 2 1 0 5 1 1 5 5 0 1 2 3 4 5 </pre> <h2>Sample Output 2</h2> <pre> 3 2 3 1 3 2 </pre>
p03055
<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 on a tree. The tree has <var>N</var> vertices numbered <var>1</var> to <var>N</var>, and the <var>i</var>-th of the <var>N-1</var> edges connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p> <p>At the beginning of the game, each vertex contains a coin. Starting from Takahashi, he and Aoki will alternately perform the following operation:</p> <ul> <li>Choose a vertex <var>v</var> that contains one or more coins, and remove all the coins from <var>v</var>.</li> <li>Then, move each coin remaining on the tree to the vertex that is nearest to <var>v</var> among the adjacent vertices of the coin's current vertex.</li> </ul> <p>The player who becomes unable to play, loses the game. That is, the player who takes his turn when there is no coin remaining on the tree, loses the game. Determine the winner of the game when both players play optimally.</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_i \neq b_i</var></li> <li>The graph given as input is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>First</code> if Takahashi will win, and print <code>Second</code> if Aoki will win.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>First </pre> <p>Here is one possible progress of the game:</p> <ul> <li>Takahashi removes the coin from Vertex <var>1</var>. Now, Vertex <var>1</var> and Vertex <var>2</var> contain one coin each.</li> <li>Aoki removes the coin from Vertex <var>2</var>. Now, Vertex <var>2</var> contains one coin.</li> <li>Takahashi removes the coin from Vertex <var>2</var>. Now, there is no coin remaining on the tree.</li> <li>Aoki takes his turn when there is no coin on the tree and loses.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 2 2 3 2 4 4 6 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Second </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 7 7 4 3 4 7 5 6 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>First </pre></section> </div> </span>
p01592
<h2>Problem B: Blame Game</h2> <p>Alice and Bob are in a factional dispute. Recently a big serious problem arised in a project both Alice and Bob had been working for. This problem was caused by lots of faults of Alice's and Bob's sides; those faults are closely related.</p> <p>Alice and Bob started to blame each other. First, Alice claimed it was caused by Bob's fault. Then Bob insisted his fault was led by Alice's fault. Soon after, Alice said that her fault should not have happened without Bob's another fault. So on so forth. It was terrible. It was totally a blame game. Still, they had their pride. They would not use the same fault more than once in their claims.</p> <p>All right, let's see the situation in terms of a game.</p> <p>Alice and Bob have a number of faults. Some pairs of Alice and Bob faults have direct relationship between them. This relationship is bidirectional; if a fault X is led by another fault Y, they can say either "X was due to Y." or "even with X, the problem could be avoided without Y." Note that not both, since they never pick up the same fault in their claims.</p> <p>Alice and Bob take their turns alternatively. Alice takes the first turn by claiming any of Bob's faults. Then Bob makes his claim with Alice's fault directly related to the claimed fault. Afterward, in each turn, one picks up another's fault directly related to the fault claimed in the previous turn. If he/she has no faults that have not been claimed, then he/she loses this game.</p> <p>By the way, you have been working both under Alice and Bob. You know all the faults and relationships. Your task is to write a program to find out which would win this game, under the assumption that they always take their optimal strategies. If you could choose the winning side, you would not have to take the responsibility for the arisen problem.</p> <h2>Input</h2> <p>Each input contains one test case. The first line of the input contains two integers <var>N</var> and <var>M</var> (0 <= <var>N</var>, <var>M</var> <= 500), which denote the numbers of Alice's and Bob's faults respectively. Alice's faults are numbered from 1 to <var>N</var>; so are Bob's from 1 to <var>M</var>. Then <var>N</var> lines follow to describe the relationships among the faults. The <var>i</var>-th line begins with a non-negative integer <var>K<sub>i</sub></var> (0 <= <var>K<sub>i</sub></var> <= <var>M</var>). It is then followed by <var>K<sub>i</sub></var> positive integers, where the <var>j</var>-th number <var>b<sub>i,j</sub></var> (1 <= <var>b<sub>i,j</sub></var> <= <var>M</var>) indicates there is a direct relationship between the <var>i</var>-th Alice's fault and the <var>b<sub>i,j</sub></var>-th Bob's fault. It is guaranteed that <var>b<sub>i,j</sub></var> != <var>b<sub>i,j'</sub></var> for all <var>i</var>, <var>j</var>, <var>j'</var> such that 1 <= <var>i</var> <= <var>N</var> and 1 <= <var>j</var> < <var>j'</var> <= <var>K<sub>i</sub></var>.</p> <h2>Output</h2> <p>Print either "Alice" or "Bob" to indicate the winner of the blame game.</p> <h2>Sample Input 1</h2> <pre> 1 1 1 1 </pre> <h2>Output for the Sample Input 1</h2> <pre> Bob </pre> <h2>Sample Input 2</h2> <pre> 3 3 3 1 2 3 1 3 1 3 </pre> <h2>Output for the Sample Input 2</h2> <pre> Alice </pre>
p01087
<h2>ICPC Calculator</h2> <p> In mathematics, we usually specify the order of operations by using parentheses. For example, 7 × (3 + 2) always means multiplying 7 by the result of 3 + 2 and never means adding 2 to the result of 7 × 3. However, there are people who do not like parentheses. International Counter of Parentheses Council (ICPC) is attempting to make a notation without parentheses the world standard. They are always making studies of such no-parentheses notations. </p> <p> Dr. Tsukuba, a member of ICPC, invented a new parenthesis-free notation. In his notation, a single expression is represented by multiple lines, each of which contains an addition operator (<t>+</t>), a multiplication operator (<t>*</t>) or an integer. An expression is either a single integer or an operator application to <i>operands.</i> Integers are denoted in decimal notation in one line. An operator application is denoted by a line of its operator immediately followed by lines denoting its two or more operands, each of which is an expression, recursively. Note that when an operand is an operator application, it comprises multiple lines. </p> <p> As expressions may be arbitrarily nested, we have to make it clear which operator is applied to which operands. For that purpose, each of the expressions is given its <i>nesting level.</i> The top level expression has the nesting level of 0. When an expression of level <i>n</i> is an operator application, its operands are expressions of level <i>n</i> + 1. The first line of an expression starts with a sequence of periods (<t>.</t>), the number of which indicates the level of the expression. </p> <p> For example, 2 + 3 in the regular mathematics is denoted as in Figure 1. An operator can be applied to two or more operands. Operators <t>+</t> and <t>*</t> represent operations of summation of all operands and multiplication of all operands, respectively. For example, Figure 2 shows an expression multiplying 2, 3, and 4. For a more complicated example, an expression (2 + 3 + 4) × 5 in the regular mathematics can be expressed as in Figure 3 while (2 + 3) × 4 × 5 can be expressed as in Figure 4. </p> <pre>+ .2 .3 </pre> Figure 1: 2 + 3 <br><br> <pre>* .2 .3 .4 </pre> Figure 2: An expression multiplying 2, 3, and 4 <br><br> <pre>* .+ ..2 ..3 ..4 .5 </pre> Figure 3: (2 + 3 + 4) × 5 <br><br> <pre>* .+ ..2 ..3 .4 .5 </pre> Figure 4: (2 + 3) × 4 × 5 <br><br> <p> Your job is to write a program that computes the value of expressions written in Dr. Tsukuba's notation to help him. </p> <h3>Input</h3> <p> The input consists of multiple datasets. Each dataset starts with a line containing a positive integer <i>n</i>, followed by <i>n</i> lines denoting a single expression in Dr. Tsukuba's notation. </p> <p> You may assume that, in the expressions given in the input, every integer comprises a single digit and that every expression has no more than nine integers. You may also assume that all the input expressions are valid in the Dr. Tsukuba's notation. The input contains no extra characters, such as spaces or empty lines. </p> <p> The last dataset is immediately followed by a line with a single zero. </p> <h3>Output</h3> <p> For each dataset, output a single line containing an integer which is the value of the given expression. </p> <h3>Sample Input</h3> <pre>1 9 4 + .1 .2 .3 9 + .0 .+ ..* ...1 ...* ....1 ....2 ..0 10 + .+ ..6 ..2 .+ ..1 ..* ...7 ...6 .3 0 </pre> <h3>Output for the Sample Input</h3> <pre>9 6 2 54 </pre>
p03540
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In some place in the Arctic Ocean, there are <var>H</var> rows and <var>W</var> columns of ice pieces floating on the sea. We regard this area as a grid, and denote the square at the <var>i</var>-th row and <var>j</var>-th column as Square <var>(i,j)</var>. The ice piece floating in each square is either thin ice or an iceberg, and a penguin lives in one of the squares that contain thin ice. There are no ice pieces floating outside the grid.</p> <p>The ice piece at Square <var>(i,j)</var> is represented by the character <var>S_{i,j}</var>. <var>S_{i,j}</var> is <code>+</code>, <code>#</code> or <code>P</code>, each of which means the following:</p> <ul> <li><code>+</code>: Occupied by thin ice.</li> <li><code>#</code>: Occupied by an iceberg.</li> <li><code>P</code>: Occupied by thin ice. The penguin lives here.</li> </ul> <p>When summer comes, unstable thin ice that is not held between some pieces of ice collapses one after another. Formally, thin ice at Square <var>(i,j)</var> will collapse when it does NOT satisfy either of the following conditions:</p> <ul> <li>Both Square <var>(i-1,j)</var> and Square <var>(i+1,j)</var> are occupied by an iceberg or uncollapsed thin ice.</li> <li>Both Square <var>(i,j-1)</var> and Square <var>(i,j+1)</var> are occupied by an iceberg or uncollapsed thin ice.</li> </ul> <p>When a collapse happens, it may cause another. Note that icebergs do not collapse.</p> <p>Now, a mischievous tourist comes here. He will do a little work so that, when summer comes, the thin ice inhabited by the penguin will collapse. He can smash an iceberg with a hammer to turn it to thin ice. At least how many icebergs does he need to smash?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H,W \leq 40</var></li> <li><var>S_{i,j}</var> is <code>+</code>, <code>#</code> or <code>P</code>.</li> <li><var>S</var> contains exactly one <code>P</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>S_{1,1}</var><var>S_{1,2}</var><var>...</var><var>S_{1,W}</var> <var>S_{2,1}</var><var>S_{2,2}</var><var>...</var><var>S_{2,W}</var> <var>:</var> <var>S_{H,1}</var><var>S_{H,2}</var><var>...</var><var>S_{H,W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of icebergs that needs to be changed to thin ice in order to cause the collapse of the thin ice inhabited by the penguin when summer comes.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 +#+ #P# +#+ </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>For example, when the right and bottom icebergs are changed to thin ice, collapses happen as follows:</p> <pre>+#+ .#. .#. .#. #P+ -&gt; #P+ -&gt; #P. -&gt; #.. +++ .+. ... ... </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 6 #+++++ +++#++ #+++++ +++P+# +##+++ ++++#+ </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>40 40 #++#+++++#+#+#+##+++++++##+#+++#++##++## +##++++++++++#+###+##++++#+++++++++#++## +++#+++++#++#++####+++#+#+###+++##+++#++ +++#+######++##+#+##+#+++#+++++++++#++#+ +++##+#+#++#+++#++++##+++++++++#++#+#+#+ #++#+++#+#++++##+#+#+++##+#+##+#++++##++ ++#+##+++#++####+#++##++#+++#+#+#++++#++ +#+###++++++##++++++#++##+#####++#++##++ ##+##+#+++#+#+##++#+###+######++++#+###+ +++#+++##+#####+#+#++++#+#+++++#+##++##+ #+++#+##+++++++#++#++++++++++###+#++#+#+ ##+++##++#+++++#++++#++#+##++#+#+#++##+# ##+++#+###+++++##++#+#+++####+#+++++#+++ +++#++#++#+++++++++#++###++++++++###+##+ ++#+++#++++++#####++##++#+++#+++++#++++# ++#++#+##++++#####+###+++####+#+#+###### ++++++##+++++##+++++#++###++#++##+++++++ +#++++##++++++#++++#+#++++#++++##+++##+# +++++++#+#++##+##+#+++++++###+###++##+++ ++++++#++###+#+#+++##+#++++++#++#+#++#+# ##+##++++++#+++++#++#+#++##+++#+#+++##+# #+++#+#+##+#+##++#P#++#++++++##++#+#++## #+++#++##+##+#++++#++#++##++++++#+#+#+++ ++++####+#++#####+++#+###+#++###++++#++# #+#++####++##++#+#+#+##+#+#+##++++##++#+ +###+###+#+##+++#++++++#+#++++###+#+++++ +++#+++++#+++#+++++##++++++++###++#+#+++ +#+#++#+#++++++###+#++##+#+##+##+#+##### #++++++++#+#+###+######++#++#+++++++++++ ##+++##+#+#++#++#++#++++++#++##+#+#++### +#+#+#+++++++#+++++++######+##++#++##+## ++#+++#+###+#++###+++#+++#+#++++#+###+++ #+#+###++#+#####+++++#+####++#++#+###+++ +#+##+#++#++##+++++++######++#++++++++++ +####+#+#+++++##+#+#++#+#++#+++##++++#+# #++##++#+#+++++##+#++++####+++++###+#+#+ ##+#++#++#+##+#+#++##++###+###+#+++++##+ ##++###+###+#+#++#++#########+++###+#+## +++#+++#++++++++++#+#+++#++#++###+####+# ++##+###+++++++##+++++#++#++++++++++++++ </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>151 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 1 P </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 </pre></section> </div> </span>
p03110
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi received <em>otoshidama</em> (New Year's money gifts) from <var>N</var> of his relatives.</p> <p>You are given <var>N</var> values <var>x_1, x_2, ..., x_N</var> and <var>N</var> strings <var>u_1, u_2, ..., u_N</var> as input. Each string <var>u_i</var> is either <code>JPY</code> or <code>BTC</code>, and <var>x_i</var> and <var>u_i</var> represent the content of the otoshidama from the <var>i</var>-th relative.</p> <p>For example, if <var>x_1 =</var> <code>10000</code> and <var>u_1 =</var> <code>JPY</code>, the otoshidama from the first relative is <var>10000</var> Japanese yen; if <var>x_2 =</var> <code>0.10000000</code> and <var>u_2 =</var> <code>BTC</code>, the otoshidama from the second relative is <var>0.1</var> bitcoins.</p> <p>If we convert the bitcoins into yen at the rate of <var>380000.0</var> JPY per <var>1.0</var> BTC, how much are the gifts worth in total?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10</var></li> <li><var>u_i =</var> <code>JPY</code> or <code>BTC</code>.</li> <li>If <var>u_i =</var> <code>JPY</code>, <var>x_i</var> is an integer such that <var>1 \leq x_i \leq 10^8</var>.</li> <li>If <var>u_i =</var> <code>BTC</code>, <var>x_i</var> is a decimal with <var>8</var> decimal digits, such that <var>0.00000001 \leq x_i \leq 100.00000000</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_1</var> <var>u_1</var> <var>x_2</var> <var>u_2</var> <var>:</var> <var>x_N</var> <var>u_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the gifts are worth <var>Y</var> yen in total, print the value <var>Y</var> (not necessarily an integer).</p> <p>Output will be judged correct when the absolute or relative error from the judge's output is at most <var>10^{-5}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 10000 JPY 0.10000000 BTC </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>48000.0 </pre> <p>The otoshidama from the first relative is <var>10000</var> yen. The otoshidama from the second relative is <var>0.1</var> bitcoins, which is worth <var>38000.0</var> yen if converted at the rate of <var>380000.0</var> JPY per <var>1.0</var> BTC. The sum of these is <var>48000.0</var> yen.</p> <p>Outputs such as <code>48000</code> and <code>48000.1</code> will also be judged correct.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 100000000 JPY 100.00000000 BTC 0.00000001 BTC </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>138000000.0038 </pre> <p>In this case, outputs such as <code>138001000</code> and <code>1.38e8</code> will also be judged correct.</p></section> </div> </span>
p01984
<h3>短歌数</h3> <!-- begin ja only --> <p>願はくは 花の䞋にお 春死なむ そのきさらぎの 望月のころ</p> <p>これは西行法垫が詠んだずされる有名な短歌の䞀぀である 短歌は日本においお叀くから芪したれおいる和歌の䞀皮でありその倚くは 5・7・5・7・7 の五句䞉十䞀音からなる</p> <p>ずころで57577 ずいう数は5 ず 7 の二皮類の数字からなる このような十進衚蚘がちょうど二皮類の数字からなる正の敎数を短歌数ず呌ぶこずにする 䟋えば10, 12, 57577, 25252 などは短歌数であるが5, 11, 123, 20180701 などは短歌数ではない</p> <p>正の敎数 <i>N</i> が䞎えられる<i>N</i> 番目に小さい短歌数を求めよ</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は最倧で 100 個のデヌタセットからなる各デヌタセットは次の圢匏で衚される</p> <blockquote><i>N</i></blockquote> <p>敎数 <i>N</i> は <i>1 &le; N &le; 10<sup>18</sup></i> を満たす</p> <p>入力の終わりは 1 ぀のれロからなる行で衚される</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに぀いお<i>N</i> 番目に小さい短歌数を 1 行に出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>1 2 3 390 1124 1546 314159265358979323 0 </pre><h3>Output for the Sample Input</h3><pre>10 12 13 2020 25252 57577 7744444777744474777777774774744777747477444774744744 </pre>
p00696
<h1> Multi-column List </h1> <P>Ever since Mr. Ikra became the chief manager of his office, he has had little time for his favorites, programming and debugging. So he wants to check programs in trains to and from his office with program lists. He has wished for the tool that prints source programs as multi-column lists so that each column just fits in a pocket of his business suit. </P> <P>In this problem, you should help him by making a program that prints the given input text in a multi-column format. Since his business suits have various sizes of pockets, your program should be flexible enough and accept four parameters, (1) the number of lines in a column, (2) the number of columns in a page, (3) the width of each column, and (4) the width of the column spacing. We assume that a fixed-width font is used for printing and so the column width is given as the maximum number of characters in a line. The column spacing is also specified as the number of characters filling it. </P> <H2>Input</H2> <P>In one file, stored are data sets in a form shown below.</P> <PRE> <I>plen</I><SUB>1</SUB> <I>cnum</I><SUB>1</SUB> <I>width</I><SUB>1</SUB> <I>cspace</I><SUB>1</SUB> <I>line</I><SUB>1</SUB><SUB>1</SUB> <I>line</I><SUB>1</SUB><SUB>2</SUB> .... <I>line</I><SUB>1</SUB><SUB>i</SUB> .... ? <I>plen</I><SUB>2</SUB> <I>cnum</I><SUB>2</SUB> <I>width</I><SUB>2</SUB> <I>cspace</I><SUB>2</SUB> <I>text</I><SUB>2</SUB> <I>line</I><SUB>2</SUB><SUB>1</SUB> <I>line</I><SUB>2</SUB><SUB>2</SUB> .... <I>line</I><SUB>2</SUB><SUB>i</SUB> .... ? 0 </PRE> <P>The first four lines of each data set give positive integers specifying the output format. <I>Plen</I> (1 &lt;= <I>plen</I> &lt;= 100) is the number of lines in a column. <I>Cnum</I> is the number of columns in one page. <I>Width</I> is the column width, i.e., the number of characters in one column. <I>Cspace</I> is the number of spacing characters between each pair of neighboring columns. You may assume 1 &lt;= (<I>cnum</I> * <I>width</I> + <I>cspace</I> * (<I>cnum</I>-1)) &lt;= 50. </P> <P>The subsequent lines terminated by a line consisting solely of '?' are the input text. Any lines of the input text do not include any characters except alphanumeric characters '0'-'9', 'A'-'Z', and 'a'-'z'. Note that some of input lines may be empty. No input lines have more than 1,000 characters. </P> <H2>Output</H2> <P> Print the formatted pages in the order of input data sets. Fill the gaps among them with dot('.') characters. If an output line is shorter than <I>width</I>, also fill its trailing space with dot characters. An input line that is empty shall occupy a single line on an output column. This empty output line is naturally filled with dot characters. An input text that is empty, however, shall not occupy any page. A line larger than <I>width</I> is wrapped around and printed on multiple lines. At the end of each page, print a line consisting only of '#'. At the end of each data set, print a line consisting only of '?'. </P> <H2>Sample Input</H2> <PRE> 6 2 8 1 AZXU5 1GU2D4B K PO4IUTFV THE Q34NBVC78 T 1961 XWS34WQ LNGLNSNXTTPG ED MN MLMNG ? 4 2 6 2 QWERTY FLHL ? 0 </PRE> <H2>Output for the Sample Input</H2> <P>You Should see the following section with a fixed-width font. </P> <PRE> AZXU5....8....... 1GU2D4B..T....... K........1961.... PO4IUTFV.XWS34WQ. THE.............. Q34NBVC7.LNGLNSNX # TTPG............. ED............... MN............... MLMNG............ ................. ................. # ? QWERTY........ FLHL.......... .............. .............. # ? </PRE>
p02351
<H1>RSQ and RAQ</H1> <p> Write a program which manipulates a sequence <var>A</var> = {<var>a<sub>1</sub>, a<sub>2</sub>, . . . , a<sub>n</sub></var>} with the following operations: </p> <ul> <li><var>add(s, t, x)</var>: add <var>x</var> to <var>a<sub>s</sub></var>, <var>a<sub>s+1</sub></var>, ..., <var>a<sub>t</sub></var>.</li> <li><var>getSum(s, t)</var>: report the sum of <var>a<sub>s</sub></var>, <var>a<sub>s+1</sub></var>, ..., <var>a<sub>t</sub></var>.</li> </ul> <p> Note that the initial values of <var>a<sub>i</sub></var> (<var>i = 1, 2, . . . , n</var>) are 0. </p> <H2>Input</H2> <pre> <var>n</var> <var>q</var> <var>query<sub>1</sub></var> <var>query<sub>2</sub></var> : <var>query<sub>q</sub></var> </pre> <p> In the first line, <var>n</var> (the number of elements in <var>A</var>) and <var>q</var> (the number of queries) are given. Then, <i>i</i>th query <var>query<sub>i</sub></var> is given in the following format: </p> <pre> 0 <var>s</var> <var>t</var> <var>x</var> </pre> <p> or </p> <pre> 1 <var>s</var> <var>t</var> </pre> <p> The first digit represents the type of the query. '0' denotes <var>add(s, t, x)</var> and '1' denotes <var>getSum(s, t)</var>. </p> <H2>Output</H2> <p> For each <var>getSum</var> operation, print the sum; </p> <H2>Constraints</H2> <ul> <li> <var>1 &le; n &le; 100000</var> </li> <li> <var>1 &le; q &le; 100000</var> </li> <li> <var>1 &le; s &le; t &le; n</var> </li> <li> <var>0 &le; x &lt; 1000</var> </li> </ul> <H2>Sample Input 1</H2> <pre> 3 5 0 1 2 1 0 2 3 2 0 3 3 3 1 1 2 1 2 3 </pre> <H2>Sample Output 1</H2> <pre> 4 8 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 3 1 1 4 0 1 4 1 1 1 4 </pre> <H2>Sample Output 2</H2> <pre> 0 4 </pre>
p03813
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than <var>1200</var>, and participate in AtCoder Regular Contest (ARC) otherwise.</p> <p>You are given Smeke's current rating, <var>x</var>. Print <code>ABC</code> if Smeke will participate in ABC, and print <code>ARC</code> otherwise.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ x ≩ 3{,}000</var></li> <li><var>x</var> is an integer.</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>x</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>1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>ABC </pre> <p>Smeke's current rating is less than <var>1200</var>, thus the output should be <code>ABC</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>ARC </pre> <p>Smeke's current rating is not less than <var>1200</var>, thus the output should be <code>ARC</code>.</p></section> </div> </span>
p02701
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You drew lottery <var>N</var> times. In the <var>i</var>-th draw, you got an item of the kind represented by a string <var>S_i</var>.</p> <p>How many kinds of items did you get?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2\times 10^5</var></li> <li><var>S_i</var> consists of lowercase English letters and has a length between <var>1</var> and <var>10</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S_1</var> <var>:</var> <var>S_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of kinds of items you got.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 apple orange apple </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>You got two kinds of items: <code>apple</code> and <code>orange</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 grape grape grape grape grape </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>4 aaaa a aaa aa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p04006
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in <var>N</var> colors. Those colors are conveniently numbered <var>1</var> through <var>N</var>. Snuke currently has no slime. His objective is to have slimes of all the colors together.</p> <p>Snuke can perform the following two actions:</p> <ul> <li> <p>Select a color <var>i</var> (<var>1≀i≀N</var>), such that he does not currently have a slime in color <var>i</var>, and catch a slime in color <var>i</var>. This action takes him <var>a_i</var> seconds.</p> </li> <li> <p>Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color <var>i</var> (<var>1≀i≀N-1</var>) will become color <var>i+1</var>, and the color of a slime in color <var>N</var> will become color <var>1</var>. This action takes him <var>x</var> seconds.</p> </li> </ul> <p>Find the minimum time that Snuke needs to have slimes in all <var>N</var> colors.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N≀2,000</var></li> <li><var>a_i</var> are integers.</li> <li><var>1≀a_i≀10^9</var></li> <li><var>x</var> is an integer.</li> <li><var>1≀x≀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>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>Find the minimum time that Snuke needs to have slimes in all <var>N</var> colors.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 10 1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 </pre> <p>Snuke can act as follows:</p> <ul> <li>Catch a slime in color <var>1</var>. This takes <var>1</var> second.</li> <li>Cast the spell. The color of the slime changes: <var>1</var> → <var>2</var>. This takes <var>10</var> seconds.</li> <li>Catch a slime in color <var>1</var>. This takes <var>1</var> second.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 10 100 1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>23 </pre> <p>Snuke can act as follows:</p> <ul> <li>Catch a slime in color <var>2</var>. This takes <var>1</var> second.</li> <li>Cast the spell. The color of the slime changes: <var>2</var> → <var>3</var>. This takes <var>10</var> seconds.</li> <li>Catch a slime in color <var>2</var>. This takes <var>1</var> second.</li> <li>Cast the soell. The color of each slime changes: <var>3</var> → <var>1</var>, <var>2</var> → <var>3</var>. This takes <var>10</var> seconds.</li> <li>Catch a slime in color <var>2</var>. This takes <var>1</var> second.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 10 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>10 </pre> <p>Snuke can act as follows:</p> <ul> <li>Catch a slime in color <var>1</var>. This takes <var>1</var> second.</li> <li>Catch a slime in color <var>2</var>. This takes <var>2</var> seconds.</li> <li>Catch a slime in color <var>3</var>. This takes <var>3</var> seconds.</li> <li>Catch a slime in color <var>4</var>. This takes <var>4</var> seconds.</li> </ul></section> </div> </span>
p03239
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>When Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.</p> <p>You, the smartwatch, has found <var>N</var> routes to his home.</p> <p>If Mr. X uses the <var>i</var>-th of these routes, he will get home in time <var>t_i</var> at cost <var>c_i</var>.</p> <p>Find the smallest cost of a route that takes not longer than time <var>T</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 100</var></li> <li><var>1 \leq T \leq 1000</var></li> <li><var>1 \leq c_i \leq 1000</var></li> <li><var>1 \leq t_i \leq 1000</var></li> <li>The pairs <var>(c_i, t_i)</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>N</var> <var>T</var> <var>c_1</var> <var>t_1</var> <var>c_2</var> <var>t_2</var> <var>:</var> <var>c_N</var> <var>t_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the smallest cost of a route that takes not longer than time <var>T</var>.</p> <p>If there is no route that takes not longer than time <var>T</var>, print <code>TLE</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 70 7 60 1 80 4 50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <ul> <li>The first route gets him home at cost <var>7</var>.</li> <li>The second route takes longer than time <var>T = 70</var>.</li> <li>The third route gets him home at cost <var>4</var>.</li> </ul> <p>Thus, the cost <var>4</var> of the third route is the minimum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 1 1000 2 4 3 1000 4 500 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>TLE </pre> <p>There is no route that takes not longer than time <var>T = 3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 9 25 8 5 9 4 10 1000 1000 6 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre></section> </div> </span>
p01204
<H1><font color="#000">Problem C:</font> Save the Energy</H1> <p> You were caught in a magical trap and transferred to a strange field due to its cause. This field is three- dimensional and has many straight paths of infinite length. With your special ability, you found where you can exit the field, but moving there is not so easy. You can move along the paths easily without your energy, but you need to spend your energy when moving outside the paths. One unit of energy is required per distance unit. As you want to save your energy, you have decided to find the best route to the exit with the assistance of your computer. </p> <p> Your task is to write a program that computes the minimum amount of energy required to move between the given source and destination. The width of each path is small enough to be negligible, and so is your size. </p> <H2>Input</H2> <p> The input consists of multiple data sets. Each data set has the following format:</p> <pre> <i>N</i> <i>x<sub>s</sub> y<sub>s</sub> z<sub>s</sub> x<sub>t</sub> y<sub>t</sub> z<sub>t</sub></i> <i>x</i><sub>1,1</sub> <i>y</i><sub>1,1</sub> <i>z</i><sub>1,1</sub> <i>x</i><sub>1,2</sub> <i>y</i><sub>1,2</sub> <i>z</i><sub>1,2</sub> . . . <i>x</i><sub><i>N</i>,1</sub> <i>y</i><sub><i>N</i>,1</sub> <i>z</i><sub><i>N</i>,1</sub> <i>x</i><sub><i>N</i>,2</sub> <i>y</i><sub><i>N</i>,2</sub> <i>z</i><sub><i>N</i>,2</sub> </pre> <p> <i>N</i> is an integer that indicates the number of the straight paths (2 &le; <i>N</i> &le; 100). (<i>x<sub>s</sub></i>, <i>y<sub>s</sub></i>, <i>z<sub>s</sub></i>) and (<i>x<sub>t</sub></i>, <i>y<sub>t</sub></i>, <i>z<sub>t</sub></i>) denote the coordinates of the source and the destination respectively. (<i>x</i><sub><i>i</i>,1</sub>, <i>y</i><sub><i>i</i>,1</sub>, <i>z</i><sub><i>i</i>,1</sub>) and (<i>x</i><sub><i>i</i>,2</sub>, <i>y</i><sub><i>i</i>,2</sub>, <i>z</i><sub><i>i</i>,2</sub>) denote the coordinates of the two points that the <i>i</i>-th straight path passes. All coordinates do not exceed 30,000 in their absolute values. </p> <p> The distance units between two points (<i>x<sub>u</sub></i>, <i>y<sub>u</sub></i>, <i>z<sub>u</sub></i>) and (<i>x<sub>v</sub></i>, <i>y<sub>v</sub></i>, <i>z<sub>v</sub></i>) is given by the Euclidean distance as follows: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_saveTheEnergy"> </center> <p> It is guaranteed that the source and the destination both lie on paths. Also, each data set contains no straight paths that are almost but not actually parallel, although may contain some straight paths that are strictly parallel. </p> <p> The end of input is indicated by a line with a single zero. This is not part of any data set. </p> <H2>Output</H2> <p> For each data set, print the required energy on a line. Each value may be printed with an arbitrary number of decimal digits, but should not contain the error greater than 0.001. </p> <H2>Sample Input</H2> <pre> 2 0 0 0 0 2 0 0 0 1 0 0 -1 2 0 0 0 2 0 3 0 5 0 3 1 4 0 1 0 0 -1 0 1 0 1 -1 0 1 3 1 -1 3 1 1 2 0 0 0 3 0 0 0 0 0 0 1 0 3 0 0 3 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1.414 2.000 3.000 </pre>
p03393
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible <strong>diverse</strong> words in lexicographical order.</p> <p>A word is called <strong>diverse</strong> if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, <code>atcoder</code>, <code>zscoder</code> and <code>agc</code> are diverse words while <code>gotou</code> and <code>connect</code> aren't diverse words.</p> <p>Given a diverse word <var>S</var>, determine the next word that appears after <var>S</var> in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than <var>S</var>, or determine that it doesn't exist.</p> <p>Let <var>X = x_{1}x_{2}...x_{n}</var> and <var>Y = y_{1}y_{2}...y_{m}</var> be two distinct strings. <var>X</var> is lexicographically larger than <var>Y</var> if and only if <var>Y</var> is a prefix of <var>X</var> or <var>x_{j} &gt; y_{j}</var> where <var>j</var> is the smallest integer such that <var>x_{j} \neq y_{j}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 26</var></li> <li><var>S</var> is a diverse word.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the next word that appears after <var>S</var> in the dictionary, or <code>-1</code> if it doesn't exist.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>atcoder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>atcoderb </pre> <p><code>atcoderb</code> is the lexicographically smallest diverse word that is lexicographically larger than <code>atcoder</code>. Note that <code>atcoderb</code> is lexicographically smaller than <code>b</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>abc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>abcd </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>zyxwvutsrqponmlkjihgfedcba </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre> <p>This is the lexicographically largest diverse word, so the answer is <code>-1</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>abcdefghijklmnopqrstuvwzyx </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>abcdefghijklmnopqrstuvx </pre></section> </div> </span>
p03669
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> irregular jigsaw pieces. Each piece is composed of three rectangular parts of width <var>1</var> and various heights joined together. More specifically:</p> <ul> <li>The <var>i</var>-th piece is a part of height <var>H</var>, with another part of height <var>A_i</var> joined to the left, and yet another part of height <var>B_i</var> joined to the right, as shown below. Here, the bottom sides of the left and right parts are respectively at <var>C_i</var> and <var>D_i</var> units length above the bottom side of the center part.</li> </ul> <p><img alt="" src="https://atcoder.jp/img/agc017/2b6cd7f4500d3621bc18de407f167522.png"/></p> <p>Snuke is arranging these pieces on a square table of side <var>10^{100}</var>. Here, the following conditions must be held:</p> <ul> <li>All pieces must be put on the table.</li> <li>The entire bottom side of the center part of each piece must touch the front side of the table.</li> <li>The entire bottom side of the non-center parts of each piece must either touch the front side of the table, or touch the top side of a part of some other piece.</li> <li>The pieces must not be rotated or flipped.</li> </ul> <p>Determine whether such an arrangement is possible.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100000</var></li> <li><var>1 \leq H \leq 200</var></li> <li><var>1 \leq A_i \leq H</var></li> <li><var>1 \leq B_i \leq H</var></li> <li><var>0 \leq C_i \leq H - A_i</var></li> <li><var>0 \leq D_i \leq H - B_i</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>H</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>D_1</var> <var>A_2</var> <var>B_2</var> <var>C_2</var> <var>D_2</var> : <var>A_N</var> <var>B_N</var> <var>C_N</var> <var>D_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to arrange the pieces under the conditions, print <code>YES</code>; if it is impossible, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 1 1 0 0 2 2 0 1 3 3 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>The figure below shows a possible arrangement.</p> <p><img alt="" src="https://atcoder.jp/img/agc017/27db184b6924d4cec5077a54b505706a.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 4 1 1 0 3 2 3 2 0 1 2 3 0 2 1 0 0 3 2 0 2 1 1 3 0 3 2 0 0 1 3 2 0 1 1 1 3 2 3 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre></section> </div> </span>
p01654
<h2>Problem Statement</h2> <p> Chelsea is a modern artist. She decided to make her next work with ladders. She wants to combine some ladders and paint some beautiful pattern. </p> <p> A ladder can be considered as a graph called <i>hashigo</i>. There are <var>n</var> <i>hashigos</i> numbered from 0 to <var>n-1</var>. <i>Hashigo</i> <var>i</var> of length <var>l_i</var> has <var>2 l_{i} + 6</var> vertices <var>v_{i, 0}, v_{i, 1}, ..., v_{i, 2 l_{i} + 5}</var> and has edges between the pair of vertices <var>(v_{i, j}, v_{i, j+2})</var> (<var>0 \leq j \leq 2 l_i +3</var>) and <var>(v_{i, 2j}, v_{i, 2j+1})</var> (<var>1 \leq j \leq l_i+1</var>). The figure below is example of a <i>hashigo</i> of length 2. This corresponds to the graph given in the first dataset in the sample input. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_hashigoSama1" height="113" width="349"><br/> <br/> </center> <p> Two <i>hashigos</i> <var>i</var> and <var>j</var> are combined at position <var>p</var> (<var>0 \leq p \leq l_{i}-1</var>) and <var>q</var> (<var>0 \leq q \leq l_{j}-1</var>) by marged each pair of vertices <var>(v_{i, 2p+2}, v_{j, 2q+2})</var>, <var>(v_{i, 2p+3}, v_{j, 2q+4})</var>, <var>(v_{i, 2p+4}, v_{j, 2q+3})</var> and <var>(v_{i, 2p+5}, v_{j, 2q+5})</var>. </p> <p> Chelsea performs this operation <var>n-1</var> times to combine the <var>n</var> <i>hashigos</i>. After this operation, the graph should be connected and the maximum degree of the graph should not exceed 4. The figure below is a example of the graph obtained by combining three <i>hashigos</i>. This corresponds to the graph given in the second dataset in the sample input. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_hashigoSama2" height="325" width="429"><br/> <br/> </center> <p> Now she decided to paint each vertex by black or white with satisfying the following condition: </p> <ul> <li> The maximum components formed by the connected vertices painted by the same color is less than or equals to <var>k</var>. </li> </ul> <p> She would like to try all the patterns and choose the best. However, the number of painting way can be very huge. Since she is not good at math nor computing, she cannot calculate the number. So please help her with your superb programming skill! </p> <h2>Input</h2> <p> The input contains several datasets, and each dataset is in the following format. </p> <pre> <var>n</var> <var>k</var> <var>l_0</var> <var>l_1</var> ... <var>l_{n-1}</var> <var>f_0</var> <var>p_0</var> <var>t_0</var> <var>q_0</var> ... <var>f_{n-2}</var> <var>p_{n-2}</var> <var>t_{n-2}</var> <var>q_{n-2}</var> </pre> <p> The first line contains two integers <var>n</var> (<var>1 \leq n \leq 30</var>) and <var>k</var> (<var>1 \leq k \leq 8</var>). </p> <p> The next line contains <var>n</var> integers <var>l_i</var> (<var>1 \leq l_i \leq 30</var>), each denotes the length of <i>hashigo</i> <var>i</var>. </p> <p> The following <var>n-1</var> lines each contains four integers <var>f_i</var> (<var>0 \leq f_i \leq n-1</var>), <var>p_i</var> (<var>0 \leq p_i \leq l_{f_i}-1</var>), <var>t_i</var> (<var>0 \leq t_i \leq n-1</var>), <var>q_i</var> (<var>0 \leq q_i \leq l_{t_i}-1</var>). It represents the <i>hashigo</i> <var>f_i</var> and the <i>hashigo</i> <var>t_i</var> are combined at the position <var>p_i</var> and the position <var>q_i</var>. You may assume that the graph obtained by combining <var>n</var> <i>hashigos</i> is connected and the degree of each vertex of the graph does not exceed 4. </p> <p> The last dataset is followed by a line containing two zeros. </p> <h2>Output</h2> <p> For each dataset, print the number of different colorings modulo 1,000,000,007 in a line. </p> <h2>Sample Input</h2> <pre> 1 5 2 3 7 2 3 1 0 1 1 0 1 2 2 0 2 8 5 6 0 2 1 2 2 8 1 1 0 0 1 0 2 2 2 2 0 1 1 0 2 3 3 3 0 2 1 1 2 4 3 1 1 0 0 1 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 708 1900484 438404500 3878 496 14246 9768 </pre>
p00946
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem A Rearranging a Sequence </h2> <p> You are given an ordered sequence of integers, ($1, 2, 3, ..., n$). Then, a number of requests will be given. Each request specifies an integer in the sequence. You need to move the specified integer to the head of the sequence, leaving the order of the rest untouched. Your task is to find the order of the elements in the sequence after following all the requests successively. </p> <h3>Input</h3> <p> The input consists of a single test case of the following form.<br/> <br/> $n$ $m$<br/> $e_1$<br/> ...<br/> $e_m$<br/> </p> <p> The integer $n$ is the length of the sequence ($1 \leq n \leq 200000$). The integer $m$ is the number of requests ($1 \leq m \leq 100000$). The following $m$ lines are the requests, namely $e_1, ..., e_m$, one per line. Each request $e_i$ ($1 \leq i \leq m$) is an integer between 1 and $n$, inclusive, designating the element to move. Note that, the integers designate the integers themselves to move, not their positions in the sequence. </p> <h3>Output</h3> <p> Output the sequence after processing all the requests. Its elements are to be output, one per line, in the order in the sequence. </p> <h3>Sample Input 1</h3> <pre>5 3 4 2 5</pre> <h3>Sample Output 1</h3> <pre>5 2 4 1 3</pre> <br/> <h3>Sample Input 2</h3> <pre>10 8 1 4 7 3 4 10 1 3</pre> <h3>Sample Output 2</h3> <pre>3 1 10 4 7 2 5 6 8 9</pre> <p> In Sample Input 1, the initial sequence is (1, 2, 3, 4, 5). The first request is to move the integer 4 to the head, that is, to change the sequence to (4, 1, 2, 3, 5). The next request to move the integer 2 to the head makes the sequence (2, 4, 1, 3, 5). Finally, 5 is moved to the head, resulting in (5, 2, 4, 1, 3). </p>
p00415
<h1>デゞット</h1>   <p> アむヅ赀べこ店では、デゞットず呌ばれるナニヌクな「くじ」を販売しおいたす。各くじには、巊から右ぞ向かっお1列に$N$個の数字が䞊んでいたす。ただし、曞かれおいるのはからたでの数字です。 </p> <p> くじの賌入者は、これらの数字から$K$個の数字を消去し、残った$N-K$個の数字を巊から順番に䞊べおできる数をポむントずしお獲埗するこずができたす。たずえば$K=3$のずき、くじに$1414213$ず曞かれおいれば、巊から$1$、$1$、$2$を遞択しお消去するこずで$4413$ポむントを獲埗するこずができたす。 </p> <p> 数字の列ず敎数$K$が䞎えられたずき、獲埗できるポむントの最倧倀を出力するプログラムを䜜成せよ。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $N$ $K$ $a_1$ $a_2$ ... $a_N$ </pre> <p> 行目に数字の数$N$ ($1 \leq N \leq 200,000$)ず敎数$K$ ($0 \leq K < N$)が䞎えられる。行目にくじに曞かれおいる$N$個の数$a_i$ ($1 \leq a_i \leq 9$)が䞎えられる。 </p> <h2>出力</h2> <p> ポむントの最倧倀を行に出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 7 3 1 4 1 4 2 1 3 </pre> <h3>出力䟋</h3> <pre> 4423 </pre> <h3>入力䟋</h3> <pre> 4 1 1 1 9 9 </pre> <h3>出力䟋</h3> <pre> 199 </pre>
p02428
<h1>Enumeration of Subsets II</h1> <p> You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$. Print all sets, each of which is a subset of $U$ and includes $T$ as a subset. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $k \; b_0 \; b_1 \; ... \; b_{k-1}$ </pre> <p> $k$ is the number of elements in $T$, and $b_i$ represents elements in $T$. </p> <h2>Output</h2> <p> Print the subsets ordered by their decimal integers. Print a subset in the following format. </p> <pre> $d$: $e_0$ $e_1$ ... </pre> <p> Print '<span>:</span>' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 18$</li> <li>$0 \leq k \leq n$</li> <li>$0 \leq b_i < n$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 2 0 2 </pre> <h2>Sample Output 1</h2> <pre> 5: 0 2 7: 0 1 2 13: 0 2 3 15: 0 1 2 3 </pre>
p02582
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have weather records at AtCoder Town for some consecutive three days. A string of length <var>3</var>, <var>S</var>, represents the records - if the <var>i</var>-th character is <code>S</code>, it means it was sunny on the <var>i</var>-th day; if that character is <code>R</code>, it means it was rainy on that day.</p> <p>Find the maximum number of consecutive rainy days in this period.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>|S| = 3</var></li> <li>Each character of <var>S</var> is <code>S</code> or <code>R</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of consecutive rainy days in the period.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>RRS </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>We had rain on the <var>1</var>-st and <var>2</var>-nd days in the period. Here, the maximum number of consecutive rainy days is <var>2</var>, so we should print <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>SSS </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>It was sunny throughout the period. We had no rainy days, so we should print <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>RSR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p>We had rain on the <var>1</var>-st and <var>3</var>-rd days - two "streaks" of one rainy day, so we should print <var>1</var>.</p></section> </div> </span>
p00045
<H1>Sum and Average</H1> <p> 販売単䟡ず販売数量を読み蟌んで、販売金額の総合蚈ず販売数量の平均を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> 販売単䟡,販売数量 販売単䟡,販売数量 : : </pre> <p> カンマで区切られた販売単䟡ず販売数量の組が、耇数行に枡っお䞎えられたす。入力される倀はすべお 0 以䞊 1,000 以䞋で、販売単䟡ず販売数量の組の数は 100 を超えたせん。 </p> <H2>Output</H2> <p> 行目に販売金額の総合蚈敎数、行目に販売数量の平均(敎数を出力しおください。 販売数量の平均に端数小数点以䞋の数が生じた堎合は小数点以䞋第 1 䜍を四捚五入しおください。 </p> <H2>Sample Input</H2> <pre> 100,20 50,10 70,35 </pre> <H2>Output for the Sample Input</H2> <pre> 4950 22 </pre>
p02078
<h1>A: Undo Swapping</h1> <h2>問題文</h2> <p>$N$ 行 $N$ 列のマス目の䞊に $N$ 個の石が眮いおありたす。 $i$ 番目の石は $R_i$ 行 $C_i$ 列にありたす。同じマスに耇数の石が眮かれおいるこずはありたせん。</p> <p>あなたは次の2皮類の操䜜を任意の順で任意の回数行うこずができたす。</p> <ol> <li>2぀の行を遞び、それらを亀換する</li> <li>2぀の列を遞び、それらを亀換する。</li> </ol> <p>$N$ 個の石を、マス目の巊䞊から右䞋にかけおの察角線䞊に䞊べるこずが出来るかを刀定するプログラムを䜜成しおください。 可胜な堎合は必芁な最小の操䜜回数を出力しおください。䞍可胜な堎合は $-1$ を出力しおください。</p> <p>ただし、<strong>察角線䞊に䞊ぶ石の順番は関係無い</strong> こずに泚意しおください。 䟋えば、1番目の石を1行1列のマスに配眮する必芁はありたせん。</p> <h2>制玄</h2> <ul> <li>入力は党お敎数</li> <li>$1 \leq N \leq 10^5$</li> <li>$1 \leq R_i, C_i \leq N$ $(1 \leq i \leq N)$</li> <li>$R_i \ne R_j$ たたは $C_i \ne C_j$ $(i \ne j)$</li> </ul> <h2>入力</h2> <p>入力は暙準入力から以䞋の圢匏で䞎えられたす。</p> <pre> $N$ $R_1$ $C_1$ $R_2$ $C_2$ $\vdots$ $R_N$ $C_N$</pre> <h2>出力</h2> <p>問題文䞭の条件を満たせる堎合は、必芁な最小の操䜜回数を䞀行に出力しおください。 䞍可胜である堎合、$-1$ を䞀行に出力しおください。</p> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre>3 2 1 3 2 1 3 </pre> <h3>出力䟋1</h3> <pre>2 </pre> <p>初めに列1ず列3を入れ替え、次に行2ず行3を入れ替えるこずで達成できたす。 1回の操䜜で条件を満たすこずは出来ないため、答えは2ずなりたす。</p> <h3>入力䟋2</h3> <pre>3 1 1 1 2 3 3 </pre> <h3>出力䟋2</h3> <pre>-1 </pre> <h3>入力䟋3</h3> <pre>3 1 1 2 2 3 3 </pre> <h3>出力䟋3</h3> <pre>0 </pre> <h3>入力䟋4</h3> <pre>5 4 1 3 5 5 4 1 2 2 3 </pre> <h3>出力䟋4</h3> <pre>4 </pre>
p00550
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h2>鉄道運賃(Train Fare)</h2> <p> JOI 囜には $N$ 個の郜垂がありそれぞれ $1, 2, ..., N$ の番号が付けられおいる郜垂 1 はJOI 囜の銖郜である </p> <p> たたJOI 囜には鉄道䌚瀟がひず぀だけありこの䌚瀟は $M$ 個の路線を運行しおいるこれらの路線にはそれぞれ $1, 2, ..., M$ の番号が付けられおおり$i$ 番目 $(1 \leq i \leq M)$ の路線は郜垂 $U_i$ ず郜垂 $V_i$ を双方向に結んでいる郜垂ず郜垂の間を鉄道以倖で移動するこずはできないたたどの郜垂からどの郜垂ぞもいく぀かの路線を乗り継いで移動するこずができるようになっおいる </p> <p> 珟圚どの路線の運賃も 1 円である経営䞍振に陥った鉄道䌚瀟は今埌 $Q$ 幎間かけおいく぀かの路線の運賃を倀䞊げする蚈画を立おたこの蚈画では蚈画開始から $j$ 幎目$(1 \leq j \leq Q)$ の幎初めに路線 $R_j$ の運賃を 1 円から 2 円に倀䞊げする予定である倀䞊げされた路線の運賃はその埌ずっず2 円のたたであり再び倀䞊げするこずはない </p> <p> ずころでこの鉄道䌚瀟では毎幎各郜垂の䜏民の満足床調査を行っおいる蚈画開始前はどの郜垂の䜏民もこの鉄道䌚瀟に満足しおいるが倀䞊げによっお䞍満を持぀䜏民が珟れる可胜性がある </p> <p> それぞれの幎の満足床調査はその幎の倀䞊げの実斜埌に行うしたがっお $j$ 幎目$(1 \leq j \leq Q)$ の満足床調査は路線 $R_1, R_2, ... , R_j$ の運賃の倀䞊げは完了しそれ以倖の路線の運賃は倀䞊げされおいない状態で行われるこずになる $j$ 幎目$(1 \leq j \leq Q)$ の満足床調査では郜垂 $k$ $(2 \leq k \leq N)$ の䜏民は以䞋の条件が満たされるずきそしおそのずきに限り鉄道䌚瀟に䞍満を抱く </p> <ul> <li> その時の運賃で郜垂 $k$ から銖郜である郜垂 $1$ ぞ移動するずきの費甚の最小倀が蚈画開始前の運賃で郜垂 $k$ から郜垂 $1$ ぞ移動するずきの費甚の最小倀よりも倧きい </li> </ul> <p> ただしいく぀かの路線を䜿っお移動するずきの費甚はそれぞれの路線の運賃の合蚈であるたた郜垂 $1$ の䜏民が鉄道䌚瀟に察しお䞍満を抱くこずはない倀䞊げ埌の運賃で最小の費甚を達成する経路は蚈画開始前の運賃で最小の費甚を達成する経路ず異なる可胜性があるこずに泚意せよ </p> <p> 蚈画の実行に先立っお今埌 $Q$ 幎間の䜏民の満足床調査それぞれにおいお鉄道䌚瀟に䞍満を抱く䜏民がいる郜垂の数を蚈算しおおきたい </p> <h2>課題</h2> <p> JOI 囜の鉄道路線の情報ず運賃の倀䞊げ蚈画が䞎えられたずきそれぞれの満足床調査においお鉄道䌚瀟に䞍満を抱く䜏民がいる郜垂の数を求めるプログラムを䜜成せよ </p> <h2>入力</h2> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には3 個の敎数 $N, M, Q$ が空癜を区切りずしお曞かれおいるこれらはJOI 囜には $N$ 個の郜垂ず $M$ 個の路線があり運賃の倀䞊げ蚈画が $Q$ 幎間に枡るこずを衚しおいる</li> <li> 続く $M$ 行のうちの $i$ 行目$(1 \leq i \leq M)$ には2 個の敎数 $U_i$, $V_i$ が空癜を区切りずしお曞かれおいるこれらは$i$ 番目の路線が郜垂 $U_i$ ず郜垂 $V_i$ を結んでいるこずを衚しおいる</li> <li> 続く $Q$ 行のうちの $j$ 行目$(1 \leq j \leq Q)$ には敎数 $R_j$ が曞かれおいるこれは蚈画の $j$ 幎目に路線 $R_j$ の運賃を倀䞊げするこずを衚しおいる</li> </ul> <h2>出力</h2> <p> 暙準出力に $Q$ 行で出力せよ $j$ 行目$(1 \leq j \leq Q)$ には $j$ 幎目の満足床調査で䞍満を抱く䜏民がいる郜垂の数を出力せよ </p> <h2>制限</h2> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li> $2 \leq N \leq 100 000$ </li> <li> $1 \leq Q \leq M \leq 200 000$ </li> <li> $1 \leq U_i \leq N$ $(1 \leq i \leq M)$ </li> <li> $1 \leq V_i \leq N$ $(1 \leq i \leq M)$ </li> <li> $U_i \ne V_i$ $(1 \leq i \leq M)$ </li> <li> $1 \leq R_j \leq M$ $(1 \leq j \leq Q)$ </li> <li> $R_j \ne R_k$ $(1 \leq j < k \leq Q)$ </li> <li> どの2 ぀の郜垂に぀いおもそれらを盎接結ぶ路線は 1 個以䞋である </li> <li> どの郜垂に぀いおもその郜垂から郜垂 1 たでいく぀かの路線を䜿っお移動するこずができる </li> </ul> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 5 6 5 1 2 1 3 4 2 3 2 2 5 5 3 5 2 4 1 3 </pre> <h3>出力䟋1</h3> <pre> 0 2 2 4 4 </pre> <p> この入力䟋では蚈画開始前及びそれぞれの満足床調査の時点でのそれぞれの郜垂から郜垂 $1$ ぞの運賃は以䞋の衚のようになる </p> <table> <tr><td>時点</td><td>郜垂2&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>郜垂3&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>郜垂4&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>郜垂5&nbsp;&nbsp;&nbsp;&nbsp;</td></tr> <tr><td>蚈画開始前 &nbsp;&nbsp;&nbsp;&nbsp;</td><td>1</td> <td>1</td><td> 2</td><td> 2</td></tr> <tr><td>1 幎目</td><td>1</td><td> 1</td><td> 2</td><td> 2</td></tr> <tr><td>2 幎目</td><td>1</td><td> 2</td><td> 2</td><td> 3</td></tr> <tr><td>3 幎目</td><td>1 </td><td>2 </td><td>2 </td><td>3</td></tr> <tr><td>4 幎目</td><td>2 </td><td>2 </td><td>3 </td><td>3</td></tr> <tr><td>5 幎目</td><td>2 </td><td>2 </td><td>4 </td><td>3</td></tr> </table> <br> <p> 䟋えば3 幎目の満足床調査では郜垂 $3$ ず郜垂 $5$ の䜏民が䞍満を抱くので出力の 3 行目には 2 を出力する </p> <h3>入力䟋2</h3> <pre> 4 6 6 1 2 1 3 1 4 2 3 2 4 3 4 1 4 2 5 3 6 </pre> <h3>出力䟋2</h3> <pre> 1 1 2 2 3 3 </pre> <h3>入力䟋3</h3> <pre> 2 1 1 1 2 1 </pre> <h3>出力䟋3</h3> <pre> 1 </pre> <div class="source"> <p class="source"> <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> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf">第15回 日本情報オリンピック本遞 課題 &nbsp; 2016 幎 2 月 14 日</a> </p> </div>
p02097
<h2>J: Horizontal-Vertical Permutation</h2> <h3>Problem Statement</h3> <p>You are given a positive integer <var>N</var>. Your task is to determine if there exists a square matrix <var>A</var> whose dimension is <var>N</var> that satisfies the following conditions and provide an example of such matrices if it exists. <var>A_{i, j}</var> denotes the element of matrix <var>A</var> at the <var>i</var>-th row and <var>j</var>-th column.</p> <ul> <li> For all <var>i, j</var> <var>(1 \leq i, j \leq N)</var>, <var>A_{i, j}</var> is an integer that satisfies <var>1 \leq A_{i, j} \leq 2N - 1</var>.</li> <li> For all <var>k = 1, 2, ..., N</var>, a set consists of <var>2N - 1</var> elements from the <var>k</var>-th row or <var>k</var>-th column is <var>\{1, 2, ..., 2N - 1\}</var>.</li> </ul> <p>If there are more than one possible matrices, output any of them.</p> <h3>Input</h3> <pre><var>N</var></pre> <p>Input consists of one line, which contains the integer <var>N</var> that is the size of a square matrix to construct.</p> <h3>Constraint</h3> <ul> <li> <var>N</var> is an integer that satisfies <var>1 \leq N \leq 500</var>.</li> </ul> <h3>Output</h3> <p>Output <code>No</code> in a single line if such a square matrix does not exist.</p> <p>If such a square matrix <var>A</var> exists, output <code>Yes</code> on the first line and <var>A</var> after that. More specifically, follow the following format.</p> <pre> Yes <var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var> <var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var> <var>:</var> <var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var> </pre> <h3>Sample Input 1</h3> <pre>4</pre> <h3>Output for Sample Input 1</h3> <pre> Yes 2 6 3 7 4 5 2 1 1 7 5 6 5 3 4 2 </pre> <h3>Sample Input 2</h3> <pre>3</pre> <h3>Output for Sample Input 2</h3> <pre>No</pre>
p00100
<H1>Sale Result</H1> <p> There is data on sales of your company. Your task is to write a program which identifies good workers. </p> <p> The program should read a list of data where each item includes the employee ID <i>i</i>, the amount of sales <i>q</i> and the corresponding unit price <i>p</i>. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p &times; q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that <i>n</i> &lt; 4000, and each employee has an unique ID. The unit price <i>p</i> is less than or equal to 1,000,000 and the amount of sales <i>q</i> is less than or equal to 100,000. </p> <H2>Input</H2> <p> The input consists of several datasets. The input ends with a line including a single 0. Each dataset consists of: </p> <pre class="exp"> <i>n</i> (the number of data in the list) <i>i</i> <i>p</i> <i>q</i> <i>i</i> <i>p</i> <i>q</i> : : <i>i</i> <i>p</i> <i>q</i> </pre> <H2>Output</H2> <p> For each dataset, print a list of employee IDs or a text "NA" </p> <H2>Sample Input</H2> <pre> 4 1001 2000 520 1002 1800 450 1003 1600 625 1001 200 1220 2 1001 100 3 1005 1000 100 2 2013 5000 100 2013 5000 100 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1001 1003 NA 2013 </pre>
p01341
<H1><font color="#000">Problem C: </font> Save your cats</H1> <p> Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them. </p> <p> One day, an evil witch visited the village. She envied the cats for being loved by everyone. She drove magical piles in his garden and enclosed the cats with magical fences running between the piles. She said “Your cats are shut away in the fences until they become ugly old cats.” like a curse and went away. </p> <p> Nicholas tried to break the fences with a hummer, but the fences are impregnable against his effort. He went to a church and asked a priest help. The priest looked for how to destroy the magical fences in books and found they could be destroyed by holy water. The Required amount of the holy water to destroy a fence was proportional to the length of the fence. The holy water was, however, fairly expensive. So he decided to buy exactly the minimum amount of the holy water required to save all his cats. How much holy water would be required? </p> <H2>Input</H2> <p> The input has the following format: </p> <p> <i>N M</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub></br> .<br> .<br> .<br> <i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub></br> <i>p</i><sub>1</sub> <i>q</i><sub>1</sub><br> .<br> .<br> .<br> <i>p</i><sub><i>M</i></sub> <i>q</i><sub><i>M</i></sub><br> </p> <p> The first line of the input contains two integers <i>N</i> (2 &le; <i>N</i> &le; 10000) and <i>M</i> (1 &le; <i>M</i>). <i>N</i> indicates the number of magical piles and <i>M</i> indicates the number of magical fences. The following <i>N</i> lines describe the coordinates of the piles. Each line contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> (-10000 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> &le; 10000). The following <i>M</i> lines describe the both ends of the fences. Each line contains two integers <i>p<sub>j</sub></i> and <i>q<sub>j</sub></i> (1 &le; <i>p<sub>j</sub></i>, <i>q<sub>j</sub></i> &le; <i>N</i>). It indicates a fence runs between the <i>p<sub>j</sub></i>-th pile and the <i>q<sub>j</sub></i>-th pile. </p> <p> You can assume the following: </p> <ul> <li> No Piles have the same coordinates.</li> <li> A pile doesn’t lie on the middle of fence.</li> <li> No Fences cross each other.</li> <li> There is at least one cat in each enclosed area.</li> <li> It is impossible to destroy a fence partially.</li> <li> A unit of holy water is required to destroy a unit length of magical fence.</li> </ul> <H2>Output</H2> <p> Output a line containing the minimum amount of the holy water required to save all his cats. Your program may output an arbitrary number of digits after the decimal point. However, the absolute error should be 0.001 or less. </p> <H2>Sample Input 1</H2> <pre> 3 3 0 0 3 0 0 4 1 2 2 3 3 1 </pre> <H2>Output for the Sample Input 1</H2> <pre> 3.000 </pre> <H2>Sample Input 2</H2> <pre> 4 3 0 0 -100 0 100 0 0 100 1 2 1 3 1 4 </pre> <H2>Output for the Sample Input 2</H2> <pre> 0.000 </pre> <H2>Sample Input 3</H2> <pre> 6 7 2 0 6 0 8 2 6 3 0 5 1 7 1 2 2 3 3 4 4 1 5 1 5 4 5 6 </pre> <H2>Output for the Sample Input 3</H2> <pre> 7.236 </pre> <H2>Sample Input 4</H2> <pre> 6 6 0 0 0 1 1 0 30 0 0 40 30 40 1 2 2 3 3 1 4 5 5 6 6 4 </pre> <H2>Output for the Sample Input 4</H2> <pre> 31.000 </pre>
p03686
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>M</var> chairs arranged in a line. The coordinate of the <var>i</var>-th chair <var>(1 ≀ i ≀ M)</var> is <var>i</var>.</p> <p><var>N</var> people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the <var>i</var>-th person wishes to sit in a chair whose coordinate is not greater than <var>L_i</var>, or not less than <var>R_i</var>. Naturally, only one person can sit in the same chair.</p> <p>It may not be possible for all of them to sit in their favorite chairs, if nothing is done. Aoki, who cares for the health of the people of the Takahashi clan, decides to provide additional chairs so that all of them can sit in chairs at their favorite positions.</p> <p>Additional chairs can be placed at arbitrary real coordinates. Find the minimum required number of additional chairs.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N,M ≀ 2 × 10^5</var></li> <li><var>0 ≀ L_i &lt; R_i ≀ M + 1(1 ≀ i ≀ N)</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>L_1</var> <var>R_1</var> <var>:</var> <var>L_N</var> <var>R_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum required number of additional chairs.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 0 3 2 3 1 3 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> <p>The four people can sit in chairs at the coordinates <var>3</var>, <var>2</var>, <var>1</var> and <var>4</var>, respectively, and no more chair is needed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 6 0 7 1 5 3 6 2 7 1 6 2 6 3 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>If we place additional chairs at the coordinates <var>0</var> and <var>2.5</var>, the seven people can sit at coordinates <var>0</var>, <var>5</var>, <var>3</var>, <var>2</var>, <var>6</var>, <var>1</var> and <var>2.5</var>, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 1 1 2 1 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 6 1 6 1 6 1 5 1 5 2 6 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>2 </pre></section> </div> </span>
p02994
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have <var>N</var> apples, called Apple <var>1</var>, Apple <var>2</var>, Apple <var>3</var>, ..., Apple <var>N</var>. The <em>flavor</em> of Apple <var>i</var> is <var>L+i-1</var>, which can be negative.</p> <p>You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.</p> <p>You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.</p> <p>You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining <var>N-1</var> apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the <var>N</var> apples.</p> <p>Find the flavor of the apple pie made of the remaining <var>N-1</var> apples when you choose the apple to eat as above.</p> <p>We can prove that this value is uniquely determined.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200</var></li> <li><var>-100 \leq L \leq 100</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>L</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the flavor of the apple pie made of the remaining <var>N-1</var> apples when you optimally choose the apple to eat.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>18 </pre> <p>The flavors of Apple <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, and <var>5</var> are <var>2</var>, <var>3</var>, <var>4</var>, <var>5</var>, and <var>6</var>, respectively. The optimal choice is to eat Apple <var>1</var>, so the answer is <var>3+4+5+6=18</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>The flavors of Apple <var>1</var>, <var>2</var>, and <var>3</var> are <var>-1</var>, <var>0</var>, and <var>1</var>, respectively. The optimal choice is to eat Apple <var>2</var>, so the answer is <var>(-1)+1=0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>30 -50 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1044 </pre></section> </div> </span>
p01711
<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> <meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" /><style type="text/css">blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }</style><div class="part"><h3>Problem Statement</h3><p>Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.) </p> <p>"<samp>Filtering</samp>" is an operation to determine the color of a pixel from the colors of itself and its six neighbors. Examples of filterings are shown below. </p> <p>Example 1: Color a pixel in white when all of its neighboring pixels are white. Otherwise the color will not change. </p> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_NoiseCanceller" height="235" width="488" /> </p> <p>Performing this operation on all the pixels simultaneously results in "<samp>noise canceling,</samp>" which removes isolated black pixels. </p> <p>Example 2: Color a pixel in white when its all neighboring pixels are black. Otherwise the color will not change. </p> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_EdgeDetector" height="235" width="488" /> </p> <p>Performing this operation on all the pixels simultaneously results in "<samp>edge detection,</samp>" which leaves only the edges of filled areas. </p> <p>Example 3: Color a pixel with the color of the pixel just below it, ignoring any other neighbors. </p> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_MoveUp" height="487" width="489" /> </p> <p>Performing this operation on all the pixels simultaneously results in "<samp>shifting up</samp>" the whole image by one pixel. </p> <p>Applying some filter, such as "<samp>noise canceling</samp>" and "<samp>edge detection,</samp>" twice to any image yields the exactly same result as if they were applied only once. We call such filters <i>idempotent</i>. The "<samp>shifting up</samp>" filter is not idempotent since every repeated application shifts the image up by one pixel. </p> <p>Your task is to determine whether the given filter is idempotent or not. </p> </div><div class="part"><h3>Input</h3> <p>The input consists of multiple datasets. The number of dataset is less than $100$. Each dataset is a string representing a filter and has the following format (without spaces between digits). </p> <blockquote style="font-size:14pt"> $c_0c_1\cdots{}c_{127}$</blockquote> <p>$c_i$ is either '<samp>0</samp>' (represents black) or '<samp>1</samp>' (represents white), which indicates the output of the filter for a pixel when the binary representation of the pixel and its neighboring six pixels is $i$. The mapping from the pixels to the bits is as following: </p> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGAsia2014_Bit" height="235" width="226" /> </p> <p>and the binary representation $i$ is defined as $i = \sum_{j=0}^6{\mathit{bit}_j \times 2^j}$, where $\mathit{bit}_j$ is $0$ or $1$ if the corresponding pixel is in black or white, respectively. Note that the filter is applied on the center pixel, denoted as bit 3. </p> <p>The input ends with a line that contains only a single "<samp>#</samp>". </p> </div><div class="part"><h3>Output</h3> <p>For each dataset, print "<samp>yes</samp>" in a line if the given filter is idempotent, or "<samp>no</samp>" otherwise (quotes are for clarity). </p> </div><div class="part"><h3>Sample Input</h3> <pre>00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111 10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111 01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 #</pre> </div><div class="part"><h3>Output for the Sample Input</h3> <pre>yes yes no</pre> </div>
p00803
<H1><font color="#000">Problem A:</font> Starship Hakodate-maru</H1> <p> The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls. </p> <p> There, however, is an inconvenience. The shapes of the fuel containers <i>#</i>1 and <i>#</i>2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should be either empty or filled according to their shapes. Otherwise, the fuel balls become extremely unstable and may explode in the fuel containers. Thus, the number of fuel balls for the container <i>#</i>1 should be a cubic number (<i>n</i><sup>3</sup> for some <i>n</i> = 0, 1, 2, 3,... ) and that for the container <i>#</i>2 should be a tetrahedral number ( <i>n</i>(<i>n</i> + 1)(<i>n</i> + 2)/6 for some <i>n</i> = 0, 1, 2, 3,... ). </p> <p> Hakodate-maru is now at the star base Goryokaku preparing for the next mission to create a precise and detailed chart of stars and interstellar matters. Both of the fuel containers are now empty. Commander Parus of Goryokaku will soon send a message to Captain Future of Hakodate-maru on how many fuel balls Goryokaku can supply. Captain Future should quickly answer to Commander Parus on how many fuel balls she requests before her ship leaves Goryokaku. Of course, Captain Future and her omcers want as many fuel balls as possible. </p> <p> For example, consider the case Commander Parus offers 151200 fuel balls. If only the fuel container <i>#</i>1 were available (i.e. ifthe fuel container <i>#</i>2 were unavailable), at most 148877 fuel balls could be put into the fuel container since 148877 = 53 &times; 53 &times; 53 &lt; 151200 &lt; 54 &times; 54 &times; 54 . If only the fuel container <i>#</i>2 were available, at most 147440 fuel balls could be put into the fuel container since 147440 = 95 &times; 96 &times; 97/6 &lt; 151200 &lt; 96 &times; 97 &times; 98/6 . Using both of the fuel containers <i>#</i>1 and <i>#</i>2, 151200 fuel balls can be put into the fuel containers since 151200 = 39 &times; 39 &times; 39 + 81 &times; 82 &times; 83/6 . In this case, Captain Future's answer should be "151200". </p> <p> Commander Parus's offer cannot be greater than 151200 because of the capacity of the fuel storages of Goryokaku. Captain Future and her omcers know that well. </p> <p> You are a fuel engineer assigned to Hakodate-maru. Your duty today is to help Captain Future with calculating the number of fuel balls she should request. </p> <H2>Input</H2> <p> The input is a sequence of at most 1024 positive integers. Each line contains a single integer. The sequence is followed by a zero, which indicates the end of data and should not be treated as input. You may assume that none of the input integers is greater than 151200. </p> <H2>Output</H2> <p> The output is composed of lines, each containing a single integer. Each output integer should be the greatest integer that is the sum of a nonnegative cubic number and a nonnegative tetrahedral number and that is not greater than the corresponding input number. No other characters should appear in the output. </p> <H2>Sample Input</H2> <pre> 100 64 50 20 151200 0 </pre> <H2>Output for the Sample Input</H2> <pre> 99 64 47 20 151200 </pre>
p01506
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Digit</H1> <p> For a positive integer <var>a</var>, let <var>S(a)</var> be the sum of the digits in base <var>l</var>. Also let <var>L(a)</var> be the minimum <var>k</var> such that <var>S^k(a)</var> is less than or equal to <var>l-1</var>. Find the minimum <var>a</var> such that <var>L(a) = N</var> for a given <var>N</var>, and print <var>a</var> modulo <var>m</var>. </p> <H2>Input</H2> <p> The input contains several test cases, followed by a line containing &quot;0 0 0&quot;. Each test case is given by a line with three integers <var>N</var>, <var>m</var>, <var>l</var> (<var>0 \leq N \leq 10^5</var>, <var>1 \leq m \leq 10^9</var>, <var>2 \leq l \leq 10^9</var>). </p> <H2>Output</H2> <p> For each test case, print its case number and the minimum <var>a</var> modulo <var>m</var> as described above. </p> <H2>Sample Input</H2> <pre> 0 1000 10 1 1000 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 1 Case 2: 10 </pre>
p03491
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For strings <var>s</var> and <var>t</var>, we will say that <var>s</var> and <var>t</var> are <em>prefix-free</em> when neither is a prefix of the other.</p> <p>Let <var>L</var> be a positive integer. A set of strings <var>S</var> is a <em>good string set</em> when the following conditions hold true:</p> <ul> <li>Each string in <var>S</var> has a length between <var>1</var> and <var>L</var> (inclusive) and consists of the characters <code>0</code> and <code>1</code>.</li> <li>Any two distinct strings in <var>S</var> are prefix-free.</li> </ul> <p>We have a good string set <var>S = \{ s_1, s_2, ..., s_N \}</var>. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:</p> <ul> <li>Add a new string to <var>S</var>. After addition, <var>S</var> must still be a good string set.</li> </ul> <p>The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.</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 L \leq 10^{18}</var></li> <li><var>s_1</var>, <var>s_2</var>, ..., <var>s_N</var> are all distinct.</li> <li>{ <var>s_1</var>, <var>s_2</var>, ..., <var>s_N</var> } is a good string set.</li> <li><var>|s_1| + |s_2| + ... + |s_N| \leq 10^5</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>L</var> <var>s_1</var> <var>s_2</var> <var>:</var> <var>s_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Alice will win, print <code>Alice</code>; if Bob will win, print <code>Bob</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 00 01 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Alice </pre> <p>If Alice adds <code>1</code>, Bob will be unable to add a new string.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 00 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Bob </pre> <p>There are two strings that Alice can add on the first turn: <code>01</code> and <code>10</code>. In case she adds <code>01</code>, if Bob add <code>10</code>, she will be unable to add a new string. Also, in case she adds <code>10</code>, if Bob add <code>01</code>, she will be unable to add a new string.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 3 0 10 110 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Alice </pre> <p>If Alice adds <code>111</code>, Bob will be unable to add a new string.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 1 0 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Bob </pre> <p>Alice is unable to add a new string on the first turn.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>1 2 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>Alice </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>2 3 101 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>Bob </pre></section> </div> </span>
p01156
<H1><font color="#000">Problem B:</font> Hyper Rock-Scissors-Paper</H1> <p> Rock-Scissors-Paper is a game played with hands and often used for random choice of a person for some purpose. Today, we have got an extended version, namely, <i>Hyper Rock-Scissors-Paper</i> (or Hyper RSP for short). </p> <p> In a game of Hyper RSP, the players simultaneously presents their hands forming any one of the following 15 gestures: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, and Gun. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hyperRSP"><br> <p>Figure 1: Hyper Rock-Scissors-Paper</p> </center> <p> The arrows in the figure above show the defeating relation. For example, Rock defeats Fire, Scissors, Snake, Human, Tree, Wolf, and Sponge. Fire defeats Scissors, Snake, Human, Tree, Wolf, Sponge, and Paper. Generally speaking, each hand defeats other seven hands located after in anti-clockwise order in the figure. A player is said to win the game if the player’s hand defeats at least one of the other hands, and is not defeated by any of the other hands. </p> <p> Your task is to determine the winning hand, given multiple hands presented by the players. </p> <H2>Input</H2> <p> The input consists of a series of data sets. The first line of each data set is the number <i>N</i> of the players (<i>N</i> &lt; 1000). The next <i>N</i> lines are the hands presented by the players. </p> <p> The end of the input is indicated by a line containing single zero. </p> <H2>Output</H2> <p> For each data set, output the winning hand in a single line. When there are no winners in the game, output “Draw” (without quotes). </p> <H2>Sample Input</H2> <pre> 8 Lightning Gun Paper Sponge Water Dragon Devil Air 3 Rock Scissors Paper 0 </pre> <H2>Output for the Sample Input</H2> <pre> Sponge Draw </pre>
p00317
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>石版</H1> <p> 叀代囜家むワシロの遺跡から無数の石版が発芋された。研究者の調査によっお、各石版には䞀぀の単語が刻たれおいるこずが分かった。しかし、長幎の颚化によっお、以䞋の理由で解読が困難な石版もあるようだ。 </p> <ul> <li> 石版に曞かれおいる単語の䞀぀の文字だけが 苔(こけ)で芆われおいる堎合があり、その文字を把握するこずができない。 </li> <li> 石版の巊偎が欠けおおり、そこに䜕か文字列が曞かれおいたかもしれない石版の巊偎文字以䞊を把握するこずができない。</li> <li> 石版の右偎が欠けおおり、そこに䜕か文字列が曞かれおいたかもしれない石版の右偎文字以䞊を把握するこずができない。 </li> </ul> <p> 石版に苔が生えおいる堎所は倚くおも䞀か所しかない。たた、欠けた石版に苔が生えおいるこずはあるが、石版の䞡偎が同時に欠けおいるこずはない。 </p> <p> 研究者は、石版発芋以前の調査でわかっおいる単語をたずめた蟞曞を持っおいる。しかし、颚化の圱響による苔ず欠けがある石版から元の単語を掚枬したずき、蟞曞の䞭の単語に圓おはたるものがいく぀あるか、すぐには分からない。 </p> <p> 石版の情報が䞎えられたずき、䞎えられた蟞曞の䞭に圓おはたりそうな単語がいく぀あるかを数えるプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>word<sub>1</sub></var> <var>word<sub>2</sub></var> : <var>word<sub>N</sub></var> <var>slate<sub>1</sub></var> <var>slate<sub>2</sub></var> : <var>slate<sub>M</sub></var> </pre> <p> 行目に蟞曞に茉っおいる単語の数 <var>N</var> (1 &le; <var>N</var> &le; 50000)、石版の数 <var>M</var> (1 &le; <var>M</var> &le; 50000) が䞎えられる。続く <var>N</var> 行に単語 <var>word<sub>i</sub></var> が䞎えられる。単語は英小文字のみを含む長さが 1 以䞊 200 以䞋の文字列である。ただし、<var>N</var> 個の単語は党お異なる。続く <var>M</var> 行に、各石版の情報を衚す文字列 <var>slate<sub>i</sub></var> が䞎えられる。<var>slate<sub>i</sub></var> は英小文字、「?」、「*」を含む長さが 1 以䞊 200 以䞋の文字列である。? は苔に芆われた文字を衚す。? は䞀぀の文字列に、倚くずも䞀぀しか珟れない。文字列の先頭が * の堎合、石版の巊偎が欠けおいるこずを瀺す。文字列の末尟が * の堎合、石版の右偎が欠けおいるこずを瀺す。* は、文字列の先頭か末尟以倖には珟れず、同時に䞡偎に珟れるこずはない。* が䞀぀だけの文字列が䞎えられるこずはない。 </p> <p> 入力で䞎えられる文字列の文字の総数は 3000000 を超えない。 </p> <h2>Output</h2> <p> 各石版に぀いお、単語の数を行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 5 4 aloe apple apricot cactus cat apple ap* *e ca?* </pre> <h2>Sample Output 1</h2> <pre> 1 2 2 2 </pre>
p02280
<H1>Binary Tree</H1> <p> A rooted binary tree is a tree with a root node in which every node has at most two children. </p> <p> Your task is to write a program which reads a rooted binary tree <i>T</i> and prints the following information for each node <i>u</i> of <i>T</i>: </p> <ul> <li>node ID of <i>u</i></li> <li>parent of <i>u</i></li> <li>sibling of <i>u</i></li> <li>the number of children of <i>u</i></li> <li>depth of <i>u</i></li> <li>height of <i>u</i></li> <li>node type (root, internal node or leaf)</li> </ul> <p> If two nodes have the same parent, they are <b>siblings</b>. Here, if <i>u</i> and <i>v</i> have the same parent, we say <i>u</i> is a sibling of <i>v</i> (vice versa). </p> <p> The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf. </p> <p> Here, the given binary tree consists of <i>n</i> nodes and evey node has a unique ID from 0 to <i>n</i>-1. </p> <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 is given in the following format: </p> <p> <i>id left right</i> </p> <p> <i>id</i> is the node ID, <i>left</i> is ID of the left child and <i>right</i> is ID of the right child. If the node does not have the left (right) child, the <i>left</i>(<i>right</i>) is indicated by <span>-1</span>. </p> <H2>Output</H2> <p> Print the information of each node in the following format: </p> <p> <span>node</span> <i>id</i><span>: <span>parent = </span><i>p</i><span>, sibling = </span><i>s</i><span>, degree = </span><i>deg</i><span>, depth = <span><i>dep</i><span>, height = </span><i>h</i><span>, </span><i>type</i><br> </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>s</i> is ID of its sibling. If the node does not have a sibling, print <spna>-1</span>. </p> <p> <i>deg</i>, <i>dep</i> and <i>h</i> are the number of children, depth and height of the node respectively. </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> Please follow the format presented in a sample output below. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>n</i> &le; 25</li> </ul> <H2>Sample Input 1</H2> <pre> 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 </pre> <H2>Sample Output 1</H2> <pre> node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf </pre> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_7_B_1"><br> </center> <H2>Reference</H2> <p> Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. </p>
p01855
<h1 id="d-垂束暡様-checkered-pattern">D : 垂束暡様 / Checkered Pattern</h1> <h2 id="問題文">問題文</h2> <p>瞊暪の長さが <var>h, w</var> の長方圢があり 内郚には䞀蟺の長さが <var>1</var> の正方圢のマスが敷き詰められおいる 最も巊䞊のマスを <var>(0,0)</var> ずし <var>(0,0)</var> の <var>i</var> 個䞋で <var>j</var> 個右のマスを <var>(i,j)</var> のように衚すこずにするず <var>(i,j)</var> は <var>i+j</var> が偶数なら赀色に奇数なら青色に塗られおいる</p> <p>今<var>(0,0)</var> の巊䞊の頂点ず <var>(h &minus; 1,w &minus; 1)</var> の右䞋の頂点を線分で結んだ この線分が通る赀色の郚分の長さを <var>a</var>, 青色の郚分の長さを <var>b</var> ずおいたずき 比 <var>a : b</var> は敎数比ずなる<var>a : b</var> を最も簡単にしお(互いに玠な敎数で)衚せ</p> <h2 id="入力">入力</h2> <pre> <var>T</var> <var>h_1 \ w_1</var> <var>
</var> <var>h_T \ w_T</var> </pre> <p><var>1</var> ぀のファむルに <var>T</var> 個の入力が含たれる <var>1</var> 行目に <var>T</var> <var>1+i</var> 行目に <var>T</var> 番目の入力における瞊暪の長さ <var>h_i</var>, <var>w_i</var> が入力される</p> <h2 id="制玄">制玄</h2> <ul> <li>敎数である</li> <li><var>1 &le; T &le; 1000</var></li> <li><var>1 &le; h_i, w_i &le; 10<sup>9</sup></var></li> </ul> <h2 id="出力">出力</h2> <p>各ケヌスに察する答えを <var>1</var> でスペヌス区切りで出力せよ 党䜓で <var>T</var> 行にわたる</p> <h2 id="サンプル">サンプル</h2> <h3 id="サンプル入力1">サンプル入力1</h3> <pre> 3 2 3 3 3 4 3 </pre> <h3 id="サンプル出力1">サンプル出力1</h3> <pre> 1 1 1 0 1 1 </pre> <div class="figure"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RUPC2015ACPC2015_D" /> </div> <!-- - - - end nicebady - - - -->
p03868
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>There are <var>N</var> computers and <var>N</var> sockets in a one-dimensional world. The coordinate of the <var>i</var>-th computer is <var>a_i</var>, and the coordinate of the <var>i</var>-th socket is <var>b_i</var>. It is guaranteed that these <var>2N</var> coordinates are pairwise distinct.</p> <p>Snuke wants to connect each computer to a socket using a cable. Each socket can be connected to only one computer.</p> <p>In how many ways can he minimize the total length of the cables? Compute the answer modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^5</var></li> <li><var>0 ≀ a_i, b_i ≀ 10^9</var></li> <li>The coordinates are integers.</li> <li>The coordinates are pairwise distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> : <var>a_N</var> <var>b_1</var> : <var>b_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to minimize the total length of the cables, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 10 20 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two optimal connections: <var>0-20, 10-30</var> and <var>0-30, 10-20</var>. In both connections the total length of the cables is <var>40</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 10 8 7 12 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre></section> </div> </span>
p00747
<!-- begin en only --> <h1><font color="#000000">Problem B:</font> Amazing Mazes</h1> <!-- end en only --> <!-- begin en only --> <p> You are requested to solve maze problems. Without passing through these mazes, you might not be able to pass through the domestic contest! </p> <!-- end en only --> <!-- begin en only --> <p> A maze here is a rectangular area of a number of squares, lined up both lengthwise and widthwise, The area is surrounded by walls except for its entry and exit. The entry to the maze is at the leftmost part of the upper side of the rectangular area, that is, the upper side of the uppermost leftmost square of the maze is open. The exit is located at the rightmost part of the lower side, likewise. </p> <!-- end en only --> <!-- begin en only --> <p> In the maze, you can move from a square to one of the squares adjoining either horizontally or vertically. Adjoining squares, however, may be separated by a wall, and when they are, you cannot go through the wall. </p> <!-- end en only --> <!-- begin en only --> <p> Your task is to find the length of the shortest path from the entry to the exit. Note that there may be more than one shortest paths, or there may be none. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of one or more datasets, each of which represents a maze. </p> <!-- end en only --> <!-- begin en only --> <p> The first line of a dataset contains two integer numbers, the width <i>w</i> and the height <i>h</i> of the rectangular area, in this order. </p> <!-- end en only --> <!-- begin en only --> <p> The following 2 &times; <i>h</i> &minus; 1 lines of a dataset describe whether there are walls between squares or not. The first line starts with a space and the rest of the line contains <i>w</i> &minus; 1 integers, 1 or 0, separated by a space. These indicate whether walls separate horizontally adjoining squares in the first row. An integer 1 indicates a wall is placed, and 0 indicates no wall is there. The second line starts without a space and contains <i>w</i> integers, 1 or 0, separated by a space. These indicate whether walls separate vertically adjoining squares in the first and the second rows. An integer 1/0 indicates a wall is placed or not. The following lines indicate placing of walls between horizontally and vertically adjoining squares, alternately, in the same manner. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing two zeros. </p> <!-- end en only --> <!-- begin en only --> <p> The number of datasets is no more than 100. Both the widths and the heights of rectangular areas are no less than 2 and no more than 30. </p> <!-- end en only --> </p> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a line having an integer indicating the length of the shortest path from the entry to the exit. The length of a path is given by the number of visited squares. If there exists no path to go through the maze, output a line containing a single zero. The line should not contain any character other than this number. </p> <!-- end en only --> <h3>Sample Input</h3> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_B-1" align="right" width=60%> <pre> 2 3 1 0 1 0 1 0 1 9 4 1 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 12 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 </pre> <br clear=all> <h3>Output for the Sample Input</h3> <pre> 4 0 20 </pre>
p00252
<H1>乗車刞</H1> <p> 新幹線に乗るためには、「乗車刞」「特急刞」の2枚の切笊が必芁です。経路の䞀郚で新幹線を利甚しない堎合があるため、これらは別々の切笊ずなっおいたすが、新幹線のみを利甚する経路では、1枚で乗車刞ず特急刞を兌ねる「乗車・特急刞」が発行されるこずもありたす。 </p> <p> 自動改札機では、これらの切笊を読み蟌んで、正しい切笊が投入されたずきだけゲヌトを開けなければなりたせん。「乗車刞」ず「特急刞」それぞれ枚、たたは、その䞡方、たたは、「乗車・特急刞」が枚投入されたかどうかを刀定し、自動改札機の扉の開閉を刀断するプログラムを䜜成しお䞋さい。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> b<sub>1</sub> b<sub>2</sub> b<sub>3</sub> </pre> <p> 入力は行からなり、぀の空癜で区切られた぀の敎数を含む。b<sub>1</sub> は「乗車刞」の投入状態、b<sub>2</sub> は「特急刞」の投入状態、b<sub>3</sub> は「乗車・特急刞」の投入状態を瀺す。投入状態は0たたは1で衚され、0の堎合は投入されおいない状態、1の堎合は投入されおいる状態を衚す。ただし、想定される投入状態の組み合わせは以䞋の堎合のみずする。 </p> <center> <table class="withborder"> <tr> <th>入力</th> <th>投入状態</th> <th>投入に察する扉の動䜜</th> </tr> <tr> <td>1 0 0</td> <td>「乗車刞」のみ投入</td> <td>Close</td> </tr> <tr> <td>0 1 0</td> <td>「特急刞」のみ投入</td> <td>Close</td> </tr> <tr> <td>1 1 0</td> <td>「乗車刞」ず「特急刞」投入</td> <td>Open</td> </tr> <tr> <td>0 0 1</td> <td>「乗車・特急刞」投入</td> <td>Open</td> </tr> <tr> <td>0 0 0</td> <td>投入なし</td> <td>Close</td> </tr> </table> </center> <br/> <h2>出力</h2> <p> 自動改札機の開閉を衚すOpenたたはCloseを行に出力する。 </p> <h2>入力䟋1</h2> <pre> 0 0 1 </pre> <h2>出力䟋1</h2> <pre> Open </pre> <br/> <h2>入力䟋2</h2> <pre> 0 1 0 </pre> <h2>出力䟋2</h2> <pre> Close </pre>
p03887
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>Consider all integers between <var>1</var> and <var>2N</var>, inclusive. Snuke wants to divide these integers into <var>N</var> pairs such that:</p> <ul> <li>Each integer between <var>1</var> and <var>2N</var> is contained in exactly one of the pairs.</li> <li>In exactly <var>A</var> pairs, the difference between the two integers is <var>1</var>.</li> <li>In exactly <var>B</var> pairs, the difference between the two integers is <var>2</var>.</li> <li>In exactly <var>C</var> pairs, the difference between the two integers is <var>3</var>.</li> </ul> <p>Note that the constraints guarantee that <var>N = A + B + C</var>, thus no pair can have the difference of <var>4</var> or more.</p> <p>Compute the number of ways to do this, modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 5000</var></li> <li><var>0 ≀ A, B, C</var></li> <li><var>A + B + C = N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two possibilities: <var>1-2, 3-5, 4-6</var> or <var>1-3, 2-4, 5-6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>600 100 200 300 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>522158867 </pre></section> </div> </span>
p02795
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns, where all the squares are initially white.</p> <p>You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions:</p> <ul> <li>Choose one row, then paint all the squares in that row black.</li> <li>Choose one column, then paint all the squares in that column black.</li> </ul> <p>At least how many operations do you need in order to have <var>N</var> or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having <var>N</var> or more black squares is always possible by performing some number of operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H \leq 100</var></li> <li><var>1 \leq W \leq 100</var></li> <li><var>1 \leq N \leq H \times W</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>W</var> <var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations needed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 7 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>You can have <var>14</var> black squares in the grid by performing the "row" operation twice, on different rows.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>14 12 112 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 100 200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre></section> </div> </span>
p01910
<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>F: カヌドゲヌム</h1> <h2>問題</h2> <p> カヌドを䜿ったゲヌムを $Q$ 回行いたす。 カヌドには $1 \cdots N$ の数が曞かれおおり、各数が曞かれたカヌドはゲヌムを行うのに十分な枚数がありたす。 $i$ 回目のゲヌムでは、はじめに手札ずしお 2 枚のカヌドが配られたす。 それぞれのカヌドに曞かれおいる数字は $x_i$ ず $y_i$ です。 カヌドはルヌルに埓っお亀換するこずができたす。 $j$ 番目 $(1 \le j \le M)$ のルヌルでは、カヌド $a_j$ を手数料 $c_j$ 円で別のカヌド $b_j$ に亀換するこずができたす。 各ルヌルは䜕回でも甚いるこずができたす。たた、手数料が足りなくお亀換できない堎合はありたせん。 最埌に、手札のカヌドの数字を $R$ で割ったあたりが等しい時、報酬ずしお $z_i$ 円受け取りたす。 異なる堎合報酬は $0$ 円です。 </p> <p> $Q$ 回ゲヌムを終えた時に増やすこずのできるお金の最倧倀を求めおください。 </p> <h2>制玄</h2> <ul> <li>$1 \le N \le 10^5$</li> <li>$0 \le M \le \min(2 \times 10^5, N\times(N-1))$</li> <li>$2 \le R \le 10$</li> <li>$1 \le Q \le 10^5$</li> <li>$1 \le a_j, b_j \le N$</li> <li>$a_j \neq b_j$</li> <li>$0 \le c_j \le 10^5$</li> <li>$1 \le x_i, y_i \le N$</li> <li>$0 \le z_i \le 10^5$</li> </ul> <h2>入力</h2> <p> 入力は以䞋の圢匏で暙準入力から䞎えられたす。 </p> <p> $N \ M \ R \ Q$<br> $a_1 \ b_1 \ c_1$<br> $\vdots$<br> $a_M \ b_M \ c_M$<br> $x_1 \ y_1 \ z_1$<br> $\vdots$<br> $x_Q \ y_Q \ z_Q$ </p> <h2>出力</h2> <p> ゲヌムを $Q$ 回行ったずきに増やすこずのできるお金の最倧倀を 1 行で出力しおください。たた、末尟に改行も出力しおください。 </p> <h2>サンプル</h2> <h3>入力䟋 1</h3> <pre> 4 4 2 2 1 2 1 2 3 1 3 4 5 4 1 7 1 4 5 2 4 3 </pre> <h3>出力䟋 1</h3> <pre> 7 </pre> <p> 1 回目のゲヌムではカヌド 1 を手数料 1 でカヌド 2 に亀換するず手札のカヌドを 2 で割った時のあたりがどちらも 0 ずなり、埗られる報酬は 5 ずなりたす。 2 回目のゲヌムではすでに 2 で割ったずきのあたりがどちらも 0 であり、埗られる報酬は 3 ずなりたす。 2 回のゲヌムの結果、増やせるお金は $5-1+3=7$ です。 </p> <h3>入力䟋 2</h3> <pre> 4 4 2 1 1 2 1 2 3 1 3 4 5 4 1 7 3 4 2 </pre> <h3>出力䟋 2</h3> <pre> 0 </pre> <p> カヌドの亀換での手数料が報酬よりも倚いので、亀換を行わないのが最適です。 </p>
p00602
<H1><font color="#000000">Problem H:</font> Fibonacci Sets</H1> <p> Fibonacci number <i>f</i>(<i>i</i>) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule <i>f</i>(<i>i</i>) = <i>f</i>(<i>i</i> - 1) + <i>f</i>(<i>i</i> - 2), where we set <i>f</i>(0) = 1 = <i>f</i>(-1). </p> <!-- <p> Let <i>V</i> and <i>d</i> be two certain positive integers and be <i>N</i> &equiv; 1001 a constant. Consider a set of <i>V</i> nodes, each node <i>i</i> having a Fibonacci label (<i>f</i>(<i>i</i>) mod N) assigned for <i>i</i> = 1,..., <i>V</i> &le; N. If |<i>f</i>(<i>i</i>) - <i>f</i>(<i>j</i>)| &lt; <i>d</i>, then the nodes <i>i</i> and <i>j</i> are connected. </p> --> <p> Let <i>V</i> and <i>d</i> be two certain positive integers and be <i>N</i> &equiv; 1001 a constant. Consider a set of <i>V</i> nodes, each node <i>i</i> having a Fibonacci label <i>F</i>[<i>i</i>] = (<i>f</i>(<i>i</i>) mod N) assigned for <i>i</i> = 1,..., <i>V</i> &le; N. If |<i>F</i>(<i>i</i>) - <i>F</i>(<i>j</i>)| &lt; <i>d</i>, then the nodes <i>i</i> and <i>j</i> are connected. </p> <p> Given <i>V</i> and <i>d</i>, how many connected subsets of nodes will you obtain? </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fibonaccisets"> </center> <center> <p> Figure 1: There are 4 connected subsets for <i>V</i> = 20 and <i>d</i> = 100. </p> </center> <H2>Input</H2> <p> Each data set is defined as one line with two integers as follows: </p> <p> <i>Line 1</i>: Number of nodes <i>V</i> and the distance <i>d</i>. </p> <p> Input includes several data sets (i.e., several lines). The number of dat sets is less than or equal to 50. </p> <h2>Constraints</h2> <ul> <li>1 &le; V &le; 1000</li> <li>1 &le; d &le; 150</li> </ul> <H2>Output</H2> <p> Output line contains one integer - the number of connected subsets - for each input line. </p> <H2>Sample Input</H2> <pre> 5 5 50 1 13 13 </pre> <H2>Output for the Sample Input</H2> <pre> 2 50 8 </pre>
p01443
<H1><font color="#000">Problem G:</font> Number Sorting</H1> <p> Consider sets of natural numbers. Some sets can be sorted in the same order numerically and lexicographically. {2, 27, 3125, 9000} is one example of such sets; {2, 27, 243} is not since lexicographic sorting would yield {2, 243, 27}. </p> <p> Your task is to write a program that, for the set of integers in a given range [<i>A</i>,<i>B</i>] (i.e. between <i>A</i> and <i>B</i> inclusive), counts the number of non-empty subsets satisfying the above property. Since the resulting number is expected to be very huge, your program should output the number in modulo <i>P</i> given as the input. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset consists of a line with three integers <i>A</i>, <i>B</i>, and <i>P</i> separated by a space. These numbers satisfy the following conditions: 1 &le; <i>A</i> &le; 1,000,000,000, 0 &le; <i>B</i> - <i>A</i> &lt; 100,000, 1 &le; <i>P</i> &le; 1,000,000,000. </p> <p> The end of input is indicated by a line with three zeros. </p> <H2>Output</H2> <p> For each dataset, output the number of the subsets in modulo <i>P</i>. </p> <H2>Sample Input</H2> <pre> 1 10 1000 1 100000 1000000000 999999999 1000099998 1000000000 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 513 899507743 941554688 </pre>
p03184
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with <var>H</var> horizontal rows and <var>W</var> vertical columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p> <p>In the grid, <var>N</var> Squares <var>(r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N)</var> are wall squares, and the others are all empty squares. It is guaranteed that Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</p> <p>Taro will start from Square <var>(1, 1)</var> and reach <var>(H, W)</var> by repeatedly moving right or down to an adjacent empty square.</p> <p>Find the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>, 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>2 \leq H, W \leq 10^5</var></li> <li><var>1 \leq N \leq 3000</var></li> <li><var>1 \leq r_i \leq H</var></li> <li><var>1 \leq c_i \leq W</var></li> <li>Squares <var>(r_i, c_i)</var> are all distinct.</li> <li>Squares <var>(1, 1)</var> and <var>(H, W)</var> are empty squares.</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>r_1</var> <var>c_1</var> <var>r_2</var> <var>c_2</var> <var>:</var> <var>r_N</var> <var>c_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of Taro's paths from Square <var>(1, 1)</var> to <var>(H, W)</var>, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 2 2 2 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are three paths as follows:</p> <p><img alt="" src="https://img.atcoder.jp/dp/grid_1_0_muffet.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 2 2 1 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>There may be no paths.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 5 4 3 1 3 5 1 3 5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>24 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100000 100000 1 50000 50000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>123445622 </pre> <p>Be sure to print the count modulo <var>10^9 + 7</var>.</p></section> </div> </span>
p01013
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1> Problem H: Cone Cut</h1> <h2> Problem </h2> <p> この問題では3次元空間䞊のある点<var>X </var>ずある点<var>Y </var>を通るような盎線を盎線<var>XY </var>ず曞く。 </p> <p> 3次元空間䞊に円錐ずその円錐内郚の点<var>P </var>が䞎えられる。点<var>P </var>を通り円錐の底面に垂盎な盎線ず円錐の底面ずの亀点を点<var>Q </var>ずする。この時、円錐の底面の䞭心を<var>O </var>ずし、盎線<var>OQ </var>ず円錐の底面の円呚ずの亀点を、点<var>Q </var>に近い方から点<var>A </var>、点<var>B </var>ずする(ただし、点<var>O </var>ず点<var>Q </var>が同䞀点のずきは、点<var>O </var>を通る任意の盎線ず円錐の底面の円呚ずの亀点を点<var>A </var>、点<var>B </var>ずする。)。たた、円錐の底面を含むような平面においお、点<var>O </var>を通り、盎線<var>AB </var>ず垂盎に亀わる盎線ず円錐の底面の円呚ずの亀点を点<var>C </var>、点<var>D </var>ずする(ただし、点<var>C </var>ず点<var>D </var>は入れ替えおも問題ない)。<br /> </p> <p> 以䞋の図は、円錐の頂点方向から芋た円錐の底面の図である。 </p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_bird" alt="円錐の頂点方向から芋た円錐の底面の図"><br /> </p> <p> 盎線<var>AP </var>ず盎線<var>BP </var>の円錐ずの亀点盎線<var>AP </var>の堎合、点<var>A </var>でない方の亀点を指す。盎線<var>BP </var>も同様。を点<var>A' </var>、点<var>B' </var>ずし、点<var>A' </var>ず点<var>B' </var>を通り盎線<var>CD </var>ず平行な平面<var>S </var>で円錐を切断する。この時、切断埌の頂点を含む図圢の䜓積ずもう䞀方の図圢の䜓積を空癜区切りで出力せよ。 </p> <h2> Input </h2> <p> 円錐の頂点の<var>x </var>座暙 <var>y </var>座暙 <var>z </var>座暙<br /> 円錐の底面の䞭心の<var>x </var>座暙 <var>y </var>座暙 <var>z </var>座暙 円錐の底面の半埄<br /> 点<var>P </var>の<var>x </var>座暙 <var>y </var>座暙 <var>z </var>座暙<br /> <br /> 各行のそれぞれの倀はスペヌス区切りで䞎えられる。 </p> <h2> Constraint </h2> <p> 入力の倀はすべお敎数であり、その絶察倀は1000以䞋である。<br /> 円錐の高さずその底面の半埄は1以䞊であり、点<var>P </var>ず円錐の距離は10<sup>-5</sup>以䞊ある。 </p> <h2> Output </h2> <p> 切断埌の頂点を含む図圢の䜓積ずもう䞀方の図圢の䜓積を空癜区切りで出力せよ。<br /> ただし、10<sup>-5</sup>を超える誀差を含んではいけない。 </p> <h2> Sample Input 1</h2> <pre> 0 0 10 0 0 0 4 0 0 1 </pre> <h2> Sample Output 1</h2> <pre> 91.769438 75.782170 </pre> <h2> Sample Input 2</h2> <pre> 0 0 10 0 0 0 4 1 1 1 </pre> <h2> Sample Output 2</h2> <pre> 84.050413 83.501195 </pre> <h2> Sample Input 3</h2> <pre> 0 0 0 8 9 10 5 1 1 1 </pre> <h2> Sample Output 3</h2> <pre> 0.071663 409.709196 </pre>
p02146
<h1>Problem J: Averaging</h1> <h2>Problem</h2> <p> アむヅ囜には$N$個の島ず$N-1$個の橋があり、各島はそれぞれ$1$から$N$たでの番号が割り振られおいる。 $i$番目の橋は島$u_i$ず島$v_i$を双方向に結んでおり、島民は橋を甚いお島ず島ずを行き来するこずができる。たた、橋以倖に島ず島を行き来する方法はない。 どの島からどの島ぞもいく぀かの橋を枡るこずで到達するこずができる。 </p> <p> 珟圚、島$i$には$X_i$人の島民がいる。 各島の環境ぞの負荷を分散させるためにアむヅ囜は䜕人かの囜民に別の島ぞ匕越しおもらうこずにした。 å³¶$a$に䜏んでいる人を島$b$に匕越しさせるためには島$a$ず島$b$の距離ず同じ分のコストがかかる。ただし、島$a$ず島$b$の距離は島$a$から島$b$ぞ行くために枡る必芁のある橋の数の最小倀で定矩される。 </p> <p> どの$2$぀の島を遞んでもそれらの島民の人数の差の絶察倀が$1$以䞋になるように囜民に匕越しおもらいたい。 このずき、必芁なコストの総和の最小倀を求めよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏ですべお敎数で䞎えられる。</p> <pre> $N$ $X_1$ $X_2$ ... $X_N$ $u_1$ $v_1$ $u_2$ $v_2$ ... $u_{N-1}$ $v_{N-1}$ </pre> <p> $1$行目に島の数$N$が䞎えられる。<br> $2$行目には各島の島民の人数を衚す$N$個の敎数が空癜区切りで䞎えられる。$i$番目の敎数$X_i$は島$i$の島民の人数を衚す。<br> $3$行目から続く$N-1$行には各橋が぀なぐ島の番号が空癜区切りで䞎えられる。$2+i$行目の入力では、$i$番目の橋が島$u_i$ず島$v_i$を双方向に結んでいるこずを衚す。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$2 \le N \le 5000$</li> <li>$0 \le X_i \le 10^9$</li> <li>$1 \le u_i, v_i \le N$</li> <li>どの島からどの島ぞもいく぀かの橋を枡るこずで到達するこずができる</li> </ul> <h2>Output</h2> <p> コストの総和の最小倀を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 5 4 0 4 0 0 1 2 1 3 1 4 2 5 </pre> <h2>Sample Output 1</h2> <pre> 7 </pre> <p> å³¶$1$の人が$1$人、島$2$ぞ、<br> å³¶$1$の人が$1$人、島$5$ぞ、<br> å³¶$3$の人が$2$人、島$4$ぞ匕っ越すこずでどの$2$぀の島を遞んでもそれらの島民の人数の差の絶察倀が$1$以䞋になる。 たたこのずきのコストの総和は$1+2+2\times2 = 7$であり、これが最小である。 </p> <h2>Sample Input 2</h2> <pre> 7 0 7 2 5 0 3 0 1 2 1 3 1 4 2 5 3 6 3 7 </pre> <h2>Sample Output 2</h2> <pre> 10 </pre>
p00481
<H1>チヌズ (Cheese)</H1> <h2>問題</h2> <p> 今幎も JOI 町のチヌズ工堎がチヌズの生産を始めねずみが巣から顔を出したJOI 町は東西南北に区画敎理されおいお各区画は巣チヌズ工堎障害物空き地のいずれかであるねずみは巣から出発しお党おのチヌズ工堎を蚪れチヌズを 1 個ず぀食べる </p> <p> この町にはN 個のチヌズ工堎がありどの工堎も皮類のチヌズだけを生産しおいるチヌズの硬さは工堎によっお異なっおおり硬さ 1 から N たでのチヌズを生産するチヌズ工堎がちょうど 1 ぀ず぀ある </p> <p> ねずみの最初の䜓力は 1 でありチヌズを 1 個食べるごずに䜓力が 1 増えるただしねずみは自分の䜓力よりも硬いチヌズを食べるこずはできない </p> <p> ねずみは東西南北に隣り合う区画に 1 分で移動するこずができるが障害物の区画には入るこずができないチヌズ工堎をチヌズを食べずに通り過ぎるこずもできるすべおのチヌズを食べ終えるたでにかかる最短時間を求めるプログラムを曞けただしねずみがチヌズを食べるのにかかる時間は無芖できる </p> <h2>入力</h2> <p> 入力は H+1 行ある1 行目には 3 ぀の敎数 HWN (1 &le; H &le; 10001 &le; W &le; 10001 &le; N &le; 9) がこの順に空癜で区切られお曞かれおいる2 行目から H+1 行目たでの各行には'S''1', '2', ..., '9''X''.' からなる W 文字の文字列が曞かれおおり各々が各区画の状態を衚しおいる北から i 番目西から j 番目の区画を (i,j) ず蚘述するこずにするず (1 &le; i &le; H, 1 &le; j &le; W)第 i+1 行目の j 番目の文字は区画 (i,j) が巣である堎合は 'S' ずなり障害物である堎合は 'X' ずなり空き地である堎合は '.' ずなり硬さ 1, 2, ..., 9 のチヌズを生産する工堎である堎合はそれぞれ '1', '2', ..., '9' ずなる入力には巣ず硬さ 1, 2, ..., N のチヌズを生産する工堎がそれぞれ 1 ぀ず぀ある他のマスは障害物たたは空き地であるこずが保蚌されおいるねずみは党おのチヌズを食べられるこずが保蚌されおいる </p> <h2>出力</h2> <p> すべおのチヌズを食べ終えるたでにかかる最短時間分を衚す敎数を 1 行で出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 3 3 1 S.. ... ..1 </pre> <h3>出力䟋 1</h3> <pre> 4 </pre> <h3>入力䟋 2</h3> <pre> 4 5 2 .X..1 ....X .XX.S .2.X. </pre> <h3>出力䟋 2</h3> <pre> 12 </pre> <h3>入力䟋 3</h3> <pre> 10 10 9 .X...X.S.X 6..5X..X1X ...XXXX..X X..9X...X. 8.X2X..X3X ...XX.X4.. XX....7X.. X..X..XX.. X...X.XX.. ..X....... </pre> <h3>出力䟋 3</h3> <pre> 91 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div> <br>
p03307
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a positive integer <var>N</var>. Find the minimum positive integer divisible by both <var>2</var> and <var>N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum positive integer divisible by both <var>2</var> and <var>N</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p><var>6</var> is divisible by both <var>2</var> and <var>3</var>. Also, there is no positive integer less than <var>6</var> that is divisible by both <var>2</var> and <var>3</var>. Thus, the answer is <var>6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>999999999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1999999998 </pre></section> </div> </span>
p03757
<span class="lang-en lang-child hidden-lang"> <div id="task-statement"> Max Score: <var>1450</var> Points <br/> <section> <h3>Problem Statement</h3> There are <var>N</var> workers in Atcoder company. Each worker is numbered <var>0</var> through <var>N - 1</var>, and the boss for worker <var>i</var> is <var>p_i</var> like a tree structure and the salary is currently <var>a_i</var>. (<var>p_i &lt; i</var>, especially <var>p_0 = -1</var> because worker <var>0</var> is a president) <br/> In atcoder, the boss of boss of boss of ... (repeated <var>k</var> times) worker <var>i</var> called "<var>k</var>-th upper boss", and "<var>k</var>-th lower subordinate" called for vice versa. <br/> <br/> You have to process <var>Q</var> queries for Atcoder: <br/> <ul> <li>Query 1: You are given <var>v_i, d_i, x_i</var>. Increase the salary of worker <var>v_i</var>, and all <var>j</var>-th (<var>1 ≀ j ≀ d_i</var>) lower subordinates by <var>x_i</var>.</li> <li>Query 2: You are given <var>v_i, d_i</var>. Calculate the sum of salary of worker <var>v_i</var> and all <var>j</var>-th (<var>1 ≀ j ≀ d_i</var>) lower subordinates.</li> <li>Query 3: You are given <var>pr_i, ar_i</var>. Now Atcoder has a new worker <var>c</var>! (<var>c</var> is the current number of workers) The boss is <var>pr_i</var>, and the first salary is <var>ar_i</var>.</li> </ul> Process all queries!!! <br/> </section> </div> <div class="io-style"> <div class="part"> <section> <h3>Input Format</h3> Let the <var>i</var>-th query <var>query_i</var>, the input format is following:<br/> <pre> <var>N</var> <var>Q</var> <var>p_0</var> <var>a_0</var> <var>p_1</var> <var>a_1</var> : : <var>p_{N - 1}</var> <var>a_{N - 1}</var> <var>query_0</var> <var>query_1</var> : : <var>query_{Q - 1}</var> </pre> THe format of <var>query_i</var> is one of the three format:<br/> <pre> 1 <var>v_i</var> <var>d_i</var> <var>x_i</var> </pre> <pre> 2 <var>v_i</var> <var>d_i</var> </pre> <pre> 3 <var>pr_i</var> <var>ar_i</var> </pre> </section> </div> <div class="part"> <section> <h3>Output Format</h3> Print the result in one line for each query 2.<br/> </section> <section> <h3>Constraints</h3> <ul> <li><var>N ≀ 400000</var></li> <li><var>Q ≀ 50000</var></li> <li><var>p_i &lt; i</var> for all valid <var>i</var>.</li> <li>In each question 1 or 2, worker <var>v_i</var> exists.</li> <li><var>d_i ≀ 400000</var></li> <li><var>0 ≀ a_i, x_i ≀ 1000</var></li> </ul> </section> <section> <h3>Scoring</h3> Subtask 1 [<var>170</var> points] <br/> <ul> <li><var>N, Q ≀ 5000</var></li> </ul> Subtask 2 [<var>310</var> points] <br/> <ul> <li><var>p_i + 1 = i</var> for all valid <var>i</var>.</li> </ul> Subtask 3 [<var>380</var> points] <br/> <ul> <li>There are no query 3.</li> </ul> Subtask 4 [<var>590</var> points] <br/> <ul> <li>There are no additional constraints.</li> </ul> </section> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 6 7 -1 6 0 5 0 4 2 3 2 2 1 1 2 0 1 1 0 2 1 2 2 1 3 3 3 2 0 3 3 3 4 2 1 1 </pre> </section> <section> <h3>Sample Output 1</h3> <pre> 15 12 30 8 </pre> </section> </div> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 7 9 -1 1 0 5 0 7 0 8 1 3 4 1 5 1 2 1 1 2 1 2 1 1 2 3 1 4 1 1 2 3 1 2 0 2 3 6 1 3 7 11 2 0 15 </pre> </section> <section> <h3>Sample Output 2</h3> <pre> 8 9 8 31 49 </pre> </section> </div> <!-- 入出力䟋の説明もできれば曞く --> </span>
p00878
<H1><font color="#000">Problem E:</font> Origami Through-Hole</H1> <p> Origami is the traditional Japanese art of paper folding. One day, Professor Egami found the message board decorated with some pieces of origami works pinned on it, and became interested in the pinholes on the origami paper. Your mission is to simulate paper folding and pin punching on the folded sheet, and calculate the number of pinholes on the original sheet when unfolded. </p> <p> A sequence of folding instructions for a flat and square piece of paper and a single pinhole position are specified. As a folding instruction, two points <i>P</i> and <i>Q</i> are given. The paper should be folded so that <i>P</i> touches <i>Q</i> from above (Figure 4). To make a fold, we first divide the sheet into two segments by creasing the sheet along the <i>folding line</i>, i.e., the perpendicular bisector of the line segment <i>PQ</i>, and then turn over the segment containing <i>P</i> onto the other. You can ignore the thickness of the paper. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_origami1"><br> <p>Figure 4: Simple case of paper folding</p> </center> <p> The original flat square piece of paper is folded into a structure consisting of layered paper segments, which are connected by linear hinges. For each instruction, we fold one or more paper segments along the specified folding line, dividing the original segments into new smaller ones. The folding operation turns over some of the paper segments (not only the new smaller segments but also some other segments that have no intersection with the folding line) to the reflective position against the folding line. That is, for a paper segment that intersects with the folding line, one of the two new segments made by dividing the original is turned over; for a paper segment that does not intersect with the folding line, the whole segment is simply turned over. </p> <p> The folding operation is carried out repeatedly applying the following rules, until we have no segment to turn over. </p> <ul> <li> Rule 1: The uppermost segment that contains <i>P</i> must be turned over.</li> <li> Rule 2: If a hinge of a segment is moved to the other side of the folding line by the operation, any segment that shares the same hinge must be turned over.</li> <li>Rule 3: If two paper segments overlap and the lower segment is turned over, the upper segment must be turned over too.</li> </ul> <p> In the examples shown in Figure 5, (a) and (c) show cases where only Rule 1 is applied. (b) shows a case where Rule 1 and 2 are applied to turn over two paper segments connected by a hinge, and (d) shows a case where Rule 1, 3 and 2 are applied to turn over three paper segments. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_origami2"><br> <p>Figure 5: Different cases of folding</p> </center> <p> After processing all the folding instructions, the pinhole goes through all the layered segments of paper at that position. In the case of Figure 6, there are three pinholes on the unfolded sheet of paper. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_origami3"><br> <p>Figure 6: Number of pinholes on the unfolded sheet</p> </center> <H2>Input</H2> <p> The input is a sequence of datasets. The end of the input is indicated by a line containing a zero. </p> <p> Each dataset is formatted as follows. </p> <p> <i>k</i><br> <i>p</i><sub><i>x</i></sub><sup>1</sup> <i>p</i><sub><i>y</i></sub><sup>1</sup> <i>q</i><sub><i>x</i></sub><sup>1</sup> <i>q</i><sub><i>y</i></sub><sup>1</sup><br> .<br> .<br> .<br> <i>p</i><sub><i>x</i></sub><sup><i>k</i></sup> <i>p</i><sub><i>y</i></sub><sup><i>k</i></sup> <i>q</i><sub><i>x</i></sub><sup><i>k</i></sup> <i>q</i><sub><i>y</i></sub><sup><i>k</i></sup><br> <i>h<sub>x</sub> h<sub>y</sub></i> </p> <p> For all datasets, the size of the initial sheet is 100 mm square, and, using mm as the coordinate unit, the corners of the sheet are located at the coordinates (0, 0), (100, 0), (100, 100) and (0, 100). The integer <i>k</i> is the number of folding instructions and 1 &le; <i>k</i> &le; 10. Each of the following <i>k</i> lines represents a single folding instruction and consists of four integers <i>p<sub>x</sub><sup>i</sup></i>, <i>p<sub>y</sub><sup>i</sup></i>, <i>q<sub>x</sub><sup>i</sup></i>, and <i>q<sub>y</sub><sup>i</sup></i>, delimited by a space. The positions of point <i>P</i> and <i>Q</i> for the <i>i</i>-th instruction are given by (<i>p<sub>x</sub><sup>i</sup></i>, <i>p<sub>y</sub><sup>i</sup></i>) and (<i>q<sub>x</sub><sup>i</sup></i>, <i>q<sub>y</sub><sup>i</sup></i>), respectively. You can assume that <i>P</i> &ne; <i>Q</i>. You must carry out these instructions in the given order. The last line of a dataset contains two integers <i>h<sub>x</sub></i> and <i>h<sub>y</sub></i> delimited by a space, and (<i>h<sub>x</sub></i>, <i>h<sub>y</sub></i> ) represents the position of the pinhole. </p> <p> You can assume the following properties: </p> <ol> <li> The points <i>P</i> and <i>Q</i> of the folding instructions are placed on some paper segments at the folding time, and <i>P</i> is at least 0.01 mm distant from any borders of the paper segments.</li> <li> The position of the pinhole also is at least 0.01 mm distant from any borders of the paper segments at the punching time.</li> <li> Every folding line, when infinitely extended to both directions, is at least 0.01 mm distant from any corners of the paper segments before the folding along that folding line.</li> <li> When two paper segments have any overlap, the overlapping area cannot be placed between any two parallel lines with 0.01 mm distance. When two paper segments do not overlap, any points on one segment are at least 0.01 mm distant from any points on the other segment.</li> </ol> <p> For example, Figure 5 (a), (b), (c) and (d) correspond to the first four datasets of the sample input. </p> <H2>Output</H2> <p> For each dataset, output a single line containing the number of the pinholes on the sheet of paper, when unfolded. No extra characters should appear in the output. </p> <H2>Sample Input</H2> <pre> 2 90 90 80 20 80 20 75 50 50 35 2 90 90 80 20 75 50 80 20 55 20 3 5 90 15 70 95 90 85 75 20 67 20 73 20 75 3 5 90 15 70 5 10 15 55 20 67 20 73 75 80 8 1 48 1 50 10 73 10 75 31 87 31 89 91 94 91 96 63 97 62 96 63 80 61 82 39 97 41 95 62 89 62 90 41 93 5 2 1 1 1 -95 1 -96 1 -190 1 -191 1 -283 1 -284 1 -373 1 -374 1 -450 1 2 77 17 89 8 103 13 85 10 53 36 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3 4 3 2 32 1 0 </pre>
p02845
<span class="lang-en"> <p>Score: <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p><var>N</var> people are standing in a queue, numbered <var>1, 2, 3, ..., N</var> from front to back. Each person wears a hat, which is red, blue, or green.</p> <p>The person numbered <var>i</var> says:</p> <ul> <li>"In front of me, exactly <var>A_i</var> people are wearing hats with the same color as mine."</li> </ul> <p>Assuming that all these statements are correct, find the number of possible combinations of colors of the <var>N</var> people's hats.</p> <p>Since the count can be enormous, compute it modulo <var>1000000007</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 100000</var></li> <li><var>0 \leq A_i \leq N-1</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>A_3</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of possible combinations of colors of the <var>N</var> people's hats, modulo <var>1000000007</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 0 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>We have three possible combinations, as follows:</p> <ul> <li>Red, Red, Red, Red, Red, Red</li> <li>Blue, Blue, Blue, Blue, Blue, Blue</li> <li>Green, Green, Green, Green, Green, Green</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 0 0 </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>54 0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>115295190 </pre></section> </div> </span>
p01290
<H1><font color="#000">Problem H:</font> Queen's Case</H1> <p> A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the queen. Now, they besieged the palace and have just rushed into the entrance. </p> <p> Your task is to write a program to determine whether the queen can escape or will be caught by the army. </p> <p> Here is detailed description. </p> <ul> <li> The palace can be considered as grid squares.</li> <li> The queen and the army move alternately. The queen moves first.</li> <li> At each of their turns, they either move to an adjacent cell or stay at the same cell.</li> <li> Each of them must follow the optimal strategy.</li> <li> If the queen and the army are at the same cell, the queen will be caught by the army immediately.</li> <li> If the queen is at any of exit cells alone after the army’s turn, the queen can escape from the army.</li> <li> There may be cases in which the queen cannot escape but won’t be caught by the army forever, under their optimal strategies.</li> </ul> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset describes a map of the palace. The first line of the input contains two integers <i>W</i> (1 &le; <i>W</i> &le; 30) and <i>H</i> (1 &le; <i>H</i> &le; 30), which indicate the width and height of the palace. The following <i>H</i> lines, each of which contains <i>W</i> characters, denote the map of the palace. "<span>Q</span>" indicates the queen, "<span>A</span>" the army,"<span>E</span>" an exit,"<span>#</span>" a wall and "<span>.</span>" a floor. </p> <p> The map contains exactly one "<span>Q</span>", exactly one "<span>A</span>" and at least one "<span>E</span>". You can assume both the queen and the army can reach all the exits. </p> <p> The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, output "<span>Queen can escape.</span>", "<span>Army can catch Queen.</span>" or "<span>Queen can not escape and Army can not catch Queen.</span>" in a line. </p> <H2>Sample Input</H2> <pre> 2 2 QE EA 3 1 QAE 3 1 AQE 5 5 ..E.. .###. A###Q .###. ..E.. 5 1 A.E.Q 5 5 A.... ####. ..E.. .#### ....Q 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Queen can not escape and Army can not catch Queen. Army can catch Queen. Queen can escape. Queen can not escape and Army can not catch Queen. Army can catch Queen. Army can catch Queen. </pre> <h2>Hint</h2> <p> On the first sample input, the queen can move to exit cells, but either way the queen will be caught at the next army’s turn. So the optimal strategy for the queen is staying at the same cell. Then the army can move to exit cells as well, but again either way the army will miss the queen from the other exit. So the optimal strategy for the army is also staying at the same cell. Thus the queen cannot escape but won’t be caught. </p>
p01785
<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>F - Polygon Guards</h2> <h3>Problem Statement</h3> <p> You are an IT system administrator in the Ministry of Defense of Polygon Country. </p> <p> Polygon Country's border forms the polygon with $N$ vertices. Drawn on the 2D-plane, all of its vertices are at the lattice points and all of its edges are parallel with either the $x$-axis or the $y$-axis. </p> <p> In order to prevent enemies from invading the country, it is surrounded by very strong defense walls along its border. However, on the vertices, the junctions of walls have unavoidable structural weaknesses. Therefore, enemies might attack and invade from the vertices. </p> <p> To observe the vertices and find an invasion by enemies as soon as possible, the ministry decided to hire some guards. The ministry plans to locate them on some vertices such that all the vertices are observed by at least one guard. A guard at the vertex $A$ can observe a vertex $B$ if the entire segment connecting $A$ and $B$ is inside or on the edge of Polygon Country. Of course, guards can observe the vertices they are located on. And a guard can observe simultaneously all the vertices he or she can observe. </p> <p> To reduce the defense expense, the ministry wants to minimize the number of guards. Your task is to calculate the minimum number of guards required to observe all the vertices of Polygon Country. </p> <h3>Input</h3> <p>The input is formatted as follows. </p> <blockquote>$N$<br>$X_1$ $Y_1$<br>:<br>:<br>$X_N$ $Y_N$</blockquote> <p> The first line contains an even integer $N$ ($4 \le N \lt 40$). The following $N$ lines describe the vertices of Polygon Country. Each of the lines contains two integers, $X_i$ and $Y_i$ ($1 \le i \le N$, $\lvert X_i \rvert \le 1{,}000$, $\lvert Y_i \rvert \le 1{,}000$), separated by one space. The position of the $i$-th vertex is $(X_i,Y_i)$. </p> <p> If $i$ is odd, $X_i = X_{i+1}$, $Y_i \ne Y_{i+1}$. Otherwise, $X_i \ne X_{i+1}$, $Y_i = Y_{i+1}$. Here, we regard that $X_{N+1} = X_1$, and $Y_{N+1} = Y_1$. The vertices are given in counterclockwise order under the coordinate system that the $x$-axis goes right, and the $y$-axis goes up. The shape of Polygon Country is simple. That is, each edge doesn’t share any points with other edges except that its both end points are shared with its neighbor edges. </p> <h3>Output</h3> <p>Print the minimum number of guards in one line. </p> <h3>Sample Input 1</h3> <pre>8 0 2 0 0 2 0 2 1 3 1 3 3 1 3 1 2</pre> <h3>Output for the Sample Input 1</h3> <pre>1</pre> <h3>Sample Input 2</h3> <pre>12 0 0 0 -13 3 -13 3 -10 10 -10 10 10 -1 10 -1 13 -4 13 -4 10 -10 10 -10 0</pre> <h3>Output for the Sample Input 2</h3> <pre>2</pre>
p00897
<H1><font color="#000">Problem D: </font>Long Distance Taxi </H1> <p> A taxi driver, Nakamura, was so delighted because he got a passenger who wanted to go to a city thousands of kilometers away. However, he had a problem. As you may know, most taxis in Japan run on liquefied petroleum gas (LPG) because it is cheaper than gasoline. There are more than 50,000 gas stations in the country, but less than one percent of them sell LPG. Although the LPG tank of his car was full, the tank capacity is limited and his car runs 10 kilometer per liter, so he may not be able to get to the destination without filling the tank on the way. He knew all the locations of LPG stations. Your task is to write a program that finds the best way from the current location to the destination without running out of gas. </p> <H2>Input</H2> <p> The input consists of several datasets, and each dataset is in the following format. </p> <p> <i>N M cap<br> src dest</i><br> <i>c</i><sub>1,1</sub> <i>c</i><sub>1,2</sub> <i>d</i><sub>1</sub><br> <i>c</i><sub>2,1</sub> <i>c</i><sub>2,2</sub> <i>d</i><sub>2</sub><br> .<br> .<br> .<br> <i>c</i><sub>N,1</sub> <i>c</i><sub>N,2</sub> <i>d</i><sub>N</sub><br> <i>s</i><sub>1</sub><br> <i>s</i><sub>2</sub><br> .<br> .<br> .<br> <i>s</i><sub>M</sub> <p> The first line of a dataset contains three integers (<i>N, M, cap</i>), where <i>N</i> is the number of roads (1 &le; <i>N</i> &le; 3000),<i>M</i> is the number of LPG stations (1&le; <i>M</i> &le; 300), and <i>cap</i> is the tank capacity (1 &le; <i>cap</i> &le; 200) in liter. The next line contains the name of the current city (<i>src</i>) and the name of the destination city (<i>dest</i>). The destination city is always different from the current city. The following <i>N</i> lines describe roads that connect cities. The road i (1 &le; <i>i</i> &le; N) connects two different cities <i>c</i><sub>i,1</sub> and <i>c</i><sub>i,2</sub> with an integer distance <i>d</i><sub>i</sub> (0 &lt; <i>d</i><sub>i</sub> &le; 2000) in kilometer, and he can go from either city to the other. You can assume that no two different roads connect the same pair of cities. The columns are separated by a single space. The next <i>M</i> lines (<i>s</i><sub>1</sub>,<i>s</i><sub>2</sub>,...,<i>s</i><sub>M</sub>) indicate the names of the cities with LPG station. You can assume that a city with LPG station has at least one road. </p> <p> The name of a city has no more than 15 characters. Only English alphabet ('A' to 'Z' and 'a' to 'z', case sensitive) is allowed for the name. </p> <p> A line with three zeros terminates the input. </p> <H2>Output</H2> <p> For each dataset, output a line containing the length (in kilometer) of the shortest possible journey from the current city to the destination city. If Nakamura cannot reach the destination, output "-1" (without quotation marks). You must not output any other characters. The actual tank capacity is usually a little bit larger than that on the specification sheet, so you can assume that he can reach a city even when the remaining amount of the gas becomes exactly zero. In addition, you can always fill the tank at the destination so you do not have to worry about the return trip. </p> <H2>Sample Input</H2> <pre> 6 3 34 Tokyo Kyoto Tokyo Niigata 335 Tokyo Shizuoka 174 Shizuoka Nagoya 176 Nagoya Kyoto 195 Toyama Niigata 215 Toyama Kyoto 296 Nagoya Niigata Toyama 6 3 30 Tokyo Kyoto Tokyo Niigata 335 Tokyo Shizuoka 174 Shizuoka Nagoya 176 Nagoya Kyoto 195 Toyama Niigata 215 Toyama Kyoto 296 Nagoya Niigata Toyama 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 846 -1 </pre>
p03242
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Cat Snuke is learning to write characters. Today, he practiced writing digits <code>1</code> and <code>9</code>, but he did it the other way around.</p> <p>You are given a three-digit integer <var>n</var> written by Snuke. Print the integer obtained by replacing each digit <code>1</code> with <code>9</code> and each digit <code>9</code> with <code>1</code> in <var>n</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>111 \leq n \leq 999</var></li> <li><var>n</var> is an integer consisting of digits <code>1</code> and <code>9</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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the integer obtained by replacing each occurrence of <code>1</code> with <code>9</code> and each occurrence of <code>9</code> with <code>1</code> in <var>n</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>119 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>991 </pre> <p>Replace the <code>9</code> in the ones place with <code>1</code>, the <code>1</code> in the tens place with <code>9</code> and the <code>1</code> in the hundreds place with <code>9</code>. The answer is <code>991</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>111 </pre></section> </div> </span>
p03612
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>p_1,p_2,...,p_N</var> consisting of <var>1</var>,<var>2</var>,..,<var>N</var>. You can perform the following operation any number of times (possibly zero):</p> <p>Operation: Swap two <strong>adjacent</strong> elements in the permutation.</p> <p>You want to have <var>p_i ≠ i</var> for all <var>1≀i≀N</var>. Find the minimum required number of operations to achieve this.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N≀10^5</var></li> <li><var>p_1,p_2,..,p_N</var> is a permutation of <var>1,2,..,N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>p_1</var> <var>p_2</var> .. <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum required number of operations</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 4 3 5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Swap <var>1</var> and <var>4</var>, then swap <var>1</var> and <var>3</var>. <var>p</var> is now <var>4,3,1,5,2</var> and satisfies the condition. This is the minimum possible number, so the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>Swapping <var>1</var> and <var>2</var> satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>The condition is already satisfied initially.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>9 1 2 4 9 5 8 7 3 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3 </pre></section> </div> </span>
p02900
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are positive integers <var>A</var> and <var>B</var>.</p> <p>Let us choose some number of positive common divisors of <var>A</var> and <var>B</var>.</p> <p>Here, any two of the chosen divisors must be coprime.</p> <p>At most, how many divisors can we choose?</p> <details><summary>Definition of common divisor</summary><div> <p>An integer <var>d</var> is said to be a common divisor of integers <var>x</var> and <var>y</var> when <var>d</var> divides both <var>x</var> and <var>y</var>.</p> </div></details> <details><summary>Definition of being coprime</summary><div> <p>Integers <var>x</var> and <var>y</var> are said to be coprime when <var>x</var> and <var>y</var> have no positive common divisors other than <var>1</var>.</p> </div></details> <details><summary>Definition of dividing</summary><div> <p>An integer <var>x</var> is said to divide another integer <var>y</var> when there exists an integer <var>\alpha</var> such that <var>y = \alpha x</var>.</p> </div></details> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq A, B \leq 10^{12}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of divisors that can be chosen to satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>12 18 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p><var>12</var> and <var>18</var> have the following positive common divisors: <var>1</var>, <var>2</var>, <var>3</var>, and <var>6</var>.</p> <p><var>1</var> and <var>2</var> are coprime, <var>2</var> and <var>3</var> are coprime, and <var>3</var> and <var>1</var> are coprime, so we can choose <var>1</var>, <var>2</var>, and <var>3</var>, which achieve the maximum result.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>420 660 </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>1 2019 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p><var>1</var> and <var>2019</var> have no positive common divisors other than <var>1</var>.</p></section> </div> </span>
p00194
<H1>運送䌚瀟</H1> <table> <tr> <td style="vertical-align:top"> <p> 癜虎運送は䌚接若束垂を代衚する運送䌚瀟です。昚今の原油䟡栌の高隰は運送䌚瀟にも倚倧なダメヌゞを䞎え、運送䌚瀟各瀟では、できるだけ少ないガ゜リンで荷物を運ぶこずが課題ずなっおいたす。 </p> </td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_byakkoDelivery1"> </td> </tr> </table> <p> 癜虎運送では、重い荷物を積んだトラックは、その走りだしに倚くの゚ネルギヌを必芁ずするこずに着目したした。トラックが倉庫を出発しおから䞀床も停止するこずなく目的地たで到達する経路の䞭で最短時間の経路を通るこずで、ガ゜リンの節玄ができるず考えたした。 </p> <p> あなたの仕事は、このような最短経路を蚈算できるカヌナビを開発するこずです。䜜成するカヌナビ甚プログラムの仕様は以䞋のずおりです。 </p> <ul> <li>垂内は、䞋図のように、東西方向の道路 <var>M</var> 本、南北方向の道路 <var>N</var> 本 からなる栌子で衚し、栌子の各亀点は亀差点を衚したす。</li> <li>亀差点のいく぀かには東西 - 南北の方向に信号機が蚭眮されおおり、䞀定の呚期で青、赀のシグナルが点灯しおいたす。</li> <li>垂内の亀差点間を結ぶ道路には工事䞭で通過できない個所がいく぀かありたす。</li> <li>トラックが亀差点から亀差点ぞ移動するのに必芁な時間は䞀定ですが、枋滞しおいる道路ではさらに長い時間がかかりたす。</li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_byakkoDelivery2"> </center> <br/> <p> 垂内の道路情報、トラックが亀差点間を移動するのに必芁な時間、信号機がある亀差点ず各信号機の呚期、工事䞭の道路、枋滞しおいる道路ず枋滞床、癜虎運送の倉庫(始点)ず目的地(終点)の䜍眮を入力ずし、始点から終点たでの最短の時間を出力するプログラムを䜜成しお䞋さい。 </p> <p> 図のように、東西の方向の道路はa、b、c、... ず英小文字で名前が付けられ 、南北の方向の道路は 1、2、3、... ず敎数で名前が付けられおいたす。垂内の亀差点は、これらの英小文字ず敎数の組み合わせ <var>H</var>-<var>V</var> で指定されたす。 </p> <p> 䟋えば、垂内の最北西の亀差点は a-1 で指定されたす。各信号は呚期 <var>k</var> をもち、<var>k</var> 分ごずに切り替わりたす。東西が青ならば南北が赀で、南北が青ならば東西が赀です。黄色のシグナルは存圚したせん。トラックは二぀の亀差点を結ぶ道路を移動するのに <var>D</var> 分芁したすが、その道路が枋滞しおいる堎合はさらに <var>d</var> 分の時間を芁したす。トラックは道路が工事䞭の堎合は移動できたせん。 </p> <p> たた、亀差点に到達した時刻に、信号が赀の堎合には進入できたせん。トラックは亀差点でのみ、東、西、南、北に方向を倉えるこずができたすが、来た方向ぞは移動(Uタヌン)できたせん。道路は2方通行であり、トラックが行き来する時間、工事状況、枋滞床は2方向共通です。 </p> <p> 初期状態ずしお、トラックは東を向いおいお、トラックが倉庫を出発する瞬間すべおの信号機が南北の方向に青に切り替わるものずしたす。たた、トラックは 100分以内で目的地に到達できるものずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>M</var> <var>N</var> <var>D</var> <var>ns</var> <var>H<sub>1</sub></var>-<var>V<sub>1</sub></var> <var>k<sub>1</sub></var> <var>H<sub>2</sub></var>-<var>V<sub>2</sub></var> <var>k<sub>2</sub></var> : <var>H<sub>ns</sub></var>-<var>V<sub>ns</sub></var> <var>k<sub>ns</sub></var> <var>nc</var> <var>H<sub>11</sub></var>-<var>V<sub>11</sub></var> <var>H<sub>12</sub></var>-<var>V<sub>12</sub></var> <var>H<sub>21</sub></var>-<var>V<sub>21</sub></var> <var>H<sub>22</sub></var>-<var>V<sub>22</sub></var> : <var>H<sub>nc1</sub></var>-<var>V<sub>nc1</sub></var> <var>H<sub>nc2</sub></var>-<var>V<sub>nc2</sub></var> <var>nj</var> <var>H<sub>11</sub></var>-<var>V<sub>11</sub></var> <var>H<sub>12</sub></var>-<var>V<sub>12</sub></var> <var>d<sub>1</sub></var> <var>H<sub>21</sub></var>-<var>V<sub>21</sub></var> <var>H<sub>22</sub></var>-<var>V<sub>22</sub></var> <var>d<sub>2</sub></var> : <var>H<sub>nj1</sub></var>-<var>V<sub>nj1</sub></var> <var>H<sub>nj2</sub></var>-<var>V<sub>nj2</sub></var> <var>d<sub>nj</sub></var> <var>H<sub>s</sub></var>-<var>V<sub>s</sub></var> <var>H<sub>d</sub></var>-<var>V<sub>d</sub></var> </pre> <p> 行目に道路の本数 <var>M</var>, <var>N</var> (2 &le; <var>M, N</var> &le; 20) が䞎えられたす。行目に、二぀の亀差点を結ぶ道路を移動するのに芁する時間 <var>D</var> (1 &le; <var>D</var> &le; D, 敎数) が䞎えられたす。 </p> <p> 行目に信号機の数 <var>ns</var> が䞎えられたす。続く <var>ns</var> 行に、<var>i</var> 個目の信号機の䜍眮を衚す英小文字ず敎数の組 <var>H<sub>i</sub></var>-<var>V<sub>i</sub></var> ず呚期 <var>k</var> (1 &le; <var>k</var> &le; 100) が䞎えられたす。 </p> <p> 続く行に、工事䞭の道路の数 <var>nc</var> が䞎えられたす。続く <var>nc</var> 行に、<var>i</var> 個目の工事䞭の道路の぀の端点亀差点を衚す英小文字ず敎数の組 <var>H<sub>i1</sub></var>-<var>V<sub>i1</sub></var> <var>H<sub>i2</sub></var>-<var>V<sub>i2</sub></var> が䞎えられたす。 </p> <p> 続く行に、枋滞道路の数 <var>nj</var> が䞎えられたす。続く <var>nj</var> 行に、<var>i</var> 個目の枋滞道路の぀の端点亀差点を衚す英小文字ず敎数の組 <var>H<sub>i1</sub></var>-<var>V<sub>i1</sub></var> <var>H<sub>i2</sub></var>-<var>V<sub>i2</sub></var> ず時間 <var>d<sub>i</sub></var> (1 &le; <var>d<sub>i</sub></var> &le; 100) が䞎えられたす。 </p> <p> 最埌の行に、始点の亀差点 <var>H<sub>s</sub></var>-<var>V<sub>d</sub></var> ず終点の亀差点 <var>H<sub>d</sub></var>-<var>V<sub>d</sub></var> が䞎えられたす。 </p> <p> デヌタセットの数は 20 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に最短時間を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 4 5 1 3 b-2 3 c-3 2 c-4 1 3 a-2 b-2 b-3 c-3 d-3 d-4 2 b-3 b-4 1 c-1 d-1 1 d-1 b-4 4 5 1 3 b-2 3 c-3 2 c-4 1 3 a-2 b-2 b-3 c-3 d-3 d-4 2 b-3 b-4 1 c-1 d-1 1 d-2 b-4 4 5 1 3 b-2 3 c-3 2 c-4 1 3 a-2 b-2 b-3 c-3 d-3 d-4 2 b-3 b-4 1 c-1 d-1 1 d-3 b-4 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 7 4 8 </pre>
p02453
<h1>Lower Bound</h1> <p> For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, find the lower bound for a specific value $k$ given as a query. </p> <ul> <li> lower bound: the place pointing to the first element greater than or equal to a specific value, or $n$ if there is no such element. </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$ $k_1$ $k_2$ : $k_q$ </pre> <p> The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries. </p> <h2>Output</h2> <p> For each query, print the position $i$ ($i = 0, 1, ..., n$) of the lower bound in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 100,000$</li> <li>$1 \leq q \leq 200,000$</li> <li>$0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$ <li>$0 \leq k_i \leq 1,000,000,000$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 1 2 2 4 3 2 3 5 </pre> <h2>Sample Output 1</h2> <pre> 1 3 4 </pre>
p02003
<h1>H: 板</h1> <h2>問題</h2> <p> $R * C$ のマスが䞎えられたす各マスは䜕もないマスか穎が開いおいるマスのどちらかです 䞎えられるマスは以䞋の条件を満たしたす。 </p> <ul> <li> 穎の開いたマス同士は連結である穎の開いたマスを十字方向に぀たっお任意の穎の開いたマスに移動するこずができる</li> <li> 䜕もないマス同士は連結である</li> </ul> <p> あなたは幅が $1$ の任意長の長方圢型のタむルを生成するこずができたす このタむルを耇数枚蚭眮しお党おの穎のあるマスを埋めたいですタむルを蚭眮するずき以䞋の制玄を守る必芁がありたす </p> <ul> <li>タむルは瞊向きか暪向きの $2$ 方向でのみ蚭眮が可胜である</li> <li>䞀぀のマスに二枚以䞊のタむルが重なるように蚭眮しおはいけない</li> <li>穎のないマスの䞊にタむルがあっおはいけない</li> </ul> <p> 䞊蚘の制玄を守っお党おの穎のあるマスをタむルで埋めたずきのタむルの最小枚数を答えおください </p> <h2>制玄</h2> <ul> <li>$1 \leq R, C \leq 25$</li> <li>$|S_i| = C \ \ \ \ |S_i|$ は文字列の長さを衚す。</li> <li>$S_{i,j}$ は '#' たたは '.' で、それぞれ穎の開いたマス、䜕もないマスを衚す。</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <p> $R\ C$<br> $S_{1,1} \dots S_{1,C}$<br> $\vdots$<br> $S_{R,1} \dots S_{R,C}$<br> </p> <h2>出力</h2> <p> 最小回数を出力しおください。末尟に改行も出力しおください。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 5 5 ..... .#.#. .###. .#.#. ..... </pre> <h3>サンプル出力 1</h3> <pre> 3 </pre> <p> $3$ 枚のタむルを以䞋のように眮くのが最適です </p> <pre> ..... .1.3. .123 .1.3 ..... </pre> <h3>サンプル入力 2</h3> <pre> 4 10 ########## ....#..... ....#..... .......... </pre> <h3>サンプル出力 2</h3> <pre> 2 </pre> <p> $2$ 枚のタむルを以䞋のように眮くのが最適ですタむルの長さは任意長にでき瞊向きにも暪向きにも䜿えるこずに泚意しおください </p> <pre> 1111111111 ....2..... ....2..... .......... </pre>
p01802
<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> <!-- begin en only --> <h3><u>Koto Municipal Subway</u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>Koto垂営地䞋鉄</u></h3> <!-- end ja only --> <!-- begin ja only --> <p>Koto垂は䞋図のように道路が碁盀の目状である有名な街である 南北に䌞びる道ず東西に䌞びる道はそれぞれ1kmの間隔で䞊んでいる Koto垂の最も南西の亀差点にあるKoto駅を (0, 0) ずしおそこから東に <var>x</var> km北に <var>y</var> km 進んだ䜍眮を (<var>x</var>, <var>y</var>) ず蚘すこずずする (0 &le; <var>x</var>, <var>y</var> である) </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2015_A1" height="456" width="414" /> <p>5幎埌に開かれるオリンピックにより芳光客が増倧するこずを芋越しお垂はKoto駅を始発駅ずする新しい地䞋鉄の路線を建蚭するこずを決めた 珟圚Koto駅の次の駅ずしお新しく建蚭されるShin-Koto駅たでのレヌルを敷く蚈画を立おおいる レヌルはKoto駅からShin-Koto駅に向かっおたっすぐ敷く 埓っおShin-Koto駅の堎所を (<var>x</var>, <var>y</var>) ずしたずきレヌルの長さは &radic;(<var>x</var><sup>2</sup> + <var>y</var><sup>2</sup>) である レヌルを敷くための費甚は敷いたレヌルの長さ分だけ必芁になる レヌルの長さが1.5kmのように小数であっおも費甚も同じように1.5必芁ずなる </p> <p>Shin-Koto駅の堎所 (<var>x</var>, <var>y</var>) はただ決定しおおらず以䞋の条件を満たす堎所にする予定である </p> <ul><li> 亀差点である぀たり <var>x</var> ず <var>y</var> がそれぞれ敎数である </li><li> Koto駅から道路に沿っお歩いた最短距離がちょうど <var>D</var> である぀たり <var>x</var> + <var>y</var> = <var>D</var> を満たす </li></ul> <p>䞊の2぀の条件を満たす䞭で垂が定めるレヌルの予算 <var>E</var> ずレヌルの費甚ずのずれ | &radic;(<var>x</var><sup>2</sup> + <var>y</var><sup>2</sup>) - <var>E</var> | が最小ずなるようにShin-Koto駅の堎所を遞ぶ ここで |<var>A</var>| は <var>A</var> の絶察倀を衚す あなたの仕事は䞊蚘のようにShin-Koto駅を建蚭したずきのレヌルを敷くための費甚ず予算ずのずれを出力するプログラムを䜜成するこずである </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットから構成され1぀の入力に含たれるデヌタセットの数は100以䞋である 各デヌタセットの圢匏は次の通りである </p> <blockquote><var>D</var> <var>E</var></blockquote> <p><var>D</var> (1 &le; <var>D</var> &le; 100)はKoto駅からShin-Koto駅たで道路に沿っお歩いたずきの最短距離を衚す敎数である <var>E</var> (1 &le; <var>E</var> &le; 100)はレヌル建蚭のための予算を衚す敎数である </p> <p>入力の終わりは空癜で区切られた2぀のれロからなる行によっお瀺される </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに察しお問題の条件を満たすようにレヌルを敷いたずきの費甚ず予算ずのずれを1行で出力せよ 答えには 10<sup>-3</sup> を越える絶察誀差があっおはならない 各行の終わりに改行を出力しなかった堎合や䞍必芁な文字を出力した堎合誀答ず刀断されおしたうため泚意するこず </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>2 1 7 5 7 6 7 7 76 5 8 41 0 0</pre> <h3>Output for Sample Input</h3> <pre>0.4142135624 0 0.0827625303 0 48.7401153702 33</pre> <h3>Hint</h3> <!-- begin ja only --> <p>1぀目のデヌタセットでは䞋図のようにKoto駅から道路に沿っお2km進んだ亀差点がShin-Koto駅を建蚭する堎所の候補ずなる </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2015_A2" height="146" width="453" /> <p>各亀差点にShin-Koto駅を建蚭した堎合のレヌルを敷くための費甚ず予算1ずのずれは次のようになる </p> <ul><li> (2, 0)  | &radic;(2<sup>2</sup> + 0<sup>2</sup>) - 1 | = 1.0 </li><li> (1, 1)  | &radic;(1<sup>2</sup> + 1<sup>2</sup>) - 1 | = 0.4142135623... </li><li> (0, 2)  | &radic;(0<sup>2</sup> + 2<sup>2</sup>) - 1 | = 1.0 </li></ul> <p>よっお費甚ず予算ずのずれが最小になるのは (1, 1) に建蚭した堎合ずなる </p> <!-- end ja only -->
p00710
<h1> <font color="#000">Problem A:</font> Hanafuda Shuffle </h1> <p> There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game 'Hanafuda' is one such example. The following is how to perform Hanafuda shuffling. </p> <p> There is a deck of <I>n</I> cards. Starting from the <I>p</I>-th card from the top of the deck, <I>c</I> cards are pulled out and put on the top of the deck, as shown in Figure 1. This operation, called a cutting operation, is repeated. </p> <p> Write a program that simulates Hanafuda shuffling and answers which card will be finally placed on the top of the deck. </p> <center> <table> <tr> <td ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hanafuda"></td> </tr> <tr> <td ALIGN="center">Figure 1: Cutting operation</td> </tr> </table> </center> <h2>Input</h2> <p> The input consists of multiple data sets. Each data set starts with a line containing two positive integers <I>n</I> (1 &lt;= <I>n</I> &lt;= 50) and <I>r</I> (1 &lt;= <I>r</I> &lt;= 50); <I>n</I> and <I>r</I> are the number of cards in the deck and the number of cutting operations, respectively. </p> <p> There are <I>r</I> more lines in the data set, each of which represents a cutting operation. These cutting operations are performed in the listed order. Each line contains two positive integers <I>p</I> and <I>c</I> (<I>p</I> + <I>c</I> &lt;= <I>n</I> + 1). Starting from the <I>p</I>-th card from the top of the deck, <I>c</I> cards should be pulled out and put on the top. </p> <p> The end of the input is indicated by a line which contains two zeros. </p> <p> Each input line contains exactly two integers separated by a space character. There are no other characters in the line. </p> <h2>Output</h2> <p> For each data set in the input, your program should write the number of the top card after the shuffle. Assume that at the beginning the cards are numbered from 1 to <I>n</I>, from the bottom to the top. Each number should be written in a separate line without any superfluous characters such as leading or following spaces. </p> <h2>Sample Input</h2> <pre> 5 2 3 1 3 1 10 3 1 10 10 1 8 3 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 4 4 </pre>
p00340
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>長方圢 </H1> <p> アむヅ攟送協䌚の教育番組(教育)では、子ども向けの工䜜番組「あそんで぀くろ」を攟送しおいたす。今日は棒で長方圢を䜜る回ですが、甚意した本の棒を䜿っお長方圢ができるかを確かめたいず思いたす。ただし、棒は切ったり折ったりしおはいけたせん。 </p> <br/> <p> 本の棒の長さが䞎えられるので、それらすべおを蟺ずする長方圢が䜜れるかどうか刀定するプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>e<sub>1</suv></var> <var>e<sub>2</suv></var> <var>e<sub>3</suv></var> <var>e<sub>4</suv></var> </pre> <p> 入力は行からなり、各棒の長さを衚す敎数 <var>e<sub>i</sub></var> (1 &le; <var>e<sub>i</sub></var> &le; 100) が䞎えられる。 </p> <h2>Output</h2> <p> 長方圢を䜜成できる堎合には「yes」を、䜜成できない堎合には「no」を出力する。ただし、正方圢は長方圢の䞀皮なので、正方圢の堎合でも「yes」ず出力する。 </p> <h2>Sample Input 1</h2> <pre> 1 1 3 4 </pre> <h2>Sample Output 1</h2> <pre> no </pre> <br/> <h2>Sample Input 2</h2> <pre> 1 1 2 2 </pre> <h2>Sample Output 2</h2> <pre> yes </pre> <br/> <h2>Sample Input 3</h2> <pre> 2 1 1 2 </pre> <h2>Sample Output 3</h2> <pre> yes </pre> <br/> <h2>Sample Input 4</h2> <pre> 4 4 4 10 </pre> <h2>Sample Output 4</h2> <pre> no </pre> <br/>
p03995
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with <var>R</var> rows and <var>C</var> columns. We call the cell in the <var>r</var>-th row and <var>c</var>-th column (<var>rc</var>).</p> <p>Mr. Takahashi wrote non-negative integers into <var>N</var> of the cells, that is, he wrote a non-negative integer <var>a_i</var> into (<var>r_ic_i</var>) for each <var>i</var> (<var>1≀i≀N</var>). After that he fell asleep.</p> <p>Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing integers into all remaining cells. The grid must meet the following conditions to really surprise Mr. Takahashi.</p> <ul> <li>Condition <var>1</var>: Each cell contains a non-negative integer.</li> <li>Condition <var>2</var>: For any <var>2×2</var> square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.</li> </ul> <p>Determine whether it is possible to meet those conditions by properly writing integers into all remaining cells.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀RC≀10^5</var></li> <li><var>1≀N≀10^5</var></li> <li><var>1≀r_i≀R</var></li> <li><var>1≀c_i≀C</var></li> <li><var>(r_ic_i) ≠ (r_jc_j)</var> (<var>i≠j</var>)</li> <li><var>a_i</var> is an integer.</li> <li><var>0≀a_i≀10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>R</var> <var>C</var> <var>N</var> <var>r_1</var> <var>c_1</var> <var>a_1</var> <var>r_2</var> <var>c_2</var> <var>a_2</var> <var>:</var> <var>r_N</var> <var>c_N</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>Yes</code> if it is possible to meet the conditions by properly writing integers into all remaining cells. Otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 3 1 1 0 1 2 10 2 1 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>You can write integers as follows.</p> <p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_0.png" width="300"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 5 1 1 0 1 2 10 1 3 20 2 1 30 2 3 40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>There are two <var>2×2</var> squares on the grid, formed by the following cells:</p> <ul> <li>Cells <var>(11)</var>, <var>(12)</var>, <var>(21)</var> and <var>(22)</var></li> <li>Cells <var>(12)</var>, <var>(13)</var>, <var>(22)</var> and <var>(23)</var></li> </ul> <p>You have to write <var>40</var> into the empty cell to meet the condition on the left square, but then it does not satisfy the condition on the right square.</p> <p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_1.png" width="168"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 2 3 1 1 20 1 2 10 2 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre> <p>You have to write <var>-10</var> into the empty cell to meet condition <var>2</var>, but then it does not satisfy condition <var>1</var>.</p> <p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_2.png" width="120"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 3 4 1 1 0 1 3 10 3 1 10 3 3 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Yes </pre> <p>You can write integers as follows.</p> <p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_3.png" width="396"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>2 2 4 1 1 0 1 2 10 2 1 30 2 2 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>No </pre> <p>All cells already contain a integer and condition <var>2</var> is not satisfied.</p> <p><img src="/img/other/code_festival_2016_quala/gbanjthabot/D_4.png" width="120"/></p></section> </div> </span>
p02687
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoder Inc. holds a contest every Saturday.</p> <p>There are two types of contests called ABC and ARC, and just one of them is held at a time.</p> <p>The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.</p> <p>Given a string <var>S</var> representing the type of the contest held last week, print the string representing the type of the contest held this week.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is <code>ABC</code> or <code>ARC</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the string representing the type of the contest held this week.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>ABC </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>ARC </pre> <p>They held an ABC last week, so they will hold an ARC this week.</p></section> </div> </span>
p01101
<h3><u>Taro's Shopping</u></h3> <p> Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he plans to buy the pair of two items with the highest price sum, not exceeding the amount Mammy allows. As getting two of the same item is boring, he wants two different items. </p> <p> You are asked to help Taro select the two items. The price list for all of the items is given. Among pairs of two items in the list, find the pair with the highest price sum not exceeding the allowed amount, and report the sum. Taro is buying two items, not one, nor three, nor more. Note that, two or more items in the list may be priced equally. </p> <h3>Input</h3> <p> The input consists of multiple datasets, each in the following format. </p> <pre> <i>n</i> <i>m</i> <i>a</i><sub>1</sub> <i>a</i><sub>2</sub> ... <i>a<sub>n</sub></i> </pre> <p> A dataset consists of two lines. In the first line, the number of items <i>n</i> and the maximum payment allowed <i>m</i> are given. <i>n</i> is an integer satisfying 2 &#8804; <i>n</i> &#8804; 1000. <i>m</i> is an integer satisfying 2 &#8804; <i>m</i> &#8804; 2,000,000. In the second line, prices of <i>n</i> items are given. <i>a<sub>i</sub></i> (1 &#8804; <i>i</i> &#8804; <i>n</i>) is the price of the <i>i</i>-th item. This value is an integer greater than or equal to 1 and less than or equal to 1,000,000. </p> <p> The end of the input is indicated by a line containing two zeros. The sum of <i>n</i>'s of all the datasets does not exceed 50,000. </p> <h3>Output</h3> <p> For each dataset, find the pair with the highest price sum not exceeding the allowed amount <i>m</i> and output the sum in a line. If the price sum of every pair of items exceeds <i>m</i>, output <tt>NONE</tt> instead. </p> <!-- end en only --> <h3>Sample Input</h3> <pre>3 45 10 20 30 6 10 1 2 5 8 9 11 7 100 11 34 83 47 59 29 70 4 100 80 70 60 50 4 20 10 5 10 16 0 0 </pre> <h3>Output for the Sample Input</h3> <pre>40 10 99 NONE 20 </pre>
p01551
<h1>問題名 DNA</h1> <p>遺䌝子は、<code>A</code>, <code>T</code>, <code>G</code>, <code>C</code> からなる文字列です。 この䞖界の遺䌝子は奇劙なこずに、ある構文芏則に埓うこずが知られおいたす。 </p> <p>構文芏則は、次のような圢で䞎えられたす。 </p><pre>非終端蚘号1: 蚘号1_1 蚘号1_2 ... 蚘号1_n1 非終端蚘号2: 蚘号2_1 蚘号2_2 ... 蚘号2_n2 ... 非終端蚘号m: 蚘号m_1 蚘号m_2 ... 蚘号m_nm </pre> <p>蚘号は非終端蚘号たたは終端蚘号のどちらかです。 非終端蚘号は小文字文字列で衚され、終端蚘号は<code>A</code>, <code>T</code>, <code>G</code>, <code>C</code>のうちのいく぀かの文字が、&quot;<code>[</code>&quot;ず&quot;<code>]</code>&quot;に囲たれた文字列で衚されたす。 </p> <p>構文芏則の䟋は次のようになりたす。 </p><pre>dna: a a b b a: [AT] b: [GC] </pre> <p>&quot;<code>非終端蚘号i: 蚘号i_1 蚘号i_2 ... 蚘号i_ni</code>&quot; を非終端蚘号 <var>i</var> のルヌルず呌び、ルヌルは、構文芏則に珟れる各非終端蚘号に察しお、ちょうど 1 ぀づ぀存圚したす。 </p> <p>文字列 <var>s</var> が非終端蚘号 <var>i</var> に「<code>マッチする</code>」ずは、 <var>s = s<sub>1</sub> + s<sub>2</sub> + ... + s<sub>ni</sub></var> ずなるような <var>s</var> の郚分文字列 <var>{s<sub>j</sub>}</var> が存圚し、<var>s<sub>j</sub></var> (<var>1 &le; j &le; n<sub>i</sub></var>)がルヌル内の蚘号 <var>j</var> にマッチするこずをいいたす。 </p> <p>文字列 <var>s</var> が終端蚘号に「<code>マッチする</code>」ずは、文字列が 1 文字からなり、その文字が終端蚘号を衚す文字列に含たれるこずをいいたす。 </p> <p>文字列が構文芏則に埓うずは、非終端蚘号 <var>1</var> にその文字列がマッチするこずをいいたす。 </p> <p>ルヌル <var>i</var> は、蚘号のうちに、非終端蚘号 <var>j</var> (<var>j &le; i</var>) を含みたせん。 </p> <p>構文芏則ず、4぀の敎数 <var>Na</var> , <var>Nt</var>, <var>Ng</var>, <var>Nc</var> が䞎えられたす。 構文芏則に埓い、A をちょうど <var>Na</var> 個、T をちょうど <var>Nt</var> 個、G をちょうど <var>Ng</var> 個、C をちょうど <var>Nc</var> 個含むような遺䌝子の総数を 1,000,000,007 で割った䜙りを求めなさい。 </p> <h2>Input</h2> <blockquote> <var>Na</var> <var>Nt</var> <var>Ng</var> <var>Nc</var><br><var>m</var><br>非終端蚘号1: 蚘号 <var>1<sub>1</sub></var> 蚘号 <var>1<sub>2</sub></var> ... 蚘号 <var>1<sub>n1</sub></var><br>非終端蚘号2: 蚘号 <var>2<sub>1</sub></var> 蚘号 <var>2<sub>2</sub></var> ... 蚘号 <var>2<sub>n2</sub></var><br>...<br>非終端蚘号 <var>m</var>: 蚘号 <var>m<sub>1</sub></var> 蚘号 <var>m<sub>2</sub></var> ... 蚘号 <var>m<sub>nm</sub></var><br></blockquote> <p><var>0 &le; Na, Nt, Ng, Nc &le; 50</var> </p> <p><var>1 &le; m &le; 50</var> </p> <p><var>1 &le; ni &le; 10</var> </p> <p><var>1 &le; </var> 蚘号を衚す文字列の長さ <var> &le; 20</var> (※蚘号にマッチする文字列の長さではないこずに泚意) </p> <h2>Output</h2> <p>総数を 1,000,000,007 で割った䜙り </p> <h2>Sample Input 1</h2> <pre>1 0 1 0 3 dna: a b a: [AT] b: [GC] </pre> <h2>Output for the Sample Input 1</h2> <pre>1 </pre> <p>"AG"の䞀぀です。 </p> <h2>Sample Input 2</h2> <pre>1 1 1 2 1 k: [ATG] [ATG] [ATG] [C] [C] </pre> <h2>Output for the Sample Input 2</h2> <pre>6 </pre> <p>"ATGCC", "AGTCC", "TAGCC", "TGACC", "GATCC", "GTACC"の6぀です。 </p> <h2>Sample Input 3</h2> <pre>3 1 1 1 3 inv: at b b b at: [ATG] b b: [C] </pre> <h2>Output for the Sample Input 3</h2> <pre>0 </pre>
p03096
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. The <var>i</var>-th stone from the left is painted in the color <var>C_i</var>.</p> <p>Snuke will perform the following operation zero or more times:</p> <ul> <li>Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.</li> </ul> <p>Find the number of possible final sequences of colors of the stones, modulo <var>10^9+7</var>.</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 C_i \leq 2\times 10^5(1\leq i\leq 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>C_1</var> <var>:</var> <var>C_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible final sequences of colors of the stones, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>We can make three sequences of colors of stones, as follows:</p> <ul> <li><var>(1,2,1,2,2)</var>, by doing nothing.</li> <li><var>(1,1,1,2,2)</var>, by choosing the first and third stones to perform the operation.</li> <li><var>(1,2,2,2,2)</var>, by choosing the second and fourth stones to perform the operation.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 4 2 5 4 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 3 1 2 3 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre></section> </div> </span>
p03583
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var>.</p> <p>Find a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> such that <var>4/N = 1/h + 1/n + 1/w</var>.</p> <p>If there are multiple solutions, any of them will be accepted.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>It is guaranteed that, for the given integer <var>N</var>, there exists a solution such that <var>h,n,w \leq 3500</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> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>Print a triple of positive integers <var>h</var>, <var>n</var> and <var>w</var> that satisfies the condition, in the following format:</p> <pre><var>h</var> <var>n</var> <var>w</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 2 </pre> <p><var>4/2 = 1/1 + 1/2 + 1/2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3485 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>872 1012974 1539173474040 </pre> <p>It is allowed to use an integer exceeding <var>3500</var> in a solution.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4664 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3498 3498 3498 </pre></section> </div> </span>