question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01691
<h2>E - Disappear Drive / 消えるドラむノ</h2> <h3>Story</h3> <p>Dのひずはバスケットボヌルが奜きだが、シュヌトが奜きなため、他のテクニックはからっきしである。ドリブルは特に苊手で、盞手の守備範囲に入るず必ずボヌルを奪われおしたう。そこでどんな盞手も必ず抜き去る必殺のドリブルを線み出すこずにした。努力の末、圌は遂に消えるドラむノ、&quot;ディスアピアドラむノ&quot;を完成させた。</p> <p>ディスアピアドラむノは、盞手を挑発するこずで集䞭力を奪い芖線を倖す&quot;ディスディレクション&quot;により隙を䜜り、その隙に次元(ディメンゞョン)の壁を超えお盞手の守備範囲をすり抜けおしたう完党無欠のドラむノである。しかし、次元の壁を超えるこずは䜓ぞの負担が倧きいため、次元を超えられる回数には制限がある。たた、垞に集䞭力を䜿うため、通垞の移動を含め、方向転換が<var>1</var>床たでしかできない。コヌト䞊でどのように動けば、ボヌルを奪われずに最短でゎヌルたで蟿り着けるだろうか。</p> <h3>Problem</h3> <p>二次元平面䞊に、<var>(0,0)</var>を巊䞋、<var>(50,94)</var>を右䞊ずする長方圢を考える。たた、この平面䞊には<var>N</var>個の円が存圚し、<var>i</var>番目の円の䞭心の䜍眮は<var>(x_i,y_i)</var>、半埄は<var>r_i</var>である。円同士に重なりはない。</p> <p><var>(25,0)</var>を点<var>S</var>、<var>(25,94)</var>を点<var>G</var>ずし、<var>S</var>から<var>G</var>ぞ至る経路を考える。「経路」ずは、(1)<var>S</var>ず<var>G</var>を結んだ線分であるか、(2)長方圢内郚の任意の点<var>P</var>に぀いお線分<var>SP</var>ず線分<var>GP</var>を結合したものからなる。<var>S</var>から<var>G</var>ぞず向かう経路の途䞭、䞀床ある円の内郚に入っおからその円の内郚から出るたでの間を「円の内郚を通過する区間」ず定矩する。ただし、長方圢・円の呚䞊はそれぞれ長方圢・円の内郚には含たれないずする。</p> <p>円の内郚を通過する区間の数が<var>D</var>個以䞋であるような経路のうち、最短の経路の長さを求めよ。どうしおもゎヌルできないずきは<var>-1</var>を返すこず。</p> <h3>Input</h3> <p>入力は以䞋の圢匏からなる。</p> <pre><var>N</var> <var>D</var> <var>x_1</var> <var>y_1</var> <var>r_1</var> <var>...</var> <var>x_N</var> <var>y_N</var> <var>r_N</var></pre> <p><var>1</var>行目は<var>2</var>぀の敎数からなり、円の個数<var>N</var>、円の内郚を通過できる回数<var>D</var>が空癜<var>1</var>文字区切りで䞎えられる。 続く<var>N</var>行は円の情報が䞎えられる。 <var>i+1</var>行目(<var>1 \leq i \leq N</var>)は<var>3</var>぀の敎数からなり、<var>i</var>番目の円の䞭心のx座暙<var>x_i</var>、y座暙<var>y_i</var>、半埄<var>r_i</var>が空癜<var>1</var>文字区切りで䞎えられる。</p> <p>制玄:</p> <ul> <li><var>0 \leq N \leq 5</var></li> <li><var>0 \leq D \leq 5</var></li> <li><var>0 \leq x_i \leq 50</var></li> <li><var>0 \leq y_i \leq 94</var></li> <li><var>1 \leq r_i \leq 100</var></li> <li>任意の<var>2</var>円間は<var>10^{-5}</var>以䞊離れおいるず仮定しおよい。</li> <li><var>S</var>,<var>G</var>はそれぞれ任意の円の内郚には含たれないず仮定しおよい。</li> <li><var>S</var>,<var>G</var>はそれぞれ任意の円ず<var>10^{-5}</var>以䞊離れおいるず仮定しおよい。</li> <li>最短経路における点Pは、長方圢の呚および任意の円呚から<var>10^{-5}</var>以䞊離れおいるず仮定しおよい。</li> </ul> <h3>Output</h3> <p>最短経路の長さを<var>1</var>行に出力せよ。行の最埌では必ず改行を行うこず。 ただし、どうしおもゎヌルできないずきは<var>-1</var>を返すこず。 正答に察し、<var>10^{-7}</var>以䞋の絶察誀差、あるいは盞察誀差は蚱容される。</p> <h3>Sample Input 1</h3> <pre>1 0 25 47 10</pre> <h3>Sample Output 1</h3> <pre>96.2027355887</pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample1" alt="DisappearDrive_sample1.png" /> <p>消えるこずができないので、迂回した経路が最短である。</p> <h3>Sample Input 2</h3> <pre>1 1 25 47 10</pre> <h3>Sample Output 2</h3> <pre>94.0000000000</pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample2" alt="DisappearDrive_sample2.png" /> <p>消えるこずができるので、䞀盎線に突き抜ければよい。</p> <h3>Sample Input 3</h3> <pre>1 0 20 47 5</pre> <h3>Sample Output 3</h3> <pre>94.0000000000</pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample3" alt="DisappearDrive_sample3.png" /> <p>円呚䞊は円の内郚に含たれないので、消えずに通過するこずができる。</p> <h3>Sample Input 4</h3> <pre>1 0 25 47 40</pre> <h3>Sample Output 4</h3> <pre>-1</pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample4" alt="DisappearDrive_sample4.png" /> <p>消えるこずも迂回するこずもできないため、ゎヌルに到達できない。</p> <h3>Sample Input 5</h3> <pre>5 2 11 10 16 33 40 18 20 66 10 45 79 14 22 85 8</pre> <h3>Sample Output 5</h3> <pre>96.1320937224</pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DisappearDrive_sample5" alt="DisappearDrive_sample5.png" />
p00983
<h2>Reordering the Documents</h2> <p> Susan is good at arranging her dining table for convenience, but not her office desk. </p> <p> Susan has just finished the paperwork on a set of documents, which are still piled on her desk. They have serial numbers and <i>were</i> stacked in order when her boss brought them in. The ordering, however, is not perfect now, as she has been too lazy to put the documents slid out of the pile back to their proper positions. Hearing that she has finished, the boss wants her to return the documents immediately in the document box he is sending her. The documents should be stowed in the box, of course, in the order of their serial numbers. </p> <p> The desk has room just enough for two more document piles where Susan plans to make two temporary piles. All the documents in the current pile are to be moved one by one from the top to either of the two temporary piles. As making these piles too tall in haste would make them tumble, not too many documents should be placed on them. After moving <i>all</i> the documents to the temporary piles and receiving the document box, documents in the two piles will be moved from their tops, one by one, into the box. Documents should be in reverse order of their serial numbers in the two piles to allow moving them to the box in order. </p> <p> For example, assume that the pile has six documents #1, #3, #4, #2, #6, and #5, in this order from the top, and that the temporary piles can have no more than three documents. Then, she can form two temporary piles, one with documents #6, #4, and #3, from the top, and the other with #5, #2, and #1 (Figure E.1). Both of the temporary piles are reversely ordered. Then, comparing the serial numbers of documents on top of the two temporary piles, one with the larger number (#6, in this case) is to be removed and stowed into the document box first. Repeating this, all the documents will be perfectly ordered in the document box. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_reordering_the_documents" width="680"/><br> Figure E.1. Making two temporary piles </center> <p> Susan is wondering whether the plan is actually feasible with the documents in the current pile and, if so, how many different ways of stacking them to two temporary piles would do. You are asked to help Susan by writing a program to compute the number of different ways, which should be zero if the plan is not feasible. </p> <p> As each of the documents in the pile can be moved to either of the two temporary piles, for $n$ documents, there are $2^n$ different choice combinations in total, but some of them may disturb the reverse order of the temporary piles and are thus inappropriate. </p> <p> The example described above corresponds to the first case of the sample input. In this case, the last two documents, #5 and #6, can be swapped their destinations. Also, exchanging the roles of two temporary piles totally will be OK. As any other move sequences would make one of the piles higher than three and/or make them out of order, the total number of different ways of stacking documents to temporary piles in this example is $2 \times 2 = 4$. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $m$ $s_1$ ... $s_n$ </pre> <p> Here, $n$ is the number of documents in the pile ($1 \leq n \leq 5000$), and $m$ is the number of documents that can be stacked in one temporary pile without committing risks of making it tumble down ($n/2 \leq m \leq n$). Numbers $s_1$ through $s_n$ are the serial numbers of the documents in the document pile, from its top to its bottom. It is guaranteed that all the numbers $1$ through $n$ appear exactly once. </p> <h3>Output</h3> <p> Output a single integer in a line which is the number of ways to form two temporary piles suited for the objective. When no choice will do, the number of ways is $0$, of course. </p> <p> If the number of possible ways is greater than or equal to $10^9 + 7$, output the number of ways modulo $10^9 + 7$. </p> <h3>Sample Input 1 </h3> <pre> 6 3 1 3 4 2 6 5 </pre> <h3>Sample Output 1</h3> <pre> 4 </pre> <h3>Sample Input 2 </h3> <pre> 6 6 1 3 4 2 6 5 </pre> <h3>Sample Output 2</h3> <pre> 8 </pre> <h3>Sample Input 3 </h3> <pre> 4 4 4 3 1 2 </pre> <h3>Sample Output 3</h3> <pre> 0 </pre>
p01384
<div> <h1 class="title">問題 I : ビット挔算</h1> <p>いよいよ G○○gle Code Jam の䞖界倧䌚が始たろうずしおいる 前では P○tr, t○mek, SnapDrag○n をはじめずする G○○gle の誇る最匷のコヌダヌ達が睚みを利かせおいる 劙な動きを芋せれば呜はないだろう 目を぀むりコンテスト開始をじっず埅぀</p> <p> 劙だコンテストが始たらない 目を開けおみるず なんずいうこずだ郚屋の党おの人間が倒れおいる いや違う党おではない䞀人の男wata を陀いおだ</p> <dl class="docutils"> <dt>wata</dt> <dd>「やっず話せるぞ 久しぶりだな(iwi)」</dd> <dt>(iwi)</dt> <dd>「 お前は䜕者だ 俺の知る wata は幌なじみ系矎少女のはずが 」</dd> <dt>wata</dt> <dd>「ただそんな劄想に取り憑かれおいるのか!! 思い出せ!! 受け止めろ!! 圌はもうこの䞖界には居ないんだ!!」</dd> </dl> <p>はっ !! 僕は党おを思い出しおいた 僕は䞖界で最初にプログラミングコンテストで人を殺めたのだ そしお僕が殺したのは他でもなく最も仲の良かった友人の䞀人kita_masa であった</p> <p>kita_masa は自らをビット挔算の達人ず蚀い あらゆる関数はビット挔算で蚘述できるず蚀う少し倉わった奎だった そういえば今ビット挔算を甚いお䜜成したい関数があるが kita_masa にそれをお願いするこずはできない そこでkita_masa の代わりになるプログラムを䜜成するこずにした</p> <div> <h1>問題</h1> <p><span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 個の敎数の組 <span style="font-size:110%;font-family:times new roman;">(<i>x</i><sub><i>i</i></sub>,&nbsp;<i>y</i><sub><i>i</i></sub>)</span> が䞎えられる 党おの組に察しお <span style="font-size:110%;font-family:times new roman;"><i>y</i><sub><i>i</i></sub>&nbsp;=&nbsp;<i>f</i>(<i>x</i><sub><i>i</i></sub>)</span> なる関数 <span style="font-size:110%;font-family:times new roman;"><i>f</i></span> を制玄の䞋で䜜るこずを考える</p> <p>関数 <span style="font-size:110%;font-family:times new roman;"><i>f</i></span> はC 蚀語の゜ヌスコヌドずしお以䞋のように衚珟できるものずする:</p> <pre class="literal-block"> uint32_t f(uint32_t x) { return 匏; } </pre> <p>ここでuint32_t は 32 ビット笊号無し敎数を衚す たた匏は以䞋の BNF で衚珟できるものずする:</p> <pre class="literal-block"> &lt;expr&gt; ::= &quot;x&quot; | &lt;num&gt; | &quot;(~&quot; &lt;expr&gt; &quot;)&quot; | &quot;(&quot; &lt;expr&gt; &lt;op2&gt; &lt;expr&gt; &quot;)&quot; &lt;op2&gt; ::= &quot;&amp;&quot; | &quot;|&quot; | &quot;^&quot; | &quot;+&quot; | &quot;-&quot; | &quot;*&quot; </pre> <p>&lt;num&gt; は 32 ビット笊号無し敎数で衚珟できる非負の敎数を 10 進数で自然に (leading-zero 等を持たず) 衚珟したものずする</p> <p>このような関数の匏を出力するプログラムを䜜成せよ</p> </div> <div> <h1>入力</h1> <p>入力の最初の行は 1 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> を含む</p> <p>続く <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 行の <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> 行目は 2 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>x</i><sub><i>i</i></sub>,&nbsp;<i>y</i><sub><i>i</i></sub></span> を含む</p> </div> <div> <h1>出力</h1> <p>条件を満たす匏を出力せよ</p> </div> <div> <h1>制玄</h1> <ul class="simple"> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>N</i>&nbsp;&le;&nbsp;8</span></li> <li><span style="font-size:110%;font-family:times new roman;">0&nbsp;&le;&nbsp;<i>x</i><sub><i>i</i></sub>,&nbsp;<i>y</i><sub><i>i</i></sub>&nbsp;&lt;&nbsp;256</span></li> <li>匏は必ず䞊蚘の BNF に埓う曞匏で出力せよ䟋え C 蚀語の衚珟ずしお劥圓であったずしおも空癜や改行の挿入や括匧の削陀などはしおはならない</li> <li>出力は 100000 文字を越えおはならない</li> <li>条件を満たす関数 <span style="font-size:110%;font-family:times new roman;"><i>f</i></span> が垞に存圚するような入力が䞎えられる</li> </ul> </div> <div> <h1>郚分点</h1> <p>この問題の刀定には20 点分のテストケヌスのグルヌプが蚭定されおいる このグルヌプに含たれるテストケヌスの入力は以䞋を満たす</p> <ul class="simple"> <li>'+', '-', '*' を甚いないような正しい出力が存圚する</li> </ul> </div> <div> <h1>入出力䟋</h1> <p>入力䟋1:</p> <pre class="literal-block"> 8 1 1 2 2 3 3 4 0 5 1 6 2 7 3 8 0 </pre> <p>入力䟋 1 に察する出力の䟋:</p> <pre class="literal-block"> (x&amp;3) </pre> <p>入力䟋2:</p> <pre class="literal-block"> 8 1 0 2 0 3 2 4 0 5 4 6 4 7 6 8 0 </pre> <p>入力䟋 2 に察する出力の䟋:</p> <pre class="literal-block"> (x&amp;(x-1)) </pre> <p>良く知られる最右の 1 ビットをオフにする操䜜である</p> </div> </div>
p03643
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>This contest, <em>AtCoder Beginner Contest</em>, is abbreviated as <em>ABC</em>.</p> <p>When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.</p> <p>What is the abbreviation for the <var>N</var>-th round of ABC? Write a program to output the answer.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>100 ≀ N ≀ 999</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 abbreviation for the <var>N</var>-th round of ABC.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>ABC100 </pre> <p>The 100th round of ABC is ABC100.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>425 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>ABC425 </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>ABC999 </pre></section> </div> </span>
p02951
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have two bottles for holding water.</p> <p>Bottle <var>1</var> can hold up to <var>A</var> milliliters of water, and now it contains <var>B</var> milliliters of water.</p> <p>Bottle <var>2</var> contains <var>C</var> milliliters of water.</p> <p>We will transfer water from Bottle <var>2</var> to Bottle <var>1</var> as much as possible.</p> <p>How much amount of water will remain in Bottle <var>2</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq B \leq A \leq 20</var></li> <li><var>1 \leq C \leq 20</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>Print the integer representing the amount of water, in milliliters, that will remain in Bottle <var>2</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>We will transfer two milliliters of water from Bottle <var>2</var> to Bottle <var>1</var>, and one milliliter of water will remain in Bottle <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 3 9 </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 3 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p03213
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Among the divisors of <var>N!</var> <var>(= 1 \times 2 \times ... \times N)</var>, how many <em>Shichi-Go numbers</em> (literally "Seven-Five numbers") are there?</p> <p>Here, a Shichi-Go number is a positive integer that has exactly <var>75</var> divisors.</p> </section> </div> <div class="part"> <section> <h3>Note</h3><p>When a positive integer <var>A</var> divides a positive integer <var>B</var>, <var>A</var> is said to a <em>divisor</em> of <var>B</var>. For example, <var>6</var> has four divisors: <var>1, 2, 3</var> and <var>6</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the Shichi-Go numbers that are divisors of <var>N!</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> <p>There are no Shichi-Go numbers among the divisors of <var>9! = 1 \times 2 \times ... \times 9 = 362880</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>There is one Shichi-Go number among the divisors of <var>10! = 3628800</var>: <var>32400</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>543 </pre></section> </div> </span>
p00595
<H1><font color="#000000">Problem A:</font> Greatest Common Divisor</H1> <p> Please find the greatest common divisor of two natural numbers. A clue is: The Euclid's algorithm is a way to resolve this task. </p> <H2>Input</H2> <p> The input file consists of several lines with pairs of two natural numbers in each line. The numbers do not exceed 100000. </p> <p> The number of pairs (datasets) is less than 50. </p> <H2>Output</H2> <p> Your program has to print the greatest common divisor for each pair of input numbers. Print each result on a new line. </p> <H2>Sample Input</H2> <pre> 57 38 60 84 </pre> <H2>Output for the Sample Input</H2> <pre> 19 12 </pre>
p02052
<h2>A: Hokkaido University Easy</h2> <h3>泚意</h3> <p> 問題蚭定は B 問題ず同䞀のものですが、制玄のみが異なりたすのでご泚意ください。</p> <h3>物語</h3> <p> 北海道倧孊に合栌し、新たな生掻の始たりに心を躍らせるほむらちゃん。しかし圌女の前には、ずお぀もなく広いキャンパスが埅ち受けおいた...。</p> <p> 「え...次の授業に間に合わないんだけど...」</p> <h3>問題</h3> <p> 北海道倧孊札幌キャンパスは異垞に広いこずで有名です。札幌キャンパスは瞊に <var>H</var> マス、暪に <var>W</var> マス䞊んだ長方圢のマス目で衚珟されたす。北から <var>i</var> マス、西から <var>j</var> マス進んだマスを <var>(i,j)</var> で衚すこずにしたす。キャンパス内にはいく぀か建物があり、マス <var>(i,j)</var> で衚される䜍眮に建物がある堎合は 'B' 、ない堎合は '.' が <var>c_{i,j}</var> に曞かれおいたす。</p> <p> 北海道倧孊の新入生のほむらちゃんは、キャンパスのあたりの広さに驚愕し、建物間の移動が心配になっおきたした。そこで、建物のある <var>2</var> ぀のマスのうち、最も遠い組はどれくらい離れおいるのかが気になりたした。ここで、<var>2</var> ぀のマスの組 <var>(i,j) , (i',j')</var> の間の距離を <var>|i-i'|+|j-j'|</var> ず定矩したす。</p> <p> ほむらちゃんは、自分にはこの問題は難しいず思い、同玚生のあなたに助けを求めおきたした。ほむらちゃんの代わりに答えを求めおください。</p> <h3>入力圢匏</h3> <pre> <var>H</var> <var>W</var> <var>c_{11}</var><var>c_{12}</var> <var>...</var> <var>c_{1W}</var> <var>:</var> <var>c_{H1}</var><var>c_{H2}</var> <var>...</var> <var>c_{HW}</var> </pre> <h3>制玄</h3> <ul> <li> <var>2\leq H,W \leq 30</var></li> <li> <var>H,W</var> は敎数</li> <li> <var>c_{i,j}</var> は 'B' か '.' のいずれかである。</li> <li> <var>c_{i,j}</var> のうち少なくずも <var>2</var> ぀は 'B' である。</li> </ul> <h3>出力圢匏</h3> <p>答えを衚す敎数を <var>1</var> 行に出力せよ。</p> <h3>入力䟋 1</h3> <pre> 3 3 B.B ..B .BB </pre> <h3>出力䟋 1</h3> <pre>4</pre> <ul> <li><var>(1,1)</var> ず <var>(3,3)</var> の <var>2</var> 点間が最長です。</li> </ul> <h3>入力䟋 2</h3> <pre> 4 3 B.. B.. ... ... </pre> <h3>出力䟋 2</h3> <pre>1</pre> <ul> <li>隣り合う䜍眮が最長になる堎合もありたす。</li> </ul> <h3>入力䟋 3</h3> <pre> 6 6 ...B.. B.B.B. .B.B.B ...B.B .B..B. ..B... </pre> <h3>出力䟋 3</h3> <pre>7</pre>
p02402
<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>Min, Max and Sum</h1> <p> Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence. </p> <h2>Input</h2> <p> In the first line, an integer $n$ is given. In the next line, $n$ integers $a_i$ are given in a line. </p> <h2>Output</h2> <p> Print the minimum value, maximum value and sum in a line. Put a single space between the values. </p> <h2>Constraints</h2> <ul> <li>$0 < n \leq 10000$</li> <li>$-1000000 \leq a_i \leq 1000000$</li> </ul> <h2>Sample Input</h2> <pre> 5 10 1 5 4 17 </pre> <h2>Sample Output</h2> <pre> 1 17 37 </pre>
p00350
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>文字列ゲヌム</H1> <p> あなたは、双子のアむ君ずヅヌ君に文字列を䜿ったゲヌムのプログラムをプレれントしたした。このゲヌムでは、アむ君ずヅヌ君が文字列の䞭から郚分文字列をそれぞれ遞び、それらを比范しお小さい方を遞んだ人に埗点が加算されたす。二人は競い合い、䜕床もゲヌムを行いたした。ずころが、同じ文字列に察しお䜕床もゲヌムをしおいるうちに飜きおしたいたした。そこであなたは、文字列が倉化するようにプログラムを修正するこずにしたした。 </p> <br/> <p> 長さ <var>N</var> の文字列 <var>U</var> ず <var>Q</var> 個の呜什文が䞎えられたずき、以䞋の呜什を凊理するプログラムを䜜成せよ。 </p> <ul> <li> 文字列 <var>U</var> の指定された範囲にあるすべおの文字を、指定された文字に眮き換える。</li> <li> 文字列 <var>U</var> の指定された぀の郚分文字列 <var>S</var>, <var>T</var> を蟞曞順で比范しお、それらの倧小関係を出力する。</li> </ul> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>U</var> <var>Q</var> <var>query<sub>1</sub></var> <var>query<sub>2</sub></var> : <var>query<sub>Q</sub></var> </pre> <p> 行目に文字列の長さ <var>N</var> (1 &le; <var>N</var> &le; 200000)、行目に文字列 <var>U</var> (英小文字のみを含む文字列)が䞎えられる。行目に呜什の数 <var>Q</var> (1 &le; <var>Q</var> &le; 100000) が䞎えられる。続く <var>Q</var> 行に <var>i</var> 番目の呜什 <var>query<sub>i</sub></var> が䞎えられる。各 <var>query<sub>i</sub></var> は、以䞋のいずれかの圢匏で䞎えられる。 </p> <pre> set <var>x</var> <var>y</var> <var>z</var> </pre> <p> たたは </p> <pre> comp <var>a</var> <var>b</var> <var>c</var> <var>d</var> </pre> <p> set <var>x</var> <var>y</var> <var>z</var> は文字列 <var>U</var> の <var>x</var> 文字目から <var>y</var> 文字目たでを、指定された文字 <var>z</var> に眮き換えるこずを衚す。ただし、1 &le; <var>x</var> &le; <var>y</var> &le; <var>N</var> であり、<var>z</var> は英小文字である。 </p> <p> comp <var>a</var> <var>b</var> <var>c</var> <var>d</var> は文字列 <var>U</var> の <var>a</var> 文字目から <var>b</var> 文字目たでの郚分文字列を <var>S</var>、文字列 <var>U</var> の <var>c</var> 文字目から <var>d</var> 文字目たでの郚分文字列を <var>T</var> ずしたずき、文字列 <var>S</var> ず文字列 <var>T</var> を蟞曞順で比范するこずを衚す。ただし、1 &le; <var>a</var> &le; <var>b</var> &le; <var>N</var> か぀ 1 &le; <var>c</var> &le; <var>d</var> &le; <var>N</var> である。 </p> <h2>Output</h2> <p> 各 comp 呜什に぀いお、<var>S</var> の方が小さいならば「s」、<var>T</var> の方が小さいならば「t」、䞡者が䞀臎しおいるならば「e」ず行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 13 aizualgorithm 9 comp 1 1 4 5 comp 2 6 1 5 set 9 12 b comp 9 9 10 10 comp 5 8 1 4 set 1 10 z set 11 13 x comp 8 10 1 5 comp 1 5 1 5 </pre> <h2>Sample Output 1</h2> <pre> s t e t s e </pre>
p02697
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are going to hold a competition of one-to-one game called AtCoder Janken. <em>(Janken is the Japanese name for Rock-paper-scissors.)</em> <var>N</var> players will participate in this competition, and they are given distinct integers from <var>1</var> through <var>N</var>. The arena has <var>M</var> playing fields for two players. You need to assign each playing field two distinct integers between <var>1</var> and <var>N</var> (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of <var>N</var> rounds, each of which proceeds as follows:</p> <ul> <li>For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.</li> <li>Then, each player adds <var>1</var> to its integer. If it becomes <var>N+1</var>, change it to <var>1</var>.</li> </ul> <p>You want to ensure that no player fights the same opponent more than once during the <var>N</var> rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq M</var></li> <li><var>M \times 2 +1 \leq N \leq 200000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>M</var> lines in the format below. The <var>i</var>-th line should contain the two integers <var>a_i</var> and <var>b_i</var> assigned to the <var>i</var>-th playing field.</p> <pre><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> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 3 </pre> <p>Let us call the four players A, B, C, and D, and assume that they are initially given the integers <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>, respectively.</p> <ul> <li> <p>The <var>1</var>-st round is fought by B and C, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>2</var>, <var>3</var>, <var>4</var>, and <var>1</var>, respectively.</p> </li> <li> <p>The <var>2</var>-nd round is fought by A and B, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>3</var>, <var>4</var>, <var>1</var>, and <var>2</var>, respectively.</p> </li> <li> <p>The <var>3</var>-rd round is fought by D and A, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>4</var>, <var>1</var>, <var>2</var>, and <var>3</var>, respectively.</p> </li> <li> <p>The <var>4</var>-th round is fought by C and D, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>, respectively.</p> </li> </ul> <p>No player fights the same opponent more than once during the four rounds, so this solution will be accepted.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 6 2 5 3 4 </pre></section> </div> </span>
p03985
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Story</h3> <p>I am a Summoner who can invoke monsters. I can embody the pictures of monsters drawn on sketchbooks. <p>I recently have received a request from Primate Research Institute of Kyoto University to invoke "Hundred Eyes Monster". <p>What an great honor it is to contribute to the prosperity of the primate research of Kyoto University! I decided to paint an extremely high-quarity monster to the best of my ability. </p> <p>I have already painted the forehead and mouth and this time I am going to paint as many eyes as possible between the forehead and mouth. Well...I cannot wait to see the complete painting. <h3>Problem Statement</h3> <p> Two circles <var>A</var>, <var>B</var> are given on a two-dimensional plane. The coordinate of the center and radius of circle <var>A</var> is (<var>x_A</var>, <var>y_A</var>) and <var>r_A</var> respectively. The coordinate of the center and radius of circle <var>B</var> is (<var>x_B</var>, <var>y_B</var>) and <var>r_B</var> respectively. These two circles have no intersection inside. Here, we consider a set of circles <var>S</var> that satisfies the following conditions. </p> <ul> <li>Each circle in <var>S</var> touches both <var>A</var> and <var>B</var>, and does not have common points with them inside the circle. </li> <li>Any two different circles in <var>S</var> have no common points inside them. </li></ul> <p> Write a program that finds the maximum number of elements in <var>S</var>. </p> </p></p></p></section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq T \leq 50000</var></li> <li><var>-10^5 \leq x_A \leq 10^5</var></li> <li><var>-10^5 \leq y_A \leq 10^5</var></li> <li><var>-10^5 \leq x_B \leq 10^5</var></li> <li><var>-10^5 \leq y_B \leq 10^5</var></li> <li><var>1 \leq r_A \leq 10^5</var></li> <li><var>1 \leq r_B \leq 10^5</var></li> <li><var>{r_A}^2 + {r_B}^2 &lt; (x_A - x_B)^2 + (y_A - y_B)^2</var></li> <li>All values given as input are integers.</li> <li>It is guaranteed that, when the radiuses of <var>A</var> and <var>B</var> change by <var>0.0005</var>, the answer does not change.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>The input consists of multiple test cases and is given from Standard Input in the following format: <pre> <var>T</var> <var>testcase_1</var> : <var>testcase_T</var> </pre> Each test case is given with the following format. <pre> <var>x_A</var> <var>y_A</var> <var>r_A</var> <var>x_B</var> <var>y_B</var> <var>r_B</var> </pre> </p></section> </div> <div class="part"> <section> <h3>Output</h3> <p> The output consists of <var>T</var> lines. On line <var>i</var> (<var>1 \leq i \leq T</var>), putput the maximum number of elements in <var>S</var> in <var>i</var>-th test case. </p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 4 0 -3 2 0 3 2 0 0 9 8 8 2 0 0 9 10 10 5 0 0 707 1000 1000 707 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 3 10 21 180 </pre> You can arrange circles ,for example, like the following images in Sample 1, 2. <br/> <div style="text-align: center;"> <img src="/img/other/kupc2016/sushi/img00.png"/> <img src="/img/other/kupc2016/sushi/img01.png"/> </div> </section> </div> </span>
p00700
<h1> Exploring Caves </h1> <p>There are many caves deep in mountains found in the countryside. In legend, each cave has a treasure hidden within the farthest room from the cave's entrance. The Shogun has ordered his Samurais to explore these caves with Karakuri dolls (robots) and to find all treasures. These robots move in the caves and log relative distances and directions between rooms. </p> <p>Each room in a cave is mapped to a point on an integer grid (x, y &gt;= 0). For each cave, the robot always starts from its entrance, runs along the grid and returns to the entrance (which also serves as the exit). The treasure in each cave is hidden in the farthest room from the entrance, using Euclid distance for measurement, i.e. the distance of the room at point (x, y) from the entrance (0, 0) is defined as the square root of (x*x+y*y). If more than one room has the same farthest distance from the entrance, the treasure is hidden in the room having the greatest value of x. While the robot explores a cave, it records how it has moved. Each time it takes a new direction at a room, it notes the difference (dx, dy) from the last time it changed its direction. For example, suppose the robot is currently in the room at point (2, 4). If it moves to room (6, 4), the robot records (4, 0), i.e. dx=6-2 and dy=4-4. The first data is defined as the difference from the entrance. The following figure shows rooms in the first cave of the Sample Input. In the figure, the farthest room is the square root of 61 distant from the entrance. <br><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cave1" width="594" height="587"> </p> <p>Based on the records that the robots bring back, your job is to determine the rooms where treasures are hidden. </p> <h2>Input</h2> <p>In the first line of the input, an integer <i>N</i> showing the number of caves in the input is given. Integers <i>dx<sub>i</sub></i> and <i>dy<sub>i</sub></i> are <i>i</i>-th data showing the differences between rooms. Note that since the robot moves along the grid, either <i>dx<sub>i</sub></i> or <i>dy<sub>i</sub></i> is zero. An integer pair <i>dx<sub>i</sub></i> = <i>dy<sub>i</sub></i> = 0 signals the end of one cave's data which means the robot finished the exploration for the cave and returned back to the entrance. The coordinates are limited to (0,0)-(1000,1000). </p> <h2>Output</h2> <p>Print the position (x, y) of the treasure room on a line for each cave. </p> <h2>Sample Input</h2> <pre> 3 1 0 0 1 -1 0 1 0 0 5 -1 0 0 -1 5 0 0 1 0 -1 1 0 0 -4 -3 0 0 3 2 0 0 -2 -1 0 0 1 0 -1 1 0 0 2 -2 0 0 -3 3 0 0 4 -4 0 0 -5 -2 0 0 0 1 0 -1 0 0 0 2 0 0 1 -1 0 0 1 -1 0 0 -2 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 6 5 1 0 2 1 </pre>
p01812
<h2>真っ暗な郚屋</h2> <p> 目を芚たすず、A君は真っ暗な郚屋の䞭にいた。 どうやらA君は <var>N</var> 個の郚屋から構成されたダンゞョンに迷い蟌んでしたったようだ。 あなたはA君がどの郚屋に迷い蟌んだのかを知るこずはできなかったが、幞いにもダンゞョンのマップを手に入れるこずができた。 A君の進むべき道を瀺し明るい郚屋に導こう。 </p> <p> <var>N</var> 個の郚屋のうち <var>M</var> 個の郚屋が真っ暗な郚屋であり、それぞれ <var>D_1</var>, <var>D_2</var>, ..., <var>D_M</var> 番目の郚屋が真っ暗な郚屋であるこずが分かっおいる。 たた、党おの郚屋からちょうど <var>K</var> 本の䞀方通行の道が順に䞊んでおり、<var>i</var> 番目の郚屋から出る道はそれぞれ <var>v_{i,1}</var>, <var>v_{i,2}</var>, ..., <var>v_{i,K}</var> 番目の郚屋に繋がっおいる。 あなたは、A君に察し今いる郚屋から <var>a_1</var>, <var>a_2</var>, ..., <var>a_l</var> 番目の道を順に進たせるこずができる。 ただし、A君は明るい郚屋に到達したらそれ以降の指瀺は無芖する。 あなたは、指瀺の前埌においおA君が今いる郚屋の情報を知るこずはできないため、A君がどの郚屋にいたずしおも明るい郚屋に蟿り着けるような指瀺列を䌝えなければならない。 そのような指瀺のうち、最も短いものの長さを答えよ。 </p> <h3>Constraints</h3> <ul> <li><var>2 &le; N &le; 100</var></li> <li><var>1 &le; M &le; min(16, N &minus; 1)</var></li> <li><var>1 &le; K &le; N</var></li> <li><var>1 &le; D_i &le; N</var></li> <li><var>D_i</var> は党お異なる</li> <li><var>1 &le; v_{i, j} &le; N</var></li> <li> 党おの暗い郚屋は少なくずも1぀の明るい郚屋に到達可胜である </li> </ul> <h3>Input Format</h3> <p> 入力は以䞋の圢匏で暙準入力から䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>K</var> <var>D_1</var> <var>D_2</var> ... <var>D_M</var> <var>v_{1,1}</var> <var>v_{1,2}</var> ... <var>v_{1,K}</var> <var>v_{2,1}</var> <var>v_{2,2}</var> ... <var>v_{2,K}</var> ... <var>v_{N,1}</var> <var>v_{N,2}</var> ... <var>v_{N,K}</var> </pre> <h3>Output Format</h3> <p> 答えを䞀行に出力せよ。 </p> <h3>Sample Input 1</h3> <pre> 4 2 2 1 2 2 4 3 1 4 2 1 3 </pre> <h3>Sample Output 1</h3> <pre> 2 </pre> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_sample1"/> <br/> 1, 1 ずいう指瀺を出すず </p> <ul> <li>A君の初期䜍眮が郚屋1である堎合、2぀目の移動で郚屋3に到達する</li> <li>A君の初期䜍眮が郚屋2である堎合、1぀目の移動で郚屋3に到達する</li> </ul> <h3>Sample Input 2</h3> <pre> 3 2 2 1 2 2 3 1 2 2 1 </pre> <h3>Sample Output 2</h3> <pre> 3 </pre> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_sample2"/> <br/> 2, 1, 2 ずいう指瀺を出すず </p> <ul> <li>A君の初期䜍眮が郚屋1である堎合、1぀目の移動で郚屋3に到達する</li> <li>A君の初期䜍眮が郚屋2である堎合、3぀目の移動で郚屋3に到達する</li> </ul> <h3>Sample Input 3</h3> <pre> 6 3 3 1 2 3 4 1 1 2 5 2 3 3 6 4 4 4 5 5 5 6 6 6 </pre> <h3>Sample Output 3</h3> <pre> 3 </pre> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_sample3"/> <br/> 非連結であるケヌスや、自己蟺、倚重蟺があるケヌスに気を぀けよう </p>
p01541
<h1>ほそながいずころ</h1> <p> 高橋君は苹果(りんご)ちゃんずニュヌペヌクを芳光するこずになりたした。 高橋君は芳光するずころに特に垌望はなかったのですが、苹果ちゃんの熱烈な誘いにより、以䞋の地図にあるような&quot;ほそながいずころ&quot;を芳光するこずに決たりたした。 </p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_hosonaga" height="344" width="454"></center> <center>Google マップ - (C)2012 Google</center> <p> この&quot;ほそながいずころ&quot;はずおも现長く、盎線ずみなすこずができたす。たた、&quot;ほそながいずころ&quot;には片方の端にスタヌト地点が、もう片方の端にゎヌル地点があり、スタヌト地点からゎヌル地点ぞ向けお䜕台かの芳光甚の銬車が走っおいたす。この銬車は以䞋のようなルヌルに埓っお運行されおいたす。 </p> <ul> <li>銬車は<var>n</var>台あり、すべおの銬車はスタヌト地点から出発しおゎヌル地点たで進みたす。 </li><li>以䞋のすべおの堎合においお銬車の倧きさは無芖できたす。 </li><li>途䞭で速床を倉曎するこずが難しいため、すべおの銬車は銬車はそれぞれ1kmあたりを<var>S<sub>i</sub></var>(<var>S<sub>i</sub></var>は1以䞊の敎数)分の等速で進みたす。 </li><li>銬車には出発する順番が定められおおり、この順番を守らなければなりたせん。ただし、ゎヌル地点に到着する順番に぀いお特に決たりはありたせん。 </li><li>耇数の銬車はスタヌト地点を同時に発車するこずはできず、ある銬車が発車すれば次の銬車が発車するたでに1分以䞊間をあけなければなりたせん。 </li><li>ゎヌル地点は十分に広いため、䜕台の銬車が同時に到着しおも構いたせん。たた、ゎヌル地点に到着した銬車はそこで止たり、ずっずゎヌル地点にいたす。 </li><li>&quot;ほそながいずころ&quot;は倧倉现長いため銬車は基本的に同じ堎所に2台䞊ぶこずはできたせん。しかし、特別に&quot;すこしひろいずころ&quot;が<var>m</var>箇所あり、そこでのみ2台たで䞊ぶこずができ、ある銬車が別の銬車を远い抜くこずが可胜です。 </li></ul> <p> たた、先述した&quot;ほそながいずころ&quot;ず&quot;すこしひろいずころ&quot;に぀いお、以䞋の制玄を満たしたす。 </p> <ul> <li>スタヌト地点からゎヌル地点たでは盎線的に結ばれおおり、その距離は(<var>dist</var>)km(<var>dist</var>は1以䞊の敎数) </li><li><var>m</var>箇所の&quot;すこしひろいずころ&quot;はスタヌト地点からゎヌル地点たでのどこかにあり、それらはいずれもスタヌト地点およびゎヌル地点ずは重なりたせん。たた、それぞれの&quot;すこしひろいずころ&quot;はスタヌト地点からちょうど(<var>D<sub>i</sub></var>)km(<var>D<sub>i</sub></var>は1以䞊の敎数)の地点にありたす。 </li></ul> <p> これを聞いた高橋君は、以䞊に述べた銬車運行のルヌルを守り぀぀銬車の出発時刻を調敎するこずにより、1台目の銬車が発車しおからすべおの銬車が到着するたでにかかる時間を小さくできるこずを芋抜きたした。 高橋君の出した結果を知るために、 銬車の台数<var>n</var> , それぞれの銬車の速床に関するパラメヌタ<var>S<sub>i</sub></var>,&quot;ほそながいずころ&quot;䞊に存圚する&quot;すこしひろいずころ&quot;の総数<var>m</var> ,それぞれの&quot;すこしひろいずころ&quot;のスタヌト地点からの距離<var>D<sub>i</sub></var> が䞎えられるので、 1台目の銬車が発車しおからすべおの銬車が到着するたでにかかる時間の最小倀を求めるプログラムを曞くこずがあなたの仕事です。 なお、苹果ちゃんは&quot;ほそながいずころ&quot;での芳光を存分に楜しみたしたが、高橋君はこの芳光の埌には「ほそながかった 」ずしか぀ぶやかなかったそうです。 </p> <h2>Input</h2> <p> 入力圢匏は以䞋のようになっおいる。 </p> <blockquote> <var>dist</var><br><var>n</var><br><var>S<sub>1</sub></var><br><var>S<sub>2</sub></var><br>..<br><var>S<sub>n</sub></var><br><var>m</var><br><var>D<sub>1</sub></var><br><var>D<sub>2</sub></var><br>..<br><var>D<sub>m</sub></var><br></blockquote> <ul> <li><var>dist</var>はスタヌト地点からゎヌル地点たでの距離(km)を衚す </li><li><var>n</var>はスタヌト地点を発車する銬車の数を衚す </li><li><var>S<sub>i</sub></var>は銬車の速床を衚し、<var>i</var>番目に出発する銬車は1kmを<var>(S<sub>i</sub>)</var>分で進むこずを衚す。 </li><li><var>m</var>は&quot;すこしひろいずころ&quot;の総数を衚す </li><li><var>D<sub>i</sub></var>はスタヌト地点からそれぞれの&quot;すこしひろいずころ&quot;ぞの距離(km)を衚す。 </li></ul> <h2>Constraints</h2> <blockquote> <var>1&le;dist&le;100000000(10<sup>8</sup>)</var><br><var>1&le;n&le;5</var><br><var>0&le;m&le;5</var><br><var>1&le;S<sub>i</sub>&le;100</var><br><var>0&lt;D<sub>i</sub>&lt;dist</var><br><var>i&ne;j</var>ならば<var>D<sub>i</sub>&ne;D<sub>j</sub></var><br>入力に出珟する数はすべお敎数である。<br></blockquote> <ul> <li><var>i &lt; j</var>ならば、<var>i</var>番目に出発する銬車は<var>j</var>番目の銬車より1分以䞊早く出発しなければならない </li></ul> <h2>Output</h2> <p> 1台目の銬車が発車しおからすべおの銬車が到着するたでにかかる時間の最小倀を1行に出力せよ。単䜍は分である。 </p> <H2>Sample Input 1</H2> <pre>100 2 1 2 0 </pre> <H2>Output for the Sample Input 1</H2> <pre>201 </pre> <p> 2台目は1台目が出発した1分埌に出発する。 </p> <H2>Sample Input 2</H2> <pre>100 2 2 1 0 </pre> <H2>Output for the Sample Input 2</H2> <pre>200 </pre> <p> 2台目は1台目が出発した100分埌に出発し、ゎヌルで1台目に远い぀く。 </p> <H2>Sample Input 3</H2> <pre>100 3 2 1 1 1 50 </pre> <H2>Output for the Sample Input 3</H2> <pre>200 </pre> <p> 2台目は1台目が出発した50分埌に出発し、50mのひろいずころで1台目を抜く。<br> 3台目は1台目が出発した100分埌に出発し、ゎヌルで1台目に远い぀く。 </p> <H2>Sample Input 4</H2> <pre>100 4 3 1 1 3 2 40 60 </pre> <H2>Output for the Sample Input 4</H2> <pre>421 </pre>
p03086
<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 uppercase English letters. Find the length of the longest <em>ACGT string</em> that is a substring (see Notes) of <var>S</var>.</p> <p>Here, a ACGT string is a string that contains no characters other than <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>A substring of a string <var>T</var> is a string obtained by removing zero or more characters from the beginning and the end of <var>T</var>.</p> <p>For example, the substrings of <code>ATCODER</code> include <code>TCO</code>, <code>AT</code>, <code>CODER</code>, <code>ATCODER</code> and <code></code> (the empty string), but not <code>AC</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is a string of length between <var>1</var> and <var>10</var> (inclusive).</li> <li>Each character in <var>S</var> is an uppercase English letter.</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 length of the longest <em>ACGT string</em> that is a substring of <var>S</var>.</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>3 </pre> <p>Among the ACGT strings that are substrings of <code>ATCODER</code>, the longest one is <code>ATC</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>HATAGAYA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>Among the ACGT strings that are substrings of <code>HATAGAYA</code>, the longest one is <code>ATAGA</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>SHINJUKU </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>Among the ACGT strings that are substrings of <code>SHINJUKU</code>, the longest one is <code></code> (the empty string).</p></section> </div> </span>
p01111
<h3>Skyscraper "MinatoHarukas"</h3> <!-- end en only --> <!-- begin en only --> <p> Mr.&nbsp;Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show advertisement on as many vertically adjacent windows as possible. The rent for one floor is proportional to the floor number, that is, the rent per month for the <i>n</i>-th floor is <i>n</i> times that of the first floor. Here, the ground floor is called the first floor in the American style, and basement floors are out of consideration for the renting. In order to help Mr.&nbsp;Port, you should write a program that computes the vertically adjacent floors satisfying his requirement and whose total rental cost per month is <em><font color="#ff0000">exactly equal</font></em> to his budget. </p> <!-- end en only --> <!-- begin en only --> <p> For example, when his budget is 15 units, with one unit being the rent of the first floor, there are four possible rent plans, 1+2+3+4+5, 4+5+6, 7+8, and 15. For all of them, the sums are equal to 15. Of course in this example the rent of maximal number of the floors is that of 1+2+3+4+5, that is, the rent from the first floor to the fifth floor. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of multiple datasets, each in the following format. </p> <!-- end en only --> <blockquote> <p> <i>b</i> <br> </p> </blockquote> <!-- begin en only --> <p> A dataset consists of one line, the budget of Mr.&nbsp;Port <i>b</i> as multiples of the rent of the first floor. <i>b</i>&nbsp; is a positive integer satisfying 1 &lt; <i>b</i> &lt; 10<sup>9</sup>. </p> <p> The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 1000. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing two positive integers representing the plan with the maximal number of vertically adjacent floors with its rent price exactly equal to the budget of Mr.&nbsp;Port. The first should be the lowest floor number and the second should be the number of floors. </p> <!-- end en only --> <h3>Sample Input</h3> <pre>15 16 2 3 9699690 223092870 847288609 900660121 987698769 999999999 0 </pre> <h3>Output for the Sample Input</h3> <pre>1 5 16 1 2 1 1 2 16 4389 129 20995 4112949 206 15006 30011 46887 17718 163837 5994 </pre>
p01404
<h2> Problem G: 氎時蚈 </h2> <p> 琵琶湖の湖底から倉わった圢の氎時蚈のようなものが発芋された。 </p> <p> 氎時蚈は氎平な広い平面䞊に眮かれ、぀以䞊の䞀蟺が30cmの立方䜓の氎槜で構成されおいる。 氎槜は栌子状に䞊べられた様々な高さの台の䞊に眮かれおいる。氎槜の厚みは無芖できる。 同じ高さの台の䞊に眮かれた氎槜が前埌巊右に隣接しおいたずき、それらの氎槜の間には穎があけられ、氎の高さが等しく保たれる仕組みになっおいる。(図1) </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_G1"> </td> </tr> <tr> <td> <center>図1</center> </td> </tr> </table> </center> <p> 䞀緒に発芋された文献によるず、ある氎槜に氎を継続的に泚ぎ、他の特定の氎槜の氎䜍を調べおいたらしい。 </p> <p> 図2のようにある氎槜に氎を泚ぎ、氎があふれたずき、あふれた氎はその氎槜に隣接しおいる方向に等しい量流れ蟌む。氎槜がない堎所に氎が流れた堎合、氎時蚈の倖に自動的に排氎される。 たた氎があふれる方向がなくずも、氎槜の容量より倚い氎が栌子内にずどたるこずはない。そのような堎合、氎槜の容量を超えた分の氎は䞍思議な力で消滅する。 隣接しおいる氎槜が、もずの氎槜より少しでも高い台に眮かれおいたずき、その方向に氎は流れないので泚意するこず。 䟋えば図3の堎合、䞭倮の氎槜から巊右ず奥の氎槜にそれぞれあふれた量の1/4ず぀の氎が流れ蟌む。 </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_G2"> </td> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_G3"> </td> </tr> <tr> <td> <center>図2</center> </td> <td> <center>図3</center> </td> </tr> </table> </center> <p> あなたの仕事はこの氎時蚈をシミュレヌトするプログラムを曞く事である。 </p> <h2> Input </h2> <p> 入力は耇数のデヌタセットからなる。 デヌタセットの個数は、300以䞋で、それぞれが以䞋の圢匏である。 </p> <pre> <i>w</i> <i>h</i> <i>f<sub>x</sub></i> <i>f<sub>y</sub></i> <i>f<sub>q</sub></i> <i>p<sub>0,0</sub></i> <i>p<sub>0,1</sub></i> ... <i>p<sub>0,w-1</sub></i> <i>p<sub>1,0</sub></i> <i>p<sub>1,1</sub></i> ... <i>p<sub>1,w-1</sub></i> ... <i>p<sub>h-1,0</sub></i> <i>p<sub>h-1,1</sub></i> ... <i>p<sub>h-1,w-1</sub></i> <i>l</i> <i>t<sub>1</sub></i> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i> ... <i>t<sub>l</sub></i> <i>x<sub>l</sub></i> <i>y<sub>l</sub></i> </pre> <p> <i>w</i>、<i>h</i>は、それぞれ栌子の列および行の数を衚す正の敎数であり、それぞれ<i>1 &le; w &le; 10</i>、<i>1 &le; h &le; 10</i>を満たす。 <i>f<sub>x</sub></i>、<i>f<sub>y</sub></i>、<i>f<sub>q</sub></i>は氎を流す氎槜が眮いおいる栌子の堎所(<i>f<sub>x</sub></i>、<i>f<sub>y</sub></i>)ず流量(<i>f<sub>q</sub></i>)を衚す。流量の単䜍は<i>cm^3</i>である。 これらは<i>0 &le; f<sub>x</sub> &lt; w</i>、<i>0 &le; f<sub>y</sub> &lt; h</i>、<i>1 &le; f<sub>q</sub> &le; 30000</i>を満たす。 続く<i>h</i>行はそれぞれスペヌスで区切られた<i>w</i>個の数字から構成されおおり、 栌子{<i>i</i>,<i>j</i>}に眮ける氎槜の眮かれた台の高さを衚す。 単䜍は<i>cm</i>であり、<i>0 &le; p<sub>i,j</sub> &le; 1000</i>を満たす敎数である。 <i>p<sub>i,j</sub>=0</i>のずき、その堎所には氎槜は眮かれおいない。 次の䞀行は氎槜の氎の高さの枬定回数を衚す正の敎数<i>l</i>からなる。 これは<i>1 &le; l &le; 10</i>を満たす。 続く<i>l</i>行はスペヌスで区切られた<i>t<sub>k</sub></i>、<i>x<sub>k</sub></i>、<i>y<sub>k</sub></i>の3぀の敎数倀を含んでいる。 <i>t<sub>k</sub></i>は枬定時間を衚し、<i>x<sub>k</sub></i>、<i>y<sub>k</sub></i>は枬定堎所の栌子を瀺す。 <i>x<sub>k</sub></i>、<i>y<sub>k</sub></i>は必ず氎槜のある栌子を瀺すず仮定しおよい。 たた、<i>0 &le; t &le; 10000</i>を満たす。 </p> <p> 入力の終わりはふた぀のれロを含む行で衚される。 </p> <h2> Output </h2> <p> 各デヌタセットに察し、敎数を<i>l</i>個出力する。 その敎数は指定された時間<i>t<sub>k</sub></i>における 栌子<i>x<sub>k</sub></i>、<i>y<sub>k</sub></i>䞊にある氎槜の氎の高さを出力するこず。 なお、氎の高さの小数点以䞋は切り捚おずする。 </p> <h2> Sample Input </h2> <pre> 3 3 1 1 900 0 10 0 10 45 10 10 0 0 3 5 1 1 50 1 0 100 0 1 5 5 2 0 9000 0 0 4 0 0 0 3 3 3 0 2 2 2 2 2 0 0 1 0 0 0 0 1 0 0 4 5 2 0 10 2 1 100 2 2 250 2 3 0 0 </pre> <h2> Output for Sample Input </h2> <pre> 5 5 8 30 5 13 4 </pre>
p03439
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><font color="red"><strong>This is an interactive task.</strong></font></p> <p>Let <var>N</var> be an odd number at least <var>3</var>.</p> <p>There are <var>N</var> seats arranged in a circle. The seats are numbered <var>0</var> through <var>N-1</var>. For each <var>i</var> (<var>0 ≀ i ≀ N - 2</var>), Seat <var>i</var> and Seat <var>i + 1</var> are adjacent. Also, Seat <var>N - 1</var> and Seat <var>0</var> are adjacent.</p> <p>Each seat is either vacant, or oppupied by a man or a woman. However, no two adjacent seats are occupied by two people of the same sex. It can be shown that there is at least one empty seat where <var>N</var> is an odd number at least <var>3</var>.</p> <p>You are given <var>N</var>, but the states of the seats are not given. Your objective is to correctly guess the ID number of any one of the empty seats. To do so, you can repeatedly send the following query:</p> <ul> <li>Choose an integer <var>i</var> (<var>0 ≀ i ≀ N - 1</var>). If Seat <var>i</var> is empty, the problem is solved. Otherwise, you are notified of the sex of the person in Seat <var>i</var>.</li> </ul> <p>Guess the ID number of an empty seat by sending at most <var>20</var> queries.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an odd number.</li> <li><var>3 ≀ N ≀ 99</var> <var>999</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Input and Output</h3><p>First, <var>N</var> is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> <p>Then, you should send queries. A query should be printed to Standart Output in the following format. Print a newline at the end.</p> <pre><var>i</var> </pre> <p>The response to the query is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> <p>Here, <var>s</var> is <code>Vacant</code>, <code>Male</code> or <code>Female</code>. Each of these means that Seat <var>i</var> is empty, occupied by a man and occupied by a woman, respectively.</p> </section> </div> <div class="part"> <section> <h3>Notice</h3><ul> <li>Flush Standard Output each time you print something. Failure to do so may result in <code>TLE</code>.</li> <li>Immediately terminate the program when <var>s</var> is <code>Vacant</code>. Otherwise, the verdict is indeterminate.</li> <li>The verdict is indeterminate if more than <var>20</var> queries or ill-formatted queries are sent.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input / Output 1</h3> <p>In this sample, <var>N = 3</var>, and Seat <var>0</var>, <var>1</var>, <var>2</var> are occupied by a man, occupied by a woman and vacant, respectively.</p> <table class="table-striped table-bordered table-condensed"> <thead> <tr><th width="200">Input</th><th width="200">Output</th></tr> </thead> <tbody> <tr><td>3</td><td></td></tr> <tr><td></td><td>0</td></tr> <tr><td>Male</td><td></td></tr> <tr><td></td><td>1</td></tr> <tr><td>Female</td><td></td></tr> <tr><td></td><td>2</td></tr> <tr><td>Vacant</td><td></td></tr> </tbody> </table> </section> </div> </span>
p03593
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have an <var>H</var>-by-<var>W</var> matrix. Let <var>a_{ij}</var> be the element at the <var>i</var>-th row from the top and <var>j</var>-th column from the left. In this matrix, each <var>a_{ij}</var> is a lowercase English letter.</p> <p>Snuke is creating another <var>H</var>-by-<var>W</var> matrix, <var>A'</var>, by freely rearranging the elements in <var>A</var>. Here, he wants to satisfy the following condition:</p> <ul> <li>Every row and column in <var>A'</var> can be read as a palindrome.</li> </ul> <p>Determine whether he can create a matrix satisfying the condition.</p> </section> </div> <div class="part"> <section> <h3>Note</h3><p>A <em>palindrome</em> is a string that reads the same forward and backward. For example, <code>a</code>, <code>aa</code>, <code>abba</code> and <code>abcba</code> are all palindromes, while <code>ab</code>, <code>abab</code> and <code>abcda</code> are not.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ H, W ≀ 100</var></li> <li><var>a_{ij}</var> is a lowercase English letter.</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>a_{11}</var><var>a_{12}</var><var>...</var><var>a_{1W}</var> <var>:</var> <var>a_{H1}</var><var>a_{H2}</var><var>...</var><var>a_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Snuke can create a matrix satisfying the condition, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 aabb aabb aacc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>For example, the following matrix satisfies the condition.</p> <pre>abba acca abba </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 aa bb </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>It is not possible to create a matrix satisfying the condition, no matter how we rearrange the elements in <var>A</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 t w e e t </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre> <p>For example, the following matrix satisfies the condition.</p> <pre>t e w e t </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>2 5 abxba abyba </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>1 1 z </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>Yes </pre></section> </div> </span>
p01054
<h1>String Conversion</h1> <h2>Problem</h2> <p> ゞェニファヌずマリアンはカヌラに文字列<var>S</var>をプレれントしたした。<br> しかし、カヌラは文字列<var>S</var>をもらっおも嬉しくありたせん。<br> 文字列<var>T</var>が欲しかったのです。<br> 3人は協力しお文字列<var>S</var>を文字列<var>T</var>に倉えるこずにしたした。<br> </p> <p> 最初にゞェニファヌが文字を任意の順番に䞊び替えたす。 </p> <p> 次にマリアンが皮類のアルファベットの小文字を亀換するこずを任意の回数行いたす。<br> この操䜜では、䟋えば以䞋のように、文字列䞭の同じ文字が党お亀換されたす。<br> </p> <ul> <li><var>aab</var> &rarr; <var>a</var>ず<var>b</var>を亀換 &rarr; <var>bba</var></li> <li><var>aab</var> &rarr; <var>a</var>ず<var>c</var>を亀換 &rarr; <var>ccb</var></li> </ul> <p> 最埌にカヌラがある1文字を別の1文字に眮換するこずを<var>T</var>になるたで繰り返したす。<br> ゞェニファヌずマリアンはカヌラの眮換回数が少なくなるようにしおあげるこずにしたした。<br> カヌラが行う眮換の回数の最小倀を求めおください。 </p> <h2>Input</h2> <pre> <var>n</var> <var>S</var> <var>T</var> </pre> <p> 1行目に文字列の長さ<var>n</var>が䞎えられる。<br> 2行目に文字列<var>S</var>、3行目に文字列<var>T</var>が䞎えられる。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>n</var> &le; 10<sup>5</sup></li> <li><var>S</var>,<var>T</var>は<var>'a'~'z'</var>のみを含む</li> <li>|<var>S</var>| = |<var>T</var>| = <var>n</var></li> </ul> <h2>Output</h2> <p> カヌラの最少の眮換回数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 abc xyz </pre> <h2>Sample Output 1</h2> <pre> 0 </pre> <h2>Sample Input 2</h2> <pre> 5 aaabb xyxyz </pre> <h2>Sample Output 2</h2> <pre> 1 </pre>
p03069
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> stones arranged in a row. Every stone is painted white or black. A string <var>S</var> represents the color of the stones. The <var>i</var>-th stone from the left is white if the <var>i</var>-th character of <var>S</var> is <code>.</code>, and the stone is black if the character is <code>#</code>.</p> <p>Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2\times 10^5</var></li> <li><var>S</var> is a string of length <var>N</var> consisting of <code>.</code> and <code>#</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of stones that needs to be recolored.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 #.# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>It is enough to change the color of the first stone to white.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 #.##. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 ......... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p02228
a
p00215
<H1>パチモンクリヌチャヌ</H1> <p> 某囜で<!--爆発的-->倧人気のゲヌム、パチモンクリヌチャヌが日本でリメむクされお発売されたした。 ゲヌムが倧奜きなあなたは、 このゲヌムを<!--今たで貯めたお小遣いで賌入し、䜕床もプレむしたした。そしお、-->䜕床もプレむするうちにどうしたら最速でクリアできるのか考えるようになりたした。しかし、いくら考えおも最速の攻略方法がわからなかったあなたは、どれだけ早くゲヌムをクリアできるかを求めるプログラムを䜜成するこずにしたした。 </p> <p> ゲヌムの詳现は以䞋の通りです。 </p> <!-- <p> パチモンクリヌチャヌ(以䞋、パチクリ)ずいう生物が倚く存圚する䞖界がゲヌムの舞台です。各パチクリは、火属性、氷属性、朚属性、土属性、氎属性の 5 皮類の属性のいずれか䞀属性を持ちたす。ゲヌムの䞻人公である E 君は、近所に䜏んでいる芪切なおじさんから奜きな属性のパチクリ䞀匹を冒険のパヌトナヌずしお受け取りたす。そのパチクリず共にゎヌルを目指し、ゎヌルにいるラむバルを倒しおパチクリマスタヌになるこずが䞻人公の倢であり、ゲヌムクリアでもありたす。 </p> --> <p> パチモンクリヌチャヌ(以䞋、パチクリ)ずいう生物が倚く存圚する䞖界がゲヌムの舞台です。各パチクリは、火属性、氷属性、朚属性、土属性、氎属性の 5 皮類の属性のいずれか぀の属性を持ちたす。ゲヌムの䞻人公は、ゲヌム開始時に奜きな属性のパチクリ䞀匹を冒険のパヌトナヌずしお遞びたす。そのパチクリず共にゎヌルを目指し、ゎヌルにいるラむバルを倒しおパチクリマスタヌになるこずがゲヌムの目的です。 </p> <p> しかし、ラむバルを倒すためには党属性のパチクリがいないず勝おないので、途䞭で党属性のパチクリを捕たえなければなりたせん。パチクリを捕たえるには属性がカギずなりたす。火属性のパチクリは氷属性のパチクリを捕たえるこずができ、同様に、氷属性は朚属性、朚属性は土属性、土属性は氎属性、氎属性は火属性を捕たえるこずができたす。属性の関連は以䞋の図のようになりたす。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pachimon1" width="30%" > </center> <br> <p> 以䞋の図はゲヌムが行われるマップの䞀䟋を衚しおいたす。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_pachimon2" width="60%" > </center> <br> <p> 䞻人公はパチクリを䞀匹もっおスタヌト地点である「S」から出発し、䞀マスず぀移動しながらゎヌル地点である「G」を目指したす。その途䞭で、最初に持っおいるパチクリ以倖の 4 ぀の属性のパチクリを捕たえ、ゎヌル地点であるマス目に移動するずゲヌム終了ずなりたす。 </p> <p> 䞻人公は、今いるマス目から、蟺を共有する隣のマス目に移動するこずができ、それを䞀回の移動ず数えたす。䞻人公がパチクリのいるマスに移動した堎合、そのパチクリを捕たえられる属性のパチクリを持っおいればそのパチクリを捕たえたこずになりたす。そのマスにいるパチクリを捕たえられるかの可吊にかかわらず、すべおのマスに䜕床でも移動するこずができたす。 </p> <p> マップの倧きさ(暪方向の列数、瞊方向の行数)ずマップの初期状態を入力ずし、初めに遞んだパチクリの属性ず、それ以倖の 4 ぀の属性のパチクリを捕たえるのにかかる、スタヌト地点からゎヌル地点に至る最小移動数を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終りはれロふた぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>W</var> <var>H</var> <var>c<sub>11</sub></var><var>c<sub>12</sub></var>...<var>c<sub>1W</sub></var> <var>c<sub>21</sub></var><var>c<sub>22</sub></var>...<var>c<sub>2W</sub></var> : <var>c<sub>H1</sub></var><var>c<sub>H2</sub></var>...<var>c<sub>HW</sub></var> </pre> <p> 1 行目にマップの暪方向の列数 <var>W</var> ず瞊方向の行数 <var>H</var> (2 &le; <var>W, H</var> &le; 1000) が䞎えられたす。続く <var>H</var> 行にマップの <var>i</var> 行目の情報が䞎えられたす。入力されるマップには各マスの状態が䞎えられたす。 「S」は䞻人公のスタヌト地点を、 「G」はゎヌル地点を、「1」「2」「3」「4」「5」はそこにいるパチクリの属性を( 1:火属性、 2:氷属性、 3:朚属性、 4:土属性、 5:氎属性 をそれぞれ衚したす)、 「.(ピリオド) 」は䜕もないマスをそれぞれ衚したす。 各属性のパチクリの数はそれぞれ 0 以䞊 1000 以䞋ずしたす。 </p> <p> デヌタセットの数は140 を超えたせん。たた、デヌタセットの 80 % に぀いお、<var>W, H</var> は100 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、最初に遞んだパチクリの属性ず最小移動数を行に出力したす。なお、どのように初めのパチクリを遞んでも、どのような経路で移動しおもそれら 4 ぀の属性のパチクリを捕たえるこずができない堎合は NA ず出力しおください。 たた、最小移動数が同じになるような最初のパチクリの遞び方が耇数ある堎合は、属性の数字が小さいものを出力しおください。 </p> <H2>Sample Input</H2> <pre> 6 6 S.1..4 3..5.. ..4.1. 4....5 .2.32. 5.1..G 3 2 ... S.G 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 10 NA </pre>
p02382
<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>Distance II</h1><br> <p> Your task is to calculate the distance between two $n$ dimensional vectors $x = \{x_1, x_2, ..., x_n\}$ and $y = \{y_1, y_2, ..., y_n\}$. </p> <p> The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance. <br> \[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \] <br> It can be the Manhattan distance <br> \[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \] <br> where $p = 1 $. <br> <br> It can be the Euclidean distance <br> \[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n - y_n|)^{2}} \] <br> where $p = 2 $. <br> <br> Also, it can be the Chebyshev distance <br> <br> \[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \] <br> <br> where $p = \infty$ </p> <p> Write a program which reads two $n$ dimensional vectors $x$ and $y$, and calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. </p> <h2>Input</h2> <p> In the first line, an integer $n$ is given. In the second and third line, $x = \{x_1, x_2, ... x_n\}$ and $y = \{y_1, y_2, ... y_n\}$ are given respectively. The elements in $x$ and $y$ are given in integers. </p> <h2>Output</h2> <p> Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively. The output should not contain an absolute error greater than 10<sup>-5</sup>. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 100$</li> <li>$0 \leq x_i, y_i \leq 1000$</li> </ul> <h2>Sample Input</h2> <pre> 3 1 2 3 2 0 4 </pre> <h2>Sample Output</h2> <pre> 4.000000 2.449490 2.154435 2.000000 </pre>
p02678
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There is a cave.</p> <p>The cave has <var>N</var> rooms and <var>M</var> passages. The rooms are numbered <var>1</var> to <var>N</var>, and the passages are numbered <var>1</var> to <var>M</var>. Passage <var>i</var> connects Room <var>A_i</var> and Room <var>B_i</var> bidirectionally. One can travel between any two rooms by traversing passages. Room <var>1</var> is a special room with an entrance from the outside.</p> <p>It is dark in the cave, so we have decided to place a signpost in each room except Room <var>1</var>. The signpost in each room will point to one of the rooms directly connected to that room with a passage.</p> <p>Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room <var>1</var>.</p> <ul> <li>If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room <var>1</var> after traversing the minimum number of passages possible.</li> </ul> <p>Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>All values in input are integers.</li> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq M \leq 2 \times 10^5</var></li> <li><var>1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)</var></li> <li><var>A_i \neq B_i\ (1 \leq i \leq M)</var></li> <li>One can travel between any two rooms by traversing passages.</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>:</var> <var>A_M</var> <var>B_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If there is no way to place signposts satisfying the objective, print <code>No</code>.</p> <p>Otherwise, print <var>N</var> lines. The first line should contain <code>Yes</code>, and the <var>i</var>-th line <var>(2 \leq i \leq N)</var> should contain the integer representing the room indicated by the signpost in Room <var>i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 1 2 2 3 3 4 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes 1 2 2 </pre> <p>If we place the signposts as described in the sample output, the following happens:</p> <ul> <li>Starting in Room <var>2</var>, you will reach Room <var>1</var> after traversing one passage: <var>(2) \to 1</var>. This is the minimum number of passages possible.</li> <li>Starting in Room <var>3</var>, you will reach Room <var>1</var> after traversing two passages: <var>(3) \to 2 \to 1</var>. This is the minimum number of passages possible.</li> <li>Starting in Room <var>4</var>, you will reach Room <var>1</var> after traversing two passages: <var>(4) \to 2 \to 1</var>. This is the minimum number of passages possible.</li> </ul> <p>Thus, the objective is satisfied.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 9 3 4 6 1 2 4 5 3 4 6 1 5 6 2 4 5 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes 6 5 5 1 1 </pre> <p>If there are multiple solutions, any of them will be accepted.</p></section> </div> </span>
p00645
<H1><font color="#000000">Problem I:</font> Mysterious Onslaught</H1> <p> In 2012, human beings have been exposed to fierce onslaught of unidentified mysterious extra-terrestrial creatures. We have exhaused because of the long war and can't regist against them any longer. Only you, an excellent wizard, can save us. Yes, it's time to stand up! </p> <p> The enemies are dispatched to the earth with being aligned like an <i>n</i> * <i>n</i> square. Appearently some of them have already lost their fighting capabilities for some unexpected reason. You have invented a highest grade magic spell 'MYON' to defeat them all. An attack of this magic covers any rectangles (which is parallel to axis). Once you cast a spell "myon," then all the enemies which the magic covers will lose their fighting capabilities because of tremendous power of the magic. However, the magic seems to activate enemies' self-repairing circuit. Therefore if any enemy which have already lost its fighting capability is exposed to the magic, the enemy repossesses its fighting capability. You will win the war when all the enemies will lose their fighting capabilities. </p> <p> Let me show an example. An array of enemies below have dispatched: </p> <pre> 1 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 1 1 1 1 </pre> <p> Here, '<span>0</span>' means an enemy that doesn't possess fighting capability, and '<span>1</span>' means an enemy that possesses. First, you cast a spell "<span>myon</span>" with covering all the enemies, which results in; </p> <pre> 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 </pre> <p> Next, cast once again with covering central 3 * 3 enemies. </p> <pre> 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 </pre> <p> Now you can defeat them all by casting a spell covers remaining one. Therefore you can cast "<span>myonmyonmyon</span>," which is the shortest spell for this case. </p> <p> You are given the information of the array. Please write a program that generates the shortest spell that can defeat them all. </p> <H2>Input</H2> <p> The first line of each test case has an integer <i>n</i>. Following <i>n</i> lines are information of an array of enemies. The format is same as described in the problem statement. </p> <p> Input terminates when n = 0. You may assume that one or more enemy have fighting capability. </p> <H2>Output</H2> <p> For each dataset, output the shortest spell. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>n</i> &le; 5</li> </ul> <H2>Sample Input</H2> <pre> 5 1 1 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 5 1 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> myonmyonmyon myon myonmyon </pre>
p01957
<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> Tournament Chart </H1> <p> In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events. </p> <p> JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '<span>[[a-b]-[c-d]]</span>' is an easy example. In this case, there are 4 contestants named a, b, c, and d, and all matches are described as follows: </p> <ul> <li>Match 1 is the match between a and b.</li> <li>Match 2 is the match between c and d.</li> <li>Match 3 is the match between [the winner of match 1] and [the winner of match 2].</li> </ul> <p> More precisely, the tournament chart satisfies the following BNF: </p> <ul> <li>&lt;winner&gt; ::= &lt;person&gt; | "[" &lt;winner&gt; "-" &lt;winner&gt; "]"</li> <li>&lt;person&gt; ::= "a" | "b" | "c" | ... | "z"</li> </ul> <p> You, the chairperson of JAG, are planning to announce the results of this year's JAG competition. However, you made a mistake and lost the results of all the matches. Fortunately, you found the tournament chart that was printed before all of the matches of the tournament. Of course, it does not contains results at all. Therefore, you asked every contestant for the number of wins in the tournament, and got $N$ pieces of information in the form of "The contestant $a_i$ won $v_i$ times". </p> <p> Now, your job is to determine whether all of these replies can be true. </p> <H2>Input</H2> <p> The input consists of a single test case in the format below. </p> <pre> $S$ $a_1$ $v_1$ : $a_N$ $v_N$ </pre> <p> $S$ represents the tournament chart. $S$ satisfies the above BNF. The following $N$ lines represent the information of the number of wins. The ($i+1$)-th line consists of a lowercase letter $a_i$ and a non-negative integer $v_i$ ($v_i \leq 26$) separated by a space, and this means that the contestant $a_i$ won $v_i$ times. Note that $N$ ($2 \leq N \leq 26$) means that the number of contestants and it can be identified by string $S$. You can assume that each letter $a_i$ is distinct. It is guaranteed that $S$ contains each $a_i$ exactly once and doesn't contain any other lowercase letters. </p> <H2>Output</H2> <p> Print '<span>Yes</span>' in one line if replies are all valid for the tournament chart. Otherwise, print '<span>No</span>' in one line. </p> <H2>Sample Input 1</H2> <pre> [[m-y]-[a-o]] o 0 a 1 y 2 m 0 </pre> <H2>Output for Sample Input 1</H2> <pre> Yes </pre> <H2>Sample Input 2</H2> <pre> [[r-i]-[m-e]] e 0 r 1 i 1 m 2 </pre> <H2>Output for Sample Input 2</H2> <pre> No </pre>
p00995
<h1>Problem F : Dungeon (I)</h1> <p> あなたはずあるゲヌムの開発に携わっおいる。 そのゲヌムはランダムに生成されたダンゞョンをプレむダヌが探玢するずいうものである。 </p> <p> このゲヌムで生成されるダンゞョンには<i>n</i> 個の郚屋が存圚しおおり、0から <i>n-1</i> たでの番号が割り振られおいる。 郚屋ず郚屋は通路で結ばれおいる。郚屋ず郚屋を結ぶ通路は、<i>m</i> 本ある。 通路はどちらの方向ぞも進むこずができる。 たた、郚屋ず郚屋の間には距離が蚭定されおいる。 生成されたダンゞョンではいく぀かの通路を経由しお、ある郚屋から他のすべおの郚屋ぞ行くこずが可胜である。 そしお、プレむダヌがゲヌムを行う際に、0番の郚屋がスタヌト地点、<i>n-1</i> 番の郚屋がゎヌル地点ずしお遞ばれる。 </p> <p> ナヌザヌがダンゞョンを探玢する際に、手助けになるようなアむテムが入った宝箱を、どこかの郚屋に蚭眮したい。 その時に、スタヌト地点から遠すぎたり、ゎヌル地点から近すぎるず意味がない。 そこで、スタヌトから距離 <i>fs</i> 以内で蟿り぀けお、ゎヌルに蟿り着くために最短経路を通った堎合に、少なくずも <i>fg</i> かかる郚屋を宝箱を蚭眮する候補ずしたい。 </p> <p> 生成されたダンゞョンず、<i>q</i> が䞎えられる。<i>q</i> 個のク゚リヌに぀いお、宝箱を蚭眮する堎所の候補の数を数えお欲しい。 </p> <h2>Input</h2> <p> 入力は以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>n</i> <i>m</i> <i>a<sub>1</sub></i> <i>b<sub>1</sub></i> <i>c<sub>1</i></i> . . . <i>a<sub>m</sub></i> <i>b<sub>m</sub></i> <i>c<sub>m</i></i> <i>q</i> <i>fs<sub>1</sub></i> <i>fg<sub>1</sub></i> . . . <i>fs<sub>q</sub></i> <i>fg<sub>q</sub></i> </pre> <p> <i>a<sub>i</sub></i> <i>b<sub>i</sub></i> <i>c<sub>i</sub></i> は 郚屋 <i>a<sub>i</sub></i> ず <i>b<sub>i</sub></i> を結ぶ通路の距離が<i>c<sub>i</sub></i>であるこずを衚す。 </p> <p> 入力は以䞋の制玄を満たす<br> 2 &le; <i>n</i> &le; 100,000 <br> 0 &le; <i>a<sub>i</sub></i> , <i>b<sub>i</sub></i> &lt; <i>n</i><br> 0 &le; <i>c<sub>i</sub></i> &le; 100,000<br> <i>n-1</i> &le; <i>m</i> &le; 100,000<br> 1 &le; <i>q</i> &le; 100,000<br> 0 &le; <i>fs<sub>i</sub></i> , <i>fg<sub>i</sub></i> &le; 2<sup>60</sup> </p> <h2>Output</h2> <p> 各ク゚リヌに぀いお、答えの倀を1行に出力せよ </p> <h2>Sample Input 1</h2> <pre> 4 4 0 1 3 1 3 4 0 2 2 2 3 1 4 0 0 2 2 2 1 3 4 </pre> <h2>Sample Output 1</h2> <pre> 1 1 2 1 </pre>
p01687
<h2>A - D's Ambition / Dのやがう</h2> <h3>Story</h3> <p>あいずにゃんは若ヶ束高校のプログラミングコンテスト郚、通称ぷろこん郚に所属する2幎生である。かわいい。Dのひずは倩䜿のごずくかわいいあいずにゃんにぞっこんであり、隙あらばぺろぺろしようず画策する倉態である。その愛は猟奇的であり、あいずにゃんを自分色に染めようず、&quot;AIZUNYAN&quot;ずいう文字列を芋る床&quot;AIDUNYAN&quot;に曞き換えおしたう。さらにあいずにゃんを自分だけのものにするため、他の人に気づかれないようにその文字列をバラバラに䞊べ替えおしたう。プロコンの名門・埋呜通倧孊䞭等郚卒の゚リヌト競技プログラマであり、ぷろこん郚の郚長であるりっ぀ちゃんは、あいずにゃんをDのひずの魔の手から救うため、Dのひずが改倉した文字列をすべお埩元するこずにした。</p> <h3>Problem</h3> <p>英倧文字のみからなる文字列<var>Z</var>がある。文字列<var>Z</var>䞭に珟れるすべおの郚分文字列&quot;AIZUNYAN&quot;に察し、個別に&quot;AIDUNYAN&quot;の任意のアナグラムを生成し、眮き換えるこずで埗られた文字列を<var>D</var>ずする。ここで、文字列<var>S</var>のアナグラムずは、<var>S</var>に珟れる文字を䞊び替えお埗られる文字列のこずをいう。文字列<var>D</var>が入力ずしお䞎えられるので、文字列<var>Z</var>を埩元せよ。 ただし、文字列<var>D</var>に含たれる&quot;AIDUNYAN&quot;のアナグラムはすべお、&quot;AIZUNYAN&quot;から眮き換えられたもののみであるず仮定しおよい。たた、<var>D</var>䞭の任意の文字<var>D_i</var>に぀いお、<var>D_i</var>を含み、か぀&quot;AIDUNYAN&quot;のアナグラムである郚分文字列は高々1぀しかないず仮定しおよい。</p> <h3>Input</h3> <pre><var>D</var></pre> <p>入力は<var>1</var>行で䞎えられ、英倧文字のみからなる文字列<var>D</var>を含む。文字列<var>D</var>の長さ|<var>D</var>|は<var>1 \leq |D| \leq 10^3</var>を満たす。</p> <h3>Output</h3> <p><var>D</var>を埩元した文字列<var>Z</var>を<var>1</var>行に出力せよ。行の最埌では必ず改行を行うこず。</p> <h3>Sample Input 1</h3> <pre>AIDUNYAN</pre> <h3>Sample Output 1</h3> <pre>AIZUNYAN</pre> <p>Dの魔の手から救うこずができた。</p> <h3>Sample Input 2</h3> <pre>ZDD</pre> <h3>Sample Output 2</h3> <pre>ZDD</pre> <p>文字列長が<var>8</var>文字未満であったり、&quot;AIDUNYAN&quot;のアナグラムを含たないこずもある。</p> <h3>Sample Input 3</h3> <pre>AADINNUYHAMAJIDETENSHIDAKARANYANAIDUPEROPEROSHITAI</pre> <h3>Sample Output 3</h3> <pre>AIZUNYANHAMAJIDETENSHIDAKARAAIZUNYANPEROPEROSHITAI</pre> <p><var>2</var>箇所以䞊含たれおいる堎合はすべお埩元する。ぺろぺろ。</p> <h3>Sample Input 4</h3> <pre>NYANAIDUAIDU</pre> <h3>Sample Output 4</h3> <pre>AIZUNYANAIDU</pre> <p>埩元埌の文字列<var>Z</var>に&quot;AIDUNYAN&quot;のアナグラムが珟れる堎合もあるが、埩元前の文字列<var>D</var>においおアナグラムでない郚分ならば倉曎しないこずに泚意せよ。</p>
p03340
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an integer sequence <var>A</var> of length <var>N</var>.</p> <p>Find the number of the pairs of integers <var>l</var> and <var>r</var> (<var>1 \leq l \leq r \leq N</var>) that satisfy the following condition:</p> <ul> <li><var>A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r</var></li> </ul> <p>Here, <var>xor</var> denotes the bitwise exclusive OR.</p> <p><details> <summary style="display:list-item">Definition of XOR</summary></details></p> <p>The XOR of integers <var>c_1, c_2, ..., c_m</var> is defined as follows:</p> <ul> <li>Let the XOR be <var>X</var>. In the binary representation of <var>X</var>, the digit in the <var>2^k</var>'s place (<var>0 \leq k</var>; <var>k</var> is an integer) is <var>1</var> if there are an odd number of integers among <var>c_1, c_2, ...c_m</var> whose binary representation has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> if that number is even.</li> </ul> <p>For example, let us compute the XOR of <var>3</var> and <var>5</var>. The binary representation of <var>3</var> is <var>011</var>, and the binary representation of <var>5</var> is <var>101</var>, thus the XOR has the binary representation <var>110</var>, that is, the XOR is <var>6</var>.</p> <p></p></section></div></span>
p02802
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi participated in a contest on AtCoder.</p> <p>The contest had <var>N</var> problems.</p> <p>Takahashi made <var>M</var> submissions during the contest.</p> <p>The <var>i</var>-th submission was made for the <var>p_i</var>-th problem and received the verdict <var>S_i</var> (<code>AC</code> or <code>WA</code>).</p> <p>The number of Takahashi's correct answers is the number of problems on which he received an <code>AC</code> once or more.</p> <p>The number of Takahashi's penalties is the sum of the following count for the problems on which he received an <code>AC</code> once or more: the number of <code>WA</code>s received before receiving an <code>AC</code> for the first time on that problem.</p> <p>Find the numbers of Takahashi's correct answers and penalties.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var>, <var>M</var>, and <var>p_i</var> are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>0 \leq M \leq 10^5</var></li> <li><var>1 \leq p_i \leq N</var></li> <li><var>S_i</var> is <code>AC</code> or <code>WA</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>p_1</var> <var>S_1</var> <var>:</var> <var>p_M</var> <var>S_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of Takahashi's correct answers and the number of Takahashi's penalties.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 5 1 WA 1 AC 2 WA 2 AC 2 WA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 2 </pre> <p>In his second submission, he received an <code>AC</code> on the first problem for the first time. Before this, he received one <code>WA</code> on this problem.</p> <p>In his fourth submission, he received an <code>AC</code> on the second problem for the first time. Before this, he received one <code>WA</code> on this problem.</p> <p>Thus, he has two correct answers and two penalties.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100000 3 7777 AC 7777 AC 7777 AC </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 0 </pre> <p>Note that it is pointless to get an <code>AC</code> more than once on the same problem.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 0 </pre></section> </div> </span>
p03710
<span class="lang-en"> <p>Score : <var>1700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Kenus, the organizer of <em>International Euclidean Olympiad</em>, is seeking a pair of two integers that requires many steps to find its greatest common divisor using the Euclidean algorithm.</p> <p>You are given <var>Q</var> queries. The <var>i</var>-th query is represented as a pair of two integers <var>X_i</var> and <var>Y_i</var>, and asks you the following: among all pairs of two integers <var>(x,y)</var> such that <var>1 ≀ x ≀ X_i</var> and <var>1 ≀ y ≀ Y_i</var>, find the maximum <em>Euclidean step count</em> (defined below), and how many pairs have the maximum step count, modulo <var>10^9+7</var>.</p> <p>Process all the queries. Here, the Euclidean step count of a pair of two non-negative integers <var>(a,b)</var> is defined as follows:</p> <ul> <li><var>(a,b)</var> and <var>(b,a)</var> have the same Euclidean step count.</li> <li><var>(0,a)</var> has a Euclidean step count of <var>0</var>.</li> <li>If <var>a &gt; 0</var> and <var>a ≀ b</var>, let <var>p</var> and <var>q</var> be a unique pair of integers such that <var>b=pa+q</var> and <var>0 ≀ q &lt; a</var>. Then, the Euclidean step count of <var>(a,b)</var> is the Euclidean step count of <var>(q,a)</var> plus <var>1</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ Q ≀ 3 × 10^5</var></li> <li><var>1 ≀ X_i,Y_i ≀ 10^{18}(1 ≀ i ≀ Q)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>Q</var> <var>X_1</var> <var>Y_1</var> <var>:</var> <var>X_Q</var> <var>Y_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query, print the maximum Euclidean step count, and the number of the pairs that have the maximum step count, modulo <var>10^9+7</var>, with a space in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 4 4 6 10 12 11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 4 4 1 4 7 </pre> <p>In the first query, <var>(2,3)</var>, <var>(3,2)</var>, <var>(3,4)</var> and <var>(4,3)</var> have a Euclidean step count of <var>2</var>. No pairs have a step count of more than <var>2</var>.</p> <p>In the second query, <var>(5,8)</var> has a Euclidean step count of <var>4</var>.</p> <p>In the third query, <var>(5,8)</var>, <var>(8,5)</var>, <var>(7,11)</var>, <var>(8,11)</var>, <var>(11,7)</var>, <var>(11,8)</var>, <var>(12,7)</var> have a Euclidean step count of <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 1 1 2 2 5 1000000000000000000 7 3 1 334334334334334334 23847657 23458792534 111111111 111111111 7 7 4 19 9 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 1 1 4 4 600000013 3 1 1 993994017 35 37447 38 2 3 6 3 9 4 2 </pre></section> </div> </span>
p00096
<H1>぀の敎数の和 II</H1> <p> 4,000 以䞋の正の敎数 <var>n</var> を入力し、0 〜 1000 の範囲の敎数 <var>a, b, c, d</var> の組で</p> <pre> <var>a + b + c + d = n</var> </pre> <p>を満たすものの組み合わせ数を出力するプログラムを䜜成しお䞋さい。</p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットに <var>n</var> が行に䞎えられたす。入力の最埌たで凊理しお䞋さい。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットごずに、<var>a, b, c, d</var> の組み合わせの個数を行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 2 3 35 </pre> <H2>Output for the Sample Input</H2> <pre> 10 20 8436 </pre>
p02551
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with <var>N</var> rows and <var>N</var> columns of squares. Let <var>(i, j)</var> be the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left.</p> <p>Each of the central <var>(N-2) \times (N-2)</var> squares in the grid has a black stone on it. Each of the <var>2N - 1</var> squares on the bottom side and the right side has a white stone on it.</p> <p><var>Q</var> queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows:</p> <ul> <li><code>1 x</code>: Place a white stone on <var>(1, x)</var>. After that, for each black stone between <var>(1, x)</var> and the first white stone you hit if you go down from <var>(1, x)</var>, replace it with a white stone.</li> <li><code>2 x</code>: Place a white stone on <var>(x, 1)</var>. After that, for each black stone between <var>(x, 1)</var> and the first white stone you hit if you go right from <var>(x, 1)</var>, replace it with a white stone.</li> </ul> <p>How many black stones are there on the grid after processing all <var>Q</var> queries?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 2\times 10^5</var></li> <li><var>0 \leq Q \leq \min(2N-4,2\times 10^5)</var></li> <li><var>2 \leq x \leq N-1</var></li> <li>Queries are pairwise distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>Query_1</var> <var>\vdots</var> <var>Query_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print how many black stones there are on the grid after processing all <var>Q</var> queries.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 1 3 2 3 1 4 2 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>After each query, the grid changes in the following way:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/31ba2cd6b3155b137f0e007299225028.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>200000 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>39999200004 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>176527 15 1 81279 2 22308 2 133061 1 80744 2 44603 1 170938 2 139754 2 15220 1 172794 1 159290 2 156968 1 56426 2 77429 1 97459 2 71282 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>31159505795 </pre></section> </div> </span>
p02101
<h1>Problem D: Let's Go To School</h1> <h2>Problem</h2> <p> がっちょ君は期末詊隓が近づくずやる気がなくなっおしたい、しばしば孊校を䌑むようになる。<br> 期末詊隓たで残り<var>N</var>日である。<br> がっちょ君の<var>i</var>日目のやる気は<var>X<sub>i</sub></var>であり、<var>i</var>日目に孊校に行くために必芁なやる気は<var>Y<sub>i</sub></var>である。<br> がっちょ君は <var>X<sub>i</sub></var> &ge; <var>Y<sub>i</sub></var> ずなる日のみ孊校に行く。<br> がっちょ君を心配したハゞ君は、がっちょ君を励たすこずで、可胜な限り孊校に行かせようず考えた。<br> ハゞ君は最初、励たし力<var>P</var>を持っおいる。<br> ハゞ君が<var>i</var>日目に励たし力<var>t</var>(<var>t</var>は0以䞊の任意の実数)を消費しおがっちょ君を励たすず、 がっちょ君の<var>i</var>日目のやる気は<var>t</var>だけ増加しお、ハゞ君の励たし力は<var>t</var>だけ枛少する。さらに、<var>i</var>&plus;1 &le; <var>N</var>のずき、<var>i</var>&plus;1日目のがっちょ君のやる気<var>X<sub>i&plus;1</sub></var>はmax(0, <var>X<sub>i&plus;1</sub></var> &minus; <var>t</var>) に倉化する。<br> ハゞ君は自分の持っおいる励たし力を超えお励たすこずはできない。 </p> <p> ハゞ君が最適な励たし方をしたずきの、がっちょ君が孊校に行く最倧日数を求めよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>P</var> <var>X<sub>1</sub></var> <var>Y<sub>1</sub></var> <var>X<sub>2</sub></var> <var>Y<sub>2</sub></var> ... <var>X<sub>N</sub></var> <var>Y<sub>N</sub></var> </pre> <p> 入力はすべお敎数で䞎えられる。<br> 1行目に期末詊隓たでの日数<var>N</var>ずハゞ君が最初に持っおいる励たし力<var>P</var>が空癜区切りで䞎えられる。<br> 2行目から続く<var>N</var>行にはがっちょ君の<var>i</var>(<var>i</var>=1,2,...,<var>N</var>)日目のやる気<var>X<sub>i</sub></var>ず孊校に行くために必芁なやる気<var>Y<sub>i</sub></var>が空癜区切りで䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var> &le; 100</li> <li>0 &le; <var>P</var> &le; 10<sup>6</sup></li> <li>0 &le; <var>X<sub>i</sub></var> &le; 10<sup>6</sup></li> <li>0 &le; <var>Y<sub>i</sub></var> &le; 10<sup>6</sup></li> </ul> <h2>Output</h2> <p> がっちょ君が孊校に行くこずができる最倧の日数を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 10 1 6 5 10 0 5 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 5 5 1 1 1 2 1 2 1 3 1 3 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre>
p00429
<H1></H1> <p> 0 から 9 たでの数字だけで構成された文字列が䞎えられたずき,その文字列から次の芏則に埓っお新しい文字列を䜜る操䜜を考える.䞎えられた文字列を巊端から1文字ず぀順に読んで行き,同じ数字 <i>a</i> が <i>r</i> 個続いおいた堎合,個数 <i>r</i> ず数字<i>a</i> を空癜で区切らずにこの順で曞き出す.䞎えられた文字列の右端たで読み,最埌の曞き出しが終わったずころたでを途䞭䜕回曞き出しがあったずしおも党郚たずめお操䜜1回ずカりントする.2回目以降の操䜜は前回の操䜜により曞き出された文字列を䞎えられた文字列ずしお同様の操䜜を実斜する.䟋えば “<span>122244</span>” ずいう文字列が䞎えられた堎合には巊端から順に1個の1, 3個の2,2個の4なのでこの操䜜1回で埗られる文字列は “<span>113224</span>” であり,“<span>44444444444</span>” (11 個の4)の堎合には埗られる文字列は “<span>114</span>” ずなる. </p> <p> 100 文字以䞋の䞎えられた文字列に䞊の操䜜を <i>n</i> 回実斜した文字列を出力するプログラムを䜜成せよ.ただし, <i>n</i> &le; 20 ずする. </p> <!-- <p> 入力ファむルのファむル名は “input.txt” である. “input.txt” は 2 行からなり,1 行目に操䜜回数 <i>n</i>, 2 行目に最初の文字列が曞かれおいる. </p> <p> 出力ファむルのファむル名は “output.txt” である.“output.txt” は 1 行であり, 指定された回数の操䜜を斜した文字列の埌に改行を入れるこず. </p> --> <p> 入力デヌタ は 2 行からなり,1 行目に操䜜回数 <i>n</i>, 2 行目に最初の文字列が曞かれおいる. </p> <table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;"> <tr> <th width="150" align="left">入力䟋</th> </tr> <tr><td></td></tr> <tr> <td>5<br> 11</td> </tr> <tr> <td> </td> </tr> <tr> <th width="150" align="left">出力䟋</th> </tr> <tr><td>13112221 </td> </tr> </table> <h3>入力</h3> <p> 入力は耇数のデヌタセットからなるn が 0 のずき入力が終了するデヌタセットの数は 5 を超えない </p> <h3>出力</h3> <p> デヌタセットごずに、指定された回数の操䜜を斜した文字列 を行に出力する </p> <H2>入力䟋</H2> <pre> 5 11 5 11 0 </pre> <H2>出力䟋</H2> <pre> 13112221 13112221 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02414
<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>Matrix Multiplication</h1><br> <p> Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: </p> \[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \] <p> where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively. </p> <h2>Input</h2> <p> In the first line, three integers $n$, $m$ and $l$ are given separated by space characters </p> <p> In the following lines, the $n \times m$ matrix $A$ and the $m \times l$ matrix $B$ are given. </p> <h2>Output</h2> <p> Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space character between adjacent elements. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n, m, l \leq 100$</li> <li>$0 \leq a_{ij}, b_{ij} \leq 10000$</li> </ul> <h2>Sample Input</h2> <pre> 3 2 3 1 2 0 3 4 5 1 2 1 0 3 2 </pre> <h2>Sample Output</h2> <pre> 1 8 5 0 9 6 4 23 14 </pre> <h2>Note</h2> <center> <a href="commentary.jsp?id=ITP1_7_D"> <div class="button">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解説&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div> </a> </center>
p00079
<H1>凞 <var>n</var> 角圢の面積</H1> <p> 凞 <var>n</var> 角圢すべおの頂点の内角が 180 床未満である倚角圢、芁するにぞこんでいない倚角圢のこずの頂点の座暙を読んで、その面積を出力するプログラムを䜜成しおください。頂点には蟺の぀ながりの順序に埓っお頂点 1、頂点 2、頂点 3、‥‥頂点 <var>n</var> ずいう名前が぀いおいたす。 </p> <p> ただし、 <var>n</var> は 3 以䞊 20 以䞋ずしたす。たた、次の、䞉角圢の 3 蟺の長さ <var>a, b, c</var> から面積 <var>S</var> を求める公匏を䜿っおもかたいたせん。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_07"> </center> <br/> <H2>入力</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>x<sub>1</sub></var>,<var>y<sub>1</sub></var> <var>x<sub>2</sub></var>,<var>y<sub>2</sub></var> : <var>x<sub>n</sub></var>,<var>y<sub>n</sub></var> </pre> <p> <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> はそれぞれ頂点 <var>i</var> の <var>x</var> 座暙, <var>y</var> 座暙を衚す実数です。 </p> <H2>出力</H2> <p> 面積 <var>S</var> 実数を行に出力したす。 出力は 0.000001 以䞋の誀差を含んでもかたいたせん。 </p> <H2>Sample Input</H2> <pre> 0.0,0.0 0.0,1.0 1.0,1.0 2.0,0.0 1.0,-1.0 </pre> <H2>Output for the Sample Input</H2> <pre> 2.500000 </pre>
p02044
<h3>割り勘</h3> <!-- begin ja only --> <p>あなたは ICPC 2019 Yokohama Regional 囜内予遞の健闘を祈るためのパヌティを䌁画したこのパヌティの参加者は <i>N</i> 人である</p> <p>このパヌティの開催には合蚈で <i>M</i> 円の費甚が必芁ずなるため<i>N</i> 人の参加者からそれぞれ <i>M/N</i> 円を集めるこずにした<i>M</i> は <i>N</i> で割り切れる金額ずなったため䜙りに぀いお心配する必芁はない</p> <p><i>i</i> 番目の参加者の今日の所持金は <i>A<sub>i</sub></i> 円である<i>M/N</i> 円を払うこずができない堎合には今日の所持金をすべお払っおもらい足りない分は埌日払っおもらうこずずする</p> <p>あなたは今日のうちにパヌティの開催費甚をいくら集めるこずができるだろうか</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は最倧で 50 個のデヌタセットからなる 各デヌタセットは次の圢匏で衚される</p> <blockquote><i>N</i> <i>M</i> <i>A<sub>1</sub></i> <i>A<sub>2</sub></i> <i>...</i> <i>A<sub>N</sub></i></blockquote> <p>デヌタセットは 2 行からなる1 行目にはパヌティの参加者の数 <i>N</i> ずかかった費甚 <i>M</i> が䞎えられる<i>N</i> ず <i>M</i> は敎数でありそれぞれ <i>2 &le; N &le; 100</i><i>N &le; M &le; 10 000</i> が成り立぀たた<i>M</i> は <i>N</i> の倍数である2 行目には <i>N</i> 人の参加者のそれぞれの所持金が䞎えられる<i>A<sub>i</sub></i> は <i>i</i> 番目の参加者の所持金を衚す敎数であり<i>1 &le; A<sub>i</sub> &le; 10 000</i> である</p> <p>入力の終わりは2 個の <i>0</i> だけからなる行で衚される</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに぀いお今日のうちに集めるこずができるパヌティの開催費甚を 1 行で出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>3 300 120 100 80 3 30 10 20 5 4 1000 100 200 300 400 5 5 2523 8430 3 4199 632 0 0 </pre><h3>Output for the Sample Input</h3><pre>280 25 800 5 </pre> <p>ひず぀めのデヌタセットでは 1 人あたりの支払いは 100 円である1 番目ず 2 番目の参加者は 100 円を支払うこずができるが3 番目の参加者は 100 円を支払うこずができないため所持金である 80 円を支払っおもらい足りない 20 円は埌日支払っおもらうこずずする今日のうちに集めるこずができるのは <i>100+100+80=280</i> 円である</p>
p00583
<h1>たのしいたのしいたのしい家庭菜園(Growing Vegetables is Fun 3)</h1> <p> JOI 君は長幎にわたる家庭菜園の経隓を生かしお自宅の庭で新たにゞョむ草ずいう怍物を育おおいる庭には東西方向に䞊んだ$N$ 個のプランタヌがあり西偎から順に1 から$N$ たでの番号が぀いおいるゞョむ草は党郚で$N$ 株ありそれぞれのプランタヌに1 株ず぀怍えおある </p> <p> 春になっお様子を芋に行ったJOI 君はゞョむ草が予想に反しお色ずりどりの葉を付けおいるこずに気が぀いたさらにゞョむ草が思ったほど生育しおいないこずに気が぀いたJOI 君はこれらのこずを䞍思議に思い本で調べたずころ次のこずがわかった </p> <ul> <li> ゞョむ草には3 皮類ありそれぞれ赀緑黄の葉を付ける</li> <li> 葉の色が同じゞョむ草を近くに眮くずその成長が阻害されおしたう</li> </ul> <p> そこでJOI 君はゞョむ草を䞊び替えお葉の色が同じゞョむ草が隣り合わないようにするこずにしたこのずきJOI 君は隣り合う2 ぀のゞョむ草を入れ替えるこずしかできない぀たり1 回の操䜜でJOI 君はプランタヌ$i$ ($1 \leq i \leq N - 1$) を任意に1 ぀遞びプランタヌ$i$ のゞョむ草ずプランタヌ$i + 1$ のゞョむ草を入れ替えるこずができるJOI 君はできるだけ少ない回数の操䜜で葉の色が同じゞョむ草が隣り合わないようにしたい </p> <p> ゞョむ草の数ずそれぞれのゞョむ草の葉の色が䞎えられたずき葉の色が同じゞョむ草が隣り合わないように䞊び替えるために必芁な操䜜回数の最小倀を求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は以䞋の圢匏で暙準入力から䞎えられる </p> <pre> $N$ $S$ </pre> <p> $S$ は長さ$N$ の文字列でその$i$ 文字目($1 \leq i \leq N$) はプランタヌ$i$ に怍えおあるゞョむ草の葉の色が赀ならばR緑ならばG黄ならばY である </p> <h2>出力</h2> <p> 暙準出力に必芁な操䜜回数の最小倀を1 行で出力せよただし葉の色が同じゞョむ草が隣り合わないように䞊び替えるこずが䞍可胜ならば代わりに-1 を出力せよ </p> <h2>制玄</h2> <ul> <li>$ 1 \leq N \leq 400$</li> <li> $S$ は長さ$N$ の文字列である</li> <li> $S$ の各文字はRGY のいずれかである</li> </ul> <!-- 小課題 1. (5 点) N ≩ 15 2. (55 点) N ≩ 60 3. (15 点) S の各文字はRG のいずれかである 4. (25 点) 远加の制玄はない --> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 5 RRGYY </pre> <h3> 出力䟋1</h3> <pre> 2 </pre> <p> この入力䟋では䟋えば次のようにするず葉の色が同じゞョむ草が隣り合わないようにするこずができる </p> <ul> <li> たずプランタヌ3 のゞョむ草ずプランタヌ4 のゞョむ草を入れ替える</li> <li> 次にプランタヌ2 のゞョむ草ずプランタヌ3 のゞョむ草を入れ替える</li> </ul> <p> このようにするずゞョむ草の䞊びはRYRGY のようになる1 回以䞋の操䜜で葉の色が同じゞョむ草が隣り合わないようにするこずはできないので2 を出力する </p> <h3>入力䟋2</h3> <pre> 6 RRRRRG </pre> <h3> 出力䟋2</h3> <pre> -1 </pre> <p> この入力䟋ではどのように操䜜をしおも葉の色が同じゞョむ草が隣り合わないようにするこずはできない </p> <h3>入力䟋3</h3> <pre> 20 YYGYYYGGGGRGYYGRGRYG </pre> <h3> 出力䟋3</h3> <pre> 8 </pre> <br/> <p> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> <br/> <a href="https://www.ioi-jp.org/joi/2018/2019-ho/index.html">情報オリンピック日本委員䌚䜜 『第18 回日本情報オリンピック(JOI 2018/2019) 本遞』</a> </p>
p03205
<span class="lang-en"> <p>Score : <var>2200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given <var>N-1</var> subsets of <var>\{1,2,...,N\}</var>. Let the <var>i</var>-th set be <var>E_i</var>.</p> <p>Let us choose two distinct elements <var>u_i</var> and <var>v_i</var> from each set <var>E_i</var>, and consider a graph <var>T</var> with <var>N</var> vertices and <var>N-1</var> edges, whose vertex set is <var>\{1,2,..,N\}</var> and whose edge set is <var>(u_1,v_1),(u_2,v_2),...,(u_{N-1},v_{N-1})</var>. Determine if <var>T</var> can be a tree by properly deciding <var>u_i</var> and <var>v_i</var>. If it can, additionally find one instance of <var>(u_1,v_1),(u_2,v_2),...,(u_{N-1},v_{N-1})</var> such that <var>T</var> is actually a tree.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>E_i</var> is a subset of <var>\{1,2,..,N\}</var>.</li> <li><var>|E_i| \geq 2</var></li> <li>The sum of <var>|E_i|</var> is at most <var>2 \times 10^5</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>c_1</var> <var>w_{1,1}</var> <var>w_{1,2}</var> <var>...</var> <var>w_{1,c_1}</var> <var>:</var> <var>c_{N-1}</var> <var>w_{N-1,1}</var> <var>w_{N-1,2}</var> <var>...</var> <var>w_{N-1,c_{N-1}}</var> </pre> <p>Here, <var>c_i</var> stands for the number of elements in <var>E_i</var>, and <var>w_{i,1},...,w_{i,c_i}</var> are the <var>c_i</var> elements in <var>c_i</var>. Here, <var>2 \leq c_i \leq N</var>, <var>1 \leq w_{i,j} \leq N</var>, and <var>w_{i,j} \neq w_{i,k}</var> (<var>1 \leq j &lt; k \leq c_i</var>) hold.</p> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>T</var> cannot be a tree, print <code>-1</code>; otherwise, print the choices of <var>(u_i,v_i)</var> that satisfy the condition, in the following format:</p> <pre><var>u_1</var> <var>v_1</var> <var>:</var> <var>u_{N-1}</var> <var>v_{N-1}</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 1 2 3 1 2 3 3 3 4 5 2 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 1 3 3 4 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 1 2 3 3 2 3 4 3 1 3 4 3 1 2 4 3 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 5 1 2 3 4 5 5 2 3 4 5 6 5 3 4 5 6 7 5 4 5 6 7 8 5 5 6 7 8 9 5 6 7 8 9 10 5 7 8 9 10 1 5 8 9 10 1 2 5 9 10 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 </pre></section> </div> </span>
p01238
<H1><font color="#000">Problem E:</font> Subdividing a Land</H1> <p> Indigo Real-estate Company is now planning to develop a new housing complex. The entire complex is a square, all of whose edges are equally <i>a</i> meters. The complex contains <i>n</i> subdivided blocks, each of which is a <i>b</i>-meter square. Here both <i>a</i> and <i>b</i> are positive integers. </p> <p> However the project is facing a big problem. In this country, a percentage limit applies to the subdivision of a land, under the pretext of environmental protection. When developing a complex, the total area of the subdivided blocks must not exceed 50% of the area of the complex; in other words, more than or equal to 50% of the newly developed housing complex must be kept for green space. As a business, a green space exceeding 50% of the total area is a <i>dead space</i>. The primary concern of the project is to minimize it. </p> <p> Of course purchasing and developing a land costs in proportion to its area, so the company also wants to minimize the land area to develop as the secondary concern. You, a member of the project, were assigned this task, but can no longer stand struggling against the problem with your pencil and paper. So you decided to write a program to find the pair of minimum <i>a</i> and <i>b</i> among those which produce the minimum dead space for given <i>n</i>. </p> <H2>Input</H2> <p> The input consists of multiple test cases. Each test case comes in a line, which contains an integer <i>n</i>. You may assume 1 &le; <i>n</i> &le; 10000. </p> <p> The end of input is indicated by a line containing a single zero. This line is not a part of the input and should not be processed. </p> <H2>Output</H2> <p> For each test case, output the case number starting from 1 and the pair of minimum <i>a</i> and <i>b</i> as in the sample output. </p> <p> You may assume both <i>a</i> and <i>b</i> fit into 64-bit signed integers. </p> <H2>Sample Input</H2> <pre> 1 2 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 3 2 Case 2: 2 1 </pre>
p02947
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will call a string obtained by arranging the characters contained in a string <var>a</var> in some order, an <em>anagram</em> of <var>a</var>.</p> <p>For example, <code>greenbin</code> is an anagram of <code>beginner</code>. As seen here, when the same character occurs multiple times, that character must be used that number of times.</p> <p>Given are <var>N</var> strings <var>s_1, s_2, \ldots, s_N</var>. Each of these strings has a length of <var>10</var> and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers <var>i, j</var> <var>(1 \leq i &lt; j \leq N)</var> such that <var>s_i</var> is an anagram of <var>s_j</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>s_i</var> is a string of length <var>10</var>.</li> <li>Each character in <var>s_i</var> is a lowercase English letter.</li> <li><var>s_1, s_2, \ldots, s_N</var> are all distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s_1</var> <var>s_2</var> <var>:</var> <var>s_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of pairs of integers <var>i, j</var> <var>(1 \leq i &lt; j \leq N)</var> such that <var>s_i</var> is an anagram of <var>s_j</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 acornistnt peanutbomb constraint </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p><var>s_1 =</var> <code>acornistnt</code> is an anagram of <var>s_3 =</var> <code>constraint</code>. There are no other pairs <var>i, j</var> such that <var>s_i</var> is an anagram of <var>s_j</var>, so the answer is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 oneplustwo ninemodsix </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>If there is no pair <var>i, j</var> such that <var>s_i</var> is an anagram of <var>s_j</var>, print <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 abaaaaaaaa oneplustwo aaaaaaaaba twoplusone aaaabaaaaa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre> <p>Note that the answer may not fit into a <var>32</var>-bit integer type, though we cannot put such a case here.</p></section> </div> </span>
p03655
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the <var>x</var>-th from the west and the <var>y</var>-th from the north as <var>(x,y)</var>.</p> <p>Joisino thinks that a <em>touring plan</em> is good if it satisfies the following conditions:</p> <ul> <li> <p>Let <var>(p,q)</var> be the section where she starts the tour. Then, <var>X_1 \leq p \leq X_2</var> and <var>Y_1 \leq q \leq Y_2</var> hold.</p> </li> <li> <p>Let <var>(s,t)</var> be the section where she has lunch. Then, <var>X_3 \leq s \leq X_4</var> and <var>Y_3 \leq t \leq Y_4</var> hold.</p> </li> <li> <p>Let <var>(u,v)</var> be the section where she ends the tour. Then, <var>X_5 \leq u \leq X_6</var> and <var>Y_5 \leq v \leq Y_6</var> hold.</p> </li> <li> <p>By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way.</p> </li> </ul> <p>Two touring plans are considered different if at least one of the following is different: the starting section, the lunch section, the ending section, and the sections that are visited on the way. Joisino would like to know how many different good touring plans there are. Find the number of the different good touring plans. Since it may be extremely large, find the count modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X_1 \leq X_2 &lt; X_3 \leq X_4 &lt; X_5 \leq X_6 \leq 10^6</var></li> <li><var>1 \leq Y_1 \leq Y_2 &lt; Y_3 \leq Y_4 &lt; Y_5 \leq Y_6 \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>X_1</var> <var>X_2</var> <var>X_3</var> <var>X_4</var> <var>X_5</var> <var>X_6</var> <var>Y_1</var> <var>Y_2</var> <var>Y_3</var> <var>Y_4</var> <var>Y_5</var> <var>Y_6</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different good touring plans, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 1 2 2 3 4 1 1 2 2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p>The starting section will always be <var>(1,1)</var>, and the lunch section will always be <var>(2,2)</var>. There are four good touring plans where <var>(3,3)</var> is the ending section, and six good touring plans where <var>(4,3)</var> is the ending section. Therefore, the answer is <var>6+4=10</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 3 4 5 6 1 2 3 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2346 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>77523 89555 420588 604360 845669 973451 2743 188053 544330 647651 709337 988194 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>137477680 </pre></section> </div> </span>
p01668
<h2>B - Integer in Integer</h2> <h3>Problem Statement</h3> <p> Given an integer interval <var>\[A, B\]</var> and an integer <var>C</var>, your job is to calculate the number of occurrences of <var>C</var> as string in the interval. </p> <p> For example, <var>33</var> appears in <var>333</var> twice, and appears in <var>334</var> once. Thus the number of occurrences of <var>33</var> in <var>\[333, 334\]</var> is <var>3</var>. </p> <h3>Input</h3> <p> The test case is given by a line with the three integers, <var>A</var>, <var>B</var>, <var>C</var> (<var>0 \leq A \leq B \leq 10^{10000}</var>, <var>0 \leq C \leq 10^{500}</var>). </p> <h3>Output</h3> <p> Print the number of occurrences of <var>C</var> mod 1000000007. </p> <h3>Sample Input 1</h3> <pre> 1 3 2 </pre> <h3>Output for Sample Input 1</h3> <pre> 1 </pre> <h3>Sample Input 2</h3> <pre> 333 334 33 </pre> <h3>Output for Sample Input 2</h3> <pre> 3 </pre> <h3>Sample Input 3</h3> <pre> 0 10 0 </pre> <h3>Output for Sample Input 3</h3> <pre> 2 </pre>
p01392
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1><font color="#000">問題 E</font> Fox Number</h1> <h2>問題文</h2> <p>き぀ねのしえるは数字に぀いお考えるのが奜きであるある日しえるはこの䞖にねこの数字ずいうものがあるこずを知り自分もそのような数字が欲しくなっおしたったそこで次の性質を満たす数字をずりあえず Fox Number ず呌ぶこずにした</p> <p>[性質]: 敎数 <var>N</var> は <var>k (&ge; 1)</var> 個の玠数 <var>p<sub>1</sub>, ..., p<sub>k</sub></var> ず正敎数 <var>e<sub>1</sub>, ..., e<sub>k</sub></var> で<var>p<sub>1</sub> &lt; ... &lt; p<sub>k</sub></var><var>e<sub>1</sub> &ge; ... &ge; e<sub>k</sub></var> を満たすものによっお <var>N = p<sub>1</sub><sup>e<sub>1</sub></sup> × ... × p<sub>k</sub><sup>e<sub>k</sub></sup></var> ず曞けるずきFox Number であるず呌ぶこずにする</p> <p>ずころでしえるはこの性質をその堎の思い぀きで決めおしたったのでこれがどういう性質を持っおいるのか党くわかっおいないそこでこの数字の性質を調べるために区間 <var>[A-B, A+B]</var> に含たれる Fox Number の個数を出力しお欲しい</p> <h2>入力圢匏</h2> <p><var>1</var> 行目に以䞋の <var>2</var> ぀の敎数が䞎えられる</p> <pre><var>A</var> <var>B</var></pre> <h2>出力圢匏</h2> <p><var>1</var> 行目に<var>A-B</var> 以䞊 <var>A+B</var> 以䞋の Fox Number の個数を出力せよ</p> <h2>制玄</h2> <ul> <li><var>1 &le; A &le; 10<sup>12</sup></var></li> <li><var>0 &le; B &le; 5 × 10<sup>5</sup></var></li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 18 2 </pre> <h3>出力䟋 1</h3> <pre> 4 </pre> <p><var>16 = 2<sup>4</sup>, 17 = 17<sup>1</sup>, 19 = 19<sup>1</sup>, 20 = 2<sup>2</sup> × 5<sup>1</sup></var> は Fox Number である䞀方で <var>18 = 2 × 3<sup>2</sup></var> は Fox Number ではない合蚈しお <var>4</var> ぀の Fox Number がある</p> <h3>入力䟋 2</h3> <pre> 100 10 </pre> <h3>出力䟋 2</h3> <pre> 18 </pre> <h3>入力䟋 3</h3> <pre> 123456 789 </pre> <h3>出力䟋 3</h3> <pre> 1464 </pre>
p03481
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence <var>A</var> needs to satisfy the conditions below:</p> <ul> <li><var>A</var> consists of integers between <var>X</var> and <var>Y</var> (inclusive).</li> <li>For each <var>1\leq i \leq |A|-1</var>, <var>A_{i+1}</var> is a multiple of <var>A_i</var> and strictly greater than <var>A_i</var>.</li> </ul> <p>Find the maximum possible length of the sequence.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X \leq Y \leq 10^{18}</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>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible length of the sequence.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 20 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The sequence <var>3,6,18</var> satisfies the conditions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>25 100 </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>314159265 358979323846264338 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>31 </pre></section> </div> </span>
p01146
<!-- begin en only --> <h3><U> Princess in Danger </U></h3> <!-- end en only --> <!-- begin ja only --> <h3><U> お姫様の危機 </U></h3> <!-- end ja only --> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> ある貧乏な囜のおおんばで勇敢なお姫様が政略結婚のため別の囜に嫁ぐこずになったずころがお姫様を亡き者ずしようずしおいる悪挢に嫁ぎ先ぞの道䞭で襲われお姫様が倧けがをしおしたい近くの病院に搬送されたずころが悪挢はお姫様は確実に亡き者ずするため特殊な毒を䜿っおいたそのためお姫様を助けるには本囜から特別な薬ず冷凍された肉芪の血液を倧急ぎで運ばなければならなくなった </p> <p> この血液は冷凍状態で茞送されるのだが鮮床を保぀ため前回の冷凍から最倧 <i>M</i> 分以内に血液冷凍斜蚭で再冷凍しなければならないしかし冷凍斜蚭が蚭眮されおいる堎所は数カ所しかない </p> <p> 血液は十分に冷凍した状態から再冷凍なしで <i>M</i> 分の間無事である再冷凍しなくおすむ残り時間が <i>S</i> 分のずきに<i>T</i> 分間冷凍しないで茞送した堎合再冷凍しなくおすむ残り時間は <i>S</i> - <i>T</i> 分ずなる再冷凍しなくおすむ残り時間は再冷凍するこずにより最倧 <i>M</i> 分たで回埩する血液の再冷凍にかかる時間はどれだけ冷凍するかに䟝存する血液を冷凍斜蚭で1分冷凍するごずに再冷凍しなくおすむ残り時間は1分回埩する </p> <p> 本囜の銖郜を出発する時点の血液を再冷凍しなくおすむ残り時間は<i>M</i>分である </p> <p> お姫様の埓者であるあなたは倧切な䞻君の呜を救うため本囜の銖郜からお姫様が搬送された病院たで血液の鮮床を保ったたた茞送するための経路を蚈算しなければならないそうあなたの䜿呜は本囜の銖郜からその病院ぞの最短経路を割り出しその最短時間を求めるこずである </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットより構成される各デヌタセットの最初の行には6 ぀の非負の敎数 <i>N</i>(2 ≩ <i>N</i> ≩ 100)<i>M</i>(1 ≩ <i>M</i> ≩ 100)<i>L</i>(0 ≩ <i>L</i> ≩ <i>N</i> - 2)<i>K</i><i>A</i>(0 ≩ <i>A</i>  <i>N</i>)<i>H</i>(0 ≩ <i>H</i>  <i>N</i>) が䞎えられるこれらはそれぞれ町の数再冷凍を行うたでの制限時間冷凍斜蚭のある町の数町ず町を盎接結ぶ道路の数本囜の銖郜を衚す番号お姫様が搬送された病院のある町の番号を衚す本囜の銖郜ずお姫様が搬送された病院は異なる町であるなお町には 0 〜 <i>N</i>-1 たでの番号がそれぞれ割り圓おられおいるものずする続く行には<i>L</i> 個の非負の敎数が 1 ぀の空癜で区切られお䞎えられるこれらは冷凍斜蚭がある町の番号を衚すなお本囜の銖郜ずお姫様が搬送された病院はこのリストには含たれないが冷凍斜蚭があるものず考えお良い続く <i>K</i> 行では町ず町を結ぶ道路の情報が䞎えられるその第 <i>i</i> 行目では3 ぀の非負の敎数 <i>X</i> <i>Y</i> <i>T</i> が 1 ぀の空癜で区切られお䞎えられこれは町 <i>X</i> ず町 <i>Y</i> を盎接結ぶ道があり移動には時間 <i>T</i> を芁するずいうこずを衚すなおこの道は双方向に通行可胜であるたた町<i>X</i>ず町<i>Y</i>を盎接結ぶ道は高々䞀぀しか無い </p> <p> 入力は <i>N = M = L = K = A = H =</i> 0 の時に終了しこれはデヌタセットに含たれない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットに぀いお鮮床を保ったたた血液を届けるこずができる最短時間を出力せよもし届けるこずができない堎合には "Help!" ず出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 2 1 0 1 0 1 0 1 2 3 1 1 2 0 1 2 0 2 1 1 2 1 3 2 1 2 0 1 2 0 2 1 1 2 1 4 4 1 4 1 3 2 0 1 2 1 2 4 0 2 1 3 0 3 5 3 2 6 0 3 1 2 2 1 2 1 0 1 3 4 1 2 4 1 4 1 2 2 0 2 5 4 2 6 0 3 1 2 4 2 4 2 1 2 4 3 1 0 1 5 1 4 2 2 0 3 0 0 0 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> Help! 3 2 10 5 12 </pre>
p01516
<!-- begin en only --> <h3><u>Milky Way </u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>倩の川 </u></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> 倩の川亀通公瀟は星間旅行ツアヌの䌁画・運営を行う旅行䌚瀟である。 倩の川亀通公瀟では「倩の川暪断織姫圊星䜓隓ツアヌ」ずいう䌁画を蚈画䞭である。 このツアヌは琎座のベガを出発し、 星々を巡っお鷲座のアルタむルに向かうずいうものである。 あなたは倩の川亀通公瀟に瀟員であり、 ツアヌの経路の遞択を任されおいる。 </p> <p> 簡単のため倩の川は2次元座暙䞊にあるものずし、 星は五芒星で衚珟されるものずする。 ツアヌに䜿甚する宇宙船には特殊な゚ンゞンが搭茉されおおり、 五芒星の線分䞊ぱネルギヌ無しで移動するこずができる。 䞀方、五芒星の間を移動する際には、その距離に比䟋した゚ネルギヌが必芁ずなる。 </p> <p> 近幎、倩の川亀通公瀟の売䞊は䜎迷しおおり、 宇宙船の゚ネルギヌ代を始めずした各皮必芁経費の節玄を迫られおいる。 あなたの仕事は、ベガからアルタむルに移動する際、 星間移動距離の総和が最小になるような経路を求め、 その総和を出力するプログラムを曞くこずである。 </p> <p> ある五芒星からその内郚に含たれる別の五芒星に移動する堎合、 五芒星同士が接しおいない堎合は星間の移動ずしお扱われるこずに泚意せよ。 </p> <p> 図D-1は3぀目のSample Inputを図瀺したものである。 図䞭、赀色の線分は星間移動距離の総和が最小になるような経路の、 星間移動の郚分を衚しおいる。 </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_Fig-D1"> </center> </center> <center> <p> <i>図 D-1: 星間の移動</i> </p> </center> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は1぀以䞊のデヌタセットからなる。1぀のデヌタセットは次の圢匏をしおいる。 </p> <blockquote> <var>N</var> <var>M</var> <var>L</var><br/> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>a<sub>1</sub></var> <var>r<sub>1</sub></var><br/> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>a<sub>2</sub></var> <var>r<sub>2</sub></var><br/> <var>...</var><br/> <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>a<sub>N</sub></var> <var>r<sub>N</sub></var><br/> </blockquote> <p> 各テストケヌスの初めの1行は敎数N、M、Lからなり、 Nは星の数(1 &#8804; N &#8804; 100)、 Mはベガの番号(1 &#8804; M &#8804; N)、 Lはアルタむルの番号(1 &#8804; L &#8804; N)を衚す。 続くN行には各星の情報が䞎えられる。 各行はx<sub>i</sub>、y<sub>i</sub>、a<sub>i</sub>、r<sub>i</sub>の4぀の敎数からなり、 x<sub>i</sub>はi番目の星の䞭心のx座暙(0 &#8804; x<sub>i</sub> &#8804; 1,000)、 y<sub>i</sub>はi番目の星の䞭心のy座暙(0 &#8804; y<sub>i</sub> &#8804; 1,000)、 a<sub>i</sub>はi番目の星の䞭心座暙ず星の先端を結んだ盎線がy軞ずなす角床(0 &#8804; a<sub>i</sub> &lt; 72)、 r<sub>i</sub>はi番目の星の䞭心座暙から星の先端たでの長さ(1 &#8804; r<sub>i</sub> &#8804; 1,000)である。 入力の終わりは3぀のれロを含む行で衚される。 </p> <p> 図 D-2の巊の星はx=5, y=10, a=0, r=5の星を衚しおおり、右の星はx=15, y=10, a=30, r=5の星を衚しおいる。 </p> <center> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_Fig-D2"> </center> </center> <center> <p> <i>図 D-2: 星の䟋</i> </p> </center> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 各入力ごずに、ベガからアルタむルに移動する際に必芁な星間移動距離の総和の最小倀を1行に出力せよ。 出力には、0.000001を超える誀差があっおはならない。 </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 1 1 1 5 5 0 5 2 1 2 5 5 0 5 15 5 0 5 3 2 3 15 15 0 5 5 5 10 5 25 25 20 5 0 0 0 </pre> <!-- begin ja only --> <!-- end ja only --> </div> <h3>Output for Sample Input</h3> <div> <pre> 0.00000000000000000000 0.48943483704846357796 9.79033725601359705593 </pre> <!-- begin ja only --> <!-- end ja only --> </div>
p02290
<H1>Projection</H1> <br/> <p> For given three points <var>p1, p2, p</var>, find the projection point <var>x</var> of <var>p</var> onto <var>p1p2</var>. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_CGL_CGL_1_A"> </center> <H2>Input</H2> <pre> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>x<sub>p2</sub></var> <var>y<sub>p2</sub></var> <var>q</var> <var>x<sub>p<sub>0</sub></sub></var> <var>y<sub>p<sub>0</sub></sub></var> <var>x<sub>p<sub>1</sub></sub></var> <var>y<sub>p<sub>1</sub></sub></var> ... <var>x<sub>p<sub>q&minus;1</sub></sub></var> <var>y<sub>p<sub>q&minus;1</sub></sub></var> </pre> <p> In the first line, integer coordinates of <var>p1</var> and <var>p2</var> are given. Then, <var>q</var> queries are given for integer coordinates of <var>p</var>. </p> <H2>Output</H2> <!-- <pre> <var>x<sub>t<sub>0</sub></sub></var> <var>y<sub>t<sub>0</sub></sub></var> <var>x<sub>t<sub>1</sub></sub></var> <var>y<sub>t<sub>1</sub></sub></var> ... <var>x<sub>t<sub>q-1</sub></sub></var> <var>y<sub>t<sub>q-1</sub></sub></var> </pre> --> <p> For each query, print the coordinate of the projection point <var>x</var>. The output values should be in a decimal fraction with an error less than 0.00000001. </p> <H2>Constraints</H2> <ul> <li> <var>1 &le; q &le; 1000</var> </li> <li> <var>-10000 &le; x<sub>i</sub>, y<sub>i</sub> &le; 10000</var> </li> <li> <var>p1</var> and <var>p2</var> are not identical. </li> </ul> <H2>Sample Input 1</H2> <pre> 0 0 2 0 3 -1 1 0 1 1 1 </pre> <H2>Sample Output 1</H2> <pre> -1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 </pre> <br/> <H2>Sample Input 2</H2> <pre> 0 0 3 4 1 2 5 </pre> <H2>Sample Output 2</H2> <pre> 3.1200000000 4.1600000000 </pre> <br/>
p00757
<h3><U>Planning Rolling Blackouts</U></h3> <!-- end en only --> <div> <!-- please enclose each h3 level section with div --> <!-- begin en only --> <p>Faced with seriously tight power supply-demand balance, the electric power company for which you are working implemented <q>rolling blackouts</q> in this spring. It divided the servicing area into several groups of towns, and divided a day into several blackout periods. At each blackout period of a day, one of the groups, which alternates from one group to another, is cut off the electricity. By keeping the total demand of electricity used by the rest of the towns within the supply capacity, the company avoided unforeseeable large-scale blackout.</p> <!-- end en only --> <!-- begin en only --> <p>Working at the customer relations department, you had to listen to so many complaints from the customers, which made you think that you could have a better implementation. Most of the complaints are about the frequent cut-offs. But you could have divided the area into a larger number of groups, which resulted in less frequent cut-offs for each group. The other complaints are about the complicated grouping (in fact, someone said that the shapes of the groups are fractals), which makes it impossible to understand which town belongs to which group without closely inspecting into the grouping list publicized by the company. With the rectangular servicing area and towns located in a grid form, you could have made a simpler grouping. </p> <!-- end en only --> <!-- begin en only --> <p> When you talked your analysis directly to the president of the company, you are appointed to plan rolling blackouts for this summer. Be careful what you propose. Anyway, you need to divide the servicing area into as many groups as possible with keeping total demand of electricity within the supply capacity. It should also divide the towns into simple and easy to remember groups. </p> <!-- end en only --> <!-- begin en only --> <p> Your task is to write a program, given a demand table (a table showing electricity demand of each town) and the supply capacity, that answers a grouping of towns that satisfy the following conditions. </p> <!-- end en only --> <!-- begin en only --> <ol> <li>The grouping should be made by horizontally or vertically splitting the area in a recursive manner. In other words, the grouping must be a set of areas after applied the following splitting procedure to a set containing only the entire area for zero or more times: <blockquote>(The splitting procedure) remove one area from the set, either vertically or horizontally split it into two sub-areas, and put the sub-areas into the set. <!-- replace one area in the set with two sub-areas that are obtained by splitting it either vertically or horizontally. pick one area and split it either vertically or horizontally. --> </blockquote> <!-- In other words, the groups are formed by repeatedly split an area either vertically or horizontally into two areas. --> </li> <li>The maximum suppressed demand of the grouping, which is the greatest total demand of the all but one group, is no more than the supply capacity.</li> <li>The grouping has the largest number of groups among the groupings that satisfy the above conditions 1 and 2.</li> <li>The grouping has the greatest amount of reserve power among the groupings that satisfy the above conditions 1, 2 and 3, where the reserve power of a grouping is the difference between the supply capacity and the maximum suppressed demand.</li> </ol> <!-- end en only --> <!-- begin en only --> <p>Note that the condition 1 does not allow such a grouping shown in Figure E-1.</p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_1176" align="center" width="200" height="200"/><br/> <!-- begin en only --> Figure E-1: A grouping that violates the condition 1 <!-- end en only --> <br/><br/> </center> </div> <h3>Input</h3> <div> <!-- begin en only --> <p>The input consists of one or more datasets. Each dataset is given in the following format.</p> <!-- end en only --> <blockquote> <i>h w s</i> <br/> <i>u</i><sub>11</sub> <i>u</i><sub>12</sub> ... <i>u</i><sub>1<i>w</i></sub><br/> <i>u</i><sub>21</sub> <i>u</i><sub>22</sub> ... <i>u</i><sub>2<i>w</i></sub><br/> ... <br/> <i>u</i><sub><i>h</i>1</sub> <i>u</i><sub><i>h</i>2</sub> ... <i>u</i><sub><i>h</i><i>w</i></sub><br/> </blockquote> <!-- begin en only --> <p> The first line contains three positive integer numbers, namely <i>h</i>, <i>w</i> and <i>s</i>, denoting the height and width of the demand table and the power supply capacity. The following <i>h</i> lines, each of which contains <i>w</i> integer numbers, denote demands of towns at respective locations. Those figures are constrained as follows. </p> <!-- end en only --> <blockquote> 1 &le; <i>h</i>, <i>w</i> &le; 32 <br/> 1 &le; <i>u<sub><i>ij</i></sub></i> &le; 100<br/> </blockquote> <!-- begin en only --> <p> Regrettably, you may assume that the supply capacity is less than the total demand of the area. </p> <!-- end en only --> <!-- begin en only --> <p> The last dataset is followed by a line containing three zeros. </p> <!-- end en only --> </div> <h3>Output</h3> <div> <!-- begin en only --> <p> For each dataset, print a line having two integers indicating the number of groups in the grouping that satisfies the conditions, and the amount of the reserve power. Each line should not have any character other than those numbers and a space in between. </p> <!-- end en only --> </div> <h3>Sample Input</h3> <div> <pre> 3 3 33 4 4 2 2 9 6 6 5 3 3 4 15 1 2 1 2 2 1 2 1 1 2 1 2 32 32 1112 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 2 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 4 1 6 0 553 0 </pre> </div>
p01845
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h3>カレヌ䜜り</h3> <p>ACM-ICPC囜内予遞が近づいおきたので緎習に远い蟌みをかけたいず思っおいたあなたは友人宅で行われる競技プログラミング合宿に参加するこずにした 参加者のこだわりで食事は自炊するこずになった </p> <p>合宿初日の倜参加者達はその日の緎習を終え倕食の準備に取り掛かり始めた 競技プログラミングだけでなく自炊でも「プロ」ず友人によく蚀われるあなたは担圓分のメニュヌをあっずいう間に䜜り終えおしたい暇を持お䜙しおしたった そこで他の人が担圓しおいたカレヌ䜜りを手䌝うこずにした </p> <p>今<i>W<sub>0</sub></i> [L] の氎に <i>R<sub>0</sub></i> [g] のルりを混ぜた䜜りかけのカレヌがある 今回䜿うルりは 1 皮類で1 個あたり <i>R</i> [g] であるルりは十分な量の備蓄がある あなたはこのルりを䜿う堎合濃床が <i>C</i> [g/L] のカレヌが最も矎味しいず考えおいるのでこのカレヌにいく぀かのルりず氎を適切に加え濃床を <i>C</i> [g/L] にしたいず考えおいる ここでルり <i>R<sub>0</sub></i> [g] が氎 <i>W<sub>0</sub></i> [L] に溶けおいるカレヌの濃床は <i>R<sub>0</sub> / W<sub>0</sub></i> [g/L] でありこのカレヌに <i>R</i> [g] のルりを <i>X</i> 個ず氎 <i>Y</i> [L] を远加するずその濃床は (<i>R<sub>0</sub> + X R</i>) / (<i>W<sub>0</sub> + Y</i>) [g/L] になる ルりは倧量にあるものの䜿い過ぎるのは良くないず考えたあなたは远加するルりの個数を出来る限り少なくしお濃床 <i>C</i> [g/L] のカレヌを䜜るこずにした </p> <p>濃床 <i>R<sub>0</sub>/W<sub>0</sub></i> [g/L] のカレヌにルりか氎のいずれかたたはその䞡方を適切に加えるこずによっお濃床 <i>C</i> [g/L] のカレヌを䜜るずき远加すべきルりの個数 <i>X</i> の最小倀を求めお欲しい </p> <p>ただし今回のカレヌ䜜りに぀いおは以䞋の事柄に泚意するこず </p><ul><li>远加するルりの個数 <i>X</i> の倀は 0 以䞊の敎数でなければならない぀たりルりを 1/3 個分だけ远加するずいったこずは出来ない </li><li>远加する氎の䜓積 <i>Y</i> の倀は 0 以䞊の実数ずしお良く敎数である必芁はない </li><li>ルりか氎のいずれかたたはその䞡方を远加しなくおも濃床 <i>C</i> のカレヌを䜜るこずが出来る堎合もある </li><li>ルりや氎は十分な量を確保しおいるのでルりや氎が足りず濃床 <i>C</i> のカレヌを䜜るこずが出来ないずいう事態は起こらないずしお良い </li></ul> <h3>Input</h3> <p>入力は耇数のデヌタセットからなる 各デヌタセットは 1 行からなり次の圢匏で衚される </p> <blockquote><i>R<sub>0</sub></i> <i>W<sub>0</sub></i> <i>C</i> <i>R</i></blockquote> <p>ここで<i>R<sub>0</sub></i><i>W<sub>0</sub></i><i>C</i><i>R</i> はそれぞれ䜜りかけのカレヌに既に溶け蟌んだルりの質量 [g]カレヌに含たれる氎の䜓積 [L]あなたが䜜りたいカレヌの濃床 [g/L]ルり 1 個あたりの質量 [g] を衚す これらの倀は党お 1 以䞊 100 以䞋の敎数である 入力の終わりは空癜で区切られた 4 ぀のれロからなる行によっお瀺される </p> <h3>Output</h3> <p>各デヌタセットに぀いお<i>W<sub>0</sub></i> [L] の氎に <i>R<sub>0</sub></i> [g] のルりを混ぜた䜜りかけのカレヌから濃床 <i>C</i> のカレヌを䜜るために远加する必芁のあるルりの個数の最小倀を 1 行で出力するこず远加する氎の量を出力しおはならない </p> <p>入力制玄から各デヌタセットの答えずなるルりの個数の最小倀は32ビット笊号付き敎数で衚珟される範囲におさたるこずが保蚌されるこずに泚意せよ </p> <h3>Sample Input</h3> <pre>10 5 3 4 2 5 2 3 91 13 7 62 10 1 3 5 20 100 2 20 2 14 7 1 0 0 0 0</pre> <h3>Output for Sample Input</h3> <pre>2 3 0 0 9 96 </pre>
p03878
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>There are <var>N</var> computers and <var>N</var> sockets in a one-dimensional world. The coordinate of the <var>i</var>-th computer is <var>a_i</var>, and the coordinate of the <var>i</var>-th socket is <var>b_i</var>. It is guaranteed that these <var>2N</var> coordinates are pairwise distinct.</p> <p>Snuke wants to connect each computer to a socket using a cable. Each socket can be connected to only one computer.</p> <p>In how many ways can he minimize the total length of the cables? Compute the answer modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 10^5</var></li> <li><var>0 ≀ a_i, b_i ≀ 10^9</var></li> <li>The coordinates are integers.</li> <li>The coordinates are pairwise distinct.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> : <var>a_N</var> <var>b_1</var> : <var>b_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to minimize the total length of the cables, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 10 20 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are two optimal connections: <var>0-20, 10-30</var> and <var>0-30, 10-20</var>. In both connections the total length of the cables is <var>40</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 10 8 7 12 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre></section> </div> </span>
p00307
<h1>ネットカフェ</h1> <p> あなたはネットカフェを経営しおいたす。今日あなたは、顧客に指摘され続けおいる問題を解決しようず取り組んでいたす。その問題ずは、店舗の本棚の単行本が巻数順に䞊んでおらず、目的の単行本を探しだすのが面倒だずいう苊情です。 </p> <p> あなたの店舗で䞀番巻数の倚い単行本は「名探偵 赀ベコ」通称「赀ベコ」です。あたりに長線なので、特別な本棚を「赀ベコ」のために甚意したした。 </p> <p> 単行本の各巻の重さず厚さは様々で、本棚の各段の幅ず、各段に䞊べるこずができる本の重さの䞊限も様々です。あなたは、次の条件を満足するように本棚に本を䞊べるこずにしたした。 </p> <ul> <li> 1 巻からある巻たでの「赀ベコ」が本棚に䞊んでいる。</li> <li> それぞれの段には、巻数順に途䞭で抜けおいる巻がないように本が䞊ぶ。</li> <li> 各段に䞊べる本の重さの合蚈が、その段で定められた重さの䞊限を超えない。</li> <li> 各段に䞊べる本の厚さの合蚈が、その段の幅を超えない。</li> </ul> <p> これらの条件を満たしたずきこの本棚に最倧で䜕巻たで「赀ベコ」を䞊べるこずができるかを求めるプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>M</var> <var>N</var> <var>w<sub>1</sub></var> <var>t<sub>1</sub></var> <var>w<sub>2</sub></var> <var>t<sub>2</sub></var> : <var>w<sub>M</sub></var> <var>t<sub>M</sub></var> <var>c<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>2</sub></var> <var>b<sub>2</sub></var> : <var>c<sub>N</sub></var> <var>b<sub>N</sub></var> </pre> <p> 最初の行に「赀ベコ」の巻数 <var>M</var> (1 &le; <var>M</var> &le; 200000) ず本棚の段数 <var>N</var> (1 &le; <var>N</var> &le; 15) が䞎えられる。続く <var>M</var> 行に、「赀ベコ」の単行本 <var>i</var> 巻目の重さ <var>w<sub>i</sub></var> (1 &le; <var>w<sub>i</sub></var> &le; 100) ず厚さ <var>t<sub>i</sub></var> (1 &le; <var>t<sub>i</sub></var> &le; 100) を衚す敎数が䞎えられる。続く <var>N</var> 行に、本棚の <var>i</var> 段目の重さの䞊限 <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; 10<sup>8</sup>)ず幅 <var>b<sub>i</sub></var> (1 &le; <var>b<sub>i</sub></var> &le; 10<sup>8</sup>) を衚す敎数が䞎えられる。 </p> <h2>出力</h2> <p> 本棚に䞊べるこずができる最倧の「赀ベコ」巻数を行に出力する。 </p> <h2>入出力䟋</h2> <h2>入力䟋</h2> <pre> 3 4 2 2 3 3 4 4 3 3 4 4 1 1 2 2 </pre> <h2>出力䟋</h2> <pre> 3 </pre> <br> <h2>入力䟋</h2> <pre> 2 2 1 2 2 1 2 1 2 1 </pre> <h2> 出力䟋</h2> <pre> 0 </pre> <br> <h2>入力䟋</h2> <pre> 3 2 1 2 2 2 2 1 3 3 2 2 </pre> <h2> 出力䟋</h2> <pre> 2 </pre> <br> <h2>入力䟋</h2> <pre> 3 2 1 2 2 1 2 2 2 2 3 3 </pre> <h2>出力䟋</h2> <pre> 3 </pre>
p00612
<H1><font color="#000000">Problem H:</font> Hedro's Hexahedron</H1> <p> Dr. Hedro is astonished. According to his theory, we can make sludge that can dissolve almost everything on the earth. Now he's trying to produce the sludge to verify his theory. </p> <p> The sludge is produced in a rectangular solid shaped tank whose size is <i>N</i> &times; <i>N</i> &times; 2. Let coordinate of two corner points of tank be (-<i>N</i>/2, -<i>N</i>/2, -1), (<i>N</i>/2, <i>N</i>/2, 1) as shown in Figure 1. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hedro2"> <p>Figure 1</p> </center> <br> <p> Doctor pours liquid that is ingredient of the sludge until height of the liquid becomes 1. Next, he get a lid on a tank and rotates slowly, without ruffling, with respect to <i>z</i> axis (Figure 2). After rotating enough long time, sludge is produced. Volume of liquid never changes through this operation. </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hedro"> <p>Figure 2</p> </center> <br> <p> Needless to say, ordinary materials cannot be the tank. According to Doctor's theory, there is only one material that is not dissolved by the sludge on the earth. Doctor named it finaldefenceproblem (for short, FDP). To attach FDP tiles inside the tank allows to produce the sludge. </p> <p> Since to produce FDP is very difficult, the size of FDP tiles are limited to 1 * 1. At first, doctor tried to cover entire the entire inside of the tank. However, it turned out that to make enough number FDP tiles that can cover completely is impossible because it takes too long time. Therefore, he decided to replace FDP tiles where an area the sludge touches is zero with those of ordinary materials. All tiles are very thin, so never affects height of the sludge. </p> <p> How many number of FDP tiles does doctor need? He has imposed this tough problem on you, his helper. </p> <H2>Input</H2> <p> Input file contains several data sets. Each data set has one integer that describes <i>N</i>. </p> <p> Input ends when <i>N</i> = 0. You should output nothing for this case. </p> <H2>Output</H2> <p> For each data set, print the number of tiles in a line. </p> <H2>Constraints</H2> <ul> <li>Judge data consists of at most 150 datasets.</li> <li>2 &le; <i>N</i> &le; 10<sup>12</sup></li> <li><i>N</i> is even number</li> </ul> <H2>Sample Input</H2> <pre> 2 4 0 </pre> <H2>Output for the Sample Input</H2> <pre> 24 64 </pre>
p01900
<link rel="stylesheet" href="css/description.css" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script> <h2>C : Mod!Mod!</h2> <h3>物語</h3> <p> じゃん探しおたすよ目撃蚌蚀 䌚接に怪盗が珟れたみんなのりマりマ棒が盗たれた犯人は誰だ 解きあかせMod!Mod! </p> <h3>問題文</h3> <p>"アむズ"...それは遞ばれし者の心に膚らむ奇跡の぀がみ...。特殊胜力"アむズ"を䜿えばどんなものだっお盗むこずができる。</p> <p>䌚接䞀の倧怪盗、あいずたるは䞖界を謎で満たすために<var>n</var>人の探偵から「りマりマ棒」を盗むこずにした。りマりマ棒ずはあいずたるが倧奜きなただのお菓子であり、<var>n</var>人の探偵はそれぞれ数本のりマりマ棒を持っおいる。たた、あいずたるは匷欲なためそれぞれの探偵からりマりマ棒を盗むずき、その探偵が所持する党おのりマりマ棒を盗む。</p> <p>りマりマ棒の3本同時食いにハマっおいるあいずたるは、3本以䞊のりマりマ棒が手元にあるずき、誘惑に負けお手持ちのりマりマ棒が3本未満になるたで、3本ず぀りマりマ棒を食べおしたう。しかし、あいずたるは手元にりマりマ棒がないずショックでアむズを倱っおしたい、それ以䞊りマりマ棒を盗むこずができなくなっおしたう。぀たり、りマりマ棒を盗むためには手持ちのりマりマ棒の本数を1本以䞊にしおおく必芁があり、0本になるずそれ以䞊りマりマ棒を盗むこずができなくなる。</p> <p>少しでも倚くの探偵からりマりマ棒を盗みたいあいずたるは、どの探偵から順にりマりマ棒を盗むかによっお䜕人の探偵からりマりマ棒を盗めるのかが倉わるこずに気づいた。しかし、あいずたるには難しいこずは分からない。「ハテヌ」あいずたるの優秀な郚䞋であるあなたは、あいずたるの代わりに最倧で䜕人の探偵からりマりマ棒を盗むこずができるのかを求めるプログラムを曞いおあげるこずにした。</p> <p>探偵の人数<var>n</var>ず、<var>n</var>人の探偵からそれぞれ䜕本のりマりマ棒を盗むのかが䞎えられるので、最適な順番で探偵からりマりマ棒を盗んだずき、最倧で䜕人の探偵からりマりマ棒を盗むこずができるかを出力するプログラムを䜜成せよ。ただし、はじめの手持ちのりマりマ棒の本数は0であるが、最初に限り手持ちが0本でもりマりマ棒を盗むこずができるずする。</p> <h3>入力圢匏</h3> <p>入力は2行からなり、以䞋の圢匏で䞎えられる。</p> <pre> <var>n</var> <var>a_1</var> <var>a_2</var> 
 <var>a_n</var> </pre> <p> 1行目には、りマりマ棒を盗む探偵の数である敎数<var>n</var>が䞎えられる。 2行目には、各探偵から盗むりマりマ棒の本数<var>n</var>個が空癜区切りで䞎えられる。 </p> <h3>制玄</h3> <ul> <li><var>1 &le; n &le; 500{,}000</var></li> <li><var>1 &le; a_i &le; 9</var> (<var>1 &le; i &le; n</var>)</li> </ul> <h3>出力圢匏</h3> <p>最適な順番で探偵からりマりマ棒を盗んだずき、最倧で䜕人の探偵からりマりマ棒を盗むこずができるか䞀行に出力せよ。</p> <h3>入力䟋1</h3> <pre> 6 2 5 2 5 2 1 </pre> <h3>出力䟋1</h3> <pre>5</pre> <p>2 5 1 2 5の順で盗むず5人から盗むこずができる。どのような順序で盗んでも6人から盗むこずはできない。</p> <h3>入力䟋2</h3> <pre> 3 3 6 9 </pre> <h3>出力䟋2</h3> <pre>1</pre> <p>どの1人から盗んでも手持ちのりマりマ棒の本数は0になっおしたい、アむズを倱っおしたう。</p> <h3>入力䟋3</h3> <pre> 6 1 2 3 4 5 6 </pre> <h3>出力䟋3</h3> <pre>6</pre>
