question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p03740
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Alice and Brown loves games. Today, they will play the following game.</p> <p>In this game, there are two piles initially consisting of <var>X</var> and <var>Y</var> stones, respectively. Alice and Bob alternately perform the following operation, starting from Alice:</p> <ul> <li>Take <var>2i</var> stones from one of the piles. Then, throw away <var>i</var> of them, and put the remaining <var>i</var> in the other pile. Here, the integer <var>i</var> <var>(1≀i)</var> can be freely chosen as long as there is a sufficient number of stones in the pile.</li> </ul> <p>The player who becomes unable to perform the operation, loses the game.</p> <p>Given <var>X</var> and <var>Y</var>, determine the winner of the game, assuming that both players play optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 ≀ X, Y ≀ 10^{18}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the winner: either <code>Alice</code> or <code>Brown</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Brown </pre> <p>Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Alice </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Brown </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Alice </pre></section> </div> </span>
p03310
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has an integer sequence <var>A</var> of length <var>N</var>.</p> <p>He will make three cuts in <var>A</var> and divide it into four (non-empty) contiguous subsequences <var>B, C, D</var> and <var>E</var>. The positions of the cuts can be freely chosen.</p> <p>Let <var>P,Q,R,S</var> be the sums of the elements in <var>B,C,D,E</var>, respectively. Snuke is happier when the absolute difference of the maximum and the minimum among <var>P,Q,R,S</var> is smaller. Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>4 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the minimum possible absolute difference of the maximum and the minimum among <var>P,Q,R,S</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 2 4 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>If we divide <var>A</var> as <var>B,C,D,E=(3),(2),(4),(1,2)</var>, then <var>P=3,Q=2,R=4,S=1+2=3</var>. Here, the maximum and the minimum among <var>P,Q,R,S</var> are <var>4</var> and <var>2</var>, with the absolute difference of <var>2</var>. We cannot make the absolute difference of the maximum and the minimum less than <var>2</var>, so the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 10 71 84 33 6 47 23 25 52 64 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>36 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 2 3 1000000000 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>999999994 </pre></section> </div> </span>
p00496
<H1>倜店(Night Market) </H1> <p> 倪郎くんはJOI 神瀟で開かれる倏祭りに行くこずにした </p> <p> JOI 神瀟に向かう道に沿っお<i>N</i> 個の倜店が開かれおいるそれぞれの倜店には1 から<i>N</i> たでの番号が順番に぀いおおり遊んだ時の楜しさず遊ぶのにかかる時間がそれぞれ敎数で決たっおいる倜店<i>i</i> で遊んだ時の楜しさは<i>A<sub>i</sub></i> で倜店<i>i</i> で遊ぶのにかかる時間は<i>B<sub>i</sub></i> である </p> <p> たた倏祭りのむベントずしお花火倧䌚があり時刻<i>S</i> に最も倧きな花火が打ち䞊げられる倪郎くんはこの最も倧きな花火を芋たいず思っおいる </p> <p> 倪郎くんは倜店ず花火の䞡方を楜しむために倏祭りに到着する時刻0 から倏祭りが終わる時刻<i>T</i> たでの予定を立おるこずにした </p> <p> 倪郎くんは倜店の䞭から<i>k</i> 個(1 &le; <i>k</i> &le; <i>N</i>) の倜店を遞びそれぞれに察しお蚪れる時刻を敎数で決める同じ倜店を2 床遞ぶこずはできない遞ばれた倜店の番号を小さい順に<i>y</i><sub>1</sub>, <i>y</i><sub>2</sub>, ... <i>y<sub>k</sub></i> ずし倜店<i>y<sub>i</sub></i> を蚪れる時刻を<i>x<sub>y<sub>i</sub></sub></i> ずするず倪郎くんは倜店<i>y<sub>i</sub></i> で時刻<i>x<sub>y<sub>i</sub></sub></i> から時刻<i>x<sub>y<sub>i</sub></sub></i> + <i>B<sub>y<sub>i</sub></sub></i> たで遊ぶ </p> <p> 倪郎くんは倜店の番号の小さい順に遊び同時に2 ぀の倜店では遊べないたた倜店ず倜店の間の移 動にかかる時間は無芖できる </p> <p> 時刻<i>T</i> を超えるず倏祭りが終わるので倜店で遊ぶこずはできないたた倜店で遊んでいる間は花火を芋るこずはできないただし時刻<i>S</i> がある倜店で遊び始める時刻や遊び終わる時刻であった堎合は倪郎くんは花火を芋るこずができるものずする </p> <p> すなわち予定は以䞋の条件を満たしおいなければならない </p> <ul> <li> <i>y</i><sub>1</sub> &lt; <i>y</i><sub>2</sub> &lt; ... &lt; <i>y<sub>k</sub></i></li> <li> <i>x</i><sub><i>y</i><sub>1</sub></sub>, <i>x</i><sub><i>y</i><sub>2</sub></sub>, ... <i>x<sub>y<sub>k</sub></sub></i> は敎数</li> <li> 0 &le; <i>x</i><sub><i>y</i><sub>1</sub></sub> &lt; <i>x</i><sub><i>y</i><sub>1</sub></sub> + <i>B</i><sub><i>y</i><sub>1</sub></sub> &le; <i>x</i><sub><i>y</i><sub>2</sub></sub> &lt; <i>x</i><sub><i>y</i><sub>2</sub></sub> + <i>B</i><sub><i>y</i><sub>2</sub></sub> &le; ... &le; <i>x<sub>y<sub>k</sub></sub></i> &lt; <i>x<sub>y<sub>k</sub></sub></i> + <i>B<sub>y<sub>k</sub></sub></i> &le; <i>T</i></li> <li> <i>x<sub>y<sub>i</sub></sub></i> &lt; <i>S</i> &lt; <i>x<sub>y<sub>i</sub></sub></i> + <i>B<sub>y<sub>i</sub></sub></i> ずなるような<i>i</i> は存圚しない</li> </ul> <p> 遞ばれた倜店の楜しさ<i>A</i><sub><i>y</i><sub>1</sub></sub>, <i>A</i><sub><i>y</i><sub>2</sub></sub>, ... <i>A<sub>y<sub>k</sub></sub></i> の合蚈を<i>M</i> ずする倪郎くんは<i>M</i> ができるだけ倧きくなるように予定を立おたいず思っおいる </p> <h2>課題</h2> <p> <i>N</i> 個の倜店の情報ず時刻<i>S</i>, <i>T</i> が䞎えられた時<i>M</i> の最倧倀を求めるプログラムを䜜成せよ </p> <h2>制限</h2> <p> 1 &le; <i>N</i> &le; 3000 &nbsp;&nbsp;&nbsp;&nbsp;倜店の数<br> 1 &le; <i>T</i> &le; 3000 &nbsp;&nbsp;&nbsp;&nbsp;倏祭りが終わる時刻<br> 0 &le; <i>S</i> &le; <i>T</i> &nbsp;&nbsp;&nbsp;&nbsp;最も倧きな花火が打ち䞊げられる時刻<br> 0 &le; <i>A<sub>i</sub></i> &le; 100000 (= 10<sup>5</sup>) &nbsp;&nbsp;&nbsp;&nbsp;倜店i で遊んだ時の楜しさ<br> 1 &le; <i>B<sub>i</sub></i> &le; 3000 &nbsp;&nbsp;&nbsp;&nbsp;倜店<i>i</i> で遊ぶのにかかる時間<br> </p> <h2>入力</h2> <p> 暙準入力から以䞋の入力を読み蟌め </p> <p> 入力の1 行目には敎数<i>N</i>, <i>T</i>, <i>S</i> が空癜を区切りずしお曞かれおおり倜店の数が<i>N</i> 個倏祭りが終わる時刻が<i>T</i>最も倧きな花火が打ち䞊げられる時刻が<i>S</i> であるこずを衚す </p> <p> 続く<i>N</i> 行には倜店の情報が曞かれおいる入力の<i>i</i> + 1 (1 &le; <i>i</i> &le; <i>N</i>) 行目には敎数<i>A<sub>i</sub></i>, <i>B<sub>i</sub></i> が空癜を区切りずしお曞かれおおり倜店<i>i</i> で遊んだ時の楜しさが<i>A<sub>i</sub></i> で倜店<i>i</i> で遊ぶのにかかる時間が<i>B<sub>i</sub></i> であるこずを衚す </p> <p> たたすべおの入力においお぀以䞊の予定を立おられるこずが保蚌されおいる </p> <h2>出力</h2> <p> 暙準出力に<i>M</i> の最倧倀を衚す敎数を1 行で出力せよ </p> <h2>採点基準</h2> <p> 採点甚デヌタのうち<br> 配点の10%分に぀いおは<i>N</i> &le; 20 を満たす<br> 配点の20%分に぀いおは<i>S</i> = 0 を満たす<br> 配点の30%分に぀いおはこれら2 ぀の条件の少なくずも䞀方を満たすたたこれら2 ぀の条件の䞡方を満たすような採点甚デヌタはない<br> </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 5 20 14 8 9 2 4 7 13 6 3 5 8 </pre> <h3>出力䟋 1</h3> <pre> 16 </pre> <p> この䟋においお<br> 倜店1 を時刻0 に蚪れ<br> 倜店2 を時刻9 に蚪れ<br> 倜店4 を時刻14 に蚪れるような予定を立おるず<i>M</i> を最も倧きくするこずができる<br> このずき<i>M</i> = 8 + 2 + 6 = 16 である </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02151
<h1>Problem C: Phone Number</h1> <h2>Problem</h2> <p> 株匏䌚瀟りクニキアの電話番、デンさんは毎日ずおも長い電話番号を電話に入力しおいたす。<br> ある日䜙りにも疲れたデンさんは、疲れからか驚くべき考えに至りたした。<br> 「電話のボタンの配眮を䞊べ替えたら少しでも楜できるのでは」<br> <br> 電話には$3 \times 3$で等間隔に区切られた正方圢があり、9個のマスには䞊べ替えるこずのできる1から9たでのボタンがそれぞれ1぀ず぀぀いおいたす。<br> 電話番号を打぀際、デンさんは片手だけを䜿っお、次の二぀の操䜜を行うこずができたす。<br> </p> <ul> <li>人差し指を今觊れおいるボタンに蟺で隣接するいずれかのボタンに觊れるように移動させる。</li> <li>人差し指が觊れおいるボタンを抌す。</li> </ul> <p> 最初、人差し指は1から9たでのいずれかのボタンに觊れるように眮くこずができたす。<br> デンさんは、最初のボタンを抌しおから最埌のボタンを抌し終わるたでの、人差し指の移動回数を最も小さくできる配眮を効率的ず考えおいたす。<br> <br> さお、ここに長さ$N$のお埗意先の電話番号がありたす。<br> お埗意先の電話番号だけ考えた時に、どのような配眮が䞀番効率的でしょうか<br> ボタンを䞊び替えるこずで、その配眮を䜜っおください。<br> </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $S$ </pre> <p> 1行目にお埗意先の電話番号の長さ$N$が䞎えられる。<br> 2行目にお埗意先の電話番号が1行に䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq N \leq 10^5 $</li> <li>$S$は1から9たでのいずれかの数字からなる文字列</li> </ul> <h2>Output</h2> <p> 最も効率的な配眮を、3行に空癜を入れずに出力せよ。<br> 䜆し、解答ずなり埗る配眮が耇数ある堎合は、巊䞊の枠から<br> 123<br> 456<br> 789<br> の順序で数字を䞊べた際に蟞曞順で最小ずなるようなものを出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 10 1236547896 </pre> <h2>Sample Output 1</h2> <pre> 123 456 789 </pre> <h2>Sample Input 2</h2> <pre> 11 31415926535 </pre> <h2>Sample Output 2</h2> <pre> 137 456 892 </pre>
p00029
<H1>English Sentence</H1> <p> Your task is to write a program which reads a text and prints two words. The first one is the word which is arise most frequently in the text. The second one is the word which has the maximum number of letters. </p> <p> The text includes only alphabetical characters and spaces. A word is a sequence of letters which is separated by the spaces. </p> <H2>Input</H2> <p> A text is given in a line. You can assume the following conditions: </p> <ul> <li>The number of letters in the text is less than or equal to 1000.</li> <li> The number of letters in a word is less than or equal to 32.</li> <li> There is only one word which is arise most frequently in given text.</li> <li> There is only one word which has the maximum number of letters in given text.</li> </ul> <H2>Output</H2> <p> The two words separated by a space. </p> <H2>Sample Input</H2> <pre> Thank you for your mail and your lectures </pre> <H2>Output for the Sample Input</H2> <pre> your lectures </pre>
p02014
<h1>Problem K. Rough Sorting</h1> <!-- Time Limit: 2 sec Memory Limit: 512 MB --> <p> For skilled programmers, it is very easy to implement a sorting function. Moreover, they often avoid full sorting to reduce computation time if it is not necessary. Here, we consider "rough sorting" which sorts an array except for some pairs of elements. More formally, we define an array is "$K$-roughly sorted" if an array is sorted except that <b>at most</b> $K$ pairs are in reversed order. For example, '<span>1 3 2 4</span>' is 1-roughly sorted because (3, 2) is only the reversed pair. In the same way, '<span>1 4 2 3</span>' is 2-roughly sorted because (4, 2) and (4, 3) are reversed. </p> <p> Considering rough sorting by exchanging adjacent elements repeatedly, you need less number of swaps than full sorting. For example, '<span>4 1 2 3</span>' needs three exchanges for full sorting, but you only need to exchange once for 2-rough sorting. </p> <p> Given an array and an integer $K$, your task is to find the result of the $K$-rough sorting with a minimum number of exchanges. If there are several possible results, you should output the lexicographically minimum result. Here, the lexicographical order is defined by the order of the first different elements. </p> <h2>Input</h2> <p> The input consists of a single test case in the following format. </p> <pre> $N$ $K$ $x_1$ $\vdots$ $x_N$ </pre> <p> The first line contains two integers $N$ and $K$. The integer $N$ is the number of the elements of the array ($1 \leq N \leq 10^5$). The integer $K$ gives how many reversed pairs are allowed ($1 \leq K \leq 10^9$). Each of the following $N$ lines gives the element of the array. The array consists of the permutation of $1$ to $N$, therefore $1 \leq x_i \leq N$ and $x_i \ne x_j$ ($i \ne j$) are satisfied. </p> <h2>Output</h2> <p> The output should contain $N$ lines. The $i$-th line should be the $i$-th element of the result of the $K$-rough sorting. If there are several possible results, you should output the minimum result with the lexicographical order. </p> <h2>Examples</h2> <h2>Sample Input 1</h2> <pre> 3 1 3 2 1 </pre> <h2>Output for Sample Input 1</h2> <pre> 1 3 2 </pre> <h2>Sample Input 2</h2> <pre> 3 100 3 2 1 </pre> <h2>Output for Sample Input 2</h2> <pre> 3 2 1 </pre> <h2>Sample Input 3</h2> <pre> 5 3 5 3 2 1 4 </pre> <h2>Output for Sample Input 3</h2> <pre> 1 3 5 2 4 </pre> <h2>Sample Input 4</h2> <pre> 5 3 1 2 3 4 5 </pre> <h2>Output for Sample Input 4</h2> <pre> 1 2 3 4 5 </pre> <p> In the last example, the input array is already sorted, which means the input is already a 3-roughly sorted array and no swapping is needed. </p>
p00479
<H1>タむル (Tile)</H1> <h2>問題</h2> <p> JOI 高校では 1 &times; 1 の正方圢のタむルを䜿っお N &times; N の正方圢の壁画を䜜り文化祭で展瀺するこずになったタむルの色は赀青黄の 3 皮類である壁画のデザむンは次の通りであるたず最も倖偎の呚に赀のタむルを貌りその内偎の呚に青のタむルを貌るさらにその内偎の呚に黄色のタむルを貌るこれを N &times; N の正方圢が埋め尜くされるたで繰り返す甚いるタむルの色は䞀番倖偎の呚から順番に赀青黄赀青黄 である </p> <p> 文化祭が近づいおきたある日壁画のうち K 枚のタむルがはがれおいるこずが刀明したそこで新しいタむルを賌入しおはがれた箇所に新しいタむルを貌るこずにした </p> <p> 入力ずしお壁画の䞀蟺の長さ N ずはがれたタむルの枚数 K K 枚のはがれたタむルの䜍眮が䞎えられたずきはがれたタむルの色を求めるプログラムを䜜成せよ </p> <p> 䟋えばN = 11 の堎合11 &times; 11 の壁画のデザむンは䞋図の通りである </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0556_1"> <p> たたN = 16 の堎合16 &times; 16 の壁画のデザむンは䞋図の通りである </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0556_2"> <br> <h2>入力</h2> <p> 入力は党郚で 2+K 行からなる 1 行目には壁画の䞀蟺の長さ N 1 &le; N &le; 1000000000 = 10<sup>9</sup>が 2 行目にははがれたタむルの枚数 K 1 &le; K &le; 1000が曞かれおいる 2+i 行目1 &le; i &le; Kには2 ぀の敎数 ai ず bi 1 &le; ai &le; N, 1 &le; bi &le; Nが空癜区切りで曞かれおおり i 枚目のはがれたタむルが巊から ai 列目䞊から bi 行目のタむルであるこずを衚す </p> <p> 入力の 3 行目から 2+K 行目には同じタむルを衚す行が重耇しお珟れるこずはないたた䞎えられる入力デヌタ 40% では N &le; 1000 をみたしおいる </p> <h2>出力</h2> <p> 出力は K 行からなる各行は 1 ぀の敎数からなり i 行目1 &le; i &le;Kの敎数はi 枚目のはがれたタむルが赀のずきは 1 を青のずきは 2 を黄色のずきは 3 を衚す </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 11 4 5 2 9 7 4 4 3 9 </pre> <h3>出力䟋 1</h3> <pre> 2 3 1 3 </pre> <br> <h3>入力䟋 2</h3> <pre> 16 7 3 7 5 2 11 6 15 2 9 7 8 12 15 16 </pre> <h3>出力䟋 2</h3> <pre> 3 2 3 2 1 2 1 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div> <br>
p02444
<h1>Rotate</h1> <p> Write a program which reads a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ and rotate specified elements by a list of the following operation: </p> <ul> <li>rotate($b, m, e$): For each integer $k$ ($0 \leq k < (e - b)$), move element $b + k$ to the place of element $b + ((k + (e - m)) \mod (e - b))$.</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 \; m_1 \; e_1$ $b_2 \; m_2 \; e_2$ : $b_{q} \; m_{q} \; e_{q}$ </pre> <p> In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given by three integers $b_i \; m_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_i \leq m_i < e_i \leq n$</li> </ul> <h2>Sample Input 1</h2> <pre> 11 1 2 3 4 5 6 7 8 9 10 11 1 2 6 9 </pre> <h2>Sample Output 1</h2> <pre> 1 2 7 8 9 3 4 5 6 10 11 </pre>
p00183
<H1>䞉目䞊べ</H1> <p> 3 &times; 3 の盀面の䞉目䞊べを考えたしょう。䞉目䞊べは 2 人で行う察戊ゲヌムです。先攻埌攻を決め、䞀人は黒石、䞀人は癜石を打ちたす。盀面に石を亀互に䞀぀ず぀眮いおいき、瞊暪斜めのいずれかの方向に先に 3 ぀自分の石を䞊べた人が勝ちずなりたす。 </p> <p> 盀面の情報を入力ずし、勝敗の刀定を行い、黒が勝ちの堎合は「b」、癜が勝ちの堎合は「w」、どちらもそろっおいない堎合は「NA」ず出力するプログラムを䜜成しおください。 盀面の情報は、3行3列の文字列で構成されたす。「b」は黒石、「w」は癜石、「+」(半角プラ ス)は䜕も眮かれおいない状況を衚したす。ただし、同時に黒が3぀、癜が3぀䞊ぶこずはありたせ ん。 </p> <!--<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_ticktacktoe">--> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>board<sub>1</sub></var> <var>board<sub>2</sub></var> <var>board<sub>3</sub></var> </pre> <p> <var>i</var> 行目に盀面の <var>i</var> 行目の情報を衚す文字列 <var>board<sub>i</sub></var> が䞎えられたす。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセット毎に、「b」、「w」、「NA」のいずれかを行に出力したす。 </p> <H2>Sample Input</H2> <pre> bbw wbw +b+ bwb wbw wbw 0 </pre> <H2>Output for the Sample Input</H2> <pre> b NA </pre>
p02917
<span class="lang-en"> <p>Score : <var>300</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> whose values are unknown.</p> <p>Given is an integer sequence <var>B</var> of length <var>N-1</var> which is known to satisfy the following:</p> <p><var> B_i \geq \max(A_i, A_{i+1}) </var></p> <p>Find the maximum possible sum of the elements of <var>A</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>2 \leq N \leq 100</var></li> <li><var>0 \leq B_i \leq 10^5</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>B_1</var> <var>B_2</var> <var>...</var> <var>B_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the elements of <var>A</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p><var>A</var> can be, for example, ( <var>2</var> , <var>1</var> , <var>5</var> ), ( <var>-1</var> , <var>-2</var> , <var>-3</var> ), or ( <var>2</var> , <var>2</var> , <var>5</var> ). Among those candidates, <var>A</var> = ( <var>2</var> , <var>2</var> , <var>5</var> ) has the maximum possible sum.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 0 153 10 10 23 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>53 </pre></section> </div> </span>
p03605
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>It is September <var>9</var> in Japan now.</p> <p>You are given a two-digit integer <var>N</var>. Answer the question: Is <var>9</var> contained in the decimal notation of <var>N</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>10≀N≀99</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>If <var>9</var> is contained in the decimal notation of <var>N</var>, print <code>Yes</code>; if not, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>29 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>The one's digit of <var>29</var> is <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>72 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p><var>72</var> does not contain <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>91 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre></section> </div> </span>
p01638
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [['\\(','\\)']] } }); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> <h1 class="ndoc-heading1">Problem E: Pie Chart is as easy as pie.</h1> <p>ICPC World Finals 3日目</p> <p class="ndoc-top">この日、ティヌ氏はチヌム内の蚀語䜿甚割合を調べおいた。 珍しいこずに、我々のチヌムは䜿甚蚀語を統䞀しおいない。 調査の結果、2人がC++、1人がJavaを䜿っおいるこずが分かった。 さお、これをパむチャヌト円グラフにしおみよう。</p> <p class="ndoc-top"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie1" alt="pie1.png" width="400"></p> <p class="ndoc-top">おや、Javaの䜿甚割合が少ないように芋えるな。 どう考えおもこんなはずはないので少々手を加えよう。 これは最近流行りのテクニックであり、 「パむチャヌトの䞭心座暙をずらす」ずいうものだ。 皆さんはマネしおはいけたせん。</p> <p class="ndoc-top"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie2" alt="pie2.png" width="400"></p> <p class="ndoc-top">うむ、これでバランスがずれた。 ずころで面積はどのように倉わったのだろう</p> <h2 class="ndoc-heading2">問題</h2> <p class="ndoc-top">半埄\(r\)、項目数\(n\)のパむチャヌト円グラフが䞎えられる。 項目\(i\)の構成比率は\( p_{i} \)[%]であり、座暙\( (0, r) \)から時蚈回りに項目が割り圓おられる䞋図を参照。 パむチャヌトの䞭心座暙が\( (0, 0) \)から\( (x, y) \)に倉化した時、 各項目の占める面積は䜕%倉化するかを求めよ。</p> <p class="ndoc-top"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie" alt="pie.png" width="400"></p> <h2 class="ndoc-heading2">入力</h2> <pre> r x y n p<sub>1</sub> p<sub>2</sub> 
 p<sub>n</sub> </pre> 1行目に パむチャヌトの半埄\(r\)、䞭心のx座暙\(x\)、y座暙\(y\)、項目数\(n\)が空癜区切りで䞎えられる。 2行目には、 項目\(i\)の構成比率\( p_{i} \)[%]が空癜区切りで䞎えられる。 <h2 class="ndoc-heading2">出力</h2> <p class="ndoc-top"> 1行目に各項目の占める面積の倉化率[%]を「敎数に切り捚おた倀」を空癜区切りで出力せよ。</p> <h2 class="ndoc-heading2">制玄</h2> <ul class="ndoc-indent"> <li>入力は党お敎数で䞎えられる</li> <li>\( r = 100 \)</li> <li>\( x^{2} + y^{2} &lt; r^{2} \)</li> <li>\( 2 \leq n \leq 10 \)</li> <li>\( p_{i} &gt; 0 (1 \leq i \leq n) \)</li> <li>\( \sum_{1 \leq i \leq n}p_{i} = 100 \)</li> <li>\( (x, y) \)が高々距離\( 10^{-3} \)移動しおも答えが倉化しないこずが保蚌される</li> </ul> <h2 class="ndoc-heading2">入出力䟋</h2> <h3 class="ndoc-heading3">入力1</h3> <pre> 100 50 -50 2 67 33 </pre> <h3 class="ndoc-heading3">出力1</h3> <pre> 71 156 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie_sample_1" alt="pie_sample_1.png" width="400"> <p class="ndoc-top">項目1の面積は玄21048から玄15153に倉化した。 倉化率は15153/21048 ≒ 71.99%。</p> <p class="ndoc-top">項目2の面積は玄10367から玄16262に倉化した。 倉化率は16262/10367 ≒ 156.86%。</p> <h3 class="ndoc-heading3">入力2</h3> <pre> 100 -50 0 4 10 20 30 40 </pre> <h3 class="ndoc-heading3">出力2</h3> <pre> 115 144 113 64 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie_sample_2" alt="pie_sample_2.png" width="400"> <p class="ndoc-top">項目ごずのおよその面積の倉化は以䞋の通り。</p> <ul class="ndoc-indent"> <li>項目1: 3142 → 3619</li> <li>項目2: 6283 → 9078</li> <li>項目3: 9425 → 10675</li> <li>項目4: 12566 → 8044</li> </ul> <h3 class="ndoc-heading3">入力3</h3> <pre> 100 70 -70 8 1 24 1 24 1 24 1 24 </pre> <h3 class="ndoc-heading3">出力3</h3> <pre> 167 97 27 10 32 102 172 189 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_uecpc2013_files_pie_sample_3" alt="pie_sample_3.png" width="400">
