question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01946
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML"></script> <H1> Slimming Plan </H1> <p> Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight. </p> <p> Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His weight is $S$ on the 0-th day of the plan and he aims to reduce it to $T$ ($S > T$). If his weight on the $i$-th day of the plan is $x$, it will be $x + w_{i\%D}$ on the $(i+1)$-th day. Note that $i\%D$ is the remainder obtained by dividing $i$ by $D$. If his weight successfully gets less than or equal to $T$, he will stop slimming immediately. </p> <p> If his slimming plan takes too many days or even does not end forever, he should reconsider it. </p> <p> Determine whether it ends or not, and report how many days it takes if it ends. </p> <h2>Input</h2> <p> The input consists of a single test case formatted as follows. </p> <pre> $S$ $T$ $D$ $w_0 ... w_{D-1}$ </pre> <p> The first line consists of three integers $S$, $T$, $D$ ($1 \leq S, T, D \leq 100,000, S > T$). The second line consists of $D$ integers $w_0, ..., w_{D-1}$ ($-100,000 \leq w_i \leq 100,000$ for each $i$). </p> <h2>Output</h2> <p> If Chokudai's slimming plan ends on the $d$-th day, print $d$ in one line. If it never ends, print $-1$. </p> <h2>Sample Input 1</h2> <pre> 65 60 3 -2 3 -4 </pre> <h2>Output for Sample Input 1</h2> <pre> 4 </pre> <p> Chokudai's weight will change as follows: $65 \rightarrow 63 \rightarrow 66 \rightarrow 62 \rightarrow 60$. </p> <h2>Sample Input 2</h2> <pre> 65 60 3 -2 10 -3 </pre> <h2>Output for Sample Input 2</h2> <pre> -1 </pre> <p> Chokudai's weight will change as follows: $65 \rightarrow 63 \rightarrow 73 \rightarrow 70 \rightarrow 68 \rightarrow 78 \rightarrow 75 \rightarrow ...$. </p> <h2>Sample Input 3</h2> <pre> 100000 1 1 -1 </pre> <H2>Output for Sample Input 3</H2> <pre> 99999 </pre> <H2>Sample Input 4</H2> <pre> 60 59 1 -123 </pre> <H2>Output for Sample Input 4</H2> <pre> 1 </pre>
p00654
<H1>Problem H: Squid Multiplication</H2> <p> Squid Eiko loves mathematics. Especially she loves to think about integer. One day, Eiko found a math problem from a website. </p> <p> "A sequence <i>b</i> ={<i>a<sub>i</sub></i> + <i>a<sub>j</sub></i> | <i>i</i> &lt <i>j</i> } is generated from a sequence <i>a</i> ={<i>a<sub>0</sub></i> , ... , <i>a<sub>n</sub></i> | <i>a<sub>i</sub></i> is even if <i>i</i> is 0, otherwise <i>a<sub>i</sub></i> is odd}. Given the sequence <i>b</i> , find the sequence <i>a</i> ." </p> <p> This problem is easy for Eiko and she feels boring. So, she made a new problem by modifying this problem . </p> <p> "A sequence <i>b</i> ={<i>a<sub>i</sub></i> *<i>a<sub>j</sub></i> | <i>i</i> &lt; <i>j</i> } is generated from a sequence <i>a</i> ={ <i>a<sub>0</sub></i>, ... , <i>a<sub>n</sub></i> | <i>a<sub>i</sub></i> is even if <i> i </i> is 0, otherwise <i>a<sub>i</sub></i> is odd}. Given the sequence <i>b</i> , find the sequence <i>a</i> ." </p> <p> Your task is to solve the problem made by Eiko. </p> <h2>Input</h2> <p> Input consists of multiple datasets.<br> Each dataset is given by following formats. </p> <pre> <i>n</i> <i>b<sub>0</sub></i> <i>b<sub>1</sub></i> ... <i>b<sub>n*(n+1)/2-1</sub></i> </pre> <p> <i>n</i> is the number of odd integers in the sequence <i>a</i>. The range of <i>n</i> is 2 &le; <i>n</i> &le; 250. <i>b<sub>i</sub></i> is separated by a space. Each <i>b<sub>i</sub></i> is 1 &le; <i>b<sub>i</sub></i> &le; 2<sup>63</sup>-1. The end of the input consists of a single 0. </pre> <h2>Output</h2> <p> For each dataset, you should output two lines. First line contains <i>a<sub>0</sub></i>, an even number in the sequence <i>a</i>. The second line contains <i>n</i> odd elements separated by a space. The odd elements are sorted by increasing order. You can assume that the result is greater than or equal to 1 and less than or equal to 2<sup>31</sup>-1. </p> <h2>Sample input</h2> <pre> 3 6 10 14 15 21 35 2 30 42 35 0 </pre> <h2>Sample output</h2> <pre> 2 3 5 7 6 5 7 </pre>
p02669
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You start with the number <var>0</var> and you want to reach the number <var>N</var>.</p> <p>You can change the number, paying a certain amount of coins, with the following operations:</p> <ul> <li>Multiply the number by <var>2</var>, paying <var>A</var> coins.</li> <li>Multiply the number by <var>3</var>, paying <var>B</var> coins.</li> <li>Multiply the number by <var>5</var>, paying <var>C</var> coins.</li> <li>Increase or decrease the number by <var>1</var>, paying <var>D</var> coins.</li> </ul> <p>You can perform these operations in arbitrary order and an arbitrary number of times.</p> <p>What is the minimum number of coins you need to reach <var>N</var>?</p> <p><strong>You have to solve <var>T</var> testcases.</strong></p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \le T \le 10</var></li> <li><var>1 \le N \le 10^{18}</var></li> <li><var>1 \le A, B, C, D \le 10^9</var></li> <li>All numbers <var>N, A, B, C, D</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input. The first line of the input is</p> <pre><var>T</var> </pre> <p>Then, <var>T</var> lines follow describing the <var>T</var> testcases. Each of the <var>T</var> lines has the format</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each testcase, print the answer on Standard Output followed by a newline.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 11 1 2 4 8 11 1 2 2 8 32 10 8 5 4 29384293847243 454353412 332423423 934923490 1 900000000000000000 332423423 454353412 934923490 987654321 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>20 19 26 3821859835 23441258666 </pre> <p>For the first testcase, a sequence of moves that achieves the minimum cost of <var>20</var> is:</p> <ul> <li>Initially <var>x = 0</var>.</li> <li>Pay <var>8</var> to increase by <var>1</var> (<var>x = 1</var>).</li> <li>Pay <var>1</var> to multiply by <var>2</var> (<var>x = 2</var>).</li> <li>Pay <var>1</var> to multiply by <var>2</var> (<var>x = 4</var>).</li> <li>Pay <var>2</var> to multiply by <var>3</var> (<var>x = 12</var>).</li> <li>Pay <var>8</var> to decrease by <var>1</var> (<var>x = 11</var>).</li> </ul> <p>For the second testcase, a sequence of moves that achieves the minimum cost of <var>19</var> is:</p> <ul> <li>Initially <var>x = 0</var>.</li> <li>Pay <var>8</var> to increase by <var>1</var> (<var>x = 1</var>).</li> <li>Pay <var>1</var> to multiply by <var>2</var> (<var>x = 2</var>).</li> <li>Pay <var>2</var> to multiply by <var>5</var> (<var>x = 10</var>).</li> <li>Pay <var>8</var> to increase by <var>1</var> (<var>x = 11</var>).</li> </ul></section> </div> </span>
p00204
<h1>UFO 撃墜作戦</h1> <p> 40XX 年、地球は宇宙人の侵攻を受けていた!すでに地球のほとんどは宇宙人により制圧されており、残る防衛拠点は鶴ヶ城要塞のみになってしまった。その鶴ヶ城要塞にも、制圧部隊が次々に迫ってきている。<!--3 時間後には最初の戦闘が始まるだろう。このままでは地球最後の砦も制圧されてしまう。--> </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ufo"> </center> <br> <p> しかし、希望は残されている。防衛軍の最終兵器、超長距離貫通レーザー砲が完成したのだ。欠点といえば、 威力が出るまでに一定の距離が必要で、 近すぎる敵はただ通りぬけてしまうということだ。 威力が出ない範囲に侵入した敵は、他の戦力でどうにかするしかない。防衛軍の参謀は、侵入して来た UFO に対処するために、その数を知らなければならないのだが、あまりにも敵が多いせいでうまく数えられそうにない。そこで参謀はあなたに、レーザーに撃墜されなかった UFO の数を出力するプログラムを用意するように命令した。戦闘開始までにプログラムを作成し、鶴ヶ城要塞を守る力となろう。 </p> <p> 敵の UFO はただまっすぐにレーザー砲のある拠点を目指して突撃してくる(UFO には互いにすり抜ける処理が施されており、衝突してしまうことはない) 。レーザー砲は、初期状態から 1 分後に最も近い UFO の中心を狙ってレーザーを発射し始め、それから 1 分ごとに同じ条件でレーザーを発射し続ける。レーザーは貫通し、その先にある UFO もレーザーがかすっただけで撃墜することができる。しかし、このレーザーには威力の出ない範囲があり、その範囲に入ってしまったUFO は狙っても意味がないため、狙わないように設計されている。撃墜できるだけ撃墜したとき、レーザーの威力が出ない範囲には何機の UFO が侵入しただろうか。 </p> <p> レーザーの威力が出ない範囲の半径 <var>R</var> と、襲来する UFO の情報を入力とし、撃墜されず侵入している UFO が何機いるかを出力するプログラムを作成してください。 襲来する UFO の情報は、UFO の数 <var>N</var> 、各 UFO の初期座標 (<var>x0, y0</var>)、各 UFO の半径 <var>r</var> 、各 UFO の分速 <var>v</var> で構成されます。 </p> <p> 座標の原点 (0 , 0) をレーザー砲の位置とします。レーザー砲と UFO の距離は原点から UFO の中心までの距離で与えられ、この距離が <var>R</var> 以下の UFO はレーザーの威力が出ない範囲に入ったとします。狙うべき対象が同時に複数存在する場合はないものとして考えます。計算は全て平面上で考え、入力はすべて整数で与えられます。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。 入力の終わりはゼロふたつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>R</var> <var>N</var> <var>x0<sub>1</sub></var> <var>y0<sub>1</sub></var> <var>r<sub>1</sub></var> <var>v<sub>1</sub></var> <var>x0<sub>2</sub></var> <var>y0<sub>2</sub></var> <var>r<sub>2</sub></var> <var>v<sub>2</sub></var> : <var>x0<sub>N</sub></var> <var>y0<sub>N</sub></var> <var>r<sub>N</sub></var> <var>v<sub>N</sub></var> </pre> <p> 1 行目にレーザーの威力が出ない範囲の半径 <var>R</var> (1 &le; <var>R</var> &le; 500) とUFO の数 <var>N</var> (1 &le; <var>N</var> &le; 100) が与えられます。続く <var>N</var> 行に <var>i</var> 機目の UFO の情報 <var>x0<sub>i</sub></var>, <var>y0<sub>i</sub></var> (-100 &le; <var>x0<sub>i</sub></var>, <var>y0<sub>i</sub></var> &le; 1000), <var>r<sub>i</sub></var>, <var>v<sub>i</sub></var> (1 &le; <var>r<sub>i</sub></var>, <var>v<sub>i</sub></var> &le; 500) が与えられます。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 入力データセットごとに、レーザーの威力が出ない範囲に侵入した UFO の数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 100 5 101 101 5 5 110 110 2 3 -112 -100 9 11 -208 160 82 90 -110 108 10 2 10 11 15 0 5 1 25 0 5 1 35 0 5 1 45 0 5 1 55 0 5 1 65 0 5 1 75 0 5 1 85 0 5 1 95 0 5 1 -20 0 5 20 -30 0 500 5 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 1 </pre>
p02239
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Breadth First Search</H1> <p> Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$. </p> <H2>Input</H2> <p> In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: </p> <p> $u$ $k$ $v_1$ $v_2$ ... $v_k$ </p> <p> $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$. </p> <H2>Constraints</H2> <ul> <li>$1 \leq n \leq 100$</li> </ul> <H2>Output</H2> <p> For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs. </p> <H2>Sample Input 1</H2> <pre> 4 1 2 2 4 2 1 4 3 0 4 1 3 </pre> <H2>Sample Output 1</H2> <pre> 1 0 2 1 3 2 4 1 </pre> <br> <H2>Reference</H2> <p> Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. </p>
p02147
<h1>Problem K: A Polygon And Circles</h1> <h2>Problem</h2> <p>$N$個の頂点からなる凸多角形と$M$個の円の中心座標が与えられる。すべての円の半径は$r$である。</p> <p>以下の条件を満たす最小の実数$r$を求めたい。</p> <p>条件: 凸多角形の内部のどの点も、少なくとも一つ以上の円に内包されている。</p> <p></p> <h2>Input</h2> <p>入力は以下の形式ですべて整数で与えられる。</p> <pre> $N$ $px_1$ $py_1$ $px_2$ $py_2$ : $px_N$ $py_N$ $M$ $cx_1$ $cy_1$ $cx_2$ $cy_2$ : $cx_M$ $cy_M$ </pre> <p> $1$行目には凸多角形の頂点数を表す整数$N$が与えられる。<br> $2$行目から$2+N-1$行目には凸多角形の各頂点の情報が反時計周りの順で与えられる。$1+i$行目には$i$番目の頂点の座標を表す$px_i$ $py_i$が空白区切りで与えられる。<br> $2+N$行目には円の数を表す整数$M$が与えられる。<br> $2+N+1$行目から$2+N+M$行には円の中心座標の情報が与えられる。$2+N+i$行目には$i$番目の円の中心座標を表す$cx_i$ $cy_i$が空白区切りで与えられる。 </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$3 \le N \le 100$</li> <li>$1 \le M \le 100$</li> <li>$-10^5 \le px_i, py_i \le 10^5$</li> <li>$-10^5 \le cx_i, cy_i \le 10^5$</li> <li>凸多角形の頂点のうちどの3点を選んでも、同一直線上には存在しない</li> </ul> <h2>Output</h2> <p> 条件を満たす最小の円の半径 $r$ を出力する。<br> ただし、$10^{-5}$ までの絶対誤差または相対誤差は許容される。 </p> <h2>Sample Input 1</h2> <pre> 4 2 3 1 2 2 1 3 2 4 1 3 1 1 3 3 3 1 </pre> <h2>Sample Output 1</h2> <pre> 1.414213562373 </pre> <h2>Sample Input 2</h2> <pre> 7 -96469 25422 -55204 -45592 -29140 -72981 98837 -86795 92303 63297 19059 96012 -67980 70342 17 -4265 -14331 33561 72343 52055 98952 -71189 60872 10459 -7512 -11981 57756 -78228 -28044 37397 -69980 -27527 -51966 22661 -16694 13759 -59976 86539 -47703 17098 31709 -62497 -70998 -57608 59799 -1904 -35574 -73860 121 </pre> <h2>Sample Output 2</h2> <pre> 75307.220122044484 </pre>
p00480
<H1>1年生 (A First Grader)</H1> <h2>問題</h2> <p> JOI君は小学 1 年生である.JOI君は教わったばかりの足し算,引き算がとても好きで,数字が並んでいるのを見ると最後の 2 つの数字の間に「=」を入れ,残りの数字の間に必ず「+」または「-」を入れて等式を作って遊んでいる.例えば「8 3 2 4 8 7 2 4 0 8 8」から,等式「8+3-2-4+8-7-2-4-0+8=8」を作ることができる. </p> <p> JOI 君は等式を作った後,それが正しい等式になっているかを計算して確かめる.ただし,JOI君はまだ負の数は知らないし,20 を超える数の計算はできない.したがって,正しい等式のうち左辺を左から計算したとき計算の途中で現れる数が全て 0 以上 20 以下の等式だけがJOI君が確かめられる正しい等式である.例えば,「8+3-2-4-8-7+2+4+0+8=8」は 正しい等式だが,途中に現れる 8+3-2-4-8 が負の数なのでJOI君はこの等式が正しいかどうか確かめることができない. </p> <p> 入力として数字の列が与えられたとき,JOI君が作り,確かめることができる正しい等式の個数を求めるプログラムを作成せよ. </p> <h2>入力</h2> <p> 入力ファイルは 2 行からなる.1 行目には並んでいる数字の個数を表す整数 N (3 &le; N &le; 100)が書かれている.2 行目には 0 以上 9 以下の整数が N 個,空白を区切りとして書かれている. </p> <p> 与えられる入力データの 60% では,JOI君が作り,確かめることができる正しい等式の個数は 2<sup>31</sup>-1 を超えない.また,与えられる入力データの全てにおいて,JOI君が作り,確かめることができる正しい等式の個数は 2<sup>63</sup>-1 を超えない. </p> <h2>出力</h2> <p> JOI君が作り,確かめることができる正しい等式の個数を表す整数を 1 行で出力せよ. </p> <h2>入出力例</h2> <h3>入力例 1</h3> <pre> 11 8 3 2 4 8 7 2 4 0 8 8 </pre> <h3>出力例 1</h3> <pre> 10 </pre> <p> 入力例 1 において,JOI君は 10 個の正しい等式 </p> <pre> 8+3-2-4+8-7-2-4-0+8=8 8+3-2-4+8-7-2-4+0+8=8 8+3+2+4-8-7+2-4-0+8=8 8+3+2+4-8-7+2-4+0+8=8 8+3-2-4+8-7+2+4-0-8=8 8+3-2-4+8-7+2+4+0-8=8 8-3+2+4-8+7+2+4-0-8=8 8-3+2+4-8+7+2+4+0-8=8 8-3+2-4+8+7+2-4-0-8=8 8-3+2-4+8+7+2-4+0-8=8 </pre> <p> を作り,確かめることができるので 10 を出力する. </p> <h3>入力例 2</h3> <pre> 40 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 </pre> <h3>出力例 2</h3> <pre> 7069052760 </pre> <p> 入力例 2 において,答えが 32 bit符号付き整数の範囲に収まらないことに注意せよ. </p> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div> <br>
p03306
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Kenkoooo found a simple connected graph. The vertices are numbered <var>1</var> through <var>n</var>. The <var>i</var>-th edge connects Vertex <var>u_i</var> and <var>v_i</var>, and has a fixed integer <var>s_i</var>.</p> <p>Kenkoooo is trying to write a <em>positive integer</em> in each vertex so that the following condition is satisfied:</p> <ul> <li>For every edge <var>i</var>, the sum of the positive integers written in Vertex <var>u_i</var> and <var>v_i</var> is equal to <var>s_i</var>.</li> </ul> <p>Find the number of such ways to write positive integers in the vertices.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq n \leq 10^5</var></li> <li><var>1 \leq m \leq 10^5</var></li> <li><var>1 \leq u_i &lt; v_i \leq n</var></li> <li><var>2 \leq s_i \leq 10^9</var></li> <li>If <var>i\neq j</var>, then <var>u_i \neq u_j </var> or <var>v_i \neq v_j</var>.</li> <li>The graph is connected.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>n</var> <var>m</var> <var>u_1</var> <var>v_1</var> <var>s_1</var> <var>:</var> <var>u_m</var> <var>v_m</var> <var>s_m</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to write positive integers in the vertices so that the condition is satisfied.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 3 2 3 5 1 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>The condition will be satisfied if we write <var>1,2</var> and <var>3</var> in vertices <var>1,2</var> and <var>3</var>, respectively. There is no other way to satisfy the condition, so the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 1 2 6 2 3 7 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>Let <var>a,b,c</var> and <var>d</var> be the numbers to write in vertices <var>1,2,3</var> and <var>4</var>, respectively. There are three quadruples <var>(a,b,c,d)</var> that satisfy the condition:</p> <ul> <li><var>(a,b,c,d)=(1,5,2,3)</var></li> <li><var>(a,b,c,d)=(2,4,3,2)</var></li> <li><var>(a,b,c,d)=(3,3,4,1)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 7 1 2 1000000000 2 3 2 3 4 1000000000 4 5 2 5 6 1000000000 6 7 2 7 8 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p03756
<span class="lang-en lang-child hidden-lang"> <div class="part"> Max Score: <var>1150</var> Points <br/> <font color="red">Task statement was updated.</font> <section> <h3>Problem Statement</h3> There is a grid which size is $H \times W$. the upper-left cell is $(1,1)$ and the lower-right cell is $(H,W)$.<br/> There is $N$ arrows. Arrow which start point is $(a_i,b_i)$ of direction is $c_i$, and size is $d_i$. ($d_i$ may be negative)<br/> It is guaranteed that there are no two arrow which start point is same.<br/> <br/> Sothe want to move from cell $(sx,sy)$ to cell $(gx,gy)$ with arrows.<br/> But it may not possible to move to goal in initial grid.<br/> So, Snuke decided to change some arrows.<br/> <br/> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/5eff69da8ebd635a501515b7f86a47e6.png" width="500"/> </div> Sothe can change each arrow as follows:<br/> <ul> <li>He can't change the start point of this arrow.</li> <li>It costs $e_i$ if he change the direction of this arrow.</li> <li>It costs $f \times |d_i-G|$ if he change <var>d_i</var> to $G$.</li> </ul> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/532f821bbe6594a29e622d7a81cbcad7.png" width="700"/> </div><br/> He can't add or erase arrows.<br/> <br/> Please calculate the minimum cost that he can move to $(gx,gy)$.<br/><h3> If he can't move to goal, please output '-1'.</h3> Note: Arrows are directed, and he can't turn in the middle of the arrow.<br/> </section> </div> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> The input is given from standard input in the following format. <br/> <br/> <pre> <var>H</var> <var>W</var> <var>N</var> <var>f</var> <var>sx</var> <var>sy</var> <var>gx</var> <var>gy</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> <var>d_1</var> <var>e_1</var> <var>a_2</var> <var>b_2</var> <var>c_2</var> <var>d_2</var> <var>e_2</var> : : : <var>a_N</var> <var>b_N</var> <var>c_N</var> <var>d_N</var> <var>e_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <ul> <li>Please output a single integer: The minimum cost to clear this puzzle.</li> <li>If you can't achieve the objective, print <code>-1</code>.</li> <li>Print <code>\n</code> (line break) in the end.</li> </ul> </section> <section> <h3>Constraints</h3> <ul> <li>$1 \le H,W \le 100000$</li> <li>$1 \le N \le 70000$</li> <li>$1 \le f,e_i \le 1000000$</li> <li>$1 \le d_i \le 100000$</li> <li>$1 \le a_i,sx,tx \le H$</li> <li>$1 \le b_i,sy,ty \le W$</li> <li>$c_i$ is <code>N</code>, <code>E</code>, <code>S</code>, or <code>W</code>, which means North, East, South, West.</li> </ul> </section> <section> <h3>Subtasks</h3> <p>Subtask 1 [ <var>190</var> points ]</p> <ul> <li>$H=1$</li> <li>$W \le 600$</li> </ul> <p>Subtask 2 [ <var>170</var> points ]</p> <ul> <li>$H,W \le 80$</li> </ul> <p>Subtask 3 [ <var>360</var> points ]</p> <ul> <li>$H,W \le 600$</li> </ul> <p>Subtask 4 [ <var>430</var> points ]</p> <ul> <li>There is no additional constraints.</li> </ul> </section> </div> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 4 4 2 2 1 1 2 2 1 1 E 1 1 1 2 E 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 4 </pre> </section> </div> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/6c5665931a6f8044048238e0a68bf17c.png" width="500"/> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 1 4 2 10 1 1 1 4 1 1 E 1 4 1 3 W 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 14 </pre> </section> </div> <div class="part"> <section> <h3>Sample Input 3</h3> <pre> 1 8 4 9 1 3 1 6 1 1 E 7 2 1 8 W 7 5 1 3 W 2 5 1 6 E 2 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3> <pre> 14 </pre> </section> </div> <div class="part"> <h3>Sample Input 4</h3> <pre> 5 5 7 10 1 2 4 5 1 2 E 2 6 2 3 S 2 7 3 1 N 1 8 3 2 W 1 10 4 1 E 4 12 5 5 N 3 13 5 1 E 2 14 </pre> </div></span>
p02844
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>AtCoder Inc. has decided to lock the door of its office with a <var>3</var>-digit PIN code.</p> <p>The company has an <var>N</var>-digit lucky number, <var>S</var>. Takahashi, the president, will erase <var>N-3</var> digits from <var>S</var> and concatenate the remaining <var>3</var> digits without changing the order to set the PIN code.</p> <p>How many different PIN codes can he set this way?</p> <p>Both the lucky number and the PIN code may begin with a <var>0</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>4 \leq N \leq 30000</var></li> <li><var>S</var> is a string of length <var>N</var> consisting of digits.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of different PIN codes Takahashi can set.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 0224 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>Takahashi has the following options:</p> <ul> <li>Erase the first digit of <var>S</var> and set <code>224</code>.</li> <li>Erase the second digit of <var>S</var> and set <code>024</code>.</li> <li>Erase the third digit of <var>S</var> and set <code>024</code>.</li> <li>Erase the fourth digit of <var>S</var> and set <code>022</code>.</li> </ul> <p>Thus, he can set three different PIN codes: <code>022</code>, <code>024</code>, and <code>224</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 123123 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>17 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>19 3141592653589793238 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>329 </pre></section> </div> </span>
p00879
<H1><font color="#000">Problem F:</font> Chemist's Math</H1> <p> You have probably learnt chemical equations (chemical reaction formulae) in your high-school days. The following are some well-known equations. </p> <pre><font face="Times New Roman"> 2H<sub>2</sub> + O<sub>2</sub> &rarr; 2H<sub>2</sub>O (1) C<sub>a</sub>(OH)<sub>2</sub> + CO<sub>2</sub> &rarr; C<sub>a</sub>CO<sub>3</sub> + H<sub>2</sub>O (2) N<sub>2</sub> + 3H<sub>2</sub> &rarr; 2NH<sub>3</sub> (3) </font> </pre> <p> While Equations (1)–(3) all have balanced left-hand sides and right-hand sides, the following ones do not. </p> <pre> <font face="Times New Roman"> Al + O<sub>2</sub> &rarr; Al<sub>2</sub>O<sub>3</sub> (<i>wrong</i>) (4) C<sub>3</sub>H<sub>8</sub> + O<sub>2</sub> &rarr; CO<sub>2</sub> + H<sub>2</sub>O (<i>wrong</i>) (5) </font> </pre> <p> The equations must follow <i>the law of conservation of mass</i>; the quantity of each chemical element (such as H, O, Ca, Al) should not change with chemical reactions. So we should "adjust" the numbers of molecules on the left-hand side and right-hand side: </p> <pre> <font face="Times New Roman"> 4Al + 3O<sub>2</sub> &rarr; 2Al<sub>2</sub>O<sub>3</sub> (<i>correct</i>) (6) C<sub>3</sub>H<sub>8</sub> + 5O<sub>2</sub> &rarr; 3CO<sub>2</sub> + 4H<sub>2</sub>O (correct) (7) </font> </pre> <p> The coefficients of Equation (6) are (4, 3, 2) from left to right, and those of Equation (7) are (1, 5, 3, 4) from left to right. Note that the coefficient 1 may be omitted from chemical equations. </p> <p> The coefficients of a <i>correct</i> equation must satisfy the following conditions. </p> <ol> <li> The coefficients are all positive integers.</li> <li> The coefficients are relatively prime, that is, their greatest common divisor (g.c.d.) is 1.</li> <li> The quantities of each chemical element on the left-hand side and the right-hand side are equal.</li> </ol> <p> Conversely, if a chemical equation satisfies the above three conditions, we regard it as a correct equation, no matter whether the reaction or its constituent molecules can be chemically realized in the real world, and no matter whether it can be called a reaction (e.g., H<sub>2</sub> &rarr; H<sub>2</sub> is considered correct). A chemical equation satisfying Conditions 1 and 3 (but not necessarily Condition 2) is called a <i>balanced</i> equation. </p> <p> Your goal is to read in chemical equations with missing coefficients like Equation (4) and (5), line by line, and output the sequences of coefficients that make the equations correct. </p> <p> Note that the above three conditions do not guarantee that a correct equation is uniquely determined. For example, if we "mix" the reactions generating H<sub>2</sub>O and NH<sub>3</sub> , we would get </p> <pre><font face="Times New Roman"> <i>x</i>H<sub>2</sub> + <i>y</i>O<sub>2</sub> + <i>z</i>N<sub>2</sub> + <i>u</i>H<sub>2</sub> &rarr; <i>v</i>H<sub>2</sub>O + <i>w</i>NH<sub>3</sub> (8) </font></pre> <p> but (<i>x</i>, <i>y</i>, <i>z</i>, <i>u</i>, <i>v</i>, <i>w</i>) = (2, 1, 1, 3, 2, 2) does not represent a unique correct equation; for instance, (4, 2, 1, 3, 4, 2) and (4, 2, 3, 9, 4, 6) are also "correct" according to the above definition! However, we guarantee that every chemical equation we give you will lead to a <i>unique</i> correct equation by adjusting their coefficients. In other words, we guarantee that (i) every chemical equation can be balanced with positive coefficients, and that (ii) <i>all</i> balanced equations of the original equation can be obtained by multiplying the coefficients of a unique correct equation by a positive integer. </p> <H2>Input</H2> <p> The input is a sequence of chemical equations (without coefficients) of the following syntax in the Backus-Naur Form: </p> <pre> &lt;chemical_equation&gt; ::= &lt;molecule_sequence&gt; "-&gt;" &lt;molecule_sequence&gt; &lt;molecule_sequence&gt; ::= &lt;molecule&gt; | &lt;molecule&gt; "+" &lt;molecule_sequence&gt; &lt;molecule&gt; ::= &lt;group&gt; | &lt;group&gt; &lt;molecule&gt; &lt;group&gt; ::= &lt;unit_group&gt; | &lt;unit_group&gt; &lt;number&gt; &lt;unit_group&gt; ::= &lt;chemical_element&gt; | "(" &lt;molecule&gt; ")" &lt;chemical_element&gt; ::= &lt;uppercase_letter&gt; | &lt;uppercase_letter&gt; &lt;lowercase_letter&gt; &lt;uppercase_letter&gt; ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" &lt;lowercase_letter&gt; ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" &lt;number&gt; ::= &lt;non_zero_digit&gt; | &lt;non_zero_digit&gt; &lt;digit&gt; &lt;non_zero_digit&gt; ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | &lt;digit&gt; ::= "0" | &lt;non_zero_digit&gt; </pre> <p> Each chemical equation is followed by a period and a newline. No other characters such as spaces do not appear in the input. For instance, the equation </p> <pre> <font face="Times New Roman"> C<sub>a</sub>(OH)<sub>2</sub> + CO<sub>2</sub> &rarr; C<sub>a</sub>CO<sub>3</sub> + H<sub>2</sub>O </font></pre> <p> is represented as </p> <pre> Ca(OH)2+CO2->CaCO3+H2O. </pre> <p> Each chemical equation is no more than 80 characters long, and as the above syntax implies, the &lt;number&gt;'s are less than 100. Parentheses may be used but will not be nested (maybe a good news to some of you!). Each side of a chemical equation consists of no more than 10 top-level molecules. The coefficients that make the equations correct will not exceed 40000. The chemical equations in the input have been chosen so that 32-bit integer arithmetic would suffice with appropriate precautions against possible arithmetic overflow. You are free to use 64-bit arithmetic, however. </p> <p> The end of the input is indicated by a line consisting of a single period. </p> <p> Note that our definition of &lt;chemical_element&gt; above allows chemical elements that do not exist or unknown as of now, and excludes known chemical elements with three-letter names (e.g., ununbium (Uub), with the atomic number 112). </p> <H2>Output</H2> <p> For each chemical equation, output a line containing the sequence of positive integer coefficients that make the chemical equation <i>correct</i>. Numbers in a line must be separated by a single space. No extra characters should appear in the output. </p> <H2>Sample Input</H2> <pre> N2+H2->NH3. Na+Cl2->NaCl. Ca(OH)2+CO2->CaCO3+H2O. CaCl2+AgNO3->Ca(NO3)2+AgCl. C2H5OH+O2->CO2+H2O. C4H10+O2->CO2+H2O. A12B23+C34D45+ABCD->A6D7+B8C9. A98B+B98C+C98->A98B99C99. A2+B3+C5+D7+E11+F13->ABCDEF. . </pre> <H2>Output for the Sample Input</H2> <pre> 1 3 2 2 1 2 1 1 1 1 1 2 1 2 1 3 2 3 2 13 8 10 2 123 33042 5511 4136 1 1 1 1 15015 10010 6006 4290 2730 2310 30030 </pre>
p01291
<H1><font color="#000">Problem I:</font> Wind Passages</H1> <p> Wind Corridor is a covered passageway where strong wind is always blowing. It is a long corridor of width W, and there are several pillars in it. Each pillar is a right prism and its face is a polygon (not necessarily convex). </p> <p> In this problem, we consider two-dimensional space where the positive <i>x</i>-axis points the east and the positive <i>y</i>-axis points the north. The passageway spans from the south to the north, and its length is infinity. Specifically, it covers the area 0 &le; <i>x</i> &le; <i>W</i>. The outside of the passageway is filled with walls. Each pillar is expressed as a polygon, and all the pillars are located within the corridor without conflicting or touching each other. </p> <p> Wind blows from the south side of the corridor to the north. For each second, <i>w</i> unit volume of air can be flowed at most if the minimum width of the path of the wind is <i>w</i>. Note that the path may fork and merge, but never overlaps with pillars and walls. </p> <p> Your task in this problem is to write a program that calculates the maximum amount of air that can be flowed through the corridor per second. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> The first line of the input contains two integers <i>W</i> and <i>N</i>. <i>W</i> is the width of the corridor, and <i>N</i> is the number of pillars. <i>W</i> and <i>N</i> satisfy the following condition: 1 &le; <i>W</i> &le; 10<sup>4</sup> and 0 &le; <i>N</i> &le; 200. </p> <p> Then, <i>N</i> specifications of each pillar follow. Each specification starts with a line that contains a single integer <i>M</i>, which is the number of the vertices of a polygon (3 &le; <i>M</i> &le; 40). The following <i>M</i> lines describe the shape of the polygon. The <i>i</i>-th line (1 &le; <i>i</i> &le; <i>M</i>) contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> that denote the coordinate of the <i>i</i>-th vertex (0 &lt; <i>x<sub>i</sub></i> &lt; <i>W</i>, 0 &lt; <i>y<sub>i</sub></i> &lt; 10<sup>4</sup>). </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, your program should print a line that contains the maximum amount of air flow per second, in unit volume. The output may contain arbitrary number of digits after the decimal point, but the absolute error must not exceed 10<sup>-6</sup>. </p> <H2>Sample Input</H2> <pre> 5 2 4 1 1 1 2 2 2 2 1 4 3 3 3 4 4 4 4 3 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3.41421356 </pre>
p01784
<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>E - Parentheses</h2> <h3>Problem Statement</h3> <p> You are given $n$ strings $\mathit{str}_1, \mathit{str}_2, \ldots, \mathit{str}_n$, each consisting of <code>(</code> and <code>)</code>. The objective is to determine whether it is possible to permute the $n$ strings so that the concatenation of the strings represents a <i>valid</i> string. </p> <p> Validity of strings are defined as follows: </p> <ul> <li> The empty string is valid. </li> <li> If $A$ and $B$ are valid, then the concatenation of $A$ and $B$ is valid. </li> <li> If $A$ is valid, then the string obtained by putting $A$ in a pair of matching parentheses is valid. </li> <li> Any other string is not valid. </li> </ul> <p> For example, "()()" and "(())" are valid, while "())" and "((()" are not valid. </p> <h3>Input</h3> <p> The first line of the input contains an integer $n$ ($1 \leq n \leq 100$), representing the number of strings. Then $n$ lines follow, each of which contains $\mathit{str}_i$ ($1 \leq \lvert \mathit{str}_i \rvert \leq 100$). All characters in $\mathit{str}_i$ are <code>(</code> or <code>)</code>. </p> <h3>Output</h3> <p> Output a line with "Yes" (without quotes) if you can make a valid string, or "No" otherwise. </p> <h3>Sample Input 1</h3> <pre>3 ()(()(( ))()()(() )())(())</pre> <h3>Output for the Sample Input 1</h3> <pre>Yes</pre> <h3>Sample Input 2</h3> <pre>2 ))()(( ))((())(</pre> <h3>Output for the Sample Input 2</h3> <pre>No</pre>
p00896
<H1><font color="#000">Problem C: </font>Weaker than Planned </H1> <p> The committee members of the Kitoshima programming contest had decided to use crypto-graphic software for their secret communication. They had asked a company, Kodai Software, to develop cryptographic software that employed a cipher based on highly sophisticated mathematics. </p> <p> According to reports on IT projects, many projects are not delivered on time, on budget, with required features and functions. This applied to this case. Kodai Software failed to implement the cipher by the appointed date of delivery, and asked to use a simpler version that employed a type of substitution cipher for the moment. The committee members got angry and strongly requested to deliver the full specification product, but they unwillingly decided to use this inferior product for the moment. </p> <p> In what follows, we call the text before encryption, plaintext, and the text after encryption,<i> ciphertext</i>. </p> <p> This simple cipher substitutes letters in the plaintext, and its substitution rule is specified with a set of pairs. A pair consists of two letters and is unordered, that is, the order of the letters in the pair does not matter. A pair (A, B) and a pair (B, A) have the same meaning. In one substitution rule, one letter can appear in at most one single pair. When a letter in a pair appears in the plaintext, the letter is replaced with the other letter in the pair. Letters not specified in any pairs are left as they are. </p> <p> For example, by substituting the plaintext </p> <pre> ABCDEFGHIJKLMNOPQRSTUVWXYZ </pre> <p> with the substitution rule {(A, Z), (B, Y)} results in the following ciphertext. </p> <pre> ZYCDEFGHIJKLMNOPQRSTUVWXBA </pre> <p> This may be a big chance for us, because the substitution rule seems weak against cracking. We may be able to know communications between committee members. The mission here is to develop a deciphering program that finds the plaintext messages from given ciphertext messages. </p> <p> A ciphertext message is composed of one or more ciphertext words. A ciphertext word is generated from a plaintext word with a substitution rule. You have a list of candidate words containing the words that can appear in the plaintext; no other words may appear. Some words in the list may not actually be used in the plaintext. </p> <p> There always exists at least one sequence of candidate words from which the given ciphertext is obtained by some substitution rule. There may be cases where it is impossible to uniquely identify the plaintext from a given ciphertext and the list of candidate words. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each of which contains a ciphertext message and a list of candidate words in the following format. </p> <p> <i>n</i><br> <i>word</i><sub>1</sub><br> .<br> .<br> .<br> <i>word</i><sub>n</sub><br> <i>sequence</i> </p> <p> <i>n</i> in the first line is a positive integer, representing the number of candidate words. Each of the next <i>n</i> lines represents one of the candidate words. The last line, sequence, is a sequence of one or more ciphertext words separated by a single space and terminated with a period. </p> <p> You may assume the number of characters in each <i>sequence</i> is more than 1 and less than or equal to 80 including spaces and the period. The number of candidate words in the list, <i>n</i>, does not exceed 20. Only 26 uppercase letters, A to Z, are used in the words and the length of each word is from 1 to 20, inclusive. </p> <p> A line of a single zero indicates the end of the input. </p> <H2>Output</H2> <p> For each dataset, your program should print the deciphered message in a line. Two adjacent words in an output line should be separated by a single space and the last word should be followed by a single period. When it is impossible to uniquely identify the plaintext, the output line should be a single hyphen followed by a single period. </p> <H2>Sample Input</H2> <pre> 4 A AND CAT DOG Z XUW ZVX Z YZT. 2 AZ AY ZA. 2 AA BB CC. 16 A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO. 0 </pre> <H2>Output for the Sample Input</H2> <pre> A DOG AND A CAT. AZ. -. A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO. </pre>
p03243
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Kurohashi has never participated in AtCoder Beginner Contest (ABC).</p> <p>The next ABC to be held is ABC <var>N</var> (the <var>N</var>-th ABC ever held). Kurohashi wants to make his debut in some ABC <var>x</var> such that all the digits of <var>x</var> in base ten are the same.</p> <p>What is the earliest ABC where Kurohashi can make his debut?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>100 \leq N \leq 999</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the earliest ABC where Kurohashi can make his debut is ABC <var>n</var>, print <var>n</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>111 </pre> <p>The next ABC to be held is ABC <var>111</var>, where Kurohashi can make his debut.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>112 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>222 </pre> <p>The next ABC to be held is ABC <var>112</var>, which means Kurohashi can no longer participate in ABC <var>111</var>. Among the ABCs where Kurohashi can make his debut, the earliest one is ABC <var>222</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>750 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>777 </pre></section> </div> </span>
p03613
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>, <var>a_1,a_2,...,a_N</var>.</p> <p>For each <var>1≤i≤N</var>, you have three choices: add <var>1</var> to <var>a_i</var>, subtract <var>1</var> from <var>a_i</var> or do nothing.</p> <p>After these operations, you select an integer <var>X</var> and count the number of <var>i</var> such that <var>a_i=X</var>.</p> <p>Maximize this count by making optimal choices.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤N≤10^5</var></li> <li><var>0≤a_i&lt;10^5 (1≤i≤N)</var></li> <li><var>a_i</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>N</var> <var>a_1</var> <var>a_2</var> .. <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible number of <var>i</var> such that <var>a_i=X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 3 1 4 1 5 9 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>For example, turn the sequence into <var>2,2,3,2,6,9,2</var> and select <var>X=2</var> to obtain <var>4</var>, the maximum possible count.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 0 1 2 3 4 5 6 7 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 99999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre></section> </div> </span>
p02901
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> locked treasure boxes, numbered <var>1</var> to <var>N</var>.</p> <p>A shop sells <var>M</var> keys. The <var>i</var>-th key is sold for <var>a_i</var> yen (the currency of Japan), and it can unlock <var>b_i</var> of the boxes: Box <var>c_{i1}</var>, <var>c_{i2}</var>, <var>...</var>, <var>c_{i{b_i}}</var>. Each key purchased can be used any number of times.</p> <p>Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print <var>-1</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 12</var></li> <li><var>1 \leq M \leq 10^3</var></li> <li><var>1 \leq a_i \leq 10^5</var></li> <li><var>1 \leq b_i \leq N</var></li> <li><var>1 \leq c_{i1} &lt; c_{i2} &lt; ... &lt; c_{i{b_i}} \leq N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>c_{11}</var> <var>c_{12}</var> <var>...</var> <var>c_{1{b_1}}</var> <var>:</var> <var>a_M</var> <var>b_M</var> <var>c_{M1}</var> <var>c_{M2}</var> <var>...</var> <var>c_{M{b_M}}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print <var>-1</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 10 1 1 15 1 2 30 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>25 </pre> <p>We can unlock all the boxes by purchasing the first and second keys, at the cost of <var>25</var> yen, which is the minimum cost required.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>12 1 100000 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>We cannot unlock all the boxes.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 6 67786 3 1 3 4 3497 1 2 44908 3 2 3 4 2156 3 2 3 4 26230 1 2 86918 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>69942 </pre></section> </div> </span>
p00195
<h1>人気の出店は?</h1> <table> <tr> <td valign="top" style="vertical-align:top"> <p> 会津若松市では、毎年1月10日に「十日市」という初市があります。この十日市は、約600年の歴史があり会津地方最大の初市です。会津地方ではお馴染みの縁起物である、起き上がり小法師(おきあがりこぼし)が売られていることでもよく知られています。起き上がり小法師は、大きさ3cm 程度の重心が底にある張り子で、転がしてもすぐに起きあがることからこの名前が付きました。各家庭では、必ず家族より一個多く買って神棚に供えます。この一個は、 「家族が増えるように」や「厄を背負ってくれる」との意味があります。 </p> </td> <td valign="top" style="vertical-align:top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_tokaichi"> </td> </tr> </table> <br/> <p> 十日市実行委員会では、次回の十日市に向けて、起き上がり小法師の販売個数が一番多い出店を調べることになりました。今年の出店の数は5店(A、B、C、D、E:半角英字)で、販売個数は、午前と午後に分けて十日市実行委員会に報告されています。 </p> <p> 各出店の情報を入力とし、一日の販売個数が一番多い出店の名前とその個数を出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>s1<sub>A</sub></var> <var>s2<sub>A</sub></var> <var>s1<sub>B</sub></var> <var>s2<sub>B</sub></var> <var>s1<sub>C</sub></var> <var>s2<sub>C</sub></var> <var>s1<sub>D</sub></var> <var>s2<sub>D</sub></var> <var>s1<sub>E</sub></var> <var>s2<sub>E</sub></var> </pre> <p> <var>i</var> 行目に、それぞれA, B, C, D, E の午前の販売個数 <var>s1<sub>i</sub></var> と午後の販売個数 <var>s2<sub>i</sub></var> (1 &le; <var>s1<sub>i</sub></var>, <var>s2<sub>i</sub></var> &le; 10000) が与えられます。ただし、一日の販売個数が同じ出店は無いものとします。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> データセットごとに、一日の販売個数の一番多い出店の名前とその個数を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 1593 4311 4321 2155 1256 6421 5310 1455 2152 5421 1549 3386 4528 3719 1234 4321 3330 3109 2739 2199 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> C 7677 B 8247 </pre>
p02452
<h1>Includes</h1> <p> For given two sequneces $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$, determine whether all elements of $B$ are included in $A$. Note that, elements of $A$ and $B$ are sorted by ascending order respectively. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1 \; ,..., \; a_{n-1}$ $m$ $b_0 \; b_1 \; ,..., \; b_{m-1}$ </pre> <p> The number of elements in $A$ and its elements $a_i$ are given in the first and second lines respectively. The number of elements in $B$ and its elements $b_i$ are given in the third and fourth lines respectively. </p> <h2>Output</h2> <p> Print <span>1</span>, if $A$ contains all elements of $B$, otherwise <span>0</span>. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n, m \leq 200,000$</li> <li>$-1,000,000,000 \leq a_0 < a_1 < ... < a_{n-1} \leq 1,000,000,000$</li> <li>$-1,000,000,000 \leq b_0 < b_1 < ... < b_{m-1} \leq 1,000,000,000$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 1 2 3 4 2 2 4 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 4 1 2 3 4 3 1 2 5 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre>
p02002
<h1>G: 式の切り取り</h1> <h2>問題</h2> <p> 長さ $N$ の数式 $S$ が与えられる。 数式は、以下の BNF で示される形式になっている。 </p> <pre> &lt;expr&gt; ::= &lt;number&gt; | &lt;expr&gt; &lt;op&gt; &lt;expr&gt; <br> &lt;op&gt; ::= ‘^’ | ‘&’ | ‘|’ <br> </pre> <p> &lt;number&gt; は、 $0$ 以上 $2^{31}-1$ 以下の整数を表す。 </p> <p> 演算子、’^’ ‘&’ ‘|’ は、それぞれ排他的論理和、論理積、論理和を表す。 演算子の優先順位は以下の通りである。 </p> <p> 高 ’^’ > ‘&’ > ‘|’ 低 </p> <p> 区間 $[i, j]$ が $Q$ 個与えられる。 $S_i, \dots , S_j$ の計算結果を出力せよ。 </p> <p> なお、数式 $S_i, \dots , S_j$ が上記のBNFで示される形式であることは保証される。また、数式にゼロ詰めされた値が含まれることはない。 </p> <h2>制約</h2> <ul> <li>$1 \leq N, Q \leq 10^5$</li> <li>$N = |S| \ \ \ \ \ |S|$ は文字列の長さを表す。</li> <li>$0 \leq i \leq j < N$</li> </ul> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる。 </p> <p> $N$<br> $S$<br> $Q$<br> $i_1\ j_1$<br> $\vdots$<br> $i_Q\ j_Q$<br> </p> <h2>出力</h2> <p>$S_i, \dots , S_j$ の計算結果を出力せよ。 また、末尾に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 7 9^2&amp;1|2 4 0 6 0 2 2 6 4 4 </pre> <h3>サンプル出力 1</h3> <pre> 3 11 2 1 </pre> <h3>サンプル入力 2</h3> <pre> 13 3423&amp;423^1234 3 2 12 5 9 9 12 </pre> <h3>サンプル出力 2</h3> <pre> 21 422 1234 </pre> <h3>サンプル入力 3</h3> <pre> 7 1234567 3 0 0 0 1 4 6 </pre> <h3>サンプル出力 3</h3> <pre> 1 12 567 </pre>
p01507
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Dungeon Creation</H1> <p> The king demon is waiting in his dungeon to defeat a brave man. His dungeon consists of <var>H \times W</var> grids. Each cell is connected to four (i.e. north, south, east and west) neighboring cells and some cells are occupied by obstacles. </p> <p> To attack the brave man, the king demon created and sent a servant that walks around in the dungeon. However, soon the king demon found that the servant does not work as he wants. The servant is too dumb. If the dungeon had cyclic path, it might keep walking along the cycle forever. </p> <p> In order to make sure that the servant eventually find the brave man, the king demon decided to eliminate all cycles by building walls between cells. At the same time, he must be careful so that there is at least one path between any two cells not occupied by obstacles. </p> <p> Your task is to write a program that computes in how many ways the kind demon can build walls. </p> <H2>Input</H2> <p> The first line of each test case has two integers <var>H</var> and <var>W</var> (<var>1 \leq H \leq 500</var>, <var>1 \leq W \leq 15</var>), which are the height and the width of the dungeon. Following <var>H</var> lines consist of exactly <var>W</var> letters each of which is '.' (there is no obstacle on the cell) or '#' (there is an obstacle). You may assume that there is at least one cell that does not have an obstacle. </p> <p> The input terminates when <var>H = 0</var> and <var>W = 0</var>. Your program must not output for this case. </p> <H2>Output</H2> <p> For each test case, print its case number and the number of ways that walls can be built in one line. Since the answer can be very big, output in modulo 1,000,000,007. </p> <H2>Sample Input</H2> <pre> 2 2 .. .. 3 3 ... ... ..# 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 4 Case 2: 56 </pre>
p03490
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive <var>x</var>-axis direction.</p> <p>This robot will be given an instruction sequence <var>s</var>. <var>s</var> consists of the following two kinds of letters, and will be executed in order from front to back.</p> <ul> <li><code>F</code> : Move in the current direction by distance <var>1</var>.</li> <li><code>T</code> : Turn <var>90</var> degrees, either clockwise or counterclockwise.</li> </ul> <p>The objective of the robot is to be at coordinates <var>(x, y)</var> after all the instructions are executed. Determine whether this objective is achievable.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>s</var> consists of <code>F</code> and <code>T</code>.</li> <li><var>1 \leq |s| \leq 8</var> <var>000</var></li> <li><var>x</var> and <var>y</var> are integers.</li> <li><var>|x|, |y| \leq |s|</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> <var>x</var> <var>y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the objective is achievable, print <code>Yes</code>; if it is not, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>FTFFTFFF 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>FTFFTFFF -2 -2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre> <p>The objective can be achieved by, for example, turning clockwise in the first <code>T</code> and turning clockwise in the second <code>T</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>FF 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>TF 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>FFTTFF 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>Yes </pre> <p>The objective can be achieved by, for example, turning counterclockwise in the first <code>T</code> and turning counterclockwise in the second <code>T</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>TTTT 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>No </pre></section> </div> </span>
p01157
<H1><font color="#000">Problem C:</font> Online Quizu System</H1> <p> ICPC (Internet Contents Providing Company) is working on a killer game named Quiz Millionaire Attack. It is a quiz system played over the Internet. You are joining ICPC as an engineer, and you are responsible for designing a protocol between clients and the game server for this system. As bandwidth assigned for the server is quite limited, data size exchanged between clients and the server should be reduced as much as possible. In addition, all clients should be well synchronized during the quiz session for a simultaneous play. In particular, much attention should be paid to the delay on receiving packets. </p> <p> To verify that your protocol meets the above demands, you have decided to simulate the communication between clients and the server and calculate the data size exchanged during one game. </p> <p> A game has the following process. First, players participating and problems to be used are fixed. All players are using the same client program and already have the problem statements downloaded, so you don’t need to simulate this part. Then the game begins. The first problem is presented to the players, and the players answer it within a fixed amount of time. After that, the second problem is presented, and so forth. When all problems have been completed, the game ends. During each problem phase, the players are notified of what other players have done. Before you submit your answer, you can know who have already submitted their answers. After you have submitted your answer, you can know what answers are submitted by other players. </p> <p> When each problem phase starts, the server sends a <i>synchronization packet for problem-start</i> to all the players, and begins a polling process. Every 1,000 milliseconds after the beginning of polling, the server checks whether it received new answers from the players strictly before that moment, and if there are any, sends a notification to all the players: </p> <ul> <li> If a player hasn’t submitted an answer yet, the server sends it a <i>notification packet type A describing others’ answers</i> about the newly received answers.</li> <li> If a player is one of those who submitted the newly received answers, the server sends it a <i>notification packet type B describing others’ answers</i> about all the answers submitted by other players (i.e. excluding the player him/herself’s answer) strictly before that moment.</li> <li> If a player has already submitted an answer, the server sends it a <i>notification packet type B describing others’ answers</i> about the newly received answers.</li> <li> Note that, in all above cases, notification packets (both types A and B) must contain information about at least one player, and otherwise a notification packet will not be sent. </li> </ul> <p> When 20,000 milliseconds have passed after sending the <i>synchronization packet for problem-start</i>, the server sends notification packets of type A or B if needed, and then sends a <i>synchronization packet for problem-end</i> to all the players, to terminate the problem. </p> <p> On the other hand, players will be able to answer the problem after receiving the <i>synchronization packet for problem-start</i> and before receiving the <i>synchronization packet for problem-end</i>. Answers will be sent using an <i>answer packet</i>. </p> <p> The packets referred above have the formats shown by the following tables. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_onlineQuiz"> </center> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case begins with a line consisting of two integers <i>M</i> and <i>N</i> (1 &le; <i>M</i>, <i>N</i> &le; 100), denoting the number of players and problems, respectively. The next line contains <i>M</i> non-negative integers <i>D</i><sub>0</sub> , <i>D</i><sub>1</sub> , . . . , <i>D<i><sub></i>M</i> - 1</sub> , denoting the communication delay between each players and the server (players are assigned ID’s ranging from 0 to <i>M</i> - 1, inclusive). Then follow <i>N</i> blocks describing the submissions for each problem. Each block begins with a line containing an integer <i>L</i>, denoting the number of players that submitted an answer for that problem. Each of the following <i>L</i> lines gives the answer from one player, described by three fields <i>P</i>, <i>T</i>, and <i>A</i> separated by a whitespace. Here <i>P</i> is an integer denoting the player ID, <i>T</i> is an integer denoting the time elapsed from the reception of <i>synchronization packet for problem-start</i> and the submission on the player’s side, and A is an alphanumeric string denoting the player’s answer, whose length is between 1 and 9, inclusive. Those <i>L</i> lines may be given in an arbitrary order. You may assume that all <i>answer packets</i> will be received by the server within 19,999 milliseconds (inclusive) after sending <i>synchronization packet for problem-start</i>. </p> <p> The input is terminated by a line containing two zeros. </p> <H2>Output</H2> <p> For each test case, you are to print <i>M</i> + 1 lines. In the first line, print the data size sent and received by the server, separated by a whitespace. In the next <i>M</i> lines, print the data size sent and received by each player, separated by a whitespace, in ascending order of player ID. Print a blank line between two consecutive test cases. </p> <H2>Sample Input</H2> <pre> 3 2 1 2 10 3 0 3420 o 1 4589 o 2 4638 x 3 1 6577 SUZUMIYA 2 7644 SUZUMIYA 0 19979 YASUZUMI 4 2 150 150 150 150 4 0 1344 HOGEHOGE 1 1466 HOGEHOGE 2 1789 HOGEHOGE 3 19100 GEHO 2 2 1200 SETTEN 3 700 SETTEN 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 177 57 19 58 19 57 19 62 253 70 13 58 13 58 24 66 20 71 </pre>
p00316
<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> A 高校の生徒会長である明は、A 高校の生徒がどの部活動に所属しているかを調査することにした。A高校には 1 から <var>N</var> の番号が付けられた <var>N</var> 人の生徒と、1 から <var>M</var> の番号が付けられた <var>M</var> 種類の部活動がある。各部活動に人数制限はなく、0 人の部活動もありえる。ただし、A 高校の校則では生徒はひとつの部活動までしか所属できない。生徒は全員この校則を守っている。 </p> <p> 明は生徒会員に調査を依頼し、各行が次のいずれかであるような <var>K</var> 行の記録を入手した。 </p> <ul> <li> 生徒 <var>a</var> と生徒 <var>b</var> は同じ部活動に所属している。</li> <li> 生徒 <var>c</var> は部活動 <var>x</var> に所属している。</li> </ul> <p> しかし、この記録には誰かが校則違反になってしまうような矛盾があるかもしれない。明は1行目から順に見ていき、矛盾があると判断できる最初の行を探すことにした。 </p> <p> <var>K</var> 行の記録が与えられたとき、矛盾があると判断できる最初の行の番号を求めるプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>M</var> <var>K</var> <var>record<sub>1</sub></var> <var>record<sub>2</sub></var> : <var>record<sub>K</sub></var> </pre> <p> 1行目に生徒の人数 <var>N</var> (1 &le; <var>N</var> &le; 100000)、部活動の種類の数 <var>M</var> (1 &le; <var>M</var> &le; 100000)、記録の行数 <var>K</var> (1 &le; <var>K</var> &le; 200000) が与えられる。続く <var>K</var> 行に記録の各行 <var>record<sub>i</sub></var> が、以下のいずれかの形式で与えられる。 </p> <pre> 1 <var>a</var> <var>b</var> </pre> <p> または </p> <pre> 2 <var>c</var> <var>x</var> </pre> <p> 先頭の数字が「1」のとき、生徒 <var>a</var> (1 &le; <var>a</var> &le; <var>N</var>) と生徒 <var>b</var> (1 &le; <var>b</var> &le; <var>N</var>) が同じ部活動に所属していることを示す。ただし、<var>a</var> &ne; <var>b</var> である。 </p> <p> 先頭の数字が「2」のとき、生徒 <var>c</var> (1 &le; <var>c</var> &le; <var>N</var>) が部活動 <var>x</var> (1 &le; <var>x</var> &le; <var>M</var>) に所属していることを示す。 </p> <h2>Output</h2> <p> 矛盾があると判断できる最初の行の番号を1行に出力する。見つからない場合は 0 を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 3 2 5 1 1 2 1 2 3 2 1 1 2 3 2 2 2 1 </pre> <h2>Sample Output 1</h2> <pre> 4 </pre> <br/> <h2>Sample Input 2</h2> <pre> 3 2 4 1 1 2 2 1 1 2 3 2 2 2 1 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre> <br/> <h2>Sample Input 3</h2> <pre> 3 2 2 1 1 2 2 1 1 </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p02281
<H1>Tree Walk</H1> <p> Binary trees are defined recursively. A binary tree <i>T</i> is a structure defined on a finite set of nodes that either </p> <ul> <li>contains no nodes, or</li> <li>is composed of three disjoint sets of nodes:<br> - a root node.<br> - a binary tree called its left subtree.<br> - a binary tree called its right subtree.<br> </li> </ul> <p> Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: </p> <ol> <li>Print the root, the left subtree and right subtree (preorder).</li> <li>Print the left subtree, the root and right subtree (inorder).</li> <li>Print the left subtree, right subtree and the root (postorder).</li> </ol> <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> linen, 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> In the 1st line, print "<span>Preorder</span>", and in the 2nd line print a list of node IDs obtained by the preorder tree walk. </p> <p> In the 3rd line, print "<span>Inorder</span>", and in the 4th line print a list of node IDs obtained by the inorder tree walk. </p> <p> In the 5th line, print "<span>Postorder</span>", and in the 6th line print a list of node IDs obtained by the postorder tree walk. </p> <p> Print a space character before each node ID. </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> Preorder 0 1 2 3 4 5 6 7 8 Inorder 2 1 3 0 6 5 7 4 8 Postorder 2 3 1 6 7 5 8 4 0 </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>
p03869
<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>Snuke received a triangle as a birthday present. The coordinates of the three vertices were <var>(x_1, y_1)</var>, <var>(x_2, y_2)</var>, and <var>(x_3, y_3)</var>.</p> <p>He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≤ x_i, y_i ≤ 1000</var></li> <li>The coordinates are integers.</li> <li>The three points are not on the same line.</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_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>x_3</var> <var>y_3</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible radius of the circles. The absolute error or the relative error must be at most <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>0 0 1 1 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0.292893218813 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 1 5 4 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0.889055514217 </pre></section> </div> </span>
p01854
<h1 id="c-壺-pot">C : 壺 / Pots</h1> <h2 id="問題文">問題文</h2> <p>ここに <var>N</var> 個の不思議な形の壺がある. <var>i</var> 番目の壺は <var>K_i</var> 個の直円柱を下から順に鉛直に繋げた形状である. 繋がっている順番は変えることができない. A 氏は体積 <var>M</var> の水を持っている. この水をそれぞれの壺に好きな量ずつに分けて注ぐ. 水が全く入っていない壺が存在しても構わない. また,全ての壺が水で満たされたとき,それ以上水を注ぐ事はできない.それぞれの壺の水面の高さの総和の最大値を求めよ.</p> <h2 id="入力">入力</h2> <pre> <var>N \ M</var> <var>K_1 \ S_{11} \ H_{11} \ … \ S_{1 K_1} \ H_{1 K_1}</var> <var>K_2 \ S_{21} \ H_{21} \ … \ S_{2 K_2} \ H_{2 K_2}</var> <var>…</var> <var>K_N \ S_{N1} \ H_{N1} \ … \ S_{N K_N} \ H_{N K_N}</var> </pre> <p><var>1</var> 行目に <var>N, M</var> が, <var>1+i</var> 行目には <var>i</var> 番目の壺の情報が入力される. <var>K_i</var> は直円柱の数であり,<var>S_{ij}, H_{ij}</var> はそれぞれ壺を構成する下から <var>j</var> 番目の直円柱の底面積と高さである.</p> <h2 id="制約">制約</h2> <ul> <li>整数である</li> <li><var>1 &le; N &le; 200</var></li> <li><var>1 &le; M &le; 200</var></li> <li><var>1 &le; K_i &le; 20</var></li> <li><var>1 &le; S_{ij} &le; 20</var></li> <li><var>1 &le; H_{ij} &le; 20</var></li> </ul> <h2 id="出力">出力</h2> <p>答えを <var>1</var> 行で出力せよ. <var>0.00001</var> 以下の絶対誤差を含んでも良い.</p> <h2 id="サンプル">サンプル</h2> <h3 id="サンプル入力1">サンプル入力1</h3> <pre> 2 15 2 3 3 7 2 2 7 1 1 4 </pre> <h3 id="サンプル出力1">サンプル出力1</h3> <pre> 6.33333333 </pre> <h3 id="サンプル入力2">サンプル入力2</h3> <pre> 2 14 1 2 4 2 5 2 1 4 </pre> <h3 id="サンプル出力">サンプル出力2</h3> <pre> 6 </pre> サンプル 1, 2 の入出力を図示すると次のようになる. <div class="figure"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RUPC2015ACPC2015_C" /> </div> <h3 id="サンプル入力3">サンプル入力3</h3> <pre> 2 25 4 8 9 1 9 6 5 2 8 4 1 7 4 4 1 6 4 3 </pre> <h3 id="サンプル出力3">サンプル出力3</h3> <pre> 13 </pre> <!-- - - - end nicebady - - - -->
p00746
<h1><font color="#000000">Problem A:</font> Pablo Squarson's Headache</h1> <!-- begin en only --> <p>Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth.</p> <!-- end en only --> <!-- begin en only --> <p>At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision.</p> <!-- end en only --> <!-- begin en only --> <p>Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face.</p> <!-- end en only --> <!-- begin en only --> <p>Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him!</p> <!-- end en only --> <!-- begin en only --> <p>Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another.</p> <!-- end en only --> <!-- begin en only --> <p>I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates".</p> <!-- end en only --> <p style="text-align: center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_A-1"> </p> <h3>Input</h3> <!-- begin en only --> <p>The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows.</p> <!-- end en only --> <blockquote> <span class="math">N</span><br /> <span class="math">n</span><sub>1</sub> <span class="math">d</span><sub>1</sub><br /> <span class="math">n</span><sub>2</sub> <span class="math">d</span><sub>2</sub><br /> ...<br /> <span class="math">n<sub>N</sub></span><sub>-1</sub> <span class="math">d<sub>N</sub></span><sub>-1</sub><br /> </blockquote> <!-- begin en only --> <p>The first line contains the number of squares (= <span class="math">N</span>) used to make the piece of artwork. The number is a positive integer and is smaller than 200. <!-- end en only --> <!-- begin en only --> <p>The remaining (<span class="math">N</span>-1) lines in the dataset are square placement instructions. The line &ldquo;<span class="math">n<sub>i</sub></span> <span class="math">d<sub>i</sub></span>&rdquo; indicates placement of the square numbered <span class="math">i</span> (&le; <span class="math">N</span>-1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., (<span class="math">N</span>-1). Note that the input does not give any placement instruction to the first square, which is numbered zero.</p> <p>A square placement instruction for the square numbered <span class="math">i</span>, namely &ldquo;<span class="math">n<sub>i</sub> d<sub>i</sub></span>&rdquo;, directs it to be placed next to the one that is numbered <span class="math">n<sub>i</sub></span>, towards the direction given by <span class="math">d<sub>i</sub></span>, which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3).</p> <!-- end en only --> <!-- begin en only --> <p>For example, pieces of artwork corresponding to the four datasets shown in <b>Sample Input</b> are depicted below. Squares are labeled by their numbers.</p> <!-- end en only --> <p style="text-align: center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_A-2"> </p> <!-- begin en only --> <p>The end of the input is indicated by a line that contains a single zero.</p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p>For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters.</p> <!-- end en only --> <h3>Sample Input</h3> <pre> 1 5 0 0 0 1 0 2 0 3 12 0 0 1 0 2 0 3 1 4 1 5 1 6 2 7 2 8 2 9 3 10 3 10 0 2 1 2 2 2 3 2 2 1 5 1 6 1 7 1 8 1 0 </pre> </blockquote> </pre> <h3>Output for the Sample Input</h3> <pre> 1 1 3 3 4 4 5 6 </pre>
p00253
<H1></H1> <p> 家庭菜園に野菜を植えることにしました。n 粒の種があったので1日に1粒ずつ、n 日かけて n 粒の種をまきました。どの種からも芽が出て、すくすくと育っています。収穫の時期が待ち遠しいものです。 </p> <p> ある日、いつものように苗に水やりをしていると、おかしなことに気づきました。n 本の野菜の苗があるはずなのに、1本多いのです。雑草が生えてきてしまいました。直ちに引っこ抜きたいのですが、困ったことにどの苗もよく似ていて、野菜と雑草の見分けがつきません。 </p> <p> 手がかりになるのは、野菜の成長速度です。この野菜は、種をまいてからずっと、1日に決まった長さだけ伸び続けるのです。しかし、この「決まった長さ」というのが何センチメートルなのかはわかりません。また、最初の種を何日前にまいたのかも忘れてしまいました。苗は一列に並んでいますが、唯一覚えているのは、種をまくとき毎日一粒ずつ右から順にまいていったことだけです。 </p> <p> n+1本の苗の長さを入力し、雑草の長さを出力するプログラムを作成して下さい。 </p> <h2>入力</h2> <p> 入力は複数のデータセットからなる。入力の終わりはゼロ1つ行で示される。入力は以下の形式で与えられる。 </p> <pre> n h<sub>1</sub> h<sub>2</sub> h<sub>3</sub> ... h<sub>n+1</sub> </pre> <p> 1行目の n (4 &le; n &le; 100) は野菜の苗の数を表す整数である。2行目は1つの空白で区切られた n+1 個の整数を含み、 h<sub>i</sub> (1 &le; h<sub>i</sub> &le; 10<sup>9</sup>)は左からi番目の苗の長さを示す。 </p> <p> h<sub>1</sub> h<sub>2</sub> ... h<sub>n+1</sub> が等差数列になっているような入力は与えられない。 </p> <p> データセットの数は 500 を超えない。 </p> <h2>出力</h2> <p> 各データセットごとに雑草の長さを出力する 。 </p> <h2>入力例</h2> <pre> 5 1 2 3 6 4 5 6 1 3 6 9 12 15 18 4 5 7 9 11 12 0 </pre> <h2>出力例</h2> <pre> 6 1 12 </pre>
p03886
<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>Construct an <var>N</var>-gon that satisfies the following conditions:</p> <ul> <li>The polygon is simple (see notes for the definition).</li> <li>Each edge of the polygon is parallel to one of the coordinate axes.</li> <li>Each coordinate is an integer between <var>0</var> and <var>10^9</var>, inclusive.</li> <li>The vertices are numbered <var>1</var> through <var>N</var> in counter-clockwise order.</li> <li>The internal angle at the <var>i</var>-th vertex is exactly <var>a_i</var> degrees.</li> </ul> <p>In case there are multiple possible answers, you can output any.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>A polygon is called simple if each edge has a positive length, and no two edges have a common point (except for adjacent edges touching at a vertex).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 ≤ N ≤ 1000</var></li> <li><var>a_i</var> is either <var>90</var> or <var>270</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> : <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>In case the answer exists, print the answer in the following format:</p> <pre><var>x_1</var> <var>y_1</var> : <var>x_N</var> <var>y_N</var> </pre> <p>Here <var>(x_i, y_i)</var> are the coordinates of the <var>i</var>-th vertex.</p> <p>In case the answer doesn't exist, print a single <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 90 90 270 90 90 90 270 90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 0 2 0 2 1 3 1 3 2 1 2 1 1 0 1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 90 90 90 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre></section> </div> </span>
p02794
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge in this tree connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.<br/> Consider painting each of these edges white or black. There are <var>2^{N-1}</var> such ways to paint the edges. Among them, how many satisfy all of the following <var>M</var> restrictions? </p> <ul> <li>The <var>i</var>-th <var>(1 \leq i \leq M)</var> restriction is represented by two integers <var>u_i</var> and <var>v_i</var>, which mean that the path connecting Vertex <var>u_i</var> and Vertex <var>v_i</var> must contain at least one edge painted black.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>2 \leq N \leq 50</var></li> <li><var>1 \leq a_i,b_i \leq N</var></li> <li>The graph given in input is a tree.</li> <li><var>1 \leq M \leq \min(20,\frac{N(N-1)}{2})</var></li> <li><var>1 \leq u_i &lt; v_i \leq N</var></li> <li>If <var>i \not= j</var>, either <var>u_i \not=u_j</var> or <var>v_i\not=v_j</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>M</var> <var>u_1</var> <var>v_1</var> <var>:</var> <var>u_M</var> <var>v_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of ways to paint the edges that satisfy all of the <var>M</var> conditions.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 1 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The tree in this input is shown below: <br/> <br/> <img alt="Figure" src="https://img.atcoder.jp/ghi/5b0208ab1e3bb39a5d4fb7bafbfc448e.png"> <br/> <br/> All of the <var>M</var> restrictions will be satisfied if Edge <var>1</var> and <var>2</var> are respectively painted (white, black), (black, white), or (black, black), so the answer is <var>3</var>.</img></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>The tree in this input is shown below: <br/> <br/> <img alt="Figure" src="https://img.atcoder.jp/ghi/d08b3f53dfa4857fe9ffe13fa5d7ae69.png"/> <br/> <br/> All of the <var>M</var> restrictions will be satisfied only if Edge <var>1</var> is painted black, so the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 2 3 2 3 4 5 3 3 1 3 2 4 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9 </pre> <p>The tree in this input is shown below: <br/> <br/> <img alt="Figure" src="https://img.atcoder.jp/ghi/386502bb3c85e0bb5aee64e4e7c087a1.png"/> <br/> <br/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 1 2 2 3 4 3 2 5 6 3 6 7 8 6 5 2 7 3 5 1 6 2 8 7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>62 </pre> <p>The tree in this input is shown below: <br/> <br/> <img alt="Figure" src="https://img.atcoder.jp/ghi/955fa8fd8af658abb24ff2f68b9997be.png"/> <br/> <br/></p></section> </div> </span>
p01911
<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>G: 雨降りバス乗り換え</h1> <h2>背景</h2> <p> 今日は AOR イカちゃんにとって初となるデートの日だ。 AOR イカちゃんは駅からバスを乗り継ぎ、待ち合わせ場所のバス停に向かう予定である。 AOR イカちゃんが駅に着いた時、不幸にも雨が降ってきた。当初予定していた経路ではバスの待ち時間で濡れてしまい、せっかく整えた身だしなみが台無しになってしまう可能性がある。 そこで、バスの待ち時間が最も少なくなるような経路でバス停まで向かうことにした。 AOR イカちゃんは、待ち合わせ場所のバス停に着くまでにどの程度濡れるのか心配している。 </p> <h2>問題</h2> <p> AOR イカちゃんは時刻 $0$ に $S$ 番目のバス停におり、そこから $G$ 番目のバス停まで行きたいと考えている。 バス停の個数 $N$ と、異なるバス停同士を繋ぐ $M$ 個の経路 (※) が与えられる。 バス停には、それぞれ $1, \dots, N$ の番号がふられている。 各経路は、出発地 $u$ 、目的地 $v$ 、出発時刻 $t$ 、所要時間 $c$ の $4$ つの値からなる。 時刻 $t$ に出発地 $u$ にいればバスに乗ることができ、時刻 $t + c$ に目的地 $v$ へ到着する。 バスに乗っていない間、 AOR イカちゃんは雨に濡れてしまう。 雨にぬれる時間が最小となる経路を通り $G$ 番目のバス停へ向かう時、時刻 $0$ から $G$ 番目のバス停に着くまでの間に雨に濡れた時間の合計を出力せよ。 </p> <p> (※) グラフ理論の用語における経路とは頂点と辺の列であるが,ここでは辺の意味で使われていることに注意してほしい。 </p> <h2>制約</h2> <ul> <li>$2 \le N \le 10^5$</li> <li>$1 \le M \le 2 \times 10^5$</li> <li>$1 \le S , G \le N$</li> <li>$1 \le u_i , v_i \le N$</li> <li>$0 \le t_i \le 10^5$</li> <li>$1 \le c_i \le 10^5$</li> <li>$S \neq G$</li> <li>$u_i \neq v_i$</li> </ul> <ul> <li>出発地 $u$ と目的地 $v$ が同じであるような経路は存在しない。</li> <li>出発地 $u$ と目的地 $v$ を結ぶ経路は複数存在する場合がある。</li> <li>バスの乗り降り、乗り換えに時間はかからないものとする。</li> <li> $G$ 番目のバス停へ到着する時間は問わない。</li> <li> $S$ 番目のバス停から $G$ 番目のバス停へ到着できることは保証されている。</li> </ul> <h2>入力</h2> <p> 入力は以下の形式で標準入力から与えられる。 </p> <p> $N \ M \ S \ G$<br> $u_1 \ v_1 \ t_1 \ c_1$<br> $\vdots$<br> $u_M \ v_M \ t_M \ c_M$<br> </p> <h2>出力</h2> <p> 雨に濡れた最小の時間を 1 行で出力せよ。また、末尾に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>入力例 1</h3> <pre> 2 2 1 2 1 2 10 100 1 2 5 500 </pre> <h3>出力例 1</h3> <pre> 5 </pre> <p> 到着時間が遅くても、できるだけ雨に濡れない経路を選ぶ。 </p> <h3>入力例 2</h3> <pre> 3 2 1 3 1 2 0 123 2 3 123 500 </pre> <h3>出力例 2</h3> <pre> 0 </pre> <p> 乗り換えに時間はかからない。 </p>
p00603
<H1><font color="#000000">Problem I:</font> Riffle Shuffle</H1> <p> There are a number of ways to shuffle a deck of cards. Riffle shuffle is one such example. The following is how to perform riffle shuffle. </p> <p> There is a deck of <i>n</i> cards. First, we divide it into two decks; deck A which consists of the top half of it and deck B of the bottom half. Deck A will have one more card when <i>n</i> is odd. </p> <p> Next, <i>c</i> cards are pulled from bottom of deck A and are stacked on deck C, which is empty initially. Then <i>c</i> cards are pulled from bottom of deck B and stacked on deck C, likewise. This operation is repeated until deck A and B become empty. When the number of cards of deck A(B) is less than <i>c</i>, all cards are pulled. Finally we obtain shuffled deck C. See an example below: </p> <pre> - A single riffle operation where n = 9, c = 3 for given deck [0 1 2 3 4 5 6 7 8] (right is top) - Step 0 deck A [4 5 6 7 8] deck B [0 1 2 3] deck C [] - Step 1 deck A [7 8] deck B [0 1 2 3] deck C [4 5 6] - Step 2 deck A [7 8] deck B [3] deck C [4 5 6 0 1 2] - Step 3 deck A [] deck B [3] deck C [4 5 6 0 1 2 7 8] - Step 4 deck A [] deck B [] deck C [4 5 6 0 1 2 7 8 3] shuffled deck [4 5 6 0 1 2 7 8 3] </pre> <p> This operation, called riffle operation, is repeated several times. </p> <p> Write a program that simulates Riffle shuffle and answer which card will be finally placed on the top of the deck. </p> <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 &le; <i>n</i> &le; 50) and <i>r</i>(1 &le; <i>r</i> &le; 50); <i>n</i> and <i>r</i> are the number of cards in the deck and the number of riffle operations, respectively. </p> <p> <i>r</i> more positive integers follow, each of which represents a riffle operation. These riffle operations are performed in the listed order. Each integer represents <i>c</i>, which is explained above. </p> <p> The end of the input is indicated by EOF. The number of data sets is less than 100.<!--a line which contains two zeros.--> </p> <H2>Output</H2> <p> For each data set in the input, your program should print the number of the top card after the shuffle. Assume that at the beginning the cards are numbered from 0 to <i>n</i>-1, from the bottom to the top. Each number should be written in a sparate line without any superfluous characters such as leading or following spaces. </p> <H2>Sample Input</H2> <pre> 9 1 3 9 4 1 2 3 4 </pre> <H2>Output for the Sample Input</H2> <pre> 3 0 </pre>
p01442
<H1><font color="#000">Problem F:</font> Mysterious Maze</H1> <p> A robot in a two-dimensional maze again. The maze has an entrance and an exit this time, though. </p> <p> Just as in the previous problem, the maze is made up of <i>H</i> &times; <i>W</i> grid cells, its upper side faces north, and each cell is either empty or wall. Unlike the previous, on the other hand, one of the empty cells is connected to the entrance and another to the exit. </p> <p> The robot is rather complex - there is some control, but not full. It is associated with a controller that has two buttons, namely <i>forward</i> and <i>turn</i>. The forward button moves the robot forward to the next cell, if possible. The robot can not move into a wall nor outside the maze. The turn button turns the robot as <i>programmed</i>. Here the program is a finite sequence of <i>N</i> commands, each of which is either 'L' (indicating a left turn) or 'R' (a right turn). The first turn follows the first command; the second turn follows the second command; similar for the following turns. The turn button stops working once the commands are exhausted; the forward button still works in such a case though. The robot always turns by 90 degrees at once. </p> <p> The robot is initially put on the entrance cell, directed to the north. Your mission is to determine whether it can reach the exit cell if controlled properly. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is formatted as follows. </p> <p> <i>H W N</i><br> <i>s</i><sub>1</sub> ... <i>s<sub>N</sub></i><br> <i>c</i><sub>1,1</sub><i>c</i><sub>1,2</sub>...<i>c</i><sub>1,<i>W</i></sub><br> ...<br> <i>c</i><sub><i>H</i>,1</sub><i>c</i><sub><i>H</i>,2</sub>...<i>c</i><sub><i>H</i>,<i>W</i></sub><br> </p> <p> The first line of a dataset contains three integers <i>H</i>, <i>W</i> and <i>N</i> (1 &le; <i>H</i>, <i>W</i> &le; 1,000, 1 &le; <i>N</i> &le; 1,000,000). </p> <p> The second line contains a program of <i>N</i> commands. </p> <p> Each of the following <i>H</i> lines contains exactly <i>W</i> characters. Each of these characters represents a cell of the maze. "<span>.</span>" indicates empty, "<span>#</span>" indicates a wall, "<span>S</span>" indicates an entrance, and "<span>G</span>" indicates an exit. There is exactly one entrance cell and one exit cell. </p> <p> The end of input is indicated by a line with three zeros. </p> <H2>Output</H2> <p> For each dataset, output whether the robot can reach the exit in a line: "<span>Yes</span>" if it can or "<span>No</span>" otherwise (without quotes). </p> <H2>Sample Input</H2> <pre> 2 2 1 L G. #S 2 2 2 RR G. .S 3 3 6 LLLLLL G#. ... .#S 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Yes No Yes </pre>
p03185
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> stones, numbered <var>1, 2, \ldots, N</var>. For each <var>i</var> (<var>1 \leq i \leq N</var>), the height of Stone <var>i</var> is <var>h_i</var>. Here, <var>h_1 &lt; h_2 &lt; \cdots &lt; h_N</var> holds.</p> <p>There is a frog who is initially on Stone <var>1</var>. He will repeat the following action some number of times to reach Stone <var>N</var>:</p> <ul> <li>If the frog is currently on Stone <var>i</var>, jump to one of the following: Stone <var>i + 1, i + 2, \ldots, N</var>. Here, a cost of <var>(h_j - h_i)^2 + C</var> is incurred, where <var>j</var> is the stone to land on.</li> </ul> <p>Find the minimum possible total cost incurred before the frog reaches Stone <var>N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq C \leq 10^{12}</var></li> <li><var>1 \leq h_1 &lt; h_2 &lt; \cdots &lt; h_N \leq 10^6</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>C</var> <var>h_1</var> <var>h_2</var> <var>\ldots</var> <var>h_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible total cost incurred.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 6 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>20 </pre> <p>If we follow the path <var>1</var> → <var>3</var> → <var>5</var>, the total cost incurred would be <var>((3 - 1)^2 + 6) + ((5 - 3)^2 + 6) = 20</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1000000000000 500000 1000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1250000000000 </pre> <p>The answer may not fit into a 32-bit integer type.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 5 1 3 4 5 10 11 12 13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>62 </pre> <p>If we follow the path <var>1</var> → <var>2</var> → <var>4</var> → <var>5</var> → <var>8</var>, the total cost incurred would be <var>((3 - 1)^2 + 5) + ((5 - 3)^2 + 5) + ((10 - 5)^2 + 5) + ((13 - 10)^2 + 5) = 62</var>.</p></section> </div> </span>
p01012
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1>Planarian Regeneration</h1> <h2>Problem</h2> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_planarian" width="250"><br/> <p> 皆さん、「プラナリア」って知っていますか?<br/> プラナリアとは、日本では川の上流の石や枯葉などの裏に張り付いて生息している水生生物です。<br/> プラナリアの最も優れた能力はその「再生能力」です。プラナリアの再生能力は著しく、例えば、三等分するとそれぞれが再生し、数週間後には元の完全な状態のプラナリアが3匹できあがります。<br/> </p> <p> この度、会津の山奥の上流にて発見された新種のプラナリアの姿は長方形をしていて、プラナリアはある法則により再生します。 このとき、プラナリアは下の図のように配置し、2つの手段でプラナリアの切断実験を行います。 </p> <p> まず1つ目の手段として、垂直方向に切ることを考えます。一度の切断では、すべての断片を水平方向の長さが(断片の頭に近い部分):(断片の頭に遠い部分)=<var>m </var>:<var>n </var>になるように切断します。この動作を<var>x </var>回繰り返します。 </p> <p> 次に2つ目の手段として、水平方向に切ることを考えます。一度の切断では、すべての断片を垂直方向の長さが(断片の右端に近い部分):(断片の左端に近い部分)=<var>k </var>:<var>l </var>に切断します。この動作を<var>y </var>回繰り返します。これらの切断によって断片が移動することはありません。 </p> <p> 数週間後に、各断片が元の完全なプラナリアの状態に再生している確率は以下の式により求まります。<br/> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_equation_new_ja" width="700"><br/> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_explanation_new_ja" width="500"><br/> </br> 上の図は、垂直方向に1:2で2回、水平方向に1:1で1回切断した状態です。 </p> <p> 以上の操作で切断した時の、数週間後に元の姿に再生しているプラナリアの数の期待値を求めてください。元のプラナリアの垂直方向の長さと水平方向の長さはともに1とします。 </p> <h2>Input</h2> <pre> <var>m </var> <var>n </var> <var>x </var> <var>k </var> <var>l </var> <var>y </var> </pre> <p> 入力では、6つの整数<var>m </var>, <var>n </var>, <var>x </var>, <var>k </var>, <var>l </var>, <var>y </var>が上記の入力フォーマットで与えられます。<br/> これら6つの整数は問題文中のものと対応しており、水平方向に<var>m </var>:<var>n </var>で切断する動作を<var>x </var>回、垂直方向に<var>k </var>:<var>l </var>で切断する動作を<var>y </var>回繰り返します。<br/> 1 &le; <var>m </var>, <var>n </var>, <var>k </var>, <var>l </var> &le; 100、 0 &le; <var>x </var>, <var>y </var> &le; 40 であり、 <var>m </var>, <var>n </var>と <var>l </var>, <var>k </var>はそれぞれ互いに素です。 </p> <h2>Output</h2> <p> 一行に数週間後に元の姿に再生しているプラナリアの数の期待値を出力してください。<br/> 出力は 10<sup>-6</sup> 以下の誤差ならば許容されます。 </p> <h2>Sample Input 1</h2> <pre> 1 1 1 1 1 1 </pre> <h2>Sample Output 1</h2> <pre> 0.562500 </pre> <h2>Sample Input 2</h2> <pre> 1 2 2 1 1 1 </pre> <h2>Sample Output 2</h2> <pre> 0.490741 </pre> <h2>Sample Input 3</h2> <pre> 1 2 0 3 4 0 </pre> <h2>Sample Output 3</h2> <pre> 1.000000 </pre> <h2>Notes</h2> <p> この問題では、doubleよりも精度の高い浮動小数を使用することを推奨します。 </p>
p04007
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with <var>H</var> rows and <var>W</var> columns.</p> <p>Snuke painted some of the cells red in his paper. Here, the cells painted red were <em>4-connected</em>, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.</p> <p>Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.</p> <p>Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.</p> <p>You are given a matrix of letters <var>a_{ij}</var> (<var>1≤i≤H</var>, <var>1≤j≤W</var>) that describes the positions of the purple cells. If the cell at the <var>i</var>-th row and <var>j</var>-th column is purple, then <var>a_{ij}</var> is <code>#</code>, otherwise <var>a_{ij}</var> is <code>.</code>. Here, it is guaranteed that <strong>no outermost cell is purple</strong>. That is, if <var>i=1, H</var> or <var>j = 1, W</var>, then <var>a_{ij}</var> is <code>.</code>.</p> <p>Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3≤H,W≤500</var></li> <li><var>a_{ij}</var> is <code>#</code> or <code>.</code>.</li> <li>If <var>i=1,H</var> or <var>j=1,W</var>, then <var>a_{ij}</var> is <code>.</code>.</li> <li>At least one of <var>a_{ij}</var> is <code>#</code>.</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>H</var> <var>W</var> <var>a_{11}</var><var>...</var><var>a_{1W}</var> <var>:</var> <var>a_{H1}</var><var>...</var><var>a_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:</p> <ul> <li>The first <var>H</var> lines should describe the positions of the red cells.</li> <li>The following <var>1</var> line should be empty.</li> <li>The following <var>H</var> lines should describe the positions of the blue cells.</li> </ul> <p>The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 ..... .#.#. ..... .#.#. ..... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>..... ##### #.... ##### ..... .###. .#.#. .#.#. .#.#. ..... </pre> <p>One possible pair of the set of the positions of the red cells and the blue cells is as follows:</p> <p><img src="/img/agc/004/gatbantar/C_1.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 13 ............. .###.###.###. .#.#.#...#... .###.#...#... .#.#.#.#.#... .#.#.###.###. ............. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>............. .###########. .###.###.###. .###.###.###. .###.###.###. .###.###.###. ............. ............. .###.###.###. .#.#.#...#... .###.#...#... .#.#.#.#.#... .#.#########. ............. </pre> <p>One possible pair of the set of the positions of the red cells and the blue cells is as follows:</p> <p><img src="/img/agc/004/gatbantar/C_2.png"/></p></section> </div> </span>
p01205
<H1><font color="#000">Problem D:</font> Goofy Converter</H1> <p> Nathan O. Davis is a student at the department of integrated systems. He is now taking a class in in- tegrated curcuits. He is an idiot. One day, he got an assignment as follows: design a logic circuit that takes a sequence of positive integers as input, and that outputs a sequence of 1-bit integers from which the original input sequence can be restored uniquely. </p> <p> Nathan has no idea. So he searched for hints on the Internet, and found several pages that describe the 1-bit DAC. This is a type of digital-analog converter which takes a sequence of positive integers as input, and outputs a sequence of 1-bit integers. </p> <p> Seeing how 1-bit DAC works on these pages, Nathan came up with a new idea for the desired converter. His converter takes a sequence L of positive integers, and a positive integer <i>M</i> aside from the sequence, and outputs a sequence <i>K</i> of 1-bit integers such that: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_goofy"> </center> <p> He is not so smart, however. It is clear that his converter does not work for some sequences. Your task is to write a program in order to show the new converter cannot satisfy the requirements of his assignment, even though it would make Nathan in despair. </p> <H2>Input</H2> <p> The input consists of a series of data sets. Each data set is given in the following format: </p> <pre> <i>N M</i> <i>L</i><sub>0</sub> <i>L</i><sub>1</sub> . . . <i>L</i><sub><i>N</i>-1</sub> </pre> <p> <i>N</i> is the length of the sequence <i>L</i>. <i>M</i> and <i>L</i> are the input to Nathan’s converter as described above. You may assume the followings: 1 &le; <i>N</i> &le; 1000, 1 &le; <i>M</i> &le; 12, and 0 &le; <i>L<sub>j</sub></i> &le; <i>M</i> for <i>j</i> = 0, . . . , <i>N</i> - 1. </p> <p> The input is terminated by <i>N</i> = <i>M</i> = 0. </p> <H2>Output</H2> <p> For each data set, output a binary sequence <i>K</i> of the length (<i>N</i> + <i>M</i> - 1) if there exists a sequence which holds the equation mentioned above, or “Goofy” (without quotes) otherwise. If more than one sequence is possible, output any one of them. </p> <H2>Sample Input</H2> <pre> 4 4 4 3 2 2 4 4 4 3 2 3 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1111001 Goofy </pre>
p03238
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In <var>2020</var>, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.<br/> One day, there was an exam where a one-year-old child must write a program that prints <code>Hello World</code>, and a two-year-old child must write a program that receives integers <var>A, B</var> and prints <var>A+B</var>.<br/> Takahashi, who is taking this exam, suddenly forgets his age.<br/> He decides to write a program that first receives his age <var>N</var> (<var>1</var> or <var>2</var>) as input, then prints <code>Hello World</code> if <var>N=1</var>, and additionally receives integers <var>A, B</var> and prints <var>A+B</var> if <var>N=2</var>.<br/> Write this program for him. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is <var>1</var> or <var>2</var>.</li> <li><var>A</var> is an integer between <var>1</var> and <var>9</var> (inclusive).</li> <li><var>B</var> is an integer between <var>1</var> and <var>9</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 one of the following formats: </p> <pre>1 </pre> <pre>2 <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If <var>N=1</var>, print <code>Hello World</code>; if <var>N=2</var>, print <var>A+B</var>. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Hello World </pre> <p>As <var>N=1</var>, Takahashi is one year old. Thus, we should print <code>Hello World</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> <p>As <var>N=2</var>, Takahashi is two years old. Thus, we should print <var>A+B</var>, which is <var>8</var> since <var>A=3</var> and <var>B=5</var>. </p></section> </div> </span>
p03392
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of <code>a</code>,<code>b</code> and <code>c</code>. Find the number of strings that can be possibly obtained by repeatedly performing the following operation zero or more times, modulo <var>998244353</var>:</p> <ul> <li>Choose an integer <var>i</var> such that <var>1\leq i\leq |S|-1</var> and the <var>i</var>-th and <var>(i+1)</var>-th characters in <var>S</var> are different. Replace each of the <var>i</var>-th and <var>(i+1)</var>-th characters in <var>S</var> with the character that differs from both of them (among <code>a</code>, <code>b</code> and <code>c</code>).</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq |S| \leq 2 × 10^5</var></li> <li><var>S</var> consists of <code>a</code>, <code>b</code> and <code>c</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of strings that can be possibly obtained by repeatedly performing the operation, modulo <var>998244353</var>.</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>3 </pre> <p><code>abc</code>, <code>aaa</code> and <code>ccc</code> can be obtained.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>abbac </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>65 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>babacabac </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6310 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>ababacbcacbacacbcbbcbbacbaccacbacbacba </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>148010497 </pre></section> </div> </span>
p01655
<h2>Problem Statement</h2> <p> You bought 3 ancient scrolls from a magician. These scrolls have a long string, and the lengths of the strings are the same. He said that these scrolls are copies of the key string to enter a dungeon with a secret treasure. However, he also said, they were copied so many times by hand, so the string will contain some errors, though the length seems correct. </p> <p> Your job is to recover the original string from these strings. When finding the original string, you decided to use the following assumption. </p> <ul> <li> The copied string will contain at most <var>d</var> errors. In other words, the Hamming distance of the original string and the copied string is at most <var>d</var>. </li> <li> If there exist many candidates, the lexicographically minimum string is the original string.</li> </ul> <p> Can you find the orignal string? </p> <h2>Input</h2> <p> The input contains a series of datasets. </p> <p> Each dataset has the following format: </p> <pre> <var>l</var> <var>d</var> <var>str_1</var> <var>str_2</var> <var>str_3</var> </pre> <p> The first line contains two integers <var>l</var> (<var>1 \leq l \leq 100,000</var>) and <var>d</var> (<var>0 \leq d \leq 5,000</var>.) <var>l</var> describes the length of 3 given strings and <var>d</var> describes acceptable maximal Hamming distance. The following 3 lines have given strings, whose lengths are <var>l</var>. These 3 strings consist of only lower and upper case alphabets. </p> <p> The input ends with a line containing two zeros, which should not be processed. </p> <h2>Output</h2> <p> Print the lexicographically minimum satisfying the condition in a line. If there do not exist such strings, print <code>-1</code>. </p> <h2>Sample Input</h2> <pre> 3 1 ACM IBM ICM 5 2 iwzwz iziwi zwizi 1 0 A B C 10 5 jLRNlNyGWx yyLnlyyGDA yLRnvyyGDA 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> ICM iwiwi -1 AARAlNyGDA </pre>
p03668
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices numbered <var>1, 2, ..., N</var>. The edges of the tree are denoted by <var>(x_i, y_i)</var>.</p> <p>On this tree, Alice and Bob play a game against each other. Starting from Alice, they alternately perform the following operation:</p> <ul> <li>Select an existing edge and remove it from the tree, disconnecting it into two separate connected components. Then, remove the component that does not contain Vertex <var>1</var>.</li> </ul> <p>A player loses the game when he/she is unable to perform the operation. Determine the winner of the game assuming that both players play optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100000</var></li> <li><var>1 \leq x_i, y_i \leq N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_{N-1}</var> <var>y_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>Alice</code> if Alice wins; print <code>Bob</code> if Bob wins.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 2 3 2 4 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Alice </pre> <p>If Alice first removes the edge connecting Vertices <var>1</var> and <var>2</var>, the tree becomes a single vertex tree containing only Vertex <var>1</var>. Since there is no edge anymore, Bob cannot perform the operation and Alice wins.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 2 2 3 1 4 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Bob </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 2 4 5 1 6 3 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Alice </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>7 1 2 3 7 4 6 2 3 2 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Bob </pre></section> </div> </span>
p00947
<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 B Quality of Check Digits </h2> <p> The small city where you live plans to introduce a new social security number (SSN) system. Each citizen will be identified by a five-digit SSN. Its first four digits indicate the basic ID number (0000 - 9999) and the last one digit is a <i>check digit</i> for detecting errors. </p> <p> For computing check digits, the city has decided to use an operation table. An operation table is a 10 $\times$ 10 table of decimal digits whose diagonal elements are all 0. Below are two example operation tables. </p> <center> <table> <tr> <td> Operation Table 1 </td> <td>&nbsp;&nbsp;&nbsp;&nbsp;</td> <td> Operation Table 2 </td> </tr> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2016_Table_B1"> </td> <td>&nbsp;&nbsp;&nbsp;&nbsp;</td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2016_Table_B2"> </td> </tr> </table> </center> <br/> <p> Using an operation table, the check digit $e$ for a four-digit basic ID number $abcd$ is computed by using the following formula. Here, $i \otimes j$ denotes the table element at row $i$ and column $j$.<br/> <br/> $e = (((0 \otimes a) \otimes b) \otimes c) \otimes d$ <br/><br/> For example, by using Operation Table 1 the check digit $e$ for a basic ID number $abcd = $ 2016 is computed in the following way.<br/> <br/> $e = (((0 \otimes 2) \otimes 0) \otimes 1) \otimes 6$<br/> $\;\;\; = (( \;\;\;\;\;\;\;\;\; 1 \otimes 0) \otimes 1) \otimes 6$<br/> $\;\;\; = ( \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 7 \otimes 1) \otimes 6$<br/> $\;\;\; = \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 9 \otimes 6$<br/> $\;\;\; = \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 6$<br/> <br/> Thus, the SSN is 20166. </p> <p> Note that the check digit depends on the operation table used. With Operation Table 2, we have $e = $ 3 for the same basic ID number 2016, and the whole SSN will be 20163. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2016_Figure_B1"><br/> Figure B.1. Two kinds of common human errors </center><br/> <p> The purpose of adding the check digit is to detect human errors in writing/typing SSNs. The following <span>check</span> function can detect certain human errors. For a five-digit number $abcde$, the check function is defined as follows. </p> <center> <span>check</span>($abcde$) $ = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e$<br/> </center> <br/> <p> This function returns 0 for a correct SSN. This is because every diagonal element in an operation table is 0 and for a correct SSN we have $e = (((0 \otimes a) \otimes b) \otimes c) \otimes d$:<br/> </p> <center> <span>check</span>($abcde$) $ = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e = e \otimes e = 0$<br/> </center> <br/> <p> On the other hand, a non-zero value returned by check indicates that the given number cannot be a correct SSN. Note that, depending on the operation table used, check function may return 0 for an incorrect SSN. Kinds of errors detected depends on the operation table used; the table decides the quality of error detection. </p> <p> The city authority wants to detect two kinds of common human errors on digit sequences: altering one single digit and transposing two adjacent digits, as shown in Figure B.1. </p> <p> An operation table is good if it can detect all the common errors of the two kinds on all SSNs made from four-digit basic ID numbers 0000{9999. Note that errors with the check digit, as well as with four basic ID digits, should be detected. For example, Operation Table 1 is good. Operation Table 2 is not good because, for 20613, which is a number obtained by transposing the 3rd and the 4th digits of a correct SSN 20163, <span>check</span>(20613) is 0. Actually, among 10000 basic ID numbers, Operation Table 2 cannot detect one or more common errors for as many as 3439 basic ID numbers. </p> <p> Given an operation table, decide how good it is by counting the number of basic ID numbers for which the given table cannot detect one or more common errors. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format.<br/> <br/> $x_{00}$ $x_{01}$ ... $x_{09}$<br/> ...<br/> $x_{90}$ $x_{91}$ ... $x_{99}$<br/> </p> <p> The input describes an operation table with $x_{ij}$ being the decimal digit at row $i$ and column $j$. Each line corresponds to a row of the table, in which elements are separated by a single space. The diagonal elements $x_{ii}$ ($i = 0, ... , 9$) are always 0. </p> <h3>Output</h3> <p> Output the number of basic ID numbers for which the given table cannot detect one or more common human errors. </p> <h3>Sample Input 1</h3> <pre>0 3 1 7 5 9 8 6 4 2 7 0 9 2 1 5 4 8 6 3 4 2 0 6 8 7 1 3 5 9 1 7 5 0 9 8 3 4 2 6 6 1 2 3 0 4 5 9 7 8 3 6 7 4 2 0 9 5 8 1 5 8 6 9 7 2 0 1 3 4 8 9 4 5 3 6 2 0 1 7 9 4 3 8 6 1 7 2 0 5 2 5 8 1 4 3 6 7 9 0</pre> <h3>Sample Output 1</h3> <pre>0</pre> <br/> <h3>Sample Input 2</h3> <pre>0 1 2 3 4 5 6 7 8 9 9 0 1 2 3 4 5 6 7 8 8 9 0 1 2 3 4 5 6 7 7 8 9 0 1 2 3 4 5 6 6 7 8 9 0 1 2 3 4 5 5 6 7 8 9 0 1 2 3 4 4 5 6 7 8 9 0 1 2 3 3 4 5 6 7 8 9 0 1 2 2 3 4 5 6 7 8 9 0 1 1 2 3 4 5 6 7 8 9 0</pre> <h3>Sample Output 2</h3> <pre>3439</pre> <br/> <h3>Sample Input 3</h3> <pre>0 9 8 7 6 5 4 3 2 1 1 0 9 8 7 6 5 4 3 2 2 1 0 9 8 7 6 5 4 3 3 2 1 0 9 8 7 6 5 4 4 3 2 1 0 9 8 7 6 5 5 4 3 2 1 0 9 8 7 6 6 5 4 3 2 1 0 9 8 7 7 6 5 4 3 2 1 0 9 8 8 7 6 5 4 3 2 1 0 9 9 8 7 6 5 4 3 2 1 0</pre> <h3>Sample Output 3</h3> <pre>9995</pre> <br/> <h3>Sample Input 4</h3> <pre>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</pre> <h3>Sample Output 4</h3> <pre>10000</pre>
p02429
<h1>Enumeration of Subsets III</h1> <p> You are given a set $T$, which is a subset of $S$. The set $S$ consists of $0, 1, ... n-1$. Print all subsets of $T$. 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 28$</li> <li>$0 \leq k \leq 18$</li> <li>$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> 0: 1: 0 4: 2 5: 0 2 </pre>
p00414
<h1>へびの脱皮</h1> <p> セアブリ高原で発見された新種のへびは、頭から尾にかけて1列に並んだマル(o)とバツ(x)からなる模様が特徴です。下図に例を示しますが、へびの模様は個体により様々です。 </p> <pre> xxoooxxxoox </pre> <p> このへびは脱皮のときに、2つのマルが並んだ部分の間すべてが伸びることで成長します。新たに加わった箇所にはマル、バツ、マルが並んだ模様が付きます。 </p> <p> たとえば、長さ3のへび<span>ooo</span>が1回脱皮すると、左から1番目と2番目、2番目と3番目のマルの間にマル、バツ、マルが並んだ模様が加わるので、脱皮後のへびは<span>ooxoooxoo</span>となります(下線部が新たに加わった箇所です)。もう一回脱皮すると<span>ooxooxooxoooxooxooxoo</span> となり、へびの長さは21になります。 </p> <p> このへびの生態を研究しているあなたは、このへびが脱皮を繰り返したら、とてつもない長さになってしまうかもしれないと危惧しています。 </p> <p> へびの模様と脱皮の回数が与えられたとき、この回数だけ脱皮した後のへびの長さを求めるプログラムを作成せよ。 </p> <h2>入力</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> $L$ $N$ $snake$ </pre> <p> 1行目に脱皮する前の蛇の長さ$L$($1\leq L \leq 100$)と脱皮の回数$N$ ($1 \leq N \leq 50$)が与えられる。続く1行に脱皮する前のへびの模様を表す長さ$L$の文字列$snake$が与えられる。ただし$snake$は英小文字<span>x</span>と<span>o</span>からなる。 </p> <h2>出力</h2> <p> へびの長さを1行に出力する。 </p> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 3 2 ooo </pre> <h3>出力例1</h3> <pre> 21 </pre> <h3>入力例2</h3> <pre> 3 4 xoo </pre> <h3>出力例2</h3> <pre> 48 </pre> <h3>入力例3</h3> <pre> 13 30 xooxoooxxxoox </pre> <h3>出力例3</h3> <pre> 12884901889 </pre>
p02583
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have sticks numbered <var>1, \cdots, N</var>. The length of Stick <var>i</var> <var>(1 \leq i \leq N)</var> is <var>L_i</var>.</p> <p>In how many ways can we choose three of the sticks with different lengths that can form a triangle?</p> <p>That is, find the number of triples of integers <var>(i, j, k)</var> <var>(1 \leq i &lt; j &lt; k \leq N)</var> that satisfy both of the following conditions:</p> <ul> <li><var>L_i</var>, <var>L_j</var>, and <var>L_k</var> are all different.</li> <li>There exists a triangle whose sides have lengths <var>L_i</var>, <var>L_j</var>, and <var>L_k</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq L_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>L_1</var> <var>L_2</var> <var>\cdots</var> <var>L_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to choose three of the sticks with different lengths that can form a triangle.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 4 9 7 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>The following five triples <var>(i, j, k)</var> satisfy the conditions: <var>(1, 3, 4)</var>, <var>(1, 4, 5)</var>, <var>(2, 3, 4)</var>, <var>(2, 4, 5)</var>, and <var>(3, 4, 5)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 4 5 4 3 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> <p>We have two sticks for each of the lengths <var>3</var>, <var>4</var>, and <var>5</var>. To satisfy the first condition, we have to choose one from each length.</p> <p>There is a triangle whose sides have lengths <var>3</var>, <var>4</var>, and <var>5</var>, so we have <var>2 ^ 3 = 8</var> triples <var>(i, j, k)</var> that satisfy the conditions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 9 4 6 1 9 6 10 6 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>39 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 </pre> <p>No triple <var>(i, j, k)</var> satisfies <var>1 \leq i &lt; j &lt; k \leq N</var>, so we should print <var>0</var>.</p></section> </div> </span>
p02079
<h1>B: Spent Fuel Disposal</h1> <h2>問題文</h2> <p>$N$ 個の下水処理施設が $M$ 本のパイプで繋がっており、$i$ 番目のパイプは $u_i$ 番目と $v_i$ 番目の施設を繋いでいます。 パイプは全て、毎秒最大 $1$ リットルの液体を流すことができます、 </p> <p>今、$S$ 番目の施設から $T$ 番目の施設へ工業廃水を、 $U$ 番目の施設から $V$ 番目の施設へ純水を流したいです。$S$ 番目および $U$ 番目の施設は、それぞれ工業廃水および純水を十分な量有しており、パイプで繋がっている別の施設へこれらの液体を好きに送ることができます。 また、各施設では、送られてきた液体をパイプで繋がっている別の処理施設へ流すことができます。</p> <p>パイプはハイテクなので、$2$ 種類の液体を同時に好きな方向へ流すことができます。 例えば、$i$ 番目のパイプは、$u_i$ から $v_i$ へ工業廃水を、$v_i$ から $u_i$ へ純水を流すことができます。 反対に $v_i$ から $u_i$ へ工業廃水を、$u_i$ から $v_i$ へ純水を流すことも可能です。 もちろん、$2$ 種類の液体を同じ方向へ流すこともできます。 </p> <p>ただし、どの場合においても、$1$ つのパイプに流す液体の総量は毎秒 $1$ リットルを超えることはできません。 $S$ から $T$ へ流す工業廃水の総量と $U$ から $V$ へ流す純水の総量の合計は、最大で毎秒何リットルにできますか。 答えは整数になることが証明できるため、整数で出力してください。</p> <h2>制約</h2> <ul> <li>入力は全て整数</li> <li>$1 \leq N, M \leq 10^5$</li> <li>$1 \leq S, T, U, V \leq N$</li> <li>$S \neq T$</li> <li>$U \neq V$</li> <li>$1 \leq u_i, v_i \leq N$</li> <li>$u_i &lt; v_i$ ($i = 1, \ldots, M$)</li> <li>$i \neq j \rightarrow (u_i, v_i) \neq (u_j, v_j)$</li> <li>全ての施設はパイプを通じて連結である</li> </ul> <h2>入力</h2> <p>入力は標準入力から以下の形式で与えられます。</p> <pre>$N$ $M$ $S$ $T$ $U$ $V$ $u_1$ $v_1$ $\vdots$ $u_M$ $v_M$</pre> <h2>出力</h2> <p>答えを1行に出力してください。</p> <h2>入出力例</h2> <h3>入力例1</h3> <pre>5 6 1 4 2 3 1 2 2 3 3 4 4 5 3 5 1 5 </pre> <h3>出力例1</h3> <pre>2 </pre> <p>例えば、$1$ から $5$、$5$ から $4$ へ工業排水を毎秒 $1$ リットル、$2$ から $3$ へ純水を毎秒 $1$ リットル流せば良いです。</p> <h3>入力例2</h3> <pre>3 3 1 2 1 3 1 2 1 3 2 3 </pre> <h3>出力例2</h3> <pre>2 </pre> <p>$T$ と $V$ が同一の施設であるケースなどに注意してください。</p>
p00044
<H1>素数 II</H1> <p> 素数というのは、1 よりも大きくそれ自身か 1 でしか割りきれない整数をいいます。例えば、2 は、2 と 1 でしか割り切れないので素数ですが、12 は、12 と 1 のほかに、2, 3, 4, 6 で割りきれる数なので素数ではありません。 </p> <p> 整数 <var>n</var> を入力したとき、<var>n</var> より小さい素数のうち最も大きいものと、<var>n</var> より大きい素数のうち最も小さいものを出力するプログラムを作成してください。 </p> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットに <var>n</var> (3 &le; <var>n</var> &le; 50,000) が1行に与えられます。 </p> <p> データセットの数は 50 を超えません。 </p> <H2>Output</H2> <p> 各データセットに対して、<var>n</var> より小さい素数のうち最大のものと、<var>n</var> より大きい素数のうち最小のものを1つのスペースで区切って1行に出力して下さい。 </p> <H2>Sample Input</H2> <pre> 19 3517 </pre> <H2>Output for the Sample Input</H2> <pre> 17 23 3511 3527 </pre>
p00551
<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>縄張り(Territory)</h2> <p> あなたは南北方向にとても長く伸びたたくさんの道路と,東西方向にとても長く伸びたたくさんの道路が交わった形をした街に住んでいる.隣り合う2 つの南北方向の道路の間隔は 1 km である.また,隣り合う 2 つの東西方向の道路の間隔も 1 km である. </p> <p> この街には市役所が 1 つある.市役所のある交差点を $(0,0)$ と表す.この街の交差点は 2 つの整数 $i, j$ を用いて交差点 $(i, j)$ と表される.すなわち,交差点 $(i, j)$ とは,交差点 $(0,0)$ から東に $i$ km ($i < 0$ のときは西に $-i$ km),北に $j$ km ( $j < 0$ のときは南に $-j$ km) 進んだ位置の交差点を表す. </p> <p> 市役所ではジョイ君という名の 1 匹の犬を飼っている.ジョイ君は $K$ 日間の散歩の計画を立てた.散歩の計画は以下の通りである. </p> <ul> <li> $K$ 日のうち最初の日の朝にはジョイ君は交差点 $(0,0)$ にいる.ジョイ君は交差点 $(0,0)$ に印を付ける.$(0,0)$ 以外にはジョイ君が印を付けた交差点はない.</li> <li> $K$ 日のそれぞれの日の昼に散歩を行う.1 日の散歩は $N$ 回のステップからなる.各ステップでは交差点から隣の交差点へと移動し,移動先に印を付ける.ジョイ君がそれぞれの日の昼にどう移動するかは日によらず一定である.</li> <li> 昼の移動が終わった後は,現在いる交差点で次の日の朝まで寝る.</li> </ul> <p> 市役所では $K$ 日間の散歩によってできるジョイ君の縄張りについて話題になっている.4 つの交差点 $(a,b),(a + 1,b),(a + 1,b + 1),(a,b + 1)$ のいずれにもジョイ君が 1 回以上印を付けているとき,4 つの交差点で囲まれた区画はジョイ君の縄張りに属する. </p> <p> あなたは,ジョイ君の散歩計画から,ジョイ君の縄張りに属する区画の個数を計算するプログラムを作成することとなった. </p> <p> この街の道路はとても長く,また,南北方向にも東西方向にも十分たくさんの道路があるため,散歩の途中でジョイ君が道路の端や街の端に到達することはない. </p> <h2>課題</h2> <p> ジョイ君の散歩計画が与えられると,ジョイ君の縄張りに属する区画の個数を求めるプログラムを作成せよ. </p> <h2>入力</h2> <p> 標準入力から以下の入力を読み込め. </p> <ul> <li> 1 行目には 2 個の整数 $N, K$ が空白を区切りとして書かれている.これはそれぞれの日の散歩が $N$ 回のステップからなり,散歩計画が $K$ 日間に渡ることを表している.</li> <li> 2 行目には長さ $N$ の文字列 $S$ が書かれている.文字列 $S$ のうち左から $p$ 文字目 $(1 \leq p \leq N)$ の文字 $C_p$ は E,N,W,S のいずれかである.これらの文字は以下のことを表す.<br> &nbsp;&nbsp;&nbsp;&nbsp; 文字 $C_p$ が E であるならば,$p$ 番目のステップで東隣の交差点に移動することを表す.<br> &nbsp;&nbsp;&nbsp;&nbsp; 文字 $C_p$ が N であるならば,$p$ 番目のステップで北隣の交差点に移動することを表す.<br> &nbsp;&nbsp;&nbsp;&nbsp; 文字 $C_p$ が W であるならば,$p$ 番目のステップで西隣の交差点に移動することを表す.<br> &nbsp;&nbsp;&nbsp;&nbsp; 文字 $C_p$ が S であるならば,$p$ 番目のステップで南隣の交差点に移動することを表す.<br> ここで,交差点$(i, j)$ に対して東隣,北隣,西隣,南隣の交差点はそれぞれ,交差点 $(i + 1, j)$,交差点$(i, j + 1)$,交差点$(i - 1, j)$,交差点$(i, j - 1)$ である. </li> </ul> <h2>出力</h2> <p> 標準出力に,ジョイ君の縄張りに属する区画の個数を 1 行で出力せよ. </p> <h2>制限</h2> <p> すべての入力データは以下の条件を満たす. </p> <ul> <li> $1 \leq N \leq 100 000$</li> <li> $1 \leq K \leq 1 000 000 000$</li> </ul> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 12 1 EENWSEEESWWS </pre> <h3>出力例1</h3> <pre> 3 </pre> <p> この入力例では,散歩は 1 日間で行われる.1 日目にジョイ君は市役所から出発して下図のように移動する.黒丸はジョイ君が印を付けた交差点,白丸はジョイ君が印を付けていない交差点,二重丸は市役所のある交差点,数字は各ステップを表す. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_territory1"><br> ジョイ君の移動経路 </center> <p> 入力例 1 において,下図の斜線部分で示された 3 個の区画がジョイ君の縄張りに属する.</p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_territory2"><br> 入力例1 におけるジョイ君の縄張り </center> <h3>入力例2</h3> <pre> 12 2 EENWSEEESWWS </pre> <h3>出力例2</h3> <pre> 7 </pre> <p> 入力例 2 では,散歩が 2 日間に渡り行われる.それぞれの日の移動経路は入力例 1 と同一である.散歩が完了したとき,下図の斜線部分で示された 7 個の区画がジョイ君の縄張りに属する. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_territory3"><br> 入力例2 におけるジョイ君の縄張り </center> <!-- <p> 入力例 2 は,小課題 1 および小課題 2 の制約を満たさないことに注意せよ. </p> --> <h3>入力例3</h3> <pre> 7 1 ENNWNNE </pre> <h3>出力例3</h3> <pre> 0 </pre> <p> 入力例 3 では,ジョイ君の縄張りに属する区画は存在しない. </p> <h3>入力例4</h3> <pre> 16 5 WSESSSWWWEEENNNW </pre> <h3>出力例4</h3> <pre> 21 </pre> <!-- <p> 入力例 4 は,小課題1 および小課題 2 の制約を満たさないことに注意せよ. </p> --> <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>
p02096
<h2>I: Add</h2> <h3>Problem Statement</h3> <p>Mr. T has had an integer sequence of <var>N</var> elements <var>a_1, a_2, ... , a_N</var> and an integer <var>K</var>. Mr. T has created <var>N</var> integer sequences <var>B_1, B_2, ... , B_N</var> such that <var>B_i</var> has <var>i</var> elements.</p> <ul> <li> <var>B_{N,j} = a_j</var> (<var>1 \leq j \leq N</var>) </li> <li> <var>B_{i,j} = K \times B_{i+1,j} + B_{i+1,j+1}</var> (<var>1\leq i \leq N-1, 1 \leq j \leq i</var>)</li> </ul> <p>Mr. T was so careless that he lost almost all elements of these sequences <var>a</var> and <var>B_i</var>. Fortunately, <var>B_{1,1}, B_{2,1}, ... , B_{N,1}</var> and <var>K</var> are not lost. Your task is to write a program that restores the elements of the initial sequence <var>a</var> for him. Output the modulo <var>65537</var> of each element instead because the absolute value of these elements can be extremely large. More specifically, for all integers <var>i</var> (<var>1 \leq i \leq N</var>), output <var>r_i</var> that satisfies <var>r_i </var> $\equiv$ <var>a_i</var> $ \bmod \;$ <var>65537, 0 \leq r_i &lt; 65537</var>. Here, we can prove that the original sequence Mr. T had can be uniquely determined under the given constraints.</p> <h3>Input</h3> <pre> <var>T</var> <var>N_1</var> <var>K_1</var> <var>C_{1,1}</var> <var>C_{1,2}</var> <var>...</var> <var>C_{1,N}</var> <var>N_2</var> <var>K_2</var> <var>C_{2,1}</var> <var>C_{2,2}</var> <var>...</var> <var>C_{2,N}</var> <var>:</var> <var>N_T</var> <var>K_T</var> <var>C_{T,1}</var> <var>C_{T,2}</var> <var>...</var> <var>C_{T,N}</var> </pre> <p>The first line contains a single integer <var>T</var> that denotes the number of test cases. Each test case consists of 2 lines. The first line of the <var>i</var>-th test case contains two integers <var>N_i</var> and <var>K_i</var>. The second line of the <var>i</var>-th test case contains <var>N_i</var> integers <var>C_{i,j}</var> (<var>1 \leq j \leq N_i</var>). These values denote that <var>N = N_i , K = K_i , B_{j,1} = C_{i,j}</var> (<var>1 \leq j \leq N_i</var>) in the <var>i</var>-th test case.</p> <h3>Constraints</h3> <ul> <li> <var>1 \leq T \leq 10</var></li> <li> <var>1 \leq N \leq 50000</var></li> <li> <var>|K| \leq 10^9</var></li> <li> <var>|B_{i,1}| \leq 10^9</var> </li> <li> All input values are integers.</li> </ul> <h3>Output</h3> <p>Output <var>T</var> lines. For the <var>i</var>-th line, output the answer for the <var>i</var>-th test case <var>a_1, a_2, ..., a_N</var> in this order. Each number must be separated by a single space.</p> <h3>Sample Input 1</h3> <pre> 2 3 0 1 2 3 3 1 1 2 3 </pre> <h3>Output for Sample Input 1</h3> <pre> 3 2 1 3 65536 0 </pre>
p00101
<H1>Aizu PR</H1> <p> An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina". </p> <p> Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000. </p> <H2>Input</H2> <p> The input consists of several datasets. There will be the number of datasets <i>n</i> in the first line. There will be <i>n</i> lines. A line consisting of english texts will be given for each dataset. </p> <H2>Output</H2> <p> For each dataset, print the converted texts in a line. </p> <H2>Sample Input</H2> <pre> 3 Hoshino Hashino Masayuki Hoshino was the grandson of Ieyasu Tokugawa. </pre> <H2>Output for the Sample Input</H2> <pre> Hoshina Hashino Masayuki Hoshina was the grandson of Ieyasu Tokugawa. </pre>
p01340
<H1><font color="#000">Problem B: </font> Kaeru Jump</H1> <p> There is a frog living in a big pond. He loves jumping between lotus leaves floating on the pond. Interestingly, these leaves have strange habits. First, a leaf will sink into the water after the frog jumps from it. Second, they are aligned regularly as if they are placed on the grid points as in the example below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kaeru1"><br> <b>Figure 1: Example of floating leaves</b> </center> <p> Recently, He came up with a puzzle game using these habits. At the beginning of the game, he is on some leaf and faces to the upper, lower, left or right side. He can jump forward or to the left or right relative to his facing direction, but not backward or diagonally. For example, suppose he is facing to the left side, then he can jump to the left, upper and lower sides but not to the right side. In each jump, he will land on the nearest leaf on his jumping direction and face to that direction regardless of his previous state. The leaf he was on will vanish into the water after the jump. The goal of this puzzle is to jump from leaf to leaf until there is only one leaf remaining. </p> <p> See the example shown in the figure below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kaeru2"> </center> <p> In this situation, he has three choices, namely, the leaves A, B and C. Note that he cannot jump to the leaf D since he cannot jump backward. Suppose that he choose the leaf B. After jumping there, the situation will change as shown in the following figure. </p> <p> He can jump to either leaf E or F next. </p> <p> After some struggles, he found this puzzle difficult, since there are a lot of leaves on the pond. Can you help him to find out a solution? </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_kaeru3"> </center> <H2>Input</H2> <p> <i>H W</i><br> <i>c</i><sub>1,1</sub> ... <i>c</i><sub>1,<i>W</i></sub><br> .<br> .<br> .<br> <i>c</i><sub><i>H</i>,1</sub> ... <i>c</i><sub><i>H</i>,<i>W</i></sub><br> </p> <p> The first line of the input contains two positive integers <i>H</i> and <i>W</i> (1 &le; <i>H</i>,<i>W</i> &le; 10). The following <i>H</i> lines, which contain <i>W</i> characters each, describe the initial configuration of the leaves and the frog using following characters: </p> <ul> <li>'.’ : water</li> <li> ‘o’ : a leaf</li> <li> ‘U’ : a frog facing upward (i.e. to the upper side) on a leaf</li> <li> ‘D’ : a frog facing downward (i.e. to the lower side) on a leaf</li> <li> ‘L’ : a frog facing leftward (i.e. to the left side) on a leaf</li> <li> ‘R’ : a frog facing rightward (i.e. to the right side) on a leaf</li> </ul> <p> You can assume that there is only one frog in each input. You can also assume that the total number of leaves (including the leaf the frog is initially on) is at most 30. </p> <H2>Output</H2> <p> Output a line consists of the characters ‘U’ (up), ‘D’ (down), ‘L’ (left) and ‘R’ (right) that describes a series of movements. The output should not contain any other characters, such as spaces. You can assume that there exists only one solution for each input. </p> <H2>Sample Input 1</H2> <pre> 2 3 Uo. .oo </pre> <H2>Output for the Sample Input 1</H2> <pre> RDR </pre> <H2>Sample Input 2</H2> <pre> 10 10 .o....o... o.oo...... ..oo..oo.. ..o....... ..oo..oo.. ..o...o.o. o..U.o.... oo......oo oo........ oo..oo.... </pre> <H2>Output for the Sample Input 2</H2> <pre> URRULULDDLUURDLLLURRDLDDDRRDR </pre> <H2>Sample Input 3</H2> <pre> 10 1 D . . . . . . . . o </pre> <H2>Output for the Sample Input 3</H2> <pre> D </pre>
p03687
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke can change a string <var>t</var> of length <var>N</var> into a string <var>t'</var> of length <var>N - 1</var> under the following rule:</p> <ul> <li>For each <var>i</var> (<var>1 ≤ i ≤ N - 1</var>), the <var>i</var>-th character of <var>t'</var> must be either the <var>i</var>-th or <var>(i + 1)</var>-th character of <var>t</var>.</li> </ul> <p>There is a string <var>s</var> consisting of lowercase English letters. Snuke's objective is to apply the above operation to <var>s</var> repeatedly so that all the characters in <var>s</var> are the same. Find the minimum necessary number of operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ |s| ≤ 100</var></li> <li><var>s</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum necessary number of operations to achieve the objective.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>serval </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>One solution is: <code>serval</code> → <code>srvvl</code> → <code>svvv</code> → <code>vvv</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>jackal </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>One solution is: <code>jackal</code> → <code>aacaa</code> → <code>aaaa</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>zzz </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>All the characters in <var>s</var> are the same from the beginning.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>whbrjpjyhsrywlqjxdbrbaomnw </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>8 </pre> <p>In <var>8</var> operations, he can change <var>s</var> to <code>rrrrrrrrrrrrrrrrrr</code>.</p></section> </div> </span>
p02995
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given four integers <var>A</var>, <var>B</var>, <var>C</var>, and <var>D</var>. Find the number of integers between <var>A</var> and <var>B</var> (inclusive) that can be evenly divided by neither <var>C</var> nor <var>D</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1\leq A\leq B\leq 10^{18}</var></li> <li><var>1\leq C,D\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>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of integers between <var>A</var> and <var>B</var> (inclusive) that can be evenly divided by neither <var>C</var> nor <var>D</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 9 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p><var>5</var> and <var>7</var> satisfy the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 40 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>23 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314159265358979323 846264338327950288 419716939 937510582 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>532105071133627368 </pre></section> </div> </span>
p01710
<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>You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. </p> <p>There are $M$ links between the websites, and we can move between websites using these links. You can assume that it doesn't take time to move between websites. These links are directed and websites may have links to themselves. </p> <p>In each website $i$, there is an advertisement and we can get $p_i$ point(s) by watching this advertisement in $t_i$ seconds. When we start on or move into a website, we can decide whether to watch the advertisement or not. But we cannot watch the same advertisement more than once before using any link in the website, while we can watch it again if we have moved among websites and returned to the website using one or more links, including ones connecting a website to itself. Also we cannot watch the advertisement in website $i$ more than $k_i$ times. </p> <p>You want to win this contest by collecting as many points as you can. So you decided to compute the maximum points that you can collect within $T$ seconds. </p> </div><div class="part"><h3>Input</h3> <p>The input consists of multiple datasets. The number of dataset is no more than $60$. </p> <p>Each dataset is formatted as follows. </p> <blockquote style="font-size:14pt">$N$ $M$ $T$<br>$p_1$ $t_1$ $k_1$<br>:<br>:<br>$p_N$ $t_N$ $k_N$<br>$a_1$ $b_1$<br>:<br>:<br>$a_M$ $b_M$</blockquote> <p>The first line of each dataset contains three integers $N$ ($1 \le N \le 100$), $M$ ($0 \le M \le 1{,}000$) and $T$ ($1 \le T \le 10{,}000$), which denote the number of websites, the number of links, and the time limit, respectively. All the time given in the input is expressed in seconds. </p> <p>The following $N$ lines describe the information of advertisements. The $i$-th of them contains three integers $p_i$ ($1 \le p_i \le 10{,}000$), $t_i$ ($1 \le t_i \le 10{,}000$) and $k_i$ ($1 \le k_i \le 10{,}000$), which denote the points of the advertisement, the time required to watch the advertisement, and the maximum number of times you can watch the advertisement in website $i$, respectively. </p> <p>The following $M$ lines describe the information of links. Each line contains two integers $a_i$ and $b_i$ ($1 \le a_i,b_i \le N$), which mean that we can move from website $a_i$ to website $b_i$ using a link. </p> <p>The end of input is indicated by a line containing three zeros. </p> </div><div class="part"><h3>Output</h3> <p>For each dataset, output the maximum points that you can collect within $T$ seconds. </p> </div><div class="part"><h3>Sample Input</h3> <pre>5 4 10 4 3 1 6 4 3 3 2 4 2 2 1 8 5 3 1 2 2 3 3 4 4 5 3 3 1000 1000 1 100 1 7 100 10 9 100 1 2 2 3 3 2 1 0 5 25 25 2 1 0 25 25 25 2 5 5 100 1 1 20 1 1 20 10 1 1 10 1 1 10 1 1 1 2 2 1 3 4 4 5 5 3 3 3 100 70 20 10 50 15 20 90 10 10 1 2 2 2 2 3 0 0 0</pre> </div><div class="part"><h3>Output for the Sample Input</h3> <pre>15 2014 0 25 40 390</pre> </div>
p00802
<H1><font color="#000">Problem G:</font> Telescope</H1> <p> Dr. Extreme experimentally made an extremely precise telescope to investigate extremely curi- ous phenomena at an extremely distant place. In order to make the telescope so precise as to investigate phenomena at such an extremely distant place, even quite a small distortion is not allowed. However, he forgot the influence of the internal gas affected by low-frequency vibration of magnetic flux passing through the telescope. The cylinder of the telescope is not affected by the low-frequency vibration, but the internal gas is. </p> <p> The cross section of the telescope forms a perfect circle. If he forms a coil by putting extremely thin wire along the (inner) circumference, he can measure (the average vertical component of) the temporal variation of magnetic flux:such measurement would be useful to estimate the influence. But points on the circumference at which the wire can be fixed are limited; furthermore, the number of special clips to fix the wire is also limited. To obtain the highest sensitivity, he wishes to form a coil of a polygon shape with the largest area by stringing the wire among carefully selected points on the circumference. </p> <p> Your job is to write a program which reports the maximum area of all possible <i>m</i>-polygons (polygons with exactly <i>m</i> vertices) each of whose vertices is one of the <i>n</i> points given on a circumference with a radius of 1. An example of the case <i>n</i> = 4 and <i>m</i> = 3 is illustrated below. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_telescope"> </center> <br> <p> In the figure above, the equations such as "<i>p</i><sub>1</sub> = 0.0" indicate the locations of the <i>n</i> given points, and the decimals such as "1.000000" on <i>m</i>-polygons indicate the areas of <i>m</i>-polygons. </p> <p> Parameter <i>p<sub>i</sub></i> denotes the location of the <i>i</i>-th given point on the circumference (1 &le; <i>i</i> &le; <i>n</i>). The location <i>p</i> of a point on the circumference is in the range 0 &le; <i>p</i> &lt; 1, corresponding to the range of rotation angles from 0 to 2<i>&pi;</i> radians. That is, the rotation angle of a point at <i>p</i> to the point at 0 equals 2<i>&pi;</i> radians. (<i>&pi;</i> is the circular constant 3.14159265358979323846....) </p> <p> You may rely on the fact that the area of an isosceles triangle ABC (AB = AC = 1) with an interior angle BAC of <i>&alpha;</i> radians (0 &lt; <i>&alpha;</i> &lt; <i>&pi;</i>) is (1/2)sin<i>&alpha;</i>, and the area of a polygon inside a circle with a radius of 1 is less than <i>&pi;</i>. <H2>Input</H2> <p> The input consists of multiple subproblems followed by a line containing two zeros that indicates the end of the input. Each subproblem is given in the following format. </p> <pre> <i>n m</i> <i>p</i><sub>1</sub> <i>p</i><sub>2</sub> ... <i>p</i><sub><i>n</i></sub> </pre> <p> <i>n</i> is the number of points on the circumference (3 &le; <i>n</i> &le; 40). <i>m</i> is the number of vertices to form <i>m</i>-polygons (3 &le; <i>m</i> &le; <i>n</i>). The locations of <i>n</i> points, <i>p</i><sub>1</sub>, <i>p</i><sub>2</sub>,..., <i>p<sub>n</sub></i>, are given as decimals and they are separated by either a space character or a newline. In addition, you may assume that 0 &le; <i>p</i><sub>1</sub> &lt; <i>p</i><sub>2</sub> &lt; ... &lt; <i>p<sub>n</sub></i> &lt; 1. </p> <H2>Output</H2> <p> For each subproblem, the maximum area should be output, each in a separate line. Each value in the output may not have an error greater than 0.000001 and its fractional part should be represented by 6 decimal digits after the decimal point. </p> <H2>Sample Input</H2> <pre> 4 3 0.0 0.25 0.5 0.666666666666666666667 4 4 0.0 0.25 0.5 0.75 30 15 0.00 0.03 0.06 0.09 0.12 0.15 0.18 0.21 0.24 0.27 0.30 0.33 0.36 0.39 0.42 0.45 0.48 0.51 0.54 0.57 0.61 0.64 0.66 0.69 0.72 0.75 0.78 0.81 0.84 0.87 40 20 0.351 0.353 0.355 0.357 0.359 0.361 0.363 0.365 0.367 0.369 0.371 0.373 0.375 0.377 0.379 0.381 0.383 0.385 0.387 0.389 0.611 0.613 0.615 0.617 0.619 0.621 0.623 0.625 0.627 0.629 0.631 0.633 0.635 0.637 0.639 0.641 0.643 0.645 0.647 0.649 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1.183013 2.000000 3.026998 0.253581 </pre>
p00228
<H1>7 セグメント</H1> <p> 電卓などでよく目にするデジタル数字を表示している画面は、デジタル数字が 7 つの部分(セグメン ト)で構成されることから、「7セグメントディスプレイ」と呼ばれています。 </p> <p> ワカマツ社で新しく売り出す予定の製品は、<!--デジタル数字の表示が必須のため、-->7セグメントディスプレイを製品に組み込むことになり、社員であるあなたは、与えられた数字を 7 セグメントディスプレイに表示するプログラムを作成することになりました。 </p> <p> この7セグメントディスプレイは、次の切り替えの指示が送られてくるまで表示状態は変わりません。7 ビットからなるシグナルを送ることで、それぞれ対応したセグメントの表示情報を切り替える事ができます。ビットとは 1 か 0 の値を持つもので、ここでは 1 が「切り替え」、0 が「そのまま」を表します。 </p> <!-- <p> 各ビットとセグメントの対応関係は下の図のようになっています。シグナルは 7 つのビットを"gfedcba"の順番になっています。例えば、非表示の状態から「0」を表示するためには"0111111"をシグナルとしてディスプレイに送らなければなりません。「0」から「5」に変更する場合には"1010010"を送ります。続けて「5」を「1」に変更する場合には"1101011"を送ります。 </p> --> <p> 各ビットとセグメントの対応関係は下の図のようになっています。シグナルは 7 つのビットを"gfedcba"の順番に送ります。例えば、非表示の状態から「0」を表示するためには"0111111"をシグナルとしてディスプレイに送らなければなりません。「0」から「5」に変更する場合には"1010010"を送ります。続けて「5」を「1」に変更する場合には"1101011"を送ります。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_7segments" width="60%" ><br/> <br/> </center> <p> 表示したい <var>n</var> (1 &le; <var>n</var> &le; 100) 個の数字を入力とし、それらの数字 <var>d<sub>i</sub></var> (0 &le; <var>d<sub>i</sub></var> &le; 9) を順に 7 セグメントディスプレイに正しく表示するために必要なシグナル列を出力するプログラムを作成してください。なお、7 セグメントディスプレイの初期状態は全て非表示の状態であるものとします。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりは-1 ひとつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>n</var> <var>d<sub>1</sub></var> <var>d<sub>2</sub></var> : <var>d<sub>n</sub></var> </pre> <p> データセットの数は 120 を超えません。 </p> <H2>Output</H2> <p> 入力データセットごとに、数字をディスプレイに正しく出力するために必要なシグナルの列を出力してください。 </p> <H2>Sample Input</H2> <pre> 3 0 5 1 1 0 -1 </pre> <H2>Output for the Sample Input</H2> <pre> 0111111 1010010 1101011 0111111 </pre>
p02215
<span class="lang"> <span class="lang-ja"> <h1>D: Xor Array</h1> <div class="part"> <section> <h3>問題文</h3><p>整数 $N$ と $X$ が与えられます。 以下の条件を満たす長さ $N$ の数列の個数を $998244353$ で割った余りを求めてください。</p> <ul> <li>数列は広義単調増加である。</li> <li>数列の各要素は $0$ 以上 $X$ 以下である。</li> <li>全ての要素の排他的論理和(xor)が $X$ である。</li> </ul> </section> </div> <div class="part"> <section> <h3>制約</h3><ul> <li>$1 \leq N \leq 500$ </li> <li>$0 \leq X \leq 500$</li> <li>$N$ と $X$ は整数である。</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以下の形式で標準入力から与えられる。</p> <pre>$N$ $X$ </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>答えを出力せよ。</p> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力例1</h3><pre>2 3 </pre> </section> </div> <div class="part"> <section> <h3>出力例1</h3><pre>2 </pre> <p>数列 $\{0,3\}$ と $\{1,2\}$ が条件を満たします。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力例2</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>出力例2</h3><pre>1 </pre> <p>数列 $\{1\}$ のみが条件を満たします。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力例3</h3><pre>224 239 </pre> </section> </div> <div class="part"> <section> <h3>出力例3</h3><pre>400351036 </pre></section> </div> </span> </span>
p03957
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>This contest is <code>CODEFESTIVAL</code>, which can be shortened to the string <code>CF</code> by deleting some characters. </p> <p>Mr. Takahashi, full of curiosity, wondered if he could obtain <code>CF</code> from other strings in the same way. </p> <p>You are given a string <var>s</var> consisting of uppercase English letters. Determine whether the string <code>CF</code> can be obtained from the string <var>s</var> by deleting some characters.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≤ |s| ≤ 100</var></li> <li>All characters in <var>s</var> are uppercase English letters (<code>A</code>-<code>Z</code>).</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>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>Yes</code> if the string <code>CF</code> can be obtained from the string <var>s</var> by deleting some characters. Otherwise print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>CODEFESTIVAL </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p><code>CF</code> is obtained by deleting characters other than the first character <code>C</code> and the fifth character <code>F</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>FESTIVALCODE </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p><code>FC</code> can be obtained but <code>CF</code> cannot be obtained because you cannot change the order of the characters.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>CF </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre> <p>It is also possible not to delete any characters.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>FCF </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Yes </pre> <p><code>CF</code> is obtained by deleting the first character.</p></section> </div> </span>
p00678
<h1>KND Runs for Sweets</h1> <h2>Problem</h2> <p>KND君は会津大学に在籍する学生プログラマである。彼は甘党であることで知られている。彼はとある市に1年間滞在することになり、その期間中に市内にある<var> N </var>箇所の甘味処をすべて回りたいと思っている。なのでこの1年間の住む場所は甘味処を回るのに一番適した場所がいいと考えている。彼の隣人であるあなたは、各甘味処への最悪の移動時間が最小になる場所を探す事になった。この甘味処がある市は簡単のため二次元平面で表すことにする。彼は目的の甘味処へのモチベーションの違いにより、単位時間あたりの移動距離が変化する。また、彼はどんな場所にでも(たとえ甘味処と同じ場所であろうと)住むつもりでいる。KND君は甘味に関しては妥協を許さないのである。</p> <h2>Input</h2> <p> 入力は複数のテストケースからなる。 ひとつのテストケースは以下のな形式で与えられる。 入力の終了を<var> N </var> = 0 のとき示す。 </p> <pre> <var>N</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>v<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>v<sub>2</sub></var> ... <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>v<sub>N</sub></var> </pre> <p>ここで、 </p> <ul> <li><var>N</var>:甘味処の数</li> <li><var>x<sub>i</sub></var>:i番目の甘味処のx座標</li> <li><var>y<sub>i</sub></var>:i番目の甘味処のy座標</li> <li><var>v<sub>i</sub></var>:i番目の甘味処へ移動するときの単位時間あたりの移動距離</li> </ul> <p> である。</p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>入力はすべて整数。</li> <li>2 &le; <var>N</var> &le; 100</li> <li>0 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 100</li> <li>1 &le; <var>v<sub>i</sub></var> &le; 100 ( 1 &le; <var>i</var> &le; <var>N</var> )</li> <li><var>x<sub>i</sub></var> &ne; <var>x<sub>j</sub></var> or <var>y<sub>i</sub></var> &ne; <var>y<sub>j</sub></var> ( ただし1 &le; <var>i</var> &lt; <var>j</var> &le; <var>N</var> )</li> </ul> <h2>Output</h2> <p>各テストケースにつき最悪の移動時間の最小値を一行に出力せよ。この値はジャッジ出力の値と10<sup>-5</sup>より大きい差を持ってはならない。</p> <h2>Sample Input</h2> <pre> 2 1 1 1 2 2 1 4 1 1 3 3 1 3 4 2 1 1 5 3 0 </pre> <h2>Sample Output</h2> <pre> 0.70710678 1.06066017 </pre>
p02645
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>When you asked some guy in your class his name, he called himself <var>S</var>, where <var>S</var> is a string of length between <var>3</var> and <var>20</var> (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from <var>S</var> and make it his nickname. Print a string that is a valid nickname for him.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq |S| \leq 20</var></li> <li><var>S</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print your answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>takahashi </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>tak </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>naohiro </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>nao </pre></section> </div> </span>
p00382
<h1>Taxi</h1>   <p> PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi stand in front of the station. </p> <p> In front of the station, there are $N$ parking spaces in row for PCK taxis, each with an index running from $1$ to $N$. Each of the parking areas is occupied by a taxi, and a queue of potential passengers is waiting for the ride. Each one in the queue has his/her own plan for how much to pay for the ride. </p> <p> To increase the company’s gain, the taxi driver is given the right to select the passenger who offers the highest taxi fare, rejecting others. </p> <p> The driver in the $i$-th parking space can perform the following actions any number of times in any sequence before he finally selects a passenger and starts driving. </p> <ol> <li>Offer a ride to the passenger who is at the head of the $i$-th parking space’s queue.</li> <li>Reject to offer a ride to the passenger who is at the head of the $i$-th parking space’s queue. The passenger is removed from the queue.</li> <li>Move to the $i + 1$-th parking area if it is empty. If he is in the $N$-th parking area, he leaves the taxi stand to cruise the open road.</li> </ol> <p> A preliminary listening is made as to the fare the users offer. Your task is to maximize the sales volume of PCK Taxi in reference to the table of offered fares. A taxi cannot accommodate more than one passenger. </p> <p> Given the number of taxi parking spaces and information regarding the persons waiting in the parking areas, calculate the maximum possible volume of sales. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $s_1$ $s_2$ $...$ $s_N$ </pre> <p> The first line provides the number of taxi parking areas $N$ ($1 \leq N \leq 300,000$). Each of the subsequent $N$ lines provides information on the customers queueing in the $i$-th taxi parking area in the following format: </p> <pre> $M$ $c_1$ $c_2$ ... $c_M$ </pre> <p> The first integer $M$ ($1 \leq M \leq 300,000$) indicates the number of customers in the queue, and the subsequent array of integers $c_j$ ($1 \leq c_j \leq 10,000$) indicates the fare the $j$-th customer in the queue is willing to pay. The total number of customers in the taxi stand is equal to or less than $300,000$. </p> <h2>Output</h2> <p> Output the maximum volume of sales. </p> <h2>Sample Input</h2> <pre> 3 3 8 10 1 4 7 1 2 15 3 11 8 19 </pre> <h2>Sample Output</h2> <pre> 45 </pre>  
p03404
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given two integers <var>A</var> and <var>B</var>.</p> <p>Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:</p> <ul> <li>Let the size of the grid be <var>h \times w</var> (<var>h</var> vertical, <var>w</var> horizontal). Both <var>h</var> and <var>w</var> are at most <var>100</var>.</li> <li>The set of the squares painted white is divided into exactly <var>A</var> connected components.</li> <li>The set of the squares painted black is divided into exactly <var>B</var> connected components.</li> </ul> <p>It can be proved that there always exist one or more solutions under the conditions specified in Constraints section. If there are multiple solutions, any of them may be printed.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>Two squares painted white, <var>c_1</var> and <var>c_2</var>, are called connected when the square <var>c_2</var> can be reached from the square <var>c_1</var> passing only white squares by repeatedly moving up, down, left or right to an adjacent square.</p> <p>A set of squares painted white, <var>S</var>, forms a connected component when the following conditions are met:</p> <ul> <li>Any two squares in <var>S</var> are connected.</li> <li>No pair of a square painted white that is not included in <var>S</var> and a square included in <var>S</var> is connected.</li> </ul> <p>A connected component of squares painted black is defined similarly.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A \leq 500</var></li> <li><var>1 \leq B \leq 500</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>Output should be in the following format:</p> <ul> <li>In the first line, print integers <var>h</var> and <var>w</var> representing the size of the grid you constructed, with a space in between.</li> <li>Then, print <var>h</var> more lines. The <var>i</var>-th (<var>1 \leq i \leq h</var>) of these lines should contain a string <var>s_i</var> as follows:<ul> <li>If the square at the <var>i</var>-th row and <var>j</var>-th column (<var>1 \leq j \leq w</var>) in the grid is painted white, the <var>j</var>-th character in <var>s_i</var> should be <code>.</code>.</li> <li>If the square at the <var>i</var>-th row and <var>j</var>-th column (<var>1 \leq j \leq w</var>) in the grid is painted black, the <var>j</var>-th character in <var>s_i</var> should be <code>#</code>.</li> </ul> </li> </ul> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 3 ##. ..# #.# </pre> <p>This output corresponds to the grid below:</p> <div style="text-align: center;"> <img alt="2701558bf42f7c088abad927b419472a.png" src="https://img.atcoder.jp/arc093/2701558bf42f7c088abad927b419472a.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 5 #.#.# .#.#. #.#.# </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 2 .. #. ## ## </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 14 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>8 18 .................. .................. ....##.......####. ....#.#.....#..... ...#...#....#..... ..#.###.#...#..... .#.......#..#..... #.........#..####. </pre></section> </div> </span>
p01439
<H1><font color="#000">Problem C:</font>Chinese Classics</H1> <p> Taro, a junior high school student, is working on his homework. Today's homework is to read Chinese classic texts. </p> <p> As you know, Japanese language shares the (mostly) same Chinese characters but the order of words is a bit different. Therefore the notation called "returning marks" was invented in order to read Chinese classic texts in the order similar to Japanese language. </p> <p> There are two major types of returning marks: 'Re' mark and jump marks. Also there are a couple of jump marks such as one-two-three marks, top-middle-bottom marks. The marks are attached to letters to describe the reading order of each letter in the Chinese classic text. Figure 1 is an example of a Chinese classic text annotated with returning marks, which are the small letters at the bottom-left of the big Chinese letters. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_chinese_classics"> <p> Figure 1: a Chinese classic text </p> </center> <p> Taro generalized the concept of jump marks, and summarized the rules to read Chinese classic texts with returning marks as below. Your task is to help Taro by writing a program that interprets Chinese classic texts with returning marks following his rules, and outputs the order of reading of each letter. </p> <p> When two (or more) rules are applicable in each step, the latter in the list below is applied first, then the former. </p> <ol> <li> Basically letters are read downwards from top to bottom, i.e. the first letter should be read (or skipped) first, and after the <i>i</i>-th letter is read or skipped, (<i>i</i> + 1)-th letter is read next. </li> <li> Each jump mark has a <i>type</i> (represented with a string consisting of lower-case letters) and a <i>number</i> (represented with a positive integer). A letter with a jump mark whose number is 2 or larger must be skipped. </li> <li> When the <i>i</i>-th letter with a jump mark of type <i>t</i>, number <i>n</i> is read, and when there exists an unread letter <i>L</i> at position less than <i>i</i> that has a jump mark of type <i>t</i>, number <i>n</i> + 1, then <i>L</i> must be read next. If there is no such letter <i>L</i>, the (<i>k</i> + 1)-th letter is read, where <i>k</i> is the index of the most recently read letter with a jump mark of type <i>t</i>, number 1. </li> <li> A letter with a 'Re' mark must be skipped. </li> <li> When the <i>i</i>-th letter is read and (<i>i</i> - 1)-th letter has a 'Re' mark, then (<i>i</i> - 1)-th letter must be read next. </li> <li> No letter may be read twice or more. Once a letter is read, the letter must be skipped in the subsequent steps. </li> <li> If no letter can be read next, finish reading. </li> </ol> <p> Let's see the first case of the sample input. We begin reading with the first letter because of the rule 1. However, since the first letter has a jump mark '<span>onetwo2</span>', we must follow the rule 2 and skip the letter. Therefore the second letter, which has no returning mark, will be read first. </p> <p> Then the third letter will be read. The third letter has a jump mark '<span>onetwo1</span>', so we must follow rule 3 and read a letter with a jump mark `onetwo2' next, if exists. The first letter has the exact jump mark, so it will be read third. Similarly, the fifth letter is read fourth, and then the sixth letter is read. </p> <p> Although we have two letters which have the same jump mark '<span>onetwo2</span>', we must not take into account the first letter, which has already been read, and must read the fourth letter. Now we have read all six letters and no letter can be read next, so we finish reading. We have read the second, third, first, fifth, sixth, and fourth letter in this order, so the output is 2 3 1 5 6 4. </p> <H2>Input</H2> <p> The input contains multiple datasets. Each dataset is given in the following format: </p> <p> <i>N</i><br> <i>mark</i><sub>1</sub><br> ...<br> <i>mark<sub>N</sub></i><br> </p> <p> <i>N</i>, a positive integer (1 &le; <i>N</i> &le; 10,000), means the number of letters in a Chinese classic text. <i>mark<sub>i</sub></i> denotes returning marks attached to the <i>i</i>-th letter. </p> <p> A 'Re' mark is represented by a single letter, namely, 'v' (quotes for clarity). The description of a jump mark is the simple concatenation of its type, specified by one or more lowercase letter, and a positive integer. Note that each letter has at most one jump mark and at most one 'Re' mark. When the same letter has both types of returning marks, the description of the jump mark comes first, followed by 'v' for the 'Re' mark. You can assume this happens only on the jump marks with the number 1. </p> <p> If the <i>i</i>-th letter has no returning mark, <i>mark<sub>i</sub></i> is '-' (quotes for clarity). The length of <i>mark<sub>i</sub></i> never exceeds 20. </p> <p> You may assume that input is well-formed, that is, there is exactly one reading order that follows the rules above. And in the ordering, every letter is read exactly once. </p> <p> You may also assume that the <i>N</i>-th letter does not have 'Re' mark. </p> <p> The input ends when <i>N</i> = 0. Your program must not output anything for this case. </p> <H2>Output</H2> <p> For each dataset, you should output N lines. The first line should contain the index of the letter which is to be read first, the second line for the letter which is to be read second, and so on. All the indices are 1-based. </p> <H2>Sample Input</H2> <pre> 6 onetwo2 - onetwo1 onetwo2 - onetwo1 7 v topbottom2 onetwo2 - onetwo1 topbottom1 - 6 baz2 foo2 baz1v bar2 foo1 bar1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 3 1 5 6 4 4 5 3 6 2 1 7 5 2 6 4 3 1 </pre>
p03054
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a rectangular grid of squares 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. On this grid, there is a piece, which is initially placed at square <var>(s_r,s_c)</var>.</p> <p>Takahashi and Aoki will play a game, where each player has a string of length <var>N</var>. Takahashi's string is <var>S</var>, and Aoki's string is <var>T</var>. <var>S</var> and <var>T</var> both consist of four kinds of letters: <code>L</code>, <code>R</code>, <code>U</code> and <code>D</code>.</p> <p>The game consists of <var>N</var> steps. The <var>i</var>-th step proceeds as follows:</p> <ul> <li>First, Takahashi performs a move. He either moves the piece in the direction of <var>S_i</var>, or does not move the piece.</li> <li>Second, Aoki performs a move. He either moves the piece in the direction of <var>T_i</var>, or does not move the piece.</li> </ul> <p>Here, to move the piece in the direction of <code>L</code>, <code>R</code>, <code>U</code> and <code>D</code>, is to move the piece from square <var>(r,c)</var> to square <var>(r,c-1)</var>, <var>(r,c+1)</var>, <var>(r-1,c)</var> and <var>(r+1,c)</var>, respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than <var>N</var> steps are done.</p> <p>Takahashi wants to remove the piece from the grid in one of the <var>N</var> steps. Aoki, on the other hand, wants to finish the <var>N</var> steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq H,W \leq 2 \times 10^5</var></li> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq s_r \leq H</var></li> <li><var>1 \leq s_c \leq W</var></li> <li><var>|S|=|T|=N</var></li> <li><var>S</var> and <var>T</var> consists of the four kinds of letters <code>L</code>, <code>R</code>, <code>U</code> and <code>D</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>N</var> <var>s_r</var> <var>s_c</var> <var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the piece will remain on the grid at the end of the game, print <code>YES</code>; otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 3 2 2 RRL LUD </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>Here is one possible progress of the game:</p> <ul> <li>Takahashi moves the piece right. The piece is now at <var>(2,3)</var>.</li> <li>Aoki moves the piece left. The piece is now at <var>(2,2)</var>.</li> <li>Takahashi does not move the piece. The piece remains at <var>(2,2)</var>.</li> <li>Aoki moves the piece up. The piece is now at <var>(1,2)</var>.</li> <li>Takahashi moves the piece left. The piece is now at <var>(1,1)</var>.</li> <li>Aoki does not move the piece. The piece remains at <var>(1,1)</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 5 2 2 UDRRR LLDUD </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>5 6 11 2 1 RLDRRUDDLRL URRDRLLDLRD </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre></section> </div> </span>
p01069
<h1>Sum of Sequences</h1> <h2>Problem</h2> <p> <var>n</var>個の要素を持つ数列<var>A</var>、<var>m</var>個の要素を持つ数列<var>B</var>、 それぞれが整数<var>c</var>からなる<var>q</var>個のクエリが与えられる。 <br> 各クエリについて、<br> 数列<var>A</var>の[<var>l<sub>a</sub></var>,<var>r<sub>a</sub></var>]を全て足した数と数列<var>B</var>の[<var>l<sub>b</sub></var>,<var>r<sub>b</sub></var>]を全て足した数の差の絶対値が<var>c</var>になる<var>l<sub>a</sub></var>,<var>r<sub>a</sub></var>,<var>l<sub>b</sub></var>,<var>r<sub>b</sub></var> (0 &le; <var>l<sub>a</sub></var> &le; <var>r<sub>a</sub></var> &le; <var>n</var>&minus;1, 0 &le; <var>l<sub>b</sub></var> &le; <var>r<sub>b</sub></var> &le; <var>m</var>&minus;1, 配列の番号は0番から始まる) の組み合わせの数を求めよ。 </p> <h2>Input</h2> <pre> <var>n</var> <var>m</var> <var>q</var> <var>a<sub>0</sub></var> <var>a<sub>1</sub></var> ... <var>a<sub>n&minus;1</sub></var> <var>b<sub>0</sub></var> <var>b<sub>1</sub></var> ... <var>b<sub>m&minus;1</sub></var> <var>c<sub>0</sub></var> <var>c<sub>1</sub></var> ... <var>c<sub>q&minus;1</sub></var> </pre> <p> 入力は全て整数で与えられる。<br> 1行目に数列の要素数<var>n</var>と<var>m</var>、クエリ数<var>q</var>が与えられる。<br> 2行目に数列<var>A</var>の要素、3行目に数列<var>B</var>の要素が空白区切りで与えられる。<br> 4行目から<var>q</var>行に各クエリの値<var>c<sub>i</sub></var>が与えられる。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>n</var>, <var>m</var> &le; 4×10<sup>4</sup></li> <li>1 &le; <var>q</var> &le; 10<sup>5</sup></li> <li>1 &le; <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> &le; 5</li> <li>0 &le; <var>c<sub>i</sub></var> &le; 2×10<sup>5</sup></li> </ul> <h2>Output</h2> <p> 出力は<var>q</var>行からなる。各クエリの組み合わせの数を順番に一行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 3 1 1 2 3 3 1 2 3 </pre> <h2>Sample Output 1</h2> <pre> 6 </pre> <h2>Sample Input 2</h2> <pre> 5 4 2 1 2 3 4 5 2 2 2 2 11 12 </pre> <h2>Sample Output 2</h2> <pre> 3 4 </pre>
p01593
<h2>Problem C: Earn Big</h2> <p>A group of <var>N</var> people is trying to challenge the following game to earn big money.</p> <p>First, <var>N</var> participants are isolated from each other. From this point, they are not allowed to contact each other, or to leave any information for other participants. The game organizer leads each participant, one by one, to a room with <var>N</var> boxes. The boxes are all closed at the beginning of the game, and the game organizer closes all the boxes whenever a participant enters the room. Each box contains a slip of paper on which a name of a distinct participant is written. The order of the boxes do not change during the game. Each participant is allowed to open up to <var>M</var> boxes. If every participant is able to open a box that contains a paper of his/her name, then the group wins the game, and everybody in the group earns big money. If anyone is failed to open a box that contains a paper of his/her name, then the group fails in the game, and nobody in the group gets money.</p> <p>Obviously, if every participant picks up boxes randomly, the winning probability will be <var>(M/N)<sup>N</sup></var>. However, there is a far more better solution.</p> <p>Before discussing the solution, let us define some concepts. Let <var>P = {p<sub>1</sub>, p<sub>2</sub>, ..., p<sub>N</sub>}</var> be a set of the participants, and <var>B = {b<sub>1</sub>, b<sub>2</sub>, ..., b<sub>N</sub>}</var> be a set of the boxes. Let us define <var>f</var>, a mapping from <var>B</var> to <var>P</var>, such that <var>f(b)</var> is a participant whose name is written on a paper in a box <var>b</var>.</p> <p>Here, consider a participant <var>p<sub>i</sub></var> picks up the boxes in the following manner:</p> <ol> <li>Let <var>x := i</var>.</li> <li>If <var>p<sub>i</sub></var> has already opened <var>M</var> boxes, then exit as a failure.</li> <li><var>p<sub>i</sub></var> opens <var>b<sub>x</sub></var>. <ol> <li>If <var>f(b<sub>x</sub>) = p<sub>i</sub></var>, then exit as a success.</li> <li>If <var>f(b<sub>x</sub>) = p<sub>j</sub></var> (<var>i != j</var>), then let <var>x := j</var>, and go to 2.</li> </ol> </li> </ol> <p>Assuming every participant follows the algorithm above, the result of the game depends only on the initial order of the boxes (i.e. the definition of <var>f</var>). Let us define <var>g</var> to be a mapping from <var>P</var> to <var>B</var>, such that <var>g(p<sub>i</sub>) = b<sub>i</sub></var>. The participants win the game if and only if, for every <var>i &isin; {1, 2, ..., N}</var>, there exists <var>k(<=M)</var> such that <var>(f</var><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_earnBig" /></var>g)<sup>k</sup> (p<sub>i</sub>) = p<sub>i</sub></var>.</p> <p>Your task is to write a program that calculates the winning probability of this game. You can assume that the boxes are placed randomly.</p> <h2>Input</h2> <p>The input consists of one line. It contains two integers <var>N</var> and <var>M</var> (1 <= <var>M</var> <= <var>N</var> <= 1,000) in this order, delimited by a space.</p> <h2>Output</h2> <!-- <p>For given <var>N</var> and <var>M</var>, your program should print the winning probability of the game. The output value should be printed with eight digits after the decimal point, and should not contain an error greater than <var>10<sup>-8</sup></var>.</p> --> <p>For given <var>N</var> and <var>M</var>, your program should print the winning probability of the game. The output value should be in a decimal fraction and should not contain an error greater than <var>10<sup>-8</sup></var>.</p> <h2>Sample Input 1</h2> <pre> 2 1 </pre> <h2>Output for the Sample Input 1</h2> <pre> 0.50000000 </pre> <h2>Sample Input 2</h2> <pre> 100 50 </pre> <h2>Output for the Sample Input 2</h2> <pre> 0.31182782 </pre>
p01086
<h2>Short Phrase</h2> <p> A <em>Short Phrase</em> (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition: </p> <blockquote> (The Condition for a Short Phrase)<br> The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively. </blockquote> <p> The following is an example of a Short Phrase. </p> <blockquote> <pre>do the best and enjoy today at acm icpc </pre> </blockquote> <p> In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase. </p> <p> Now, <em>Short Phrase Parnassus</em> published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix. </p> <h3>Input</h3> <p> The input consists of multiple datasets, each in the following format. </p> <blockquote> <i>n</i><br> <i>w</i><sub>1</sub><br> ... <br> <i>w<sub>n</sub></i><br> </blockquote> <p> Here, <i>n</i> is the number of words, which is a positive integer not exceeding 40; <i>w<sub>i</sub></i> is the <i>i</i>-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase. </p> <p> The end of the input is indicated by a line with a single zero. </p> <h3>Output</h3> <p> For each dataset, output a single line containing <i>i</i> where the first word of the Short Phrase is <i>w<sub>i</sub></i>. When multiple Short Phrases occur in the dataset, you should output the first one. </p> <h3>Sample Input</h3> <pre>9 do the best and enjoy today at acm icpc 14 oh yes by far it is wow so bad to me you know hey 15 abcde fghijkl mnopq rstuvwx yzz abcde fghijkl mnopq rstuvwx yz abcde fghijkl mnopq rstuvwx yz 0 </pre> <h3>Output for the Sample Input</h3> <pre>1 2 6 </pre>
p03541
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>2^N</var> players competed in a tournament. Each player has a unique ID number from <var>1</var> through <var>2^N</var>. When two players play a match, the player with the smaller ID always wins.</p> <p>This tournament was a little special, in which losers are not eliminated to fully rank all the players.</p> <p>We will call such a tournament that involves <var>2^n</var> players a <em>full tournament of level <var>n</var></em>. In a full tournament of level <var>n</var>, the players are ranked as follows:</p> <ul> <li>In a full tournament of level <var>0</var>, the only player is ranked first.</li> <li>In a full tournament of level <var>n\ (1 \leq n)</var>, initially all <var>2^n</var> players are lined up in a row. Then:</li> <li>First, starting from the two leftmost players, the players are successively divided into <var>2^{n-1}</var> pairs of two players.</li> <li>Each of the pairs plays a match. The winner enters the "Won" group, and the loser enters the "Lost" group.</li> <li>The players in the "Won" group are lined up in a row, maintaining the relative order in the previous row. Then, a full tournament of level <var>n-1</var> is held to fully rank these players.</li> <li>The players in the "Lost" group are also ranked in the same manner, then the rank of each of these players increases by <var>2^{n-1}</var>.</li> </ul> <p>For example, the figure below shows how a full tournament of level <var>3</var> progresses when eight players are lined up in the order <var>3,4,8,6,2,1,7,5</var>. The list of the players sorted by the final ranking will be <var>1,3,5,6,2,4,7,8</var>.</p> <p><img alt="" src="https://img.atcoder.jp/cf17-final/e93269f0dfb68bcdff175a3b634ab0d8.png"/></p> <p>Takahashi has a sheet of paper with the list of the players sorted by the final ranking in the tournament, but some of it blurred and became unreadable. You are given the information on the sheet as a sequence <var>A</var> of length <var>N</var>. When <var>A_i</var> is <var>1</var> or greater, it means that the <var>i</var>-th ranked player had the ID <var>A_i</var>. If <var>A_i</var> is <var>0</var>, it means that the ID of the <var>i</var>-th ranked player is lost.</p> <p>Determine whether there exists a valid order in the first phase of the tournament which is consistent with the sheet. If it exists, provide one such order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 18</var></li> <li><var>0 \leq A_i \leq 2^N</var></li> <li>No integer, except <var>0</var>, occurs more than once in <var>A_i</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_{2^N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a valid order in the first phase of the tournament, print <code>YES</code> first, then in the subsequent line, print the IDs of the players sorted by the final ranking, with spaces in between. If there is no such order, print <code>NO</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 3 0 6 0 0 0 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES 3 4 8 6 2 1 7 5 </pre> <p>This is the same order as the one in the statement.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre></section> </div> </span>
p03111
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have <var>N</var> bamboos. The lengths (in centimeters) of these are <var>l_1, l_2, ..., l_N</var>, respectively.</p> <p>Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length <var>A, B, C</var>. For that, you can use the following three kinds of magics any number:</p> <ul> <li>Extension Magic: Consumes <var>1</var> <em>MP</em> (magic point). Choose one bamboo and increase its length by <var>1</var>.</li> <li>Shortening Magic: Consumes <var>1</var> MP. Choose one bamboo of length at least <var>2</var> and decrease its length by <var>1</var>.</li> <li>Composition Magic: Consumes <var>10</var> MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)</li> </ul> <p>At least how much MP is needed to achieve the objective?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 8</var></li> <li><var>1 \leq C &lt; B &lt; A \leq 1000</var></li> <li><var>1 \leq l_i \leq 1000</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</var> <var>B</var> <var>C</var> <var>l_1</var> <var>l_2</var> <var>:</var> <var>l_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum amount of MP needed to achieve the objective.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 100 90 80 98 40 30 21 80 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>23 </pre> <p>We are obtaining three bamboos of lengths <var>100, 90, 80</var> from five bamboos <var>98, 40, 30, 21, 80</var>. We already have a bamboo of length <var>80</var>, and we can obtain bamboos of lengths <var>100, 90</var> by using the magics as follows at the total cost of <var>23</var> MP, which is optimal.</p> <ol> <li>Use Extension Magic twice on the bamboo of length <var>98</var> to obtain a bamboo of length <var>100</var>. (MP consumed: <var>2</var>)</li> <li>Use Composition Magic on the bamboos of lengths <var>40, 30</var> to obtain a bamboo of length <var>70</var>. (MP consumed: <var>10</var>)</li> <li>Use Shortening Magic once on the bamboo of length <var>21</var> to obtain a bamboo of length <var>20</var>. (MP consumed: <var>1</var>)</li> <li>Use Composition Magic on the bamboo of length <var>70</var> obtained in step 2 and the bamboo of length <var>20</var> obtained in step 3 to obtain a bamboo of length <var>90</var>. (MP consumed: <var>10</var>)</li> </ol> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 100 90 80 100 100 90 90 90 80 80 80 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>If we already have all bamboos of the desired lengths, the amount of MP needed is <var>0</var>. As seen here, we do not necessarily need to use all the bamboos.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 1000 800 100 300 333 400 444 500 555 600 666 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>243 </pre></section> </div> </span>
p01985
<h3>分割統治</h3> <!-- begin ja only --> <p>太郎さんと花子さんと次郎さんは3人で JAG 王国を統治している.JAG 王国には <i>N</i> 個の街が存在し,いくつかの街は双方向の道路で繋がっている.どの街からも別のすべての街へ 1 本以上の道路を経由して必ず辿り着くことができる.</p> <p>ある日太郎さんと花子さんはとうとう仲違いを起こしてしまい,3 人で街を分担して統治することに決めた.しかし,あまりにも仲が悪くなりすぎてしまったため,太郎さんが統治している街と花子さんが統治している街が 1 本の道路で直接繋がっていることすら嫌がっている.そこで,以下の条件を満たすように統治する街を分担することにした.</p> <ul> <li>太郎さんが統治する街と花子さんが統治する街からなる任意のペアは,直接道路で繋がっていない.これは太郎さんと花子さんの仲がめちゃくちゃ悪いからである.</li> <li>同じ人に統治されている街同士も直接道路で繋がっていない.これは,そんな中でも他者の統治下の経由を義務付けることで外交を促すためである.</li> <li>太郎さんの統治する街の総数と花子さんが統治する街の総数は同じでなければならない.これは総数を等しくしないと太郎さんと花子さんの仲がさらにめちゃくちゃ悪くなりそうだからである.ここで,次郎さんはとても心が広いので,次郎さんが統治する街の総数はいくつでもよい.</li> </ul> <p>以上の条件を満たすような分担であれば,3 人は納得して統治することができ,たとえ誰かの統治する街が 0 個であっても文句はない.このとき,太郎さんが統治する街の総数 (=花子さんが統治する街の総数) としてあり得る数をすべて列挙するプログラムを作成せよ.</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は複数のデータセットからなる. データセットの数は最大で 50 である. 各データセットは,次の形式で表される.</p> <blockquote><i>N</i> <i>M</i> <i>u<sub>1</sub></i> <i>v<sub>1</sub></i> <i>...</i> <i>u<sub>M</sub></i> <i>v<sub>M</sub></i></blockquote> <p>1 行目は 2 つの整数 <i>N</i> (<i>2 &le; N &le; 10<sup>3</sup></i>) と <i>M</i> (<i>1 &le; M &le; 10<sup>3</sup></i>) からなり,それぞれ街の数と道路の数を表す.続く <i>M</i> 行のうち <i>i</i> 行目は 2 つの整数 <i>u<sub>i</sub></i> と <i>v<sub>i</sub></i> (<i>1 &le; u<sub>i</sub> &lt; v<sub>i</sub> &le; N</i>) からなり,<i>i</i> 番目の道路が街 <i>u<sub>i</sub></i> と 街 <i>v<sub>i</sub></i> を双方向に繋いでいることを表す.ここで,どの街からも別のすべての街へ 1 本以上の道路を経由して必ず辿り着くことができることが保証される.また,同じ街のペアを結ぶ道路が複数与えられることはない.すなわち,すべての <i>1 &le; i &lt; j &le; M</i> について <i>(u<sub>i</sub>, v<sub>i</sub>) &ne; (u<sub>j</sub>, v<sub>j</sub>)</i> を満たす.</p> <p>入力の終わりは 2 つのゼロからなる行で表される.</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各データセットについて,太郎さんが統治する街の総数として考えられる数が <i>K</i> 通りあるとき,まず 1 行目に <i>K</i> を出力し,その後,あり得る総数を 1 行に 1 つずつ昇順で出力せよ.</p> <!-- end ja only --> <h3>Sample Input</h3><pre>6 7 1 2 1 4 2 3 2 5 3 4 4 5 4 6 2 1 1 2 3 3 1 2 1 3 2 3 4 3 1 2 2 3 3 4 5 4 1 2 2 3 3 4 4 5 0 0 </pre><h3>Output for the Sample Input</h3><pre>2 1 2 0 0 1 1 1 1 </pre>
p00697
<H1> Jigsaw Puzzles for Computers </H1> <P> Ordinary Jigsaw puzzles are solved with visual hints; players solve a puzzle with the picture which the puzzle shows on finish, and the diverse patterns of pieces. Such Jigsaw puzzles may be suitable for human players, because they require abilities of pattern recognition and imagination. </P> <P> On the other hand, "Jigsaw puzzles" described below may be just the things for simple-minded computers. </P> <P> As shown in <B>Figure 1</B>, a puzzle is composed of nine square pieces, and each of the four edges of a piece is labeled with one of the following eight symbols: <BR> <BR> <B>"R", "G", "B", "W", "r", "g", "b"</B>, and <B>"w".</B><BR> </P> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_jigsaw1"></TD></TR> <TR><TD ALIGN=center><B>Figure 1</B>: The nine pieces of a puzzle</TD></TR> </TABLE> <P> In a completed puzzle, the nine pieces are arranged in a 3 x 3 grid, and each of the 12 pairs of edges facing each other must be labeled with one of the following four combinations of symbols: <BR> <BR> <B>"R"</B> with <B>"r"</B>, <B>"G"</B> with <B>"g"</B>, <B>"B"</B> with <B>"b"</B>, and <B>"W"</B> with <B>"w"</B>.<BR> <BR> For example, an edge labeled <B>"R"</B> can only face an edge with <B>"r"</B>. <B>Figure 2</B> is an example of a completed state of a puzzle. In the figure, edges under this restriction are indicated by shadowing their labels. The player can freely move and rotate the pieces, but cannot turn them over. There are no symbols on the reverse side of a piece ! </P> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_jigsaw2"></TD></TR> <TR><TD ALIGN=center><B>Figure 2</B>: A completed puzzle example</TD></TR> </TABLE> <P> Each piece is represented by a sequence of the four symbols on the piece, starting with the symbol of the top edge, followed by the symbols of the right edge, the bottom edge, and the left edge. For example, <B>gwgW</B> represents the leftmost piece in <B>Figure 1</B>. Note that the same piece can be represented as <B>wgWg</B>, <B>gWgw</B> or <B>Wgwg</B> since you can rotate it in 90, 180 or 270 degrees. </P> <P> <B>The mission for you</B> is to create a program which counts the number of solutions. It is needless to say that these numbers must be multiples of four, because, as shown in <B>Figure 3</B>, a configuration created by rotating a solution in 90, 180 or 270 degrees is also a solution. </P> <TABLE> <TR><TD ALIGN=center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_jigsaw3"></TD></TR> <TR><TD ALIGN=center><B>Figure 3</B>: Four obvious variations for a completed puzzle</TD></TR> </TABLE> <P> A term <U>"rotationally equal"</U> is defined; if two different pieces are identical when one piece is rotated (in 90, 180 or 270 degrees), they are rotationally equal. For example, <B>WgWr</B> and <B>WrWg</B> are rotationally equal. </P> <P> Another term <U>"rotationally symmetric"</U> is defined; if a piece is rotationally equal to itself, it is rotationally symmetric. For example, a piece <B>gWgW</B> is rotationally symmetric.<BR> </P> <P> Given puzzles satisfy the following three conditions: <OL> <LI>There is no identical pair of pieces in a puzzle. <LI>There is no <U>rotationally equal</U> pair of pieces in a puzzle. <LI>There is no <U>rotationally symmetric</U> piece in a puzzle. </OL> </P> <H2>Input</H2> <P> The input consists of multiple puzzles. </P> <PRE> <I>N</I><br> <I>Puzzle</I><SUB>1</SUB><br> <I>Puzzle</I><SUB>2</SUB><br> <I>. . .</I><br> <I>Puzzle<SUB>N</SUB></I><br> </PRE> <P> <I>N</I> is the number of puzzles. Each <I>Puzzle<SUB>i</SUB></I> gives a puzzle with a single line of 44 characters, consisting of four-character representations of the nine pieces of the puzzle, separated by a space character. For example, the following line represents the puzzle in <B>Figure 1</B>.<BR> </P> <PRE> <TT>gwgW RBbW GWrb GRRb BWGr Rbgw rGbR gBrg GRwb</TT> </PRE> <H2>Output</H2> <P> For each <I>Puzzle<SUB>i</SUB></I> , the number of its solutions should be the output, each in a separate line. </P> <H2>Sample Input</H2> <PRE> 6 WwRR wwrg RRGb rGBG RGrb RrRg RGrg rgBB Wrgr RrGb WWGR rGgb Wbrg wgBb GgBg WbBG Wwwg WWGG RBbr Wrbr wGGG wggR WgGR WBWb WRgB wBgG WBgG wBrg rGgb WRrB WWbw wRRB RbbB WRrb wrbb WgrG WrwB WWww wRRB WGGb Wbbg WBgG WrbG Wrww RBgg WWgg RBrr Rggr RGBg Wbgr WGbg WBbr WGWB GGGg </PRE> <H2>Output for the Sample Input:</H2> <PRE> 40 8 32 4 12 0 </PRE>
p02350
<H1>RMQ and RUQ</H1> <p> Write a program which manipulates a sequence <var>A</var> = {<var>a<sub>0</sub>, a<sub>1</sub>, . . . , a<sub>n&minus;1</sub></var>} with the following operations: </p> <ul> <li><var>update(s, t, x)</var>: change <var>a<sub>s</sub></var>, <var>a<sub>s+1</sub></var>, ..., <var>a<sub>t</sub></var> to <var>x</var>.</li> <li><var>find(s, t)</var>: report the minimum element in <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 = 0, 1, . . . , n&minus;1</var>) are 2<sup>31</sup>-1. </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>update(s, t, x)</var> and '1' denotes <var>find(s, t)</var>. </p> <H2>Output</H2> <p> For each <var>find</var> operation, print the minimum value. </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>0 &le; s &le; t &lt; n</var> </li> <li> <var>0 &le; x &lt; 2<sup>31</sup>&minus;1</var> </li> </ul> <H2>Sample Input 1</H2> <pre> 3 5 0 0 1 1 0 1 2 3 0 2 2 2 1 0 2 1 1 2 </pre> <H2>Sample Output 1</H2> <pre> 1 2 </pre> <br/> <H2>Sample Input 2</H2> <pre> 1 3 1 0 0 0 0 0 5 1 0 0 </pre> <H2>Sample Output 2</H2> <pre> 2147483647 5 </pre>
p03812
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices, numbered <var>1</var> through <var>N</var>. The <var>i</var>-th of the <var>N-1</var> edges connects vertices <var>a_i</var> and <var>b_i</var>.</p> <p>Currently, there are <var>A_i</var> stones placed on vertex <var>i</var>. Takahashi and Aoki will play a game using this tree.</p> <p>First, Takahashi will select a vertex and place a piece on it. Then, starting from Takahashi, they will alternately perform the following operation:</p> <ul> <li>Remove one stone from the vertex currently occupied by the piece.</li> <li>Then, move the piece to a vertex that is adjacent to the currently occupied vertex.</li> </ul> <p>The player who is left with no stone on the vertex occupied by the piece and thus cannot perform the operation, loses the game. Find all the vertices <var>v</var> such that Takahashi can place the piece on <var>v</var> at the beginning and win the game.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≦ N ≦ 3000</var></li> <li><var>1 ≦ a_i,b_i ≦ N</var></li> <li><var>0 ≦ A_i ≦ 10^9</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>A_2</var> … <var>A_N</var> <var>a_1</var> <var>b_1</var> : <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the indices of the vertices <var>v</var> such that Takahashi can place the piece on <var>v</var> at the beginning and win the game, in a line, in ascending order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The following is one possible progress of the game when Takahashi places the piece on vertex <var>2</var>:</p> <ul> <li>Takahashi moves the piece to vertex <var>1</var>. The number of the stones on each vertex is now: <var>(1,1,3)</var>.</li> <li>Aoki moves the piece to vertex <var>2</var>. The number of the stones on each vertex is now: <var>(0,1,3)</var>.</li> <li>Takahashi moves the piece to vertex <var>1</var>. The number of the stones on each vertex is now: <var>(0,0,3)</var>.</li> <li>Aoki cannot take a stone from the vertex, and thus Takahashi wins.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 4 1 2 3 1 2 1 3 2 4 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 1 1 1 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre> </pre> <p>Note that the correct output may be an empty line.</p></section> </div> </span>
p02700
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi and Aoki will have a battle using their monsters.</p> <p>The health and strength of Takahashi's monster are <var>A</var> and <var>B</var>, respectively, and those of Aoki's monster are <var>C</var> and <var>D</var>, respectively.</p> <p>The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ... Here, an attack decreases the opponent's health by the value equal to the attacker's strength. The monsters keep attacking until the health of one monster becomes <var>0</var> or below. The person with the monster whose health becomes <var>0</var> or below loses, and the other person wins.</p> <p>If Takahashi will win, print <code>Yes</code>; if he will lose, print <code>No</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A,B,C,D \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>A</var> <var>B</var> <var>C</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Takahashi will win, print <code>Yes</code>; if he will lose, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 9 10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>No </pre> <p>First, Takahashi's monster attacks Aoki's monster, whose health is now <var>10-9=1</var>.</p> <p>Next, Aoki's monster attacks Takahashi's monster, whose health is now <var>10-10=0</var>.</p> <p>Takahashi's monster is the first to have <var>0</var> or less health, so Takahashi loses.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>46 4 40 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre></section> </div> </span>
p00013
<H1>Switching Railroad Cars</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_switchingRailroadCars"> </center> <br> <p> This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks. </p> <p> We can simulate the movement (comings and goings) of the cars as follow: </p> <ul> <li>An entry of a car is represented by its number.</li> <li>An exit of a car is represented by 0</li> </ul> <p> For example, a sequence </p> <pre> 1 6 0 8 10 </pre> <p> demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter. </p> <p> Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks. </p> <H2>Input</H2> <pre> car number car number or 0 car number or 0 . . . car number or 0 </pre> <p> The number of input lines is less than or equal to 100. </p> <H2>Output</H2> <p> For each 0, print the car number. </p> <H2>Sample Input</H2> <pre> 1 6 0 8 10 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 6 10 8 1 </pre>
p00443
<H1>最軽量のモビール</H1> <h2>問題</h2> <p> モビールは動く芸術品として広く親しまれている.IOI 日本委員会では,JOI を広報するためにモビールを作成することになった.JOI 広報用モビールは,棒,紐(ひも),錘(おもり)の 3 種類の要素を用いて,次のように構成される. </p> <ul> <li> 棒の一方の端は青に,もう一方の端は赤に塗られている. </li> <li> 棒は両端以外の 1 箇所を支点として紐でつるされる.</li> <li> 支点から赤の端までの長さも支点から青の端までの長さも正整数である.</li> <li> 棒の両端には,紐で錘か他の棒をつるす.</li> <li> 錘は紐を用いてどれかの棒の一端につるされる.</li> <li> 錘には何もつるさない.</li> <li> 錘の重さは正整数である.</li> <li> 紐のうち 1 本だけは,片方の端をある棒をつるすためにその棒の支点に結ばれ, もう一方の端は他のどの構成要素とも結ばれていない.他の紐は全て次のいず れかを満たす.</li> <ul> <li> ある棒の端とある棒の支点を結ぶ.</li> <li> ある棒の端とある錘を結ぶ.</li> </ul> </ul> <p> ただし,どの棒においても,バランスが取れている必要がある.棒と紐の重さは無視できるほど軽いので,棒と紐の重さは全て 0 であるとみなして解答せよ.つまり,それぞれの棒について, </p> <p> (その棒の赤の端より下につるされている錘の重さの総計) &times; (その棒の支点から赤の端までの長さ) = (その棒の青の端より下につるされている錘の重さの総計) &times; (その棒の支点から青の端までの長さ) </p> <p> であるとき,その棒はバランスが取れているとせよ. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lightestMobile1"> </center> <br> <p> どのような長さの棒をどのように結びモビールを構成するかは既に決まっているのだが,錘の重さがまだ決まっていない.モビールは軽い方がつりやすいため, なるべく軽いモビールを作りたい.前述したようにどの棒もバランスを取りながら, モビールの総重量を最小にするような錘の付け方を求め, そのときのモビールの総重量を出力するプログラムを作れ. プログラムには以下のモビールの構成に関する情報が与えられる. </p> <ul> <li> 棒の本数 n</li> <li> 各棒ごとの情報(棒の番号は 1 から n)</li> <ul> <li>支点から赤の端までの長さと支点から青の端までの長さの比</li> <li> 赤の端につるす棒の番号 (錘をつるす場合は 0)</li> <li> 青の端につるす棒の番号 (錘をつるす場合は 0)</li> </ul> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lightestMobile2"> </center> <h2>入力</h2> <p> <!-- 入力ファイルのファイル名は input.txt である.--> 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる.入力はゼロ1つを含む行で終了する. </p> <p> 1 行目にはモビールに使われている棒の本数 n が書かれている.続く n 行 (1 &le; n &le; 100) には,各々の棒のデータが書かれている.i + 1 行目 (1 &le; i &le; n) には,4 つの整数 p, q, r, b が空白を区切りとして書かれており,棒 i において,支点から赤の端までの長さと支点から青の端までの比が p : q であり,赤の端につるされる棒の番号が r であり,青の端につるされる棒の番号が b であることを表している.ただし,棒番号 0 は錘がつるされることを表している.また,どの入力においても,モビールの重量の最小値を w とし,入力中で比を表すのに用いられる正整数の最大値を L とすると,wL &lt; 2<sup>31</sup> を満たす. </p> <p> データセットの数は 15 を超えない. </p> <h2>出力</h2> <p> <!-- 出力ファイルのファイル名は output.txt である. output.txt は 1 行だけであり,モビールの重量を出力する. --> データセットごとにモビールの重量を1行に出力する. </p> <h2>入出力例</h2> <h3>入力例</h3> <pre> 1 6 9 0 0 4 3 2 0 4 1 3 0 0 4 4 2 1 2 2 0 0 0 </pre> <h3>出力例</h3> <pre> 5 40 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p02184
<h2>C: カニサル暗号</h2> <h3>問題</h3> <p>えびちゃんは、ある非負整数 <var>D</var> を「カニサル暗号」で暗号化して得られた文字列 <var>C</var> を与えられました。この暗号は、非負整数を <var>10</var> 進法で表したときの各数字をある(元と異なるとは限らない)決められた数字で置き換えるものです。異なる数字が同じ数字に置き換えられたり、同じ数字が出現位置によって異なる数字に書き換えられることはありません。</p> <p>たとえば、この暗号化方式によって <var>2646</var> が <var>0545</var> になることはありますが、<var>3456</var> が <var>1333</var> になったり <var>1333</var> が <var>3456</var> になることはありません。</p> <p>いま、えびちゃんは <var>D</var> を <var>10^9+7</var> で割った余りが <var>M</var> になることを教えてもらいました。このとき、<var>D</var> として考えられるものを一つ出力してください。複数考えられる場合はどれを出力しても構いません。ただし、<var>D</var> の先頭には余分な <code>0</code> はついていないものとします。</p> <h3>入力形式</h3> <pre> <var>M</var> <var>C</var> </pre> <h3>制約</h3> <ul> <li><var>0\leq M &lt; 10^9+7</var></li> <li><var>1\leq |C| \leq 10^5</var></li> </ul> <h3>出力形式</h3> <p><var>D</var> として考えられる非負整数を一行に出力してください。存在しない場合は <code>-1</code> を出力してください。</p> <h3>入力例1</h3> <pre> 2 1000000007 </pre> <h3>出力例1</h3> <pre>1000000009</pre> <p>今回の暗号化方式は、<var>0</var> を <var>0</var> に、<var>1</var> を <var>1</var> に、<var>9</var> を <var>7</var> に置き換えるものでした。</p> <h3>入力例2</h3> <pre> 3 1000000007 </pre> <h3>出力例2</h3> <pre>-1</pre> <h3>入力例3</h3> <pre> 1 01 </pre> <h3>出力例3</h3> <pre>-1</pre> <p><var>D</var> の先頭に余分な <code>0</code> がついていることはありません。</p> <h3>入力例4</h3> <pre> 45 1000000023 </pre> <h3>出力例4</h3> <pre>6000000087</pre> <p><code>1000000052</code> や <code>2000000059</code> なども条件を満たすので、それを出力してもかまいません。</p> <h3>入力例5</h3> <pre> 0 940578326285963740 </pre> <h3>出力例5</h3> <pre>123456789864197523</pre>
p01602
<h2>()</h2> <h2>Problem Statement</h2> <p>文字列<var>S</var>がある.はじめ,<var>S</var>は空文字列である.<br /> 以下の処理を<var>n</var>個順番に行う.</p> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>S</var>の末尾に<var>p_i</var>(=&quot;(&quot;または&quot;)&quot;)を<var>x_i</var>個追加する.</li></ul> <p>処理を施した後,<var>S</var>がバランスのとれた文字列であるかどうか判定せよ.</p> <p>「文字列のバランスが取れている」とは,次のように定義される.</p> <ul class="list1" style="padding-left:16px;margin-left:16px"><li>空文字列はバランスが取れている.</li> <li>バランスの取れている文字列<var>a</var>と<var>b</var>に対して,<var>a + b</var>(+は文字列の連結を表す)はバランスが取れている.</li> <li>バランスの取れている文字列<var>a</var>に対して,&quot;(&quot; + <var>a</var> + &quot;)&quot;はバランスが取れている.</li></ul> <h2>Input</h2> <p>入力は以下の形式に従う.与えられる数は全て整数である.</p> <pre><var>n</var> <var>p_1</var> <var>x_1</var> <var>. . .</var> <var>p_n</var> <var>x_n</var></pre> <h2>Constraints</h2> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>1≦n≦1,000</var></li> <li><var>1≦x_i≦10^6</var></li> <li><var>p_i</var>は&quot;(&quot;または&quot;)&quot;</li></ul> <h2>Output</h2> <p>バランスがとれているときは&quot;YES&quot;を,そうでなければ&quot;NO&quot;を1行に出力せよ.</p> <h2>Sample Input 1</h2> <pre>3 ( 5 ) 4 ) 1</pre> <h2>Output for the Sample Input 1</h2> <pre>YES</pre> <p>文字列<var>S</var>=&quot;&#x28;&#x28;&#x28;&#x28;&#x28;&#x29;&#x29;&#x29;&#x29;&#x29;&quot;はバランスがとれている.</p> <h2>Sample Input 2</h2> <pre>5 ( 2 ) 2 ( 3 ) 1 ) 2</pre> <h2>Output for the Sample Input 2</h2> <pre>YES</pre> <h2>Sample Input 3</h2> <pre>2 ) 1 ( 1</pre> <h2>Output for the Sample Input 3</h2> <pre>NO</pre>
p00910
<H1><font color="#000">Problem G: </font>Let There Be Light</H1> <p> Suppose that there are some light sources and many spherical balloons. All light sources have sizes small enough to be modeled as point light sources, and they emit light in all directions. The surfaces of the balloons absorb light and do not reflect light. Surprisingly in this world, balloons may overlap. </p> <p> You want the total illumination intensity at an objective point as high as possible. For this purpose, some of the balloons obstructing lights can be removed. Because of the removal costs, however, there is a certain limit on the number of balloons to be removed. Thus, you would like to remove an appropriate set of balloons so as to maximize the illumination intensity at the objective point. </p> <p> The following figure illustrates the configuration specified in the first dataset of the sample input given below. The figure shows the <i>xy</i>-plane, which is enough because, in this dataset, the <i>z</i>-coordinates of all the light sources, balloon centers, and the objective point are zero. In the figure, light sources are shown as stars and balloons as circles. The objective point is at the origin, and you may remove up to 4 balloons. In this case, the dashed circles in the figure correspond to the balloons to be removed. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_letThereBeLight"> <p> Figure G.1: First dataset of the sample input. </p> </center> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is formatted as follows. </p> <p> <i>N M R</i><br/> <i>S</i><sub>1<i>x</i></sub> <i>S</i><sub>1<i>y</i></sub> <i>S</i><sub>1<i>z</i></sub> <i>S</i><sub>1<i>r</i></sub><br/> ...<br/> <i>S</i><sub><i>Nx</i></sub> <i>S</i><sub><i>Ny</i></sub> <i>S</i><sub><i>Nz</i></sub> <i>S</i><sub><i>Nr</i></sub><br/> <i>T</i><sub>1<i>x</i></sub> <i>T</i><sub>1<i>y</i></sub> <i>T</i><sub>1<i>z</i></sub> <i>T</i><sub>1<i>b</i></sub><br/> ...<br/> <i>T</i><sub><i>Mx</i></sub> <i>T</i><sub><i>My</i></sub> <i>T</i><sub><i>Mz</i></sub> <i>T</i><sub><i>Mb</i></sub><br/> <i>E<sub>x</sub> E<sub>y</sub> E<sub>z</sub></i><br/> </p> <p> The first line of a dataset contains three positive integers, <i>N</i>, <i>M</i> and <i>R</i>, separated by a single space. <i>N</i> means the number of balloons that does not exceed 2000. <i>M</i> means the number of light sources that does not exceed 15. <i>R</i> means the number of balloons that may be removed, which does not exceed <i>N</i>. </p> <p> Each of the <i>N</i> lines following the first line contains four integers separated by a single space. (<i>S<sub>ix</sub></i>, <i>S<sub>iy</sub></i>, <i>S<sub>iz</sub></i>) means the center position of the <i>i</i>-th balloon and <i>S<sub>ir</sub></i> means its radius. </p> <p> Each of the following <i>M</i> lines contains four integers separated by a single space. (<i>T<sub>jx</sub></i>, <i>T<sub>jy</sub></i>, <i>T<sub>jz</sub></i>) means the position of the <i>j</i>-th light source and <i>T<sub>jb</sub></i> means its brightness. </p> <p> The last line of a dataset contains three integers separated by a single space. (<i>E<sub>x</sub></i>, <i>E<sub>y</sub></i>, <i>E<sub>z</sub></i>) means the position of the objective point. </p> <p> <i>S<sub>ix</sub></i>, <i>S<sub>iy</sub></i>, <i>S<sub>iz</sub></i>, <i>T<sub>jx</sub></i>, <i>T<sub>jy</sub></i>, <i>T<sub>jz</sub></i>, <i>E<sub>x</sub></i>, <i>E<sub>y</sub></i> and <i>E<sub>z</sub></i> are greater than -500, and less than 500. <i>S<sub>ir</sub></i> is greater than 0, and less than 500. <i>T<sub>jb</sub></i> is greater than 0, and less than 80000. </p> <p> At the objective point, the intensity of the light from the <i>j</i>-th light source is in inverse proportion to the square of the distance, namely </p> <p style="text-align:center"> <i>T<sub>jb</sub></i> / { (<i>T<sub>jx</sub></i> &minus; <i>E<sub>x</sub></i>)<sup>2</sup> + (<i>T<sub>jy</sub></i> &minus; <i>E<sub>y</sub></i>)<sup>2</sup> + (<i>T<sub>jz</sub></i> &minus; <i>E<sub>z</sub></i>)<sup>2</sup> }, </p> <p> if there is no balloon interrupting the light. The total illumination intensity is the sum of the above. </p> <p> You may assume the following. </p> <ol> <li> The distance between the objective point and any light source is not less than 1.</li> <li> For every <i>i</i> and <i>j</i>, even if <i>S<sub>ir</sub></i> changes by &epsilon; (|&epsilon;| &lt; 0.01), whether the <i>i</i>-th balloon hides the <i>j</i>-th light or not does not change. </ol> <p> The end of the input is indicated by a line of three zeros. </p> <H2>Output</H2> <p> For each dataset, output a line containing a decimal fraction which means the highest possible illumination intensity at the objective point after removing <i>R</i> balloons. The output should not contain an error greater than 0.0001. </p> <H2>Sample Input</H2> <pre> 12 5 4 0 10 0 1 1 5 0 2 1 4 0 2 0 0 0 2 10 0 0 1 3 -1 0 2 5 -1 0 2 10 10 0 15 0 -10 0 1 10 -10 0 1 -10 -10 0 1 10 10 0 1 0 10 0 240 10 0 0 200 10 -2 0 52 -10 0 0 100 1 1 0 2 0 0 0 12 5 4 0 10 0 1 1 5 0 2 1 4 0 2 0 0 0 2 10 0 0 1 3 -1 0 2 5 -1 0 2 10 10 0 15 0 -10 0 1 10 -10 0 1 -10 -10 0 1 10 10 0 1 0 10 0 260 10 0 0 200 10 -2 0 52 -10 0 0 100 1 1 0 2 0 0 0 5 1 3 1 2 0 2 -1 8 -1 8 -2 -3 5 6 -2 1 3 3 -4 2 3 5 1 1 2 7 0 0 0 5 1 2 1 2 0 2 -1 8 -1 8 -2 -3 5 6 -2 1 3 3 -4 2 3 5 1 1 2 7 0 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 3.5 3.6 1.1666666666666667 0.0 </pre>
p01252
<H1><font color="#000">Problem C:</font> Alice and Bob</H1> <p> Alice and Bob are in love with each other, but they have difficulty going out on a date - Alice is a very busy graduate student at the ACM university. </p> <p> For this reason, Bob came to the ACM university to meet her on a day. He tried to reach the meeting spot but got lost because the campus of the university was very large. Alice talked with him via mobile phones and identified his current location exactly. So she told him to stay there and decided to go to the place where she would be visible to him without interruption by buildings. </p> <p> The campus can be considered as a two-dimensional plane and all buildings as rectangles whose edges are parallel to x-axis or y-axis. Alice and Bob can be considered as points. Alice is visible to Bob if the line segment connecting them does not intersect the interior of any building. Note that she is still visible even if the line segment touches the borders of buildings. </p> <p> Since Alice does not like to walk, she wants to minimize her walking distance. Can you write a program that finds the best route for her? </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_aliceAndBob"> <p>Figure 1: Example Situation</p> </center> <H2>Input</H2> <p> The input contains multiple datasets. The end of the input is indicated by a line containing a single zero. Each dataset is formatted as follows. </p> <pre> <i>N</i> <i>x</i><sub>11</sub> <i>y</i><sub>11</sub> <i>x</i><sub>12</sub> <i>y</i><sub>12</sub> <i>x</i><sub>21</sub> <i>y</i><sub>21</sub> <i>x</i><sub>22</sub> <i>y</i><sub>22</sub> ... <i>x</i><sub><i>N</i>1</sub> <i>y</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>A<sub>x</sub> A<sub>y</sub> B<sub>x</sub> B<sub>y</sub></i> </pre> <p> <i>N</i> (0 &lt; <i>N</i> &le; 30) is the number of buildings. The <i>i</i>-th building is given by its bottom left corner (<i>x</i><sub><i>i</i>1</sub> , <i>y</i><sub><i>i</i>1</sub>) and up right corner (<i>x</i><sub><i>i</i>2</sub>, <i>y</i><sub><i>i</i>2</sub> ). (<i>A<sub>x</sub></i>, <i>A<sub>y</sub></i>) is the location of Alice and (<i>B<sub>x</sub></i>, <i>B<sub>y</sub></i>) is that of Bob. All integers <i>x</i><sub><i>i</i>1</sub>, <i>y</i><sub><i>i</i>1</sub>, <i>x</i><sub><i>i</i>2</sub>, <i>y</i><sub><i>i</i>2</sub>, <i>A<sub>x</sub></i>, <i>A<sub>y</sub></i>, <i>B<sub>x</sub></i> and <i>B<sub>y</sub></i> are between -10000 and 10000, inclusive. You may assume that no building touches or overlaps other buildings. </p> <H2>Output</H2> <p> For each dataset, output a separate line containing the minimum distance Alice has to walk. </p> <p> The value may contain an error less than or equal to 0.001. You may print any number of digits after the decimal point. </p> <H2>Sample Input</H2> <pre> 1 3 3 7 7 2 2 8 2 2 2 5 5 9 6 1 9 5 1 5 10 5 2 2 1 3 2 2 3 3 4 1 1 4 4 1 3 3 7 7 1 5 9 5 1 3 3 7 7 1 5 8 5 1 3 3 7 7 1 5 10 5 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.000 0.000 0.000 5.657 6.406 4.992 </pre>
p03795
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has a favorite restaurant.</p> <p>The price of any meal served at the restaurant is <var>800</var> yen (the currency of Japan), and each time a customer orders <var>15</var> meals, the restaurant pays <var>200</var> yen back to the customer.</p> <p>So far, Snuke has ordered <var>N</var> meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be <var>x</var> yen, and let the amount of money the restaurant has paid back to Snuke be <var>y</var> yen. Find <var>x-y</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> </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>20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>15800 </pre> <p>So far, Snuke has paid <var>16000</var> yen, and the restaurant has paid back <var>200</var> yen. Thus, the answer is <var>15800</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>60 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>47200 </pre> <p>Snuke has paid <var>48000</var> yen for <var>60</var> meals, and the restaurant has paid back <var>800</var> yen.</p></section> </div> </span>
p04050
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got a present from his mother on his birthday. The present was a pair of two sequences <var>a</var> and <var>b</var>, consisting of positive integers. They satisfied all of the following properties:</p> <ul> <li>The sum of all elements of <var>a</var> is <var>N</var>.</li> <li>The sum of all elements of <var>b</var> is <var>N</var>.</li> <li>Any string of length <var>N</var> that satisfies the following two conditions (1) and (2) will also satisfy the condition (3).</li> <ul style="list-style:none;"> <li><b>(1)</b> Any of the following forms a palindrome: the first <var>a_1</var> letters, the following <var>a_2</var> letters, the following <var>a_3</var> letters and so on.</li> <li><b>(2)</b> Any of the following forms a palindrome: the first <var>b_1</var> letters, the following <var>b_2</var> letters, the following <var>b_3</var> letters and so on.</li> <li><b>(3)</b> All <var>N</var> letters are the same.</li> </ul> </ul> <p>He was happy, until one day he lost both of the sequences. Now, he only remembers that the sequence <var>a</var> was a permutation of another sequence <var>A</var> of length <var>M</var>.</p> <p>To bring him happiness again, his mother has decided to give him another pair of sequences <var>a</var> and <var>b</var> that satisfies his favorite properties and is consistent with his memory.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≦N≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦A_i≦10^5</var></li> <li>The sum of all <var>A_i</var> equals <var>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>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a pair of sequences <var>a</var> and <var>b</var> that satisfies the properties and is consistent with Snuke's memory, print three lines. The first line must contain the sequence <var>a</var>, the second line must contain the length of the sequence <var>b</var>, and the third line must contain the sequence <var>b</var>.</p> <p>If such a pair does not exist (because Snuke's memory is wrong or some other reason), print a single line containing the word <code>Impossible</code> (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 1 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 3 1 2 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>55 10 1 2 3 4 5 6 7 8 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Impossible </pre></section> </div> </span>
p02887
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> slimes lining up from left to right. The colors of these slimes will be given as a string <var>S</var> of length <var>N</var> consisting of lowercase English letters. The <var>i</var>-th slime from the left has the color that corresponds to the <var>i</var>-th character of <var>S</var>.</p> <p>Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.</p> <p>Ultimately, how many slimes will be there?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>|S| = N</var></li> <li><var>S</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the final number of slimes.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 aabbbbaaca </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>Ultimately, these slimes will fuse into <code>abaca</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 aaaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>All the slimes will fuse into one.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>20 xxzaffeeeeddfkkkkllq </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>10 </pre></section> </div> </span>
p03280
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There is a farm whose length and width are <var>A</var> yard and <var>B</var> yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)</p> <p><img alt=" " src="https://img.atcoder.jp/ghi/27d063746b460f1132b6a99aa535a562.png"/></p> <p>What is the area of this yard excluding the roads? Find it.</p> </section> </div> <div class="part"> <section> <h3>Note</h3> <p>It can be proved that the positions of the roads do not affect the area.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>A</var> is an integer between <var>2</var> and <var>100</var> (inclusive).</li> <li><var>B</var> is an integer between <var>2</var> and <var>100</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the area of this yard excluding the roads (in square yards).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>In this case, the area is <var>1</var> square yard.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>24 </pre> <p>In this case, the area is <var>24</var> square yards. </p></section> </div> </span>
p01747
<p> すなけ君は,(自己交差を持たない) <var>n</var> 個の頂点からなる折れ線の形をしている.最初に,すなけ君の <var>i</var> 番目の頂点は <var>(x<sub>i</sub>, y<sub>i</sub>)</var> にある.すなけ君は,平行移動や回転をして連続的に移動することはできるが,変形(折れ線の長さや二つの線分のなす角度を変える) することはできない.<var>y</var> = 0 は壁であり,(0, 0) に微小な穴が開いている.すなけ君がこの穴を通って全体が <var>y</var> &lt; 0 をみたすように移動できるかどうか判定せよ. </p> <h2>Constraints</h2> <ul> <li> 2 &le; <var>n</var> &le; 1000 </li> <li> 0 &le; <var>x<sub>i</sub></var> &le; 10<sup>9</sup> </li> <li> 1 &le; <var>y<sub>i</sub></var> &le; 10<sup>9</sup> </li> <li> 折れ線は自己交差を持たない </li> <li> どの三点も同一直線上にない </li> <li> <var>(x<sub>i</sub>, y<sub>i</sub>) &ne; (x<sub>i+1</sub>, y<sub>i+1</sub>)</var> </li> <li> 入力は全て整数である </li> </ul> <h2>Input</h2> <pre> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> . . . <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <h2>Output</h2> <p> すなけ君が穴を通って移動できる場合は"<spna>Possible</span>", できない場合は"<span>Impossible</span>" と出力せよ. </p> <h2>Sample Input 1</h2> <pre> 4 0 1 1 1 1 2 2 2 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummer2014_sunake" title="Sunake" alt="Sunake"> <h2>Sample Output 1</h2> <pre> Possible </pre> <ul> <li> −<var>y</var> 方向に 1 平行移動する. </li> <li> (0, 0) を中心として 90 度反時計回りに回転する.</li> <li> −<var>y</var> 方向に 1 平行移動する.</li> <li> (0, 0) を中心として 90 度時計回りに回転する.</li> <li> −<var>y</var> 方向に 1 平行移動する.</li> <li> (0, 0) を中心として 90 度反時計回りに回転する.</li> <li> −<var>y</var> 方向に 2 平行移動する.</li> </ul> <h2>Sample Input 2</h2> <pre> 11 63 106 87 143 102 132 115 169 74 145 41 177 56 130 28 141 19 124 0 156 22 183 </pre> <h2>Sample Output 2</h2> <pre> Impossible </pre>
p02868
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> points numbered <var>1</var> to <var>N</var> arranged in a line in this order.</p> <p>Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do <var>M</var> operations to add edges in this graph. The <var>i</var>-th operation is as follows:</p> <ul> <li>The operation uses integers <var>L_i</var> and <var>R_i</var> between <var>1</var> and <var>N</var> (inclusive), and a positive integer <var>C_i</var>. For every pair of integers <var>(s, t)</var> such that <var>L_i \leq s &lt; t \leq R_i</var>, add an edge of length <var>C_i</var> between Vertex <var>s</var> and Vertex <var>t</var>.</li> </ul> <p>The integers <var>L_1, ..., L_M</var>, <var>R_1, ..., R_M</var>, <var>C_1, ..., C_M</var> are all given as input.</p> <p>Takahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex <var>1</var> to Vertex <var>N</var> in the final graph.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq M \leq 10^5</var></li> <li><var>1 \leq L_i &lt; R_i \leq N</var></li> <li><var>1 \leq C_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>L_1</var> <var>R_1</var> <var>C_1</var> <var>:</var> <var>L_M</var> <var>R_M</var> <var>C_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the length of the shortest path from Vertex <var>1</var> to Vertex <var>N</var> in the final graph. If there is no shortest path, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 3 2 2 4 3 1 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>We have an edge of length <var>2</var> between Vertex <var>1</var> and Vertex <var>2</var>, and an edge of length <var>3</var> between Vertex <var>2</var> and Vertex <var>4</var>, so there is a path of length <var>5</var> between Vertex <var>1</var> and Vertex <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 1 2 1 3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 7 1 5 18 3 4 8 1 3 5 4 7 10 5 9 8 6 10 5 8 10 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>28 </pre></section> </div> </span>
p00855
<H1><font color="#000">Problem B:</font> Prime Gap</H1> <p> The sequence of <i>n</i> - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers <i>p</i> and <i>p</i> + <i>n</i> is called a <i>prime</i> gap of length <i>n</i>. For example, (24, 25, 26, 27, 28) between 23 and 29 is a prime gap of length 6. </p> <p> Your mission is to write a program to calculate, for a given positive integer <i>k</i>, the length of the prime gap that contains <i>k</i>. For convenience, the length is considered 0 in case no prime gap contains <i>k</i>. </p> <H2>Input</H2> <p> The input is a sequence of lines each of which contains a single positive integer. Each positive integer is greater than 1 and less than or equal to the 100000th prime number, which is 1299709. The end of the input is indicated by a line containing a single zero. </p> <H2>Output</H2> <p> The output should be composed of lines each of which contains a single non-negative integer. It is the length of the prime gap that contains the corresponding positive integer in the input if it is a composite number, or 0 otherwise. No other characters should occur in the output. </p> <H2>Sample Input</H2> <pre> 10 11 27 2 492170 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4 0 6 0 114 </pre>
p01317
<h2><font color="#000">Problem D:</font> Mr. Rito Post Office</h2> <!-- <h3><U>Mr. リトー郵便局</U></h3> --> <p>あなたは離島の郵便局に勤めるプログラマである.あなたの住んでいる地域は,複数の島々からなる.各島には一つ以上の港町がある.それらに加えて他の町や村があるかもしない.ある島から別の島に向かうためには船を使わなければならない.一つの島の中を回るには陸路が使えるが,海路を利用した方が速いこともある.</p> <p>近年行われた郵便局の民営化をきっかけに,経費削減に向けて郵便配達員の人員整理が全国的に行われた.離島の郵便局もその例外ではなく,結果として郵便配達員は利藤さんただ一人となってしまった.その郵便局が集配を担当する地域は非常に広いため,一人で集配するのは大変な作業である.なので,どのようにすれば効率的に集配を行えるのか,利藤さんがあなたに助けを求めてきた.</p> <p>あなたの仕事は,利藤さんがたどるべき町や村の集配順序が与えられたときに,最短巡回経路を求めるプログラムを書くことである.</p> <p>利藤さんは,決して指定された順序以外で集配業務を行うことができない.しかし,ある町や村から別の町や村へ移動する際に,他の町や村を経由して移動することは許可されている.また,利藤さんは島々を巡るための一隻の船を持っている.</p> <p>例えば,町A,町B,村Cという集配順序が与えられた場合,町Aから町Bへ向かう際にどの町や村を経由してもかまわない.このとき,村Cを経由しても構わないが,集配順序を守るためには,一度町Bに行って集配をおこなってから,改めて村Cを訪れて集配をおこなわなければならない.また,町Aから海路を用いて町Bに向かい,町Bから陸路を用いて村Cに向かった場合,船を町Bに置いたままになる.したがって,次に海路を使いたい場合は町Bに戻る必要がある.</p> <p>一つの町や村において複数回集配をしなければならない場合もある.たとえば,町A,村B,町C,村Bという集配順序が与えられるかもしれない.このとき,町Aから村Bをたどらずに町Cに向かった場合は,町Cでいきなり集配をおこなうことはできない.最初の村Bでの集配が終わっていないからである.町Cで集配を済ませた後で村Bを訪れて集配しても,一回目の村Bの集配を終わらせたことにはならない.</p> <p>利藤さんは,はじめに必ずある港町に船とともにいる.利藤さんはベテランであるため,移動時間以外の集配作業にかかる時間は無視してよい.また,最後の町または村での集配業務が完了するまでの時間だけが問題であり,船をもとの位置に戻して郵便局に帰るまでの時間は考慮しなくてよい.</p> <h2>Input</h2> <p>入力は複数のデータセットから構成される.各データセットの形式は次に示すとおりである.</p> <blockquote><i>N</i> <i>M</i><br /> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i> <i>t<sub>1</sub></i> <i>sl<sub>1</sub></i><br /> <i>x<sub>2</sub></i> <i>y<sub>2</sub></i> <i>t<sub>2</sub></i> <i>sl<sub>2</sub></i><br /> ...<br /> <i>x<sub>M</sub></i> <i>y<sub>M</sub></i> <i>t<sub>M</sub></i> <i>sl<sub>M</sub></i><br /> <i>R</i><br /> <i>z<sub>1</sub></i> <i>z<sub>2</sub></i> ... <i>z<sub>R</sub></i><br /> </blockquote> <p>データセットの中の入力項目は,すべて非負の整数である.行中の入力項目の区切りは空白 1 個である.</p> <p>最初の行は,陸路及び海路網の大きさを規定する.</p> <p><i>N</i> (2 &le; <i>N</i> &le; 200) は,町または村の数である. それぞれの町または村には,1 から <i>N</i> までの固有の番号を割り当てる. <i>M</i> (1 &le; <i>M</i> &le; 10000) は,陸路と海路の合計本数である.</p> <p>2 行目から 1 + <i>M</i> 行目は,陸路または海路の記述である. <i>x<sub>i</sub></i> と <i>y<sub>i</sub></i> (1 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> &le; <i>N</i>) は両端の町または村の番号を表す. <i>t<sub>i</sub></i> (1 &le; <i>t<sub>i</sub></i> &le; 1000) はその陸路または海路の移動時間を表す. <i>sl<sub>i</sub></i> は &lsquo;L&rsquo; または &lsquo;S&rsquo; のいずれかであり,Lは陸路を,Sは海路をそれぞれ表す.</p> <p>ある2つの町や村を直接結ぶ陸路または海路が2本以上存在することがある. それぞれの陸路または海路は双方向であり,すなわちどちらの向きにも移動できる.</p> <p><i>M</i> + 2 行目の <i>R</i> (1 &le; <i>R</i> &le; 1000)は,利藤さんが担当する集配先の数を表す. <i>M</i> + 3 行目には,集配先の町や村の番号 <i>z<sub>i</sub></i> (1 &le; <i>z<sub>i</sub></i> &le; <i>N</i>) が集配順に <i>R</i> 個並んでいる.</p> <p>初期状態では利藤さんと船はともに港町 <i>z<sub>1</sub></i> に存在する. 初期状態から集配先の町や村へは,必ず何らかの方法で移動することができる.</p> <p>入力の終わりは,空白で区切られた2つの0を含む1行で示される.</p> <h2>Output</h2> <p>入力の各データセットに対して,与えられた集配順序で利藤さんが町と村を巡回するために必要な最短移動時間を求め,1行に出力せよ.</p> <h2>Sample Input</h2> <pre> 3 3 1 2 5 L 1 2 7 S 2 3 11 S 3 1 2 3 5 5 1 2 15 L 2 3 10 L 4 5 7 L 1 3 30 S 3 4 100 S 5 1 3 5 4 1 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 18 269 </pre>
p00156
<H1>城の堀</H1> <p> いま、忍者が城外から天守閣に忍び入ろうと計画を立てています。この忍者は地面を走ったり、堀の中を泳いだりすることは難なくできますが、堀から這い上がることはとても苦手なので、忍者は堀に入る回数をできるだけ少なくしたいと考えています。 </p> <p> お城の見取図を入力とし、城外から天守閣に至るまでに、堀から這い上がらなくてはならない最小回数を出力するプログラムを作成して下さい。お城の見取図は二次元格子として与えられます。見取り図に描かれた記号には、天守閣の位置を示す「&」と堀の位置を示す「#」の位置が記され、そのほかの地点には「.」(半角ピリオド)が記されています。なお、お城には天守閣は一つだけあるものとし、忍者は走ったり泳いだりして移動するときに東西南北方向に1マスずつ移動するものとし、斜めには移動しません。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロ2つの行で示されます。各データセットは以下の形式で与えられます。 </p> <pre> <var>n</var> <var>m</var> <var>c<sub>1,1</sub></var><var>c<sub>1,2</sub></var>...<var>c<sub>1,n</sub></var> <var>c<sub>2,1</sub></var><var>c<sub>2,2</sub></var>...<var>c<sub>2,n</sub></var> : <var>c<sub>m,1</sub></var><var>c<sub>m,2</sub></var>...<var>c<sub>m,n</sub></var> </pre> <p> 1行目に見取図の東西の幅 <var>n</var> と 南北の幅 <var>m</var> (1 &le; <var>n</var>, <var>m</var> &le; 100) が与えられる。続く<var>m</var> 行に見取り図の <var>i</var> 行目の情報が与えられる。各情報は記号「&」、「#」、「.」からなる長さ <var>n</var> の文字列である。 </p> <p> データセットの数は 50 を越えない。 </p> <H2>Output</H2> <p> データセットごとに堀から這い上がらなくてはならない最小回数(整数)を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 5 5 .###. #...# #.&.# #...# .###. 18 15 ..####....####.... ####..####....#### #...............## .#.############.## #..#..........#.## .#.#.########.#.## #..#.#......#.#.## .#.#....&...#.#.## #..#........#.#.## .#.#.########.#.## #..#..........#.## .#.############.## #...............## .################# ################## 9 10 ######### ........# #######.# #.....#.# #.###.#.# #.#&#.#.# #.#...#.# #.#####.# #.......# ######### 9 3 ###...### #.#.&.#.# ###...### 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 0 0 </pre>
p00506
<H1> 問題 2</H1> <br/> <p>  入力ファイルの1行目に正整数 n が書いてあり, 2行目には半角空白文字1つを区切りとして, n 個の正整数が書いてある. n は 2 または 3 であり, 2行目に書かれているどの整数も値は 10<sup>8</sup> 以下である. これら2個または3個の数の公約数をすべて求め, 小さい方から順に1行に1個ずつ出力せよ. 自明な公約数(「1」)も出力すること. </p> <p>  <!--入力ファイルの改行コードは CR+LF である. また,--> 出力ファイルにおいては, 出力の最後行にも改行コードを入れること. </p> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 2 75 125 </pre> <h3>出力例1</h3> <pre> 1 5 25 </pre> <br> <h3>入力例2</h3> <pre> 3 110 22 88 </pre> <h3>出力例2</h3> <pre> 1 2 11 22 </pre> <br> <h3>入力例3</h3> <pre> 3 66 11 3 </pre> <h3>出力例3</h3> <pre> 1 </pre> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p03003
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given two integer sequences <var>S</var> and <var>T</var> of length <var>N</var> and <var>M</var>, respectively, both consisting of integers between <var>1</var> and <var>10^5</var> (inclusive).</p> <p>In how many pairs of a subsequence of <var>S</var> and a subsequence of <var>T</var> do the two subsequences are the same in content?</p> <p>Here the subsequence of <var>A</var> is a sequence obtained by removing zero or more elements from <var>A</var> and concatenating the remaining elements without changing the order.</p> <p>For both <var>S</var> and <var>T</var>, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.</p> <p>Since the answer can be tremendous, print the number modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N, M \leq 2 \times 10^3</var></li> <li>The length of <var>S</var> is <var>N</var>.</li> <li>The length of <var>T</var> is <var>M</var>. </li> <li><var>1 \leq S_i, T_i \leq 10^5</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>S_1</var> <var>S_2</var> <var>...</var> <var>S_{N-1}</var> <var>S_{N}</var> <var>T_1</var> <var>T_2</var> <var>...</var> <var>T_{M-1}</var> <var>T_{M}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of pairs of a subsequence of <var>S</var> and a subsequence of <var>T</var> such that the subsequences are the same in content, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 1 3 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p><var>S</var> has four subsequences: <var>(), (1), (3), (1, 3)</var>.</p> <p><var>T</var> has four subsequences: <var>(), (3), (1), (3, 1)</var>.</p> <p>There are <var>1 \times 1</var> pair of subsequences in which the subsequences are both <var>()</var>, <var>1 \times 1</var> pair of subsequences in which the subsequences are both <var>(1)</var>, and <var>1 \times 1</var> pair of subsequences in which the subsequences are both <var>(3)</var>, for a total of three pairs.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> <p><var>S</var> has four subsequences: <var>(), (1), (1), (1, 1)</var>.</p> <p><var>T</var> has four subsequences: <var>(), (1), (1), (1, 1)</var>.</p> <p>There are <var>1 \times 1</var> pair of subsequences in which the subsequences are both <var>()</var>, <var>2 \times 2</var> pairs of subsequences in which the subsequences are both <var>(1)</var>, and <var>1 \times 1</var> pair of subsequences in which the subsequences are both <var>(1,1)</var>, for a total of six pairs. Note again that we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 4 3 4 5 6 3 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>16 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 9 9 6 5 7 5 9 8 5 6 7 8 6 8 5 5 7 9 9 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>191 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>20 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>846527861 </pre> <p>Be sure to print the number modulo <var>10^9+7</var>.</p></section> </div> </span>
p01194
<H1><font color="#000"></font>Web 0.5</H1> <!-- Problem F--> <p> In a forest, there lived a spider named Tim. Tim was so smart that he created a huge, well-structured web. Surprisingly, his web forms a set of equilateral and concentric <i>N</i>-sided polygons whose edge lengths form an arithmetic sequence. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_web05"> <p>Figure 1: An example web of Tim</p> </center> <p> Corresponding vertices of the N-sided polygons lie on a straight line, each apart from neighboring ver- tices by distance 1. Neighboring vertices are connected by a thread (shown in the figure as solid lines), on which Tim can walk (you may regard Tim as a point). Radial axes are numbered from 1 to <i>N</i> in a rotational order, so you can denote by (<i>r</i>, <i>i</i>) the vertex on axis <i>i</i> and apart from the center of the web by distance <i>r</i>. You may consider the web as infinitely large, i.e. consisting of infinite number of <i>N</i>-sided polygons, since the web is so gigantic. </p> <p> Tim’s web is thus marvelous, but currently has one problem: due to rainstorms, some of the threads are damaged and Tim can’t walk on those parts. </p> <p> Now, a bug has been caught on the web. Thanks to the web having so organized a structure, Tim accu- rately figures out where the bug is, and heads out for that position. You, as a biologist, are interested in whether Tim is smart enough to move through the shortest possible route. To judge that, however, you need to know the length of the shortest route yourself, and thereby decided to write a program which calculates that length. </p> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case begins with a line containing two integers <i>N</i> (3 &le; <i>N</i> &le; 100) and <i>X</i> (0 &le; <i>X</i> &le; 100), where <i>N</i> is as described above and <i>X</i> denotes the number of damaged threads. Next line contains four integers <i>r<sub>S</sub></i>, <i>i<sub>S</sub></i>, <i>r<sub>T</sub></i>, and <i>i<sub>T</sub></i>, meaning that Tim is starting at (<i>r<sub>S</sub></i>, <i>i<sub>S</sub></i>) and the bug is at (<i>r<sub>T</sub></i>, <i>i<sub>T</sub></i>). This line is followed by <i>X</i> lines, each containing four integers <i>r<sub>A</sub></i>, <i>i<sub>A</sub></i>, <i>r<sub>B</sub></i>, and <i>i<sub>B</sub></i>, meaning that a thread connecting (<i>r<sub>A</sub></i>, <i>i<sub>A</sub></i>) and (<i>r<sub>B</sub></i>, <i>i<sub>B</sub></i>) is damaged. Here (<i>r<sub>A</sub></i>, <i>i<sub>A</sub></i>) and (<i>r<sub>B</sub></i>, <i>i<sub>B</sub></i>) will be always neighboring to each other. Also, for all vertices (<i>r</i>, <i>i</i>) given above, you may assume 1 &le; <i>r</i> &le; 10<sup>7</sup> and 1 &le; <i>i</i> &le; <i>N</i>. </p> <p> There will be at most 200 test cases. You may also assume that Tim is always able to reach where the bug is. </p> <p> The input is terminated by a line containing two zeros. </p> <H2>Output</H2> <p> For each test case, print the length of the shortest route in a line. You may print any number of digits after the decimal point, but the error must not be greater than 0.01. </p> <H2>Sample Input</H2> <pre> 5 1 2 1 3 2 2 1 2 2 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4.18 </pre>
p03453
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a graph with <var>N</var> vertices and <var>M</var> edges, and there are two people on the graph: Takahashi and Aoki.</p> <p>The <var>i</var>-th edge connects Vertex <var>U_i</var> and Vertex <var>V_i</var>. The time it takes to traverse this edge is <var>D_i</var> minutes, regardless of direction and who traverses the edge (Takahashi or Aoki).</p> <p>Takahashi departs Vertex <var>S</var> and Aoki departs Vertex <var>T</var> at the same time. Takahashi travels to Vertex <var>T</var> and Aoki travels to Vertex <var>S</var>, both in the shortest time possible. Find the number of the pairs of ways for Takahashi and Aoki to choose their shortest paths such that they never meet (at a vertex or on an edge) during the travel, modulo <var>10^9 + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var> <var>000</var></li> <li><var>1 \leq M \leq 200</var> <var>000</var></li> <li><var>1 \leq S, T \leq N</var></li> <li><var>S \neq T</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 D_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><var>D_i</var> are integers.</li> <li>The given graph is connected.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>S</var> <var>T</var> <var>U_1</var> <var>V_1</var> <var>D_1</var> <var>U_2</var> <var>V_2</var> <var>D_2</var> <var>:</var> <var>U_M</var> <var>V_M</var> <var>D_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 4 1 3 1 2 1 2 3 1 3 4 1 4 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two ways to choose shortest paths that satisfies the condition:</p> <ul> <li>Takahashi chooses the path <var>1 \rightarrow 2 \rightarrow 3</var>, and Aoki chooses the path <var>3 \rightarrow 4 \rightarrow 1</var>.</li> <li>Takahashi chooses the path <var>1 \rightarrow 4 \rightarrow 3</var>, and Aoki chooses the path <var>3 \rightarrow 2 \rightarrow 1</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 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>3 3 1 3 1 2 1 2 3 1 3 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>8 13 4 2 7 3 9 6 2 3 1 6 4 7 6 9 3 8 9 1 2 2 2 8 12 8 6 9 2 5 5 4 2 18 5 3 7 5 1 515371567 4 8 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>6 </pre></section> </div> </span>
p03900
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi found an integer sequence <var>(A_1,A_2,...,A_N)</var> with <var>N</var> terms. Since it was too heavy to carry, he decided to compress it into a single integer.</p> <p>The compression takes place in <var>N-1</var> steps, each of which shorten the length of the sequence by <var>1</var>. Let <var>S</var> be a string describing the steps, and the sequence on which the <var>i</var>-th step is performed be <var>(a_1,a_2,...,a_K)</var>, then the <var>i</var>-th step will be as follows:</p> <ul> <li>When the <var>i</var>-th character in <var>S</var> is <code>M</code>, let <var>b_i = max(a_i,a_{i+1})</var> <var>(1 ≦ i ≦ K-1)</var>, and replace the current sequence by <var>(b_1,b_2,...,b_{K-1})</var>.</li> <li>When the <var>i</var>-th character in <var>S</var> is <code>m</code>, let <var>b_i = min(a_i,a_{i+1})</var> <var>(1 ≦ i ≦ K-1)</var>, and replace the current sequence by <var>(b_1,b_2,...,b_{K-1})</var>.</li> </ul> <p>Takahashi decided the steps <var>S</var>, but he is too tired to carry out the compression. On behalf of him, find the single integer obtained from the compression.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≦ N ≦ 10^5</var></li> <li><var>1 ≦ A_i ≦ N</var></li> <li><var>S</var> consists of <var>N-1</var> characters.</li> <li>Each character in <var>S</var> is either <code>M</code> or <code>m</code>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li>In the test set worth <var>400</var> points, there exists <var>i (1 ≦ i &lt; N-1)</var> such that the first <var>i</var> characters in <var>S</var> are <code>M</code>, and the remaining characters are <code>m</code>, that is, <var>S</var> is in the form <code>M...Mm...m</code>.</li> <li>In the test set worth <var>800</var> points, the odd-number-th characters in <var>S</var> are <code>M</code>, and the even-number-th characters are <code>m</code>, that is, <var>S</var> is in the form <code>MmMmMm...</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> … <var>A_N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the single integer obtained from the compression.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 3 4 MmM </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The initial sequence <var>( 1 , 2 , 3 , 4 )</var> is compressed as follows:</p> <ul> <li>After the first step, the sequence is <var>( 2 , 3 , 4 )</var>.</li> <li>After the second step, the sequence is <var>( 2 , 3 )</var>.</li> <li>After the third step, the sequence is <var>( 3 )</var>.</li> </ul> <p>Thus, the single integer obtained from the compression is <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 4 2 2 1 MMmm </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>10 1 8 7 6 8 5 2 2 6 1 MmmmmMMMm </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>20 12 7 16 8 7 19 8 19 20 11 7 13 20 3 4 11 19 11 15 5 mMMmmmMMMMMMmMmmmMM </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>11 </pre></section> </div> </span>
p02612
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will buy a product for <var>N</var> yen (the currency of Japan) at a shop.</p> <p>If we use only <var>1000</var>-yen bills to pay the price, how much change will we receive?</p> <p>Assume we use the minimum number of bills required.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10000</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the amount of change as an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1900 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>100 </pre> <p>We will use two <var>1000</var>-yen bills to pay the price and receive <var>100</var> yen in change.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>We can pay the exact price.</p></section> </div> </span>
p01897
<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>G: DAG トリオ / DAG Trio</h1> <p> この問題は D: DAG Trio (Easy) と制約のみが異なる同じ設定の問題です。 </p> <h2>プロローグ</h2> <p> 弟は最近「だぐとりお」が欲しいとしきりに呟いています。 心配になった兄が調べたところ、弟のクラスでは $k$-DAG (有向グラフであって、ある $k$ 個の辺を削除すると、辺の向きを無視したときの連結成分数を $k$ にでき、かつそれら全てが DAG である) が流行っており、 3-DAG を特に DAG トリオと呼ぶことを突き止めました。 弟に尊敬されたい兄は、与えられたグラフが DAG トリオかどうかを判別するプログラムを作成することにしました。 </p> <h2>問題文</h2> <p> $N$ 頂点 $M$ 辺の有向グラフが与えられます。 各頂点には $1$ から $N$ まで番号が振られています。 各有向辺には $1$ から $M$ まで番号が振られています。 有向辺 $i$ は頂点 $a_i$ から $b_i$ に向かいます。 グラフは連結かつ単純です (辺の向きを無視すると、任意の 2 点間に道があり自己ループと多重辺がありません)。 与えられたグラフが DAG トリオならば ”YES”、そうでないなら ”NO” を出力してください。 </p> <h2>入力</h2> <p> $N \ M$<br> $a_1 \ b_1$<br> $a_2 \ b_2$<br> $\vdots$<br> $a_M \ b_M$<br> </p> <h2>制約</h2> <p> $3 \le N \le 500$<br> $\max(3, N−1) \le M \le 30000$<br> $1 \le a_i, b_i \le N$<br> グラフは辺の向きを無視したときに連結である。<br> 各 $i$ に対して$a_i \neq b_i$<br> 異なる $i, j$ に対して $\{a_i, b_i\} \neq \{a_j, b_j\}$<br> </p> <h2>出力</h2> <p> ”YES” または ”NO” を $1$ 行で出力してください。 </p> <h2>サンプル</h2> <h3>サンプル入力1</h3> <pre> 3 3 1 2 2 3 3 1 </pre> <h3>サンプル出力1</h3> <pre> YES </pre> <h3>サンプル入力2</h3> <pre> 6 7 1 2 2 3 4 3 4 5 5 6 6 4 3 6 </pre> <h3>サンプル出力2</h3> <pre> YES </pre> <h3>サンプル入力3</h3> <pre> 7 10 4 2 4 7 4 6 2 7 2 5 2 1 5 6 1 3 6 3 4 3 </pre> <h3>サンプル出力3</h3> <pre> NO </pre> <h3>サンプル入力4</h3> <pre> 4 4 1 2 3 2 4 3 2 4 </pre> <h3>サンプル出力4</h3> <pre> YES </pre> <h3>サンプル入力5</h3> <pre> 8 9 5 1 3 8 1 2 4 8 4 7 7 5 6 5 3 2 4 2 </pre> <h3>サンプル出力5</h3> <pre> YES </pre>
p00785
<H1><font color="#000">Problem F:</font> Triangle Partition</H1> <p> Suppose that a triangle and a number of points inside the triangle are given. Your job is to find a partition of the triangle so that the set of the given points are divided into three subsets of equal size. </p> <p> Let A, B and C denote the vertices of the triangle. There are <i>n</i> points, P<sub>1</sub>, P<sub>2</sub>, ... , P<sub><i>n</i></sub>, given inside &#8710;ABC. You are requested to find a point Q such that each of the three triangles &#8710;QBC, &#8710QCA and &#8710QAB contains at least <i>n</i>/3 points. Points on the boundary line are counted in both triangles. For example, a point on the line QA is counted in &#8710QCA and also in &#8710QAB. If Q coincides a point, the point is counted in all three triangles. </p> <p> It can be proved that there always exists a point Q satisfying the above condition. The problem will be easily understood from the figure below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_trianglePartition"> </center> <H2>Input</H2> <p> The input consists of multiple data sets, each representing a set of points. A data set is given in the following format. </p> <pre> <i>n</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> ... <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub> </pre> <p> The first integer <i>n</i> is the number of points, such that 3 &le; <i>n</i> &le; 300. <i>n</i> is always a multiple of 3. The coordinate of a point P<i><sub>i</sub></i> is given by (<i>x<sub>i</sub>, y<sub>i</sub></i>). <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> are integers between 0 and 1000. </p> <p> The coordinates of the triangle ABC are fixed. They are A(0, 0), B(1000, 0) and C(0, 1000). </p> <p> Each of P<sub><i>i</i></sub> is located strictly inside the triangle ABC, not on the side BC, CA nor AB. No two points can be connected by a straight line running through one of the vertices of the triangle. Speaking more precisely, if you connect a point P<i><sub>i</sub></i> with the vertex A by a straight line, another point P<i><sub>j</sub></i> never appears on the line. The same holds for B and C. </p> <p> The end of the input is indicated by a 0 as the value of <i>n</i>. The number of data sets does not exceed 10. </p> <H2>Output</H2> <p> For each data set, your program should output the coordinate of the point Q. The format of the output is as follows. </p> <pre> <i>q<sub>x</sub> q<sub>y</sub></i> </pre> <p> For each data set, a line of this format should be given. No extra lines are allowed. On the contrary, any number of space characters may be inserted before <i>q<sub>x</sub></i>, between <i>q<sub>x</sub></i> and <i>q<sub>y</sub></i> or after <i>q<sub>y</sub></i>. </p> <p> Each of <i>q<sub>x</sub></i> and <i>q<sub>y</sub></i> should be represented by a fractional number (e.g., 3.1416) but not with an exponential part (e.g., 6.023e+23 is not allowed). Four digits should follow the decimal point. </p> <p> Note that there is no unique "correct answer" in this problem. In general, there are infinitely many points which satisfy the given condition. Your result may be any one of these "possible answers". </p> <p> In your program you should be careful to minimize the effect of numeric errors in the handling of floating-point numbers. However, it seems inevitable that some rounding errors exist in the output. We expect that there is an error of 0.5 &times; 10<sup>-4</sup> in the output, and will judge your result accordingly. </p> <H2>Sample Input</H2> <pre> 3 100 500 200 500 300 500 6 100 300 100 600 200 100 200 700 500 100 600 300 0 </pre> <H2>Output for the Sample Input</H2> <pre> 166.6667 555.5556 333.3333 333.3333 </pre> <p> As mentioned above, the results shown here are not the only solutions. Many other coordinates for the point Q are also acceptable. The title of this section should really be "Sample Output for the Sample Input". </p>
p02242
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Single Source Shortest Path</H1> <p> For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$. </p> <H2>Input</H2> <p> In the first line, an integer $n$ denoting the number of vertices in $G$ is given. In the following $n$ lines, adjacency lists for each vertex $u$ are respectively given in the following format: </p> <p> $u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$ </p> <p> Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge connecting $u$ and $v_i$ (from $u$ to $v_i$). </p> <H2>Output</H2> <p> For each vertex, print its ID and the distance separated by a space character in a line respectively. Print in order of vertex IDs. </p> <H2>Constraints</H2> <ul> <li>$1 \leq n \leq 100$</li> <li>$0 \leq c_i \leq 100,000$</li> <li>$|E| \leq 10,000$</li> <li>All vertices are reachable from vertex $0$</li> </ul> <H2>Sample Input 1</H2> <pre> 5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3 </pre> <H2>Sample Output 1</H2> <pre> 0 0 1 2 2 2 3 1 4 3 </pre> <H2>Reference</H2> <p> Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. </p>
p03845
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Joisino is about to compete in the final round of a certain programming competition. In this contest, there are <var>N</var> problems, numbered <var>1</var> through <var>N</var>. Joisino knows that it takes her <var>T_i</var> seconds to solve problem <var>i(1≦i≦N)</var>.</p> <p>Also, there are <var>M</var> kinds of drinks offered to the contestants, numbered <var>1</var> through <var>M</var>. If Joisino takes drink <var>i(1≦i≦M)</var>, her brain will be stimulated and the time it takes for her to solve problem <var>P_i</var> will become <var>X_i</var> seconds. It does not affect the time to solve the other problems.</p> <p>A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1≦N≦100</var></li> <li><var>1≦T_i≦10^5</var></li> <li><var>1≦M≦100</var></li> <li><var>1≦P_i≦N</var></li> <li><var>1≦X_i≦10^5</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>T_1</var> <var>T_2</var> <var>...</var> <var>T_N</var> <var>M</var> <var>P_1</var> <var>X_1</var> <var>P_2</var> <var>X_2</var> <var>:</var> <var>P_M</var> <var>X_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 4 2 1 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 9 </pre> <p>If Joisino takes drink <var>1</var>, the time it takes her to solve each problem will be <var>1</var>, <var>1</var> and <var>4</var> seconds, respectively, totaling <var>6</var> seconds.</p> <p>If Joisino takes drink <var>2</var>, the time it takes her to solve each problem will be <var>2</var>, <var>3</var> and <var>4</var> seconds, respectively, totaling <var>9</var> seconds.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 7 2 3 8 5 3 4 2 1 7 4 13 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>19 25 30 </pre></section> </div> </span>