question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00084
<H1>怜玢゚ンゞン</H1> <p> むンタヌネットの怜玢゚ンゞン、䟋えば、Google などでは、䞖界䞭のりェブペヌゞを自動で収捚しお分類し、巚倧なデヌタベヌスを䜜成したす。たた、ナヌザが入力した怜玢キヌワヌドを解析しお、デヌタベヌス怜玢のための問い合わせ文を䜜成したす。 </p> <p> いずれの堎合も、効率的な怜玢を実珟するために耇雑な凊理を行っおいたすが、ずりあえずの基本は党お文章からの単語の切り出しです。 </p> <p> ずいうこずで、文章からの単語の切り出しに挑戊しおください。今回は以䞋の通り、単語区切りが明確な英語の文章を察象ずしたす。 </p> <ul> <li> 察象ずなる文章  改行を含たない 1024 文字以䞋の英語の文章 </li> <li> 区切り文字  いずれも半角で空癜、ピリオド、カンマのみ</li> <li> 切り出す単語  3 から 6 文字の単語2文字以䞋や7文字以䞊の単語は無芖 </li> </ul> <H2>入力</H2> <p>区切り文字及び英数字で構成される英文が行すべお半角に䞎えられたす。 </p> <H2>出力</H2> <p>空癜文字文字半角で区切られた単語を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> Rain, rain, go to Spain. </pre> <H2>Output for the Sample Input</H2> <pre> Rain rain Spain </pre> <H2>Sample Input 2</H2> <pre> Win today's preliminary contest and be qualified to visit University of Aizu. </pre> <H2>Output for the Sample Input 2</H2> <pre> Win and visit Aizu </pre>
p02543
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> points on a number line, <var>i</var>-th of which is placed on coordinate <var>X_i</var>. These points are numbered in the increasing order of coordinates. In other words, for all <var>i</var> (<var>1 \leq i \leq N-1</var>), <var>X_i &lt; X_{i+1}</var> holds. In addition to that, an integer <var>K</var> is given.</p> <p>Process <var>Q</var> queries.</p> <p>In the <var>i</var>-th query, two integers <var>L_i</var> and <var>R_i</var> are given. Here, a set <var>s</var> of points is said to be a <em>good</em> set if it satisfies all of the following conditions. Note that the definition of good sets varies over queries.</p> <ul> <li>Each point in <var>s</var> is one of <var>X_{L_i},X_{L_i+1},\ldots,X_{R_i}</var>.</li> <li>For any two distinct points in <var>s</var>, the distance between them is greater than or equal to <var>K</var>.</li> <li>The size of <var>s</var> is maximum among all sets that satisfy the aforementioned conditions.</li> </ul> <p>For each query, find the size of the union of all good sets.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq K \leq 10^9</var></li> <li><var>0 \leq X_1 &lt; X_2 &lt; \cdots &lt; X_N \leq 10^9</var></li> <li><var>1 \leq Q \leq 2 \times 10^5</var></li> <li><var>1 \leq L_i \leq R_i \leq N</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>X_1</var> <var>X_2</var> <var>\cdots</var> <var>X_N</var> <var>Q</var> <var>L_1</var> <var>R_1</var> <var>L_2</var> <var>R_2</var> <var>\vdots</var> <var>L_Q</var> <var>R_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query, print the size of the union of all good sets in a line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 1 2 4 7 8 2 1 5 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 2 </pre> <p>In the first query, you can have at most <var>3</var> points in a good set. There exist two good sets: <var>\{1,4,7\}</var> and <var>\{1,4,8\}</var>. Therefore, the size of the union of all good sets is <var>|\{1,4,7,8\}|=4</var>.</p> <p>In the second query, you can have at most <var>1</var> point in a good set. There exist two good sets: <var>\{1\}</var> and <var>\{2\}</var>. Therefore, the size of the union of all good sets is <var>|\{1,2\}|=2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>15 220492538 4452279 12864090 23146757 31318558 133073771 141315707 263239555 350278176 401243954 418305779 450172439 560311491 625900495 626194585 891960194 5 6 14 1 8 1 13 7 12 4 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 6 11 2 3 </pre></section> </div> </span>
p02810
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Niwango bought a piece of land that can be represented as a half-open interval <var>[0, X)</var>.</p> <p>Niwango will lay out <var>N</var> vinyl sheets on this land. The sheets are numbered <var>1,2, \ldots, N</var>, and they are distinguishable. For Sheet <var>i</var>, he can choose an integer <var>j</var> such that <var>0 \leq j \leq X - L_i</var> and cover <var>[j, j + L_i)</var> with this sheet.</p> <p>Find the number of ways to cover the land with the sheets such that no point in <var>[0, X)</var> remains uncovered, modulo <var>(10^9+7)</var>. We consider two ways to cover the land different if and only if there is an integer <var>i</var> <var>(1 \leq i \leq N)</var> such that the region covered by Sheet <var>i</var> is different.</p> </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 X \leq 500</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>X</var> <var>L_1</var> <var>L_2</var> <var>\ldots</var> <var>L_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>3 3 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <ul> <li>If we ignore whether the whole interval is covered, there are <var>18</var> ways to lay out the sheets.</li> <li>Among them, there are <var>4</var> ways that leave <var>[0, 1)</var> uncovered, and <var>4</var> ways that leave <var>[2, 3)</var> uncovered.</li> <li>Each of the other ways covers the whole interval <var>[0,3)</var>, so the answer is <var>10</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>18 477 324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>134796357 </pre> <ul> <li>Find the number of ways modulo <var>(10^9+7)</var>.</li> </ul></section> </div> </span>
p03702
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are going out for a walk, when you suddenly encounter <var>N</var> monsters. Each monster has a parameter called <em>health</em>, and the health of the <var>i</var>-th monster is <var>h_i</var> at the moment of encounter. A monster will vanish immediately when its health drops to <var>0</var> or below.</p> <p>Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:</p> <ul> <li>Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by <var>A</var>, and the health of each of the other monsters will decrease by <var>B</var>. Here, <var>A</var> and <var>B</var> are predetermined parameters, and <var>A &gt; B</var> holds.</li> </ul> <p>At least how many explosions do you need to cause in order to vanish all the monsters?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 ≀ N ≀ 10^5</var></li> <li><var>1 ≀ B &lt; A ≀ 10^9</var></li> <li><var>1 ≀ h_i ≀ 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>h_1</var> <var>h_2</var> <var>:</var> <var>h_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 3 8 7 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>You can vanish all the monsters in two explosion, as follows:</p> <ul> <li>First, cause an explosion centered at the monster with <var>8</var> health. The healths of the four monsters become <var>3</var>, <var>4</var>, <var>1</var> and <var>-1</var>, respectively, and the last monster vanishes.</li> <li>Second, cause an explosion centered at the monster with <var>4</var> health remaining. The healths of the three remaining monsters become <var>0</var>, <var>-1</var> and <var>-2</var>, respectively, and all the monsters are now vanished.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 10 4 20 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p>You need to cause two explosions centered at each monster, for a total of four.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 2 1 900000000 900000000 1000000000 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>800000000 </pre></section> </div> </span>
p00987
<h2>One-Way Conveyors</h2> <p> You are working at a factory manufacturing many different products. Products have to be processed on a number of different machine tools. Machine shops with these machines are connected with conveyor lines to exchange unfinished products. Each unfinished product is transferred from a machine shop to another through one or more of these conveyors. </p> <p> As the orders of the processes required are not the same for different types of products, the conveyor lines are currently operated in two-way. This may induce inefficiency as conveyors have to be completely emptied before switching their directions. <i>Kaizen</i> (efficiency improvements) may be found here! </p> <p> Adding more conveyors is too costly. If all the required transfers are possible with currently installed conveyors operating in fixed directions, no additional costs are required. All the required transfers, from which machine shop to which, are listed at hand. You want to know whether all the required transfers can be enabled with all the conveyors operated in one-way, and if yes, directions of the conveyor lines enabling it. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $m$ $x_1$ $y_1$ . . . $x_m$ $y_m$ $k$ $a_1$ $b_1$ . . . $a_k$ $b_k$ </pre> <p> The first line contains two integers $n$ ($2 \leq n \leq 10 000$) and $m$ ($1 \leq m \leq 100 000$), the number of machine shops and the number of conveyors, respectively. Machine shops are numbered $1$ through $n$. Each of the following $m$ lines contains two integers $x_i$ and $y_i$ ($1 \leq x_i < y_i \leq n$), meaning that the $i$-th conveyor connects machine shops $x_i$ and $y_i$. At most one conveyor is installed between any two machine shops. It is guaranteed that any two machine shops are connected through one or more conveyors. The next line contains an integer $k$ ($1 \leq k \leq 100 000$), which indicates the number of required transfers from a machine shop to another. Each of the following $k$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i \leq n$, $1 \leq b_i \leq n$, $a_i \ne b_i$), meaning that transfer from the machine shop $a_i$ to the machine shop $b_i$ is required. Either $a_i \ne a_j$ or $b_i \ne b_j$ holds for $i \ne j$. </p> <h3> Output </h3> <p> Output “<pan>No</span>” if it is impossible to enable all the required transfers when all the conveyors are operated in one-way. Otherwise, output “<span>Yes</span>” in a line first, followed by $m$ lines each of which describes the directions of the conveyors. All the required transfers should be possible with the conveyor lines operated in these directions. Each direction should be described as a pair of the machine shop numbers separated by a space, with the start shop number on the left and the end shop number on the right. The order of these $m$ lines do not matter as far as all the conveyors are specified without duplicates or omissions. If there are multiple feasible direction assignments, whichever is fine. </p> <h3>Sample Input 1 </h3> <pre> 3 2 1 2 2 3 3 1 2 1 3 2 3 </pre> <h3>Sample Output 1</h3> <pre> Yes 1 2 2 3 </pre> <h3>Sample Input 2 </h3> <pre> 3 2 1 2 2 3 3 1 2 1 3 3 2 </pre> <h3>Sample Output 2</h3> <pre> No </pre> <h3>Sample Input 3 </h3> <pre> 4 4 1 2 1 3 1 4 2 3 7 1 2 1 3 1 4 2 1 2 3 3 1 3 2 </pre> <h3>Sample Output 3</h3> <pre> Yes 1 2 2 3 3 1 1 4 </pre>
p01695
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <!-- begin en only --> <h3><u>JAG-channel</u></h3> <!-- end en only --> <!-- begin ja only --> <!--<h3><u>JAG-channel</u></h3>--> <!-- end ja only --> <!-- begin en only --> <!-- end en only --> <!-- begin ja only --> <p>ネむサン・O・デむビスはJAG-channelずいう電子掲瀺板を運営しおいる 圌は珟圚スレッドビュヌずいう新機胜の远加に取り組んでいる </p> <p>他の倚くの電子掲瀺板ず同じようにJAG-channelはスレッドベヌスである ここでスレッドずは䞀連の投皿からなる䞀぀の䌚話のたずたりを指す 投皿には以䞋の2皮類が存圚する </p><ul><li>新しいスレッドを䜜る最初の投皿 </li><li>すでにあるスレッドの過去の投皿ぞの返信 </li></ul> <p>スレッドビュヌは投皿間の返信・被返信関係による論理的な構造を衚すツリヌ状のビュヌである それぞれの投皿はツリヌのノヌドずなりその投皿に察する返信を子ノヌドずしお持぀ ある投皿に察する盎接・間接の返信が党䜓ずしお郚分朚ずなるこずに泚意しおほしい </p> <p>䟋を芋おみよう䟋えば "<samp>hoge</samp>"ずいう最初の投皿に察しお "<samp>fuga</samp>"ず"<samp>piyo</samp>"ずいう2぀の返信が付き "<samp>fuga</samp>"に察しおさらに"<samp>foobar</samp>"ず"<samp>jagjag</samp>"ずいう返信が付き "<samp>jagjag</samp>"に察しお"<samp>zigzag</samp>"ずいう返信が付いたずする このスレッドのツリヌは次のようになる </p> <pre>hoge ├─fuga │ ├─foobar │ └─jagjag │   └─zigzag └─piyo</pre> <p>ネむサン・O・デむビスはプログラマヌを雇っお機胜を実装させおいたがこのプログラマヌが最埌の段階で倱螪しおしたった このプログラマヌはスレッドのツリヌを䜜りそれを簡易フォヌマットで衚瀺するずころたで完成させおいる この簡易フォヌマットでは返信の深さが '<samp>.</samp>' (半角ドット) で衚されある投皿に察する返信は元の投皿より1぀倚くの '<samp>.</samp>' が巊に぀くたたある投皿に察する返信は必ず元の投皿よりも䞋に来る返信元の投皿ず返信の間には返信元の投皿に察する他の返信 (およびそれに察する盎接・間接の返信) が珟れるこずがあるがそれ以倖の投皿が䞡者の間に珟れるこずはない 䞊のツリヌの簡易フォヌマット衚瀺は次のようになる </p> <pre>hoge .fuga ..foobar ..jagjag ...zigzag .piyo</pre> <p>あなたの仕事はこの簡易フォヌマット衚瀺を受け取り芋やすく敎圢するこずである すなわち </p> <ul><li>各投皿のすぐ巊の '<samp>.</samp>' (各投皿の巊に぀いた '<samp>.</samp>' のうちもっずも右のもの) を '<samp>+</samp>' (半角プラス) </li><li>同じ投皿に察する盎接の返信に぀いおそれぞれのすぐ巊にある '<samp>+</samp>' の間に䜍眮する '<samp>.</samp>' を '<samp>|</samp>' (半角瞊線) </li><li>それ以倖の '<samp>.</samp>' は '<samp> </samp>' (半角スペヌス) </li></ul> <p>に眮き換えお欲しい </p> <p>䞊の簡易フォヌマット衚瀺に察する敎圢枈みの衚瀺は次のようになる </p> <pre>hoge +fuga |+foobar |+jagjag | +zigzag +piyo</pre> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットから構成される各デヌタセットの圢匏は次の通りである </p><blockquote>$n$<br>$s_1$<br>$s_2$<br>...<br>$s_n$</blockquote> <p>$n$ は簡易フォヌマット衚瀺の行数を衚す敎数であり$1$ 以䞊 $1{,}000$ 以䞋ず仮定しおよい 続く $n$ 行にはスレッドツリヌの簡易フォヌマット衚瀺が蚘茉されおいる $s_i$ は簡易フォヌマット衚瀺の $i$ 行目を衚しいく぀かの '<samp>.</samp>' ずそれに続く $1$ 文字以䞊 $50$ 文字以䞋のアルファベット小文字で構成された文字列からなる $s_1$ はスレッドの最初の投皿であり'<samp>.</samp>' を含たない $s_2$, ..., $s_n$ はそのスレッドでの返信であり必ず1぀以䞊の '<samp>.</samp>' を含む </p> <p>$n=0$ は入力の終わりを瀺すこれはデヌタセットには含めない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに察する敎圢枈みの衚瀺を各 $n$ 行で出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>6 hoge .fuga ..foobar ..jagjag ...zigzag .piyo 8 jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi 8 hello .goodmorning ..howareyou .goodafternoon ..letshavealunch .goodevening .goodnight ..gotobed 3 caution .themessagelengthislessthanorequaltofifty ..sothelengthoftheentirelinecanexceedfiftycharacters 0</pre> <h3>Output for Sample Input</h3> <pre>hoge +fuga |+foobar |+jagjag | +zigzag +piyo jagjag +hogehoge |+fugafuga | +ponyoponyo | |+evaeva | |+pokemon | +nowawa +buhihi hello +goodmorning |+howareyou +goodafternoon |+letshavealunch +goodevening +goodnight +gotobed caution +themessagelengthislessthanorequaltofifty +sothelengthoftheentirelinecanexceedfiftycharacters</pre>
p03352
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a positive integer <var>X</var>. Find the largest <em>perfect power</em> that is at most <var>X</var>. Here, a perfect power is an integer that can be represented as <var>b^p</var>, where <var>b</var> is an integer not less than <var>1</var> and <var>p</var> is an integer not less than <var>2</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>X</var> <var>≀</var> <var>1000</var></li> <li><var>X</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the largest perfect power that is at most <var>X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>There are four perfect powers that are at most <var>10</var>: <var>1</var>, <var>4</var>, <var>8</var> and <var>9</var>. We should print the largest among them, <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 </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>999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>961 </pre></section> </div> </span>
p02390
<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>Watch</H1> <p> Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively. </p> <H2>Input</H2> <p> An integer $S$ is given in a line. </p> <H2>Output</H2> <p> Print $h$, $m$ and $s$ separated by ':'. You do not need to put '0' for a value, which consists of a digit. </p> <h2>Constraints</h2> <ul> <li>$0 \leq S \leq 86400$</li> </ul> <H2>Sample Input 1</H2> <pre> 46979 </pre> <H2>Sample Output 1</H2> <pre> 13:2:59 </pre>
p00657
<H1>Problem K: Rearranging Seats</H1> <p> Haruna is a high school student. She must remember the seating arrangements in her class because she is a class president. It is too difficult task to remember if there are so many students. </p> <p> That is the reason why seating rearrangement is depress task for her. But students have a complaint if seating is fixed. </p> <p> One day, she made a rule that all students must move but they don't move so far as the result of seating rearrangement. </p> <p> The following is the rule. The class room consists of <i>r*c</i> seats. Each <i>r</i> row has <i>c</i> seats. The coordinate of the front row and most left is (1,1). The last row and right most is (<i>r</i>,<i>c</i>). After seating rearrangement, all students must move next to their seat. If a student sit (<i>y</i>,<i>x</i>) before seating arrangement, his/her seat must be (<i>y</i>,<i>x</i>+1) , (<i>y</i>,<i>x</i>-1), (<i>y</i>+1,<i>x</i>) or (<i>y</i>-1,<i>x</i>). The new seat must be inside of the class room. For example (0,1) or (<i>r</i>+1,<i>c</i>) is not allowed. </p> <p> Your task is to check whether it is possible to rearrange seats based on the above rule. </p> <H2>Input</h2> <p> Input consists of multiple datasets. Each dataset consists of 2 integers. The last input contains two 0. A dataset is given by the following format. </p> <pre> <i>r</i> <i>c</i> </pre> <p> Input satisfies the following constraint.<br> 1 &le; <i>r</i> &le; 19, 1 &le; <i>c</i> &le; 19 </p> <h2>Output</h2> <p> Print "yes" without quates in one line if it is possible to rearrange the seats, otherwise print "no" without quates in one line. </p> <h2>Sample Input</h2> <pre> 1 1 2 2 0 0 </pre> <h2>Sample Output</h2> <pre> no yes </pre> <h2>Hint</h2> <p> For the second case, before seat rearrangement, the state is shown as follows. </p> <pre> 1 2 3 4 </pre> <p> There are some possible arrangements. For example </p> <pre> 2 4 1 3 </pre> <p> or </p> <pre> 2 1 4 3 </pre> <p> is valid arrangement. </p>
p03978
<span class="lang-en"> <p>Score : <var>150</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p> There is a long blackboard with <var>2</var> rows and <var>N</var> columns in a classroom of Kyoto University. This blackboard is so long that it is impossible to tell which cells are already used and which unused. </p> <p> Recently, a blackboard retrieval device was installed at the classroom. To use this device, you type a search query that forms a rectangle with 2 rows and any length of columns, where each cell is used or unused. When you input a query, the decive answers whether the rectangle that corresponds to the query exists in the blackboard. Here, for a rectangle that corresponds to a search query, if two integer <var>i, j</var> ( <var>i &lt; j</var> ) exist and the rectangle equals to the partial blackboard between column <var>i</var> and <var>j</var> , the rectangle is called a sub-blackboard of the blackboard. </p> <p> You are currently preparing for a presentation at this classroom. To make the presentation go well, you decided to write a program to detect the status of the whole blackboard using the retrieval device. Since it takes time to use the device, you want to use it as few times as possible. </p> <p> The status of the whole blackboard is already determined at the beginning and does not change while you are using the device. </p> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>The first input is given in the following format:</p> <pre> <var>N</var> </pre> <p> <var>N</var> <var>(1 \leq N \leq 100)</var> is an integer that represents the length of the blackboard. </p> <p> After this input value, your program must print search queries. A search query has the following format. </p> <pre> <var>s_1</var> <var>s_2</var> </pre> <p> Here, <var>s_1</var> represents the upper part of the blackboard and <var>s_2</var> represents the lower. <code>#</code> in <var>s_1</var> and <var>s_2</var> represents the cell is already used and <code>.</code> represents the cell is still unused. The lengths of <var>s_1</var> and <var>s_2</var> are arbitrary, but they must be the same. Make sure to insert a line break at the end of the lines. </p> <p> Every time your program prints a search query, a string that represents the search result of the device is returned in the followin format. </p> <pre> <var>r</var> </pre> <p> <var>r</var> is either <code>T</code> or <code>F</code> . The meaning of each character is as follows. </p> <ul> <li> <code>T</code> represents that the sub-blackboard that corresponds to the search query exists in the blackboard. </li> <li> <code>F</code> represents that the sub-blackboard that corresponds to the search query does not exist in the blackboard. </li> </ul> <p> If the search query equals to the whole blackboard or the number of the search queries exceeds the limit, string <code>end</code> is given instead of <var>r</var> . Once you receive this string, exit your program immediately. If your program prints the whole blackboard as a search query before exceedin the limit, it is judged as <em>Accepted</em>. Note that the search query that represents the whole blackboard is also counted as the number of search queries. </p> </section> </div> </div> <p> Note that the output needs to be flushed every time the output is printed. For example, In C/C++, search query <code>s1</code>, <code>s2</code> can be printed as follows. </p> <pre class="prettyprint">printf("%s\n%s\n", s1, s2); fflush(stdout);</pre> <p> Make sure your program receive all the input from the device. Otherwise, the result may be <em>Time Limit Exceeded</em> . </p> <hr/> <div class="part"> <section> <h3>Query Limit</h3> <p> The maximun number of search queries is <var>420</var>. If the number of queries exceeds the limit, the result will be <em>Query Limit Exceeded</em> . </p> <hr/> </section> </div> <div class="part"> <section> <h3>Sample Input and Output</h3> <p>The following is an example where <var>N=3</var> and the blackboard is as follows. </p> <pre> .#. ... </pre> <p>Note that your program does not know the state of the blackboard. </p> <pre> <table class="table table-striped table-bordered table-condensed"> <tr> <th>Output of your program</th> <th>Input to your program</th> <th>Explanation</th> </tr> <tr> <td></td> <td>3</td> <td>The length of the blackboard is given</td> </tr> <tr> <td>..<br/>##</td> <td></td> <td>Output a search query</td> </tr> <tr> <td></td> <td>F</td> <td>The sub-blackboard does not exist</td> </tr> <tr> <td>.<br/>.</td> <td></td> <td>Output a search query</td> </tr> <tr> <td></td> <td>T</td> <td>The sub-blackboard exists</td> </tr> <tr> <td>..<br/>..</td> <td></td> <td>Output a search query</td> </tr> <tr> <td></td> <td>F</td> <td>The sub-blackboard does not exist</td> </tr> <tr> <td>.#<br/>..</td> <td></td> <td>Output a search query</td> </tr> <tr> <td></td> <td>T</td> <td>The sub-blackboard exists</td> </tr> <tr> <td>.#.<br/>...</td> <td></td> <td>Output a search query</td> </tr> <tr> <td></td> <td>end</td> <td>Exit your program because the above sub-blackboard equals to the whole blackboard. </td> </tr> </table> </pre> </section> </div> </span>
p01945
<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> Star in Parentheses </H1> <p> You are given a string $S$, which is balanced parentheses with a star symbol '<span>*</span>' inserted. </p> <p> Any balanced parentheses can be constructed using the following rules: </p> <ul> <li>An empty string is balanced.</li> <li>Concatenation of two balanced parentheses is balanced.</li> <li>If $T$ is balanced parentheses, concatenation of '<span>(</span>', $T$, and '<span>)</span>' in this order is balanced.</li> </ul> <p> For example, '<span>()()</span>' and '<span>(()())</span>' are balanced parentheses. '<span>)(</span>' and '<span>)()(()</span>' are not balanced parentheses. </p> <p> Your task is to count how many matching pairs of parentheses surround the star. </p> <p> Let $S_i$be the $i$-th character of a string $S$. The pair of $S_l$ and $S_r$ ($l < r$) is called a matching pair of parentheses if $S_l$ is '<span>(</span>', $S_r$ is '<span>)</span>' and the surrounded string by them is balanced when ignoring a star symbol. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $S$ </pre> <p> $S$ is balanced parentheses with exactly one '<span>*</span>' inserted somewhere. The length of $S$ is between 1 and 100, inclusive. </p> <H2>Output</H2> <p> Print the answer in one line. </p> <H2>Sample Input 1</H2> <pre> ((*)()) </pre> <H2>Output for Sample Input 1</H2> <pre> 2 </pre> <H2>Sample Input 2</H2> <pre> (*) </pre> <H2>Output for Sample Input 2</H2> <pre> 1 </pre> <H2>Sample Input 3</H2> <pre> (()())* </pre> <H2>Output for Sample Input 3</H2> <pre> 0 </pre> <H2>Sample Input 4</H2> <pre> ()*() </pre> <H2>Output for Sample Input 4</H2> <pre> 0 </pre> <H2>Sample Input 5</H2> <pre> ((((((((((*)))))))))) </pre> <H2>Output for Sample Input 5</H2> <pre> 10 </pre> <H2>Sample Input 6</H2> <pre> * </pre> <H2>Output for Sample Input 6</H2> <pre> 0 </pre>
p00207
<H1>ブロック</H1> <p> A さんの家に芪戚の B 君がやっおきたした。圌は 3 歳でブロックが倧奜きです。圌が持っおいるブロックは図 1 のような圢をしおいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_blockMaze1"> <p> 図1 </p> </center> <p> B 君はボヌドの䞊にブロックを敷き詰めおいたす。圌に「䜕を䜜っおいるの?」ず聞くず、圌は「迷路!!」ず元気よく答えたした。圌の蚀う迷路ずは、スタヌトからゎヌルたで偎面が接しおいる、同じ色のブロックだけでたどるこずができるブロックの配眮のこずだそうです。図 2 は黄色のブロックにより、巊䞊(スタヌト)から右䞋(ゎヌル)ぞ迷路ができおいるこずを衚しおいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_blockMaze2"> <p> 図2 </p> </center> <p> 無邪気に遊んでいる B 君を暪目に、プログラマヌであるあなたは、ブロックの䞊びが迷路ずなっおいるかを確かめおみるこずにしたした。 </p> <p> ブロックの情報ずスタヌト、ゎヌルの座暙を入力ずし、ブロックが迷路ずなっおいれば OK 、なっおいなければ NG を出力するプログラムを䜜成しおください。 ボヌドは暪方向に <var>w</var> 、瞊方向に <var>h</var> の倧きさをもち、 巊䞊の座暙は(1 , 1)、右䞋の座暙は(<var>w, h</var>)ずしたす。ブロックは <var>2 &times; 4</var> の長方圢ですべお同じ倧きさです。ブロックの色 <var>c</var> は 1 (癜)、2 (黄)、3 (緑)、4 (青)、5 (èµ€) のいずれかです。ブロックのボヌド䞊での向き <var>d</var> は 暪方向に長い堎合 0 、 瞊方向に長い堎合 1 ずしたす。 ブロックの䜍眮はブロックの巊䞊の座暙 (<var>x, y</var>) によっお衚されたす。なお、ブロックの䜍眮は他のブロックず重なるこずは無く、ボヌドからはみ出すこずもありたせん。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。 入力の終わりはれロふた぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>w</var> <var>h</var> <var>xs</var> <var>ys</var> <var>xg</var> <var>yg</var> <var>n</var> <var>c<sub>1</sub></var> <var>d<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>c<sub>2</sub></var> <var>d<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>c<sub>n</sub></var> <var>d<sub>n</sub></var> <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <p> 1 行目にボヌドの倧きさ<var>w, h</var> (4 &le; <var>w, h</var> &le; 100) が䞎えられたす。2 行目にスタヌトの座暙 <var>xs, ys</var>、3 行目にゎヌルの座暙 <var>xg, yg</var> が䞎えられたす。 </p> <p> 4 行目にブロックの個数 <var>n</var> が䞎えられたす。続く <var>n</var> 行に <var>i</var> 番目のブロックの色 <var>c<sub>i</sub></var>、向き <var>d<sub>i</sub></var>、䜍眮 <var>x<sub>i</sub>, y<sub>i</sub></var> が䞎えられたす。 </p> <p> デヌタセットの数は 30 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、刀別結果を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 20 20 1 1 9 9 7 2 0 1 1 5 1 1 3 2 1 3 3 1 1 5 2 5 1 7 3 2 0 2 7 2 0 6 8 20 20 9 9 1 1 6 2 0 1 1 1 0 5 1 2 1 1 3 5 0 1 7 3 1 5 5 4 1 8 5 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> OK NG </pre>
p03581
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>A + B</var> balls are arranged in a row. The leftmost <var>A</var> balls are colored red, and the rightmost <var>B</var> balls are colored blue.</p> <p>You perform the following operation:</p> <ul> <li>First, you choose two integers <var>s, t</var> such that <var>1 \leq s, t \leq A + B</var>.</li> <li>Then, you repeat the following step <var>A + B</var> times: In each step, you remove the first ball or the <var>s</var>-th ball (if it exists) or the <var>t</var>-th ball (if it exists, all indices are 1-based) from left in the row, and give it to Snuke.</li> </ul> <p>In how many ways can you give the balls to Snuke? Compute the answer modulo <var>10^9 + 7</var>.</p> <p>Here, we consider two ways to be different if for some <var>k</var>, the <var>k</var>-th ball given to Snuke has different colors. In particular, the choice of <var>s, t</var> doesn't matter. Also, we don't distinguish two balls of the same color.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A, B \leq 2000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>20 </pre> <p>There are <var>20</var> ways to give <var>3</var> red balls and <var>3</var> blue balls. It turns out that all of them are possible.</p> <p>Here is an example of the operation (<code>r</code> stands for red, <code>b</code> stands for blue):</p> <ul> <li>You choose <var>s = 3, t = 4</var>.</li> <li>Initially, the row looks like <code>rrrbbb</code>.</li> <li>You remove <var>3</var>rd ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>rrbbb</code>.</li> <li>You remove <var>4</var>th ball (<code>b</code>) and give it to Snuke. Now the row looks like <code>rrbb</code>.</li> <li>You remove <var>1</var>st ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>rbb</code>.</li> <li>You remove <var>3</var>rd ball (<code>b</code>) and give it to Snuke. Now the row looks like <code>rb</code>.</li> <li>You remove <var>1</var>st ball (<code>r</code>) and give it to Snuke. Now the row looks like <code>b</code>.</li> <li>You remove <var>1</var>st ball (<code>b</code>) and give it to Snuke. Now the row is empty.</li> </ul> <p>This way, Snuke receives balls in the order <code>rbrbrb</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>67 </pre> <p>There are <var>70</var> ways to give <var>4</var> red balls and <var>4</var> blue balls. Among them, only <code>bbrrbrbr</code>, <code>brbrbrbr</code>, and <code>brrbbrbr</code> are impossible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7772 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1987 1789 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>456315553 </pre></section> </div> </span>
p01046
<h1>Problem J: Yu-kun Likes a lot of Money</h1> <h2>Background</h2> <p> 䌚接倧孊付属幌皚園はプログラミングが倧奜きな子䟛が集たる幌皚園である。園児の䞀人であるゆう君は、プログラミングず同じくらいお金が倧奜きだ。ゆう君は、今日もお金を皌ぐために財宝の眠る島を蚪れた。ゆう君は事前に財宝のありかの描かれた地図を手に入れおいる。その地図をもずに出来るだけ倚くのお金を皌ぎたい。ゆう君は最倧でどのくらいお金を手に入れるこずができるだろうか </p> <h2>Problem</h2> <p> 地図、ゆう君の初期䜍眮、財宝の皮類ずそれらから埗られるお金、そしお小さい岩を砎壊するために必芁な費甚の情報が䞎えられる。地図の情報は <var>h</var>マス &times; <var>w</var>マスのフィヌルドずしお䞎えられる。地図の各マスに曞かれおいる文字ずその意味は次の通りである。 </p> <ul> <li>'@' : ゆう君が最初にいる䜍眮を衚す。ゆう君が移動した埌は道ず同じように扱う。</li> <li>'.' : 道を衚す。このマスは自由に通るこずができ費甚もかからない。</li> <li>'#' : 倧きな岩を衚す。このマスは通るこずができない。</li> <li>'*' : 小さな岩を衚す。䞀定の金額を支払うこずで壊すこずができる。壊した埌は道になる。</li> <li>'0','1',...,'9','a','b',...,'z','A','B',...,'Z' : 財宝があるマスを衚す。このマスを蚪れるこずでそこに曞かれおいる文字に察応する財宝の金額分のお金を埗る。ただしお金を埗るこずが出来るのは最初に蚪れた時のみである。</li> </ul> <p> ゆう君は回の移動で隣接する䞊䞋巊右のいずれかのマスに移動するこずができる。 ただし、地図の倖ぞ出るような移動はできない。 </p> <p> 埌払いをするこずができるため、小さな岩を壊す際にそれに必芁な金額をその時に所持しおいる必芁はない。そのため、ゆう君は最終的に小さな岩を壊す際にかかった金額の総和以䞊のお金を埗おいる必芁がある。 </p> <p> ゆう君が埗られる最倧の金額を出力せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>h</var> <var>w</var> <var>n</var> <var>r</var> <var>c<sub>1,1</sub></var> <var>c<sub>1,2</sub></var> 
 <var>c<sub>1,w</sub></var> <var>c<sub>2,1</sub></var> <var>c<sub>2,2</sub></var> 
 <var>c<sub>2,w</sub></var> 
 <var>c<sub>h,1</sub></var> <var>c<sub>h,2</sub></var> 
 <var>c<sub>h,w</sub></var> <var>m<sub>1</sub></var> <var>v<sub>1</sub></var> <var>m<sub>2</sub></var> <var>v<sub>2</sub></var> 
 <var>m<sub>n</sub></var> <var>v<sub>n</sub></var> </pre> <p> 行目に地図の瞊の長さ<var>h</var>,暪の長さ<var>w</var>,地図に含たれる財宝の数<var>n</var>,小さな岩を砎壊するためにかかる費甚<var>r</var>が空癜区切りで䞎えられる。 </p> <p> 続く<var>h</var>行に地図を衚す各マスの情報<var>c<sub>i,j</sub></var>が<var>w</var>個䞎えられる。 ( 1 &le; <var>i</var> &le; <var>h</var>, 1 &le; <var>j</var> &le; <var>w</var> ) </p> <p> 続く<var>n</var>行に財宝の皮類<var>m<sub>k</sub></var> ずその財宝の金額<var>v<sub>k</sub></var>が空癜区切りで䞎えられる。 ( 1 &le; <var>k</var> &le; <var>n</var> ) </p> <h2>Constraints</h2> <p> 入力は以䞋の制玄を満たす。 </p> <ul> <li>1 &le; <var>h</var>,<var>w</var> &le; 8</li> <li>0 &le; <var>n</var> &le; min(<var>h</var>&times;<var>w</var> -1,62) ただし、min(<var>a</var>,<var>b</var>)は<var>a</var>,<var>b</var>の最小倀を衚す</li> <li> 1 &le; <var>v<sub>i</sub></var> &le; 10<sup>5</sup> ( 1 &le; <var>i</var> &le; <var>n</var> )</li> <li>1 &le; <var>r</var> &le; 10<sup>5</sup></li> <li><var>c<sub>j,k</sub></var>, <var>m<sub>l</sub></var> を陀く党おの入力は敎数ずしお䞎えられる ( 1 &le; <var>j</var> &le; <var>h</var>, 1 &le; <var>k</var> &le; <var>w</var>, 1 &le; <var>l</var> &le; <var>n</var> )</li> <li>地図にはちょうどひず぀'@'が曞かれおいる</li> <li>地図にはちょうど<var>n</var>個の財宝が曞かれおいる</li> <li>地図に曞かれおいる財宝の皮類は入力で䞎えられた<var>m<sub>l</sub></var>のいずれかである</li> <li>地図に同じ皮類の財宝が぀以䞊珟れるこずはない</li> </ul> <h2>Output</h2> <p> ゆう君が埗られる最倧のお金の金額を1行に出力せよ。 </p> <h2>Sample Input1</h2> <pre> 3 3 1 10 @0. ... ... 0 100 </pre> <h2>Sample Output1</h2> <pre> 100 </pre> <h2>Sample Input2</h2> <pre> 3 3 1 10 @#b .#. .#. b 100 </pre> <h2>Sample Output2</h2> <pre> 0 </pre> <h2>Sample Input3</h2> <pre> 3 3 1 20 @*C ..* ... C 10 </pre> <h2>Sample Output3</h2> <pre> 0 </pre>