p00242
<H1>入力候補</H1> <p> 携垯電話には、メヌルなどの文章を効率良く入力するために入力候補を衚瀺する機胜が搭茉されおいたす。これは、䜿われる頻床が高い単語を蚘録しおおき、入力された文字を頭文字に持぀単語を入力候補ずしお提瀺するものです。䟋えば、普段”computer”ずいう単語を倚く入力しおいるなら、”c”ず入力するだけで候補ずしお”computer”が提瀺されたす。このような機胜の基本郚分を䜜成しおみたしょう。 </p> <p> 文章、文字を入力ずし、その文字を頭文字に持぀単語を出珟数の順に出力するプログラムを䜜成しおください。ただし、出珟数が同じ単語が耇数ある堎合は、蟞曞匏順序で出力したす。出力する単語は最倧5぀たでずしたす。該圓する単語が存圚しない堎合は”NA”ず出力しおください。 </p> <h2>入力</h2> <p> 耇数のデヌタセットが䞎えられたす。入力の終わりはれロひず぀で衚されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>line<sub>1</sub></var> <var>line<sub>2</sub></var> : <var>line<sub>n</sub></var> <var>k</var> </pre> <p> 1行目に文章の行数 <var>n</var> (1 &le; <var>n</var> &le; 10) が䞎えられたす。続く <var>n</var> 行に文章が䞎えられたす。文章は半角英小文字ず半角空癜からなり、行の文字数は1文字以䞊1024文字以䞋ずしたす。空癜によっお区切られる単語は1文字以䞊20文字以䞋です。 </p> <p> 続く行に頭文字 <var>k</var> が半角英字で䞎えられたす。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <h2>出力</h2> <p> デヌタセットごずに、指定された文字を頭文字にも぀単語たたは”NA” を出力したす。 </p> <h2>入力䟋</h2> <pre> 1 ben likes bananas the best among many fruits because bananas are sweet and cheap b 1 winners get to visit aizu and the university of aizu and make many friends as well a 3 ask alex about the answer for the assignment on android apps a 2 programming is both a sport and an intellectual puzzle c 0 </pre> <h2>出力䟋</h2> <pre> bananas because ben best aizu and as about alex android answer apps NA </pre>
p02785
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Fennec is fighting with <var>N</var> monsters.</p> <p>The <em>health</em> of the <var>i</var>-th monster is <var>H_i</var>.</p> <p>Fennec can do the following two actions:</p> <ul> <li>Attack: Fennec chooses one monster. That monster's health will decrease by <var>1</var>.</li> <li>Special Move: Fennec chooses one monster. That monster's health will become <var>0</var>.</li> </ul> <p>There is no way other than Attack and Special Move to decrease the monsters' health.</p> <p>Fennec wins when all the monsters' healths become <var>0</var> or below.</p> <p>Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most <var>K</var> times.</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>0 \leq K \leq 2 \times 10^5</var></li> <li><var>1 \leq H_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>H_1</var> <var>...</var> <var>H_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 9 7 9 3 2 3 8 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>She can use Special Move on all the monsters.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 0 1000000000 1000000000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3000000000 </pre> <p>Watch out for overflow.</p></section> </div> </span>
p03897
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have an <var>N×N</var> checkerboard.</p> <p>From the square at the upper left corner, a square that is <var>i</var> squares to the right and <var>j</var> squares below is denoted as <var>(i, j)</var>. Particularly, the square at the upper left corner is denoted as <var>(0, 0)</var>.</p> <p>Each square <var>(i, j)</var> such that <var>i+j</var> is even, is colored black, and the other squares are colored white.</p> <p>We will satisfy the following condition by painting some of the white squares:</p> <ul> <li>Any black square can be reached from square <var>(0, 0)</var> by repeatedly moving to a black square that shares a side with the current square.</li> </ul> <p>Achieve the objective by painting at most <var>170000</var> squares black.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1,000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the squares to paint in the following format:</p> <pre><var>K</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_K</var> <var>y_K</var> </pre> <p>This means that a total of <var>K</var> squares are painted black, the <var>i</var>-th of which is <var>(x_i, y_i)</var>.</p> </section> </div> <div class="part"> <section> <h3>Judging</h3><p>The output is considered correct only if all of the following conditions are satisfied:</p> <ul> <li><var>0 \leq K \leq 170000</var></li> <li><var>0 \leq x_i, y_i \leq N-1</var></li> <li>For each <var>i</var>, <var>x_i + y_i</var> is odd.</li> <li>If <var>i \neq j</var>, then <var>(x_i, y_i) \neq (x_j, y_j)</var>.</li> <li>The condition in the statement is satisfied by painting all specified squares.</li> </ul> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 1 0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 0 1 2 1 2 3 </pre></section> </div> </span>
p01003
<h1>Problem E: Doragoso Ball</h1> <h2>Problem</h2> <p> <var> L </var>個集めるずドラゎ゜が珟れどんな願いでも䞀぀だけ叶えおくれるずいうドラゎ゜ボヌルがずある迷宮に散らばっおいる。入口からスタヌトし、途䞭で立ち止たるこずなくすべおのボヌルを回収し、それらを迷宮内にある祭壇に奉玍し、そのたた呪文を唱えるずドラゎ゜が珟れ願いを叶えおくれるずいう。ただし、呪文を唱え始める時間は入口からボヌルを奉玍するたでのルヌトのうち、移動時間が<var> K </var>番目に短いルヌトで移動したずきの時間でなければならない。 </p> <p> この迷宮は郚屋ずわたり通路からなり、郚屋ず郚屋はわたり通路を通る事によっお行き来できる。ドラゎ゜ボヌルはそれらの数ある郚屋のどこかに萜ちおいる。<!--だが、科孊の進歩により、迷宮の郚屋ず郚屋の䜍眮関係の解析が進み、ドラゎ゜レヌダヌの開発によっおどの郚屋にボヌルが萜ちおいるかも把握できる予定である。文研究所に郚屋の䜍眮関係ずボヌルの䜍眮のデヌタが送られる予定である。ずある研究所で最も優秀なプログラマヌであるあなたは、呪文を唱え始めるべき時間を求めるずいう重芁な任務が䞎えられた。-->なお、迷宮は入り口から祭壇ぞたどり぀く道が存圚しない可胜性もあるようだ。たた、移動時間はわたり通路の移動だけを考慮し、郚屋の䞭を移動する時間、ボヌルを拟うずきにかかる時間、祭壇に奉玍する時間は考慮しなくおよい。<!--たた、同じ郚屋に䜕床も蚪れおもよいが、ドラゎ゜ボヌルがある郚屋に初めお入った堎合は、そのボヌルを拟うこずにする。-->たた、同じ通路や同じ郚屋に䜕床も蚪れおもよいが、ドラゎ゜ボヌルがある郚屋に初めお入った堎合は、そのボヌルを拟うこずにする。祭壇に到達したずき、必ずしもボヌルを玍めなければならないわけではない。 </p> <p> 迷宮の内郚構造の情報ず迷宮の入り口、祭壇の堎所ずボヌルの数<var> L </var>ずボヌルの配眮堎所ず求められおいる最短な経路の順䜍<var> K </var>が䞎えられるので、呪文を唱え始めるべき時間を求めよ。 </p> <p> たた、異なる移動ルヌトでも、移動時間が同じである堎合はそれらのルヌトは同じ順䜍ずしお扱う。 <br/> 䟋えば、 <br/> <pre> ルヌトA 時間 2 ルヌトB 時間 5 ルヌトC 時間 5 ルヌトD 時間 5 ルヌトE 時間 5 ルヌトF 時間 7 </pre> <p> このようなずき、ルヌトB,C,D,Eは2䜍か぀3䜍か぀4䜍か぀5䜍ずしお扱う。ルヌトFは6䜍ずしお扱う。 </p> <h2>Input</h2> <p> 入力は耇数のデヌタセットからなる。</br> 各デヌタセットは以䞋のフォヌマットで衚される。 </p> <pre> <var>N</var> <var>M</var> <var>L</var> <var>K</var> <var>u<sub>1</sub></var> <var>v<sub>1</sub></var> <var>c<sub>1</sub></var> 
 <var>u<sub>M</sub></var> <var>v<sub>M</sub></var> <var>c<sub>M</sub></var> <var>S</var> <var>G</var> <var>B<sub>1</sub></var> <var>B<sub>2</sub></var> 
 <var>B<sub>L</sub></var> </pre> <p> 最初に<var> N </var>,<var> M </var>,<var> L </var>,<var> K </var>が䞎えられる。</br> それぞれ、郚屋の数、わたり通路の数、ボヌルの数、求められおいる最短な経路の順䜍を衚す。それぞれの郚屋は1〜<var> N </var>で番号付けされる。</br> 次に<var> M </var>行にわたり通路の情報、<var> u<sub>i</sub> </var>,<var> v<sub>i</sub> </var>,<var> c<sub>i</sub> </var>が䞎えられる。</br> 郚屋<var> u<sub>i</sub> </var>,<var> v<sub>i</sub> </var>間にわたり通路が存圚し、通過するのに時間<var> c<sub>i</sub> </var>がかかるこずを衚す。</br> 次に<var> S </var>,<var> G </var>が䞎えられる。</br> それぞれ、迷宮の入り口ず祭壇がある郚屋番号を衚す。</br> 次に<var> L </var>行にわたっおドラゎ゜ボヌルが萜ちおいる郚屋の番号<var> B<sub>i</sub> </var>( 1 &le;<var> i </var>&le;<var> L </var>)が䞎えられる。</br> </p> <p> 入力の終わりは4぀のれロからなる。</br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>入力に含たれる倀はすべお敎数</li> <li>2 &le;<var> N </var>&le; 50</li> <li>0 &le;<var> M </var>&le; 1225</li> <li>1 &le;<var> L </var>&le; 7</li> <li>1 &le;<var> K </var>&le; 10</li> <li>1 &le;<var> S </var>,<var> G </var>&le; <var>N</var></li> <li>1 &le;<var> B<sub>i</sub> </var>&le; <var>N </var>( 1 &le;<var> i </var>&le; <var> L </var>)</li> <li><var> B<sub>i</sub> </var>&ne;<var> B<sub>j</sub> </var> ( 1 &le;<var> i </var>&lt;<var> j </var>&le;<var> L </var>)</li> <li>1 &le;<var> u<sub>i</sub> </var>,<var> v<sub>i</sub> </var>&le;<var> N </var>( 1 &le;<var> i </var>&le; <var> M </var>)</li> <li>1 &le;<var> c<sub>i</sub> </var>&le; 1000 ( 1 &le;<var> i </var>&le; <var> M </var>)</li> <li>デヌタセットは最倧10個である</li> </ul> <h2>Output</h2> <p>各デヌタセットに察し、呪文を唱え始めるべき時間を1行に出力せよ。<var> K </var>番目に短い経路が存圚しない堎合は"NA"を1行に出力せよ。</p> <h2>Sample Input</h2> <pre> 9 14 5 10 1 2 1 1 4 5 2 4 4 2 3 3 2 6 2 3 6 3 3 7 2 4 6 5 4 5 6 5 8 8 6 7 3 7 8 1 7 9 9 8 9 2 1 9 1 2 5 7 9 4 5 1 3 1 2 1 1 3 2 2 3 2 2 4 9 3 4 1 1 4 2 4 5 1 10 1 2 1 1 3 2 2 3 2 2 4 9 3 4 1 1 4 2 4 3 1 1 1 2 1 2 3 1 3 4 1 1 4 1 4 3 1 2 1 2 1 2 3 1 3 4 1 1 4 1 4 3 1 10 1 2 1 2 3 1 3 4 1 1 4 1 2 1 1 1 1 2 1 1 2 1 2 1 1 10 1 2 1 1 2 1 4 2 1 4 1 2 1 3 4 1 1 4 2 0 0 0 0 </pre> <h2>Sample Output</h2> <pre> 27 6 8 3 5 7 1 19 NA </pre>