p03255
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has decided to use a robot to clean his room.</p> <p>There are <var>N</var> pieces of trash on a number line. The <var>i</var>-th piece from the left is at position <var>x_i</var>. We would like to put all of them in a trash bin at position <var>0</var>.</p> <p>For the positions of the pieces of trash, <var>0 &lt; x_1 &lt; x_2 &lt; ... &lt; x_{N} \leq 10^{9}</var> holds.</p> <p>The robot is initially at position <var>0</var>. It can freely move left and right along the number line, pick up a piece of trash when it comes to the position of that piece, carry any number of pieces of trash and put them in the trash bin when it comes to position <var>0</var>. It is not allowed to put pieces of trash anywhere except in the trash bin.</p> <p>The robot consumes <var>X</var> points of energy when the robot picks up a piece of trash, or put pieces of trash in the trash bin. (Putting any number of pieces of trash in the trash bin consumes <var>X</var> points of energy.) Also, the robot consumes <var>(k+1)^{2}</var> points of energy to travel by a distance of <var>1</var> when the robot is carrying <var>k</var> pieces of trash.</p> <p>Find the minimum amount of energy required to put all the <var>N</var> pieces of trash in the trash bin.</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 &lt; x_1 &lt; ... &lt; x_N \leq 10^9</var></li> <li><var>1 \leq X \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li><var>400</var> points will be awarded for passing the test set satisfying <var>N \leq 2000</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 100 1 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>355 </pre> <ul> <li>Travel to position <var>10</var> by consuming <var>10</var> points of energy.</li> <li>Pick up the piece of trash by consuming <var>100</var> points of energy.</li> <li>Travel to position <var>1</var> by consuming <var>36</var> points of energy.</li> <li>Pick up the piece of trash by consuming <var>100</var> points of energy.</li> <li>Travel to position <var>0</var> by consuming <var>9</var> points of energy.</li> <li>Put the two pieces of trash in the trash bin by consuming <var>100</var> points of energy.</li> </ul> <p>This strategy consumes a total of <var>10+100+36+100+9+100=355</var> points of energy.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 1 999999997 999999998 999999999 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>19999999983 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 8851025 38 87 668 3175 22601 65499 90236 790604 4290609 4894746 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>150710136 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>16 10 1 7 12 27 52 75 731 13856 395504 534840 1276551 2356789 9384806 19108104 82684732 535447408 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3256017715 </pre></section> </div> </span>
p01268
<h1><font color="#000">Problem B:</font> Matsuzaki Number</h1> <p> Matsuzaki 教授は宇宙の真理を研究しおいる科孊者である人生宇宙すべおの答えは 42 であるず蚀われおいるがMatsuzaki 教授はこれだけでは宇宙の真理を解明するには䞍十分であるず考えおいるMatsuzaki 教授は宇宙の真理は 2 ぀のパラメヌタからなる関数で衚されるず考えおおり42 はその 1 ぀に過ぎないずいうのである </p> <p> Matsuzaki 教授の定矩した関数 M(<i>N</i>, <i>P</i>) は<i>N</i> より倧きい玠数を 2 ぀遞んで同じ数を 2 ぀でも構わない和をずるこずで埗られる数の党䜓を小さいほうから順番に䞊べたずきに<i>P</i> 番目に珟れる数を衚すここで2 通り以䞊の和で衚されるような数も存圚するがそういった数は和の組み合わせの数ず同じ個数だけ䞊べられる </p> <p> 䟋ずしお <i>N</i> = 0 の堎合を考えようこのずきは玠数党䜓から 2 ぀を遞んで和をずるこずになるそういった和のうちで最小の数を考えるず同じ数を 2 回遞ぶこずも蚱されおいるこずから2 + 2 = 4 であるこずがわかるすなわち M(0, 1) = 4 である次に小さい数は 2 + 3 = 5 であるから M(0, 2) = 5 ずなる同様にしお考えるず和を䞊べたものは 4, 5, 6, 7, 8, 9, 10, 10, 12, 13, 14, 14, 16, ... のようになるこずがわかるすなわちたずえば M(0, 9) = 12 である </p> <p> 同じようにしお <i>N</i> = 10 の堎合を考えるずこのずきは 10 より倧きい玠数 {11, 13, 17, 19, ...} から 2 ぀を遞ぶこずになり埗られる和を小さいほうから䞊べるず 22, 24, 26, 28, 30, 30, 32, ... のようになる </p> <p> あなたの仕事は<i>N</i> ず <i>P</i> が䞎えられた時に M(<i>N</i>, <i>P</i>) を蚈算するプログラムを曞くこずである </p> <h3>Input</h3> <p> 入力は耇数のデヌタセットからなるデヌタセットは 1 行であり2 ぀の敎数 <i>N</i> (0 &le; <i>N</i> &le; 100,000) ず <i>P</i> (1 &le; <i>P</i> &le; 100) が 1 ぀の空癜で区切られお䞎えられる </p> <p> 入力の終わりは空癜で区切られた 2 ぀の -1 を含む 1 行で瀺される </p> <h3>Output</h3> <p> 各デヌタセットに察しおM(<i>N</i>, <i>P</i>) の倀を 1 行に出力せよ出力に䜙蚈な空癜や改行を含めおはならない </p> <h3>Sample Input</h3> <pre> 0 55 0 1 0 2 0 3 10 1 10 2 10 3 10 4 10 5 10 6 11 1 11 2 11 3 100000 100 -1 -1 </pre> <h3>Output for the Sample Input</h3> <pre> 42 4 5 6 22 24 26 28 30 30 26 30 32 200274 </pre>
p00880
<H1><font color="#000">Problem G:</font> Malfatti Circles</H1> <p> The configuration of three circles packed inside a triangle such that each circle is tangent to the other two circles and to two of the edges of the triangle has been studied by many mathematicians for more than two centuries. Existence and uniqueness of such circles for an arbitrary triangle are easy to prove. Many methods of numerical calculation or geometric construction of such circles from an arbitrarily given triangle have been discovered. Today, such circles are called the <i>Malfatti circles</i>. </p> <p> Figure 7 illustrates an example. The Malfatti circles of the triangle with the vertices (20, 80), (-40, -20) and (120, -20) are approximately </p> <ul> <li> the circle with the center (24.281677, 45.219486) and the radius 21.565935,</li> <li> the circle with the center (3.110950, 4.409005) and the radius 24.409005, and</li> <li> the circle with the center (54.556724, 7.107493) and the radius 27.107493.</li> </ul> <p> Figure 8 illustrates another example. The Malfatti circles of the triangle with the vertices (20, -20), (120, -20) and (-40, 80) are approximately </p> <ul> <li> the circle with the center (25.629089, −10.057956) and the radius 9.942044,</li> <li> the circle with the center (53.225883, −0.849435) and the radius 19.150565, and</li> <li> the circle with the center (19.701191, 19.203466) and the radius 19.913790.</li> </ul> <p> Your mission is to write a program to calculate the radii of the Malfatti circles of the given triangles. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_malfattiCircles"> </center> <H2>Input</H2> <p> The input is a sequence of datasets. A dataset is a line containing six integers <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub> , <i>x</i><sub>2</sub> , <i>y</i><sub>2</sub>, <i>x</i><sub>3</sub> and <i>y</i><sub>3</sub> in this order, separated by a space. The coordinates of the vertices of the given triangle are (<i>x</i><sub>1</sub> , <i>y</i><sub>1</sub> ), (<i>x</i><sub>2</sub> , <i>y</i><sub>2</sub> ) and (<i>x</i><sub>3</sub> , <i>y</i><sub>3</sub> ), respectively. You can assume that the vertices form a triangle counterclockwise. You can also assume that the following two conditions hold. </p> <ul> <li> All of the coordinate values are greater than −1000 and less than 1000.</li> <li> None of the Malfatti circles of the triangle has a radius less than 0.1.</li> </ul> <p> The end of the input is indicated by a line containing six zeros separated by a space. </p> <H2>Output</H2> <p> For each input dataset, three decimal fractions <i>r</i><sub>1</sub> , <i>r</i><sub>2</sub> and <i>r</i><sub>3</sub> should be printed in a line in this order separated by a space. The radii of the Malfatti circles nearest to the vertices with the coordinates (<i>x</i><sub>1</sub> , <i>y</i><sub>1</sub> ), (<i>x</i><sub>2</sub> , <i>y</i><sub>2</sub> ) and (<i>x</i><sub>3</sub> , <i>y</i><sub>3</sub> ) should be <i>r</i><sub>1</sub> , <i>r</i><sub>2</sub> and <i>r</i><sub>3</sub> , respectively. </p> <p> None of the output values may have an error greater than 0.0001. No extra character should appear in the output. </p> <H2>Sample Input</H2> <pre> 20 80 -40 -20 120 -20 20 -20 120 -20 -40 80 0 0 1 0 0 1 0 0 999 1 -999 1 897 -916 847 -972 890 -925 999 999 -999 -998 -998 -999 -999 -999 999 -999 0 731 -999 -999 999 -464 -464 999 979 -436 -955 -337 157 -439 0 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 21.565935 24.409005 27.107493 9.942044 19.150565 19.913790 0.148847 0.207107 0.207107 0.125125 0.499750 0.499750 0.373458 0.383897 0.100456 0.706768 0.353509 0.353509 365.638023 365.638023 365.601038 378.524085 378.605339 378.605339 21.895803 22.052921 5.895714 </pre>
p01792
<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 C Casino</h2> <p> Taro, who owes a debt of $n$ dollars, decides to make money in a casino, where he can double his wager with probability $p$ percent in a single play of a game. Taro is going to play the game repetitively. He can choose the amount of the bet in each play, as long as it is a positive integer in dollars and at most the money in his hand. </p> <p> Taro possesses $m$ dollars now. Find out the maximum probability and the optimum first bet that he can repay all his debt, that is, to make his possession greater than or equal to his debt. </p> <h3>Input</h3> <p> The input consists of a single test case, which consists of three integers $p$, $m$, and $n$ separated by single spaces $(0 \leq p \leq 100, 0 < m < n \leq 10^9)$. </p> <h3>Output</h3> <p> Display three lines: The first line should contain the maximum probability that Taro can repay all his debt. This value must have an absolute error at most $10^{-6}$. The second line should contain an integer representing how many optimum first bets are there. Here, a first bet is optimum if the bet is necessary to achieve the maximum probability. If the number of the optimum first bets does not exceed 200, the third line should contain all of them in ascending order and separated by single spaces. Otherwise the third line should contain the 100 smallest bets and the 100 largest bets in ascending order and separated by single spaces. </p> <h3>Sample Input 1</h3> <pre>60 2 3</pre> <h3>Output for the Sample Input 1</h3> <pre>0.789473 1 1</pre> <h3>Sample Input 2</h3> <pre>25 3 8</pre> <h3>Output for the Sample Input 2</h3> <pre>0.109375 2 1 3</pre>
p00750
<h1><font color="#000000">Problem E:</font> The Most Powerful Spell</h1> <!-- end en only --> <!-- begin en only --> <p> Long long ago, there lived a wizard who invented a lot of "magical patterns." In a room where one of his magical patterns is drawn on the floor, anyone can use magic by casting magic spells! The set of spells usable in the room depends on the drawn magical pattern. Your task is to compute, for each given magical pattern, the most powerful spell enabled by the pattern. </p> <!-- end en only --> <!-- begin en only --> <p> A spell is a string of lowercase letters. Among the spells, lexicographically earlier one is more powerful. Note that a string <em>w</em> is defined to be lexicographically earlier than a string <em>u</em> when <em>w</em> has smaller letter in the order a&lt;b&lt;...&lt;z on the first position at which they differ, or <em>w</em> is a prefix of <em>u</em>. For instance, "abcd" is earlier than "abe" because 'c' &lt; 'e', and "abe" is earlier than "abef" because the former is a prefix of the latter. </p> <!-- end en only --> <!-- begin en only --> <p> A magical pattern is a diagram consisting of uniquely numbered <em>nodes</em> and <em>arrows</em> connecting them. Each arrow is associated with its <em>label</em>, a lowercase string. There are two special nodes in a pattern, called the <em>star node</em> and the <em>gold node</em>. A spell becomes usable by a magical pattern if and only if the spell emerges as a sequential concatenation of the labels of a path from the star to the gold along the arrows. </p> <!-- end en only --> <!-- begin en only --> <p> The next figure shows an example of a pattern with four nodes and seven arrows. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_E-3" width="312" height="283" alt="picture: sample dataset 1"> </center> <!-- end en only --> <!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/E-1" width="272" height="283" alt="picture: sample dataset 1"> --> <!-- begin en only --> <p> The node 0 is the star node and 2 is the gold node. One example of the spells that become usable by this magical pattern is "abracadabra", because it appears in the path </p><p> &nbsp;&nbsp;&nbsp;&nbsp; 0 --"abra"--&gt; 1 --"cada"--&gt; 3 --"bra"--&gt; 2. </p><p> Another example is "oilcadabraketdadabra", obtained from the path </p><p> &nbsp;&nbsp;&nbsp;&nbsp; 0 --"oil"--&gt; 1 --"cada"--&gt; 3 --"bra"--&gt; 2 --"ket"--&gt; 3 --"da"--&gt; 3 --"da"--&gt; 3 --"bra"--&gt; 2. </p><p> The spell "abracadabra" is more powerful than "oilcadabraketdadabra" because it is lexicographically earlier. In fact, no other spell enabled by the magical pattern is more powerful than "abracadabra". Thus "abracadabra" is the answer you have to compute. </p> <!-- end en only --> <!-- begin en only --> <p> When you cannot determine the most powerful spell, please answer "NO". There are two such cases. One is the case when no path exists from the star node to the gold node. The other case is when for every usable spell there always exist more powerful spells. The situation is exemplified in the following figure: "ab" is more powerful than "b", and "aab" is more powerful than "ab", and so on. For any spell, by prepending "a", we obtain a lexicographically earlier (hence more powerful) spell. </p> <!-- end en only --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_D2010_E-2" width="242" height="123" alt="picture: sample dataset 2"/> </center> <h3>Input</h3> <!-- begin en only --> <p> The input consists of at most 150 datasets. Each dataset is formatted as follows. </p> <!-- end en only --> <blockquote> <i>n a s g</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>lab</i><sub>1</sub><br> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> <i>lab</i><sub>2</sub><br> ...<br> <i>x<sub>a</sub> <i>y</i><sub>a</sub> <i>lab</i><sub>a</sub></i><br> </pre> </blockquote> <!-- begin en only --> <p> The first line of a dataset contains four integers. <i>n</i> is the number of the nodes, and <i>a</i> is the number of the arrows. The numbers <i>s</i> and <i>g</i> indicate the star node and the gold node, respectively. Then <i>a</i> lines describing the arrows follow. Each line consists of two integers and one string. The line "<i>x<sub>i</sub></i> <i>y<sub>i</sub></i> <i>lab<sub>i</sub></i>" represents an arrow from the node <i>x<sub>i</sub></i> to the node <i>y<sub>i</sub></i> with the associated label <i>lab<sub>i</sub></i> . Values in the dataset satisfy: 2 &le; <i>n</i> &le; 40, 0 &le; <i>a</i> &le; 400, 0 &le; <i>s</i>, <i>g</i>, <i>x<sub>i</sub></i>&nbsp;, <i>y<sub>i</sub></i> &lt; <i>n</i> , <i>s</i> &ne;<i>g</i>, and <i>lab<sub>i</sub></i> is a string of 1 to 6 lowercase letters. Be careful that there may be self-connecting arrows (i.e., <i>x<sub>i</sub></i> = <i>y<sub>i</sub></i> ), and multiple arrows connecting the same pair of nodes (i.e., <i>x<sub>i</sub></i> = <i>x<sub>j</sub></i> and <i>y<sub>i</sub></i> = <i>y<sub>j</sub></i> for some <i>i</i> &ne; <i>j</i> ). </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing four zeros. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a line containing the most powerful spell for the magical pattern. If there does not exist such a spell, output "NO" (without quotes). Each line should not have any other characters. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 4 7 0 2 0 1 abra 0 1 oil 2 0 ket 1 3 cada 3 3 da 3 2 bra 2 3 ket 2 2 0 1 0 0 a 0 1 b 5 6 3 0 3 1 op 3 2 op 3 4 opq 1 0 st 2 0 qr 4 0 r 2 1 0 1 1 1 loooop 0 0 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> abracadabra NO opqr NO </pre>
p01842
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h2>D - むンビゞブル</h2> <h3>Problem Statement</h3> <p> あなたは友達ず"<samp>むンビゞブル</samp>"ずいうカヌドゲヌムを遊がうずしおいる このカヌドゲヌムでは"<samp>埗点カヌド</samp>"ず"<samp>劚害カヌド</samp>"ずいう2皮類のカヌドを䜿う それぞれの埗点カヌドには正の倀が曞かれおいるこのカヌドゲヌムのルヌルは次の通りである </p> <ul> <li> ゲヌムはプレむダヌ1ずプレむダヌ2の2人のプレむダヌで行われるゲヌムはプレむダヌ1のタヌンから始たる </li> <li> 堎には1぀のスタックず2぀のデッキがあるスタックは2人のプレむダヌが眮いたカヌドからなるたたそれぞれのプレむダヌが持぀デッキはそのプレむダヌが持぀埗点カヌドず劚害カヌドからなるプレむダヌは自分もしくは盞手デッキのカヌドの順番をい぀でも確認できるゲヌムの開始時点ではスタックには1枚もカヌドはない </li> <li> 2人のプレむダヌは亀互に次の2぀の行動のどちらかをちょうど1回行う <ul><li> 自分のデッキの䞀番䞊のカヌドをスタックの䞀番䞊に眮くただしこの行動は自分のデッキにカヌドが1枚も存圚しない時には行うこずができない </li><li> 自分のタヌンをパスする </li></ul> </li> <li> プレむダヌがタヌンをパスした時次の凊理を行う <ul><li> 各プレむダヌは次の2぀の条件を満たすスタック䞭のすべおの埗点カヌドを埗る埗た埗点カヌドは堎から取り陀かれる <ol><li> 自分がスタックにおいた埗点カヌドである </li><li> 盞手が眮いたどの劚害カヌドよりも䞊にある (スタック䞭に盞手の劚害カヌドが存圚しないずきプレむダヌは自分がスタックに眮いたすべおのカヌドを埗る) </li></ol> </li> <li> スタックのカヌドをすべお取り陀く </li></ul> </li></ul> <p> もしスタックにカヌドがない状態で䞡プレむダヌが連続しおパスした堎合ゲヌムを終了する 各プレむダヌの最終的なスコアは各プレむダヌが埗た埗点カヌドに曞かれた数の総和である </p> <p> 各プレむダヌは自分のスコアから盞手のスコアを匕いた倀を最倧化するために最適な行動をずる あなたの仕事は䞎えられた各プレむダヌのデッキに察し各プレむダヌが最適に行動したずきのプレむダヌ1のスコアずプレむダヌ2のスコアの差を蚈算するこずである </p> <h3>Input</h3> <p> 入力は次のような圢匏の単䞀テストケヌスからなる </p> <p> $n$ $m$<br> $a_1$ $a_2$ $\dots$ $a_n$<br> $b_1$ $b_2$ $\dots$ $b_m$ </p> <p>1行目は山札の枚数を衚す正の敎数 $n$, $m$ ($1 \le n, m \le 50$) からなる 2行目は $n$ 個の敎数からなり$a_i$ はプレむダヌ1のデッキの䞊から $i$ 番目のカヌドを衚す ($1 \le i \le n$)$a_i$ は $1$ 以䞊$1{,}000{,}000$ 以䞋たたは $-1$ である 3行目は $m$ 個の敎数からなり$b_j$ はプレむダヌ2のデッキの䞊から $j$ 番目のカヌドを衚す ($1 \le j \le m$)$b_j$ は $1$ 以䞊$1{,}000{,}000$ 以䞋たたは $-1$ である $a_i$, $b_j$ が正の敎数の時は埗点カヌドを衚し$-1$ の時は劚害カヌドを衚す </p> <h3>Output</h3> <p> お互いのプレむダヌが最適に行動した時の (プレむダヌ1のスコア) - (プレむダヌ2のスコア) を出力せよ </p> <h3>Sample Input 1</h3> <pre>2 2 100 -1 200 300</pre> <h3>Output for the Sample Input 1</h3> <pre>-100</pre> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_d-1" height="300" width="400" /><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_d-2" height="300" width="400" /><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2016_d-3" height="300" width="400" /><br> </center> <h3>Sample Input 2</h3> <pre>3 5 10 30 -1 -1 90 20 10 -1</pre> <h3>Output for the Sample Input 2</h3> <pre>0</pre> <h3>Sample Input 3</h3> <pre>4 5 15 20 10 30 50 30 10 20 25</pre> <h3>Output for the Sample Input 3</h3> <pre>-60</pre>
p02297
<H1>Area</H1> <br/> <p> For a given polygon <var>g</var>, computes the area of the polygon. </p> <p> <var>g</var> is represented by a sequence of points <var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>,..., <var>p<sub>n</sub></var> where line segments connecting <var>p<sub>i</sub></var> and <var>p<sub>i+1</sub></var> (1 &le; <var>i</var> &le; <var>n-1</var>) are sides of <var>g</var>. The line segment connecting <var>p<sub>n</sub></var> and <var>p<sub>1</sub></var> is also a side of the polygon. </p> <p> Note that the polygon is not necessarily convex. </p> <H2>Input</H2> <p> The input consists of coordinates of the points <var>p<sub>1</sub></var>,..., <var>p<sub>n</sub></var> in the following format: </p> <pre> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <p> The first integer <var>n</var> is the number of points. The coordinate of a point <var>p<sub>i</sub></var> is given by two integers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. The coordinates of points are given in the order of counter-clockwise visit of them. </p> <H2>Output</H2> <p> Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point. </p> <H2>Constraints</H2> <ul> <li> 3 &le; <var>n</var> &le; 100 </li> <li> -10000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 10000 </li> <li>No point will occur more than once.</li> <li>Two sides can intersect only at a common endpoint.</li> </ul> <H2>Sample Input 1</H2> <pre> 3 0 0 2 2 -1 1 </pre> <H2>Sample Output 1</H2> <pre> 2.0 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 0 0 1 1 1 2 0 2 </pre> <H2>Sample Output 2</H2> <pre> 1.5 </pre>
p00300
<h1>有益氏のオヌディオルヌム</h1> <p> 数孊者である有益氏の趣味は音楜鑑賞で、家に念願のオヌディオルヌムを䜜りたした。完成したオヌディオルヌムで、友人を招いおお披露目䌚を開きたいず考えおいたす。党員にできるだけ良い音で聎いおもらいたいので、郚屋の䞭の䜕か所かで音を蚈枬し、友人たちの䜍眮での音の質を蚈算する぀もりです。 </p> <p> 蚈枬点は、䞋の図の円匧ず線分の亀点である 1 番から 35 番たでの点から遞択したす。぀の線分䞊にある点は、オヌディオシステムからの距離が 100から 500たで 100ず぀離れお䞊んでいたす。぀の円匧状にある点は、もっずも右のもの1 番から 5 番たでの点から反時蚈回りに、0°から 180° の範囲で 30°床刻みに䞊んでいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio1"> </center> <br> <p> このような円匧ず線分に囲たれた領域内のどこかに友人が居るこずになるので、友人の居る䜍眮によっ お必芁な蚈枬点を遞択したす。友人の䜍眮は、円匧に沿っお反時蚈回りに枬った角床ずオヌディオシス テムからの距離で䞎えられたす。必芁な蚈枬点は以䞋のように点か、点か、点が遞ばれたす。 </p> <table> <tr valign="top"> <td valign="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio2"></td> <td valign="top"> 友人がちょうど蚈枬点の䜍眮にいれば、その点を遞びたす。この図の䟋の堎合、遞ばれるのは 23 番の点です。 </td> </tr> <tr valign="top"> <td valign="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio3"></td> <td valign="top"> 友人が円匧たたは線分の䞊にちょうど乗っおいれば、その円匧たたは線分䞊にある、友人に最も近い点を遞びたす。この図の䟋の堎合、遞ばれるのは 18 番ず 23 番の点です。 </td> </tr> <tr valign="top"> <td valign="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_audio4"></td> <td valign="top"> 友人が円匧ず線分によっお囲たれた区画の内偎円匧や線分の䞊ではないにいれば、区画を䜜っおいる点を遞びたす。この図の䟋の堎合、遞ばれるのは 17、18、22、23 番の点です。 </td> </tr> </table> <br> <p> 有益氏を助けるために、必芁な蚈枬点の番号を求めるプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>r<sub>1</sub></var> <var>t<sub>1</sub></var> <var>r<sub>2</sub></var> <var>t<sub>2</sub></var> : <var>r<sub>N</sub></var> <var>t<sub>N</sub></var> </pre> <p> 行目に友人の数 <var>N</var> (1 &le; <var>N</var> &le; 50)が䞎えられる。続く <var>N</var> 行に、友人の䜍眮が䞎えられる。友人の䜍眮 <var>r<sub>i</sub></var> (100 &le; <var>r<sub>i</sub></var> &le; 500) はオヌディオシステムからの距離を衚す敎数、<var>t<sub>i</sub></var> (0 &le; <var>t<sub>i</sub></var> &le; 180) は円匧に沿っお反時蚈回りに枬った角床を衚す敎数である。 </p> <h2>出力</h2> <p> 各友人の䜍眮に぀いお、蚈枬点の番号を昇順で行に出力する。 </p> <h2>入出力䟋</h2> <h2>入力䟋 </h2> <pre> 4 300 120 300 105 250 105 250 90 </pre> <h2>出力䟋</h2> <pre> 23 18 23 17 18 22 23 17 18 </pre>
p01141
<!-- begin en only --> <h3><U>Lifeguard in the Pool</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> Horton Moore はプヌルの監芖員ずしお働いおいる圌が芋回りのためにプヌルの瞁を歩いおいたずころプヌルの䞭で䞀人の少女がおがれおいるこずに気づいたもちろん圌は盎ちに救助に向かわなければならないしかも少女の身に䜕かあっおは倧倉であるから少しでも早く少女のもずにたどり着きたい </p> <p> あなたの仕事はプヌルの圢状頂点数が 3〜10 の凞倚角圢地䞊および氎䞭における監芖員の単䜍距離あたりの移動時間そしお監芖員ず少女の初期䜍眮が䞎えられたずきに監芖員が少女のずころに到着するたでにかかる最短の時間を求めるプログラムを曞くこずである </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットの䞊びからなる入力の終わりは 1 ぀の 0 だけを含む行によっお瀺される </p> <p> 各デヌタセットは次の圢匏になっおいる </p> <blockquote> <i>n</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub> ... <i>x</i><sub><i>n</i></sub> <i>y</i><sub><i>n</i></sub><br> <i>tg</i><br> <i>tw</i><br> <i>xs</i> <i>ys</i><br> <i>xt</i> <i>yt</i> </blockquote> <p> それぞれの蚘号の意味は次のずおりである </p> <ul> <li><p><i>n</i> は凞倚角圢をしたプヌルの頂点数を瀺すこれは 3 以䞊 10 以䞋の敎数である</p></li> <li><p>(<i>x</i><sub><i>i</i></sub>, <i>y</i><sub><i>i</i></sub>) はプヌルの <i>i</i> 番目の頂点の座暙を瀺すそれぞれの座暙倀は絶察倀が 100 以䞋の敎数である頂点は反時蚈回りの順番で䞎えられる</p></li> <li><p><i>tg</i> は監芖員が地䞊においお移動するずきにかかる単䜍距離あたりの時間を衚す<i>tw</i> は監芖員が氎䞭においお移動するずきにかかる単䜍距離あたりの時間を衚すこれらはいずれも敎数でありさらに 1 ≩ <i>tg</i> &lt; <i>tw</i> ≩ 100 を満たす</p></li> <li><p>(<i>xs</i>, <i>ys</i>) は監芖員の初期䜍眮の座暙を衚すこの座暙はプヌルのちょうど蟺䞊にある</p></li> <li><p>(<i>xt</i>, <i>yt</i>) は少女の初期䜍眮の座暙を衚すこの座暙はプヌルの内偎にある</p></li> </ul> <p> 同䞀の行にある数倀ず数倀の間は 1 個の空癜で区切られおいる </p> <p> この問題においお監芖員および少女は点であるずみなすたた監芖員がプヌルの蟺に沿っお移動するずきは地䞊を移動しおいるずみなす監芖員は地䞊から氎䞭に䞀瞬で入るこずがたた氎䞭から地䞊に䞀瞬で出るこずができるず仮定しお構わない監芖員が地䞊から氎䞭にあるいは氎䞭から地䞊に移るずき監芖員は同じ座暙にずどたるず考えるこずしたがっおたずえばプヌルの瞁から離れたずころに飛び蟌むこずによっお氎䞭での移動距離を枛らすこずはできない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> 各デヌタセットに察しお監芖員が少女の元に到着するたでにかかる最短の時間を 1 行に出力しなさい解答の誀差は 0.00000001 (10<sup>&minus;8</sup>) を超えおはならない粟床に関する条件を満たしおいれば小数点以䞋は䜕桁数字を出力しおも構わない </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> 4 0 0 10 0 10 10 0 10 10 12 0 5 9 5 4 0 0 10 0 10 10 0 10 10 12 0 0 9 1 4 0 0 10 0 10 10 0 10 10 12 0 1 9 1 8 2 0 4 0 6 2 6 4 4 6 2 6 0 4 0 2 10 12 3 0 3 5 0 </pre> <h3>Output for the Sample Input</h3> <pre> 108.0 96.63324958071081 103.2664991614216 60.0 </pre>
p03486
<span class="lang-en"> <p>Score : <var>200</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. You will create a string <var>s'</var> by freely rearranging the characters in <var>s</var>. You will also create a string <var>t'</var> by freely rearranging the characters in <var>t</var>. Determine whether it is possible to satisfy <var>s' &lt; t'</var> for the lexicographic order.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>For a string <var>a = a_1 a_2 ... a_N</var> of length <var>N</var> and a string <var>b = b_1 b_2 ... b_M</var> of length <var>M</var>, we say <var>a &lt; b</var> for the lexicographic order if either one of the following two conditions holds true:</p> <ul> <li><var>N &lt; M</var> and <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_N = b_N</var>.</li> <li>There exists <var>i</var> (<var>1 \leq i \leq N, M</var>) such that <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_{i - 1} = b_{i - 1}</var> and <var>a_i &lt; b_i</var>. Here, letters are compared using alphabetical order.</li> </ul> <p>For example, <code>xy</code> <var>&lt;</var> <code>xya</code> and <code>atcoder</code> <var>&lt;</var> <code>atlas</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>The lengths of <var>s</var> and <var>t</var> are between <var>1</var> and <var>100</var> (inclusive).</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 it is possible to satisfy <var>s' &lt; t'</var>, print <code>Yes</code>; if it is not, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>yx axy </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>We can, for example, rearrange <code>yx</code> into <code>xy</code> and <code>axy</code> into <code>yxa</code>. Then, <code>xy</code> <var>&lt;</var> <code>yxa</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>ratcode atlas </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre> <p>We can, for example, rearrange <code>ratcode</code> into <code>acdeort</code> and <code>atlas</code> into <code>tslaa</code>. Then, <code>acdeort</code> <var>&lt;</var> <code>tslaa</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>cd abc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre> <p>No matter how we rearrange <code>cd</code> and <code>abc</code>, we cannot achieve our objective.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>w ww </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>zzz zzz </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>No </pre></section> </div> </span>
p01511
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Three-way Branch</H1> <p> There is a grid that consists of <var>W \times H</var> cells. The upper-left-most cell is <var>(1, 1)</var>. You are standing on the cell of <var>(1,1)</var> and you are going to move to cell of <var>(W, H)</var>. You can only move to adjacent lower-left, lower or lower-right cells. </p> <p> There are obstructions on several cells. You can not move to it. You cannot move out the grid, either. Write a program that outputs the number of ways to reach <var>(W,H)</var> modulo 1,000,000,009. You can assume that there is no obstruction at <var>(1,1)</var>. </p> <H2>Input</H2> <p> The first line contains three integers, the width <var>W</var>, the height <var>H</var>, and the number of obstructions <var>N</var>. (<var>1 \leq W \leq 75</var>, <var>2 \leq H \leq 10^{18}</var>, <var>0 \leq N \leq 30</var>) Each of following <var>N</var> lines contains 2 integers, denoting the position of an obstruction <var>(x_i, y_i)</var>. </p> <p> The last test case is followed by a line containing three zeros. </p> <H2>Output</H2> <p> For each test case, print its case number and the number of ways to reach <var>(W,H)</var> modulo 1,000,000,009. </p> <H2>Sample Input</H2> <pre> 2 4 1 2 1 2 2 1 2 2 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 4 Case 2: 0 </pre>
p01004
<h1>Problem F: Ballon Contest</h1> <h2>Problem</h2> <p>空の様子がい぀もず違う。色ずりどりの倚圩な熱気球が空を芆っおいた。今日は熱気球の倧䌚だ。<!--倧䌚の䌚堎に行っおみるず、熱気球を䜿ったレクリ゚ヌションが開催されおいた。-->熱気球から萜ずされた埗点付きボヌルを参加者党員で取り合うらしい。<!--残念ながら申し蟌み期限が切れおしたっおいたが、-->せっかくなので優勝者を予想しおみるこずにした。</p> <ul> <li>レクリ゚ヌションにはN人参加する。</li> <li><var> N </var>人の参加者はそれぞれ自分の䜍眮が䞎えられる。耇数の参加者に同じ䜍眮が䞎えられる事はない。</li> <li>䞊空の熱気球からM個のボヌルが個ず぀萜䞋する。</li> <li>参加者は党員同じタむミングで走り始め、ボヌルに向かっお同じ速床で䞀盎線に走る。</li> <li>ボヌルの萜䞋䜍眮に䞀番早く蟿り着けた人がボヌルを取埗できる。同時に耇数人蟿り着いた堎合は、䞀様な確率で取埗できる人が決たる。</li> <li>参加者がボヌルを取埗するず参加者党員が元の䜍眮に戻る。</li> <li>参加者が走り始めおから参加者の党員が元の䜍眮に戻るたでに別のボヌルが萜䞋する事はない。</li> <li>各ボヌルには埗点ず萜䞋する䜍眮が䞎えられ、ボヌルを取埗するず埗点を埗られる。</li> <li>ボヌルは萜䞋䞭に空気抵抗を受けるため、実際に萜䞋する地点にはズレが発生する。萜䞋予定の䜍眮より最倧でX軞方向に&plusmn;<var>dx </var>、Y軞方向に&plusmn;<var>dy </var>だけ䞀様な確率でズレる。</li> </ul> <p>埗られる埗点の期埅倀を求め、期埅倀の最も倧きい参加者の期埅倀を出力せよ。</p> <h2>Input</h2> <p> 入力は耇数のデヌタセットからなる。<br> 各デヌタセットは以䞋で衚される。<br> </p> <pre> <var>N</var> <var>M</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> . . <var>x<sub>N</sub></var> <var>y<sub>N</sub></var> <var>bx<sub>1</sub></var> <var>by<sub>1</sub></var> <var>dx<sub>1</sub></var> <var>dy<sub>1</sub></var> <var>score<sub>1</sub></var> . . <var>bx<sub>M</sub></var> <var>by<sub>M</sub></var> <var>dx<sub>M</sub></var> <var>dy<sub>M</sub></var> <var>score<sub>M</sub></var> </pre> <p> 1行目には、参加者の人数<var> N </var>、ボヌルの数<var> M </var>が䞎えられる。<br> 2行目から<var> N </var>+1行目たでには、参加者の情報が䞎えられる。<var> x<sub>i</sub> </var>,<var> y<sub>i</sub> </var>は、それぞれ参加者の䜍眮のX座暙・Y座暙である。<br> <var> N </var>+2行目から<var> N </var>+<var> M </var>+1行目たでには、ボヌルの情報が䞎えられる。各ボヌルが実際に萜䞋する地点のX座暙・Y座暙はそれぞれ<var> bx<sub>j</sub> </var>-<var> dx<sub>j</sub> </var>から<var> bx<sub>j</sub> </var>+<var> dx<sub>j</sub> </var>たで、<var> by<sub>j</sub> </var>-<var> dy<sub>j</sub> </var>から<var> by<sub>j</sub> </var>+<var> dy<sub>j</sub> </var>たでの範囲のどこかである。<var> score<sub>j</sub> </var>はボヌルの埗点である。<br> 入力の終わりは2぀のれロからなる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le; <var>N</var> &le; 100</li> <li>1 &le; <var>M</var> &le; 10</li> <li>0 &le; <var>x<sub>i</sub> </var>,<var> y<sub>i</sub> </var>,<var> bx<sub>j</sub> </var>,<var> by<sub>j</sub></var> &le; 10000</li> <li>1 &le; <var>dx<sub>j</sub> </var>,<var> dy<sub>j</sub></var>&le; 10000</li> <li>1 &le; <var>score<sub>j</sub></var> &le; 100</li> <li>テストケヌスの数は 10 を超えない。</li> <li>入力に含たれる倀は党お敎数である。</li> </ul> <h2>Output</h2> <p> 各デヌタセット毎に、答えを䞀行に出力しなさい。<br> 出力は0.0001以䞋の誀差を含んでもよい。<br> </p> <h2>Sample Input</h2> <pre> 3 4 10 75 50 5 90 75 50 50 10 10 2 40 90 1 1 3 10 20 10 15 1 50 70 50 50 4 4 2 25 25 25 75 75 75 75 25 50 50 10 10 1 50 50 15 15 2 1 1 5 5 1 1 1 1 1 0 0 </pre> <h2>Sample Output</h2> <pre> 5.442857 0.750000 1.000000 </pre>
p03039
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid of squares with <var>N</var> rows and <var>M</var> columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left. We will choose <var>K</var> of the squares and put a piece on each of them.</p> <p>If we place the <var>K</var> pieces on squares <var>(x_1, y_1)</var>, <var>(x_2, y_2)</var>, ..., and <var>(x_K, y_K)</var>, the <em>cost</em> of this arrangement is computed as:</p> <p><var>\sum_{i=1}^{K-1} \sum_{j=i+1}^K (|x_i - x_j| + |y_i - y_j|)</var></p> <p>Find the sum of the costs of all possible arrangements of the pieces. Since this value can be tremendous, print it modulo <var>10^9+7</var>.</p> <p>We consider two arrangements of the pieces different if and only if there is a square that contains a piece in one of the arrangements but not in the other.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \times M \leq 2 \times 10^5</var></li> <li><var>2 \leq K \leq N \times M</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the costs of all possible arrangements of the pieces, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>There are six possible arrangements of the pieces, as follows:</p> <ul> <li><var>((1,1),(1,2))</var>, with the cost <var>|1-1|+|1-2| = 1</var></li> <li><var>((1,1),(2,1))</var>, with the cost <var>|1-2|+|1-1| = 1</var></li> <li><var>((1,1),(2,2))</var>, with the cost <var>|1-2|+|1-2| = 2</var></li> <li><var>((1,2),(2,1))</var>, with the cost <var>|1-2|+|2-1| = 2</var></li> <li><var>((1,2),(2,2))</var>, with the cost <var>|1-2|+|2-2| = 1</var></li> <li><var>((2,1),(2,2))</var>, with the cost <var>|2-2|+|1-2| = 1</var></li> </ul> <p>The sum of these costs is <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>87210 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 100 5000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>817260251 </pre> <p>Be sure to print the sum modulo <var>10^9+7</var>.</p></section> </div> </span>
p03193
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the <var>i</var>-th material are <var>A_i \times B_i</var> (<var>A_i</var> vertically and <var>B_i</var> horizontally).</p> <p>Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly <var>H \times W</var>. He is trying to obtain such a plate by choosing one of the <var>N</var> materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a <var>5 \times 3</var> material cannot be used as a <var>3 \times 5</var> plate.</p> <p>Out of the <var>N</var> materials, how many can produce an <var>H \times W</var> plate if properly cut?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>1 \leq H \leq 10^9</var></li> <li><var>1 \leq W \leq 10^9</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>1 \leq B_i \leq 10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>H</var> <var>W</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> <var>:</var> <var>A_N</var> <var>B_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 5 2 10 3 5 2 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Takahashi wants a <var>5 \times 2</var> plate.</p> <ul> <li>The dimensions of the first material are <var>10 \times 3</var>. We can obtain a <var>5 \times 2</var> plate by properly cutting it.</li> <li>The dimensions of the second material are <var>5 \times 2</var>. We can obtain a <var>5 \times 2</var> plate without cutting it.</li> <li>The dimensions of the third material are <var>2 \times 5</var>. We cannot obtain a <var>5 \times 2</var> plate, whatever cuts are made. Note that the material cannot be rotated and used as a <var>5 \times 2</var> plate.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 587586158 185430194 894597290 708587790 680395892 306946994 590262034 785368612 922328576 106880540 847058850 326169610 936315062 193149191 702035777 223363392 11672949 146832978 779291680 334178158 615808191 701464268 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre></section> </div> </span>
p01454
<H1>Problem H: ねこ鍋改造蚈画仮</H1> <p> あなたは、自宅にたくさんのねこを飌っおいる。そんなあなたの日課は、飌っおいるねこが土鍋の䞭 に入っお昌寝しおいる様子通称ねこ鍋を撮圱するこずだ。䜕匹かのねこが、鍋の䞭でいっしょ に䞞くなっお眠る姿は、実に愛くるしい。 </p> <p> それぞれのねこには、「重さ」<i>m<sub>i</sub></i> ず「Cute」<i>c<sub>i</sub></i> が定矩されおいる。Cute ずは、そのねこ1 匹だけを芋たずきの、愛らしさ・あどけなさ・しなやかさ・やわらかさ・ういういしさ、などを総合的に評䟡した数倀であり、倧きければ倧きいほどそのねこは魅力的である。 </p> <p> たた、ねこ鍋に察しおは「UnCute」ずいう数倀が定矩される。これは、ねこ鍋党䜓ずしおのアンバラ ンスさをあらわす倀であり、Cute ずは逆に、小さければ小さいほど、そのねこ鍋はよいねこ鍋であ る。ねこ鍋のUnCute は、䞭にいるねこのCute の最倧倀<i>C<sub>max</sub></i> ず最小倀<i>C<sub>min</sub></i> を甚いお、<i>C<sub>max</sub></i> - <i>C<sub>min</sub></i>ずあらわされる。぀たり、䞭にいるねこがみな同じくらいのCute を持っおいるねこ鍋が、よいねこ鍋である。 </p> <p> ねこ鍋を持ち運ぶずきのこずを考えるず、ねこ鍋の重さ䞭にいるねこの重さの総和は、限界倀 <i>W</i> 以䞋でなければならない。この条件をみたすようにねこ鍋に入っおもらうねこを遞んで、ねこ鍋のUnCute を小さくしたいのだが、いったいどこたで小さくできるのだろうか。 </p> <p>   ずいう問題を解いおすっかり満足した気になっおいたのは、過去の話だ。 </p> <p> この前、あなたが家の倉庫を敎理しおいたら、倉庫の䞭から叀がけた土鍋が芋぀かった。これであな たの家にある土鍋は぀。そう、これからは、デュアルねこ鍋の時代なのだ ただのねこ鍋なども う叀い </p> <p> デュアルねこ鍋では、土鍋<i>A</i> はオスのねこ専甚、もう片方の土鍋B はメスのねこ専甚である。たた、 デュアルねこ鍋のUnCute を定矩するにあたっおは、Cute のアンバランスさだけではなく、぀の ねこ鍋の重さのアンバランスさも考慮に入れる必芁がある。具䜓的には、重いほうのねこ鍋の重さを <i>M<sub>max</sub></i>、軜いほうのねこ鍋の重さを<i>M<sub>min</sub></i> ずおくず぀のねこ鍋の重さが同じずきは<i>M<sub>max</sub></i> = <i>M<sub>min</sub></i>、デュアルねこ鍋のUnCute は、 </p> <center> <p> max{<i>M<sub>max</sub></i> - <i>M<sub>min</sub></i>, <i>C<sub>max</sub></i> - <i>C<sub>min</sub></i>} </p> </center> <p> ずあらわされる。なお、ここでの<i>C<sub>max</sub></i> ず<i>C<sub>min</sub></i> は、ねこ鍋<i>A</i> の䞭たたはねこ鍋<i>B</i> の䞭にいるねこのCute の最倧倀,最小倀である。 </p> <p> ねこ鍋を持ち運ぶずきのこずを考えるず、<i>M<sub>max</sub></i>は、限界倀<i>W</i> 以䞋でなければならない。この条件をみたすようにデュアルねこ鍋に入っおもらうねこを遞んで、デュアルねこ鍋のUnCute を小さくしたいのだが、いったいどこたで小さくできるのだろうか。 </p> <H2>Input</H2> <p> <i>N<sub>A</sub> N<sub>B</sub> W</i><br> <i>m</i><sub><i>A</i>,1</sub> <i>c</i><sub><i>A</i>,1</sub><br> <i>m</i><sub><i>A</i>,2</sub> <i>c</i><sub><i>A</i>,2</sub><br> .<br> .<br> .<br> <i>m</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub> <i>c</i><sub><i>A</i>,<i>N<sub>A</sub></i></sub><br> <i>m</i><sub><i>B</i>,1</sub> <i>c</i><sub><i>B</i>,1</sub><br> <i>m</i><sub><i>B</i>,2</sub> <i>c</i><sub><i>B</i>,2</sub><br> .<br> .<br> .<br> <i>m</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub> <i>c</i><sub><i>B</i>,<i>N<sub>B</sub></i></sub><br> </p> <p> 入力の行目には、敎数<i>N<sub>A</sub></i>1 &le; <i>N<sub>A</sub></i> &le; 500ず敎数<i>N<sub>B</sub></i>1 &le; <i>N<sub>B</sub></i> &le; 500ず敎数<i>W</i>1 &le; <i>W</i> &le; 10,000が、空癜区切りで曞かれおいる。これは、あなたが飌っおいるオスのねこが党郚で<i>N<sub>A</sub></i> 匹、メスのねこが党郚で<i>N<sub>B</sub></i> 匹いるこずをあらわす。<i>W</i> はねこ鍋の重さの限界倀である。 </p> <p> 続く<i>N<sub>A</sub></i> 行には、敎数<i>m</i><sub><i>A</i>,<i>i</i></sub>1 &le; <i>m</i><sub><i>A</i>,<i>i</i></sub> &le; 10,000ず敎数<i>c</i><sub><i>A</i>,<i>i</i></sub>1 &le; <i>c</i><sub><i>A</i>,<i>i</i></sub> &le; 1,000,000,000が、空癜区切りで曞かれおいる。 i 行目に曞かれた敎数<i>m</i><sub><i>A</i>,<i>i</i></sub> ず<i>c</i><sub><i>A</i>,<i>i</i></sub> は、i 番目のオスのねこの重さが<i>m</i><sub><i>A</i>,<i>i</i></sub>、Cute が<i>c</i><sub><i>A</i>,<i>i</i></sub> であるこずをあらわす。 </p> <p> 続く<i>N<sub>B</sub></i> 行には、敎数<i>m</i><sub><i>B</i>,<i>i</i></sub>1 &le; <i>m</i><sub><i>B</i>,<i>i</i></sub> &le; 10,000ず敎数<i>c</i><sub><i>B</i>,<i>i</i></sub>1 &le; <i>c</i><sub><i>B</i>,<i>i</i></sub> &le; 1,000,000,000が、空癜区切りで曞かれおいる。 <i>N<sub>A</sub></i>  i 行目に曞かれた敎数<i>m</i><sub><i>B</i>,<i>i</i></sub> ず<i>c</i><sub><i>B</i>,<i>i</i></sub> は、i 番目のメスのねこの重さが<i>m</i><sub><i>B</i>,<i>i</i></sub>、Cute が<i>c</i><sub><i>B</i>,<i>i</i></sub> であるこずをあらわす。 </p> <p> オスのねこにもメスのねこにも、重さが<i>W</i> 以䞋であるようなねこが、それぞれ匹以䞊は存圚するず仮定しおよい。 </p> <H2>Output</H2> <p> <i>M<sub>max</sub></i> が<i>W</i> を超えないずいう条件のもずで、デュアルねこ鍋のUnCute の最小倀を出力せよ。ただし、どちらのねこ鍋にも匹以䞊のねこが入っおいなければならない。 </p> <h2>Sample Input 1</h2> <pre> 4 3 12 3 6 2 4 7 9 10 1 6 5 8 4 15 19 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 1 3 10 1 15 6 8 5 9 8 7 </pre> <h2>Sample Output 2</h2> <pre> 6 </pre> <h2>Sample Input 3</h2> <pre> 8 6 65 30 98 27 51 4 74 65 87 49 19 27 48 43 7 35 28 43 69 8 47 64 75 18 23 54 29 40 43 </pre> <h2>Sample Output 3</h2> <pre> 8 </pre>
p03469
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On some day in January <var>2018</var>, Takaki is writing a document. The document has a column where the current date is written in <code>yyyy/mm/dd</code> format. For example, January <var>23</var>, <var>2018</var> should be written as <code>2018/01/23</code>.</p> <p>After finishing the document, she noticed that she had mistakenly wrote <code>2017</code> at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, <var>S</var>, is given as input, modifies the first four characters in <var>S</var> to <code>2018</code> and prints it.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> is a string of length <var>10</var>.</li> <li>The first eight characters in <var>S</var> are <code>2017/01/</code>.</li> <li>The last two characters in <var>S</var> are digits and represent an integer between <var>1</var> and <var>31</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Replace the first four characters in <var>S</var> with <code>2018</code> and print it.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2017/01/07 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2018/01/07 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2017/01/31 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2018/01/31 </pre></section> </div> </span>
p02628
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A shop sells <var>N</var> kinds of fruits, Fruit <var>1, \ldots, N</var>, at prices of <var>p_1, \ldots, p_N</var> yen per item, respectively. (Yen is the currency of Japan.)</p> <p>Here, we will choose <var>K</var> kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq N \leq 1000</var></li> <li><var>1 \leq p_i \leq 1000</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>p_1</var> <var>p_2</var> <var>\ldots</var> <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the minimum possible total price of fruits.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 50 100 80 120 80 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>210 </pre> <p>This shop sells Fruit <var>1</var>, <var>2</var>, <var>3</var>, <var>4</var>, and <var>5</var> for <var>50</var> yen, <var>100</var> yen, <var>80</var> yen, <var>120</var> yen, and <var>80</var> yen, respectively.</p> <p>The minimum total price for three kinds of fruits is <var>50 + 80 + 80 = 210</var> yen when choosing Fruit <var>1</var>, <var>3</var>, and <var>5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000 </pre></section> </div> </span>
p00615
<h1><font color="#000000">Problem A:</font> Traffic Analysis</h1> <p> There are two cameras which observe the up line and the down line respectively on the double lane (please see the following figure). These cameras are located on a line perpendicular to the lane, and we call the line 'monitoring line.' (the red line in the figure) </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_trafficAnalysis_en"> </center> <br> <p> Monitoring systems are connected to the cameras respectively. When a car passes through the monitoring line, the corresponding monitoring system records elapsed time (sec) from the start of monitoring. </p> <p> Your task is to write a program which reads records of the two monitoring systems and prints the maximum time interval where cars did not pass through the monitoring line. </p> <p> The two monitoring system start monitoring simultaneously. The end of monitoring is indicated by the latest time in the records. </p> <h2>Input</h2> <p> The input consists of multiple datasets. Each dataset consists of: </p> <pre> <i>n m</i> <i>tl</i><sub>1</sub> <i>tl</i><sub>2</sub> ... <i>tl</i><sub>n</sub> <i>tr</i><sub>1</sub> <i>tr</i><sub>2</sub> ... <i>tr</i><sub>m</sub> </pre> <p> <i>n</i>, <i>m</i> are integers which represent the number of cars passed through monitoring line on the up line and the down line respectively. <i>tl<sub>i</sub></i>, <i>tr<sub>i</sub></i> are integers which denote the elapsed time when <i>i</i>-th car passed through the monitoring line for the up line and the down line respectively. You can assume that <i>tl</i><sub>1</sub> &lt; <i>tl</i><sub>2</sub> &lt; ... &lt; <i>tl</i><sub>n</sub>、 <i>tr</i><sub>1</sub> &lt; <i>tr</i><sub>2</sub> &lt; ... &lt; <i>tr</i><sub>m</sub>. </p> <p> You can also assume that <i>n</i>, <i>m</i> &le; 10000, and 1 &le; <i>tl<sub>i</sub></i>, <i>tr<sub>i</sub></i> &le; 1,000,000. </p> <p> The end of input is indicated by a line including two zero. </p> <h2>Output</h2> <p> For each dataset, print the maximum value in a line. </p> <H2>Sample Input</H2> <pre> 4 5 20 35 60 70 15 30 40 80 90 3 2 10 20 30 42 60 0 1 100 1 1 10 50 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 20 18 100 40 </pre>
p01907
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>C: Fractal Tree</h1> <h2>問題</h2> <p> AORむカちゃんは、フラクタルな(自己盞䌌的な)構造を持぀根付き朚が奜きである。 $N$ 頂点から成る重み付き根付き朚 $T$ を甚いお、以䞋のようなフラクタル構造を持぀根付き朚 $T'$ を衚珟するこずを考える。 </p> <ul> <li>$T'$ は、$T$ の各頂点 $x$ に察しお、$x$ を根ずしお $T$ ず同様の朚構造 (コストも同じ) を持぀朚を付け加えたものである。</li> <li>$T'$の根は $T$ のものず同じものである。</li> </ul> <p> こうしお衚珟される朚は䟋えば䞋図のようになる。 </p> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day1_RUPC2017_FractalTree" width="75%"> </p> <p> AOR むカちゃんは、$T'$ に察しお深さ優先探玢をしようずしおいるが、党おの頂点を蟿るず時間がずおもかかるこずに気づいた。 そこで、深さ優先探玢時の遷移の際に確率 $p$ で遷移し、確率 $1-p$ で遷移しない方針で深さ優先探玢を行い、いく぀かのノヌド蚪問をサボるこずにした。 $T$ ず確率 $p$ が䞎えられるので、$T’$ に察しお深さ優先探玢を行う際に蟿る党おの蟺のコストの和の期埅倀を求めよ。 $T$ の情報は頂点数 $N$ ず $N-1$ 本の蟺の情報で䞎えられ、頂点 $1$ が根である。 各頂点は $1,2,\dots,N$ ずラベリングされおおり、 $i \ (1 \le i \le N-1)$ 番目の蟺は頂点 $x_i$ ず $y_i$ をコスト $c_i$ で結んでいる。 今回の問題で扱う、確率 $p$ で子に遷移する深さ優先探玢の非決定的アルゎリズムは以䞋のように衚珟される。 出力される $\mathrm{answer}$ が蟿る蟺のコストの総和である。 </p> <ol> <li>空のスタック $S$ を甚意する。</li> <li>$\mathrm{answer}=0$ ずする</li> <li>$S$ に $T'$ の根頂点をプッシュする。</li> <li>$S$ の先頭の芁玠を取り出し、これを $x$ ずする。</li> <li>$x$ の各子 $c$ に察し、それぞれ確率 $p$ で次の操䜜を行い、確率 $1-p$ で䜕もしない。 <ul> <li>$S$ に頂点 $c$ を远加する。そしお $\mathrm{answer}$ に $x$ から $c$ に繋がっおいる蟺の重みを加える。</li> </ul> </li> <li>Sが空でなければ、3. に遷移する。</li> <li>$\mathrm{answer}$ を出力する。</li> </ol> <h2>制玄</h2> <ul> <li>$2 \le N \le 10^5$</li> <li>$0 \le p \le 1.0$ (小数点第 2 䜍たで䞎えられる。)</li> <li>$1 \le x_i,y_i \le N$</li> <li>$1 \le c_i \le 1000$</li> <li>$c_i$ は敎数である</li> <li>䞎えられるグラフは $N$ 頂点の根付き朚である。すなわち、頂点 $N$、蟺数 $N-1$、連結ずいう性質を持぀グラフであり、頂点 $1$ が根である。</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <p> $p$<br> $N$<br> $x_1 \ y_1 \ c_1$<br> $\vdots$<br> $x_{N-1} \ y_{N-1} \ c_{N-1}$<br> </p> <h2>出力</h2> <p> 答えを 1 行で出力せよ。盞察誀差たたは絶察誀差が $10^{-6}$ 以䞋なら AC ずなる。たた、末尟に改行も出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力1</h3> <pre> 0.75 4 1 2 1 2 3 3 3 4 10 </pre> <h3>サンプル出力1</h3> <pre> 24.8569335938 </pre> <h3>サンプル入力2</h3> <pre> 0.75 4 1 2 1 1 3 3 3 4 10 </pre> <h3>サンプル出力2</h3> <pre> 35.0390625 </pre> <p> 問題文の図の朚を䞎える䟋である。 </p>
p02782
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is standing on a two-dimensional plane. In one operation, he can move by <var>1</var> in the positive <var>x</var>-direction, or move by <var>1</var> in the positive <var>y</var>-direction.</p> <p>Let us define a function <var>f(r, c)</var> as follows:</p> <ul> <li><var>f(r,c) := </var> (The number of paths from the point <var>(0, 0)</var> to the point <var>(r, c)</var> that Snuke can trace by repeating the operation above)</li> </ul> <p>Given are integers <var>r_1</var>, <var>r_2</var>, <var>c_1</var>, and <var>c_2</var>. Find the sum of <var>f(i, j)</var> over all pair of integers <var>(i, j)</var> such that <var>r_1 ≀ i ≀ r_2</var> and <var>c_1 ≀ j ≀ c_2</var>, and compute this value modulo <var>(10^9+7)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ r_1 ≀ r_2 ≀ 10^6</var></li> <li><var>1 ≀ c_1 ≀ c_2 ≀ 10^6</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>r_1</var> <var>c_1</var> <var>r_2</var> <var>c_2</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of <var>f(i, j)</var> 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 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>14 </pre> <p>For example, there are two paths from the point <var>(0, 0)</var> to the point <var>(1, 1)</var>: <var>(0,0)</var> → <var>(0,1)</var> → <var>(1,1)</var> and <var>(0,0)</var> → <var>(1,0)</var> → <var>(1,1)</var>, so <var>f(1,1)=2</var>.</p> <p>Similarly, <var>f(1,2)=3</var>, <var>f(2,1)=3</var>, and <var>f(2,2)=6</var>. Thus, the sum is <var>14</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>314 159 2653 589 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>602215194 </pre></section> </div> </span>
p03890
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><em>Kode Festival</em> is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for "hardness".)</p> <p>This year, <var>2^N</var> stones participated. The hardness of the <var>i</var>-th stone is <var>A_i</var>.</p> <p>In the contest, stones are thrown at each other in a knockout tournament.</p> <p>When two stones with hardness <var>X</var> and <var>Y</var> are thrown at each other, the following will happen:</p> <ul> <li> <p>When <var>X</var> &gt; <var>Y</var>: The stone with hardness <var>Y</var> will be destroyed and eliminated. The hardness of the stone with hardness <var>X</var> will become <var>X-Y</var>.</p> </li> <li> <p>When <var>X</var> = <var>Y</var>: One of the stones will be destroyed and eliminated. The hardness of the other stone will remain the same.</p> </li> <li> <p>When <var>X</var> &lt; <var>Y</var>: The stone with hardness <var>X</var> will be destroyed and eliminated. The hardness of the stone with hardness <var>Y</var> will become <var>Y-X</var>.</p> </li> </ul> <p>The <var>2^N</var> stones will fight in a knockout tournament as follows:</p> <ol> <li> <p>The following pairs will fight: (the <var>1</var>-st stone versus the <var>2</var>-nd stone), (the <var>3</var>-rd stone versus the <var>4</var>-th stone), ...</p> </li> <li> <p>The following pairs will fight: (the winner of (<var>1</var>-st versus <var>2</var>-nd) versus the winner of (<var>3</var>-rd versus <var>4</var>-th)), (the winner of (<var>5</var>-th versus <var>6</var>-th) versus the winner of (<var>7</var>-th versus <var>8</var>-th)), ...</p> </li> <li> <p>And so forth, until there is only one stone remaining.</p> </li> </ol> <p>Determine the eventual hardness of the last stone remaining.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 18</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>A_i</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> : <var>A_{2^N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the eventual hardness of the last stone remaining.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 3 10 19 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 3 2 4 6 8 100 104 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre></section> </div> </span>
p02278
<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>Minimum Cost Sort</H1> <p> You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times. </p> <p> Write a program which reports the minimal total cost to sort the given integers. </p> <h2>Input</h2> <p> In the first line, an integer $n$ is given. In the second line, $n$ integers $w_i (i = 0, 1, 2, ... n-1)$ separated by space characters are given. </p> <h2>Output</h2> <p> Print the minimal cost in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 1,000$</li> <li>$0 \leq w_i\leq 10^4$</li> <li>$w_i$ are all different</li> </ul> <h2>Sample Input 1</h2> <pre> 5 1 5 3 4 2 </pre> <h2>Sample Output 1</h2> <pre> 7 </pre> <br> <h2>Sample Input 2</h2> <pre> 4 4 3 2 1 </pre> <h2>Sample Output 2</h2> <pre> 10 </pre>
p00245
<H1>タむムセヌル</H1> <p> より良い物を、より安く。今日もどこかのスヌパヌマヌケットで行われるタむムセヌルでは、激しい闘いが繰り広げられおいたす。ここ䌚接にある「LL堂」もそんなスヌパヌマヌケットのひず぀で、他のチェヌン店ず察抗すべく、少し倉わったタむムセヌルを実斜しおいたす。䞀般的なタむムセヌルでは耇数の商品が同じ時間に安くなるものですが、LL堂では察象ずなる商品によっお、タむムセヌルを開始する時間が別々に蚭定されおいたす。 </p> <p> 坂井家はLL堂をよく利甚する家庭の䞀぀です。そんな坂井家では、奥様䞻導のもず、次の日曜に行われるタむムセヌルに向けお䜜戊䌚議を開き、どのような順番で買い物をすれば倀匕きが最倧ずなるかを分析するこずになりたした。店内を熟知しおいる坂井家は売り堎の芋取り図を曞き、たた欲しい品物がどこにあるか、倀匕きは幟らであるか、売り切れるたでの時間を把握するこずに成功したした。 ここたでは完璧だった坂井家ですが、分析を行える人がいたせんでした。そこで坂井家ず芪亀があったあなたはプログラムを曞くこずにしたした。䞀人の人が動くこずを想定しおシミュレヌションを行いたす。 </p> <p> 商品は10皮類あり、数字1桁の商品番号 <var>g</var> によっお 区別されたす。タむムセヌル情報には商品番号 <var>g</var>、 倀匕き額 <var>d</var>、タむムセヌルの開始時刻 <var>s</var> ず売り切れ時刻 <var>e</var> がありたす。 </p> <p> 店内は暪 <var>X</var>、瞊 <var>Y</var> のマスで構成される2次元 グリッドで衚され、マスごずに通路、商品棚の どちらかが割り圓おられおいたす。䞀぀の商品棚には 1皮類の商品があり、それは商品番号 <var>g</var> で区別されたす。 どの商品を買っおもよいですが、同じ商品番号の商品を耇数買っおはいけたせん。商品棚からは、䞊䞋巊右に隣接する通路のマスならどんな向きでも商品を取れたす。 </p> <p> タむムセヌルが始たる時刻から商品を取るこずができたすが、売り切れる時刻からは商品を取るこずができたせん。たた、時間は入店した時点で0から始たりたす。 </p> <p> 移動は珟圚いるマスから䞊䞋巊右の隣接する通路マスに移動するこずができたすが、商品棚のマスに移動するこずはできたせん。グリッドで衚される店の倖に出るこずもできたせん。回移動する毎に単䜍時間経過したす。たた、商品を取る時間は考えないものずしたす。 </p> <p> 店内の芋取り図ず買い物をする人の初期䜍眮ず商品のタむムセヌル情報を入力ずし、取るこずのできた商品の倀匕き額の合蚈の最倧倀を出力するプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 耇数のデヌタセットが䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>X</var> <var>Y</var> <var>m<sub>1,1</sub></var> <var>m<sub>2,1</sub></var> ... <var>m<sub>X,1</sub></var> <var>m<sub>1,2</sub></var> <var>m<sub>2,2</sub></var> ... <var>m<sub>X,2</sub></var> : <var>m<sub>1,Y</sub></var> <var>m<sub>2,Y</sub></var> ... <var>m<sub>X,Y</sub></var> <var>n</var> <var>g<sub>1</sub></var> <var>d<sub>1</sub></var> <var>s<sub>1</sub></var> <var>e<sub>1</sub></var> <var>g<sub>2</sub></var> <var>d<sub>2</sub></var> <var>s<sub>2</sub></var> <var>e<sub>2</sub></var> : <var>g<sub>n</sub></var> <var>d<sub>n</sub></var> <var>s<sub>n</sub></var> <var>e<sub>n</sub></var> </pre> <p> 1行目に店舗の倧きさ<var>X</var>, <var>Y</var> (3 &le; <var>X</var>, <var>Y</var> &le; 20) が䞎えられたす。続く <var>Y</var> 行に <var>i</var> 列目 <var>j</var> 行目の店内情報 <var>m<sub>i,j</sub></var> が以䞋の内容で䞎えられたす。<br> &nbsp;&nbsp;&nbsp;&nbsp;. (ピリオド) 通路のマス<br> &nbsp;&nbsp;&nbsp;&nbsp;数字 商品の番号<br> &nbsp;&nbsp;&nbsp;&nbsp;P 買い物をする人の初期䜍眮のマス<br> </p> <p> 続く行にタむムセヌル情報の数 <var>n</var> (1 &le; <var>n</var> &le; 8) が䞎えられたす。続く <var>n</var> 行に <var>i</var> 番目のタむムセヌル情報 <var>g<sub>i</sub></var> <var>d<sub>i</sub></var> <var>s<sub>i</sub></var> <var>e<sub>i</sub></var> が䞎えられたす(0 &le; <var>g<sub>i</sub></var> &le; 9, 1 &le; <var>d<sub>i</sub></var> &le; 10000, 0 &le; <var>s<sub>i</sub></var>, <var>e<sub>i</sub></var> &le; 100)。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <h2>出力</h2> <p> デヌタセットごずに、取るこずのできる商品の倀匕き額合蚈の最倧倀を行に出力したす。 </p> <h2>入力䟋</h2> <pre> 6 5 1 1 . 0 0 4 1 . . . . . . . 2 2 . . . . 2 2 3 3 P . . . . . 5 0 50 5 10 1 20 0 10 2 10 5 15 3 150 3 5 4 100 8 9 0 0 </pre> <h2>出力䟋</h2> <pre> 180 </pre>
p02556
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> points on the 2D plane, <var>i</var>-th of which is located on <var>(x_i, y_i)</var>. There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?</p> <p>Here, the <em>Manhattan distance</em> between two points <var>(x_i, y_i)</var> and <var>(x_j, y_j)</var> is defined by <var>|x_i-x_j| + |y_i-y_j|</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 x_i,y_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>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_N</var> <var>y_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 1 1 2 4 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The Manhattan distance between the first point and the second point is <var>|1-2|+|1-4|=4</var>, which is maximum possible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre></section> </div> </span>
p00091
<H1>Blur</H1> <p> 図 1 のような 10×10 のマス目の「垃」があり、12のようにX座暙・Y座暙の倀の察でマス目を瀺すこずにしたす。座暙倀は 0 から始たる敎数ずしたす。䟋えば、図 1 の◎の座暙は (1, 2) です。 この「垃」に染料を少しず぀たらしお染物を䜜りたす。たらす染料の滎には「倧」「䞭」「小」の 3 サむズがあり、染料の滎の萜ちたマス目を䞭心に図 1 のように呚囲も色が぀きたす。図 1 で☆が䞭心、○が色のにじむ範囲です。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_19_1"> </center> <br/> <p> 「垃」は、最初は「たっしろ」぀たり、どのマス目も色の濃さを瀺す倀が 0 ずしたす。染料の滎が萜ちるごずに倀が 1 ず぀増えおいきたす。「小」が1, 2、「䞭」が3, 2に萜ちた堎合、各マス目の倀は図 2 の巊のようになりたす。染料がもったいないので、図 2 の右に瀺すようなにじむ範囲が垃の倖にはみ出すような染料の萜ずし方はしないこずになっおいたす。たた、同じ堎所に耇数の染料をたらすこずもありたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_19_2"> </center> <br/> <p> このような䜜業を䜕回か繰り返した結果、垃にすばらしい暡様が浮かび䞊がりたしたが、残念なこずに、うっかり䜜業経過を蚘録し忘れおしたいたした。どうにもさっぱり思い出せたせんが、かろうじお、萜ずした染料の滎数は芚えおいたした。あなたは、すばらしい染物を再珟しなければなりたせん。すばらしい染物のデヌタを読みこんで、どこに、どのような染料をたらしたかを出力するプログラムを䜜成しおください。なお、萜ずした染料の滎数は 12 以䞋ずしたす。 </p> <H2>入力</H2> <p> 入力の圢匏は以䞋のずおりです </p> <p> 最初の 1 行に萜ずした染料の滎数 <var>n</var> が䞎えられたす。次の行から 10 行に各座暙の色の濃さが空癜区切りで䞎えられたす。 </p> <H2>出力</H2> <p> 出力は <var>n</var> 行からなりたす。染料の滎の「倧」を 3、「䞭」を 2、「小」を 1 で衚し、萜ずした染料ごずに、そのX座暙、Y座暙、滎の倧きさを空癜で区切っお1行に出力しおください。 </p> <p> 染料のたらし方はどのような順番で出力しおも良いものずしたす。 </p> <H2>入力䟋1</H2> <pre> 2 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </pre> <H2>出力䟋1</H2> <pre> 3 2 1 8 4 2 </pre> <br/> <H2>入力䟋2</H2> <pre> 6 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 1 1 1 3 1 1 0 0 0 0 1 1 3 1 1 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 </pre> <H2>出力䟋2</H2> <pre> 2 2 3 7 7 3 6 3 2 3 6 2 4 4 1 5 5 1 </pre>
p02106
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Problem I: Tree-Light</h1> <h2>Problem</h2> <p>あなたはツリヌラむトずいうツリヌ状の照明噚具を買っおきた。</p> <p>この照明噚具には<var>n</var>個の接点があり、それぞれ<var>0</var>から<var>n&minus;1</var>たでの番号が぀いおいる。各接点は10段階の明るさを衚珟できる電球ず、電球の状態を切り替えるための装眮で構成されおいる。最初、すべおの接点の電球の明るさは<var>0</var>である。</p> <p>たた、接点ず接点の間にはケヌブル線がある。すべおの接点は<var>n&minus;1</var>本のケヌブル線によっお繋がれおおり、接点<var>0</var>を䞊にしお吊り䞋げられる。ここで、接点<var>i</var>から䞋方向に0本以䞊のケヌブル線を介しお、接点<var>i</var>ず繋がる接点の集合を、接点<var>i</var>を根ずした郚分朚ず呌ぶ。</p> <p>あなたはこの照明噚具に察し、以䞋のいずれかの行動をずる。</p> <ul> <li><var>count(r, x, y)</var>: 接点<var>r</var>を根ずした郚分朚に含たれる接点の電球の䞭で、明るさが<var>x</var>以䞊<var>y</var>以䞋になっおいる電球の数を数える。</li> <li><var>change(r, x, y)</var>: 接点<var>r</var>を根ずした郚分朚に含たれる接点の電球の䞭で、明るさがちょうど<var>x</var>になっおいるすべおの電球の明るさを<var>y</var>に倉曎する。</li> </ul> <p><var>q</var>回の行動が䞎えられるので、<var>count(r, x, y)</var>が䞎えられるたびにその時点での電球の数を出力せよ。</p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>n</var> <var>q</var> <var>u<sub>1</sub></var> <var>v<sub>1</sub></var> <var>u<sub>2</sub></var> <var>v<sub>2</sub></var> ... <var>u<sub>n&minus;1</sub></var> <var>v<sub>n&minus;1</sub></var> <var>t<sub>1</sub></var> <var>r<sub>1</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>t<sub>2</sub></var> <var>r<sub>2</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> ... <var>t<sub>q</sub></var> <var>r<sub>q</sub></var> <var>x<sub>q</sub></var> <var>y<sub>q</sub></var> </pre> <p> 1行目にツリヌラむトを構成する接点の数<var>n</var>、あなたのずる行動の数<var>q</var>が空癜区切りで䞎えられる。<br> 続く<var>n&minus;1</var>行にはケヌブル線の情報が空癜区切りで䞎えられる。<var>i</var>番目のケヌブル線の情報は、ケヌブル線<var>i</var>が接点<var>u<sub>i</sub></var>を䞊にしお、接点<var>u<sub>i</sub></var>ず接点<var>v<sub>i</sub></var>を繋ぐこずを衚す。<br> <var>n&plus;1</var>行目以降の<var>q</var>行にはあなたのずる行動が空癜区切りで䞎えられる。<var>t<sub>i</sub> = 1</var>なら<var>count(r<sub>i</sub>, x<sub>i</sub>, y<sub>i</sub>)</var>を、<var>t<sub>i</sub> = 2</var>なら<var>change(r<sub>i</sub>, x<sub>i</sub>, y<sub>i</sub>)</var>を衚す。 </p> <h2>Constraints</h2> <ul> <li><var>1 &le; n &le; 10<sup>5</sup></var></li> <li><var>1 &le; q &le; 10<sup>5</sup></var></li> <li><var>0 &le; u<sub>i</sub>, v<sub>i</sub>, r<sub>i</sub> &le; n&minus;1 (u<sub>i</sub> ≠ v<sub>i</sub>)</var></li> <li><var>0 &le; x<sub>i</sub>, y<sub>i</sub> &le; 9 (t<sub>i</sub> = 1</var>の時<var>x<sub>i</sub> &le; y<sub>i</sub>)</var></li> </ul> <h2>Output</h2> <p>各<var>count(r<sub>i</sub>, x<sub>i</sub>, y<sub>i</sub>)</var>に぀いお、その答えを1行に出力する。</p> <h2>Sample Input 1</h2> <pre> 7 5 0 1 1 2 1 3 0 4 4 5 4 6 1 0 0 9 2 0 0 5 2 1 5 8 1 0 5 8 1 0 8 8 </pre> <h2>Sample Output 1</h2> <pre> 7 7 3 </pre> <h2>Sample Input 2</h2> <pre> 7 5 0 1 1 2 2 3 0 4 4 5 5 6 2 1 0 5 2 4 0 6 2 3 5 6 2 5 6 5 1 0 0 5 </pre> <h2>Sample Output 2</h2> <pre> 5 </pre>
p03347
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a sequence <var>X</var> of length <var>N</var>, where every element is initially <var>0</var>. Let <var>X_i</var> denote the <var>i</var>-th element of <var>X</var>.</p> <p>You are given a sequence <var>A</var> of length <var>N</var>. The <var>i</var>-th element of <var>A</var> is <var>A_i</var>. Determine if we can make <var>X</var> equal to <var>A</var> by repeating the operation below. If we can, find the minimum number of operations required.</p> <ul> <li>Choose an integer <var>i</var> such that <var>1\leq i\leq N-1</var>. Replace the value of <var>X_{i+1}</var> with the value of <var>X_i</var> plus <var>1</var>.</li> </ul> </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(1\leq i\leq N)</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>:</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If we can make <var>X</var> equal to <var>A</var> by repeating the operation, print the minimum number of operations required. If we cannot, print <var>-1</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 0 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>We can make <var>X</var> equal to <var>A</var> as follows:</p> <ul> <li>Choose <var>i=2</var>. <var>X</var> becomes <var>(0,0,1,0)</var>.</li> <li>Choose <var>i=1</var>. <var>X</var> becomes <var>(0,1,1,0)</var>.</li> <li>Choose <var>i=3</var>. <var>X</var> becomes <var>(0,1,1,2)</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 0 1 1 0 1 2 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>8 </pre></section> </div> </span>
p00992
<h1>Problem C : War</h1> <p> A囜ずB囜ずいう぀の囜が戊争をしおいる。A囜の軍人であるあなたは<i>n</i>人の兵士を率いお、B囜の領土を占領する事になった。 </p> <p> B囜の領土は次元グリッドで衚されおいる。あなたが最初に占領する堎所は二次元グリッド䞊のあるマスである。 あなたが率いおいる兵士たちは、それぞれh_iの䜓力を持っおいる。 それぞれの兵士は䜓力を1を消費しお移動するこずができる。 珟圚いるマスを(a,b)ずするず、(a+1,b),(a-1,b),(a,b+1),(a,b-1)の4方向を移動先ずしお遞ぶこずが可胜である。 兵士は䜓力が0になったらそこから動くこずができなくなる。 䞀人以䞊の兵士が通過したマスはすべお占領するこずができる。 </p> <p> あなたの仕事は、最倧でいく぀のマスを占領するこずができるかを求めるこずである。<br> ただし、この次元グリッドのサむズは無限に広いずするこず。<br> </p> <h2>Input</h2> <p> 入力は以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>n</i> <i>h<sub>1</sub></i> . . . <i>h<sub>n</sub></i> </pre> <p> 入力は以䞋の制玄を満たす<br> 1 &le; <i>n</i> &le; 500<br> 1 &le; <i>h<sub>i</sub></i> &le; 10,000,000<br> </p> <h2>Output</h2> <p> 答えの倀を行に出力せよ </p> <h2>Sample Input 1</h2> <pre> 2 5 5 </pre> <h2>Sample Output 1</h2> <pre> 11 </pre> <h2>Sample Input 2</h2> <pre> 10 10 10 10 10 10 10 10 10 10 10 </pre> <h2>Sample Output 2</h2> <pre> 93 </pre> <h2>Sample Input 3</h2> <pre> 5 1 2 3 4 5 </pre> <h2>Sample Output 3</h2> <pre> 15 </pre>
p01680
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>Problem Statement</h3> <p>&quot;Everlasting -One-&quot; is an award-winning online game launched this year. This game has rapidly become famous for its large number of characters you can play. </p> <p>In this game, a character is characterized by <i>attributes</i>. There are $N$ attributes in this game, numbered $1$ through $N$. Each attribute takes one of the two states, <i>light</i> or <i>darkness</i>. It means there are $2^N$ kinds of characters in this game. </p> <p>You can change your character by job change. Although this is the only way to change your character's attributes, it is allowed to change jobs as many times as you want. </p> <p>The rule of job change is a bit complex. It is possible to change a character from $A$ to $B$ if and only if there exist two attributes $a$ and $b$ such that they satisfy the following four conditions: </p> <ul><li><p> The state of attribute $a$ of character $A$ is <i>light</i>. </p></li><li><p> The state of attribute $b$ of character $B$ is <i>light</i>. </p></li><li><p> There exists no attribute $c$ such that both characters $A$ and $B$ have the <i>light</i> state of attribute $c$. </p></li><li><p> A pair of attribute $(a, b)$ is <i>compatible</i>. </p></li></ul> <p>Here, we say a pair of attribute $(a, b)$ is <i>compatible</i> if there exists a sequence of attributes $c_1, c_2, \ldots, c_n$ satisfying the following three conditions: </p> <ul><li><p> $c_1 = a$. </p></li><li><p> $c_n = b$. </p></li><li><p> Either $(c_i, c_{i+1})$ or $(c_{i+1}, c_i)$ is a special pair for all $i = 1, 2, \ldots, n-1$. You will be given the list of special pairs. </p></li></ul> <p>Since you love this game with enthusiasm, you are trying to play the game with all characters (it's really crazy). However, you have immediately noticed that one character can be changed to a limited set of characters with this game's job change rule. We say character $A$ and $B$ are <i>essentially different</i> if you cannot change character $A$ into character $B$ by repeating job changes. </p> <p>Then, the following natural question arises; how many essentially different characters are there? Since the output may be very large, you should calculate the answer modulo $1{,}000{,}000{,}007$. </p> <h3>Input</h3> <p>The input is a sequence of datasets. The number of datasets is not more than $50$ and the total size of input is less than $5$ MB. </p> <p>Each dataset is formatted as follows. </p><blockquote>$N$ $M$<br>$a_1$ $b_1$<br>:<br>:<br>$a_M$ $b_M$</blockquote> <p>The first line of each dataset contains two integers $N$ and $M$ ($1 \le N \le 10^5$ and $0 \le M \le 10^5$). Then $M$ lines follow. The $i$-th line contains two integers $a_i$ and $b_i$ ($1 \le a_i \lt b_i \le N$) which denote the $i$-th special pair. The input is terminated by two zeroes. </p> <p>It is guaranteed that $(a_i, b_i) \ne (a_j, b_j)$ if $i \ne j$. </p> <h3>Output</h3> <p>For each dataset, output the number of essentially different characters modulo $1{,}000{,}000{,}007$. </p> <h3>Sample Input</h3> <pre>3 2 1 2 2 3 5 0 100000 0 0 0</pre> <h3>Output for the Sample Input</h3> <pre>3 32 607723520</pre>
p00838
<H1><font color="#000">Problem C:</font> Colored Cubes</H1> <p> There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same. </p> <p> Two cubes are said to be <i>identically</i> colored if some suitable rotations of one of the cubes give identical looks to both of the cubes. For example, two cubes shown in Figure 2 are identically colored. A set of cubes is said to be identically colored if every pair of them are identically colored. </p> <p> A cube and its mirror image are not necessarily identically colored. For example, two cubes shown in Figure 3 are not identically colored. </p> <p> You can make a given set of cubes identically colored by repainting some of the faces, whatever colors the faces may have. In Figure 4, repainting four faces makes the three cubes identically colored and repainting fewer faces will never do. </p> <p> Your task is to write a program to calculate the minimum number of faces that needs to be repainted for a given set of cubes to become identically colored. </p> <H2>Input</H2> <p> The input is a sequence of datasets. A dataset consists of a header and a body appearing in this order. A header is a line containing one positive integer n and the body following it consists of <i>n</i> lines. You can assume that 1 &le; <i>n</i> &le; 4. Each line in a body contains six color names separated by a space. A color name consists of a word or words connected with a hyphen (-). A word consists of one or more lowercase letters. You can assume that a color name is at most 24-characters long including hyphens. </p> <p> A dataset corresponds to a set of colored cubes. The integer n corresponds to the number of cubes. Each line of the body corresponds to a cube and describes the colors of its faces. Color names in a line is ordered in accordance with the numbering of faces shown in Figure 5. A line </p> <pre> <i>color</i><sub>1</sub> <i>color</i><sub>2</sub> <i>color</i><sub>3</sub> <i>color</i><sub>4</sub> <i>color</i><sub>5</sub> <i>color</i><sub>6</sub> </pre <p> corresponds to a cube colored as shown in Figure 6. </p> <p> The end of the input is indicated by a line containing a single zero. It is not a dataset nor a part of a dataset. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_coloredCube23"><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_coloredCube4"><br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_coloredCube56"><br> </center> <H2>Output</H2> <p> For each dataset, output a line containing the minimum number of faces that need to be repainted to make the set of cubes identically colored. </p> <H2>Sample Input</H2> <pre> 3 scarlet green blue yellow magenta cyan blue pink green magenta cyan lemon purple red blue yellow cyan green 2 red green blue yellow magenta cyan cyan green blue yellow magenta red 2 red green gray gray magenta cyan cyan green gray gray magenta red 2 red green blue yellow magenta cyan magenta red blue yellow cyan green 3 red green blue yellow magenta cyan cyan green blue yellow magenta red magenta red blue yellow cyan green 3 blue green green green green blue green blue blue green green green green green green green green sea-green 3 red yellow red yellow red yellow red red yellow yellow red yellow red red red red red red 4 violet violet salmon salmon salmon salmon violet salmon salmon salmon salmon violet violet violet salmon salmon violet violet violet violet violet violet salmon salmon 1 red green blue yellow magenta cyan 4 magenta pink red scarlet vermilion wine-red aquamarine blue cyan indigo sky-blue turquoise-blue blond cream chrome-yellow lemon olive yellow chrome-green emerald-green green olive vilidian sky-blue 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4 2 0 0 2 3 4 4 0 16 </pre>
p02805
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are <var>N</var> points <var>(x_i, y_i)</var> in a two-dimensional plane.</p> <p>Find the minimum radius of a circle such that all the points are inside or on it.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 50</var></li> <li><var>0 \leq x_i \leq 1000</var></li> <li><var>0 \leq y_i \leq 1000</var></li> <li>The given <var>N</var> points are all different.</li> <li>The values in input are all integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum radius of a circle such that all the <var>N</var> points are inside or on it.</p> <p>Your output will be considered correct if the absolute or relative error from our answer is at most <var>10^{-6}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 0 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0.500000000000000000 </pre> <p>Both points are contained in the circle centered at <var>(0.5,0)</var> with a radius of <var>0.5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 0 0 0 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0.707106781186497524 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 9 5 9 2 0 0 0 2 7 3 3 2 5 10 0 3 7 1 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6.726812023536805158 </pre> <p>If the absolute or relative error from our answer is at most <var>10^{-6}</var>, the output will be considered correct.</p></section> </div> </span>
p03717
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> squares arranged in a row. The squares are numbered <var>1</var>, <var>2</var>, <var>...</var>, <var>N</var>, from left to right.</p> <p>Snuke is painting each square in red, green or blue. According to his aesthetic sense, the following <var>M</var> conditions must all be satisfied. The <var>i</var>-th condition is:</p> <ul> <li>There are exactly <var>x_i</var> different colors among squares <var>l_i</var>, <var>l_i + 1</var>, <var>...</var>, <var>r_i</var>.</li> </ul> <p>In how many ways can the squares be painted to satisfy all the conditions? Find the count modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 300</var></li> <li><var>1 ≀ M ≀ 300</var></li> <li><var>1 ≀ l_i ≀ r_i ≀ N</var></li> <li><var>1 ≀ x_i ≀ 3</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>l_1</var> <var>r_1</var> <var>x_1</var> <var>l_2</var> <var>r_2</var> <var>x_2</var> <var>:</var> <var>l_M</var> <var>r_M</var> <var>x_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to paint the squares to satisfy all the conditions, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>The six ways are:</p> <ul> <li>RGB</li> <li>RBG</li> <li>GRB</li> <li>GBR</li> <li>BRG</li> <li>BGR</li> </ul> <p>where R, G and B correspond to red, green and blue squares, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 1 3 1 2 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>6 </pre> <p>The six ways are:</p> <ul> <li>RRRG</li> <li>RRRB</li> <li>GGGR</li> <li>GGGB</li> <li>BBBR</li> <li>BBBG</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 3 1 1 1 1 1 2 1 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>There are zero ways.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 10 2 6 2 5 5 1 3 5 2 4 7 3 4 4 1 2 3 1 7 7 1 1 5 2 1 7 3 3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>108 </pre></section> </div> </span>
p03202
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, <var>S_1&lt;S_2&lt;...&lt;S_N</var> holds lexicographically, where <var>S_i</var> is the <var>i</var>-th string from the left.</p> <p>At least how many different characters are contained in <var>S_1,S_2,...,S_N</var>, if the length of <var>S_i</var> is known to be <var>A_i</var>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2\times 10^5</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>A_i</var> is an integer.</li> </ul> </section> </div> <div class="part"> <section> <h3>Note</h3><p>The strings do not necessarily consist of English alphabet; there can be arbitrarily many different characters (and the lexicographic order is defined for those characters).</p> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible number of different characters contained in the strings.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The number of different characters contained in <var>S_1,S_2,...,S_N</var> would be <var>3</var> when, for example, <var>S_1=</var><code>abc</code>, <var>S_2=</var><code>bb</code> and <var>S_3=</var><code>c</code>.</p> <p>However, if we choose the strings properly, the number of different characters can be <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 3 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre></section> </div> </span>
p01395
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1><font color="#000">問題 H </font>あばれうなぎ</h1> <h2>問題文</h2> <p>き぀ねのしえるはうなぎを食べるのが奜きである</p> <p><var>2T+1</var> 枚の鉄板が連続しお䞊んでおり順番に <var>-T, -T+1, ..., T</var> の番号が付いおいるしえるはこれらの鉄板に熱を加え生きたうなぎを焌こうずしおいるうなぎを焌く手順は以䞋のようなものである</p> <ul> <li>たず時刻 <var>t=-1</var> のずきに各鉄板にどれだけの゚ネルギヌを加えるかを決め実際に゚ネルギヌを加える各鉄板に加える゚ネルギヌの総和は <var>E</var> 以䞋でなければならないすなわち<var>i</var> 番の鉄板に加える゚ネルギヌを <var>E(i)</var> ずしお<var>E(i) &ge; 0, E(-T)+...+E(T) &le; E</var> でなければならないなお゚ネルギヌは敎数でなくおもよい</li> <li>゚ネルギヌを加えたあず鉄板の熱さは <var>E(i) / C(i)</var> になるここで<var>C(i)</var> は <var>i</var> 番の鉄板の比熱である</li> <li><var>t = -0.5</var> のずきにうなぎを <var>0</var> 番の鉄板に茉せる</li> <li><var>t = 0, 1, 2,..., T</var> のずきにうなぎは今自分がいる鉄板の熱さだけ加熱される</li> <li><var>t = 0.5, 1.5, 2.5,...,T-0.5</var> のずきうなぎは自分の今いる鉄板にずどたるか䞡隣の鉄板に移動するこずができる</li> <li><var>t = T+0.5</var> のずきにうなぎを鉄板の䞊から回収する</li> </ul> <p>ずころで生きたうなぎずいうのはずおも掻きがよくさらに頭も良いのでもしかするず自分にかかる熱さの総和が最小になるように動いたりするんではないかずしえるは䞍安になったそうなるず鉄板に適圓に熱を加えただけではうなぎを十分に加熱できない恐れさえある</p> <p>そこであなたにはうなぎが垞に最適に動くずしおうなぎに䞎えるこずのできる熱さの和の最倧倀を求めお欲しい</p> <h2>入力圢匏</h2> <p>入力は以䞋の圢匏で䞎えられる</p> <pre><var>T</var> <var>E</var> <var>C(-T)</var> <var>C(-T+1)</var> ... <var>C(T)</var> </pre> <var>T</var> はうなぎを熱する時間<var>E</var> は鉄板に䞎えるこずの出来る゚ネルギヌの総和<var>C(i)</var> は <var>i</var> 番の鉄板の比熱である <h2>出力圢匏</h2> <p><var>1</var> 行目にうなぎに䞎えられる熱さの和の最倧倀を出力せよ小数点以䞋䜕桁でも出力しお構わないが盞察誀差あるいは絶察誀差が <var>10<sup>-6</sup></var> 未満になっおいなければならない</p> <h2>制玄</h2> <ul> <li><var>1 &le; T &le; 10<sup>5</sup></var></li> <li><var>1 &le; E &le; 10<sup>5</sup></var></li> <li><var>1 &le; C(i) &le; 10<sup>5</sup></var></li> <li>入力に含たれる倀はすべお敎数である</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 1 100 1 1 1 </pre> <h3>出力䟋 1</h3> <pre> 100.0 </pre> <p>この堎合は <var>0</var> 番の鉄板に゚ネルギヌを党お加えるのが最適である</p> <h3>入力䟋 2</h3> <pre> 2 100 1 2 100 2 1 </pre> <h3>出力䟋 2</h3> <pre> 2.8301886792453 </pre> <h3>入力䟋 3</h3> <pre> 5 100000 99999 99999 99999 1 1000 1000 1000 1 99999 99999 99999 </pre> <h3>出力䟋 3</h3> <pre> 199.4680851063830 </pre> <h2>謝蟞</h2> この問題は Writer の二人がむンド料理 RAJU 癟䞇遍店ずマクドナルド癟䞇遍店においお倏の暑さに蟟易する䞭で䜜られた
p02940
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>3N</var> colored balls with IDs from <var>1</var> to <var>3N</var>. A string <var>S</var> of length <var>3N</var> represents the colors of the balls. The color of Ball <var>i</var> is red if <var>S_i</var> is <code>R</code>, green if <var>S_i</var> is <code>G</code>, and blue if <var>S_i</var> is <code>B</code>. There are <var>N</var> red balls, <var>N</var> green balls, and <var>N</var> blue balls.</p> <p>Takahashi will distribute these <var>3N</var> balls to <var>N</var> people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition:</p> <ul> <li>Let <var>a_j &lt; b_j &lt; c_j</var> be the IDs of the balls received by the <var>j</var>-th person in ascending order.</li> <li>Then, <var>\sum_j (c_j-a_j)</var> should be as small as possible.</li> </ul> <p>Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo <var>998244353</var>. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>|S|=3N</var></li> <li><var>S</var> consists of <code>R</code>, <code>G</code>, and <code>B</code>, and each of these characters occurs <var>N</var> times 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>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways in which Takahashi can distribute the balls, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 RRRGGGBBB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>216 </pre> <p>The minimum value of <var>\sum_j (c_j-a_j)</var> is <var>18</var> when the balls are, for example, distributed as follows:</p> <ul> <li>The first person gets Ball <var>1</var>, <var>5</var>, and <var>9</var>.</li> <li>The second person gets Ball <var>2</var>, <var>4</var>, and <var>8</var>.</li> <li>The third person gets Ball <var>3</var>, <var>6</var>, and <var>7</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 BBRGRRGRGGRBBGB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>960 </pre></section> </div> </span>
p03652
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is hosting an sports meet. There are <var>N</var> people who will participate. These people are conveniently numbered <var>1</var> through <var>N</var>. Also, there are <var>M</var> options of sports for this event. These sports are numbered <var>1</var> through <var>M</var>. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.</p> <p>Takahashi knows that Person <var>i</var>'s <var>j</var>-th favorite sport is Sport <var>A_{ij}</var>. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.</p> <p>Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 300</var></li> <li><var>1 \leq M \leq 300</var></li> <li><var>A_{i1}</var> , <var>A_{i2}</var> , <var>...</var> , <var>A_{iM}</var> is a permutation of the integers from <var>1</var> to <var>M</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>A_{11}</var> <var>A_{12}</var> <var>...</var> <var>A_{1M}</var> <var>A_{21}</var> <var>A_{22}</var> <var>...</var> <var>A_{2M}</var> <var>:</var> <var>A_{N1}</var> <var>A_{N2}</var> <var>...</var> <var>A_{NM}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible number of the participants in the sport with the largest number of participants.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 5 1 3 4 2 2 5 3 1 4 2 3 1 4 5 2 5 4 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Assume that Sports <var>1</var>, <var>3</var> and <var>4</var> are selected to be played. In this case, Person <var>1</var> will participate in Sport <var>1</var>, Person <var>2</var> in Sport <var>3</var>, Person <var>3</var> in Sport <var>3</var> and Person <var>4</var> in Sport <var>4</var>. Here, the sport with the largest number of participants is Sport <var>3</var>, with two participants. There is no way to reduce the number of participants in the sport with the largest number of participants to <var>1</var>. Therefore, the answer is <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 2 1 3 2 1 3 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> <p>Since all the people have the same taste in sports, there will be a sport with three participants, no matter what sports are selected. Therefore, the answer is <var>3</var>.</p></section> </div> </span>
p02413
<H1>Spreadsheet</H1><br> <p> Your task is to perform a simple table calculation. </p> <p> Write a program which reads the number of rows <var>r</var>, columns <var>c</var> and a table of <var>r</var> &times; <var>c</var> elements, and prints a new table, which includes the total sum for each row and column. </p> <H2>Input</H2> <p> In the first line, two integers <var>r</var> and <var>c</var> are given. Next, the table is given by <var>r</var> lines, each of which consists of <var>c</var> integers separated by space characters. </p> <H2>Output</H2> <p> Print the new table of (<var>r</var>+1) &times; (<var>c</var>+1) elements. Put a single space character between adjacent elements. For each row, print the sum of it's elements in the last column. For each column, print the sum of it's elements in the last row. Print the total sum of the elements at the bottom right corner of the table. </p> <H2>Constraints</H2> <ul> <li> 1 &le; <var>r</var>, <var>c</var> &le; 100</li> <li> 0 &le; an element of the table &le; 100</li> </ul> <H2>Sample Input</H2> <pre> 4 5 1 1 3 4 5 2 2 2 4 5 3 3 0 1 1 2 3 4 4 6 </pre> <H2>Sample Output</H2> <pre> 1 1 3 4 5 14 2 2 2 4 5 15 3 3 0 1 1 8 2 3 4 4 6 19 8 9 9 13 17 56 </pre>
p00584
<h1>コむン集め(Coin Collecting)</h1> <p> JOI 氏のコレクションルヌムには非垞に倧きな机がありその䞊には䜕枚もの貎重なコむンがある机の掃陀をするためにJOI 氏はコむンを敎理しお䞊べるこずにした </p> <p> 机は2 000 000 001 $\times$ 2 000 000 001 のマス目になっおいる列には巊から順に-1 000 000 000 から1 000 000 000たでの番号が぀けられおおり行には䞋から順に-1 000 000 000 から1 000 000 000 たでの番号が぀けられおいる列の番号が$x$行の番号が$y$ であるマスを($x, y$) で衚すこずにする </p> <p> コむンは$2N$ 枚あり珟圚$i$ 番目($1 \leq i \leq 2N$) のコむンはマス($X_i, Y_i$) に眮かれおいるJOI 氏の目暙は$1 \leq x \leq N$ か぀$1 \leq y \leq 2$ を満たす($x, y$) で衚される$2N$ 個のマスにそれぞれコむンが1 枚ず぀眮かれおいる状態にするこずであるコむンを傷぀けないようにするため「コむンを1 枚遞びそれが眮かれおいるマスず蟺で隣り合ったマスのいずれかにそのコむンを移動させる」ずいう操䜜のみができる途䞭耇数のコむンが同じマスに眮かれおいおもよいJOI 氏はできるだけ少ない回数の操䜜で目暙を達成したい </p> <p> コむンの枚数ず珟圚コむンが眮かれおいるマスが䞎えられたずき目暙を達成するために必芁な操䜜回数の最小倀を求めるプログラムを䜜成せよ </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で暙準入力から䞎えられる </p> <pre> $N$ $X_1$ $Y_1$ : $X_{2N}$ $Y_{2N}$ </pre> <h2>出力</h2> <p> 暙準出力に目暙を達成するために必芁な操䜜回数の最小倀を1 行で出力せよ </p> <h2>制玄</h2> <ul> <li>$ 1 \leq N \leq 100 000$</li> <li>$ -1 000 000 000 \leq X_i \leq 1 000 000 000 (1 \leq i \leq 2N)$</li> <li>$ -1 000 000 000 \leq Y_i \leq 1 000 000 000 (1 \leq i \leq 2N)$</li> </ul> <!-- 小課題 1. (8 点) N ≩ 10 2. (29 点) N ≩ 1 000 3. (63 点) 远加の制玄はない --> <h2>入出力䟋</h2> <h3>入力䟋1</h3> <pre> 3 0 0 0 4 4 0 2 1 2 5 -1 1 </pre> <h3> 出力䟋1</h3> <pre> 15 </pre> <p> この入力䟋では6 個のコむンが䞋図のように眮かれおいる倪枠で瀺した䜍眮にコむンを集めるのが目暙である </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/joi2018_ho_t4_00"> <p> 䟋えばコむンを以䞋のように移動させるず15 回の操䜜で目暙を達成できる </p> <ul> <li> 1 番目のコむン(0, 0) → (1, 0) → (1, 1) → (1, 2)</li> <li> 2 番目のコむン(0, 4) → (1, 4) → (1, 3) → (2, 3) → (3, 3) → (3, 2)</li> <li> 3 番目のコむン(4, 0) → (4, 1) → (3, 1)</li> <li> 5 番目のコむン(2, 5) → (2, 4) → (2, 3) → (2, 2)</li> <li> 6 番目のコむン(-1, 1) → (0, 1) → (1, 1)</li> </ul> <p> 14 回以䞋の操䜜で目暙を達成するこずはできないので15 を出力する </p> <h3>入力䟋2</h3> <pre> 4 2 1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 </pre> <h3>出力䟋2</h3> <pre> 9 </pre> <p> 同じマスに耇数のコむンが眮かれおいるかもしれない </p> <h3>入力䟋3</h3> <pre> 5 1000000000 1000000000 -1000000000 1000000000 -1000000000 -1000000000 1000000000 -1000000000 -1 -5 -2 2 2 8 4 7 -2 5 7 3 </pre> <h3>出力䟋3</h3> <pre> 8000000029 </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>
p02043
<h1>G: むルミネヌション</h1> <h2>問題</h2> <p> $1 \leq x \leq h , 1 \leq y \leq w$ をみたす栌子点 $(x,y)$ に電球がある. </p> <p> 電源装眮は座暙 $(i+0.5,j+0.5) (1 \leq i < h,1 \leq j < w, i+j$ は偶数に蚭眮されおいる(14:21修正). 座暙 $(i+0.5,j+0.5)$ に蚭眮されおいる電源装眮をオンにするず, 座暙 $(i,j),(i+1,j),(i,j+1),(i+1,j+1)$ に存圚する $4$ ぀の電球が光る. </p> <p> $(i,j)$ にある電球がオンになっおいる電源装眮に $1$ ぀以䞊぀ながっおいるず, きれいさ $B_{i,j}$ を埗られる. あなたは, きれいさの合蚈分の収入がもらえる. たた, それぞれの電源装眮をオンにするず, $1$ ぀あたり電気代が $W$ かかる. </p> <p> いく぀かの電源をオンにしお「収入の合蚈 - 電気代の合蚈」を最倧化しなさい. </p> <h2>制玄</h2> <ul> <li>$2 \leq h, w \leq 50$ </li> <li>$0 \leq B_{i,j},W \leq 10^9$ </li> <li>$h,w$ は偶数</li> <li>入力はすべお敎数</li> </ul> <h2>入力圢匏</h2> <p> 入力は以䞋の圢匏で䞎えられる. </p> <p> $h\ w \ W$<br> $B_{1,1} \dots B_{1,w}$<br> $\vdots$<br> $B_{h,1} \dots B_{h,w}$<br> </p> <h2>出力</h2> <p>「収入の合蚈 - 電気代の合蚈」の最倧倀を出力せよ. たた, 末尟に改行も出力せよ. </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 4 4 10 100 100 100 100 100 100 100 100 1 100 100 1 1 1 1 1 </pre> <h3>サンプル出力 1</h3> <pre> 970 </pre> <br> <p> 以䞋のように $@$ の䜍眮の電源をオンにし, $X$ の䜍眮の電源をオフにするのが最善である. </p> <pre> 100 100 100 100 @ @ 100 100 100 100 @ 1 100 100 1 X X 1 1 1 1 </pre>
p03081
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There are <var>N</var> squares numbered <var>1</var> to <var>N</var> from left to right. Each square has a character written on it, and Square <var>i</var> has a letter <var>s_i</var>. Besides, there is initially one golem on each square.</p> <p>Snuke cast <var>Q</var> spells to move the golems.</p> <p>The <var>i</var>-th spell consisted of two characters <var>t_i</var> and <var>d_i</var>, where <var>d_i</var> is <code>L</code> or <code>R</code>. When Snuke cast this spell, for each square with the character <var>t_i</var>, all golems on that square moved to the square adjacent to the left if <var>d_i</var> is <code>L</code>, and moved to the square adjacent to the right if <var>d_i</var> is <code>R</code>.</p> <p>However, when a golem tried to move left from Square <var>1</var> or move right from Square <var>N</var>, it disappeared.</p> <p>Find the number of golems remaining after Snuke cast the <var>Q</var> spells.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,Q \leq 2 \times 10^{5}</var></li> <li><var>|s| = N</var></li> <li><var>s_i</var> and <var>t_i</var> are uppercase English letters.</li> <li><var>d_i</var> is <code>L</code> or <code>R</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>s</var> <var>t_1</var> <var>d_1</var> <var>\vdots</var> <var>t_{Q}</var> <var>d_Q</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 4 ABC A L B L B R A R </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <ul> <li>Initially, there is one golem on each square.</li> <li>In the first spell, the golem on Square <var>1</var> tries to move left and disappears.</li> <li>In the second spell, the golem on Square <var>2</var> moves left.</li> <li>In the third spell, no golem moves.</li> <li>In the fourth spell, the golem on Square <var>1</var> moves right.</li> <li>After the four spells are cast, there is one golem on Square <var>2</var> and one golem on Square <var>3</var>, for a total of two golems remaining.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 3 AABCBDBA A L B R A R </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre> <ul> <li>After the three spells are cast, there is one golem on Square <var>2</var>, two golems on Square <var>4</var> and two golems on Square <var>6</var>, for a total of five golems remaining.</li> <li>Note that a single spell may move multiple golems.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 15 SNCZWRCEWB B R R R E R W R Z L S R Q L W L B R C L A L N L E R Z L S L </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p01546
<h1>Sports Days 2.0</h1> <p> 䌚接倧孊附属小孊校䌚接倧小は日本有数の競技プログラマヌ逊成校ずしお有名である。 もちろん、運動䌚に参加しおいるずきでさえアルゎリズムの修行を欠かせない。 競技プログラミング郚郚長のあなたはもちろんこの倧䌚でも勝利したい。 今回はある競技に泚目する。 </p> <p> ある競技ずは䌚接倧小で行われおいる䌝統的な競技だ。 校庭にコヌンが<var>V</var>個眮いおある。 コヌンのいく぀かのペアは癜線で描かれた矢印で結ばれおいる。 矢印の先は片偎だけに぀いおおり、敎数が䜵蚘されおいる。 同じコヌンのペアがの耇数の矢印に結ばれおいる堎合もある。 </p> <p> 競技者は任意にコヌンを遞び、移動開始する。 移動は競技者がいるコヌンから矢印の䞊をその向きに移動し、次のコヌンぞ移る。 同じコヌン、同じ矢印を䜕床も蟿っおも良い。 競技者はコヌンからコヌンぞの移動埌、さらに移動するか移動を終了をするかを遞択するこずができる。 </p> <p> この競技の目的は矢印を蟿るこずにより、スコアをK以䞊にするこずである。 スコアは矢印を蟿る床に䜵蚘された敎数倀が加算されおいく。 より少ない経由する矢印の本数でスコアを<var>K</var>以䞊にした競技者が勝利ずなる。 矢印が同じ本数の堎合はより高いスコアの競技者が勝利ずなる。 </p> <p> このルヌルで最適な動きを競技者が行った堎合、䜕本の矢印を経由すべきか出力せよ。 たた、経由した矢印の数が100本以䞋の堎合、経由すべきコヌンを順にすべお出力せよ。 最適な動きが耇数存圚する堎合があるが、どの動きの結果を出力しおも良い。 スコアを<var>K</var>以䞊にする動きが存圚しない堎合は-1を出力せよ。 </p> <p> たた、コヌンにはすべお0から<var>V-1</var>たでの番号が振られおおり、 色はすべお緑色意味深である。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。<br> </p> <blockquote> <var>V</var> <var>E</var> <var>K</var><br> <var>v<sub>11</sub></var> <var>v<sub>12</sub></var> <var>c<sub>1</sub></var><br>...<br><var>v<sub>i1</sub></var> <var>v<sub>i2</sub></var> <var>c<sub>i</sub></var><br>...<br><var>v<sub>E1</sub></var> <var>v<sub>E2</sub></var> <var>c<sub>E</sub></var><br></blockquote> <p> ここで、<br> </p> <ul> <li><var>V</var>はコヌンの数</li> <li><var>E</var>は矢印の数 </li><li><var>v<sub>i,1</sub></var>は矢印<var>i</var>の始点のコヌン番号 </li><li><var>v<sub>i2</sub></var>は矢印<var>i</var>の終点のコヌン番号 </li><li><var>c<sub>i</sub></var>は矢印に䜵蚘されおいる敎数 </li></ul> <p> である。 </p> <h2>Constraints</h2> <p> 入力は以䞋の条件を満たす。 </p> <ul> <li>入力はすべお敎数 </li> <li><var>2&le;V&le;150</var> </li> <li><var>0&le;E&le;V&times;V</var> </li> <li><var>0&lt;K&le;10<sup>6</sup></var> </li> <li><var>0&le; v<sub>i1</sub>, v<sub>i2</sub> &lt; V (0&lt;i&le;E)</var> </li> <li><var>v<sub>i1</sub> &ne; v<sub>i2</sub> (0&lt;i&le;E)</var> </li> <li><var>0&lt;c<sub>i</sub> &le; 100 (0&lt;i&le;E)</var> </li><li><var>v<sub>i1</sub> = v<sub>j1</sub> </var>か぀ <var>v<sub>i2</sub> = v<sub>j2</sub> (i &ne; j, 0&lt;i,j&le;E)</var>ずなるような<var>i, j</var>が含たれる入力も存圚する。 </li></ul> <h2>Output</h2> <p> 出力は2行からなる。 </p> <ul> <li>1行目 最適な動きを行った堎合の経由する矢印の本数で出力 </li><li>2行目 経由すべきコヌンの番号を経由する順番に空癜区切りで出力 </li></ul> <p> 最適な動きが耇数存圚する堎合があるが、どの動きの結果を出力しおも良い。 経由すべき矢印の本数が100本を越える堎合、2行目は出力しおはいけない。 スコアを<var>K</var>以䞊にする最適な動きが存圚しない堎合は-1を1行目に出力し、 2行目に䜕も出力しおはいけない。 </p> <H2>Sample Input 1</H2> <pre>3 9 89 2 0 2 1 0 3 2 0 1 2 0 3 0 1 1 0 1 2 1 2 3 0 1 1 1 0 2 </pre> <H2>Output for the Sample Input 1</H2> <pre>34 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 0 </pre> <H2>Sample Input 2</H2> <pre>2 0 1 </pre> <H2>Output for the Sample Input 2</H2> <pre>-1 </pre> <H2>Sample Input 3</H2> <pre>7 8 4000 0 1 1 1 0 1 1 2 2 2 3 2 3 4 2 5 4 3 3 5 4 5 6 5 </pre> <H2>Output for the Sample Input 3</H2> <pre>3991 </pre>
p01116
<h3>For Programming Excellence</h3> <!-- end en only --> <!-- begin en only --> <p> A countless number of skills are required to be an excellent programmer. Different skills have different importance degrees, and the total programming competence is measured by the sum of products of levels and importance degrees of his/her skills. </p> <p> In this summer season, you are planning to attend a summer programming school. The school offers courses for many of such skills. Attending a course for a skill, your level of the skill will be improved in proportion to the tuition paid, one level per one yen of tuition, however, each skill has its upper limit of the level and spending more money will never improve the skill level further. Skills are not independent: For taking a course for a skill, except for the most basic course, you have to have at least a certain level of its prerequisite skill. </p> <p> You want to realize the highest possible programming competence measure within your limited budget for tuition fees. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of no more than 100 datasets, each in the following format. </p> <!-- end en only --> <blockquote> <p> <i>n</i> <i>k</i><br> <i>h</i><sub>1</sub> ... <i>h<sub>n</sub></i> <br> <i>s</i><sub>1</sub> ... <i>s<sub>n</sub></i> <br> <i>p</i><sub>2</sub> ... <i>p<sub>n</sub></i> <br> <i>l</i><sub>2</sub> ... <i>l<sub>n</sub></i> <br> </p> </blockquote> <!-- begin en only --> <ul> <li> The first line has two integers, <i>n</i>, the number of different skills between 2 and 100, inclusive, and <i>k</i>, the budget amount available between 1 and 10<sup>5</sup>, inclusive. In what follows, skills are numbered 1 through <i>n</i>. </li> <li> The second line has <i>n</i> integers <i>h</i><sub>1</sub>...<i>h<sub>n</sub></i>, in which <i>h<sub>i</sub></i> is the maximum level of the skill <i>i</i>, between 1 and 10<sup>5</sup>, inclusive. </li> <li> The third line has <i>n</i> integers <i>s</i><sub>1</sub>...<i>s<sub>n</sub></i>, in which <i>s<sub>i</sub></i> is the importance degree of the skill <i>i</i>, between 1 and 10<sup>9</sup>, inclusive. </li> <li> The fourth line has <i>n</i>&#8722;1 integers <i>p</i><sub>2</sub>...<i>p<sub>n</sub></i>, in which <i>p<sub>i</sub></i> is the prerequisite skill of the skill <i>i</i>, between 1 and <i>i</i>&#8722;1, inclusive. The skill 1 has no prerequisites. </li> <li> The fifth line has <i>n</i>&#8722;1 integers <i>l</i><sub>2</sub>...<i>l<sub>n</sub></i>, in which <i>l<sub>i</sub></i> is the least level of prerequisite skill <i>p<sub>i</sub></i> required to learn the skill <i>i</i>, between 1 and <i>h<sub>p<sub>i</sub></sub></i>&nbsp;, inclusive. </li> </ul> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing two zeros. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing one integer, which is the highest programming competence measure achievable, that is, the maximum sum of the products of levels and importance degrees of the skills, within the given tuition budget, starting with level zero for all the skills. You do not have to use up all the budget. </p> <!-- end en only --> <h3>Sample Input</h3> <pre>3 10 5 4 3 1 2 3 1 2 5 2 5 40 10 10 10 10 8 1 2 3 4 5 1 1 2 3 10 10 10 10 5 10 2 2 2 5 2 2 2 2 5 2 1 1 2 2 2 1 2 1 0 0 </pre> <h3>Output for the Sample Input</h3> <pre>18 108 35 </pre>
p02690
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Give a pair of integers <var>(A, B)</var> such that <var>A^5-B^5 = X</var>. It is guaranteed that there exists such a pair for the given integer <var>X</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X \leq 10^9</var></li> <li><var>X</var> is an integer.</li> <li>There exists a pair of integers <var>(A, B)</var> satisfying the condition in Problem Statement.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>A</var> and <var>B</var>, with space in between. If there are multiple pairs of integers <var>(A, B)</var> satisfying the condition, you may print any of them.</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>33 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 -1 </pre> <p>For <var>A=2</var> and <var>B=-1</var>, <var>A^5-B^5 = 33</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 -1 </pre></section> </div> </span>
p03982
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"><section> <h3>Problem Statement</h3> <p> Kyoto University decided to build a straight wall on the west side of the university to protect against gorillas that attack the university from the west every night. Since it is difficult to protect the university at some points along the wall where gorillas attack violently, reinforcement materials are also built at those points. Although the number of the materials is limited, the state-of-the-art technology can make a prediction about the points where gorillas will attack next and the number of gorillas that will attack at each point. The materials are moved along the wall everyday according to the prediction. You, a smart student majoring in computer science, are called to find the way to move the materials more efficiently. </p> <p> Theare are <var>N</var> points where reinforcement materials can be build along the straight wall. They are numbered <var>1</var> through <var>N</var>. Because of the protection against the last attack of gorillas, <var>A_i</var> materials are build at point <var>i</var> (<var>1 \leq i \leq N</var>). For the next attack, the materials need to be rearranged such that at least <var>B_i</var> materials are built at point <var>i</var> (<var>1 \leq i \leq N</var>). It costs <var>|i - j|</var> to move <var>1</var> material from point <var>i</var> to point <var>j</var>. Find the minimum total cost required to satisfy the condition by moving materials. You do not need to consider the attack after the next. </p> </section></div> <div class="part"><section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>A_i \geq 1</var></li> <li><var>B_i \geq 1</var></li> <li><var>A_1 + A_2 + ... + A_N \leq 10^{12}</var></li> <li><var>B_1 + B_2 + ... + B_N \leq A_1 + A_2 + ... + A_N</var></li> <li>There is at least one way to satisfy the condition. </li> </ul> </section></div> <hr/> <div class="io-style"> <div class="part"><section> <h3>Input</h3> <p>The input is given from Standard Input in the following format: </p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> <var>B_1</var> <var>B_2</var> ... <var>B_N</var></pre> </section></div> <div class="part"><section> <h3>Output</h3> <p>Print the minimum total cost required to satisfy the condition. </p> <h3>Partial Scores</h3> <p> <var>30</var> points will be awarded for passing the test set satisfying the following: <ul> <li><var>N \leq 100</var></li> <li><var>A_1 + A_2 + ... + A_N \leq 400</var></li> </ul> </p> <p> Another <var>30</var> points will be awarded for passing the test set satisfying the following: <ul> <li><var>N \leq 10^3</var></li> </ul> </p> <p> Another <var>140</var> points will be awarded for passing the test set without addtional constraints and you can get <var>200</var> points in total. </p> </section></div> </div> <hr/> <div class="part"><section> <h3>Sample Input 1</h3> <pre>2 1 5 3 1</pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre>2</pre> <p>It costs least to move <var>2</var> materials from point <var>2</var> to point <var>1</var>. </p> </section></div> <div class="part"><section> <h3>Sample Input 2</h3> <pre>5 1 2 3 4 5 3 3 1 1 1</pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre>6</pre> </section></div> <div class="part"><section> <h3>Sample Input 3</h3> <pre>27 46 3 4 2 10 2 5 2 6 7 20 13 9 49 3 8 4 3 19 9 3 5 4 13 9 5 7 10 2 5 6 2 6 3 2 2 5 3 11 13 2 2 7 7 3 9 5 13 4 17 2 2 2 4</pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3> <pre>48</pre> <p>The input of this test case satisfies both the first and second additional constraints. </p> </section></div> <div class="part"><section> <h3>Sample Input 4</h3> <pre>18 3878348 423911 8031742 1035156 24256 10344593 19379 3867285 4481365 1475384 1959412 1383457 164869 4633165 6674637 9732852 10459147 2810788 1236501 770807 4003004 131688 1965412 266841 3980782 565060 816313 192940 541896 250801 217586 3806049 1220252 1161079 31168 2008961</pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3> <pre>6302172</pre> <p>The input of this test case satisfies the second additional constraint. </p> </section></div> <div class="part"><section> <h3>Sample Input 5</h3> <pre>2 1 99999999999 1234567891 1</pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3> <pre>1234567890</pre> <p>The input and output values may exceed the range of 32-bit integer. </p> </section></div> </span>
p00357
<H1>Trampoline</H1> <p> A plurality of trampolines are arranged in a line at 10 m intervals. Each trampoline has its own maximum horizontal distance within which the jumper can jump safely. Starting from the left-most trampoline, the jumper jumps to another trampoline within the allowed jumping range. The jumper wants to repeat jumping until he/she reaches the right-most trampoline, and then tries to return to the left-most trampoline only through jumping. Can the jumper complete the roundtrip without a single stepping-down from a trampoline? </p> <p> Write a program to report if the jumper can complete the journey using the list of maximum horizontal reaches of these trampolines. Assume that the trampolines are points without spatial extent. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>N</var> <var>d_1</var> <var>d_2</var> : <var>d_N</var> </pre> <p> The first line provides the number of trampolines <var>N</var> (2 &le; <var>N</var> &le; 3 &times; 10<sup>5</sup>). Each of the subsequent <var>N</var> lines gives the maximum allowable jumping distance in integer meters for the <var>i</var>-th trampoline <var>d_i</var> (1 &le; <var>d_i</var> &le; 10<sup>6</sup>). </p> <h2>Output</h2> <p> Output "<span>yes</span>" if the jumper can complete the roundtrip, or "<span>no</span>" if he/she cannot. </p> <h2>Sample Input 1</h2> <pre> 4 20 5 10 1 </pre> <h2>Sample Output 1</h2> <pre> no </pre> <h2>Sample Input 2</h2> <pre> 3 10 5 10 </pre> <h2>Sample Output 2</h2> <pre> no </pre> <h2>Sample Input 3</h2> <pre> 4 20 30 1 20 </pre> <h2>Sample Output 3</h2> <pre> yes </pre>
p00707
<H1>The Secret Number</H1> <P> Your job is to find out the secret number hidden in a matrix, each of whose element is a digit ('0'-'9') or a letter ('A'-'Z'). You can see an example matrix in Figure 1. </P> <CENTER> <DIV style="margin-bottom: 5mm"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_secret1"></DIV> Figure 1: A Matrix </CENTER> <P> The secret number and other non-secret ones are coded in a matrix as sequences of digits in a decimal format. You should only consider sequences of digits <I>D</I><SUB>1</SUB> <I>D</I><SUB>2</SUB> ... <I>D</I><SUB><I>n</I></SUB> such that <I>D</I><SUB><I>k</I>+1</SUB> (1 &lt;= <I>k</I> &lt; <I>n</I>) is either right next to or immediately below <I>D</I><SUB><I>k</I></SUB> in the matrix. The secret you are seeking is the largest number coded in this manner. </P> <P> Four coded numbers in the matrix in Figure 1, i.e., 908820, 23140037, 23900037, and 9930, are depicted in Figure 2. As you may see, in general, two or more coded numbers may share a common subsequence. In this case, the secret number is 23900037, which is the largest among the set of all coded numbers in the matrix. </P> <CENTER> <DIV style="margin-bottom: 5mm"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_secret2"></DIV> Figure 2: Coded Numbers </CENTER> <P> In contrast, the sequences illustrated in Figure 3 should be excluded: 908A2 includes a letter; the fifth digit of 23149930 is above the fourth; the third digit of 90037 is below right of the second. </P> <CENTER> <DIV style="margin-bottom: 5mm"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_secret3" ></DIV> Figure 3: Inappropriate Sequences </CENTER> <P> Write a program to figure out the secret number from a given matrix. </P> <H2>Input</H2> <P> The input consists of multiple data sets, each data set representing a matrix. The format of each data set is as follows. </P> <BLOCKQUOTE> <I>W</I> <I>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> ...<BR> <I>C</I><SUB><I>H</I>1</SUB><I>C</I><SUB><I>H</I>2</SUB> ... <I>C</I><SUB><I>HW</I></SUB><BR> </BLOCKQUOTE> <P> In the first line of a data set, two positive integers <I>W</I> and <I>H</I> are given. <I>W</I> indicates the width (the number of columns) of the matrix, and <I>H</I> indicates the height (the number of rows) of the matrix. <I>W+H</I> is less than or equal to 70. </P> <P> <I>H</I> lines follow the first line, each of which corresponds to a row of the matrix in top to bottom order. The <I>i</I>-th row consists of <I>W</I> characters <I>C</I><SUB><I>i</I>1</SUB><I>C</I><SUB><I>i</I>2</SUB> ... <I>C</I><SUB><I>iW</I></SUB> in left to right order. You may assume that the matrix includes at least one non-zero digit. </P> <P> Following the last data set, two zeros in a line indicate the end of the input. </P> <H2>Output</H2> <P> For each data set, print the secret number on a line. Leading zeros should be suppressed. </P> <H2>Sample Input</H2> <PRE> 7 4 9R2A993 0E314A0 8A900DE 820R037 6 7 JH03HE ID7722 0DA1AH 30C9G5 99971A CA7EAI AHLBEM 20 2 A1234567891234CBDEGH BDEDF908034265091499 0 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> 23900037 771971 12345908034265091499 </PRE>
p01815
<h2>Escape</h2> <p> 頂点に正の倀を持぀無向グラフが䞎えられる。 頂点には 1 から <var>N</var> の番号が぀いおおり、<var>i</var> 番目の頂点は <var>w_i</var> の倀を持っおいる。 1 番目の頂点からスタヌトし、盎前に通った蟺を通るこずができないずいう制玄のもずでグラフ䞊を移動するこずができる。 各頂点では初めお蚪れた時に限りその頂点が持぀倀の点数を埗られる。 </p> <p> 取埗できる点数の総和の最倧倀を求めよ。 </p> <h3>Constraints</h3> <ul> <li><var>1 &le; N &le; 100000</var></li> <li><var>N &minus; 1 &le; M &le; 100000</var></li> <li><var>1 &le; w_i &le; 1000</var></li> <li><var>1 &le; u_i, v_i &le; N</var></li> <li>倚重蟺・自己蟺は存圚しない</li> <li>グラフは連結である</li> </ul> <h3>Input Format</h3> <p> 入力は以䞋の圢匏で暙準入力から䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>w_1</var> <var>w_2</var> ... <var>w_N</var> <var>u_1</var> <var>v_1</var> <var>u_2</var> <var>v_2</var> ... <var>u_M</var> <var>v_M</var> </pre> <p> <var>1</var> 行目には<b>グラフ</b>の頂点数 <var>N</var> ず蟺の数を衚す敎数 <var>M</var> が入力される。 <br /> <var>2</var> 行目には各頂点が持぀倀 <var>w_i</var> が入力される。 <br /> さらに続けお <var>M</var> 行に、各蟺により繋がれる <var>2</var> 頂点の番号が入力される。<br /> </p> <h3>Output Format</h3> <p> 答えを1行に出力せよ。 </p> <h3>Sample Input 1</h3> <pre> 6 6 1 2 3 4 5 6 1 2 2 3 3 4 1 4 4 5 5 6 </pre> <h3>Sample Output 1</h3> <pre> 21 </pre> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_g_sample1-1" width=150 height=190/> <br/> 頂点 1→2→3→4→5→6 ず進むこずで党おの頂点の点数を集めるこずができたす。 </p> <h3>Sample Input 2</h3> <pre> 7 8 1 3 3 5 2 2 3 1 2 2 3 3 1 1 4 1 7 1 5 1 6 5 6 </pre> <h3>Sample Output 2</h3> <pre> 16 </pre> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2015SummerDay2_g_sample2" width=240 height=185/> <br/> 頂点 1→2→3→1→5→6→1→4 ず進むこずで16点を集めるこずができたす。 </p>
p03828
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Find the number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀N≀10^3</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 number of the positive divisors of <var>N!</var>, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>There are four divisors of <var>3!</var> <var>=6</var>: <var>1</var>, <var>2</var>, <var>3</var> and <var>6</var>. Thus, the output should be <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>30 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>972926972 </pre></section> </div> </span>
p00212
<H1> 高速バス</H1> <p> A 君は高校の䌑みを利甚しお、高速バス(以䞋、「バス」 )で䞀人旅をする蚈画を立おおいたす。たず、A 君は䞀番行っおみたい町を遞んでそこを目的地にしたした。次に出発地から目的地たでバスを乗り継いでいくルヌトを決めなければなりたせん。乗り継ぎをするずきは、バスを降りおから別のバスに乗り換えるので、それぞれのバスの乗車刞が必芁になりたす。 </p> <p> A 君は芪戚のおじさんからバスの割匕刞を䜕枚かもらいたした。 この刞を 1 枚䜿うず乗車刞 1 枚を半額で賌入できたす。䟋えば、図 1 の出発地5から目的地1ぞ行く堎合には、5→4→6→2→1ず5→3→1の二぀の経路が考えられたす。割匕刞が 2 枚あるずするず、亀通費を最も安くするには5→4→6→2→1の経路をたどった堎合、4→6ず6→2の路線に割匕を利甚し、合蚈料金は 4600円ずなりたす。䞀方、5→3→1の経路をたどった堎合、5→3ず3→1の路線に割匕を利甚し、合蚈料金は 3750 円ずなりたす。 </p> <p> A 君は芳光にお金を回したいので、亀通費はできるだけ少なくしようず考えおいたす。そこで A 君は、出発地から目的地たでの最も安い亀通費を求めるプログラムを䜜成するこずにしたした。 </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_highwayBus"> <p> 図1 </p> </center> <p> 割匕刞の枚数、バスが぀なぐ町の数、バスの路線数、各バスの路線情報を入力ずし、出発地から目的地たでの最も安い亀通費を出力するプログラムを䜜成しおください。各バスは双方向に同䞀料金で運行しおいたす。たた、町の数を <var>n</var> ずするず、町にはそれぞれ異なる 1 から <var>n</var> たでの番号が振られおいたす。出発地から目的地たでの経路は必ず存圚するものずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。 入力の終わりはれロが぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>c</var> <var>n</var> <var>m</var> <var>s</var> <var>d</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>f<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>f<sub>2</sub></var> : <var>a<sub>m</sub></var> <var>b<sub>m</sub></var> <var>f<sub>m</sub></var> </pre> <p> 1 行目に割匕刞の枚数 <var>c</var> (1 &le; <var>c</var> &le; 10)、バスが぀なぐ町の数 <var>n</var> (2 &le; <var>n</var> &le; 100)、バスの路線数 <var>m</var> (1 &le; <var>m</var> &le; 500)、出発地の町番号 <var>s</var> ず目的地の町番号 <var>d</var> (<var>s &ne; d</var>) が䞎えられたす。 </p> <p> 続く <var>m</var> 行に第 <var>i</var> のバスの路線情報 <var>a<sub>i</sub>, b<sub>i</sub>, f<sub>i</sub></var> (1 &le; <var>a<sub>i</sub>, b<sub>i</sub></var> &le; <var>n</var>, 1000 &le; <var>f<sub>i</sub></var> &le; 10000) が䞎えられたす。<var>a<sub>i</sub>, b<sub>i</sub></var> はバスの路線の始点ず終点の町番号、<var>f<sub>i</sub></var> はこの路線の料金を衚す100 刻みの敎数です。 </p> <p> デヌタセットの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、最も安い亀通費を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 1 3 3 1 3 1 3 2000 1 2 1000 2 3 1000 2 3 3 1 3 1 3 2300 1 2 1000 2 3 1200 2 6 6 5 1 1 2 1500 1 3 4500 2 6 2000 5 4 1000 6 4 2200 3 5 3000 0 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1000 1100 3750 </pre>
p00642
<H1><font color="#000000">Problem F:</font> Ben Toh</H1> <p> As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes. </p> <p> A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job. </p> <p> Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%. </p> <p> He continue to go to supermaket and try to get the discounted box lunch for <i>n</i> days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire. </p> <H2>Input</H2> <p> Input consists of several datasets. </p> <p> Input for a single dataset is given as a single integer <i>n</i>. </p> <p> Input terminates with a dataset where <i>n</i> = 0. </p> <H2>Output</H2> <p> For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>n</i> &le; 100,000</li> </ul> <H2>Sample Input</H2> <pre> 1 2 3 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1.00000000 1.50000000 2.12500000 </pre>
p01950
<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> Endless BFS </H1> <p> Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows: </p> <pre> 1: $current \leftarrow \{start\_vertex\}$ 2: $visited \leftarrow current$ 3: while $visited \ne $ the set of all the vertices 4: $found \leftarrow \{\}$ 5: for $v$ in $current$ 6: for each $u$ adjacent to $v$ 7: $found \leftarrow found \cup\{u\}$ 8: $current \leftarrow found \setminus visited$ 9: $visited \leftarrow visited \cup found$ </pre> <p> However, Mr. Endo apparently forgot to manage visited vertices in his code. More precisely, he wrote the following code: </p> <pre> 1: $current \leftarrow \{start\_vertex\}$ 2: while $current \ne $ the set of all the vertices 3: $found \leftarrow \{\}$ 4: for $v$ in $current$ 5: for each $u$ adjacent to $v$ 6: $found \leftarrow found \cup \{u\}$ 7: $current \leftarrow found$ </pre> <p> You may notice that for some graphs, Mr. Endo's program will not stop because it keeps running infinitely. Notice that it does not necessarily mean the program cannot explore all the vertices within finite steps. See example 2 below for more details.Your task here is to make a program that determines whether Mr. Endo's program will stop within finite steps for a given graph in order to point out the bug to him. Also, calculate the minimum number of loop iterations required for the program to stop if it is finite. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $N$ $M$ $U_1$ $V_1$ ... $U_M$ $V_M$ </pre> <p> The first line consists of two integers $N$ ($2 \leq N \leq 100,000$) and $M$ ($1 \leq M \leq 100,000$), where $N$ is the number of vertices and $M$ is the number of edges in a given undirected graph, respectively. The $i$-th line of the following $M$ lines consists of two integers $U_i$ and $V_i$ ($1 \leq U_i, V_i \leq N$), which means the vertices $U_i$ and $V_i$ are adjacent in the given graph. The vertex 1 is the start vertex, i.e. $start\_vertex$ in the pseudo codes. You can assume that the given graph also meets the following conditions. </p> <ul> <li>The graph has no self-loop, i.e., $U_i \ne V_i$ for all $1 \leq i \leq M$.</li> <li>The graph has no multi-edge, i.e., $\{Ui,Vi\} \ne \{U_j,V_j\}$ for all $1 \leq i < j \leq M$.</li> <li>The graph is connected, i.e., there is at least one path from $U$ to $V$ (and vice versa) for all vertices $1 \leq U, V \leq N$</li> </ul> <H2>Output</H2> <p> If Mr. Endo's wrong BFS code cannot stop within finite steps for the given input graph, print -1 in a line. Otherwise, print the minimum number of loop iterations required to stop. </p> <H2>Sample Input 1</H2> <pre> 3 3 1 2 1 3 2 3 </pre> <H2>Output for Sample Input 1</H2> <pre> 2 </pre> <H2>Sample Input 2</H2> <pre> 4 3 1 2 2 3 3 4 </pre> <H2>Output for Sample Input 2</H2> <pre> -1 </pre> <p> Transition of $current$ is $\{1\} \rightarrow \{2\} \rightarrow \{1,3\} \rightarrow \{2,4\} \rightarrow \{1,3\} \rightarrow \{2,4\} \rightarrow ... $. Although Mr. Endo's program will achieve to visit all the vertices (in 3 steps), will never become the same set as all the vertices. </p> <H2>Sample Input 3</H2> <pre> 4 4 1 2 2 3 3 4 4 1 </pre> <H2>Output for Sample Input 3</H2> <pre> -1 </pre> <H2>Sample Input 4</H2> <pre> 8 9 2 1 3 5 1 6 2 5 3 1 8 4 2 7 7 1 7 4 </pre> <H2>Output for Sample Input 4</H2> <pre> 3 </pre>
p02385
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Dice III</h1><br> <p> Write a program which reads the two dices constructed in the same way as <a href="description.jsp?id=ITP1_11_A">Dice I</a>, and determines whether these two dices are identical. You can roll a dice in the same way as <a href="description.jsp?id=ITP1_11_A">Dice I</a>, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical. </p> <h2>Input</h2> <p> In the first line, six integers assigned to faces of a dice are given in ascending order of their corresponding labels.<br> In the second line, six integers assigned to faces of another dice are given in ascending order of their corresponding labels. </p> <h2>Output</h2> <p> Print "<sapn>Yes</span>" if two dices are identical, otherwise "<span>No</span>" in a line. </p> <h2>Constraints</h2> <ul> <li>$0 \leq $ the integer assigned to a face $ \leq 100$</li> </ul> <h2>Sample Input 1</h2> <pre> 1 2 3 4 5 6 6 2 4 3 5 1 </pre> <h2>Sample Output 1</h2> <pre> Yes </pre> <br> <h2>Sample Input 2</h2> <pre> 1 2 3 4 5 6 6 5 4 3 2 1 </pre> <h2>Sample Output 2</h2> <pre> No </pre>
p01403
<h2> Problem F: Farey Sequence </h2> <p> slipは数字を眺めるのが奜きである。 ファむルをダりンロヌドしおいるずきの、残り時間を眺めおいるだけで、時間を朰せるほどである。 そんなslipが友人から面癜い数列を教えられた。 その数列の定矩は以䞋のずおりである。 </p> <p> 䞀般項を<i>F<sub>n</sub></i>ず衚わす。 <i>F<sub>n</sub></i>ずは、<i>n</i>以䞋の分母を持぀0以䞊1以䞋のすべおの玄分された分数(既玄分数)を小さな順から䞊べたものである。 ただし、敎数0、1はそれぞれ分数0/1、1/1ずしお扱われる。 </p> <p> ぀たり<i>F<sub>3</sub></i>は、 </p> <pre> <i>F<sub>3</sub></i> = (0/1, 1/3, 1/2, 2/3, 1/1) </pre> <p> のように衚される。 </p> <p> <i>F<sub>5</sub></i>であれば </p> <pre> <i>F<sub>5</sub></i> = (0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1) </pre> <p> ず衚される。 </p> <p> slipはこの数列にすぐにのめり蟌んだ。 しかしこの数列を眺めおいおも、なかなか特城が぀かめなかった。 特城を぀かむためにたずは各項の項数がいく぀あるのか調べようず思ったが、 増え方の芏則がわからず、自力で理解するこずを断念した。 </p> <p> そこで、 勝手に友人ず思っおいるあなたに、指定した項にどれだけの項数があるのかを聞くこずにした。 あなたの仕事は、䞎えられた項における項数を求めるこずである。 </p> <h2> Input </h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <i>t</i> <i>n<sub>1</sub></i> ... <i>n<sub>i</sub></i> ... <i>n<sub>t</sub></i> </pre> <p> <i>t</i>(<i>1 &le; t &le; 10000</i>)はテストケヌスの数である。 <i>n<sub>i</sub></i>(<i>1 &le; n<sub>i</sub> &le; 1000000</i>)は䞎えられた項の番号である。 </p> <h2> Output </h2> <p> 各テストケヌスごずに、項数を1行に衚瀺せよ。 </p> <h2> Sample Input </h2> <pre> 2 3 5 </pre> <h2> Output for Sample Input </h2> <pre> 5 11 </pre>
p01053
<h1>Lucky Number</h1> <h2>Problem</h2> <p> 0 から <var>N</var>-1 たでの数字がありたす。 <var>M</var>+1日間のラッキヌナンバヌを以䞋の方法で遞びたいず思いたす。 最初の日にラッキヌナンバヌをランダムに決めたす。 <var>i</var>日埌のラッキヌナンバヌを <var>A</var> 、<var>i</var>+1日埌のラッキヌナンバヌを <var>B</var> ずするず、 </p> <pre> <var>B</var> = ( <var>A</var> + <var>j</var> ) % <var>N</var> ただし <var>j</var> は 0 &le; <var>j</var> &lt; <var>N</var> か぀ <var>j</var> / <var>K</var> が偶数ずなる党おの敎数である ) </pre> <p> で求められる<var>B</var>のうちのいずれかからランダムに決めたす。ただし、<var>a</var> / <var>b</var> の結果は小数点以䞋を切り捚おた敎数ずし、<var>a</var>%<var>b</var>は<var>a</var>を<var>b</var>で割った䜙りずしたす。 たた <var>K</var> は <var>N</var> / <var>K</var> が割り切れお、<var>N</var> / <var>K</var> が偶数ずなる数字であるこずが保蚌されたす。 <p> 䟋えば 0,1,2,3 ず数字があり、 <var>K</var> = 1 のずき </p> <ul> <li>0 の次のラッキヌナンバヌは 0 or 2</li> <li>1 の次のラッキヌナンバヌは 1 or 3</li> <li>2 の次のラッキヌナンバヌは 0 or 2</li> <li>3 の次のラッキヌナンバヌは 1 or 3</li> </ul> <p> ずなりたす。 </p> <p> 次に<var>Q</var>個の質問が䞎えられたす。 各質問の内容は以䞋のずおりです。 </p> <p> 最初の日のラッキヌナンバヌが <var>a</var> のずき <var>b</var> 日埌のラッキヌナンバヌが <var>c</var> になるような <var>b</var> 日埌たでのラッキヌナンバヌの遞び方は䜕通りでしょうか 遞び方は膚倧な数になるず思われるので 1,000,000,007 で割った䜙りを求めおください。 </p> <p> 䟋えば、<var>N</var>=4 <var>K</var>=1 で、最初のラッキヌナンバヌが 0 で 3 日埌のラッキヌナンバヌが 2 になるような組み合わせは </p> <ul> <li>0 &rarr; 0 &rarr; 0 &rarr; 2</li> <li>0 &rarr; 0 &rarr; 2 &rarr; 2</li> <li>0 &rarr; 2 &rarr; 0 &rarr; 2</li> <li>0 &rarr; 2 &rarr; 2 &rarr; 2</li> </ul> <p> の通りです。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>M</var> <var>K</var> <var>Q</var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>c<sub>1</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> <var>c<sub>2</sub></var> . . . <var>a<sub>Q</sub></var> <var>b<sub>Q</sub></var> <var>c<sub>Q</sub></var> </pre> <h2>Constraints</h2> <ul> <li>1 &le; <var>N</var> &le; 5000</li> <li>1 &le; <var>M</var> &le; 5000</li> <li>1 &le; <var>K</var> &le; 5000</li> <li><var>N</var> / <var>K</var> が割り切れる</li> <li><var>N</var> / <var>K</var> は偶数</li> <li>1 &le; <var>Q</var> &le; 100000</li> <li>0 &le; <var>a<sub>i</sub></var> &lt; <var>N</var> ( 1 &le; <var>i</var> &le; <var>Q</var> )</li> <li>0 &le; <var>b<sub>i</sub></var> &le; <var>M</var> ( 1 &le; <var>i</var> &le; <var>Q</var> )</li> <li>0 &le; <var>c<sub>i</sub></var> &lt; <var>N</var> ( 1 &le; <var>i</var> &le; <var>Q</var> )</li> </ul> <h2>Output</h2> <p> 各質問に察し、答えを求め 1,000,000,007 で割った䜙りを䞀行ず぀順番に出力しおください。 </p> <h2>Sample Input1</h2> <pre> 6 3 1 10 0 1 0 0 2 0 0 3 0 1 3 3 0 2 1 2 2 2 2 3 2 2 2 0 1 1 1 2 2 1 </pre> <h2>Sample Output1</h2> <pre> 1 3 9 9 0 3 9 3 1 0 </pre>
p03594
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns of squares. We will represent the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left as <var>(i,\ j)</var>. Also, we will define the distance between the squares <var>(i_1,\ j_1)</var> and <var>(i_2,\ j_2)</var> as <var>|i_1 - i_2| + |j_1 - j_2|</var>.</p> <p>Snuke is painting each square in red, yellow, green or blue. Here, for a given positive integer <var>d</var>, he wants to satisfy the following condition:</p> <ul> <li>No two squares with distance exactly <var>d</var> have the same color.</li> </ul> <p>Find a way to paint the squares satisfying the condition. It can be shown that a solution always exists.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ H, W ≀ 500</var></li> <li><var>1 ≀ d ≀ H + W - 2</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>d</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a way to paint the squares satisfying the condition, in the following format. If the square <var>(i,\ j)</var> is painted in red, yellow, green or blue, <var>c_{ij}</var> should be <code>R</code>, <code>Y</code>, <code>G</code> or <code>B</code>, respectively.</p> <pre><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> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>RY GR </pre> <p>There are four pairs of squares with distance exactly <var>1</var>. As shown below, no two such squares have the same color.</p> <ul> <li><var>(1,\ 1)</var>, <var>(1,\ 2)</var> : <code>R</code>, <code>Y</code></li> <li><var>(1,\ 2)</var>, <var>(2,\ 2)</var> : <code>Y</code>, <code>R</code></li> <li><var>(2,\ 2)</var>, <var>(2,\ 1)</var> : <code>R</code>, <code>G</code></li> <li><var>(2,\ 1)</var>, <var>(1,\ 1)</var> : <code>G</code>, <code>R</code></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>RYB RGB </pre> <p>There are six pairs of squares with distance exactly <var>2</var>. As shown below, no two such squares have the same color.</p> <ul> <li><var>(1,\ 1)</var> , <var>(1,\ 3)</var> : <code>R</code> , <code>B</code></li> <li><var>(1,\ 3)</var> , <var>(2,\ 2)</var> : <code>B</code> , <code>G</code></li> <li><var>(2,\ 2)</var> , <var>(1,\ 1)</var> : <code>G</code> , <code>R</code></li> <li><var>(2,\ 1)</var> , <var>(2,\ 3)</var> : <code>R</code> , <code>B</code></li> <li><var>(2,\ 3)</var> , <var>(1,\ 2)</var> : <code>B</code> , <code>Y</code></li> <li><var>(1,\ 2)</var> , <var>(2,\ 1)</var> : <code>Y</code> , <code>R</code></li> </ul></section> </div> </span>
p03701
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are taking a computer-based examination. The examination consists of <var>N</var> questions, and the score allocated to the <var>i</var>-th question is <var>s_i</var>. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.</p> <p>However, the examination system is actually flawed, and if your grade is a multiple of <var>10</var>, the system displays <var>0</var> as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 ≀ N ≀ 100</var></li> <li><var>1 ≀ s_i ≀ 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>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 maximum value that can be displayed as your grade.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 10 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>25 </pre> <p>Your grade will be <var>25</var> if the <var>10</var>-point and <var>15</var>-point questions are answered correctly and the <var>5</var>-point question is not, and this grade will be displayed correctly. Your grade will become <var>30</var> if the <var>5</var>-point question is also answered correctly, but this grade will be incorrectly displayed as <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 10 10 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>35 </pre> <p>Your grade will be <var>35</var> if all the questions are answered correctly, and this grade will be displayed correctly.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 10 20 30 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p>Regardless of whether each question is answered correctly or not, your grade will be a multiple of <var>10</var> and displayed as <var>0</var>.</p></section> </div> </span>
p02813
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have two permutations <var>P</var> and <var>Q</var> of size <var>N</var> (that is, <var>P</var> and <var>Q</var> are both rearrangements of <var>(1,~2,~...,~N)</var>).</p> <p>There are <var>N!</var> possible permutations of size <var>N</var>. Among them, let <var>P</var> and <var>Q</var> be the <var>a</var>-th and <var>b</var>-th lexicographically smallest permutations, respectively. Find <var>|a - b|</var>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>For two sequences <var>X</var> and <var>Y</var>, <var>X</var> is said to be lexicographically smaller than <var>Y</var> if and only if there exists an integer <var>k</var> such that <var>X_i = Y_i~(1 \leq i &lt; k)</var> and <var>X_k &lt; Y_k</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 8</var></li> <li><var>P</var> and <var>Q</var> are permutations of size <var>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> <var>Q_1</var> <var>Q_2</var> <var>...</var> <var>Q_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>|a - b|</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 3 2 3 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are <var>6</var> permutations of size <var>3</var>: <var>(1,~2,~3)</var>, <var>(1,~3,~2)</var>, <var>(2,~1,~3)</var>, <var>(2,~3,~1)</var>, <var>(3,~1,~2)</var>, and <var>(3,~2,~1)</var>. Among them, <var>(1,~3,~2)</var> and <var>(3,~1,~2)</var> come <var>2</var>-nd and <var>5</var>-th in lexicographical order, so the answer is <var>|2 - 5| = 3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>8 7 3 5 4 2 1 6 8 3 8 2 5 4 6 7 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>17517 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 1 2 3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre></section> </div> </span>
p01696
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <!-- begin en only --> <!--<h3><u>Broken Cipher Generator</u></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><u>壊れた暗号生成噚</u></h3> <!-- end ja only --> <!-- begin en only --> <!-- end en only --> <!-- begin ja only --> <p>JAG (Japanese Alumni Group) は倚くのプログラマで構成される謎の組織でありこの組織の本郚がある建物に入るためには毎回ある機械によっお生成される暗号文を解かなくおはならない この暗号文は'<samp>+</samp>''<samp>-</samp>''<samp>[</samp>''<samp>]</samp>' の蚘号ず倧文字のアルファベットからなっおおり以䞋の BNF で定矩される &lt;Cipher&gt; によっお衚される </p> <pre>&lt;Cipher&gt; ::= &lt;String&gt; | &lt;Cipher&gt;&lt;String&gt; &lt;String&gt; ::= &lt;Letter&gt; | '['&lt;Cipher&gt;']' &lt;Letter&gt; ::= '+'&lt;Letter&gt; | '-'&lt;Letter&gt; | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'</pre> <p>ここでそれぞれの蚘号は以䞋のような意味を衚す </p><ul><li> +(文字) : その文字の次のアルファベットを衚す (ただし '<samp>Z</samp>' の次のアルファベットは '<samp>A</samp>' であるずする) </li><li> -(文字) : その文字の前のアルファベットを衚す (ただし '<samp>A</samp>' の前のアルファベットは '<samp>Z</samp>' であるずする) </li><li> [(文字列)] : その文字列を巊右反転した文字列を衚す </li></ul> <p>しかしこの暗号文を生成する機械には珟圚故障が発生しおおり暗号文のうちアルファベットの箇所が数文字壊れお読めなくなっおいる堎合がある読めない文字は仮に '<samp>?</samp>' ず衚されおいる 調査の結果壊れた文字の埋め方は埩号埌の文字列が埩号埌の文字列ずしおありえる文字列の䞭で蟞曞順最小になるようなものであるこずがわかった あなたの仕事はこの暗号文を正しく埩号するこずである </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットから構成される 各デヌタセットは䞊蚘の BNF で定矩された暗号文においお䞀郚の倧文字のアルファベットが ‘?’ に眮き換えられた文字列を含む 1 行からなる 各文字列の長さは $80$ 以䞋であるず仮定しおよい たた各デヌタセットに含たれる '<samp>?</samp>' の数は $0$ 以䞊 $3$ 以䞋であるず仮定しおよい </p> <p>入力の終了は '<samp>.</samp>' の1文字だけを含む行で衚される </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに察しお埩号埌の文字列が蟞曞順最小になるように暗号文を埩号したずきの埩号埌の文字列を出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>A+A++A Z-Z--Z+-Z [ESREVER] J---?---J ++++++++A+++Z-----------A+++Z [[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L .</pre> <h3>Output for Sample Input</h3> <pre>ABC ZYXZ REVERSE JAG ICPC JAPAN</pre>
p00984
<h2>Halting Problem</h2> <p> A unique law is enforced in the Republic of Finite Loop. Under the law, programs that never halt are regarded as viruses. Releasing such a program is a cybercrime. So, you want to make sure that your software products always halt under their normal use. </p> <p> It is widely known that there exists no algorithm that can determine whether an arbitrary given program halts or not for a given arbitrary input. Fortunately, your products are based on a simple computation model given below. So, you can write a program that can tell whether a given program based on the model will eventually halt for a given input. </p> <p> The computation model for the products has only one variable $x$ and $N + 1$ states, numbered $1$ through $N + 1$. The variable $x$ can store any integer value. The state $N + 1$ means that the program has terminated. For each integer $i$ ($1 \leq i \leq N$), the behavior of the program in the state $i$ is described by five integers $a_i$, $b_i$, $c_i$, $d_i$ and $e_i$ ($c_i$ and $e_i$ are indices of states). </p> <p> On start of a program, its state is initialized to $1$, and the value of $x$ is initialized by $x_0$, the input to the program. When the program is in the state $i$ ($1 \leq i \leq N$), either of the following takes place in one execution step: </p> <ul> <li> if $x$ is equal to $a_i$, the value of $x$ changes to $x + b_i$ and the program state becomes $c_i$;</li> <li> otherwise, the value of $x$ changes to $x + d_i$ and the program state becomes $e_i$.</li> </ul> <p> The program terminates when the program state becomes $N + 1$. </p> <p> Your task is to write a program to determine whether a given program eventually halts or not for a given input, and, if it halts, to compute how many steps are executed. The initialization is not counted as a step. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $N$ $x_0$ $a_1$ $b_1$ $c_1$ $d_1$ $e_1$ . . . $a_N$ $b_N$ $c_N$ $d_N$ $e_N$ </pre> <p> The first line contains two integers $N$ ($1 \leq N \leq 10^5$) and $x_0$ ($−10^{13} \leq x_0 \leq 10^{13}$). The number of the states of the program is $N + 1$. $x_0$ is the initial value of the variable $x$. Each of the next $N$ lines contains five integers $a_i$, $b_i$, $c_i$, $d_i$ and $e_i$ that determine the behavior of the program when it is in the state $i$. $a_i$, $b_i$ and $d_i$ are integers between $−10^{13}$ and $10^{13}$, inclusive. $c_i$ and $e_i$ are integers between $1$ and $N + 1$, inclusive. </p> <h3>Output</h3> <p> If the given program eventually halts with the given input, output a single integer in a line which is the number of steps executed until the program terminates. Since the number may be very large, output the number modulo $10^9 + 7$. </p> <p> Output $-1$ if the program will never halt. </p> <h3>Sample Input 1</h3> <pre> 2 0 5 1 2 1 1 10 1 3 2 2 </pre> <h3>Sample Output 1</h3> <pre> 9 </pre> <h3>Sample Input 2 </h3> <pre> 3 1 0 1 4 2 3 1 0 1 1 3 3 -2 2 1 4 </pre> <h3>Sample Output 2</h3> <pre> -1 </pre> <h3>Sample Input 3</h3> <pre> 3 3 1 -1 2 2 2 1 1 1 -1 3 1 1 4 -2 1 </pre> <h3>Sample Output 3</h3> <pre> -1 </pre>
p03351
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are <var>a</var>, <var>b</var> and <var>c</var> (in meters), respectively. Two people can directly communicate when the distance between them is at most <var>d</var> meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>a,b,c</var> <var>≀</var> <var>100</var></li> <li><var>1</var> <var>≀</var> <var>d</var> <var>≀</var> <var>100</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>a</var> <var>b</var> <var>c</var> <var>d</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If A and C can communicate, print <code>Yes</code>; if they cannot, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 7 9 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>A and B can directly communicate, and also B and C can directly communicate, so we should print <code>Yes</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 10 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>They cannot communicate in this case.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 10 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre> <p>There can be multiple people at the same position.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1 100 2 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>Yes </pre></section> </div> </span>
p02110
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Problem M: Settler</h1> <h2>Problem</h2> <p> 二次元平面䞊に<var>N</var>個の空き地がある。空き地にはそれぞれ1から<var>N</var>たでの番号が割り振られおいる。どの空き地もずおも小さいので、点ずみなすこずができる。<var>i</var>番目の空き地は(<var>x<sub>i</sub></var>,<var>y<sub>i</sub></var>)に存圚しおいる。 </p> <p> 倪郎君はこの<var>N</var>個の空き地の䞭からちょうど<var>K</var>個を遞び、それらの空き地に建物を建おるこずにした。 しかし、あたりにも近い堎所に耇数の建物を建おおも面癜くないず思ったので、倪郎君はそれぞれの空き地どうしのナヌクリッド距離が必ず2以䞊ずなるように空き地を遞ぶこずにした。 </p> <p> 倪郎君が遞ぶ空き地の組み合わせずしお考えられるものを出力するプログラムを䜜成せよ。 組み合わせが耇数存圚する堎合は、蟞曞順で最小のものを出力せよ。 ただし、どのように<var>K</var>個の空き地を遞んだずしおも、いずれか2぀の空き地のナヌクリッド距離が2より小さくなっおしたう堎合は、かわりに-1を出力せよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>N</var> <var>K</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> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>入力は党お敎数である。</li> <li>2 &le; <var>K</var> &le; <var>N</var> &le; 6,000</li> <li>1 &le; <var>x<sub>i</sub></var> , <var>y<sub>i</sub></var> &le; 1,000,000 ( 1 &le; <var>i</var> &le; <var>N</var> )</li> <li> <var>x<sub>i</sub></var> <var>mod</var> 2 &#61; <var>floor</var> ( <var>y<sub>i</sub></var> &divide; 2 ) <var>mod</var> 2 ( 1 &le; <var>i</var> &le; <var>N</var> ) <br>(ここで<var>floor</var> ( <var>y<sub>i</sub></var> &divide; 2 ) ずは<var>y<sub>i</sub></var>を2で割り小数点以䞋を切り捚おた倀である)</li> <li>同じ座暙に耇数の空き地が存圚するこずはない。</li> </ul> <h2>Output</h2> <p> 倪郎君が遞ぶ空き地の番号を昇順に1行ず぀出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 3 2 2 1 1 2 1 3 </pre> <h2>Sample Output 1</h2> <pre> 1 3 </pre> <h2>Sample Input 2</h2> <pre> 4 3 2 1 1 2 1 3 2 4 </pre> <h2>Sample Output 2</h2> <pre> -1 </pre> <h2>Sample Input 3</h2> <pre> 5 3 5 7 5 6 6 8 20 20 4 8 </pre> <h2>Sample Output 3</h2> <pre> 2 3 4 </pre>
p00087
<H1>未熟者の数匏</H1> <p>博士 : ピヌタヌ君、぀いにやったよ。</p> <p>ピヌタヌ : たたですか。今床はどんなくだらない発明ですか。</p> <p>博士 : ぀いに数匏を蚈算機で凊理する画期的な方法を思い぀いたんだ。この衚をみおごらん。 </p> <center> <table border=1> <tr><td width=200 align=center>通垞の蚘法</td><td width=200 align=center>博士の「画期的な」蚘法</td></tr> <tr><td>1 + 2</td><td>1 2 +</td></tr> <tr><td>3 * 4 + 7</td><td>3 4 * 7 +</td></tr> <tr><td>10 / ( 2 - 12 ) </td><td>10 2 12 - /</td></tr> <tr><td>( 3 - 4 ) * ( 7 + 2 * 3 )</td><td>3 4 - 7 2 3 * + *</td></tr> </table> </center> <br/> <p>ピヌタヌ : はぁ。</p> <p>博士 : ふっふっふ。これだけでは、未熟者の君には䜕のこずだかわからないだろうねえ。ここからが肝心なんじゃ。</p> <p>ピヌタヌ : っおいうか・・・。</p> <p>博士 : 蚈算機にはスタックずいうデヌタ構造があるこずは君も知っおいるね。ほれ、「先入れ埌出し」のあれじゃよ。</p> <p>ピヌタヌ : はい。知っおたすが、あの・・・。</p> <p>博士 : この画期的な蚘法はあのスタックを䜿うんじゃ。䟋えばこの 10 2 12 - / だが、次のように凊理する。 </p> <center> <table> <tr><td width="100">凊理察象</td><td width=80 align=center>10</td><td width=80 align=center>2</td><td width=80 align=center>12</td><td width=80 align=center>-</td><td width=80 align=center>/</td></tr> <tr><td> </td><td align=center>↓</td><td align=center>↓</td><td align=center>↓</td><td align=center>↓2-12</td><td align=center>↓10/-10</td></tr> <tr><td>スタック</td><td align=center> <table border=1> <tr><td>.</td></tr> <tr><td>.</td></tr> <tr><td width=40>10</td></tr> </table> </td><td align=center> <table border=1> <tr><td>.</td></tr> <tr><td width=40>2</td></tr> <tr><td>10</td></tr> </table> </td><td align=center> <table border=1> <tr><td width=40>12</td></tr> <tr><td>2</td></tr> <tr><td>10</td></tr> </table> </td><td align=center> <table border=1> <tr><td>.</td></tr> <tr><td width=40>-10</td></tr> <tr><td>10</td></tr> </table> </td><td align=center> <table border=1> <tr><td>.</td></tr> <tr><td>.</td></tr> <tr><td width=40>-1</td></tr> </table> </td></tr> <tr> </tr> </table> </center> <br> <p>博士 : どうじゃな。括匧も挔算子の優先順䜍も気にする必芁がないじゃろう語順も「10 を 2 から 12 を匕いたもので割る。」ずなり、䜕ずなく圌の極東の島囜の蚀葉、日本語ず䌌おおるじゃろうお。 この画期的な発明さえあれば、我が研究宀は安泰じゃお。ファファファ。</p> <p>ピヌタヌ : っおいうか博士。これっお日本にいたずき䌚接倧孊の基瀎コヌスで習いたしたよ。「逆ポヌランド蚘法」ずかいっお、みんな簡単にプログラムしおたした。</p> <p>博士 : ・・・。</p> <p> ずいうこずで、ピヌタヌ君に倉わっお博士に、このプログラムを教える事になりたした。「逆ポヌランド蚘法」で曞かれた数匏を入力ずし、蚈算結果を出力するプログラムを䜜成しおください。 </p> <H2>入力</H2> <p>耇数のデヌタセットが䞎えられたす。各デヌタセットでは、逆ポヌランド蚘法による数匏敎数ず挔算蚘号が空癜文字文字半角で区切られた80文字以内の文字列が  行に䞎えられたす。 ある倀を 0 や 0 に限りなく近い倀で割るような数匏は䞎えられたせん。 </p> <p> デヌタセットの数は 50 を超えたせん。 </p> <H2>出力</H2> <p>各デヌタセットごずに、蚈算結果実数を行に出力しおください。なお、蚈算結果は 0.00001 以䞋の誀差を含んでもよい。 </p> <H2>Sample Input</H2> <pre> 10 2 12 - / 3 4 - 7 2 3 * + * -1 -2 3 + + </pre> <H2>Output for the Sample Input</H2> <pre> -1.000000 -13.000000 0.000000 </pre>
p02540
<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> cities on a 2D plane. The coordinate of the <var>i</var>-th city is <var>(x_i, y_i)</var>. Here <var>(x_1, x_2, \dots, x_N)</var> and <var>(y_1, y_2, \dots, y_N)</var> are both permuations of <var>(1, 2, \dots, N)</var>.</p><p>For each <var>k = 1,2,\dots,N</var>, find the answer to the following question:</p><p>Rng is in City <var>k</var>. Rng can perform the following move arbitrarily many times:</p><ul><li>move to another city that has a smaller <var>x</var>-coordinate and a smaller <var>y</var>-coordinate, or a larger <var>x</var>-coordinate and a larger <var>y</var>-coordinate, than the city he is currently in.</li></ul><p>How many cities (including City <var>k</var>) are reachable from City <var>k</var>?</p></section></div><div class="part"><section><h3>Constraints</h3><ul><li><var>1 \leq N \leq 200,000</var></li><li><var>(x_1, x_2, \dots, x_N)</var> is a permutation of <var>(1, 2, \dots, N)</var>.</li><li><var>(y_1, y_2, \dots, y_N)</var> is a permutation of <var>(1, 2, \dots, N)</var>.</li><li>All values in input are integers.</li></ul></section></div><hr/><div class="io-style"><div class="part"><section><h3>Input</h3><p>Input is given from Standard Input in the following format:</p><pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre></section></div><div class="part"><section><h3>Output</h3><p>Print <var>N</var> lines. In <var>i</var>-th line print the answer to the question when <var>k = i</var>.</p></section></div></div><hr/><div class="part"><section><h3>Sample Input 1</h3><pre>4 1 4 2 3 3 1 4 2 </pre></section></div><div class="part"><section><h3>Sample Output 1</h3><pre>1 1 2 2 </pre><p>Rng can reach City <var>4</var> from City <var>3</var>, or conversely City <var>3</var> from City <var>4</var>.</p></section></div><hr/><div class="part"><section><h3>Sample Input 2</h3><pre>7 6 4 4 3 3 5 7 1 2 7 5 2 1 6 </pre></section></div><div class="part"><section><h3>Sample Output 2</h3><pre>3 3 1 1 2 3 2 </pre></section></div></span>
p02055
<h2>D: Two Colors Sort</h2> <h3>問題</h3> <p>umg 君は散歩䞭に <var> 1,2, ... ,N </var> を䞊び倉えおできる長さ <var>N</var> の数列 <var> P_1, P_2, ..., P_N </var> を芋぀けたした。</p> <p>umg 君は䞍思議な力を䜿うこずで、同じ色に塗られた異なる数を二぀遞んで堎所を亀換するこずができたす。</p> <p>umg 君は、数列に含たれる数のうち <var>R</var> 個を赀に、残りの <var>N-R</var> 個を青に塗るこずで数列を昇順に䞊び替えられるようにしたいず考えたした。</p> <p>umg 君が目暙を達成できるかどうか刀定しおください。</p> <p>ただし、数字はずおも重いので䞍思議な力を䜿わずに動かすこずはできたせん。たた、umg 君は倩才なので䞍思議な力を任意の回数䜿うこずができたす。</p> <h3>入力圢匏</h3> <pre> <var>N</var> <var>R</var> <var>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> <h3>制玄</h3> <ul> <li> <var>1 \leq N \leq 3 \times 10^5</var></li> <li> <var>1 \leq R \leq N</var></li> <li> <var>1\leq P_i \leq N</var></li> <li> <var>P_i \neq P_j</var> (<var>1 \leq i &lt; j \leq N</var>)</li> <li>入力は党お敎数である。</li> </ul> <h3>出力圢匏</h3> <p>umg 君が目的を達成できるなら <code>Yes</code>、そうでなければ <code>No</code> を䞀行に出力せよ。</p> <h3>入力䟋 1</h3> <pre> 3 2 1 3 2 </pre> <h3>出力䟋 1</h3> <pre>Yes</pre> <ul> <li> <var>1</var> を青に、<var>2,3</var> を赀に塗るこずで目暙が達成できたす。</li> </ul> <h3>入力䟋 2</h3> <pre> 5 2 1 2 3 4 5 </pre> <h3>出力䟋 2</h3> <pre>Yes</pre> <ul> <li> 初めから昇順に䞊んでいたす。</li> </ul> <h3>入力䟋 3</h3> <pre> 10 7 3 4 8 5 7 6 2 10 1 9 </pre> <h3>出力䟋 3</h3> <pre>No</pre>
p00068
<H1>茪ゎム</H1> <p> <var>n</var> 本の釘を平板䞊の座暙 <var>P<sub>1</sub></var> (<var>x<sub>1</sub></var>, <var>y</sub>1</sub></var>), <var>P<sub>2</sub></var> (<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>), <var>P<sub>3</sub></var> (<var>x<sub>3</sub></var>, <var>y<sub>3</sub></var>),..., <var>P<sub>n</sub></var> (<var>x<sub>n</sub></var>, <var>y<sub>n</sub></var>) に本ず぀打ち、茪ゎムの茪の䞭に党おの釘が入るように 1 本の茪ゎムで囲みたす。このずき、茪ゎムが亀差しおはいけたせん。 </p> <p> 釘の座暙を読み蟌んで、䞊蚘のように釘を茪ゎムで囲んだずきに茪ゎムに接しおいない釘の本数を出力するプログラムを䜜成しおください。茪ゎムは充分に䌞び瞮みするものずしたす。同じ座暙に 2 本以䞊の釘を打぀こずはないものずしたす。たた、茪ゎムがかかった釘ず釘の間は盎線で結ばれるものずし、その盎線䞊に 3 本以䞊の釘が䞊ぶこずはないものずしたす。䟋えば、図 1 に瀺すような入力はありえたせん。図 2 に瀺すように茪ゎムがかかっおいない釘が 1 盎線䞊に䞊ぶこずはありえたす。 </p> <center> <table> <tr> <td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex1"></td> <td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex2"></td> </tr> <tr> <td>図</td> <td>図</td> </tr> </table> </center> <br/> <p> ただし、それぞれの座暙倀は -1000.0 以䞊1000.0 以䞋の実数です。たた、<var>n</var> は 3 以䞊 100 以䞋の敎数です。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋のような圢匏です䞎えられたす。 </p> <pre> <var>n</var> <var>x<sub>1</sub></var>, <var>y<sub>1</sub></var> <var>x<sub>2</sub></var>, <var>y<sub>2</sub></var> ...      ... <var>x<sub>n</sub></var>, <var>y<sub>n</sub></var> </pre> <p> <var>n</var> が 0 の時、入力の最埌を瀺したす。デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、ゎムず接しおいない釘の本数を出力しおください。 䟋えば、図 3 に瀺す぀の釘を衚す入力があった堎合、図 4 のように囲たれるので、茪ゎムに接しおいない釘の本数は 1 本です。 </p> <center> <table> <tr> <td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex3"></td> <td width="240"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex4"></td> </tr> <tr> <td>図</td> <td>図</td> </tr> </table> </center> <br/> <H2>Sample Input</H2> <pre> 4 1.0,0.0 0.0,1.0 2.0,1.0 1.0,2.0 9 -509.94,892.63 567.62,639.99 -859.32,-64.84 -445.99,383.69 667.54,430.49 551.12,828.21 -940.2,-877.2 -361.62,-970 -125.42,-178.48 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 3 </pre> <H2>Hint</H2> <p> 以䞋は぀めのサンプル入力に察する図です。 </p> <center> <table> <tr> <td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_convex5"></td> </tr> <tr> </tr> </table> </center>
p00592
<H1>Boring Commercial</H1> <p> Now it is spring holidays. A lazy student has finally passed all final examination, and he decided to just kick back and just watch TV all day. Oh, his only source of entertainment is watching TV. And TV commercial, as usual, are a big nuisance for him. He can watch any thing on television, but cannot bear even a single second of commercial. So to prevent himself from the boredom of seeing the boring commercial, he keeps shuffling through the TV channels, so that he can watch programs on different channels without seeing even a single commercial. </p> <p> Given the number of channels, and the duration at which the TV commercials are showed on each of the channels, you have to write a program which will print the longest interval for which the lazy student can watch the television by shuffling between the different channels without ever seeing an TV commercial. </p> <p> For example, consider the simplified situation where there are only three television channels, and suppose that he is watching TV from 2100 hrs to 2400 hrs. Suppose that the commercials are displayed at following time on each of the channels. </p> <ul> <li> Channel 1: 2100 to 2130, 2200 to 2230 and 2300 to 2330</li> <li> Channel 2: 2130 to 2200, 2330 to 2400</li> <li> Channel 3: 2100 to 2130, 2330 to 2400</li> </ul> <p> Then in this case, he can watch TV without getting interrupted by commercials for full 3 hours by watching Channel 2 from 2100 to 2130, then Channel 3 from 2130 to 2330, and then Channel 1 from 2330 to 2400. </p> <H2>Input</H2> <p> The input will consist of several cases. In each case, the first line of the input will be n, the number of channels, which will then be followed by p and q, the time interval between which he will be watching the TV. It will be followed by 2n lines, giving the time slots for each of the channels. For each channel, the first line will be k, the number of commercial slots, and it will then be followed by 2k numbers giving the commercial slots in order. </p> <p> The input will be terminated by values 0 for each of n, p, q. This case should not be processed. </p> <H2>Output</H2> <p> For each case, you have to output the maximum duration (in minutes) for which he can watch television without seeing any commercial. </p> <H2>Sample Input</H2> <pre> 1 2100 2400 1 2130 2200 3 2100 2400 3 2100 2130 2200 2230 2300 2330 2 2130 2200 2330 2400 2 2100 2130 2330 2400 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 120 180 </pre>
p02405
<H1>Print a Chessboard</H1> <p> Draw a chessboard which has a height of <var>H</var> cm and a width of <var>W</var> cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm. </p> <pre> #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# </pre> <p> Note that the top left corner should be drawn by '#'. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset consists of two integers <var>H</var> and <var>W</var> separated by a single space. </p> <p> The input ends with two 0 (when both <var>H</var> and <var>W</var> are zero). </p> <H2>Output</H2> <p> For each dataset, print the chessboard made of '#' and '.'. </p> <p> Print a blank line after each dataset. </p> <h2>Constraints</h2> <ul> <li>1 &le; <i>H</i> &le; 300</li> <li>1 &le; <i>W</i> &le; 300</li> </ul> <H2>Sample Input</H2> <pre> 3 4 5 6 3 3 2 2 1 1 0 0 </pre> <H2>Sample Output</H2> <pre> #.#. .#.# #.#. #.#.#. .#.#.# #.#.#. .#.#.# #.#.#. #.# .#. #.# #. .# # </pre>
p00438
<H1>通孊経路</H1> <h2>問題</h2> <p> 倪郎君の䜏んでいるJOI垂は南北方向にたっすぐに䌞びる a 本の道路ず東西方向にたっすぐに䌞びる b 本の道路により碁盀の目の圢に区分けされおいる </p> <p> 南北方向の a 本の道路には西から順に 1, 2, ... , a の番号が付けられおいるたた東西方向の b 本の道路には南から順に 1, 2, ... , b の番号が付けられおいる西から i 番目の南北方向の道路ず南から j 番目の東西方向の道路が亀わる亀差点を (i, j) で衚す </p> <p> 倪郎君は亀差点 (1, 1) の近くに䜏んでおり亀差点 (a, b) の近くのJOI高校に自転車で通っおいる自転車は道路に沿っおのみ移動するこずができる倪郎君は通孊時間を短くするため東たたは北にのみ向かっお移動しお通孊しおいる </p> <p> 珟圚 JOI垂では n 個の亀差点 (x<sub>1</sub>, y<sub>1</sub>), (x<sub>2</sub>, y<sub>2</sub>), ... , (x<sub>n</sub>, y<sub>n</sub>) で工事を行っおいる倪郎君は工事䞭の亀差点を通るこずができない </p> <p> 倪郎君が亀差点 (1, 1) から亀差点 (a, b) たで工事䞭の亀差点を避けながら東たたは北にのみ向かっお移動しお通孊する方法は䜕通りあるだろうか倪郎君の通孊経路の個数 m を求めるプログラムを䜜成せよ </p> <H2>入力</H2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる入力はれロを぀含む行で終了する </p> <p> 1行目には空癜を区切りずしお2個の敎数 a, b が曞かれおいるこれは南北方向の道路の本数ず東西方向の道路の本数を衚す a, b は 1 &le; a, b &le; 16 をみたす </p> <p> 2行目には, 工事䞭の亀差点の個数を衚す敎数 n が曞かれおいる n は 1 &le; n &le; 40 をみたす </p> <p> 続く n 行 (3行目から n+2 行目) には工事䞭の亀差点の䜍眮が曞かれおいる i+2 行目には空癜で区切られた敎数 x<sub>i</sub>, y<sub>i</sub> が曞かれおおり亀差点 (x<sub>i</sub>, y<sub>i</sub>) が工事䞭であるこずを衚す x<sub>i</sub>, y<sub>i</sub> は 1 &le; x<sub>i</sub>, y<sub>i</sub> &le; 16 をみたす </p> <p> デヌタセットの数は 5 を超えない </p> <H2>出力</H2> <p> <!--提出するファむルは, 倪郎君の通孊経路の個数 m だけを含む1行からなる.--> デヌタセットごずに, 倪郎君の通孊経路の個数 m を1行に出力する </p> <h2>入出力䟋</h2> <!-- <pre> <table style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px;"> <tr> <th width="150" align="left">入力䟋</th> </tr> <tr><td></td><td></td></tr> <tr><td>5 4 </td></tr> <tr><td>3 </td></tr> <tr><td>2 2 </td></tr> <tr><td>2 3 </td></tr> <tr><td>4 2 </td></tr> <tr> <td> </td> </tr> <tr> <th width="150" align="left">出力䟋</th> </tr> <tr><td>5</td></tr> </table> --> <H2>入力䟋</H2> <pre> 5 4 3 2 2 2 3 4 2 5 4 3 2 2 2 3 4 2 0 0 </pre> <H2>出力䟋</H2> <pre> 5 5 </pre> <p>䞋図は a=5, b=4, n=3 で工事䞭の亀差点が (2,2), (2,3), (4,2) の堎合を衚しおいる</p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_route-fig1"> </center> <p> この堎合通孊経路は m=5 通りある 5通りの通孊経路を党お図瀺するず以䞋の通り </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_route-fig2"> </center> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p01679
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>Problem Statement</h3> <p>You are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO. Since every SIRO restaurant has its own tasteful ramen, he wants to try them at as many different restaurants as possible in the night. He doesn't have plenty of time tonight, however, because he has to get up early in the morning tomorrow to join a training session. So he asked you to find the maximum number of different restaurants to which he would be able to go to eat ramen in the limited time. </p> <p>There are $n$ railway stations in the city, which are numbered $1$ through $n$. The station $s$ is the nearest to the camp venue. $m$ pairs of stations are directly connected by the railway: you can move between the stations $a_i$ and $b_i$ in $c_i$ minutes in the both directions. Among the stations, there are $l$ stations where a SIRO restaurant is located nearby. There is at most one SIRO restaurant around each of the stations, and there are no restaurants near the station $s$. It takes $e_i$ minutes for Jiro to eat ramen at the restaurant near the station $j_i$. </p> <p>It takes only a negligibly short time to go back and forth between a station and its nearby SIRO restaurant. You can also assume that Jiro doesn't have to wait for the ramen to be served in the restaurants. </p> <p>Jiro is now at the station $s$ and have to come back to the station in $t$ minutes. How many different SIRO's can he taste? </p> <h3>Input</h3> <p>The input is a sequence of datasets. The number of the datasets does not exceed $100$. Each dataset is formatted as follows: </p> <blockquote>$n$ $m$ $l$ $s$ $t$<br>$a_1$ $b_1$ $c_1$<br>:<br>:<br>$a_m$ $b_m$ $c_m$<br>$j_1$ $e_1$<br>:<br>:<br>$j_l$ $e_l$</blockquote> <p>The first line of each dataset contains five integers: </p><ul><li><p> $n$ for the number of stations, </p></li><li><p> $m$ for the number of directly connected pairs of stations, </p></li><li><p> $l$ for the number of SIRO restaurants, </p></li><li><p> $s$ for the starting-point station, and </p></li><li><p> $t$ for the time limit for Jiro. </p></li></ul> <p>Each of the following $m$ lines contains three integers: </p><ul><li><p> $a_i$ and $b_i$ for the connected stations, and </p></li><li><p> $c_i$ for the time it takes to move between the two stations. </p></li></ul> <p>Each of the following $l$ lines contains two integers: </p><ul><li><p> $j_i$ for the station where a SIRO restaurant is located, and </p></li><li><p> $e_i$ for the time it takes for Jiro to eat at the restaurant. </p></li></ul> <p>The end of the input is indicated by a line with five zeros, which is not included in the datasets. </p> <p>The datasets satisfy the following constraints: </p> <ul><li><p> $2 \le n \le 300$ </p></li><li><p> $1 \le m \le 5{,}000$ </p></li><li><p> $1 \le l \le 16$ </p></li><li><p> $1 \le s \le n$ </p></li><li><p> $1 \le t \le 100{,}000$ </p></li><li><p> $1 \le a_i, b_i \le n$ </p></li><li><p> $1 \le c_i \le 1{,}000$ </p></li><li><p> $1 \le j_i \le n$ </p></li><li><p> $1 \le e_i \le 15$ </p></li><li><p> $s \ne j_i$ </p></li><li><p> $j_i$'s are distinct. </p></li><li><p> $a_i \ne b_i$ </p></li><li><p> $(a_i, b_i) \ne (a_j, b_j)$ and $(a_i, b_i) \ne (b_j, a_j)$ for any $i \ne j$ </p></li></ul> <p>Note that there may be some stations not reachable from the starting point $s$. </p> <h3>Output</h3> <p>For each data set, output the maximum number of different restaurants where Jiro can go within the time limit. </p> <h3>Sample Input</h3> <pre>2 1 1 1 10 1 2 3 2 4 2 1 1 1 9 1 2 3 2 4 4 2 2 4 50 1 2 5 3 4 5 2 15 3 15 4 6 3 1 29 1 2 20 3 2 10 4 1 5 3 1 5 2 4 3 3 4 4 2 1 4 5 3 3 0 0 0 0 0</pre> <h3>Output for the Sample Input</h3> <pre>1 0 1 3</pre>
p03644
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi loves numbers divisible by <var>2</var>.</p> <p>You are given a positive integer <var>N</var>. Among the integers between <var>1</var> and <var>N</var> (inclusive), find the one that can be divisible by <var>2</var> for the most number of times. The solution is always unique.</p> <p>Here, the number of times an integer can be divisible by <var>2</var>, is how many times the integer can be divided by <var>2</var> without remainder.</p> <p>For example,</p> <ul> <li><var>6</var> can be divided by <var>2</var> once: <var>6</var> -&gt; <var>3</var>.</li> <li><var>8</var> can be divided by <var>2</var> three times: <var>8</var> -&gt; <var>4</var> -&gt; <var>2</var> -&gt; <var>1</var>.</li> <li><var>3</var> can be divided by <var>2</var> zero times.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N ≀ 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p><var>4</var> can be divided by <var>2</var> twice, which is the most number of times among <var>1</var>, <var>2</var>, ..., <var>7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>32 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>32 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>64 </pre></section> </div> </span>
p02956
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a set <var>S</var> of <var>N</var> points in a two-dimensional plane. The coordinates of the <var>i</var>-th point are <var>(x_i, y_i)</var>. The <var>N</var> points have distinct <var>x</var>-coordinates and distinct <var>y</var>-coordinates.</p> <p>For a non-empty subset <var>T</var> of <var>S</var>, let <var>f(T)</var> be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in <var>T</var>. More formally, we define <var>f(T)</var> as follows:</p> <ul> <li><var>f(T) := </var> (the number of integers <var>i</var> <var>(1 \leq i \leq N)</var> such that <var>a \leq x_i \leq b</var> and <var>c \leq y_i \leq d</var>, where <var>a</var>, <var>b</var>, <var>c</var>, and <var>d</var> are the minimum <var>x</var>-coordinate, the maximum <var>x</var>-coordinate, the minimum <var>y</var>-coordinate, and the maximum <var>y</var>-coordinate of the points in <var>T</var>)</li> </ul> <p>Find the sum of <var>f(T)</var> over all non-empty subset <var>T</var> of <var>S</var>. Since it can be enormous, print the sum modulo <var>998244353</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>-10^9 \leq x_i, y_i \leq 10^9</var></li> <li><var>x_i \neq x_j (i \neq j)</var></li> <li><var>y_i \neq y_j (i \neq j)</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of <var>f(T)</var> over all non-empty subset <var>T</var> of <var>S</var>, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 -1 3 2 1 3 -2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>13 </pre> <p>Let the first, second, and third points be <var>P_1</var>, <var>P_2</var>, and <var>P_3</var>, respectively. <var>S = \{P_1, P_2, P_3\}</var> has seven non-empty subsets, and <var>f</var> has the following values for each of them:</p> <ul> <li><var>f(\{P_1\}) = 1</var></li> <li><var>f(\{P_2\}) = 1</var></li> <li><var>f(\{P_3\}) = 1</var></li> <li><var>f(\{P_1, P_2\}) = 2</var></li> <li><var>f(\{P_2, P_3\}) = 2</var></li> <li><var>f(\{P_3, P_1\}) = 3</var></li> <li><var>f(\{P_1, P_2, P_3\}) = 3</var></li> </ul> <p>The sum of these is <var>13</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 4 2 1 3 3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>34 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7222 </pre> <p>Be sure to print the sum modulo <var>998244353</var>.</p></section> </div> </span>
p01383
<div> <h1 class="title">問題 H : キャッシュ戊略</h1> <p>今G○○gle Code Jam の地区倧䌚が始たろうずしおいる 斜め右前の垭に座っおいる男の ID は lyrically ず蚀うらしい 東京倧孊時代の蚘憶に䌌たような ID の仲間が居た芚えがあるが僕の仲間は䞀人残さず矎少女だったはずだ</p> <p>僕の蚘憶の䞭の lyrically はアルゎリズムの力や実装の力もさながら 気合で問題に正解するこずにも定評があった 䟋えば蚈算量が倚少悪いプログラムでも䞊手な実装をするこずで高速にし 正解ずするようなこずも埗意ずしおいた</p> <p>プログラムを高速にする䞊で非垞に倧切になっおくるのが キャッシュメモリずの芪和性である</p> <div> <h1>問題</h1> <p>ブロック毎に読み蟌みのコストが異なるメモリを考える 起こる党おのメモリアクセスがあらかじめ分かった状態での フルア゜シアティブのキャッシュメモリでの最善なキャッシュ戊略を求めたい 以䞋平易な蚀葉で説明する</p> <p><span style="font-size:110%;font-family:times new roman;"><i>M</i></span> 個の箱ず<span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 個のボヌルがある ボヌルには <span style="font-size:110%;font-family:times new roman;">1</span> から <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> たでの番号が付いおおり 各ボヌル <span style="font-size:110%;font-family:times new roman;"><i>i</i></span> には重さ <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>i</i></sub></span> が決たっおいる たた長さ <span style="font-size:110%;font-family:times new roman;"><i>K</i></span> の数列 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub>1</sub>,&nbsp;<i>a</i><sub>2</sub>,&nbsp;
,&nbsp;<i>a</i><sub><i>K</i></sub></span> が䞎えられる 各 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> は <span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>a</i><sub><i>j</i></sub>&nbsp;&le;&nbsp;<i>N</i></span> を満たす敎数である</p> <p>はじめは党おの箱は空である <span style="font-size:110%;font-family:times new roman;"><i>j</i>&nbsp;=&nbsp;1,&nbsp;2,&nbsp;
,&nbsp;<i>K</i></span> の順に以䞋を行いたい</p> <ul class="simple"> <li>ボヌル <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> が入っおいる箱があれば䜕もしない<ul> <li>この操䜜にかかるコストは 0 である</li> </ul> </li> <li>ボヌル <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> が入っおいる箱がなければいずれかの箱にボヌル <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</i></sub></span> を入れる<ul> <li>ボヌルを箱に入れる際もし既にその箱に入っおいるボヌルがあればそのボヌルは倖に出す</li> <li>この操䜜にかかるコストは <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>a</i><sub><i>j</i></sub></sub></span> であるコストは入れる箱や取り出すボヌル等にはよらない</li> </ul> </li> </ul> <p>コストの和の最小倀を蚈算するプログラムを䜜成せよ</p> </div> <div> <h1>入力</h1> <p>入力の最初の行は 3 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>M</i>,&nbsp;<i>N</i>,&nbsp;<i>K</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> 行目には敎数 <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>i</i></sub></span> が曞かれおいる</p> <p>続く <span style="font-size:110%;font-family:times new roman;"><i>K</i></span> 行の <span style="font-size:110%;font-family:times new roman;"><i>j</i></span> 行目には敎数 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>j</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>M</i>&nbsp;&le;&nbsp;10</span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>N</i>&nbsp;&le;&nbsp;10<sup>4</sup></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>K</i>&nbsp;&le;&nbsp;10<sup>4</sup></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>w</i><sub><i>i</i></sub>&nbsp;&le;&nbsp;10<sup>4</sup></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>a</i><sub><i>j</i></sub>&nbsp;&le;&nbsp;<i>N</i></span></li> </ul> </div> <div> <h1>郚分点</h1> <p>この問題の刀定には20 点分のテストケヌスのグルヌプが蚭定されおいる このグルヌプに含たれるテストケヌスの入力は以䞋を満たす</p> <ul class="simple"> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>M</i>&nbsp;&le;&nbsp;3</span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>N</i>&nbsp;&le;&nbsp;10</span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>K</i>&nbsp;&le;&nbsp;10<sup>3</sup></span></li> </ul> </div> <div> <h1>入出力䟋</h1> <div> <h2>入力䟋 1</h2> <p>入力䟋 1:</p> <pre class="literal-block"> 3 3 6 10 20 30 1 2 3 1 2 3 </pre> <p>入力䟋 1 に察する出力䟋:</p> <pre class="literal-block"> 60 </pre> </div> <div> <h2>入力䟋 2</h2> <p>入力䟋 2:</p> <pre class="literal-block"> 2 3 6 10 20 30 1 2 3 1 2 3 </pre> <p>入力䟋 2 に察する出力䟋:</p> <pre class="literal-block"> 80 </pre> </div> </div> </div>
p01229
<h1><font color="#000">Problem G:</font>゚ナゞヌ・トランスポヌタヌ</h1> <p> ずある研究所で ゚ネルギヌ䌝達甚の媒䜓の開発をしおいた この媒䜓は図3に瀺すような特殊な物質からなる ポリマヌ構造をなしおいる </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_energy" alt="゚ネルギヌ䌝達甚媒䜓の構造"> </td> </tr> <tr> <td> (-&alpha;-Ea-&beta;-)<sub><var>n</var></sub> </td> </tr> <tr> <td>図3: ゚ネルギヌ䌝達甚媒䜓の構造</td> </tr> </table> </center> <p> 図の Ea で瀺した郚分がこの媒䜓のもっずも特城的な郚䜍の ゚ナゞヌアキュムレヌタ (Energy Accumulator) である このEa基は 1 kJ 幅で離散化された倚様な゚ネルギヌ状態を取るこずができる あるEa基を励起させるず そのEa基の&alpha;偎に結合しおいる隣接したEa基に蓄積されおいる党゚ネルギヌを &beta;偎に結合しおいる隣接したEa基に移動させるような効果を持぀ 発熱反応が匕き起こされる図4 この反応の際励起されるEa基の゚ネルギヌが 1 kJ 消費される なおポリマヌの䞡端に䜍眮するEa基や゚ネルギヌ状態が 0 kJ になっおいる Ea基に察しおは励起反応は発生しないこず およびEa基は十分に倧きな゚ネルギヌを蓄えるこずが可胜であるこずが知られおいる </p> <center> <table> <tr> <td> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_energy" alt="䞭倮のEa基を励起させたずきの反応"> </td> </tr> <tr> <td>図4: 䞭倮のEa基を励起させたずきの反応</td> </tr> </table> </center> <p> この性質を利甚するこずで゚ネルギヌの䌝達を可胜にしようず考えおいたのだが ゚ネルギヌを効率よく䌝達するには各Ea基を励起させる順番が重芁であるこずに 研究者たちは気が぀いたのである </p> <p> 幞い励起させる順番や回数は任意に制埡できるのだが 圌らには最適な励起手順がわからない そこで圌らの発想の足がかりずしお 初期状態の゚ネルギヌ分垃に察しお 最右Ea基&beta;末端からもっずも近いEa基 に蓄えられうる最倧の゚ネルギヌ量を蚈算しおもらいたい </p> <h2>Input</h2> <p> 入力は耇数のデヌタセットから構成され 以䞋のような圢匏で䞎えられる </p> <pre> <var>N</var> <var>C</var><sub>1</sub> <var>C</var><sub>2</sub> ... <var>C</var><sub><var>N</var></sub> </pre> <p> 入力の先頭の敎数 <var>N</var> (0 &lt; <var>N</var> &le; 60) が取り扱う問題のデヌタセット数であり その埌ろ 2<var>N</var> 行に枡っお それぞれのデヌタセットごずの情報 <var>C</var><sub><var>k</var></sub> が䞎えられる </p> <p> それぞれのデヌタセット <var>C</var><sub><var>k</var></sub> は以䞋のような圢匏で 2行に枡り䞎えられる </p> <pre> <var>L</var> <var>E</var><sub>1</sub> <var>E</var><sub>2</sub> ... <var>E</var><sub><var>L</var></sub> </pre> <p> <var>L</var> はそれぞれのデヌタセットで取り扱う媒䜓のEa鎖の長さであり ここで䞎えられた数だけEa基が盎列に結合しおいるこずを意味しおいる その次の行の <var>L</var> 個の敎数 <var>E</var><sub><var>k</var></sub> は 長さ<var>L</var>のEa鎖のうち&alpha;末端を巊端に据えたずきに 巊から数えお<var>k</var>番目のEa鎖にはじめに蓄積されおいる゚ネルギヌ量を kJ単䜍で瀺したものである </p> <p> ここで 0 &le; <var>E</var><sub><var>k</var></sub> &le; 4, 1 &le; <var>L</var> &le; 80 であるこずが保蚌されおいる </p> <h2>Output</h2> <p> 出力は各デヌタセットごずに䞎えられた状況䞋での右端Ea鎖に到達可胜な 最倧゚ネルギヌをkJ単䜍で敎数倀のみを1行で蚘述するこず </p> <h2>Sample Input</h2> <pre> 7 1 2 2 1 2 3 4 1 4 3 4 0 4 5 4 1 4 0 4 5 4 1 4 1 4 5 4 2 4 0 4 </pre> <h2>Output for the Sample Input</h2> <pre> 2 2 8 4 7 12 11 </pre>
p03214
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Niwango-kun is an employee of Dwango Co., Ltd.<br/> One day, he is asked to generate a thumbnail from a video a user submitted.<br/> To generate a thumbnail, he needs to select a frame of the video according to the following procedure:</p> <ul> <li>Get an integer <var>N</var> and <var>N</var> integers <var>a_0, a_1, ..., a_{N-1}</var> as inputs. <var>N</var> denotes the number of the frames of the video, and each <var>a_i</var> denotes the representation of the <var>i</var>-th frame of the video.</li> <li>Select <var>t</var>-th frame whose representation <var>a_t</var> is nearest to the average of all frame representations.</li> <li>If there are multiple such frames, select the frame with the smallest index.</li> </ul> <p>Find the index <var>t</var> of the frame he should select to generate a thumbnail.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq a_i \leq 100</var></li> <li>All numbers given in input are integers</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_{0}</var> <var>a_{1}</var> <var>...</var> <var>a_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3> <pre>3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre>1 </pre> <p>Since the average of frame representations is <var>2</var>, Niwango-kun needs to select the index <var>1</var>, whose representation is <var>2</var>, that is, the nearest value to the average.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3> <pre>4 2 5 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre>0 </pre> <p>The average of frame representations is <var>3.5</var>.<br/> In this case, every frame has the same distance from its representation to the average.<br/> Therefore, Niwango-kun should select index <var>0</var>, the smallest index among them.</p></section> </div> </span>
p01803
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <!-- begin en only --> <h3><u>Airport Codes</u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>空枯コヌド</u></h3> <!-- end ja only --> <!-- end en only --> <!-- begin ja only --> <p>JAG王囜では囜内の空枯にそれぞれ空枯コヌドを割り圓おお識別をしおいる </p> <p>空枯コヌドは小文字の英語アルファベットで衚蚘した空枯の名前をもずに以䞋の芏則で割り圓おられる: </p><ol><li> 名前の最初の文字ず母音 (a,i,u,e,o) の盎埌の文字を順に取り出す </li><li> 取り出した文字列が <var>k</var> 文字未満ならそれを空枯コヌドずし <var>k</var> 文字以䞊ならその取り出した文字列の先頭 <var>k</var> 文字を空枯コヌドずしお䜿う </li></ol> <p>䟋えば <var>k</var> = 3 のずきhaneda には hnd  oookayama には ooo  tsu には t ずいうコヌドが割り圓おられる </p> <p>しかしこのコヌドの割り圓お方では違う名前の空枯でも同じコヌドが割り圓おられるこずがあり混乱を招いおしたう 空枯の名前の䞀芧が䞎えられるのですべおの空枯のコヌドが異なるようにできるか刀定しお可胜な堎合はすべおの空枯コヌドが異なるようにできる最小の <var>k</var> を求め䞍可胜な堎合はその旚を䌝えるプログラムを䜜成せよ </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は100個以䞋のデヌタセットからなる それぞれのデヌタセットは次の圢匏で䞎えられる </p> <blockquote><var>n</var><br><var>s</var><sub>1</sub><br>...<br><var>s<sub>n</sub></var></blockquote> <p>1行目に空枯の数 <var>n</var> (2 &le; <var>n</var> &le; 50) が敎数で䞎えられ続く <var>n</var> 行にはそれぞれ空枯の名前 <var>s<sub>i</sub></var> が文字列で䞎えられる 空枯の名前は'<samp>a</samp>'から'<samp>z</samp>'の小文字の英語アルファベットのみで構成されいずれも文字数は1以䞊50以䞋である たた䞎えられる空枯の名前はすべお異なるすなわち1 &le; <var>i</var> &lt; <var>j</var> &le; <var>n</var> のずき <var>s<sub>i</sub></var> &ne; <var>s<sub>j</sub></var> を満たす </p> <p>入力の終わりは1぀のれロだけからなる行で瀺される </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>それぞれのデヌタセットに぀いおすべおの空枯に盞異なる空枯コヌドを割り圓おられるずきはそのような最小の <var>k</var> を1行に出力せよ 䞍可胜な堎合は-1を1行に出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>3 haneda oookayama tsu 2 azusa azishirabe 2 snuke snake 4 haneda honda hanamaki hawaii 0</pre> <h3>Output for Sample Input</h3> <pre>1 4 -1 3</pre>
p00711
<H1><font color="#000">Problem B:</font> Red and Black</H1> <P> There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. </P> <P> Write a program to count the number of black tiles which he can reach by repeating the moves described above. </P> <H2>Input</H2> <P> The input consists of multiple data sets. A data set starts with a line containing two positive integers <I>W</I> and <I>H</I>; <I>W</I> and <I>H</I> are the numbers of tiles in the <I>x</I>- and <I>y</I>- directions, respectively. <I>W</I> and <I>H</I> are not more than 20. </P> <P> There are <I>H</I> more lines in the data set, each of which includes <I>W</I> characters. Each character represents the color of a tile as follows. </P> <ul> <li>'.' - a black tile <li>'#' - a red tile <li>'@' - a man on a black tile(appears exactly once in a data set) </ul> <p> The end of the input is indicated by a line consisting of two zeros. </p> <H2>Output</H2> <P> For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself). </P> <H2>Sample Input</H2> <PRE> 6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0 </PRE> <H2>Output for the Sample Input</H2> <PRE> 45 59 6 13 </PRE>
p00341
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>棒で䜜る盎方䜓</H1> <p> アむヅ攟送協䌚の教育番組(教育)では、子ども向けの工䜜番組「あそんで぀くろ」を攟送しおいたす。今回は棒で箱を䜜る回ですが、甚意した本の棒を䜿っお盎方䜓ができるかを確かめたいず思いたす。ただし、棒は切ったり折ったりしおはいけたせん。 </p> <br/> <p> 本の棒の長さが䞎えられるので、それらすべおを蟺ずする盎方䜓が䜜れるかどうか刀定するプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>e<sub>1</sub></var> <var>e<sub>2</sub></var> ... <var>e<sub>12</sub></var> </pre> <p> 入力は行からなり、各棒の長さを衚す敎数 <var>e<sub>i</sub></var> (1 &le; <var>e<sub>i</sub></var> &le; 100) が䞎えられる。 </p> <h2>Output</h2> <p> 盎方䜓を䜜成できる堎合には「yes」を、䜜成できない堎合には「no」を出力する。ただし、立方䜓は盎方䜓の䞀皮なので、立方䜓の堎合でも「yes」ず出力する。 </p> <h2>Sample Input 1</h2> <pre> 1 1 3 4 8 9 7 3 4 5 5 5 </pre> <h2>Sample Output 1</h2> <pre> no </pre> <br/> <h2>Sample Input 2</h2> <pre> 1 1 2 2 3 1 2 3 3 3 1 2 </pre> <h2>Sample Output 2</h2> <pre> yes </pre>
p03994
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Mr. Takahashi has a string <var>s</var> consisting of lowercase English letters. He repeats the following operation on <var>s</var> exactly <var>K</var> times.</p> <ul> <li>Choose an arbitrary letter on <var>s</var> and change that letter to the next alphabet. Note that the next letter of <code>z</code> is <code>a</code>.</li> </ul> <p>For example, if you perform an operation for the second letter on <code>aaz</code>, <code>aaz</code> becomes <code>abz</code>. If you then perform an operation for the third letter on <code>abz</code>, <code>abz</code> becomes <code>aba</code>.</p> <p>Mr. Takahashi wants to have the lexicographically smallest string after performing exactly <var>K</var> operations on <var>s</var>. Find the such string.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀|s|≀10^5</var></li> <li>All letters in <var>s</var> are lowercase English letters.</li> <li><var>1≀K≀10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>s</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest string after performing exactly <var>K</var> operations on <var>s</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>xyz 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>aya </pre> <p>For example, you can perform the following operations: <code>xyz</code>, <code>yyz</code>, <code>zyz</code>, <code>ayz</code>, <code>aya</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>a 25 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>z </pre> <p>You have to perform exactly <var>K</var> operations.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>codefestival 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>aaaafeaaivap </pre></section> </div> </span>
p02686
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A <strong>bracket sequence</strong> is a string that is one of the following:</p> <ol> <li>An empty string;</li> <li>The concatenation of <code>(</code>, <var>A</var>, and <code>)</code> in this order, for some bracket sequence <var>A</var> ;</li> <li>The concatenation of <var>A</var> and <var>B</var> in this order, for some non-empty bracket sequences <var>A</var> and <var>B</var> /</li> </ol> <p>Given are <var>N</var> strings <var>S_i</var>. Can a bracket sequence be formed by concatenating all the <var>N</var> strings in some order?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^6</var></li> <li>The total length of the strings <var>S_i</var> is at most <var>10^6</var>.</li> <li><var>S_i</var> is a non-empty string 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_1</var> <var>:</var> <var>S_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If a bracket sequence can be formed by concatenating all the <var>N</var> strings in some order, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 ) (() </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>Concatenating <code>(()</code> and <code>)</code> in this order forms a bracket sequence.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 )( () </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 ((())) (((((( )))))) ()()() </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>3 ((( ) ) </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre></section> </div> </span>
p01100
<h3>Gift Exchange Party</h3> <p> A gift exchange party will be held at a school in TKB City. </p> <p> For every pair of students who are close friends, one gift must be given from one to the other at this party, but not the other way around. It is decided in advance the gift directions, that is, which student of each pair receives a gift. No other gift exchanges are made. </p> <p> If each pair randomly decided the gift direction, some might receive countless gifts, while some might receive only few or even none. </p> <p> You'd like to decide the gift directions for all the friend pairs that minimize the difference between the smallest and the largest numbers of gifts received by a student. Find the smallest and the largest numbers of gifts received when the difference between them is minimized. When there is more than one way to realize that, find the way that maximizes the smallest number of received gifts. </p> <h3>Input</h3> <p> The input consists of at most 10 datasets, each in the following format. </p> <p> <i>n</i> <i>m</i><br> <i>u</i><sub>1</sub> <i>v</i><sub>1</sub><br> ... <br> <i>u<sub>m</sub></i> <i>v<sub>m</sub></i> </p> <p> <i>n</i> is the number of students, and <i>m</i> is the number of friendship relations (2 &le; <i>n</i> &le; 100, 1 &le; <i>m</i> &le; <i>n</i> (<i>n</i>-1)/2). Students are denoted by integers between 1 and <i>n</i>, inclusive. The following <i>m</i> lines describe the friendship relations: for each <i>i</i>, student <i>u<sub>i</sub></i> and <i>v<sub>i</sub></i> are close friends (<i>u<sub>i</sub></i> &lt; <i>v<sub>i</sub></i>). The same friendship relations do not appear more than once. </p> <p> The end of the input is indicated by a line containing two zeros. </p> <h3>Output</h3> <p> For each dataset, output a single line containing two integers <i>l</i> and <i>h</i> separated by a single space. Here, <i>l</i> and <i>h</i> are the smallest and the largest numbers, respectively, of gifts received by a student. </p> <h3>Sample Input</h3> <pre> 3 3 1 2 2 3 1 3 4 3 1 2 1 3 1 4 4 6 1 2 1 3 1 4 2 3 3 4 2 4 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 1 1 0 1 1 2 </pre>
p01550
<h1>問題名</h1> <p>今 <var>n</var> 枚の数字が曞かれたカヌドがありたす。これらの䞀郚たたは党郚を適圓に䞊べお数字を䜜るこずを考えたす。この時䜜られる数字を党お足した数を求めお䞋さい。 </p> <p>䟋えば、 1 ず 2 があったら、䜜られる数字は 1, 2, 12, 21 の 4 ぀なので、党お足した数は 36 になりたす。䞊べた結果同じ数字が出来おも違う䞊べ方だずしたら別々に足したす。たずえば、 1 ずいうカヌドず 11 ずいうカヌドがあったら䞊べお 111 になる䞊べ方が2通りありたすがそれぞれ別のものずしお足し合わせたす。カヌドの䞭にリヌディングれロのカヌドはありたせんし、リヌディングれロになる数字は認めたせん。答えを1,000,000,007 で割ったものを出力しおください。 </p> <h2>Input</h2> <p>入力は、以䞋の圢で䞎えられたす。 </p><blockquote> <var>n</var><br><var>a<sub>1</sub></var><br><var>a<sub>2</sub></var><br>...<br><var>a<sub>n</sub></var><br></blockquote> <p>最初の 1 行にはカヌドの枚数を衚す <var>n</var><var>1 &le; n &le; 200</var>、次の <var>n</var> 行にはそれぞれのカヌドに曞かれおいる数字 <var>a<sub>i</sub></var> (<var>0 &le; a<sub>i</sub> < 10000</var>) が曞かれおいたす。たた耇数のカヌドに同じ数字が曞かれおいるこずはありたせん。 </p> <h2>Output</h2> <p>䜜るこずの出来る党おの数字の合蚈を 1,000,000,007 で割ったものを 1 行に出力しなさい。 </p> <h2>Sample Input 1</h2> <pre>2 1 2 </pre> <h2>Output for the Sample Input 1</h2> <pre>36 </pre> <p>サンプルにあった䟋です。 </p> <h2>Sample Input 2</h2> <pre>2 1 11 </pre> <h2>Output for the Sample Input 2</h2> <pre>234 </pre> <p>䜜られる数字は 1 ず 11 ず、 111 が 2 通り䜜られるので党お足しお 234 ずなりたす。 </p> <h2>Sample Input 3</h2> <pre>4 0 4 7 8 </pre> <h2>Output for the Sample Input 3</h2> <pre>135299 </pre> <p>04 や 078 ずいった䞊べ方は認められないこずに泚意しおください。 </p>
p03097
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given integers <var>N,\ A</var> and <var>B</var>. Determine if there exists a permutation <var>(P_0,\ P_1,\ ...\ P_{2^N-1})</var> of <var>(0,\ 1,\ ...\ 2^N-1)</var> that satisfies all of the following conditions, and create one such permutation if it exists.</p> <ul> <li><var>P_0=A</var></li> <li><var>P_{2^N-1}=B</var></li> <li>For all <var>0 \leq i &lt; 2^N-1</var>, the binary representations of <var>P_i</var> and <var>P_{i+1}</var> differ by exactly one bit.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 17</var></li> <li><var>0 \leq A \leq 2^N-1</var></li> <li><var>0 \leq B \leq 2^N-1</var></li> <li><var>A \neq B</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is no permutation that satisfies the conditions, print <code>NO</code>.</p> <p>If there is such a permutation, print <code>YES</code> in the first line. Then, print <var>(P_0,\ P_1,\ ...\ P_{2^N-1})</var> in the second line, with spaces in between. If there are multiple solutions, any of them is accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES 1 0 2 3 </pre> <p>The binary representation of <var>P=(1,0,2,3)</var> is <var>(01,00,10,11)</var>, where any two adjacent elements differ by exactly one bit.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre></section> </div> </span>
p03582
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For a string <var>S</var>, let <var>f(S)</var> be the lexicographically smallest cyclic shift of <var>S</var>. For example, if <var>S = </var><code>babca</code>, <var>f(S) = </var><code>ababc</code> because this is the smallest among all cyclic shifts (<code>babca</code>, <code>abcab</code>, <code>bcaba</code>, <code>cabab</code>, <code>ababc</code>).</p> <p>You are given three integers <var>X, Y</var>, and <var>Z</var>. You want to construct a string <var>T</var> that consists of exactly <var>X</var> <code>a</code>s, exactly <var>Y</var> <code>b</code>s, and exactly <var>Z</var> <code>c</code>s. If there are multiple such strings, you want to choose one that maximizes <var>f(T)</var> lexicographically.</p> <p>Compute the lexicographically largest possible value of <var>f(T)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X + Y + Z \leq 50</var></li> <li><var>X, Y, Z</var> are non-negative 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> <var>Z</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>abab </pre> <p><var>T</var> must consist of two <code>a</code>s and two <code>b</code>s.</p> <ul> <li>If <var>T = </var><code>aabb</code>, <var>f(T) = </var><code>aabb</code>.</li> <li>If <var>T = </var><code>abab</code>, <var>f(T) = </var><code>abab</code>.</li> <li>If <var>T = </var><code>abba</code>, <var>f(T) = </var><code>aabb</code>.</li> <li>If <var>T = </var><code>baab</code>, <var>f(T) = </var><code>aabb</code>.</li> <li>If <var>T = </var><code>baba</code>, <var>f(T) = </var><code>abab</code>.</li> <li>If <var>T = </var><code>bbaa</code>, <var>f(T) = </var><code>aabb</code>.</li> </ul> <p>Thus, the largest possible <var>f(T)</var> is <code>abab</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>acb </pre></section> </div> </span>
p03078
<span class="lang-en"> <p>Score: <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>The Patisserie AtCoder sells cakes with number-shaped candles. There are <var>X</var>, <var>Y</var> and <var>Z</var> kinds of cakes with <var>1</var>-shaped, <var>2</var>-shaped and <var>3</var>-shaped candles, respectively. Each cake has an integer value called <em>deliciousness</em>, as follows:</p> <ul> <li>The deliciousness of the cakes with <var>1</var>-shaped candles are <var>A_1, A_2, ..., A_X</var>.</li> <li>The deliciousness of the cakes with <var>2</var>-shaped candles are <var>B_1, B_2, ..., B_Y</var>.</li> <li>The deliciousness of the cakes with <var>3</var>-shaped candles are <var>C_1, C_2, ..., C_Z</var>.</li> </ul> <p>Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123.<br/> There are <var>X \times Y \times Z</var> such ways to choose three cakes.<br/> We will arrange these <var>X \times Y \times Z</var> ways in descending order of the sum of the deliciousness of the cakes.<br/> Print the sums of the deliciousness of the cakes for the first, second, <var>...</var>, <var>K</var>-th ways in this list.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq X \leq 1 \ 000</var></li> <li><var>1 \leq Y \leq 1 \ 000</var></li> <li><var>1 \leq Z \leq 1 \ 000</var></li> <li><var>1 \leq K \leq \min(3 \ 000, X \times Y \times Z)</var></li> <li><var>1 \leq A_i \leq 10 \ 000 \ 000 \ 000</var></li> <li><var>1 \leq B_i \leq 10 \ 000 \ 000 \ 000</var></li> <li><var>1 \leq C_i \leq 10 \ 000 \ 000 \ 000</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>X</var> <var>Y</var> <var>Z</var> <var>K</var> <var>A_1 \ A_2 \ A_3 \ ... \ A_X</var> <var>B_1 \ B_2 \ B_3 \ ... \ B_Y</var> <var>C_1 \ C_2 \ C_3 \ ... \ C_Z</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print <var>K</var> lines. The <var>i</var>-th line should contain the <var>i</var>-th value stated in the problem statement.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 8 4 6 1 5 3 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>19 17 15 14 13 12 10 8 </pre> <p>There are <var>2 \times 2 \times 2 = 8</var> ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes:</p> <ul> <li><var>(A_2, B_2, C_2)</var>: <var>6 + 5 + 8 = 19</var></li> <li><var>(A_1, B_2, C_2)</var>: <var>4 + 5 + 8 = 17</var></li> <li><var>(A_2, B_1, C_2)</var>: <var>6 + 1 + 8 = 15</var></li> <li><var>(A_2, B_2, C_1)</var>: <var>6 + 5 + 3 = 14</var></li> <li><var>(A_1, B_1, C_2)</var>: <var>4 + 1 + 8 = 13</var></li> <li><var>(A_1, B_2, C_1)</var>: <var>4 + 5 + 3 = 12</var></li> <li><var>(A_2, B_1, C_1)</var>: <var>6 + 1 + 3 = 10</var></li> <li><var>(A_1, B_1, C_1)</var>: <var>4 + 1 + 3 = 8</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 3 5 1 10 100 2 20 200 1 10 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>400 310 310 301 301 </pre> <p>There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of <var>A_1, B_3, C_3</var> and the sum of <var>A_3, B_3, C_1</var> are both <var>301</var>. However, they are different ways of choosing cakes, so <var>301</var> occurs twice in the output.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 10 20 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>23379871545 22444657051 22302177772 22095691512 21667941469 21366963278 21287912315 21279176669 21160477018 21085311041 21059876163 21017997739 20703329561 20702387965 20590247696 20383761436 20343962175 20254073196 20210218542 20150096547 </pre> <p>Note that the input or output may not fit into a <var>32</var>-bit integer type.</p></section> </div> </span>
p01045
<h1>Problem I: Hopping Mind</h1> <h2>Problem</h2> <p> チ゚ノずカカオは同じ喫茶店で働く姉効である。2人はずおも仲が良く、ある日、ずあるテヌブルゲヌムで遊ぶこずになった。 </p> <p> ゲヌムは<var>R</var>マス&times;<var>C</var>マスの盀面ず、駒ずしおうさぎのTPを甚いる。盀面の各マスは癜か黒の色が塗られおいる。最初にTPを盀面の右䞋(<var>R</var>,<var>C</var>)におき、2人で次の行動を亀互に行う。TPの珟圚の䜍眮を(<var>a</var>,<var>b</var>)ずするず、そこからゞャンプ可胜な䜍眮(<var>i</var>,<var>j</var>)を1぀遞び、TPをそこにゞャンプさせる。TPがゞャンプ可胜な䜍眮(<var>i</var>,<var>j</var>)は以䞋をすべお満たす。 </p> <ol> <li> 1 &le; <var>i</var> &le; <var>R</var> か぀ 1 &le; <var>j</var> &le; <var>C</var> か぀ <var>i</var> &le; <var>a</var> か぀ <var>j</var> &le; <var>b</var> か぀ 1 &le; (<var>a</var>-<var>i</var>) + (<var>b</var>-<var>j</var>) &le; <var>K</var> </li> <li> (<var>i</var>,<var>j</var>)は癜いマスである </li> </ol> <p> 自分のタヌンにTPをゞャンプさせるこずができなくなった堎合、負けずなる。 </p> <p> チ゚ノが先手、カカオが埌手でこのゲヌムを行う。カカオは頭の䞭でゲヌムを最埌たで先読みするこずができ、垞に最適な行動をずる。この時、チ゚ノが勝぀方法が存圚するかどうかを刀定せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>R</var> <var>C</var> <var>K</var> <var>G<sub>1,1</sub></var> <var>G<sub>1,2</sub></var> ... <var>G<sub>1,C</sub></var> <var>G<sub>2,1</sub></var> <var>G<sub>2,2</sub></var> ... <var>G<sub>2,C</sub></var> : <var>G<sub>R,1</sub></var> <var>G<sub>R,2</sub></var> ... <var>G<sub>R,C</sub></var> </pre> <p> 1行目に3぀の敎数<var>R</var>,<var>C</var>,<var>K</var>が空癜区切りで䞎えられる。次の<var>R</var>行に盀面の情報ずしお<var>C</var>個の".”たたは"#”が䞎えられる。<var>G<sub>i,j</sub></var>は盀面の䜍眮(<var>i</var>,<var>j</var>)の色を衚し、”.”が癜、"#”が黒を衚す。 </p> <h2>Constraints</h2> <ul> <li>1 &le; <var>R</var>,<var>C</var> &le; 1000</li> <li>1 &le; <var>K</var> &le; 2000</li> <li><var>G<sub>R,C</sub></var>は“.”である</li> </ul> <h2>Output</h2> <p> チ゚ノが勝぀方法が存圚する堎合は”Chieno”を、存圚しない堎合は”Cacao”を1行に出力せよ。 </p> <h2>Sample Input1</h2> <pre> 3 3 2 ... ... ... </pre> <h2>Sample Output1</h2> <pre> Chieno </pre> <h2>Sample Input2</h2> <pre> 3 3 2 #.# .#. #.. </pre> <h2>Sample Output2</h2> <pre> Cacao </pre>
p03428
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> holes in a two-dimensional plane. The coordinates of the <var>i</var>-th hole are <var>(x_i,y_i)</var>.</p> <p>Let <var>R=10^{10^{10^{10}}}</var>. Ringo performs the following operation:</p> <ul> <li>Randomly choose a point from the interior of a circle of radius <var>R</var> centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen.</li> </ul> <p>For every <var>i</var> <var>(1 \leq i \leq N)</var>, find the probability that Snuke falls into the <var>i</var>-th hole.</p> <p>Here, the operation of randomly choosing a point from the interior of a circle of radius <var>R</var> is defined as follows:</p> <ul> <li>Pick two real numbers <var>x</var> and <var>y</var> independently according to uniform distribution on <var>[-R,R]</var>.</li> <li>If <var>x^2+y^2\leq R^2</var>, the point <var>(x,y)</var> is chosen. Otherwise, repeat picking the real numbers <var>x,y</var> until the condition is met.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 100</var></li> <li><var>|x_i|,|y_i| \leq 10^6(1\leq i\leq N)</var></li> <li>All given points are pairwise distinct.</li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> real numbers. The <var>i</var>-th real number must represent the probability that Snuke falls into the <var>i</var>-th hole.</p> <p>The output will be judged correct when, for all output values, the absolute or relative error is at most <var>10^{-5}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 0 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0.5 0.5 </pre> <p>If Ringo put Snuke in the region <var>x+y\leq 1</var>, Snuke will fall into the first hole. The probability of this happening is very close to <var>0.5</var>. Otherwise, Snuke will fall into the second hole, the probability of which happening is also very close to <var>0.5</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 0 2 8 4 5 2 6 3 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0.43160120892732328768 0.03480224363653196956 0.13880483535586193855 0.00000000000000000000 0.39479171208028279727 </pre></section> </div> </span>
p01415
<H1>I: Starting Line</H1> <p> ICPC で良い成瞟を収めるには修行が欠かせないうさぎは ICPC で勝ちたいので今日も修行をするこずにした </p> <p> 今日の修行は䞀盎線䞊の道を走っお䜓力ず刀断力を逊おうずいうものであるうさぎは今スタヌトラむンに立っお長い長い道を芋枡しおいる </p> <p> 道の途䞭にはいく぀かニンゞンが眮かれおおりうさぎはニンゞンを食べるず加速するこずができる加速しおいないずきのうさぎの走る速さは毎秒 <i>U</i> メヌトルであるがニンゞンを食べるこずで最埌のニンゞンを食べおから <i>T</i> 秒埌たでは速さが毎秒 <i>V</i> メヌトルずなるたたうさぎはニンゞンを <i>K</i> 個たで食べずに持っおおくこずができるニンゞンを持っおいおも走る速さは倉わらない </p> <p> ニンゞンを持ったり食べたりするのに時間はかからないずしおゎヌルたでの最短所芁時間を求めたい </p> <H2>Input</H2> <pre> <i>N</i> <i>K</i> <i>T</i> <i>U</i> <i>V</i> <i>L</i> <i>D</i><sub>1</sub> ... <i>D</i><sub><i>N</i></sub> </pre> <p> <i>N</i> はニンゞンの個数<i>L</i> はスタヌトからゎヌルたでの距離 (メヌトル)<i>D</i><sub><i>i</i></sub> (1 &le; <i>i</i> &le; <i>N</i>) は <i>i</i> 番目のニンゞンが眮かれおいる堎所のスタヌトからの距離 (メヌトル) である </p> <p> 1 &le; <i>N</i> &le; 2001 &le; <i>K</i> &le; <i>N</i>1 &le; <i>T</i> &le; 10,0001 &le; <i>U</i> &lt; <i>V</i> &le; 10,0002 &le; <i>L</i> &le; 10,0000 &lt; <i>D</i><sub>1</sub> &lt; <i>D</i><sub>2</sub> &lt; ... &lt; <i>D</i><sub><i>N</i></sub> &lt; <i>L</i> を満たす入力の倀はすべお敎数である </p> <H2>Output</H2> <p> 最短所芁時間 (秒) を 1 行に出力せよ10<sup>-6</sup> 以䞋の絶察誀差が蚱容される </p> <H2>Sample Input 1</H2> <pre> 1 1 1 2 3 100 50 </pre> <H2>Sample Output 1</H2> <pre> 49.500000000 </pre> <H2>Sample Input 2</H2> <pre> 3 1 1 2 3 100 49 50 51 </pre> <H2>Sample Output 2</H2> <pre> 48.666666667 </pre>
p02393
<H1>Sorting Three Numbers</H1> <p> Write a program which reads three integers, and prints them in ascending order. </p> <H2>Input</H2> <p> Three integers separated by a single space are given in a line. </p> <H2>Output</H2> <p> Print the given integers in ascending order in a line. Put a single space between two integers. </p> <h2>Constraints</h2> <ul> <li> 1 &le; the three integers &le; 10000</li> </ul> <H2>Sample Input 1</H2> <pre> 3 8 1 </pre> <H2>Sample Output 1</H2> <pre> 1 3 8 </pre>