p01416
<H1>J: Tiles are Colorful</H1> <p> ICPC で良い成瞟を収めるには修行が欠かせないうさぎは ICPC で勝ちたいので今日も修行をするこずにした </p> <p> 今日の修行は流行りのパズルをすばやく解いお瞬発力を鍛えようずいうものである今日挑戊するのは色ずりどりのタむルが䞊んでいおそれらを䞊手く消しおいくパズルだ </p> <p> 初期状態ではグリッド䞊のいく぀かのマスにタむルが眮かれおいる各タむルには色が぀いおいるプレむダヌはゲヌム開始埌以䞋の手順で瀺される操䜜を䜕回も行うこずができる </p> <ol> <li>タむルが眮かれおいないマスを 1 ぀遞択しそのマスを叩く</li> <li>叩いたマスから䞊に順に蟿っおいきタむルが眮かれおいるマスに至ったずころでそのタむルに着目するタむルが眮かれおいるマスがないたた盀面の端に蟿り着いたら䜕にも着目しない</li> <li>同様の操䜜を叩いたマスから䞋・巊・右方向に察しお行う最倧 4 枚のタむルが着目されるこずになる</li> <li>着目したタむルの䞭で同じ色のものがあればそれらのタむルを盀面から取り陀く同じ色のタむルの組が 2 組あればそれら䞡方を取り陀く</li> <li>タむルを取り陀いた枚数ず同じ倀の埗点が入る</li> <li>着目をやめる</li> </ol> <p> たずえば以䞋のような状況を考えようタむルが眮かれおいないマスはピリオドでタむルの色はアルファベット倧文字で衚されおいる </p> <center><pre> ..A....... .......B.. .......... ..B....... ..A.CC.... </pre></center> <p> ここで䞊から 2 行目巊から 3 列目のマスを叩く操䜜を考える着目するこずになるタむルは <tt>A</tt> , <tt>B</tt> , <tt>B</tt> の 3 枚であるから<tt>B</tt> の 2 枚が消えお盀面は以䞋のようになり2 点を埗る </p> <center><pre> ..A....... .......... .......... .......... ..A.CC.... </pre></center> <p> このパズルはゆっくりしおいるず時間切れになっおしたい盀面の䞀郚が芋えなくなりどのくらい修行が足りなかったのかがわからなくなっおしたう 各色のタむルは 2 枚ず぀眮かれおいるがそれらをすべお消せるずは限らないので予めプログラムに埗点の最倧倀を蚈算させおおきたい </p> <H2>Input</H2> <pre> <i>M</i> <i>N</i> <i>C</i><sub>1,1</sub><i>C</i><sub>1,2</sub>...<i>C</i><sub>1,<i>N</i></sub> <i>C</i><sub>2,1</sub><i>C</i><sub>2,2</sub>...<i>C</i><sub>2,<i>N</i></sub> ... <i>C</i><sub><i>M</i>,1</sub><i>C</i><sub><i>M</i>,2</sub>...<i>C</i><sub><i>M</i>,<i>N</i></sub> </pre> <p> 敎数 <i>M</i>, <i>N</i> は盀が 瞊 <i>M</i> &times; 暪 <i>N</i> のマス目であるこずを衚す<i>C</i><sub><i>i</i>, <i>j</i></sub> はアルファベット倧文字たたはピリオド ( <tt>.</tt> ) であり䞊から <i>i</i> 行目巊から <i>j</i> 列目のマスに぀いおアルファベット倧文字の堎合は眮かれおいるタむルの色を衚しピリオドの堎合はこのマスにタむルが眮かれおいないこずを衚す </p> <p> 1 &le; <i>M</i> &le; 5001 &le; <i>N</i> &le; 500 を満たす各アルファベット倧文字は入力䞭に 0 個たたは 2 個珟れる </p> <H2>Output</H2> <p> 埗点の最倧倀を 1 行に出力せよ </p> <H2>Sample Input 1</H2> <pre> 5 10 ..A....... .......B.. .......... ..B....... ..A.CC.... </pre> <H2>Sample Output 1</H2> <pre> 4 </pre> <H2>Sample Input 2</H2> <pre> 3 3 ABC D.D CBA </pre> <H2>Sample Output 2</H2> <pre> 4 </pre> <H2>Sample Input 3</H2> <pre> 5 7 NUTUBOR QT.SZRQ SANAGIP LMDGZBM KLKIODP </pre> <H2>Sample Output 3</H2> <pre> 34 </pre>
p01103
<h3><u>A Garden with Ponds</u></h3> <p> Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. </p> <p> According to his unique design procedure, all of his ponds are rectangular with simple aspect ratios. First, Mr. Gardiner draws a regular grid on the map of the garden site so that the land is divided into cells of unit square, and annotates every cell with its elevation. In his design method, a pond occupies a rectangular area consisting of a number of cells. Each of its outermost cells has to be higher than all of its inner cells. For instance, in the following grid map, in which numbers are elevations of cells, a pond can occupy the shaded area, where the outermost cells are shaded darker and the inner cells are shaded lighter. You can easily see that the elevations of the outermost cells are at least three and those of the inner ones are at most two. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_C1" width="300pt"> </center> <p> A rectangular area on which a pond is built must have at least one inner cell. Therefore, both its width and depth are at least three. </p> <p> When you pour water at an inner cell of a pond, the water can be kept in the pond until its level reaches that of the lowest outermost cells. If you continue pouring, the water inevitably spills over. Mr. Gardiner considers the larger <i>capacity</i> the pond has, the better it is. Here, the capacity of a pond is the maximum amount of water it can keep. For instance, when a pond is built on the shaded area in the above map, its capacity is (3 &#8722; 1) + (3 &#8722; 0) + (3 &#8722; 2) = 6, where 3 is the lowest elevation of the outermost cells and 1, 0, 2 are the elevations of the inner cells. Your mission is to write a computer program that, given a grid map describing the elevation of each unit square cell, calculates the largest possible capacity of a pond built in the site. </p> <p> Note that neither of the following rectangular areas can be a pond. In the left one, the cell at the bottom right corner is not higher than the inner cell. In the right one, the central cell is as high as the outermost cells. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_C2" width="500pt"> </center> <h3>Input</h3> <p> The input consists of at most 100 datasets, each in the following format. </p> <pre> <i>d w</i> <i>e</i><sub>1, 1</sub> ... <i>e</i><sub>1, <i>w</i></sub> ... <i>e</i><sub><i>d</i>, 1</sub> ... <i>e<sub>d, w</sub></i> </pre> <p> The first line contains <i>d</i> and <i>w</i>, representing the depth and the width, respectively, of the garden site described in the map. They are positive integers between 3 and 10, inclusive. Each of the following <i>d</i> lines contains <i>w</i> integers between 0 and 9, inclusive, separated by a space. The <i>x</i>-th integer in the <i>y</i>-th line of the <i>d</i> lines is the elevation of the unit square cell with coordinates (<i>x, y</i>). </p> <p> The end of the input is indicated by a line containing two zeros separated by a space. </p> <h3>Output</h3> <p> For each dataset, output a single line containing the largest possible capacity of a pond that can be built in the garden site described in the dataset. If no ponds can be built, output a single line containing a zero. </p> <h3>Sample Input</h3> <pre>3 3 2 3 2 2 1 2 2 3 1 3 5 3 3 4 3 3 3 1 0 2 3 3 3 4 3 2 7 7 1 1 1 1 1 0 0 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 1 1 1 1 6 6 1 1 1 1 2 2 1 0 0 2 0 2 1 0 0 2 0 2 3 3 3 9 9 9 3 0 0 9 0 9 3 3 3 9 9 9 0 0 </pre> <h3>Output for the Sample Input</h3> <pre>0 3 1 9 </pre>
p01553
<h1>問題名 箱根駅䌝</h1> <p>日本のお正月の颚物詩に箱根駅䌝がありたす。箱根駅䌝は、各チヌム 10 人の走者が䞭継所ごずに襷を぀なぎながらゎヌルを目指すずいうものです。テレビの攟送では䞭継所で各チヌムの通過順䜍ず共に前の䞭継所からの順䜍倉動が衚瀺されたす。そこで、それを芋お前の䞭継所の各チヌムの通過順ずしお考えられるものが䜕通りあるか答えおください。ありえた通過順の数は非垞に倧きくなりうるので、1,000,000,007 で割った䜙りで答えお䞋さい。 </p> <h2>Input</h2> <p>入力は以䞋の圢で䞎えられたす </p><blockquote> <var>n</var><br><var>c<sub>1</sub></var><br><var>c<sub>2</sub></var><br>...<br><var>c<sub>n</sub></var><br></blockquote> <p>1行目にはチヌム数を衚す数字 <var>n</var> (<var>1 &le; n &le; 200</var>) が、続く <var>n</var> 行には 1 䜍から順に前の䞭継所からの順䜍倉動 <var>c<sub>i</sub></var> ('<code>D</code>' なら順䜍が萜ちおる、'<code>U</code>' なら順䜍が䞊がっおる、'<code>-</code>' なら順䜍が倉わっおない) が曞いおありたす。 </p> <h2>Output</h2> <p>前の䞭継所でありえた通過順が䜕通りかを、 1,000,000,007 で割ったあたりで 1 行で出力しお䞋さい。 </p> <h2>Sample Input 1</h2> <pre>3 - U D </pre> <h2>Output for the Sample Input 1</h2> <pre>1 </pre> <p>この䞭継所を 1 䜍、 2 䜍、 3 䜍で通過したチヌムのチヌム名をそれぞれ A, B, C ずするず、前の䞭継所の通過順ずしお考えられるのは 1 䜍チヌム A, 2 䜍チヌム C, 3 䜍チヌム B の 1 通りのみです。 </p> <h2>Sample Input 2</h2> <pre>5 U U - D D </pre> <h2>Output for the Sample Input 2</h2> <pre>5 </pre> <p>この䞭継所の通過順にチヌム名を A, B, C, D, E ずするず、前の䞭継所の通過順ずしお考えられるのは {D, E, C, A, B}, {D, E, C, B, A}, {E, D, C, A, B}, {E, D, C, B, A}, {D, A, C, E, B} の5通りです。 </p> <h2>Sample Input 3</h2> <pre>8 U D D D D D D D </pre> <h2>Output for the Sample Input 3</h2> <pre>1 </pre> <h2>Sample Input 4</h2> <pre>10 U D U D U D U D U D </pre> <h2>Output for the Sample Input 4</h2> <pre>608 </pre> <h2>Sample Input 5</h2> <pre>2 D U </pre> <h2>Output for the Sample Input 5</h2> <pre>0 </pre>
p03094
<span class="lang-en"> <p>Score : <var>1800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a round pizza. Snuke wants to eat one third of it, or something as close as possible to that.</p> <p>He decides to cut this pizza as follows.</p> <p>First, he divides the pizza into <var>N</var> pieces by making <var>N</var> cuts with a knife. The knife can make a cut along the segment connecting the center of the pizza and some point on the circumference of the pizza. However, he is very poor at handling knives, so the cuts are made at uniformly random angles, independent from each other.</p> <p>Then, he chooses one or more <strong>consecutive</strong> pieces so that the total is as close as possible to one third of the pizza, and eat them. (Let the total be x of the pizza. He chooses consecutive pieces so that <var>|x - 1/3|</var> is minimized.)</p> <p>Find the expected value of <var>|x - 1/3|</var>. It can be shown that this value is rational, and we ask you to print it modulo <var>10^9 + 7</var>, as described in Notes.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>When you print a rational number, first write it as a fraction <var>\frac{y}{x}</var>, where <var>x, y</var> are integers and <var>x</var> is not divisible by <var>10^9 + 7</var> (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer <var>z</var> between <var>0</var> and <var>10^9 + 6</var>, inclusive, that satisfies <var>xz \equiv y \pmod{10^9 + 7}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq 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> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the expected value of <var>|x - 1/3|</var> modulo <var>10^9 + 7</var>, as described in Notes.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>138888890 </pre> <p>The expected value is <var>\frac{5}{36}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>179012347 </pre> <p>The expected value is <var>\frac{11}{162}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>954859137 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>44679646 </pre></section> </div> </span>
p00712
<h1> <font color="#000">Problem C:</font> Unit Fraction Partition </h1> <p> A fraction whose numerator is 1 and whose denominator is a positive integer is called a unit fraction. A representation of a positive rational number <I>p</I>/<I>q</I> as the sum of finitely many unit fractions is called a <I>partition</I> of <I>p</I>/<I>q</I> into unit fractions. For example, 1/2 + 1/6 is a partition of 2/3 into unit fractions. The difference in the order of addition is disregarded. For example, we do not distinguish 1/6 + 1/2 from 1/2 + 1/6. </p> <p> For given four positive integers <I>p</I>, <I>q</I>, <I>a</I>, and <I>n</I>, count the number of partitions of <I>p</I>/<I>q</I> into unit fractions satisfying the following two conditions. </p> <UL> <LI> The partition is the sum of at most <I>n</I> many unit fractions. </LI> <LI> The product of the denominators of the unit fractions in the partition is less than or equal to <I>a</I>. </LI> </UL> <p> For example, if (<I>p</I>,<I>q</I>,<I>a</I>,<I>n</I>) = (2,3,120,3), you should report 4 since </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_c009" WIDTH="104" HEIGHT="156" ALIGN="MIDDLE" BORDER="0" ALT="2/3 = 1/3 + 1/3 = 1/2 + 1/6 = 1/4 + 1/4 + 1/6 = 1/3 + 1/6 + 1/6"> </center> <p> enumerates all of the valid partitions. </p> <h2>Input</h2> <p> The input is a sequence of at most 1000 data sets followed by a terminator. </p> <p> A data set is a line containing four positive integers <I>p</I>, <I>q</I>, <I>a</I>, and <I>n</I> satisfying <I>p</I>,<I>q</I> &lt;= 800, <I>a</I> &lt;= 12000 and <I>n</I> &lt;= 7. The integers are separated by a space. </p> <p> The terminator is composed of just one line which contains four zeros separated by a space. It is not a part of the input data but a mark for the end of the input. </p> <h2>Output</h2> <p> The output should be composed of lines each of which contains a single integer. No other characters should appear in the output. </p> <p> The output integer corresponding to a data set <I>p</I>, <I>q</I>, <I>a</I>, <I>n</I> should be the number of all partitions of <I>p</I>/<I>q</I> into at most <I>n</I> many unit fractions such that the product of the denominators of the unit fractions is less than or equal to <I>a</I>. </p> <h2>Sample Input</h2> <pre> 2 3 120 3 2 3 300 3 2 3 299 3 2 3 12 3 2 3 12000 7 54 795 12000 7 2 3 300 1 2 1 200 5 2 4 54 2 0 0 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 4 7 6 2 42 1 0 9 3 </pre>
p01800
<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 K Runner and Sniper</h2> <p> You are escaping from an enemy for some reason. The enemy is a sniper equipped with a high-tech laser gun, and you will be immediately defeated if you get shot. You are a very good runner, but just wondering how fast you have to run in order not to be shot by the sniper. The situation is as follows: </p> <p> You and the sniper are on the $xy$-plane whose $x$-axis and $y$-axis are directed to the right and the top, respectively. You can assume that the plane is infinitely large, and that there is no obstacle that blocks the laser or your movement. </p> <p> The sniper and the laser gun are at $(0, 0)$ and cannot move from the initial location. The sniper can continuously rotate the laser gun by at most $\omega$ degrees per unit time, either clockwise or counterclockwise, and can change the direction of rotation at any time. The laser gun is initially directed $\theta$ degrees counterclockwise from the positive direction of the $x$-axis. </p> <p> You are initially at ($x$, $y$) on the plane and can move in any direction at speed not more than $v$ (you can arbitrarily determine the value of $v$ since you are a very good runner). You will be shot by the sniper exactly when the laser gun is directed toward your position, that is, you can ignore the time that the laser reaches you from the laser gun. Assume that your body is a point and the laser is a half-line whose end point is (0, 0). </p> <p> Find the maximum speed $v$ at which you are shot by the sniper in finite time when you and the sniper behave optimally. </p> <h3>Input</h3> <p> The input consists of a single test case. The input contains four integers in a line, $x$, $y$, $\theta$ and $\omega$. The two integers $x$ and $y$ $(0 \leq |x|, |y| \leq 1,000$, ($x$, $y$) $\ne$ (0, 0)) represent your initial position on the $xy$-plane. The integer $\theta$ $(0 \leq \theta < 360)$ represents the initial direction of the laser gun: it is the counterclockwise angle in degrees from the positive direction of the $x$-axis. The integer $\omega$ $(1 \leq \omega \leq 100)$ is the angle which the laser gun can rotate in unit time. You can assume that you are not shot by the sniper at the initial position. </p> <h3>Output</h3> <p> Display a line containing the maximum speed $v$ at which you are shot by the sniper in finite time. The absolute error or the relative error should be less than $10^{-6}$. </p> <h3>Sample Input 1</h3> <pre>100 100 0 1</pre> <h3>Output for the Sample Input 1</h3> <pre>1.16699564</pre>
p00342
<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> <var>N</var> 個の異なる自然数が䞎えられる。その䞭から異なる぀を遞んで、それらを $A$, $B$, $C$, $D$ ずしたずき、次の数匏 </p> <center> $\frac{A + B}{C - D}$ <br/> </center> <br/> <p> の最倧倀を求めたい。 </p> <br/> <p> <var>N</var> 個の異なる自然数が䞎えられたずき、その䞭から異なる぀を遞んで、䞊の数匏の最倧倀を求めるプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var> </pre> <p> 行目に自然数の個数 <var>N</var> (4 &le; <var>N</var> &le; 1000) が䞎えられる。行目に各自然数の倀 <var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; 10<sup>8</sup>) が䞎えられる。ただし、同じ自然数が重耇しお珟れるこずはない<var>i</var> &ne; <var>j</var> に぀いお <var>a<sub>i</sub></var> &ne; <var>a<sub>j</sub></var>)。 </p> <h2>Output</h2> <p> 䞎えられた <var>N</var> 個の自然数に察しお、䞊の数匏の最倧倀を実数で出力する。ただし、誀差がプラスマむナス 10<sup>-5</sup> を超えおはならない。 </p> <h2>Sample Input 1</h2> <pre> 10 1 2 3 4 5 6 7 8 9 10 </pre> <h2>Sample Output 1</h2> <pre> 19.00000 </pre> <p> 入力䟋では、$A=9$, $B=10$, $C=2$, $D=1$ などの組み合わせで最倧になる。 </p> <br/> <h2>Sample Input 2</h2> <pre> 5 22 100 42 3 86 </pre> <h2>Sample Output 2</h2> <pre> 9.78947 </pre> <p> 入力䟋では、$A=100$, $B=86$, $C=22$, $D=3$ などの組み合わせで最倧になる。 </p> <br/> <h2>Sample Input 3</h2> <pre> 6 15 21 36 10 34 5 </pre> <h2>Sample Output 3</h2> <pre> 18.00000 </pre> <p> 入力䟋では、$A=21$, $B=15$, $C=36$, $D=34$ などの組み合わせで最倧になる。 </p> <br/> <h2>Sample Input 4</h2> <pre> 4 100000 99999 8 1 </pre> <h2>Sample Output 4</h2> <pre> 28571.285714 </pre> <br/>
p02685
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> blocks arranged in a row. Let us paint these blocks.</p> <p>We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.</p> <p>Find the number of ways to paint the blocks under the following conditions:</p> <ul> <li>For each block, use one of the <var>M</var> colors, Color <var>1</var> through Color <var>M</var>, to paint it. It is not mandatory to use all the colors.</li> <li>There may be at most <var>K</var> pairs of adjacent blocks that are painted in the same color.</li> </ul> <p>Since the count may be enormous, print it modulo <var>998244353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N, M \leq 2 \times 10^5</var></li> <li><var>0 \leq K \leq N - 1</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>The following ways to paint the blocks satisfy the conditions: <code>112</code>, <code>121</code>, <code>122</code>, <code>211</code>, <code>212</code>, and <code>221</code>. Here, digits represent the colors of the blocks.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 100 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>73074801 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>60522 114575 7559 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>479519525 </pre></section> </div> </span>
p03997
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a trapezoid. The lengths of its upper base, lower base, and height are <var>a</var>, <var>b</var>, and <var>h</var>, respectively.</p> <div style="text-align: center;"> <img src="https://atcoder.jp/img/arc061/1158e37155d46a42e90f31566478e6da.png"> <p>An example of a trapezoid</p> </img></div> <p>Find the area of this trapezoid.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩a≩100</var></li> <li><var>1≩b≩100</var></li> <li><var>1≩h≩100</var></li> <li>All input values are integers.</li> <li><var>h</var> is even.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> <var>h</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the area of the given trapezoid. It is guaranteed that the area is an integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>When the lengths of the upper base, lower base, and height are <var>3</var>, <var>4</var>, and <var>2</var>, respectively, the area of the trapezoid is <var>(3+4)×2/2 = 7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>16 </pre> <p>In this case, a parallelogram is given, which is also a trapezoid.</p></section> </div> </span>
p00196
<H1>野球倧䌚</H1> <p> 野球の囜別察抗戊 WBC で、日本が2連芇達成!! 野球人気が高たる䞭、䌚接孊園高校を䌚堎に野球倧䌚が行われたした。この倧䌚では、総圓りのリヌグ戊を行い、以䞋のような方法で順䜍を決めるこずになりたした。 </p> <ol> <li> 勝ち数の倚いチヌムを䞊䜍ずする</li> <li> 勝ち数が同数の堎合は負け数の少ないチヌムを䞊䜍ずする</li> </ol> <p> 各チヌムの成瞟を入力ずし、チヌム名を䞊䜍のチヌムから順に出力するプログラムを䜜成しおください。同順䜍のチヌムが存圚する堎合は、入力順に出力しおください。ただし、チヌム数 <var>n</var> は 2 以䞊 10 以䞋の敎数、チヌム名 <var>t</var> は 1 文字の半角英字、詊合毎の成瞟 <var>r</var> は <var>n</var> - 1 個の数字で衚され、勝ちの堎合は 0 、負けの堎合は 1 、匕き分けの堎合は 2 ずしたす。たた、チヌム名に重耇はないものずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>score<sub>1</sub></var> <var>score<sub>2</sub></var> : <var>score<sub>n</sub></var> </pre> <p> 1 行目にチヌムの数 <var>n</var> (2 &le; <var>n</var> &le; 10) 、続く <var>n</var> 行に第 <var>i</var> のチヌムの成瞟 <var>score<sub>i</sub></var> が䞎えられたす。各成瞟は次の圢匏で䞎えられたす。 </p> <pre> <var>t</var> <var>r<sub>1</sub></var> <var>r<sub>2</sub></var> ... <var>r<sub>n&minus;1</sub></var> </pre> <p> チヌム名 <var>t</var> (文字の半角英字)、<var>t</var> の詊合毎の成瞟 <var>r<sub>i</sub></var> (0, 1, たたは 2) が空癜区切りで䞎えられたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、チヌム名を䞊䜍のチヌムから順に出力したす。 </p> <H2>Sample Input</H2> <pre> 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> E A B D F C w h b g </pre>
p02451
<h1>Binary Search</h1> <p> For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, find a specific value $k$ given as a query. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1 \; ,..., \; a_{n-1}$ $q$ $k_1$ $k_2$ : $k_q$ </pre> <p> The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries. <h2>Output</h2> <p> For each query, print <span>1</span> if any element in $A$ is equivalent to $k$, and <span>0</span> otherwise. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 100,000$</li> <li>$1 \leq q \leq 200,000$</li> <li>$0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$ <li>$0 \leq k_i \leq 1,000,000,000$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 1 2 2 4 3 2 3 5 </pre> <h2>Sample Output 1</h2> <pre> 1 0 0 </pre>
p02001
<h1>F: Swap</h1> <h2>問題</h2> <p> 長さ $N$ の文字列 $S,\ T$ が䞎えられたす$S,\ T$ はそれぞれ 'o' , '.' の二皮類の文字だけで構成されおいたす あなたは $S$ に察しお以䞋の操䜜を行うこずができたす </p> <p> <ul> <li> 以䞋の条件を党お満たす敎数察 $(l, r)$ を遞択するその埌$S[l]$ ず $S[l + 1]S[r - 1]$ ず $S[r]$ をそれぞれスワップする</li> <ul> <li>$1 \leq l, r \leq N$</li> <li>$r - l \geq 3$</li> <li>$S[l] = S[r] =$ '.'</li> <li>$S[l + 1] = S[l + 2] = \dots = S[r - 1] =$ 'o'</li> </ul> </ul> </p> <p> 䜕回か操䜜を繰り返したあず(0回でも可)文字列 S を T に倉圢するこずが可胜か刀定しおください </p> <h2>制玄</h2> <ul> <li>$1 \leq N \leq 100000$</li> <li>$|S| = |T| = N \ \ \ \ \ \ \ |S|$ , $|T|$ は文字列の長さ</li> <li>$S$ , $T$ は 'o', '.' の二皮類の文字からのみ構成される。 </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <p> $N$<br> $S$<br> $T$<br> </p> <h2>出力</h2> <p>操䜜を䜕回か適甚埌( $0$ 回でも可) $S$ を $T$ に倉圢するこずが可胜ならば Yesどのように操䜜しおも䞍可胜ならば No を出力しおくださいたた、末尟に改行も出力しおください </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 8 .oo.ooo. o.o.oo.o </pre> <h3>サンプル出力 1</h3> <pre> Yes </pre> <p> 以䞋の手順で操䜜を行うこずで達成できたす <ol> <li>$S$ = ".oo.ooo." : $(l, r) = (1, 4)$ を遞択する</li> <li>$S$ = "o..oooo." : $(l, r) = (4, 9)$ を遞択する</li> <li>$S$ = "o.o.oo.o" : $T$ ず䞀臎し目的を達成</li> </ol> </p> <h3>サンプル入力 2</h3> <pre> 7 .ooooo. oo.o.oo </pre> <h3>サンプル出力 2</h3> <pre> Yes </pre> <p> 以䞋の手順で操䜜を行うこずで達成できたす <ol> <li>$S$ = ".ooooo." : $(l, r) = (1, 7)$ を遞択する</li> <li>$S$ = "o.ooo.o" : $(l, r) = (2, 6)$ を遞択する</li> <li>$S$ = "oo.o.oo" : $T$ ず䞀臎し目的を達成</li> </ol> </p> <h3>サンプル入力 3</h3> <pre> 6 o.o.o. ooo... </pre> <h3>サンプル出力 3</h3> <pre> No </pre> <p> 操䜜を適甚できる $(l, r)$ が存圚しないため$S$ を倉圢しお $T$ にするこずができたせん </p> <h3>サンプル入力 4</h3> <pre> 9 .oo.oooo. .oo.oooo. </pre> <h3>サンプル出力 4</h3> <pre> Yes </pre> <p> $1$ 回も倉圢させずに目的を達成できたす </p> <h3>サンプル入力 5</h3> <pre> 11 .oooo.oooo. oo.oo.oo.oo </pre> <h3>サンプル出力 5</h3> <pre> Yes </pre>
p00895
<H1><font color="#000">Problem B: </font>The Sorcerer's Donut </H1> <p> Your master went to the town for a day. You could have a relaxed day without hearing his scolding. But he ordered you to make donuts dough by the evening. Loving donuts so much, he can't live without eating tens of donuts everyday. What a chore for such a beautiful day. </p> <p> But last week, you overheard a magic spell that your master was using. It was the time to try. You casted the spell on a broomstick sitting on a corner of the kitchen. With a flash of lights, the broom sprouted two arms and two legs, and became alive. You ordered him, then he brought flour from the storage, and started kneading dough. The spell worked, and how fast he kneaded it! </p> <p> A few minutes later, there was a tall pile of dough on the kitchen table. That was enough for the next week. \OK, stop now." You ordered. But he didn't stop. Help! You didn't know the spell to stop him! Soon the kitchen table was filled with hundreds of pieces of dough, and he still worked as fast as he could. If you could not stop him now, you would be choked in the kitchen filled with pieces of dough. </p> <p> Wait, didn't your master write his spells on his notebooks? You went to his den, and found the notebook that recorded the spell of cessation. </p> <p> But it was not the end of the story. The spell written in the notebook is not easily read by others. He used a plastic model of a donut as a notebook for recording the spell. He split the surface of the donut-shaped model into square mesh (Figure B.1), and filled with the letters (Figure B.2). He hid the spell so carefully that the pattern on the surface looked meaningless. But you knew that he wrote the pattern so that the spell "appears" more than once (see the next paragraph for the precise conditions). The spell was not necessarily written in the left-to-right direction, but any of the 8 directions, namely left-to-right, right-to-left, top-down, bottom-up, and the 4 diagonal directions. </p> <p> You should be able to find the spell as the longest string that appears more than once. Here, a string is considered to appear more than once if there are square sequences having the string on the donut that satisfy the following conditions.<br><br> <li>Each square sequence does not overlap itself. (Two square sequences can share some squares.)</li> <li>The square sequences start from different squares, and/or go to different directions.</li> </p> <center> <table width="480"> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1316_1"> </td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1316_2"> </td> <tr> <td> <b>Figure B.1: The Sorcerer's Donut Before Filled with Letters, Showing the Mesh and 8 Possible Spell Directions </b> </td> <td valign="top"> <b> Figure B.2: The Sorcerer's Donut After Filled with Letters </b> </td> </tr> </table> </center> <p> Note that a palindrome (i.e., a string that is the same whether you read it backwards or forwards) that satisfies the first condition "appears" twice. </p> <p> The pattern on the donut is given as a matrix of letters as follows. </p> <pre> ABCD EFGH IJKL </pre> <p> Note that the surface of the donut has no ends; the top and bottom sides, and the left and right sides of the pattern are respectively connected. There can be square sequences longer than both the vertical and horizontal lengths of the pattern. For example, from the letter F in the above pattern, the strings in the longest non-self-overlapping sequences towards the 8 directions are as follows. </p> <pre> FGHE FKDEJCHIBGLA FJB FIDGJAHKBELC FEHG FALGBIHCJEDK FBJ FCLEBKHAJGDI </pre> <p> Please write a program that finds the magic spell before you will be choked with pieces of donuts dough. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset begins with a line of two integers <i>h</i> and <i>w</i>, which denote the size of the pattern, followed by <i>h</i> lines of <i>w</i> uppercase letters from A to Z, inclusive, which denote the pattern on the donut. You may assume 3 &le; <i>h</i> &le; 10 and 3 &le; <i>w</i> &le; 20. </p> <p> The end of the input is indicated by a line containing two zeros. </p> <H2>Output</H2> <p> For each dataset, output the magic spell. If there is more than one longest string of the same length, the first one in the dictionary order must be the spell. The spell is known to be at least two letters long. When no spell is found, output 0 (zero). </p> <H2>Sample Input</H2> <pre> 5 7 RRCABXT AABMFAB RROMJAC APTADAB YABADAO 3 13 ABCDEFGHIJKLM XMADAMIMADAMY ACEGIKMOQSUWY 3 4 DEFG ACAB HIJK 3 6 ABCDEF GHIAKL MNOPQR 10 19 JFZODYDXMZZPEYTRNCW XVGHPOKEYNZTQFZJKOD EYEHHQKHFZOVNRGOOLP QFZOIHRQMGHPNISHXOC DRGILJHSQEHHQLYTILL NCSHQMKHTZZIHRPAUJA NCCTINCLAUTFJHSZBVK LPBAUJIUMBVQYKHTZCW XMYHBVKUGNCWTLLAUID EYNDCCWLEOODXYUMBVN 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> ABRACADABRA MADAMIMADAM ABAC 0 ABCDEFGHIJKLMNOPQRSTUVWXYZHHHHHABCDEFGHIJKLMNOPQRSTUVWXYZ </pre>
p01787
<h2>H - RLE Replacement</h2> <h3>Problem Statement</h3> <p> In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only contain uppercase English letters and the same letters often appear repeatedly in ICPC programs. Thus, programmers in JAG Kingdom prefer to compress ICPC programs by <i>Run Length Encoding</i> in order to manage very large-scale ICPC programs. </p> <p> Run Length Encoding (RLE) is a string compression method such that each maximal sequence of the same letters is encoded by a pair of the letter and the length. For example, the string "RRRRLEEE" is represented as "R4L1E3" in RLE. </p> <p> Now, you manage many ICPC programs encoded by RLE. You are developing an editor for ICPC programs encoded by RLE, and now you would like to implement a replacement function. Given three strings $A$, $B$, and $C$ that are encoded by RLE, your task is to implement a function replacing the first occurrence of the substring $B$ in $A$ with $C$, and outputting the edited string encoded by RLE. If $B$ does not occur in $A$, you must output $A$ encoded by RLE without changes. </p> <h3>Input</h3> <p> The input consists of three lines. </p> <blockquote> $A$<br> $B$<br> $C$</blockquote> <p> The lines represent strings $A$, $B$, and $C$ that are encoded by RLE, respectively. Each of the lines has the following format: </p> <blockquote> $c_1$ $l_1$ $c_2$ $l_2$ $\ldots$ $c_n$ $l_n$ \$</blockquote> <p> Each $c_i$ ($1 \leq i \leq n$) is an uppercase English letter (<code>A</code>-<code>Z</code>) and $l_i$ ($1 \leq i \leq n$, $1 \leq l_i \leq 10^8$) is an integer which represents the length of the repetition of $c_i$. The number $n$ of the pairs of a letter and an integer satisfies $1 \leq n \leq 10^3$. A terminal symbol <code>$</code> indicates the end of a string encoded by RLE. The letters and the integers are separated by a single space. It is guaranteed that $c_i \neq c_{i+1}$ holds for any $1 \leq i \leq n-1$. </p> <h3>Output</h3> <p> Replace the first occurrence of the substring $B$ in $A$ with $C$ if $B$ occurs in $A$, and output the string encoded by RLE. The output must have the following format: </p> <blockquote> $c_1$ $l_1$ $c_2$ $l_2$ $\ldots$ $c_m$ $l_m$ \$</blockquote> <p> Here, $c_i \neq c_{i+1}$ for $1 \leq i \leq m-1$ and $l_i \gt 0$ for $1 \leq i \leq m$ must hold. </p> <h3>Sample Input 1</h3> <pre>R 100 L 20 E 10 \$ R 5 L 10 \$ X 20 \$</pre> <h3>Output for the Sample Input 1</h3> <pre>R 95 X 20 L 10 E 10 \$</pre> <h3>Sample Input 2</h3> <pre>A 3 B 3 A 3 \$ A 1 B 3 A 1 \$ A 2 \$</pre> <h3>Output for the Sample Input 2</h3> <pre>A 6 \$</pre>
p03240
<span class="lang-en"> <p>Score: <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.<br/> The pyramid had <em>center coordinates</em> <var>(C_X, C_Y)</var> and <em>height</em> <var>H</var>. The altitude of coordinates <var>(X, Y)</var> is <var>max(H - |X - C_X| - |Y - C_Y|, 0)</var>. </p> <p>Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information: </p> <ul> <li><var>C_X, C_Y</var> was integers between <var>0</var> and <var>100</var> (inclusive), and <var>H</var> was an integer not less than <var>1</var>. </li> <li>Additionally, he obtained <var>N</var> pieces of information. The <var>i</var>-th of them is: "the altitude of point <var>(x_i, y_i)</var> is <var>h_i</var>." </li> </ul> <p>This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</li> <li><var>x_i</var> and <var>y_i</var> are integers between <var>0</var> and <var>100</var> (inclusive).</li> <li><var>h_i</var> is an integer between <var>0</var> and <var>10^9</var> (inclusive).</li> <li>The <var>N</var> coordinates <var>(x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N)</var> are all different.</li> <li>The center coordinates and the height of the pyramid can be uniquely identified.</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>h_1</var> <var>x_2</var> <var>y_2</var> <var>h_2</var> <var>x_3</var> <var>y_3</var> <var>h_3</var> <var>:</var> <var>x_N</var> <var>y_N</var> <var>h_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print values <var>C_X, C_Y</var> and <var>H</var> representing the center coordinates and the height of the pyramid in one line, with spaces in between. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 3 5 2 1 5 1 2 5 3 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 2 6 </pre> <p>In this case, the center coordinates and the height can be identified as <var>(2, 2)</var> and <var>6</var>. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 0 0 100 1 1 98 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 0 100 </pre> <p>In this case, the center coordinates and the height can be identified as <var>(0, 0)</var> and <var>100</var>.<br/> Note that <var>C_X</var> and <var>C_Y</var> are known to be integers between <var>0</var> and <var>100</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 99 1 191 100 1 192 99 0 192 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>100 0 193 </pre> <p>In this case, the center coordinates and the height can be identified as <var>(100, 0)</var> and <var>193</var>. </p></section> </div> </span>
p02902
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a directed graph <var>G</var> with <var>N</var> vertices and <var>M</var> edges.<br/> The vertices are numbered <var>1</var> to <var>N</var>, and the <var>i</var>-th edge is directed from Vertex <var>A_i</var> to Vertex <var>B_i</var>.<br/> It is guaranteed that the graph contains no self-loops or multiple edges.</p> <p>Determine whether there exists an induced subgraph (see Notes) of <var>G</var> such that the in-degree and out-degree of every vertex are both <var>1</var>. If the answer is yes, show one such subgraph.<br/> Here the null graph is not considered as a subgraph.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>For a directed graph <var>G = (V, E)</var>, we call a directed graph <var>G' = (V', E')</var> satisfying the following conditions an induced subgraph of <var>G</var>:</p> <ul> <li><var>V'</var> is a (non-empty) subset of <var>V</var>.</li> <li><var>E'</var> is the set of all the edges in <var>E</var> that have both endpoints in <var>V'</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>0 \leq M \leq 2000</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li><var>A_i \neq B_i</var></li> <li>All pairs <var>(A_i, B_i)</var> are distinct.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>:</var> <var>A_M</var> <var>B_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is no induced subgraph of <var>G</var> that satisfies the condition, print <code>-1</code>. Otherwise, print an induced subgraph of <var>G</var> that satisfies the condition, in the following format:</p> <pre><var>K</var> <var>v_1</var> <var>v_2</var> : <var>v_K</var> </pre> <p>This represents the induced subgraph of <var>G</var> with <var>K</var> vertices whose vertex set is <var>\{v_1, v_2, \ldots, v_K\}</var>. (The order of <var>v_1, v_2, \ldots, v_K</var> does not matter.) If there are multiple subgraphs of <var>G</var> that satisfy the condition, printing any of them is accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 1 2 2 3 2 4 4 1 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 1 2 4 </pre> <p>The induced subgraph of <var>G</var> whose vertex set is <var>\{1, 2, 4\}</var> has the edge set <var>\{(1, 2), (2, 4), (4, 1)\}</var>. The in-degree and out-degree of every vertex in this graph are both <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 1 2 2 3 2 4 1 4 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>There is no induced subgraph of <var>G</var> that satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 9 1 2 2 3 3 4 4 5 5 6 5 1 5 2 6 1 6 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 2 3 4 5 </pre></section> </div> </span>
p03610
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>s</var> consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index <var>1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>Each character in <var>s</var> is a lowercase English letter.</li> <li><var>1≀|s|≀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>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the string obtained by concatenating all the characters in the odd-numbered positions.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>atcoder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>acdr </pre> <p>Extract the first character <code>a</code>, the third character <code>c</code>, the fifth character <code>d</code> and the seventh character <code>r</code> to obtain <code>acdr</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>aaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>aa </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>z </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>z </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>fukuokayamaguchi </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>fkoaaauh </pre></section> </div> </span>
p01338
<h1><font color="#000">Problem F:</font> KULASIS</h1> <h2>Description</h2> <p> <i>  KULASISずは党孊共通科目に関する情報をWeb化し孊生・教員ぞの支揎やサヌビスの向䞊を目的に高等教育研究開発掚進機構で開発・運甚しおいるシステムの名称です。 KULASISは2003幎床のオンラむンシラバス開発から始たりWeb掲瀺板・履修登録・成瞟関係採点登録・孊生からの採点確認ず順次システムを拡充しおきたした。<br>  孊生はパ゜コン・携垯電話から孊内倖を問わず教務情報䌑講・授業倉曎・レポヌトの確認・履修登録・採点確認等の機胜を利甚するこずができたす。ログむン件数は倚い日には10,000件を超え京郜倧孊の教務情報システムずしお浞透し党孊共通科目を履修するためには欠かせないものずなっおいたす。このKULASISを党孊共通科目のみにずどたらず孊郚専門課皋や倧孊院にも適甚できるよう 開発を進めおいたす。<br> http://www.z.k.kyoto-u.ac.jp/introduction_kulasis.html </i> </p> <p> 京倧生のQは埌期のシラバスを組むためにKULASISにログむンしおいた どの科目を入れようずしおいるか悩んでいるず突然KULASISが眩い光を攟ち別のペヌゞぞず遷移した<br> 遷移した先のペヌゞは䞋図のようなものであった5x5のマスには科目名ず評䟡(䞍可可良優)が曞かれおおり栌子䞊には<font color=orange>●</font>のボタンが16個配眮されおいる<br> いったいなにが起きたのか分からなかったQだったがどうやら栌子䞊にある<font color=orange>●</font>のボタンを抌すずその右䞊右䞋巊䞊巊䞋にあるマスの科目の評䟡がそれぞれ 䞍可→可可→良良→優優→䞍可 ず入れ替わるようであった<br> <br><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_03Ffig" height=263 width=646><br> <br><br> <font color=orange>●</font>のボタンは䜕床でも抌すこずができる<br> KULASISが䜕者かによっお曞き換えられおしたったのか自分が倢を芋おいるのかよく分からないがこれで成瞟を確定できるならば出来るだけ良い成瞟を埗たいずQは考えた<br> 単䜍を倚く集めおいるこずに自信があったQは単䜍の数そのものよりも半幎埌の研究宀配属に備えお<b>戊闘力</b>を最倧にさせるこずにした<br> <b>戊闘力</b>ずは各科目の評䟡を䞍可→0点可→60点良→70点優→80点ず換算しお合蚈した倀のこずでこれは研究宀配属の際に自分がどの皋床優䜍なのかを衚すず(Qの孊科では)思われおいる<br> <br> いたKULASISの画面の衚瀺されおいる科目ずその評䟡が䞎えられるので埗るこずが出来る<b>戊闘力</b>の最倧倀を出力するプログラムを蚘しおほしい </p> <h2>Input</h2> <p> 入力の1行目にはテストケヌスの個数が䞎えられるテストケヌスの数は100個以䞋であるこずが保障されおいる<br> 2行目以降は5x5の数字が䞊びKULASISの画面に衚瀺されおいる科目の評䟡が䞎えられ1,2,3,4がそれぞれ䞍可可良優に察応する<br> 0ならばそのコマには科目は登録されおいない<br> テストケヌス同士の間は空行で区切られおいる </p> <h2>Output</h2> <p> 各テストケヌスに察し埗るこずの出来る<b>戊闘力</b>の最倧倀を出力せよ </p> <h2>Sample Input</h2> <pre> 5 1 1 0 3 3 1 1 0 3 3 0 0 0 0 0 2 2 0 4 4 2 2 0 4 4 1 1 1 0 0 1 1 1 1 0 1 0 1 1 0 0 0 1 1 1 1 1 1 1 1 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 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 2 2 2 2 2 0 0 0 2 0 2 2 0 2 0 2 2 0 2 0 0 0 0 2 0 </pre> <h2>Output for Sample Input</h2> <pre> 1280 1420 0 1920 1020 </pre>
p03305
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Kenkoooo is planning a trip in Republic of Snuke. In this country, there are <var>n</var> cities and <var>m</var> trains running. The cities are numbered <var>1</var> through <var>n</var>, and the <var>i</var>-th train connects City <var>u_i</var> and <var>v_i</var> bidirectionally. Any city can be reached from any city by changing trains.</p> <p>Two currencies are used in the country: yen and snuuk. Any train fare can be paid by both yen and snuuk. The fare of the <var>i</var>-th train is <var>a_i</var> yen if paid in yen, and <var>b_i</var> snuuk if paid in snuuk.</p> <p>In a city with a money exchange office, you can change <var>1</var> yen into <var>1</var> snuuk. However, when you do a money exchange, you have to change all your yen into snuuk. That is, if Kenkoooo does a money exchange when he has <var>X</var> yen, he will then have <var>X</var> snuuk. Currently, there is a money exchange office in every city, but the office in City <var>i</var> will shut down in <var>i</var> years and can never be used in and after that year.</p> <p>Kenkoooo is planning to depart City <var>s</var> with <var>10^{15}</var> yen in his pocket and head for City <var>t</var>, and change his yen into snuuk in some city while traveling. It is acceptable to do the exchange in City <var>s</var> or City <var>t</var>.</p> <p>Kenkoooo would like to have as much snuuk as possible when he reaches City <var>t</var> by making the optimal choices for the route to travel and the city to do the exchange. For each <var>i=0,...,n-1</var>, find the maximum amount of snuuk that Kenkoooo has when he reaches City <var>t</var> if he goes on a trip from City <var>s</var> to City <var>t</var> after <var>i</var> years. You can assume that the trip finishes within the year.</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 s,t \leq n</var></li> <li><var>s \neq t</var></li> <li><var>1 \leq u_i &lt; v_i \leq n</var></li> <li><var>1 \leq a_i,b_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>Any city can be reached from any city by changing trains.</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</var> <var>t</var> <var>u_1</var> <var>v_1</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>u_m</var> <var>v_m</var> <var>a_m</var> <var>b_m</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>n</var> lines. In the <var>i</var>-th line, print the maximum amount of snuuk that Kenkoooo has when he reaches City <var>t</var> if he goes on a trip from City <var>s</var> to City <var>t</var> after <var>i-1</var> years.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 2 3 1 4 1 100 1 2 1 10 1 3 20 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>999999999999998 999999999999989 999999999999979 999999999999897 </pre> <p>After <var>0</var> years, it is optimal to do the exchange in City <var>1</var>.<br/> After <var>1</var> years, it is optimal to do the exchange in City <var>2</var>.<br/> Note that City <var>1</var> can still be visited even after the exchange office is closed. Also note that, if it was allowed to keep <var>1</var> yen when do the exchange in City <var>2</var> and change the remaining yen into snuuk, we could reach City <var>3</var> with <var>999999999999998</var> snuuk, but this is NOT allowed.<br/> After <var>2</var> years, it is optimal to do the exchange in City <var>3</var>.<br/> After <var>3</var> years, it is optimal to do the exchange in City <var>4</var>. Note that the same train can be used multiple times.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 12 3 8 2 8 685087149 857180777 6 7 298270585 209942236 2 4 346080035 234079976 2 5 131857300 22507157 4 8 30723332 173476334 2 6 480845267 448565596 1 4 181424400 548830121 4 5 57429995 195056405 7 8 160277628 479932440 1 6 475692952 203530153 3 5 336869679 160714712 2 7 389775999 199123879 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 </pre></section> </div> </span>
p02847
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var> representing the day of the week today.</p> <p><var>S</var> is <code>SUN</code>, <code>MON</code>, <code>TUE</code>, <code>WED</code>, <code>THU</code>, <code>FRI</code>, or <code>SAT</code>, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.</p> <p>After how many days is the next Sunday (tomorrow or later)?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is <code>SUN</code>, <code>MON</code>, <code>TUE</code>, <code>WED</code>, <code>THU</code>, <code>FRI</code>, or <code>SAT</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 days before the next Sunday.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>SAT </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>It is Saturday today, and tomorrow will be Sunday.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>SUN </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> <p>It is Sunday today, and seven days later, it will be Sunday again.</p></section> </div> </span>
p01768
<h1 id="c-shopping-買い物">C : Shopping / 買い物</h1> <h2 id="問題文">問題文</h2> <p>料理が埗意な2D君は昌ごはんを䜜ろうずしおいる。料理には <var>N</var> 個の材料 <var>a_{0}, a_{1}, 
 , a_{N&minus;1}</var> が党おが必芁である。</p> <p>さお、今2D君の家の冷蔵庫には䞀぀も材料が入っおいないので、スヌパヌに買いに行かなければならない。スヌパヌでは材料 <var>a_{i}</var> を倀段 <var>x_{i}</var> 円で買うこずができる。</p> <p>2D君は魔法䜿いでもあり、 <var>M</var> 皮類の魔法が䜿える。 <var>i</var> 番目の魔法を材料 <var>s_{i}</var> にかければ材料 <var>t_{i}</var> に、たた逆に <var>t_{i}</var> にかければ <var>s_{i}</var> に倉えるこずができる。さらに、䞀぀の材料に察しお耇数の魔法を繰り返しお䜿うこずができる。䟋えば、 <var>p</var> から <var>q</var> に倉える魔法ず、 <var>q</var> から <var>r</var> に倉える魔法の2぀を䜿っお、 <var>p</var> から <var>r</var> を埗るこずができる。</p> <p>2D君は魔法の力を借りおなるべく安く材料を揃えるこずにした。料理を完成させるために2D君が買う必芁のある材料の、倀段の総和の最小倀を求めよ。</p> <h2 id="入力">入力</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre><var>N</var> <var>a_{0}</var> <var>x_{0}</var> <var>