p01453
<H1>Problem G: スプリング・タむル</H1> <p> ある朝、あなたが目芚めるず、そこはバネだらけの迷宮の䞭だった。 </p> <p> なぜ自分がこんな芋知らぬ堎所にいるのかはわからない。この堎でじっず助けを埅぀ずいう遞択肢も あるにはあるが、こういった迷宮の䞭に長居しおいるず、い぀かは必ず突颚が吹いおきお吹き飛ばさ れおしたうこずを、あなたは経隓䞊知っおいた。しかし、突颚が吹いおくるたでの時間は刀断のしよ うがない。そこであなたは、迷宮から脱出するたでに必芁な移動回数の期埅倀が最小になるように行 動するのが最善の戊略だず考えた。 </p> <p> 足元に萜ちおいた正䜓䞍明の巻物を拟っおためしに読んでみたずころ、偶然にも迷宮の党䜓マップを 知芚するこずができた。さらに、たたたた持っおいた草を飲むこずで、すべおのワナの䜍眮も知るこ ずができた。どうやらこの迷宮には、危険なモンスタヌやバネ以倖のワナは存圚しないらしい。 </p> <p> この迷宮は、いく぀かの皮類のタむルが長方圢に䞊んだ圢をしおおり、たずえば以䞋のようにあらわ される。 </p> <center> <pre> ######## #..##g.# #*#.*#.# #......# #*s#*.*# ######## </pre> </center> <p> 「.」床。この䞊なら自由に歩き回るこずができる。 </p> <p> 「#」壁。あなたは壁の䞭に入るこずはできない。 </p> <p> 「s」あなたの最初の䜍眮。このタむルの䞋は床になっおいる。 </p> <p> 「g」階段。このタむルの䞊に乗れば、迷宮を脱出したこずになる。 </p> <p> 「*」バネ。このタむルの䞊に乗るず、いずれかの床の䞊階段、バネのタむルは陀くにランダムに飛ばされる。それぞれの床に飛ばされる確率はすべお等しい。 </p> <p> タむルの皮類は、この぀のいずれかである。 </p> <p> あなたは、珟圚乗っおいるタむルから隣り合ったタむルぞ、䞊䞋巊右いずれかの方向にマスず぀移 動するこずができる。ただし、ナナメに移動するこずはできない。 </p> <p> 迷宮のマップが䞎えられたずき、最善の戊略をずった堎合に迷宮から脱出するたでに必芁な移動回数 の期埅倀を求めよ。バネで飛ばされるのは移動回数には含めない。 </p> <H2>Input</H2> <p> <i>W H</i><br> <i>c</i><sub>11</sub> <i>c</i><sub>12</sub> ... <i>c</i><sub>1<i>w</i></sub><br> <i>c</i><sub>21</sub> <i>c</i><sub>22</sub> ... <i>c</i><sub>2<i>w</i></sub><br> :: &nbsp; &nbsp;:<br> <i>c</i><sub><i>h</i>1</sub> <i>c</i><sub><i>h</i>2</sub> ... <i>c</i><sub><i>c</i><i>w</i></sub><br> </p> <p> 入力の行目には、敎数<i>W</i>3 &le; <i>W</i> &le; 500ず敎数<i>H</i>3 &le; <i>H</i> &le; 500が、この順に空癜区切りで曞かれおいる。敎数<i>W</i> は迷宮の暪幅を、敎数<i>H</i> は迷宮の瞊幅をあらわす。 </p> <p> 続く<i>H</i> 行には、迷宮のマップをあらわす<i>W</i> 個の文字が曞かれおいる空癜区切りではない。この郚分の圢匏は、先に挙げた䟋のずおりである。なお、デヌタ䞭に「s」ず「g」は、それぞれちょうど回ず぀出珟する。たた、迷宮の呚囲マスは、必ず壁で囲たれおいる。 </p> <p> なお、䞎えられる迷宮では、どのように移動し、バネでどのように飛ばされたずしおも、「バネで飛 ばされる床を任意に蚭定できたずしおも脱出䞍可胜な状態」に陥るこずはないず仮定しおよい。 </p> <H2>Output</H2> <p> 最善の戊略をずったずきに、脱出たでにかかる移動回数の期埅倀を出力せよ。出力は誀差を含んでい おもよいが、真の倀ずの盞察誀差が10<sup>-9</sup> 未満でなければならない。 </p> <h2>Sample Input 1</h2> <pre> 8 6 ######## #..##g.# #*#.*#.# #......# #*s#*.*# ######## </pre> <h2>Sample Output 1</h2> <pre> 5.857142857143 </pre> <h2>Sample Input 2</h2> <pre> 21 11 ##################### #*#*.*.*.*.*.*.*.*#*# #*#...............#*# #*#.#.#.#.#.#.#.#.#*# ##.#.#.#.#.#.#.#.#.## #...................# ##.#.#.#.#.#.#.#.#.## #s#.#.#.#.#.#.#.#.#g# #...................# #...................# ##################### </pre> <h2>Sample Output 2</h2> <pre> 20.000000000000 </pre> <h2>Sample Input 3</h2> <pre> 9 8 ######### #...#*.*# #.*.#...# #...#*.*# ######### #.s....g# #.*#.*..# ######### </pre> <h2>Sample Output 3</h2> <pre> 5.000000000000 </pre>
p03194
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> integers <var>a_1, a_2, ..., a_N</var> not less than <var>1</var>. The values of <var>a_1, a_2, ..., a_N</var> are not known, but it is known that <var>a_1 \times a_2 \times ... \times a_N = P</var>.</p> <p>Find the maximum possible greatest common divisor of <var>a_1, a_2, ..., a_N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^{12}</var></li> <li><var>1 \leq P \leq 10^{12}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>P</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 24 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The greatest common divisor would be <var>2</var> when, for example, <var>a_1=2, a_2=6</var> and <var>a_3=2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>As <var>a_i</var> are positive integers, the only possible case is <var>a_1 = a_2 = a_3 = a_4 = a_5 = 1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>111 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 972439611840 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>206 </pre></section> </div> </span>
p02156
<h1>Problem H: Ghost</h1> <h2>Problem</h2> <p> 幜霊が䞀盎線䞊に巊から右に$N$人䞊んでいる。<br> 最初、巊から$i$番目の幜霊は$U_i$が'L'ならば巊を、'R'ならば右を向いおいる。<br> <br> 圌らはずおも臆病なのでなるべく怖い幜霊を芋たくない。<br> <br> あなたは、各幜霊に察しお振り返るように指瀺をできる。<br> 埌ろを振り返るのは怖いので、$i$番目の幜霊が䞀回振り返るず$A_i$の恐怖床が発生する。<br> 巊を向いおいる幜霊が振り返るず、右を向く。<br> 右を向いおいる幜霊が振り返るず、巊を向く。<br> <br> $ i < j $ に察しお、$i$番目の幜霊が右を向いおいお、か぀$j$番目の幜霊が巊を向いおいる堎合、$i$番目の幜霊ず$j$番目の幜霊は向き合っおいるず定矩する。<br> 以䞋の制玄が$M$個䞎えられる。<br> $S_i$番目の幜霊は$T_i$番目の幜霊が怖い。<br> 最終的な状態で、$S_i$番目の幜霊ず$T_i$番目の幜霊が向き合っおいるず$B_i$の恐怖床が発生する。<br> <br> 最適な指瀺を行なったずきに発生する恐怖床の合蚈の最小倀を求めよ。<br> </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $M$ $U$ $A_1$ $A_2$ $...$ $A_N$ $S_1$ $T_1$ $B_1$ $S_2$ $T_2$ $B_2$ $\vdots$ $S_M$ $T_M$ $B_M$ </pre> <p> 入力はすべお敎数で䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \le N \le 500$</li> <li>$0 \le M \le \min ( N \times (N-1) , 1000 )$</li> <li>$|U|=N$</li_> <li>$U_i = $'L' or 'R'</li> <li>$1 \le A_i \le 1000$</li> <li>$1 \le B_i \le 1000$</li> <li>$1 \le S_i,T_i \le N$</li> <li>$(S_i,T_i) \ne (S_j,T_j), $if $ i \ne j$</li> <li>$S_i \ne T_i$</li> </ul> <h2>Output</h2> <p> 恐怖床の合蚈の最小倀を出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 3 1 RRL 5 5 1 3 1 10 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <p> 3番目の幜霊に振り向くように指瀺をするず、恐怖床の合蚈は1ずなる。恐怖床の合蚈が0以䞋になるような指瀺は存圚しないので、1を出力する。 </p> <h2>Sample Input 2</h2> <pre> 5 5 RLRLL 9 5 1 3 10 1 3 5 2 4 9 4 2 16 1 5 2 3 5 10 </pre> <h2>Sample Output 2</h2> <pre> 8 </pre>
p00491
<H1>パスタ (Pasta) </H1> <h2> 問題</h2> <p> あなたはパスタが倧奜物であり毎日晩埡飯にパスタを䜜っお食べおいるあなたはトマト゜ヌスクリヌム゜ヌスバゞル゜ヌスの 3 皮類のパスタを䜜るこずができる </p> <p> N 日間の晩埡飯の予定を考えるこずにしたそれぞれの日に 3 皮類のパスタから 1 皮類を遞ぶただし同じパスタが続くず飜きおしたうので3 日以䞊連続しお同じパスタを遞んではいけないたたN 日のうちの K 日分のパスタはすでに決めおある </p> <p> 入力ずしお N の倀ずK 日分のパスタの情報が䞎えられたずき条件をみたす予定が䜕通りあるかを 10000 で割った䜙りを求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力は K + 1 行からなる </p> <p> 1 行目には 2 ぀の敎数 N, K (3 ≩ N ≩ 1001 ≩ K ≩ N) が空癜を区切りずしお曞かれおいる <p> 1 + i 行目 (1 ≩ i ≩ K) には 2 ぀の敎数 A<sub>i</sub>, B<sub>i</sub> (1 ≩ A<sub>i</sub> ≩ N1 ≩ B<sub>i</sub> ≩ 3) が空癜を区切りずしお曞かれおいるこれはA<sub>i</sub> 日目のパスタはすでに決たっおおりB<sub>i</sub> = 1 のずきはトマト゜ヌスでありB<sub>i</sub> = 2 のずきはクリヌム゜ヌスでありB<sub>i</sub> = 3 のずきはバゞル゜ヌスであるこずを衚すA<sub>i</sub> (1 ≩ i ≩ K) は党お異なる䞎えられる入力デヌタにおいお条件をみたす予定は 1 通り以䞊あるこずが保蚌されおいる </p> <h2> 出力</h2> <p> 条件をみたす予定が䜕通りあるかを 10000 で割った䜙りを 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 5 3 3 1 1 1 4 2 </pre> <h3>出力䟋 1</h3> <pre> 6 </pre> <p> 入出力䟋 1 においおあなたは 5 日間の予定を考える1 日目ず 3 日目はトマト゜ヌスであり4 日目はクリヌム゜ヌスであるたた3 日以䞊連続しお同じパスタを遞んではいけないこれらの条件をみたす予定は 6 通りある </p> <table style="margin-left: 50px; margin-right: 50px;"> <tr> <th></th> <th>&nbsp;1日目&nbsp;</th> <th>&nbsp;2日目&nbsp;</th> <th>&nbsp;3日目&nbsp;</th> <th>&nbsp;4日目&nbsp;</th> <th>&nbsp;5日目&nbsp;</th> </tr> <tr> <th>予定 1&nbsp;&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">2</td> <td align="center">1</td> <td align="center">2</td> <td align="center">1</td> </tr> <tr> <th>予定 2&nbsp;&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">2</td> <td align="center">1</td> <td align="center">2</td> <td align="center">2</td> </tr> <tr> <th>予定 3&nbsp;&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">2</td> <td align="center">1</td> <td align="center">2</td> <td align="center">3</td> </tr> <tr> <th>予定 4&nbsp;&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">3</td> <td align="center">1</td> <td align="center">2</td> <td align="center">1</td> </tr> <tr> <th>予定 5&nbsp;&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">3</td> <td align="center">1</td> <td align="center">2</td> <td align="center">2</td> </tr> <tr> <th>予定 6&nbsp;&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">3</td> <td align="center">1</td> <td align="center">2</td> <td align="center">3</td> </tr> </table> <br> <p> この衚では1 はトマト゜ヌスを2 はクリヌム゜ヌスを3 はバゞル゜ヌスを衚す </p> <br> <h3>入力䟋 2</h3> <pre> 20 5 10 2 4 3 12 1 13 2 9 1 </pre> <h3>出力䟋 2</h3> <pre> 2640 </pre> <p> 入出力䟋 2 においお条件をみたす予定は党郚で 4112640 通りあるそれを 10000 で割った䜙りである 2640 を出力する </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00868
<H1><font color="#000">Problem E:</font> Spherical Mirrors</H1> <p> <i> A long time ago in a galaxy, far, far away, there were N spheres with various radii. Spheres were mirrors, that is, they had reflective surfaces . . . . </i> </p> <p> You are standing at the origin of the galaxy (0, 0, 0), and emit a laser ray to the direction (<i>u</i>,<i>v</i>, <i>w</i>). The ray travels in a straight line. </p> <p> When the laser ray from <i>I</i> hits the surface of a sphere at <i>Q</i>, let <i>N</i> be a point outside of the sphere on the line connecting the sphere center and Q. The reflected ray goes to the direction towards <i>R</i> that satisfies the following conditions: (1) <i>R</i> is on the plane formed by the three points <i>I</i>, <i>Q</i> and <i>N</i> , (2) &ang; <i>IQN</i> = &ang; <i>NQR</i>, as shown in Figure 1. </p> <center> <table> <tr><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_spherical"></td></tr> <tr><th>Figure 1: Laser ray reflection</th></tr> </table> </center> <p> After it is reflected several times, finally it goes beyond our observation. Your mission is to write a program that identifies the last reflection point. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each in the following format. </p> <pre> <i>N</i> <i>u v w</i> <i>x<sub>1</sub> y<sub>1</sub> z<sub>1</sub> r<sub>1</sub></i> . . . <i>x<sub>N</sub> y<sub>N</sub> z<sub>N</sub> r<sub>N</sub></i> </pre> <p> The first line of a dataset contains a positive integer <i>N</i> which is the number of spheres. The next line contains three integers <i>u</i>, <i>v</i> and <i>w</i> separated by single spaces, where (<i>u</i>, <i>v</i>, <i>w</i>) is the direction of the laser ray initially emitted from the origin. </p> <p> Each of the following <i>N</i> lines contains four integers separated by single spaces. The <i>i</i>-th line corresponds to the <i>i</i>-th sphere, and the numbers represent the center position (<i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> ) and the radius <i>r<sub>i</sub></i> . </p> <p> <i>N</i>, <i>u</i>, <i>v</i>, <i>w</i>, <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> and <i>r<sub>i</sub></i> satisfy the following conditions. </p> <p align="center"> 1 &le; <i>N</i> &le; 100 <br> −100 &le; <i>u</i>, <i>v</i>, <i>w</i> &le; 100<br> −100 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> &le; 100<br> 5 &le; <i>r<sub>i</sub></i> &le; 30<br> <i>u</i><sup>2</sup> + <i>v</i><sup>2</sup> + <i>w</i><sup>2</sup> &gt; 0<br> </p> <p> You can assume that the distance between the surfaces of any two spheres is no less than 0.1. You can also assume that the origin (0, 0, 0) is located outside of any sphere, and is at least 0.1 distant from the surface of any sphere. </p> <p> The ray is known to be reflected by the sphere surfaces at least once, and at most five times. You can assume that the angle between the ray and the line connecting the sphere center and the reflection point, which is known as the angle of reflection (i.e. &theta; in Figure 1), is less than 85 degrees for each point of reflection. </p> <p> The last dataset is followed by a line containing a single zero. </p> <H2>Output</H2> <p> For each dataset in the input, you should print the x-, y- and z-coordinates of the last reflection point separated by single spaces in a line. No output line should contain extra characters. </p> <p> No coordinate values in the output should have an error greater than 0.01. </p> <H2>Sample Input</H2> <pre> 3 -20 -20 -24 100 100 100 30 10 8 3 5 -70 -70 -84 5 4 0 47 84 -23 41 42 8 45 -10 14 19 -5 28 47 12 -27 68 34 14 0 </pre> <H2>Output for the Sample Input</H2> <pre> 79.0940 79.0940 94.9128 -21.8647 54.9770 34.1761 </pre>
p02855
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Chokudai made a rectangular cake for contestants in DDCC 2020 Finals.</p> <p>The cake has <var>H - 1</var> horizontal notches and <var>W - 1</var> vertical notches, which divide the cake into <var>H \times W</var> equal sections. <var>K</var> of these sections has a strawberry on top of each of them.</p> <p>The positions of the strawberries are given to you as <var>H \times W</var> characters <var>s_{i, j}</var> <var>(1 \leq i \leq H, 1 \leq j \leq W)</var>. If <var>s_{i, j}</var> is <code>#</code>, the section at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left contains a strawberry; if <var>s_{i, j}</var> is <code>.</code>, the section does not contain one. There are exactly <var>K</var> occurrences of <code>#</code>s.</p> <p>Takahashi wants to cut this cake into <var>K</var> pieces and serve them to the contestants. Each of these pieces must satisfy the following conditions:</p> <ul> <li>Has a rectangular shape.</li> <li>Contains exactly one strawberry.</li> </ul> <p>One possible way to cut the cake is shown below:</p> <p><img alt=" " src="https://img.atcoder.jp/ddcc2020-qual/47ee461adfe41e931b433ab3e5dae2f3.png"/></p> <p>Find one way to cut the cake and satisfy the condition. We can show that this is always possible, regardless of the number and positions of the strawberries. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq H \leq 300</var></li> <li><var>1 \leq W \leq 300</var></li> <li><var>1 \leq K \leq H \times W</var></li> <li><var>s_{i, j}</var> is <code>#</code> or <code>.</code>.</li> <li>There are exactly <var>K</var> occurrences of <code>#</code> in <var>s</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>K</var> <var>s_{1, 1} s_{1, 2} \cdots s_{1, W}</var> <var>s_{2, 1} s_{2, 2} \cdots s_{2, W}</var> <var>:</var> <var>s_{H, 1} s_{H, 2} \cdots s_{H, W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Assign the numbers <var>1, 2, 3, \dots, K</var> to the <var>K</var> pieces obtained after the cut, in any order. Then, let <var>a_{i, j}</var> be the number representing the piece containing the section at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left of the cake. Output should be in the following format:</p> <pre><var>a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}</var> <var>a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}</var> <var>:</var> <var>a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}</var> </pre> <p>If multiple solutions exist, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 5 #.# .#. #.# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 2 2 1 3 4 5 5 4 </pre> <p>One way to cut this cake is shown below:</p> <p><img alt=" " src="https://img.atcoder.jp/ddcc2020-qual/d09e88243931000a04e555892fe7e6c9.png"> </img></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 7 7 #...#.# ..#...# .#..#.. </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 1 2 2 3 4 4 6 6 2 2 3 5 5 6 6 7 7 7 7 7 </pre> <p>One way to cut this cake is shown below: </p> <p><img alt=" " src="https://img.atcoder.jp/ddcc2020-qual/18d0f45847f5d107ac0322aecea39835.png"/> </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>13 21 106 ..................... .####.####.####.####. ..#.#..#.#.#....#.... ..#.#..#.#.#....#.... ..#.#..#.#.#....#.... .####.####.####.####. ..................... .####.####.####.####. ....#.#..#....#.#..#. .####.#..#.####.#..#. .#....#..#.#....#..#. .####.####.####.####. ..................... </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50 12 12 23 34 45 45 60 71 82 93 93 2 13 24 35 35 17 28 39 50 50 12 12 56 89 89 89 60 104 82 31 31 46 13 24 35 35 61 61 39 50 50 12 12 67 67 100 100 60 9 9 42 42 57 13 24 6 72 72 72 72 72 72 12 12 78 5 5 5 20 20 20 53 68 68 90 24 6 83 83 83 83 83 83 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21 16 16 27 38 49 49 64 75 86 97 79 79 90 101 6 94 94 105 10 21 21 32 32 43 54 65 65 80 11 106 95 22 22 33 44 55 55 70 1 96 85 85 32 32 43 54 76 76 91 11 106 84 84 4 99 66 66 66 81 1 96 74 74 14 14 3 98 87 87 102 11 73 73 73 4 99 88 77 77 92 92 63 63 63 25 25 3 98 87 87 7 29 62 62 62 15 99 88 77 77 103 19 30 52 52 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41 36 36 47 58 69 69 18 29 40 51 51 26 37 48 59 59 8 19 30 41 41 </pre></section> </div> </span>
p03747
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a circle with a circumference of <var>L</var>. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are <var>N</var> ants. These ants are numbered <var>1</var> through <var>N</var> in order of increasing coordinate, and ant <var>i</var> is at coordinate <var>X_i</var>.</p> <p>The <var>N</var> ants have just started walking. For each ant <var>i</var>, you are given the initial direction <var>W_i</var>. Ant <var>i</var> is initially walking clockwise if <var>W_i</var> is <var>1</var>; counterclockwise if <var>W_i</var> is <var>2</var>. Every ant walks at a constant speed of <var>1</var> per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction.</p> <p>For each ant, find its position after <var>T</var> seconds.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq L \leq 10^9</var></li> <li><var>1 \leq T \leq 10^9</var></li> <li><var>0 \leq X_1 &lt; X_2 &lt; ... &lt; X_N \leq L - 1</var></li> <li><var>1 \leq W_i \leq 2</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>L</var> <var>T</var> <var>X_1</var> <var>W_1</var> <var>X_2</var> <var>W_2</var> <var>:</var> <var>X_N</var> <var>W_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain the coordinate of ant <var>i</var> after <var>T</var> seconds. Here, each coordinate must be between <var>0</var> and <var>L-1</var>, inclusive.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 8 3 0 1 3 2 6 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 3 0 </pre> <p><var>1.5</var> seconds after the ants start walking, ant <var>1</var> and <var>2</var> bump into each other at coordinate <var>1.5</var>. <var>1</var> second after that, ant <var>1</var> and <var>3</var> bump into each other at coordinate <var>0.5</var>. <var>0.5</var> seconds after that, that is, <var>3</var> seconds after the ants start walking, ants <var>1</var>, <var>2</var> and <var>3</var> are at coordinates <var>1</var>, <var>3</var> and <var>0</var>, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 20 9 7 2 9 1 12 1 18 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 18 18 1 </pre></section> </div> </span>
p01280
<H1><font color="#000">Problem H:</font> Galaxy Wide Web Service</H1> <p> The volume of access to a web service varies from time to time in a day. Also, the hours with the highest volume of access varies from service to service. For example, a service popular in the United States may receive more access in the daytime in the United States, while another service popular in Japan may receive more access in the daytime in Japan. When you develop a web service, you have to design the system so it can handle all requests made during the busiest hours. </p> <p> You are a lead engineer in charge of a web service in the 30th century. It’s the era of Galaxy Wide Web (GWW), thanks to the invention of faster-than-light communication. The service can be accessed from all over the galaxy. Thus many intelligent creatures, not limited to human beings, can use the service. Since the volume of access to your service is increasing these days, you have decided to reinforce the server system. You want to design a new system that handles requests well even during the hours with the highest volume of access. However, this is not a trivial task. Residents in each planet have their specific length of <i>a day</i>, say, a cycle of life. The length of <i>a day</i> is not always 24 hours. Therefore, a cycle of the volume of access are different by planets of users. </p> <p> You have obtained hourly data of the volume of access for all planets where you provide the service. Assuming the volume of access follows a daily cycle for each planet, you want to know the highest volume of access in one hour. It should be a quite easy task for you, a famous talented engineer in the galaxy. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> <i>N</i><br> <i>d</i><sub>1</sub> <i>t</i><sub>1</sub> <i>q</i><sub>1,0</sub> ... <i>q</i><sub>1,<i>d</i><sub>1</sub>-1</sub><br> ...<br> <i>d</i><sub><i>N</i></sub> <i>t</i><sub><i>N</i></sub> <i>q</i><sub><i>N</i>,0</sub> ... <i>q</i><sub><i>N</i>,<i>d</i><sub><i>N</i></sub>-1</sub><br> </p> <p> <i>N</i> is the number of planets. <i>d<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>N</i>) is the length of a day in the planet <i>i</i>. <!-- added at 2013/01/13 --> <i>t<sub>i</sub></i> (0 &le; <i>t<sub>i</sub></i> &le; <i>d<sub>i</sub></i> - 1) is the current time of the planet <i>i</i>. <i>q<sub>i, j</sub></i> is the volume of access on the planet <i>i</i> during from the <i>j</i>-th hour to the (<i>j</i>+1)-th hour. </p> <p> You may assume that <i>N</i> &le; 100, <i>d<sub>i</sub></i> &le; 24, <i>q<sub>i, j</sub></i> &le; 1000000 (1 &le; <i>i</i> &le; <i>N</i>, 0 &le; <i>j</i> &le; <i>d<sub>i</sub></i> - 1). </p> <p> The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, output the maximum volume of access in one hour in a line. </p> <H2>Sample Input</H2> <pre> 2 4 0 1 2 3 4 2 0 2 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 </pre>
p03317
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a sequence of length <var>N</var>: <var>A_1, A_2, ..., A_N</var>. Initially, this sequence is a permutation of <var>1, 2, ..., N</var>.</p> <p>On this sequence, Snuke can perform the following operation:</p> <ul> <li>Choose <var>K</var> consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.</li> </ul> <p>Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times. Find the minimum number of operations required. It can be proved that, Under the constraints of this problem, this objective is always achievable.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq K \leq N \leq 100000</var></li> <li><var>A_1, A_2, ..., A_N</var> is a permutation of <var>1, 2, ..., N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 2 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>One optimal strategy is as follows:</p> <ul> <li> <p>In the first operation, choose the first, second and third elements. The sequence <var>A</var> becomes <var>1, 1, 1, 4</var>.</p> </li> <li> <p>In the second operation, choose the second, third and fourth elements. The sequence <var>A</var> becomes <var>1, 1, 1, 1</var>.</p> </li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 2 3 </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>8 3 7 3 1 8 4 6 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p02910
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Takahashi will do a tap dance. The dance is described by a string <var>S</var> where each character is <code>L</code>, <code>R</code>, <code>U</code>, or <code>D</code>. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.</p> <p><var>S</var> is said to be <em>easily playable</em> if and only if it satisfies both of the following conditions:</p> <ul> <li>Every character in an odd position (<var>1</var>-st, <var>3</var>-rd, <var>5</var>-th, <var>\ldots</var>) is <code>R</code>, <code>U</code>, or <code>D</code>.</li> <li>Every character in an even position (<var>2</var>-nd, <var>4</var>-th, <var>6</var>-th, <var>\ldots</var>) is <code>L</code>, <code>U</code>, or <code>D</code>.</li> </ul> <p>Your task is to print <code>Yes</code> if <var>S</var> is easily playable, and <code>No</code> otherwise.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>S</var> is a string of length between <var>1</var> and <var>100</var> (inclusive).</li> <li>Each character of <var>S</var> is <code>L</code>, <code>R</code>, <code>U</code>, or <code>D</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print <code>Yes</code> if <var>S</var> is easily playable, and <code>No</code> otherwise.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>RUDLUDR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>Every character in an odd position (<var>1</var>-st, <var>3</var>-rd, <var>5</var>-th, <var>7</var>-th) is <code>R</code>, <code>U</code>, or <code>D</code>.</p> <p>Every character in an even position (<var>2</var>-nd, <var>4</var>-th, <var>6</var>-th) is <code>L</code>, <code>U</code>, or <code>D</code>.</p> <p>Thus, <var>S</var> is easily playable.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>DULL </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>The <var>3</var>-rd character is not <code>R</code>, <code>U</code>, nor <code>D</code>, so <var>S</var> is not easily playable.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>UUUUUUUUUUUUUUU </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>ULURU </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>RDULULDURURLRDULRLR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>Yes </pre></section> </div> </span>
p03602
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In Takahashi Kingdom, which once existed, there are <var>N</var> cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network:</p> <ul> <li>People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.</li> <li>Different roads may have had different lengths, but all the lengths were positive integers.</li> </ul> <p>Snuke the archeologist found a table with <var>N</var> rows and <var>N</var> columns, <var>A</var>, in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom.</p> <p>Determine whether there exists a road network such that for each <var>u</var> and <var>v</var>, the integer <var>A_{u, v}</var> at the <var>u</var>-th row and <var>v</var>-th column of <var>A</var> is equal to the length of the shortest path from City <var>u</var> to City <var>v</var>. If such a network exist, find the shortest possible total length of the roads.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300</var></li> <li>If <var>i ≠ j</var>, <var>1 \leq A_{i, j} = A_{j, i} \leq 10^9</var>.</li> <li><var>A_{i, i} = 0</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_{1, 1}</var> <var>A_{1, 2}</var> <var>...</var> <var>A_{1, N}</var> <var>A_{2, 1}</var> <var>A_{2, 2}</var> <var>...</var> <var>A_{2, N}</var> <var>...</var> <var>A_{N, 1}</var> <var>A_{N, 2}</var> <var>...</var> <var>A_{N, N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>If there exists no network that satisfies the condition, print <code>-1</code>. If it exists, print the shortest possible total length of the roads.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 1 3 1 0 2 3 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The network below satisfies the condition:</p> <ul> <li>City <var>1</var> and City <var>2</var> is connected by a road of length <var>1</var>.</li> <li>City <var>2</var> and City <var>3</var> is connected by a road of length <var>2</var>.</li> <li>City <var>3</var> and City <var>1</var> is not connected by a road.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 1 3 1 0 1 3 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>As there is a path of length <var>1</var> from City <var>1</var> to City <var>2</var> and City <var>2</var> to City <var>3</var>, there is a path of length <var>2</var> from City <var>1</var> to City <var>3</var>. However, according to the table, the shortest distance between City <var>1</var> and City <var>3</var> must be <var>3</var>.</p> <p>Thus, we conclude that there exists no network that satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 0 21 18 11 28 21 0 13 10 26 18 13 0 23 13 11 10 23 0 17 28 26 13 17 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>82 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>3 0 1000000000 1000000000 1000000000 0 1000000000 1000000000 1000000000 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3000000000 </pre></section> </div> </span>
p00887
<H1><font color="#000">Problem D:</font> Awkward Lights</H1> <p> You are working as a night watchman in an office building. Your task is to check whether all the lights in the building are turned off after all the office workers in the building have left the office. If there are lights that are turned on, you must turn off those lights. This task is not as easy as it sounds to be because of the strange behavior of the lighting system of the building as described below. Although an electrical engineer checked the lighting system carefully, he could not determine the cause of this behavior. So you have no option but to continue to rely on this system for the time being. </p> <p> Each floor in the building consists of a grid of square rooms. Every room is equipped with one light and one toggle switch. A toggle switch has two positions but they do not mean fixed ON/OFF. When the position of the toggle switch of a room is changed to the other position, in addition to that room, the ON/OFF states of the lights of the rooms at a certain Manhattan distance from that room are reversed. The Manhattan distance between the room at (<i>x</i><sub>1</sub>, <i>y</i><sub>1</sub>) of a grid of rooms and the room at (<i>x</i><sub>2</sub>, <i>y</i><sub>2</sub>) is given by |<i>x</i><sub>1</sub> - <i>x</i><sub>2</sub>| + |<i>y</i><sub>1</sub> - <i>y</i><sub>2</sub>|. For example, if the position of the toggle switch of the room at (2, 2) of a 4 &times; 4 grid of rooms is changed and the given Manhattan distance is two, the ON/OFF states of the lights of the rooms at (1, 1), (1, 3), (2, 4), (3, 1), (3, 3), and (4, 2) as well as at (2, 2) are reversed as shown in Figure D.1, where black and white squares represent the ON/OFF states of the lights. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_awkwardLights"> <p> Figure D.1: An example behavior of the lighting system </p> </center> <p> Your mission is to write a program that answer whether all the lights on a floor can be turned off. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is formatted as follows. </p> <p> <i>m n d</i><br> <i>S</i><sub>11</sub> <i>S</i><sub>12</sub> <i>S</i><sub>13</sub> ... <i>S</i><sub>1<i>m</i></sub><br> <i>S</i><sub>21</sub> <i>S</i><sub>22</sub> <i>S</i><sub>23</sub> ... <i>S</i><sub>2<i>m</i></sub><br> ...<br> <i>S</i><sub><i>n</i>1</sub> <i>S</i><sub><i>n</i>2</sub> <i>S</i><sub><i>n</i>3</sub> ... <i>S</i><sub><i>nm</i></sub><br> </p> <p> The first line of a dataset contains three integers. <i>m</i> and <i>n</i> (1 &le; <i>m</i> &le; 25, 1 &le; <i>n</i> &le; 25) are the numbers of columns and rows of the grid, respectively. <i>d</i> (1 &le; <i>d</i> &le; <i>m</i> + <i>n</i>) indicates the Manhattan distance. Subsequent n lines of m integers are the initial ON/OFF states. Each <i>S<sub>ij</sub></i> (1 &le; <i>i</i> &le; <i>n</i>, 1 &le; <i>j</i> &le; <i>m</i>) indicates the initial ON/OFF state of the light of the room at (<i>i</i>, <i>j</i>): '0' for OFF and '1' for ON. </p> <p> The end of the input is indicated by a line containing three zeros. </p> <H2>Output</H2> <p> For each dataset, output '1' if all the lights can be turned off. If not, output '0'. In either case, print it in one line for each input dataset. </p> <H2>Sample Input</H2> <pre> 1 1 1 1 2 2 1 1 1 1 1 3 2 1 1 0 1 0 1 0 3 3 1 1 0 1 0 1 0 1 0 1 4 4 2 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 5 5 1 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 5 5 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 11 11 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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 11 11 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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 13 13 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 1 0 1 0 0 1 1 0 1 </pre>
p01795
<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 F ICPC Teams</h2> <p> You are a coach of the International Collegiate Programming Contest (ICPC) club in your university. There are 3N students in the ICPC club and you want to make $N$ teams for the next ICPC. All teams in ICPC consist of 3 members. Every student belongs to exactly one team. </p> <p> When you form the teams, you should consider several relationships among the students. Some student has an extremely good relationship with other students. If they belong to a same team, their performance will improve surprisingly. The contrary situation also occurs for a student pair with a bad relationship. In short, students with a good relationship must be in the same team, and students with a bad relationship must be in different teams. Since you are a competent coach, you know all $M$ relationships among the students. </p> <p> Your task is to write a program that calculates the number of possible team assignments. Two assignments are considered different if and only if there exists a pair of students such that in one assignment they are in the same team and in the other they are not. </p> <h3>Input</h3> <p> The input consists of a single test case. The first line contains two integers $N$ $(1 \leq N \leq 10^6)$ and $M$ $(1 \leq M \leq 18)$. The $i$-th line of the following $M$ lines contains three integers $A_i$, $B_i$ $(1 \leq A_i, B_i \leq 3N, A_i \ne B_i)$, and $C_i$ $(C_i \in \{0, 1\})$. $A_i$ and $B_i$ denote indices of the students and $C_i$ denotes the relation type. If $C_i$ is 0, the $A_i$-th student and the $B_i$-th student have a good relation. If $C_i$ is 1, they have a bad relation. You can assume that $\{A_i, B_i\} \ne \{A_j, B_j\}$ if $i \ne j$ for all $1 \leq i, j \leq M$. </p> <h3>Output</h3> <p> Display a line containing the number of the possible team assignments modulo $10^9 + 9$. </p> <h3>Sample Input 1</h3> <pre>2 2 1 2 0 3 4 1</pre> <h3>Output for the Sample Input 1</h3> <pre>2</pre>
p03252
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given strings <var>S</var> and <var>T</var> consisting of lowercase English letters.</p> <p>You can perform the following operation on <var>S</var> any number of times:</p> <p>Operation: Choose two distinct lowercase English letters <var>c_1</var> and <var>c_2</var>, then replace every occurrence of <var>c_1</var> with <var>c_2</var>, and every occurrence of <var>c_2</var> with <var>c_1</var>.</p> <p>Determine if <var>S</var> and <var>T</var> can be made equal by performing the operation zero or more times.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 2 \times 10^5</var></li> <li><var>|S| = |T|</var></li> <li><var>S</var> and <var>T</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If <var>S</var> and <var>T</var> can be made equal, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>azzel apple </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p><code>azzel</code> can be changed to <code>apple</code>, as follows:</p> <ul> <li>Choose <code>e</code> as <var>c_1</var> and <code>l</code> as <var>c_2</var>. <code>azzel</code> becomes <code>azzle</code>.</li> <li>Choose <code>z</code> as <var>c_1</var> and <code>p</code> as <var>c_2</var>. <code>azzle</code> becomes <code>apple</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>chokudai redcoder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>No sequences of operation can change <code>chokudai</code> to <code>redcoder</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>abcdefghijklmnopqrstuvwxyz ibyhqfrekavclxjstdwgpzmonu </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
p02013
<h1>Problem J. Prime Routing</h1> <!-- Time Limit: 2 sec Memory Limit: 512 MB --> <p> Fox Jiro is one of the staffs of the ACM-ICPC 2018 Asia Yokohama Regional Contest and is responsible for designing the network for the venue of the contest. His network consists of $N$ computers, which are connected by $M$ cables. The $i$-th cable connects the $a_i$-th computer and the $b_i$-th computer, and it carries data in both directions. Your team will use the $S$-th computer in the contest, and a judge server is the $T$-th computer. </p> <p> He decided to adjust the routing algorithm of the network to maximize the performance of the contestants through the magical power of prime numbers. In this algorithm, a packet (a unit of data carried by the network) is sent from your computer to the judge server passing through the cables a prime number of times if possible. If it is impossible, the contestants cannot benefit by the magical power of prime numbers. To accomplish this target, a packet is allowed to pass through the same cable multiple times. </p> <p> You decided to write a program to calculate the minimum number of times a packet from $S$ to $T$ needed to pass through the cables. If the number of times a packet passes through the cables cannot be a prime number, print $-1$. </p> <h2>Input</h2> <p> The input consists of a single test case, formatted as follows. </p> <pre> $N$ $M$ $S$ $T$ $a_1$ $b_1$ $\vdots$ $a_M$ $b_M$ </pre> <p> The first line consists of four integers $N, M, S,$ and $T$ ($2 \leq N \leq 10^5, 1 \leq M \leq 10^5, 1 \leq S, T \leq N, S \ne T$). The $i$-th line of the following $M$ lines consists of two integers $a_i$ and $b_i$ ($1 \leq a_i < b_i \leq N$), which means the $i$-th cables connects the $a_i$-th computer and the $b_i$-th computer in the network. You can assume that the network satisfies the following conditions. </p> <ul> <li>The network has no multi-edge, i.e.,$(a_i, b_i) \ne (a_j, b_j)$ for all $i,j$ ($1 \leq i < j \leq M$).</li> <li>The packets from $N$ computers are reachable to $T$ by passing through some number of cables. The number is not necessarily a prime.</li> </ul> <h2>Output</h2> <p> If there are ways such that the number of times a packet sent from $S$ to $T$ passes through the cables is a prime number, print the minimum prime number of times in one line. Otherwise, print $-1$. </p> <h2>Examples</h2> <h2>Sample Input 1</h2> <pre> 5 5 1 5 1 2 1 4 2 3 3 4 3 5 </pre> <h2>Output for Sample Input 1</h2> <pre> 3 </pre> <h2>Sample Input 2</h2> <pre> 5 4 1 5 1 2 2 3 3 4 4 5 </pre> <h2>Output for Sample Input 2</h2> <pre> -1 </pre> <h2>Sample Input 3</h2> <pre> 2 1 1 2 1 2 </pre> <h2>Output for Sample Input 3</h2> <pre> 3 </pre> <h2>Sample Input 4</h2> <pre> 3 3 1 2 1 2 1 3 2 3 </pre> <h2>Output for Sample Input 4</h2> <pre> 2 </pre>
p00184
<H1>鶎ヶ城</H1> <p> 䌚接若束垂のシンボルである鶎ヶ城は、蒲生氏郷が本栌的な倩守閣を築城し、「鶎ヶ城」ず名付けたした。倩守閣からは䌚接盆地が䞀望できたす。たた、晎れた日には、癜虎隊で有名な飯盛山の山頂から鶎ヶ城を芋るこずができたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_tsuruga"><br/> <br/> </center> <p> 䌚接若束垂の今埌の広報掻動の参考にするため、鶎ヶ城に蚪れた来堎者に぀いお、幎代調査をするこずにしたした。来堎者の幎霢を入力ずし、䞋蚘の幎霢区分別に人数を出力するプログラムを䜜成しおください。 </p> <center> <table> <tr><th width="100"> 区分</th><th width="100"> 幎霢</th></tr> <tr><td>10歳未満</td><td> 0 ~ 9</td></tr> <tr><td> 10代</td><td> 10 ~ 19</td></tr> <tr><td> 20代</td><td> 20 ~ 29</td></tr> <tr><td> 30代</td><td> 30 ~ 39</td></tr> <tr><td> 40代 </td><td> 40 ~ 49</td></tr> <tr><td> 50代</td><td> 50 ~ 59</td></tr> <tr><td>60歳以䞊</td><td> 60 ~</td></tr> </table> </center> <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> 1 行目に来堎者の人数 <var>n</var> (1 &le; <var>n</var> &le; 1000000)、続く <var>n</var> 行に <var>i</var> 人目の来堎者の幎霢 <var>a<sub>i</sub></var> ( 0 &le; <var>a<sub>i</sub></var> &le; 120 ) が䞎えられたす。 </p> <H2>Output</H2> <p> デヌタセット毎に以䞋の圢匏で人数を出力したす。<br/> <br/> 1 行目: 10 歳未満の人数<br/> 2 行目: 10 代の人数<br/> 3 行目: 20 代の人数<br/> 4 行目: 30 代の人数<br/> 5 行目: 40 代の人数<br/> 6 行目: 50 代の人数<br/> 7 行目: 60 歳以䞊の人数<br/> </pre> <H2>Sample Input</H2> <pre> 8 71 34 65 11 41 39 6 5 4 67 81 78 65 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 1 0 2 1 0 2 0 0 0 0 0 0 4 </pre>
p02443
<h1>Reverse</h1> <p> Write a program which reads a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ and reverse specified elements by a list of the following operation: </p> <ul> <li>reverse($b, e$): reverse the order of $a_b, a_{b+1}, ..., a_{e-1}$</li> </ul> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1 \; ...,\; a_{n-1}$ $q$ $b_1 \; e_1$ $b_2 \; e_2$ : $b_{q} \; b_{q}$ </pre> <p> In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by two integers $b_i \; e_i$ in the following $q$ lines. </p> <h2>Output</h2> <p> Print all elements of $A$ in a line after performing the given operations. Put a single space character between adjacency elements and a newline at the end of the last element. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 1,000$</li> <li>$-1,000,000,000 \leq a_i \leq 1,000,000,000$</li> <li>$1 \leq q \leq 1,000$</li> <li>$0 \leq b < e \leq n$</li> </ul> <h2>Sample Input 1</h2> <pre> 8 1 2 3 4 5 6 7 8 2 1 6 3 8 </pre> <h2>Sample Output 1</h2> <pre> 1 6 5 8 7 2 3 4 </pre>
p02434
<h1>Vector II</h1> <p> For $n$ dynamic arrays $A_i$ ($i = 0, 1, ..., n-1$), perform a sequence of the following operations: </p> <ul> <li>pushBack($t$, $x$): Add element $x$ at the end of $A_t$.</li> <li>dump($t$): Print all elements in $A_t$.</li> <li>clear($t$): Clear $A_t$. If $A_t$ is empty, do nothing.</li> </ul> <p> $A_i$ is a 0-origin array and it is empty in the initial state. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $q$ $query_1$ $query_2$ : $query_q$ </pre> <p> Each query $query_i$ is given by </p> <pre> 0 $t$ $x$ </pre> <p>or</p> <pre> 1 $t$ </pre> <p>or</p> <pre> 2 $t$ </pre> <p> where the first digits <span>0</span>, <span>1</span> and <span>2</span> represent pushBack, dump and clear operations respectively. </p> <h2>Output</h2> <p> For each dump operation, print elements of $A_t$ a line. Separete adjacency elements by a space character (do not print the space after the last element). Note that, if the array is empty, an empty line should be printed. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 1,000$</li> <li>$1 \leq q \leq 500,000$</li> <li>$-1,000,000,000 \leq x \leq 1,000,000,000$</li> <li>The total number of elements printed by dump operations do not exceed 500,000</li> </ul> <h2>Sample Input 1</h2> <pre> 3 13 0 0 1 0 0 2 0 0 3 0 1 -1 0 2 4 0 2 5 1 0 1 1 1 2 2 1 1 0 1 1 1 2 </pre> <h2>Sample Output 1</h2> <pre> 1 2 3 -1 4 5 1 2 3 4 5 </pre>
p00409
<h1>むワシロの祈り</h1>  <p> 叀代囜家むワシロでは、灜害が起きたずきにそれを鎮めるために、神官が祈りをささげたす。 </p> <p> 神官は叀文曞から文字列Sを遞び、以䞋を繰り返すこずで儀匏を進めおいきたす。 </p> <ul> <li>文字列$S$の䞭の堎所を䞀぀遞び、そこに曞かれた文字を他の文字に入れ替えお、$S$を曎新する。</li> <li>$S$がどのような文字列の繰り返しで衚せるかを芋぀けお、芋぀けた文字列を唱える。ただし、$S$が文字列の繰り返しで衚せないずきは$S$を唱える。 </li> </ul> <p> 祈りの効力が最倧になるのは、最も短い文字列の繰り返しで元の文字列を衚すものを唱えたずきです。たずえば、ababababずいう文字列に察しお、この文字列そのものやababではなく、abず唱えたずきに祈りの効力が最倧になりたす。 </p> <p> 新米神官のあなたは、䞎えられた文字列$S$から祈りの効力を最倧にする文字列を玠早く芋぀ける方法を䌚埗しなければなりたせん。 </p> </p> 文字列$S$ず文字の入れ替えの情報がいく぀か䞎えられる。文字を入れ替えるたびに、埗られた文字列に぀いお祈りの効力を最倧にする文字列の長さを求めるプログラムを䜜成せよ。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> $N$ $Q$ $S$ $p_1$ $c_1$ $p_2$ $c_2$ : $p_Q$ $c_Q$ </pre> <p> 行目に文字列の長さ$N$ ($2 \leq N \leq 10^5$)ず文字を入れ替える回数$Q$ ($1 \leq Q \leq 10^5$)が䞎えられる。行目に英小文字からなる長さ$N$の文字列$S$が䞎えられる。続く$Q$行に、$i$番目に入れ替える文字の䜍眮$p_i$ ($1 \leq p_i \leq N$)ず入れ替えた埌の文字$c_i$が䞎えられる。ただし、$p_i$は文字列の巊端から数えお䜕番目かで衚される。たた、$c_i$は英小文字である。 </p> <h2>出力</h2> <p> 文字を入れ替えるたびに、埗られる文字列に぀いお祈りの効力を最倧にする文字列の長さを行に出力する。 </p> <h2>入出力䟋</h2> <h3>入力䟋</h3> <pre> 6 5 ababac 6 b 3 c 4 a 5 b 6 c </pre> <h3>出力䟋</h3> <pre> 2 6 6 6 3 </pre>
p02064
<h2>E: 最短経路の埩元</h2> <h3>物語</h3> <p>競技プログラマヌは日々最短経路問題を解いおいる。BFS や、ベルマンフォヌド、ダむクストラ、ワヌシャルフロむドず倚くのアルゎリズムも知られおいる。</p> <p>あなたはそんな䞭、どうしおも解けない最短路問題があった。それはグラフを芋ずに最短路問題を解けずいう問題だこんなもの通垞の人類には解けるわけがないのだが、30 分だけ ivvivvi 神の倩啓を受けるこずができるようになった。</p> <p>ivvivvi 神は競技プログラミングにも最短経路問題にも粟通しおおり、どんなグラフに察しおも任意の 2 点間の最短経路長を定数時間で求める胜力を持っおいる。あなたは ivvivvi 神の力を借りお最短経路問題を解こうず思ったが、残念ながらあなたの解くべき最短経路問題では具䜓的な経路を出力しなければならない。ivvivvi 神なら、最短経路の埩元も容易だが、ivvivvi 神は非垞に忙しいので、これ以䞊手を煩わせるわけには行けない。そこで、できるだけ少ない質問回数で自力で最短経路を埩元するこずにした。</p> <h3>問題</h3> <p><var>3</var> ぀の敎数 <var>N</var>、 <var>s</var>、そしお、<var>t</var> が䞎えられる。このずき、頂点数 <var>N</var> のグラフがあり、頂点数以倖の蟺数や頂点の隣接関係などのグラフに関する情報は䞎えられないが、<var>2</var> 頂点 <var>u</var>、<var>v</var> の距離を質問するこずができる。ここで、グラフの頂点番号は <var>1</var> 以䞊 <var>N</var> 以䞋である。<var>5N</var> 回以䞋の質問回数で <var>s</var> から <var>t</var> ぞの最短路を発芋し、最短路を衚す頂点列を <var>1</var> ぀出力せよ。</p> <p> <b>この問題では <var>2</var> 頂点 <var>u</var>、<var>v</var> 間の距離をゞャッゞに質問しなければならない。</b> 暙準出力に次のように出力するこずで、<var>u</var>、<var>v</var> 間の距離を質問するこずができる。 </p> <pre>? <var>u</var> <var>v</var></pre> <p> このように暙準出力したあず、この答えは暙準入力に <var>1</var> 行の敎数ずしお䞎えられる。 この問題ではプログラムの行った質問の回数が <var>5N</var> 回を超えるず誀答WAず刀定される。この問題では最埌に頂点列、぀たり敎数列を出力する。頂点列 <var>(x_1, ..., x_k)</var> を出力する出力圢匏は次のようである。 </p> <pre>! <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_k</var></pre> <p> ここで、出力は <var>x_1 = s</var> 、 <var>x_k = t</var> を満たし、任意の<var>1 \leq i \leq k - 1</var> に察しお、<var>x_i</var> ず <var>x_{i + 1}</var> を盎接結ぶ蟺が存圚する。 さらに、この最終的な解答は、䞀床しか行うこずができない。この解答が正しい出力だったずき、正答ずみなす。さらに、暙準出力ずしお䞊蚘の <var>2</var> ぀の蚘法ず異なる出力や質問回数が <var>5N</var> 回を超えた時はゞャッゞは <var>-1</var> を返す。この時、即座にプログラムを終了させない堎合、ゞャッゞが WA を正しく刀定するこずを保蚌しない。 </p> <p>たた、暙準出力を行う毎に、ストリヌムをフラッシュ (flush) する必芁があるこずに泚意されよ。䞻芁な蚀語でのフラッシュ䟋を以䞋に瀺す。もちろん、これ以倖の方法でフラッシュを行っおも構わない。</p> <p>C 蚀語:</p> <pre> #include &lt;stdio.h&gt; fflush(stdout); </pre> <p>C++:</p> <pre> #include &lt;iostream&gt; std::cout.flush(); </pre> <p>Java:</p> <pre>System.out.flush();</pre> <p>Python:</p> <pre>print(end='', flush=True)</pre> <h3>入力圢匏</h3> <p>入力ずしお敎数 <var>3</var> ぀が䞎えられる。</p> <pre><var>N</var> <var>s</var> <var>t</var></pre> <h3>制玄</h3> <ul> <li><var>2 \leq N \leq 300</var></li> <li><var>1 \leq s, t \leq N</var></li> <li><var>s \neq t</var></li> <li>問題においお䜿甚されるグラフ䞊の任意の 2 頂点 <var>u</var>, <var>v</var> に぀いお、最短距離を求めたものの最倧倀は <var>10^9</var> 以䞋である</li> <li>問題においお䜿甚されるグラフは連結であるこずが保蚌される</li> </ul> <h3>入出力䟋</h3> <p> <table width="600" class="withborder"><tbody> <tr><th>暙準入力</th><th>暙準出力</th></tr> <tr><td>4 1 3</td><td> </td></tr> <tr><td> </td><td>? 4 3</td></tr> <tr><td>3</td><td> </td></tr> <tr><td> </td><td>? 1 4</td></tr> <tr><td>2</td><td> </td></tr> <tr><td> </td><td>? 2 1</td></tr> <tr><td>1</td><td> </td></tr> <tr><td> </td><td>? 3 2</td></tr> <tr><td>2</td><td> </td></tr> <tr><td> </td><td>? 1 3</td></tr> <tr><td>3</td><td> </td></tr> <tr><td> </td><td>? 4 2</td></tr> <tr><td>1</td><td> </td></tr> <tr><td> </td><td>! 1 2 3</td></tr> </tbody></table> </p> <p>この入出力䟋では以䞋のグラフに察しお 2 点間の距離を質問しおいる。</p> <!--<object data="images/exam.png" type="image/png" width="400"></object>--> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_HUPC2019Day1_E_exam" width="400"/>
p00059
<H1>長方圢の重なり</H1> <p> 底蟺が <var>x</var> 軞に察しお平行な 2 ぀の長方圢がありたす。長方圢 A の巊䞋の座暙 (<var>xa1</var>, <var>ya1</var>) ず右䞊の座暙 (<var>xa2</var>, <var>ya2</var>)、長方圢 B の巊䞋の座暙 (<var>xb1</var>, <var>yb1</var>) ず右䞊の座暙 (<var>xb2</var>, <var>yb2</var>) を読み蟌んで、長方圢 A ず長方圢 B が䞀郚でも重なっおいれば YES を、たったく重なっおいなければ NO を出力するプログラムを䜜成しおください。ただし、長方圢 A ず長方圢 B は同じものではないずしたす。たた、接しおいるものも重なっおいるずみなしたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_intersection"> </center> <br/> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットの圢匏は以䞋のずおりです。 </p> <pre> <var>xa1</var> <var>ya1</var> <var>xa2</var> <var>ya2</var> <var>xb1</var> <var>yb1</var> <var>xb2</var> <var>yb2</var> </pre> <p> 入力される倀はそれぞれ -2,000 以䞊 2,000 以䞋であり、各倀は小数点以䞋最倧 5 桁たでの数字を含む実数で䞎えられたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットに察しお、<span>YES</span> たたは <span>NO</span> を行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 0.0 0.0 5.0 5.0 1.0 1.0 4.0 4.0 0.0 0.0 4.0 5.0 1.0 1.0 5.0 5.0 0.0 0.0 4.0 4.0 -3.0 -5.0 2.0 -1.0 </pre> <H2>Output for the Sample Input</H2> <pre> YES YES NO </pre>
p01218
<H1><font color="#000">Problem C:</font> Nagashi Soumen</H1> <p> Mr. Natsume, the captain of a baseball club, decided to hold a <i>nagashi-soumen</i> party. He first planned to put a flume at the arena, and let members stand by the side of the flume to eat soumen. But they are so weird that they adhere to each special position, and refused to move to the side of the flume. They requested Mr. Natsume to have the flumes go through their special positions. As they never changed their minds easily, Mr. Natsume tried to rearrange flumes in order to fulfill their requests. </p> <p> As a caretaker of the baseball club, you are to help Mr. Natsume arrange the flumes. Here are the rules on the arrangement: </p> <ul> <li> each flume can begin and end at arbitrary points. Also it can be curved at any point in any direction, but cannot have any branches nor merge with another flume;</li> <li> each flume needs to be placed so that its height strictly decreases as it goes, otherwise soumen does not flow;</li> <li> Mr. Natsume cannot make more than <i>K</i> flumes since he has only K machines for water-sliders; and</li> <li> needless to say, flumes must go through all the special positions so that every member can eat soumen.</li> </ul> <p> In addition, to save the cost, you want to arrange flumes so that the total length is as small as possible. What is the minimum total length of all flumes? </p> <H2>Input</H2> <p> Input consists of multiple data sets. Each data set follows the format below: </p> <pre> <i>N K</i> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>z</i><sub>1</sub> ... <i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub> <i>z</i><sub><i>N</i></sub> </pre> <p> <i>N</i> (1 &le; <i>N</i> &le; 100) represents the number of attendants, <i>K</i> (1 &le; <i>K</i> &le; 4) represents the number of available flumes, and <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> (-100 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i>, <i>z<sub>i</sub></i> &le; 100) represent the <i>i</i>-th attendant’s coordinates. All numbers are integers. The attendants’ coordinates are all different. </p> <p> A line with two zeros represents the end of input. </p> <H2>Output</H2> <p> For each data set, output in one line the minimum total length of all flumes in Euclidean distance. No absolute error in your answer may exceed 10<sup>-9</sup>. Output -1 if it is impossible to arrange flumes. </p> <H2>Sample Input</H2> <pre> 1 1 0 0 0 4 4 0 0 0 1 1 1 2 2 2 3 3 3 3 4 0 0 0 1 1 1 2 2 2 4 1 1 0 1 0 0 0 1 1 0 0 1 -1 5 2 0 0 100 0 0 99 1 0 99 1 0 98 1 0 -100 7 4 71 55 -77 -43 -49 50 73 -22 -89 32 99 -33 64 -22 -25 -76 -1 6 39 4 23 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 0 0 -1 200 197.671366737338417 </pre>
p03225
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are some coins in the <var>xy</var>-plane. The positions of the coins are represented by a grid of characters with <var>H</var> rows and <var>W</var> columns. If the character at the <var>i</var>-th row and <var>j</var>-th column, <var>s_{ij}</var>, is <code>#</code>, there is one coin at point <var>(i,j)</var>; if that character is <code>.</code>, there is no coin at point <var>(i,j)</var>. There are no other coins in the <var>xy</var>-plane.</p> <p>There is no coin at point <var>(x,y)</var> where <var>1\leq i\leq H,1\leq j\leq W</var> does not hold. There is also no coin at point <var>(x,y)</var> where <var>x</var> or <var>y</var> (or both) is not an integer. Additionally, two or more coins never exist at the same point.</p> <p>Find the number of triples of different coins that satisfy the following condition:</p> <ul> <li>Choosing any two of the three coins would result in the same Manhattan distance between the points where they exist.</li> </ul> <p>Here, the Manhattan distance between points <var>(x,y)</var> and <var>(x',y')</var> is <var>|x-x'|+|y-y'|</var>. Two triples are considered the same if the only difference between them is the order of the coins.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H,W \leq 300</var></li> <li><var>s_{ij}</var> is <code>#</code> or <code>.</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>s_{11}...s_{1W}</var> <var>:</var> <var>s_{H1}...s_{HW}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of triples that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 #.## .##. #... ..## ...# </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p><var>((1,1),(1,3),(2,2)),((1,1),(2,2),(3,1))</var> and <var>((1,3),(3,1),(4,4))</var> satisfy the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>13 27 ......#.........#.......#.. #############...#.....###.. ..............#####...##... ...#######......#...####### ...#.....#.....###...#...#. ...#######....#.#.#.#.###.# ..............#.#.#...#.#.. #############.#.#.#...###.. #...........#...#...####### #..#######..#...#...#.....# #..#.....#..#...#...#.###.# #..#######..#...#...#.#.#.# #..........##...#...#.##### </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>870 </pre></section> </div> </span>
p02967
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var> consisting of <code>A</code>,<code>B</code>, and <code>C</code>.</p> <p>Consider the (not necessarily contiguous) subsequences <var>x</var> of <var>S</var> that satisfy all of the following conditions:</p> <ul> <li><code>A</code>, <code>B</code>, and <code>C</code> all occur the same number of times in <var>x</var>.</li> <li>No two adjacent characters in <var>x</var> are the same.</li> </ul> <p>Among these subsequences, find one of the longest. Here a subsequence of <var>S</var> is a string obtained by deleting zero or more characters from <var>S</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 10^6</var></li> <li><var>S</var> consists of <code>A</code>,<code>B</code>, and <code>C</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print one longest subsequence that satisfies the conditions. If multiple solutions exist, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>ABBCBCAB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>ACBCAB </pre> <p>Consider the subsequence <code>ACBCAB</code> of <var>S</var>. It satisfies the conditions and is one of the longest with these properties, along with <code>ABCBCA</code>. On the other hand, the subsequences <code>ABCBCAB</code> and <code>ABBCCA</code> do not satisfy the conditions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>ABABABABACACACAC </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>BABCAC </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>ABCABACBCBABABACBCBCBCBCBCAB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>ACABACABABACBCBCBCBCA </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>AAA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre> </pre> <p>It is possible that only the empty string satisfies the condition.</p></section> </div> </span>
p01648
<h2>Problem Statement</h2> <p> You are given a connected undirected graph which has even numbers of nodes. A connected graph is a graph in which all nodes are connected directly or indirectly by edges. </p> <p> Your task is to find a spanning tree whose median value of edges' costs is minimum. A spanning tree of a graph means that a tree which contains all nodes of the graph. </p> <h2>Input</h2> <p> The input consists of multiple datasets. </p> <p> The format of each dataset is as follows. </p> <pre> <var>n</var> <var>m</var> <var>s_1</var> <var>t_1</var> <var>c_1</var> ... <var>s_m</var> <var>t_m</var> <var>c_m</var> </pre> <p> The first line contains an even number <var>n</var> (<var>2 \leq n \leq 1,000</var>) and an integer <var>m</var> <var>(n-1 \leq m \leq 10,000)</var>. <var>n</var> is the nubmer of nodes and <var>m</var> is the number of edges in the graph. </p> <p> Then <var>m</var> lines follow, each of which contains <var>s_i</var> (<var>1 \leq s_i \leq n</var>), <var>t_i</var> (<var>1 \leq s_i \leq n, t_i \neq s_i</var>) and <var>c_i</var> (<var>1 \leq c_i \leq 1,000</var>). This means there is an edge between the nodes <var>s_i</var> and <var>t_i</var> and its cost is <var>c_i</var>. There is no more than one edge which connects <var>s_i</var> and <var>t_i</var>. </p> <p> The input terminates when <var>n=0</var> and <var>m=0</var>. Your program must not output anything for this case. </p> <h2>Output</h2> <p> Print the median value in a line for each dataset. </p> <h2>Sample Input</h2> <pre> 2 1 1 2 5 4 6 1 2 1 1 3 2 1 4 3 2 3 4 2 4 5 3 4 6 8 17 1 4 767 3 1 609 8 3 426 6 5 972 8 1 607 6 4 51 5 1 683 3 6 451 3 4 630 8 7 912 3 7 43 4 7 421 3 5 582 8 4 538 5 7 832 1 6 345 8 2 608 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 5 2 421 </pre>
p03675
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer sequence of length <var>n</var>, <var>a_1, ..., a_n</var>. Let us consider performing the following <var>n</var> operations on an empty sequence <var>b</var>.</p> <p>The <var>i</var>-th operation is as follows:</p> <ol> <li>Append <var>a_i</var> to the end of <var>b</var>.</li> <li>Reverse the order of the elements in <var>b</var>.</li> </ol> <p>Find the sequence <var>b</var> obtained after these <var>n</var> operations.</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>0 \leq a_i \leq 10^9</var></li> <li><var>n</var> and <var>a_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>n</var> <var>a_1</var> <var>a_2</var> <var>...</var> <var>a_n</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>n</var> integers in a line with spaces in between. The <var>i</var>-th integer should be <var>b_i</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 2 1 3 </pre> <ul> <li>After step 1 of the first operation, <var>b</var> becomes: <var>1</var>.</li> <li>After step 2 of the first operation, <var>b</var> becomes: <var>1</var>.</li> <li>After step 1 of the second operation, <var>b</var> becomes: <var>1, 2</var>.</li> <li>After step 2 of the second operation, <var>b</var> becomes: <var>2, 1</var>.</li> <li>After step 1 of the third operation, <var>b</var> becomes: <var>2, 1, 3</var>.</li> <li>After step 2 of the third operation, <var>b</var> becomes: <var>3, 1, 2</var>.</li> <li>After step 1 of the fourth operation, <var>b</var> becomes: <var>3, 1, 2, 4</var>.</li> <li>After step 2 of the fourth operation, <var>b</var> becomes: <var>4, 2, 1, 3</var>.</li> </ul> <p>Thus, the answer is <code>4 2 1 3</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 1 2 </pre> <p>As shown above in Sample Output 1, <var>b</var> becomes <var>3, 1, 2</var> after step 2 of the third operation. Thus, the answer is <code>3 1 2</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 0 6 7 6 7 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 6 6 0 7 7 </pre></section> </div> </span>
p02988
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a permutation <var>p</var> = {<var>p_1,\ p_2,\ ...,\ p_n</var>} of {<var>1,\ 2,\ ...,\ n</var>}.</p> <p>Print the number of elements <var>p_i</var> (<var>1 &lt; i &lt; n</var>) that satisfy the following condition:</p> <ul> <li><var>p_i</var> is the second smallest number among the three numbers <var>p_{i - 1}</var>, <var>p_i</var>, and <var>p_{i + 1}</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>3 \leq n \leq 20</var></li> <li><var>p</var> is a permutation of {<var>1,\ 2,\ ...,\ n</var>}.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>n</var> <var>p_1</var> <var>p_2</var> <var>...</var> <var>p_n</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of elements <var>p_i</var> (<var>1 &lt; i &lt; n</var>) that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 3 5 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p><var>p_2 = 3</var> is the second smallest number among <var>p_1 = 1</var>, <var>p_2 = 3</var>, and <var>p_3 = 5</var>. Also, <var>p_4 = 4</var> is the second smallest number among <var>p_3 = 5</var>, <var>p_4 = 4</var>, and <var>p_5 = 2</var>. These two elements satisfy the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 9 6 3 2 5 8 7 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre></section> </div> </span>
p03360
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There are three positive integers <var>A</var>, <var>B</var> and <var>C</var> written on a blackboard. E869120 performs the following operation <var>K</var> times:</p> <ul> <li>Choose one integer written on the blackboard and let the chosen integer be <var>n</var>. Replace the chosen integer with <var>2n</var>.</li> </ul> <p>What is the largest possible sum of the integers written on the blackboard after <var>K</var> operations?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>A, B</var> and <var>C</var> are integers between <var>1</var> and <var>50</var> (inclusive).</li> <li><var>K</var> is an integer between <var>1</var> and <var>10</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the largest possible sum of the integers written on the blackboard after <var>K</var> operations by E869220.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 11 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>30 </pre> <p>In this sample, <var>5, 3, 11</var> are initially written on the blackboard, and E869120 can perform the operation once.<br/> There are three choices: </p> <ol> <li>Double <var>5</var>: The integers written on the board after the operation are <var>10, 3, 11</var>.</li> <li>Double <var>3</var>: The integers written on the board after the operation are <var>5, 6, 11</var>.</li> <li>Double <var>11</var>: The integers written on the board after the operation are <var>5, 3, 22</var>.</li> </ol> <p>If he chooses 3., the sum of the integers written on the board afterwards is <var>5 + 3 + 22 = 30</var>, which is the largest among 1. through 3. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>22 </pre> <p>E869120 can perform the operation twice. The sum of the integers eventually written on the blackboard is maximized as follows: </p> <ul> <li>First, double <var>4</var>. The integers written on the board are now <var>3, 3, 8</var>. </li> <li>Next, double <var>8</var>. The integers written on the board are now <var>3, 3, 16</var>. </li> </ul> <p>Then, the sum of the integers eventually written on the blackboard is <var>3 + 3 + 16 = 22</var>.</p></section> </div> </span>
p02822
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a tree <var>T</var> with <var>N</var> vertices. The <var>i</var>-th edge connects Vertex <var>A_i</var> and <var>B_i</var> (<var>1 \leq A_i,B_i \leq N</var>).</p> <p>Now, each vertex is painted black with probability <var>1/2</var> and white with probability <var>1/2</var>, which is chosen independently from other vertices. Then, let <var>S</var> be the smallest subtree (connected subgraph) of <var>T</var> containing all the vertices painted black. (If no vertex is painted black, <var>S</var> is the empty graph.)</p> <p>Let the <em>holeyness</em> of <var>S</var> be the number of white vertices contained in <var>S</var>. Find the expected holeyness of <var>S</var>.</p> <p>Since the answer is a rational number, we ask you to print it <var>\bmod 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).</p> <p>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 2 \times 10^5</var></li> <li><var>1 \leq A_i,B_i \leq N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>B_1</var> <var>:</var> <var>A_{N-1}</var> <var>B_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the expected holeyness of <var>S</var>, <var>\bmod 10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>125000001 </pre> <p>If the vertices <var>1, 2, 3</var> are painted black, white, black, respectively, the holeyness of <var>S</var> is <var>1</var>.</p> <p>Otherwise, the holeyness is <var>0</var>, so the expected holeyness is <var>1/8</var>.</p> <p>Since <var>8 \times 125000001 \equiv 1 \pmod{10^9+7}</var>, we should print <var>125000001</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 2 3 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>375000003 </pre> <p>The expected holeyness is <var>3/8</var>.</p> <p>Since <var>8 \times 375000003 \equiv 3 \pmod{10^9+7}</var>, we should print <var>375000003</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 2 1 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>250000002 </pre> <p>The expected holeyness is <var>1/4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>7 4 7 3 1 2 6 5 2 7 1 2 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>570312505 </pre></section> </div> </span>
p03730
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We ask you to select some number of positive integers, and calculate the sum of them.</p> <p>It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of <var>A</var>, and you need to select at least one integer.</p> <p>Your objective is to make the sum congruent to <var>C</var> modulo <var>B</var>. Determine whether this is possible.</p> <p>If the objective is achievable, print <code>YES</code>. Otherwise, print <code>NO</code>.</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>0 ≀ C &lt; B</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>Print <code>YES</code> or <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 5 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>For example, if you select <var>7</var> and <var>14</var>, the sum <var>21</var> is congruent to <var>1</var> modulo <var>5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p>The sum of even numbers, no matter how many, is never odd.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 100 97 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>YES </pre> <p>You can select <var>97</var>, since you may select multiples of <var>1</var>, that is, all integers.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>40 98 58 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>YES </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>77 42 36 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>NO </pre></section> </div> </span>
p02571
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are two strings <var>S</var> and <var>T</var>.</p> <p>Let us change some of the characters in <var>S</var> so that <var>T</var> will be a substring of <var>S</var>.</p> <p>At least how many characters do we need to change?</p> <p>Here, a substring is a consecutive subsequence. For example, <code>xxx</code> is a substring of <code>yxxxy</code>, but not a substring of <code>xxyxx</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>The lengths of <var>S</var> and <var>T</var> are each at least <var>1</var> and at most <var>1000</var>.</li> <li>The length of <var>T</var> is at most that of <var>S</var>.</li> <li><var>S</var> and <var>T</var> consist of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of characters in <var>S</var> that need to be changed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>cabacc abc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>For example, changing the fourth character <code>a</code> in <var>S</var> to <code>c</code> will match the second through fourth characters in <var>S</var> to <var>T</var>.</p> <p>Since <var>S</var> itself does not have <var>T</var> as its substring, this number of changes - one - is the minimum needed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>codeforces atcoder </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre></section> </div> </span>
p02121
<h1>Problem K: Chinol Choco</h1> <h2>Problem</h2> <p> チョコレヌト䌚瀟チノルチョコは新しい店を<var>n</var>店建おるこずにした。<br> それぞれの店は各店長に建おたい堎所の候補を2぀甚意しおもらい、どちらかの堎所に建おる。 </p> <p> チノルチョコでは<var>m</var>皮類のチョコレヌトを販売しおおり、それぞれ別の工堎で補造しおいる。<br> すべおの店で党皮類のチョコレヌトを販売する。<br> チノルチョコではチョコレヌトを搬送するためのトラックを1台しか所有しおおらず、1台のトラックでは1店分のチョコレヌトしか運べない。<br> そのため、トラックは店から別の店ぞ移動する際にすべおの工堎を回る必芁がある。 </p> <p> ある店から別の店ぞ移動する時の最短移動距離の最倧が最小になるように店を配眮した時の、最倧の移動距離を求めよ。 </p> <p> 同じ堎所に耇数の店や工堎が存圚するこずができる。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>n</var> <var>m</var> <var>a</var><sub>0</sub> <var>b</var><sub>0</sub> <var>c</var><sub>0</sub> <var>d</var><sub>0</sub> ... <var>a</var><sub><var>n</var>&minus;1</sub> <var>b</var><sub><var>n</var>&minus;1</sub> <var>c</var><sub><var>n</var>&minus;1</sub> <var>d</var><sub><var>n</var>&minus;1</sub> <var>x</var><sub>0</sub> <var>y</var><sub>0</sub> ... <var>x</var><sub><var>m</var>&minus;1</sub> <var>y</var><sub><var>m</var>&minus;1</sub> </pre> <p> 入力はすべお敎数で䞎えられる。<br> 1行目にチノルチョコの店の数<var>n</var>、チョコレヌトを補造しおいる工堎の数<var>m</var>が空癜区切りで䞎えられる。<br> 2行目から<var>n</var>行にそれぞれの店を建おる堎所の候補の座暙(<var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>),(<var>c<sub>i</sub></var>,<var>d<sub>i</sub></var>)が空癜区切りで䞎えられる。<br> 2&plus;<var>n</var>行目から<var>m</var>行に工堎の座暙(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>)が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li>2 &le; <var>n</var> &le; 200</li> <li>1 &le; <var>m</var> &le; 15</li> <li>0 &le; <var>a<sub>i</sub></var>,<var>b<sub>i</sub></var>,<var>c<sub>i</sub></var>,<var>d<sub>i</sub></var>,<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var> &le; 1000</li> </ul> <h2>Output</h2> <p> 最短移動距離の最倧が最小になるように店を配眮した時の、最倧の移動距離を出力せよ。<br> 誀差が10<sup>&minus;6</sup>を超えおはならない。 </p> <h2>Sample Input 1</h2> <pre> 2 1 0 0 5 5 3 3 6 6 2 2 </pre> <h2>Sample Output 1</h2> <pre> 4.2426406871 </pre> <h2>Sample Input 2</h2> <pre> 2 2 0 0 6 0 7 0 3 0 4 0 5 0 </pre> <h2>Sample Output 2</h2> <pre> 3.0000000000 </pre>
p03419
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive <var>N</var> rows and <var>M</var> columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.</p> <p>We will perform the following operation once for each square contains a card:</p> <ul> <li>For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.</li> </ul> <p>It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,M \leq 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>M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of cards that face down after all the operations.</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>0 </pre> <p>We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <p>After all the operations, all cards except at both ends face down.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>314 1592 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>496080 </pre></section> </div> </span>
p01424
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Palindrome Generator</H1> <p> A palidrome craftsperson starts to work in the early morning, with the clear air allowing him to polish up his palindromes. </p> <p> On this morning, he is making his pieces to submit to the International Contest for Palindrome Craftspeople. </p> <p> By the way, in order to make palindromes, he uses a special dictionary which contains a set of words and a set of ordered pairs of the words. Any words and any ordered pairs of consecutive words in his palindromes must appear in the dictionary. </p> <p> We already have his dictionary, so let's estimate how long a palindrome he can make. </p> <H2>Input</H2> <p> The first line in the data set consists of two integers <var>N</var> (<var>1 \leq N \leq 100</var>) and <var>M</var> (<var>0 \leq M \leq 1\,000</var>). <var>N</var> describes the number of words in the dictionary and <var>M</var> describes the number of ordered pairs of words. </p> <p> The following <var>N</var> lines describe the words he can use. The <var>i</var>-th line (<var>1</var>-based) contains the word <var>i</var>, which consists of only lower-case letters and whose length is between <var>1</var> and <var>10</var>, inclusive. </p> <p> The following <var>M</var> lines describe the ordered pairs of consecutive words he can use. The <var>j</var>-th line (<var>1</var>-based) contains two integers <var>X_j</var> and <var>Y_j</var> (<var>1 \leq X_j, Y_j \leq N</var>). <var>X_j</var> describes the (<var>1</var>-based) index of the former word in the palindrome and <var>Y_j</var> describes that of the latter word. </p> <H2>Output</H2> <p> Print the maximal length of the possible palindrome in a line. If he can make no palidromes, print &quot;0&quot;. If he can make arbitrary long palindromes, print &quot;-1&quot;. </p> <H2>Sample Input 1</H2> <pre> 2 2 ab ba 1 1 1 2 </pre> <H2>Output for the Sample Input 1</H2> <pre> 4 </pre> <H2>Sample Input 2</H2> <pre> 2 2 ab ba 1 1 2 2 </pre> <H2>Output for the Sample Input 2</H2> <pre> 0 </pre> <H2>Sample Input 3</H2> <pre> 2 2 ab a 1 1 1 2 </pre> <H2>Output for the Sample Input 3</H2> <pre> -1 </pre>
p03049
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has <var>N</var> strings. The <var>i</var>-th string is <var>s_i</var>.</p> <p>Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of <code>AB</code> in the resulting string.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^{4}</var></li> <li><var>2 \leq |s_i| \leq 10</var></li> <li><var>s_i</var> consists of uppercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s_1</var> <var>\vdots</var> <var>s_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 ABCA XBAZ BAD </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>For example, if we concatenate <code>ABCA</code>, <code>BAD</code> and <code>XBAZ</code> in this order, the resulting string <code>ABCABADXBAZ</code> has two occurrences of <code>AB</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 BEWPVCRWH ZZNQYIJX BAVREA PA HJMYITEOX BCJHMRMNK BP QVFABZ PRGKSPUNA </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>7 RABYBBE JOZ BMHQUVA BPA ISU MCMABAOBHZ SZMEHMA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p01074
<h1>Problem C: Unhappy Class</h1> <h2>Problem</h2> <p> 山之埡船孊園の1幎G組は、䞍幞を背負った女子生埒たちが集たるクラスである。 圌女たちは、幞犏になるこずを目暙に、日々様々な詊緎に立ち向かう。 </p> <p> 圌女たちのクラスでは、幞犏になるための詊緎の䞀環ずしお、幞犏実技科目を受講するこずができる。<br> 月曜から金曜のそれぞれ1限から<var>N</var>限たでに授業科目の枠があり、<var>M</var>個の受講可胜な科目がある。 </p> <p> 科目<var>i</var>は、曜日<var>d<sub>i</sub></var>(<var>d<sub>i</sub></var> = 0, 1, 2, 3, 4がそれぞれ、月曜、火曜、氎曜、朚曜、金曜に察応する)の<var>a<sub>i</sub></var>限目から始たり、連続する<var>k<sub>i</sub></var>コマで行われ、それを受講したずきに埗られる幞犏床は<var>t<sub>i</sub></var>である。 </p> <p> 各生埒は、最倧<var>L</var>個の科目を互いに重ならないように自由に遞ぶこずができる。どのように科目を遞べば、最も高い幞犏床を埗られるだろうか。䞎えられた科目の情報から、埗られる幞犏床の最倧倀を求めおほしい。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>M</var> <var>L</var> <var>d<sub>1</sub></var> <var>a<sub>1</sub></var> <var>k<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>2</sub></var> <var>a<sub>2</sub></var> <var>k<sub>2</sub></var> <var>t<sub>2</sub></var> ... <var>d<sub>M</sub></var> <var>a<sub>M</sub></var> <var>k<sub>M</sub></var> <var>t<sub>M</sub></var> </pre> <p> 1行目に3぀の敎数<var>N</var>, <var>M</var>, <var>L</var>が空癜区切りで䞎えられる。<br> 2行目から<var>M</var>+1行目に4぀の敎数<var>d<sub>i</sub></var>, <var>a<sub>i</sub></var>, <var>k<sub>i</sub></var>, <var>t<sub>i</sub></var>が空癜区切りで䞎えられる。 </p> <h2>Constraints</h2> <ul> <li>2 &le; <var>N</var> &le; 8</li> <li>0 &le; <var>M</var> &le; 300</li> <li>0 &le; <var>L</var> &le; min(<var>N</var>&times;5, <var>M</var>)</li> <li>0 &le; <var>d<sub>i</sub></var> &le; 4</li> <li>1 &le; <var>a<sub>i</sub></var> &le; <var>N</var></li> <li>1 &le; <var>k<sub>i</sub></var></li> <li><var>a<sub>i</sub></var> + <var>k<sub>i</sub></var> - 1 &le; <var>N</var></li> <li>1 &le; <var>t<sub>i</sub></var> &le; 100</li> </ul> <h2>Output</h2> <p> 幞犏床の和の最倧倀を1行に出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 7 3 0 1 1 1 0 1 1 2 1 1 3 4 1 1 1 1 1 2 1 2 2 1 1 3 2 2 2 1 </pre> <h2>Sample Output 1</h2> <pre> 9 </pre> <h2>Sample Input 2</h2> <pre> 5 10 5 0 1 1 2 0 2 1 2 0 1 2 3 1 2 1 2 1 4 2 3 2 1 1 1 2 1 1 2 3 3 2 3 4 1 1 2 4 2 1 2 </pre> <h2>Sample Output 2</h2> <pre> 13 </pre>
p00235
<H1>サヌゞェント・ラむアン</H1> <p> 「ラむアン軍曹を救え」ずいう指什のもず、アむヅ軍の救出郚隊はドむツリヌの氎䞊郜垂で敵軍ず激しい戊闘を繰り広げおいたした。圌らは無事に軍曹ず合流したしたが、敵の戊車が倚く、救出ヘリを呌べずにいたした。そこで、圌らは敵の戊車を混乱させるため、郜垂にある橋を党お爆砎するずいう䜜戊を実行するこずにしたした。 </p> <p> 䜜戊はすぐに叞什郚に䌝えられ、救出ヘリの準備が進められたした。救出ヘリを飛ばすためには、い぀橋が党お爆砎されるかを予枬しなければなりたせん。軍のプログラマであるあなたの任務は、救出郚隊が党おの橋の爆砎に必芁な時間を蚈算するこずです。 </p> <p> 氎䞊郜垂は <var>N</var> 個の島で構成されおおり、島ず島ずの間には橋がかかっおいたす。すべおの島はツリヌ状に繋がっおいたす(䞋図参照) 。ある島からある島ぞの経路は、䞀通りだけ存圚したす。各橋を枡るには、橋ごずに決められた時間がかかり、どちらの方向にもその時間で橋を枡るこずが可胜です。 </p> <p> 救出郚隊はボヌトなど氎䞊を移動する手段を持っおいないので島ず島の間を移動するには橋を通る他ありたせん。救出郚隊は、その時いる島に隣接しおいる橋のうち、必芁なものを䞀瞬で爆砎するこずができたす。救出郚隊が党おの橋を爆砎するのに必芁な最小の時間はいくらでしょうか。ただし、島の䞭での移動時間は考えたせん。 </p> <p> 島の数、それぞれの橋情報を入力ずし、橋を党お爆砎するのに必芁な最小の時間を出力するプログラムを䜜成しおください。島はそれぞれ 1 から <var>N</var> の番号で衚されたす。橋は <var>N</var>-1 本ありたす。橋情報は、その橋が隣接しおいる二぀の島の番号(<var>a</var>, <var>b</var>)ず、その橋を枡るのに必芁な時間 <var>t</var> で構成されたす。救出郚隊は島番号 1 の島からスタヌトするものずしたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_sergeant"> </center> <br> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられる。入力の終わりはれロひず぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>t<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>t<sub>2</sub></var> : <var>a<sub>N-1</sub></var> <var>b<sub>N-1</sub></var> <var>t<sub>N-1</sub></var> </pre> <p> 入力はすべお敎数で䞎えられる。1 行目に島の数 <var>N</var> (2 &le; <var>N</var> &le; 20) が䞎えられる。 </p> <p> 続く <var>N</var>-1 行に <var>i</var> 番目の橋の情報が䞎えられる。 <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var>, <var>t<sub>i</sub></var> (1 &le; <var>t<sub>i</sub></var> &le; 500) は、<var>i</var> 番目の橋を通っお島 <var>a<sub>i</sub></var> ず島 <var>b<sub>i</sub></var> の間を時間 <var>t<sub>i</sub></var> で移動できるこずを衚す。 </p> <p> デヌタセットの数は 100 を超えない。 </p> <H2>Output</H2> <p> デヌタセットごずに、橋を党お爆砎するのに必芁な最小の時間を1行に出力する。 </p> <H2>Sample Input</H2> <pre> 7 1 2 5 2 3 2 3 4 3 2 5 3 5 6 3 5 7 8 0 </pre> <H2>Output for the Sample Input</H2> <pre> 12 </pre>
p02208
<h2>カツサンド (Cutlet Sandwich)</h2> <p>ある䞖界には、 $X$ 皮類の「サンド」、 $Y$ 皮類の「カツ」、 $Z$ 皮類の「カレヌ」ずいう食べ物がありたす。</p> <p>この䞖界には $N$ 皮類の「カツサンド」ずいう食べ物があり、 $i$ 皮類目のカツサンドは $A_i$ 皮類目のサンドず $B_i$ 皮類目のカツが原料です。</p> <p>たた、 $M$ 皮類の「カツカレヌ」ずいう食べ物があり、 $i$ 皮類目のカツカレヌは $C_i$ 皮類目のカツず $D_i$ 皮類目のカレヌが原料です。</p> <p>Segtree 君は、あるカツサンドたたはカツカレヌを持っおいるずき、原料のうち少なくずも $1$ ぀が共通しおいるようなカツサンドたたはカツカレヌず亀換するこずができたす。</p> <p>䟋えば、$a$ 皮類目のサンドず $b$ 皮類目のカツが原料であるカツサンドを持っおいるずき、 $a$ 皮類目のサンドたたは $b$ 皮類目のカツを原料に持぀任意のカツサンド、たたは、 $b$ 皮類目のカツを原料に含む任意のカツカレヌず亀換できたす。 </p> <p>今、 Segtree 君は $S$ 皮類目のカツサンドを持っおいたすが、食べたいのは $T$ 皮類目のカツカレヌです。</p> <p>$T$ 皮類目のカツカレヌを手に入れるこずができるか刀定しおください。もし可胜ならば、最小䜕回の亀換で目的のカツカレヌを手にいられるかを求めおください。</p> <h3>入力</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre> $X$ $Y$ $Z$ $N$ $M$ $S$ $T$ $A_1$ $B_1$ $A_2$ $B_2$ $\ldots$ $A_N$ $B_N$ $C_1$ $D_1$ $C_2$ $D_2$ $\ldots$ $C_M$ $D_M$ </pre> <h3>出力</h3> <p> $T$ 皮類目のカツカレヌを手に入れるために必芁な最小の亀換回数を出力しおください。手に入れるこずが䞍可胜ならば、代わりに「 $-1$ 」を出力しおください。 </p> <p>ただし、最埌には改行を入れるこず。</p> <h3>制玄</h3> <ul> <li>$1 \leq X,Y,Z,N,M \leq 10^5$</li> <li>$1 \leq S \leq N$</li> <li>$1 \leq T \leq M$</li> <li>$1 \leq A_i \leq X$</li> <li>$1 \leq B_i \leq Y$</li> <li>$1 \leq C_i \leq Y$</li> <li>$1 \leq D_i \leq Z$</li> <li>入力は党お敎数である。</li> </ul> <h3>入力䟋1</h3> <pre> 1 1 1 1 1 1 1 1 1 1 1 </pre> <h3>出力䟋1</h3> <pre> 1 </pre> <h3>入力䟋2</h3> <pre> 2 3 4 3 5 1 5 1 1 1 2 2 2 2 1 3 1 3 2 3 3 3 4 </pre> <h3>出力䟋2</h3> <pre> 4 </pre> <h3>入力䟋3</h3> <pre> 1 2 2 1 2 1 1 1 2 1 2 2 1 </pre> <h3>出力䟋3</h3> <pre> -1 </pre>
p00665
<H1>Problem G : Everything Starts With Your Vote</H1> <p> ヒュヌリスティクスずいう蚀葉がある。確実にうたくいくずいう保蚌はないけれども倧抵の堎合はうたくいく、比范的単玔なアプロヌチのこずだ。単玔にしお匷力であるがゆえに、この䞖の䞭は倚くのヒュヌリスティクスで満ち溢れおいる。 </p> <p> ヒュヌリスティクスの䞀䟋ずしお、こんなものが挙げられる。アニメ番組においお、あるキャラクタヌの人気床は、そのアニメ本線䞭における登堎時間の総和に比䟋する。確かにこれは倚くの堎合に成り立っおいるようだ。しかし、どうやら僕は少数掟に属するらしい。圱の薄いキャラ、背景にちらりず映るモブキャラなんかに限っお可愛く芋えたりするのだ。 </p> <p> 自分の奜きなキャラのこずを、他人がどう思っおいようがいいじゃないか。ずは蚀っおられない事情が、残念ながらある。関連商品、フィギュアやキャラクタヌ゜ングCDなどは、人気のあるキャラのものから優先的に発売される傟向にあるのだ。商業的には圓然の遞択だずはいえ、䞍人気キャラのファンの肩身は狭い。 </p> <p> そこで重芁ずなっおくるのが、アニメ番組の制䜜䌚瀟によっお行われる人気投祚である。実際の人気がどうであれ、ここで倚くの祚を獲埗すれば、関連商品ぞの道が開かれるのだ。どんな手段を䜿っおも祚を集めねばなるたい。 </p> <p> 厳正なる投祚のために、ある関連商品を1぀賌入するたびに1祚の投祚暩が䞎えられる。この仕組を厳正ず呌ぶべきかどうかは今倧きく議論されおいるが、ずにかく僕は <i>L</i> 祚の投祚暩を埗た。投祚の察象ずなるキャラは党郚で <i>N</i> 人いお、より倚くの祚を獲埗した <i>K</i> 人のキャラ (同祚の堎合は名前の蟞曞順) の関連商品が䌁画されるこずになる。僕の奜きなキャラは党郚で <i>M</i> 人いお、その䞭からできるだけ倚くのキャラを䞊䜍 <i>K</i> 人に入れたいず思っおいる。 </p> <p> 僕はたず、それぞれのキャラがどれだけの祚を獲埗するかを予枬した(難しいこずではない。あるキャラクタヌの人気床は、その登堎時間の総和に比䟋するず仮定しただけだ)。この予枬が正しいずしお、より倚くの僕の奜きなキャラの関連商品が発売されるようにするためには、僕はこの <i>L</i> 祚を誰にどれだけ投じればいいだろうか。 </p> <h2>Input</h2> <p> 入力は耇数のケヌスからなる。 各ケヌスは以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>N</i> <i>M</i> <i>K</i> <i>L</i> <i>name<sub>0</sub></i> <i>x<sub>0</sub></i> . . . <i>name<sub>N-1</sub></i> <i>x<sub>N-1</sub></i> <i>fav<sub>0</sub></i> . . . <i>fav<sub>M-1</sub></i> </pre> <p> <i>N</i>、<i>M</i>、<i>K</i>、<i>L</i>の意味は問題文に蚘されおいるずおりである。<br> <i>name<sub>i</sub></i> はキャラクタヌの名前、<i>x<sub>i</sub></i> は<i>i</i> 番目のキャラクタヌの祚の総数を衚す。<br> <i>fav<sub>i</sub></i> はあなたがひいきしおいるキャラクタヌの名前を衚す。これらの名前は必ず異なり、たた必ずキャラクタヌの名前の入力の䞭に含たれる。<br> </p> <p> 入力の終わりは<i>N</i> = 0 か぀ <i>M</i> = 0 か぀ <i>K</i> = 0 か぀ <i>L</i> = 0からなる行によっお䞎えられる<br> </p> <p> たた各倀は以䞋の条件を満たす<br> 1 &le; <i>N</i> &le; 100,000<br> 1 &le; <i>M</i> &le; <i>N</i><br> 1 &le; <i>K</i> &le; <i>N</i><br> 1 &le; <i>L</i> &le; 100,000,000<br> 0 &le; <i>x<sub>i</sub></i> &le; 100,000,000<br> <i>name<sub>i</sub></i>はアルファベットのみを含み、長さは10文字以䞋である。 </p> <p> テストケヌスの数は150を超えない。<br> たた20,000 &le; <i>N</i> ずなるケヌスの数は20を超えないこずが保蚌されおいる。<br> </p> <p> ゞャッゞデヌタは倧きいので、速い入力を䜿うこずを掚奚する。 </p> <h2>Output</h2> <p> <i>M</i> 人のキャラの䞭から最倧で䜕人を䞊䜍<i>K</i> 人に入れるこずが出来るかを1行で出力せよ。 </p> <h2>Sample input</h2> <pre>4 1 3 4 yskwcnt 16 akzakr 7 tsnukk 12 fnmyi 13 akzakr 4 1 3 5 akzakr 7 tsnukk 12 fnmyi 13 yskwcnt 16 akzakr 4 2 2 1 akzakr 4 tsnukk 6 yskwcnt 6 fnmyi 12 akzakr fnmyi 5 2 3 28 knmmdk 6 skrkyk 14 tmemm 14 akmhmr 15 mksyk 25 knmmdk skrkyk 5 2 3 11 tmemm 12 skrkyk 18 knmmdk 21 mksyk 23 akmhmr 42 skrkyk tmemm 14 5 10 38 iormns 19 hbkgnh 23 yyitktk 31 rtkakzk 36 mmftm 43 ykhhgwr 65 hrkamm 66 ktrotns 67 mktkkc 68 mkhsi 69 azsmur 73 tknsj 73 amftm 81 chyksrg 88 mkhsi hbkgnh mktkkc yyitktk tknsj 14 5 10 38 mktkkc 24 rtkakzk 25 ykhhgwr 25 hrkamm 27 amftm 37 iormns 38 tknsj 38 yyitktk 39 hbkgnh 53 mmftm 53 chyksrg 63 ktrotns 63 azsmur 65 mkhsi 76 mkhsi hbkgnh mktkkc yyitktk tknsj 0 0 0 0 </pre> <H2>Sample output</H2> <pre> 0 1 1 2 1 4 5 </pre> <hr> <p> The University of Aizu Programming Contest 2011 Summer<br> 原案: Tomoya Sakai<br> 問題文: Takashi Tayama<br> </p>