</var> <var>a_{N&minus;1}</var> <var>x_{N&minus;1}</var> <var>M</var> <var>s_{0}</var> <var>t_{0}</var> <var>
</var> <var>s_{M&minus;1}</var> <var>t_{M&minus;1}</var> </pre> <h2 id="制玄">制玄</h2> <ul> <li>数倀はすべお敎数である</li> <li>材料の名前はすべお <var>1</var> 文字以䞊 <var>10</var> 文字以䞋のアルファベット小文字からなる</li> <li><var>i ≠ j</var> なら <var>a_{i} ≠ a_{j}</var></li> <li><var>1 \&le; x_{i} \&le; 1,000</var></li> <li><var>1 \&le; N \&le; 5,000</var></li> <li><var>0 \&le; M \&le; {\rm min}(N(N&minus;1)</var>/<var>2, 1000)</var></li> <li><var>s_{i} ≠ t_{i}</var></li> <li><var>s_{i},t_{i}</var> の組に重耇はない</li> <li><var>s_{i},t_{i}</var> は <var>a_{0},
,a_{N&minus;1}</var> に含たれる</li> </ul> <h2 id="出力">出力</h2> <p>答えを1行で出力せよ。</p> <h2 id="サンプル">サンプル</h2> <h3 id="サンプル入力1">サンプル入力1</h3> <pre>2 tako 2 yaki 1 1 tako yaki </pre> <p>魔法によっお安い yaki を tako に倉えるこずができるので、 yaki を <var>2</var> 個買えばよい。</p> <h3 id="サンプル出力1">サンプル出力1</h3> <pre>2 </pre> <h3 id="サンプル入力2">サンプル入力2</h3> <pre>5 a 1 b 2 c 2 d 4 e 3 5 b a a c c d e b c b </pre> <h3 id="サンプル出力2">サンプル出力2</h3> <pre>5 </pre> <p>䞋に瀺すように、党おの材料を a から倉えおそろえるこずができる。</p> <ul> <li>a : a そのたた</li> <li>b : a -&gt; c -&gt; b</li> <li>c : a -&gt; c</li> <li>d : a -&gt; c -&gt; d</li> <li>e : a -&gt; b -&gt; e</li> </ul> <div class="figure"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RUPC2015_C1" /> </div>
p03755
<span class="lang-en lang-child hidden-lang"> <div id="task-statement"> Max Score: <var>1000</var> Points <br/> <section> <h3>Problem Statement</h3> There is a railroad company in Atcoder Kingdom, "Atcoder Railroad". <br/> There are <var>N + 1</var> stations numbered <var>0, 1, 2, ..., N</var> along a railway. <br/> Currently, two kinds of train are operated, local and express. <br/> A local train stops at every station, and it takes one minute from station <var>i</var> to <var>i + 1</var>, and vice versa. <br/> An express train only stops at station <var>S_0, S_1, S_2, ..., S_{K-1} (0 = S_0 &lt; S_1 &lt; S_2 &lt; ... &lt; S_{K-1} = N)</var>. It takes one minute from station <var>S_i</var> to <var>S_{i + 1}</var>, and vice versa. <br/> But the president of Atcoder Railroad, Semiexp said it is not very convenient so he planned to operate one more kind of train, "semi-express". <br/> The stations where the semi-express stops (This is <var>T_0, T_1, T_2, ..., T_{L-1}</var>, <var>0 = T_0 &lt; T_1 &lt; T_2 &lt; ... &lt; T_{L-1} = N</var>) have to follow following conditions: <br/> From station <var>T_i</var> to <var>T_{i+1}</var> takes 1 minutes, and vice versa. <br/> <ul> <li>The center of Atcoder Kingdom is station <var>0</var>, and you have to be able to go to station <var>i</var> atmost <var>X</var> minutes.</li> <li>If the express stops at the station, semi-express should stops at the station.</li> </ul> Print the number of ways of the set of the station where semi-express stops (sequence <var>T</var>). <br/> Since the answer can be large, print the number modulo <var>10^9 + 7</var>. <br/> </section> </div> <div class="io-style"> <div class="part"> <section> <h3>Input Format</h3> <pre> <var>N</var> <var>K</var> <var>X</var> <var>S_0</var> <var>S_1</var> <var>S_2</var> ... <var>S_{K-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output Format</h3> Print the number of ways of the set of the station where semi-express stops, mod <var>10^9 + 7</var> in one line. <br/> Print <code>\n</code> (line break) in the end. <br/> </section> <section> <h3>Constraints</h3> <ul> <li><var>2 ≀ K ≀ 2500</var>.</li> <li><var>1 ≀ X ≀ 2500</var>.</li> <li><var>S_0 = 0, S_{K-1} = N</var>.</li> <li><var>1 ≀ S_{i + 1} - S_i ≀ 10000</var>.</li> </ul> </section> <section> <h3>Scoring</h3> Subtask 1 [<var>120</var> points] <br/> <ul> <li><var>N, K, X ≀ 15</var>.</li> </ul> Subtask 2 [<var>90</var> points] <br/> <ul> <li><var>K, X ≀ 15</var>.</li> <li><var>S_{i + 1} - S_i ≀ 15</var>.</li> </ul> Subtask 3 [<var>260</var> points] <br/> <ul> <li><var>K, X ≀ 40</var>.</li> <li><var>S_{i + 1} - S_i ≀ 40</var>.</li> </ul> Subtask 4 [<var>160</var> points] <br/> <ul> <li><var>K, X ≀ 300</var>.</li> <li><var>S_{i + 1} - S_i ≀ 300</var>.</li> </ul> Subtask 5 [<var>370</var> points] <br/> <ul> <li>There are no additional constraints.</li> </ul> </section> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 7 2 3 0 7 </pre> </section> <section> <h3>Sample Output 1</h3> <pre> 55 </pre> The set of trains that stops station <var>0</var> and <var>7</var>, and can't satisfy the condition is: <br/> <var>[0, 7], [0, 1, 7], [0, 1, 2, 7], [0, 1, 6, 7], [0, 1, 2, 6, 7], [0, 1, 2, 3, 6, 7], [0, 1, 2, 5, 6, 7], [0, 1, 2, 3, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]</var>, <var>9</var> ways.<br/> Therefore, the number of ways is <var>2^6 - 9 = 55</var>. <br/> </section> </div> </div> </span>
p01292
<H1><font color="#000">Problem J:</font> Secret Operation</H1> <p> Mary Ice is a member of a spy group. She is about to carry out a secret operation with her colleague. </p> <p> She has got into a target place just now, but unfortunately the colleague has not reached there yet. She needs to hide from her enemy George Water until the colleague comes. Mary may want to make herself appear in George’s sight as short as possible, so she will give less chance for George to find her. </p> <p> You are requested to write a program that calculates the time Mary is in George’s sight before her colleague arrives, given the information about moves of Mary and George as well as obstacles blocking their sight. </p> <p> Read the Input section for the details of the situation. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> <i>Time R</i><br> <i>L</i><br> <i>MaryX</i><sub>1</sub> <i>MaryY</i><sub>1</sub> <i>MaryT</i><sub>1</sub><br> <i>MaryX</i><sub>2</sub> <i>MaryY</i><sub>2</sub> <i>MaryT</i><sub>2</sub><br> ...<br> <i>MaryX</i><sub><i>L</i></sub> <i>MaryY</i><sub><i>L</i></sub> <i>MaryT</i><sub><i>L</i></sub><br> <i>M</i><br> <i>GeorgeX</i><sub>1</sub> <i>GeorgeY</i><sub>1</sub> <i>GeorgeT</i><sub>1</sub><br> <i>GeorgeX</i><sub>2</sub> <i>GeorgeY</i><sub>2</sub> <i>GeorgeT</i><sub>2</sub><br> ...<br> <i>GeorgeX</i><sub><i>M</i></sub> <i>GeorgeY</i><sub><i>M</i></sub> <i>GeorgeT</i><sub><i>M</i></sub><br> <i>N</i> <i>BlockSX</i><sub>1</sub> <i>BlockSY</i><sub>1</sub> <i>BlockTX</i><sub>1</sub> <i>BlockTY</i><sub>1</sub><br> <i>BlockSX</i><sub>2</sub> <i>BlockSY</i><sub>2</sub> <i>BlockTX</i><sub>2</sub> <i>BlockTY</i><sub>2</sub><br> ...<br> <i>BlockSX</i><sub><i>N</i></sub> <i>BlockSY</i><sub><i>N</i></sub> <i>BlockTX</i><sub><i>N</i></sub> <i>BlockTY</i><sub><i>N</i></sub><br> </p> <p> The first line contains two integers. Time (0 &le; <i>Time</i> &le; 100) is the time Mary's colleague reaches the place. <i>R</i> (0 &lt; <i>R</i> &lt; 30000) is the distance George can see - he has a sight of this distance and of 45 degrees left and right from the direction he is moving. In other words, Mary is found by him if and only if she is within this distance from him and in the direction different by not greater than 45 degrees from his moving direction and there is no obstacles between them. </p> <p> The description of Mary's move follows. Mary moves from (<i>MaryX<sub>i</sub></i>, <i>MaryY<sub>i</sub></i>) to (<i>MaryX</i><sub><i>i</i>+1</sub>, <i>MaryY</i><sub><i>i</i>+1</sub>) straight and at a constant speed during the time between <i>MaryT<sub>i</sub></i> and <i>MaryT</i><sub><i>i</i>+1</sub>, for each 1 &le; <i>i</i> &le; <i>L</i> - 1. The following constraints apply: 2 &le; <i>L</i> &le; 20, <i>MaryT</i><sub>1</sub> = 0 and <i>MaryT<sub>L</sub></i> = <i>Time</i>, and <i>MaryT<sub>i</sub></i> &lt; <i>MaryT</i><sub><i>i</i>+1</sub> for any 1 &le; <i>i</i> &le; <i>L</i> - 1. </p> <p> The description of George's move is given in the same way with the same constraints, following Mary's. In addition, (<i>GeorgeX<sub>j</sub></i>, <i>GeorgeY<sub>j</sub></i> ) and (<i>GeorgeX</i><sub><i>j</i>+1</sub>, <i>GeorgeY</i><sub><i>j</i>+1</sub>) do not coincide for any 1 &le; <i>j</i> &le; <i>M</i> - 1. In other words, George is always moving in some direction. </p> <p> Finally, there comes the information of the obstacles. Each obstacle has a rectangular shape occupying (<i>BlockSX<sub>k</sub></i>, <i>BlockSY<sub>k</sub></i>) to (<i>BlockTX<sub>k</sub></i>, <i>BlockTY<sub>k</sub></i>). No obstacle touches or crosses with another. The number of obstacles ranges from 0 to 20 inclusive. </p> <p> All the coordinates are integers not greater than 10000 in their absolute values. You may assume that, if the coordinates of Mary's and George's moves would be changed within the distance of 10<sup>-6</sup>, the solution would be changed by not greater than 10<sup>-6</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, print the calculated time in a line. The time may be printed with any number of digits after the decimal point, but should be accurate to 10<sup>-4</sup> . </p> <H2>Sample Input</H2> <pre> 50 100 2 50 50 0 51 51 50 2 0 0 0 1 1 50 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 50 </pre>
p00529
<h2>JOIOI の塔(Tower of JOIOI)</h2> <p> JOIOI の塔ずは1 人で遊ぶ円盀を䜿ったゲヌムである </p> <p> このゲヌムは<span>J</span><span>O</span><span>I</span> のいずれかの文字が曞かれたいく぀かの円盀を甚いお行う円盀は盎埄が互いに異なりゲヌム開始時にはこれらの円盀は盎埄の倧きいものから順に䞋から䞊に向かっお積たれおいるあなたはこれらの円盀を甚いお出来るだけ倚くのミニ JOIOI の塔を䜜りたいミニ JOIOI の塔ずは 3 枚の円盀からなり円盀の盎埄が小さいものから順に読んで <span>JOI</span> もしくは <span>IOI</span> ず読めるものであるただし同じ円盀を2 床以䞊䜿うこずはできない </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2012_2012_ho_4"><br> <p> 図: <span>JOIOII</span> からはミニ JOIOI の塔が 2 ぀䜜れる </p> </center> <h3>課題</h3> <p> 甚意された円盀に曞かれた文字がそれぞれ円盀の盎埄が小さいものから順に長さ <var>N</var> の文字列 <var>S</var> ずしお䞎えられるこれらの円盀を䜿っお䜜るこずのできるミニ JOIOI の塔の個数の最倧倀を求めるプログラムを䜜成せよ </p> <h3>制限</h3> <ul> <li>1 &le; <var>N</var> &le; 1 000 000 &nbsp;&nbsp;&nbsp;&nbsp; 文字列 <var>S</var> の長さ</li> </ul> <h3>入力</h3> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li> 1 行目には敎数 <var>N</var> が曞かれおいる<var>N</var> は文字列 <var>S</var> の長さを衚す </li> <li> 2 行目には文字列 <var>S</var> が曞かれおいる</li> </ul> <h3>出力</h3> <p> 暙準出力に䜜るこずのできるミニ JOIOI の塔の数の最倧倀を衚す敎数を 1 行で出力せよ </p> <h3>入出力䟋</h3> <h3>入力䟋 1</h3> <pre> 6 JOIIOI </pre> <h3> 出力䟋 1</h3> <pre> 2 </pre> <p> <span>JOIIOI</span> は <span>JOI</span> および <span>IOI</span> をそれぞれ 1 ぀ず぀郚分列ずしお含んでおり䜜るこずのできるミニ JOIOI の塔は 2 ぀である </p> <br> <h3>入力䟋 2</h3> <pre> 5 JOIOI </pre> <h3>出力䟋 2</h3> <pre> 1 </pre> <p> 郚分列ずしお <span>JOI</span> および <span>IOI</span> を含んでいるが文字を 2 床以䞊䜿うこずはできないため同時に取り出すこずはできない </p> <br> <h3>入力䟋 3</h3> <pre> 6 JOIOII </pre> <h3> 出力䟋 3</h3> <pre> 2 </pre> <p> この入出力䟋は問題文䞭の䟋に察応しおいる </p> <br> <h3>入力䟋 4</h3> <pre> 15 JJOIIOOJOJIOIIO </pre> <h3>出力䟋 4</h3> <pre> 4 </pre> <br> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02144
<h1>Problem H: Loss</h1> <h2>Problem</h2> <p> あなたは、ずある䌚瀟からプログラムの䜜成を䟝頌された。 その䌚瀟には$N$個の仕事があり、それぞれの仕事には$1$から$N$たでの番号が振られおいる。 仕事$i$には、$M_i$個の前提ずなる仕事$X_{i,j}$が存圚し、仕事$i$を前提ずなる仕事$X_{i,j}$よりも先に行うず、仕事$i$は倚倧な損倱を被る。 </p> <p>そこであなたには、損倱を被る仕事の数が最小ずなるような順番ですべおの仕事を行ったずきの損倱を被った仕事の数を求めおもらいたい。</p> <h2>Input</h2> <p>入力は以䞋の圢匏ですべお敎数で䞎えられる。</p> <pre> $N$ $M_1$ $X_{1,1}$ $X_{1,2}$ ... $X_{1,M_1}$ $M_2$ $X_{2,1}$ $X_{2,2}$ ... $X_{2,M_2}$ : $M_N$ $X_{N,1}$ $X_{N,2}$ ...$X_{N,M_N}$ </pre> <p> 仕事の数$N$が$1$行に䞎えられる。<br> 続く$N$行に前提ずなる仕事の情報が䞎えられる。$i+1$行目には仕事$i$の情報が空癜区切りで䞎えられる。$M_i$は、仕事$i$の前提ずなる仕事の数、$X_{i,j}$は仕事$i$の前提ずなる仕事の番号を衚しおいる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \le N \le 10^5$</li> <li>$0 \le M_i \le N$</li> <li>$M_i$の総和は$10^5$を超えない</li> <li>$1 \le X_{i,j} \le min(i+1,N)$</li> </ul> <h2>Output</h2> <p>損倱を被る仕事の数が最小になるような順番ですべおの仕事を行ったずき、そのずきの損倱を被った仕事の数を䞀行に出力する。</p> <h2>Sample Input 1</h2> <pre> 2 1 1 0 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <p> 仕事$1$のように前提ずなる仕事がその仕事自身ずなるような入力も存圚する。 </p> <h2>Sample Input 2</h2> <pre> 3 3 2 1 2 0 1 2 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre> <h2>Sample Input 3</h2> <pre> 5 1 2 1 3 2 1 2 3 1 3 5 0 </pre> <h2>Sample Output 3</h2> <pre> 1 </pre> <p>䟋えば、$3,2,1,5,4$の順に仕事を行うず損倱を最小化できる。</p>
p00179
<H1>ふしぎな虫</H1> <p> 䌚接生物孊研究所のA博士は、ずある南の島でふしぎな虫を発芋したした。圢は芋虫のように现長いのですが、ひず぀の䜓節が玉のような圢をしおいるので、糞で぀ないだビヌズ玉のように芋えたす。ふしぎなのは䜓の色に様々なバリ゚ヌションがあるこずず、なかには時間がた぀に぀れお䜓の色が倉っおいく虫がいるこずでした。どの虫の䜓節の色も赀か緑か青のどれかに限られるようですが、1 秒ごずに䜓節の色が倉わっおいき、最埌にはすべおの䜓節が同じ色になっお萜ち着く堎合もあれば、い぀たで埅っおもずっず色が倉わり぀づける堎合もあるようでした。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck200807_1"> <br/><br/> </center> <p> 調べおいくうちに、ふだんはすべおの䜓節が同じ色をしおいるのですが、䜕かに驚いたりしお興奮した埌は䜓節の色が勝手に倉わっおしたうこずがわかりたした。䞀床䜓節の色が倉わっおしたうず、ふたたびすべおの䜓節が同じ色になるたではずっず色が倉わり続けるこずがわかりたした。 </p> <p> A博士はこの虫を䜕匹も捕たえお興奮させおみおは、色が倉わる様子を興味深く芳察しおいたしたが、やがお色が倉化しおいる最䞭の色の倉わり方には次のような芏則性があるこずに気が぀きたした。 </p> <ul> <li>色が倉わるのは、隣り合っおいる色違いの 2぀の䜓節のペア 1組だけが倉わり、他の䜓節の色は倉わらない。ただし、そのようなペアが耇数あるずきに、どのペアの色が倉わるかはあらかじめ予枬できない。</li> <li>そのようなペアは、2぀の䜓節の色のどちらでもない色に同時に倉わる(たずえば、緑ず赀の䜓節が隣り合っおいるずきは、それらが同時に青に倉わる)。</li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pck200807_2"> <br/><br/> </center> <p> 虫の色の倉化を、2秒埌たですべお曞いたものが䞊の図です。図の䞊段のような色をした虫がいるずしたす。このずき、隣り合った色違いの䜓節のペアは 3組あるので、1秒埌には䞭段に䞊べお描いた 3通りの色のどれかに倉わりたす。1秒埌に䞭段巊偎の 2぀のように倉わったずきには、2秒埌にすべおの䜓節が緑色になるこずができたす(図の䞋段の巊偎から 2番目)。 それに察しお、1秒埌に䞭段の1番右のように倉わったずきには、2秒埌にすべおの䜓節が同じ色に倉わるこずはありたせん。 </p> <p> 博士は、目の前にいる虫の䜓節がすべお同じ色になる可胜性があるのか、あるずしたらそうなるのは最短で䜕秒埌なのかを予枬するこずにしたした。 </p> <p> 目の前にいる虫の䜓節の色の䞊びを入力ずし、その虫の䜓節がすべお同じ色になるのに芁する最短の時間を秒単䜍で出力するプログラムを䜜成しおください。ただし、同じ色になる可胜性がないずきは「NA(半角英倧文字)」ず出力しおください。たた、虫の䜓節の色の䞊びは2 以䞊 10 以䞋のr(èµ€)、g(緑)、b(青)からなる文字列で衚されたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺された す。各デヌタセットずしお、 虫の䜓節の情報を衚す぀の文字列が行に䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に、すべおの䜓節の色が同じになるたでに芁する最小時間 (秒単䜍の敎数) たたは NA を行に出力したす。 </pre> <H2>Sample Input</H2> <pre> rbgrg rbbgbbr bgr bgrbrgbr bggrgbgrr gbrggrbggr rrrrr bgbr 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 7 1 6 NA 8 0 4 </pre>
p00483
<H1> 惑星探査(Planetary Exploration) </H1> <p> あなたを乗せた超時空移民船は長旅の末぀いに居䜏可胜ず思われる惑星を発芋したJOI 星ず名付けられたその惑星はその名の通り「ゞャングル(Jungle)」「海(Ocean)」「氷(Ice)」の3 皮類の地圢が入り組んだ過酷な惑星である簡単な調査により居䜏予定地近蟺の地図が䜜成された居䜏予定地は南北<i>M</i> km, 東西<i>N</i> km の長方圢の圢をしおおり 1 km 四方の正方圢の区画に分けられおいる区画は党郚で<i>MN</i> 個あり北から<i>p</i> 行目西から<i>q</i> 列目の区画を(<i>p</i>, <i>q</i>) で衚す北西の角の区画が(1, 1) であり南東の角の区画が(<i>M</i>, <i>N</i>) である各区画の地圢は「ゞャングル」「海」「氷」のいずれかであり「ゞャングル」はJ, 「海」はO, 「氷」はI の英字1 文字で衚される. </p> <p> さお詳现な移䜏蚈画を立おるにあたり K 箇所の長方圢領域内に「ゞャングル」「海」「氷」がそれぞれ䜕区画含たれるかを調べるこずにした </p> <h2>課題</h2> <p> 居䜏予定地の情報ず調査察象ずなる領域の情報が䞎えられたずきそれぞれの領域に぀いお 「ゞャングル」「海」「氷」が䜕区画含たれおいるかを求めるプログラムを䜜成せよ </p> <h2>制限</h2> <p> 1 &le; <i>M</i> &le; 1000 &nbsp;&nbsp;&nbsp;居䜏予定地の南北の長さ(km)<br> 1 &le; <i>N</i> &le; 1000 &nbsp;&nbsp;&nbsp;居䜏予定地の東西の長さ(km)<br> 1 &le; <i>K</i> &le; 100000 &nbsp;&nbsp;&nbsp;調査察象ずなる領域の個数 </p> <h2>入力</h2> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には敎数<i>M</i>, <i>N</i> が空癜を区切りずしお曞かれおおり居䜏予定地が南北に<i>M</i> km 東西に<i>N</i> km の広さであるこずを衚す</li> <li> 2 行目には敎数<i>K</i> が曞かれおおり調査察象ずなる領域の個数を衚す</li> <li> 続く<i>M</i> 行には居䜏予定地の情報が曞かれおいる<i>i</i> + 2 行目(1 &le; <i>i</I> &le; <i>M</i>) には居䜏予定地の北から<i>i</i>行目に䜍眮する<i>N</i> 区画の情報を衚すJOI からなる<i>N</i> 文字の文字列が曞かれおいる</li> <li> 続く<i>K</i> 行には調査察象ずなる領域が曞かれおいる<i>j</i> + <i>M</i> + 2 行目(1 &le; <i>j</i> &le; <i>K</i>) には <i>j</i> 番目の領域を衚す正敎数<i>a<sub>j</sub></i>, <i>b<sub>j</sub></i>, <i>c<sub>j</sub></i>, <i>d<sub>j</sub></i> が空癜を区切りずしお曞かれおいる(<i>a<sub>j</sub></i>, <i>b<sub>j</sub></i>) は調査領域の北西の角の区画を(<i>c<sub>j</sub></i>, <i>d<sub>j</sub></i>) は調査領域の南東の角の区画を衚すただし<i>a<sub>j</sub></i>, <i>b<sub>j</sub></i>, <i>c<sub>j</sub></i>, <i>d<sub>j</sub></i> は1 &le; <i>a<sub>j</sub></i> &le; <i>c<sub>j</sub></i> &le; <i>M</i>, 1 &le; <i>b<sub>j</sub></i> &le; <i>d<sub>j</sub></i> &le; <i>N</i>を満たす </ul> <h2>出力</h2> <p> 暙準出力に調査の結果を衚す<i>K</i> 行を出力せよ出力の<i>j</i> 行目には j 番目の調査領域に含たれる「ゞャングル」(J) の区画数「海」(O) の区画数「氷」(I) の区画数を衚す3 ぀の敎数をこの順に空癜を区切りずしお曞け </p> <h2>採点基準</h2> <p> 採点甚デヌタのうち配点の30%分に぀いおは<i>M</i> &le; 50 か぀<i>K</i> &le; 100 を満たす配点の50%分に぀いおは<i>M</i> &le; 50 を満たす </p> <h2>入出力の䟋</h2> <h3>入力䟋</h3> <pre> 4 7 4 JIOJOIJ IOJOIJO JOIJOOI OOJJIJO 3 5 4 7 2 2 3 6 2 2 2 2 1 1 4 7 </pre> <h3>出力䟋</h3> <pre> 1 3 2 3 5 2 0 1 0 10 11 7 </pre> <br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_planetaryExploration"> <br> <p> この入力䟋では 2 番目の領域は䞊図のように「ゞャングル」を3 区画「海」を5 区画「氷」を2 区画含む </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p01441
<H1><font color="#000">Problem E:</font> Full Text Search</H1> <p> Mr. Don is an administrator of a famous quiz website named QMACloneClone. The users there can submit their own questions to the system as well as search for question texts with arbitrary queries. This search system employs bi-gram search method. </p> <p> The bi-gram search method introduces two phases, namely preprocessing and search: </p> <p> <b>Preprocessing</b> Precompute the set of all the substrings of one or two characters long for each question text. </p> <p> <b>Search</b> Compute the set for the query string in the same way. Then nd the question texts whose precomputed sets completely contain the set constructed from the query. </p> <p> Everything looked fine for a while after the feature was released. However, one of the users found an issue: the search results occasionally contained questions that did not include the query string as-is. Those questions are not likely what the users want. So Mr. Don has started to dig into the issue and asked you for help. For each given search query, your task is to find the length of the shortest question text picked up by the bi-gram method but not containing the query text as its substring. </p> <H2>Input</H2> <p> The input consists of multiple datasets. A dataset is given as a search query on each line. The input ends with a line containing only a hash sign ("<span>#</span>"), which should not be processed. </p> <p> A search query consists of no more than 1,000 and non-empty lowercase and/or uppercase letters. The question texts and queries are case-sensitive. </p> <H2>Output</H2> <p> For each search query, print the minimum possible length of a question text causing the issue. If there is no such question text, print "<span>No Results</span>" in one line (quotes only to clarify). </p> <H2>Sample Input</H2> <pre> a QMAClone acmicpc abcdefgha abcdefgdhbi abcbcd # </pre> <H2>Output for the Sample Input</H2> <pre> No Results 9 7 9 12 6 </pre> <H2>Note</H2> <p> Let's consider the situation that one question text is "CloneQMAC". In this situation, the set computed in the preprocessing phase is {"C", "Cl", "l", "lo", "o", "on", "n", "ne", "e", "eQ", "Q", "QM", "M", "MA", "A", "AC"}. </p> <p> In the testcase 2, our input text (search query) is "QMAClone". Thus the set computed by the program in the search phase is {"Q", "QM", "M", "MA", "A", "AC", "C", "Cl", "l", "lo", "o", "on", "n", "ne", "e"}. </p> <p> Since the first set contains all the elements in the second set, the question text "CloneQMAC" is picked up by the program when the search query is "QMAClone" although the text "CloneQ-MAC" itself does not contain the question text "QMAClone". In addition, we can prove that there's no such text of the length less than 9, thus, the expected output for this search query is 9. </p>
p03186
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has <var>A</var> untasty cookies containing antidotes, <var>B</var> tasty cookies containing antidotes and <var>C</var> tasty cookies containing poison.</p> <p>Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches.</p> <p>Find the maximum number of tasty cookies that Takahashi can eat.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq A,B,C \leq 10^9</var></li> <li><var>A,B</var> and <var>C</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of tasty cookies that Takahashi can eat.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>We can eat all tasty cookies, in the following order:</p> <ul> <li>A tasty cookie containing poison</li> <li>An untasty cookie containing antidotes</li> <li>A tasty cookie containing poison</li> <li>A tasty cookie containing antidotes</li> <li>A tasty cookie containing poison</li> <li>An untasty cookie containing antidotes</li> <li>A tasty cookie containing poison</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 8 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9 </pre></section> </div> </span>
p01011
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1>Problem F: Prize Game</h1> <h2>Problem</h2> <p> 新しいゲヌムセンタヌが開店するこずになった。たくさんのお客さんを取り入れるために、党く新しいプラむズゲヌムを蚭眮するこずになった。 </p> <p> このプラむズゲヌムは<var>R</var>&times;<var>C</var>のグリッドから構成される。各マスは空癜か、1〜18のいずれかの数字が曞かれおいる。プレむダヌはひず぀の空癜のマスを遞択し、そのマスの景品を獲埗できる。ただし、マスにある景品はプレむダヌから芋るこずができない。 </p> <p> スタッフはこのプラむズゲヌムに景品を蚭眮しなければならない。スタッフは以䞋のルヌルが守られおいれば、どのように景品を配眮しおもよい。数字が曞かれおいるマスに぀いお、その数字を<var>x</var>ずするず、その数字を䞭心ずする凞型の範囲の䞭に景品がちょうど<var>x</var>個眮かれおいる必芁がある䞋の図を参照。この凞型の出っ匵っおいる郚分は䞊を向いおいる。たた、景品は空癜のマスのみに眮くこずができ、1぀のマスに3個たで眮くこずが出来る。1個も眮かないこずも可胜である。 </p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2013Aizu_aizuicpc_grid" alt="凞型の範囲の図"><br> 䞭倮の数字が5だった堎合の景品の眮き方の䟋。オレンゞ色の郚分にちょうど蚈5個の景品が眮かれおいる必芁がある。 </p> <p> お客さんに景品の堎所が簡単に掚枬されおは倧損である。そこで、オヌプニングスタッフであるあなたに、䞊蚘ルヌルに則った景品の眮き方の堎合の数を数えおもらいたい。ただし、景品は互いに区別できないものずする。答えは倧きくなる堎合があるので答えの堎合の数を1000000007で割った䜙りを答えなさい。 </p> <h2>Input</h2> <pre> <var>R</var> <var>C</var> <var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,C</sub></var> <var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,C</sub></var> : <var>a<sub>R,1</sub></var> <var>a<sub>R,2</sub></var> ... <var>a<sub>R,C</sub></var> </pre> <p> 1行目に2぀の敎数<var>R</var>,<var>C</var>が空癜区切りで䞎えられる。それぞれグリッドの行数ず列数を衚す。次にプラむズゲヌムを衚すグリッドの情報が<var>R</var>行で䞎えられる。グリッドの情報の<var>i</var>行目には<var>C</var>個の敎数 <var>a<sub>i,j</sub></var>が空癜区切りで䞎えられる。<var>a<sub>i,j</sub></var>はグリッドの<var>i</var>行<var>j</var>列のマス情報を衚す。0の堎合は空癜のマス、それ以倖の堎合は数字<var>a<sub>i,j</var></sub></var>が曞かれたマスを衚す。たた、䞎えられるグリッドは1行目がプラむズゲヌムの䞀番䞊を衚し、<var>R</var>行目が䞀番䞋を衚す。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>R</var>,<var>C</var> &le; 6</li> <li>0 &le; <var>a<sub>i,j</sub></var> &le; 18 (1 &le; <var>i</var> &le; <var>R</var> , 1 &le; <var>j</var> &le; <var>C</var>)</li> </ul> <h2>Output</h2> <p>ルヌルに則った景品の眮き方の堎合の数を1000000007で割った䜙りを1行に出力せよ。</p> <h2>Sample Input 1</h2> <pre> 3 3 0 0 0 0 18 0 0 0 0 </pre> <h2>Sample Output 1</h2> <pre> 16 </pre> <h2>Sample Input 2</h2> <pre> 3 3 0 0 0 0 2 0 0 0 0 </pre> <h2>Sample Output 2</h2> <pre> 336 </pre> <h2>Sample Input 3</h2> <pre> 3 3 0 1 0 1 0 0 0 1 1 </pre> <h2>Sample Output 3</h2> <pre> 1 </pre> <h2>Sample Input 4</h2> <pre> 1 1 1 </pre> <h2>Sample Output 4</h2> <pre> 0 </pre> <h2>Sample Input 5</h2> <pre> 6 6 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> <h2>Sample Output 5</h2> <pre> 80065005 </pre>
p00250
<H1>スコヌン配達蚈画</H1> <p> 愛歌さんの家は、小さな喫茶店を経営しおいたす。愛歌さんのお母さんが焌くスコヌンはずおも矎味しくお、店はずおも繁盛しおいたした。 </p> <p> りェむトレスである愛歌さんの仕事の䞀぀は、次々ず焌き䞊がるスコヌンを、お客様の垭たで届けるこずです。焌きあがったスコヌンはお盆の䞊に乗せられ、カりンタヌの䞊に䞀列に䞊べられたす。<var>i</var> 番目のお盆の䞊に乗っおいるスコヌンの数を <var>K<sub>i</sub></var> ずしたしょう。愛歌さんは、それぞれのお客様にちょうど <var>m</var> 個のスコヌンを運ばなければなりたせん。愛歌さんは䞀床にいく぀でもお盆を持぀こずができ、たた耇数のお盆から 1 人のお客様にスコヌンを配ったり、぀のお盆から耇数のお客様に配っおも構いたせん。 </p> <p> 喫茶店にはずおもたくさんのお客様がやっおくるので、カりンタヌに眮いおある党おのスコヌンを運んでも、党おのお客様に届けるこずはできたせん。しかし、できるだけ倚くのお客様に届けた埌で、<var>m</var> 個に満たない数のスコヌンが䜙るこずもあるかもしれたせん。そのようなスコヌンは、お手䌝いのご耒矎ずしお、愛歌さんが貰えるこずになりたした。 <!--スコヌンはずおも矎味しいので、愛歌さんも倧奜きなのです。--> </p> <p> ここでふず、愛歌さんは考えたした。䞀床に党おのお盆を持぀のではなく、䞀郚のお盆だけを持っおお客様にスコヌンを届けるず、䜙るスコヌンの数も違っおくるはずです。適切にお盆を遞ぶこずで、より倚くのスコヌンが䜙るようにできるかもしれたせん。愛歌さんは、䜜為的にお盆を遞んでいるこずをお母さんに芋抜かれないように、カりンタヌの䞊の1぀の連続した範囲のお盆を遞ぶこずにしたした。たた、残ったお盆はお父さんやお母さんが運んでしたうので、愛歌さんがスコヌンをもらうチャンスは䞀床しかありたせん。 </p> <p> さお、愛歌さんは最倧いく぀のスコヌンを貰えるでしょうか蚈算するプログラムを曞いおください。お盆の数 <var>n</var> は 1 以䞊 30,000以䞋、 <var>m</var> は 1 以䞊 100,000 以䞋です。たた数列の各芁玠 <var>K<sub>i</sub></var> は 0 以䞊 2<sup>32</sup>-1 です。 </p> <h2>入力</h2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットは以䞋のずおりです。 </p> <p> 1行目 <var>n</var> <var>m</var>敎数 敎数半角空癜区切り<br> 2行目 お盆䞊のスコヌンの情報 <var>K<sub>1</sub></var> <var>K<sub>2</sub></var> ... <var>K<sub>n</sub></var>すべお敎数 ; 半角空癜区切り<br> <var>K<sub>i</sub></var>: <var>i</var>番目のお盆䞊のスコヌンの数<br> </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <h2>出力</h2> <p> デヌタセットごずに、もらえるスコヌンの最倧数を行に出力したす。 </p> <h2>入力䟋</h2> <pre> 5 11 11 27 34 45 56 8 5 0 2 1 5 4 6 8 3 5 2 2 4 2 4 6 10 18 10 15 12 31 12 50 11 23 43 181 1 100 5 0 0 </pre> <h2>出力䟋</h2> <pre> 8 4 0 17 5 </pre>
p02797
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are three integers <var>N</var>, <var>K</var>, and <var>S</var>.</p> <p>Find a sequence <var>A_1, A_2, ..., A_N</var> of <var>N</var> integers between <var>1</var> and <var>10^9</var> (inclusive) that satisfies the condition below. We can prove that, under the conditions in Constraints, such a sequence always exists.</p> <ul> <li>There are exactly <var>K</var> pairs <var>(l, r)</var> of integers such that <var>1 \leq l \leq r \leq N</var> and <var>A_l + A_{l + 1} + \cdots + A_r = S</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>0 \leq K \leq N</var></li> <li><var>1 \leq S \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>K</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a sequence satisfying the condition, in the following format:</p> <pre><var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 3 4 </pre> <p>Two pairs <var>(l, r) = (1, 2)</var> and <var>(3, 3)</var> satisfy the condition in the statement.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 3 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>50 50 50 30 70 </pre></section> </div> </span>
p03885
<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>Snuke received two matrices <var>A</var> and <var>B</var> as birthday presents. Each of the matrices is an <var>N</var> by <var>N</var> matrix that consists of only <var>0</var> and <var>1</var>.</p> <p>Then he computed the product of the two matrices, <var>C = AB</var>. Since he performed all computations in modulo two, <var>C</var> was also an <var>N</var> by <var>N</var> matrix that consists of only <var>0</var> and <var>1</var>. For each <var>1 ≀ i, j ≀ N</var>, you are given <var>c_{i, j}</var>, the <var>(i, j)</var>-element of the matrix <var>C</var>.</p> <p>However, Snuke accidentally ate the two matrices <var>A</var> and <var>B</var>, and now he only knows <var>C</var>. Compute the number of possible (ordered) pairs of the two matrices <var>A</var> and <var>B</var>, modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 300</var></li> <li><var>c_{i, j}</var> is either <var>0</var> or <var>1</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>c_{1, 1}</var> <var>...</var> <var>c_{1, N}</var> : <var>c_{N, 1}</var> <var>...</var> <var>c_{N, N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible (ordered) pairs of two matrices <var>A</var> and <var>B</var> (modulo <var>10^9+7</var>).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 1 0 0 1 1 1 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>741992411 </pre></section> </div> </span>
p00600
<H1><font color="#000000">Problem F:</font> Computation of Minimum Length of Pipeline</H1> <p> The Aizu Wakamatsu city office decided to lay a hot water pipeline covering the whole area of the city to heat houses. The pipeline starts from some hot springs and connects every district in the city. The pipeline can fork at a hot spring or a district, but no cycle is allowed. The city office wants to minimize the length of pipeline in order to build it at the least possible expense. </p> <p> Write a program to compute the minimal length of the pipeline. The program reads an input that consists of the following three parts: </p> <H2>Input</H2> <ul> <li>The first part consists of two positive integers in one line, which represent the number <i>s</i> of hot springs and the number <i>d</i> of districts in the city, respectively.</li> <li>The second part consists of <i>s</i> lines: each line contains <i>d</i> non-negative integers. The <i>i</i>-th integer in the <i>j</i>-th line represents the distance between the <i>j</i>-th hot spring and the <i>i</i>-th district if it is non-zero. If zero it means they are not connectable due to an obstacle between them.</li> <li>The third part consists of <i>d</i>-1 lines. The <i>i</i>-th line has <i>d - i</i> non-negative integers. The <i>i</i>-th integer in the <i>j</i>-th line represents the distance between the <i>j</i>-th and the (<i>i</i> + <i>j</i>)-th districts if it is non-zero. The meaning of zero is the same as mentioned above.</li> </ul> <p> For the sake of simplicity, you can assume the following: </p> <ul> <li>The number of hot springs and that of districts do not exceed 50.</li> <li>Each distance is no more than 100.</li> <li>Each line in the input file contains at most 256 characters.</li> <li>Each number is delimited by either whitespace or tab.</li> </ul> <p> The input has several test cases. The input terminate with a line which has two 0. The number of test cases is less than 20. </p> <H2>Output</H2> <p> Output the minimum length of pipeline for each test case. </p> <H2>Sample Input</H2> <pre> 3 5 12 8 25 19 23 9 13 16 0 17 20 14 16 10 22 17 27 18 16 9 7 0 19 5 21 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 38 </pre> <H2>Hint</H2> <p> The first line correspondings to the first part: there are three hot springs and five districts. The following three lines are the second part: the distances between a hot spring and a district. For instance, the distance between the first hot spring and the third district is 25. The last four lines are the third part: the distances between two districts. For instance, the distance between the second and the third districts is 9. The second hot spring and the fourth district are not connectable The second and the fifth districts are not connectable, either. </p>
p01912
<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>H: ゞャンプパヌティ</h1> <h2>問題</h2> <p> ずあるダンスホヌルで $N$ 人の参加するダンスパヌティヌが行われる。 そのダンスホヌルは瞊方向に $H$ 個、暪方向に $W$ 個のグリッドに分けられおおり、 巊䞊を $(0,0)$、䞊から $r$ マス、巊から $c$ マス目のグリッドの座暙を $(r,c)$ ず衚す。 $i$ 番目の参加者の初期䜍眮は $(R_i, C_i)$ であり、$(i,j)$ のグリッドには $(r_{ij}, c_{ij})$ が曞かれおいる。 </p> <p> 各参加者は、無限に続く音楜に合わせお次のように同時に移動を行う。 </p> <ul> <li>その時にいる座暙が $(i,j)$ のずき、$(r_{ij}, c_{ij})$ ぞゞャンプで移動する。</li> </ul> <p> それぞれのグリッドは狭く、2 人以䞊の参加者が同時に同じグリッドに移動するず衝突しおしたう。ただし、空䞭で衝突するこずは無いずする。 これを聞いたあなたは、ゞャンプ埌に 2 人以䞊の参加者が衝突しおしたわないかず心配になった。 そこで、衝突が起こる可胜性があるか、あるならば䜕回目のゞャンプの埌に衝突が起こるかを求めるこずにした。 </p> <h2>制玄</h2> <ul> <li>$1 \le H,W \le 500$</li> <li>$0 \le N \le H \times W$</li> <li>$0 \le r_{ij} < H \ (0 \le i < H, 0 \le j < W)$</li> <li>$0 \le c_{ij} < W \ (0 \le i < H, 0 \le j < W)$</li> <li>$0 \le R_i < H \ (0 \le i < N)$</li> <li>$0 \le C_i < W \ (0 \le i < N)$</li> <li>参加者の初期䜍眮は盞異なる</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <p> $H \ W \ N$<br> $r_{00} \ c_{00} \ \cdots \ r_{0 \ W-1} \ c_{0 \ W-1}$<br> $\vdots$<br> $r_{H-1 \ 0} \ c_{H-1 \ 0} \ \cdots \ r_{H-1 \ W-1} \ c_{H-1 \ W-1}$<br> $R_0 \ C_0$<br> $\vdots$<br> $R_{N-1} \ C_{N-1}$<br> </p> <p> この問題では入力ファむルが非垞に倧きくなるこずがあるこずに泚意せよ。 C++ なら<a href="http://qnighy.hatenablog.com/entry/20110115/1295054750">このペヌゞ</a>を参考にするず良いかもしれない。 </p> <h2>出力</h2> <p> 衝突が起こる堎合は䜕回目のゞャンプの埌に起こるかを 1 行で出力せよ。 そうでない堎合は -1 を出力せよ。 たた、末尟に改行を出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 2 2 2 1 0 0 1 0 0 1 0 0 0 0 1 </pre> <h3>サンプル出力 1</h3> <pre> -1 </pre> <h3>サンプル入力 2</h3> <pre> 2 2 2 1 0 0 1 0 0 1 0 0 0 1 1 </pre> <h3>サンプル出力 2</h3> <pre> 1 </pre>
p00315
<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> 䌚接タカダ垂が生産販売する垃補コヌスタヌは、察称なデザむンでずおも矎しいこずで知られおいる。䌚接タカダ垂では品質管理の䞀環ずしお、補造ラむンにカメラを蚭眮し、各コヌスタヌを撮圱しお埗られた画像が察称になっおいるかを自動で怜蚌しおいる。各コヌスタヌは <var>N</var> &times; <var>N</var> ピクセルの正方圢の癜黒画像ずしお衚される。各ピクセルは癜たたは黒の画像に察応しお、0 たたは 1 の倀をずる。 </p> <p> この床、生産ラむンの機噚曎新にずもなっお、画像解析システムの゜フトりェアを曎新するこずになった。新システムでは、通信デヌタ量を削枛する工倫がなされ、以䞋の方法でカメラから解析システムにデヌタが送られおくる。 </p> <ul> <li> ラむンに流れおくる最初のコヌスタヌの情報は、<var>N</var> &times; <var>N</var> ピクセルの画像ずしおシステムに送られおくる。</li> <li> 枚目以降のコヌスタヌの情報は、぀前に送られた画像ずの差分だけが送られおくる。差分は、「0 から 1 」たたは「1 から 0 」ぞず倉化したピクセルの䜍眮の集合ずしお䞎えられる。</li> </ul> <p> <var>C</var> 枚のコヌスタヌに぀いお、枚目の画像のピクセル情報ず続く <var>C</var> - 1 枚分の差分情報を入力し、䞊䞋察称か぀巊右察称ずなっおいるコヌスタヌの枚数を報告するプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>C</var> <var>N</var> <var>p<sub>11</sub>p<sub>12</sub></var>...<var>p<sub>1N</sub></var> <var>p<sub>21</sub>p<sub>22</sub></var>...<var>p<sub>2N</sub></var> : <var>p<sub>N1</sub>p<sub>N2</sub></var>...<var>p<sub>NN</sub></var> <var>diff<sub>1</sub></var> <var>diff<sub>2</sub></var> : <var>diff<sub>C&minus;1</sub></var> </pre> <p> 行目にコヌスタヌの枚数 <var>C</var> (1 &le; <var>C</var> &le; 10000) ず画像の瞊ず暪のピクセル数 <var>N</var> (2 &le; <var>N</var> &le; 1000 か぀ <var>N</var> は偶数) が䞎えられる。行目から <var>N</var> + 1 行目に最初のコヌスタヌの画像のピクセルを衚す <var>N</var>行 &times; <var>N</var> 列の数字 <var>p<sub>ij</sub></var> (<var>p<sub>ij</sub></var> は 0 たたは 1)が䞎えられる。 </p> <p> <var>N</var> + 2 行目以降に、枚目以降のコヌスタヌの情報を衚す差分 <var>diff<sub>i</sub></var> が次の圢匏で䞎えられる。 </p> <pre> <var>D</var> <var>r<sub>1</sub></var> <var>c<sub>1</sub></var> <var>r<sub>2</sub></var> <var>c<sub>2</sub></var> : <var>r<sub>D</sub></var> <var>c<sub>D</sub></var> </pre> <p> 行目に倉化したピクセルの数 <var>D</var> (0 &le; <var>D</var> &le; 100) が䞎えられる。続く<var>D</var> 行に倉化したピクセルの行ず列の番号をそれぞれ衚す <var>r<sub>i</sub></var> ず<var>c<sub>i</sub></var> (1 &le; <var>r<sub>i</sub></var>, <var>c<sub>i</sub></var> &le; <var>N</var>) が䞎えられる。<var>diff<sub>i</sub></var> の䞭に、同じ䜍眮は回以䞊䞎えられない。 </p> <h2>Output</h2> <p> 䞊䞋察称か぀巊右察称ずなっおいるコヌスタヌの枚数を行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 7 8 00100000 00011000 10111101 01100110 01000110 10111101 00011000 00100100 2 5 3 1 6 1 6 8 3 6 8 3 3 3 6 2 6 3 6 6 0 2 3 8 6 8 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <p> 入力䟋のコヌスタヌの画像を以䞋に瀺す。この堎合、枚目、枚目、枚目のコヌスタヌが䞊䞋察称か぀巊右察称ずなるため、3ず報告する。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_checking" width="680"> </center> <br/> <h2>Sample Input 2</h2> <pre> 1 6 000000 000000 010010 010010 000000 000000 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre> <br/> <h2>Sample Input 3</h2> <pre> 2 2 00 00 4 1 1 1 2 2 1 2 2 </pre> <h2>Sample Output 3</h2> <pre> 2 </pre>
p02328
<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>Largest Rectangle in a Histogram</H1> <p> A histogram is made of a number of contiguous bars, which have same width. </p> <p> For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. </p> <h2>Constraints</h2> <ul> <li> $1 \leq N \leq 10^5$ </li> <li> $0 \leq h_i \leq 10^9$</li> </ul> <h2>Input</h2> <p>The input is given in the following format.</p> <p> $N$<br> $h_1$ $h_2$ ... $h_N$<br> </p> <h2>Output</h2> <p> Print the area of the largest rectangle. </p> <h2>Sample Input 1</h2> <pre> 8 2 1 3 5 3 4 2 1 </pre> <h2>Sample Output 1</h2> <pre> 12 </pre> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_DPL_3_histogram"> </center> <br/> <h2>Sample Input 2</h2> <pre> 3 2 0 1 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre>
p02282
<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>Reconstruction of a Tree</H1> <p> Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree. </p> <H2>Input</H2> <p> In the first line, an integer $n$, which is the number of nodes in the binary tree, is given.<br> In the second line, the sequence of node IDs obtained by the preorder tree walk is given separated by space characters.<br> In the second line, the sequence of node IDs obtained by the inorder tree walk is given separated by space characters. </p> <p> Every node has a unique ID from $1$ to $n$. Note that the root does not always correspond to $1$. </p> <H2>Output</H2> <p> Print the sequence of node IDs obtained by the postorder tree walk in a line. Put a single space character between adjacent IDs. </p> <H2>Constraints</H2> <ul> <li>$1 \leq n \leq 40$</li> </ul> <H2>Sample Input 1</H2> <pre> 5 1 2 3 4 5 3 2 4 1 5 </pre> <H2>Sample Output 1</H2> <pre> 3 4 2 5 1 </pre> <H2>Sample Input 2</H2> <pre> 4 1 2 3 4 1 2 3 4 </pre> <H2>Sample Output 2</H2> <pre> 4 3 2 1 </pre>
p00745
<h1><font color="#000000">Problem F:</font> Tighten Up!</h1> <p> We have a flat panel with two holes. Pins are nailed on its surface. From the back of the panel, a string comes out through one of the holes to the surface. The string is then laid on the surface in a form of a polygonal chain, and goes out to the panel's back through the other hole. Initially, the string does not touch any pins. </p> <p> Figures F-1, F-2, and F-3 show three example layouts of holes, pins and strings. In each layout, white squares and circles denote holes and pins, respectively. A polygonal chain of solid segments denotes the string. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F7" width="400"><br/> Figure F-1: An example layout of holes, pins and a string </center> </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F0" width="400"><br/> Figure F-2: An example layout of holes, pins and a string </center> </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F3" width="400"><br/> Figure F-3: An example layout of holes, pins and a string </center> </p> <p> When we tie a pair of equal weight stones to the both ends of the string, the stones slowly straighten the string until there is no loose part. The string eventually forms a different polygonal chain as it is obstructed by some of the pins. (There are also cases when the string is obstructed by no pins, though.) </p> <p> The string does not hook itself while being straightened. A fully tightened string thus draws a polygonal chain on the surface of the panel, whose vertices are the positions of some pins with the end vertices at the two holes. The layouts in Figures F-1, F-2, and F-3 result in the respective polygonal chains in Figures F-4, F-5, and F-6. Write a program that calculates the length of the tightened polygonal chain. </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F8" width="400"><br/> Figure F-4: Tightened polygonal chains from the example in Figure F-1. </center> </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F1" width="400"><br/> Figure F-5: Tightened polygonal chains from the example in Figure F-2. </center> </p> <p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2009F6" width="400"><br/> Figure F-6: Tightened polygonal chains from the example in Figure F-3. </center> </p> <p> Note that the strings, pins and holes are thin enough so that you can ignore their diameters. </p> <!-- end en only --> <h3>Input</h3> <p> The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset gives the initial shape of the string (i.e., the positions of holes and vertices) and the positions of pins in the following format. </p> <blockquote> <i>m n</i> <br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br> ... <br> <i>x<sub>l</sub> y<sub>l</sub></i> <br> </blockquote> <!-- begin en only --> <p> The first line has two integers <i>m</i> and <i>n</i> (2 &le; <i>m</i> &le; 100, 0 &le; <i>n</i> &le; 100), representing the number of vertices including two holes that give the initial string shape (<i>m</i>) and the number of pins (<i>n</i>). Each of the following <i>l</i> = <i>m</i> + <i>n</i> lines has two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> (0 &le; <i>x<sub>i</sub></i> &le; 1000, 0 &le; <i>y<sub>i</sub></i> &le; 1000), representing a position <i>P<sub>i</sub></i> = (<i>x<sub>i</sub></i> ,<i>y<sub>i</sub></i> ) on the surface of the panel. <ul> <li>Positions <i>P</i><sub>1</sub>, ..., <i>P<sub>m</sub></i> give the initial shape of the string; i.e., the two holes are at <i>P</i><sub>1</sub> and <i>P<sub>m</sub></i> , and the string's shape is a polygonal chain whose vertices are <i>P<sub>i</sub></i> (<i>i</i> = 1, ..., <i>m</i>), in this order. <li>Positions <i>P</i><sub><i>m</i>+1</sub>, ..., <i>P</i><sub><i>m</i>+<i>n</i></sub> are the positions of the pins. </ul> </p> <!-- end en only --> </p> <!-- begin en only --> <p> Note that no two points are at the same position. No three points are exactly on a straight line. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, the length of the part of the tightened string that remains on the surface of the panel should be output in a line. No extra characters should appear in the output. </p> <!-- end en only --> <!-- begin en only --> <p> No lengths in the output should have an error greater than 0.001. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 6 16 5 4 11 988 474 975 459 16 985 12 984 982 242 227 140 266 45 410 92 570 237 644 370 567 406 424 336 290 756 220 634 251 511 404 575 554 726 643 868 571 907 403 845 283 10 4 261 196 943 289 859 925 56 822 112 383 514 0 1000 457 514 1000 0 485 233 224 710 242 850 654 485 915 140 663 26 5 0 953 180 0 299 501 37 301 325 124 162 507 84 140 913 409 635 157 645 555 894 229 598 223 783 514 765 137 599 445 695 126 859 462 599 312 838 167 708 563 565 258 945 283 251 454 125 111 28 469 1000 1000 185 319 717 296 9 315 372 249 203 528 15 15 200 247 859 597 340 134 967 247 421 623 1000 427 751 1000 102 737 448 0 978 510 556 907 0 582 627 201 697 963 616 608 345 819 810 809 437 706 702 695 448 474 605 474 329 355 691 350 816 231 313 216 864 360 772 278 756 747 529 639 513 525 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 2257.0518296609 3609.92159564177 2195.83727086364 3619.77160684813 </pre>
p02778
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Given is a string <var>S</var>. Replace every character in <var>S</var> with <code>x</code> and print the result.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>S</var> is a string consisting of lowercase English letters.</li> <li>The length of <var>S</var> is between <var>1</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>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Replace every character in <var>S</var> with <code>x</code> and print the result.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>sardine </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>xxxxxxx </pre> <p>Replacing every character in <var>S</var> with <code>x</code> results in <code>xxxxxxx</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>xxxx </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>xxxx </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>gone </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>xxxx </pre></section> </div> </span>
p01857
<h1 id="f-卵-eggs">F : 卵 / Eggs</h1> <h2 id="問題文">問題文</h2> <p><var>1</var> か月前のこずである 小孊生の肉西君は倏䌑みの宿題をやっおいなかった そこで自由研究は家にあった卵の匷床を調べるこずにした</p> <p>この研究においお卵を高さ <var>H</var> から萜ずしおも割れず 高さ <var>H+1</var> から萜ずすず割れるずき その卵の匷床は <var>H</var> であるず定矩する ここで <var>H</var> は非負敎数であり非負敎数以倖の高さから萜ずすこずは無いずする 肉西くんは卵を <var>1</var> ぀萜䞋させる実隓を行う 実隓の結果は割れるか割れないかのいずれかである たた卵の匷床は党お同じである぀たりどの卵を甚いおも実隓の結果は同じである</p> <p>肉西くんは高さ <var>1</var> から <var>N</var> たでの敎数の高さの段からなる階段ず 匷床が䞍明な <var>E</var> 個の卵を甚意した 高さ <var>0</var> では割れず高さ <var>N+1</var> では割れるずいうこずは既にわかっおいる 肉西くんは各段ず同じ高さから地面に向かっお萜ずしその床に卵が割れたか割れなかったかを調べる このずき割れた卵は二床ず䜿えないが割れなかった堎合は再利甚できる この実隓を卵が残っおいる限り続けるこずができる 䜕床か実隓を繰り返し䞊に定めた <var>H</var> が求たったずき卵の匷床が求たったずする</p> <p>倏䌑み終了たで埌数日しか無い 最小の回数で実隓を終わらせないず間に合わない そこで肉西くんの兄であるあなたは卵の匷床を知るために 萜ずす回数が少なくなるように最適な方法をずった堎合に 必芁な実隓回数の最倧倀を求めるプログラムを曞くこずにした</p> <h2 id="入力">入力</h2> <pre> <var>T</var> <var>N_1 E_1</var> 
 <var>N_T</var> <var>E_T</var> </pre> <p>1 ぀のファむルに耇数のテストケヌスが含たれる <var>1</var> 行目に敎数 <var>T</var> が䞎えられる <var>1+i</var> 行目に <var>i</var> 番目のテストケヌス <var>E_i, N_i</var> が䞎えられる</p> <h2 id="制玄">制玄</h2> <ul> <li>敎数である</li> <li><var>1 &le; T &le; 1000</var></li> <li><var>1 &le; N_i &le; 10^{18}</var></li> <li><var>1 &le; E_i &le; 50</var></li> <li>出力が <var>50</var> を超えるような入力は含たれない</li> </ul> <h2 id="出力">出力</h2> <p><var>i</var> 番目のテストケヌスに察する答えを <var>i</var> 行目に出力せよ 党䜓で <var>T</var> 行にわたる</p> <h2 id="サンプル">サンプル</h2> <h3 id="サンプル入力1">サンプル入力1</h3> <pre> 3 5 1 5 2 1 2 </pre> <h3 id="サンプル出力1">サンプル出力1</h3> <pre> 5 3 1 </pre> <ul> <li><var>1</var> ぀目の堎合 <ul> <li>卵が <var>1</var> ぀しかないため <var>1</var> 段目から順に萜ずしおいくしかない</li> </ul></li> <li><var>2</var> ぀目の堎合 <ul> <li>たず <var>2</var> 段目から萜ずす</li> <li><var>2</var> 段目から萜ずしお割れた堎合 <var>1</var> 段目から萜ずす</li> <li><var>2</var> 段目から萜ずしお割れなかった堎合 <var>4</var> 段目から萜ずす</li> <li><var>1</var> 段目から萜ずしお割れた堎合実隓終了</li> <li><var>1</var> 段目から萜ずしお割れなかった堎合実隓終了</li> <li><var>4</var> 段目から萜ずしお割れた堎合 <var>3</var> 段目から萜ずす</li> <li><var>4</var> 段目から萜ずしお割れなかった堎合 <var>5</var> 段目から萜ずす</li> <li><var>3</var> 段目から萜ずしお割れた堎合実隓終了</li> <li><var>3</var> 段目から萜ずしお割れなかった堎合実隓終了</li> <li><var>5</var> 段目から萜ずしお割れた堎合実隓終了</li> <li><var>5</var> 段目から萜ずしお割れなかった堎合実隓終了</li> </ul></li> <li><var>3</var> ぀目の堎合 <ul> <li><var>1</var> 段目から萜ずしお実隓終了</li> </ul></li> </ul> <!-- - - - end nicebady - - - -->
p03539
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider the following game:</p> <ul> <li>The game is played using a row of <var>N</var> squares and many stones.</li> <li>First, <var>a_i</var> stones are put in Square <var>i\ (1 \leq i \leq N)</var>.</li> <li>A player can perform the following operation as many time as desired: "Select an integer <var>i</var> such that Square <var>i</var> contains exactly <var>i</var> stones. Remove all the stones from Square <var>i</var>, and add one stone to each of the <var>i-1</var> squares from Square <var>1</var> to Square <var>i-1</var>."</li> <li>The final score of the player is the total number of the stones remaining in the squares.</li> </ul> <p>For a sequence <var>a</var> of length <var>N</var>, let <var>f(a)</var> be the minimum score that can be obtained when the game is played on <var>a</var>.</p> <p>Find the sum of <var>f(a)</var> over all sequences <var>a</var> of length <var>N</var> where each element is between <var>0</var> and <var>K</var> (inclusive). Since it can be extremely large, find the answer modulo <var>1000000007 (= 10^9+7)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq K \leq N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of <var>f(a)</var> modulo <var>1000000007 (= 10^9+7)</var>.</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>10 </pre> <p>There are nine sequences of length <var>2</var> where each element is between <var>0</var> and <var>2</var>. For each of them, the value of <var>f(a)</var> and how to achieve it is as follows:</p> <ul> <li><var>f(\{0,0\})</var>: <var>0</var> (Nothing can be done)</li> <li><var>f(\{0,1\})</var>: <var>1</var> (Nothing can be done)</li> <li><var>f(\{0,2\})</var>: <var>0</var> (Select Square <var>2</var>, then Square <var>1</var>)</li> <li><var>f(\{1,0\})</var>: <var>0</var> (Select Square <var>1</var>)</li> <li><var>f(\{1,1\})</var>: <var>1</var> (Select Square <var>1</var>)</li> <li><var>f(\{1,2\})</var>: <var>0</var> (Select Square <var>1</var>, Square <var>2</var>, then Square <var>1</var>)</li> <li><var>f(\{2,0\})</var>: <var>2</var> (Nothing can be done)</li> <li><var>f(\{2,1\})</var>: <var>3</var> (Nothing can be done)</li> <li><var>f(\{2,2\})</var>: <var>3</var> (Select Square <var>2</var>)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>20 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>983853488 </pre></section> </div> </span>
p01504
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>AYBABTU</H1> <p> There is a tree that has <var>n</var> nodes and <var>n-1</var> edges. There are military bases on <var>t</var> out of the <var>n</var> nodes. We want to disconnect the bases as much as possible by destroying <var>k</var> edges. The tree will be split into <var>k+1</var> regions when we destroy <var>k</var> edges. Given the purpose to disconnect the bases, we only consider to split in a way that each of these <var>k+1</var> regions has at least one base. When we destroy an edge, we must pay destroying cost. Find the minimum destroying cost to split the tree. </p> <H2>Input</H2> <p> The input consists of multiple data sets. Each data set has the following format. The first line consists of three integers <var>n</var>, <var>t</var>, and <var>k</var> (<var>1 \leq n \leq 10,000</var>, <var>1 \leq t \leq n</var>, <var>0 \leq k \leq t-1</var>). Each of the next <var>n-1</var> lines consists of three integers representing an edge. The first two integers represent node numbers connected by the edge. A node number is a positive integer less than or equal to <var>n</var>. The last one integer represents destroying cost. Destroying cost is a non-negative integer less than or equal to 10,000. The next <var>t</var> lines contain a distinct list of integers one in each line, and represent the list of nodes with bases. The input ends with a line containing three zeros, which should not be processed. </p> <H2>Output</H2> <p> For each test case, print its case number and the minimum destroying cost to split the tree with the case number. </p> <H2>Sample Input</H2> <pre> 2 2 1 1 2 1 1 2 4 3 2 1 2 1 1 3 2 1 4 3 2 3 4 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 1 Case 2: 3 </pre>
p03493
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has a grid consisting of three squares numbered <var>1</var>, <var>2</var> and <var>3</var>. In each square, either <code>0</code> or <code>1</code> is written. The number written in Square <var>i</var> is <var>s_i</var>.</p> <p>Snuke will place a marble on each square that says <code>1</code>. Find the number of squares on which Snuke will place a marble.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>Each of <var>s_1</var>, <var>s_2</var> and <var>s_3</var> is either <code>1</code> or <code>0</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s_{1}s_{2}s_{3}</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>101 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <ul> <li>A marble will be placed on Square <var>1</var> and <var>3</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <ul> <li>No marble will be placed on any square.</li> </ul></section> </div> </span>
p03169
<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> dishes, numbered <var>1, 2, \ldots, N</var>. Initially, for each <var>i</var> (<var>1 \leq i \leq N</var>), Dish <var>i</var> has <var>a_i</var> (<var>1 \leq a_i \leq 3</var>) pieces of sushi on it.</p> <p>Taro will perform the following operation repeatedly until all the pieces of sushi are eaten:</p> <ul> <li>Roll a die that shows the numbers <var>1, 2, \ldots, N</var> with equal probabilities, and let <var>i</var> be the outcome. If there are some pieces of sushi on Dish <var>i</var>, eat one of them; if there is none, do nothing.</li> </ul> <p>Find the expected number of times the operation is performed before all the pieces of sushi are eaten.</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 300</var></li> <li><var>1 \leq a_i \leq 3</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the expected number of times the operation is performed before all the pieces of sushi are eaten. The output is considered correct when the relative difference is not greater than <var>10^{-9}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5.5 </pre> <p>The expected number of operations before the first piece of sushi is eaten, is <var>1</var>. After that, the expected number of operations before the second sushi is eaten, is <var>1.5</var>. After that, the expected number of operations before the third sushi is eaten, is <var>3</var>. Thus, the expected total number of operations is <var>1 + 1.5 + 3 = 5.5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>Outputs such as <code>3.00</code>, <code>3.000000003</code> and <code>2.999999997</code> will also be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4.5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 1 3 2 3 3 2 3 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>54.48064457488221 </pre></section> </div> </span>
p01154
<H1><font color="#000">Problem I:</font> Light The Room</H1> <p> You are given plans of rooms of polygonal shapes. The walls of the rooms on the plans are placed parallel to either <i>x</i>-axis or <i>y</i>-axis. In addition, the walls are made of special materials so they reflect light from sources as mirrors do, but only once. In other words, the walls do not reflect light already reflected at another point of the walls. </p> <p> Now we have each room furnished with one lamp. Walls will be illuminated by the lamp directly or indirectly. However, since the walls reflect the light only once, some part of the walls may not be illuminated. </p> <p> You are requested to write a program that calculates the total length of <i>unilluminated</i> part of the walls. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_lightTheRoom"> <p>Figure 10: The room given as the second case in Sample Input</p> </center> <H2>Input</H2> <p> The input consists of multiple test cases. </p> <p> The first line of each case contains a single positive even integer <i>N</i> (4 &le; <i>N</i> &le; 20), which indicates the number of the corners. The following <i>N</i> lines describe the corners counterclockwise. The i-th line contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> , where (<i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> ) indicates the coordinates of the <i>i</i>-th corner. The last line of the case contains <i>x'</i> and <i>y'</i> , where (<i>x'</i> , <i>y'</i> ) indicates the coordinates of the lamp. </p> <p> To make the problem simple, you may assume that the input meets the following conditions: </p> <ul> <li>All coordinate values are integers not greater than 100 in their absolute values.</li> <li>No two walls intersect or touch except for their ends.</li> <li>The walls do not intersect nor touch each other.</li> <li>The walls turn each corner by a right angle.</li> <li>The lamp exists strictly inside the room off the wall.</li> <li>The x-coordinate of the lamp does not coincide with that of any wall; neither does the y-coordinate.</li> </ul> <p> The input is terminated by a line containing a single zero. </p> <H2>Output</H2> <p> For each case, output the length of the unilluminated part in one line. The output value may have an arbitrary number of decimal digits, but may not contain an error greater than 10<sup>-3</sup> . </p> <H2>Sample Input</H2> <pre> 4 0 0 2 0 2 2 0 2 1 1 6 2 2 2 5 0 5 0 0 5 0 5 2 1 4 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.000 3.000 </pre>
p01343
<H1><font color="#000">Problem E: </font>Psychic Accelerator</H1> <p> In the west of Tokyo, there is a city named “Academy City.” There are many schools and laboratories to develop psychics in Academy City. </p> <p> You are a psychic student of a school in Academy City. Your psychic ability is to give acceleration to a certain object. </p> <p> You can use your psychic ability anytime and anywhere, but there are constraints. If the object remains stationary, you can give acceleration to the object in any direction. If the object is moving, you can give acceleration to the object only in 1) the direction the object is moving to, 2) the direction opposite to it, or 3) the direction perpendicular to it. </p> <p> Today’s training menu is to move the object along a given course. For simplicity you can regard the course as consisting of line segments and circular arcs in a 2-dimensional space. The course has no branching. All segments and arcs are connected smoothly, i.e. there are no sharp corners. </p> <p> In the beginning, the object is placed at the starting point of the first line segment. You have to move the object to the ending point of the last line segment along the course and stop the object at that point by controlling its acceleration properly. Before the training, a coach ordered you to simulate the minimum time to move the object from the starting point to the ending point. </p> <p> Your task is to write a program which reads the shape of the course and the maximum acceleration <i>a<sub>max</sub></i> you can give to the object and calculates the minimum time to move the object from the starting point to the ending point. </p> <p> The object follows basic physical laws. When the object is moving straight in some direction, with acceleration either forward or backward, the following equations hold: </p> <center> <p> <i>v</i> = <i>v</i><sub>0</sub> + <i>at</i> </p> </center> <p> and </p> <center> <p> <i>s</i> = <i>v</i><sub>0</sub><i>t</i> + (1/2)<i>at</i><sup>2</sup> </p> </center> <p> where <i>v</i>, <i>s</i>, <i>v</i><sub>0</sub>, <i>a</i>, and <i>t</i> are the velocity, the distance from the starting point, the initial velocity (i.e. the velocity at the starting point), the acceleration, and the time the object has been moving in that direction, respectively. Note that they can be simplified as follows: </p> <center> <p> <i>v</i><sup>2</sup> &minus; <i>v</i><sub>0</sub><sup>2</sup> = 2<i>as</i> </p> </center> <p> When the object is moving along an arc, with acceleration to the centroid, the following equations hold: </p> <center> <p> <i>a</i> = <i>v</i><sup>2</sup>/<i>r</i> </p> </center> <p> wher <i>v</i>, <i>a</i>, and <i>r</i> are the velocity, the acceleration, and the radius of the arc, respectively. Note that the object cannot change the velocity due to the criteria on your psychic ability. </p> <H2>Input</H2> <p> The input has the following format: </p> <p> <i>N a<sub>max</sub></i><br> <i>x</i><sub><i>a</i>,1</sub> <i>y</i><sub><i>a</i>,1</sub> <i>x</i><sub><i>b</i>,1</sub> <i>y</i><sub><i>b</i></sub>,1</sub><br> <i>x</i><sub><i>a</i>,2</sub> <i>y</i><sub><i>a</i>,2</sub> <i>x</i><sub><i>b</i>,2</sub> <i>y</i><sub><i>b</i></sub>,2</sub><br> .<br> .<br> .<br> </p> <p> <i>N</i> is the number of line segments; <i>a<sub>max</sub></i> is the maximum acceleration you can give to the object; (<i>x<sub>a,i</sub></i>, <i>y<sub>a,i</sub></i>) and (<i>x<sub>b,i</sub></i>, <i>y<sub>b,i</sub></i>) are the starting point and the ending point of the <i>i</i>-th line segment, respectively. The given course may have crosses but you cannot change the direction there. </p> <p> The input meets the following constraints: 0 &lt; <i>N</I> &le; 40000, 1 &le; <i>a<sub>max</sub></i> &le; 100, and -100 &le; <i>x<sub>a</sub>i</i>, <i>y<sub>a</sub>i</i>, <i>x<sub>b</sub>i</i>, <i>y<sub>b</sub>i</i> &le; 100. </p> <H2>Output</H2> <p> Print the minimum time to move the object from the starting point to the ending point with an relative or absolute error of at most 10<sup>-6</sup>. You may output any number of digits after the decimal point. </p> <H2>Sample Input 1</H2> <pre> 2 1 0 0 1 0 1 1 0 1 </pre> <H2>Output for the Sample Input 1</H2> <pre> 5.2793638507 </pre> <H2>Sample Input 2</H2> <pre> 1 1 0 0 2 0 </pre> <H2>Output for the Sample Input 2</H2> <pre> 2.8284271082 </pre> <H2>Sample Input 3</H2> <pre> 3 2 0 0 2 0 1 -1 1 2 0 1 2 1 </pre> <H2>Output for the Sample Input 3</H2> <pre> 11.1364603512 </pre>
p02996
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.</p> <p>Let the current time be time <var>0</var>. Kizahashi has <var>N</var> jobs numbered <var>1</var> to <var>N</var>.</p> <p>It takes <var>A_i</var> units of time for Kizahashi to complete Job <var>i</var>. The deadline for Job <var>i</var> is time <var>B_i</var>, and he must complete the job before or at this time.</p> <p>Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.</p> <p>Can Kizahashi complete all the jobs in time? If he can, print <code>Yes</code>; if he cannot, print <code>No</code>.</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 2 \times 10^5</var></li> <li><var>1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>B_1</var> <var>.</var> <var>.</var> <var>.</var> <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If Kizahashi can complete all the jobs in time, print <code>Yes</code>; if he cannot, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 4 1 9 1 8 4 9 3 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>He can complete all the jobs in time by, for example, doing them in the following order:</p> <ul> <li>Do Job <var>2</var> from time <var>0</var> to <var>1</var>.</li> <li>Do Job <var>1</var> from time <var>1</var> to <var>3</var>.</li> <li>Do Job <var>4</var> from time <var>3</var> to <var>7</var>.</li> <li>Do Job <var>3</var> from time <var>7</var> to <var>8</var>.</li> <li>Do Job <var>5</var> from time <var>8</var> to <var>11</var>.</li> </ul> <p>Note that it is fine to complete Job <var>3</var> exactly at the deadline, time <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 334 1000 334 1000 334 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>He cannot complete all the jobs in time, no matter what order he does them in.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>30 384 8895 1725 9791 170 1024 4 11105 2 6 578 1815 702 3352 143 5141 1420 6980 24 1602 849 999 76 7586 85 5570 444 4991 719 11090 470 10708 1137 4547 455 9003 110 9901 15 8578 368 3692 104 1286 3 4 366 12143 7 6649 610 2374 152 7324 4 7042 292 11386 334 5720 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
p03684
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> towns on a plane. The <var>i</var>-th town is located at the coordinates <var>(x_i,y_i)</var>. There may be more than one town at the same coordinates.</p> <p>You can build a road between two towns at coordinates <var>(a,b)</var> and <var>(c,d)</var> for a cost of <var>min(|a-c|,|b-d|)</var> yen (the currency of Japan). It is not possible to build other types of roads.</p> <p>Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ N ≀ 10^5</var></li> <li><var>0 ≀ x_i,y_i ≀ 10^9</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 5 3 9 7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>Build a road between Towns <var>1</var> and <var>2</var>, and another between Towns <var>2</var> and <var>3</var>. The total cost is <var>2+1=3</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 8 3 4 9 12 19 18 1 13 5 7 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre></section> </div> </span>
p00801
<H1><font color="#000">Problem F:</font> Numoeba</H1> <p> A scientist discovered a strange variation of amoeba. The scientist named it <i>numoeba</i>. A numoeba, though it looks like an amoeba, is actually a community of cells, which always forms a tree. </p> <p> The scientist called the cell <i>leader</i> that is at the root position of the tree. For example, in Fig. 1, the leader is <i>A</i>. In a numoeba, its leader may change time to time. For example, if <i>E</i> gets new leadership, the tree in Fig. 1 becomes one in Fig. 2. We will use the terms root, leaf, parent, child and subtree for a numoeba as defined in the graph theory. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba1"> </center> <p> Numoeba changes its physical structure at every biological clock by cell division and cell death. The leader may change depending on this physical change. </p> <p> The most astonishing fact about the numoeba cell is that it contains an organic unit called <i>numbosome</i>, which represents an odd integer within the range from 1 to 12,345,677. At every biological clock, the value of a numbosome changes from n to a new value as follows: </p> <ol> <li> The maximum odd factor of 3<i>n</i> + 1 is calculated. This value can be obtained from 3<i>n</i> + 1 by repeating division by 2 while even.</li> <li> If the resulting integer is greater than 12,345,678, then it is subtracted by 12,345,678.</li> </ol> <p> For example, if the numbosome value of a cell is 13, 13 &times; 3 + 1 = 40 is divided by 2<sup>3</sup> = 8 and a new numbosome value 5 is obtained. If the numbosome value of a cell is 11,111,111, it changes to 4,320,989, instead of 16,666,667. If 3<i>n</i> + 1 is a power of 2, yielding 1 as the result, it signifies the death of the cell as will be described below. </p> <p> At every biological clock, the next numbosome value of every cell is calculated and the fate of the cell and thereby the fate of numoeba is determined according to the following steps. </p> <ol> <li> A cell that is a leaf and increases its numbosome value is designated as a <i>candidate</i> leaf.<br> A cell dies if its numbosome value becomes 1. If the dying cell is the leader of the numoeba, the numoeba dies as a whole. Otherwise, all the cells in the subtree from the dying cell (including itself) die. However, there is an exceptional case where the cells in the subtree do not necessarily die; if there is only one child cell of the dying non-leader cell, the child cell will replace the dying cell. Thus, a straight chain simply shrinks if its non-leader constituent dies. <br> For example, consider a numoeba with the leader A below. <br> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba2"> </center> <br> If the leader A dies in (1), the numoeba dies.<br> If the cell D dies in (1), (1) will be as follows. <br> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba3"> </center> <br> And, if the cell E dies in (1), (1) will be as follows.<br> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba4"> </center> <br> Note that this procedure is executed sequentially, top-down from the root of the numoeba to leaves. If the cells <i>E</i> and <i>F</i> will die in (1), the death of <i>F</i> is not detected at the time the procedure examines the cell <i>E</i>. The numoeba, therefore, becomes (3). One should not consider in such a way that the death of <i>F</i> makes <i>G</i> the only child of <i>E</i>, and, therefore, <i>G</i> will replace the dying <i>E</i>.</li> <li> If a <i>candidate</i> leaf survives with the numbosome value of <i>n</i>, it spawns a cell as its child, thereby a new leaf, whose numbosome value is the least odd integer greater than or equal to (<i>n</i> + 1)/2. We call the child leaf bonus.</li> <li> Finally, a new leader of the numoeba is selected, who has a unique maximum numbosome value among all the constituent cells. The tree structure of the numoeba is changed so that the new leader is its root, like what is shown in Fig. 1 and Fig. 2. Note that the parent-child relationship of some cells may be reversed by this leader change. When a new leader of a unique maximum numbosome value, say <i>m</i>, is selected (it may be the same cell as the previous leader), it spawns a cell as its child with the numbosome whose value is the greatest odd integer less than or equal to (<i>m</i> + 1)/2. We call the child <i>leader bonus</i>. If there is more than one cell of the same maximum numbosome value, however, the leader does not change for the next period, and there is no leader bonus. </li> </ol> <p> The following illustrates the growth and death of a numoeba starting from a single cell seed with the numbosome value 15, which plays both roles of the leader and a leaf at the start. In the figure, a cell is nicknamed with its numbosome value. Note that the order of the children of a parent is irrelevant. </p> <br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba5"><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba6"> <br> <p> The numoeba continues changing its structure, and at clock 104, it looks as follows. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_numoeba7"><br> </center> <br> <p> Here, two ambitious 2429's could not become the leader. The leader 5 will die without promoting these talented cells at the next clock. This alludes the fragility of a big organization. </p> <p> And, the numoeba dies at clock 105. </p> <p> Your job is to write a program that outputs statistics about the life of numoebae that start from a single cell seed at clock zero. </p> <H2>Input</H2> <p> A sequence of odd integers, each in a line. Each odd integer <i>k<sub>i</sub></i> (3 &le; <i>k<sub>i</sub></i> &le; 9,999) indicates the initial numbosome value of the starting cell. This sequence is terminated by a zero. </p> <H2>Output</H2> <p> A sequence of pairs of integers:an integer that represents the numoeba's life time and an integer that represents the maximum number of constituent cells in its life. These two integers should be separated by a space character, and each pair should be followed immediately by a newline. Here, the lifetime means the clock when the numoeba dies. </p> <p> You can use the fact that the life time is less than 500, and that the number of cells does not exceed 500 in any time, for any seed value given in the input. You might guess that the program would consume a lot of memory. It is true in general. But, don't mind. Referees will use a test data set consisting of no more than 10 starting values, and, starting from any of the those values, the total numbers of cells spawned during the lifetime will not exceed 5000. </p> <H2>Sample Input</H2> <pre> 3 5 7 15 655 2711 6395 7195 8465 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 3 1 1 9 11 105 65 398 332 415 332 430 332 428 332 190 421 </pre>
p01713
<h1>問題 B : Evacuation Route</h1> <h2>問題文</h2> <p> 日本では防灜研究が盛んに行われおおり近幎その重芁性がたすたす増しおいる 避難経路の評䟡も重芁な研究のひず぀である 今回は盎線状の通路の安党評䟡を行う </p> <p> 通路は <var>W</var> 個のナニットに分けられおおり䞀方の端のナニットからもう䞀方の端のナニットたで <var>0, &thinsp;1, &thinsp;2, &thinsp;
&thinsp;, &thinsp;W-1</var> の番号が぀けられおいる 通路内の各ナニットには入口の扉出口の扉防火扉のいずれか1぀が存圚する 入り口の扉出口の扉防火扉はそれぞれ通路内に耇数個存圚しうる </p> <p> この問題では時刻 <var>t=0</var> で火灜が発生したず想定する それにより通路の倖郚にいお避難しようずしおいる人々が入口の扉を通じお通路ぞ入りより安党な堎所ぞ出るために出口の扉ぞ脱出しようずするものずする 避難䞭のそれぞれの人は単䜍時刻ごずに 1 ぀のナニットを移動するか今のナニットに留たるこずができる すなわち時刻 <var>t</var> にある人がナニット <var>i</var> にいたずするずきその人は時刻 <var>t+1</var> ではナニット <var>i-1, &thinsp;i, &thinsp; i+1</var> の3぀の数字のうち <var>0</var> 以䞊 <var>W-1</var> 以䞋であるものを遞択しその番号のナニットぞ移動するこずができる 防火扉があるナニットはある䞀定時刻以降になるず完党に遮断されおしたい避難䞭の人々はそのナニットに立ち入りできなくなるたたそのナニット内に居た人々もそこから他のナニットに移動できなくなっおしたう </p> <p> この問題における目的はそれぞれの扉の情報が䞎えられるので避難䞭の人々が最適に行動した時に最倧で䜕人が出口の扉ぞたどり着けるか蚈算するこずである </p> <p> 通路の情報が<var>W</var>個の敎数<var>a_i</var>で䞎えられる </p> <ul> <li><var>a_i = 0</var>のずき<var>i</var> 番目のナニットが出口の扉であるこずをあらわす</li> <li><var>a_i < 0</var>のずき<var>i</var> 番目のナニットが防火扉により時間 <var>|a_i|</var> 以降出入りできなくなるこずを衚す</li> <li><var>a_i > 0</var>のずき時刻 <var>t=0,&thinsp;1,&thinsp;2,&thinsp;
&thinsp;,&thinsp;a_{i}-1</var> のそれぞれにおいおちょうど䞀人の人が <var>i</var> 番目のナニットに珟れる時刻 <var>t</var> に珟れた人は時刻 <var>t+1</var> 以降から移動を開始する</li> </ul> <p> なお1぀のナニットに耇数の人々が存圚しおもかたわない </p> <p> 出口の扉ぞたどり着ける最倧の人数を求めよ </p> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる <pre> <var>W</var> <var>a_0</var> <var>a_1</var> <var>...</var> <var>a_{W-1}</var> </pre> <h2>出力圢匏</h2> <p> 最倧人数を1行で出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; W &le; 10^5</var></li> <li><var>|a_i| &thinsp; &le; 10^4</var></li> <li>入力倀はすべお敎数である</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 7 2 0 -2 3 2 -2 0 </pre> <h3>出力䟋 1</h3> <pre> 4 </pre> <p> <var>0, &thinsp; 3, &thinsp; 5</var>番目のナニットに入り口の扉があり <var>1, &thinsp; 6</var>番目のナニットに出口の扉がある<br> <var>0</var>番目のナニットからは<var>1</var>番目のナニットぞ人出るこずができる<br> <var>3</var>番目のナニットからは<var>1</var>番目のナニットぞ人出るこずができる<br> <var>5</var>番目のナニットからは<var>6</var>番目のナニットぞ人出るこずができる<br> よっお合わせお人が出口ぞずたどり着ける </p> <h3>入力䟋 2</h3> <pre> 4 1 1 1 1 </pre> <h3>出力䟋 2</h3> <pre> 0 </pre> <p> 出口がないので誰も脱出できない </p> <h3>入力䟋 3</h3> <pre> 9 10 -10 10 -10 10 -10 10 -10 0 </pre> <h3>出力䟋 3</h3> <pre> 24 </pre>
p00552
<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>æ–­å±€(Geologic Fault)</h2> <p> 遠い昔IOI 文明ずいう高床な文明が栄えおいたしかし火山の噎火によりこの高床な文明は぀いに滅んでしたったIOI 文明は盎線状の河川に沿っお繁栄しおおりIOI 文明が滅んだずきその地衚面は平らであったIOI 文明の跡地は座暙平面のx 軞ず芋なすこずができるy 軞は高さ方向を衚すすなわち座暙平面においお盎線 $y = 0$ は地衚を領域 $y > 0$ は地䞊を領域 $y < 0$ は地䞋を衚すたたIOI 文明が滅んだずき$a$ 幎前$(a \geq 0)$ の地局は盎線 $y = -a$ の䜍眮にあった </p> <p> IOI 文明が滅んだ埌IOI 文明の跡地では $Q$ 回の地殻倉動が起きた$i$ 回目$(1 \leq i \leq Q)$ の地殻倉動は䜍眮 $X_i$方向 $D_i$倉動の量 $L_i$ で衚される$D_i$ は 1 たたは 2 である$i$ 回目の地殻倉動は以䞋のように起きる </p> <ul> <li> 地局の移動が次のように起きる <ul> <li> $D_i = 1$ のずき断局が点$(X_i, 0)$ を通る傟き $1$ の盎線に沿っお造られこの盎線より䞊の領域にある地局が盎線に沿っお高さ $L_i$ だけ移動するすなわちこの盎線より䞊の点 $(x, y)$ は点$(x + L_i, y + L_i)$ に移動する</li> <li> $D_i = 2$ のずき断局が点$(X_i, 0)$ を通る傟き $-1$ の盎線に沿っお造られこの盎線より䞊の領域にある地局が盎線に沿っお高さ $L_i$ だけ移動するすなわちこの盎線より䞊の点$(x, y)$ は点$(x - L_i, y + L_i)$ に移動する</li> </ul> </li> <li> そのすぐ埌に領域 $y > 0$ の地局が颚化によっおすべお消える</li> </ul> <p> 時は倉わり珟代考叀孊者のJOI 博士はIOI 文明の遺跡を発掘するこずにしたJOI 博士はどの䜍眮の地衚の地局がIOI 文明が滅ぶ䜕幎前の地局であるかを知りたいどのような地殻倉動が起きたかは分かっおいるあなたの仕事はJOI 博士にかわっお$1 \leq i \leq N$ を満たす各敎数 $i$ に぀いお点$(i-1, 0)$ ず点$(i, 0)$の間の地衚の地局がIOI 文明が滅ぶ䜕幎前の地局であるかを求めるこずである </p> <h2>課題</h2> <p> IOI 文明の跡地に起きたの情報が䞎えられたずきすべおの敎数 $i$ $(1 \leq i \leq N)$ に察し点$(i - 1, 0)$ ず点$(i, 0)$ の間の地衚の地局がIOI 文明が滅ぶ䜕幎前の地局であるかを出力せよ </p> <h2>入力</h2> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には 2 個の敎数 $N, Q$ が空癜を区切りずしお曞かれおいるこれは答えを求める地点の数が $N$地殻倉動の回数が $Q$ であるこずを衚す</li> <li> 続く $Q$ 行のうちの $i$ 行目$(1 \leq i \leq Q)$ には3 個の敎数 $X_i, D_i, L_i$ が空癜を区切りずしお曞かれおいるこれは$i$ 回目の地殻倉動の䜍眮が $X_i$方向が $D_i$倉動の量が $L_i$ であるこずを衚す</li> </ul> <h2>出力</h2> <p> 出力は $N$ 行からなる暙準出力の $i$ 行目$(1 \leq i \leq N)$ には点$(i - 1, 0)$ ず点$(i, 0)$ の間の地衚の地局がIOI文明が滅ぶ䜕幎前の地局であるかを衚す敎数を出力せよ </p> <h2>制限</h2> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li> $1 \leq N \leq 200 000$ </li> <li> $1 \leq Q \leq 200 000$ </li> <li> $ -1 000 000 000 \leq X_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$ </li> <li> $1 \leq D_i \leq 2$ $(1 \leq i \leq Q)$ </li> <li> $1 \leq L_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$ </li> </ul> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 10 2 12 1 3 2 2 2 </pre> <h3>出力䟋1</h3> <pre> 3 3 5 5 5 5 5 5 2 2 </pre> <p> この入力䟋は以䞋の図に察応する </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2015_geologicFault1"> </center> <h3>入力䟋2</h3> <pre> 10 6 14 1 1 17 1 1 -6 2 1 3 2 1 4 1 1 0 2 1 </pre> <h3>出力䟋2</h3> <pre> 5 5 4 5 5 5 5 5 4 4 </pre> <h3>入力䟋3</h3> <pre> 15 10 28 1 7 -24 2 1 1 1 1 8 1 1 6 2 1 20 1 3 12 2 2 -10 1 3 7 2 1 5 1 2 </pre> <h3>出力䟋3</h3> <pre> 15 14 14 14 14 12 12 12 12 12 12 12 15 15 12 </pre> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2015/2016-ho/2016-ho.pdf">第15回 日本情報オリンピック本遞 課題 &nbsp; 2016 幎 2 月 14 日</a> </p> </div>
p02095
<h2>H: Colorful Tree</h2> <h3>Story</h3> <p> <i>Yamiuchi</i> (assassination) is a traditional event that is held annually in JAG summer camp. Every team displays a decorated tree in the dark and all teams' trees are compared from the point of view of their colorfulness. In this competition, it is allowed to cut the other teams’ tree to reduce its colorfulness. Despite a team would get a penalty if it were discovered that the team cuts the tree of another team, many teams do this obstruction. </p> <p>You decided to compete in <i>Yamiuchi</i> and write a program that maximizes the colorfulness of your team’s tree. The program has to calculate maximum scores for all subtrees in case the other teams cut your tree.</p> <h3>Problem Statement</h3> <p>You are given a rooted tree <var>G</var> with <var>N</var> vertices indexed with <var>1</var> through <var>N</var>. The root is vertex <var>1</var>. There are <var>K</var> kinds of colors indexed with <var>1</var> through <var>K</var>. You can paint vertex <var>i</var> with either color <var>c_i</var> or <var>d_i</var>. Note that <var>c_i = d_i</var> may hold, and if so you have to paint vertex <var>i</var> with <var>c_i</var> (<var>=d_i</var>).</p> <p>Let the colorfulness of tree <var>T</var> be the number of different colors in <var>T</var>. Your task is to write a program that calculates maximum colorfulness for all rooted subtrees. Note that coloring for each rooted subtree is done independently, so previous coloring does not affect to other coloring.</p> <h3>Input</h3> <pre> <var>N</var> <var>K</var> <var>u_1</var> <var>v_1</var> <var>:</var> <var>u_{N-1}</var> <var>v_{N-1}</var> <var>c_1</var> <var>d_1</var> <var>:</var> <var>c_N</var> <var>d_N</var> </pre> <p>The first line contains two integers <var>N</var> and <var>K</var> in this order.</p> <p>The following <var>N-1</var> lines provide information about the edges of <var>G</var>. The <var>i</var>-th line of them contains two integers <var>u_i</var> and <var>v_i</var>, meaning these two vertices are connected with an edge.</p> <p>The following <var>N</var> lines provide information about color constraints. The <var>i</var>-th line of them contains two integers <var>c_i</var> and <var>d_i</var> explained above.</p> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq K \leq 2\times 10^5</var></li> <li><var>1 \leq u_i , v_i \leq N</var></li> <li><var>1 \leq c_i , d_i \leq K</var></li> <li>The input graph is a tree.</li> <li> All inputs are integers.</li> </ul> <h3>Output</h3> <p>Output <var>N</var> lines.</p> <p>The <var>i</var>-th line of them contains the maximum colorfulness of the rooted subtree of <var>G</var> whose root is <var>i</var>.</p> <h3>Sample Input 1</h3> <pre> 2 10 1 2 1 9 8 7 </pre> <h3>Output for Sample Input 1</h3> <pre> 2 1 </pre> <h3>Sample Input 2</h3> <pre> 3 2 1 2 1 3 1 2 1 1 1 2 </pre> <h3>Output for Sample Input 2</h3> <pre> 2 1 1 </pre> <p>Note that two color options of a vertex can be the same.</p> <h3>Sample Input 3</h3> <pre> 5 100000 4 3 3 5 1 3 2 1 3 2 1 3 2 1 4 2 1 4 </pre> <h3>Output for Sample Input 3</h3> <pre> 4 1 3 1 1 </pre>
p00102
<H1>Matrix-like Computation</H1> <p> Your task is to develop a tiny little part of spreadsheet software. </p> <p> Write a program which adds up columns and rows of given table as shown in the following figure: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_matrixLike" width="640"> </center> <H2>Input</H2> <p> The input consists of several datasets. Each dataset consists of: </p> <pre> <i>n</i> (the size of row and column of the given table) 1st row of the table 2nd row of the table : : <i>n</i>th row of the table </pre> <p> The input ends with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details. </p> <H2>Sample Input</H2> <pre> 4 52 96 15 20 86 22 35 45 45 78 54 36 16 86 74 55 4 52 96 15 20 86 22 35 45 45 78 54 36 16 86 74 55 0 </pre> <H2>Output for the Sample Input</H2> <pre> 52 96 15 20 183 86 22 35 45 188 45 78 54 36 213 16 86 74 55 231 199 282 178 156 815 52 96 15 20 183 86 22 35 45 188 45 78 54 36 213 16 86 74 55 231 199 282 178 156 815 </pre>
p00417
<h1>コンピュヌタシステムの䞍具合</h1>   <p> あなたは䞖界最高性胜のコンピュヌタシステム「那由倚なゆた」を蚭蚈しおいる。しかし、このシステムのプロトタむプの実装䞭に、呜什列がある条件を満たすずシステムが停止するずいう䞍具合が芋぀かった。 </p> <p> このシステムは、長さ$N$の呜什列をプログラムずしお䞎えるこずで動䜜する。呜什列の䞭の$m$番目の呜什を数$X_m$で衚したずき、䞍具合が起こる条件は、ある敎数$i,j$ ($2 \leq ij \leq N$)に察しお$X_i + X_{j-1} = X_j + X_{i-1}$ずなる呜什のパタヌンが呜什列に存圚するこずであるず刀明した。 </p> <p> あなたはこの䞍具合がどの皋床の圱響になるのかを調べるため、ある長さで䜜るこずができる呜什列のうち、䜕皮類の呜什列が䞍具合を起こすかを調べるこずにした。 </p> <p> 長さ$N$の呜什列のうち、䞍具合が起こる呜什列が䜕通りあるかを求めるプログラムを䜜成せよ。ただし、呜什は$1$以䞊$K$以䞋の敎数で衚せるこずずする。答えは䞎えられた玠数$M$で割った䜙りずする。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $N$ $K$ $M$ </pre> <p> 行に、呜什列の長さ$N$ ($3 \leq N \leq 100,000$)、呜什の皮類の数$K$ ($1 \leq K \leq 10$)、玠数$M$ ($100,000,007 \leq M \leq 1,000,000,007$)が䞎えられる。 </p> <h2>出力</h2> <p> 䞍具合を起こす呜什列の数をMで割った䜙りを出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 3 2 100000007 </pre> <h3>出力䟋</h3> <pre> 2 </pre> <p> 呜什列を$(X_1,X_2,X_3)$のように衚すず、考えられる呜什列は$(1,1,1)$、$(1,1,2)$、$(1,2,1)$、$(1,2,2)$、$(2,1,1)$、$(2,1,2)$、$(2,2,1)$、$(2,2,2)$の通り。このうち、䞍具合が起こる呜什列は$(1,1,1)$、$(2,2,2)$の通り。 </p> <h3>入力䟋</h3> <pre> 9 10 100000037 </pre> <h3>出力䟋</h3> <pre> 66631256 </pre> <p> 䞍具合が起こる呜什列は866631552通りあるが、その数を玠数100000037で割った䜙りが出力ずなる。 </p>
p02580
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a two-dimensional grid with <var>H \times W</var> squares. There are <var>M</var> targets to destroy in this grid - the position of the <var>i</var>-th target is <var>\left(h_i, w_i \right)</var>.</p> <p>Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.</p> <p>Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq H, W \leq 3 \times 10^5</var></li> <li><var>1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)</var></li> <li><var>1 \leq h_i \leq H</var></li> <li><var>1 \leq w_i \leq W</var></li> <li><var>\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>M</var> <var>h_1</var> <var>w_1</var> <var>\vdots</var> <var>h_M</var> <var>w_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 3 2 2 1 1 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>We can destroy all the targets by placing the bomb at <var>\left(1, 2\right)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 4 3 3 3 1 1 1 1 2 </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>5 5 10 2 5 4 3 2 3 5 5 2 2 5 4 5 3 5 1 3 5 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6 </pre></section> </div> </span>
p00047
<H1>カップゲヌム</H1> <center> <table> <tr> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cupGame"></td> </tr> </table> </center> <br/> <p> 3 ぀のカップがふせお眮かれおいたす。カップの眮かれおいる堎所を、順に A,B,C ず呌ぶこずにしたす。最初は A に眮かれおいるカップの䞭にボヌルが隠されおいるずしたす。カップの䜍眮を入れ替えるず、䞭に入っおいるボヌルも䞀緒に移動したす。 </p> <p> 入れ替える぀のカップの䜍眮を読み蟌んで、最終的にどの堎所のカップにボヌルが隠されおいるかを出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 入れ替える぀のカップの䜍眮が順番に耇数行にわたり䞎えられたす。各行に、入れ替える぀のカップの䜍眮を衚す文字A, B, たたは Cがカンマ区切りで䞎えられたす。 </p> <p> 入れ替える操䜜は 50 回を超えたせん。 </p> <H2>Output</H2> <p> ボヌルが入っおいるカップの堎所A, B, たたは Cを行に出力したす。 </p> <H2>Sample Input</H2> <pre> B,C A,C C,B A,B C,B </pre> <H2>Output for the Sample Input</H2> <pre> A </pre>
p04004
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Alice, Bob and Charlie are playing <em>Card Game for Three</em>, as below:</p> <ul> <li>At first, each of the three players has a deck consisting of some number of cards. Alice's deck has <var>N</var> cards, Bob's deck has <var>M</var> cards, and Charlie's deck has <var>K</var> cards. Each card has a letter <code>a</code>, <code>b</code> or <code>c</code> written on it. The orders of the cards in the decks cannot be rearranged.</li> <li>The players take turns. Alice goes first.</li> <li>If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says <code>a</code>, Alice takes the next turn.)</li> <li>If the current player's deck is empty, the game ends and the current player wins the game.</li> </ul> <p>There are <var>3^{N+M+K}</var> possible patters of the three player's initial decks. Among these patterns, how many will lead to Alice's victory?</p> <p>Since the answer can be large, print the count modulo <var>1\,000\,000\,007 (=10^9+7)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 3×10^5</var></li> <li><var>1 \leq M \leq 3×10^5</var></li> <li><var>1 \leq K \leq 3×10^5</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li><var>500</var> points will be awarded for passing the test set satisfying the following: <var>1 \leq N \leq 1000</var>, <var>1 \leq M \leq 1000</var>, <var>1 \leq K \leq 1000</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>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer modulo <var>1\,000\,000\,007 (=10^9+7)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>17 </pre> <ul> <li>If Alice's card is <code>a</code>, then Alice will win regardless of Bob's and Charlie's card. There are <var>3×3=9</var> such patterns.</li> <li>If Alice's card is <code>b</code>, Alice will only win when Bob's card is <code>a</code>, or when Bob's card is <code>c</code> and Charlie's card is <code>a</code>. There are <var>3+1=4</var> such patterns.</li> <li>If Alice's card is <code>c</code>, Alice will only win when Charlie's card is <code>a</code>, or when Charlie's card is <code>b</code> and Bob's card is <code>a</code>. There are <var>3+1=4</var> such patterns.</li> </ul> <p>Thus, there are total of <var>9+4+4=17</var> patterns that will lead to Alice's victory.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1227 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000 1000 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>261790852 </pre></section> </div> </span>
p01206
<H1><font color="#000">Problem E:</font> Black Force</H1> <p> A dam construction project was designed around an area called Black Force. The area is surrounded by mountains and its rugged terrain is said to be very suitable for constructing a dam. </p> <p> However, the project is now almost pushed into cancellation by a strong protest campaign started by the local residents. Your task is to plan out a compromise proposal. In other words, you must find a way to build a dam with sufficient capacity, without destroying the inhabited area of the residents. </p> <p> The map of Black Force is given as <i>H</i> &times; <i>W</i> cells (0 &lt; <i>H</i>, <i>W</i> &le; 20). Each cell <i>h<sub>i, j</sub></i> is a positive integer representing the height of the place. The dam can be constructed at a connected region surrounded by higher cells, as long as the region contains neither the outermost cells nor the inhabited area of the residents. Here, a region is said to be connected if one can go between any pair of cells in the region by following a sequence of left-, right-, top-, or bottom-adjacent cells without leaving the region. The constructed dam can store water up to the height of the lowest surrounding cell. The capacity of the dam is the maximum volume of water it can store. Water of the depth of 1 poured to a single cell has the volume of 1. </p> <p> The important thing is that, in the case it is difficult to build a sufficient large dam, it is allowed to choose (at most) one cell and do groundwork to increase the height of the cell by 1 unit. Unfortunately, considering the protest campaign, groundwork of larger scale is impossible. Needless to say, you cannot do the groundwork at the inhabited cell. </p> <p> Given the map, the required capacity, and the list of cells inhabited, please determine whether it is possible to construct a dam. </p> <H2>Input</H2> <p> The input consists of multiple data sets. Each data set is given in the following format: </p> <pre> <i>H W C R</i> <i>h</i><sub>1,1</sub> <i>h</i><sub>1,2</sub> . . . <i>h</i><sub>1,<i>W</i></sub> ... <i>h</i><sub><i>H</i>,1</sub> <i>h</i><sub><i>H</i>,2</sub> . . . <i>h</i><sub><i>H</i>,<i>W</i></sub> <i>y</i><sub>1</sub> <i>x</i><sub>1</sub> ... <i>y<sub>R</sub> x<sub>R</sub></i> </pre> <p> <i>H</i> and <i>W</i> is the size of the map. <i.C</i> is the required capacity. <i>R</i> (0 &lt; <i>R</i> &lt; <i>H</i> &times; <i>W</i>) is the number of cells inhabited. The following <i>H</i> lines represent the map, where each line contains <i>W</i> numbers separated by space. Then, the <i>R</i> lines containing the coordinates of inhabited cells follow. The line “<i>y x</i>” means that the cell <i>h<sub>y,x</sub></i> is inhabited. </p> <p> The end of input is indicated by a line “0 0 0 0”. This line should not be processed. </p> <H2>Output</H2> <p> For each data set, print “Yes” if it is possible to construct a dam with capacity equal to or more than <i>C</i>. Otherwise, print “No”. </p> <H2>Sample Input</H2> <pre> 4 4 1 1 2 2 2 2 2 1 1 2 2 1 1 2 2 1 2 2 1 1 4 4 1 1 2 2 2 2 2 1 1 2 2 1 1 2 2 1 2 2 2 2 4 4 1 1 2 2 2 2 2 1 1 2 2 1 1 2 2 1 1 2 1 1 3 6 6 1 1 6 7 1 7 1 5 1 2 8 1 6 1 4 3 1 5 1 1 4 5 6 21 1 1 3 3 3 3 1 3 1 1 1 1 3 3 1 1 3 2 2 3 1 1 1 1 3 1 3 3 3 3 1 3 4 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Yes No No No Yes </pre>
p03391
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given sequences <var>A</var> and <var>B</var> consisting of non-negative integers. The lengths of both <var>A</var> and <var>B</var> are <var>N</var>, and the sums of the elements in <var>A</var> and <var>B</var> are equal. The <var>i</var>-th element in <var>A</var> is <var>A_i</var>, and the <var>i</var>-th element in <var>B</var> is <var>B_i</var>.</p> <p>Tozan and Gezan repeats the following sequence of operations:</p> <ul> <li>If <var>A</var> and <var>B</var> are equal sequences, terminate the process.</li> <li>Otherwise, first Tozan chooses a positive element in <var>A</var> and decrease it by <var>1</var>.</li> <li>Then, Gezan chooses a positive element in <var>B</var> and decrease it by <var>1</var>.</li> <li>Then, give one candy to Takahashi, their pet.</li> </ul> <p>Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 × 10^5</var></li> <li><var>0 \leq A_i,B_i \leq 10^9(1\leq i\leq N)</var></li> <li>The sums of the elements in <var>A</var> and <var>B</var> are equal.</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</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 2 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>When both Tozan and Gezan perform the operations optimally, the process will proceed as follows:</p> <ul> <li>Tozan decreases <var>A_1</var> by <var>1</var>.</li> <li>Gezan decreases <var>B_1</var> by <var>1</var>.</li> <li>One candy is given to Takahashi.</li> <li>Tozan decreases <var>A_2</var> by <var>1</var>.</li> <li>Gezan decreases <var>B_1</var> by <var>1</var>.</li> <li>One candy is given to Takahashi.</li> <li>As <var>A</var> and <var>B</var> are equal, the process is terminated.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 8 3 0 1 4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p02979
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a blackboard on which all integers from <var>-10^{18}</var> through <var>10^{18}</var> are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero:</p> <ul> <li>Choose an integer between <var>1</var> and <var>N</var> (inclusive) that is written on the blackboard. Let <var>x</var> be the chosen integer, and erase <var>x</var>.</li> <li>If <var>x-2</var> is not written on the blackboard, write <var>x-2</var> on the blackboard.</li> <li>If <var>x+K</var> is not written on the blackboard, write <var>x+K</var> on the blackboard.</li> </ul> <p>Find the number of possible sets of integers written on the blackboard after some number of operations, modulo <var>M</var>. We consider two sets different when there exists an integer contained in only one of the sets.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K\leq N \leq 150</var></li> <li><var>10^8\leq M\leq 10^9</var></li> <li><var>N</var>, <var>K</var>, and <var>M</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible sets of integers written on the blackboard after some number of operations, modulo <var>M</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 998244353 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>Every set containing all integers less than <var>1</var>, all integers greater than <var>3</var>, and at least one of the three integers <var>1</var>, <var>2</var>, and <var>3</var> satisfies the condition. There are seven such sets.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 998244353 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>61 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 4 702443618 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>312 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>17 7 208992811 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>128832 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>123 45 678901234 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>256109226 </pre></section> </div> </span>
p00944
<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 J Post Office Investigation</h2> <p> In this country, all international mails from abroad are first gathered to the central post office, and then delivered to each destination post office relaying some post offices on the way. The delivery routes between post offices are described by a directed graph $G = (V,E)$, where $V$ is the set of post offices and $E$ is the set of possible mail forwarding steps. Due to the inefficient operations, you cannot expect that the mails are delivered along the shortest route. </p> <p> The set of post offices can be divided into a certain number of groups. Here, a group is defined as a set of post offices where mails can be forwarded from any member of the group to any other member, directly or indirectly. The number of post offices in such a group does not exceed 10. </p> <p> The post offices frequently receive complaints from customers that some mails are not delivered yet. Such a problem is usually due to system trouble in a single post office, but identifying which is not easy. Thus, when such complaints are received, the customer support sends staff to check the system of each candidate post office. Here, the investigation cost to check the system of the post office $u$ is given by $c_u$, which depends on the scale of the post office. </p> <p> Since there are many post offices in the country, and such complaints are frequently received, reducing the investigation cost is an important issue. To reduce the cost, the post service administration determined to use the following scheduling rule: When complaints on undelivered mails are received by the post offices $w_1, ..., w_k$ one day, staff is sent on the next day to investigate a single post office $v$ with the lowest investigation cost among candidates. Here, the post office $v$ is a candidate if all mails from the central post office to the post offices $w_1, ... , w_k$ must go through $v$. If no problem is found in the post office $v$, we have to decide the order of investigating other post offices, but the problem is left to some future days. </p> <p> Your job is to write a program that finds the cost of the lowest-cost candidate when the list of complained post offices in a day, described by $w_1, ... , w_k$, is given as a query. </p> <h3>Input</h3> <p> The input consists of a single test case, formatted as follows.<br> <br> $n$ $m$<br> $u_1$ $v_1$<br> ...<br> $u_m$ $v_m$<br> $c_1$<br> ...<br> $c_n$<br> $q$<br> $k_1$ $w_{11}$ ... $w_{1k_1}$<br> ...<br> $k_q$ $w_{q1}$ ... $w_{qk_q}$<br> <br> $n$ is the number of post offices $(2 \leq n \leq 50,000)$, which are numbered from 1 to $n$. Here, post office 1 corresponds to the central post office. $m$ is the number of forwarding pairs of post offices $(1 \leq m \leq 100,000)$. The pair, $u_i$ and $v_i$, means that some of the mails received at post office $u_i$ are forwarded to post office $v_i$ $(i = 1, ..., m)$. $c_j$ is the investigation cost for the post office $j$ $(j = 1, ..., n, 1 \leq c_j \leq 10^9)$. $q$ $(q \geq 1)$ is the number of queries, and each query is specified by a list of post offices which received undelivered mail complaints. $k_i$ $(k_i \geq 1)$ is the length of the list and $w_{i1}, ..., w_{ik_i}$ are the distinct post offices in the list. $\sum_{i=1}^{q} k_i \leq 50,000$. </p> <p> You can assume that there is at least one delivery route from the central post office to all the post offices. </p> <h3>Output</h3> <p> For each query, you should output a single integer that is the lowest cost of the candidate of troubled post office. </p> <h3>Sample Input 1</h3> <pre>8 8 1 2 1 3 2 4 2 5 2 8 3 5 3 6 4 7 1000 100 100 10 10 10 1 1 3 2 8 6 2 4 7 2 7 8</pre> <h3>Sample Output 1</h3> <pre>1000 10 100</pre> <h3>Sample Input 2</h3> <pre>10 12 1 2 2 3 3 4 4 2 4 5 5 6 6 7 7 5 7 8 8 9 9 10 10 8 10 9 8 7 6 5 4 3 2 1 3 2 3 4 3 6 7 8 3 9 6 3</pre> <h3>Sample Output 2</h3> <pre>8 5 8</pre>
p01656
<h2>A - 旧総合研究号通</h2> <p> 時は平成50幎春䌑み情報孊研究科に所属する京子さんは京郜にある某研究パヌクからの研究宀の匕越しがやっず終わりホッず䞀息぀いおいた 今回の匕越しは叀くなった校舎の改修工事によるもので新幎床から工事に䌎い校舎の名前が倉曎されるこずになっおいる </p> <p> ホッずしおいたのも぀かの間京子さんは先生から倧孊の資料に茉っおいる校舎名を新しい名前に倉曎するお仕事を頌たれおしたった しかし線集しなければならない資料には今たでの担圓者が仕事を怠っおいたせいかひず぀叀い名前よりもっず叀い名前が䜿われおいるものもあった </p> <p> なんずか京子さんは平成の間に校舎が改名が行われた幎床ずその名前のリストを芋぀けるこずができた平成元幎床の校舎名は "kogakubu10gokan" であった<br> だが匕越し䜜業にずおも疲れたのでその資料が䜜られた幎床にこの校舎がどんな名前だったのかを自分の手で調べるのには我慢ならなかった </p> <p> そこで京子さんはプログラミングが埗意なあなたに手䌝っおずお願いするこずにした<br> 改名の歎史ず資料が䜜られた幎床が䞎えられるのでその幎床の校舎の名前を出力するプログラミングを曞いおあげよう </p> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる </p><pre><var>N</var> <var>Q</var> <var>year<sub>1</sub></var> <var>name<sub>1</sub></var> <var>year<sub>2</sub></var> <var>name<sub>2</sub></var> <var>
</var> <var>year<sub>N</sub></var> <var>name<sub>N</sub></var> </pre> <p> <var>N</var> は平成2幎床から平成50幎床たでに行われた改名ず改名された幎床の組の個数であり<var>Q</var> は資料が䜜られた幎床を衚す<br> <var>year<sub>i</sub></var> は改名が行われた幎床であり<var>name<sub>i</sub></var> は改名された名前をあらわす </p> <h2>出力圢匏</h2> <p>平成<var>Q</var>幎床の校舎の名前を出力せよ </p> <h2>制玄</h2> <ul> <li><var>1 &le; N &lt; 50</var></li> <li><var>1 &le; Q &lt; 50</var></li> <li><var>2 &le; year<sub>1</sub> &lt; year<sub>2</sub> &lt; 
 &lt; year<sub>n</sub> &le; 50 </var></li> <li>すべおの <var>i</var> に察しお<var>name<sub>i</sub></var> は長さ1以䞊30以䞋で含たれる文字は英数字('a'-'z', 'A'-'Z', '0'-'9') である</li> <!-- <li><var>∀i </var> <var>Q</var> ≠ <var>year_i</var> </li> --> <li>平成元幎床の校舎の名前は"kogakubu10gokan" である </li></ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre>3 12 5 sogo5gokan 10 sogo10gokan 15 sogo15gokan </pre> <h3>出力䟋 1</h3> <pre>sogo10gokan </pre> <p> 平成12幎床の校舎名を出力すればよい<br> 校舎は平成元幎床の kogakubu10gokan から始たり平成5幎床に sogo5gokan 平成10幎床に sogo10gokan および平成15幎床に sogo15gokan に改名されおいる </p> <h3>入力䟋 2</h3> <pre>3 10 5 kogakubu11gokan 10 sogo10gokan 15 KyotoUniversityResearchPark </pre> <h3>出力䟋 2</h3> <pre>sogo10gokan </pre> <p> 平成10幎床の校舎名を出力すればよい<br> 校舎は平成10幎床に sogo10gokan に改名されおいる </p> <h3>入力䟋 3</h3> <pre>3 3 5 kogakubu11gokan 10 sogo10gokan 15 KyotoUniversityResearchPark </pre> <h3>出力䟋 3</h3> <pre>kogakubu10gokan </pre> <p> 平成3幎床の校舎名を出力すればよい<br> 平成元幎床から平成4幎床たでの校舎の名前は "kogakubu10gokan" である </p>
p00694
<h1> Strange Key </h1> <p> Professor Tsukuba invented a mysterious jewelry box that can be opened with a special gold key whose shape is very strange. It is composed of gold bars joined at their ends. Each gold bar has the same length and is placed parallel to one of the three orthogonal axes in a three dimensional space, i.e., x-axis, y-axis and z-axis.</p> <p> The locking mechanism of the jewelry box is truly mysterious, but the shape of the key is known. To identify the key of the jewelry box, he gave a way to describe its shape.</p> <p> The description indicates a list of connected paths that completely defines the shape of the key: the gold bars of the key are arranged along the paths and joined at their ends. Except for the first path, each path must start from an end point of a gold bar on a previously defined path. Each path is represented by a sequence of elements, each of which is one of six symbols (+x, -x, +y, -y, +z and -z) or a positive integer. Each symbol indicates the direction from an end point to the other end point of a gold bar along the path. Since each gold bar is parallel to one of the three orthogonal axes, the 6 symbols are enough to indicate the direction. Note that a description of a path has direction but the gold bars themselves have no direction. </p> <p> An end point of a gold bar can have a label, which is a positive integer. The labeled point may be referred to as the beginnings of other paths. In a key description, the first occurrence of a positive integer defines a label of a point and each subsequent occurrence of the same positive integer indicates the beginning of a new path at the point. </p> <p> An example of a key composed of 13 gold bars is depicted in Figure 1. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fig1"> <br> <p>The following sequence of lines</p> <pre> 19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +z 2 +y </pre> <p> is a description of the key in Figure 1. Note that newlines have the same role as space characters in the description, so that <tt>"19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +z 2 +y"</tt> has the same meaning. </p> <p> The meaning of this description is quite simple. The first integer "19" means the number of the following elements in this description. Each element is one of the 6 symbols or a positive integer. </p> <p> The integer "1" at the head of the second line is a label attached to the starting point of the first path. Without loss of generality, it can be assumed that the starting point of the first path is the origin, i.e., (0,0,0), and that the length of each gold bar is 1. The next element "+x" indicates that the first gold bar is parallel to the x-axis, so that the other end point of the gold bar is at (1,0,0). These two elements "1" and "+x" indicates the first path consisting of only one gold bar. The third element of the second line in the description is the positive integer "1", meaning that the point with the label "1", i.e., the origin (0,0,0) is the beginning of a new path. The following elements "+y", "+z", "3", and "+z" indicate the second path consisting of three gold bars. Note that this "3" is its first occurrence so that the point with coordinates (0,1,1) is labeled "3". The head of the third line "3" indicates the beginning of the third path and so on. Consequently, there are four paths by which the shape of the key in Figure 1 is completely defined. </p> <p> Note that there are various descriptions of the same key since there are various sets of paths that cover the shape of the key. For example, the following sequence of lines</p> <pre> 19 1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y 3 +z 2 +z </pre> <p> is another description of the key in Figure 1, since the gold bars are placed in the same way. </p> <p> Furthermore, the key may be turned 90-degrees around x-axis, y-axis or z-axis several times and may be moved parallelly. Since any combinations of rotations and parallel moves don't change the shape of the key, a description of a rotated and moved key also represent the same shape of the original key. For example, a sequence</p> <pre> 17 +y 1 +y -z +x 1 +z +y +x +z +y -x -y 2 -y 2 +z </pre> <p> is a description of a key in Figure 2 that represents the same key as in Figure 1. Indeed, they are congruent under a rotation around x-axis and a parallel move. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_fig2"> <p> Your job is to write a program to judge whether or not the given two descriptions define the same key. </p> <p> Note that paths may make a cycle. For example, <tt>"4 +x +y -x -y"</tt> and <tt>"6 1 +x 1 +y +x -y"</tt> are valid descriptions. However, two or more gold bars must not be placed at the same position. For example, key descriptions <tt>"2 +x -x"</tt> and <tt>"7 1 +x 1 +y +x -y -x"</tt> are invalid. </p> <h2>Input</h2> <p> An input data is a list of pairs of key descriptions followed by a zero that indicates the end of the input. For <i>p</i> pairs of key descriptions, the input is given in the following format. </p> <ul> <i>key-description</i><sub>1-a</sub><br> <i>key-description</i><sub>1-b</sub><br> <i>key-description</i><sub>2-a</sub><br> <i>key-description</i><sub>2-b</sub><br> ...<br> <i>key-description</i><sub><i>p</i>-a</sub><br> <i>key-description</i><sub><i>p</i>-b</sub><br> 0 </ul> <p> Each key description (<i>key-description</i>) has the following format.</p> <ul> <I>n</I><tt> </tt> <I>e</I><sub>1</sub> <tt> </tt> <I>e</I><sub>2</sub> <tt> </tt> ... <tt> </tt> <I>e</I><sub><I>k</I></sub> <tt> </tt> ... <tt> </tt> <I>e</I><sub><I>n</I></sub> </ul> <p> The positive integer <I>n</I> indicates the number of the following elements <I>e</I><sub>1</sub>, ..., <I>e<sub>n</sub></I> . They are separated by one or more space characters and/or newlines. Each element <I>e<sub>k</sub></I> is one of the six symbols (<tt>+x</tt>, <tt>-x</tt>, <tt>+y</tt>, <tt>-y</tt>, <tt>+z</tt> and <tt>-z</tt>) or a positive integer. </p> <p> You can assume that each label is a positive integer that is less than 51, the number of elements in a single key description is less than 301, and the number of characters in a line is less than 80. You can also assume that the given key descriptions are valid and contain at least one gold bar. </p> <h2>Output</h2> <p> The number of output lines should be equal to that of pairs of key descriptions given in the input. In each line, you should output one of two words "SAME", when the two key descriptions represent the same key, and "DIFFERENT", when they are different. Note that the letters should be in upper case. </p> <H2>Sample Input</H2> <pre> 19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +z 2 +y 19 1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y 3 +z 2 +z 19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +y 2 +z 18 1 -y 1 +y -z +x 1 +z +y +x +z +y -x -y 2 -y 2 +z 3 +x +y +z 3 +y +z -x 0 </pre> <H2>Output for the Sample Input</H2> <pre> SAME SAME DIFFERENT </pre>
p01986
<h3>察空シヌルド</h3> <!-- begin ja only --> <p>時は3xxx幎倪陜系倖の惑星に進出した人類は倧量の隕石の飛来による基地の被害で頭を悩たせおいた囜際宇宙防護䌚瀟International Cosmic Protection Companyはこの問題を解決するために新たな察空シヌルドを開発した</p> <p>防護察象の基地は同じサむズの <i>N</i> 個のナニットが䞀盎線䞊に等間隔で䞊んだ圢をしおおり 1 から <i>N</i> たでの番号が順に付けられおいるICPCはこれらのナニットに合蚈で <i>M</i> 個のシヌルドを蚭眮するこずにした<i>i</i> 番目のシヌルドが胜力 <i>a<sub>i</sub></i> を持ちナニット <i>x<sub>i</sub></i> に蚭眮されおいるずするこのずきあるナニット <i>u</i> における匷床は以䞋の匏で衚される</p> <blockquote><i>&Sigma;<sub>i=1</sub><sup>M</sup> max(a<sub>i</sub>-(u-x<sub>i</sub>)<sup>2</sup>,0)</i></blockquote> <p>シヌルドはナニットにのみ蚭眮するこずができ耇数のシヌルドを同じナニットに蚭眮するこずもできるそしおICPCに支払われる報酬は <i>N</i> 個のナニットの匷床の最小倀に比䟋した額ずなる</p> <p>シヌルドの胜力は党お既に決たっおおり䜍眮も最埌の 1 ぀以倖は決定しおいる最埌の 1 ぀のシヌルドの䜍眮を決めるにあたっお報酬がなるべく倧きくなるようにしたいこのように最埌のシヌルドの䜍眮を決めたずきの匷床の最小倀を求めよ</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は最倧で 30 個のデヌタセットからなる各デヌタセットは次の圢匏で衚される</p> <blockquote><i>N</i> <i>M</i> <i>a<sub>1</sub></i> <i>x<sub>1</sub></i> 
 <i>a<sub>M-1</sub></i> <i>x<sub>M-1</sub></i> <i>a<sub>M</sub></i></blockquote> <p><i>N</i> はナニットの個数<i>M</i> はシヌルドの個数を衚す<i>N</i> ず <i>M</i> は敎数であり<i>1 &le; N &le; 10<sup>6</sup></i><i>1 &le; M &le; 10<sup>5</sup></i>を満たす続く <i>M</i> 行には各シヌルドの情報が䞎えられる<i>a<sub>i</sub></i> ず <i>x<sub>i</sub></i> はそれぞれシヌルドの胜力ず䜍眮を衚す敎数であり<i>1 &le; a<sub>i</sub> &le; 10<sup>9</sup></i><i>1 &le; x<sub>i</sub> &le; N</i> を満たす<i>M</i> 番目のシヌルドの䜍眮はただ決定しおいないため入力で䞎えられないこずに泚意せよ</p> <p>入力の終わりは 2 ぀のれロからなる行で衚される</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに぀いお<i>M</i> 番目のシヌルドの蚭眮䜍眮を適切に決めたずきの匷床の最小倀を 1 行に出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>3 3 2 1 2 2 10 10 4 1 1 1 5 1 9 1 5 7 1000000000 1 1000000000 1 1000000000 3 1000000000 3 1000000000 5 1000000000 5 1 10000 11 10934235 560 3155907 1508 10901182 2457 3471816 3590 10087848 4417 16876957 5583 23145027 6540 15162205 7454 1749653 8481 6216466 9554 7198514 701 14 8181 636 4942 273 1706 282 6758 20 7139 148 6055 629 8765 369 5487 95 6111 77 2302 419 9974 699 108 444 1136 495 2443 0 0 </pre><h3>Output for the Sample Input</h3><pre>10 0 5999999960 23574372 985 </pre>
p02353
<H1>RSQ and RUQ</H1> <p> Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations: </p> <p> <ul> <li> $update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$.</li> <li> $getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$.</li> </ul> </p> <p> Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0. </p> <h2>Input</h2> <pre> $n$ $q$ $query_1$ $query_2$ : $query_q$ </pre> <p> In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$-th query $query_i$ is given in the following format: </p> </p> <pre> 0 $s$ $t$ $x$ </pre> <p>or</p> <pre> 1 $s$ $t$ </pre> <p> The first digit represents the type of the query. '<span>0</span>' denotes $update(s, t, x)$ and '<span>1</span>' denotes $find(s, t)$. </p> <h2>Output</h2> <p> For each $getSum$ query, print the sum in a line. </p> <h2>Constraints</h2> <ul> <li>$1 &le; n &le; 100000$</li> <li>$1 &le; q &le; 100000$</li> <li>$0 &le; s &le; t &lt; n$</li> <li>$-1000 &le; x &le; 1000$</li> </ul> <h2>Sample Input 1</h2> <pre> 6 7 0 1 3 1 0 2 4 -2 1 0 5 1 0 1 0 3 5 3 1 3 4 1 0 5 </pre> <h2>Sample Output 1</h2> <pre> -5 1 6 8 </pre>
p02703
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There are <var>N</var> cities numbered <var>1</var> to <var>N</var>, connected by <var>M</var> railroads.</p> <p>You are now at City <var>1</var>, with <var>10^{100}</var> gold coins and <var>S</var> silver coins in your pocket.</p> <p>The <var>i</var>-th railroad connects City <var>U_i</var> and City <var>V_i</var> bidirectionally, and a one-way trip costs <var>A_i</var> silver coins and takes <var>B_i</var> minutes. You cannot use gold coins to pay the fare.</p> <p>There is an exchange counter in each city. At the exchange counter in City <var>i</var>, you can get <var>C_i</var> silver coins for <var>1</var> gold coin. The transaction takes <var>D_i</var> minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter.</p> <p>For each <var>t=2, ..., N</var>, find the minimum time needed to travel from City <var>1</var> to City <var>t</var>. You can ignore the time spent waiting for trains.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>2 \leq N \leq 50</var></li> <li><var>N-1 \leq M \leq 100</var></li> <li><var>0 \leq S \leq 10^9</var></li> <li><var>1 \leq A_i \leq 50</var></li> <li><var>1 \leq B_i,C_i,D_i \leq 10^9</var></li> <li><var>1 \leq U_i &lt; V_i \leq N</var></li> <li>There is no pair <var>i, j(i \neq j)</var> such that <var>(U_i,V_i)=(U_j,V_j)</var>.</li> <li>Each city <var>t=2,...,N</var> can be reached from City <var>1</var> with some number of railroads.</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</var> <var>U_1</var> <var>V_1</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>U_M</var> <var>V_M</var> <var>A_M</var> <var>B_M</var> <var>C_1</var> <var>D_1</var> <var>:</var> <var>C_N</var> <var>D_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>For each <var>t=2, ..., N</var> in this order, print a line containing the minimum time needed to travel from City <var>1</var> to City <var>t</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 1 2 1 2 1 3 2 4 1 11 1 2 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 14 </pre> <p>The railway network in this input is shown in the figure below.</p> <p>In this figure, each city is labeled as follows:</p> <ul> <li>The first line: the ID number <var>i</var> of the city (<var>i</var> for City <var>i</var>)</li> <li>The second line: <var>C_i</var> / <var>D_i</var></li> </ul> <p>Similarly, each railroad is labeled as follows:</p> <ul> <li>The first line: the ID number <var>i</var> of the railroad (<var>i</var> for the <var>i</var>-th railroad in input)</li> <li>The second line: <var>A_i</var> / <var>B_i</var></li> </ul> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/83f6a1d296d017f40372ea1e1d3b26e5.png"/></p> <p>You can travel from City <var>1</var> to City <var>2</var> in <var>2</var> minutes, as follows:</p> <ul> <li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>2</var> minutes.</li> </ul> <p><br/></p> <p>You can travel from City <var>1</var> to City <var>3</var> in <var>14</var> minutes, as follows:</p> <ul> <li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>2</var> minutes.</li> <li>At the exchange counter in City <var>2</var>, exchange <var>3</var> gold coins for <var>3</var> silver coins in <var>6</var> minutes.</li> <li>Use the <var>1</var>-st railroad to move from City <var>2</var> to City <var>1</var> in <var>2</var> minutes.</li> <li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>4</var> minutes.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 1 1 2 1 5 1 3 4 4 2 4 2 2 3 4 1 1 3 1 3 1 5 2 6 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 5 7 </pre> <p>The railway network in this input is shown in the figure below:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/a081a72c42da7902a30f29f981c368d0.png"/></p> <p>You can travel from City <var>1</var> to City <var>4</var> in <var>7</var> minutes, as follows:</p> <ul> <li>At the exchange counter in City <var>1</var>, exchange <var>2</var> gold coins for <var>6</var> silver coins in <var>2</var> minutes.</li> <li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>4</var> minutes.</li> <li>Use the <var>4</var>-th railroad to move from City <var>3</var> to City <var>4</var> in <var>1</var> minutes.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 5 1 1 2 1 1 1 3 2 1 2 4 5 1 3 5 11 1 1 6 50 1 1 10000 1 3000 1 700 1 100 1 1 100 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 9003 14606 16510 16576 </pre> <p>The railway network in this input is shown in the figure below:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/c61c66a7977129c9ef86c6770b37acba.png"/></p> <p>You can travel from City <var>1</var> to City <var>6</var> in <var>16576</var> minutes, as follows:</p> <ul> <li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>1</var> minute.</li> <li>At the exchange counter in City <var>2</var>, exchange <var>3</var> gold coins for <var>3</var> silver coins in <var>9000</var> minutes.</li> <li>Use the <var>1</var>-st railroad to move from City <var>2</var> to City <var>1</var> in <var>1</var> minute.</li> <li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>1</var> minute.</li> <li>At the exchange counter in City <var>3</var>, exchange <var>8</var> gold coins for <var>8</var> silver coins in <var>5600</var> minutes.</li> <li>Use the <var>2</var>-nd railroad to move from City <var>3</var> to City <var>1</var> in <var>1</var> minute.</li> <li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>1</var> minute.</li> <li>Use the <var>3</var>-rd railroad to move from City <var>2</var> to City <var>4</var> in <var>1</var> minute.</li> <li>At the exchange counter in City <var>4</var>, exchange <var>19</var> gold coins for <var>19</var> silver coins in <var>1900</var> minutes.</li> <li>Use the <var>3</var>-rd railroad to move from City <var>4</var> to City <var>2</var> in <var>1</var> minute.</li> <li>Use the <var>1</var>-st railroad to move from City <var>2</var> to City <var>1</var> in <var>1</var> minute.</li> <li>Use the <var>2</var>-nd railroad to move from City <var>1</var> to City <var>3</var> in <var>1</var> minute.</li> <li>Use the <var>4</var>-th railroad to move from City <var>3</var> to City <var>5</var> in <var>1</var> minute.</li> <li>At the exchange counter in City <var>5</var>, exchange <var>63</var> gold coins for <var>63</var> silver coins in <var>63</var> minutes.</li> <li>Use the <var>4</var>-th railroad to move from City <var>5</var> to City <var>3</var> in <var>1</var> minute.</li> <li>Use the <var>2</var>-nd railroad to move from City <var>3</var> to City <var>1</var> in <var>1</var> minute.</li> <li>Use the <var>5</var>-th railroad to move from City <var>1</var> to City <var>6</var> in <var>1</var> minute.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 6 1000000000 1 2 50 1 1 3 50 5 1 4 50 7 2 3 50 2 2 4 50 4 3 4 50 3 10 2 4 4 5 5 7 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 3 5 </pre> <p>The railway network in this input is shown in the figure below:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/bfbde2d55baea1e0487f80a62ef9b4ab.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>2 1 0 1 2 1 1 1 1000000000 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>1000000001 </pre> <p>The railway network in this input is shown in the figure below:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/16b8d5c94640ed5b38c0863716196890.png"/></p> <p>You can travel from City <var>1</var> to City <var>2</var> in <var>1000000001</var> minutes, as follows:</p> <ul> <li>At the exchange counter in City <var>1</var>, exchange <var>1</var> gold coin for <var>1</var> silver coin in <var>1000000000</var> minutes.</li> <li>Use the <var>1</var>-st railroad to move from City <var>1</var> to City <var>2</var> in <var>1</var> minute.</li> </ul></section> </div> </span>
p03811
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> integers written on a blackboard. The <var>i</var>-th integer is <var>A_i</var>.</p> <p>Takahashi and Aoki will arrange these integers in a row, as follows:</p> <ul> <li>First, Takahashi will arrange the integers as he wishes.</li> <li>Then, Aoki will repeatedly swap two adjacent integers that are coprime, as many times as he wishes.</li> </ul> <p>We will assume that Takahashi acts optimally so that the eventual sequence will be lexicographically as small as possible, and we will also assume that Aoki acts optimally so that the eventual sequence will be lexicographically as large as possible. Find the eventual sequence that will be produced.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ N ≩ 2000</var></li> <li><var>1 ≩ A_i ≩ 10^8</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> 
 <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the eventual sequence that will be produced, in a line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 3 2 4 1 </pre> <p>If Takahashi arranges the given integers in the order <var>(1,2,3,4,5)</var>, they will become <var>(5,3,2,4,1)</var> after Aoki optimally manipulates them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 3 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 4 6 3 </pre></section> </div> </span>
p01085
<h2>Entrance Examination</h2> <p> The International Competitive Programming College (ICPC) is famous for its research on competitive programming. Applicants to the college are required to take its entrance examination. </p> <p> The successful applicants of the examination are chosen as follows. </p> <ul> <li>The score of any successful applicant is higher than that of any unsuccessful applicant.</li> <li>The number of successful applicants <i>n</i> must be between <i>n</i><sub>min</sub> and <i>n</i><sub>max</sub>, inclusive. We choose <i>n</i> within the specified range that maximizes the <i>gap.</i> Here, the <i>gap</i> means the difference between the lowest score of successful applicants and the highest score of unsuccessful applicants. </li> <li> When two or more candidates for <i>n</i> make exactly the same <i>gap,</i> use the greatest <i>n</i> among them.</li> </ul> <p> Let's see the first couple of examples given in Sample Input below. In the first example, <i>n</i><sub>min</sub> and <i>n</i><sub>max</sub> are two and four, respectively, and there are five applicants whose scores are 100, 90, 82, 70, and 65. For <i>n</i> of two, three and four, the gaps will be 8, 12, and 5, respectively. We must choose three as <i>n</i>, because it maximizes the gap. </p> <p> In the second example, <i>n</i><sub>min</sub> and <i>n</i><sub>max</sub> are two and four, respectively, and there are five applicants whose scores are 100, 90, 80, 75, and 65. For <i>n</i> of two, three and four, the gap will be 10, 5, and 10, respectively. Both two and four maximize the gap, and we must choose the greatest number, four. </p> <p> You are requested to write a program that computes the number of successful applicants that satisfies the conditions. </p> <h3>Input</h3> <p> The input consists of multiple datasets. Each dataset is formatted as follows. </p> <blockquote> <i>m</i> <i>n</i><sub>min</sub> <i>n</i><sub>max</sub><br> <i>P</i><sub>1</sub><br> <i>P</i><sub>2</sub><br> ...<br> <i>P<sub>m</sub></i><br> </blockquote> <p> The first line of a dataset contains three integers separated by single spaces. <i>m</i> represents the number of applicants, <i>n</i><sub>min</sub> represents the minimum number of successful applicants, and <i>n</i><sub>max</sub> represents the maximum number of successful applicants. Each of the following <i>m</i> lines contains an integer <i>P<sub>i</sub></i>, which represents the score of each applicant. The scores are listed in descending order. These numbers satisfy 0 &lt; <i>n</i><sub>min</sub> &lt; <i>n</i><sub>max</sub> &lt; <i>m</i> &#8804; 200, 0 &#8804; <i>P<sub>i</sub></i> &#8804; 10000 (1 &#8804; <i>i</i> &#8804; <i>m</i>) and <i>P</i><sub><i>n</i><sub>min</sub></sub> &gt; <i>P</i><sub><i>n</i><sub>max</sub>+1</sub>. These ensure that there always exists an <i>n</i> satisfying the conditions. </p> <p> The end of the input is represented by a line containing three zeros separated by single spaces. </p> <h3>Output</h3> <p> For each dataset, output the number of successful applicants in a line. </p> <h3>Sample Input</h3> <pre>5 2 4 100 90 82 70 65 5 2 4 100 90 80 75 65 3 1 2 5000 4000 3000 4 2 3 10000 10000 8000 8000 4 2 3 10000 10000 10000 8000 5 2 3 100 80 68 60 45 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre>3 4 2 2 3 2 </pre>
p03542
<span class="lang-en"> <p>Score : <var>1900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ringo has a tree with <var>N</var> vertices. The <var>i</var>-th of the <var>N-1</var> edges in this tree connects Vertex <var>A_i</var> and Vertex <var>B_i</var> and has a weight of <var>C_i</var>. Additionally, Vertex <var>i</var> has a weight of <var>X_i</var>.</p> <p>Here, we define <var>f(u,v)</var> as the distance between Vertex <var>u</var> and Vertex <var>v</var>, plus <var>X_u + X_v</var>.</p> <p>We will consider a complete graph <var>G</var> with <var>N</var> vertices. The cost of its edge that connects Vertex <var>u</var> and Vertex <var>v</var> is <var>f(u,v)</var>. Find the minimum spanning tree of <var>G</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200,000</var></li> <li><var>1 \leq X_i \leq 10^9</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li><var>1 \leq C_i \leq 10^9</var></li> <li>The given graph is a tree.</li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>A_2</var> <var>B_2</var> <var>C_2</var> <var>:</var> <var>A_{N-1}</var> <var>B_{N-1}</var> <var>C_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the cost of the minimum spanning tree of <var>G</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 3 5 1 1 2 1 2 3 2 3 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>22 </pre> <p>We connect the following pairs: Vertex <var>1</var> and <var>2</var>, Vertex <var>1</var> and <var>4</var>, Vertex <var>3</var> and <var>4</var>. The costs are <var>5</var>, <var>8</var> and <var>9</var>, respectively, for a total of <var>22</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 44 23 31 29 32 15 1 2 10 1 3 12 1 4 16 4 5 8 4 6 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>359 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2 1000000000 1000000000 2 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3000000000 </pre></section> </div> </span>
p03112
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Along a road running in an east-west direction, there are <var>A</var> shrines and <var>B</var> temples. The <var>i</var>-th shrine from the west is located at a distance of <var>s_i</var> meters from the west end of the road, and the <var>i</var>-th temple from the west is located at a distance of <var>t_i</var> meters from the west end of the road.</p> <p>Answer the following <var>Q</var> queries:</p> <ul> <li>Query <var>i</var> (<var>1 \leq i \leq Q</var>): If we start from a point at a distance of <var>x_i</var> meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A, B \leq 10^5</var></li> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>1 \leq s_1 &lt; s_2 &lt; ... &lt; s_A \leq 10^{10}</var></li> <li><var>1 \leq t_1 &lt; t_2 &lt; ... &lt; t_B \leq 10^{10}</var></li> <li><var>1 \leq x_i \leq 10^{10}</var></li> <li><var>s_1, ..., s_A, t_1, ..., t_B, x_1, ..., x_Q</var> are all different.</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>Q</var> <var>s_1</var> <var>:</var> <var>s_A</var> <var>t_1</var> <var>:</var> <var>t_B</var> <var>x_1</var> <var>:</var> <var>x_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the answer to the <var>i</var>-th query.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 4 100 600 400 900 1000 150 2000 899 799 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>350 1400 301 399 </pre> <p>There are two shrines and three temples. The shrines are located at distances of <var>100, 600</var> meters from the west end of the road, and the temples are located at distances of <var>400, 900, 1000</var> meters from the west end of the road.</p> <ul> <li>Query <var>1</var>: If we start from a point at a distance of <var>150</var> meters from the west end of the road, the optimal move is first to walk <var>50</var> meters west to visit a shrine, then to walk <var>300</var> meters east to visit a temple.</li> <li>Query <var>2</var>: If we start from a point at a distance of <var>2000</var> meters from the west end of the road, the optimal move is first to walk <var>1000</var> meters west to visit a temple, then to walk <var>400</var> meters west to visit a shrine. We will pass by another temple on the way, but it is fine.</li> <li>Query <var>3</var>: If we start from a point at a distance of <var>899</var> meters from the west end of the road, the optimal move is first to walk <var>1</var> meter east to visit a temple, then to walk <var>300</var> meters west to visit a shrine.</li> <li>Query <var>4</var>: If we start from a point at a distance of <var>799</var> meters from the west end of the road, the optimal move is first to walk <var>199</var> meters west to visit a shrine, then to walk <var>200</var> meters west to visit a temple.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 3 1 10000000000 2 9999999999 5000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10000000000 10000000000 14999999998 </pre> <p>The road is quite long, and we may need to travel a distance that does not fit into a <var>32</var>-bit integer.</p></section> </div> </span>
p03407
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>An elementary school student Takahashi has come to a variety store.</p> <p>He has two coins, <var>A</var>-yen and <var>B</var>-yen coins (yen is the currency of Japan), and wants to buy a toy that costs <var>C</var> yen. Can he buy it?</p> <p>Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 \leq A, B \leq 500</var></li> <li><var>1 \leq C \leq 1000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Takahashi can buy the toy, print <code>Yes</code>; if he cannot, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>50 100 120 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>He has <var>50 + 100 = 150</var> yen, so he can buy the <var>120</var>-yen toy.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>500 100 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>He has <var>500 + 100 = 600</var> yen, but he cannot buy the <var>1000</var>-yen toy.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>19 123 143 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre> <p>There are <var>19</var>-yen and <var>123</var>-yen coins in Takahashi Kingdom, which are rather hard to use.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>19 123 142 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Yes </pre></section> </div> </span>
p03057
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Consider a circle whose perimeter is divided by <var>N</var> points into <var>N</var> arcs of equal length, and each of the arcs is painted red or blue. Such a circle is said to <em>generate a string <var>S</var> from every point</em> when the following condition is satisfied:</p> <ul> <li>We will arbitrarily choose one of the <var>N</var> points on the perimeter and place a piece on it.</li> <li>Then, we will perform the following move <var>M</var> times: move the piece clockwise or counter-clockwise to an adjacent point.</li> <li>Here, whatever point we choose initially, it is always possible to move the piece so that the color of the <var>i</var>-th arc the piece goes along is <var>S_i</var>, by properly deciding the directions of the moves.</li> </ul> <p>Assume that, if <var>S_i</var> is <code>R</code>, it represents red; if <var>S_i</var> is <code>B</code>, it represents blue. Note that the directions of the moves can be decided separately for each choice of the initial point.</p> <p>You are given a string <var>S</var> of length <var>M</var> consisting of <code>R</code> and <code>B</code>. Out of the <var>2^N</var> ways to paint each of the arcs red or blue in a circle whose perimeter is divided into <var>N</var> arcs of equal length, find the number of ways resulting in a circle that generates <var>S</var> from every point, modulo <var>10^9+7</var>.</p> <p>Note that the rotations of the same coloring are also distinguished.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq M \leq 2 \times 10^5</var></li> <li><var>|S|=M</var></li> <li><var>S_i</var> is <code>R</code> or <code>B</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to paint each of the arcs that satisfy the condition, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 7 RBRRBRR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The condition is satisfied only if the arcs are alternately painted red and blue, so the answer here is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 BBB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>12 10 RRRRBRRRRB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>78 </pre></section> </div> </span>
p01590
<H1><font color="#000">Problem K:</font> Trading Ship</H1> <p> You are on board a trading ship as a crew. </p> <p> The ship is now going to pass through a strait notorious for many pirates often robbing ships. The Maritime Police has attempted to expel those pirates many times, but failed their attempts as the pirates are fairly strong. For this reason, every ship passing through the strait needs to defend themselves from the pirates. </p> <p> The navigator has obtained a sea map on which the location of every hideout of pirates is shown. The strait is considered to be a rectangle of W &times; H on an xy-plane, where the two opposite corners have the coordinates of (0, 0) and (<i>W</i>, <i>H</i>). The ship is going to enter and exit the strait at arbitrary points on <i>y</i> = 0 and <i>y</i> = <i>H</i> respectively. </p> <p> To minimize the risk of attack, the navigator has decided to take a route as distant from the hideouts as possible. As a talented programmer, you are asked by the navigator to write a program that finds the best route, that is, the route with the maximum possible distance to the closest hideouts. For simplicity, your program just needs to report the distance in this problem. </p> <H2>Input</H2> <p> The input begins with a line containing three integers <i>W</i>, <i>H</i>, and <i>N</i>. Here, <i>N</i> indicates the number of hideouts on the strait. Then <i>N</i> lines follow, each of which contains two integers <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i>, which denote the coordinates the <i>i</i>-th hideout is located on. </p> <p> The input satisfies the following conditions: 1 &le; <i>W</i>, <i>H</i> &le; 10<sup>9</sup>, 1 &le; <i>N</i> &le; 500, 0 &le; <i>x<sub>i</sub></i> &le; <i>W</i>, 0 &le; <i>y<sub>i</sub></i> &le; <i>H</i>. </p> <H2>Output</H2> <!-- <p> There should be a line containing the distance from the best route to the closest hideout(s). The distance should be printed with three fractional digits and should not contain an absolute error greater than 10<sup>-3</sup>. </p> --> <p> There should be a line containing the distance from the best route to the closest hideout(s). The distance should be in a decimal fraction and should not contain an absolute error greater than 10<sup>-3</sup>. </p> <H2>Sample Input and Output</H2> <H2>Input #1</H2> <pre> 10 10 1 3 5 </pre> <H2>Output #1</H2> <pre> 7.000 </pre> <br/> <H2>Input #2</H2> <pre> 10 10 2 2 2 8 8 </pre> <H2>Output #2</H2> <pre> 4.243 </pre> <br/> <H2>Input #3</H2> <pre> 10 10 3 0 1 4 4 8 1 </pre> <H2>Output #3</H2> <pre> 2.500 </pre>
p02216
<span class="lang"> <span class="lang-ja"> <h1>E: 数列ゲヌム</h1> <div class="part"> <section> <h3>問題文</h3><p>長さ $N$ の正敎数列 $a_1, a_2, \ldots, a_N$ がありたす。</p> <p>この数列を甚いた、$2$ 人のプレむダヌが先手ず埌手に分かれお行う以䞋のゲヌムを考えたす。</p> <ul> <li>先手ず埌手は亀互に、以䞋の操䜜のどちらかを遞んで行う。<ul> <li>数列の正の項を $1$ ぀遞び、その倀を $1$ 枛らす。</li> <li>数列の党おの項が正のずき、党おの項の倀を $1$ ず぀枛らす。</li> </ul> </li> </ul> <p>先に操䜜を行えなくなったほうが負けです。</p> <p>$2$ 人のプレむダヌが最適に行動したずき、先手ず埌手どちらが勝぀かを求めおください。</p> </section> </div> <div class="part"> <section> <h3>制玄</h3><ul> <li>$1 \leq N \leq 2 \times 10^5$</li> <li>$1 \leq a_i \leq 10^9$</li> <li>入力は党お敎数である</li> </ul> </section> </div> <hr /> <div class="io-style"> <div class="part"> <section> <h3>入力</h3><p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre>$N$ $a_1$ $a_2$ $...$ $a_N$ </pre> </section> </div> <div class="part"> <section> <h3>出力</h3><p>先手が勝぀ずきは <code>First</code> を、埌手が勝぀ずきは <code>Second</code> を出力せよ。</p> </section> </div> </div> <hr /> <div class="part"> <section> <h3>入力䟋 1</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 1</h3><pre>First </pre> <p>先手が最初に第 $1$ 項の倀を $1$ 枛らすず、次に埌手は第 $2$ 項の倀を $1$ 枛らすしかありたせん。</p> <p>そのあずで先手が第 $2$ 項の倀を $1$ 枛らすず、数列の党おの項の倀は $0$ になり、 埌手は操䜜を行うこずができなくなりたす。</p> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋 2</h3><pre>5 3 1 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 2</h3><pre>Second </pre> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋 3</h3><pre>8 2 4 8 16 32 64 128 256 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 3</h3><pre>Second </pre> </section> </div> <hr /> <div class="part"> <section> <h3>入力䟋 4</h3><pre>3 999999999 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>出力䟋 4</h3><pre>First </pre></section> </div> </span> </span>
p02646
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate <var>A</var>, and he can travel the distance of <var>V</var> per second. The other child is now at coordinate <var>B</var>, and she can travel the distance of <var>W</var> per second.</p> <p>He can catch her when his coordinate is the same as hers. Determine whether he can catch her within <var>T</var> seconds (including exactly <var>T</var> seconds later). We assume that both children move optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>-10^9 \leq A,B \leq 10^9</var></li> <li><var>1 \leq V,W \leq 10^9</var></li> <li><var>1 \leq T \leq 10^9</var></li> <li><var>A \neq B</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>V</var> <var>B</var> <var>W</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If "it" can catch the other child, print <code>YES</code>; otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 2 3 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 2 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre></section> </div> </span>
p03954
<span class="lang-en"> <p>Score : <var>1300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a pyramid with <var>N</var> steps, built with blocks. The steps are numbered <var>1</var> through <var>N</var> from top to bottom. For each <var>1≀i≀N</var>, step <var>i</var> consists of <var>2i-1</var> blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically.</p> <div style="text-align: center;"> <img src="https://atcoder.jp/img/agc006/a2bde72df5ad036d1699f4a74d74a370.png"> <p>A pyramid with <var>N=4</var> steps</p> </img></div> <p>Snuke wrote a permutation of (<var>1</var>, <var>2</var>, <var>...</var>, <var>2N-1</var>) into the blocks of step <var>N</var>. Then, he wrote integers into all remaining blocks, under the following rule:</p> <ul> <li>The integer written into a block <var>b</var> must be equal to the median of the three integers written into the three blocks directly under <var>b</var>, or to the lower left or lower right of <var>b</var>.</li> </ul> <div style="text-align: center;"> <img src="https://atcoder.jp/img/agc006/a940f1d8303f255e1f91d17a5696633f.png"> <p>Writing integers into the blocks</p> </img></div> <p>Afterwards, he erased all integers written into the blocks. Now, he only remembers that the permutation written into the blocks of step <var>N</var> was (<var>a_1</var>, <var>a_2</var>, <var>...</var>, <var>a_{2N-1}</var>).</p> <p>Find the integer written into the block of step <var>1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N≀10^5</var></li> <li>(<var>a_1</var>, <var>a_2</var>, <var>...</var>, <var>a_{2N-1}</var>) is a permutation of (<var>1</var>, <var>2</var>, <var>...</var>, <var>2N-1</var>).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_{2N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the integer written into the block of step <var>1</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 6 3 7 4 5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>This case corresponds to the figure in the problem statement.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre></section> </div> </span>
p01969
<h2>C AA グラフ (AA Graph)</h2> <h3>Problem</h3> <p>Given a graph as an ASCII Art (AA), please print the length of shortest paths from the vertex <var>s</var> to the vertex <var>t</var>. The AA of the graph satisfies the following constraints.</p> <p>A vertex is represented by an uppercase alphabet and symbols <code>o</code> in 8 neighbors as follows.</p> <pre> ooo oAo ooo </pre> <p> Horizontal edges and vertical edges are represented by symbols <code>-</code> and <code>|</code>, respectively. Lengths of all edges are 1, that is, it do not depends on the number of continuous symbols <code>-</code> or <code>|</code>. All edges do not cross each other, and all vertices do not overlap and touch each other. </p> <p> For each vertex, outgoing edges are at most 1 for each directions top, bottom, left, and right. Each edge is connected to a symbol <code>o</code> that is adjacent to an uppercase alphabet in 4 neighbors as follows. </p> <pre> ..|.. .ooo. -oAo- .ooo. ..|.. </pre> <p>Therefore, for example, following inputs are not given.</p> <pre> .......... .ooo..ooo. .oAo..oBo. .ooo--ooo. .......... </pre> <p>(Edges do not satisfies the constraint about their position.)</p> <pre> oooooo oAooBo oooooo </pre> <p>(Two vertices are adjacent each other.)</p> <h3>Input Format</h3> <pre> <var>H</var> <var>W</var> <var>s</var> <var>t</var> <var>a_1</var> $\vdots$ <var>a_H</var> </pre> <ul> <li> In line 1, two integers <var>H</var> and <var>W</var>, and two characters <var>s</var> and <var>t</var> are given. <var>H</var> and <var>W</var> is the width and height of the AA, respectively. <var>s</var> and <var>t</var> is the start and end vertices, respectively. They are given in separating by en spaces.</li> <li> In line <var>1 + i</var> where <var>1 \leq i \leq H</var>, the string representing line <var>i</var> of the AA is given.</li> </ul> <h3>Constraints</h3> <ul> <li> <var>3 \leq H, W \leq 50</var></li> <li> <var>s</var> and <var>t</var> are selected by uppercase alphabets from <code>A</code> to <code>Z</code>, and <var>s \neq t</var>.</li> <li> <var>a_i</var> (<var>1 \leq i \leq H</var>) consists of uppercase alphabets and symbols <code>o</code>, <code>-</code>, <code>|</code>, and <code>.</code>.</li> <li> Each uppercase alphabet occurs at most once in the AA.</li> <li> It is guaranteed that there are two vertices representing <var>s</var> and <var>t</var>.</li> <li> The AA represents a connected graph.</li> </ul> <h3>Output Format</h3> <p>Print the length of the shortest paths from <var>s</var> to <var>t</var> in one line.</p> <h3>Example 1</h3> <pre> 14 16 A L ooo.....ooo..... oAo-----oHo..... ooo.....ooo..ooo .|.......|...oLo ooo..ooo.|...ooo oKo--oYo.|....|. ooo..ooo.|....|. .|....|.ooo...|. .|....|.oGo...|. .|....|.ooo...|. .|....|.......|. ooo..ooo.....ooo oFo--oXo-----oEo ooo..ooo.....ooo </pre> <h3>Output 1</h3> <pre>5</pre> <h3>Exapmple 2</h3> <pre> 21 17 F L ................. .....ooo.....ooo. .....oAo-----oBo. .....ooo.....ooo. ......|.......|.. .ooo..|..ooo..|.. .oCo..|..oDo.ooo. .ooo.ooo.ooo.oEo. ..|..oFo..|..ooo. ..|..ooo..|...|.. ..|...|...|...|.. ..|...|...|...|.. ..|...|...|...|.. .ooo.ooo.ooo..|.. .oGo-oHo-oIo..|.. .ooo.ooo.ooo..|.. ..|...........|.. .ooo...ooo...ooo. .oJo---oKo---oLo. .ooo...ooo...ooo. ................. </pre> <h3>Output 2</h3> <pre>4</pre>
p00381
<h1>Transporter</h1> <p> In the year 30XX, an expedition team reached a planet and found a warp machine suggesting the existence of a mysterious supercivilization. When you go through one of its entrance gates, you can instantaneously move to the exit irrespective of how far away it is. You can move even to the end of the universe at will with this technology! </p> <p> The scientist team started examining the machine and successfully identified all the planets on which the entrances to the machine were located. Each of these N planets (identified by an index from $1$ to $N$) has an entrance to, and an exit from the warp machine. Each of the entrances and exits has a letter inscribed on it. </p> <p> The mechanism of spatial mobility through the warp machine is as follows: </p> <ul> <li>If you go into an entrance gate labeled with c, then you can exit from any gate with label c.</li> <li>If you go into an entrance located on the $i$-th planet, then you can exit from any gate located on the $j$-th planet where $i < j$.</li> </ul> <p> Once you have reached an exit of the warp machine on a planet, you can continue your journey by entering into the warp machine on the same planet. In this way, you can reach a faraway planet. Our human race has decided to dispatch an expedition to the star $N$, starting from Star $1$ and using the warp machine until it reaches Star $N$. To evaluate the possibility of successfully reaching the destination. it is highly desirable for us to know how many different routes are available for the expedition team to track. </p> <p> Given information regarding the stars, make a program to enumerate the passages from Star $1$ to Star $N$. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $N$ $s$ $t$ </pre> <p> The first line provides the number of the stars on which the warp machine is located $N$ ($2 \leq N \leq 100,000$). The second line provides a string $s$ of length $N$, each component of which represents the letter inscribed on the entrance of the machine on the star. By the same token, the third line provides a string $t$ of length $N$ consisting of the letters inscribed on the exit of the machine. Two strings $s$ and $t$ consist all of lower-case alphabetical letters, and the $i$-th letter of these strings corresponds respectively to the entrance and exit of Star $i$ machine. </p> <h2>Output</h2> <p> Divide the number of possible routes from Star $1$ to Star $N$ obtained above by 1,000,000,007, and output the remainder. </p> <h2>Sample Input 1</h2> <pre> 6 abbaba baabab </pre> <h2>Sample Output 1</h2> <pre> 5 </pre> <h2>Sample Input 2</h2> <pre> 25 neihsokcpuziafoytisrevinu universityofaizupckoshien </pre> <h2>Sample Output 2</h2> <pre> 4 </pre>
p02168
<h1>Problem G: Double or Increment</h1> <h2>Problem</h2> <p> ある日、mo3tthi君ずtubuann君は、魔法のポケットずビスケットを䜿っおゲヌムをするこずにしたした。<br> 今ここに $K$ 個のポケットがあり、$1,2, \ldots ,K$ の番号が぀いおいたす。<br> $i$ 番目のポケットの容量は $M_i$ で、最初 $N_i$ 枚のビスケットが入っおいたす。<br> mo3tthi君ずtubuann君は、mo3tthi君から始めお、以䞋の䞀連の操䜜を亀互に行いたす。<br> </p> <ul> <li>ポケットを䞀぀遞ぶ。</li> <li>以䞋のいずれか䞀方の操䜜を䞀床だけ行う。ただし、操䜜の結果遞んだポケットに入っおいるビスケットの枚数がポケットの容量を超える堎合、操䜜を行うこずはできない。</li> <ul> <li>遞んだポケットを撫でる。魔法の力によっお遞んだポケットに入っおいるビスケットの枚数が $1$ 増える。</li> <li>遞んだポケットを叩く。魔法の力によっお遞んだポケットに入っおいるビスケットの枚数が $2$ 倍になる。</li> </ul> </ul> <p> 操䜜を行えなくなった時点でゲヌムは終了し、操䜜を行えなくなった人が負け、そうでない人が勝ちになりたす。<br> mo3tthi君の友人であるあなたは、mo3tthi君から事前にこのゲヌムに勝おるかどうかを刀定できないか盞談されたした。<br> mo3tthi君のために、mo3tthi君がこのゲヌムに必ず勝぀こずができるかどうかを刀定するプログラムを䜜っおください。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $K$ $N_1$ $M_1$ $\vdots$ $N_K$ $M_K$ </pre> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq K \leq 10^5$</li> <li>$1 \leq N_i \leq M_i \leq 10^{18}$</li> <li>入力は党お敎数である</li> </ul> <h2>Output</h2> <p> mo3tthi君が最適に行動したずき、必ず勝぀こずができるなら"mo3tthi"を、そうでないなら"tubuann"を䞀行に出力する。<br> </p> <h2>Sample Input 1</h2> <pre> 1 2 4 </pre> <h2>Sample Output 1</h2> <pre> mo3tthi </pre> <p> mo3tthi君が䞀番目のポケットを叩くず、䞀番目のポケットに入っおいるビスケットの枚数が $4$ になり、tubuann君は操䜜を行うこずができない。 </p> <h2>Sample Input 2</h2> <pre> 2 2 3 3 8 </pre> <h2>Sample Output 2</h2> <pre> tubuann </pre> <h2>Sample Input 3</h2> <pre> 10 2 8 5 9 7 20 8 41 23 48 90 112 4 5 7 7 2344 8923 1 29 </pre> <h2>Sample Output 3</h2> <pre> mo3tthi </pre>
p00155
<H1>スパむダヌ人</H1> <p> 正矩のヒヌロヌ「スパむダヌ人」は、腕からロヌプを出しおビルからビルぞ飛び移るこずができたす。しかし、ロヌプが短いので自分からの距離が 50 以䞋のビルにしか移動できたせん。それより遠くのビルに移動するには、䞀旊別のビルに飛び移らなくおはなりたせん。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_spider"> </center> <br><br> <p> ビルの数 <var>n</var>、<var>n</var> 個のビルの情報、スパむダヌ人の移動開始䜍眮及び目的地を入力ずし、その移動の最短経路を出力するプログラムを䜜成しおください。どのようにビルを経由しおも目暙のビルに移動できない堎合は NA ず出力しおください。各ビルは点ずしお扱い、最短距離で移動するビルの経由方法が぀以䞊存圚するこずはないものずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>b<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>b<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>b<sub>n</sub></var> <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> <var>m</var> <var>s<sub>1</sub></var> <var>g<sub>1</sub></var> <var>s<sub>2</sub></var> <var>g<sub>2</sub></var> : <var>s<sub>m</sub></var> <var>g<sub>m</sub></var> </pre> <p> 行目にビルの数 <var>n</var> (1 &le; <var>n</var> &le; 100)、続く <var>n</var> 行に <var>i</var> 番目のビルのビル番号 <var>b<sub>i</sub></var> (1 &le; <var>b<sub>i</sub></var> &le; <var>n</var>)、そのビルのx座暙ずy座暙を衚す敎数 <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> (-1000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 1000) が空癜区切りで䞎えられたす。 </p> <p> 続く行に移動情報の個数 <var>m</var> (1 &le; <var>m</var> &le; 100)、続く <var>m</var> 行に<var>i</var> 番目の移動情報が䞎えられたす。各移動情報ずしお、移動を開始するビルの番号 <var>s<sub>i</sub></var> ず目的地ビルの番号 <var>g<sub>i</sub></var> が空癜区切りで䞎えられたす。 </p> <p> デヌタセットの数は 10 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに次の圢匏で出力したす。 </p> <p> <var>i</var> 行目に <var>i</var> 番目の移動情報に察する経路たたは NA を行に出力したす。各経路は以䞋の圢匏で出力したす。 </p> <pre> <var>s<sub>i</sub></var> <var>br<sub>i1</sub></var> <var>br<sub>i2</sub></var> ... <var>g<sub>i</sub></var> </pre> <p> <var>br<sub>ij</sub></var> は <var>i</var> 番目の移動情報における、<var>j</var> 番目に経由するビルの番号を衚したす。 </p> <H2>Sample Input</H2> <pre> 4 1 0 0 2 30 0 3 60 40 4 0 60 2 1 3 1 4 22 1 0 0 2 150 40 3 30 20 4 180 150 5 40 80 6 130 130 7 72 28 8 172 118 9 50 50 10 160 82 11 90 105 12 144 131 13 130 64 14 80 140 15 38 117 16 190 90 17 60 100 18 100 70 19 130 100 20 71 69 21 200 110 22 120 150 1 1 22 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 3 NA 1 3 9 20 11 6 22 </pre>
p02538
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have a string <var>S</var> of length <var>N</var>. Initially, all characters in <var>S</var> are <code>1</code>s.</p> <p>You will perform queries <var>Q</var> times. In the <var>i</var>-th query, you are given two integers <var>L_i, R_i</var> and a character <var>D_i</var> (which is a digit). Then, you must replace all characters from the <var>L_i</var>-th to the <var>R_i</var>-th (inclusive) with <var>D_i</var>.</p> <p>After each query, read the string <var>S</var> as a decimal integer, and print its value modulo <var>998,244,353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N, Q \leq 200,000</var></li> <li><var>1 \leq L_i \leq R_i \leq N</var></li> <li><var>1 \leq D_i \leq 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>Q</var> <var>L_1</var> <var>R_1</var> <var>D_1</var> <var>:</var> <var>L_Q</var> <var>R_Q</var> <var>D_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines. In the <var>i</var>-th line print the value of <var>S</var> after the <var>i</var>-th query, modulo <var>998,244,353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 5 3 6 2 1 4 7 3 8 3 2 2 2 4 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>11222211 77772211 77333333 72333333 72311333 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>200000 1 123 456 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>641437905 </pre> <p>Don't forget to take the modulo.</p></section> </div> </span>
p00505
<H1>問題1</h2> <br/> <p style="line-height: 200%;">  䞉角圢の圢は蟺の長さで決たる 順番に぀の正敎数が䞎えられたずき 蟺の長さがそれらの倀ず䞀臎する䞉角圢が存圚するかどうかを調べ 存圚するなら鋭角䞉角圢盎角䞉角圢鈍角䞉角圢のいずれかを刀定し 次の入力ぞ進む 䞉角圢が存圚しないずき それたでに入力された䞉角圢盎角䞉角圢鋭角䞉角圢鈍角䞉角圢の 個数を空癜で区切っお出力し それ以降の入力は無芖しお終了する 入力の䞭には必ず䞉角圢が存圚しないようなものがある ず仮定しおよい. 入力の行数は刀らないが各行には぀の正敎数が空癜で区切っお曞かれおいる ただし各敎数は100 以䞋ずする. </p> <p style="line-height: 200%;"> <!-- 入力ファむルの改行コヌドは CR+LF である たた--> 出力ファむルにおいおは 出力の最埌の行にも改行コヌドを入れるこず </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 3 4 5 2 1 2 6 3 4 1 1 1 1 2 3 </pre> <h3出力䟋</h3> <pre> 4 1 2 1 </pre> <br> <h3>入力䟋</h3> <pre> 3 4 5 2 1 2 6 3 4 1 2 3 1 1 1 </pre> <h3>出力䟋</h3> <pre> 3 1 1 1 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p03283
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In Takahashi Kingdom, there is a east-west railroad and <var>N</var> cities along it, numbered <var>1</var>, <var>2</var>, <var>3</var>, ..., <var>N</var> from west to east. A company called <em>AtCoder Express</em> possesses <var>M</var> trains, and the train <var>i</var> runs from City <var>L_i</var> to City <var>R_i</var> (it is possible that <var>L_i = R_i</var>). Takahashi the king is interested in the following <var>Q</var> matters:</p> <ul> <li>The number of the trains that runs <strong>strictly within</strong> the section from City <var>p_i</var> to City <var>q_i</var>, that is, the number of trains <var>j</var> such that <var>p_i \leq L_j</var> and <var>R_j \leq q_i</var>.</li> </ul> <p>Although he is genius, this is too much data to process by himself. Find the answer for each of these <var>Q</var> queries to help him.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>N</var> is an integer between <var>1</var> and <var>500</var> (inclusive).</li> <li><var>M</var> is an integer between <var>1</var> and <var>200 \ 000</var> (inclusive).</li> <li><var>Q</var> is an integer between <var>1</var> and <var>100 \ 000</var> (inclusive).</li> <li><var>1 \leq L_i \leq R_i \leq N</var> <var>(1 \leq i \leq M)</var></li> <li><var>1 \leq p_i \leq q_i \leq N</var> <var>(1 \leq i \leq Q)</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>Q</var> <var>L_1</var> <var>R_1</var> <var>L_2</var> <var>R_2</var> <var>:</var> <var>L_M</var> <var>R_M</var> <var>p_1</var> <var>q_1</var> <var>p_2</var> <var>q_2</var> <var>:</var> <var>p_Q</var> <var>q_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print <var>Q</var> lines. The <var>i</var>-th line should contain the number of the trains that runs <strong>strictly within</strong> the section from City <var>p_i</var> to City <var>q_i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 3 1 1 1 1 2 2 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>As all the trains runs within the section from City <var>1</var> to City <var>2</var>, the answer to the only query is <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 3 2 1 5 2 8 7 10 1 7 3 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 1 </pre> <p>The first query is on the section from City <var>1</var> to <var>7</var>. There is only one train that runs strictly within that section: Train <var>1</var>. The second query is on the section from City <var>3</var> to <var>10</var>. There is only one train that runs strictly within that section: Train <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 10 1 6 2 9 4 5 4 7 4 7 5 8 6 6 6 7 7 9 10 10 1 8 1 9 1 10 2 8 2 9 2 10 3 8 3 9 3 10 1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7 9 10 6 8 9 6 7 8 10 </pre></section> </div> </span>
p00856
<H1><font color="#000">Problem C:</font> Minimal Backgammon</H1> <p> Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player). </p> <p> The game board is a line of (<i>N</i> + 1) squares labeled as 0 (the start) to <i>N</i> (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square <i>N</i>). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability. </p> <p> The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square (<i>N</i> - 3), the roll "5" brings the checker to the square (<i>N</i> - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual. </p> <p> Each square, except the start and the goal, may be given one of the following two special instructions. </p> <ul> <li>Lose one turn (labeled "<span>L</span>" in Figure 2) If the checker stops here, you cannot move the checker in the next turn.</li> <li> Go back to the start (labeled "<span>B</span>" in Figure 2)<br> If the checker stops here, the checker is brought back to the start.</li> </ul> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_minimalBackgammon"> <br> Figure 2: An example game <br> </center> <br> <p> Given a game board configuration (the size <i>N</i>, and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each containing integers in the following format. </p> <pre> <i>N T L B</i> <i>Lose</i><sub>1</sub> ... <i>Lose<sub>L</sub></i> <i>Back</i><sub>1</sub> ... <i>Back<sub>B</sub></i> </pre> <p> <i>N</i> is the index of the goal, which satisfies 5 &le; <i>N</i> &le; 100. <i>T</i> is the number of turns. You are requested to compute the probability of success within <i>T</i> turns. <i>T</i> satisfies 1 &le; <i>T</i> &le; 100. <i>L</i> is the number of squares marked “Lose one turn”, which satisfies 0 &le; <i>L</i> &le; <i>N</i> - 1. <i>B</i> is the number of squares marked “Go back to the start”, which satisfies 0 &le; <i>B</i> &le; <i>N</i> - 1. They are separated by a space. </p> <p> <i>Lose<sub>i</sub></i>'s are the indexes of the squares marked “Lose one turn”, which satisfy 1 &le; <i>Lose<sub>i</sub></i> &le; <i>N</i> - 1. All <i>Lose<sub>i</sub></i>'s are distinct, and sorted in ascending order. <i>Back<sub>i</sub></i>'s are the indexes of the squares marked “Go back to the start”, which satisfy 1 &le; <i>Back<sub>i</sub></i> &le; <i>N</i> - 1. All <i>Back<sub>i</sub></i>'s are distinct, and sorted in ascending order. No numbers occur both in <i>Lose<sub>i</sub></i>'s and <i>Back<sub>i</sub></i>'s. </p> <p> The end of the input is indicated by a line containing four zeros separated by a space. </p> <H2>Output</H2> <p> For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001. </p> <H2>Sample Input</H2> <pre> 6 1 0 0 7 1 0 0 7 2 0 0 6 6 1 1 2 5 7 10 0 6 1 2 3 4 5 6 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.166667 0.000000 0.166667 0.619642 0.000000 </pre>
p01744
<p> <var>w</var> 本の瞊棒からなり高さ(暪棒を远加するこずのできる段数) が <var>h</var> のあみだくじがある<var>w</var> は偶数であるこのあみだくじの暪棒を远加する堎所の候補のうち䞊から <var>a</var> 番目巊から <var>b</var> 番目を <var>(a, b)</var> ずいう(<var>(a, b)</var> に暪棒を远加した堎合䞊から <var>a</var> 段目で巊から <var>b</var> 番目ず <var>b+1</var> 番目の瞊棒が結ばれる) このような堎所は合蚈 <var>h(w &minus;1)</var> 箇所(1 &le; <var>a</var> &le; <var>h</var>, 1 &le; <var>b</var> &le; <var>w</var> − 1) 存圚する </p> <p> すぬけ君は<var>a</var> &equiv; <var>b</var> (mod 2) をみたす堎所 <var>(a, b)</var> に党お暪棒を远加した次にすぬけ君は<var>(a<sub>1</sub>, b<sub>1</sub>), . . . , (a<sub>n</sub>, b<sub>n</sub>)</var> の堎所の暪棒を消した䞊端で巊から <var>i</var> 番目を遞んだずき䞋端で巊から䜕番目になるかずいうのを党お求めよ </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>h, w, n</var> &le; 200000 </li> <li> <var>w</var> は偶数</li> <li> 1 &le; <var>a<sub>i</sub></var> &le; <var>h</var></li> <li> 1 &le; <var>b<sub>i</sub></var> &le; <var>w</var> − 1</li> <li> <var>a<sub>i</sub></var> &equiv; <var>b<sub>i</sub></var> (mod 2)</li> <li> <var>(a<sub>i</sub>, b<sub>i</sub>)</var> = <var>(a<sub>j</sub>, b<sub>j</sub>)</var> ずなるような盞異なる <var>i, j</var> は存圚しない</li> </ul> <h2>Input</h2> <pre> <var>h</var> <var>w</var> <var>n</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> . . . <var>a<sub>n</sub></var> <var>b<sub>n</sub></var> </pre> <h2>Output</h2> <p> <var>w</var> 行出力せよ<var>i</var> 行目には䞊端で巊から <var>i</var> 番目を遞んだずき䞋端で巊から䜕番目になるかを出力せよ </p> <h2>Sample Input 1</h2> <pre> 4 4 1 3 3 </pre> <h2>Sample Output 1</h2> <pre> 2 3 4 1 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummer2014_denseAmidakuji" title="Dense Amidakuji" alt="Dense Amidakuji" width="200"> <p> 図1: たずえば䞊端で巊端の瞊棒を遞ぶず(1, 1), (2, 2), (4, 2) を通っお䞋端で巊から二番目の瞊棒にたどり着く </p> <h2>Sample Input 2</h2> <pre> 10 6 10 10 4 4 4 5 1 4 2 7 3 1 3 2 4 8 2 7 5 7 1 </pre> <h2>Sample Output 2</h2> <pre> 1 4 3 2 5 6 </pre>